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