xaudio2: Implement IXAudio2SourceVoice::Discontinuity.
[wine/multimedia.git] / dlls / shell32 / shfldr_desktop.c
blob40cd752eaf64cde4d682bcc7873a1b9dbb0af222
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
34 #include "winerror.h"
35 #include "windef.h"
36 #include "winbase.h"
37 #include "winreg.h"
38 #include "wingdi.h"
39 #include "winuser.h"
41 #include "ole2.h"
42 #include "shlguid.h"
44 #include "pidl.h"
45 #include "undocshell.h"
46 #include "shell32_main.h"
47 #include "shresdef.h"
48 #include "shlwapi.h"
49 #include "shellfolder.h"
50 #include "wine/debug.h"
51 #include "debughlp.h"
52 #include "shfldr.h"
54 WINE_DEFAULT_DEBUG_CHANNEL (shell);
56 /* Undocumented functions from shdocvw */
57 extern HRESULT WINAPI IEParseDisplayNameWithBCW(DWORD codepage, LPCWSTR lpszDisplayName, LPBC pbc, LPITEMIDLIST *ppidl);
59 /***********************************************************************
60 * Desktopfolder implementation
63 typedef struct {
64 IShellFolder2 IShellFolder2_iface;
65 IPersistFolder2 IPersistFolder2_iface;
66 LONG ref;
68 /* both paths are parsible from the desktop */
69 LPWSTR sPathTarget; /* complete path to target used for enumeration and ChangeNotify */
70 LPITEMIDLIST pidlRoot; /* absolute pidl */
72 UINT cfShellIDList; /* clipboardformat for IDropTarget */
73 BOOL fAcceptFmt; /* flag for pending Drop */
74 } IDesktopFolderImpl;
76 static IDesktopFolderImpl *cached_sf;
78 static inline IDesktopFolderImpl *impl_from_IShellFolder2(IShellFolder2 *iface)
80 return CONTAINING_RECORD(iface, IDesktopFolderImpl, IShellFolder2_iface);
83 static inline IDesktopFolderImpl *impl_from_IPersistFolder2( IPersistFolder2 *iface )
85 return CONTAINING_RECORD(iface, IDesktopFolderImpl, IPersistFolder2_iface);
88 static const shvheader desktop_header[] = {
89 {IDS_SHV_COLUMN1, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 15},
90 {IDS_SHV_COLUMN2, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
91 {IDS_SHV_COLUMN3, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
92 {IDS_SHV_COLUMN4, SHCOLSTATE_TYPE_DATE | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 12},
93 {IDS_SHV_COLUMN5, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 5}
96 #define DESKTOPSHELLVIEWCOLUMNS sizeof(desktop_header)/sizeof(shvheader)
98 /**************************************************************************
99 * ISF_Desktop_fnQueryInterface
102 static HRESULT WINAPI ISF_Desktop_fnQueryInterface(
103 IShellFolder2 * iface, REFIID riid, LPVOID * ppvObj)
105 IDesktopFolderImpl *This = impl_from_IShellFolder2(iface);
107 TRACE ("(%p)->(%s,%p)\n", This, shdebugstr_guid (riid), ppvObj);
109 if (!ppvObj) return E_POINTER;
111 *ppvObj = NULL;
113 if (IsEqualIID (riid, &IID_IUnknown) ||
114 IsEqualIID (riid, &IID_IShellFolder) ||
115 IsEqualIID (riid, &IID_IShellFolder2))
117 *ppvObj = &This->IShellFolder2_iface;
119 else if (IsEqualIID (riid, &IID_IPersist) ||
120 IsEqualIID (riid, &IID_IPersistFolder) ||
121 IsEqualIID (riid, &IID_IPersistFolder2))
123 *ppvObj = &This->IPersistFolder2_iface;
126 if (*ppvObj)
128 IUnknown_AddRef ((IUnknown *) (*ppvObj));
129 TRACE ("-- Interface: (%p)->(%p)\n", ppvObj, *ppvObj);
130 return S_OK;
132 TRACE ("-- Interface: E_NOINTERFACE\n");
133 return E_NOINTERFACE;
136 static ULONG WINAPI ISF_Desktop_fnAddRef (IShellFolder2 * iface)
138 return 2; /* non-heap based object */
141 static ULONG WINAPI ISF_Desktop_fnRelease (IShellFolder2 * iface)
143 return 1; /* non-heap based object */
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 IDesktopFolderImpl *This = impl_from_IShellFolder2(iface);
158 IShellFolder *shell_folder = (IShellFolder*)iface;
159 WCHAR szElement[MAX_PATH];
160 LPCWSTR szNext = NULL;
161 LPITEMIDLIST pidlTemp = NULL;
162 PARSEDURLW urldata;
163 HRESULT hr = S_OK;
164 CLSID clsid;
166 TRACE ("(%p)->(HWND=%p,%p,%p=%s,%p,pidl=%p,%p)\n",
167 This, hwndOwner, pbc, lpszDisplayName, debugstr_w(lpszDisplayName),
168 pchEaten, ppidl, pdwAttributes);
170 if (!ppidl) return E_INVALIDARG;
171 *ppidl = 0;
173 if (!lpszDisplayName) return E_INVALIDARG;
175 if (pchEaten)
176 *pchEaten = 0; /* strange but like the original */
178 urldata.cbSize = sizeof(urldata);
180 if (lpszDisplayName[0] == ':' && lpszDisplayName[1] == ':')
182 szNext = GetNextElementW (lpszDisplayName, szElement, MAX_PATH);
183 TRACE ("-- element: %s\n", debugstr_w (szElement));
184 SHCLSIDFromStringW (szElement + 2, &clsid);
185 pidlTemp = _ILCreateGuid (PT_GUID, &clsid);
187 else if (PathGetDriveNumberW (lpszDisplayName) >= 0)
189 /* it's a filesystem path with a drive. Let MyComputer/UnixDosFolder parse it */
190 if (UNIXFS_is_rooted_at_desktop())
191 pidlTemp = _ILCreateGuid(PT_GUID, &CLSID_UnixDosFolder);
192 else
193 pidlTemp = _ILCreateMyComputer ();
194 szNext = lpszDisplayName;
196 else if (PathIsUNCW(lpszDisplayName))
198 pidlTemp = _ILCreateNetwork();
199 szNext = lpszDisplayName;
201 else if( (pidlTemp = SHELL32_CreatePidlFromBindCtx(pbc, lpszDisplayName)) )
203 *ppidl = pidlTemp;
204 return S_OK;
206 else if (SUCCEEDED(ParseURLW(lpszDisplayName, &urldata)))
208 if (urldata.nScheme == URL_SCHEME_SHELL) /* handle shell: urls */
210 TRACE ("-- shell url: %s\n", debugstr_w(urldata.pszSuffix));
211 SHCLSIDFromStringW (urldata.pszSuffix+2, &clsid);
212 pidlTemp = _ILCreateGuid (PT_GUID, &clsid);
214 else
215 return IEParseDisplayNameWithBCW(CP_ACP,lpszDisplayName,pbc,ppidl);
217 else
219 /* it's a filesystem path on the desktop. Let a FSFolder parse it */
221 if (*lpszDisplayName)
223 if (*lpszDisplayName == '/')
225 /* UNIX paths should be parsed by unixfs */
226 IShellFolder *unixFS;
227 hr = UnixFolder_Constructor(NULL, &IID_IShellFolder, (LPVOID*)&unixFS);
228 if (SUCCEEDED(hr))
230 hr = IShellFolder_ParseDisplayName(unixFS, NULL, NULL,
231 lpszDisplayName, NULL, &pidlTemp, NULL);
232 IShellFolder_Release(unixFS);
235 else
237 /* build a complete path to create a simple pidl */
238 WCHAR szPath[MAX_PATH];
239 LPWSTR pathPtr;
241 lstrcpynW(szPath, This->sPathTarget, MAX_PATH);
242 pathPtr = PathAddBackslashW(szPath);
243 if (pathPtr)
245 lstrcpynW(pathPtr, lpszDisplayName, MAX_PATH - (pathPtr - szPath));
246 hr = _ILCreateFromPathW(szPath, &pidlTemp);
248 else
250 /* should never reach here, but for completeness */
251 hr = E_NOT_SUFFICIENT_BUFFER;
255 else
256 pidlTemp = _ILCreateMyComputer();
258 szNext = NULL;
261 if (SUCCEEDED(hr) && pidlTemp)
263 if (szNext && *szNext)
265 hr = SHELL32_ParseNextElement(iface, hwndOwner, pbc,
266 &pidlTemp, (LPOLESTR) szNext, pchEaten, pdwAttributes);
268 else
270 if (pdwAttributes && *pdwAttributes)
271 hr = SHELL32_GetItemAttributes(shell_folder, pidlTemp, pdwAttributes);
275 *ppidl = pidlTemp;
277 TRACE ("(%p)->(-- ret=0x%08x)\n", This, hr);
279 return hr;
282 /**************************************************************************
283 * CreateDesktopEnumList()
285 static const WCHAR Desktop_NameSpaceW[] = { 'S','O','F','T','W','A','R','E',
286 '\\','M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
287 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\','E','x','p','l',
288 'o','r','e','r','\\','D','e','s','k','t','o','p','\\','N','a','m','e','s','p',
289 'a','c','e','\0' };
291 static BOOL CreateDesktopEnumList(IEnumIDListImpl *list, DWORD dwFlags)
293 BOOL ret = TRUE;
294 WCHAR szPath[MAX_PATH];
296 TRACE("(%p)->(flags=0x%08x)\n", list, dwFlags);
298 /* enumerate the root folders */
299 if (dwFlags & SHCONTF_FOLDERS)
301 HKEY hkey;
302 UINT i;
304 /* create the pidl for This item */
305 ret = AddToEnumList(list, _ILCreateMyComputer());
307 for (i=0; i<2; i++) {
308 if (ret && !RegOpenKeyExW(i == 0 ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER,
309 Desktop_NameSpaceW, 0, KEY_READ, &hkey))
311 WCHAR iid[50];
312 int i=0;
314 while (ret)
316 DWORD size;
317 LONG r;
319 size = sizeof (iid) / sizeof (iid[0]);
320 r = RegEnumKeyExW(hkey, i, iid, &size, 0, NULL, NULL, NULL);
321 if (ERROR_SUCCESS == r)
323 ret = AddToEnumList(list, _ILCreateGuidFromStrW(iid));
324 i++;
326 else if (ERROR_NO_MORE_ITEMS == r)
327 break;
328 else
329 ret = FALSE;
331 RegCloseKey(hkey);
336 /* enumerate the elements in %windir%\desktop */
337 ret = ret && SHGetSpecialFolderPathW(0, szPath, CSIDL_DESKTOPDIRECTORY, FALSE);
338 ret = ret && CreateFolderEnumList(list, szPath, dwFlags);
340 return ret;
343 /**************************************************************************
344 * ISF_Desktop_fnEnumObjects
346 static HRESULT WINAPI ISF_Desktop_fnEnumObjects (IShellFolder2 * iface,
347 HWND hwndOwner, DWORD dwFlags, LPENUMIDLIST * ppEnumIDList)
349 IDesktopFolderImpl *This = impl_from_IShellFolder2(iface);
350 IEnumIDListImpl *list;
352 TRACE ("(%p)->(HWND=%p flags=0x%08x pplist=%p)\n",
353 This, hwndOwner, dwFlags, ppEnumIDList);
355 if (!(list = IEnumIDList_Constructor()))
356 return E_OUTOFMEMORY;
357 CreateDesktopEnumList(list, dwFlags);
358 *ppEnumIDList = &list->IEnumIDList_iface;
360 TRACE ("-- (%p)->(new ID List: %p)\n", This, *ppEnumIDList);
362 return S_OK;
365 /**************************************************************************
366 * ISF_Desktop_fnBindToObject
368 static HRESULT WINAPI ISF_Desktop_fnBindToObject (IShellFolder2 * iface,
369 LPCITEMIDLIST pidl, LPBC pbcReserved, REFIID riid, LPVOID * ppvOut)
371 IDesktopFolderImpl *This = impl_from_IShellFolder2(iface);
373 TRACE ("(%p)->(pidl=%p,%p,%s,%p)\n",
374 This, pidl, pbcReserved, shdebugstr_guid (riid), ppvOut);
376 return SHELL32_BindToChild( This->pidlRoot, This->sPathTarget, pidl, riid, ppvOut );
379 /**************************************************************************
380 * ISF_Desktop_fnBindToStorage
382 static HRESULT WINAPI ISF_Desktop_fnBindToStorage (IShellFolder2 * iface,
383 LPCITEMIDLIST pidl, LPBC pbcReserved, REFIID riid, LPVOID * ppvOut)
385 IDesktopFolderImpl *This = impl_from_IShellFolder2(iface);
387 FIXME ("(%p)->(pidl=%p,%p,%s,%p) stub\n",
388 This, pidl, pbcReserved, shdebugstr_guid (riid), ppvOut);
390 *ppvOut = NULL;
391 return E_NOTIMPL;
394 /**************************************************************************
395 * ISF_Desktop_fnCompareIDs
397 static HRESULT WINAPI ISF_Desktop_fnCompareIDs (IShellFolder2 *iface,
398 LPARAM lParam, LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
400 IDesktopFolderImpl *This = impl_from_IShellFolder2(iface);
401 HRESULT hr;
403 TRACE ("(%p)->(0x%08lx,pidl1=%p,pidl2=%p)\n", This, lParam, pidl1, pidl2);
404 hr = SHELL32_CompareIDs(iface, lParam, pidl1, pidl2);
405 TRACE ("-- 0x%08x\n", hr);
406 return hr;
409 /**************************************************************************
410 * ISF_Desktop_fnCreateViewObject
412 static HRESULT WINAPI ISF_Desktop_fnCreateViewObject (IShellFolder2 * iface,
413 HWND hwndOwner, REFIID riid, LPVOID * ppvOut)
415 IDesktopFolderImpl *This = impl_from_IShellFolder2(iface);
416 LPSHELLVIEW pShellView;
417 HRESULT hr = E_INVALIDARG;
419 TRACE ("(%p)->(hwnd=%p,%s,%p)\n",
420 This, hwndOwner, shdebugstr_guid (riid), ppvOut);
422 if (!ppvOut)
423 return E_INVALIDARG;
425 *ppvOut = NULL;
427 if (IsEqualIID (riid, &IID_IDropTarget))
429 WARN ("IDropTarget not implemented\n");
430 hr = E_NOTIMPL;
432 else if (IsEqualIID (riid, &IID_IContextMenu))
434 WARN ("IContextMenu not implemented\n");
435 hr = E_NOTIMPL;
437 else if (IsEqualIID (riid, &IID_IShellView))
439 pShellView = IShellView_Constructor ((IShellFolder *) iface);
440 if (pShellView)
442 hr = IShellView_QueryInterface (pShellView, riid, ppvOut);
443 IShellView_Release (pShellView);
446 TRACE ("-- (%p)->(interface=%p)\n", This, ppvOut);
447 return hr;
450 /**************************************************************************
451 * ISF_Desktop_fnGetAttributesOf
453 static HRESULT WINAPI ISF_Desktop_fnGetAttributesOf (IShellFolder2 * iface,
454 UINT cidl, LPCITEMIDLIST * apidl, DWORD * rgfInOut)
456 IDesktopFolderImpl *This = impl_from_IShellFolder2(iface);
457 IShellFolder *shell_folder = (IShellFolder*)iface;
459 static const DWORD dwDesktopAttributes =
460 SFGAO_STORAGE | SFGAO_HASPROPSHEET | SFGAO_STORAGEANCESTOR |
461 SFGAO_FILESYSANCESTOR | SFGAO_FOLDER | SFGAO_FILESYSTEM | SFGAO_HASSUBFOLDER;
462 static const DWORD dwMyComputerAttributes =
463 SFGAO_CANRENAME | SFGAO_CANDELETE | SFGAO_HASPROPSHEET |
464 SFGAO_DROPTARGET | SFGAO_FILESYSANCESTOR | SFGAO_FOLDER | SFGAO_HASSUBFOLDER;
466 TRACE ("(%p)->(cidl=%d apidl=%p mask=%p (0x%08x))\n",
467 This, cidl, apidl, rgfInOut, rgfInOut ? *rgfInOut : 0);
469 if (!rgfInOut)
470 return E_INVALIDARG;
471 if (cidl && !apidl)
472 return E_INVALIDARG;
474 if (*rgfInOut == 0)
475 *rgfInOut = ~0;
477 if(cidl == 0) {
478 *rgfInOut &= dwDesktopAttributes;
479 } else {
480 while (cidl > 0 && *apidl) {
481 pdump (*apidl);
482 if (_ILIsDesktop(*apidl)) {
483 *rgfInOut &= dwDesktopAttributes;
484 } else if (_ILIsMyComputer(*apidl)) {
485 *rgfInOut &= dwMyComputerAttributes;
486 } else {
487 SHELL32_GetItemAttributes ( shell_folder, *apidl, rgfInOut);
489 apidl++;
490 cidl--;
493 /* make sure SFGAO_VALIDATE is cleared, some apps depend on that */
494 *rgfInOut &= ~SFGAO_VALIDATE;
496 TRACE ("-- result=0x%08x\n", *rgfInOut);
498 return S_OK;
501 /**************************************************************************
502 * ISF_Desktop_fnGetUIObjectOf
504 * PARAMETERS
505 * HWND hwndOwner, //[in ] Parent window for any output
506 * UINT cidl, //[in ] array size
507 * LPCITEMIDLIST* apidl, //[in ] simple pidl array
508 * REFIID riid, //[in ] Requested Interface
509 * UINT* prgfInOut, //[ ] reserved
510 * LPVOID* ppvObject) //[out] Resulting Interface
513 static HRESULT WINAPI ISF_Desktop_fnGetUIObjectOf (IShellFolder2 * iface,
514 HWND hwndOwner, UINT cidl, LPCITEMIDLIST * apidl,
515 REFIID riid, UINT * prgfInOut, LPVOID * ppvOut)
517 IDesktopFolderImpl *This = impl_from_IShellFolder2(iface);
519 LPITEMIDLIST pidl;
520 IUnknown *pObj = NULL;
521 HRESULT hr = E_INVALIDARG;
523 TRACE ("(%p)->(%p,%u,apidl=%p,%s,%p,%p)\n",
524 This, hwndOwner, cidl, apidl, shdebugstr_guid (riid), prgfInOut, ppvOut);
526 if (!ppvOut)
527 return E_INVALIDARG;
529 *ppvOut = NULL;
531 if (IsEqualIID (riid, &IID_IContextMenu))
533 if (cidl > 0)
534 return ItemMenu_Constructor((IShellFolder*)iface, This->pidlRoot, apidl, cidl, riid, ppvOut);
535 else
536 return BackgroundMenu_Constructor((IShellFolder*)iface, TRUE, riid, ppvOut);
538 else if (IsEqualIID (riid, &IID_IDataObject) && (cidl >= 1))
540 pObj = (LPUNKNOWN) IDataObject_Constructor( hwndOwner,
541 This->pidlRoot, apidl, cidl);
542 hr = S_OK;
544 else if (IsEqualIID (riid, &IID_IExtractIconA) && (cidl == 1))
546 pidl = ILCombine (This->pidlRoot, apidl[0]);
547 pObj = (LPUNKNOWN) IExtractIconA_Constructor (pidl);
548 SHFree (pidl);
549 hr = S_OK;
551 else if (IsEqualIID (riid, &IID_IExtractIconW) && (cidl == 1))
553 pidl = ILCombine (This->pidlRoot, apidl[0]);
554 pObj = (LPUNKNOWN) IExtractIconW_Constructor (pidl);
555 SHFree (pidl);
556 hr = S_OK;
558 else if (IsEqualIID (riid, &IID_IDropTarget) && (cidl >= 1))
560 hr = IShellFolder2_QueryInterface (iface,
561 &IID_IDropTarget, (LPVOID *) & pObj);
563 else if ((IsEqualIID(riid,&IID_IShellLinkW) ||
564 IsEqualIID(riid,&IID_IShellLinkA)) && (cidl == 1))
566 pidl = ILCombine (This->pidlRoot, apidl[0]);
567 hr = IShellLink_ConstructFromFile(NULL, riid, pidl, &pObj);
568 SHFree (pidl);
570 else
571 hr = E_NOINTERFACE;
573 if (SUCCEEDED(hr) && !pObj)
574 hr = E_OUTOFMEMORY;
576 *ppvOut = pObj;
577 TRACE ("(%p)->hr=0x%08x\n", This, hr);
578 return hr;
581 /**************************************************************************
582 * ISF_Desktop_fnGetDisplayNameOf
584 * NOTES
585 * special case: pidl = null gives desktop-name back
587 static HRESULT WINAPI ISF_Desktop_fnGetDisplayNameOf (IShellFolder2 * iface,
588 LPCITEMIDLIST pidl, DWORD dwFlags, LPSTRRET strRet)
590 IDesktopFolderImpl *This = impl_from_IShellFolder2(iface);
591 HRESULT hr = S_OK;
592 LPWSTR pszPath;
594 TRACE ("(%p)->(pidl=%p,0x%08x,%p)\n", This, pidl, dwFlags, strRet);
595 pdump (pidl);
597 if (!strRet)
598 return E_INVALIDARG;
600 pszPath = CoTaskMemAlloc((MAX_PATH +1) * sizeof(WCHAR));
601 if (!pszPath)
602 return E_OUTOFMEMORY;
604 if (_ILIsDesktop (pidl))
606 if ((GET_SHGDN_RELATION (dwFlags) == SHGDN_NORMAL) &&
607 (GET_SHGDN_FOR (dwFlags) & SHGDN_FORPARSING))
608 strcpyW(pszPath, This->sPathTarget);
609 else
610 HCR_GetClassNameW(&CLSID_ShellDesktop, pszPath, MAX_PATH);
612 else if (_ILIsPidlSimple (pidl))
614 GUID const *clsid;
616 if ((clsid = _ILGetGUIDPointer (pidl)))
618 if (GET_SHGDN_FOR (dwFlags) & SHGDN_FORPARSING)
620 BOOL bWantsForParsing;
623 * We can only get a filesystem path from a shellfolder if the
624 * value WantsFORPARSING in CLSID\\{...}\\shellfolder exists.
626 * Exception: The MyComputer folder doesn't have this key,
627 * but any other filesystem backed folder it needs it.
629 if (IsEqualIID (clsid, &CLSID_MyComputer))
631 bWantsForParsing = TRUE;
633 else
635 /* get the "WantsFORPARSING" flag from the registry */
636 static const WCHAR clsidW[] =
637 { 'C','L','S','I','D','\\',0 };
638 static const WCHAR shellfolderW[] =
639 { '\\','s','h','e','l','l','f','o','l','d','e','r',0 };
640 static const WCHAR wantsForParsingW[] =
641 { 'W','a','n','t','s','F','o','r','P','a','r','s','i','n',
642 'g',0 };
643 WCHAR szRegPath[100];
644 LONG r;
646 lstrcpyW (szRegPath, clsidW);
647 SHELL32_GUIDToStringW (clsid, &szRegPath[6]);
648 lstrcatW (szRegPath, shellfolderW);
649 r = SHGetValueW(HKEY_CLASSES_ROOT, szRegPath,
650 wantsForParsingW, NULL, NULL, NULL);
651 if (r == ERROR_SUCCESS)
652 bWantsForParsing = TRUE;
653 else
654 bWantsForParsing = FALSE;
657 if ((GET_SHGDN_RELATION (dwFlags) == SHGDN_NORMAL) &&
658 bWantsForParsing)
661 * we need the filesystem path to the destination folder.
662 * Only the folder itself can know it
664 hr = SHELL32_GetDisplayNameOfChild (iface, pidl, dwFlags,
665 pszPath,
666 MAX_PATH);
668 else
670 /* parsing name like ::{...} */
671 pszPath[0] = ':';
672 pszPath[1] = ':';
673 SHELL32_GUIDToStringW (clsid, &pszPath[2]);
676 else
678 /* user friendly name */
679 HCR_GetClassNameW (clsid, pszPath, MAX_PATH);
682 else
684 int cLen = 0;
686 /* file system folder or file rooted at the desktop */
687 if ((GET_SHGDN_FOR(dwFlags) == SHGDN_FORPARSING) &&
688 (GET_SHGDN_RELATION(dwFlags) != SHGDN_INFOLDER))
690 lstrcpynW(pszPath, This->sPathTarget, MAX_PATH - 1);
691 PathAddBackslashW(pszPath);
692 cLen = lstrlenW(pszPath);
695 _ILSimpleGetTextW(pidl, pszPath + cLen, MAX_PATH - cLen);
697 if (!_ILIsFolder(pidl))
698 SHELL_FS_ProcessDisplayFilename(pszPath, dwFlags);
701 else
703 /* a complex pidl, let the subfolder do the work */
704 hr = SHELL32_GetDisplayNameOfChild (iface, pidl, dwFlags,
705 pszPath, MAX_PATH);
708 if (SUCCEEDED(hr))
710 /* Win9x always returns ANSI strings, NT always returns Unicode strings */
711 if (GetVersion() & 0x80000000)
713 strRet->uType = STRRET_CSTR;
714 if (!WideCharToMultiByte(CP_ACP, 0, pszPath, -1, strRet->u.cStr, MAX_PATH,
715 NULL, NULL))
716 strRet->u.cStr[0] = '\0';
717 CoTaskMemFree(pszPath);
719 else
721 strRet->uType = STRRET_WSTR;
722 strRet->u.pOleStr = pszPath;
725 else
726 CoTaskMemFree(pszPath);
728 TRACE ("-- (%p)->(%s,0x%08x)\n", This,
729 strRet->uType == STRRET_CSTR ? strRet->u.cStr :
730 debugstr_w(strRet->u.pOleStr), hr);
731 return hr;
734 /**************************************************************************
735 * ISF_Desktop_fnSetNameOf
736 * Changes the name of a file object or subfolder, possibly changing its item
737 * identifier in the process.
739 * PARAMETERS
740 * HWND hwndOwner, //[in ] Owner window for output
741 * LPCITEMIDLIST pidl, //[in ] simple pidl of item to change
742 * LPCOLESTR lpszName, //[in ] the items new display name
743 * DWORD dwFlags, //[in ] SHGNO formatting flags
744 * LPITEMIDLIST* ppidlOut) //[out] simple pidl returned
746 static HRESULT WINAPI ISF_Desktop_fnSetNameOf (IShellFolder2 * iface,
747 HWND hwndOwner, LPCITEMIDLIST pidl, /* simple pidl */
748 LPCOLESTR lpName, DWORD dwFlags, LPITEMIDLIST * pPidlOut)
750 IDesktopFolderImpl *This = impl_from_IShellFolder2(iface);
752 FIXME ("(%p)->(%p,pidl=%p,%s,%u,%p) stub\n", This, hwndOwner, pidl,
753 debugstr_w (lpName), dwFlags, pPidlOut);
755 return E_FAIL;
758 static HRESULT WINAPI ISF_Desktop_fnGetDefaultSearchGUID(IShellFolder2 *iface,
759 GUID * pguid)
761 IDesktopFolderImpl *This = impl_from_IShellFolder2(iface);
762 FIXME ("(%p)->(%p) stub\n", This, pguid);
763 return E_NOTIMPL;
766 static HRESULT WINAPI ISF_Desktop_fnEnumSearches (IShellFolder2 *iface,
767 IEnumExtraSearch ** ppenum)
769 IDesktopFolderImpl *This = impl_from_IShellFolder2(iface);
770 FIXME ("(%p)->(%p) stub\n", This, ppenum);
771 return E_NOTIMPL;
774 static HRESULT WINAPI ISF_Desktop_fnGetDefaultColumn (IShellFolder2 * iface,
775 DWORD reserved, ULONG * pSort, ULONG * pDisplay)
777 IDesktopFolderImpl *This = impl_from_IShellFolder2(iface);
779 TRACE ("(%p)->(%d %p %p)\n", This, reserved, pSort, pDisplay);
781 if (pSort)
782 *pSort = 0;
783 if (pDisplay)
784 *pDisplay = 0;
786 return S_OK;
788 static HRESULT WINAPI ISF_Desktop_fnGetDefaultColumnState (
789 IShellFolder2 * iface, UINT iColumn, DWORD * pcsFlags)
791 IDesktopFolderImpl *This = impl_from_IShellFolder2(iface);
793 TRACE ("(%p)->(%d %p)\n", This, iColumn, pcsFlags);
795 if (!pcsFlags || iColumn >= DESKTOPSHELLVIEWCOLUMNS)
796 return E_INVALIDARG;
798 *pcsFlags = desktop_header[iColumn].pcsFlags;
800 return S_OK;
803 static HRESULT WINAPI ISF_Desktop_fnGetDetailsEx (IShellFolder2 * iface,
804 LPCITEMIDLIST pidl, const SHCOLUMNID * pscid, VARIANT * pv)
806 IDesktopFolderImpl *This = impl_from_IShellFolder2(iface);
807 FIXME ("(%p)->(%p %p %p) stub\n", This, pidl, pscid, pv);
808 return E_NOTIMPL;
811 static HRESULT WINAPI ISF_Desktop_fnGetDetailsOf (IShellFolder2 * iface,
812 LPCITEMIDLIST pidl, UINT iColumn, SHELLDETAILS * psd)
814 IDesktopFolderImpl *This = impl_from_IShellFolder2(iface);
816 HRESULT hr = S_OK;
818 TRACE ("(%p)->(%p %i %p)\n", This, pidl, iColumn, psd);
820 if (!psd || iColumn >= DESKTOPSHELLVIEWCOLUMNS)
821 return E_INVALIDARG;
823 if (!pidl)
824 return SHELL32_GetColumnDetails(desktop_header, iColumn, psd);
826 /* the data from the pidl */
827 psd->str.uType = STRRET_CSTR;
828 switch (iColumn)
830 case 0: /* name */
831 hr = IShellFolder2_GetDisplayNameOf(iface, pidl,
832 SHGDN_NORMAL | SHGDN_INFOLDER, &psd->str);
833 break;
834 case 1: /* size */
835 _ILGetFileSize (pidl, psd->str.u.cStr, MAX_PATH);
836 break;
837 case 2: /* type */
838 _ILGetFileType (pidl, psd->str.u.cStr, MAX_PATH);
839 break;
840 case 3: /* date */
841 _ILGetFileDate (pidl, psd->str.u.cStr, MAX_PATH);
842 break;
843 case 4: /* attributes */
844 _ILGetFileAttributes (pidl, psd->str.u.cStr, MAX_PATH);
845 break;
848 return hr;
851 static HRESULT WINAPI ISF_Desktop_fnMapColumnToSCID (
852 IShellFolder2 * iface, UINT column, SHCOLUMNID * pscid)
854 IDesktopFolderImpl *This = impl_from_IShellFolder2(iface);
855 FIXME ("(%p)->(%d %p) stub\n", This, column, pscid);
856 return E_NOTIMPL;
859 static const IShellFolder2Vtbl vt_MCFldr_ShellFolder2 =
861 ISF_Desktop_fnQueryInterface,
862 ISF_Desktop_fnAddRef,
863 ISF_Desktop_fnRelease,
864 ISF_Desktop_fnParseDisplayName,
865 ISF_Desktop_fnEnumObjects,
866 ISF_Desktop_fnBindToObject,
867 ISF_Desktop_fnBindToStorage,
868 ISF_Desktop_fnCompareIDs,
869 ISF_Desktop_fnCreateViewObject,
870 ISF_Desktop_fnGetAttributesOf,
871 ISF_Desktop_fnGetUIObjectOf,
872 ISF_Desktop_fnGetDisplayNameOf,
873 ISF_Desktop_fnSetNameOf,
874 /* ShellFolder2 */
875 ISF_Desktop_fnGetDefaultSearchGUID,
876 ISF_Desktop_fnEnumSearches,
877 ISF_Desktop_fnGetDefaultColumn,
878 ISF_Desktop_fnGetDefaultColumnState,
879 ISF_Desktop_fnGetDetailsEx,
880 ISF_Desktop_fnGetDetailsOf,
881 ISF_Desktop_fnMapColumnToSCID
884 /**************************************************************************
885 * IPersist
887 static HRESULT WINAPI ISF_Desktop_IPersistFolder2_fnQueryInterface(
888 IPersistFolder2 *iface, REFIID riid, LPVOID *ppvObj)
890 IDesktopFolderImpl *This = impl_from_IPersistFolder2( iface );
891 return IShellFolder2_QueryInterface(&This->IShellFolder2_iface, riid, ppvObj);
894 static ULONG WINAPI ISF_Desktop_IPersistFolder2_fnAddRef(
895 IPersistFolder2 *iface)
897 IDesktopFolderImpl *This = impl_from_IPersistFolder2( iface );
898 return IShellFolder2_AddRef(&This->IShellFolder2_iface);
901 static ULONG WINAPI ISF_Desktop_IPersistFolder2_fnRelease(
902 IPersistFolder2 *iface)
904 IDesktopFolderImpl *This = impl_from_IPersistFolder2( iface );
905 return IShellFolder2_Release(&This->IShellFolder2_iface);
908 static HRESULT WINAPI ISF_Desktop_IPersistFolder2_fnGetClassID(
909 IPersistFolder2 *iface, CLSID *clsid)
911 *clsid = CLSID_ShellDesktop;
912 return S_OK;
914 static HRESULT WINAPI ISF_Desktop_IPersistFolder2_fnInitialize(
915 IPersistFolder2 *iface, LPCITEMIDLIST pidl)
917 IDesktopFolderImpl *This = impl_from_IPersistFolder2( iface );
918 FIXME ("(%p)->(%p) stub\n", This, pidl);
919 return E_NOTIMPL;
921 static HRESULT WINAPI ISF_Desktop_IPersistFolder2_fnGetCurFolder(
922 IPersistFolder2 *iface, LPITEMIDLIST *ppidl)
924 IDesktopFolderImpl *This = impl_from_IPersistFolder2( iface );
925 *ppidl = ILClone(This->pidlRoot);
926 return S_OK;
929 static const IPersistFolder2Vtbl vt_IPersistFolder2 =
931 ISF_Desktop_IPersistFolder2_fnQueryInterface,
932 ISF_Desktop_IPersistFolder2_fnAddRef,
933 ISF_Desktop_IPersistFolder2_fnRelease,
934 ISF_Desktop_IPersistFolder2_fnGetClassID,
935 ISF_Desktop_IPersistFolder2_fnInitialize,
936 ISF_Desktop_IPersistFolder2_fnGetCurFolder
939 void release_desktop_folder(void)
941 if (!cached_sf) return;
942 SHFree(cached_sf->pidlRoot);
943 SHFree(cached_sf->sPathTarget);
944 LocalFree(cached_sf);
947 /**************************************************************************
948 * ISF_Desktop_Constructor
950 HRESULT WINAPI ISF_Desktop_Constructor (
951 IUnknown * pUnkOuter, REFIID riid, LPVOID * ppv)
953 WCHAR szMyPath[MAX_PATH];
955 TRACE ("unkOut=%p %s\n", pUnkOuter, shdebugstr_guid (riid));
957 if (!ppv)
958 return E_POINTER;
959 if (pUnkOuter)
960 return CLASS_E_NOAGGREGATION;
962 if (!cached_sf)
964 IDesktopFolderImpl *sf;
966 if (!SHGetSpecialFolderPathW( 0, szMyPath, CSIDL_DESKTOPDIRECTORY, TRUE ))
967 return E_UNEXPECTED;
969 sf = LocalAlloc( LMEM_ZEROINIT, sizeof (IDesktopFolderImpl) );
970 if (!sf)
971 return E_OUTOFMEMORY;
973 sf->ref = 1;
974 sf->IShellFolder2_iface.lpVtbl = &vt_MCFldr_ShellFolder2;
975 sf->IPersistFolder2_iface.lpVtbl = &vt_IPersistFolder2;
976 sf->pidlRoot = _ILCreateDesktop(); /* my qualified pidl */
977 sf->sPathTarget = SHAlloc( (lstrlenW(szMyPath) + 1)*sizeof(WCHAR) );
978 lstrcpyW( sf->sPathTarget, szMyPath );
980 if (InterlockedCompareExchangePointer((void *)&cached_sf, sf, NULL) != NULL)
982 /* some other thread already been here */
983 SHFree( sf->pidlRoot );
984 SHFree( sf->sPathTarget );
985 LocalFree( sf );
989 return IShellFolder2_QueryInterface( &cached_sf->IShellFolder2_iface, riid, ppv );