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
[] =
90 { &FMTID_Storage
, PID_STG_NAME
, IDS_SHV_COLUMN1
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 15 },
91 { &FMTID_Storage
, PID_STG_SIZE
, IDS_SHV_COLUMN2
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 10 },
92 { &FMTID_Storage
, PID_STG_STORAGETYPE
, IDS_SHV_COLUMN3
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 10 },
93 { &FMTID_Storage
, PID_STG_WRITETIME
, IDS_SHV_COLUMN4
, SHCOLSTATE_TYPE_DATE
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 12 },
94 { &FMTID_Storage
, PID_STG_ATTRIBUTES
, IDS_SHV_COLUMN5
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 5 },
97 /**************************************************************************
98 * ISF_Desktop_fnQueryInterface
101 static HRESULT WINAPI
ISF_Desktop_fnQueryInterface(
102 IShellFolder2
* iface
, REFIID riid
, LPVOID
* ppvObj
)
104 IDesktopFolderImpl
*This
= impl_from_IShellFolder2(iface
);
106 TRACE ("(%p)->(%s,%p)\n", This
, shdebugstr_guid (riid
), ppvObj
);
108 if (!ppvObj
) return E_POINTER
;
112 if (IsEqualIID (riid
, &IID_IUnknown
) ||
113 IsEqualIID (riid
, &IID_IShellFolder
) ||
114 IsEqualIID (riid
, &IID_IShellFolder2
))
116 *ppvObj
= &This
->IShellFolder2_iface
;
118 else if (IsEqualIID (riid
, &IID_IPersist
) ||
119 IsEqualIID (riid
, &IID_IPersistFolder
) ||
120 IsEqualIID (riid
, &IID_IPersistFolder2
))
122 *ppvObj
= &This
->IPersistFolder2_iface
;
127 IUnknown_AddRef ((IUnknown
*) (*ppvObj
));
128 TRACE ("-- Interface: (%p)->(%p)\n", ppvObj
, *ppvObj
);
131 TRACE ("-- Interface: E_NOINTERFACE\n");
132 return E_NOINTERFACE
;
135 static ULONG WINAPI
ISF_Desktop_fnAddRef (IShellFolder2
* iface
)
137 return 2; /* non-heap based object */
140 static ULONG WINAPI
ISF_Desktop_fnRelease (IShellFolder2
* iface
)
142 return 1; /* non-heap based object */
145 /**************************************************************************
146 * ISF_Desktop_fnParseDisplayName
149 * "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}" and "" binds
152 static HRESULT WINAPI
ISF_Desktop_fnParseDisplayName (IShellFolder2
* iface
,
153 HWND hwndOwner
, LPBC pbc
, LPOLESTR lpszDisplayName
,
154 DWORD
* pchEaten
, LPITEMIDLIST
* ppidl
, DWORD
* pdwAttributes
)
156 IDesktopFolderImpl
*This
= impl_from_IShellFolder2(iface
);
157 WCHAR szElement
[MAX_PATH
];
158 LPCWSTR szNext
= NULL
;
159 LPITEMIDLIST pidlTemp
= NULL
;
164 TRACE ("(%p)->(HWND=%p,%p,%p=%s,%p,pidl=%p,%p)\n",
165 This
, hwndOwner
, pbc
, lpszDisplayName
, debugstr_w(lpszDisplayName
),
166 pchEaten
, ppidl
, pdwAttributes
);
168 if (!ppidl
) return E_INVALIDARG
;
171 if (!lpszDisplayName
) return E_INVALIDARG
;
174 *pchEaten
= 0; /* strange but like the original */
176 urldata
.cbSize
= sizeof(urldata
);
178 if (lpszDisplayName
[0] == ':' && lpszDisplayName
[1] == ':')
180 szNext
= GetNextElementW (lpszDisplayName
, szElement
, MAX_PATH
);
181 TRACE ("-- element: %s\n", debugstr_w (szElement
));
182 SHCLSIDFromStringW (szElement
+ 2, &clsid
);
183 pidlTemp
= _ILCreateGuid (PT_GUID
, &clsid
);
185 else if (PathGetDriveNumberW (lpszDisplayName
) >= 0)
187 /* it's a filesystem path with a drive. Let MyComputer/UnixDosFolder parse it */
188 if (UNIXFS_is_rooted_at_desktop())
189 pidlTemp
= _ILCreateGuid(PT_GUID
, &CLSID_UnixDosFolder
);
191 pidlTemp
= _ILCreateMyComputer ();
192 szNext
= lpszDisplayName
;
194 else if (PathIsUNCW(lpszDisplayName
))
196 pidlTemp
= _ILCreateNetwork();
197 szNext
= lpszDisplayName
;
199 else if( (pidlTemp
= SHELL32_CreatePidlFromBindCtx(pbc
, lpszDisplayName
)) )
204 else if (SUCCEEDED(ParseURLW(lpszDisplayName
, &urldata
)))
206 if (urldata
.nScheme
== URL_SCHEME_SHELL
) /* handle shell: urls */
208 TRACE ("-- shell url: %s\n", debugstr_w(urldata
.pszSuffix
));
209 SHCLSIDFromStringW (urldata
.pszSuffix
+2, &clsid
);
210 pidlTemp
= _ILCreateGuid (PT_GUID
, &clsid
);
213 return IEParseDisplayNameWithBCW(CP_ACP
,lpszDisplayName
,pbc
,ppidl
);
217 /* it's a filesystem path on the desktop. Let a FSFolder parse it */
219 if (*lpszDisplayName
)
221 if (*lpszDisplayName
== '/')
223 /* UNIX paths should be parsed by unixfs */
224 IShellFolder
*unixFS
;
225 hr
= UnixFolder_Constructor(NULL
, &IID_IShellFolder
, (LPVOID
*)&unixFS
);
228 hr
= IShellFolder_ParseDisplayName(unixFS
, NULL
, NULL
,
229 lpszDisplayName
, NULL
, &pidlTemp
, NULL
);
230 IShellFolder_Release(unixFS
);
235 /* build a complete path to create a simple pidl */
236 WCHAR szPath
[MAX_PATH
];
239 lstrcpynW(szPath
, This
->sPathTarget
, MAX_PATH
);
240 pathPtr
= PathAddBackslashW(szPath
);
243 lstrcpynW(pathPtr
, lpszDisplayName
, MAX_PATH
- (pathPtr
- szPath
));
244 hr
= _ILCreateFromPathW(szPath
, &pidlTemp
);
248 /* should never reach here, but for completeness */
249 hr
= E_NOT_SUFFICIENT_BUFFER
;
254 pidlTemp
= _ILCreateMyComputer();
259 if (SUCCEEDED(hr
) && pidlTemp
)
261 if (szNext
&& *szNext
)
263 hr
= SHELL32_ParseNextElement(iface
, hwndOwner
, pbc
,
264 &pidlTemp
, (LPOLESTR
) szNext
, pchEaten
, pdwAttributes
);
268 if (pdwAttributes
&& *pdwAttributes
)
269 hr
= SHELL32_GetItemAttributes(iface
, pidlTemp
, pdwAttributes
);
275 TRACE ("(%p)->(-- ret=0x%08x)\n", This
, hr
);
280 static void add_shell_namespace_extensions(IEnumIDListImpl
*list
, HKEY root
)
282 static const WCHAR Desktop_NameSpaceW
[] = { 'S','O','F','T','W','A','R','E','\\',
283 'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
284 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
285 'E','x','p','l','o','r','e','r','\\','D','e','s','k','t','o','p','\\',
286 'N','a','m','e','s','p','a','c','e','\0' };
287 static const WCHAR clsidfmtW
[] = {'C','L','S','I','D','\\','%','s','\\',
288 'S','h','e','l','l','F','o','l','d','e','r',0};
289 static const WCHAR attributesW
[] = {'A','t','t','r','i','b','u','t','e','s',0};
290 WCHAR guid
[39], clsidkeyW
[ARRAY_SIZE(clsidfmtW
) + 39];
294 if (RegOpenKeyExW(root
, Desktop_NameSpaceW
, 0, KEY_READ
, &hkey
))
297 size
= ARRAY_SIZE(guid
);
298 while (!RegEnumKeyExW(hkey
, i
++, guid
, &size
, 0, NULL
, NULL
, NULL
))
300 DWORD attributes
, value_size
= sizeof(attributes
);
302 /* Check if extension is configured as nonenumerable */
303 sprintfW(clsidkeyW
, clsidfmtW
, guid
);
304 RegGetValueW(HKEY_CLASSES_ROOT
, clsidkeyW
, attributesW
, RRF_RT_REG_DWORD
| RRF_ZEROONFAILURE
,
305 NULL
, &attributes
, &value_size
);
307 if (!(attributes
& SFGAO_NONENUMERATED
))
308 AddToEnumList(list
, _ILCreateGuidFromStrW(guid
));
309 size
= ARRAY_SIZE(guid
);
315 /**************************************************************************
316 * CreateDesktopEnumList()
318 static BOOL
CreateDesktopEnumList(IEnumIDListImpl
*list
, DWORD dwFlags
)
321 WCHAR szPath
[MAX_PATH
];
323 TRACE("(%p)->(flags=0x%08x)\n", list
, dwFlags
);
325 /* enumerate the root folders */
326 if (dwFlags
& SHCONTF_FOLDERS
)
328 ret
= AddToEnumList(list
, _ILCreateMyComputer());
329 add_shell_namespace_extensions(list
, HKEY_LOCAL_MACHINE
);
330 add_shell_namespace_extensions(list
, HKEY_CURRENT_USER
);
333 /* enumerate the elements in %windir%\desktop */
334 ret
= ret
&& SHGetSpecialFolderPathW(0, szPath
, CSIDL_DESKTOPDIRECTORY
, FALSE
);
335 ret
= ret
&& CreateFolderEnumList(list
, szPath
, dwFlags
);
340 /**************************************************************************
341 * ISF_Desktop_fnEnumObjects
343 static HRESULT WINAPI
ISF_Desktop_fnEnumObjects (IShellFolder2
* iface
,
344 HWND hwndOwner
, DWORD dwFlags
, LPENUMIDLIST
* ppEnumIDList
)
346 IDesktopFolderImpl
*This
= impl_from_IShellFolder2(iface
);
347 IEnumIDListImpl
*list
;
349 TRACE ("(%p)->(HWND=%p flags=0x%08x pplist=%p)\n",
350 This
, hwndOwner
, dwFlags
, ppEnumIDList
);
352 if (!(list
= IEnumIDList_Constructor()))
353 return E_OUTOFMEMORY
;
354 CreateDesktopEnumList(list
, dwFlags
);
355 *ppEnumIDList
= &list
->IEnumIDList_iface
;
357 TRACE ("-- (%p)->(new ID List: %p)\n", This
, *ppEnumIDList
);
362 /**************************************************************************
363 * ISF_Desktop_fnBindToObject
365 static HRESULT WINAPI
ISF_Desktop_fnBindToObject (IShellFolder2
* iface
,
366 LPCITEMIDLIST pidl
, LPBC pbcReserved
, REFIID riid
, LPVOID
* ppvOut
)
368 IDesktopFolderImpl
*This
= impl_from_IShellFolder2(iface
);
370 TRACE ("(%p)->(pidl=%p,%p,%s,%p)\n",
371 This
, pidl
, pbcReserved
, shdebugstr_guid (riid
), ppvOut
);
373 return SHELL32_BindToChild( This
->pidlRoot
, This
->sPathTarget
, pidl
, riid
, ppvOut
);
376 /**************************************************************************
377 * ISF_Desktop_fnBindToStorage
379 static HRESULT WINAPI
ISF_Desktop_fnBindToStorage (IShellFolder2
* iface
,
380 LPCITEMIDLIST pidl
, LPBC pbcReserved
, REFIID riid
, LPVOID
* ppvOut
)
382 IDesktopFolderImpl
*This
= impl_from_IShellFolder2(iface
);
384 FIXME ("(%p)->(pidl=%p,%p,%s,%p) stub\n",
385 This
, pidl
, pbcReserved
, shdebugstr_guid (riid
), ppvOut
);
391 /**************************************************************************
392 * ISF_Desktop_fnCompareIDs
394 static HRESULT WINAPI
ISF_Desktop_fnCompareIDs (IShellFolder2
*iface
,
395 LPARAM lParam
, LPCITEMIDLIST pidl1
, LPCITEMIDLIST pidl2
)
397 IDesktopFolderImpl
*This
= impl_from_IShellFolder2(iface
);
400 TRACE ("(%p)->(0x%08lx,pidl1=%p,pidl2=%p)\n", This
, lParam
, pidl1
, pidl2
);
401 hr
= SHELL32_CompareIDs(iface
, lParam
, pidl1
, pidl2
);
402 TRACE ("-- 0x%08x\n", hr
);
406 /**************************************************************************
407 * ISF_Desktop_fnCreateViewObject
409 static HRESULT WINAPI
ISF_Desktop_fnCreateViewObject (IShellFolder2
* iface
,
410 HWND hwndOwner
, REFIID riid
, LPVOID
* ppvOut
)
412 IDesktopFolderImpl
*This
= impl_from_IShellFolder2(iface
);
413 LPSHELLVIEW pShellView
;
414 HRESULT hr
= E_INVALIDARG
;
416 TRACE ("(%p)->(hwnd=%p,%s,%p)\n",
417 This
, hwndOwner
, shdebugstr_guid (riid
), ppvOut
);
424 if (IsEqualIID (riid
, &IID_IDropTarget
))
426 WARN ("IDropTarget not implemented\n");
429 else if (IsEqualIID (riid
, &IID_IContextMenu
))
431 WARN ("IContextMenu not implemented\n");
434 else if (IsEqualIID (riid
, &IID_IShellView
))
436 pShellView
= IShellView_Constructor ((IShellFolder
*) iface
);
439 hr
= IShellView_QueryInterface (pShellView
, riid
, ppvOut
);
440 IShellView_Release (pShellView
);
443 TRACE ("-- (%p)->(interface=%p)\n", This
, ppvOut
);
447 /**************************************************************************
448 * ISF_Desktop_fnGetAttributesOf
450 static HRESULT WINAPI
ISF_Desktop_fnGetAttributesOf (IShellFolder2
* iface
,
451 UINT cidl
, LPCITEMIDLIST
* apidl
, DWORD
* rgfInOut
)
453 IDesktopFolderImpl
*This
= impl_from_IShellFolder2(iface
);
455 static const DWORD dwDesktopAttributes
=
456 SFGAO_STORAGE
| SFGAO_HASPROPSHEET
| SFGAO_STORAGEANCESTOR
|
457 SFGAO_FILESYSANCESTOR
| SFGAO_FOLDER
| SFGAO_FILESYSTEM
| SFGAO_HASSUBFOLDER
;
458 static const DWORD dwMyComputerAttributes
=
459 SFGAO_CANRENAME
| SFGAO_CANDELETE
| SFGAO_HASPROPSHEET
|
460 SFGAO_DROPTARGET
| SFGAO_FILESYSANCESTOR
| SFGAO_FOLDER
| SFGAO_HASSUBFOLDER
;
462 TRACE ("(%p)->(cidl=%d apidl=%p mask=%p (0x%08x))\n",
463 This
, cidl
, apidl
, rgfInOut
, rgfInOut
? *rgfInOut
: 0);
474 *rgfInOut
&= dwDesktopAttributes
;
476 while (cidl
> 0 && *apidl
) {
478 if (_ILIsDesktop(*apidl
)) {
479 *rgfInOut
&= dwDesktopAttributes
;
480 } else if (_ILIsMyComputer(*apidl
)) {
481 *rgfInOut
&= dwMyComputerAttributes
;
483 SHELL32_GetItemAttributes(iface
, *apidl
, rgfInOut
);
489 /* make sure SFGAO_VALIDATE is cleared, some apps depend on that */
490 *rgfInOut
&= ~SFGAO_VALIDATE
;
492 TRACE ("-- result=0x%08x\n", *rgfInOut
);
497 /**************************************************************************
498 * ISF_Desktop_fnGetUIObjectOf
501 * HWND hwndOwner, //[in ] Parent window for any output
502 * UINT cidl, //[in ] array size
503 * LPCITEMIDLIST* apidl, //[in ] simple pidl array
504 * REFIID riid, //[in ] Requested Interface
505 * UINT* prgfInOut, //[ ] reserved
506 * LPVOID* ppvObject) //[out] Resulting Interface
509 static HRESULT WINAPI
ISF_Desktop_fnGetUIObjectOf (IShellFolder2
* iface
,
510 HWND hwndOwner
, UINT cidl
, LPCITEMIDLIST
* apidl
,
511 REFIID riid
, UINT
* prgfInOut
, LPVOID
* ppvOut
)
513 IDesktopFolderImpl
*This
= impl_from_IShellFolder2(iface
);
516 IUnknown
*pObj
= NULL
;
517 HRESULT hr
= E_INVALIDARG
;
519 TRACE ("(%p)->(%p,%u,apidl=%p,%s,%p,%p)\n",
520 This
, hwndOwner
, cidl
, apidl
, shdebugstr_guid (riid
), prgfInOut
, ppvOut
);
527 if (IsEqualIID (riid
, &IID_IContextMenu
))
530 return ItemMenu_Constructor((IShellFolder
*)iface
, This
->pidlRoot
, apidl
, cidl
, riid
, ppvOut
);
532 return BackgroundMenu_Constructor((IShellFolder
*)iface
, TRUE
, riid
, ppvOut
);
534 else if (IsEqualIID (riid
, &IID_IDataObject
) && (cidl
>= 1))
536 pObj
= (LPUNKNOWN
) IDataObject_Constructor( hwndOwner
,
537 This
->pidlRoot
, apidl
, cidl
);
540 else if (IsEqualIID (riid
, &IID_IExtractIconA
) && (cidl
== 1))
542 pidl
= ILCombine (This
->pidlRoot
, apidl
[0]);
543 pObj
= (LPUNKNOWN
) IExtractIconA_Constructor (pidl
);
547 else if (IsEqualIID (riid
, &IID_IExtractIconW
) && (cidl
== 1))
549 pidl
= ILCombine (This
->pidlRoot
, apidl
[0]);
550 pObj
= (LPUNKNOWN
) IExtractIconW_Constructor (pidl
);
554 else if (IsEqualIID (riid
, &IID_IDropTarget
) && (cidl
>= 1))
556 hr
= IShellFolder2_QueryInterface (iface
,
557 &IID_IDropTarget
, (LPVOID
*) & pObj
);
559 else if ((IsEqualIID(riid
,&IID_IShellLinkW
) ||
560 IsEqualIID(riid
,&IID_IShellLinkA
)) && (cidl
== 1))
562 pidl
= ILCombine (This
->pidlRoot
, apidl
[0]);
563 hr
= IShellLink_ConstructFromFile(NULL
, riid
, pidl
, &pObj
);
569 if (SUCCEEDED(hr
) && !pObj
)
573 TRACE ("(%p)->hr=0x%08x\n", This
, hr
);
577 /**************************************************************************
578 * ISF_Desktop_fnGetDisplayNameOf
581 * special case: pidl = null gives desktop-name back
583 static HRESULT WINAPI
ISF_Desktop_fnGetDisplayNameOf (IShellFolder2
* iface
,
584 LPCITEMIDLIST pidl
, DWORD dwFlags
, LPSTRRET strRet
)
586 IDesktopFolderImpl
*This
= impl_from_IShellFolder2(iface
);
590 TRACE ("(%p)->(pidl=%p,0x%08x,%p)\n", This
, pidl
, dwFlags
, strRet
);
596 pszPath
= CoTaskMemAlloc((MAX_PATH
+1) * sizeof(WCHAR
));
598 return E_OUTOFMEMORY
;
600 if (_ILIsDesktop (pidl
))
602 if ((GET_SHGDN_RELATION (dwFlags
) == SHGDN_NORMAL
) &&
603 (GET_SHGDN_FOR (dwFlags
) & SHGDN_FORPARSING
))
604 strcpyW(pszPath
, This
->sPathTarget
);
606 HCR_GetClassNameW(&CLSID_ShellDesktop
, pszPath
, MAX_PATH
);
608 else if (_ILIsPidlSimple (pidl
))
612 if ((clsid
= _ILGetGUIDPointer (pidl
)))
614 if ((GET_SHGDN_FOR (dwFlags
) & (SHGDN_FORPARSING
| SHGDN_FORADDRESSBAR
)) == SHGDN_FORPARSING
)
616 BOOL bWantsForParsing
;
619 * We can only get a filesystem path from a shellfolder if the
620 * value WantsFORPARSING in CLSID\\{...}\\shellfolder exists.
622 * Exception: The MyComputer folder doesn't have this key,
623 * but any other filesystem backed folder it needs it.
625 if (IsEqualIID (clsid
, &CLSID_MyComputer
))
627 bWantsForParsing
= TRUE
;
631 /* get the "WantsFORPARSING" flag from the registry */
632 static const WCHAR clsidW
[] =
633 { 'C','L','S','I','D','\\',0 };
634 static const WCHAR shellfolderW
[] =
635 { '\\','s','h','e','l','l','f','o','l','d','e','r',0 };
636 static const WCHAR wantsForParsingW
[] =
637 { 'W','a','n','t','s','F','o','r','P','a','r','s','i','n',
639 WCHAR szRegPath
[100];
642 lstrcpyW (szRegPath
, clsidW
);
643 SHELL32_GUIDToStringW (clsid
, &szRegPath
[6]);
644 lstrcatW (szRegPath
, shellfolderW
);
645 r
= SHGetValueW(HKEY_CLASSES_ROOT
, szRegPath
,
646 wantsForParsingW
, NULL
, NULL
, NULL
);
647 if (r
== ERROR_SUCCESS
)
648 bWantsForParsing
= TRUE
;
650 bWantsForParsing
= FALSE
;
653 if ((GET_SHGDN_RELATION (dwFlags
) == SHGDN_NORMAL
) &&
657 * we need the filesystem path to the destination folder.
658 * Only the folder itself can know it
660 hr
= SHELL32_GetDisplayNameOfChild (iface
, pidl
, dwFlags
,
666 /* parsing name like ::{...} */
669 SHELL32_GUIDToStringW (clsid
, &pszPath
[2]);
674 /* user friendly name */
675 HCR_GetClassNameW (clsid
, pszPath
, MAX_PATH
);
682 /* file system folder or file rooted at the desktop */
683 if ((GET_SHGDN_FOR(dwFlags
) == SHGDN_FORPARSING
) &&
684 (GET_SHGDN_RELATION(dwFlags
) != SHGDN_INFOLDER
))
686 lstrcpynW(pszPath
, This
->sPathTarget
, MAX_PATH
- 1);
687 PathAddBackslashW(pszPath
);
688 cLen
= lstrlenW(pszPath
);
691 _ILSimpleGetTextW(pidl
, pszPath
+ cLen
, MAX_PATH
- cLen
);
693 if (!_ILIsFolder(pidl
))
694 SHELL_FS_ProcessDisplayFilename(pszPath
, dwFlags
);
699 /* a complex pidl, let the subfolder do the work */
700 hr
= SHELL32_GetDisplayNameOfChild (iface
, pidl
, dwFlags
,
706 /* Win9x always returns ANSI strings, NT always returns Unicode strings */
707 if (GetVersion() & 0x80000000)
709 strRet
->uType
= STRRET_CSTR
;
710 if (!WideCharToMultiByte(CP_ACP
, 0, pszPath
, -1, strRet
->u
.cStr
, MAX_PATH
,
712 strRet
->u
.cStr
[0] = '\0';
713 CoTaskMemFree(pszPath
);
717 strRet
->uType
= STRRET_WSTR
;
718 strRet
->u
.pOleStr
= pszPath
;
722 CoTaskMemFree(pszPath
);
724 TRACE ("-- (%p)->(%s,0x%08x)\n", This
,
725 strRet
->uType
== STRRET_CSTR
? strRet
->u
.cStr
:
726 debugstr_w(strRet
->u
.pOleStr
), hr
);
730 /**************************************************************************
731 * ISF_Desktop_fnSetNameOf
732 * Changes the name of a file object or subfolder, possibly changing its item
733 * identifier in the process.
736 * HWND hwndOwner, //[in ] Owner window for output
737 * LPCITEMIDLIST pidl, //[in ] simple pidl of item to change
738 * LPCOLESTR lpszName, //[in ] the items new display name
739 * DWORD dwFlags, //[in ] SHGNO formatting flags
740 * LPITEMIDLIST* ppidlOut) //[out] simple pidl returned
742 static HRESULT WINAPI
ISF_Desktop_fnSetNameOf (IShellFolder2
* iface
,
743 HWND hwndOwner
, LPCITEMIDLIST pidl
, /* simple pidl */
744 LPCOLESTR lpName
, DWORD dwFlags
, LPITEMIDLIST
* pPidlOut
)
746 IDesktopFolderImpl
*This
= impl_from_IShellFolder2(iface
);
748 FIXME ("(%p)->(%p,pidl=%p,%s,%u,%p) stub\n", This
, hwndOwner
, pidl
,
749 debugstr_w (lpName
), dwFlags
, pPidlOut
);
754 static HRESULT WINAPI
ISF_Desktop_fnGetDefaultSearchGUID(IShellFolder2
*iface
, GUID
*guid
)
756 IDesktopFolderImpl
*This
= impl_from_IShellFolder2(iface
);
757 TRACE("(%p)->(%p)\n", This
, guid
);
761 static HRESULT WINAPI
ISF_Desktop_fnEnumSearches (IShellFolder2
*iface
,
762 IEnumExtraSearch
** ppenum
)
764 IDesktopFolderImpl
*This
= impl_from_IShellFolder2(iface
);
765 FIXME ("(%p)->(%p) stub\n", This
, ppenum
);
769 static HRESULT WINAPI
ISF_Desktop_fnGetDefaultColumn(IShellFolder2
*iface
, DWORD reserved
, ULONG
*sort
, ULONG
*display
)
771 IDesktopFolderImpl
*This
= impl_from_IShellFolder2(iface
);
773 TRACE ("(%p)->(%#x, %p, %p)\n", This
, reserved
, sort
, display
);
778 static HRESULT WINAPI
ISF_Desktop_fnGetDefaultColumnState (
779 IShellFolder2
* iface
, UINT iColumn
, DWORD
* pcsFlags
)
781 IDesktopFolderImpl
*This
= impl_from_IShellFolder2(iface
);
783 TRACE ("(%p)->(%d %p)\n", This
, iColumn
, pcsFlags
);
785 if (!pcsFlags
|| iColumn
>= ARRAY_SIZE(desktop_header
))
788 *pcsFlags
= desktop_header
[iColumn
].pcsFlags
;
793 static HRESULT WINAPI
ISF_Desktop_fnGetDetailsEx (IShellFolder2
* iface
,
794 LPCITEMIDLIST pidl
, const SHCOLUMNID
* pscid
, VARIANT
* pv
)
796 IDesktopFolderImpl
*This
= impl_from_IShellFolder2(iface
);
797 FIXME ("(%p)->(%p %p %p) stub\n", This
, pidl
, pscid
, pv
);
801 static HRESULT WINAPI
ISF_Desktop_fnGetDetailsOf (IShellFolder2
* iface
,
802 LPCITEMIDLIST pidl
, UINT iColumn
, SHELLDETAILS
* psd
)
804 IDesktopFolderImpl
*This
= impl_from_IShellFolder2(iface
);
808 TRACE ("(%p)->(%p %i %p)\n", This
, pidl
, iColumn
, psd
);
810 if (!psd
|| iColumn
>= ARRAY_SIZE(desktop_header
))
814 return SHELL32_GetColumnDetails(desktop_header
, iColumn
, psd
);
816 /* the data from the pidl */
817 psd
->str
.uType
= STRRET_CSTR
;
821 hr
= IShellFolder2_GetDisplayNameOf(iface
, pidl
,
822 SHGDN_NORMAL
| SHGDN_INFOLDER
, &psd
->str
);
825 _ILGetFileSize (pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
828 _ILGetFileType (pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
831 _ILGetFileDate (pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
833 case 4: /* attributes */
834 _ILGetFileAttributes (pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
841 static HRESULT WINAPI
ISF_Desktop_fnMapColumnToSCID(IShellFolder2
*iface
, UINT column
, SHCOLUMNID
*scid
)
843 IDesktopFolderImpl
*This
= impl_from_IShellFolder2(iface
);
845 TRACE("(%p)->(%u %p)\n", This
, column
, scid
);
847 if (column
>= ARRAY_SIZE(desktop_header
))
850 return shellfolder_map_column_to_scid(desktop_header
, column
, scid
);
853 static const IShellFolder2Vtbl vt_MCFldr_ShellFolder2
=
855 ISF_Desktop_fnQueryInterface
,
856 ISF_Desktop_fnAddRef
,
857 ISF_Desktop_fnRelease
,
858 ISF_Desktop_fnParseDisplayName
,
859 ISF_Desktop_fnEnumObjects
,
860 ISF_Desktop_fnBindToObject
,
861 ISF_Desktop_fnBindToStorage
,
862 ISF_Desktop_fnCompareIDs
,
863 ISF_Desktop_fnCreateViewObject
,
864 ISF_Desktop_fnGetAttributesOf
,
865 ISF_Desktop_fnGetUIObjectOf
,
866 ISF_Desktop_fnGetDisplayNameOf
,
867 ISF_Desktop_fnSetNameOf
,
869 ISF_Desktop_fnGetDefaultSearchGUID
,
870 ISF_Desktop_fnEnumSearches
,
871 ISF_Desktop_fnGetDefaultColumn
,
872 ISF_Desktop_fnGetDefaultColumnState
,
873 ISF_Desktop_fnGetDetailsEx
,
874 ISF_Desktop_fnGetDetailsOf
,
875 ISF_Desktop_fnMapColumnToSCID
878 /**************************************************************************
881 static HRESULT WINAPI
ISF_Desktop_IPersistFolder2_fnQueryInterface(
882 IPersistFolder2
*iface
, REFIID riid
, LPVOID
*ppvObj
)
884 IDesktopFolderImpl
*This
= impl_from_IPersistFolder2( iface
);
885 return IShellFolder2_QueryInterface(&This
->IShellFolder2_iface
, riid
, ppvObj
);
888 static ULONG WINAPI
ISF_Desktop_IPersistFolder2_fnAddRef(
889 IPersistFolder2
*iface
)
891 IDesktopFolderImpl
*This
= impl_from_IPersistFolder2( iface
);
892 return IShellFolder2_AddRef(&This
->IShellFolder2_iface
);
895 static ULONG WINAPI
ISF_Desktop_IPersistFolder2_fnRelease(
896 IPersistFolder2
*iface
)
898 IDesktopFolderImpl
*This
= impl_from_IPersistFolder2( iface
);
899 return IShellFolder2_Release(&This
->IShellFolder2_iface
);
902 static HRESULT WINAPI
ISF_Desktop_IPersistFolder2_fnGetClassID(
903 IPersistFolder2
*iface
, CLSID
*clsid
)
905 *clsid
= CLSID_ShellDesktop
;
908 static HRESULT WINAPI
ISF_Desktop_IPersistFolder2_fnInitialize(
909 IPersistFolder2
*iface
, LPCITEMIDLIST pidl
)
911 IDesktopFolderImpl
*This
= impl_from_IPersistFolder2( iface
);
912 FIXME ("(%p)->(%p) stub\n", This
, pidl
);
915 static HRESULT WINAPI
ISF_Desktop_IPersistFolder2_fnGetCurFolder(
916 IPersistFolder2
*iface
, LPITEMIDLIST
*ppidl
)
918 IDesktopFolderImpl
*This
= impl_from_IPersistFolder2( iface
);
919 *ppidl
= ILClone(This
->pidlRoot
);
923 static const IPersistFolder2Vtbl vt_IPersistFolder2
=
925 ISF_Desktop_IPersistFolder2_fnQueryInterface
,
926 ISF_Desktop_IPersistFolder2_fnAddRef
,
927 ISF_Desktop_IPersistFolder2_fnRelease
,
928 ISF_Desktop_IPersistFolder2_fnGetClassID
,
929 ISF_Desktop_IPersistFolder2_fnInitialize
,
930 ISF_Desktop_IPersistFolder2_fnGetCurFolder
933 void release_desktop_folder(void)
935 if (!cached_sf
) return;
936 SHFree(cached_sf
->pidlRoot
);
937 SHFree(cached_sf
->sPathTarget
);
938 LocalFree(cached_sf
);
941 /**************************************************************************
942 * ISF_Desktop_Constructor
944 HRESULT WINAPI
ISF_Desktop_Constructor (
945 IUnknown
* pUnkOuter
, REFIID riid
, LPVOID
* ppv
)
947 WCHAR szMyPath
[MAX_PATH
];
949 TRACE ("unkOut=%p %s\n", pUnkOuter
, shdebugstr_guid (riid
));
954 return CLASS_E_NOAGGREGATION
;
958 IDesktopFolderImpl
*sf
;
960 if (!SHGetSpecialFolderPathW( 0, szMyPath
, CSIDL_DESKTOPDIRECTORY
, TRUE
))
963 sf
= LocalAlloc( LMEM_ZEROINIT
, sizeof (IDesktopFolderImpl
) );
965 return E_OUTOFMEMORY
;
968 sf
->IShellFolder2_iface
.lpVtbl
= &vt_MCFldr_ShellFolder2
;
969 sf
->IPersistFolder2_iface
.lpVtbl
= &vt_IPersistFolder2
;
970 sf
->pidlRoot
= _ILCreateDesktop(); /* my qualified pidl */
971 sf
->sPathTarget
= SHAlloc( (lstrlenW(szMyPath
) + 1)*sizeof(WCHAR
) );
972 lstrcpyW( sf
->sPathTarget
, szMyPath
);
974 if (InterlockedCompareExchangePointer((void *)&cached_sf
, sf
, NULL
) != NULL
)
976 /* some other thread already been here */
977 SHFree( sf
->pidlRoot
);
978 SHFree( sf
->sPathTarget
);
983 return IShellFolder2_QueryInterface( &cached_sf
->IShellFolder2_iface
, riid
, ppv
);