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