Many bugfixes, new stubs SHGetRealIDL, SHRegQueryValue32W,
[wine] / dlls / shell32 / shlfolder.c
1 /*
2  *      Shell Folder stuff (...and all the OLE-Objects of SHELL32.DLL)
3  *
4  *      Copyright 1997  Marcus Meissner
5  *      Copyright 1998  Juergen Schmied
6  *
7  *  !!! currently work in progress on all classes 980930 !!!
8  *  <contact juergen.schmied@metronet.de>
9  */
10
11 #include <ctype.h>
12 #include <stdlib.h>
13 #include <string.h>
14 #include "ole.h"
15 #include "ole2.h"
16 #include "debug.h"
17 #include "compobj.h"
18 #include "interfaces.h"
19 #include "shlobj.h"
20 #include "shell.h"
21 #include "winerror.h"
22 #include "winnls.h"
23 #include "winproc.h"
24 #include "commctrl.h"
25 #include "pidl.h"
26 #include "shell32_main.h"
27
28 static HRESULT WINAPI IShellFolder_QueryInterface(LPSHELLFOLDER,REFIID,LPVOID*);
29 static ULONG WINAPI IShellFolder_AddRef(LPSHELLFOLDER);
30 static ULONG WINAPI IShellFolder_Release(LPSHELLFOLDER);
31 static HRESULT WINAPI IShellFolder_Initialize(LPSHELLFOLDER,LPCITEMIDLIST);
32 static HRESULT WINAPI IShellFolder_ParseDisplayName(LPSHELLFOLDER,HWND32,LPBC,LPOLESTR32,DWORD*,LPITEMIDLIST*,DWORD*);
33 static HRESULT WINAPI IShellFolder_EnumObjects(LPSHELLFOLDER,HWND32,DWORD,LPENUMIDLIST*);
34 static HRESULT WINAPI IShellFolder_BindToObject(LPSHELLFOLDER,LPCITEMIDLIST,LPBC,REFIID,LPVOID*);
35 static HRESULT WINAPI IShellFolder_BindToStorage(LPSHELLFOLDER,LPCITEMIDLIST,LPBC,REFIID,LPVOID*);
36 static HRESULT WINAPI IShellFolder_CompareIDs(LPSHELLFOLDER,LPARAM,LPCITEMIDLIST,LPCITEMIDLIST);
37 static HRESULT WINAPI IShellFolder_CreateViewObject(LPSHELLFOLDER,HWND32,REFIID,LPVOID*);
38 static HRESULT WINAPI IShellFolder_GetAttributesOf(LPSHELLFOLDER,UINT32,LPCITEMIDLIST*,DWORD*);
39 static HRESULT WINAPI IShellFolder_GetUIObjectOf(LPSHELLFOLDER,HWND32,UINT32,LPCITEMIDLIST*,REFIID,UINT32*,LPVOID*);
40 static HRESULT WINAPI IShellFolder_GetDisplayNameOf(LPSHELLFOLDER,LPCITEMIDLIST,DWORD,LPSTRRET);
41 static HRESULT WINAPI IShellFolder_SetNameOf(LPSHELLFOLDER,HWND32,LPCITEMIDLIST,LPCOLESTR32,DWORD,LPITEMIDLIST*);
42 static BOOL32 WINAPI IShellFolder_GetFolderPath(LPSHELLFOLDER,LPSTR,DWORD);
43
44 /***************************************************************************
45  *  GetNextElement (internal function)
46  *
47  * gets a part of a string till the first backslash
48  *
49  * PARAMETERS
50  *  pszNext [IN] string to get the element from
51  *  pszOut  [IN] pointer to buffer whitch receives string
52  *  dwOut   [IN] length of pszOut
53  *
54  *  RETURNS
55  *    LPSTR pointer to first, not yet parsed char
56  */
57 LPSTR GetNextElement(LPSTR pszNext,LPSTR pszOut,DWORD dwOut)
58 {       LPSTR   pszTail = pszNext;
59         DWORD dwCopy;
60         TRACE(shell,"(%s %p 0x%08lx)\n",debugstr_a(pszNext),pszOut,dwOut);
61
62         if(!pszNext || !*pszNext)
63           return NULL;
64
65         while(*pszTail && (*pszTail != '\\'))
66         { pszTail++;
67         }
68         dwCopy=((LPBYTE)pszTail-(LPBYTE)pszNext)/sizeof(CHAR)+1;
69         lstrcpyn32A(pszOut, pszNext, (dwOut<dwCopy)? dwOut : dwCopy);
70
71         if(*pszTail)
72         {  pszTail++;
73         }
74
75         TRACE(shell,"--(%s %s 0x%08lx)\n",debugstr_a(pszNext),debugstr_a(pszOut),dwOut);
76         return pszTail;
77 }
78
79 /***********************************************************************
80 *   IShellFolder implementation
81 */
82 static struct IShellFolder_VTable sfvt = 
83 { IShellFolder_QueryInterface,
84   IShellFolder_AddRef,
85   IShellFolder_Release,
86   IShellFolder_ParseDisplayName,
87   IShellFolder_EnumObjects,
88   IShellFolder_BindToObject,
89   IShellFolder_BindToStorage,
90   IShellFolder_CompareIDs,
91   IShellFolder_CreateViewObject,
92   IShellFolder_GetAttributesOf,
93   IShellFolder_GetUIObjectOf,
94   IShellFolder_GetDisplayNameOf,
95   IShellFolder_SetNameOf,
96   IShellFolder_GetFolderPath
97 };
98 /**************************************************************************
99 *         IShellFolder_Constructor
100 */
101
102 LPSHELLFOLDER IShellFolder_Constructor(LPSHELLFOLDER pParent,LPITEMIDLIST pidl) 
103 {       LPSHELLFOLDER    sf;
104         DWORD dwSize=0;
105         sf=(LPSHELLFOLDER)HeapAlloc(GetProcessHeap(),0,sizeof(IShellFolder));
106         sf->ref=1;
107         sf->lpvtbl=&sfvt;
108         sf->mlpszFolder=NULL;   /* path of the folder */
109         sf->mpSFParent=pParent; /* parrent shellfolder */
110
111         TRACE(shell,"(%p)->(parent=%p, pidl=%p)\n",sf,pParent, pidl);
112         
113         /* keep a copy of the pidl in the instance*/
114         sf->mpidl = ILClone(pidl);
115         sf->mpidlNSRoot = NULL;
116         
117         if(sf->mpidl)        /* do we have a pidl? */
118         { dwSize = 0;
119           if(sf->mpSFParent->mlpszFolder)               /* get the size of the parents path */
120           { dwSize += strlen(sf->mpSFParent->mlpszFolder) + 1;
121             TRACE(shell,"-- (%p)->(parent's path=%s)\n",sf, debugstr_a(sf->mpSFParent->mlpszFolder));
122           }   
123           dwSize += _ILGetFolderText(sf->mpidl,NULL,0); /* add the size of the foldername*/
124           sf->mlpszFolder = SHAlloc(dwSize);
125           if(sf->mlpszFolder)
126           { *(sf->mlpszFolder)=0x00;
127             if(sf->mpSFParent->mlpszFolder)             /* if the parent has a path, get it*/
128             {  strcpy(sf->mlpszFolder, sf->mpSFParent->mlpszFolder);
129                PathAddBackslash (sf->mlpszFolder);
130             }
131             _ILGetFolderText(sf->mpidl, sf->mlpszFolder+strlen(sf->mlpszFolder), dwSize-strlen(sf->mlpszFolder));
132             TRACE(shell,"-- (%p)->(my path=%s)\n",sf, debugstr_a(sf->mlpszFolder));
133           }
134         }
135         return sf;
136 }
137 /**************************************************************************
138 *  IShellFolder::QueryInterface
139 * PARAMETERS
140 *  REFIID riid,        //[in ] Requested InterfaceID
141 *  LPVOID* ppvObject)  //[out] Interface* to hold the result
142 */
143 static HRESULT WINAPI IShellFolder_QueryInterface(
144   LPSHELLFOLDER this, REFIID riid, LPVOID *ppvObj)
145 {  char xriid[50];
146    WINE_StringFromCLSID((LPCLSID)riid,xriid);
147    TRACE(shell,"(%p)->(\n\tIID:\t%s,%p)\n",this,xriid,ppvObj);
148
149   *ppvObj = NULL;
150
151   if(IsEqualIID(riid, &IID_IUnknown))          /*IUnknown*/
152   { *ppvObj = this; 
153   }
154   else if(IsEqualIID(riid, &IID_IShellFolder))  /*IShellFolder*/
155   {    *ppvObj = (IShellFolder*)this;
156   }   
157
158   if(*ppvObj)
159   { (*(LPSHELLFOLDER*)ppvObj)->lpvtbl->fnAddRef(this);          
160     TRACE(shell,"-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
161                 return S_OK;
162   }
163         TRACE(shell,"-- Interface: E_NOINTERFACE\n");
164         return E_NOINTERFACE;
165 }   
166
167 /**************************************************************************
168 *  IShellFolder::AddRef
169 */
170
171 static ULONG WINAPI IShellFolder_AddRef(LPSHELLFOLDER this)
172 {       TRACE(shell,"(%p)->(count=%lu)\n",this,(this->ref)+1);
173         return ++(this->ref);
174 }
175
176 /**************************************************************************
177  *  IShellFolder_Release
178  */
179 static ULONG WINAPI IShellFolder_Release(LPSHELLFOLDER this) 
180 {       TRACE(shell,"(%p)->(count=%lu)\n",this,this->ref);
181         if (!--(this->ref)) 
182         { TRACE(shell,"-- destroying IShellFolder(%p)\n",this);
183
184           if (pdesktopfolder==this)
185           { pdesktopfolder=NULL;
186             TRACE(shell,"-- destroyed IShellFolder(%p) was Desktopfolder\n",this);
187           }
188           if(this->mpidlNSRoot)
189           { SHFree(this->mpidlNSRoot);
190           }
191           if(this->mpidl)
192           { SHFree(this->mpidl);
193           }
194           if(this->mlpszFolder)
195           { SHFree(this->mlpszFolder);
196           }
197
198           HeapFree(GetProcessHeap(),0,this);
199
200           return 0;
201         }
202         return this->ref;
203 }
204 /**************************************************************************
205 *               IShellFolder_ParseDisplayName
206 * PARAMETERS
207 *  HWND          hwndOwner,      //[in ] Parent window for any message's
208 *  LPBC          pbc,            //[in ] reserved
209 *  LPOLESTR      lpszDisplayName,//[in ] "Unicode" displayname.
210 *  ULONG*        pchEaten,       //[out] (unicode) characters processed
211 *  LPITEMIDLIST* ppidl,          //[out] complex pidl to item
212 *  ULONG*        pdwAttributes   //[out] items attributes
213 *
214 * FIXME: 
215 *    pdwAttributes: not used
216 */
217 static HRESULT WINAPI IShellFolder_ParseDisplayName(
218         LPSHELLFOLDER this,
219         HWND32 hwndOwner,
220         LPBC pbcReserved,
221     LPOLESTR32 lpszDisplayName,
222     DWORD *pchEaten,
223     LPITEMIDLIST *ppidl,
224         DWORD *pdwAttributes)
225 {       HRESULT        hr=E_OUTOFMEMORY;
226   LPITEMIDLIST   pidlFull=NULL, pidlTemp = NULL, pidlOld = NULL;
227   LPSTR          pszNext=NULL;
228   CHAR           szElement[MAX_PATH];
229   BOOL32         bType;
230
231   DWORD          dwChars=lstrlen32W(lpszDisplayName) + 1;
232   LPSTR          pszTemp=(LPSTR)HeapAlloc(GetProcessHeap(),0,dwChars * sizeof(CHAR));
233        
234   TRACE(shell,"(%p)->(HWND=0x%08x,%p,%p=%s,%p,pidl=%p,%p)\n",
235         this,hwndOwner,pbcReserved,lpszDisplayName,debugstr_w(lpszDisplayName),pchEaten,ppidl,pdwAttributes);
236
237         if(pszTemp)
238         { hr = E_FAIL;
239           WideCharToLocal32(pszTemp, lpszDisplayName, dwChars);
240           if(*pszTemp)
241           { if (strcmp(pszTemp,"Desktop")==0)
242             { pidlFull = (LPITEMIDLIST)HeapAlloc(GetProcessHeap(),0,2);
243               pidlFull->mkid.cb = 0;
244             }
245             else if (strcmp(pszTemp,"My Computer")==0)
246             { pidlFull = _ILCreateMyComputer();
247             }
248             else
249             { pidlFull = _ILCreateMyComputer();
250
251               /* check if the lpszDisplayName is Folder or File*/
252               bType = ! (GetFileAttributes32A(pszNext) & FILE_ATTRIBUTE_DIRECTORY);
253               pszNext = GetNextElement(pszTemp, szElement, MAX_PATH);
254   
255               pidlTemp = _ILCreateDrive(szElement);                     
256               pidlOld = pidlFull;
257               pidlFull = ILCombine(pidlFull,pidlTemp);
258               SHFree(pidlOld);
259   
260               if(pidlFull)
261               { while((pszNext=GetNextElement(pszNext, szElement, MAX_PATH)))
262                 { if(!*pszNext && bType)
263                   { pidlTemp = _ILCreateValue(szElement);
264                   }
265                   else                          
266                   { pidlTemp = _ILCreateFolder(szElement);
267                   }
268                   pidlOld = pidlFull;
269                   pidlFull = ILCombine(pidlFull,pidlTemp);
270                   SHFree(pidlOld);
271                 }
272                 hr = S_OK;
273               }
274             }
275           }
276         }
277         HeapFree(GetProcessHeap(),0,pszTemp);
278         *ppidl = pidlFull;
279         return hr;
280 }
281
282 /**************************************************************************
283 *               IShellFolder_EnumObjects
284 * PARAMETERS
285 *  HWND          hwndOwner,    //[in ] Parent Window
286 *  DWORD         grfFlags,     //[in ] SHCONTF enumeration mask
287 *  LPENUMIDLIST* ppenumIDList  //[out] IEnumIDList interface
288 */
289 static HRESULT WINAPI IShellFolder_EnumObjects(
290         LPSHELLFOLDER this,
291         HWND32 hwndOwner,
292         DWORD dwFlags,
293         LPENUMIDLIST* ppEnumIDList)
294 {       TRACE(shell,"(%p)->(HWND=0x%08x flags=0x%08lx pplist=%p)\n",this,hwndOwner,dwFlags,ppEnumIDList);
295
296         *ppEnumIDList = NULL;
297         *ppEnumIDList = IEnumIDList_Constructor (this->mlpszFolder, dwFlags);
298         TRACE(shell,"-- (%p)->(new ID List: %p)\n",this,*ppEnumIDList);
299         if(!*ppEnumIDList)
300         { return E_OUTOFMEMORY;
301         }
302         return S_OK;            
303 }
304 /**************************************************************************
305  *  IShellFolder_Initialize()
306  *  IPersistFolder Method
307  */
308 static HRESULT WINAPI IShellFolder_Initialize(
309         LPSHELLFOLDER this,
310         LPCITEMIDLIST pidl)
311 { TRACE(shell,"(%p)->(pidl=%p)\n",this,pidl);
312   if(this->mpidlNSRoot)
313   { SHFree(this->mpidlNSRoot);
314     this->mpidlNSRoot = NULL;
315   }
316   this->mpidlNSRoot=ILClone(pidl);
317   return S_OK;
318 }
319
320 /**************************************************************************
321 *               IShellFolder_BindToObject
322 * PARAMETERS
323 *  LPCITEMIDLIST pidl,       //[in ] complex pidl to open
324 *  LPBC          pbc,        //[in ] reserved
325 *  REFIID        riid,       //[in ] Initial Interface
326 *  LPVOID*       ppvObject   //[out] Interface*
327 */
328 static HRESULT WINAPI IShellFolder_BindToObject(
329         LPSHELLFOLDER this,
330         LPCITEMIDLIST pidl,
331         LPBC pbcReserved,
332         REFIID riid,
333         LPVOID * ppvOut)
334 {       char            xriid[50];
335   HRESULT       hr;
336         LPSHELLFOLDER pShellFolder;
337         
338         WINE_StringFromCLSID(riid,xriid);
339
340         TRACE(shell,"(%p)->(pidl=%p,%p,\n\tIID:%s,%p)\n",this,pidl,pbcReserved,xriid,ppvOut);
341
342   *ppvOut = NULL;
343   pShellFolder = IShellFolder_Constructor(this, pidl);
344   if(!pShellFolder)
345     return E_OUTOFMEMORY;
346   /*  pShellFolder->lpvtbl->fnInitialize(pShellFolder, this->mpidlNSRoot);*/
347   IShellFolder_Initialize(pShellFolder, this->mpidlNSRoot);
348   hr = pShellFolder->lpvtbl->fnQueryInterface(pShellFolder, riid, ppvOut);
349   pShellFolder->lpvtbl->fnRelease(pShellFolder);
350         TRACE(shell,"-- (%p)->(interface=%p)\n",this, ppvOut);
351   return hr;
352 }
353
354 /**************************************************************************
355 *  IShellFolder_BindToStorage
356 * PARAMETERS
357 *  LPCITEMIDLIST pidl,       //[in ] complex pidl to store
358 *  LPBC          pbc,        //[in ] reserved
359 *  REFIID        riid,       //[in ] Initial storage interface 
360 *  LPVOID*       ppvObject   //[out] Interface* returned
361 */
362 static HRESULT WINAPI IShellFolder_BindToStorage(
363         LPSHELLFOLDER this,
364     LPCITEMIDLIST pidl, /*simple/complex pidl*/
365     LPBC pbcReserved, 
366     REFIID riid, 
367     LPVOID *ppvOut)
368 {       char xriid[50];
369         WINE_StringFromCLSID(riid,xriid);
370
371         FIXME(shell,"(%p)->(pidl=%p,%p,\n\tIID:%s,%p) stub\n",this,pidl,pbcReserved,xriid,ppvOut);
372
373   *ppvOut = NULL;
374   return E_NOTIMPL;
375 }
376
377 /**************************************************************************
378 *  IShellFolder_CompareIDs
379 *
380 * PARMETERS
381 *  LPARAM        lParam, //[in ] Column?
382 *  LPCITEMIDLIST pidl1,  //[in ] simple pidl
383 *  LPCITEMIDLIST pidl2)  //[in ] simple pidl
384 *
385 * NOTES
386 *   Special case - If one of the items is a Path and the other is a File,
387 *   always make the Path come before the File.
388 *
389 * FIXME
390 *  we have to handle simple pidl's only (?)
391 */
392 static HRESULT WINAPI  IShellFolder_CompareIDs(LPSHELLFOLDER this,
393                  LPARAM lParam, LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2) 
394 { CHAR szString1[MAX_PATH] = "";
395   CHAR szString2[MAX_PATH] = "";
396   int   nReturn;
397   LPCITEMIDLIST  pidlTemp1 = pidl1, pidlTemp2 = pidl2;
398
399   TRACE(shell,"(%p)->(0x%08lx,pidl1=%p,pidl2=%p)\n",this,lParam,pidl1,pidl2);
400   pdump (pidl1);
401   pdump (pidl2);
402
403   if (!pidl1 && !pidl2)
404     return 0;
405   if (!pidl1)   /* Desktop < anything */
406     return -1;
407   if (!pidl2)
408     return 1;
409   
410   /* get the last item in each list */
411   while((ILGetNext(pidlTemp1))->mkid.cb)
412     pidlTemp1 = ILGetNext(pidlTemp1);
413   while((ILGetNext(pidlTemp2))->mkid.cb)
414     pidlTemp2 = ILGetNext(pidlTemp2);
415
416   /* at this point, both pidlTemp1 and pidlTemp2 point to the last item in the list */
417   if(_ILIsValue(pidlTemp1) != _ILIsValue(pidlTemp2))
418   { if(_ILIsValue(pidlTemp1))
419       return 1;
420    return -1;
421   }
422
423   _ILGetDrive( pidl1,szString1,sizeof(szString1));
424   _ILGetDrive( pidl2,szString1,sizeof(szString2));
425   nReturn = strcasecmp(szString1, szString2);
426
427   if(nReturn)
428     return nReturn;
429
430   _ILGetFolderText( pidl1,szString1,sizeof(szString1));
431   _ILGetFolderText( pidl2,szString2,sizeof(szString2));
432   nReturn = strcasecmp(szString1, szString2);
433
434   if(nReturn)
435     return nReturn;
436
437   _ILGetValueText(pidl1,szString1,sizeof(szString1));
438   _ILGetValueText(pidl2,szString2,sizeof(szString2));
439   return strcasecmp(szString1, szString2);
440 }
441
442 /**************************************************************************
443 *         IShellFolder_CreateViewObject
444 * Creates an View Object representing the ShellFolder
445 *  IShellView / IShellBrowser / IContextMenu
446 *
447 * PARAMETERS
448 *  HWND    hwndOwner,  // Handle of owner window
449 *  REFIID  riid,       // Requested initial interface
450 *  LPVOID* ppvObject)  // Resultant interface*
451 *
452 * NOTES
453 *  the same as SHCreateShellFolderViewEx ???
454 */
455 static HRESULT WINAPI IShellFolder_CreateViewObject( LPSHELLFOLDER this,
456                  HWND32 hwndOwner, REFIID riid, LPVOID *ppvOut)
457 {       LPSHELLVIEW pShellView;
458         char    xriid[50];
459         HRESULT       hr;
460
461         WINE_StringFromCLSID(riid,xriid);
462         TRACE(shell,"(%p)->(hwnd=0x%x,\n\tIID:\t%s,%p)\n",this,hwndOwner,xriid,ppvOut);
463         
464         *ppvOut = NULL;
465
466         pShellView = IShellView_Constructor(this, this->mpidl);
467         if(!pShellView)
468           return E_OUTOFMEMORY;
469         hr = pShellView->lpvtbl->fnQueryInterface(pShellView, riid, ppvOut);
470         pShellView->lpvtbl->fnRelease(pShellView);
471         TRACE(shell,"-- (%p)->(interface=%p)\n",this, ppvOut);
472         return hr; 
473 }
474
475 /**************************************************************************
476 *  IShellFolder_GetAttributesOf
477 *
478 * PARAMETERS
479 *  UINT            cidl,     //[in ] num elements in pidl array
480 +  LPCITEMIDLIST*  apidl,    //[in ] simple pidl array 
481 *  ULONG*          rgfInOut) //[out] result array  
482 *
483 * FIXME: quick hack
484 *  Note: rgfInOut is documented as being an array of ULONGS.
485 *  This does not seem to be the case. Testing this function using the shell to 
486 *  call it with cidl > 1 (by deleting multiple items) reveals that the shell
487 *  passes ONE element in the array and writing to further elements will
488 *  cause the shell to fail later.
489 */
490 static HRESULT WINAPI IShellFolder_GetAttributesOf(LPSHELLFOLDER this,UINT32 cidl,LPCITEMIDLIST *apidl,DWORD *rgfInOut)
491 { LPCITEMIDLIST * pidltemp;
492   DWORD i;
493
494   TRACE(shell,"(%p)->(%d,%p,%p)\n",this,cidl,apidl,rgfInOut);
495
496   if ((! cidl )| (!apidl) | (!rgfInOut))
497     return E_INVALIDARG;
498
499   pidltemp=apidl;
500   *rgfInOut = 0x00;
501   i=cidl;
502
503   TRACE(shell,"-- mask=0x%08lx\n",*rgfInOut);
504   
505   do
506   { if (*pidltemp)
507     { pdump (*pidltemp);
508       if (_ILIsDesktop( *pidltemp))
509       { *rgfInOut |= ( SFGAO_HASSUBFOLDER | SFGAO_FOLDER | SFGAO_DROPTARGET | SFGAO_HASPROPSHEET | SFGAO_CANLINK );
510       }
511       else if (_ILIsMyComputer( *pidltemp))
512       { *rgfInOut |= ( SFGAO_HASSUBFOLDER | SFGAO_FOLDER | SFGAO_FILESYSANCESTOR
513                         | SFGAO_DROPTARGET | SFGAO_HASPROPSHEET | SFGAO_CANRENAME | SFGAO_CANLINK );
514       }
515       else if (_ILIsDrive( *pidltemp))
516       { *rgfInOut |= ( SFGAO_HASSUBFOLDER | SFGAO_FILESYSTEM  | SFGAO_FOLDER | SFGAO_FILESYSANCESTOR  | 
517                         SFGAO_DROPTARGET | SFGAO_HASPROPSHEET | SFGAO_CANLINK );
518       }
519       else if (_ILIsFolder( *pidltemp))
520       { *rgfInOut |= ( SFGAO_HASSUBFOLDER | SFGAO_FILESYSTEM | SFGAO_FOLDER | SFGAO_CAPABILITYMASK );
521       }
522       else if (_ILIsValue( *pidltemp))
523       { *rgfInOut |= (SFGAO_FILESYSTEM | SFGAO_CAPABILITYMASK );
524       }
525     }
526     pidltemp++;
527     cidl--;
528   } while (cidl > 0 && *pidltemp);
529
530   return S_OK;
531 }
532 /**************************************************************************
533 *  IShellFolder_GetUIObjectOf
534 *
535 * PARAMETERS
536 *  HWND           hwndOwner, //[in ] Parent window for any output
537 *  UINT           cidl,      //[in ] array size
538 *  LPCITEMIDLIST* apidl,     //[in ] simple pidl array
539 *  REFIID         riid,      //[in ] Requested Interface
540 *  UINT*          prgfInOut, //[   ] reserved 
541 *  LPVOID*        ppvObject) //[out] Resulting Interface
542 *
543 * NOTES
544 *  This function gets asked to return "view objects" for one or more (multiple select)
545 *  items:
546 *  The viewobject typically is an COM object with one of the following interfaces:
547 *  IExtractIcon,IDataObject,IContextMenu
548 *  In order to support icon positions in the default Listview your DataObject
549 *  must implement the SetData method (in addition to GetData :) - the shell passes
550 *  a barely documented "Icon positions" structure to SetData when the drag starts,
551 *  and GetData's it if the drop is in another explorer window that needs the positions.
552 */
553 static HRESULT WINAPI IShellFolder_GetUIObjectOf( LPSHELLFOLDER this,HWND32 hwndOwner,UINT32 cidl,
554  LPCITEMIDLIST * apidl, REFIID riid, UINT32 * prgfInOut,LPVOID * ppvOut)
555 {       char            xclsid[50];
556         LPITEMIDLIST    pidl;
557         LPUNKNOWN       pObj = NULL; 
558    
559         WINE_StringFromCLSID(riid,xclsid);
560
561         TRACE(shell,"(%p)->(%u,%u,pidl=%p,\n\tIID:%s,%p,%p)\n",
562           this,hwndOwner,cidl,apidl,xclsid,prgfInOut,ppvOut);
563
564         *ppvOut = NULL;
565
566         if(IsEqualIID(riid, &IID_IContextMenu))
567         { if(cidl < 1)
568             return E_INVALIDARG;
569           pObj  = (LPUNKNOWN)IContextMenu_Constructor(this, apidl, cidl);
570         }
571         else if (IsEqualIID(riid, &IID_IDataObject))
572         { if (cidl < 1)
573             return(E_INVALIDARG);
574           pObj = (LPUNKNOWN)IDataObject_Constructor (hwndOwner, this, apidl, cidl);
575         }
576         else if(IsEqualIID(riid, &IID_IExtractIcon))
577         { if (cidl != 1)
578             return(E_INVALIDARG);
579           pidl = ILCombine(this->mpidl, apidl[0]);
580           pObj = (LPUNKNOWN)IExtractIcon_Constructor(pidl);
581           SHFree(pidl);
582         } 
583         else
584         { ERR(shell,"(%p)->E_NOINTERFACE\n",this);
585           return E_NOINTERFACE;
586         }
587         if(!pObj)
588           return E_OUTOFMEMORY;
589
590         *ppvOut = pObj;
591         return S_OK;
592 }
593 /**************************************************************************
594 *  IShellFolder_GetDisplayNameOf
595 *  Retrieves the display name for the specified file object or subfolder
596 *
597 * PARAMETERS
598 *  LPCITEMIDLIST pidl,    //[in ] complex pidl to item
599 *  DWORD         dwFlags, //[in ] SHGNO formatting flags
600 *  LPSTRRET      lpName)  //[out] Returned display name
601 *
602 * FIXME
603 *  if the name is in the pidl the ret value should be a STRRET_OFFSET
604 */
605 #define GET_SHGDN_FOR(dwFlags)         ((DWORD)dwFlags & (DWORD)0x0000FF00)
606 #define GET_SHGDN_RELATION(dwFlags)    ((DWORD)dwFlags & (DWORD)0x000000FF)
607
608 static HRESULT WINAPI IShellFolder_GetDisplayNameOf( LPSHELLFOLDER this, LPCITEMIDLIST pidl, DWORD dwFlags, LPSTRRET lpName)
609 {       CHAR    szText[MAX_PATH];
610         CHAR    szTemp[MAX_PATH];
611         CHAR    szSpecial[MAX_PATH];
612         CHAR    szDrive[MAX_PATH];
613         DWORD   dwVolumeSerialNumber,dwMaximumComponetLength,dwFileSystemFlags;
614         LPITEMIDLIST    pidlTemp=NULL;
615         BOOL32  bSimplePidl=FALSE;
616                 
617         TRACE(shell,"(%p)->(pidl=%p,0x%08lx,%p)\n",this,pidl,dwFlags,lpName);
618
619         szSpecial[0]=0x00; 
620         szDrive[0]=0x00;
621
622         /* test if simple(relative) or complex(absolute) pidl */
623         pidlTemp = ILGetNext(pidl);
624         if (pidlTemp && pidlTemp->mkid.cb==0x00)
625         { bSimplePidl = TRUE;
626           TRACE(shell,"-- simple pidl\n");
627         }
628         if (_ILIsDesktop( pidl))
629         { strcpy (szText,"Desktop");
630         }
631         else
632         { if (_ILIsMyComputer( pidl))
633           { _ILGetItemText( pidl, szSpecial, MAX_PATH);
634           }
635           if (_ILIsDrive( pidl))
636           { pidlTemp = ILFindLastID(pidl);
637             if (pidlTemp)
638             { _ILGetItemText( pidlTemp, szTemp, MAX_PATH);
639             }
640             if ( dwFlags==SHGDN_NORMAL || dwFlags==SHGDN_INFOLDER)
641             { GetVolumeInformation32A(szTemp,szDrive,MAX_PATH,&dwVolumeSerialNumber,&dwMaximumComponetLength,&dwFileSystemFlags,NULL,0);
642               if (szTemp[2]=='\\')
643               { szTemp[2]=0x00;
644               }
645               strcat (szDrive," (");
646               strcat (szDrive,szTemp);
647               strcat (szDrive,")"); 
648             }
649             else
650             {  PathAddBackslash (szTemp);
651                strcpy(szDrive,szTemp);
652             }
653           }
654                 
655           switch(dwFlags)
656           { case SHGDN_NORMAL:
657               _ILGetPidlPath( pidl, szText, MAX_PATH);
658               break;
659
660             case SHGDN_INFOLDER | SHGDN_FORPARSING: /*fall thru*/
661             case SHGDN_INFOLDER:
662               pidlTemp = ILFindLastID(pidl);
663               if (pidlTemp)
664               { _ILGetItemText( pidlTemp, szText, MAX_PATH);
665               }
666               break;                            
667
668             case SHGDN_FORPARSING:
669               if (bSimplePidl)
670               { /* if the IShellFolder has parents, get the path from the
671                 parent and add the ItemName*/
672                 szText[0]=0x00;
673                 if (this->mlpszFolder && strlen (this->mlpszFolder))
674                 { if (strcmp(this->mlpszFolder,"My Computer"))
675                   { strcpy (szText,this->mlpszFolder);
676                     PathAddBackslash (szText);
677                   }
678                 }
679                 pidlTemp = ILFindLastID(pidl);
680                 if (pidlTemp)
681                 { _ILGetItemText( pidlTemp, szTemp, MAX_PATH );
682                 } 
683                 strcat(szText,szTemp);
684               }
685               else                                      
686               { /* if the pidl is absolute, get everything from the pidl*/
687                 _ILGetPidlPath( pidl, szText, MAX_PATH);
688               }
689               break;
690             default:
691               TRACE(shell,"--- wrong flags=%lx\n", dwFlags);
692               return E_INVALIDARG;
693           }
694           if ((szText[0]==0x00 && szDrive[0]!=0x00)|| (bSimplePidl && szDrive[0]!=0x00))
695           { strcpy(szText,szDrive);
696           }
697           if (szText[0]==0x00 && szSpecial[0]!=0x00)
698           { strcpy(szText,szSpecial);
699           }
700         }
701   
702         TRACE(shell,"-- (%p)->(%s)\n",this,szText);
703
704         if(!(lpName))
705         {  return E_OUTOFMEMORY;
706         }
707         lpName->uType = STRRET_CSTR;    
708         strcpy(lpName->u.cStr,szText);
709         return S_OK;
710 }
711
712 /**************************************************************************
713 *  IShellFolder_SetNameOf
714 *  Changes the name of a file object or subfolder, possibly changing its item
715 *  identifier in the process.
716 *
717 * PARAMETERS
718 *  HWND          hwndOwner,  //[in ] Owner window for output
719 *  LPCITEMIDLIST pidl,       //[in ] simple pidl of item to change
720 *  LPCOLESTR     lpszName,   //[in ] the items new display name
721 *  DWORD         dwFlags,    //[in ] SHGNO formatting flags
722 *  LPITEMIDLIST* ppidlOut)   //[out] simple pidl returned
723 */
724 static HRESULT WINAPI IShellFolder_SetNameOf(
725         LPSHELLFOLDER this,
726                 HWND32 hwndOwner, 
727     LPCITEMIDLIST pidl, /*simple pidl*/
728     LPCOLESTR32 lpName, 
729     DWORD dw, 
730     LPITEMIDLIST *pPidlOut)
731 {  FIXME(shell,"(%p)->(%u,pidl=%p,%s,%lu,%p),stub!\n",
732           this,hwndOwner,pidl,debugstr_w(lpName),dw,pPidlOut);
733          return E_NOTIMPL;
734 }
735 /**************************************************************************
736 *  IShellFolder_GetFolderPath
737 *  FIXME: drive not included
738 */
739 static BOOL32 WINAPI IShellFolder_GetFolderPath(LPSHELLFOLDER this, LPSTR lpszOut, DWORD dwOutSize)
740 {       DWORD   dwSize;
741
742         TRACE(shell,"(%p)->(%p %lu)\n",this, lpszOut, dwOutSize);
743         if (!lpszOut)
744         { return FALSE;
745         }
746     
747         *lpszOut=0;
748
749         if (! this->mlpszFolder)
750           return FALSE;
751           
752         dwSize = strlen (this->mlpszFolder) +1;
753         if ( dwSize > dwOutSize)
754           return FALSE;
755         strcpy(lpszOut, this->mlpszFolder);
756
757         TRACE(shell,"-- (%p)->(return=%s)\n",this, lpszOut);
758         return TRUE;
759 }