3 * Virtual Desktop Folder
5 * Copyright 1997 Marcus Meissner
6 * Copyright 1998, 1999, 2002 Juergen Schmied
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "wine/port.h"
32 #define NONAMELESSUNION
45 #include "undocshell.h"
46 #include "shell32_main.h"
49 #include "shellfolder.h"
50 #include "wine/debug.h"
54 WINE_DEFAULT_DEBUG_CHANNEL (shell
);
56 /* Undocumented functions from shdocvw */
57 extern HRESULT WINAPI
IEParseDisplayNameWithBCW(DWORD codepage
, LPCWSTR lpszDisplayName
, LPBC pbc
, LPITEMIDLIST
*ppidl
);
59 /***********************************************************************
60 * Desktopfolder implementation
64 IShellFolder2 IShellFolder2_iface
;
65 IPersistFolder2 IPersistFolder2_iface
;
68 /* both paths are parsible from the desktop */
69 LPWSTR sPathTarget
; /* complete path to target used for enumeration and ChangeNotify */
70 LPITEMIDLIST pidlRoot
; /* absolute pidl */
72 UINT cfShellIDList
; /* clipboardformat for IDropTarget */
73 BOOL fAcceptFmt
; /* flag for pending Drop */
76 static IDesktopFolderImpl
*cached_sf
;
78 static inline IDesktopFolderImpl
*impl_from_IShellFolder2(IShellFolder2
*iface
)
80 return CONTAINING_RECORD(iface
, IDesktopFolderImpl
, IShellFolder2_iface
);
83 static inline IDesktopFolderImpl
*impl_from_IPersistFolder2( IPersistFolder2
*iface
)
85 return CONTAINING_RECORD(iface
, IDesktopFolderImpl
, IPersistFolder2_iface
);
88 static const shvheader desktop_header
[] = {
89 {IDS_SHV_COLUMN1
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 15},
90 {IDS_SHV_COLUMN2
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 10},
91 {IDS_SHV_COLUMN3
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 10},
92 {IDS_SHV_COLUMN4
, SHCOLSTATE_TYPE_DATE
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 12},
93 {IDS_SHV_COLUMN5
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 5}
96 #define DESKTOPSHELLVIEWCOLUMNS sizeof(desktop_header)/sizeof(shvheader)
98 /**************************************************************************
99 * ISF_Desktop_fnQueryInterface
102 static HRESULT WINAPI
ISF_Desktop_fnQueryInterface(
103 IShellFolder2
* iface
, REFIID riid
, LPVOID
* ppvObj
)
105 IDesktopFolderImpl
*This
= impl_from_IShellFolder2(iface
);
107 TRACE ("(%p)->(%s,%p)\n", This
, shdebugstr_guid (riid
), ppvObj
);
109 if (!ppvObj
) return E_POINTER
;
113 if (IsEqualIID (riid
, &IID_IUnknown
) ||
114 IsEqualIID (riid
, &IID_IShellFolder
) ||
115 IsEqualIID (riid
, &IID_IShellFolder2
))
117 *ppvObj
= &This
->IShellFolder2_iface
;
119 else if (IsEqualIID (riid
, &IID_IPersist
) ||
120 IsEqualIID (riid
, &IID_IPersistFolder
) ||
121 IsEqualIID (riid
, &IID_IPersistFolder2
))
123 *ppvObj
= &This
->IPersistFolder2_iface
;
128 IUnknown_AddRef ((IUnknown
*) (*ppvObj
));
129 TRACE ("-- Interface: (%p)->(%p)\n", ppvObj
, *ppvObj
);
132 TRACE ("-- Interface: E_NOINTERFACE\n");
133 return E_NOINTERFACE
;
136 static ULONG WINAPI
ISF_Desktop_fnAddRef (IShellFolder2
* iface
)
138 return 2; /* non-heap based object */
141 static ULONG WINAPI
ISF_Desktop_fnRelease (IShellFolder2
* iface
)
143 return 1; /* non-heap based object */
146 /**************************************************************************
147 * ISF_Desktop_fnParseDisplayName
150 * "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}" and "" binds
153 static HRESULT WINAPI
ISF_Desktop_fnParseDisplayName (IShellFolder2
* iface
,
154 HWND hwndOwner
, LPBC pbc
, LPOLESTR lpszDisplayName
,
155 DWORD
* pchEaten
, LPITEMIDLIST
* ppidl
, DWORD
* pdwAttributes
)
157 IDesktopFolderImpl
*This
= impl_from_IShellFolder2(iface
);
158 WCHAR szElement
[MAX_PATH
];
159 LPCWSTR szNext
= NULL
;
160 LPITEMIDLIST pidlTemp
= NULL
;
165 TRACE ("(%p)->(HWND=%p,%p,%p=%s,%p,pidl=%p,%p)\n",
166 This
, hwndOwner
, pbc
, lpszDisplayName
, debugstr_w(lpszDisplayName
),
167 pchEaten
, ppidl
, pdwAttributes
);
169 if (!ppidl
) return E_INVALIDARG
;
172 if (!lpszDisplayName
) return E_INVALIDARG
;
175 *pchEaten
= 0; /* strange but like the original */
177 urldata
.cbSize
= sizeof(urldata
);
179 if (lpszDisplayName
[0] == ':' && lpszDisplayName
[1] == ':')
181 szNext
= GetNextElementW (lpszDisplayName
, szElement
, MAX_PATH
);
182 TRACE ("-- element: %s\n", debugstr_w (szElement
));
183 SHCLSIDFromStringW (szElement
+ 2, &clsid
);
184 pidlTemp
= _ILCreateGuid (PT_GUID
, &clsid
);
186 else if (PathGetDriveNumberW (lpszDisplayName
) >= 0)
188 /* it's a filesystem path with a drive. Let MyComputer/UnixDosFolder parse it */
189 if (UNIXFS_is_rooted_at_desktop())
190 pidlTemp
= _ILCreateGuid(PT_GUID
, &CLSID_UnixDosFolder
);
192 pidlTemp
= _ILCreateMyComputer ();
193 szNext
= lpszDisplayName
;
195 else if (PathIsUNCW(lpszDisplayName
))
197 pidlTemp
= _ILCreateNetwork();
198 szNext
= lpszDisplayName
;
200 else if( (pidlTemp
= SHELL32_CreatePidlFromBindCtx(pbc
, lpszDisplayName
)) )
205 else if (SUCCEEDED(ParseURLW(lpszDisplayName
, &urldata
)))
207 if (urldata
.nScheme
== URL_SCHEME_SHELL
) /* handle shell: urls */
209 TRACE ("-- shell url: %s\n", debugstr_w(urldata
.pszSuffix
));
210 SHCLSIDFromStringW (urldata
.pszSuffix
+2, &clsid
);
211 pidlTemp
= _ILCreateGuid (PT_GUID
, &clsid
);
214 return IEParseDisplayNameWithBCW(CP_ACP
,lpszDisplayName
,pbc
,ppidl
);
218 /* it's a filesystem path on the desktop. Let a FSFolder parse it */
220 if (*lpszDisplayName
)
222 if (*lpszDisplayName
== '/')
224 /* UNIX paths should be parsed by unixfs */
225 IShellFolder
*unixFS
;
226 hr
= UnixFolder_Constructor(NULL
, &IID_IShellFolder
, (LPVOID
*)&unixFS
);
229 hr
= IShellFolder_ParseDisplayName(unixFS
, NULL
, NULL
,
230 lpszDisplayName
, NULL
, &pidlTemp
, NULL
);
231 IShellFolder_Release(unixFS
);
236 /* build a complete path to create a simple pidl */
237 WCHAR szPath
[MAX_PATH
];
240 lstrcpynW(szPath
, This
->sPathTarget
, MAX_PATH
);
241 pathPtr
= PathAddBackslashW(szPath
);
244 lstrcpynW(pathPtr
, lpszDisplayName
, MAX_PATH
- (pathPtr
- szPath
));
245 hr
= _ILCreateFromPathW(szPath
, &pidlTemp
);
249 /* should never reach here, but for completeness */
250 hr
= E_NOT_SUFFICIENT_BUFFER
;
255 pidlTemp
= _ILCreateMyComputer();
260 if (SUCCEEDED(hr
) && pidlTemp
)
262 if (szNext
&& *szNext
)
264 hr
= SHELL32_ParseNextElement(iface
, hwndOwner
, pbc
,
265 &pidlTemp
, (LPOLESTR
) szNext
, pchEaten
, pdwAttributes
);
269 if (pdwAttributes
&& *pdwAttributes
)
270 hr
= SHELL32_GetItemAttributes(iface
, pidlTemp
, pdwAttributes
);
276 TRACE ("(%p)->(-- ret=0x%08x)\n", This
, hr
);
281 static void add_shell_namespace_extensions(IEnumIDListImpl
*list
, HKEY root
)
283 static const WCHAR Desktop_NameSpaceW
[] = { 'S','O','F','T','W','A','R','E','\\',
284 'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
285 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
286 'E','x','p','l','o','r','e','r','\\','D','e','s','k','t','o','p','\\',
287 'N','a','m','e','s','p','a','c','e','\0' };
288 static const WCHAR clsidfmtW
[] = {'C','L','S','I','D','\\','%','s','\\',
289 'S','h','e','l','l','F','o','l','d','e','r',0};
290 static const WCHAR attributesW
[] = {'A','t','t','r','i','b','u','t','e','s',0};
291 WCHAR guid
[39], clsidkeyW
[sizeof(clsidfmtW
)/sizeof(*clsidfmtW
) + 39];
295 if (RegOpenKeyExW(root
, Desktop_NameSpaceW
, 0, KEY_READ
, &hkey
))
298 size
= sizeof(guid
)/sizeof(guid
[0]);
299 while (!RegEnumKeyExW(hkey
, i
++, guid
, &size
, 0, NULL
, NULL
, NULL
))
301 DWORD attributes
, value_size
= sizeof(attributes
);
303 /* Check if extension is configured as nonenumerable */
304 sprintfW(clsidkeyW
, clsidfmtW
, guid
);
305 RegGetValueW(HKEY_CLASSES_ROOT
, clsidkeyW
, attributesW
, RRF_RT_REG_DWORD
| RRF_ZEROONFAILURE
,
306 NULL
, &attributes
, &value_size
);
308 if (!(attributes
& SFGAO_NONENUMERATED
))
309 AddToEnumList(list
, _ILCreateGuidFromStrW(guid
));
310 size
= sizeof(guid
)/sizeof(guid
[0]);
316 /**************************************************************************
317 * CreateDesktopEnumList()
319 static BOOL
CreateDesktopEnumList(IEnumIDListImpl
*list
, DWORD dwFlags
)
322 WCHAR szPath
[MAX_PATH
];
324 TRACE("(%p)->(flags=0x%08x)\n", list
, dwFlags
);
326 /* enumerate the root folders */
327 if (dwFlags
& SHCONTF_FOLDERS
)
329 ret
= AddToEnumList(list
, _ILCreateMyComputer());
330 add_shell_namespace_extensions(list
, HKEY_LOCAL_MACHINE
);
331 add_shell_namespace_extensions(list
, HKEY_CURRENT_USER
);
334 /* enumerate the elements in %windir%\desktop */
335 ret
= ret
&& SHGetSpecialFolderPathW(0, szPath
, CSIDL_DESKTOPDIRECTORY
, FALSE
);
336 ret
= ret
&& CreateFolderEnumList(list
, szPath
, dwFlags
);
341 /**************************************************************************
342 * ISF_Desktop_fnEnumObjects
344 static HRESULT WINAPI
ISF_Desktop_fnEnumObjects (IShellFolder2
* iface
,
345 HWND hwndOwner
, DWORD dwFlags
, LPENUMIDLIST
* ppEnumIDList
)
347 IDesktopFolderImpl
*This
= impl_from_IShellFolder2(iface
);
348 IEnumIDListImpl
*list
;
350 TRACE ("(%p)->(HWND=%p flags=0x%08x pplist=%p)\n",
351 This
, hwndOwner
, dwFlags
, ppEnumIDList
);
353 if (!(list
= IEnumIDList_Constructor()))
354 return E_OUTOFMEMORY
;
355 CreateDesktopEnumList(list
, dwFlags
);
356 *ppEnumIDList
= &list
->IEnumIDList_iface
;
358 TRACE ("-- (%p)->(new ID List: %p)\n", This
, *ppEnumIDList
);
363 /**************************************************************************
364 * ISF_Desktop_fnBindToObject
366 static HRESULT WINAPI
ISF_Desktop_fnBindToObject (IShellFolder2
* iface
,
367 LPCITEMIDLIST pidl
, LPBC pbcReserved
, REFIID riid
, LPVOID
* ppvOut
)
369 IDesktopFolderImpl
*This
= impl_from_IShellFolder2(iface
);
371 TRACE ("(%p)->(pidl=%p,%p,%s,%p)\n",
372 This
, pidl
, pbcReserved
, shdebugstr_guid (riid
), ppvOut
);
374 return SHELL32_BindToChild( This
->pidlRoot
, This
->sPathTarget
, pidl
, riid
, ppvOut
);
377 /**************************************************************************
378 * ISF_Desktop_fnBindToStorage
380 static HRESULT WINAPI
ISF_Desktop_fnBindToStorage (IShellFolder2
* iface
,
381 LPCITEMIDLIST pidl
, LPBC pbcReserved
, REFIID riid
, LPVOID
* ppvOut
)
383 IDesktopFolderImpl
*This
= impl_from_IShellFolder2(iface
);
385 FIXME ("(%p)->(pidl=%p,%p,%s,%p) stub\n",
386 This
, pidl
, pbcReserved
, shdebugstr_guid (riid
), ppvOut
);
392 /**************************************************************************
393 * ISF_Desktop_fnCompareIDs
395 static HRESULT WINAPI
ISF_Desktop_fnCompareIDs (IShellFolder2
*iface
,
396 LPARAM lParam
, LPCITEMIDLIST pidl1
, LPCITEMIDLIST pidl2
)
398 IDesktopFolderImpl
*This
= impl_from_IShellFolder2(iface
);
401 TRACE ("(%p)->(0x%08lx,pidl1=%p,pidl2=%p)\n", This
, lParam
, pidl1
, pidl2
);
402 hr
= SHELL32_CompareIDs(iface
, lParam
, pidl1
, pidl2
);
403 TRACE ("-- 0x%08x\n", hr
);
407 /**************************************************************************
408 * ISF_Desktop_fnCreateViewObject
410 static HRESULT WINAPI
ISF_Desktop_fnCreateViewObject (IShellFolder2
* iface
,
411 HWND hwndOwner
, REFIID riid
, LPVOID
* ppvOut
)
413 IDesktopFolderImpl
*This
= impl_from_IShellFolder2(iface
);
414 LPSHELLVIEW pShellView
;
415 HRESULT hr
= E_INVALIDARG
;
417 TRACE ("(%p)->(hwnd=%p,%s,%p)\n",
418 This
, hwndOwner
, shdebugstr_guid (riid
), ppvOut
);
425 if (IsEqualIID (riid
, &IID_IDropTarget
))
427 WARN ("IDropTarget not implemented\n");
430 else if (IsEqualIID (riid
, &IID_IContextMenu
))
432 WARN ("IContextMenu not implemented\n");
435 else if (IsEqualIID (riid
, &IID_IShellView
))
437 pShellView
= IShellView_Constructor ((IShellFolder
*) iface
);
440 hr
= IShellView_QueryInterface (pShellView
, riid
, ppvOut
);
441 IShellView_Release (pShellView
);
444 TRACE ("-- (%p)->(interface=%p)\n", This
, ppvOut
);
448 /**************************************************************************
449 * ISF_Desktop_fnGetAttributesOf
451 static HRESULT WINAPI
ISF_Desktop_fnGetAttributesOf (IShellFolder2
* iface
,
452 UINT cidl
, LPCITEMIDLIST
* apidl
, DWORD
* rgfInOut
)
454 IDesktopFolderImpl
*This
= impl_from_IShellFolder2(iface
);
456 static const DWORD dwDesktopAttributes
=
457 SFGAO_STORAGE
| SFGAO_HASPROPSHEET
| SFGAO_STORAGEANCESTOR
|
458 SFGAO_FILESYSANCESTOR
| SFGAO_FOLDER
| SFGAO_FILESYSTEM
| SFGAO_HASSUBFOLDER
;
459 static const DWORD dwMyComputerAttributes
=
460 SFGAO_CANRENAME
| SFGAO_CANDELETE
| SFGAO_HASPROPSHEET
|
461 SFGAO_DROPTARGET
| SFGAO_FILESYSANCESTOR
| SFGAO_FOLDER
| SFGAO_HASSUBFOLDER
;
463 TRACE ("(%p)->(cidl=%d apidl=%p mask=%p (0x%08x))\n",
464 This
, cidl
, apidl
, rgfInOut
, rgfInOut
? *rgfInOut
: 0);
475 *rgfInOut
&= dwDesktopAttributes
;
477 while (cidl
> 0 && *apidl
) {
479 if (_ILIsDesktop(*apidl
)) {
480 *rgfInOut
&= dwDesktopAttributes
;
481 } else if (_ILIsMyComputer(*apidl
)) {
482 *rgfInOut
&= dwMyComputerAttributes
;
484 SHELL32_GetItemAttributes(iface
, *apidl
, rgfInOut
);
490 /* make sure SFGAO_VALIDATE is cleared, some apps depend on that */
491 *rgfInOut
&= ~SFGAO_VALIDATE
;
493 TRACE ("-- result=0x%08x\n", *rgfInOut
);
498 /**************************************************************************
499 * ISF_Desktop_fnGetUIObjectOf
502 * HWND hwndOwner, //[in ] Parent window for any output
503 * UINT cidl, //[in ] array size
504 * LPCITEMIDLIST* apidl, //[in ] simple pidl array
505 * REFIID riid, //[in ] Requested Interface
506 * UINT* prgfInOut, //[ ] reserved
507 * LPVOID* ppvObject) //[out] Resulting Interface
510 static HRESULT WINAPI
ISF_Desktop_fnGetUIObjectOf (IShellFolder2
* iface
,
511 HWND hwndOwner
, UINT cidl
, LPCITEMIDLIST
* apidl
,
512 REFIID riid
, UINT
* prgfInOut
, LPVOID
* ppvOut
)
514 IDesktopFolderImpl
*This
= impl_from_IShellFolder2(iface
);
517 IUnknown
*pObj
= NULL
;
518 HRESULT hr
= E_INVALIDARG
;
520 TRACE ("(%p)->(%p,%u,apidl=%p,%s,%p,%p)\n",
521 This
, hwndOwner
, cidl
, apidl
, shdebugstr_guid (riid
), prgfInOut
, ppvOut
);
528 if (IsEqualIID (riid
, &IID_IContextMenu
))
531 return ItemMenu_Constructor((IShellFolder
*)iface
, This
->pidlRoot
, apidl
, cidl
, riid
, ppvOut
);
533 return BackgroundMenu_Constructor((IShellFolder
*)iface
, TRUE
, riid
, ppvOut
);
535 else if (IsEqualIID (riid
, &IID_IDataObject
) && (cidl
>= 1))
537 pObj
= (LPUNKNOWN
) IDataObject_Constructor( hwndOwner
,
538 This
->pidlRoot
, apidl
, cidl
);
541 else if (IsEqualIID (riid
, &IID_IExtractIconA
) && (cidl
== 1))
543 pidl
= ILCombine (This
->pidlRoot
, apidl
[0]);
544 pObj
= (LPUNKNOWN
) IExtractIconA_Constructor (pidl
);
548 else if (IsEqualIID (riid
, &IID_IExtractIconW
) && (cidl
== 1))
550 pidl
= ILCombine (This
->pidlRoot
, apidl
[0]);
551 pObj
= (LPUNKNOWN
) IExtractIconW_Constructor (pidl
);
555 else if (IsEqualIID (riid
, &IID_IDropTarget
) && (cidl
>= 1))
557 hr
= IShellFolder2_QueryInterface (iface
,
558 &IID_IDropTarget
, (LPVOID
*) & pObj
);
560 else if ((IsEqualIID(riid
,&IID_IShellLinkW
) ||
561 IsEqualIID(riid
,&IID_IShellLinkA
)) && (cidl
== 1))
563 pidl
= ILCombine (This
->pidlRoot
, apidl
[0]);
564 hr
= IShellLink_ConstructFromFile(NULL
, riid
, pidl
, &pObj
);
570 if (SUCCEEDED(hr
) && !pObj
)
574 TRACE ("(%p)->hr=0x%08x\n", This
, hr
);
578 /**************************************************************************
579 * ISF_Desktop_fnGetDisplayNameOf
582 * special case: pidl = null gives desktop-name back
584 static HRESULT WINAPI
ISF_Desktop_fnGetDisplayNameOf (IShellFolder2
* iface
,
585 LPCITEMIDLIST pidl
, DWORD dwFlags
, LPSTRRET strRet
)
587 IDesktopFolderImpl
*This
= impl_from_IShellFolder2(iface
);
591 TRACE ("(%p)->(pidl=%p,0x%08x,%p)\n", This
, pidl
, dwFlags
, strRet
);
597 pszPath
= CoTaskMemAlloc((MAX_PATH
+1) * sizeof(WCHAR
));
599 return E_OUTOFMEMORY
;
601 if (_ILIsDesktop (pidl
))
603 if ((GET_SHGDN_RELATION (dwFlags
) == SHGDN_NORMAL
) &&
604 (GET_SHGDN_FOR (dwFlags
) & SHGDN_FORPARSING
))
605 strcpyW(pszPath
, This
->sPathTarget
);
607 HCR_GetClassNameW(&CLSID_ShellDesktop
, pszPath
, MAX_PATH
);
609 else if (_ILIsPidlSimple (pidl
))
613 if ((clsid
= _ILGetGUIDPointer (pidl
)))
615 if (GET_SHGDN_FOR (dwFlags
) & SHGDN_FORPARSING
)
617 BOOL bWantsForParsing
;
620 * We can only get a filesystem path from a shellfolder if the
621 * value WantsFORPARSING in CLSID\\{...}\\shellfolder exists.
623 * Exception: The MyComputer folder doesn't have this key,
624 * but any other filesystem backed folder it needs it.
626 if (IsEqualIID (clsid
, &CLSID_MyComputer
))
628 bWantsForParsing
= TRUE
;
632 /* get the "WantsFORPARSING" flag from the registry */
633 static const WCHAR clsidW
[] =
634 { 'C','L','S','I','D','\\',0 };
635 static const WCHAR shellfolderW
[] =
636 { '\\','s','h','e','l','l','f','o','l','d','e','r',0 };
637 static const WCHAR wantsForParsingW
[] =
638 { 'W','a','n','t','s','F','o','r','P','a','r','s','i','n',
640 WCHAR szRegPath
[100];
643 lstrcpyW (szRegPath
, clsidW
);
644 SHELL32_GUIDToStringW (clsid
, &szRegPath
[6]);
645 lstrcatW (szRegPath
, shellfolderW
);
646 r
= SHGetValueW(HKEY_CLASSES_ROOT
, szRegPath
,
647 wantsForParsingW
, NULL
, NULL
, NULL
);
648 if (r
== ERROR_SUCCESS
)
649 bWantsForParsing
= TRUE
;
651 bWantsForParsing
= FALSE
;
654 if ((GET_SHGDN_RELATION (dwFlags
) == SHGDN_NORMAL
) &&
658 * we need the filesystem path to the destination folder.
659 * Only the folder itself can know it
661 hr
= SHELL32_GetDisplayNameOfChild (iface
, pidl
, dwFlags
,
667 /* parsing name like ::{...} */
670 SHELL32_GUIDToStringW (clsid
, &pszPath
[2]);
675 /* user friendly name */
676 HCR_GetClassNameW (clsid
, pszPath
, MAX_PATH
);
683 /* file system folder or file rooted at the desktop */
684 if ((GET_SHGDN_FOR(dwFlags
) == SHGDN_FORPARSING
) &&
685 (GET_SHGDN_RELATION(dwFlags
) != SHGDN_INFOLDER
))
687 lstrcpynW(pszPath
, This
->sPathTarget
, MAX_PATH
- 1);
688 PathAddBackslashW(pszPath
);
689 cLen
= lstrlenW(pszPath
);
692 _ILSimpleGetTextW(pidl
, pszPath
+ cLen
, MAX_PATH
- cLen
);
694 if (!_ILIsFolder(pidl
))
695 SHELL_FS_ProcessDisplayFilename(pszPath
, dwFlags
);
700 /* a complex pidl, let the subfolder do the work */
701 hr
= SHELL32_GetDisplayNameOfChild (iface
, pidl
, dwFlags
,
707 /* Win9x always returns ANSI strings, NT always returns Unicode strings */
708 if (GetVersion() & 0x80000000)
710 strRet
->uType
= STRRET_CSTR
;
711 if (!WideCharToMultiByte(CP_ACP
, 0, pszPath
, -1, strRet
->u
.cStr
, MAX_PATH
,
713 strRet
->u
.cStr
[0] = '\0';
714 CoTaskMemFree(pszPath
);
718 strRet
->uType
= STRRET_WSTR
;
719 strRet
->u
.pOleStr
= pszPath
;
723 CoTaskMemFree(pszPath
);
725 TRACE ("-- (%p)->(%s,0x%08x)\n", This
,
726 strRet
->uType
== STRRET_CSTR
? strRet
->u
.cStr
:
727 debugstr_w(strRet
->u
.pOleStr
), hr
);
731 /**************************************************************************
732 * ISF_Desktop_fnSetNameOf
733 * Changes the name of a file object or subfolder, possibly changing its item
734 * identifier in the process.
737 * HWND hwndOwner, //[in ] Owner window for output
738 * LPCITEMIDLIST pidl, //[in ] simple pidl of item to change
739 * LPCOLESTR lpszName, //[in ] the items new display name
740 * DWORD dwFlags, //[in ] SHGNO formatting flags
741 * LPITEMIDLIST* ppidlOut) //[out] simple pidl returned
743 static HRESULT WINAPI
ISF_Desktop_fnSetNameOf (IShellFolder2
* iface
,
744 HWND hwndOwner
, LPCITEMIDLIST pidl
, /* simple pidl */
745 LPCOLESTR lpName
, DWORD dwFlags
, LPITEMIDLIST
* pPidlOut
)
747 IDesktopFolderImpl
*This
= impl_from_IShellFolder2(iface
);
749 FIXME ("(%p)->(%p,pidl=%p,%s,%u,%p) stub\n", This
, hwndOwner
, pidl
,
750 debugstr_w (lpName
), dwFlags
, pPidlOut
);
755 static HRESULT WINAPI
ISF_Desktop_fnGetDefaultSearchGUID(IShellFolder2
*iface
,
758 IDesktopFolderImpl
*This
= impl_from_IShellFolder2(iface
);
759 FIXME ("(%p)->(%p) stub\n", This
, pguid
);
763 static HRESULT WINAPI
ISF_Desktop_fnEnumSearches (IShellFolder2
*iface
,
764 IEnumExtraSearch
** ppenum
)
766 IDesktopFolderImpl
*This
= impl_from_IShellFolder2(iface
);
767 FIXME ("(%p)->(%p) stub\n", This
, ppenum
);
771 static HRESULT WINAPI
ISF_Desktop_fnGetDefaultColumn (IShellFolder2
* iface
,
772 DWORD reserved
, ULONG
* pSort
, ULONG
* pDisplay
)
774 IDesktopFolderImpl
*This
= impl_from_IShellFolder2(iface
);
776 TRACE ("(%p)->(%d %p %p)\n", This
, reserved
, pSort
, pDisplay
);
785 static HRESULT WINAPI
ISF_Desktop_fnGetDefaultColumnState (
786 IShellFolder2
* iface
, UINT iColumn
, DWORD
* pcsFlags
)
788 IDesktopFolderImpl
*This
= impl_from_IShellFolder2(iface
);
790 TRACE ("(%p)->(%d %p)\n", This
, iColumn
, pcsFlags
);
792 if (!pcsFlags
|| iColumn
>= DESKTOPSHELLVIEWCOLUMNS
)
795 *pcsFlags
= desktop_header
[iColumn
].pcsFlags
;
800 static HRESULT WINAPI
ISF_Desktop_fnGetDetailsEx (IShellFolder2
* iface
,
801 LPCITEMIDLIST pidl
, const SHCOLUMNID
* pscid
, VARIANT
* pv
)
803 IDesktopFolderImpl
*This
= impl_from_IShellFolder2(iface
);
804 FIXME ("(%p)->(%p %p %p) stub\n", This
, pidl
, pscid
, pv
);
808 static HRESULT WINAPI
ISF_Desktop_fnGetDetailsOf (IShellFolder2
* iface
,
809 LPCITEMIDLIST pidl
, UINT iColumn
, SHELLDETAILS
* psd
)
811 IDesktopFolderImpl
*This
= impl_from_IShellFolder2(iface
);
815 TRACE ("(%p)->(%p %i %p)\n", This
, pidl
, iColumn
, psd
);
817 if (!psd
|| iColumn
>= DESKTOPSHELLVIEWCOLUMNS
)
821 return SHELL32_GetColumnDetails(desktop_header
, iColumn
, psd
);
823 /* the data from the pidl */
824 psd
->str
.uType
= STRRET_CSTR
;
828 hr
= IShellFolder2_GetDisplayNameOf(iface
, pidl
,
829 SHGDN_NORMAL
| SHGDN_INFOLDER
, &psd
->str
);
832 _ILGetFileSize (pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
835 _ILGetFileType (pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
838 _ILGetFileDate (pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
840 case 4: /* attributes */
841 _ILGetFileAttributes (pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
848 static HRESULT WINAPI
ISF_Desktop_fnMapColumnToSCID (
849 IShellFolder2
* iface
, UINT column
, SHCOLUMNID
* pscid
)
851 IDesktopFolderImpl
*This
= impl_from_IShellFolder2(iface
);
852 FIXME ("(%p)->(%d %p) stub\n", This
, column
, pscid
);
856 static const IShellFolder2Vtbl vt_MCFldr_ShellFolder2
=
858 ISF_Desktop_fnQueryInterface
,
859 ISF_Desktop_fnAddRef
,
860 ISF_Desktop_fnRelease
,
861 ISF_Desktop_fnParseDisplayName
,
862 ISF_Desktop_fnEnumObjects
,
863 ISF_Desktop_fnBindToObject
,
864 ISF_Desktop_fnBindToStorage
,
865 ISF_Desktop_fnCompareIDs
,
866 ISF_Desktop_fnCreateViewObject
,
867 ISF_Desktop_fnGetAttributesOf
,
868 ISF_Desktop_fnGetUIObjectOf
,
869 ISF_Desktop_fnGetDisplayNameOf
,
870 ISF_Desktop_fnSetNameOf
,
872 ISF_Desktop_fnGetDefaultSearchGUID
,
873 ISF_Desktop_fnEnumSearches
,
874 ISF_Desktop_fnGetDefaultColumn
,
875 ISF_Desktop_fnGetDefaultColumnState
,
876 ISF_Desktop_fnGetDetailsEx
,
877 ISF_Desktop_fnGetDetailsOf
,
878 ISF_Desktop_fnMapColumnToSCID
881 /**************************************************************************
884 static HRESULT WINAPI
ISF_Desktop_IPersistFolder2_fnQueryInterface(
885 IPersistFolder2
*iface
, REFIID riid
, LPVOID
*ppvObj
)
887 IDesktopFolderImpl
*This
= impl_from_IPersistFolder2( iface
);
888 return IShellFolder2_QueryInterface(&This
->IShellFolder2_iface
, riid
, ppvObj
);
891 static ULONG WINAPI
ISF_Desktop_IPersistFolder2_fnAddRef(
892 IPersistFolder2
*iface
)
894 IDesktopFolderImpl
*This
= impl_from_IPersistFolder2( iface
);
895 return IShellFolder2_AddRef(&This
->IShellFolder2_iface
);
898 static ULONG WINAPI
ISF_Desktop_IPersistFolder2_fnRelease(
899 IPersistFolder2
*iface
)
901 IDesktopFolderImpl
*This
= impl_from_IPersistFolder2( iface
);
902 return IShellFolder2_Release(&This
->IShellFolder2_iface
);
905 static HRESULT WINAPI
ISF_Desktop_IPersistFolder2_fnGetClassID(
906 IPersistFolder2
*iface
, CLSID
*clsid
)
908 *clsid
= CLSID_ShellDesktop
;
911 static HRESULT WINAPI
ISF_Desktop_IPersistFolder2_fnInitialize(
912 IPersistFolder2
*iface
, LPCITEMIDLIST pidl
)
914 IDesktopFolderImpl
*This
= impl_from_IPersistFolder2( iface
);
915 FIXME ("(%p)->(%p) stub\n", This
, pidl
);
918 static HRESULT WINAPI
ISF_Desktop_IPersistFolder2_fnGetCurFolder(
919 IPersistFolder2
*iface
, LPITEMIDLIST
*ppidl
)
921 IDesktopFolderImpl
*This
= impl_from_IPersistFolder2( iface
);
922 *ppidl
= ILClone(This
->pidlRoot
);
926 static const IPersistFolder2Vtbl vt_IPersistFolder2
=
928 ISF_Desktop_IPersistFolder2_fnQueryInterface
,
929 ISF_Desktop_IPersistFolder2_fnAddRef
,
930 ISF_Desktop_IPersistFolder2_fnRelease
,
931 ISF_Desktop_IPersistFolder2_fnGetClassID
,
932 ISF_Desktop_IPersistFolder2_fnInitialize
,
933 ISF_Desktop_IPersistFolder2_fnGetCurFolder
936 void release_desktop_folder(void)
938 if (!cached_sf
) return;
939 SHFree(cached_sf
->pidlRoot
);
940 SHFree(cached_sf
->sPathTarget
);
941 LocalFree(cached_sf
);
944 /**************************************************************************
945 * ISF_Desktop_Constructor
947 HRESULT WINAPI
ISF_Desktop_Constructor (
948 IUnknown
* pUnkOuter
, REFIID riid
, LPVOID
* ppv
)
950 WCHAR szMyPath
[MAX_PATH
];
952 TRACE ("unkOut=%p %s\n", pUnkOuter
, shdebugstr_guid (riid
));
957 return CLASS_E_NOAGGREGATION
;
961 IDesktopFolderImpl
*sf
;
963 if (!SHGetSpecialFolderPathW( 0, szMyPath
, CSIDL_DESKTOPDIRECTORY
, TRUE
))
966 sf
= LocalAlloc( LMEM_ZEROINIT
, sizeof (IDesktopFolderImpl
) );
968 return E_OUTOFMEMORY
;
971 sf
->IShellFolder2_iface
.lpVtbl
= &vt_MCFldr_ShellFolder2
;
972 sf
->IPersistFolder2_iface
.lpVtbl
= &vt_IPersistFolder2
;
973 sf
->pidlRoot
= _ILCreateDesktop(); /* my qualified pidl */
974 sf
->sPathTarget
= SHAlloc( (lstrlenW(szMyPath
) + 1)*sizeof(WCHAR
) );
975 lstrcpyW( sf
->sPathTarget
, szMyPath
);
977 if (InterlockedCompareExchangePointer((void *)&cached_sf
, sf
, NULL
) != NULL
)
979 /* some other thread already been here */
980 SHFree( sf
->pidlRoot
);
981 SHFree( sf
->sPathTarget
);
986 return IShellFolder2_QueryInterface( &cached_sf
->IShellFolder2_iface
, riid
, ppv
);