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 IPersistFolder2Vtbl
*lpVtblPF2
;
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_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
);
107 if (IsEqualIID (riid
, &IID_IUnknown
) ||
108 IsEqualIID (riid
, &IID_IShellFolder
) ||
109 IsEqualIID (riid
, &IID_IShellFolder2
))
113 else if (IsEqualIID (riid
, &IID_IPersist
) ||
114 IsEqualIID (riid
, &IID_IPersistFolder
) ||
115 IsEqualIID (riid
, &IID_IPersistFolder2
))
117 *ppvObj
= &This
->lpVtblPF2
;
122 IUnknown_AddRef ((IUnknown
*) (*ppvObj
));
123 TRACE ("-- Interface: (%p)->(%p)\n", ppvObj
, *ppvObj
);
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
144 * "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}" and "" binds
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
;
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
;
167 if (!lpszDisplayName
) return E_INVALIDARG
;
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
);
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
)) )
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
);
209 return IEParseDisplayNameWithBCW(CP_ACP
,lpszDisplayName
,pbc
,ppidl
);
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
);
224 hr
= IShellFolder_ParseDisplayName(unixFS
, NULL
, NULL
,
225 lpszDisplayName
, NULL
, &pidlTemp
, NULL
);
226 IShellFolder_Release(unixFS
);
231 /* build a complete path to create a simple pidl */
232 WCHAR szPath
[MAX_PATH
];
235 lstrcpynW(szPath
, This
->sPathTarget
, MAX_PATH
);
236 pathPtr
= PathAddBackslashW(szPath
);
239 lstrcpynW(pathPtr
, lpszDisplayName
, MAX_PATH
- (pathPtr
- szPath
));
240 hr
= _ILCreateFromPathW(szPath
, &pidlTemp
);
244 /* should never reach here, but for completeness */
245 hr
= HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER
);
250 pidlTemp
= _ILCreateMyComputer();
255 if (SUCCEEDED(hr
) && pidlTemp
)
257 if (szNext
&& *szNext
)
259 hr
= SHELL32_ParseNextElement(iface
, hwndOwner
, pbc
,
260 &pidlTemp
, (LPOLESTR
) szNext
, pchEaten
, pdwAttributes
);
264 if (pdwAttributes
&& *pdwAttributes
)
265 hr
= SHELL32_GetItemAttributes(shell_folder
, pidlTemp
, pdwAttributes
);
271 TRACE ("(%p)->(-- ret=0x%08x)\n", This
, 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',
285 static BOOL
CreateDesktopEnumList(IEnumIDList
*list
, DWORD dwFlags
)
288 WCHAR szPath
[MAX_PATH
];
290 TRACE("(%p)->(flags=0x%08x)\n", list
, dwFlags
);
292 /* enumerate the root folders */
293 if (dwFlags
& SHCONTF_FOLDERS
)
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
))
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
));
320 else if (ERROR_NO_MORE_ITEMS
== r
)
330 /* enumerate the elements in %windir%\desktop */
331 SHGetSpecialFolderPathW(0, szPath
, CSIDL_DESKTOPDIRECTORY
, FALSE
);
332 ret
= ret
&& CreateFolderEnumList(list
, szPath
, dwFlags
);
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();
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
);
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
;
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
);
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
);
420 if (IsEqualIID (riid
, &IID_IDropTarget
))
422 WARN ("IDropTarget not implemented\n");
425 else if (IsEqualIID (riid
, &IID_IContextMenu
))
427 WARN ("IContextMenu not implemented\n");
430 else if (IsEqualIID (riid
, &IID_IShellView
))
432 pShellView
= IShellView_Constructor ((IShellFolder
*) iface
);
435 hr
= IShellView_QueryInterface (pShellView
, riid
, ppvOut
);
436 IShellView_Release (pShellView
);
439 TRACE ("-- (%p)->(interface=%p)\n", This
, ppvOut
);
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);
471 *rgfInOut
&= dwDesktopAttributes
;
473 while (cidl
> 0 && *apidl
) {
475 if (_ILIsDesktop(*apidl
)) {
476 *rgfInOut
&= dwDesktopAttributes
;
477 } else if (_ILIsMyComputer(*apidl
)) {
478 *rgfInOut
&= dwMyComputerAttributes
;
480 SHELL32_GetItemAttributes ( shell_folder
, *apidl
, rgfInOut
);
486 /* make sure SFGAO_VALIDATE is cleared, some apps depend on that */
487 *rgfInOut
&= ~SFGAO_VALIDATE
;
489 TRACE ("-- result=0x%08x\n", *rgfInOut
);
494 /**************************************************************************
495 * ISF_Desktop_fnGetUIObjectOf
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
;
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
);
524 if (IsEqualIID (riid
, &IID_IContextMenu
))
527 pObj
= (LPUNKNOWN
) ISvItemCm_Constructor( (IShellFolder
*) iface
, This
->pidlRoot
, apidl
, cidl
);
529 pObj
= (LPUNKNOWN
) ISvBgCm_Constructor( (IShellFolder
*) iface
, TRUE
);
532 else if (IsEqualIID (riid
, &IID_IDataObject
) && (cidl
>= 1))
534 pObj
= (LPUNKNOWN
) IDataObject_Constructor( hwndOwner
,
535 This
->pidlRoot
, apidl
, cidl
);
538 else if (IsEqualIID (riid
, &IID_IExtractIconA
) && (cidl
== 1))
540 pidl
= ILCombine (This
->pidlRoot
, apidl
[0]);
541 pObj
= (LPUNKNOWN
) IExtractIconA_Constructor (pidl
);
545 else if (IsEqualIID (riid
, &IID_IExtractIconW
) && (cidl
== 1))
547 pidl
= ILCombine (This
->pidlRoot
, apidl
[0]);
548 pObj
= (LPUNKNOWN
) IExtractIconW_Constructor (pidl
);
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
);
567 if (SUCCEEDED(hr
) && !pObj
)
571 TRACE ("(%p)->hr=0x%08x\n", This
, hr
);
575 /**************************************************************************
576 * ISF_Desktop_fnGetDisplayNameOf
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
;
588 TRACE ("(%p)->(pidl=%p,0x%08x,%p)\n", This
, pidl
, dwFlags
, strRet
);
594 pszPath
= CoTaskMemAlloc((MAX_PATH
+1) * sizeof(WCHAR
));
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
);
604 HCR_GetClassNameW(&CLSID_ShellDesktop
, pszPath
, MAX_PATH
);
606 else if (_ILIsPidlSimple (pidl
))
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
;
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',
637 WCHAR szRegPath
[100];
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
;
648 bWantsForParsing
= FALSE
;
651 if ((GET_SHGDN_RELATION (dwFlags
) == SHGDN_NORMAL
) &&
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
,
664 /* parsing name like ::{...} */
667 SHELL32_GUIDToStringW (clsid
, &pszPath
[2]);
672 /* user friendly name */
673 HCR_GetClassNameW (clsid
, pszPath
, MAX_PATH
);
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
);
697 /* a complex pidl, let the subfolder do the work */
698 hr
= SHELL32_GetDisplayNameOfChild (iface
, pidl
, dwFlags
,
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
,
710 strRet
->u
.cStr
[0] = '\0';
711 CoTaskMemFree(pszPath
);
715 strRet
->uType
= STRRET_WSTR
;
716 strRet
->u
.pOleStr
= pszPath
;
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
);
728 /**************************************************************************
729 * ISF_Desktop_fnSetNameOf
730 * Changes the name of a file object or subfolder, possibly changing its item
731 * identifier in the process.
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
);
752 static HRESULT WINAPI
ISF_Desktop_fnGetDefaultSearchGUID(IShellFolder2
*iface
,
755 IDesktopFolderImpl
*This
= (IDesktopFolderImpl
*)iface
;
756 FIXME ("(%p)->(%p) stub\n", This
, pguid
);
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
);
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
);
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
)
792 *pcsFlags
= desktop_header
[iColumn
].pcsFlags
;
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
);
805 static HRESULT WINAPI
ISF_Desktop_fnGetDetailsOf (IShellFolder2
* iface
,
806 LPCITEMIDLIST pidl
, UINT iColumn
, SHELLDETAILS
* psd
)
808 IDesktopFolderImpl
*This
= (IDesktopFolderImpl
*)iface
;
812 TRACE ("(%p)->(%p %i %p)\n", This
, pidl
, iColumn
, psd
);
814 if (!psd
|| iColumn
>= DESKTOPSHELLVIEWCOLUMNS
)
818 return SHELL32_GetColumnDetails(desktop_header
, iColumn
, psd
);
820 /* the data from the pidl */
821 psd
->str
.uType
= STRRET_CSTR
;
825 hr
= IShellFolder_GetDisplayNameOf(iface
, pidl
,
826 SHGDN_NORMAL
| SHGDN_INFOLDER
, &psd
->str
);
829 _ILGetFileSize (pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
832 _ILGetFileType (pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
835 _ILGetFileDate (pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
837 case 4: /* attributes */
838 _ILGetFileAttributes (pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
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
);
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
,
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 /**************************************************************************
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
;
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
);
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
);
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
));
947 return CLASS_E_NOAGGREGATION
;
951 IDesktopFolderImpl
*sf
;
953 if (!SHGetSpecialFolderPathW( 0, szMyPath
, CSIDL_DESKTOPDIRECTORY
, TRUE
))
956 sf
= LocalAlloc( LMEM_ZEROINIT
, sizeof (IDesktopFolderImpl
) );
958 return E_OUTOFMEMORY
;
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
);
976 return IUnknown_QueryInterface( (IShellFolder2
*)cached_sf
, riid
, ppv
);