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 "wine/obj_base.h"
39 #include "wine/obj_dragdrop.h"
40 #include "wine/obj_shellfolder.h"
41 #include "undocshell.h"
42 #include "shell32_main.h"
45 #include "shellfolder.h"
46 #include "wine/debug.h"
50 WINE_DEFAULT_DEBUG_CHANNEL (shell);
52 /***********************************************************************
53 * Desktopfolder implementation
57 ICOM_VFIELD (IShellFolder2);
62 /* both paths are parsible from the desktop */
63 LPSTR sPathTarget; /* complete path to target used for enumeration and ChangeNotify */
64 LPITEMIDLIST pidlRoot; /* absolute pidl */
66 int dwAttributes; /* attributes returned by GetAttributesOf FIXME: use it */
68 UINT cfShellIDList; /* clipboardformat for IDropTarget */
69 BOOL fAcceptFmt; /* flag for pending Drop */
72 #define _IUnknown_(This) (IShellFolder*)&(This->lpVtbl)
73 #define _IShellFolder_(This) (IShellFolder*)&(This->lpVtbl)
75 HRESULT WINAPI ISF_MyComputer_Constructor (IUnknown * pUnkOuter, REFIID riid, LPVOID * ppv);
77 static struct ICOM_VTABLE (IShellFolder2) vt_MCFldr_ShellFolder2;
79 static shvheader DesktopSFHeader[] = {
80 {IDS_SHV_COLUMN1, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 15},
81 {IDS_SHV_COLUMN2, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
82 {IDS_SHV_COLUMN3, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
83 {IDS_SHV_COLUMN4, SHCOLSTATE_TYPE_DATE | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 12},
84 {IDS_SHV_COLUMN5, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 5}
87 #define DESKTOPSHELLVIEWCOLUMNS 5
89 /**************************************************************************
90 * ISF_Desktop_Constructor
92 HRESULT WINAPI ISF_Desktop_Constructor (IUnknown * pUnkOuter, REFIID riid, LPVOID * ppv)
95 char szMyPath[MAX_PATH];
97 TRACE ("unkOut=%p %s\n", pUnkOuter, shdebugstr_guid (riid));
102 return CLASS_E_NOAGGREGATION;
104 if (!SHGetSpecialFolderPathA (0, szMyPath, CSIDL_DESKTOPDIRECTORY, TRUE))
107 sf = (IGenericSFImpl *) LocalAlloc (GMEM_ZEROINIT, sizeof (IGenericSFImpl));
109 return E_OUTOFMEMORY;
112 ICOM_VTBL (sf) = &vt_MCFldr_ShellFolder2;
113 sf->pidlRoot = _ILCreateDesktop (); /* my qualified pidl */
114 sf->sPathTarget = SHAlloc (strlen (szMyPath) + 1);
115 lstrcpyA (sf->sPathTarget, szMyPath);
117 if (!SUCCEEDED (IUnknown_QueryInterface (_IUnknown_ (sf), riid, ppv))) {
118 IUnknown_Release (_IUnknown_ (sf));
119 return E_NOINTERFACE;
122 TRACE ("--(%p)\n", sf);
126 /**************************************************************************
127 * ISF_Desktop_fnQueryInterface
129 * NOTES supports not IPersist/IPersistFolder
131 static HRESULT WINAPI ISF_Desktop_fnQueryInterface (IShellFolder2 * iface, REFIID riid, LPVOID * ppvObj)
133 ICOM_THIS (IGenericSFImpl, iface);
135 TRACE ("(%p)->(%s,%p)\n", This, shdebugstr_guid (riid), ppvObj);
139 if (IsEqualIID (riid, &IID_IUnknown) || IsEqualIID (riid, &IID_IShellFolder)
140 || IsEqualIID (riid, &IID_IShellFolder2)) {
145 IUnknown_AddRef ((IUnknown *) (*ppvObj));
146 TRACE ("-- Interface: (%p)->(%p)\n", ppvObj, *ppvObj);
149 TRACE ("-- Interface: E_NOINTERFACE\n");
150 return E_NOINTERFACE;
153 static ULONG WINAPI ISF_Desktop_fnAddRef (IShellFolder2 * iface)
155 ICOM_THIS (IGenericSFImpl, iface);
157 TRACE ("(%p)->(count=%lu)\n", This, This->ref);
159 return ++(This->ref);
162 static ULONG WINAPI ISF_Desktop_fnRelease (IShellFolder2 * iface)
164 ICOM_THIS (IGenericSFImpl, iface);
166 TRACE ("(%p)->(count=%lu)\n", This, This->ref);
168 if (!--(This->ref)) {
169 TRACE ("-- destroying IShellFolder(%p)\n", This);
171 SHFree (This->pidlRoot);
172 if (This->sPathTarget)
173 SHFree (This->sPathTarget);
174 LocalFree ((HLOCAL) This);
179 /**************************************************************************
180 * ISF_Desktop_fnParseDisplayName
183 * "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}" and "" binds
186 static HRESULT WINAPI ISF_Desktop_fnParseDisplayName (IShellFolder2 * iface,
189 LPOLESTR lpszDisplayName,
190 DWORD * pchEaten, LPITEMIDLIST * ppidl, DWORD * pdwAttributes)
192 ICOM_THIS (IGenericSFImpl, iface);
194 WCHAR szElement[MAX_PATH];
195 LPCWSTR szNext = NULL;
196 LPITEMIDLIST pidlTemp = NULL;
197 HRESULT hr = E_OUTOFMEMORY;
200 TRACE ("(%p)->(HWND=0x%08x,%p,%p=%s,%p,pidl=%p,%p)\n",
201 This, hwndOwner, pbcReserved, lpszDisplayName, debugstr_w (lpszDisplayName), pchEaten, ppidl, pdwAttributes);
205 *pchEaten = 0; /* strange but like the original */
207 if (lpszDisplayName[0] == ':' && lpszDisplayName[1] == ':') {
208 szNext = GetNextElementW (lpszDisplayName, szElement, MAX_PATH);
209 TRACE ("-- element: %s\n", debugstr_w (szElement));
210 CLSIDFromString (szElement + 2, &clsid);
211 pidlTemp = _ILCreate (PT_MYCOMP, &clsid, sizeof (clsid));
212 } else if (PathGetDriveNumberW (lpszDisplayName) >= 0) {
213 /* it's a filesystem path with a drive. Let MyComputer parse it */
214 pidlTemp = _ILCreateMyComputer ();
215 szNext = lpszDisplayName;
217 /* it's a filesystem path on the desktop. Let a FSFolder parse it */
218 WCHAR szCompletePath[MAX_PATH];
220 /* build a complete path to create a simpel pidl */
221 MultiByteToWideChar (CP_ACP, 0, This->sPathTarget, -1, szCompletePath, MAX_PATH);
222 PathAddBackslashW (szCompletePath);
223 lstrcatW (szCompletePath, lpszDisplayName);
224 pidlTemp = SHSimpleIDListFromPathW (lpszDisplayName);
225 szNext = lpszDisplayName;
229 if (szNext && *szNext) {
230 hr = SHELL32_ParseNextElement (hwndOwner, iface, &pidlTemp, (LPOLESTR) szNext, pchEaten, pdwAttributes);
233 if (pdwAttributes && *pdwAttributes) {
234 SHELL32_GetItemAttributes (_IShellFolder_ (This), pidlTemp, pdwAttributes);
241 TRACE ("(%p)->(-- ret=0x%08lx)\n", This, hr);
246 /**************************************************************************
247 * ISF_Desktop_fnEnumObjects
249 static HRESULT WINAPI ISF_Desktop_fnEnumObjects (IShellFolder2 * iface,
250 HWND hwndOwner, DWORD dwFlags, LPENUMIDLIST * ppEnumIDList)
252 ICOM_THIS (IGenericSFImpl, iface);
254 TRACE ("(%p)->(HWND=0x%08x flags=0x%08lx pplist=%p)\n", This, hwndOwner, dwFlags, ppEnumIDList);
256 *ppEnumIDList = NULL;
257 *ppEnumIDList = IEnumIDList_Constructor (NULL, dwFlags, EIDL_DESK);
259 TRACE ("-- (%p)->(new ID List: %p)\n", This, *ppEnumIDList);
262 return E_OUTOFMEMORY;
267 /**************************************************************************
268 * ISF_Desktop_fnBindToObject
270 static HRESULT WINAPI ISF_Desktop_fnBindToObject (IShellFolder2 * iface,
271 LPCITEMIDLIST pidl, LPBC pbcReserved, REFIID riid, LPVOID * ppvOut)
273 ICOM_THIS (IGenericSFImpl, iface);
275 TRACE ("(%p)->(pidl=%p,%p,%s,%p)\n", This, pidl, pbcReserved, shdebugstr_guid (riid), ppvOut);
277 return SHELL32_BindToChild (This->pidlRoot, This->sPathTarget, pidl, riid, ppvOut);
280 /**************************************************************************
281 * ISF_Desktop_fnBindToStorage
283 static HRESULT WINAPI ISF_Desktop_fnBindToStorage (IShellFolder2 * iface,
284 LPCITEMIDLIST pidl, LPBC pbcReserved, REFIID riid, LPVOID * ppvOut)
286 ICOM_THIS (IGenericSFImpl, iface);
288 FIXME ("(%p)->(pidl=%p,%p,%s,%p) stub\n", This, pidl, pbcReserved, shdebugstr_guid (riid), ppvOut);
294 /**************************************************************************
295 * ISF_Desktop_fnCompareIDs
298 static HRESULT WINAPI ISF_Desktop_fnCompareIDs (IShellFolder2 * iface,
299 LPARAM lParam, LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
301 ICOM_THIS (IGenericSFImpl, iface);
305 TRACE ("(%p)->(0x%08lx,pidl1=%p,pidl2=%p)\n", This, lParam, pidl1, pidl2);
306 nReturn = SHELL32_CompareIDs (_IShellFolder_ (This), lParam, pidl1, pidl2);
307 TRACE ("-- %i\n", nReturn);
311 /**************************************************************************
312 * ISF_Desktop_fnCreateViewObject
314 static HRESULT WINAPI ISF_Desktop_fnCreateViewObject (IShellFolder2 * iface,
315 HWND hwndOwner, REFIID riid, LPVOID * ppvOut)
317 ICOM_THIS (IGenericSFImpl, iface);
319 LPSHELLVIEW pShellView;
320 HRESULT hr = E_INVALIDARG;
322 TRACE ("(%p)->(hwnd=0x%x,%s,%p)\n", This, hwndOwner, shdebugstr_guid (riid), ppvOut);
327 if (IsEqualIID (riid, &IID_IDropTarget)) {
328 WARN ("IDropTarget not implemented\n");
330 } else if (IsEqualIID (riid, &IID_IContextMenu)) {
331 WARN ("IContextMenu not implemented\n");
333 } else if (IsEqualIID (riid, &IID_IShellView)) {
334 pShellView = IShellView_Constructor ((IShellFolder *) iface);
336 hr = IShellView_QueryInterface (pShellView, riid, ppvOut);
337 IShellView_Release (pShellView);
341 TRACE ("-- (%p)->(interface=%p)\n", This, ppvOut);
345 /**************************************************************************
346 * ISF_Desktop_fnGetAttributesOf
348 static HRESULT WINAPI ISF_Desktop_fnGetAttributesOf (IShellFolder2 * iface,
349 UINT cidl, LPCITEMIDLIST * apidl, DWORD * rgfInOut)
351 ICOM_THIS (IGenericSFImpl, iface);
355 TRACE ("(%p)->(cidl=%d apidl=%p mask=0x%08lx)\n", This, cidl, apidl, *rgfInOut);
357 if ((!cidl) || (!apidl) || (!rgfInOut))
360 while (cidl > 0 && *apidl) {
362 SHELL32_GetItemAttributes (_IShellFolder_ (This), *apidl, rgfInOut);
367 TRACE ("-- result=0x%08lx\n", *rgfInOut);
372 /**************************************************************************
373 * ISF_Desktop_fnGetUIObjectOf
376 * HWND hwndOwner, //[in ] Parent window for any output
377 * UINT cidl, //[in ] array size
378 * LPCITEMIDLIST* apidl, //[in ] simple pidl array
379 * REFIID riid, //[in ] Requested Interface
380 * UINT* prgfInOut, //[ ] reserved
381 * LPVOID* ppvObject) //[out] Resulting Interface
384 static HRESULT WINAPI ISF_Desktop_fnGetUIObjectOf (IShellFolder2 * iface,
387 LPCITEMIDLIST * apidl,
388 REFIID riid, UINT * prgfInOut, LPVOID * ppvOut)
390 ICOM_THIS (IGenericSFImpl, iface);
393 IUnknown *pObj = NULL;
394 HRESULT hr = E_INVALIDARG;
396 TRACE ("(%p)->(0x%04x,%u,apidl=%p,%s,%p,%p)\n",
397 This, hwndOwner, cidl, apidl, shdebugstr_guid (riid), prgfInOut, ppvOut);
402 if (IsEqualIID (riid, &IID_IContextMenu) && (cidl >= 1)) {
403 pObj = (LPUNKNOWN) ISvItemCm_Constructor ((IShellFolder *) iface, This->pidlRoot, apidl, cidl);
405 } else if (IsEqualIID (riid, &IID_IDataObject) && (cidl >= 1)) {
406 pObj = (LPUNKNOWN) IDataObject_Constructor (hwndOwner, This->pidlRoot, apidl, cidl);
408 } else if (IsEqualIID (riid, &IID_IExtractIconA) && (cidl == 1)) {
409 pidl = ILCombine (This->pidlRoot, apidl[0]);
410 pObj = (LPUNKNOWN) IExtractIconA_Constructor (pidl);
413 } else if (IsEqualIID (riid, &IID_IDropTarget) && (cidl >= 1)) {
414 hr = IShellFolder_QueryInterface (iface, &IID_IDropTarget, (LPVOID *) & pObj);
424 TRACE ("(%p)->hr=0x%08lx\n", This, hr);
428 /**************************************************************************
429 * ISF_Desktop_fnGetDisplayNameOf
432 * special case: pidl = null gives desktop-name back
434 DWORD WINAPI __SHGUIDToStringA (REFGUID guid, LPSTR str)
436 CHAR sFormat[52] = "{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}";
438 return wsprintfA (str, sFormat,
439 guid->Data1, guid->Data2, guid->Data3,
440 guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
441 guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7]);
445 static HRESULT WINAPI ISF_Desktop_fnGetDisplayNameOf (IShellFolder2 * iface,
446 LPCITEMIDLIST pidl, DWORD dwFlags, LPSTRRET strRet)
448 ICOM_THIS (IGenericSFImpl, iface);
450 CHAR szPath[MAX_PATH] = "";
454 TRACE ("(%p)->(pidl=%p,0x%08lx,%p)\n", This, pidl, dwFlags, strRet);
460 if (_ILIsDesktop (pidl)) {
461 if ((GET_SHGDN_RELATION (dwFlags) == SHGDN_NORMAL) && (GET_SHGDN_FOR (dwFlags) == SHGDN_FORPARSING)) {
462 lstrcpyA (szPath, This->sPathTarget);
464 HCR_GetClassName (&CLSID_ShellDesktop, szPath, MAX_PATH);
466 } else if (_ILIsPidlSimple (pidl)) {
467 if ((clsid = _ILGetGUIDPointer (pidl))) {
468 if (GET_SHGDN_FOR (dwFlags) == SHGDN_FORPARSING) {
469 int bWantsForParsing;
472 * we can only get a filesystem path from a shellfolder if the value WantsFORPARSING in
473 * CLSID\\{...}\\shellfolder exists
474 * exception: the MyComputer folder has this keys not but like any filesystem backed
475 * folder it needs these behaviour
477 if (IsEqualIID (clsid, &CLSID_MyComputer)) {
478 bWantsForParsing = 1;
480 /* get the "WantsFORPARSING" flag from the registry */
483 lstrcpyA (szRegPath, "CLSID\\");
484 __SHGUIDToStringA (clsid, &szRegPath[6]);
485 lstrcatA (szRegPath, "\\shellfolder");
488 SHGetValueA (HKEY_CLASSES_ROOT, szRegPath, "WantsFORPARSING", NULL, NULL, NULL));
491 if ((GET_SHGDN_RELATION (dwFlags) == SHGDN_NORMAL) && bWantsForParsing) {
492 /* we need the filesystem path to the destination folder. Only the folder itself can know it */
493 hr = SHELL32_GetDisplayNameOfChild (iface, pidl, dwFlags, szPath, MAX_PATH);
495 /* parsing name like ::{...} */
496 lstrcpyA (szPath, "::");
497 __SHGUIDToStringA (clsid, &szPath[2]);
500 /* user friendly name */
501 HCR_GetClassName (clsid, szPath, MAX_PATH);
504 /* file system folder */
505 _ILSimpleGetText (pidl, szPath, MAX_PATH);
508 /* a complex pidl, let the subfolder do the work */
509 hr = SHELL32_GetDisplayNameOfChild (iface, pidl, dwFlags, szPath, MAX_PATH);
512 if (SUCCEEDED (hr)) {
513 strRet->uType = STRRET_CSTR;
514 lstrcpynA (strRet->u.cStr, szPath, MAX_PATH);
517 TRACE ("-- (%p)->(%s,0x%08lx)\n", This, szPath, hr);
521 /**************************************************************************
522 * ISF_Desktop_fnSetNameOf
523 * Changes the name of a file object or subfolder, possibly changing its item
524 * identifier in the process.
527 * HWND hwndOwner, //[in ] Owner window for output
528 * LPCITEMIDLIST pidl, //[in ] simple pidl of item to change
529 * LPCOLESTR lpszName, //[in ] the items new display name
530 * DWORD dwFlags, //[in ] SHGNO formatting flags
531 * LPITEMIDLIST* ppidlOut) //[out] simple pidl returned
533 static HRESULT WINAPI ISF_Desktop_fnSetNameOf (IShellFolder2 * iface, HWND hwndOwner, LPCITEMIDLIST pidl, /*simple pidl */
534 LPCOLESTR lpName, DWORD dwFlags, LPITEMIDLIST * pPidlOut)
536 ICOM_THIS (IGenericSFImpl, iface);
538 FIXME ("(%p)->(%u,pidl=%p,%s,%lu,%p)\n", This, hwndOwner, pidl, debugstr_w (lpName), dwFlags, pPidlOut);
543 static HRESULT WINAPI ISF_Desktop_fnGetDefaultSearchGUID (IShellFolder2 * iface, GUID * pguid)
545 ICOM_THIS (IGenericSFImpl, iface);
547 FIXME ("(%p)\n", This);
550 static HRESULT WINAPI ISF_Desktop_fnEnumSearches (IShellFolder2 * iface, IEnumExtraSearch ** ppenum)
552 ICOM_THIS (IGenericSFImpl, iface);
553 FIXME ("(%p)\n", This);
556 static HRESULT WINAPI ISF_Desktop_fnGetDefaultColumn (IShellFolder2 * iface,
557 DWORD dwRes, ULONG * pSort, ULONG * pDisplay)
559 ICOM_THIS (IGenericSFImpl, iface);
561 TRACE ("(%p)\n", This);
570 static HRESULT WINAPI ISF_Desktop_fnGetDefaultColumnState (IShellFolder2 * iface, UINT iColumn, DWORD * pcsFlags)
572 ICOM_THIS (IGenericSFImpl, iface);
574 TRACE ("(%p)\n", This);
576 if (!pcsFlags || iColumn >= DESKTOPSHELLVIEWCOLUMNS)
579 *pcsFlags = DesktopSFHeader[iColumn].pcsFlags;
583 static HRESULT WINAPI ISF_Desktop_fnGetDetailsEx (IShellFolder2 * iface,
584 LPCITEMIDLIST pidl, const SHCOLUMNID * pscid, VARIANT * pv)
586 ICOM_THIS (IGenericSFImpl, iface);
587 FIXME ("(%p)\n", This);
591 static HRESULT WINAPI ISF_Desktop_fnGetDetailsOf (IShellFolder2 * iface,
592 LPCITEMIDLIST pidl, UINT iColumn, SHELLDETAILS * psd)
594 ICOM_THIS (IGenericSFImpl, iface);
598 TRACE ("(%p)->(%p %i %p)\n", This, pidl, iColumn, psd);
600 if (!psd || iColumn >= DESKTOPSHELLVIEWCOLUMNS)
604 psd->fmt = DesktopSFHeader[iColumn].fmt;
605 psd->cxChar = DesktopSFHeader[iColumn].cxChar;
606 psd->str.uType = STRRET_CSTR;
607 LoadStringA (shell32_hInstance, DesktopSFHeader[iColumn].colnameid, psd->str.u.cStr, MAX_PATH);
610 /* the data from the pidl */
613 hr = IShellFolder_GetDisplayNameOf (iface, pidl, SHGDN_NORMAL | SHGDN_INFOLDER, &psd->str);
616 _ILGetFileSize (pidl, psd->str.u.cStr, MAX_PATH);
619 _ILGetFileType (pidl, psd->str.u.cStr, MAX_PATH);
622 _ILGetFileDate (pidl, psd->str.u.cStr, MAX_PATH);
624 case 4: /* attributes */
625 _ILGetFileAttributes (pidl, psd->str.u.cStr, MAX_PATH);
629 psd->str.uType = STRRET_CSTR;
634 static HRESULT WINAPI ISF_Desktop_fnMapNameToSCID (IShellFolder2 * iface, LPCWSTR pwszName, SHCOLUMNID * pscid)
636 ICOM_THIS (IGenericSFImpl, iface);
637 FIXME ("(%p)\n", This);
641 static ICOM_VTABLE (IShellFolder2) vt_MCFldr_ShellFolder2 =
643 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
644 ISF_Desktop_fnQueryInterface,
645 ISF_Desktop_fnAddRef,
646 ISF_Desktop_fnRelease,
647 ISF_Desktop_fnParseDisplayName,
648 ISF_Desktop_fnEnumObjects,
649 ISF_Desktop_fnBindToObject,
650 ISF_Desktop_fnBindToStorage,
651 ISF_Desktop_fnCompareIDs,
652 ISF_Desktop_fnCreateViewObject,
653 ISF_Desktop_fnGetAttributesOf,
654 ISF_Desktop_fnGetUIObjectOf,
655 ISF_Desktop_fnGetDisplayNameOf,
656 ISF_Desktop_fnSetNameOf,
658 ISF_Desktop_fnGetDefaultSearchGUID,
659 ISF_Desktop_fnEnumSearches,
660 ISF_Desktop_fnGetDefaultColumn,
661 ISF_Desktop_fnGetDefaultColumnState,
662 ISF_Desktop_fnGetDetailsEx,
663 ISF_Desktop_fnGetDetailsOf,
664 ISF_Desktop_fnMapNameToSCID};