Revert an unwanted change from r66575.
[reactos.git] / reactos / dll / win32 / shell32 / shfldr_mydocuments.c
1
2 /*
3 * Virtual MyDocuments Folder
4 *
5 * Copyright 2007 Johannes Anderwald
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 */
21
22 #include <precomp.h>
23
24 WINE_DEFAULT_DEBUG_CHANNEL (mydocs);
25
26 /***********************************************************************
27 * MyDocumentsfolder implementation
28 */
29
30 typedef struct {
31 const IShellFolder2Vtbl *lpVtbl;
32 const IPersistFolder2Vtbl *lpPF2;
33 LONG ref;
34
35 /* both paths are parsible from the MyDocuments */
36 LPWSTR sPathTarget; /* complete path to target used for enumeration and ChangeNotify */
37 LPITEMIDLIST pidlRoot; /* absolute pidl */
38
39 UINT cfShellIDList; /* clipboardformat for IDropTarget */
40 BOOL fAcceptFmt; /* flag for pending Drop */
41 } IGenericSFImpl, *LPIGenericSFImpl;
42
43 #define _IUnknown_(This) (IShellFolder*)&(This->lpVtbl)
44 #define _IShellFolder_(This) (IShellFolder*)&(This->lpVtbl)
45
46 static const shvheader MyDocumentsSFHeader[] = {
47 {IDS_SHV_COLUMN1, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 15},
48 {IDS_SHV_COLUMN2, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
49 {IDS_SHV_COLUMN3, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
50 {IDS_SHV_COLUMN4, SHCOLSTATE_TYPE_DATE | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 12},
51 {IDS_SHV_COLUMN5, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 5}
52 };
53
54 #define MYDOCUMENTSSHELLVIEWCOLUMNS 5
55
56 /**************************************************************************
57 * ISF_MyDocuments_fnQueryInterface
58 *
59 * NOTES supports not IPersist/IPersistFolder
60 */
61 static HRESULT WINAPI ISF_MyDocuments_fnQueryInterface(
62 IShellFolder2 * iface, REFIID riid, LPVOID * ppvObj)
63 {
64 IGenericSFImpl *This = (IGenericSFImpl *)iface;
65
66 TRACE ("(%p)->(%s,%p)\n", This, shdebugstr_guid (riid), ppvObj);
67
68 *ppvObj = NULL;
69
70 if (IsEqualIID (riid, &IID_IUnknown) ||
71 IsEqualIID (riid, &IID_IShellFolder) ||
72 IsEqualIID (riid, &IID_IShellFolder2))
73 {
74 *ppvObj = This;
75 }
76 else if (IsEqualIID (riid, &IID_IPersistFolder) ||
77 IsEqualIID (riid, &IID_IPersistFolder2))
78 {
79 *ppvObj = (void *)&This->lpPF2;
80 }
81 if (*ppvObj)
82 {
83 IUnknown_AddRef ((IUnknown *) (*ppvObj));
84 TRACE ("-- Interface: (%p)->(%p)\n", ppvObj, *ppvObj);
85 return S_OK;
86 }
87 TRACE ("-- Interface: E_NOINTERFACE\n");
88 return E_NOINTERFACE;
89 }
90
91 static ULONG WINAPI ISF_MyDocuments_fnAddRef (IShellFolder2 * iface)
92 {
93 IGenericSFImpl *This = (IGenericSFImpl *)iface;
94 ULONG refCount = InterlockedIncrement(&This->ref);
95
96 TRACE ("(%p)->(count=%u)\n", This, refCount - 1);
97
98 return refCount;
99 }
100
101 static ULONG WINAPI ISF_MyDocuments_fnRelease (IShellFolder2 * iface)
102 {
103 IGenericSFImpl *This = (IGenericSFImpl *)iface;
104 ULONG refCount = InterlockedDecrement(&This->ref);
105
106 TRACE ("(%p)->(count=%u)\n", This, refCount + 1);
107
108 if (!refCount)
109 {
110 TRACE ("-- destroying IShellFolder(%p)\n", This);
111 SHFree (This->pidlRoot);
112 HeapFree(GetProcessHeap(), 0, This->sPathTarget);
113 HeapFree(GetProcessHeap(), 0, This);
114 }
115 return refCount;
116 }
117
118 static
119 HRESULT
120 WINAPI ISF_MyDocuments_fnParseDisplayName (IShellFolder2 * iface,
121 HWND hwndOwner, LPBC pbc, LPOLESTR lpszDisplayName,
122 DWORD * pchEaten, LPITEMIDLIST * ppidl, DWORD * pdwAttributes)
123 {
124 IGenericSFImpl *This = (IGenericSFImpl *)iface;
125 WCHAR szElement[MAX_PATH];
126 LPCWSTR szNext = NULL;
127 LPITEMIDLIST pidlTemp = NULL;
128 HRESULT hr = S_OK;
129 CLSID clsid;
130
131 TRACE ("(%p)->(HWND=%p,%p,%p=%s,%p,pidl=%p,%p)\n",
132 This, hwndOwner, pbc, lpszDisplayName, debugstr_w(lpszDisplayName),
133 pchEaten, ppidl, pdwAttributes);
134
135 if (!lpszDisplayName || !ppidl)
136 return E_INVALIDARG;
137
138 *ppidl = 0;
139
140 if (pchEaten)
141 *pchEaten = 0; /* strange but like the original */
142
143 if (lpszDisplayName[0] == ':' && lpszDisplayName[1] == ':')
144 {
145 szNext = GetNextElementW (lpszDisplayName, szElement, MAX_PATH);
146 TRACE ("-- element: %s\n", debugstr_w (szElement));
147 CLSIDFromString (szElement + 2, &clsid);
148 pidlTemp = _ILCreateGuid (PT_GUID, &clsid);
149 }
150 else if( (pidlTemp = SHELL32_CreatePidlFromBindCtx(pbc, lpszDisplayName)) )
151 {
152 *ppidl = pidlTemp;
153 return S_OK;
154 }
155 else
156 {
157 /* it's a filesystem path on the desktop. Let a FSFolder parse it */
158
159 if (*lpszDisplayName)
160 {
161 WCHAR szPath[MAX_PATH];
162 LPWSTR pathPtr;
163
164 /* build a complete path to create a simple pidl */
165 lstrcpynW(szPath, This->sPathTarget, MAX_PATH);
166 pathPtr = PathAddBackslashW(szPath);
167 if (pathPtr)
168 {
169 lstrcpynW(pathPtr, lpszDisplayName, MAX_PATH - (pathPtr - szPath));
170 hr = _ILCreateFromPathW(szPath, &pidlTemp);
171 }
172 else
173 {
174 /* should never reach here, but for completeness */
175 hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
176 }
177 }
178 else
179 pidlTemp = _ILCreateMyDocuments();
180
181 szNext = NULL;
182 }
183
184 if (SUCCEEDED(hr) && pidlTemp)
185 {
186 if (szNext && *szNext)
187 {
188 hr = SHELL32_ParseNextElement(iface, hwndOwner, pbc,
189 &pidlTemp, (LPOLESTR) szNext, pchEaten, pdwAttributes);
190 }
191 else
192 {
193 if (pdwAttributes && *pdwAttributes)
194 hr = SHELL32_GetItemAttributes(_IShellFolder_ (This),
195 pidlTemp, pdwAttributes);
196 }
197 }
198
199 *ppidl = pidlTemp;
200
201 TRACE ("(%p)->(-- ret=0x%08x)\n", This, hr);
202
203 return hr;
204 }
205
206 /**************************************************************************
207 * CreateMyDocumentsEnumList()
208 */
209 static BOOL CreateMyDocumentsEnumList(IEnumIDList *list, DWORD dwFlags)
210 {
211 BOOL ret = TRUE;
212 WCHAR szPath[MAX_PATH] = {0};
213
214 TRACE("(%p)->(flags=0x%08x)\n", list, dwFlags);
215
216 /* enumerate the elements in %windir%\desktop */
217 ret = SHGetSpecialFolderPathW(0, szPath, CSIDL_PERSONAL, FALSE);
218 ret = ret && CreateFolderEnumList(list, szPath, dwFlags);
219
220 return ret;
221 }
222
223 /**************************************************************************
224 * ISF_MyDocuments_fnEnumObjects
225 */
226 static HRESULT WINAPI ISF_MyDocuments_fnEnumObjects (IShellFolder2 * iface,
227 HWND hwndOwner, DWORD dwFlags, LPENUMIDLIST * ppEnumIDList)
228 {
229 IGenericSFImpl *This = (IGenericSFImpl *)iface;
230
231 TRACE ("(%p)->(HWND=%p flags=0x%08x pplist=%p)\n",
232 This, hwndOwner, dwFlags, ppEnumIDList);
233
234 *ppEnumIDList = IEnumIDList_Constructor();
235 if (*ppEnumIDList)
236 CreateMyDocumentsEnumList(*ppEnumIDList, dwFlags);
237
238 TRACE ("-- (%p)->(new ID List: %p)\n", This, *ppEnumIDList);
239
240 return *ppEnumIDList ? S_OK : E_OUTOFMEMORY;
241 }
242
243 /**************************************************************************
244 * ISF_MyDocuments_fnBindToObject
245 */
246 static HRESULT WINAPI ISF_MyDocuments_fnBindToObject (IShellFolder2 * iface,
247 LPCITEMIDLIST pidl, LPBC pbcReserved, REFIID riid, LPVOID * ppvOut)
248 {
249 IGenericSFImpl *This = (IGenericSFImpl *)iface;
250
251 TRACE ("(%p)->(pidl=%p,%p,%s,%p)\n",
252 This, pidl, pbcReserved, shdebugstr_guid (riid), ppvOut);
253
254 return SHELL32_BindToChild( This->pidlRoot, This->sPathTarget, pidl, riid, ppvOut );
255 }
256
257 /**************************************************************************
258 * ISF_MyDocuments_fnBindToStorage
259 */
260 static
261 HRESULT
262 WINAPI
263 ISF_MyDocuments_fnBindToStorage (IShellFolder2 * iface,
264 LPCITEMIDLIST pidl, LPBC pbcReserved, REFIID riid, LPVOID * ppvOut)
265 {
266 IGenericSFImpl *This = (IGenericSFImpl *)iface;
267
268 FIXME ("(%p)->(pidl=%p,%p,%s,%p) stub\n",
269 This, pidl, pbcReserved, shdebugstr_guid (riid), ppvOut);
270
271 *ppvOut = NULL;
272 return E_NOTIMPL;
273 }
274
275 /**************************************************************************
276 * ISF_MyDocuments_fnCompareIDs
277 */
278 static HRESULT WINAPI ISF_MyDocuments_fnCompareIDs (IShellFolder2 * iface,
279 LPARAM lParam, LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
280 {
281 IGenericSFImpl *This = (IGenericSFImpl *)iface;
282 int nReturn;
283
284 TRACE ("(%p)->(0x%08lx,pidl1=%p,pidl2=%p)\n", This, lParam, pidl1, pidl2);
285 nReturn = SHELL32_CompareIDs (_IShellFolder_ (This), lParam, pidl1, pidl2);
286 TRACE ("-- %i\n", nReturn);
287 return nReturn;
288 }
289
290 /**************************************************************************
291 * ISF_MyDocuments_fnCreateViewObject
292 */
293 static HRESULT WINAPI ISF_MyDocuments_fnCreateViewObject (IShellFolder2 * iface,
294 HWND hwndOwner, REFIID riid, LPVOID * ppvOut)
295 {
296 IGenericSFImpl *This = (IGenericSFImpl *)iface;
297 LPSHELLVIEW pShellView;
298 HRESULT hr = E_INVALIDARG;
299
300 TRACE ("(%p)->(hwnd=%p,%s,%p)\n",
301 This, hwndOwner, shdebugstr_guid (riid), ppvOut);
302
303 if (!ppvOut)
304 return hr;
305
306 *ppvOut = NULL;
307
308 if (IsEqualIID (riid, &IID_IDropTarget))
309 {
310 WARN ("IDropTarget not implemented\n");
311 hr = E_NOTIMPL;
312 }
313 else if (IsEqualIID (riid, &IID_IContextMenu))
314 {
315 WARN ("IContextMenu not implemented\n");
316 hr = E_NOTIMPL;
317 }
318 else if (IsEqualIID (riid, &IID_IShellView))
319 {
320 pShellView = IShellView_Constructor ((IShellFolder *) iface);
321 if (pShellView)
322 {
323 hr = IShellView_QueryInterface (pShellView, riid, ppvOut);
324 IShellView_Release (pShellView);
325 }
326 }
327 TRACE ("-- (%p)->(interface=%p)\n", This, ppvOut);
328 return hr;
329 }
330
331 /**************************************************************************
332 * ISF_MyDocuments_fnGetAttributesOf
333 */
334 static HRESULT WINAPI ISF_MyDocuments_fnGetAttributesOf (IShellFolder2 * iface,
335 UINT cidl, LPCITEMIDLIST * apidl, DWORD * rgfInOut)
336 {
337 IGenericSFImpl *This = (IGenericSFImpl *)iface;
338 HRESULT hr = S_OK;
339 static const DWORD dwMyDocumentsAttributes =
340 SFGAO_STORAGE | SFGAO_HASPROPSHEET | SFGAO_STORAGEANCESTOR | SFGAO_CANCOPY |
341 SFGAO_FILESYSANCESTOR | SFGAO_FOLDER | SFGAO_FILESYSTEM | SFGAO_HASSUBFOLDER | SFGAO_CANRENAME | SFGAO_CANDELETE;
342
343 TRACE ("(%p)->(cidl=%d apidl=%p mask=%p (0x%08x))\n",
344 This, cidl, apidl, rgfInOut, rgfInOut ? *rgfInOut : 0);
345
346 if (!rgfInOut)
347 return E_INVALIDARG;
348 if (cidl && !apidl)
349 return E_INVALIDARG;
350
351 if (*rgfInOut == 0)
352 *rgfInOut = ~0;
353
354 if(cidl == 0) {
355 *rgfInOut &= dwMyDocumentsAttributes;
356 } else {
357 while (cidl > 0 && *apidl) {
358 pdump (*apidl);
359 if (_ILIsMyDocuments(*apidl)) {
360 *rgfInOut &= dwMyDocumentsAttributes;
361 } else {
362 SHELL32_GetItemAttributes (_IShellFolder_ (This), *apidl, rgfInOut);
363 }
364 apidl++;
365 cidl--;
366 }
367 }
368 /* make sure SFGAO_VALIDATE is cleared, some apps depend on that */
369 *rgfInOut &= ~SFGAO_VALIDATE;
370
371 TRACE ("-- result=0x%08x\n", *rgfInOut);
372
373 return hr;
374 }
375
376 /**************************************************************************
377 * ISF_MyDocuments_fnGetUIObjectOf
378 *
379 * PARAMETERS
380 * HWND hwndOwner, //[in ] Parent window for any output
381 * UINT cidl, //[in ] array size
382 * LPCITEMIDLIST* apidl, //[in ] simple pidl array
383 * REFIID riid, //[in ] Requested Interface
384 * UINT* prgfInOut, //[ ] reserved
385 * LPVOID* ppvObject) //[out] Resulting Interface
386 *
387 */
388 static HRESULT WINAPI ISF_MyDocuments_fnGetUIObjectOf (IShellFolder2 * iface,
389 HWND hwndOwner, UINT cidl, LPCITEMIDLIST * apidl,
390 REFIID riid, UINT * prgfInOut, LPVOID * ppvOut)
391 {
392 IGenericSFImpl *This = (IGenericSFImpl *)iface;
393
394 LPITEMIDLIST pidl;
395 IUnknown *pObj = NULL;
396 HRESULT hr = E_INVALIDARG;
397
398 TRACE ("(%p)->(%p,%u,apidl=%p,%s,%p,%p)\n",
399 This, hwndOwner, cidl, apidl, shdebugstr_guid (riid), prgfInOut, ppvOut);
400
401 if (!ppvOut)
402 return hr;
403
404 *ppvOut = NULL;
405
406 if (IsEqualIID (riid, &IID_IContextMenu))
407 {
408 hr = CDefFolderMenu_Create2(This->pidlRoot, hwndOwner, cidl, apidl, (IShellFolder*)iface, NULL, 0, NULL, (IContextMenu**)&pObj);
409 }
410 else if (IsEqualIID (riid, &IID_IDataObject) && (cidl >= 1))
411 {
412 pObj = (LPUNKNOWN) IDataObject_Constructor( hwndOwner,
413 This->pidlRoot, apidl, cidl);
414 hr = S_OK;
415 }
416 else if (IsEqualIID (riid, &IID_IExtractIconA) && (cidl == 1))
417 {
418 pidl = ILCombine (This->pidlRoot, apidl[0]);
419 pObj = (LPUNKNOWN) IExtractIconA_Constructor (pidl);
420 SHFree (pidl);
421 hr = S_OK;
422 }
423 else if (IsEqualIID (riid, &IID_IExtractIconW) && (cidl == 1))
424 {
425 pidl = ILCombine (This->pidlRoot, apidl[0]);
426 pObj = (LPUNKNOWN) IExtractIconW_Constructor (pidl);
427 SHFree (pidl);
428 hr = S_OK;
429 }
430 else if (IsEqualIID (riid, &IID_IDropTarget) && (cidl >= 1))
431 {
432 hr = IShellFolder_QueryInterface (iface,
433 &IID_IDropTarget, (LPVOID *) & pObj);
434 }
435 else if ((IsEqualIID(riid,&IID_IShellLinkW) ||
436 IsEqualIID(riid,&IID_IShellLinkA)) && (cidl == 1))
437 {
438 pidl = ILCombine (This->pidlRoot, apidl[0]);
439 hr = IShellLink_ConstructFromFile(NULL, riid, pidl, (LPVOID*)&pObj);
440 SHFree (pidl);
441 }
442 else
443 hr = E_NOINTERFACE;
444
445 if (SUCCEEDED(hr) && !pObj)
446 hr = E_OUTOFMEMORY;
447
448 *ppvOut = pObj;
449 TRACE ("(%p)->hr=0x%08x\n", This, hr);
450 return hr;
451 }
452
453 static
454 HRESULT
455 WINAPI ISF_MyDocuments_fnGetDisplayNameOf (IShellFolder2 * iface,
456 LPCITEMIDLIST pidl, DWORD dwFlags, LPSTRRET strRet)
457 {
458 IGenericSFImpl *This = (IGenericSFImpl *)iface;
459 HRESULT hr = S_OK;
460 LPWSTR pszPath;
461
462 TRACE ("(%p)->(pidl=%p,0x%08x,%p)\n", This, pidl, dwFlags, strRet);
463 pdump (pidl);
464
465 if (!strRet)
466 return E_INVALIDARG;
467
468 pszPath = CoTaskMemAlloc((MAX_PATH +1) * sizeof(WCHAR));
469 if (!pszPath)
470 return E_OUTOFMEMORY;
471
472 ZeroMemory(pszPath, (MAX_PATH +1) * sizeof(WCHAR));
473
474 if (_ILIsMyDocuments (pidl))
475 {
476 if ((GET_SHGDN_RELATION (dwFlags) == SHGDN_NORMAL) &&
477 (GET_SHGDN_FOR (dwFlags) & SHGDN_FORPARSING))
478 wcscpy(pszPath, This->sPathTarget);
479 else
480 HCR_GetClassNameW(&CLSID_MyDocuments, pszPath, MAX_PATH);
481 TRACE("CP\n");
482 }
483 else if (_ILIsPidlSimple (pidl))
484 {
485 GUID const *clsid;
486
487 if ((clsid = _ILGetGUIDPointer (pidl)))
488 {
489 if (GET_SHGDN_FOR (dwFlags) & SHGDN_FORPARSING)
490 {
491 int bWantsForParsing;
492
493 /*
494 * We can only get a filesystem path from a shellfolder if the
495 * value WantsFORPARSING in CLSID\\{...}\\shellfolder exists.
496 *
497 * Exception: The MyComputer folder doesn't have this key,
498 * but any other filesystem backed folder it needs it.
499 */
500 if (IsEqualIID (clsid, &CLSID_MyDocuments))
501 {
502 bWantsForParsing = TRUE;
503 }
504 else
505 {
506 /* get the "WantsFORPARSING" flag from the registry */
507 static const WCHAR clsidW[] =
508 { 'C','L','S','I','D','\\',0 };
509 static const WCHAR shellfolderW[] =
510 { '\\','s','h','e','l','l','f','o','l','d','e','r',0 };
511 static const WCHAR wantsForParsingW[] =
512 { 'W','a','n','t','s','F','o','r','P','a','r','s','i','n',
513 'g',0 };
514 WCHAR szRegPath[100];
515 LONG r;
516
517 wcscpy (szRegPath, clsidW);
518 SHELL32_GUIDToStringW (clsid, &szRegPath[6]);
519 wcscat (szRegPath, shellfolderW);
520 r = SHGetValueW(HKEY_CLASSES_ROOT, szRegPath,
521 wantsForParsingW, NULL, NULL, NULL);
522 if (r == ERROR_SUCCESS)
523 bWantsForParsing = TRUE;
524 else
525 bWantsForParsing = FALSE;
526 }
527
528 if ((GET_SHGDN_RELATION (dwFlags) == SHGDN_NORMAL) &&
529 bWantsForParsing)
530 {
531 /*
532 * we need the filesystem path to the destination folder.
533 * Only the folder itself can know it
534 */
535 hr = SHELL32_GetDisplayNameOfChild (iface, pidl, dwFlags,
536 pszPath,
537 MAX_PATH);
538 TRACE("CP\n");
539 }
540 else
541 {
542 /* parsing name like ::{...} */
543 pszPath[0] = ':';
544 pszPath[1] = ':';
545 SHELL32_GUIDToStringW (clsid, &pszPath[2]);
546 TRACE("CP\n");
547 }
548 }
549 else
550 {
551 /* user friendly name */
552 HCR_GetClassNameW (clsid, pszPath, MAX_PATH);
553 TRACE("CP\n");
554 }
555 }
556 else
557 {
558 int cLen = 0;
559
560 /* file system folder or file rooted at the desktop */
561 if ((GET_SHGDN_FOR(dwFlags) == SHGDN_FORPARSING) &&
562 (GET_SHGDN_RELATION(dwFlags) != SHGDN_INFOLDER))
563 {
564 lstrcpynW(pszPath, This->sPathTarget, MAX_PATH - 1);
565 TRACE("CP %s\n", debugstr_w(pszPath));
566 }
567
568 if (!_ILIsDesktop(pidl))
569 {
570 PathAddBackslashW(pszPath);
571 cLen = wcslen(pszPath);
572 _ILSimpleGetTextW(pidl, pszPath + cLen, MAX_PATH - cLen);
573 if (!_ILIsFolder(pidl))
574 {
575 SHELL_FS_ProcessDisplayFilename(pszPath, dwFlags);
576 TRACE("CP\n");
577 }
578 }
579 }
580 }
581 else
582 {
583 /* a complex pidl, let the subfolder do the work */
584 hr = SHELL32_GetDisplayNameOfChild (iface, pidl, dwFlags,
585 pszPath, MAX_PATH);
586 TRACE("CP\n");
587 }
588
589 if (SUCCEEDED(hr))
590 {
591 strRet->uType = STRRET_WSTR;
592 strRet->u.pOleStr = pszPath;
593 }
594 else
595 CoTaskMemFree(pszPath);
596
597 TRACE ("-- (%p)->(%s,0x%08x)\n", This, debugstr_w(strRet->u.pOleStr), hr);
598 return hr;
599 }
600
601 static HRESULT WINAPI ISF_MyDocuments_fnSetNameOf (IShellFolder2 * iface,
602 HWND hwndOwner, LPCITEMIDLIST pidl, /* simple pidl */
603 LPCOLESTR lpName, DWORD dwFlags, LPITEMIDLIST * pPidlOut)
604 {
605 IGenericSFImpl *This = (IGenericSFImpl *)iface;
606
607 FIXME ("(%p)->(%p,pidl=%p,%s,%u,%p)\n", This, hwndOwner, pidl,
608 debugstr_w (lpName), dwFlags, pPidlOut);
609
610 return E_FAIL;
611 }
612
613 static HRESULT WINAPI ISF_MyDocuments_fnGetDefaultSearchGUID(IShellFolder2 *iface,
614 GUID * pguid)
615 {
616 IGenericSFImpl *This = (IGenericSFImpl *)iface;
617
618 FIXME ("(%p)\n", This);
619 return E_NOTIMPL;
620 }
621
622 static HRESULT WINAPI ISF_MyDocuments_fnEnumSearches (IShellFolder2 *iface,
623 IEnumExtraSearch ** ppenum)
624 {
625 IGenericSFImpl *This = (IGenericSFImpl *)iface;
626 FIXME ("(%p)\n", This);
627 return E_NOTIMPL;
628 }
629
630 static
631 HRESULT
632 WINAPI
633 ISF_MyDocuments_fnGetDefaultColumn (IShellFolder2 * iface,
634 DWORD dwRes, ULONG * pSort, ULONG * pDisplay)
635 {
636 IGenericSFImpl *This = (IGenericSFImpl *)iface;
637
638 TRACE ("(%p)\n", This);
639
640 if (pSort)
641 *pSort = 0;
642 if (pDisplay)
643 *pDisplay = 0;
644
645 return S_OK;
646 }
647 static
648 HRESULT
649 WINAPI
650 ISF_MyDocuments_fnGetDefaultColumnState (IShellFolder2 * iface, UINT iColumn, DWORD * pcsFlags)
651 {
652 IGenericSFImpl *This = (IGenericSFImpl *)iface;
653
654 TRACE ("(%p)\n", This);
655
656 if (!pcsFlags || iColumn >= MYDOCUMENTSSHELLVIEWCOLUMNS)
657 return E_INVALIDARG;
658
659 *pcsFlags = MyDocumentsSFHeader[iColumn].pcsFlags;
660
661 return S_OK;
662 }
663
664 static
665 HRESULT
666 WINAPI
667 ISF_MyDocuments_fnGetDetailsEx (IShellFolder2 * iface, LPCITEMIDLIST pidl, const SHCOLUMNID * pscid, VARIANT * pv)
668 {
669 IGenericSFImpl *This = (IGenericSFImpl *)iface;
670 FIXME ("(%p)\n", This);
671
672 return E_NOTIMPL;
673 }
674
675 static
676 HRESULT
677 WINAPI
678 ISF_MyDocuments_fnGetDetailsOf (IShellFolder2 * iface, LPCITEMIDLIST pidl, UINT iColumn, SHELLDETAILS * psd)
679 {
680 IGenericSFImpl *This = (IGenericSFImpl *)iface;
681
682 HRESULT hr = S_OK;
683
684 TRACE ("(%p)->(%p %i %p)\n", This, pidl, iColumn, psd);
685
686 if (!psd || iColumn >= MYDOCUMENTSSHELLVIEWCOLUMNS)
687 return E_INVALIDARG;
688
689 if (!pidl)
690 {
691 psd->fmt = MyDocumentsSFHeader[iColumn].fmt;
692 psd->cxChar = MyDocumentsSFHeader[iColumn].cxChar;
693 psd->str.uType = STRRET_CSTR;
694 LoadStringA (shell32_hInstance, MyDocumentsSFHeader[iColumn].colnameid,
695 psd->str.u.cStr, MAX_PATH);
696 return S_OK;
697 }
698
699 /* the data from the pidl */
700 psd->str.uType = STRRET_CSTR;
701 switch (iColumn)
702 {
703 case 0: /* name */
704 hr = IShellFolder_GetDisplayNameOf(iface, pidl,
705 SHGDN_NORMAL | SHGDN_INFOLDER, &psd->str);
706 break;
707 case 1: /* size */
708 _ILGetFileSize (pidl, psd->str.u.cStr, MAX_PATH);
709 break;
710 case 2: /* type */
711 _ILGetFileType (pidl, psd->str.u.cStr, MAX_PATH);
712 break;
713 case 3: /* date */
714 _ILGetFileDate (pidl, psd->str.u.cStr, MAX_PATH);
715 break;
716 case 4: /* attributes */
717 _ILGetFileAttributes (pidl, psd->str.u.cStr, MAX_PATH);
718 break;
719 }
720
721 return hr;
722 }
723
724 static
725 HRESULT
726 WINAPI
727 ISF_MyDocuments_fnMapColumnToSCID (IShellFolder2 * iface, UINT column, SHCOLUMNID * pscid)
728 {
729 IGenericSFImpl *This = (IGenericSFImpl *)iface;
730 FIXME ("(%p)\n", This);
731 return E_NOTIMPL;
732 }
733
734 static const IShellFolder2Vtbl vt_MCFldr_ShellFolder2 =
735 {
736 ISF_MyDocuments_fnQueryInterface,
737 ISF_MyDocuments_fnAddRef,
738 ISF_MyDocuments_fnRelease,
739 ISF_MyDocuments_fnParseDisplayName,
740 ISF_MyDocuments_fnEnumObjects,
741 ISF_MyDocuments_fnBindToObject,
742 ISF_MyDocuments_fnBindToStorage,
743 ISF_MyDocuments_fnCompareIDs,
744 ISF_MyDocuments_fnCreateViewObject,
745 ISF_MyDocuments_fnGetAttributesOf,
746 ISF_MyDocuments_fnGetUIObjectOf,
747 ISF_MyDocuments_fnGetDisplayNameOf,
748 ISF_MyDocuments_fnSetNameOf,
749 /* ShellFolder2 */
750 ISF_MyDocuments_fnGetDefaultSearchGUID,
751 ISF_MyDocuments_fnEnumSearches,
752 ISF_MyDocuments_fnGetDefaultColumn,
753 ISF_MyDocuments_fnGetDefaultColumnState,
754 ISF_MyDocuments_fnGetDetailsEx,
755 ISF_MyDocuments_fnGetDetailsOf,
756 ISF_MyDocuments_fnMapColumnToSCID
757 };
758
759 static LPIGenericSFImpl __inline impl_from_IPersistFolder2( IPersistFolder2 *iface )
760 {
761 return (LPIGenericSFImpl)((char*)iface - FIELD_OFFSET(IGenericSFImpl, lpPF2));
762 }
763
764 static HRESULT WINAPI
765 ISF_MyDocuments_PersistFolder2_fnQueryInterface (IPersistFolder2 * iface, REFIID iid, LPVOID * ppvObj)
766 {
767 IGenericSFImpl *This = impl_from_IPersistFolder2(iface);
768
769 TRACE ("(%p)\n", This);
770
771 return ISF_MyDocuments_fnQueryInterface ((IShellFolder2*)This, iid, ppvObj);
772 }
773
774 static ULONG WINAPI
775 ISF_MyDocuments_PersistFolder2_fnAddRef (IPersistFolder2 * iface)
776 {
777 IGenericSFImpl *This = impl_from_IPersistFolder2(iface);
778
779 TRACE ("(%p)->(count=%u)\n", This, This->ref);
780
781 return ISF_MyDocuments_fnAddRef((IShellFolder2*)This);
782 }
783
784 static ULONG WINAPI
785 ISF_MyDocuments_PersistFolder2_fnRelease (IPersistFolder2 * iface)
786 {
787 IGenericSFImpl *This = impl_from_IPersistFolder2(iface);
788
789 TRACE ("(%p)->(count=%u)\n", This, This->ref);
790
791 return ISF_MyDocuments_fnRelease ((IShellFolder2*)This);
792 }
793
794 static HRESULT WINAPI
795 ISF_MyDocuments_PersistFolder2_fnGetClassID (IPersistFolder2 * iface, CLSID * lpClassId)
796 {
797 IGenericSFImpl *This = impl_from_IPersistFolder2(iface);
798
799 static GUID const CLSID_MyDocuments =
800 { 0x450d8fba, 0xad25, 0x11d0, {0x98,0xa8,0x08,0x00,0x36,0x1b,0x11,0x03} };
801
802 TRACE ("(%p)\n", This);
803
804 if (!lpClassId)
805 return E_POINTER;
806
807 memcpy(lpClassId, &CLSID_MyDocuments, sizeof(GUID));
808
809 return S_OK;
810 }
811 static HRESULT WINAPI
812 ISF_MyDocuments_PersistFolder2_fnInitialize (IPersistFolder2 * iface, LPCITEMIDLIST pidl)
813 {
814 IGenericSFImpl *This = impl_from_IPersistFolder2(iface);
815
816 TRACE ("(%p)->(%p)\n", This, pidl);
817
818 return E_NOTIMPL;
819 }
820
821 static HRESULT WINAPI
822 ISF_MyDocuments_PersistFolder2_fnGetCurFolder (IPersistFolder2 * iface,
823 LPITEMIDLIST * pidl)
824 {
825 IGenericSFImpl *This = impl_from_IPersistFolder2(iface);
826
827 TRACE ("(%p)->(%p)\n", This, pidl);
828
829 if (!pidl) return E_POINTER;
830 *pidl = ILClone (This->pidlRoot);
831 return S_OK;
832 }
833
834 static const IPersistFolder2Vtbl vt_FSFldr_PersistFolder2 =
835 {
836 ISF_MyDocuments_PersistFolder2_fnQueryInterface,
837 ISF_MyDocuments_PersistFolder2_fnAddRef,
838 ISF_MyDocuments_PersistFolder2_fnRelease,
839 ISF_MyDocuments_PersistFolder2_fnGetClassID,
840 ISF_MyDocuments_PersistFolder2_fnInitialize,
841 ISF_MyDocuments_PersistFolder2_fnGetCurFolder,
842 };
843
844
845 /**************************************************************************
846 * ISF_MyDocuments_Constructor
847 */
848 HRESULT WINAPI ISF_MyDocuments_Constructor (
849 IUnknown * pUnkOuter, REFIID riid, LPVOID * ppv)
850 {
851 static IGenericSFImpl *cached_sf;
852 WCHAR szMyPath[MAX_PATH];
853
854 TRACE ("unkOut=%p %s\n", pUnkOuter, shdebugstr_guid (riid));
855
856 if (!ppv)
857 return E_POINTER;
858 if (pUnkOuter)
859 return CLASS_E_NOAGGREGATION;
860
861 if (!cached_sf)
862 {
863 IGenericSFImpl *sf;
864
865 if (!SHGetSpecialFolderPathW( 0, szMyPath, CSIDL_PERSONAL, TRUE ))
866 return E_UNEXPECTED;
867
868 sf = LocalAlloc( LMEM_ZEROINIT, sizeof (IGenericSFImpl) );
869 if (!sf)
870 return E_OUTOFMEMORY;
871
872 sf->ref = 1;
873 sf->lpVtbl = &vt_MCFldr_ShellFolder2;
874 sf->lpPF2 = &vt_FSFldr_PersistFolder2;
875 sf->pidlRoot = _ILCreateMyDocuments(); /* my qualified pidl */
876 sf->sPathTarget = SHAlloc( (wcslen(szMyPath) + 1)*sizeof(WCHAR) );
877 wcscpy( sf->sPathTarget, szMyPath );
878
879 if (InterlockedCompareExchangePointer((void *)&cached_sf, sf, NULL) != NULL)
880 {
881 /* some other thread already been here */
882 SHFree( sf->pidlRoot );
883 SHFree( sf->sPathTarget );
884 LocalFree( sf );
885 }
886 }
887
888 return IUnknown_QueryInterface( _IUnknown_(cached_sf), riid, ppv );
889 }