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