wined3d: Add basic support for rendering to 3D textures.
[wine.git] / dlls / shell32 / shfldr_desktop.c
blobe4cdeb154b3b20b908c43c24b8298d9190d50746
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 "config.h"
24 #include "wine/port.h"
26 #include <stdlib.h>
27 #include <string.h>
28 #include <stdarg.h>
29 #include <stdio.h>
31 #define COBJMACROS
32 #define NONAMELESSUNION
34 #include "winerror.h"
35 #include "windef.h"
36 #include "winbase.h"
37 #include "winreg.h"
38 #include "wingdi.h"
39 #include "winuser.h"
41 #include "ole2.h"
42 #include "shlguid.h"
44 #include "pidl.h"
45 #include "undocshell.h"
46 #include "shell32_main.h"
47 #include "shresdef.h"
48 #include "shlwapi.h"
49 #include "shellfolder.h"
50 #include "wine/debug.h"
51 #include "debughlp.h"
52 #include "shfldr.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
63 typedef struct {
64 IShellFolder2 IShellFolder2_iface;
65 IPersistFolder2 IPersistFolder2_iface;
66 LONG ref;
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 */
74 } IDesktopFolderImpl;
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;
111 *ppvObj = NULL;
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;
126 if (*ppvObj)
128 IUnknown_AddRef ((IUnknown *) (*ppvObj));
129 TRACE ("-- Interface: (%p)->(%p)\n", ppvObj, *ppvObj);
130 return S_OK;
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
149 * NOTES
150 * "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}" and "" binds
151 * to MyComputer
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;
161 PARSEDURLW urldata;
162 HRESULT hr = S_OK;
163 CLSID clsid;
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;
170 *ppidl = 0;
172 if (!lpszDisplayName) return E_INVALIDARG;
174 if (pchEaten)
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);
191 else
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)) )
202 *ppidl = pidlTemp;
203 return S_OK;
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);
213 else
214 return IEParseDisplayNameWithBCW(CP_ACP,lpszDisplayName,pbc,ppidl);
216 else
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);
227 if (SUCCEEDED(hr))
229 hr = IShellFolder_ParseDisplayName(unixFS, NULL, NULL,
230 lpszDisplayName, NULL, &pidlTemp, NULL);
231 IShellFolder_Release(unixFS);
234 else
236 /* build a complete path to create a simple pidl */
237 WCHAR szPath[MAX_PATH];
238 LPWSTR pathPtr;
240 lstrcpynW(szPath, This->sPathTarget, MAX_PATH);
241 pathPtr = PathAddBackslashW(szPath);
242 if (pathPtr)
244 lstrcpynW(pathPtr, lpszDisplayName, MAX_PATH - (pathPtr - szPath));
245 hr = _ILCreateFromPathW(szPath, &pidlTemp);
247 else
249 /* should never reach here, but for completeness */
250 hr = E_NOT_SUFFICIENT_BUFFER;
254 else
255 pidlTemp = _ILCreateMyComputer();
257 szNext = NULL;
260 if (SUCCEEDED(hr) && pidlTemp)
262 if (szNext && *szNext)
264 hr = SHELL32_ParseNextElement(iface, hwndOwner, pbc,
265 &pidlTemp, (LPOLESTR) szNext, pchEaten, pdwAttributes);
267 else
269 if (pdwAttributes && *pdwAttributes)
270 hr = SHELL32_GetItemAttributes(iface, pidlTemp, pdwAttributes);
274 *ppidl = pidlTemp;
276 TRACE ("(%p)->(-- ret=0x%08x)\n", This, hr);
278 return 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];
292 DWORD size, i = 0;
293 HKEY hkey;
295 if (RegOpenKeyExW(root, Desktop_NameSpaceW, 0, KEY_READ, &hkey))
296 return;
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]);
313 RegCloseKey(hkey);
316 /**************************************************************************
317 * CreateDesktopEnumList()
319 static BOOL CreateDesktopEnumList(IEnumIDListImpl *list, DWORD dwFlags)
321 BOOL ret = TRUE;
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);
338 return ret;
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);
360 return S_OK;
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);
388 *ppvOut = NULL;
389 return E_NOTIMPL;
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);
399 HRESULT hr;
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);
404 return 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);
420 if (!ppvOut)
421 return E_INVALIDARG;
423 *ppvOut = NULL;
425 if (IsEqualIID (riid, &IID_IDropTarget))
427 WARN ("IDropTarget not implemented\n");
428 hr = E_NOTIMPL;
430 else if (IsEqualIID (riid, &IID_IContextMenu))
432 WARN ("IContextMenu not implemented\n");
433 hr = E_NOTIMPL;
435 else if (IsEqualIID (riid, &IID_IShellView))
437 pShellView = IShellView_Constructor ((IShellFolder *) iface);
438 if (pShellView)
440 hr = IShellView_QueryInterface (pShellView, riid, ppvOut);
441 IShellView_Release (pShellView);
444 TRACE ("-- (%p)->(interface=%p)\n", This, ppvOut);
445 return hr;
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);
466 if (!rgfInOut)
467 return E_INVALIDARG;
468 if (cidl && !apidl)
469 return E_INVALIDARG;
471 if (*rgfInOut == 0)
472 *rgfInOut = ~0;
474 if(cidl == 0) {
475 *rgfInOut &= dwDesktopAttributes;
476 } else {
477 while (cidl > 0 && *apidl) {
478 pdump (*apidl);
479 if (_ILIsDesktop(*apidl)) {
480 *rgfInOut &= dwDesktopAttributes;
481 } else if (_ILIsMyComputer(*apidl)) {
482 *rgfInOut &= dwMyComputerAttributes;
483 } else {
484 SHELL32_GetItemAttributes(iface, *apidl, rgfInOut);
486 apidl++;
487 cidl--;
490 /* make sure SFGAO_VALIDATE is cleared, some apps depend on that */
491 *rgfInOut &= ~SFGAO_VALIDATE;
493 TRACE ("-- result=0x%08x\n", *rgfInOut);
495 return S_OK;
498 /**************************************************************************
499 * ISF_Desktop_fnGetUIObjectOf
501 * PARAMETERS
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);
516 LPITEMIDLIST pidl;
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);
523 if (!ppvOut)
524 return E_INVALIDARG;
526 *ppvOut = NULL;
528 if (IsEqualIID (riid, &IID_IContextMenu))
530 if (cidl > 0)
531 return ItemMenu_Constructor((IShellFolder*)iface, This->pidlRoot, apidl, cidl, riid, ppvOut);
532 else
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);
539 hr = S_OK;
541 else if (IsEqualIID (riid, &IID_IExtractIconA) && (cidl == 1))
543 pidl = ILCombine (This->pidlRoot, apidl[0]);
544 pObj = (LPUNKNOWN) IExtractIconA_Constructor (pidl);
545 SHFree (pidl);
546 hr = S_OK;
548 else if (IsEqualIID (riid, &IID_IExtractIconW) && (cidl == 1))
550 pidl = ILCombine (This->pidlRoot, apidl[0]);
551 pObj = (LPUNKNOWN) IExtractIconW_Constructor (pidl);
552 SHFree (pidl);
553 hr = S_OK;
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);
565 SHFree (pidl);
567 else
568 hr = E_NOINTERFACE;
570 if (SUCCEEDED(hr) && !pObj)
571 hr = E_OUTOFMEMORY;
573 *ppvOut = pObj;
574 TRACE ("(%p)->hr=0x%08x\n", This, hr);
575 return hr;
578 /**************************************************************************
579 * ISF_Desktop_fnGetDisplayNameOf
581 * NOTES
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);
588 HRESULT hr = S_OK;
589 LPWSTR pszPath;
591 TRACE ("(%p)->(pidl=%p,0x%08x,%p)\n", This, pidl, dwFlags, strRet);
592 pdump (pidl);
594 if (!strRet)
595 return E_INVALIDARG;
597 pszPath = CoTaskMemAlloc((MAX_PATH +1) * sizeof(WCHAR));
598 if (!pszPath)
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);
606 else
607 HCR_GetClassNameW(&CLSID_ShellDesktop, pszPath, MAX_PATH);
609 else if (_ILIsPidlSimple (pidl))
611 GUID const *clsid;
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;
630 else
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',
639 'g',0 };
640 WCHAR szRegPath[100];
641 LONG r;
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;
650 else
651 bWantsForParsing = FALSE;
654 if ((GET_SHGDN_RELATION (dwFlags) == SHGDN_NORMAL) &&
655 bWantsForParsing)
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,
662 pszPath,
663 MAX_PATH);
665 else
667 /* parsing name like ::{...} */
668 pszPath[0] = ':';
669 pszPath[1] = ':';
670 SHELL32_GUIDToStringW (clsid, &pszPath[2]);
673 else
675 /* user friendly name */
676 HCR_GetClassNameW (clsid, pszPath, MAX_PATH);
679 else
681 int cLen = 0;
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);
698 else
700 /* a complex pidl, let the subfolder do the work */
701 hr = SHELL32_GetDisplayNameOfChild (iface, pidl, dwFlags,
702 pszPath, MAX_PATH);
705 if (SUCCEEDED(hr))
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,
712 NULL, NULL))
713 strRet->u.cStr[0] = '\0';
714 CoTaskMemFree(pszPath);
716 else
718 strRet->uType = STRRET_WSTR;
719 strRet->u.pOleStr = pszPath;
722 else
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);
728 return 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.
736 * PARAMETERS
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);
752 return E_FAIL;
755 static HRESULT WINAPI ISF_Desktop_fnGetDefaultSearchGUID(IShellFolder2 *iface,
756 GUID * pguid)
758 IDesktopFolderImpl *This = impl_from_IShellFolder2(iface);
759 FIXME ("(%p)->(%p) stub\n", This, pguid);
760 return E_NOTIMPL;
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);
768 return E_NOTIMPL;
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);
778 if (pSort)
779 *pSort = 0;
780 if (pDisplay)
781 *pDisplay = 0;
783 return S_OK;
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)
793 return E_INVALIDARG;
795 *pcsFlags = desktop_header[iColumn].pcsFlags;
797 return S_OK;
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);
805 return E_NOTIMPL;
808 static HRESULT WINAPI ISF_Desktop_fnGetDetailsOf (IShellFolder2 * iface,
809 LPCITEMIDLIST pidl, UINT iColumn, SHELLDETAILS * psd)
811 IDesktopFolderImpl *This = impl_from_IShellFolder2(iface);
813 HRESULT hr = S_OK;
815 TRACE ("(%p)->(%p %i %p)\n", This, pidl, iColumn, psd);
817 if (!psd || iColumn >= DESKTOPSHELLVIEWCOLUMNS)
818 return E_INVALIDARG;
820 if (!pidl)
821 return SHELL32_GetColumnDetails(desktop_header, iColumn, psd);
823 /* the data from the pidl */
824 psd->str.uType = STRRET_CSTR;
825 switch (iColumn)
827 case 0: /* name */
828 hr = IShellFolder2_GetDisplayNameOf(iface, pidl,
829 SHGDN_NORMAL | SHGDN_INFOLDER, &psd->str);
830 break;
831 case 1: /* size */
832 _ILGetFileSize (pidl, psd->str.u.cStr, MAX_PATH);
833 break;
834 case 2: /* type */
835 _ILGetFileType (pidl, psd->str.u.cStr, MAX_PATH);
836 break;
837 case 3: /* date */
838 _ILGetFileDate (pidl, psd->str.u.cStr, MAX_PATH);
839 break;
840 case 4: /* attributes */
841 _ILGetFileAttributes (pidl, psd->str.u.cStr, MAX_PATH);
842 break;
845 return hr;
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);
853 return E_NOTIMPL;
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,
871 /* ShellFolder2 */
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 /**************************************************************************
882 * IPersist
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;
909 return S_OK;
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);
916 return E_NOTIMPL;
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);
923 return S_OK;
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));
954 if (!ppv)
955 return E_POINTER;
956 if (pUnkOuter)
957 return CLASS_E_NOAGGREGATION;
959 if (!cached_sf)
961 IDesktopFolderImpl *sf;
963 if (!SHGetSpecialFolderPathW( 0, szMyPath, CSIDL_DESKTOPDIRECTORY, TRUE ))
964 return E_UNEXPECTED;
966 sf = LocalAlloc( LMEM_ZEROINIT, sizeof (IDesktopFolderImpl) );
967 if (!sf)
968 return E_OUTOFMEMORY;
970 sf->ref = 1;
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 );
982 LocalFree( sf );
986 return IShellFolder2_QueryInterface( &cached_sf->IShellFolder2_iface, riid, ppv );