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 DesktopSFHeader
[] = {
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 5
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
;
158 TRACE ("(%p)->(HWND=%p,%p,%p=%s,%p,pidl=%p,%p)\n",
159 This
, hwndOwner
, pbc
, lpszDisplayName
, debugstr_w(lpszDisplayName
),
160 pchEaten
, ppidl
, pdwAttributes
);
162 if (!ppidl
) return E_INVALIDARG
;
165 if (!lpszDisplayName
) return E_INVALIDARG
;
168 *pchEaten
= 0; /* strange but like the original */
170 if (lpszDisplayName
[0] == ':' && lpszDisplayName
[1] == ':')
172 szNext
= GetNextElementW (lpszDisplayName
, szElement
, MAX_PATH
);
173 TRACE ("-- element: %s\n", debugstr_w (szElement
));
174 SHCLSIDFromStringW (szElement
+ 2, &clsid
);
175 pidlTemp
= _ILCreateGuid (PT_GUID
, &clsid
);
177 else if (PathGetDriveNumberW (lpszDisplayName
) >= 0)
179 /* it's a filesystem path with a drive. Let MyComputer/UnixDosFolder parse it */
180 if (UNIXFS_is_rooted_at_desktop())
181 pidlTemp
= _ILCreateGuid(PT_GUID
, &CLSID_UnixDosFolder
);
183 pidlTemp
= _ILCreateMyComputer ();
184 szNext
= lpszDisplayName
;
186 else if (PathIsUNCW(lpszDisplayName
))
188 pidlTemp
= _ILCreateNetwork();
189 szNext
= lpszDisplayName
;
191 else if( (pidlTemp
= SHELL32_CreatePidlFromBindCtx(pbc
, lpszDisplayName
)) )
196 else if (strchrW(lpszDisplayName
,':'))
200 urldata
.cbSize
= sizeof(urldata
);
201 ParseURLW(lpszDisplayName
,&urldata
);
203 if (urldata
.nScheme
== URL_SCHEME_SHELL
) /* handle shell: urls */
205 TRACE ("-- shell url: %s\n", debugstr_w(urldata
.pszSuffix
));
206 SHCLSIDFromStringW (urldata
.pszSuffix
+2, &clsid
);
207 pidlTemp
= _ILCreateGuid (PT_GUID
, &clsid
);
210 return IEParseDisplayNameWithBCW(CP_ACP
,lpszDisplayName
,pbc
,ppidl
);
214 /* it's a filesystem path on the desktop. Let a FSFolder parse it */
216 if (*lpszDisplayName
)
218 WCHAR szPath
[MAX_PATH
];
221 /* build a complete path to create a simple pidl */
222 lstrcpynW(szPath
, This
->sPathTarget
, MAX_PATH
);
223 pathPtr
= PathAddBackslashW(szPath
);
226 lstrcpynW(pathPtr
, lpszDisplayName
, MAX_PATH
- (pathPtr
- szPath
));
227 hr
= _ILCreateFromPathW(szPath
, &pidlTemp
);
231 /* should never reach here, but for completeness */
232 hr
= HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER
);
236 pidlTemp
= _ILCreateMyComputer();
241 if (SUCCEEDED(hr
) && pidlTemp
)
243 if (szNext
&& *szNext
)
245 hr
= SHELL32_ParseNextElement(iface
, hwndOwner
, pbc
,
246 &pidlTemp
, (LPOLESTR
) szNext
, pchEaten
, pdwAttributes
);
250 if (pdwAttributes
&& *pdwAttributes
)
251 hr
= SHELL32_GetItemAttributes(shell_folder
, pidlTemp
, pdwAttributes
);
257 TRACE ("(%p)->(-- ret=0x%08x)\n", This
, hr
);
262 /**************************************************************************
263 * CreateDesktopEnumList()
265 static const WCHAR Desktop_NameSpaceW
[] = { 'S','O','F','T','W','A','R','E',
266 '\\','M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
267 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\','E','x','p','l',
268 'o','r','e','r','\\','D','e','s','k','t','o','p','\\','N','a','m','e','s','p',
271 static BOOL
CreateDesktopEnumList(IEnumIDList
*list
, DWORD dwFlags
)
274 WCHAR szPath
[MAX_PATH
];
276 TRACE("(%p)->(flags=0x%08x)\n", list
, dwFlags
);
278 /* enumerate the root folders */
279 if (dwFlags
& SHCONTF_FOLDERS
)
284 /* create the pidl for This item */
285 ret
= AddToEnumList(list
, _ILCreateMyComputer());
287 for (i
=0; i
<2; i
++) {
288 if (ret
&& !RegOpenKeyExW(i
== 0 ? HKEY_LOCAL_MACHINE
: HKEY_CURRENT_USER
,
289 Desktop_NameSpaceW
, 0, KEY_READ
, &hkey
))
299 size
= sizeof (iid
) / sizeof (iid
[0]);
300 r
= RegEnumKeyExW(hkey
, i
, iid
, &size
, 0, NULL
, NULL
, NULL
);
301 if (ERROR_SUCCESS
== r
)
303 ret
= AddToEnumList(list
, _ILCreateGuidFromStrW(iid
));
306 else if (ERROR_NO_MORE_ITEMS
== r
)
316 /* enumerate the elements in %windir%\desktop */
317 SHGetSpecialFolderPathW(0, szPath
, CSIDL_DESKTOPDIRECTORY
, FALSE
);
318 ret
= ret
&& CreateFolderEnumList(list
, szPath
, dwFlags
);
323 /**************************************************************************
324 * ISF_Desktop_fnEnumObjects
326 static HRESULT WINAPI
ISF_Desktop_fnEnumObjects (IShellFolder2
* iface
,
327 HWND hwndOwner
, DWORD dwFlags
, LPENUMIDLIST
* ppEnumIDList
)
329 IDesktopFolderImpl
*This
= (IDesktopFolderImpl
*)iface
;
331 TRACE ("(%p)->(HWND=%p flags=0x%08x pplist=%p)\n",
332 This
, hwndOwner
, dwFlags
, ppEnumIDList
);
334 *ppEnumIDList
= IEnumIDList_Constructor();
336 CreateDesktopEnumList(*ppEnumIDList
, dwFlags
);
338 TRACE ("-- (%p)->(new ID List: %p)\n", This
, *ppEnumIDList
);
340 return *ppEnumIDList
? S_OK
: E_OUTOFMEMORY
;
343 /**************************************************************************
344 * ISF_Desktop_fnBindToObject
346 static HRESULT WINAPI
ISF_Desktop_fnBindToObject (IShellFolder2
* iface
,
347 LPCITEMIDLIST pidl
, LPBC pbcReserved
, REFIID riid
, LPVOID
* ppvOut
)
349 IDesktopFolderImpl
*This
= (IDesktopFolderImpl
*)iface
;
351 TRACE ("(%p)->(pidl=%p,%p,%s,%p)\n",
352 This
, pidl
, pbcReserved
, shdebugstr_guid (riid
), ppvOut
);
354 return SHELL32_BindToChild( This
->pidlRoot
, This
->sPathTarget
, pidl
, riid
, ppvOut
);
357 /**************************************************************************
358 * ISF_Desktop_fnBindToStorage
360 static HRESULT WINAPI
ISF_Desktop_fnBindToStorage (IShellFolder2
* iface
,
361 LPCITEMIDLIST pidl
, LPBC pbcReserved
, REFIID riid
, LPVOID
* ppvOut
)
363 IDesktopFolderImpl
*This
= (IDesktopFolderImpl
*)iface
;
365 FIXME ("(%p)->(pidl=%p,%p,%s,%p) stub\n",
366 This
, pidl
, pbcReserved
, shdebugstr_guid (riid
), ppvOut
);
372 /**************************************************************************
373 * ISF_Desktop_fnCompareIDs
375 static HRESULT WINAPI
ISF_Desktop_fnCompareIDs (IShellFolder2
*iface
,
376 LPARAM lParam
, LPCITEMIDLIST pidl1
, LPCITEMIDLIST pidl2
)
378 IDesktopFolderImpl
*This
= (IDesktopFolderImpl
*)iface
;
379 IShellFolder
*shell_folder
= (IShellFolder
*)iface
;
382 TRACE ("(%p)->(0x%08lx,pidl1=%p,pidl2=%p)\n", This
, lParam
, pidl1
, pidl2
);
383 hr
= SHELL32_CompareIDs ( shell_folder
, lParam
, pidl1
, pidl2
);
384 TRACE ("-- 0x%08x\n", hr
);
388 /**************************************************************************
389 * ISF_Desktop_fnCreateViewObject
391 static HRESULT WINAPI
ISF_Desktop_fnCreateViewObject (IShellFolder2
* iface
,
392 HWND hwndOwner
, REFIID riid
, LPVOID
* ppvOut
)
394 IDesktopFolderImpl
*This
= (IDesktopFolderImpl
*)iface
;
395 LPSHELLVIEW pShellView
;
396 HRESULT hr
= E_INVALIDARG
;
398 TRACE ("(%p)->(hwnd=%p,%s,%p)\n",
399 This
, hwndOwner
, shdebugstr_guid (riid
), ppvOut
);
406 if (IsEqualIID (riid
, &IID_IDropTarget
))
408 WARN ("IDropTarget not implemented\n");
411 else if (IsEqualIID (riid
, &IID_IContextMenu
))
413 WARN ("IContextMenu not implemented\n");
416 else if (IsEqualIID (riid
, &IID_IShellView
))
418 pShellView
= IShellView_Constructor ((IShellFolder
*) iface
);
421 hr
= IShellView_QueryInterface (pShellView
, riid
, ppvOut
);
422 IShellView_Release (pShellView
);
425 TRACE ("-- (%p)->(interface=%p)\n", This
, ppvOut
);
429 /**************************************************************************
430 * ISF_Desktop_fnGetAttributesOf
432 static HRESULT WINAPI
ISF_Desktop_fnGetAttributesOf (IShellFolder2
* iface
,
433 UINT cidl
, LPCITEMIDLIST
* apidl
, DWORD
* rgfInOut
)
435 IDesktopFolderImpl
*This
= (IDesktopFolderImpl
*)iface
;
436 IShellFolder
*shell_folder
= (IShellFolder
*)iface
;
438 static const DWORD dwDesktopAttributes
=
439 SFGAO_STORAGE
| SFGAO_HASPROPSHEET
| SFGAO_STORAGEANCESTOR
|
440 SFGAO_FILESYSANCESTOR
| SFGAO_FOLDER
| SFGAO_FILESYSTEM
| SFGAO_HASSUBFOLDER
;
441 static const DWORD dwMyComputerAttributes
=
442 SFGAO_CANRENAME
| SFGAO_CANDELETE
| SFGAO_HASPROPSHEET
|
443 SFGAO_DROPTARGET
| SFGAO_FILESYSANCESTOR
| SFGAO_FOLDER
| SFGAO_HASSUBFOLDER
;
445 TRACE ("(%p)->(cidl=%d apidl=%p mask=%p (0x%08x))\n",
446 This
, cidl
, apidl
, rgfInOut
, rgfInOut
? *rgfInOut
: 0);
457 *rgfInOut
&= dwDesktopAttributes
;
459 while (cidl
> 0 && *apidl
) {
461 if (_ILIsDesktop(*apidl
)) {
462 *rgfInOut
&= dwDesktopAttributes
;
463 } else if (_ILIsMyComputer(*apidl
)) {
464 *rgfInOut
&= dwMyComputerAttributes
;
466 SHELL32_GetItemAttributes ( shell_folder
, *apidl
, rgfInOut
);
472 /* make sure SFGAO_VALIDATE is cleared, some apps depend on that */
473 *rgfInOut
&= ~SFGAO_VALIDATE
;
475 TRACE ("-- result=0x%08x\n", *rgfInOut
);
480 /**************************************************************************
481 * ISF_Desktop_fnGetUIObjectOf
484 * HWND hwndOwner, //[in ] Parent window for any output
485 * UINT cidl, //[in ] array size
486 * LPCITEMIDLIST* apidl, //[in ] simple pidl array
487 * REFIID riid, //[in ] Requested Interface
488 * UINT* prgfInOut, //[ ] reserved
489 * LPVOID* ppvObject) //[out] Resulting Interface
492 static HRESULT WINAPI
ISF_Desktop_fnGetUIObjectOf (IShellFolder2
* iface
,
493 HWND hwndOwner
, UINT cidl
, LPCITEMIDLIST
* apidl
,
494 REFIID riid
, UINT
* prgfInOut
, LPVOID
* ppvOut
)
496 IDesktopFolderImpl
*This
= (IDesktopFolderImpl
*)iface
;
499 IUnknown
*pObj
= NULL
;
500 HRESULT hr
= E_INVALIDARG
;
502 TRACE ("(%p)->(%p,%u,apidl=%p,%s,%p,%p)\n",
503 This
, hwndOwner
, cidl
, apidl
, shdebugstr_guid (riid
), prgfInOut
, ppvOut
);
510 if (IsEqualIID (riid
, &IID_IContextMenu
))
513 pObj
= (LPUNKNOWN
) ISvItemCm_Constructor( (IShellFolder
*) iface
, This
->pidlRoot
, apidl
, cidl
);
515 pObj
= (LPUNKNOWN
) ISvBgCm_Constructor( (IShellFolder
*) iface
, TRUE
);
518 else if (IsEqualIID (riid
, &IID_IDataObject
) && (cidl
>= 1))
520 pObj
= (LPUNKNOWN
) IDataObject_Constructor( hwndOwner
,
521 This
->pidlRoot
, apidl
, cidl
);
524 else if (IsEqualIID (riid
, &IID_IExtractIconA
) && (cidl
== 1))
526 pidl
= ILCombine (This
->pidlRoot
, apidl
[0]);
527 pObj
= (LPUNKNOWN
) IExtractIconA_Constructor (pidl
);
531 else if (IsEqualIID (riid
, &IID_IExtractIconW
) && (cidl
== 1))
533 pidl
= ILCombine (This
->pidlRoot
, apidl
[0]);
534 pObj
= (LPUNKNOWN
) IExtractIconW_Constructor (pidl
);
538 else if (IsEqualIID (riid
, &IID_IDropTarget
) && (cidl
>= 1))
540 hr
= IShellFolder_QueryInterface (iface
,
541 &IID_IDropTarget
, (LPVOID
*) & pObj
);
543 else if ((IsEqualIID(riid
,&IID_IShellLinkW
) ||
544 IsEqualIID(riid
,&IID_IShellLinkA
)) && (cidl
== 1))
546 pidl
= ILCombine (This
->pidlRoot
, apidl
[0]);
547 hr
= IShellLink_ConstructFromFile(NULL
, riid
, pidl
, (LPVOID
*)&pObj
);
553 if (SUCCEEDED(hr
) && !pObj
)
557 TRACE ("(%p)->hr=0x%08x\n", This
, hr
);
561 /**************************************************************************
562 * ISF_Desktop_fnGetDisplayNameOf
565 * special case: pidl = null gives desktop-name back
567 static HRESULT WINAPI
ISF_Desktop_fnGetDisplayNameOf (IShellFolder2
* iface
,
568 LPCITEMIDLIST pidl
, DWORD dwFlags
, LPSTRRET strRet
)
570 IDesktopFolderImpl
*This
= (IDesktopFolderImpl
*)iface
;
574 TRACE ("(%p)->(pidl=%p,0x%08x,%p)\n", This
, pidl
, dwFlags
, strRet
);
580 pszPath
= CoTaskMemAlloc((MAX_PATH
+1) * sizeof(WCHAR
));
582 return E_OUTOFMEMORY
;
584 if (_ILIsDesktop (pidl
))
586 if ((GET_SHGDN_RELATION (dwFlags
) == SHGDN_NORMAL
) &&
587 (GET_SHGDN_FOR (dwFlags
) & SHGDN_FORPARSING
))
588 strcpyW(pszPath
, This
->sPathTarget
);
590 HCR_GetClassNameW(&CLSID_ShellDesktop
, pszPath
, MAX_PATH
);
592 else if (_ILIsPidlSimple (pidl
))
596 if ((clsid
= _ILGetGUIDPointer (pidl
)))
598 if (GET_SHGDN_FOR (dwFlags
) & SHGDN_FORPARSING
)
600 int bWantsForParsing
;
603 * We can only get a filesystem path from a shellfolder if the
604 * value WantsFORPARSING in CLSID\\{...}\\shellfolder exists.
606 * Exception: The MyComputer folder doesn't have this key,
607 * but any other filesystem backed folder it needs it.
609 if (IsEqualIID (clsid
, &CLSID_MyComputer
))
611 bWantsForParsing
= TRUE
;
615 /* get the "WantsFORPARSING" flag from the registry */
616 static const WCHAR clsidW
[] =
617 { 'C','L','S','I','D','\\',0 };
618 static const WCHAR shellfolderW
[] =
619 { '\\','s','h','e','l','l','f','o','l','d','e','r',0 };
620 static const WCHAR wantsForParsingW
[] =
621 { 'W','a','n','t','s','F','o','r','P','a','r','s','i','n',
623 WCHAR szRegPath
[100];
626 lstrcpyW (szRegPath
, clsidW
);
627 SHELL32_GUIDToStringW (clsid
, &szRegPath
[6]);
628 lstrcatW (szRegPath
, shellfolderW
);
629 r
= SHGetValueW(HKEY_CLASSES_ROOT
, szRegPath
,
630 wantsForParsingW
, NULL
, NULL
, NULL
);
631 if (r
== ERROR_SUCCESS
)
632 bWantsForParsing
= TRUE
;
634 bWantsForParsing
= FALSE
;
637 if ((GET_SHGDN_RELATION (dwFlags
) == SHGDN_NORMAL
) &&
641 * we need the filesystem path to the destination folder.
642 * Only the folder itself can know it
644 hr
= SHELL32_GetDisplayNameOfChild (iface
, pidl
, dwFlags
,
650 /* parsing name like ::{...} */
653 SHELL32_GUIDToStringW (clsid
, &pszPath
[2]);
658 /* user friendly name */
659 HCR_GetClassNameW (clsid
, pszPath
, MAX_PATH
);
666 /* file system folder or file rooted at the desktop */
667 if ((GET_SHGDN_FOR(dwFlags
) == SHGDN_FORPARSING
) &&
668 (GET_SHGDN_RELATION(dwFlags
) != SHGDN_INFOLDER
))
670 lstrcpynW(pszPath
, This
->sPathTarget
, MAX_PATH
- 1);
671 PathAddBackslashW(pszPath
);
672 cLen
= lstrlenW(pszPath
);
675 _ILSimpleGetTextW(pidl
, pszPath
+ cLen
, MAX_PATH
- cLen
);
677 if (!_ILIsFolder(pidl
))
678 SHELL_FS_ProcessDisplayFilename(pszPath
, dwFlags
);
683 /* a complex pidl, let the subfolder do the work */
684 hr
= SHELL32_GetDisplayNameOfChild (iface
, pidl
, dwFlags
,
690 /* Win9x always returns ANSI strings, NT always returns Unicode strings */
691 if (GetVersion() & 0x80000000)
693 strRet
->uType
= STRRET_CSTR
;
694 if (!WideCharToMultiByte(CP_ACP
, 0, pszPath
, -1, strRet
->u
.cStr
, MAX_PATH
,
696 strRet
->u
.cStr
[0] = '\0';
697 CoTaskMemFree(pszPath
);
701 strRet
->uType
= STRRET_WSTR
;
702 strRet
->u
.pOleStr
= pszPath
;
706 CoTaskMemFree(pszPath
);
708 TRACE ("-- (%p)->(%s,0x%08x)\n", This
,
709 strRet
->uType
== STRRET_CSTR
? strRet
->u
.cStr
:
710 debugstr_w(strRet
->u
.pOleStr
), hr
);
714 /**************************************************************************
715 * ISF_Desktop_fnSetNameOf
716 * Changes the name of a file object or subfolder, possibly changing its item
717 * identifier in the process.
720 * HWND hwndOwner, //[in ] Owner window for output
721 * LPCITEMIDLIST pidl, //[in ] simple pidl of item to change
722 * LPCOLESTR lpszName, //[in ] the items new display name
723 * DWORD dwFlags, //[in ] SHGNO formatting flags
724 * LPITEMIDLIST* ppidlOut) //[out] simple pidl returned
726 static HRESULT WINAPI
ISF_Desktop_fnSetNameOf (IShellFolder2
* iface
,
727 HWND hwndOwner
, LPCITEMIDLIST pidl
, /* simple pidl */
728 LPCOLESTR lpName
, DWORD dwFlags
, LPITEMIDLIST
* pPidlOut
)
730 IDesktopFolderImpl
*This
= (IDesktopFolderImpl
*)iface
;
732 FIXME ("(%p)->(%p,pidl=%p,%s,%u,%p) stub\n", This
, hwndOwner
, pidl
,
733 debugstr_w (lpName
), dwFlags
, pPidlOut
);
738 static HRESULT WINAPI
ISF_Desktop_fnGetDefaultSearchGUID(IShellFolder2
*iface
,
741 IDesktopFolderImpl
*This
= (IDesktopFolderImpl
*)iface
;
742 FIXME ("(%p)->(%p) stub\n", This
, pguid
);
746 static HRESULT WINAPI
ISF_Desktop_fnEnumSearches (IShellFolder2
*iface
,
747 IEnumExtraSearch
** ppenum
)
749 IDesktopFolderImpl
*This
= (IDesktopFolderImpl
*)iface
;
750 FIXME ("(%p)->(%p) stub\n", This
, ppenum
);
754 static HRESULT WINAPI
ISF_Desktop_fnGetDefaultColumn (IShellFolder2
* iface
,
755 DWORD reserved
, ULONG
* pSort
, ULONG
* pDisplay
)
757 IDesktopFolderImpl
*This
= (IDesktopFolderImpl
*)iface
;
759 TRACE ("(%p)->(%d %p %p)\n", This
, reserved
, pSort
, pDisplay
);
768 static HRESULT WINAPI
ISF_Desktop_fnGetDefaultColumnState (
769 IShellFolder2
* iface
, UINT iColumn
, DWORD
* pcsFlags
)
771 IDesktopFolderImpl
*This
= (IDesktopFolderImpl
*)iface
;
773 TRACE ("(%p)->(%d %p)\n", This
, iColumn
, pcsFlags
);
775 if (!pcsFlags
|| iColumn
>= DESKTOPSHELLVIEWCOLUMNS
)
778 *pcsFlags
= DesktopSFHeader
[iColumn
].pcsFlags
;
783 static HRESULT WINAPI
ISF_Desktop_fnGetDetailsEx (IShellFolder2
* iface
,
784 LPCITEMIDLIST pidl
, const SHCOLUMNID
* pscid
, VARIANT
* pv
)
786 IDesktopFolderImpl
*This
= (IDesktopFolderImpl
*)iface
;
787 FIXME ("(%p)->(%p %p %p) stub\n", This
, pidl
, pscid
, pv
);
791 static HRESULT WINAPI
ISF_Desktop_fnGetDetailsOf (IShellFolder2
* iface
,
792 LPCITEMIDLIST pidl
, UINT iColumn
, SHELLDETAILS
* psd
)
794 IDesktopFolderImpl
*This
= (IDesktopFolderImpl
*)iface
;
798 TRACE ("(%p)->(%p %i %p)\n", This
, pidl
, iColumn
, psd
);
800 if (!psd
|| iColumn
>= DESKTOPSHELLVIEWCOLUMNS
)
805 psd
->fmt
= DesktopSFHeader
[iColumn
].fmt
;
806 psd
->cxChar
= DesktopSFHeader
[iColumn
].cxChar
;
807 psd
->str
.uType
= STRRET_CSTR
;
808 LoadStringA (shell32_hInstance
, DesktopSFHeader
[iColumn
].colnameid
,
809 psd
->str
.u
.cStr
, MAX_PATH
);
813 /* the data from the pidl */
814 psd
->str
.uType
= STRRET_CSTR
;
818 hr
= IShellFolder_GetDisplayNameOf(iface
, pidl
,
819 SHGDN_NORMAL
| SHGDN_INFOLDER
, &psd
->str
);
822 _ILGetFileSize (pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
825 _ILGetFileType (pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
828 _ILGetFileDate (pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
830 case 4: /* attributes */
831 _ILGetFileAttributes (pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
838 static HRESULT WINAPI
ISF_Desktop_fnMapColumnToSCID (
839 IShellFolder2
* iface
, UINT column
, SHCOLUMNID
* pscid
)
841 IDesktopFolderImpl
*This
= (IDesktopFolderImpl
*)iface
;
842 FIXME ("(%p)->(%d %p) stub\n", This
, column
, pscid
);
846 static const IShellFolder2Vtbl vt_MCFldr_ShellFolder2
=
848 ISF_Desktop_fnQueryInterface
,
849 ISF_Desktop_fnAddRef
,
850 ISF_Desktop_fnRelease
,
851 ISF_Desktop_fnParseDisplayName
,
852 ISF_Desktop_fnEnumObjects
,
853 ISF_Desktop_fnBindToObject
,
854 ISF_Desktop_fnBindToStorage
,
855 ISF_Desktop_fnCompareIDs
,
856 ISF_Desktop_fnCreateViewObject
,
857 ISF_Desktop_fnGetAttributesOf
,
858 ISF_Desktop_fnGetUIObjectOf
,
859 ISF_Desktop_fnGetDisplayNameOf
,
860 ISF_Desktop_fnSetNameOf
,
862 ISF_Desktop_fnGetDefaultSearchGUID
,
863 ISF_Desktop_fnEnumSearches
,
864 ISF_Desktop_fnGetDefaultColumn
,
865 ISF_Desktop_fnGetDefaultColumnState
,
866 ISF_Desktop_fnGetDetailsEx
,
867 ISF_Desktop_fnGetDetailsOf
,
868 ISF_Desktop_fnMapColumnToSCID
871 /**************************************************************************
874 static HRESULT WINAPI
ISF_Desktop_IPersist_fnQueryInterface(
875 IPersist
*iface
, REFIID riid
, LPVOID
*ppvObj
)
877 IDesktopFolderImpl
*This
= impl_from_IPersist( iface
);
878 return IShellFolder2_QueryInterface((IShellFolder2
*)This
, riid
, ppvObj
);
881 static ULONG WINAPI
ISF_Desktop_IPersist_fnAddRef(IPersist
*iface
)
883 IDesktopFolderImpl
*This
= impl_from_IPersist( iface
);
884 return IShellFolder2_AddRef((IShellFolder2
*)This
);
887 static ULONG WINAPI
ISF_Desktop_IPersist_fnRelease(IPersist
*iface
)
889 IDesktopFolderImpl
*This
= impl_from_IPersist( iface
);
890 return IShellFolder2_Release((IShellFolder2
*)This
);
893 static HRESULT WINAPI
ISF_Desktop_IPersist_fnGetClassID(IPersist
*iface
, CLSID
*clsid
)
895 *clsid
= CLSID_ShellDesktop
;
899 static const IPersistVtbl vt_IPersist
=
901 ISF_Desktop_IPersist_fnQueryInterface
,
902 ISF_Desktop_IPersist_fnAddRef
,
903 ISF_Desktop_IPersist_fnRelease
,
904 ISF_Desktop_IPersist_fnGetClassID
907 /**************************************************************************
908 * ISF_Desktop_Constructor
910 HRESULT WINAPI
ISF_Desktop_Constructor (
911 IUnknown
* pUnkOuter
, REFIID riid
, LPVOID
* ppv
)
913 static IDesktopFolderImpl
*cached_sf
;
914 WCHAR szMyPath
[MAX_PATH
];
916 TRACE ("unkOut=%p %s\n", pUnkOuter
, shdebugstr_guid (riid
));
921 return CLASS_E_NOAGGREGATION
;
925 IDesktopFolderImpl
*sf
;
927 if (!SHGetSpecialFolderPathW( 0, szMyPath
, CSIDL_DESKTOPDIRECTORY
, TRUE
))
930 sf
= LocalAlloc( LMEM_ZEROINIT
, sizeof (IDesktopFolderImpl
) );
932 return E_OUTOFMEMORY
;
935 sf
->lpVtbl
= &vt_MCFldr_ShellFolder2
;
936 sf
->lpVtblIPersist
= &vt_IPersist
;
937 sf
->pidlRoot
= _ILCreateDesktop(); /* my qualified pidl */
938 sf
->sPathTarget
= SHAlloc( (lstrlenW(szMyPath
) + 1)*sizeof(WCHAR
) );
939 lstrcpyW( sf
->sPathTarget
, szMyPath
);
941 if (InterlockedCompareExchangePointer((void *)&cached_sf
, sf
, NULL
) != NULL
)
943 /* some other thread already been here */
944 SHFree( sf
->pidlRoot
);
945 SHFree( sf
->sPathTarget
);
950 return IUnknown_QueryInterface( (IShellFolder2
*)cached_sf
, riid
, ppv
);