push e1d8a1293d44015bb0894687d02c5c53339996f7
[wine/hacks.git] / dlls / shell32 / shfldr_desktop.c
blobc9b74123d1b75d46784ecbe65f349e74f0a1267c
2 /*
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "config.h"
24 #include "wine/port.h"
26 #include <stdlib.h>
27 #include <string.h>
28 #include <stdarg.h>
29 #include <stdio.h>
31 #define COBJMACROS
32 #define NONAMELESSUNION
33 #define NONAMELESSSTRUCT
35 #include "winerror.h"
36 #include "windef.h"
37 #include "winbase.h"
38 #include "winreg.h"
39 #include "wingdi.h"
40 #include "winuser.h"
42 #include "ole2.h"
43 #include "shlguid.h"
45 #include "enumidlist.h"
46 #include "pidl.h"
47 #include "undocshell.h"
48 #include "shell32_main.h"
49 #include "shresdef.h"
50 #include "shlwapi.h"
51 #include "shellfolder.h"
52 #include "wine/debug.h"
53 #include "debughlp.h"
54 #include "shfldr.h"
56 WINE_DEFAULT_DEBUG_CHANNEL (shell);
58 /* Undocumented functions from shdocvw */
59 extern HRESULT WINAPI IEParseDisplayNameWithBCW(DWORD codepage, LPCWSTR lpszDisplayName, LPBC pbc, LPITEMIDLIST *ppidl);
62 /***********************************************************************
63 * Desktopfolder implementation
66 typedef struct {
67 const IShellFolder2Vtbl *lpVtbl;
68 LONG ref;
70 /* both paths are parsible from the desktop */
71 LPWSTR sPathTarget; /* complete path to target used for enumeration and ChangeNotify */
72 LPITEMIDLIST pidlRoot; /* absolute pidl */
74 UINT cfShellIDList; /* clipboardformat for IDropTarget */
75 BOOL fAcceptFmt; /* flag for pending Drop */
76 } IGenericSFImpl;
78 #define _IUnknown_(This) (IShellFolder*)&(This->lpVtbl)
79 #define _IShellFolder_(This) (IShellFolder*)&(This->lpVtbl)
81 static const shvheader DesktopSFHeader[] = {
82 {IDS_SHV_COLUMN1, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 15},
83 {IDS_SHV_COLUMN2, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
84 {IDS_SHV_COLUMN3, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
85 {IDS_SHV_COLUMN4, SHCOLSTATE_TYPE_DATE | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 12},
86 {IDS_SHV_COLUMN5, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 5}
89 #define DESKTOPSHELLVIEWCOLUMNS 5
91 /**************************************************************************
92 * ISF_Desktop_fnQueryInterface
94 * NOTES supports not IPersist/IPersistFolder
96 static HRESULT WINAPI ISF_Desktop_fnQueryInterface(
97 IShellFolder2 * iface, REFIID riid, LPVOID * ppvObj)
99 IGenericSFImpl *This = (IGenericSFImpl *)iface;
101 TRACE ("(%p)->(%s,%p)\n", This, shdebugstr_guid (riid), ppvObj);
103 *ppvObj = NULL;
105 if (IsEqualIID (riid, &IID_IUnknown) ||
106 IsEqualIID (riid, &IID_IShellFolder) ||
107 IsEqualIID (riid, &IID_IShellFolder2))
109 *ppvObj = This;
112 if (*ppvObj)
114 IUnknown_AddRef ((IUnknown *) (*ppvObj));
115 TRACE ("-- Interface: (%p)->(%p)\n", ppvObj, *ppvObj);
116 return S_OK;
118 TRACE ("-- Interface: E_NOINTERFACE\n");
119 return E_NOINTERFACE;
122 static ULONG WINAPI ISF_Desktop_fnAddRef (IShellFolder2 * iface)
124 return 2; /* non-heap based object */
127 static ULONG WINAPI ISF_Desktop_fnRelease (IShellFolder2 * iface)
129 return 1; /* non-heap based object */
132 /**************************************************************************
133 * ISF_Desktop_fnParseDisplayName
135 * NOTES
136 * "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}" and "" binds
137 * to MyComputer
139 static HRESULT WINAPI ISF_Desktop_fnParseDisplayName (IShellFolder2 * iface,
140 HWND hwndOwner, LPBC pbc, LPOLESTR lpszDisplayName,
141 DWORD * pchEaten, LPITEMIDLIST * ppidl, DWORD * pdwAttributes)
143 IGenericSFImpl *This = (IGenericSFImpl *)iface;
144 WCHAR szElement[MAX_PATH];
145 LPCWSTR szNext = NULL;
146 LPITEMIDLIST pidlTemp = NULL;
147 HRESULT hr = S_OK;
148 CLSID clsid;
150 TRACE ("(%p)->(HWND=%p,%p,%p=%s,%p,pidl=%p,%p)\n",
151 This, hwndOwner, pbc, lpszDisplayName, debugstr_w(lpszDisplayName),
152 pchEaten, ppidl, pdwAttributes);
154 if (!lpszDisplayName || !ppidl)
155 return E_INVALIDARG;
157 *ppidl = 0;
159 if (pchEaten)
160 *pchEaten = 0; /* strange but like the original */
162 if (lpszDisplayName[0] == ':' && lpszDisplayName[1] == ':')
164 szNext = GetNextElementW (lpszDisplayName, szElement, MAX_PATH);
165 TRACE ("-- element: %s\n", debugstr_w (szElement));
166 SHCLSIDFromStringW (szElement + 2, &clsid);
167 pidlTemp = _ILCreateGuid (PT_GUID, &clsid);
169 else if (PathGetDriveNumberW (lpszDisplayName) >= 0)
171 /* it's a filesystem path with a drive. Let MyComputer/UnixDosFolder parse it */
172 if (UNIXFS_is_rooted_at_desktop())
173 pidlTemp = _ILCreateGuid(PT_GUID, &CLSID_UnixDosFolder);
174 else
175 pidlTemp = _ILCreateMyComputer ();
176 szNext = lpszDisplayName;
178 else if (PathIsUNCW(lpszDisplayName))
180 pidlTemp = _ILCreateNetwork();
181 szNext = lpszDisplayName;
183 else if( (pidlTemp = SHELL32_CreatePidlFromBindCtx(pbc, lpszDisplayName)) )
185 *ppidl = pidlTemp;
186 return S_OK;
188 else if (strchrW(lpszDisplayName,':'))
190 return IEParseDisplayNameWithBCW(CP_ACP,lpszDisplayName,pbc,ppidl);
192 else
194 /* it's a filesystem path on the desktop. Let a FSFolder parse it */
196 if (*lpszDisplayName)
198 WCHAR szPath[MAX_PATH];
199 LPWSTR pathPtr;
201 /* build a complete path to create a simple pidl */
202 lstrcpynW(szPath, This->sPathTarget, MAX_PATH);
203 pathPtr = PathAddBackslashW(szPath);
204 if (pathPtr)
206 lstrcpynW(pathPtr, lpszDisplayName, MAX_PATH - (pathPtr - szPath));
207 hr = _ILCreateFromPathW(szPath, &pidlTemp);
209 else
211 /* should never reach here, but for completeness */
212 hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
215 else
216 pidlTemp = _ILCreateMyComputer();
218 szNext = NULL;
221 if (SUCCEEDED(hr) && pidlTemp)
223 if (szNext && *szNext)
225 hr = SHELL32_ParseNextElement(iface, hwndOwner, pbc,
226 &pidlTemp, (LPOLESTR) szNext, pchEaten, pdwAttributes);
228 else
230 if (pdwAttributes && *pdwAttributes)
231 hr = SHELL32_GetItemAttributes(_IShellFolder_ (This),
232 pidlTemp, pdwAttributes);
236 *ppidl = pidlTemp;
238 TRACE ("(%p)->(-- ret=0x%08x)\n", This, hr);
240 return hr;
243 /**************************************************************************
244 * CreateDesktopEnumList()
246 static const WCHAR Desktop_NameSpaceW[] = { 'S','O','F','T','W','A','R','E',
247 '\\','M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
248 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\','E','x','p','l',
249 'o','r','e','r','\\','D','e','s','k','t','o','p','\\','N','a','m','e','s','p',
250 'a','c','e','\0' };
252 static BOOL CreateDesktopEnumList(IEnumIDList *list, DWORD dwFlags)
254 BOOL ret = TRUE;
255 WCHAR szPath[MAX_PATH];
257 TRACE("(%p)->(flags=0x%08x)\n", list, dwFlags);
259 /* enumerate the root folders */
260 if (dwFlags & SHCONTF_FOLDERS)
262 HKEY hkey;
263 UINT i;
265 /* create the pidl for This item */
266 ret = AddToEnumList(list, _ILCreateMyComputer());
268 for (i=0; i<2; i++) {
269 if (ret && !RegOpenKeyExW(i == 0 ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER,
270 Desktop_NameSpaceW, 0, KEY_READ, &hkey))
272 WCHAR iid[50];
273 int i=0;
275 while (ret)
277 DWORD size;
278 LONG r;
280 size = sizeof (iid) / sizeof (iid[0]);
281 r = RegEnumKeyExW(hkey, i, iid, &size, 0, NULL, NULL, NULL);
282 if (ERROR_SUCCESS == r)
284 ret = AddToEnumList(list, _ILCreateGuidFromStrW(iid));
285 i++;
287 else if (ERROR_NO_MORE_ITEMS == r)
288 break;
289 else
290 ret = FALSE;
292 RegCloseKey(hkey);
297 /* enumerate the elements in %windir%\desktop */
298 SHGetSpecialFolderPathW(0, szPath, CSIDL_DESKTOPDIRECTORY, FALSE);
299 ret = ret && CreateFolderEnumList(list, szPath, dwFlags);
301 return ret;
304 /**************************************************************************
305 * ISF_Desktop_fnEnumObjects
307 static HRESULT WINAPI ISF_Desktop_fnEnumObjects (IShellFolder2 * iface,
308 HWND hwndOwner, DWORD dwFlags, LPENUMIDLIST * ppEnumIDList)
310 IGenericSFImpl *This = (IGenericSFImpl *)iface;
312 TRACE ("(%p)->(HWND=%p flags=0x%08x pplist=%p)\n",
313 This, hwndOwner, dwFlags, ppEnumIDList);
315 *ppEnumIDList = IEnumIDList_Constructor();
316 if (*ppEnumIDList)
317 CreateDesktopEnumList(*ppEnumIDList, dwFlags);
319 TRACE ("-- (%p)->(new ID List: %p)\n", This, *ppEnumIDList);
321 return *ppEnumIDList ? S_OK : E_OUTOFMEMORY;
324 /**************************************************************************
325 * ISF_Desktop_fnBindToObject
327 static HRESULT WINAPI ISF_Desktop_fnBindToObject (IShellFolder2 * iface,
328 LPCITEMIDLIST pidl, LPBC pbcReserved, REFIID riid, LPVOID * ppvOut)
330 IGenericSFImpl *This = (IGenericSFImpl *)iface;
332 TRACE ("(%p)->(pidl=%p,%p,%s,%p)\n",
333 This, pidl, pbcReserved, shdebugstr_guid (riid), ppvOut);
335 return SHELL32_BindToChild( This->pidlRoot, This->sPathTarget, pidl, riid, ppvOut );
338 /**************************************************************************
339 * ISF_Desktop_fnBindToStorage
341 static HRESULT WINAPI ISF_Desktop_fnBindToStorage (IShellFolder2 * iface,
342 LPCITEMIDLIST pidl, LPBC pbcReserved, REFIID riid, LPVOID * ppvOut)
344 IGenericSFImpl *This = (IGenericSFImpl *)iface;
346 FIXME ("(%p)->(pidl=%p,%p,%s,%p) stub\n",
347 This, pidl, pbcReserved, shdebugstr_guid (riid), ppvOut);
349 *ppvOut = NULL;
350 return E_NOTIMPL;
353 /**************************************************************************
354 * ISF_Desktop_fnCompareIDs
356 static HRESULT WINAPI ISF_Desktop_fnCompareIDs (IShellFolder2 * iface,
357 LPARAM lParam, LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
359 IGenericSFImpl *This = (IGenericSFImpl *)iface;
360 int nReturn;
362 TRACE ("(%p)->(0x%08lx,pidl1=%p,pidl2=%p)\n", This, lParam, pidl1, pidl2);
363 nReturn = SHELL32_CompareIDs (_IShellFolder_ (This), lParam, pidl1, pidl2);
364 TRACE ("-- %i\n", nReturn);
365 return nReturn;
368 /**************************************************************************
369 * ISF_Desktop_fnCreateViewObject
371 static HRESULT WINAPI ISF_Desktop_fnCreateViewObject (IShellFolder2 * iface,
372 HWND hwndOwner, REFIID riid, LPVOID * ppvOut)
374 IGenericSFImpl *This = (IGenericSFImpl *)iface;
375 LPSHELLVIEW pShellView;
376 HRESULT hr = E_INVALIDARG;
378 TRACE ("(%p)->(hwnd=%p,%s,%p)\n",
379 This, hwndOwner, shdebugstr_guid (riid), ppvOut);
381 if (!ppvOut)
382 return hr;
384 *ppvOut = NULL;
386 if (IsEqualIID (riid, &IID_IDropTarget))
388 WARN ("IDropTarget not implemented\n");
389 hr = E_NOTIMPL;
391 else if (IsEqualIID (riid, &IID_IContextMenu))
393 WARN ("IContextMenu not implemented\n");
394 hr = E_NOTIMPL;
396 else if (IsEqualIID (riid, &IID_IShellView))
398 pShellView = IShellView_Constructor ((IShellFolder *) iface);
399 if (pShellView)
401 hr = IShellView_QueryInterface (pShellView, riid, ppvOut);
402 IShellView_Release (pShellView);
405 TRACE ("-- (%p)->(interface=%p)\n", This, ppvOut);
406 return hr;
409 /**************************************************************************
410 * ISF_Desktop_fnGetAttributesOf
412 static HRESULT WINAPI ISF_Desktop_fnGetAttributesOf (IShellFolder2 * iface,
413 UINT cidl, LPCITEMIDLIST * apidl, DWORD * rgfInOut)
415 IGenericSFImpl *This = (IGenericSFImpl *)iface;
416 HRESULT hr = S_OK;
417 static const DWORD dwDesktopAttributes =
418 SFGAO_STORAGE | SFGAO_HASPROPSHEET | SFGAO_STORAGEANCESTOR |
419 SFGAO_FILESYSANCESTOR | SFGAO_FOLDER | SFGAO_FILESYSTEM | SFGAO_HASSUBFOLDER;
420 static const DWORD dwMyComputerAttributes =
421 SFGAO_CANRENAME | SFGAO_CANDELETE | SFGAO_HASPROPSHEET |
422 SFGAO_DROPTARGET | SFGAO_FILESYSANCESTOR | SFGAO_FOLDER | SFGAO_HASSUBFOLDER;
424 TRACE ("(%p)->(cidl=%d apidl=%p mask=%p (0x%08x))\n",
425 This, cidl, apidl, rgfInOut, rgfInOut ? *rgfInOut : 0);
427 if (!rgfInOut)
428 return E_INVALIDARG;
429 if (cidl && !apidl)
430 return E_INVALIDARG;
432 if (*rgfInOut == 0)
433 *rgfInOut = ~0;
435 if(cidl == 0) {
436 *rgfInOut &= dwDesktopAttributes;
437 } else {
438 while (cidl > 0 && *apidl) {
439 pdump (*apidl);
440 if (_ILIsDesktop(*apidl)) {
441 *rgfInOut &= dwDesktopAttributes;
442 } else if (_ILIsMyComputer(*apidl)) {
443 *rgfInOut &= dwMyComputerAttributes;
444 } else {
445 SHELL32_GetItemAttributes (_IShellFolder_ (This), *apidl, rgfInOut);
447 apidl++;
448 cidl--;
451 /* make sure SFGAO_VALIDATE is cleared, some apps depend on that */
452 *rgfInOut &= ~SFGAO_VALIDATE;
454 TRACE ("-- result=0x%08x\n", *rgfInOut);
456 return hr;
459 /**************************************************************************
460 * ISF_Desktop_fnGetUIObjectOf
462 * PARAMETERS
463 * HWND hwndOwner, //[in ] Parent window for any output
464 * UINT cidl, //[in ] array size
465 * LPCITEMIDLIST* apidl, //[in ] simple pidl array
466 * REFIID riid, //[in ] Requested Interface
467 * UINT* prgfInOut, //[ ] reserved
468 * LPVOID* ppvObject) //[out] Resulting Interface
471 static HRESULT WINAPI ISF_Desktop_fnGetUIObjectOf (IShellFolder2 * iface,
472 HWND hwndOwner, UINT cidl, LPCITEMIDLIST * apidl,
473 REFIID riid, UINT * prgfInOut, LPVOID * ppvOut)
475 IGenericSFImpl *This = (IGenericSFImpl *)iface;
477 LPITEMIDLIST pidl;
478 IUnknown *pObj = NULL;
479 HRESULT hr = E_INVALIDARG;
481 TRACE ("(%p)->(%p,%u,apidl=%p,%s,%p,%p)\n",
482 This, hwndOwner, cidl, apidl, shdebugstr_guid (riid), prgfInOut, ppvOut);
484 if (!ppvOut)
485 return hr;
487 *ppvOut = NULL;
489 if (IsEqualIID (riid, &IID_IContextMenu))
491 if (cidl > 0)
492 pObj = (LPUNKNOWN) ISvItemCm_Constructor( (IShellFolder *) iface, This->pidlRoot, apidl, cidl);
493 else
494 pObj = (LPUNKNOWN) ISvBgCm_Constructor( (IShellFolder *) iface, TRUE);
495 hr = S_OK;
497 else if (IsEqualIID (riid, &IID_IDataObject) && (cidl >= 1))
499 pObj = (LPUNKNOWN) IDataObject_Constructor( hwndOwner,
500 This->pidlRoot, apidl, cidl);
501 hr = S_OK;
503 else if (IsEqualIID (riid, &IID_IExtractIconA) && (cidl == 1))
505 pidl = ILCombine (This->pidlRoot, apidl[0]);
506 pObj = (LPUNKNOWN) IExtractIconA_Constructor (pidl);
507 SHFree (pidl);
508 hr = S_OK;
510 else if (IsEqualIID (riid, &IID_IExtractIconW) && (cidl == 1))
512 pidl = ILCombine (This->pidlRoot, apidl[0]);
513 pObj = (LPUNKNOWN) IExtractIconW_Constructor (pidl);
514 SHFree (pidl);
515 hr = S_OK;
517 else if (IsEqualIID (riid, &IID_IDropTarget) && (cidl >= 1))
519 hr = IShellFolder_QueryInterface (iface,
520 &IID_IDropTarget, (LPVOID *) & pObj);
522 else if ((IsEqualIID(riid,&IID_IShellLinkW) ||
523 IsEqualIID(riid,&IID_IShellLinkA)) && (cidl == 1))
525 pidl = ILCombine (This->pidlRoot, apidl[0]);
526 hr = IShellLink_ConstructFromFile(NULL, riid, pidl, (LPVOID*)&pObj);
527 SHFree (pidl);
529 else
530 hr = E_NOINTERFACE;
532 if (SUCCEEDED(hr) && !pObj)
533 hr = E_OUTOFMEMORY;
535 *ppvOut = pObj;
536 TRACE ("(%p)->hr=0x%08x\n", This, hr);
537 return hr;
540 /**************************************************************************
541 * ISF_Desktop_fnGetDisplayNameOf
543 * NOTES
544 * special case: pidl = null gives desktop-name back
546 static HRESULT WINAPI ISF_Desktop_fnGetDisplayNameOf (IShellFolder2 * iface,
547 LPCITEMIDLIST pidl, DWORD dwFlags, LPSTRRET strRet)
549 IGenericSFImpl *This = (IGenericSFImpl *)iface;
550 HRESULT hr = S_OK;
551 LPWSTR pszPath;
553 TRACE ("(%p)->(pidl=%p,0x%08x,%p)\n", This, pidl, dwFlags, strRet);
554 pdump (pidl);
556 if (!strRet)
557 return E_INVALIDARG;
559 pszPath = CoTaskMemAlloc((MAX_PATH +1) * sizeof(WCHAR));
560 if (!pszPath)
561 return E_OUTOFMEMORY;
563 if (_ILIsDesktop (pidl))
565 if ((GET_SHGDN_RELATION (dwFlags) == SHGDN_NORMAL) &&
566 (GET_SHGDN_FOR (dwFlags) & SHGDN_FORPARSING))
567 strcpyW(pszPath, This->sPathTarget);
568 else
569 HCR_GetClassNameW(&CLSID_ShellDesktop, pszPath, MAX_PATH);
571 else if (_ILIsPidlSimple (pidl))
573 GUID const *clsid;
575 if ((clsid = _ILGetGUIDPointer (pidl)))
577 if (GET_SHGDN_FOR (dwFlags) & SHGDN_FORPARSING)
579 int bWantsForParsing;
582 * We can only get a filesystem path from a shellfolder if the
583 * value WantsFORPARSING in CLSID\\{...}\\shellfolder exists.
585 * Exception: The MyComputer folder doesn't have this key,
586 * but any other filesystem backed folder it needs it.
588 if (IsEqualIID (clsid, &CLSID_MyComputer))
590 bWantsForParsing = TRUE;
592 else
594 /* get the "WantsFORPARSING" flag from the registry */
595 static const WCHAR clsidW[] =
596 { 'C','L','S','I','D','\\',0 };
597 static const WCHAR shellfolderW[] =
598 { '\\','s','h','e','l','l','f','o','l','d','e','r',0 };
599 static const WCHAR wantsForParsingW[] =
600 { 'W','a','n','t','s','F','o','r','P','a','r','s','i','n',
601 'g',0 };
602 WCHAR szRegPath[100];
603 LONG r;
605 lstrcpyW (szRegPath, clsidW);
606 SHELL32_GUIDToStringW (clsid, &szRegPath[6]);
607 lstrcatW (szRegPath, shellfolderW);
608 r = SHGetValueW(HKEY_CLASSES_ROOT, szRegPath,
609 wantsForParsingW, NULL, NULL, NULL);
610 if (r == ERROR_SUCCESS)
611 bWantsForParsing = TRUE;
612 else
613 bWantsForParsing = FALSE;
616 if ((GET_SHGDN_RELATION (dwFlags) == SHGDN_NORMAL) &&
617 bWantsForParsing)
620 * we need the filesystem path to the destination folder.
621 * Only the folder itself can know it
623 hr = SHELL32_GetDisplayNameOfChild (iface, pidl, dwFlags,
624 pszPath,
625 MAX_PATH);
627 else
629 /* parsing name like ::{...} */
630 pszPath[0] = ':';
631 pszPath[1] = ':';
632 SHELL32_GUIDToStringW (clsid, &pszPath[2]);
635 else
637 /* user friendly name */
638 HCR_GetClassNameW (clsid, pszPath, MAX_PATH);
641 else
643 int cLen = 0;
645 /* file system folder or file rooted at the desktop */
646 if ((GET_SHGDN_FOR(dwFlags) == SHGDN_FORPARSING) &&
647 (GET_SHGDN_RELATION(dwFlags) != SHGDN_INFOLDER))
649 lstrcpynW(pszPath, This->sPathTarget, MAX_PATH - 1);
650 PathAddBackslashW(pszPath);
651 cLen = lstrlenW(pszPath);
654 _ILSimpleGetTextW(pidl, pszPath + cLen, MAX_PATH - cLen);
656 if (!_ILIsFolder(pidl))
657 SHELL_FS_ProcessDisplayFilename(pszPath, dwFlags);
660 else
662 /* a complex pidl, let the subfolder do the work */
663 hr = SHELL32_GetDisplayNameOfChild (iface, pidl, dwFlags,
664 pszPath, MAX_PATH);
667 if (SUCCEEDED(hr))
669 /* Win9x always returns ANSI strings, NT always returns Unicode strings */
670 if (GetVersion() & 0x80000000)
672 strRet->uType = STRRET_CSTR;
673 if (!WideCharToMultiByte(CP_ACP, 0, pszPath, -1, strRet->u.cStr, MAX_PATH,
674 NULL, NULL))
675 strRet->u.cStr[0] = '\0';
676 CoTaskMemFree(pszPath);
678 else
680 strRet->uType = STRRET_WSTR;
681 strRet->u.pOleStr = pszPath;
684 else
685 CoTaskMemFree(pszPath);
687 TRACE ("-- (%p)->(%s,0x%08x)\n", This,
688 strRet->uType == STRRET_CSTR ? strRet->u.cStr :
689 debugstr_w(strRet->u.pOleStr), hr);
690 return hr;
693 /**************************************************************************
694 * ISF_Desktop_fnSetNameOf
695 * Changes the name of a file object or subfolder, possibly changing its item
696 * identifier in the process.
698 * PARAMETERS
699 * HWND hwndOwner, //[in ] Owner window for output
700 * LPCITEMIDLIST pidl, //[in ] simple pidl of item to change
701 * LPCOLESTR lpszName, //[in ] the items new display name
702 * DWORD dwFlags, //[in ] SHGNO formatting flags
703 * LPITEMIDLIST* ppidlOut) //[out] simple pidl returned
705 static HRESULT WINAPI ISF_Desktop_fnSetNameOf (IShellFolder2 * iface,
706 HWND hwndOwner, LPCITEMIDLIST pidl, /* simple pidl */
707 LPCOLESTR lpName, DWORD dwFlags, LPITEMIDLIST * pPidlOut)
709 IGenericSFImpl *This = (IGenericSFImpl *)iface;
711 FIXME ("(%p)->(%p,pidl=%p,%s,%u,%p)\n", This, hwndOwner, pidl,
712 debugstr_w (lpName), dwFlags, pPidlOut);
714 return E_FAIL;
717 static HRESULT WINAPI ISF_Desktop_fnGetDefaultSearchGUID(IShellFolder2 *iface,
718 GUID * pguid)
720 IGenericSFImpl *This = (IGenericSFImpl *)iface;
722 FIXME ("(%p)\n", This);
723 return E_NOTIMPL;
726 static HRESULT WINAPI ISF_Desktop_fnEnumSearches (IShellFolder2 *iface,
727 IEnumExtraSearch ** ppenum)
729 IGenericSFImpl *This = (IGenericSFImpl *)iface;
730 FIXME ("(%p)\n", This);
731 return E_NOTIMPL;
734 static HRESULT WINAPI ISF_Desktop_fnGetDefaultColumn (IShellFolder2 * iface,
735 DWORD dwRes, ULONG * pSort, ULONG * pDisplay)
737 IGenericSFImpl *This = (IGenericSFImpl *)iface;
739 TRACE ("(%p)\n", This);
741 if (pSort)
742 *pSort = 0;
743 if (pDisplay)
744 *pDisplay = 0;
746 return S_OK;
748 static HRESULT WINAPI ISF_Desktop_fnGetDefaultColumnState (
749 IShellFolder2 * iface, UINT iColumn, DWORD * pcsFlags)
751 IGenericSFImpl *This = (IGenericSFImpl *)iface;
753 TRACE ("(%p)\n", This);
755 if (!pcsFlags || iColumn >= DESKTOPSHELLVIEWCOLUMNS)
756 return E_INVALIDARG;
758 *pcsFlags = DesktopSFHeader[iColumn].pcsFlags;
760 return S_OK;
763 static HRESULT WINAPI ISF_Desktop_fnGetDetailsEx (IShellFolder2 * iface,
764 LPCITEMIDLIST pidl, const SHCOLUMNID * pscid, VARIANT * pv)
766 IGenericSFImpl *This = (IGenericSFImpl *)iface;
767 FIXME ("(%p)\n", This);
769 return E_NOTIMPL;
772 static HRESULT WINAPI ISF_Desktop_fnGetDetailsOf (IShellFolder2 * iface,
773 LPCITEMIDLIST pidl, UINT iColumn, SHELLDETAILS * psd)
775 IGenericSFImpl *This = (IGenericSFImpl *)iface;
777 HRESULT hr = S_OK;
779 TRACE ("(%p)->(%p %i %p)\n", This, pidl, iColumn, psd);
781 if (!psd || iColumn >= DESKTOPSHELLVIEWCOLUMNS)
782 return E_INVALIDARG;
784 if (!pidl)
786 psd->fmt = DesktopSFHeader[iColumn].fmt;
787 psd->cxChar = DesktopSFHeader[iColumn].cxChar;
788 psd->str.uType = STRRET_CSTR;
789 LoadStringA (shell32_hInstance, DesktopSFHeader[iColumn].colnameid,
790 psd->str.u.cStr, MAX_PATH);
791 return S_OK;
794 /* the data from the pidl */
795 psd->str.uType = STRRET_CSTR;
796 switch (iColumn)
798 case 0: /* name */
799 hr = IShellFolder_GetDisplayNameOf(iface, pidl,
800 SHGDN_NORMAL | SHGDN_INFOLDER, &psd->str);
801 break;
802 case 1: /* size */
803 _ILGetFileSize (pidl, psd->str.u.cStr, MAX_PATH);
804 break;
805 case 2: /* type */
806 _ILGetFileType (pidl, psd->str.u.cStr, MAX_PATH);
807 break;
808 case 3: /* date */
809 _ILGetFileDate (pidl, psd->str.u.cStr, MAX_PATH);
810 break;
811 case 4: /* attributes */
812 _ILGetFileAttributes (pidl, psd->str.u.cStr, MAX_PATH);
813 break;
816 return hr;
819 static HRESULT WINAPI ISF_Desktop_fnMapColumnToSCID (
820 IShellFolder2 * iface, UINT column, SHCOLUMNID * pscid)
822 IGenericSFImpl *This = (IGenericSFImpl *)iface;
823 FIXME ("(%p)\n", This);
824 return E_NOTIMPL;
827 static const IShellFolder2Vtbl vt_MCFldr_ShellFolder2 =
829 ISF_Desktop_fnQueryInterface,
830 ISF_Desktop_fnAddRef,
831 ISF_Desktop_fnRelease,
832 ISF_Desktop_fnParseDisplayName,
833 ISF_Desktop_fnEnumObjects,
834 ISF_Desktop_fnBindToObject,
835 ISF_Desktop_fnBindToStorage,
836 ISF_Desktop_fnCompareIDs,
837 ISF_Desktop_fnCreateViewObject,
838 ISF_Desktop_fnGetAttributesOf,
839 ISF_Desktop_fnGetUIObjectOf,
840 ISF_Desktop_fnGetDisplayNameOf,
841 ISF_Desktop_fnSetNameOf,
842 /* ShellFolder2 */
843 ISF_Desktop_fnGetDefaultSearchGUID,
844 ISF_Desktop_fnEnumSearches,
845 ISF_Desktop_fnGetDefaultColumn,
846 ISF_Desktop_fnGetDefaultColumnState,
847 ISF_Desktop_fnGetDetailsEx,
848 ISF_Desktop_fnGetDetailsOf,
849 ISF_Desktop_fnMapColumnToSCID
852 /**************************************************************************
853 * ISF_Desktop_Constructor
855 HRESULT WINAPI ISF_Desktop_Constructor (
856 IUnknown * pUnkOuter, REFIID riid, LPVOID * ppv)
858 static IGenericSFImpl *cached_sf;
859 WCHAR szMyPath[MAX_PATH];
861 TRACE ("unkOut=%p %s\n", pUnkOuter, shdebugstr_guid (riid));
863 if (!ppv)
864 return E_POINTER;
865 if (pUnkOuter)
866 return CLASS_E_NOAGGREGATION;
868 if (!cached_sf)
870 IGenericSFImpl *sf;
872 if (!SHGetSpecialFolderPathW( 0, szMyPath, CSIDL_DESKTOPDIRECTORY, TRUE ))
873 return E_UNEXPECTED;
875 sf = LocalAlloc( LMEM_ZEROINIT, sizeof (IGenericSFImpl) );
876 if (!sf)
877 return E_OUTOFMEMORY;
879 sf->ref = 1;
880 sf->lpVtbl = &vt_MCFldr_ShellFolder2;
881 sf->pidlRoot = _ILCreateDesktop(); /* my qualified pidl */
882 sf->sPathTarget = SHAlloc( (lstrlenW(szMyPath) + 1)*sizeof(WCHAR) );
883 lstrcpyW( sf->sPathTarget, szMyPath );
885 if (InterlockedCompareExchangePointer((void *)&cached_sf, sf, NULL) != NULL)
887 /* some other thread already been here */
888 SHFree( sf->pidlRoot );
889 SHFree( sf->sPathTarget );
890 LocalFree( sf );
894 return IUnknown_QueryInterface( _IUnknown_(cached_sf), riid, ppv );