xcopy: Remove spaces before '\n's in the Korean translation.
[wine/hramrach.git] / dlls / shell32 / shfldr_desktop.c
blobe4a612a36ee7218f5bd213f410a8f55ae720a51b
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 IPersistFolder2Vtbl *lpVtblPF2;
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 } IDesktopFolderImpl;
79 static inline IDesktopFolderImpl *impl_from_IPersistFolder2( IPersistFolder2 *iface )
81 return (IDesktopFolderImpl *)((char*)iface - FIELD_OFFSET(IDesktopFolderImpl, lpVtblPF2));
84 static const shvheader desktop_header[] = {
85 {IDS_SHV_COLUMN1, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 15},
86 {IDS_SHV_COLUMN2, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
87 {IDS_SHV_COLUMN3, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
88 {IDS_SHV_COLUMN4, SHCOLSTATE_TYPE_DATE | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 12},
89 {IDS_SHV_COLUMN5, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 5}
92 #define DESKTOPSHELLVIEWCOLUMNS sizeof(desktop_header)/sizeof(shvheader)
94 /**************************************************************************
95 * ISF_Desktop_fnQueryInterface
98 static HRESULT WINAPI ISF_Desktop_fnQueryInterface(
99 IShellFolder2 * iface, REFIID riid, LPVOID * ppvObj)
101 IDesktopFolderImpl *This = (IDesktopFolderImpl *)iface;
103 TRACE ("(%p)->(%s,%p)\n", This, shdebugstr_guid (riid), ppvObj);
105 *ppvObj = NULL;
107 if (IsEqualIID (riid, &IID_IUnknown) ||
108 IsEqualIID (riid, &IID_IShellFolder) ||
109 IsEqualIID (riid, &IID_IShellFolder2))
111 *ppvObj = This;
113 else if (IsEqualIID (riid, &IID_IPersist) ||
114 IsEqualIID (riid, &IID_IPersistFolder) ||
115 IsEqualIID (riid, &IID_IPersistFolder2))
117 *ppvObj = &This->lpVtblPF2;
120 if (*ppvObj)
122 IUnknown_AddRef ((IUnknown *) (*ppvObj));
123 TRACE ("-- Interface: (%p)->(%p)\n", ppvObj, *ppvObj);
124 return S_OK;
126 TRACE ("-- Interface: E_NOINTERFACE\n");
127 return E_NOINTERFACE;
130 static ULONG WINAPI ISF_Desktop_fnAddRef (IShellFolder2 * iface)
132 return 2; /* non-heap based object */
135 static ULONG WINAPI ISF_Desktop_fnRelease (IShellFolder2 * iface)
137 return 1; /* non-heap based object */
140 /**************************************************************************
141 * ISF_Desktop_fnParseDisplayName
143 * NOTES
144 * "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}" and "" binds
145 * to MyComputer
147 static HRESULT WINAPI ISF_Desktop_fnParseDisplayName (IShellFolder2 * iface,
148 HWND hwndOwner, LPBC pbc, LPOLESTR lpszDisplayName,
149 DWORD * pchEaten, LPITEMIDLIST * ppidl, DWORD * pdwAttributes)
151 IDesktopFolderImpl *This = (IDesktopFolderImpl *)iface;
152 IShellFolder *shell_folder = (IShellFolder*)iface;
153 WCHAR szElement[MAX_PATH];
154 LPCWSTR szNext = NULL;
155 LPITEMIDLIST pidlTemp = NULL;
156 PARSEDURLW urldata;
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 urldata.cbSize = sizeof(urldata);
174 if (lpszDisplayName[0] == ':' && lpszDisplayName[1] == ':')
176 szNext = GetNextElementW (lpszDisplayName, szElement, MAX_PATH);
177 TRACE ("-- element: %s\n", debugstr_w (szElement));
178 SHCLSIDFromStringW (szElement + 2, &clsid);
179 pidlTemp = _ILCreateGuid (PT_GUID, &clsid);
181 else if (PathGetDriveNumberW (lpszDisplayName) >= 0)
183 /* it's a filesystem path with a drive. Let MyComputer/UnixDosFolder parse it */
184 if (UNIXFS_is_rooted_at_desktop())
185 pidlTemp = _ILCreateGuid(PT_GUID, &CLSID_UnixDosFolder);
186 else
187 pidlTemp = _ILCreateMyComputer ();
188 szNext = lpszDisplayName;
190 else if (PathIsUNCW(lpszDisplayName))
192 pidlTemp = _ILCreateNetwork();
193 szNext = lpszDisplayName;
195 else if( (pidlTemp = SHELL32_CreatePidlFromBindCtx(pbc, lpszDisplayName)) )
197 *ppidl = pidlTemp;
198 return S_OK;
200 else if (SUCCEEDED(ParseURLW(lpszDisplayName, &urldata)))
202 if (urldata.nScheme == URL_SCHEME_SHELL) /* handle shell: urls */
204 TRACE ("-- shell url: %s\n", debugstr_w(urldata.pszSuffix));
205 SHCLSIDFromStringW (urldata.pszSuffix+2, &clsid);
206 pidlTemp = _ILCreateGuid (PT_GUID, &clsid);
208 else
209 return IEParseDisplayNameWithBCW(CP_ACP,lpszDisplayName,pbc,ppidl);
211 else
213 /* it's a filesystem path on the desktop. Let a FSFolder parse it */
215 if (*lpszDisplayName)
217 if (*lpszDisplayName == '/')
219 /* UNIX paths should be parsed by unixfs */
220 IShellFolder *unixFS;
221 hr = UnixFolder_Constructor(NULL, &IID_IShellFolder, (LPVOID*)&unixFS);
222 if (SUCCEEDED(hr))
224 hr = IShellFolder_ParseDisplayName(unixFS, NULL, NULL,
225 lpszDisplayName, NULL, &pidlTemp, NULL);
226 IShellFolder_Release(unixFS);
229 else
231 /* build a complete path to create a simple pidl */
232 WCHAR szPath[MAX_PATH];
233 LPWSTR pathPtr;
235 lstrcpynW(szPath, This->sPathTarget, MAX_PATH);
236 pathPtr = PathAddBackslashW(szPath);
237 if (pathPtr)
239 lstrcpynW(pathPtr, lpszDisplayName, MAX_PATH - (pathPtr - szPath));
240 hr = _ILCreateFromPathW(szPath, &pidlTemp);
242 else
244 /* should never reach here, but for completeness */
245 hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
249 else
250 pidlTemp = _ILCreateMyComputer();
252 szNext = NULL;
255 if (SUCCEEDED(hr) && pidlTemp)
257 if (szNext && *szNext)
259 hr = SHELL32_ParseNextElement(iface, hwndOwner, pbc,
260 &pidlTemp, (LPOLESTR) szNext, pchEaten, pdwAttributes);
262 else
264 if (pdwAttributes && *pdwAttributes)
265 hr = SHELL32_GetItemAttributes(shell_folder, pidlTemp, pdwAttributes);
269 *ppidl = pidlTemp;
271 TRACE ("(%p)->(-- ret=0x%08x)\n", This, hr);
273 return hr;
276 /**************************************************************************
277 * CreateDesktopEnumList()
279 static const WCHAR Desktop_NameSpaceW[] = { 'S','O','F','T','W','A','R','E',
280 '\\','M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
281 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\','E','x','p','l',
282 'o','r','e','r','\\','D','e','s','k','t','o','p','\\','N','a','m','e','s','p',
283 'a','c','e','\0' };
285 static BOOL CreateDesktopEnumList(IEnumIDList *list, DWORD dwFlags)
287 BOOL ret = TRUE;
288 WCHAR szPath[MAX_PATH];
290 TRACE("(%p)->(flags=0x%08x)\n", list, dwFlags);
292 /* enumerate the root folders */
293 if (dwFlags & SHCONTF_FOLDERS)
295 HKEY hkey;
296 UINT i;
298 /* create the pidl for This item */
299 ret = AddToEnumList(list, _ILCreateMyComputer());
301 for (i=0; i<2; i++) {
302 if (ret && !RegOpenKeyExW(i == 0 ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER,
303 Desktop_NameSpaceW, 0, KEY_READ, &hkey))
305 WCHAR iid[50];
306 int i=0;
308 while (ret)
310 DWORD size;
311 LONG r;
313 size = sizeof (iid) / sizeof (iid[0]);
314 r = RegEnumKeyExW(hkey, i, iid, &size, 0, NULL, NULL, NULL);
315 if (ERROR_SUCCESS == r)
317 ret = AddToEnumList(list, _ILCreateGuidFromStrW(iid));
318 i++;
320 else if (ERROR_NO_MORE_ITEMS == r)
321 break;
322 else
323 ret = FALSE;
325 RegCloseKey(hkey);
330 /* enumerate the elements in %windir%\desktop */
331 SHGetSpecialFolderPathW(0, szPath, CSIDL_DESKTOPDIRECTORY, FALSE);
332 ret = ret && CreateFolderEnumList(list, szPath, dwFlags);
334 return ret;
337 /**************************************************************************
338 * ISF_Desktop_fnEnumObjects
340 static HRESULT WINAPI ISF_Desktop_fnEnumObjects (IShellFolder2 * iface,
341 HWND hwndOwner, DWORD dwFlags, LPENUMIDLIST * ppEnumIDList)
343 IDesktopFolderImpl *This = (IDesktopFolderImpl *)iface;
345 TRACE ("(%p)->(HWND=%p flags=0x%08x pplist=%p)\n",
346 This, hwndOwner, dwFlags, ppEnumIDList);
348 *ppEnumIDList = IEnumIDList_Constructor();
349 if (*ppEnumIDList)
350 CreateDesktopEnumList(*ppEnumIDList, dwFlags);
352 TRACE ("-- (%p)->(new ID List: %p)\n", This, *ppEnumIDList);
354 return *ppEnumIDList ? S_OK : E_OUTOFMEMORY;
357 /**************************************************************************
358 * ISF_Desktop_fnBindToObject
360 static HRESULT WINAPI ISF_Desktop_fnBindToObject (IShellFolder2 * iface,
361 LPCITEMIDLIST pidl, LPBC pbcReserved, REFIID riid, LPVOID * ppvOut)
363 IDesktopFolderImpl *This = (IDesktopFolderImpl *)iface;
365 TRACE ("(%p)->(pidl=%p,%p,%s,%p)\n",
366 This, pidl, pbcReserved, shdebugstr_guid (riid), ppvOut);
368 return SHELL32_BindToChild( This->pidlRoot, This->sPathTarget, pidl, riid, ppvOut );
371 /**************************************************************************
372 * ISF_Desktop_fnBindToStorage
374 static HRESULT WINAPI ISF_Desktop_fnBindToStorage (IShellFolder2 * iface,
375 LPCITEMIDLIST pidl, LPBC pbcReserved, REFIID riid, LPVOID * ppvOut)
377 IDesktopFolderImpl *This = (IDesktopFolderImpl *)iface;
379 FIXME ("(%p)->(pidl=%p,%p,%s,%p) stub\n",
380 This, pidl, pbcReserved, shdebugstr_guid (riid), ppvOut);
382 *ppvOut = NULL;
383 return E_NOTIMPL;
386 /**************************************************************************
387 * ISF_Desktop_fnCompareIDs
389 static HRESULT WINAPI ISF_Desktop_fnCompareIDs (IShellFolder2 *iface,
390 LPARAM lParam, LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
392 IDesktopFolderImpl *This = (IDesktopFolderImpl *)iface;
393 IShellFolder *shell_folder = (IShellFolder*)iface;
394 HRESULT hr;
396 TRACE ("(%p)->(0x%08lx,pidl1=%p,pidl2=%p)\n", This, lParam, pidl1, pidl2);
397 hr = SHELL32_CompareIDs ( shell_folder, lParam, pidl1, pidl2);
398 TRACE ("-- 0x%08x\n", hr);
399 return hr;
402 /**************************************************************************
403 * ISF_Desktop_fnCreateViewObject
405 static HRESULT WINAPI ISF_Desktop_fnCreateViewObject (IShellFolder2 * iface,
406 HWND hwndOwner, REFIID riid, LPVOID * ppvOut)
408 IDesktopFolderImpl *This = (IDesktopFolderImpl *)iface;
409 LPSHELLVIEW pShellView;
410 HRESULT hr = E_INVALIDARG;
412 TRACE ("(%p)->(hwnd=%p,%s,%p)\n",
413 This, hwndOwner, shdebugstr_guid (riid), ppvOut);
415 if (!ppvOut)
416 return E_INVALIDARG;
418 *ppvOut = NULL;
420 if (IsEqualIID (riid, &IID_IDropTarget))
422 WARN ("IDropTarget not implemented\n");
423 hr = E_NOTIMPL;
425 else if (IsEqualIID (riid, &IID_IContextMenu))
427 WARN ("IContextMenu not implemented\n");
428 hr = E_NOTIMPL;
430 else if (IsEqualIID (riid, &IID_IShellView))
432 pShellView = IShellView_Constructor ((IShellFolder *) iface);
433 if (pShellView)
435 hr = IShellView_QueryInterface (pShellView, riid, ppvOut);
436 IShellView_Release (pShellView);
439 TRACE ("-- (%p)->(interface=%p)\n", This, ppvOut);
440 return hr;
443 /**************************************************************************
444 * ISF_Desktop_fnGetAttributesOf
446 static HRESULT WINAPI ISF_Desktop_fnGetAttributesOf (IShellFolder2 * iface,
447 UINT cidl, LPCITEMIDLIST * apidl, DWORD * rgfInOut)
449 IDesktopFolderImpl *This = (IDesktopFolderImpl *)iface;
450 IShellFolder *shell_folder = (IShellFolder*)iface;
452 static const DWORD dwDesktopAttributes =
453 SFGAO_STORAGE | SFGAO_HASPROPSHEET | SFGAO_STORAGEANCESTOR |
454 SFGAO_FILESYSANCESTOR | SFGAO_FOLDER | SFGAO_FILESYSTEM | SFGAO_HASSUBFOLDER;
455 static const DWORD dwMyComputerAttributes =
456 SFGAO_CANRENAME | SFGAO_CANDELETE | SFGAO_HASPROPSHEET |
457 SFGAO_DROPTARGET | SFGAO_FILESYSANCESTOR | SFGAO_FOLDER | SFGAO_HASSUBFOLDER;
459 TRACE ("(%p)->(cidl=%d apidl=%p mask=%p (0x%08x))\n",
460 This, cidl, apidl, rgfInOut, rgfInOut ? *rgfInOut : 0);
462 if (!rgfInOut)
463 return E_INVALIDARG;
464 if (cidl && !apidl)
465 return E_INVALIDARG;
467 if (*rgfInOut == 0)
468 *rgfInOut = ~0;
470 if(cidl == 0) {
471 *rgfInOut &= dwDesktopAttributes;
472 } else {
473 while (cidl > 0 && *apidl) {
474 pdump (*apidl);
475 if (_ILIsDesktop(*apidl)) {
476 *rgfInOut &= dwDesktopAttributes;
477 } else if (_ILIsMyComputer(*apidl)) {
478 *rgfInOut &= dwMyComputerAttributes;
479 } else {
480 SHELL32_GetItemAttributes ( shell_folder, *apidl, rgfInOut);
482 apidl++;
483 cidl--;
486 /* make sure SFGAO_VALIDATE is cleared, some apps depend on that */
487 *rgfInOut &= ~SFGAO_VALIDATE;
489 TRACE ("-- result=0x%08x\n", *rgfInOut);
491 return S_OK;
494 /**************************************************************************
495 * ISF_Desktop_fnGetUIObjectOf
497 * PARAMETERS
498 * HWND hwndOwner, //[in ] Parent window for any output
499 * UINT cidl, //[in ] array size
500 * LPCITEMIDLIST* apidl, //[in ] simple pidl array
501 * REFIID riid, //[in ] Requested Interface
502 * UINT* prgfInOut, //[ ] reserved
503 * LPVOID* ppvObject) //[out] Resulting Interface
506 static HRESULT WINAPI ISF_Desktop_fnGetUIObjectOf (IShellFolder2 * iface,
507 HWND hwndOwner, UINT cidl, LPCITEMIDLIST * apidl,
508 REFIID riid, UINT * prgfInOut, LPVOID * ppvOut)
510 IDesktopFolderImpl *This = (IDesktopFolderImpl *)iface;
512 LPITEMIDLIST pidl;
513 IUnknown *pObj = NULL;
514 HRESULT hr = E_INVALIDARG;
516 TRACE ("(%p)->(%p,%u,apidl=%p,%s,%p,%p)\n",
517 This, hwndOwner, cidl, apidl, shdebugstr_guid (riid), prgfInOut, ppvOut);
519 if (!ppvOut)
520 return E_INVALIDARG;
522 *ppvOut = NULL;
524 if (IsEqualIID (riid, &IID_IContextMenu))
526 if (cidl > 0)
527 pObj = (LPUNKNOWN) ISvItemCm_Constructor( (IShellFolder *) iface, This->pidlRoot, apidl, cidl);
528 else
529 pObj = (LPUNKNOWN) ISvBgCm_Constructor( (IShellFolder *) iface, TRUE);
530 hr = S_OK;
532 else if (IsEqualIID (riid, &IID_IDataObject) && (cidl >= 1))
534 pObj = (LPUNKNOWN) IDataObject_Constructor( hwndOwner,
535 This->pidlRoot, apidl, cidl);
536 hr = S_OK;
538 else if (IsEqualIID (riid, &IID_IExtractIconA) && (cidl == 1))
540 pidl = ILCombine (This->pidlRoot, apidl[0]);
541 pObj = (LPUNKNOWN) IExtractIconA_Constructor (pidl);
542 SHFree (pidl);
543 hr = S_OK;
545 else if (IsEqualIID (riid, &IID_IExtractIconW) && (cidl == 1))
547 pidl = ILCombine (This->pidlRoot, apidl[0]);
548 pObj = (LPUNKNOWN) IExtractIconW_Constructor (pidl);
549 SHFree (pidl);
550 hr = S_OK;
552 else if (IsEqualIID (riid, &IID_IDropTarget) && (cidl >= 1))
554 hr = IShellFolder_QueryInterface (iface,
555 &IID_IDropTarget, (LPVOID *) & pObj);
557 else if ((IsEqualIID(riid,&IID_IShellLinkW) ||
558 IsEqualIID(riid,&IID_IShellLinkA)) && (cidl == 1))
560 pidl = ILCombine (This->pidlRoot, apidl[0]);
561 hr = IShellLink_ConstructFromFile(NULL, riid, pidl, (LPVOID*)&pObj);
562 SHFree (pidl);
564 else
565 hr = E_NOINTERFACE;
567 if (SUCCEEDED(hr) && !pObj)
568 hr = E_OUTOFMEMORY;
570 *ppvOut = pObj;
571 TRACE ("(%p)->hr=0x%08x\n", This, hr);
572 return hr;
575 /**************************************************************************
576 * ISF_Desktop_fnGetDisplayNameOf
578 * NOTES
579 * special case: pidl = null gives desktop-name back
581 static HRESULT WINAPI ISF_Desktop_fnGetDisplayNameOf (IShellFolder2 * iface,
582 LPCITEMIDLIST pidl, DWORD dwFlags, LPSTRRET strRet)
584 IDesktopFolderImpl *This = (IDesktopFolderImpl *)iface;
585 HRESULT hr = S_OK;
586 LPWSTR pszPath;
588 TRACE ("(%p)->(pidl=%p,0x%08x,%p)\n", This, pidl, dwFlags, strRet);
589 pdump (pidl);
591 if (!strRet)
592 return E_INVALIDARG;
594 pszPath = CoTaskMemAlloc((MAX_PATH +1) * sizeof(WCHAR));
595 if (!pszPath)
596 return E_OUTOFMEMORY;
598 if (_ILIsDesktop (pidl))
600 if ((GET_SHGDN_RELATION (dwFlags) == SHGDN_NORMAL) &&
601 (GET_SHGDN_FOR (dwFlags) & SHGDN_FORPARSING))
602 strcpyW(pszPath, This->sPathTarget);
603 else
604 HCR_GetClassNameW(&CLSID_ShellDesktop, pszPath, MAX_PATH);
606 else if (_ILIsPidlSimple (pidl))
608 GUID const *clsid;
610 if ((clsid = _ILGetGUIDPointer (pidl)))
612 if (GET_SHGDN_FOR (dwFlags) & SHGDN_FORPARSING)
614 int bWantsForParsing;
617 * We can only get a filesystem path from a shellfolder if the
618 * value WantsFORPARSING in CLSID\\{...}\\shellfolder exists.
620 * Exception: The MyComputer folder doesn't have this key,
621 * but any other filesystem backed folder it needs it.
623 if (IsEqualIID (clsid, &CLSID_MyComputer))
625 bWantsForParsing = TRUE;
627 else
629 /* get the "WantsFORPARSING" flag from the registry */
630 static const WCHAR clsidW[] =
631 { 'C','L','S','I','D','\\',0 };
632 static const WCHAR shellfolderW[] =
633 { '\\','s','h','e','l','l','f','o','l','d','e','r',0 };
634 static const WCHAR wantsForParsingW[] =
635 { 'W','a','n','t','s','F','o','r','P','a','r','s','i','n',
636 'g',0 };
637 WCHAR szRegPath[100];
638 LONG r;
640 lstrcpyW (szRegPath, clsidW);
641 SHELL32_GUIDToStringW (clsid, &szRegPath[6]);
642 lstrcatW (szRegPath, shellfolderW);
643 r = SHGetValueW(HKEY_CLASSES_ROOT, szRegPath,
644 wantsForParsingW, NULL, NULL, NULL);
645 if (r == ERROR_SUCCESS)
646 bWantsForParsing = TRUE;
647 else
648 bWantsForParsing = FALSE;
651 if ((GET_SHGDN_RELATION (dwFlags) == SHGDN_NORMAL) &&
652 bWantsForParsing)
655 * we need the filesystem path to the destination folder.
656 * Only the folder itself can know it
658 hr = SHELL32_GetDisplayNameOfChild (iface, pidl, dwFlags,
659 pszPath,
660 MAX_PATH);
662 else
664 /* parsing name like ::{...} */
665 pszPath[0] = ':';
666 pszPath[1] = ':';
667 SHELL32_GUIDToStringW (clsid, &pszPath[2]);
670 else
672 /* user friendly name */
673 HCR_GetClassNameW (clsid, pszPath, MAX_PATH);
676 else
678 int cLen = 0;
680 /* file system folder or file rooted at the desktop */
681 if ((GET_SHGDN_FOR(dwFlags) == SHGDN_FORPARSING) &&
682 (GET_SHGDN_RELATION(dwFlags) != SHGDN_INFOLDER))
684 lstrcpynW(pszPath, This->sPathTarget, MAX_PATH - 1);
685 PathAddBackslashW(pszPath);
686 cLen = lstrlenW(pszPath);
689 _ILSimpleGetTextW(pidl, pszPath + cLen, MAX_PATH - cLen);
691 if (!_ILIsFolder(pidl))
692 SHELL_FS_ProcessDisplayFilename(pszPath, dwFlags);
695 else
697 /* a complex pidl, let the subfolder do the work */
698 hr = SHELL32_GetDisplayNameOfChild (iface, pidl, dwFlags,
699 pszPath, MAX_PATH);
702 if (SUCCEEDED(hr))
704 /* Win9x always returns ANSI strings, NT always returns Unicode strings */
705 if (GetVersion() & 0x80000000)
707 strRet->uType = STRRET_CSTR;
708 if (!WideCharToMultiByte(CP_ACP, 0, pszPath, -1, strRet->u.cStr, MAX_PATH,
709 NULL, NULL))
710 strRet->u.cStr[0] = '\0';
711 CoTaskMemFree(pszPath);
713 else
715 strRet->uType = STRRET_WSTR;
716 strRet->u.pOleStr = pszPath;
719 else
720 CoTaskMemFree(pszPath);
722 TRACE ("-- (%p)->(%s,0x%08x)\n", This,
723 strRet->uType == STRRET_CSTR ? strRet->u.cStr :
724 debugstr_w(strRet->u.pOleStr), hr);
725 return hr;
728 /**************************************************************************
729 * ISF_Desktop_fnSetNameOf
730 * Changes the name of a file object or subfolder, possibly changing its item
731 * identifier in the process.
733 * PARAMETERS
734 * HWND hwndOwner, //[in ] Owner window for output
735 * LPCITEMIDLIST pidl, //[in ] simple pidl of item to change
736 * LPCOLESTR lpszName, //[in ] the items new display name
737 * DWORD dwFlags, //[in ] SHGNO formatting flags
738 * LPITEMIDLIST* ppidlOut) //[out] simple pidl returned
740 static HRESULT WINAPI ISF_Desktop_fnSetNameOf (IShellFolder2 * iface,
741 HWND hwndOwner, LPCITEMIDLIST pidl, /* simple pidl */
742 LPCOLESTR lpName, DWORD dwFlags, LPITEMIDLIST * pPidlOut)
744 IDesktopFolderImpl *This = (IDesktopFolderImpl *)iface;
746 FIXME ("(%p)->(%p,pidl=%p,%s,%u,%p) stub\n", This, hwndOwner, pidl,
747 debugstr_w (lpName), dwFlags, pPidlOut);
749 return E_FAIL;
752 static HRESULT WINAPI ISF_Desktop_fnGetDefaultSearchGUID(IShellFolder2 *iface,
753 GUID * pguid)
755 IDesktopFolderImpl *This = (IDesktopFolderImpl *)iface;
756 FIXME ("(%p)->(%p) stub\n", This, pguid);
757 return E_NOTIMPL;
760 static HRESULT WINAPI ISF_Desktop_fnEnumSearches (IShellFolder2 *iface,
761 IEnumExtraSearch ** ppenum)
763 IDesktopFolderImpl *This = (IDesktopFolderImpl *)iface;
764 FIXME ("(%p)->(%p) stub\n", This, ppenum);
765 return E_NOTIMPL;
768 static HRESULT WINAPI ISF_Desktop_fnGetDefaultColumn (IShellFolder2 * iface,
769 DWORD reserved, ULONG * pSort, ULONG * pDisplay)
771 IDesktopFolderImpl *This = (IDesktopFolderImpl *)iface;
773 TRACE ("(%p)->(%d %p %p)\n", This, reserved, pSort, pDisplay);
775 if (pSort)
776 *pSort = 0;
777 if (pDisplay)
778 *pDisplay = 0;
780 return S_OK;
782 static HRESULT WINAPI ISF_Desktop_fnGetDefaultColumnState (
783 IShellFolder2 * iface, UINT iColumn, DWORD * pcsFlags)
785 IDesktopFolderImpl *This = (IDesktopFolderImpl *)iface;
787 TRACE ("(%p)->(%d %p)\n", This, iColumn, pcsFlags);
789 if (!pcsFlags || iColumn >= DESKTOPSHELLVIEWCOLUMNS)
790 return E_INVALIDARG;
792 *pcsFlags = desktop_header[iColumn].pcsFlags;
794 return S_OK;
797 static HRESULT WINAPI ISF_Desktop_fnGetDetailsEx (IShellFolder2 * iface,
798 LPCITEMIDLIST pidl, const SHCOLUMNID * pscid, VARIANT * pv)
800 IDesktopFolderImpl *This = (IDesktopFolderImpl *)iface;
801 FIXME ("(%p)->(%p %p %p) stub\n", This, pidl, pscid, pv);
802 return E_NOTIMPL;
805 static HRESULT WINAPI ISF_Desktop_fnGetDetailsOf (IShellFolder2 * iface,
806 LPCITEMIDLIST pidl, UINT iColumn, SHELLDETAILS * psd)
808 IDesktopFolderImpl *This = (IDesktopFolderImpl *)iface;
810 HRESULT hr = S_OK;
812 TRACE ("(%p)->(%p %i %p)\n", This, pidl, iColumn, psd);
814 if (!psd || iColumn >= DESKTOPSHELLVIEWCOLUMNS)
815 return E_INVALIDARG;
817 if (!pidl)
818 return SHELL32_GetColumnDetails(desktop_header, iColumn, psd);
820 /* the data from the pidl */
821 psd->str.uType = STRRET_CSTR;
822 switch (iColumn)
824 case 0: /* name */
825 hr = IShellFolder_GetDisplayNameOf(iface, pidl,
826 SHGDN_NORMAL | SHGDN_INFOLDER, &psd->str);
827 break;
828 case 1: /* size */
829 _ILGetFileSize (pidl, psd->str.u.cStr, MAX_PATH);
830 break;
831 case 2: /* type */
832 _ILGetFileType (pidl, psd->str.u.cStr, MAX_PATH);
833 break;
834 case 3: /* date */
835 _ILGetFileDate (pidl, psd->str.u.cStr, MAX_PATH);
836 break;
837 case 4: /* attributes */
838 _ILGetFileAttributes (pidl, psd->str.u.cStr, MAX_PATH);
839 break;
842 return hr;
845 static HRESULT WINAPI ISF_Desktop_fnMapColumnToSCID (
846 IShellFolder2 * iface, UINT column, SHCOLUMNID * pscid)
848 IDesktopFolderImpl *This = (IDesktopFolderImpl *)iface;
849 FIXME ("(%p)->(%d %p) stub\n", This, column, pscid);
850 return E_NOTIMPL;
853 static const IShellFolder2Vtbl vt_MCFldr_ShellFolder2 =
855 ISF_Desktop_fnQueryInterface,
856 ISF_Desktop_fnAddRef,
857 ISF_Desktop_fnRelease,
858 ISF_Desktop_fnParseDisplayName,
859 ISF_Desktop_fnEnumObjects,
860 ISF_Desktop_fnBindToObject,
861 ISF_Desktop_fnBindToStorage,
862 ISF_Desktop_fnCompareIDs,
863 ISF_Desktop_fnCreateViewObject,
864 ISF_Desktop_fnGetAttributesOf,
865 ISF_Desktop_fnGetUIObjectOf,
866 ISF_Desktop_fnGetDisplayNameOf,
867 ISF_Desktop_fnSetNameOf,
868 /* ShellFolder2 */
869 ISF_Desktop_fnGetDefaultSearchGUID,
870 ISF_Desktop_fnEnumSearches,
871 ISF_Desktop_fnGetDefaultColumn,
872 ISF_Desktop_fnGetDefaultColumnState,
873 ISF_Desktop_fnGetDetailsEx,
874 ISF_Desktop_fnGetDetailsOf,
875 ISF_Desktop_fnMapColumnToSCID
878 /**************************************************************************
879 * IPersist
881 static HRESULT WINAPI ISF_Desktop_IPersistFolder2_fnQueryInterface(
882 IPersistFolder2 *iface, REFIID riid, LPVOID *ppvObj)
884 IDesktopFolderImpl *This = impl_from_IPersistFolder2( iface );
885 return IShellFolder2_QueryInterface((IShellFolder2*)This, riid, ppvObj);
888 static ULONG WINAPI ISF_Desktop_IPersistFolder2_fnAddRef(
889 IPersistFolder2 *iface)
891 IDesktopFolderImpl *This = impl_from_IPersistFolder2( iface );
892 return IShellFolder2_AddRef((IShellFolder2*)This);
895 static ULONG WINAPI ISF_Desktop_IPersistFolder2_fnRelease(
896 IPersistFolder2 *iface)
898 IDesktopFolderImpl *This = impl_from_IPersistFolder2( iface );
899 return IShellFolder2_Release((IShellFolder2*)This);
902 static HRESULT WINAPI ISF_Desktop_IPersistFolder2_fnGetClassID(
903 IPersistFolder2 *iface, CLSID *clsid)
905 *clsid = CLSID_ShellDesktop;
906 return S_OK;
908 static HRESULT WINAPI ISF_Desktop_IPersistFolder2_fnInitialize(
909 IPersistFolder2 *iface, LPCITEMIDLIST pidl)
911 IDesktopFolderImpl *This = impl_from_IPersistFolder2( iface );
912 FIXME ("(%p)->(%p) stub\n", This, pidl);
913 return E_NOTIMPL;
915 static HRESULT WINAPI ISF_Desktop_IPersistFolder2_fnGetCurFolder(
916 IPersistFolder2 *iface, LPITEMIDLIST *ppidl)
918 IDesktopFolderImpl *This = impl_from_IPersistFolder2( iface );
919 *ppidl = ILClone(This->pidlRoot);
920 return S_OK;
923 static const IPersistFolder2Vtbl vt_IPersistFolder2 =
925 ISF_Desktop_IPersistFolder2_fnQueryInterface,
926 ISF_Desktop_IPersistFolder2_fnAddRef,
927 ISF_Desktop_IPersistFolder2_fnRelease,
928 ISF_Desktop_IPersistFolder2_fnGetClassID,
929 ISF_Desktop_IPersistFolder2_fnInitialize,
930 ISF_Desktop_IPersistFolder2_fnGetCurFolder
933 /**************************************************************************
934 * ISF_Desktop_Constructor
936 HRESULT WINAPI ISF_Desktop_Constructor (
937 IUnknown * pUnkOuter, REFIID riid, LPVOID * ppv)
939 static IDesktopFolderImpl *cached_sf;
940 WCHAR szMyPath[MAX_PATH];
942 TRACE ("unkOut=%p %s\n", pUnkOuter, shdebugstr_guid (riid));
944 if (!ppv)
945 return E_POINTER;
946 if (pUnkOuter)
947 return CLASS_E_NOAGGREGATION;
949 if (!cached_sf)
951 IDesktopFolderImpl *sf;
953 if (!SHGetSpecialFolderPathW( 0, szMyPath, CSIDL_DESKTOPDIRECTORY, TRUE ))
954 return E_UNEXPECTED;
956 sf = LocalAlloc( LMEM_ZEROINIT, sizeof (IDesktopFolderImpl) );
957 if (!sf)
958 return E_OUTOFMEMORY;
960 sf->ref = 1;
961 sf->lpVtbl = &vt_MCFldr_ShellFolder2;
962 sf->lpVtblPF2 = &vt_IPersistFolder2;
963 sf->pidlRoot = _ILCreateDesktop(); /* my qualified pidl */
964 sf->sPathTarget = SHAlloc( (lstrlenW(szMyPath) + 1)*sizeof(WCHAR) );
965 lstrcpyW( sf->sPathTarget, szMyPath );
967 if (InterlockedCompareExchangePointer((void *)&cached_sf, sf, NULL) != NULL)
969 /* some other thread already been here */
970 SHFree( sf->pidlRoot );
971 SHFree( sf->sPathTarget );
972 LocalFree( sf );
976 return IUnknown_QueryInterface( (IShellFolder2*)cached_sf, riid, ppv );