dnsapi: Add a version resource.
[wine.git] / dlls / shell32 / shfldr_desktop.c
blobe744fd3e710ba4977b7c11f74b95142add74d013
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 const IPersistVtbl *lpVtblIPersist;
69 LONG ref;
71 /* both paths are parsible from the desktop */
72 LPWSTR sPathTarget; /* complete path to target used for enumeration and ChangeNotify */
73 LPITEMIDLIST pidlRoot; /* absolute pidl */
75 UINT cfShellIDList; /* clipboardformat for IDropTarget */
76 BOOL fAcceptFmt; /* flag for pending Drop */
77 } IGenericSFImpl;
79 #define _IUnknown_(This) (IShellFolder*)&(This->lpVtbl)
80 #define _IShellFolder_(This) (IShellFolder*)&(This->lpVtbl)
82 static inline IGenericSFImpl *impl_from_IPersist( IPersist *iface )
84 return (IGenericSFImpl *)((char*)iface - FIELD_OFFSET(IGenericSFImpl, lpVtblIPersist));
87 static const shvheader DesktopSFHeader[] = {
88 {IDS_SHV_COLUMN1, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 15},
89 {IDS_SHV_COLUMN2, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
90 {IDS_SHV_COLUMN3, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
91 {IDS_SHV_COLUMN4, SHCOLSTATE_TYPE_DATE | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 12},
92 {IDS_SHV_COLUMN5, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 5}
95 #define DESKTOPSHELLVIEWCOLUMNS 5
97 /**************************************************************************
98 * ISF_Desktop_fnQueryInterface
100 * NOTES supports not IPersistFolder
102 static HRESULT WINAPI ISF_Desktop_fnQueryInterface(
103 IShellFolder2 * iface, REFIID riid, LPVOID * ppvObj)
105 IGenericSFImpl *This = (IGenericSFImpl *)iface;
107 TRACE ("(%p)->(%s,%p)\n", This, shdebugstr_guid (riid), ppvObj);
109 *ppvObj = NULL;
111 if (IsEqualIID (riid, &IID_IUnknown) ||
112 IsEqualIID (riid, &IID_IShellFolder) ||
113 IsEqualIID (riid, &IID_IShellFolder2))
115 *ppvObj = This;
117 else if (IsEqualIID (riid, &IID_IPersist))
119 *ppvObj = &This->lpVtblIPersist;
122 if (*ppvObj)
124 IUnknown_AddRef ((IUnknown *) (*ppvObj));
125 TRACE ("-- Interface: (%p)->(%p)\n", ppvObj, *ppvObj);
126 return S_OK;
128 TRACE ("-- Interface: E_NOINTERFACE\n");
129 return E_NOINTERFACE;
132 static ULONG WINAPI ISF_Desktop_fnAddRef (IShellFolder2 * iface)
134 return 2; /* non-heap based object */
137 static ULONG WINAPI ISF_Desktop_fnRelease (IShellFolder2 * iface)
139 return 1; /* non-heap based object */
142 /**************************************************************************
143 * ISF_Desktop_fnParseDisplayName
145 * NOTES
146 * "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}" and "" binds
147 * to MyComputer
149 static HRESULT WINAPI ISF_Desktop_fnParseDisplayName (IShellFolder2 * iface,
150 HWND hwndOwner, LPBC pbc, LPOLESTR lpszDisplayName,
151 DWORD * pchEaten, LPITEMIDLIST * ppidl, DWORD * pdwAttributes)
153 IGenericSFImpl *This = (IGenericSFImpl *)iface;
154 WCHAR szElement[MAX_PATH];
155 LPCWSTR szNext = NULL;
156 LPITEMIDLIST pidlTemp = NULL;
157 HRESULT hr = S_OK;
158 CLSID clsid;
160 TRACE ("(%p)->(HWND=%p,%p,%p=%s,%p,pidl=%p,%p)\n",
161 This, hwndOwner, pbc, lpszDisplayName, debugstr_w(lpszDisplayName),
162 pchEaten, ppidl, pdwAttributes);
164 if (!ppidl) return E_INVALIDARG;
165 *ppidl = 0;
167 if (!lpszDisplayName) return E_INVALIDARG;
169 if (pchEaten)
170 *pchEaten = 0; /* strange but like the original */
172 if (lpszDisplayName[0] == ':' && lpszDisplayName[1] == ':')
174 szNext = GetNextElementW (lpszDisplayName, szElement, MAX_PATH);
175 TRACE ("-- element: %s\n", debugstr_w (szElement));
176 SHCLSIDFromStringW (szElement + 2, &clsid);
177 pidlTemp = _ILCreateGuid (PT_GUID, &clsid);
179 else if (PathGetDriveNumberW (lpszDisplayName) >= 0)
181 /* it's a filesystem path with a drive. Let MyComputer/UnixDosFolder parse it */
182 if (UNIXFS_is_rooted_at_desktop())
183 pidlTemp = _ILCreateGuid(PT_GUID, &CLSID_UnixDosFolder);
184 else
185 pidlTemp = _ILCreateMyComputer ();
186 szNext = lpszDisplayName;
188 else if (PathIsUNCW(lpszDisplayName))
190 pidlTemp = _ILCreateNetwork();
191 szNext = lpszDisplayName;
193 else if( (pidlTemp = SHELL32_CreatePidlFromBindCtx(pbc, lpszDisplayName)) )
195 *ppidl = pidlTemp;
196 return S_OK;
198 else if (strchrW(lpszDisplayName,':'))
200 PARSEDURLW urldata;
202 urldata.cbSize = sizeof(urldata);
203 ParseURLW(lpszDisplayName,&urldata);
205 if (urldata.nScheme == URL_SCHEME_SHELL) /* handle shell: urls */
207 TRACE ("-- shell url: %s\n", debugstr_w(urldata.pszSuffix));
208 SHCLSIDFromStringW (urldata.pszSuffix+2, &clsid);
209 pidlTemp = _ILCreateGuid (PT_GUID, &clsid);
211 else
212 return IEParseDisplayNameWithBCW(CP_ACP,lpszDisplayName,pbc,ppidl);
214 else
216 /* it's a filesystem path on the desktop. Let a FSFolder parse it */
218 if (*lpszDisplayName)
220 WCHAR szPath[MAX_PATH];
221 LPWSTR pathPtr;
223 /* build a complete path to create a simple pidl */
224 lstrcpynW(szPath, This->sPathTarget, MAX_PATH);
225 pathPtr = PathAddBackslashW(szPath);
226 if (pathPtr)
228 lstrcpynW(pathPtr, lpszDisplayName, MAX_PATH - (pathPtr - szPath));
229 hr = _ILCreateFromPathW(szPath, &pidlTemp);
231 else
233 /* should never reach here, but for completeness */
234 hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
237 else
238 pidlTemp = _ILCreateMyComputer();
240 szNext = NULL;
243 if (SUCCEEDED(hr) && pidlTemp)
245 if (szNext && *szNext)
247 hr = SHELL32_ParseNextElement(iface, hwndOwner, pbc,
248 &pidlTemp, (LPOLESTR) szNext, pchEaten, pdwAttributes);
250 else
252 if (pdwAttributes && *pdwAttributes)
253 hr = SHELL32_GetItemAttributes(_IShellFolder_ (This),
254 pidlTemp, pdwAttributes);
258 *ppidl = pidlTemp;
260 TRACE ("(%p)->(-- ret=0x%08x)\n", This, hr);
262 return hr;
265 /**************************************************************************
266 * CreateDesktopEnumList()
268 static const WCHAR Desktop_NameSpaceW[] = { 'S','O','F','T','W','A','R','E',
269 '\\','M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
270 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\','E','x','p','l',
271 'o','r','e','r','\\','D','e','s','k','t','o','p','\\','N','a','m','e','s','p',
272 'a','c','e','\0' };
274 static BOOL CreateDesktopEnumList(IEnumIDList *list, DWORD dwFlags)
276 BOOL ret = TRUE;
277 WCHAR szPath[MAX_PATH];
279 TRACE("(%p)->(flags=0x%08x)\n", list, dwFlags);
281 /* enumerate the root folders */
282 if (dwFlags & SHCONTF_FOLDERS)
284 HKEY hkey;
285 UINT i;
287 /* create the pidl for This item */
288 ret = AddToEnumList(list, _ILCreateMyComputer());
290 for (i=0; i<2; i++) {
291 if (ret && !RegOpenKeyExW(i == 0 ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER,
292 Desktop_NameSpaceW, 0, KEY_READ, &hkey))
294 WCHAR iid[50];
295 int i=0;
297 while (ret)
299 DWORD size;
300 LONG r;
302 size = sizeof (iid) / sizeof (iid[0]);
303 r = RegEnumKeyExW(hkey, i, iid, &size, 0, NULL, NULL, NULL);
304 if (ERROR_SUCCESS == r)
306 ret = AddToEnumList(list, _ILCreateGuidFromStrW(iid));
307 i++;
309 else if (ERROR_NO_MORE_ITEMS == r)
310 break;
311 else
312 ret = FALSE;
314 RegCloseKey(hkey);
319 /* enumerate the elements in %windir%\desktop */
320 SHGetSpecialFolderPathW(0, szPath, CSIDL_DESKTOPDIRECTORY, FALSE);
321 ret = ret && CreateFolderEnumList(list, szPath, dwFlags);
323 return ret;
326 /**************************************************************************
327 * ISF_Desktop_fnEnumObjects
329 static HRESULT WINAPI ISF_Desktop_fnEnumObjects (IShellFolder2 * iface,
330 HWND hwndOwner, DWORD dwFlags, LPENUMIDLIST * ppEnumIDList)
332 IGenericSFImpl *This = (IGenericSFImpl *)iface;
334 TRACE ("(%p)->(HWND=%p flags=0x%08x pplist=%p)\n",
335 This, hwndOwner, dwFlags, ppEnumIDList);
337 *ppEnumIDList = IEnumIDList_Constructor();
338 if (*ppEnumIDList)
339 CreateDesktopEnumList(*ppEnumIDList, dwFlags);
341 TRACE ("-- (%p)->(new ID List: %p)\n", This, *ppEnumIDList);
343 return *ppEnumIDList ? S_OK : E_OUTOFMEMORY;
346 /**************************************************************************
347 * ISF_Desktop_fnBindToObject
349 static HRESULT WINAPI ISF_Desktop_fnBindToObject (IShellFolder2 * iface,
350 LPCITEMIDLIST pidl, LPBC pbcReserved, REFIID riid, LPVOID * ppvOut)
352 IGenericSFImpl *This = (IGenericSFImpl *)iface;
354 TRACE ("(%p)->(pidl=%p,%p,%s,%p)\n",
355 This, pidl, pbcReserved, shdebugstr_guid (riid), ppvOut);
357 return SHELL32_BindToChild( This->pidlRoot, This->sPathTarget, pidl, riid, ppvOut );
360 /**************************************************************************
361 * ISF_Desktop_fnBindToStorage
363 static HRESULT WINAPI ISF_Desktop_fnBindToStorage (IShellFolder2 * iface,
364 LPCITEMIDLIST pidl, LPBC pbcReserved, REFIID riid, LPVOID * ppvOut)
366 IGenericSFImpl *This = (IGenericSFImpl *)iface;
368 FIXME ("(%p)->(pidl=%p,%p,%s,%p) stub\n",
369 This, pidl, pbcReserved, shdebugstr_guid (riid), ppvOut);
371 *ppvOut = NULL;
372 return E_NOTIMPL;
375 /**************************************************************************
376 * ISF_Desktop_fnCompareIDs
378 static HRESULT WINAPI ISF_Desktop_fnCompareIDs (IShellFolder2 * iface,
379 LPARAM lParam, LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
381 IGenericSFImpl *This = (IGenericSFImpl *)iface;
382 int nReturn;
384 TRACE ("(%p)->(0x%08lx,pidl1=%p,pidl2=%p)\n", This, lParam, pidl1, pidl2);
385 nReturn = SHELL32_CompareIDs (_IShellFolder_ (This), lParam, pidl1, pidl2);
386 TRACE ("-- %i\n", nReturn);
387 return nReturn;
390 /**************************************************************************
391 * ISF_Desktop_fnCreateViewObject
393 static HRESULT WINAPI ISF_Desktop_fnCreateViewObject (IShellFolder2 * iface,
394 HWND hwndOwner, REFIID riid, LPVOID * ppvOut)
396 IGenericSFImpl *This = (IGenericSFImpl *)iface;
397 LPSHELLVIEW pShellView;
398 HRESULT hr = E_INVALIDARG;
400 TRACE ("(%p)->(hwnd=%p,%s,%p)\n",
401 This, hwndOwner, shdebugstr_guid (riid), ppvOut);
403 if (!ppvOut)
404 return hr;
406 *ppvOut = NULL;
408 if (IsEqualIID (riid, &IID_IDropTarget))
410 WARN ("IDropTarget not implemented\n");
411 hr = E_NOTIMPL;
413 else if (IsEqualIID (riid, &IID_IContextMenu))
415 WARN ("IContextMenu not implemented\n");
416 hr = E_NOTIMPL;
418 else if (IsEqualIID (riid, &IID_IShellView))
420 pShellView = IShellView_Constructor ((IShellFolder *) iface);
421 if (pShellView)
423 hr = IShellView_QueryInterface (pShellView, riid, ppvOut);
424 IShellView_Release (pShellView);
427 TRACE ("-- (%p)->(interface=%p)\n", This, ppvOut);
428 return hr;
431 /**************************************************************************
432 * ISF_Desktop_fnGetAttributesOf
434 static HRESULT WINAPI ISF_Desktop_fnGetAttributesOf (IShellFolder2 * iface,
435 UINT cidl, LPCITEMIDLIST * apidl, DWORD * rgfInOut)
437 IGenericSFImpl *This = (IGenericSFImpl *)iface;
438 HRESULT hr = S_OK;
439 static const DWORD dwDesktopAttributes =
440 SFGAO_STORAGE | SFGAO_HASPROPSHEET | SFGAO_STORAGEANCESTOR |
441 SFGAO_FILESYSANCESTOR | SFGAO_FOLDER | SFGAO_FILESYSTEM | SFGAO_HASSUBFOLDER;
442 static const DWORD dwMyComputerAttributes =
443 SFGAO_CANRENAME | SFGAO_CANDELETE | SFGAO_HASPROPSHEET |
444 SFGAO_DROPTARGET | SFGAO_FILESYSANCESTOR | SFGAO_FOLDER | SFGAO_HASSUBFOLDER;
446 TRACE ("(%p)->(cidl=%d apidl=%p mask=%p (0x%08x))\n",
447 This, cidl, apidl, rgfInOut, rgfInOut ? *rgfInOut : 0);
449 if (!rgfInOut)
450 return E_INVALIDARG;
451 if (cidl && !apidl)
452 return E_INVALIDARG;
454 if (*rgfInOut == 0)
455 *rgfInOut = ~0;
457 if(cidl == 0) {
458 *rgfInOut &= dwDesktopAttributes;
459 } else {
460 while (cidl > 0 && *apidl) {
461 pdump (*apidl);
462 if (_ILIsDesktop(*apidl)) {
463 *rgfInOut &= dwDesktopAttributes;
464 } else if (_ILIsMyComputer(*apidl)) {
465 *rgfInOut &= dwMyComputerAttributes;
466 } else {
467 SHELL32_GetItemAttributes (_IShellFolder_ (This), *apidl, rgfInOut);
469 apidl++;
470 cidl--;
473 /* make sure SFGAO_VALIDATE is cleared, some apps depend on that */
474 *rgfInOut &= ~SFGAO_VALIDATE;
476 TRACE ("-- result=0x%08x\n", *rgfInOut);
478 return hr;
481 /**************************************************************************
482 * ISF_Desktop_fnGetUIObjectOf
484 * PARAMETERS
485 * HWND hwndOwner, //[in ] Parent window for any output
486 * UINT cidl, //[in ] array size
487 * LPCITEMIDLIST* apidl, //[in ] simple pidl array
488 * REFIID riid, //[in ] Requested Interface
489 * UINT* prgfInOut, //[ ] reserved
490 * LPVOID* ppvObject) //[out] Resulting Interface
493 static HRESULT WINAPI ISF_Desktop_fnGetUIObjectOf (IShellFolder2 * iface,
494 HWND hwndOwner, UINT cidl, LPCITEMIDLIST * apidl,
495 REFIID riid, UINT * prgfInOut, LPVOID * ppvOut)
497 IGenericSFImpl *This = (IGenericSFImpl *)iface;
499 LPITEMIDLIST pidl;
500 IUnknown *pObj = NULL;
501 HRESULT hr = E_INVALIDARG;
503 TRACE ("(%p)->(%p,%u,apidl=%p,%s,%p,%p)\n",
504 This, hwndOwner, cidl, apidl, shdebugstr_guid (riid), prgfInOut, ppvOut);
506 if (!ppvOut)
507 return hr;
509 *ppvOut = NULL;
511 if (IsEqualIID (riid, &IID_IContextMenu))
513 if (cidl > 0)
514 pObj = (LPUNKNOWN) ISvItemCm_Constructor( (IShellFolder *) iface, This->pidlRoot, apidl, cidl);
515 else
516 pObj = (LPUNKNOWN) ISvBgCm_Constructor( (IShellFolder *) iface, TRUE);
517 hr = S_OK;
519 else if (IsEqualIID (riid, &IID_IDataObject) && (cidl >= 1))
521 pObj = (LPUNKNOWN) IDataObject_Constructor( hwndOwner,
522 This->pidlRoot, apidl, cidl);
523 hr = S_OK;
525 else if (IsEqualIID (riid, &IID_IExtractIconA) && (cidl == 1))
527 pidl = ILCombine (This->pidlRoot, apidl[0]);
528 pObj = (LPUNKNOWN) IExtractIconA_Constructor (pidl);
529 SHFree (pidl);
530 hr = S_OK;
532 else if (IsEqualIID (riid, &IID_IExtractIconW) && (cidl == 1))
534 pidl = ILCombine (This->pidlRoot, apidl[0]);
535 pObj = (LPUNKNOWN) IExtractIconW_Constructor (pidl);
536 SHFree (pidl);
537 hr = S_OK;
539 else if (IsEqualIID (riid, &IID_IDropTarget) && (cidl >= 1))
541 hr = IShellFolder_QueryInterface (iface,
542 &IID_IDropTarget, (LPVOID *) & pObj);
544 else if ((IsEqualIID(riid,&IID_IShellLinkW) ||
545 IsEqualIID(riid,&IID_IShellLinkA)) && (cidl == 1))
547 pidl = ILCombine (This->pidlRoot, apidl[0]);
548 hr = IShellLink_ConstructFromFile(NULL, riid, pidl, (LPVOID*)&pObj);
549 SHFree (pidl);
551 else
552 hr = E_NOINTERFACE;
554 if (SUCCEEDED(hr) && !pObj)
555 hr = E_OUTOFMEMORY;
557 *ppvOut = pObj;
558 TRACE ("(%p)->hr=0x%08x\n", This, hr);
559 return hr;
562 /**************************************************************************
563 * ISF_Desktop_fnGetDisplayNameOf
565 * NOTES
566 * special case: pidl = null gives desktop-name back
568 static HRESULT WINAPI ISF_Desktop_fnGetDisplayNameOf (IShellFolder2 * iface,
569 LPCITEMIDLIST pidl, DWORD dwFlags, LPSTRRET strRet)
571 IGenericSFImpl *This = (IGenericSFImpl *)iface;
572 HRESULT hr = S_OK;
573 LPWSTR pszPath;
575 TRACE ("(%p)->(pidl=%p,0x%08x,%p)\n", This, pidl, dwFlags, strRet);
576 pdump (pidl);
578 if (!strRet)
579 return E_INVALIDARG;
581 pszPath = CoTaskMemAlloc((MAX_PATH +1) * sizeof(WCHAR));
582 if (!pszPath)
583 return E_OUTOFMEMORY;
585 if (_ILIsDesktop (pidl))
587 if ((GET_SHGDN_RELATION (dwFlags) == SHGDN_NORMAL) &&
588 (GET_SHGDN_FOR (dwFlags) & SHGDN_FORPARSING))
589 strcpyW(pszPath, This->sPathTarget);
590 else
591 HCR_GetClassNameW(&CLSID_ShellDesktop, pszPath, MAX_PATH);
593 else if (_ILIsPidlSimple (pidl))
595 GUID const *clsid;
597 if ((clsid = _ILGetGUIDPointer (pidl)))
599 if (GET_SHGDN_FOR (dwFlags) & SHGDN_FORPARSING)
601 int bWantsForParsing;
604 * We can only get a filesystem path from a shellfolder if the
605 * value WantsFORPARSING in CLSID\\{...}\\shellfolder exists.
607 * Exception: The MyComputer folder doesn't have this key,
608 * but any other filesystem backed folder it needs it.
610 if (IsEqualIID (clsid, &CLSID_MyComputer))
612 bWantsForParsing = TRUE;
614 else
616 /* get the "WantsFORPARSING" flag from the registry */
617 static const WCHAR clsidW[] =
618 { 'C','L','S','I','D','\\',0 };
619 static const WCHAR shellfolderW[] =
620 { '\\','s','h','e','l','l','f','o','l','d','e','r',0 };
621 static const WCHAR wantsForParsingW[] =
622 { 'W','a','n','t','s','F','o','r','P','a','r','s','i','n',
623 'g',0 };
624 WCHAR szRegPath[100];
625 LONG r;
627 lstrcpyW (szRegPath, clsidW);
628 SHELL32_GUIDToStringW (clsid, &szRegPath[6]);
629 lstrcatW (szRegPath, shellfolderW);
630 r = SHGetValueW(HKEY_CLASSES_ROOT, szRegPath,
631 wantsForParsingW, NULL, NULL, NULL);
632 if (r == ERROR_SUCCESS)
633 bWantsForParsing = TRUE;
634 else
635 bWantsForParsing = FALSE;
638 if ((GET_SHGDN_RELATION (dwFlags) == SHGDN_NORMAL) &&
639 bWantsForParsing)
642 * we need the filesystem path to the destination folder.
643 * Only the folder itself can know it
645 hr = SHELL32_GetDisplayNameOfChild (iface, pidl, dwFlags,
646 pszPath,
647 MAX_PATH);
649 else
651 /* parsing name like ::{...} */
652 pszPath[0] = ':';
653 pszPath[1] = ':';
654 SHELL32_GUIDToStringW (clsid, &pszPath[2]);
657 else
659 /* user friendly name */
660 HCR_GetClassNameW (clsid, pszPath, MAX_PATH);
663 else
665 int cLen = 0;
667 /* file system folder or file rooted at the desktop */
668 if ((GET_SHGDN_FOR(dwFlags) == SHGDN_FORPARSING) &&
669 (GET_SHGDN_RELATION(dwFlags) != SHGDN_INFOLDER))
671 lstrcpynW(pszPath, This->sPathTarget, MAX_PATH - 1);
672 PathAddBackslashW(pszPath);
673 cLen = lstrlenW(pszPath);
676 _ILSimpleGetTextW(pidl, pszPath + cLen, MAX_PATH - cLen);
678 if (!_ILIsFolder(pidl))
679 SHELL_FS_ProcessDisplayFilename(pszPath, dwFlags);
682 else
684 /* a complex pidl, let the subfolder do the work */
685 hr = SHELL32_GetDisplayNameOfChild (iface, pidl, dwFlags,
686 pszPath, MAX_PATH);
689 if (SUCCEEDED(hr))
691 /* Win9x always returns ANSI strings, NT always returns Unicode strings */
692 if (GetVersion() & 0x80000000)
694 strRet->uType = STRRET_CSTR;
695 if (!WideCharToMultiByte(CP_ACP, 0, pszPath, -1, strRet->u.cStr, MAX_PATH,
696 NULL, NULL))
697 strRet->u.cStr[0] = '\0';
698 CoTaskMemFree(pszPath);
700 else
702 strRet->uType = STRRET_WSTR;
703 strRet->u.pOleStr = pszPath;
706 else
707 CoTaskMemFree(pszPath);
709 TRACE ("-- (%p)->(%s,0x%08x)\n", This,
710 strRet->uType == STRRET_CSTR ? strRet->u.cStr :
711 debugstr_w(strRet->u.pOleStr), hr);
712 return hr;
715 /**************************************************************************
716 * ISF_Desktop_fnSetNameOf
717 * Changes the name of a file object or subfolder, possibly changing its item
718 * identifier in the process.
720 * PARAMETERS
721 * HWND hwndOwner, //[in ] Owner window for output
722 * LPCITEMIDLIST pidl, //[in ] simple pidl of item to change
723 * LPCOLESTR lpszName, //[in ] the items new display name
724 * DWORD dwFlags, //[in ] SHGNO formatting flags
725 * LPITEMIDLIST* ppidlOut) //[out] simple pidl returned
727 static HRESULT WINAPI ISF_Desktop_fnSetNameOf (IShellFolder2 * iface,
728 HWND hwndOwner, LPCITEMIDLIST pidl, /* simple pidl */
729 LPCOLESTR lpName, DWORD dwFlags, LPITEMIDLIST * pPidlOut)
731 IGenericSFImpl *This = (IGenericSFImpl *)iface;
733 FIXME ("(%p)->(%p,pidl=%p,%s,%u,%p)\n", This, hwndOwner, pidl,
734 debugstr_w (lpName), dwFlags, pPidlOut);
736 return E_FAIL;
739 static HRESULT WINAPI ISF_Desktop_fnGetDefaultSearchGUID(IShellFolder2 *iface,
740 GUID * pguid)
742 IGenericSFImpl *This = (IGenericSFImpl *)iface;
744 FIXME ("(%p)\n", This);
745 return E_NOTIMPL;
748 static HRESULT WINAPI ISF_Desktop_fnEnumSearches (IShellFolder2 *iface,
749 IEnumExtraSearch ** ppenum)
751 IGenericSFImpl *This = (IGenericSFImpl *)iface;
752 FIXME ("(%p)\n", This);
753 return E_NOTIMPL;
756 static HRESULT WINAPI ISF_Desktop_fnGetDefaultColumn (IShellFolder2 * iface,
757 DWORD dwRes, ULONG * pSort, ULONG * pDisplay)
759 IGenericSFImpl *This = (IGenericSFImpl *)iface;
761 TRACE ("(%p)\n", This);
763 if (pSort)
764 *pSort = 0;
765 if (pDisplay)
766 *pDisplay = 0;
768 return S_OK;
770 static HRESULT WINAPI ISF_Desktop_fnGetDefaultColumnState (
771 IShellFolder2 * iface, UINT iColumn, DWORD * pcsFlags)
773 IGenericSFImpl *This = (IGenericSFImpl *)iface;
775 TRACE ("(%p)\n", This);
777 if (!pcsFlags || iColumn >= DESKTOPSHELLVIEWCOLUMNS)
778 return E_INVALIDARG;
780 *pcsFlags = DesktopSFHeader[iColumn].pcsFlags;
782 return S_OK;
785 static HRESULT WINAPI ISF_Desktop_fnGetDetailsEx (IShellFolder2 * iface,
786 LPCITEMIDLIST pidl, const SHCOLUMNID * pscid, VARIANT * pv)
788 IGenericSFImpl *This = (IGenericSFImpl *)iface;
789 FIXME ("(%p)\n", This);
791 return E_NOTIMPL;
794 static HRESULT WINAPI ISF_Desktop_fnGetDetailsOf (IShellFolder2 * iface,
795 LPCITEMIDLIST pidl, UINT iColumn, SHELLDETAILS * psd)
797 IGenericSFImpl *This = (IGenericSFImpl *)iface;
799 HRESULT hr = S_OK;
801 TRACE ("(%p)->(%p %i %p)\n", This, pidl, iColumn, psd);
803 if (!psd || iColumn >= DESKTOPSHELLVIEWCOLUMNS)
804 return E_INVALIDARG;
806 if (!pidl)
808 psd->fmt = DesktopSFHeader[iColumn].fmt;
809 psd->cxChar = DesktopSFHeader[iColumn].cxChar;
810 psd->str.uType = STRRET_CSTR;
811 LoadStringA (shell32_hInstance, DesktopSFHeader[iColumn].colnameid,
812 psd->str.u.cStr, MAX_PATH);
813 return S_OK;
816 /* the data from the pidl */
817 psd->str.uType = STRRET_CSTR;
818 switch (iColumn)
820 case 0: /* name */
821 hr = IShellFolder_GetDisplayNameOf(iface, pidl,
822 SHGDN_NORMAL | SHGDN_INFOLDER, &psd->str);
823 break;
824 case 1: /* size */
825 _ILGetFileSize (pidl, psd->str.u.cStr, MAX_PATH);
826 break;
827 case 2: /* type */
828 _ILGetFileType (pidl, psd->str.u.cStr, MAX_PATH);
829 break;
830 case 3: /* date */
831 _ILGetFileDate (pidl, psd->str.u.cStr, MAX_PATH);
832 break;
833 case 4: /* attributes */
834 _ILGetFileAttributes (pidl, psd->str.u.cStr, MAX_PATH);
835 break;
838 return hr;
841 static HRESULT WINAPI ISF_Desktop_fnMapColumnToSCID (
842 IShellFolder2 * iface, UINT column, SHCOLUMNID * pscid)
844 IGenericSFImpl *This = (IGenericSFImpl *)iface;
845 FIXME ("(%p)\n", This);
846 return E_NOTIMPL;
849 static const IShellFolder2Vtbl vt_MCFldr_ShellFolder2 =
851 ISF_Desktop_fnQueryInterface,
852 ISF_Desktop_fnAddRef,
853 ISF_Desktop_fnRelease,
854 ISF_Desktop_fnParseDisplayName,
855 ISF_Desktop_fnEnumObjects,
856 ISF_Desktop_fnBindToObject,
857 ISF_Desktop_fnBindToStorage,
858 ISF_Desktop_fnCompareIDs,
859 ISF_Desktop_fnCreateViewObject,
860 ISF_Desktop_fnGetAttributesOf,
861 ISF_Desktop_fnGetUIObjectOf,
862 ISF_Desktop_fnGetDisplayNameOf,
863 ISF_Desktop_fnSetNameOf,
864 /* ShellFolder2 */
865 ISF_Desktop_fnGetDefaultSearchGUID,
866 ISF_Desktop_fnEnumSearches,
867 ISF_Desktop_fnGetDefaultColumn,
868 ISF_Desktop_fnGetDefaultColumnState,
869 ISF_Desktop_fnGetDetailsEx,
870 ISF_Desktop_fnGetDetailsOf,
871 ISF_Desktop_fnMapColumnToSCID
874 /**************************************************************************
875 * IPersist
877 static HRESULT WINAPI ISF_Desktop_IPersist_fnQueryInterface(
878 IPersist *iface, REFIID riid, LPVOID *ppvObj)
880 IGenericSFImpl *This = impl_from_IPersist( iface );
881 return IShellFolder2_QueryInterface((IShellFolder2*)This, riid, ppvObj);
884 static ULONG WINAPI ISF_Desktop_IPersist_fnAddRef(IPersist *iface)
886 IGenericSFImpl *This = impl_from_IPersist( iface );
887 return IShellFolder2_AddRef((IShellFolder2*)This);
890 static ULONG WINAPI ISF_Desktop_IPersist_fnRelease(IPersist *iface)
892 IGenericSFImpl *This = impl_from_IPersist( iface );
893 return IShellFolder2_Release((IShellFolder2*)This);
896 static HRESULT WINAPI ISF_Desktop_IPersist_fnGetClassID(IPersist *iface, CLSID *clsid)
898 *clsid = CLSID_ShellDesktop;
899 return S_OK;
902 static const IPersistVtbl vt_IPersist =
904 ISF_Desktop_IPersist_fnQueryInterface,
905 ISF_Desktop_IPersist_fnAddRef,
906 ISF_Desktop_IPersist_fnRelease,
907 ISF_Desktop_IPersist_fnGetClassID
910 /**************************************************************************
911 * ISF_Desktop_Constructor
913 HRESULT WINAPI ISF_Desktop_Constructor (
914 IUnknown * pUnkOuter, REFIID riid, LPVOID * ppv)
916 static IGenericSFImpl *cached_sf;
917 WCHAR szMyPath[MAX_PATH];
919 TRACE ("unkOut=%p %s\n", pUnkOuter, shdebugstr_guid (riid));
921 if (!ppv)
922 return E_POINTER;
923 if (pUnkOuter)
924 return CLASS_E_NOAGGREGATION;
926 if (!cached_sf)
928 IGenericSFImpl *sf;
930 if (!SHGetSpecialFolderPathW( 0, szMyPath, CSIDL_DESKTOPDIRECTORY, TRUE ))
931 return E_UNEXPECTED;
933 sf = LocalAlloc( LMEM_ZEROINIT, sizeof (IGenericSFImpl) );
934 if (!sf)
935 return E_OUTOFMEMORY;
937 sf->ref = 1;
938 sf->lpVtbl = &vt_MCFldr_ShellFolder2;
939 sf->lpVtblIPersist = &vt_IPersist;
940 sf->pidlRoot = _ILCreateDesktop(); /* my qualified pidl */
941 sf->sPathTarget = SHAlloc( (lstrlenW(szMyPath) + 1)*sizeof(WCHAR) );
942 lstrcpyW( sf->sPathTarget, szMyPath );
944 if (InterlockedCompareExchangePointer((void *)&cached_sf, sf, NULL) != NULL)
946 /* some other thread already been here */
947 SHFree( sf->pidlRoot );
948 SHFree( sf->sPathTarget );
949 LocalFree( sf );
953 return IUnknown_QueryInterface( _IUnknown_(cached_sf), riid, ppv );