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 hr
= BackgroundMenu_Constructor((IShellFolder
*)iface
, FALSE
, riid
, ppvOut
);
471 } else if (IsEqualIID (riid
, &IID_IShellView
)) {
472 pShellView
= IShellView_Constructor ((IShellFolder
*) iface
);
474 hr
= IShellView_QueryInterface (pShellView
, riid
, ppvOut
);
475 IShellView_Release (pShellView
);
479 TRACE ("-- (%p)->(interface=%p)\n", This
, ppvOut
);
483 /**************************************************************************
484 * IShellFolder_fnGetAttributesOf
487 * UINT cidl, //[in ] num elements in pidl array
488 * LPCITEMIDLIST* apidl, //[in ] simple pidl array
489 * ULONG* rgfInOut) //[out] result array
492 static HRESULT WINAPI
493 IShellFolder_fnGetAttributesOf (IShellFolder2
* iface
, UINT cidl
,
494 LPCITEMIDLIST
* apidl
, DWORD
* rgfInOut
)
496 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
500 TRACE ("(%p)->(cidl=%d apidl=%p mask=%p (0x%08x))\n", This
, cidl
, apidl
,
501 rgfInOut
, rgfInOut
? *rgfInOut
: 0);
512 IShellFolder2
*parent
= NULL
;
513 LPCITEMIDLIST rpidl
= NULL
;
515 hr
= SHBindToParent(This
->pidlRoot
, &IID_IShellFolder2
, (void **)&parent
, &rpidl
);
517 SHELL32_GetItemAttributes(parent
, rpidl
, rgfInOut
);
518 IShellFolder2_Release(parent
);
522 while (cidl
> 0 && *apidl
) {
524 SHELL32_GetItemAttributes(&This
->IShellFolder2_iface
, *apidl
, rgfInOut
);
529 /* make sure SFGAO_VALIDATE is cleared, some apps depend on that */
530 *rgfInOut
&= ~SFGAO_VALIDATE
;
532 TRACE ("-- result=0x%08x\n", *rgfInOut
);
537 /**************************************************************************
538 * SHELL32_CreateExtensionUIObject (internal)
540 HRESULT
SHELL32_CreateExtensionUIObject(IShellFolder2
*iface
,
541 LPCITEMIDLIST pidl
, REFIID riid
, LPVOID
*ppvOut
)
543 static const WCHAR reg_blockedW
[] = {'S','o','f','t','w','a','r','e','\\',
544 'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
545 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
546 'S','h','e','l','l',' ','E','x','t','e','n','s','i','o','n','s','\\',
547 'B','l','o','c','k','e','d',0};
548 static const WCHAR formatW
[] = {'.','%','s','\\','S','h','e','l','l','E','x','\\',
549 '{','%','0','8','x','-','%','0','4','x','-','%','0','4','x','-',
550 '%','0','2','x','%','0','2','x','-','%','0','2','x','%','0','2','x',
551 '%','0','2','x','%','0','2','x','%','0','2','x','%','0','2','x','}',0};
553 IPersistFile
*persist_file
;
555 WCHAR extensionW
[20], buf
[MAX_PATH
];
556 DWORD size
= MAX_PATH
;
564 if(!_ILGetExtension(pidl
, extensionA
, 20))
567 MultiByteToWideChar(CP_ACP
, 0, extensionA
, -1, extensionW
, 20);
569 sprintfW(buf
, formatW
, extensionW
, riid
->Data1
, riid
->Data2
, riid
->Data3
,
570 riid
->Data4
[0], riid
->Data4
[1], riid
->Data4
[2], riid
->Data4
[3],
571 riid
->Data4
[4], riid
->Data4
[5], riid
->Data4
[6], riid
->Data4
[7]);
573 if(RegGetValueW(HKEY_CLASSES_ROOT
, buf
, NULL
, RRF_RT_REG_SZ
,
574 NULL
, buf
, &size
) != ERROR_SUCCESS
)
577 if(RegCreateKeyExW(HKEY_LOCAL_MACHINE
, reg_blockedW
, 0, 0, 0,
578 KEY_READ
, NULL
, &key
, NULL
) != ERROR_SUCCESS
)
580 if(RegQueryValueExW(key
, buf
, 0, NULL
, NULL
, NULL
)
581 != ERROR_FILE_NOT_FOUND
)
582 return E_ACCESSDENIED
;
585 if(RegCreateKeyExW(HKEY_CURRENT_USER
, reg_blockedW
, 0, 0, 0,
586 KEY_READ
, NULL
, &key
, NULL
) != ERROR_SUCCESS
)
588 if(RegQueryValueExW(key
, buf
, 0, NULL
, NULL
, NULL
)
589 != ERROR_FILE_NOT_FOUND
)
590 return E_ACCESSDENIED
;
593 if(!GUIDFromStringW(buf
, &guid
))
596 hr
= CoCreateInstance(&guid
, NULL
, CLSCTX_INPROC_SERVER
,
597 &IID_IPersistFile
, (void**)&persist_file
);
601 hr
= IShellFolder2_GetDisplayNameOf(iface
, pidl
, SHGDN_FORPARSING
, &path
);
603 hr
= StrRetToStrW(&path
, NULL
, &file
);
605 IPersistFile_Release(persist_file
);
609 hr
= IPersistFile_Load(persist_file
, file
, STGM_READ
);
612 IPersistFile_Release(persist_file
);
616 hr
= IPersistFile_QueryInterface(persist_file
, riid
, ppvOut
);
617 IPersistFile_Release(persist_file
);
621 /**************************************************************************
622 * IShellFolder_fnGetUIObjectOf
625 * HWND hwndOwner, //[in ] Parent window for any output
626 * UINT cidl, //[in ] array size
627 * LPCITEMIDLIST* apidl, //[in ] simple pidl array
628 * REFIID riid, //[in ] Requested Interface
629 * UINT* prgfInOut, //[ ] reserved
630 * LPVOID* ppvObject) //[out] Resulting Interface
633 * This function gets asked to return "view objects" for one or more (multiple
635 * The viewobject typically is an COM object with one of the following
637 * IExtractIcon,IDataObject,IContextMenu
638 * In order to support icon positions in the default Listview your DataObject
639 * must implement the SetData method (in addition to GetData :) - the shell
640 * passes a barely documented "Icon positions" structure to SetData when the
641 * drag starts, and GetData's it if the drop is in another explorer window that
642 * needs the positions.
644 static HRESULT WINAPI
645 IShellFolder_fnGetUIObjectOf (IShellFolder2
* iface
,
647 UINT cidl
, LPCITEMIDLIST
* apidl
, REFIID riid
,
648 UINT
* prgfInOut
, LPVOID
* ppvOut
)
650 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
653 IUnknown
*pObj
= NULL
;
654 HRESULT hr
= E_INVALIDARG
;
656 TRACE ("(%p)->(%p,%u,apidl=%p,%s,%p,%p)\n",
657 This
, hwndOwner
, cidl
, apidl
, shdebugstr_guid (riid
), prgfInOut
, ppvOut
);
663 hr
= SHELL32_CreateExtensionUIObject(iface
, *apidl
, riid
, ppvOut
);
668 if (IsEqualIID (riid
, &IID_IContextMenu
) && (cidl
>= 1)) {
669 return ItemMenu_Constructor((IShellFolder
*)iface
, This
->pidlRoot
, apidl
, cidl
, riid
, ppvOut
);
670 } else if (IsEqualIID (riid
, &IID_IDataObject
) && (cidl
>= 1)) {
671 pObj
= (LPUNKNOWN
) IDataObject_Constructor (hwndOwner
,
672 This
->pidlRoot
, apidl
, cidl
);
674 } else if (IsEqualIID (riid
, &IID_IExtractIconA
) && (cidl
== 1)) {
675 pidl
= ILCombine (This
->pidlRoot
, apidl
[0]);
676 pObj
= (LPUNKNOWN
) IExtractIconA_Constructor (pidl
);
679 } else if (IsEqualIID (riid
, &IID_IExtractIconW
) && (cidl
== 1)) {
680 pidl
= ILCombine (This
->pidlRoot
, apidl
[0]);
681 pObj
= (LPUNKNOWN
) IExtractIconW_Constructor (pidl
);
684 } else if (IsEqualIID (riid
, &IID_IDropTarget
) && (cidl
>= 1)) {
685 hr
= IShellFolder2_QueryInterface (iface
, &IID_IDropTarget
,
687 } else if ((IsEqualIID(riid
,&IID_IShellLinkW
) ||
688 IsEqualIID(riid
,&IID_IShellLinkA
)) && (cidl
== 1)) {
689 pidl
= ILCombine (This
->pidlRoot
, apidl
[0]);
690 hr
= IShellLink_ConstructFromFile(NULL
, riid
, pidl
, &pObj
);
696 if (SUCCEEDED(hr
) && !pObj
)
701 TRACE ("(%p)->hr=0x%08x\n", This
, hr
);
705 static const WCHAR AdvancedW
[] = { 'S','O','F','T','W','A','R','E',
706 '\\','M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
707 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\','E','x','p','l',
708 'o','r','e','r','\\','A','d','v','a','n','c','e','d',0 };
709 static const WCHAR HideFileExtW
[] = { 'H','i','d','e','F','i','l','e','E','x',
711 static const WCHAR NeverShowExtW
[] = { 'N','e','v','e','r','S','h','o','w','E',
714 /******************************************************************************
715 * SHELL_FS_HideExtension [Internal]
717 * Query the registry if the filename extension of a given path should be
721 * szPath [I] Relative or absolute path of a file
724 * TRUE, if the filename's extension should be hidden
727 BOOL
SHELL_FS_HideExtension(LPCWSTR szPath
)
731 DWORD dwDataSize
= sizeof (DWORD
);
732 BOOL doHide
= FALSE
; /* The default value is FALSE (win98 at least) */
734 if (!RegCreateKeyExW(HKEY_CURRENT_USER
, AdvancedW
, 0, 0, 0, KEY_ALL_ACCESS
, 0, &hKey
, 0)) {
735 if (!RegQueryValueExW(hKey
, HideFileExtW
, 0, 0, (LPBYTE
) &dwData
, &dwDataSize
))
741 LPWSTR ext
= PathFindExtensionW(szPath
);
744 WCHAR classname
[MAX_PATH
];
745 LONG classlen
= sizeof(classname
);
747 if (!RegQueryValueW(HKEY_CLASSES_ROOT
, ext
, classname
, &classlen
))
748 if (!RegOpenKeyW(HKEY_CLASSES_ROOT
, classname
, &hKey
)) {
749 if (!RegQueryValueExW(hKey
, NeverShowExtW
, 0, NULL
, NULL
, NULL
))
758 void SHELL_FS_ProcessDisplayFilename(LPWSTR szPath
, DWORD dwFlags
)
760 /*FIXME: MSDN also mentions SHGDN_FOREDITING which is not yet handled. */
761 if (!(dwFlags
& SHGDN_FORPARSING
) &&
762 ((dwFlags
& SHGDN_INFOLDER
) || (dwFlags
== SHGDN_NORMAL
))) {
763 if (SHELL_FS_HideExtension(szPath
) && szPath
[0] != '.')
764 PathRemoveExtensionW(szPath
);
768 /**************************************************************************
769 * IShellFolder_fnGetDisplayNameOf
770 * Retrieves the display name for the specified file object or subfolder
773 * LPCITEMIDLIST pidl, //[in ] complex pidl to item
774 * DWORD dwFlags, //[in ] SHGNO formatting flags
775 * LPSTRRET lpName) //[out] Returned display name
778 * if the name is in the pidl the ret value should be a STRRET_OFFSET
781 static HRESULT WINAPI
782 IShellFolder_fnGetDisplayNameOf (IShellFolder2
* iface
, LPCITEMIDLIST pidl
,
783 DWORD dwFlags
, LPSTRRET strRet
)
785 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
791 TRACE ("(%p)->(pidl=%p,0x%08x,%p)\n", This
, pidl
, dwFlags
, strRet
);
794 if (!pidl
|| !strRet
)
797 pszPath
= CoTaskMemAlloc((MAX_PATH
+1) * sizeof(WCHAR
));
799 return E_OUTOFMEMORY
;
801 if (_ILIsDesktop(pidl
)) { /* empty pidl */
802 if ((GET_SHGDN_FOR(dwFlags
) & SHGDN_FORPARSING
) &&
803 (GET_SHGDN_RELATION(dwFlags
) != SHGDN_INFOLDER
))
805 if (This
->sPathTarget
)
806 lstrcpynW(pszPath
, This
->sPathTarget
, MAX_PATH
);
808 /* pidl has to contain exactly one non null SHITEMID */
811 } else if (_ILIsPidlSimple(pidl
)) {
812 if ((GET_SHGDN_FOR(dwFlags
) & SHGDN_FORPARSING
) &&
813 (GET_SHGDN_RELATION(dwFlags
) != SHGDN_INFOLDER
) &&
816 lstrcpynW(pszPath
, This
->sPathTarget
, MAX_PATH
);
817 PathAddBackslashW(pszPath
);
818 len
= lstrlenW(pszPath
);
820 _ILSimpleGetTextW(pidl
, pszPath
+ len
, MAX_PATH
+ 1 - len
);
821 if (!_ILIsFolder(pidl
)) SHELL_FS_ProcessDisplayFilename(pszPath
, dwFlags
);
823 hr
= SHELL32_GetDisplayNameOfChild(iface
, pidl
, dwFlags
, pszPath
, MAX_PATH
);
827 /* Win9x always returns ANSI strings, NT always returns Unicode strings */
828 if (GetVersion() & 0x80000000) {
829 strRet
->uType
= STRRET_CSTR
;
830 if (!WideCharToMultiByte(CP_ACP
, 0, pszPath
, -1, strRet
->u
.cStr
, MAX_PATH
,
832 strRet
->u
.cStr
[0] = '\0';
833 CoTaskMemFree(pszPath
);
835 strRet
->uType
= STRRET_WSTR
;
836 strRet
->u
.pOleStr
= pszPath
;
839 CoTaskMemFree(pszPath
);
841 TRACE ("-- (%p)->(%s)\n", This
, strRet
->uType
== STRRET_CSTR
? strRet
->u
.cStr
: debugstr_w(strRet
->u
.pOleStr
));
845 /**************************************************************************
846 * IShellFolder_fnSetNameOf
847 * Changes the name of a file object or subfolder, possibly changing its item
848 * identifier in the process.
851 * HWND hwndOwner, //[in ] Owner window for output
852 * LPCITEMIDLIST pidl, //[in ] simple pidl of item to change
853 * LPCOLESTR lpszName, //[in ] the items new display name
854 * DWORD dwFlags, //[in ] SHGNO formatting flags
855 * LPITEMIDLIST* ppidlOut) //[out] simple pidl returned
857 static HRESULT WINAPI
IShellFolder_fnSetNameOf (IShellFolder2
* iface
,
862 LPITEMIDLIST
* pPidlOut
)
864 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
865 WCHAR szSrc
[MAX_PATH
+ 1], szDest
[MAX_PATH
+ 1];
867 BOOL bIsFolder
= _ILIsFolder (ILFindLastID (pidl
));
869 TRACE ("(%p)->(%p,pidl=%p,%s,%u,%p)\n", This
, hwndOwner
, pidl
,
870 debugstr_w (lpName
), dwFlags
, pPidlOut
);
872 /* build source path */
873 lstrcpynW(szSrc
, This
->sPathTarget
, MAX_PATH
);
874 ptr
= PathAddBackslashW (szSrc
);
876 _ILSimpleGetTextW (pidl
, ptr
, MAX_PATH
+ 1 - (ptr
- szSrc
));
878 /* build destination path */
879 if (dwFlags
== SHGDN_NORMAL
|| dwFlags
& SHGDN_INFOLDER
) {
880 lstrcpynW(szDest
, This
->sPathTarget
, MAX_PATH
);
881 ptr
= PathAddBackslashW (szDest
);
883 lstrcpynW(ptr
, lpName
, MAX_PATH
+ 1 - (ptr
- szDest
));
885 lstrcpynW(szDest
, lpName
, MAX_PATH
);
887 if(!(dwFlags
& SHGDN_FORPARSING
) && SHELL_FS_HideExtension(szSrc
)) {
888 WCHAR
*ext
= PathFindExtensionW(szSrc
);
890 INT len
= strlenW(szDest
);
891 lstrcpynW(szDest
+ len
, ext
, MAX_PATH
- len
);
895 TRACE ("src=%s dest=%s\n", debugstr_w(szSrc
), debugstr_w(szDest
));
897 if (MoveFileW (szSrc
, szDest
)) {
901 hr
= _ILCreateFromPathW(szDest
, pPidlOut
);
903 SHChangeNotify (bIsFolder
? SHCNE_RENAMEFOLDER
: SHCNE_RENAMEITEM
,
904 SHCNF_PATHW
, szSrc
, szDest
);
912 static HRESULT WINAPI
IShellFolder_fnGetDefaultSearchGUID(IShellFolder2
*iface
, GUID
*guid
)
914 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
915 TRACE("(%p)->(%p)\n", This
, guid
);
919 static HRESULT WINAPI
IShellFolder_fnEnumSearches (IShellFolder2
* iface
,
920 IEnumExtraSearch
** ppenum
)
922 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
923 FIXME ("(%p)\n", This
);
927 static HRESULT WINAPI
928 IShellFolder_fnGetDefaultColumn(IShellFolder2
*iface
, DWORD reserved
, ULONG
*sort
, ULONG
*display
)
930 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
932 TRACE("(%p)->(%#x, %p, %p)\n", This
, reserved
, sort
, display
);
937 static HRESULT WINAPI
938 IShellFolder_fnGetDefaultColumnState (IShellFolder2
* iface
, UINT iColumn
,
941 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
943 TRACE ("(%p)\n", This
);
945 if (!pcsFlags
|| iColumn
>= GENERICSHELLVIEWCOLUMNS
)
948 *pcsFlags
= GenericSFHeader
[iColumn
].pcsFlags
;
953 static HRESULT WINAPI
954 IShellFolder_fnGetDetailsEx (IShellFolder2
* iface
, LPCITEMIDLIST pidl
,
955 const SHCOLUMNID
* pscid
, VARIANT
* pv
)
957 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
958 FIXME ("(%p)\n", This
);
963 static HRESULT WINAPI
964 IShellFolder_fnGetDetailsOf (IShellFolder2
* iface
, LPCITEMIDLIST pidl
,
965 UINT iColumn
, SHELLDETAILS
* psd
)
967 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
970 TRACE ("(%p)->(%p %i %p)\n", This
, pidl
, iColumn
, psd
);
972 if (!psd
|| iColumn
>= GENERICSHELLVIEWCOLUMNS
)
976 /* the header titles */
977 psd
->fmt
= GenericSFHeader
[iColumn
].fmt
;
978 psd
->cxChar
= GenericSFHeader
[iColumn
].cxChar
;
979 psd
->str
.uType
= STRRET_CSTR
;
980 LoadStringA (shell32_hInstance
, GenericSFHeader
[iColumn
].colnameid
,
981 psd
->str
.u
.cStr
, MAX_PATH
);
985 psd
->str
.uType
= STRRET_CSTR
;
986 /* the data from the pidl */
989 hr
= IShellFolder2_GetDisplayNameOf (iface
, pidl
,
990 SHGDN_NORMAL
| SHGDN_INFOLDER
, &psd
->str
);
993 _ILGetFileSize (pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
996 _ILGetFileType (pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
999 _ILGetFileDate (pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
1001 case 4: /* attributes */
1002 _ILGetFileAttributes (pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
1010 static HRESULT WINAPI
1011 IShellFolder_fnMapColumnToSCID (IShellFolder2
*iface
, UINT column
, SHCOLUMNID
*scid
)
1013 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
1015 TRACE("(%p)->(%u %p)\n", This
, column
, scid
);
1017 if (column
>= GENERICSHELLVIEWCOLUMNS
)
1018 return E_INVALIDARG
;
1020 return shellfolder_map_column_to_scid(GenericSFHeader
, column
, scid
);
1023 static const IShellFolder2Vtbl sfvt
=
1025 IShellFolder_fnQueryInterface
,
1026 IShellFolder_fnAddRef
,
1027 IShellFolder_fnRelease
,
1028 IShellFolder_fnParseDisplayName
,
1029 IShellFolder_fnEnumObjects
,
1030 IShellFolder_fnBindToObject
,
1031 IShellFolder_fnBindToStorage
,
1032 IShellFolder_fnCompareIDs
,
1033 IShellFolder_fnCreateViewObject
,
1034 IShellFolder_fnGetAttributesOf
,
1035 IShellFolder_fnGetUIObjectOf
,
1036 IShellFolder_fnGetDisplayNameOf
,
1037 IShellFolder_fnSetNameOf
,
1039 IShellFolder_fnGetDefaultSearchGUID
,
1040 IShellFolder_fnEnumSearches
,
1041 IShellFolder_fnGetDefaultColumn
,
1042 IShellFolder_fnGetDefaultColumnState
,
1043 IShellFolder_fnGetDetailsEx
,
1044 IShellFolder_fnGetDetailsOf
,
1045 IShellFolder_fnMapColumnToSCID
1048 /****************************************************************************
1049 * ISFHelper for IShellFolder implementation
1052 static HRESULT WINAPI
ISFHelper_fnQueryInterface(ISFHelper
*iface
, REFIID riid
, void **ppvObj
)
1054 IGenericSFImpl
*This
= impl_from_ISFHelper(iface
);
1056 return IUnknown_QueryInterface(This
->outer_unk
, riid
, ppvObj
);
1059 static ULONG WINAPI
ISFHelper_fnAddRef(ISFHelper
*iface
)
1061 IGenericSFImpl
*This
= impl_from_ISFHelper(iface
);
1063 return IUnknown_AddRef(This
->outer_unk
);
1066 static ULONG WINAPI
ISFHelper_fnRelease(ISFHelper
*iface
)
1068 IGenericSFImpl
*This
= impl_from_ISFHelper(iface
);
1070 return IUnknown_Release(This
->outer_unk
);
1073 /****************************************************************************
1074 * ISFHelper_fnGetUniqueName
1076 * creates a unique folder name
1079 static HRESULT WINAPI
1080 ISFHelper_fnGetUniqueName (ISFHelper
* iface
, LPWSTR pwszName
, UINT uLen
)
1082 IGenericSFImpl
*This
= impl_from_ISFHelper(iface
);
1085 WCHAR wszText
[MAX_PATH
];
1086 WCHAR wszNewFolder
[25];
1087 static const WCHAR wszFormat
[] = {'%','s',' ','%','d',0 };
1089 TRACE ("(%p)(%p %u)\n", This
, pwszName
, uLen
);
1091 LoadStringW(shell32_hInstance
, IDS_NEWFOLDER
, wszNewFolder
, ARRAY_SIZE(wszNewFolder
));
1092 if (uLen
< ARRAY_SIZE(wszNewFolder
) + 3)
1095 lstrcpynW (pwszName
, wszNewFolder
, uLen
);
1097 hr
= IShellFolder2_EnumObjects(&This
->IShellFolder2_iface
, 0,
1098 SHCONTF_FOLDERS
| SHCONTF_NONFOLDERS
| SHCONTF_INCLUDEHIDDEN
, &penum
);
1105 IEnumIDList_Reset (penum
);
1106 while (S_OK
== IEnumIDList_Next (penum
, 1, &pidl
, &dwFetched
) &&
1108 _ILSimpleGetTextW (pidl
, wszText
, MAX_PATH
);
1109 if (0 == lstrcmpiW (wszText
, pwszName
)) {
1110 snprintfW (pwszName
, uLen
, wszFormat
, wszNewFolder
, i
++);
1119 IEnumIDList_Release (penum
);
1124 /****************************************************************************
1125 * ISFHelper_fnAddFolder
1127 * adds a new folder.
1130 static HRESULT WINAPI
1131 ISFHelper_fnAddFolder (ISFHelper
* iface
, HWND hwnd
, LPCWSTR pwszName
,
1132 LPITEMIDLIST
* ppidlOut
)
1134 IGenericSFImpl
*This
= impl_from_ISFHelper(iface
);
1135 WCHAR wszNewDir
[MAX_PATH
];
1137 HRESULT hres
= E_FAIL
;
1139 TRACE ("(%p)(%s %p)\n", This
, debugstr_w(pwszName
), ppidlOut
);
1142 if (This
->sPathTarget
)
1143 lstrcpynW(wszNewDir
, This
->sPathTarget
, MAX_PATH
);
1144 PathAppendW(wszNewDir
, pwszName
);
1146 bRes
= CreateDirectoryW (wszNewDir
, NULL
);
1148 LPITEMIDLIST relPidl
;
1150 lstrcpyW(wszNewDir
, pwszName
);
1152 hres
= IShellFolder2_ParseDisplayName(&This
->IShellFolder2_iface
, hwnd
, NULL
, wszNewDir
,
1153 NULL
, &relPidl
, NULL
);
1155 if (SUCCEEDED(hres
)) {
1156 LPITEMIDLIST fullPidl
;
1158 fullPidl
= ILCombine(This
->pidlRoot
, relPidl
);
1161 SHChangeNotify(SHCNE_MKDIR
, SHCNF_IDLIST
, fullPidl
, NULL
);
1165 *ppidlOut
= relPidl
;
1169 WARN("failed to combine %s into a full PIDL\n", wine_dbgstr_w(pwszName
));
1174 WARN("failed to parse %s into a PIDL\n", wine_dbgstr_w(pwszName
));
1177 WCHAR wszText
[128 + MAX_PATH
];
1178 WCHAR wszTempText
[128];
1179 WCHAR wszCaption
[256];
1181 /* Cannot Create folder because of permissions */
1182 LoadStringW (shell32_hInstance
, IDS_CREATEFOLDER_DENIED
, wszTempText
, ARRAY_SIZE(wszTempText
));
1183 LoadStringW (shell32_hInstance
, IDS_CREATEFOLDER_CAPTION
, wszCaption
, ARRAY_SIZE(wszCaption
));
1184 sprintfW (wszText
, wszTempText
, wszNewDir
);
1185 MessageBoxW (hwnd
, wszText
, wszCaption
, MB_OK
| MB_ICONEXCLAMATION
);
1191 /****************************************************************************
1194 * Builds a list of paths like the one used in SHFileOperation from a table of
1195 * PIDLs relative to the given base folder
1197 static WCHAR
*build_paths_list(LPCWSTR wszBasePath
, int cidl
, const LPCITEMIDLIST
*pidls
)
1199 WCHAR
*wszPathsList
;
1204 iPathLen
= lstrlenW(wszBasePath
);
1205 wszPathsList
= heap_alloc(MAX_PATH
*sizeof(WCHAR
)*cidl
+1);
1206 wszListPos
= wszPathsList
;
1208 for (i
= 0; i
< cidl
; i
++) {
1209 if (!_ILIsFolder(pidls
[i
]) && !_ILIsValue(pidls
[i
]))
1212 lstrcpynW(wszListPos
, wszBasePath
, MAX_PATH
);
1213 /* FIXME: abort if path too long */
1214 _ILSimpleGetTextW(pidls
[i
], wszListPos
+iPathLen
, MAX_PATH
-iPathLen
);
1215 wszListPos
+= lstrlenW(wszListPos
)+1;
1218 return wszPathsList
;
1221 /****************************************************************************
1222 * ISFHelper_fnDeleteItems
1224 * deletes items in folder
1226 static HRESULT WINAPI
1227 ISFHelper_fnDeleteItems (ISFHelper
* iface
, UINT cidl
, LPCITEMIDLIST
* apidl
)
1229 IGenericSFImpl
*This
= impl_from_ISFHelper(iface
);
1232 WCHAR wszPath
[MAX_PATH
];
1233 WCHAR
*wszPathsList
;
1235 WCHAR
*wszCurrentPath
;
1237 TRACE ("(%p)(%u %p)\n", This
, cidl
, apidl
);
1238 if (cidl
==0) return S_OK
;
1240 if (This
->sPathTarget
)
1241 lstrcpynW(wszPath
, This
->sPathTarget
, MAX_PATH
);
1244 PathAddBackslashW(wszPath
);
1245 wszPathsList
= build_paths_list(wszPath
, cidl
, apidl
);
1247 ZeroMemory(&op
, sizeof(op
));
1248 op
.hwnd
= GetActiveWindow();
1249 op
.wFunc
= FO_DELETE
;
1250 op
.pFrom
= wszPathsList
;
1251 op
.fFlags
= FOF_ALLOWUNDO
;
1252 if (SHFileOperationW(&op
))
1254 WARN("SHFileOperation failed\n");
1260 /* we currently need to manually send the notifies */
1261 wszCurrentPath
= wszPathsList
;
1262 for (i
= 0; i
< cidl
; i
++)
1266 if (_ILIsFolder(apidl
[i
]))
1267 wEventId
= SHCNE_RMDIR
;
1268 else if (_ILIsValue(apidl
[i
]))
1269 wEventId
= SHCNE_DELETE
;
1273 /* check if file exists */
1274 if (GetFileAttributesW(wszCurrentPath
) == INVALID_FILE_ATTRIBUTES
)
1276 LPITEMIDLIST pidl
= ILCombine(This
->pidlRoot
, apidl
[i
]);
1277 SHChangeNotify(wEventId
, SHCNF_IDLIST
, pidl
, NULL
);
1281 wszCurrentPath
+= lstrlenW(wszCurrentPath
)+1;
1283 heap_free(wszPathsList
);
1287 /****************************************************************************
1288 * ISFHelper_fnCopyItems
1290 * copies items to this folder
1292 static HRESULT WINAPI
1293 ISFHelper_fnCopyItems (ISFHelper
* iface
, IShellFolder
* pSFFrom
, UINT cidl
,
1294 LPCITEMIDLIST
* apidl
)
1297 IPersistFolder2
*ppf2
= NULL
;
1298 WCHAR wszSrcPathRoot
[MAX_PATH
],
1299 wszDstPath
[MAX_PATH
+1];
1300 WCHAR
*wszSrcPathsList
;
1301 IGenericSFImpl
*This
= impl_from_ISFHelper(iface
);
1303 SHFILEOPSTRUCTW fop
;
1305 TRACE ("(%p)->(%p,%u,%p)\n", This
, pSFFrom
, cidl
, apidl
);
1307 IShellFolder_QueryInterface (pSFFrom
, &IID_IPersistFolder2
,
1312 if (SUCCEEDED (IPersistFolder2_GetCurFolder (ppf2
, &pidl
))) {
1313 SHGetPathFromIDListW (pidl
, wszSrcPathRoot
);
1314 if (This
->sPathTarget
)
1315 lstrcpynW(wszDstPath
, This
->sPathTarget
, MAX_PATH
);
1318 PathAddBackslashW(wszSrcPathRoot
);
1319 PathAddBackslashW(wszDstPath
);
1320 wszSrcPathsList
= build_paths_list(wszSrcPathRoot
, cidl
, apidl
);
1321 ZeroMemory(&fop
, sizeof(fop
));
1322 fop
.hwnd
= GetActiveWindow();
1323 fop
.wFunc
= FO_COPY
;
1324 fop
.pFrom
= wszSrcPathsList
;
1325 fop
.pTo
= wszDstPath
;
1326 fop
.fFlags
= FOF_ALLOWUNDO
;
1328 if(SHFileOperationW(&fop
))
1330 WARN("Copy failed\n");
1333 heap_free(wszSrcPathsList
);
1336 IPersistFolder2_Release(ppf2
);
1341 static const ISFHelperVtbl shvt
=
1343 ISFHelper_fnQueryInterface
,
1345 ISFHelper_fnRelease
,
1346 ISFHelper_fnGetUniqueName
,
1347 ISFHelper_fnAddFolder
,
1348 ISFHelper_fnDeleteItems
,
1349 ISFHelper_fnCopyItems
1352 /************************************************************************
1353 * IFSFldr_PersistFolder3_QueryInterface
1356 static HRESULT WINAPI
IFSFldr_PersistFolder3_QueryInterface(IPersistFolder3
*iface
, REFIID iid
,
1359 IGenericSFImpl
*This
= impl_from_IPersistFolder3(iface
);
1361 return IUnknown_QueryInterface(This
->outer_unk
, iid
, ppv
);
1364 /************************************************************************
1365 * IFSFldr_PersistFolder3_AddRef
1368 static ULONG WINAPI
IFSFldr_PersistFolder3_AddRef(IPersistFolder3
*iface
)
1370 IGenericSFImpl
*This
= impl_from_IPersistFolder3(iface
);
1372 return IUnknown_AddRef(This
->outer_unk
);
1375 /************************************************************************
1376 * IFSFldr_PersistFolder3_Release
1379 static ULONG WINAPI
IFSFldr_PersistFolder3_Release(IPersistFolder3
*iface
)
1381 IGenericSFImpl
*This
= impl_from_IPersistFolder3(iface
);
1383 return IUnknown_Release(This
->outer_unk
);
1386 /************************************************************************
1387 * IFSFldr_PersistFolder3_GetClassID
1389 static HRESULT WINAPI
1390 IFSFldr_PersistFolder3_GetClassID (IPersistFolder3
* iface
, CLSID
* lpClassId
)
1392 IGenericSFImpl
*This
= impl_from_IPersistFolder3(iface
);
1394 TRACE ("(%p)\n", This
);
1398 *lpClassId
= *This
->pclsid
;
1403 /************************************************************************
1404 * IFSFldr_PersistFolder3_Initialize
1407 * sPathTarget is not set. Don't know how to handle in a non rooted environment.
1409 static HRESULT WINAPI
1410 IFSFldr_PersistFolder3_Initialize (IPersistFolder3
* iface
, LPCITEMIDLIST pidl
)
1412 WCHAR wszTemp
[MAX_PATH
];
1414 IGenericSFImpl
*This
= impl_from_IPersistFolder3(iface
);
1416 TRACE ("(%p)->(%p)\n", This
, pidl
);
1418 SHFree (This
->pidlRoot
); /* free the old pidl */
1419 This
->pidlRoot
= ILClone (pidl
); /* set my pidl */
1421 SHFree (This
->sPathTarget
);
1422 This
->sPathTarget
= NULL
;
1425 if (SHGetPathFromIDListW (pidl
, wszTemp
)) {
1426 int len
= strlenW(wszTemp
);
1427 This
->sPathTarget
= SHAlloc((len
+ 1) * sizeof(WCHAR
));
1428 if (!This
->sPathTarget
)
1429 return E_OUTOFMEMORY
;
1430 memcpy(This
->sPathTarget
, wszTemp
, (len
+ 1) * sizeof(WCHAR
));
1433 TRACE ("--(%p)->(%s)\n", This
, debugstr_w(This
->sPathTarget
));
1437 /**************************************************************************
1438 * IFSFldr_PersistFolder3_GetCurFolder
1440 static HRESULT WINAPI
1441 IFSFldr_PersistFolder3_fnGetCurFolder (IPersistFolder3
* iface
,
1442 LPITEMIDLIST
* pidl
)
1444 IGenericSFImpl
*This
= impl_from_IPersistFolder3(iface
);
1446 TRACE ("(%p)->(%p)\n", This
, pidl
);
1448 if (!pidl
) return E_POINTER
;
1449 *pidl
= ILClone (This
->pidlRoot
);
1453 /**************************************************************************
1454 * IFSFldr_PersistFolder3_InitializeEx
1456 * FIXME: error handling
1458 static HRESULT WINAPI
1459 IFSFldr_PersistFolder3_InitializeEx (IPersistFolder3
* iface
,
1460 IBindCtx
* pbc
, LPCITEMIDLIST pidlRoot
,
1461 const PERSIST_FOLDER_TARGET_INFO
* ppfti
)
1463 WCHAR wszTemp
[MAX_PATH
];
1465 IGenericSFImpl
*This
= impl_from_IPersistFolder3(iface
);
1467 TRACE ("(%p)->(%p,%p,%p)\n", This
, pbc
, pidlRoot
, ppfti
);
1469 TRACE ("--%p %s %s 0x%08x 0x%08x\n",
1470 ppfti
->pidlTargetFolder
, debugstr_w (ppfti
->szTargetParsingName
),
1471 debugstr_w (ppfti
->szNetworkProvider
), ppfti
->dwAttributes
,
1475 if (ppfti
&& ppfti
->pidlTargetFolder
)
1476 pdump (ppfti
->pidlTargetFolder
);
1480 SHFree(This
->pidlRoot
);
1481 This
->pidlRoot
= NULL
;
1483 if (This
->sPathTarget
)
1485 SHFree(This
->sPathTarget
);
1486 This
->sPathTarget
= NULL
;
1490 * Root path and pidl
1492 This
->pidlRoot
= ILClone (pidlRoot
);
1495 * the target folder is specified in csidl OR pidlTargetFolder OR
1496 * szTargetParsingName
1499 if (ppfti
->csidl
!= -1) {
1500 if (SHGetSpecialFolderPathW (0, wszTemp
, ppfti
->csidl
,
1501 ppfti
->csidl
& CSIDL_FLAG_CREATE
)) {
1502 int len
= strlenW(wszTemp
);
1503 This
->sPathTarget
= SHAlloc((len
+ 1) * sizeof(WCHAR
));
1504 if (!This
->sPathTarget
)
1505 return E_OUTOFMEMORY
;
1506 memcpy(This
->sPathTarget
, wszTemp
, (len
+ 1) * sizeof(WCHAR
));
1508 } else if (ppfti
->szTargetParsingName
[0]) {
1509 int len
= strlenW(ppfti
->szTargetParsingName
);
1510 This
->sPathTarget
= SHAlloc((len
+ 1) * sizeof(WCHAR
));
1511 if (!This
->sPathTarget
)
1512 return E_OUTOFMEMORY
;
1513 memcpy(This
->sPathTarget
, ppfti
->szTargetParsingName
,
1514 (len
+ 1) * sizeof(WCHAR
));
1515 } else if (ppfti
->pidlTargetFolder
) {
1516 if (SHGetPathFromIDListW(ppfti
->pidlTargetFolder
, wszTemp
)) {
1517 int len
= strlenW(wszTemp
);
1518 This
->sPathTarget
= SHAlloc((len
+ 1) * sizeof(WCHAR
));
1519 if (!This
->sPathTarget
)
1520 return E_OUTOFMEMORY
;
1521 memcpy(This
->sPathTarget
, wszTemp
, (len
+ 1) * sizeof(WCHAR
));
1526 TRACE ("--(%p)->(target=%s)\n", This
, debugstr_w(This
->sPathTarget
));
1527 pdump (This
->pidlRoot
);
1528 return (This
->sPathTarget
) ? S_OK
: E_FAIL
;
1531 static HRESULT WINAPI
1532 IFSFldr_PersistFolder3_GetFolderTargetInfo (IPersistFolder3
* iface
,
1533 PERSIST_FOLDER_TARGET_INFO
* ppfti
)
1535 IGenericSFImpl
*This
= impl_from_IPersistFolder3(iface
);
1536 FIXME ("(%p)->(%p)\n", This
, ppfti
);
1537 ZeroMemory (ppfti
, sizeof (*ppfti
));
1541 static const IPersistFolder3Vtbl pfvt
=
1543 IFSFldr_PersistFolder3_QueryInterface
,
1544 IFSFldr_PersistFolder3_AddRef
,
1545 IFSFldr_PersistFolder3_Release
,
1546 IFSFldr_PersistFolder3_GetClassID
,
1547 IFSFldr_PersistFolder3_Initialize
,
1548 IFSFldr_PersistFolder3_fnGetCurFolder
,
1549 IFSFldr_PersistFolder3_InitializeEx
,
1550 IFSFldr_PersistFolder3_GetFolderTargetInfo
1553 /****************************************************************************
1554 * ISFDropTarget implementation
1556 static HRESULT WINAPI
ISFDropTarget_QueryInterface(IDropTarget
*iface
, REFIID riid
, void **ppv
)
1558 IGenericSFImpl
*This
= impl_from_IDropTarget(iface
);
1560 return IUnknown_QueryInterface(This
->outer_unk
, riid
, ppv
);
1563 static ULONG WINAPI
ISFDropTarget_AddRef(IDropTarget
*iface
)
1565 IGenericSFImpl
*This
= impl_from_IDropTarget(iface
);
1567 return IUnknown_AddRef(This
->outer_unk
);
1570 static ULONG WINAPI
ISFDropTarget_Release(IDropTarget
*iface
)
1572 IGenericSFImpl
*This
= impl_from_IDropTarget(iface
);
1574 return IUnknown_Release(This
->outer_unk
);
1577 static HRESULT WINAPI
1578 ISFDropTarget_DragEnter (IDropTarget
* iface
, IDataObject
* pDataObject
,
1579 DWORD dwKeyState
, POINTL pt
, DWORD
* pdwEffect
)
1583 IGenericSFImpl
*This
= impl_from_IDropTarget(iface
);
1585 TRACE ("(%p)->(DataObject=%p)\n", This
, pDataObject
);
1587 InitFormatEtc (fmt
, This
->cfShellIDList
, TYMED_HGLOBAL
);
1588 This
->fAcceptFmt
= IDataObject_QueryGetData (pDataObject
, &fmt
) == S_OK
;
1589 if (This
->fAcceptFmt
)
1590 *pdwEffect
= KeyStateToDropEffect(dwKeyState
);
1592 *pdwEffect
= DROPEFFECT_NONE
;
1597 static HRESULT WINAPI
1598 ISFDropTarget_DragOver (IDropTarget
* iface
, DWORD dwKeyState
, POINTL pt
,
1601 IGenericSFImpl
*This
= impl_from_IDropTarget(iface
);
1603 TRACE ("(%p)\n", This
);
1606 return E_INVALIDARG
;
1608 if (This
->fAcceptFmt
)
1609 *pdwEffect
= KeyStateToDropEffect(dwKeyState
);
1611 *pdwEffect
= DROPEFFECT_NONE
;
1616 static HRESULT WINAPI
ISFDropTarget_DragLeave (IDropTarget
* iface
)
1618 IGenericSFImpl
*This
= impl_from_IDropTarget(iface
);
1620 TRACE ("(%p)\n", This
);
1622 This
->fAcceptFmt
= FALSE
;
1627 static HRESULT WINAPI
1628 ISFDropTarget_Drop (IDropTarget
* iface
, IDataObject
* pDataObject
,
1629 DWORD dwKeyState
, POINTL pt
, DWORD
* pdwEffect
)
1631 IGenericSFImpl
*This
= impl_from_IDropTarget(iface
);
1633 FIXME ("(%p) object dropped\n", This
);
1638 static const IDropTargetVtbl dtvt
= {
1639 ISFDropTarget_QueryInterface
,
1640 ISFDropTarget_AddRef
,
1641 ISFDropTarget_Release
,
1642 ISFDropTarget_DragEnter
,
1643 ISFDropTarget_DragOver
,
1644 ISFDropTarget_DragLeave
,
1648 HRESULT WINAPI
IFSFolder_Constructor(IUnknown
*outer_unk
, REFIID riid
, void **ppv
)
1653 TRACE("outer_unk=%p %s\n", outer_unk
, shdebugstr_guid(riid
));
1655 if (outer_unk
&& !IsEqualIID(riid
, &IID_IUnknown
))
1656 return CLASS_E_NOAGGREGATION
;
1658 sf
= LocalAlloc(LMEM_ZEROINIT
, sizeof(*sf
));
1660 return E_OUTOFMEMORY
;
1663 sf
->IUnknown_inner
.lpVtbl
= &unkvt
;
1664 sf
->IShellFolder2_iface
.lpVtbl
= &sfvt
;
1665 sf
->IPersistFolder3_iface
.lpVtbl
= &pfvt
;
1666 sf
->IDropTarget_iface
.lpVtbl
= &dtvt
;
1667 sf
->ISFHelper_iface
.lpVtbl
= &shvt
;
1668 sf
->pclsid
= (CLSID
*) & CLSID_ShellFSFolder
;
1669 sf
->outer_unk
= outer_unk
? outer_unk
: &sf
->IUnknown_inner
;
1671 hr
= IUnknown_QueryInterface(&sf
->IUnknown_inner
, riid
, ppv
);
1672 IUnknown_Release(&sf
->IUnknown_inner
);
1674 TRACE ("--%p\n", *ppv
);