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