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 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) (IPersist*)&(This->lpvtblPersistFolder3)
117 #define _IPersistFolder_(This) (IPersistFolder*)&(This->lpvtblPersistFolder3)
118 #define _IPersistFolder2_(This) (IPersistFolder2*)&(This->lpvtblPersistFolder3)
119 #define _IPersistFolder3_(This) (IPersistFolder3*)&(This->lpvtblPersistFolder3)
120 #define _IDropTarget_(This) (IDropTarget*)&(This->lpvtblDropTarget)
121 #define _ISFHelper_(This) (ISFHelper*)&(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
= RegisterClipboardFormatA (CFSTR_SHELLIDLIST
);
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=%lu)\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=%lu)\n", This
, refCount
+ 1);
195 TRACE ("-- destroying IShellFolder(%p)\n", This
);
198 SHFree (This
->pidlRoot
);
199 if (This
->sPathTarget
)
200 SHFree (This
->sPathTarget
);
201 LocalFree ((HLOCAL
) This
);
206 static const IUnknownVtbl unkvt
=
208 IUnknown_fnQueryInterface
,
213 static shvheader GenericSFHeader
[] = {
214 {IDS_SHV_COLUMN1
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 15},
215 {IDS_SHV_COLUMN2
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 10},
216 {IDS_SHV_COLUMN3
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 10},
217 {IDS_SHV_COLUMN4
, SHCOLSTATE_TYPE_DATE
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 12},
218 {IDS_SHV_COLUMN5
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 5}
221 #define GENERICSHELLVIEWCOLUMNS 5
223 /**************************************************************************
224 * IFSFolder_Constructor
227 * creating undocumented ShellFS_Folder as part of an aggregation
228 * {F3364BA0-65B9-11CE-A9BA-00AA004AE837}
232 IFSFolder_Constructor (IUnknown
* pUnkOuter
, REFIID riid
, LPVOID
* ppv
)
236 TRACE ("unkOut=%p %s\n", pUnkOuter
, shdebugstr_guid (riid
));
238 if (pUnkOuter
&& !IsEqualIID (riid
, &IID_IUnknown
))
239 return CLASS_E_NOAGGREGATION
;
240 sf
= (IGenericSFImpl
*) LocalAlloc (LMEM_ZEROINIT
, sizeof (IGenericSFImpl
));
242 return E_OUTOFMEMORY
;
246 sf
->lpvtblShellFolder
= &sfvt
;
247 sf
->lpvtblPersistFolder3
= &vt_FSFldr_PersistFolder3
;
248 sf
->lpvtblDropTarget
= &dtvt
;
249 sf
->lpvtblSFHelper
= &shvt
;
250 sf
->pclsid
= (CLSID
*) & CLSID_ShellFSFolder
;
251 sf
->pUnkOuter
= pUnkOuter
? pUnkOuter
: _IUnknown_ (sf
);
253 if (!SUCCEEDED (IUnknown_QueryInterface (_IUnknown_ (sf
), riid
, ppv
))) {
254 IUnknown_Release (_IUnknown_ (sf
));
255 return E_NOINTERFACE
;
258 TRACE ("--%p\n", *ppv
);
262 /**************************************************************************
263 * IShellFolder_fnQueryInterface
266 * REFIID riid [in ] Requested InterfaceID
267 * LPVOID* ppvObject [out] Interface* to hold the result
269 static HRESULT WINAPI
270 IShellFolder_fnQueryInterface (IShellFolder2
* iface
, REFIID riid
,
273 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
275 TRACE ("(%p)->(%s,%p)\n", This
, shdebugstr_guid (riid
), ppvObj
);
277 return IUnknown_QueryInterface (This
->pUnkOuter
, riid
, ppvObj
);
280 /**************************************************************************
281 * IShellFolder_AddRef
284 static ULONG WINAPI
IShellFolder_fnAddRef (IShellFolder2
* iface
)
286 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
288 TRACE ("(%p)->(count=%lu)\n", This
, This
->ref
);
290 return IUnknown_AddRef (This
->pUnkOuter
);
293 /**************************************************************************
294 * IShellFolder_fnRelease
296 static ULONG WINAPI
IShellFolder_fnRelease (IShellFolder2
* iface
)
298 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
300 TRACE ("(%p)->(count=%lu)\n", This
, This
->ref
);
302 return IUnknown_Release (This
->pUnkOuter
);
305 /**************************************************************************
306 * SHELL32_CreatePidlFromBindCtx [internal]
308 * If the caller bound File System Bind Data, assume it is the
309 * find data for the path.
310 * This allows binding of paths that don't exist.
312 LPITEMIDLIST
SHELL32_CreatePidlFromBindCtx(IBindCtx
*pbc
, LPCWSTR path
)
314 static const WCHAR szfsbc
[] = {
315 'F','i','l','e',' ','S','y','s','t','e','m',' ',
316 'B','i','n','d',' ','D','a','t','a',0 };
317 IFileSystemBindData
*fsbd
= NULL
;
318 LPITEMIDLIST pidl
= NULL
;
319 IUnknown
*param
= NULL
;
320 WIN32_FIND_DATAW wfd
;
323 TRACE("%p %s\n", pbc
, debugstr_w(path
));
328 /* see if the caller bound File System Bind Data */
329 r
= IBindCtx_GetObjectParam( pbc
, (LPOLESTR
) szfsbc
, ¶m
);
333 r
= IUnknown_QueryInterface( param
, &IID_IFileSystemBindData
,
337 r
= IFileSystemBindData_GetFindData( fsbd
, &wfd
);
340 lstrcpynW( &wfd
.cFileName
[0], path
, MAX_PATH
);
341 pidl
= _ILCreateFromFindDataW( &wfd
);
343 IFileSystemBindData_Release( fsbd
);
349 /**************************************************************************
350 * IShellFolder_ParseDisplayName {SHELL32}
352 * Parse a display name.
355 * hwndOwner [in] Parent window for any message's
356 * pbc [in] optional FileSystemBindData context
357 * lpszDisplayName [in] Unicode displayname.
358 * pchEaten [out] (unicode) characters processed
359 * ppidl [out] complex pidl to item
360 * pdwAttributes [out] items attributes
363 * Every folder tries to parse only its own (the leftmost) pidl and creates a
364 * subfolder to evaluate the remaining parts.
365 * Now we can parse into namespaces implemented by shell extensions
367 * Behaviour on win98: lpszDisplayName=NULL -> crash
368 * lpszDisplayName="" -> returns mycoputer-pidl
371 * pdwAttributes is not set
372 * pchEaten is not set like in windows
374 static HRESULT WINAPI
375 IShellFolder_fnParseDisplayName (IShellFolder2
* iface
,
378 LPOLESTR lpszDisplayName
,
379 DWORD
* pchEaten
, LPITEMIDLIST
* ppidl
,
380 DWORD
* pdwAttributes
)
382 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
384 HRESULT hr
= E_INVALIDARG
;
385 LPCWSTR szNext
= NULL
;
386 WCHAR szElement
[MAX_PATH
];
387 WCHAR szPath
[MAX_PATH
];
388 LPITEMIDLIST pidlTemp
= NULL
;
391 TRACE ("(%p)->(HWND=%p,%p,%p=%s,%p,pidl=%p,%p)\n",
392 This
, hwndOwner
, pbc
, lpszDisplayName
, debugstr_w (lpszDisplayName
),
393 pchEaten
, ppidl
, pdwAttributes
);
395 if (!lpszDisplayName
|| !ppidl
)
399 *pchEaten
= 0; /* strange but like the original */
401 pidlTemp
= SHELL32_CreatePidlFromBindCtx(pbc
, lpszDisplayName
);
402 if (!pidlTemp
&& *lpszDisplayName
)
404 /* get the next element */
405 szNext
= GetNextElementW (lpszDisplayName
, szElement
, MAX_PATH
);
407 /* build the full pathname to the element */
408 lstrcpynW(szPath
, This
->sPathTarget
, MAX_PATH
- 1);
409 PathAddBackslashW(szPath
);
410 len
= lstrlenW(szPath
);
411 lstrcpynW(szPath
+ len
, szElement
, MAX_PATH
- len
);
414 hr
= _ILCreateFromPathW(szPath
, &pidlTemp
);
417 if (szNext
&& *szNext
) {
418 /* try to analyse the next element */
419 hr
= SHELL32_ParseNextElement (iface
, hwndOwner
, pbc
,
420 &pidlTemp
, (LPOLESTR
) szNext
, pchEaten
, pdwAttributes
);
422 /* it's the last element */
423 if (pdwAttributes
&& *pdwAttributes
) {
424 hr
= SHELL32_GetItemAttributes (_IShellFolder_ (This
),
425 pidlTemp
, pdwAttributes
);
436 TRACE ("(%p)->(-- pidl=%p ret=0x%08lx)\n", This
, ppidl
? *ppidl
: 0, hr
);
441 /**************************************************************************
442 * IShellFolder_fnEnumObjects
444 * HWND hwndOwner, //[in ] Parent Window
445 * DWORD grfFlags, //[in ] SHCONTF enumeration mask
446 * LPENUMIDLIST* ppenumIDList //[out] IEnumIDList interface
448 static HRESULT WINAPI
449 IShellFolder_fnEnumObjects (IShellFolder2
* iface
, HWND hwndOwner
,
450 DWORD dwFlags
, LPENUMIDLIST
* ppEnumIDList
)
452 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
454 TRACE ("(%p)->(HWND=%p flags=0x%08lx pplist=%p)\n", This
, hwndOwner
,
455 dwFlags
, ppEnumIDList
);
457 *ppEnumIDList
= IEnumIDList_Constructor();
459 CreateFolderEnumList(*ppEnumIDList
, This
->sPathTarget
, dwFlags
);
461 TRACE ("-- (%p)->(new ID List: %p)\n", This
, *ppEnumIDList
);
463 return *ppEnumIDList
? S_OK
: E_OUTOFMEMORY
;
466 /**************************************************************************
467 * IShellFolder_fnBindToObject
469 * LPCITEMIDLIST pidl, //[in ] relative pidl to open
470 * LPBC pbc, //[in ] optional FileSystemBindData context
471 * REFIID riid, //[in ] Initial Interface
472 * LPVOID* ppvObject //[out] Interface*
474 static HRESULT WINAPI
475 IShellFolder_fnBindToObject (IShellFolder2
* iface
, LPCITEMIDLIST pidl
,
476 LPBC pbc
, REFIID riid
, LPVOID
* ppvOut
)
478 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
480 TRACE ("(%p)->(pidl=%p,%p,%s,%p)\n", This
, pidl
, pbc
,
481 shdebugstr_guid (riid
), ppvOut
);
483 return SHELL32_BindToChild (This
->pidlRoot
, This
->sPathTarget
, pidl
, riid
,
487 /**************************************************************************
488 * IShellFolder_fnBindToStorage
490 * LPCITEMIDLIST pidl, //[in ] complex pidl to store
491 * LPBC pbc, //[in ] reserved
492 * REFIID riid, //[in ] Initial storage interface
493 * LPVOID* ppvObject //[out] Interface* returned
495 static HRESULT WINAPI
496 IShellFolder_fnBindToStorage (IShellFolder2
* iface
, LPCITEMIDLIST pidl
,
497 LPBC pbcReserved
, REFIID riid
, LPVOID
* ppvOut
)
499 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
501 FIXME ("(%p)->(pidl=%p,%p,%s,%p) stub\n", This
, pidl
, pbcReserved
,
502 shdebugstr_guid (riid
), ppvOut
);
508 /**************************************************************************
509 * IShellFolder_fnCompareIDs
512 static HRESULT WINAPI
513 IShellFolder_fnCompareIDs (IShellFolder2
* iface
, LPARAM lParam
,
514 LPCITEMIDLIST pidl1
, LPCITEMIDLIST pidl2
)
516 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
520 TRACE ("(%p)->(0x%08lx,pidl1=%p,pidl2=%p)\n", This
, lParam
, pidl1
, pidl2
);
521 nReturn
= SHELL32_CompareIDs (_IShellFolder_ (This
), lParam
, pidl1
, pidl2
);
522 TRACE ("-- %i\n", nReturn
);
526 /**************************************************************************
527 * IShellFolder_fnCreateViewObject
529 static HRESULT WINAPI
530 IShellFolder_fnCreateViewObject (IShellFolder2
* iface
, HWND hwndOwner
,
531 REFIID riid
, LPVOID
* ppvOut
)
533 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
535 LPSHELLVIEW pShellView
;
536 HRESULT hr
= E_INVALIDARG
;
538 TRACE ("(%p)->(hwnd=%p,%s,%p)\n", This
, hwndOwner
, shdebugstr_guid (riid
),
544 if (IsEqualIID (riid
, &IID_IDropTarget
)) {
545 hr
= IShellFolder_QueryInterface (iface
, &IID_IDropTarget
, ppvOut
);
546 } else if (IsEqualIID (riid
, &IID_IContextMenu
)) {
547 FIXME ("IContextMenu not implemented\n");
549 } else if (IsEqualIID (riid
, &IID_IShellView
)) {
550 pShellView
= IShellView_Constructor ((IShellFolder
*) iface
);
552 hr
= IShellView_QueryInterface (pShellView
, riid
, ppvOut
);
553 IShellView_Release (pShellView
);
557 TRACE ("-- (%p)->(interface=%p)\n", This
, ppvOut
);
561 /**************************************************************************
562 * IShellFolder_fnGetAttributesOf
565 * UINT cidl, //[in ] num elements in pidl array
566 * LPCITEMIDLIST* apidl, //[in ] simple pidl array
567 * ULONG* rgfInOut) //[out] result array
570 static HRESULT WINAPI
571 IShellFolder_fnGetAttributesOf (IShellFolder2
* iface
, UINT cidl
,
572 LPCITEMIDLIST
* apidl
, DWORD
* rgfInOut
)
574 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
578 TRACE ("(%p)->(cidl=%d apidl=%p mask=%p (0x%08lx))\n", This
, cidl
, apidl
,
579 rgfInOut
, rgfInOut
? *rgfInOut
: 0);
590 IShellFolder
*psfParent
= NULL
;
591 LPCITEMIDLIST rpidl
= NULL
;
593 hr
= SHBindToParent(This
->pidlRoot
, &IID_IShellFolder
, (LPVOID
*)&psfParent
, (LPCITEMIDLIST
*)&rpidl
);
595 SHELL32_GetItemAttributes (psfParent
, rpidl
, rgfInOut
);
596 IShellFolder_Release(psfParent
);
600 while (cidl
> 0 && *apidl
) {
602 SHELL32_GetItemAttributes (_IShellFolder_ (This
), *apidl
, rgfInOut
);
607 /* make sure SFGAO_VALIDATE is cleared, some apps depend on that */
608 *rgfInOut
&= ~SFGAO_VALIDATE
;
610 TRACE ("-- result=0x%08lx\n", *rgfInOut
);
615 /**************************************************************************
616 * IShellFolder_fnGetUIObjectOf
619 * HWND hwndOwner, //[in ] Parent window for any output
620 * UINT cidl, //[in ] array size
621 * LPCITEMIDLIST* apidl, //[in ] simple pidl array
622 * REFIID riid, //[in ] Requested Interface
623 * UINT* prgfInOut, //[ ] reserved
624 * LPVOID* ppvObject) //[out] Resulting Interface
627 * This function gets asked to return "view objects" for one or more (multiple
629 * The viewobject typically is an COM object with one of the following
631 * IExtractIcon,IDataObject,IContextMenu
632 * In order to support icon positions in the default Listview your DataObject
633 * must implement the SetData method (in addition to GetData :) - the shell
634 * passes a barely documented "Icon positions" structure to SetData when the
635 * drag starts, and GetData's it if the drop is in another explorer window that
636 * needs the positions.
638 static HRESULT WINAPI
639 IShellFolder_fnGetUIObjectOf (IShellFolder2
* iface
,
641 UINT cidl
, LPCITEMIDLIST
* apidl
, REFIID riid
,
642 UINT
* prgfInOut
, LPVOID
* ppvOut
)
644 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
647 IUnknown
*pObj
= NULL
;
648 HRESULT hr
= E_INVALIDARG
;
650 TRACE ("(%p)->(%p,%u,apidl=%p,%s,%p,%p)\n",
651 This
, hwndOwner
, cidl
, apidl
, shdebugstr_guid (riid
), prgfInOut
, ppvOut
);
656 if (IsEqualIID (riid
, &IID_IContextMenu
) && (cidl
>= 1)) {
657 pObj
= (LPUNKNOWN
) ISvItemCm_Constructor ((IShellFolder
*) iface
,
658 This
->pidlRoot
, apidl
, cidl
);
660 } else if (IsEqualIID (riid
, &IID_IDataObject
) && (cidl
>= 1)) {
661 pObj
= (LPUNKNOWN
) IDataObject_Constructor (hwndOwner
,
662 This
->pidlRoot
, apidl
, cidl
);
664 } else if (IsEqualIID (riid
, &IID_IExtractIconA
) && (cidl
== 1)) {
665 pidl
= ILCombine (This
->pidlRoot
, apidl
[0]);
666 pObj
= (LPUNKNOWN
) IExtractIconA_Constructor (pidl
);
669 } else if (IsEqualIID (riid
, &IID_IExtractIconW
) && (cidl
== 1)) {
670 pidl
= ILCombine (This
->pidlRoot
, apidl
[0]);
671 pObj
= (LPUNKNOWN
) IExtractIconW_Constructor (pidl
);
674 } else if (IsEqualIID (riid
, &IID_IDropTarget
) && (cidl
>= 1)) {
675 hr
= IShellFolder_QueryInterface (iface
, &IID_IDropTarget
,
677 } else if ((IsEqualIID(riid
,&IID_IShellLinkW
) ||
678 IsEqualIID(riid
,&IID_IShellLinkA
)) && (cidl
== 1)) {
679 pidl
= ILCombine (This
->pidlRoot
, apidl
[0]);
680 hr
= IShellLink_ConstructFromFile(NULL
, riid
, pidl
, (LPVOID
*)&pObj
);
686 if (SUCCEEDED(hr
) && !pObj
)
691 TRACE ("(%p)->hr=0x%08lx\n", This
, hr
);
695 static const WCHAR AdvancedW
[] = { 'S','O','F','T','W','A','R','E',
696 '\\','M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
697 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\','E','x','p','l',
698 'o','r','e','r','\\','A','d','v','a','n','c','e','d',0 };
699 static const WCHAR HideFileExtW
[] = { 'H','i','d','e','F','i','l','e','E','x',
701 static const WCHAR NeverShowExtW
[] = { 'N','e','v','e','r','S','h','o','w','E',
704 /******************************************************************************
705 * SHELL_FS_HideExtension [Internal]
707 * Query the registry if the filename extension of a given path should be
711 * szPath [I] Relative or absolute path of a file
714 * TRUE, if the filename's extension should be hidden
717 BOOL
SHELL_FS_HideExtension(LPWSTR szPath
)
721 DWORD dwDataSize
= sizeof (DWORD
);
722 BOOL doHide
= FALSE
; /* The default value is FALSE (win98 at least) */
724 if (!RegCreateKeyExW(HKEY_CURRENT_USER
, AdvancedW
, 0, 0, 0, KEY_ALL_ACCESS
, 0, &hKey
, 0)) {
725 if (!RegQueryValueExW(hKey
, HideFileExtW
, 0, 0, (LPBYTE
) &dwData
, &dwDataSize
))
731 LPWSTR ext
= PathFindExtensionW(szPath
);
734 WCHAR classname
[MAX_PATH
];
735 LONG classlen
= sizeof(classname
);
737 if (!RegQueryValueW(HKEY_CLASSES_ROOT
, ext
, classname
, &classlen
))
738 if (!RegOpenKeyW(HKEY_CLASSES_ROOT
, classname
, &hKey
)) {
739 if (!RegQueryValueExW(hKey
, NeverShowExtW
, 0, NULL
, NULL
, NULL
))
748 void SHELL_FS_ProcessDisplayFilename(LPWSTR szPath
, DWORD dwFlags
)
750 /*FIXME: MSDN also mentions SHGDN_FOREDITING which is not yet handled. */
751 if (!(dwFlags
& SHGDN_FORPARSING
) &&
752 ((dwFlags
& SHGDN_INFOLDER
) || (dwFlags
== SHGDN_NORMAL
))) {
753 if (SHELL_FS_HideExtension(szPath
) && szPath
[0] != '.')
754 PathRemoveExtensionW(szPath
);
758 /**************************************************************************
759 * IShellFolder_fnGetDisplayNameOf
760 * Retrieves the display name for the specified file object or subfolder
763 * LPCITEMIDLIST pidl, //[in ] complex pidl to item
764 * DWORD dwFlags, //[in ] SHGNO formatting flags
765 * LPSTRRET lpName) //[out] Returned display name
768 * if the name is in the pidl the ret value should be a STRRET_OFFSET
771 static HRESULT WINAPI
772 IShellFolder_fnGetDisplayNameOf (IShellFolder2
* iface
, LPCITEMIDLIST pidl
,
773 DWORD dwFlags
, LPSTRRET strRet
)
775 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
776 WCHAR wszPath
[MAX_PATH
+1];
781 TRACE ("(%p)->(pidl=%p,0x%08lx,%p)\n", This
, pidl
, dwFlags
, strRet
);
784 if (!pidl
|| !strRet
)
787 if (_ILIsDesktop(pidl
)) { /* empty pidl */
788 if ((GET_SHGDN_FOR(dwFlags
) & SHGDN_FORPARSING
) &&
789 (GET_SHGDN_RELATION(dwFlags
) != SHGDN_INFOLDER
))
791 if (This
->sPathTarget
)
792 lstrcpynW(wszPath
, This
->sPathTarget
, MAX_PATH
);
794 /* pidl has to contain exactly one non null SHITEMID */
797 } else if (_ILIsPidlSimple(pidl
)) {
798 if ((GET_SHGDN_FOR(dwFlags
) & SHGDN_FORPARSING
) &&
799 (GET_SHGDN_RELATION(dwFlags
) != SHGDN_INFOLDER
) &&
802 lstrcpynW(wszPath
, This
->sPathTarget
, MAX_PATH
);
803 PathAddBackslashW(wszPath
);
804 len
= lstrlenW(wszPath
);
806 _ILSimpleGetTextW(pidl
, wszPath
+ len
, MAX_PATH
+ 1 - len
);
807 if (!_ILIsFolder(pidl
)) SHELL_FS_ProcessDisplayFilename(wszPath
, dwFlags
);
809 hr
= SHELL32_GetDisplayNameOfChild(iface
, pidl
, dwFlags
, wszPath
, MAX_PATH
);
813 strRet
->uType
= STRRET_CSTR
;
814 if (!WideCharToMultiByte(CP_ACP
, 0, wszPath
, -1, strRet
->u
.cStr
, MAX_PATH
,
816 strRet
->u
.cStr
[0] = '\0';
819 TRACE ("-- (%p)->(%s)\n", This
, strRet
->u
.cStr
);
823 /**************************************************************************
824 * IShellFolder_fnSetNameOf
825 * Changes the name of a file object or subfolder, possibly changing its item
826 * identifier in the process.
829 * HWND hwndOwner, //[in ] Owner window for output
830 * LPCITEMIDLIST pidl, //[in ] simple pidl of item to change
831 * LPCOLESTR lpszName, //[in ] the items new display name
832 * DWORD dwFlags, //[in ] SHGNO formatting flags
833 * LPITEMIDLIST* ppidlOut) //[out] simple pidl returned
835 static HRESULT WINAPI
IShellFolder_fnSetNameOf (IShellFolder2
* iface
,
840 LPITEMIDLIST
* pPidlOut
)
842 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
843 WCHAR szSrc
[MAX_PATH
+ 1], szDest
[MAX_PATH
+ 1];
845 BOOL bIsFolder
= _ILIsFolder (ILFindLastID (pidl
));
847 TRACE ("(%p)->(%p,pidl=%p,%s,%lu,%p)\n", This
, hwndOwner
, pidl
,
848 debugstr_w (lpName
), dwFlags
, pPidlOut
);
850 /* build source path */
851 lstrcpynW(szSrc
, This
->sPathTarget
, MAX_PATH
);
852 ptr
= PathAddBackslashW (szSrc
);
854 _ILSimpleGetTextW (pidl
, ptr
, MAX_PATH
+ 1 - (ptr
- szSrc
));
856 /* build destination path */
857 if (dwFlags
== SHGDN_NORMAL
|| dwFlags
& SHGDN_INFOLDER
) {
858 lstrcpynW(szDest
, This
->sPathTarget
, MAX_PATH
);
859 ptr
= PathAddBackslashW (szDest
);
861 lstrcpynW(ptr
, lpName
, MAX_PATH
+ 1 - (ptr
- szDest
));
863 lstrcpynW(szDest
, lpName
, MAX_PATH
);
865 if(!(dwFlags
& SHGDN_FORPARSING
) && SHELL_FS_HideExtension(szSrc
)) {
866 WCHAR
*ext
= PathFindExtensionW(szSrc
);
868 INT len
= strlenW(szDest
);
869 lstrcpynW(szDest
+ len
, ext
, MAX_PATH
- len
);
873 TRACE ("src=%s dest=%s\n", debugstr_w(szSrc
), debugstr_w(szDest
));
875 if (MoveFileW (szSrc
, szDest
)) {
879 hr
= _ILCreateFromPathW(szDest
, pPidlOut
);
881 SHChangeNotify (bIsFolder
? SHCNE_RENAMEFOLDER
: SHCNE_RENAMEITEM
,
882 SHCNF_PATHW
, szSrc
, szDest
);
890 static HRESULT WINAPI
IShellFolder_fnGetDefaultSearchGUID (IShellFolder2
*iface
,
893 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
894 FIXME ("(%p)\n", This
);
897 static HRESULT WINAPI
IShellFolder_fnEnumSearches (IShellFolder2
* iface
,
898 IEnumExtraSearch
** ppenum
)
900 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
901 FIXME ("(%p)\n", This
);
905 static HRESULT WINAPI
906 IShellFolder_fnGetDefaultColumn (IShellFolder2
* iface
, DWORD dwRes
,
907 ULONG
* pSort
, ULONG
* pDisplay
)
909 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
911 TRACE ("(%p)\n", This
);
921 static HRESULT WINAPI
922 IShellFolder_fnGetDefaultColumnState (IShellFolder2
* iface
, UINT iColumn
,
925 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
927 TRACE ("(%p)\n", This
);
929 if (!pcsFlags
|| iColumn
>= GENERICSHELLVIEWCOLUMNS
)
932 *pcsFlags
= GenericSFHeader
[iColumn
].pcsFlags
;
937 static HRESULT WINAPI
938 IShellFolder_fnGetDetailsEx (IShellFolder2
* iface
, LPCITEMIDLIST pidl
,
939 const SHCOLUMNID
* pscid
, VARIANT
* pv
)
941 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
942 FIXME ("(%p)\n", This
);
947 static HRESULT WINAPI
948 IShellFolder_fnGetDetailsOf (IShellFolder2
* iface
, LPCITEMIDLIST pidl
,
949 UINT iColumn
, SHELLDETAILS
* psd
)
951 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
954 TRACE ("(%p)->(%p %i %p)\n", This
, pidl
, iColumn
, psd
);
956 if (!psd
|| iColumn
>= GENERICSHELLVIEWCOLUMNS
)
960 /* the header titles */
961 psd
->fmt
= GenericSFHeader
[iColumn
].fmt
;
962 psd
->cxChar
= GenericSFHeader
[iColumn
].cxChar
;
963 psd
->str
.uType
= STRRET_CSTR
;
964 LoadStringA (shell32_hInstance
, GenericSFHeader
[iColumn
].colnameid
,
965 psd
->str
.u
.cStr
, MAX_PATH
);
968 /* the data from the pidl */
971 hr
= IShellFolder_GetDisplayNameOf (iface
, pidl
,
972 SHGDN_NORMAL
| SHGDN_INFOLDER
, &psd
->str
);
975 _ILGetFileSize (pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
978 _ILGetFileType (pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
981 _ILGetFileDate (pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
983 case 4: /* attributes */
984 _ILGetFileAttributes (pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
988 psd
->str
.uType
= STRRET_CSTR
;
994 static HRESULT WINAPI
995 IShellFolder_fnMapColumnToSCID (IShellFolder2
* iface
, UINT column
,
998 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
999 FIXME ("(%p)\n", This
);
1003 static const IShellFolder2Vtbl sfvt
=
1005 IShellFolder_fnQueryInterface
,
1006 IShellFolder_fnAddRef
,
1007 IShellFolder_fnRelease
,
1008 IShellFolder_fnParseDisplayName
,
1009 IShellFolder_fnEnumObjects
,
1010 IShellFolder_fnBindToObject
,
1011 IShellFolder_fnBindToStorage
,
1012 IShellFolder_fnCompareIDs
,
1013 IShellFolder_fnCreateViewObject
,
1014 IShellFolder_fnGetAttributesOf
,
1015 IShellFolder_fnGetUIObjectOf
,
1016 IShellFolder_fnGetDisplayNameOf
,
1017 IShellFolder_fnSetNameOf
,
1019 IShellFolder_fnGetDefaultSearchGUID
,
1020 IShellFolder_fnEnumSearches
,
1021 IShellFolder_fnGetDefaultColumn
,
1022 IShellFolder_fnGetDefaultColumnState
,
1023 IShellFolder_fnGetDetailsEx
,
1024 IShellFolder_fnGetDetailsOf
,
1025 IShellFolder_fnMapColumnToSCID
1028 /****************************************************************************
1029 * ISFHelper for IShellFolder implementation
1032 static HRESULT WINAPI
1033 ISFHelper_fnQueryInterface (ISFHelper
* iface
, REFIID riid
, LPVOID
* ppvObj
)
1035 IGenericSFImpl
*This
= impl_from_ISFHelper(iface
);
1037 TRACE ("(%p)->(count=%lu)\n", This
, This
->ref
);
1039 return IUnknown_QueryInterface (This
->pUnkOuter
, riid
, ppvObj
);
1042 static ULONG WINAPI
ISFHelper_fnAddRef (ISFHelper
* iface
)
1044 IGenericSFImpl
*This
= impl_from_ISFHelper(iface
);
1046 TRACE ("(%p)->(count=%lu)\n", This
, This
->ref
);
1048 return IUnknown_AddRef (This
->pUnkOuter
);
1051 static ULONG WINAPI
ISFHelper_fnRelease (ISFHelper
* iface
)
1053 IGenericSFImpl
*This
= impl_from_ISFHelper(iface
);
1055 TRACE ("(%p)\n", This
);
1057 return IUnknown_Release (This
->pUnkOuter
);
1060 /****************************************************************************
1061 * ISFHelper_fnAddFolder
1063 * creates a unique folder name
1066 static HRESULT WINAPI
1067 ISFHelper_fnGetUniqueName (ISFHelper
* iface
, LPSTR lpName
, UINT uLen
)
1069 IGenericSFImpl
*This
= impl_from_ISFHelper(iface
);
1072 char szText
[MAX_PATH
];
1073 const char *szNewFolder
= "New Folder";
1075 TRACE ("(%p)(%s %u)\n", This
, lpName
, uLen
);
1077 if (uLen
< strlen (szNewFolder
) + 4)
1080 strcpy (lpName
, szNewFolder
);
1082 hr
= IShellFolder_fnEnumObjects (_IShellFolder2_ (This
), 0,
1083 SHCONTF_FOLDERS
| SHCONTF_NONFOLDERS
| SHCONTF_INCLUDEHIDDEN
, &penum
);
1090 IEnumIDList_Reset (penum
);
1091 while (S_OK
== IEnumIDList_Next (penum
, 1, &pidl
, &dwFetched
) &&
1093 _ILSimpleGetText (pidl
, szText
, MAX_PATH
);
1094 if (0 == strcasecmp (szText
, lpName
)) {
1095 sprintf (lpName
, "%s %d", szNewFolder
, i
++);
1104 IEnumIDList_Release (penum
);
1109 /****************************************************************************
1110 * ISFHelper_fnAddFolder
1112 * adds a new folder.
1115 static HRESULT WINAPI
1116 ISFHelper_fnAddFolder (ISFHelper
* iface
, HWND hwnd
, LPCSTR lpName
,
1117 LPITEMIDLIST
* ppidlOut
)
1119 IGenericSFImpl
*This
= impl_from_ISFHelper(iface
);
1120 char lpstrNewDir
[MAX_PATH
];
1122 HRESULT hres
= E_FAIL
;
1124 TRACE ("(%p)(%s %p)\n", This
, lpName
, ppidlOut
);
1126 if (!WideCharToMultiByte(CP_ACP
, 0, This
->sPathTarget
, -1, lpstrNewDir
, MAX_PATH
, NULL
, NULL
))
1127 lpstrNewDir
[0] = '\0';
1128 PathAppendA(lpstrNewDir
, lpName
);
1130 bRes
= CreateDirectoryA (lpstrNewDir
, NULL
);
1132 SHChangeNotify (SHCNE_MKDIR
, SHCNF_PATHA
, lpstrNewDir
, NULL
);
1137 hres
= _ILCreateFromPathA(lpstrNewDir
, ppidlOut
);
1139 char lpstrText
[128 + MAX_PATH
];
1140 char lpstrTempText
[128];
1141 char lpstrCaption
[256];
1143 /* Cannot Create folder because of permissions */
1144 LoadStringA (shell32_hInstance
, IDS_CREATEFOLDER_DENIED
, lpstrTempText
,
1145 sizeof (lpstrTempText
));
1146 LoadStringA (shell32_hInstance
, IDS_CREATEFOLDER_CAPTION
, lpstrCaption
,
1147 sizeof (lpstrCaption
));
1148 sprintf (lpstrText
, lpstrTempText
, lpstrNewDir
);
1149 MessageBoxA (hwnd
, lpstrText
, lpstrCaption
, MB_OK
| MB_ICONEXCLAMATION
);
1155 /****************************************************************************
1156 * ISFHelper_fnDeleteItems
1158 * deletes items in folder
1160 static HRESULT WINAPI
1161 ISFHelper_fnDeleteItems (ISFHelper
* iface
, UINT cidl
, LPCITEMIDLIST
* apidl
)
1163 IGenericSFImpl
*This
= impl_from_ISFHelper(iface
);
1165 char szPath
[MAX_PATH
];
1166 BOOL bConfirm
= TRUE
;
1168 TRACE ("(%p)(%u %p)\n", This
, cidl
, apidl
);
1170 /* deleting multiple items so give a slightly different warning */
1174 snprintf (tmp
, sizeof (tmp
), "%d", cidl
);
1175 if (!SHELL_ConfirmDialog(ASK_DELETE_MULTIPLE_ITEM
, tmp
))
1180 for (i
= 0; i
< cidl
; i
++) {
1181 if (!WideCharToMultiByte(CP_ACP
, 0, This
->sPathTarget
, -1, szPath
, MAX_PATH
, NULL
, NULL
))
1183 PathAddBackslashA (szPath
);
1184 _ILSimpleGetText (apidl
[i
], szPath
+ strlen (szPath
), MAX_PATH
);
1186 if (_ILIsFolder (apidl
[i
])) {
1189 TRACE ("delete %s\n", szPath
);
1190 if (!SHELL_DeleteDirectoryA (szPath
, bConfirm
)) {
1191 TRACE ("delete %s failed, bConfirm=%d\n", szPath
, bConfirm
);
1194 pidl
= ILCombine (This
->pidlRoot
, apidl
[i
]);
1195 SHChangeNotify (SHCNE_RMDIR
, SHCNF_IDLIST
, pidl
, NULL
);
1197 } else if (_ILIsValue (apidl
[i
])) {
1200 TRACE ("delete %s\n", szPath
);
1201 if (!SHELL_DeleteFileA (szPath
, bConfirm
)) {
1202 TRACE ("delete %s failed, bConfirm=%d\n", szPath
, bConfirm
);
1205 pidl
= ILCombine (This
->pidlRoot
, apidl
[i
]);
1206 SHChangeNotify (SHCNE_DELETE
, SHCNF_IDLIST
, pidl
, NULL
);
1214 /****************************************************************************
1215 * ISFHelper_fnCopyItems
1217 * copies items to this folder
1219 static HRESULT WINAPI
1220 ISFHelper_fnCopyItems (ISFHelper
* iface
, IShellFolder
* pSFFrom
, UINT cidl
,
1221 LPCITEMIDLIST
* apidl
)
1224 IPersistFolder2
*ppf2
= NULL
;
1225 char szSrcPath
[MAX_PATH
],
1226 szDstPath
[MAX_PATH
];
1228 IGenericSFImpl
*This
= impl_from_ISFHelper(iface
);
1230 TRACE ("(%p)->(%p,%u,%p)\n", This
, pSFFrom
, cidl
, apidl
);
1232 IShellFolder_QueryInterface (pSFFrom
, &IID_IPersistFolder2
,
1237 if (SUCCEEDED (IPersistFolder2_GetCurFolder (ppf2
, &pidl
))) {
1238 for (i
= 0; i
< cidl
; i
++) {
1239 SHGetPathFromIDListA (pidl
, szSrcPath
);
1240 PathAddBackslashA (szSrcPath
);
1241 _ILSimpleGetText (apidl
[i
], szSrcPath
+ strlen (szSrcPath
),
1244 if (!WideCharToMultiByte(CP_ACP
, 0, This
->sPathTarget
, -1, szDstPath
, MAX_PATH
, NULL
, NULL
))
1245 szDstPath
[0] = '\0';
1246 PathAddBackslashA (szDstPath
);
1247 _ILSimpleGetText (apidl
[i
], szDstPath
+ strlen (szDstPath
),
1249 MESSAGE ("would copy %s to %s\n", szSrcPath
, szDstPath
);
1253 IPersistFolder2_Release (ppf2
);
1258 static const ISFHelperVtbl shvt
=
1260 ISFHelper_fnQueryInterface
,
1262 ISFHelper_fnRelease
,
1263 ISFHelper_fnGetUniqueName
,
1264 ISFHelper_fnAddFolder
,
1265 ISFHelper_fnDeleteItems
,
1266 ISFHelper_fnCopyItems
1269 /************************************************************************
1270 * IFSFldr_PersistFolder3_QueryInterface
1273 static HRESULT WINAPI
1274 IFSFldr_PersistFolder3_QueryInterface (IPersistFolder3
* iface
, REFIID iid
,
1277 IGenericSFImpl
*This
= impl_from_IPersistFolder3(iface
);
1279 TRACE ("(%p)\n", This
);
1281 return IUnknown_QueryInterface (This
->pUnkOuter
, iid
, ppvObj
);
1284 /************************************************************************
1285 * IFSFldr_PersistFolder3_AddRef
1289 IFSFldr_PersistFolder3_AddRef (IPersistFolder3
* iface
)
1291 IGenericSFImpl
*This
= impl_from_IPersistFolder3(iface
);
1293 TRACE ("(%p)->(count=%lu)\n", This
, This
->ref
);
1295 return IUnknown_AddRef (This
->pUnkOuter
);
1298 /************************************************************************
1299 * IFSFldr_PersistFolder3_Release
1303 IFSFldr_PersistFolder3_Release (IPersistFolder3
* iface
)
1305 IGenericSFImpl
*This
= impl_from_IPersistFolder3(iface
);
1307 TRACE ("(%p)->(count=%lu)\n", This
, This
->ref
);
1309 return IUnknown_Release (This
->pUnkOuter
);
1312 /************************************************************************
1313 * IFSFldr_PersistFolder3_GetClassID
1315 static HRESULT WINAPI
1316 IFSFldr_PersistFolder3_GetClassID (IPersistFolder3
* iface
, CLSID
* lpClassId
)
1318 IGenericSFImpl
*This
= impl_from_IPersistFolder3(iface
);
1320 TRACE ("(%p)\n", This
);
1324 *lpClassId
= *This
->pclsid
;
1329 /************************************************************************
1330 * IFSFldr_PersistFolder3_Initialize
1333 * sPathTarget is not set. Don't know how to handle in a non rooted environment.
1335 static HRESULT WINAPI
1336 IFSFldr_PersistFolder3_Initialize (IPersistFolder3
* iface
, LPCITEMIDLIST pidl
)
1338 WCHAR wszTemp
[MAX_PATH
];
1340 IGenericSFImpl
*This
= impl_from_IPersistFolder3(iface
);
1342 TRACE ("(%p)->(%p)\n", This
, pidl
);
1345 SHFree (This
->pidlRoot
); /* free the old pidl */
1346 This
->pidlRoot
= ILClone (pidl
); /* set my pidl */
1348 if (This
->sPathTarget
)
1350 SHFree (This
->sPathTarget
);
1351 This
->sPathTarget
= NULL
;
1355 if (SHGetPathFromIDListW (pidl
, wszTemp
)) {
1356 int len
= strlenW(wszTemp
);
1357 This
->sPathTarget
= SHAlloc((len
+ 1) * sizeof(WCHAR
));
1358 if (!This
->sPathTarget
)
1359 return E_OUTOFMEMORY
;
1360 memcpy(This
->sPathTarget
, wszTemp
, (len
+ 1) * sizeof(WCHAR
));
1363 TRACE ("--(%p)->(%s)\n", This
, debugstr_w(This
->sPathTarget
));
1367 /**************************************************************************
1368 * IFSFldr_PersistFolder3_GetCurFolder
1370 static HRESULT WINAPI
1371 IFSFldr_PersistFolder3_fnGetCurFolder (IPersistFolder3
* iface
,
1372 LPITEMIDLIST
* pidl
)
1374 IGenericSFImpl
*This
= impl_from_IPersistFolder3(iface
);
1376 TRACE ("(%p)->(%p)\n", This
, pidl
);
1378 if (!pidl
) return E_POINTER
;
1379 *pidl
= ILClone (This
->pidlRoot
);
1383 /**************************************************************************
1384 * IFSFldr_PersistFolder3_InitializeEx
1386 * FIXME: error handling
1388 static HRESULT WINAPI
1389 IFSFldr_PersistFolder3_InitializeEx (IPersistFolder3
* iface
,
1390 IBindCtx
* pbc
, LPCITEMIDLIST pidlRoot
,
1391 const PERSIST_FOLDER_TARGET_INFO
* ppfti
)
1393 WCHAR wszTemp
[MAX_PATH
];
1395 IGenericSFImpl
*This
= impl_from_IPersistFolder3(iface
);
1397 TRACE ("(%p)->(%p,%p,%p)\n", This
, pbc
, pidlRoot
, ppfti
);
1399 TRACE ("--%p %s %s 0x%08lx 0x%08x\n",
1400 ppfti
->pidlTargetFolder
, debugstr_w (ppfti
->szTargetParsingName
),
1401 debugstr_w (ppfti
->szNetworkProvider
), ppfti
->dwAttributes
,
1405 if (ppfti
&& ppfti
->pidlTargetFolder
)
1406 pdump (ppfti
->pidlTargetFolder
);
1409 __SHFreeAndNil (&This
->pidlRoot
); /* free the old */
1410 if (This
->sPathTarget
)
1411 __SHFreeAndNil (&This
->sPathTarget
);
1414 * Root path and pidl
1416 This
->pidlRoot
= ILClone (pidlRoot
);
1419 * the target folder is spezified in csidl OR pidlTargetFolder OR
1420 * szTargetParsingName
1423 if (ppfti
->csidl
!= -1) {
1424 if (SHGetSpecialFolderPathW (0, wszTemp
, ppfti
->csidl
,
1425 ppfti
->csidl
& CSIDL_FLAG_CREATE
)) {
1426 int len
= strlenW(wszTemp
);
1427 This
->sPathTarget
= SHAlloc((len
+ 1) * sizeof(WCHAR
));
1428 if (!This
->sPathTarget
)
1429 return E_OUTOFMEMORY
;
1430 memcpy(This
->sPathTarget
, wszTemp
, (len
+ 1) * sizeof(WCHAR
));
1432 } else if (ppfti
->szTargetParsingName
[0]) {
1433 int len
= strlenW(ppfti
->szTargetParsingName
);
1434 This
->sPathTarget
= SHAlloc((len
+ 1) * sizeof(WCHAR
));
1435 if (!This
->sPathTarget
)
1436 return E_OUTOFMEMORY
;
1437 memcpy(This
->sPathTarget
, ppfti
->szTargetParsingName
,
1438 (len
+ 1) * sizeof(WCHAR
));
1439 } else if (ppfti
->pidlTargetFolder
) {
1440 if (SHGetPathFromIDListW(ppfti
->pidlTargetFolder
, wszTemp
)) {
1441 int len
= strlenW(wszTemp
);
1442 This
->sPathTarget
= SHAlloc((len
+ 1) * sizeof(WCHAR
));
1443 if (!This
->sPathTarget
)
1444 return E_OUTOFMEMORY
;
1445 memcpy(This
->sPathTarget
, wszTemp
, (len
+ 1) * sizeof(WCHAR
));
1450 TRACE ("--(%p)->(target=%s)\n", This
, debugstr_w(This
->sPathTarget
));
1451 pdump (This
->pidlRoot
);
1452 return (This
->sPathTarget
) ? S_OK
: E_FAIL
;
1455 static HRESULT WINAPI
1456 IFSFldr_PersistFolder3_GetFolderTargetInfo (IPersistFolder3
* iface
,
1457 PERSIST_FOLDER_TARGET_INFO
* ppfti
)
1459 IGenericSFImpl
*This
= impl_from_IPersistFolder3(iface
);
1460 FIXME ("(%p)->(%p)\n", This
, ppfti
);
1461 ZeroMemory (ppfti
, sizeof (ppfti
));
1465 static const IPersistFolder3Vtbl vt_FSFldr_PersistFolder3
=
1467 IFSFldr_PersistFolder3_QueryInterface
,
1468 IFSFldr_PersistFolder3_AddRef
,
1469 IFSFldr_PersistFolder3_Release
,
1470 IFSFldr_PersistFolder3_GetClassID
,
1471 IFSFldr_PersistFolder3_Initialize
,
1472 IFSFldr_PersistFolder3_fnGetCurFolder
,
1473 IFSFldr_PersistFolder3_InitializeEx
,
1474 IFSFldr_PersistFolder3_GetFolderTargetInfo
1477 /****************************************************************************
1478 * ISFDropTarget implementation
1481 ISFDropTarget_QueryDrop (IDropTarget
* iface
, DWORD dwKeyState
,
1484 DWORD dwEffect
= *pdwEffect
;
1486 IGenericSFImpl
*This
= impl_from_IDropTarget(iface
);
1488 *pdwEffect
= DROPEFFECT_NONE
;
1490 if (This
->fAcceptFmt
) { /* Does our interpretation of the keystate ... */
1491 *pdwEffect
= KeyStateToDropEffect (dwKeyState
);
1493 /* ... matches the desired effect ? */
1494 if (dwEffect
& *pdwEffect
) {
1501 static HRESULT WINAPI
1502 ISFDropTarget_QueryInterface (IDropTarget
* iface
, REFIID riid
, LPVOID
* ppvObj
)
1504 IGenericSFImpl
*This
= impl_from_IDropTarget(iface
);
1506 TRACE ("(%p)\n", This
);
1508 return IUnknown_QueryInterface (This
->pUnkOuter
, riid
, ppvObj
);
1511 static ULONG WINAPI
ISFDropTarget_AddRef (IDropTarget
* iface
)
1513 IGenericSFImpl
*This
= impl_from_IDropTarget(iface
);
1515 TRACE ("(%p)\n", This
);
1517 return IUnknown_AddRef (This
->pUnkOuter
);
1520 static ULONG WINAPI
ISFDropTarget_Release (IDropTarget
* iface
)
1522 IGenericSFImpl
*This
= impl_from_IDropTarget(iface
);
1524 TRACE ("(%p)\n", This
);
1526 return IUnknown_Release (This
->pUnkOuter
);
1529 static HRESULT WINAPI
1530 ISFDropTarget_DragEnter (IDropTarget
* iface
, IDataObject
* pDataObject
,
1531 DWORD dwKeyState
, POINTL pt
, DWORD
* pdwEffect
)
1535 IGenericSFImpl
*This
= impl_from_IDropTarget(iface
);
1537 TRACE ("(%p)->(DataObject=%p)\n", This
, pDataObject
);
1539 InitFormatEtc (fmt
, This
->cfShellIDList
, TYMED_HGLOBAL
);
1541 This
->fAcceptFmt
= (S_OK
== IDataObject_QueryGetData (pDataObject
, &fmt
)) ?
1544 ISFDropTarget_QueryDrop (iface
, dwKeyState
, pdwEffect
);
1549 static HRESULT WINAPI
1550 ISFDropTarget_DragOver (IDropTarget
* iface
, DWORD dwKeyState
, POINTL pt
,
1553 IGenericSFImpl
*This
= impl_from_IDropTarget(iface
);
1555 TRACE ("(%p)\n", This
);
1558 return E_INVALIDARG
;
1560 ISFDropTarget_QueryDrop (iface
, dwKeyState
, pdwEffect
);
1565 static HRESULT WINAPI
ISFDropTarget_DragLeave (IDropTarget
* iface
)
1567 IGenericSFImpl
*This
= impl_from_IDropTarget(iface
);
1569 TRACE ("(%p)\n", This
);
1571 This
->fAcceptFmt
= FALSE
;
1576 static HRESULT WINAPI
1577 ISFDropTarget_Drop (IDropTarget
* iface
, IDataObject
* pDataObject
,
1578 DWORD dwKeyState
, POINTL pt
, DWORD
* pdwEffect
)
1580 IGenericSFImpl
*This
= impl_from_IDropTarget(iface
);
1582 FIXME ("(%p) object dropped\n", This
);
1587 static const IDropTargetVtbl dtvt
= {
1588 ISFDropTarget_QueryInterface
,
1589 ISFDropTarget_AddRef
,
1590 ISFDropTarget_Release
,
1591 ISFDropTarget_DragEnter
,
1592 ISFDropTarget_DragOver
,
1593 ISFDropTarget_DragLeave
,