Correct failing test and transform it into a bunch of another tests.
[wine.git] / dlls / shell32 / shfldr_fs.c
blobcb92d73eceb46aa5a91d980188bb1c247aa65f86
2 /*
3 * file system folder
5 * Copyright 1997 Marcus Meissner
6 * Copyright 1998, 1999, 2002 Juergen Schmied
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "config.h"
24 #include "wine/port.h"
26 #include <stdlib.h>
27 #include <string.h>
28 #include <stdarg.h>
29 #include <stdio.h>
31 #define COBJMACROS
32 #define NONAMELESSUNION
33 #define NONAMELESSSTRUCT
35 #include "winerror.h"
36 #include "windef.h"
37 #include "winbase.h"
38 #include "winreg.h"
39 #include "wingdi.h"
40 #include "winuser.h"
42 #include "ole2.h"
43 #include "shlguid.h"
45 #include "enumidlist.h"
46 #include "pidl.h"
47 #include "undocshell.h"
48 #include "shell32_main.h"
49 #include "shresdef.h"
50 #include "shlwapi.h"
51 #include "shellfolder.h"
52 #include "wine/debug.h"
53 #include "debughlp.h"
54 #include "shfldr.h"
56 WINE_DEFAULT_DEBUG_CHANNEL (shell);
58 /***********************************************************************
59 * IShellFolder implementation
62 typedef struct {
63 const IUnknownVtbl *lpVtbl;
64 LONG ref;
65 const IShellFolder2Vtbl *lpvtblShellFolder;
66 const IPersistFolder3Vtbl *lpvtblPersistFolder3;
67 const IDropTargetVtbl *lpvtblDropTarget;
68 const ISFHelperVtbl *lpvtblSFHelper;
70 IUnknown *pUnkOuter; /* used for aggregation */
72 CLSID *pclsid;
74 /* both paths are parsible from the desktop */
75 LPSTR sPathTarget; /* complete path to target used for enumeration and ChangeNotify */
77 LPITEMIDLIST pidlRoot; /* absolute pidl */
79 UINT cfShellIDList; /* clipboardformat for IDropTarget */
80 BOOL fAcceptFmt; /* flag for pending Drop */
81 } IGenericSFImpl;
83 static const IUnknownVtbl unkvt;
84 static const IShellFolder2Vtbl sfvt;
85 static const IPersistFolder3Vtbl vt_FSFldr_PersistFolder3; /* IPersistFolder3 for a FS_Folder */
86 static const IDropTargetVtbl dtvt;
87 static const ISFHelperVtbl shvt;
89 static inline IGenericSFImpl *impl_from_IShellFolder2( IShellFolder2 *iface )
91 return (IGenericSFImpl *)((char*)iface - FIELD_OFFSET(IGenericSFImpl, lpvtblShellFolder));
94 static inline IGenericSFImpl *impl_from_IPersistFolder3( IPersistFolder3 *iface )
96 return (IGenericSFImpl *)((char*)iface - FIELD_OFFSET(IGenericSFImpl, lpvtblPersistFolder3));
99 static inline IGenericSFImpl *impl_from_IDropTarget( IDropTarget *iface )
101 return (IGenericSFImpl *)((char*)iface - FIELD_OFFSET(IGenericSFImpl, lpvtblDropTarget));
104 static inline IGenericSFImpl *impl_from_ISFHelper( ISFHelper *iface )
106 return (IGenericSFImpl *)((char*)iface - FIELD_OFFSET(IGenericSFImpl, lpvtblSFHelper));
111 converts This to an interface pointer
113 #define _IUnknown_(This) (IUnknown*)&(This->lpVtbl)
114 #define _IShellFolder_(This) (IShellFolder*)&(This->lpvtblShellFolder)
115 #define _IShellFolder2_(This) (IShellFolder2*)&(This->lpvtblShellFolder)
116 #define _IPersist_(This) (IPersist*)&(This->lpvtblPersistFolder3)
117 #define _IPersistFolder_(This) (IPersistFolder*)&(This->lpvtblPersistFolder3)
118 #define _IPersistFolder2_(This) (IPersistFolder2*)&(This->lpvtblPersistFolder3)
119 #define _IPersistFolder3_(This) (IPersistFolder3*)&(This->lpvtblPersistFolder3)
120 #define _IDropTarget_(This) (IDropTarget*)&(This->lpvtblDropTarget)
121 #define _ISFHelper_(This) (ISFHelper*)&(This->lpvtblSFHelper)
123 /**************************************************************************
124 * registers clipboardformat once
126 static void SF_RegisterClipFmt (IGenericSFImpl * This)
128 TRACE ("(%p)\n", This);
130 if (!This->cfShellIDList) {
131 This->cfShellIDList = RegisterClipboardFormatA (CFSTR_SHELLIDLIST);
135 /**************************************************************************
136 * we need a separate IUnknown to handle aggregation
137 * (inner IUnknown)
139 static HRESULT WINAPI IUnknown_fnQueryInterface (IUnknown * iface, REFIID riid, LPVOID * ppvObj)
141 IGenericSFImpl *This = (IGenericSFImpl *)iface;
143 TRACE ("(%p)->(%s,%p)\n", This, shdebugstr_guid (riid), ppvObj);
145 *ppvObj = NULL;
147 if (IsEqualIID (riid, &IID_IUnknown))
148 *ppvObj = _IUnknown_ (This);
149 else if (IsEqualIID (riid, &IID_IShellFolder))
150 *ppvObj = _IShellFolder_ (This);
151 else if (IsEqualIID (riid, &IID_IShellFolder2))
152 *ppvObj = _IShellFolder_ (This);
153 else if (IsEqualIID (riid, &IID_IPersist))
154 *ppvObj = _IPersist_ (This);
155 else if (IsEqualIID (riid, &IID_IPersistFolder))
156 *ppvObj = _IPersistFolder_ (This);
157 else if (IsEqualIID (riid, &IID_IPersistFolder2))
158 *ppvObj = _IPersistFolder2_ (This);
159 else if (IsEqualIID (riid, &IID_IPersistFolder3))
160 *ppvObj = _IPersistFolder3_ (This);
161 else if (IsEqualIID (riid, &IID_ISFHelper))
162 *ppvObj = _ISFHelper_ (This);
163 else if (IsEqualIID (riid, &IID_IDropTarget)) {
164 *ppvObj = _IDropTarget_ (This);
165 SF_RegisterClipFmt (This);
168 if (*ppvObj) {
169 IUnknown_AddRef ((IUnknown *) (*ppvObj));
170 TRACE ("-- Interface = %p\n", *ppvObj);
171 return S_OK;
173 TRACE ("-- Interface: E_NOINTERFACE\n");
174 return E_NOINTERFACE;
177 static ULONG WINAPI IUnknown_fnAddRef (IUnknown * iface)
179 IGenericSFImpl *This = (IGenericSFImpl *)iface;
180 ULONG refCount = InterlockedIncrement(&This->ref);
182 TRACE ("(%p)->(count=%lu)\n", This, refCount - 1);
184 return refCount;
187 static ULONG WINAPI IUnknown_fnRelease (IUnknown * iface)
189 IGenericSFImpl *This = (IGenericSFImpl *)iface;
190 ULONG refCount = InterlockedDecrement(&This->ref);
192 TRACE ("(%p)->(count=%lu)\n", This, refCount + 1);
194 if (!refCount) {
195 TRACE ("-- destroying IShellFolder(%p)\n", This);
197 if (This->pidlRoot)
198 SHFree (This->pidlRoot);
199 if (This->sPathTarget)
200 SHFree (This->sPathTarget);
201 LocalFree ((HLOCAL) This);
203 return refCount;
206 static const IUnknownVtbl unkvt =
208 IUnknown_fnQueryInterface,
209 IUnknown_fnAddRef,
210 IUnknown_fnRelease,
213 static shvheader GenericSFHeader[] = {
214 {IDS_SHV_COLUMN1, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 15},
215 {IDS_SHV_COLUMN2, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
216 {IDS_SHV_COLUMN3, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
217 {IDS_SHV_COLUMN4, SHCOLSTATE_TYPE_DATE | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 12},
218 {IDS_SHV_COLUMN5, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 5}
221 #define GENERICSHELLVIEWCOLUMNS 5
223 /**************************************************************************
224 * IFSFolder_Constructor
226 * NOTES
227 * creating undocumented ShellFS_Folder as part of an aggregation
228 * {F3364BA0-65B9-11CE-A9BA-00AA004AE837}
231 HRESULT WINAPI
232 IFSFolder_Constructor (IUnknown * pUnkOuter, REFIID riid, LPVOID * ppv)
234 IGenericSFImpl *sf;
236 TRACE ("unkOut=%p %s\n", pUnkOuter, shdebugstr_guid (riid));
238 if (pUnkOuter && !IsEqualIID (riid, &IID_IUnknown))
239 return CLASS_E_NOAGGREGATION;
240 sf = (IGenericSFImpl *) LocalAlloc (LMEM_ZEROINIT, sizeof (IGenericSFImpl));
241 if (!sf)
242 return E_OUTOFMEMORY;
244 sf->ref = 0;
245 sf->lpVtbl = &unkvt;
246 sf->lpvtblShellFolder = &sfvt;
247 sf->lpvtblPersistFolder3 = &vt_FSFldr_PersistFolder3;
248 sf->lpvtblDropTarget = &dtvt;
249 sf->lpvtblSFHelper = &shvt;
250 sf->pclsid = (CLSID *) & CLSID_ShellFSFolder;
251 sf->pUnkOuter = pUnkOuter ? pUnkOuter : _IUnknown_ (sf);
253 if (!SUCCEEDED (IUnknown_QueryInterface (_IUnknown_ (sf), riid, ppv))) {
254 IUnknown_Release (_IUnknown_ (sf));
255 return E_NOINTERFACE;
258 TRACE ("--%p\n", *ppv);
259 return S_OK;
262 /**************************************************************************
263 * IShellFolder_fnQueryInterface
265 * PARAMETERS
266 * REFIID riid [in ] Requested InterfaceID
267 * LPVOID* ppvObject [out] Interface* to hold the result
269 static HRESULT WINAPI
270 IShellFolder_fnQueryInterface (IShellFolder2 * iface, REFIID riid,
271 LPVOID * ppvObj)
273 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
275 TRACE ("(%p)->(%s,%p)\n", This, shdebugstr_guid (riid), ppvObj);
277 return IUnknown_QueryInterface (This->pUnkOuter, riid, ppvObj);
280 /**************************************************************************
281 * IShellFolder_AddRef
284 static ULONG WINAPI IShellFolder_fnAddRef (IShellFolder2 * iface)
286 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
288 TRACE ("(%p)->(count=%lu)\n", This, This->ref);
290 return IUnknown_AddRef (This->pUnkOuter);
293 /**************************************************************************
294 * IShellFolder_fnRelease
296 static ULONG WINAPI IShellFolder_fnRelease (IShellFolder2 * iface)
298 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
300 TRACE ("(%p)->(count=%lu)\n", This, This->ref);
302 return IUnknown_Release (This->pUnkOuter);
305 /**************************************************************************
306 * SHELL32_CreatePidlFromBindCtx [internal]
308 * If the caller bound File System Bind Data, assume it is the
309 * find data for the path.
310 * This allows binding of paths that don't exist.
312 LPITEMIDLIST SHELL32_CreatePidlFromBindCtx(IBindCtx *pbc, LPCWSTR path)
314 static const WCHAR szfsbc[] = {
315 'F','i','l','e',' ','S','y','s','t','e','m',' ',
316 'B','i','n','d',' ','D','a','t','a',0 };
317 IFileSystemBindData *fsbd = NULL;
318 LPITEMIDLIST pidl = NULL;
319 IUnknown *param = NULL;
320 WIN32_FIND_DATAW wfd;
321 HRESULT r;
323 TRACE("%p %s\n", pbc, debugstr_w(path));
325 if (!pbc)
326 return NULL;
328 /* see if the caller bound File System Bind Data */
329 r = IBindCtx_GetObjectParam( pbc, (LPOLESTR) szfsbc, &param );
330 if (FAILED(r))
331 return NULL;
333 r = IUnknown_QueryInterface( param, &IID_IFileSystemBindData,
334 (LPVOID*) &fsbd );
335 if (SUCCEEDED(r))
337 r = IFileSystemBindData_GetFindData( fsbd, &wfd );
338 if (SUCCEEDED(r))
340 lstrcpynW( &wfd.cFileName[0], path, MAX_PATH );
341 pidl = _ILCreateFromFindDataW( &wfd );
343 IFileSystemBindData_Release( fsbd );
346 return pidl;
349 /**************************************************************************
350 * IShellFolder_ParseDisplayName {SHELL32}
352 * Parse a display name.
354 * PARAMS
355 * hwndOwner [in] Parent window for any message's
356 * pbc [in] optional FileSystemBindData context
357 * lpszDisplayName [in] Unicode displayname.
358 * pchEaten [out] (unicode) characters processed
359 * ppidl [out] complex pidl to item
360 * pdwAttributes [out] items attributes
362 * NOTES
363 * Every folder tries to parse only its own (the leftmost) pidl and creates a
364 * subfolder to evaluate the remaining parts.
365 * Now we can parse into namespaces implemented by shell extensions
367 * Behaviour on win98: lpszDisplayName=NULL -> crash
368 * lpszDisplayName="" -> returns mycoputer-pidl
370 * FIXME
371 * pdwAttributes is not set
372 * pchEaten is not set like in windows
374 static HRESULT WINAPI
375 IShellFolder_fnParseDisplayName (IShellFolder2 * iface,
376 HWND hwndOwner,
377 LPBC pbc,
378 LPOLESTR lpszDisplayName,
379 DWORD * pchEaten, LPITEMIDLIST * ppidl,
380 DWORD * pdwAttributes)
382 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
384 HRESULT hr = E_INVALIDARG;
385 LPCWSTR szNext = NULL;
386 WCHAR szElement[MAX_PATH];
387 WCHAR szPath[MAX_PATH];
388 LPITEMIDLIST pidlTemp = NULL;
389 DWORD len;
391 TRACE ("(%p)->(HWND=%p,%p,%p=%s,%p,pidl=%p,%p)\n",
392 This, hwndOwner, pbc, lpszDisplayName, debugstr_w (lpszDisplayName),
393 pchEaten, ppidl, pdwAttributes);
395 if (!lpszDisplayName || !ppidl)
396 return E_INVALIDARG;
398 if (pchEaten)
399 *pchEaten = 0; /* strange but like the original */
401 pidlTemp = SHELL32_CreatePidlFromBindCtx(pbc, lpszDisplayName);
402 if (!pidlTemp && *lpszDisplayName)
404 /* get the next element */
405 szNext = GetNextElementW (lpszDisplayName, szElement, MAX_PATH);
407 /* build the full pathname to the element */
408 /* lstrcpyW(szPath, This->sPathTarget); */
409 MultiByteToWideChar(CP_ACP, 0, This->sPathTarget, -1, szPath, MAX_PATH);
410 PathAddBackslashW(szPath);
411 len = lstrlenW(szPath);
412 lstrcpynW(szPath + len, szElement, MAX_PATH - len);
414 /* get the pidl */
415 hr = _ILCreateFromPathW(szPath, &pidlTemp);
417 if (SUCCEEDED(hr)) {
418 if (szNext && *szNext) {
419 /* try to analyse the next element */
420 hr = SHELL32_ParseNextElement (iface, hwndOwner, pbc,
421 &pidlTemp, (LPOLESTR) szNext, pchEaten, pdwAttributes);
422 } else {
423 /* it's the last element */
424 if (pdwAttributes && *pdwAttributes) {
425 hr = SHELL32_GetItemAttributes (_IShellFolder_ (This),
426 pidlTemp, pdwAttributes);
432 if (SUCCEEDED(hr))
433 *ppidl = pidlTemp;
434 else
435 *ppidl = NULL;
437 TRACE ("(%p)->(-- pidl=%p ret=0x%08lx)\n", This, ppidl ? *ppidl : 0, hr);
439 return hr;
442 /**************************************************************************
443 * IShellFolder_fnEnumObjects
444 * PARAMETERS
445 * HWND hwndOwner, //[in ] Parent Window
446 * DWORD grfFlags, //[in ] SHCONTF enumeration mask
447 * LPENUMIDLIST* ppenumIDList //[out] IEnumIDList interface
449 static HRESULT WINAPI
450 IShellFolder_fnEnumObjects (IShellFolder2 * iface, HWND hwndOwner,
451 DWORD dwFlags, LPENUMIDLIST * ppEnumIDList)
453 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
455 TRACE ("(%p)->(HWND=%p flags=0x%08lx pplist=%p)\n", This, hwndOwner,
456 dwFlags, ppEnumIDList);
458 *ppEnumIDList = IEnumIDList_Constructor();
459 if (*ppEnumIDList)
461 WCHAR path[MAX_PATH];
462 MultiByteToWideChar(CP_ACP, 0, This->sPathTarget, -1, path, MAX_PATH);
463 CreateFolderEnumList(*ppEnumIDList, path, dwFlags);
466 TRACE ("-- (%p)->(new ID List: %p)\n", This, *ppEnumIDList);
468 return *ppEnumIDList ? S_OK : E_OUTOFMEMORY;
471 /**************************************************************************
472 * IShellFolder_fnBindToObject
473 * PARAMETERS
474 * LPCITEMIDLIST pidl, //[in ] relative pidl to open
475 * LPBC pbc, //[in ] optional FileSystemBindData context
476 * REFIID riid, //[in ] Initial Interface
477 * LPVOID* ppvObject //[out] Interface*
479 static HRESULT WINAPI
480 IShellFolder_fnBindToObject (IShellFolder2 * iface, LPCITEMIDLIST pidl,
481 LPBC pbc, REFIID riid, LPVOID * ppvOut)
483 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
485 TRACE ("(%p)->(pidl=%p,%p,%s,%p)\n", This, pidl, pbc,
486 shdebugstr_guid (riid), ppvOut);
488 return SHELL32_BindToChild (This->pidlRoot, This->sPathTarget, pidl, riid,
489 ppvOut);
492 /**************************************************************************
493 * IShellFolder_fnBindToStorage
494 * PARAMETERS
495 * LPCITEMIDLIST pidl, //[in ] complex pidl to store
496 * LPBC pbc, //[in ] reserved
497 * REFIID riid, //[in ] Initial storage interface
498 * LPVOID* ppvObject //[out] Interface* returned
500 static HRESULT WINAPI
501 IShellFolder_fnBindToStorage (IShellFolder2 * iface, LPCITEMIDLIST pidl,
502 LPBC pbcReserved, REFIID riid, LPVOID * ppvOut)
504 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
506 FIXME ("(%p)->(pidl=%p,%p,%s,%p) stub\n", This, pidl, pbcReserved,
507 shdebugstr_guid (riid), ppvOut);
509 *ppvOut = NULL;
510 return E_NOTIMPL;
513 /**************************************************************************
514 * IShellFolder_fnCompareIDs
517 static HRESULT WINAPI
518 IShellFolder_fnCompareIDs (IShellFolder2 * iface, LPARAM lParam,
519 LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
521 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
523 int nReturn;
525 TRACE ("(%p)->(0x%08lx,pidl1=%p,pidl2=%p)\n", This, lParam, pidl1, pidl2);
526 nReturn = SHELL32_CompareIDs (_IShellFolder_ (This), lParam, pidl1, pidl2);
527 TRACE ("-- %i\n", nReturn);
528 return nReturn;
531 /**************************************************************************
532 * IShellFolder_fnCreateViewObject
534 static HRESULT WINAPI
535 IShellFolder_fnCreateViewObject (IShellFolder2 * iface, HWND hwndOwner,
536 REFIID riid, LPVOID * ppvOut)
538 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
540 LPSHELLVIEW pShellView;
541 HRESULT hr = E_INVALIDARG;
543 TRACE ("(%p)->(hwnd=%p,%s,%p)\n", This, hwndOwner, shdebugstr_guid (riid),
544 ppvOut);
546 if (ppvOut) {
547 *ppvOut = NULL;
549 if (IsEqualIID (riid, &IID_IDropTarget)) {
550 hr = IShellFolder_QueryInterface (iface, &IID_IDropTarget, ppvOut);
551 } else if (IsEqualIID (riid, &IID_IContextMenu)) {
552 FIXME ("IContextMenu not implemented\n");
553 hr = E_NOTIMPL;
554 } else if (IsEqualIID (riid, &IID_IShellView)) {
555 pShellView = IShellView_Constructor ((IShellFolder *) iface);
556 if (pShellView) {
557 hr = IShellView_QueryInterface (pShellView, riid, ppvOut);
558 IShellView_Release (pShellView);
562 TRACE ("-- (%p)->(interface=%p)\n", This, ppvOut);
563 return hr;
566 /**************************************************************************
567 * IShellFolder_fnGetAttributesOf
569 * PARAMETERS
570 * UINT cidl, //[in ] num elements in pidl array
571 * LPCITEMIDLIST* apidl, //[in ] simple pidl array
572 * ULONG* rgfInOut) //[out] result array
575 static HRESULT WINAPI
576 IShellFolder_fnGetAttributesOf (IShellFolder2 * iface, UINT cidl,
577 LPCITEMIDLIST * apidl, DWORD * rgfInOut)
579 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
581 HRESULT hr = S_OK;
583 TRACE ("(%p)->(cidl=%d apidl=%p mask=%p (0x%08lx))\n", This, cidl, apidl,
584 rgfInOut, rgfInOut ? *rgfInOut : 0);
586 if (!rgfInOut)
587 return E_INVALIDARG;
588 if (cidl && !apidl)
589 return E_INVALIDARG;
591 if (*rgfInOut == 0)
592 *rgfInOut = ~0;
594 if(cidl == 0){
595 IShellFolder *psfParent = NULL;
596 LPCITEMIDLIST rpidl = NULL;
598 hr = SHBindToParent(This->pidlRoot, &IID_IShellFolder, (LPVOID*)&psfParent, (LPCITEMIDLIST*)&rpidl);
599 if(SUCCEEDED(hr)) {
600 SHELL32_GetItemAttributes (psfParent, rpidl, rgfInOut);
601 IShellFolder_Release(psfParent);
604 else {
605 while (cidl > 0 && *apidl) {
606 pdump (*apidl);
607 SHELL32_GetItemAttributes (_IShellFolder_ (This), *apidl, rgfInOut);
608 apidl++;
609 cidl--;
612 /* make sure SFGAO_VALIDATE is cleared, some apps depend on that */
613 *rgfInOut &= ~SFGAO_VALIDATE;
615 TRACE ("-- result=0x%08lx\n", *rgfInOut);
617 return hr;
620 /**************************************************************************
621 * IShellFolder_fnGetUIObjectOf
623 * PARAMETERS
624 * HWND hwndOwner, //[in ] Parent window for any output
625 * UINT cidl, //[in ] array size
626 * LPCITEMIDLIST* apidl, //[in ] simple pidl array
627 * REFIID riid, //[in ] Requested Interface
628 * UINT* prgfInOut, //[ ] reserved
629 * LPVOID* ppvObject) //[out] Resulting Interface
631 * NOTES
632 * This function gets asked to return "view objects" for one or more (multiple
633 * select) items:
634 * The viewobject typically is an COM object with one of the following
635 * interfaces:
636 * IExtractIcon,IDataObject,IContextMenu
637 * In order to support icon positions in the default Listview your DataObject
638 * must implement the SetData method (in addition to GetData :) - the shell
639 * passes a barely documented "Icon positions" structure to SetData when the
640 * drag starts, and GetData's it if the drop is in another explorer window that
641 * needs the positions.
643 static HRESULT WINAPI
644 IShellFolder_fnGetUIObjectOf (IShellFolder2 * iface,
645 HWND hwndOwner,
646 UINT cidl, LPCITEMIDLIST * apidl, REFIID riid,
647 UINT * prgfInOut, LPVOID * ppvOut)
649 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
651 LPITEMIDLIST pidl;
652 IUnknown *pObj = NULL;
653 HRESULT hr = E_INVALIDARG;
655 TRACE ("(%p)->(%p,%u,apidl=%p,%s,%p,%p)\n",
656 This, hwndOwner, cidl, apidl, shdebugstr_guid (riid), prgfInOut, ppvOut);
658 if (ppvOut) {
659 *ppvOut = NULL;
661 if (IsEqualIID (riid, &IID_IContextMenu) && (cidl >= 1)) {
662 pObj = (LPUNKNOWN) ISvItemCm_Constructor ((IShellFolder *) iface,
663 This->pidlRoot, apidl, cidl);
664 hr = S_OK;
665 } else if (IsEqualIID (riid, &IID_IDataObject) && (cidl >= 1)) {
666 pObj = (LPUNKNOWN) IDataObject_Constructor (hwndOwner,
667 This->pidlRoot, apidl, cidl);
668 hr = S_OK;
669 } else if (IsEqualIID (riid, &IID_IExtractIconA) && (cidl == 1)) {
670 pidl = ILCombine (This->pidlRoot, apidl[0]);
671 pObj = (LPUNKNOWN) IExtractIconA_Constructor (pidl);
672 SHFree (pidl);
673 hr = S_OK;
674 } else if (IsEqualIID (riid, &IID_IExtractIconW) && (cidl == 1)) {
675 pidl = ILCombine (This->pidlRoot, apidl[0]);
676 pObj = (LPUNKNOWN) IExtractIconW_Constructor (pidl);
677 SHFree (pidl);
678 hr = S_OK;
679 } else if (IsEqualIID (riid, &IID_IDropTarget) && (cidl >= 1)) {
680 hr = IShellFolder_QueryInterface (iface, &IID_IDropTarget,
681 (LPVOID *) & pObj);
682 } else if ((IsEqualIID(riid,&IID_IShellLinkW) ||
683 IsEqualIID(riid,&IID_IShellLinkA)) && (cidl == 1)) {
684 pidl = ILCombine (This->pidlRoot, apidl[0]);
685 hr = IShellLink_ConstructFromFile(NULL, riid, pidl, (LPVOID*)&pObj);
686 SHFree (pidl);
687 } else {
688 hr = E_NOINTERFACE;
691 if (SUCCEEDED(hr) && !pObj)
692 hr = E_OUTOFMEMORY;
694 *ppvOut = pObj;
696 TRACE ("(%p)->hr=0x%08lx\n", This, hr);
697 return hr;
700 static const WCHAR AdvancedW[] = { 'S','O','F','T','W','A','R','E',
701 '\\','M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
702 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\','E','x','p','l',
703 'o','r','e','r','\\','A','d','v','a','n','c','e','d',0 };
704 static const WCHAR HideFileExtW[] = { 'H','i','d','e','F','i','l','e','E','x',
705 't',0 };
706 static const WCHAR NeverShowExtW[] = { 'N','e','v','e','r','S','h','o','w','E',
707 'x','t',0 };
709 /******************************************************************************
710 * SHELL_FS_HideExtension [Internal]
712 * Query the registry if the filename extension of a given path should be
713 * hidden.
715 * PARAMS
716 * szPath [I] Relative or absolute path of a file
718 * RETURNS
719 * TRUE, if the filename's extension should be hidden
720 * FALSE, otherwise.
722 BOOL SHELL_FS_HideExtension(LPWSTR szPath)
724 HKEY hKey;
725 DWORD dwData;
726 DWORD dwDataSize = sizeof (DWORD);
727 BOOL doHide = FALSE; /* The default value is FALSE (win98 at least) */
729 if (!RegCreateKeyExW(HKEY_CURRENT_USER, AdvancedW, 0, 0, 0, KEY_ALL_ACCESS, 0, &hKey, 0)) {
730 if (!RegQueryValueExW(hKey, HideFileExtW, 0, 0, (LPBYTE) &dwData, &dwDataSize))
731 doHide = dwData;
732 RegCloseKey (hKey);
735 if (!doHide) {
736 LPWSTR ext = PathFindExtensionW(szPath);
738 if (*ext != '\0') {
739 WCHAR classname[MAX_PATH];
740 LONG classlen = sizeof(classname);
742 if (!RegQueryValueW(HKEY_CLASSES_ROOT, ext, classname, &classlen))
743 if (!RegOpenKeyW(HKEY_CLASSES_ROOT, classname, &hKey)) {
744 if (!RegQueryValueExW(hKey, NeverShowExtW, 0, NULL, NULL, NULL))
745 doHide = TRUE;
746 RegCloseKey(hKey);
750 return doHide;
753 void SHELL_FS_ProcessDisplayFilename(LPSTR szPath, DWORD dwFlags)
755 WCHAR pathW[MAX_PATH];
757 /*FIXME: MSDN also mentions SHGDN_FOREDITING which is not yet handled. */
758 if (!(dwFlags & SHGDN_FORPARSING) &&
759 ((dwFlags & SHGDN_INFOLDER) || (dwFlags == SHGDN_NORMAL))) {
760 MultiByteToWideChar(CP_ACP, 0, szPath, -1, pathW, MAX_PATH);
761 if (SHELL_FS_HideExtension(pathW) && szPath[0] != '.')
762 PathRemoveExtensionA (szPath);
766 /**************************************************************************
767 * IShellFolder_fnGetDisplayNameOf
768 * Retrieves the display name for the specified file object or subfolder
770 * PARAMETERS
771 * LPCITEMIDLIST pidl, //[in ] complex pidl to item
772 * DWORD dwFlags, //[in ] SHGNO formatting flags
773 * LPSTRRET lpName) //[out] Returned display name
775 * FIXME
776 * if the name is in the pidl the ret value should be a STRRET_OFFSET
779 static HRESULT WINAPI
780 IShellFolder_fnGetDisplayNameOf (IShellFolder2 * iface, LPCITEMIDLIST pidl,
781 DWORD dwFlags, LPSTRRET strRet)
783 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
785 HRESULT hr = S_OK;
786 int len = 0;
788 TRACE ("(%p)->(pidl=%p,0x%08lx,%p)\n", This, pidl, dwFlags, strRet);
789 pdump (pidl);
791 if (!pidl || !strRet)
792 return E_INVALIDARG;
794 strRet->uType = STRRET_CSTR;
795 if (_ILIsDesktop(pidl)) { /* empty pidl */
796 if ((GET_SHGDN_FOR(dwFlags) & SHGDN_FORPARSING) &&
797 (GET_SHGDN_RELATION(dwFlags) != SHGDN_INFOLDER))
799 if (This->sPathTarget)
800 lstrcpynA(strRet->u.cStr, This->sPathTarget, MAX_PATH);
801 } else {
802 /* pidl has to contain exactly one non null SHITEMID */
803 hr = E_INVALIDARG;
805 } else if (_ILIsPidlSimple(pidl)) {
806 if ((GET_SHGDN_FOR(dwFlags) & SHGDN_FORPARSING) &&
807 (GET_SHGDN_RELATION(dwFlags) != SHGDN_INFOLDER) &&
808 This->sPathTarget)
810 lstrcpynA(strRet->u.cStr, This->sPathTarget, MAX_PATH);
811 PathAddBackslashA(strRet->u.cStr);
812 len = lstrlenA(strRet->u.cStr);
814 _ILSimpleGetText(pidl, strRet->u.cStr + len, MAX_PATH - len);
815 if (!_ILIsFolder(pidl)) SHELL_FS_ProcessDisplayFilename(strRet->u.cStr, dwFlags);
816 } else {
817 hr = SHELL32_GetDisplayNameOfChild(iface, pidl, dwFlags, strRet->u.cStr, MAX_PATH);
820 TRACE ("-- (%p)->(%s)\n", This, strRet->u.cStr);
821 return hr;
824 /**************************************************************************
825 * IShellFolder_fnSetNameOf
826 * Changes the name of a file object or subfolder, possibly changing its item
827 * identifier in the process.
829 * PARAMETERS
830 * HWND hwndOwner, //[in ] Owner window for output
831 * LPCITEMIDLIST pidl, //[in ] simple pidl of item to change
832 * LPCOLESTR lpszName, //[in ] the items new display name
833 * DWORD dwFlags, //[in ] SHGNO formatting flags
834 * LPITEMIDLIST* ppidlOut) //[out] simple pidl returned
836 static HRESULT WINAPI IShellFolder_fnSetNameOf (IShellFolder2 * iface,
837 HWND hwndOwner,
838 LPCITEMIDLIST pidl,
839 LPCOLESTR lpName,
840 DWORD dwFlags,
841 LPITEMIDLIST * pPidlOut)
843 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
844 WCHAR szSrc[MAX_PATH], szDest[MAX_PATH];
845 LPWSTR ptr;
846 BOOL bIsFolder = _ILIsFolder (ILFindLastID (pidl));
848 TRACE ("(%p)->(%p,pidl=%p,%s,%lu,%p)\n", This, hwndOwner, pidl,
849 debugstr_w (lpName), dwFlags, pPidlOut);
851 /* build source path */
852 MultiByteToWideChar(CP_ACP, 0, This->sPathTarget, -1, szSrc, MAX_PATH);
853 ptr = PathAddBackslashW (szSrc);
854 if (ptr)
855 _ILSimpleGetTextW (pidl, ptr, MAX_PATH - (ptr - szSrc));
857 /* build destination path */
858 if (dwFlags == SHGDN_NORMAL || dwFlags & SHGDN_INFOLDER) {
859 MultiByteToWideChar(CP_ACP, 0, This->sPathTarget, -1, szDest, MAX_PATH);
860 ptr = PathAddBackslashW (szDest);
861 if (ptr)
862 lstrcpynW(ptr, lpName, MAX_PATH - (ptr - szDest));
863 } else
864 lstrcpynW(szDest, lpName, MAX_PATH);
866 if(!(dwFlags & SHGDN_FORPARSING) && SHELL_FS_HideExtension(szSrc)) {
867 WCHAR *ext = PathFindExtensionW(szSrc);
868 if(*ext != '\0') {
869 INT len = strlenW(szDest);
870 lstrcpynW(szDest + len, ext, MAX_PATH - len);
874 TRACE ("src=%s dest=%s\n", debugstr_w(szSrc), debugstr_w(szDest));
876 if (MoveFileW (szSrc, szDest)) {
877 HRESULT hr = S_OK;
879 if (pPidlOut)
880 hr = _ILCreateFromPathW(szDest, pPidlOut);
882 SHChangeNotify (bIsFolder ? SHCNE_RENAMEFOLDER : SHCNE_RENAMEITEM,
883 SHCNF_PATHW, szSrc, szDest);
885 return hr;
888 return E_FAIL;
891 static HRESULT WINAPI IShellFolder_fnGetDefaultSearchGUID (IShellFolder2 *iface,
892 GUID * pguid)
894 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
895 FIXME ("(%p)\n", This);
896 return E_NOTIMPL;
898 static HRESULT WINAPI IShellFolder_fnEnumSearches (IShellFolder2 * iface,
899 IEnumExtraSearch ** ppenum)
901 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
902 FIXME ("(%p)\n", This);
903 return E_NOTIMPL;
906 static HRESULT WINAPI
907 IShellFolder_fnGetDefaultColumn (IShellFolder2 * iface, DWORD dwRes,
908 ULONG * pSort, ULONG * pDisplay)
910 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
912 TRACE ("(%p)\n", This);
914 if (pSort)
915 *pSort = 0;
916 if (pDisplay)
917 *pDisplay = 0;
919 return S_OK;
922 static HRESULT WINAPI
923 IShellFolder_fnGetDefaultColumnState (IShellFolder2 * iface, UINT iColumn,
924 DWORD * pcsFlags)
926 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
928 TRACE ("(%p)\n", This);
930 if (!pcsFlags || iColumn >= GENERICSHELLVIEWCOLUMNS)
931 return E_INVALIDARG;
933 *pcsFlags = GenericSFHeader[iColumn].pcsFlags;
935 return S_OK;
938 static HRESULT WINAPI
939 IShellFolder_fnGetDetailsEx (IShellFolder2 * iface, LPCITEMIDLIST pidl,
940 const SHCOLUMNID * pscid, VARIANT * pv)
942 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
943 FIXME ("(%p)\n", This);
945 return E_NOTIMPL;
948 static HRESULT WINAPI
949 IShellFolder_fnGetDetailsOf (IShellFolder2 * iface, LPCITEMIDLIST pidl,
950 UINT iColumn, SHELLDETAILS * psd)
952 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
953 HRESULT hr = E_FAIL;
955 TRACE ("(%p)->(%p %i %p)\n", This, pidl, iColumn, psd);
957 if (!psd || iColumn >= GENERICSHELLVIEWCOLUMNS)
958 return E_INVALIDARG;
960 if (!pidl) {
961 /* the header titles */
962 psd->fmt = GenericSFHeader[iColumn].fmt;
963 psd->cxChar = GenericSFHeader[iColumn].cxChar;
964 psd->str.uType = STRRET_CSTR;
965 LoadStringA (shell32_hInstance, GenericSFHeader[iColumn].colnameid,
966 psd->str.u.cStr, MAX_PATH);
967 return S_OK;
968 } else {
969 /* the data from the pidl */
970 switch (iColumn) {
971 case 0: /* name */
972 hr = IShellFolder_GetDisplayNameOf (iface, pidl,
973 SHGDN_NORMAL | SHGDN_INFOLDER, &psd->str);
974 break;
975 case 1: /* size */
976 _ILGetFileSize (pidl, psd->str.u.cStr, MAX_PATH);
977 break;
978 case 2: /* type */
979 _ILGetFileType (pidl, psd->str.u.cStr, MAX_PATH);
980 break;
981 case 3: /* date */
982 _ILGetFileDate (pidl, psd->str.u.cStr, MAX_PATH);
983 break;
984 case 4: /* attributes */
985 _ILGetFileAttributes (pidl, psd->str.u.cStr, MAX_PATH);
986 break;
988 hr = S_OK;
989 psd->str.uType = STRRET_CSTR;
992 return hr;
995 static HRESULT WINAPI
996 IShellFolder_fnMapColumnToSCID (IShellFolder2 * iface, UINT column,
997 SHCOLUMNID * pscid)
999 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
1000 FIXME ("(%p)\n", This);
1001 return E_NOTIMPL;
1004 static const IShellFolder2Vtbl sfvt =
1006 IShellFolder_fnQueryInterface,
1007 IShellFolder_fnAddRef,
1008 IShellFolder_fnRelease,
1009 IShellFolder_fnParseDisplayName,
1010 IShellFolder_fnEnumObjects,
1011 IShellFolder_fnBindToObject,
1012 IShellFolder_fnBindToStorage,
1013 IShellFolder_fnCompareIDs,
1014 IShellFolder_fnCreateViewObject,
1015 IShellFolder_fnGetAttributesOf,
1016 IShellFolder_fnGetUIObjectOf,
1017 IShellFolder_fnGetDisplayNameOf,
1018 IShellFolder_fnSetNameOf,
1019 /* ShellFolder2 */
1020 IShellFolder_fnGetDefaultSearchGUID,
1021 IShellFolder_fnEnumSearches,
1022 IShellFolder_fnGetDefaultColumn,
1023 IShellFolder_fnGetDefaultColumnState,
1024 IShellFolder_fnGetDetailsEx,
1025 IShellFolder_fnGetDetailsOf,
1026 IShellFolder_fnMapColumnToSCID
1029 /****************************************************************************
1030 * ISFHelper for IShellFolder implementation
1033 static HRESULT WINAPI
1034 ISFHelper_fnQueryInterface (ISFHelper * iface, REFIID riid, LPVOID * ppvObj)
1036 IGenericSFImpl *This = impl_from_ISFHelper(iface);
1038 TRACE ("(%p)->(count=%lu)\n", This, This->ref);
1040 return IUnknown_QueryInterface (This->pUnkOuter, riid, ppvObj);
1043 static ULONG WINAPI ISFHelper_fnAddRef (ISFHelper * iface)
1045 IGenericSFImpl *This = impl_from_ISFHelper(iface);
1047 TRACE ("(%p)->(count=%lu)\n", This, This->ref);
1049 return IUnknown_AddRef (This->pUnkOuter);
1052 static ULONG WINAPI ISFHelper_fnRelease (ISFHelper * iface)
1054 IGenericSFImpl *This = impl_from_ISFHelper(iface);
1056 TRACE ("(%p)\n", This);
1058 return IUnknown_Release (This->pUnkOuter);
1061 /****************************************************************************
1062 * ISFHelper_fnAddFolder
1064 * creates a unique folder name
1067 static HRESULT WINAPI
1068 ISFHelper_fnGetUniqueName (ISFHelper * iface, LPSTR lpName, UINT uLen)
1070 IGenericSFImpl *This = impl_from_ISFHelper(iface);
1071 IEnumIDList *penum;
1072 HRESULT hr;
1073 char szText[MAX_PATH];
1074 const char *szNewFolder = "New Folder";
1076 TRACE ("(%p)(%s %u)\n", This, lpName, uLen);
1078 if (uLen < strlen (szNewFolder) + 4)
1079 return E_POINTER;
1081 strcpy (lpName, szNewFolder);
1083 hr = IShellFolder_fnEnumObjects (_IShellFolder2_ (This), 0,
1084 SHCONTF_FOLDERS | SHCONTF_NONFOLDERS | SHCONTF_INCLUDEHIDDEN, &penum);
1085 if (penum) {
1086 LPITEMIDLIST pidl;
1087 DWORD dwFetched;
1088 int i = 1;
1090 next:
1091 IEnumIDList_Reset (penum);
1092 while (S_OK == IEnumIDList_Next (penum, 1, &pidl, &dwFetched) &&
1093 dwFetched) {
1094 _ILSimpleGetText (pidl, szText, MAX_PATH);
1095 if (0 == strcasecmp (szText, lpName)) {
1096 sprintf (lpName, "%s %d", szNewFolder, i++);
1097 if (i > 99) {
1098 hr = E_FAIL;
1099 break;
1101 goto next;
1105 IEnumIDList_Release (penum);
1107 return hr;
1110 /****************************************************************************
1111 * ISFHelper_fnAddFolder
1113 * adds a new folder.
1116 static HRESULT WINAPI
1117 ISFHelper_fnAddFolder (ISFHelper * iface, HWND hwnd, LPCSTR lpName,
1118 LPITEMIDLIST * ppidlOut)
1120 IGenericSFImpl *This = impl_from_ISFHelper(iface);
1121 char lpstrNewDir[MAX_PATH];
1122 DWORD bRes;
1123 HRESULT hres = E_FAIL;
1125 TRACE ("(%p)(%s %p)\n", This, lpName, ppidlOut);
1127 strcpy (lpstrNewDir, This->sPathTarget);
1128 PathAppendA(lpstrNewDir, lpName);
1130 bRes = CreateDirectoryA (lpstrNewDir, NULL);
1131 if (bRes) {
1132 SHChangeNotify (SHCNE_MKDIR, SHCNF_PATHA, lpstrNewDir, NULL);
1134 hres = S_OK;
1136 if (ppidlOut)
1137 hres = _ILCreateFromPathA(lpstrNewDir, ppidlOut);
1138 } else {
1139 char lpstrText[128 + MAX_PATH];
1140 char lpstrTempText[128];
1141 char lpstrCaption[256];
1143 /* Cannot Create folder because of permissions */
1144 LoadStringA (shell32_hInstance, IDS_CREATEFOLDER_DENIED, lpstrTempText,
1145 sizeof (lpstrTempText));
1146 LoadStringA (shell32_hInstance, IDS_CREATEFOLDER_CAPTION, lpstrCaption,
1147 sizeof (lpstrCaption));
1148 sprintf (lpstrText, lpstrTempText, lpstrNewDir);
1149 MessageBoxA (hwnd, lpstrText, lpstrCaption, MB_OK | MB_ICONEXCLAMATION);
1152 return hres;
1155 /****************************************************************************
1156 * ISFHelper_fnDeleteItems
1158 * deletes items in folder
1160 static HRESULT WINAPI
1161 ISFHelper_fnDeleteItems (ISFHelper * iface, UINT cidl, LPCITEMIDLIST * apidl)
1163 IGenericSFImpl *This = impl_from_ISFHelper(iface);
1164 UINT i;
1165 char szPath[MAX_PATH];
1166 BOOL bConfirm = TRUE;
1168 TRACE ("(%p)(%u %p)\n", This, cidl, apidl);
1170 /* deleting multiple items so give a slightly different warning */
1171 if (cidl != 1) {
1172 char tmp[8];
1174 snprintf (tmp, sizeof (tmp), "%d", cidl);
1175 if (!SHELL_ConfirmDialog(ASK_DELETE_MULTIPLE_ITEM, tmp))
1176 return E_FAIL;
1177 bConfirm = FALSE;
1180 for (i = 0; i < cidl; i++) {
1181 strcpy (szPath, This->sPathTarget);
1182 PathAddBackslashA (szPath);
1183 _ILSimpleGetText (apidl[i], szPath + strlen (szPath), MAX_PATH);
1185 if (_ILIsFolder (apidl[i])) {
1186 LPITEMIDLIST pidl;
1188 TRACE ("delete %s\n", szPath);
1189 if (!SHELL_DeleteDirectoryA (szPath, bConfirm)) {
1190 TRACE ("delete %s failed, bConfirm=%d\n", szPath, bConfirm);
1191 return E_FAIL;
1193 pidl = ILCombine (This->pidlRoot, apidl[i]);
1194 SHChangeNotify (SHCNE_RMDIR, SHCNF_IDLIST, pidl, NULL);
1195 SHFree (pidl);
1196 } else if (_ILIsValue (apidl[i])) {
1197 LPITEMIDLIST pidl;
1199 TRACE ("delete %s\n", szPath);
1200 if (!SHELL_DeleteFileA (szPath, bConfirm)) {
1201 TRACE ("delete %s failed, bConfirm=%d\n", szPath, bConfirm);
1202 return E_FAIL;
1204 pidl = ILCombine (This->pidlRoot, apidl[i]);
1205 SHChangeNotify (SHCNE_DELETE, SHCNF_IDLIST, pidl, NULL);
1206 SHFree (pidl);
1210 return S_OK;
1213 /****************************************************************************
1214 * ISFHelper_fnCopyItems
1216 * copies items to this folder
1218 static HRESULT WINAPI
1219 ISFHelper_fnCopyItems (ISFHelper * iface, IShellFolder * pSFFrom, UINT cidl,
1220 LPCITEMIDLIST * apidl)
1222 UINT i;
1223 IPersistFolder2 *ppf2 = NULL;
1224 char szSrcPath[MAX_PATH],
1225 szDstPath[MAX_PATH];
1227 IGenericSFImpl *This = impl_from_ISFHelper(iface);
1229 TRACE ("(%p)->(%p,%u,%p)\n", This, pSFFrom, cidl, apidl);
1231 IShellFolder_QueryInterface (pSFFrom, &IID_IPersistFolder2,
1232 (LPVOID *) & ppf2);
1233 if (ppf2) {
1234 LPITEMIDLIST pidl;
1236 if (SUCCEEDED (IPersistFolder2_GetCurFolder (ppf2, &pidl))) {
1237 for (i = 0; i < cidl; i++) {
1238 SHGetPathFromIDListA (pidl, szSrcPath);
1239 PathAddBackslashA (szSrcPath);
1240 _ILSimpleGetText (apidl[i], szSrcPath + strlen (szSrcPath),
1241 MAX_PATH);
1243 strcpy (szDstPath, This->sPathTarget);
1244 PathAddBackslashA (szDstPath);
1245 _ILSimpleGetText (apidl[i], szDstPath + strlen (szDstPath),
1246 MAX_PATH);
1247 MESSAGE ("would copy %s to %s\n", szSrcPath, szDstPath);
1249 SHFree (pidl);
1251 IPersistFolder2_Release (ppf2);
1253 return S_OK;
1256 static const ISFHelperVtbl shvt =
1258 ISFHelper_fnQueryInterface,
1259 ISFHelper_fnAddRef,
1260 ISFHelper_fnRelease,
1261 ISFHelper_fnGetUniqueName,
1262 ISFHelper_fnAddFolder,
1263 ISFHelper_fnDeleteItems,
1264 ISFHelper_fnCopyItems
1267 /************************************************************************
1268 * IFSFldr_PersistFolder3_QueryInterface
1271 static HRESULT WINAPI
1272 IFSFldr_PersistFolder3_QueryInterface (IPersistFolder3 * iface, REFIID iid,
1273 LPVOID * ppvObj)
1275 IGenericSFImpl *This = impl_from_IPersistFolder3(iface);
1277 TRACE ("(%p)\n", This);
1279 return IUnknown_QueryInterface (This->pUnkOuter, iid, ppvObj);
1282 /************************************************************************
1283 * IFSFldr_PersistFolder3_AddRef
1286 static ULONG WINAPI
1287 IFSFldr_PersistFolder3_AddRef (IPersistFolder3 * iface)
1289 IGenericSFImpl *This = impl_from_IPersistFolder3(iface);
1291 TRACE ("(%p)->(count=%lu)\n", This, This->ref);
1293 return IUnknown_AddRef (This->pUnkOuter);
1296 /************************************************************************
1297 * IFSFldr_PersistFolder3_Release
1300 static ULONG WINAPI
1301 IFSFldr_PersistFolder3_Release (IPersistFolder3 * iface)
1303 IGenericSFImpl *This = impl_from_IPersistFolder3(iface);
1305 TRACE ("(%p)->(count=%lu)\n", This, This->ref);
1307 return IUnknown_Release (This->pUnkOuter);
1310 /************************************************************************
1311 * IFSFldr_PersistFolder3_GetClassID
1313 static HRESULT WINAPI
1314 IFSFldr_PersistFolder3_GetClassID (IPersistFolder3 * iface, CLSID * lpClassId)
1316 IGenericSFImpl *This = impl_from_IPersistFolder3(iface);
1318 TRACE ("(%p)\n", This);
1320 if (!lpClassId)
1321 return E_POINTER;
1322 *lpClassId = *This->pclsid;
1324 return S_OK;
1327 /************************************************************************
1328 * IFSFldr_PersistFolder3_Initialize
1330 * NOTES
1331 * sPathTarget is not set. Don't know how to handle in a non rooted environment.
1333 static HRESULT WINAPI
1334 IFSFldr_PersistFolder3_Initialize (IPersistFolder3 * iface, LPCITEMIDLIST pidl)
1336 char sTemp[MAX_PATH];
1338 IGenericSFImpl *This = impl_from_IPersistFolder3(iface);
1340 TRACE ("(%p)->(%p)\n", This, pidl);
1342 if (This->pidlRoot)
1343 SHFree (This->pidlRoot); /* free the old pidl */
1344 This->pidlRoot = ILClone (pidl); /* set my pidl */
1346 if (This->sPathTarget)
1347 SHFree (This->sPathTarget);
1349 /* set my path */
1350 if (SHGetPathFromIDListA (pidl, sTemp)) {
1351 This->sPathTarget = SHAlloc (strlen (sTemp) + 1);
1352 strcpy (This->sPathTarget, sTemp);
1355 TRACE ("--(%p)->(%s)\n", This, This->sPathTarget);
1356 return S_OK;
1359 /**************************************************************************
1360 * IFSFldr_PersistFolder3_GetCurFolder
1362 static HRESULT WINAPI
1363 IFSFldr_PersistFolder3_fnGetCurFolder (IPersistFolder3 * iface,
1364 LPITEMIDLIST * pidl)
1366 IGenericSFImpl *This = impl_from_IPersistFolder3(iface);
1368 TRACE ("(%p)->(%p)\n", This, pidl);
1370 if (!pidl) return E_POINTER;
1371 *pidl = ILClone (This->pidlRoot);
1372 return S_OK;
1375 /**************************************************************************
1376 * IFSFldr_PersistFolder3_InitializeEx
1378 * FIXME: error handling
1380 static HRESULT WINAPI
1381 IFSFldr_PersistFolder3_InitializeEx (IPersistFolder3 * iface,
1382 IBindCtx * pbc, LPCITEMIDLIST pidlRoot,
1383 const PERSIST_FOLDER_TARGET_INFO * ppfti)
1385 char sTemp[MAX_PATH];
1387 IGenericSFImpl *This = impl_from_IPersistFolder3(iface);
1389 TRACE ("(%p)->(%p,%p,%p)\n", This, pbc, pidlRoot, ppfti);
1390 if (ppfti)
1391 TRACE ("--%p %s %s 0x%08lx 0x%08x\n",
1392 ppfti->pidlTargetFolder, debugstr_w (ppfti->szTargetParsingName),
1393 debugstr_w (ppfti->szNetworkProvider), ppfti->dwAttributes,
1394 ppfti->csidl);
1396 pdump (pidlRoot);
1397 if (ppfti && ppfti->pidlTargetFolder)
1398 pdump (ppfti->pidlTargetFolder);
1400 if (This->pidlRoot)
1401 __SHFreeAndNil (&This->pidlRoot); /* free the old */
1402 if (This->sPathTarget)
1403 __SHFreeAndNil (&This->sPathTarget);
1406 * Root path and pidl
1408 This->pidlRoot = ILClone (pidlRoot);
1411 * the target folder is spezified in csidl OR pidlTargetFolder OR
1412 * szTargetParsingName
1414 if (ppfti) {
1415 if (ppfti->csidl != -1) {
1416 if (SHGetSpecialFolderPathA (0, sTemp, ppfti->csidl,
1417 ppfti->csidl & CSIDL_FLAG_CREATE)) {
1418 __SHCloneStrA (&This->sPathTarget, sTemp);
1420 } else if (ppfti->szTargetParsingName[0]) {
1421 __SHCloneStrWtoA (&This->sPathTarget, ppfti->szTargetParsingName);
1422 } else if (ppfti->pidlTargetFolder) {
1423 if (SHGetPathFromIDListA (ppfti->pidlTargetFolder, sTemp)) {
1424 __SHCloneStrA (&This->sPathTarget, sTemp);
1429 TRACE ("--(%p)->(target=%s)\n", This, debugstr_a (This->sPathTarget));
1430 pdump (This->pidlRoot);
1431 return (This->sPathTarget) ? S_OK : E_FAIL;
1434 static HRESULT WINAPI
1435 IFSFldr_PersistFolder3_GetFolderTargetInfo (IPersistFolder3 * iface,
1436 PERSIST_FOLDER_TARGET_INFO * ppfti)
1438 IGenericSFImpl *This = impl_from_IPersistFolder3(iface);
1439 FIXME ("(%p)->(%p)\n", This, ppfti);
1440 ZeroMemory (ppfti, sizeof (ppfti));
1441 return E_NOTIMPL;
1444 static const IPersistFolder3Vtbl vt_FSFldr_PersistFolder3 =
1446 IFSFldr_PersistFolder3_QueryInterface,
1447 IFSFldr_PersistFolder3_AddRef,
1448 IFSFldr_PersistFolder3_Release,
1449 IFSFldr_PersistFolder3_GetClassID,
1450 IFSFldr_PersistFolder3_Initialize,
1451 IFSFldr_PersistFolder3_fnGetCurFolder,
1452 IFSFldr_PersistFolder3_InitializeEx,
1453 IFSFldr_PersistFolder3_GetFolderTargetInfo
1456 /****************************************************************************
1457 * ISFDropTarget implementation
1459 static BOOL
1460 ISFDropTarget_QueryDrop (IDropTarget * iface, DWORD dwKeyState,
1461 LPDWORD pdwEffect)
1463 DWORD dwEffect = *pdwEffect;
1465 IGenericSFImpl *This = impl_from_IDropTarget(iface);
1467 *pdwEffect = DROPEFFECT_NONE;
1469 if (This->fAcceptFmt) { /* Does our interpretation of the keystate ... */
1470 *pdwEffect = KeyStateToDropEffect (dwKeyState);
1472 /* ... matches the desired effect ? */
1473 if (dwEffect & *pdwEffect) {
1474 return TRUE;
1477 return FALSE;
1480 static HRESULT WINAPI
1481 ISFDropTarget_QueryInterface (IDropTarget * iface, REFIID riid, LPVOID * ppvObj)
1483 IGenericSFImpl *This = impl_from_IDropTarget(iface);
1485 TRACE ("(%p)\n", This);
1487 return IUnknown_QueryInterface (This->pUnkOuter, riid, ppvObj);
1490 static ULONG WINAPI ISFDropTarget_AddRef (IDropTarget * iface)
1492 IGenericSFImpl *This = impl_from_IDropTarget(iface);
1494 TRACE ("(%p)\n", This);
1496 return IUnknown_AddRef (This->pUnkOuter);
1499 static ULONG WINAPI ISFDropTarget_Release (IDropTarget * iface)
1501 IGenericSFImpl *This = impl_from_IDropTarget(iface);
1503 TRACE ("(%p)\n", This);
1505 return IUnknown_Release (This->pUnkOuter);
1508 static HRESULT WINAPI
1509 ISFDropTarget_DragEnter (IDropTarget * iface, IDataObject * pDataObject,
1510 DWORD dwKeyState, POINTL pt, DWORD * pdwEffect)
1512 FORMATETC fmt;
1514 IGenericSFImpl *This = impl_from_IDropTarget(iface);
1516 TRACE ("(%p)->(DataObject=%p)\n", This, pDataObject);
1518 InitFormatEtc (fmt, This->cfShellIDList, TYMED_HGLOBAL);
1520 This->fAcceptFmt = (S_OK == IDataObject_QueryGetData (pDataObject, &fmt)) ?
1521 TRUE : FALSE;
1523 ISFDropTarget_QueryDrop (iface, dwKeyState, pdwEffect);
1525 return S_OK;
1528 static HRESULT WINAPI
1529 ISFDropTarget_DragOver (IDropTarget * iface, DWORD dwKeyState, POINTL pt,
1530 DWORD * pdwEffect)
1532 IGenericSFImpl *This = impl_from_IDropTarget(iface);
1534 TRACE ("(%p)\n", This);
1536 if (!pdwEffect)
1537 return E_INVALIDARG;
1539 ISFDropTarget_QueryDrop (iface, dwKeyState, pdwEffect);
1541 return S_OK;
1544 static HRESULT WINAPI ISFDropTarget_DragLeave (IDropTarget * iface)
1546 IGenericSFImpl *This = impl_from_IDropTarget(iface);
1548 TRACE ("(%p)\n", This);
1550 This->fAcceptFmt = FALSE;
1552 return S_OK;
1555 static HRESULT WINAPI
1556 ISFDropTarget_Drop (IDropTarget * iface, IDataObject * pDataObject,
1557 DWORD dwKeyState, POINTL pt, DWORD * pdwEffect)
1559 IGenericSFImpl *This = impl_from_IDropTarget(iface);
1561 FIXME ("(%p) object dropped\n", This);
1563 return E_NOTIMPL;
1566 static const IDropTargetVtbl dtvt = {
1567 ISFDropTarget_QueryInterface,
1568 ISFDropTarget_AddRef,
1569 ISFDropTarget_Release,
1570 ISFDropTarget_DragEnter,
1571 ISFDropTarget_DragOver,
1572 ISFDropTarget_DragLeave,
1573 ISFDropTarget_Drop