- Implement IPersistFolder2.
[wine] / dlls / shell32 / shfldr_mycomp.c
1 /*
2  *    Virtual Workplace folder
3  *
4  *    Copyright 1997            Marcus Meissner
5  *    Copyright 1998, 1999, 2002    Juergen Schmied
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21
22 #include "config.h"
23 #include "wine/port.h"
24
25 #include <stdlib.h>
26 #include <string.h>
27 #include <stdarg.h>
28 #include <stdio.h>
29
30 #define COBJMACROS
31 #define NONAMELESSUNION
32 #define NONAMELESSSTRUCT
33
34 #include "winerror.h"
35 #include "windef.h"
36 #include "winbase.h"
37 #include "winreg.h"
38
39 #include "wingdi.h"
40 #include "pidl.h"
41 #include "shlguid.h"
42 #include "enumidlist.h"
43 #include "undocshell.h"
44 #include "shell32_main.h"
45 #include "shresdef.h"
46 #include "shlwapi.h"
47 #include "wine/debug.h"
48 #include "debughlp.h"
49 #include "shfldr.h"
50
51 WINE_DEFAULT_DEBUG_CHANNEL (shell);
52
53 /***********************************************************************
54 *   IShellFolder implementation
55 */
56
57 typedef struct {
58     IShellFolder2Vtbl   *lpVtbl;
59     DWORD                ref;
60     IPersistFolder2Vtbl *lpVtblPersistFolder2;
61
62     /* both paths are parsible from the desktop */
63     LPITEMIDLIST pidlRoot;    /* absolute pidl */
64     int dwAttributes;        /* attributes returned by GetAttributesOf FIXME: use it */
65 } IGenericSFImpl;
66
67 static struct IShellFolder2Vtbl vt_ShellFolder2;
68 static struct IPersistFolder2Vtbl vt_PersistFolder2;
69
70 #define _IPersistFolder2_Offset ((int)(&(((IGenericSFImpl*)0)->lpVtblPersistFolder2)))
71 #define _ICOM_THIS_From_IPersistFolder2(class, name) class* This = (class*)(((char*)name)-_IPersistFolder2_Offset);
72
73 /*
74   converts This to an interface pointer
75 */
76 #define _IUnknown_(This)    (IUnknown*)&(This->lpVtbl)
77 #define _IShellFolder_(This)    (IShellFolder*)&(This->lpVtbl)
78 #define _IShellFolder2_(This)    (IShellFolder2*)&(This->lpVtbl)
79
80 #define _IPersist_(This)    (IPersist*)&(This->lpVtblPersistFolder2)
81 #define _IPersistFolder_(This)    (IPersistFolder*)&(This->lpVtblPersistFolder2)
82 #define _IPersistFolder2_(This)    (IPersistFolder2*)&(This->lpVtblPersistFolder2)
83
84 /***********************************************************************
85 *   IShellFolder [MyComputer] implementation
86 */
87
88 static shvheader MyComputerSFHeader[] = {
89     {IDS_SHV_COLUMN1, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 15},
90     {IDS_SHV_COLUMN3, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
91     {IDS_SHV_COLUMN6, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
92     {IDS_SHV_COLUMN7, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
93 };
94
95 #define MYCOMPUTERSHELLVIEWCOLUMNS 4
96
97 /**************************************************************************
98 *    ISF_MyComputer_Constructor
99 */
100 HRESULT WINAPI ISF_MyComputer_Constructor (IUnknown * pUnkOuter, REFIID riid, LPVOID * ppv)
101 {
102     IGenericSFImpl *sf;
103
104     TRACE ("unkOut=%p %s\n", pUnkOuter, shdebugstr_guid (riid));
105
106     if (!ppv)
107         return E_POINTER;
108     if (pUnkOuter)
109         return CLASS_E_NOAGGREGATION;
110
111     sf = LocalAlloc (LMEM_ZEROINIT, sizeof (IGenericSFImpl));
112     if (!sf)
113         return E_OUTOFMEMORY;
114
115     sf->ref = 0;
116     sf->lpVtbl = &vt_ShellFolder2;
117     sf->lpVtblPersistFolder2 = &vt_PersistFolder2;
118     sf->pidlRoot = _ILCreateMyComputer ();    /* my qualified pidl */
119
120     if (!SUCCEEDED (IUnknown_QueryInterface (_IUnknown_ (sf), riid, ppv)))
121     {
122         IUnknown_Release (_IUnknown_ (sf));
123         return E_NOINTERFACE;
124     }
125
126     TRACE ("--(%p)\n", sf);
127     return S_OK;
128 }
129
130 /**************************************************************************
131  *    ISF_MyComputer_fnQueryInterface
132  *
133  * NOTES supports not IPersist/IPersistFolder
134  */
135 static HRESULT WINAPI ISF_MyComputer_fnQueryInterface (IShellFolder2 *iface,
136                REFIID riid, LPVOID *ppvObj)
137 {
138     IGenericSFImpl *This = (IGenericSFImpl *)iface;
139
140     TRACE ("(%p)->(%s,%p)\n", This, shdebugstr_guid (riid), ppvObj);
141
142     *ppvObj = NULL;
143
144     if (IsEqualIID (riid, &IID_IUnknown) ||
145         IsEqualIID (riid, &IID_IShellFolder) ||
146         IsEqualIID (riid, &IID_IShellFolder2))
147     {
148         *ppvObj = This;
149     }
150     else if (IsEqualIID (riid, &IID_IPersist) ||
151              IsEqualIID (riid, &IID_IPersistFolder) ||
152              IsEqualIID (riid, &IID_IPersistFolder2))
153     {
154         *ppvObj = _IPersistFolder2_ (This);
155     }
156
157     if (*ppvObj)
158     {
159         IUnknown_AddRef ((IUnknown *) (*ppvObj));
160         TRACE ("-- Interface: (%p)->(%p)\n", ppvObj, *ppvObj);
161         return S_OK;
162     }
163     TRACE ("-- Interface: E_NOINTERFACE\n");
164     return E_NOINTERFACE;
165 }
166
167 static ULONG WINAPI ISF_MyComputer_fnAddRef (IShellFolder2 * iface)
168 {
169     IGenericSFImpl *This = (IGenericSFImpl *)iface;
170     ULONG refCount = InterlockedIncrement(&This->ref);
171
172     TRACE ("(%p)->(count=%lu)\n", This, refCount - 1);
173
174     return refCount;
175 }
176
177 static ULONG WINAPI ISF_MyComputer_fnRelease (IShellFolder2 * iface)
178 {
179     IGenericSFImpl *This = (IGenericSFImpl *)iface;
180     ULONG refCount = InterlockedDecrement(&This->ref);
181
182     TRACE ("(%p)->(count=%lu)\n", This, refCount + 1);
183
184     if (!refCount)
185     {
186         TRACE ("-- destroying IShellFolder(%p)\n", This);
187         if (This->pidlRoot)
188             SHFree (This->pidlRoot);
189         LocalFree ((HLOCAL) This);
190     }
191     return refCount;
192 }
193
194 /**************************************************************************
195 *    ISF_MyComputer_fnParseDisplayName
196 */
197 static HRESULT WINAPI ISF_MyComputer_fnParseDisplayName (IShellFolder2 *iface,
198                HWND hwndOwner, LPBC pbc, LPOLESTR lpszDisplayName,
199                DWORD * pchEaten, LPITEMIDLIST * ppidl, DWORD * pdwAttributes)
200 {
201     IGenericSFImpl *This = (IGenericSFImpl *)iface;
202     HRESULT hr = E_INVALIDARG;
203     LPCWSTR szNext = NULL;
204     WCHAR szElement[MAX_PATH];
205     LPITEMIDLIST pidlTemp = NULL;
206     CLSID clsid;
207
208     TRACE("(%p)->(HWND=%p,%p,%p=%s,%p,pidl=%p,%p)\n", This,
209           hwndOwner, pbc, lpszDisplayName, debugstr_w (lpszDisplayName),
210           pchEaten, ppidl, pdwAttributes);
211
212     *ppidl = 0;
213     if (pchEaten)
214         *pchEaten = 0;        /* strange but like the original */
215
216     /* handle CLSID paths */
217     if (lpszDisplayName[0] == ':' && lpszDisplayName[1] == ':')
218     {
219         szNext = GetNextElementW (lpszDisplayName, szElement, MAX_PATH);
220         TRACE ("-- element: %s\n", debugstr_w (szElement));
221         SHCLSIDFromStringW (szElement + 2, &clsid);
222         pidlTemp = _ILCreateGuid (PT_GUID, &clsid);
223     }
224     /* do we have an absolute path name ? */
225     else if (PathGetDriveNumberW (lpszDisplayName) >= 0 &&
226               lpszDisplayName[2] == (WCHAR) '\\')
227     {
228         szNext = GetNextElementW (lpszDisplayName, szElement, MAX_PATH);
229         /* make drive letter uppercase to enable PIDL comparison */
230         szElement[0] = toupper(szElement[0]);
231         pidlTemp = _ILCreateDrive (szElement);
232     }
233
234     if (szNext && *szNext)
235     {
236         hr = SHELL32_ParseNextElement (iface, hwndOwner, pbc, &pidlTemp,
237                               (LPOLESTR) szNext, pchEaten, pdwAttributes);
238     }
239     else
240     {
241         if (pdwAttributes && *pdwAttributes)
242             SHELL32_GetItemAttributes (_IShellFolder_ (This),
243                                        pidlTemp, pdwAttributes);
244         hr = S_OK;
245     }
246
247     *ppidl = pidlTemp;
248
249     TRACE ("(%p)->(-- ret=0x%08lx)\n", This, hr);
250
251     return hr;
252 }
253
254 /**************************************************************************
255  *  CreateMyCompEnumList()
256  */
257 static const WCHAR MyComputer_NameSpaceW[] = { 'S','O','F','T','W','A','R','E',
258  '\\','M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
259  'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\','E','x','p','l',
260  'o','r','e','r','\\','M','y','C','o','m','p','u','t','e','r','\\','N','a','m',
261  'e','s','p','a','c','e','\0' };
262
263 static BOOL CreateMyCompEnumList(IEnumIDList *list, DWORD dwFlags)
264 {
265     BOOL ret = TRUE;
266
267     TRACE("(%p)->(flags=0x%08lx) \n",list,dwFlags);
268
269     /* enumerate the folders */
270     if (dwFlags & SHCONTF_FOLDERS)
271     {
272         WCHAR wszDriveName[] = {'A', ':', '\\', '\0'};
273         DWORD dwDrivemap = GetLogicalDrives();
274         HKEY hkey;
275
276         while (ret && wszDriveName[0]<='Z')
277         {
278             if(dwDrivemap & 0x00000001L)
279                 ret = AddToEnumList(list, _ILCreateDrive(wszDriveName));
280             wszDriveName[0]++;
281             dwDrivemap = dwDrivemap >> 1;
282         }
283
284         TRACE("-- (%p)-> enumerate (mycomputer shell extensions)\n",list);
285         if (ret && !RegOpenKeyExW(HKEY_LOCAL_MACHINE, MyComputer_NameSpaceW,
286          0, KEY_READ, &hkey))
287         {
288             WCHAR iid[50];
289             int i=0;
290
291             while (ret)
292             {
293                 DWORD size;
294                 LONG r;
295
296                 size = sizeof(iid) / sizeof(iid[0]);
297                 r = RegEnumKeyExW(hkey, i, iid, &size, 0, NULL, NULL, NULL);
298                 if (ERROR_SUCCESS == r)
299                 {
300                     /* FIXME: shell extensions, shouldn't the type be
301                      * PT_SHELLEXT? */
302                     ret = AddToEnumList(list, _ILCreateGuidFromStrW(iid));
303                     i++;
304                 }
305                 else if (ERROR_NO_MORE_ITEMS == r)
306                     break;
307                 else
308                     ret = FALSE;
309             }
310             RegCloseKey(hkey);
311         }
312     }
313     return ret;
314 }
315
316 /**************************************************************************
317 *        ISF_MyComputer_fnEnumObjects
318 */
319 static HRESULT WINAPI ISF_MyComputer_fnEnumObjects (IShellFolder2 *iface,
320                HWND hwndOwner, DWORD dwFlags, LPENUMIDLIST *ppEnumIDList)
321 {
322     IGenericSFImpl *This = (IGenericSFImpl *)iface;
323
324     TRACE("(%p)->(HWND=%p flags=0x%08lx pplist=%p)\n", This,
325           hwndOwner, dwFlags, ppEnumIDList);
326
327     *ppEnumIDList = IEnumIDList_Constructor();
328     if (*ppEnumIDList)
329         CreateMyCompEnumList(*ppEnumIDList, dwFlags);
330
331     TRACE ("-- (%p)->(new ID List: %p)\n", This, *ppEnumIDList);
332
333     return (*ppEnumIDList) ? S_OK : E_OUTOFMEMORY;
334 }
335
336 /**************************************************************************
337 *        ISF_MyComputer_fnBindToObject
338 */
339 static HRESULT WINAPI ISF_MyComputer_fnBindToObject (IShellFolder2 *iface,
340                LPCITEMIDLIST pidl, LPBC pbcReserved, REFIID riid, LPVOID *ppvOut)
341 {
342     IGenericSFImpl *This = (IGenericSFImpl *)iface;
343
344     TRACE("(%p)->(pidl=%p,%p,%s,%p)\n", This,
345           pidl, pbcReserved, shdebugstr_guid (riid), ppvOut);
346
347     return SHELL32_BindToChild (This->pidlRoot, NULL, pidl, riid, ppvOut);
348 }
349
350 /**************************************************************************
351 *    ISF_MyComputer_fnBindToStorage
352 */
353 static HRESULT WINAPI ISF_MyComputer_fnBindToStorage (IShellFolder2 * iface,
354                LPCITEMIDLIST pidl, LPBC pbcReserved, REFIID riid, LPVOID *ppvOut)
355 {
356     IGenericSFImpl *This = (IGenericSFImpl *)iface;
357
358     FIXME("(%p)->(pidl=%p,%p,%s,%p) stub\n", This,
359           pidl, pbcReserved, shdebugstr_guid (riid), ppvOut);
360
361     *ppvOut = NULL;
362     return E_NOTIMPL;
363 }
364
365 /**************************************************************************
366 *     ISF_MyComputer_fnCompareIDs
367 */
368
369 static HRESULT WINAPI ISF_MyComputer_fnCompareIDs (IShellFolder2 *iface,
370                LPARAM lParam, LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
371 {
372     IGenericSFImpl *This = (IGenericSFImpl *)iface;
373     int nReturn;
374
375     TRACE ("(%p)->(0x%08lx,pidl1=%p,pidl2=%p)\n", This, lParam, pidl1, pidl2);
376     nReturn = SHELL32_CompareIDs (_IShellFolder_ (This), lParam, pidl1, pidl2);
377     TRACE ("-- %i\n", nReturn);
378     return nReturn;
379 }
380
381 /**************************************************************************
382 *    ISF_MyComputer_fnCreateViewObject
383 */
384 static HRESULT WINAPI ISF_MyComputer_fnCreateViewObject (IShellFolder2 *iface,
385                HWND hwndOwner, REFIID riid, LPVOID * ppvOut)
386 {
387     IGenericSFImpl *This = (IGenericSFImpl *)iface;
388     LPSHELLVIEW pShellView;
389     HRESULT hr = E_INVALIDARG;
390
391     TRACE("(%p)->(hwnd=%p,%s,%p)\n", This,
392           hwndOwner, shdebugstr_guid (riid), ppvOut);
393
394     if (!ppvOut)
395         return hr;
396
397     *ppvOut = NULL;
398
399     if (IsEqualIID (riid, &IID_IDropTarget))
400     {
401         WARN ("IDropTarget not implemented\n");
402         hr = E_NOTIMPL;
403     }
404     else if (IsEqualIID (riid, &IID_IContextMenu))
405     {
406         WARN ("IContextMenu not implemented\n");
407         hr = E_NOTIMPL;
408     }
409     else if (IsEqualIID (riid, &IID_IShellView))
410     {
411         pShellView = IShellView_Constructor ((IShellFolder *) iface);
412         if (pShellView)
413         {
414             hr = IShellView_QueryInterface (pShellView, riid, ppvOut);
415             IShellView_Release (pShellView);
416         }
417     }
418     TRACE ("-- (%p)->(interface=%p)\n", This, ppvOut);
419     return hr;
420 }
421
422 /**************************************************************************
423 *  ISF_MyComputer_fnGetAttributesOf
424 */
425 static HRESULT WINAPI ISF_MyComputer_fnGetAttributesOf (IShellFolder2 * iface,
426                 UINT cidl, LPCITEMIDLIST * apidl, DWORD * rgfInOut)
427 {
428     IGenericSFImpl *This = (IGenericSFImpl *)iface;
429     HRESULT hr = S_OK;
430
431     TRACE ("(%p)->(cidl=%d apidl=%p mask=%p (0x%08lx))\n",
432            This, cidl, apidl, rgfInOut, rgfInOut ? *rgfInOut : 0);
433
434     if (!rgfInOut)
435         return E_INVALIDARG;
436     if (cidl && !apidl)
437         return E_INVALIDARG;
438
439     if (*rgfInOut == 0)
440         *rgfInOut = ~0;
441
442     while (cidl > 0 && *apidl)
443     {
444         pdump (*apidl);
445         SHELL32_GetItemAttributes (_IShellFolder_ (This), *apidl, rgfInOut);
446         apidl++;
447         cidl--;
448     }
449     /* make sure SFGAO_VALIDATE is cleared, some apps depend on that */
450     *rgfInOut &= ~SFGAO_VALIDATE;
451
452     TRACE ("-- result=0x%08lx\n", *rgfInOut);
453     return hr;
454 }
455
456 /**************************************************************************
457 *    ISF_MyComputer_fnGetUIObjectOf
458 *
459 * PARAMETERS
460 *  hwndOwner [in]  Parent window for any output
461 *  cidl      [in]  array size
462 *  apidl     [in]  simple pidl array
463 *  riid      [in]  Requested Interface
464 *  prgfInOut [   ] reserved
465 *  ppvObject [out] Resulting Interface
466 *
467 */
468 static HRESULT WINAPI ISF_MyComputer_fnGetUIObjectOf (IShellFolder2 * iface,
469                 HWND hwndOwner, UINT cidl, LPCITEMIDLIST * apidl, REFIID riid,
470                 UINT * prgfInOut, LPVOID * ppvOut)
471 {
472     IGenericSFImpl *This = (IGenericSFImpl *)iface;
473
474     LPITEMIDLIST pidl;
475     IUnknown *pObj = NULL;
476     HRESULT hr = E_INVALIDARG;
477
478     TRACE("(%p)->(%p,%u,apidl=%p,%s,%p,%p)\n", This,
479           hwndOwner, cidl, apidl, shdebugstr_guid (riid), prgfInOut, ppvOut);
480
481     if (!ppvOut)
482         return hr;
483
484     *ppvOut = NULL;
485
486     if (IsEqualIID (riid, &IID_IContextMenu) && (cidl >= 1))
487     {
488         pObj = (LPUNKNOWN) ISvItemCm_Constructor ((IShellFolder *) iface,
489                                               This->pidlRoot, apidl, cidl);
490         hr = S_OK;
491     }
492     else if (IsEqualIID (riid, &IID_IDataObject) && (cidl >= 1))
493     {
494         pObj = (LPUNKNOWN) IDataObject_Constructor (hwndOwner,
495                                               This->pidlRoot, apidl, cidl);
496         hr = S_OK;
497     }
498     else if (IsEqualIID (riid, &IID_IExtractIconA) && (cidl == 1))
499     {
500         pidl = ILCombine (This->pidlRoot, apidl[0]);
501         pObj = (LPUNKNOWN) IExtractIconA_Constructor (pidl);
502         SHFree (pidl);
503         hr = S_OK;
504     }
505     else if (IsEqualIID (riid, &IID_IExtractIconW) && (cidl == 1))
506     {
507         pidl = ILCombine (This->pidlRoot, apidl[0]);
508         pObj = (LPUNKNOWN) IExtractIconW_Constructor (pidl);
509         SHFree (pidl);
510         hr = S_OK;
511     }
512     else if (IsEqualIID (riid, &IID_IDropTarget) && (cidl >= 1))
513     {
514         hr = IShellFolder_QueryInterface (iface, &IID_IDropTarget,
515                                           (LPVOID *) &pObj);
516     }
517     else if ((IsEqualIID(riid,&IID_IShellLinkW) ||
518               IsEqualIID(riid,&IID_IShellLinkA)) && (cidl == 1))
519     {
520         pidl = ILCombine (This->pidlRoot, apidl[0]);
521         hr = IShellLink_ConstructFromFile(NULL, riid, pidl, (LPVOID*) &pObj);
522         SHFree (pidl);
523     }
524     else 
525         hr = E_NOINTERFACE;
526
527     if (SUCCEEDED(hr) && !pObj)
528         hr = E_OUTOFMEMORY;
529
530     *ppvOut = pObj;
531     TRACE ("(%p)->hr=0x%08lx\n", This, hr);
532     return hr;
533 }
534
535 /**************************************************************************
536 *    ISF_MyComputer_fnGetDisplayNameOf
537 */
538 static HRESULT WINAPI ISF_MyComputer_fnGetDisplayNameOf (IShellFolder2 *iface,
539                LPCITEMIDLIST pidl, DWORD dwFlags, LPSTRRET strRet)
540 {
541     IGenericSFImpl *This = (IGenericSFImpl *)iface;
542
543     char szPath[MAX_PATH];
544     HRESULT hr = S_OK;
545
546     TRACE ("(%p)->(pidl=%p,0x%08lx,%p)\n", This, pidl, dwFlags, strRet);
547     pdump (pidl);
548
549     if (!strRet)
550         return E_INVALIDARG;
551
552     szPath[0] = 0x00;
553
554     if (!pidl->mkid.cb)
555     {
556         /* parsing name like ::{...} */
557         lstrcpyA (szPath, "::");
558         SHELL32_GUIDToStringA(&CLSID_MyComputer, &szPath[2]);
559     }
560     else if (_ILIsPidlSimple(pidl))    
561     {
562         /* take names of special folders only if its only this folder */
563         if (_ILIsSpecialFolder(pidl))
564         {
565             GUID const *clsid;
566
567             clsid = _ILGetGUIDPointer (pidl);
568             if (clsid)
569             {
570                 if (GET_SHGDN_FOR (dwFlags) == SHGDN_FORPARSING)
571                 {
572                     static const WCHAR clsidW[] =
573                      { 'C','L','S','I','D','\\',0 };
574                     static const WCHAR shellfolderW[] =
575                      { '\\','s','h','e','l','l','f','o','l','d','e','r',0 };
576                     static const WCHAR wantsForParsingW[] =
577                      { 'W','a','n','t','s','F','o','r','P','a','r','s','i','n',
578                      'g',0 };
579                     int bWantsForParsing = FALSE;
580                     WCHAR szRegPath[100];
581                     LONG r;
582
583                     /*
584                      * We can only get a filesystem path from a shellfolder
585                      * if the value WantsFORPARSING exists in
586                      *      CLSID\\{...}\\shellfolder 
587                      * exception: the MyComputer folder has this keys not
588                      *            but like any filesystem backed
589                      *            folder it needs these behaviour
590                      *
591                      * Get the "WantsFORPARSING" flag from the registry
592                      */
593
594                     lstrcpyW (szRegPath, clsidW);
595                     SHELL32_GUIDToStringW (clsid, &szRegPath[6]);
596                     lstrcatW (szRegPath, shellfolderW);
597                     r = SHGetValueW (HKEY_CLASSES_ROOT, szRegPath, 
598                                      wantsForParsingW, NULL, NULL, NULL);
599                     if (r == ERROR_SUCCESS)
600                         bWantsForParsing = TRUE;
601
602                     if ((GET_SHGDN_RELATION (dwFlags) == SHGDN_NORMAL) &&
603                         bWantsForParsing)
604                     {
605                         /*
606                          * We need the filesystem path to the destination folder
607                          * Only the folder itself can know it
608                          */
609                         hr = SHELL32_GetDisplayNameOfChild (iface, pidl,
610                                                 dwFlags, szPath, MAX_PATH);
611                     }
612                     else
613                     {
614                         LPSTR p;
615
616                         /* parsing name like ::{...} */
617                         p = lstrcpyA(szPath, "::") + 2;
618                         p += SHELL32_GUIDToStringA(&CLSID_MyComputer, p);
619
620                         lstrcatA(p, "\\::");
621                         p += 3;
622                         SHELL32_GUIDToStringA(clsid, p);
623                     }
624                 }
625                 else
626                 {
627                     /* user friendly name */
628                     HCR_GetClassNameA (clsid, szPath, MAX_PATH);
629                 }
630             }
631             else
632             {
633                 /* append my own path */
634                 _ILSimpleGetText (pidl, szPath, MAX_PATH);
635             }
636         }
637         else if (_ILIsDrive(pidl))
638         {        
639             _ILSimpleGetText (pidl, szPath, MAX_PATH);    /* append my own path */
640
641             /* long view "lw_name (C:)" */
642             if (!(dwFlags & SHGDN_FORPARSING))
643             {
644                 DWORD dwVolumeSerialNumber, dwMaximumComponetLength, dwFileSystemFlags;
645                 char szDrive[18] = "";
646
647                 GetVolumeInformationA (szPath, szDrive, sizeof (szDrive) - 6,
648                            &dwVolumeSerialNumber,
649                            &dwMaximumComponetLength, &dwFileSystemFlags, NULL, 0);
650                 strcat (szDrive, " (");
651                 strncat (szDrive, szPath, 2);
652                 strcat (szDrive, ")");
653                 strcpy (szPath, szDrive);
654             }
655         }
656         else 
657         {
658             /* Neither a shell namespace extension nor a drive letter. */
659             ERR("Wrong pidl type\n");
660             return E_INVALIDARG;
661         }
662     }
663     else
664     {
665         /* Complex pidl. Let the child folder do the work */
666         strRet->uType = STRRET_CSTR;
667         hr = SHELL32_GetDisplayNameOfChild(iface, pidl, dwFlags, szPath, MAX_PATH);
668     }
669
670     if (SUCCEEDED (hr))
671     {
672         strRet->uType = STRRET_CSTR;
673         lstrcpynA (strRet->u.cStr, szPath, MAX_PATH);
674     }
675
676     TRACE ("-- (%p)->(%s)\n", This, szPath);
677     return hr;
678 }
679
680 /**************************************************************************
681 *  ISF_MyComputer_fnSetNameOf
682 *  Changes the name of a file object or subfolder, possibly changing its item
683 *  identifier in the process.
684 *
685 * PARAMETERS
686 *  hwndOwner  [in]   Owner window for output
687 *  pidl       [in]   simple pidl of item to change
688 *  lpszName   [in]   the items new display name
689 *  dwFlags    [in]   SHGNO formatting flags
690 *  ppidlOut   [out]  simple pidl returned
691 */
692 static HRESULT WINAPI ISF_MyComputer_fnSetNameOf (
693                IShellFolder2 * iface, HWND hwndOwner, LPCITEMIDLIST pidl,
694                LPCOLESTR lpName, DWORD dwFlags, LPITEMIDLIST * pPidlOut)
695 {
696     IGenericSFImpl *This = (IGenericSFImpl *)iface;
697     FIXME ("(%p)->(%p,pidl=%p,%s,%lu,%p)\n", This,
698            hwndOwner, pidl, debugstr_w (lpName), dwFlags, pPidlOut);
699     return E_FAIL;
700 }
701
702 static HRESULT WINAPI ISF_MyComputer_fnGetDefaultSearchGUID (
703                IShellFolder2 * iface, GUID * pguid)
704 {
705     IGenericSFImpl *This = (IGenericSFImpl *)iface;
706     FIXME ("(%p)\n", This);
707     return E_NOTIMPL;
708 }
709 static HRESULT WINAPI ISF_MyComputer_fnEnumSearches (
710                IShellFolder2 * iface, IEnumExtraSearch ** ppenum)
711 {
712     IGenericSFImpl *This = (IGenericSFImpl *)iface;
713     FIXME ("(%p)\n", This);
714     return E_NOTIMPL;
715 }
716 static HRESULT WINAPI ISF_MyComputer_fnGetDefaultColumn (
717                IShellFolder2 *iface, DWORD dwRes, ULONG *pSort, ULONG *pDisplay)
718 {
719     IGenericSFImpl *This = (IGenericSFImpl *)iface;
720
721     TRACE ("(%p)\n", This);
722
723     if (pSort)
724          *pSort = 0;
725     if (pDisplay)
726         *pDisplay = 0;
727     return S_OK;
728 }
729 static HRESULT WINAPI ISF_MyComputer_fnGetDefaultColumnState (
730                IShellFolder2 * iface, UINT iColumn, DWORD * pcsFlags)
731 {
732     IGenericSFImpl *This = (IGenericSFImpl *)iface;
733
734     TRACE ("(%p)\n", This);
735
736     if (!pcsFlags || iColumn >= MYCOMPUTERSHELLVIEWCOLUMNS)
737         return E_INVALIDARG;
738     *pcsFlags = MyComputerSFHeader[iColumn].pcsFlags;
739     return S_OK;
740 }
741
742 static HRESULT WINAPI ISF_MyComputer_fnGetDetailsEx (IShellFolder2 * iface,
743                LPCITEMIDLIST pidl, const SHCOLUMNID * pscid, VARIANT * pv)
744 {
745     IGenericSFImpl *This = (IGenericSFImpl *)iface;
746     FIXME ("(%p)\n", This);
747     return E_NOTIMPL;
748 }
749
750 /* FIXME: drive size >4GB is rolling over */
751 static HRESULT WINAPI ISF_MyComputer_fnGetDetailsOf (IShellFolder2 * iface,
752                LPCITEMIDLIST pidl, UINT iColumn, SHELLDETAILS * psd)
753 {
754     IGenericSFImpl *This = (IGenericSFImpl *)iface;
755     HRESULT hr;
756
757     TRACE ("(%p)->(%p %i %p)\n", This, pidl, iColumn, psd);
758
759     if (!psd || iColumn >= MYCOMPUTERSHELLVIEWCOLUMNS)
760         return E_INVALIDARG;
761
762     if (!pidl)
763     {
764         psd->fmt = MyComputerSFHeader[iColumn].fmt;
765         psd->cxChar = MyComputerSFHeader[iColumn].cxChar;
766         psd->str.uType = STRRET_CSTR;
767         LoadStringA (shell32_hInstance, MyComputerSFHeader[iColumn].colnameid,
768                      psd->str.u.cStr, MAX_PATH);
769         return S_OK;
770     }
771     else
772     {
773         char szPath[MAX_PATH];
774         ULARGE_INTEGER ulBytes;
775
776         psd->str.u.cStr[0] = 0x00;
777         psd->str.uType = STRRET_CSTR;
778         switch (iColumn)
779         {
780         case 0:        /* name */
781             hr = IShellFolder_GetDisplayNameOf (iface, pidl,
782                        SHGDN_NORMAL | SHGDN_INFOLDER, &psd->str);
783             break;
784         case 1:        /* type */
785             _ILGetFileType (pidl, psd->str.u.cStr, MAX_PATH);
786             break;
787         case 2:        /* total size */
788             if (_ILIsDrive (pidl))
789             {
790                 _ILSimpleGetText (pidl, szPath, MAX_PATH);
791                 GetDiskFreeSpaceExA (szPath, NULL, &ulBytes, NULL);
792                 StrFormatByteSizeA (ulBytes.u.LowPart, psd->str.u.cStr, MAX_PATH);
793             }
794             break;
795         case 3:        /* free size */
796             if (_ILIsDrive (pidl))
797             {
798                 _ILSimpleGetText (pidl, szPath, MAX_PATH);
799                 GetDiskFreeSpaceExA (szPath, &ulBytes, NULL, NULL);
800                 StrFormatByteSizeA (ulBytes.u.LowPart, psd->str.u.cStr, MAX_PATH);
801             }
802             break;
803         }
804         hr = S_OK;
805     }
806
807     return hr;
808 }
809
810 static HRESULT WINAPI ISF_MyComputer_fnMapColumnToSCID (
811                IShellFolder2 * iface, UINT column, SHCOLUMNID * pscid)
812 {
813     IGenericSFImpl *This = (IGenericSFImpl *)iface;
814     FIXME ("(%p)\n", This);
815     return E_NOTIMPL;
816 }
817
818 static IShellFolder2Vtbl vt_ShellFolder2 =
819 {
820     ISF_MyComputer_fnQueryInterface,
821     ISF_MyComputer_fnAddRef,
822     ISF_MyComputer_fnRelease,
823     ISF_MyComputer_fnParseDisplayName,
824     ISF_MyComputer_fnEnumObjects,
825     ISF_MyComputer_fnBindToObject,
826     ISF_MyComputer_fnBindToStorage,
827     ISF_MyComputer_fnCompareIDs,
828     ISF_MyComputer_fnCreateViewObject,
829     ISF_MyComputer_fnGetAttributesOf,
830     ISF_MyComputer_fnGetUIObjectOf,
831     ISF_MyComputer_fnGetDisplayNameOf,
832     ISF_MyComputer_fnSetNameOf,
833     /* ShellFolder2 */
834     ISF_MyComputer_fnGetDefaultSearchGUID,
835     ISF_MyComputer_fnEnumSearches,
836     ISF_MyComputer_fnGetDefaultColumn,
837     ISF_MyComputer_fnGetDefaultColumnState,
838     ISF_MyComputer_fnGetDetailsEx,
839     ISF_MyComputer_fnGetDetailsOf,
840     ISF_MyComputer_fnMapColumnToSCID
841 };
842
843 /************************************************************************
844  *    IMCFldr_PersistFolder2_QueryInterface
845  */
846 static HRESULT WINAPI IMCFldr_PersistFolder2_QueryInterface (
847                IPersistFolder2 * iface, REFIID iid, LPVOID * ppvObj)
848 {
849     _ICOM_THIS_From_IPersistFolder2 (IGenericSFImpl, iface);
850
851     TRACE ("(%p)\n", This);
852
853     return IUnknown_QueryInterface (_IUnknown_ (This), iid, ppvObj);
854 }
855
856 /************************************************************************
857  *    IMCFldr_PersistFolder2_AddRef
858  */
859 static ULONG WINAPI IMCFldr_PersistFolder2_AddRef (IPersistFolder2 * iface)
860 {
861     _ICOM_THIS_From_IPersistFolder2 (IGenericSFImpl, iface);
862
863     TRACE ("(%p)->(count=%lu)\n", This, This->ref);
864
865     return IUnknown_AddRef (_IUnknown_ (This));
866 }
867
868 /************************************************************************
869  *    ISFPersistFolder_Release
870  */
871 static ULONG WINAPI IMCFldr_PersistFolder2_Release (IPersistFolder2 * iface)
872 {
873     _ICOM_THIS_From_IPersistFolder2 (IGenericSFImpl, iface);
874
875     TRACE ("(%p)->(count=%lu)\n", This, This->ref);
876
877     return IUnknown_Release (_IUnknown_ (This));
878 }
879
880 /************************************************************************
881  *    IMCFldr_PersistFolder2_GetClassID
882  */
883 static HRESULT WINAPI IMCFldr_PersistFolder2_GetClassID (
884                IPersistFolder2 * iface, CLSID * lpClassId)
885 {
886     _ICOM_THIS_From_IPersistFolder2 (IGenericSFImpl, iface);
887
888     TRACE ("(%p)\n", This);
889
890     if (!lpClassId)
891     return E_POINTER;
892     *lpClassId = CLSID_MyComputer;
893
894     return S_OK;
895 }
896
897 /************************************************************************
898  *    IMCFldr_PersistFolder2_Initialize
899  *
900  * NOTES: it makes no sense to change the pidl
901  */
902 static HRESULT WINAPI IMCFldr_PersistFolder2_Initialize (
903                IPersistFolder2 * iface, LPCITEMIDLIST pidl)
904 {
905     _ICOM_THIS_From_IPersistFolder2 (IGenericSFImpl, iface);
906     TRACE ("(%p)->(%p)\n", This, pidl);
907     return E_NOTIMPL;
908 }
909
910 /**************************************************************************
911  *    IPersistFolder2_fnGetCurFolder
912  */
913 static HRESULT WINAPI IMCFldr_PersistFolder2_GetCurFolder (
914                IPersistFolder2 * iface, LPITEMIDLIST * pidl)
915 {
916     _ICOM_THIS_From_IPersistFolder2 (IGenericSFImpl, iface);
917
918     TRACE ("(%p)->(%p)\n", This, pidl);
919
920     if (!pidl)
921         return E_POINTER;
922     *pidl = ILClone (This->pidlRoot);
923     return S_OK;
924 }
925
926 static IPersistFolder2Vtbl vt_PersistFolder2 =
927 {
928     IMCFldr_PersistFolder2_QueryInterface,
929     IMCFldr_PersistFolder2_AddRef,
930     IMCFldr_PersistFolder2_Release,
931     IMCFldr_PersistFolder2_GetClassID,
932     IMCFldr_PersistFolder2_Initialize,
933     IMCFldr_PersistFolder2_GetCurFolder
934 };