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
33 #define NONAMELESSSTRUCT
45 #include "enumidlist.h"
47 #include "undocshell.h"
48 #include "shell32_main.h"
51 #include "shellfolder.h"
52 #include "wine/debug.h"
56 WINE_DEFAULT_DEBUG_CHANNEL (shell
);
58 /***********************************************************************
59 * IShellFolder implementation
63 const IUnknownVtbl
*lpVtbl
;
65 const IShellFolder2Vtbl
*lpvtblShellFolder
;
66 const IPersistFolder3Vtbl
*lpvtblPersistFolder3
;
67 const IDropTargetVtbl
*lpvtblDropTarget
;
68 const ISFHelperVtbl
*lpvtblSFHelper
;
70 IUnknown
*pUnkOuter
; /* used for aggregation */
74 /* both paths are parsible from the desktop */
75 LPWSTR sPathTarget
; /* complete path to target used for enumeration and ChangeNotify */
77 LPITEMIDLIST pidlRoot
; /* absolute pidl */
79 UINT cfShellIDList
; /* clipboardformat for IDropTarget */
80 BOOL fAcceptFmt
; /* flag for pending Drop */
83 static const IUnknownVtbl unkvt
;
84 static const IShellFolder2Vtbl sfvt
;
85 static const IPersistFolder3Vtbl vt_FSFldr_PersistFolder3
; /* IPersistFolder3 for a FS_Folder */
86 static const IDropTargetVtbl dtvt
;
87 static const ISFHelperVtbl shvt
;
89 static inline IGenericSFImpl
*impl_from_IShellFolder2( IShellFolder2
*iface
)
91 return (IGenericSFImpl
*)((char*)iface
- FIELD_OFFSET(IGenericSFImpl
, lpvtblShellFolder
));
94 static inline IGenericSFImpl
*impl_from_IPersistFolder3( IPersistFolder3
*iface
)
96 return (IGenericSFImpl
*)((char*)iface
- FIELD_OFFSET(IGenericSFImpl
, lpvtblPersistFolder3
));
99 static inline IGenericSFImpl
*impl_from_IDropTarget( IDropTarget
*iface
)
101 return (IGenericSFImpl
*)((char*)iface
- FIELD_OFFSET(IGenericSFImpl
, lpvtblDropTarget
));
104 static inline IGenericSFImpl
*impl_from_ISFHelper( ISFHelper
*iface
)
106 return (IGenericSFImpl
*)((char*)iface
- FIELD_OFFSET(IGenericSFImpl
, lpvtblSFHelper
));
111 converts This to an interface pointer
113 #define _IUnknown_(This) ((IUnknown*)&(This)->lpVtbl)
114 #define _IShellFolder_(This) ((IShellFolder*)&(This)->lpvtblShellFolder)
115 #define _IShellFolder2_(This) ((IShellFolder2*)&(This)->lpvtblShellFolder)
116 #define _IPersist_(This) (&(This)->lpvtblPersistFolder3)
117 #define _IPersistFolder_(This) (&(This)->lpvtblPersistFolder3)
118 #define _IPersistFolder2_(This) (&(This)->lpvtblPersistFolder3)
119 #define _IPersistFolder3_(This) (&(This)->lpvtblPersistFolder3)
120 #define _IDropTarget_(This) (&(This)->lpvtblDropTarget)
121 #define _ISFHelper_(This) (&(This)->lpvtblSFHelper)
123 /**************************************************************************
124 * registers clipboardformat once
126 static void SF_RegisterClipFmt (IGenericSFImpl
* This
)
128 TRACE ("(%p)\n", This
);
130 if (!This
->cfShellIDList
) {
131 This
->cfShellIDList
= RegisterClipboardFormatW (CFSTR_SHELLIDLISTW
);
135 /**************************************************************************
136 * we need a separate IUnknown to handle aggregation
139 static HRESULT WINAPI
IUnknown_fnQueryInterface (IUnknown
* iface
, REFIID riid
, LPVOID
* ppvObj
)
141 IGenericSFImpl
*This
= (IGenericSFImpl
*)iface
;
143 TRACE ("(%p)->(%s,%p)\n", This
, shdebugstr_guid (riid
), ppvObj
);
147 if (IsEqualIID (riid
, &IID_IUnknown
))
148 *ppvObj
= _IUnknown_ (This
);
149 else if (IsEqualIID (riid
, &IID_IShellFolder
))
150 *ppvObj
= _IShellFolder_ (This
);
151 else if (IsEqualIID (riid
, &IID_IShellFolder2
))
152 *ppvObj
= _IShellFolder_ (This
);
153 else if (IsEqualIID (riid
, &IID_IPersist
))
154 *ppvObj
= _IPersist_ (This
);
155 else if (IsEqualIID (riid
, &IID_IPersistFolder
))
156 *ppvObj
= _IPersistFolder_ (This
);
157 else if (IsEqualIID (riid
, &IID_IPersistFolder2
))
158 *ppvObj
= _IPersistFolder2_ (This
);
159 else if (IsEqualIID (riid
, &IID_IPersistFolder3
))
160 *ppvObj
= _IPersistFolder3_ (This
);
161 else if (IsEqualIID (riid
, &IID_ISFHelper
))
162 *ppvObj
= _ISFHelper_ (This
);
163 else if (IsEqualIID (riid
, &IID_IDropTarget
)) {
164 *ppvObj
= _IDropTarget_ (This
);
165 SF_RegisterClipFmt (This
);
169 IUnknown_AddRef ((IUnknown
*) (*ppvObj
));
170 TRACE ("-- Interface = %p\n", *ppvObj
);
173 TRACE ("-- Interface: E_NOINTERFACE\n");
174 return E_NOINTERFACE
;
177 static ULONG WINAPI
IUnknown_fnAddRef (IUnknown
* iface
)
179 IGenericSFImpl
*This
= (IGenericSFImpl
*)iface
;
180 ULONG refCount
= InterlockedIncrement(&This
->ref
);
182 TRACE ("(%p)->(count=%u)\n", This
, refCount
- 1);
187 static ULONG WINAPI
IUnknown_fnRelease (IUnknown
* iface
)
189 IGenericSFImpl
*This
= (IGenericSFImpl
*)iface
;
190 ULONG refCount
= InterlockedDecrement(&This
->ref
);
192 TRACE ("(%p)->(count=%u)\n", This
, refCount
+ 1);
195 TRACE ("-- destroying IShellFolder(%p)\n", This
);
197 SHFree (This
->pidlRoot
);
198 SHFree (This
->sPathTarget
);
204 static const IUnknownVtbl unkvt
=
206 IUnknown_fnQueryInterface
,
211 static const shvheader GenericSFHeader
[] = {
212 {IDS_SHV_COLUMN1
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 15},
213 {IDS_SHV_COLUMN2
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 10},
214 {IDS_SHV_COLUMN3
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 10},
215 {IDS_SHV_COLUMN4
, SHCOLSTATE_TYPE_DATE
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 12},
216 {IDS_SHV_COLUMN5
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 5}
219 #define GENERICSHELLVIEWCOLUMNS 5
221 /**************************************************************************
222 * IFSFolder_Constructor
225 * creating undocumented ShellFS_Folder as part of an aggregation
226 * {F3364BA0-65B9-11CE-A9BA-00AA004AE837}
230 IFSFolder_Constructor (IUnknown
* pUnkOuter
, REFIID riid
, LPVOID
* ppv
)
234 TRACE ("unkOut=%p %s\n", pUnkOuter
, shdebugstr_guid (riid
));
236 if (pUnkOuter
&& !IsEqualIID (riid
, &IID_IUnknown
))
237 return CLASS_E_NOAGGREGATION
;
238 sf
= LocalAlloc (LMEM_ZEROINIT
, sizeof (IGenericSFImpl
));
240 return E_OUTOFMEMORY
;
244 sf
->lpvtblShellFolder
= &sfvt
;
245 sf
->lpvtblPersistFolder3
= &vt_FSFldr_PersistFolder3
;
246 sf
->lpvtblDropTarget
= &dtvt
;
247 sf
->lpvtblSFHelper
= &shvt
;
248 sf
->pclsid
= (CLSID
*) & CLSID_ShellFSFolder
;
249 sf
->pUnkOuter
= pUnkOuter
? pUnkOuter
: _IUnknown_ (sf
);
251 if (FAILED (IUnknown_QueryInterface (_IUnknown_ (sf
), riid
, ppv
))) {
252 IUnknown_Release (_IUnknown_ (sf
));
253 return E_NOINTERFACE
;
256 TRACE ("--%p\n", *ppv
);
260 /**************************************************************************
261 * IShellFolder_fnQueryInterface
264 * REFIID riid [in ] Requested InterfaceID
265 * LPVOID* ppvObject [out] Interface* to hold the result
267 static HRESULT WINAPI
268 IShellFolder_fnQueryInterface (IShellFolder2
* iface
, REFIID riid
,
271 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
273 TRACE ("(%p)->(%s,%p)\n", This
, shdebugstr_guid (riid
), ppvObj
);
275 return IUnknown_QueryInterface (This
->pUnkOuter
, riid
, ppvObj
);
278 /**************************************************************************
279 * IShellFolder_AddRef
282 static ULONG WINAPI
IShellFolder_fnAddRef (IShellFolder2
* iface
)
284 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
286 TRACE ("(%p)->(count=%u)\n", This
, This
->ref
);
288 return IUnknown_AddRef (This
->pUnkOuter
);
291 /**************************************************************************
292 * IShellFolder_fnRelease
294 static ULONG WINAPI
IShellFolder_fnRelease (IShellFolder2
* iface
)
296 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
298 TRACE ("(%p)->(count=%u)\n", This
, This
->ref
);
300 return IUnknown_Release (This
->pUnkOuter
);
303 /**************************************************************************
304 * SHELL32_CreatePidlFromBindCtx [internal]
306 * If the caller bound File System Bind Data, assume it is the
307 * find data for the path.
308 * This allows binding of paths that don't exist.
310 LPITEMIDLIST
SHELL32_CreatePidlFromBindCtx(IBindCtx
*pbc
, LPCWSTR path
)
312 static WCHAR szfsbc
[] = {
313 'F','i','l','e',' ','S','y','s','t','e','m',' ',
314 'B','i','n','d',' ','D','a','t','a',0 };
315 IFileSystemBindData
*fsbd
= NULL
;
316 LPITEMIDLIST pidl
= NULL
;
317 IUnknown
*unk
= NULL
;
320 TRACE("%p %s\n", pbc
, debugstr_w(path
));
325 /* see if the caller bound File System Bind Data */
326 r
= IBindCtx_GetObjectParam( pbc
, szfsbc
, &unk
);
330 r
= IUnknown_QueryInterface( unk
, &IID_IFileSystemBindData
, (void**)&fsbd
);
333 WIN32_FIND_DATAW wfd
;
335 r
= IFileSystemBindData_GetFindData( fsbd
, &wfd
);
338 lstrcpynW( &wfd
.cFileName
[0], path
, MAX_PATH
);
339 pidl
= _ILCreateFromFindDataW( &wfd
);
341 IFileSystemBindData_Release( fsbd
);
343 IUnknown_Release( unk
);
348 /**************************************************************************
349 * IShellFolder_ParseDisplayName {SHELL32}
351 * Parse a display name.
354 * hwndOwner [in] Parent window for any message's
355 * pbc [in] optional FileSystemBindData context
356 * lpszDisplayName [in] Unicode displayname.
357 * pchEaten [out] (unicode) characters processed
358 * ppidl [out] complex pidl to item
359 * pdwAttributes [out] items attributes
362 * Every folder tries to parse only its own (the leftmost) pidl and creates a
363 * subfolder to evaluate the remaining parts.
364 * Now we can parse into namespaces implemented by shell extensions
366 * Behaviour on win98: lpszDisplayName=NULL -> crash
367 * lpszDisplayName="" -> returns mycoputer-pidl
370 * pdwAttributes is not set
371 * pchEaten is not set like in windows
373 static HRESULT WINAPI
374 IShellFolder_fnParseDisplayName (IShellFolder2
* iface
,
377 LPOLESTR lpszDisplayName
,
378 DWORD
* pchEaten
, LPITEMIDLIST
* ppidl
,
379 DWORD
* pdwAttributes
)
381 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
383 HRESULT hr
= E_INVALIDARG
;
384 LPCWSTR szNext
= NULL
;
385 WCHAR szElement
[MAX_PATH
];
386 WCHAR szPath
[MAX_PATH
];
387 LPITEMIDLIST pidlTemp
= NULL
;
390 TRACE ("(%p)->(HWND=%p,%p,%p=%s,%p,pidl=%p,%p)\n",
391 This
, hwndOwner
, pbc
, lpszDisplayName
, debugstr_w (lpszDisplayName
),
392 pchEaten
, ppidl
, pdwAttributes
);
394 if (!lpszDisplayName
|| !ppidl
)
398 *pchEaten
= 0; /* strange but like the original */
400 pidlTemp
= SHELL32_CreatePidlFromBindCtx(pbc
, lpszDisplayName
);
401 if (!pidlTemp
&& *lpszDisplayName
)
403 /* get the next element */
404 szNext
= GetNextElementW (lpszDisplayName
, szElement
, MAX_PATH
);
406 /* build the full pathname to the element */
407 lstrcpynW(szPath
, This
->sPathTarget
, MAX_PATH
- 1);
408 PathAddBackslashW(szPath
);
409 len
= lstrlenW(szPath
);
410 lstrcpynW(szPath
+ len
, szElement
, MAX_PATH
- len
);
413 hr
= _ILCreateFromPathW(szPath
, &pidlTemp
);
416 if (szNext
&& *szNext
) {
417 /* try to analyse the next element */
418 hr
= SHELL32_ParseNextElement (iface
, hwndOwner
, pbc
,
419 &pidlTemp
, (LPOLESTR
) szNext
, pchEaten
, pdwAttributes
);
421 /* it's the last element */
422 if (pdwAttributes
&& *pdwAttributes
) {
423 hr
= SHELL32_GetItemAttributes (_IShellFolder_ (This
),
424 pidlTemp
, pdwAttributes
);
435 TRACE ("(%p)->(-- pidl=%p ret=0x%08x)\n", This
, *ppidl
, hr
);
440 /**************************************************************************
441 * IShellFolder_fnEnumObjects
443 * HWND hwndOwner, //[in ] Parent Window
444 * DWORD grfFlags, //[in ] SHCONTF enumeration mask
445 * LPENUMIDLIST* ppenumIDList //[out] IEnumIDList interface
447 static HRESULT WINAPI
448 IShellFolder_fnEnumObjects (IShellFolder2
* iface
, HWND hwndOwner
,
449 DWORD dwFlags
, LPENUMIDLIST
* ppEnumIDList
)
451 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
453 TRACE ("(%p)->(HWND=%p flags=0x%08x pplist=%p)\n", This
, hwndOwner
,
454 dwFlags
, ppEnumIDList
);
456 *ppEnumIDList
= IEnumIDList_Constructor();
458 CreateFolderEnumList(*ppEnumIDList
, This
->sPathTarget
, dwFlags
);
460 TRACE ("-- (%p)->(new ID List: %p)\n", This
, *ppEnumIDList
);
462 return *ppEnumIDList
? S_OK
: E_OUTOFMEMORY
;
465 /**************************************************************************
466 * IShellFolder_fnBindToObject
468 * LPCITEMIDLIST pidl, //[in ] relative pidl to open
469 * LPBC pbc, //[in ] optional FileSystemBindData context
470 * REFIID riid, //[in ] Initial Interface
471 * LPVOID* ppvObject //[out] Interface*
473 static HRESULT WINAPI
474 IShellFolder_fnBindToObject (IShellFolder2
* iface
, LPCITEMIDLIST pidl
,
475 LPBC pbc
, REFIID riid
, LPVOID
* ppvOut
)
477 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
479 TRACE ("(%p)->(pidl=%p,%p,%s,%p)\n", This
, pidl
, pbc
,
480 shdebugstr_guid (riid
), ppvOut
);
482 return SHELL32_BindToChild (This
->pidlRoot
, This
->sPathTarget
, pidl
, riid
,
486 /**************************************************************************
487 * IShellFolder_fnBindToStorage
489 * LPCITEMIDLIST pidl, //[in ] complex pidl to store
490 * LPBC pbc, //[in ] reserved
491 * REFIID riid, //[in ] Initial storage interface
492 * LPVOID* ppvObject //[out] Interface* returned
494 static HRESULT WINAPI
495 IShellFolder_fnBindToStorage (IShellFolder2
* iface
, LPCITEMIDLIST pidl
,
496 LPBC pbcReserved
, REFIID riid
, LPVOID
* ppvOut
)
498 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
500 FIXME ("(%p)->(pidl=%p,%p,%s,%p) stub\n", This
, pidl
, pbcReserved
,
501 shdebugstr_guid (riid
), ppvOut
);
507 /**************************************************************************
508 * IShellFolder_fnCompareIDs
511 static HRESULT WINAPI
512 IShellFolder_fnCompareIDs (IShellFolder2
* iface
, LPARAM lParam
,
513 LPCITEMIDLIST pidl1
, LPCITEMIDLIST pidl2
)
515 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
519 TRACE ("(%p)->(0x%08lx,pidl1=%p,pidl2=%p)\n", This
, lParam
, pidl1
, pidl2
);
520 nReturn
= SHELL32_CompareIDs (_IShellFolder_ (This
), lParam
, pidl1
, pidl2
);
521 TRACE ("-- %i\n", nReturn
);
525 /**************************************************************************
526 * IShellFolder_fnCreateViewObject
528 static HRESULT WINAPI
529 IShellFolder_fnCreateViewObject (IShellFolder2
* iface
, HWND hwndOwner
,
530 REFIID riid
, LPVOID
* ppvOut
)
532 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
534 LPSHELLVIEW pShellView
;
535 HRESULT hr
= E_INVALIDARG
;
537 TRACE ("(%p)->(hwnd=%p,%s,%p)\n", This
, hwndOwner
, shdebugstr_guid (riid
),
543 if (IsEqualIID (riid
, &IID_IDropTarget
)) {
544 hr
= IShellFolder_QueryInterface (iface
, &IID_IDropTarget
, ppvOut
);
545 } else if (IsEqualIID (riid
, &IID_IContextMenu
)) {
546 FIXME ("IContextMenu not implemented\n");
548 } else if (IsEqualIID (riid
, &IID_IShellView
)) {
549 pShellView
= IShellView_Constructor ((IShellFolder
*) iface
);
551 hr
= IShellView_QueryInterface (pShellView
, riid
, ppvOut
);
552 IShellView_Release (pShellView
);
556 TRACE ("-- (%p)->(interface=%p)\n", This
, ppvOut
);
560 /**************************************************************************
561 * IShellFolder_fnGetAttributesOf
564 * UINT cidl, //[in ] num elements in pidl array
565 * LPCITEMIDLIST* apidl, //[in ] simple pidl array
566 * ULONG* rgfInOut) //[out] result array
569 static HRESULT WINAPI
570 IShellFolder_fnGetAttributesOf (IShellFolder2
* iface
, UINT cidl
,
571 LPCITEMIDLIST
* apidl
, DWORD
* rgfInOut
)
573 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
577 TRACE ("(%p)->(cidl=%d apidl=%p mask=%p (0x%08x))\n", This
, cidl
, apidl
,
578 rgfInOut
, rgfInOut
? *rgfInOut
: 0);
589 IShellFolder
*psfParent
= NULL
;
590 LPCITEMIDLIST rpidl
= NULL
;
592 hr
= SHBindToParent(This
->pidlRoot
, &IID_IShellFolder
, (LPVOID
*)&psfParent
, &rpidl
);
594 SHELL32_GetItemAttributes (psfParent
, rpidl
, rgfInOut
);
595 IShellFolder_Release(psfParent
);
599 while (cidl
> 0 && *apidl
) {
601 SHELL32_GetItemAttributes (_IShellFolder_ (This
), *apidl
, rgfInOut
);
606 /* make sure SFGAO_VALIDATE is cleared, some apps depend on that */
607 *rgfInOut
&= ~SFGAO_VALIDATE
;
609 TRACE ("-- result=0x%08x\n", *rgfInOut
);
614 /**************************************************************************
615 * SHELL32_CreateExtensionUIObject (internal)
617 HRESULT
SHELL32_CreateExtensionUIObject(IShellFolder2
*iface
,
618 LPCITEMIDLIST pidl
, REFIID riid
, LPVOID
*ppvOut
)
620 static const WCHAR reg_blockedW
[] = {'S','o','f','t','w','a','r','e','\\',
621 'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
622 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
623 'S','h','e','l','l',' ','E','x','t','e','n','s','i','o','n','s','\\',
624 'B','l','o','c','k','e','d',0};
625 static const WCHAR formatW
[] = {'.','%','s','\\','S','h','e','l','l','E','x','\\',
626 '{','%','0','8','x','-','%','0','4','x','-','%','0','4','x','-',
627 '%','0','2','x','%','0','2','x','-','%','0','2','x','%','0','2','x',
628 '%','0','2','x','%','0','2','x','%','0','2','x','%','0','2','x','}',0};
630 IPersistFile
*persist_file
;
632 WCHAR extensionW
[20], buf
[MAX_PATH
];
633 DWORD size
= MAX_PATH
;
641 if(!_ILGetExtension(pidl
, extensionA
, 20))
644 MultiByteToWideChar(CP_ACP
, 0, extensionA
, -1, extensionW
, 20);
646 sprintfW(buf
, formatW
, extensionW
, riid
->Data1
, riid
->Data2
, riid
->Data3
,
647 riid
->Data4
[0], riid
->Data4
[1], riid
->Data4
[2], riid
->Data4
[3],
648 riid
->Data4
[4], riid
->Data4
[5], riid
->Data4
[6], riid
->Data4
[7]);
650 if(RegGetValueW(HKEY_CLASSES_ROOT
, buf
, NULL
, RRF_RT_REG_SZ
,
651 NULL
, buf
, &size
) != ERROR_SUCCESS
)
654 if(RegCreateKeyExW(HKEY_LOCAL_MACHINE
, reg_blockedW
, 0, 0, 0,
655 KEY_READ
, NULL
, &key
, NULL
) != ERROR_SUCCESS
)
657 if(RegQueryValueExW(key
, buf
, 0, NULL
, NULL
, NULL
)
658 != ERROR_FILE_NOT_FOUND
)
659 return E_ACCESSDENIED
;
662 if(RegCreateKeyExW(HKEY_CURRENT_USER
, reg_blockedW
, 0, 0, 0,
663 KEY_READ
, NULL
, &key
, NULL
) != ERROR_SUCCESS
)
665 if(RegQueryValueExW(key
, buf
, 0, NULL
, NULL
, NULL
)
666 != ERROR_FILE_NOT_FOUND
)
667 return E_ACCESSDENIED
;
670 if(!GUIDFromStringW(buf
, &guid
))
673 hr
= CoCreateInstance(&guid
, NULL
, CLSCTX_INPROC_SERVER
,
674 &IID_IPersistFile
, (void**)&persist_file
);
678 hr
= IShellFolder_GetDisplayNameOf(iface
, pidl
, SHGDN_FORPARSING
, &path
);
680 hr
= StrRetToStrW(&path
, NULL
, &file
);
682 IPersistFile_Release(persist_file
);
686 hr
= IPersistFile_Load(persist_file
, file
, STGM_READ
);
689 IPersistFile_Release(persist_file
);
693 hr
= IPersistFile_QueryInterface(persist_file
, riid
, ppvOut
);
694 IPersistFile_Release(persist_file
);
698 /**************************************************************************
699 * IShellFolder_fnGetUIObjectOf
702 * HWND hwndOwner, //[in ] Parent window for any output
703 * UINT cidl, //[in ] array size
704 * LPCITEMIDLIST* apidl, //[in ] simple pidl array
705 * REFIID riid, //[in ] Requested Interface
706 * UINT* prgfInOut, //[ ] reserved
707 * LPVOID* ppvObject) //[out] Resulting Interface
710 * This function gets asked to return "view objects" for one or more (multiple
712 * The viewobject typically is an COM object with one of the following
714 * IExtractIcon,IDataObject,IContextMenu
715 * In order to support icon positions in the default Listview your DataObject
716 * must implement the SetData method (in addition to GetData :) - the shell
717 * passes a barely documented "Icon positions" structure to SetData when the
718 * drag starts, and GetData's it if the drop is in another explorer window that
719 * needs the positions.
721 static HRESULT WINAPI
722 IShellFolder_fnGetUIObjectOf (IShellFolder2
* iface
,
724 UINT cidl
, LPCITEMIDLIST
* apidl
, REFIID riid
,
725 UINT
* prgfInOut
, LPVOID
* ppvOut
)
727 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
730 IUnknown
*pObj
= NULL
;
731 HRESULT hr
= E_INVALIDARG
;
733 TRACE ("(%p)->(%p,%u,apidl=%p,%s,%p,%p)\n",
734 This
, hwndOwner
, cidl
, apidl
, shdebugstr_guid (riid
), prgfInOut
, ppvOut
);
740 hr
= SHELL32_CreateExtensionUIObject(iface
, *apidl
, riid
, ppvOut
);
745 if (IsEqualIID (riid
, &IID_IContextMenu
) && (cidl
>= 1)) {
746 pObj
= (LPUNKNOWN
) ISvItemCm_Constructor ((IShellFolder
*) iface
,
747 This
->pidlRoot
, apidl
, cidl
);
749 } else if (IsEqualIID (riid
, &IID_IDataObject
) && (cidl
>= 1)) {
750 pObj
= (LPUNKNOWN
) IDataObject_Constructor (hwndOwner
,
751 This
->pidlRoot
, apidl
, cidl
);
753 } else if (IsEqualIID (riid
, &IID_IExtractIconA
) && (cidl
== 1)) {
754 pidl
= ILCombine (This
->pidlRoot
, apidl
[0]);
755 pObj
= (LPUNKNOWN
) IExtractIconA_Constructor (pidl
);
758 } else if (IsEqualIID (riid
, &IID_IExtractIconW
) && (cidl
== 1)) {
759 pidl
= ILCombine (This
->pidlRoot
, apidl
[0]);
760 pObj
= (LPUNKNOWN
) IExtractIconW_Constructor (pidl
);
763 } else if (IsEqualIID (riid
, &IID_IDropTarget
) && (cidl
>= 1)) {
764 hr
= IShellFolder_QueryInterface (iface
, &IID_IDropTarget
,
766 } else if ((IsEqualIID(riid
,&IID_IShellLinkW
) ||
767 IsEqualIID(riid
,&IID_IShellLinkA
)) && (cidl
== 1)) {
768 pidl
= ILCombine (This
->pidlRoot
, apidl
[0]);
769 hr
= IShellLink_ConstructFromFile(NULL
, riid
, pidl
, (LPVOID
*)&pObj
);
775 if (SUCCEEDED(hr
) && !pObj
)
780 TRACE ("(%p)->hr=0x%08x\n", This
, hr
);
784 static const WCHAR AdvancedW
[] = { 'S','O','F','T','W','A','R','E',
785 '\\','M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
786 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\','E','x','p','l',
787 'o','r','e','r','\\','A','d','v','a','n','c','e','d',0 };
788 static const WCHAR HideFileExtW
[] = { 'H','i','d','e','F','i','l','e','E','x',
790 static const WCHAR NeverShowExtW
[] = { 'N','e','v','e','r','S','h','o','w','E',
793 /******************************************************************************
794 * SHELL_FS_HideExtension [Internal]
796 * Query the registry if the filename extension of a given path should be
800 * szPath [I] Relative or absolute path of a file
803 * TRUE, if the filename's extension should be hidden
806 BOOL
SHELL_FS_HideExtension(LPCWSTR szPath
)
810 DWORD dwDataSize
= sizeof (DWORD
);
811 BOOL doHide
= FALSE
; /* The default value is FALSE (win98 at least) */
813 if (!RegCreateKeyExW(HKEY_CURRENT_USER
, AdvancedW
, 0, 0, 0, KEY_ALL_ACCESS
, 0, &hKey
, 0)) {
814 if (!RegQueryValueExW(hKey
, HideFileExtW
, 0, 0, (LPBYTE
) &dwData
, &dwDataSize
))
820 LPWSTR ext
= PathFindExtensionW(szPath
);
823 WCHAR classname
[MAX_PATH
];
824 LONG classlen
= sizeof(classname
);
826 if (!RegQueryValueW(HKEY_CLASSES_ROOT
, ext
, classname
, &classlen
))
827 if (!RegOpenKeyW(HKEY_CLASSES_ROOT
, classname
, &hKey
)) {
828 if (!RegQueryValueExW(hKey
, NeverShowExtW
, 0, NULL
, NULL
, NULL
))
837 void SHELL_FS_ProcessDisplayFilename(LPWSTR szPath
, DWORD dwFlags
)
839 /*FIXME: MSDN also mentions SHGDN_FOREDITING which is not yet handled. */
840 if (!(dwFlags
& SHGDN_FORPARSING
) &&
841 ((dwFlags
& SHGDN_INFOLDER
) || (dwFlags
== SHGDN_NORMAL
))) {
842 if (SHELL_FS_HideExtension(szPath
) && szPath
[0] != '.')
843 PathRemoveExtensionW(szPath
);
847 /**************************************************************************
848 * IShellFolder_fnGetDisplayNameOf
849 * Retrieves the display name for the specified file object or subfolder
852 * LPCITEMIDLIST pidl, //[in ] complex pidl to item
853 * DWORD dwFlags, //[in ] SHGNO formatting flags
854 * LPSTRRET lpName) //[out] Returned display name
857 * if the name is in the pidl the ret value should be a STRRET_OFFSET
860 static HRESULT WINAPI
861 IShellFolder_fnGetDisplayNameOf (IShellFolder2
* iface
, LPCITEMIDLIST pidl
,
862 DWORD dwFlags
, LPSTRRET strRet
)
864 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
870 TRACE ("(%p)->(pidl=%p,0x%08x,%p)\n", This
, pidl
, dwFlags
, strRet
);
873 if (!pidl
|| !strRet
)
876 pszPath
= CoTaskMemAlloc((MAX_PATH
+1) * sizeof(WCHAR
));
878 return E_OUTOFMEMORY
;
880 if (_ILIsDesktop(pidl
)) { /* empty pidl */
881 if ((GET_SHGDN_FOR(dwFlags
) & SHGDN_FORPARSING
) &&
882 (GET_SHGDN_RELATION(dwFlags
) != SHGDN_INFOLDER
))
884 if (This
->sPathTarget
)
885 lstrcpynW(pszPath
, This
->sPathTarget
, MAX_PATH
);
887 /* pidl has to contain exactly one non null SHITEMID */
890 } else if (_ILIsPidlSimple(pidl
)) {
891 if ((GET_SHGDN_FOR(dwFlags
) & SHGDN_FORPARSING
) &&
892 (GET_SHGDN_RELATION(dwFlags
) != SHGDN_INFOLDER
) &&
895 lstrcpynW(pszPath
, This
->sPathTarget
, MAX_PATH
);
896 PathAddBackslashW(pszPath
);
897 len
= lstrlenW(pszPath
);
899 _ILSimpleGetTextW(pidl
, pszPath
+ len
, MAX_PATH
+ 1 - len
);
900 if (!_ILIsFolder(pidl
)) SHELL_FS_ProcessDisplayFilename(pszPath
, dwFlags
);
902 hr
= SHELL32_GetDisplayNameOfChild(iface
, pidl
, dwFlags
, pszPath
, MAX_PATH
);
906 /* Win9x always returns ANSI strings, NT always returns Unicode strings */
907 if (GetVersion() & 0x80000000) {
908 strRet
->uType
= STRRET_CSTR
;
909 if (!WideCharToMultiByte(CP_ACP
, 0, pszPath
, -1, strRet
->u
.cStr
, MAX_PATH
,
911 strRet
->u
.cStr
[0] = '\0';
912 CoTaskMemFree(pszPath
);
914 strRet
->uType
= STRRET_WSTR
;
915 strRet
->u
.pOleStr
= pszPath
;
918 CoTaskMemFree(pszPath
);
920 TRACE ("-- (%p)->(%s)\n", This
, strRet
->uType
== STRRET_CSTR
? strRet
->u
.cStr
: debugstr_w(strRet
->u
.pOleStr
));
924 /**************************************************************************
925 * IShellFolder_fnSetNameOf
926 * Changes the name of a file object or subfolder, possibly changing its item
927 * identifier in the process.
930 * HWND hwndOwner, //[in ] Owner window for output
931 * LPCITEMIDLIST pidl, //[in ] simple pidl of item to change
932 * LPCOLESTR lpszName, //[in ] the items new display name
933 * DWORD dwFlags, //[in ] SHGNO formatting flags
934 * LPITEMIDLIST* ppidlOut) //[out] simple pidl returned
936 static HRESULT WINAPI
IShellFolder_fnSetNameOf (IShellFolder2
* iface
,
941 LPITEMIDLIST
* pPidlOut
)
943 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
944 WCHAR szSrc
[MAX_PATH
+ 1], szDest
[MAX_PATH
+ 1];
946 BOOL bIsFolder
= _ILIsFolder (ILFindLastID (pidl
));
948 TRACE ("(%p)->(%p,pidl=%p,%s,%u,%p)\n", This
, hwndOwner
, pidl
,
949 debugstr_w (lpName
), dwFlags
, pPidlOut
);
951 /* build source path */
952 lstrcpynW(szSrc
, This
->sPathTarget
, MAX_PATH
);
953 ptr
= PathAddBackslashW (szSrc
);
955 _ILSimpleGetTextW (pidl
, ptr
, MAX_PATH
+ 1 - (ptr
- szSrc
));
957 /* build destination path */
958 if (dwFlags
== SHGDN_NORMAL
|| dwFlags
& SHGDN_INFOLDER
) {
959 lstrcpynW(szDest
, This
->sPathTarget
, MAX_PATH
);
960 ptr
= PathAddBackslashW (szDest
);
962 lstrcpynW(ptr
, lpName
, MAX_PATH
+ 1 - (ptr
- szDest
));
964 lstrcpynW(szDest
, lpName
, MAX_PATH
);
966 if(!(dwFlags
& SHGDN_FORPARSING
) && SHELL_FS_HideExtension(szSrc
)) {
967 WCHAR
*ext
= PathFindExtensionW(szSrc
);
969 INT len
= strlenW(szDest
);
970 lstrcpynW(szDest
+ len
, ext
, MAX_PATH
- len
);
974 TRACE ("src=%s dest=%s\n", debugstr_w(szSrc
), debugstr_w(szDest
));
976 if (MoveFileW (szSrc
, szDest
)) {
980 hr
= _ILCreateFromPathW(szDest
, pPidlOut
);
982 SHChangeNotify (bIsFolder
? SHCNE_RENAMEFOLDER
: SHCNE_RENAMEITEM
,
983 SHCNF_PATHW
, szSrc
, szDest
);
991 static HRESULT WINAPI
IShellFolder_fnGetDefaultSearchGUID (IShellFolder2
*iface
,
994 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
995 FIXME ("(%p)\n", This
);
998 static HRESULT WINAPI
IShellFolder_fnEnumSearches (IShellFolder2
* iface
,
999 IEnumExtraSearch
** ppenum
)
1001 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
1002 FIXME ("(%p)\n", This
);
1006 static HRESULT WINAPI
1007 IShellFolder_fnGetDefaultColumn (IShellFolder2
* iface
, DWORD dwRes
,
1008 ULONG
* pSort
, ULONG
* pDisplay
)
1010 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
1012 TRACE ("(%p)\n", This
);
1022 static HRESULT WINAPI
1023 IShellFolder_fnGetDefaultColumnState (IShellFolder2
* iface
, UINT iColumn
,
1026 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
1028 TRACE ("(%p)\n", This
);
1030 if (!pcsFlags
|| iColumn
>= GENERICSHELLVIEWCOLUMNS
)
1031 return E_INVALIDARG
;
1033 *pcsFlags
= GenericSFHeader
[iColumn
].pcsFlags
;
1038 static HRESULT WINAPI
1039 IShellFolder_fnGetDetailsEx (IShellFolder2
* iface
, LPCITEMIDLIST pidl
,
1040 const SHCOLUMNID
* pscid
, VARIANT
* pv
)
1042 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
1043 FIXME ("(%p)\n", This
);
1048 static HRESULT WINAPI
1049 IShellFolder_fnGetDetailsOf (IShellFolder2
* iface
, LPCITEMIDLIST pidl
,
1050 UINT iColumn
, SHELLDETAILS
* psd
)
1052 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
1053 HRESULT hr
= E_FAIL
;
1055 TRACE ("(%p)->(%p %i %p)\n", This
, pidl
, iColumn
, psd
);
1057 if (!psd
|| iColumn
>= GENERICSHELLVIEWCOLUMNS
)
1058 return E_INVALIDARG
;
1061 /* the header titles */
1062 psd
->fmt
= GenericSFHeader
[iColumn
].fmt
;
1063 psd
->cxChar
= GenericSFHeader
[iColumn
].cxChar
;
1064 psd
->str
.uType
= STRRET_CSTR
;
1065 LoadStringA (shell32_hInstance
, GenericSFHeader
[iColumn
].colnameid
,
1066 psd
->str
.u
.cStr
, MAX_PATH
);
1070 psd
->str
.uType
= STRRET_CSTR
;
1071 /* the data from the pidl */
1074 hr
= IShellFolder_GetDisplayNameOf (iface
, pidl
,
1075 SHGDN_NORMAL
| SHGDN_INFOLDER
, &psd
->str
);
1078 _ILGetFileSize (pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
1081 _ILGetFileType (pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
1084 _ILGetFileDate (pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
1086 case 4: /* attributes */
1087 _ILGetFileAttributes (pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
1095 static HRESULT WINAPI
1096 IShellFolder_fnMapColumnToSCID (IShellFolder2
* iface
, UINT column
,
1099 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
1100 FIXME ("(%p)\n", This
);
1104 static const IShellFolder2Vtbl sfvt
=
1106 IShellFolder_fnQueryInterface
,
1107 IShellFolder_fnAddRef
,
1108 IShellFolder_fnRelease
,
1109 IShellFolder_fnParseDisplayName
,
1110 IShellFolder_fnEnumObjects
,
1111 IShellFolder_fnBindToObject
,
1112 IShellFolder_fnBindToStorage
,
1113 IShellFolder_fnCompareIDs
,
1114 IShellFolder_fnCreateViewObject
,
1115 IShellFolder_fnGetAttributesOf
,
1116 IShellFolder_fnGetUIObjectOf
,
1117 IShellFolder_fnGetDisplayNameOf
,
1118 IShellFolder_fnSetNameOf
,
1120 IShellFolder_fnGetDefaultSearchGUID
,
1121 IShellFolder_fnEnumSearches
,
1122 IShellFolder_fnGetDefaultColumn
,
1123 IShellFolder_fnGetDefaultColumnState
,
1124 IShellFolder_fnGetDetailsEx
,
1125 IShellFolder_fnGetDetailsOf
,
1126 IShellFolder_fnMapColumnToSCID
1129 /****************************************************************************
1130 * ISFHelper for IShellFolder implementation
1133 static HRESULT WINAPI
1134 ISFHelper_fnQueryInterface (ISFHelper
* iface
, REFIID riid
, LPVOID
* ppvObj
)
1136 IGenericSFImpl
*This
= impl_from_ISFHelper(iface
);
1138 TRACE ("(%p)->(count=%u)\n", This
, This
->ref
);
1140 return IUnknown_QueryInterface (This
->pUnkOuter
, riid
, ppvObj
);
1143 static ULONG WINAPI
ISFHelper_fnAddRef (ISFHelper
* iface
)
1145 IGenericSFImpl
*This
= impl_from_ISFHelper(iface
);
1147 TRACE ("(%p)->(count=%u)\n", This
, This
->ref
);
1149 return IUnknown_AddRef (This
->pUnkOuter
);
1152 static ULONG WINAPI
ISFHelper_fnRelease (ISFHelper
* iface
)
1154 IGenericSFImpl
*This
= impl_from_ISFHelper(iface
);
1156 TRACE ("(%p)\n", This
);
1158 return IUnknown_Release (This
->pUnkOuter
);
1161 /****************************************************************************
1162 * ISFHelper_fnGetUniqueName
1164 * creates a unique folder name
1167 static HRESULT WINAPI
1168 ISFHelper_fnGetUniqueName (ISFHelper
* iface
, LPWSTR pwszName
, UINT uLen
)
1170 IGenericSFImpl
*This
= impl_from_ISFHelper(iface
);
1173 WCHAR wszText
[MAX_PATH
];
1174 WCHAR wszNewFolder
[25];
1175 const WCHAR wszFormat
[] = {'%','s',' ','%','d',0 };
1177 TRACE ("(%p)(%p %u)\n", This
, pwszName
, uLen
);
1179 LoadStringW(shell32_hInstance
, IDS_NEWFOLDER
, wszNewFolder
, sizeof(wszNewFolder
)/sizeof(WCHAR
));
1180 if (uLen
< sizeof(wszNewFolder
)/sizeof(WCHAR
) + 3)
1183 lstrcpynW (pwszName
, wszNewFolder
, uLen
);
1185 hr
= IShellFolder_fnEnumObjects (_IShellFolder2_ (This
), 0,
1186 SHCONTF_FOLDERS
| SHCONTF_NONFOLDERS
| SHCONTF_INCLUDEHIDDEN
, &penum
);
1193 IEnumIDList_Reset (penum
);
1194 while (S_OK
== IEnumIDList_Next (penum
, 1, &pidl
, &dwFetched
) &&
1196 _ILSimpleGetTextW (pidl
, wszText
, MAX_PATH
);
1197 if (0 == lstrcmpiW (wszText
, pwszName
)) {
1198 snprintfW (pwszName
, uLen
, wszFormat
, wszNewFolder
, i
++);
1207 IEnumIDList_Release (penum
);
1212 /****************************************************************************
1213 * ISFHelper_fnAddFolder
1215 * adds a new folder.
1218 static HRESULT WINAPI
1219 ISFHelper_fnAddFolder (ISFHelper
* iface
, HWND hwnd
, LPCWSTR pwszName
,
1220 LPITEMIDLIST
* ppidlOut
)
1222 IGenericSFImpl
*This
= impl_from_ISFHelper(iface
);
1223 WCHAR wszNewDir
[MAX_PATH
];
1225 HRESULT hres
= E_FAIL
;
1227 TRACE ("(%p)(%s %p)\n", This
, debugstr_w(pwszName
), ppidlOut
);
1230 if (This
->sPathTarget
)
1231 lstrcpynW(wszNewDir
, This
->sPathTarget
, MAX_PATH
);
1232 PathAppendW(wszNewDir
, pwszName
);
1234 bRes
= CreateDirectoryW (wszNewDir
, NULL
);
1236 LPITEMIDLIST relPidl
;
1238 lstrcpyW(wszNewDir
, pwszName
);
1240 hres
= IShellFolder_ParseDisplayName((IShellFolder
*)&This
->lpvtblShellFolder
,
1241 hwnd
, NULL
, wszNewDir
, NULL
, &relPidl
, NULL
);
1243 if (SUCCEEDED(hres
)) {
1244 LPITEMIDLIST fullPidl
;
1246 fullPidl
= ILCombine(This
->pidlRoot
, relPidl
);
1249 SHChangeNotify(SHCNE_MKDIR
, SHCNF_IDLIST
, fullPidl
, NULL
);
1253 *ppidlOut
= relPidl
;
1257 WARN("failed to combine %s into a full PIDL\n", wine_dbgstr_w(pwszName
));
1262 WARN("failed to parse %s into a PIDL\n", wine_dbgstr_w(pwszName
));
1265 WCHAR wszText
[128 + MAX_PATH
];
1266 WCHAR wszTempText
[128];
1267 WCHAR wszCaption
[256];
1269 /* Cannot Create folder because of permissions */
1270 LoadStringW (shell32_hInstance
, IDS_CREATEFOLDER_DENIED
, wszTempText
,
1271 sizeof (wszTempText
)/sizeof (wszTempText
[0]));
1272 LoadStringW (shell32_hInstance
, IDS_CREATEFOLDER_CAPTION
, wszCaption
,
1273 sizeof (wszCaption
)/sizeof (wszCaption
[0]));
1274 sprintfW (wszText
, wszTempText
, wszNewDir
);
1275 MessageBoxW (hwnd
, wszText
, wszCaption
, MB_OK
| MB_ICONEXCLAMATION
);
1281 /****************************************************************************
1284 * Builds a list of paths like the one used in SHFileOperation from a table of
1285 * PIDLs relative to the given base folder
1287 static WCHAR
*build_paths_list(LPCWSTR wszBasePath
, int cidl
, const LPCITEMIDLIST
*pidls
)
1289 WCHAR
*wszPathsList
;
1294 iPathLen
= lstrlenW(wszBasePath
);
1295 wszPathsList
= HeapAlloc(GetProcessHeap(), 0, MAX_PATH
*sizeof(WCHAR
)*cidl
+1);
1296 wszListPos
= wszPathsList
;
1298 for (i
= 0; i
< cidl
; i
++) {
1299 if (!_ILIsFolder(pidls
[i
]) && !_ILIsValue(pidls
[i
]))
1302 lstrcpynW(wszListPos
, wszBasePath
, MAX_PATH
);
1303 /* FIXME: abort if path too long */
1304 _ILSimpleGetTextW(pidls
[i
], wszListPos
+iPathLen
, MAX_PATH
-iPathLen
);
1305 wszListPos
+= lstrlenW(wszListPos
)+1;
1308 return wszPathsList
;
1311 /****************************************************************************
1312 * ISFHelper_fnDeleteItems
1314 * deletes items in folder
1316 static HRESULT WINAPI
1317 ISFHelper_fnDeleteItems (ISFHelper
* iface
, UINT cidl
, LPCITEMIDLIST
* apidl
)
1319 IGenericSFImpl
*This
= impl_from_ISFHelper(iface
);
1322 WCHAR wszPath
[MAX_PATH
];
1323 WCHAR
*wszPathsList
;
1325 WCHAR
*wszCurrentPath
;
1327 TRACE ("(%p)(%u %p)\n", This
, cidl
, apidl
);
1328 if (cidl
==0) return S_OK
;
1330 if (This
->sPathTarget
)
1331 lstrcpynW(wszPath
, This
->sPathTarget
, MAX_PATH
);
1334 PathAddBackslashW(wszPath
);
1335 wszPathsList
= build_paths_list(wszPath
, cidl
, apidl
);
1337 ZeroMemory(&op
, sizeof(op
));
1338 op
.hwnd
= GetActiveWindow();
1339 op
.wFunc
= FO_DELETE
;
1340 op
.pFrom
= wszPathsList
;
1341 op
.fFlags
= FOF_ALLOWUNDO
;
1342 if (SHFileOperationW(&op
))
1344 WARN("SHFileOperation failed\n");
1350 /* we currently need to manually send the notifies */
1351 wszCurrentPath
= wszPathsList
;
1352 for (i
= 0; i
< cidl
; i
++)
1356 if (_ILIsFolder(apidl
[i
]))
1357 wEventId
= SHCNE_RMDIR
;
1358 else if (_ILIsValue(apidl
[i
]))
1359 wEventId
= SHCNE_DELETE
;
1363 /* check if file exists */
1364 if (GetFileAttributesW(wszCurrentPath
) == INVALID_FILE_ATTRIBUTES
)
1366 LPITEMIDLIST pidl
= ILCombine(This
->pidlRoot
, apidl
[i
]);
1367 SHChangeNotify(wEventId
, SHCNF_IDLIST
, pidl
, NULL
);
1371 wszCurrentPath
+= lstrlenW(wszCurrentPath
)+1;
1373 HeapFree(GetProcessHeap(), 0, wszPathsList
);
1377 /****************************************************************************
1378 * ISFHelper_fnCopyItems
1380 * copies items to this folder
1382 static HRESULT WINAPI
1383 ISFHelper_fnCopyItems (ISFHelper
* iface
, IShellFolder
* pSFFrom
, UINT cidl
,
1384 LPCITEMIDLIST
* apidl
)
1387 IPersistFolder2
*ppf2
= NULL
;
1388 WCHAR wszSrcPathRoot
[MAX_PATH
],
1389 wszDstPath
[MAX_PATH
+1];
1390 WCHAR
*wszSrcPathsList
;
1391 IGenericSFImpl
*This
= impl_from_ISFHelper(iface
);
1393 SHFILEOPSTRUCTW fop
;
1395 TRACE ("(%p)->(%p,%u,%p)\n", This
, pSFFrom
, cidl
, apidl
);
1397 IShellFolder_QueryInterface (pSFFrom
, &IID_IPersistFolder2
,
1402 if (SUCCEEDED (IPersistFolder2_GetCurFolder (ppf2
, &pidl
))) {
1403 SHGetPathFromIDListW (pidl
, wszSrcPathRoot
);
1404 ZeroMemory(wszDstPath
, MAX_PATH
+1);
1405 if (This
->sPathTarget
)
1406 lstrcpynW(wszDstPath
, This
->sPathTarget
, MAX_PATH
);
1407 PathAddBackslashW(wszSrcPathRoot
);
1408 PathAddBackslashW(wszDstPath
);
1409 wszSrcPathsList
= build_paths_list(wszSrcPathRoot
, cidl
, apidl
);
1410 ZeroMemory(&fop
, sizeof(fop
));
1411 fop
.hwnd
= GetActiveWindow();
1412 fop
.wFunc
= FO_COPY
;
1413 fop
.pFrom
= wszSrcPathsList
;
1414 fop
.pTo
= wszDstPath
;
1415 fop
.fFlags
= FOF_ALLOWUNDO
;
1417 if(SHFileOperationW(&fop
))
1419 WARN("Copy failed\n");
1422 HeapFree(GetProcessHeap(), 0, wszSrcPathsList
);
1426 IPersistFolder2_Release(ppf2
);
1431 static const ISFHelperVtbl shvt
=
1433 ISFHelper_fnQueryInterface
,
1435 ISFHelper_fnRelease
,
1436 ISFHelper_fnGetUniqueName
,
1437 ISFHelper_fnAddFolder
,
1438 ISFHelper_fnDeleteItems
,
1439 ISFHelper_fnCopyItems
1442 /************************************************************************
1443 * IFSFldr_PersistFolder3_QueryInterface
1446 static HRESULT WINAPI
1447 IFSFldr_PersistFolder3_QueryInterface (IPersistFolder3
* iface
, REFIID iid
,
1450 IGenericSFImpl
*This
= impl_from_IPersistFolder3(iface
);
1452 TRACE ("(%p)\n", This
);
1454 return IUnknown_QueryInterface (This
->pUnkOuter
, iid
, ppvObj
);
1457 /************************************************************************
1458 * IFSFldr_PersistFolder3_AddRef
1462 IFSFldr_PersistFolder3_AddRef (IPersistFolder3
* iface
)
1464 IGenericSFImpl
*This
= impl_from_IPersistFolder3(iface
);
1466 TRACE ("(%p)->(count=%u)\n", This
, This
->ref
);
1468 return IUnknown_AddRef (This
->pUnkOuter
);
1471 /************************************************************************
1472 * IFSFldr_PersistFolder3_Release
1476 IFSFldr_PersistFolder3_Release (IPersistFolder3
* iface
)
1478 IGenericSFImpl
*This
= impl_from_IPersistFolder3(iface
);
1480 TRACE ("(%p)->(count=%u)\n", This
, This
->ref
);
1482 return IUnknown_Release (This
->pUnkOuter
);
1485 /************************************************************************
1486 * IFSFldr_PersistFolder3_GetClassID
1488 static HRESULT WINAPI
1489 IFSFldr_PersistFolder3_GetClassID (IPersistFolder3
* iface
, CLSID
* lpClassId
)
1491 IGenericSFImpl
*This
= impl_from_IPersistFolder3(iface
);
1493 TRACE ("(%p)\n", This
);
1497 *lpClassId
= *This
->pclsid
;
1502 /************************************************************************
1503 * IFSFldr_PersistFolder3_Initialize
1506 * sPathTarget is not set. Don't know how to handle in a non rooted environment.
1508 static HRESULT WINAPI
1509 IFSFldr_PersistFolder3_Initialize (IPersistFolder3
* iface
, LPCITEMIDLIST pidl
)
1511 WCHAR wszTemp
[MAX_PATH
];
1513 IGenericSFImpl
*This
= impl_from_IPersistFolder3(iface
);
1515 TRACE ("(%p)->(%p)\n", This
, pidl
);
1517 SHFree (This
->pidlRoot
); /* free the old pidl */
1518 This
->pidlRoot
= ILClone (pidl
); /* set my pidl */
1520 SHFree (This
->sPathTarget
);
1521 This
->sPathTarget
= NULL
;
1524 if (SHGetPathFromIDListW (pidl
, wszTemp
)) {
1525 int len
= strlenW(wszTemp
);
1526 This
->sPathTarget
= SHAlloc((len
+ 1) * sizeof(WCHAR
));
1527 if (!This
->sPathTarget
)
1528 return E_OUTOFMEMORY
;
1529 memcpy(This
->sPathTarget
, wszTemp
, (len
+ 1) * sizeof(WCHAR
));
1532 TRACE ("--(%p)->(%s)\n", This
, debugstr_w(This
->sPathTarget
));
1536 /**************************************************************************
1537 * IFSFldr_PersistFolder3_GetCurFolder
1539 static HRESULT WINAPI
1540 IFSFldr_PersistFolder3_fnGetCurFolder (IPersistFolder3
* iface
,
1541 LPITEMIDLIST
* pidl
)
1543 IGenericSFImpl
*This
= impl_from_IPersistFolder3(iface
);
1545 TRACE ("(%p)->(%p)\n", This
, pidl
);
1547 if (!pidl
) return E_POINTER
;
1548 *pidl
= ILClone (This
->pidlRoot
);
1552 /**************************************************************************
1553 * IFSFldr_PersistFolder3_InitializeEx
1555 * FIXME: error handling
1557 static HRESULT WINAPI
1558 IFSFldr_PersistFolder3_InitializeEx (IPersistFolder3
* iface
,
1559 IBindCtx
* pbc
, LPCITEMIDLIST pidlRoot
,
1560 const PERSIST_FOLDER_TARGET_INFO
* ppfti
)
1562 WCHAR wszTemp
[MAX_PATH
];
1564 IGenericSFImpl
*This
= impl_from_IPersistFolder3(iface
);
1566 TRACE ("(%p)->(%p,%p,%p)\n", This
, pbc
, pidlRoot
, ppfti
);
1568 TRACE ("--%p %s %s 0x%08x 0x%08x\n",
1569 ppfti
->pidlTargetFolder
, debugstr_w (ppfti
->szTargetParsingName
),
1570 debugstr_w (ppfti
->szNetworkProvider
), ppfti
->dwAttributes
,
1574 if (ppfti
&& ppfti
->pidlTargetFolder
)
1575 pdump (ppfti
->pidlTargetFolder
);
1578 __SHFreeAndNil (&This
->pidlRoot
); /* free the old */
1579 if (This
->sPathTarget
)
1580 __SHFreeAndNil (&This
->sPathTarget
);
1583 * Root path and pidl
1585 This
->pidlRoot
= ILClone (pidlRoot
);
1588 * the target folder is specified in csidl OR pidlTargetFolder OR
1589 * szTargetParsingName
1592 if (ppfti
->csidl
!= -1) {
1593 if (SHGetSpecialFolderPathW (0, wszTemp
, ppfti
->csidl
,
1594 ppfti
->csidl
& CSIDL_FLAG_CREATE
)) {
1595 int len
= strlenW(wszTemp
);
1596 This
->sPathTarget
= SHAlloc((len
+ 1) * sizeof(WCHAR
));
1597 if (!This
->sPathTarget
)
1598 return E_OUTOFMEMORY
;
1599 memcpy(This
->sPathTarget
, wszTemp
, (len
+ 1) * sizeof(WCHAR
));
1601 } else if (ppfti
->szTargetParsingName
[0]) {
1602 int len
= strlenW(ppfti
->szTargetParsingName
);
1603 This
->sPathTarget
= SHAlloc((len
+ 1) * sizeof(WCHAR
));
1604 if (!This
->sPathTarget
)
1605 return E_OUTOFMEMORY
;
1606 memcpy(This
->sPathTarget
, ppfti
->szTargetParsingName
,
1607 (len
+ 1) * sizeof(WCHAR
));
1608 } else if (ppfti
->pidlTargetFolder
) {
1609 if (SHGetPathFromIDListW(ppfti
->pidlTargetFolder
, wszTemp
)) {
1610 int len
= strlenW(wszTemp
);
1611 This
->sPathTarget
= SHAlloc((len
+ 1) * sizeof(WCHAR
));
1612 if (!This
->sPathTarget
)
1613 return E_OUTOFMEMORY
;
1614 memcpy(This
->sPathTarget
, wszTemp
, (len
+ 1) * sizeof(WCHAR
));
1619 TRACE ("--(%p)->(target=%s)\n", This
, debugstr_w(This
->sPathTarget
));
1620 pdump (This
->pidlRoot
);
1621 return (This
->sPathTarget
) ? S_OK
: E_FAIL
;
1624 static HRESULT WINAPI
1625 IFSFldr_PersistFolder3_GetFolderTargetInfo (IPersistFolder3
* iface
,
1626 PERSIST_FOLDER_TARGET_INFO
* ppfti
)
1628 IGenericSFImpl
*This
= impl_from_IPersistFolder3(iface
);
1629 FIXME ("(%p)->(%p)\n", This
, ppfti
);
1630 ZeroMemory (ppfti
, sizeof (*ppfti
));
1634 static const IPersistFolder3Vtbl vt_FSFldr_PersistFolder3
=
1636 IFSFldr_PersistFolder3_QueryInterface
,
1637 IFSFldr_PersistFolder3_AddRef
,
1638 IFSFldr_PersistFolder3_Release
,
1639 IFSFldr_PersistFolder3_GetClassID
,
1640 IFSFldr_PersistFolder3_Initialize
,
1641 IFSFldr_PersistFolder3_fnGetCurFolder
,
1642 IFSFldr_PersistFolder3_InitializeEx
,
1643 IFSFldr_PersistFolder3_GetFolderTargetInfo
1646 /****************************************************************************
1647 * ISFDropTarget implementation
1650 ISFDropTarget_QueryDrop (IDropTarget
* iface
, DWORD dwKeyState
,
1653 DWORD dwEffect
= *pdwEffect
;
1655 IGenericSFImpl
*This
= impl_from_IDropTarget(iface
);
1657 *pdwEffect
= DROPEFFECT_NONE
;
1659 if (This
->fAcceptFmt
) { /* Does our interpretation of the keystate ... */
1660 *pdwEffect
= KeyStateToDropEffect (dwKeyState
);
1662 /* ... matches the desired effect ? */
1663 if (dwEffect
& *pdwEffect
) {
1670 static HRESULT WINAPI
1671 ISFDropTarget_QueryInterface (IDropTarget
* iface
, REFIID riid
, LPVOID
* ppvObj
)
1673 IGenericSFImpl
*This
= impl_from_IDropTarget(iface
);
1675 TRACE ("(%p)\n", This
);
1677 return IUnknown_QueryInterface (This
->pUnkOuter
, riid
, ppvObj
);
1680 static ULONG WINAPI
ISFDropTarget_AddRef (IDropTarget
* iface
)
1682 IGenericSFImpl
*This
= impl_from_IDropTarget(iface
);
1684 TRACE ("(%p)\n", This
);
1686 return IUnknown_AddRef (This
->pUnkOuter
);
1689 static ULONG WINAPI
ISFDropTarget_Release (IDropTarget
* iface
)
1691 IGenericSFImpl
*This
= impl_from_IDropTarget(iface
);
1693 TRACE ("(%p)\n", This
);
1695 return IUnknown_Release (This
->pUnkOuter
);
1698 static HRESULT WINAPI
1699 ISFDropTarget_DragEnter (IDropTarget
* iface
, IDataObject
* pDataObject
,
1700 DWORD dwKeyState
, POINTL pt
, DWORD
* pdwEffect
)
1704 IGenericSFImpl
*This
= impl_from_IDropTarget(iface
);
1706 TRACE ("(%p)->(DataObject=%p)\n", This
, pDataObject
);
1708 InitFormatEtc (fmt
, This
->cfShellIDList
, TYMED_HGLOBAL
);
1710 This
->fAcceptFmt
= (S_OK
== IDataObject_QueryGetData (pDataObject
, &fmt
)) ?
1713 ISFDropTarget_QueryDrop (iface
, dwKeyState
, pdwEffect
);
1718 static HRESULT WINAPI
1719 ISFDropTarget_DragOver (IDropTarget
* iface
, DWORD dwKeyState
, POINTL pt
,
1722 IGenericSFImpl
*This
= impl_from_IDropTarget(iface
);
1724 TRACE ("(%p)\n", This
);
1727 return E_INVALIDARG
;
1729 ISFDropTarget_QueryDrop (iface
, dwKeyState
, pdwEffect
);
1734 static HRESULT WINAPI
ISFDropTarget_DragLeave (IDropTarget
* iface
)
1736 IGenericSFImpl
*This
= impl_from_IDropTarget(iface
);
1738 TRACE ("(%p)\n", This
);
1740 This
->fAcceptFmt
= FALSE
;
1745 static HRESULT WINAPI
1746 ISFDropTarget_Drop (IDropTarget
* iface
, IDataObject
* pDataObject
,
1747 DWORD dwKeyState
, POINTL pt
, DWORD
* pdwEffect
)
1749 IGenericSFImpl
*This
= impl_from_IDropTarget(iface
);
1751 FIXME ("(%p) object dropped\n", This
);
1756 static const IDropTargetVtbl dtvt
= {
1757 ISFDropTarget_QueryInterface
,
1758 ISFDropTarget_AddRef
,
1759 ISFDropTarget_Release
,
1760 ISFDropTarget_DragEnter
,
1761 ISFDropTarget_DragOver
,
1762 ISFDropTarget_DragLeave
,