dplayx: Implement proper interface locking for DP_EnumSession.
[wine/multimedia.git] / dlls / shell32 / shfldr_desktop.c
blob428c3f710a27797fd14f25350c8df205d9bd3dea
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 IGenericSFImpl *This = (IGenericSFImpl *)iface;
121 ULONG refCount = InterlockedIncrement(&This->ref);
123 TRACE ("(%p)->(count=%u)\n", This, refCount - 1);
125 return refCount;
128 static ULONG WINAPI ISF_Desktop_fnRelease (IShellFolder2 * iface)
130 IGenericSFImpl *This = (IGenericSFImpl *)iface;
131 ULONG refCount = InterlockedDecrement(&This->ref);
133 TRACE ("(%p)->(count=%u)\n", This, refCount + 1);
135 if (!refCount)
137 TRACE ("-- destroying IShellFolder(%p)\n", This);
138 SHFree (This->pidlRoot);
139 SHFree (This->sPathTarget);
140 LocalFree ((HLOCAL) This);
141 return 0;
143 return refCount;
146 /**************************************************************************
147 * ISF_Desktop_fnParseDisplayName
149 * NOTES
150 * "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}" and "" binds
151 * to MyComputer
153 static HRESULT WINAPI ISF_Desktop_fnParseDisplayName (IShellFolder2 * iface,
154 HWND hwndOwner, LPBC pbc, LPOLESTR lpszDisplayName,
155 DWORD * pchEaten, LPITEMIDLIST * ppidl, DWORD * pdwAttributes)
157 IGenericSFImpl *This = (IGenericSFImpl *)iface;
158 WCHAR szElement[MAX_PATH];
159 LPCWSTR szNext = NULL;
160 LPITEMIDLIST pidlTemp = NULL;
161 HRESULT hr = S_OK;
162 CLSID clsid;
164 TRACE ("(%p)->(HWND=%p,%p,%p=%s,%p,pidl=%p,%p)\n",
165 This, hwndOwner, pbc, lpszDisplayName, debugstr_w(lpszDisplayName),
166 pchEaten, ppidl, pdwAttributes);
168 if (!lpszDisplayName || !ppidl)
169 return E_INVALIDARG;
171 *ppidl = 0;
173 if (pchEaten)
174 *pchEaten = 0; /* strange but like the original */
176 if (lpszDisplayName[0] == ':' && lpszDisplayName[1] == ':')
178 szNext = GetNextElementW (lpszDisplayName, szElement, MAX_PATH);
179 TRACE ("-- element: %s\n", debugstr_w (szElement));
180 SHCLSIDFromStringW (szElement + 2, &clsid);
181 pidlTemp = _ILCreateGuid (PT_GUID, &clsid);
183 else if (PathGetDriveNumberW (lpszDisplayName) >= 0)
185 /* it's a filesystem path with a drive. Let MyComputer/UnixDosFolder parse it */
186 if (UNIXFS_is_rooted_at_desktop())
187 pidlTemp = _ILCreateGuid(PT_GUID, &CLSID_UnixDosFolder);
188 else
189 pidlTemp = _ILCreateMyComputer ();
190 szNext = lpszDisplayName;
192 else if (PathIsUNCW(lpszDisplayName))
194 pidlTemp = _ILCreateNetwork();
195 szNext = lpszDisplayName;
197 else if( (pidlTemp = SHELL32_CreatePidlFromBindCtx(pbc, lpszDisplayName)) )
199 *ppidl = pidlTemp;
200 return S_OK;
202 else
204 /* it's a filesystem path on the desktop. Let a FSFolder parse it */
206 if (*lpszDisplayName)
208 WCHAR szPath[MAX_PATH];
209 LPWSTR pathPtr;
211 /* build a complete path to create a simple pidl */
212 lstrcpynW(szPath, This->sPathTarget, MAX_PATH);
213 pathPtr = PathAddBackslashW(szPath);
214 if (pathPtr)
216 lstrcpynW(pathPtr, lpszDisplayName, MAX_PATH - (pathPtr - szPath));
217 hr = _ILCreateFromPathW(szPath, &pidlTemp);
219 else
221 /* should never reach here, but for completeness */
222 hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
225 else
226 pidlTemp = _ILCreateMyComputer();
228 szNext = NULL;
231 if (SUCCEEDED(hr) && pidlTemp)
233 if (szNext && *szNext)
235 hr = SHELL32_ParseNextElement(iface, hwndOwner, pbc,
236 &pidlTemp, (LPOLESTR) szNext, pchEaten, pdwAttributes);
238 else
240 if (pdwAttributes && *pdwAttributes)
241 hr = SHELL32_GetItemAttributes(_IShellFolder_ (This),
242 pidlTemp, pdwAttributes);
246 *ppidl = pidlTemp;
248 TRACE ("(%p)->(-- ret=0x%08x)\n", This, hr);
250 return hr;
253 /**************************************************************************
254 * CreateDesktopEnumList()
256 static const WCHAR Desktop_NameSpaceW[] = { 'S','O','F','T','W','A','R','E',
257 '\\','M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
258 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\','E','x','p','l',
259 'o','r','e','r','\\','D','e','s','k','t','o','p','\\','N','a','m','e','s','p',
260 'a','c','e','\0' };
262 static BOOL CreateDesktopEnumList(IEnumIDList *list, DWORD dwFlags)
264 BOOL ret = TRUE;
265 WCHAR szPath[MAX_PATH];
267 TRACE("(%p)->(flags=0x%08x)\n", list, dwFlags);
269 /* enumerate the root folders */
270 if (dwFlags & SHCONTF_FOLDERS)
272 HKEY hkey;
273 UINT i;
275 /* create the pidl for This item */
276 ret = AddToEnumList(list, _ILCreateMyComputer());
278 for (i=0; i<2; i++) {
279 if (ret && !RegOpenKeyExW(i == 0 ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER,
280 Desktop_NameSpaceW, 0, KEY_READ, &hkey))
282 WCHAR iid[50];
283 int i=0;
285 while (ret)
287 DWORD size;
288 LONG r;
290 size = sizeof (iid);
291 r = RegEnumKeyExW(hkey, i, iid, &size, 0, NULL, NULL, NULL);
292 if (ERROR_SUCCESS == r)
294 ret = AddToEnumList(list, _ILCreateGuidFromStrW(iid));
295 i++;
297 else if (ERROR_NO_MORE_ITEMS == r)
298 break;
299 else
300 ret = FALSE;
302 RegCloseKey(hkey);
307 /* enumerate the elements in %windir%\desktop */
308 SHGetSpecialFolderPathW(0, szPath, CSIDL_DESKTOPDIRECTORY, FALSE);
309 ret = ret && CreateFolderEnumList(list, szPath, dwFlags);
311 return ret;
314 /**************************************************************************
315 * ISF_Desktop_fnEnumObjects
317 static HRESULT WINAPI ISF_Desktop_fnEnumObjects (IShellFolder2 * iface,
318 HWND hwndOwner, DWORD dwFlags, LPENUMIDLIST * ppEnumIDList)
320 IGenericSFImpl *This = (IGenericSFImpl *)iface;
322 TRACE ("(%p)->(HWND=%p flags=0x%08x pplist=%p)\n",
323 This, hwndOwner, dwFlags, ppEnumIDList);
325 *ppEnumIDList = IEnumIDList_Constructor();
326 if (*ppEnumIDList)
327 CreateDesktopEnumList(*ppEnumIDList, dwFlags);
329 TRACE ("-- (%p)->(new ID List: %p)\n", This, *ppEnumIDList);
331 return *ppEnumIDList ? S_OK : E_OUTOFMEMORY;
334 /**************************************************************************
335 * ISF_Desktop_fnBindToObject
337 static HRESULT WINAPI ISF_Desktop_fnBindToObject (IShellFolder2 * iface,
338 LPCITEMIDLIST pidl, LPBC pbcReserved, REFIID riid, LPVOID * ppvOut)
340 IGenericSFImpl *This = (IGenericSFImpl *)iface;
342 TRACE ("(%p)->(pidl=%p,%p,%s,%p)\n",
343 This, pidl, pbcReserved, shdebugstr_guid (riid), ppvOut);
345 return SHELL32_BindToChild( This->pidlRoot, This->sPathTarget, pidl, riid, ppvOut );
348 /**************************************************************************
349 * ISF_Desktop_fnBindToStorage
351 static HRESULT WINAPI ISF_Desktop_fnBindToStorage (IShellFolder2 * iface,
352 LPCITEMIDLIST pidl, LPBC pbcReserved, REFIID riid, LPVOID * ppvOut)
354 IGenericSFImpl *This = (IGenericSFImpl *)iface;
356 FIXME ("(%p)->(pidl=%p,%p,%s,%p) stub\n",
357 This, pidl, pbcReserved, shdebugstr_guid (riid), ppvOut);
359 *ppvOut = NULL;
360 return E_NOTIMPL;
363 /**************************************************************************
364 * ISF_Desktop_fnCompareIDs
366 static HRESULT WINAPI ISF_Desktop_fnCompareIDs (IShellFolder2 * iface,
367 LPARAM lParam, LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
369 IGenericSFImpl *This = (IGenericSFImpl *)iface;
370 int nReturn;
372 TRACE ("(%p)->(0x%08lx,pidl1=%p,pidl2=%p)\n", This, lParam, pidl1, pidl2);
373 nReturn = SHELL32_CompareIDs (_IShellFolder_ (This), lParam, pidl1, pidl2);
374 TRACE ("-- %i\n", nReturn);
375 return nReturn;
378 /**************************************************************************
379 * ISF_Desktop_fnCreateViewObject
381 static HRESULT WINAPI ISF_Desktop_fnCreateViewObject (IShellFolder2 * iface,
382 HWND hwndOwner, REFIID riid, LPVOID * ppvOut)
384 IGenericSFImpl *This = (IGenericSFImpl *)iface;
385 LPSHELLVIEW pShellView;
386 HRESULT hr = E_INVALIDARG;
388 TRACE ("(%p)->(hwnd=%p,%s,%p)\n",
389 This, hwndOwner, shdebugstr_guid (riid), ppvOut);
391 if (!ppvOut)
392 return hr;
394 *ppvOut = NULL;
396 if (IsEqualIID (riid, &IID_IDropTarget))
398 WARN ("IDropTarget not implemented\n");
399 hr = E_NOTIMPL;
401 else if (IsEqualIID (riid, &IID_IContextMenu))
403 WARN ("IContextMenu not implemented\n");
404 hr = E_NOTIMPL;
406 else if (IsEqualIID (riid, &IID_IShellView))
408 pShellView = IShellView_Constructor ((IShellFolder *) iface);
409 if (pShellView)
411 hr = IShellView_QueryInterface (pShellView, riid, ppvOut);
412 IShellView_Release (pShellView);
415 TRACE ("-- (%p)->(interface=%p)\n", This, ppvOut);
416 return hr;
419 /**************************************************************************
420 * ISF_Desktop_fnGetAttributesOf
422 static HRESULT WINAPI ISF_Desktop_fnGetAttributesOf (IShellFolder2 * iface,
423 UINT cidl, LPCITEMIDLIST * apidl, DWORD * rgfInOut)
425 IGenericSFImpl *This = (IGenericSFImpl *)iface;
426 HRESULT hr = S_OK;
427 static const DWORD dwDesktopAttributes =
428 SFGAO_STORAGE | SFGAO_HASPROPSHEET | SFGAO_STORAGEANCESTOR |
429 SFGAO_FILESYSANCESTOR | SFGAO_FOLDER | SFGAO_FILESYSTEM | SFGAO_HASSUBFOLDER;
430 static const DWORD dwMyComputerAttributes =
431 SFGAO_CANRENAME | SFGAO_CANDELETE | SFGAO_HASPROPSHEET |
432 SFGAO_DROPTARGET | SFGAO_FILESYSANCESTOR | SFGAO_FOLDER | SFGAO_HASSUBFOLDER;
434 TRACE ("(%p)->(cidl=%d apidl=%p mask=%p (0x%08x))\n",
435 This, cidl, apidl, rgfInOut, rgfInOut ? *rgfInOut : 0);
437 if (!rgfInOut)
438 return E_INVALIDARG;
439 if (cidl && !apidl)
440 return E_INVALIDARG;
442 if (*rgfInOut == 0)
443 *rgfInOut = ~0;
445 if(cidl == 0) {
446 *rgfInOut &= dwDesktopAttributes;
447 } else {
448 while (cidl > 0 && *apidl) {
449 pdump (*apidl);
450 if (_ILIsDesktop(*apidl)) {
451 *rgfInOut &= dwDesktopAttributes;
452 } else if (_ILIsMyComputer(*apidl)) {
453 *rgfInOut &= dwMyComputerAttributes;
454 } else {
455 SHELL32_GetItemAttributes (_IShellFolder_ (This), *apidl, rgfInOut);
457 apidl++;
458 cidl--;
461 /* make sure SFGAO_VALIDATE is cleared, some apps depend on that */
462 *rgfInOut &= ~SFGAO_VALIDATE;
464 TRACE ("-- result=0x%08x\n", *rgfInOut);
466 return hr;
469 /**************************************************************************
470 * ISF_Desktop_fnGetUIObjectOf
472 * PARAMETERS
473 * HWND hwndOwner, //[in ] Parent window for any output
474 * UINT cidl, //[in ] array size
475 * LPCITEMIDLIST* apidl, //[in ] simple pidl array
476 * REFIID riid, //[in ] Requested Interface
477 * UINT* prgfInOut, //[ ] reserved
478 * LPVOID* ppvObject) //[out] Resulting Interface
481 static HRESULT WINAPI ISF_Desktop_fnGetUIObjectOf (IShellFolder2 * iface,
482 HWND hwndOwner, UINT cidl, LPCITEMIDLIST * apidl,
483 REFIID riid, UINT * prgfInOut, LPVOID * ppvOut)
485 IGenericSFImpl *This = (IGenericSFImpl *)iface;
487 LPITEMIDLIST pidl;
488 IUnknown *pObj = NULL;
489 HRESULT hr = E_INVALIDARG;
491 TRACE ("(%p)->(%p,%u,apidl=%p,%s,%p,%p)\n",
492 This, hwndOwner, cidl, apidl, shdebugstr_guid (riid), prgfInOut, ppvOut);
494 if (!ppvOut)
495 return hr;
497 *ppvOut = NULL;
499 if (IsEqualIID (riid, &IID_IContextMenu))
501 if (cidl > 0)
502 pObj = (LPUNKNOWN) ISvItemCm_Constructor( (IShellFolder *) iface, This->pidlRoot, apidl, cidl);
503 else
504 pObj = (LPUNKNOWN) ISvBgCm_Constructor( (IShellFolder *) iface, TRUE);
505 hr = S_OK;
507 else if (IsEqualIID (riid, &IID_IDataObject) && (cidl >= 1))
509 pObj = (LPUNKNOWN) IDataObject_Constructor( hwndOwner,
510 This->pidlRoot, apidl, cidl);
511 hr = S_OK;
513 else if (IsEqualIID (riid, &IID_IExtractIconA) && (cidl == 1))
515 pidl = ILCombine (This->pidlRoot, apidl[0]);
516 pObj = (LPUNKNOWN) IExtractIconA_Constructor (pidl);
517 SHFree (pidl);
518 hr = S_OK;
520 else if (IsEqualIID (riid, &IID_IExtractIconW) && (cidl == 1))
522 pidl = ILCombine (This->pidlRoot, apidl[0]);
523 pObj = (LPUNKNOWN) IExtractIconW_Constructor (pidl);
524 SHFree (pidl);
525 hr = S_OK;
527 else if (IsEqualIID (riid, &IID_IDropTarget) && (cidl >= 1))
529 hr = IShellFolder_QueryInterface (iface,
530 &IID_IDropTarget, (LPVOID *) & pObj);
532 else if ((IsEqualIID(riid,&IID_IShellLinkW) ||
533 IsEqualIID(riid,&IID_IShellLinkA)) && (cidl == 1))
535 pidl = ILCombine (This->pidlRoot, apidl[0]);
536 hr = IShellLink_ConstructFromFile(NULL, riid, pidl, (LPVOID*)&pObj);
537 SHFree (pidl);
539 else
540 hr = E_NOINTERFACE;
542 if (SUCCEEDED(hr) && !pObj)
543 hr = E_OUTOFMEMORY;
545 *ppvOut = pObj;
546 TRACE ("(%p)->hr=0x%08x\n", This, hr);
547 return hr;
550 /**************************************************************************
551 * ISF_Desktop_fnGetDisplayNameOf
553 * NOTES
554 * special case: pidl = null gives desktop-name back
556 static HRESULT WINAPI ISF_Desktop_fnGetDisplayNameOf (IShellFolder2 * iface,
557 LPCITEMIDLIST pidl, DWORD dwFlags, LPSTRRET strRet)
559 IGenericSFImpl *This = (IGenericSFImpl *)iface;
560 HRESULT hr = S_OK;
561 WCHAR wszPath[MAX_PATH];
563 TRACE ("(%p)->(pidl=%p,0x%08x,%p)\n", This, pidl, dwFlags, strRet);
564 pdump (pidl);
566 if (!strRet)
567 return E_INVALIDARG;
569 if (_ILIsDesktop (pidl))
571 if ((GET_SHGDN_RELATION (dwFlags) == SHGDN_NORMAL) &&
572 (GET_SHGDN_FOR (dwFlags) & SHGDN_FORPARSING))
573 strcpyW(wszPath, This->sPathTarget);
574 else
575 HCR_GetClassNameW(&CLSID_ShellDesktop, wszPath, MAX_PATH);
577 else if (_ILIsPidlSimple (pidl))
579 GUID const *clsid;
581 if ((clsid = _ILGetGUIDPointer (pidl)))
583 if (GET_SHGDN_FOR (dwFlags) & SHGDN_FORPARSING)
585 int bWantsForParsing;
588 * We can only get a filesystem path from a shellfolder if the
589 * value WantsFORPARSING in CLSID\\{...}\\shellfolder exists.
591 * Exception: The MyComputer folder doesn't have this key,
592 * but any other filesystem backed folder it needs it.
594 if (IsEqualIID (clsid, &CLSID_MyComputer))
596 bWantsForParsing = TRUE;
598 else
600 /* get the "WantsFORPARSING" flag from the registry */
601 static const WCHAR clsidW[] =
602 { 'C','L','S','I','D','\\',0 };
603 static const WCHAR shellfolderW[] =
604 { '\\','s','h','e','l','l','f','o','l','d','e','r',0 };
605 static const WCHAR wantsForParsingW[] =
606 { 'W','a','n','t','s','F','o','r','P','a','r','s','i','n',
607 'g',0 };
608 WCHAR szRegPath[100];
609 LONG r;
611 lstrcpyW (szRegPath, clsidW);
612 SHELL32_GUIDToStringW (clsid, &szRegPath[6]);
613 lstrcatW (szRegPath, shellfolderW);
614 r = SHGetValueW(HKEY_CLASSES_ROOT, szRegPath,
615 wantsForParsingW, NULL, NULL, NULL);
616 if (r == ERROR_SUCCESS)
617 bWantsForParsing = TRUE;
618 else
619 bWantsForParsing = FALSE;
622 if ((GET_SHGDN_RELATION (dwFlags) == SHGDN_NORMAL) &&
623 bWantsForParsing)
626 * we need the filesystem path to the destination folder.
627 * Only the folder itself can know it
629 hr = SHELL32_GetDisplayNameOfChild (iface, pidl, dwFlags,
630 wszPath,
631 MAX_PATH);
633 else
635 /* parsing name like ::{...} */
636 wszPath[0] = ':';
637 wszPath[1] = ':';
638 SHELL32_GUIDToStringW (clsid, &wszPath[2]);
641 else
643 /* user friendly name */
644 HCR_GetClassNameW (clsid, wszPath, MAX_PATH);
647 else
649 int cLen = 0;
651 /* file system folder or file rooted at the desktop */
652 if ((GET_SHGDN_FOR(dwFlags) == SHGDN_FORPARSING) &&
653 (GET_SHGDN_RELATION(dwFlags) != SHGDN_INFOLDER))
655 lstrcpynW(wszPath, This->sPathTarget, MAX_PATH - 1);
656 PathAddBackslashW(wszPath);
657 cLen = lstrlenW(wszPath);
660 _ILSimpleGetTextW(pidl, wszPath + cLen, MAX_PATH - cLen);
662 if (!_ILIsFolder(pidl))
663 SHELL_FS_ProcessDisplayFilename(wszPath, dwFlags);
666 else
668 /* a complex pidl, let the subfolder do the work */
669 hr = SHELL32_GetDisplayNameOfChild (iface, pidl, dwFlags,
670 wszPath, MAX_PATH);
673 if (SUCCEEDED(hr))
675 BOOL defCharUsed;
676 strRet->uType = STRRET_CSTR;
677 if (!WideCharToMultiByte(CP_ACP, 0, wszPath, -1, strRet->u.cStr, MAX_PATH,
678 NULL, &defCharUsed))
679 strRet->u.cStr[0] = '\0';
680 if (defCharUsed)
682 strRet->u.pOleStr = SHAlloc((lstrlenW(This->sPathTarget)+1) *
683 sizeof(WCHAR));
684 if (!strRet->u.pOleStr)
685 hr = E_OUTOFMEMORY;
686 else
688 strcpyW(strRet->u.pOleStr, This->sPathTarget);
689 strRet->uType = STRRET_WSTR;
694 TRACE ("-- (%p)->(%s,0x%08x)\n", This,
695 strRet->uType == STRRET_CSTR ? strRet->u.cStr :
696 debugstr_w(strRet->u.pOleStr), hr);
697 return hr;
700 /**************************************************************************
701 * ISF_Desktop_fnSetNameOf
702 * Changes the name of a file object or subfolder, possibly changing its item
703 * identifier in the process.
705 * PARAMETERS
706 * HWND hwndOwner, //[in ] Owner window for output
707 * LPCITEMIDLIST pidl, //[in ] simple pidl of item to change
708 * LPCOLESTR lpszName, //[in ] the items new display name
709 * DWORD dwFlags, //[in ] SHGNO formatting flags
710 * LPITEMIDLIST* ppidlOut) //[out] simple pidl returned
712 static HRESULT WINAPI ISF_Desktop_fnSetNameOf (IShellFolder2 * iface,
713 HWND hwndOwner, LPCITEMIDLIST pidl, /* simple pidl */
714 LPCOLESTR lpName, DWORD dwFlags, LPITEMIDLIST * pPidlOut)
716 IGenericSFImpl *This = (IGenericSFImpl *)iface;
718 FIXME ("(%p)->(%p,pidl=%p,%s,%u,%p)\n", This, hwndOwner, pidl,
719 debugstr_w (lpName), dwFlags, pPidlOut);
721 return E_FAIL;
724 static HRESULT WINAPI ISF_Desktop_fnGetDefaultSearchGUID(IShellFolder2 *iface,
725 GUID * pguid)
727 IGenericSFImpl *This = (IGenericSFImpl *)iface;
729 FIXME ("(%p)\n", This);
730 return E_NOTIMPL;
733 static HRESULT WINAPI ISF_Desktop_fnEnumSearches (IShellFolder2 *iface,
734 IEnumExtraSearch ** ppenum)
736 IGenericSFImpl *This = (IGenericSFImpl *)iface;
737 FIXME ("(%p)\n", This);
738 return E_NOTIMPL;
741 static HRESULT WINAPI ISF_Desktop_fnGetDefaultColumn (IShellFolder2 * iface,
742 DWORD dwRes, ULONG * pSort, ULONG * pDisplay)
744 IGenericSFImpl *This = (IGenericSFImpl *)iface;
746 TRACE ("(%p)\n", This);
748 if (pSort)
749 *pSort = 0;
750 if (pDisplay)
751 *pDisplay = 0;
753 return S_OK;
755 static HRESULT WINAPI ISF_Desktop_fnGetDefaultColumnState (
756 IShellFolder2 * iface, UINT iColumn, DWORD * pcsFlags)
758 IGenericSFImpl *This = (IGenericSFImpl *)iface;
760 TRACE ("(%p)\n", This);
762 if (!pcsFlags || iColumn >= DESKTOPSHELLVIEWCOLUMNS)
763 return E_INVALIDARG;
765 *pcsFlags = DesktopSFHeader[iColumn].pcsFlags;
767 return S_OK;
770 static HRESULT WINAPI ISF_Desktop_fnGetDetailsEx (IShellFolder2 * iface,
771 LPCITEMIDLIST pidl, const SHCOLUMNID * pscid, VARIANT * pv)
773 IGenericSFImpl *This = (IGenericSFImpl *)iface;
774 FIXME ("(%p)\n", This);
776 return E_NOTIMPL;
779 static HRESULT WINAPI ISF_Desktop_fnGetDetailsOf (IShellFolder2 * iface,
780 LPCITEMIDLIST pidl, UINT iColumn, SHELLDETAILS * psd)
782 IGenericSFImpl *This = (IGenericSFImpl *)iface;
784 HRESULT hr = S_OK;
786 TRACE ("(%p)->(%p %i %p)\n", This, pidl, iColumn, psd);
788 if (!psd || iColumn >= DESKTOPSHELLVIEWCOLUMNS)
789 return E_INVALIDARG;
791 if (!pidl)
793 psd->fmt = DesktopSFHeader[iColumn].fmt;
794 psd->cxChar = DesktopSFHeader[iColumn].cxChar;
795 psd->str.uType = STRRET_CSTR;
796 LoadStringA (shell32_hInstance, DesktopSFHeader[iColumn].colnameid,
797 psd->str.u.cStr, MAX_PATH);
798 return S_OK;
801 /* the data from the pidl */
802 psd->str.uType = STRRET_CSTR;
803 switch (iColumn)
805 case 0: /* name */
806 hr = IShellFolder_GetDisplayNameOf(iface, pidl,
807 SHGDN_NORMAL | SHGDN_INFOLDER, &psd->str);
808 break;
809 case 1: /* size */
810 _ILGetFileSize (pidl, psd->str.u.cStr, MAX_PATH);
811 break;
812 case 2: /* type */
813 _ILGetFileType (pidl, psd->str.u.cStr, MAX_PATH);
814 break;
815 case 3: /* date */
816 _ILGetFileDate (pidl, psd->str.u.cStr, MAX_PATH);
817 break;
818 case 4: /* attributes */
819 _ILGetFileAttributes (pidl, psd->str.u.cStr, MAX_PATH);
820 break;
823 return hr;
826 static HRESULT WINAPI ISF_Desktop_fnMapColumnToSCID (
827 IShellFolder2 * iface, UINT column, SHCOLUMNID * pscid)
829 IGenericSFImpl *This = (IGenericSFImpl *)iface;
830 FIXME ("(%p)\n", This);
831 return E_NOTIMPL;
834 static const IShellFolder2Vtbl vt_MCFldr_ShellFolder2 =
836 ISF_Desktop_fnQueryInterface,
837 ISF_Desktop_fnAddRef,
838 ISF_Desktop_fnRelease,
839 ISF_Desktop_fnParseDisplayName,
840 ISF_Desktop_fnEnumObjects,
841 ISF_Desktop_fnBindToObject,
842 ISF_Desktop_fnBindToStorage,
843 ISF_Desktop_fnCompareIDs,
844 ISF_Desktop_fnCreateViewObject,
845 ISF_Desktop_fnGetAttributesOf,
846 ISF_Desktop_fnGetUIObjectOf,
847 ISF_Desktop_fnGetDisplayNameOf,
848 ISF_Desktop_fnSetNameOf,
849 /* ShellFolder2 */
850 ISF_Desktop_fnGetDefaultSearchGUID,
851 ISF_Desktop_fnEnumSearches,
852 ISF_Desktop_fnGetDefaultColumn,
853 ISF_Desktop_fnGetDefaultColumnState,
854 ISF_Desktop_fnGetDetailsEx,
855 ISF_Desktop_fnGetDetailsOf,
856 ISF_Desktop_fnMapColumnToSCID
859 /**************************************************************************
860 * ISF_Desktop_Constructor
862 HRESULT WINAPI ISF_Desktop_Constructor (
863 IUnknown * pUnkOuter, REFIID riid, LPVOID * ppv)
865 IGenericSFImpl *sf;
866 WCHAR szMyPath[MAX_PATH];
867 HRESULT r;
869 TRACE ("unkOut=%p %s\n", pUnkOuter, shdebugstr_guid (riid));
871 if (!ppv)
872 return E_POINTER;
873 if (pUnkOuter)
874 return CLASS_E_NOAGGREGATION;
876 if (!SHGetSpecialFolderPathW( 0, szMyPath, CSIDL_DESKTOPDIRECTORY, TRUE ))
877 return E_UNEXPECTED;
879 sf = LocalAlloc( LMEM_ZEROINIT, sizeof (IGenericSFImpl) );
880 if (!sf)
881 return E_OUTOFMEMORY;
883 sf->ref = 0;
884 sf->lpVtbl = &vt_MCFldr_ShellFolder2;
885 sf->pidlRoot = _ILCreateDesktop(); /* my qualified pidl */
886 sf->sPathTarget = SHAlloc( (lstrlenW(szMyPath) + 1)*sizeof(WCHAR) );
887 lstrcpyW( sf->sPathTarget, szMyPath );
889 r = IUnknown_QueryInterface( _IUnknown_(sf), riid, ppv );
890 if (!SUCCEEDED (r))
892 IUnknown_Release( _IUnknown_(sf) );
893 return r;
896 TRACE ("--(%p)\n", sf);
897 return S_OK;