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
24 #include "wine/port.h"
32 #define NONAMELESSUNION
33 #define NONAMELESSSTRUCT
45 #include "enumidlist.h"
47 #include "undocshell.h"
48 #include "shell32_main.h"
51 #include "shellfolder.h"
52 #include "wine/debug.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
67 const IShellFolder2Vtbl
*lpVtbl
;
68 const IPersistVtbl
*lpVtblIPersist
;
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 */
79 static inline IDesktopFolderImpl
*impl_from_IPersist( IPersist
*iface
)
81 return (IDesktopFolderImpl
*)((char*)iface
- FIELD_OFFSET(IDesktopFolderImpl
, lpVtblIPersist
));
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
97 * NOTES supports not IPersistFolder
99 static HRESULT WINAPI
ISF_Desktop_fnQueryInterface(
100 IShellFolder2
* iface
, REFIID riid
, LPVOID
* ppvObj
)
102 IDesktopFolderImpl
*This
= (IDesktopFolderImpl
*)iface
;
104 TRACE ("(%p)->(%s,%p)\n", This
, shdebugstr_guid (riid
), ppvObj
);
108 if (IsEqualIID (riid
, &IID_IUnknown
) ||
109 IsEqualIID (riid
, &IID_IShellFolder
) ||
110 IsEqualIID (riid
, &IID_IShellFolder2
))
114 else if (IsEqualIID (riid
, &IID_IPersist
))
116 *ppvObj
= &This
->lpVtblIPersist
;
121 IUnknown_AddRef ((IUnknown
*) (*ppvObj
));
122 TRACE ("-- Interface: (%p)->(%p)\n", ppvObj
, *ppvObj
);
125 TRACE ("-- Interface: E_NOINTERFACE\n");
126 return E_NOINTERFACE
;
129 static ULONG WINAPI
ISF_Desktop_fnAddRef (IShellFolder2
* iface
)
131 return 2; /* non-heap based object */
134 static ULONG WINAPI
ISF_Desktop_fnRelease (IShellFolder2
* iface
)
136 return 1; /* non-heap based object */
139 /**************************************************************************
140 * ISF_Desktop_fnParseDisplayName
143 * "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}" and "" binds
146 static HRESULT WINAPI
ISF_Desktop_fnParseDisplayName (IShellFolder2
* iface
,
147 HWND hwndOwner
, LPBC pbc
, LPOLESTR lpszDisplayName
,
148 DWORD
* pchEaten
, LPITEMIDLIST
* ppidl
, DWORD
* pdwAttributes
)
150 IDesktopFolderImpl
*This
= (IDesktopFolderImpl
*)iface
;
151 IShellFolder
*shell_folder
= (IShellFolder
*)iface
;
152 WCHAR szElement
[MAX_PATH
];
153 LPCWSTR szNext
= NULL
;
154 LPITEMIDLIST pidlTemp
= NULL
;
159 TRACE ("(%p)->(HWND=%p,%p,%p=%s,%p,pidl=%p,%p)\n",
160 This
, hwndOwner
, pbc
, lpszDisplayName
, debugstr_w(lpszDisplayName
),
161 pchEaten
, ppidl
, pdwAttributes
);
163 if (!ppidl
) return E_INVALIDARG
;
166 if (!lpszDisplayName
) return E_INVALIDARG
;
169 *pchEaten
= 0; /* strange but like the original */
171 urldata
.cbSize
= sizeof(urldata
);
173 if (lpszDisplayName
[0] == ':' && lpszDisplayName
[1] == ':')
175 szNext
= GetNextElementW (lpszDisplayName
, szElement
, MAX_PATH
);
176 TRACE ("-- element: %s\n", debugstr_w (szElement
));
177 SHCLSIDFromStringW (szElement
+ 2, &clsid
);
178 pidlTemp
= _ILCreateGuid (PT_GUID
, &clsid
);
180 else if (PathGetDriveNumberW (lpszDisplayName
) >= 0)
182 /* it's a filesystem path with a drive. Let MyComputer/UnixDosFolder parse it */
183 if (UNIXFS_is_rooted_at_desktop())
184 pidlTemp
= _ILCreateGuid(PT_GUID
, &CLSID_UnixDosFolder
);
186 pidlTemp
= _ILCreateMyComputer ();
187 szNext
= lpszDisplayName
;
189 else if (PathIsUNCW(lpszDisplayName
))
191 pidlTemp
= _ILCreateNetwork();
192 szNext
= lpszDisplayName
;
194 else if( (pidlTemp
= SHELL32_CreatePidlFromBindCtx(pbc
, lpszDisplayName
)) )
199 else if (SUCCEEDED(ParseURLW(lpszDisplayName
, &urldata
)))
201 if (urldata
.nScheme
== URL_SCHEME_SHELL
) /* handle shell: urls */
203 TRACE ("-- shell url: %s\n", debugstr_w(urldata
.pszSuffix
));
204 SHCLSIDFromStringW (urldata
.pszSuffix
+2, &clsid
);
205 pidlTemp
= _ILCreateGuid (PT_GUID
, &clsid
);
208 return IEParseDisplayNameWithBCW(CP_ACP
,lpszDisplayName
,pbc
,ppidl
);
212 /* it's a filesystem path on the desktop. Let a FSFolder parse it */
214 if (*lpszDisplayName
)
216 if (*lpszDisplayName
== '/')
218 /* UNIX paths should be parsed by unixfs */
219 IShellFolder
*unixFS
;
220 hr
= UnixFolder_Constructor(NULL
, &IID_IShellFolder
, (LPVOID
*)&unixFS
);
223 hr
= IShellFolder_ParseDisplayName(unixFS
, NULL
, NULL
,
224 lpszDisplayName
, NULL
, &pidlTemp
, NULL
);
225 IShellFolder_Release(unixFS
);
230 /* build a complete path to create a simple pidl */
231 WCHAR szPath
[MAX_PATH
];
234 lstrcpynW(szPath
, This
->sPathTarget
, MAX_PATH
);
235 pathPtr
= PathAddBackslashW(szPath
);
238 lstrcpynW(pathPtr
, lpszDisplayName
, MAX_PATH
- (pathPtr
- szPath
));
239 hr
= _ILCreateFromPathW(szPath
, &pidlTemp
);
243 /* should never reach here, but for completeness */
244 hr
= HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER
);
249 pidlTemp
= _ILCreateMyComputer();
254 if (SUCCEEDED(hr
) && pidlTemp
)
256 if (szNext
&& *szNext
)
258 hr
= SHELL32_ParseNextElement(iface
, hwndOwner
, pbc
,
259 &pidlTemp
, (LPOLESTR
) szNext
, pchEaten
, pdwAttributes
);
263 if (pdwAttributes
&& *pdwAttributes
)
264 hr
= SHELL32_GetItemAttributes(shell_folder
, pidlTemp
, pdwAttributes
);
270 TRACE ("(%p)->(-- ret=0x%08x)\n", This
, hr
);
275 /**************************************************************************
276 * CreateDesktopEnumList()
278 static const WCHAR Desktop_NameSpaceW
[] = { 'S','O','F','T','W','A','R','E',
279 '\\','M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
280 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\','E','x','p','l',
281 'o','r','e','r','\\','D','e','s','k','t','o','p','\\','N','a','m','e','s','p',
284 static BOOL
CreateDesktopEnumList(IEnumIDList
*list
, DWORD dwFlags
)
287 WCHAR szPath
[MAX_PATH
];
289 TRACE("(%p)->(flags=0x%08x)\n", list
, dwFlags
);
291 /* enumerate the root folders */
292 if (dwFlags
& SHCONTF_FOLDERS
)
297 /* create the pidl for This item */
298 ret
= AddToEnumList(list
, _ILCreateMyComputer());
300 for (i
=0; i
<2; i
++) {
301 if (ret
&& !RegOpenKeyExW(i
== 0 ? HKEY_LOCAL_MACHINE
: HKEY_CURRENT_USER
,
302 Desktop_NameSpaceW
, 0, KEY_READ
, &hkey
))
312 size
= sizeof (iid
) / sizeof (iid
[0]);
313 r
= RegEnumKeyExW(hkey
, i
, iid
, &size
, 0, NULL
, NULL
, NULL
);
314 if (ERROR_SUCCESS
== r
)
316 ret
= AddToEnumList(list
, _ILCreateGuidFromStrW(iid
));
319 else if (ERROR_NO_MORE_ITEMS
== r
)
329 /* enumerate the elements in %windir%\desktop */
330 SHGetSpecialFolderPathW(0, szPath
, CSIDL_DESKTOPDIRECTORY
, FALSE
);
331 ret
= ret
&& CreateFolderEnumList(list
, szPath
, dwFlags
);
336 /**************************************************************************
337 * ISF_Desktop_fnEnumObjects
339 static HRESULT WINAPI
ISF_Desktop_fnEnumObjects (IShellFolder2
* iface
,
340 HWND hwndOwner
, DWORD dwFlags
, LPENUMIDLIST
* ppEnumIDList
)
342 IDesktopFolderImpl
*This
= (IDesktopFolderImpl
*)iface
;
344 TRACE ("(%p)->(HWND=%p flags=0x%08x pplist=%p)\n",
345 This
, hwndOwner
, dwFlags
, ppEnumIDList
);
347 *ppEnumIDList
= IEnumIDList_Constructor();
349 CreateDesktopEnumList(*ppEnumIDList
, dwFlags
);
351 TRACE ("-- (%p)->(new ID List: %p)\n", This
, *ppEnumIDList
);
353 return *ppEnumIDList
? S_OK
: E_OUTOFMEMORY
;
356 /**************************************************************************
357 * ISF_Desktop_fnBindToObject
359 static HRESULT WINAPI
ISF_Desktop_fnBindToObject (IShellFolder2
* iface
,
360 LPCITEMIDLIST pidl
, LPBC pbcReserved
, REFIID riid
, LPVOID
* ppvOut
)
362 IDesktopFolderImpl
*This
= (IDesktopFolderImpl
*)iface
;
364 TRACE ("(%p)->(pidl=%p,%p,%s,%p)\n",
365 This
, pidl
, pbcReserved
, shdebugstr_guid (riid
), ppvOut
);
367 return SHELL32_BindToChild( This
->pidlRoot
, This
->sPathTarget
, pidl
, riid
, ppvOut
);
370 /**************************************************************************
371 * ISF_Desktop_fnBindToStorage
373 static HRESULT WINAPI
ISF_Desktop_fnBindToStorage (IShellFolder2
* iface
,
374 LPCITEMIDLIST pidl
, LPBC pbcReserved
, REFIID riid
, LPVOID
* ppvOut
)
376 IDesktopFolderImpl
*This
= (IDesktopFolderImpl
*)iface
;
378 FIXME ("(%p)->(pidl=%p,%p,%s,%p) stub\n",
379 This
, pidl
, pbcReserved
, shdebugstr_guid (riid
), ppvOut
);
385 /**************************************************************************
386 * ISF_Desktop_fnCompareIDs
388 static HRESULT WINAPI
ISF_Desktop_fnCompareIDs (IShellFolder2
*iface
,
389 LPARAM lParam
, LPCITEMIDLIST pidl1
, LPCITEMIDLIST pidl2
)
391 IDesktopFolderImpl
*This
= (IDesktopFolderImpl
*)iface
;
392 IShellFolder
*shell_folder
= (IShellFolder
*)iface
;
395 TRACE ("(%p)->(0x%08lx,pidl1=%p,pidl2=%p)\n", This
, lParam
, pidl1
, pidl2
);
396 hr
= SHELL32_CompareIDs ( shell_folder
, lParam
, pidl1
, pidl2
);
397 TRACE ("-- 0x%08x\n", hr
);
401 /**************************************************************************
402 * ISF_Desktop_fnCreateViewObject
404 static HRESULT WINAPI
ISF_Desktop_fnCreateViewObject (IShellFolder2
* iface
,
405 HWND hwndOwner
, REFIID riid
, LPVOID
* ppvOut
)
407 IDesktopFolderImpl
*This
= (IDesktopFolderImpl
*)iface
;
408 LPSHELLVIEW pShellView
;
409 HRESULT hr
= E_INVALIDARG
;
411 TRACE ("(%p)->(hwnd=%p,%s,%p)\n",
412 This
, hwndOwner
, shdebugstr_guid (riid
), ppvOut
);
419 if (IsEqualIID (riid
, &IID_IDropTarget
))
421 WARN ("IDropTarget not implemented\n");
424 else if (IsEqualIID (riid
, &IID_IContextMenu
))
426 WARN ("IContextMenu not implemented\n");
429 else if (IsEqualIID (riid
, &IID_IShellView
))
431 pShellView
= IShellView_Constructor ((IShellFolder
*) iface
);
434 hr
= IShellView_QueryInterface (pShellView
, riid
, ppvOut
);
435 IShellView_Release (pShellView
);
438 TRACE ("-- (%p)->(interface=%p)\n", This
, ppvOut
);
442 /**************************************************************************
443 * ISF_Desktop_fnGetAttributesOf
445 static HRESULT WINAPI
ISF_Desktop_fnGetAttributesOf (IShellFolder2
* iface
,
446 UINT cidl
, LPCITEMIDLIST
* apidl
, DWORD
* rgfInOut
)
448 IDesktopFolderImpl
*This
= (IDesktopFolderImpl
*)iface
;
449 IShellFolder
*shell_folder
= (IShellFolder
*)iface
;
451 static const DWORD dwDesktopAttributes
=
452 SFGAO_STORAGE
| SFGAO_HASPROPSHEET
| SFGAO_STORAGEANCESTOR
|
453 SFGAO_FILESYSANCESTOR
| SFGAO_FOLDER
| SFGAO_FILESYSTEM
| SFGAO_HASSUBFOLDER
;
454 static const DWORD dwMyComputerAttributes
=
455 SFGAO_CANRENAME
| SFGAO_CANDELETE
| SFGAO_HASPROPSHEET
|
456 SFGAO_DROPTARGET
| SFGAO_FILESYSANCESTOR
| SFGAO_FOLDER
| SFGAO_HASSUBFOLDER
;
458 TRACE ("(%p)->(cidl=%d apidl=%p mask=%p (0x%08x))\n",
459 This
, cidl
, apidl
, rgfInOut
, rgfInOut
? *rgfInOut
: 0);
470 *rgfInOut
&= dwDesktopAttributes
;
472 while (cidl
> 0 && *apidl
) {
474 if (_ILIsDesktop(*apidl
)) {
475 *rgfInOut
&= dwDesktopAttributes
;
476 } else if (_ILIsMyComputer(*apidl
)) {
477 *rgfInOut
&= dwMyComputerAttributes
;
479 SHELL32_GetItemAttributes ( shell_folder
, *apidl
, rgfInOut
);
485 /* make sure SFGAO_VALIDATE is cleared, some apps depend on that */
486 *rgfInOut
&= ~SFGAO_VALIDATE
;
488 TRACE ("-- result=0x%08x\n", *rgfInOut
);
493 /**************************************************************************
494 * ISF_Desktop_fnGetUIObjectOf
497 * HWND hwndOwner, //[in ] Parent window for any output
498 * UINT cidl, //[in ] array size
499 * LPCITEMIDLIST* apidl, //[in ] simple pidl array
500 * REFIID riid, //[in ] Requested Interface
501 * UINT* prgfInOut, //[ ] reserved
502 * LPVOID* ppvObject) //[out] Resulting Interface
505 static HRESULT WINAPI
ISF_Desktop_fnGetUIObjectOf (IShellFolder2
* iface
,
506 HWND hwndOwner
, UINT cidl
, LPCITEMIDLIST
* apidl
,
507 REFIID riid
, UINT
* prgfInOut
, LPVOID
* ppvOut
)
509 IDesktopFolderImpl
*This
= (IDesktopFolderImpl
*)iface
;
512 IUnknown
*pObj
= NULL
;
513 HRESULT hr
= E_INVALIDARG
;
515 TRACE ("(%p)->(%p,%u,apidl=%p,%s,%p,%p)\n",
516 This
, hwndOwner
, cidl
, apidl
, shdebugstr_guid (riid
), prgfInOut
, ppvOut
);
523 if (IsEqualIID (riid
, &IID_IContextMenu
))
526 pObj
= (LPUNKNOWN
) ISvItemCm_Constructor( (IShellFolder
*) iface
, This
->pidlRoot
, apidl
, cidl
);
528 pObj
= (LPUNKNOWN
) ISvBgCm_Constructor( (IShellFolder
*) iface
, TRUE
);
531 else if (IsEqualIID (riid
, &IID_IDataObject
) && (cidl
>= 1))
533 pObj
= (LPUNKNOWN
) IDataObject_Constructor( hwndOwner
,
534 This
->pidlRoot
, apidl
, cidl
);
537 else if (IsEqualIID (riid
, &IID_IExtractIconA
) && (cidl
== 1))
539 pidl
= ILCombine (This
->pidlRoot
, apidl
[0]);
540 pObj
= (LPUNKNOWN
) IExtractIconA_Constructor (pidl
);
544 else if (IsEqualIID (riid
, &IID_IExtractIconW
) && (cidl
== 1))
546 pidl
= ILCombine (This
->pidlRoot
, apidl
[0]);
547 pObj
= (LPUNKNOWN
) IExtractIconW_Constructor (pidl
);
551 else if (IsEqualIID (riid
, &IID_IDropTarget
) && (cidl
>= 1))
553 hr
= IShellFolder_QueryInterface (iface
,
554 &IID_IDropTarget
, (LPVOID
*) & pObj
);
556 else if ((IsEqualIID(riid
,&IID_IShellLinkW
) ||
557 IsEqualIID(riid
,&IID_IShellLinkA
)) && (cidl
== 1))
559 pidl
= ILCombine (This
->pidlRoot
, apidl
[0]);
560 hr
= IShellLink_ConstructFromFile(NULL
, riid
, pidl
, (LPVOID
*)&pObj
);
566 if (SUCCEEDED(hr
) && !pObj
)
570 TRACE ("(%p)->hr=0x%08x\n", This
, hr
);
574 /**************************************************************************
575 * ISF_Desktop_fnGetDisplayNameOf
578 * special case: pidl = null gives desktop-name back
580 static HRESULT WINAPI
ISF_Desktop_fnGetDisplayNameOf (IShellFolder2
* iface
,
581 LPCITEMIDLIST pidl
, DWORD dwFlags
, LPSTRRET strRet
)
583 IDesktopFolderImpl
*This
= (IDesktopFolderImpl
*)iface
;
587 TRACE ("(%p)->(pidl=%p,0x%08x,%p)\n", This
, pidl
, dwFlags
, strRet
);
593 pszPath
= CoTaskMemAlloc((MAX_PATH
+1) * sizeof(WCHAR
));
595 return E_OUTOFMEMORY
;
597 if (_ILIsDesktop (pidl
))
599 if ((GET_SHGDN_RELATION (dwFlags
) == SHGDN_NORMAL
) &&
600 (GET_SHGDN_FOR (dwFlags
) & SHGDN_FORPARSING
))
601 strcpyW(pszPath
, This
->sPathTarget
);
603 HCR_GetClassNameW(&CLSID_ShellDesktop
, pszPath
, MAX_PATH
);
605 else if (_ILIsPidlSimple (pidl
))
609 if ((clsid
= _ILGetGUIDPointer (pidl
)))
611 if (GET_SHGDN_FOR (dwFlags
) & SHGDN_FORPARSING
)
613 int bWantsForParsing
;
616 * We can only get a filesystem path from a shellfolder if the
617 * value WantsFORPARSING in CLSID\\{...}\\shellfolder exists.
619 * Exception: The MyComputer folder doesn't have this key,
620 * but any other filesystem backed folder it needs it.
622 if (IsEqualIID (clsid
, &CLSID_MyComputer
))
624 bWantsForParsing
= TRUE
;
628 /* get the "WantsFORPARSING" flag from the registry */
629 static const WCHAR clsidW
[] =
630 { 'C','L','S','I','D','\\',0 };
631 static const WCHAR shellfolderW
[] =
632 { '\\','s','h','e','l','l','f','o','l','d','e','r',0 };
633 static const WCHAR wantsForParsingW
[] =
634 { 'W','a','n','t','s','F','o','r','P','a','r','s','i','n',
636 WCHAR szRegPath
[100];
639 lstrcpyW (szRegPath
, clsidW
);
640 SHELL32_GUIDToStringW (clsid
, &szRegPath
[6]);
641 lstrcatW (szRegPath
, shellfolderW
);
642 r
= SHGetValueW(HKEY_CLASSES_ROOT
, szRegPath
,
643 wantsForParsingW
, NULL
, NULL
, NULL
);
644 if (r
== ERROR_SUCCESS
)
645 bWantsForParsing
= TRUE
;
647 bWantsForParsing
= FALSE
;
650 if ((GET_SHGDN_RELATION (dwFlags
) == SHGDN_NORMAL
) &&
654 * we need the filesystem path to the destination folder.
655 * Only the folder itself can know it
657 hr
= SHELL32_GetDisplayNameOfChild (iface
, pidl
, dwFlags
,
663 /* parsing name like ::{...} */
666 SHELL32_GUIDToStringW (clsid
, &pszPath
[2]);
671 /* user friendly name */
672 HCR_GetClassNameW (clsid
, pszPath
, MAX_PATH
);
679 /* file system folder or file rooted at the desktop */
680 if ((GET_SHGDN_FOR(dwFlags
) == SHGDN_FORPARSING
) &&
681 (GET_SHGDN_RELATION(dwFlags
) != SHGDN_INFOLDER
))
683 lstrcpynW(pszPath
, This
->sPathTarget
, MAX_PATH
- 1);
684 PathAddBackslashW(pszPath
);
685 cLen
= lstrlenW(pszPath
);
688 _ILSimpleGetTextW(pidl
, pszPath
+ cLen
, MAX_PATH
- cLen
);
690 if (!_ILIsFolder(pidl
))
691 SHELL_FS_ProcessDisplayFilename(pszPath
, dwFlags
);
696 /* a complex pidl, let the subfolder do the work */
697 hr
= SHELL32_GetDisplayNameOfChild (iface
, pidl
, dwFlags
,
703 /* Win9x always returns ANSI strings, NT always returns Unicode strings */
704 if (GetVersion() & 0x80000000)
706 strRet
->uType
= STRRET_CSTR
;
707 if (!WideCharToMultiByte(CP_ACP
, 0, pszPath
, -1, strRet
->u
.cStr
, MAX_PATH
,
709 strRet
->u
.cStr
[0] = '\0';
710 CoTaskMemFree(pszPath
);
714 strRet
->uType
= STRRET_WSTR
;
715 strRet
->u
.pOleStr
= pszPath
;
719 CoTaskMemFree(pszPath
);
721 TRACE ("-- (%p)->(%s,0x%08x)\n", This
,
722 strRet
->uType
== STRRET_CSTR
? strRet
->u
.cStr
:
723 debugstr_w(strRet
->u
.pOleStr
), hr
);
727 /**************************************************************************
728 * ISF_Desktop_fnSetNameOf
729 * Changes the name of a file object or subfolder, possibly changing its item
730 * identifier in the process.
733 * HWND hwndOwner, //[in ] Owner window for output
734 * LPCITEMIDLIST pidl, //[in ] simple pidl of item to change
735 * LPCOLESTR lpszName, //[in ] the items new display name
736 * DWORD dwFlags, //[in ] SHGNO formatting flags
737 * LPITEMIDLIST* ppidlOut) //[out] simple pidl returned
739 static HRESULT WINAPI
ISF_Desktop_fnSetNameOf (IShellFolder2
* iface
,
740 HWND hwndOwner
, LPCITEMIDLIST pidl
, /* simple pidl */
741 LPCOLESTR lpName
, DWORD dwFlags
, LPITEMIDLIST
* pPidlOut
)
743 IDesktopFolderImpl
*This
= (IDesktopFolderImpl
*)iface
;
745 FIXME ("(%p)->(%p,pidl=%p,%s,%u,%p) stub\n", This
, hwndOwner
, pidl
,
746 debugstr_w (lpName
), dwFlags
, pPidlOut
);
751 static HRESULT WINAPI
ISF_Desktop_fnGetDefaultSearchGUID(IShellFolder2
*iface
,
754 IDesktopFolderImpl
*This
= (IDesktopFolderImpl
*)iface
;
755 FIXME ("(%p)->(%p) stub\n", This
, pguid
);
759 static HRESULT WINAPI
ISF_Desktop_fnEnumSearches (IShellFolder2
*iface
,
760 IEnumExtraSearch
** ppenum
)
762 IDesktopFolderImpl
*This
= (IDesktopFolderImpl
*)iface
;
763 FIXME ("(%p)->(%p) stub\n", This
, ppenum
);
767 static HRESULT WINAPI
ISF_Desktop_fnGetDefaultColumn (IShellFolder2
* iface
,
768 DWORD reserved
, ULONG
* pSort
, ULONG
* pDisplay
)
770 IDesktopFolderImpl
*This
= (IDesktopFolderImpl
*)iface
;
772 TRACE ("(%p)->(%d %p %p)\n", This
, reserved
, pSort
, pDisplay
);
781 static HRESULT WINAPI
ISF_Desktop_fnGetDefaultColumnState (
782 IShellFolder2
* iface
, UINT iColumn
, DWORD
* pcsFlags
)
784 IDesktopFolderImpl
*This
= (IDesktopFolderImpl
*)iface
;
786 TRACE ("(%p)->(%d %p)\n", This
, iColumn
, pcsFlags
);
788 if (!pcsFlags
|| iColumn
>= DESKTOPSHELLVIEWCOLUMNS
)
791 *pcsFlags
= desktop_header
[iColumn
].pcsFlags
;
796 static HRESULT WINAPI
ISF_Desktop_fnGetDetailsEx (IShellFolder2
* iface
,
797 LPCITEMIDLIST pidl
, const SHCOLUMNID
* pscid
, VARIANT
* pv
)
799 IDesktopFolderImpl
*This
= (IDesktopFolderImpl
*)iface
;
800 FIXME ("(%p)->(%p %p %p) stub\n", This
, pidl
, pscid
, pv
);
804 static HRESULT WINAPI
ISF_Desktop_fnGetDetailsOf (IShellFolder2
* iface
,
805 LPCITEMIDLIST pidl
, UINT iColumn
, SHELLDETAILS
* psd
)
807 IDesktopFolderImpl
*This
= (IDesktopFolderImpl
*)iface
;
811 TRACE ("(%p)->(%p %i %p)\n", This
, pidl
, iColumn
, psd
);
813 if (!psd
|| iColumn
>= DESKTOPSHELLVIEWCOLUMNS
)
817 return SHELL32_GetColumnDetails(desktop_header
, iColumn
, psd
);
819 /* the data from the pidl */
820 psd
->str
.uType
= STRRET_CSTR
;
824 hr
= IShellFolder_GetDisplayNameOf(iface
, pidl
,
825 SHGDN_NORMAL
| SHGDN_INFOLDER
, &psd
->str
);
828 _ILGetFileSize (pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
831 _ILGetFileType (pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
834 _ILGetFileDate (pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
836 case 4: /* attributes */
837 _ILGetFileAttributes (pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
844 static HRESULT WINAPI
ISF_Desktop_fnMapColumnToSCID (
845 IShellFolder2
* iface
, UINT column
, SHCOLUMNID
* pscid
)
847 IDesktopFolderImpl
*This
= (IDesktopFolderImpl
*)iface
;
848 FIXME ("(%p)->(%d %p) stub\n", This
, column
, pscid
);
852 static const IShellFolder2Vtbl vt_MCFldr_ShellFolder2
=
854 ISF_Desktop_fnQueryInterface
,
855 ISF_Desktop_fnAddRef
,
856 ISF_Desktop_fnRelease
,
857 ISF_Desktop_fnParseDisplayName
,
858 ISF_Desktop_fnEnumObjects
,
859 ISF_Desktop_fnBindToObject
,
860 ISF_Desktop_fnBindToStorage
,
861 ISF_Desktop_fnCompareIDs
,
862 ISF_Desktop_fnCreateViewObject
,
863 ISF_Desktop_fnGetAttributesOf
,
864 ISF_Desktop_fnGetUIObjectOf
,
865 ISF_Desktop_fnGetDisplayNameOf
,
866 ISF_Desktop_fnSetNameOf
,
868 ISF_Desktop_fnGetDefaultSearchGUID
,
869 ISF_Desktop_fnEnumSearches
,
870 ISF_Desktop_fnGetDefaultColumn
,
871 ISF_Desktop_fnGetDefaultColumnState
,
872 ISF_Desktop_fnGetDetailsEx
,
873 ISF_Desktop_fnGetDetailsOf
,
874 ISF_Desktop_fnMapColumnToSCID
877 /**************************************************************************
880 static HRESULT WINAPI
ISF_Desktop_IPersist_fnQueryInterface(
881 IPersist
*iface
, REFIID riid
, LPVOID
*ppvObj
)
883 IDesktopFolderImpl
*This
= impl_from_IPersist( iface
);
884 return IShellFolder2_QueryInterface((IShellFolder2
*)This
, riid
, ppvObj
);
887 static ULONG WINAPI
ISF_Desktop_IPersist_fnAddRef(IPersist
*iface
)
889 IDesktopFolderImpl
*This
= impl_from_IPersist( iface
);
890 return IShellFolder2_AddRef((IShellFolder2
*)This
);
893 static ULONG WINAPI
ISF_Desktop_IPersist_fnRelease(IPersist
*iface
)
895 IDesktopFolderImpl
*This
= impl_from_IPersist( iface
);
896 return IShellFolder2_Release((IShellFolder2
*)This
);
899 static HRESULT WINAPI
ISF_Desktop_IPersist_fnGetClassID(IPersist
*iface
, CLSID
*clsid
)
901 *clsid
= CLSID_ShellDesktop
;
905 static const IPersistVtbl vt_IPersist
=
907 ISF_Desktop_IPersist_fnQueryInterface
,
908 ISF_Desktop_IPersist_fnAddRef
,
909 ISF_Desktop_IPersist_fnRelease
,
910 ISF_Desktop_IPersist_fnGetClassID
913 /**************************************************************************
914 * ISF_Desktop_Constructor
916 HRESULT WINAPI
ISF_Desktop_Constructor (
917 IUnknown
* pUnkOuter
, REFIID riid
, LPVOID
* ppv
)
919 static IDesktopFolderImpl
*cached_sf
;
920 WCHAR szMyPath
[MAX_PATH
];
922 TRACE ("unkOut=%p %s\n", pUnkOuter
, shdebugstr_guid (riid
));
927 return CLASS_E_NOAGGREGATION
;
931 IDesktopFolderImpl
*sf
;
933 if (!SHGetSpecialFolderPathW( 0, szMyPath
, CSIDL_DESKTOPDIRECTORY
, TRUE
))
936 sf
= LocalAlloc( LMEM_ZEROINIT
, sizeof (IDesktopFolderImpl
) );
938 return E_OUTOFMEMORY
;
941 sf
->lpVtbl
= &vt_MCFldr_ShellFolder2
;
942 sf
->lpVtblIPersist
= &vt_IPersist
;
943 sf
->pidlRoot
= _ILCreateDesktop(); /* my qualified pidl */
944 sf
->sPathTarget
= SHAlloc( (lstrlenW(szMyPath
) + 1)*sizeof(WCHAR
) );
945 lstrcpyW( sf
->sPathTarget
, szMyPath
);
947 if (InterlockedCompareExchangePointer((void *)&cached_sf
, sf
, NULL
) != NULL
)
949 /* some other thread already been here */
950 SHFree( sf
->pidlRoot
);
951 SHFree( sf
->sPathTarget
);
956 return IUnknown_QueryInterface( (IShellFolder2
*)cached_sf
, riid
, ppv
);