Recovery of release 990110 after disk crash.
[wine.git] / dlls / shell32 / shlfolder.c
blob3fff67dc7e976fe90bbc973f41baf6c40d156989
1 /*
2 * Shell Folder stuff
4 * Copyright 1997 Marcus Meissner
5 * Copyright 1998 Juergen Schmied
7 */
9 #include <ctype.h>
10 #include <stdlib.h>
11 #include <string.h>
12 #include "ole.h"
13 #include "ole2.h"
14 #include "debug.h"
15 #include "shlobj.h"
16 #include "objbase.h"
17 #include "shell.h"
18 #include "winerror.h"
19 #include "winnls.h"
20 #include "winproc.h"
21 #include "commctrl.h"
22 #include "pidl.h"
23 #include "shell32_main.h"
25 static HRESULT WINAPI IShellFolder_QueryInterface(LPSHELLFOLDER,REFIID,LPVOID*);
26 static ULONG WINAPI IShellFolder_AddRef(LPSHELLFOLDER);
27 static ULONG WINAPI IShellFolder_Release(LPSHELLFOLDER);
28 static HRESULT WINAPI IShellFolder_Initialize(LPSHELLFOLDER,LPCITEMIDLIST);
29 static HRESULT WINAPI IShellFolder_ParseDisplayName(LPSHELLFOLDER,HWND32,LPBC,LPOLESTR32,DWORD*,LPITEMIDLIST*,DWORD*);
30 static HRESULT WINAPI IShellFolder_EnumObjects(LPSHELLFOLDER,HWND32,DWORD,LPENUMIDLIST*);
31 static HRESULT WINAPI IShellFolder_BindToObject(LPSHELLFOLDER,LPCITEMIDLIST,LPBC,REFIID,LPVOID*);
32 static HRESULT WINAPI IShellFolder_BindToStorage(LPSHELLFOLDER,LPCITEMIDLIST,LPBC,REFIID,LPVOID*);
33 static HRESULT WINAPI IShellFolder_CompareIDs(LPSHELLFOLDER,LPARAM,LPCITEMIDLIST,LPCITEMIDLIST);
34 static HRESULT WINAPI IShellFolder_CreateViewObject(LPSHELLFOLDER,HWND32,REFIID,LPVOID*);
35 static HRESULT WINAPI IShellFolder_GetAttributesOf(LPSHELLFOLDER,UINT32,LPCITEMIDLIST*,DWORD*);
36 static HRESULT WINAPI IShellFolder_GetUIObjectOf(LPSHELLFOLDER,HWND32,UINT32,LPCITEMIDLIST*,REFIID,UINT32*,LPVOID*);
37 static HRESULT WINAPI IShellFolder_GetDisplayNameOf(LPSHELLFOLDER,LPCITEMIDLIST,DWORD,LPSTRRET);
38 static HRESULT WINAPI IShellFolder_SetNameOf(LPSHELLFOLDER,HWND32,LPCITEMIDLIST,LPCOLESTR32,DWORD,LPITEMIDLIST*);
39 static BOOL32 WINAPI IShellFolder_GetFolderPath(LPSHELLFOLDER,LPSTR,DWORD);
41 /***************************************************************************
42 * GetNextElement (internal function)
44 * gets a part of a string till the first backslash
46 * PARAMETERS
47 * pszNext [IN] string to get the element from
48 * pszOut [IN] pointer to buffer whitch receives string
49 * dwOut [IN] length of pszOut
51 * RETURNS
52 * LPSTR pointer to first, not yet parsed char
54 LPSTR GetNextElement(LPSTR pszNext,LPSTR pszOut,DWORD dwOut)
55 { LPSTR pszTail = pszNext;
56 DWORD dwCopy;
57 TRACE(shell,"(%s %p 0x%08lx)\n",debugstr_a(pszNext),pszOut,dwOut);
59 if(!pszNext || !*pszNext)
60 return NULL;
62 while(*pszTail && (*pszTail != '\\'))
63 { pszTail++;
65 dwCopy=((LPBYTE)pszTail-(LPBYTE)pszNext)/sizeof(CHAR)+1;
66 lstrcpyn32A(pszOut, pszNext, (dwOut<dwCopy)? dwOut : dwCopy);
68 if(*pszTail)
69 { pszTail++;
72 TRACE(shell,"--(%s %s 0x%08lx)\n",debugstr_a(pszNext),debugstr_a(pszOut),dwOut);
73 return pszTail;
76 /***********************************************************************
77 * IShellFolder implementation
79 static struct IShellFolder_VTable sfvt =
80 { IShellFolder_QueryInterface,
81 IShellFolder_AddRef,
82 IShellFolder_Release,
83 IShellFolder_ParseDisplayName,
84 IShellFolder_EnumObjects,
85 IShellFolder_BindToObject,
86 IShellFolder_BindToStorage,
87 IShellFolder_CompareIDs,
88 IShellFolder_CreateViewObject,
89 IShellFolder_GetAttributesOf,
90 IShellFolder_GetUIObjectOf,
91 IShellFolder_GetDisplayNameOf,
92 IShellFolder_SetNameOf,
93 IShellFolder_GetFolderPath
95 /**************************************************************************
96 * IShellFolder_Constructor
99 LPSHELLFOLDER IShellFolder_Constructor(LPSHELLFOLDER pParent,LPITEMIDLIST pidl)
100 { LPSHELLFOLDER sf;
101 DWORD dwSize=0;
102 sf=(LPSHELLFOLDER)HeapAlloc(GetProcessHeap(),0,sizeof(IShellFolder));
103 sf->ref=1;
104 sf->lpvtbl=&sfvt;
105 sf->sMyPath=NULL; /* path of the folder */
106 sf->pMyPidl=NULL; /* my qualified pidl */
107 sf->mpSFParent=pParent; /* parrent shellfolder */
109 TRACE(shell,"(%p)->(parent=%p, pidl=%p)\n",sf,pParent, pidl);
111 /* keep a copy of the pidl in the instance*/
112 sf->mpidl = ILClone(pidl);
114 if(sf->mpidl) /* do we have a pidl? */
115 { dwSize = 0;
116 if(sf->mpSFParent->sMyPath) /* get the size of the parents path */
117 { dwSize += strlen(sf->mpSFParent->sMyPath) ;
118 TRACE(shell,"-- (%p)->(parent's path=%s)\n",sf, debugstr_a(sf->mpSFParent->sMyPath));
120 dwSize += _ILGetFolderText(sf->mpidl,NULL,0); /* add the size of the foldername*/
121 sf->sMyPath = SHAlloc(dwSize+1);
122 if(sf->sMyPath)
123 { *(sf->sMyPath)=0x00;
124 if(sf->mpSFParent->sMyPath) /* if the parent has a path, get it*/
125 { strcpy(sf->sMyPath, sf->mpSFParent->sMyPath);
126 PathAddBackslash32A (sf->sMyPath);
128 sf->pMyPidl = ILCombine(sf->pMyPidl, pidl);
129 _ILGetFolderText(sf->mpidl, sf->sMyPath+strlen(sf->sMyPath), dwSize-strlen(sf->sMyPath));
130 TRACE(shell,"-- (%p)->(my path=%s)\n",sf, debugstr_a(sf->sMyPath));
133 return sf;
135 /**************************************************************************
136 * IShellFolder::QueryInterface
137 * PARAMETERS
138 * REFIID riid, //[in ] Requested InterfaceID
139 * LPVOID* ppvObject) //[out] Interface* to hold the result
141 static HRESULT WINAPI IShellFolder_QueryInterface(
142 LPSHELLFOLDER this, REFIID riid, LPVOID *ppvObj)
143 { char xriid[50];
144 WINE_StringFromCLSID((LPCLSID)riid,xriid);
145 TRACE(shell,"(%p)->(\n\tIID:\t%s,%p)\n",this,xriid,ppvObj);
147 *ppvObj = NULL;
149 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
150 { *ppvObj = this;
152 else if(IsEqualIID(riid, &IID_IShellFolder)) /*IShellFolder*/
153 { *ppvObj = (IShellFolder*)this;
156 if(*ppvObj)
157 { (*(LPSHELLFOLDER*)ppvObj)->lpvtbl->fnAddRef(this);
158 TRACE(shell,"-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
159 return S_OK;
161 TRACE(shell,"-- Interface: E_NOINTERFACE\n");
162 return E_NOINTERFACE;
165 /**************************************************************************
166 * IShellFolder::AddRef
169 static ULONG WINAPI IShellFolder_AddRef(LPSHELLFOLDER this)
170 { TRACE(shell,"(%p)->(count=%lu)\n",this,(this->ref)+1);
171 return ++(this->ref);
174 /**************************************************************************
175 * IShellFolder_Release
177 static ULONG WINAPI IShellFolder_Release(LPSHELLFOLDER this)
178 { TRACE(shell,"(%p)->(count=%lu)\n",this,this->ref);
179 if (!--(this->ref))
180 { TRACE(shell,"-- destroying IShellFolder(%p)\n",this);
182 if (pdesktopfolder==this)
183 { pdesktopfolder=NULL;
184 TRACE(shell,"-- destroyed IShellFolder(%p) was Desktopfolder\n",this);
186 if(this->pMyPidl)
187 { SHFree(this->pMyPidl);
189 if(this->mpidl)
190 { SHFree(this->mpidl);
192 if(this->sMyPath)
193 { SHFree(this->sMyPath);
196 HeapFree(GetProcessHeap(),0,this);
198 return 0;
200 return this->ref;
202 /**************************************************************************
203 * IShellFolder_ParseDisplayName
204 * PARAMETERS
205 * HWND hwndOwner, //[in ] Parent window for any message's
206 * LPBC pbc, //[in ] reserved
207 * LPOLESTR lpszDisplayName,//[in ] "Unicode" displayname.
208 * ULONG* pchEaten, //[out] (unicode) characters processed
209 * LPITEMIDLIST* ppidl, //[out] complex pidl to item
210 * ULONG* pdwAttributes //[out] items attributes
212 * FIXME:
213 * pdwAttributes: not used
215 static HRESULT WINAPI IShellFolder_ParseDisplayName(
216 LPSHELLFOLDER this,
217 HWND32 hwndOwner,
218 LPBC pbcReserved,
219 LPOLESTR32 lpszDisplayName,
220 DWORD *pchEaten,
221 LPITEMIDLIST *ppidl,
222 DWORD *pdwAttributes)
223 { HRESULT hr=E_OUTOFMEMORY;
224 LPITEMIDLIST pidlFull=NULL, pidlTemp = NULL, pidlOld = NULL;
225 LPSTR pszNext=NULL;
226 CHAR szTemp[MAX_PATH],szElement[MAX_PATH];
227 BOOL32 bIsFile;
229 TRACE(shell,"(%p)->(HWND=0x%08x,%p,%p=%s,%p,pidl=%p,%p)\n",
230 this,hwndOwner,pbcReserved,lpszDisplayName,
231 debugstr_w(lpszDisplayName),pchEaten,ppidl,pdwAttributes);
233 { hr = E_FAIL;
234 WideCharToLocal32(szTemp, lpszDisplayName, lstrlen32W(lpszDisplayName) + 1);
235 if(szTemp[0])
236 { if (strcmp(szTemp,"Desktop")==0)
237 { pidlFull = _ILCreateDesktop();
239 else if (strcmp(szTemp,"My Computer")==0)
240 { pidlFull = _ILCreateMyComputer();
242 else
243 { if (!PathIsRoot32A(szTemp))
244 { if (this->sMyPath && strlen (this->sMyPath))
245 { if (strcmp(this->sMyPath,"My Computer"))
246 { strcpy (szElement,this->sMyPath);
247 PathAddBackslash32A (szElement);
248 strcat (szElement, szTemp);
249 strcpy (szTemp, szElement);
254 /* check if the lpszDisplayName is Folder or File*/
255 bIsFile = ! (GetFileAttributes32A(szTemp) & FILE_ATTRIBUTE_DIRECTORY);
256 pszNext = GetNextElement(szTemp, szElement, MAX_PATH);
258 pidlFull = _ILCreateMyComputer();
259 pidlTemp = _ILCreateDrive(szElement);
260 pidlOld = pidlFull;
261 pidlFull = ILCombine(pidlFull,pidlTemp);
262 SHFree(pidlOld);
264 if(pidlFull)
265 { while((pszNext=GetNextElement(pszNext, szElement, MAX_PATH)))
266 { if(!*pszNext && bIsFile)
267 { pidlTemp = _ILCreateValue(szElement);
269 else
270 { pidlTemp = _ILCreateFolder(szElement);
272 pidlOld = pidlFull;
273 pidlFull = ILCombine(pidlFull,pidlTemp);
274 SHFree(pidlOld);
276 hr = S_OK;
281 *ppidl = pidlFull;
282 return hr;
285 /**************************************************************************
286 * IShellFolder_EnumObjects
287 * PARAMETERS
288 * HWND hwndOwner, //[in ] Parent Window
289 * DWORD grfFlags, //[in ] SHCONTF enumeration mask
290 * LPENUMIDLIST* ppenumIDList //[out] IEnumIDList interface
292 static HRESULT WINAPI IShellFolder_EnumObjects(
293 LPSHELLFOLDER this,
294 HWND32 hwndOwner,
295 DWORD dwFlags,
296 LPENUMIDLIST* ppEnumIDList)
297 { TRACE(shell,"(%p)->(HWND=0x%08x flags=0x%08lx pplist=%p)\n",this,hwndOwner,dwFlags,ppEnumIDList);
299 *ppEnumIDList = NULL;
300 *ppEnumIDList = IEnumIDList_Constructor (this->sMyPath, dwFlags);
301 TRACE(shell,"-- (%p)->(new ID List: %p)\n",this,*ppEnumIDList);
302 if(!*ppEnumIDList)
303 { return E_OUTOFMEMORY;
305 return S_OK;
307 /**************************************************************************
308 * IShellFolder_Initialize()
309 * IPersistFolder Method
311 static HRESULT WINAPI IShellFolder_Initialize( LPSHELLFOLDER this,LPCITEMIDLIST pidl)
312 { TRACE(shell,"(%p)->(pidl=%p)\n",this,pidl);
314 if(this->pMyPidl)
315 { SHFree(this->pMyPidl);
316 this->pMyPidl = NULL;
318 this->pMyPidl = ILClone(pidl);
319 return S_OK;
322 /**************************************************************************
323 * IShellFolder_BindToObject
324 * PARAMETERS
325 * LPCITEMIDLIST pidl, //[in ] complex pidl to open
326 * LPBC pbc, //[in ] reserved
327 * REFIID riid, //[in ] Initial Interface
328 * LPVOID* ppvObject //[out] Interface*
330 static HRESULT WINAPI IShellFolder_BindToObject( LPSHELLFOLDER this, LPCITEMIDLIST pidl,
331 LPBC pbcReserved, REFIID riid, LPVOID * ppvOut)
332 { char xriid[50];
333 HRESULT hr;
334 LPSHELLFOLDER pShellFolder;
336 WINE_StringFromCLSID(riid,xriid);
338 TRACE(shell,"(%p)->(pidl=%p,%p,\n\tIID:%s,%p)\n",this,pidl,pbcReserved,xriid,ppvOut);
340 *ppvOut = NULL;
342 pShellFolder = IShellFolder_Constructor(this, pidl);
344 if(!pShellFolder)
345 return E_OUTOFMEMORY;
347 IShellFolder_Initialize(pShellFolder, this->pMyPidl);
349 hr = pShellFolder->lpvtbl->fnQueryInterface(pShellFolder, riid, ppvOut);
350 pShellFolder->lpvtbl->fnRelease(pShellFolder);
351 TRACE(shell,"-- (%p)->(interface=%p)\n",this, ppvOut);
352 return hr;
355 /**************************************************************************
356 * IShellFolder_BindToStorage
357 * PARAMETERS
358 * LPCITEMIDLIST pidl, //[in ] complex pidl to store
359 * LPBC pbc, //[in ] reserved
360 * REFIID riid, //[in ] Initial storage interface
361 * LPVOID* ppvObject //[out] Interface* returned
363 static HRESULT WINAPI IShellFolder_BindToStorage(LPSHELLFOLDER this,
364 LPCITEMIDLIST pidl,LPBC pbcReserved, REFIID riid, LPVOID *ppvOut)
365 { char xriid[50];
366 WINE_StringFromCLSID(riid,xriid);
368 FIXME(shell,"(%p)->(pidl=%p,%p,\n\tIID:%s,%p) stub\n",this,pidl,pbcReserved,xriid,ppvOut);
370 *ppvOut = NULL;
371 return E_NOTIMPL;
374 /**************************************************************************
375 * IShellFolder_CompareIDs
377 * PARMETERS
378 * LPARAM lParam, //[in ] Column?
379 * LPCITEMIDLIST pidl1, //[in ] simple pidl
380 * LPCITEMIDLIST pidl2) //[in ] simple pidl
382 * NOTES
383 * Special case - If one of the items is a Path and the other is a File,
384 * always make the Path come before the File.
386 * FIXME
387 * we have to handle simple pidl's only (?)
389 static HRESULT WINAPI IShellFolder_CompareIDs(LPSHELLFOLDER this,
390 LPARAM lParam, LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
391 { CHAR szString1[MAX_PATH] = "";
392 CHAR szString2[MAX_PATH] = "";
393 int nReturn;
394 LPCITEMIDLIST pidlTemp1 = pidl1, pidlTemp2 = pidl2;
396 TRACE(shell,"(%p)->(0x%08lx,pidl1=%p,pidl2=%p)\n",this,lParam,pidl1,pidl2);
397 pdump (pidl1);
398 pdump (pidl2);
400 if (!pidl1 && !pidl2)
401 return 0;
402 if (!pidl1) /* Desktop < anything */
403 return -1;
404 if (!pidl2)
405 return 1;
407 /* get the last item in each list */
408 while((ILGetNext(pidlTemp1))->mkid.cb)
409 pidlTemp1 = ILGetNext(pidlTemp1);
410 while((ILGetNext(pidlTemp2))->mkid.cb)
411 pidlTemp2 = ILGetNext(pidlTemp2);
413 /* at this point, both pidlTemp1 and pidlTemp2 point to the last item in the list */
414 if(_ILIsValue(pidlTemp1) != _ILIsValue(pidlTemp2))
415 { if(_ILIsValue(pidlTemp1))
416 return 1;
417 return -1;
420 _ILGetDrive( pidl1,szString1,sizeof(szString1));
421 _ILGetDrive( pidl2,szString1,sizeof(szString2));
422 nReturn = strcasecmp(szString1, szString2);
424 if(nReturn)
425 return nReturn;
427 _ILGetFolderText( pidl1,szString1,sizeof(szString1));
428 _ILGetFolderText( pidl2,szString2,sizeof(szString2));
429 nReturn = strcasecmp(szString1, szString2);
431 if(nReturn)
432 return nReturn;
434 _ILGetValueText(pidl1,szString1,sizeof(szString1));
435 _ILGetValueText(pidl2,szString2,sizeof(szString2));
436 return strcasecmp(szString1, szString2);
439 /**************************************************************************
440 * IShellFolder_CreateViewObject
441 * Creates an View Object representing the ShellFolder
442 * IShellView / IShellBrowser / IContextMenu
444 * PARAMETERS
445 * HWND hwndOwner, // Handle of owner window
446 * REFIID riid, // Requested initial interface
447 * LPVOID* ppvObject) // Resultant interface*
449 * NOTES
450 * the same as SHCreateShellFolderViewEx ???
452 static HRESULT WINAPI IShellFolder_CreateViewObject( LPSHELLFOLDER this,
453 HWND32 hwndOwner, REFIID riid, LPVOID *ppvOut)
454 { LPSHELLVIEW pShellView;
455 char xriid[50];
456 HRESULT hr;
458 WINE_StringFromCLSID(riid,xriid);
459 TRACE(shell,"(%p)->(hwnd=0x%x,\n\tIID:\t%s,%p)\n",this,hwndOwner,xriid,ppvOut);
461 *ppvOut = NULL;
463 pShellView = IShellView_Constructor(this, this->mpidl);
465 if(!pShellView)
466 return E_OUTOFMEMORY;
468 hr = pShellView->lpvtbl->fnQueryInterface(pShellView, riid, ppvOut);
469 pShellView->lpvtbl->fnRelease(pShellView);
470 TRACE(shell,"-- (%p)->(interface=%p)\n",this, ppvOut);
471 return hr;
474 /**************************************************************************
475 * IShellFolder_GetAttributesOf
477 * PARAMETERS
478 * UINT cidl, //[in ] num elements in pidl array
479 + LPCITEMIDLIST* apidl, //[in ] simple pidl array
480 * ULONG* rgfInOut) //[out] result array
482 * FIXME: quick hack
483 * Note: rgfInOut is documented as being an array of ULONGS.
484 * This does not seem to be the case. Testing this function using the shell to
485 * call it with cidl > 1 (by deleting multiple items) reveals that the shell
486 * passes ONE element in the array and writing to further elements will
487 * cause the shell to fail later.
489 static HRESULT WINAPI IShellFolder_GetAttributesOf(LPSHELLFOLDER this,UINT32 cidl,LPCITEMIDLIST *apidl,DWORD *rgfInOut)
490 { LPCITEMIDLIST * pidltemp;
491 DWORD i;
493 TRACE(shell,"(%p)->(%d,%p,%p)\n",this,cidl,apidl,rgfInOut);
495 if ((! cidl )| (!apidl) | (!rgfInOut))
496 return E_INVALIDARG;
498 pidltemp=apidl;
499 *rgfInOut = 0x00;
500 i=cidl;
502 TRACE(shell,"-- mask=0x%08lx\n",*rgfInOut);
505 { if (*pidltemp)
506 { pdump (*pidltemp);
507 if (_ILIsDesktop( *pidltemp))
508 { *rgfInOut |= ( SFGAO_HASSUBFOLDER | SFGAO_FOLDER | SFGAO_DROPTARGET | SFGAO_HASPROPSHEET | SFGAO_CANLINK );
510 else if (_ILIsMyComputer( *pidltemp))
511 { *rgfInOut |= ( SFGAO_HASSUBFOLDER | SFGAO_FOLDER | SFGAO_FILESYSANCESTOR
512 | SFGAO_DROPTARGET | SFGAO_HASPROPSHEET | SFGAO_CANRENAME | SFGAO_CANLINK );
514 else if (_ILIsDrive( *pidltemp))
515 { *rgfInOut |= ( SFGAO_HASSUBFOLDER | SFGAO_FILESYSTEM | SFGAO_FOLDER | SFGAO_FILESYSANCESTOR |
516 SFGAO_DROPTARGET | SFGAO_HASPROPSHEET | SFGAO_CANLINK );
518 else if (_ILIsFolder( *pidltemp))
519 { *rgfInOut |= ( SFGAO_HASSUBFOLDER | SFGAO_FILESYSTEM | SFGAO_FOLDER | SFGAO_CAPABILITYMASK );
521 else if (_ILIsValue( *pidltemp))
522 { *rgfInOut |= (SFGAO_FILESYSTEM | SFGAO_CAPABILITYMASK );
525 pidltemp++;
526 cidl--;
527 } while (cidl > 0 && *pidltemp);
529 return S_OK;
531 /**************************************************************************
532 * IShellFolder_GetUIObjectOf
534 * PARAMETERS
535 * HWND hwndOwner, //[in ] Parent window for any output
536 * UINT cidl, //[in ] array size
537 * LPCITEMIDLIST* apidl, //[in ] simple pidl array
538 * REFIID riid, //[in ] Requested Interface
539 * UINT* prgfInOut, //[ ] reserved
540 * LPVOID* ppvObject) //[out] Resulting Interface
542 * NOTES
543 * This function gets asked to return "view objects" for one or more (multiple select)
544 * items:
545 * The viewobject typically is an COM object with one of the following interfaces:
546 * IExtractIcon,IDataObject,IContextMenu
547 * In order to support icon positions in the default Listview your DataObject
548 * must implement the SetData method (in addition to GetData :) - the shell passes
549 * a barely documented "Icon positions" structure to SetData when the drag starts,
550 * and GetData's it if the drop is in another explorer window that needs the positions.
552 static HRESULT WINAPI IShellFolder_GetUIObjectOf( LPSHELLFOLDER this,HWND32 hwndOwner,UINT32 cidl,
553 LPCITEMIDLIST * apidl, REFIID riid, UINT32 * prgfInOut,LPVOID * ppvOut)
554 { char xclsid[50];
555 LPITEMIDLIST pidl;
556 LPUNKNOWN pObj = NULL;
558 WINE_StringFromCLSID(riid,xclsid);
560 TRACE(shell,"(%p)->(%u,%u,apidl=%p,\n\tIID:%s,%p,%p)\n",
561 this,hwndOwner,cidl,apidl,xclsid,prgfInOut,ppvOut);
563 *ppvOut = NULL;
565 if(IsEqualIID(riid, &IID_IContextMenu))
566 { if(cidl < 1)
567 return E_INVALIDARG;
568 pObj = (LPUNKNOWN)IContextMenu_Constructor(this, apidl, cidl);
570 else if (IsEqualIID(riid, &IID_IDataObject))
571 { if (cidl < 1)
572 return(E_INVALIDARG);
573 pObj = (LPUNKNOWN)IDataObject_Constructor (hwndOwner, this, apidl, cidl);
575 else if(IsEqualIID(riid, &IID_IExtractIcon))
576 { if (cidl != 1)
577 return(E_INVALIDARG);
578 pidl = ILCombine(this->pMyPidl,apidl[0]);
579 pObj = (LPUNKNOWN)IExtractIcon_Constructor( pidl );
580 SHFree(pidl);
582 else
583 { ERR(shell,"(%p)->E_NOINTERFACE\n",this);
584 return E_NOINTERFACE;
586 if(!pObj)
587 return E_OUTOFMEMORY;
589 *ppvOut = pObj;
590 return S_OK;
592 /**************************************************************************
593 * IShellFolder_GetDisplayNameOf
594 * Retrieves the display name for the specified file object or subfolder
596 * PARAMETERS
597 * LPCITEMIDLIST pidl, //[in ] complex pidl to item
598 * DWORD dwFlags, //[in ] SHGNO formatting flags
599 * LPSTRRET lpName) //[out] Returned display name
601 * FIXME
602 * if the name is in the pidl the ret value should be a STRRET_OFFSET
604 #define GET_SHGDN_FOR(dwFlags) ((DWORD)dwFlags & (DWORD)0x0000FF00)
605 #define GET_SHGDN_RELATION(dwFlags) ((DWORD)dwFlags & (DWORD)0x000000FF)
607 static HRESULT WINAPI IShellFolder_GetDisplayNameOf( LPSHELLFOLDER this, LPCITEMIDLIST pidl, DWORD dwFlags, LPSTRRET lpName)
608 { CHAR szText[MAX_PATH];
609 CHAR szTemp[MAX_PATH];
610 CHAR szSpecial[MAX_PATH];
611 CHAR szDrive[MAX_PATH];
612 DWORD dwVolumeSerialNumber,dwMaximumComponetLength,dwFileSystemFlags;
613 LPITEMIDLIST pidlTemp=NULL;
614 BOOL32 bSimplePidl=FALSE;
616 TRACE(shell,"(%p)->(pidl=%p,0x%08lx,%p)\n",this,pidl,dwFlags,lpName);
618 szSpecial[0]=0x00;
619 szDrive[0]=0x00;
620 szText[0]=0x00;
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");
630 if (_ILIsDesktop( pidl))
631 { strcpy (szText,"Desktop");
633 else
634 { if (_ILIsMyComputer(pidl))
635 { _ILGetItemText(pidl, szSpecial, MAX_PATH);
636 pidl = ILGetNext(pidl);
639 if (_ILIsDrive(pidl))
640 { _ILGetDrive( pidl, szTemp, MAX_PATH);
642 if ( dwFlags==SHGDN_NORMAL || dwFlags==SHGDN_INFOLDER) /* like "A1-dos (C:)" */
643 { GetVolumeInformation32A(szTemp,szDrive,MAX_PATH,&dwVolumeSerialNumber,&dwMaximumComponetLength,&dwFileSystemFlags,NULL,0);
644 szTemp[2]=0x00; /* overwrite '\' */
645 strcat (szDrive," (");
646 strcat (szDrive,szTemp);
647 strcat (szDrive,")");
649 else /* like "C:\" */
650 { PathAddBackslash32A (szTemp);
651 strcpy(szDrive,szTemp);
656 switch(dwFlags)
657 { case SHGDN_NORMAL: /* 0x0000 */
658 _ILGetPidlPath( pidl, szText, MAX_PATH);
659 break;
661 case SHGDN_INFOLDER | SHGDN_FORPARSING: /* 0x8001 */
662 case SHGDN_INFOLDER: /* 0x0001 */
663 pidlTemp = ILFindLastID(pidl);
664 if (pidlTemp)
665 { _ILGetItemText( pidlTemp, szText, MAX_PATH);
667 break;
669 case SHGDN_FORPARSING: /* 0x8000 */
670 if (bSimplePidl)
671 { /* if the IShellFolder has parents, get the path from the
672 parent and add the ItemName*/
673 szText[0]=0x00;
674 if (this->sMyPath && strlen (this->sMyPath))
675 { if (strcmp(this->sMyPath,"My Computer"))
676 { strcpy (szText,this->sMyPath);
677 PathAddBackslash32A (szText);
680 pidlTemp = ILFindLastID(pidl);
681 if (pidlTemp)
682 { _ILGetItemText( pidlTemp, szTemp, MAX_PATH );
684 strcat(szText,szTemp);
686 else /* if the pidl is absolute, get everything from the pidl*/
687 { _ILGetPidlPath( pidl, szText, MAX_PATH);
689 break;
690 default:
691 TRACE(shell,"--- wrong flags=%lx\n", dwFlags);
692 return E_INVALIDARG;
694 if ((szText[0]==0x00 && szDrive[0]!=0x00)|| (bSimplePidl && szDrive[0]!=0x00))
695 { strcpy(szText,szDrive);
697 if (szText[0]==0x00 && szSpecial[0]!=0x00)
698 { strcpy(szText,szSpecial);
702 TRACE(shell,"-- (%p)->(%s)\n",this,szText);
704 if(!(lpName))
705 { return E_OUTOFMEMORY;
707 lpName->uType = STRRET_CSTRA;
708 strcpy(lpName->u.cStr,szText);
709 return S_OK;
712 /**************************************************************************
713 * IShellFolder_SetNameOf
714 * Changes the name of a file object or subfolder, possibly changing its item
715 * identifier in the process.
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
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;
735 /**************************************************************************
736 * IShellFolder_GetFolderPath
737 * FIXME: drive not included
739 static BOOL32 WINAPI IShellFolder_GetFolderPath(LPSHELLFOLDER this, LPSTR lpszOut, DWORD dwOutSize)
740 { DWORD dwSize;
742 TRACE(shell,"(%p)->(%p %lu)\n",this, lpszOut, dwOutSize);
743 if (!lpszOut)
744 { return FALSE;
747 *lpszOut=0;
749 if (! this->sMyPath)
750 return FALSE;
752 dwSize = strlen (this->sMyPath) +1;
753 if ( dwSize > dwOutSize)
754 return FALSE;
755 strcpy(lpszOut, this->sMyPath);
757 TRACE(shell,"-- (%p)->(return=%s)\n",this, lpszOut);
758 return TRUE;