4 * Copyright 1997 Marcus Meissner
5 * Copyright 1998, 1999, 2002 Juergen Schmied
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "wine/port.h"
31 #define NONAMELESSUNION
32 #define NONAMELESSSTRUCT
44 #include "enumidlist.h"
46 #include "undocshell.h"
47 #include "shell32_main.h"
50 #include "shellfolder.h"
51 #include "wine/debug.h"
55 WINE_DEFAULT_DEBUG_CHANNEL (shell
);
57 extern BOOL fileMoving
;
59 /***********************************************************************
60 * IShellFolder implementation
64 const IUnknownVtbl
*lpVtbl
;
66 const IShellFolder2Vtbl
*lpvtblShellFolder
;
67 const IPersistFolder3Vtbl
*lpvtblPersistFolder3
;
68 const IDropTargetVtbl
*lpvtblDropTarget
;
69 const ISFHelperVtbl
*lpvtblSFHelper
;
71 IUnknown
*pUnkOuter
; /* used for aggregation */
75 /* both paths are parsible from the desktop */
76 LPSTR sPathTarget
; /* complete path to target used for enumeration and ChangeNotify */
78 LPITEMIDLIST pidlRoot
; /* absolute pidl */
80 UINT cfShellIDList
; /* clipboardformat for IDropTarget */
81 BOOL fAcceptFmt
; /* flag for pending Drop */
84 static const IUnknownVtbl unkvt
;
85 static const IShellFolder2Vtbl sfvt
;
86 static const IPersistFolder3Vtbl vt_FSFldr_PersistFolder3
; /* IPersistFolder3 for a FS_Folder */
87 static const IDropTargetVtbl dtvt
;
88 static const ISFHelperVtbl shvt
;
90 static inline IGenericSFImpl
*impl_from_IShellFolder2( IShellFolder2
*iface
)
92 return (IGenericSFImpl
*)((char*)iface
- FIELD_OFFSET(IGenericSFImpl
, lpvtblShellFolder
));
95 static inline IGenericSFImpl
*impl_from_IPersistFolder3( IPersistFolder3
*iface
)
97 return (IGenericSFImpl
*)((char*)iface
- FIELD_OFFSET(IGenericSFImpl
, lpvtblPersistFolder3
));
100 static inline IGenericSFImpl
*impl_from_IDropTarget( IDropTarget
*iface
)
102 return (IGenericSFImpl
*)((char*)iface
- FIELD_OFFSET(IGenericSFImpl
, lpvtblDropTarget
));
105 static inline IGenericSFImpl
*impl_from_ISFHelper( ISFHelper
*iface
)
107 return (IGenericSFImpl
*)((char*)iface
- FIELD_OFFSET(IGenericSFImpl
, lpvtblSFHelper
));
112 converts This to an interface pointer
114 #define _IUnknown_(This) (IUnknown*)&(This->lpVtbl)
115 #define _IShellFolder_(This) (IShellFolder*)&(This->lpvtblShellFolder)
116 #define _IShellFolder2_(This) (IShellFolder2*)&(This->lpvtblShellFolder)
117 #define _IPersist_(This) (IPersist*)&(This->lpvtblPersistFolder3)
118 #define _IPersistFolder_(This) (IPersistFolder*)&(This->lpvtblPersistFolder3)
119 #define _IPersistFolder2_(This) (IPersistFolder2*)&(This->lpvtblPersistFolder3)
120 #define _IPersistFolder3_(This) (IPersistFolder3*)&(This->lpvtblPersistFolder3)
121 #define _IDropTarget_(This) (IDropTarget*)&(This->lpvtblDropTarget)
122 #define _ISFHelper_(This) (ISFHelper*)&(This->lpvtblSFHelper)
124 /**************************************************************************
125 * registers clipboardformat once
127 static void SF_RegisterClipFmt (IGenericSFImpl
* This
)
129 TRACE ("(%p)\n", This
);
131 if (!This
->cfShellIDList
) {
132 This
->cfShellIDList
= RegisterClipboardFormatA (CFSTR_SHELLIDLIST
);
136 /**************************************************************************
137 * we need a separate IUnknown to handle aggregation
140 static HRESULT WINAPI
IUnknown_fnQueryInterface (IUnknown
* iface
, REFIID riid
, LPVOID
* ppvObj
)
142 IGenericSFImpl
*This
= (IGenericSFImpl
*)iface
;
144 TRACE ("(%p)->(%s,%p)\n", This
, shdebugstr_guid (riid
), ppvObj
);
148 if (IsEqualIID (riid
, &IID_IUnknown
))
149 *ppvObj
= _IUnknown_ (This
);
150 else if (IsEqualIID (riid
, &IID_IShellFolder
))
151 *ppvObj
= _IShellFolder_ (This
);
152 else if (IsEqualIID (riid
, &IID_IShellFolder2
))
153 *ppvObj
= _IShellFolder_ (This
);
154 else if (IsEqualIID (riid
, &IID_IPersist
))
155 *ppvObj
= _IPersist_ (This
);
156 else if (IsEqualIID (riid
, &IID_IPersistFolder
))
157 *ppvObj
= _IPersistFolder_ (This
);
158 else if (IsEqualIID (riid
, &IID_IPersistFolder2
))
159 *ppvObj
= _IPersistFolder2_ (This
);
160 else if (IsEqualIID (riid
, &IID_IPersistFolder3
))
161 *ppvObj
= _IPersistFolder3_ (This
);
162 else if (IsEqualIID (riid
, &IID_ISFHelper
))
163 *ppvObj
= _ISFHelper_ (This
);
164 else if (IsEqualIID (riid
, &IID_IDropTarget
)) {
165 *ppvObj
= _IDropTarget_ (This
);
166 SF_RegisterClipFmt (This
);
170 IUnknown_AddRef ((IUnknown
*) (*ppvObj
));
171 TRACE ("-- Interface = %p\n", *ppvObj
);
174 TRACE ("-- Interface: E_NOINTERFACE\n");
175 return E_NOINTERFACE
;
178 static ULONG WINAPI
IUnknown_fnAddRef (IUnknown
* iface
)
180 IGenericSFImpl
*This
= (IGenericSFImpl
*)iface
;
181 ULONG refCount
= InterlockedIncrement(&This
->ref
);
183 TRACE ("(%p)->(count=%lu)\n", This
, refCount
- 1);
188 static ULONG WINAPI
IUnknown_fnRelease (IUnknown
* iface
)
190 IGenericSFImpl
*This
= (IGenericSFImpl
*)iface
;
191 ULONG refCount
= InterlockedDecrement(&This
->ref
);
193 TRACE ("(%p)->(count=%lu)\n", This
, refCount
+ 1);
196 TRACE ("-- destroying IShellFolder(%p)\n", This
);
199 SHFree (This
->pidlRoot
);
200 if (This
->sPathTarget
)
201 SHFree (This
->sPathTarget
);
202 LocalFree ((HLOCAL
) This
);
207 static const IUnknownVtbl unkvt
=
209 IUnknown_fnQueryInterface
,
214 static shvheader GenericSFHeader
[] = {
215 {IDS_SHV_COLUMN1
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 15},
216 {IDS_SHV_COLUMN2
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 10},
217 {IDS_SHV_COLUMN3
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 10},
218 {IDS_SHV_COLUMN4
, SHCOLSTATE_TYPE_DATE
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 12},
219 {IDS_SHV_COLUMN5
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 5}
222 #define GENERICSHELLVIEWCOLUMNS 5
224 /**************************************************************************
225 * IFSFolder_Constructor
228 * creating undocumented ShellFS_Folder as part of an aggregation
229 * {F3364BA0-65B9-11CE-A9BA-00AA004AE837}
233 IFSFolder_Constructor (IUnknown
* pUnkOuter
, REFIID riid
, LPVOID
* ppv
)
237 TRACE ("unkOut=%p %s\n", pUnkOuter
, shdebugstr_guid (riid
));
239 if (pUnkOuter
&& !IsEqualIID (riid
, &IID_IUnknown
))
240 return CLASS_E_NOAGGREGATION
;
241 sf
= (IGenericSFImpl
*) LocalAlloc (LMEM_ZEROINIT
, sizeof (IGenericSFImpl
));
243 return E_OUTOFMEMORY
;
247 sf
->lpvtblShellFolder
= &sfvt
;
248 sf
->lpvtblPersistFolder3
= &vt_FSFldr_PersistFolder3
;
249 sf
->lpvtblDropTarget
= &dtvt
;
250 sf
->lpvtblSFHelper
= &shvt
;
251 sf
->pclsid
= (CLSID
*) & CLSID_ShellFSFolder
;
252 sf
->pUnkOuter
= pUnkOuter
? pUnkOuter
: _IUnknown_ (sf
);
254 if (!SUCCEEDED (IUnknown_QueryInterface (_IUnknown_ (sf
), riid
, ppv
))) {
255 IUnknown_Release (_IUnknown_ (sf
));
256 return E_NOINTERFACE
;
259 TRACE ("--%p\n", *ppv
);
263 /**************************************************************************
264 * IShellFolder_fnQueryInterface
267 * REFIID riid [in ] Requested InterfaceID
268 * LPVOID* ppvObject [out] Interface* to hold the result
270 static HRESULT WINAPI
271 IShellFolder_fnQueryInterface (IShellFolder2
* iface
, REFIID riid
,
274 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
276 TRACE ("(%p)->(%s,%p)\n", This
, shdebugstr_guid (riid
), ppvObj
);
278 return IUnknown_QueryInterface (This
->pUnkOuter
, riid
, ppvObj
);
281 /**************************************************************************
282 * IShellFolder_AddRef
285 static ULONG WINAPI
IShellFolder_fnAddRef (IShellFolder2
* iface
)
287 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
289 TRACE ("(%p)->(count=%lu)\n", This
, This
->ref
);
291 return IUnknown_AddRef (This
->pUnkOuter
);
294 /**************************************************************************
295 * IShellFolder_fnRelease
297 static ULONG WINAPI
IShellFolder_fnRelease (IShellFolder2
* iface
)
299 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
301 TRACE ("(%p)->(count=%lu)\n", This
, This
->ref
);
303 return IUnknown_Release (This
->pUnkOuter
);
306 /**************************************************************************
307 * SHELL32_CreatePidlFromBindCtx [internal]
309 * If the caller bound File System Bind Data, assume it is the
310 * find data for the path.
311 * This allows binding of paths that don't exist.
313 LPITEMIDLIST
SHELL32_CreatePidlFromBindCtx(IBindCtx
*pbc
, LPCWSTR path
)
315 static const WCHAR szfsbc
[] = {
316 'F','i','l','e',' ','S','y','s','t','e','m',' ',
317 'B','i','n','d',' ','D','a','t','a',0 };
318 IFileSystemBindData
*fsbd
= NULL
;
319 LPITEMIDLIST pidl
= NULL
;
320 IUnknown
*param
= NULL
;
321 WIN32_FIND_DATAW wfd
;
324 TRACE("%p %s\n", pbc
, debugstr_w(path
));
329 /* see if the caller bound File System Bind Data */
330 r
= IBindCtx_GetObjectParam( pbc
, (LPOLESTR
) szfsbc
, ¶m
);
334 r
= IUnknown_QueryInterface( param
, &IID_IFileSystemBindData
,
338 r
= IFileSystemBindData_GetFindData( fsbd
, &wfd
);
341 lstrcpynW( &wfd
.cFileName
[0], path
, MAX_PATH
);
342 pidl
= _ILCreateFromFindDataW( &wfd
);
344 IFileSystemBindData_Release( fsbd
);
350 /**************************************************************************
351 * IShellFolder_ParseDisplayName {SHELL32}
353 * Parse a display name.
356 * hwndOwner [in] Parent window for any message's
357 * pbc [in] optional FileSystemBindData context
358 * lpszDisplayName [in] Unicode displayname.
359 * pchEaten [out] (unicode) characters processed
360 * ppidl [out] complex pidl to item
361 * pdwAttributes [out] items attributes
364 * Every folder tries to parse only its own (the leftmost) pidl and creates a
365 * subfolder to evaluate the remaining parts.
366 * Now we can parse into namespaces implemented by shell extensions
368 * Behaviour on win98: lpszDisplayName=NULL -> crash
369 * lpszDisplayName="" -> returns mycoputer-pidl
372 * pdwAttributes is not set
373 * pchEaten is not set like in windows
375 static HRESULT WINAPI
376 IShellFolder_fnParseDisplayName (IShellFolder2
* iface
,
379 LPOLESTR lpszDisplayName
,
380 DWORD
* pchEaten
, LPITEMIDLIST
* ppidl
,
381 DWORD
* pdwAttributes
)
383 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
385 HRESULT hr
= E_INVALIDARG
;
386 LPCWSTR szNext
= NULL
;
387 WCHAR szElement
[MAX_PATH
];
388 WCHAR szPath
[MAX_PATH
];
389 LPITEMIDLIST pidlTemp
= NULL
;
392 TRACE ("(%p)->(HWND=%p,%p,%p=%s,%p,pidl=%p,%p)\n",
393 This
, hwndOwner
, pbc
, lpszDisplayName
, debugstr_w (lpszDisplayName
),
394 pchEaten
, ppidl
, pdwAttributes
);
396 if (!lpszDisplayName
|| !ppidl
)
400 *pchEaten
= 0; /* strange but like the original */
402 pidlTemp
= SHELL32_CreatePidlFromBindCtx(pbc
, lpszDisplayName
);
403 if (!pidlTemp
&& *lpszDisplayName
)
405 /* get the next element */
406 szNext
= GetNextElementW (lpszDisplayName
, szElement
, MAX_PATH
);
408 /* build the full pathname to the element */
409 /* lstrcpyW(szPath, This->sPathTarget); */
410 MultiByteToWideChar(CP_ACP
, 0, This
->sPathTarget
, -1, szPath
, MAX_PATH
);
411 PathAddBackslashW(szPath
);
412 len
= lstrlenW(szPath
);
413 lstrcpynW(szPath
+ len
, szElement
, MAX_PATH
- len
);
416 hr
= _ILCreateFromPathW(szPath
, &pidlTemp
);
419 if (szNext
&& *szNext
) {
420 /* try to analyse the next element */
421 hr
= SHELL32_ParseNextElement (iface
, hwndOwner
, pbc
,
422 &pidlTemp
, (LPOLESTR
) szNext
, pchEaten
, pdwAttributes
);
424 /* it's the last element */
425 if (pdwAttributes
&& *pdwAttributes
) {
426 hr
= SHELL32_GetItemAttributes (_IShellFolder_ (This
),
427 pidlTemp
, pdwAttributes
);
438 TRACE ("(%p)->(-- pidl=%p ret=0x%08lx)\n", This
, ppidl
? *ppidl
: 0, hr
);
443 /**************************************************************************
444 * IShellFolder_fnEnumObjects
446 * HWND hwndOwner, //[in ] Parent Window
447 * DWORD grfFlags, //[in ] SHCONTF enumeration mask
448 * LPENUMIDLIST* ppenumIDList //[out] IEnumIDList interface
450 static HRESULT WINAPI
451 IShellFolder_fnEnumObjects (IShellFolder2
* iface
, HWND hwndOwner
,
452 DWORD dwFlags
, LPENUMIDLIST
* ppEnumIDList
)
454 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
456 TRACE ("(%p)->(HWND=%p flags=0x%08lx pplist=%p)\n", This
, hwndOwner
,
457 dwFlags
, ppEnumIDList
);
459 *ppEnumIDList
= IEnumIDList_Constructor();
462 WCHAR path
[MAX_PATH
];
463 MultiByteToWideChar(CP_ACP
, 0, This
->sPathTarget
, -1, path
, MAX_PATH
);
464 CreateFolderEnumList(*ppEnumIDList
, path
, dwFlags
);
467 TRACE ("-- (%p)->(new ID List: %p)\n", This
, *ppEnumIDList
);
469 return *ppEnumIDList
? S_OK
: E_OUTOFMEMORY
;
472 /**************************************************************************
473 * IShellFolder_fnBindToObject
475 * LPCITEMIDLIST pidl, //[in ] relative pidl to open
476 * LPBC pbc, //[in ] optional FileSystemBindData context
477 * REFIID riid, //[in ] Initial Interface
478 * LPVOID* ppvObject //[out] Interface*
480 static HRESULT WINAPI
481 IShellFolder_fnBindToObject (IShellFolder2
* iface
, LPCITEMIDLIST pidl
,
482 LPBC pbc
, REFIID riid
, LPVOID
* ppvOut
)
484 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
485 WCHAR szPath
[MAX_PATH
];
487 TRACE ("(%p)->(pidl=%p,%p,%s,%p)\n", This
, pidl
, pbc
,
488 shdebugstr_guid (riid
), ppvOut
);
490 MultiByteToWideChar(CP_ACP
, 0, This
->sPathTarget
, -1, szPath
, MAX_PATH
);
491 return SHELL32_BindToChild (This
->pidlRoot
, szPath
, pidl
, riid
,
495 /**************************************************************************
496 * IShellFolder_fnBindToStorage
498 * LPCITEMIDLIST pidl, //[in ] complex pidl to store
499 * LPBC pbc, //[in ] reserved
500 * REFIID riid, //[in ] Initial storage interface
501 * LPVOID* ppvObject //[out] Interface* returned
503 static HRESULT WINAPI
504 IShellFolder_fnBindToStorage (IShellFolder2
* iface
, LPCITEMIDLIST pidl
,
505 LPBC pbcReserved
, REFIID riid
, LPVOID
* ppvOut
)
507 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
509 FIXME ("(%p)->(pidl=%p,%p,%s,%p) stub\n", This
, pidl
, pbcReserved
,
510 shdebugstr_guid (riid
), ppvOut
);
516 /**************************************************************************
517 * IShellFolder_fnCompareIDs
520 static HRESULT WINAPI
521 IShellFolder_fnCompareIDs (IShellFolder2
* iface
, LPARAM lParam
,
522 LPCITEMIDLIST pidl1
, LPCITEMIDLIST pidl2
)
524 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
528 TRACE ("(%p)->(0x%08lx,pidl1=%p,pidl2=%p)\n", This
, lParam
, pidl1
, pidl2
);
529 nReturn
= SHELL32_CompareIDs (_IShellFolder_ (This
), lParam
, pidl1
, pidl2
);
530 TRACE ("-- %i\n", nReturn
);
534 /**************************************************************************
535 * IShellFolder_fnCreateViewObject
537 static HRESULT WINAPI
538 IShellFolder_fnCreateViewObject (IShellFolder2
* iface
, HWND hwndOwner
,
539 REFIID riid
, LPVOID
* ppvOut
)
541 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
543 LPSHELLVIEW pShellView
;
544 HRESULT hr
= E_INVALIDARG
;
546 TRACE ("(%p)->(hwnd=%p,%s,%p)\n", This
, hwndOwner
, shdebugstr_guid (riid
),
552 if (IsEqualIID (riid
, &IID_IDropTarget
)) {
553 hr
= IShellFolder_QueryInterface (iface
, &IID_IDropTarget
, ppvOut
);
554 } else if (IsEqualIID (riid
, &IID_IContextMenu
)) {
555 FIXME ("IContextMenu not implemented\n");
557 } else if (IsEqualIID (riid
, &IID_IShellView
)) {
558 pShellView
= IShellView_Constructor ((IShellFolder
*) iface
);
560 hr
= IShellView_QueryInterface (pShellView
, riid
, ppvOut
);
561 IShellView_Release (pShellView
);
565 TRACE ("-- (%p)->(interface=%p)\n", This
, ppvOut
);
569 /**************************************************************************
570 * IShellFolder_fnGetAttributesOf
573 * UINT cidl, //[in ] num elements in pidl array
574 * LPCITEMIDLIST* apidl, //[in ] simple pidl array
575 * ULONG* rgfInOut) //[out] result array
578 static HRESULT WINAPI
579 IShellFolder_fnGetAttributesOf (IShellFolder2
* iface
, UINT cidl
,
580 LPCITEMIDLIST
* apidl
, DWORD
* rgfInOut
)
582 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
586 TRACE ("(%p)->(cidl=%d apidl=%p mask=%p (0x%08lx))\n", This
, cidl
, apidl
,
587 rgfInOut
, rgfInOut
? *rgfInOut
: 0);
598 IShellFolder
*psfParent
= NULL
;
599 LPCITEMIDLIST rpidl
= NULL
;
601 hr
= SHBindToParent(This
->pidlRoot
, &IID_IShellFolder
, (LPVOID
*)&psfParent
, (LPCITEMIDLIST
*)&rpidl
);
603 SHELL32_GetItemAttributes (psfParent
, rpidl
, rgfInOut
);
604 IShellFolder_Release(psfParent
);
608 while (cidl
> 0 && *apidl
) {
610 SHELL32_GetItemAttributes (_IShellFolder_ (This
), *apidl
, rgfInOut
);
615 /* make sure SFGAO_VALIDATE is cleared, some apps depend on that */
616 *rgfInOut
&= ~SFGAO_VALIDATE
;
618 TRACE ("-- result=0x%08lx\n", *rgfInOut
);
623 /**************************************************************************
624 * IShellFolder_fnGetUIObjectOf
627 * HWND hwndOwner, //[in ] Parent window for any output
628 * UINT cidl, //[in ] array size
629 * LPCITEMIDLIST* apidl, //[in ] simple pidl array
630 * REFIID riid, //[in ] Requested Interface
631 * UINT* prgfInOut, //[ ] reserved
632 * LPVOID* ppvObject) //[out] Resulting Interface
635 * This function gets asked to return "view objects" for one or more (multiple
637 * The viewobject typically is an COM object with one of the following
639 * IExtractIcon,IDataObject,IContextMenu
640 * In order to support icon positions in the default Listview your DataObject
641 * must implement the SetData method (in addition to GetData :) - the shell
642 * passes a barely documented "Icon positions" structure to SetData when the
643 * drag starts, and GetData's it if the drop is in another explorer window that
644 * needs the positions.
646 static HRESULT WINAPI
647 IShellFolder_fnGetUIObjectOf (IShellFolder2
* iface
,
649 UINT cidl
, LPCITEMIDLIST
* apidl
, REFIID riid
,
650 UINT
* prgfInOut
, LPVOID
* ppvOut
)
652 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
655 IUnknown
*pObj
= NULL
;
656 HRESULT hr
= E_INVALIDARG
;
658 TRACE ("(%p)->(%p,%u,apidl=%p,%s,%p,%p)\n",
659 This
, hwndOwner
, cidl
, apidl
, shdebugstr_guid (riid
), prgfInOut
, ppvOut
);
664 if (IsEqualIID (riid
, &IID_IContextMenu
) && (cidl
>= 1)) {
665 pObj
= (LPUNKNOWN
) ISvItemCm_Constructor ((IShellFolder
*) iface
,
666 This
->pidlRoot
, apidl
, cidl
);
668 } else if (IsEqualIID (riid
, &IID_IDataObject
) && (cidl
>= 1)) {
669 pObj
= (LPUNKNOWN
) IDataObject_Constructor (hwndOwner
,
670 This
->pidlRoot
, apidl
, cidl
);
672 } else if (IsEqualIID (riid
, &IID_IExtractIconA
) && (cidl
== 1)) {
673 pidl
= ILCombine (This
->pidlRoot
, apidl
[0]);
674 pObj
= (LPUNKNOWN
) IExtractIconA_Constructor (pidl
);
677 } else if (IsEqualIID (riid
, &IID_IExtractIconW
) && (cidl
== 1)) {
678 pidl
= ILCombine (This
->pidlRoot
, apidl
[0]);
679 pObj
= (LPUNKNOWN
) IExtractIconW_Constructor (pidl
);
682 } else if (IsEqualIID (riid
, &IID_IDropTarget
) && (cidl
>= 1)) {
683 hr
= IShellFolder_QueryInterface (iface
, &IID_IDropTarget
,
685 } else if ((IsEqualIID(riid
,&IID_IShellLinkW
) ||
686 IsEqualIID(riid
,&IID_IShellLinkA
)) && (cidl
== 1)) {
687 pidl
= ILCombine (This
->pidlRoot
, apidl
[0]);
688 hr
= IShellLink_ConstructFromFile(NULL
, riid
, pidl
, (LPVOID
*)&pObj
);
694 if (SUCCEEDED(hr
) && !pObj
)
699 TRACE ("(%p)->hr=0x%08lx\n", This
, hr
);
703 static const WCHAR AdvancedW
[] = { 'S','O','F','T','W','A','R','E',
704 '\\','M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
705 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\','E','x','p','l',
706 'o','r','e','r','\\','A','d','v','a','n','c','e','d',0 };
707 static const WCHAR HideFileExtW
[] = { 'H','i','d','e','F','i','l','e','E','x',
709 static const WCHAR NeverShowExtW
[] = { 'N','e','v','e','r','S','h','o','w','E',
712 /******************************************************************************
713 * SHELL_FS_HideExtension [Internal]
715 * Query the registry if the filename extension of a given path should be
719 * szPath [I] Relative or absolute path of a file
722 * TRUE, if the filename's extension should be hidden
725 BOOL
SHELL_FS_HideExtension(LPWSTR szPath
)
729 DWORD dwDataSize
= sizeof (DWORD
);
730 BOOL doHide
= FALSE
; /* The default value is FALSE (win98 at least) */
732 if (!RegCreateKeyExW(HKEY_CURRENT_USER
, AdvancedW
, 0, 0, 0, KEY_ALL_ACCESS
, 0, &hKey
, 0)) {
733 if (!RegQueryValueExW(hKey
, HideFileExtW
, 0, 0, (LPBYTE
) &dwData
, &dwDataSize
))
739 LPWSTR ext
= PathFindExtensionW(szPath
);
742 WCHAR classname
[MAX_PATH
];
743 LONG classlen
= sizeof(classname
);
745 if (!RegQueryValueW(HKEY_CLASSES_ROOT
, ext
, classname
, &classlen
))
746 if (!RegOpenKeyW(HKEY_CLASSES_ROOT
, classname
, &hKey
)) {
747 if (!RegQueryValueExW(hKey
, NeverShowExtW
, 0, NULL
, NULL
, NULL
))
756 void SHELL_FS_ProcessDisplayFilename(LPSTR szPath
, DWORD dwFlags
)
758 WCHAR pathW
[MAX_PATH
];
760 /*FIXME: MSDN also mentions SHGDN_FOREDITING which is not yet handled. */
761 if (!(dwFlags
& SHGDN_FORPARSING
) &&
762 ((dwFlags
& SHGDN_INFOLDER
) || (dwFlags
== SHGDN_NORMAL
))) {
763 MultiByteToWideChar(CP_ACP
, 0, szPath
, -1, pathW
, MAX_PATH
);
764 if (SHELL_FS_HideExtension(pathW
) && szPath
[0] != '.')
765 PathRemoveExtensionA (szPath
);
769 /**************************************************************************
770 * IShellFolder_fnGetDisplayNameOf
771 * Retrieves the display name for the specified file object or subfolder
774 * LPCITEMIDLIST pidl, //[in ] complex pidl to item
775 * DWORD dwFlags, //[in ] SHGNO formatting flags
776 * LPSTRRET lpName) //[out] Returned display name
779 * if the name is in the pidl the ret value should be a STRRET_OFFSET
782 static HRESULT WINAPI
783 IShellFolder_fnGetDisplayNameOf (IShellFolder2
* iface
, LPCITEMIDLIST pidl
,
784 DWORD dwFlags
, LPSTRRET strRet
)
786 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
791 TRACE ("(%p)->(pidl=%p,0x%08lx,%p)\n", This
, pidl
, dwFlags
, strRet
);
794 if (!pidl
|| !strRet
)
797 strRet
->uType
= STRRET_CSTR
;
798 if (_ILIsDesktop(pidl
)) { /* empty pidl */
799 if ((GET_SHGDN_FOR(dwFlags
) & SHGDN_FORPARSING
) &&
800 (GET_SHGDN_RELATION(dwFlags
) != SHGDN_INFOLDER
))
802 if (This
->sPathTarget
)
803 lstrcpynA(strRet
->u
.cStr
, This
->sPathTarget
, MAX_PATH
);
805 /* pidl has to contain exactly one non null SHITEMID */
808 } else if (_ILIsPidlSimple(pidl
)) {
809 if ((GET_SHGDN_FOR(dwFlags
) & SHGDN_FORPARSING
) &&
810 (GET_SHGDN_RELATION(dwFlags
) != SHGDN_INFOLDER
) &&
813 lstrcpynA(strRet
->u
.cStr
, This
->sPathTarget
, MAX_PATH
);
814 PathAddBackslashA(strRet
->u
.cStr
);
815 len
= lstrlenA(strRet
->u
.cStr
);
817 _ILSimpleGetText(pidl
, strRet
->u
.cStr
+ len
, MAX_PATH
- len
);
818 if (!_ILIsFolder(pidl
)) SHELL_FS_ProcessDisplayFilename(strRet
->u
.cStr
, dwFlags
);
820 hr
= SHELL32_GetDisplayNameOfChild(iface
, pidl
, dwFlags
, strRet
->u
.cStr
, MAX_PATH
);
823 TRACE ("-- (%p)->(%s)\n", This
, strRet
->u
.cStr
);
827 /**************************************************************************
828 * IShellFolder_fnSetNameOf
829 * Changes the name of a file object or subfolder, possibly changing its item
830 * identifier in the process.
833 * HWND hwndOwner, //[in ] Owner window for output
834 * LPCITEMIDLIST pidl, //[in ] simple pidl of item to change
835 * LPCOLESTR lpszName, //[in ] the items new display name
836 * DWORD dwFlags, //[in ] SHGNO formatting flags
837 * LPITEMIDLIST* ppidlOut) //[out] simple pidl returned
839 static HRESULT WINAPI
IShellFolder_fnSetNameOf (IShellFolder2
* iface
,
844 LPITEMIDLIST
* pPidlOut
)
846 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
847 WCHAR szSrc
[MAX_PATH
], szDest
[MAX_PATH
];
849 BOOL bIsFolder
= _ILIsFolder (ILFindLastID (pidl
));
851 TRACE ("(%p)->(%p,pidl=%p,%s,%lu,%p)\n", This
, hwndOwner
, pidl
,
852 debugstr_w (lpName
), dwFlags
, pPidlOut
);
854 /* build source path */
855 MultiByteToWideChar(CP_ACP
, 0, This
->sPathTarget
, -1, szSrc
, MAX_PATH
);
856 ptr
= PathAddBackslashW (szSrc
);
858 _ILSimpleGetTextW (pidl
, ptr
, MAX_PATH
- (ptr
- szSrc
));
860 /* build destination path */
861 if (dwFlags
== SHGDN_NORMAL
|| dwFlags
& SHGDN_INFOLDER
) {
862 MultiByteToWideChar(CP_ACP
, 0, This
->sPathTarget
, -1, szDest
, MAX_PATH
);
863 ptr
= PathAddBackslashW (szDest
);
865 lstrcpynW(ptr
, lpName
, MAX_PATH
- (ptr
- szDest
));
867 lstrcpynW(szDest
, lpName
, MAX_PATH
);
869 if(!(dwFlags
& SHGDN_FORPARSING
) && SHELL_FS_HideExtension(szSrc
)) {
870 WCHAR
*ext
= PathFindExtensionW(szSrc
);
872 INT len
= strlenW(szDest
);
873 lstrcpynW(szDest
+ len
, ext
, MAX_PATH
- len
);
877 TRACE ("src=%s dest=%s\n", debugstr_w(szSrc
), debugstr_w(szDest
));
879 if (MoveFileW (szSrc
, szDest
)) {
883 hr
= _ILCreateFromPathW(szDest
, pPidlOut
);
885 SHChangeNotify (bIsFolder
? SHCNE_RENAMEFOLDER
: SHCNE_RENAMEITEM
,
886 SHCNF_PATHW
, szSrc
, szDest
);
894 static HRESULT WINAPI
IShellFolder_fnGetDefaultSearchGUID (IShellFolder2
*iface
,
897 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
898 FIXME ("(%p)\n", This
);
901 static HRESULT WINAPI
IShellFolder_fnEnumSearches (IShellFolder2
* iface
,
902 IEnumExtraSearch
** ppenum
)
904 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
905 FIXME ("(%p)\n", This
);
909 static HRESULT WINAPI
910 IShellFolder_fnGetDefaultColumn (IShellFolder2
* iface
, DWORD dwRes
,
911 ULONG
* pSort
, ULONG
* pDisplay
)
913 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
915 TRACE ("(%p)\n", This
);
925 static HRESULT WINAPI
926 IShellFolder_fnGetDefaultColumnState (IShellFolder2
* iface
, UINT iColumn
,
929 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
931 TRACE ("(%p)\n", This
);
933 if (!pcsFlags
|| iColumn
>= GENERICSHELLVIEWCOLUMNS
)
936 *pcsFlags
= GenericSFHeader
[iColumn
].pcsFlags
;
941 static HRESULT WINAPI
942 IShellFolder_fnGetDetailsEx (IShellFolder2
* iface
, LPCITEMIDLIST pidl
,
943 const SHCOLUMNID
* pscid
, VARIANT
* pv
)
945 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
946 FIXME ("(%p)\n", This
);
951 static HRESULT WINAPI
952 IShellFolder_fnGetDetailsOf (IShellFolder2
* iface
, LPCITEMIDLIST pidl
,
953 UINT iColumn
, SHELLDETAILS
* psd
)
955 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
958 TRACE ("(%p)->(%p %i %p)\n", This
, pidl
, iColumn
, psd
);
960 if (!psd
|| iColumn
>= GENERICSHELLVIEWCOLUMNS
)
964 /* the header titles */
965 psd
->fmt
= GenericSFHeader
[iColumn
].fmt
;
966 psd
->cxChar
= GenericSFHeader
[iColumn
].cxChar
;
967 psd
->str
.uType
= STRRET_CSTR
;
968 LoadStringA (shell32_hInstance
, GenericSFHeader
[iColumn
].colnameid
,
969 psd
->str
.u
.cStr
, MAX_PATH
);
972 /* the data from the pidl */
975 hr
= IShellFolder_GetDisplayNameOf (iface
, pidl
,
976 SHGDN_NORMAL
| SHGDN_INFOLDER
, &psd
->str
);
979 _ILGetFileSize (pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
982 _ILGetFileType (pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
985 _ILGetFileDate (pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
987 case 4: /* attributes */
988 _ILGetFileAttributes (pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
992 psd
->str
.uType
= STRRET_CSTR
;
998 static HRESULT WINAPI
999 IShellFolder_fnMapColumnToSCID (IShellFolder2
* iface
, UINT column
,
1002 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
1003 FIXME ("(%p)\n", This
);
1007 static const IShellFolder2Vtbl sfvt
=
1009 IShellFolder_fnQueryInterface
,
1010 IShellFolder_fnAddRef
,
1011 IShellFolder_fnRelease
,
1012 IShellFolder_fnParseDisplayName
,
1013 IShellFolder_fnEnumObjects
,
1014 IShellFolder_fnBindToObject
,
1015 IShellFolder_fnBindToStorage
,
1016 IShellFolder_fnCompareIDs
,
1017 IShellFolder_fnCreateViewObject
,
1018 IShellFolder_fnGetAttributesOf
,
1019 IShellFolder_fnGetUIObjectOf
,
1020 IShellFolder_fnGetDisplayNameOf
,
1021 IShellFolder_fnSetNameOf
,
1023 IShellFolder_fnGetDefaultSearchGUID
,
1024 IShellFolder_fnEnumSearches
,
1025 IShellFolder_fnGetDefaultColumn
,
1026 IShellFolder_fnGetDefaultColumnState
,
1027 IShellFolder_fnGetDetailsEx
,
1028 IShellFolder_fnGetDetailsOf
,
1029 IShellFolder_fnMapColumnToSCID
1032 /****************************************************************************
1033 * ISFHelper for IShellFolder implementation
1036 static HRESULT WINAPI
1037 ISFHelper_fnQueryInterface (ISFHelper
* iface
, REFIID riid
, LPVOID
* ppvObj
)
1039 IGenericSFImpl
*This
= impl_from_ISFHelper(iface
);
1041 TRACE ("(%p)->(count=%lu)\n", This
, This
->ref
);
1043 return IUnknown_QueryInterface (This
->pUnkOuter
, riid
, ppvObj
);
1046 static ULONG WINAPI
ISFHelper_fnAddRef (ISFHelper
* iface
)
1048 IGenericSFImpl
*This
= impl_from_ISFHelper(iface
);
1050 TRACE ("(%p)->(count=%lu)\n", This
, This
->ref
);
1052 return IUnknown_AddRef (This
->pUnkOuter
);
1055 static ULONG WINAPI
ISFHelper_fnRelease (ISFHelper
* iface
)
1057 IGenericSFImpl
*This
= impl_from_ISFHelper(iface
);
1059 TRACE ("(%p)\n", This
);
1061 return IUnknown_Release (This
->pUnkOuter
);
1064 /****************************************************************************
1065 * ISFHelper_fnAddFolder
1067 * creates a unique folder name
1070 static HRESULT WINAPI
1071 ISFHelper_fnGetUniqueName (ISFHelper
* iface
, LPSTR lpName
, UINT uLen
)
1073 IGenericSFImpl
*This
= impl_from_ISFHelper(iface
);
1076 char szText
[MAX_PATH
];
1077 const char *szNewFolder
= "New Folder";
1079 TRACE ("(%p)(%s %u)\n", This
, lpName
, uLen
);
1081 if (uLen
< strlen (szNewFolder
) + 4)
1084 strcpy (lpName
, szNewFolder
);
1086 hr
= IShellFolder_fnEnumObjects (_IShellFolder2_ (This
), 0,
1087 SHCONTF_FOLDERS
| SHCONTF_NONFOLDERS
| SHCONTF_INCLUDEHIDDEN
, &penum
);
1094 IEnumIDList_Reset (penum
);
1095 while (S_OK
== IEnumIDList_Next (penum
, 1, &pidl
, &dwFetched
) &&
1097 _ILSimpleGetText (pidl
, szText
, MAX_PATH
);
1098 if (0 == strcasecmp (szText
, lpName
)) {
1099 sprintf (lpName
, "%s %d", szNewFolder
, i
++);
1108 IEnumIDList_Release (penum
);
1113 /****************************************************************************
1114 * ISFHelper_fnAddFolder
1116 * adds a new folder.
1119 static HRESULT WINAPI
1120 ISFHelper_fnAddFolder (ISFHelper
* iface
, HWND hwnd
, LPCSTR lpName
,
1121 LPITEMIDLIST
* ppidlOut
)
1123 IGenericSFImpl
*This
= impl_from_ISFHelper(iface
);
1124 char lpstrNewDir
[MAX_PATH
];
1126 HRESULT hres
= E_FAIL
;
1128 TRACE ("(%p)(%s %p)\n", This
, lpName
, ppidlOut
);
1130 strcpy (lpstrNewDir
, This
->sPathTarget
);
1131 PathAppendA(lpstrNewDir
, lpName
);
1133 bRes
= CreateDirectoryA (lpstrNewDir
, NULL
);
1135 SHChangeNotify (SHCNE_MKDIR
, SHCNF_PATHA
, lpstrNewDir
, NULL
);
1140 hres
= _ILCreateFromPathA(lpstrNewDir
, ppidlOut
);
1142 char lpstrText
[128 + MAX_PATH
];
1143 char lpstrTempText
[128];
1144 char lpstrCaption
[256];
1146 /* Cannot Create folder because of permissions */
1147 LoadStringA (shell32_hInstance
, IDS_CREATEFOLDER_DENIED
, lpstrTempText
,
1148 sizeof (lpstrTempText
));
1149 LoadStringA (shell32_hInstance
, IDS_CREATEFOLDER_CAPTION
, lpstrCaption
,
1150 sizeof (lpstrCaption
));
1151 sprintf (lpstrText
, lpstrTempText
, lpstrNewDir
);
1152 MessageBoxA (hwnd
, lpstrText
, lpstrCaption
, MB_OK
| MB_ICONEXCLAMATION
);
1158 /****************************************************************************
1159 * ISFHelper_fnDeleteItems
1161 * deletes items in folder
1163 static HRESULT WINAPI
1164 ISFHelper_fnDeleteItems (ISFHelper
* iface
, UINT cidl
, LPCITEMIDLIST
* apidl
)
1166 IGenericSFImpl
*This
= impl_from_ISFHelper(iface
);
1168 char szPath
[MAX_PATH
];
1169 BOOL bConfirm
= TRUE
;
1171 TRACE ("(%p)(%u %p)\n", This
, cidl
, apidl
);
1173 /* deleting multiple items so give a slightly different warning */
1177 snprintf (tmp
, sizeof (tmp
), "%d", cidl
);
1178 if (!SHELL_ConfirmDialog(ASK_DELETE_MULTIPLE_ITEM
, tmp
))
1183 for (i
= 0; i
< cidl
; i
++) {
1184 strcpy (szPath
, This
->sPathTarget
);
1185 PathAddBackslashA (szPath
);
1186 _ILSimpleGetText (apidl
[i
], szPath
+ strlen (szPath
), MAX_PATH
);
1188 if (_ILIsFolder (apidl
[i
])) {
1191 TRACE ("delete %s\n", szPath
);
1192 if (!SHELL_DeleteDirectoryA (szPath
, bConfirm
)) {
1193 TRACE ("delete %s failed, bConfirm=%d\n", szPath
, bConfirm
);
1196 pidl
= ILCombine (This
->pidlRoot
, apidl
[i
]);
1197 SHChangeNotify (SHCNE_RMDIR
, SHCNF_IDLIST
, pidl
, NULL
);
1199 } else if (_ILIsValue (apidl
[i
])) {
1202 TRACE ("delete %s\n", szPath
);
1203 if (!SHELL_DeleteFileA (szPath
, bConfirm
)) {
1204 TRACE ("delete %s failed, bConfirm=%d\n", szPath
, bConfirm
);
1207 pidl
= ILCombine (This
->pidlRoot
, apidl
[i
]);
1208 SHChangeNotify (SHCNE_DELETE
, SHCNF_IDLIST
, pidl
, NULL
);
1216 /****************************************************************************
1217 * ISFHelper_fnCopyItems
1219 * copies items to this folder
1221 static HRESULT WINAPI
1222 ISFHelper_fnCopyItems (ISFHelper
* iface
, IShellFolder
* pSFFrom
, UINT cidl
,
1223 LPCITEMIDLIST
* apidl
)
1226 IPersistFolder2
*ppf2
= NULL
;
1227 char szSrcPath
[MAX_PATH
],
1228 szDstPath
[MAX_PATH
];
1230 IGenericSFImpl
*This
= impl_from_ISFHelper(iface
);
1232 TRACE ("(%p)->(%p,%u,%p)\n", This
, pSFFrom
, cidl
, apidl
);
1234 IShellFolder_QueryInterface (pSFFrom
, &IID_IPersistFolder2
,
1240 if (SUCCEEDED (IPersistFolder2_GetCurFolder (ppf2
, &pidl
)))
1242 for (i
= 0; i
< cidl
; i
++)
1244 SHGetPathFromIDListA (pidl
, szSrcPath
);
1245 PathAddBackslashA (szSrcPath
);
1246 _ILSimpleGetText (apidl
[i
], szSrcPath
+ strlen (szSrcPath
),
1249 strcpy (szDstPath
, This
->sPathTarget
);
1250 PathAddBackslashA (szDstPath
);
1251 _ILSimpleGetText (apidl
[i
], szDstPath
+ strlen (szDstPath
),
1253 DPRINT1 ("copy %s to %s\n", szSrcPath
, szDstPath
);
1258 SHNotifyMoveFileA(szSrcPath
, szDstPath
);
1262 SHNotifyCopyFileA(szSrcPath
, szDstPath
, TRUE
);
1265 /* FIXME: to work with folders we need SHFileOperation!
1279 op.pFrom = szSrcPath;
1280 op.fFlags = FOF_SIMPLEPROGRESS;
1282 op.hNameMappings = NULL;
1283 op.lpszProgressTitle = NULL;
1285 UINT bRes = SHFileOperationA(&op);
1286 DbgPrint("CopyItems SHFileOperationA 0x%08x\n", bRes);
1292 IPersistFolder2_Release (ppf2
);
1297 static const ISFHelperVtbl shvt
=
1299 ISFHelper_fnQueryInterface
,
1301 ISFHelper_fnRelease
,
1302 ISFHelper_fnGetUniqueName
,
1303 ISFHelper_fnAddFolder
,
1304 ISFHelper_fnDeleteItems
,
1305 ISFHelper_fnCopyItems
1308 /************************************************************************
1309 * IFSFldr_PersistFolder3_QueryInterface
1312 static HRESULT WINAPI
1313 IFSFldr_PersistFolder3_QueryInterface (IPersistFolder3
* iface
, REFIID iid
,
1316 IGenericSFImpl
*This
= impl_from_IPersistFolder3(iface
);
1318 TRACE ("(%p)\n", This
);
1320 return IUnknown_QueryInterface (This
->pUnkOuter
, iid
, ppvObj
);
1323 /************************************************************************
1324 * IFSFldr_PersistFolder3_AddRef
1328 IFSFldr_PersistFolder3_AddRef (IPersistFolder3
* iface
)
1330 IGenericSFImpl
*This
= impl_from_IPersistFolder3(iface
);
1332 TRACE ("(%p)->(count=%lu)\n", This
, This
->ref
);
1334 return IUnknown_AddRef (This
->pUnkOuter
);
1337 /************************************************************************
1338 * IFSFldr_PersistFolder3_Release
1342 IFSFldr_PersistFolder3_Release (IPersistFolder3
* iface
)
1344 IGenericSFImpl
*This
= impl_from_IPersistFolder3(iface
);
1346 TRACE ("(%p)->(count=%lu)\n", This
, This
->ref
);
1348 return IUnknown_Release (This
->pUnkOuter
);
1351 /************************************************************************
1352 * IFSFldr_PersistFolder3_GetClassID
1354 static HRESULT WINAPI
1355 IFSFldr_PersistFolder3_GetClassID (IPersistFolder3
* iface
, CLSID
* lpClassId
)
1357 IGenericSFImpl
*This
= impl_from_IPersistFolder3(iface
);
1359 TRACE ("(%p)\n", This
);
1363 *lpClassId
= *This
->pclsid
;
1368 /************************************************************************
1369 * IFSFldr_PersistFolder3_Initialize
1372 * sPathTarget is not set. Don't know how to handle in a non rooted environment.
1374 static HRESULT WINAPI
1375 IFSFldr_PersistFolder3_Initialize (IPersistFolder3
* iface
, LPCITEMIDLIST pidl
)
1377 char sTemp
[MAX_PATH
];
1379 IGenericSFImpl
*This
= impl_from_IPersistFolder3(iface
);
1381 TRACE ("(%p)->(%p)\n", This
, pidl
);
1384 SHFree (This
->pidlRoot
); /* free the old pidl */
1385 This
->pidlRoot
= ILClone (pidl
); /* set my pidl */
1387 if (This
->sPathTarget
)
1388 SHFree (This
->sPathTarget
);
1391 if (SHGetPathFromIDListA (pidl
, sTemp
)) {
1392 This
->sPathTarget
= SHAlloc (strlen (sTemp
) + 1);
1393 strcpy (This
->sPathTarget
, sTemp
);
1396 TRACE ("--(%p)->(%s)\n", This
, This
->sPathTarget
);
1400 /**************************************************************************
1401 * IFSFldr_PersistFolder3_GetCurFolder
1403 static HRESULT WINAPI
1404 IFSFldr_PersistFolder3_fnGetCurFolder (IPersistFolder3
* iface
,
1405 LPITEMIDLIST
* pidl
)
1407 IGenericSFImpl
*This
= impl_from_IPersistFolder3(iface
);
1409 TRACE ("(%p)->(%p)\n", This
, pidl
);
1411 if (!pidl
) return E_POINTER
;
1412 *pidl
= ILClone (This
->pidlRoot
);
1416 /**************************************************************************
1417 * IFSFldr_PersistFolder3_InitializeEx
1419 * FIXME: error handling
1421 static HRESULT WINAPI
1422 IFSFldr_PersistFolder3_InitializeEx (IPersistFolder3
* iface
,
1423 IBindCtx
* pbc
, LPCITEMIDLIST pidlRoot
,
1424 const PERSIST_FOLDER_TARGET_INFO
* ppfti
)
1426 char sTemp
[MAX_PATH
];
1428 IGenericSFImpl
*This
= impl_from_IPersistFolder3(iface
);
1430 TRACE ("(%p)->(%p,%p,%p)\n", This
, pbc
, pidlRoot
, ppfti
);
1432 TRACE ("--%p %s %s 0x%08lx 0x%08x\n",
1433 ppfti
->pidlTargetFolder
, debugstr_w (ppfti
->szTargetParsingName
),
1434 debugstr_w (ppfti
->szNetworkProvider
), ppfti
->dwAttributes
,
1438 if (ppfti
&& ppfti
->pidlTargetFolder
)
1439 pdump (ppfti
->pidlTargetFolder
);
1442 __SHFreeAndNil (&This
->pidlRoot
); /* free the old */
1443 if (This
->sPathTarget
)
1444 __SHFreeAndNil (&This
->sPathTarget
);
1447 * Root path and pidl
1449 This
->pidlRoot
= ILClone (pidlRoot
);
1452 * the target folder is spezified in csidl OR pidlTargetFolder OR
1453 * szTargetParsingName
1456 if (ppfti
->csidl
!= -1) {
1457 if (SHGetSpecialFolderPathA (0, sTemp
, ppfti
->csidl
,
1458 ppfti
->csidl
& CSIDL_FLAG_CREATE
)) {
1459 __SHCloneStrA (&This
->sPathTarget
, sTemp
);
1461 } else if (ppfti
->szTargetParsingName
[0]) {
1462 __SHCloneStrWtoA (&This
->sPathTarget
, ppfti
->szTargetParsingName
);
1463 } else if (ppfti
->pidlTargetFolder
) {
1464 if (SHGetPathFromIDListA (ppfti
->pidlTargetFolder
, sTemp
)) {
1465 __SHCloneStrA (&This
->sPathTarget
, sTemp
);
1470 TRACE ("--(%p)->(target=%s)\n", This
, debugstr_a (This
->sPathTarget
));
1471 pdump (This
->pidlRoot
);
1472 return (This
->sPathTarget
) ? S_OK
: E_FAIL
;
1475 static HRESULT WINAPI
1476 IFSFldr_PersistFolder3_GetFolderTargetInfo (IPersistFolder3
* iface
,
1477 PERSIST_FOLDER_TARGET_INFO
* ppfti
)
1479 IGenericSFImpl
*This
= impl_from_IPersistFolder3(iface
);
1480 FIXME ("(%p)->(%p)\n", This
, ppfti
);
1481 ZeroMemory (ppfti
, sizeof (ppfti
));
1485 static const IPersistFolder3Vtbl vt_FSFldr_PersistFolder3
=
1487 IFSFldr_PersistFolder3_QueryInterface
,
1488 IFSFldr_PersistFolder3_AddRef
,
1489 IFSFldr_PersistFolder3_Release
,
1490 IFSFldr_PersistFolder3_GetClassID
,
1491 IFSFldr_PersistFolder3_Initialize
,
1492 IFSFldr_PersistFolder3_fnGetCurFolder
,
1493 IFSFldr_PersistFolder3_InitializeEx
,
1494 IFSFldr_PersistFolder3_GetFolderTargetInfo
1497 /****************************************************************************
1498 * ISFDropTarget implementation
1501 ISFDropTarget_QueryDrop (IDropTarget
* iface
, DWORD dwKeyState
,
1504 DWORD dwEffect
= *pdwEffect
;
1506 IGenericSFImpl
*This
= impl_from_IDropTarget(iface
);
1508 *pdwEffect
= DROPEFFECT_NONE
;
1510 if (This
->fAcceptFmt
) { /* Does our interpretation of the keystate ... */
1511 *pdwEffect
= KeyStateToDropEffect (dwKeyState
);
1513 /* ... matches the desired effect ? */
1514 if (dwEffect
& *pdwEffect
) {
1521 static HRESULT WINAPI
1522 ISFDropTarget_QueryInterface (IDropTarget
* iface
, REFIID riid
, LPVOID
* ppvObj
)
1524 IGenericSFImpl
*This
= impl_from_IDropTarget(iface
);
1526 TRACE ("(%p)\n", This
);
1528 return IUnknown_QueryInterface (This
->pUnkOuter
, riid
, ppvObj
);
1531 static ULONG WINAPI
ISFDropTarget_AddRef (IDropTarget
* iface
)
1533 IGenericSFImpl
*This
= impl_from_IDropTarget(iface
);
1535 TRACE ("(%p)\n", This
);
1537 return IUnknown_AddRef (This
->pUnkOuter
);
1540 static ULONG WINAPI
ISFDropTarget_Release (IDropTarget
* iface
)
1542 IGenericSFImpl
*This
= impl_from_IDropTarget(iface
);
1544 TRACE ("(%p)\n", This
);
1546 return IUnknown_Release (This
->pUnkOuter
);
1549 static HRESULT WINAPI
1550 ISFDropTarget_DragEnter (IDropTarget
* iface
, IDataObject
* pDataObject
,
1551 DWORD dwKeyState
, POINTL pt
, DWORD
* pdwEffect
)
1555 IGenericSFImpl
*This
= impl_from_IDropTarget(iface
);
1557 TRACE ("(%p)->(DataObject=%p)\n", This
, pDataObject
);
1559 InitFormatEtc (fmt
, This
->cfShellIDList
, TYMED_HGLOBAL
);
1561 This
->fAcceptFmt
= (S_OK
== IDataObject_QueryGetData (pDataObject
, &fmt
)) ?
1564 ISFDropTarget_QueryDrop (iface
, dwKeyState
, pdwEffect
);
1569 static HRESULT WINAPI
1570 ISFDropTarget_DragOver (IDropTarget
* iface
, DWORD dwKeyState
, POINTL pt
,
1573 IGenericSFImpl
*This
= impl_from_IDropTarget(iface
);
1575 TRACE ("(%p)\n", This
);
1578 return E_INVALIDARG
;
1580 ISFDropTarget_QueryDrop (iface
, dwKeyState
, pdwEffect
);
1585 static HRESULT WINAPI
ISFDropTarget_DragLeave (IDropTarget
* iface
)
1587 IGenericSFImpl
*This
= impl_from_IDropTarget(iface
);
1589 TRACE ("(%p)\n", This
);
1591 This
->fAcceptFmt
= FALSE
;
1596 static HRESULT WINAPI
1597 ISFDropTarget_Drop (IDropTarget
* iface
, IDataObject
* pDataObject
,
1598 DWORD dwKeyState
, POINTL pt
, DWORD
* pdwEffect
)
1600 IGenericSFImpl
*This
= impl_from_IDropTarget(iface
);
1602 FIXME ("(%p) object dropped\n", This
);
1607 static const IDropTargetVtbl dtvt
= {
1608 ISFDropTarget_QueryInterface
,
1609 ISFDropTarget_AddRef
,
1610 ISFDropTarget_Release
,
1611 ISFDropTarget_DragEnter
,
1612 ISFDropTarget_DragOver
,
1613 ISFDropTarget_DragLeave
,