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