server: Use common get_fd_type implementation for both pipe end implementations.
[wine.git] / dlls / shell32 / shfldr_mycomp.c
blobd47d2af3266817f72262086c8f5e7e8c2a1c4b58
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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
33 #include "winerror.h"
34 #include "windef.h"
35 #include "winbase.h"
36 #include "winreg.h"
38 #include "wingdi.h"
39 #include "pidl.h"
40 #include "shlguid.h"
41 #include "undocshell.h"
42 #include "shell32_main.h"
43 #include "shresdef.h"
44 #include "shlwapi.h"
45 #include "wine/debug.h"
46 #include "debughlp.h"
47 #include "shfldr.h"
49 WINE_DEFAULT_DEBUG_CHANNEL (shell);
51 /***********************************************************************
52 * IShellFolder implementation
55 typedef struct {
56 IShellFolder2 IShellFolder2_iface;
57 IPersistFolder2 IPersistFolder2_iface;
58 LONG ref;
60 /* both paths are parsible from the desktop */
61 LPITEMIDLIST pidlRoot; /* absolute pidl */
62 } IMyComputerFolderImpl;
64 static const IShellFolder2Vtbl vt_ShellFolder2;
65 static const IPersistFolder2Vtbl vt_PersistFolder2;
67 static inline IMyComputerFolderImpl *impl_from_IShellFolder2(IShellFolder2 *iface)
69 return CONTAINING_RECORD(iface, IMyComputerFolderImpl, IShellFolder2_iface);
72 static inline IMyComputerFolderImpl *impl_from_IPersistFolder2(IPersistFolder2 *iface)
74 return CONTAINING_RECORD(iface, IMyComputerFolderImpl, IPersistFolder2_iface);
78 /***********************************************************************
79 * IShellFolder [MyComputer] implementation
82 static const shvheader mycomputer_header[] = {
83 {IDS_SHV_COLUMN1, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 15},
84 {IDS_SHV_COLUMN3, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
85 {IDS_SHV_COLUMN6, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
86 {IDS_SHV_COLUMN7, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
89 #define MYCOMPUTERSHELLVIEWCOLUMNS sizeof(mycomputer_header)/sizeof(shvheader)
91 /**************************************************************************
92 * ISF_MyComputer_Constructor
94 HRESULT WINAPI ISF_MyComputer_Constructor (IUnknown * pUnkOuter, REFIID riid, LPVOID * ppv)
96 IMyComputerFolderImpl *sf;
98 TRACE ("unkOut=%p %s\n", pUnkOuter, shdebugstr_guid (riid));
100 if (!ppv)
101 return E_POINTER;
102 if (pUnkOuter)
103 return CLASS_E_NOAGGREGATION;
105 sf = LocalAlloc (LMEM_ZEROINIT, sizeof (IMyComputerFolderImpl));
106 if (!sf)
107 return E_OUTOFMEMORY;
109 sf->ref = 0;
110 sf->IShellFolder2_iface.lpVtbl = &vt_ShellFolder2;
111 sf->IPersistFolder2_iface.lpVtbl = &vt_PersistFolder2;
112 sf->pidlRoot = _ILCreateMyComputer (); /* my qualified pidl */
114 if (FAILED (IShellFolder2_QueryInterface (&sf->IShellFolder2_iface, riid, ppv)))
116 IShellFolder2_Release (&sf->IShellFolder2_iface);
117 return E_NOINTERFACE;
120 TRACE ("--(%p)\n", sf);
121 return S_OK;
124 /**************************************************************************
125 * ISF_MyComputer_fnQueryInterface
127 * NOTES supports not IPersist/IPersistFolder
129 static HRESULT WINAPI ISF_MyComputer_fnQueryInterface (IShellFolder2 *iface,
130 REFIID riid, LPVOID *ppvObj)
132 IMyComputerFolderImpl *This = impl_from_IShellFolder2(iface);
134 TRACE ("(%p)->(%s,%p)\n", This, shdebugstr_guid (riid), ppvObj);
136 *ppvObj = NULL;
138 if (IsEqualIID (riid, &IID_IUnknown) ||
139 IsEqualIID (riid, &IID_IShellFolder) ||
140 IsEqualIID (riid, &IID_IShellFolder2))
142 *ppvObj = &This->IShellFolder2_iface;
144 else if (IsEqualIID (riid, &IID_IPersist) ||
145 IsEqualIID (riid, &IID_IPersistFolder) ||
146 IsEqualIID (riid, &IID_IPersistFolder2))
148 *ppvObj = &This->IPersistFolder2_iface;
151 if (*ppvObj)
153 IUnknown_AddRef ((IUnknown *) (*ppvObj));
154 TRACE ("-- Interface: (%p)->(%p)\n", ppvObj, *ppvObj);
155 return S_OK;
157 TRACE ("-- Interface: E_NOINTERFACE\n");
158 return E_NOINTERFACE;
161 static ULONG WINAPI ISF_MyComputer_fnAddRef (IShellFolder2 * iface)
163 IMyComputerFolderImpl *This = impl_from_IShellFolder2(iface);
164 ULONG refCount = InterlockedIncrement(&This->ref);
166 TRACE ("(%p)->(count=%u)\n", This, refCount - 1);
168 return refCount;
171 static ULONG WINAPI ISF_MyComputer_fnRelease (IShellFolder2 * iface)
173 IMyComputerFolderImpl *This = impl_from_IShellFolder2(iface);
174 ULONG refCount = InterlockedDecrement(&This->ref);
176 TRACE ("(%p)->(count=%u)\n", This, refCount + 1);
178 if (!refCount)
180 TRACE ("-- destroying IShellFolder(%p)\n", This);
181 SHFree (This->pidlRoot);
182 LocalFree (This);
184 return refCount;
187 /**************************************************************************
188 * ISF_MyComputer_fnParseDisplayName
190 static HRESULT WINAPI ISF_MyComputer_fnParseDisplayName (IShellFolder2 *iface,
191 HWND hwndOwner, LPBC pbc, LPOLESTR lpszDisplayName,
192 DWORD * pchEaten, LPITEMIDLIST * ppidl, DWORD * pdwAttributes)
194 IMyComputerFolderImpl *This = impl_from_IShellFolder2(iface);
195 HRESULT hr = E_INVALIDARG;
196 LPCWSTR szNext = NULL;
197 WCHAR szElement[MAX_PATH];
198 LPITEMIDLIST pidlTemp = NULL;
199 CLSID clsid;
201 TRACE("(%p)->(HWND=%p,%p,%p=%s,%p,pidl=%p,%p)\n", This,
202 hwndOwner, pbc, lpszDisplayName, debugstr_w (lpszDisplayName),
203 pchEaten, ppidl, pdwAttributes);
205 *ppidl = 0;
206 if (pchEaten)
207 *pchEaten = 0; /* strange but like the original */
209 /* handle CLSID paths */
210 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 = _ILCreateGuid (PT_GUID, &clsid);
217 /* do we have an absolute path name ? */
218 else if (PathGetDriveNumberW (lpszDisplayName) >= 0 &&
219 lpszDisplayName[2] == (WCHAR) '\\')
221 szNext = GetNextElementW (lpszDisplayName, szElement, MAX_PATH);
222 /* make drive letter uppercase to enable PIDL comparison */
223 szElement[0] = toupper(szElement[0]);
224 pidlTemp = _ILCreateDrive (szElement);
227 if (szNext && *szNext)
229 hr = SHELL32_ParseNextElement (iface, hwndOwner, pbc, &pidlTemp,
230 (LPOLESTR) szNext, pchEaten, pdwAttributes);
232 else
234 if (pdwAttributes && *pdwAttributes)
235 SHELL32_GetItemAttributes (&This->IShellFolder2_iface, pidlTemp, pdwAttributes);
236 hr = S_OK;
239 *ppidl = pidlTemp;
241 TRACE ("(%p)->(-- ret=0x%08x)\n", This, hr);
243 return hr;
246 /* retrieve a map of drives that should be displayed */
247 static DWORD get_drive_map(void)
249 static const WCHAR policiesW[] = {'S','o','f','t','w','a','r','e','\\',
250 'M','i','c','r','o','s','o','f','t','\\',
251 'W','i','n','d','o','w','s','\\',
252 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
253 'P','o','l','i','c','i','e','s','\\',
254 'E','x','p','l','o','r','e','r',0};
255 static const WCHAR nodrivesW[] = {'N','o','D','r','i','v','e','s',0};
256 static DWORD drive_mask;
257 static BOOL init_done = FALSE;
259 if (!init_done)
261 DWORD type, size, data, mask = 0;
262 HKEY hkey;
264 if (!RegOpenKeyW( HKEY_LOCAL_MACHINE, policiesW, &hkey ))
266 size = sizeof(data);
267 if (!RegQueryValueExW( hkey, nodrivesW, NULL, &type, (LPBYTE)&data, &size ) && type == REG_DWORD)
268 mask |= data;
269 RegCloseKey( hkey );
271 if (!RegOpenKeyW( HKEY_CURRENT_USER, policiesW, &hkey ))
273 size = sizeof(data);
274 if (!RegQueryValueExW( hkey, nodrivesW, NULL, &type, (LPBYTE)&data, &size ) && type == REG_DWORD)
275 mask |= data;
276 RegCloseKey( hkey );
278 drive_mask = mask;
279 init_done = TRUE;
282 return GetLogicalDrives() & ~drive_mask;
285 /**************************************************************************
286 * CreateMyCompEnumList()
288 static const WCHAR MyComputer_NameSpaceW[] = { 'S','O','F','T','W','A','R','E',
289 '\\','M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
290 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\','E','x','p','l',
291 'o','r','e','r','\\','M','y','C','o','m','p','u','t','e','r','\\','N','a','m',
292 'e','s','p','a','c','e','\0' };
294 static BOOL CreateMyCompEnumList(IEnumIDListImpl *list, DWORD dwFlags)
296 BOOL ret = TRUE;
298 TRACE("(%p)->(flags=0x%08x)\n", list, dwFlags);
300 /* enumerate the folders */
301 if (dwFlags & SHCONTF_FOLDERS)
303 WCHAR wszDriveName[] = {'A', ':', '\\', '\0'};
304 DWORD dwDrivemap = get_drive_map();
305 HKEY hkey;
306 UINT i;
308 while (ret && wszDriveName[0]<='Z')
310 if(dwDrivemap & 0x00000001L)
311 ret = AddToEnumList(list, _ILCreateDrive(wszDriveName));
312 wszDriveName[0]++;
313 dwDrivemap = dwDrivemap >> 1;
316 TRACE("-- (%p)-> enumerate (mycomputer shell extensions)\n",list);
317 for (i=0; i<2; i++) {
318 if (ret && !RegOpenKeyExW(i == 0 ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER,
319 MyComputer_NameSpaceW, 0, KEY_READ, &hkey))
321 WCHAR iid[50];
322 int i=0;
324 while (ret)
326 DWORD size;
327 LONG r;
329 size = sizeof(iid) / sizeof(iid[0]);
330 r = RegEnumKeyExW(hkey, i, iid, &size, 0, NULL, NULL, NULL);
331 if (ERROR_SUCCESS == r)
333 /* FIXME: shell extensions, shouldn't the type be
334 * PT_SHELLEXT? */
335 ret = AddToEnumList(list, _ILCreateGuidFromStrW(iid));
336 i++;
338 else if (ERROR_NO_MORE_ITEMS == r)
339 break;
340 else
341 ret = FALSE;
343 RegCloseKey(hkey);
347 return ret;
350 /**************************************************************************
351 * ISF_MyComputer_fnEnumObjects
353 static HRESULT WINAPI ISF_MyComputer_fnEnumObjects (IShellFolder2 *iface,
354 HWND hwndOwner, DWORD dwFlags, LPENUMIDLIST *ppEnumIDList)
356 IMyComputerFolderImpl *This = impl_from_IShellFolder2(iface);
357 IEnumIDListImpl *list;
359 TRACE("(%p)->(HWND=%p flags=0x%08x pplist=%p)\n", This,
360 hwndOwner, dwFlags, ppEnumIDList);
362 if (!(list = IEnumIDList_Constructor()))
363 return E_OUTOFMEMORY;
364 CreateMyCompEnumList(list, dwFlags);
365 *ppEnumIDList = &list->IEnumIDList_iface;
367 TRACE ("-- (%p)->(new ID List: %p)\n", This, *ppEnumIDList);
369 return S_OK;
372 /**************************************************************************
373 * ISF_MyComputer_fnBindToObject
375 static HRESULT WINAPI ISF_MyComputer_fnBindToObject (IShellFolder2 *iface,
376 LPCITEMIDLIST pidl, LPBC pbcReserved, REFIID riid, LPVOID *ppvOut)
378 IMyComputerFolderImpl *This = impl_from_IShellFolder2(iface);
380 TRACE("(%p)->(pidl=%p,%p,%s,%p)\n", This,
381 pidl, pbcReserved, shdebugstr_guid (riid), ppvOut);
383 return SHELL32_BindToChild (This->pidlRoot, NULL, pidl, riid, ppvOut);
386 /**************************************************************************
387 * ISF_MyComputer_fnBindToStorage
389 static HRESULT WINAPI ISF_MyComputer_fnBindToStorage (IShellFolder2 * iface,
390 LPCITEMIDLIST pidl, LPBC pbcReserved, REFIID riid, LPVOID *ppvOut)
392 IMyComputerFolderImpl *This = impl_from_IShellFolder2(iface);
394 FIXME("(%p)->(pidl=%p,%p,%s,%p) stub\n", This,
395 pidl, pbcReserved, shdebugstr_guid (riid), ppvOut);
397 *ppvOut = NULL;
398 return E_NOTIMPL;
401 /**************************************************************************
402 * ISF_MyComputer_fnCompareIDs
405 static HRESULT WINAPI ISF_MyComputer_fnCompareIDs (IShellFolder2 *iface,
406 LPARAM lParam, LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
408 IMyComputerFolderImpl *This = impl_from_IShellFolder2(iface);
409 HRESULT hr;
411 TRACE ("(%p)->(0x%08lx,pidl1=%p,pidl2=%p)\n", This, lParam, pidl1, pidl2);
412 hr = SHELL32_CompareIDs(&This->IShellFolder2_iface, lParam, pidl1, pidl2);
413 TRACE ("-- 0x%08x\n", hr);
414 return hr;
417 /**************************************************************************
418 * ISF_MyComputer_fnCreateViewObject
420 static HRESULT WINAPI ISF_MyComputer_fnCreateViewObject (IShellFolder2 *iface,
421 HWND hwndOwner, REFIID riid, LPVOID * ppvOut)
423 IMyComputerFolderImpl *This = impl_from_IShellFolder2(iface);
424 LPSHELLVIEW pShellView;
425 HRESULT hr = E_INVALIDARG;
427 TRACE("(%p)->(hwnd=%p,%s,%p)\n", This,
428 hwndOwner, shdebugstr_guid (riid), ppvOut);
430 if (!ppvOut)
431 return hr;
433 *ppvOut = NULL;
435 if (IsEqualIID (riid, &IID_IDropTarget))
437 WARN ("IDropTarget not implemented\n");
438 hr = E_NOTIMPL;
440 else if (IsEqualIID (riid, &IID_IContextMenu))
442 WARN ("IContextMenu not implemented\n");
443 hr = E_NOTIMPL;
445 else if (IsEqualIID (riid, &IID_IShellView))
447 pShellView = IShellView_Constructor ((IShellFolder *) iface);
448 if (pShellView)
450 hr = IShellView_QueryInterface (pShellView, riid, ppvOut);
451 IShellView_Release (pShellView);
454 TRACE ("-- (%p)->(interface=%p)\n", This, ppvOut);
455 return hr;
458 /**************************************************************************
459 * ISF_MyComputer_fnGetAttributesOf
461 static HRESULT WINAPI ISF_MyComputer_fnGetAttributesOf (IShellFolder2 * iface,
462 UINT cidl, LPCITEMIDLIST * apidl, DWORD * rgfInOut)
464 IMyComputerFolderImpl *This = impl_from_IShellFolder2(iface);
465 HRESULT hr = S_OK;
467 TRACE ("(%p)->(cidl=%d apidl=%p mask=%p (0x%08x))\n",
468 This, cidl, apidl, rgfInOut, rgfInOut ? *rgfInOut : 0);
470 if (!rgfInOut)
471 return E_INVALIDARG;
472 if (cidl && !apidl)
473 return E_INVALIDARG;
475 if (*rgfInOut == 0)
476 *rgfInOut = ~0;
478 if(cidl == 0){
479 IShellFolder2 *parent = NULL;
480 LPCITEMIDLIST rpidl = NULL;
482 hr = SHBindToParent(This->pidlRoot, &IID_IShellFolder2, (void **)&parent, &rpidl);
483 if(SUCCEEDED(hr)) {
484 SHELL32_GetItemAttributes(parent, rpidl, rgfInOut);
485 IShellFolder2_Release(parent);
487 } else {
488 while (cidl > 0 && *apidl) {
489 pdump (*apidl);
490 SHELL32_GetItemAttributes(&This->IShellFolder2_iface, *apidl, rgfInOut);
491 apidl++;
492 cidl--;
495 /* make sure SFGAO_VALIDATE is cleared, some apps depend on that */
496 *rgfInOut &= ~SFGAO_VALIDATE;
498 TRACE ("-- result=0x%08x\n", *rgfInOut);
499 return hr;
502 /**************************************************************************
503 * ISF_MyComputer_fnGetUIObjectOf
505 * PARAMETERS
506 * hwndOwner [in] Parent window for any output
507 * cidl [in] array size
508 * apidl [in] simple pidl array
509 * riid [in] Requested Interface
510 * prgfInOut [ ] reserved
511 * ppvObject [out] Resulting Interface
514 static HRESULT WINAPI ISF_MyComputer_fnGetUIObjectOf (IShellFolder2 * iface,
515 HWND hwndOwner, UINT cidl, LPCITEMIDLIST * apidl, REFIID riid,
516 UINT * prgfInOut, LPVOID * ppvOut)
518 IMyComputerFolderImpl *This = impl_from_IShellFolder2(iface);
520 LPITEMIDLIST pidl;
521 IUnknown *pObj = NULL;
522 HRESULT hr = E_INVALIDARG;
524 TRACE("(%p)->(%p,%u,apidl=%p,%s,%p,%p)\n", This,
525 hwndOwner, cidl, apidl, shdebugstr_guid (riid), prgfInOut, ppvOut);
527 if (!ppvOut)
528 return hr;
530 *ppvOut = NULL;
532 if (IsEqualIID (riid, &IID_IContextMenu) && (cidl >= 1))
534 return ItemMenu_Constructor((IShellFolder*) iface, This->pidlRoot, apidl, cidl, riid, ppvOut);
536 else if (IsEqualIID (riid, &IID_IDataObject) && (cidl >= 1))
538 pObj = (LPUNKNOWN) IDataObject_Constructor (hwndOwner,
539 This->pidlRoot, apidl, cidl);
540 hr = S_OK;
542 else if (IsEqualIID (riid, &IID_IExtractIconA) && (cidl == 1))
544 pidl = ILCombine (This->pidlRoot, apidl[0]);
545 pObj = (LPUNKNOWN) IExtractIconA_Constructor (pidl);
546 SHFree (pidl);
547 hr = S_OK;
549 else if (IsEqualIID (riid, &IID_IExtractIconW) && (cidl == 1))
551 pidl = ILCombine (This->pidlRoot, apidl[0]);
552 pObj = (LPUNKNOWN) IExtractIconW_Constructor (pidl);
553 SHFree (pidl);
554 hr = S_OK;
556 else if (IsEqualIID (riid, &IID_IDropTarget) && (cidl >= 1))
558 hr = IShellFolder2_QueryInterface (iface, &IID_IDropTarget,
559 (LPVOID *) &pObj);
561 else if ((IsEqualIID(riid,&IID_IShellLinkW) ||
562 IsEqualIID(riid,&IID_IShellLinkA)) && (cidl == 1))
564 pidl = ILCombine (This->pidlRoot, apidl[0]);
565 hr = IShellLink_ConstructFromFile(NULL, riid, pidl, &pObj);
566 SHFree (pidl);
568 else
569 hr = E_NOINTERFACE;
571 if (SUCCEEDED(hr) && !pObj)
572 hr = E_OUTOFMEMORY;
574 *ppvOut = pObj;
575 TRACE ("(%p)->hr=0x%08x\n", This, hr);
576 return hr;
579 /**************************************************************************
580 * ISF_MyComputer_fnGetDisplayNameOf
582 static HRESULT WINAPI ISF_MyComputer_fnGetDisplayNameOf (IShellFolder2 *iface,
583 LPCITEMIDLIST pidl, DWORD dwFlags, LPSTRRET strRet)
585 IMyComputerFolderImpl *This = impl_from_IShellFolder2(iface);
587 LPWSTR pszPath;
588 HRESULT hr = S_OK;
590 TRACE ("(%p)->(pidl=%p,0x%08x,%p)\n", This, pidl, dwFlags, strRet);
591 pdump (pidl);
593 if (!strRet)
594 return E_INVALIDARG;
596 pszPath = CoTaskMemAlloc((MAX_PATH +1) * sizeof(WCHAR));
597 if (!pszPath)
598 return E_OUTOFMEMORY;
600 pszPath[0] = 0;
602 if (!pidl->mkid.cb)
604 /* parsing name like ::{...} */
605 pszPath[0] = ':';
606 pszPath[1] = ':';
607 SHELL32_GUIDToStringW(&CLSID_MyComputer, &pszPath[2]);
609 else if (_ILIsPidlSimple(pidl))
611 /* take names of special folders only if its only this folder */
612 if (_ILIsSpecialFolder(pidl))
614 GUID const *clsid;
616 clsid = _ILGetGUIDPointer (pidl);
617 if (clsid)
619 if (GET_SHGDN_FOR (dwFlags) & SHGDN_FORPARSING)
621 static const WCHAR clsidW[] =
622 { 'C','L','S','I','D','\\',0 };
623 static const WCHAR shellfolderW[] =
624 { '\\','s','h','e','l','l','f','o','l','d','e','r',0 };
625 static const WCHAR wantsForParsingW[] =
626 { 'W','a','n','t','s','F','o','r','P','a','r','s','i','n',
627 'g',0 };
628 BOOL bWantsForParsing = FALSE;
629 WCHAR szRegPath[100];
630 LONG r;
633 * We can only get a filesystem path from a shellfolder
634 * if the value WantsFORPARSING exists in
635 * CLSID\\{...}\\shellfolder
636 * exception: the MyComputer folder has this keys not
637 * but like any filesystem backed
638 * folder it needs these behaviour
640 * Get the "WantsFORPARSING" flag from the registry
643 lstrcpyW (szRegPath, clsidW);
644 SHELL32_GUIDToStringW (clsid, &szRegPath[6]);
645 lstrcatW (szRegPath, shellfolderW);
646 r = SHGetValueW (HKEY_CLASSES_ROOT, szRegPath,
647 wantsForParsingW, NULL, NULL, NULL);
648 if (r == ERROR_SUCCESS)
649 bWantsForParsing = TRUE;
651 if ((GET_SHGDN_RELATION (dwFlags) == SHGDN_NORMAL) &&
652 bWantsForParsing)
655 * We need the filesystem path to the destination folder
656 * Only the folder itself can know it
658 hr = SHELL32_GetDisplayNameOfChild (iface, pidl,
659 dwFlags, pszPath, MAX_PATH);
661 else
663 LPWSTR p = pszPath;
665 /* parsing name like ::{...} */
666 p[0] = ':';
667 p[1] = ':';
668 p += 2;
669 p += SHELL32_GUIDToStringW(&CLSID_MyComputer, p);
671 /* \:: */
672 p[0] = '\\';
673 p[1] = ':';
674 p[2] = ':';
675 p += 3;
676 SHELL32_GUIDToStringW(clsid, p);
679 else
681 /* user friendly name */
682 HCR_GetClassNameW (clsid, pszPath, MAX_PATH);
685 else
687 /* append my own path */
688 _ILSimpleGetTextW (pidl, pszPath, MAX_PATH);
691 else if (_ILIsDrive(pidl))
693 _ILSimpleGetTextW (pidl, pszPath, MAX_PATH); /* append my own path */
695 /* long view "lw_name (C:)" */
696 if (!(dwFlags & SHGDN_FORPARSING))
698 static const WCHAR wszOpenBracket[] = {' ','(',0};
699 static const WCHAR wszCloseBracket[] = {')',0};
700 WCHAR wszDrive[32 /* label */ + 6 /* ' (C:)'\0 */] = {0};
702 GetVolumeInformationW (pszPath, wszDrive, sizeof(wszDrive)/sizeof(wszDrive[0]) - 5,
703 NULL, NULL, NULL, NULL, 0);
704 strcatW (wszDrive, wszOpenBracket);
705 lstrcpynW (wszDrive + strlenW(wszDrive), pszPath, 3);
706 strcatW (wszDrive, wszCloseBracket);
707 strcpyW (pszPath, wszDrive);
710 else
712 /* Neither a shell namespace extension nor a drive letter. */
713 ERR("Wrong pidl type\n");
714 CoTaskMemFree(pszPath);
715 return E_INVALIDARG;
718 else
720 /* Complex pidl. Let the child folder do the work */
721 hr = SHELL32_GetDisplayNameOfChild(iface, pidl, dwFlags, pszPath, MAX_PATH);
724 if (SUCCEEDED (hr))
726 /* Win9x always returns ANSI strings, NT always returns Unicode strings */
727 if (GetVersion() & 0x80000000)
729 strRet->uType = STRRET_CSTR;
730 if (!WideCharToMultiByte(CP_ACP, 0, pszPath, -1, strRet->u.cStr, MAX_PATH,
731 NULL, NULL))
732 strRet->u.cStr[0] = '\0';
733 CoTaskMemFree(pszPath);
735 else
737 strRet->uType = STRRET_WSTR;
738 strRet->u.pOleStr = pszPath;
741 else
742 CoTaskMemFree(pszPath);
744 TRACE ("-- (%p)->(%s)\n", This, strRet->uType == STRRET_CSTR ? strRet->u.cStr : debugstr_w(strRet->u.pOleStr));
745 return hr;
748 /**************************************************************************
749 * ISF_MyComputer_fnSetNameOf
750 * Changes the name of a file object or subfolder, possibly changing its item
751 * identifier in the process.
753 * PARAMETERS
754 * hwndOwner [in] Owner window for output
755 * pidl [in] simple pidl of item to change
756 * lpszName [in] the items new display name
757 * dwFlags [in] SHGNO formatting flags
758 * ppidlOut [out] simple pidl returned
760 static HRESULT WINAPI ISF_MyComputer_fnSetNameOf (
761 IShellFolder2 * iface, HWND hwndOwner, LPCITEMIDLIST pidl,
762 LPCOLESTR lpName, DWORD dwFlags, LPITEMIDLIST * pPidlOut)
764 IMyComputerFolderImpl *This = impl_from_IShellFolder2(iface);
765 FIXME ("(%p)->(%p,pidl=%p,%s,%u,%p)\n", This,
766 hwndOwner, pidl, debugstr_w (lpName), dwFlags, pPidlOut);
767 return E_FAIL;
770 static HRESULT WINAPI ISF_MyComputer_fnGetDefaultSearchGUID (
771 IShellFolder2 * iface, GUID * pguid)
773 IMyComputerFolderImpl *This = impl_from_IShellFolder2(iface);
774 FIXME ("(%p)\n", This);
775 return E_NOTIMPL;
777 static HRESULT WINAPI ISF_MyComputer_fnEnumSearches (
778 IShellFolder2 * iface, IEnumExtraSearch ** ppenum)
780 IMyComputerFolderImpl *This = impl_from_IShellFolder2(iface);
781 FIXME ("(%p)\n", This);
782 return E_NOTIMPL;
784 static HRESULT WINAPI ISF_MyComputer_fnGetDefaultColumn (
785 IShellFolder2 *iface, DWORD dwRes, ULONG *pSort, ULONG *pDisplay)
787 IMyComputerFolderImpl *This = impl_from_IShellFolder2(iface);
789 TRACE ("(%p)\n", This);
791 if (pSort)
792 *pSort = 0;
793 if (pDisplay)
794 *pDisplay = 0;
795 return S_OK;
797 static HRESULT WINAPI ISF_MyComputer_fnGetDefaultColumnState (
798 IShellFolder2 * iface, UINT iColumn, DWORD * pcsFlags)
800 IMyComputerFolderImpl *This = impl_from_IShellFolder2(iface);
802 TRACE ("(%p)->(%d %p)\n", This, iColumn, pcsFlags);
804 if (!pcsFlags || iColumn >= MYCOMPUTERSHELLVIEWCOLUMNS)
805 return E_INVALIDARG;
807 *pcsFlags = mycomputer_header[iColumn].pcsFlags;
809 return S_OK;
812 static HRESULT WINAPI ISF_MyComputer_fnGetDetailsEx (IShellFolder2 * iface,
813 LPCITEMIDLIST pidl, const SHCOLUMNID * pscid, VARIANT * pv)
815 IMyComputerFolderImpl *This = impl_from_IShellFolder2(iface);
816 FIXME ("(%p)\n", This);
817 return E_NOTIMPL;
820 /* FIXME: drive size >4GB is rolling over */
821 static HRESULT WINAPI ISF_MyComputer_fnGetDetailsOf (IShellFolder2 *iface,
822 LPCITEMIDLIST pidl, UINT iColumn, SHELLDETAILS *psd)
824 IMyComputerFolderImpl *This = impl_from_IShellFolder2(iface);
825 char szPath[MAX_PATH];
826 ULARGE_INTEGER ulBytes;
827 HRESULT hr = S_OK;
829 TRACE ("(%p)->(%p %i %p)\n", This, pidl, iColumn, psd);
831 if (!psd || iColumn >= MYCOMPUTERSHELLVIEWCOLUMNS)
832 return E_INVALIDARG;
834 if (!pidl)
835 return SHELL32_GetColumnDetails(mycomputer_header, iColumn, psd);
837 psd->str.u.cStr[0] = 0;
838 psd->str.uType = STRRET_CSTR;
840 switch (iColumn)
842 case 0: /* name */
843 hr = IShellFolder2_GetDisplayNameOf (iface, pidl,
844 SHGDN_NORMAL | SHGDN_INFOLDER, &psd->str);
845 break;
846 case 1: /* type */
847 _ILGetFileType (pidl, psd->str.u.cStr, MAX_PATH);
848 break;
849 case 2: /* total size */
850 if (_ILIsDrive (pidl))
852 _ILSimpleGetText (pidl, szPath, MAX_PATH);
853 GetDiskFreeSpaceExA (szPath, NULL, &ulBytes, NULL);
854 StrFormatByteSizeA (ulBytes.u.LowPart, psd->str.u.cStr, MAX_PATH);
856 break;
857 case 3: /* free size */
858 if (_ILIsDrive (pidl))
860 _ILSimpleGetText (pidl, szPath, MAX_PATH);
861 GetDiskFreeSpaceExA (szPath, &ulBytes, NULL, NULL);
862 StrFormatByteSizeA (ulBytes.u.LowPart, psd->str.u.cStr, MAX_PATH);
864 break;
867 return hr;
870 static HRESULT WINAPI ISF_MyComputer_fnMapColumnToSCID (
871 IShellFolder2 * iface, UINT column, SHCOLUMNID * pscid)
873 IMyComputerFolderImpl *This = impl_from_IShellFolder2(iface);
874 FIXME ("(%p)\n", This);
875 return E_NOTIMPL;
878 static const IShellFolder2Vtbl vt_ShellFolder2 =
880 ISF_MyComputer_fnQueryInterface,
881 ISF_MyComputer_fnAddRef,
882 ISF_MyComputer_fnRelease,
883 ISF_MyComputer_fnParseDisplayName,
884 ISF_MyComputer_fnEnumObjects,
885 ISF_MyComputer_fnBindToObject,
886 ISF_MyComputer_fnBindToStorage,
887 ISF_MyComputer_fnCompareIDs,
888 ISF_MyComputer_fnCreateViewObject,
889 ISF_MyComputer_fnGetAttributesOf,
890 ISF_MyComputer_fnGetUIObjectOf,
891 ISF_MyComputer_fnGetDisplayNameOf,
892 ISF_MyComputer_fnSetNameOf,
893 /* ShellFolder2 */
894 ISF_MyComputer_fnGetDefaultSearchGUID,
895 ISF_MyComputer_fnEnumSearches,
896 ISF_MyComputer_fnGetDefaultColumn,
897 ISF_MyComputer_fnGetDefaultColumnState,
898 ISF_MyComputer_fnGetDetailsEx,
899 ISF_MyComputer_fnGetDetailsOf,
900 ISF_MyComputer_fnMapColumnToSCID
903 /************************************************************************
904 * IMCFldr_PersistFolder2_QueryInterface
906 static HRESULT WINAPI IMCFldr_PersistFolder2_QueryInterface (
907 IPersistFolder2 * iface, REFIID iid, LPVOID * ppvObj)
909 IMyComputerFolderImpl *This = impl_from_IPersistFolder2(iface);
910 TRACE ("(%p)\n", This);
911 return IShellFolder2_QueryInterface (&This->IShellFolder2_iface, iid, ppvObj);
914 /************************************************************************
915 * IMCFldr_PersistFolder2_AddRef
917 static ULONG WINAPI IMCFldr_PersistFolder2_AddRef (IPersistFolder2 * iface)
919 IMyComputerFolderImpl *This = impl_from_IPersistFolder2(iface);
920 TRACE ("(%p)->(count=%u)\n", This, This->ref);
921 return IShellFolder2_AddRef (&This->IShellFolder2_iface);
924 /************************************************************************
925 * ISFPersistFolder_Release
927 static ULONG WINAPI IMCFldr_PersistFolder2_Release (IPersistFolder2 * iface)
929 IMyComputerFolderImpl *This = impl_from_IPersistFolder2(iface);
930 TRACE ("(%p)->(count=%u)\n", This, This->ref);
931 return IShellFolder2_Release (&This->IShellFolder2_iface);
934 /************************************************************************
935 * IMCFldr_PersistFolder2_GetClassID
937 static HRESULT WINAPI IMCFldr_PersistFolder2_GetClassID (
938 IPersistFolder2 * iface, CLSID * lpClassId)
940 IMyComputerFolderImpl *This = impl_from_IPersistFolder2(iface);
942 TRACE ("(%p)\n", This);
944 if (!lpClassId)
945 return E_POINTER;
946 *lpClassId = CLSID_MyComputer;
948 return S_OK;
951 /************************************************************************
952 * IMCFldr_PersistFolder2_Initialize
954 * NOTES: it makes no sense to change the pidl
956 static HRESULT WINAPI IMCFldr_PersistFolder2_Initialize (
957 IPersistFolder2 * iface, LPCITEMIDLIST pidl)
959 IMyComputerFolderImpl *This = impl_from_IPersistFolder2(iface);
960 TRACE ("(%p)->(%p)\n", This, pidl);
961 return E_NOTIMPL;
964 /**************************************************************************
965 * IPersistFolder2_fnGetCurFolder
967 static HRESULT WINAPI IMCFldr_PersistFolder2_GetCurFolder (
968 IPersistFolder2 * iface, LPITEMIDLIST * pidl)
970 IMyComputerFolderImpl *This = impl_from_IPersistFolder2(iface);
972 TRACE ("(%p)->(%p)\n", This, pidl);
974 if (!pidl)
975 return E_POINTER;
976 *pidl = ILClone (This->pidlRoot);
977 return S_OK;
980 static const IPersistFolder2Vtbl vt_PersistFolder2 =
982 IMCFldr_PersistFolder2_QueryInterface,
983 IMCFldr_PersistFolder2_AddRef,
984 IMCFldr_PersistFolder2_Release,
985 IMCFldr_PersistFolder2_GetClassID,
986 IMCFldr_PersistFolder2_Initialize,
987 IMCFldr_PersistFolder2_GetCurFolder