Some cleanup.
[wine/multimedia.git] / dlls / shell32 / shlfolder.c
blob393753fea652a9026333a5021e00749caed35164
1 /*
2 * Shell Folder stuff (...and all the OLE-Objects of SHELL32.DLL)
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 "compobj.h"
16 #include "interfaces.h"
17 #include "shlobj.h"
18 #include "shell.h"
19 #include "winerror.h"
20 #include "winnls.h"
21 #include "winproc.h"
22 #include "commctrl.h"
23 #include "pidl.h"
24 #include "shell32_main.h"
26 static HRESULT WINAPI IShellFolder_QueryInterface(LPSHELLFOLDER,REFIID,LPVOID*);
27 static ULONG WINAPI IShellFolder_AddRef(LPSHELLFOLDER);
28 static ULONG WINAPI IShellFolder_Release(LPSHELLFOLDER);
29 static HRESULT WINAPI IShellFolder_Initialize(LPSHELLFOLDER,LPCITEMIDLIST);
30 static HRESULT WINAPI IShellFolder_ParseDisplayName(LPSHELLFOLDER,HWND32,LPBC,LPOLESTR32,DWORD*,LPITEMIDLIST*,DWORD*);
31 static HRESULT WINAPI IShellFolder_EnumObjects(LPSHELLFOLDER,HWND32,DWORD,LPENUMIDLIST*);
32 static HRESULT WINAPI IShellFolder_BindToObject(LPSHELLFOLDER,LPCITEMIDLIST,LPBC,REFIID,LPVOID*);
33 static HRESULT WINAPI IShellFolder_BindToStorage(LPSHELLFOLDER,LPCITEMIDLIST,LPBC,REFIID,LPVOID*);
34 static HRESULT WINAPI IShellFolder_CompareIDs(LPSHELLFOLDER,LPARAM,LPCITEMIDLIST,LPCITEMIDLIST);
35 static HRESULT WINAPI IShellFolder_CreateViewObject(LPSHELLFOLDER,HWND32,REFIID,LPVOID*);
36 static HRESULT WINAPI IShellFolder_GetAttributesOf(LPSHELLFOLDER,UINT32,LPCITEMIDLIST*,DWORD*);
37 static HRESULT WINAPI IShellFolder_GetUIObjectOf(LPSHELLFOLDER,HWND32,UINT32,LPCITEMIDLIST*,REFIID,UINT32*,LPVOID*);
38 static HRESULT WINAPI IShellFolder_GetDisplayNameOf(LPSHELLFOLDER,LPCITEMIDLIST,DWORD,LPSTRRET);
39 static HRESULT WINAPI IShellFolder_SetNameOf(LPSHELLFOLDER,HWND32,LPCITEMIDLIST,LPCOLESTR32,DWORD,LPITEMIDLIST*);
40 static BOOL32 WINAPI IShellFolder_GetFolderPath(LPSHELLFOLDER,LPSTR,DWORD);
42 /***************************************************************************
43 * GetNextElement (internal function)
45 * gets a part of a string till the first backslash
47 * PARAMETERS
48 * pszNext [IN] string to get the element from
49 * pszOut [IN] pointer to buffer whitch receives string
50 * dwOut [IN] length of pszOut
52 * RETURNS
53 * LPSTR pointer to first, not yet parsed char
55 LPSTR GetNextElement(LPSTR pszNext,LPSTR pszOut,DWORD dwOut)
56 { LPSTR pszTail = pszNext;
57 DWORD dwCopy;
58 TRACE(shell,"(%s %p 0x%08lx)\n",debugstr_a(pszNext),pszOut,dwOut);
60 if(!pszNext || !*pszNext)
61 return NULL;
63 while(*pszTail && (*pszTail != '\\'))
64 { pszTail++;
66 dwCopy=((LPBYTE)pszTail-(LPBYTE)pszNext)/sizeof(CHAR)+1;
67 lstrcpyn32A(pszOut, pszNext, (dwOut<dwCopy)? dwOut : dwCopy);
69 if(*pszTail)
70 { pszTail++;
73 TRACE(shell,"--(%s %s 0x%08lx)\n",debugstr_a(pszNext),debugstr_a(pszOut),dwOut);
74 return pszTail;
77 /***********************************************************************
78 * IShellFolder implementation
80 static struct IShellFolder_VTable sfvt =
81 { IShellFolder_QueryInterface,
82 IShellFolder_AddRef,
83 IShellFolder_Release,
84 IShellFolder_ParseDisplayName,
85 IShellFolder_EnumObjects,
86 IShellFolder_BindToObject,
87 IShellFolder_BindToStorage,
88 IShellFolder_CompareIDs,
89 IShellFolder_CreateViewObject,
90 IShellFolder_GetAttributesOf,
91 IShellFolder_GetUIObjectOf,
92 IShellFolder_GetDisplayNameOf,
93 IShellFolder_SetNameOf,
94 IShellFolder_GetFolderPath
96 /**************************************************************************
97 * IShellFolder_Constructor
100 LPSHELLFOLDER IShellFolder_Constructor(LPSHELLFOLDER pParent,LPITEMIDLIST pidl)
101 { LPSHELLFOLDER sf;
102 DWORD dwSize=0;
103 sf=(LPSHELLFOLDER)HeapAlloc(GetProcessHeap(),0,sizeof(IShellFolder));
104 sf->ref=1;
105 sf->lpvtbl=&sfvt;
106 sf->sMyPath=NULL; /* path of the folder */
107 sf->pMyPidl=NULL; /* my qualified pidl */
108 sf->mpSFParent=pParent; /* parrent shellfolder */
110 TRACE(shell,"(%p)->(parent=%p, pidl=%p)\n",sf,pParent, pidl);
112 /* keep a copy of the pidl in the instance*/
113 sf->mpidl = ILClone(pidl);
115 if(sf->mpidl) /* do we have a pidl? */
116 { dwSize = 0;
117 if(sf->mpSFParent->sMyPath) /* get the size of the parents path */
118 { dwSize += strlen(sf->mpSFParent->sMyPath) + 1;
119 TRACE(shell,"-- (%p)->(parent's path=%s)\n",sf, debugstr_a(sf->mpSFParent->sMyPath));
121 dwSize += _ILGetFolderText(sf->mpidl,NULL,0); /* add the size of the foldername*/
122 sf->sMyPath = SHAlloc(dwSize);
123 if(sf->sMyPath)
124 { *(sf->sMyPath)=0x00;
125 if(sf->mpSFParent->sMyPath) /* if the parent has a path, get it*/
126 { strcpy(sf->sMyPath, sf->mpSFParent->sMyPath);
127 PathAddBackslash32A (sf->sMyPath);
129 sf->pMyPidl = ILCombine(sf->pMyPidl, pidl);
130 _ILGetFolderText(sf->mpidl, sf->sMyPath+strlen(sf->sMyPath), dwSize-strlen(sf->sMyPath));
131 TRACE(shell,"-- (%p)->(my path=%s)\n",sf, debugstr_a(sf->sMyPath));
134 return sf;
136 /**************************************************************************
137 * IShellFolder::QueryInterface
138 * PARAMETERS
139 * REFIID riid, //[in ] Requested InterfaceID
140 * LPVOID* ppvObject) //[out] Interface* to hold the result
142 static HRESULT WINAPI IShellFolder_QueryInterface(
143 LPSHELLFOLDER this, REFIID riid, LPVOID *ppvObj)
144 { char xriid[50];
145 WINE_StringFromCLSID((LPCLSID)riid,xriid);
146 TRACE(shell,"(%p)->(\n\tIID:\t%s,%p)\n",this,xriid,ppvObj);
148 *ppvObj = NULL;
150 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
151 { *ppvObj = this;
153 else if(IsEqualIID(riid, &IID_IShellFolder)) /*IShellFolder*/
154 { *ppvObj = (IShellFolder*)this;
157 if(*ppvObj)
158 { (*(LPSHELLFOLDER*)ppvObj)->lpvtbl->fnAddRef(this);
159 TRACE(shell,"-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
160 return S_OK;
162 TRACE(shell,"-- Interface: E_NOINTERFACE\n");
163 return E_NOINTERFACE;
166 /**************************************************************************
167 * IShellFolder::AddRef
170 static ULONG WINAPI IShellFolder_AddRef(LPSHELLFOLDER this)
171 { TRACE(shell,"(%p)->(count=%lu)\n",this,(this->ref)+1);
172 return ++(this->ref);
175 /**************************************************************************
176 * IShellFolder_Release
178 static ULONG WINAPI IShellFolder_Release(LPSHELLFOLDER this)
179 { TRACE(shell,"(%p)->(count=%lu)\n",this,this->ref);
180 if (!--(this->ref))
181 { TRACE(shell,"-- destroying IShellFolder(%p)\n",this);
183 if (pdesktopfolder==this)
184 { pdesktopfolder=NULL;
185 TRACE(shell,"-- destroyed IShellFolder(%p) was Desktopfolder\n",this);
187 if(this->pMyPidl)
188 { SHFree(this->pMyPidl);
190 if(this->mpidl)
191 { SHFree(this->mpidl);
193 if(this->sMyPath)
194 { SHFree(this->sMyPath);
197 HeapFree(GetProcessHeap(),0,this);
199 return 0;
201 return this->ref;
203 /**************************************************************************
204 * IShellFolder_ParseDisplayName
205 * PARAMETERS
206 * HWND hwndOwner, //[in ] Parent window for any message's
207 * LPBC pbc, //[in ] reserved
208 * LPOLESTR lpszDisplayName,//[in ] "Unicode" displayname.
209 * ULONG* pchEaten, //[out] (unicode) characters processed
210 * LPITEMIDLIST* ppidl, //[out] complex pidl to item
211 * ULONG* pdwAttributes //[out] items attributes
213 * FIXME:
214 * pdwAttributes: not used
216 static HRESULT WINAPI IShellFolder_ParseDisplayName(
217 LPSHELLFOLDER this,
218 HWND32 hwndOwner,
219 LPBC pbcReserved,
220 LPOLESTR32 lpszDisplayName,
221 DWORD *pchEaten,
222 LPITEMIDLIST *ppidl,
223 DWORD *pdwAttributes)
224 { HRESULT hr=E_OUTOFMEMORY;
225 LPITEMIDLIST pidlFull=NULL, pidlTemp = NULL, pidlOld = NULL;
226 LPSTR pszTemp, pszNext=NULL;
227 CHAR szElement[MAX_PATH];
228 BOOL32 bType;
229 DWORD dwChars;
231 TRACE(shell,"(%p)->(HWND=0x%08x,%p,%p=%s,%p,pidl=%p,%p)\n",
232 this,hwndOwner,pbcReserved,lpszDisplayName,
233 debugstr_w(lpszDisplayName),pchEaten,ppidl,pdwAttributes);
235 dwChars=lstrlen32W(lpszDisplayName) + 1;
236 pszTemp=(LPSTR)HeapAlloc(GetProcessHeap(),0,dwChars);
238 if(pszTemp)
239 { hr = E_FAIL;
240 WideCharToLocal32(pszTemp, lpszDisplayName, dwChars);
241 if(*pszTemp)
242 { if (strcmp(pszTemp,"Desktop")==0)
243 { pidlFull = (LPITEMIDLIST)HeapAlloc(GetProcessHeap(),0,2);
244 pidlFull->mkid.cb = 0;
246 else if (strcmp(pszTemp,"My Computer")==0)
247 { pidlFull = _ILCreateMyComputer();
249 else
250 { pidlFull = _ILCreateMyComputer();
252 /* check if the lpszDisplayName is Folder or File*/
253 bType = ! (GetFileAttributes32A(pszNext) & FILE_ATTRIBUTE_DIRECTORY);
254 pszNext = GetNextElement(pszTemp, szElement, MAX_PATH);
256 pidlTemp = _ILCreateDrive(szElement);
257 pidlOld = pidlFull;
258 pidlFull = ILCombine(pidlFull,pidlTemp);
259 SHFree(pidlOld);
261 if(pidlFull)
262 { while((pszNext=GetNextElement(pszNext, szElement, MAX_PATH)))
263 { if(!*pszNext && bType)
264 { pidlTemp = _ILCreateValue(szElement);
266 else
267 { pidlTemp = _ILCreateFolder(szElement);
269 pidlOld = pidlFull;
270 pidlFull = ILCombine(pidlFull,pidlTemp);
271 SHFree(pidlOld);
273 hr = S_OK;
278 HeapFree(GetProcessHeap(),0,pszTemp);
279 *ppidl = pidlFull;
280 return hr;
283 /**************************************************************************
284 * IShellFolder_EnumObjects
285 * PARAMETERS
286 * HWND hwndOwner, //[in ] Parent Window
287 * DWORD grfFlags, //[in ] SHCONTF enumeration mask
288 * LPENUMIDLIST* ppenumIDList //[out] IEnumIDList interface
290 static HRESULT WINAPI IShellFolder_EnumObjects(
291 LPSHELLFOLDER this,
292 HWND32 hwndOwner,
293 DWORD dwFlags,
294 LPENUMIDLIST* ppEnumIDList)
295 { TRACE(shell,"(%p)->(HWND=0x%08x flags=0x%08lx pplist=%p)\n",this,hwndOwner,dwFlags,ppEnumIDList);
297 *ppEnumIDList = NULL;
298 *ppEnumIDList = IEnumIDList_Constructor (this->sMyPath, dwFlags);
299 TRACE(shell,"-- (%p)->(new ID List: %p)\n",this,*ppEnumIDList);
300 if(!*ppEnumIDList)
301 { return E_OUTOFMEMORY;
303 return S_OK;
305 /**************************************************************************
306 * IShellFolder_Initialize()
307 * IPersistFolder Method
309 static HRESULT WINAPI IShellFolder_Initialize( LPSHELLFOLDER this,LPCITEMIDLIST pidl)
310 { TRACE(shell,"(%p)->(pidl=%p)\n",this,pidl);
312 if(this->pMyPidl)
313 { SHFree(this->pMyPidl);
314 this->pMyPidl = NULL;
316 this->pMyPidl = ILClone(pidl);
317 return S_OK;
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*
328 static HRESULT WINAPI IShellFolder_BindToObject( LPSHELLFOLDER this, LPCITEMIDLIST pidl,
329 LPBC pbcReserved, REFIID riid, LPVOID * ppvOut)
330 { char xriid[50];
331 HRESULT hr;
332 LPSHELLFOLDER pShellFolder;
334 WINE_StringFromCLSID(riid,xriid);
336 TRACE(shell,"(%p)->(pidl=%p,%p,\n\tIID:%s,%p)\n",this,pidl,pbcReserved,xriid,ppvOut);
338 *ppvOut = NULL;
340 pShellFolder = IShellFolder_Constructor(this, pidl);
342 if(!pShellFolder)
343 return E_OUTOFMEMORY;
345 IShellFolder_Initialize(pShellFolder, this->pMyPidl);
347 hr = pShellFolder->lpvtbl->fnQueryInterface(pShellFolder, riid, ppvOut);
348 pShellFolder->lpvtbl->fnRelease(pShellFolder);
349 TRACE(shell,"-- (%p)->(interface=%p)\n",this, ppvOut);
350 return hr;
353 /**************************************************************************
354 * IShellFolder_BindToStorage
355 * PARAMETERS
356 * LPCITEMIDLIST pidl, //[in ] complex pidl to store
357 * LPBC pbc, //[in ] reserved
358 * REFIID riid, //[in ] Initial storage interface
359 * LPVOID* ppvObject //[out] Interface* returned
361 static HRESULT WINAPI IShellFolder_BindToStorage(
362 LPSHELLFOLDER this,
363 LPCITEMIDLIST pidl, /*simple/complex pidl*/
364 LPBC pbcReserved,
365 REFIID riid,
366 LPVOID *ppvOut)
367 { char xriid[50];
368 WINE_StringFromCLSID(riid,xriid);
370 FIXME(shell,"(%p)->(pidl=%p,%p,\n\tIID:%s,%p) stub\n",this,pidl,pbcReserved,xriid,ppvOut);
372 *ppvOut = NULL;
373 return E_NOTIMPL;
376 /**************************************************************************
377 * IShellFolder_CompareIDs
379 * PARMETERS
380 * LPARAM lParam, //[in ] Column?
381 * LPCITEMIDLIST pidl1, //[in ] simple pidl
382 * LPCITEMIDLIST pidl2) //[in ] simple pidl
384 * NOTES
385 * Special case - If one of the items is a Path and the other is a File,
386 * always make the Path come before the File.
388 * FIXME
389 * we have to handle simple pidl's only (?)
391 static HRESULT WINAPI IShellFolder_CompareIDs(LPSHELLFOLDER this,
392 LPARAM lParam, LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
393 { CHAR szString1[MAX_PATH] = "";
394 CHAR szString2[MAX_PATH] = "";
395 int nReturn;
396 LPCITEMIDLIST pidlTemp1 = pidl1, pidlTemp2 = pidl2;
398 TRACE(shell,"(%p)->(0x%08lx,pidl1=%p,pidl2=%p)\n",this,lParam,pidl1,pidl2);
399 pdump (pidl1);
400 pdump (pidl2);
402 if (!pidl1 && !pidl2)
403 return 0;
404 if (!pidl1) /* Desktop < anything */
405 return -1;
406 if (!pidl2)
407 return 1;
409 /* get the last item in each list */
410 while((ILGetNext(pidlTemp1))->mkid.cb)
411 pidlTemp1 = ILGetNext(pidlTemp1);
412 while((ILGetNext(pidlTemp2))->mkid.cb)
413 pidlTemp2 = ILGetNext(pidlTemp2);
415 /* at this point, both pidlTemp1 and pidlTemp2 point to the last item in the list */
416 if(_ILIsValue(pidlTemp1) != _ILIsValue(pidlTemp2))
417 { if(_ILIsValue(pidlTemp1))
418 return 1;
419 return -1;
422 _ILGetDrive( pidl1,szString1,sizeof(szString1));
423 _ILGetDrive( pidl2,szString1,sizeof(szString2));
424 nReturn = strcasecmp(szString1, szString2);
426 if(nReturn)
427 return nReturn;
429 _ILGetFolderText( pidl1,szString1,sizeof(szString1));
430 _ILGetFolderText( pidl2,szString2,sizeof(szString2));
431 nReturn = strcasecmp(szString1, szString2);
433 if(nReturn)
434 return nReturn;
436 _ILGetValueText(pidl1,szString1,sizeof(szString1));
437 _ILGetValueText(pidl2,szString2,sizeof(szString2));
438 return strcasecmp(szString1, szString2);
441 /**************************************************************************
442 * IShellFolder_CreateViewObject
443 * Creates an View Object representing the ShellFolder
444 * IShellView / IShellBrowser / IContextMenu
446 * PARAMETERS
447 * HWND hwndOwner, // Handle of owner window
448 * REFIID riid, // Requested initial interface
449 * LPVOID* ppvObject) // Resultant interface*
451 * NOTES
452 * the same as SHCreateShellFolderViewEx ???
454 static HRESULT WINAPI IShellFolder_CreateViewObject( LPSHELLFOLDER this,
455 HWND32 hwndOwner, REFIID riid, LPVOID *ppvOut)
456 { LPSHELLVIEW pShellView;
457 char xriid[50];
458 HRESULT hr;
460 WINE_StringFromCLSID(riid,xriid);
461 TRACE(shell,"(%p)->(hwnd=0x%x,\n\tIID:\t%s,%p)\n",this,hwndOwner,xriid,ppvOut);
463 *ppvOut = NULL;
465 pShellView = IShellView_Constructor(this, this->mpidl);
466 if(!pShellView)
467 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;
621 /* test if simple(relative) or complex(absolute) pidl */
622 pidlTemp = ILGetNext(pidl);
623 if (pidlTemp && pidlTemp->mkid.cb==0x00)
624 { bSimplePidl = TRUE;
625 TRACE(shell,"-- simple pidl\n");
627 if (_ILIsDesktop( pidl))
628 { strcpy (szText,"Desktop");
630 else
631 { if (_ILIsMyComputer( pidl))
632 { _ILGetItemText( pidl, szSpecial, MAX_PATH);
634 if (_ILIsDrive( pidl))
635 { pidlTemp = ILFindLastID(pidl);
636 if (pidlTemp)
637 { _ILGetItemText( pidlTemp, szTemp, MAX_PATH);
639 if ( dwFlags==SHGDN_NORMAL || dwFlags==SHGDN_INFOLDER)
640 { GetVolumeInformation32A(szTemp,szDrive,MAX_PATH,&dwVolumeSerialNumber,&dwMaximumComponetLength,&dwFileSystemFlags,NULL,0);
641 if (szTemp[2]=='\\')
642 { szTemp[2]=0x00;
644 strcat (szDrive," (");
645 strcat (szDrive,szTemp);
646 strcat (szDrive,")");
648 else
649 { PathAddBackslash32A (szTemp);
650 strcpy(szDrive,szTemp);
654 switch(dwFlags)
655 { case SHGDN_NORMAL:
656 _ILGetPidlPath( pidl, szText, MAX_PATH);
657 break;
659 case SHGDN_INFOLDER | SHGDN_FORPARSING: /*fall thru*/
660 case SHGDN_INFOLDER:
661 pidlTemp = ILFindLastID(pidl);
662 if (pidlTemp)
663 { _ILGetItemText( pidlTemp, szText, MAX_PATH);
665 break;
667 case SHGDN_FORPARSING:
668 if (bSimplePidl)
669 { /* if the IShellFolder has parents, get the path from the
670 parent and add the ItemName*/
671 szText[0]=0x00;
672 if (this->sMyPath && strlen (this->sMyPath))
673 { if (strcmp(this->sMyPath,"My Computer"))
674 { strcpy (szText,this->sMyPath);
675 PathAddBackslash32A (szText);
678 pidlTemp = ILFindLastID(pidl);
679 if (pidlTemp)
680 { _ILGetItemText( pidlTemp, szTemp, MAX_PATH );
682 strcat(szText,szTemp);
684 else
685 { /* if the pidl is absolute, get everything from the pidl*/
686 _ILGetPidlPath( pidl, szText, MAX_PATH);
688 break;
689 default:
690 TRACE(shell,"--- wrong flags=%lx\n", dwFlags);
691 return E_INVALIDARG;
693 if ((szText[0]==0x00 && szDrive[0]!=0x00)|| (bSimplePidl && szDrive[0]!=0x00))
694 { strcpy(szText,szDrive);
696 if (szText[0]==0x00 && szSpecial[0]!=0x00)
697 { strcpy(szText,szSpecial);
701 TRACE(shell,"-- (%p)->(%s)\n",this,szText);
703 if(!(lpName))
704 { return E_OUTOFMEMORY;
706 lpName->uType = STRRET_CSTRA;
707 strcpy(lpName->u.cStr,szText);
708 return S_OK;
711 /**************************************************************************
712 * IShellFolder_SetNameOf
713 * Changes the name of a file object or subfolder, possibly changing its item
714 * identifier in the process.
716 * PARAMETERS
717 * HWND hwndOwner, //[in ] Owner window for output
718 * LPCITEMIDLIST pidl, //[in ] simple pidl of item to change
719 * LPCOLESTR lpszName, //[in ] the items new display name
720 * DWORD dwFlags, //[in ] SHGNO formatting flags
721 * LPITEMIDLIST* ppidlOut) //[out] simple pidl returned
723 static HRESULT WINAPI IShellFolder_SetNameOf(
724 LPSHELLFOLDER this,
725 HWND32 hwndOwner,
726 LPCITEMIDLIST pidl, /*simple pidl*/
727 LPCOLESTR32 lpName,
728 DWORD dw,
729 LPITEMIDLIST *pPidlOut)
730 { FIXME(shell,"(%p)->(%u,pidl=%p,%s,%lu,%p),stub!\n",
731 this,hwndOwner,pidl,debugstr_w(lpName),dw,pPidlOut);
732 return E_NOTIMPL;
734 /**************************************************************************
735 * IShellFolder_GetFolderPath
736 * FIXME: drive not included
738 static BOOL32 WINAPI IShellFolder_GetFolderPath(LPSHELLFOLDER this, LPSTR lpszOut, DWORD dwOutSize)
739 { DWORD dwSize;
741 TRACE(shell,"(%p)->(%p %lu)\n",this, lpszOut, dwOutSize);
742 if (!lpszOut)
743 { return FALSE;
746 *lpszOut=0;
748 if (! this->sMyPath)
749 return FALSE;
751 dwSize = strlen (this->sMyPath) +1;
752 if ( dwSize > dwOutSize)
753 return FALSE;
754 strcpy(lpszOut, this->sMyPath);
756 TRACE(shell,"-- (%p)->(return=%s)\n",this, lpszOut);
757 return TRUE;