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
[] = {
186 {IDS_SHV_COLUMN1
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 15},
187 {IDS_SHV_COLUMN2
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 10},
188 {IDS_SHV_COLUMN3
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 10},
189 {IDS_SHV_COLUMN4
, SHCOLSTATE_TYPE_DATE
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 12},
190 {IDS_SHV_COLUMN5
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 5}
193 #define GENERICSHELLVIEWCOLUMNS 5
195 /**************************************************************************
196 * IShellFolder_fnQueryInterface
198 static HRESULT WINAPI
IShellFolder_fnQueryInterface(IShellFolder2
*iface
, REFIID riid
,
201 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
203 return IUnknown_QueryInterface(This
->outer_unk
, riid
, ppvObj
);
206 /**************************************************************************
207 * IShellFolder_AddRef
209 static ULONG WINAPI
IShellFolder_fnAddRef(IShellFolder2
*iface
)
211 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
213 return IUnknown_AddRef(This
->outer_unk
);
216 /**************************************************************************
217 * IShellFolder_fnRelease
219 static ULONG WINAPI
IShellFolder_fnRelease(IShellFolder2
*iface
)
221 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
223 return IUnknown_Release(This
->outer_unk
);
226 /**************************************************************************
227 * SHELL32_CreatePidlFromBindCtx [internal]
229 * If the caller bound File System Bind Data, assume it is the
230 * find data for the path.
231 * This allows binding of paths that don't exist.
233 LPITEMIDLIST
SHELL32_CreatePidlFromBindCtx(IBindCtx
*pbc
, LPCWSTR path
)
235 static WCHAR szfsbc
[] = {
236 'F','i','l','e',' ','S','y','s','t','e','m',' ',
237 'B','i','n','d',' ','D','a','t','a',0 };
238 IFileSystemBindData
*fsbd
= NULL
;
239 LPITEMIDLIST pidl
= NULL
;
240 IUnknown
*unk
= NULL
;
243 TRACE("%p %s\n", pbc
, debugstr_w(path
));
248 /* see if the caller bound File System Bind Data */
249 r
= IBindCtx_GetObjectParam( pbc
, szfsbc
, &unk
);
253 r
= IUnknown_QueryInterface( unk
, &IID_IFileSystemBindData
, (void**)&fsbd
);
256 WIN32_FIND_DATAW wfd
;
258 r
= IFileSystemBindData_GetFindData( fsbd
, &wfd
);
261 lstrcpynW( &wfd
.cFileName
[0], path
, MAX_PATH
);
262 pidl
= _ILCreateFromFindDataW( &wfd
);
264 IFileSystemBindData_Release( fsbd
);
266 IUnknown_Release( unk
);
271 /**************************************************************************
272 * IShellFolder_ParseDisplayName {SHELL32}
274 * Parse a display name.
277 * hwndOwner [in] Parent window for any message's
278 * pbc [in] optional FileSystemBindData context
279 * lpszDisplayName [in] Unicode displayname.
280 * pchEaten [out] (unicode) characters processed
281 * ppidl [out] complex pidl to item
282 * pdwAttributes [out] items attributes
285 * Every folder tries to parse only its own (the leftmost) pidl and creates a
286 * subfolder to evaluate the remaining parts.
287 * Now we can parse into namespaces implemented by shell extensions
289 * Behaviour on win98: lpszDisplayName=NULL -> crash
290 * lpszDisplayName="" -> returns mycoputer-pidl
293 * pdwAttributes is not set
294 * pchEaten is not set like in windows
296 static HRESULT WINAPI
297 IShellFolder_fnParseDisplayName (IShellFolder2
* iface
,
300 LPOLESTR lpszDisplayName
,
301 DWORD
* pchEaten
, LPITEMIDLIST
* ppidl
,
302 DWORD
* pdwAttributes
)
304 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
306 HRESULT hr
= E_INVALIDARG
;
307 LPCWSTR szNext
= NULL
;
308 WCHAR szElement
[MAX_PATH
];
309 WCHAR szPath
[MAX_PATH
];
310 LPITEMIDLIST pidlTemp
= NULL
;
313 TRACE ("(%p)->(HWND=%p,%p,%p=%s,%p,pidl=%p,%p)\n",
314 This
, hwndOwner
, pbc
, lpszDisplayName
, debugstr_w (lpszDisplayName
),
315 pchEaten
, ppidl
, pdwAttributes
);
317 if (!lpszDisplayName
|| !ppidl
)
321 *pchEaten
= 0; /* strange but like the original */
323 pidlTemp
= SHELL32_CreatePidlFromBindCtx(pbc
, lpszDisplayName
);
324 if (!pidlTemp
&& *lpszDisplayName
)
326 /* get the next element */
327 szNext
= GetNextElementW (lpszDisplayName
, szElement
, MAX_PATH
);
329 /* build the full pathname to the element */
330 lstrcpynW(szPath
, This
->sPathTarget
, MAX_PATH
- 1);
331 PathAddBackslashW(szPath
);
332 len
= lstrlenW(szPath
);
333 lstrcpynW(szPath
+ len
, szElement
, MAX_PATH
- len
);
336 hr
= _ILCreateFromPathW(szPath
, &pidlTemp
);
339 if (szNext
&& *szNext
) {
340 /* try to analyse the next element */
341 hr
= SHELL32_ParseNextElement (iface
, hwndOwner
, pbc
,
342 &pidlTemp
, (LPOLESTR
) szNext
, pchEaten
, pdwAttributes
);
344 /* it's the last element */
345 if (pdwAttributes
&& *pdwAttributes
)
346 hr
= SHELL32_GetItemAttributes(&This
->IShellFolder2_iface
, pidlTemp
, pdwAttributes
);
356 TRACE ("(%p)->(-- pidl=%p ret=0x%08x)\n", This
, *ppidl
, hr
);
361 /**************************************************************************
362 * IShellFolder_fnEnumObjects
364 * HWND hwndOwner, //[in ] Parent Window
365 * DWORD grfFlags, //[in ] SHCONTF enumeration mask
366 * LPENUMIDLIST* ppenumIDList //[out] IEnumIDList interface
368 static HRESULT WINAPI
369 IShellFolder_fnEnumObjects (IShellFolder2
* iface
, HWND hwndOwner
,
370 DWORD dwFlags
, LPENUMIDLIST
* ppEnumIDList
)
372 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
373 IEnumIDListImpl
*list
;
375 TRACE ("(%p)->(HWND=%p flags=0x%08x pplist=%p)\n", This
, hwndOwner
,
376 dwFlags
, ppEnumIDList
);
378 if (!(list
= IEnumIDList_Constructor()))
379 return E_OUTOFMEMORY
;
380 CreateFolderEnumList(list
, This
->sPathTarget
, dwFlags
);
381 *ppEnumIDList
= &list
->IEnumIDList_iface
;
383 TRACE ("-- (%p)->(new ID List: %p)\n", This
, *ppEnumIDList
);
388 /**************************************************************************
389 * IShellFolder_fnBindToObject
391 * LPCITEMIDLIST pidl, //[in ] relative pidl to open
392 * LPBC pbc, //[in ] optional FileSystemBindData context
393 * REFIID riid, //[in ] Initial Interface
394 * LPVOID* ppvObject //[out] Interface*
396 static HRESULT WINAPI
397 IShellFolder_fnBindToObject (IShellFolder2
* iface
, LPCITEMIDLIST pidl
,
398 LPBC pbc
, REFIID riid
, LPVOID
* ppvOut
)
400 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
402 TRACE ("(%p)->(pidl=%p,%p,%s,%p)\n", This
, pidl
, pbc
,
403 shdebugstr_guid (riid
), ppvOut
);
405 return SHELL32_BindToChild (This
->pidlRoot
, This
->sPathTarget
, pidl
, riid
,
409 /**************************************************************************
410 * IShellFolder_fnBindToStorage
412 * LPCITEMIDLIST pidl, //[in ] complex pidl to store
413 * LPBC pbc, //[in ] reserved
414 * REFIID riid, //[in ] Initial storage interface
415 * LPVOID* ppvObject //[out] Interface* returned
417 static HRESULT WINAPI
418 IShellFolder_fnBindToStorage (IShellFolder2
* iface
, LPCITEMIDLIST pidl
,
419 LPBC pbcReserved
, REFIID riid
, LPVOID
* ppvOut
)
421 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
423 FIXME ("(%p)->(pidl=%p,%p,%s,%p) stub\n", This
, pidl
, pbcReserved
,
424 shdebugstr_guid (riid
), ppvOut
);
430 /**************************************************************************
431 * IShellFolder_fnCompareIDs
434 static HRESULT WINAPI
435 IShellFolder_fnCompareIDs (IShellFolder2
* iface
, LPARAM lParam
,
436 LPCITEMIDLIST pidl1
, LPCITEMIDLIST pidl2
)
438 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
442 TRACE ("(%p)->(0x%08lx,pidl1=%p,pidl2=%p)\n", This
, lParam
, pidl1
, pidl2
);
443 nReturn
= SHELL32_CompareIDs(&This
->IShellFolder2_iface
, lParam
, pidl1
, pidl2
);
444 TRACE ("-- %i\n", nReturn
);
448 /**************************************************************************
449 * IShellFolder_fnCreateViewObject
451 static HRESULT WINAPI
452 IShellFolder_fnCreateViewObject (IShellFolder2
* iface
, HWND hwndOwner
,
453 REFIID riid
, LPVOID
* ppvOut
)
455 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
457 LPSHELLVIEW pShellView
;
458 HRESULT hr
= E_INVALIDARG
;
460 TRACE ("(%p)->(hwnd=%p,%s,%p)\n", This
, hwndOwner
, shdebugstr_guid (riid
),
466 if (IsEqualIID (riid
, &IID_IDropTarget
)) {
467 hr
= IShellFolder2_QueryInterface (iface
, &IID_IDropTarget
, ppvOut
);
468 } else if (IsEqualIID (riid
, &IID_IContextMenu
)) {
469 FIXME ("IContextMenu not implemented\n");
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
,
915 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
916 FIXME ("(%p)\n", This
);
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 dwRes
,
929 ULONG
* pSort
, ULONG
* pDisplay
)
931 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
933 TRACE ("(%p)\n", This
);
943 static HRESULT WINAPI
944 IShellFolder_fnGetDefaultColumnState (IShellFolder2
* iface
, UINT iColumn
,
947 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
949 TRACE ("(%p)\n", This
);
951 if (!pcsFlags
|| iColumn
>= GENERICSHELLVIEWCOLUMNS
)
954 *pcsFlags
= GenericSFHeader
[iColumn
].pcsFlags
;
959 static HRESULT WINAPI
960 IShellFolder_fnGetDetailsEx (IShellFolder2
* iface
, LPCITEMIDLIST pidl
,
961 const SHCOLUMNID
* pscid
, VARIANT
* pv
)
963 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
964 FIXME ("(%p)\n", This
);
969 static HRESULT WINAPI
970 IShellFolder_fnGetDetailsOf (IShellFolder2
* iface
, LPCITEMIDLIST pidl
,
971 UINT iColumn
, SHELLDETAILS
* psd
)
973 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
976 TRACE ("(%p)->(%p %i %p)\n", This
, pidl
, iColumn
, psd
);
978 if (!psd
|| iColumn
>= GENERICSHELLVIEWCOLUMNS
)
982 /* the header titles */
983 psd
->fmt
= GenericSFHeader
[iColumn
].fmt
;
984 psd
->cxChar
= GenericSFHeader
[iColumn
].cxChar
;
985 psd
->str
.uType
= STRRET_CSTR
;
986 LoadStringA (shell32_hInstance
, GenericSFHeader
[iColumn
].colnameid
,
987 psd
->str
.u
.cStr
, MAX_PATH
);
991 psd
->str
.uType
= STRRET_CSTR
;
992 /* the data from the pidl */
995 hr
= IShellFolder2_GetDisplayNameOf (iface
, pidl
,
996 SHGDN_NORMAL
| SHGDN_INFOLDER
, &psd
->str
);
999 _ILGetFileSize (pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
1002 _ILGetFileType (pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
1005 _ILGetFileDate (pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
1007 case 4: /* attributes */
1008 _ILGetFileAttributes (pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
1016 static HRESULT WINAPI
1017 IShellFolder_fnMapColumnToSCID (IShellFolder2
* iface
, UINT column
,
1020 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
1021 FIXME ("(%p)\n", This
);
1025 static const IShellFolder2Vtbl sfvt
=
1027 IShellFolder_fnQueryInterface
,
1028 IShellFolder_fnAddRef
,
1029 IShellFolder_fnRelease
,
1030 IShellFolder_fnParseDisplayName
,
1031 IShellFolder_fnEnumObjects
,
1032 IShellFolder_fnBindToObject
,
1033 IShellFolder_fnBindToStorage
,
1034 IShellFolder_fnCompareIDs
,
1035 IShellFolder_fnCreateViewObject
,
1036 IShellFolder_fnGetAttributesOf
,
1037 IShellFolder_fnGetUIObjectOf
,
1038 IShellFolder_fnGetDisplayNameOf
,
1039 IShellFolder_fnSetNameOf
,
1041 IShellFolder_fnGetDefaultSearchGUID
,
1042 IShellFolder_fnEnumSearches
,
1043 IShellFolder_fnGetDefaultColumn
,
1044 IShellFolder_fnGetDefaultColumnState
,
1045 IShellFolder_fnGetDetailsEx
,
1046 IShellFolder_fnGetDetailsOf
,
1047 IShellFolder_fnMapColumnToSCID
1050 /****************************************************************************
1051 * ISFHelper for IShellFolder implementation
1054 static HRESULT WINAPI
ISFHelper_fnQueryInterface(ISFHelper
*iface
, REFIID riid
, void **ppvObj
)
1056 IGenericSFImpl
*This
= impl_from_ISFHelper(iface
);
1058 return IUnknown_QueryInterface(This
->outer_unk
, riid
, ppvObj
);
1061 static ULONG WINAPI
ISFHelper_fnAddRef(ISFHelper
*iface
)
1063 IGenericSFImpl
*This
= impl_from_ISFHelper(iface
);
1065 return IUnknown_AddRef(This
->outer_unk
);
1068 static ULONG WINAPI
ISFHelper_fnRelease(ISFHelper
*iface
)
1070 IGenericSFImpl
*This
= impl_from_ISFHelper(iface
);
1072 return IUnknown_Release(This
->outer_unk
);
1075 /****************************************************************************
1076 * ISFHelper_fnGetUniqueName
1078 * creates a unique folder name
1081 static HRESULT WINAPI
1082 ISFHelper_fnGetUniqueName (ISFHelper
* iface
, LPWSTR pwszName
, UINT uLen
)
1084 IGenericSFImpl
*This
= impl_from_ISFHelper(iface
);
1087 WCHAR wszText
[MAX_PATH
];
1088 WCHAR wszNewFolder
[25];
1089 const WCHAR wszFormat
[] = {'%','s',' ','%','d',0 };
1091 TRACE ("(%p)(%p %u)\n", This
, pwszName
, uLen
);
1093 LoadStringW(shell32_hInstance
, IDS_NEWFOLDER
, wszNewFolder
, sizeof(wszNewFolder
)/sizeof(WCHAR
));
1094 if (uLen
< sizeof(wszNewFolder
)/sizeof(WCHAR
) + 3)
1097 lstrcpynW (pwszName
, wszNewFolder
, uLen
);
1099 hr
= IShellFolder2_EnumObjects(&This
->IShellFolder2_iface
, 0,
1100 SHCONTF_FOLDERS
| SHCONTF_NONFOLDERS
| SHCONTF_INCLUDEHIDDEN
, &penum
);
1107 IEnumIDList_Reset (penum
);
1108 while (S_OK
== IEnumIDList_Next (penum
, 1, &pidl
, &dwFetched
) &&
1110 _ILSimpleGetTextW (pidl
, wszText
, MAX_PATH
);
1111 if (0 == lstrcmpiW (wszText
, pwszName
)) {
1112 snprintfW (pwszName
, uLen
, wszFormat
, wszNewFolder
, i
++);
1121 IEnumIDList_Release (penum
);
1126 /****************************************************************************
1127 * ISFHelper_fnAddFolder
1129 * adds a new folder.
1132 static HRESULT WINAPI
1133 ISFHelper_fnAddFolder (ISFHelper
* iface
, HWND hwnd
, LPCWSTR pwszName
,
1134 LPITEMIDLIST
* ppidlOut
)
1136 IGenericSFImpl
*This
= impl_from_ISFHelper(iface
);
1137 WCHAR wszNewDir
[MAX_PATH
];
1139 HRESULT hres
= E_FAIL
;
1141 TRACE ("(%p)(%s %p)\n", This
, debugstr_w(pwszName
), ppidlOut
);
1144 if (This
->sPathTarget
)
1145 lstrcpynW(wszNewDir
, This
->sPathTarget
, MAX_PATH
);
1146 PathAppendW(wszNewDir
, pwszName
);
1148 bRes
= CreateDirectoryW (wszNewDir
, NULL
);
1150 LPITEMIDLIST relPidl
;
1152 lstrcpyW(wszNewDir
, pwszName
);
1154 hres
= IShellFolder2_ParseDisplayName(&This
->IShellFolder2_iface
, hwnd
, NULL
, wszNewDir
,
1155 NULL
, &relPidl
, NULL
);
1157 if (SUCCEEDED(hres
)) {
1158 LPITEMIDLIST fullPidl
;
1160 fullPidl
= ILCombine(This
->pidlRoot
, relPidl
);
1163 SHChangeNotify(SHCNE_MKDIR
, SHCNF_IDLIST
, fullPidl
, NULL
);
1167 *ppidlOut
= relPidl
;
1171 WARN("failed to combine %s into a full PIDL\n", wine_dbgstr_w(pwszName
));
1176 WARN("failed to parse %s into a PIDL\n", wine_dbgstr_w(pwszName
));
1179 WCHAR wszText
[128 + MAX_PATH
];
1180 WCHAR wszTempText
[128];
1181 WCHAR wszCaption
[256];
1183 /* Cannot Create folder because of permissions */
1184 LoadStringW (shell32_hInstance
, IDS_CREATEFOLDER_DENIED
, wszTempText
,
1185 sizeof (wszTempText
)/sizeof (wszTempText
[0]));
1186 LoadStringW (shell32_hInstance
, IDS_CREATEFOLDER_CAPTION
, wszCaption
,
1187 sizeof (wszCaption
)/sizeof (wszCaption
[0]));
1188 sprintfW (wszText
, wszTempText
, wszNewDir
);
1189 MessageBoxW (hwnd
, wszText
, wszCaption
, MB_OK
| MB_ICONEXCLAMATION
);
1195 /****************************************************************************
1198 * Builds a list of paths like the one used in SHFileOperation from a table of
1199 * PIDLs relative to the given base folder
1201 static WCHAR
*build_paths_list(LPCWSTR wszBasePath
, int cidl
, const LPCITEMIDLIST
*pidls
)
1203 WCHAR
*wszPathsList
;
1208 iPathLen
= lstrlenW(wszBasePath
);
1209 wszPathsList
= HeapAlloc(GetProcessHeap(), 0, MAX_PATH
*sizeof(WCHAR
)*cidl
+1);
1210 wszListPos
= wszPathsList
;
1212 for (i
= 0; i
< cidl
; i
++) {
1213 if (!_ILIsFolder(pidls
[i
]) && !_ILIsValue(pidls
[i
]))
1216 lstrcpynW(wszListPos
, wszBasePath
, MAX_PATH
);
1217 /* FIXME: abort if path too long */
1218 _ILSimpleGetTextW(pidls
[i
], wszListPos
+iPathLen
, MAX_PATH
-iPathLen
);
1219 wszListPos
+= lstrlenW(wszListPos
)+1;
1222 return wszPathsList
;
1225 /****************************************************************************
1226 * ISFHelper_fnDeleteItems
1228 * deletes items in folder
1230 static HRESULT WINAPI
1231 ISFHelper_fnDeleteItems (ISFHelper
* iface
, UINT cidl
, LPCITEMIDLIST
* apidl
)
1233 IGenericSFImpl
*This
= impl_from_ISFHelper(iface
);
1236 WCHAR wszPath
[MAX_PATH
];
1237 WCHAR
*wszPathsList
;
1239 WCHAR
*wszCurrentPath
;
1241 TRACE ("(%p)(%u %p)\n", This
, cidl
, apidl
);
1242 if (cidl
==0) return S_OK
;
1244 if (This
->sPathTarget
)
1245 lstrcpynW(wszPath
, This
->sPathTarget
, MAX_PATH
);
1248 PathAddBackslashW(wszPath
);
1249 wszPathsList
= build_paths_list(wszPath
, cidl
, apidl
);
1251 ZeroMemory(&op
, sizeof(op
));
1252 op
.hwnd
= GetActiveWindow();
1253 op
.wFunc
= FO_DELETE
;
1254 op
.pFrom
= wszPathsList
;
1255 op
.fFlags
= FOF_ALLOWUNDO
;
1256 if (SHFileOperationW(&op
))
1258 WARN("SHFileOperation failed\n");
1264 /* we currently need to manually send the notifies */
1265 wszCurrentPath
= wszPathsList
;
1266 for (i
= 0; i
< cidl
; i
++)
1270 if (_ILIsFolder(apidl
[i
]))
1271 wEventId
= SHCNE_RMDIR
;
1272 else if (_ILIsValue(apidl
[i
]))
1273 wEventId
= SHCNE_DELETE
;
1277 /* check if file exists */
1278 if (GetFileAttributesW(wszCurrentPath
) == INVALID_FILE_ATTRIBUTES
)
1280 LPITEMIDLIST pidl
= ILCombine(This
->pidlRoot
, apidl
[i
]);
1281 SHChangeNotify(wEventId
, SHCNF_IDLIST
, pidl
, NULL
);
1285 wszCurrentPath
+= lstrlenW(wszCurrentPath
)+1;
1287 HeapFree(GetProcessHeap(), 0, wszPathsList
);
1291 /****************************************************************************
1292 * ISFHelper_fnCopyItems
1294 * copies items to this folder
1296 static HRESULT WINAPI
1297 ISFHelper_fnCopyItems (ISFHelper
* iface
, IShellFolder
* pSFFrom
, UINT cidl
,
1298 LPCITEMIDLIST
* apidl
)
1301 IPersistFolder2
*ppf2
= NULL
;
1302 WCHAR wszSrcPathRoot
[MAX_PATH
],
1303 wszDstPath
[MAX_PATH
+1];
1304 WCHAR
*wszSrcPathsList
;
1305 IGenericSFImpl
*This
= impl_from_ISFHelper(iface
);
1307 SHFILEOPSTRUCTW fop
;
1309 TRACE ("(%p)->(%p,%u,%p)\n", This
, pSFFrom
, cidl
, apidl
);
1311 IShellFolder_QueryInterface (pSFFrom
, &IID_IPersistFolder2
,
1316 if (SUCCEEDED (IPersistFolder2_GetCurFolder (ppf2
, &pidl
))) {
1317 SHGetPathFromIDListW (pidl
, wszSrcPathRoot
);
1318 ZeroMemory(wszDstPath
, MAX_PATH
+1);
1319 if (This
->sPathTarget
)
1320 lstrcpynW(wszDstPath
, This
->sPathTarget
, MAX_PATH
);
1321 PathAddBackslashW(wszSrcPathRoot
);
1322 PathAddBackslashW(wszDstPath
);
1323 wszSrcPathsList
= build_paths_list(wszSrcPathRoot
, cidl
, apidl
);
1324 ZeroMemory(&fop
, sizeof(fop
));
1325 fop
.hwnd
= GetActiveWindow();
1326 fop
.wFunc
= FO_COPY
;
1327 fop
.pFrom
= wszSrcPathsList
;
1328 fop
.pTo
= wszDstPath
;
1329 fop
.fFlags
= FOF_ALLOWUNDO
;
1331 if(SHFileOperationW(&fop
))
1333 WARN("Copy failed\n");
1336 HeapFree(GetProcessHeap(), 0, wszSrcPathsList
);
1340 IPersistFolder2_Release(ppf2
);
1345 static const ISFHelperVtbl shvt
=
1347 ISFHelper_fnQueryInterface
,
1349 ISFHelper_fnRelease
,
1350 ISFHelper_fnGetUniqueName
,
1351 ISFHelper_fnAddFolder
,
1352 ISFHelper_fnDeleteItems
,
1353 ISFHelper_fnCopyItems
1356 /************************************************************************
1357 * IFSFldr_PersistFolder3_QueryInterface
1360 static HRESULT WINAPI
IFSFldr_PersistFolder3_QueryInterface(IPersistFolder3
*iface
, REFIID iid
,
1363 IGenericSFImpl
*This
= impl_from_IPersistFolder3(iface
);
1365 return IUnknown_QueryInterface(This
->outer_unk
, iid
, ppv
);
1368 /************************************************************************
1369 * IFSFldr_PersistFolder3_AddRef
1372 static ULONG WINAPI
IFSFldr_PersistFolder3_AddRef(IPersistFolder3
*iface
)
1374 IGenericSFImpl
*This
= impl_from_IPersistFolder3(iface
);
1376 return IUnknown_AddRef(This
->outer_unk
);
1379 /************************************************************************
1380 * IFSFldr_PersistFolder3_Release
1383 static ULONG WINAPI
IFSFldr_PersistFolder3_Release(IPersistFolder3
*iface
)
1385 IGenericSFImpl
*This
= impl_from_IPersistFolder3(iface
);
1387 return IUnknown_Release(This
->outer_unk
);
1390 /************************************************************************
1391 * IFSFldr_PersistFolder3_GetClassID
1393 static HRESULT WINAPI
1394 IFSFldr_PersistFolder3_GetClassID (IPersistFolder3
* iface
, CLSID
* lpClassId
)
1396 IGenericSFImpl
*This
= impl_from_IPersistFolder3(iface
);
1398 TRACE ("(%p)\n", This
);
1402 *lpClassId
= *This
->pclsid
;
1407 /************************************************************************
1408 * IFSFldr_PersistFolder3_Initialize
1411 * sPathTarget is not set. Don't know how to handle in a non rooted environment.
1413 static HRESULT WINAPI
1414 IFSFldr_PersistFolder3_Initialize (IPersistFolder3
* iface
, LPCITEMIDLIST pidl
)
1416 WCHAR wszTemp
[MAX_PATH
];
1418 IGenericSFImpl
*This
= impl_from_IPersistFolder3(iface
);
1420 TRACE ("(%p)->(%p)\n", This
, pidl
);
1422 SHFree (This
->pidlRoot
); /* free the old pidl */
1423 This
->pidlRoot
= ILClone (pidl
); /* set my pidl */
1425 SHFree (This
->sPathTarget
);
1426 This
->sPathTarget
= NULL
;
1429 if (SHGetPathFromIDListW (pidl
, wszTemp
)) {
1430 int len
= strlenW(wszTemp
);
1431 This
->sPathTarget
= SHAlloc((len
+ 1) * sizeof(WCHAR
));
1432 if (!This
->sPathTarget
)
1433 return E_OUTOFMEMORY
;
1434 memcpy(This
->sPathTarget
, wszTemp
, (len
+ 1) * sizeof(WCHAR
));
1437 TRACE ("--(%p)->(%s)\n", This
, debugstr_w(This
->sPathTarget
));
1441 /**************************************************************************
1442 * IFSFldr_PersistFolder3_GetCurFolder
1444 static HRESULT WINAPI
1445 IFSFldr_PersistFolder3_fnGetCurFolder (IPersistFolder3
* iface
,
1446 LPITEMIDLIST
* pidl
)
1448 IGenericSFImpl
*This
= impl_from_IPersistFolder3(iface
);
1450 TRACE ("(%p)->(%p)\n", This
, pidl
);
1452 if (!pidl
) return E_POINTER
;
1453 *pidl
= ILClone (This
->pidlRoot
);
1457 /**************************************************************************
1458 * IFSFldr_PersistFolder3_InitializeEx
1460 * FIXME: error handling
1462 static HRESULT WINAPI
1463 IFSFldr_PersistFolder3_InitializeEx (IPersistFolder3
* iface
,
1464 IBindCtx
* pbc
, LPCITEMIDLIST pidlRoot
,
1465 const PERSIST_FOLDER_TARGET_INFO
* ppfti
)
1467 WCHAR wszTemp
[MAX_PATH
];
1469 IGenericSFImpl
*This
= impl_from_IPersistFolder3(iface
);
1471 TRACE ("(%p)->(%p,%p,%p)\n", This
, pbc
, pidlRoot
, ppfti
);
1473 TRACE ("--%p %s %s 0x%08x 0x%08x\n",
1474 ppfti
->pidlTargetFolder
, debugstr_w (ppfti
->szTargetParsingName
),
1475 debugstr_w (ppfti
->szNetworkProvider
), ppfti
->dwAttributes
,
1479 if (ppfti
&& ppfti
->pidlTargetFolder
)
1480 pdump (ppfti
->pidlTargetFolder
);
1484 SHFree(This
->pidlRoot
);
1485 This
->pidlRoot
= NULL
;
1487 if (This
->sPathTarget
)
1489 SHFree(This
->sPathTarget
);
1490 This
->sPathTarget
= NULL
;
1494 * Root path and pidl
1496 This
->pidlRoot
= ILClone (pidlRoot
);
1499 * the target folder is specified in csidl OR pidlTargetFolder OR
1500 * szTargetParsingName
1503 if (ppfti
->csidl
!= -1) {
1504 if (SHGetSpecialFolderPathW (0, wszTemp
, ppfti
->csidl
,
1505 ppfti
->csidl
& CSIDL_FLAG_CREATE
)) {
1506 int len
= strlenW(wszTemp
);
1507 This
->sPathTarget
= SHAlloc((len
+ 1) * sizeof(WCHAR
));
1508 if (!This
->sPathTarget
)
1509 return E_OUTOFMEMORY
;
1510 memcpy(This
->sPathTarget
, wszTemp
, (len
+ 1) * sizeof(WCHAR
));
1512 } else if (ppfti
->szTargetParsingName
[0]) {
1513 int len
= strlenW(ppfti
->szTargetParsingName
);
1514 This
->sPathTarget
= SHAlloc((len
+ 1) * sizeof(WCHAR
));
1515 if (!This
->sPathTarget
)
1516 return E_OUTOFMEMORY
;
1517 memcpy(This
->sPathTarget
, ppfti
->szTargetParsingName
,
1518 (len
+ 1) * sizeof(WCHAR
));
1519 } else if (ppfti
->pidlTargetFolder
) {
1520 if (SHGetPathFromIDListW(ppfti
->pidlTargetFolder
, wszTemp
)) {
1521 int len
= strlenW(wszTemp
);
1522 This
->sPathTarget
= SHAlloc((len
+ 1) * sizeof(WCHAR
));
1523 if (!This
->sPathTarget
)
1524 return E_OUTOFMEMORY
;
1525 memcpy(This
->sPathTarget
, wszTemp
, (len
+ 1) * sizeof(WCHAR
));
1530 TRACE ("--(%p)->(target=%s)\n", This
, debugstr_w(This
->sPathTarget
));
1531 pdump (This
->pidlRoot
);
1532 return (This
->sPathTarget
) ? S_OK
: E_FAIL
;
1535 static HRESULT WINAPI
1536 IFSFldr_PersistFolder3_GetFolderTargetInfo (IPersistFolder3
* iface
,
1537 PERSIST_FOLDER_TARGET_INFO
* ppfti
)
1539 IGenericSFImpl
*This
= impl_from_IPersistFolder3(iface
);
1540 FIXME ("(%p)->(%p)\n", This
, ppfti
);
1541 ZeroMemory (ppfti
, sizeof (*ppfti
));
1545 static const IPersistFolder3Vtbl pfvt
=
1547 IFSFldr_PersistFolder3_QueryInterface
,
1548 IFSFldr_PersistFolder3_AddRef
,
1549 IFSFldr_PersistFolder3_Release
,
1550 IFSFldr_PersistFolder3_GetClassID
,
1551 IFSFldr_PersistFolder3_Initialize
,
1552 IFSFldr_PersistFolder3_fnGetCurFolder
,
1553 IFSFldr_PersistFolder3_InitializeEx
,
1554 IFSFldr_PersistFolder3_GetFolderTargetInfo
1557 /****************************************************************************
1558 * ISFDropTarget implementation
1560 static HRESULT WINAPI
ISFDropTarget_QueryInterface(IDropTarget
*iface
, REFIID riid
, void **ppv
)
1562 IGenericSFImpl
*This
= impl_from_IDropTarget(iface
);
1564 return IUnknown_QueryInterface(This
->outer_unk
, riid
, ppv
);
1567 static ULONG WINAPI
ISFDropTarget_AddRef(IDropTarget
*iface
)
1569 IGenericSFImpl
*This
= impl_from_IDropTarget(iface
);
1571 return IUnknown_AddRef(This
->outer_unk
);
1574 static ULONG WINAPI
ISFDropTarget_Release(IDropTarget
*iface
)
1576 IGenericSFImpl
*This
= impl_from_IDropTarget(iface
);
1578 return IUnknown_Release(This
->outer_unk
);
1581 static HRESULT WINAPI
1582 ISFDropTarget_DragEnter (IDropTarget
* iface
, IDataObject
* pDataObject
,
1583 DWORD dwKeyState
, POINTL pt
, DWORD
* pdwEffect
)
1587 IGenericSFImpl
*This
= impl_from_IDropTarget(iface
);
1589 TRACE ("(%p)->(DataObject=%p)\n", This
, pDataObject
);
1591 InitFormatEtc (fmt
, This
->cfShellIDList
, TYMED_HGLOBAL
);
1592 This
->fAcceptFmt
= IDataObject_QueryGetData (pDataObject
, &fmt
) == S_OK
;
1593 if (This
->fAcceptFmt
)
1594 *pdwEffect
= KeyStateToDropEffect(dwKeyState
);
1596 *pdwEffect
= DROPEFFECT_NONE
;
1601 static HRESULT WINAPI
1602 ISFDropTarget_DragOver (IDropTarget
* iface
, DWORD dwKeyState
, POINTL pt
,
1605 IGenericSFImpl
*This
= impl_from_IDropTarget(iface
);
1607 TRACE ("(%p)\n", This
);
1610 return E_INVALIDARG
;
1612 if (This
->fAcceptFmt
)
1613 *pdwEffect
= KeyStateToDropEffect(dwKeyState
);
1615 *pdwEffect
= DROPEFFECT_NONE
;
1620 static HRESULT WINAPI
ISFDropTarget_DragLeave (IDropTarget
* iface
)
1622 IGenericSFImpl
*This
= impl_from_IDropTarget(iface
);
1624 TRACE ("(%p)\n", This
);
1626 This
->fAcceptFmt
= FALSE
;
1631 static HRESULT WINAPI
1632 ISFDropTarget_Drop (IDropTarget
* iface
, IDataObject
* pDataObject
,
1633 DWORD dwKeyState
, POINTL pt
, DWORD
* pdwEffect
)
1635 IGenericSFImpl
*This
= impl_from_IDropTarget(iface
);
1637 FIXME ("(%p) object dropped\n", This
);
1642 static const IDropTargetVtbl dtvt
= {
1643 ISFDropTarget_QueryInterface
,
1644 ISFDropTarget_AddRef
,
1645 ISFDropTarget_Release
,
1646 ISFDropTarget_DragEnter
,
1647 ISFDropTarget_DragOver
,
1648 ISFDropTarget_DragLeave
,
1652 HRESULT WINAPI
IFSFolder_Constructor(IUnknown
*outer_unk
, REFIID riid
, void **ppv
)
1657 TRACE("outer_unk=%p %s\n", outer_unk
, shdebugstr_guid(riid
));
1659 if (outer_unk
&& !IsEqualIID(riid
, &IID_IUnknown
))
1660 return CLASS_E_NOAGGREGATION
;
1662 sf
= LocalAlloc(LMEM_ZEROINIT
, sizeof(*sf
));
1664 return E_OUTOFMEMORY
;
1667 sf
->IUnknown_inner
.lpVtbl
= &unkvt
;
1668 sf
->IShellFolder2_iface
.lpVtbl
= &sfvt
;
1669 sf
->IPersistFolder3_iface
.lpVtbl
= &pfvt
;
1670 sf
->IDropTarget_iface
.lpVtbl
= &dtvt
;
1671 sf
->ISFHelper_iface
.lpVtbl
= &shvt
;
1672 sf
->pclsid
= (CLSID
*) & CLSID_ShellFSFolder
;
1673 sf
->outer_unk
= outer_unk
? outer_unk
: &sf
->IUnknown_inner
;
1675 hr
= IUnknown_QueryInterface(&sf
->IUnknown_inner
, riid
, ppv
);
1676 IUnknown_Release(&sf
->IUnknown_inner
);
1678 TRACE ("--%p\n", *ppv
);