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
29 #define NONAMELESSUNION
43 #include "shell32_main.h"
46 #include "shellfolder.h"
47 #include "wine/debug.h"
51 WINE_DEFAULT_DEBUG_CHANNEL (shell
);
53 /* Undocumented functions from shdocvw */
54 extern HRESULT WINAPI
IEParseDisplayNameWithBCW(DWORD codepage
, LPCWSTR lpszDisplayName
, LPBC pbc
, LPITEMIDLIST
*ppidl
);
56 /***********************************************************************
57 * Desktopfolder implementation
61 IShellFolder2 IShellFolder2_iface
;
62 IPersistFolder2 IPersistFolder2_iface
;
65 /* both paths are parsible from the desktop */
66 LPWSTR sPathTarget
; /* complete path to target used for enumeration and ChangeNotify */
67 LPITEMIDLIST pidlRoot
; /* absolute pidl */
69 UINT cfShellIDList
; /* clipboardformat for IDropTarget */
70 BOOL fAcceptFmt
; /* flag for pending Drop */
73 static IDesktopFolderImpl
*cached_sf
;
75 static inline IDesktopFolderImpl
*impl_from_IShellFolder2(IShellFolder2
*iface
)
77 return CONTAINING_RECORD(iface
, IDesktopFolderImpl
, IShellFolder2_iface
);
80 static inline IDesktopFolderImpl
*impl_from_IPersistFolder2( IPersistFolder2
*iface
)
82 return CONTAINING_RECORD(iface
, IDesktopFolderImpl
, IPersistFolder2_iface
);
85 static const shvheader desktop_header
[] =
87 { &FMTID_Storage
, PID_STG_NAME
, IDS_SHV_COLUMN1
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 15 },
88 { &FMTID_Storage
, PID_STG_SIZE
, IDS_SHV_COLUMN2
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 10 },
89 { &FMTID_Storage
, PID_STG_STORAGETYPE
, IDS_SHV_COLUMN3
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 10 },
90 { &FMTID_Storage
, PID_STG_WRITETIME
, IDS_SHV_COLUMN4
, SHCOLSTATE_TYPE_DATE
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 12 },
91 { &FMTID_Storage
, PID_STG_ATTRIBUTES
, IDS_SHV_COLUMN5
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 5 },
94 /**************************************************************************
95 * ISF_Desktop_fnQueryInterface
98 static HRESULT WINAPI
ISF_Desktop_fnQueryInterface(
99 IShellFolder2
* iface
, REFIID riid
, LPVOID
* ppvObj
)
101 IDesktopFolderImpl
*This
= impl_from_IShellFolder2(iface
);
103 TRACE ("(%p)->(%s,%p)\n", This
, shdebugstr_guid (riid
), ppvObj
);
105 if (!ppvObj
) return E_POINTER
;
109 if (IsEqualIID (riid
, &IID_IUnknown
) ||
110 IsEqualIID (riid
, &IID_IShellFolder
) ||
111 IsEqualIID (riid
, &IID_IShellFolder2
))
113 *ppvObj
= &This
->IShellFolder2_iface
;
115 else if (IsEqualIID (riid
, &IID_IPersist
) ||
116 IsEqualIID (riid
, &IID_IPersistFolder
) ||
117 IsEqualIID (riid
, &IID_IPersistFolder2
))
119 *ppvObj
= &This
->IPersistFolder2_iface
;
124 IUnknown_AddRef ((IUnknown
*) (*ppvObj
));
125 TRACE ("-- Interface: (%p)->(%p)\n", ppvObj
, *ppvObj
);
128 TRACE ("-- Interface: E_NOINTERFACE\n");
129 return E_NOINTERFACE
;
132 static ULONG WINAPI
ISF_Desktop_fnAddRef (IShellFolder2
* iface
)
134 return 2; /* non-heap based object */
137 static ULONG WINAPI
ISF_Desktop_fnRelease (IShellFolder2
* iface
)
139 return 1; /* non-heap based object */
142 /**************************************************************************
143 * ISF_Desktop_fnParseDisplayName
146 * "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}" and "" binds
149 static HRESULT WINAPI
ISF_Desktop_fnParseDisplayName (IShellFolder2
* iface
,
150 HWND hwndOwner
, LPBC pbc
, LPOLESTR lpszDisplayName
,
151 DWORD
* pchEaten
, LPITEMIDLIST
* ppidl
, DWORD
* pdwAttributes
)
153 IDesktopFolderImpl
*This
= impl_from_IShellFolder2(iface
);
154 WCHAR c
, szElement
[MAX_PATH
];
155 LPCWSTR szNext
= NULL
;
156 LPITEMIDLIST pidlTemp
= NULL
;
161 TRACE ("(%p)->(HWND=%p,%p,%p=%s,%p,pidl=%p,%p)\n",
162 This
, hwndOwner
, pbc
, lpszDisplayName
, debugstr_w(lpszDisplayName
),
163 pchEaten
, ppidl
, pdwAttributes
);
165 if (!ppidl
) return E_INVALIDARG
;
168 if (!lpszDisplayName
) return E_INVALIDARG
;
171 *pchEaten
= 0; /* strange but like the original */
173 urldata
.cbSize
= sizeof(urldata
);
175 if (lpszDisplayName
[0] == ':' && lpszDisplayName
[1] == ':')
177 szNext
= GetNextElementW (lpszDisplayName
, szElement
, MAX_PATH
);
178 TRACE ("-- element: %s\n", debugstr_w (szElement
));
179 SHCLSIDFromStringW (szElement
+ 2, &clsid
);
180 pidlTemp
= _ILCreateGuid (PT_GUID
, &clsid
);
182 /* we can't use PathGetDriveNumberW because we can't have the \\?\ prefix */
183 else if ((c
= towupper(lpszDisplayName
[0])) >= 'A' && c
<= 'Z' && lpszDisplayName
[1] == ':')
185 /* it's a filesystem path with a drive. Let MyComputer/UnixDosFolder parse it */
186 pidlTemp
= _ILCreateMyComputer ();
187 szNext
= lpszDisplayName
;
189 else if (!wcsncmp( lpszDisplayName
, L
"\\\\?\\unix\\", 9 ))
191 pidlTemp
= _ILCreateGuid(PT_GUID
, &CLSID_UnixDosFolder
);
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%08lx)\n", This
, hr
);
280 static void add_shell_namespace_extensions(IEnumIDListImpl
*list
, HKEY root
)
282 WCHAR guid
[39], clsidkeyW
[60];
286 if (RegOpenKeyExW(root
, L
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Desktop\\Namespace", 0, KEY_READ
, &hkey
))
289 size
= ARRAY_SIZE(guid
);
290 while (!RegEnumKeyExW(hkey
, i
++, guid
, &size
, 0, NULL
, NULL
, NULL
))
292 DWORD attributes
, value_size
= sizeof(attributes
);
294 /* Check if extension is configured as nonenumerable */
295 swprintf(clsidkeyW
, ARRAY_SIZE(clsidkeyW
), L
"CLSID\\%s\\ShellFolder", guid
);
296 RegGetValueW(HKEY_CLASSES_ROOT
, clsidkeyW
, L
"Attributes", RRF_RT_REG_DWORD
| RRF_ZEROONFAILURE
,
297 NULL
, &attributes
, &value_size
);
299 if (!(attributes
& SFGAO_NONENUMERATED
))
300 AddToEnumList(list
, _ILCreateGuidFromStrW(guid
));
301 size
= ARRAY_SIZE(guid
);
307 /**************************************************************************
308 * CreateDesktopEnumList()
310 static BOOL
CreateDesktopEnumList(IEnumIDListImpl
*list
, DWORD dwFlags
)
313 WCHAR szPath
[MAX_PATH
];
315 TRACE("(%p)->(flags=0x%08lx)\n", list
, dwFlags
);
317 /* enumerate the root folders */
318 if (dwFlags
& SHCONTF_FOLDERS
)
320 ret
= AddToEnumList(list
, _ILCreateMyComputer());
321 add_shell_namespace_extensions(list
, HKEY_LOCAL_MACHINE
);
322 add_shell_namespace_extensions(list
, HKEY_CURRENT_USER
);
325 /* enumerate the elements in %windir%\desktop */
326 ret
= ret
&& SHGetSpecialFolderPathW(0, szPath
, CSIDL_DESKTOPDIRECTORY
, FALSE
);
327 ret
= ret
&& CreateFolderEnumList(list
, szPath
, dwFlags
);
332 /**************************************************************************
333 * ISF_Desktop_fnEnumObjects
335 static HRESULT WINAPI
ISF_Desktop_fnEnumObjects (IShellFolder2
* iface
,
336 HWND hwndOwner
, DWORD dwFlags
, LPENUMIDLIST
* ppEnumIDList
)
338 IDesktopFolderImpl
*This
= impl_from_IShellFolder2(iface
);
339 IEnumIDListImpl
*list
;
341 TRACE ("(%p)->(HWND=%p flags=0x%08lx pplist=%p)\n",
342 This
, hwndOwner
, dwFlags
, ppEnumIDList
);
344 if (!(list
= IEnumIDList_Constructor()))
345 return E_OUTOFMEMORY
;
346 CreateDesktopEnumList(list
, dwFlags
);
347 *ppEnumIDList
= &list
->IEnumIDList_iface
;
349 TRACE ("-- (%p)->(new ID List: %p)\n", This
, *ppEnumIDList
);
354 /**************************************************************************
355 * ISF_Desktop_fnBindToObject
357 static HRESULT WINAPI
ISF_Desktop_fnBindToObject (IShellFolder2
* iface
,
358 LPCITEMIDLIST pidl
, LPBC pbcReserved
, REFIID riid
, LPVOID
* ppvOut
)
360 IDesktopFolderImpl
*This
= impl_from_IShellFolder2(iface
);
362 TRACE ("(%p)->(pidl=%p,%p,%s,%p)\n",
363 This
, pidl
, pbcReserved
, shdebugstr_guid (riid
), ppvOut
);
365 return SHELL32_BindToChild( This
->pidlRoot
, &CLSID_ShellFSFolder
, This
->sPathTarget
, pidl
, riid
, ppvOut
);
368 /**************************************************************************
369 * ISF_Desktop_fnBindToStorage
371 static HRESULT WINAPI
ISF_Desktop_fnBindToStorage (IShellFolder2
* iface
,
372 LPCITEMIDLIST pidl
, LPBC pbcReserved
, REFIID riid
, LPVOID
* ppvOut
)
374 IDesktopFolderImpl
*This
= impl_from_IShellFolder2(iface
);
376 FIXME ("(%p)->(pidl=%p,%p,%s,%p) stub\n",
377 This
, pidl
, pbcReserved
, shdebugstr_guid (riid
), ppvOut
);
383 /**************************************************************************
384 * ISF_Desktop_fnCompareIDs
386 static HRESULT WINAPI
ISF_Desktop_fnCompareIDs (IShellFolder2
*iface
,
387 LPARAM lParam
, LPCITEMIDLIST pidl1
, LPCITEMIDLIST pidl2
)
389 IDesktopFolderImpl
*This
= impl_from_IShellFolder2(iface
);
392 TRACE ("(%p)->(0x%08Ix,pidl1=%p,pidl2=%p)\n", This
, lParam
, pidl1
, pidl2
);
393 hr
= SHELL32_CompareIDs(iface
, lParam
, pidl1
, pidl2
);
394 TRACE ("-- 0x%08lx\n", hr
);
398 /**************************************************************************
399 * ISF_Desktop_fnCreateViewObject
401 static HRESULT WINAPI
ISF_Desktop_fnCreateViewObject (IShellFolder2
* iface
,
402 HWND hwndOwner
, REFIID riid
, LPVOID
* ppvOut
)
404 IDesktopFolderImpl
*This
= impl_from_IShellFolder2(iface
);
405 LPSHELLVIEW pShellView
;
406 HRESULT hr
= E_INVALIDARG
;
408 TRACE ("(%p)->(hwnd=%p,%s,%p)\n",
409 This
, hwndOwner
, shdebugstr_guid (riid
), ppvOut
);
416 if (IsEqualIID (riid
, &IID_IDropTarget
))
418 WARN ("IDropTarget not implemented\n");
421 else if (IsEqualIID (riid
, &IID_IContextMenu
))
423 hr
= BackgroundMenu_Constructor((IShellFolder
*)iface
, TRUE
, riid
, ppvOut
);
425 else if (IsEqualIID (riid
, &IID_IShellView
))
427 pShellView
= IShellView_Constructor ((IShellFolder
*) iface
);
430 hr
= IShellView_QueryInterface (pShellView
, riid
, ppvOut
);
431 IShellView_Release (pShellView
);
434 TRACE ("-- (%p)->(interface=%p)\n", This
, ppvOut
);
438 /**************************************************************************
439 * ISF_Desktop_fnGetAttributesOf
441 static HRESULT WINAPI
ISF_Desktop_fnGetAttributesOf (IShellFolder2
* iface
,
442 UINT cidl
, LPCITEMIDLIST
* apidl
, DWORD
* rgfInOut
)
444 IDesktopFolderImpl
*This
= impl_from_IShellFolder2(iface
);
446 static const DWORD dwDesktopAttributes
=
447 SFGAO_STORAGE
| SFGAO_HASPROPSHEET
| SFGAO_STORAGEANCESTOR
|
448 SFGAO_FILESYSANCESTOR
| SFGAO_FOLDER
| SFGAO_FILESYSTEM
| SFGAO_HASSUBFOLDER
;
449 static const DWORD dwMyComputerAttributes
=
450 SFGAO_CANRENAME
| SFGAO_CANDELETE
| SFGAO_HASPROPSHEET
|
451 SFGAO_DROPTARGET
| SFGAO_FILESYSANCESTOR
| SFGAO_FOLDER
| SFGAO_HASSUBFOLDER
;
453 TRACE ("(%p)->(cidl=%d apidl=%p mask=%p (0x%08lx))\n",
454 This
, cidl
, apidl
, rgfInOut
, rgfInOut
? *rgfInOut
: 0);
465 *rgfInOut
&= dwDesktopAttributes
;
467 while (cidl
> 0 && *apidl
) {
469 if (_ILIsDesktop(*apidl
)) {
470 *rgfInOut
&= dwDesktopAttributes
;
471 } else if (_ILIsMyComputer(*apidl
)) {
472 *rgfInOut
&= dwMyComputerAttributes
;
474 SHELL32_GetItemAttributes(iface
, *apidl
, rgfInOut
);
480 /* make sure SFGAO_VALIDATE is cleared, some apps depend on that */
481 *rgfInOut
&= ~SFGAO_VALIDATE
;
483 TRACE ("-- result=0x%08lx\n", *rgfInOut
);
488 /**************************************************************************
489 * ISF_Desktop_fnGetUIObjectOf
492 * HWND hwndOwner, //[in ] Parent window for any output
493 * UINT cidl, //[in ] array size
494 * LPCITEMIDLIST* apidl, //[in ] simple pidl array
495 * REFIID riid, //[in ] Requested Interface
496 * UINT* prgfInOut, //[ ] reserved
497 * LPVOID* ppvObject) //[out] Resulting Interface
500 static HRESULT WINAPI
ISF_Desktop_fnGetUIObjectOf (IShellFolder2
* iface
,
501 HWND hwndOwner
, UINT cidl
, LPCITEMIDLIST
* apidl
,
502 REFIID riid
, UINT
* prgfInOut
, LPVOID
* ppvOut
)
504 IDesktopFolderImpl
*This
= impl_from_IShellFolder2(iface
);
507 IUnknown
*pObj
= NULL
;
508 HRESULT hr
= E_INVALIDARG
;
510 TRACE ("(%p)->(%p,%u,apidl=%p,%s,%p,%p)\n",
511 This
, hwndOwner
, cidl
, apidl
, shdebugstr_guid (riid
), prgfInOut
, ppvOut
);
518 if (IsEqualIID (riid
, &IID_IContextMenu
))
521 return ItemMenu_Constructor((IShellFolder
*)iface
, This
->pidlRoot
, apidl
, cidl
, riid
, ppvOut
);
523 return BackgroundMenu_Constructor((IShellFolder
*)iface
, TRUE
, riid
, ppvOut
);
525 else if (IsEqualIID (riid
, &IID_IDataObject
) && (cidl
>= 1))
527 pObj
= (LPUNKNOWN
) IDataObject_Constructor( hwndOwner
,
528 This
->pidlRoot
, apidl
, cidl
);
531 else if (IsEqualIID (riid
, &IID_IExtractIconA
) && (cidl
== 1))
533 pidl
= ILCombine (This
->pidlRoot
, apidl
[0]);
534 pObj
= (LPUNKNOWN
) IExtractIconA_Constructor (pidl
);
538 else if (IsEqualIID (riid
, &IID_IExtractIconW
) && (cidl
== 1))
540 pidl
= ILCombine (This
->pidlRoot
, apidl
[0]);
541 pObj
= (LPUNKNOWN
) IExtractIconW_Constructor (pidl
);
545 else if (IsEqualIID (riid
, &IID_IDropTarget
) && (cidl
>= 1))
547 hr
= IShellFolder2_QueryInterface (iface
,
548 &IID_IDropTarget
, (LPVOID
*) & pObj
);
550 else if ((IsEqualIID(riid
,&IID_IShellLinkW
) ||
551 IsEqualIID(riid
,&IID_IShellLinkA
)) && (cidl
== 1))
553 pidl
= ILCombine (This
->pidlRoot
, apidl
[0]);
554 hr
= IShellLink_ConstructFromFile(NULL
, riid
, pidl
, &pObj
);
560 if (SUCCEEDED(hr
) && !pObj
)
564 TRACE ("(%p)->hr=0x%08lx\n", This
, hr
);
568 /**************************************************************************
569 * ISF_Desktop_fnGetDisplayNameOf
572 * special case: pidl = null gives desktop-name back
574 static HRESULT WINAPI
ISF_Desktop_fnGetDisplayNameOf (IShellFolder2
* iface
,
575 LPCITEMIDLIST pidl
, DWORD dwFlags
, LPSTRRET strRet
)
577 IDesktopFolderImpl
*This
= impl_from_IShellFolder2(iface
);
581 TRACE ("(%p)->(pidl=%p,0x%08lx,%p)\n", This
, pidl
, dwFlags
, strRet
);
587 pszPath
= CoTaskMemAlloc((MAX_PATH
+1) * sizeof(WCHAR
));
589 return E_OUTOFMEMORY
;
591 if (_ILIsDesktop (pidl
))
593 if ((GET_SHGDN_RELATION (dwFlags
) == SHGDN_NORMAL
) &&
594 (GET_SHGDN_FOR (dwFlags
) & SHGDN_FORPARSING
))
595 lstrcpyW(pszPath
, This
->sPathTarget
);
597 HCR_GetClassNameW(&CLSID_ShellDesktop
, pszPath
, MAX_PATH
);
599 else if (_ILIsPidlSimple (pidl
))
603 if ((clsid
= _ILGetGUIDPointer (pidl
)))
605 if ((GET_SHGDN_FOR (dwFlags
) & (SHGDN_FORPARSING
| SHGDN_FORADDRESSBAR
)) == SHGDN_FORPARSING
)
607 BOOL bWantsForParsing
;
610 * We can only get a filesystem path from a shellfolder if the
611 * value WantsFORPARSING in CLSID\\{...}\\shellfolder exists.
613 * Exception: The MyComputer folder doesn't have this key,
614 * but any other filesystem backed folder it needs it.
616 if (IsEqualIID (clsid
, &CLSID_MyComputer
))
618 bWantsForParsing
= TRUE
;
622 /* get the "WantsFORPARSING" flag from the registry */
623 WCHAR szRegPath
[100];
626 lstrcpyW (szRegPath
, L
"CLSID\\");
627 SHELL32_GUIDToStringW (clsid
, &szRegPath
[6]);
628 lstrcatW (szRegPath
, L
"\\shellfolder");
629 r
= SHGetValueW(HKEY_CLASSES_ROOT
, szRegPath
, L
"WantsForParsing", NULL
, NULL
, NULL
);
630 if (r
== ERROR_SUCCESS
)
631 bWantsForParsing
= TRUE
;
633 bWantsForParsing
= FALSE
;
636 if ((GET_SHGDN_RELATION (dwFlags
) == SHGDN_NORMAL
) &&
640 * we need the filesystem path to the destination folder.
641 * Only the folder itself can know it
643 hr
= SHELL32_GetDisplayNameOfChild (iface
, pidl
, dwFlags
,
649 /* parsing name like ::{...} */
652 SHELL32_GUIDToStringW (clsid
, &pszPath
[2]);
657 /* user friendly name */
658 HCR_GetClassNameW (clsid
, pszPath
, MAX_PATH
);
665 /* file system folder or file rooted at the desktop */
666 if ((GET_SHGDN_FOR(dwFlags
) == SHGDN_FORPARSING
) &&
667 (GET_SHGDN_RELATION(dwFlags
) != SHGDN_INFOLDER
))
669 lstrcpynW(pszPath
, This
->sPathTarget
, MAX_PATH
- 1);
670 PathAddBackslashW(pszPath
);
671 cLen
= lstrlenW(pszPath
);
674 _ILSimpleGetTextW(pidl
, pszPath
+ cLen
, MAX_PATH
- cLen
);
676 if (!_ILIsFolder(pidl
))
677 SHELL_FS_ProcessDisplayFilename(pszPath
, dwFlags
);
682 /* a complex pidl, let the subfolder do the work */
683 hr
= SHELL32_GetDisplayNameOfChild (iface
, pidl
, dwFlags
,
689 /* Win9x always returns ANSI strings, NT always returns Unicode strings */
690 if (GetVersion() & 0x80000000)
692 strRet
->uType
= STRRET_CSTR
;
693 if (!WideCharToMultiByte(CP_ACP
, 0, pszPath
, -1, strRet
->u
.cStr
, MAX_PATH
,
695 strRet
->u
.cStr
[0] = '\0';
696 CoTaskMemFree(pszPath
);
700 strRet
->uType
= STRRET_WSTR
;
701 strRet
->u
.pOleStr
= pszPath
;
705 CoTaskMemFree(pszPath
);
707 TRACE ("-- (%p)->(%s,0x%08lx)\n", This
,
708 strRet
->uType
== STRRET_CSTR
? strRet
->u
.cStr
:
709 debugstr_w(strRet
->u
.pOleStr
), hr
);
713 /**************************************************************************
714 * ISF_Desktop_fnSetNameOf
715 * Changes the name of a file object or subfolder, possibly changing its item
716 * identifier in the process.
719 * HWND hwndOwner, //[in ] Owner window for output
720 * LPCITEMIDLIST pidl, //[in ] simple pidl of item to change
721 * LPCOLESTR lpszName, //[in ] the items new display name
722 * DWORD dwFlags, //[in ] SHGNO formatting flags
723 * LPITEMIDLIST* ppidlOut) //[out] simple pidl returned
725 static HRESULT WINAPI
ISF_Desktop_fnSetNameOf (IShellFolder2
* iface
,
726 HWND hwndOwner
, LPCITEMIDLIST pidl
, /* simple pidl */
727 LPCOLESTR lpName
, DWORD dwFlags
, LPITEMIDLIST
* pPidlOut
)
729 IDesktopFolderImpl
*This
= impl_from_IShellFolder2(iface
);
731 FIXME ("(%p)->(%p,pidl=%p,%s,%lu,%p) stub\n", This
, hwndOwner
, pidl
,
732 debugstr_w (lpName
), dwFlags
, pPidlOut
);
737 static HRESULT WINAPI
ISF_Desktop_fnGetDefaultSearchGUID(IShellFolder2
*iface
, GUID
*guid
)
739 IDesktopFolderImpl
*This
= impl_from_IShellFolder2(iface
);
740 TRACE("(%p)->(%p)\n", This
, guid
);
744 static HRESULT WINAPI
ISF_Desktop_fnEnumSearches (IShellFolder2
*iface
,
745 IEnumExtraSearch
** ppenum
)
747 IDesktopFolderImpl
*This
= impl_from_IShellFolder2(iface
);
748 FIXME ("(%p)->(%p) stub\n", This
, ppenum
);
752 static HRESULT WINAPI
ISF_Desktop_fnGetDefaultColumn(IShellFolder2
*iface
, DWORD reserved
, ULONG
*sort
, ULONG
*display
)
754 IDesktopFolderImpl
*This
= impl_from_IShellFolder2(iface
);
756 TRACE ("(%p)->(%#lx, %p, %p)\n", This
, reserved
, sort
, display
);
761 static HRESULT WINAPI
ISF_Desktop_fnGetDefaultColumnState (
762 IShellFolder2
* iface
, UINT iColumn
, DWORD
* pcsFlags
)
764 IDesktopFolderImpl
*This
= impl_from_IShellFolder2(iface
);
766 TRACE ("(%p)->(%d %p)\n", This
, iColumn
, pcsFlags
);
768 if (!pcsFlags
|| iColumn
>= ARRAY_SIZE(desktop_header
))
771 *pcsFlags
= desktop_header
[iColumn
].pcsFlags
;
776 static HRESULT WINAPI
ISF_Desktop_fnGetDetailsEx (IShellFolder2
* iface
,
777 LPCITEMIDLIST pidl
, const SHCOLUMNID
* pscid
, VARIANT
* pv
)
779 IDesktopFolderImpl
*This
= impl_from_IShellFolder2(iface
);
780 FIXME ("(%p)->(%p %p %p) stub\n", This
, pidl
, pscid
, pv
);
784 static HRESULT WINAPI
ISF_Desktop_fnGetDetailsOf (IShellFolder2
* iface
,
785 LPCITEMIDLIST pidl
, UINT iColumn
, SHELLDETAILS
* psd
)
787 IDesktopFolderImpl
*This
= impl_from_IShellFolder2(iface
);
789 TRACE ("(%p)->(%p %i %p)\n", This
, pidl
, iColumn
, psd
);
791 if (!psd
|| iColumn
>= ARRAY_SIZE(desktop_header
))
795 return SHELL32_GetColumnDetails(desktop_header
, iColumn
, psd
);
797 return shellfolder_get_file_details( iface
, pidl
, desktop_header
, iColumn
, psd
);
800 static HRESULT WINAPI
ISF_Desktop_fnMapColumnToSCID(IShellFolder2
*iface
, UINT column
, SHCOLUMNID
*scid
)
802 IDesktopFolderImpl
*This
= impl_from_IShellFolder2(iface
);
804 TRACE("(%p)->(%u %p)\n", This
, column
, scid
);
806 if (column
>= ARRAY_SIZE(desktop_header
))
809 return shellfolder_map_column_to_scid(desktop_header
, column
, scid
);
812 static const IShellFolder2Vtbl vt_MCFldr_ShellFolder2
=
814 ISF_Desktop_fnQueryInterface
,
815 ISF_Desktop_fnAddRef
,
816 ISF_Desktop_fnRelease
,
817 ISF_Desktop_fnParseDisplayName
,
818 ISF_Desktop_fnEnumObjects
,
819 ISF_Desktop_fnBindToObject
,
820 ISF_Desktop_fnBindToStorage
,
821 ISF_Desktop_fnCompareIDs
,
822 ISF_Desktop_fnCreateViewObject
,
823 ISF_Desktop_fnGetAttributesOf
,
824 ISF_Desktop_fnGetUIObjectOf
,
825 ISF_Desktop_fnGetDisplayNameOf
,
826 ISF_Desktop_fnSetNameOf
,
828 ISF_Desktop_fnGetDefaultSearchGUID
,
829 ISF_Desktop_fnEnumSearches
,
830 ISF_Desktop_fnGetDefaultColumn
,
831 ISF_Desktop_fnGetDefaultColumnState
,
832 ISF_Desktop_fnGetDetailsEx
,
833 ISF_Desktop_fnGetDetailsOf
,
834 ISF_Desktop_fnMapColumnToSCID
837 /**************************************************************************
840 static HRESULT WINAPI
ISF_Desktop_IPersistFolder2_fnQueryInterface(
841 IPersistFolder2
*iface
, REFIID riid
, LPVOID
*ppvObj
)
843 IDesktopFolderImpl
*This
= impl_from_IPersistFolder2( iface
);
844 return IShellFolder2_QueryInterface(&This
->IShellFolder2_iface
, riid
, ppvObj
);
847 static ULONG WINAPI
ISF_Desktop_IPersistFolder2_fnAddRef(
848 IPersistFolder2
*iface
)
850 IDesktopFolderImpl
*This
= impl_from_IPersistFolder2( iface
);
851 return IShellFolder2_AddRef(&This
->IShellFolder2_iface
);
854 static ULONG WINAPI
ISF_Desktop_IPersistFolder2_fnRelease(
855 IPersistFolder2
*iface
)
857 IDesktopFolderImpl
*This
= impl_from_IPersistFolder2( iface
);
858 return IShellFolder2_Release(&This
->IShellFolder2_iface
);
861 static HRESULT WINAPI
ISF_Desktop_IPersistFolder2_fnGetClassID(
862 IPersistFolder2
*iface
, CLSID
*clsid
)
864 *clsid
= CLSID_ShellDesktop
;
867 static HRESULT WINAPI
ISF_Desktop_IPersistFolder2_fnInitialize(
868 IPersistFolder2
*iface
, LPCITEMIDLIST pidl
)
870 IDesktopFolderImpl
*This
= impl_from_IPersistFolder2( iface
);
871 FIXME ("(%p)->(%p) stub\n", This
, pidl
);
874 static HRESULT WINAPI
ISF_Desktop_IPersistFolder2_fnGetCurFolder(
875 IPersistFolder2
*iface
, LPITEMIDLIST
*ppidl
)
877 IDesktopFolderImpl
*This
= impl_from_IPersistFolder2( iface
);
878 *ppidl
= ILClone(This
->pidlRoot
);
882 static const IPersistFolder2Vtbl vt_IPersistFolder2
=
884 ISF_Desktop_IPersistFolder2_fnQueryInterface
,
885 ISF_Desktop_IPersistFolder2_fnAddRef
,
886 ISF_Desktop_IPersistFolder2_fnRelease
,
887 ISF_Desktop_IPersistFolder2_fnGetClassID
,
888 ISF_Desktop_IPersistFolder2_fnInitialize
,
889 ISF_Desktop_IPersistFolder2_fnGetCurFolder
892 void release_desktop_folder(void)
894 if (!cached_sf
) return;
895 SHFree(cached_sf
->pidlRoot
);
896 SHFree(cached_sf
->sPathTarget
);
897 LocalFree(cached_sf
);
900 /**************************************************************************
901 * ISF_Desktop_Constructor
903 HRESULT WINAPI
ISF_Desktop_Constructor (
904 IUnknown
* pUnkOuter
, REFIID riid
, LPVOID
* ppv
)
906 WCHAR szMyPath
[MAX_PATH
];
908 TRACE ("unkOut=%p %s\n", pUnkOuter
, shdebugstr_guid (riid
));
913 return CLASS_E_NOAGGREGATION
;
917 IDesktopFolderImpl
*sf
;
919 if (!SHGetSpecialFolderPathW( 0, szMyPath
, CSIDL_DESKTOPDIRECTORY
, FALSE
))
922 sf
= LocalAlloc( LMEM_ZEROINIT
, sizeof (IDesktopFolderImpl
) );
924 return E_OUTOFMEMORY
;
927 sf
->IShellFolder2_iface
.lpVtbl
= &vt_MCFldr_ShellFolder2
;
928 sf
->IPersistFolder2_iface
.lpVtbl
= &vt_IPersistFolder2
;
929 sf
->pidlRoot
= _ILCreateDesktop(); /* my qualified pidl */
930 sf
->sPathTarget
= SHAlloc( (lstrlenW(szMyPath
) + 1)*sizeof(WCHAR
) );
931 lstrcpyW( sf
->sPathTarget
, szMyPath
);
933 if (InterlockedCompareExchangePointer((void *)&cached_sf
, sf
, NULL
) != NULL
)
935 /* some other thread already been here */
936 SHFree( sf
->pidlRoot
);
937 SHFree( sf
->sPathTarget
);
942 return IShellFolder2_QueryInterface( &cached_sf
->IShellFolder2_iface
, riid
, ppv
);
945 static HRESULT WINAPI
active_desktop_QueryInterface(IActiveDesktop
*iface
, REFIID riid
, void **obj
)
947 TRACE("%p, %s, %p.\n", iface
, debugstr_guid(riid
), obj
);
951 if (IsEqualIID(riid
, &IID_IActiveDesktop
)
952 || IsEqualIID(riid
, &IID_IUnknown
))
959 IUnknown_AddRef((IUnknown
*)*obj
);
963 WARN("Unsupported interface %s.\n", debugstr_guid(riid
));
965 return E_NOINTERFACE
;
968 static ULONG WINAPI
active_desktop_AddRef(IActiveDesktop
*iface
)
973 static ULONG WINAPI
active_desktop_Release(IActiveDesktop
*iface
)
978 static HRESULT WINAPI
active_desktop_ApplyChanges(IActiveDesktop
*iface
, DWORD flags
)
980 FIXME("%p, %#lx.\n", iface
, flags
);
985 static HRESULT WINAPI
active_desktop_GetWallpaper(IActiveDesktop
*iface
, PWSTR wallpaper
, UINT length
, DWORD flags
)
987 FIXME("%p, %p, %u, %#lx.\n", iface
, wallpaper
, length
, flags
);
992 static HRESULT WINAPI
active_desktop_SetWallpaper(IActiveDesktop
*iface
, PCWSTR wallpaper
, DWORD reserved
)
994 FIXME("%p, %s, %#lx.\n", iface
, debugstr_w(wallpaper
), reserved
);
999 static HRESULT WINAPI
active_desktop_GetWallpaperOptions(IActiveDesktop
*iface
, LPWALLPAPEROPT options
, DWORD reserved
)
1001 FIXME("%p, %p, %#lx.\n", iface
, options
, reserved
);
1006 static HRESULT WINAPI
active_desktop_SetWallpaperOptions(IActiveDesktop
*iface
, LPCWALLPAPEROPT options
, DWORD reserved
)
1008 FIXME("%p, %p, %#lx.\n", iface
, options
, reserved
);
1013 static HRESULT WINAPI
active_desktop_GetPattern(IActiveDesktop
*iface
, PWSTR pattern
, UINT length
, DWORD reserved
)
1015 FIXME("%p, %p, %u, %#lx.\n", iface
, pattern
, length
, reserved
);
1020 static HRESULT WINAPI
active_desktop_SetPattern(IActiveDesktop
*iface
, PCWSTR pattern
, DWORD reserved
)
1022 FIXME("%p, %s, %#lx.\n", iface
, debugstr_w(pattern
), reserved
);
1027 static HRESULT WINAPI
active_desktop_GetDesktopItemOptions(IActiveDesktop
*iface
, LPCOMPONENTSOPT options
, DWORD reserved
)
1029 FIXME("%p, %p, %#lx.\n", iface
, options
, reserved
);
1034 static HRESULT WINAPI
active_desktop_SetDesktopItemOptions(IActiveDesktop
*iface
, LPCCOMPONENTSOPT options
, DWORD reserved
)
1036 FIXME("%p, %p, %#lx.\n", iface
, options
, reserved
);
1041 static HRESULT WINAPI
active_desktop_AddDesktopItem(IActiveDesktop
*iface
, LPCCOMPONENT component
, DWORD reserved
)
1043 FIXME("%p, %p, %#lx.\n", iface
, component
, reserved
);
1048 static HRESULT WINAPI
active_desktop_AddDesktopItemWithUI(IActiveDesktop
*iface
, HWND hwnd
, LPCOMPONENT component
, DWORD reserved
)
1050 FIXME("%p, %p, %p, %#lx.\n", iface
, hwnd
, component
, reserved
);
1055 static HRESULT WINAPI
active_desktop_ModifyDesktopItem(IActiveDesktop
*iface
, LPCCOMPONENT component
, DWORD flags
)
1057 FIXME("%p, %p, %#lx.\n", iface
, component
, flags
);
1062 static HRESULT WINAPI
active_desktop_RemoveDesktopItem(IActiveDesktop
*iface
, LPCCOMPONENT component
, DWORD reserved
)
1064 FIXME("%p, %p, %#lx.\n", iface
, component
, reserved
);
1069 static HRESULT WINAPI
active_desktop_GetDesktopItemCount(IActiveDesktop
*iface
, int *count
, DWORD reserved
)
1071 FIXME("%p, %p, %#lx.\n", iface
, count
, reserved
);
1076 static HRESULT WINAPI
active_desktop_GetDesktopItem(IActiveDesktop
*iface
, int index
, LPCOMPONENT component
, DWORD reserved
)
1078 FIXME("%p, %d, %p, %#lx.\n", iface
, index
, component
, reserved
);
1083 static HRESULT WINAPI
active_desktop_GetDesktopItemByID(IActiveDesktop
*iface
, ULONG_PTR id
, LPCOMPONENT component
, DWORD reserved
)
1085 FIXME("%p, %Ix, %p, %#lx.\n", iface
, id
, component
, reserved
);
1090 static HRESULT WINAPI
active_desktop_GenerateDesktopItemHtml(IActiveDesktop
*iface
, PCWSTR filename
, LPCOMPONENT component
, DWORD reserved
)
1092 FIXME("%p, %s, %p, %#lx.\n", iface
, debugstr_w(filename
), component
, reserved
);
1097 static HRESULT WINAPI
active_desktop_AddUrl(IActiveDesktop
*iface
, HWND hwnd
, PCWSTR source
, LPCOMPONENT component
, DWORD flags
)
1099 FIXME("%p, %p, %s, %p, %#lx.\n", iface
, hwnd
, debugstr_w(source
), component
, flags
);
1104 static HRESULT WINAPI
active_desktop_GetDesktopItemBySource(IActiveDesktop
*iface
, PCWSTR source
, LPCOMPONENT component
, DWORD reserved
)
1106 FIXME("%p, %s, %p, %#lx.\n", iface
, debugstr_w(source
), component
, reserved
);
1111 static const IActiveDesktopVtbl active_desktop_vtbl
=
1113 active_desktop_QueryInterface
,
1114 active_desktop_AddRef
,
1115 active_desktop_Release
,
1116 active_desktop_ApplyChanges
,
1117 active_desktop_GetWallpaper
,
1118 active_desktop_SetWallpaper
,
1119 active_desktop_GetWallpaperOptions
,
1120 active_desktop_SetWallpaperOptions
,
1121 active_desktop_GetPattern
,
1122 active_desktop_SetPattern
,
1123 active_desktop_GetDesktopItemOptions
,
1124 active_desktop_SetDesktopItemOptions
,
1125 active_desktop_AddDesktopItem
,
1126 active_desktop_AddDesktopItemWithUI
,
1127 active_desktop_ModifyDesktopItem
,
1128 active_desktop_RemoveDesktopItem
,
1129 active_desktop_GetDesktopItemCount
,
1130 active_desktop_GetDesktopItem
,
1131 active_desktop_GetDesktopItemByID
,
1132 active_desktop_GenerateDesktopItemHtml
,
1133 active_desktop_AddUrl
,
1134 active_desktop_GetDesktopItemBySource
,
1137 HRESULT WINAPI
ActiveDesktop_Constructor(IUnknown
*outer
, REFIID riid
, void **obj
)
1139 static IActiveDesktop object
= { &active_desktop_vtbl
};
1142 TRACE("%p, %s, %p.\n", outer
, debugstr_guid(riid
), obj
);
1145 return CLASS_E_NOAGGREGATION
;
1147 hr
= IUnknown_QueryInterface(&object
, riid
, obj
);
1148 IUnknown_Release(&object
);