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 /***********************************************************************
59 * Desktopfolder implementation
63 const IShellFolder2Vtbl
*lpVtbl
;
64 const IPersistFolder2Vtbl
*lpPF2
;
67 /* both paths are parsible from the desktop */
68 LPWSTR sPathTarget
; /* complete path to target used for enumeration and ChangeNotify */
69 LPITEMIDLIST pidlRoot
; /* absolute pidl */
71 UINT cfShellIDList
; /* clipboardformat for IDropTarget */
72 BOOL fAcceptFmt
; /* flag for pending Drop */
75 #define _IUnknown_(This) (IShellFolder*)&(This->lpVtbl)
76 #define _IShellFolder_(This) (IShellFolder*)&(This->lpVtbl)
78 static const shvheader DesktopSFHeader
[] = {
79 {IDS_SHV_COLUMN1
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 15},
80 {IDS_SHV_COLUMN2
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 10},
81 {IDS_SHV_COLUMN3
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 10},
82 {IDS_SHV_COLUMN4
, SHCOLSTATE_TYPE_DATE
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 12},
83 {IDS_SHV_COLUMN5
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 5}
86 #define DESKTOPSHELLVIEWCOLUMNS 5
88 /**************************************************************************
89 * ISF_Desktop_fnQueryInterface
91 * NOTES supports not IPersist/IPersistFolder
93 static HRESULT WINAPI
ISF_Desktop_fnQueryInterface(
94 IShellFolder2
* iface
, REFIID riid
, LPVOID
* ppvObj
)
96 IGenericSFImpl
*This
= (IGenericSFImpl
*)iface
;
98 TRACE ("(%p)->(%s,%p)\n", This
, shdebugstr_guid (riid
), ppvObj
);
102 if (IsEqualIID (riid
, &IID_IUnknown
) ||
103 IsEqualIID (riid
, &IID_IShellFolder
) ||
104 IsEqualIID (riid
, &IID_IShellFolder2
))
108 else if (IsEqualIID (riid
, &IID_IPersistFolder
) ||
109 IsEqualIID (riid
, &IID_IPersistFolder2
))
111 *ppvObj
= &This
->lpPF2
;
115 IUnknown_AddRef ((IUnknown
*) (*ppvObj
));
116 TRACE ("-- Interface: (%p)->(%p)\n", ppvObj
, *ppvObj
);
119 TRACE ("-- Interface: E_NOINTERFACE\n");
120 return E_NOINTERFACE
;
123 static ULONG WINAPI
ISF_Desktop_fnAddRef (IShellFolder2
* iface
)
125 return 2; /* non-heap based object */
128 static ULONG WINAPI
ISF_Desktop_fnRelease (IShellFolder2
* iface
)
130 return 1; /* non-heap based object */
133 /**************************************************************************
134 * ISF_Desktop_fnParseDisplayName
137 * "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}" and "" binds
140 static HRESULT WINAPI
ISF_Desktop_fnParseDisplayName (IShellFolder2
* iface
,
141 HWND hwndOwner
, LPBC pbc
, LPOLESTR lpszDisplayName
,
142 DWORD
* pchEaten
, LPITEMIDLIST
* ppidl
, DWORD
* pdwAttributes
)
144 IGenericSFImpl
*This
= (IGenericSFImpl
*)iface
;
145 WCHAR szElement
[MAX_PATH
];
146 LPCWSTR szNext
= NULL
;
147 LPITEMIDLIST pidlTemp
= NULL
;
151 TRACE ("(%p)->(HWND=%p,%p,%p=%s,%p,pidl=%p,%p)\n",
152 This
, hwndOwner
, pbc
, lpszDisplayName
, debugstr_w(lpszDisplayName
),
153 pchEaten
, ppidl
, pdwAttributes
);
155 if (!lpszDisplayName
|| !ppidl
)
161 *pchEaten
= 0; /* strange but like the original */
163 if (lpszDisplayName
[0] == ':' && lpszDisplayName
[1] == ':')
165 szNext
= GetNextElementW (lpszDisplayName
, szElement
, MAX_PATH
);
166 TRACE ("-- element: %s\n", debugstr_w (szElement
));
167 SHCLSIDFromStringW (szElement
+ 2, &clsid
);
168 pidlTemp
= _ILCreateGuid (PT_GUID
, &clsid
);
170 else if (PathGetDriveNumberW (lpszDisplayName
) >= 0)
172 /* it's a filesystem path with a drive. Let MyComputer/UnixDosFolder parse it */
174 if (UNIXFS_is_rooted_at_desktop())
175 pidlTemp
= _ILCreateGuid(PT_GUID
, &CLSID_UnixDosFolder
);
178 pidlTemp
= _ILCreateMyComputer ();
179 szNext
= lpszDisplayName
;
181 else if (PathIsUNCW(lpszDisplayName
))
183 pidlTemp
= _ILCreateNetwork();
184 szNext
= lpszDisplayName
;
186 else if( (pidlTemp
= SHELL32_CreatePidlFromBindCtx(pbc
, lpszDisplayName
)) )
193 /* it's a filesystem path on the desktop. Let a FSFolder parse it */
195 if (*lpszDisplayName
)
197 WCHAR szPath
[MAX_PATH
];
200 /* build a complete path to create a simple pidl */
201 lstrcpynW(szPath
, This
->sPathTarget
, MAX_PATH
);
202 pathPtr
= PathAddBackslashW(szPath
);
205 lstrcpynW(pathPtr
, lpszDisplayName
, MAX_PATH
- (pathPtr
- szPath
));
206 hr
= _ILCreateFromPathW(szPath
, &pidlTemp
);
210 /* should never reach here, but for completeness */
211 hr
= HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER
);
215 pidlTemp
= _ILCreateMyComputer();
220 if (SUCCEEDED(hr
) && pidlTemp
)
222 if (szNext
&& *szNext
)
224 hr
= SHELL32_ParseNextElement(iface
, hwndOwner
, pbc
,
225 &pidlTemp
, (LPOLESTR
) szNext
, pchEaten
, pdwAttributes
);
229 if (pdwAttributes
&& *pdwAttributes
)
230 hr
= SHELL32_GetItemAttributes(_IShellFolder_ (This
),
231 pidlTemp
, pdwAttributes
);
237 TRACE ("(%p)->(-- ret=0x%08x)\n", This
, hr
);
242 static const WCHAR ClassicStartMenuW
[] = {'S','O','F','T','W','A','R','E','\\',
243 'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
244 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\','E','x','p','l','o','r','e','r',
245 '\\','H','i','d','e','D','e','s','k','t','o','p','I','c','o','n','s','\\',
246 'C','l','a','s','s','i','c','S','t','a','r','t','M','e','n','u','\0' };
249 HideNamespaceExtension(WCHAR
*iid
)
251 DWORD Result
, dwResult
;
252 dwResult
= sizeof(DWORD
);
254 if (RegGetValueW(HKEY_CURRENT_USER
, /* FIXME use NewStartPanel when activated */
260 &dwResult
) != ERROR_SUCCESS
)
270 /**************************************************************************
271 * CreateDesktopEnumList()
273 static const WCHAR Desktop_NameSpaceW
[] = { 'S','O','F','T','W','A','R','E',
274 '\\','M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
275 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\','E','x','p','l',
276 'o','r','e','r','\\','D','e','s','k','t','o','p','\\','N','a','m','e','s','p',
279 static BOOL
CreateDesktopEnumList(IEnumIDList
*list
, DWORD dwFlags
)
282 WCHAR szPath
[MAX_PATH
];
283 static WCHAR MyDocumentsClassString
[] = L
"{450D8FBA-AD25-11D0-98A8-0800361B1103}";
286 TRACE("(%p)->(flags=0x%08x)\n", list
, dwFlags
);
288 /* enumerate the root folders */
289 if (dwFlags
& SHCONTF_FOLDERS
)
295 /* create the pidl for This item */
296 if (HideNamespaceExtension(MyDocumentsClassString
) < 1)
298 ret
= AddToEnumList(list
, _ILCreateMyDocuments());
300 ret
= AddToEnumList(list
, _ILCreateMyComputer());
302 for (i
= 0; i
< 2; i
++)
305 dwResult
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
, Desktop_NameSpaceW
, 0, KEY_READ
, &hkey
);
307 dwResult
= RegOpenKeyExW(HKEY_CURRENT_USER
, Desktop_NameSpaceW
, 0, KEY_READ
, &hkey
);
309 if (dwResult
== ERROR_SUCCESS
)
321 r
= RegEnumKeyExW(hkey
, i
, iid
, &size
, 0, NULL
, NULL
, NULL
);
322 if (ERROR_SUCCESS
== r
)
324 if (HideNamespaceExtension(iid
) < 1)
326 pidl
= _ILCreateGuidFromStrW(iid
);
327 if (!HasItemWithCLSID(list
, pidl
))
329 ret
= AddToEnumList(list
, pidl
);
337 else if (ERROR_NO_MORE_ITEMS
== r
)
346 for (i
= 0; i
< 2; i
++)
349 dwResult
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
, ClassicStartMenuW
, 0, KEY_READ
, &hkey
);
351 dwResult
= RegOpenKeyExW(HKEY_CURRENT_USER
, ClassicStartMenuW
, 0, KEY_READ
, &hkey
);
353 if (dwResult
== ERROR_SUCCESS
)
355 DWORD j
= 0, dwVal
, Val
, dwType
, dwIID
;
362 dwIID
= sizeof(iid
) / sizeof(WCHAR
);
364 r
= RegEnumValueW(hkey
, j
++, iid
, &dwIID
, NULL
, &dwType
, (LPBYTE
)&Val
, &dwVal
);
365 if (r
== ERROR_SUCCESS
)
367 if (Val
== 0 && dwType
== REG_DWORD
)
369 LPITEMIDLIST pidl
= _ILCreateGuidFromStrW(iid
);
370 if (!HasItemWithCLSID(list
, pidl
))
372 AddToEnumList(list
, pidl
);
380 else if (ERROR_NO_MORE_ITEMS
== r
)
390 /* enumerate the elements in %windir%\desktop */
391 SHGetSpecialFolderPathW(0, szPath
, CSIDL_DESKTOPDIRECTORY
, FALSE
);
392 ret
= ret
&& CreateFolderEnumList(list
, szPath
, dwFlags
);
397 /**************************************************************************
398 * ISF_Desktop_fnEnumObjects
400 static HRESULT WINAPI
ISF_Desktop_fnEnumObjects (IShellFolder2
* iface
,
401 HWND hwndOwner
, DWORD dwFlags
, LPENUMIDLIST
* ppEnumIDList
)
403 IGenericSFImpl
*This
= (IGenericSFImpl
*)iface
;
405 TRACE ("(%p)->(HWND=%p flags=0x%08x pplist=%p)\n",
406 This
, hwndOwner
, dwFlags
, ppEnumIDList
);
408 *ppEnumIDList
= IEnumIDList_Constructor();
410 CreateDesktopEnumList(*ppEnumIDList
, dwFlags
);
412 TRACE ("-- (%p)->(new ID List: %p)\n", This
, *ppEnumIDList
);
414 return *ppEnumIDList
? S_OK
: E_OUTOFMEMORY
;
417 /**************************************************************************
418 * ISF_Desktop_fnBindToObject
420 static HRESULT WINAPI
ISF_Desktop_fnBindToObject (IShellFolder2
* iface
,
421 LPCITEMIDLIST pidl
, LPBC pbcReserved
, REFIID riid
, LPVOID
* ppvOut
)
423 IGenericSFImpl
*This
= (IGenericSFImpl
*)iface
;
425 TRACE ("(%p)->(pidl=%p,%p,%s,%p)\n",
426 This
, pidl
, pbcReserved
, shdebugstr_guid (riid
), ppvOut
);
428 return SHELL32_BindToChild( This
->pidlRoot
, This
->sPathTarget
, pidl
, riid
, ppvOut
);
431 /**************************************************************************
432 * ISF_Desktop_fnBindToStorage
434 static HRESULT WINAPI
ISF_Desktop_fnBindToStorage (IShellFolder2
* iface
,
435 LPCITEMIDLIST pidl
, LPBC pbcReserved
, REFIID riid
, LPVOID
* ppvOut
)
437 IGenericSFImpl
*This
= (IGenericSFImpl
*)iface
;
439 FIXME ("(%p)->(pidl=%p,%p,%s,%p) stub\n",
440 This
, pidl
, pbcReserved
, shdebugstr_guid (riid
), ppvOut
);
446 /**************************************************************************
447 * ISF_Desktop_fnCompareIDs
449 static HRESULT WINAPI
ISF_Desktop_fnCompareIDs (IShellFolder2
* iface
,
450 LPARAM lParam
, LPCITEMIDLIST pidl1
, LPCITEMIDLIST pidl2
)
452 IGenericSFImpl
*This
= (IGenericSFImpl
*)iface
;
455 TRACE ("(%p)->(0x%08lx,pidl1=%p,pidl2=%p)\n", This
, lParam
, pidl1
, pidl2
);
456 nReturn
= SHELL32_CompareIDs (_IShellFolder_ (This
), lParam
, pidl1
, pidl2
);
457 TRACE ("-- %i\n", nReturn
);
461 /**************************************************************************
462 * ISF_Desktop_fnCreateViewObject
464 static HRESULT WINAPI
ISF_Desktop_fnCreateViewObject (IShellFolder2
* iface
,
465 HWND hwndOwner
, REFIID riid
, LPVOID
* ppvOut
)
467 IGenericSFImpl
*This
= (IGenericSFImpl
*)iface
;
468 LPSHELLVIEW pShellView
;
469 HRESULT hr
= E_INVALIDARG
;
471 TRACE ("(%p)->(hwnd=%p,%s,%p)\n",
472 This
, hwndOwner
, shdebugstr_guid (riid
), ppvOut
);
479 if (IsEqualIID (riid
, &IID_IDropTarget
))
481 WARN ("IDropTarget not implemented\n");
484 else if (IsEqualIID (riid
, &IID_IContextMenu
))
486 WARN ("IContextMenu not implemented\n");
489 else if (IsEqualIID (riid
, &IID_IShellView
))
491 pShellView
= IShellView_Constructor ((IShellFolder
*) iface
);
494 hr
= IShellView_QueryInterface (pShellView
, riid
, ppvOut
);
495 IShellView_Release (pShellView
);
498 TRACE ("-- (%p)->(interface=%p)\n", This
, ppvOut
);
502 /**************************************************************************
503 * ISF_Desktop_fnGetAttributesOf
505 static HRESULT WINAPI
ISF_Desktop_fnGetAttributesOf (IShellFolder2
* iface
,
506 UINT cidl
, LPCITEMIDLIST
* apidl
, DWORD
* rgfInOut
)
508 IGenericSFImpl
*This
= (IGenericSFImpl
*)iface
;
510 static const DWORD dwDesktopAttributes
=
511 SFGAO_STORAGE
| SFGAO_HASPROPSHEET
| SFGAO_STORAGEANCESTOR
|
512 SFGAO_FILESYSANCESTOR
| SFGAO_FOLDER
| SFGAO_FILESYSTEM
| SFGAO_HASSUBFOLDER
;
513 static const DWORD dwMyComputerAttributes
=
514 SFGAO_CANRENAME
| SFGAO_CANDELETE
| SFGAO_HASPROPSHEET
|
515 SFGAO_DROPTARGET
| SFGAO_FILESYSANCESTOR
| SFGAO_FOLDER
| SFGAO_HASSUBFOLDER
;
517 TRACE ("(%p)->(cidl=%d apidl=%p mask=%p (0x%08x))\n",
518 This
, cidl
, apidl
, rgfInOut
, rgfInOut
? *rgfInOut
: 0);
529 *rgfInOut
&= dwDesktopAttributes
;
531 while (cidl
> 0 && *apidl
) {
533 if (_ILIsDesktop(*apidl
)) {
534 *rgfInOut
&= dwDesktopAttributes
;
535 } else if (_ILIsMyComputer(*apidl
)) {
536 *rgfInOut
&= dwMyComputerAttributes
;
538 SHELL32_GetItemAttributes (_IShellFolder_ (This
), *apidl
, rgfInOut
);
544 /* make sure SFGAO_VALIDATE is cleared, some apps depend on that */
545 *rgfInOut
&= ~SFGAO_VALIDATE
;
547 TRACE ("-- result=0x%08x\n", *rgfInOut
);
552 /**************************************************************************
553 * ISF_Desktop_fnGetUIObjectOf
556 * HWND hwndOwner, //[in ] Parent window for any output
557 * UINT cidl, //[in ] array size
558 * LPCITEMIDLIST* apidl, //[in ] simple pidl array
559 * REFIID riid, //[in ] Requested Interface
560 * UINT* prgfInOut, //[ ] reserved
561 * LPVOID* ppvObject) //[out] Resulting Interface
564 static HRESULT WINAPI
ISF_Desktop_fnGetUIObjectOf (IShellFolder2
* iface
,
565 HWND hwndOwner
, UINT cidl
, LPCITEMIDLIST
* apidl
,
566 REFIID riid
, UINT
* prgfInOut
, LPVOID
* ppvOut
)
568 IGenericSFImpl
*This
= (IGenericSFImpl
*)iface
;
571 IUnknown
*pObj
= NULL
;
572 HRESULT hr
= E_INVALIDARG
;
574 TRACE ("(%p)->(%p,%u,apidl=%p,%s,%p,%p)\n",
575 This
, hwndOwner
, cidl
, apidl
, shdebugstr_guid (riid
), prgfInOut
, ppvOut
);
582 if (IsEqualIID (riid
, &IID_IContextMenu
))
584 hr
= CDefFolderMenu_Create2(This
->pidlRoot
, hwndOwner
, cidl
, apidl
, (IShellFolder
*)iface
, NULL
, 0, NULL
, (IContextMenu
**)&pObj
);
586 else if (IsEqualIID (riid
, &IID_IDataObject
) && (cidl
>= 1))
588 pObj
= (LPUNKNOWN
) IDataObject_Constructor( hwndOwner
,
589 This
->pidlRoot
, apidl
, cidl
);
592 else if (IsEqualIID (riid
, &IID_IExtractIconA
) && (cidl
== 1))
594 pidl
= ILCombine (This
->pidlRoot
, apidl
[0]);
595 pObj
= (LPUNKNOWN
) IExtractIconA_Constructor (pidl
);
599 else if (IsEqualIID (riid
, &IID_IExtractIconW
) && (cidl
== 1))
601 pidl
= ILCombine (This
->pidlRoot
, apidl
[0]);
602 pObj
= (LPUNKNOWN
) IExtractIconW_Constructor (pidl
);
606 else if (IsEqualIID (riid
, &IID_IDropTarget
) && (cidl
>= 1))
608 hr
= IShellFolder_QueryInterface (iface
,
609 &IID_IDropTarget
, (LPVOID
*) & pObj
);
611 else if ((IsEqualIID(riid
,&IID_IShellLinkW
) ||
612 IsEqualIID(riid
,&IID_IShellLinkA
)) && (cidl
== 1))
614 pidl
= ILCombine (This
->pidlRoot
, apidl
[0]);
615 hr
= IShellLink_ConstructFromFile(NULL
, riid
, pidl
, (LPVOID
*)&pObj
);
621 if (SUCCEEDED(hr
) && !pObj
)
625 TRACE ("(%p)->hr=0x%08x\n", This
, hr
);
629 /**************************************************************************
630 * ISF_Desktop_fnGetDisplayNameOf
633 * special case: pidl = null gives desktop-name back
635 static HRESULT WINAPI
ISF_Desktop_fnGetDisplayNameOf (IShellFolder2
* iface
,
636 LPCITEMIDLIST pidl
, DWORD dwFlags
, LPSTRRET strRet
)
638 IGenericSFImpl
*This
= (IGenericSFImpl
*)iface
;
642 TRACE ("(%p)->(pidl=%p,0x%08x,%p)\n", This
, pidl
, dwFlags
, strRet
);
648 pszPath
= CoTaskMemAlloc((MAX_PATH
+1) * sizeof(WCHAR
));
650 return E_OUTOFMEMORY
;
652 if (_ILIsDesktop (pidl
))
654 if ((GET_SHGDN_RELATION (dwFlags
) == SHGDN_NORMAL
) &&
655 (GET_SHGDN_FOR (dwFlags
) & SHGDN_FORPARSING
))
656 strcpyW(pszPath
, This
->sPathTarget
);
658 HCR_GetClassNameW(&CLSID_ShellDesktop
, pszPath
, MAX_PATH
);
660 else if (_ILIsPidlSimple (pidl
))
664 if ((clsid
= _ILGetGUIDPointer (pidl
)))
666 if (GET_SHGDN_FOR (dwFlags
) & SHGDN_FORPARSING
)
668 int bWantsForParsing
;
671 * We can only get a filesystem path from a shellfolder if the
672 * value WantsFORPARSING in CLSID\\{...}\\shellfolder exists.
674 * Exception: The MyComputer folder doesn't have this key,
675 * but any other filesystem backed folder it needs it.
677 if (IsEqualIID (clsid
, &CLSID_MyComputer
))
679 bWantsForParsing
= TRUE
;
683 /* get the "WantsFORPARSING" flag from the registry */
684 static const WCHAR clsidW
[] =
685 { 'C','L','S','I','D','\\',0 };
686 static const WCHAR shellfolderW
[] =
687 { '\\','s','h','e','l','l','f','o','l','d','e','r',0 };
688 static const WCHAR wantsForParsingW
[] =
689 { 'W','a','n','t','s','F','o','r','P','a','r','s','i','n',
691 WCHAR szRegPath
[100];
694 lstrcpyW (szRegPath
, clsidW
);
695 SHELL32_GUIDToStringW (clsid
, &szRegPath
[6]);
696 lstrcatW (szRegPath
, shellfolderW
);
697 r
= SHGetValueW(HKEY_CLASSES_ROOT
, szRegPath
,
698 wantsForParsingW
, NULL
, NULL
, NULL
);
699 if (r
== ERROR_SUCCESS
)
700 bWantsForParsing
= TRUE
;
702 bWantsForParsing
= FALSE
;
705 if ((GET_SHGDN_RELATION (dwFlags
) == SHGDN_NORMAL
) &&
709 * we need the filesystem path to the destination folder.
710 * Only the folder itself can know it
712 hr
= SHELL32_GetDisplayNameOfChild (iface
, pidl
, dwFlags
,
718 /* parsing name like ::{...} */
721 SHELL32_GUIDToStringW (clsid
, &pszPath
[2]);
726 /* user friendly name */
727 HCR_GetClassNameW (clsid
, pszPath
, MAX_PATH
);
734 /* file system folder or file rooted at the desktop */
735 if ((GET_SHGDN_FOR(dwFlags
) == SHGDN_FORPARSING
) &&
736 (GET_SHGDN_RELATION(dwFlags
) != SHGDN_INFOLDER
))
738 lstrcpynW(pszPath
, This
->sPathTarget
, MAX_PATH
- 1);
739 PathAddBackslashW(pszPath
);
740 cLen
= lstrlenW(pszPath
);
743 _ILSimpleGetTextW(pidl
, pszPath
+ cLen
, MAX_PATH
- cLen
);
745 if (!_ILIsFolder(pidl
))
746 SHELL_FS_ProcessDisplayFilename(pszPath
, dwFlags
);
751 /* a complex pidl, let the subfolder do the work */
752 hr
= SHELL32_GetDisplayNameOfChild (iface
, pidl
, dwFlags
,
758 /* Win9x always returns ANSI strings, NT always returns Unicode strings */
759 if (GetVersion() & 0x80000000)
761 strRet
->uType
= STRRET_CSTR
;
762 if (!WideCharToMultiByte(CP_ACP
, 0, pszPath
, -1, strRet
->u
.cStr
, MAX_PATH
,
764 strRet
->u
.cStr
[0] = '\0';
765 CoTaskMemFree(pszPath
);
769 strRet
->uType
= STRRET_WSTR
;
770 strRet
->u
.pOleStr
= pszPath
;
774 CoTaskMemFree(pszPath
);
776 TRACE ("-- (%p)->(%s,0x%08x)\n", This
,
777 strRet
->uType
== STRRET_CSTR
? strRet
->u
.cStr
:
778 debugstr_w(strRet
->u
.pOleStr
), hr
);
782 /**************************************************************************
783 * ISF_Desktop_fnSetNameOf
784 * Changes the name of a file object or subfolder, possibly changing its item
785 * identifier in the process.
788 * HWND hwndOwner, //[in ] Owner window for output
789 * LPCITEMIDLIST pidl, //[in ] simple pidl of item to change
790 * LPCOLESTR lpszName, //[in ] the items new display name
791 * DWORD dwFlags, //[in ] SHGNO formatting flags
792 * LPITEMIDLIST* ppidlOut) //[out] simple pidl returned
794 static HRESULT WINAPI
ISF_Desktop_fnSetNameOf (IShellFolder2
* iface
,
795 HWND hwndOwner
, LPCITEMIDLIST pidl
, /* simple pidl */
796 LPCOLESTR lpName
, DWORD dwFlags
, LPITEMIDLIST
* pPidlOut
)
798 IGenericSFImpl
*This
= (IGenericSFImpl
*)iface
;
800 FIXME ("(%p)->(%p,pidl=%p,%s,%u,%p)\n", This
, hwndOwner
, pidl
,
801 debugstr_w (lpName
), dwFlags
, pPidlOut
);
806 static HRESULT WINAPI
ISF_Desktop_fnGetDefaultSearchGUID(IShellFolder2
*iface
,
809 IGenericSFImpl
*This
= (IGenericSFImpl
*)iface
;
811 FIXME ("(%p)\n", This
);
815 static HRESULT WINAPI
ISF_Desktop_fnEnumSearches (IShellFolder2
*iface
,
816 IEnumExtraSearch
** ppenum
)
818 IGenericSFImpl
*This
= (IGenericSFImpl
*)iface
;
819 FIXME ("(%p)\n", This
);
823 static HRESULT WINAPI
ISF_Desktop_fnGetDefaultColumn (IShellFolder2
* iface
,
824 DWORD dwRes
, ULONG
* pSort
, ULONG
* pDisplay
)
826 IGenericSFImpl
*This
= (IGenericSFImpl
*)iface
;
828 TRACE ("(%p)\n", This
);
837 static HRESULT WINAPI
ISF_Desktop_fnGetDefaultColumnState (
838 IShellFolder2
* iface
, UINT iColumn
, DWORD
* pcsFlags
)
840 IGenericSFImpl
*This
= (IGenericSFImpl
*)iface
;
842 TRACE ("(%p)\n", This
);
844 if (!pcsFlags
|| iColumn
>= DESKTOPSHELLVIEWCOLUMNS
)
847 *pcsFlags
= DesktopSFHeader
[iColumn
].pcsFlags
;
852 static HRESULT WINAPI
ISF_Desktop_fnGetDetailsEx (IShellFolder2
* iface
,
853 LPCITEMIDLIST pidl
, const SHCOLUMNID
* pscid
, VARIANT
* pv
)
855 IGenericSFImpl
*This
= (IGenericSFImpl
*)iface
;
856 FIXME ("(%p)\n", This
);
861 static HRESULT WINAPI
ISF_Desktop_fnGetDetailsOf (IShellFolder2
* iface
,
862 LPCITEMIDLIST pidl
, UINT iColumn
, SHELLDETAILS
* psd
)
864 IGenericSFImpl
*This
= (IGenericSFImpl
*)iface
;
868 TRACE ("(%p)->(%p %i %p)\n", This
, pidl
, iColumn
, psd
);
870 if (!psd
|| iColumn
>= DESKTOPSHELLVIEWCOLUMNS
)
875 psd
->fmt
= DesktopSFHeader
[iColumn
].fmt
;
876 psd
->cxChar
= DesktopSFHeader
[iColumn
].cxChar
;
877 psd
->str
.uType
= STRRET_CSTR
;
878 LoadStringA (shell32_hInstance
, DesktopSFHeader
[iColumn
].colnameid
,
879 psd
->str
.u
.cStr
, MAX_PATH
);
883 /* the data from the pidl */
884 psd
->str
.uType
= STRRET_CSTR
;
888 hr
= IShellFolder_GetDisplayNameOf(iface
, pidl
,
889 SHGDN_NORMAL
| SHGDN_INFOLDER
, &psd
->str
);
892 _ILGetFileSize (pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
895 _ILGetFileType (pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
898 _ILGetFileDate (pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
900 case 4: /* attributes */
901 _ILGetFileAttributes (pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
908 static HRESULT WINAPI
ISF_Desktop_fnMapColumnToSCID (
909 IShellFolder2
* iface
, UINT column
, SHCOLUMNID
* pscid
)
911 IGenericSFImpl
*This
= (IGenericSFImpl
*)iface
;
912 FIXME ("(%p)\n", This
);
916 static const IShellFolder2Vtbl vt_MCFldr_ShellFolder2
=
918 ISF_Desktop_fnQueryInterface
,
919 ISF_Desktop_fnAddRef
,
920 ISF_Desktop_fnRelease
,
921 ISF_Desktop_fnParseDisplayName
,
922 ISF_Desktop_fnEnumObjects
,
923 ISF_Desktop_fnBindToObject
,
924 ISF_Desktop_fnBindToStorage
,
925 ISF_Desktop_fnCompareIDs
,
926 ISF_Desktop_fnCreateViewObject
,
927 ISF_Desktop_fnGetAttributesOf
,
928 ISF_Desktop_fnGetUIObjectOf
,
929 ISF_Desktop_fnGetDisplayNameOf
,
930 ISF_Desktop_fnSetNameOf
,
932 ISF_Desktop_fnGetDefaultSearchGUID
,
933 ISF_Desktop_fnEnumSearches
,
934 ISF_Desktop_fnGetDefaultColumn
,
935 ISF_Desktop_fnGetDefaultColumnState
,
936 ISF_Desktop_fnGetDetailsEx
,
937 ISF_Desktop_fnGetDetailsOf
,
938 ISF_Desktop_fnMapColumnToSCID
941 static inline IGenericSFImpl
*impl_from_IPersistFolder2( IPersistFolder2
*iface
)
943 return (IGenericSFImpl
*)((char*)iface
- FIELD_OFFSET(IGenericSFImpl
, lpPF2
));
946 static HRESULT WINAPI
947 ISF_Desktop_PersistFolder2_fnQueryInterface (IPersistFolder2
* iface
, REFIID iid
,
950 IGenericSFImpl
*This
= impl_from_IPersistFolder2(iface
);
952 TRACE ("(%p)\n", This
);
954 return ISF_Desktop_fnQueryInterface ((IShellFolder2
*)This
, iid
, ppvObj
);
958 ISF_Desktop_PersistFolder2_fnAddRef (IPersistFolder2
* iface
)
960 IGenericSFImpl
*This
= impl_from_IPersistFolder2(iface
);
962 TRACE ("(%p)->(count=%u)\n", This
, This
->ref
);
964 return ISF_Desktop_fnAddRef((IShellFolder2
*)This
);
968 ISF_Desktop_PersistFolder2_fnRelease (IPersistFolder2
* iface
)
970 IGenericSFImpl
*This
= impl_from_IPersistFolder2(iface
);
972 TRACE ("(%p)->(count=%u)\n", This
, This
->ref
);
974 return ISF_Desktop_fnRelease ((IShellFolder2
*)This
);
977 static HRESULT WINAPI
978 ISF_Desktop_PersistFolder2_fnGetClassID (IPersistFolder2
* iface
, CLSID
* lpClassId
)
980 static GUID
const CLSID_Desktop
=
981 { 0x00021400, 0x0000, 0x0000, {0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46} };
983 IGenericSFImpl
*This
= impl_from_IPersistFolder2(iface
);
985 TRACE ("(%p)\n", This
);
990 memcpy(lpClassId
, &CLSID_Desktop
, sizeof(GUID
));
994 static HRESULT WINAPI
995 ISF_Desktop_PersistFolder2_fnInitialize (IPersistFolder2
* iface
, LPCITEMIDLIST pidl
)
997 IGenericSFImpl
*This
= impl_from_IPersistFolder2(iface
);
999 TRACE ("(%p)->(%p)\n", This
, pidl
);
1004 static HRESULT WINAPI
1005 ISF_Desktop_PersistFolder2_fnGetCurFolder (IPersistFolder2
* iface
,
1006 LPITEMIDLIST
* pidl
)
1008 IGenericSFImpl
*This
= impl_from_IPersistFolder2(iface
);
1010 TRACE ("(%p)->(%p)\n", This
, pidl
);
1012 if (!pidl
) return E_POINTER
;
1013 *pidl
= ILClone (This
->pidlRoot
);
1017 static const IPersistFolder2Vtbl vt_FSFldr_PersistFolder2
=
1019 ISF_Desktop_PersistFolder2_fnQueryInterface
,
1020 ISF_Desktop_PersistFolder2_fnAddRef
,
1021 ISF_Desktop_PersistFolder2_fnRelease
,
1022 ISF_Desktop_PersistFolder2_fnGetClassID
,
1023 ISF_Desktop_PersistFolder2_fnInitialize
,
1024 ISF_Desktop_PersistFolder2_fnGetCurFolder
,
1028 /**************************************************************************
1029 * ISF_Desktop_Constructor
1031 HRESULT WINAPI
ISF_Desktop_Constructor (
1032 IUnknown
* pUnkOuter
, REFIID riid
, LPVOID
* ppv
)
1034 static IGenericSFImpl
*cached_sf
;
1035 WCHAR szMyPath
[MAX_PATH
];
1037 TRACE ("unkOut=%p %s\n", pUnkOuter
, shdebugstr_guid (riid
));
1042 return CLASS_E_NOAGGREGATION
;
1048 if (!SHGetSpecialFolderPathW( 0, szMyPath
, CSIDL_DESKTOPDIRECTORY
, TRUE
))
1049 return E_UNEXPECTED
;
1051 sf
= LocalAlloc( LMEM_ZEROINIT
, sizeof (IGenericSFImpl
) );
1053 return E_OUTOFMEMORY
;
1056 sf
->lpVtbl
= &vt_MCFldr_ShellFolder2
;
1057 sf
->lpPF2
= &vt_FSFldr_PersistFolder2
;
1058 sf
->pidlRoot
= _ILCreateDesktop(); /* my qualified pidl */
1059 sf
->sPathTarget
= SHAlloc( (lstrlenW(szMyPath
) + 1)*sizeof(WCHAR
) );
1060 lstrcpyW( sf
->sPathTarget
, szMyPath
);
1062 if (InterlockedCompareExchangePointer((void *)&cached_sf
, sf
, NULL
) != NULL
)
1064 /* some other thread already been here */
1065 SHFree( sf
->pidlRoot
);
1066 SHFree( sf
->sPathTarget
);
1071 return IUnknown_QueryInterface( _IUnknown_(cached_sf
), riid
, ppv
);