4 * Copyright 1997 Marcus Meissner
5 * Copyright 1998 Juergen Schmied
15 #include "wine/obj_base.h"
21 #include "shell32_main.h"
23 static HRESULT WINAPI IShellFolder_QueryInterface(LPSHELLFOLDER,REFIID,LPVOID*);
24 static ULONG WINAPI IShellFolder_AddRef(LPSHELLFOLDER);
25 static ULONG WINAPI IShellFolder_Release(LPSHELLFOLDER);
26 static HRESULT WINAPI IShellFolder_Initialize(LPSHELLFOLDER,LPCITEMIDLIST);
27 static HRESULT WINAPI IShellFolder_ParseDisplayName(LPSHELLFOLDER,HWND32,LPBC,LPOLESTR32,DWORD*,LPITEMIDLIST*,DWORD*);
28 static HRESULT WINAPI IShellFolder_EnumObjects(LPSHELLFOLDER,HWND32,DWORD,LPENUMIDLIST*);
29 static HRESULT WINAPI IShellFolder_BindToObject(LPSHELLFOLDER,LPCITEMIDLIST,LPBC,REFIID,LPVOID*);
30 static HRESULT WINAPI IShellFolder_BindToStorage(LPSHELLFOLDER,LPCITEMIDLIST,LPBC,REFIID,LPVOID*);
31 static HRESULT WINAPI IShellFolder_CompareIDs(LPSHELLFOLDER,LPARAM,LPCITEMIDLIST,LPCITEMIDLIST);
32 static HRESULT WINAPI IShellFolder_CreateViewObject(LPSHELLFOLDER,HWND32,REFIID,LPVOID*);
33 static HRESULT WINAPI IShellFolder_GetAttributesOf(LPSHELLFOLDER,UINT32,LPCITEMIDLIST*,DWORD*);
34 static HRESULT WINAPI IShellFolder_GetUIObjectOf(LPSHELLFOLDER,HWND32,UINT32,LPCITEMIDLIST*,REFIID,UINT32*,LPVOID*);
35 static HRESULT WINAPI IShellFolder_GetDisplayNameOf(LPSHELLFOLDER,LPCITEMIDLIST,DWORD,LPSTRRET);
36 static HRESULT WINAPI IShellFolder_SetNameOf(LPSHELLFOLDER,HWND32,LPCITEMIDLIST,LPCOLESTR32,DWORD,LPITEMIDLIST*);
37 static BOOL32 WINAPI IShellFolder_GetFolderPath(LPSHELLFOLDER,LPSTR,DWORD);
42 /***************************************************************************
43 * IDropTarget interface definition for the ShellFolder
47 * Forward declarations of the structure
49 typedef struct ShellFolderDropTargetImpl ShellFolderDropTargetImpl;
52 * ShellFolderDropTargetImpl definitions.
54 struct ShellFolderDropTargetImpl
56 ICOM_VTABLE(IDropTarget)* lpvtbl; /* Needs to be the first item in the struct
57 * since we want to cast this in a
58 * IDropTarget pointer */
60 * Reference count of this object (IUnknown)
66 * ShellFolderDropTargetImpl prototypes definition
69 ShellFolderDropTargetImpl* WINAPI ShellFolderDropTargetImpl_Constructor();
71 void WINAPI ShellFolderDropTargetImpl_Destroy( /* not static to avoid warning */
72 ShellFolderDropTargetImpl *This);
74 static HRESULT WINAPI ShellFolderDropTargetImpl_QueryInterface(
75 ShellFolderDropTargetImpl *This,
79 static ULONG WINAPI ShellFolderDropTargetImpl_AddRef(
80 ShellFolderDropTargetImpl *This);
82 static ULONG WINAPI ShellFolderDropTargetImpl_Release(
83 ShellFolderDropTargetImpl *This);
85 static HRESULT WINAPI ShellFolderDropTargetImpl_DragEnter(
86 ShellFolderDropTargetImpl *This,
87 IDataObject *pDataObject,
92 static HRESULT WINAPI ShellFolderDropTargetImpl_DragOver(
93 ShellFolderDropTargetImpl *This,
98 static HRESULT WINAPI ShellFolderDropTargetImpl_DragLeave(
99 ShellFolderDropTargetImpl *This);
101 static HRESULT WINAPI ShellFolderDropTargetImpl_Drop(
102 ShellFolderDropTargetImpl *This,
108 * This define allows me to assign a function to a vtable without having the
109 * nasty warning about incompatible types.
111 * This is necessary because of the usage of implementation classes pointers
112 * as the first parameter of the interface functions instead of the pointer
115 #define VTABLE_FUNC(a) ((void*)a)
118 * Virtual function table for the ShellFolderDropTargetImpl class.
120 static ICOM_VTABLE(IDropTarget) ShellFolderDropTargetImpl_VTable =
123 VTABLE_FUNC(ShellFolderDropTargetImpl_QueryInterface),
124 VTABLE_FUNC(ShellFolderDropTargetImpl_AddRef),
125 VTABLE_FUNC(ShellFolderDropTargetImpl_Release)
127 VTABLE_FUNC(ShellFolderDropTargetImpl_DragEnter),
128 VTABLE_FUNC(ShellFolderDropTargetImpl_DragOver),
129 VTABLE_FUNC(ShellFolderDropTargetImpl_DragLeave),
130 VTABLE_FUNC(ShellFolderDropTargetImpl_Drop),
134 /***************************************************************************
135 * GetNextElement (internal function)
137 * gets a part of a string till the first backslash
140 * pszNext [IN] string to get the element from
141 * pszOut [IN] pointer to buffer whitch receives string
142 * dwOut [IN] length of pszOut
145 * LPSTR pointer to first, not yet parsed char
147 LPSTR GetNextElement(LPSTR pszNext,LPSTR pszOut,DWORD dwOut)
148 { LPSTR pszTail = pszNext;
150 TRACE(shell,"(%s %p 0x%08lx)\n",debugstr_a(pszNext),pszOut,dwOut);
152 if(!pszNext || !*pszNext)
155 while(*pszTail && (*pszTail != '\\'))
158 dwCopy=((LPBYTE)pszTail-(LPBYTE)pszNext)/sizeof(CHAR)+1;
159 lstrcpyn32A(pszOut, pszNext, (dwOut<dwCopy)? dwOut : dwCopy);
165 TRACE(shell,"--(%s %s 0x%08lx)\n",debugstr_a(pszNext),debugstr_a(pszOut),dwOut);
169 /***********************************************************************
170 * IShellFolder implementation
172 static struct IShellFolder_VTable sfvt =
173 { IShellFolder_QueryInterface,
175 IShellFolder_Release,
176 IShellFolder_ParseDisplayName,
177 IShellFolder_EnumObjects,
178 IShellFolder_BindToObject,
179 IShellFolder_BindToStorage,
180 IShellFolder_CompareIDs,
181 IShellFolder_CreateViewObject,
182 IShellFolder_GetAttributesOf,
183 IShellFolder_GetUIObjectOf,
184 IShellFolder_GetDisplayNameOf,
185 IShellFolder_SetNameOf,
186 IShellFolder_GetFolderPath
188 /**************************************************************************
189 * IShellFolder_Constructor
192 LPSHELLFOLDER IShellFolder_Constructor(LPSHELLFOLDER pParent,LPITEMIDLIST pidl)
195 sf=(LPSHELLFOLDER)HeapAlloc(GetProcessHeap(),0,sizeof(IShellFolder));
198 sf->sMyPath=NULL; /* path of the folder */
199 sf->pMyPidl=NULL; /* my qualified pidl */
201 TRACE(shell,"(%p)->(parent=%p, pidl=%p)\n",sf,pParent, pidl);
204 /* keep a copy of the pidl in the instance*/
205 sf->mpidl = ILClone(pidl); /* my short pidl */
207 if(sf->mpidl) /* do we have a pidl? */
209 if(pParent->sMyPath) /* get the size of the parents path */
210 { dwSize += strlen(pParent->sMyPath) ;
211 TRACE(shell,"-- (%p)->(parent's path=%s)\n",sf, debugstr_a(pParent->sMyPath));
213 dwSize += _ILGetFolderText(sf->mpidl,NULL,0); /* add the size of the foldername*/
214 sf->sMyPath = SHAlloc(dwSize+2); /* '\0' and backslash */
218 if(pParent->sMyPath) /* if the parent has a path, get it*/
219 { strcpy(sf->sMyPath, pParent->sMyPath);
220 PathAddBackslash32A (sf->sMyPath);
222 sf->pMyPidl = ILCombine(pParent->pMyPidl, pidl);
223 len = strlen(sf->sMyPath);
224 _ILGetFolderText(sf->mpidl, sf->sMyPath+len, dwSize-len);
225 TRACE(shell,"-- (%p)->(my pidl=%p, my path=%s)\n",sf, sf->pMyPidl,debugstr_a(sf->sMyPath));
232 /**************************************************************************
233 * IShellFolder::QueryInterface
235 * REFIID riid, //[in ] Requested InterfaceID
236 * LPVOID* ppvObject) //[out] Interface* to hold the result
238 static HRESULT WINAPI IShellFolder_QueryInterface(
239 LPSHELLFOLDER this, REFIID riid, LPVOID *ppvObj)
241 WINE_StringFromCLSID((LPCLSID)riid,xriid);
242 TRACE(shell,"(%p)->(\n\tIID:\t%s,%p)\n",this,xriid,ppvObj);
246 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
249 else if(IsEqualIID(riid, &IID_IShellFolder)) /*IShellFolder*/
250 { *ppvObj = (IShellFolder*)this;
254 { (*(LPSHELLFOLDER*)ppvObj)->lpvtbl->fnAddRef(this);
255 TRACE(shell,"-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
258 TRACE(shell,"-- Interface: E_NOINTERFACE\n");
259 return E_NOINTERFACE;
262 /**************************************************************************
263 * IShellFolder::AddRef
266 static ULONG WINAPI IShellFolder_AddRef(LPSHELLFOLDER this)
267 { TRACE(shell,"(%p)->(count=%lu)\n",this,this->ref);
269 return ++(this->ref);
272 /**************************************************************************
273 * IShellFolder_Release
275 static ULONG WINAPI IShellFolder_Release(LPSHELLFOLDER this)
276 { TRACE(shell,"(%p)->(count=%lu)\n",this,this->ref);
280 { TRACE(shell,"-- destroying IShellFolder(%p)\n",this);
282 if (pdesktopfolder==this)
283 { pdesktopfolder=NULL;
284 TRACE(shell,"-- destroyed IShellFolder(%p) was Desktopfolder\n",this);
287 { SHFree(this->pMyPidl);
290 { SHFree(this->mpidl);
293 { SHFree(this->sMyPath);
296 HeapFree(GetProcessHeap(),0,this);
302 /**************************************************************************
303 * IShellFolder_ParseDisplayName
305 * HWND hwndOwner, //[in ] Parent window for any message's
306 * LPBC pbc, //[in ] reserved
307 * LPOLESTR lpszDisplayName,//[in ] "Unicode" displayname.
308 * ULONG* pchEaten, //[out] (unicode) characters processed
309 * LPITEMIDLIST* ppidl, //[out] complex pidl to item
310 * ULONG* pdwAttributes //[out] items attributes
313 * pdwAttributes: not used
315 static HRESULT WINAPI IShellFolder_ParseDisplayName(
319 LPOLESTR32 lpszDisplayName,
322 DWORD *pdwAttributes)
323 { HRESULT hr=E_OUTOFMEMORY;
324 LPITEMIDLIST pidlFull=NULL, pidlTemp = NULL, pidlOld = NULL;
326 CHAR szTemp[MAX_PATH],szElement[MAX_PATH];
329 TRACE(shell,"(%p)->(HWND=0x%08x,%p,%p=%s,%p,pidl=%p,%p)\n",
330 this,hwndOwner,pbcReserved,lpszDisplayName,
331 debugstr_w(lpszDisplayName),pchEaten,ppidl,pdwAttributes);
334 WideCharToLocal32(szTemp, lpszDisplayName, lstrlen32W(lpszDisplayName) + 1);
336 { if (strcmp(szTemp,"Desktop")==0)
337 { pidlFull = _ILCreateDesktop();
339 else if (strcmp(szTemp,"My Computer")==0)
340 { pidlFull = _ILCreateMyComputer();
343 { if (!PathIsRoot32A(szTemp))
344 { if (this->sMyPath && strlen (this->sMyPath))
345 { if (strcmp(this->sMyPath,"My Computer"))
346 { strcpy (szElement,this->sMyPath);
347 PathAddBackslash32A (szElement);
348 strcat (szElement, szTemp);
349 strcpy (szTemp, szElement);
354 /* check if the lpszDisplayName is Folder or File*/
355 bIsFile = ! (GetFileAttributes32A(szTemp) & FILE_ATTRIBUTE_DIRECTORY);
356 pszNext = GetNextElement(szTemp, szElement, MAX_PATH);
358 pidlFull = _ILCreateMyComputer();
359 pidlTemp = _ILCreateDrive(szElement);
361 pidlFull = ILCombine(pidlFull,pidlTemp);
365 { while((pszNext=GetNextElement(pszNext, szElement, MAX_PATH)))
366 { if(!*pszNext && bIsFile)
367 { pidlTemp = _ILCreateValue(szElement);
370 { pidlTemp = _ILCreateFolder(szElement);
373 pidlFull = ILCombine(pidlFull,pidlTemp);
385 /**************************************************************************
386 * IShellFolder_EnumObjects
388 * HWND hwndOwner, //[in ] Parent Window
389 * DWORD grfFlags, //[in ] SHCONTF enumeration mask
390 * LPENUMIDLIST* ppenumIDList //[out] IEnumIDList interface
392 static HRESULT WINAPI IShellFolder_EnumObjects(
396 LPENUMIDLIST* ppEnumIDList)
397 { TRACE(shell,"(%p)->(HWND=0x%08x flags=0x%08lx pplist=%p)\n",this,hwndOwner,dwFlags,ppEnumIDList);
399 *ppEnumIDList = NULL;
400 *ppEnumIDList = IEnumIDList_Constructor (this->sMyPath, dwFlags);
401 TRACE(shell,"-- (%p)->(new ID List: %p)\n",this,*ppEnumIDList);
403 { return E_OUTOFMEMORY;
407 /**************************************************************************
408 * IShellFolder_Initialize()
409 * IPersistFolder Method
411 static HRESULT WINAPI IShellFolder_Initialize( LPSHELLFOLDER this,LPCITEMIDLIST pidl)
412 { TRACE(shell,"(%p)->(pidl=%p)\n",this,pidl);
415 { SHFree(this->pMyPidl);
416 this->pMyPidl = NULL;
418 this->pMyPidl = ILClone(pidl);
422 /**************************************************************************
423 * IShellFolder_BindToObject
425 * LPCITEMIDLIST pidl, //[in ] complex pidl to open
426 * LPBC pbc, //[in ] reserved
427 * REFIID riid, //[in ] Initial Interface
428 * LPVOID* ppvObject //[out] Interface*
430 static HRESULT WINAPI IShellFolder_BindToObject( LPSHELLFOLDER this, LPCITEMIDLIST pidl,
431 LPBC pbcReserved, REFIID riid, LPVOID * ppvOut)
434 LPSHELLFOLDER pShellFolder;
436 WINE_StringFromCLSID(riid,xriid);
438 TRACE(shell,"(%p)->(pidl=%p,%p,\n\tIID:%s,%p)\n",this,pidl,pbcReserved,xriid,ppvOut);
442 pShellFolder = IShellFolder_Constructor(this, pidl);
445 return E_OUTOFMEMORY;
447 hr = pShellFolder->lpvtbl->fnQueryInterface(pShellFolder, riid, ppvOut);
448 pShellFolder->lpvtbl->fnRelease(pShellFolder);
449 TRACE(shell,"-- (%p)->(interface=%p)\n",this, ppvOut);
453 /**************************************************************************
454 * IShellFolder_BindToStorage
456 * LPCITEMIDLIST pidl, //[in ] complex pidl to store
457 * LPBC pbc, //[in ] reserved
458 * REFIID riid, //[in ] Initial storage interface
459 * LPVOID* ppvObject //[out] Interface* returned
461 static HRESULT WINAPI IShellFolder_BindToStorage(LPSHELLFOLDER this,
462 LPCITEMIDLIST pidl,LPBC pbcReserved, REFIID riid, LPVOID *ppvOut)
464 WINE_StringFromCLSID(riid,xriid);
466 FIXME(shell,"(%p)->(pidl=%p,%p,\n\tIID:%s,%p) stub\n",this,pidl,pbcReserved,xriid,ppvOut);
472 /**************************************************************************
473 * IShellFolder_CompareIDs
476 * LPARAM lParam, //[in ] Column?
477 * LPCITEMIDLIST pidl1, //[in ] simple pidl
478 * LPCITEMIDLIST pidl2) //[in ] simple pidl
481 * Special case - If one of the items is a Path and the other is a File,
482 * always make the Path come before the File.
485 * we have to handle simple pidl's only (?)
487 static HRESULT WINAPI IShellFolder_CompareIDs(LPSHELLFOLDER this,
488 LPARAM lParam, LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
489 { CHAR szString1[MAX_PATH] = "";
490 CHAR szString2[MAX_PATH] = "";
492 LPCITEMIDLIST pidlTemp1 = pidl1, pidlTemp2 = pidl2;
494 TRACE(shell,"(%p)->(0x%08lx,pidl1=%p,pidl2=%p)\n",this,lParam,pidl1,pidl2);
498 if (!pidl1 && !pidl2)
500 if (!pidl1) /* Desktop < anything */
505 /* get the last item in each list */
506 while((ILGetNext(pidlTemp1))->mkid.cb)
507 pidlTemp1 = ILGetNext(pidlTemp1);
508 while((ILGetNext(pidlTemp2))->mkid.cb)
509 pidlTemp2 = ILGetNext(pidlTemp2);
511 /* at this point, both pidlTemp1 and pidlTemp2 point to the last item in the list */
512 if(_ILIsValue(pidlTemp1) != _ILIsValue(pidlTemp2))
513 { if(_ILIsValue(pidlTemp1))
518 _ILGetDrive( pidl1,szString1,sizeof(szString1));
519 _ILGetDrive( pidl2,szString1,sizeof(szString2));
520 nReturn = strcasecmp(szString1, szString2);
525 _ILGetFolderText( pidl1,szString1,sizeof(szString1));
526 _ILGetFolderText( pidl2,szString2,sizeof(szString2));
527 nReturn = strcasecmp(szString1, szString2);
532 _ILGetValueText(pidl1,szString1,sizeof(szString1));
533 _ILGetValueText(pidl2,szString2,sizeof(szString2));
534 return strcasecmp(szString1, szString2);
537 /**************************************************************************
538 * IShellFolder_CreateViewObject
539 * Creates an View Object representing the ShellFolder
540 * IShellView / IShellBrowser / IContextMenu
543 * HWND hwndOwner, // Handle of owner window
544 * REFIID riid, // Requested initial interface
545 * LPVOID* ppvObject) // Resultant interface*
548 * the same as SHCreateShellFolderViewEx ???
550 static HRESULT WINAPI IShellFolder_CreateViewObject( LPSHELLFOLDER this,
551 HWND32 hwndOwner, REFIID riid, LPVOID *ppvOut)
552 { LPSHELLVIEW pShellView;
556 WINE_StringFromCLSID(riid,xriid);
557 TRACE(shell,"(%p)->(hwnd=0x%x,\n\tIID:\t%s,%p)\n",this,hwndOwner,xriid,ppvOut);
561 pShellView = IShellView_Constructor(this, this->mpidl);
564 return E_OUTOFMEMORY;
566 hr = pShellView->lpvtbl->fnQueryInterface(pShellView, riid, ppvOut);
567 pShellView->lpvtbl->fnRelease(pShellView);
568 TRACE(shell,"-- (%p)->(interface=%p)\n",this, ppvOut);
572 /**************************************************************************
573 * IShellFolder_GetAttributesOf
576 * UINT cidl, //[in ] num elements in pidl array
577 + LPCITEMIDLIST* apidl, //[in ] simple pidl array
578 * ULONG* rgfInOut) //[out] result array
581 * Note: rgfInOut is documented as being an array of ULONGS.
582 * This does not seem to be the case. Testing this function using the shell to
583 * call it with cidl > 1 (by deleting multiple items) reveals that the shell
584 * passes ONE element in the array and writing to further elements will
585 * cause the shell to fail later.
587 static HRESULT WINAPI IShellFolder_GetAttributesOf(LPSHELLFOLDER this,UINT32 cidl,LPCITEMIDLIST *apidl,DWORD *rgfInOut)
588 { LPCITEMIDLIST * pidltemp;
591 TRACE(shell,"(%p)->(%d,%p,%p)\n",this,cidl,apidl,rgfInOut);
593 if ((! cidl )| (!apidl) | (!rgfInOut))
600 TRACE(shell,"-- mask=0x%08lx\n",*rgfInOut);
605 if (_ILIsDesktop( *pidltemp))
606 { *rgfInOut |= ( SFGAO_HASSUBFOLDER | SFGAO_FOLDER | SFGAO_DROPTARGET | SFGAO_HASPROPSHEET | SFGAO_CANLINK );
608 else if (_ILIsMyComputer( *pidltemp))
609 { *rgfInOut |= ( SFGAO_HASSUBFOLDER | SFGAO_FOLDER | SFGAO_FILESYSANCESTOR
610 | SFGAO_DROPTARGET | SFGAO_HASPROPSHEET | SFGAO_CANRENAME | SFGAO_CANLINK );
612 else if (_ILIsDrive( *pidltemp))
613 { *rgfInOut |= ( SFGAO_HASSUBFOLDER | SFGAO_FILESYSTEM | SFGAO_FOLDER | SFGAO_FILESYSANCESTOR |
614 SFGAO_DROPTARGET | SFGAO_HASPROPSHEET | SFGAO_CANLINK );
616 else if (_ILIsFolder( *pidltemp))
617 { *rgfInOut |= ( SFGAO_HASSUBFOLDER | SFGAO_FILESYSTEM | SFGAO_FOLDER | SFGAO_CAPABILITYMASK );
619 else if (_ILIsValue( *pidltemp))
620 { *rgfInOut |= (SFGAO_FILESYSTEM | SFGAO_CAPABILITYMASK );
625 } while (cidl > 0 && *pidltemp);
629 /**************************************************************************
630 * IShellFolder_GetUIObjectOf
633 * HWND hwndOwner, //[in ] Parent window for any output
634 * UINT cidl, //[in ] array size
635 * LPCITEMIDLIST* apidl, //[in ] simple pidl array
636 * REFIID riid, //[in ] Requested Interface
637 * UINT* prgfInOut, //[ ] reserved
638 * LPVOID* ppvObject) //[out] Resulting Interface
641 * This function gets asked to return "view objects" for one or more (multiple select)
643 * The viewobject typically is an COM object with one of the following interfaces:
644 * IExtractIcon,IDataObject,IContextMenu
645 * In order to support icon positions in the default Listview your DataObject
646 * must implement the SetData method (in addition to GetData :) - the shell passes
647 * a barely documented "Icon positions" structure to SetData when the drag starts,
648 * and GetData's it if the drop is in another explorer window that needs the positions.
650 static HRESULT WINAPI IShellFolder_GetUIObjectOf(
654 LPCITEMIDLIST * apidl,
661 LPUNKNOWN pObj = NULL;
663 WINE_StringFromCLSID(riid,xclsid);
665 TRACE(shell,"(%p)->(%u,%u,apidl=%p,\n\tIID:%s,%p,%p)\n",
666 this,hwndOwner,cidl,apidl,xclsid,prgfInOut,ppvOut);
670 if(IsEqualIID(riid, &IID_IContextMenu))
675 pObj = (LPUNKNOWN)IContextMenu_Constructor(this, apidl, cidl);
677 else if (IsEqualIID(riid, &IID_IDataObject))
680 return(E_INVALIDARG);
682 pObj = (LPUNKNOWN)IDataObject_Constructor (hwndOwner, this, apidl, cidl);
684 else if(IsEqualIID(riid, &IID_IExtractIcon))
687 return(E_INVALIDARG);
689 pidl = ILCombine(this->pMyPidl,apidl[0]);
690 pObj = (LPUNKNOWN)IExtractIcon_Constructor( pidl );
693 else if (IsEqualIID(riid, &IID_IDropTarget))
696 return(E_INVALIDARG);
698 pObj = (LPUNKNOWN)ShellFolderDropTargetImpl_Constructor();
699 ShellFolderDropTargetImpl_AddRef((ShellFolderDropTargetImpl*)pObj);
703 ERR(shell,"(%p)->E_NOINTERFACE\n",this);
704 return E_NOINTERFACE;
708 return E_OUTOFMEMORY;
713 /**************************************************************************
714 * IShellFolder_GetDisplayNameOf
715 * Retrieves the display name for the specified file object or subfolder
718 * LPCITEMIDLIST pidl, //[in ] complex pidl to item
719 * DWORD dwFlags, //[in ] SHGNO formatting flags
720 * LPSTRRET lpName) //[out] Returned display name
723 * if the name is in the pidl the ret value should be a STRRET_OFFSET
725 #define GET_SHGDN_FOR(dwFlags) ((DWORD)dwFlags & (DWORD)0x0000FF00)
726 #define GET_SHGDN_RELATION(dwFlags) ((DWORD)dwFlags & (DWORD)0x000000FF)
728 static HRESULT WINAPI IShellFolder_GetDisplayNameOf( LPSHELLFOLDER this, LPCITEMIDLIST pidl, DWORD dwFlags, LPSTRRET lpName)
729 { CHAR szText[MAX_PATH];
730 CHAR szTemp[MAX_PATH];
731 CHAR szSpecial[MAX_PATH];
732 CHAR szDrive[MAX_PATH];
733 DWORD dwVolumeSerialNumber,dwMaximumComponetLength,dwFileSystemFlags;
734 LPITEMIDLIST pidlTemp=NULL;
735 BOOL32 bSimplePidl=FALSE;
737 TRACE(shell,"(%p)->(pidl=%p,0x%08lx,%p)\n",this,pidl,dwFlags,lpName);
745 /* test if simple(relative) or complex(absolute) pidl */
746 pidlTemp = ILGetNext(pidl);
747 if (pidlTemp && pidlTemp->mkid.cb==0x00)
748 { bSimplePidl = TRUE;
749 TRACE(shell,"-- simple pidl\n");
752 if (_ILIsDesktop( pidl))
753 { strcpy (szText,"Desktop");
756 { if (_ILIsMyComputer(pidl))
757 { _ILGetItemText(pidl, szSpecial, MAX_PATH);
758 pidl = ILGetNext(pidl);
761 if (_ILIsDrive(pidl))
762 { _ILGetDrive( pidl, szTemp, MAX_PATH);
764 if ( dwFlags==SHGDN_NORMAL || dwFlags==SHGDN_INFOLDER) /* like "A1-dos (C:)" */
765 { GetVolumeInformation32A(szTemp,szDrive,MAX_PATH,&dwVolumeSerialNumber,&dwMaximumComponetLength,&dwFileSystemFlags,NULL,0);
766 szTemp[2]=0x00; /* overwrite '\' */
767 strcat (szDrive," (");
768 strcat (szDrive,szTemp);
769 strcat (szDrive,")");
771 else /* like "C:\" */
772 { PathAddBackslash32A (szTemp);
773 strcpy(szDrive,szTemp);
779 { case SHGDN_NORMAL: /* 0x0000 */
780 _ILGetPidlPath( pidl, szText, MAX_PATH);
783 case SHGDN_INFOLDER | SHGDN_FORPARSING: /* 0x8001 */
784 case SHGDN_INFOLDER: /* 0x0001 */
785 pidlTemp = ILFindLastID(pidl);
787 { _ILGetItemText( pidlTemp, szText, MAX_PATH);
791 case SHGDN_FORPARSING: /* 0x8000 */
793 { /* if the IShellFolder has parents, get the path from the
794 parent and add the ItemName*/
796 if (this->sMyPath && strlen (this->sMyPath))
797 { if (strcmp(this->sMyPath,"My Computer"))
798 { strcpy (szText,this->sMyPath);
799 PathAddBackslash32A (szText);
802 pidlTemp = ILFindLastID(pidl);
804 { _ILGetItemText( pidlTemp, szTemp, MAX_PATH );
806 strcat(szText,szTemp);
808 else /* if the pidl is absolute, get everything from the pidl*/
809 { _ILGetPidlPath( pidl, szText, MAX_PATH);
813 TRACE(shell,"--- wrong flags=%lx\n", dwFlags);
816 if ((szText[0]==0x00 && szDrive[0]!=0x00)|| (bSimplePidl && szDrive[0]!=0x00))
817 { strcpy(szText,szDrive);
819 if (szText[0]==0x00 && szSpecial[0]!=0x00)
820 { strcpy(szText,szSpecial);
824 TRACE(shell,"-- (%p)->(%s)\n",this,szText);
827 { return E_OUTOFMEMORY;
829 lpName->uType = STRRET_CSTRA;
830 strcpy(lpName->u.cStr,szText);
834 /**************************************************************************
835 * IShellFolder_SetNameOf
836 * Changes the name of a file object or subfolder, possibly changing its item
837 * identifier in the process.
840 * HWND hwndOwner, //[in ] Owner window for output
841 * LPCITEMIDLIST pidl, //[in ] simple pidl of item to change
842 * LPCOLESTR lpszName, //[in ] the items new display name
843 * DWORD dwFlags, //[in ] SHGNO formatting flags
844 * LPITEMIDLIST* ppidlOut) //[out] simple pidl returned
846 static HRESULT WINAPI IShellFolder_SetNameOf(
849 LPCITEMIDLIST pidl, /*simple pidl*/
852 LPITEMIDLIST *pPidlOut)
853 { FIXME(shell,"(%p)->(%u,pidl=%p,%s,%lu,%p),stub!\n",
854 this,hwndOwner,pidl,debugstr_w(lpName),dw,pPidlOut);
857 /**************************************************************************
858 * IShellFolder_GetFolderPath
859 * FIXME: drive not included
861 static BOOL32 WINAPI IShellFolder_GetFolderPath(LPSHELLFOLDER this, LPSTR lpszOut, DWORD dwOutSize)
864 TRACE(shell,"(%p)->(%p %lu)\n",this, lpszOut, dwOutSize);
874 dwSize = strlen (this->sMyPath) +1;
875 if ( dwSize > dwOutSize)
877 strcpy(lpszOut, this->sMyPath);
879 TRACE(shell,"-- (%p)->(return=%s)\n",this, lpszOut);
884 /****************************************************************************
885 * ShellFolderDropTargetImpl implementation
888 static ShellFolderDropTargetImpl* WINAPI ShellFolderDropTargetImpl_Constructor()
890 ShellFolderDropTargetImpl* newShellFolderDropTarget;
892 newShellFolderDropTarget =
893 HeapAlloc(GetProcessHeap(), 0, sizeof(ShellFolderDropTargetImpl));
895 if (newShellFolderDropTarget!=0)
898 * Set-up the virtual function table and reference count.
900 newShellFolderDropTarget->lpvtbl = &ShellFolderDropTargetImpl_VTable;
901 newShellFolderDropTarget->ref = 0;
904 * We want to nail-down the reference to the storage in case the
905 * enumeration out-lives the storage in the client application.
907 ShellFolderDropTargetImpl_AddRef(newShellFolderDropTarget);
910 return newShellFolderDropTarget;
913 void WINAPI ShellFolderDropTargetImpl_Destroy(
914 ShellFolderDropTargetImpl *This)
916 ShellFolderDropTargetImpl_Release(This);
917 HeapFree(GetProcessHeap(), 0, This);
920 static HRESULT WINAPI ShellFolderDropTargetImpl_QueryInterface(
921 ShellFolderDropTargetImpl *This,
926 * Perform a sanity check on the parameters.
928 if ( (This==0) || (ppvObject==0) )
932 * Initialize the return parameter.
937 * Compare the riid with the interface IDs implemented by this object.
939 if (memcmp(&IID_IUnknown, iid, sizeof(IID_IUnknown)) == 0)
941 *ppvObject = (ShellFolderDropTargetImpl*)This;
943 else if (memcmp(&IID_IDropTarget, iid, sizeof(IID_IDropTarget)) == 0)
945 *ppvObject = (ShellFolderDropTargetImpl*)This;
949 * Check that we obtained an interface.
952 return E_NOINTERFACE;
955 * Query Interface always increases the reference count by one when it is
958 ShellFolderDropTargetImpl_AddRef(This);
963 static ULONG WINAPI ShellFolderDropTargetImpl_AddRef(
964 ShellFolderDropTargetImpl *This)
971 static ULONG WINAPI ShellFolderDropTargetImpl_Release(
972 ShellFolderDropTargetImpl *This)
979 static HRESULT WINAPI ShellFolderDropTargetImpl_DragEnter(
980 ShellFolderDropTargetImpl *This,
981 IDataObject *pDataObject,
986 FIXME(shell, "Stub: This=%p, DataObject=%p\n",This,pDataObject);
990 static HRESULT WINAPI ShellFolderDropTargetImpl_DragOver(
991 ShellFolderDropTargetImpl *This,
996 FIXME(shell, "Stub: This=%p\n",This);
1000 static HRESULT WINAPI ShellFolderDropTargetImpl_DragLeave(
1001 ShellFolderDropTargetImpl *This)
1003 FIXME(shell, "Stub: This=%p\n",This);
1007 static HRESULT WINAPI ShellFolderDropTargetImpl_Drop(
1008 ShellFolderDropTargetImpl *This,
1013 FIXME(shell, "Stub: This=%p\n",This);