source: trunk/src/shell32/shlfolder.c@ 8614

Last change on this file since 8614 was 8614, checked in by sandervl, 23 years ago

compile fixes

File size: 72.4 KB
Line 
1/*
2 * Shell Folder stuff
3 *
4 * Copyright 1997 Marcus Meissner
5 * Copyright 1998, 1999 Juergen Schmied
6 *
7 * IShellFolder2 and related interfaces
8 *
9 */
10
11/****************************************************************************
12 * includes
13 ****************************************************************************/
14
15#include <odin.h>
16#include <os2sel.h>
17#include <odinwrap.h>
18
19ODINDEBUGCHANNEL(SHELL32-SHLFOLDER)
20
21
22
23#ifdef __WIN32OS2__
24#define snprintf(a,b,c,d) sprintf(a,c,d)
25#endif
26#include <stdlib.h>
27#include <string.h>
28#include <stdio.h>
29
30#include "debugtools.h"
31#include "winerror.h"
32#include "winbase.h"
33
34#include "oleidl.h"
35#include "shlguid.h"
36
37#include "pidl.h"
38#include "wine/obj_base.h"
39#include "wine/obj_dragdrop.h"
40#include "wine/obj_shellfolder.h"
41#include "undocshell.h"
42#include "shell32_main.h"
43#include "shresdef.h"
44#include "shlwapi.h"
45#include "shellfolder.h"
46
47DEFAULT_DEBUG_CHANNEL(shell);
48
49
50/***************************************************************************
51 * debughelper: print out the return adress
52 * helps especially to track down unbalanced AddRef/Release
53 */
54#define MEM_DEBUG 0
55
56#if MEM_DEBUG
57#define _CALL_TRACE TRACE("called from: 0x%08x\n", *( ((UINT*)&iface)-1 ));
58#else
59#define _CALL_TRACE
60#endif
61
62typedef struct
63{
64 int colnameid;
65 int pcsFlags;
66 int fmt;
67 int cxChar;
68
69} shvheader;
70
71/***************************************************************************
72 * GetNextElement (internal function)
73 *
74 * gets a part of a string till the first backslash
75 *
76 * PARAMETERS
77 * pszNext [IN] string to get the element from
78 * pszOut [IN] pointer to buffer whitch receives string
79 * dwOut [IN] length of pszOut
80 *
81 * RETURNS
82 * LPSTR pointer to first, not yet parsed char
83 */
84
85static LPCWSTR GetNextElementW(LPCWSTR pszNext,LPWSTR pszOut,DWORD dwOut)
86{ LPCWSTR pszTail = pszNext;
87 DWORD dwCopy;
88 TRACE("(%s %p 0x%08lx)\n",debugstr_w(pszNext),pszOut,dwOut);
89
90 *pszOut=0x0000;
91
92 if(!pszNext || !*pszNext)
93 return NULL;
94
95 while(*pszTail && (*pszTail != (WCHAR)'\\'))
96 pszTail++;
97
98 dwCopy = (WCHAR*)pszTail - (WCHAR*)pszNext + 1;
99 lstrcpynW(pszOut, pszNext, (dwOut<dwCopy)? dwOut : dwCopy);
100
101 if(*pszTail)
102 pszTail++;
103 else
104 pszTail = NULL;
105
106 TRACE("--(%s %s 0x%08lx %p)\n",debugstr_w(pszNext),debugstr_w(pszOut),dwOut,pszTail);
107 return pszTail;
108}
109
110static HRESULT SHELL32_ParseNextElement(
111 HWND hwndOwner,
112 IShellFolder2 * psf,
113 LPITEMIDLIST * pidlInOut,
114 LPOLESTR szNext,
115 DWORD *pEaten,
116 DWORD *pdwAttributes)
117{
118 HRESULT hr = E_OUTOFMEMORY;
119 LPITEMIDLIST pidlOut, pidlTemp = NULL;
120 IShellFolder *psfChild;
121
122 TRACE("(%p, %p, %s)\n",psf, pidlInOut ? *pidlInOut : NULL, debugstr_w(szNext));
123
124
125 /* get the shellfolder for the child pidl and let it analyse further */
126 hr = IShellFolder_BindToObject(psf, *pidlInOut, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
127
128 if (psfChild)
129 {
130 hr = IShellFolder_ParseDisplayName(psfChild, hwndOwner, NULL, szNext, pEaten, &pidlOut, pdwAttributes);
131 IShellFolder_Release(psfChild);
132
133 pidlTemp = ILCombine(*pidlInOut, pidlOut);
134
135 if (pidlOut)
136 ILFree(pidlOut);
137 }
138
139 ILFree(*pidlInOut);
140 *pidlInOut = pidlTemp;
141
142 TRACE("-- pidl=%p ret=0x%08lx\n", pidlInOut? *pidlInOut: NULL, hr);
143 return hr;
144}
145
146/***********************************************************************
147 * SHELL32_CoCreateInitSF
148 *
149 * creates a initialized shell folder
150 */
151static HRESULT SHELL32_CoCreateInitSF (
152 LPITEMIDLIST pidlRoot,
153 LPITEMIDLIST pidlChild,
154 REFCLSID clsid,
155 REFIID iid,
156 LPVOID * ppvOut)
157{
158 HRESULT hr;
159 LPITEMIDLIST absPidl;
160 IShellFolder2 *pShellFolder;
161 IPersistFolder *pPersistFolder;
162
163 TRACE("%p %p\n", pidlRoot, pidlChild);
164
165 *ppvOut = NULL;
166
167 /* we have to ask first for IPersistFolder, some special folders are expecting this */
168 hr = SHCoCreateInstance(NULL, clsid, NULL, &IID_IPersistFolder, (LPVOID*)&pPersistFolder);
169 if (SUCCEEDED(hr))
170 {
171 hr = IPersistFolder_QueryInterface(pPersistFolder, iid, (LPVOID*)&pShellFolder);
172 if (SUCCEEDED(hr))
173 {
174 absPidl = ILCombine (pidlRoot, pidlChild);
175 hr = IPersistFolder_Initialize(pPersistFolder, absPidl);
176 IPersistFolder_Release(pPersistFolder);
177 SHFree(absPidl);
178 *ppvOut = pShellFolder;
179 }
180 }
181
182 TRACE("-- ret=0x%08lx\n", hr);
183 return hr;
184}
185
186static HRESULT SHELL32_GetDisplayNameOfChild(
187 IShellFolder2 * psf,
188 LPCITEMIDLIST pidl,
189 DWORD dwFlags,
190 LPSTR szOut,
191 DWORD dwOutLen)
192{
193 LPITEMIDLIST pidlFirst, pidlNext;
194 IShellFolder2 * psfChild;
195 HRESULT hr = E_OUTOFMEMORY;
196 STRRET strTemp;
197
198 TRACE("(%p)->(pidl=%p 0x%08lx %p 0x%08lx)\n",psf,pidl,dwFlags,szOut, dwOutLen);
199 pdump(pidl);
200
201 if ((pidlFirst = ILCloneFirst(pidl)))
202 {
203 hr = IShellFolder_BindToObject(psf, pidlFirst, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
204 if (SUCCEEDED(hr))
205 {
206 pidlNext = ILGetNext(pidl);
207
208 hr = IShellFolder_GetDisplayNameOf(psfChild, pidlNext, dwFlags | SHGDN_INFOLDER, &strTemp);
209 if (SUCCEEDED(hr))
210 {
211 hr = StrRetToStrNA(szOut, dwOutLen, &strTemp, pidlNext);
212 }
213
214 IShellFolder_Release(psfChild);
215 }
216 ILFree(pidlFirst);
217 }
218
219 TRACE("-- ret=0x%08lx %s\n", hr, szOut);
220
221 return hr;
222}
223
224/***********************************************************************
225 * SHELL32_GetItemAttributes
226 *
227 * NOTES
228 * observerd values:
229 * folder: 0xE0000177 FILESYSTEM | HASSUBFOLDER | FOLDER
230 * file: 0x40000177 FILESYSTEM
231 * drive: 0xf0000144 FILESYSTEM | HASSUBFOLDER | FOLDER | FILESYSANCESTOR
232 * mycomputer: 0xb0000154 HASSUBFOLDER | FOLDER | FILESYSANCESTOR
233 * (seems to be default for shell extensions if no registry entry exists)
234 *
235 * This functions does not set flags!! It only resets flags when nessesary.
236 */
237static HRESULT SHELL32_GetItemAttributes(
238 IShellFolder * psf,
239 LPITEMIDLIST pidl,
240 LPDWORD pdwAttributes)
241{
242 GUID const * clsid;
243 DWORD dwAttributes;
244
245 TRACE("0x%08lx\n", *pdwAttributes);
246
247 if (*pdwAttributes & (0xcff3fe88))
248 WARN("attribute 0x%08lx not implemented\n", *pdwAttributes);
249 *pdwAttributes &= ~SFGAO_LINK; /* FIXME: for native filedialogs */
250
251 if (_ILIsDrive(pidl))
252 {
253 *pdwAttributes &= 0xf0000144;
254 }
255 else if ((clsid=_ILGetGUIDPointer(pidl)))
256 {
257 if (HCR_GetFolderAttributes(clsid, &dwAttributes))
258 {
259 *pdwAttributes &= dwAttributes;
260 }
261 else
262 {
263 *pdwAttributes &= 0xb0000154;
264 }
265 }
266 else if (_ILGetDataPointer(pidl))
267 {
268 dwAttributes = _ILGetFileAttributes(pidl, NULL, 0);
269 *pdwAttributes &= ~SFGAO_FILESYSANCESTOR;
270
271 if(( SFGAO_FOLDER & *pdwAttributes) && !(dwAttributes & FILE_ATTRIBUTE_DIRECTORY))
272 *pdwAttributes &= ~(SFGAO_FOLDER|SFGAO_HASSUBFOLDER);
273
274 if(( SFGAO_HIDDEN & *pdwAttributes) && !(dwAttributes & FILE_ATTRIBUTE_HIDDEN))
275 *pdwAttributes &= ~SFGAO_HIDDEN;
276
277 if(( SFGAO_READONLY & *pdwAttributes) && !(dwAttributes & FILE_ATTRIBUTE_READONLY))
278 *pdwAttributes &= ~SFGAO_READONLY;
279 }
280 else
281 {
282 *pdwAttributes &= 0xb0000154;
283 }
284 TRACE("-- 0x%08lx\n", *pdwAttributes);
285 return S_OK;
286}
287
288/***********************************************************************
289* IShellFolder implementation
290*/
291
292typedef struct
293{
294 ICOM_VFIELD(IUnknown);
295 DWORD ref;
296 ICOM_VTABLE(IShellFolder2)* lpvtblShellFolder;
297 ICOM_VTABLE(IPersistFolder2)* lpvtblPersistFolder2;
298 ICOM_VTABLE(IDropTarget)* lpvtblDropTarget;
299 ICOM_VTABLE(ISFHelper)* lpvtblSFHelper;
300
301 IUnknown *pUnkOuter; /* used for aggregation */
302
303 CLSID* pclsid;
304
305 LPSTR sMyPath;
306 LPITEMIDLIST absPidl; /* complete pidl */
307
308 UINT cfShellIDList; /* clipboardformat for IDropTarget */
309 BOOL fAcceptFmt; /* flag for pending Drop */
310} IGenericSFImpl;
311
312static struct ICOM_VTABLE(IUnknown) unkvt;
313static struct ICOM_VTABLE(IShellFolder2) sfvt;
314static struct ICOM_VTABLE(IPersistFolder2) psfvt;
315static struct ICOM_VTABLE(IDropTarget) dtvt;
316static struct ICOM_VTABLE(ISFHelper) shvt;
317
318static IShellFolder * ISF_MyComputer_Constructor(void);
319
320#define _IShellFolder2_Offset ((int)(&(((IGenericSFImpl*)0)->lpvtblShellFolder)))
321#define _ICOM_THIS_From_IShellFolder2(class, name) class* This = (class*)(((char*)name)-_IShellFolder2_Offset);
322
323#define _IPersistFolder_Offset ((int)(&(((IGenericSFImpl*)0)->lpvtblPersistFolder2)))
324#define _ICOM_THIS_From_IPersistFolder2(class, name) class* This = (class*)(((char*)name)-_IPersistFolder_Offset);
325
326#define _IDropTarget_Offset ((int)(&(((IGenericSFImpl*)0)->lpvtblDropTarget)))
327#define _ICOM_THIS_From_IDropTarget(class, name) class* This = (class*)(((char*)name)-_IDropTarget_Offset);
328
329#define _ISFHelper_Offset ((int)(&(((IGenericSFImpl*)0)->lpvtblSFHelper)))
330#define _ICOM_THIS_From_ISFHelper(class, name) class* This = (class*)(((char*)name)-_ISFHelper_Offset);
331/*
332 converts This to a interface pointer
333*/
334#define _IUnknown_(This) (IUnknown*)&(This->lpVtbl)
335#define _IShellFolder_(This) (IShellFolder*)&(This->lpvtblShellFolder)
336#define _IShellFolder2_(This) (IShellFolder2*)&(This->lpvtblShellFolder)
337#define _IPersist_(This) (IPersist*)&(This->lpvtblPersistFolder2)
338#define _IPersistFolder_(This) (IPersistFolder*)&(This->lpvtblPersistFolder2)
339#define _IPersistFolder2_(This) (IPersistFolder2*)&(This->lpvtblPersistFolder2)
340#define _IDropTarget_(This) (IDropTarget*)&(This->lpvtblDropTarget)
341#define _ISFHelper_(This) (ISFHelper*)&(This->lpvtblSFHelper)
342/**************************************************************************
343* registers clipboardformat once
344*/
345static void SF_RegisterClipFmt (IGenericSFImpl * This)
346{
347 TRACE("(%p)\n", This);
348
349 if (!This->cfShellIDList)
350 {
351 This->cfShellIDList = RegisterClipboardFormatA(CFSTR_SHELLIDLIST);
352 }
353}
354
355/**************************************************************************
356* we need a separate IUnknown to handle aggregation
357* (inner IUnknown)
358*/
359static HRESULT WINAPI IUnknown_fnQueryInterface(
360 IUnknown * iface,
361 REFIID riid,
362 LPVOID *ppvObj)
363{
364 ICOM_THIS(IGenericSFImpl, iface);
365
366 _CALL_TRACE
367 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
368
369 *ppvObj = NULL;
370
371 if(IsEqualIID(riid, &IID_IUnknown)) *ppvObj = _IUnknown_(This);
372 else if(IsEqualIID(riid, &IID_IShellFolder)) *ppvObj = _IShellFolder_(This);
373 else if(IsEqualIID(riid, &IID_IShellFolder2)) *ppvObj = _IShellFolder_(This);
374 else if(IsEqualIID(riid, &IID_IPersist)) *ppvObj = _IPersist_(This);
375 else if(IsEqualIID(riid, &IID_IPersistFolder)) *ppvObj = _IPersistFolder_(This);
376 else if(IsEqualIID(riid, &IID_IPersistFolder2)) *ppvObj = _IPersistFolder2_(This);
377 else if(IsEqualIID(riid, &IID_ISFHelper)) *ppvObj = _ISFHelper_(This);
378 else if(IsEqualIID(riid, &IID_IDropTarget))
379 {
380 *ppvObj = _IDropTarget_(This);
381 SF_RegisterClipFmt(This);
382 }
383
384 if(*ppvObj)
385 {
386 IUnknown_AddRef((IUnknown*)(*ppvObj));
387 TRACE("-- Interface = %p\n", *ppvObj);
388 return S_OK;
389 }
390 TRACE("-- Interface: E_NOINTERFACE\n");
391 return E_NOINTERFACE;
392}
393
394static ULONG WINAPI IUnknown_fnAddRef(IUnknown * iface)
395{
396 ICOM_THIS(IGenericSFImpl, iface);
397
398 _CALL_TRACE
399 TRACE("(%p)->(count=%lu)\n",This,This->ref);
400
401 shell32_ObjCount++;
402 return ++(This->ref);
403}
404
405static ULONG WINAPI IUnknown_fnRelease(IUnknown * iface)
406{
407 ICOM_THIS(IGenericSFImpl, iface);
408
409 _CALL_TRACE
410 TRACE("(%p)->(count=%lu)\n",This,This->ref);
411
412 shell32_ObjCount--;
413 if (!--(This->ref))
414 {
415 TRACE("-- destroying IShellFolder(%p)\n",This);
416
417 if (pdesktopfolder == _IShellFolder_(This))
418 {
419 pdesktopfolder=NULL;
420 TRACE("-- destroyed IShellFolder(%p) was Desktopfolder\n",This);
421 }
422 if(This->absPidl) SHFree(This->absPidl);
423 if(This->sMyPath) SHFree(This->sMyPath);
424 HeapFree(GetProcessHeap(),0,This);
425 return 0;
426 }
427 return This->ref;
428}
429
430static ICOM_VTABLE(IUnknown) unkvt =
431{
432 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
433 IUnknown_fnQueryInterface,
434 IUnknown_fnAddRef,
435 IUnknown_fnRelease,
436};
437
438static shvheader GenericSFHeader [] =
439{
440 { IDS_SHV_COLUMN1, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 15 },
441 { IDS_SHV_COLUMN2, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10 },
442 { IDS_SHV_COLUMN3, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10 },
443 { IDS_SHV_COLUMN4, SHCOLSTATE_TYPE_DATE | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 12 },
444 { IDS_SHV_COLUMN5, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 5 }
445};
446#define GENERICSHELLVIEWCOLUMNS 5
447
448/**************************************************************************
449* IShellFolder_Constructor
450*
451* NOTES
452* creating undocumented ShellFS_Folder as part of an aggregation
453* {F3364BA0-65B9-11CE-A9BA-00AA004AE837}
454*
455* FIXME
456* when pUnkOuter = 0 then rrid = IID_IShellFolder is returned
457*/
458HRESULT IFSFolder_Constructor(
459 IUnknown * pUnkOuter,
460 REFIID riid,
461 LPVOID * ppv)
462{
463 IGenericSFImpl * sf;
464 HRESULT hr = S_OK;
465
466 TRACE("unkOut=%p riid=%s\n",pUnkOuter, debugstr_guid(riid));
467
468 if(pUnkOuter && ! IsEqualIID(riid, &IID_IUnknown))
469 {
470 hr = CLASS_E_NOAGGREGATION; /* forbidden by definition */
471 }
472 else
473 {
474 sf=(IGenericSFImpl*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IGenericSFImpl));
475 if (sf)
476 {
477 sf->ref=1;
478 ICOM_VTBL(sf)=&unkvt;
479 sf->lpvtblShellFolder=&sfvt;
480 sf->lpvtblPersistFolder2=&psfvt;
481 sf->lpvtblDropTarget=&dtvt;
482 sf->lpvtblSFHelper=&shvt;
483
484 sf->pclsid = (CLSID*)&CLSID_SFFile;
485 sf->pUnkOuter = pUnkOuter ? pUnkOuter : _IUnknown_(sf);
486 *ppv = _IUnknown_(sf);
487 hr = S_OK;
488 shell32_ObjCount++;
489 }
490 else
491 {
492 hr = E_OUTOFMEMORY;
493 }
494 }
495 return hr;
496}
497/**************************************************************************
498* IShellFolder_Constructor
499*
500* NOTES
501* THIS points to the parent folder
502*/
503
504IShellFolder * IShellFolder_Constructor(
505 IShellFolder2 * iface,
506 LPITEMIDLIST pidl)
507{
508 IGenericSFImpl * sf;
509 DWORD dwSize=0;
510
511 _ICOM_THIS_From_IShellFolder2(IGenericSFImpl, iface)
512
513 sf=(IGenericSFImpl*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IGenericSFImpl));
514 sf->ref=1;
515
516 ICOM_VTBL(sf)=&unkvt;
517 sf->lpvtblShellFolder=&sfvt;
518 sf->lpvtblPersistFolder2=&psfvt;
519 sf->lpvtblDropTarget=&dtvt;
520 sf->lpvtblSFHelper=&shvt;
521
522 sf->pclsid = (CLSID*)&CLSID_SFFile;
523 sf->pUnkOuter = _IUnknown_(sf);
524
525 TRACE("(%p)->(parent=%p, pidl=%p)\n",sf,This, pidl);
526 pdump(pidl);
527
528 if(pidl && iface) /* do we have a pidl? */
529 {
530 int len;
531
532 sf->absPidl = ILCombine(This->absPidl, pidl); /* build a absolute pidl */
533
534 if (!_ILIsSpecialFolder(pidl)) /* only file system paths */
535 {
536 if(This->sMyPath) /* get the size of the parents path */
537 {
538 dwSize += strlen(This->sMyPath) ;
539 TRACE("-- (%p)->(parent's path=%s)\n",sf, debugstr_a(This->sMyPath));
540 }
541
542 dwSize += _ILSimpleGetText(pidl,NULL,0); /* add the size of our name*/
543 sf->sMyPath = SHAlloc(dwSize + 2); /* '\0' and backslash */
544
545 if(!sf->sMyPath) return NULL;
546 *(sf->sMyPath)=0x00;
547
548 if(This->sMyPath) /* if the parent has a path, get it*/
549 {
550 strcpy(sf->sMyPath, This->sMyPath);
551 PathAddBackslashA (sf->sMyPath);
552 }
553
554 len = strlen(sf->sMyPath);
555 _ILSimpleGetText(pidl, sf->sMyPath + len, dwSize+2 - len);
556 }
557
558 TRACE("-- (%p)->(my pidl=%p, my path=%s)\n",sf, sf->absPidl,debugstr_a(sf->sMyPath));
559
560 pdump (sf->absPidl);
561 }
562
563 shell32_ObjCount++;
564 return _IShellFolder_(sf);
565}
566
567/**************************************************************************
568 * IShellFolder_fnQueryInterface
569 *
570 * PARAMETERS
571 * REFIID riid [in ] Requested InterfaceID
572 * LPVOID* ppvObject [out] Interface* to hold the result
573 */
574static HRESULT WINAPI IShellFolder_fnQueryInterface(
575 IShellFolder2 * iface,
576 REFIID riid,
577 LPVOID *ppvObj)
578{
579 _ICOM_THIS_From_IShellFolder2(IGenericSFImpl, iface)
580
581 _CALL_TRACE
582 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
583
584 return IUnknown_QueryInterface(This->pUnkOuter, riid, ppvObj);
585}
586
587/**************************************************************************
588* IShellFolder_AddRef
589*/
590
591static ULONG WINAPI IShellFolder_fnAddRef(IShellFolder2 * iface)
592{
593 _ICOM_THIS_From_IShellFolder2(IGenericSFImpl, iface)
594
595 _CALL_TRACE
596 TRACE("(%p)->(count=%lu)\n",This,This->ref);
597
598 return IUnknown_AddRef(This->pUnkOuter);
599}
600
601/**************************************************************************
602 * IShellFolder_fnRelease
603 */
604static ULONG WINAPI IShellFolder_fnRelease(IShellFolder2 * iface)
605{
606 _ICOM_THIS_From_IShellFolder2(IGenericSFImpl, iface)
607
608 _CALL_TRACE
609 TRACE("(%p)->(count=%lu)\n",This,This->ref);
610
611 return IUnknown_Release(This->pUnkOuter);
612}
613
614/**************************************************************************
615* IShellFolder_fnParseDisplayName
616* PARAMETERS
617* HWND hwndOwner, //[in ] Parent window for any message's
618* LPBC pbc, //[in ] reserved
619* LPOLESTR lpszDisplayName,//[in ] "Unicode" displayname.
620* ULONG* pchEaten, //[out] (unicode) characters processed
621* LPITEMIDLIST* ppidl, //[out] complex pidl to item
622* ULONG* pdwAttributes //[out] items attributes
623*
624* NOTES
625* every folder tries to parse only its own (the leftmost) pidl and creates a
626* subfolder to evaluate the remaining parts
627* now we can parse into namespaces implemented by shell extensions
628*
629* behaviour on win98: lpszDisplayName=NULL -> chrash
630* lpszDisplayName="" -> returns mycoputer-pidl
631*
632* FIXME:
633* pdwAttributes: not set
634* pchEaten: not set like in windows
635*/
636static HRESULT WINAPI IShellFolder_fnParseDisplayName(
637 IShellFolder2 * iface,
638 HWND hwndOwner,
639 LPBC pbcReserved,
640 LPOLESTR lpszDisplayName,
641 DWORD *pchEaten,
642 LPITEMIDLIST *ppidl,
643 DWORD *pdwAttributes)
644{
645 _ICOM_THIS_From_IShellFolder2(IGenericSFImpl, iface)
646
647 HRESULT hr = E_OUTOFMEMORY;
648 LPCWSTR szNext=NULL;
649 WCHAR szElement[MAX_PATH];
650 CHAR szTempA[MAX_PATH], szPath[MAX_PATH];
651 LPITEMIDLIST pidlTemp=NULL;
652
653 TRACE("(%p)->(HWND=0x%08x,%p,%p=%s,%p,pidl=%p,%p)\n",
654 This,hwndOwner,pbcReserved,lpszDisplayName,
655 debugstr_w(lpszDisplayName),pchEaten,ppidl,pdwAttributes);
656
657 if (!lpszDisplayName || !ppidl) return E_INVALIDARG;
658
659 if (pchEaten) *pchEaten = 0; /* strange but like the original */
660
661 if (*lpszDisplayName)
662 {
663 /* get the next element */
664 szNext = GetNextElementW(lpszDisplayName, szElement, MAX_PATH);
665
666 /* build the full pathname to the element */
667 WideCharToMultiByte( CP_ACP, 0, szElement, -1, szTempA, MAX_PATH, NULL, NULL );
668 strcpy(szPath, This->sMyPath);
669 PathAddBackslashA(szPath);
670 strcat(szPath, szTempA);
671
672 /* get the pidl */
673 pidlTemp = SHSimpleIDListFromPathA(szPath);
674
675 if (pidlTemp)
676 {
677 /* try to analyse the next element */
678 if (szNext && *szNext)
679 {
680 hr = SHELL32_ParseNextElement(hwndOwner, iface, &pidlTemp, (LPOLESTR)szNext, pchEaten, pdwAttributes);
681 }
682 else
683 {
684 if (pdwAttributes && *pdwAttributes)
685 {
686 SHELL32_GetItemAttributes(_IShellFolder_(This), pidlTemp, pdwAttributes);
687/* WIN32_FIND_DATAA fd;
688 SHGetDataFromIDListA(_IShellFolder_(This), pidlTemp, SHGDFIL_FINDDATA, &fd, sizeof(fd));
689 if (!(FILE_ATTRIBUTE_DIRECTORY & fd.dwFileAttributes))
690 *pdwAttributes &= ~SFGAO_FOLDER;
691 if (FILE_ATTRIBUTE_READONLY & fd.dwFileAttributes)
692 *pdwAttributes &= ~(SFGAO_CANDELETE|SFGAO_CANMOVE|SFGAO_CANRENAME );
693*/
694 }
695 hr = S_OK;
696 }
697 }
698 }
699
700 if (!hr)
701 *ppidl = pidlTemp;
702 else
703 *ppidl = NULL;
704
705 TRACE("(%p)->(-- pidl=%p ret=0x%08lx)\n", This, ppidl? *ppidl:0, hr);
706
707 return hr;
708}
709
710/**************************************************************************
711* IShellFolder_fnEnumObjects
712* PARAMETERS
713* HWND hwndOwner, //[in ] Parent Window
714* DWORD grfFlags, //[in ] SHCONTF enumeration mask
715* LPENUMIDLIST* ppenumIDList //[out] IEnumIDList interface
716*/
717static HRESULT WINAPI IShellFolder_fnEnumObjects(
718 IShellFolder2 * iface,
719 HWND hwndOwner,
720 DWORD dwFlags,
721 LPENUMIDLIST* ppEnumIDList)
722{
723 _ICOM_THIS_From_IShellFolder2(IGenericSFImpl, iface)
724
725 TRACE("(%p)->(HWND=0x%08x flags=0x%08lx pplist=%p)\n",This,hwndOwner,dwFlags,ppEnumIDList);
726
727 *ppEnumIDList = NULL;
728 *ppEnumIDList = IEnumIDList_Constructor (This->sMyPath, dwFlags, EIDL_FILE);
729
730 TRACE("-- (%p)->(new ID List: %p)\n",This,*ppEnumIDList);
731
732 if(!*ppEnumIDList) return E_OUTOFMEMORY;
733
734 return S_OK;
735}
736
737/**************************************************************************
738* IShellFolder_fnBindToObject
739* PARAMETERS
740* LPCITEMIDLIST pidl, //[in ] relative pidl to open
741* LPBC pbc, //[in ] reserved
742* REFIID riid, //[in ] Initial Interface
743* LPVOID* ppvObject //[out] Interface*
744*/
745static HRESULT WINAPI IShellFolder_fnBindToObject( IShellFolder2 * iface, LPCITEMIDLIST pidl,
746 LPBC pbcReserved, REFIID riid, LPVOID * ppvOut)
747{
748 _ICOM_THIS_From_IShellFolder2(IGenericSFImpl, iface)
749 GUID const * iid;
750 IShellFolder *pShellFolder, *pSubFolder;
751 IPersistFolder *pPersistFolder;
752 LPITEMIDLIST absPidl;
753
754 TRACE("(%p)->(pidl=%p,%p,\n\tIID:\t%s,%p)\n",This,pidl,pbcReserved,debugstr_guid(riid),ppvOut);
755
756 if(!pidl || !ppvOut) return E_INVALIDARG;
757
758 *ppvOut = NULL;
759
760 if ((iid=_ILGetGUIDPointer(pidl)))
761 {
762 /* we have to create a alien folder */
763 if ( SUCCEEDED(SHCoCreateInstance(NULL, iid, NULL, riid, (LPVOID*)&pShellFolder))
764 && SUCCEEDED(IShellFolder_QueryInterface(pShellFolder, &IID_IPersistFolder, (LPVOID*)&pPersistFolder)))
765 {
766 absPidl = ILCombine (This->absPidl, pidl);
767 IPersistFolder_Initialize(pPersistFolder, absPidl);
768 IPersistFolder_Release(pPersistFolder);
769 SHFree(absPidl);
770 }
771 else
772 {
773 return E_FAIL;
774 }
775 }
776 else if(_ILIsFolder(pidl))
777 {
778 LPITEMIDLIST pidltemp = ILCloneFirst(pidl);
779 pShellFolder = IShellFolder_Constructor(iface, pidltemp);
780 ILFree(pidltemp);
781 }
782 else
783 {
784 ERR("can't bind to a file\n");
785 return E_FAIL;
786 }
787
788 if (_ILIsPidlSimple(pidl))
789 {
790 *ppvOut = pShellFolder;
791 }
792 else
793 {
794 IShellFolder_BindToObject(pShellFolder, ILGetNext(pidl), NULL, &IID_IShellFolder, (LPVOID)&pSubFolder);
795 IShellFolder_Release(pShellFolder);
796 *ppvOut = pSubFolder;
797 }
798
799 TRACE("-- (%p) returning (%p)\n",This, *ppvOut);
800
801 return S_OK;
802}
803
804/**************************************************************************
805* IShellFolder_fnBindToStorage
806* PARAMETERS
807* LPCITEMIDLIST pidl, //[in ] complex pidl to store
808* LPBC pbc, //[in ] reserved
809* REFIID riid, //[in ] Initial storage interface
810* LPVOID* ppvObject //[out] Interface* returned
811*/
812static HRESULT WINAPI IShellFolder_fnBindToStorage(
813 IShellFolder2 * iface,
814 LPCITEMIDLIST pidl,
815 LPBC pbcReserved,
816 REFIID riid,
817 LPVOID *ppvOut)
818{
819 _ICOM_THIS_From_IShellFolder2(IGenericSFImpl, iface)
820
821 FIXME("(%p)->(pidl=%p,%p,\n\tIID:%s,%p) stub\n",
822 This,pidl,pbcReserved,debugstr_guid(riid),ppvOut);
823
824 *ppvOut = NULL;
825 return E_NOTIMPL;
826}
827
828/**************************************************************************
829* IShellFolder_fnCompareIDs
830*
831* PARMETERS
832* LPARAM lParam, //[in ] Column?
833* LPCITEMIDLIST pidl1, //[in ] simple pidl
834* LPCITEMIDLIST pidl2) //[in ] simple pidl
835*
836* NOTES
837* Special case - If one of the items is a Path and the other is a File,
838* always make the Path come before the File.
839*
840* NOTES
841* use SCODE_CODE() on the return value to get the result
842*/
843
844static ODINFUNCTION4(HRESULT, IShellFolder_fnCompareIDs,
845 IShellFolder2 *, iface,
846 LPARAM, lParam,
847 LPCITEMIDLIST, pidl1,
848 LPCITEMIDLIST, pidl2)
849{
850 _ICOM_THIS_From_IShellFolder2(IGenericSFImpl, iface)
851
852 int nReturn;
853 IShellFolder * psf;
854 HRESULT hr = E_OUTOFMEMORY;
855 LPCITEMIDLIST pidlTemp;
856 PIDLTYPE pt1, pt2;
857
858// TRACE("(%p)->(0x%08lx,pidl1=%p,pidl2=%p)\n",This,lParam,pidl1,pidl2);
859// pdump (pidl1);
860// pdump (pidl2);
861
862 if (!pidl1 && !pidl2)
863 {
864 hr = ResultFromShort(0);
865 }
866 else if (!pidl1)
867 {
868 hr = ResultFromShort(-1);
869 }
870 else if (!pidl2)
871 {
872 hr = ResultFromShort(1);
873 }
874 else
875 {
876 LPPIDLDATA pd1, pd2;
877 pd1 = _ILGetDataPointer(pidl1);
878 pd2 = _ILGetDataPointer(pidl2);
879
880 /* compate the types. sort order is the PT_* constant */
881 pt1 = ( pd1 ? pd1->type: PT_DESKTOP);
882 pt2 = ( pd2 ? pd2->type: PT_DESKTOP);
883
884 if (pt1 != pt2)
885 {
886 hr = ResultFromShort(pt1-pt2);
887 }
888 else /* same type of pidl */
889 {
890// _ILSimpleGetText(pidl1, szTemp1, MAX_PATH);
891// _ILSimpleGetText(pidl2, szTemp2, MAX_PATH);
892// nReturn = strcasecmp(szTemp1, szTemp2);
893 nReturn = _ILSimpleCompareText( pidl1, pidl2 );
894
895 if (nReturn == 0) /* first pidl different ? */
896 {
897 pidl1 = ILGetNext(pidl1);
898
899 if (pidl1 && pidl1->mkid.cb) /* go deeper? */
900 {
901#ifdef __WIN32OS2__
902 //SvL: shortcut for efficiency. might have to remove it
903 // in the future if this method is changed
904 pidl2 = ILGetNext(pidl2);
905
906 nReturn = IShellFolder_CompareIDs(iface, 0, pidl1, pidl2);
907 hr = ResultFromShort(nReturn);
908#else
909 pidlTemp = ILCloneFirst(pidl1);
910 pidl2 = ILGetNext(pidl2);
911
912 hr = IShellFolder_BindToObject(iface, pidlTemp, NULL, &IID_IShellFolder, (LPVOID*)&psf);
913 if (SUCCEEDED(hr))
914 {
915 nReturn = IShellFolder_CompareIDs(psf, 0, pidl1, pidl2);
916 IShellFolder_Release(psf);
917 hr = ResultFromShort(nReturn);
918 }
919 ILFree(pidlTemp);
920#endif
921 }
922 else
923 {
924 pidl2 = ILGetNext(pidl2);
925 if (pidl2 && pidl2->mkid.cb) /* go deeper on #2 ? */
926 hr = ResultFromShort(-1); /* two different */
927 else
928 hr = ResultFromShort(nReturn); /* two equal simple pidls */
929 }
930 }
931 else
932 {
933 hr = ResultFromShort(nReturn); /* two different simple pidls */
934 }
935 }
936 }
937
938 TRACE("-- res=0x%08lx\n", hr);
939 return hr;
940}
941
942/**************************************************************************
943* IShellFolder_fnCreateViewObject
944*/
945static HRESULT WINAPI IShellFolder_fnCreateViewObject(
946 IShellFolder2 * iface,
947 HWND hwndOwner,
948 REFIID riid,
949 LPVOID *ppvOut)
950{
951 _ICOM_THIS_From_IShellFolder2(IGenericSFImpl, iface)
952
953 LPSHELLVIEW pShellView;
954 HRESULT hr = E_INVALIDARG;
955
956 TRACE("(%p)->(hwnd=0x%x,\n\tIID:\t%s,%p)\n",This,hwndOwner,debugstr_guid(riid),ppvOut);
957
958 if(ppvOut)
959 {
960 *ppvOut = NULL;
961
962 if(IsEqualIID(riid, &IID_IDropTarget))
963 {
964 hr = IShellFolder_QueryInterface(iface, &IID_IDropTarget, ppvOut);
965 }
966 else if(IsEqualIID(riid, &IID_IContextMenu))
967 {
968 FIXME("IContextMenu not implemented\n");
969 hr = E_NOTIMPL;
970 }
971 else if(IsEqualIID(riid, &IID_IShellView))
972 {
973 pShellView = IShellView_Constructor((IShellFolder*)iface);
974 if(pShellView)
975 {
976 hr = IShellView_QueryInterface(pShellView, riid, ppvOut);
977 IShellView_Release(pShellView);
978 }
979 }
980 }
981 TRACE("-- (%p)->(interface=%p)\n",This, ppvOut);
982 return hr;
983}
984
985/**************************************************************************
986* IShellFolder_fnGetAttributesOf
987*
988* PARAMETERS
989* UINT cidl, //[in ] num elements in pidl array
990* LPCITEMIDLIST* apidl, //[in ] simple pidl array
991* ULONG* rgfInOut) //[out] result array
992*
993*/
994static HRESULT WINAPI IShellFolder_fnGetAttributesOf(
995 IShellFolder2 * iface,
996 UINT cidl,
997 LPCITEMIDLIST *apidl,
998 DWORD *rgfInOut)
999{
1000 _ICOM_THIS_From_IShellFolder2(IGenericSFImpl, iface)
1001
1002 HRESULT hr = S_OK;
1003
1004 TRACE("(%p)->(cidl=%d apidl=%p mask=0x%08lx)\n",This,cidl,apidl,*rgfInOut);
1005
1006 if ( (!cidl) || (!apidl) || (!rgfInOut))
1007 return E_INVALIDARG;
1008
1009 while (cidl > 0 && *apidl)
1010 {
1011 pdump (*apidl);
1012 SHELL32_GetItemAttributes(_IShellFolder_(This), *apidl, rgfInOut);
1013 apidl++;
1014 cidl--;
1015 }
1016
1017 TRACE("-- result=0x%08lx\n",*rgfInOut);
1018
1019 return hr;
1020}
1021/**************************************************************************
1022* IShellFolder_fnGetUIObjectOf
1023*
1024* PARAMETERS
1025* HWND hwndOwner, //[in ] Parent window for any output
1026* UINT cidl, //[in ] array size
1027* LPCITEMIDLIST* apidl, //[in ] simple pidl array
1028* REFIID riid, //[in ] Requested Interface
1029* UINT* prgfInOut, //[ ] reserved
1030* LPVOID* ppvObject) //[out] Resulting Interface
1031*
1032* NOTES
1033* This function gets asked to return "view objects" for one or more (multiple select)
1034* items:
1035* The viewobject typically is an COM object with one of the following interfaces:
1036* IExtractIcon,IDataObject,IContextMenu
1037* In order to support icon positions in the default Listview your DataObject
1038* must implement the SetData method (in addition to GetData :) - the shell passes
1039* a barely documented "Icon positions" structure to SetData when the drag starts,
1040* and GetData's it if the drop is in another explorer window that needs the positions.
1041*/
1042static HRESULT WINAPI IShellFolder_fnGetUIObjectOf(
1043 IShellFolder2 * iface,
1044 HWND hwndOwner,
1045 UINT cidl,
1046 LPCITEMIDLIST * apidl,
1047 REFIID riid,
1048 UINT * prgfInOut,
1049 LPVOID * ppvOut)
1050{
1051 _ICOM_THIS_From_IShellFolder2(IGenericSFImpl, iface)
1052
1053 LPITEMIDLIST pidl;
1054 IUnknown* pObj = NULL;
1055 HRESULT hr = E_INVALIDARG;
1056
1057 TRACE("(%p)->(0x%04x,%u,apidl=%p,\n\tIID:%s,%p,%p)\n",
1058 This,hwndOwner,cidl,apidl,debugstr_guid(riid),prgfInOut,ppvOut);
1059
1060 if (ppvOut)
1061 {
1062 *ppvOut = NULL;
1063
1064 if(IsEqualIID(riid, &IID_IContextMenu) && (cidl >= 1))
1065 {
1066 pObj = (LPUNKNOWN)ISvItemCm_Constructor((IShellFolder*)iface, This->absPidl, apidl, cidl);
1067 hr = S_OK;
1068 }
1069 else if (IsEqualIID(riid, &IID_IDataObject) &&(cidl >= 1))
1070 {
1071 pObj = (LPUNKNOWN)IDataObject_Constructor (hwndOwner, This->absPidl, apidl, cidl);
1072 hr = S_OK;
1073 }
1074 else if (IsEqualIID(riid, &IID_IExtractIconA) && (cidl == 1))
1075 {
1076 pidl = ILCombine(This->absPidl,apidl[0]);
1077 pObj = (LPUNKNOWN)IExtractIconA_Constructor( pidl );
1078 SHFree(pidl);
1079 hr = S_OK;
1080 }
1081 else if (IsEqualIID(riid, &IID_IDropTarget) && (cidl >= 1))
1082 {
1083 hr = IShellFolder_QueryInterface(iface, &IID_IDropTarget, (LPVOID*)&pObj);
1084 }
1085 else
1086 {
1087 hr = E_NOINTERFACE;
1088 }
1089
1090 if(!pObj)
1091 hr = E_OUTOFMEMORY;
1092
1093 *ppvOut = pObj;
1094 }
1095 TRACE("(%p)->hr=0x%08lx\n",This, hr);
1096 return hr;
1097}
1098
1099/**************************************************************************
1100* IShellFolder_fnGetDisplayNameOf
1101* Retrieves the display name for the specified file object or subfolder
1102*
1103* PARAMETERS
1104* LPCITEMIDLIST pidl, //[in ] complex pidl to item
1105* DWORD dwFlags, //[in ] SHGNO formatting flags
1106* LPSTRRET lpName) //[out] Returned display name
1107*
1108* FIXME
1109* if the name is in the pidl the ret value should be a STRRET_OFFSET
1110*/
1111#define GET_SHGDN_FOR(dwFlags) ((DWORD)dwFlags & (DWORD)0x0000FF00)
1112#define GET_SHGDN_RELATION(dwFlags) ((DWORD)dwFlags & (DWORD)0x000000FF)
1113
1114static HRESULT WINAPI IShellFolder_fnGetDisplayNameOf(
1115 IShellFolder2 * iface,
1116 LPCITEMIDLIST pidl,
1117 DWORD dwFlags,
1118 LPSTRRET strRet)
1119{
1120 _ICOM_THIS_From_IShellFolder2(IGenericSFImpl, iface)
1121
1122 CHAR szPath[MAX_PATH]= "";
1123 int len = 0;
1124 BOOL bSimplePidl;
1125
1126 TRACE("(%p)->(pidl=%p,0x%08lx,%p)\n",This,pidl,dwFlags,strRet);
1127 pdump(pidl);
1128
1129 if(!pidl || !strRet) return E_INVALIDARG;
1130
1131 bSimplePidl = _ILIsPidlSimple(pidl);
1132
1133 /* take names of special folders only if its only this folder */
1134 if (_ILIsSpecialFolder(pidl))
1135 {
1136 if ( bSimplePidl)
1137 {
1138 _ILSimpleGetText(pidl, szPath, MAX_PATH); /* append my own path */
1139 }
1140 }
1141 else
1142 {
1143 if (!(dwFlags & SHGDN_INFOLDER) && (dwFlags & SHGDN_FORPARSING) && This->sMyPath)
1144 {
1145 strcpy (szPath, This->sMyPath); /* get path to root*/
1146 PathAddBackslashA(szPath);
1147 len = strlen(szPath);
1148 }
1149 _ILSimpleGetText(pidl, szPath + len, MAX_PATH - len); /* append my own path */
1150 }
1151
1152 if ( (dwFlags & SHGDN_FORPARSING) && !bSimplePidl) /* go deeper if needed */
1153 {
1154 PathAddBackslashA(szPath);
1155 len = strlen(szPath);
1156
1157 if (!SUCCEEDED(SHELL32_GetDisplayNameOfChild(iface, pidl, dwFlags, szPath + len, MAX_PATH - len)))
1158 return E_OUTOFMEMORY;
1159 }
1160 strRet->uType = STRRET_CSTRA;
1161 lstrcpynA(strRet->u.cStr, szPath, MAX_PATH);
1162
1163 TRACE("-- (%p)->(%s)\n", This, szPath);
1164 return S_OK;
1165}
1166
1167/**************************************************************************
1168* IShellFolder_fnSetNameOf
1169* Changes the name of a file object or subfolder, possibly changing its item
1170* identifier in the process.
1171*
1172* PARAMETERS
1173* HWND hwndOwner, //[in ] Owner window for output
1174* LPCITEMIDLIST pidl, //[in ] simple pidl of item to change
1175* LPCOLESTR lpszName, //[in ] the items new display name
1176* DWORD dwFlags, //[in ] SHGNO formatting flags
1177* LPITEMIDLIST* ppidlOut) //[out] simple pidl returned
1178*/
1179static HRESULT WINAPI IShellFolder_fnSetNameOf(
1180 IShellFolder2 * iface,
1181 HWND hwndOwner,
1182 LPCITEMIDLIST pidl, /*simple pidl*/
1183 LPCOLESTR lpName,
1184 DWORD dwFlags,
1185 LPITEMIDLIST *pPidlOut)
1186{
1187 _ICOM_THIS_From_IShellFolder2(IGenericSFImpl, iface)
1188 char szSrc[MAX_PATH], szDest[MAX_PATH];
1189 int len;
1190 BOOL bIsFolder = _ILIsFolder(ILFindLastID(pidl));
1191
1192 TRACE("(%p)->(%u,pidl=%p,%s,%lu,%p)\n",
1193 This,hwndOwner,pidl,debugstr_w(lpName),dwFlags,pPidlOut);
1194
1195 /* build source path */
1196 if (dwFlags & SHGDN_INFOLDER)
1197 {
1198 strcpy(szSrc, This->sMyPath);
1199 PathAddBackslashA(szSrc);
1200 len = strlen (szSrc);
1201 _ILSimpleGetText(pidl, szSrc+len, MAX_PATH-len);
1202 }
1203 else
1204 {
1205 SHGetPathFromIDListA(pidl, szSrc);
1206 }
1207
1208 /* build destination path */
1209 strcpy(szDest, This->sMyPath);
1210 PathAddBackslashA(szDest);
1211 len = strlen (szDest);
1212 WideCharToMultiByte( CP_ACP, 0, lpName, -1, szDest+len, MAX_PATH-len, NULL, NULL );
1213 szDest[MAX_PATH-1] = 0;
1214 TRACE("src=%s dest=%s\n", szSrc, szDest);
1215 if ( MoveFileA(szSrc, szDest) )
1216 {
1217 if (pPidlOut) *pPidlOut = SHSimpleIDListFromPathA(szDest);
1218 SHChangeNotifyA( bIsFolder?SHCNE_RENAMEFOLDER:SHCNE_RENAMEITEM, SHCNF_PATHA, szSrc, szDest);
1219 return S_OK;
1220 }
1221 return E_FAIL;
1222}
1223
1224static HRESULT WINAPI IShellFolder_fnGetDefaultSearchGUID(
1225 IShellFolder2 * iface,
1226 GUID *pguid)
1227{
1228 _ICOM_THIS_From_IShellFolder2(IGenericSFImpl, iface)
1229 FIXME("(%p)\n",This);
1230 return E_NOTIMPL;
1231}
1232static HRESULT WINAPI IShellFolder_fnEnumSearches(
1233 IShellFolder2 * iface,
1234 IEnumExtraSearch **ppenum)
1235{
1236 _ICOM_THIS_From_IShellFolder2(IGenericSFImpl, iface)
1237 FIXME("(%p)\n",This);
1238 return E_NOTIMPL;
1239}
1240static HRESULT WINAPI IShellFolder_fnGetDefaultColumn(
1241 IShellFolder2 * iface,
1242 DWORD dwRes,
1243 ULONG *pSort,
1244 ULONG *pDisplay)
1245{
1246 _ICOM_THIS_From_IShellFolder2(IGenericSFImpl, iface)
1247
1248 TRACE("(%p)\n",This);
1249
1250 if (pSort) *pSort = 0;
1251 if (pDisplay) *pDisplay = 0;
1252
1253 return S_OK;
1254}
1255static HRESULT WINAPI IShellFolder_fnGetDefaultColumnState(
1256 IShellFolder2 * iface,
1257 UINT iColumn,
1258 DWORD *pcsFlags)
1259{
1260 _ICOM_THIS_From_IShellFolder2(IGenericSFImpl, iface)
1261
1262 TRACE("(%p)\n",This);
1263
1264 if (!pcsFlags || iColumn >= GENERICSHELLVIEWCOLUMNS ) return E_INVALIDARG;
1265
1266 *pcsFlags = GenericSFHeader[iColumn].pcsFlags;
1267
1268 return S_OK;
1269}
1270static HRESULT WINAPI IShellFolder_fnGetDetailsEx(
1271 IShellFolder2 * iface,
1272 LPCITEMIDLIST pidl,
1273 const SHCOLUMNID *pscid,
1274 VARIANT *pv)
1275{
1276 _ICOM_THIS_From_IShellFolder2(IGenericSFImpl, iface)
1277 FIXME("(%p)\n",This);
1278
1279 return E_NOTIMPL;
1280}
1281static HRESULT WINAPI IShellFolder_fnGetDetailsOf(
1282 IShellFolder2 * iface,
1283 LPCITEMIDLIST pidl,
1284 UINT iColumn,
1285 SHELLDETAILS *psd)
1286{
1287 _ICOM_THIS_From_IShellFolder2(IGenericSFImpl, iface)
1288 HRESULT hr = E_FAIL;
1289
1290 TRACE("(%p)->(%p %i %p)\n",This, pidl, iColumn, psd);
1291
1292 if (!psd || iColumn >= GENERICSHELLVIEWCOLUMNS ) return E_INVALIDARG;
1293
1294 if (!pidl)
1295 {
1296 /* the header titles */
1297 psd->fmt = GenericSFHeader[iColumn].fmt;
1298 psd->cxChar = GenericSFHeader[iColumn].cxChar;
1299 psd->str.uType = STRRET_CSTRA;
1300 LoadStringA(shell32_hInstance, GenericSFHeader[iColumn].colnameid, psd->str.u.cStr, MAX_PATH);
1301 return S_OK;
1302 }
1303 else
1304 {
1305 /* the data from the pidl */
1306 switch(iColumn)
1307 {
1308 case 0: /* name */
1309 hr = IShellFolder_GetDisplayNameOf(iface, pidl, SHGDN_NORMAL | SHGDN_INFOLDER, &psd->str);
1310 break;
1311 case 1: /* size */
1312 _ILGetFileSize (pidl, psd->str.u.cStr, MAX_PATH);
1313 break;
1314 case 2: /* type */
1315 _ILGetFileType(pidl, psd->str.u.cStr, MAX_PATH);
1316 break;
1317 case 3: /* date */
1318 _ILGetFileDate(pidl, psd->str.u.cStr, MAX_PATH);
1319 break;
1320 case 4: /* attributes */
1321 _ILGetFileAttributes(pidl, psd->str.u.cStr, MAX_PATH);
1322 break;
1323 }
1324 hr = S_OK;
1325 psd->str.uType = STRRET_CSTRA;
1326 }
1327
1328 return hr;
1329}
1330static HRESULT WINAPI IShellFolder_fnMapNameToSCID(
1331 IShellFolder2 * iface,
1332 LPCWSTR pwszName,
1333 SHCOLUMNID *pscid)
1334{
1335 _ICOM_THIS_From_IShellFolder2(IGenericSFImpl, iface)
1336 FIXME("(%p)\n",This);
1337 return E_NOTIMPL;
1338}
1339
1340static ICOM_VTABLE(IShellFolder2) sfvt =
1341{
1342 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1343 IShellFolder_fnQueryInterface,
1344 IShellFolder_fnAddRef,
1345 IShellFolder_fnRelease,
1346 IShellFolder_fnParseDisplayName,
1347 IShellFolder_fnEnumObjects,
1348 IShellFolder_fnBindToObject,
1349 IShellFolder_fnBindToStorage,
1350 IShellFolder_fnCompareIDs,
1351 IShellFolder_fnCreateViewObject,
1352 IShellFolder_fnGetAttributesOf,
1353 IShellFolder_fnGetUIObjectOf,
1354 IShellFolder_fnGetDisplayNameOf,
1355 IShellFolder_fnSetNameOf,
1356
1357 /* ShellFolder2 */
1358 IShellFolder_fnGetDefaultSearchGUID,
1359 IShellFolder_fnEnumSearches,
1360 IShellFolder_fnGetDefaultColumn,
1361 IShellFolder_fnGetDefaultColumnState,
1362 IShellFolder_fnGetDetailsEx,
1363 IShellFolder_fnGetDetailsOf,
1364 IShellFolder_fnMapNameToSCID
1365};
1366
1367/****************************************************************************
1368 * ISFHelper for IShellFolder implementation
1369 */
1370
1371static HRESULT WINAPI ISFHelper_fnQueryInterface(
1372 ISFHelper *iface,
1373 REFIID riid,
1374 LPVOID *ppvObj)
1375{
1376 _ICOM_THIS_From_ISFHelper(IGenericSFImpl,iface);
1377
1378 TRACE("(%p)\n", This);
1379
1380 return IUnknown_QueryInterface(This->pUnkOuter, riid, ppvObj);
1381}
1382
1383static ULONG WINAPI ISFHelper_fnAddRef(
1384 ISFHelper *iface)
1385{
1386 _ICOM_THIS_From_ISFHelper(IGenericSFImpl,iface);
1387
1388 TRACE("(%p)\n", This);
1389
1390 return IUnknown_AddRef(This->pUnkOuter);
1391}
1392
1393static ULONG WINAPI ISFHelper_fnRelease(
1394 ISFHelper *iface)
1395{
1396 _ICOM_THIS_From_ISFHelper(IGenericSFImpl,iface);
1397
1398 TRACE("(%p)\n", This);
1399
1400 return IUnknown_Release(This->pUnkOuter);
1401}
1402
1403
1404/****************************************************************************
1405 * ISFHelper_fnAddFolder
1406 *
1407 * creates a unique folder name
1408 */
1409
1410static HRESULT WINAPI ISFHelper_fnGetUniqueName(
1411 ISFHelper *iface,
1412 LPSTR lpName,
1413 UINT uLen)
1414{
1415 _ICOM_THIS_From_ISFHelper(IGenericSFImpl,iface)
1416 IEnumIDList * penum;
1417 HRESULT hr;
1418 char szText[MAX_PATH];
1419 char * szNewFolder = "New Folder";
1420
1421 TRACE("(%p)(%s %u)\n", This, lpName, uLen);
1422
1423 if (uLen < strlen(szNewFolder) + 4) return E_POINTER;
1424
1425 strcpy(lpName, szNewFolder);
1426
1427 hr = IShellFolder_fnEnumObjects(_IShellFolder2_(This), 0, SHCONTF_FOLDERS | SHCONTF_NONFOLDERS | SHCONTF_INCLUDEHIDDEN, &penum);
1428 if (penum)
1429 {
1430 LPITEMIDLIST pidl;
1431 DWORD dwFetched;
1432 int i=1;
1433
1434next: IEnumIDList_Reset(penum);
1435 while(S_OK == IEnumIDList_Next(penum, 1, &pidl, &dwFetched) && dwFetched)
1436 {
1437 _ILSimpleGetText(pidl, szText, MAX_PATH);
1438 if (0 == strcasecmp(szText, lpName))
1439 {
1440 sprintf(lpName, "%s %d", szNewFolder, i++);
1441 if (i > 99)
1442 {
1443 hr = E_FAIL;
1444 break;
1445 }
1446 goto next;
1447 }
1448 }
1449
1450 IEnumIDList_Release(penum);
1451 }
1452 return hr;
1453}
1454
1455/****************************************************************************
1456 * ISFHelper_fnAddFolder
1457 *
1458 * adds a new folder.
1459 */
1460
1461static HRESULT WINAPI ISFHelper_fnAddFolder(
1462 ISFHelper *iface,
1463 HWND hwnd,
1464 LPCSTR lpName,
1465 LPITEMIDLIST* ppidlOut)
1466{
1467 _ICOM_THIS_From_ISFHelper(IGenericSFImpl,iface)
1468 char lpstrNewDir[MAX_PATH];
1469 DWORD bRes;
1470 HRESULT hres = E_FAIL;
1471
1472 TRACE("(%p)(%s %p)\n", This, lpName, ppidlOut);
1473
1474 strcpy(lpstrNewDir, This->sMyPath);
1475 PathAddBackslashA(lpstrNewDir);
1476 strcat(lpstrNewDir, lpName);
1477
1478 bRes = CreateDirectoryA(lpstrNewDir, NULL);
1479
1480 if (bRes)
1481 {
1482 LPITEMIDLIST pidl, pidlitem;
1483
1484 pidlitem = SHSimpleIDListFromPathA(lpstrNewDir);
1485
1486 pidl = ILCombine(This->absPidl, pidlitem);
1487 SHChangeNotifyA(SHCNE_MKDIR, SHCNF_IDLIST, pidl, NULL);
1488 SHFree(pidl);
1489
1490 if (ppidlOut) *ppidlOut = pidlitem;
1491 hres = S_OK;
1492 }
1493 else
1494 {
1495 char lpstrText[128+MAX_PATH];
1496 char lpstrTempText[128];
1497 char lpstrCaption[256];
1498
1499 /* Cannot Create folder because of permissions */
1500 LoadStringA(shell32_hInstance, IDS_CREATEFOLDER_DENIED, lpstrTempText, sizeof(lpstrTempText));
1501 LoadStringA(shell32_hInstance, IDS_CREATEFOLDER_CAPTION, lpstrCaption, sizeof(lpstrCaption));
1502 sprintf(lpstrText,lpstrTempText, lpstrNewDir);
1503 MessageBoxA(hwnd,lpstrText, lpstrCaption, MB_OK | MB_ICONEXCLAMATION);
1504 }
1505
1506 return hres;
1507}
1508
1509/****************************************************************************
1510 * ISFHelper_fnDeleteItems
1511 *
1512 * deletes items in folder
1513 */
1514static HRESULT WINAPI ISFHelper_fnDeleteItems(
1515 ISFHelper *iface,
1516 UINT cidl,
1517 LPCITEMIDLIST* apidl)
1518{
1519 _ICOM_THIS_From_ISFHelper(IGenericSFImpl,iface)
1520 int i;
1521 char szPath[MAX_PATH];
1522 BOOL bConfirm = TRUE;
1523
1524 TRACE("(%p)(%u %p)\n", This, cidl, apidl);
1525
1526 /* deleting multiple items so give a slightly different warning */
1527 if(cidl != 1)
1528 {
1529 char tmp[8];
1530 snprintf(tmp, sizeof(tmp), "%d", cidl);
1531 if(!SHELL_WarnItemDelete(ASK_DELETE_MULTIPLE_ITEM, tmp))
1532 return E_FAIL;
1533 bConfirm = FALSE;
1534 }
1535
1536 for(i=0; i< cidl; i++)
1537 {
1538 strcpy(szPath, This->sMyPath);
1539 PathAddBackslashA(szPath);
1540 _ILSimpleGetText(apidl[i], szPath+strlen(szPath), MAX_PATH);
1541
1542 if (_ILIsFolder(apidl[i]))
1543 {
1544 LPITEMIDLIST pidl;
1545 TRACE("delete %s\n", szPath);
1546 if (! SHELL_DeleteDirectoryA(szPath, bConfirm))
1547 {
1548 TRACE("delete %s failed, bConfirm=%d\n", szPath, bConfirm);
1549 return E_FAIL;
1550 }
1551 pidl = ILCombine(This->absPidl, apidl[i]);
1552 SHChangeNotifyA(SHCNE_RMDIR, SHCNF_IDLIST, pidl, NULL);
1553 SHFree(pidl);
1554 }
1555 else if (_ILIsValue(apidl[i]))
1556 {
1557 LPITEMIDLIST pidl;
1558
1559 TRACE("delete %s\n", szPath);
1560 if (! SHELL_DeleteFileA(szPath, bConfirm))
1561 {
1562 TRACE("delete %s failed, bConfirm=%d\n", szPath, bConfirm);
1563 return E_FAIL;
1564 }
1565 pidl = ILCombine(This->absPidl, apidl[i]);
1566 SHChangeNotifyA(SHCNE_DELETE, SHCNF_IDLIST, pidl, NULL);
1567 SHFree(pidl);
1568 }
1569
1570 }
1571 return S_OK;
1572}
1573
1574/****************************************************************************
1575 * ISFHelper_fnCopyItems
1576 *
1577 * copies items to this folder
1578 */
1579static HRESULT WINAPI ISFHelper_fnCopyItems(
1580 ISFHelper *iface,
1581 IShellFolder* pSFFrom,
1582 UINT cidl,
1583 LPCITEMIDLIST *apidl)
1584{
1585 int i;
1586 IPersistFolder2 * ppf2=NULL;
1587 char szSrcPath[MAX_PATH], szDstPath[MAX_PATH];
1588 _ICOM_THIS_From_ISFHelper(IGenericSFImpl,iface);
1589
1590 TRACE("(%p)->(%p,%u,%p)\n", This, pSFFrom, cidl, apidl);
1591
1592 IShellFolder_QueryInterface(pSFFrom, &IID_IPersistFolder2, (LPVOID*)&ppf2);
1593 if (ppf2)
1594 {
1595 LPITEMIDLIST pidl;
1596 if (SUCCEEDED(IPersistFolder2_GetCurFolder(ppf2, &pidl)))
1597 {
1598 for (i=0; i<cidl; i++)
1599 {
1600 SHGetPathFromIDListA(pidl, szSrcPath);
1601 PathAddBackslashA(szSrcPath);
1602 _ILSimpleGetText(apidl[i], szSrcPath+strlen(szSrcPath), MAX_PATH);
1603
1604 strcpy(szDstPath, This->sMyPath);
1605 PathAddBackslashA(szDstPath);
1606 _ILSimpleGetText(apidl[i], szDstPath+strlen(szDstPath), MAX_PATH);
1607 MESSAGE("would copy %s to %s\n", szSrcPath, szDstPath);
1608 }
1609 SHFree(pidl);
1610 }
1611 IPersistFolder2_Release(ppf2);
1612 }
1613 return S_OK;
1614}
1615
1616static ICOM_VTABLE(ISFHelper) shvt =
1617{
1618 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1619 ISFHelper_fnQueryInterface,
1620 ISFHelper_fnAddRef,
1621 ISFHelper_fnRelease,
1622 ISFHelper_fnGetUniqueName,
1623 ISFHelper_fnAddFolder,
1624 ISFHelper_fnDeleteItems,
1625 ISFHelper_fnCopyItems,
1626};
1627
1628/***********************************************************************
1629* [Desktopfolder] IShellFolder implementation
1630*/
1631static struct ICOM_VTABLE(IShellFolder2) sfdvt;
1632
1633static shvheader DesktopSFHeader [] =
1634{
1635 { IDS_SHV_COLUMN1, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 15 },
1636 { IDS_SHV_COLUMN2, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10 },
1637 { IDS_SHV_COLUMN3, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10 },
1638 { IDS_SHV_COLUMN4, SHCOLSTATE_TYPE_DATE | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 12 },
1639 { IDS_SHV_COLUMN5, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 5 }
1640};
1641#define DESKTOPSHELLVIEWCOLUMNS 5
1642
1643/**************************************************************************
1644* ISF_Desktop_Constructor
1645*
1646*/
1647IShellFolder * ISF_Desktop_Constructor()
1648{
1649 IGenericSFImpl * sf;
1650
1651 sf=(IGenericSFImpl*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IGenericSFImpl));
1652 sf->ref=1;
1653 ICOM_VTBL(sf)=&unkvt;
1654 sf->lpvtblShellFolder=&sfdvt;
1655 sf->absPidl=_ILCreateDesktop(); /* my qualified pidl */
1656 sf->pUnkOuter = (IUnknown *) &sf->lpVtbl;
1657
1658 TRACE("(%p)\n",sf);
1659
1660 shell32_ObjCount++;
1661 return _IShellFolder_(sf);
1662}
1663
1664/**************************************************************************
1665 * ISF_Desktop_fnQueryInterface
1666 *
1667 * NOTES supports not IPersist/IPersistFolder
1668 */
1669static HRESULT WINAPI ISF_Desktop_fnQueryInterface(
1670 IShellFolder2 * iface,
1671 REFIID riid,
1672 LPVOID *ppvObj)
1673{
1674 _ICOM_THIS_From_IShellFolder2(IGenericSFImpl, iface)
1675
1676 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
1677
1678 *ppvObj = NULL;
1679
1680 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
1681 {
1682 *ppvObj = _IUnknown_(This);
1683 }
1684 else if(IsEqualIID(riid, &IID_IShellFolder)) /*IShellFolder*/
1685 {
1686 *ppvObj = _IShellFolder_(This);
1687 }
1688 else if(IsEqualIID(riid, &IID_IShellFolder2)) /*IShellFolder2*/
1689 {
1690 *ppvObj = _IShellFolder_(This);
1691 }
1692
1693 if(*ppvObj)
1694 {
1695 IUnknown_AddRef((IUnknown*)(*ppvObj));
1696 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
1697 return S_OK;
1698 }
1699 TRACE("-- Interface: E_NOINTERFACE\n");
1700 return E_NOINTERFACE;
1701}
1702
1703/**************************************************************************
1704* ISF_Desktop_fnParseDisplayName
1705*
1706* NOTES
1707* "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}" and "" binds
1708* to MyComputer
1709*/
1710static HRESULT WINAPI ISF_Desktop_fnParseDisplayName(
1711 IShellFolder2 * iface,
1712 HWND hwndOwner,
1713 LPBC pbcReserved,
1714 LPOLESTR lpszDisplayName,
1715 DWORD *pchEaten,
1716 LPITEMIDLIST *ppidl,
1717 DWORD *pdwAttributes)
1718{
1719 _ICOM_THIS_From_IShellFolder2(IGenericSFImpl, iface)
1720
1721 LPCWSTR szNext=NULL;
1722 LPITEMIDLIST pidlTemp=NULL;
1723 HRESULT hr=E_OUTOFMEMORY;
1724
1725 TRACE("(%p)->(HWND=0x%08x,%p,%p=%s,%p,pidl=%p,%p)\n",
1726 This,hwndOwner,pbcReserved,lpszDisplayName,
1727 debugstr_w(lpszDisplayName),pchEaten,ppidl,pdwAttributes);
1728
1729 *ppidl = 0;
1730 if (pchEaten) *pchEaten = 0; /* strange but like the original */
1731
1732 /* FIXME no real parsing implemented */
1733 pidlTemp = _ILCreateMyComputer();
1734 szNext = lpszDisplayName;
1735
1736 if (szNext && *szNext)
1737 {
1738 hr = SHELL32_ParseNextElement(hwndOwner, iface, &pidlTemp, (LPOLESTR)szNext, pchEaten, pdwAttributes);
1739 }
1740 else
1741 {
1742 hr = S_OK;
1743
1744 if (pdwAttributes && *pdwAttributes)
1745 {
1746 SHELL32_GetItemAttributes(_IShellFolder_(This), pidlTemp, pdwAttributes);
1747 }
1748 }
1749
1750 *ppidl = pidlTemp;
1751
1752 TRACE("(%p)->(-- ret=0x%08lx)\n", This, hr);
1753
1754 return hr;
1755}
1756
1757/**************************************************************************
1758* ISF_Desktop_fnEnumObjects
1759*/
1760static HRESULT WINAPI ISF_Desktop_fnEnumObjects(
1761 IShellFolder2 * iface,
1762 HWND hwndOwner,
1763 DWORD dwFlags,
1764 LPENUMIDLIST* ppEnumIDList)
1765{
1766 _ICOM_THIS_From_IShellFolder2(IGenericSFImpl, iface)
1767
1768 TRACE("(%p)->(HWND=0x%08x flags=0x%08lx pplist=%p)\n",This,hwndOwner,dwFlags,ppEnumIDList);
1769
1770 *ppEnumIDList = NULL;
1771 *ppEnumIDList = IEnumIDList_Constructor (NULL, dwFlags, EIDL_DESK);
1772
1773 TRACE("-- (%p)->(new ID List: %p)\n",This,*ppEnumIDList);
1774
1775 if(!*ppEnumIDList) return E_OUTOFMEMORY;
1776
1777 return S_OK;
1778}
1779
1780/**************************************************************************
1781* ISF_Desktop_fnBindToObject
1782*/
1783static HRESULT WINAPI ISF_Desktop_fnBindToObject( IShellFolder2 * iface, LPCITEMIDLIST pidl,
1784 LPBC pbcReserved, REFIID riid, LPVOID * ppvOut)
1785{
1786 _ICOM_THIS_From_IShellFolder2(IGenericSFImpl, iface)
1787 GUID const * clsid;
1788 IShellFolder *pShellFolder, *pSubFolder;
1789 HRESULT hr;
1790
1791 TRACE("(%p)->(pidl=%p,%p,\n\tIID:\t%s,%p)\n",
1792 This,pidl,pbcReserved,debugstr_guid(riid),ppvOut);
1793
1794 *ppvOut = NULL;
1795
1796 if ((clsid=_ILGetGUIDPointer(pidl)))
1797 {
1798 if ( IsEqualIID(clsid, &CLSID_MyComputer))
1799 {
1800 pShellFolder = ISF_MyComputer_Constructor();
1801 }
1802 else
1803 {
1804 /* shell extension */
1805 if (!SUCCEEDED(SHELL32_CoCreateInitSF (This->absPidl, pidl, clsid, riid, (LPVOID*)&pShellFolder)))
1806 {
1807 return E_INVALIDARG;
1808 }
1809 }
1810 }
1811 else
1812 {
1813 /* file system folder on the desktop */
1814 LPITEMIDLIST deskpidl, firstpidl, completepidl;
1815 IPersistFolder * ppf;
1816
1817 /* combine pidls */
1818 SHGetSpecialFolderLocation(0, CSIDL_DESKTOPDIRECTORY, &deskpidl);
1819 firstpidl = ILCloneFirst(pidl);
1820 completepidl = ILCombine(deskpidl, firstpidl);
1821
1822 pShellFolder = IShellFolder_Constructor(NULL, NULL);
1823 if (SUCCEEDED(IShellFolder_QueryInterface(pShellFolder, &IID_IPersistFolder, (LPVOID*)&ppf)))
1824 {
1825 IPersistFolder_Initialize(ppf, completepidl);
1826 IPersistFolder_Release(ppf);
1827 }
1828 ILFree(completepidl);
1829 ILFree(deskpidl);
1830 ILFree(firstpidl);
1831 }
1832
1833 if (_ILIsPidlSimple(pidl)) /* no sub folders */
1834 {
1835 *ppvOut = pShellFolder;
1836 hr = S_OK;
1837 }
1838 else /* go deeper */
1839 {
1840 hr = IShellFolder_BindToObject(pShellFolder, ILGetNext(pidl), NULL, riid, (LPVOID)&pSubFolder);
1841 IShellFolder_Release(pShellFolder);
1842 *ppvOut = pSubFolder;
1843 }
1844
1845 TRACE("-- (%p) returning (%p) %08lx\n",This, *ppvOut, hr);
1846
1847 return hr;
1848}
1849
1850/**************************************************************************
1851* ISF_Desktop_fnCreateViewObject
1852*/
1853static HRESULT WINAPI ISF_Desktop_fnCreateViewObject( IShellFolder2 * iface,
1854 HWND hwndOwner, REFIID riid, LPVOID *ppvOut)
1855{
1856 _ICOM_THIS_From_IShellFolder2(IGenericSFImpl, iface)
1857
1858 LPSHELLVIEW pShellView;
1859 HRESULT hr = E_INVALIDARG;
1860
1861 TRACE("(%p)->(hwnd=0x%x,\n\tIID:\t%s,%p)\n",This,hwndOwner,debugstr_guid(riid),ppvOut);
1862
1863 if(ppvOut)
1864 {
1865 *ppvOut = NULL;
1866
1867 if(IsEqualIID(riid, &IID_IDropTarget))
1868 {
1869 WARN("IDropTarget not implemented\n");
1870 hr = E_NOTIMPL;
1871 }
1872 else if(IsEqualIID(riid, &IID_IContextMenu))
1873 {
1874 WARN("IContextMenu not implemented\n");
1875 hr = E_NOTIMPL;
1876 }
1877 else if(IsEqualIID(riid, &IID_IShellView))
1878 {
1879 pShellView = IShellView_Constructor((IShellFolder*)iface);
1880 if(pShellView)
1881 {
1882 hr = IShellView_QueryInterface(pShellView, riid, ppvOut);
1883 IShellView_Release(pShellView);
1884 }
1885 }
1886 }
1887 TRACE("-- (%p)->(interface=%p)\n",This, ppvOut);
1888 return hr;
1889}
1890
1891/**************************************************************************
1892* ISF_Desktop_fnGetAttributesOf
1893*/
1894static HRESULT WINAPI ISF_Desktop_fnGetAttributesOf(
1895 IShellFolder2 * iface,
1896 UINT cidl,
1897 LPCITEMIDLIST *apidl,
1898 DWORD *rgfInOut)
1899{
1900 _ICOM_THIS_From_IShellFolder2(IGenericSFImpl, iface)
1901
1902 HRESULT hr = S_OK;
1903
1904 TRACE("(%p)->(cidl=%d apidl=%p mask=0x%08lx)\n",This,cidl,apidl, *rgfInOut);
1905
1906 if ( (!cidl) || (!apidl) || (!rgfInOut))
1907 return E_INVALIDARG;
1908
1909 while (cidl > 0 && *apidl)
1910 {
1911 pdump (*apidl);
1912 SHELL32_GetItemAttributes(_IShellFolder_(This), *apidl, rgfInOut);
1913 apidl++;
1914 cidl--;
1915 }
1916
1917 TRACE("-- result=0x%08lx\n",*rgfInOut);
1918
1919 return hr;
1920}
1921
1922/**************************************************************************
1923* ISF_Desktop_fnGetDisplayNameOf
1924*
1925* NOTES
1926* special case: pidl = null gives desktop-name back
1927*/
1928static HRESULT WINAPI ISF_Desktop_fnGetDisplayNameOf(
1929 IShellFolder2 * iface,
1930 LPCITEMIDLIST pidl,
1931 DWORD dwFlags,
1932 LPSTRRET strRet)
1933{
1934 _ICOM_THIS_From_IShellFolder2(IGenericSFImpl, iface)
1935
1936 CHAR szPath[MAX_PATH]= "";
1937
1938 TRACE("(%p)->(pidl=%p,0x%08lx,%p)\n",This,pidl,dwFlags,strRet);
1939 pdump(pidl);
1940
1941 if(!strRet) return E_INVALIDARG;
1942
1943 if(!pidl)
1944 {
1945 HCR_GetClassName(&CLSID_ShellDesktop, szPath, MAX_PATH);
1946 }
1947 else if ( _ILIsPidlSimple(pidl) )
1948 {
1949 _ILSimpleGetText(pidl, szPath, MAX_PATH);
1950 }
1951 else
1952 {
1953 if (!SUCCEEDED(SHELL32_GetDisplayNameOfChild(iface, pidl, dwFlags, szPath, MAX_PATH)))
1954 return E_OUTOFMEMORY;
1955 }
1956 strRet->uType = STRRET_CSTRA;
1957 lstrcpynA(strRet->u.cStr, szPath, MAX_PATH);
1958
1959
1960 TRACE("-- (%p)->(%s)\n", This, szPath);
1961 return S_OK;
1962}
1963
1964static HRESULT WINAPI ISF_Desktop_fnGetDefaultSearchGUID(
1965 IShellFolder2 * iface,
1966 GUID *pguid)
1967{
1968 _ICOM_THIS_From_IShellFolder2(IGenericSFImpl, iface)
1969 FIXME("(%p)\n",This);
1970 return E_NOTIMPL;
1971}
1972static HRESULT WINAPI ISF_Desktop_fnEnumSearches(
1973 IShellFolder2 * iface,
1974 IEnumExtraSearch **ppenum)
1975{
1976 _ICOM_THIS_From_IShellFolder2(IGenericSFImpl, iface)
1977 FIXME("(%p)\n",This);
1978 return E_NOTIMPL;
1979}
1980static HRESULT WINAPI ISF_Desktop_fnGetDefaultColumn(
1981 IShellFolder2 * iface,
1982 DWORD dwRes,
1983 ULONG *pSort,
1984 ULONG *pDisplay)
1985{
1986 _ICOM_THIS_From_IShellFolder2(IGenericSFImpl, iface)
1987
1988 TRACE("(%p)\n",This);
1989
1990 if (pSort) *pSort = 0;
1991 if (pDisplay) *pDisplay = 0;
1992
1993 return S_OK;
1994}
1995static HRESULT WINAPI ISF_Desktop_fnGetDefaultColumnState(
1996 IShellFolder2 * iface,
1997 UINT iColumn,
1998 DWORD *pcsFlags)
1999{
2000 _ICOM_THIS_From_IShellFolder2(IGenericSFImpl, iface)
2001
2002 TRACE("(%p)\n",This);
2003
2004 if (!pcsFlags || iColumn >= DESKTOPSHELLVIEWCOLUMNS ) return E_INVALIDARG;
2005
2006 *pcsFlags = DesktopSFHeader[iColumn].pcsFlags;
2007
2008 return S_OK;
2009}
2010static HRESULT WINAPI ISF_Desktop_fnGetDetailsEx(
2011 IShellFolder2 * iface,
2012 LPCITEMIDLIST pidl,
2013 const SHCOLUMNID *pscid,
2014 VARIANT *pv)
2015{
2016 _ICOM_THIS_From_IShellFolder2(IGenericSFImpl, iface)
2017 FIXME("(%p)\n",This);
2018
2019 return E_NOTIMPL;
2020}
2021static HRESULT WINAPI ISF_Desktop_fnGetDetailsOf(
2022 IShellFolder2 * iface,
2023 LPCITEMIDLIST pidl,
2024 UINT iColumn,
2025 SHELLDETAILS *psd)
2026{
2027 _ICOM_THIS_From_IShellFolder2(IGenericSFImpl, iface)
2028 HRESULT hr = E_FAIL;;
2029
2030 TRACE("(%p)->(%p %i %p)\n",This, pidl, iColumn, psd);
2031
2032 if (!psd || iColumn >= DESKTOPSHELLVIEWCOLUMNS ) return E_INVALIDARG;
2033
2034 if (!pidl)
2035 {
2036 psd->fmt = DesktopSFHeader[iColumn].fmt;
2037 psd->cxChar = DesktopSFHeader[iColumn].cxChar;
2038 psd->str.uType = STRRET_CSTRA;
2039 LoadStringA(shell32_hInstance, DesktopSFHeader[iColumn].colnameid, psd->str.u.cStr, MAX_PATH);
2040 return S_OK;
2041 }
2042 else
2043 {
2044 /* the data from the pidl */
2045 switch(iColumn)
2046 {
2047 case 0: /* name */
2048 hr = IShellFolder_GetDisplayNameOf(iface, pidl, SHGDN_NORMAL | SHGDN_INFOLDER, &psd->str);
2049 break;
2050 case 1: /* size */
2051 _ILGetFileSize (pidl, psd->str.u.cStr, MAX_PATH);
2052 break;
2053 case 2: /* type */
2054 _ILGetFileType(pidl, psd->str.u.cStr, MAX_PATH);
2055 break;
2056 case 3: /* date */
2057 _ILGetFileDate(pidl, psd->str.u.cStr, MAX_PATH);
2058 break;
2059 case 4: /* attributes */
2060 _ILGetFileAttributes(pidl, psd->str.u.cStr, MAX_PATH);
2061 break;
2062 }
2063 hr = S_OK;
2064 psd->str.uType = STRRET_CSTRA;
2065 }
2066
2067 return hr;
2068}
2069static HRESULT WINAPI ISF_Desktop_fnMapNameToSCID(
2070 IShellFolder2 * iface,
2071 LPCWSTR pwszName,
2072 SHCOLUMNID *pscid)
2073{
2074 _ICOM_THIS_From_IShellFolder2(IGenericSFImpl, iface)
2075 FIXME("(%p)\n",This);
2076 return E_NOTIMPL;
2077}
2078
2079static ICOM_VTABLE(IShellFolder2) sfdvt =
2080{
2081 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
2082 ISF_Desktop_fnQueryInterface,
2083 IShellFolder_fnAddRef,
2084 IShellFolder_fnRelease,
2085 ISF_Desktop_fnParseDisplayName,
2086 ISF_Desktop_fnEnumObjects,
2087 ISF_Desktop_fnBindToObject,
2088 IShellFolder_fnBindToStorage,
2089 IShellFolder_fnCompareIDs,
2090 ISF_Desktop_fnCreateViewObject,
2091 ISF_Desktop_fnGetAttributesOf,
2092 IShellFolder_fnGetUIObjectOf,
2093 ISF_Desktop_fnGetDisplayNameOf,
2094 IShellFolder_fnSetNameOf,
2095
2096 /* ShellFolder2 */
2097 ISF_Desktop_fnGetDefaultSearchGUID,
2098 ISF_Desktop_fnEnumSearches,
2099 ISF_Desktop_fnGetDefaultColumn,
2100 ISF_Desktop_fnGetDefaultColumnState,
2101 ISF_Desktop_fnGetDetailsEx,
2102 ISF_Desktop_fnGetDetailsOf,
2103 ISF_Desktop_fnMapNameToSCID
2104};
2105
2106
2107/***********************************************************************
2108* IShellFolder [MyComputer] implementation
2109*/
2110
2111static struct ICOM_VTABLE(IShellFolder2) sfmcvt;
2112
2113static shvheader MyComputerSFHeader [] =
2114{
2115 { IDS_SHV_COLUMN1, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 15 },
2116 { IDS_SHV_COLUMN3, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10 },
2117 { IDS_SHV_COLUMN6, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10 },
2118 { IDS_SHV_COLUMN7, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10 },
2119};
2120#define MYCOMPUTERSHELLVIEWCOLUMNS 4
2121
2122/**************************************************************************
2123* ISF_MyComputer_Constructor
2124*/
2125static IShellFolder * ISF_MyComputer_Constructor(void)
2126{
2127 IGenericSFImpl * sf;
2128
2129 sf=(IGenericSFImpl*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IGenericSFImpl));
2130 sf->ref=1;
2131
2132 ICOM_VTBL(sf)=&unkvt;
2133 sf->lpvtblShellFolder=&sfmcvt;
2134 sf->lpvtblPersistFolder2 = &psfvt;
2135 sf->pclsid = (CLSID*)&CLSID_SFMyComp;
2136 sf->absPidl=_ILCreateMyComputer(); /* my qualified pidl */
2137 sf->pUnkOuter = (IUnknown *) &sf->lpVtbl;
2138
2139 TRACE("(%p)\n",sf);
2140
2141 shell32_ObjCount++;
2142 return _IShellFolder_(sf);
2143}
2144
2145/**************************************************************************
2146* ISF_MyComputer_fnParseDisplayName
2147*/
2148static HRESULT WINAPI ISF_MyComputer_fnParseDisplayName(
2149 IShellFolder2 * iface,
2150 HWND hwndOwner,
2151 LPBC pbcReserved,
2152 LPOLESTR lpszDisplayName,
2153 DWORD *pchEaten,
2154 LPITEMIDLIST *ppidl,
2155 DWORD *pdwAttributes)
2156{
2157 _ICOM_THIS_From_IShellFolder2(IGenericSFImpl, iface)
2158
2159 HRESULT hr = E_OUTOFMEMORY;
2160 LPCWSTR szNext=NULL;
2161 WCHAR szElement[MAX_PATH];
2162 CHAR szTempA[MAX_PATH];
2163 LPITEMIDLIST pidlTemp;
2164
2165 TRACE("(%p)->(HWND=0x%08x,%p,%p=%s,%p,pidl=%p,%p)\n",
2166 This,hwndOwner,pbcReserved,lpszDisplayName,
2167 debugstr_w(lpszDisplayName),pchEaten,ppidl,pdwAttributes);
2168
2169 *ppidl = 0;
2170 if (pchEaten) *pchEaten = 0; /* strange but like the original */
2171
2172 /* do we have an absolute path name ? */
2173 if (PathGetDriveNumberW(lpszDisplayName) >= 0 &&
2174 lpszDisplayName[2] == (WCHAR)'\\')
2175 {
2176 szNext = GetNextElementW(lpszDisplayName, szElement, MAX_PATH);
2177 WideCharToMultiByte( CP_ACP, 0, szElement, -1, szTempA, MAX_PATH, NULL, NULL );
2178 pidlTemp = _ILCreateDrive(szTempA);
2179
2180 if (szNext && *szNext)
2181 {
2182 hr = SHELL32_ParseNextElement(hwndOwner, iface, &pidlTemp, (LPOLESTR)szNext, pchEaten, pdwAttributes);
2183 }
2184 else
2185 {
2186 if (pdwAttributes && *pdwAttributes)
2187 {
2188 SHELL32_GetItemAttributes(_IShellFolder_(This), pidlTemp, pdwAttributes);
2189 }
2190 hr = S_OK;
2191 }
2192 *ppidl = pidlTemp;
2193 }
2194
2195 TRACE("(%p)->(-- ret=0x%08lx)\n", This, hr);
2196
2197 return hr;
2198}
2199
2200/**************************************************************************
2201* ISF_MyComputer_fnEnumObjects
2202*/
2203static HRESULT WINAPI ISF_MyComputer_fnEnumObjects(
2204 IShellFolder2 * iface,
2205 HWND hwndOwner,
2206 DWORD dwFlags,
2207 LPENUMIDLIST* ppEnumIDList)
2208{
2209 _ICOM_THIS_From_IShellFolder2(IGenericSFImpl, iface)
2210
2211 TRACE("(%p)->(HWND=0x%08x flags=0x%08lx pplist=%p)\n",This,hwndOwner,dwFlags,ppEnumIDList);
2212
2213 *ppEnumIDList = NULL;
2214 *ppEnumIDList = IEnumIDList_Constructor (NULL, dwFlags, EIDL_MYCOMP);
2215
2216 TRACE("-- (%p)->(new ID List: %p)\n",This,*ppEnumIDList);
2217
2218 if(!*ppEnumIDList) return E_OUTOFMEMORY;
2219
2220 return S_OK;
2221}
2222
2223/**************************************************************************
2224* ISF_MyComputer_fnBindToObject
2225*/
2226static HRESULT WINAPI ISF_MyComputer_fnBindToObject( IShellFolder2 * iface, LPCITEMIDLIST pidl,
2227 LPBC pbcReserved, REFIID riid, LPVOID * ppvOut)
2228{
2229 _ICOM_THIS_From_IShellFolder2(IGenericSFImpl, iface)
2230 GUID const * clsid;
2231 IShellFolder *pShellFolder, *pSubFolder;
2232 LPITEMIDLIST pidltemp;
2233 HRESULT hr;
2234
2235 TRACE("(%p)->(pidl=%p,%p,\n\tIID:\t%s,%p)\n",
2236 This,pidl,pbcReserved,debugstr_guid(riid),ppvOut);
2237
2238 if(!pidl || !ppvOut) return E_INVALIDARG;
2239
2240 *ppvOut = NULL;
2241
2242 if ((clsid=_ILGetGUIDPointer(pidl)) && !IsEqualIID(clsid, &CLSID_MyComputer))
2243 {
2244 if (!SUCCEEDED(SHELL32_CoCreateInitSF (This->absPidl, pidl, clsid, riid, (LPVOID*)&pShellFolder)))
2245 {
2246 return E_FAIL;
2247 }
2248 }
2249 else
2250 {
2251 if (!_ILIsDrive(pidl)) return E_INVALIDARG;
2252
2253 pidltemp = ILCloneFirst(pidl);
2254 pShellFolder = IShellFolder_Constructor(iface, pidltemp);
2255 ILFree(pidltemp);
2256 }
2257
2258 if (_ILIsPidlSimple(pidl)) /* no sub folders */
2259 {
2260 *ppvOut = pShellFolder;
2261 hr = S_OK;
2262 }
2263 else /* go deeper */
2264 {
2265 hr = IShellFolder_BindToObject(pShellFolder, ILGetNext(pidl), NULL,
2266 riid, (LPVOID)&pSubFolder);
2267 IShellFolder_Release(pShellFolder);
2268 *ppvOut = pSubFolder;
2269 }
2270
2271 TRACE("-- (%p) returning (%p) %08lx\n",This, *ppvOut, hr);
2272
2273 return hr;
2274}
2275
2276/**************************************************************************
2277* ISF_MyComputer_fnCreateViewObject
2278*/
2279static HRESULT WINAPI ISF_MyComputer_fnCreateViewObject( IShellFolder2 * iface,
2280 HWND hwndOwner, REFIID riid, LPVOID *ppvOut)
2281{
2282 _ICOM_THIS_From_IShellFolder2(IGenericSFImpl, iface)
2283
2284 LPSHELLVIEW pShellView;
2285 HRESULT hr = E_INVALIDARG;
2286
2287 TRACE("(%p)->(hwnd=0x%x,\n\tIID:\t%s,%p)\n",This,hwndOwner,debugstr_guid(riid),ppvOut);
2288
2289 if(ppvOut)
2290 {
2291 *ppvOut = NULL;
2292
2293 if(IsEqualIID(riid, &IID_IDropTarget))
2294 {
2295 WARN("IDropTarget not implemented\n");
2296 hr = E_NOTIMPL;
2297 }
2298 else if(IsEqualIID(riid, &IID_IContextMenu))
2299 {
2300 WARN("IContextMenu not implemented\n");
2301 hr = E_NOTIMPL;
2302 }
2303 else if(IsEqualIID(riid, &IID_IShellView))
2304 {
2305 pShellView = IShellView_Constructor((IShellFolder*)iface);
2306 if(pShellView)
2307 {
2308 hr = IShellView_QueryInterface(pShellView, riid, ppvOut);
2309 IShellView_Release(pShellView);
2310 }
2311 }
2312 }
2313 TRACE("-- (%p)->(interface=%p)\n",This, ppvOut);
2314 return hr;
2315}
2316
2317/**************************************************************************
2318* ISF_MyComputer_fnGetAttributesOf
2319*/
2320static HRESULT WINAPI ISF_MyComputer_fnGetAttributesOf(
2321 IShellFolder2 * iface,
2322 UINT cidl,
2323 LPCITEMIDLIST *apidl,
2324 DWORD *rgfInOut)
2325{
2326 _ICOM_THIS_From_IShellFolder2(IGenericSFImpl, iface)
2327
2328 HRESULT hr = S_OK;
2329
2330 TRACE("(%p)->(cidl=%d apidl=%p mask=0x%08lx)\n",This,cidl,apidl,*rgfInOut);
2331
2332 if ( (!cidl) || (!apidl) || (!rgfInOut))
2333 return E_INVALIDARG;
2334
2335 while (cidl > 0 && *apidl)
2336 {
2337 pdump (*apidl);
2338 SHELL32_GetItemAttributes(_IShellFolder_(This), *apidl, rgfInOut);
2339 apidl++;
2340 cidl--;
2341 }
2342
2343 TRACE("-- result=0x%08lx\n",*rgfInOut);
2344 return hr;
2345}
2346
2347/**************************************************************************
2348* ISF_MyComputer_fnGetDisplayNameOf
2349*
2350* NOTES
2351* The desktopfolder creates only complete paths (SHGDN_FORPARSING).
2352* SHGDN_INFOLDER makes no sense.
2353*/
2354static HRESULT WINAPI ISF_MyComputer_fnGetDisplayNameOf(
2355 IShellFolder2 * iface,
2356 LPCITEMIDLIST pidl,
2357 DWORD dwFlags,
2358 LPSTRRET strRet)
2359{
2360 _ICOM_THIS_From_IShellFolder2(IGenericSFImpl, iface)
2361
2362 char szPath[MAX_PATH], szDrive[18];
2363 int len = 0;
2364 BOOL bSimplePidl;
2365
2366 TRACE("(%p)->(pidl=%p,0x%08lx,%p)\n",This,pidl,dwFlags,strRet);
2367 pdump(pidl);
2368
2369 if(!strRet) return E_INVALIDARG;
2370
2371 szPath[0]=0x00; szDrive[0]=0x00;
2372
2373
2374 bSimplePidl = _ILIsPidlSimple(pidl);
2375
2376 if (_ILIsSpecialFolder(pidl))
2377 {
2378 /* take names of special folders only if its only this folder */
2379 if ( bSimplePidl )
2380 {
2381 _ILSimpleGetText(pidl, szPath, MAX_PATH); /* append my own path */
2382 }
2383 }
2384 else
2385 {
2386 if (!_ILIsDrive(pidl))
2387 {
2388 ERR("Wrong pidl type\n");
2389 return E_INVALIDARG;
2390 }
2391
2392 _ILSimpleGetText(pidl, szPath, MAX_PATH); /* append my own path */
2393
2394 /* long view "lw_name (C:)" */
2395 if ( bSimplePidl && !(dwFlags & SHGDN_FORPARSING))
2396 {
2397 DWORD dwVolumeSerialNumber,dwMaximumComponetLength,dwFileSystemFlags;
2398
2399#ifdef __WIN32OS2__
2400//CB: floppy drives have a fixed name
2401 if ((szPath[0] == 'A') || (szPath[0] == 'a') || (szPath[0] == 'B') || (szPath[0] == 'b'))
2402 {
2403 //floppy
2404 strncpy(szDrive,szPath,2);
2405 //3.5 floppy
2406 LoadStringA(shell32_hInstance,IDS_35FLOPPY,szPath,sizeof(szPath)-10);
2407 //CB: todo: 5.25 floppy check
2408 strcat(szPath," (");
2409 strncat(szPath,szDrive,2);
2410 strcat(szPath,")");
2411 } else
2412 {
2413 GetVolumeInformationA(szPath,szDrive,12,&dwVolumeSerialNumber,&dwMaximumComponetLength,&dwFileSystemFlags,NULL,0);
2414 strcat (szDrive," (");
2415 strncat (szDrive, szPath, 2);
2416 strcat (szDrive,")");
2417 strcpy (szPath, szDrive);
2418 }
2419#else
2420 GetVolumeInformationA(szPath,szDrive,12,&dwVolumeSerialNumber,&dwMaximumComponetLength,&dwFileSystemFlags,NULL,0);
2421 strcat (szDrive," (");
2422 strncat (szDrive, szPath, 2);
2423 strcat (szDrive,")");
2424 strcpy (szPath, szDrive);
2425#endif
2426 }
2427 }
2428
2429 if (!bSimplePidl) /* go deeper if needed */
2430 {
2431 PathAddBackslashA(szPath);
2432 len = strlen(szPath);
2433
2434 if (!SUCCEEDED(SHELL32_GetDisplayNameOfChild(iface, pidl, dwFlags | SHGDN_FORPARSING, szPath + len, MAX_PATH - len)))
2435 return E_OUTOFMEMORY;
2436 }
2437 strRet->uType = STRRET_CSTRA;
2438 lstrcpynA(strRet->u.cStr, szPath, MAX_PATH);
2439
2440
2441 TRACE("-- (%p)->(%s)\n", This, szPath);
2442 return S_OK;
2443}
2444
2445static HRESULT WINAPI ISF_MyComputer_fnGetDefaultSearchGUID(
2446 IShellFolder2 * iface,
2447 GUID *pguid)
2448{
2449 _ICOM_THIS_From_IShellFolder2(IGenericSFImpl, iface)
2450 FIXME("(%p)\n",This);
2451 return E_NOTIMPL;
2452}
2453static HRESULT WINAPI ISF_MyComputer_fnEnumSearches(
2454 IShellFolder2 * iface,
2455 IEnumExtraSearch **ppenum)
2456{
2457 _ICOM_THIS_From_IShellFolder2(IGenericSFImpl, iface)
2458 FIXME("(%p)\n",This);
2459 return E_NOTIMPL;
2460}
2461static HRESULT WINAPI ISF_MyComputer_fnGetDefaultColumn(
2462 IShellFolder2 * iface,
2463 DWORD dwRes,
2464 ULONG *pSort,
2465 ULONG *pDisplay)
2466{
2467 _ICOM_THIS_From_IShellFolder2(IGenericSFImpl, iface)
2468
2469 TRACE("(%p)\n",This);
2470
2471 if (pSort) *pSort = 0;
2472 if (pDisplay) *pDisplay = 0;
2473
2474 return S_OK;
2475}
2476static HRESULT WINAPI ISF_MyComputer_fnGetDefaultColumnState(
2477 IShellFolder2 * iface,
2478 UINT iColumn,
2479 DWORD *pcsFlags)
2480{
2481 _ICOM_THIS_From_IShellFolder2(IGenericSFImpl, iface)
2482
2483 TRACE("(%p)\n",This);
2484
2485 if (!pcsFlags || iColumn >= MYCOMPUTERSHELLVIEWCOLUMNS ) return E_INVALIDARG;
2486
2487 *pcsFlags = MyComputerSFHeader[iColumn].pcsFlags;
2488
2489 return S_OK;
2490}
2491static HRESULT WINAPI ISF_MyComputer_fnGetDetailsEx(
2492 IShellFolder2 * iface,
2493 LPCITEMIDLIST pidl,
2494 const SHCOLUMNID *pscid,
2495 VARIANT *pv)
2496{
2497 _ICOM_THIS_From_IShellFolder2(IGenericSFImpl, iface)
2498 FIXME("(%p)\n",This);
2499
2500 return E_NOTIMPL;
2501}
2502
2503/* fixme: drive size >4GB is rolling over */
2504static HRESULT WINAPI ISF_MyComputer_fnGetDetailsOf(
2505 IShellFolder2 * iface,
2506 LPCITEMIDLIST pidl,
2507 UINT iColumn,
2508 SHELLDETAILS *psd)
2509{
2510 _ICOM_THIS_From_IShellFolder2(IGenericSFImpl, iface)
2511 HRESULT hr;
2512
2513 TRACE("(%p)->(%p %i %p)\n",This, pidl, iColumn, psd);
2514
2515 if (!psd || iColumn >= MYCOMPUTERSHELLVIEWCOLUMNS ) return E_INVALIDARG;
2516
2517 if (!pidl)
2518 {
2519 psd->fmt = MyComputerSFHeader[iColumn].fmt;
2520 psd->cxChar = MyComputerSFHeader[iColumn].cxChar;
2521 psd->str.uType = STRRET_CSTRA;
2522 LoadStringA(shell32_hInstance, MyComputerSFHeader[iColumn].colnameid, psd->str.u.cStr, MAX_PATH);
2523 return S_OK;
2524 }
2525 else
2526 {
2527 char szPath[MAX_PATH];
2528 ULARGE_INTEGER ulBytes;
2529
2530 psd->str.u.cStr[0] = 0x00;
2531 psd->str.uType = STRRET_CSTRA;
2532 switch(iColumn)
2533 {
2534 case 0: /* name */
2535 hr = IShellFolder_GetDisplayNameOf(iface, pidl, SHGDN_NORMAL | SHGDN_INFOLDER, &psd->str);
2536 break;
2537 case 1: /* type */
2538 _ILGetFileType(pidl, psd->str.u.cStr, MAX_PATH);
2539 break;
2540 case 2: /* total size */
2541 if (_ILIsDrive(pidl))
2542 {
2543 _ILSimpleGetText(pidl, szPath, MAX_PATH);
2544 GetDiskFreeSpaceExA(szPath, NULL, &ulBytes, NULL);
2545 StrFormatByteSizeA(ulBytes.LowPart, psd->str.u.cStr, MAX_PATH);
2546 }
2547 break;
2548 case 3: /* free size */
2549 if (_ILIsDrive(pidl))
2550 {
2551 _ILSimpleGetText(pidl, szPath, MAX_PATH);
2552 GetDiskFreeSpaceExA(szPath, &ulBytes, NULL, NULL);
2553 StrFormatByteSizeA(ulBytes.LowPart, psd->str.u.cStr, MAX_PATH);
2554 }
2555 break;
2556 }
2557 hr = S_OK;
2558 }
2559
2560 return hr;
2561}
2562static HRESULT WINAPI ISF_MyComputer_fnMapNameToSCID(
2563 IShellFolder2 * iface,
2564 LPCWSTR pwszName,
2565 SHCOLUMNID *pscid)
2566{
2567 _ICOM_THIS_From_IShellFolder2(IGenericSFImpl, iface)
2568 FIXME("(%p)\n",This);
2569 return E_NOTIMPL;
2570}
2571
2572static ICOM_VTABLE(IShellFolder2) sfmcvt =
2573{
2574 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
2575 IShellFolder_fnQueryInterface,
2576 IShellFolder_fnAddRef,
2577 IShellFolder_fnRelease,
2578 ISF_MyComputer_fnParseDisplayName,
2579 ISF_MyComputer_fnEnumObjects,
2580 ISF_MyComputer_fnBindToObject,
2581 IShellFolder_fnBindToStorage,
2582 IShellFolder_fnCompareIDs,
2583 ISF_MyComputer_fnCreateViewObject,
2584 ISF_MyComputer_fnGetAttributesOf,
2585 IShellFolder_fnGetUIObjectOf,
2586 ISF_MyComputer_fnGetDisplayNameOf,
2587 IShellFolder_fnSetNameOf,
2588
2589 /* ShellFolder2 */
2590 ISF_MyComputer_fnGetDefaultSearchGUID,
2591 ISF_MyComputer_fnEnumSearches,
2592 ISF_MyComputer_fnGetDefaultColumn,
2593 ISF_MyComputer_fnGetDefaultColumnState,
2594 ISF_MyComputer_fnGetDetailsEx,
2595 ISF_MyComputer_fnGetDetailsOf,
2596 ISF_MyComputer_fnMapNameToSCID
2597};
2598
2599
2600/************************************************************************
2601 * ISFPersistFolder_QueryInterface (IUnknown)
2602 *
2603 */
2604static HRESULT WINAPI ISFPersistFolder2_QueryInterface(
2605 IPersistFolder2 * iface,
2606 REFIID iid,
2607 LPVOID* ppvObj)
2608{
2609 _ICOM_THIS_From_IPersistFolder2(IGenericSFImpl, iface);
2610
2611 TRACE("(%p)\n", This);
2612
2613 return IUnknown_QueryInterface(This->pUnkOuter, iid, ppvObj);
2614}
2615
2616/************************************************************************
2617 * ISFPersistFolder_AddRef (IUnknown)
2618 *
2619 */
2620static ULONG WINAPI ISFPersistFolder2_AddRef(
2621 IPersistFolder2 * iface)
2622{
2623 _ICOM_THIS_From_IPersistFolder2(IGenericSFImpl, iface);
2624
2625 TRACE("(%p)\n", This);
2626
2627 return IUnknown_AddRef(This->pUnkOuter);
2628}
2629
2630/************************************************************************
2631 * ISFPersistFolder_Release (IUnknown)
2632 *
2633 */
2634static ULONG WINAPI ISFPersistFolder2_Release(
2635 IPersistFolder2 * iface)
2636{
2637 _ICOM_THIS_From_IPersistFolder2(IGenericSFImpl, iface);
2638
2639 TRACE("(%p)\n", This);
2640
2641 return IUnknown_Release(This->pUnkOuter);
2642}
2643
2644/************************************************************************
2645 * ISFPersistFolder_GetClassID (IPersist)
2646 */
2647static HRESULT WINAPI ISFPersistFolder2_GetClassID(
2648 IPersistFolder2 * iface,
2649 CLSID * lpClassId)
2650{
2651 _ICOM_THIS_From_IPersistFolder2(IGenericSFImpl, iface);
2652
2653 TRACE("(%p)\n", This);
2654
2655 if (!lpClassId) return E_POINTER;
2656 *lpClassId = *This->pclsid;
2657
2658 return S_OK;
2659}
2660
2661/************************************************************************
2662 * ISFPersistFolder_Initialize (IPersistFolder)
2663 *
2664 * NOTES
2665 * sMyPath is not set. Don't know how to handle in a non rooted environment.
2666 */
2667static HRESULT WINAPI ISFPersistFolder2_Initialize(
2668 IPersistFolder2 * iface,
2669 LPCITEMIDLIST pidl)
2670{
2671 char sTemp[MAX_PATH];
2672 _ICOM_THIS_From_IPersistFolder2(IGenericSFImpl, iface);
2673
2674 TRACE("(%p)->(%p)\n", This, pidl);
2675
2676 /* free the old stuff */
2677 if(This->absPidl)
2678 {
2679 SHFree(This->absPidl);
2680 This->absPidl = NULL;
2681 }
2682 if(This->sMyPath)
2683 {
2684 SHFree(This->sMyPath);
2685 This->sMyPath = NULL;
2686 }
2687
2688 /* set my pidl */
2689 This->absPidl = ILClone(pidl);
2690
2691 /* set my path */
2692 if (SHGetPathFromIDListA(pidl, sTemp))
2693 {
2694 This->sMyPath = SHAlloc(strlen(sTemp)+1);
2695 strcpy(This->sMyPath, sTemp);
2696 }
2697
2698 TRACE("--(%p)->(%s)\n", This, This->sMyPath);
2699
2700 return S_OK;
2701}
2702
2703/**************************************************************************
2704* IPersistFolder2_fnGetCurFolder
2705*/
2706static HRESULT WINAPI ISFPersistFolder2_fnGetCurFolder(
2707 IPersistFolder2 * iface,
2708 LPITEMIDLIST * pidl)
2709{
2710 _ICOM_THIS_From_IPersistFolder2(IGenericSFImpl, iface);
2711
2712 TRACE("(%p)->(%p)\n",This, pidl);
2713
2714 if (!pidl) return E_POINTER;
2715
2716 *pidl = ILClone(This->absPidl);
2717
2718 return S_OK;
2719}
2720
2721static ICOM_VTABLE(IPersistFolder2) psfvt =
2722{
2723 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
2724 ISFPersistFolder2_QueryInterface,
2725 ISFPersistFolder2_AddRef,
2726 ISFPersistFolder2_Release,
2727 ISFPersistFolder2_GetClassID,
2728 ISFPersistFolder2_Initialize,
2729 ISFPersistFolder2_fnGetCurFolder
2730};
2731
2732/****************************************************************************
2733 * ISFDropTarget implementation
2734 */
2735static BOOL ISFDropTarget_QueryDrop(
2736 IDropTarget *iface,
2737 DWORD dwKeyState,
2738 LPDWORD pdwEffect)
2739{
2740 DWORD dwEffect = *pdwEffect;
2741
2742 _ICOM_THIS_From_IDropTarget(IGenericSFImpl,iface);
2743
2744 *pdwEffect = DROPEFFECT_NONE;
2745
2746 if (This->fAcceptFmt)
2747 { /* Does our interpretation of the keystate ... */
2748 *pdwEffect = KeyStateToDropEffect(dwKeyState);
2749
2750 /* ... matches the desired effect ? */
2751 if (dwEffect & *pdwEffect)
2752 {
2753 return TRUE;
2754 }
2755 }
2756 return FALSE;
2757}
2758
2759static HRESULT WINAPI ISFDropTarget_QueryInterface(
2760 IDropTarget *iface,
2761 REFIID riid,
2762 LPVOID *ppvObj)
2763{
2764 _ICOM_THIS_From_IDropTarget(IGenericSFImpl,iface);
2765
2766 TRACE("(%p)\n", This);
2767
2768 return IUnknown_QueryInterface(This->pUnkOuter, riid, ppvObj);
2769}
2770
2771static ULONG WINAPI ISFDropTarget_AddRef( IDropTarget *iface)
2772{
2773 _ICOM_THIS_From_IDropTarget(IGenericSFImpl,iface);
2774
2775 TRACE("(%p)\n", This);
2776
2777 return IUnknown_AddRef(This->pUnkOuter);
2778}
2779
2780static ULONG WINAPI ISFDropTarget_Release( IDropTarget *iface)
2781{
2782 _ICOM_THIS_From_IDropTarget(IGenericSFImpl,iface);
2783
2784 TRACE("(%p)\n", This);
2785
2786 return IUnknown_Release(This->pUnkOuter);
2787}
2788
2789static HRESULT WINAPI ISFDropTarget_DragEnter(
2790 IDropTarget *iface,
2791 IDataObject *pDataObject,
2792 DWORD dwKeyState,
2793 POINTL pt,
2794 DWORD *pdwEffect)
2795{
2796 FORMATETC fmt;
2797
2798 _ICOM_THIS_From_IDropTarget(IGenericSFImpl,iface);
2799
2800 TRACE("(%p)->(DataObject=%p)\n",This,pDataObject);
2801
2802 InitFormatEtc(fmt, This->cfShellIDList, TYMED_HGLOBAL);
2803
2804 This->fAcceptFmt = (S_OK == IDataObject_QueryGetData(pDataObject, &fmt)) ? TRUE : FALSE;
2805
2806 ISFDropTarget_QueryDrop(iface, dwKeyState, pdwEffect);
2807
2808 return S_OK;
2809}
2810
2811static HRESULT WINAPI ISFDropTarget_DragOver(
2812 IDropTarget *iface,
2813 DWORD dwKeyState,
2814 POINTL pt,
2815 DWORD *pdwEffect)
2816{
2817 _ICOM_THIS_From_IDropTarget(IGenericSFImpl,iface);
2818
2819 TRACE("(%p)\n",This);
2820
2821 if(!pdwEffect) return E_INVALIDARG;
2822
2823 ISFDropTarget_QueryDrop(iface, dwKeyState, pdwEffect);
2824
2825 return S_OK;
2826}
2827
2828static HRESULT WINAPI ISFDropTarget_DragLeave(
2829 IDropTarget *iface)
2830{
2831 _ICOM_THIS_From_IDropTarget(IGenericSFImpl,iface);
2832
2833 TRACE("(%p)\n",This);
2834
2835 This->fAcceptFmt = FALSE;
2836
2837 return S_OK;
2838}
2839
2840static HRESULT WINAPI ISFDropTarget_Drop(
2841 IDropTarget *iface,
2842 IDataObject* pDataObject,
2843 DWORD dwKeyState,
2844 POINTL pt,
2845 DWORD *pdwEffect)
2846{
2847 _ICOM_THIS_From_IDropTarget(IGenericSFImpl,iface);
2848
2849 FIXME("(%p) object dropped\n",This);
2850
2851 return E_NOTIMPL;
2852}
2853
2854static struct ICOM_VTABLE(IDropTarget) dtvt =
2855{
2856 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
2857 ISFDropTarget_QueryInterface,
2858 ISFDropTarget_AddRef,
2859 ISFDropTarget_Release,
2860 ISFDropTarget_DragEnter,
2861 ISFDropTarget_DragOver,
2862 ISFDropTarget_DragLeave,
2863 ISFDropTarget_Drop
2864};
Note: See TracBrowser for help on using the repository browser.