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