Changes in crossover-wine-src-6.1.0 except for configure
[wine/hacks.git] / dlls / shell32 / shfldr_desktop.c
blob3fee311bf0b0008f8991d7f9fe0434d502abec05
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 LPWSTR pszPath;
563 TRACE ("(%p)->(pidl=%p,0x%08x,%p)\n", This, pidl, dwFlags, strRet);
564 pdump (pidl);
566 if (!strRet)
567 return E_INVALIDARG;
569 pszPath = CoTaskMemAlloc((MAX_PATH +1) * sizeof(WCHAR));
570 if (!pszPath)
571 return E_OUTOFMEMORY;
573 if (_ILIsDesktop (pidl))
575 if ((GET_SHGDN_RELATION (dwFlags) == SHGDN_NORMAL) &&
576 (GET_SHGDN_FOR (dwFlags) & SHGDN_FORPARSING))
577 strcpyW(pszPath, This->sPathTarget);
578 else
579 HCR_GetClassNameW(&CLSID_ShellDesktop, pszPath, MAX_PATH);
581 else if (_ILIsPidlSimple (pidl))
583 GUID const *clsid;
585 if ((clsid = _ILGetGUIDPointer (pidl)))
587 if (GET_SHGDN_FOR (dwFlags) & SHGDN_FORPARSING)
589 int bWantsForParsing;
592 * We can only get a filesystem path from a shellfolder if the
593 * value WantsFORPARSING in CLSID\\{...}\\shellfolder exists.
595 * Exception: The MyComputer folder doesn't have this key,
596 * but any other filesystem backed folder it needs it.
598 if (IsEqualIID (clsid, &CLSID_MyComputer))
600 bWantsForParsing = TRUE;
602 else
604 /* get the "WantsFORPARSING" flag from the registry */
605 static const WCHAR clsidW[] =
606 { 'C','L','S','I','D','\\',0 };
607 static const WCHAR shellfolderW[] =
608 { '\\','s','h','e','l','l','f','o','l','d','e','r',0 };
609 static const WCHAR wantsForParsingW[] =
610 { 'W','a','n','t','s','F','o','r','P','a','r','s','i','n',
611 'g',0 };
612 WCHAR szRegPath[100];
613 LONG r;
615 lstrcpyW (szRegPath, clsidW);
616 SHELL32_GUIDToStringW (clsid, &szRegPath[6]);
617 lstrcatW (szRegPath, shellfolderW);
618 r = SHGetValueW(HKEY_CLASSES_ROOT, szRegPath,
619 wantsForParsingW, NULL, NULL, NULL);
620 if (r == ERROR_SUCCESS)
621 bWantsForParsing = TRUE;
622 else
623 bWantsForParsing = FALSE;
626 if ((GET_SHGDN_RELATION (dwFlags) == SHGDN_NORMAL) &&
627 bWantsForParsing)
630 * we need the filesystem path to the destination folder.
631 * Only the folder itself can know it
633 hr = SHELL32_GetDisplayNameOfChild (iface, pidl, dwFlags,
634 pszPath,
635 MAX_PATH);
637 else
639 /* parsing name like ::{...} */
640 pszPath[0] = ':';
641 pszPath[1] = ':';
642 SHELL32_GUIDToStringW (clsid, &pszPath[2]);
645 else
647 /* user friendly name */
648 HCR_GetClassNameW (clsid, pszPath, MAX_PATH);
651 else
653 int cLen = 0;
655 /* file system folder or file rooted at the desktop */
656 if ((GET_SHGDN_FOR(dwFlags) == SHGDN_FORPARSING) &&
657 (GET_SHGDN_RELATION(dwFlags) != SHGDN_INFOLDER))
659 lstrcpynW(pszPath, This->sPathTarget, MAX_PATH - 1);
660 PathAddBackslashW(pszPath);
661 cLen = lstrlenW(pszPath);
664 _ILSimpleGetTextW(pidl, pszPath + cLen, MAX_PATH - cLen);
666 if (!_ILIsFolder(pidl))
667 SHELL_FS_ProcessDisplayFilename(pszPath, dwFlags);
670 else
672 /* a complex pidl, let the subfolder do the work */
673 hr = SHELL32_GetDisplayNameOfChild (iface, pidl, dwFlags,
674 pszPath, MAX_PATH);
677 if (SUCCEEDED(hr))
679 /* Win9x always returns ANSI strings, NT always returns Unicode strings */
680 if (GetVersion() & 0x80000000)
682 strRet->uType = STRRET_CSTR;
683 if (!WideCharToMultiByte(CP_ACP, 0, pszPath, -1, strRet->u.cStr, MAX_PATH,
684 NULL, NULL))
685 strRet->u.cStr[0] = '\0';
686 CoTaskMemFree(pszPath);
688 else
690 strRet->uType = STRRET_WSTR;
691 strRet->u.pOleStr = pszPath;
694 else
695 CoTaskMemFree(pszPath);
697 TRACE ("-- (%p)->(%s,0x%08x)\n", This,
698 strRet->uType == STRRET_CSTR ? strRet->u.cStr :
699 debugstr_w(strRet->u.pOleStr), hr);
700 return hr;
703 /**************************************************************************
704 * ISF_Desktop_fnSetNameOf
705 * Changes the name of a file object or subfolder, possibly changing its item
706 * identifier in the process.
708 * PARAMETERS
709 * HWND hwndOwner, //[in ] Owner window for output
710 * LPCITEMIDLIST pidl, //[in ] simple pidl of item to change
711 * LPCOLESTR lpszName, //[in ] the items new display name
712 * DWORD dwFlags, //[in ] SHGNO formatting flags
713 * LPITEMIDLIST* ppidlOut) //[out] simple pidl returned
715 static HRESULT WINAPI ISF_Desktop_fnSetNameOf (IShellFolder2 * iface,
716 HWND hwndOwner, LPCITEMIDLIST pidl, /* simple pidl */
717 LPCOLESTR lpName, DWORD dwFlags, LPITEMIDLIST * pPidlOut)
719 IGenericSFImpl *This = (IGenericSFImpl *)iface;
721 FIXME ("(%p)->(%p,pidl=%p,%s,%u,%p)\n", This, hwndOwner, pidl,
722 debugstr_w (lpName), dwFlags, pPidlOut);
724 return E_FAIL;
727 static HRESULT WINAPI ISF_Desktop_fnGetDefaultSearchGUID(IShellFolder2 *iface,
728 GUID * pguid)
730 IGenericSFImpl *This = (IGenericSFImpl *)iface;
732 FIXME ("(%p)\n", This);
733 return E_NOTIMPL;
736 static HRESULT WINAPI ISF_Desktop_fnEnumSearches (IShellFolder2 *iface,
737 IEnumExtraSearch ** ppenum)
739 IGenericSFImpl *This = (IGenericSFImpl *)iface;
740 FIXME ("(%p)\n", This);
741 return E_NOTIMPL;
744 static HRESULT WINAPI ISF_Desktop_fnGetDefaultColumn (IShellFolder2 * iface,
745 DWORD dwRes, ULONG * pSort, ULONG * pDisplay)
747 IGenericSFImpl *This = (IGenericSFImpl *)iface;
749 TRACE ("(%p)\n", This);
751 if (pSort)
752 *pSort = 0;
753 if (pDisplay)
754 *pDisplay = 0;
756 return S_OK;
758 static HRESULT WINAPI ISF_Desktop_fnGetDefaultColumnState (
759 IShellFolder2 * iface, UINT iColumn, DWORD * pcsFlags)
761 IGenericSFImpl *This = (IGenericSFImpl *)iface;
763 TRACE ("(%p)\n", This);
765 if (!pcsFlags || iColumn >= DESKTOPSHELLVIEWCOLUMNS)
766 return E_INVALIDARG;
768 *pcsFlags = DesktopSFHeader[iColumn].pcsFlags;
770 return S_OK;
773 static HRESULT WINAPI ISF_Desktop_fnGetDetailsEx (IShellFolder2 * iface,
774 LPCITEMIDLIST pidl, const SHCOLUMNID * pscid, VARIANT * pv)
776 IGenericSFImpl *This = (IGenericSFImpl *)iface;
777 FIXME ("(%p)\n", This);
779 return E_NOTIMPL;
782 static HRESULT WINAPI ISF_Desktop_fnGetDetailsOf (IShellFolder2 * iface,
783 LPCITEMIDLIST pidl, UINT iColumn, SHELLDETAILS * psd)
785 IGenericSFImpl *This = (IGenericSFImpl *)iface;
787 HRESULT hr = S_OK;
789 TRACE ("(%p)->(%p %i %p)\n", This, pidl, iColumn, psd);
791 if (!psd || iColumn >= DESKTOPSHELLVIEWCOLUMNS)
792 return E_INVALIDARG;
794 if (!pidl)
796 psd->fmt = DesktopSFHeader[iColumn].fmt;
797 psd->cxChar = DesktopSFHeader[iColumn].cxChar;
798 psd->str.uType = STRRET_CSTR;
799 LoadStringA (shell32_hInstance, DesktopSFHeader[iColumn].colnameid,
800 psd->str.u.cStr, MAX_PATH);
801 return S_OK;
804 /* the data from the pidl */
805 psd->str.uType = STRRET_CSTR;
806 switch (iColumn)
808 case 0: /* name */
809 hr = IShellFolder_GetDisplayNameOf(iface, pidl,
810 SHGDN_NORMAL | SHGDN_INFOLDER, &psd->str);
811 break;
812 case 1: /* size */
813 _ILGetFileSize (pidl, psd->str.u.cStr, MAX_PATH);
814 break;
815 case 2: /* type */
816 _ILGetFileType (pidl, psd->str.u.cStr, MAX_PATH);
817 break;
818 case 3: /* date */
819 _ILGetFileDate (pidl, psd->str.u.cStr, MAX_PATH);
820 break;
821 case 4: /* attributes */
822 _ILGetFileAttributes (pidl, psd->str.u.cStr, MAX_PATH);
823 break;
826 return hr;
829 static HRESULT WINAPI ISF_Desktop_fnMapColumnToSCID (
830 IShellFolder2 * iface, UINT column, SHCOLUMNID * pscid)
832 IGenericSFImpl *This = (IGenericSFImpl *)iface;
833 FIXME ("(%p)\n", This);
834 return E_NOTIMPL;
837 static const IShellFolder2Vtbl vt_MCFldr_ShellFolder2 =
839 ISF_Desktop_fnQueryInterface,
840 ISF_Desktop_fnAddRef,
841 ISF_Desktop_fnRelease,
842 ISF_Desktop_fnParseDisplayName,
843 ISF_Desktop_fnEnumObjects,
844 ISF_Desktop_fnBindToObject,
845 ISF_Desktop_fnBindToStorage,
846 ISF_Desktop_fnCompareIDs,
847 ISF_Desktop_fnCreateViewObject,
848 ISF_Desktop_fnGetAttributesOf,
849 ISF_Desktop_fnGetUIObjectOf,
850 ISF_Desktop_fnGetDisplayNameOf,
851 ISF_Desktop_fnSetNameOf,
852 /* ShellFolder2 */
853 ISF_Desktop_fnGetDefaultSearchGUID,
854 ISF_Desktop_fnEnumSearches,
855 ISF_Desktop_fnGetDefaultColumn,
856 ISF_Desktop_fnGetDefaultColumnState,
857 ISF_Desktop_fnGetDetailsEx,
858 ISF_Desktop_fnGetDetailsOf,
859 ISF_Desktop_fnMapColumnToSCID
862 /**************************************************************************
863 * ISF_Desktop_Constructor
865 HRESULT WINAPI ISF_Desktop_Constructor (
866 IUnknown * pUnkOuter, REFIID riid, LPVOID * ppv)
868 IGenericSFImpl *sf;
869 WCHAR szMyPath[MAX_PATH];
870 HRESULT r;
872 TRACE ("unkOut=%p %s\n", pUnkOuter, shdebugstr_guid (riid));
874 if (!ppv)
875 return E_POINTER;
876 if (pUnkOuter)
877 return CLASS_E_NOAGGREGATION;
879 if (!SHGetSpecialFolderPathW( 0, szMyPath, CSIDL_DESKTOPDIRECTORY, TRUE ))
880 return E_UNEXPECTED;
882 sf = LocalAlloc( LMEM_ZEROINIT, sizeof (IGenericSFImpl) );
883 if (!sf)
884 return E_OUTOFMEMORY;
886 sf->ref = 0;
887 sf->lpVtbl = &vt_MCFldr_ShellFolder2;
888 sf->pidlRoot = _ILCreateDesktop(); /* my qualified pidl */
889 sf->sPathTarget = SHAlloc( (lstrlenW(szMyPath) + 1)*sizeof(WCHAR) );
890 lstrcpyW( sf->sPathTarget, szMyPath );
892 r = IUnknown_QueryInterface( _IUnknown_(sf), riid, ppv );
893 if (!SUCCEEDED (r))
895 IUnknown_Release( _IUnknown_(sf) );
896 return r;
899 TRACE ("--(%p)\n", sf);
900 return S_OK;