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"
31 #define NONAMELESSUNION
32 #define NONAMELESSSTRUCT
44 #include "undocshell.h"
45 #include "shell32_main.h"
48 #include "shellfolder.h"
49 #include "wine/debug.h"
53 WINE_DEFAULT_DEBUG_CHANNEL (shell);
55 /***********************************************************************
56 * Desktopfolder implementation
60 ICOM_VFIELD (IShellFolder2);
65 /* both paths are parsible from the desktop */
66 LPSTR sPathTarget; /* complete path to target used for enumeration and ChangeNotify */
67 LPITEMIDLIST pidlRoot; /* absolute pidl */
69 int dwAttributes; /* attributes returned by GetAttributesOf FIXME: use it */
71 UINT cfShellIDList; /* clipboardformat for IDropTarget */
72 BOOL fAcceptFmt; /* flag for pending Drop */
75 #define _IUnknown_(This) (IShellFolder*)&(This->lpVtbl)
76 #define _IShellFolder_(This) (IShellFolder*)&(This->lpVtbl)
78 static struct ICOM_VTABLE (IShellFolder2) vt_MCFldr_ShellFolder2;
80 static shvheader DesktopSFHeader[] = {
81 {IDS_SHV_COLUMN1, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 15},
82 {IDS_SHV_COLUMN2, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
83 {IDS_SHV_COLUMN3, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
84 {IDS_SHV_COLUMN4, SHCOLSTATE_TYPE_DATE | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 12},
85 {IDS_SHV_COLUMN5, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 5}
88 #define DESKTOPSHELLVIEWCOLUMNS 5
90 /**************************************************************************
91 * ISF_Desktop_Constructor
93 HRESULT WINAPI ISF_Desktop_Constructor (IUnknown * pUnkOuter, REFIID riid, LPVOID * ppv)
96 char szMyPath[MAX_PATH];
98 TRACE ("unkOut=%p %s\n", pUnkOuter, shdebugstr_guid (riid));
103 return CLASS_E_NOAGGREGATION;
105 if (!SHGetSpecialFolderPathA (0, szMyPath, CSIDL_DESKTOPDIRECTORY, TRUE))
108 sf = (IGenericSFImpl *) LocalAlloc (GMEM_ZEROINIT, sizeof (IGenericSFImpl));
110 return E_OUTOFMEMORY;
113 sf->lpVtbl = &vt_MCFldr_ShellFolder2;
114 sf->pidlRoot = _ILCreateDesktop (); /* my qualified pidl */
115 sf->sPathTarget = SHAlloc (strlen (szMyPath) + 1);
116 lstrcpyA (sf->sPathTarget, szMyPath);
118 if (!SUCCEEDED (IUnknown_QueryInterface (_IUnknown_ (sf), riid, ppv))) {
119 IUnknown_Release (_IUnknown_ (sf));
120 return E_NOINTERFACE;
123 TRACE ("--(%p)\n", sf);
127 /**************************************************************************
128 * ISF_Desktop_fnQueryInterface
130 * NOTES supports not IPersist/IPersistFolder
132 static HRESULT WINAPI ISF_Desktop_fnQueryInterface (IShellFolder2 * iface, REFIID riid, LPVOID * ppvObj)
134 ICOM_THIS (IGenericSFImpl, iface);
136 TRACE ("(%p)->(%s,%p)\n", This, shdebugstr_guid (riid), ppvObj);
140 if (IsEqualIID (riid, &IID_IUnknown) || IsEqualIID (riid, &IID_IShellFolder)
141 || IsEqualIID (riid, &IID_IShellFolder2)) {
146 IUnknown_AddRef ((IUnknown *) (*ppvObj));
147 TRACE ("-- Interface: (%p)->(%p)\n", ppvObj, *ppvObj);
150 TRACE ("-- Interface: E_NOINTERFACE\n");
151 return E_NOINTERFACE;
154 static ULONG WINAPI ISF_Desktop_fnAddRef (IShellFolder2 * iface)
156 ICOM_THIS (IGenericSFImpl, iface);
158 TRACE ("(%p)->(count=%lu)\n", This, This->ref);
160 return ++(This->ref);
163 static ULONG WINAPI ISF_Desktop_fnRelease (IShellFolder2 * iface)
165 ICOM_THIS (IGenericSFImpl, iface);
167 TRACE ("(%p)->(count=%lu)\n", This, This->ref);
169 if (!--(This->ref)) {
170 TRACE ("-- destroying IShellFolder(%p)\n", This);
172 SHFree (This->pidlRoot);
173 if (This->sPathTarget)
174 SHFree (This->sPathTarget);
175 LocalFree ((HLOCAL) This);
181 /**************************************************************************
182 * ISF_Desktop_fnParseDisplayName
185 * "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}" and "" binds
188 static HRESULT WINAPI ISF_Desktop_fnParseDisplayName (IShellFolder2 * iface,
191 LPOLESTR lpszDisplayName,
192 DWORD * pchEaten, LPITEMIDLIST * ppidl, DWORD * pdwAttributes)
194 ICOM_THIS (IGenericSFImpl, iface);
196 WCHAR szElement[MAX_PATH];
197 LPCWSTR szNext = NULL;
198 LPITEMIDLIST pidlTemp = NULL;
199 HRESULT hr = E_INVALIDARG;
200 char szPath[MAX_PATH];
204 TRACE ("(%p)->(HWND=%p,%p,%p=%s,%p,pidl=%p,%p)\n",
205 This, hwndOwner, pbc, lpszDisplayName, debugstr_w (lpszDisplayName), pchEaten, ppidl, pdwAttributes);
207 if (!lpszDisplayName || !ppidl)
213 *pchEaten = 0; /* strange but like the original */
215 if (lpszDisplayName[0] == ':' && lpszDisplayName[1] == ':') {
216 szNext = GetNextElementW (lpszDisplayName, szElement, MAX_PATH);
217 TRACE ("-- element: %s\n", debugstr_w (szElement));
218 SHCLSIDFromStringW (szElement + 2, &clsid);
219 pidlTemp = _ILCreate (PT_MYCOMP, &clsid, sizeof (clsid));
220 } else if (PathGetDriveNumberW (lpszDisplayName) >= 0) {
221 /* it's a filesystem path with a drive. Let MyComputer parse it */
222 pidlTemp = _ILCreateMyComputer ();
223 szNext = lpszDisplayName;
224 } else if (PathIsUNCW(lpszDisplayName)) {
225 pidlTemp = _ILCreateNetwork();
226 szNext = lpszDisplayName;
228 /* it's a filesystem path on the desktop. Let a FSFolder parse it */
230 if (*lpszDisplayName) {
231 /* build a complete path to create a simple pidl */
232 lstrcpyA(szPath, This->sPathTarget);
233 PathAddBackslashA(szPath);
234 len = lstrlenA(szPath);
235 WideCharToMultiByte(CP_ACP, 0, lpszDisplayName, -1, szPath + len, MAX_PATH - len, NULL, NULL);
236 pidlTemp = _ILCreateFromPathA(szPath);
238 pidlTemp = _ILCreateMyComputer();
245 if (szNext && *szNext) {
246 hr = SHELL32_ParseNextElement (iface, hwndOwner, pbc, &pidlTemp, (LPOLESTR) szNext, pchEaten, pdwAttributes);
249 if (pdwAttributes && *pdwAttributes) {
250 SHELL32_GetItemAttributes (_IShellFolder_ (This), pidlTemp, pdwAttributes);
257 TRACE ("(%p)->(-- ret=0x%08lx)\n", This, hr);
262 /**************************************************************************
263 * ISF_Desktop_fnEnumObjects
265 static HRESULT WINAPI ISF_Desktop_fnEnumObjects (IShellFolder2 * iface,
266 HWND hwndOwner, DWORD dwFlags, LPENUMIDLIST * ppEnumIDList)
268 ICOM_THIS (IGenericSFImpl, iface);
270 TRACE ("(%p)->(HWND=%p flags=0x%08lx pplist=%p)\n", This, hwndOwner, dwFlags, ppEnumIDList);
272 *ppEnumIDList = NULL;
273 *ppEnumIDList = IEnumIDList_Constructor (NULL, dwFlags, EIDL_DESK);
275 TRACE ("-- (%p)->(new ID List: %p)\n", This, *ppEnumIDList);
278 return E_OUTOFMEMORY;
283 /**************************************************************************
284 * ISF_Desktop_fnBindToObject
286 static HRESULT WINAPI ISF_Desktop_fnBindToObject (IShellFolder2 * iface,
287 LPCITEMIDLIST pidl, LPBC pbcReserved, REFIID riid, LPVOID * ppvOut)
289 ICOM_THIS (IGenericSFImpl, iface);
291 TRACE ("(%p)->(pidl=%p,%p,%s,%p)\n", This, pidl, pbcReserved, shdebugstr_guid (riid), ppvOut);
293 return SHELL32_BindToChild (This->pidlRoot, This->sPathTarget, pidl, riid, ppvOut);
296 /**************************************************************************
297 * ISF_Desktop_fnBindToStorage
299 static HRESULT WINAPI ISF_Desktop_fnBindToStorage (IShellFolder2 * iface,
300 LPCITEMIDLIST pidl, LPBC pbcReserved, REFIID riid, LPVOID * ppvOut)
302 ICOM_THIS (IGenericSFImpl, iface);
304 FIXME ("(%p)->(pidl=%p,%p,%s,%p) stub\n", This, pidl, pbcReserved, shdebugstr_guid (riid), ppvOut);
310 /**************************************************************************
311 * ISF_Desktop_fnCompareIDs
314 static HRESULT WINAPI ISF_Desktop_fnCompareIDs (IShellFolder2 * iface,
315 LPARAM lParam, LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
317 ICOM_THIS (IGenericSFImpl, iface);
321 TRACE ("(%p)->(0x%08lx,pidl1=%p,pidl2=%p)\n", This, lParam, pidl1, pidl2);
322 nReturn = SHELL32_CompareIDs (_IShellFolder_ (This), lParam, pidl1, pidl2);
323 TRACE ("-- %i\n", nReturn);
327 /**************************************************************************
328 * ISF_Desktop_fnCreateViewObject
330 static HRESULT WINAPI ISF_Desktop_fnCreateViewObject (IShellFolder2 * iface,
331 HWND hwndOwner, REFIID riid, LPVOID * ppvOut)
333 ICOM_THIS (IGenericSFImpl, iface);
335 LPSHELLVIEW pShellView;
336 HRESULT hr = E_INVALIDARG;
338 TRACE ("(%p)->(hwnd=%p,%s,%p)\n", This, hwndOwner, shdebugstr_guid (riid), ppvOut);
343 if (IsEqualIID (riid, &IID_IDropTarget)) {
344 WARN ("IDropTarget not implemented\n");
346 } else if (IsEqualIID (riid, &IID_IContextMenu)) {
347 WARN ("IContextMenu not implemented\n");
349 } else if (IsEqualIID (riid, &IID_IShellView)) {
350 pShellView = IShellView_Constructor ((IShellFolder *) iface);
352 hr = IShellView_QueryInterface (pShellView, riid, ppvOut);
353 IShellView_Release (pShellView);
357 TRACE ("-- (%p)->(interface=%p)\n", This, ppvOut);
361 /**************************************************************************
362 * ISF_Desktop_fnGetAttributesOf
364 static HRESULT WINAPI ISF_Desktop_fnGetAttributesOf (IShellFolder2 * iface,
365 UINT cidl, LPCITEMIDLIST * apidl, DWORD * rgfInOut)
367 ICOM_THIS (IGenericSFImpl, iface);
371 TRACE ("(%p)->(cidl=%d apidl=%p mask=0x%08lx)\n", This, cidl, apidl, *rgfInOut);
373 if ((!cidl) || (!apidl) || (!rgfInOut))
376 while (cidl > 0 && *apidl) {
378 SHELL32_GetItemAttributes (_IShellFolder_ (This), *apidl, rgfInOut);
383 TRACE ("-- result=0x%08lx\n", *rgfInOut);
388 /**************************************************************************
389 * ISF_Desktop_fnGetUIObjectOf
392 * HWND hwndOwner, //[in ] Parent window for any output
393 * UINT cidl, //[in ] array size
394 * LPCITEMIDLIST* apidl, //[in ] simple pidl array
395 * REFIID riid, //[in ] Requested Interface
396 * UINT* prgfInOut, //[ ] reserved
397 * LPVOID* ppvObject) //[out] Resulting Interface
400 static HRESULT WINAPI ISF_Desktop_fnGetUIObjectOf (IShellFolder2 * iface,
403 LPCITEMIDLIST * apidl,
404 REFIID riid, UINT * prgfInOut, LPVOID * ppvOut)
406 ICOM_THIS (IGenericSFImpl, iface);
409 IUnknown *pObj = NULL;
410 HRESULT hr = E_INVALIDARG;
412 TRACE ("(%p)->(%p,%u,apidl=%p,%s,%p,%p)\n",
413 This, hwndOwner, cidl, apidl, shdebugstr_guid (riid), prgfInOut, ppvOut);
418 if (IsEqualIID (riid, &IID_IContextMenu)) {
419 pObj = (LPUNKNOWN) ISvItemCm_Constructor ((IShellFolder *) iface, This->pidlRoot, apidl, cidl);
421 } else if (IsEqualIID (riid, &IID_IDataObject) && (cidl >= 1)) {
422 pObj = (LPUNKNOWN) IDataObject_Constructor (hwndOwner, This->pidlRoot, apidl, cidl);
424 } else if (IsEqualIID (riid, &IID_IExtractIconA) && (cidl == 1)) {
425 pidl = ILCombine (This->pidlRoot, apidl[0]);
426 pObj = (LPUNKNOWN) IExtractIconA_Constructor (pidl);
429 } else if (IsEqualIID (riid, &IID_IExtractIconW) && (cidl == 1)) {
430 pidl = ILCombine (This->pidlRoot, apidl[0]);
431 pObj = (LPUNKNOWN) IExtractIconW_Constructor (pidl);
434 } else if (IsEqualIID (riid, &IID_IDropTarget) && (cidl >= 1)) {
435 hr = IShellFolder_QueryInterface (iface, &IID_IDropTarget, (LPVOID *) & pObj);
436 } else if ((IsEqualIID(riid,&IID_IShellLinkW) || IsEqualIID(riid,&IID_IShellLinkA))
438 pidl = ILCombine (This->pidlRoot, apidl[0]);
439 hr = IShellLink_ConstructFromFile(NULL, riid, pidl, (LPVOID*)&pObj);
445 if (SUCCEEDED(hr) && !pObj)
450 TRACE ("(%p)->hr=0x%08lx\n", This, hr);
454 /**************************************************************************
455 * ISF_Desktop_fnGetDisplayNameOf
458 * special case: pidl = null gives desktop-name back
460 static HRESULT WINAPI ISF_Desktop_fnGetDisplayNameOf (IShellFolder2 * iface,
461 LPCITEMIDLIST pidl, DWORD dwFlags, LPSTRRET strRet)
463 ICOM_THIS (IGenericSFImpl, iface);
465 CHAR szPath[MAX_PATH];
471 TRACE ("(%p)->(pidl=%p,0x%08lx,%p)\n", This, pidl, dwFlags, strRet);
477 if (_ILIsDesktop (pidl)) {
478 if ((GET_SHGDN_RELATION (dwFlags) == SHGDN_NORMAL) && (GET_SHGDN_FOR (dwFlags) == SHGDN_FORPARSING)) {
479 lstrcpyA (szPath, This->sPathTarget);
481 HCR_GetClassNameA(&CLSID_ShellDesktop, szPath, MAX_PATH);
483 } else if (_ILIsPidlSimple (pidl)) {
484 if ((clsid = _ILGetGUIDPointer (pidl))) {
485 if (GET_SHGDN_FOR (dwFlags) == SHGDN_FORPARSING) {
486 int bWantsForParsing;
489 * we can only get a filesystem path from a shellfolder if the value WantsFORPARSING in
490 * CLSID\\{...}\\shellfolder exists
491 * exception: the MyComputer folder has this keys not but like any filesystem backed
492 * folder it needs these behaviour
494 if (IsEqualIID (clsid, &CLSID_MyComputer)) {
495 bWantsForParsing = 1;
497 /* get the "WantsFORPARSING" flag from the registry */
500 lstrcpyA (szRegPath, "CLSID\\");
501 SHELL32_GUIDToStringA (clsid, &szRegPath[6]);
502 lstrcatA (szRegPath, "\\shellfolder");
505 SHGetValueA (HKEY_CLASSES_ROOT, szRegPath, "WantsFORPARSING", NULL, NULL, NULL));
508 if ((GET_SHGDN_RELATION (dwFlags) == SHGDN_NORMAL) && bWantsForParsing) {
509 /* we need the filesystem path to the destination folder. Only the folder itself can know it */
510 hr = SHELL32_GetDisplayNameOfChild (iface, pidl, dwFlags, szPath, MAX_PATH);
512 /* parsing name like ::{...} */
513 lstrcpyA (szPath, "::");
514 SHELL32_GUIDToStringA (clsid, &szPath[2]);
517 /* user friendly name */
518 HCR_GetClassNameA (clsid, szPath, MAX_PATH);
521 /* file system folder */
522 _ILSimpleGetText (pidl, szPath, MAX_PATH);
524 if (!_ILIsFolder(pidl))
525 SHELL_FS_ProcessDisplayFilename(szPath, dwFlags);
528 /* a complex pidl, let the subfolder do the work */
529 hr = SHELL32_GetDisplayNameOfChild (iface, pidl, dwFlags, szPath, MAX_PATH);
532 if (SUCCEEDED (hr)) {
533 strRet->uType = STRRET_CSTR;
534 lstrcpynA (strRet->u.cStr, szPath, MAX_PATH);
537 TRACE ("-- (%p)->(%s,0x%08lx)\n", This, szPath, hr);
541 /**************************************************************************
542 * ISF_Desktop_fnSetNameOf
543 * Changes the name of a file object or subfolder, possibly changing its item
544 * identifier in the process.
547 * HWND hwndOwner, //[in ] Owner window for output
548 * LPCITEMIDLIST pidl, //[in ] simple pidl of item to change
549 * LPCOLESTR lpszName, //[in ] the items new display name
550 * DWORD dwFlags, //[in ] SHGNO formatting flags
551 * LPITEMIDLIST* ppidlOut) //[out] simple pidl returned
553 static HRESULT WINAPI ISF_Desktop_fnSetNameOf (IShellFolder2 * iface, HWND hwndOwner, LPCITEMIDLIST pidl, /*simple pidl */
554 LPCOLESTR lpName, DWORD dwFlags, LPITEMIDLIST * pPidlOut)
556 ICOM_THIS (IGenericSFImpl, iface);
558 FIXME ("(%p)->(%p,pidl=%p,%s,%lu,%p)\n", This, hwndOwner, pidl, debugstr_w (lpName), dwFlags, pPidlOut);
563 static HRESULT WINAPI ISF_Desktop_fnGetDefaultSearchGUID (IShellFolder2 * iface, GUID * pguid)
565 ICOM_THIS (IGenericSFImpl, iface);
567 FIXME ("(%p)\n", This);
570 static HRESULT WINAPI ISF_Desktop_fnEnumSearches (IShellFolder2 * iface, IEnumExtraSearch ** ppenum)
572 ICOM_THIS (IGenericSFImpl, iface);
573 FIXME ("(%p)\n", This);
576 static HRESULT WINAPI ISF_Desktop_fnGetDefaultColumn (IShellFolder2 * iface,
577 DWORD dwRes, ULONG * pSort, ULONG * pDisplay)
579 ICOM_THIS (IGenericSFImpl, iface);
581 TRACE ("(%p)\n", This);
590 static HRESULT WINAPI ISF_Desktop_fnGetDefaultColumnState (IShellFolder2 * iface, UINT iColumn, DWORD * pcsFlags)
592 ICOM_THIS (IGenericSFImpl, iface);
594 TRACE ("(%p)\n", This);
596 if (!pcsFlags || iColumn >= DESKTOPSHELLVIEWCOLUMNS)
599 *pcsFlags = DesktopSFHeader[iColumn].pcsFlags;
603 static HRESULT WINAPI ISF_Desktop_fnGetDetailsEx (IShellFolder2 * iface,
604 LPCITEMIDLIST pidl, const SHCOLUMNID * pscid, VARIANT * pv)
606 ICOM_THIS (IGenericSFImpl, iface);
607 FIXME ("(%p)\n", This);
611 static HRESULT WINAPI ISF_Desktop_fnGetDetailsOf (IShellFolder2 * iface,
612 LPCITEMIDLIST pidl, UINT iColumn, SHELLDETAILS * psd)
614 ICOM_THIS (IGenericSFImpl, iface);
618 TRACE ("(%p)->(%p %i %p)\n", This, pidl, iColumn, psd);
620 if (!psd || iColumn >= DESKTOPSHELLVIEWCOLUMNS)
624 psd->fmt = DesktopSFHeader[iColumn].fmt;
625 psd->cxChar = DesktopSFHeader[iColumn].cxChar;
626 psd->str.uType = STRRET_CSTR;
627 LoadStringA (shell32_hInstance, DesktopSFHeader[iColumn].colnameid, psd->str.u.cStr, MAX_PATH);
630 /* the data from the pidl */
633 hr = IShellFolder_GetDisplayNameOf (iface, pidl, SHGDN_NORMAL | SHGDN_INFOLDER, &psd->str);
636 _ILGetFileSize (pidl, psd->str.u.cStr, MAX_PATH);
639 _ILGetFileType (pidl, psd->str.u.cStr, MAX_PATH);
642 _ILGetFileDate (pidl, psd->str.u.cStr, MAX_PATH);
644 case 4: /* attributes */
645 _ILGetFileAttributes (pidl, psd->str.u.cStr, MAX_PATH);
649 psd->str.uType = STRRET_CSTR;
654 static HRESULT WINAPI ISF_Desktop_fnMapColumnToSCID (IShellFolder2 * iface, UINT column, SHCOLUMNID * pscid)
656 ICOM_THIS (IGenericSFImpl, iface);
657 FIXME ("(%p)\n", This);
661 static ICOM_VTABLE (IShellFolder2) vt_MCFldr_ShellFolder2 =
663 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
664 ISF_Desktop_fnQueryInterface,
665 ISF_Desktop_fnAddRef,
666 ISF_Desktop_fnRelease,
667 ISF_Desktop_fnParseDisplayName,
668 ISF_Desktop_fnEnumObjects,
669 ISF_Desktop_fnBindToObject,
670 ISF_Desktop_fnBindToStorage,
671 ISF_Desktop_fnCompareIDs,
672 ISF_Desktop_fnCreateViewObject,
673 ISF_Desktop_fnGetAttributesOf,
674 ISF_Desktop_fnGetUIObjectOf,
675 ISF_Desktop_fnGetDisplayNameOf,
676 ISF_Desktop_fnSetNameOf,
678 ISF_Desktop_fnGetDefaultSearchGUID,
679 ISF_Desktop_fnEnumSearches,
680 ISF_Desktop_fnGetDefaultColumn,
681 ISF_Desktop_fnGetDefaultColumnState,
682 ISF_Desktop_fnGetDetailsEx,
683 ISF_Desktop_fnGetDetailsOf,
684 ISF_Desktop_fnMapColumnToSCID};