wow32: Use spec file imports.
[wine.git] / dlls / shell32 / shfldr_desktop.c
blobf4df3ed0190b4a03f66731828284d87f8a6a9d57
2 /*
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
23 #include <stdlib.h>
24 #include <string.h>
25 #include <stdarg.h>
26 #include <stdio.h>
28 #define COBJMACROS
29 #define NONAMELESSUNION
31 #include "winerror.h"
32 #include "windef.h"
33 #include "winbase.h"
34 #include "winreg.h"
35 #include "wingdi.h"
36 #include "winuser.h"
38 #include "ole2.h"
39 #include "shlguid.h"
41 #include "wininet.h"
42 #include "pidl.h"
43 #include "shell32_main.h"
44 #include "shresdef.h"
45 #include "shlwapi.h"
46 #include "shellfolder.h"
47 #include "wine/debug.h"
48 #include "debughlp.h"
49 #include "shfldr.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
60 typedef struct {
61 IShellFolder2 IShellFolder2_iface;
62 IPersistFolder2 IPersistFolder2_iface;
63 LONG ref;
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 */
71 } IDesktopFolderImpl;
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;
107 *ppvObj = NULL;
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;
122 if (*ppvObj)
124 IUnknown_AddRef ((IUnknown *) (*ppvObj));
125 TRACE ("-- Interface: (%p)->(%p)\n", ppvObj, *ppvObj);
126 return S_OK;
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
145 * NOTES
146 * "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}" and "" binds
147 * to MyComputer
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;
157 PARSEDURLW urldata;
158 HRESULT hr = S_OK;
159 CLSID clsid;
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;
166 *ppidl = 0;
168 if (!lpszDisplayName) return E_INVALIDARG;
170 if (pchEaten)
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)) )
201 *ppidl = pidlTemp;
202 return S_OK;
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);
212 else
213 return IEParseDisplayNameWithBCW(CP_ACP,lpszDisplayName,pbc,ppidl);
215 else
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);
226 if (SUCCEEDED(hr))
228 hr = IShellFolder_ParseDisplayName(unixFS, NULL, NULL,
229 lpszDisplayName, NULL, &pidlTemp, NULL);
230 IShellFolder_Release(unixFS);
233 else
235 /* build a complete path to create a simple pidl */
236 WCHAR szPath[MAX_PATH];
237 LPWSTR pathPtr;
239 lstrcpynW(szPath, This->sPathTarget, MAX_PATH);
240 pathPtr = PathAddBackslashW(szPath);
241 if (pathPtr)
243 lstrcpynW(pathPtr, lpszDisplayName, MAX_PATH - (pathPtr - szPath));
244 hr = _ILCreateFromPathW(szPath, &pidlTemp);
246 else
248 /* should never reach here, but for completeness */
249 hr = E_NOT_SUFFICIENT_BUFFER;
253 else
254 pidlTemp = _ILCreateMyComputer();
256 szNext = NULL;
259 if (SUCCEEDED(hr) && pidlTemp)
261 if (szNext && *szNext)
263 hr = SHELL32_ParseNextElement(iface, hwndOwner, pbc,
264 &pidlTemp, (LPOLESTR) szNext, pchEaten, pdwAttributes);
266 else
268 if (pdwAttributes && *pdwAttributes)
269 hr = SHELL32_GetItemAttributes(iface, pidlTemp, pdwAttributes);
273 *ppidl = pidlTemp;
275 TRACE ("(%p)->(-- ret=0x%08lx)\n", This, hr);
277 return hr;
280 static void add_shell_namespace_extensions(IEnumIDListImpl *list, HKEY root)
282 WCHAR guid[39], clsidkeyW[60];
283 DWORD size, i = 0;
284 HKEY hkey;
286 if (RegOpenKeyExW(root, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Desktop\\Namespace", 0, KEY_READ, &hkey))
287 return;
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);
304 RegCloseKey(hkey);
307 /**************************************************************************
308 * CreateDesktopEnumList()
310 static BOOL CreateDesktopEnumList(IEnumIDListImpl *list, DWORD dwFlags)
312 BOOL ret = TRUE;
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);
329 return ret;
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);
351 return S_OK;
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);
379 *ppvOut = NULL;
380 return E_NOTIMPL;
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);
390 HRESULT hr;
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);
395 return 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);
411 if (!ppvOut)
412 return E_INVALIDARG;
414 *ppvOut = NULL;
416 if (IsEqualIID (riid, &IID_IDropTarget))
418 WARN ("IDropTarget not implemented\n");
419 hr = E_NOTIMPL;
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);
428 if (pShellView)
430 hr = IShellView_QueryInterface (pShellView, riid, ppvOut);
431 IShellView_Release (pShellView);
434 TRACE ("-- (%p)->(interface=%p)\n", This, ppvOut);
435 return hr;
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);
456 if (!rgfInOut)
457 return E_INVALIDARG;
458 if (cidl && !apidl)
459 return E_INVALIDARG;
461 if (*rgfInOut == 0)
462 *rgfInOut = ~0;
464 if(cidl == 0) {
465 *rgfInOut &= dwDesktopAttributes;
466 } else {
467 while (cidl > 0 && *apidl) {
468 pdump (*apidl);
469 if (_ILIsDesktop(*apidl)) {
470 *rgfInOut &= dwDesktopAttributes;
471 } else if (_ILIsMyComputer(*apidl)) {
472 *rgfInOut &= dwMyComputerAttributes;
473 } else {
474 SHELL32_GetItemAttributes(iface, *apidl, rgfInOut);
476 apidl++;
477 cidl--;
480 /* make sure SFGAO_VALIDATE is cleared, some apps depend on that */
481 *rgfInOut &= ~SFGAO_VALIDATE;
483 TRACE ("-- result=0x%08lx\n", *rgfInOut);
485 return S_OK;
488 /**************************************************************************
489 * ISF_Desktop_fnGetUIObjectOf
491 * PARAMETERS
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);
506 LPITEMIDLIST pidl;
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);
513 if (!ppvOut)
514 return E_INVALIDARG;
516 *ppvOut = NULL;
518 if (IsEqualIID (riid, &IID_IContextMenu))
520 if (cidl > 0)
521 return ItemMenu_Constructor((IShellFolder*)iface, This->pidlRoot, apidl, cidl, riid, ppvOut);
522 else
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);
529 hr = S_OK;
531 else if (IsEqualIID (riid, &IID_IExtractIconA) && (cidl == 1))
533 pidl = ILCombine (This->pidlRoot, apidl[0]);
534 pObj = (LPUNKNOWN) IExtractIconA_Constructor (pidl);
535 SHFree (pidl);
536 hr = S_OK;
538 else if (IsEqualIID (riid, &IID_IExtractIconW) && (cidl == 1))
540 pidl = ILCombine (This->pidlRoot, apidl[0]);
541 pObj = (LPUNKNOWN) IExtractIconW_Constructor (pidl);
542 SHFree (pidl);
543 hr = S_OK;
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);
555 SHFree (pidl);
557 else
558 hr = E_NOINTERFACE;
560 if (SUCCEEDED(hr) && !pObj)
561 hr = E_OUTOFMEMORY;
563 *ppvOut = pObj;
564 TRACE ("(%p)->hr=0x%08lx\n", This, hr);
565 return hr;
568 /**************************************************************************
569 * ISF_Desktop_fnGetDisplayNameOf
571 * NOTES
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);
578 HRESULT hr = S_OK;
579 LPWSTR pszPath;
581 TRACE ("(%p)->(pidl=%p,0x%08lx,%p)\n", This, pidl, dwFlags, strRet);
582 pdump (pidl);
584 if (!strRet)
585 return E_INVALIDARG;
587 pszPath = CoTaskMemAlloc((MAX_PATH +1) * sizeof(WCHAR));
588 if (!pszPath)
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);
596 else
597 HCR_GetClassNameW(&CLSID_ShellDesktop, pszPath, MAX_PATH);
599 else if (_ILIsPidlSimple (pidl))
601 GUID const *clsid;
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;
620 else
622 /* get the "WantsFORPARSING" flag from the registry */
623 WCHAR szRegPath[100];
624 LONG r;
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;
632 else
633 bWantsForParsing = FALSE;
636 if ((GET_SHGDN_RELATION (dwFlags) == SHGDN_NORMAL) &&
637 bWantsForParsing)
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,
644 pszPath,
645 MAX_PATH);
647 else
649 /* parsing name like ::{...} */
650 pszPath[0] = ':';
651 pszPath[1] = ':';
652 SHELL32_GUIDToStringW (clsid, &pszPath[2]);
655 else
657 /* user friendly name */
658 HCR_GetClassNameW (clsid, pszPath, MAX_PATH);
661 else
663 int cLen = 0;
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);
680 else
682 /* a complex pidl, let the subfolder do the work */
683 hr = SHELL32_GetDisplayNameOfChild (iface, pidl, dwFlags,
684 pszPath, MAX_PATH);
687 if (SUCCEEDED(hr))
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,
694 NULL, NULL))
695 strRet->u.cStr[0] = '\0';
696 CoTaskMemFree(pszPath);
698 else
700 strRet->uType = STRRET_WSTR;
701 strRet->u.pOleStr = pszPath;
704 else
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);
710 return 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.
718 * PARAMETERS
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);
734 return E_FAIL;
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);
741 return E_NOTIMPL;
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);
749 return E_NOTIMPL;
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);
758 return E_NOTIMPL;
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))
769 return E_INVALIDARG;
771 *pcsFlags = desktop_header[iColumn].pcsFlags;
773 return S_OK;
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);
781 return E_NOTIMPL;
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))
792 return E_INVALIDARG;
794 if (!pidl)
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))
807 return E_INVALIDARG;
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,
827 /* ShellFolder2 */
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 /**************************************************************************
838 * IPersist
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;
865 return S_OK;
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);
872 return E_NOTIMPL;
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);
879 return S_OK;
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));
910 if (!ppv)
911 return E_POINTER;
912 if (pUnkOuter)
913 return CLASS_E_NOAGGREGATION;
915 if (!cached_sf)
917 IDesktopFolderImpl *sf;
919 if (!SHGetSpecialFolderPathW( 0, szMyPath, CSIDL_DESKTOPDIRECTORY, FALSE ))
920 return E_UNEXPECTED;
922 sf = LocalAlloc( LMEM_ZEROINIT, sizeof (IDesktopFolderImpl) );
923 if (!sf)
924 return E_OUTOFMEMORY;
926 sf->ref = 1;
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 );
938 LocalFree( sf );
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);
949 *obj = NULL;
951 if (IsEqualIID(riid, &IID_IActiveDesktop)
952 || IsEqualIID(riid, &IID_IUnknown))
954 *obj = iface;
957 if (*obj)
959 IUnknown_AddRef((IUnknown *)*obj);
960 return S_OK;
963 WARN("Unsupported interface %s.\n", debugstr_guid(riid));
964 *obj = NULL;
965 return E_NOINTERFACE;
968 static ULONG WINAPI active_desktop_AddRef(IActiveDesktop *iface)
970 return 2;
973 static ULONG WINAPI active_desktop_Release(IActiveDesktop *iface)
975 return 1;
978 static HRESULT WINAPI active_desktop_ApplyChanges(IActiveDesktop *iface, DWORD flags)
980 FIXME("%p, %#lx.\n", iface, flags);
982 return E_NOTIMPL;
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);
989 return E_NOTIMPL;
992 static HRESULT WINAPI active_desktop_SetWallpaper(IActiveDesktop *iface, PCWSTR wallpaper, DWORD reserved)
994 FIXME("%p, %s, %#lx.\n", iface, debugstr_w(wallpaper), reserved);
996 return E_NOTIMPL;
999 static HRESULT WINAPI active_desktop_GetWallpaperOptions(IActiveDesktop *iface, LPWALLPAPEROPT options, DWORD reserved)
1001 FIXME("%p, %p, %#lx.\n", iface, options, reserved);
1003 return E_NOTIMPL;
1006 static HRESULT WINAPI active_desktop_SetWallpaperOptions(IActiveDesktop *iface, LPCWALLPAPEROPT options, DWORD reserved)
1008 FIXME("%p, %p, %#lx.\n", iface, options, reserved);
1010 return E_NOTIMPL;
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);
1017 return E_NOTIMPL;
1020 static HRESULT WINAPI active_desktop_SetPattern(IActiveDesktop *iface, PCWSTR pattern, DWORD reserved)
1022 FIXME("%p, %s, %#lx.\n", iface, debugstr_w(pattern), reserved);
1024 return E_NOTIMPL;
1027 static HRESULT WINAPI active_desktop_GetDesktopItemOptions(IActiveDesktop *iface, LPCOMPONENTSOPT options, DWORD reserved)
1029 FIXME("%p, %p, %#lx.\n", iface, options, reserved);
1031 return E_NOTIMPL;
1034 static HRESULT WINAPI active_desktop_SetDesktopItemOptions(IActiveDesktop *iface, LPCCOMPONENTSOPT options, DWORD reserved)
1036 FIXME("%p, %p, %#lx.\n", iface, options, reserved);
1038 return E_NOTIMPL;
1041 static HRESULT WINAPI active_desktop_AddDesktopItem(IActiveDesktop *iface, LPCCOMPONENT component, DWORD reserved)
1043 FIXME("%p, %p, %#lx.\n", iface, component, reserved);
1045 return E_NOTIMPL;
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);
1052 return E_NOTIMPL;
1055 static HRESULT WINAPI active_desktop_ModifyDesktopItem(IActiveDesktop *iface, LPCCOMPONENT component, DWORD flags)
1057 FIXME("%p, %p, %#lx.\n", iface, component, flags);
1059 return E_NOTIMPL;
1062 static HRESULT WINAPI active_desktop_RemoveDesktopItem(IActiveDesktop *iface, LPCCOMPONENT component, DWORD reserved)
1064 FIXME("%p, %p, %#lx.\n", iface, component, reserved);
1066 return E_NOTIMPL;
1069 static HRESULT WINAPI active_desktop_GetDesktopItemCount(IActiveDesktop *iface, int *count, DWORD reserved)
1071 FIXME("%p, %p, %#lx.\n", iface, count, reserved);
1073 return E_NOTIMPL;
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);
1080 return E_NOTIMPL;
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);
1087 return E_NOTIMPL;
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);
1094 return E_NOTIMPL;
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);
1101 return E_NOTIMPL;
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);
1108 return E_NOTIMPL;
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 };
1140 HRESULT hr;
1142 TRACE("%p, %s, %p.\n", outer, debugstr_guid(riid), obj);
1144 if (outer)
1145 return CLASS_E_NOAGGREGATION;
1147 hr = IUnknown_QueryInterface(&object, riid, obj);
1148 IUnknown_Release(&object);
1150 return hr;