3 * Virtual Desktop Folder
5 * Copyright 1997 Marcus Meissner
6 * Copyright 1998, 1999, 2002 Juergen Schmied
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "wine/port.h"
38 #include "undocshell.h"
39 #include "shell32_main.h"
42 #include "shellfolder.h"
43 #include "wine/debug.h"
47 WINE_DEFAULT_DEBUG_CHANNEL (shell);
49 /***********************************************************************
50 * Desktopfolder implementation
54 ICOM_VFIELD (IShellFolder2);
59 /* both paths are parsible from the desktop */
60 LPSTR sPathTarget; /* complete path to target used for enumeration and ChangeNotify */
61 LPITEMIDLIST pidlRoot; /* absolute pidl */
63 int dwAttributes; /* attributes returned by GetAttributesOf FIXME: use it */
65 UINT cfShellIDList; /* clipboardformat for IDropTarget */
66 BOOL fAcceptFmt; /* flag for pending Drop */
69 #define _IUnknown_(This) (IShellFolder*)&(This->lpVtbl)
70 #define _IShellFolder_(This) (IShellFolder*)&(This->lpVtbl)
72 HRESULT WINAPI ISF_MyComputer_Constructor (IUnknown * pUnkOuter, REFIID riid, LPVOID * ppv);
74 static struct ICOM_VTABLE (IShellFolder2) vt_MCFldr_ShellFolder2;
76 static shvheader DesktopSFHeader[] = {
77 {IDS_SHV_COLUMN1, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 15},
78 {IDS_SHV_COLUMN2, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
79 {IDS_SHV_COLUMN3, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
80 {IDS_SHV_COLUMN4, SHCOLSTATE_TYPE_DATE | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 12},
81 {IDS_SHV_COLUMN5, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 5}
84 #define DESKTOPSHELLVIEWCOLUMNS 5
86 /**************************************************************************
87 * ISF_Desktop_Constructor
89 HRESULT WINAPI ISF_Desktop_Constructor (IUnknown * pUnkOuter, REFIID riid, LPVOID * ppv)
92 char szMyPath[MAX_PATH];
94 TRACE ("unkOut=%p %s\n", pUnkOuter, shdebugstr_guid (riid));
99 return CLASS_E_NOAGGREGATION;
101 if (!SHGetSpecialFolderPathA (0, szMyPath, CSIDL_DESKTOPDIRECTORY, TRUE))
104 sf = (IGenericSFImpl *) LocalAlloc (GMEM_ZEROINIT, sizeof (IGenericSFImpl));
106 return E_OUTOFMEMORY;
109 ICOM_VTBL (sf) = &vt_MCFldr_ShellFolder2;
110 sf->pidlRoot = _ILCreateDesktop (); /* my qualified pidl */
111 sf->sPathTarget = SHAlloc (strlen (szMyPath) + 1);
112 lstrcpyA (sf->sPathTarget, szMyPath);
114 if (!SUCCEEDED (IUnknown_QueryInterface (_IUnknown_ (sf), riid, ppv))) {
115 IUnknown_Release (_IUnknown_ (sf));
116 return E_NOINTERFACE;
119 TRACE ("--(%p)\n", sf);
123 /**************************************************************************
124 * ISF_Desktop_fnQueryInterface
126 * NOTES supports not IPersist/IPersistFolder
128 static HRESULT WINAPI ISF_Desktop_fnQueryInterface (IShellFolder2 * iface, REFIID riid, LPVOID * ppvObj)
130 ICOM_THIS (IGenericSFImpl, iface);
132 TRACE ("(%p)->(%s,%p)\n", This, shdebugstr_guid (riid), ppvObj);
136 if (IsEqualIID (riid, &IID_IUnknown) || IsEqualIID (riid, &IID_IShellFolder)
137 || IsEqualIID (riid, &IID_IShellFolder2)) {
142 IUnknown_AddRef ((IUnknown *) (*ppvObj));
143 TRACE ("-- Interface: (%p)->(%p)\n", ppvObj, *ppvObj);
146 TRACE ("-- Interface: E_NOINTERFACE\n");
147 return E_NOINTERFACE;
150 static ULONG WINAPI ISF_Desktop_fnAddRef (IShellFolder2 * iface)
152 ICOM_THIS (IGenericSFImpl, iface);
154 TRACE ("(%p)->(count=%lu)\n", This, This->ref);
156 return ++(This->ref);
159 static ULONG WINAPI ISF_Desktop_fnRelease (IShellFolder2 * iface)
161 ICOM_THIS (IGenericSFImpl, iface);
163 TRACE ("(%p)->(count=%lu)\n", This, This->ref);
165 if (!--(This->ref)) {
166 TRACE ("-- destroying IShellFolder(%p)\n", This);
168 SHFree (This->pidlRoot);
169 if (This->sPathTarget)
170 SHFree (This->sPathTarget);
171 LocalFree ((HLOCAL) This);
177 /**************************************************************************
178 * ISF_Desktop_fnParseDisplayName
181 * "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}" and "" binds
184 static HRESULT WINAPI ISF_Desktop_fnParseDisplayName (IShellFolder2 * iface,
187 LPOLESTR lpszDisplayName,
188 DWORD * pchEaten, LPITEMIDLIST * ppidl, DWORD * pdwAttributes)
190 ICOM_THIS (IGenericSFImpl, iface);
192 WCHAR szElement[MAX_PATH];
193 LPCWSTR szNext = NULL;
194 LPITEMIDLIST pidlTemp = NULL;
195 HRESULT hr = E_OUTOFMEMORY;
198 TRACE ("(%p)->(HWND=%p,%p,%p=%s,%p,pidl=%p,%p)\n",
199 This, hwndOwner, pbcReserved, lpszDisplayName, debugstr_w (lpszDisplayName), pchEaten, ppidl, pdwAttributes);
203 *pchEaten = 0; /* strange but like the original */
205 if (lpszDisplayName[0] == ':' && lpszDisplayName[1] == ':') {
206 szNext = GetNextElementW (lpszDisplayName, szElement, MAX_PATH);
207 TRACE ("-- element: %s\n", debugstr_w (szElement));
208 SHCLSIDFromStringW (szElement + 2, &clsid);
209 pidlTemp = _ILCreate (PT_MYCOMP, &clsid, sizeof (clsid));
210 } else if (PathGetDriveNumberW (lpszDisplayName) >= 0) {
211 /* it's a filesystem path with a drive. Let MyComputer parse it */
212 pidlTemp = _ILCreateMyComputer ();
213 szNext = lpszDisplayName;
215 /* it's a filesystem path on the desktop. Let a FSFolder parse it */
216 WCHAR szCompletePath[MAX_PATH];
218 /* build a complete path to create a simpel pidl */
219 MultiByteToWideChar (CP_ACP, 0, This->sPathTarget, -1, szCompletePath, MAX_PATH);
220 PathAddBackslashW (szCompletePath);
221 lstrcatW (szCompletePath, lpszDisplayName);
222 pidlTemp = SHSimpleIDListFromPathW (lpszDisplayName);
223 szNext = lpszDisplayName;
227 if (szNext && *szNext) {
228 hr = SHELL32_ParseNextElement (hwndOwner, iface, &pidlTemp, (LPOLESTR) szNext, pchEaten, pdwAttributes);
231 if (pdwAttributes && *pdwAttributes) {
232 SHELL32_GetItemAttributes (_IShellFolder_ (This), pidlTemp, pdwAttributes);
239 TRACE ("(%p)->(-- ret=0x%08lx)\n", This, hr);
244 /**************************************************************************
245 * ISF_Desktop_fnEnumObjects
247 static HRESULT WINAPI ISF_Desktop_fnEnumObjects (IShellFolder2 * iface,
248 HWND hwndOwner, DWORD dwFlags, LPENUMIDLIST * ppEnumIDList)
250 ICOM_THIS (IGenericSFImpl, iface);
252 TRACE ("(%p)->(HWND=%p flags=0x%08lx pplist=%p)\n", This, hwndOwner, dwFlags, ppEnumIDList);
254 *ppEnumIDList = NULL;
255 *ppEnumIDList = IEnumIDList_Constructor (NULL, dwFlags, EIDL_DESK);
257 TRACE ("-- (%p)->(new ID List: %p)\n", This, *ppEnumIDList);
260 return E_OUTOFMEMORY;
265 /**************************************************************************
266 * ISF_Desktop_fnBindToObject
268 static HRESULT WINAPI ISF_Desktop_fnBindToObject (IShellFolder2 * iface,
269 LPCITEMIDLIST pidl, LPBC pbcReserved, REFIID riid, LPVOID * ppvOut)
271 ICOM_THIS (IGenericSFImpl, iface);
273 TRACE ("(%p)->(pidl=%p,%p,%s,%p)\n", This, pidl, pbcReserved, shdebugstr_guid (riid), ppvOut);
275 return SHELL32_BindToChild (This->pidlRoot, This->sPathTarget, pidl, riid, ppvOut);
278 /**************************************************************************
279 * ISF_Desktop_fnBindToStorage
281 static HRESULT WINAPI ISF_Desktop_fnBindToStorage (IShellFolder2 * iface,
282 LPCITEMIDLIST pidl, LPBC pbcReserved, REFIID riid, LPVOID * ppvOut)
284 ICOM_THIS (IGenericSFImpl, iface);
286 FIXME ("(%p)->(pidl=%p,%p,%s,%p) stub\n", This, pidl, pbcReserved, shdebugstr_guid (riid), ppvOut);
292 /**************************************************************************
293 * ISF_Desktop_fnCompareIDs
296 static HRESULT WINAPI ISF_Desktop_fnCompareIDs (IShellFolder2 * iface,
297 LPARAM lParam, LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
299 ICOM_THIS (IGenericSFImpl, iface);
303 TRACE ("(%p)->(0x%08lx,pidl1=%p,pidl2=%p)\n", This, lParam, pidl1, pidl2);
304 nReturn = SHELL32_CompareIDs (_IShellFolder_ (This), lParam, pidl1, pidl2);
305 TRACE ("-- %i\n", nReturn);
309 /**************************************************************************
310 * ISF_Desktop_fnCreateViewObject
312 static HRESULT WINAPI ISF_Desktop_fnCreateViewObject (IShellFolder2 * iface,
313 HWND hwndOwner, REFIID riid, LPVOID * ppvOut)
315 ICOM_THIS (IGenericSFImpl, iface);
317 LPSHELLVIEW pShellView;
318 HRESULT hr = E_INVALIDARG;
320 TRACE ("(%p)->(hwnd=%p,%s,%p)\n", This, hwndOwner, shdebugstr_guid (riid), ppvOut);
325 if (IsEqualIID (riid, &IID_IDropTarget)) {
326 WARN ("IDropTarget not implemented\n");
328 } else if (IsEqualIID (riid, &IID_IContextMenu)) {
329 WARN ("IContextMenu not implemented\n");
331 } else if (IsEqualIID (riid, &IID_IShellView)) {
332 pShellView = IShellView_Constructor ((IShellFolder *) iface);
334 hr = IShellView_QueryInterface (pShellView, riid, ppvOut);
335 IShellView_Release (pShellView);
339 TRACE ("-- (%p)->(interface=%p)\n", This, ppvOut);
343 /**************************************************************************
344 * ISF_Desktop_fnGetAttributesOf
346 static HRESULT WINAPI ISF_Desktop_fnGetAttributesOf (IShellFolder2 * iface,
347 UINT cidl, LPCITEMIDLIST * apidl, DWORD * rgfInOut)
349 ICOM_THIS (IGenericSFImpl, iface);
353 TRACE ("(%p)->(cidl=%d apidl=%p mask=0x%08lx)\n", This, cidl, apidl, *rgfInOut);
355 if ((!cidl) || (!apidl) || (!rgfInOut))
358 while (cidl > 0 && *apidl) {
360 SHELL32_GetItemAttributes (_IShellFolder_ (This), *apidl, rgfInOut);
365 TRACE ("-- result=0x%08lx\n", *rgfInOut);
370 /**************************************************************************
371 * ISF_Desktop_fnGetUIObjectOf
374 * HWND hwndOwner, //[in ] Parent window for any output
375 * UINT cidl, //[in ] array size
376 * LPCITEMIDLIST* apidl, //[in ] simple pidl array
377 * REFIID riid, //[in ] Requested Interface
378 * UINT* prgfInOut, //[ ] reserved
379 * LPVOID* ppvObject) //[out] Resulting Interface
382 static HRESULT WINAPI ISF_Desktop_fnGetUIObjectOf (IShellFolder2 * iface,
385 LPCITEMIDLIST * apidl,
386 REFIID riid, UINT * prgfInOut, LPVOID * ppvOut)
388 ICOM_THIS (IGenericSFImpl, iface);
391 IUnknown *pObj = NULL;
392 HRESULT hr = E_INVALIDARG;
394 TRACE ("(%p)->(%p,%u,apidl=%p,%s,%p,%p)\n",
395 This, hwndOwner, cidl, apidl, shdebugstr_guid (riid), prgfInOut, ppvOut);
400 if (IsEqualIID (riid, &IID_IContextMenu) && (cidl >= 1)) {
401 pObj = (LPUNKNOWN) ISvItemCm_Constructor ((IShellFolder *) iface, This->pidlRoot, apidl, cidl);
403 } else if (IsEqualIID (riid, &IID_IDataObject) && (cidl >= 1)) {
404 pObj = (LPUNKNOWN) IDataObject_Constructor (hwndOwner, This->pidlRoot, apidl, cidl);
406 } else if (IsEqualIID (riid, &IID_IExtractIconA) && (cidl == 1)) {
407 pidl = ILCombine (This->pidlRoot, apidl[0]);
408 pObj = (LPUNKNOWN) IExtractIconA_Constructor (pidl);
411 } else if (IsEqualIID (riid, &IID_IExtractIconW) && (cidl == 1)) {
412 pidl = ILCombine (This->pidlRoot, apidl[0]);
413 pObj = (LPUNKNOWN) IExtractIconW_Constructor (pidl);
416 } else if (IsEqualIID (riid, &IID_IDropTarget) && (cidl >= 1)) {
417 hr = IShellFolder_QueryInterface (iface, &IID_IDropTarget, (LPVOID *) & pObj);
427 TRACE ("(%p)->hr=0x%08lx\n", This, hr);
431 /**************************************************************************
432 * ISF_Desktop_fnGetDisplayNameOf
435 * special case: pidl = null gives desktop-name back
437 DWORD WINAPI __SHGUIDToStringA (REFGUID guid, LPSTR str)
439 CHAR sFormat[52] = "{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}";
441 return wsprintfA (str, sFormat,
442 guid->Data1, guid->Data2, guid->Data3,
443 guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
444 guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7]);
448 static HRESULT WINAPI ISF_Desktop_fnGetDisplayNameOf (IShellFolder2 * iface,
449 LPCITEMIDLIST pidl, DWORD dwFlags, LPSTRRET strRet)
451 ICOM_THIS (IGenericSFImpl, iface);
453 CHAR szPath[MAX_PATH] = "";
457 TRACE ("(%p)->(pidl=%p,0x%08lx,%p)\n", This, pidl, dwFlags, strRet);
463 if (_ILIsDesktop (pidl)) {
464 if ((GET_SHGDN_RELATION (dwFlags) == SHGDN_NORMAL) && (GET_SHGDN_FOR (dwFlags) == SHGDN_FORPARSING)) {
465 lstrcpyA (szPath, This->sPathTarget);
467 HCR_GetClassNameA(&CLSID_ShellDesktop, szPath, MAX_PATH);
469 } else if (_ILIsPidlSimple (pidl)) {
470 if ((clsid = _ILGetGUIDPointer (pidl))) {
471 if (GET_SHGDN_FOR (dwFlags) == SHGDN_FORPARSING) {
472 int bWantsForParsing;
475 * we can only get a filesystem path from a shellfolder if the value WantsFORPARSING in
476 * CLSID\\{...}\\shellfolder exists
477 * exception: the MyComputer folder has this keys not but like any filesystem backed
478 * folder it needs these behaviour
480 if (IsEqualIID (clsid, &CLSID_MyComputer)) {
481 bWantsForParsing = 1;
483 /* get the "WantsFORPARSING" flag from the registry */
486 lstrcpyA (szRegPath, "CLSID\\");
487 __SHGUIDToStringA (clsid, &szRegPath[6]);
488 lstrcatA (szRegPath, "\\shellfolder");
491 SHGetValueA (HKEY_CLASSES_ROOT, szRegPath, "WantsFORPARSING", NULL, NULL, NULL));
494 if ((GET_SHGDN_RELATION (dwFlags) == SHGDN_NORMAL) && bWantsForParsing) {
495 /* we need the filesystem path to the destination folder. Only the folder itself can know it */
496 hr = SHELL32_GetDisplayNameOfChild (iface, pidl, dwFlags, szPath, MAX_PATH);
498 /* parsing name like ::{...} */
499 lstrcpyA (szPath, "::");
500 __SHGUIDToStringA (clsid, &szPath[2]);
503 /* user friendly name */
504 HCR_GetClassNameA (clsid, szPath, MAX_PATH);
507 /* file system folder */
508 _ILSimpleGetText (pidl, szPath, MAX_PATH);
511 /* a complex pidl, let the subfolder do the work */
512 hr = SHELL32_GetDisplayNameOfChild (iface, pidl, dwFlags, szPath, MAX_PATH);
515 if (SUCCEEDED (hr)) {
516 strRet->uType = STRRET_CSTR;
517 lstrcpynA (strRet->u.cStr, szPath, MAX_PATH);
520 TRACE ("-- (%p)->(%s,0x%08lx)\n", This, szPath, hr);
524 /**************************************************************************
525 * ISF_Desktop_fnSetNameOf
526 * Changes the name of a file object or subfolder, possibly changing its item
527 * identifier in the process.
530 * HWND hwndOwner, //[in ] Owner window for output
531 * LPCITEMIDLIST pidl, //[in ] simple pidl of item to change
532 * LPCOLESTR lpszName, //[in ] the items new display name
533 * DWORD dwFlags, //[in ] SHGNO formatting flags
534 * LPITEMIDLIST* ppidlOut) //[out] simple pidl returned
536 static HRESULT WINAPI ISF_Desktop_fnSetNameOf (IShellFolder2 * iface, HWND hwndOwner, LPCITEMIDLIST pidl, /*simple pidl */
537 LPCOLESTR lpName, DWORD dwFlags, LPITEMIDLIST * pPidlOut)
539 ICOM_THIS (IGenericSFImpl, iface);
541 FIXME ("(%p)->(%p,pidl=%p,%s,%lu,%p)\n", This, hwndOwner, pidl, debugstr_w (lpName), dwFlags, pPidlOut);
546 static HRESULT WINAPI ISF_Desktop_fnGetDefaultSearchGUID (IShellFolder2 * iface, GUID * pguid)
548 ICOM_THIS (IGenericSFImpl, iface);
550 FIXME ("(%p)\n", This);
553 static HRESULT WINAPI ISF_Desktop_fnEnumSearches (IShellFolder2 * iface, IEnumExtraSearch ** ppenum)
555 ICOM_THIS (IGenericSFImpl, iface);
556 FIXME ("(%p)\n", This);
559 static HRESULT WINAPI ISF_Desktop_fnGetDefaultColumn (IShellFolder2 * iface,
560 DWORD dwRes, ULONG * pSort, ULONG * pDisplay)
562 ICOM_THIS (IGenericSFImpl, iface);
564 TRACE ("(%p)\n", This);
573 static HRESULT WINAPI ISF_Desktop_fnGetDefaultColumnState (IShellFolder2 * iface, UINT iColumn, DWORD * pcsFlags)
575 ICOM_THIS (IGenericSFImpl, iface);
577 TRACE ("(%p)\n", This);
579 if (!pcsFlags || iColumn >= DESKTOPSHELLVIEWCOLUMNS)
582 *pcsFlags = DesktopSFHeader[iColumn].pcsFlags;
586 static HRESULT WINAPI ISF_Desktop_fnGetDetailsEx (IShellFolder2 * iface,
587 LPCITEMIDLIST pidl, const SHCOLUMNID * pscid, VARIANT * pv)
589 ICOM_THIS (IGenericSFImpl, iface);
590 FIXME ("(%p)\n", This);
594 static HRESULT WINAPI ISF_Desktop_fnGetDetailsOf (IShellFolder2 * iface,
595 LPCITEMIDLIST pidl, UINT iColumn, SHELLDETAILS * psd)
597 ICOM_THIS (IGenericSFImpl, iface);
601 TRACE ("(%p)->(%p %i %p)\n", This, pidl, iColumn, psd);
603 if (!psd || iColumn >= DESKTOPSHELLVIEWCOLUMNS)
607 psd->fmt = DesktopSFHeader[iColumn].fmt;
608 psd->cxChar = DesktopSFHeader[iColumn].cxChar;
609 psd->str.uType = STRRET_CSTR;
610 LoadStringA (shell32_hInstance, DesktopSFHeader[iColumn].colnameid, psd->str.u.cStr, MAX_PATH);
613 /* the data from the pidl */
616 hr = IShellFolder_GetDisplayNameOf (iface, pidl, SHGDN_NORMAL | SHGDN_INFOLDER, &psd->str);
619 _ILGetFileSize (pidl, psd->str.u.cStr, MAX_PATH);
622 _ILGetFileType (pidl, psd->str.u.cStr, MAX_PATH);
625 _ILGetFileDate (pidl, psd->str.u.cStr, MAX_PATH);
627 case 4: /* attributes */
628 _ILGetFileAttributes (pidl, psd->str.u.cStr, MAX_PATH);
632 psd->str.uType = STRRET_CSTR;
637 static HRESULT WINAPI ISF_Desktop_fnMapNameToSCID (IShellFolder2 * iface, LPCWSTR pwszName, SHCOLUMNID * pscid)
639 ICOM_THIS (IGenericSFImpl, iface);
640 FIXME ("(%p)\n", This);
644 static ICOM_VTABLE (IShellFolder2) vt_MCFldr_ShellFolder2 =
646 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
647 ISF_Desktop_fnQueryInterface,
648 ISF_Desktop_fnAddRef,
649 ISF_Desktop_fnRelease,
650 ISF_Desktop_fnParseDisplayName,
651 ISF_Desktop_fnEnumObjects,
652 ISF_Desktop_fnBindToObject,
653 ISF_Desktop_fnBindToStorage,
654 ISF_Desktop_fnCompareIDs,
655 ISF_Desktop_fnCreateViewObject,
656 ISF_Desktop_fnGetAttributesOf,
657 ISF_Desktop_fnGetUIObjectOf,
658 ISF_Desktop_fnGetDisplayNameOf,
659 ISF_Desktop_fnSetNameOf,
661 ISF_Desktop_fnGetDefaultSearchGUID,
662 ISF_Desktop_fnEnumSearches,
663 ISF_Desktop_fnGetDefaultColumn,
664 ISF_Desktop_fnGetDefaultColumnState,
665 ISF_Desktop_fnGetDetailsEx,
666 ISF_Desktop_fnGetDetailsOf,
667 ISF_Desktop_fnMapNameToSCID};