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