Use LMEM_ flags for LocalAlloc(), not GMEM_ (GlobalAlloc).
[wine/hacks.git] / dlls / shell32 / shfldr_desktop.c
blobc8fa6363f384821924887e6e70c0a6706d56a54d
2 /*
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "config.h"
24 #include "wine/port.h"
26 #include <stdlib.h>
27 #include <string.h>
28 #include <stdarg.h>
29 #include <stdio.h>
31 #define COBJMACROS
32 #define NONAMELESSUNION
33 #define NONAMELESSSTRUCT
35 #include "winerror.h"
36 #include "windef.h"
37 #include "winbase.h"
38 #include "winreg.h"
39 #include "wingdi.h"
40 #include "winuser.h"
42 #include "ole2.h"
43 #include "shlguid.h"
45 #include "enumidlist.h"
46 #include "pidl.h"
47 #include "undocshell.h"
48 #include "shell32_main.h"
49 #include "shresdef.h"
50 #include "shlwapi.h"
51 #include "shellfolder.h"
52 #include "wine/debug.h"
53 #include "debughlp.h"
54 #include "shfldr.h"
56 WINE_DEFAULT_DEBUG_CHANNEL (shell);
58 /***********************************************************************
59 * Desktopfolder implementation
62 typedef struct {
63 IShellFolder2Vtbl *lpVtbl;
64 DWORD ref;
66 CLSID *pclsid;
68 /* both paths are parsible from the desktop */
69 LPWSTR sPathTarget; /* complete path to target used for enumeration and ChangeNotify */
70 LPITEMIDLIST pidlRoot; /* absolute pidl */
72 int dwAttributes; /* attributes returned by GetAttributesOf FIXME: use it */
74 UINT cfShellIDList; /* clipboardformat for IDropTarget */
75 BOOL fAcceptFmt; /* flag for pending Drop */
76 } IGenericSFImpl;
78 #define _IUnknown_(This) (IShellFolder*)&(This->lpVtbl)
79 #define _IShellFolder_(This) (IShellFolder*)&(This->lpVtbl)
81 static shvheader DesktopSFHeader[] = {
82 {IDS_SHV_COLUMN1, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 15},
83 {IDS_SHV_COLUMN2, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
84 {IDS_SHV_COLUMN3, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
85 {IDS_SHV_COLUMN4, SHCOLSTATE_TYPE_DATE | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 12},
86 {IDS_SHV_COLUMN5, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 5}
89 #define DESKTOPSHELLVIEWCOLUMNS 5
91 /**************************************************************************
92 * ISF_Desktop_fnQueryInterface
94 * NOTES supports not IPersist/IPersistFolder
96 static HRESULT WINAPI ISF_Desktop_fnQueryInterface(
97 IShellFolder2 * iface, REFIID riid, LPVOID * ppvObj)
99 IGenericSFImpl *This = (IGenericSFImpl *)iface;
101 TRACE ("(%p)->(%s,%p)\n", This, shdebugstr_guid (riid), ppvObj);
103 *ppvObj = NULL;
105 if (IsEqualIID (riid, &IID_IUnknown) ||
106 IsEqualIID (riid, &IID_IShellFolder) ||
107 IsEqualIID (riid, &IID_IShellFolder2))
109 *ppvObj = This;
112 if (*ppvObj)
114 IUnknown_AddRef ((IUnknown *) (*ppvObj));
115 TRACE ("-- Interface: (%p)->(%p)\n", ppvObj, *ppvObj);
116 return S_OK;
118 TRACE ("-- Interface: E_NOINTERFACE\n");
119 return E_NOINTERFACE;
122 static ULONG WINAPI ISF_Desktop_fnAddRef (IShellFolder2 * iface)
124 IGenericSFImpl *This = (IGenericSFImpl *)iface;
125 ULONG refCount = InterlockedIncrement(&This->ref);
127 TRACE ("(%p)->(count=%lu)\n", This, refCount - 1);
129 return refCount;
132 static ULONG WINAPI ISF_Desktop_fnRelease (IShellFolder2 * iface)
134 IGenericSFImpl *This = (IGenericSFImpl *)iface;
135 ULONG refCount = InterlockedDecrement(&This->ref);
137 TRACE ("(%p)->(count=%lu)\n", This, refCount + 1);
139 if (!refCount)
141 TRACE ("-- destroying IShellFolder(%p)\n", This);
142 if (This->pidlRoot)
143 SHFree (This->pidlRoot);
144 if (This->sPathTarget)
145 SHFree (This->sPathTarget);
146 LocalFree ((HLOCAL) This);
147 return 0;
149 return refCount;
152 /**************************************************************************
153 * ISF_Desktop_fnParseDisplayName
155 * NOTES
156 * "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}" and "" binds
157 * to MyComputer
159 static HRESULT WINAPI ISF_Desktop_fnParseDisplayName (IShellFolder2 * iface,
160 HWND hwndOwner, LPBC pbc, LPOLESTR lpszDisplayName,
161 DWORD * pchEaten, LPITEMIDLIST * ppidl, DWORD * pdwAttributes)
163 IGenericSFImpl *This = (IGenericSFImpl *)iface;
164 WCHAR szElement[MAX_PATH];
165 LPCWSTR szNext = NULL;
166 LPITEMIDLIST pidlTemp = NULL;
167 HRESULT hr = S_OK;
168 CLSID clsid;
170 TRACE ("(%p)->(HWND=%p,%p,%p=%s,%p,pidl=%p,%p)\n",
171 This, hwndOwner, pbc, lpszDisplayName, debugstr_w(lpszDisplayName),
172 pchEaten, ppidl, pdwAttributes);
174 if (!lpszDisplayName || !ppidl)
175 return E_INVALIDARG;
177 *ppidl = 0;
179 if (pchEaten)
180 *pchEaten = 0; /* strange but like the original */
182 if (lpszDisplayName[0] == ':' && lpszDisplayName[1] == ':')
184 szNext = GetNextElementW (lpszDisplayName, szElement, MAX_PATH);
185 TRACE ("-- element: %s\n", debugstr_w (szElement));
186 SHCLSIDFromStringW (szElement + 2, &clsid);
187 pidlTemp = _ILCreateGuid (PT_GUID, &clsid);
189 else if (PathGetDriveNumberW (lpszDisplayName) >= 0)
191 /* it's a filesystem path with a drive. Let MyComputer parse it */
192 pidlTemp = _ILCreateMyComputer ();
193 szNext = lpszDisplayName;
195 else if (PathIsUNCW(lpszDisplayName))
197 pidlTemp = _ILCreateNetwork();
198 szNext = lpszDisplayName;
200 else if( (pidlTemp = SHELL32_CreatePidlFromBindCtx(pbc, lpszDisplayName)) )
202 *ppidl = pidlTemp;
203 return S_OK;
205 else
207 /* it's a filesystem path on the desktop. Let a FSFolder parse it */
209 if (*lpszDisplayName)
211 WCHAR szPath[MAX_PATH];
212 LPWSTR pathPtr;
214 /* build a complete path to create a simple pidl */
215 lstrcpynW(szPath, This->sPathTarget, MAX_PATH);
216 pathPtr = PathAddBackslashW(szPath);
217 if (pathPtr)
219 lstrcpynW(pathPtr, lpszDisplayName, MAX_PATH - (pathPtr - szPath));
220 hr = _ILCreateFromPathW(szPath, &pidlTemp);
222 else
224 /* should never reach here, but for completeness */
225 hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
228 else
229 pidlTemp = _ILCreateMyComputer();
231 szNext = NULL;
234 if (SUCCEEDED(hr) && pidlTemp)
236 if (szNext && *szNext)
238 hr = SHELL32_ParseNextElement(iface, hwndOwner, pbc,
239 &pidlTemp, (LPOLESTR) szNext, pchEaten, pdwAttributes);
241 else
243 if (pdwAttributes && *pdwAttributes)
244 hr = SHELL32_GetItemAttributes(_IShellFolder_ (This),
245 pidlTemp, pdwAttributes);
249 *ppidl = pidlTemp;
251 TRACE ("(%p)->(-- ret=0x%08lx)\n", This, hr);
253 return hr;
256 /**************************************************************************
257 * CreateDesktopEnumList()
259 static const WCHAR Desktop_NameSpaceW[] = { 'S','O','F','T','W','A','R','E',
260 '\\','M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
261 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\','E','x','p','l',
262 'o','r','e','r','\\','D','e','s','k','t','o','p','\\','N','a','m','e','s','p',
263 'a','c','e','\0' };
265 static BOOL CreateDesktopEnumList(IEnumIDList *list, DWORD dwFlags)
267 BOOL ret = TRUE;
268 WCHAR szPath[MAX_PATH];
270 TRACE("(%p)->(flags=0x%08lx) \n",list,dwFlags);
272 /* enumerate the root folders */
273 if (dwFlags & SHCONTF_FOLDERS)
275 HKEY hkey;
276 LONG r;
278 /* create the pidl for This item */
279 ret = AddToEnumList(list, _ILCreateMyComputer());
281 r = RegOpenKeyExW(HKEY_LOCAL_MACHINE, Desktop_NameSpaceW,
282 0, KEY_READ, &hkey);
283 if (ret && ERROR_SUCCESS == r)
285 WCHAR iid[50];
286 int i=0;
287 BOOL moreKeys = TRUE;
289 while (ret && moreKeys)
291 DWORD size;
293 size = sizeof (iid);
294 r = RegEnumKeyExW(hkey, i, iid, &size, 0, NULL, NULL, NULL);
295 if (ERROR_SUCCESS == r)
297 ret = AddToEnumList(list, _ILCreateGuidFromStrW(iid));
298 i++;
300 else if (ERROR_NO_MORE_ITEMS == r)
301 moreKeys = FALSE;
302 else
303 ret = FALSE;
305 RegCloseKey(hkey);
309 /* enumerate the elements in %windir%\desktop */
310 SHGetSpecialFolderPathW(0, szPath, CSIDL_DESKTOPDIRECTORY, FALSE);
311 ret = ret && CreateFolderEnumList(list, szPath, dwFlags);
313 return ret;
316 /**************************************************************************
317 * ISF_Desktop_fnEnumObjects
319 static HRESULT WINAPI ISF_Desktop_fnEnumObjects (IShellFolder2 * iface,
320 HWND hwndOwner, DWORD dwFlags, LPENUMIDLIST * ppEnumIDList)
322 IGenericSFImpl *This = (IGenericSFImpl *)iface;
324 TRACE ("(%p)->(HWND=%p flags=0x%08lx pplist=%p)\n",
325 This, hwndOwner, dwFlags, ppEnumIDList);
327 *ppEnumIDList = IEnumIDList_Constructor();
328 if (*ppEnumIDList)
329 CreateDesktopEnumList(*ppEnumIDList, dwFlags);
331 TRACE ("-- (%p)->(new ID List: %p)\n", This, *ppEnumIDList);
333 return *ppEnumIDList ? S_OK : E_OUTOFMEMORY;
336 /**************************************************************************
337 * ISF_Desktop_fnBindToObject
339 static HRESULT WINAPI ISF_Desktop_fnBindToObject (IShellFolder2 * iface,
340 LPCITEMIDLIST pidl, LPBC pbcReserved, REFIID riid, LPVOID * ppvOut)
342 IGenericSFImpl *This = (IGenericSFImpl *)iface;
343 char szPath[MAX_PATH];
345 TRACE ("(%p)->(pidl=%p,%p,%s,%p)\n",
346 This, pidl, pbcReserved, shdebugstr_guid (riid), ppvOut);
348 WideCharToMultiByte( CP_ACP, 0, This->sPathTarget, -1,
349 szPath, MAX_PATH, NULL, NULL );
350 return SHELL32_BindToChild( This->pidlRoot, szPath, pidl, riid, ppvOut );
353 /**************************************************************************
354 * ISF_Desktop_fnBindToStorage
356 static HRESULT WINAPI ISF_Desktop_fnBindToStorage (IShellFolder2 * iface,
357 LPCITEMIDLIST pidl, LPBC pbcReserved, REFIID riid, LPVOID * ppvOut)
359 IGenericSFImpl *This = (IGenericSFImpl *)iface;
361 FIXME ("(%p)->(pidl=%p,%p,%s,%p) stub\n",
362 This, pidl, pbcReserved, shdebugstr_guid (riid), ppvOut);
364 *ppvOut = NULL;
365 return E_NOTIMPL;
368 /**************************************************************************
369 * ISF_Desktop_fnCompareIDs
371 static HRESULT WINAPI ISF_Desktop_fnCompareIDs (IShellFolder2 * iface,
372 LPARAM lParam, LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
374 IGenericSFImpl *This = (IGenericSFImpl *)iface;
375 int nReturn;
377 TRACE ("(%p)->(0x%08lx,pidl1=%p,pidl2=%p)\n", This, lParam, pidl1, pidl2);
378 nReturn = SHELL32_CompareIDs (_IShellFolder_ (This), lParam, pidl1, pidl2);
379 TRACE ("-- %i\n", nReturn);
380 return nReturn;
383 /**************************************************************************
384 * ISF_Desktop_fnCreateViewObject
386 static HRESULT WINAPI ISF_Desktop_fnCreateViewObject (IShellFolder2 * iface,
387 HWND hwndOwner, REFIID riid, LPVOID * ppvOut)
389 IGenericSFImpl *This = (IGenericSFImpl *)iface;
390 LPSHELLVIEW pShellView;
391 HRESULT hr = E_INVALIDARG;
393 TRACE ("(%p)->(hwnd=%p,%s,%p)\n",
394 This, hwndOwner, shdebugstr_guid (riid), ppvOut);
396 if (!ppvOut)
397 return hr;
399 *ppvOut = NULL;
401 if (IsEqualIID (riid, &IID_IDropTarget))
403 WARN ("IDropTarget not implemented\n");
404 hr = E_NOTIMPL;
406 else if (IsEqualIID (riid, &IID_IContextMenu))
408 WARN ("IContextMenu not implemented\n");
409 hr = E_NOTIMPL;
411 else if (IsEqualIID (riid, &IID_IShellView))
413 pShellView = IShellView_Constructor ((IShellFolder *) iface);
414 if (pShellView)
416 hr = IShellView_QueryInterface (pShellView, riid, ppvOut);
417 IShellView_Release (pShellView);
420 TRACE ("-- (%p)->(interface=%p)\n", This, ppvOut);
421 return hr;
424 /**************************************************************************
425 * ISF_Desktop_fnGetAttributesOf
427 static HRESULT WINAPI ISF_Desktop_fnGetAttributesOf (IShellFolder2 * iface,
428 UINT cidl, LPCITEMIDLIST * apidl, DWORD * rgfInOut)
430 IGenericSFImpl *This = (IGenericSFImpl *)iface;
431 HRESULT hr = S_OK;
433 TRACE ("(%p)->(cidl=%d apidl=%p mask=0x%08lx)\n",
434 This, cidl, apidl, *rgfInOut);
436 if (!cidl || !apidl || !rgfInOut)
437 return E_INVALIDARG;
439 if (*rgfInOut == 0)
440 *rgfInOut = ~0;
442 while (cidl > 0 && *apidl)
444 pdump (*apidl);
445 SHELL32_GetItemAttributes (_IShellFolder_ (This), *apidl, rgfInOut);
446 apidl++;
447 cidl--;
450 TRACE ("-- result=0x%08lx\n", *rgfInOut);
452 return hr;
455 /**************************************************************************
456 * ISF_Desktop_fnGetUIObjectOf
458 * PARAMETERS
459 * HWND hwndOwner, //[in ] Parent window for any output
460 * UINT cidl, //[in ] array size
461 * LPCITEMIDLIST* apidl, //[in ] simple pidl array
462 * REFIID riid, //[in ] Requested Interface
463 * UINT* prgfInOut, //[ ] reserved
464 * LPVOID* ppvObject) //[out] Resulting Interface
467 static HRESULT WINAPI ISF_Desktop_fnGetUIObjectOf (IShellFolder2 * iface,
468 HWND hwndOwner, UINT cidl, LPCITEMIDLIST * apidl,
469 REFIID riid, UINT * prgfInOut, LPVOID * ppvOut)
471 IGenericSFImpl *This = (IGenericSFImpl *)iface;
473 LPITEMIDLIST pidl;
474 IUnknown *pObj = NULL;
475 HRESULT hr = E_INVALIDARG;
477 TRACE ("(%p)->(%p,%u,apidl=%p,%s,%p,%p)\n",
478 This, hwndOwner, cidl, apidl, shdebugstr_guid (riid), prgfInOut, ppvOut);
480 if (!ppvOut)
481 return hr;
483 *ppvOut = NULL;
485 if (IsEqualIID (riid, &IID_IContextMenu))
487 if (cidl > 0)
488 pObj = (LPUNKNOWN) ISvItemCm_Constructor( (IShellFolder *) iface, This->pidlRoot, apidl, cidl);
489 else
490 pObj = (LPUNKNOWN) ISvBgCm_Constructor( (IShellFolder *) iface, TRUE);
491 hr = S_OK;
493 else if (IsEqualIID (riid, &IID_IDataObject) && (cidl >= 1))
495 pObj = (LPUNKNOWN) IDataObject_Constructor( hwndOwner,
496 This->pidlRoot, apidl, cidl);
497 hr = S_OK;
499 else if (IsEqualIID (riid, &IID_IExtractIconA) && (cidl == 1))
501 pidl = ILCombine (This->pidlRoot, apidl[0]);
502 pObj = (LPUNKNOWN) IExtractIconA_Constructor (pidl);
503 SHFree (pidl);
504 hr = S_OK;
506 else if (IsEqualIID (riid, &IID_IExtractIconW) && (cidl == 1))
508 pidl = ILCombine (This->pidlRoot, apidl[0]);
509 pObj = (LPUNKNOWN) IExtractIconW_Constructor (pidl);
510 SHFree (pidl);
511 hr = S_OK;
513 else if (IsEqualIID (riid, &IID_IDropTarget) && (cidl >= 1))
515 hr = IShellFolder_QueryInterface (iface,
516 &IID_IDropTarget, (LPVOID *) & pObj);
518 else if ((IsEqualIID(riid,&IID_IShellLinkW) ||
519 IsEqualIID(riid,&IID_IShellLinkA)) && (cidl == 1))
521 pidl = ILCombine (This->pidlRoot, apidl[0]);
522 hr = IShellLink_ConstructFromFile(NULL, riid, pidl, (LPVOID*)&pObj);
523 SHFree (pidl);
525 else
526 hr = E_NOINTERFACE;
528 if (SUCCEEDED(hr) && !pObj)
529 hr = E_OUTOFMEMORY;
531 *ppvOut = pObj;
532 TRACE ("(%p)->hr=0x%08lx\n", This, hr);
533 return hr;
536 /**************************************************************************
537 * ISF_Desktop_fnGetDisplayNameOf
539 * NOTES
540 * special case: pidl = null gives desktop-name back
542 static HRESULT WINAPI ISF_Desktop_fnGetDisplayNameOf (IShellFolder2 * iface,
543 LPCITEMIDLIST pidl, DWORD dwFlags, LPSTRRET strRet)
545 IGenericSFImpl *This = (IGenericSFImpl *)iface;
546 CHAR szPath[MAX_PATH];
547 GUID const *clsid;
548 HRESULT hr = S_OK;
550 *szPath = '\0';
552 TRACE ("(%p)->(pidl=%p,0x%08lx,%p)\n", This, pidl, dwFlags, strRet);
553 pdump (pidl);
555 if (!strRet)
556 return E_INVALIDARG;
558 if (_ILIsDesktop (pidl))
560 if ((GET_SHGDN_RELATION (dwFlags) == SHGDN_NORMAL) &&
561 (GET_SHGDN_FOR (dwFlags) == SHGDN_FORPARSING))
563 WideCharToMultiByte( CP_ACP, 0, This->sPathTarget, -1,
564 szPath, MAX_PATH, NULL, NULL );
566 else
567 HCR_GetClassNameA(&CLSID_ShellDesktop, szPath, MAX_PATH);
569 else if (_ILIsPidlSimple (pidl))
571 if ((clsid = _ILGetGUIDPointer (pidl)))
573 if (GET_SHGDN_FOR (dwFlags) == SHGDN_FORPARSING)
575 int bWantsForParsing;
578 * We can only get a filesystem path from a shellfolder if the
579 * value WantsFORPARSING in CLSID\\{...}\\shellfolder exists.
581 * Exception: The MyComputer folder doesn't have this key,
582 * but any other filesystem backed folder it needs it.
584 if (IsEqualIID (clsid, &CLSID_MyComputer))
586 bWantsForParsing = 1;
588 else
590 /* get the "WantsFORPARSING" flag from the registry */
591 static const WCHAR clsidW[] =
592 { 'C','L','S','I','D','\\',0 };
593 static const WCHAR shellfolderW[] =
594 { '\\','s','h','e','l','l','f','o','l','d','e','r',0 };
595 static const WCHAR wantsForParsingW[] =
596 { 'W','a','n','t','s','F','o','r','P','a','r','s','i','n',
597 'g',0 };
598 WCHAR szRegPath[100];
599 LONG r;
601 lstrcpyW (szRegPath, clsidW);
602 SHELL32_GUIDToStringW (clsid, &szRegPath[6]);
603 lstrcatW (szRegPath, shellfolderW);
604 r = SHGetValueW(HKEY_CLASSES_ROOT, szRegPath,
605 wantsForParsingW, NULL, NULL, NULL);
606 if (r == ERROR_SUCCESS)
607 bWantsForParsing = TRUE;
608 else
609 bWantsForParsing = FALSE;
612 if ((GET_SHGDN_RELATION (dwFlags) == SHGDN_NORMAL) &&
613 bWantsForParsing)
616 * we need the filesystem path to the destination folder.
617 * Only the folder itself can know it
619 hr = SHELL32_GetDisplayNameOfChild (iface, pidl, dwFlags,
620 szPath, MAX_PATH);
622 else
624 /* parsing name like ::{...} */
625 lstrcpyA (szPath, "::");
626 SHELL32_GUIDToStringA (clsid, &szPath[2]);
629 else
631 /* user friendly name */
632 HCR_GetClassNameA (clsid, szPath, MAX_PATH);
635 else
637 /* file system folder */
638 _ILSimpleGetText (pidl, szPath, MAX_PATH);
640 if (!_ILIsFolder(pidl))
641 SHELL_FS_ProcessDisplayFilename(szPath, dwFlags);
644 else
646 /* a complex pidl, let the subfolder do the work */
647 hr = SHELL32_GetDisplayNameOfChild (iface, pidl, dwFlags, szPath, MAX_PATH);
650 if (SUCCEEDED (hr))
652 strRet->uType = STRRET_CSTR;
653 lstrcpynA (strRet->u.cStr, szPath, MAX_PATH);
656 TRACE ("-- (%p)->(%s,0x%08lx)\n", This, szPath, hr);
657 return hr;
660 /**************************************************************************
661 * ISF_Desktop_fnSetNameOf
662 * Changes the name of a file object or subfolder, possibly changing its item
663 * identifier in the process.
665 * PARAMETERS
666 * HWND hwndOwner, //[in ] Owner window for output
667 * LPCITEMIDLIST pidl, //[in ] simple pidl of item to change
668 * LPCOLESTR lpszName, //[in ] the items new display name
669 * DWORD dwFlags, //[in ] SHGNO formatting flags
670 * LPITEMIDLIST* ppidlOut) //[out] simple pidl returned
672 static HRESULT WINAPI ISF_Desktop_fnSetNameOf (IShellFolder2 * iface,
673 HWND hwndOwner, LPCITEMIDLIST pidl, /* simple pidl */
674 LPCOLESTR lpName, DWORD dwFlags, LPITEMIDLIST * pPidlOut)
676 IGenericSFImpl *This = (IGenericSFImpl *)iface;
678 FIXME ("(%p)->(%p,pidl=%p,%s,%lu,%p)\n", This, hwndOwner, pidl,
679 debugstr_w (lpName), dwFlags, pPidlOut);
681 return E_FAIL;
684 static HRESULT WINAPI ISF_Desktop_fnGetDefaultSearchGUID(IShellFolder2 *iface,
685 GUID * pguid)
687 IGenericSFImpl *This = (IGenericSFImpl *)iface;
689 FIXME ("(%p)\n", This);
690 return E_NOTIMPL;
693 static HRESULT WINAPI ISF_Desktop_fnEnumSearches (IShellFolder2 *iface,
694 IEnumExtraSearch ** ppenum)
696 IGenericSFImpl *This = (IGenericSFImpl *)iface;
697 FIXME ("(%p)\n", This);
698 return E_NOTIMPL;
701 static HRESULT WINAPI ISF_Desktop_fnGetDefaultColumn (IShellFolder2 * iface,
702 DWORD dwRes, ULONG * pSort, ULONG * pDisplay)
704 IGenericSFImpl *This = (IGenericSFImpl *)iface;
706 TRACE ("(%p)\n", This);
708 if (pSort)
709 *pSort = 0;
710 if (pDisplay)
711 *pDisplay = 0;
713 return S_OK;
715 static HRESULT WINAPI ISF_Desktop_fnGetDefaultColumnState (
716 IShellFolder2 * iface, UINT iColumn, DWORD * pcsFlags)
718 IGenericSFImpl *This = (IGenericSFImpl *)iface;
720 TRACE ("(%p)\n", This);
722 if (!pcsFlags || iColumn >= DESKTOPSHELLVIEWCOLUMNS)
723 return E_INVALIDARG;
725 *pcsFlags = DesktopSFHeader[iColumn].pcsFlags;
727 return S_OK;
730 static HRESULT WINAPI ISF_Desktop_fnGetDetailsEx (IShellFolder2 * iface,
731 LPCITEMIDLIST pidl, const SHCOLUMNID * pscid, VARIANT * pv)
733 IGenericSFImpl *This = (IGenericSFImpl *)iface;
734 FIXME ("(%p)\n", This);
736 return E_NOTIMPL;
739 static HRESULT WINAPI ISF_Desktop_fnGetDetailsOf (IShellFolder2 * iface,
740 LPCITEMIDLIST pidl, UINT iColumn, SHELLDETAILS * psd)
742 IGenericSFImpl *This = (IGenericSFImpl *)iface;
744 HRESULT hr = E_FAIL;
746 TRACE ("(%p)->(%p %i %p)\n", This, pidl, iColumn, psd);
748 if (!psd || iColumn >= DESKTOPSHELLVIEWCOLUMNS)
749 return E_INVALIDARG;
751 if (!pidl)
753 psd->fmt = DesktopSFHeader[iColumn].fmt;
754 psd->cxChar = DesktopSFHeader[iColumn].cxChar;
755 psd->str.uType = STRRET_CSTR;
756 LoadStringA (shell32_hInstance, DesktopSFHeader[iColumn].colnameid,
757 psd->str.u.cStr, MAX_PATH);
758 return S_OK;
761 /* the data from the pidl */
762 switch (iColumn)
764 case 0: /* name */
765 hr = IShellFolder_GetDisplayNameOf(iface, pidl,
766 SHGDN_NORMAL | SHGDN_INFOLDER, &psd->str);
767 break;
768 case 1: /* size */
769 _ILGetFileSize (pidl, psd->str.u.cStr, MAX_PATH);
770 break;
771 case 2: /* type */
772 _ILGetFileType (pidl, psd->str.u.cStr, MAX_PATH);
773 break;
774 case 3: /* date */
775 _ILGetFileDate (pidl, psd->str.u.cStr, MAX_PATH);
776 break;
777 case 4: /* attributes */
778 _ILGetFileAttributes (pidl, psd->str.u.cStr, MAX_PATH);
779 break;
781 hr = S_OK;
782 psd->str.uType = STRRET_CSTR;
784 return hr;
787 static HRESULT WINAPI ISF_Desktop_fnMapColumnToSCID (
788 IShellFolder2 * iface, UINT column, SHCOLUMNID * pscid)
790 IGenericSFImpl *This = (IGenericSFImpl *)iface;
791 FIXME ("(%p)\n", This);
792 return E_NOTIMPL;
795 static IShellFolder2Vtbl vt_MCFldr_ShellFolder2 =
797 ISF_Desktop_fnQueryInterface,
798 ISF_Desktop_fnAddRef,
799 ISF_Desktop_fnRelease,
800 ISF_Desktop_fnParseDisplayName,
801 ISF_Desktop_fnEnumObjects,
802 ISF_Desktop_fnBindToObject,
803 ISF_Desktop_fnBindToStorage,
804 ISF_Desktop_fnCompareIDs,
805 ISF_Desktop_fnCreateViewObject,
806 ISF_Desktop_fnGetAttributesOf,
807 ISF_Desktop_fnGetUIObjectOf,
808 ISF_Desktop_fnGetDisplayNameOf,
809 ISF_Desktop_fnSetNameOf,
810 /* ShellFolder2 */
811 ISF_Desktop_fnGetDefaultSearchGUID,
812 ISF_Desktop_fnEnumSearches,
813 ISF_Desktop_fnGetDefaultColumn,
814 ISF_Desktop_fnGetDefaultColumnState,
815 ISF_Desktop_fnGetDetailsEx,
816 ISF_Desktop_fnGetDetailsOf,
817 ISF_Desktop_fnMapColumnToSCID
820 /**************************************************************************
821 * ISF_Desktop_Constructor
823 HRESULT WINAPI ISF_Desktop_Constructor (
824 IUnknown * pUnkOuter, REFIID riid, LPVOID * ppv)
826 IGenericSFImpl *sf;
827 WCHAR szMyPath[MAX_PATH];
828 HRESULT r;
830 TRACE ("unkOut=%p %s\n", pUnkOuter, shdebugstr_guid (riid));
832 if (!ppv)
833 return E_POINTER;
834 if (pUnkOuter)
835 return CLASS_E_NOAGGREGATION;
837 if (!SHGetSpecialFolderPathW( 0, szMyPath, CSIDL_DESKTOPDIRECTORY, TRUE ))
838 return E_UNEXPECTED;
840 sf = LocalAlloc( LMEM_ZEROINIT, sizeof (IGenericSFImpl) );
841 if (!sf)
842 return E_OUTOFMEMORY;
844 sf->ref = 0;
845 sf->lpVtbl = &vt_MCFldr_ShellFolder2;
846 sf->pidlRoot = _ILCreateDesktop(); /* my qualified pidl */
847 sf->sPathTarget = SHAlloc( (lstrlenW(szMyPath) + 1)*sizeof(WCHAR) );
848 lstrcpyW( sf->sPathTarget, szMyPath );
850 r = IUnknown_QueryInterface( _IUnknown_(sf), riid, ppv );
851 if (!SUCCEEDED (r))
853 IUnknown_Release( _IUnknown_(sf) );
854 return r;
857 TRACE ("--(%p)\n", sf);
858 return S_OK;