quartz: Reset EcCompleteCount before starting filters.
[wine/wine64.git] / dlls / shell32 / shfldr_desktop.c
blobaeb6e4b9df288dd58fea3c1877109ae37a5ec6ee
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 /***********************************************************************
59 * Desktopfolder implementation
62 typedef struct {
63 const IShellFolder2Vtbl *lpVtbl;
64 LONG ref;
66 /* both paths are parsible from the desktop */
67 LPWSTR sPathTarget; /* complete path to target used for enumeration and ChangeNotify */
68 LPITEMIDLIST pidlRoot; /* absolute pidl */
70 UINT cfShellIDList; /* clipboardformat for IDropTarget */
71 BOOL fAcceptFmt; /* flag for pending Drop */
72 } IGenericSFImpl;
74 #define _IUnknown_(This) (IShellFolder*)&(This->lpVtbl)
75 #define _IShellFolder_(This) (IShellFolder*)&(This->lpVtbl)
77 static const shvheader DesktopSFHeader[] = {
78 {IDS_SHV_COLUMN1, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 15},
79 {IDS_SHV_COLUMN2, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
80 {IDS_SHV_COLUMN3, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
81 {IDS_SHV_COLUMN4, SHCOLSTATE_TYPE_DATE | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 12},
82 {IDS_SHV_COLUMN5, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 5}
85 #define DESKTOPSHELLVIEWCOLUMNS 5
87 /**************************************************************************
88 * ISF_Desktop_fnQueryInterface
90 * NOTES supports not IPersist/IPersistFolder
92 static HRESULT WINAPI ISF_Desktop_fnQueryInterface(
93 IShellFolder2 * iface, REFIID riid, LPVOID * ppvObj)
95 IGenericSFImpl *This = (IGenericSFImpl *)iface;
97 TRACE ("(%p)->(%s,%p)\n", This, shdebugstr_guid (riid), ppvObj);
99 *ppvObj = NULL;
101 if (IsEqualIID (riid, &IID_IUnknown) ||
102 IsEqualIID (riid, &IID_IShellFolder) ||
103 IsEqualIID (riid, &IID_IShellFolder2))
105 *ppvObj = This;
108 if (*ppvObj)
110 IUnknown_AddRef ((IUnknown *) (*ppvObj));
111 TRACE ("-- Interface: (%p)->(%p)\n", ppvObj, *ppvObj);
112 return S_OK;
114 TRACE ("-- Interface: E_NOINTERFACE\n");
115 return E_NOINTERFACE;
118 static ULONG WINAPI ISF_Desktop_fnAddRef (IShellFolder2 * iface)
120 return 2; /* non-heap based object */
123 static ULONG WINAPI ISF_Desktop_fnRelease (IShellFolder2 * iface)
125 return 1; /* non-heap based object */
128 /**************************************************************************
129 * ISF_Desktop_fnParseDisplayName
131 * NOTES
132 * "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}" and "" binds
133 * to MyComputer
135 static HRESULT WINAPI ISF_Desktop_fnParseDisplayName (IShellFolder2 * iface,
136 HWND hwndOwner, LPBC pbc, LPOLESTR lpszDisplayName,
137 DWORD * pchEaten, LPITEMIDLIST * ppidl, DWORD * pdwAttributes)
139 IGenericSFImpl *This = (IGenericSFImpl *)iface;
140 WCHAR szElement[MAX_PATH];
141 LPCWSTR szNext = NULL;
142 LPITEMIDLIST pidlTemp = NULL;
143 HRESULT hr = S_OK;
144 CLSID clsid;
146 TRACE ("(%p)->(HWND=%p,%p,%p=%s,%p,pidl=%p,%p)\n",
147 This, hwndOwner, pbc, lpszDisplayName, debugstr_w(lpszDisplayName),
148 pchEaten, ppidl, pdwAttributes);
150 if (!lpszDisplayName || !ppidl)
151 return E_INVALIDARG;
153 *ppidl = 0;
155 if (pchEaten)
156 *pchEaten = 0; /* strange but like the original */
158 if (lpszDisplayName[0] == ':' && lpszDisplayName[1] == ':')
160 szNext = GetNextElementW (lpszDisplayName, szElement, MAX_PATH);
161 TRACE ("-- element: %s\n", debugstr_w (szElement));
162 SHCLSIDFromStringW (szElement + 2, &clsid);
163 pidlTemp = _ILCreateGuid (PT_GUID, &clsid);
165 else if (PathGetDriveNumberW (lpszDisplayName) >= 0)
167 /* it's a filesystem path with a drive. Let MyComputer/UnixDosFolder parse it */
168 if (UNIXFS_is_rooted_at_desktop())
169 pidlTemp = _ILCreateGuid(PT_GUID, &CLSID_UnixDosFolder);
170 else
171 pidlTemp = _ILCreateMyComputer ();
172 szNext = lpszDisplayName;
174 else if (PathIsUNCW(lpszDisplayName))
176 pidlTemp = _ILCreateNetwork();
177 szNext = lpszDisplayName;
179 else if( (pidlTemp = SHELL32_CreatePidlFromBindCtx(pbc, lpszDisplayName)) )
181 *ppidl = pidlTemp;
182 return S_OK;
184 else
186 /* it's a filesystem path on the desktop. Let a FSFolder parse it */
188 if (*lpszDisplayName)
190 WCHAR szPath[MAX_PATH];
191 LPWSTR pathPtr;
193 /* build a complete path to create a simple pidl */
194 lstrcpynW(szPath, This->sPathTarget, MAX_PATH);
195 pathPtr = PathAddBackslashW(szPath);
196 if (pathPtr)
198 lstrcpynW(pathPtr, lpszDisplayName, MAX_PATH - (pathPtr - szPath));
199 hr = _ILCreateFromPathW(szPath, &pidlTemp);
201 else
203 /* should never reach here, but for completeness */
204 hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
207 else
208 pidlTemp = _ILCreateMyComputer();
210 szNext = NULL;
213 if (SUCCEEDED(hr) && pidlTemp)
215 if (szNext && *szNext)
217 hr = SHELL32_ParseNextElement(iface, hwndOwner, pbc,
218 &pidlTemp, (LPOLESTR) szNext, pchEaten, pdwAttributes);
220 else
222 if (pdwAttributes && *pdwAttributes)
223 hr = SHELL32_GetItemAttributes(_IShellFolder_ (This),
224 pidlTemp, pdwAttributes);
228 *ppidl = pidlTemp;
230 TRACE ("(%p)->(-- ret=0x%08x)\n", This, hr);
232 return hr;
235 /**************************************************************************
236 * CreateDesktopEnumList()
238 static const WCHAR Desktop_NameSpaceW[] = { 'S','O','F','T','W','A','R','E',
239 '\\','M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
240 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\','E','x','p','l',
241 'o','r','e','r','\\','D','e','s','k','t','o','p','\\','N','a','m','e','s','p',
242 'a','c','e','\0' };
244 static BOOL CreateDesktopEnumList(IEnumIDList *list, DWORD dwFlags)
246 BOOL ret = TRUE;
247 WCHAR szPath[MAX_PATH];
249 TRACE("(%p)->(flags=0x%08x)\n", list, dwFlags);
251 /* enumerate the root folders */
252 if (dwFlags & SHCONTF_FOLDERS)
254 HKEY hkey;
255 UINT i;
257 /* create the pidl for This item */
258 ret = AddToEnumList(list, _ILCreateMyComputer());
260 for (i=0; i<2; i++) {
261 if (ret && !RegOpenKeyExW(i == 0 ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER,
262 Desktop_NameSpaceW, 0, KEY_READ, &hkey))
264 WCHAR iid[50];
265 int i=0;
267 while (ret)
269 DWORD size;
270 LONG r;
272 size = sizeof (iid) / sizeof (iid[0]);
273 r = RegEnumKeyExW(hkey, i, iid, &size, 0, NULL, NULL, NULL);
274 if (ERROR_SUCCESS == r)
276 ret = AddToEnumList(list, _ILCreateGuidFromStrW(iid));
277 i++;
279 else if (ERROR_NO_MORE_ITEMS == r)
280 break;
281 else
282 ret = FALSE;
284 RegCloseKey(hkey);
289 /* enumerate the elements in %windir%\desktop */
290 SHGetSpecialFolderPathW(0, szPath, CSIDL_DESKTOPDIRECTORY, FALSE);
291 ret = ret && CreateFolderEnumList(list, szPath, dwFlags);
293 return ret;
296 /**************************************************************************
297 * ISF_Desktop_fnEnumObjects
299 static HRESULT WINAPI ISF_Desktop_fnEnumObjects (IShellFolder2 * iface,
300 HWND hwndOwner, DWORD dwFlags, LPENUMIDLIST * ppEnumIDList)
302 IGenericSFImpl *This = (IGenericSFImpl *)iface;
304 TRACE ("(%p)->(HWND=%p flags=0x%08x pplist=%p)\n",
305 This, hwndOwner, dwFlags, ppEnumIDList);
307 *ppEnumIDList = IEnumIDList_Constructor();
308 if (*ppEnumIDList)
309 CreateDesktopEnumList(*ppEnumIDList, dwFlags);
311 TRACE ("-- (%p)->(new ID List: %p)\n", This, *ppEnumIDList);
313 return *ppEnumIDList ? S_OK : E_OUTOFMEMORY;
316 /**************************************************************************
317 * ISF_Desktop_fnBindToObject
319 static HRESULT WINAPI ISF_Desktop_fnBindToObject (IShellFolder2 * iface,
320 LPCITEMIDLIST pidl, LPBC pbcReserved, REFIID riid, LPVOID * ppvOut)
322 IGenericSFImpl *This = (IGenericSFImpl *)iface;
324 TRACE ("(%p)->(pidl=%p,%p,%s,%p)\n",
325 This, pidl, pbcReserved, shdebugstr_guid (riid), ppvOut);
327 return SHELL32_BindToChild( This->pidlRoot, This->sPathTarget, pidl, riid, ppvOut );
330 /**************************************************************************
331 * ISF_Desktop_fnBindToStorage
333 static HRESULT WINAPI ISF_Desktop_fnBindToStorage (IShellFolder2 * iface,
334 LPCITEMIDLIST pidl, LPBC pbcReserved, REFIID riid, LPVOID * ppvOut)
336 IGenericSFImpl *This = (IGenericSFImpl *)iface;
338 FIXME ("(%p)->(pidl=%p,%p,%s,%p) stub\n",
339 This, pidl, pbcReserved, shdebugstr_guid (riid), ppvOut);
341 *ppvOut = NULL;
342 return E_NOTIMPL;
345 /**************************************************************************
346 * ISF_Desktop_fnCompareIDs
348 static HRESULT WINAPI ISF_Desktop_fnCompareIDs (IShellFolder2 * iface,
349 LPARAM lParam, LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
351 IGenericSFImpl *This = (IGenericSFImpl *)iface;
352 int nReturn;
354 TRACE ("(%p)->(0x%08lx,pidl1=%p,pidl2=%p)\n", This, lParam, pidl1, pidl2);
355 nReturn = SHELL32_CompareIDs (_IShellFolder_ (This), lParam, pidl1, pidl2);
356 TRACE ("-- %i\n", nReturn);
357 return nReturn;
360 /**************************************************************************
361 * ISF_Desktop_fnCreateViewObject
363 static HRESULT WINAPI ISF_Desktop_fnCreateViewObject (IShellFolder2 * iface,
364 HWND hwndOwner, REFIID riid, LPVOID * ppvOut)
366 IGenericSFImpl *This = (IGenericSFImpl *)iface;
367 LPSHELLVIEW pShellView;
368 HRESULT hr = E_INVALIDARG;
370 TRACE ("(%p)->(hwnd=%p,%s,%p)\n",
371 This, hwndOwner, shdebugstr_guid (riid), ppvOut);
373 if (!ppvOut)
374 return hr;
376 *ppvOut = NULL;
378 if (IsEqualIID (riid, &IID_IDropTarget))
380 WARN ("IDropTarget not implemented\n");
381 hr = E_NOTIMPL;
383 else if (IsEqualIID (riid, &IID_IContextMenu))
385 WARN ("IContextMenu not implemented\n");
386 hr = E_NOTIMPL;
388 else if (IsEqualIID (riid, &IID_IShellView))
390 pShellView = IShellView_Constructor ((IShellFolder *) iface);
391 if (pShellView)
393 hr = IShellView_QueryInterface (pShellView, riid, ppvOut);
394 IShellView_Release (pShellView);
397 TRACE ("-- (%p)->(interface=%p)\n", This, ppvOut);
398 return hr;
401 /**************************************************************************
402 * ISF_Desktop_fnGetAttributesOf
404 static HRESULT WINAPI ISF_Desktop_fnGetAttributesOf (IShellFolder2 * iface,
405 UINT cidl, LPCITEMIDLIST * apidl, DWORD * rgfInOut)
407 IGenericSFImpl *This = (IGenericSFImpl *)iface;
408 HRESULT hr = S_OK;
409 static const DWORD dwDesktopAttributes =
410 SFGAO_STORAGE | SFGAO_HASPROPSHEET | SFGAO_STORAGEANCESTOR |
411 SFGAO_FILESYSANCESTOR | SFGAO_FOLDER | SFGAO_FILESYSTEM | SFGAO_HASSUBFOLDER;
412 static const DWORD dwMyComputerAttributes =
413 SFGAO_CANRENAME | SFGAO_CANDELETE | SFGAO_HASPROPSHEET |
414 SFGAO_DROPTARGET | SFGAO_FILESYSANCESTOR | SFGAO_FOLDER | SFGAO_HASSUBFOLDER;
416 TRACE ("(%p)->(cidl=%d apidl=%p mask=%p (0x%08x))\n",
417 This, cidl, apidl, rgfInOut, rgfInOut ? *rgfInOut : 0);
419 if (!rgfInOut)
420 return E_INVALIDARG;
421 if (cidl && !apidl)
422 return E_INVALIDARG;
424 if (*rgfInOut == 0)
425 *rgfInOut = ~0;
427 if(cidl == 0) {
428 *rgfInOut &= dwDesktopAttributes;
429 } else {
430 while (cidl > 0 && *apidl) {
431 pdump (*apidl);
432 if (_ILIsDesktop(*apidl)) {
433 *rgfInOut &= dwDesktopAttributes;
434 } else if (_ILIsMyComputer(*apidl)) {
435 *rgfInOut &= dwMyComputerAttributes;
436 } else {
437 SHELL32_GetItemAttributes (_IShellFolder_ (This), *apidl, rgfInOut);
439 apidl++;
440 cidl--;
443 /* make sure SFGAO_VALIDATE is cleared, some apps depend on that */
444 *rgfInOut &= ~SFGAO_VALIDATE;
446 TRACE ("-- result=0x%08x\n", *rgfInOut);
448 return hr;
451 /**************************************************************************
452 * ISF_Desktop_fnGetUIObjectOf
454 * PARAMETERS
455 * HWND hwndOwner, //[in ] Parent window for any output
456 * UINT cidl, //[in ] array size
457 * LPCITEMIDLIST* apidl, //[in ] simple pidl array
458 * REFIID riid, //[in ] Requested Interface
459 * UINT* prgfInOut, //[ ] reserved
460 * LPVOID* ppvObject) //[out] Resulting Interface
463 static HRESULT WINAPI ISF_Desktop_fnGetUIObjectOf (IShellFolder2 * iface,
464 HWND hwndOwner, UINT cidl, LPCITEMIDLIST * apidl,
465 REFIID riid, UINT * prgfInOut, LPVOID * ppvOut)
467 IGenericSFImpl *This = (IGenericSFImpl *)iface;
469 LPITEMIDLIST pidl;
470 IUnknown *pObj = NULL;
471 HRESULT hr = E_INVALIDARG;
473 TRACE ("(%p)->(%p,%u,apidl=%p,%s,%p,%p)\n",
474 This, hwndOwner, cidl, apidl, shdebugstr_guid (riid), prgfInOut, ppvOut);
476 if (!ppvOut)
477 return hr;
479 *ppvOut = NULL;
481 if (IsEqualIID (riid, &IID_IContextMenu))
483 if (cidl > 0)
484 pObj = (LPUNKNOWN) ISvItemCm_Constructor( (IShellFolder *) iface, This->pidlRoot, apidl, cidl);
485 else
486 pObj = (LPUNKNOWN) ISvBgCm_Constructor( (IShellFolder *) iface, TRUE);
487 hr = S_OK;
489 else if (IsEqualIID (riid, &IID_IDataObject) && (cidl >= 1))
491 pObj = (LPUNKNOWN) IDataObject_Constructor( hwndOwner,
492 This->pidlRoot, apidl, cidl);
493 hr = S_OK;
495 else if (IsEqualIID (riid, &IID_IExtractIconA) && (cidl == 1))
497 pidl = ILCombine (This->pidlRoot, apidl[0]);
498 pObj = (LPUNKNOWN) IExtractIconA_Constructor (pidl);
499 SHFree (pidl);
500 hr = S_OK;
502 else if (IsEqualIID (riid, &IID_IExtractIconW) && (cidl == 1))
504 pidl = ILCombine (This->pidlRoot, apidl[0]);
505 pObj = (LPUNKNOWN) IExtractIconW_Constructor (pidl);
506 SHFree (pidl);
507 hr = S_OK;
509 else if (IsEqualIID (riid, &IID_IDropTarget) && (cidl >= 1))
511 hr = IShellFolder_QueryInterface (iface,
512 &IID_IDropTarget, (LPVOID *) & pObj);
514 else if ((IsEqualIID(riid,&IID_IShellLinkW) ||
515 IsEqualIID(riid,&IID_IShellLinkA)) && (cidl == 1))
517 pidl = ILCombine (This->pidlRoot, apidl[0]);
518 hr = IShellLink_ConstructFromFile(NULL, riid, pidl, (LPVOID*)&pObj);
519 SHFree (pidl);
521 else
522 hr = E_NOINTERFACE;
524 if (SUCCEEDED(hr) && !pObj)
525 hr = E_OUTOFMEMORY;
527 *ppvOut = pObj;
528 TRACE ("(%p)->hr=0x%08x\n", This, hr);
529 return hr;
532 /**************************************************************************
533 * ISF_Desktop_fnGetDisplayNameOf
535 * NOTES
536 * special case: pidl = null gives desktop-name back
538 static HRESULT WINAPI ISF_Desktop_fnGetDisplayNameOf (IShellFolder2 * iface,
539 LPCITEMIDLIST pidl, DWORD dwFlags, LPSTRRET strRet)
541 IGenericSFImpl *This = (IGenericSFImpl *)iface;
542 HRESULT hr = S_OK;
543 LPWSTR pszPath;
545 TRACE ("(%p)->(pidl=%p,0x%08x,%p)\n", This, pidl, dwFlags, strRet);
546 pdump (pidl);
548 if (!strRet)
549 return E_INVALIDARG;
551 pszPath = CoTaskMemAlloc((MAX_PATH +1) * sizeof(WCHAR));
552 if (!pszPath)
553 return E_OUTOFMEMORY;
555 if (_ILIsDesktop (pidl))
557 if ((GET_SHGDN_RELATION (dwFlags) == SHGDN_NORMAL) &&
558 (GET_SHGDN_FOR (dwFlags) & SHGDN_FORPARSING))
559 strcpyW(pszPath, This->sPathTarget);
560 else
561 HCR_GetClassNameW(&CLSID_ShellDesktop, pszPath, MAX_PATH);
563 else if (_ILIsPidlSimple (pidl))
565 GUID const *clsid;
567 if ((clsid = _ILGetGUIDPointer (pidl)))
569 if (GET_SHGDN_FOR (dwFlags) & SHGDN_FORPARSING)
571 int bWantsForParsing;
574 * We can only get a filesystem path from a shellfolder if the
575 * value WantsFORPARSING in CLSID\\{...}\\shellfolder exists.
577 * Exception: The MyComputer folder doesn't have this key,
578 * but any other filesystem backed folder it needs it.
580 if (IsEqualIID (clsid, &CLSID_MyComputer))
582 bWantsForParsing = TRUE;
584 else
586 /* get the "WantsFORPARSING" flag from the registry */
587 static const WCHAR clsidW[] =
588 { 'C','L','S','I','D','\\',0 };
589 static const WCHAR shellfolderW[] =
590 { '\\','s','h','e','l','l','f','o','l','d','e','r',0 };
591 static const WCHAR wantsForParsingW[] =
592 { 'W','a','n','t','s','F','o','r','P','a','r','s','i','n',
593 'g',0 };
594 WCHAR szRegPath[100];
595 LONG r;
597 lstrcpyW (szRegPath, clsidW);
598 SHELL32_GUIDToStringW (clsid, &szRegPath[6]);
599 lstrcatW (szRegPath, shellfolderW);
600 r = SHGetValueW(HKEY_CLASSES_ROOT, szRegPath,
601 wantsForParsingW, NULL, NULL, NULL);
602 if (r == ERROR_SUCCESS)
603 bWantsForParsing = TRUE;
604 else
605 bWantsForParsing = FALSE;
608 if ((GET_SHGDN_RELATION (dwFlags) == SHGDN_NORMAL) &&
609 bWantsForParsing)
612 * we need the filesystem path to the destination folder.
613 * Only the folder itself can know it
615 hr = SHELL32_GetDisplayNameOfChild (iface, pidl, dwFlags,
616 pszPath,
617 MAX_PATH);
619 else
621 /* parsing name like ::{...} */
622 pszPath[0] = ':';
623 pszPath[1] = ':';
624 SHELL32_GUIDToStringW (clsid, &pszPath[2]);
627 else
629 /* user friendly name */
630 HCR_GetClassNameW (clsid, pszPath, MAX_PATH);
633 else
635 int cLen = 0;
637 /* file system folder or file rooted at the desktop */
638 if ((GET_SHGDN_FOR(dwFlags) == SHGDN_FORPARSING) &&
639 (GET_SHGDN_RELATION(dwFlags) != SHGDN_INFOLDER))
641 lstrcpynW(pszPath, This->sPathTarget, MAX_PATH - 1);
642 PathAddBackslashW(pszPath);
643 cLen = lstrlenW(pszPath);
646 _ILSimpleGetTextW(pidl, pszPath + cLen, MAX_PATH - cLen);
648 if (!_ILIsFolder(pidl))
649 SHELL_FS_ProcessDisplayFilename(pszPath, dwFlags);
652 else
654 /* a complex pidl, let the subfolder do the work */
655 hr = SHELL32_GetDisplayNameOfChild (iface, pidl, dwFlags,
656 pszPath, MAX_PATH);
659 if (SUCCEEDED(hr))
661 /* Win9x always returns ANSI strings, NT always returns Unicode strings */
662 if (GetVersion() & 0x80000000)
664 strRet->uType = STRRET_CSTR;
665 if (!WideCharToMultiByte(CP_ACP, 0, pszPath, -1, strRet->u.cStr, MAX_PATH,
666 NULL, NULL))
667 strRet->u.cStr[0] = '\0';
668 CoTaskMemFree(pszPath);
670 else
672 strRet->uType = STRRET_WSTR;
673 strRet->u.pOleStr = pszPath;
676 else
677 CoTaskMemFree(pszPath);
679 TRACE ("-- (%p)->(%s,0x%08x)\n", This,
680 strRet->uType == STRRET_CSTR ? strRet->u.cStr :
681 debugstr_w(strRet->u.pOleStr), hr);
682 return hr;
685 /**************************************************************************
686 * ISF_Desktop_fnSetNameOf
687 * Changes the name of a file object or subfolder, possibly changing its item
688 * identifier in the process.
690 * PARAMETERS
691 * HWND hwndOwner, //[in ] Owner window for output
692 * LPCITEMIDLIST pidl, //[in ] simple pidl of item to change
693 * LPCOLESTR lpszName, //[in ] the items new display name
694 * DWORD dwFlags, //[in ] SHGNO formatting flags
695 * LPITEMIDLIST* ppidlOut) //[out] simple pidl returned
697 static HRESULT WINAPI ISF_Desktop_fnSetNameOf (IShellFolder2 * iface,
698 HWND hwndOwner, LPCITEMIDLIST pidl, /* simple pidl */
699 LPCOLESTR lpName, DWORD dwFlags, LPITEMIDLIST * pPidlOut)
701 IGenericSFImpl *This = (IGenericSFImpl *)iface;
703 FIXME ("(%p)->(%p,pidl=%p,%s,%u,%p)\n", This, hwndOwner, pidl,
704 debugstr_w (lpName), dwFlags, pPidlOut);
706 return E_FAIL;
709 static HRESULT WINAPI ISF_Desktop_fnGetDefaultSearchGUID(IShellFolder2 *iface,
710 GUID * pguid)
712 IGenericSFImpl *This = (IGenericSFImpl *)iface;
714 FIXME ("(%p)\n", This);
715 return E_NOTIMPL;
718 static HRESULT WINAPI ISF_Desktop_fnEnumSearches (IShellFolder2 *iface,
719 IEnumExtraSearch ** ppenum)
721 IGenericSFImpl *This = (IGenericSFImpl *)iface;
722 FIXME ("(%p)\n", This);
723 return E_NOTIMPL;
726 static HRESULT WINAPI ISF_Desktop_fnGetDefaultColumn (IShellFolder2 * iface,
727 DWORD dwRes, ULONG * pSort, ULONG * pDisplay)
729 IGenericSFImpl *This = (IGenericSFImpl *)iface;
731 TRACE ("(%p)\n", This);
733 if (pSort)
734 *pSort = 0;
735 if (pDisplay)
736 *pDisplay = 0;
738 return S_OK;
740 static HRESULT WINAPI ISF_Desktop_fnGetDefaultColumnState (
741 IShellFolder2 * iface, UINT iColumn, DWORD * pcsFlags)
743 IGenericSFImpl *This = (IGenericSFImpl *)iface;
745 TRACE ("(%p)\n", This);
747 if (!pcsFlags || iColumn >= DESKTOPSHELLVIEWCOLUMNS)
748 return E_INVALIDARG;
750 *pcsFlags = DesktopSFHeader[iColumn].pcsFlags;
752 return S_OK;
755 static HRESULT WINAPI ISF_Desktop_fnGetDetailsEx (IShellFolder2 * iface,
756 LPCITEMIDLIST pidl, const SHCOLUMNID * pscid, VARIANT * pv)
758 IGenericSFImpl *This = (IGenericSFImpl *)iface;
759 FIXME ("(%p)\n", This);
761 return E_NOTIMPL;
764 static HRESULT WINAPI ISF_Desktop_fnGetDetailsOf (IShellFolder2 * iface,
765 LPCITEMIDLIST pidl, UINT iColumn, SHELLDETAILS * psd)
767 IGenericSFImpl *This = (IGenericSFImpl *)iface;
769 HRESULT hr = S_OK;
771 TRACE ("(%p)->(%p %i %p)\n", This, pidl, iColumn, psd);
773 if (!psd || iColumn >= DESKTOPSHELLVIEWCOLUMNS)
774 return E_INVALIDARG;
776 if (!pidl)
778 psd->fmt = DesktopSFHeader[iColumn].fmt;
779 psd->cxChar = DesktopSFHeader[iColumn].cxChar;
780 psd->str.uType = STRRET_CSTR;
781 LoadStringA (shell32_hInstance, DesktopSFHeader[iColumn].colnameid,
782 psd->str.u.cStr, MAX_PATH);
783 return S_OK;
786 /* the data from the pidl */
787 psd->str.uType = STRRET_CSTR;
788 switch (iColumn)
790 case 0: /* name */
791 hr = IShellFolder_GetDisplayNameOf(iface, pidl,
792 SHGDN_NORMAL | SHGDN_INFOLDER, &psd->str);
793 break;
794 case 1: /* size */
795 _ILGetFileSize (pidl, psd->str.u.cStr, MAX_PATH);
796 break;
797 case 2: /* type */
798 _ILGetFileType (pidl, psd->str.u.cStr, MAX_PATH);
799 break;
800 case 3: /* date */
801 _ILGetFileDate (pidl, psd->str.u.cStr, MAX_PATH);
802 break;
803 case 4: /* attributes */
804 _ILGetFileAttributes (pidl, psd->str.u.cStr, MAX_PATH);
805 break;
808 return hr;
811 static HRESULT WINAPI ISF_Desktop_fnMapColumnToSCID (
812 IShellFolder2 * iface, UINT column, SHCOLUMNID * pscid)
814 IGenericSFImpl *This = (IGenericSFImpl *)iface;
815 FIXME ("(%p)\n", This);
816 return E_NOTIMPL;
819 static const IShellFolder2Vtbl vt_MCFldr_ShellFolder2 =
821 ISF_Desktop_fnQueryInterface,
822 ISF_Desktop_fnAddRef,
823 ISF_Desktop_fnRelease,
824 ISF_Desktop_fnParseDisplayName,
825 ISF_Desktop_fnEnumObjects,
826 ISF_Desktop_fnBindToObject,
827 ISF_Desktop_fnBindToStorage,
828 ISF_Desktop_fnCompareIDs,
829 ISF_Desktop_fnCreateViewObject,
830 ISF_Desktop_fnGetAttributesOf,
831 ISF_Desktop_fnGetUIObjectOf,
832 ISF_Desktop_fnGetDisplayNameOf,
833 ISF_Desktop_fnSetNameOf,
834 /* ShellFolder2 */
835 ISF_Desktop_fnGetDefaultSearchGUID,
836 ISF_Desktop_fnEnumSearches,
837 ISF_Desktop_fnGetDefaultColumn,
838 ISF_Desktop_fnGetDefaultColumnState,
839 ISF_Desktop_fnGetDetailsEx,
840 ISF_Desktop_fnGetDetailsOf,
841 ISF_Desktop_fnMapColumnToSCID
844 /**************************************************************************
845 * ISF_Desktop_Constructor
847 HRESULT WINAPI ISF_Desktop_Constructor (
848 IUnknown * pUnkOuter, REFIID riid, LPVOID * ppv)
850 static IGenericSFImpl *cached_sf;
851 WCHAR szMyPath[MAX_PATH];
853 TRACE ("unkOut=%p %s\n", pUnkOuter, shdebugstr_guid (riid));
855 if (!ppv)
856 return E_POINTER;
857 if (pUnkOuter)
858 return CLASS_E_NOAGGREGATION;
860 if (!cached_sf)
862 IGenericSFImpl *sf;
864 if (!SHGetSpecialFolderPathW( 0, szMyPath, CSIDL_DESKTOPDIRECTORY, TRUE ))
865 return E_UNEXPECTED;
867 sf = LocalAlloc( LMEM_ZEROINIT, sizeof (IGenericSFImpl) );
868 if (!sf)
869 return E_OUTOFMEMORY;
871 sf->ref = 1;
872 sf->lpVtbl = &vt_MCFldr_ShellFolder2;
873 sf->pidlRoot = _ILCreateDesktop(); /* my qualified pidl */
874 sf->sPathTarget = SHAlloc( (lstrlenW(szMyPath) + 1)*sizeof(WCHAR) );
875 lstrcpyW( sf->sPathTarget, szMyPath );
877 if (InterlockedCompareExchangePointer((void *)&cached_sf, sf, NULL) != NULL)
879 /* some other thread already been here */
880 SHFree( sf->pidlRoot );
881 SHFree( sf->sPathTarget );
882 LocalFree( sf );
886 return IUnknown_QueryInterface( _IUnknown_(cached_sf), riid, ppv );