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