Sync to Wine-20050310:
[reactos.git] / reactos / lib / shell32 / shfldr_desktop.c
1
2 /*
3 * Virtual Desktop Folder
4 *
5 * Copyright 1997 Marcus Meissner
6 * Copyright 1998, 1999, 2002 Juergen Schmied
7 *
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.
12 *
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.
17 *
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
21 */
22
23 #include "config.h"
24 #include "wine/port.h"
25
26 #include <stdlib.h>
27 #include <string.h>
28 #include <stdarg.h>
29 #include <stdio.h>
30
31 #define COBJMACROS
32 #define NONAMELESSUNION
33 #define NONAMELESSSTRUCT
34
35 #include "winerror.h"
36 #include "windef.h"
37 #include "winbase.h"
38 #include "winreg.h"
39 #include "wingdi.h"
40 #include "winuser.h"
41
42 #include "ole2.h"
43 #include "shlguid.h"
44
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"
55
56 WINE_DEFAULT_DEBUG_CHANNEL (shell);
57
58 /***********************************************************************
59 * Desktopfolder implementation
60 */
61
62 typedef struct {
63 IShellFolder2Vtbl *lpVtbl;
64 DWORD ref;
65
66 CLSID *pclsid;
67
68 /* both paths are parsible from the desktop */
69 LPSTR sPathTarget; /* complete path to target used for enumeration and ChangeNotify */
70 LPITEMIDLIST pidlRoot; /* absolute pidl */
71
72 int dwAttributes; /* attributes returned by GetAttributesOf FIXME: use it */
73
74 UINT cfShellIDList; /* clipboardformat for IDropTarget */
75 BOOL fAcceptFmt; /* flag for pending Drop */
76 } IGenericSFImpl;
77
78 #define _IUnknown_(This) (IShellFolder*)&(This->lpVtbl)
79 #define _IShellFolder_(This) (IShellFolder*)&(This->lpVtbl)
80
81 static struct IShellFolder2Vtbl vt_MCFldr_ShellFolder2;
82
83 static shvheader DesktopSFHeader[] = {
84 {IDS_SHV_COLUMN1, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 15},
85 {IDS_SHV_COLUMN2, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
86 {IDS_SHV_COLUMN3, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
87 {IDS_SHV_COLUMN4, SHCOLSTATE_TYPE_DATE | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 12},
88 {IDS_SHV_COLUMN5, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 5}
89 };
90
91 #define DESKTOPSHELLVIEWCOLUMNS 5
92
93 /**************************************************************************
94 * ISF_Desktop_Constructor
95 */
96 HRESULT WINAPI ISF_Desktop_Constructor (
97 IUnknown * pUnkOuter, REFIID riid, LPVOID * ppv)
98 {
99 IGenericSFImpl *sf;
100 char szMyPath[MAX_PATH];
101
102 TRACE ("unkOut=%p %s\n", pUnkOuter, shdebugstr_guid (riid));
103
104 if (!ppv)
105 return E_POINTER;
106 if (pUnkOuter)
107 return CLASS_E_NOAGGREGATION;
108
109 if (!SHGetSpecialFolderPathA (0, szMyPath, CSIDL_DESKTOPDIRECTORY, TRUE))
110 return E_UNEXPECTED;
111
112 sf = (IGenericSFImpl *) LocalAlloc (GMEM_ZEROINIT, sizeof (IGenericSFImpl));
113 if (!sf)
114 return E_OUTOFMEMORY;
115
116 sf->ref = 0;
117 sf->lpVtbl = &vt_MCFldr_ShellFolder2;
118 sf->pidlRoot = _ILCreateDesktop (); /* my qualified pidl */
119 sf->sPathTarget = SHAlloc (strlen (szMyPath) + 1);
120 lstrcpyA (sf->sPathTarget, szMyPath);
121
122 if (!SUCCEEDED (IUnknown_QueryInterface (_IUnknown_ (sf), riid, ppv)))
123 {
124 IUnknown_Release (_IUnknown_ (sf));
125 return E_NOINTERFACE;
126 }
127
128 TRACE ("--(%p)\n", sf);
129 return S_OK;
130 }
131
132 /**************************************************************************
133 * ISF_Desktop_fnQueryInterface
134 *
135 * NOTES supports not IPersist/IPersistFolder
136 */
137 static HRESULT WINAPI ISF_Desktop_fnQueryInterface(
138 IShellFolder2 * iface, REFIID riid, LPVOID * ppvObj)
139 {
140 IGenericSFImpl *This = (IGenericSFImpl *)iface;
141
142 TRACE ("(%p)->(%s,%p)\n", This, shdebugstr_guid (riid), ppvObj);
143
144 *ppvObj = NULL;
145
146 if (IsEqualIID (riid, &IID_IUnknown) ||
147 IsEqualIID (riid, &IID_IShellFolder) ||
148 IsEqualIID (riid, &IID_IShellFolder2))
149 {
150 *ppvObj = This;
151 }
152
153 if (*ppvObj)
154 {
155 IUnknown_AddRef ((IUnknown *) (*ppvObj));
156 TRACE ("-- Interface: (%p)->(%p)\n", ppvObj, *ppvObj);
157 return S_OK;
158 }
159 TRACE ("-- Interface: E_NOINTERFACE\n");
160 return E_NOINTERFACE;
161 }
162
163 static ULONG WINAPI ISF_Desktop_fnAddRef (IShellFolder2 * iface)
164 {
165 IGenericSFImpl *This = (IGenericSFImpl *)iface;
166 ULONG refCount = InterlockedIncrement(&This->ref);
167
168 TRACE ("(%p)->(count=%lu)\n", This, refCount - 1);
169
170 return refCount;
171 }
172
173 static ULONG WINAPI ISF_Desktop_fnRelease (IShellFolder2 * iface)
174 {
175 IGenericSFImpl *This = (IGenericSFImpl *)iface;
176 ULONG refCount = InterlockedDecrement(&This->ref);
177
178 TRACE ("(%p)->(count=%lu)\n", This, refCount + 1);
179
180 if (!refCount)
181 {
182 TRACE ("-- destroying IShellFolder(%p)\n", This);
183 if (This->pidlRoot)
184 SHFree (This->pidlRoot);
185 if (This->sPathTarget)
186 SHFree (This->sPathTarget);
187 LocalFree ((HLOCAL) This);
188 return 0;
189 }
190 return refCount;
191 }
192
193 /**************************************************************************
194 * ISF_Desktop_fnParseDisplayName
195 *
196 * NOTES
197 * "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}" and "" binds
198 * to MyComputer
199 */
200 static HRESULT WINAPI ISF_Desktop_fnParseDisplayName (IShellFolder2 * iface,
201 HWND hwndOwner, LPBC pbc, LPOLESTR lpszDisplayName,
202 DWORD * pchEaten, LPITEMIDLIST * ppidl, DWORD * pdwAttributes)
203 {
204 IGenericSFImpl *This = (IGenericSFImpl *)iface;
205 WCHAR szElement[MAX_PATH];
206 LPCWSTR szNext = NULL;
207 LPITEMIDLIST pidlTemp = NULL;
208 HRESULT hr = S_OK;
209 CLSID clsid;
210
211 TRACE ("(%p)->(HWND=%p,%p,%p=%s,%p,pidl=%p,%p)\n",
212 This, hwndOwner, pbc, lpszDisplayName, debugstr_w(lpszDisplayName),
213 pchEaten, ppidl, pdwAttributes);
214
215 if (!lpszDisplayName || !ppidl)
216 return E_INVALIDARG;
217
218 *ppidl = 0;
219
220 if (pchEaten)
221 *pchEaten = 0; /* strange but like the original */
222
223 if (lpszDisplayName[0] == ':' && lpszDisplayName[1] == ':')
224 {
225 szNext = GetNextElementW (lpszDisplayName, szElement, MAX_PATH);
226 TRACE ("-- element: %s\n", debugstr_w (szElement));
227 SHCLSIDFromStringW (szElement + 2, &clsid);
228 pidlTemp = _ILCreateGuid (PT_GUID, &clsid);
229 }
230 else if (PathGetDriveNumberW (lpszDisplayName) >= 0)
231 {
232 /* it's a filesystem path with a drive. Let MyComputer parse it */
233 pidlTemp = _ILCreateMyComputer ();
234 szNext = lpszDisplayName;
235 }
236 else if (PathIsUNCW(lpszDisplayName))
237 {
238 pidlTemp = _ILCreateNetwork();
239 szNext = lpszDisplayName;
240 }
241 else if( (pidlTemp = SHELL32_CreatePidlFromBindCtx(pbc, lpszDisplayName)) )
242 {
243 *ppidl = pidlTemp;
244 return S_OK;
245 }
246 else
247 {
248 /* it's a filesystem path on the desktop. Let a FSFolder parse it */
249
250 if (*lpszDisplayName)
251 {
252 WCHAR szPath[MAX_PATH];
253 LPWSTR pathPtr;
254
255 /* build a complete path to create a simple pidl */
256 MultiByteToWideChar(CP_ACP, 0, This->sPathTarget, -1, szPath,
257 sizeof(szPath) / sizeof(szPath[0]));
258 pathPtr = PathAddBackslashW(szPath);
259 if (pathPtr)
260 {
261 lstrcpynW(pathPtr, lpszDisplayName,
262 sizeof(szPath)/sizeof(szPath[0]) - (pathPtr - szPath));
263 hr = _ILCreateFromPathW(szPath, &pidlTemp);
264 }
265 else
266 {
267 /* should never reach here, but for completeness */
268 hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
269 }
270 }
271 else
272 pidlTemp = _ILCreateMyComputer();
273
274 szNext = NULL;
275 }
276
277 if (SUCCEEDED(hr) && pidlTemp)
278 {
279 if (szNext && *szNext)
280 {
281 hr = SHELL32_ParseNextElement(iface, hwndOwner, pbc,
282 &pidlTemp, (LPOLESTR) szNext, pchEaten, pdwAttributes);
283 }
284 else
285 {
286 if (pdwAttributes && *pdwAttributes)
287 hr = SHELL32_GetItemAttributes(_IShellFolder_ (This),
288 pidlTemp, pdwAttributes);
289 }
290 }
291
292 *ppidl = pidlTemp;
293
294 TRACE ("(%p)->(-- ret=0x%08lx)\n", This, hr);
295
296 return hr;
297 }
298
299 /**************************************************************************
300 * CreateDesktopEnumList()
301 */
302 static const WCHAR Desktop_NameSpaceW[] = { 'S','O','F','T','W','A','R','E',
303 '\\','M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
304 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\','E','x','p','l',
305 'o','r','e','r','\\','D','e','s','k','t','o','p','\\','N','a','m','e','s','p',
306 'a','c','e','\0' };
307
308 static BOOL CreateDesktopEnumList(IEnumIDList *list, DWORD dwFlags)
309 {
310 BOOL ret = TRUE;
311 WCHAR szPath[MAX_PATH];
312
313 TRACE("(%p)->(flags=0x%08lx) \n",list,dwFlags);
314
315 /* enumerate the root folders */
316 if (dwFlags & SHCONTF_FOLDERS)
317 {
318 HKEY hkey;
319 LONG r;
320
321 /* create the pidl for This item */
322 ret = AddToEnumList(list, _ILCreateMyComputer());
323
324 r = RegOpenKeyExW(HKEY_LOCAL_MACHINE, Desktop_NameSpaceW,
325 0, KEY_READ, &hkey);
326 if (ret && ERROR_SUCCESS == r)
327 {
328 WCHAR iid[50];
329 int i=0;
330 BOOL moreKeys = TRUE;
331
332 while (ret && moreKeys)
333 {
334 DWORD size;
335
336 size = sizeof (iid);
337 r = RegEnumKeyExW(hkey, i, iid, &size, 0, NULL, NULL, NULL);
338 if (ERROR_SUCCESS == r)
339 {
340 ret = AddToEnumList(list, _ILCreateGuidFromStrW(iid));
341 i++;
342 }
343 else if (ERROR_NO_MORE_ITEMS == r)
344 moreKeys = FALSE;
345 else
346 ret = FALSE;
347 }
348 RegCloseKey(hkey);
349 }
350 }
351
352 /* enumerate the elements in %windir%\desktop */
353 SHGetSpecialFolderPathW(0, szPath, CSIDL_DESKTOPDIRECTORY, FALSE);
354 ret = ret && CreateFolderEnumList(list, szPath, dwFlags);
355
356 return ret;
357 }
358
359 /**************************************************************************
360 * ISF_Desktop_fnEnumObjects
361 */
362 static HRESULT WINAPI ISF_Desktop_fnEnumObjects (IShellFolder2 * iface,
363 HWND hwndOwner, DWORD dwFlags, LPENUMIDLIST * ppEnumIDList)
364 {
365 IGenericSFImpl *This = (IGenericSFImpl *)iface;
366
367 TRACE ("(%p)->(HWND=%p flags=0x%08lx pplist=%p)\n",
368 This, hwndOwner, dwFlags, ppEnumIDList);
369
370 *ppEnumIDList = IEnumIDList_Constructor();
371 if (*ppEnumIDList)
372 CreateDesktopEnumList(*ppEnumIDList, dwFlags);
373
374 TRACE ("-- (%p)->(new ID List: %p)\n", This, *ppEnumIDList);
375
376 return *ppEnumIDList ? S_OK : E_OUTOFMEMORY;
377 }
378
379 /**************************************************************************
380 * ISF_Desktop_fnBindToObject
381 */
382 static HRESULT WINAPI ISF_Desktop_fnBindToObject (IShellFolder2 * iface,
383 LPCITEMIDLIST pidl, LPBC pbcReserved, REFIID riid, LPVOID * ppvOut)
384 {
385 IGenericSFImpl *This = (IGenericSFImpl *)iface;
386
387 TRACE ("(%p)->(pidl=%p,%p,%s,%p)\n",
388 This, pidl, pbcReserved, shdebugstr_guid (riid), ppvOut);
389
390 return SHELL32_BindToChild (This->pidlRoot, This->sPathTarget, pidl, riid, ppvOut);
391 }
392
393 /**************************************************************************
394 * ISF_Desktop_fnBindToStorage
395 */
396 static HRESULT WINAPI ISF_Desktop_fnBindToStorage (IShellFolder2 * iface,
397 LPCITEMIDLIST pidl, LPBC pbcReserved, REFIID riid, LPVOID * ppvOut)
398 {
399 IGenericSFImpl *This = (IGenericSFImpl *)iface;
400
401 FIXME ("(%p)->(pidl=%p,%p,%s,%p) stub\n",
402 This, pidl, pbcReserved, shdebugstr_guid (riid), ppvOut);
403
404 *ppvOut = NULL;
405 return E_NOTIMPL;
406 }
407
408 /**************************************************************************
409 * ISF_Desktop_fnCompareIDs
410 */
411 static HRESULT WINAPI ISF_Desktop_fnCompareIDs (IShellFolder2 * iface,
412 LPARAM lParam, LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
413 {
414 IGenericSFImpl *This = (IGenericSFImpl *)iface;
415 int nReturn;
416
417 TRACE ("(%p)->(0x%08lx,pidl1=%p,pidl2=%p)\n", This, lParam, pidl1, pidl2);
418 nReturn = SHELL32_CompareIDs (_IShellFolder_ (This), lParam, pidl1, pidl2);
419 TRACE ("-- %i\n", nReturn);
420 return nReturn;
421 }
422
423 /**************************************************************************
424 * ISF_Desktop_fnCreateViewObject
425 */
426 static HRESULT WINAPI ISF_Desktop_fnCreateViewObject (IShellFolder2 * iface,
427 HWND hwndOwner, REFIID riid, LPVOID * ppvOut)
428 {
429 IGenericSFImpl *This = (IGenericSFImpl *)iface;
430 LPSHELLVIEW pShellView;
431 HRESULT hr = E_INVALIDARG;
432
433 TRACE ("(%p)->(hwnd=%p,%s,%p)\n",
434 This, hwndOwner, shdebugstr_guid (riid), ppvOut);
435
436 if (!ppvOut)
437 return hr;
438
439 *ppvOut = NULL;
440
441 if (IsEqualIID (riid, &IID_IDropTarget))
442 {
443 WARN ("IDropTarget not implemented\n");
444 hr = E_NOTIMPL;
445 }
446 else if (IsEqualIID (riid, &IID_IContextMenu))
447 {
448 WARN ("IContextMenu not implemented\n");
449 hr = E_NOTIMPL;
450 }
451 else if (IsEqualIID (riid, &IID_IShellView))
452 {
453 pShellView = IShellView_Constructor ((IShellFolder *) iface);
454 if (pShellView)
455 {
456 hr = IShellView_QueryInterface (pShellView, riid, ppvOut);
457 IShellView_Release (pShellView);
458 }
459 }
460 TRACE ("-- (%p)->(interface=%p)\n", This, ppvOut);
461 return hr;
462 }
463
464 /**************************************************************************
465 * ISF_Desktop_fnGetAttributesOf
466 */
467 static HRESULT WINAPI ISF_Desktop_fnGetAttributesOf (IShellFolder2 * iface,
468 UINT cidl, LPCITEMIDLIST * apidl, DWORD * rgfInOut)
469 {
470 IGenericSFImpl *This = (IGenericSFImpl *)iface;
471 HRESULT hr = S_OK;
472
473 TRACE ("(%p)->(cidl=%d apidl=%p mask=0x%08lx)\n",
474 This, cidl, apidl, *rgfInOut);
475
476 if (!cidl || !apidl || !rgfInOut)
477 return E_INVALIDARG;
478
479 if (*rgfInOut == 0)
480 *rgfInOut = ~0;
481
482 while (cidl > 0 && *apidl)
483 {
484 pdump (*apidl);
485 SHELL32_GetItemAttributes (_IShellFolder_ (This), *apidl, rgfInOut);
486 apidl++;
487 cidl--;
488 }
489
490 TRACE ("-- result=0x%08lx\n", *rgfInOut);
491
492 return hr;
493 }
494
495 /**************************************************************************
496 * ISF_Desktop_fnGetUIObjectOf
497 *
498 * PARAMETERS
499 * HWND hwndOwner, //[in ] Parent window for any output
500 * UINT cidl, //[in ] array size
501 * LPCITEMIDLIST* apidl, //[in ] simple pidl array
502 * REFIID riid, //[in ] Requested Interface
503 * UINT* prgfInOut, //[ ] reserved
504 * LPVOID* ppvObject) //[out] Resulting Interface
505 *
506 */
507 static HRESULT WINAPI ISF_Desktop_fnGetUIObjectOf (IShellFolder2 * iface,
508 HWND hwndOwner, UINT cidl, LPCITEMIDLIST * apidl,
509 REFIID riid, UINT * prgfInOut, LPVOID * ppvOut)
510 {
511 IGenericSFImpl *This = (IGenericSFImpl *)iface;
512
513 LPITEMIDLIST pidl;
514 IUnknown *pObj = NULL;
515 HRESULT hr = E_INVALIDARG;
516
517 TRACE ("(%p)->(%p,%u,apidl=%p,%s,%p,%p)\n",
518 This, hwndOwner, cidl, apidl, shdebugstr_guid (riid), prgfInOut, ppvOut);
519
520 if (!ppvOut)
521 return hr;
522
523 if (IsEqualIID (riid, &IID_IDataObject) && (cidl >= 1))
524 {
525 pObj = (LPUNKNOWN) IDataObject_Constructor( hwndOwner,
526 This->pidlRoot, apidl, cidl);
527 hr = S_OK;
528 }
529 else if ((IsEqualIID(riid,&IID_IShellLinkW) ||
530 IsEqualIID(riid,&IID_IShellLinkA)) && (cidl == 1))
531 {
532 pidl = ILCombine (This->pidlRoot, apidl[0]);
533 hr = IShellLink_ConstructFromFile(NULL, riid, pidl, (LPVOID*)&pObj);
534 SHFree (pidl);
535 }
536 else if (IsEqualIID (riid, &IID_IContextMenu))
537 {
538 if (cidl > 0)
539 pObj = (LPUNKNOWN) ISvItemCm_Constructor( (IShellFolder *) iface, This->pidlRoot, apidl, cidl);
540 else
541 pObj = (LPUNKNOWN) ISvBgCm_Constructor( (IShellFolder *) iface, TRUE);
542 hr = S_OK;
543 }
544 else if (IsEqualIID (riid, &IID_IExtractIconA) && (cidl == 1))
545 {
546 pidl = ILCombine (This->pidlRoot, apidl[0]);
547 pObj = (LPUNKNOWN) IExtractIconA_Constructor (pidl);
548 SHFree (pidl);
549 hr = S_OK;
550 }
551 else if (IsEqualIID (riid, &IID_IExtractIconW) && (cidl == 1))
552 {
553 pidl = ILCombine (This->pidlRoot, apidl[0]);
554 pObj = (LPUNKNOWN) IExtractIconW_Constructor (pidl);
555 SHFree (pidl);
556 hr = S_OK;
557 }
558 else if (IsEqualIID (riid, &IID_IDropTarget) && (cidl >= 1))
559 {
560 hr = IShellFolder_QueryInterface (iface,
561 &IID_IDropTarget, (LPVOID *) & pObj);
562 }
563 else
564 hr = E_NOINTERFACE;
565
566 if (SUCCEEDED(hr) && !pObj)
567 hr = E_OUTOFMEMORY;
568
569 *ppvOut = pObj;
570 TRACE ("(%p)->hr=0x%08lx\n", This, hr);
571 return hr;
572 }
573
574 /**************************************************************************
575 * ISF_Desktop_fnGetDisplayNameOf
576 *
577 * NOTES
578 * special case: pidl = null gives desktop-name back
579 */
580 static HRESULT WINAPI ISF_Desktop_fnGetDisplayNameOf (IShellFolder2 * iface,
581 LPCITEMIDLIST pidl, DWORD dwFlags, LPSTRRET strRet)
582 {
583 IGenericSFImpl *This = (IGenericSFImpl *)iface;
584 CHAR szPath[MAX_PATH];
585 GUID const *clsid;
586 HRESULT hr = S_OK;
587
588 *szPath = '\0';
589
590 TRACE ("(%p)->(pidl=%p,0x%08lx,%p)\n", This, pidl, dwFlags, strRet);
591 pdump (pidl);
592
593 if (!strRet)
594 return E_INVALIDARG;
595
596 if (_ILIsDesktop (pidl))
597 {
598 if ((GET_SHGDN_RELATION (dwFlags) == SHGDN_NORMAL) &&
599 (GET_SHGDN_FOR (dwFlags) == SHGDN_FORPARSING))
600 {
601 lstrcpyA (szPath, This->sPathTarget);
602 }
603 else
604 HCR_GetClassNameA(&CLSID_ShellDesktop, szPath, MAX_PATH);
605 }
606 else if (_ILIsPidlSimple (pidl))
607 {
608 if ((clsid = _ILGetGUIDPointer (pidl)))
609 {
610 if (GET_SHGDN_FOR (dwFlags) == SHGDN_FORPARSING)
611 {
612 int bWantsForParsing;
613
614 /*
615 * We can only get a filesystem path from a shellfolder if the
616 * value WantsFORPARSING in CLSID\\{...}\\shellfolder exists.
617 *
618 * Exception: The MyComputer folder doesn't have this key,
619 * but any other filesystem backed folder it needs it.
620 */
621 if (IsEqualIID (clsid, &CLSID_MyComputer))
622 {
623 bWantsForParsing = 1;
624 }
625 else
626 {
627 /* get the "WantsFORPARSING" flag from the registry */
628 static const WCHAR clsidW[] =
629 { 'C','L','S','I','D','\\',0 };
630 static const WCHAR shellfolderW[] =
631 { '\\','s','h','e','l','l','f','o','l','d','e','r',0 };
632 static const WCHAR wantsForParsingW[] =
633 { 'W','a','n','t','s','F','o','r','P','a','r','s','i','n',
634 'g',0 };
635 WCHAR szRegPath[100];
636 LONG r;
637
638 lstrcpyW (szRegPath, clsidW);
639 SHELL32_GUIDToStringW (clsid, &szRegPath[6]);
640 lstrcatW (szRegPath, shellfolderW);
641 r = SHGetValueW(HKEY_CLASSES_ROOT, szRegPath,
642 wantsForParsingW, NULL, NULL, NULL);
643 if (r == ERROR_SUCCESS)
644 bWantsForParsing = TRUE;
645 else
646 bWantsForParsing = FALSE;
647 }
648
649 if ((GET_SHGDN_RELATION (dwFlags) == SHGDN_NORMAL) &&
650 bWantsForParsing)
651 {
652 /*
653 * we need the filesystem path to the destination folder.
654 * Only the folder itself can know it
655 */
656 hr = SHELL32_GetDisplayNameOfChild (iface, pidl, dwFlags,
657 szPath, MAX_PATH);
658 }
659 else
660 {
661 /* parsing name like ::{...} */
662 lstrcpyA (szPath, "::");
663 SHELL32_GUIDToStringA (clsid, &szPath[2]);
664 }
665 }
666 else
667 {
668 /* user friendly name */
669 HCR_GetClassNameA (clsid, szPath, MAX_PATH);
670 }
671 }
672 else
673 {
674 /* file system folder */
675 _ILSimpleGetText (pidl, szPath, MAX_PATH);
676
677 if (!_ILIsFolder(pidl))
678 SHELL_FS_ProcessDisplayFilename(szPath, dwFlags);
679 }
680 }
681 else
682 {
683 /* a complex pidl, let the subfolder do the work */
684 hr = SHELL32_GetDisplayNameOfChild (iface, pidl, dwFlags, szPath, MAX_PATH);
685 }
686
687 if (SUCCEEDED (hr))
688 {
689 strRet->uType = STRRET_CSTR;
690 lstrcpynA (strRet->u.cStr, szPath, MAX_PATH);
691 }
692
693 TRACE ("-- (%p)->(%s,0x%08lx)\n", This, szPath, hr);
694 return hr;
695 }
696
697 /**************************************************************************
698 * ISF_Desktop_fnSetNameOf
699 * Changes the name of a file object or subfolder, possibly changing its item
700 * identifier in the process.
701 *
702 * PARAMETERS
703 * HWND hwndOwner, //[in ] Owner window for output
704 * LPCITEMIDLIST pidl, //[in ] simple pidl of item to change
705 * LPCOLESTR lpszName, //[in ] the items new display name
706 * DWORD dwFlags, //[in ] SHGNO formatting flags
707 * LPITEMIDLIST* ppidlOut) //[out] simple pidl returned
708 */
709 static HRESULT WINAPI ISF_Desktop_fnSetNameOf (IShellFolder2 * iface,
710 HWND hwndOwner, LPCITEMIDLIST pidl, /* simple pidl */
711 LPCOLESTR lpName, DWORD dwFlags, LPITEMIDLIST * pPidlOut)
712 {
713 IGenericSFImpl *This = (IGenericSFImpl *)iface;
714
715 FIXME ("(%p)->(%p,pidl=%p,%s,%lu,%p)\n", This, hwndOwner, pidl,
716 debugstr_w (lpName), dwFlags, pPidlOut);
717
718 return E_FAIL;
719 }
720
721 static HRESULT WINAPI ISF_Desktop_fnGetDefaultSearchGUID(IShellFolder2 *iface,
722 GUID * pguid)
723 {
724 IGenericSFImpl *This = (IGenericSFImpl *)iface;
725
726 FIXME ("(%p)\n", This);
727 return E_NOTIMPL;
728 }
729
730 static HRESULT WINAPI ISF_Desktop_fnEnumSearches (IShellFolder2 *iface,
731 IEnumExtraSearch ** ppenum)
732 {
733 IGenericSFImpl *This = (IGenericSFImpl *)iface;
734 FIXME ("(%p)\n", This);
735 return E_NOTIMPL;
736 }
737
738 static HRESULT WINAPI ISF_Desktop_fnGetDefaultColumn (IShellFolder2 * iface,
739 DWORD dwRes, ULONG * pSort, ULONG * pDisplay)
740 {
741 IGenericSFImpl *This = (IGenericSFImpl *)iface;
742
743 TRACE ("(%p)\n", This);
744
745 if (pSort)
746 *pSort = 0;
747 if (pDisplay)
748 *pDisplay = 0;
749
750 return S_OK;
751 }
752 static HRESULT WINAPI ISF_Desktop_fnGetDefaultColumnState (
753 IShellFolder2 * iface, UINT iColumn, DWORD * pcsFlags)
754 {
755 IGenericSFImpl *This = (IGenericSFImpl *)iface;
756
757 TRACE ("(%p)\n", This);
758
759 if (!pcsFlags || iColumn >= DESKTOPSHELLVIEWCOLUMNS)
760 return E_INVALIDARG;
761
762 *pcsFlags = DesktopSFHeader[iColumn].pcsFlags;
763
764 return S_OK;
765 }
766
767 static HRESULT WINAPI ISF_Desktop_fnGetDetailsEx (IShellFolder2 * iface,
768 LPCITEMIDLIST pidl, const SHCOLUMNID * pscid, VARIANT * pv)
769 {
770 IGenericSFImpl *This = (IGenericSFImpl *)iface;
771 FIXME ("(%p)\n", This);
772
773 return E_NOTIMPL;
774 }
775
776 static HRESULT WINAPI ISF_Desktop_fnGetDetailsOf (IShellFolder2 * iface,
777 LPCITEMIDLIST pidl, UINT iColumn, SHELLDETAILS * psd)
778 {
779 IGenericSFImpl *This = (IGenericSFImpl *)iface;
780
781 HRESULT hr = E_FAIL;
782
783 TRACE ("(%p)->(%p %i %p)\n", This, pidl, iColumn, psd);
784
785 if (!psd || iColumn >= DESKTOPSHELLVIEWCOLUMNS)
786 return E_INVALIDARG;
787
788 if (!pidl)
789 {
790 psd->fmt = DesktopSFHeader[iColumn].fmt;
791 psd->cxChar = DesktopSFHeader[iColumn].cxChar;
792 psd->str.uType = STRRET_CSTR;
793 LoadStringA (shell32_hInstance, DesktopSFHeader[iColumn].colnameid,
794 psd->str.u.cStr, MAX_PATH);
795 return S_OK;
796 }
797
798 /* the data from the pidl */
799 switch (iColumn)
800 {
801 case 0: /* name */
802 hr = IShellFolder_GetDisplayNameOf(iface, pidl,
803 SHGDN_NORMAL | SHGDN_INFOLDER, &psd->str);
804 break;
805 case 1: /* size */
806 _ILGetFileSize (pidl, psd->str.u.cStr, MAX_PATH);
807 break;
808 case 2: /* type */
809 _ILGetFileType (pidl, psd->str.u.cStr, MAX_PATH);
810 break;
811 case 3: /* date */
812 _ILGetFileDate (pidl, psd->str.u.cStr, MAX_PATH);
813 break;
814 case 4: /* attributes */
815 _ILGetFileAttributes (pidl, psd->str.u.cStr, MAX_PATH);
816 break;
817 }
818 hr = S_OK;
819 psd->str.uType = STRRET_CSTR;
820
821 return hr;
822 }
823
824 static HRESULT WINAPI ISF_Desktop_fnMapColumnToSCID (
825 IShellFolder2 * iface, UINT column, SHCOLUMNID * pscid)
826 {
827 IGenericSFImpl *This = (IGenericSFImpl *)iface;
828 FIXME ("(%p)\n", This);
829 return E_NOTIMPL;
830 }
831
832 static IShellFolder2Vtbl vt_MCFldr_ShellFolder2 =
833 {
834 ISF_Desktop_fnQueryInterface,
835 ISF_Desktop_fnAddRef,
836 ISF_Desktop_fnRelease,
837 ISF_Desktop_fnParseDisplayName,
838 ISF_Desktop_fnEnumObjects,
839 ISF_Desktop_fnBindToObject,
840 ISF_Desktop_fnBindToStorage,
841 ISF_Desktop_fnCompareIDs,
842 ISF_Desktop_fnCreateViewObject,
843 ISF_Desktop_fnGetAttributesOf,
844 ISF_Desktop_fnGetUIObjectOf,
845 ISF_Desktop_fnGetDisplayNameOf,
846 ISF_Desktop_fnSetNameOf,
847 /* ShellFolder2 */
848 ISF_Desktop_fnGetDefaultSearchGUID,
849 ISF_Desktop_fnEnumSearches,
850 ISF_Desktop_fnGetDefaultColumn,
851 ISF_Desktop_fnGetDefaultColumnState,
852 ISF_Desktop_fnGetDetailsEx,
853 ISF_Desktop_fnGetDetailsOf,
854 ISF_Desktop_fnMapColumnToSCID
855 };