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 HRESULT WINAPI ISF_MyComputer_Constructor (IUnknown * pUnkOuter, REFIID riid, LPVOID * ppv);
80 static struct ICOM_VTABLE (IShellFolder2) vt_MCFldr_ShellFolder2;
82 static shvheader DesktopSFHeader[] = {
83 {IDS_SHV_COLUMN1, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 15},
84 {IDS_SHV_COLUMN2, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
85 {IDS_SHV_COLUMN3, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
86 {IDS_SHV_COLUMN4, SHCOLSTATE_TYPE_DATE | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 12},
87 {IDS_SHV_COLUMN5, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 5}
90 #define DESKTOPSHELLVIEWCOLUMNS 5
92 /**************************************************************************
93 * ISF_Desktop_Constructor
95 HRESULT WINAPI ISF_Desktop_Constructor (IUnknown * pUnkOuter, REFIID riid, LPVOID * ppv)
98 char szMyPath[MAX_PATH];
100 TRACE ("unkOut=%p %s\n", pUnkOuter, shdebugstr_guid (riid));
105 return CLASS_E_NOAGGREGATION;
107 if (!SHGetSpecialFolderPathA (0, szMyPath, CSIDL_DESKTOPDIRECTORY, TRUE))
110 sf = (IGenericSFImpl *) LocalAlloc (GMEM_ZEROINIT, sizeof (IGenericSFImpl));
112 return E_OUTOFMEMORY;
115 sf->lpVtbl = &vt_MCFldr_ShellFolder2;
116 sf->pidlRoot = _ILCreateDesktop (); /* my qualified pidl */
117 sf->sPathTarget = SHAlloc (strlen (szMyPath) + 1);
118 lstrcpyA (sf->sPathTarget, szMyPath);
120 if (!SUCCEEDED (IUnknown_QueryInterface (_IUnknown_ (sf), riid, ppv))) {
121 IUnknown_Release (_IUnknown_ (sf));
122 return E_NOINTERFACE;
125 TRACE ("--(%p)\n", sf);
129 /**************************************************************************
130 * ISF_Desktop_fnQueryInterface
132 * NOTES supports not IPersist/IPersistFolder
134 static HRESULT WINAPI ISF_Desktop_fnQueryInterface (IShellFolder2 * iface, REFIID riid, LPVOID * ppvObj)
136 ICOM_THIS (IGenericSFImpl, iface);
138 TRACE ("(%p)->(%s,%p)\n", This, shdebugstr_guid (riid), ppvObj);
142 if (IsEqualIID (riid, &IID_IUnknown) || IsEqualIID (riid, &IID_IShellFolder)
143 || IsEqualIID (riid, &IID_IShellFolder2)) {
148 IUnknown_AddRef ((IUnknown *) (*ppvObj));
149 TRACE ("-- Interface: (%p)->(%p)\n", ppvObj, *ppvObj);
152 TRACE ("-- Interface: E_NOINTERFACE\n");
153 return E_NOINTERFACE;
156 static ULONG WINAPI ISF_Desktop_fnAddRef (IShellFolder2 * iface)
158 ICOM_THIS (IGenericSFImpl, iface);
160 TRACE ("(%p)->(count=%lu)\n", This, This->ref);
162 return ++(This->ref);
165 static ULONG WINAPI ISF_Desktop_fnRelease (IShellFolder2 * iface)
167 ICOM_THIS (IGenericSFImpl, iface);
169 TRACE ("(%p)->(count=%lu)\n", This, This->ref);
171 if (!--(This->ref)) {
172 TRACE ("-- destroying IShellFolder(%p)\n", This);
174 SHFree (This->pidlRoot);
175 if (This->sPathTarget)
176 SHFree (This->sPathTarget);
177 LocalFree ((HLOCAL) This);
183 /**************************************************************************
184 * ISF_Desktop_fnParseDisplayName
187 * "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}" and "" binds
190 static HRESULT WINAPI ISF_Desktop_fnParseDisplayName (IShellFolder2 * iface,
193 LPOLESTR lpszDisplayName,
194 DWORD * pchEaten, LPITEMIDLIST * ppidl, DWORD * pdwAttributes)
196 ICOM_THIS (IGenericSFImpl, iface);
198 WCHAR szElement[MAX_PATH];
199 LPCWSTR szNext = NULL;
200 LPITEMIDLIST pidlTemp = NULL;
201 HRESULT hr = E_INVALIDARG;
202 char szPath[MAX_PATH];
206 TRACE ("(%p)->(HWND=%p,%p,%p=%s,%p,pidl=%p,%p)\n",
207 This, hwndOwner, pbc, lpszDisplayName, debugstr_w (lpszDisplayName), pchEaten, ppidl, pdwAttributes);
209 if (!lpszDisplayName || !ppidl)
215 *pchEaten = 0; /* strange but like the original */
217 if (lpszDisplayName[0] == ':' && lpszDisplayName[1] == ':') {
218 szNext = GetNextElementW (lpszDisplayName, szElement, MAX_PATH);
219 TRACE ("-- element: %s\n", debugstr_w (szElement));
220 SHCLSIDFromStringW (szElement + 2, &clsid);
221 pidlTemp = _ILCreate (PT_MYCOMP, &clsid, sizeof (clsid));
222 } else if (PathGetDriveNumberW (lpszDisplayName) >= 0) {
223 /* it's a filesystem path with a drive. Let MyComputer parse it */
224 pidlTemp = _ILCreateMyComputer ();
225 szNext = lpszDisplayName;
226 } else if (PathIsUNCW(lpszDisplayName)) {
227 pidlTemp = _ILCreateNetwork();
228 szNext = lpszDisplayName;
230 /* it's a filesystem path on the desktop. Let a FSFolder parse it */
232 /* build a complete path to create a simple pidl */
233 lstrcpyA(szPath, This->sPathTarget);
234 PathAddBackslashA(szPath);
235 len = lstrlenA(szPath);
236 WideCharToMultiByte(CP_ACP, 0, lpszDisplayName, -1, szPath + len, MAX_PATH - len, NULL, NULL);
237 pidlTemp = _ILCreateFromPathA(szPath);
242 if (szNext && *szNext) {
243 hr = SHELL32_ParseNextElement (iface, hwndOwner, pbc, &pidlTemp, (LPOLESTR) szNext, pchEaten, pdwAttributes);
246 if (pdwAttributes && *pdwAttributes) {
247 SHELL32_GetItemAttributes (_IShellFolder_ (This), pidlTemp, pdwAttributes);
254 TRACE ("(%p)->(-- ret=0x%08lx)\n", This, hr);
259 /**************************************************************************
260 * ISF_Desktop_fnEnumObjects
262 static HRESULT WINAPI ISF_Desktop_fnEnumObjects (IShellFolder2 * iface,
263 HWND hwndOwner, DWORD dwFlags, LPENUMIDLIST * ppEnumIDList)
265 ICOM_THIS (IGenericSFImpl, iface);
267 TRACE ("(%p)->(HWND=%p flags=0x%08lx pplist=%p)\n", This, hwndOwner, dwFlags, ppEnumIDList);
269 *ppEnumIDList = NULL;
270 *ppEnumIDList = IEnumIDList_Constructor (NULL, dwFlags, EIDL_DESK);
272 TRACE ("-- (%p)->(new ID List: %p)\n", This, *ppEnumIDList);
275 return E_OUTOFMEMORY;
280 /**************************************************************************
281 * ISF_Desktop_fnBindToObject
283 static HRESULT WINAPI ISF_Desktop_fnBindToObject (IShellFolder2 * iface,
284 LPCITEMIDLIST pidl, LPBC pbcReserved, REFIID riid, LPVOID * ppvOut)
286 ICOM_THIS (IGenericSFImpl, iface);
288 TRACE ("(%p)->(pidl=%p,%p,%s,%p)\n", This, pidl, pbcReserved, shdebugstr_guid (riid), ppvOut);
290 return SHELL32_BindToChild (This->pidlRoot, This->sPathTarget, pidl, riid, ppvOut);
293 /**************************************************************************
294 * ISF_Desktop_fnBindToStorage
296 static HRESULT WINAPI ISF_Desktop_fnBindToStorage (IShellFolder2 * iface,
297 LPCITEMIDLIST pidl, LPBC pbcReserved, REFIID riid, LPVOID * ppvOut)
299 ICOM_THIS (IGenericSFImpl, iface);
301 FIXME ("(%p)->(pidl=%p,%p,%s,%p) stub\n", This, pidl, pbcReserved, shdebugstr_guid (riid), ppvOut);
307 /**************************************************************************
308 * ISF_Desktop_fnCompareIDs
311 static HRESULT WINAPI ISF_Desktop_fnCompareIDs (IShellFolder2 * iface,
312 LPARAM lParam, LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
314 ICOM_THIS (IGenericSFImpl, iface);
318 TRACE ("(%p)->(0x%08lx,pidl1=%p,pidl2=%p)\n", This, lParam, pidl1, pidl2);
319 nReturn = SHELL32_CompareIDs (_IShellFolder_ (This), lParam, pidl1, pidl2);
320 TRACE ("-- %i\n", nReturn);
324 /**************************************************************************
325 * ISF_Desktop_fnCreateViewObject
327 static HRESULT WINAPI ISF_Desktop_fnCreateViewObject (IShellFolder2 * iface,
328 HWND hwndOwner, REFIID riid, LPVOID * ppvOut)
330 ICOM_THIS (IGenericSFImpl, iface);
332 LPSHELLVIEW pShellView;
333 HRESULT hr = E_INVALIDARG;
335 TRACE ("(%p)->(hwnd=%p,%s,%p)\n", This, hwndOwner, shdebugstr_guid (riid), ppvOut);
340 if (IsEqualIID (riid, &IID_IDropTarget)) {
341 WARN ("IDropTarget not implemented\n");
343 } else if (IsEqualIID (riid, &IID_IContextMenu)) {
344 WARN ("IContextMenu not implemented\n");
346 } else if (IsEqualIID (riid, &IID_IShellView)) {
347 pShellView = IShellView_Constructor ((IShellFolder *) iface);
349 hr = IShellView_QueryInterface (pShellView, riid, ppvOut);
350 IShellView_Release (pShellView);
354 TRACE ("-- (%p)->(interface=%p)\n", This, ppvOut);
358 /**************************************************************************
359 * ISF_Desktop_fnGetAttributesOf
361 static HRESULT WINAPI ISF_Desktop_fnGetAttributesOf (IShellFolder2 * iface,
362 UINT cidl, LPCITEMIDLIST * apidl, DWORD * rgfInOut)
364 ICOM_THIS (IGenericSFImpl, iface);
368 TRACE ("(%p)->(cidl=%d apidl=%p mask=0x%08lx)\n", This, cidl, apidl, *rgfInOut);
370 if ((!cidl) || (!apidl) || (!rgfInOut))
373 while (cidl > 0 && *apidl) {
375 SHELL32_GetItemAttributes (_IShellFolder_ (This), *apidl, rgfInOut);
380 TRACE ("-- result=0x%08lx\n", *rgfInOut);
385 /**************************************************************************
386 * ISF_Desktop_fnGetUIObjectOf
389 * HWND hwndOwner, //[in ] Parent window for any output
390 * UINT cidl, //[in ] array size
391 * LPCITEMIDLIST* apidl, //[in ] simple pidl array
392 * REFIID riid, //[in ] Requested Interface
393 * UINT* prgfInOut, //[ ] reserved
394 * LPVOID* ppvObject) //[out] Resulting Interface
397 static HRESULT WINAPI ISF_Desktop_fnGetUIObjectOf (IShellFolder2 * iface,
400 LPCITEMIDLIST * apidl,
401 REFIID riid, UINT * prgfInOut, LPVOID * ppvOut)
403 ICOM_THIS (IGenericSFImpl, iface);
406 IUnknown *pObj = NULL;
407 HRESULT hr = E_INVALIDARG;
409 TRACE ("(%p)->(%p,%u,apidl=%p,%s,%p,%p)\n",
410 This, hwndOwner, cidl, apidl, shdebugstr_guid (riid), prgfInOut, ppvOut);
415 if (IsEqualIID (riid, &IID_IContextMenu) && (cidl >= 1)) {
416 pObj = (LPUNKNOWN) ISvItemCm_Constructor ((IShellFolder *) iface, This->pidlRoot, apidl, cidl);
418 } else if (IsEqualIID (riid, &IID_IDataObject) && (cidl >= 1)) {
419 pObj = (LPUNKNOWN) IDataObject_Constructor (hwndOwner, This->pidlRoot, apidl, cidl);
421 } else if (IsEqualIID (riid, &IID_IExtractIconA) && (cidl == 1)) {
422 pidl = ILCombine (This->pidlRoot, apidl[0]);
423 pObj = (LPUNKNOWN) IExtractIconA_Constructor (pidl);
426 } else if (IsEqualIID (riid, &IID_IExtractIconW) && (cidl == 1)) {
427 pidl = ILCombine (This->pidlRoot, apidl[0]);
428 pObj = (LPUNKNOWN) IExtractIconW_Constructor (pidl);
431 } else if (IsEqualIID (riid, &IID_IDropTarget) && (cidl >= 1)) {
432 hr = IShellFolder_QueryInterface (iface, &IID_IDropTarget, (LPVOID *) & pObj);
442 TRACE ("(%p)->hr=0x%08lx\n", This, hr);
446 /**************************************************************************
447 * ISF_Desktop_fnGetDisplayNameOf
450 * special case: pidl = null gives desktop-name back
452 static HRESULT WINAPI ISF_Desktop_fnGetDisplayNameOf (IShellFolder2 * iface,
453 LPCITEMIDLIST pidl, DWORD dwFlags, LPSTRRET strRet)
455 ICOM_THIS (IGenericSFImpl, iface);
457 CHAR szPath[MAX_PATH] = "";
461 TRACE ("(%p)->(pidl=%p,0x%08lx,%p)\n", This, pidl, dwFlags, strRet);
467 if (_ILIsDesktop (pidl)) {
468 if ((GET_SHGDN_RELATION (dwFlags) == SHGDN_NORMAL) && (GET_SHGDN_FOR (dwFlags) == SHGDN_FORPARSING)) {
469 lstrcpyA (szPath, This->sPathTarget);
471 HCR_GetClassNameA(&CLSID_ShellDesktop, szPath, MAX_PATH);
473 } else if (_ILIsPidlSimple (pidl)) {
474 if ((clsid = _ILGetGUIDPointer (pidl))) {
475 if (GET_SHGDN_FOR (dwFlags) == SHGDN_FORPARSING) {
476 int bWantsForParsing;
479 * we can only get a filesystem path from a shellfolder if the value WantsFORPARSING in
480 * CLSID\\{...}\\shellfolder exists
481 * exception: the MyComputer folder has this keys not but like any filesystem backed
482 * folder it needs these behaviour
484 if (IsEqualIID (clsid, &CLSID_MyComputer)) {
485 bWantsForParsing = 1;
487 /* get the "WantsFORPARSING" flag from the registry */
490 lstrcpyA (szRegPath, "CLSID\\");
491 SHELL32_GUIDToStringA (clsid, &szRegPath[6]);
492 lstrcatA (szRegPath, "\\shellfolder");
495 SHGetValueA (HKEY_CLASSES_ROOT, szRegPath, "WantsFORPARSING", NULL, NULL, NULL));
498 if ((GET_SHGDN_RELATION (dwFlags) == SHGDN_NORMAL) && bWantsForParsing) {
499 /* we need the filesystem path to the destination folder. Only the folder itself can know it */
500 hr = SHELL32_GetDisplayNameOfChild (iface, pidl, dwFlags, szPath, MAX_PATH);
502 /* parsing name like ::{...} */
503 lstrcpyA (szPath, "::");
504 SHELL32_GUIDToStringA (clsid, &szPath[2]);
507 /* user friendly name */
508 HCR_GetClassNameA (clsid, szPath, MAX_PATH);
511 /* file system folder */
512 _ILSimpleGetText (pidl, szPath, MAX_PATH);
515 /* a complex pidl, let the subfolder do the work */
516 hr = SHELL32_GetDisplayNameOfChild (iface, pidl, dwFlags, szPath, MAX_PATH);
519 if (SUCCEEDED (hr)) {
520 strRet->uType = STRRET_CSTR;
521 lstrcpynA (strRet->u.cStr, szPath, MAX_PATH);
524 TRACE ("-- (%p)->(%s,0x%08lx)\n", This, szPath, hr);
528 /**************************************************************************
529 * ISF_Desktop_fnSetNameOf
530 * Changes the name of a file object or subfolder, possibly changing its item
531 * identifier in the process.
534 * HWND hwndOwner, //[in ] Owner window for output
535 * LPCITEMIDLIST pidl, //[in ] simple pidl of item to change
536 * LPCOLESTR lpszName, //[in ] the items new display name
537 * DWORD dwFlags, //[in ] SHGNO formatting flags
538 * LPITEMIDLIST* ppidlOut) //[out] simple pidl returned
540 static HRESULT WINAPI ISF_Desktop_fnSetNameOf (IShellFolder2 * iface, HWND hwndOwner, LPCITEMIDLIST pidl, /*simple pidl */
541 LPCOLESTR lpName, DWORD dwFlags, LPITEMIDLIST * pPidlOut)
543 ICOM_THIS (IGenericSFImpl, iface);
545 FIXME ("(%p)->(%p,pidl=%p,%s,%lu,%p)\n", This, hwndOwner, pidl, debugstr_w (lpName), dwFlags, pPidlOut);
550 static HRESULT WINAPI ISF_Desktop_fnGetDefaultSearchGUID (IShellFolder2 * iface, GUID * pguid)
552 ICOM_THIS (IGenericSFImpl, iface);
554 FIXME ("(%p)\n", This);
557 static HRESULT WINAPI ISF_Desktop_fnEnumSearches (IShellFolder2 * iface, IEnumExtraSearch ** ppenum)
559 ICOM_THIS (IGenericSFImpl, iface);
560 FIXME ("(%p)\n", This);
563 static HRESULT WINAPI ISF_Desktop_fnGetDefaultColumn (IShellFolder2 * iface,
564 DWORD dwRes, ULONG * pSort, ULONG * pDisplay)
566 ICOM_THIS (IGenericSFImpl, iface);
568 TRACE ("(%p)\n", This);
577 static HRESULT WINAPI ISF_Desktop_fnGetDefaultColumnState (IShellFolder2 * iface, UINT iColumn, DWORD * pcsFlags)
579 ICOM_THIS (IGenericSFImpl, iface);
581 TRACE ("(%p)\n", This);
583 if (!pcsFlags || iColumn >= DESKTOPSHELLVIEWCOLUMNS)
586 *pcsFlags = DesktopSFHeader[iColumn].pcsFlags;
590 static HRESULT WINAPI ISF_Desktop_fnGetDetailsEx (IShellFolder2 * iface,
591 LPCITEMIDLIST pidl, const SHCOLUMNID * pscid, VARIANT * pv)
593 ICOM_THIS (IGenericSFImpl, iface);
594 FIXME ("(%p)\n", This);
598 static HRESULT WINAPI ISF_Desktop_fnGetDetailsOf (IShellFolder2 * iface,
599 LPCITEMIDLIST pidl, UINT iColumn, SHELLDETAILS * psd)
601 ICOM_THIS (IGenericSFImpl, iface);
605 TRACE ("(%p)->(%p %i %p)\n", This, pidl, iColumn, psd);
607 if (!psd || iColumn >= DESKTOPSHELLVIEWCOLUMNS)
611 psd->fmt = DesktopSFHeader[iColumn].fmt;
612 psd->cxChar = DesktopSFHeader[iColumn].cxChar;
613 psd->str.uType = STRRET_CSTR;
614 LoadStringA (shell32_hInstance, DesktopSFHeader[iColumn].colnameid, psd->str.u.cStr, MAX_PATH);
617 /* the data from the pidl */
620 hr = IShellFolder_GetDisplayNameOf (iface, pidl, SHGDN_NORMAL | SHGDN_INFOLDER, &psd->str);
623 _ILGetFileSize (pidl, psd->str.u.cStr, MAX_PATH);
626 _ILGetFileType (pidl, psd->str.u.cStr, MAX_PATH);
629 _ILGetFileDate (pidl, psd->str.u.cStr, MAX_PATH);
631 case 4: /* attributes */
632 _ILGetFileAttributes (pidl, psd->str.u.cStr, MAX_PATH);
636 psd->str.uType = STRRET_CSTR;
641 static HRESULT WINAPI ISF_Desktop_fnMapColumnToSCID (IShellFolder2 * iface, UINT column, SHCOLUMNID * pscid)
643 ICOM_THIS (IGenericSFImpl, iface);
644 FIXME ("(%p)\n", This);
648 static ICOM_VTABLE (IShellFolder2) vt_MCFldr_ShellFolder2 =
650 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
651 ISF_Desktop_fnQueryInterface,
652 ISF_Desktop_fnAddRef,
653 ISF_Desktop_fnRelease,
654 ISF_Desktop_fnParseDisplayName,
655 ISF_Desktop_fnEnumObjects,
656 ISF_Desktop_fnBindToObject,
657 ISF_Desktop_fnBindToStorage,
658 ISF_Desktop_fnCompareIDs,
659 ISF_Desktop_fnCreateViewObject,
660 ISF_Desktop_fnGetAttributesOf,
661 ISF_Desktop_fnGetUIObjectOf,
662 ISF_Desktop_fnGetDisplayNameOf,
663 ISF_Desktop_fnSetNameOf,
665 ISF_Desktop_fnGetDefaultSearchGUID,
666 ISF_Desktop_fnEnumSearches,
667 ISF_Desktop_fnGetDefaultColumn,
668 ISF_Desktop_fnGetDefaultColumnState,
669 ISF_Desktop_fnGetDetailsEx,
670 ISF_Desktop_fnGetDetailsOf,
671 ISF_Desktop_fnMapColumnToSCID};