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
*param
= NULL
;
318 WIN32_FIND_DATAW wfd
;
321 TRACE("%p %s\n", pbc
, debugstr_w(path
));
326 /* see if the caller bound File System Bind Data */
327 r
= IBindCtx_GetObjectParam( pbc
, szfsbc
, ¶m
);
331 r
= IUnknown_QueryInterface( param
, &IID_IFileSystemBindData
,
335 r
= IFileSystemBindData_GetFindData( fsbd
, &wfd
);
338 lstrcpynW( &wfd
.cFileName
[0], path
, MAX_PATH
);
339 pidl
= _ILCreateFromFindDataW( &wfd
);
341 IFileSystemBindData_Release( fsbd
);
347 /**************************************************************************
348 * IShellFolder_ParseDisplayName {SHELL32}
350 * Parse a display name.
353 * hwndOwner [in] Parent window for any message's
354 * pbc [in] optional FileSystemBindData context
355 * lpszDisplayName [in] Unicode displayname.
356 * pchEaten [out] (unicode) characters processed
357 * ppidl [out] complex pidl to item
358 * pdwAttributes [out] items attributes
361 * Every folder tries to parse only its own (the leftmost) pidl and creates a
362 * subfolder to evaluate the remaining parts.
363 * Now we can parse into namespaces implemented by shell extensions
365 * Behaviour on win98: lpszDisplayName=NULL -> crash
366 * lpszDisplayName="" -> returns mycoputer-pidl
369 * pdwAttributes is not set
370 * pchEaten is not set like in windows
372 static HRESULT WINAPI
373 IShellFolder_fnParseDisplayName (IShellFolder2
* iface
,
376 LPOLESTR lpszDisplayName
,
377 DWORD
* pchEaten
, LPITEMIDLIST
* ppidl
,
378 DWORD
* pdwAttributes
)
380 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
382 HRESULT hr
= E_INVALIDARG
;
383 LPCWSTR szNext
= NULL
;
384 WCHAR szElement
[MAX_PATH
];
385 WCHAR szPath
[MAX_PATH
];
386 LPITEMIDLIST pidlTemp
= NULL
;
389 TRACE ("(%p)->(HWND=%p,%p,%p=%s,%p,pidl=%p,%p)\n",
390 This
, hwndOwner
, pbc
, lpszDisplayName
, debugstr_w (lpszDisplayName
),
391 pchEaten
, ppidl
, pdwAttributes
);
393 if (!lpszDisplayName
|| !ppidl
)
397 *pchEaten
= 0; /* strange but like the original */
399 pidlTemp
= SHELL32_CreatePidlFromBindCtx(pbc
, lpszDisplayName
);
400 if (!pidlTemp
&& *lpszDisplayName
)
402 /* get the next element */
403 szNext
= GetNextElementW (lpszDisplayName
, szElement
, MAX_PATH
);
405 /* build the full pathname to the element */
406 lstrcpynW(szPath
, This
->sPathTarget
, MAX_PATH
- 1);
407 PathAddBackslashW(szPath
);
408 len
= lstrlenW(szPath
);
409 lstrcpynW(szPath
+ len
, szElement
, MAX_PATH
- len
);
412 hr
= _ILCreateFromPathW(szPath
, &pidlTemp
);
415 if (szNext
&& *szNext
) {
416 /* try to analyse the next element */
417 hr
= SHELL32_ParseNextElement (iface
, hwndOwner
, pbc
,
418 &pidlTemp
, (LPOLESTR
) szNext
, pchEaten
, pdwAttributes
);
420 /* it's the last element */
421 if (pdwAttributes
&& *pdwAttributes
) {
422 hr
= SHELL32_GetItemAttributes (_IShellFolder_ (This
),
423 pidlTemp
, pdwAttributes
);
434 TRACE ("(%p)->(-- pidl=%p ret=0x%08x)\n", This
, *ppidl
, hr
);
439 /**************************************************************************
440 * IShellFolder_fnEnumObjects
442 * HWND hwndOwner, //[in ] Parent Window
443 * DWORD grfFlags, //[in ] SHCONTF enumeration mask
444 * LPENUMIDLIST* ppenumIDList //[out] IEnumIDList interface
446 static HRESULT WINAPI
447 IShellFolder_fnEnumObjects (IShellFolder2
* iface
, HWND hwndOwner
,
448 DWORD dwFlags
, LPENUMIDLIST
* ppEnumIDList
)
450 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
452 TRACE ("(%p)->(HWND=%p flags=0x%08x pplist=%p)\n", This
, hwndOwner
,
453 dwFlags
, ppEnumIDList
);
455 *ppEnumIDList
= IEnumIDList_Constructor();
457 CreateFolderEnumList(*ppEnumIDList
, This
->sPathTarget
, dwFlags
);
459 TRACE ("-- (%p)->(new ID List: %p)\n", This
, *ppEnumIDList
);
461 return *ppEnumIDList
? S_OK
: E_OUTOFMEMORY
;
464 /**************************************************************************
465 * IShellFolder_fnBindToObject
467 * LPCITEMIDLIST pidl, //[in ] relative pidl to open
468 * LPBC pbc, //[in ] optional FileSystemBindData context
469 * REFIID riid, //[in ] Initial Interface
470 * LPVOID* ppvObject //[out] Interface*
472 static HRESULT WINAPI
473 IShellFolder_fnBindToObject (IShellFolder2
* iface
, LPCITEMIDLIST pidl
,
474 LPBC pbc
, REFIID riid
, LPVOID
* ppvOut
)
476 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
478 TRACE ("(%p)->(pidl=%p,%p,%s,%p)\n", This
, pidl
, pbc
,
479 shdebugstr_guid (riid
), ppvOut
);
481 return SHELL32_BindToChild (This
->pidlRoot
, This
->sPathTarget
, pidl
, riid
,
485 /**************************************************************************
486 * IShellFolder_fnBindToStorage
488 * LPCITEMIDLIST pidl, //[in ] complex pidl to store
489 * LPBC pbc, //[in ] reserved
490 * REFIID riid, //[in ] Initial storage interface
491 * LPVOID* ppvObject //[out] Interface* returned
493 static HRESULT WINAPI
494 IShellFolder_fnBindToStorage (IShellFolder2
* iface
, LPCITEMIDLIST pidl
,
495 LPBC pbcReserved
, REFIID riid
, LPVOID
* ppvOut
)
497 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
499 FIXME ("(%p)->(pidl=%p,%p,%s,%p) stub\n", This
, pidl
, pbcReserved
,
500 shdebugstr_guid (riid
), ppvOut
);
506 /**************************************************************************
507 * IShellFolder_fnCompareIDs
510 static HRESULT WINAPI
511 IShellFolder_fnCompareIDs (IShellFolder2
* iface
, LPARAM lParam
,
512 LPCITEMIDLIST pidl1
, LPCITEMIDLIST pidl2
)
514 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
518 TRACE ("(%p)->(0x%08lx,pidl1=%p,pidl2=%p)\n", This
, lParam
, pidl1
, pidl2
);
519 nReturn
= SHELL32_CompareIDs (_IShellFolder_ (This
), lParam
, pidl1
, pidl2
);
520 TRACE ("-- %i\n", nReturn
);
524 /**************************************************************************
525 * IShellFolder_fnCreateViewObject
527 static HRESULT WINAPI
528 IShellFolder_fnCreateViewObject (IShellFolder2
* iface
, HWND hwndOwner
,
529 REFIID riid
, LPVOID
* ppvOut
)
531 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
533 LPSHELLVIEW pShellView
;
534 HRESULT hr
= E_INVALIDARG
;
536 TRACE ("(%p)->(hwnd=%p,%s,%p)\n", This
, hwndOwner
, shdebugstr_guid (riid
),
542 if (IsEqualIID (riid
, &IID_IDropTarget
)) {
543 hr
= IShellFolder_QueryInterface (iface
, &IID_IDropTarget
, ppvOut
);
544 } else if (IsEqualIID (riid
, &IID_IContextMenu
)) {
545 FIXME ("IContextMenu not implemented\n");
547 } else if (IsEqualIID (riid
, &IID_IShellView
)) {
548 pShellView
= IShellView_Constructor ((IShellFolder
*) iface
);
550 hr
= IShellView_QueryInterface (pShellView
, riid
, ppvOut
);
551 IShellView_Release (pShellView
);
555 TRACE ("-- (%p)->(interface=%p)\n", This
, ppvOut
);
559 /**************************************************************************
560 * IShellFolder_fnGetAttributesOf
563 * UINT cidl, //[in ] num elements in pidl array
564 * LPCITEMIDLIST* apidl, //[in ] simple pidl array
565 * ULONG* rgfInOut) //[out] result array
568 static HRESULT WINAPI
569 IShellFolder_fnGetAttributesOf (IShellFolder2
* iface
, UINT cidl
,
570 LPCITEMIDLIST
* apidl
, DWORD
* rgfInOut
)
572 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
576 TRACE ("(%p)->(cidl=%d apidl=%p mask=%p (0x%08x))\n", This
, cidl
, apidl
,
577 rgfInOut
, rgfInOut
? *rgfInOut
: 0);
588 IShellFolder
*psfParent
= NULL
;
589 LPCITEMIDLIST rpidl
= NULL
;
591 hr
= SHBindToParent(This
->pidlRoot
, &IID_IShellFolder
, (LPVOID
*)&psfParent
, &rpidl
);
593 SHELL32_GetItemAttributes (psfParent
, rpidl
, rgfInOut
);
594 IShellFolder_Release(psfParent
);
598 while (cidl
> 0 && *apidl
) {
600 SHELL32_GetItemAttributes (_IShellFolder_ (This
), *apidl
, rgfInOut
);
605 /* make sure SFGAO_VALIDATE is cleared, some apps depend on that */
606 *rgfInOut
&= ~SFGAO_VALIDATE
;
608 TRACE ("-- result=0x%08x\n", *rgfInOut
);
613 /**************************************************************************
614 * SHELL32_CreateExtensionUIObject (internal)
616 HRESULT
SHELL32_CreateExtensionUIObject(IShellFolder2
*iface
,
617 LPCITEMIDLIST pidl
, REFIID riid
, LPVOID
*ppvOut
)
619 static const WCHAR reg_blockedW
[] = {'S','o','f','t','w','a','r','e','\\',
620 'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
621 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
622 'S','h','e','l','l',' ','E','x','t','e','n','s','i','o','n','s','\\',
623 'B','l','o','c','k','e','d',0};
624 static const WCHAR formatW
[] = {'.','%','s','\\','S','h','e','l','l','E','x','\\',
625 '{','%','0','8','x','-','%','0','4','x','-','%','0','4','x','-',
626 '%','0','2','x','%','0','2','x','-','%','0','2','x','%','0','2','x',
627 '%','0','2','x','%','0','2','x','%','0','2','x','%','0','2','x','}',0};
629 IPersistFile
*persist_file
;
631 WCHAR extensionW
[20], buf
[MAX_PATH
];
632 DWORD size
= MAX_PATH
;
640 if(!_ILGetExtension(pidl
, extensionA
, 20))
643 MultiByteToWideChar(CP_ACP
, 0, extensionA
, -1, extensionW
, 20);
645 sprintfW(buf
, formatW
, extensionW
, riid
->Data1
, riid
->Data2
, riid
->Data3
,
646 riid
->Data4
[0], riid
->Data4
[1], riid
->Data4
[2], riid
->Data4
[3],
647 riid
->Data4
[4], riid
->Data4
[5], riid
->Data4
[6], riid
->Data4
[7]);
649 if(RegGetValueW(HKEY_CLASSES_ROOT
, buf
, NULL
, RRF_RT_REG_SZ
,
650 NULL
, buf
, &size
) != ERROR_SUCCESS
)
653 if(RegCreateKeyExW(HKEY_LOCAL_MACHINE
, reg_blockedW
, 0, 0, 0,
654 KEY_READ
, NULL
, &key
, NULL
) != ERROR_SUCCESS
)
656 if(RegQueryValueExW(key
, buf
, 0, NULL
, NULL
, NULL
)
657 != ERROR_FILE_NOT_FOUND
)
658 return E_ACCESSDENIED
;
661 if(RegCreateKeyExW(HKEY_CURRENT_USER
, reg_blockedW
, 0, 0, 0,
662 KEY_READ
, NULL
, &key
, NULL
) != ERROR_SUCCESS
)
664 if(RegQueryValueExW(key
, buf
, 0, NULL
, NULL
, NULL
)
665 != ERROR_FILE_NOT_FOUND
)
666 return E_ACCESSDENIED
;
669 if(!GUIDFromStringW(buf
, &guid
))
672 hr
= CoCreateInstance(&guid
, NULL
, CLSCTX_INPROC_SERVER
,
673 &IID_IPersistFile
, (void**)&persist_file
);
677 hr
= IShellFolder_GetDisplayNameOf(iface
, pidl
, SHGDN_FORPARSING
, &path
);
679 hr
= StrRetToStrW(&path
, NULL
, &file
);
681 IPersistFile_Release(persist_file
);
685 hr
= IPersistFile_Load(persist_file
, file
, STGM_READ
);
688 IPersistFile_Release(persist_file
);
692 hr
= IPersistFile_QueryInterface(persist_file
, riid
, ppvOut
);
693 IPersistFile_Release(persist_file
);
697 /**************************************************************************
698 * IShellFolder_fnGetUIObjectOf
701 * HWND hwndOwner, //[in ] Parent window for any output
702 * UINT cidl, //[in ] array size
703 * LPCITEMIDLIST* apidl, //[in ] simple pidl array
704 * REFIID riid, //[in ] Requested Interface
705 * UINT* prgfInOut, //[ ] reserved
706 * LPVOID* ppvObject) //[out] Resulting Interface
709 * This function gets asked to return "view objects" for one or more (multiple
711 * The viewobject typically is an COM object with one of the following
713 * IExtractIcon,IDataObject,IContextMenu
714 * In order to support icon positions in the default Listview your DataObject
715 * must implement the SetData method (in addition to GetData :) - the shell
716 * passes a barely documented "Icon positions" structure to SetData when the
717 * drag starts, and GetData's it if the drop is in another explorer window that
718 * needs the positions.
720 static HRESULT WINAPI
721 IShellFolder_fnGetUIObjectOf (IShellFolder2
* iface
,
723 UINT cidl
, LPCITEMIDLIST
* apidl
, REFIID riid
,
724 UINT
* prgfInOut
, LPVOID
* ppvOut
)
726 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
729 IUnknown
*pObj
= NULL
;
730 HRESULT hr
= E_INVALIDARG
;
732 TRACE ("(%p)->(%p,%u,apidl=%p,%s,%p,%p)\n",
733 This
, hwndOwner
, cidl
, apidl
, shdebugstr_guid (riid
), prgfInOut
, ppvOut
);
739 hr
= SHELL32_CreateExtensionUIObject(iface
, *apidl
, riid
, ppvOut
);
744 if (IsEqualIID (riid
, &IID_IContextMenu
) && (cidl
>= 1)) {
745 pObj
= (LPUNKNOWN
) ISvItemCm_Constructor ((IShellFolder
*) iface
,
746 This
->pidlRoot
, apidl
, cidl
);
748 } else if (IsEqualIID (riid
, &IID_IDataObject
) && (cidl
>= 1)) {
749 pObj
= (LPUNKNOWN
) IDataObject_Constructor (hwndOwner
,
750 This
->pidlRoot
, apidl
, cidl
);
752 } else if (IsEqualIID (riid
, &IID_IExtractIconA
) && (cidl
== 1)) {
753 pidl
= ILCombine (This
->pidlRoot
, apidl
[0]);
754 pObj
= (LPUNKNOWN
) IExtractIconA_Constructor (pidl
);
757 } else if (IsEqualIID (riid
, &IID_IExtractIconW
) && (cidl
== 1)) {
758 pidl
= ILCombine (This
->pidlRoot
, apidl
[0]);
759 pObj
= (LPUNKNOWN
) IExtractIconW_Constructor (pidl
);
762 } else if (IsEqualIID (riid
, &IID_IDropTarget
) && (cidl
>= 1)) {
763 hr
= IShellFolder_QueryInterface (iface
, &IID_IDropTarget
,
765 } else if ((IsEqualIID(riid
,&IID_IShellLinkW
) ||
766 IsEqualIID(riid
,&IID_IShellLinkA
)) && (cidl
== 1)) {
767 pidl
= ILCombine (This
->pidlRoot
, apidl
[0]);
768 hr
= IShellLink_ConstructFromFile(NULL
, riid
, pidl
, (LPVOID
*)&pObj
);
774 if (SUCCEEDED(hr
) && !pObj
)
779 TRACE ("(%p)->hr=0x%08x\n", This
, hr
);
783 static const WCHAR AdvancedW
[] = { 'S','O','F','T','W','A','R','E',
784 '\\','M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
785 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\','E','x','p','l',
786 'o','r','e','r','\\','A','d','v','a','n','c','e','d',0 };
787 static const WCHAR HideFileExtW
[] = { 'H','i','d','e','F','i','l','e','E','x',
789 static const WCHAR NeverShowExtW
[] = { 'N','e','v','e','r','S','h','o','w','E',
792 /******************************************************************************
793 * SHELL_FS_HideExtension [Internal]
795 * Query the registry if the filename extension of a given path should be
799 * szPath [I] Relative or absolute path of a file
802 * TRUE, if the filename's extension should be hidden
805 BOOL
SHELL_FS_HideExtension(LPCWSTR szPath
)
809 DWORD dwDataSize
= sizeof (DWORD
);
810 BOOL doHide
= FALSE
; /* The default value is FALSE (win98 at least) */
812 if (!RegCreateKeyExW(HKEY_CURRENT_USER
, AdvancedW
, 0, 0, 0, KEY_ALL_ACCESS
, 0, &hKey
, 0)) {
813 if (!RegQueryValueExW(hKey
, HideFileExtW
, 0, 0, (LPBYTE
) &dwData
, &dwDataSize
))
819 LPWSTR ext
= PathFindExtensionW(szPath
);
822 WCHAR classname
[MAX_PATH
];
823 LONG classlen
= sizeof(classname
);
825 if (!RegQueryValueW(HKEY_CLASSES_ROOT
, ext
, classname
, &classlen
))
826 if (!RegOpenKeyW(HKEY_CLASSES_ROOT
, classname
, &hKey
)) {
827 if (!RegQueryValueExW(hKey
, NeverShowExtW
, 0, NULL
, NULL
, NULL
))
836 void SHELL_FS_ProcessDisplayFilename(LPWSTR szPath
, DWORD dwFlags
)
838 /*FIXME: MSDN also mentions SHGDN_FOREDITING which is not yet handled. */
839 if (!(dwFlags
& SHGDN_FORPARSING
) &&
840 ((dwFlags
& SHGDN_INFOLDER
) || (dwFlags
== SHGDN_NORMAL
))) {
841 if (SHELL_FS_HideExtension(szPath
) && szPath
[0] != '.')
842 PathRemoveExtensionW(szPath
);
846 /**************************************************************************
847 * IShellFolder_fnGetDisplayNameOf
848 * Retrieves the display name for the specified file object or subfolder
851 * LPCITEMIDLIST pidl, //[in ] complex pidl to item
852 * DWORD dwFlags, //[in ] SHGNO formatting flags
853 * LPSTRRET lpName) //[out] Returned display name
856 * if the name is in the pidl the ret value should be a STRRET_OFFSET
859 static HRESULT WINAPI
860 IShellFolder_fnGetDisplayNameOf (IShellFolder2
* iface
, LPCITEMIDLIST pidl
,
861 DWORD dwFlags
, LPSTRRET strRet
)
863 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
869 TRACE ("(%p)->(pidl=%p,0x%08x,%p)\n", This
, pidl
, dwFlags
, strRet
);
872 if (!pidl
|| !strRet
)
875 pszPath
= CoTaskMemAlloc((MAX_PATH
+1) * sizeof(WCHAR
));
877 return E_OUTOFMEMORY
;
879 if (_ILIsDesktop(pidl
)) { /* empty pidl */
880 if ((GET_SHGDN_FOR(dwFlags
) & SHGDN_FORPARSING
) &&
881 (GET_SHGDN_RELATION(dwFlags
) != SHGDN_INFOLDER
))
883 if (This
->sPathTarget
)
884 lstrcpynW(pszPath
, This
->sPathTarget
, MAX_PATH
);
886 /* pidl has to contain exactly one non null SHITEMID */
889 } else if (_ILIsPidlSimple(pidl
)) {
890 if ((GET_SHGDN_FOR(dwFlags
) & SHGDN_FORPARSING
) &&
891 (GET_SHGDN_RELATION(dwFlags
) != SHGDN_INFOLDER
) &&
894 lstrcpynW(pszPath
, This
->sPathTarget
, MAX_PATH
);
895 PathAddBackslashW(pszPath
);
896 len
= lstrlenW(pszPath
);
898 _ILSimpleGetTextW(pidl
, pszPath
+ len
, MAX_PATH
+ 1 - len
);
899 if (!_ILIsFolder(pidl
)) SHELL_FS_ProcessDisplayFilename(pszPath
, dwFlags
);
901 hr
= SHELL32_GetDisplayNameOfChild(iface
, pidl
, dwFlags
, pszPath
, MAX_PATH
);
905 /* Win9x always returns ANSI strings, NT always returns Unicode strings */
906 if (GetVersion() & 0x80000000) {
907 strRet
->uType
= STRRET_CSTR
;
908 if (!WideCharToMultiByte(CP_ACP
, 0, pszPath
, -1, strRet
->u
.cStr
, MAX_PATH
,
910 strRet
->u
.cStr
[0] = '\0';
911 CoTaskMemFree(pszPath
);
913 strRet
->uType
= STRRET_WSTR
;
914 strRet
->u
.pOleStr
= pszPath
;
917 CoTaskMemFree(pszPath
);
919 TRACE ("-- (%p)->(%s)\n", This
, strRet
->uType
== STRRET_CSTR
? strRet
->u
.cStr
: debugstr_w(strRet
->u
.pOleStr
));
923 /**************************************************************************
924 * IShellFolder_fnSetNameOf
925 * Changes the name of a file object or subfolder, possibly changing its item
926 * identifier in the process.
929 * HWND hwndOwner, //[in ] Owner window for output
930 * LPCITEMIDLIST pidl, //[in ] simple pidl of item to change
931 * LPCOLESTR lpszName, //[in ] the items new display name
932 * DWORD dwFlags, //[in ] SHGNO formatting flags
933 * LPITEMIDLIST* ppidlOut) //[out] simple pidl returned
935 static HRESULT WINAPI
IShellFolder_fnSetNameOf (IShellFolder2
* iface
,
940 LPITEMIDLIST
* pPidlOut
)
942 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
943 WCHAR szSrc
[MAX_PATH
+ 1], szDest
[MAX_PATH
+ 1];
945 BOOL bIsFolder
= _ILIsFolder (ILFindLastID (pidl
));
947 TRACE ("(%p)->(%p,pidl=%p,%s,%u,%p)\n", This
, hwndOwner
, pidl
,
948 debugstr_w (lpName
), dwFlags
, pPidlOut
);
950 /* build source path */
951 lstrcpynW(szSrc
, This
->sPathTarget
, MAX_PATH
);
952 ptr
= PathAddBackslashW (szSrc
);
954 _ILSimpleGetTextW (pidl
, ptr
, MAX_PATH
+ 1 - (ptr
- szSrc
));
956 /* build destination path */
957 if (dwFlags
== SHGDN_NORMAL
|| dwFlags
& SHGDN_INFOLDER
) {
958 lstrcpynW(szDest
, This
->sPathTarget
, MAX_PATH
);
959 ptr
= PathAddBackslashW (szDest
);
961 lstrcpynW(ptr
, lpName
, MAX_PATH
+ 1 - (ptr
- szDest
));
963 lstrcpynW(szDest
, lpName
, MAX_PATH
);
965 if(!(dwFlags
& SHGDN_FORPARSING
) && SHELL_FS_HideExtension(szSrc
)) {
966 WCHAR
*ext
= PathFindExtensionW(szSrc
);
968 INT len
= strlenW(szDest
);
969 lstrcpynW(szDest
+ len
, ext
, MAX_PATH
- len
);
973 TRACE ("src=%s dest=%s\n", debugstr_w(szSrc
), debugstr_w(szDest
));
975 if (MoveFileW (szSrc
, szDest
)) {
979 hr
= _ILCreateFromPathW(szDest
, pPidlOut
);
981 SHChangeNotify (bIsFolder
? SHCNE_RENAMEFOLDER
: SHCNE_RENAMEITEM
,
982 SHCNF_PATHW
, szSrc
, szDest
);
990 static HRESULT WINAPI
IShellFolder_fnGetDefaultSearchGUID (IShellFolder2
*iface
,
993 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
994 FIXME ("(%p)\n", This
);
997 static HRESULT WINAPI
IShellFolder_fnEnumSearches (IShellFolder2
* iface
,
998 IEnumExtraSearch
** ppenum
)
1000 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
1001 FIXME ("(%p)\n", This
);
1005 static HRESULT WINAPI
1006 IShellFolder_fnGetDefaultColumn (IShellFolder2
* iface
, DWORD dwRes
,
1007 ULONG
* pSort
, ULONG
* pDisplay
)
1009 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
1011 TRACE ("(%p)\n", This
);
1021 static HRESULT WINAPI
1022 IShellFolder_fnGetDefaultColumnState (IShellFolder2
* iface
, UINT iColumn
,
1025 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
1027 TRACE ("(%p)\n", This
);
1029 if (!pcsFlags
|| iColumn
>= GENERICSHELLVIEWCOLUMNS
)
1030 return E_INVALIDARG
;
1032 *pcsFlags
= GenericSFHeader
[iColumn
].pcsFlags
;
1037 static HRESULT WINAPI
1038 IShellFolder_fnGetDetailsEx (IShellFolder2
* iface
, LPCITEMIDLIST pidl
,
1039 const SHCOLUMNID
* pscid
, VARIANT
* pv
)
1041 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
1042 FIXME ("(%p)\n", This
);
1047 static HRESULT WINAPI
1048 IShellFolder_fnGetDetailsOf (IShellFolder2
* iface
, LPCITEMIDLIST pidl
,
1049 UINT iColumn
, SHELLDETAILS
* psd
)
1051 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
1052 HRESULT hr
= E_FAIL
;
1054 TRACE ("(%p)->(%p %i %p)\n", This
, pidl
, iColumn
, psd
);
1056 if (!psd
|| iColumn
>= GENERICSHELLVIEWCOLUMNS
)
1057 return E_INVALIDARG
;
1060 /* the header titles */
1061 psd
->fmt
= GenericSFHeader
[iColumn
].fmt
;
1062 psd
->cxChar
= GenericSFHeader
[iColumn
].cxChar
;
1063 psd
->str
.uType
= STRRET_CSTR
;
1064 LoadStringA (shell32_hInstance
, GenericSFHeader
[iColumn
].colnameid
,
1065 psd
->str
.u
.cStr
, MAX_PATH
);
1069 psd
->str
.uType
= STRRET_CSTR
;
1070 /* the data from the pidl */
1073 hr
= IShellFolder_GetDisplayNameOf (iface
, pidl
,
1074 SHGDN_NORMAL
| SHGDN_INFOLDER
, &psd
->str
);
1077 _ILGetFileSize (pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
1080 _ILGetFileType (pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
1083 _ILGetFileDate (pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
1085 case 4: /* attributes */
1086 _ILGetFileAttributes (pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
1094 static HRESULT WINAPI
1095 IShellFolder_fnMapColumnToSCID (IShellFolder2
* iface
, UINT column
,
1098 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
1099 FIXME ("(%p)\n", This
);
1103 static const IShellFolder2Vtbl sfvt
=
1105 IShellFolder_fnQueryInterface
,
1106 IShellFolder_fnAddRef
,
1107 IShellFolder_fnRelease
,
1108 IShellFolder_fnParseDisplayName
,
1109 IShellFolder_fnEnumObjects
,
1110 IShellFolder_fnBindToObject
,
1111 IShellFolder_fnBindToStorage
,
1112 IShellFolder_fnCompareIDs
,
1113 IShellFolder_fnCreateViewObject
,
1114 IShellFolder_fnGetAttributesOf
,
1115 IShellFolder_fnGetUIObjectOf
,
1116 IShellFolder_fnGetDisplayNameOf
,
1117 IShellFolder_fnSetNameOf
,
1119 IShellFolder_fnGetDefaultSearchGUID
,
1120 IShellFolder_fnEnumSearches
,
1121 IShellFolder_fnGetDefaultColumn
,
1122 IShellFolder_fnGetDefaultColumnState
,
1123 IShellFolder_fnGetDetailsEx
,
1124 IShellFolder_fnGetDetailsOf
,
1125 IShellFolder_fnMapColumnToSCID
1128 /****************************************************************************
1129 * ISFHelper for IShellFolder implementation
1132 static HRESULT WINAPI
1133 ISFHelper_fnQueryInterface (ISFHelper
* iface
, REFIID riid
, LPVOID
* ppvObj
)
1135 IGenericSFImpl
*This
= impl_from_ISFHelper(iface
);
1137 TRACE ("(%p)->(count=%u)\n", This
, This
->ref
);
1139 return IUnknown_QueryInterface (This
->pUnkOuter
, riid
, ppvObj
);
1142 static ULONG WINAPI
ISFHelper_fnAddRef (ISFHelper
* iface
)
1144 IGenericSFImpl
*This
= impl_from_ISFHelper(iface
);
1146 TRACE ("(%p)->(count=%u)\n", This
, This
->ref
);
1148 return IUnknown_AddRef (This
->pUnkOuter
);
1151 static ULONG WINAPI
ISFHelper_fnRelease (ISFHelper
* iface
)
1153 IGenericSFImpl
*This
= impl_from_ISFHelper(iface
);
1155 TRACE ("(%p)\n", This
);
1157 return IUnknown_Release (This
->pUnkOuter
);
1160 /****************************************************************************
1161 * ISFHelper_fnGetUniqueName
1163 * creates a unique folder name
1166 static HRESULT WINAPI
1167 ISFHelper_fnGetUniqueName (ISFHelper
* iface
, LPWSTR pwszName
, UINT uLen
)
1169 IGenericSFImpl
*This
= impl_from_ISFHelper(iface
);
1172 WCHAR wszText
[MAX_PATH
];
1173 WCHAR wszNewFolder
[25];
1174 const WCHAR wszFormat
[] = {'%','s',' ','%','d',0 };
1176 TRACE ("(%p)(%p %u)\n", This
, pwszName
, uLen
);
1178 LoadStringW(shell32_hInstance
, IDS_NEWFOLDER
, wszNewFolder
, sizeof(wszNewFolder
)/sizeof(WCHAR
));
1179 if (uLen
< sizeof(wszNewFolder
)/sizeof(WCHAR
) + 3)
1182 lstrcpynW (pwszName
, wszNewFolder
, uLen
);
1184 hr
= IShellFolder_fnEnumObjects (_IShellFolder2_ (This
), 0,
1185 SHCONTF_FOLDERS
| SHCONTF_NONFOLDERS
| SHCONTF_INCLUDEHIDDEN
, &penum
);
1192 IEnumIDList_Reset (penum
);
1193 while (S_OK
== IEnumIDList_Next (penum
, 1, &pidl
, &dwFetched
) &&
1195 _ILSimpleGetTextW (pidl
, wszText
, MAX_PATH
);
1196 if (0 == lstrcmpiW (wszText
, pwszName
)) {
1197 snprintfW (pwszName
, uLen
, wszFormat
, wszNewFolder
, i
++);
1206 IEnumIDList_Release (penum
);
1211 /****************************************************************************
1212 * ISFHelper_fnAddFolder
1214 * adds a new folder.
1217 static HRESULT WINAPI
1218 ISFHelper_fnAddFolder (ISFHelper
* iface
, HWND hwnd
, LPCWSTR pwszName
,
1219 LPITEMIDLIST
* ppidlOut
)
1221 IGenericSFImpl
*This
= impl_from_ISFHelper(iface
);
1222 WCHAR wszNewDir
[MAX_PATH
];
1224 HRESULT hres
= E_FAIL
;
1226 TRACE ("(%p)(%s %p)\n", This
, debugstr_w(pwszName
), ppidlOut
);
1229 if (This
->sPathTarget
)
1230 lstrcpynW(wszNewDir
, This
->sPathTarget
, MAX_PATH
);
1231 PathAppendW(wszNewDir
, pwszName
);
1233 bRes
= CreateDirectoryW (wszNewDir
, NULL
);
1235 LPITEMIDLIST relPidl
;
1237 lstrcpyW(wszNewDir
, pwszName
);
1239 hres
= IShellFolder_ParseDisplayName((IShellFolder
*)&This
->lpvtblShellFolder
,
1240 hwnd
, NULL
, wszNewDir
, NULL
, &relPidl
, NULL
);
1242 if (SUCCEEDED(hres
)) {
1243 LPITEMIDLIST fullPidl
;
1245 fullPidl
= ILCombine(This
->pidlRoot
, relPidl
);
1248 SHChangeNotify(SHCNE_MKDIR
, SHCNF_IDLIST
, fullPidl
, NULL
);
1252 *ppidlOut
= relPidl
;
1256 WARN("failed to combine %s into a full PIDL\n", wine_dbgstr_w(pwszName
));
1261 WARN("failed to parse %s into a PIDL\n", wine_dbgstr_w(pwszName
));
1264 WCHAR wszText
[128 + MAX_PATH
];
1265 WCHAR wszTempText
[128];
1266 WCHAR wszCaption
[256];
1268 /* Cannot Create folder because of permissions */
1269 LoadStringW (shell32_hInstance
, IDS_CREATEFOLDER_DENIED
, wszTempText
,
1270 sizeof (wszTempText
)/sizeof (wszTempText
[0]));
1271 LoadStringW (shell32_hInstance
, IDS_CREATEFOLDER_CAPTION
, wszCaption
,
1272 sizeof (wszCaption
)/sizeof (wszCaption
[0]));
1273 sprintfW (wszText
, wszTempText
, wszNewDir
);
1274 MessageBoxW (hwnd
, wszText
, wszCaption
, MB_OK
| MB_ICONEXCLAMATION
);
1280 /****************************************************************************
1283 * Builds a list of paths like the one used in SHFileOperation from a table of
1284 * PIDLs relative to the given base folder
1286 static WCHAR
*build_paths_list(LPCWSTR wszBasePath
, int cidl
, const LPCITEMIDLIST
*pidls
)
1288 WCHAR
*wszPathsList
;
1293 iPathLen
= lstrlenW(wszBasePath
);
1294 wszPathsList
= HeapAlloc(GetProcessHeap(), 0, MAX_PATH
*sizeof(WCHAR
)*cidl
+1);
1295 wszListPos
= wszPathsList
;
1297 for (i
= 0; i
< cidl
; i
++) {
1298 if (!_ILIsFolder(pidls
[i
]) && !_ILIsValue(pidls
[i
]))
1301 lstrcpynW(wszListPos
, wszBasePath
, MAX_PATH
);
1302 /* FIXME: abort if path too long */
1303 _ILSimpleGetTextW(pidls
[i
], wszListPos
+iPathLen
, MAX_PATH
-iPathLen
);
1304 wszListPos
+= lstrlenW(wszListPos
)+1;
1307 return wszPathsList
;
1310 /****************************************************************************
1311 * ISFHelper_fnDeleteItems
1313 * deletes items in folder
1315 static HRESULT WINAPI
1316 ISFHelper_fnDeleteItems (ISFHelper
* iface
, UINT cidl
, LPCITEMIDLIST
* apidl
)
1318 IGenericSFImpl
*This
= impl_from_ISFHelper(iface
);
1321 WCHAR wszPath
[MAX_PATH
];
1322 WCHAR
*wszPathsList
;
1324 WCHAR
*wszCurrentPath
;
1326 TRACE ("(%p)(%u %p)\n", This
, cidl
, apidl
);
1327 if (cidl
==0) return S_OK
;
1329 if (This
->sPathTarget
)
1330 lstrcpynW(wszPath
, This
->sPathTarget
, MAX_PATH
);
1333 PathAddBackslashW(wszPath
);
1334 wszPathsList
= build_paths_list(wszPath
, cidl
, apidl
);
1336 ZeroMemory(&op
, sizeof(op
));
1337 op
.hwnd
= GetActiveWindow();
1338 op
.wFunc
= FO_DELETE
;
1339 op
.pFrom
= wszPathsList
;
1340 op
.fFlags
= FOF_ALLOWUNDO
;
1341 if (SHFileOperationW(&op
))
1343 WARN("SHFileOperation failed\n");
1349 /* we currently need to manually send the notifies */
1350 wszCurrentPath
= wszPathsList
;
1351 for (i
= 0; i
< cidl
; i
++)
1355 if (_ILIsFolder(apidl
[i
]))
1356 wEventId
= SHCNE_RMDIR
;
1357 else if (_ILIsValue(apidl
[i
]))
1358 wEventId
= SHCNE_DELETE
;
1362 /* check if file exists */
1363 if (GetFileAttributesW(wszCurrentPath
) == INVALID_FILE_ATTRIBUTES
)
1365 LPITEMIDLIST pidl
= ILCombine(This
->pidlRoot
, apidl
[i
]);
1366 SHChangeNotify(wEventId
, SHCNF_IDLIST
, pidl
, NULL
);
1370 wszCurrentPath
+= lstrlenW(wszCurrentPath
)+1;
1372 HeapFree(GetProcessHeap(), 0, wszPathsList
);
1376 /****************************************************************************
1377 * ISFHelper_fnCopyItems
1379 * copies items to this folder
1381 static HRESULT WINAPI
1382 ISFHelper_fnCopyItems (ISFHelper
* iface
, IShellFolder
* pSFFrom
, UINT cidl
,
1383 LPCITEMIDLIST
* apidl
)
1386 IPersistFolder2
*ppf2
= NULL
;
1387 char szSrcPath
[MAX_PATH
],
1388 szDstPath
[MAX_PATH
];
1390 IGenericSFImpl
*This
= impl_from_ISFHelper(iface
);
1392 TRACE ("(%p)->(%p,%u,%p)\n", This
, pSFFrom
, cidl
, apidl
);
1394 IShellFolder_QueryInterface (pSFFrom
, &IID_IPersistFolder2
,
1399 if (SUCCEEDED (IPersistFolder2_GetCurFolder (ppf2
, &pidl
))) {
1400 for (i
= 0; i
< cidl
; i
++) {
1401 SHGetPathFromIDListA (pidl
, szSrcPath
);
1402 PathAddBackslashA (szSrcPath
);
1403 _ILSimpleGetText (apidl
[i
], szSrcPath
+ strlen (szSrcPath
),
1406 if (!WideCharToMultiByte(CP_ACP
, 0, This
->sPathTarget
, -1, szDstPath
, MAX_PATH
, NULL
, NULL
))
1407 szDstPath
[0] = '\0';
1408 PathAddBackslashA (szDstPath
);
1409 _ILSimpleGetText (apidl
[i
], szDstPath
+ strlen (szDstPath
),
1411 MESSAGE ("would copy %s to %s\n", szSrcPath
, szDstPath
);
1415 IPersistFolder2_Release (ppf2
);
1420 static const ISFHelperVtbl shvt
=
1422 ISFHelper_fnQueryInterface
,
1424 ISFHelper_fnRelease
,
1425 ISFHelper_fnGetUniqueName
,
1426 ISFHelper_fnAddFolder
,
1427 ISFHelper_fnDeleteItems
,
1428 ISFHelper_fnCopyItems
1431 /************************************************************************
1432 * IFSFldr_PersistFolder3_QueryInterface
1435 static HRESULT WINAPI
1436 IFSFldr_PersistFolder3_QueryInterface (IPersistFolder3
* iface
, REFIID iid
,
1439 IGenericSFImpl
*This
= impl_from_IPersistFolder3(iface
);
1441 TRACE ("(%p)\n", This
);
1443 return IUnknown_QueryInterface (This
->pUnkOuter
, iid
, ppvObj
);
1446 /************************************************************************
1447 * IFSFldr_PersistFolder3_AddRef
1451 IFSFldr_PersistFolder3_AddRef (IPersistFolder3
* iface
)
1453 IGenericSFImpl
*This
= impl_from_IPersistFolder3(iface
);
1455 TRACE ("(%p)->(count=%u)\n", This
, This
->ref
);
1457 return IUnknown_AddRef (This
->pUnkOuter
);
1460 /************************************************************************
1461 * IFSFldr_PersistFolder3_Release
1465 IFSFldr_PersistFolder3_Release (IPersistFolder3
* iface
)
1467 IGenericSFImpl
*This
= impl_from_IPersistFolder3(iface
);
1469 TRACE ("(%p)->(count=%u)\n", This
, This
->ref
);
1471 return IUnknown_Release (This
->pUnkOuter
);
1474 /************************************************************************
1475 * IFSFldr_PersistFolder3_GetClassID
1477 static HRESULT WINAPI
1478 IFSFldr_PersistFolder3_GetClassID (IPersistFolder3
* iface
, CLSID
* lpClassId
)
1480 IGenericSFImpl
*This
= impl_from_IPersistFolder3(iface
);
1482 TRACE ("(%p)\n", This
);
1486 *lpClassId
= *This
->pclsid
;
1491 /************************************************************************
1492 * IFSFldr_PersistFolder3_Initialize
1495 * sPathTarget is not set. Don't know how to handle in a non rooted environment.
1497 static HRESULT WINAPI
1498 IFSFldr_PersistFolder3_Initialize (IPersistFolder3
* iface
, LPCITEMIDLIST pidl
)
1500 WCHAR wszTemp
[MAX_PATH
];
1502 IGenericSFImpl
*This
= impl_from_IPersistFolder3(iface
);
1504 TRACE ("(%p)->(%p)\n", This
, pidl
);
1506 SHFree (This
->pidlRoot
); /* free the old pidl */
1507 This
->pidlRoot
= ILClone (pidl
); /* set my pidl */
1509 SHFree (This
->sPathTarget
);
1510 This
->sPathTarget
= NULL
;
1513 if (SHGetPathFromIDListW (pidl
, wszTemp
)) {
1514 int len
= strlenW(wszTemp
);
1515 This
->sPathTarget
= SHAlloc((len
+ 1) * sizeof(WCHAR
));
1516 if (!This
->sPathTarget
)
1517 return E_OUTOFMEMORY
;
1518 memcpy(This
->sPathTarget
, wszTemp
, (len
+ 1) * sizeof(WCHAR
));
1521 TRACE ("--(%p)->(%s)\n", This
, debugstr_w(This
->sPathTarget
));
1525 /**************************************************************************
1526 * IFSFldr_PersistFolder3_GetCurFolder
1528 static HRESULT WINAPI
1529 IFSFldr_PersistFolder3_fnGetCurFolder (IPersistFolder3
* iface
,
1530 LPITEMIDLIST
* pidl
)
1532 IGenericSFImpl
*This
= impl_from_IPersistFolder3(iface
);
1534 TRACE ("(%p)->(%p)\n", This
, pidl
);
1536 if (!pidl
) return E_POINTER
;
1537 *pidl
= ILClone (This
->pidlRoot
);
1541 /**************************************************************************
1542 * IFSFldr_PersistFolder3_InitializeEx
1544 * FIXME: error handling
1546 static HRESULT WINAPI
1547 IFSFldr_PersistFolder3_InitializeEx (IPersistFolder3
* iface
,
1548 IBindCtx
* pbc
, LPCITEMIDLIST pidlRoot
,
1549 const PERSIST_FOLDER_TARGET_INFO
* ppfti
)
1551 WCHAR wszTemp
[MAX_PATH
];
1553 IGenericSFImpl
*This
= impl_from_IPersistFolder3(iface
);
1555 TRACE ("(%p)->(%p,%p,%p)\n", This
, pbc
, pidlRoot
, ppfti
);
1557 TRACE ("--%p %s %s 0x%08x 0x%08x\n",
1558 ppfti
->pidlTargetFolder
, debugstr_w (ppfti
->szTargetParsingName
),
1559 debugstr_w (ppfti
->szNetworkProvider
), ppfti
->dwAttributes
,
1563 if (ppfti
&& ppfti
->pidlTargetFolder
)
1564 pdump (ppfti
->pidlTargetFolder
);
1567 __SHFreeAndNil (&This
->pidlRoot
); /* free the old */
1568 if (This
->sPathTarget
)
1569 __SHFreeAndNil (&This
->sPathTarget
);
1572 * Root path and pidl
1574 This
->pidlRoot
= ILClone (pidlRoot
);
1577 * the target folder is specified in csidl OR pidlTargetFolder OR
1578 * szTargetParsingName
1581 if (ppfti
->csidl
!= -1) {
1582 if (SHGetSpecialFolderPathW (0, wszTemp
, ppfti
->csidl
,
1583 ppfti
->csidl
& CSIDL_FLAG_CREATE
)) {
1584 int len
= strlenW(wszTemp
);
1585 This
->sPathTarget
= SHAlloc((len
+ 1) * sizeof(WCHAR
));
1586 if (!This
->sPathTarget
)
1587 return E_OUTOFMEMORY
;
1588 memcpy(This
->sPathTarget
, wszTemp
, (len
+ 1) * sizeof(WCHAR
));
1590 } else if (ppfti
->szTargetParsingName
[0]) {
1591 int len
= strlenW(ppfti
->szTargetParsingName
);
1592 This
->sPathTarget
= SHAlloc((len
+ 1) * sizeof(WCHAR
));
1593 if (!This
->sPathTarget
)
1594 return E_OUTOFMEMORY
;
1595 memcpy(This
->sPathTarget
, ppfti
->szTargetParsingName
,
1596 (len
+ 1) * sizeof(WCHAR
));
1597 } else if (ppfti
->pidlTargetFolder
) {
1598 if (SHGetPathFromIDListW(ppfti
->pidlTargetFolder
, wszTemp
)) {
1599 int len
= strlenW(wszTemp
);
1600 This
->sPathTarget
= SHAlloc((len
+ 1) * sizeof(WCHAR
));
1601 if (!This
->sPathTarget
)
1602 return E_OUTOFMEMORY
;
1603 memcpy(This
->sPathTarget
, wszTemp
, (len
+ 1) * sizeof(WCHAR
));
1608 TRACE ("--(%p)->(target=%s)\n", This
, debugstr_w(This
->sPathTarget
));
1609 pdump (This
->pidlRoot
);
1610 return (This
->sPathTarget
) ? S_OK
: E_FAIL
;
1613 static HRESULT WINAPI
1614 IFSFldr_PersistFolder3_GetFolderTargetInfo (IPersistFolder3
* iface
,
1615 PERSIST_FOLDER_TARGET_INFO
* ppfti
)
1617 IGenericSFImpl
*This
= impl_from_IPersistFolder3(iface
);
1618 FIXME ("(%p)->(%p)\n", This
, ppfti
);
1619 ZeroMemory (ppfti
, sizeof (*ppfti
));
1623 static const IPersistFolder3Vtbl vt_FSFldr_PersistFolder3
=
1625 IFSFldr_PersistFolder3_QueryInterface
,
1626 IFSFldr_PersistFolder3_AddRef
,
1627 IFSFldr_PersistFolder3_Release
,
1628 IFSFldr_PersistFolder3_GetClassID
,
1629 IFSFldr_PersistFolder3_Initialize
,
1630 IFSFldr_PersistFolder3_fnGetCurFolder
,
1631 IFSFldr_PersistFolder3_InitializeEx
,
1632 IFSFldr_PersistFolder3_GetFolderTargetInfo
1635 /****************************************************************************
1636 * ISFDropTarget implementation
1639 ISFDropTarget_QueryDrop (IDropTarget
* iface
, DWORD dwKeyState
,
1642 DWORD dwEffect
= *pdwEffect
;
1644 IGenericSFImpl
*This
= impl_from_IDropTarget(iface
);
1646 *pdwEffect
= DROPEFFECT_NONE
;
1648 if (This
->fAcceptFmt
) { /* Does our interpretation of the keystate ... */
1649 *pdwEffect
= KeyStateToDropEffect (dwKeyState
);
1651 /* ... matches the desired effect ? */
1652 if (dwEffect
& *pdwEffect
) {
1659 static HRESULT WINAPI
1660 ISFDropTarget_QueryInterface (IDropTarget
* iface
, REFIID riid
, LPVOID
* ppvObj
)
1662 IGenericSFImpl
*This
= impl_from_IDropTarget(iface
);
1664 TRACE ("(%p)\n", This
);
1666 return IUnknown_QueryInterface (This
->pUnkOuter
, riid
, ppvObj
);
1669 static ULONG WINAPI
ISFDropTarget_AddRef (IDropTarget
* iface
)
1671 IGenericSFImpl
*This
= impl_from_IDropTarget(iface
);
1673 TRACE ("(%p)\n", This
);
1675 return IUnknown_AddRef (This
->pUnkOuter
);
1678 static ULONG WINAPI
ISFDropTarget_Release (IDropTarget
* iface
)
1680 IGenericSFImpl
*This
= impl_from_IDropTarget(iface
);
1682 TRACE ("(%p)\n", This
);
1684 return IUnknown_Release (This
->pUnkOuter
);
1687 static HRESULT WINAPI
1688 ISFDropTarget_DragEnter (IDropTarget
* iface
, IDataObject
* pDataObject
,
1689 DWORD dwKeyState
, POINTL pt
, DWORD
* pdwEffect
)
1693 IGenericSFImpl
*This
= impl_from_IDropTarget(iface
);
1695 TRACE ("(%p)->(DataObject=%p)\n", This
, pDataObject
);
1697 InitFormatEtc (fmt
, This
->cfShellIDList
, TYMED_HGLOBAL
);
1699 This
->fAcceptFmt
= (S_OK
== IDataObject_QueryGetData (pDataObject
, &fmt
)) ?
1702 ISFDropTarget_QueryDrop (iface
, dwKeyState
, pdwEffect
);
1707 static HRESULT WINAPI
1708 ISFDropTarget_DragOver (IDropTarget
* iface
, DWORD dwKeyState
, POINTL pt
,
1711 IGenericSFImpl
*This
= impl_from_IDropTarget(iface
);
1713 TRACE ("(%p)\n", This
);
1716 return E_INVALIDARG
;
1718 ISFDropTarget_QueryDrop (iface
, dwKeyState
, pdwEffect
);
1723 static HRESULT WINAPI
ISFDropTarget_DragLeave (IDropTarget
* iface
)
1725 IGenericSFImpl
*This
= impl_from_IDropTarget(iface
);
1727 TRACE ("(%p)\n", This
);
1729 This
->fAcceptFmt
= FALSE
;
1734 static HRESULT WINAPI
1735 ISFDropTarget_Drop (IDropTarget
* iface
, IDataObject
* pDataObject
,
1736 DWORD dwKeyState
, POINTL pt
, DWORD
* pdwEffect
)
1738 IGenericSFImpl
*This
= impl_from_IDropTarget(iface
);
1740 FIXME ("(%p) object dropped\n", This
);
1745 static const IDropTargetVtbl dtvt
= {
1746 ISFDropTarget_QueryInterface
,
1747 ISFDropTarget_AddRef
,
1748 ISFDropTarget_Release
,
1749 ISFDropTarget_DragEnter
,
1750 ISFDropTarget_DragOver
,
1751 ISFDropTarget_DragLeave
,