Change interfaces to THUNK_Alloc/Free slightly and make them non-static.
[wine/wine64.git] / dlls / shell32 / folders.c
blob1e24e7964f1eafd28458e70a8aab3c5ff8f9bd80
1 /*
2 * Copyright 1997 Marcus Meissner
3 * Copyright 1998 Juergen Schmied
5 */
7 #include <stdlib.h>
8 #include <string.h>
10 #include "wine/obj_base.h"
11 #include "wine/obj_extracticon.h"
12 #include "wine/undocshell.h"
14 #include "debugtools.h"
15 #include "winerror.h"
17 #include "pidl.h"
18 #include "shell32_main.h"
20 DEFAULT_DEBUG_CHANNEL(shell)
23 /***********************************************************************
24 * IExtractIconA implementation
27 typedef struct
28 { ICOM_VTABLE(IExtractIconA)* lpvtbl;
29 DWORD ref;
30 ICOM_VTABLE(IPersistFile)* lpvtblPersistFile;
31 LPITEMIDLIST pidl;
32 } IExtractIconAImpl;
34 static struct ICOM_VTABLE(IExtractIconA) eivt;
35 static struct ICOM_VTABLE(IPersistFile) pfvt;
37 #define _IPersistFile_Offset ((int)(&(((IExtractIconAImpl*)0)->lpvtblPersistFile)))
38 #define _ICOM_THIS_From_IPersistFile(class, name) class* This = (class*)(((char*)name)-_IPersistFile_Offset);
40 /**************************************************************************
41 * IExtractIconA_Constructor
43 IExtractIconA* IExtractIconA_Constructor(LPCITEMIDLIST pidl)
45 IExtractIconAImpl* ei;
47 ei=(IExtractIconAImpl*)HeapAlloc(GetProcessHeap(),0,sizeof(IExtractIconAImpl));
48 ei->ref=1;
49 ei->lpvtbl = &eivt;
50 ei->lpvtblPersistFile = &pfvt;
51 ei->pidl=ILClone(pidl);
53 pdump(pidl);
55 TRACE("(%p)\n",ei);
56 shell32_ObjCount++;
57 return (IExtractIconA *)ei;
59 /**************************************************************************
60 * IExtractIconA_QueryInterface
62 static HRESULT WINAPI IExtractIconA_fnQueryInterface( IExtractIconA * iface, REFIID riid, LPVOID *ppvObj)
64 ICOM_THIS(IExtractIconAImpl,iface);
66 char xriid[50];
67 WINE_StringFromCLSID((LPCLSID)riid,xriid);
68 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,xriid,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 strcpy(xriid,"CLSID\\");
159 WINE_StringFromCLSID((LPCLSID)riid,&xriid[strlen(xriid)]);
161 if (HCR_GetDefaultIcon(xriid, sTemp, MAX_PATH, &dwNr))
163 lstrcpynA(szIconFile, sTemp, cchMax);
164 *piIndex = dwNr;
166 else
168 lstrcpynA(szIconFile, "shell32.dll", cchMax);
169 *piIndex = 15;
173 else if (_ILIsDrive (pSimplePidl))
175 if (HCR_GetDefaultIcon("Drive", sTemp, MAX_PATH, &dwNr))
177 lstrcpynA(szIconFile, sTemp, cchMax);
178 *piIndex = dwNr;
180 else
182 lstrcpynA(szIconFile, "shell32.dll", cchMax);
183 *piIndex = 8;
186 else if (_ILIsFolder (pSimplePidl))
188 if (HCR_GetDefaultIcon("Folder", sTemp, MAX_PATH, &dwNr))
190 lstrcpynA(szIconFile, sTemp, cchMax);
191 *piIndex = dwNr;
193 else
195 lstrcpynA(szIconFile, "shell32.dll", cchMax);
196 *piIndex = 3;
199 else /* object is file */
201 if (_ILGetExtension (pSimplePidl, sTemp, MAX_PATH)
202 && HCR_MapTypeToValue(sTemp, sTemp, MAX_PATH, TRUE)
203 && HCR_GetDefaultIcon(sTemp, sTemp, MAX_PATH, &dwNr))
205 if (!strcmp("%1",sTemp)) /* icon is in the file */
207 SHGetPathFromIDListA(This->pidl, sTemp);
208 dwNr = 0;
210 lstrcpynA(szIconFile, sTemp, cchMax);
211 *piIndex = dwNr;
213 else /* default icon */
215 lstrcpynA(szIconFile, "shell32.dll", cchMax);
216 *piIndex = 0;
220 TRACE("-- %s %x\n", szIconFile, *piIndex);
221 return NOERROR;
223 /**************************************************************************
224 * IExtractIconA_Extract
226 static HRESULT WINAPI IExtractIconA_fnExtract(IExtractIconA * iface, LPCSTR pszFile, UINT nIconIndex, HICON *phiconLarge, HICON *phiconSmall, UINT nIconSize)
228 ICOM_THIS(IExtractIconAImpl,iface);
230 FIXME("(%p) (file=%p index=%u %p %p size=%u) semi-stub\n", This, pszFile, nIconIndex, phiconLarge, phiconSmall, nIconSize);
232 if (phiconLarge)
233 *phiconLarge = pImageList_GetIcon(ShellBigIconList, nIconIndex, ILD_TRANSPARENT);
235 if (phiconSmall)
236 *phiconSmall = pImageList_GetIcon(ShellSmallIconList, nIconIndex, ILD_TRANSPARENT);
238 return S_OK;
241 static struct ICOM_VTABLE(IExtractIconA) eivt =
243 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
244 IExtractIconA_fnQueryInterface,
245 IExtractIconA_fnAddRef,
246 IExtractIconA_fnRelease,
247 IExtractIconA_fnGetIconLocation,
248 IExtractIconA_fnExtract
251 /************************************************************************
252 * IEIPersistFile_QueryInterface (IUnknown)
254 static HRESULT WINAPI IEIPersistFile_fnQueryInterface(
255 IPersistFile *iface,
256 REFIID iid,
257 LPVOID *ppvObj)
259 _ICOM_THIS_From_IPersistFile(IExtractIconA, iface);
261 return IShellFolder_QueryInterface((IExtractIconA*)This, iid, ppvObj);
264 /************************************************************************
265 * IEIPersistFile_AddRef (IUnknown)
267 static ULONG WINAPI IEIPersistFile_fnAddRef(
268 IPersistFile *iface)
270 _ICOM_THIS_From_IPersistFile(IExtractIconA, iface);
272 return IExtractIconA_AddRef((IExtractIconA*)This);
275 /************************************************************************
276 * IEIPersistFile_Release (IUnknown)
278 static ULONG WINAPI IEIPersistFile_fnRelease(
279 IPersistFile *iface)
281 _ICOM_THIS_From_IPersistFile(IExtractIconA, iface);
283 return IExtractIconA_Release((IExtractIconA*)This);
286 /************************************************************************
287 * IEIPersistFile_GetClassID (IPersist)
289 static HRESULT WINAPI IEIPersistFile_fnGetClassID(
290 IPersistFile *iface,
291 LPCLSID lpClassId)
293 CLSID StdFolderID = { 0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} };
295 if (lpClassId==NULL)
296 return E_POINTER;
298 memcpy(lpClassId, &StdFolderID, sizeof(StdFolderID));
300 return S_OK;
303 /************************************************************************
304 * IEIPersistFile_Load (IPersistFile)
306 static HRESULT WINAPI IEIPersistFile_fnLoad(IPersistFile* iface, LPCOLESTR pszFileName, DWORD dwMode)
308 _ICOM_THIS_From_IPersistFile(IExtractIconA, iface);
309 FIXME("%p\n", This);
310 return E_NOTIMPL;
314 static struct ICOM_VTABLE(IPersistFile) pfvt =
316 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
317 IEIPersistFile_fnQueryInterface,
318 IEIPersistFile_fnAddRef,
319 IEIPersistFile_fnRelease,
320 IEIPersistFile_fnGetClassID,
321 (void *) 0xdeadbeef /* IEIPersistFile_fnIsDirty */,
322 IEIPersistFile_fnLoad,
323 (void *) 0xdeadbeef /* IEIPersistFile_fnSave */,
324 (void *) 0xdeadbeef /* IEIPersistFile_fnSaveCompleted */,
325 (void *) 0xdeadbeef /* IEIPersistFile_fnGetCurFile */