Changes in crossover-wine-src-6.1.0 except for configure
[wine/hacks.git] / dlls / shell32 / shfldr_mycomp.c
blob1901bde8e380d92f86315e1d4dd21fad028cfd06
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>
29 #include <limits.h>
31 #define COBJMACROS
32 #define NONAMELESSUNION
33 #define NONAMELESSSTRUCT
35 #include "winerror.h"
36 #include "windef.h"
37 #include "winbase.h"
38 #include "winreg.h"
40 #include "wingdi.h"
41 #include "pidl.h"
42 #include "shlguid.h"
43 #include "enumidlist.h"
44 #include "undocshell.h"
45 #include "shell32_main.h"
46 #include "shresdef.h"
47 #include "shlwapi.h"
48 #include "wine/debug.h"
49 #include "debughlp.h"
50 #include "shfldr.h"
52 WINE_DEFAULT_DEBUG_CHANNEL (shell);
54 /***********************************************************************
55 * SHELL32_DisplayUnixPaths
57 * Check if unix paths should be displayed.
59 static int bDisplayUnixPath = -1;
61 static int SHELL32_DisplayUnixPaths(void)
63 if (bDisplayUnixPath < 0)
65 HKEY hkey;
67 bDisplayUnixPath = 0;
69 /* @@ Wine registry key: HKCU\Software\Wine */
70 if (!RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine", &hkey))
72 char buffer[20];
73 DWORD type, count = sizeof(buffer);
75 if(!RegQueryValueExA(hkey, "DisplayUnixPaths", 0, &type, (LPBYTE)buffer, &count))
76 bDisplayUnixPath = atoi(buffer);
78 RegCloseKey(hkey);
82 return bDisplayUnixPath;
86 /***********************************************************************
87 * IShellFolder implementation
90 typedef struct {
91 const IShellFolder2Vtbl *lpVtbl;
92 LONG ref;
93 const IPersistFolder2Vtbl *lpVtblPersistFolder2;
95 /* both paths are parsible from the desktop */
96 LPITEMIDLIST pidlRoot; /* absolute pidl */
97 } IGenericSFImpl;
99 static const IShellFolder2Vtbl vt_ShellFolder2;
100 static const IPersistFolder2Vtbl vt_PersistFolder2;
102 static inline IGenericSFImpl *impl_from_IPersistFolder2( IPersistFolder2 *iface )
104 return (IGenericSFImpl *)((char*)iface - FIELD_OFFSET(IGenericSFImpl, lpVtblPersistFolder2));
109 converts This to an interface pointer
111 #define _IUnknown_(This) (IUnknown*)&(This->lpVtbl)
112 #define _IShellFolder_(This) (IShellFolder*)&(This->lpVtbl)
113 #define _IShellFolder2_(This) (IShellFolder2*)&(This->lpVtbl)
115 #define _IPersist_(This) (IPersist*)&(This->lpVtblPersistFolder2)
116 #define _IPersistFolder_(This) (IPersistFolder*)&(This->lpVtblPersistFolder2)
117 #define _IPersistFolder2_(This) (IPersistFolder2*)&(This->lpVtblPersistFolder2)
119 /***********************************************************************
120 * IShellFolder [MyComputer] implementation
123 static const shvheader MyComputerSFHeader[] = {
124 {IDS_SHV_COLUMN1, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 15},
125 {IDS_SHV_COLUMN3, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
126 {IDS_SHV_COLUMN6, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
127 {IDS_SHV_COLUMN7, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
130 #define MYCOMPUTERSHELLVIEWCOLUMNS 4
132 /**************************************************************************
133 * ISF_MyComputer_Constructor
135 HRESULT WINAPI ISF_MyComputer_Constructor (IUnknown * pUnkOuter, REFIID riid, LPVOID * ppv)
137 IGenericSFImpl *sf;
139 TRACE ("unkOut=%p %s\n", pUnkOuter, shdebugstr_guid (riid));
141 if (!ppv)
142 return E_POINTER;
143 if (pUnkOuter)
144 return CLASS_E_NOAGGREGATION;
146 sf = LocalAlloc (LMEM_ZEROINIT, sizeof (IGenericSFImpl));
147 if (!sf)
148 return E_OUTOFMEMORY;
150 sf->ref = 0;
151 sf->lpVtbl = &vt_ShellFolder2;
152 sf->lpVtblPersistFolder2 = &vt_PersistFolder2;
153 sf->pidlRoot = _ILCreateMyComputer (); /* my qualified pidl */
155 if (!SUCCEEDED (IUnknown_QueryInterface (_IUnknown_ (sf), riid, ppv)))
157 IUnknown_Release (_IUnknown_ (sf));
158 return E_NOINTERFACE;
161 TRACE ("--(%p)\n", sf);
162 return S_OK;
165 /**************************************************************************
166 * ISF_MyComputer_fnQueryInterface
168 * NOTES supports not IPersist/IPersistFolder
170 static HRESULT WINAPI ISF_MyComputer_fnQueryInterface (IShellFolder2 *iface,
171 REFIID riid, LPVOID *ppvObj)
173 IGenericSFImpl *This = (IGenericSFImpl *)iface;
175 TRACE ("(%p)->(%s,%p)\n", This, shdebugstr_guid (riid), ppvObj);
177 *ppvObj = NULL;
179 if (IsEqualIID (riid, &IID_IUnknown) ||
180 IsEqualIID (riid, &IID_IShellFolder) ||
181 IsEqualIID (riid, &IID_IShellFolder2))
183 *ppvObj = This;
185 else if (IsEqualIID (riid, &IID_IPersist) ||
186 IsEqualIID (riid, &IID_IPersistFolder) ||
187 IsEqualIID (riid, &IID_IPersistFolder2))
189 *ppvObj = _IPersistFolder2_ (This);
192 if (*ppvObj)
194 IUnknown_AddRef ((IUnknown *) (*ppvObj));
195 TRACE ("-- Interface: (%p)->(%p)\n", ppvObj, *ppvObj);
196 return S_OK;
198 TRACE ("-- Interface: E_NOINTERFACE\n");
199 return E_NOINTERFACE;
202 static ULONG WINAPI ISF_MyComputer_fnAddRef (IShellFolder2 * iface)
204 IGenericSFImpl *This = (IGenericSFImpl *)iface;
205 ULONG refCount = InterlockedIncrement(&This->ref);
207 TRACE ("(%p)->(count=%u)\n", This, refCount - 1);
209 return refCount;
212 static ULONG WINAPI ISF_MyComputer_fnRelease (IShellFolder2 * iface)
214 IGenericSFImpl *This = (IGenericSFImpl *)iface;
215 ULONG refCount = InterlockedDecrement(&This->ref);
217 TRACE ("(%p)->(count=%u)\n", This, refCount + 1);
219 if (!refCount)
221 TRACE ("-- destroying IShellFolder(%p)\n", This);
222 SHFree (This->pidlRoot);
223 LocalFree ((HLOCAL) This);
225 return refCount;
228 /**************************************************************************
229 * ISF_MyComputer_fnParseDisplayName
231 static HRESULT WINAPI ISF_MyComputer_fnParseDisplayName (IShellFolder2 *iface,
232 HWND hwndOwner, LPBC pbc, LPOLESTR lpszDisplayName,
233 DWORD * pchEaten, LPITEMIDLIST * ppidl, DWORD * pdwAttributes)
235 IGenericSFImpl *This = (IGenericSFImpl *)iface;
236 HRESULT hr = E_INVALIDARG;
237 LPCWSTR szNext = NULL;
238 WCHAR szElement[MAX_PATH];
239 LPITEMIDLIST pidlTemp = NULL;
240 CLSID clsid;
242 TRACE("(%p)->(HWND=%p,%p,%p=%s,%p,pidl=%p,%p)\n", This,
243 hwndOwner, pbc, lpszDisplayName, debugstr_w (lpszDisplayName),
244 pchEaten, ppidl, pdwAttributes);
246 *ppidl = 0;
247 if (pchEaten)
248 *pchEaten = 0; /* strange but like the original */
250 /* handle CLSID paths */
251 if (lpszDisplayName[0] == ':' && lpszDisplayName[1] == ':')
253 szNext = GetNextElementW (lpszDisplayName, szElement, MAX_PATH);
254 TRACE ("-- element: %s\n", debugstr_w (szElement));
255 SHCLSIDFromStringW (szElement + 2, &clsid);
256 pidlTemp = _ILCreateGuid (PT_GUID, &clsid);
258 /* do we have an absolute path name ? */
259 else if (PathGetDriveNumberW (lpszDisplayName) >= 0 &&
260 lpszDisplayName[2] == (WCHAR) '\\')
262 szNext = GetNextElementW (lpszDisplayName, szElement, MAX_PATH);
263 /* make drive letter uppercase to enable PIDL comparison */
264 szElement[0] = toupper(szElement[0]);
265 pidlTemp = _ILCreateDrive (szElement);
268 if (szNext && *szNext)
270 hr = SHELL32_ParseNextElement (iface, hwndOwner, pbc, &pidlTemp,
271 (LPOLESTR) szNext, pchEaten, pdwAttributes);
273 else
275 if (pdwAttributes && *pdwAttributes)
276 SHELL32_GetItemAttributes (_IShellFolder_ (This),
277 pidlTemp, pdwAttributes);
278 hr = S_OK;
281 *ppidl = pidlTemp;
283 TRACE ("(%p)->(-- ret=0x%08x)\n", This, hr);
285 return hr;
288 /**************************************************************************
289 * CreateMyCompEnumList()
291 static const WCHAR MyComputer_NameSpaceW[] = { 'S','O','F','T','W','A','R','E',
292 '\\','M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
293 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\','E','x','p','l',
294 'o','r','e','r','\\','M','y','C','o','m','p','u','t','e','r','\\','N','a','m',
295 'e','s','p','a','c','e','\0' };
297 static BOOL CreateMyCompEnumList(IEnumIDList *list, DWORD dwFlags)
299 BOOL ret = TRUE;
301 TRACE("(%p)->(flags=0x%08x)\n", list, dwFlags);
303 /* enumerate the folders */
304 if (dwFlags & SHCONTF_FOLDERS)
306 WCHAR wszDriveName[] = {'A', ':', '\\', '\0'};
307 DWORD dwDrivemap = GetLogicalDrives();
308 HKEY hkey;
309 UINT i;
311 while (ret && wszDriveName[0]<='Z')
313 if(dwDrivemap & 0x00000001L)
314 ret = AddToEnumList(list, _ILCreateDrive(wszDriveName));
315 wszDriveName[0]++;
316 dwDrivemap = dwDrivemap >> 1;
319 TRACE("-- (%p)-> enumerate (mycomputer shell extensions)\n",list);
320 for (i=0; i<2; i++) {
321 if (ret && !RegOpenKeyExW(i == 0 ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER,
322 MyComputer_NameSpaceW, 0, KEY_READ, &hkey))
324 WCHAR iid[50];
325 int i=0;
327 while (ret)
329 DWORD size;
330 LONG r;
332 size = sizeof(iid) / sizeof(iid[0]);
333 r = RegEnumKeyExW(hkey, i, iid, &size, 0, NULL, NULL, NULL);
334 if (ERROR_SUCCESS == r)
336 /* FIXME: shell extensions, shouldn't the type be
337 * PT_SHELLEXT? */
338 ret = AddToEnumList(list, _ILCreateGuidFromStrW(iid));
339 i++;
341 else if (ERROR_NO_MORE_ITEMS == r)
342 break;
343 else
344 ret = FALSE;
346 RegCloseKey(hkey);
350 return ret;
353 /**************************************************************************
354 * ISF_MyComputer_fnEnumObjects
356 static HRESULT WINAPI ISF_MyComputer_fnEnumObjects (IShellFolder2 *iface,
357 HWND hwndOwner, DWORD dwFlags, LPENUMIDLIST *ppEnumIDList)
359 IGenericSFImpl *This = (IGenericSFImpl *)iface;
361 TRACE("(%p)->(HWND=%p flags=0x%08x pplist=%p)\n", This,
362 hwndOwner, dwFlags, ppEnumIDList);
364 *ppEnumIDList = IEnumIDList_Constructor();
365 if (*ppEnumIDList)
366 CreateMyCompEnumList(*ppEnumIDList, dwFlags);
368 TRACE ("-- (%p)->(new ID List: %p)\n", This, *ppEnumIDList);
370 return (*ppEnumIDList) ? S_OK : E_OUTOFMEMORY;
373 /**************************************************************************
374 * ISF_MyComputer_fnBindToObject
376 static HRESULT WINAPI ISF_MyComputer_fnBindToObject (IShellFolder2 *iface,
377 LPCITEMIDLIST pidl, LPBC pbcReserved, REFIID riid, LPVOID *ppvOut)
379 IGenericSFImpl *This = (IGenericSFImpl *)iface;
381 TRACE("(%p)->(pidl=%p,%p,%s,%p)\n", This,
382 pidl, pbcReserved, shdebugstr_guid (riid), ppvOut);
384 return SHELL32_BindToChild (This->pidlRoot, NULL, pidl, riid, ppvOut);
387 /**************************************************************************
388 * ISF_MyComputer_fnBindToStorage
390 static HRESULT WINAPI ISF_MyComputer_fnBindToStorage (IShellFolder2 * iface,
391 LPCITEMIDLIST pidl, LPBC pbcReserved, REFIID riid, LPVOID *ppvOut)
393 IGenericSFImpl *This = (IGenericSFImpl *)iface;
395 FIXME("(%p)->(pidl=%p,%p,%s,%p) stub\n", This,
396 pidl, pbcReserved, shdebugstr_guid (riid), ppvOut);
398 *ppvOut = NULL;
399 return E_NOTIMPL;
402 /**************************************************************************
403 * ISF_MyComputer_fnCompareIDs
406 static HRESULT WINAPI ISF_MyComputer_fnCompareIDs (IShellFolder2 *iface,
407 LPARAM lParam, LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
409 IGenericSFImpl *This = (IGenericSFImpl *)iface;
410 int nReturn;
412 TRACE ("(%p)->(0x%08lx,pidl1=%p,pidl2=%p)\n", This, lParam, pidl1, pidl2);
413 nReturn = SHELL32_CompareIDs (_IShellFolder_ (This), lParam, pidl1, pidl2);
414 TRACE ("-- %i\n", nReturn);
415 return nReturn;
418 /**************************************************************************
419 * ISF_MyComputer_fnCreateViewObject
421 static HRESULT WINAPI ISF_MyComputer_fnCreateViewObject (IShellFolder2 *iface,
422 HWND hwndOwner, REFIID riid, LPVOID * ppvOut)
424 IGenericSFImpl *This = (IGenericSFImpl *)iface;
425 LPSHELLVIEW pShellView;
426 HRESULT hr = E_INVALIDARG;
428 TRACE("(%p)->(hwnd=%p,%s,%p)\n", This,
429 hwndOwner, shdebugstr_guid (riid), ppvOut);
431 if (!ppvOut)
432 return hr;
434 *ppvOut = NULL;
436 if (IsEqualIID (riid, &IID_IDropTarget))
438 WARN ("IDropTarget not implemented\n");
439 hr = E_NOTIMPL;
441 else if (IsEqualIID (riid, &IID_IContextMenu))
443 WARN ("IContextMenu not implemented\n");
444 hr = E_NOTIMPL;
446 else if (IsEqualIID (riid, &IID_IShellView))
448 pShellView = IShellView_Constructor ((IShellFolder *) iface);
449 if (pShellView)
451 hr = IShellView_QueryInterface (pShellView, riid, ppvOut);
452 IShellView_Release (pShellView);
455 TRACE ("-- (%p)->(interface=%p)\n", This, ppvOut);
456 return hr;
459 /**************************************************************************
460 * ISF_MyComputer_fnGetAttributesOf
462 static HRESULT WINAPI ISF_MyComputer_fnGetAttributesOf (IShellFolder2 * iface,
463 UINT cidl, LPCITEMIDLIST * apidl, DWORD * rgfInOut)
465 IGenericSFImpl *This = (IGenericSFImpl *)iface;
466 HRESULT hr = S_OK;
468 TRACE ("(%p)->(cidl=%d apidl=%p mask=%p (0x%08x))\n",
469 This, cidl, apidl, rgfInOut, rgfInOut ? *rgfInOut : 0);
471 if (!rgfInOut)
472 return E_INVALIDARG;
473 if (cidl && !apidl)
474 return E_INVALIDARG;
476 if (*rgfInOut == 0)
477 *rgfInOut = ~0;
479 if(cidl == 0){
480 IShellFolder *psfParent = NULL;
481 LPCITEMIDLIST rpidl = NULL;
483 hr = SHBindToParent(This->pidlRoot, &IID_IShellFolder, (LPVOID*)&psfParent, (LPCITEMIDLIST*)&rpidl);
484 if(SUCCEEDED(hr)) {
485 SHELL32_GetItemAttributes (psfParent, rpidl, rgfInOut);
486 IShellFolder_Release(psfParent);
488 } else {
489 while (cidl > 0 && *apidl) {
490 pdump (*apidl);
491 SHELL32_GetItemAttributes (_IShellFolder_ (This), *apidl, rgfInOut);
492 apidl++;
493 cidl--;
496 /* make sure SFGAO_VALIDATE is cleared, some apps depend on that */
497 *rgfInOut &= ~SFGAO_VALIDATE;
499 TRACE ("-- result=0x%08x\n", *rgfInOut);
500 return hr;
503 /**************************************************************************
504 * ISF_MyComputer_fnGetUIObjectOf
506 * PARAMETERS
507 * hwndOwner [in] Parent window for any output
508 * cidl [in] array size
509 * apidl [in] simple pidl array
510 * riid [in] Requested Interface
511 * prgfInOut [ ] reserved
512 * ppvObject [out] Resulting Interface
515 static HRESULT WINAPI ISF_MyComputer_fnGetUIObjectOf (IShellFolder2 * iface,
516 HWND hwndOwner, UINT cidl, LPCITEMIDLIST * apidl, REFIID riid,
517 UINT * prgfInOut, LPVOID * ppvOut)
519 IGenericSFImpl *This = (IGenericSFImpl *)iface;
521 LPITEMIDLIST pidl;
522 IUnknown *pObj = NULL;
523 HRESULT hr = E_INVALIDARG;
525 TRACE("(%p)->(%p,%u,apidl=%p,%s,%p,%p)\n", This,
526 hwndOwner, cidl, apidl, shdebugstr_guid (riid), prgfInOut, ppvOut);
528 if (!ppvOut)
529 return hr;
531 *ppvOut = NULL;
533 if (IsEqualIID (riid, &IID_IContextMenu) && (cidl >= 1))
535 pObj = (LPUNKNOWN) ISvItemCm_Constructor ((IShellFolder *) iface,
536 This->pidlRoot, apidl, cidl);
537 hr = S_OK;
539 else if (IsEqualIID (riid, &IID_IDataObject) && (cidl >= 1))
541 pObj = (LPUNKNOWN) IDataObject_Constructor (hwndOwner,
542 This->pidlRoot, apidl, cidl);
543 hr = S_OK;
545 else if (IsEqualIID (riid, &IID_IExtractIconA) && (cidl == 1))
547 pidl = ILCombine (This->pidlRoot, apidl[0]);
548 pObj = (LPUNKNOWN) IExtractIconA_Constructor (pidl);
549 SHFree (pidl);
550 hr = S_OK;
552 else if (IsEqualIID (riid, &IID_IExtractIconW) && (cidl == 1))
554 pidl = ILCombine (This->pidlRoot, apidl[0]);
555 pObj = (LPUNKNOWN) IExtractIconW_Constructor (pidl);
556 SHFree (pidl);
557 hr = S_OK;
559 else if (IsEqualIID (riid, &IID_IDropTarget) && (cidl >= 1))
561 hr = IShellFolder_QueryInterface (iface, &IID_IDropTarget,
562 (LPVOID *) &pObj);
564 else if ((IsEqualIID(riid,&IID_IShellLinkW) ||
565 IsEqualIID(riid,&IID_IShellLinkA)) && (cidl == 1))
567 pidl = ILCombine (This->pidlRoot, apidl[0]);
568 hr = IShellLink_ConstructFromFile(NULL, riid, pidl, (LPVOID*) &pObj);
569 SHFree (pidl);
571 else
572 hr = E_NOINTERFACE;
574 if (SUCCEEDED(hr) && !pObj)
575 hr = E_OUTOFMEMORY;
577 *ppvOut = pObj;
578 TRACE ("(%p)->hr=0x%08x\n", This, hr);
579 return hr;
582 /**************************************************************************
583 * ISF_MyComputer_fnGetDisplayNameOf
585 static HRESULT WINAPI ISF_MyComputer_fnGetDisplayNameOf (IShellFolder2 *iface,
586 LPCITEMIDLIST pidl, DWORD dwFlags, LPSTRRET strRet)
588 IGenericSFImpl *This = (IGenericSFImpl *)iface;
590 LPWSTR pszPath;
591 HRESULT hr = S_OK;
593 TRACE ("(%p)->(pidl=%p,0x%08x,%p)\n", This, pidl, dwFlags, strRet);
594 pdump (pidl);
596 if (!strRet)
597 return E_INVALIDARG;
599 pszPath = CoTaskMemAlloc((MAX_PATH +1) * sizeof(WCHAR));
600 if (!pszPath)
601 return E_OUTOFMEMORY;
603 pszPath[0] = 0;
605 if (!pidl->mkid.cb)
607 /* parsing name like ::{...} */
608 pszPath[0] = ':';
609 pszPath[1] = ':';
610 SHELL32_GUIDToStringW(&CLSID_MyComputer, &pszPath[2]);
612 else if (_ILIsPidlSimple(pidl))
614 /* take names of special folders only if its only this folder */
615 if (_ILIsSpecialFolder(pidl))
617 GUID const *clsid;
619 clsid = _ILGetGUIDPointer (pidl);
620 if (clsid)
622 if (GET_SHGDN_FOR (dwFlags) & SHGDN_FORPARSING)
624 static const WCHAR clsidW[] =
625 { 'C','L','S','I','D','\\',0 };
626 static const WCHAR shellfolderW[] =
627 { '\\','s','h','e','l','l','f','o','l','d','e','r',0 };
628 static const WCHAR wantsForParsingW[] =
629 { 'W','a','n','t','s','F','o','r','P','a','r','s','i','n',
630 'g',0 };
631 int bWantsForParsing = FALSE;
632 WCHAR szRegPath[100];
633 LONG r;
636 * We can only get a filesystem path from a shellfolder
637 * if the value WantsFORPARSING exists in
638 * CLSID\\{...}\\shellfolder
639 * exception: the MyComputer folder has this keys not
640 * but like any filesystem backed
641 * folder it needs these behaviour
643 * Get the "WantsFORPARSING" flag from the registry
646 lstrcpyW (szRegPath, clsidW);
647 SHELL32_GUIDToStringW (clsid, &szRegPath[6]);
648 lstrcatW (szRegPath, shellfolderW);
649 r = SHGetValueW (HKEY_CLASSES_ROOT, szRegPath,
650 wantsForParsingW, NULL, NULL, NULL);
651 if (r == ERROR_SUCCESS)
652 bWantsForParsing = TRUE;
654 if ((GET_SHGDN_RELATION (dwFlags) == SHGDN_NORMAL) &&
655 bWantsForParsing)
658 * We need the filesystem path to the destination folder
659 * Only the folder itself can know it
661 hr = SHELL32_GetDisplayNameOfChild (iface, pidl,
662 dwFlags, pszPath, MAX_PATH);
664 else
666 LPWSTR p = pszPath;
668 /* parsing name like ::{...} */
669 p[0] = ':';
670 p[1] = ':';
671 p += 2;
672 p += SHELL32_GUIDToStringW(&CLSID_MyComputer, p);
674 p[0] = '\\';
675 p[1] = ':';
676 p[2] = ':';
677 p += 3;
678 SHELL32_GUIDToStringW(clsid, p);
681 else
683 /* user friendly name */
684 HCR_GetClassNameW (clsid, pszPath, MAX_PATH);
687 else
689 /* append my own path */
690 _ILSimpleGetTextW (pidl, pszPath, MAX_PATH);
693 else if (_ILIsDrive(pidl))
695 _ILSimpleGetTextW (pidl, pszPath, MAX_PATH); /* append my own path */
697 /* long view "lw_name (C:)" */
698 if (!(dwFlags & SHGDN_FORPARSING))
700 DWORD dwVolumeSerialNumber, dwMaximumComponetLength, dwFileSystemFlags;
701 WCHAR wszDrive[18] = {0};
702 static const WCHAR wszOpenBracket[] = {' ','(',0};
703 static const WCHAR wszCloseBracket[] = {')',0};
705 GetVolumeInformationW (pszPath, wszDrive,
706 sizeof(wszDrive)/sizeof(wszDrive[0]) - 6,
707 &dwVolumeSerialNumber,
708 &dwMaximumComponetLength, &dwFileSystemFlags, NULL, 0);
710 /* Display unix path if volume has no label */
711 if (!wszDrive[0])
713 char *unix_path;
714 char real_unix_path[PATH_MAX];
716 unix_path = wine_get_unix_file_name(pszPath);
717 if (unix_path)
719 realpath(unix_path, real_unix_path);
720 HeapFree( GetProcessHeap(), 0, unix_path );
721 MultiByteToWideChar(CP_UNIXCP, 0, real_unix_path, -1, wszDrive, sizeof(wszDrive)/sizeof(wszDrive[0]));
722 wszDrive[sizeof(wszDrive)/sizeof(wszDrive[0])-1] = '\0';
726 strcatW (wszDrive, wszOpenBracket);
728 if (SHELL32_DisplayUnixPaths())
730 char *unix_path;
731 char real_unix_path[PATH_MAX];
733 unix_path = wine_get_unix_file_name(pszPath);
734 if (unix_path)
736 realpath(unix_path, real_unix_path);
737 HeapFree( GetProcessHeap(), 0, unix_path );
738 MultiByteToWideChar(CP_UNIXCP, 0, real_unix_path, -1, wszDrive, sizeof(wszDrive)/sizeof(wszDrive[0]));
739 wszDrive[sizeof(wszDrive)/sizeof(wszDrive[0])-1] = '\0';
742 else
743 lstrcpynW (wszDrive + strlenW(wszDrive), pszPath, 3);
745 strcatW (wszDrive, wszCloseBracket);
746 strcpyW (pszPath, wszDrive);
749 else
751 /* Neither a shell namespace extension nor a drive letter. */
752 ERR("Wrong pidl type\n");
753 return E_INVALIDARG;
756 else
758 /* Complex pidl. Let the child folder do the work */
759 hr = SHELL32_GetDisplayNameOfChild(iface, pidl, dwFlags, pszPath, MAX_PATH);
762 if (SUCCEEDED (hr))
764 /* Win9x always returns ANSI strings, NT always returns Unicode strings */
765 if (GetVersion() & 0x80000000)
767 strRet->uType = STRRET_CSTR;
768 if (!WideCharToMultiByte(CP_ACP, 0, pszPath, -1, strRet->u.cStr, MAX_PATH,
769 NULL, NULL))
770 strRet->u.cStr[0] = '\0';
771 CoTaskMemFree(pszPath);
773 else
775 strRet->uType = STRRET_WSTR;
776 strRet->u.pOleStr = pszPath;
779 else
780 CoTaskMemFree(pszPath);
782 TRACE ("-- (%p)->(%s)\n", This, strRet->uType == STRRET_CSTR ? strRet->u.cStr : debugstr_w(strRet->u.pOleStr));
783 return hr;
786 /**************************************************************************
787 * ISF_MyComputer_fnSetNameOf
788 * Changes the name of a file object or subfolder, possibly changing its item
789 * identifier in the process.
791 * PARAMETERS
792 * hwndOwner [in] Owner window for output
793 * pidl [in] simple pidl of item to change
794 * lpszName [in] the items new display name
795 * dwFlags [in] SHGNO formatting flags
796 * ppidlOut [out] simple pidl returned
798 static HRESULT WINAPI ISF_MyComputer_fnSetNameOf (
799 IShellFolder2 * iface, HWND hwndOwner, LPCITEMIDLIST pidl,
800 LPCOLESTR lpName, DWORD dwFlags, LPITEMIDLIST * pPidlOut)
802 IGenericSFImpl *This = (IGenericSFImpl *)iface;
803 FIXME ("(%p)->(%p,pidl=%p,%s,%u,%p)\n", This,
804 hwndOwner, pidl, debugstr_w (lpName), dwFlags, pPidlOut);
805 return E_FAIL;
808 static HRESULT WINAPI ISF_MyComputer_fnGetDefaultSearchGUID (
809 IShellFolder2 * iface, GUID * pguid)
811 IGenericSFImpl *This = (IGenericSFImpl *)iface;
812 FIXME ("(%p)\n", This);
813 return E_NOTIMPL;
815 static HRESULT WINAPI ISF_MyComputer_fnEnumSearches (
816 IShellFolder2 * iface, IEnumExtraSearch ** ppenum)
818 IGenericSFImpl *This = (IGenericSFImpl *)iface;
819 FIXME ("(%p)\n", This);
820 return E_NOTIMPL;
822 static HRESULT WINAPI ISF_MyComputer_fnGetDefaultColumn (
823 IShellFolder2 *iface, DWORD dwRes, ULONG *pSort, ULONG *pDisplay)
825 IGenericSFImpl *This = (IGenericSFImpl *)iface;
827 TRACE ("(%p)\n", This);
829 if (pSort)
830 *pSort = 0;
831 if (pDisplay)
832 *pDisplay = 0;
833 return S_OK;
835 static HRESULT WINAPI ISF_MyComputer_fnGetDefaultColumnState (
836 IShellFolder2 * iface, UINT iColumn, DWORD * pcsFlags)
838 IGenericSFImpl *This = (IGenericSFImpl *)iface;
840 TRACE ("(%p)\n", This);
842 if (!pcsFlags || iColumn >= MYCOMPUTERSHELLVIEWCOLUMNS)
843 return E_INVALIDARG;
844 *pcsFlags = MyComputerSFHeader[iColumn].pcsFlags;
845 return S_OK;
848 static HRESULT WINAPI ISF_MyComputer_fnGetDetailsEx (IShellFolder2 * iface,
849 LPCITEMIDLIST pidl, const SHCOLUMNID * pscid, VARIANT * pv)
851 IGenericSFImpl *This = (IGenericSFImpl *)iface;
852 FIXME ("(%p)\n", This);
853 return E_NOTIMPL;
856 /* FIXME: drive size >4GB is rolling over */
857 static HRESULT WINAPI ISF_MyComputer_fnGetDetailsOf (IShellFolder2 * iface,
858 LPCITEMIDLIST pidl, UINT iColumn, SHELLDETAILS * psd)
860 IGenericSFImpl *This = (IGenericSFImpl *)iface;
861 HRESULT hr;
863 TRACE ("(%p)->(%p %i %p)\n", This, pidl, iColumn, psd);
865 if (!psd || iColumn >= MYCOMPUTERSHELLVIEWCOLUMNS)
866 return E_INVALIDARG;
868 if (!pidl)
870 psd->fmt = MyComputerSFHeader[iColumn].fmt;
871 psd->cxChar = MyComputerSFHeader[iColumn].cxChar;
872 psd->str.uType = STRRET_CSTR;
873 LoadStringA (shell32_hInstance, MyComputerSFHeader[iColumn].colnameid,
874 psd->str.u.cStr, MAX_PATH);
875 return S_OK;
877 else
879 char szPath[MAX_PATH];
880 ULARGE_INTEGER ulBytes;
882 psd->str.u.cStr[0] = 0x00;
883 psd->str.uType = STRRET_CSTR;
884 switch (iColumn)
886 case 0: /* name */
887 hr = IShellFolder_GetDisplayNameOf (iface, pidl,
888 SHGDN_NORMAL | SHGDN_INFOLDER, &psd->str);
889 break;
890 case 1: /* type */
891 _ILGetFileType (pidl, psd->str.u.cStr, MAX_PATH);
892 break;
893 case 2: /* total size */
894 if (_ILIsDrive (pidl))
896 _ILSimpleGetText (pidl, szPath, MAX_PATH);
897 GetDiskFreeSpaceExA (szPath, NULL, &ulBytes, NULL);
898 StrFormatByteSizeA (ulBytes.u.LowPart, psd->str.u.cStr, MAX_PATH);
900 break;
901 case 3: /* free size */
902 if (_ILIsDrive (pidl))
904 _ILSimpleGetText (pidl, szPath, MAX_PATH);
905 GetDiskFreeSpaceExA (szPath, &ulBytes, NULL, NULL);
906 StrFormatByteSizeA (ulBytes.u.LowPart, psd->str.u.cStr, MAX_PATH);
908 break;
910 hr = S_OK;
913 return hr;
916 static HRESULT WINAPI ISF_MyComputer_fnMapColumnToSCID (
917 IShellFolder2 * iface, UINT column, SHCOLUMNID * pscid)
919 IGenericSFImpl *This = (IGenericSFImpl *)iface;
920 FIXME ("(%p)\n", This);
921 return E_NOTIMPL;
924 static const IShellFolder2Vtbl vt_ShellFolder2 =
926 ISF_MyComputer_fnQueryInterface,
927 ISF_MyComputer_fnAddRef,
928 ISF_MyComputer_fnRelease,
929 ISF_MyComputer_fnParseDisplayName,
930 ISF_MyComputer_fnEnumObjects,
931 ISF_MyComputer_fnBindToObject,
932 ISF_MyComputer_fnBindToStorage,
933 ISF_MyComputer_fnCompareIDs,
934 ISF_MyComputer_fnCreateViewObject,
935 ISF_MyComputer_fnGetAttributesOf,
936 ISF_MyComputer_fnGetUIObjectOf,
937 ISF_MyComputer_fnGetDisplayNameOf,
938 ISF_MyComputer_fnSetNameOf,
939 /* ShellFolder2 */
940 ISF_MyComputer_fnGetDefaultSearchGUID,
941 ISF_MyComputer_fnEnumSearches,
942 ISF_MyComputer_fnGetDefaultColumn,
943 ISF_MyComputer_fnGetDefaultColumnState,
944 ISF_MyComputer_fnGetDetailsEx,
945 ISF_MyComputer_fnGetDetailsOf,
946 ISF_MyComputer_fnMapColumnToSCID
949 /************************************************************************
950 * IMCFldr_PersistFolder2_QueryInterface
952 static HRESULT WINAPI IMCFldr_PersistFolder2_QueryInterface (
953 IPersistFolder2 * iface, REFIID iid, LPVOID * ppvObj)
955 IGenericSFImpl *This = impl_from_IPersistFolder2(iface);
957 TRACE ("(%p)\n", This);
959 return IUnknown_QueryInterface (_IUnknown_ (This), iid, ppvObj);
962 /************************************************************************
963 * IMCFldr_PersistFolder2_AddRef
965 static ULONG WINAPI IMCFldr_PersistFolder2_AddRef (IPersistFolder2 * iface)
967 IGenericSFImpl *This = impl_from_IPersistFolder2(iface);
969 TRACE ("(%p)->(count=%u)\n", This, This->ref);
971 return IUnknown_AddRef (_IUnknown_ (This));
974 /************************************************************************
975 * ISFPersistFolder_Release
977 static ULONG WINAPI IMCFldr_PersistFolder2_Release (IPersistFolder2 * iface)
979 IGenericSFImpl *This = impl_from_IPersistFolder2(iface);
981 TRACE ("(%p)->(count=%u)\n", This, This->ref);
983 return IUnknown_Release (_IUnknown_ (This));
986 /************************************************************************
987 * IMCFldr_PersistFolder2_GetClassID
989 static HRESULT WINAPI IMCFldr_PersistFolder2_GetClassID (
990 IPersistFolder2 * iface, CLSID * lpClassId)
992 IGenericSFImpl *This = impl_from_IPersistFolder2(iface);
994 TRACE ("(%p)\n", This);
996 if (!lpClassId)
997 return E_POINTER;
998 *lpClassId = CLSID_MyComputer;
1000 return S_OK;
1003 /************************************************************************
1004 * IMCFldr_PersistFolder2_Initialize
1006 * NOTES: it makes no sense to change the pidl
1008 static HRESULT WINAPI IMCFldr_PersistFolder2_Initialize (
1009 IPersistFolder2 * iface, LPCITEMIDLIST pidl)
1011 IGenericSFImpl *This = impl_from_IPersistFolder2(iface);
1012 TRACE ("(%p)->(%p)\n", This, pidl);
1013 return E_NOTIMPL;
1016 /**************************************************************************
1017 * IPersistFolder2_fnGetCurFolder
1019 static HRESULT WINAPI IMCFldr_PersistFolder2_GetCurFolder (
1020 IPersistFolder2 * iface, LPITEMIDLIST * pidl)
1022 IGenericSFImpl *This = impl_from_IPersistFolder2(iface);
1024 TRACE ("(%p)->(%p)\n", This, pidl);
1026 if (!pidl)
1027 return E_POINTER;
1028 *pidl = ILClone (This->pidlRoot);
1029 return S_OK;
1032 static const IPersistFolder2Vtbl vt_PersistFolder2 =
1034 IMCFldr_PersistFolder2_QueryInterface,
1035 IMCFldr_PersistFolder2_AddRef,
1036 IMCFldr_PersistFolder2_Release,
1037 IMCFldr_PersistFolder2_GetClassID,
1038 IMCFldr_PersistFolder2_Initialize,
1039 IMCFldr_PersistFolder2_GetCurFolder