riched20: Use WARN() not ERR() on unknown tokens.
[wine] / dlls / shell32 / shfldr_desktop.c
1
2 /*
3  *    Virtual Desktop Folder
4  *
5  *    Copyright 1997            Marcus Meissner
6  *    Copyright 1998, 1999, 2002    Juergen Schmied
7  *
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.
12  *
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.
17  *
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
21  */
22
23 #include "config.h"
24 #include "wine/port.h"
25
26 #include <stdlib.h>
27 #include <string.h>
28 #include <stdarg.h>
29 #include <stdio.h>
30
31 #define COBJMACROS
32 #define NONAMELESSUNION
33 #define NONAMELESSSTRUCT
34
35 #include "winerror.h"
36 #include "windef.h"
37 #include "winbase.h"
38 #include "winreg.h"
39 #include "wingdi.h"
40 #include "winuser.h"
41
42 #include "ole2.h"
43 #include "shlguid.h"
44
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"
55
56 WINE_DEFAULT_DEBUG_CHANNEL (shell);
57
58 /***********************************************************************
59 *     Desktopfolder implementation
60 */
61
62 typedef struct {
63     const IShellFolder2Vtbl *lpVtbl;
64     LONG ref;
65
66     CLSID *pclsid;
67
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 */
71
72     UINT cfShellIDList;        /* clipboardformat for IDropTarget */
73     BOOL fAcceptFmt;        /* flag for pending Drop */
74 } IGenericSFImpl;
75
76 #define _IUnknown_(This)    (IShellFolder*)&(This->lpVtbl)
77 #define _IShellFolder_(This)    (IShellFolder*)&(This->lpVtbl)
78
79 static shvheader DesktopSFHeader[] = {
80     {IDS_SHV_COLUMN1, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 15},
81     {IDS_SHV_COLUMN2, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
82     {IDS_SHV_COLUMN3, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
83     {IDS_SHV_COLUMN4, SHCOLSTATE_TYPE_DATE | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 12},
84     {IDS_SHV_COLUMN5, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 5}
85 };
86
87 #define DESKTOPSHELLVIEWCOLUMNS 5
88
89 /**************************************************************************
90  *    ISF_Desktop_fnQueryInterface
91  *
92  * NOTES supports not IPersist/IPersistFolder
93  */
94 static HRESULT WINAPI ISF_Desktop_fnQueryInterface(
95                 IShellFolder2 * iface, REFIID riid, LPVOID * ppvObj)
96 {
97     IGenericSFImpl *This = (IGenericSFImpl *)iface;
98
99     TRACE ("(%p)->(%s,%p)\n", This, shdebugstr_guid (riid), ppvObj);
100
101     *ppvObj = NULL;
102
103     if (IsEqualIID (riid, &IID_IUnknown) ||
104         IsEqualIID (riid, &IID_IShellFolder) ||
105         IsEqualIID (riid, &IID_IShellFolder2))
106     {
107         *ppvObj = This;
108     }
109
110     if (*ppvObj)
111     {
112         IUnknown_AddRef ((IUnknown *) (*ppvObj));
113         TRACE ("-- Interface: (%p)->(%p)\n", ppvObj, *ppvObj);
114         return S_OK;
115     }
116     TRACE ("-- Interface: E_NOINTERFACE\n");
117     return E_NOINTERFACE;
118 }
119
120 static ULONG WINAPI ISF_Desktop_fnAddRef (IShellFolder2 * iface)
121 {
122     IGenericSFImpl *This = (IGenericSFImpl *)iface;
123     ULONG refCount = InterlockedIncrement(&This->ref);
124
125     TRACE ("(%p)->(count=%u)\n", This, refCount - 1);
126
127     return refCount;
128 }
129
130 static ULONG WINAPI ISF_Desktop_fnRelease (IShellFolder2 * iface)
131 {
132     IGenericSFImpl *This = (IGenericSFImpl *)iface;
133     ULONG refCount = InterlockedDecrement(&This->ref);
134
135     TRACE ("(%p)->(count=%u)\n", This, refCount + 1);
136
137     if (!refCount)
138     {
139         TRACE ("-- destroying IShellFolder(%p)\n", This);
140         SHFree (This->pidlRoot);
141         SHFree (This->sPathTarget);
142         LocalFree ((HLOCAL) This);
143         return 0;
144     }
145     return refCount;
146 }
147
148 /**************************************************************************
149  *    ISF_Desktop_fnParseDisplayName
150  *
151  * NOTES
152  *    "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}" and "" binds
153  *    to MyComputer
154  */
155 static HRESULT WINAPI ISF_Desktop_fnParseDisplayName (IShellFolder2 * iface,
156                 HWND hwndOwner, LPBC pbc, LPOLESTR lpszDisplayName,
157                 DWORD * pchEaten, LPITEMIDLIST * ppidl, DWORD * pdwAttributes)
158 {
159     IGenericSFImpl *This = (IGenericSFImpl *)iface;
160     WCHAR szElement[MAX_PATH];
161     LPCWSTR szNext = NULL;
162     LPITEMIDLIST pidlTemp = NULL;
163     HRESULT hr = S_OK;
164     CLSID clsid;
165
166     TRACE ("(%p)->(HWND=%p,%p,%p=%s,%p,pidl=%p,%p)\n",
167            This, hwndOwner, pbc, lpszDisplayName, debugstr_w(lpszDisplayName),
168            pchEaten, ppidl, pdwAttributes);
169
170     if (!lpszDisplayName || !ppidl)
171         return E_INVALIDARG;
172
173     *ppidl = 0;
174
175     if (pchEaten)
176         *pchEaten = 0;        /* strange but like the original */
177
178     if (lpszDisplayName[0] == ':' && lpszDisplayName[1] == ':')
179     {
180         szNext = GetNextElementW (lpszDisplayName, szElement, MAX_PATH);
181         TRACE ("-- element: %s\n", debugstr_w (szElement));
182         SHCLSIDFromStringW (szElement + 2, &clsid);
183         pidlTemp = _ILCreateGuid (PT_GUID, &clsid);
184     }
185     else if (PathGetDriveNumberW (lpszDisplayName) >= 0)
186     {
187         /* it's a filesystem path with a drive. Let MyComputer/UnixDosFolder parse it */
188         if (UNIXFS_is_rooted_at_desktop()) 
189             pidlTemp = _ILCreateGuid(PT_GUID, &CLSID_UnixDosFolder);
190         else
191             pidlTemp = _ILCreateMyComputer ();
192         szNext = lpszDisplayName;
193     }
194     else if (PathIsUNCW(lpszDisplayName))
195     {
196         pidlTemp = _ILCreateNetwork();
197         szNext = lpszDisplayName;
198     }
199     else if( (pidlTemp = SHELL32_CreatePidlFromBindCtx(pbc, lpszDisplayName)) )
200     {
201         *ppidl = pidlTemp;
202         return S_OK;
203     }
204     else
205     {
206         /* it's a filesystem path on the desktop. Let a FSFolder parse it */
207
208         if (*lpszDisplayName)
209         {
210             WCHAR szPath[MAX_PATH];
211             LPWSTR pathPtr;
212
213             /* build a complete path to create a simple pidl */
214             lstrcpynW(szPath, This->sPathTarget, MAX_PATH);
215             pathPtr = PathAddBackslashW(szPath);
216             if (pathPtr)
217             {
218                 lstrcpynW(pathPtr, lpszDisplayName, MAX_PATH - (pathPtr - szPath));
219                 hr = _ILCreateFromPathW(szPath, &pidlTemp);
220             }
221             else
222             {
223                 /* should never reach here, but for completeness */
224                 hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
225             }
226         }
227         else
228             pidlTemp = _ILCreateMyComputer();
229
230         szNext = NULL;
231     }
232
233     if (SUCCEEDED(hr) && pidlTemp)
234     {
235         if (szNext && *szNext)
236         {
237             hr = SHELL32_ParseNextElement(iface, hwndOwner, pbc,
238                     &pidlTemp, (LPOLESTR) szNext, pchEaten, pdwAttributes);
239         }
240         else
241         {
242             if (pdwAttributes && *pdwAttributes)
243                 hr = SHELL32_GetItemAttributes(_IShellFolder_ (This),
244                                                pidlTemp, pdwAttributes);
245         }
246     }
247
248     *ppidl = pidlTemp;
249
250     TRACE ("(%p)->(-- ret=0x%08x)\n", This, hr);
251
252     return hr;
253 }
254
255 /**************************************************************************
256  *  CreateDesktopEnumList()
257  */
258 static const WCHAR Desktop_NameSpaceW[] = { 'S','O','F','T','W','A','R','E',
259  '\\','M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
260  'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\','E','x','p','l',
261  'o','r','e','r','\\','D','e','s','k','t','o','p','\\','N','a','m','e','s','p',
262  'a','c','e','\0' };
263
264 static BOOL CreateDesktopEnumList(IEnumIDList *list, DWORD dwFlags)
265 {
266     BOOL ret = TRUE;
267     WCHAR szPath[MAX_PATH];
268
269     TRACE("(%p)->(flags=0x%08x)\n", list, dwFlags);
270
271     /* enumerate the root folders */
272     if (dwFlags & SHCONTF_FOLDERS)
273     {
274         HKEY hkey;
275         UINT i;
276
277         /* create the pidl for This item */
278         ret = AddToEnumList(list, _ILCreateMyComputer());
279
280         for (i=0; i<2; i++) {
281             if (ret && !RegOpenKeyExW(i == 0 ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER,
282                                       Desktop_NameSpaceW, 0, KEY_READ, &hkey))
283             {
284                 WCHAR iid[50];
285                 int i=0;
286
287                 while (ret)
288                 {
289                     DWORD size;
290                     LONG r;
291
292                     size = sizeof (iid);
293                     r = RegEnumKeyExW(hkey, i, iid, &size, 0, NULL, NULL, NULL);
294                     if (ERROR_SUCCESS == r)
295                     {
296                         ret = AddToEnumList(list, _ILCreateGuidFromStrW(iid));
297                         i++;
298                     }
299                     else if (ERROR_NO_MORE_ITEMS == r)
300                         break;
301                     else
302                         ret = FALSE;
303                 }
304                 RegCloseKey(hkey);
305             }
306         }
307     }
308
309     /* enumerate the elements in %windir%\desktop */
310     SHGetSpecialFolderPathW(0, szPath, CSIDL_DESKTOPDIRECTORY, FALSE);
311     ret = ret && CreateFolderEnumList(list, szPath, dwFlags);
312
313     return ret;
314 }
315
316 /**************************************************************************
317  *        ISF_Desktop_fnEnumObjects
318  */
319 static HRESULT WINAPI ISF_Desktop_fnEnumObjects (IShellFolder2 * iface,
320                 HWND hwndOwner, DWORD dwFlags, LPENUMIDLIST * ppEnumIDList)
321 {
322     IGenericSFImpl *This = (IGenericSFImpl *)iface;
323
324     TRACE ("(%p)->(HWND=%p flags=0x%08x pplist=%p)\n",
325            This, hwndOwner, dwFlags, ppEnumIDList);
326
327     *ppEnumIDList = IEnumIDList_Constructor();
328     if (*ppEnumIDList)
329         CreateDesktopEnumList(*ppEnumIDList, dwFlags);
330
331     TRACE ("-- (%p)->(new ID List: %p)\n", This, *ppEnumIDList);
332
333     return *ppEnumIDList ? S_OK : E_OUTOFMEMORY;
334 }
335
336 /**************************************************************************
337  *        ISF_Desktop_fnBindToObject
338  */
339 static HRESULT WINAPI ISF_Desktop_fnBindToObject (IShellFolder2 * iface,
340                 LPCITEMIDLIST pidl, LPBC pbcReserved, REFIID riid, LPVOID * ppvOut)
341 {
342     IGenericSFImpl *This = (IGenericSFImpl *)iface;
343
344     TRACE ("(%p)->(pidl=%p,%p,%s,%p)\n",
345            This, pidl, pbcReserved, shdebugstr_guid (riid), ppvOut);
346
347     return SHELL32_BindToChild( This->pidlRoot, This->sPathTarget, pidl, riid, ppvOut );
348 }
349
350 /**************************************************************************
351  *    ISF_Desktop_fnBindToStorage
352  */
353 static HRESULT WINAPI ISF_Desktop_fnBindToStorage (IShellFolder2 * iface,
354                 LPCITEMIDLIST pidl, LPBC pbcReserved, REFIID riid, LPVOID * ppvOut)
355 {
356     IGenericSFImpl *This = (IGenericSFImpl *)iface;
357
358     FIXME ("(%p)->(pidl=%p,%p,%s,%p) stub\n",
359            This, pidl, pbcReserved, shdebugstr_guid (riid), ppvOut);
360
361     *ppvOut = NULL;
362     return E_NOTIMPL;
363 }
364
365 /**************************************************************************
366  *     ISF_Desktop_fnCompareIDs
367  */
368 static HRESULT WINAPI ISF_Desktop_fnCompareIDs (IShellFolder2 * iface,
369                         LPARAM lParam, LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
370 {
371     IGenericSFImpl *This = (IGenericSFImpl *)iface;
372     int nReturn;
373
374     TRACE ("(%p)->(0x%08lx,pidl1=%p,pidl2=%p)\n", This, lParam, pidl1, pidl2);
375     nReturn = SHELL32_CompareIDs (_IShellFolder_ (This), lParam, pidl1, pidl2);
376     TRACE ("-- %i\n", nReturn);
377     return nReturn;
378 }
379
380 /**************************************************************************
381  *    ISF_Desktop_fnCreateViewObject
382  */
383 static HRESULT WINAPI ISF_Desktop_fnCreateViewObject (IShellFolder2 * iface,
384                               HWND hwndOwner, REFIID riid, LPVOID * ppvOut)
385 {
386     IGenericSFImpl *This = (IGenericSFImpl *)iface;
387     LPSHELLVIEW pShellView;
388     HRESULT hr = E_INVALIDARG;
389
390     TRACE ("(%p)->(hwnd=%p,%s,%p)\n",
391            This, hwndOwner, shdebugstr_guid (riid), ppvOut);
392
393     if (!ppvOut)
394         return hr;
395
396     *ppvOut = NULL;
397
398     if (IsEqualIID (riid, &IID_IDropTarget))
399     {
400         WARN ("IDropTarget not implemented\n");
401         hr = E_NOTIMPL;
402     }
403     else if (IsEqualIID (riid, &IID_IContextMenu))
404     {
405         WARN ("IContextMenu not implemented\n");
406         hr = E_NOTIMPL;
407     }
408     else if (IsEqualIID (riid, &IID_IShellView))
409     {
410         pShellView = IShellView_Constructor ((IShellFolder *) iface);
411         if (pShellView)
412         {
413             hr = IShellView_QueryInterface (pShellView, riid, ppvOut);
414             IShellView_Release (pShellView);
415         }
416     }
417     TRACE ("-- (%p)->(interface=%p)\n", This, ppvOut);
418     return hr;
419 }
420
421 /**************************************************************************
422  *  ISF_Desktop_fnGetAttributesOf
423  */
424 static HRESULT WINAPI ISF_Desktop_fnGetAttributesOf (IShellFolder2 * iface,
425                 UINT cidl, LPCITEMIDLIST * apidl, DWORD * rgfInOut)
426 {
427     IGenericSFImpl *This = (IGenericSFImpl *)iface;
428     HRESULT hr = S_OK;
429     static const DWORD dwDesktopAttributes = 
430         SFGAO_STORAGE | SFGAO_HASPROPSHEET | SFGAO_STORAGEANCESTOR |
431         SFGAO_FILESYSANCESTOR | SFGAO_FOLDER | SFGAO_FILESYSTEM | SFGAO_HASSUBFOLDER;
432     static const DWORD dwMyComputerAttributes = 
433         SFGAO_CANRENAME | SFGAO_CANDELETE | SFGAO_HASPROPSHEET |
434         SFGAO_DROPTARGET | SFGAO_FILESYSANCESTOR | SFGAO_FOLDER | SFGAO_HASSUBFOLDER;
435
436     TRACE ("(%p)->(cidl=%d apidl=%p mask=%p (0x%08x))\n",
437            This, cidl, apidl, rgfInOut, rgfInOut ? *rgfInOut : 0);
438
439     if (!rgfInOut)
440         return E_INVALIDARG;
441     if (cidl && !apidl)
442         return E_INVALIDARG;
443
444     if (*rgfInOut == 0)
445         *rgfInOut = ~0;
446     
447     if(cidl == 0) {
448         *rgfInOut &= dwDesktopAttributes; 
449     } else {
450         while (cidl > 0 && *apidl) {
451             pdump (*apidl);
452             if (_ILIsDesktop(*apidl)) { 
453                 *rgfInOut &= dwDesktopAttributes;
454             } else if (_ILIsMyComputer(*apidl)) {
455                 *rgfInOut &= dwMyComputerAttributes;
456             } else {
457                 SHELL32_GetItemAttributes (_IShellFolder_ (This), *apidl, rgfInOut);
458             }
459             apidl++;
460             cidl--;
461         }
462     }
463     /* make sure SFGAO_VALIDATE is cleared, some apps depend on that */
464     *rgfInOut &= ~SFGAO_VALIDATE;
465
466     TRACE ("-- result=0x%08x\n", *rgfInOut);
467
468     return hr;
469 }
470
471 /**************************************************************************
472  *    ISF_Desktop_fnGetUIObjectOf
473  *
474  * PARAMETERS
475  *  HWND           hwndOwner, //[in ] Parent window for any output
476  *  UINT           cidl,      //[in ] array size
477  *  LPCITEMIDLIST* apidl,     //[in ] simple pidl array
478  *  REFIID         riid,      //[in ] Requested Interface
479  *  UINT*          prgfInOut, //[   ] reserved
480  *  LPVOID*        ppvObject) //[out] Resulting Interface
481  *
482  */
483 static HRESULT WINAPI ISF_Desktop_fnGetUIObjectOf (IShellFolder2 * iface,
484                 HWND hwndOwner, UINT cidl, LPCITEMIDLIST * apidl,
485                 REFIID riid, UINT * prgfInOut, LPVOID * ppvOut)
486 {
487     IGenericSFImpl *This = (IGenericSFImpl *)iface;
488
489     LPITEMIDLIST pidl;
490     IUnknown *pObj = NULL;
491     HRESULT hr = E_INVALIDARG;
492
493     TRACE ("(%p)->(%p,%u,apidl=%p,%s,%p,%p)\n",
494        This, hwndOwner, cidl, apidl, shdebugstr_guid (riid), prgfInOut, ppvOut);
495
496     if (!ppvOut)
497         return hr;
498
499     *ppvOut = NULL;
500
501     if (IsEqualIID (riid, &IID_IContextMenu))
502     {
503         if (cidl > 0)
504             pObj = (LPUNKNOWN) ISvItemCm_Constructor( (IShellFolder *) iface, This->pidlRoot, apidl, cidl);
505         else
506             pObj = (LPUNKNOWN) ISvBgCm_Constructor( (IShellFolder *) iface, TRUE);
507         hr = S_OK;
508     }
509     else if (IsEqualIID (riid, &IID_IDataObject) && (cidl >= 1))
510     {
511         pObj = (LPUNKNOWN) IDataObject_Constructor( hwndOwner,
512                                                   This->pidlRoot, apidl, cidl);
513         hr = S_OK;
514     }
515     else if (IsEqualIID (riid, &IID_IExtractIconA) && (cidl == 1))
516     {
517         pidl = ILCombine (This->pidlRoot, apidl[0]);
518         pObj = (LPUNKNOWN) IExtractIconA_Constructor (pidl);
519         SHFree (pidl);
520         hr = S_OK;
521     }
522     else if (IsEqualIID (riid, &IID_IExtractIconW) && (cidl == 1))
523     {
524         pidl = ILCombine (This->pidlRoot, apidl[0]);
525         pObj = (LPUNKNOWN) IExtractIconW_Constructor (pidl);
526         SHFree (pidl);
527         hr = S_OK;
528     }
529     else if (IsEqualIID (riid, &IID_IDropTarget) && (cidl >= 1))
530     {
531         hr = IShellFolder_QueryInterface (iface,
532                                           &IID_IDropTarget, (LPVOID *) & pObj);
533     }
534     else if ((IsEqualIID(riid,&IID_IShellLinkW) ||
535               IsEqualIID(riid,&IID_IShellLinkA)) && (cidl == 1))
536     {
537         pidl = ILCombine (This->pidlRoot, apidl[0]);
538         hr = IShellLink_ConstructFromFile(NULL, riid, pidl, (LPVOID*)&pObj);
539         SHFree (pidl);
540     }
541     else
542         hr = E_NOINTERFACE;
543
544     if (SUCCEEDED(hr) && !pObj)
545         hr = E_OUTOFMEMORY;
546
547     *ppvOut = pObj;
548     TRACE ("(%p)->hr=0x%08x\n", This, hr);
549     return hr;
550 }
551
552 /**************************************************************************
553  *    ISF_Desktop_fnGetDisplayNameOf
554  *
555  * NOTES
556  *    special case: pidl = null gives desktop-name back
557  */
558 static HRESULT WINAPI ISF_Desktop_fnGetDisplayNameOf (IShellFolder2 * iface,
559                 LPCITEMIDLIST pidl, DWORD dwFlags, LPSTRRET strRet)
560 {
561     IGenericSFImpl *This = (IGenericSFImpl *)iface;
562     HRESULT hr = S_OK;
563     WCHAR wszPath[MAX_PATH];
564
565     TRACE ("(%p)->(pidl=%p,0x%08x,%p)\n", This, pidl, dwFlags, strRet);
566     pdump (pidl);
567
568     if (!strRet)
569         return E_INVALIDARG;
570
571     if (_ILIsDesktop (pidl))
572     {
573         if ((GET_SHGDN_RELATION (dwFlags) == SHGDN_NORMAL) &&
574             (GET_SHGDN_FOR (dwFlags) & SHGDN_FORPARSING))
575             strcpyW(wszPath, This->sPathTarget);
576         else
577             HCR_GetClassNameW(&CLSID_ShellDesktop, wszPath, MAX_PATH);
578     }
579     else if (_ILIsPidlSimple (pidl))
580     {
581         GUID const *clsid;
582
583         if ((clsid = _ILGetGUIDPointer (pidl)))
584         {
585             if (GET_SHGDN_FOR (dwFlags) & SHGDN_FORPARSING)
586             {
587                 int bWantsForParsing;
588
589                 /*
590                  * We can only get a filesystem path from a shellfolder if the
591                  *  value WantsFORPARSING in CLSID\\{...}\\shellfolder exists.
592                  *
593                  * Exception: The MyComputer folder doesn't have this key,
594                  *   but any other filesystem backed folder it needs it.
595                  */
596                 if (IsEqualIID (clsid, &CLSID_MyComputer))
597                 {
598                     bWantsForParsing = TRUE;
599                 }
600                 else
601                 {
602                     /* get the "WantsFORPARSING" flag from the registry */
603                     static const WCHAR clsidW[] =
604                      { 'C','L','S','I','D','\\',0 };
605                     static const WCHAR shellfolderW[] =
606                      { '\\','s','h','e','l','l','f','o','l','d','e','r',0 };
607                     static const WCHAR wantsForParsingW[] =
608                      { 'W','a','n','t','s','F','o','r','P','a','r','s','i','n',
609                      'g',0 };
610                     WCHAR szRegPath[100];
611                     LONG r;
612
613                     lstrcpyW (szRegPath, clsidW);
614                     SHELL32_GUIDToStringW (clsid, &szRegPath[6]);
615                     lstrcatW (szRegPath, shellfolderW);
616                     r = SHGetValueW(HKEY_CLASSES_ROOT, szRegPath,
617                                     wantsForParsingW, NULL, NULL, NULL);
618                     if (r == ERROR_SUCCESS)
619                         bWantsForParsing = TRUE;
620                     else
621                         bWantsForParsing = FALSE;
622                 }
623
624                 if ((GET_SHGDN_RELATION (dwFlags) == SHGDN_NORMAL) &&
625                      bWantsForParsing)
626                 {
627                     /*
628                      * we need the filesystem path to the destination folder.
629                      * Only the folder itself can know it
630                      */
631                     hr = SHELL32_GetDisplayNameOfChild (iface, pidl, dwFlags,
632                                                         wszPath,
633                                                         MAX_PATH);
634                 }
635                 else
636                 {
637                     /* parsing name like ::{...} */
638                     wszPath[0] = ':';
639                     wszPath[1] = ':';
640                     SHELL32_GUIDToStringW (clsid, &wszPath[2]);
641                 }
642             }
643             else
644             {
645                 /* user friendly name */
646                 HCR_GetClassNameW (clsid, wszPath, MAX_PATH);
647             }
648         }
649         else
650         {
651             int cLen = 0;
652
653             /* file system folder or file rooted at the desktop */
654             if ((GET_SHGDN_FOR(dwFlags) == SHGDN_FORPARSING) &&
655                 (GET_SHGDN_RELATION(dwFlags) != SHGDN_INFOLDER))
656             {
657                 lstrcpynW(wszPath, This->sPathTarget, MAX_PATH - 1);
658                 PathAddBackslashW(wszPath);
659                 cLen = lstrlenW(wszPath);
660             }
661
662             _ILSimpleGetTextW(pidl, wszPath + cLen, MAX_PATH - cLen);
663
664             if (!_ILIsFolder(pidl))
665                 SHELL_FS_ProcessDisplayFilename(wszPath, dwFlags);
666         }
667     }
668     else
669     {
670         /* a complex pidl, let the subfolder do the work */
671         hr = SHELL32_GetDisplayNameOfChild (iface, pidl, dwFlags,
672                                             wszPath, MAX_PATH);
673     }
674
675     if (SUCCEEDED(hr))
676     {
677         BOOL defCharUsed;
678         strRet->uType = STRRET_CSTR;
679         if (!WideCharToMultiByte(CP_ACP, 0, wszPath, -1, strRet->u.cStr, MAX_PATH,
680                                  NULL, &defCharUsed))
681             strRet->u.cStr[0] = '\0';
682         if (defCharUsed)
683         {
684             strRet->u.pOleStr = SHAlloc((lstrlenW(This->sPathTarget)+1) *
685              sizeof(WCHAR));
686             if (!strRet->u.pOleStr)
687                 hr = E_OUTOFMEMORY;
688             else
689             {
690                 strcpyW(strRet->u.pOleStr, This->sPathTarget);
691                 strRet->uType = STRRET_WSTR;
692             }
693         }
694     }
695
696     TRACE ("-- (%p)->(%s,0x%08x)\n", This,
697      strRet->uType == STRRET_CSTR ? strRet->u.cStr :
698      debugstr_w(strRet->u.pOleStr), hr);
699     return hr;
700 }
701
702 /**************************************************************************
703  *  ISF_Desktop_fnSetNameOf
704  *  Changes the name of a file object or subfolder, possibly changing its item
705  *  identifier in the process.
706  *
707  * PARAMETERS
708  *  HWND          hwndOwner,  //[in ] Owner window for output
709  *  LPCITEMIDLIST pidl,       //[in ] simple pidl of item to change
710  *  LPCOLESTR     lpszName,   //[in ] the items new display name
711  *  DWORD         dwFlags,    //[in ] SHGNO formatting flags
712  *  LPITEMIDLIST* ppidlOut)   //[out] simple pidl returned
713  */
714 static HRESULT WINAPI ISF_Desktop_fnSetNameOf (IShellFolder2 * iface,
715                 HWND hwndOwner, LPCITEMIDLIST pidl,    /* simple pidl */
716                 LPCOLESTR lpName, DWORD dwFlags, LPITEMIDLIST * pPidlOut)
717 {
718     IGenericSFImpl *This = (IGenericSFImpl *)iface;
719
720     FIXME ("(%p)->(%p,pidl=%p,%s,%u,%p)\n", This, hwndOwner, pidl,
721            debugstr_w (lpName), dwFlags, pPidlOut);
722
723     return E_FAIL;
724 }
725
726 static HRESULT WINAPI ISF_Desktop_fnGetDefaultSearchGUID(IShellFolder2 *iface,
727                 GUID * pguid)
728 {
729     IGenericSFImpl *This = (IGenericSFImpl *)iface;
730
731     FIXME ("(%p)\n", This);
732     return E_NOTIMPL;
733 }
734
735 static HRESULT WINAPI ISF_Desktop_fnEnumSearches (IShellFolder2 *iface,
736                 IEnumExtraSearch ** ppenum)
737 {
738     IGenericSFImpl *This = (IGenericSFImpl *)iface;
739     FIXME ("(%p)\n", This);
740     return E_NOTIMPL;
741 }
742
743 static HRESULT WINAPI ISF_Desktop_fnGetDefaultColumn (IShellFolder2 * iface,
744                 DWORD dwRes, ULONG * pSort, ULONG * pDisplay)
745 {
746     IGenericSFImpl *This = (IGenericSFImpl *)iface;
747
748     TRACE ("(%p)\n", This);
749
750     if (pSort)
751         *pSort = 0;
752     if (pDisplay)
753         *pDisplay = 0;
754
755     return S_OK;
756 }
757 static HRESULT WINAPI ISF_Desktop_fnGetDefaultColumnState (
758                 IShellFolder2 * iface, UINT iColumn, DWORD * pcsFlags)
759 {
760     IGenericSFImpl *This = (IGenericSFImpl *)iface;
761
762     TRACE ("(%p)\n", This);
763
764     if (!pcsFlags || iColumn >= DESKTOPSHELLVIEWCOLUMNS)
765     return E_INVALIDARG;
766
767     *pcsFlags = DesktopSFHeader[iColumn].pcsFlags;
768
769     return S_OK;
770 }
771
772 static HRESULT WINAPI ISF_Desktop_fnGetDetailsEx (IShellFolder2 * iface,
773                 LPCITEMIDLIST pidl, const SHCOLUMNID * pscid, VARIANT * pv)
774 {
775     IGenericSFImpl *This = (IGenericSFImpl *)iface;
776     FIXME ("(%p)\n", This);
777
778     return E_NOTIMPL;
779 }
780
781 static HRESULT WINAPI ISF_Desktop_fnGetDetailsOf (IShellFolder2 * iface,
782                 LPCITEMIDLIST pidl, UINT iColumn, SHELLDETAILS * psd)
783 {
784     IGenericSFImpl *This = (IGenericSFImpl *)iface;
785
786     HRESULT hr = S_OK;
787
788     TRACE ("(%p)->(%p %i %p)\n", This, pidl, iColumn, psd);
789
790     if (!psd || iColumn >= DESKTOPSHELLVIEWCOLUMNS)
791         return E_INVALIDARG;
792
793     if (!pidl)
794     {
795         psd->fmt = DesktopSFHeader[iColumn].fmt;
796         psd->cxChar = DesktopSFHeader[iColumn].cxChar;
797         psd->str.uType = STRRET_CSTR;
798         LoadStringA (shell32_hInstance, DesktopSFHeader[iColumn].colnameid,
799                      psd->str.u.cStr, MAX_PATH);
800         return S_OK;
801     }
802
803     /* the data from the pidl */
804     psd->str.uType = STRRET_CSTR;
805     switch (iColumn)
806     {
807     case 0:        /* name */
808         hr = IShellFolder_GetDisplayNameOf(iface, pidl,
809                    SHGDN_NORMAL | SHGDN_INFOLDER, &psd->str);
810         break;
811     case 1:        /* size */
812         _ILGetFileSize (pidl, psd->str.u.cStr, MAX_PATH);
813         break;
814     case 2:        /* type */
815         _ILGetFileType (pidl, psd->str.u.cStr, MAX_PATH);
816         break;
817     case 3:        /* date */
818         _ILGetFileDate (pidl, psd->str.u.cStr, MAX_PATH);
819         break;
820     case 4:        /* attributes */
821         _ILGetFileAttributes (pidl, psd->str.u.cStr, MAX_PATH);
822         break;
823     }
824
825     return hr;
826 }
827
828 static HRESULT WINAPI ISF_Desktop_fnMapColumnToSCID (
829                 IShellFolder2 * iface, UINT column, SHCOLUMNID * pscid)
830 {
831     IGenericSFImpl *This = (IGenericSFImpl *)iface;
832     FIXME ("(%p)\n", This);
833     return E_NOTIMPL;
834 }
835
836 static const IShellFolder2Vtbl vt_MCFldr_ShellFolder2 =
837 {
838     ISF_Desktop_fnQueryInterface,
839     ISF_Desktop_fnAddRef,
840     ISF_Desktop_fnRelease,
841     ISF_Desktop_fnParseDisplayName,
842     ISF_Desktop_fnEnumObjects,
843     ISF_Desktop_fnBindToObject,
844     ISF_Desktop_fnBindToStorage,
845     ISF_Desktop_fnCompareIDs,
846     ISF_Desktop_fnCreateViewObject,
847     ISF_Desktop_fnGetAttributesOf,
848     ISF_Desktop_fnGetUIObjectOf,
849     ISF_Desktop_fnGetDisplayNameOf,
850     ISF_Desktop_fnSetNameOf,
851     /* ShellFolder2 */
852     ISF_Desktop_fnGetDefaultSearchGUID,
853     ISF_Desktop_fnEnumSearches,
854     ISF_Desktop_fnGetDefaultColumn,
855     ISF_Desktop_fnGetDefaultColumnState,
856     ISF_Desktop_fnGetDetailsEx,
857     ISF_Desktop_fnGetDetailsOf,
858     ISF_Desktop_fnMapColumnToSCID
859 };
860
861 /**************************************************************************
862  *    ISF_Desktop_Constructor
863  */
864 HRESULT WINAPI ISF_Desktop_Constructor (
865                 IUnknown * pUnkOuter, REFIID riid, LPVOID * ppv)
866 {
867     IGenericSFImpl *sf;
868     WCHAR szMyPath[MAX_PATH];
869     HRESULT r;
870
871     TRACE ("unkOut=%p %s\n", pUnkOuter, shdebugstr_guid (riid));
872
873     if (!ppv)
874         return E_POINTER;
875     if (pUnkOuter)
876         return CLASS_E_NOAGGREGATION;
877
878     if (!SHGetSpecialFolderPathW( 0, szMyPath, CSIDL_DESKTOPDIRECTORY, TRUE ))
879         return E_UNEXPECTED;
880
881     sf = LocalAlloc( LMEM_ZEROINIT, sizeof (IGenericSFImpl) );
882     if (!sf)
883         return E_OUTOFMEMORY;
884
885     sf->ref = 0;
886     sf->lpVtbl = &vt_MCFldr_ShellFolder2;
887     sf->pidlRoot = _ILCreateDesktop();    /* my qualified pidl */
888     sf->sPathTarget = SHAlloc( (lstrlenW(szMyPath) + 1)*sizeof(WCHAR) );
889     lstrcpyW( sf->sPathTarget, szMyPath );
890
891     r = IUnknown_QueryInterface( _IUnknown_(sf), riid, ppv );
892     if (!SUCCEEDED (r))
893     {
894         IUnknown_Release( _IUnknown_(sf) );
895         return r;
896     }
897
898     TRACE ("--(%p)\n", sf);
899     return S_OK;
900 }