cmd: Fix German translation.
[wine/hramrach.git] / dlls / shell32 / shfldr_desktop.c
bloba08bb41110a1217c94f201e94e33cf930e75fa1c
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 PARSEDURLW urldata;
192 urldata.cbSize = sizeof(urldata);
193 ParseURLW(lpszDisplayName,&urldata);
195 if (urldata.nScheme == URL_SCHEME_SHELL) /* handle shell: urls */
197 TRACE ("-- shell url: %s\n", debugstr_w(urldata.pszSuffix));
198 SHCLSIDFromStringW (urldata.pszSuffix+2, &clsid);
199 pidlTemp = _ILCreateGuid (PT_GUID, &clsid);
201 else
202 return IEParseDisplayNameWithBCW(CP_ACP,lpszDisplayName,pbc,ppidl);
204 else
206 /* it's a filesystem path on the desktop. Let a FSFolder parse it */
208 if (*lpszDisplayName)
210 WCHAR szPath[MAX_PATH];
211 LPWSTR pathPtr;
213 /* build a complete path to create a simple pidl */
214 lstrcpynW(szPath, This->sPathTarget, MAX_PATH);
215 pathPtr = PathAddBackslashW(szPath);
216 if (pathPtr)
218 lstrcpynW(pathPtr, lpszDisplayName, MAX_PATH - (pathPtr - szPath));
219 hr = _ILCreateFromPathW(szPath, &pidlTemp);
221 else
223 /* should never reach here, but for completeness */
224 hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
227 else
228 pidlTemp = _ILCreateMyComputer();
230 szNext = NULL;
233 if (SUCCEEDED(hr) && pidlTemp)
235 if (szNext && *szNext)
237 hr = SHELL32_ParseNextElement(iface, hwndOwner, pbc,
238 &pidlTemp, (LPOLESTR) szNext, pchEaten, pdwAttributes);
240 else
242 if (pdwAttributes && *pdwAttributes)
243 hr = SHELL32_GetItemAttributes(_IShellFolder_ (This),
244 pidlTemp, pdwAttributes);
248 *ppidl = pidlTemp;
250 TRACE ("(%p)->(-- ret=0x%08x)\n", This, hr);
252 return hr;
255 /**************************************************************************
256 * CreateDesktopEnumList()
258 static const WCHAR Desktop_NameSpaceW[] = { 'S','O','F','T','W','A','R','E',
259 '\\','M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
260 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\','E','x','p','l',
261 'o','r','e','r','\\','D','e','s','k','t','o','p','\\','N','a','m','e','s','p',
262 'a','c','e','\0' };
264 static BOOL CreateDesktopEnumList(IEnumIDList *list, DWORD dwFlags)
266 BOOL ret = TRUE;
267 WCHAR szPath[MAX_PATH];
269 TRACE("(%p)->(flags=0x%08x)\n", list, dwFlags);
271 /* enumerate the root folders */
272 if (dwFlags & SHCONTF_FOLDERS)
274 HKEY hkey;
275 UINT i;
277 /* create the pidl for This item */
278 ret = AddToEnumList(list, _ILCreateMyComputer());
280 for (i=0; i<2; i++) {
281 if (ret && !RegOpenKeyExW(i == 0 ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER,
282 Desktop_NameSpaceW, 0, KEY_READ, &hkey))
284 WCHAR iid[50];
285 int i=0;
287 while (ret)
289 DWORD size;
290 LONG r;
292 size = sizeof (iid) / sizeof (iid[0]);
293 r = RegEnumKeyExW(hkey, i, iid, &size, 0, NULL, NULL, NULL);
294 if (ERROR_SUCCESS == r)
296 ret = AddToEnumList(list, _ILCreateGuidFromStrW(iid));
297 i++;
299 else if (ERROR_NO_MORE_ITEMS == r)
300 break;
301 else
302 ret = FALSE;
304 RegCloseKey(hkey);
309 /* enumerate the elements in %windir%\desktop */
310 SHGetSpecialFolderPathW(0, szPath, CSIDL_DESKTOPDIRECTORY, FALSE);
311 ret = ret && CreateFolderEnumList(list, szPath, dwFlags);
313 return ret;
316 /**************************************************************************
317 * ISF_Desktop_fnEnumObjects
319 static HRESULT WINAPI ISF_Desktop_fnEnumObjects (IShellFolder2 * iface,
320 HWND hwndOwner, DWORD dwFlags, LPENUMIDLIST * ppEnumIDList)
322 IGenericSFImpl *This = (IGenericSFImpl *)iface;
324 TRACE ("(%p)->(HWND=%p flags=0x%08x pplist=%p)\n",
325 This, hwndOwner, dwFlags, ppEnumIDList);
327 *ppEnumIDList = IEnumIDList_Constructor();
328 if (*ppEnumIDList)
329 CreateDesktopEnumList(*ppEnumIDList, dwFlags);
331 TRACE ("-- (%p)->(new ID List: %p)\n", This, *ppEnumIDList);
333 return *ppEnumIDList ? S_OK : E_OUTOFMEMORY;
336 /**************************************************************************
337 * ISF_Desktop_fnBindToObject
339 static HRESULT WINAPI ISF_Desktop_fnBindToObject (IShellFolder2 * iface,
340 LPCITEMIDLIST pidl, LPBC pbcReserved, REFIID riid, LPVOID * ppvOut)
342 IGenericSFImpl *This = (IGenericSFImpl *)iface;
344 TRACE ("(%p)->(pidl=%p,%p,%s,%p)\n",
345 This, pidl, pbcReserved, shdebugstr_guid (riid), ppvOut);
347 return SHELL32_BindToChild( This->pidlRoot, This->sPathTarget, pidl, riid, ppvOut );
350 /**************************************************************************
351 * ISF_Desktop_fnBindToStorage
353 static HRESULT WINAPI ISF_Desktop_fnBindToStorage (IShellFolder2 * iface,
354 LPCITEMIDLIST pidl, LPBC pbcReserved, REFIID riid, LPVOID * ppvOut)
356 IGenericSFImpl *This = (IGenericSFImpl *)iface;
358 FIXME ("(%p)->(pidl=%p,%p,%s,%p) stub\n",
359 This, pidl, pbcReserved, shdebugstr_guid (riid), ppvOut);
361 *ppvOut = NULL;
362 return E_NOTIMPL;
365 /**************************************************************************
366 * ISF_Desktop_fnCompareIDs
368 static HRESULT WINAPI ISF_Desktop_fnCompareIDs (IShellFolder2 * iface,
369 LPARAM lParam, LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
371 IGenericSFImpl *This = (IGenericSFImpl *)iface;
372 int nReturn;
374 TRACE ("(%p)->(0x%08lx,pidl1=%p,pidl2=%p)\n", This, lParam, pidl1, pidl2);
375 nReturn = SHELL32_CompareIDs (_IShellFolder_ (This), lParam, pidl1, pidl2);
376 TRACE ("-- %i\n", nReturn);
377 return nReturn;
380 /**************************************************************************
381 * ISF_Desktop_fnCreateViewObject
383 static HRESULT WINAPI ISF_Desktop_fnCreateViewObject (IShellFolder2 * iface,
384 HWND hwndOwner, REFIID riid, LPVOID * ppvOut)
386 IGenericSFImpl *This = (IGenericSFImpl *)iface;
387 LPSHELLVIEW pShellView;
388 HRESULT hr = E_INVALIDARG;
390 TRACE ("(%p)->(hwnd=%p,%s,%p)\n",
391 This, hwndOwner, shdebugstr_guid (riid), ppvOut);
393 if (!ppvOut)
394 return hr;
396 *ppvOut = NULL;
398 if (IsEqualIID (riid, &IID_IDropTarget))
400 WARN ("IDropTarget not implemented\n");
401 hr = E_NOTIMPL;
403 else if (IsEqualIID (riid, &IID_IContextMenu))
405 WARN ("IContextMenu not implemented\n");
406 hr = E_NOTIMPL;
408 else if (IsEqualIID (riid, &IID_IShellView))
410 pShellView = IShellView_Constructor ((IShellFolder *) iface);
411 if (pShellView)
413 hr = IShellView_QueryInterface (pShellView, riid, ppvOut);
414 IShellView_Release (pShellView);
417 TRACE ("-- (%p)->(interface=%p)\n", This, ppvOut);
418 return hr;
421 /**************************************************************************
422 * ISF_Desktop_fnGetAttributesOf
424 static HRESULT WINAPI ISF_Desktop_fnGetAttributesOf (IShellFolder2 * iface,
425 UINT cidl, LPCITEMIDLIST * apidl, DWORD * rgfInOut)
427 IGenericSFImpl *This = (IGenericSFImpl *)iface;
428 HRESULT hr = S_OK;
429 static const DWORD dwDesktopAttributes =
430 SFGAO_STORAGE | SFGAO_HASPROPSHEET | SFGAO_STORAGEANCESTOR |
431 SFGAO_FILESYSANCESTOR | SFGAO_FOLDER | SFGAO_FILESYSTEM | SFGAO_HASSUBFOLDER;
432 static const DWORD dwMyComputerAttributes =
433 SFGAO_CANRENAME | SFGAO_CANDELETE | SFGAO_HASPROPSHEET |
434 SFGAO_DROPTARGET | SFGAO_FILESYSANCESTOR | SFGAO_FOLDER | SFGAO_HASSUBFOLDER;
436 TRACE ("(%p)->(cidl=%d apidl=%p mask=%p (0x%08x))\n",
437 This, cidl, apidl, rgfInOut, rgfInOut ? *rgfInOut : 0);
439 if (!rgfInOut)
440 return E_INVALIDARG;
441 if (cidl && !apidl)
442 return E_INVALIDARG;
444 if (*rgfInOut == 0)
445 *rgfInOut = ~0;
447 if(cidl == 0) {
448 *rgfInOut &= dwDesktopAttributes;
449 } else {
450 while (cidl > 0 && *apidl) {
451 pdump (*apidl);
452 if (_ILIsDesktop(*apidl)) {
453 *rgfInOut &= dwDesktopAttributes;
454 } else if (_ILIsMyComputer(*apidl)) {
455 *rgfInOut &= dwMyComputerAttributes;
456 } else {
457 SHELL32_GetItemAttributes (_IShellFolder_ (This), *apidl, rgfInOut);
459 apidl++;
460 cidl--;
463 /* make sure SFGAO_VALIDATE is cleared, some apps depend on that */
464 *rgfInOut &= ~SFGAO_VALIDATE;
466 TRACE ("-- result=0x%08x\n", *rgfInOut);
468 return hr;
471 /**************************************************************************
472 * ISF_Desktop_fnGetUIObjectOf
474 * PARAMETERS
475 * HWND hwndOwner, //[in ] Parent window for any output
476 * UINT cidl, //[in ] array size
477 * LPCITEMIDLIST* apidl, //[in ] simple pidl array
478 * REFIID riid, //[in ] Requested Interface
479 * UINT* prgfInOut, //[ ] reserved
480 * LPVOID* ppvObject) //[out] Resulting Interface
483 static HRESULT WINAPI ISF_Desktop_fnGetUIObjectOf (IShellFolder2 * iface,
484 HWND hwndOwner, UINT cidl, LPCITEMIDLIST * apidl,
485 REFIID riid, UINT * prgfInOut, LPVOID * ppvOut)
487 IGenericSFImpl *This = (IGenericSFImpl *)iface;
489 LPITEMIDLIST pidl;
490 IUnknown *pObj = NULL;
491 HRESULT hr = E_INVALIDARG;
493 TRACE ("(%p)->(%p,%u,apidl=%p,%s,%p,%p)\n",
494 This, hwndOwner, cidl, apidl, shdebugstr_guid (riid), prgfInOut, ppvOut);
496 if (!ppvOut)
497 return hr;
499 *ppvOut = NULL;
501 if (IsEqualIID (riid, &IID_IContextMenu))
503 if (cidl > 0)
504 pObj = (LPUNKNOWN) ISvItemCm_Constructor( (IShellFolder *) iface, This->pidlRoot, apidl, cidl);
505 else
506 pObj = (LPUNKNOWN) ISvBgCm_Constructor( (IShellFolder *) iface, TRUE);
507 hr = S_OK;
509 else if (IsEqualIID (riid, &IID_IDataObject) && (cidl >= 1))
511 pObj = (LPUNKNOWN) IDataObject_Constructor( hwndOwner,
512 This->pidlRoot, apidl, cidl);
513 hr = S_OK;
515 else if (IsEqualIID (riid, &IID_IExtractIconA) && (cidl == 1))
517 pidl = ILCombine (This->pidlRoot, apidl[0]);
518 pObj = (LPUNKNOWN) IExtractIconA_Constructor (pidl);
519 SHFree (pidl);
520 hr = S_OK;
522 else if (IsEqualIID (riid, &IID_IExtractIconW) && (cidl == 1))
524 pidl = ILCombine (This->pidlRoot, apidl[0]);
525 pObj = (LPUNKNOWN) IExtractIconW_Constructor (pidl);
526 SHFree (pidl);
527 hr = S_OK;
529 else if (IsEqualIID (riid, &IID_IDropTarget) && (cidl >= 1))
531 hr = IShellFolder_QueryInterface (iface,
532 &IID_IDropTarget, (LPVOID *) & pObj);
534 else if ((IsEqualIID(riid,&IID_IShellLinkW) ||
535 IsEqualIID(riid,&IID_IShellLinkA)) && (cidl == 1))
537 pidl = ILCombine (This->pidlRoot, apidl[0]);
538 hr = IShellLink_ConstructFromFile(NULL, riid, pidl, (LPVOID*)&pObj);
539 SHFree (pidl);
541 else
542 hr = E_NOINTERFACE;
544 if (SUCCEEDED(hr) && !pObj)
545 hr = E_OUTOFMEMORY;
547 *ppvOut = pObj;
548 TRACE ("(%p)->hr=0x%08x\n", This, hr);
549 return hr;
552 /**************************************************************************
553 * ISF_Desktop_fnGetDisplayNameOf
555 * NOTES
556 * special case: pidl = null gives desktop-name back
558 static HRESULT WINAPI ISF_Desktop_fnGetDisplayNameOf (IShellFolder2 * iface,
559 LPCITEMIDLIST pidl, DWORD dwFlags, LPSTRRET strRet)
561 IGenericSFImpl *This = (IGenericSFImpl *)iface;
562 HRESULT hr = S_OK;
563 LPWSTR pszPath;
565 TRACE ("(%p)->(pidl=%p,0x%08x,%p)\n", This, pidl, dwFlags, strRet);
566 pdump (pidl);
568 if (!strRet)
569 return E_INVALIDARG;
571 pszPath = CoTaskMemAlloc((MAX_PATH +1) * sizeof(WCHAR));
572 if (!pszPath)
573 return E_OUTOFMEMORY;
575 if (_ILIsDesktop (pidl))
577 if ((GET_SHGDN_RELATION (dwFlags) == SHGDN_NORMAL) &&
578 (GET_SHGDN_FOR (dwFlags) & SHGDN_FORPARSING))
579 strcpyW(pszPath, This->sPathTarget);
580 else
581 HCR_GetClassNameW(&CLSID_ShellDesktop, pszPath, MAX_PATH);
583 else if (_ILIsPidlSimple (pidl))
585 GUID const *clsid;
587 if ((clsid = _ILGetGUIDPointer (pidl)))
589 if (GET_SHGDN_FOR (dwFlags) & SHGDN_FORPARSING)
591 int bWantsForParsing;
594 * We can only get a filesystem path from a shellfolder if the
595 * value WantsFORPARSING in CLSID\\{...}\\shellfolder exists.
597 * Exception: The MyComputer folder doesn't have this key,
598 * but any other filesystem backed folder it needs it.
600 if (IsEqualIID (clsid, &CLSID_MyComputer))
602 bWantsForParsing = TRUE;
604 else
606 /* get the "WantsFORPARSING" flag from the registry */
607 static const WCHAR clsidW[] =
608 { 'C','L','S','I','D','\\',0 };
609 static const WCHAR shellfolderW[] =
610 { '\\','s','h','e','l','l','f','o','l','d','e','r',0 };
611 static const WCHAR wantsForParsingW[] =
612 { 'W','a','n','t','s','F','o','r','P','a','r','s','i','n',
613 'g',0 };
614 WCHAR szRegPath[100];
615 LONG r;
617 lstrcpyW (szRegPath, clsidW);
618 SHELL32_GUIDToStringW (clsid, &szRegPath[6]);
619 lstrcatW (szRegPath, shellfolderW);
620 r = SHGetValueW(HKEY_CLASSES_ROOT, szRegPath,
621 wantsForParsingW, NULL, NULL, NULL);
622 if (r == ERROR_SUCCESS)
623 bWantsForParsing = TRUE;
624 else
625 bWantsForParsing = FALSE;
628 if ((GET_SHGDN_RELATION (dwFlags) == SHGDN_NORMAL) &&
629 bWantsForParsing)
632 * we need the filesystem path to the destination folder.
633 * Only the folder itself can know it
635 hr = SHELL32_GetDisplayNameOfChild (iface, pidl, dwFlags,
636 pszPath,
637 MAX_PATH);
639 else
641 /* parsing name like ::{...} */
642 pszPath[0] = ':';
643 pszPath[1] = ':';
644 SHELL32_GUIDToStringW (clsid, &pszPath[2]);
647 else
649 /* user friendly name */
650 HCR_GetClassNameW (clsid, pszPath, MAX_PATH);
653 else
655 int cLen = 0;
657 /* file system folder or file rooted at the desktop */
658 if ((GET_SHGDN_FOR(dwFlags) == SHGDN_FORPARSING) &&
659 (GET_SHGDN_RELATION(dwFlags) != SHGDN_INFOLDER))
661 lstrcpynW(pszPath, This->sPathTarget, MAX_PATH - 1);
662 PathAddBackslashW(pszPath);
663 cLen = lstrlenW(pszPath);
666 _ILSimpleGetTextW(pidl, pszPath + cLen, MAX_PATH - cLen);
668 if (!_ILIsFolder(pidl))
669 SHELL_FS_ProcessDisplayFilename(pszPath, dwFlags);
672 else
674 /* a complex pidl, let the subfolder do the work */
675 hr = SHELL32_GetDisplayNameOfChild (iface, pidl, dwFlags,
676 pszPath, MAX_PATH);
679 if (SUCCEEDED(hr))
681 /* Win9x always returns ANSI strings, NT always returns Unicode strings */
682 if (GetVersion() & 0x80000000)
684 strRet->uType = STRRET_CSTR;
685 if (!WideCharToMultiByte(CP_ACP, 0, pszPath, -1, strRet->u.cStr, MAX_PATH,
686 NULL, NULL))
687 strRet->u.cStr[0] = '\0';
688 CoTaskMemFree(pszPath);
690 else
692 strRet->uType = STRRET_WSTR;
693 strRet->u.pOleStr = pszPath;
696 else
697 CoTaskMemFree(pszPath);
699 TRACE ("-- (%p)->(%s,0x%08x)\n", This,
700 strRet->uType == STRRET_CSTR ? strRet->u.cStr :
701 debugstr_w(strRet->u.pOleStr), hr);
702 return hr;
705 /**************************************************************************
706 * ISF_Desktop_fnSetNameOf
707 * Changes the name of a file object or subfolder, possibly changing its item
708 * identifier in the process.
710 * PARAMETERS
711 * HWND hwndOwner, //[in ] Owner window for output
712 * LPCITEMIDLIST pidl, //[in ] simple pidl of item to change
713 * LPCOLESTR lpszName, //[in ] the items new display name
714 * DWORD dwFlags, //[in ] SHGNO formatting flags
715 * LPITEMIDLIST* ppidlOut) //[out] simple pidl returned
717 static HRESULT WINAPI ISF_Desktop_fnSetNameOf (IShellFolder2 * iface,
718 HWND hwndOwner, LPCITEMIDLIST pidl, /* simple pidl */
719 LPCOLESTR lpName, DWORD dwFlags, LPITEMIDLIST * pPidlOut)
721 IGenericSFImpl *This = (IGenericSFImpl *)iface;
723 FIXME ("(%p)->(%p,pidl=%p,%s,%u,%p)\n", This, hwndOwner, pidl,
724 debugstr_w (lpName), dwFlags, pPidlOut);
726 return E_FAIL;
729 static HRESULT WINAPI ISF_Desktop_fnGetDefaultSearchGUID(IShellFolder2 *iface,
730 GUID * pguid)
732 IGenericSFImpl *This = (IGenericSFImpl *)iface;
734 FIXME ("(%p)\n", This);
735 return E_NOTIMPL;
738 static HRESULT WINAPI ISF_Desktop_fnEnumSearches (IShellFolder2 *iface,
739 IEnumExtraSearch ** ppenum)
741 IGenericSFImpl *This = (IGenericSFImpl *)iface;
742 FIXME ("(%p)\n", This);
743 return E_NOTIMPL;
746 static HRESULT WINAPI ISF_Desktop_fnGetDefaultColumn (IShellFolder2 * iface,
747 DWORD dwRes, ULONG * pSort, ULONG * pDisplay)
749 IGenericSFImpl *This = (IGenericSFImpl *)iface;
751 TRACE ("(%p)\n", This);
753 if (pSort)
754 *pSort = 0;
755 if (pDisplay)
756 *pDisplay = 0;
758 return S_OK;
760 static HRESULT WINAPI ISF_Desktop_fnGetDefaultColumnState (
761 IShellFolder2 * iface, UINT iColumn, DWORD * pcsFlags)
763 IGenericSFImpl *This = (IGenericSFImpl *)iface;
765 TRACE ("(%p)\n", This);
767 if (!pcsFlags || iColumn >= DESKTOPSHELLVIEWCOLUMNS)
768 return E_INVALIDARG;
770 *pcsFlags = DesktopSFHeader[iColumn].pcsFlags;
772 return S_OK;
775 static HRESULT WINAPI ISF_Desktop_fnGetDetailsEx (IShellFolder2 * iface,
776 LPCITEMIDLIST pidl, const SHCOLUMNID * pscid, VARIANT * pv)
778 IGenericSFImpl *This = (IGenericSFImpl *)iface;
779 FIXME ("(%p)\n", This);
781 return E_NOTIMPL;
784 static HRESULT WINAPI ISF_Desktop_fnGetDetailsOf (IShellFolder2 * iface,
785 LPCITEMIDLIST pidl, UINT iColumn, SHELLDETAILS * psd)
787 IGenericSFImpl *This = (IGenericSFImpl *)iface;
789 HRESULT hr = S_OK;
791 TRACE ("(%p)->(%p %i %p)\n", This, pidl, iColumn, psd);
793 if (!psd || iColumn >= DESKTOPSHELLVIEWCOLUMNS)
794 return E_INVALIDARG;
796 if (!pidl)
798 psd->fmt = DesktopSFHeader[iColumn].fmt;
799 psd->cxChar = DesktopSFHeader[iColumn].cxChar;
800 psd->str.uType = STRRET_CSTR;
801 LoadStringA (shell32_hInstance, DesktopSFHeader[iColumn].colnameid,
802 psd->str.u.cStr, MAX_PATH);
803 return S_OK;
806 /* the data from the pidl */
807 psd->str.uType = STRRET_CSTR;
808 switch (iColumn)
810 case 0: /* name */
811 hr = IShellFolder_GetDisplayNameOf(iface, pidl,
812 SHGDN_NORMAL | SHGDN_INFOLDER, &psd->str);
813 break;
814 case 1: /* size */
815 _ILGetFileSize (pidl, psd->str.u.cStr, MAX_PATH);
816 break;
817 case 2: /* type */
818 _ILGetFileType (pidl, psd->str.u.cStr, MAX_PATH);
819 break;
820 case 3: /* date */
821 _ILGetFileDate (pidl, psd->str.u.cStr, MAX_PATH);
822 break;
823 case 4: /* attributes */
824 _ILGetFileAttributes (pidl, psd->str.u.cStr, MAX_PATH);
825 break;
828 return hr;
831 static HRESULT WINAPI ISF_Desktop_fnMapColumnToSCID (
832 IShellFolder2 * iface, UINT column, SHCOLUMNID * pscid)
834 IGenericSFImpl *This = (IGenericSFImpl *)iface;
835 FIXME ("(%p)\n", This);
836 return E_NOTIMPL;
839 static const IShellFolder2Vtbl vt_MCFldr_ShellFolder2 =
841 ISF_Desktop_fnQueryInterface,
842 ISF_Desktop_fnAddRef,
843 ISF_Desktop_fnRelease,
844 ISF_Desktop_fnParseDisplayName,
845 ISF_Desktop_fnEnumObjects,
846 ISF_Desktop_fnBindToObject,
847 ISF_Desktop_fnBindToStorage,
848 ISF_Desktop_fnCompareIDs,
849 ISF_Desktop_fnCreateViewObject,
850 ISF_Desktop_fnGetAttributesOf,
851 ISF_Desktop_fnGetUIObjectOf,
852 ISF_Desktop_fnGetDisplayNameOf,
853 ISF_Desktop_fnSetNameOf,
854 /* ShellFolder2 */
855 ISF_Desktop_fnGetDefaultSearchGUID,
856 ISF_Desktop_fnEnumSearches,
857 ISF_Desktop_fnGetDefaultColumn,
858 ISF_Desktop_fnGetDefaultColumnState,
859 ISF_Desktop_fnGetDetailsEx,
860 ISF_Desktop_fnGetDetailsOf,
861 ISF_Desktop_fnMapColumnToSCID
864 /**************************************************************************
865 * ISF_Desktop_Constructor
867 HRESULT WINAPI ISF_Desktop_Constructor (
868 IUnknown * pUnkOuter, REFIID riid, LPVOID * ppv)
870 static IGenericSFImpl *cached_sf;
871 WCHAR szMyPath[MAX_PATH];
873 TRACE ("unkOut=%p %s\n", pUnkOuter, shdebugstr_guid (riid));
875 if (!ppv)
876 return E_POINTER;
877 if (pUnkOuter)
878 return CLASS_E_NOAGGREGATION;
880 if (!cached_sf)
882 IGenericSFImpl *sf;
884 if (!SHGetSpecialFolderPathW( 0, szMyPath, CSIDL_DESKTOPDIRECTORY, TRUE ))
885 return E_UNEXPECTED;
887 sf = LocalAlloc( LMEM_ZEROINIT, sizeof (IGenericSFImpl) );
888 if (!sf)
889 return E_OUTOFMEMORY;
891 sf->ref = 1;
892 sf->lpVtbl = &vt_MCFldr_ShellFolder2;
893 sf->pidlRoot = _ILCreateDesktop(); /* my qualified pidl */
894 sf->sPathTarget = SHAlloc( (lstrlenW(szMyPath) + 1)*sizeof(WCHAR) );
895 lstrcpyW( sf->sPathTarget, szMyPath );
897 if (InterlockedCompareExchangePointer((void *)&cached_sf, sf, NULL) != NULL)
899 /* some other thread already been here */
900 SHFree( sf->pidlRoot );
901 SHFree( sf->sPathTarget );
902 LocalFree( sf );
906 return IUnknown_QueryInterface( _IUnknown_(cached_sf), riid, ppv );