Release 980913
[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 980818 !!!
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;
109         sf->mpSFParent=pParent;
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)
120           { dwSize += strlen(sf->mpSFParent->mlpszFolder) + 1;
121           }   
122           dwSize += _ILGetFolderText(sf->mpidl,NULL,0);
123           sf->mlpszFolder = SHAlloc(dwSize);
124           if(sf->mlpszFolder)
125           { *(sf->mlpszFolder)=0x00;
126             if(sf->mpSFParent->mlpszFolder)
127             {  strcpy(sf->mlpszFolder, sf->mpSFParent->mlpszFolder);
128                PathAddBackslash (sf->mlpszFolder);
129             }
130             _ILGetFolderText(sf->mpidl, sf->mlpszFolder+strlen(sf->mlpszFolder), dwSize-strlen(sf->mlpszFolder));
131           }
132         }
133         
134         TRACE(shell,"-- (%p)->(%p,%p,parent=%s)\n",sf,pParent, pidl, debugstr_a(sf->mlpszFolder));
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
246             { pidlFull = _ILCreateMyComputer();
247
248               /* check if the lpszDisplayName is Folder or File*/
249               bType = ! (GetFileAttributes32A(pszNext) & FILE_ATTRIBUTE_DIRECTORY);
250               pszNext = GetNextElement(pszTemp, szElement, MAX_PATH);
251   
252               pidlTemp = _ILCreateDrive(szElement);                     
253               pidlOld = pidlFull;
254               pidlFull = ILCombine(pidlFull,pidlTemp);
255               SHFree(pidlOld);
256   
257               if(pidlFull)
258               { while((pszNext=GetNextElement(pszNext, szElement, MAX_PATH)))
259                 { if(!*pszNext && bType)
260                   { pidlTemp = _ILCreateValue(szElement);
261                   }
262                   else                          
263                   { pidlTemp = _ILCreateFolder(szElement);
264                   }
265                   pidlOld = pidlFull;
266                   pidlFull = ILCombine(pidlFull,pidlTemp);
267                   SHFree(pidlOld);
268                 }
269                 hr = S_OK;
270               }
271             }
272           }
273         }
274         HeapFree(GetProcessHeap(),0,pszTemp);
275         *ppidl = pidlFull;
276         return hr;
277 }
278
279 /**************************************************************************
280 *               IShellFolder_EnumObjects
281 * PARAMETERS
282 *  HWND          hwndOwner,    //[in ] Parent Window
283 *  DWORD         grfFlags,     //[in ] SHCONTF enumeration mask
284 *  LPENUMIDLIST* ppenumIDList  //[out] IEnumIDList interface
285 */
286 static HRESULT WINAPI IShellFolder_EnumObjects(
287         LPSHELLFOLDER this,
288         HWND32 hwndOwner,
289         DWORD dwFlags,
290         LPENUMIDLIST* ppEnumIDList)
291 { HRESULT  hr;
292         TRACE(shell,"(%p)->(HWND=0x%08x,0x%08lx,%p)\n",this,hwndOwner,dwFlags,ppEnumIDList);
293
294   *ppEnumIDList = NULL;
295         *ppEnumIDList = IEnumIDList_Constructor (this->mlpszFolder, dwFlags, &hr);
296   TRACE(shell,"-- (%p)->(new ID List: %p)\n",this,*ppEnumIDList);
297   if(!*ppEnumIDList)
298   { return hr;
299   }
300   return S_OK;          
301 }
302 /**************************************************************************
303  *  IShellFolder_Initialize()
304  *  IPersistFolder Method
305  */
306 static HRESULT WINAPI IShellFolder_Initialize(
307         LPSHELLFOLDER this,
308         LPCITEMIDLIST pidl)
309 { TRACE(shell,"(%p)->(pidl=%p)\n",this,pidl);
310   if(this->mpidlNSRoot)
311   { SHFree(this->mpidlNSRoot);
312     this->mpidlNSRoot = NULL;
313   }
314   this->mpidlNSRoot=ILClone(pidl);
315   return S_OK;
316 }
317
318 /**************************************************************************
319 *               IShellFolder_BindToObject
320 * PARAMETERS
321 *  LPCITEMIDLIST pidl,       //[in ] complex pidl to open
322 *  LPBC          pbc,        //[in ] reserved
323 *  REFIID        riid,       //[in ] Initial Interface
324 *  LPVOID*       ppvObject   //[out] Interface*
325 */
326 static HRESULT WINAPI IShellFolder_BindToObject(
327         LPSHELLFOLDER this,
328         LPCITEMIDLIST pidl,
329         LPBC pbcReserved,
330         REFIID riid,
331         LPVOID * ppvOut)
332 {       char            xriid[50];
333   HRESULT       hr;
334         LPSHELLFOLDER pShellFolder;
335         
336         WINE_StringFromCLSID(riid,xriid);
337
338         TRACE(shell,"(%p)->(pidl=%p,%p,\n\tIID:%s,%p)\n",this,pidl,pbcReserved,xriid,ppvOut);
339
340   *ppvOut = NULL;
341   pShellFolder = IShellFolder_Constructor(this, pidl);
342   if(!pShellFolder)
343     return E_OUTOFMEMORY;
344   /*  pShellFolder->lpvtbl->fnInitialize(pShellFolder, this->mpidlNSRoot);*/
345   IShellFolder_Initialize(pShellFolder, this->mpidlNSRoot);
346   hr = pShellFolder->lpvtbl->fnQueryInterface(pShellFolder, riid, ppvOut);
347   pShellFolder->lpvtbl->fnRelease(pShellFolder);
348         TRACE(shell,"-- (%p)->(interface=%p)\n",this, ppvOut);
349   return hr;
350 }
351
352 /**************************************************************************
353 *  IShellFolder_BindToStorage
354 * PARAMETERS
355 *  LPCITEMIDLIST pidl,       //[in ] complex pidl to store
356 *  LPBC          pbc,        //[in ] reserved
357 *  REFIID        riid,       //[in ] Initial storage interface 
358 *  LPVOID*       ppvObject   //[out] Interface* returned
359 */
360 static HRESULT WINAPI IShellFolder_BindToStorage(
361         LPSHELLFOLDER this,
362     LPCITEMIDLIST pidl, /*simple/complex pidl*/
363     LPBC pbcReserved, 
364     REFIID riid, 
365     LPVOID *ppvOut)
366 {       char xriid[50];
367         WINE_StringFromCLSID(riid,xriid);
368
369         FIXME(shell,"(%p)->(pidl=%p,%p,\n\tIID:%s,%p) stub\n",this,pidl,pbcReserved,xriid,ppvOut);
370
371   *ppvOut = NULL;
372   return E_NOTIMPL;
373 }
374
375 /**************************************************************************
376 *  IShellFolder_CompareIDs
377 *
378 * PARMETERS
379 *  LPARAM        lParam, //[in ] Column?
380 *  LPCITEMIDLIST pidl1,  //[in ] simple pidl
381 *  LPCITEMIDLIST pidl2)  //[in ] simple pidl
382 * FIXME
383 *  we have to handle simple pidl's only
384 */
385 static HRESULT WINAPI  IShellFolder_CompareIDs(
386         LPSHELLFOLDER this,
387                 LPARAM lParam, 
388     LPCITEMIDLIST pidl1, /*simple pidl*/
389     LPCITEMIDLIST pidl2) /*simple pidl*/
390 { CHAR szString1[MAX_PATH] = "";
391   CHAR szString2[MAX_PATH] = "";
392   int   nReturn;
393   LPCITEMIDLIST  pidlTemp1 = pidl1, pidlTemp2 = pidl2;
394
395   TRACE(shell,"(%p)->(0x%08lx,pidl1=%p,pidl2=%p)\n",this,lParam,pidl1,pidl2);
396
397   /*Special case - If one of the items is a Path and the other is a File, always 
398   make the Path come before the File.*/
399
400   /* get the last item in each list */
401   while((ILGetNext(pidlTemp1))->mkid.cb)
402     pidlTemp1 = ILGetNext(pidlTemp1);
403   while((ILGetNext(pidlTemp2))->mkid.cb)
404     pidlTemp2 = ILGetNext(pidlTemp2);
405
406   /* at this point, both pidlTemp1 and pidlTemp2 point to the last item in the list */
407   if(_ILIsValue(pidlTemp1) != _ILIsValue(pidlTemp2))
408   { if(_ILIsValue(pidlTemp1))
409       return 1;
410    return -1;
411   }
412
413   _ILGetDrive( pidl1,szString1,sizeof(szString1));
414   _ILGetDrive( pidl2,szString1,sizeof(szString2));
415   nReturn = strcasecmp(szString1, szString2);
416   if(nReturn)
417     return nReturn;
418
419   _ILGetFolderText( pidl1,szString1,sizeof(szString1));
420   _ILGetFolderText( pidl2,szString2,sizeof(szString2));
421   nReturn = strcasecmp(szString1, szString2);
422   if(nReturn)
423     return nReturn;
424
425   _ILGetValueText(pidl1,szString1,sizeof(szString1));
426   _ILGetValueText(pidl2,szString2,sizeof(szString2));
427   return strcasecmp(szString1, szString2);
428 }
429
430 /**************************************************************************
431 *         IShellFolder_CreateViewObject
432 * Creates an View Object representing the ShellFolder
433 *  IShellView / IShellBrowser / IContextMenu
434 *
435 * PARAMETERS
436 *  HWND    hwndOwner,  // Handle of owner window
437 *  REFIID  riid,       // Requested initial interface
438 *  LPVOID* ppvObject)  // Resultant interface*
439 *
440 * NOTES
441 *  the same as SHCreateShellFolderViewEx ???
442 */
443 static HRESULT WINAPI IShellFolder_CreateViewObject(
444         LPSHELLFOLDER this,
445         HWND32 hwndOwner,
446         REFIID riid,
447         LPVOID *ppvOut)
448 { LPSHELLVIEW pShellView;
449   char    xriid[50];
450   HRESULT       hr;
451
452         WINE_StringFromCLSID(riid,xriid);
453   TRACE(shell,"(%p)->(hwnd=0x%x,\n\tIID:\t%s,%p)\n",this,hwndOwner,xriid,ppvOut);
454         
455         *ppvOut = NULL;
456
457   pShellView = IShellView_Constructor(this, this->mpidl);
458   if(!pShellView)
459     return E_OUTOFMEMORY;
460   hr = pShellView->lpvtbl->fnQueryInterface(pShellView, riid, ppvOut);
461   pShellView->lpvtbl->fnRelease(pShellView);
462   TRACE(shell,"-- (%p)->(interface=%p)\n",this, ppvOut);
463   return hr; 
464 }
465
466 /**************************************************************************
467 *  IShellFolder_GetAttributesOf
468 *
469 * PARAMETERS
470 *  UINT            cidl,     //[in ] num elements in pidl array
471 +  LPCITEMIDLIST*  apidl,    //[in ] simple pidl array 
472 *  ULONG*          rgfInOut) //[out] result array  
473 *
474 * FIXME: quick hack
475 *  Note: rgfInOut is documented as being an array of ULONGS.
476 *  This does not seem to be the case. Testing this function using the shell to 
477 *  call it with cidl > 1 (by deleting multiple items) reveals that the shell
478 *  passes ONE element in the array and writing to further elements will
479 *  cause the shell to fail later.
480 */
481 static HRESULT WINAPI IShellFolder_GetAttributesOf(LPSHELLFOLDER this,UINT32 cidl,LPCITEMIDLIST *apidl,DWORD *rgfInOut)
482 { LPCITEMIDLIST * pidltemp;
483   DWORD i;
484
485   TRACE(shell,"(%p)->(%d,%p,%p)\n",this,cidl,apidl,rgfInOut);
486
487   if ((! cidl )| (!apidl) | (!rgfInOut))
488     return E_INVALIDARG;
489
490   pidltemp=apidl;
491   *rgfInOut = 0x00;
492   i=cidl;
493
494   TRACE(shell,"-- mask=0x%08lx\n",*rgfInOut);
495   
496   do
497   { if (*pidltemp)
498     { if (_ILIsDesktop( *pidltemp))
499       { *rgfInOut |= (SFGAO_FOLDER | SFGAO_HASSUBFOLDER | SFGAO_FILESYSANCESTOR);
500       }
501       else if (_ILIsMyComputer( *pidltemp))
502       { *rgfInOut |= (SFGAO_FOLDER | SFGAO_HASSUBFOLDER);
503       }
504       else if (_ILIsDrive( *pidltemp))
505       { *rgfInOut |= (SFGAO_FOLDER | SFGAO_HASSUBFOLDER  | SFGAO_FILESYSTEM);
506       }
507       else if (_ILIsFolder( *pidltemp))
508       { *rgfInOut |= (SFGAO_FOLDER | SFGAO_HASSUBFOLDER | SFGAO_FILESYSTEM );
509       }
510       else if (_ILIsValue( *pidltemp))
511       { *rgfInOut |= (SFGAO_FILESYSTEM);
512       }
513     }
514     pidltemp++;
515     cidl--;
516   } while (cidl > 0 && *pidltemp);
517
518   return S_OK;
519 }
520 /**************************************************************************
521 *  IShellFolder_GetUIObjectOf
522 *
523 * PARAMETERS
524 *  HWND           hwndOwner, //[in ] Parent window for any output
525 *  UINT           cidl,      //[in ] array size
526 *  LPCITEMIDLIST* apidl,     //[in ] simple pidl array
527 *  REFIID         riid,      //[in ] Requested Interface
528 *  UINT*          prgfInOut, //[   ] reserved 
529 *  LPVOID*        ppvObject) //[out] Resulting Interface
530 *
531 * NOTES
532 *  This function gets asked to return "view objects" for one or more (multiple select)
533 *  items:
534 *  The viewobject typically is an COM object with one of the following interfaces:
535 *  IExtractIcon,IDataObject,IContextMenu
536 *  In order to support icon positions in the default Listview your DataObject
537 *  must implement the SetData method (in addition to GetData :) - the shell passes
538 *  a barely documented "Icon positions" structure to SetData when the drag starts,
539 *  and GetData's it if the drop is in another explorer window that needs the positions.
540 */
541 static HRESULT WINAPI IShellFolder_GetUIObjectOf( LPSHELLFOLDER this,HWND32 hwndOwner,UINT32 cidl,
542  LPCITEMIDLIST * apidl, REFIID riid, UINT32 * prgfInOut,LPVOID * ppvOut)
543 { char          xclsid[50];
544   LPEXTRACTICON pei;
545   LPCONTEXTMENU pcm;
546   LPITEMIDLIST  pidl;
547    
548   WINE_StringFromCLSID(riid,xclsid);
549
550   TRACE(shell,"(%p)->(%u,%u,pidl=%p,\n\tIID:%s,%p,%p)\n",
551           this,hwndOwner,cidl,apidl,xclsid,prgfInOut,ppvOut);
552
553   *ppvOut = NULL;
554
555   if(IsEqualIID(riid, &IID_IContextMenu))
556   { pcm  = IContextMenu_Constructor(this, apidl, cidl);
557     if(pcm)
558     { *ppvOut = pcm;
559       return S_OK;
560     }
561   }
562
563   if(cidl != 1)
564     return E_FAIL;
565
566   if(IsEqualIID(riid, &IID_IExtractIcon))
567   { pidl = ILCombine(this->mpidl, apidl[0]);
568     pei = IExtractIcon_Constructor(pidl);
569
570     /* The temp PIDL can be deleted because the new CExtractIcon either failed or 
571     made its own copy of it. */
572     SHFree(pidl);
573
574     if(pei)
575     { *ppvOut = pei;
576        return S_OK;
577     }
578     return E_OUTOFMEMORY;
579   }
580
581 /*  if(IsEqualIID(riid, IID_IQueryInfo))
582   { CQueryInfo     *pqit;
583     LPITEMIDLIST   pidl;
584     pidl = m_pPidlMgr->Concatenate(m_pidl, pPidl[0]);
585     pqit = new CQueryInfo(pidl);
586  */
587     /* The temp PIDL can be deleted because the new CQueryInfo either failed or 
588     made its own copy of it. */
589  /*   m_pPidlMgr->Delete(pidl);
590  
591     if(pqit)
592     { *ppvReturn = pqit;
593       return S_OK;
594     }
595     return E_OUTOFMEMORY;
596   }
597 */
598   ERR(shell,"(%p)->E_NOINTERFACE\n",this);
599   return E_NOINTERFACE;
600 }
601 /**************************************************************************
602 *  IShellFolder_GetDisplayNameOf
603 *  Retrieves the display name for the specified file object or subfolder
604 *
605 * PARAMETERS
606 *  LPCITEMIDLIST pidl,    //[in ] complex pidl to item
607 *  DWORD         dwFlags, //[in ] SHGNO formatting flags
608 *  LPSTRRET      lpName)  //[out] Returned display name
609 *
610 * FIXME
611 *  if the name is in the pidl the ret value should be a STRRET_OFFSET
612 */
613 #define GET_SHGDN_FOR(dwFlags)         ((DWORD)dwFlags & (DWORD)0x0000FF00)
614 #define GET_SHGDN_RELATION(dwFlags)    ((DWORD)dwFlags & (DWORD)0x000000FF)
615
616 static HRESULT WINAPI IShellFolder_GetDisplayNameOf( LPSHELLFOLDER this, LPCITEMIDLIST pidl, DWORD dwFlags, LPSTRRET lpName)
617 {       CHAR           szText[MAX_PATH];
618         CHAR           szTemp[MAX_PATH];
619         CHAR           szSpecial[MAX_PATH];
620         CHAR           szDrive[MAX_PATH];
621         DWORD          dwVolumeSerialNumber,dwMaximumComponetLength,dwFileSystemFlags;
622         LPITEMIDLIST   pidlTemp=NULL;
623         BOOL32                           bSimplePidl=FALSE;
624                 
625         TRACE(shell,"(%p)->(pidl=%p,0x%08lx,%p)\n",this,pidl,dwFlags,lpName);
626
627         if (!pidl)
628         {  return E_OUTOFMEMORY;
629         } 
630
631         szSpecial[0]=0x00; 
632         szDrive[0]=0x00;
633
634         /* test if simple(relative) or complex(absolute) pidl */
635         pidlTemp = ILGetNext(pidl);
636         if (pidlTemp->mkid.cb==0x00)
637         { bSimplePidl = TRUE;
638         }
639         if (_ILIsDesktop( pidl))
640         { strcpy (szText,"Desktop");
641         }
642         else
643         { if (_ILIsMyComputer( pidl))
644           { _ILGetItemText( pidl, szSpecial, MAX_PATH);
645           }
646           if (_ILIsDrive( pidl))
647           { pidlTemp = ILFindLastID(pidl);
648             if (pidlTemp)
649             { _ILGetItemText( pidlTemp, szTemp, MAX_PATH);
650             }
651             if ( dwFlags==SHGDN_NORMAL || dwFlags==SHGDN_INFOLDER)
652             { GetVolumeInformation32A(szTemp,szDrive,MAX_PATH,&dwVolumeSerialNumber,&dwMaximumComponetLength,&dwFileSystemFlags,NULL,0);
653               if (szTemp[2]=='\\')
654               { szTemp[2]=0x00;
655               }
656               strcat (szDrive," (");
657               strcat (szDrive,szTemp);
658               strcat (szDrive,")"); 
659             }
660             else
661             {  PathAddBackslash (szTemp);
662                strcpy(szDrive,szTemp);
663             }
664           }
665                 
666           switch(dwFlags)
667           { case SHGDN_NORMAL:
668               _ILGetPidlPath( pidl, szText, MAX_PATH);
669               break;
670             case SHGDN_INFOLDER:
671               pidlTemp = ILFindLastID(pidl);
672               if (pidlTemp)
673               { _ILGetItemText( pidlTemp, szText, MAX_PATH);
674               }
675               break;                            
676             case SHGDN_FORPARSING:
677               if (bSimplePidl)
678               { /* if the IShellFolder has parents, get the path from the
679                 parent and add the ItemName*/
680                 szText[0]=0x00;
681                 if (this->mlpszFolder && strlen (this->mlpszFolder))
682                 { if (strcmp(this->mlpszFolder,"My Computer"))
683                   { strcpy (szText,this->mlpszFolder);
684                     PathAddBackslash (szText);
685                   }
686                 }
687                 pidlTemp = ILFindLastID(pidl);
688                 if (pidlTemp)
689                 { _ILGetItemText( pidlTemp, szTemp, MAX_PATH );
690                 } 
691                 strcat(szText,szTemp);
692               }
693               else                                      
694               { /* if the pidl is absolute, get everything from the pidl*/
695                 _ILGetPidlPath( pidl, szText, MAX_PATH);
696               }
697               break;
698             default:
699               return E_INVALIDARG;
700           }
701           if ((szText[0]==0x00 && szDrive[0]!=0x00)|| (bSimplePidl && szDrive[0]!=0x00))
702           { strcpy(szText,szDrive);
703           }
704           if (szText[0]==0x00 && szSpecial[0]!=0x00)
705           { strcpy(szText,szSpecial);
706           }
707         }
708   
709         TRACE(shell,"-- (%p)->(%s,%s,%s)\n",this,szSpecial,szDrive,szText);
710
711         if(!(lpName))
712         {  return E_OUTOFMEMORY;
713         }
714         lpName->uType = STRRET_CSTR;    
715         strcpy(lpName->u.cStr,szText);
716         return S_OK;
717 }
718
719 /**************************************************************************
720 *  IShellFolder_SetNameOf
721 *  Changes the name of a file object or subfolder, possibly changing its item
722 *  identifier in the process.
723 *
724 * PARAMETERS
725 *  HWND          hwndOwner,  //[in ] Owner window for output
726 *  LPCITEMIDLIST pidl,       //[in ] simple pidl of item to change
727 *  LPCOLESTR     lpszName,   //[in ] the items new display name
728 *  DWORD         dwFlags,    //[in ] SHGNO formatting flags
729 *  LPITEMIDLIST* ppidlOut)   //[out] simple pidl returned
730 */
731 static HRESULT WINAPI IShellFolder_SetNameOf(
732         LPSHELLFOLDER this,
733                 HWND32 hwndOwner, 
734     LPCITEMIDLIST pidl, /*simple pidl*/
735     LPCOLESTR32 lpName, 
736     DWORD dw, 
737     LPITEMIDLIST *pPidlOut)
738 {  FIXME(shell,"(%p)->(%u,pidl=%p,%s,%lu,%p),stub!\n",
739           this,hwndOwner,pidl,debugstr_w(lpName),dw,pPidlOut);
740          return E_NOTIMPL;
741 }
742 /**************************************************************************
743 *  IShellFolder_GetFolderPath
744 *  FIXME: drive not included
745 */
746 static BOOL32 WINAPI IShellFolder_GetFolderPath(LPSHELLFOLDER this, LPSTR lpszOut, DWORD dwOutSize)
747 {       DWORD   dwSize;
748
749         TRACE(shell,"(%p)->(%p %lu)\n",this, lpszOut, dwOutSize);
750         if (!lpszOut)
751         { return FALSE;
752         }
753     
754         *lpszOut=0;
755     
756         dwSize = strlen (this->mlpszFolder) +1;
757         if ( dwSize > dwOutSize)
758           return FALSE;
759         strcpy(lpszOut, this->mlpszFolder);
760
761         TRACE(shell,"-- (%p)->(return=%s)\n",this, lpszOut);
762         return TRUE;
763 }