Get rid of the non-standard ICOM_VFIELD macro.
[wine] / dlls / shell32 / shfldr_mycomp.c
1
2 /*
3  *      Virtual Workplace 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 NONAMELESSUNION
32 #define NONAMELESSSTRUCT
33 #include "winerror.h"
34 #include "windef.h"
35 #include "winbase.h"
36 #include "winreg.h"
37
38 #include "wingdi.h"
39 #include "pidl.h"
40 #include "shlguid.h"
41 #include "enumidlist.h"
42 #include "undocshell.h"
43 #include "shell32_main.h"
44 #include "shresdef.h"
45 #include "shlwapi.h"
46 #include "shellfolder.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 ICOM_VTABLE (IShellFolder2) vt_ShellFolder2;
68 static struct ICOM_VTABLE (IPersistFolder2) 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 a 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 = (IGenericSFImpl *) LocalAlloc (GMEM_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         IUnknown_Release (_IUnknown_ (sf));
122         return E_NOINTERFACE;
123     }
124
125     TRACE ("--(%p)\n", sf);
126     return S_OK;
127 }
128
129 /**************************************************************************
130  *      ISF_MyComputer_fnQueryInterface
131  *
132  * NOTES supports not IPersist/IPersistFolder
133  */
134 static HRESULT WINAPI ISF_MyComputer_fnQueryInterface (IShellFolder2 * iface, REFIID riid, LPVOID * ppvObj)
135 {
136     ICOM_THIS (IGenericSFImpl, iface);
137
138     TRACE ("(%p)->(%s,%p)\n", This, shdebugstr_guid (riid), ppvObj);
139
140     *ppvObj = NULL;
141
142     if (IsEqualIID (riid, &IID_IUnknown) ||
143         IsEqualIID (riid, &IID_IShellFolder) || IsEqualIID (riid, &IID_IShellFolder2)) {
144         *ppvObj = This;
145     } else if (IsEqualIID (riid, &IID_IPersist) ||
146                IsEqualIID (riid, &IID_IPersistFolder) || IsEqualIID (riid, &IID_IPersistFolder2)) {
147         *ppvObj = _IPersistFolder2_ (This);
148     }
149
150     if (*ppvObj) {
151         IUnknown_AddRef ((IUnknown *) (*ppvObj));
152         TRACE ("-- Interface: (%p)->(%p)\n", ppvObj, *ppvObj);
153         return S_OK;
154     }
155     TRACE ("-- Interface: E_NOINTERFACE\n");
156     return E_NOINTERFACE;
157 }
158
159 static ULONG WINAPI ISF_MyComputer_fnAddRef (IShellFolder2 * iface)
160 {
161     ICOM_THIS (IGenericSFImpl, iface);
162
163     TRACE ("(%p)->(count=%lu)\n", This, This->ref);
164
165     return ++(This->ref);
166 }
167
168 static ULONG WINAPI ISF_MyComputer_fnRelease (IShellFolder2 * iface)
169 {
170     ICOM_THIS (IGenericSFImpl, iface);
171
172     TRACE ("(%p)->(count=%lu)\n", This, This->ref);
173
174     if (!--(This->ref)) {
175         TRACE ("-- destroying IShellFolder(%p)\n", This);
176         if (This->pidlRoot)
177             SHFree (This->pidlRoot);
178         LocalFree ((HLOCAL) This);
179         return 0;
180     }
181     return This->ref;
182 }
183
184 /**************************************************************************
185 *       ISF_MyComputer_fnParseDisplayName
186 */
187 static HRESULT WINAPI
188 ISF_MyComputer_fnParseDisplayName (IShellFolder2 * iface,
189                                    HWND hwndOwner,
190                                    LPBC pbc,
191                                    LPOLESTR lpszDisplayName,
192                                    DWORD * pchEaten, LPITEMIDLIST * ppidl, DWORD * pdwAttributes)
193 {
194     ICOM_THIS (IGenericSFImpl, iface);
195
196     HRESULT hr = E_INVALIDARG;
197     LPCWSTR szNext = NULL;
198     WCHAR szElement[MAX_PATH];
199     LPITEMIDLIST pidlTemp = NULL;
200     CLSID clsid;
201
202     TRACE ("(%p)->(HWND=%p,%p,%p=%s,%p,pidl=%p,%p)\n",
203            This, hwndOwner, pbc, lpszDisplayName, debugstr_w (lpszDisplayName), pchEaten, ppidl, pdwAttributes);
204
205     *ppidl = 0;
206     if (pchEaten)
207         *pchEaten = 0;          /* strange but like the original */
208
209     /* handle CLSID paths */
210     if (lpszDisplayName[0] == ':' && lpszDisplayName[1] == ':') {
211         szNext = GetNextElementW (lpszDisplayName, szElement, MAX_PATH);
212         TRACE ("-- element: %s\n", debugstr_w (szElement));
213         SHCLSIDFromStringW (szElement + 2, &clsid);
214         pidlTemp = _ILCreateGuid (PT_GUID, &clsid);
215     }
216     /* do we have an absolute path name ? */
217     else if (PathGetDriveNumberW (lpszDisplayName) >= 0 && lpszDisplayName[2] == (WCHAR) '\\') {
218         szNext = GetNextElementW (lpszDisplayName, szElement, MAX_PATH);
219         pidlTemp = _ILCreateDrive (szElement);
220     }
221
222     if (szNext && *szNext) {
223         hr = SHELL32_ParseNextElement (iface, hwndOwner, pbc, &pidlTemp, (LPOLESTR) szNext, pchEaten, pdwAttributes);
224     } else {
225         if (pdwAttributes && *pdwAttributes) {
226             SHELL32_GetItemAttributes (_IShellFolder_ (This), pidlTemp, pdwAttributes);
227         }
228         hr = S_OK;
229     }
230
231     *ppidl = pidlTemp;
232
233     TRACE ("(%p)->(-- ret=0x%08lx)\n", This, hr);
234
235     return hr;
236 }
237
238 /**************************************************************************
239  *  CreateMyCompEnumList()
240  */
241 static BOOL CreateMyCompEnumList(IEnumIDList *list, DWORD dwFlags)
242 {
243     BOOL ret = TRUE;
244
245     TRACE("(%p)->(flags=0x%08lx) \n",list,dwFlags);
246
247     /*enumerate the folders*/
248     if(dwFlags & SHCONTF_FOLDERS)
249     {
250         WCHAR wszDriveName[] = {'A', ':', '\\', '\0'};
251         DWORD dwDrivemap = GetLogicalDrives();
252         HKEY hkey;
253
254         while (ret && wszDriveName[0]<='Z')
255         {
256             if(dwDrivemap & 0x00000001L)
257                 ret = AddToEnumList(list, _ILCreateDrive(wszDriveName));
258             wszDriveName[0]++;
259             dwDrivemap = dwDrivemap >> 1;
260         }
261
262         TRACE("-- (%p)-> enumerate (mycomputer shell extensions)\n",list);
263         if (ret && !RegOpenKeyExA(HKEY_LOCAL_MACHINE,
264          "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\explorer\\mycomputer\\NameSpace",
265          0, KEY_READ, &hkey))
266         {
267             char iid[50];
268             int i=0;
269
270             while (ret)
271             {
272                 DWORD size = sizeof (iid);
273                 LONG apiRet = RegEnumKeyExA(hkey, i, iid, &size, 0, NULL, NULL,
274                  NULL);
275
276                 if (ERROR_SUCCESS == apiRet)
277                 {
278                     /* FIXME: shell extensions, shouldn't the type be
279                      * PT_SHELLEXT? */
280                     ret = AddToEnumList(list, _ILCreateGuidFromStrA(iid));
281                     i++;
282                 }
283                 else if (ERROR_NO_MORE_ITEMS == apiRet)
284                     break;
285                 else
286                     ret = FALSE;
287             }
288             RegCloseKey(hkey);
289         }
290     }
291     return ret;
292 }
293
294 /**************************************************************************
295 *               ISF_MyComputer_fnEnumObjects
296 */
297 static HRESULT WINAPI
298 ISF_MyComputer_fnEnumObjects (IShellFolder2 * iface, HWND hwndOwner, DWORD dwFlags, LPENUMIDLIST * ppEnumIDList)
299 {
300     ICOM_THIS (IGenericSFImpl, iface);
301
302     TRACE ("(%p)->(HWND=%p flags=0x%08lx pplist=%p)\n", This, hwndOwner, dwFlags, ppEnumIDList);
303
304     *ppEnumIDList = IEnumIDList_Constructor();
305     if (*ppEnumIDList)
306         CreateMyCompEnumList(*ppEnumIDList, dwFlags);
307
308     TRACE ("-- (%p)->(new ID List: %p)\n", This, *ppEnumIDList);
309
310     return (*ppEnumIDList) ? S_OK : E_OUTOFMEMORY;
311 }
312
313 /**************************************************************************
314 *               ISF_MyComputer_fnBindToObject
315 */
316 static HRESULT WINAPI
317 ISF_MyComputer_fnBindToObject (IShellFolder2 * iface, LPCITEMIDLIST pidl,
318                                LPBC pbcReserved, REFIID riid, LPVOID * ppvOut)
319 {
320     ICOM_THIS (IGenericSFImpl, iface);
321
322     TRACE ("(%p)->(pidl=%p,%p,%s,%p)\n", This, pidl, pbcReserved, shdebugstr_guid (riid), ppvOut);
323
324     return SHELL32_BindToChild (This->pidlRoot, NULL, pidl, riid, ppvOut);
325 }
326
327 /**************************************************************************
328 *       ISF_MyComputer_fnBindToStorage
329 */
330 static HRESULT WINAPI
331 ISF_MyComputer_fnBindToStorage (IShellFolder2 * iface,
332                                 LPCITEMIDLIST pidl, LPBC pbcReserved, REFIID riid, LPVOID * ppvOut)
333 {
334     ICOM_THIS (IGenericSFImpl, iface);
335
336     FIXME ("(%p)->(pidl=%p,%p,%s,%p) stub\n", This, pidl, pbcReserved, shdebugstr_guid (riid), ppvOut);
337
338     *ppvOut = NULL;
339     return E_NOTIMPL;
340 }
341
342 /**************************************************************************
343 *       ISF_MyComputer_fnCompareIDs
344 */
345
346 static HRESULT WINAPI
347 ISF_MyComputer_fnCompareIDs (IShellFolder2 * iface, LPARAM lParam, LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
348 {
349     ICOM_THIS (IGenericSFImpl, iface);
350
351     int nReturn;
352
353     TRACE ("(%p)->(0x%08lx,pidl1=%p,pidl2=%p)\n", This, lParam, pidl1, pidl2);
354     nReturn = SHELL32_CompareIDs (_IShellFolder_ (This), lParam, pidl1, pidl2);
355     TRACE ("-- %i\n", nReturn);
356     return nReturn;
357 }
358
359 /**************************************************************************
360 *       ISF_MyComputer_fnCreateViewObject
361 */
362 static HRESULT WINAPI
363 ISF_MyComputer_fnCreateViewObject (IShellFolder2 * iface, HWND hwndOwner, REFIID riid, LPVOID * ppvOut)
364 {
365     ICOM_THIS (IGenericSFImpl, iface);
366
367     LPSHELLVIEW pShellView;
368     HRESULT hr = E_INVALIDARG;
369
370     TRACE ("(%p)->(hwnd=%p,%s,%p)\n", This, hwndOwner, shdebugstr_guid (riid), ppvOut);
371
372     if (ppvOut) {
373         *ppvOut = NULL;
374
375         if (IsEqualIID (riid, &IID_IDropTarget)) {
376             WARN ("IDropTarget not implemented\n");
377             hr = E_NOTIMPL;
378         } else if (IsEqualIID (riid, &IID_IContextMenu)) {
379             WARN ("IContextMenu not implemented\n");
380             hr = E_NOTIMPL;
381         } else if (IsEqualIID (riid, &IID_IShellView)) {
382             pShellView = IShellView_Constructor ((IShellFolder *) iface);
383             if (pShellView) {
384                 hr = IShellView_QueryInterface (pShellView, riid, ppvOut);
385                 IShellView_Release (pShellView);
386             }
387         }
388     }
389     TRACE ("-- (%p)->(interface=%p)\n", This, ppvOut);
390     return hr;
391 }
392
393 /**************************************************************************
394 *  ISF_MyComputer_fnGetAttributesOf
395 */
396 static HRESULT WINAPI
397 ISF_MyComputer_fnGetAttributesOf (IShellFolder2 * iface, UINT cidl, LPCITEMIDLIST * apidl, DWORD * rgfInOut)
398 {
399     ICOM_THIS (IGenericSFImpl, iface);
400
401     HRESULT hr = S_OK;
402
403     TRACE ("(%p)->(cidl=%d apidl=%p mask=0x%08lx)\n", This, cidl, apidl, *rgfInOut);
404
405     if ((!cidl) || (!apidl) || (!rgfInOut))
406         return E_INVALIDARG;
407
408     if (*rgfInOut == 0)
409         *rgfInOut = ~0;
410
411     while (cidl > 0 && *apidl) {
412         pdump (*apidl);
413         SHELL32_GetItemAttributes (_IShellFolder_ (This), *apidl, rgfInOut);
414         apidl++;
415         cidl--;
416     }
417
418     TRACE ("-- result=0x%08lx\n", *rgfInOut);
419     return hr;
420 }
421
422 /**************************************************************************
423 *       ISF_MyComputer_fnGetUIObjectOf
424 *
425 * PARAMETERS
426 *  HWND           hwndOwner, //[in ] Parent window for any output
427 *  UINT           cidl,      //[in ] array size
428 *  LPCITEMIDLIST* apidl,     //[in ] simple pidl array
429 *  REFIID         riid,      //[in ] Requested Interface
430 *  UINT*          prgfInOut, //[   ] reserved
431 *  LPVOID*        ppvObject) //[out] Resulting Interface
432 *
433 */
434 static HRESULT WINAPI
435 ISF_MyComputer_fnGetUIObjectOf (IShellFolder2 * iface,
436                                 HWND hwndOwner,
437                                 UINT cidl, LPCITEMIDLIST * apidl, REFIID riid, UINT * prgfInOut, LPVOID * ppvOut)
438 {
439     ICOM_THIS (IGenericSFImpl, iface);
440
441     LPITEMIDLIST pidl;
442     IUnknown *pObj = NULL;
443     HRESULT hr = E_INVALIDARG;
444
445     TRACE ("(%p)->(%p,%u,apidl=%p,%s,%p,%p)\n",
446            This, hwndOwner, cidl, apidl, shdebugstr_guid (riid), prgfInOut, ppvOut);
447
448     if (ppvOut) {
449         *ppvOut = NULL;
450
451         if (IsEqualIID (riid, &IID_IContextMenu) && (cidl >= 1)) {
452             pObj = (LPUNKNOWN) ISvItemCm_Constructor ((IShellFolder *) iface, This->pidlRoot, apidl, cidl);
453             hr = S_OK;
454         } else if (IsEqualIID (riid, &IID_IDataObject) && (cidl >= 1)) {
455             pObj = (LPUNKNOWN) IDataObject_Constructor (hwndOwner, This->pidlRoot, apidl, cidl);
456             hr = S_OK;
457         } else if (IsEqualIID (riid, &IID_IExtractIconA) && (cidl == 1)) {
458             pidl = ILCombine (This->pidlRoot, apidl[0]);
459             pObj = (LPUNKNOWN) IExtractIconA_Constructor (pidl);
460             SHFree (pidl);
461             hr = S_OK;
462         } else if (IsEqualIID (riid, &IID_IExtractIconW) && (cidl == 1)) {
463             pidl = ILCombine (This->pidlRoot, apidl[0]);
464             pObj = (LPUNKNOWN) IExtractIconW_Constructor (pidl);
465             SHFree (pidl);
466             hr = S_OK;
467         } else if (IsEqualIID (riid, &IID_IDropTarget) && (cidl >= 1)) {
468             hr = IShellFolder_QueryInterface (iface, &IID_IDropTarget, (LPVOID *) & pObj);
469         } else if ((IsEqualIID(riid,&IID_IShellLinkW) || IsEqualIID(riid,&IID_IShellLinkA))
470                                 && (cidl == 1)) {
471             pidl = ILCombine (This->pidlRoot, apidl[0]);
472             hr = IShellLink_ConstructFromFile(NULL, riid, pidl, (LPVOID*)&pObj);
473             SHFree (pidl);
474         } else {
475             hr = E_NOINTERFACE;
476         }
477
478         if (SUCCEEDED(hr) && !pObj)
479             hr = E_OUTOFMEMORY;
480
481         *ppvOut = pObj;
482     }
483     TRACE ("(%p)->hr=0x%08lx\n", This, hr);
484     return hr;
485 }
486
487 /**************************************************************************
488 *       ISF_MyComputer_fnGetDisplayNameOf
489 */
490 static HRESULT WINAPI ISF_MyComputer_fnGetDisplayNameOf (IShellFolder2 * iface, LPCITEMIDLIST pidl, DWORD dwFlags, LPSTRRET strRet)
491 {
492     ICOM_THIS (IGenericSFImpl, iface);
493
494     char szPath[MAX_PATH],
495       szDrive[18];
496     int len = 0;
497     BOOL bSimplePidl;
498     HRESULT hr = S_OK;
499
500     TRACE ("(%p)->(pidl=%p,0x%08lx,%p)\n", This, pidl, dwFlags, strRet);
501     pdump (pidl);
502
503     if (!strRet)
504         return E_INVALIDARG;
505
506     szPath[0] = 0x00;
507     szDrive[0] = 0x00;
508
509     bSimplePidl = _ILIsPidlSimple (pidl);
510
511     if (!pidl->mkid.cb) {
512         /* parsing name like ::{...} */
513         lstrcpyA (szPath, "::");
514         SHELL32_GUIDToStringA(&CLSID_MyComputer, &szPath[2]);
515     } else if (_ILIsSpecialFolder (pidl)) {
516         /* take names of special folders only if its only this folder */
517         if (bSimplePidl) {
518             GUID const *clsid;
519
520             if ((clsid = _ILGetGUIDPointer (pidl))) {
521                 if (GET_SHGDN_FOR (dwFlags) == SHGDN_FORPARSING) {
522                     int bWantsForParsing;
523
524                     /*
525                      * we can only get a filesystem path from a shellfolder if the value WantsFORPARSING in
526                      * CLSID\\{...}\\shellfolder exists
527                      * exception: the MyComputer folder has this keys not but like any filesystem backed
528                      *            folder it needs these behaviour
529                      */
530                     /* get the "WantsFORPARSING" flag from the registry */
531                     char szRegPath[100];
532
533                     lstrcpyA (szRegPath, "CLSID\\");
534                     SHELL32_GUIDToStringA (clsid, &szRegPath[6]);
535                     lstrcatA (szRegPath, "\\shellfolder");
536                     bWantsForParsing =
537                         (ERROR_SUCCESS ==
538                          SHGetValueA (HKEY_CLASSES_ROOT, szRegPath, "WantsFORPARSING", NULL, NULL, NULL));
539
540                     if ((GET_SHGDN_RELATION (dwFlags) == SHGDN_NORMAL) && bWantsForParsing) {
541                         /* we need the filesystem path to the destination folder. Only the folder itself can know it */
542                         hr = SHELL32_GetDisplayNameOfChild (iface, pidl, dwFlags, szPath, MAX_PATH);
543                     } else {
544                         LPSTR p;
545
546                         /* parsing name like ::{...} */
547                         p = lstrcpyA(szPath, "::") + 2;
548                         p += SHELL32_GUIDToStringA(&CLSID_MyComputer, p);
549
550                         lstrcatA(p, "\\::");
551                         p += 3;
552                         SHELL32_GUIDToStringA(clsid, p);
553                     }
554                 } else {
555                     /* user friendly name */
556                     HCR_GetClassNameA (clsid, szPath, MAX_PATH);
557                 }
558             } else
559                 _ILSimpleGetText (pidl, szPath, MAX_PATH);      /* append my own path */
560         } else {
561             FIXME ("special folder\n");
562         }
563     } else {
564         if (!_ILIsDrive (pidl)) {
565             ERR ("Wrong pidl type\n");
566             return E_INVALIDARG;
567         }
568
569         _ILSimpleGetText (pidl, szPath, MAX_PATH);      /* append my own path */
570
571         /* long view "lw_name (C:)" */
572         if (bSimplePidl && !(dwFlags & SHGDN_FORPARSING)) {
573             DWORD dwVolumeSerialNumber,
574               dwMaximumComponetLength,
575               dwFileSystemFlags;
576
577             GetVolumeInformationA (szPath, szDrive, sizeof (szDrive) - 6, &dwVolumeSerialNumber,
578                                    &dwMaximumComponetLength, &dwFileSystemFlags, NULL, 0);
579             strcat (szDrive, " (");
580             strncat (szDrive, szPath, 2);
581             strcat (szDrive, ")");
582             strcpy (szPath, szDrive);
583         }
584     }
585
586     if (!bSimplePidl) {         /* go deeper if needed */
587         PathAddBackslashA (szPath);
588         len = strlen (szPath);
589
590         hr = SHELL32_GetDisplayNameOfChild (iface, pidl, dwFlags | SHGDN_INFOLDER, szPath + len, MAX_PATH - len);
591     }
592
593     if (SUCCEEDED (hr)) {
594         strRet->uType = STRRET_CSTR;
595         lstrcpynA (strRet->u.cStr, szPath, MAX_PATH);
596     }
597
598     TRACE ("-- (%p)->(%s)\n", This, szPath);
599     return hr;
600 }
601
602 /**************************************************************************
603 *  ISF_MyComputer_fnSetNameOf
604 *  Changes the name of a file object or subfolder, possibly changing its item
605 *  identifier in the process.
606 *
607 * PARAMETERS
608 *  HWND          hwndOwner,  //[in ] Owner window for output
609 *  LPCITEMIDLIST pidl,       //[in ] simple pidl of item to change
610 *  LPCOLESTR     lpszName,   //[in ] the items new display name
611 *  DWORD         dwFlags,    //[in ] SHGNO formatting flags
612 *  LPITEMIDLIST* ppidlOut)   //[out] simple pidl returned
613 */
614 static HRESULT WINAPI ISF_MyComputer_fnSetNameOf (IShellFolder2 * iface, HWND hwndOwner, LPCITEMIDLIST pidl,    /*simple pidl */
615                                                   LPCOLESTR lpName, DWORD dwFlags, LPITEMIDLIST * pPidlOut)
616 {
617     ICOM_THIS (IGenericSFImpl, iface);
618     FIXME ("(%p)->(%p,pidl=%p,%s,%lu,%p)\n", This, hwndOwner, pidl, debugstr_w (lpName), dwFlags, pPidlOut);
619     return E_FAIL;
620 }
621
622 static HRESULT WINAPI ISF_MyComputer_fnGetDefaultSearchGUID (IShellFolder2 * iface, GUID * pguid)
623 {
624     ICOM_THIS (IGenericSFImpl, iface);
625     FIXME ("(%p)\n", This);
626     return E_NOTIMPL;
627 }
628 static HRESULT WINAPI ISF_MyComputer_fnEnumSearches (IShellFolder2 * iface, IEnumExtraSearch ** ppenum)
629 {
630     ICOM_THIS (IGenericSFImpl, iface);
631     FIXME ("(%p)\n", This);
632     return E_NOTIMPL;
633 }
634 static HRESULT WINAPI ISF_MyComputer_fnGetDefaultColumn (IShellFolder2 * iface, DWORD dwRes, ULONG * pSort, ULONG * pDisplay)
635 {
636     ICOM_THIS (IGenericSFImpl, iface);
637
638     TRACE ("(%p)\n", This);
639
640     if (pSort) *pSort = 0;
641     if (pDisplay) *pDisplay = 0;
642     return S_OK;
643 }
644 static HRESULT WINAPI ISF_MyComputer_fnGetDefaultColumnState (IShellFolder2 * iface, UINT iColumn, DWORD * pcsFlags)
645 {
646     ICOM_THIS (IGenericSFImpl, iface);
647
648     TRACE ("(%p)\n", This);
649
650     if (!pcsFlags || iColumn >= MYCOMPUTERSHELLVIEWCOLUMNS) return E_INVALIDARG;
651     *pcsFlags = MyComputerSFHeader[iColumn].pcsFlags;
652     return S_OK;
653 }
654 static HRESULT WINAPI ISF_MyComputer_fnGetDetailsEx (IShellFolder2 * iface, LPCITEMIDLIST pidl, const SHCOLUMNID * pscid, VARIANT * pv)
655 {
656     ICOM_THIS (IGenericSFImpl, iface);
657     FIXME ("(%p)\n", This);
658     return E_NOTIMPL;
659 }
660
661 /* FIXME: drive size >4GB is rolling over */
662 static HRESULT WINAPI ISF_MyComputer_fnGetDetailsOf (IShellFolder2 * iface, LPCITEMIDLIST pidl, UINT iColumn, SHELLDETAILS * psd)
663 {
664     ICOM_THIS (IGenericSFImpl, iface);
665     HRESULT hr;
666
667     TRACE ("(%p)->(%p %i %p)\n", This, pidl, iColumn, psd);
668
669     if (!psd || iColumn >= MYCOMPUTERSHELLVIEWCOLUMNS)
670         return E_INVALIDARG;
671
672     if (!pidl) {
673         psd->fmt = MyComputerSFHeader[iColumn].fmt;
674         psd->cxChar = MyComputerSFHeader[iColumn].cxChar;
675         psd->str.uType = STRRET_CSTR;
676         LoadStringA (shell32_hInstance, MyComputerSFHeader[iColumn].colnameid, psd->str.u.cStr, MAX_PATH);
677         return S_OK;
678     } else {
679         char szPath[MAX_PATH];
680         ULARGE_INTEGER ulBytes;
681
682         psd->str.u.cStr[0] = 0x00;
683         psd->str.uType = STRRET_CSTR;
684         switch (iColumn) {
685         case 0:         /* name */
686             hr = IShellFolder_GetDisplayNameOf (iface, pidl, SHGDN_NORMAL | SHGDN_INFOLDER, &psd->str);
687             break;
688         case 1:         /* type */
689             _ILGetFileType (pidl, psd->str.u.cStr, MAX_PATH);
690             break;
691         case 2:         /* total size */
692             if (_ILIsDrive (pidl)) {
693                 _ILSimpleGetText (pidl, szPath, MAX_PATH);
694                 GetDiskFreeSpaceExA (szPath, NULL, &ulBytes, NULL);
695                 StrFormatByteSizeA (ulBytes.u.LowPart, psd->str.u.cStr, MAX_PATH);
696             }
697             break;
698         case 3:         /* free size */
699             if (_ILIsDrive (pidl)) {
700                 _ILSimpleGetText (pidl, szPath, MAX_PATH);
701                 GetDiskFreeSpaceExA (szPath, &ulBytes, NULL, NULL);
702                 StrFormatByteSizeA (ulBytes.u.LowPart, psd->str.u.cStr, MAX_PATH);
703             }
704             break;
705         }
706         hr = S_OK;
707     }
708
709     return hr;
710 }
711 static HRESULT WINAPI ISF_MyComputer_fnMapColumnToSCID (IShellFolder2 * iface, UINT column, SHCOLUMNID * pscid)
712 {
713     ICOM_THIS (IGenericSFImpl, iface);
714     FIXME ("(%p)\n", This);
715     return E_NOTIMPL;
716 }
717
718 static ICOM_VTABLE (IShellFolder2) vt_ShellFolder2 =
719 {
720         ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
721         ISF_MyComputer_fnQueryInterface,
722         ISF_MyComputer_fnAddRef,
723         ISF_MyComputer_fnRelease,
724         ISF_MyComputer_fnParseDisplayName,
725         ISF_MyComputer_fnEnumObjects,
726         ISF_MyComputer_fnBindToObject,
727         ISF_MyComputer_fnBindToStorage,
728         ISF_MyComputer_fnCompareIDs,
729         ISF_MyComputer_fnCreateViewObject,
730         ISF_MyComputer_fnGetAttributesOf,
731         ISF_MyComputer_fnGetUIObjectOf,
732         ISF_MyComputer_fnGetDisplayNameOf,
733         ISF_MyComputer_fnSetNameOf,
734         /* ShellFolder2 */
735         ISF_MyComputer_fnGetDefaultSearchGUID,
736         ISF_MyComputer_fnEnumSearches,
737         ISF_MyComputer_fnGetDefaultColumn,
738         ISF_MyComputer_fnGetDefaultColumnState,
739         ISF_MyComputer_fnGetDetailsEx,
740         ISF_MyComputer_fnGetDetailsOf,
741         ISF_MyComputer_fnMapColumnToSCID
742 };
743
744 /************************************************************************
745  *      IMCFldr_PersistFolder2_QueryInterface
746  */
747 static HRESULT WINAPI IMCFldr_PersistFolder2_QueryInterface (IPersistFolder2 * iface, REFIID iid, LPVOID * ppvObj)
748 {
749     _ICOM_THIS_From_IPersistFolder2 (IGenericSFImpl, iface);
750
751     TRACE ("(%p)\n", This);
752
753     return IUnknown_QueryInterface (_IUnknown_ (This), iid, ppvObj);
754 }
755
756 /************************************************************************
757  *      IMCFldr_PersistFolder2_AddRef
758  */
759 static ULONG WINAPI IMCFldr_PersistFolder2_AddRef (IPersistFolder2 * iface)
760 {
761     _ICOM_THIS_From_IPersistFolder2 (IGenericSFImpl, iface);
762
763     TRACE ("(%p)->(count=%lu)\n", This, This->ref);
764
765     return IUnknown_AddRef (_IUnknown_ (This));
766 }
767
768 /************************************************************************
769  *      ISFPersistFolder_Release
770  */
771 static ULONG WINAPI IMCFldr_PersistFolder2_Release (IPersistFolder2 * iface)
772 {
773     _ICOM_THIS_From_IPersistFolder2 (IGenericSFImpl, iface);
774
775     TRACE ("(%p)->(count=%lu)\n", This, This->ref);
776
777     return IUnknown_Release (_IUnknown_ (This));
778 }
779
780 /************************************************************************
781  *      IMCFldr_PersistFolder2_GetClassID
782  */
783 static HRESULT WINAPI IMCFldr_PersistFolder2_GetClassID (IPersistFolder2 * iface, CLSID * lpClassId)
784 {
785     _ICOM_THIS_From_IPersistFolder2 (IGenericSFImpl, iface);
786
787     TRACE ("(%p)\n", This);
788
789     if (!lpClassId)
790         return E_POINTER;
791     *lpClassId = CLSID_MyComputer;
792
793     return S_OK;
794 }
795
796 /************************************************************************
797  *      IMCFldr_PersistFolder2_Initialize
798  *
799  * NOTES: it makes no sense to change the pidl
800  */
801 static HRESULT WINAPI IMCFldr_PersistFolder2_Initialize (IPersistFolder2 * iface, LPCITEMIDLIST pidl)
802 {
803     _ICOM_THIS_From_IPersistFolder2 (IGenericSFImpl, iface);
804     TRACE ("(%p)->(%p)\n", This, pidl);
805     return E_NOTIMPL;
806 }
807
808 /**************************************************************************
809  *      IPersistFolder2_fnGetCurFolder
810  */
811 static HRESULT WINAPI IMCFldr_PersistFolder2_GetCurFolder (IPersistFolder2 * iface, LPITEMIDLIST * pidl)
812 {
813     _ICOM_THIS_From_IPersistFolder2 (IGenericSFImpl, iface);
814
815     TRACE ("(%p)->(%p)\n", This, pidl);
816
817     if (!pidl)
818         return E_POINTER;
819     *pidl = ILClone (This->pidlRoot);
820     return S_OK;
821 }
822
823 static ICOM_VTABLE (IPersistFolder2) vt_PersistFolder2 =
824 {
825 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
826         IMCFldr_PersistFolder2_QueryInterface,
827         IMCFldr_PersistFolder2_AddRef,
828         IMCFldr_PersistFolder2_Release,
829         IMCFldr_PersistFolder2_GetClassID,
830         IMCFldr_PersistFolder2_Initialize,
831         IMCFldr_PersistFolder2_GetCurFolder
832 };