StrRetToStrN returns BOOL and shouldn't crash on NULL dest.
[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
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     ICOM_VFIELD (IShellFolder2);
59     DWORD ref;
60       ICOM_VTABLE (IPersistFolder2) * 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     CHAR szTempA[MAX_PATH];
200     LPITEMIDLIST pidlTemp = NULL;
201     CLSID clsid;
202
203     TRACE ("(%p)->(HWND=%p,%p,%p=%s,%p,pidl=%p,%p)\n",
204            This, hwndOwner, pbc, lpszDisplayName, debugstr_w (lpszDisplayName), pchEaten, ppidl, pdwAttributes);
205
206     *ppidl = 0;
207     if (pchEaten)
208         *pchEaten = 0;          /* strange but like the original */
209
210     /* handle CLSID paths */
211     if (lpszDisplayName[0] == ':' && lpszDisplayName[1] == ':') {
212         szNext = GetNextElementW (lpszDisplayName, szElement, MAX_PATH);
213         TRACE ("-- element: %s\n", debugstr_w (szElement));
214         SHCLSIDFromStringW (szElement + 2, &clsid);
215         pidlTemp = _ILCreate (PT_MYCOMP, &clsid, sizeof (clsid));
216     }
217     /* do we have an absolute path name ? */
218     else if (PathGetDriveNumberW (lpszDisplayName) >= 0 && lpszDisplayName[2] == (WCHAR) '\\') {
219         szNext = GetNextElementW (lpszDisplayName, szElement, MAX_PATH);
220         WideCharToMultiByte (CP_ACP, 0, szElement, -1, szTempA, MAX_PATH, NULL, NULL);
221         pidlTemp = _ILCreateDrive (szTempA);
222     }
223
224     if (szNext && *szNext) {
225         hr = SHELL32_ParseNextElement (iface, hwndOwner, pbc, &pidlTemp, (LPOLESTR) szNext, pchEaten, pdwAttributes);
226     } else {
227         if (pdwAttributes && *pdwAttributes) {
228             SHELL32_GetItemAttributes (_IShellFolder_ (This), pidlTemp, pdwAttributes);
229         }
230         hr = S_OK;
231     }
232
233     *ppidl = pidlTemp;
234
235     TRACE ("(%p)->(-- ret=0x%08lx)\n", This, hr);
236
237     return hr;
238 }
239
240 /**************************************************************************
241 *               ISF_MyComputer_fnEnumObjects
242 */
243 static HRESULT WINAPI
244 ISF_MyComputer_fnEnumObjects (IShellFolder2 * iface, HWND hwndOwner, DWORD dwFlags, LPENUMIDLIST * ppEnumIDList)
245 {
246     ICOM_THIS (IGenericSFImpl, iface);
247
248     TRACE ("(%p)->(HWND=%p flags=0x%08lx pplist=%p)\n", This, hwndOwner, dwFlags, ppEnumIDList);
249
250     *ppEnumIDList = IEnumIDList_Constructor (NULL, dwFlags, EIDL_MYCOMP);
251
252     TRACE ("-- (%p)->(new ID List: %p)\n", This, *ppEnumIDList);
253
254     return (*ppEnumIDList) ? S_OK : E_OUTOFMEMORY;
255 }
256
257 /**************************************************************************
258 *               ISF_MyComputer_fnBindToObject
259 */
260 static HRESULT WINAPI
261 ISF_MyComputer_fnBindToObject (IShellFolder2 * iface, LPCITEMIDLIST pidl,
262                                LPBC pbcReserved, REFIID riid, LPVOID * ppvOut)
263 {
264     ICOM_THIS (IGenericSFImpl, iface);
265
266     TRACE ("(%p)->(pidl=%p,%p,%s,%p)\n", This, pidl, pbcReserved, shdebugstr_guid (riid), ppvOut);
267
268     return SHELL32_BindToChild (This->pidlRoot, NULL, pidl, riid, ppvOut);
269 }
270
271 /**************************************************************************
272 *       ISF_MyComputer_fnBindToStorage
273 */
274 static HRESULT WINAPI
275 ISF_MyComputer_fnBindToStorage (IShellFolder2 * iface,
276                                 LPCITEMIDLIST pidl, LPBC pbcReserved, REFIID riid, LPVOID * ppvOut)
277 {
278     ICOM_THIS (IGenericSFImpl, iface);
279
280     FIXME ("(%p)->(pidl=%p,%p,%s,%p) stub\n", This, pidl, pbcReserved, shdebugstr_guid (riid), ppvOut);
281
282     *ppvOut = NULL;
283     return E_NOTIMPL;
284 }
285
286 /**************************************************************************
287 *       ISF_MyComputer_fnCompareIDs
288 */
289
290 static HRESULT WINAPI
291 ISF_MyComputer_fnCompareIDs (IShellFolder2 * iface, LPARAM lParam, LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
292 {
293     ICOM_THIS (IGenericSFImpl, iface);
294
295     int nReturn;
296
297     TRACE ("(%p)->(0x%08lx,pidl1=%p,pidl2=%p)\n", This, lParam, pidl1, pidl2);
298     nReturn = SHELL32_CompareIDs (_IShellFolder_ (This), lParam, pidl1, pidl2);
299     TRACE ("-- %i\n", nReturn);
300     return nReturn;
301 }
302
303 /**************************************************************************
304 *       ISF_MyComputer_fnCreateViewObject
305 */
306 static HRESULT WINAPI
307 ISF_MyComputer_fnCreateViewObject (IShellFolder2 * iface, HWND hwndOwner, REFIID riid, LPVOID * ppvOut)
308 {
309     ICOM_THIS (IGenericSFImpl, iface);
310
311     LPSHELLVIEW pShellView;
312     HRESULT hr = E_INVALIDARG;
313
314     TRACE ("(%p)->(hwnd=%p,%s,%p)\n", This, hwndOwner, shdebugstr_guid (riid), ppvOut);
315
316     if (ppvOut) {
317         *ppvOut = NULL;
318
319         if (IsEqualIID (riid, &IID_IDropTarget)) {
320             WARN ("IDropTarget not implemented\n");
321             hr = E_NOTIMPL;
322         } else if (IsEqualIID (riid, &IID_IContextMenu)) {
323             WARN ("IContextMenu not implemented\n");
324             hr = E_NOTIMPL;
325         } else if (IsEqualIID (riid, &IID_IShellView)) {
326             pShellView = IShellView_Constructor ((IShellFolder *) iface);
327             if (pShellView) {
328                 hr = IShellView_QueryInterface (pShellView, riid, ppvOut);
329                 IShellView_Release (pShellView);
330             }
331         }
332     }
333     TRACE ("-- (%p)->(interface=%p)\n", This, ppvOut);
334     return hr;
335 }
336
337 /**************************************************************************
338 *  ISF_MyComputer_fnGetAttributesOf
339 */
340 static HRESULT WINAPI
341 ISF_MyComputer_fnGetAttributesOf (IShellFolder2 * iface, UINT cidl, LPCITEMIDLIST * apidl, DWORD * rgfInOut)
342 {
343     ICOM_THIS (IGenericSFImpl, iface);
344
345     HRESULT hr = S_OK;
346
347     TRACE ("(%p)->(cidl=%d apidl=%p mask=0x%08lx)\n", This, cidl, apidl, *rgfInOut);
348
349     if ((!cidl) || (!apidl) || (!rgfInOut))
350         return E_INVALIDARG;
351
352     while (cidl > 0 && *apidl) {
353         pdump (*apidl);
354         SHELL32_GetItemAttributes (_IShellFolder_ (This), *apidl, rgfInOut);
355         apidl++;
356         cidl--;
357     }
358
359     TRACE ("-- result=0x%08lx\n", *rgfInOut);
360     return hr;
361 }
362
363 /**************************************************************************
364 *       ISF_MyComputer_fnGetUIObjectOf
365 *
366 * PARAMETERS
367 *  HWND           hwndOwner, //[in ] Parent window for any output
368 *  UINT           cidl,      //[in ] array size
369 *  LPCITEMIDLIST* apidl,     //[in ] simple pidl array
370 *  REFIID         riid,      //[in ] Requested Interface
371 *  UINT*          prgfInOut, //[   ] reserved
372 *  LPVOID*        ppvObject) //[out] Resulting Interface
373 *
374 */
375 static HRESULT WINAPI
376 ISF_MyComputer_fnGetUIObjectOf (IShellFolder2 * iface,
377                                 HWND hwndOwner,
378                                 UINT cidl, LPCITEMIDLIST * apidl, REFIID riid, UINT * prgfInOut, LPVOID * ppvOut)
379 {
380     ICOM_THIS (IGenericSFImpl, iface);
381
382     LPITEMIDLIST pidl;
383     IUnknown *pObj = NULL;
384     HRESULT hr = E_INVALIDARG;
385
386     TRACE ("(%p)->(%p,%u,apidl=%p,%s,%p,%p)\n",
387            This, hwndOwner, cidl, apidl, shdebugstr_guid (riid), prgfInOut, ppvOut);
388
389     if (ppvOut) {
390         *ppvOut = NULL;
391
392         if (IsEqualIID (riid, &IID_IContextMenu) && (cidl >= 1)) {
393             pObj = (LPUNKNOWN) ISvItemCm_Constructor ((IShellFolder *) iface, This->pidlRoot, apidl, cidl);
394             hr = S_OK;
395         } else if (IsEqualIID (riid, &IID_IDataObject) && (cidl >= 1)) {
396             pObj = (LPUNKNOWN) IDataObject_Constructor (hwndOwner, This->pidlRoot, apidl, cidl);
397             hr = S_OK;
398         } else if (IsEqualIID (riid, &IID_IExtractIconA) && (cidl == 1)) {
399             pidl = ILCombine (This->pidlRoot, apidl[0]);
400             pObj = (LPUNKNOWN) IExtractIconA_Constructor (pidl);
401             SHFree (pidl);
402             hr = S_OK;
403         } else if (IsEqualIID (riid, &IID_IExtractIconW) && (cidl == 1)) {
404             pidl = ILCombine (This->pidlRoot, apidl[0]);
405             pObj = (LPUNKNOWN) IExtractIconW_Constructor (pidl);
406             SHFree (pidl);
407             hr = S_OK;
408         } else if (IsEqualIID (riid, &IID_IDropTarget) && (cidl >= 1)) {
409             hr = IShellFolder_QueryInterface (iface, &IID_IDropTarget, (LPVOID *) & pObj);
410         } else if ((IsEqualIID(riid,&IID_IShellLinkW) || IsEqualIID(riid,&IID_IShellLinkA))
411                                 && (cidl == 1)) {
412             pidl = ILCombine (This->pidlRoot, apidl[0]);
413             hr = IShellLink_ConstructFromFile(NULL, riid, pidl, (LPVOID*)&pObj);
414             SHFree (pidl);
415         } else {
416             hr = E_NOINTERFACE;
417         }
418
419         if (SUCCEEDED(hr) && !pObj)
420             hr = E_OUTOFMEMORY;
421
422         *ppvOut = pObj;
423     }
424     TRACE ("(%p)->hr=0x%08lx\n", This, hr);
425     return hr;
426 }
427
428 /**************************************************************************
429 *       ISF_MyComputer_fnGetDisplayNameOf
430 */
431 static HRESULT WINAPI ISF_MyComputer_fnGetDisplayNameOf (IShellFolder2 * iface, LPCITEMIDLIST pidl, DWORD dwFlags, LPSTRRET strRet)
432 {
433     ICOM_THIS (IGenericSFImpl, iface);
434
435     char szPath[MAX_PATH],
436       szDrive[18];
437     int len = 0;
438     BOOL bSimplePidl;
439     HRESULT hr = S_OK;
440
441     TRACE ("(%p)->(pidl=%p,0x%08lx,%p)\n", This, pidl, dwFlags, strRet);
442     pdump (pidl);
443
444     if (!strRet)
445         return E_INVALIDARG;
446
447     szPath[0] = 0x00;
448     szDrive[0] = 0x00;
449
450     bSimplePidl = _ILIsPidlSimple (pidl);
451
452     if (!pidl->mkid.cb) {
453         /* parsing name like ::{...} */
454         lstrcpyA (szPath, "::");
455         SHELL32_GUIDToStringA(&CLSID_MyComputer, &szPath[2]);
456     } else if (_ILIsSpecialFolder (pidl)) {
457         /* take names of special folders only if its only this folder */
458         if (bSimplePidl) {
459             GUID const *clsid;
460
461             if ((clsid = _ILGetGUIDPointer (pidl))) {
462                 if (GET_SHGDN_FOR (dwFlags) == SHGDN_FORPARSING) {
463                     int bWantsForParsing;
464
465                     /*
466                      * we can only get a filesystem path from a shellfolder if the value WantsFORPARSING in
467                      * CLSID\\{...}\\shellfolder exists
468                      * exception: the MyComputer folder has this keys not but like any filesystem backed
469                      *            folder it needs these behaviour
470                      */
471                     /* get the "WantsFORPARSING" flag from the registry */
472                     char szRegPath[100];
473
474                     lstrcpyA (szRegPath, "CLSID\\");
475                     SHELL32_GUIDToStringA (clsid, &szRegPath[6]);
476                     lstrcatA (szRegPath, "\\shellfolder");
477                     bWantsForParsing =
478                         (ERROR_SUCCESS ==
479                          SHGetValueA (HKEY_CLASSES_ROOT, szRegPath, "WantsFORPARSING", NULL, NULL, NULL));
480
481                     if ((GET_SHGDN_RELATION (dwFlags) == SHGDN_NORMAL) && bWantsForParsing) {
482                         /* we need the filesystem path to the destination folder. Only the folder itself can know it */
483                         hr = SHELL32_GetDisplayNameOfChild (iface, pidl, dwFlags, szPath, MAX_PATH);
484                     } else {
485                         LPSTR p;
486
487                         /* parsing name like ::{...} */
488                         p = lstrcpyA(szPath, "::") + 2;
489                         p += SHELL32_GUIDToStringA(&CLSID_MyComputer, p);
490
491                         lstrcatA(p, "\\::");
492                         p += 3;
493                         SHELL32_GUIDToStringA(clsid, p);
494                     }
495                 } else {
496                     /* user friendly name */
497                     HCR_GetClassNameA (clsid, szPath, MAX_PATH);
498                 }
499             } else
500                 _ILSimpleGetText (pidl, szPath, MAX_PATH);      /* append my own path */
501         } else {
502             FIXME ("special folder\n");
503         }
504     } else {
505         if (!_ILIsDrive (pidl)) {
506             ERR ("Wrong pidl type\n");
507             return E_INVALIDARG;
508         }
509
510         _ILSimpleGetText (pidl, szPath, MAX_PATH);      /* append my own path */
511
512         /* long view "lw_name (C:)" */
513         if (bSimplePidl && !(dwFlags & SHGDN_FORPARSING)) {
514             DWORD dwVolumeSerialNumber,
515               dwMaximumComponetLength,
516               dwFileSystemFlags;
517
518             GetVolumeInformationA (szPath, szDrive, sizeof (szDrive) - 6, &dwVolumeSerialNumber,
519                                    &dwMaximumComponetLength, &dwFileSystemFlags, NULL, 0);
520             strcat (szDrive, " (");
521             strncat (szDrive, szPath, 2);
522             strcat (szDrive, ")");
523             strcpy (szPath, szDrive);
524         }
525     }
526
527     if (!bSimplePidl) {         /* go deeper if needed */
528         PathAddBackslashA (szPath);
529         len = strlen (szPath);
530
531         hr = SHELL32_GetDisplayNameOfChild (iface, pidl, dwFlags | SHGDN_INFOLDER, szPath + len, MAX_PATH - len);
532     }
533
534     if (SUCCEEDED (hr)) {
535         strRet->uType = STRRET_CSTR;
536         lstrcpynA (strRet->u.cStr, szPath, MAX_PATH);
537     }
538
539     TRACE ("-- (%p)->(%s)\n", This, szPath);
540     return hr;
541 }
542
543 /**************************************************************************
544 *  ISF_MyComputer_fnSetNameOf
545 *  Changes the name of a file object or subfolder, possibly changing its item
546 *  identifier in the process.
547 *
548 * PARAMETERS
549 *  HWND          hwndOwner,  //[in ] Owner window for output
550 *  LPCITEMIDLIST pidl,       //[in ] simple pidl of item to change
551 *  LPCOLESTR     lpszName,   //[in ] the items new display name
552 *  DWORD         dwFlags,    //[in ] SHGNO formatting flags
553 *  LPITEMIDLIST* ppidlOut)   //[out] simple pidl returned
554 */
555 static HRESULT WINAPI ISF_MyComputer_fnSetNameOf (IShellFolder2 * iface, HWND hwndOwner, LPCITEMIDLIST pidl,    /*simple pidl */
556                                                   LPCOLESTR lpName, DWORD dwFlags, LPITEMIDLIST * pPidlOut)
557 {
558     ICOM_THIS (IGenericSFImpl, iface);
559     FIXME ("(%p)->(%p,pidl=%p,%s,%lu,%p)\n", This, hwndOwner, pidl, debugstr_w (lpName), dwFlags, pPidlOut);
560     return E_FAIL;
561 }
562
563 static HRESULT WINAPI ISF_MyComputer_fnGetDefaultSearchGUID (IShellFolder2 * iface, GUID * pguid)
564 {
565     ICOM_THIS (IGenericSFImpl, iface);
566     FIXME ("(%p)\n", This);
567     return E_NOTIMPL;
568 }
569 static HRESULT WINAPI ISF_MyComputer_fnEnumSearches (IShellFolder2 * iface, IEnumExtraSearch ** ppenum)
570 {
571     ICOM_THIS (IGenericSFImpl, iface);
572     FIXME ("(%p)\n", This);
573     return E_NOTIMPL;
574 }
575 static HRESULT WINAPI ISF_MyComputer_fnGetDefaultColumn (IShellFolder2 * iface, DWORD dwRes, ULONG * pSort, ULONG * pDisplay)
576 {
577     ICOM_THIS (IGenericSFImpl, iface);
578
579     TRACE ("(%p)\n", This);
580
581     if (pSort) *pSort = 0;
582     if (pDisplay) *pDisplay = 0;
583     return S_OK;
584 }
585 static HRESULT WINAPI ISF_MyComputer_fnGetDefaultColumnState (IShellFolder2 * iface, UINT iColumn, DWORD * pcsFlags)
586 {
587     ICOM_THIS (IGenericSFImpl, iface);
588
589     TRACE ("(%p)\n", This);
590
591     if (!pcsFlags || iColumn >= MYCOMPUTERSHELLVIEWCOLUMNS) return E_INVALIDARG;
592     *pcsFlags = MyComputerSFHeader[iColumn].pcsFlags;
593     return S_OK;
594 }
595 static HRESULT WINAPI ISF_MyComputer_fnGetDetailsEx (IShellFolder2 * iface, LPCITEMIDLIST pidl, const SHCOLUMNID * pscid, VARIANT * pv)
596 {
597     ICOM_THIS (IGenericSFImpl, iface);
598     FIXME ("(%p)\n", This);
599     return E_NOTIMPL;
600 }
601
602 /* FIXME: drive size >4GB is rolling over */
603 static HRESULT WINAPI ISF_MyComputer_fnGetDetailsOf (IShellFolder2 * iface, LPCITEMIDLIST pidl, UINT iColumn, SHELLDETAILS * psd)
604 {
605     ICOM_THIS (IGenericSFImpl, iface);
606     HRESULT hr;
607
608     TRACE ("(%p)->(%p %i %p)\n", This, pidl, iColumn, psd);
609
610     if (!psd || iColumn >= MYCOMPUTERSHELLVIEWCOLUMNS)
611         return E_INVALIDARG;
612
613     if (!pidl) {
614         psd->fmt = MyComputerSFHeader[iColumn].fmt;
615         psd->cxChar = MyComputerSFHeader[iColumn].cxChar;
616         psd->str.uType = STRRET_CSTR;
617         LoadStringA (shell32_hInstance, MyComputerSFHeader[iColumn].colnameid, psd->str.u.cStr, MAX_PATH);
618         return S_OK;
619     } else {
620         char szPath[MAX_PATH];
621         ULARGE_INTEGER ulBytes;
622
623         psd->str.u.cStr[0] = 0x00;
624         psd->str.uType = STRRET_CSTR;
625         switch (iColumn) {
626         case 0:         /* name */
627             hr = IShellFolder_GetDisplayNameOf (iface, pidl, SHGDN_NORMAL | SHGDN_INFOLDER, &psd->str);
628             break;
629         case 1:         /* type */
630             _ILGetFileType (pidl, psd->str.u.cStr, MAX_PATH);
631             break;
632         case 2:         /* total size */
633             if (_ILIsDrive (pidl)) {
634                 _ILSimpleGetText (pidl, szPath, MAX_PATH);
635                 GetDiskFreeSpaceExA (szPath, NULL, &ulBytes, NULL);
636                 StrFormatByteSizeA (ulBytes.u.LowPart, psd->str.u.cStr, MAX_PATH);
637             }
638             break;
639         case 3:         /* free size */
640             if (_ILIsDrive (pidl)) {
641                 _ILSimpleGetText (pidl, szPath, MAX_PATH);
642                 GetDiskFreeSpaceExA (szPath, &ulBytes, NULL, NULL);
643                 StrFormatByteSizeA (ulBytes.u.LowPart, psd->str.u.cStr, MAX_PATH);
644             }
645             break;
646         }
647         hr = S_OK;
648     }
649
650     return hr;
651 }
652 static HRESULT WINAPI ISF_MyComputer_fnMapColumnToSCID (IShellFolder2 * iface, UINT column, SHCOLUMNID * pscid)
653 {
654     ICOM_THIS (IGenericSFImpl, iface);
655     FIXME ("(%p)\n", This);
656     return E_NOTIMPL;
657 }
658
659 static ICOM_VTABLE (IShellFolder2) vt_ShellFolder2 =
660 {
661         ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
662         ISF_MyComputer_fnQueryInterface,
663         ISF_MyComputer_fnAddRef,
664         ISF_MyComputer_fnRelease,
665         ISF_MyComputer_fnParseDisplayName,
666         ISF_MyComputer_fnEnumObjects,
667         ISF_MyComputer_fnBindToObject,
668         ISF_MyComputer_fnBindToStorage,
669         ISF_MyComputer_fnCompareIDs,
670         ISF_MyComputer_fnCreateViewObject,
671         ISF_MyComputer_fnGetAttributesOf,
672         ISF_MyComputer_fnGetUIObjectOf,
673         ISF_MyComputer_fnGetDisplayNameOf,
674         ISF_MyComputer_fnSetNameOf,
675         /* ShellFolder2 */
676         ISF_MyComputer_fnGetDefaultSearchGUID,
677         ISF_MyComputer_fnEnumSearches,
678         ISF_MyComputer_fnGetDefaultColumn,
679         ISF_MyComputer_fnGetDefaultColumnState,
680         ISF_MyComputer_fnGetDetailsEx,
681         ISF_MyComputer_fnGetDetailsOf,
682         ISF_MyComputer_fnMapColumnToSCID
683 };
684
685 /************************************************************************
686  *      IMCFldr_PersistFolder2_QueryInterface
687  */
688 static HRESULT WINAPI IMCFldr_PersistFolder2_QueryInterface (IPersistFolder2 * iface, REFIID iid, LPVOID * ppvObj)
689 {
690     _ICOM_THIS_From_IPersistFolder2 (IGenericSFImpl, iface);
691
692     TRACE ("(%p)\n", This);
693
694     return IUnknown_QueryInterface (_IUnknown_ (This), iid, ppvObj);
695 }
696
697 /************************************************************************
698  *      IMCFldr_PersistFolder2_AddRef
699  */
700 static ULONG WINAPI IMCFldr_PersistFolder2_AddRef (IPersistFolder2 * iface)
701 {
702     _ICOM_THIS_From_IPersistFolder2 (IGenericSFImpl, iface);
703
704     TRACE ("(%p)->(count=%lu)\n", This, This->ref);
705
706     return IUnknown_AddRef (_IUnknown_ (This));
707 }
708
709 /************************************************************************
710  *      ISFPersistFolder_Release
711  */
712 static ULONG WINAPI IMCFldr_PersistFolder2_Release (IPersistFolder2 * iface)
713 {
714     _ICOM_THIS_From_IPersistFolder2 (IGenericSFImpl, iface);
715
716     TRACE ("(%p)->(count=%lu)\n", This, This->ref);
717
718     return IUnknown_Release (_IUnknown_ (This));
719 }
720
721 /************************************************************************
722  *      IMCFldr_PersistFolder2_GetClassID
723  */
724 static HRESULT WINAPI IMCFldr_PersistFolder2_GetClassID (IPersistFolder2 * iface, CLSID * lpClassId)
725 {
726     _ICOM_THIS_From_IPersistFolder2 (IGenericSFImpl, iface);
727
728     TRACE ("(%p)\n", This);
729
730     if (!lpClassId)
731         return E_POINTER;
732     *lpClassId = CLSID_MyComputer;
733
734     return S_OK;
735 }
736
737 /************************************************************************
738  *      IMCFldr_PersistFolder2_Initialize
739  *
740  * NOTES: it makes no sense to change the pidl
741  */
742 static HRESULT WINAPI IMCFldr_PersistFolder2_Initialize (IPersistFolder2 * iface, LPCITEMIDLIST pidl)
743 {
744     _ICOM_THIS_From_IPersistFolder2 (IGenericSFImpl, iface);
745     TRACE ("(%p)->(%p)\n", This, pidl);
746     return E_NOTIMPL;
747 }
748
749 /**************************************************************************
750  *      IPersistFolder2_fnGetCurFolder
751  */
752 static HRESULT WINAPI IMCFldr_PersistFolder2_GetCurFolder (IPersistFolder2 * iface, LPITEMIDLIST * pidl)
753 {
754     _ICOM_THIS_From_IPersistFolder2 (IGenericSFImpl, iface);
755
756     TRACE ("(%p)->(%p)\n", This, pidl);
757
758     if (!pidl)
759         return E_POINTER;
760     *pidl = ILClone (This->pidlRoot);
761     return S_OK;
762 }
763
764 static ICOM_VTABLE (IPersistFolder2) vt_PersistFolder2 =
765 {
766 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
767         IMCFldr_PersistFolder2_QueryInterface,
768         IMCFldr_PersistFolder2_AddRef,
769         IMCFldr_PersistFolder2_Release,
770         IMCFldr_PersistFolder2_GetClassID,
771         IMCFldr_PersistFolder2_Initialize,
772         IMCFldr_PersistFolder2_GetCurFolder
773 };