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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 LPSTR 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 #define _IShellFolder2_Offset ((int)(&(((IGenericSFImpl*)0)->lpvtblShellFolder)))
90 #define _ICOM_THIS_From_IShellFolder2(class, name) class* This = (class*)(((char*)name)-_IShellFolder2_Offset);
92 #define _IPersistFolder2_Offset ((int)(&(((IGenericSFImpl*)0)->lpvtblPersistFolder3)))
93 #define _ICOM_THIS_From_IPersistFolder2(class, name) class* This = (class*)(((char*)name)-_IPersistFolder2_Offset);
95 #define _IPersistFolder3_Offset ((int)(&(((IGenericSFImpl*)0)->lpvtblPersistFolder3)))
96 #define _ICOM_THIS_From_IPersistFolder3(class, name) class* This = (class*)(((char*)name)-_IPersistFolder3_Offset);
98 #define _IDropTarget_Offset ((int)(&(((IGenericSFImpl*)0)->lpvtblDropTarget)))
99 #define _ICOM_THIS_From_IDropTarget(class, name) class* This = (class*)(((char*)name)-_IDropTarget_Offset);
101 #define _ISFHelper_Offset ((int)(&(((IGenericSFImpl*)0)->lpvtblSFHelper)))
102 #define _ICOM_THIS_From_ISFHelper(class, name) class* This = (class*)(((char*)name)-_ISFHelper_Offset);
105 converts This to an interface pointer
107 #define _IUnknown_(This) (IUnknown*)&(This->lpVtbl)
108 #define _IShellFolder_(This) (IShellFolder*)&(This->lpvtblShellFolder)
109 #define _IShellFolder2_(This) (IShellFolder2*)&(This->lpvtblShellFolder)
110 #define _IPersist_(This) (IPersist*)&(This->lpvtblPersistFolder3)
111 #define _IPersistFolder_(This) (IPersistFolder*)&(This->lpvtblPersistFolder3)
112 #define _IPersistFolder2_(This) (IPersistFolder2*)&(This->lpvtblPersistFolder3)
113 #define _IPersistFolder3_(This) (IPersistFolder3*)&(This->lpvtblPersistFolder3)
114 #define _IDropTarget_(This) (IDropTarget*)&(This->lpvtblDropTarget)
115 #define _ISFHelper_(This) (ISFHelper*)&(This->lpvtblSFHelper)
117 /**************************************************************************
118 * registers clipboardformat once
120 static void SF_RegisterClipFmt (IGenericSFImpl
* This
)
122 TRACE ("(%p)\n", This
);
124 if (!This
->cfShellIDList
) {
125 This
->cfShellIDList
= RegisterClipboardFormatA (CFSTR_SHELLIDLIST
);
129 /**************************************************************************
130 * we need a separate IUnknown to handle aggregation
133 static HRESULT WINAPI
IUnknown_fnQueryInterface (IUnknown
* iface
, REFIID riid
, LPVOID
* ppvObj
)
135 IGenericSFImpl
*This
= (IGenericSFImpl
*)iface
;
137 TRACE ("(%p)->(%s,%p)\n", This
, shdebugstr_guid (riid
), ppvObj
);
141 if (IsEqualIID (riid
, &IID_IUnknown
))
142 *ppvObj
= _IUnknown_ (This
);
143 else if (IsEqualIID (riid
, &IID_IShellFolder
))
144 *ppvObj
= _IShellFolder_ (This
);
145 else if (IsEqualIID (riid
, &IID_IShellFolder2
))
146 *ppvObj
= _IShellFolder_ (This
);
147 else if (IsEqualIID (riid
, &IID_IPersist
))
148 *ppvObj
= _IPersist_ (This
);
149 else if (IsEqualIID (riid
, &IID_IPersistFolder
))
150 *ppvObj
= _IPersistFolder_ (This
);
151 else if (IsEqualIID (riid
, &IID_IPersistFolder2
))
152 *ppvObj
= _IPersistFolder2_ (This
);
153 else if (IsEqualIID (riid
, &IID_IPersistFolder3
))
154 *ppvObj
= _IPersistFolder3_ (This
);
155 else if (IsEqualIID (riid
, &IID_ISFHelper
))
156 *ppvObj
= _ISFHelper_ (This
);
157 else if (IsEqualIID (riid
, &IID_IDropTarget
)) {
158 *ppvObj
= _IDropTarget_ (This
);
159 SF_RegisterClipFmt (This
);
163 IUnknown_AddRef ((IUnknown
*) (*ppvObj
));
164 TRACE ("-- Interface = %p\n", *ppvObj
);
167 TRACE ("-- Interface: E_NOINTERFACE\n");
168 return E_NOINTERFACE
;
171 static ULONG WINAPI
IUnknown_fnAddRef (IUnknown
* iface
)
173 IGenericSFImpl
*This
= (IGenericSFImpl
*)iface
;
174 ULONG refCount
= InterlockedIncrement(&This
->ref
);
176 TRACE ("(%p)->(count=%lu)\n", This
, refCount
- 1);
181 static ULONG WINAPI
IUnknown_fnRelease (IUnknown
* iface
)
183 IGenericSFImpl
*This
= (IGenericSFImpl
*)iface
;
184 ULONG refCount
= InterlockedDecrement(&This
->ref
);
186 TRACE ("(%p)->(count=%lu)\n", This
, refCount
+ 1);
189 TRACE ("-- destroying IShellFolder(%p)\n", This
);
192 SHFree (This
->pidlRoot
);
193 if (This
->sPathTarget
)
194 SHFree (This
->sPathTarget
);
195 LocalFree ((HLOCAL
) This
);
200 static const IUnknownVtbl unkvt
=
202 IUnknown_fnQueryInterface
,
207 static shvheader GenericSFHeader
[] = {
208 {IDS_SHV_COLUMN1
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 15},
209 {IDS_SHV_COLUMN2
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 10},
210 {IDS_SHV_COLUMN3
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 10},
211 {IDS_SHV_COLUMN4
, SHCOLSTATE_TYPE_DATE
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 12},
212 {IDS_SHV_COLUMN5
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 5}
215 #define GENERICSHELLVIEWCOLUMNS 5
217 /**************************************************************************
218 * IFSFolder_Constructor
221 * creating undocumented ShellFS_Folder as part of an aggregation
222 * {F3364BA0-65B9-11CE-A9BA-00AA004AE837}
226 IFSFolder_Constructor (IUnknown
* pUnkOuter
, REFIID riid
, LPVOID
* ppv
)
230 TRACE ("unkOut=%p %s\n", pUnkOuter
, shdebugstr_guid (riid
));
232 if (pUnkOuter
&& !IsEqualIID (riid
, &IID_IUnknown
))
233 return CLASS_E_NOAGGREGATION
;
234 sf
= (IGenericSFImpl
*) LocalAlloc (LMEM_ZEROINIT
, sizeof (IGenericSFImpl
));
236 return E_OUTOFMEMORY
;
240 sf
->lpvtblShellFolder
= &sfvt
;
241 sf
->lpvtblPersistFolder3
= &vt_FSFldr_PersistFolder3
;
242 sf
->lpvtblDropTarget
= &dtvt
;
243 sf
->lpvtblSFHelper
= &shvt
;
244 sf
->pclsid
= (CLSID
*) & CLSID_ShellFSFolder
;
245 sf
->pUnkOuter
= pUnkOuter
? pUnkOuter
: _IUnknown_ (sf
);
247 if (!SUCCEEDED (IUnknown_QueryInterface (_IUnknown_ (sf
), riid
, ppv
))) {
248 IUnknown_Release (_IUnknown_ (sf
));
249 return E_NOINTERFACE
;
252 TRACE ("--%p\n", *ppv
);
256 /**************************************************************************
257 * IShellFolder_fnQueryInterface
260 * REFIID riid [in ] Requested InterfaceID
261 * LPVOID* ppvObject [out] Interface* to hold the result
263 static HRESULT WINAPI
264 IShellFolder_fnQueryInterface (IShellFolder2
* iface
, REFIID riid
,
267 _ICOM_THIS_From_IShellFolder2 (IGenericSFImpl
, iface
)
269 TRACE ("(%p)->(%s,%p)\n", This
, shdebugstr_guid (riid
), ppvObj
);
271 return IUnknown_QueryInterface (This
->pUnkOuter
, riid
, ppvObj
);
274 /**************************************************************************
275 * IShellFolder_AddRef
278 static ULONG WINAPI
IShellFolder_fnAddRef (IShellFolder2
* iface
)
280 _ICOM_THIS_From_IShellFolder2 (IGenericSFImpl
, iface
)
282 TRACE ("(%p)->(count=%lu)\n", This
, This
->ref
);
284 return IUnknown_AddRef (This
->pUnkOuter
);
287 /**************************************************************************
288 * IShellFolder_fnRelease
290 static ULONG WINAPI
IShellFolder_fnRelease (IShellFolder2
* iface
)
292 _ICOM_THIS_From_IShellFolder2 (IGenericSFImpl
, iface
)
294 TRACE ("(%p)->(count=%lu)\n", This
, This
->ref
);
296 return IUnknown_Release (This
->pUnkOuter
);
299 /**************************************************************************
300 * SHELL32_CreatePidlFromBindCtx [internal]
302 * If the caller bound File System Bind Data, assume it is the
303 * find data for the path.
304 * This allows binding of paths that don't exist.
306 LPITEMIDLIST
SHELL32_CreatePidlFromBindCtx(IBindCtx
*pbc
, LPCWSTR path
)
308 static const WCHAR szfsbc
[] = {
309 'F','i','l','e',' ','S','y','s','t','e','m',' ',
310 'B','i','n','d',' ','D','a','t','a',0 };
311 IFileSystemBindData
*fsbd
= NULL
;
312 LPITEMIDLIST pidl
= NULL
;
313 IUnknown
*param
= NULL
;
314 WIN32_FIND_DATAW wfd
;
317 TRACE("%p %s\n", pbc
, debugstr_w(path
));
322 /* see if the caller bound File System Bind Data */
323 r
= IBindCtx_GetObjectParam( pbc
, (LPOLESTR
) szfsbc
, ¶m
);
327 r
= IUnknown_QueryInterface( param
, &IID_IFileSystemBindData
,
331 r
= IFileSystemBindData_GetFindData( fsbd
, &wfd
);
334 lstrcpynW( &wfd
.cFileName
[0], path
, MAX_PATH
);
335 pidl
= _ILCreateFromFindDataW( &wfd
);
337 IFileSystemBindData_Release( fsbd
);
343 /**************************************************************************
344 * IShellFolder_ParseDisplayName {SHELL32}
346 * Parse a display name.
349 * hwndOwner [in] Parent window for any message's
350 * pbc [in] optional FileSystemBindData context
351 * lpszDisplayName [in] Unicode displayname.
352 * pchEaten [out] (unicode) characters processed
353 * ppidl [out] complex pidl to item
354 * pdwAttributes [out] items attributes
357 * Every folder tries to parse only its own (the leftmost) pidl and creates a
358 * subfolder to evaluate the remaining parts.
359 * Now we can parse into namespaces implemented by shell extensions
361 * Behaviour on win98: lpszDisplayName=NULL -> crash
362 * lpszDisplayName="" -> returns mycoputer-pidl
365 * pdwAttributes is not set
366 * pchEaten is not set like in windows
368 static HRESULT WINAPI
369 IShellFolder_fnParseDisplayName (IShellFolder2
* iface
,
372 LPOLESTR lpszDisplayName
,
373 DWORD
* pchEaten
, LPITEMIDLIST
* ppidl
,
374 DWORD
* pdwAttributes
)
376 _ICOM_THIS_From_IShellFolder2 (IGenericSFImpl
, iface
)
378 HRESULT hr
= E_INVALIDARG
;
379 LPCWSTR szNext
= NULL
;
380 WCHAR szElement
[MAX_PATH
];
381 WCHAR szPath
[MAX_PATH
];
382 LPITEMIDLIST pidlTemp
= NULL
;
385 TRACE ("(%p)->(HWND=%p,%p,%p=%s,%p,pidl=%p,%p)\n",
386 This
, hwndOwner
, pbc
, lpszDisplayName
, debugstr_w (lpszDisplayName
),
387 pchEaten
, ppidl
, pdwAttributes
);
389 if (!lpszDisplayName
|| !ppidl
)
393 *pchEaten
= 0; /* strange but like the original */
395 pidlTemp
= SHELL32_CreatePidlFromBindCtx(pbc
, lpszDisplayName
);
396 if (!pidlTemp
&& *lpszDisplayName
)
398 /* get the next element */
399 szNext
= GetNextElementW (lpszDisplayName
, szElement
, MAX_PATH
);
401 /* build the full pathname to the element */
402 /* lstrcpyW(szPath, This->sPathTarget); */
403 MultiByteToWideChar(CP_ACP
, 0, This
->sPathTarget
, -1, szPath
, MAX_PATH
);
404 PathAddBackslashW(szPath
);
405 len
= lstrlenW(szPath
);
406 lstrcpynW(szPath
+ len
, szElement
, MAX_PATH
- len
);
409 hr
= _ILCreateFromPathW(szPath
, &pidlTemp
);
412 if (szNext
&& *szNext
) {
413 /* try to analyse the next element */
414 hr
= SHELL32_ParseNextElement (iface
, hwndOwner
, pbc
,
415 &pidlTemp
, (LPOLESTR
) szNext
, pchEaten
, pdwAttributes
);
417 /* it's the last element */
418 if (pdwAttributes
&& *pdwAttributes
) {
419 hr
= SHELL32_GetItemAttributes (_IShellFolder_ (This
),
420 pidlTemp
, pdwAttributes
);
431 TRACE ("(%p)->(-- pidl=%p ret=0x%08lx)\n", This
, ppidl
? *ppidl
: 0, hr
);
436 /**************************************************************************
437 * IShellFolder_fnEnumObjects
439 * HWND hwndOwner, //[in ] Parent Window
440 * DWORD grfFlags, //[in ] SHCONTF enumeration mask
441 * LPENUMIDLIST* ppenumIDList //[out] IEnumIDList interface
443 static HRESULT WINAPI
444 IShellFolder_fnEnumObjects (IShellFolder2
* iface
, HWND hwndOwner
,
445 DWORD dwFlags
, LPENUMIDLIST
* ppEnumIDList
)
447 _ICOM_THIS_From_IShellFolder2 (IGenericSFImpl
, iface
)
449 TRACE ("(%p)->(HWND=%p flags=0x%08lx pplist=%p)\n", This
, hwndOwner
,
450 dwFlags
, ppEnumIDList
);
452 *ppEnumIDList
= IEnumIDList_Constructor();
455 WCHAR path
[MAX_PATH
];
456 MultiByteToWideChar(CP_ACP
, 0, This
->sPathTarget
, -1, path
, MAX_PATH
);
457 CreateFolderEnumList(*ppEnumIDList
, path
, 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 _ICOM_THIS_From_IShellFolder2 (IGenericSFImpl
, 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 _ICOM_THIS_From_IShellFolder2 (IGenericSFImpl
, 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 _ICOM_THIS_From_IShellFolder2 (IGenericSFImpl
, 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 _ICOM_THIS_From_IShellFolder2 (IGenericSFImpl
, 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 _ICOM_THIS_From_IShellFolder2 (IGenericSFImpl
, iface
)
577 TRACE ("(%p)->(cidl=%d apidl=%p mask=%p (0x%08lx))\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
, (LPCITEMIDLIST
*)&rpidl
);
594 SHELL32_GetItemAttributes (psfParent
, rpidl
, rgfInOut
);
597 while (cidl
> 0 && *apidl
) {
599 SHELL32_GetItemAttributes (_IShellFolder_ (This
), *apidl
, rgfInOut
);
604 /* make sure SFGAO_VALIDATE is cleared, some apps depend on that */
605 *rgfInOut
&= ~SFGAO_VALIDATE
;
607 TRACE ("-- result=0x%08lx\n", *rgfInOut
);
612 /**************************************************************************
613 * IShellFolder_fnGetUIObjectOf
616 * HWND hwndOwner, //[in ] Parent window for any output
617 * UINT cidl, //[in ] array size
618 * LPCITEMIDLIST* apidl, //[in ] simple pidl array
619 * REFIID riid, //[in ] Requested Interface
620 * UINT* prgfInOut, //[ ] reserved
621 * LPVOID* ppvObject) //[out] Resulting Interface
624 * This function gets asked to return "view objects" for one or more (multiple
626 * The viewobject typically is an COM object with one of the following
628 * IExtractIcon,IDataObject,IContextMenu
629 * In order to support icon positions in the default Listview your DataObject
630 * must implement the SetData method (in addition to GetData :) - the shell
631 * passes a barely documented "Icon positions" structure to SetData when the
632 * drag starts, and GetData's it if the drop is in another explorer window that
633 * needs the positions.
635 static HRESULT WINAPI
636 IShellFolder_fnGetUIObjectOf (IShellFolder2
* iface
,
638 UINT cidl
, LPCITEMIDLIST
* apidl
, REFIID riid
,
639 UINT
* prgfInOut
, LPVOID
* ppvOut
)
641 _ICOM_THIS_From_IShellFolder2 (IGenericSFImpl
, iface
)
644 IUnknown
*pObj
= NULL
;
645 HRESULT hr
= E_INVALIDARG
;
647 TRACE ("(%p)->(%p,%u,apidl=%p,%s,%p,%p)\n",
648 This
, hwndOwner
, cidl
, apidl
, shdebugstr_guid (riid
), prgfInOut
, ppvOut
);
653 if (IsEqualIID (riid
, &IID_IContextMenu
) && (cidl
>= 1)) {
654 pObj
= (LPUNKNOWN
) ISvItemCm_Constructor ((IShellFolder
*) iface
,
655 This
->pidlRoot
, apidl
, cidl
);
657 } else if (IsEqualIID (riid
, &IID_IDataObject
) && (cidl
>= 1)) {
658 pObj
= (LPUNKNOWN
) IDataObject_Constructor (hwndOwner
,
659 This
->pidlRoot
, apidl
, cidl
);
661 } else if (IsEqualIID (riid
, &IID_IExtractIconA
) && (cidl
== 1)) {
662 pidl
= ILCombine (This
->pidlRoot
, apidl
[0]);
663 pObj
= (LPUNKNOWN
) IExtractIconA_Constructor (pidl
);
666 } else if (IsEqualIID (riid
, &IID_IExtractIconW
) && (cidl
== 1)) {
667 pidl
= ILCombine (This
->pidlRoot
, apidl
[0]);
668 pObj
= (LPUNKNOWN
) IExtractIconW_Constructor (pidl
);
671 } else if (IsEqualIID (riid
, &IID_IDropTarget
) && (cidl
>= 1)) {
672 hr
= IShellFolder_QueryInterface (iface
, &IID_IDropTarget
,
674 } else if ((IsEqualIID(riid
,&IID_IShellLinkW
) ||
675 IsEqualIID(riid
,&IID_IShellLinkA
)) && (cidl
== 1)) {
676 pidl
= ILCombine (This
->pidlRoot
, apidl
[0]);
677 hr
= IShellLink_ConstructFromFile(NULL
, riid
, pidl
, (LPVOID
*)&pObj
);
683 if (SUCCEEDED(hr
) && !pObj
)
688 TRACE ("(%p)->hr=0x%08lx\n", This
, hr
);
692 static const WCHAR AdvancedW
[] = { 'S','O','F','T','W','A','R','E',
693 '\\','M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
694 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\','E','x','p','l',
695 'o','r','e','r','\\','A','d','v','a','n','c','e','d',0 };
696 static const WCHAR HideFileExtW
[] = { 'H','i','d','e','F','i','l','e','E','x',
698 static const WCHAR NeverShowExtW
[] = { 'N','e','v','e','r','S','h','o','w','E',
701 static BOOL
hide_extension(LPWSTR szPath
)
705 DWORD dwDataSize
= sizeof (DWORD
);
706 BOOL doHide
= FALSE
; /* The default value is FALSE (win98 at least) */
708 if (!RegCreateKeyExW(HKEY_CURRENT_USER
, AdvancedW
, 0, 0, 0, KEY_ALL_ACCESS
, 0, &hKey
, 0)) {
709 if (!RegQueryValueExW(hKey
, HideFileExtW
, 0, 0, (LPBYTE
) &dwData
, &dwDataSize
))
715 LPWSTR ext
= PathFindExtensionW(szPath
);
718 WCHAR classname
[MAX_PATH
];
719 LONG classlen
= sizeof(classname
);
721 if (!RegQueryValueW(HKEY_CLASSES_ROOT
, ext
, classname
, &classlen
))
722 if (!RegOpenKeyW(HKEY_CLASSES_ROOT
, classname
, &hKey
)) {
723 if (!RegQueryValueExW(hKey
, NeverShowExtW
, 0, NULL
, NULL
, NULL
))
732 void SHELL_FS_ProcessDisplayFilename(LPSTR szPath
, DWORD dwFlags
)
734 WCHAR pathW
[MAX_PATH
];
736 /*FIXME: MSDN also mentions SHGDN_FOREDITING which is not yet handled. */
737 if (!(dwFlags
& SHGDN_FORPARSING
) &&
738 ((dwFlags
& SHGDN_INFOLDER
) || (dwFlags
== SHGDN_NORMAL
))) {
739 MultiByteToWideChar(CP_ACP
, 0, szPath
, -1, pathW
, MAX_PATH
);
740 if (hide_extension(pathW
) && szPath
[0] != '.')
741 PathRemoveExtensionA (szPath
);
745 /**************************************************************************
746 * IShellFolder_fnGetDisplayNameOf
747 * Retrieves the display name for the specified file object or subfolder
750 * LPCITEMIDLIST pidl, //[in ] complex pidl to item
751 * DWORD dwFlags, //[in ] SHGNO formatting flags
752 * LPSTRRET lpName) //[out] Returned display name
755 * if the name is in the pidl the ret value should be a STRRET_OFFSET
758 static HRESULT WINAPI
759 IShellFolder_fnGetDisplayNameOf (IShellFolder2
* iface
, LPCITEMIDLIST pidl
,
760 DWORD dwFlags
, LPSTRRET strRet
)
762 _ICOM_THIS_From_IShellFolder2 (IGenericSFImpl
, iface
)
767 TRACE ("(%p)->(pidl=%p,0x%08lx,%p)\n", This
, pidl
, dwFlags
, strRet
);
770 if (!pidl
|| !strRet
)
773 strRet
->uType
= STRRET_CSTR
;
774 if (_ILIsDesktop(pidl
)) { /* empty pidl */
775 if ((GET_SHGDN_FOR(dwFlags
) & SHGDN_FORPARSING
) &&
776 (GET_SHGDN_RELATION(dwFlags
) != SHGDN_INFOLDER
))
778 if (This
->sPathTarget
)
779 lstrcpynA(strRet
->u
.cStr
, This
->sPathTarget
, MAX_PATH
);
781 /* pidl has to contain exactly one non null SHITEMID */
784 } else if (_ILIsPidlSimple(pidl
)) {
785 if ((GET_SHGDN_FOR(dwFlags
) & SHGDN_FORPARSING
) &&
786 (GET_SHGDN_RELATION(dwFlags
) != SHGDN_INFOLDER
) &&
789 lstrcpynA(strRet
->u
.cStr
, This
->sPathTarget
, MAX_PATH
);
790 PathAddBackslashA(strRet
->u
.cStr
);
791 len
= lstrlenA(strRet
->u
.cStr
);
793 _ILSimpleGetText(pidl
, strRet
->u
.cStr
+ len
, MAX_PATH
- len
);
794 if (!_ILIsFolder(pidl
)) SHELL_FS_ProcessDisplayFilename(strRet
->u
.cStr
, dwFlags
);
796 hr
= SHELL32_GetDisplayNameOfChild(iface
, pidl
, dwFlags
, strRet
->u
.cStr
, MAX_PATH
);
799 TRACE ("-- (%p)->(%s)\n", This
, strRet
->u
.cStr
);
803 /**************************************************************************
804 * IShellFolder_fnSetNameOf
805 * Changes the name of a file object or subfolder, possibly changing its item
806 * identifier in the process.
809 * HWND hwndOwner, //[in ] Owner window for output
810 * LPCITEMIDLIST pidl, //[in ] simple pidl of item to change
811 * LPCOLESTR lpszName, //[in ] the items new display name
812 * DWORD dwFlags, //[in ] SHGNO formatting flags
813 * LPITEMIDLIST* ppidlOut) //[out] simple pidl returned
815 static HRESULT WINAPI
IShellFolder_fnSetNameOf (IShellFolder2
* iface
,
820 LPITEMIDLIST
* pPidlOut
)
822 _ICOM_THIS_From_IShellFolder2 (IGenericSFImpl
, iface
)
823 WCHAR szSrc
[MAX_PATH
], szDest
[MAX_PATH
];
825 BOOL bIsFolder
= _ILIsFolder (ILFindLastID (pidl
));
827 TRACE ("(%p)->(%p,pidl=%p,%s,%lu,%p)\n", This
, hwndOwner
, pidl
,
828 debugstr_w (lpName
), dwFlags
, pPidlOut
);
830 /* build source path */
831 MultiByteToWideChar(CP_ACP
, 0, This
->sPathTarget
, -1, szSrc
, MAX_PATH
);
832 ptr
= PathAddBackslashW (szSrc
);
834 _ILSimpleGetTextW (pidl
, ptr
, MAX_PATH
- (ptr
- szSrc
));
836 /* build destination path */
837 if (dwFlags
== SHGDN_NORMAL
|| dwFlags
& SHGDN_INFOLDER
) {
838 MultiByteToWideChar(CP_ACP
, 0, This
->sPathTarget
, -1, szDest
, MAX_PATH
);
839 ptr
= PathAddBackslashW (szDest
);
841 lstrcpynW(ptr
, lpName
, MAX_PATH
- (ptr
- szDest
));
843 lstrcpynW(szDest
, lpName
, MAX_PATH
);
845 if(!(dwFlags
& SHGDN_FORPARSING
) && hide_extension(szSrc
)) {
846 WCHAR
*ext
= PathFindExtensionW(szSrc
);
848 INT len
= strlenW(szDest
);
849 lstrcpynW(szDest
+ len
, ext
, MAX_PATH
- len
);
853 TRACE ("src=%s dest=%s\n", debugstr_w(szSrc
), debugstr_w(szDest
));
855 if (MoveFileW (szSrc
, szDest
)) {
859 hr
= _ILCreateFromPathW(szDest
, pPidlOut
);
861 SHChangeNotify (bIsFolder
? SHCNE_RENAMEFOLDER
: SHCNE_RENAMEITEM
,
862 SHCNF_PATHW
, szSrc
, szDest
);
870 static HRESULT WINAPI
IShellFolder_fnGetDefaultSearchGUID (IShellFolder2
*iface
,
873 _ICOM_THIS_From_IShellFolder2 (IGenericSFImpl
, iface
)
874 FIXME ("(%p)\n", This
);
877 static HRESULT WINAPI
IShellFolder_fnEnumSearches (IShellFolder2
* iface
,
878 IEnumExtraSearch
** ppenum
)
880 _ICOM_THIS_From_IShellFolder2 (IGenericSFImpl
, iface
)
881 FIXME ("(%p)\n", This
);
885 static HRESULT WINAPI
886 IShellFolder_fnGetDefaultColumn (IShellFolder2
* iface
, DWORD dwRes
,
887 ULONG
* pSort
, ULONG
* pDisplay
)
889 _ICOM_THIS_From_IShellFolder2 (IGenericSFImpl
, iface
)
891 TRACE ("(%p)\n", This
);
901 static HRESULT WINAPI
902 IShellFolder_fnGetDefaultColumnState (IShellFolder2
* iface
, UINT iColumn
,
905 _ICOM_THIS_From_IShellFolder2 (IGenericSFImpl
, iface
)
907 TRACE ("(%p)\n", This
);
909 if (!pcsFlags
|| iColumn
>= GENERICSHELLVIEWCOLUMNS
)
912 *pcsFlags
= GenericSFHeader
[iColumn
].pcsFlags
;
917 static HRESULT WINAPI
918 IShellFolder_fnGetDetailsEx (IShellFolder2
* iface
, LPCITEMIDLIST pidl
,
919 const SHCOLUMNID
* pscid
, VARIANT
* pv
)
921 _ICOM_THIS_From_IShellFolder2 (IGenericSFImpl
, iface
)
922 FIXME ("(%p)\n", This
);
927 static HRESULT WINAPI
928 IShellFolder_fnGetDetailsOf (IShellFolder2
* iface
, LPCITEMIDLIST pidl
,
929 UINT iColumn
, SHELLDETAILS
* psd
)
931 _ICOM_THIS_From_IShellFolder2 (IGenericSFImpl
, iface
)
934 TRACE ("(%p)->(%p %i %p)\n", This
, pidl
, iColumn
, psd
);
936 if (!psd
|| iColumn
>= GENERICSHELLVIEWCOLUMNS
)
940 /* the header titles */
941 psd
->fmt
= GenericSFHeader
[iColumn
].fmt
;
942 psd
->cxChar
= GenericSFHeader
[iColumn
].cxChar
;
943 psd
->str
.uType
= STRRET_CSTR
;
944 LoadStringA (shell32_hInstance
, GenericSFHeader
[iColumn
].colnameid
,
945 psd
->str
.u
.cStr
, MAX_PATH
);
948 /* the data from the pidl */
951 hr
= IShellFolder_GetDisplayNameOf (iface
, pidl
,
952 SHGDN_NORMAL
| SHGDN_INFOLDER
, &psd
->str
);
955 _ILGetFileSize (pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
958 _ILGetFileType (pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
961 _ILGetFileDate (pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
963 case 4: /* attributes */
964 _ILGetFileAttributes (pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
968 psd
->str
.uType
= STRRET_CSTR
;
974 static HRESULT WINAPI
975 IShellFolder_fnMapColumnToSCID (IShellFolder2
* iface
, UINT column
,
978 _ICOM_THIS_From_IShellFolder2 (IGenericSFImpl
, iface
)
979 FIXME ("(%p)\n", This
);
983 static const IShellFolder2Vtbl sfvt
=
985 IShellFolder_fnQueryInterface
,
986 IShellFolder_fnAddRef
,
987 IShellFolder_fnRelease
,
988 IShellFolder_fnParseDisplayName
,
989 IShellFolder_fnEnumObjects
,
990 IShellFolder_fnBindToObject
,
991 IShellFolder_fnBindToStorage
,
992 IShellFolder_fnCompareIDs
,
993 IShellFolder_fnCreateViewObject
,
994 IShellFolder_fnGetAttributesOf
,
995 IShellFolder_fnGetUIObjectOf
,
996 IShellFolder_fnGetDisplayNameOf
,
997 IShellFolder_fnSetNameOf
,
999 IShellFolder_fnGetDefaultSearchGUID
,
1000 IShellFolder_fnEnumSearches
,
1001 IShellFolder_fnGetDefaultColumn
,
1002 IShellFolder_fnGetDefaultColumnState
,
1003 IShellFolder_fnGetDetailsEx
,
1004 IShellFolder_fnGetDetailsOf
,
1005 IShellFolder_fnMapColumnToSCID
1008 /****************************************************************************
1009 * ISFHelper for IShellFolder implementation
1012 static HRESULT WINAPI
1013 ISFHelper_fnQueryInterface (ISFHelper
* iface
, REFIID riid
, LPVOID
* ppvObj
)
1015 _ICOM_THIS_From_ISFHelper (IGenericSFImpl
, iface
);
1017 TRACE ("(%p)->(count=%lu)\n", This
, This
->ref
);
1019 return IUnknown_QueryInterface (This
->pUnkOuter
, riid
, ppvObj
);
1022 static ULONG WINAPI
ISFHelper_fnAddRef (ISFHelper
* iface
)
1024 _ICOM_THIS_From_ISFHelper (IGenericSFImpl
, iface
);
1026 TRACE ("(%p)->(count=%lu)\n", This
, This
->ref
);
1028 return IUnknown_AddRef (This
->pUnkOuter
);
1031 static ULONG WINAPI
ISFHelper_fnRelease (ISFHelper
* iface
)
1033 _ICOM_THIS_From_ISFHelper (IGenericSFImpl
, iface
);
1035 TRACE ("(%p)\n", This
);
1037 return IUnknown_Release (This
->pUnkOuter
);
1040 /****************************************************************************
1041 * ISFHelper_fnAddFolder
1043 * creates a unique folder name
1046 static HRESULT WINAPI
1047 ISFHelper_fnGetUniqueName (ISFHelper
* iface
, LPSTR lpName
, UINT uLen
)
1049 _ICOM_THIS_From_ISFHelper (IGenericSFImpl
, iface
)
1052 char szText
[MAX_PATH
];
1053 char *szNewFolder
= "New Folder";
1055 TRACE ("(%p)(%s %u)\n", This
, lpName
, uLen
);
1057 if (uLen
< strlen (szNewFolder
) + 4)
1060 strcpy (lpName
, szNewFolder
);
1062 hr
= IShellFolder_fnEnumObjects (_IShellFolder2_ (This
), 0,
1063 SHCONTF_FOLDERS
| SHCONTF_NONFOLDERS
| SHCONTF_INCLUDEHIDDEN
, &penum
);
1070 IEnumIDList_Reset (penum
);
1071 while (S_OK
== IEnumIDList_Next (penum
, 1, &pidl
, &dwFetched
) &&
1073 _ILSimpleGetText (pidl
, szText
, MAX_PATH
);
1074 if (0 == strcasecmp (szText
, lpName
)) {
1075 sprintf (lpName
, "%s %d", szNewFolder
, i
++);
1084 IEnumIDList_Release (penum
);
1089 /****************************************************************************
1090 * ISFHelper_fnAddFolder
1092 * adds a new folder.
1095 static HRESULT WINAPI
1096 ISFHelper_fnAddFolder (ISFHelper
* iface
, HWND hwnd
, LPCSTR lpName
,
1097 LPITEMIDLIST
* ppidlOut
)
1099 _ICOM_THIS_From_ISFHelper (IGenericSFImpl
, iface
)
1100 char lpstrNewDir
[MAX_PATH
];
1102 HRESULT hres
= E_FAIL
;
1104 TRACE ("(%p)(%s %p)\n", This
, lpName
, ppidlOut
);
1106 strcpy (lpstrNewDir
, This
->sPathTarget
);
1107 PathAppendA(lpstrNewDir
, lpName
);
1109 bRes
= CreateDirectoryA (lpstrNewDir
, NULL
);
1111 SHChangeNotify (SHCNE_MKDIR
, SHCNF_PATHA
, lpstrNewDir
, NULL
);
1116 hres
= _ILCreateFromPathA(lpstrNewDir
, ppidlOut
);
1118 char lpstrText
[128 + MAX_PATH
];
1119 char lpstrTempText
[128];
1120 char lpstrCaption
[256];
1122 /* Cannot Create folder because of permissions */
1123 LoadStringA (shell32_hInstance
, IDS_CREATEFOLDER_DENIED
, lpstrTempText
,
1124 sizeof (lpstrTempText
));
1125 LoadStringA (shell32_hInstance
, IDS_CREATEFOLDER_CAPTION
, lpstrCaption
,
1126 sizeof (lpstrCaption
));
1127 sprintf (lpstrText
, lpstrTempText
, lpstrNewDir
);
1128 MessageBoxA (hwnd
, lpstrText
, lpstrCaption
, MB_OK
| MB_ICONEXCLAMATION
);
1134 /****************************************************************************
1135 * ISFHelper_fnDeleteItems
1137 * deletes items in folder
1139 static HRESULT WINAPI
1140 ISFHelper_fnDeleteItems (ISFHelper
* iface
, UINT cidl
, LPCITEMIDLIST
* apidl
)
1142 _ICOM_THIS_From_ISFHelper (IGenericSFImpl
, iface
)
1144 char szPath
[MAX_PATH
];
1145 BOOL bConfirm
= TRUE
;
1147 TRACE ("(%p)(%u %p)\n", This
, cidl
, apidl
);
1149 /* deleting multiple items so give a slightly different warning */
1153 snprintf (tmp
, sizeof (tmp
), "%d", cidl
);
1154 if (!SHELL_ConfirmDialog(ASK_DELETE_MULTIPLE_ITEM
, tmp
))
1159 for (i
= 0; i
< cidl
; i
++) {
1160 strcpy (szPath
, This
->sPathTarget
);
1161 PathAddBackslashA (szPath
);
1162 _ILSimpleGetText (apidl
[i
], szPath
+ strlen (szPath
), MAX_PATH
);
1164 if (_ILIsFolder (apidl
[i
])) {
1167 TRACE ("delete %s\n", szPath
);
1168 if (!SHELL_DeleteDirectoryA (szPath
, bConfirm
)) {
1169 TRACE ("delete %s failed, bConfirm=%d\n", szPath
, bConfirm
);
1172 pidl
= ILCombine (This
->pidlRoot
, apidl
[i
]);
1173 SHChangeNotify (SHCNE_RMDIR
, SHCNF_IDLIST
, pidl
, NULL
);
1175 } else if (_ILIsValue (apidl
[i
])) {
1178 TRACE ("delete %s\n", szPath
);
1179 if (!SHELL_DeleteFileA (szPath
, bConfirm
)) {
1180 TRACE ("delete %s failed, bConfirm=%d\n", szPath
, bConfirm
);
1183 pidl
= ILCombine (This
->pidlRoot
, apidl
[i
]);
1184 SHChangeNotify (SHCNE_DELETE
, SHCNF_IDLIST
, pidl
, NULL
);
1192 /****************************************************************************
1193 * ISFHelper_fnCopyItems
1195 * copies items to this folder
1197 static HRESULT WINAPI
1198 ISFHelper_fnCopyItems (ISFHelper
* iface
, IShellFolder
* pSFFrom
, UINT cidl
,
1199 LPCITEMIDLIST
* apidl
)
1202 IPersistFolder2
*ppf2
= NULL
;
1203 char szSrcPath
[MAX_PATH
],
1204 szDstPath
[MAX_PATH
];
1206 _ICOM_THIS_From_ISFHelper (IGenericSFImpl
, iface
);
1208 TRACE ("(%p)->(%p,%u,%p)\n", This
, pSFFrom
, cidl
, apidl
);
1210 IShellFolder_QueryInterface (pSFFrom
, &IID_IPersistFolder2
,
1215 if (SUCCEEDED (IPersistFolder2_GetCurFolder (ppf2
, &pidl
))) {
1216 for (i
= 0; i
< cidl
; i
++) {
1217 SHGetPathFromIDListA (pidl
, szSrcPath
);
1218 PathAddBackslashA (szSrcPath
);
1219 _ILSimpleGetText (apidl
[i
], szSrcPath
+ strlen (szSrcPath
),
1222 strcpy (szDstPath
, This
->sPathTarget
);
1223 PathAddBackslashA (szDstPath
);
1224 _ILSimpleGetText (apidl
[i
], szDstPath
+ strlen (szDstPath
),
1226 MESSAGE ("would copy %s to %s\n", szSrcPath
, szDstPath
);
1230 IPersistFolder2_Release (ppf2
);
1235 static const ISFHelperVtbl shvt
=
1237 ISFHelper_fnQueryInterface
,
1239 ISFHelper_fnRelease
,
1240 ISFHelper_fnGetUniqueName
,
1241 ISFHelper_fnAddFolder
,
1242 ISFHelper_fnDeleteItems
,
1243 ISFHelper_fnCopyItems
1246 /************************************************************************
1247 * IFSFldr_PersistFolder3_QueryInterface
1250 static HRESULT WINAPI
1251 IFSFldr_PersistFolder3_QueryInterface (IPersistFolder3
* iface
, REFIID iid
,
1254 _ICOM_THIS_From_IPersistFolder3 (IGenericSFImpl
, iface
);
1256 TRACE ("(%p)\n", This
);
1258 return IUnknown_QueryInterface (This
->pUnkOuter
, iid
, ppvObj
);
1261 /************************************************************************
1262 * IFSFldr_PersistFolder3_AddRef
1266 IFSFldr_PersistFolder3_AddRef (IPersistFolder3
* iface
)
1268 _ICOM_THIS_From_IPersistFolder3 (IGenericSFImpl
, iface
);
1270 TRACE ("(%p)->(count=%lu)\n", This
, This
->ref
);
1272 return IUnknown_AddRef (This
->pUnkOuter
);
1275 /************************************************************************
1276 * IFSFldr_PersistFolder3_Release
1280 IFSFldr_PersistFolder3_Release (IPersistFolder3
* iface
)
1282 _ICOM_THIS_From_IPersistFolder3 (IGenericSFImpl
, iface
);
1284 TRACE ("(%p)->(count=%lu)\n", This
, This
->ref
);
1286 return IUnknown_Release (This
->pUnkOuter
);
1289 /************************************************************************
1290 * IFSFldr_PersistFolder3_GetClassID
1292 static HRESULT WINAPI
1293 IFSFldr_PersistFolder3_GetClassID (IPersistFolder3
* iface
, CLSID
* lpClassId
)
1295 _ICOM_THIS_From_IPersistFolder3 (IGenericSFImpl
, iface
);
1297 TRACE ("(%p)\n", This
);
1301 *lpClassId
= *This
->pclsid
;
1306 /************************************************************************
1307 * IFSFldr_PersistFolder3_Initialize
1310 * sPathTarget is not set. Don't know how to handle in a non rooted environment.
1312 static HRESULT WINAPI
1313 IFSFldr_PersistFolder3_Initialize (IPersistFolder3
* iface
, LPCITEMIDLIST pidl
)
1315 char sTemp
[MAX_PATH
];
1317 _ICOM_THIS_From_IPersistFolder3 (IGenericSFImpl
, iface
);
1319 TRACE ("(%p)->(%p)\n", This
, pidl
);
1322 SHFree (This
->pidlRoot
); /* free the old pidl */
1323 This
->pidlRoot
= ILClone (pidl
); /* set my pidl */
1325 if (This
->sPathTarget
)
1326 SHFree (This
->sPathTarget
);
1329 if (SHGetPathFromIDListA (pidl
, sTemp
)) {
1330 This
->sPathTarget
= SHAlloc (strlen (sTemp
) + 1);
1331 strcpy (This
->sPathTarget
, sTemp
);
1334 TRACE ("--(%p)->(%s)\n", This
, This
->sPathTarget
);
1338 /**************************************************************************
1339 * IFSFldr_PersistFolder3_GetCurFolder
1341 static HRESULT WINAPI
1342 IFSFldr_PersistFolder3_fnGetCurFolder (IPersistFolder3
* iface
,
1343 LPITEMIDLIST
* pidl
)
1345 _ICOM_THIS_From_IPersistFolder3 (IGenericSFImpl
, iface
);
1347 TRACE ("(%p)->(%p)\n", This
, pidl
);
1349 if (!pidl
) return E_POINTER
;
1350 *pidl
= ILClone (This
->pidlRoot
);
1354 /**************************************************************************
1355 * IFSFldr_PersistFolder3_InitializeEx
1357 * FIXME: error handling
1359 static HRESULT WINAPI
1360 IFSFldr_PersistFolder3_InitializeEx (IPersistFolder3
* iface
,
1361 IBindCtx
* pbc
, LPCITEMIDLIST pidlRoot
,
1362 const PERSIST_FOLDER_TARGET_INFO
* ppfti
)
1364 char sTemp
[MAX_PATH
];
1366 _ICOM_THIS_From_IPersistFolder3 (IGenericSFImpl
, iface
);
1368 TRACE ("(%p)->(%p,%p,%p)\n", This
, pbc
, pidlRoot
, ppfti
);
1370 TRACE ("--%p %s %s 0x%08lx 0x%08x\n",
1371 ppfti
->pidlTargetFolder
, debugstr_w (ppfti
->szTargetParsingName
),
1372 debugstr_w (ppfti
->szNetworkProvider
), ppfti
->dwAttributes
,
1376 if (ppfti
&& ppfti
->pidlTargetFolder
)
1377 pdump (ppfti
->pidlTargetFolder
);
1380 __SHFreeAndNil (&This
->pidlRoot
); /* free the old */
1381 if (This
->sPathTarget
)
1382 __SHFreeAndNil (&This
->sPathTarget
);
1385 * Root path and pidl
1387 This
->pidlRoot
= ILClone (pidlRoot
);
1390 * the target folder is spezified in csidl OR pidlTargetFolder OR
1391 * szTargetParsingName
1394 if (ppfti
->csidl
!= -1) {
1395 if (SHGetSpecialFolderPathA (0, sTemp
, ppfti
->csidl
,
1396 ppfti
->csidl
& CSIDL_FLAG_CREATE
)) {
1397 __SHCloneStrA (&This
->sPathTarget
, sTemp
);
1399 } else if (ppfti
->szTargetParsingName
[0]) {
1400 __SHCloneStrWtoA (&This
->sPathTarget
, ppfti
->szTargetParsingName
);
1401 } else if (ppfti
->pidlTargetFolder
) {
1402 if (SHGetPathFromIDListA (ppfti
->pidlTargetFolder
, sTemp
)) {
1403 __SHCloneStrA (&This
->sPathTarget
, sTemp
);
1408 TRACE ("--(%p)->(target=%s)\n", This
, debugstr_a (This
->sPathTarget
));
1409 pdump (This
->pidlRoot
);
1410 return (This
->sPathTarget
) ? S_OK
: E_FAIL
;
1413 static HRESULT WINAPI
1414 IFSFldr_PersistFolder3_GetFolderTargetInfo (IPersistFolder3
* iface
,
1415 PERSIST_FOLDER_TARGET_INFO
* ppfti
)
1417 _ICOM_THIS_From_IPersistFolder3 (IGenericSFImpl
, iface
);
1418 FIXME ("(%p)->(%p)\n", This
, ppfti
);
1419 ZeroMemory (ppfti
, sizeof (ppfti
));
1423 static const IPersistFolder3Vtbl vt_FSFldr_PersistFolder3
=
1425 IFSFldr_PersistFolder3_QueryInterface
,
1426 IFSFldr_PersistFolder3_AddRef
,
1427 IFSFldr_PersistFolder3_Release
,
1428 IFSFldr_PersistFolder3_GetClassID
,
1429 IFSFldr_PersistFolder3_Initialize
,
1430 IFSFldr_PersistFolder3_fnGetCurFolder
,
1431 IFSFldr_PersistFolder3_InitializeEx
,
1432 IFSFldr_PersistFolder3_GetFolderTargetInfo
1435 /****************************************************************************
1436 * ISFDropTarget implementation
1439 ISFDropTarget_QueryDrop (IDropTarget
* iface
, DWORD dwKeyState
,
1442 DWORD dwEffect
= *pdwEffect
;
1444 _ICOM_THIS_From_IDropTarget (IGenericSFImpl
, iface
);
1446 *pdwEffect
= DROPEFFECT_NONE
;
1448 if (This
->fAcceptFmt
) { /* Does our interpretation of the keystate ... */
1449 *pdwEffect
= KeyStateToDropEffect (dwKeyState
);
1451 /* ... matches the desired effect ? */
1452 if (dwEffect
& *pdwEffect
) {
1459 static HRESULT WINAPI
1460 ISFDropTarget_QueryInterface (IDropTarget
* iface
, REFIID riid
, LPVOID
* ppvObj
)
1462 _ICOM_THIS_From_IDropTarget (IGenericSFImpl
, iface
);
1464 TRACE ("(%p)\n", This
);
1466 return IUnknown_QueryInterface (This
->pUnkOuter
, riid
, ppvObj
);
1469 static ULONG WINAPI
ISFDropTarget_AddRef (IDropTarget
* iface
)
1471 _ICOM_THIS_From_IDropTarget (IGenericSFImpl
, iface
);
1473 TRACE ("(%p)\n", This
);
1475 return IUnknown_AddRef (This
->pUnkOuter
);
1478 static ULONG WINAPI
ISFDropTarget_Release (IDropTarget
* iface
)
1480 _ICOM_THIS_From_IDropTarget (IGenericSFImpl
, iface
);
1482 TRACE ("(%p)\n", This
);
1484 return IUnknown_Release (This
->pUnkOuter
);
1487 static HRESULT WINAPI
1488 ISFDropTarget_DragEnter (IDropTarget
* iface
, IDataObject
* pDataObject
,
1489 DWORD dwKeyState
, POINTL pt
, DWORD
* pdwEffect
)
1493 _ICOM_THIS_From_IDropTarget (IGenericSFImpl
, iface
);
1495 TRACE ("(%p)->(DataObject=%p)\n", This
, pDataObject
);
1497 InitFormatEtc (fmt
, This
->cfShellIDList
, TYMED_HGLOBAL
);
1499 This
->fAcceptFmt
= (S_OK
== IDataObject_QueryGetData (pDataObject
, &fmt
)) ?
1502 ISFDropTarget_QueryDrop (iface
, dwKeyState
, pdwEffect
);
1507 static HRESULT WINAPI
1508 ISFDropTarget_DragOver (IDropTarget
* iface
, DWORD dwKeyState
, POINTL pt
,
1511 _ICOM_THIS_From_IDropTarget (IGenericSFImpl
, iface
);
1513 TRACE ("(%p)\n", This
);
1516 return E_INVALIDARG
;
1518 ISFDropTarget_QueryDrop (iface
, dwKeyState
, pdwEffect
);
1523 static HRESULT WINAPI
ISFDropTarget_DragLeave (IDropTarget
* iface
)
1525 _ICOM_THIS_From_IDropTarget (IGenericSFImpl
, iface
);
1527 TRACE ("(%p)\n", This
);
1529 This
->fAcceptFmt
= FALSE
;
1534 static HRESULT WINAPI
1535 ISFDropTarget_Drop (IDropTarget
* iface
, IDataObject
* pDataObject
,
1536 DWORD dwKeyState
, POINTL pt
, DWORD
* pdwEffect
)
1538 _ICOM_THIS_From_IDropTarget (IGenericSFImpl
, iface
);
1540 FIXME ("(%p) object dropped\n", This
);
1545 static const IDropTargetVtbl dtvt
= {
1546 ISFDropTarget_QueryInterface
,
1547 ISFDropTarget_AddRef
,
1548 ISFDropTarget_Release
,
1549 ISFDropTarget_DragEnter
,
1550 ISFDropTarget_DragOver
,
1551 ISFDropTarget_DragLeave
,