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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "wine/port.h"
32 #define NONAMELESSUNION
45 #include "undocshell.h"
46 #include "shell32_main.h"
49 #include "shellfolder.h"
50 #include "wine/debug.h"
54 WINE_DEFAULT_DEBUG_CHANNEL (shell
);
56 /***********************************************************************
57 * IShellFolder implementation
61 IUnknown IUnknown_inner
;
63 IShellFolder2 IShellFolder2_iface
;
64 IPersistFolder3 IPersistFolder3_iface
;
65 IDropTarget IDropTarget_iface
;
66 ISFHelper ISFHelper_iface
;
71 /* both paths are parsible from the desktop */
72 LPWSTR sPathTarget
; /* complete path to target used for enumeration and ChangeNotify */
74 LPITEMIDLIST pidlRoot
; /* absolute pidl */
76 UINT cfShellIDList
; /* clipboardformat for IDropTarget */
77 BOOL fAcceptFmt
; /* flag for pending Drop */
80 static inline IGenericSFImpl
*impl_from_IUnknown(IUnknown
*iface
)
82 return CONTAINING_RECORD(iface
, IGenericSFImpl
, IUnknown_inner
);
85 static inline IGenericSFImpl
*impl_from_IShellFolder2(IShellFolder2
*iface
)
87 return CONTAINING_RECORD(iface
, IGenericSFImpl
, IShellFolder2_iface
);
90 static inline IGenericSFImpl
*impl_from_IPersistFolder3(IPersistFolder3
*iface
)
92 return CONTAINING_RECORD(iface
, IGenericSFImpl
, IPersistFolder3_iface
);
95 static inline IGenericSFImpl
*impl_from_IDropTarget(IDropTarget
*iface
)
97 return CONTAINING_RECORD(iface
, IGenericSFImpl
, IDropTarget_iface
);
100 static inline IGenericSFImpl
*impl_from_ISFHelper(ISFHelper
*iface
)
102 return CONTAINING_RECORD(iface
, IGenericSFImpl
, ISFHelper_iface
);
105 /**************************************************************************
106 * registers clipboardformat once
108 static void SF_RegisterClipFmt (IGenericSFImpl
* This
)
110 TRACE ("(%p)\n", This
);
112 if (!This
->cfShellIDList
) {
113 This
->cfShellIDList
= RegisterClipboardFormatW (CFSTR_SHELLIDLISTW
);
117 /**************************************************************************
120 static HRESULT WINAPI
IUnknown_fnQueryInterface(IUnknown
*iface
, REFIID riid
, void **ppvObj
)
122 IGenericSFImpl
*This
= impl_from_IUnknown(iface
);
124 TRACE("(%p)->(%s,%p)\n", This
, shdebugstr_guid(riid
), ppvObj
);
128 if (IsEqualIID (riid
, &IID_IUnknown
))
129 *ppvObj
= &This
->IUnknown_inner
;
130 else if (IsEqualIID(riid
, &IID_IShellFolder
) || IsEqualIID(riid
, &IID_IShellFolder2
))
131 *ppvObj
= &This
->IShellFolder2_iface
;
132 else if (IsEqualIID(riid
, &IID_IPersist
) || IsEqualIID(riid
, &IID_IPersistFolder
) ||
133 IsEqualIID(riid
, &IID_IPersistFolder2
) || IsEqualIID(riid
, &IID_IPersistFolder3
))
134 *ppvObj
= &This
->IPersistFolder3_iface
;
135 else if (IsEqualIID (riid
, &IID_ISFHelper
))
136 *ppvObj
= &This
->ISFHelper_iface
;
137 else if (IsEqualIID (riid
, &IID_IDropTarget
)) {
138 *ppvObj
= &This
->IDropTarget_iface
;
139 SF_RegisterClipFmt(This
);
143 IUnknown_AddRef((IUnknown
*)*ppvObj
);
144 TRACE ("-- Interface = %p\n", *ppvObj
);
147 TRACE ("-- Interface: E_NOINTERFACE\n");
148 return E_NOINTERFACE
;
151 static ULONG WINAPI
IUnknown_fnAddRef(IUnknown
*iface
)
153 IGenericSFImpl
*This
= impl_from_IUnknown(iface
);
154 ULONG ref
= InterlockedIncrement(&This
->ref
);
156 TRACE("(%p) ref=%d\n", This
, ref
);
161 static ULONG WINAPI
IUnknown_fnRelease(IUnknown
*iface
)
163 IGenericSFImpl
*This
= impl_from_IUnknown(iface
);
164 ULONG ref
= InterlockedDecrement(&This
->ref
);
166 TRACE("(%p) ref=%d\n", This
, ref
);
169 TRACE("-- destroying IShellFolder(%p)\n", This
);
171 SHFree(This
->pidlRoot
);
172 SHFree(This
->sPathTarget
);
178 static const IUnknownVtbl unkvt
=
180 IUnknown_fnQueryInterface
,
185 static const shvheader GenericSFHeader
[] =
187 { &FMTID_Storage
, PID_STG_NAME
, IDS_SHV_COLUMN1
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 15 },
188 { &FMTID_Storage
, PID_STG_SIZE
, IDS_SHV_COLUMN2
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 10 },
189 { &FMTID_Storage
, PID_STG_STORAGETYPE
, IDS_SHV_COLUMN3
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 10 },
190 { &FMTID_Storage
, PID_STG_WRITETIME
, IDS_SHV_COLUMN4
, SHCOLSTATE_TYPE_DATE
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 12 },
191 { &FMTID_Storage
, PID_STG_ATTRIBUTES
, IDS_SHV_COLUMN5
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 5 },
194 #define GENERICSHELLVIEWCOLUMNS 5
196 /**************************************************************************
197 * IShellFolder_fnQueryInterface
199 static HRESULT WINAPI
IShellFolder_fnQueryInterface(IShellFolder2
*iface
, REFIID riid
,
202 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
204 return IUnknown_QueryInterface(This
->outer_unk
, riid
, ppvObj
);
207 /**************************************************************************
208 * IShellFolder_AddRef
210 static ULONG WINAPI
IShellFolder_fnAddRef(IShellFolder2
*iface
)
212 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
214 return IUnknown_AddRef(This
->outer_unk
);
217 /**************************************************************************
218 * IShellFolder_fnRelease
220 static ULONG WINAPI
IShellFolder_fnRelease(IShellFolder2
*iface
)
222 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
224 return IUnknown_Release(This
->outer_unk
);
227 /**************************************************************************
228 * SHELL32_CreatePidlFromBindCtx [internal]
230 * If the caller bound File System Bind Data, assume it is the
231 * find data for the path.
232 * This allows binding of paths that don't exist.
234 LPITEMIDLIST
SHELL32_CreatePidlFromBindCtx(IBindCtx
*pbc
, LPCWSTR path
)
236 static WCHAR szfsbc
[] = {
237 'F','i','l','e',' ','S','y','s','t','e','m',' ',
238 'B','i','n','d',' ','D','a','t','a',0 };
239 IFileSystemBindData
*fsbd
= NULL
;
240 LPITEMIDLIST pidl
= NULL
;
241 IUnknown
*unk
= NULL
;
244 TRACE("%p %s\n", pbc
, debugstr_w(path
));
249 /* see if the caller bound File System Bind Data */
250 r
= IBindCtx_GetObjectParam( pbc
, szfsbc
, &unk
);
254 r
= IUnknown_QueryInterface( unk
, &IID_IFileSystemBindData
, (void**)&fsbd
);
257 WIN32_FIND_DATAW wfd
;
259 r
= IFileSystemBindData_GetFindData( fsbd
, &wfd
);
262 lstrcpynW( &wfd
.cFileName
[0], path
, MAX_PATH
);
263 pidl
= _ILCreateFromFindDataW( &wfd
);
265 IFileSystemBindData_Release( fsbd
);
267 IUnknown_Release( unk
);
272 /**************************************************************************
273 * IShellFolder_ParseDisplayName {SHELL32}
275 * Parse a display name.
278 * hwndOwner [in] Parent window for any message's
279 * pbc [in] optional FileSystemBindData context
280 * lpszDisplayName [in] Unicode displayname.
281 * pchEaten [out] (unicode) characters processed
282 * ppidl [out] complex pidl to item
283 * pdwAttributes [out] items attributes
286 * Every folder tries to parse only its own (the leftmost) pidl and creates a
287 * subfolder to evaluate the remaining parts.
288 * Now we can parse into namespaces implemented by shell extensions
290 * Behaviour on win98: lpszDisplayName=NULL -> crash
291 * lpszDisplayName="" -> returns mycomputer-pidl
294 * pdwAttributes is not set
295 * pchEaten is not set like in windows
297 static HRESULT WINAPI
298 IShellFolder_fnParseDisplayName (IShellFolder2
* iface
,
301 LPOLESTR lpszDisplayName
,
302 DWORD
* pchEaten
, LPITEMIDLIST
* ppidl
,
303 DWORD
* pdwAttributes
)
305 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
307 HRESULT hr
= E_INVALIDARG
;
308 LPCWSTR szNext
= NULL
;
309 WCHAR szElement
[MAX_PATH
];
310 WCHAR szPath
[MAX_PATH
];
311 LPITEMIDLIST pidlTemp
= NULL
;
314 TRACE ("(%p)->(HWND=%p,%p,%p=%s,%p,pidl=%p,%p)\n",
315 This
, hwndOwner
, pbc
, lpszDisplayName
, debugstr_w (lpszDisplayName
),
316 pchEaten
, ppidl
, pdwAttributes
);
318 if (!lpszDisplayName
|| !ppidl
)
322 *pchEaten
= 0; /* strange but like the original */
324 pidlTemp
= SHELL32_CreatePidlFromBindCtx(pbc
, lpszDisplayName
);
325 if (!pidlTemp
&& *lpszDisplayName
)
327 /* get the next element */
328 szNext
= GetNextElementW (lpszDisplayName
, szElement
, MAX_PATH
);
330 /* build the full pathname to the element */
331 lstrcpynW(szPath
, This
->sPathTarget
, MAX_PATH
- 1);
332 PathAddBackslashW(szPath
);
333 len
= lstrlenW(szPath
);
334 lstrcpynW(szPath
+ len
, szElement
, MAX_PATH
- len
);
337 hr
= _ILCreateFromPathW(szPath
, &pidlTemp
);
340 if (szNext
&& *szNext
) {
341 /* try to analyse the next element */
342 hr
= SHELL32_ParseNextElement (iface
, hwndOwner
, pbc
,
343 &pidlTemp
, (LPOLESTR
) szNext
, pchEaten
, pdwAttributes
);
345 /* it's the last element */
346 if (pdwAttributes
&& *pdwAttributes
)
347 hr
= SHELL32_GetItemAttributes(&This
->IShellFolder2_iface
, pidlTemp
, pdwAttributes
);
357 TRACE ("(%p)->(-- pidl=%p ret=0x%08x)\n", This
, *ppidl
, hr
);
362 /**************************************************************************
363 * IShellFolder_fnEnumObjects
365 * HWND hwndOwner, //[in ] Parent Window
366 * DWORD grfFlags, //[in ] SHCONTF enumeration mask
367 * LPENUMIDLIST* ppenumIDList //[out] IEnumIDList interface
369 static HRESULT WINAPI
370 IShellFolder_fnEnumObjects (IShellFolder2
* iface
, HWND hwndOwner
,
371 DWORD dwFlags
, LPENUMIDLIST
* ppEnumIDList
)
373 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
374 IEnumIDListImpl
*list
;
376 TRACE ("(%p)->(HWND=%p flags=0x%08x pplist=%p)\n", This
, hwndOwner
,
377 dwFlags
, ppEnumIDList
);
379 if (!(list
= IEnumIDList_Constructor()))
380 return E_OUTOFMEMORY
;
381 CreateFolderEnumList(list
, This
->sPathTarget
, dwFlags
);
382 *ppEnumIDList
= &list
->IEnumIDList_iface
;
384 TRACE ("-- (%p)->(new ID List: %p)\n", This
, *ppEnumIDList
);
389 /**************************************************************************
390 * IShellFolder_fnBindToObject
392 * LPCITEMIDLIST pidl, //[in ] relative pidl to open
393 * LPBC pbc, //[in ] optional FileSystemBindData context
394 * REFIID riid, //[in ] Initial Interface
395 * LPVOID* ppvObject //[out] Interface*
397 static HRESULT WINAPI
398 IShellFolder_fnBindToObject (IShellFolder2
* iface
, LPCITEMIDLIST pidl
,
399 LPBC pbc
, REFIID riid
, LPVOID
* ppvOut
)
401 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
403 TRACE ("(%p)->(pidl=%p,%p,%s,%p)\n", This
, pidl
, pbc
,
404 shdebugstr_guid (riid
), ppvOut
);
406 return SHELL32_BindToChild (This
->pidlRoot
, This
->sPathTarget
, pidl
, riid
,
410 /**************************************************************************
411 * IShellFolder_fnBindToStorage
413 * LPCITEMIDLIST pidl, //[in ] complex pidl to store
414 * LPBC pbc, //[in ] reserved
415 * REFIID riid, //[in ] Initial storage interface
416 * LPVOID* ppvObject //[out] Interface* returned
418 static HRESULT WINAPI
419 IShellFolder_fnBindToStorage (IShellFolder2
* iface
, LPCITEMIDLIST pidl
,
420 LPBC pbcReserved
, REFIID riid
, LPVOID
* ppvOut
)
422 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
424 FIXME ("(%p)->(pidl=%p,%p,%s,%p) stub\n", This
, pidl
, pbcReserved
,
425 shdebugstr_guid (riid
), ppvOut
);
431 /**************************************************************************
432 * IShellFolder_fnCompareIDs
435 static HRESULT WINAPI
436 IShellFolder_fnCompareIDs (IShellFolder2
* iface
, LPARAM lParam
,
437 LPCITEMIDLIST pidl1
, LPCITEMIDLIST pidl2
)
439 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
443 TRACE ("(%p)->(0x%08lx,pidl1=%p,pidl2=%p)\n", This
, lParam
, pidl1
, pidl2
);
444 nReturn
= SHELL32_CompareIDs(&This
->IShellFolder2_iface
, lParam
, pidl1
, pidl2
);
445 TRACE ("-- %i\n", nReturn
);
449 /**************************************************************************
450 * IShellFolder_fnCreateViewObject
452 static HRESULT WINAPI
453 IShellFolder_fnCreateViewObject (IShellFolder2
* iface
, HWND hwndOwner
,
454 REFIID riid
, LPVOID
* ppvOut
)
456 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
458 LPSHELLVIEW pShellView
;
459 HRESULT hr
= E_INVALIDARG
;
461 TRACE ("(%p)->(hwnd=%p,%s,%p)\n", This
, hwndOwner
, shdebugstr_guid (riid
),
467 if (IsEqualIID (riid
, &IID_IDropTarget
)) {
468 hr
= IShellFolder2_QueryInterface (iface
, &IID_IDropTarget
, ppvOut
);
469 } else if (IsEqualIID (riid
, &IID_IContextMenu
)) {
470 FIXME ("IContextMenu not implemented\n");
472 } else if (IsEqualIID (riid
, &IID_IShellView
)) {
473 pShellView
= IShellView_Constructor ((IShellFolder
*) iface
);
475 hr
= IShellView_QueryInterface (pShellView
, riid
, ppvOut
);
476 IShellView_Release (pShellView
);
480 TRACE ("-- (%p)->(interface=%p)\n", This
, ppvOut
);
484 /**************************************************************************
485 * IShellFolder_fnGetAttributesOf
488 * UINT cidl, //[in ] num elements in pidl array
489 * LPCITEMIDLIST* apidl, //[in ] simple pidl array
490 * ULONG* rgfInOut) //[out] result array
493 static HRESULT WINAPI
494 IShellFolder_fnGetAttributesOf (IShellFolder2
* iface
, UINT cidl
,
495 LPCITEMIDLIST
* apidl
, DWORD
* rgfInOut
)
497 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
501 TRACE ("(%p)->(cidl=%d apidl=%p mask=%p (0x%08x))\n", This
, cidl
, apidl
,
502 rgfInOut
, rgfInOut
? *rgfInOut
: 0);
513 IShellFolder2
*parent
= NULL
;
514 LPCITEMIDLIST rpidl
= NULL
;
516 hr
= SHBindToParent(This
->pidlRoot
, &IID_IShellFolder2
, (void **)&parent
, &rpidl
);
518 SHELL32_GetItemAttributes(parent
, rpidl
, rgfInOut
);
519 IShellFolder2_Release(parent
);
523 while (cidl
> 0 && *apidl
) {
525 SHELL32_GetItemAttributes(&This
->IShellFolder2_iface
, *apidl
, rgfInOut
);
530 /* make sure SFGAO_VALIDATE is cleared, some apps depend on that */
531 *rgfInOut
&= ~SFGAO_VALIDATE
;
533 TRACE ("-- result=0x%08x\n", *rgfInOut
);
538 /**************************************************************************
539 * SHELL32_CreateExtensionUIObject (internal)
541 HRESULT
SHELL32_CreateExtensionUIObject(IShellFolder2
*iface
,
542 LPCITEMIDLIST pidl
, REFIID riid
, LPVOID
*ppvOut
)
544 static const WCHAR reg_blockedW
[] = {'S','o','f','t','w','a','r','e','\\',
545 'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
546 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
547 'S','h','e','l','l',' ','E','x','t','e','n','s','i','o','n','s','\\',
548 'B','l','o','c','k','e','d',0};
549 static const WCHAR formatW
[] = {'.','%','s','\\','S','h','e','l','l','E','x','\\',
550 '{','%','0','8','x','-','%','0','4','x','-','%','0','4','x','-',
551 '%','0','2','x','%','0','2','x','-','%','0','2','x','%','0','2','x',
552 '%','0','2','x','%','0','2','x','%','0','2','x','%','0','2','x','}',0};
554 IPersistFile
*persist_file
;
556 WCHAR extensionW
[20], buf
[MAX_PATH
];
557 DWORD size
= MAX_PATH
;
565 if(!_ILGetExtension(pidl
, extensionA
, 20))
568 MultiByteToWideChar(CP_ACP
, 0, extensionA
, -1, extensionW
, 20);
570 sprintfW(buf
, formatW
, extensionW
, riid
->Data1
, riid
->Data2
, riid
->Data3
,
571 riid
->Data4
[0], riid
->Data4
[1], riid
->Data4
[2], riid
->Data4
[3],
572 riid
->Data4
[4], riid
->Data4
[5], riid
->Data4
[6], riid
->Data4
[7]);
574 if(RegGetValueW(HKEY_CLASSES_ROOT
, buf
, NULL
, RRF_RT_REG_SZ
,
575 NULL
, buf
, &size
) != ERROR_SUCCESS
)
578 if(RegCreateKeyExW(HKEY_LOCAL_MACHINE
, reg_blockedW
, 0, 0, 0,
579 KEY_READ
, NULL
, &key
, NULL
) != ERROR_SUCCESS
)
581 if(RegQueryValueExW(key
, buf
, 0, NULL
, NULL
, NULL
)
582 != ERROR_FILE_NOT_FOUND
)
583 return E_ACCESSDENIED
;
586 if(RegCreateKeyExW(HKEY_CURRENT_USER
, reg_blockedW
, 0, 0, 0,
587 KEY_READ
, NULL
, &key
, NULL
) != ERROR_SUCCESS
)
589 if(RegQueryValueExW(key
, buf
, 0, NULL
, NULL
, NULL
)
590 != ERROR_FILE_NOT_FOUND
)
591 return E_ACCESSDENIED
;
594 if(!GUIDFromStringW(buf
, &guid
))
597 hr
= CoCreateInstance(&guid
, NULL
, CLSCTX_INPROC_SERVER
,
598 &IID_IPersistFile
, (void**)&persist_file
);
602 hr
= IShellFolder2_GetDisplayNameOf(iface
, pidl
, SHGDN_FORPARSING
, &path
);
604 hr
= StrRetToStrW(&path
, NULL
, &file
);
606 IPersistFile_Release(persist_file
);
610 hr
= IPersistFile_Load(persist_file
, file
, STGM_READ
);
613 IPersistFile_Release(persist_file
);
617 hr
= IPersistFile_QueryInterface(persist_file
, riid
, ppvOut
);
618 IPersistFile_Release(persist_file
);
622 /**************************************************************************
623 * IShellFolder_fnGetUIObjectOf
626 * HWND hwndOwner, //[in ] Parent window for any output
627 * UINT cidl, //[in ] array size
628 * LPCITEMIDLIST* apidl, //[in ] simple pidl array
629 * REFIID riid, //[in ] Requested Interface
630 * UINT* prgfInOut, //[ ] reserved
631 * LPVOID* ppvObject) //[out] Resulting Interface
634 * This function gets asked to return "view objects" for one or more (multiple
636 * The viewobject typically is an COM object with one of the following
638 * IExtractIcon,IDataObject,IContextMenu
639 * In order to support icon positions in the default Listview your DataObject
640 * must implement the SetData method (in addition to GetData :) - the shell
641 * passes a barely documented "Icon positions" structure to SetData when the
642 * drag starts, and GetData's it if the drop is in another explorer window that
643 * needs the positions.
645 static HRESULT WINAPI
646 IShellFolder_fnGetUIObjectOf (IShellFolder2
* iface
,
648 UINT cidl
, LPCITEMIDLIST
* apidl
, REFIID riid
,
649 UINT
* prgfInOut
, LPVOID
* ppvOut
)
651 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
654 IUnknown
*pObj
= NULL
;
655 HRESULT hr
= E_INVALIDARG
;
657 TRACE ("(%p)->(%p,%u,apidl=%p,%s,%p,%p)\n",
658 This
, hwndOwner
, cidl
, apidl
, shdebugstr_guid (riid
), prgfInOut
, ppvOut
);
664 hr
= SHELL32_CreateExtensionUIObject(iface
, *apidl
, riid
, ppvOut
);
669 if (IsEqualIID (riid
, &IID_IContextMenu
) && (cidl
>= 1)) {
670 return ItemMenu_Constructor((IShellFolder
*)iface
, This
->pidlRoot
, apidl
, cidl
, riid
, ppvOut
);
671 } else if (IsEqualIID (riid
, &IID_IDataObject
) && (cidl
>= 1)) {
672 pObj
= (LPUNKNOWN
) IDataObject_Constructor (hwndOwner
,
673 This
->pidlRoot
, apidl
, cidl
);
675 } else if (IsEqualIID (riid
, &IID_IExtractIconA
) && (cidl
== 1)) {
676 pidl
= ILCombine (This
->pidlRoot
, apidl
[0]);
677 pObj
= (LPUNKNOWN
) IExtractIconA_Constructor (pidl
);
680 } else if (IsEqualIID (riid
, &IID_IExtractIconW
) && (cidl
== 1)) {
681 pidl
= ILCombine (This
->pidlRoot
, apidl
[0]);
682 pObj
= (LPUNKNOWN
) IExtractIconW_Constructor (pidl
);
685 } else if (IsEqualIID (riid
, &IID_IDropTarget
) && (cidl
>= 1)) {
686 hr
= IShellFolder2_QueryInterface (iface
, &IID_IDropTarget
,
688 } else if ((IsEqualIID(riid
,&IID_IShellLinkW
) ||
689 IsEqualIID(riid
,&IID_IShellLinkA
)) && (cidl
== 1)) {
690 pidl
= ILCombine (This
->pidlRoot
, apidl
[0]);
691 hr
= IShellLink_ConstructFromFile(NULL
, riid
, pidl
, &pObj
);
697 if (SUCCEEDED(hr
) && !pObj
)
702 TRACE ("(%p)->hr=0x%08x\n", This
, hr
);
706 static const WCHAR AdvancedW
[] = { 'S','O','F','T','W','A','R','E',
707 '\\','M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
708 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\','E','x','p','l',
709 'o','r','e','r','\\','A','d','v','a','n','c','e','d',0 };
710 static const WCHAR HideFileExtW
[] = { 'H','i','d','e','F','i','l','e','E','x',
712 static const WCHAR NeverShowExtW
[] = { 'N','e','v','e','r','S','h','o','w','E',
715 /******************************************************************************
716 * SHELL_FS_HideExtension [Internal]
718 * Query the registry if the filename extension of a given path should be
722 * szPath [I] Relative or absolute path of a file
725 * TRUE, if the filename's extension should be hidden
728 BOOL
SHELL_FS_HideExtension(LPCWSTR szPath
)
732 DWORD dwDataSize
= sizeof (DWORD
);
733 BOOL doHide
= FALSE
; /* The default value is FALSE (win98 at least) */
735 if (!RegCreateKeyExW(HKEY_CURRENT_USER
, AdvancedW
, 0, 0, 0, KEY_ALL_ACCESS
, 0, &hKey
, 0)) {
736 if (!RegQueryValueExW(hKey
, HideFileExtW
, 0, 0, (LPBYTE
) &dwData
, &dwDataSize
))
742 LPWSTR ext
= PathFindExtensionW(szPath
);
745 WCHAR classname
[MAX_PATH
];
746 LONG classlen
= sizeof(classname
);
748 if (!RegQueryValueW(HKEY_CLASSES_ROOT
, ext
, classname
, &classlen
))
749 if (!RegOpenKeyW(HKEY_CLASSES_ROOT
, classname
, &hKey
)) {
750 if (!RegQueryValueExW(hKey
, NeverShowExtW
, 0, NULL
, NULL
, NULL
))
759 void SHELL_FS_ProcessDisplayFilename(LPWSTR szPath
, DWORD dwFlags
)
761 /*FIXME: MSDN also mentions SHGDN_FOREDITING which is not yet handled. */
762 if (!(dwFlags
& SHGDN_FORPARSING
) &&
763 ((dwFlags
& SHGDN_INFOLDER
) || (dwFlags
== SHGDN_NORMAL
))) {
764 if (SHELL_FS_HideExtension(szPath
) && szPath
[0] != '.')
765 PathRemoveExtensionW(szPath
);
769 /**************************************************************************
770 * IShellFolder_fnGetDisplayNameOf
771 * Retrieves the display name for the specified file object or subfolder
774 * LPCITEMIDLIST pidl, //[in ] complex pidl to item
775 * DWORD dwFlags, //[in ] SHGNO formatting flags
776 * LPSTRRET lpName) //[out] Returned display name
779 * if the name is in the pidl the ret value should be a STRRET_OFFSET
782 static HRESULT WINAPI
783 IShellFolder_fnGetDisplayNameOf (IShellFolder2
* iface
, LPCITEMIDLIST pidl
,
784 DWORD dwFlags
, LPSTRRET strRet
)
786 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
792 TRACE ("(%p)->(pidl=%p,0x%08x,%p)\n", This
, pidl
, dwFlags
, strRet
);
795 if (!pidl
|| !strRet
)
798 pszPath
= CoTaskMemAlloc((MAX_PATH
+1) * sizeof(WCHAR
));
800 return E_OUTOFMEMORY
;
802 if (_ILIsDesktop(pidl
)) { /* empty pidl */
803 if ((GET_SHGDN_FOR(dwFlags
) & SHGDN_FORPARSING
) &&
804 (GET_SHGDN_RELATION(dwFlags
) != SHGDN_INFOLDER
))
806 if (This
->sPathTarget
)
807 lstrcpynW(pszPath
, This
->sPathTarget
, MAX_PATH
);
809 /* pidl has to contain exactly one non null SHITEMID */
812 } else if (_ILIsPidlSimple(pidl
)) {
813 if ((GET_SHGDN_FOR(dwFlags
) & SHGDN_FORPARSING
) &&
814 (GET_SHGDN_RELATION(dwFlags
) != SHGDN_INFOLDER
) &&
817 lstrcpynW(pszPath
, This
->sPathTarget
, MAX_PATH
);
818 PathAddBackslashW(pszPath
);
819 len
= lstrlenW(pszPath
);
821 _ILSimpleGetTextW(pidl
, pszPath
+ len
, MAX_PATH
+ 1 - len
);
822 if (!_ILIsFolder(pidl
)) SHELL_FS_ProcessDisplayFilename(pszPath
, dwFlags
);
824 hr
= SHELL32_GetDisplayNameOfChild(iface
, pidl
, dwFlags
, pszPath
, MAX_PATH
);
828 /* Win9x always returns ANSI strings, NT always returns Unicode strings */
829 if (GetVersion() & 0x80000000) {
830 strRet
->uType
= STRRET_CSTR
;
831 if (!WideCharToMultiByte(CP_ACP
, 0, pszPath
, -1, strRet
->u
.cStr
, MAX_PATH
,
833 strRet
->u
.cStr
[0] = '\0';
834 CoTaskMemFree(pszPath
);
836 strRet
->uType
= STRRET_WSTR
;
837 strRet
->u
.pOleStr
= pszPath
;
840 CoTaskMemFree(pszPath
);
842 TRACE ("-- (%p)->(%s)\n", This
, strRet
->uType
== STRRET_CSTR
? strRet
->u
.cStr
: debugstr_w(strRet
->u
.pOleStr
));
846 /**************************************************************************
847 * IShellFolder_fnSetNameOf
848 * Changes the name of a file object or subfolder, possibly changing its item
849 * identifier in the process.
852 * HWND hwndOwner, //[in ] Owner window for output
853 * LPCITEMIDLIST pidl, //[in ] simple pidl of item to change
854 * LPCOLESTR lpszName, //[in ] the items new display name
855 * DWORD dwFlags, //[in ] SHGNO formatting flags
856 * LPITEMIDLIST* ppidlOut) //[out] simple pidl returned
858 static HRESULT WINAPI
IShellFolder_fnSetNameOf (IShellFolder2
* iface
,
863 LPITEMIDLIST
* pPidlOut
)
865 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
866 WCHAR szSrc
[MAX_PATH
+ 1], szDest
[MAX_PATH
+ 1];
868 BOOL bIsFolder
= _ILIsFolder (ILFindLastID (pidl
));
870 TRACE ("(%p)->(%p,pidl=%p,%s,%u,%p)\n", This
, hwndOwner
, pidl
,
871 debugstr_w (lpName
), dwFlags
, pPidlOut
);
873 /* build source path */
874 lstrcpynW(szSrc
, This
->sPathTarget
, MAX_PATH
);
875 ptr
= PathAddBackslashW (szSrc
);
877 _ILSimpleGetTextW (pidl
, ptr
, MAX_PATH
+ 1 - (ptr
- szSrc
));
879 /* build destination path */
880 if (dwFlags
== SHGDN_NORMAL
|| dwFlags
& SHGDN_INFOLDER
) {
881 lstrcpynW(szDest
, This
->sPathTarget
, MAX_PATH
);
882 ptr
= PathAddBackslashW (szDest
);
884 lstrcpynW(ptr
, lpName
, MAX_PATH
+ 1 - (ptr
- szDest
));
886 lstrcpynW(szDest
, lpName
, MAX_PATH
);
888 if(!(dwFlags
& SHGDN_FORPARSING
) && SHELL_FS_HideExtension(szSrc
)) {
889 WCHAR
*ext
= PathFindExtensionW(szSrc
);
891 INT len
= strlenW(szDest
);
892 lstrcpynW(szDest
+ len
, ext
, MAX_PATH
- len
);
896 TRACE ("src=%s dest=%s\n", debugstr_w(szSrc
), debugstr_w(szDest
));
898 if (MoveFileW (szSrc
, szDest
)) {
902 hr
= _ILCreateFromPathW(szDest
, pPidlOut
);
904 SHChangeNotify (bIsFolder
? SHCNE_RENAMEFOLDER
: SHCNE_RENAMEITEM
,
905 SHCNF_PATHW
, szSrc
, szDest
);
913 static HRESULT WINAPI
IShellFolder_fnGetDefaultSearchGUID(IShellFolder2
*iface
, GUID
*guid
)
915 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
916 TRACE("(%p)->(%p)\n", This
, guid
);
920 static HRESULT WINAPI
IShellFolder_fnEnumSearches (IShellFolder2
* iface
,
921 IEnumExtraSearch
** ppenum
)
923 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
924 FIXME ("(%p)\n", This
);
928 static HRESULT WINAPI
929 IShellFolder_fnGetDefaultColumn(IShellFolder2
*iface
, DWORD reserved
, ULONG
*sort
, ULONG
*display
)
931 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
933 TRACE("(%p)->(%#x, %p, %p)\n", This
, reserved
, sort
, display
);
938 static HRESULT WINAPI
939 IShellFolder_fnGetDefaultColumnState (IShellFolder2
* iface
, UINT iColumn
,
942 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
944 TRACE ("(%p)\n", This
);
946 if (!pcsFlags
|| iColumn
>= GENERICSHELLVIEWCOLUMNS
)
949 *pcsFlags
= GenericSFHeader
[iColumn
].pcsFlags
;
954 static HRESULT WINAPI
955 IShellFolder_fnGetDetailsEx (IShellFolder2
* iface
, LPCITEMIDLIST pidl
,
956 const SHCOLUMNID
* pscid
, VARIANT
* pv
)
958 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
959 FIXME ("(%p)\n", This
);
964 static HRESULT WINAPI
965 IShellFolder_fnGetDetailsOf (IShellFolder2
* iface
, LPCITEMIDLIST pidl
,
966 UINT iColumn
, SHELLDETAILS
* psd
)
968 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
971 TRACE ("(%p)->(%p %i %p)\n", This
, pidl
, iColumn
, psd
);
973 if (!psd
|| iColumn
>= GENERICSHELLVIEWCOLUMNS
)
977 /* the header titles */
978 psd
->fmt
= GenericSFHeader
[iColumn
].fmt
;
979 psd
->cxChar
= GenericSFHeader
[iColumn
].cxChar
;
980 psd
->str
.uType
= STRRET_CSTR
;
981 LoadStringA (shell32_hInstance
, GenericSFHeader
[iColumn
].colnameid
,
982 psd
->str
.u
.cStr
, MAX_PATH
);
986 psd
->str
.uType
= STRRET_CSTR
;
987 /* the data from the pidl */
990 hr
= IShellFolder2_GetDisplayNameOf (iface
, pidl
,
991 SHGDN_NORMAL
| SHGDN_INFOLDER
, &psd
->str
);
994 _ILGetFileSize (pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
997 _ILGetFileType (pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
1000 _ILGetFileDate (pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
1002 case 4: /* attributes */
1003 _ILGetFileAttributes (pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
1011 static HRESULT WINAPI
1012 IShellFolder_fnMapColumnToSCID (IShellFolder2
*iface
, UINT column
, SHCOLUMNID
*scid
)
1014 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
1016 TRACE("(%p)->(%u %p)\n", This
, column
, scid
);
1018 if (column
>= GENERICSHELLVIEWCOLUMNS
)
1019 return E_INVALIDARG
;
1021 return shellfolder_map_column_to_scid(GenericSFHeader
, column
, scid
);
1024 static const IShellFolder2Vtbl sfvt
=
1026 IShellFolder_fnQueryInterface
,
1027 IShellFolder_fnAddRef
,
1028 IShellFolder_fnRelease
,
1029 IShellFolder_fnParseDisplayName
,
1030 IShellFolder_fnEnumObjects
,
1031 IShellFolder_fnBindToObject
,
1032 IShellFolder_fnBindToStorage
,
1033 IShellFolder_fnCompareIDs
,
1034 IShellFolder_fnCreateViewObject
,
1035 IShellFolder_fnGetAttributesOf
,
1036 IShellFolder_fnGetUIObjectOf
,
1037 IShellFolder_fnGetDisplayNameOf
,
1038 IShellFolder_fnSetNameOf
,
1040 IShellFolder_fnGetDefaultSearchGUID
,
1041 IShellFolder_fnEnumSearches
,
1042 IShellFolder_fnGetDefaultColumn
,
1043 IShellFolder_fnGetDefaultColumnState
,
1044 IShellFolder_fnGetDetailsEx
,
1045 IShellFolder_fnGetDetailsOf
,
1046 IShellFolder_fnMapColumnToSCID
1049 /****************************************************************************
1050 * ISFHelper for IShellFolder implementation
1053 static HRESULT WINAPI
ISFHelper_fnQueryInterface(ISFHelper
*iface
, REFIID riid
, void **ppvObj
)
1055 IGenericSFImpl
*This
= impl_from_ISFHelper(iface
);
1057 return IUnknown_QueryInterface(This
->outer_unk
, riid
, ppvObj
);
1060 static ULONG WINAPI
ISFHelper_fnAddRef(ISFHelper
*iface
)
1062 IGenericSFImpl
*This
= impl_from_ISFHelper(iface
);
1064 return IUnknown_AddRef(This
->outer_unk
);
1067 static ULONG WINAPI
ISFHelper_fnRelease(ISFHelper
*iface
)
1069 IGenericSFImpl
*This
= impl_from_ISFHelper(iface
);
1071 return IUnknown_Release(This
->outer_unk
);
1074 /****************************************************************************
1075 * ISFHelper_fnGetUniqueName
1077 * creates a unique folder name
1080 static HRESULT WINAPI
1081 ISFHelper_fnGetUniqueName (ISFHelper
* iface
, LPWSTR pwszName
, UINT uLen
)
1083 IGenericSFImpl
*This
= impl_from_ISFHelper(iface
);
1086 WCHAR wszText
[MAX_PATH
];
1087 WCHAR wszNewFolder
[25];
1088 static const WCHAR wszFormat
[] = {'%','s',' ','%','d',0 };
1090 TRACE ("(%p)(%p %u)\n", This
, pwszName
, uLen
);
1092 LoadStringW(shell32_hInstance
, IDS_NEWFOLDER
, wszNewFolder
, ARRAY_SIZE(wszNewFolder
));
1093 if (uLen
< ARRAY_SIZE(wszNewFolder
) + 3)
1096 lstrcpynW (pwszName
, wszNewFolder
, uLen
);
1098 hr
= IShellFolder2_EnumObjects(&This
->IShellFolder2_iface
, 0,
1099 SHCONTF_FOLDERS
| SHCONTF_NONFOLDERS
| SHCONTF_INCLUDEHIDDEN
, &penum
);
1106 IEnumIDList_Reset (penum
);
1107 while (S_OK
== IEnumIDList_Next (penum
, 1, &pidl
, &dwFetched
) &&
1109 _ILSimpleGetTextW (pidl
, wszText
, MAX_PATH
);
1110 if (0 == lstrcmpiW (wszText
, pwszName
)) {
1111 snprintfW (pwszName
, uLen
, wszFormat
, wszNewFolder
, i
++);
1120 IEnumIDList_Release (penum
);
1125 /****************************************************************************
1126 * ISFHelper_fnAddFolder
1128 * adds a new folder.
1131 static HRESULT WINAPI
1132 ISFHelper_fnAddFolder (ISFHelper
* iface
, HWND hwnd
, LPCWSTR pwszName
,
1133 LPITEMIDLIST
* ppidlOut
)
1135 IGenericSFImpl
*This
= impl_from_ISFHelper(iface
);
1136 WCHAR wszNewDir
[MAX_PATH
];
1138 HRESULT hres
= E_FAIL
;
1140 TRACE ("(%p)(%s %p)\n", This
, debugstr_w(pwszName
), ppidlOut
);
1143 if (This
->sPathTarget
)
1144 lstrcpynW(wszNewDir
, This
->sPathTarget
, MAX_PATH
);
1145 PathAppendW(wszNewDir
, pwszName
);
1147 bRes
= CreateDirectoryW (wszNewDir
, NULL
);
1149 LPITEMIDLIST relPidl
;
1151 lstrcpyW(wszNewDir
, pwszName
);
1153 hres
= IShellFolder2_ParseDisplayName(&This
->IShellFolder2_iface
, hwnd
, NULL
, wszNewDir
,
1154 NULL
, &relPidl
, NULL
);
1156 if (SUCCEEDED(hres
)) {
1157 LPITEMIDLIST fullPidl
;
1159 fullPidl
= ILCombine(This
->pidlRoot
, relPidl
);
1162 SHChangeNotify(SHCNE_MKDIR
, SHCNF_IDLIST
, fullPidl
, NULL
);
1166 *ppidlOut
= relPidl
;
1170 WARN("failed to combine %s into a full PIDL\n", wine_dbgstr_w(pwszName
));
1175 WARN("failed to parse %s into a PIDL\n", wine_dbgstr_w(pwszName
));
1178 WCHAR wszText
[128 + MAX_PATH
];
1179 WCHAR wszTempText
[128];
1180 WCHAR wszCaption
[256];
1182 /* Cannot Create folder because of permissions */
1183 LoadStringW (shell32_hInstance
, IDS_CREATEFOLDER_DENIED
, wszTempText
, ARRAY_SIZE(wszTempText
));
1184 LoadStringW (shell32_hInstance
, IDS_CREATEFOLDER_CAPTION
, wszCaption
, ARRAY_SIZE(wszCaption
));
1185 sprintfW (wszText
, wszTempText
, wszNewDir
);
1186 MessageBoxW (hwnd
, wszText
, wszCaption
, MB_OK
| MB_ICONEXCLAMATION
);
1192 /****************************************************************************
1195 * Builds a list of paths like the one used in SHFileOperation from a table of
1196 * PIDLs relative to the given base folder
1198 static WCHAR
*build_paths_list(LPCWSTR wszBasePath
, int cidl
, const LPCITEMIDLIST
*pidls
)
1200 WCHAR
*wszPathsList
;
1205 iPathLen
= lstrlenW(wszBasePath
);
1206 wszPathsList
= heap_alloc(MAX_PATH
*sizeof(WCHAR
)*cidl
+1);
1207 wszListPos
= wszPathsList
;
1209 for (i
= 0; i
< cidl
; i
++) {
1210 if (!_ILIsFolder(pidls
[i
]) && !_ILIsValue(pidls
[i
]))
1213 lstrcpynW(wszListPos
, wszBasePath
, MAX_PATH
);
1214 /* FIXME: abort if path too long */
1215 _ILSimpleGetTextW(pidls
[i
], wszListPos
+iPathLen
, MAX_PATH
-iPathLen
);
1216 wszListPos
+= lstrlenW(wszListPos
)+1;
1219 return wszPathsList
;
1222 /****************************************************************************
1223 * ISFHelper_fnDeleteItems
1225 * deletes items in folder
1227 static HRESULT WINAPI
1228 ISFHelper_fnDeleteItems (ISFHelper
* iface
, UINT cidl
, LPCITEMIDLIST
* apidl
)
1230 IGenericSFImpl
*This
= impl_from_ISFHelper(iface
);
1233 WCHAR wszPath
[MAX_PATH
];
1234 WCHAR
*wszPathsList
;
1236 WCHAR
*wszCurrentPath
;
1238 TRACE ("(%p)(%u %p)\n", This
, cidl
, apidl
);
1239 if (cidl
==0) return S_OK
;
1241 if (This
->sPathTarget
)
1242 lstrcpynW(wszPath
, This
->sPathTarget
, MAX_PATH
);
1245 PathAddBackslashW(wszPath
);
1246 wszPathsList
= build_paths_list(wszPath
, cidl
, apidl
);
1248 ZeroMemory(&op
, sizeof(op
));
1249 op
.hwnd
= GetActiveWindow();
1250 op
.wFunc
= FO_DELETE
;
1251 op
.pFrom
= wszPathsList
;
1252 op
.fFlags
= FOF_ALLOWUNDO
;
1253 if (SHFileOperationW(&op
))
1255 WARN("SHFileOperation failed\n");
1261 /* we currently need to manually send the notifies */
1262 wszCurrentPath
= wszPathsList
;
1263 for (i
= 0; i
< cidl
; i
++)
1267 if (_ILIsFolder(apidl
[i
]))
1268 wEventId
= SHCNE_RMDIR
;
1269 else if (_ILIsValue(apidl
[i
]))
1270 wEventId
= SHCNE_DELETE
;
1274 /* check if file exists */
1275 if (GetFileAttributesW(wszCurrentPath
) == INVALID_FILE_ATTRIBUTES
)
1277 LPITEMIDLIST pidl
= ILCombine(This
->pidlRoot
, apidl
[i
]);
1278 SHChangeNotify(wEventId
, SHCNF_IDLIST
, pidl
, NULL
);
1282 wszCurrentPath
+= lstrlenW(wszCurrentPath
)+1;
1284 heap_free(wszPathsList
);
1288 /****************************************************************************
1289 * ISFHelper_fnCopyItems
1291 * copies items to this folder
1293 static HRESULT WINAPI
1294 ISFHelper_fnCopyItems (ISFHelper
* iface
, IShellFolder
* pSFFrom
, UINT cidl
,
1295 LPCITEMIDLIST
* apidl
)
1298 IPersistFolder2
*ppf2
= NULL
;
1299 WCHAR wszSrcPathRoot
[MAX_PATH
],
1300 wszDstPath
[MAX_PATH
+1];
1301 WCHAR
*wszSrcPathsList
;
1302 IGenericSFImpl
*This
= impl_from_ISFHelper(iface
);
1304 SHFILEOPSTRUCTW fop
;
1306 TRACE ("(%p)->(%p,%u,%p)\n", This
, pSFFrom
, cidl
, apidl
);
1308 IShellFolder_QueryInterface (pSFFrom
, &IID_IPersistFolder2
,
1313 if (SUCCEEDED (IPersistFolder2_GetCurFolder (ppf2
, &pidl
))) {
1314 SHGetPathFromIDListW (pidl
, wszSrcPathRoot
);
1315 if (This
->sPathTarget
)
1316 lstrcpynW(wszDstPath
, This
->sPathTarget
, MAX_PATH
);
1319 PathAddBackslashW(wszSrcPathRoot
);
1320 PathAddBackslashW(wszDstPath
);
1321 wszSrcPathsList
= build_paths_list(wszSrcPathRoot
, cidl
, apidl
);
1322 ZeroMemory(&fop
, sizeof(fop
));
1323 fop
.hwnd
= GetActiveWindow();
1324 fop
.wFunc
= FO_COPY
;
1325 fop
.pFrom
= wszSrcPathsList
;
1326 fop
.pTo
= wszDstPath
;
1327 fop
.fFlags
= FOF_ALLOWUNDO
;
1329 if(SHFileOperationW(&fop
))
1331 WARN("Copy failed\n");
1334 heap_free(wszSrcPathsList
);
1337 IPersistFolder2_Release(ppf2
);
1342 static const ISFHelperVtbl shvt
=
1344 ISFHelper_fnQueryInterface
,
1346 ISFHelper_fnRelease
,
1347 ISFHelper_fnGetUniqueName
,
1348 ISFHelper_fnAddFolder
,
1349 ISFHelper_fnDeleteItems
,
1350 ISFHelper_fnCopyItems
1353 /************************************************************************
1354 * IFSFldr_PersistFolder3_QueryInterface
1357 static HRESULT WINAPI
IFSFldr_PersistFolder3_QueryInterface(IPersistFolder3
*iface
, REFIID iid
,
1360 IGenericSFImpl
*This
= impl_from_IPersistFolder3(iface
);
1362 return IUnknown_QueryInterface(This
->outer_unk
, iid
, ppv
);
1365 /************************************************************************
1366 * IFSFldr_PersistFolder3_AddRef
1369 static ULONG WINAPI
IFSFldr_PersistFolder3_AddRef(IPersistFolder3
*iface
)
1371 IGenericSFImpl
*This
= impl_from_IPersistFolder3(iface
);
1373 return IUnknown_AddRef(This
->outer_unk
);
1376 /************************************************************************
1377 * IFSFldr_PersistFolder3_Release
1380 static ULONG WINAPI
IFSFldr_PersistFolder3_Release(IPersistFolder3
*iface
)
1382 IGenericSFImpl
*This
= impl_from_IPersistFolder3(iface
);
1384 return IUnknown_Release(This
->outer_unk
);
1387 /************************************************************************
1388 * IFSFldr_PersistFolder3_GetClassID
1390 static HRESULT WINAPI
1391 IFSFldr_PersistFolder3_GetClassID (IPersistFolder3
* iface
, CLSID
* lpClassId
)
1393 IGenericSFImpl
*This
= impl_from_IPersistFolder3(iface
);
1395 TRACE ("(%p)\n", This
);
1399 *lpClassId
= *This
->pclsid
;
1404 /************************************************************************
1405 * IFSFldr_PersistFolder3_Initialize
1408 * sPathTarget is not set. Don't know how to handle in a non rooted environment.
1410 static HRESULT WINAPI
1411 IFSFldr_PersistFolder3_Initialize (IPersistFolder3
* iface
, LPCITEMIDLIST pidl
)
1413 WCHAR wszTemp
[MAX_PATH
];
1415 IGenericSFImpl
*This
= impl_from_IPersistFolder3(iface
);
1417 TRACE ("(%p)->(%p)\n", This
, pidl
);
1419 SHFree (This
->pidlRoot
); /* free the old pidl */
1420 This
->pidlRoot
= ILClone (pidl
); /* set my pidl */
1422 SHFree (This
->sPathTarget
);
1423 This
->sPathTarget
= NULL
;
1426 if (SHGetPathFromIDListW (pidl
, wszTemp
)) {
1427 int len
= strlenW(wszTemp
);
1428 This
->sPathTarget
= SHAlloc((len
+ 1) * sizeof(WCHAR
));
1429 if (!This
->sPathTarget
)
1430 return E_OUTOFMEMORY
;
1431 memcpy(This
->sPathTarget
, wszTemp
, (len
+ 1) * sizeof(WCHAR
));
1434 TRACE ("--(%p)->(%s)\n", This
, debugstr_w(This
->sPathTarget
));
1438 /**************************************************************************
1439 * IFSFldr_PersistFolder3_GetCurFolder
1441 static HRESULT WINAPI
1442 IFSFldr_PersistFolder3_fnGetCurFolder (IPersistFolder3
* iface
,
1443 LPITEMIDLIST
* pidl
)
1445 IGenericSFImpl
*This
= impl_from_IPersistFolder3(iface
);
1447 TRACE ("(%p)->(%p)\n", This
, pidl
);
1449 if (!pidl
) return E_POINTER
;
1450 *pidl
= ILClone (This
->pidlRoot
);
1454 /**************************************************************************
1455 * IFSFldr_PersistFolder3_InitializeEx
1457 * FIXME: error handling
1459 static HRESULT WINAPI
1460 IFSFldr_PersistFolder3_InitializeEx (IPersistFolder3
* iface
,
1461 IBindCtx
* pbc
, LPCITEMIDLIST pidlRoot
,
1462 const PERSIST_FOLDER_TARGET_INFO
* ppfti
)
1464 WCHAR wszTemp
[MAX_PATH
];
1466 IGenericSFImpl
*This
= impl_from_IPersistFolder3(iface
);
1468 TRACE ("(%p)->(%p,%p,%p)\n", This
, pbc
, pidlRoot
, ppfti
);
1470 TRACE ("--%p %s %s 0x%08x 0x%08x\n",
1471 ppfti
->pidlTargetFolder
, debugstr_w (ppfti
->szTargetParsingName
),
1472 debugstr_w (ppfti
->szNetworkProvider
), ppfti
->dwAttributes
,
1476 if (ppfti
&& ppfti
->pidlTargetFolder
)
1477 pdump (ppfti
->pidlTargetFolder
);
1481 SHFree(This
->pidlRoot
);
1482 This
->pidlRoot
= NULL
;
1484 if (This
->sPathTarget
)
1486 SHFree(This
->sPathTarget
);
1487 This
->sPathTarget
= NULL
;
1491 * Root path and pidl
1493 This
->pidlRoot
= ILClone (pidlRoot
);
1496 * the target folder is specified in csidl OR pidlTargetFolder OR
1497 * szTargetParsingName
1500 if (ppfti
->csidl
!= -1) {
1501 if (SHGetSpecialFolderPathW (0, wszTemp
, ppfti
->csidl
,
1502 ppfti
->csidl
& CSIDL_FLAG_CREATE
)) {
1503 int len
= strlenW(wszTemp
);
1504 This
->sPathTarget
= SHAlloc((len
+ 1) * sizeof(WCHAR
));
1505 if (!This
->sPathTarget
)
1506 return E_OUTOFMEMORY
;
1507 memcpy(This
->sPathTarget
, wszTemp
, (len
+ 1) * sizeof(WCHAR
));
1509 } else if (ppfti
->szTargetParsingName
[0]) {
1510 int len
= strlenW(ppfti
->szTargetParsingName
);
1511 This
->sPathTarget
= SHAlloc((len
+ 1) * sizeof(WCHAR
));
1512 if (!This
->sPathTarget
)
1513 return E_OUTOFMEMORY
;
1514 memcpy(This
->sPathTarget
, ppfti
->szTargetParsingName
,
1515 (len
+ 1) * sizeof(WCHAR
));
1516 } else if (ppfti
->pidlTargetFolder
) {
1517 if (SHGetPathFromIDListW(ppfti
->pidlTargetFolder
, wszTemp
)) {
1518 int len
= strlenW(wszTemp
);
1519 This
->sPathTarget
= SHAlloc((len
+ 1) * sizeof(WCHAR
));
1520 if (!This
->sPathTarget
)
1521 return E_OUTOFMEMORY
;
1522 memcpy(This
->sPathTarget
, wszTemp
, (len
+ 1) * sizeof(WCHAR
));
1527 TRACE ("--(%p)->(target=%s)\n", This
, debugstr_w(This
->sPathTarget
));
1528 pdump (This
->pidlRoot
);
1529 return (This
->sPathTarget
) ? S_OK
: E_FAIL
;
1532 static HRESULT WINAPI
1533 IFSFldr_PersistFolder3_GetFolderTargetInfo (IPersistFolder3
* iface
,
1534 PERSIST_FOLDER_TARGET_INFO
* ppfti
)
1536 IGenericSFImpl
*This
= impl_from_IPersistFolder3(iface
);
1537 FIXME ("(%p)->(%p)\n", This
, ppfti
);
1538 ZeroMemory (ppfti
, sizeof (*ppfti
));
1542 static const IPersistFolder3Vtbl pfvt
=
1544 IFSFldr_PersistFolder3_QueryInterface
,
1545 IFSFldr_PersistFolder3_AddRef
,
1546 IFSFldr_PersistFolder3_Release
,
1547 IFSFldr_PersistFolder3_GetClassID
,
1548 IFSFldr_PersistFolder3_Initialize
,
1549 IFSFldr_PersistFolder3_fnGetCurFolder
,
1550 IFSFldr_PersistFolder3_InitializeEx
,
1551 IFSFldr_PersistFolder3_GetFolderTargetInfo
1554 /****************************************************************************
1555 * ISFDropTarget implementation
1557 static HRESULT WINAPI
ISFDropTarget_QueryInterface(IDropTarget
*iface
, REFIID riid
, void **ppv
)
1559 IGenericSFImpl
*This
= impl_from_IDropTarget(iface
);
1561 return IUnknown_QueryInterface(This
->outer_unk
, riid
, ppv
);
1564 static ULONG WINAPI
ISFDropTarget_AddRef(IDropTarget
*iface
)
1566 IGenericSFImpl
*This
= impl_from_IDropTarget(iface
);
1568 return IUnknown_AddRef(This
->outer_unk
);
1571 static ULONG WINAPI
ISFDropTarget_Release(IDropTarget
*iface
)
1573 IGenericSFImpl
*This
= impl_from_IDropTarget(iface
);
1575 return IUnknown_Release(This
->outer_unk
);
1578 static HRESULT WINAPI
1579 ISFDropTarget_DragEnter (IDropTarget
* iface
, IDataObject
* pDataObject
,
1580 DWORD dwKeyState
, POINTL pt
, DWORD
* pdwEffect
)
1584 IGenericSFImpl
*This
= impl_from_IDropTarget(iface
);
1586 TRACE ("(%p)->(DataObject=%p)\n", This
, pDataObject
);
1588 InitFormatEtc (fmt
, This
->cfShellIDList
, TYMED_HGLOBAL
);
1589 This
->fAcceptFmt
= IDataObject_QueryGetData (pDataObject
, &fmt
) == S_OK
;
1590 if (This
->fAcceptFmt
)
1591 *pdwEffect
= KeyStateToDropEffect(dwKeyState
);
1593 *pdwEffect
= DROPEFFECT_NONE
;
1598 static HRESULT WINAPI
1599 ISFDropTarget_DragOver (IDropTarget
* iface
, DWORD dwKeyState
, POINTL pt
,
1602 IGenericSFImpl
*This
= impl_from_IDropTarget(iface
);
1604 TRACE ("(%p)\n", This
);
1607 return E_INVALIDARG
;
1609 if (This
->fAcceptFmt
)
1610 *pdwEffect
= KeyStateToDropEffect(dwKeyState
);
1612 *pdwEffect
= DROPEFFECT_NONE
;
1617 static HRESULT WINAPI
ISFDropTarget_DragLeave (IDropTarget
* iface
)
1619 IGenericSFImpl
*This
= impl_from_IDropTarget(iface
);
1621 TRACE ("(%p)\n", This
);
1623 This
->fAcceptFmt
= FALSE
;
1628 static HRESULT WINAPI
1629 ISFDropTarget_Drop (IDropTarget
* iface
, IDataObject
* pDataObject
,
1630 DWORD dwKeyState
, POINTL pt
, DWORD
* pdwEffect
)
1632 IGenericSFImpl
*This
= impl_from_IDropTarget(iface
);
1634 FIXME ("(%p) object dropped\n", This
);
1639 static const IDropTargetVtbl dtvt
= {
1640 ISFDropTarget_QueryInterface
,
1641 ISFDropTarget_AddRef
,
1642 ISFDropTarget_Release
,
1643 ISFDropTarget_DragEnter
,
1644 ISFDropTarget_DragOver
,
1645 ISFDropTarget_DragLeave
,
1649 HRESULT WINAPI
IFSFolder_Constructor(IUnknown
*outer_unk
, REFIID riid
, void **ppv
)
1654 TRACE("outer_unk=%p %s\n", outer_unk
, shdebugstr_guid(riid
));
1656 if (outer_unk
&& !IsEqualIID(riid
, &IID_IUnknown
))
1657 return CLASS_E_NOAGGREGATION
;
1659 sf
= LocalAlloc(LMEM_ZEROINIT
, sizeof(*sf
));
1661 return E_OUTOFMEMORY
;
1664 sf
->IUnknown_inner
.lpVtbl
= &unkvt
;
1665 sf
->IShellFolder2_iface
.lpVtbl
= &sfvt
;
1666 sf
->IPersistFolder3_iface
.lpVtbl
= &pfvt
;
1667 sf
->IDropTarget_iface
.lpVtbl
= &dtvt
;
1668 sf
->ISFHelper_iface
.lpVtbl
= &shvt
;
1669 sf
->pclsid
= (CLSID
*) & CLSID_ShellFSFolder
;
1670 sf
->outer_unk
= outer_unk
? outer_unk
: &sf
->IUnknown_inner
;
1672 hr
= IUnknown_QueryInterface(&sf
->IUnknown_inner
, riid
, ppv
);
1673 IUnknown_Release(&sf
->IUnknown_inner
);
1675 TRACE ("--%p\n", *ppv
);