wininet: Added Esperanto language.
[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         UINT i;
278
279         /* create the pidl for This item */
280         ret = AddToEnumList(list, _ILCreateMyComputer());
281
282         for (i=0; i<2; i++) {
283             if (ret && !RegOpenKeyExW(i == 0 ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER,
284                                       Desktop_NameSpaceW, 0, KEY_READ, &hkey))
285             {
286                 WCHAR iid[50];
287                 int i=0;
288
289                 while (ret)
290                 {
291                     DWORD size;
292                     LONG r;
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                         break;
303                     else
304                         ret = FALSE;
305                 }
306                 RegCloseKey(hkey);
307             }
308         }
309     }
310
311     /* enumerate the elements in %windir%\desktop */
312     SHGetSpecialFolderPathW(0, szPath, CSIDL_DESKTOPDIRECTORY, FALSE);
313     ret = ret && CreateFolderEnumList(list, szPath, dwFlags);
314
315     return ret;
316 }
317
318 /**************************************************************************
319  *        ISF_Desktop_fnEnumObjects
320  */
321 static HRESULT WINAPI ISF_Desktop_fnEnumObjects (IShellFolder2 * iface,
322                 HWND hwndOwner, DWORD dwFlags, LPENUMIDLIST * ppEnumIDList)
323 {
324     IGenericSFImpl *This = (IGenericSFImpl *)iface;
325
326     TRACE ("(%p)->(HWND=%p flags=0x%08lx pplist=%p)\n",
327            This, hwndOwner, dwFlags, ppEnumIDList);
328
329     *ppEnumIDList = IEnumIDList_Constructor();
330     if (*ppEnumIDList)
331         CreateDesktopEnumList(*ppEnumIDList, dwFlags);
332
333     TRACE ("-- (%p)->(new ID List: %p)\n", This, *ppEnumIDList);
334
335     return *ppEnumIDList ? S_OK : E_OUTOFMEMORY;
336 }
337
338 /**************************************************************************
339  *        ISF_Desktop_fnBindToObject
340  */
341 static HRESULT WINAPI ISF_Desktop_fnBindToObject (IShellFolder2 * iface,
342                 LPCITEMIDLIST pidl, LPBC pbcReserved, REFIID riid, LPVOID * ppvOut)
343 {
344     IGenericSFImpl *This = (IGenericSFImpl *)iface;
345
346     TRACE ("(%p)->(pidl=%p,%p,%s,%p)\n",
347            This, pidl, pbcReserved, shdebugstr_guid (riid), ppvOut);
348
349     return SHELL32_BindToChild( This->pidlRoot, This->sPathTarget, pidl, riid, ppvOut );
350 }
351
352 /**************************************************************************
353  *    ISF_Desktop_fnBindToStorage
354  */
355 static HRESULT WINAPI ISF_Desktop_fnBindToStorage (IShellFolder2 * iface,
356                 LPCITEMIDLIST pidl, LPBC pbcReserved, REFIID riid, LPVOID * ppvOut)
357 {
358     IGenericSFImpl *This = (IGenericSFImpl *)iface;
359
360     FIXME ("(%p)->(pidl=%p,%p,%s,%p) stub\n",
361            This, pidl, pbcReserved, shdebugstr_guid (riid), ppvOut);
362
363     *ppvOut = NULL;
364     return E_NOTIMPL;
365 }
366
367 /**************************************************************************
368  *     ISF_Desktop_fnCompareIDs
369  */
370 static HRESULT WINAPI ISF_Desktop_fnCompareIDs (IShellFolder2 * iface,
371                         LPARAM lParam, LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
372 {
373     IGenericSFImpl *This = (IGenericSFImpl *)iface;
374     int nReturn;
375
376     TRACE ("(%p)->(0x%08lx,pidl1=%p,pidl2=%p)\n", This, lParam, pidl1, pidl2);
377     nReturn = SHELL32_CompareIDs (_IShellFolder_ (This), lParam, pidl1, pidl2);
378     TRACE ("-- %i\n", nReturn);
379     return nReturn;
380 }
381
382 /**************************************************************************
383  *    ISF_Desktop_fnCreateViewObject
384  */
385 static HRESULT WINAPI ISF_Desktop_fnCreateViewObject (IShellFolder2 * iface,
386                               HWND hwndOwner, REFIID riid, LPVOID * ppvOut)
387 {
388     IGenericSFImpl *This = (IGenericSFImpl *)iface;
389     LPSHELLVIEW pShellView;
390     HRESULT hr = E_INVALIDARG;
391
392     TRACE ("(%p)->(hwnd=%p,%s,%p)\n",
393            This, hwndOwner, shdebugstr_guid (riid), ppvOut);
394
395     if (!ppvOut)
396         return hr;
397
398     *ppvOut = NULL;
399
400     if (IsEqualIID (riid, &IID_IDropTarget))
401     {
402         WARN ("IDropTarget not implemented\n");
403         hr = E_NOTIMPL;
404     }
405     else if (IsEqualIID (riid, &IID_IContextMenu))
406     {
407         WARN ("IContextMenu not implemented\n");
408         hr = E_NOTIMPL;
409     }
410     else if (IsEqualIID (riid, &IID_IShellView))
411     {
412         pShellView = IShellView_Constructor ((IShellFolder *) iface);
413         if (pShellView)
414         {
415             hr = IShellView_QueryInterface (pShellView, riid, ppvOut);
416             IShellView_Release (pShellView);
417         }
418     }
419     TRACE ("-- (%p)->(interface=%p)\n", This, ppvOut);
420     return hr;
421 }
422
423 /**************************************************************************
424  *  ISF_Desktop_fnGetAttributesOf
425  */
426 static HRESULT WINAPI ISF_Desktop_fnGetAttributesOf (IShellFolder2 * iface,
427                 UINT cidl, LPCITEMIDLIST * apidl, DWORD * rgfInOut)
428 {
429     IGenericSFImpl *This = (IGenericSFImpl *)iface;
430     HRESULT hr = S_OK;
431     static const DWORD dwDesktopAttributes = 
432         SFGAO_STORAGE | SFGAO_HASPROPSHEET | SFGAO_STORAGEANCESTOR |
433         SFGAO_FILESYSANCESTOR | SFGAO_FOLDER | SFGAO_FILESYSTEM | SFGAO_HASSUBFOLDER;
434     static const DWORD dwMyComputerAttributes = 
435         SFGAO_CANRENAME | SFGAO_CANDELETE | SFGAO_HASPROPSHEET |
436         SFGAO_DROPTARGET | SFGAO_FILESYSANCESTOR | SFGAO_FOLDER | SFGAO_HASSUBFOLDER;
437
438     TRACE ("(%p)->(cidl=%d apidl=%p mask=%p (0x%08lx))\n",
439            This, cidl, apidl, rgfInOut, rgfInOut ? *rgfInOut : 0);
440
441     if (!rgfInOut)
442         return E_INVALIDARG;
443     if (cidl && !apidl)
444         return E_INVALIDARG;
445
446     if (*rgfInOut == 0)
447         *rgfInOut = ~0;
448     
449     if(cidl == 0) {
450         *rgfInOut &= dwDesktopAttributes; 
451     } else {
452         while (cidl > 0 && *apidl) {
453             pdump (*apidl);
454             if (_ILIsDesktop(*apidl)) { 
455                 *rgfInOut &= dwDesktopAttributes;
456             } else if (_ILIsMyComputer(*apidl)) {
457                 *rgfInOut &= dwMyComputerAttributes;
458             } else {
459                 SHELL32_GetItemAttributes (_IShellFolder_ (This), *apidl, rgfInOut);
460             }
461             apidl++;
462             cidl--;
463         }
464     }
465     /* make sure SFGAO_VALIDATE is cleared, some apps depend on that */
466     *rgfInOut &= ~SFGAO_VALIDATE;
467
468     TRACE ("-- result=0x%08lx\n", *rgfInOut);
469
470     return hr;
471 }
472
473 /**************************************************************************
474  *    ISF_Desktop_fnGetUIObjectOf
475  *
476  * PARAMETERS
477  *  HWND           hwndOwner, //[in ] Parent window for any output
478  *  UINT           cidl,      //[in ] array size
479  *  LPCITEMIDLIST* apidl,     //[in ] simple pidl array
480  *  REFIID         riid,      //[in ] Requested Interface
481  *  UINT*          prgfInOut, //[   ] reserved
482  *  LPVOID*        ppvObject) //[out] Resulting Interface
483  *
484  */
485 static HRESULT WINAPI ISF_Desktop_fnGetUIObjectOf (IShellFolder2 * iface,
486                 HWND hwndOwner, UINT cidl, LPCITEMIDLIST * apidl,
487                 REFIID riid, UINT * prgfInOut, LPVOID * ppvOut)
488 {
489     IGenericSFImpl *This = (IGenericSFImpl *)iface;
490
491     LPITEMIDLIST pidl;
492     IUnknown *pObj = NULL;
493     HRESULT hr = E_INVALIDARG;
494
495     TRACE ("(%p)->(%p,%u,apidl=%p,%s,%p,%p)\n",
496        This, hwndOwner, cidl, apidl, shdebugstr_guid (riid), prgfInOut, ppvOut);
497
498     if (!ppvOut)
499         return hr;
500
501     *ppvOut = NULL;
502
503     if (IsEqualIID (riid, &IID_IContextMenu))
504     {
505         if (cidl > 0)
506             pObj = (LPUNKNOWN) ISvItemCm_Constructor( (IShellFolder *) iface, This->pidlRoot, apidl, cidl);
507         else
508             pObj = (LPUNKNOWN) ISvBgCm_Constructor( (IShellFolder *) iface, TRUE);
509         hr = S_OK;
510     }
511     else if (IsEqualIID (riid, &IID_IDataObject) && (cidl >= 1))
512     {
513         pObj = (LPUNKNOWN) IDataObject_Constructor( hwndOwner,
514                                                   This->pidlRoot, apidl, cidl);
515         hr = S_OK;
516     }
517     else if (IsEqualIID (riid, &IID_IExtractIconA) && (cidl == 1))
518     {
519         pidl = ILCombine (This->pidlRoot, apidl[0]);
520         pObj = (LPUNKNOWN) IExtractIconA_Constructor (pidl);
521         SHFree (pidl);
522         hr = S_OK;
523     }
524     else if (IsEqualIID (riid, &IID_IExtractIconW) && (cidl == 1))
525     {
526         pidl = ILCombine (This->pidlRoot, apidl[0]);
527         pObj = (LPUNKNOWN) IExtractIconW_Constructor (pidl);
528         SHFree (pidl);
529         hr = S_OK;
530     }
531     else if (IsEqualIID (riid, &IID_IDropTarget) && (cidl >= 1))
532     {
533         hr = IShellFolder_QueryInterface (iface,
534                                           &IID_IDropTarget, (LPVOID *) & pObj);
535     }
536     else if ((IsEqualIID(riid,&IID_IShellLinkW) ||
537               IsEqualIID(riid,&IID_IShellLinkA)) && (cidl == 1))
538     {
539         pidl = ILCombine (This->pidlRoot, apidl[0]);
540         hr = IShellLink_ConstructFromFile(NULL, riid, pidl, (LPVOID*)&pObj);
541         SHFree (pidl);
542     }
543     else
544         hr = E_NOINTERFACE;
545
546     if (SUCCEEDED(hr) && !pObj)
547         hr = E_OUTOFMEMORY;
548
549     *ppvOut = pObj;
550     TRACE ("(%p)->hr=0x%08lx\n", This, hr);
551     return hr;
552 }
553
554 /**************************************************************************
555  *    ISF_Desktop_fnGetDisplayNameOf
556  *
557  * NOTES
558  *    special case: pidl = null gives desktop-name back
559  */
560 static HRESULT WINAPI ISF_Desktop_fnGetDisplayNameOf (IShellFolder2 * iface,
561                 LPCITEMIDLIST pidl, DWORD dwFlags, LPSTRRET strRet)
562 {
563     IGenericSFImpl *This = (IGenericSFImpl *)iface;
564     HRESULT hr = S_OK;
565     WCHAR wszPath[MAX_PATH];
566
567     TRACE ("(%p)->(pidl=%p,0x%08lx,%p)\n", This, pidl, dwFlags, strRet);
568     pdump (pidl);
569
570     if (!strRet)
571         return E_INVALIDARG;
572
573     strRet->uType = STRRET_CSTR;
574     if (_ILIsDesktop (pidl))
575     {
576         if ((GET_SHGDN_RELATION (dwFlags) == SHGDN_NORMAL) &&
577             (GET_SHGDN_FOR (dwFlags) & SHGDN_FORPARSING))
578         {
579             BOOL defCharUsed;
580
581             WideCharToMultiByte( CP_ACP, 0, This->sPathTarget, -1,
582                                  strRet->u.cStr, MAX_PATH, NULL, &defCharUsed );
583             if (defCharUsed)
584             {
585                 strRet->u.pOleStr = SHAlloc((lstrlenW(This->sPathTarget)+1) *
586                  sizeof(WCHAR));
587                 if (!strRet->u.pOleStr)
588                     hr = E_OUTOFMEMORY;
589                 else
590                 {
591                     strcpyW(strRet->u.pOleStr, This->sPathTarget);
592                     strRet->uType = STRRET_WSTR;
593                 }
594             }
595         }
596         else
597         {
598             HCR_GetClassNameA(&CLSID_ShellDesktop, strRet->u.cStr, MAX_PATH);
599         }
600     }
601     else if (_ILIsPidlSimple (pidl))
602     {
603         GUID const *clsid;
604
605         if ((clsid = _ILGetGUIDPointer (pidl)))
606         {
607             if (GET_SHGDN_FOR (dwFlags) & SHGDN_FORPARSING)
608             {
609                 int bWantsForParsing;
610
611                 /*
612                  * We can only get a filesystem path from a shellfolder if the
613                  *  value WantsFORPARSING in CLSID\\{...}\\shellfolder exists.
614                  *
615                  * Exception: The MyComputer folder doesn't have this key,
616                  *   but any other filesystem backed folder it needs it.
617                  */
618                 if (IsEqualIID (clsid, &CLSID_MyComputer))
619                 {
620                     bWantsForParsing = TRUE;
621                 }
622                 else
623                 {
624                     /* get the "WantsFORPARSING" flag from the registry */
625                     static const WCHAR clsidW[] =
626                      { 'C','L','S','I','D','\\',0 };
627                     static const WCHAR shellfolderW[] =
628                      { '\\','s','h','e','l','l','f','o','l','d','e','r',0 };
629                     static const WCHAR wantsForParsingW[] =
630                      { 'W','a','n','t','s','F','o','r','P','a','r','s','i','n',
631                      'g',0 };
632                     WCHAR szRegPath[100];
633                     LONG r;
634
635                     lstrcpyW (szRegPath, clsidW);
636                     SHELL32_GUIDToStringW (clsid, &szRegPath[6]);
637                     lstrcatW (szRegPath, shellfolderW);
638                     r = SHGetValueW(HKEY_CLASSES_ROOT, szRegPath,
639                                     wantsForParsingW, NULL, NULL, NULL);
640                     if (r == ERROR_SUCCESS)
641                         bWantsForParsing = TRUE;
642                     else
643                         bWantsForParsing = FALSE;
644                 }
645
646                 if ((GET_SHGDN_RELATION (dwFlags) == SHGDN_NORMAL) &&
647                      bWantsForParsing)
648                 {
649                     WCHAR wszPath[MAX_PATH];
650                     /*
651                      * we need the filesystem path to the destination folder.
652                      * Only the folder itself can know it
653                      */
654                     hr = SHELL32_GetDisplayNameOfChild (iface, pidl, dwFlags,
655                                                         wszPath,
656                                                         MAX_PATH);
657                     if (SUCCEEDED(hr))
658                     {
659                         if (!WideCharToMultiByte(CP_ACP, 0, wszPath, -1, strRet->u.cStr, MAX_PATH,
660                                                  NULL, NULL))
661                             wszPath[0] = '\0';
662                     }
663                 }
664                 else
665                 {
666                     /* parsing name like ::{...} */
667                     lstrcpyA (strRet->u.cStr, "::");
668                     SHELL32_GUIDToStringA (clsid, &strRet->u.cStr[2]);
669                 }
670             }
671             else
672             {
673                 /* user friendly name */
674                 HCR_GetClassNameA (clsid, strRet->u.cStr, MAX_PATH);
675             }
676         }
677         else
678         {
679             int cLen = 0;
680
681             /* file system folder or file rooted at the desktop */
682             if ((GET_SHGDN_FOR(dwFlags) == SHGDN_FORPARSING) &&
683                 (GET_SHGDN_RELATION(dwFlags) != SHGDN_INFOLDER))
684             {
685                 lstrcpynW(wszPath, This->sPathTarget, MAX_PATH - 1);
686                 PathAddBackslashW(wszPath);
687                 cLen = lstrlenW(wszPath);
688             }
689
690             _ILSimpleGetTextW(pidl, wszPath + cLen, MAX_PATH - cLen);
691
692             if (!_ILIsFolder(pidl))
693                 SHELL_FS_ProcessDisplayFilename(wszPath, dwFlags);
694
695             WideCharToMultiByte(CP_ACP, 0, wszPath, -1, strRet->u.cStr, MAX_PATH,
696                                 NULL, NULL);
697         }
698     }
699     else
700     {
701         /* a complex pidl, let the subfolder do the work */
702         hr = SHELL32_GetDisplayNameOfChild (iface, pidl, dwFlags,
703                                             wszPath, MAX_PATH);
704         if (SUCCEEDED(hr))
705         {
706             if (!WideCharToMultiByte(CP_ACP, 0, wszPath, -1, strRet->u.cStr, MAX_PATH,
707                                      NULL, NULL))
708                 wszPath[0] = '\0';
709         }
710     }
711
712     TRACE ("-- (%p)->(%s,0x%08lx)\n", This,
713      strRet->uType == STRRET_CSTR ? strRet->u.cStr :
714      debugstr_w(strRet->u.pOleStr), hr);
715     return hr;
716 }
717
718 /**************************************************************************
719  *  ISF_Desktop_fnSetNameOf
720  *  Changes the name of a file object or subfolder, possibly changing its item
721  *  identifier in the process.
722  *
723  * PARAMETERS
724  *  HWND          hwndOwner,  //[in ] Owner window for output
725  *  LPCITEMIDLIST pidl,       //[in ] simple pidl of item to change
726  *  LPCOLESTR     lpszName,   //[in ] the items new display name
727  *  DWORD         dwFlags,    //[in ] SHGNO formatting flags
728  *  LPITEMIDLIST* ppidlOut)   //[out] simple pidl returned
729  */
730 static HRESULT WINAPI ISF_Desktop_fnSetNameOf (IShellFolder2 * iface,
731                 HWND hwndOwner, LPCITEMIDLIST pidl,    /* simple pidl */
732                 LPCOLESTR lpName, DWORD dwFlags, LPITEMIDLIST * pPidlOut)
733 {
734     IGenericSFImpl *This = (IGenericSFImpl *)iface;
735
736     FIXME ("(%p)->(%p,pidl=%p,%s,%lu,%p)\n", This, hwndOwner, pidl,
737            debugstr_w (lpName), dwFlags, pPidlOut);
738
739     return E_FAIL;
740 }
741
742 static HRESULT WINAPI ISF_Desktop_fnGetDefaultSearchGUID(IShellFolder2 *iface,
743                 GUID * pguid)
744 {
745     IGenericSFImpl *This = (IGenericSFImpl *)iface;
746
747     FIXME ("(%p)\n", This);
748     return E_NOTIMPL;
749 }
750
751 static HRESULT WINAPI ISF_Desktop_fnEnumSearches (IShellFolder2 *iface,
752                 IEnumExtraSearch ** ppenum)
753 {
754     IGenericSFImpl *This = (IGenericSFImpl *)iface;
755     FIXME ("(%p)\n", This);
756     return E_NOTIMPL;
757 }
758
759 static HRESULT WINAPI ISF_Desktop_fnGetDefaultColumn (IShellFolder2 * iface,
760                 DWORD dwRes, ULONG * pSort, ULONG * pDisplay)
761 {
762     IGenericSFImpl *This = (IGenericSFImpl *)iface;
763
764     TRACE ("(%p)\n", This);
765
766     if (pSort)
767         *pSort = 0;
768     if (pDisplay)
769         *pDisplay = 0;
770
771     return S_OK;
772 }
773 static HRESULT WINAPI ISF_Desktop_fnGetDefaultColumnState (
774                 IShellFolder2 * iface, UINT iColumn, DWORD * pcsFlags)
775 {
776     IGenericSFImpl *This = (IGenericSFImpl *)iface;
777
778     TRACE ("(%p)\n", This);
779
780     if (!pcsFlags || iColumn >= DESKTOPSHELLVIEWCOLUMNS)
781     return E_INVALIDARG;
782
783     *pcsFlags = DesktopSFHeader[iColumn].pcsFlags;
784
785     return S_OK;
786 }
787
788 static HRESULT WINAPI ISF_Desktop_fnGetDetailsEx (IShellFolder2 * iface,
789                 LPCITEMIDLIST pidl, const SHCOLUMNID * pscid, VARIANT * pv)
790 {
791     IGenericSFImpl *This = (IGenericSFImpl *)iface;
792     FIXME ("(%p)\n", This);
793
794     return E_NOTIMPL;
795 }
796
797 static HRESULT WINAPI ISF_Desktop_fnGetDetailsOf (IShellFolder2 * iface,
798                 LPCITEMIDLIST pidl, UINT iColumn, SHELLDETAILS * psd)
799 {
800     IGenericSFImpl *This = (IGenericSFImpl *)iface;
801
802     HRESULT hr = S_OK;
803
804     TRACE ("(%p)->(%p %i %p)\n", This, pidl, iColumn, psd);
805
806     if (!psd || iColumn >= DESKTOPSHELLVIEWCOLUMNS)
807         return E_INVALIDARG;
808
809     if (!pidl)
810     {
811         psd->fmt = DesktopSFHeader[iColumn].fmt;
812         psd->cxChar = DesktopSFHeader[iColumn].cxChar;
813         psd->str.uType = STRRET_CSTR;
814         LoadStringA (shell32_hInstance, DesktopSFHeader[iColumn].colnameid,
815                      psd->str.u.cStr, MAX_PATH);
816         return S_OK;
817     }
818
819     /* the data from the pidl */
820     psd->str.uType = STRRET_CSTR;
821     switch (iColumn)
822     {
823     case 0:        /* name */
824         hr = IShellFolder_GetDisplayNameOf(iface, pidl,
825                    SHGDN_NORMAL | SHGDN_INFOLDER, &psd->str);
826         break;
827     case 1:        /* size */
828         _ILGetFileSize (pidl, psd->str.u.cStr, MAX_PATH);
829         break;
830     case 2:        /* type */
831         _ILGetFileType (pidl, psd->str.u.cStr, MAX_PATH);
832         break;
833     case 3:        /* date */
834         _ILGetFileDate (pidl, psd->str.u.cStr, MAX_PATH);
835         break;
836     case 4:        /* attributes */
837         _ILGetFileAttributes (pidl, psd->str.u.cStr, MAX_PATH);
838         break;
839     }
840
841     return hr;
842 }
843
844 static HRESULT WINAPI ISF_Desktop_fnMapColumnToSCID (
845                 IShellFolder2 * iface, UINT column, SHCOLUMNID * pscid)
846 {
847     IGenericSFImpl *This = (IGenericSFImpl *)iface;
848     FIXME ("(%p)\n", This);
849     return E_NOTIMPL;
850 }
851
852 static const IShellFolder2Vtbl vt_MCFldr_ShellFolder2 =
853 {
854     ISF_Desktop_fnQueryInterface,
855     ISF_Desktop_fnAddRef,
856     ISF_Desktop_fnRelease,
857     ISF_Desktop_fnParseDisplayName,
858     ISF_Desktop_fnEnumObjects,
859     ISF_Desktop_fnBindToObject,
860     ISF_Desktop_fnBindToStorage,
861     ISF_Desktop_fnCompareIDs,
862     ISF_Desktop_fnCreateViewObject,
863     ISF_Desktop_fnGetAttributesOf,
864     ISF_Desktop_fnGetUIObjectOf,
865     ISF_Desktop_fnGetDisplayNameOf,
866     ISF_Desktop_fnSetNameOf,
867     /* ShellFolder2 */
868     ISF_Desktop_fnGetDefaultSearchGUID,
869     ISF_Desktop_fnEnumSearches,
870     ISF_Desktop_fnGetDefaultColumn,
871     ISF_Desktop_fnGetDefaultColumnState,
872     ISF_Desktop_fnGetDetailsEx,
873     ISF_Desktop_fnGetDetailsOf,
874     ISF_Desktop_fnMapColumnToSCID
875 };
876
877 /**************************************************************************
878  *    ISF_Desktop_Constructor
879  */
880 HRESULT WINAPI ISF_Desktop_Constructor (
881                 IUnknown * pUnkOuter, REFIID riid, LPVOID * ppv)
882 {
883     IGenericSFImpl *sf;
884     WCHAR szMyPath[MAX_PATH];
885     HRESULT r;
886
887     TRACE ("unkOut=%p %s\n", pUnkOuter, shdebugstr_guid (riid));
888
889     if (!ppv)
890         return E_POINTER;
891     if (pUnkOuter)
892         return CLASS_E_NOAGGREGATION;
893
894     if (!SHGetSpecialFolderPathW( 0, szMyPath, CSIDL_DESKTOPDIRECTORY, TRUE ))
895         return E_UNEXPECTED;
896
897     sf = LocalAlloc( LMEM_ZEROINIT, sizeof (IGenericSFImpl) );
898     if (!sf)
899         return E_OUTOFMEMORY;
900
901     sf->ref = 0;
902     sf->lpVtbl = &vt_MCFldr_ShellFolder2;
903     sf->pidlRoot = _ILCreateDesktop();    /* my qualified pidl */
904     sf->sPathTarget = SHAlloc( (lstrlenW(szMyPath) + 1)*sizeof(WCHAR) );
905     lstrcpyW( sf->sPathTarget, szMyPath );
906
907     r = IUnknown_QueryInterface( _IUnknown_(sf), riid, ppv );
908     if (!SUCCEEDED (r))
909     {
910         IUnknown_Release( _IUnknown_(sf) );
911         return r;
912     }
913
914     TRACE ("--(%p)\n", sf);
915     return S_OK;
916 }