Improved a bit the folder browsing implementation.
[wine.git] / dlls / shell32 / folders.c
blob5bf89ebac966bbb2eb7cbea6c6b73c39070e4f7f
1 /*
2 * Copyright 1997 Marcus Meissner
3 * Copyright 1998 Juergen Schmied
5 */
7 #include <stdlib.h>
8 #include <stdio.h>
9 #include <string.h>
11 #include "wine/obj_base.h"
12 #include "wine/obj_extracticon.h"
13 #include "wine/undocshell.h"
14 #include "shlguid.h"
16 #include "debugtools.h"
17 #include "winerror.h"
19 #include "pidl.h"
20 #include "shell32_main.h"
22 DEFAULT_DEBUG_CHANNEL(shell)
25 /***********************************************************************
26 * IExtractIconA implementation
29 typedef struct
30 { ICOM_VFIELD(IExtractIconA);
31 DWORD ref;
32 ICOM_VTABLE(IPersistFile)* lpvtblPersistFile;
33 LPITEMIDLIST pidl;
34 } IExtractIconAImpl;
36 static struct ICOM_VTABLE(IExtractIconA) eivt;
37 static struct ICOM_VTABLE(IPersistFile) pfvt;
39 #define _IPersistFile_Offset ((int)(&(((IExtractIconAImpl*)0)->lpvtblPersistFile)))
40 #define _ICOM_THIS_From_IPersistFile(class, name) class* This = (class*)(((char*)name)-_IPersistFile_Offset);
42 /**************************************************************************
43 * IExtractIconA_Constructor
45 IExtractIconA* IExtractIconA_Constructor(LPCITEMIDLIST pidl)
47 IExtractIconAImpl* ei;
49 ei=(IExtractIconAImpl*)HeapAlloc(GetProcessHeap(),0,sizeof(IExtractIconAImpl));
50 ei->ref=1;
51 ICOM_VTBL(ei) = &eivt;
52 ei->lpvtblPersistFile = &pfvt;
53 ei->pidl=ILClone(pidl);
55 pdump(pidl);
57 TRACE("(%p)\n",ei);
58 shell32_ObjCount++;
59 return (IExtractIconA *)ei;
61 /**************************************************************************
62 * IExtractIconA_QueryInterface
64 static HRESULT WINAPI IExtractIconA_fnQueryInterface( IExtractIconA * iface, REFIID riid, LPVOID *ppvObj)
66 ICOM_THIS(IExtractIconAImpl,iface);
68 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
70 *ppvObj = NULL;
72 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
73 { *ppvObj = This;
75 else if(IsEqualIID(riid, &IID_IPersistFile)) /*IExtractIcon*/
76 { *ppvObj = (IPersistFile*)&(This->lpvtblPersistFile);
78 else if(IsEqualIID(riid, &IID_IExtractIconA)) /*IExtractIcon*/
79 { *ppvObj = (IExtractIconA*)This;
82 if(*ppvObj)
83 { IExtractIconA_AddRef((IExtractIconA*) *ppvObj);
84 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
85 return S_OK;
87 TRACE("-- Interface: E_NOINTERFACE\n");
88 return E_NOINTERFACE;
91 /**************************************************************************
92 * IExtractIconA_AddRef
94 static ULONG WINAPI IExtractIconA_fnAddRef(IExtractIconA * iface)
96 ICOM_THIS(IExtractIconAImpl,iface);
98 TRACE("(%p)->(count=%lu)\n",This, This->ref );
100 shell32_ObjCount++;
102 return ++(This->ref);
104 /**************************************************************************
105 * IExtractIconA_Release
107 static ULONG WINAPI IExtractIconA_fnRelease(IExtractIconA * iface)
109 ICOM_THIS(IExtractIconAImpl,iface);
111 TRACE("(%p)->()\n",This);
113 shell32_ObjCount--;
115 if (!--(This->ref))
116 { TRACE(" destroying IExtractIcon(%p)\n",This);
117 SHFree(This->pidl);
118 HeapFree(GetProcessHeap(),0,This);
119 return 0;
121 return This->ref;
123 /**************************************************************************
124 * IExtractIconA_GetIconLocation
126 * mapping filetype to icon
128 static HRESULT WINAPI IExtractIconA_fnGetIconLocation(
129 IExtractIconA * iface,
130 UINT uFlags,
131 LPSTR szIconFile,
132 UINT cchMax,
133 int * piIndex,
134 UINT * pwFlags)
136 ICOM_THIS(IExtractIconAImpl,iface);
138 char sTemp[MAX_PATH];
139 DWORD dwNr;
140 GUID const * riid;
141 LPITEMIDLIST pSimplePidl = ILFindLastID(This->pidl);
143 TRACE("(%p) (flags=%u %p %u %p %p)\n", This, uFlags, szIconFile, cchMax, piIndex, pwFlags);
145 if (pwFlags)
146 *pwFlags = 0;
148 if (_ILIsDesktop(pSimplePidl))
150 lstrcpynA(szIconFile, "shell32.dll", cchMax);
151 *piIndex = 34;
154 /* my computer and other shell extensions */
155 else if ( (riid = _ILGetGUIDPointer(pSimplePidl)) )
157 char xriid[50];
158 sprintf( xriid, "CLSID\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
159 riid->Data1, riid->Data2, riid->Data3,
160 riid->Data4[0], riid->Data4[1], riid->Data4[2], riid->Data4[3],
161 riid->Data4[4], riid->Data4[5], riid->Data4[6], riid->Data4[7] );
163 if (HCR_GetDefaultIcon(xriid, sTemp, MAX_PATH, &dwNr))
165 lstrcpynA(szIconFile, sTemp, cchMax);
166 *piIndex = dwNr;
168 else
170 lstrcpynA(szIconFile, "shell32.dll", cchMax);
171 *piIndex = 15;
175 else if (_ILIsDrive (pSimplePidl))
177 if (HCR_GetDefaultIcon("Drive", sTemp, MAX_PATH, &dwNr))
179 lstrcpynA(szIconFile, sTemp, cchMax);
180 *piIndex = dwNr;
182 else
184 lstrcpynA(szIconFile, "shell32.dll", cchMax);
185 *piIndex = 8;
188 else if (_ILIsFolder (pSimplePidl))
190 if (HCR_GetDefaultIcon("Folder", sTemp, MAX_PATH, &dwNr))
192 lstrcpynA(szIconFile, sTemp, cchMax);
193 *piIndex = dwNr;
195 else
197 lstrcpynA(szIconFile, "shell32.dll", cchMax);
198 *piIndex = (uFlags & GIL_OPENICON)? 4 : 3;
201 else /* object is file */
203 if (_ILGetExtension (pSimplePidl, sTemp, MAX_PATH)
204 && HCR_MapTypeToValue(sTemp, sTemp, MAX_PATH, TRUE)
205 && HCR_GetDefaultIcon(sTemp, sTemp, MAX_PATH, &dwNr))
207 if (!strcmp("%1",sTemp)) /* icon is in the file */
209 SHGetPathFromIDListA(This->pidl, sTemp);
210 dwNr = 0;
212 lstrcpynA(szIconFile, sTemp, cchMax);
213 *piIndex = dwNr;
215 else /* default icon */
217 lstrcpynA(szIconFile, "shell32.dll", cchMax);
218 *piIndex = 0;
222 TRACE("-- %s %x\n", szIconFile, *piIndex);
223 return NOERROR;
225 /**************************************************************************
226 * IExtractIconA_Extract
228 static HRESULT WINAPI IExtractIconA_fnExtract(IExtractIconA * iface, LPCSTR pszFile, UINT nIconIndex, HICON *phiconLarge, HICON *phiconSmall, UINT nIconSize)
230 ICOM_THIS(IExtractIconAImpl,iface);
232 FIXME("(%p) (file=%p index=%u %p %p size=%u) semi-stub\n", This, pszFile, nIconIndex, phiconLarge, phiconSmall, nIconSize);
234 if (phiconLarge)
235 *phiconLarge = pImageList_GetIcon(ShellBigIconList, nIconIndex, ILD_TRANSPARENT);
237 if (phiconSmall)
238 *phiconSmall = pImageList_GetIcon(ShellSmallIconList, nIconIndex, ILD_TRANSPARENT);
240 return S_OK;
243 static struct ICOM_VTABLE(IExtractIconA) eivt =
245 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
246 IExtractIconA_fnQueryInterface,
247 IExtractIconA_fnAddRef,
248 IExtractIconA_fnRelease,
249 IExtractIconA_fnGetIconLocation,
250 IExtractIconA_fnExtract
253 /************************************************************************
254 * IEIPersistFile_QueryInterface (IUnknown)
256 static HRESULT WINAPI IEIPersistFile_fnQueryInterface(
257 IPersistFile *iface,
258 REFIID iid,
259 LPVOID *ppvObj)
261 _ICOM_THIS_From_IPersistFile(IExtractIconA, iface);
263 return IShellFolder_QueryInterface((IExtractIconA*)This, iid, ppvObj);
266 /************************************************************************
267 * IEIPersistFile_AddRef (IUnknown)
269 static ULONG WINAPI IEIPersistFile_fnAddRef(
270 IPersistFile *iface)
272 _ICOM_THIS_From_IPersistFile(IExtractIconA, iface);
274 return IExtractIconA_AddRef((IExtractIconA*)This);
277 /************************************************************************
278 * IEIPersistFile_Release (IUnknown)
280 static ULONG WINAPI IEIPersistFile_fnRelease(
281 IPersistFile *iface)
283 _ICOM_THIS_From_IPersistFile(IExtractIconA, iface);
285 return IExtractIconA_Release((IExtractIconA*)This);
288 /************************************************************************
289 * IEIPersistFile_GetClassID (IPersist)
291 static HRESULT WINAPI IEIPersistFile_fnGetClassID(
292 IPersistFile *iface,
293 LPCLSID lpClassId)
295 CLSID StdFolderID = { 0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} };
297 if (lpClassId==NULL)
298 return E_POINTER;
300 memcpy(lpClassId, &StdFolderID, sizeof(StdFolderID));
302 return S_OK;
305 /************************************************************************
306 * IEIPersistFile_Load (IPersistFile)
308 static HRESULT WINAPI IEIPersistFile_fnLoad(IPersistFile* iface, LPCOLESTR pszFileName, DWORD dwMode)
310 _ICOM_THIS_From_IPersistFile(IExtractIconA, iface);
311 FIXME("%p\n", This);
312 return E_NOTIMPL;
316 static struct ICOM_VTABLE(IPersistFile) pfvt =
318 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
319 IEIPersistFile_fnQueryInterface,
320 IEIPersistFile_fnAddRef,
321 IEIPersistFile_fnRelease,
322 IEIPersistFile_fnGetClassID,
323 (void *) 0xdeadbeef /* IEIPersistFile_fnIsDirty */,
324 IEIPersistFile_fnLoad,
325 (void *) 0xdeadbeef /* IEIPersistFile_fnSave */,
326 (void *) 0xdeadbeef /* IEIPersistFile_fnSaveCompleted */,
327 (void *) 0xdeadbeef /* IEIPersistFile_fnGetCurFile */