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
24 WINE_DEFAULT_DEBUG_CHANNEL (shell
);
26 /***********************************************************************
27 * IShellFolder implementation
31 const IShellFolder2Vtbl
*lpVtbl
;
33 const IPersistFolder2Vtbl
*lpVtblPersistFolder2
;
35 /* both paths are parsible from the desktop */
36 LPITEMIDLIST pidlRoot
; /* absolute pidl */
38 } IGenericSFImpl
, *LPIGenericSFImpl
;
40 static const IShellFolder2Vtbl vt_ShellFolder2
;
41 static const IPersistFolder2Vtbl vt_PersistFolder2
;
43 static LPIGenericSFImpl __inline
impl_from_IPersistFolder2( IPersistFolder2
*iface
)
45 return (LPIGenericSFImpl
)((char*)iface
- FIELD_OFFSET(IGenericSFImpl
, lpVtblPersistFolder2
));
50 converts This to an interface pointer
52 #define _IUnknown_(This) (IUnknown*)&(This->lpVtbl)
53 #define _IShellFolder_(This) (IShellFolder*)&(This->lpVtbl)
54 #define _IShellFolder2_(This) (IShellFolder2*)&(This->lpVtbl)
56 #define _IPersist_(This) (IPersist*)&(This->lpVtblPersistFolder2)
57 #define _IPersistFolder_(This) (IPersistFolder*)&(This->lpVtblPersistFolder2)
58 #define _IPersistFolder2_(This) (IPersistFolder2*)&(This->lpVtblPersistFolder2)
60 /***********************************************************************
61 * IShellFolder [MyComputer] implementation
64 static const shvheader MyComputerSFHeader
[] = {
65 {IDS_SHV_COLUMN1
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 15},
66 {IDS_SHV_COLUMN3
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 10},
67 {IDS_SHV_COLUMN6
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 10},
68 {IDS_SHV_COLUMN7
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 10},
71 #define MYCOMPUTERSHELLVIEWCOLUMNS 4
73 /**************************************************************************
74 * ISF_MyComputer_Constructor
76 HRESULT WINAPI
ISF_MyComputer_Constructor (IUnknown
* pUnkOuter
, REFIID riid
, LPVOID
* ppv
)
80 WCHAR szName
[MAX_PATH
];
81 TRACE ("unkOut=%p %s\n", pUnkOuter
, shdebugstr_guid (riid
));
86 return CLASS_E_NOAGGREGATION
;
88 sf
= LocalAlloc (LMEM_ZEROINIT
, sizeof (IGenericSFImpl
));
93 sf
->lpVtbl
= &vt_ShellFolder2
;
94 sf
->lpVtblPersistFolder2
= &vt_PersistFolder2
;
95 sf
->pidlRoot
= _ILCreateMyComputer (); /* my qualified pidl */
97 if (FAILED (IUnknown_QueryInterface (_IUnknown_ (sf
), riid
, ppv
)))
99 IUnknown_Release (_IUnknown_ (sf
));
100 return E_NOINTERFACE
;
103 dwSize
= sizeof(szName
);
104 if (RegGetValueW(HKEY_CURRENT_USER
,
105 L
"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\CLSID\\{20D04FE0-3AEA-1069-A2D8-08002B30309D}",
110 &dwSize
) == ERROR_SUCCESS
)
112 szName
[MAX_PATH
-1] = 0;
113 sf
->sName
= SHAlloc((wcslen(szName
)+1) * sizeof(WCHAR
));
116 wcscpy( sf
->sName
, szName
);
118 TRACE("sName %s\n", debugstr_w(sf
->sName
));
121 TRACE ("--(%p)\n", sf
);
125 /**************************************************************************
126 * ISF_MyComputer_fnQueryInterface
128 * NOTES supports not IPersist/IPersistFolder
130 static HRESULT WINAPI
ISF_MyComputer_fnQueryInterface (IShellFolder2
*iface
,
131 REFIID riid
, LPVOID
*ppvObj
)
133 IGenericSFImpl
*This
= (IGenericSFImpl
*)iface
;
135 TRACE ("(%p)->(%s,%p)\n", This
, shdebugstr_guid (riid
), ppvObj
);
139 if (IsEqualIID (riid
, &IID_IUnknown
) ||
140 IsEqualIID (riid
, &IID_IShellFolder
) ||
141 IsEqualIID (riid
, &IID_IShellFolder2
))
145 else if (IsEqualIID (riid
, &IID_IPersist
) ||
146 IsEqualIID (riid
, &IID_IPersistFolder
) ||
147 IsEqualIID (riid
, &IID_IPersistFolder2
))
149 *ppvObj
= _IPersistFolder2_ (This
);
154 IUnknown_AddRef ((IUnknown
*) (*ppvObj
));
155 TRACE ("-- Interface: (%p)->(%p)\n", ppvObj
, *ppvObj
);
158 TRACE ("-- Interface: E_NOINTERFACE\n");
159 return E_NOINTERFACE
;
162 static ULONG WINAPI
ISF_MyComputer_fnAddRef (IShellFolder2
* iface
)
164 IGenericSFImpl
*This
= (IGenericSFImpl
*)iface
;
165 ULONG refCount
= InterlockedIncrement(&This
->ref
);
167 TRACE ("(%p)->(count=%u)\n", This
, refCount
- 1);
172 static ULONG WINAPI
ISF_MyComputer_fnRelease (IShellFolder2
* iface
)
174 IGenericSFImpl
*This
= (IGenericSFImpl
*)iface
;
175 ULONG refCount
= InterlockedDecrement(&This
->ref
);
177 TRACE ("(%p)->(count=%u)\n", This
, refCount
+ 1);
181 TRACE ("-- destroying IShellFolder(%p)\n", This
);
182 SHFree (This
->pidlRoot
);
188 /**************************************************************************
189 * ISF_MyComputer_fnParseDisplayName
191 static HRESULT WINAPI
ISF_MyComputer_fnParseDisplayName (IShellFolder2
*iface
,
192 HWND hwndOwner
, LPBC pbc
, LPOLESTR lpszDisplayName
,
193 DWORD
* pchEaten
, LPITEMIDLIST
* ppidl
, DWORD
* pdwAttributes
)
195 IGenericSFImpl
*This
= (IGenericSFImpl
*)iface
;
196 HRESULT hr
= E_INVALIDARG
;
197 LPCWSTR szNext
= NULL
;
198 WCHAR szElement
[MAX_PATH
];
199 LPITEMIDLIST pidlTemp
= NULL
;
202 TRACE("(%p)->(HWND=%p,%p,%p=%s,%p,pidl=%p,%p)\n", This
,
203 hwndOwner
, pbc
, lpszDisplayName
, debugstr_w (lpszDisplayName
),
204 pchEaten
, ppidl
, pdwAttributes
);
208 *pchEaten
= 0; /* strange but like the original */
210 /* handle CLSID paths */
211 if (lpszDisplayName
[0] == ':' && lpszDisplayName
[1] == ':')
213 szNext
= GetNextElementW (lpszDisplayName
, szElement
, MAX_PATH
);
214 TRACE ("-- element: %s\n", debugstr_w (szElement
));
215 CLSIDFromString (szElement
+ 2, &clsid
);
216 pidlTemp
= _ILCreateGuid (PT_GUID
, &clsid
);
218 /* do we have an absolute path name ? */
219 else if (PathGetDriveNumberW (lpszDisplayName
) >= 0 &&
220 lpszDisplayName
[2] == (WCHAR
) '\\')
222 szNext
= GetNextElementW (lpszDisplayName
, szElement
, MAX_PATH
);
223 /* make drive letter uppercase to enable PIDL comparison */
224 szElement
[0] = toupper(szElement
[0]);
225 pidlTemp
= _ILCreateDrive (szElement
);
228 if (szNext
&& *szNext
)
230 hr
= SHELL32_ParseNextElement (iface
, hwndOwner
, pbc
, &pidlTemp
,
231 (LPOLESTR
) szNext
, pchEaten
, pdwAttributes
);
235 if (pdwAttributes
&& *pdwAttributes
)
236 SHELL32_GetItemAttributes (_IShellFolder_ (This
),
237 pidlTemp
, pdwAttributes
);
243 TRACE ("(%p)->(-- ret=0x%08x)\n", This
, hr
);
248 /**************************************************************************
249 * CreateMyCompEnumList()
251 static const WCHAR MyComputer_NameSpaceW
[] = { 'S','O','F','T','W','A','R','E',
252 '\\','M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
253 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\','E','x','p','l',
254 'o','r','e','r','\\','M','y','C','o','m','p','u','t','e','r','\\','N','a','m',
255 'e','s','p','a','c','e','\0' };
257 static BOOL
CreateMyCompEnumList(IEnumIDList
*list
, DWORD dwFlags
)
261 TRACE("(%p)->(flags=0x%08x)\n", list
, dwFlags
);
263 /* enumerate the folders */
264 if (dwFlags
& SHCONTF_FOLDERS
)
266 WCHAR wszDriveName
[] = {'A', ':', '\\', '\0'};
267 DWORD dwDrivemap
= GetLogicalDrives();
271 while (ret
&& wszDriveName
[0]<='Z')
273 if(dwDrivemap
& 0x00000001L
)
274 ret
= AddToEnumList(list
, _ILCreateDrive(wszDriveName
));
276 dwDrivemap
= dwDrivemap
>> 1;
279 TRACE("-- (%p)-> enumerate (mycomputer shell extensions)\n",list
);
280 for (i
=0; i
<2; i
++) {
281 if (ret
&& !RegOpenKeyExW(i
== 0 ? HKEY_LOCAL_MACHINE
: HKEY_CURRENT_USER
,
282 MyComputer_NameSpaceW
, 0, KEY_READ
, &hkey
))
292 size
= sizeof(iid
) / sizeof(iid
[0]);
293 r
= RegEnumKeyExW(hkey
, i
, iid
, &size
, 0, NULL
, NULL
, NULL
);
294 if (ERROR_SUCCESS
== r
)
296 /* FIXME: shell extensions, shouldn't the type be
298 ret
= AddToEnumList(list
, _ILCreateGuidFromStrW(iid
));
301 else if (ERROR_NO_MORE_ITEMS
== r
)
313 /**************************************************************************
314 * ISF_MyComputer_fnEnumObjects
316 static HRESULT WINAPI
ISF_MyComputer_fnEnumObjects (IShellFolder2
*iface
,
317 HWND hwndOwner
, DWORD dwFlags
, LPENUMIDLIST
*ppEnumIDList
)
319 IGenericSFImpl
*This
= (IGenericSFImpl
*)iface
;
321 TRACE("(%p)->(HWND=%p flags=0x%08x pplist=%p)\n", This
,
322 hwndOwner
, dwFlags
, ppEnumIDList
);
324 *ppEnumIDList
= IEnumIDList_Constructor();
326 CreateMyCompEnumList(*ppEnumIDList
, dwFlags
);
328 TRACE ("-- (%p)->(new ID List: %p)\n", This
, *ppEnumIDList
);
330 return (*ppEnumIDList
) ? S_OK
: E_OUTOFMEMORY
;
333 /**************************************************************************
334 * ISF_MyComputer_fnBindToObject
336 static HRESULT WINAPI
ISF_MyComputer_fnBindToObject (IShellFolder2
*iface
,
337 LPCITEMIDLIST pidl
, LPBC pbcReserved
, REFIID riid
, LPVOID
*ppvOut
)
339 IGenericSFImpl
*This
= (IGenericSFImpl
*)iface
;
341 TRACE("(%p)->(pidl=%p,%p,%s,%p)\n", This
,
342 pidl
, pbcReserved
, shdebugstr_guid (riid
), ppvOut
);
344 return SHELL32_BindToChild (This
->pidlRoot
, NULL
, pidl
, riid
, ppvOut
);
347 /**************************************************************************
348 * ISF_MyComputer_fnBindToStorage
350 static HRESULT WINAPI
ISF_MyComputer_fnBindToStorage (IShellFolder2
* iface
,
351 LPCITEMIDLIST pidl
, LPBC pbcReserved
, REFIID riid
, LPVOID
*ppvOut
)
353 IGenericSFImpl
*This
= (IGenericSFImpl
*)iface
;
355 FIXME("(%p)->(pidl=%p,%p,%s,%p) stub\n", This
,
356 pidl
, pbcReserved
, shdebugstr_guid (riid
), ppvOut
);
362 /**************************************************************************
363 * ISF_MyComputer_fnCompareIDs
366 static HRESULT WINAPI
ISF_MyComputer_fnCompareIDs (IShellFolder2
*iface
,
367 LPARAM lParam
, LPCITEMIDLIST pidl1
, LPCITEMIDLIST pidl2
)
369 IGenericSFImpl
*This
= (IGenericSFImpl
*)iface
;
372 TRACE ("(%p)->(0x%08lx,pidl1=%p,pidl2=%p)\n", This
, lParam
, pidl1
, pidl2
);
373 nReturn
= SHELL32_CompareIDs (_IShellFolder_ (This
), lParam
, pidl1
, pidl2
);
374 TRACE ("-- %i\n", nReturn
);
378 /**************************************************************************
379 * ISF_MyComputer_fnCreateViewObject
381 static HRESULT WINAPI
ISF_MyComputer_fnCreateViewObject (IShellFolder2
*iface
,
382 HWND hwndOwner
, REFIID riid
, LPVOID
* ppvOut
)
384 IGenericSFImpl
*This
= (IGenericSFImpl
*)iface
;
385 LPSHELLVIEW pShellView
;
386 HRESULT hr
= E_INVALIDARG
;
388 TRACE("(%p)->(hwnd=%p,%s,%p)\n", This
,
389 hwndOwner
, shdebugstr_guid (riid
), ppvOut
);
396 if (IsEqualIID (riid
, &IID_IDropTarget
))
398 WARN ("IDropTarget not implemented\n");
401 else if (IsEqualIID (riid
, &IID_IContextMenu
))
403 WARN ("IContextMenu not implemented\n");
406 else if (IsEqualIID (riid
, &IID_IShellView
))
408 pShellView
= IShellView_Constructor ((IShellFolder
*) iface
);
411 hr
= IShellView_QueryInterface (pShellView
, riid
, ppvOut
);
412 IShellView_Release (pShellView
);
415 TRACE ("-- (%p)->(interface=%p)\n", This
, ppvOut
);
419 /**************************************************************************
420 * ISF_MyComputer_fnGetAttributesOf
422 static HRESULT WINAPI
ISF_MyComputer_fnGetAttributesOf (IShellFolder2
* iface
,
423 UINT cidl
, LPCITEMIDLIST
* apidl
, DWORD
* rgfInOut
)
425 IGenericSFImpl
*This
= (IGenericSFImpl
*)iface
;
427 static const DWORD dwComputerAttributes
=
428 SFGAO_STORAGE
| SFGAO_HASPROPSHEET
| SFGAO_STORAGEANCESTOR
| SFGAO_CANCOPY
|
429 SFGAO_FILESYSANCESTOR
| SFGAO_FOLDER
| SFGAO_FILESYSTEM
| SFGAO_HASSUBFOLDER
| SFGAO_CANRENAME
| SFGAO_CANDELETE
;
431 TRACE ("(%p)->(cidl=%d apidl=%p mask=%p (0x%08x))\n",
432 This
, cidl
, apidl
, rgfInOut
, rgfInOut
? *rgfInOut
: 0);
443 *rgfInOut
&= dwComputerAttributes
;
445 while (cidl
> 0 && *apidl
) {
447 SHELL32_GetItemAttributes (_IShellFolder_ (This
), *apidl
, rgfInOut
);
452 /* make sure SFGAO_VALIDATE is cleared, some apps depend on that */
453 *rgfInOut
&= ~SFGAO_VALIDATE
;
455 TRACE ("-- result=0x%08x\n", *rgfInOut
);
459 /**************************************************************************
460 * ISF_MyComputer_fnGetUIObjectOf
463 * hwndOwner [in] Parent window for any output
464 * cidl [in] array size
465 * apidl [in] simple pidl array
466 * riid [in] Requested Interface
467 * prgfInOut [ ] reserved
468 * ppvObject [out] Resulting Interface
471 static HRESULT WINAPI
ISF_MyComputer_fnGetUIObjectOf (IShellFolder2
* iface
,
472 HWND hwndOwner
, UINT cidl
, LPCITEMIDLIST
* apidl
, REFIID riid
,
473 UINT
* prgfInOut
, LPVOID
* ppvOut
)
475 IGenericSFImpl
*This
= (IGenericSFImpl
*)iface
;
478 IUnknown
*pObj
= NULL
;
479 HRESULT hr
= E_INVALIDARG
;
481 TRACE("(%p)->(%p,%u,apidl=%p,%s,%p,%p)\n", This
,
482 hwndOwner
, cidl
, apidl
, shdebugstr_guid (riid
), prgfInOut
, ppvOut
);
489 if (IsEqualIID (riid
, &IID_IContextMenu
) && (cidl
>= 1))
491 hr
= CDefFolderMenu_Create2(This
->pidlRoot
, hwndOwner
, cidl
, apidl
, (IShellFolder
*)iface
, NULL
, 0, NULL
, (IContextMenu
**)&pObj
);
493 else if (IsEqualIID (riid
, &IID_IDataObject
) && (cidl
>= 1))
495 pObj
= (LPUNKNOWN
) IDataObject_Constructor (hwndOwner
,
496 This
->pidlRoot
, apidl
, cidl
);
499 else if (IsEqualIID (riid
, &IID_IExtractIconA
) && (cidl
== 1))
501 pidl
= ILCombine (This
->pidlRoot
, apidl
[0]);
502 pObj
= (LPUNKNOWN
) IExtractIconA_Constructor (pidl
);
506 else if (IsEqualIID (riid
, &IID_IExtractIconW
) && (cidl
== 1))
508 pidl
= ILCombine (This
->pidlRoot
, apidl
[0]);
509 pObj
= (LPUNKNOWN
) IExtractIconW_Constructor (pidl
);
513 else if (IsEqualIID (riid
, &IID_IDropTarget
) && (cidl
>= 1))
515 hr
= IShellFolder_QueryInterface (iface
, &IID_IDropTarget
,
518 else if ((IsEqualIID(riid
,&IID_IShellLinkW
) ||
519 IsEqualIID(riid
,&IID_IShellLinkA
)) && (cidl
== 1))
521 pidl
= ILCombine (This
->pidlRoot
, apidl
[0]);
522 hr
= IShellLink_ConstructFromFile(NULL
, riid
, pidl
, (LPVOID
*) &pObj
);
528 if (SUCCEEDED(hr
) && !pObj
)
532 TRACE ("(%p)->hr=0x%08x\n", This
, hr
);
536 /**************************************************************************
537 * ISF_MyComputer_fnGetDisplayNameOf
539 static HRESULT WINAPI
ISF_MyComputer_fnGetDisplayNameOf (IShellFolder2
*iface
,
540 LPCITEMIDLIST pidl
, DWORD dwFlags
, LPSTRRET strRet
)
542 IGenericSFImpl
*This
= (IGenericSFImpl
*)iface
;
547 TRACE ("(%p)->(pidl=%p,0x%08x,%p)\n", This
, pidl
, dwFlags
, strRet
);
553 pszPath
= CoTaskMemAlloc((MAX_PATH
+1) * sizeof(WCHAR
));
555 return E_OUTOFMEMORY
;
561 /* parsing name like ::{...} */
564 SHELL32_GUIDToStringW(&CLSID_MyComputer
, &pszPath
[2]);
566 else if (_ILIsPidlSimple(pidl
))
568 /* take names of special folders only if its only this folder */
569 if (_ILIsSpecialFolder(pidl
))
573 clsid
= _ILGetGUIDPointer (pidl
);
576 if (GET_SHGDN_FOR (dwFlags
) & SHGDN_FORPARSING
)
578 static const WCHAR clsidW
[] =
579 { 'C','L','S','I','D','\\',0 };
580 static const WCHAR shellfolderW
[] =
581 { '\\','s','h','e','l','l','f','o','l','d','e','r',0 };
582 static const WCHAR wantsForParsingW
[] =
583 { 'W','a','n','t','s','F','o','r','P','a','r','s','i','n',
585 int bWantsForParsing
= FALSE
;
586 WCHAR szRegPath
[100];
590 * We can only get a filesystem path from a shellfolder
591 * if the value WantsFORPARSING exists in
592 * CLSID\\{...}\\shellfolder
593 * exception: the MyComputer folder has this keys not
594 * but like any filesystem backed
595 * folder it needs these behaviour
597 * Get the "WantsFORPARSING" flag from the registry
600 wcscpy (szRegPath
, clsidW
);
601 SHELL32_GUIDToStringW (clsid
, &szRegPath
[6]);
602 wcscat (szRegPath
, shellfolderW
);
603 r
= SHGetValueW (HKEY_CLASSES_ROOT
, szRegPath
,
604 wantsForParsingW
, NULL
, NULL
, NULL
);
605 if (r
== ERROR_SUCCESS
)
606 bWantsForParsing
= TRUE
;
608 if ((GET_SHGDN_RELATION (dwFlags
) == SHGDN_NORMAL
) &&
612 * We need the filesystem path to the destination folder
613 * Only the folder itself can know it
615 hr
= SHELL32_GetDisplayNameOfChild (iface
, pidl
,
616 dwFlags
, pszPath
, MAX_PATH
);
622 /* parsing name like ::{...} */
626 p
+= SHELL32_GUIDToStringW(&CLSID_MyComputer
, p
);
633 SHELL32_GUIDToStringW(clsid
, p
);
638 /* user friendly name */
640 if (_ILIsMyComputer(pidl
) && This
->sName
)
641 wcscpy(pszPath
, This
->sName
);
643 HCR_GetClassNameW (clsid
, pszPath
, MAX_PATH
);
645 TRACE("pszPath %s\n", debugstr_w(pszPath
));
650 /* append my own path */
651 _ILSimpleGetTextW (pidl
, pszPath
, MAX_PATH
);
654 else if (_ILIsDrive(pidl
))
657 _ILSimpleGetTextW (pidl
, pszPath
, MAX_PATH
); /* append my own path */
658 /* long view "lw_name (C:)" */
659 if (!(dwFlags
& SHGDN_FORPARSING
))
661 WCHAR wszDrive
[18] = {0};
662 DWORD dwVolumeSerialNumber
, dwMaximumComponentLength
, dwFileSystemFlags
;
663 static const WCHAR wszOpenBracket
[] = {' ','(',0};
664 static const WCHAR wszCloseBracket
[] = {')',0};
666 lstrcpynW(wszDrive
, pszPath
, 4);
668 GetVolumeInformationW (wszDrive
, pszPath
,
670 &dwVolumeSerialNumber
,
671 &dwMaximumComponentLength
, &dwFileSystemFlags
, NULL
, 0);
672 pszPath
[MAX_PATH
-1] = L
'\0';
673 if (!wcslen(pszPath
))
675 UINT DriveType
, ResourceId
;
676 DriveType
= GetDriveTypeW(wszDrive
);
680 ResourceId
= IDS_DRIVE_FIXED
;
683 ResourceId
= IDS_DRIVE_NETWORK
;
686 ResourceId
= IDS_DRIVE_CDROM
;
693 dwFileSystemFlags
= LoadStringW(shell32_hInstance
, ResourceId
, pszPath
, MAX_PATH
);
694 if (dwFileSystemFlags
> MAX_PATH
- 7)
695 pszPath
[MAX_PATH
-7] = L
'\0';
698 wcscat (pszPath
, wszOpenBracket
);
700 wcscat (pszPath
, wszDrive
);
701 wcscat (pszPath
, wszCloseBracket
);
706 /* Neither a shell namespace extension nor a drive letter. */
707 ERR("Wrong pidl type\n");
708 CoTaskMemFree(pszPath
);
714 /* Complex pidl. Let the child folder do the work */
715 hr
= SHELL32_GetDisplayNameOfChild(iface
, pidl
, dwFlags
, pszPath
, MAX_PATH
);
720 strRet
->uType
= STRRET_WSTR
;
721 strRet
->u
.pOleStr
= pszPath
;
724 CoTaskMemFree(pszPath
);
726 TRACE ("-- (%p)->(%s)\n", This
, strRet
->uType
== STRRET_CSTR
? strRet
->u
.cStr
: debugstr_w(strRet
->u
.pOleStr
));
730 /**************************************************************************
731 * ISF_MyComputer_fnSetNameOf
732 * Changes the name of a file object or subfolder, possibly changing its item
733 * identifier in the process.
736 * hwndOwner [in] Owner window for output
737 * pidl [in] simple pidl of item to change
738 * lpszName [in] the items new display name
739 * dwFlags [in] SHGNO formatting flags
740 * ppidlOut [out] simple pidl returned
742 static HRESULT WINAPI
ISF_MyComputer_fnSetNameOf (
743 IShellFolder2
* iface
, HWND hwndOwner
, LPCITEMIDLIST pidl
,
744 LPCOLESTR lpName
, DWORD dwFlags
, LPITEMIDLIST
* pPidlOut
)
746 IGenericSFImpl
*This
= (IGenericSFImpl
*)iface
;
752 TRACE ("(%p)->(%p,pidl=%p,%s,%u,%p)\n", This
,
753 hwndOwner
, pidl
, debugstr_w (lpName
), dwFlags
, pPidlOut
);
755 if (_ILIsDrive(pidl
))
757 if (_ILSimpleGetTextW(pidl
, szName
, sizeof(szName
)/sizeof(WCHAR
)))
759 SetVolumeLabelW(szName
, lpName
);
762 *pPidlOut
= _ILCreateDrive(szName
);
767 if (pPidlOut
!= NULL
)
769 *pPidlOut
= _ILCreateMyComputer();
772 length
= (wcslen(lpName
)+1) * sizeof(WCHAR
);
773 sName
= SHAlloc(length
);
777 return E_OUTOFMEMORY
;
780 if (RegOpenKeyExW(HKEY_CURRENT_USER
,
781 L
"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\CLSID\\{20D04FE0-3AEA-1069-A2D8-08002B30309D}",
784 &hKey
) != ERROR_SUCCESS
)
786 WARN("Error: failed to open registry key\n");
790 RegSetValueExW(hKey
, NULL
, 0, REG_SZ
, (const LPBYTE
)lpName
, length
);
794 wcscpy(sName
, lpName
);
797 TRACE("result %s\n", debugstr_w(This
->sName
));
801 static HRESULT WINAPI
ISF_MyComputer_fnGetDefaultSearchGUID (
802 IShellFolder2
* iface
, GUID
* pguid
)
804 IGenericSFImpl
*This
= (IGenericSFImpl
*)iface
;
805 FIXME ("(%p)\n", This
);
808 static HRESULT WINAPI
ISF_MyComputer_fnEnumSearches (
809 IShellFolder2
* iface
, IEnumExtraSearch
** ppenum
)
811 IGenericSFImpl
*This
= (IGenericSFImpl
*)iface
;
812 FIXME ("(%p)\n", This
);
815 static HRESULT WINAPI
ISF_MyComputer_fnGetDefaultColumn (
816 IShellFolder2
*iface
, DWORD dwRes
, ULONG
*pSort
, ULONG
*pDisplay
)
818 IGenericSFImpl
*This
= (IGenericSFImpl
*)iface
;
820 TRACE ("(%p)\n", This
);
828 static HRESULT WINAPI
ISF_MyComputer_fnGetDefaultColumnState (
829 IShellFolder2
* iface
, UINT iColumn
, DWORD
* pcsFlags
)
831 IGenericSFImpl
*This
= (IGenericSFImpl
*)iface
;
833 TRACE ("(%p)\n", This
);
835 if (!pcsFlags
|| iColumn
>= MYCOMPUTERSHELLVIEWCOLUMNS
)
837 *pcsFlags
= MyComputerSFHeader
[iColumn
].pcsFlags
;
841 static HRESULT WINAPI
ISF_MyComputer_fnGetDetailsEx (IShellFolder2
* iface
,
842 LPCITEMIDLIST pidl
, const SHCOLUMNID
* pscid
, VARIANT
* pv
)
844 IGenericSFImpl
*This
= (IGenericSFImpl
*)iface
;
845 FIXME ("(%p)\n", This
);
849 /* FIXME: drive size >4GB is rolling over */
850 static HRESULT WINAPI
ISF_MyComputer_fnGetDetailsOf (IShellFolder2
* iface
,
851 LPCITEMIDLIST pidl
, UINT iColumn
, SHELLDETAILS
* psd
)
853 IGenericSFImpl
*This
= (IGenericSFImpl
*)iface
;
856 TRACE ("(%p)->(%p %i %p)\n", This
, pidl
, iColumn
, psd
);
858 if (!psd
|| iColumn
>= MYCOMPUTERSHELLVIEWCOLUMNS
)
863 psd
->fmt
= MyComputerSFHeader
[iColumn
].fmt
;
864 psd
->cxChar
= MyComputerSFHeader
[iColumn
].cxChar
;
865 psd
->str
.uType
= STRRET_CSTR
;
866 LoadStringA (shell32_hInstance
, MyComputerSFHeader
[iColumn
].colnameid
,
867 psd
->str
.u
.cStr
, MAX_PATH
);
872 char szPath
[MAX_PATH
];
873 ULARGE_INTEGER ulBytes
;
875 psd
->str
.u
.cStr
[0] = 0x00;
876 psd
->str
.uType
= STRRET_CSTR
;
880 hr
= IShellFolder_GetDisplayNameOf (iface
, pidl
,
881 SHGDN_NORMAL
| SHGDN_INFOLDER
, &psd
->str
);
884 _ILGetFileType (pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
886 case 2: /* total size */
887 if (_ILIsDrive (pidl
))
889 _ILSimpleGetText (pidl
, szPath
, MAX_PATH
);
890 GetDiskFreeSpaceExA (szPath
, NULL
, &ulBytes
, NULL
);
891 StrFormatByteSizeA (ulBytes
.u
.LowPart
, psd
->str
.u
.cStr
, MAX_PATH
);
894 case 3: /* free size */
895 if (_ILIsDrive (pidl
))
897 _ILSimpleGetText (pidl
, szPath
, MAX_PATH
);
898 GetDiskFreeSpaceExA (szPath
, &ulBytes
, NULL
, NULL
);
899 StrFormatByteSizeA (ulBytes
.u
.LowPart
, psd
->str
.u
.cStr
, MAX_PATH
);
909 static HRESULT WINAPI
ISF_MyComputer_fnMapColumnToSCID (
910 IShellFolder2
* iface
, UINT column
, SHCOLUMNID
* pscid
)
912 IGenericSFImpl
*This
= (IGenericSFImpl
*)iface
;
913 FIXME ("(%p)\n", This
);
917 static const IShellFolder2Vtbl vt_ShellFolder2
=
919 ISF_MyComputer_fnQueryInterface
,
920 ISF_MyComputer_fnAddRef
,
921 ISF_MyComputer_fnRelease
,
922 ISF_MyComputer_fnParseDisplayName
,
923 ISF_MyComputer_fnEnumObjects
,
924 ISF_MyComputer_fnBindToObject
,
925 ISF_MyComputer_fnBindToStorage
,
926 ISF_MyComputer_fnCompareIDs
,
927 ISF_MyComputer_fnCreateViewObject
,
928 ISF_MyComputer_fnGetAttributesOf
,
929 ISF_MyComputer_fnGetUIObjectOf
,
930 ISF_MyComputer_fnGetDisplayNameOf
,
931 ISF_MyComputer_fnSetNameOf
,
933 ISF_MyComputer_fnGetDefaultSearchGUID
,
934 ISF_MyComputer_fnEnumSearches
,
935 ISF_MyComputer_fnGetDefaultColumn
,
936 ISF_MyComputer_fnGetDefaultColumnState
,
937 ISF_MyComputer_fnGetDetailsEx
,
938 ISF_MyComputer_fnGetDetailsOf
,
939 ISF_MyComputer_fnMapColumnToSCID
942 /************************************************************************
943 * IMCFldr_PersistFolder2_QueryInterface
945 static HRESULT WINAPI
IMCFldr_PersistFolder2_QueryInterface (
946 IPersistFolder2
* iface
, REFIID iid
, LPVOID
* ppvObj
)
948 IGenericSFImpl
*This
= impl_from_IPersistFolder2(iface
);
950 TRACE ("(%p)\n", This
);
952 return IUnknown_QueryInterface (_IUnknown_ (This
), iid
, ppvObj
);
955 /************************************************************************
956 * IMCFldr_PersistFolder2_AddRef
958 static ULONG WINAPI
IMCFldr_PersistFolder2_AddRef (IPersistFolder2
* iface
)
960 IGenericSFImpl
*This
= impl_from_IPersistFolder2(iface
);
962 TRACE ("(%p)->(count=%u)\n", This
, This
->ref
);
964 return IUnknown_AddRef (_IUnknown_ (This
));
967 /************************************************************************
968 * ISFPersistFolder_Release
970 static ULONG WINAPI
IMCFldr_PersistFolder2_Release (IPersistFolder2
* iface
)
972 IGenericSFImpl
*This
= impl_from_IPersistFolder2(iface
);
974 TRACE ("(%p)->(count=%u)\n", This
, This
->ref
);
976 return IUnknown_Release (_IUnknown_ (This
));
979 /************************************************************************
980 * IMCFldr_PersistFolder2_GetClassID
982 static HRESULT WINAPI
IMCFldr_PersistFolder2_GetClassID (
983 IPersistFolder2
* iface
, CLSID
* lpClassId
)
985 IGenericSFImpl
*This
= impl_from_IPersistFolder2(iface
);
987 TRACE ("(%p)\n", This
);
991 *lpClassId
= CLSID_MyComputer
;
996 /************************************************************************
997 * IMCFldr_PersistFolder2_Initialize
999 * NOTES: it makes no sense to change the pidl
1001 static HRESULT WINAPI
IMCFldr_PersistFolder2_Initialize (
1002 IPersistFolder2
* iface
, LPCITEMIDLIST pidl
)
1004 IGenericSFImpl
*This
= impl_from_IPersistFolder2(iface
);
1005 TRACE ("(%p)->(%p)\n", This
, pidl
);
1008 SHFree((LPVOID
)This
->pidlRoot
);
1010 This
->pidlRoot
= ILClone(pidl
);
1014 /**************************************************************************
1015 * IPersistFolder2_fnGetCurFolder
1017 static HRESULT WINAPI
IMCFldr_PersistFolder2_GetCurFolder (
1018 IPersistFolder2
* iface
, LPITEMIDLIST
* pidl
)
1020 IGenericSFImpl
*This
= impl_from_IPersistFolder2(iface
);
1022 TRACE ("(%p)->(%p)\n", This
, pidl
);
1026 *pidl
= ILClone (This
->pidlRoot
);
1030 static const IPersistFolder2Vtbl vt_PersistFolder2
=
1032 IMCFldr_PersistFolder2_QueryInterface
,
1033 IMCFldr_PersistFolder2_AddRef
,
1034 IMCFldr_PersistFolder2_Release
,
1035 IMCFldr_PersistFolder2_GetClassID
,
1036 IMCFldr_PersistFolder2_Initialize
,
1037 IMCFldr_PersistFolder2_GetCurFolder