wined3d: Fix a comment.
[wine/hramrach.git] / dlls / shell32 / shfldr_desktop.c
blob30aea3b18a44127e9650e9318c5cb717d97858b2
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
33 #define NONAMELESSSTRUCT
35 #include "winerror.h"
36 #include "windef.h"
37 #include "winbase.h"
38 #include "winreg.h"
39 #include "wingdi.h"
40 #include "winuser.h"
42 #include "ole2.h"
43 #include "shlguid.h"
45 #include "enumidlist.h"
46 #include "pidl.h"
47 #include "undocshell.h"
48 #include "shell32_main.h"
49 #include "shresdef.h"
50 #include "shlwapi.h"
51 #include "shellfolder.h"
52 #include "wine/debug.h"
53 #include "debughlp.h"
54 #include "shfldr.h"
56 WINE_DEFAULT_DEBUG_CHANNEL (shell);
58 /* Undocumented functions from shdocvw */
59 extern HRESULT WINAPI IEParseDisplayNameWithBCW(DWORD codepage, LPCWSTR lpszDisplayName, LPBC pbc, LPITEMIDLIST *ppidl);
62 /***********************************************************************
63 * Desktopfolder implementation
66 typedef struct {
67 const IShellFolder2Vtbl *lpVtbl;
68 const IPersistVtbl *lpVtblIPersist;
69 LONG ref;
71 /* both paths are parsible from the desktop */
72 LPWSTR sPathTarget; /* complete path to target used for enumeration and ChangeNotify */
73 LPITEMIDLIST pidlRoot; /* absolute pidl */
75 UINT cfShellIDList; /* clipboardformat for IDropTarget */
76 BOOL fAcceptFmt; /* flag for pending Drop */
77 } IDesktopFolderImpl;
79 static inline IDesktopFolderImpl *impl_from_IPersist( IPersist *iface )
81 return (IDesktopFolderImpl *)((char*)iface - FIELD_OFFSET(IDesktopFolderImpl, lpVtblIPersist));
84 static const shvheader desktop_header[] = {
85 {IDS_SHV_COLUMN1, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 15},
86 {IDS_SHV_COLUMN2, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
87 {IDS_SHV_COLUMN3, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
88 {IDS_SHV_COLUMN4, SHCOLSTATE_TYPE_DATE | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 12},
89 {IDS_SHV_COLUMN5, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 5}
92 #define DESKTOPSHELLVIEWCOLUMNS sizeof(desktop_header)/sizeof(shvheader)
94 /**************************************************************************
95 * ISF_Desktop_fnQueryInterface
97 * NOTES supports not IPersistFolder
99 static HRESULT WINAPI ISF_Desktop_fnQueryInterface(
100 IShellFolder2 * iface, REFIID riid, LPVOID * ppvObj)
102 IDesktopFolderImpl *This = (IDesktopFolderImpl *)iface;
104 TRACE ("(%p)->(%s,%p)\n", This, shdebugstr_guid (riid), ppvObj);
106 *ppvObj = NULL;
108 if (IsEqualIID (riid, &IID_IUnknown) ||
109 IsEqualIID (riid, &IID_IShellFolder) ||
110 IsEqualIID (riid, &IID_IShellFolder2))
112 *ppvObj = This;
114 else if (IsEqualIID (riid, &IID_IPersist))
116 *ppvObj = &This->lpVtblIPersist;
119 if (*ppvObj)
121 IUnknown_AddRef ((IUnknown *) (*ppvObj));
122 TRACE ("-- Interface: (%p)->(%p)\n", ppvObj, *ppvObj);
123 return S_OK;
125 TRACE ("-- Interface: E_NOINTERFACE\n");
126 return E_NOINTERFACE;
129 static ULONG WINAPI ISF_Desktop_fnAddRef (IShellFolder2 * iface)
131 return 2; /* non-heap based object */
134 static ULONG WINAPI ISF_Desktop_fnRelease (IShellFolder2 * iface)
136 return 1; /* non-heap based object */
139 /**************************************************************************
140 * ISF_Desktop_fnParseDisplayName
142 * NOTES
143 * "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}" and "" binds
144 * to MyComputer
146 static HRESULT WINAPI ISF_Desktop_fnParseDisplayName (IShellFolder2 * iface,
147 HWND hwndOwner, LPBC pbc, LPOLESTR lpszDisplayName,
148 DWORD * pchEaten, LPITEMIDLIST * ppidl, DWORD * pdwAttributes)
150 IDesktopFolderImpl *This = (IDesktopFolderImpl *)iface;
151 IShellFolder *shell_folder = (IShellFolder*)iface;
152 WCHAR szElement[MAX_PATH];
153 LPCWSTR szNext = NULL;
154 LPITEMIDLIST pidlTemp = NULL;
155 HRESULT hr = S_OK;
156 CLSID clsid;
158 TRACE ("(%p)->(HWND=%p,%p,%p=%s,%p,pidl=%p,%p)\n",
159 This, hwndOwner, pbc, lpszDisplayName, debugstr_w(lpszDisplayName),
160 pchEaten, ppidl, pdwAttributes);
162 if (!ppidl) return E_INVALIDARG;
163 *ppidl = 0;
165 if (!lpszDisplayName) return E_INVALIDARG;
167 if (pchEaten)
168 *pchEaten = 0; /* strange but like the original */
170 if (lpszDisplayName[0] == ':' && lpszDisplayName[1] == ':')
172 szNext = GetNextElementW (lpszDisplayName, szElement, MAX_PATH);
173 TRACE ("-- element: %s\n", debugstr_w (szElement));
174 SHCLSIDFromStringW (szElement + 2, &clsid);
175 pidlTemp = _ILCreateGuid (PT_GUID, &clsid);
177 else if (PathGetDriveNumberW (lpszDisplayName) >= 0)
179 /* it's a filesystem path with a drive. Let MyComputer/UnixDosFolder parse it */
180 if (UNIXFS_is_rooted_at_desktop())
181 pidlTemp = _ILCreateGuid(PT_GUID, &CLSID_UnixDosFolder);
182 else
183 pidlTemp = _ILCreateMyComputer ();
184 szNext = lpszDisplayName;
186 else if (PathIsUNCW(lpszDisplayName))
188 pidlTemp = _ILCreateNetwork();
189 szNext = lpszDisplayName;
191 else if( (pidlTemp = SHELL32_CreatePidlFromBindCtx(pbc, lpszDisplayName)) )
193 *ppidl = pidlTemp;
194 return S_OK;
196 else if (strchrW(lpszDisplayName,':'))
198 PARSEDURLW urldata;
200 urldata.cbSize = sizeof(urldata);
201 ParseURLW(lpszDisplayName,&urldata);
203 if (urldata.nScheme == URL_SCHEME_SHELL) /* handle shell: urls */
205 TRACE ("-- shell url: %s\n", debugstr_w(urldata.pszSuffix));
206 SHCLSIDFromStringW (urldata.pszSuffix+2, &clsid);
207 pidlTemp = _ILCreateGuid (PT_GUID, &clsid);
209 else
210 return IEParseDisplayNameWithBCW(CP_ACP,lpszDisplayName,pbc,ppidl);
212 else
214 /* it's a filesystem path on the desktop. Let a FSFolder parse it */
216 if (*lpszDisplayName)
218 WCHAR szPath[MAX_PATH];
219 LPWSTR pathPtr;
221 /* build a complete path to create a simple pidl */
222 lstrcpynW(szPath, This->sPathTarget, MAX_PATH);
223 pathPtr = PathAddBackslashW(szPath);
224 if (pathPtr)
226 lstrcpynW(pathPtr, lpszDisplayName, MAX_PATH - (pathPtr - szPath));
227 hr = _ILCreateFromPathW(szPath, &pidlTemp);
229 else
231 /* should never reach here, but for completeness */
232 hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
235 else
236 pidlTemp = _ILCreateMyComputer();
238 szNext = NULL;
241 if (SUCCEEDED(hr) && pidlTemp)
243 if (szNext && *szNext)
245 hr = SHELL32_ParseNextElement(iface, hwndOwner, pbc,
246 &pidlTemp, (LPOLESTR) szNext, pchEaten, pdwAttributes);
248 else
250 if (pdwAttributes && *pdwAttributes)
251 hr = SHELL32_GetItemAttributes(shell_folder, pidlTemp, pdwAttributes);
255 *ppidl = pidlTemp;
257 TRACE ("(%p)->(-- ret=0x%08x)\n", This, hr);
259 return hr;
262 /**************************************************************************
263 * CreateDesktopEnumList()
265 static const WCHAR Desktop_NameSpaceW[] = { 'S','O','F','T','W','A','R','E',
266 '\\','M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
267 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\','E','x','p','l',
268 'o','r','e','r','\\','D','e','s','k','t','o','p','\\','N','a','m','e','s','p',
269 'a','c','e','\0' };
271 static BOOL CreateDesktopEnumList(IEnumIDList *list, DWORD dwFlags)
273 BOOL ret = TRUE;
274 WCHAR szPath[MAX_PATH];
276 TRACE("(%p)->(flags=0x%08x)\n", list, dwFlags);
278 /* enumerate the root folders */
279 if (dwFlags & SHCONTF_FOLDERS)
281 HKEY hkey;
282 UINT i;
284 /* create the pidl for This item */
285 ret = AddToEnumList(list, _ILCreateMyComputer());
287 for (i=0; i<2; i++) {
288 if (ret && !RegOpenKeyExW(i == 0 ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER,
289 Desktop_NameSpaceW, 0, KEY_READ, &hkey))
291 WCHAR iid[50];
292 int i=0;
294 while (ret)
296 DWORD size;
297 LONG r;
299 size = sizeof (iid) / sizeof (iid[0]);
300 r = RegEnumKeyExW(hkey, i, iid, &size, 0, NULL, NULL, NULL);
301 if (ERROR_SUCCESS == r)
303 ret = AddToEnumList(list, _ILCreateGuidFromStrW(iid));
304 i++;
306 else if (ERROR_NO_MORE_ITEMS == r)
307 break;
308 else
309 ret = FALSE;
311 RegCloseKey(hkey);
316 /* enumerate the elements in %windir%\desktop */
317 SHGetSpecialFolderPathW(0, szPath, CSIDL_DESKTOPDIRECTORY, FALSE);
318 ret = ret && CreateFolderEnumList(list, szPath, dwFlags);
320 return ret;
323 /**************************************************************************
324 * ISF_Desktop_fnEnumObjects
326 static HRESULT WINAPI ISF_Desktop_fnEnumObjects (IShellFolder2 * iface,
327 HWND hwndOwner, DWORD dwFlags, LPENUMIDLIST * ppEnumIDList)
329 IDesktopFolderImpl *This = (IDesktopFolderImpl *)iface;
331 TRACE ("(%p)->(HWND=%p flags=0x%08x pplist=%p)\n",
332 This, hwndOwner, dwFlags, ppEnumIDList);
334 *ppEnumIDList = IEnumIDList_Constructor();
335 if (*ppEnumIDList)
336 CreateDesktopEnumList(*ppEnumIDList, dwFlags);
338 TRACE ("-- (%p)->(new ID List: %p)\n", This, *ppEnumIDList);
340 return *ppEnumIDList ? S_OK : E_OUTOFMEMORY;
343 /**************************************************************************
344 * ISF_Desktop_fnBindToObject
346 static HRESULT WINAPI ISF_Desktop_fnBindToObject (IShellFolder2 * iface,
347 LPCITEMIDLIST pidl, LPBC pbcReserved, REFIID riid, LPVOID * ppvOut)
349 IDesktopFolderImpl *This = (IDesktopFolderImpl *)iface;
351 TRACE ("(%p)->(pidl=%p,%p,%s,%p)\n",
352 This, pidl, pbcReserved, shdebugstr_guid (riid), ppvOut);
354 return SHELL32_BindToChild( This->pidlRoot, This->sPathTarget, pidl, riid, ppvOut );
357 /**************************************************************************
358 * ISF_Desktop_fnBindToStorage
360 static HRESULT WINAPI ISF_Desktop_fnBindToStorage (IShellFolder2 * iface,
361 LPCITEMIDLIST pidl, LPBC pbcReserved, REFIID riid, LPVOID * ppvOut)
363 IDesktopFolderImpl *This = (IDesktopFolderImpl *)iface;
365 FIXME ("(%p)->(pidl=%p,%p,%s,%p) stub\n",
366 This, pidl, pbcReserved, shdebugstr_guid (riid), ppvOut);
368 *ppvOut = NULL;
369 return E_NOTIMPL;
372 /**************************************************************************
373 * ISF_Desktop_fnCompareIDs
375 static HRESULT WINAPI ISF_Desktop_fnCompareIDs (IShellFolder2 *iface,
376 LPARAM lParam, LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
378 IDesktopFolderImpl *This = (IDesktopFolderImpl *)iface;
379 IShellFolder *shell_folder = (IShellFolder*)iface;
380 HRESULT hr;
382 TRACE ("(%p)->(0x%08lx,pidl1=%p,pidl2=%p)\n", This, lParam, pidl1, pidl2);
383 hr = SHELL32_CompareIDs ( shell_folder, lParam, pidl1, pidl2);
384 TRACE ("-- 0x%08x\n", hr);
385 return hr;
388 /**************************************************************************
389 * ISF_Desktop_fnCreateViewObject
391 static HRESULT WINAPI ISF_Desktop_fnCreateViewObject (IShellFolder2 * iface,
392 HWND hwndOwner, REFIID riid, LPVOID * ppvOut)
394 IDesktopFolderImpl *This = (IDesktopFolderImpl *)iface;
395 LPSHELLVIEW pShellView;
396 HRESULT hr = E_INVALIDARG;
398 TRACE ("(%p)->(hwnd=%p,%s,%p)\n",
399 This, hwndOwner, shdebugstr_guid (riid), ppvOut);
401 if (!ppvOut)
402 return E_INVALIDARG;
404 *ppvOut = NULL;
406 if (IsEqualIID (riid, &IID_IDropTarget))
408 WARN ("IDropTarget not implemented\n");
409 hr = E_NOTIMPL;
411 else if (IsEqualIID (riid, &IID_IContextMenu))
413 WARN ("IContextMenu not implemented\n");
414 hr = E_NOTIMPL;
416 else if (IsEqualIID (riid, &IID_IShellView))
418 pShellView = IShellView_Constructor ((IShellFolder *) iface);
419 if (pShellView)
421 hr = IShellView_QueryInterface (pShellView, riid, ppvOut);
422 IShellView_Release (pShellView);
425 TRACE ("-- (%p)->(interface=%p)\n", This, ppvOut);
426 return hr;
429 /**************************************************************************
430 * ISF_Desktop_fnGetAttributesOf
432 static HRESULT WINAPI ISF_Desktop_fnGetAttributesOf (IShellFolder2 * iface,
433 UINT cidl, LPCITEMIDLIST * apidl, DWORD * rgfInOut)
435 IDesktopFolderImpl *This = (IDesktopFolderImpl *)iface;
436 IShellFolder *shell_folder = (IShellFolder*)iface;
438 static const DWORD dwDesktopAttributes =
439 SFGAO_STORAGE | SFGAO_HASPROPSHEET | SFGAO_STORAGEANCESTOR |
440 SFGAO_FILESYSANCESTOR | SFGAO_FOLDER | SFGAO_FILESYSTEM | SFGAO_HASSUBFOLDER;
441 static const DWORD dwMyComputerAttributes =
442 SFGAO_CANRENAME | SFGAO_CANDELETE | SFGAO_HASPROPSHEET |
443 SFGAO_DROPTARGET | SFGAO_FILESYSANCESTOR | SFGAO_FOLDER | SFGAO_HASSUBFOLDER;
445 TRACE ("(%p)->(cidl=%d apidl=%p mask=%p (0x%08x))\n",
446 This, cidl, apidl, rgfInOut, rgfInOut ? *rgfInOut : 0);
448 if (!rgfInOut)
449 return E_INVALIDARG;
450 if (cidl && !apidl)
451 return E_INVALIDARG;
453 if (*rgfInOut == 0)
454 *rgfInOut = ~0;
456 if(cidl == 0) {
457 *rgfInOut &= dwDesktopAttributes;
458 } else {
459 while (cidl > 0 && *apidl) {
460 pdump (*apidl);
461 if (_ILIsDesktop(*apidl)) {
462 *rgfInOut &= dwDesktopAttributes;
463 } else if (_ILIsMyComputer(*apidl)) {
464 *rgfInOut &= dwMyComputerAttributes;
465 } else {
466 SHELL32_GetItemAttributes ( shell_folder, *apidl, rgfInOut);
468 apidl++;
469 cidl--;
472 /* make sure SFGAO_VALIDATE is cleared, some apps depend on that */
473 *rgfInOut &= ~SFGAO_VALIDATE;
475 TRACE ("-- result=0x%08x\n", *rgfInOut);
477 return S_OK;
480 /**************************************************************************
481 * ISF_Desktop_fnGetUIObjectOf
483 * PARAMETERS
484 * HWND hwndOwner, //[in ] Parent window for any output
485 * UINT cidl, //[in ] array size
486 * LPCITEMIDLIST* apidl, //[in ] simple pidl array
487 * REFIID riid, //[in ] Requested Interface
488 * UINT* prgfInOut, //[ ] reserved
489 * LPVOID* ppvObject) //[out] Resulting Interface
492 static HRESULT WINAPI ISF_Desktop_fnGetUIObjectOf (IShellFolder2 * iface,
493 HWND hwndOwner, UINT cidl, LPCITEMIDLIST * apidl,
494 REFIID riid, UINT * prgfInOut, LPVOID * ppvOut)
496 IDesktopFolderImpl *This = (IDesktopFolderImpl *)iface;
498 LPITEMIDLIST pidl;
499 IUnknown *pObj = NULL;
500 HRESULT hr = E_INVALIDARG;
502 TRACE ("(%p)->(%p,%u,apidl=%p,%s,%p,%p)\n",
503 This, hwndOwner, cidl, apidl, shdebugstr_guid (riid), prgfInOut, ppvOut);
505 if (!ppvOut)
506 return E_INVALIDARG;
508 *ppvOut = NULL;
510 if (IsEqualIID (riid, &IID_IContextMenu))
512 if (cidl > 0)
513 pObj = (LPUNKNOWN) ISvItemCm_Constructor( (IShellFolder *) iface, This->pidlRoot, apidl, cidl);
514 else
515 pObj = (LPUNKNOWN) ISvBgCm_Constructor( (IShellFolder *) iface, TRUE);
516 hr = S_OK;
518 else if (IsEqualIID (riid, &IID_IDataObject) && (cidl >= 1))
520 pObj = (LPUNKNOWN) IDataObject_Constructor( hwndOwner,
521 This->pidlRoot, apidl, cidl);
522 hr = S_OK;
524 else if (IsEqualIID (riid, &IID_IExtractIconA) && (cidl == 1))
526 pidl = ILCombine (This->pidlRoot, apidl[0]);
527 pObj = (LPUNKNOWN) IExtractIconA_Constructor (pidl);
528 SHFree (pidl);
529 hr = S_OK;
531 else if (IsEqualIID (riid, &IID_IExtractIconW) && (cidl == 1))
533 pidl = ILCombine (This->pidlRoot, apidl[0]);
534 pObj = (LPUNKNOWN) IExtractIconW_Constructor (pidl);
535 SHFree (pidl);
536 hr = S_OK;
538 else if (IsEqualIID (riid, &IID_IDropTarget) && (cidl >= 1))
540 hr = IShellFolder_QueryInterface (iface,
541 &IID_IDropTarget, (LPVOID *) & pObj);
543 else if ((IsEqualIID(riid,&IID_IShellLinkW) ||
544 IsEqualIID(riid,&IID_IShellLinkA)) && (cidl == 1))
546 pidl = ILCombine (This->pidlRoot, apidl[0]);
547 hr = IShellLink_ConstructFromFile(NULL, riid, pidl, (LPVOID*)&pObj);
548 SHFree (pidl);
550 else
551 hr = E_NOINTERFACE;
553 if (SUCCEEDED(hr) && !pObj)
554 hr = E_OUTOFMEMORY;
556 *ppvOut = pObj;
557 TRACE ("(%p)->hr=0x%08x\n", This, hr);
558 return hr;
561 /**************************************************************************
562 * ISF_Desktop_fnGetDisplayNameOf
564 * NOTES
565 * special case: pidl = null gives desktop-name back
567 static HRESULT WINAPI ISF_Desktop_fnGetDisplayNameOf (IShellFolder2 * iface,
568 LPCITEMIDLIST pidl, DWORD dwFlags, LPSTRRET strRet)
570 IDesktopFolderImpl *This = (IDesktopFolderImpl *)iface;
571 HRESULT hr = S_OK;
572 LPWSTR pszPath;
574 TRACE ("(%p)->(pidl=%p,0x%08x,%p)\n", This, pidl, dwFlags, strRet);
575 pdump (pidl);
577 if (!strRet)
578 return E_INVALIDARG;
580 pszPath = CoTaskMemAlloc((MAX_PATH +1) * sizeof(WCHAR));
581 if (!pszPath)
582 return E_OUTOFMEMORY;
584 if (_ILIsDesktop (pidl))
586 if ((GET_SHGDN_RELATION (dwFlags) == SHGDN_NORMAL) &&
587 (GET_SHGDN_FOR (dwFlags) & SHGDN_FORPARSING))
588 strcpyW(pszPath, This->sPathTarget);
589 else
590 HCR_GetClassNameW(&CLSID_ShellDesktop, pszPath, MAX_PATH);
592 else if (_ILIsPidlSimple (pidl))
594 GUID const *clsid;
596 if ((clsid = _ILGetGUIDPointer (pidl)))
598 if (GET_SHGDN_FOR (dwFlags) & SHGDN_FORPARSING)
600 int bWantsForParsing;
603 * We can only get a filesystem path from a shellfolder if the
604 * value WantsFORPARSING in CLSID\\{...}\\shellfolder exists.
606 * Exception: The MyComputer folder doesn't have this key,
607 * but any other filesystem backed folder it needs it.
609 if (IsEqualIID (clsid, &CLSID_MyComputer))
611 bWantsForParsing = TRUE;
613 else
615 /* get the "WantsFORPARSING" flag from the registry */
616 static const WCHAR clsidW[] =
617 { 'C','L','S','I','D','\\',0 };
618 static const WCHAR shellfolderW[] =
619 { '\\','s','h','e','l','l','f','o','l','d','e','r',0 };
620 static const WCHAR wantsForParsingW[] =
621 { 'W','a','n','t','s','F','o','r','P','a','r','s','i','n',
622 'g',0 };
623 WCHAR szRegPath[100];
624 LONG r;
626 lstrcpyW (szRegPath, clsidW);
627 SHELL32_GUIDToStringW (clsid, &szRegPath[6]);
628 lstrcatW (szRegPath, shellfolderW);
629 r = SHGetValueW(HKEY_CLASSES_ROOT, szRegPath,
630 wantsForParsingW, NULL, NULL, NULL);
631 if (r == ERROR_SUCCESS)
632 bWantsForParsing = TRUE;
633 else
634 bWantsForParsing = FALSE;
637 if ((GET_SHGDN_RELATION (dwFlags) == SHGDN_NORMAL) &&
638 bWantsForParsing)
641 * we need the filesystem path to the destination folder.
642 * Only the folder itself can know it
644 hr = SHELL32_GetDisplayNameOfChild (iface, pidl, dwFlags,
645 pszPath,
646 MAX_PATH);
648 else
650 /* parsing name like ::{...} */
651 pszPath[0] = ':';
652 pszPath[1] = ':';
653 SHELL32_GUIDToStringW (clsid, &pszPath[2]);
656 else
658 /* user friendly name */
659 HCR_GetClassNameW (clsid, pszPath, MAX_PATH);
662 else
664 int cLen = 0;
666 /* file system folder or file rooted at the desktop */
667 if ((GET_SHGDN_FOR(dwFlags) == SHGDN_FORPARSING) &&
668 (GET_SHGDN_RELATION(dwFlags) != SHGDN_INFOLDER))
670 lstrcpynW(pszPath, This->sPathTarget, MAX_PATH - 1);
671 PathAddBackslashW(pszPath);
672 cLen = lstrlenW(pszPath);
675 _ILSimpleGetTextW(pidl, pszPath + cLen, MAX_PATH - cLen);
677 if (!_ILIsFolder(pidl))
678 SHELL_FS_ProcessDisplayFilename(pszPath, dwFlags);
681 else
683 /* a complex pidl, let the subfolder do the work */
684 hr = SHELL32_GetDisplayNameOfChild (iface, pidl, dwFlags,
685 pszPath, MAX_PATH);
688 if (SUCCEEDED(hr))
690 /* Win9x always returns ANSI strings, NT always returns Unicode strings */
691 if (GetVersion() & 0x80000000)
693 strRet->uType = STRRET_CSTR;
694 if (!WideCharToMultiByte(CP_ACP, 0, pszPath, -1, strRet->u.cStr, MAX_PATH,
695 NULL, NULL))
696 strRet->u.cStr[0] = '\0';
697 CoTaskMemFree(pszPath);
699 else
701 strRet->uType = STRRET_WSTR;
702 strRet->u.pOleStr = pszPath;
705 else
706 CoTaskMemFree(pszPath);
708 TRACE ("-- (%p)->(%s,0x%08x)\n", This,
709 strRet->uType == STRRET_CSTR ? strRet->u.cStr :
710 debugstr_w(strRet->u.pOleStr), hr);
711 return hr;
714 /**************************************************************************
715 * ISF_Desktop_fnSetNameOf
716 * Changes the name of a file object or subfolder, possibly changing its item
717 * identifier in the process.
719 * PARAMETERS
720 * HWND hwndOwner, //[in ] Owner window for output
721 * LPCITEMIDLIST pidl, //[in ] simple pidl of item to change
722 * LPCOLESTR lpszName, //[in ] the items new display name
723 * DWORD dwFlags, //[in ] SHGNO formatting flags
724 * LPITEMIDLIST* ppidlOut) //[out] simple pidl returned
726 static HRESULT WINAPI ISF_Desktop_fnSetNameOf (IShellFolder2 * iface,
727 HWND hwndOwner, LPCITEMIDLIST pidl, /* simple pidl */
728 LPCOLESTR lpName, DWORD dwFlags, LPITEMIDLIST * pPidlOut)
730 IDesktopFolderImpl *This = (IDesktopFolderImpl *)iface;
732 FIXME ("(%p)->(%p,pidl=%p,%s,%u,%p) stub\n", This, hwndOwner, pidl,
733 debugstr_w (lpName), dwFlags, pPidlOut);
735 return E_FAIL;
738 static HRESULT WINAPI ISF_Desktop_fnGetDefaultSearchGUID(IShellFolder2 *iface,
739 GUID * pguid)
741 IDesktopFolderImpl *This = (IDesktopFolderImpl *)iface;
742 FIXME ("(%p)->(%p) stub\n", This, pguid);
743 return E_NOTIMPL;
746 static HRESULT WINAPI ISF_Desktop_fnEnumSearches (IShellFolder2 *iface,
747 IEnumExtraSearch ** ppenum)
749 IDesktopFolderImpl *This = (IDesktopFolderImpl *)iface;
750 FIXME ("(%p)->(%p) stub\n", This, ppenum);
751 return E_NOTIMPL;
754 static HRESULT WINAPI ISF_Desktop_fnGetDefaultColumn (IShellFolder2 * iface,
755 DWORD reserved, ULONG * pSort, ULONG * pDisplay)
757 IDesktopFolderImpl *This = (IDesktopFolderImpl *)iface;
759 TRACE ("(%p)->(%d %p %p)\n", This, reserved, pSort, pDisplay);
761 if (pSort)
762 *pSort = 0;
763 if (pDisplay)
764 *pDisplay = 0;
766 return S_OK;
768 static HRESULT WINAPI ISF_Desktop_fnGetDefaultColumnState (
769 IShellFolder2 * iface, UINT iColumn, DWORD * pcsFlags)
771 IDesktopFolderImpl *This = (IDesktopFolderImpl *)iface;
773 TRACE ("(%p)->(%d %p)\n", This, iColumn, pcsFlags);
775 if (!pcsFlags || iColumn >= DESKTOPSHELLVIEWCOLUMNS)
776 return E_INVALIDARG;
778 *pcsFlags = desktop_header[iColumn].pcsFlags;
780 return S_OK;
783 static HRESULT WINAPI ISF_Desktop_fnGetDetailsEx (IShellFolder2 * iface,
784 LPCITEMIDLIST pidl, const SHCOLUMNID * pscid, VARIANT * pv)
786 IDesktopFolderImpl *This = (IDesktopFolderImpl *)iface;
787 FIXME ("(%p)->(%p %p %p) stub\n", This, pidl, pscid, pv);
788 return E_NOTIMPL;
791 static HRESULT WINAPI ISF_Desktop_fnGetDetailsOf (IShellFolder2 * iface,
792 LPCITEMIDLIST pidl, UINT iColumn, SHELLDETAILS * psd)
794 IDesktopFolderImpl *This = (IDesktopFolderImpl *)iface;
796 HRESULT hr = S_OK;
798 TRACE ("(%p)->(%p %i %p)\n", This, pidl, iColumn, psd);
800 if (!psd || iColumn >= DESKTOPSHELLVIEWCOLUMNS)
801 return E_INVALIDARG;
803 if (!pidl)
804 return SHELL32_GetColumnDetails(desktop_header, iColumn, psd);
806 /* the data from the pidl */
807 psd->str.uType = STRRET_CSTR;
808 switch (iColumn)
810 case 0: /* name */
811 hr = IShellFolder_GetDisplayNameOf(iface, pidl,
812 SHGDN_NORMAL | SHGDN_INFOLDER, &psd->str);
813 break;
814 case 1: /* size */
815 _ILGetFileSize (pidl, psd->str.u.cStr, MAX_PATH);
816 break;
817 case 2: /* type */
818 _ILGetFileType (pidl, psd->str.u.cStr, MAX_PATH);
819 break;
820 case 3: /* date */
821 _ILGetFileDate (pidl, psd->str.u.cStr, MAX_PATH);
822 break;
823 case 4: /* attributes */
824 _ILGetFileAttributes (pidl, psd->str.u.cStr, MAX_PATH);
825 break;
828 return hr;
831 static HRESULT WINAPI ISF_Desktop_fnMapColumnToSCID (
832 IShellFolder2 * iface, UINT column, SHCOLUMNID * pscid)
834 IDesktopFolderImpl *This = (IDesktopFolderImpl *)iface;
835 FIXME ("(%p)->(%d %p) stub\n", This, column, pscid);
836 return E_NOTIMPL;
839 static const IShellFolder2Vtbl vt_MCFldr_ShellFolder2 =
841 ISF_Desktop_fnQueryInterface,
842 ISF_Desktop_fnAddRef,
843 ISF_Desktop_fnRelease,
844 ISF_Desktop_fnParseDisplayName,
845 ISF_Desktop_fnEnumObjects,
846 ISF_Desktop_fnBindToObject,
847 ISF_Desktop_fnBindToStorage,
848 ISF_Desktop_fnCompareIDs,
849 ISF_Desktop_fnCreateViewObject,
850 ISF_Desktop_fnGetAttributesOf,
851 ISF_Desktop_fnGetUIObjectOf,
852 ISF_Desktop_fnGetDisplayNameOf,
853 ISF_Desktop_fnSetNameOf,
854 /* ShellFolder2 */
855 ISF_Desktop_fnGetDefaultSearchGUID,
856 ISF_Desktop_fnEnumSearches,
857 ISF_Desktop_fnGetDefaultColumn,
858 ISF_Desktop_fnGetDefaultColumnState,
859 ISF_Desktop_fnGetDetailsEx,
860 ISF_Desktop_fnGetDetailsOf,
861 ISF_Desktop_fnMapColumnToSCID
864 /**************************************************************************
865 * IPersist
867 static HRESULT WINAPI ISF_Desktop_IPersist_fnQueryInterface(
868 IPersist *iface, REFIID riid, LPVOID *ppvObj)
870 IDesktopFolderImpl *This = impl_from_IPersist( iface );
871 return IShellFolder2_QueryInterface((IShellFolder2*)This, riid, ppvObj);
874 static ULONG WINAPI ISF_Desktop_IPersist_fnAddRef(IPersist *iface)
876 IDesktopFolderImpl *This = impl_from_IPersist( iface );
877 return IShellFolder2_AddRef((IShellFolder2*)This);
880 static ULONG WINAPI ISF_Desktop_IPersist_fnRelease(IPersist *iface)
882 IDesktopFolderImpl *This = impl_from_IPersist( iface );
883 return IShellFolder2_Release((IShellFolder2*)This);
886 static HRESULT WINAPI ISF_Desktop_IPersist_fnGetClassID(IPersist *iface, CLSID *clsid)
888 *clsid = CLSID_ShellDesktop;
889 return S_OK;
892 static const IPersistVtbl vt_IPersist =
894 ISF_Desktop_IPersist_fnQueryInterface,
895 ISF_Desktop_IPersist_fnAddRef,
896 ISF_Desktop_IPersist_fnRelease,
897 ISF_Desktop_IPersist_fnGetClassID
900 /**************************************************************************
901 * ISF_Desktop_Constructor
903 HRESULT WINAPI ISF_Desktop_Constructor (
904 IUnknown * pUnkOuter, REFIID riid, LPVOID * ppv)
906 static IDesktopFolderImpl *cached_sf;
907 WCHAR szMyPath[MAX_PATH];
909 TRACE ("unkOut=%p %s\n", pUnkOuter, shdebugstr_guid (riid));
911 if (!ppv)
912 return E_POINTER;
913 if (pUnkOuter)
914 return CLASS_E_NOAGGREGATION;
916 if (!cached_sf)
918 IDesktopFolderImpl *sf;
920 if (!SHGetSpecialFolderPathW( 0, szMyPath, CSIDL_DESKTOPDIRECTORY, TRUE ))
921 return E_UNEXPECTED;
923 sf = LocalAlloc( LMEM_ZEROINIT, sizeof (IDesktopFolderImpl) );
924 if (!sf)
925 return E_OUTOFMEMORY;
927 sf->ref = 1;
928 sf->lpVtbl = &vt_MCFldr_ShellFolder2;
929 sf->lpVtblIPersist = &vt_IPersist;
930 sf->pidlRoot = _ILCreateDesktop(); /* my qualified pidl */
931 sf->sPathTarget = SHAlloc( (lstrlenW(szMyPath) + 1)*sizeof(WCHAR) );
932 lstrcpyW( sf->sPathTarget, szMyPath );
934 if (InterlockedCompareExchangePointer((void *)&cached_sf, sf, NULL) != NULL)
936 /* some other thread already been here */
937 SHFree( sf->pidlRoot );
938 SHFree( sf->sPathTarget );
939 LocalFree( sf );
943 return IUnknown_QueryInterface( (IShellFolder2*)cached_sf, riid, ppv );