Avoid accessing the htask16 TEB field from ntdll.
[wine/dcerpc.git] / dlls / shell32 / shfldr_mycomp.c
blobc7856a6e6d48d1d9923e0cd036daf18d3a35d6a1
1 /*
2 * Virtual Workplace folder
4 * Copyright 1997 Marcus Meissner
5 * Copyright 1998, 1999, 2002 Juergen Schmied
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.
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.
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
22 #include "config.h"
23 #include "wine/port.h"
25 #include <stdlib.h>
26 #include <string.h>
27 #include <stdarg.h>
28 #include <stdio.h>
30 #define COBJMACROS
31 #define NONAMELESSUNION
32 #define NONAMELESSSTRUCT
34 #include "winerror.h"
35 #include "windef.h"
36 #include "winbase.h"
37 #include "winreg.h"
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"
51 WINE_DEFAULT_DEBUG_CHANNEL (shell);
53 /***********************************************************************
54 * IShellFolder implementation
57 typedef struct {
58 IShellFolder2Vtbl *lpVtbl;
59 DWORD ref;
60 IPersistFolder2Vtbl *lpVtblPersistFolder2;
62 /* both paths are parsible from the desktop */
63 LPITEMIDLIST pidlRoot; /* absolute pidl */
64 } IGenericSFImpl;
66 static struct IShellFolder2Vtbl vt_ShellFolder2;
67 static struct IPersistFolder2Vtbl vt_PersistFolder2;
69 #define _IPersistFolder2_Offset ((int)(&(((IGenericSFImpl*)0)->lpVtblPersistFolder2)))
70 #define _ICOM_THIS_From_IPersistFolder2(class, name) class* This = (class*)(((char*)name)-_IPersistFolder2_Offset);
73 converts This to an interface pointer
75 #define _IUnknown_(This) (IUnknown*)&(This->lpVtbl)
76 #define _IShellFolder_(This) (IShellFolder*)&(This->lpVtbl)
77 #define _IShellFolder2_(This) (IShellFolder2*)&(This->lpVtbl)
79 #define _IPersist_(This) (IPersist*)&(This->lpVtblPersistFolder2)
80 #define _IPersistFolder_(This) (IPersistFolder*)&(This->lpVtblPersistFolder2)
81 #define _IPersistFolder2_(This) (IPersistFolder2*)&(This->lpVtblPersistFolder2)
83 /***********************************************************************
84 * IShellFolder [MyComputer] implementation
87 static shvheader MyComputerSFHeader[] = {
88 {IDS_SHV_COLUMN1, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 15},
89 {IDS_SHV_COLUMN3, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
90 {IDS_SHV_COLUMN6, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
91 {IDS_SHV_COLUMN7, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
94 #define MYCOMPUTERSHELLVIEWCOLUMNS 4
96 /**************************************************************************
97 * ISF_MyComputer_Constructor
99 HRESULT WINAPI ISF_MyComputer_Constructor (IUnknown * pUnkOuter, REFIID riid, LPVOID * ppv)
101 IGenericSFImpl *sf;
103 TRACE ("unkOut=%p %s\n", pUnkOuter, shdebugstr_guid (riid));
105 if (!ppv)
106 return E_POINTER;
107 if (pUnkOuter)
108 return CLASS_E_NOAGGREGATION;
110 sf = LocalAlloc (LMEM_ZEROINIT, sizeof (IGenericSFImpl));
111 if (!sf)
112 return E_OUTOFMEMORY;
114 sf->ref = 0;
115 sf->lpVtbl = &vt_ShellFolder2;
116 sf->lpVtblPersistFolder2 = &vt_PersistFolder2;
117 sf->pidlRoot = _ILCreateMyComputer (); /* my qualified pidl */
119 if (!SUCCEEDED (IUnknown_QueryInterface (_IUnknown_ (sf), riid, ppv)))
121 IUnknown_Release (_IUnknown_ (sf));
122 return E_NOINTERFACE;
125 TRACE ("--(%p)\n", sf);
126 return S_OK;
129 /**************************************************************************
130 * ISF_MyComputer_fnQueryInterface
132 * NOTES supports not IPersist/IPersistFolder
134 static HRESULT WINAPI ISF_MyComputer_fnQueryInterface (IShellFolder2 *iface,
135 REFIID riid, LPVOID *ppvObj)
137 IGenericSFImpl *This = (IGenericSFImpl *)iface;
139 TRACE ("(%p)->(%s,%p)\n", This, shdebugstr_guid (riid), ppvObj);
141 *ppvObj = NULL;
143 if (IsEqualIID (riid, &IID_IUnknown) ||
144 IsEqualIID (riid, &IID_IShellFolder) ||
145 IsEqualIID (riid, &IID_IShellFolder2))
147 *ppvObj = This;
149 else if (IsEqualIID (riid, &IID_IPersist) ||
150 IsEqualIID (riid, &IID_IPersistFolder) ||
151 IsEqualIID (riid, &IID_IPersistFolder2))
153 *ppvObj = _IPersistFolder2_ (This);
156 if (*ppvObj)
158 IUnknown_AddRef ((IUnknown *) (*ppvObj));
159 TRACE ("-- Interface: (%p)->(%p)\n", ppvObj, *ppvObj);
160 return S_OK;
162 TRACE ("-- Interface: E_NOINTERFACE\n");
163 return E_NOINTERFACE;
166 static ULONG WINAPI ISF_MyComputer_fnAddRef (IShellFolder2 * iface)
168 IGenericSFImpl *This = (IGenericSFImpl *)iface;
169 ULONG refCount = InterlockedIncrement(&This->ref);
171 TRACE ("(%p)->(count=%lu)\n", This, refCount - 1);
173 return refCount;
176 static ULONG WINAPI ISF_MyComputer_fnRelease (IShellFolder2 * iface)
178 IGenericSFImpl *This = (IGenericSFImpl *)iface;
179 ULONG refCount = InterlockedDecrement(&This->ref);
181 TRACE ("(%p)->(count=%lu)\n", This, refCount + 1);
183 if (!refCount)
185 TRACE ("-- destroying IShellFolder(%p)\n", This);
186 if (This->pidlRoot)
187 SHFree (This->pidlRoot);
188 LocalFree ((HLOCAL) This);
190 return refCount;
193 /**************************************************************************
194 * ISF_MyComputer_fnParseDisplayName
196 static HRESULT WINAPI ISF_MyComputer_fnParseDisplayName (IShellFolder2 *iface,
197 HWND hwndOwner, LPBC pbc, LPOLESTR lpszDisplayName,
198 DWORD * pchEaten, LPITEMIDLIST * ppidl, DWORD * pdwAttributes)
200 IGenericSFImpl *This = (IGenericSFImpl *)iface;
201 HRESULT hr = E_INVALIDARG;
202 LPCWSTR szNext = NULL;
203 WCHAR szElement[MAX_PATH];
204 LPITEMIDLIST pidlTemp = NULL;
205 CLSID clsid;
207 TRACE("(%p)->(HWND=%p,%p,%p=%s,%p,pidl=%p,%p)\n", This,
208 hwndOwner, pbc, lpszDisplayName, debugstr_w (lpszDisplayName),
209 pchEaten, ppidl, pdwAttributes);
211 *ppidl = 0;
212 if (pchEaten)
213 *pchEaten = 0; /* strange but like the original */
215 /* handle CLSID paths */
216 if (lpszDisplayName[0] == ':' && lpszDisplayName[1] == ':')
218 szNext = GetNextElementW (lpszDisplayName, szElement, MAX_PATH);
219 TRACE ("-- element: %s\n", debugstr_w (szElement));
220 SHCLSIDFromStringW (szElement + 2, &clsid);
221 pidlTemp = _ILCreateGuid (PT_GUID, &clsid);
223 /* do we have an absolute path name ? */
224 else if (PathGetDriveNumberW (lpszDisplayName) >= 0 &&
225 lpszDisplayName[2] == (WCHAR) '\\')
227 szNext = GetNextElementW (lpszDisplayName, szElement, MAX_PATH);
228 /* make drive letter uppercase to enable PIDL comparison */
229 szElement[0] = toupper(szElement[0]);
230 pidlTemp = _ILCreateDrive (szElement);
233 if (szNext && *szNext)
235 hr = SHELL32_ParseNextElement (iface, hwndOwner, pbc, &pidlTemp,
236 (LPOLESTR) szNext, pchEaten, pdwAttributes);
238 else
240 if (pdwAttributes && *pdwAttributes)
241 SHELL32_GetItemAttributes (_IShellFolder_ (This),
242 pidlTemp, pdwAttributes);
243 hr = S_OK;
246 *ppidl = pidlTemp;
248 TRACE ("(%p)->(-- ret=0x%08lx)\n", This, hr);
250 return hr;
253 /**************************************************************************
254 * CreateMyCompEnumList()
256 static const WCHAR MyComputer_NameSpaceW[] = { 'S','O','F','T','W','A','R','E',
257 '\\','M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
258 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\','E','x','p','l',
259 'o','r','e','r','\\','M','y','C','o','m','p','u','t','e','r','\\','N','a','m',
260 'e','s','p','a','c','e','\0' };
262 static BOOL CreateMyCompEnumList(IEnumIDList *list, DWORD dwFlags)
264 BOOL ret = TRUE;
266 TRACE("(%p)->(flags=0x%08lx) \n",list,dwFlags);
268 /* enumerate the folders */
269 if (dwFlags & SHCONTF_FOLDERS)
271 WCHAR wszDriveName[] = {'A', ':', '\\', '\0'};
272 DWORD dwDrivemap = GetLogicalDrives();
273 HKEY hkey;
275 while (ret && wszDriveName[0]<='Z')
277 if(dwDrivemap & 0x00000001L)
278 ret = AddToEnumList(list, _ILCreateDrive(wszDriveName));
279 wszDriveName[0]++;
280 dwDrivemap = dwDrivemap >> 1;
283 TRACE("-- (%p)-> enumerate (mycomputer shell extensions)\n",list);
284 if (ret && !RegOpenKeyExW(HKEY_LOCAL_MACHINE, MyComputer_NameSpaceW,
285 0, KEY_READ, &hkey))
287 WCHAR iid[50];
288 int i=0;
290 while (ret)
292 DWORD size;
293 LONG r;
295 size = sizeof(iid) / sizeof(iid[0]);
296 r = RegEnumKeyExW(hkey, i, iid, &size, 0, NULL, NULL, NULL);
297 if (ERROR_SUCCESS == r)
299 /* FIXME: shell extensions, shouldn't the type be
300 * PT_SHELLEXT? */
301 ret = AddToEnumList(list, _ILCreateGuidFromStrW(iid));
302 i++;
304 else if (ERROR_NO_MORE_ITEMS == r)
305 break;
306 else
307 ret = FALSE;
309 RegCloseKey(hkey);
312 return ret;
315 /**************************************************************************
316 * ISF_MyComputer_fnEnumObjects
318 static HRESULT WINAPI ISF_MyComputer_fnEnumObjects (IShellFolder2 *iface,
319 HWND hwndOwner, DWORD dwFlags, LPENUMIDLIST *ppEnumIDList)
321 IGenericSFImpl *This = (IGenericSFImpl *)iface;
323 TRACE("(%p)->(HWND=%p flags=0x%08lx pplist=%p)\n", This,
324 hwndOwner, dwFlags, ppEnumIDList);
326 *ppEnumIDList = IEnumIDList_Constructor();
327 if (*ppEnumIDList)
328 CreateMyCompEnumList(*ppEnumIDList, dwFlags);
330 TRACE ("-- (%p)->(new ID List: %p)\n", This, *ppEnumIDList);
332 return (*ppEnumIDList) ? S_OK : E_OUTOFMEMORY;
335 /**************************************************************************
336 * ISF_MyComputer_fnBindToObject
338 static HRESULT WINAPI ISF_MyComputer_fnBindToObject (IShellFolder2 *iface,
339 LPCITEMIDLIST pidl, LPBC pbcReserved, REFIID riid, LPVOID *ppvOut)
341 IGenericSFImpl *This = (IGenericSFImpl *)iface;
343 TRACE("(%p)->(pidl=%p,%p,%s,%p)\n", This,
344 pidl, pbcReserved, shdebugstr_guid (riid), ppvOut);
346 return SHELL32_BindToChild (This->pidlRoot, NULL, pidl, riid, ppvOut);
349 /**************************************************************************
350 * ISF_MyComputer_fnBindToStorage
352 static HRESULT WINAPI ISF_MyComputer_fnBindToStorage (IShellFolder2 * iface,
353 LPCITEMIDLIST pidl, LPBC pbcReserved, REFIID riid, LPVOID *ppvOut)
355 IGenericSFImpl *This = (IGenericSFImpl *)iface;
357 FIXME("(%p)->(pidl=%p,%p,%s,%p) stub\n", This,
358 pidl, pbcReserved, shdebugstr_guid (riid), ppvOut);
360 *ppvOut = NULL;
361 return E_NOTIMPL;
364 /**************************************************************************
365 * ISF_MyComputer_fnCompareIDs
368 static HRESULT WINAPI ISF_MyComputer_fnCompareIDs (IShellFolder2 *iface,
369 LPARAM lParam, LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
371 IGenericSFImpl *This = (IGenericSFImpl *)iface;
372 int nReturn;
374 TRACE ("(%p)->(0x%08lx,pidl1=%p,pidl2=%p)\n", This, lParam, pidl1, pidl2);
375 nReturn = SHELL32_CompareIDs (_IShellFolder_ (This), lParam, pidl1, pidl2);
376 TRACE ("-- %i\n", nReturn);
377 return nReturn;
380 /**************************************************************************
381 * ISF_MyComputer_fnCreateViewObject
383 static HRESULT WINAPI ISF_MyComputer_fnCreateViewObject (IShellFolder2 *iface,
384 HWND hwndOwner, REFIID riid, LPVOID * ppvOut)
386 IGenericSFImpl *This = (IGenericSFImpl *)iface;
387 LPSHELLVIEW pShellView;
388 HRESULT hr = E_INVALIDARG;
390 TRACE("(%p)->(hwnd=%p,%s,%p)\n", This,
391 hwndOwner, shdebugstr_guid (riid), ppvOut);
393 if (!ppvOut)
394 return hr;
396 *ppvOut = NULL;
398 if (IsEqualIID (riid, &IID_IDropTarget))
400 WARN ("IDropTarget not implemented\n");
401 hr = E_NOTIMPL;
403 else if (IsEqualIID (riid, &IID_IContextMenu))
405 WARN ("IContextMenu not implemented\n");
406 hr = E_NOTIMPL;
408 else if (IsEqualIID (riid, &IID_IShellView))
410 pShellView = IShellView_Constructor ((IShellFolder *) iface);
411 if (pShellView)
413 hr = IShellView_QueryInterface (pShellView, riid, ppvOut);
414 IShellView_Release (pShellView);
417 TRACE ("-- (%p)->(interface=%p)\n", This, ppvOut);
418 return hr;
421 /**************************************************************************
422 * ISF_MyComputer_fnGetAttributesOf
424 static HRESULT WINAPI ISF_MyComputer_fnGetAttributesOf (IShellFolder2 * iface,
425 UINT cidl, LPCITEMIDLIST * apidl, DWORD * rgfInOut)
427 IGenericSFImpl *This = (IGenericSFImpl *)iface;
428 HRESULT hr = S_OK;
430 TRACE ("(%p)->(cidl=%d apidl=%p mask=%p (0x%08lx))\n",
431 This, cidl, apidl, rgfInOut, rgfInOut ? *rgfInOut : 0);
433 if (!rgfInOut)
434 return E_INVALIDARG;
435 if (cidl && !apidl)
436 return E_INVALIDARG;
438 if (*rgfInOut == 0)
439 *rgfInOut = ~0;
441 if(cidl == 0){
442 IShellFolder *psfParent = NULL;
443 LPCITEMIDLIST rpidl = NULL;
445 hr = SHBindToParent(This->pidlRoot, &IID_IShellFolder, (LPVOID*)&psfParent, (LPCITEMIDLIST*)&rpidl);
446 if(SUCCEEDED(hr))
447 SHELL32_GetItemAttributes (psfParent, rpidl, rgfInOut);
448 } else {
449 while (cidl > 0 && *apidl) {
450 pdump (*apidl);
451 SHELL32_GetItemAttributes (_IShellFolder_ (This), *apidl, rgfInOut);
452 apidl++;
453 cidl--;
456 /* make sure SFGAO_VALIDATE is cleared, some apps depend on that */
457 *rgfInOut &= ~SFGAO_VALIDATE;
459 TRACE ("-- result=0x%08lx\n", *rgfInOut);
460 return hr;
463 /**************************************************************************
464 * ISF_MyComputer_fnGetUIObjectOf
466 * PARAMETERS
467 * hwndOwner [in] Parent window for any output
468 * cidl [in] array size
469 * apidl [in] simple pidl array
470 * riid [in] Requested Interface
471 * prgfInOut [ ] reserved
472 * ppvObject [out] Resulting Interface
475 static HRESULT WINAPI ISF_MyComputer_fnGetUIObjectOf (IShellFolder2 * iface,
476 HWND hwndOwner, UINT cidl, LPCITEMIDLIST * apidl, REFIID riid,
477 UINT * prgfInOut, LPVOID * ppvOut)
479 IGenericSFImpl *This = (IGenericSFImpl *)iface;
481 LPITEMIDLIST pidl;
482 IUnknown *pObj = NULL;
483 HRESULT hr = E_INVALIDARG;
485 TRACE("(%p)->(%p,%u,apidl=%p,%s,%p,%p)\n", This,
486 hwndOwner, cidl, apidl, shdebugstr_guid (riid), prgfInOut, ppvOut);
488 if (!ppvOut)
489 return hr;
491 *ppvOut = NULL;
493 if (IsEqualIID (riid, &IID_IContextMenu) && (cidl >= 1))
495 pObj = (LPUNKNOWN) ISvItemCm_Constructor ((IShellFolder *) iface,
496 This->pidlRoot, apidl, cidl);
497 hr = S_OK;
499 else if (IsEqualIID (riid, &IID_IDataObject) && (cidl >= 1))
501 pObj = (LPUNKNOWN) IDataObject_Constructor (hwndOwner,
502 This->pidlRoot, apidl, cidl);
503 hr = S_OK;
505 else if (IsEqualIID (riid, &IID_IExtractIconA) && (cidl == 1))
507 pidl = ILCombine (This->pidlRoot, apidl[0]);
508 pObj = (LPUNKNOWN) IExtractIconA_Constructor (pidl);
509 SHFree (pidl);
510 hr = S_OK;
512 else if (IsEqualIID (riid, &IID_IExtractIconW) && (cidl == 1))
514 pidl = ILCombine (This->pidlRoot, apidl[0]);
515 pObj = (LPUNKNOWN) IExtractIconW_Constructor (pidl);
516 SHFree (pidl);
517 hr = S_OK;
519 else if (IsEqualIID (riid, &IID_IDropTarget) && (cidl >= 1))
521 hr = IShellFolder_QueryInterface (iface, &IID_IDropTarget,
522 (LPVOID *) &pObj);
524 else if ((IsEqualIID(riid,&IID_IShellLinkW) ||
525 IsEqualIID(riid,&IID_IShellLinkA)) && (cidl == 1))
527 pidl = ILCombine (This->pidlRoot, apidl[0]);
528 hr = IShellLink_ConstructFromFile(NULL, riid, pidl, (LPVOID*) &pObj);
529 SHFree (pidl);
531 else
532 hr = E_NOINTERFACE;
534 if (SUCCEEDED(hr) && !pObj)
535 hr = E_OUTOFMEMORY;
537 *ppvOut = pObj;
538 TRACE ("(%p)->hr=0x%08lx\n", This, hr);
539 return hr;
542 /**************************************************************************
543 * ISF_MyComputer_fnGetDisplayNameOf
545 static HRESULT WINAPI ISF_MyComputer_fnGetDisplayNameOf (IShellFolder2 *iface,
546 LPCITEMIDLIST pidl, DWORD dwFlags, LPSTRRET strRet)
548 IGenericSFImpl *This = (IGenericSFImpl *)iface;
550 char szPath[MAX_PATH];
551 HRESULT hr = S_OK;
553 TRACE ("(%p)->(pidl=%p,0x%08lx,%p)\n", This, pidl, dwFlags, strRet);
554 pdump (pidl);
556 if (!strRet)
557 return E_INVALIDARG;
559 szPath[0] = 0x00;
561 if (!pidl->mkid.cb)
563 /* parsing name like ::{...} */
564 lstrcpyA (szPath, "::");
565 SHELL32_GUIDToStringA(&CLSID_MyComputer, &szPath[2]);
567 else if (_ILIsPidlSimple(pidl))
569 /* take names of special folders only if its only this folder */
570 if (_ILIsSpecialFolder(pidl))
572 GUID const *clsid;
574 clsid = _ILGetGUIDPointer (pidl);
575 if (clsid)
577 if (GET_SHGDN_FOR (dwFlags) & SHGDN_FORPARSING)
579 static const WCHAR clsidW[] =
580 { 'C','L','S','I','D','\\',0 };
581 static const WCHAR shellfolderW[] =
582 { '\\','s','h','e','l','l','f','o','l','d','e','r',0 };
583 static const WCHAR wantsForParsingW[] =
584 { 'W','a','n','t','s','F','o','r','P','a','r','s','i','n',
585 'g',0 };
586 int bWantsForParsing = FALSE;
587 WCHAR szRegPath[100];
588 LONG r;
591 * We can only get a filesystem path from a shellfolder
592 * if the value WantsFORPARSING exists in
593 * CLSID\\{...}\\shellfolder
594 * exception: the MyComputer folder has this keys not
595 * but like any filesystem backed
596 * folder it needs these behaviour
598 * Get the "WantsFORPARSING" flag from the registry
601 lstrcpyW (szRegPath, clsidW);
602 SHELL32_GUIDToStringW (clsid, &szRegPath[6]);
603 lstrcatW (szRegPath, shellfolderW);
604 r = SHGetValueW (HKEY_CLASSES_ROOT, szRegPath,
605 wantsForParsingW, NULL, NULL, NULL);
606 if (r == ERROR_SUCCESS)
607 bWantsForParsing = TRUE;
609 if ((GET_SHGDN_RELATION (dwFlags) == SHGDN_NORMAL) &&
610 bWantsForParsing)
613 * We need the filesystem path to the destination folder
614 * Only the folder itself can know it
616 hr = SHELL32_GetDisplayNameOfChild (iface, pidl,
617 dwFlags, szPath, MAX_PATH);
619 else
621 LPSTR p;
623 /* parsing name like ::{...} */
624 p = lstrcpyA(szPath, "::") + 2;
625 p += SHELL32_GUIDToStringA(&CLSID_MyComputer, p);
627 lstrcatA(p, "\\::");
628 p += 3;
629 SHELL32_GUIDToStringA(clsid, p);
632 else
634 /* user friendly name */
635 HCR_GetClassNameA (clsid, szPath, MAX_PATH);
638 else
640 /* append my own path */
641 _ILSimpleGetText (pidl, szPath, MAX_PATH);
644 else if (_ILIsDrive(pidl))
646 _ILSimpleGetText (pidl, szPath, MAX_PATH); /* append my own path */
648 /* long view "lw_name (C:)" */
649 if (!(dwFlags & SHGDN_FORPARSING))
651 DWORD dwVolumeSerialNumber, dwMaximumComponetLength, dwFileSystemFlags;
652 char szDrive[18] = "";
654 GetVolumeInformationA (szPath, szDrive, sizeof (szDrive) - 6,
655 &dwVolumeSerialNumber,
656 &dwMaximumComponetLength, &dwFileSystemFlags, NULL, 0);
657 strcat (szDrive, " (");
658 strncat (szDrive, szPath, 2);
659 strcat (szDrive, ")");
660 strcpy (szPath, szDrive);
663 else
665 /* Neither a shell namespace extension nor a drive letter. */
666 ERR("Wrong pidl type\n");
667 return E_INVALIDARG;
670 else
672 /* Complex pidl. Let the child folder do the work */
673 strRet->uType = STRRET_CSTR;
674 hr = SHELL32_GetDisplayNameOfChild(iface, pidl, dwFlags, szPath, MAX_PATH);
677 if (SUCCEEDED (hr))
679 strRet->uType = STRRET_CSTR;
680 lstrcpynA (strRet->u.cStr, szPath, MAX_PATH);
683 TRACE ("-- (%p)->(%s)\n", This, szPath);
684 return hr;
687 /**************************************************************************
688 * ISF_MyComputer_fnSetNameOf
689 * Changes the name of a file object or subfolder, possibly changing its item
690 * identifier in the process.
692 * PARAMETERS
693 * hwndOwner [in] Owner window for output
694 * pidl [in] simple pidl of item to change
695 * lpszName [in] the items new display name
696 * dwFlags [in] SHGNO formatting flags
697 * ppidlOut [out] simple pidl returned
699 static HRESULT WINAPI ISF_MyComputer_fnSetNameOf (
700 IShellFolder2 * iface, HWND hwndOwner, LPCITEMIDLIST pidl,
701 LPCOLESTR lpName, DWORD dwFlags, LPITEMIDLIST * pPidlOut)
703 IGenericSFImpl *This = (IGenericSFImpl *)iface;
704 FIXME ("(%p)->(%p,pidl=%p,%s,%lu,%p)\n", This,
705 hwndOwner, pidl, debugstr_w (lpName), dwFlags, pPidlOut);
706 return E_FAIL;
709 static HRESULT WINAPI ISF_MyComputer_fnGetDefaultSearchGUID (
710 IShellFolder2 * iface, GUID * pguid)
712 IGenericSFImpl *This = (IGenericSFImpl *)iface;
713 FIXME ("(%p)\n", This);
714 return E_NOTIMPL;
716 static HRESULT WINAPI ISF_MyComputer_fnEnumSearches (
717 IShellFolder2 * iface, IEnumExtraSearch ** ppenum)
719 IGenericSFImpl *This = (IGenericSFImpl *)iface;
720 FIXME ("(%p)\n", This);
721 return E_NOTIMPL;
723 static HRESULT WINAPI ISF_MyComputer_fnGetDefaultColumn (
724 IShellFolder2 *iface, DWORD dwRes, ULONG *pSort, ULONG *pDisplay)
726 IGenericSFImpl *This = (IGenericSFImpl *)iface;
728 TRACE ("(%p)\n", This);
730 if (pSort)
731 *pSort = 0;
732 if (pDisplay)
733 *pDisplay = 0;
734 return S_OK;
736 static HRESULT WINAPI ISF_MyComputer_fnGetDefaultColumnState (
737 IShellFolder2 * iface, UINT iColumn, DWORD * pcsFlags)
739 IGenericSFImpl *This = (IGenericSFImpl *)iface;
741 TRACE ("(%p)\n", This);
743 if (!pcsFlags || iColumn >= MYCOMPUTERSHELLVIEWCOLUMNS)
744 return E_INVALIDARG;
745 *pcsFlags = MyComputerSFHeader[iColumn].pcsFlags;
746 return S_OK;
749 static HRESULT WINAPI ISF_MyComputer_fnGetDetailsEx (IShellFolder2 * iface,
750 LPCITEMIDLIST pidl, const SHCOLUMNID * pscid, VARIANT * pv)
752 IGenericSFImpl *This = (IGenericSFImpl *)iface;
753 FIXME ("(%p)\n", This);
754 return E_NOTIMPL;
757 /* FIXME: drive size >4GB is rolling over */
758 static HRESULT WINAPI ISF_MyComputer_fnGetDetailsOf (IShellFolder2 * iface,
759 LPCITEMIDLIST pidl, UINT iColumn, SHELLDETAILS * psd)
761 IGenericSFImpl *This = (IGenericSFImpl *)iface;
762 HRESULT hr;
764 TRACE ("(%p)->(%p %i %p)\n", This, pidl, iColumn, psd);
766 if (!psd || iColumn >= MYCOMPUTERSHELLVIEWCOLUMNS)
767 return E_INVALIDARG;
769 if (!pidl)
771 psd->fmt = MyComputerSFHeader[iColumn].fmt;
772 psd->cxChar = MyComputerSFHeader[iColumn].cxChar;
773 psd->str.uType = STRRET_CSTR;
774 LoadStringA (shell32_hInstance, MyComputerSFHeader[iColumn].colnameid,
775 psd->str.u.cStr, MAX_PATH);
776 return S_OK;
778 else
780 char szPath[MAX_PATH];
781 ULARGE_INTEGER ulBytes;
783 psd->str.u.cStr[0] = 0x00;
784 psd->str.uType = STRRET_CSTR;
785 switch (iColumn)
787 case 0: /* name */
788 hr = IShellFolder_GetDisplayNameOf (iface, pidl,
789 SHGDN_NORMAL | SHGDN_INFOLDER, &psd->str);
790 break;
791 case 1: /* type */
792 _ILGetFileType (pidl, psd->str.u.cStr, MAX_PATH);
793 break;
794 case 2: /* total size */
795 if (_ILIsDrive (pidl))
797 _ILSimpleGetText (pidl, szPath, MAX_PATH);
798 GetDiskFreeSpaceExA (szPath, NULL, &ulBytes, NULL);
799 StrFormatByteSizeA (ulBytes.u.LowPart, psd->str.u.cStr, MAX_PATH);
801 break;
802 case 3: /* free size */
803 if (_ILIsDrive (pidl))
805 _ILSimpleGetText (pidl, szPath, MAX_PATH);
806 GetDiskFreeSpaceExA (szPath, &ulBytes, NULL, NULL);
807 StrFormatByteSizeA (ulBytes.u.LowPart, psd->str.u.cStr, MAX_PATH);
809 break;
811 hr = S_OK;
814 return hr;
817 static HRESULT WINAPI ISF_MyComputer_fnMapColumnToSCID (
818 IShellFolder2 * iface, UINT column, SHCOLUMNID * pscid)
820 IGenericSFImpl *This = (IGenericSFImpl *)iface;
821 FIXME ("(%p)\n", This);
822 return E_NOTIMPL;
825 static IShellFolder2Vtbl vt_ShellFolder2 =
827 ISF_MyComputer_fnQueryInterface,
828 ISF_MyComputer_fnAddRef,
829 ISF_MyComputer_fnRelease,
830 ISF_MyComputer_fnParseDisplayName,
831 ISF_MyComputer_fnEnumObjects,
832 ISF_MyComputer_fnBindToObject,
833 ISF_MyComputer_fnBindToStorage,
834 ISF_MyComputer_fnCompareIDs,
835 ISF_MyComputer_fnCreateViewObject,
836 ISF_MyComputer_fnGetAttributesOf,
837 ISF_MyComputer_fnGetUIObjectOf,
838 ISF_MyComputer_fnGetDisplayNameOf,
839 ISF_MyComputer_fnSetNameOf,
840 /* ShellFolder2 */
841 ISF_MyComputer_fnGetDefaultSearchGUID,
842 ISF_MyComputer_fnEnumSearches,
843 ISF_MyComputer_fnGetDefaultColumn,
844 ISF_MyComputer_fnGetDefaultColumnState,
845 ISF_MyComputer_fnGetDetailsEx,
846 ISF_MyComputer_fnGetDetailsOf,
847 ISF_MyComputer_fnMapColumnToSCID
850 /************************************************************************
851 * IMCFldr_PersistFolder2_QueryInterface
853 static HRESULT WINAPI IMCFldr_PersistFolder2_QueryInterface (
854 IPersistFolder2 * iface, REFIID iid, LPVOID * ppvObj)
856 _ICOM_THIS_From_IPersistFolder2 (IGenericSFImpl, iface);
858 TRACE ("(%p)\n", This);
860 return IUnknown_QueryInterface (_IUnknown_ (This), iid, ppvObj);
863 /************************************************************************
864 * IMCFldr_PersistFolder2_AddRef
866 static ULONG WINAPI IMCFldr_PersistFolder2_AddRef (IPersistFolder2 * iface)
868 _ICOM_THIS_From_IPersistFolder2 (IGenericSFImpl, iface);
870 TRACE ("(%p)->(count=%lu)\n", This, This->ref);
872 return IUnknown_AddRef (_IUnknown_ (This));
875 /************************************************************************
876 * ISFPersistFolder_Release
878 static ULONG WINAPI IMCFldr_PersistFolder2_Release (IPersistFolder2 * iface)
880 _ICOM_THIS_From_IPersistFolder2 (IGenericSFImpl, iface);
882 TRACE ("(%p)->(count=%lu)\n", This, This->ref);
884 return IUnknown_Release (_IUnknown_ (This));
887 /************************************************************************
888 * IMCFldr_PersistFolder2_GetClassID
890 static HRESULT WINAPI IMCFldr_PersistFolder2_GetClassID (
891 IPersistFolder2 * iface, CLSID * lpClassId)
893 _ICOM_THIS_From_IPersistFolder2 (IGenericSFImpl, iface);
895 TRACE ("(%p)\n", This);
897 if (!lpClassId)
898 return E_POINTER;
899 *lpClassId = CLSID_MyComputer;
901 return S_OK;
904 /************************************************************************
905 * IMCFldr_PersistFolder2_Initialize
907 * NOTES: it makes no sense to change the pidl
909 static HRESULT WINAPI IMCFldr_PersistFolder2_Initialize (
910 IPersistFolder2 * iface, LPCITEMIDLIST pidl)
912 _ICOM_THIS_From_IPersistFolder2 (IGenericSFImpl, iface);
913 TRACE ("(%p)->(%p)\n", This, pidl);
914 return E_NOTIMPL;
917 /**************************************************************************
918 * IPersistFolder2_fnGetCurFolder
920 static HRESULT WINAPI IMCFldr_PersistFolder2_GetCurFolder (
921 IPersistFolder2 * iface, LPITEMIDLIST * pidl)
923 _ICOM_THIS_From_IPersistFolder2 (IGenericSFImpl, iface);
925 TRACE ("(%p)->(%p)\n", This, pidl);
927 if (!pidl)
928 return E_POINTER;
929 *pidl = ILClone (This->pidlRoot);
930 return S_OK;
933 static IPersistFolder2Vtbl vt_PersistFolder2 =
935 IMCFldr_PersistFolder2_QueryInterface,
936 IMCFldr_PersistFolder2_AddRef,
937 IMCFldr_PersistFolder2_Release,
938 IMCFldr_PersistFolder2_GetClassID,
939 IMCFldr_PersistFolder2_Initialize,
940 IMCFldr_PersistFolder2_GetCurFolder