Added DECL_GLOBAL_CONSTRUCTOR macro.
[wine/multimedia.git] / dlls / shell32 / folders.c
blob9464a6f9484e9bd0792fba313194d07a86a2be3b
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_VFIELD(IExtractIconA);
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 ICOM_VTBL(ei) = &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 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
68 *ppvObj = NULL;
70 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
71 { *ppvObj = This;
73 else if(IsEqualIID(riid, &IID_IPersistFile)) /*IExtractIcon*/
74 { *ppvObj = (IPersistFile*)&(This->lpvtblPersistFile);
76 else if(IsEqualIID(riid, &IID_IExtractIconA)) /*IExtractIcon*/
77 { *ppvObj = (IExtractIconA*)This;
80 if(*ppvObj)
81 { IExtractIconA_AddRef((IExtractIconA*) *ppvObj);
82 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
83 return S_OK;
85 TRACE("-- Interface: E_NOINTERFACE\n");
86 return E_NOINTERFACE;
89 /**************************************************************************
90 * IExtractIconA_AddRef
92 static ULONG WINAPI IExtractIconA_fnAddRef(IExtractIconA * iface)
94 ICOM_THIS(IExtractIconAImpl,iface);
96 TRACE("(%p)->(count=%lu)\n",This, This->ref );
98 shell32_ObjCount++;
100 return ++(This->ref);
102 /**************************************************************************
103 * IExtractIconA_Release
105 static ULONG WINAPI IExtractIconA_fnRelease(IExtractIconA * iface)
107 ICOM_THIS(IExtractIconAImpl,iface);
109 TRACE("(%p)->()\n",This);
111 shell32_ObjCount--;
113 if (!--(This->ref))
114 { TRACE(" destroying IExtractIcon(%p)\n",This);
115 SHFree(This->pidl);
116 HeapFree(GetProcessHeap(),0,This);
117 return 0;
119 return This->ref;
121 /**************************************************************************
122 * IExtractIconA_GetIconLocation
124 * mapping filetype to icon
126 static HRESULT WINAPI IExtractIconA_fnGetIconLocation(
127 IExtractIconA * iface,
128 UINT uFlags,
129 LPSTR szIconFile,
130 UINT cchMax,
131 int * piIndex,
132 UINT * pwFlags)
134 ICOM_THIS(IExtractIconAImpl,iface);
136 char sTemp[MAX_PATH];
137 DWORD dwNr;
138 GUID const * riid;
139 LPITEMIDLIST pSimplePidl = ILFindLastID(This->pidl);
141 TRACE("(%p) (flags=%u %p %u %p %p)\n", This, uFlags, szIconFile, cchMax, piIndex, pwFlags);
143 if (pwFlags)
144 *pwFlags = 0;
146 if (_ILIsDesktop(pSimplePidl))
148 lstrcpynA(szIconFile, "shell32.dll", cchMax);
149 *piIndex = 34;
152 /* my computer and other shell extensions */
153 else if ( (riid = _ILGetGUIDPointer(pSimplePidl)) )
155 char xriid[50];
156 strcpy(xriid,"CLSID\\");
157 WINE_StringFromCLSID((LPCLSID)riid,&xriid[strlen(xriid)]);
159 if (HCR_GetDefaultIcon(xriid, sTemp, MAX_PATH, &dwNr))
161 lstrcpynA(szIconFile, sTemp, cchMax);
162 *piIndex = dwNr;
164 else
166 lstrcpynA(szIconFile, "shell32.dll", cchMax);
167 *piIndex = 15;
171 else if (_ILIsDrive (pSimplePidl))
173 if (HCR_GetDefaultIcon("Drive", sTemp, MAX_PATH, &dwNr))
175 lstrcpynA(szIconFile, sTemp, cchMax);
176 *piIndex = dwNr;
178 else
180 lstrcpynA(szIconFile, "shell32.dll", cchMax);
181 *piIndex = 8;
184 else if (_ILIsFolder (pSimplePidl))
186 if (HCR_GetDefaultIcon("Folder", sTemp, MAX_PATH, &dwNr))
188 lstrcpynA(szIconFile, sTemp, cchMax);
189 *piIndex = dwNr;
191 else
193 lstrcpynA(szIconFile, "shell32.dll", cchMax);
194 *piIndex = (uFlags & GIL_OPENICON)? 4 : 3;
197 else /* object is file */
199 if (_ILGetExtension (pSimplePidl, sTemp, MAX_PATH)
200 && HCR_MapTypeToValue(sTemp, sTemp, MAX_PATH, TRUE)
201 && HCR_GetDefaultIcon(sTemp, sTemp, MAX_PATH, &dwNr))
203 if (!strcmp("%1",sTemp)) /* icon is in the file */
205 SHGetPathFromIDListA(This->pidl, sTemp);
206 dwNr = 0;
208 lstrcpynA(szIconFile, sTemp, cchMax);
209 *piIndex = dwNr;
211 else /* default icon */
213 lstrcpynA(szIconFile, "shell32.dll", cchMax);
214 *piIndex = 0;
218 TRACE("-- %s %x\n", szIconFile, *piIndex);
219 return NOERROR;
221 /**************************************************************************
222 * IExtractIconA_Extract
224 static HRESULT WINAPI IExtractIconA_fnExtract(IExtractIconA * iface, LPCSTR pszFile, UINT nIconIndex, HICON *phiconLarge, HICON *phiconSmall, UINT nIconSize)
226 ICOM_THIS(IExtractIconAImpl,iface);
228 FIXME("(%p) (file=%p index=%u %p %p size=%u) semi-stub\n", This, pszFile, nIconIndex, phiconLarge, phiconSmall, nIconSize);
230 if (phiconLarge)
231 *phiconLarge = pImageList_GetIcon(ShellBigIconList, nIconIndex, ILD_TRANSPARENT);
233 if (phiconSmall)
234 *phiconSmall = pImageList_GetIcon(ShellSmallIconList, nIconIndex, ILD_TRANSPARENT);
236 return S_OK;
239 static struct ICOM_VTABLE(IExtractIconA) eivt =
241 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
242 IExtractIconA_fnQueryInterface,
243 IExtractIconA_fnAddRef,
244 IExtractIconA_fnRelease,
245 IExtractIconA_fnGetIconLocation,
246 IExtractIconA_fnExtract
249 /************************************************************************
250 * IEIPersistFile_QueryInterface (IUnknown)
252 static HRESULT WINAPI IEIPersistFile_fnQueryInterface(
253 IPersistFile *iface,
254 REFIID iid,
255 LPVOID *ppvObj)
257 _ICOM_THIS_From_IPersistFile(IExtractIconA, iface);
259 return IShellFolder_QueryInterface((IExtractIconA*)This, iid, ppvObj);
262 /************************************************************************
263 * IEIPersistFile_AddRef (IUnknown)
265 static ULONG WINAPI IEIPersistFile_fnAddRef(
266 IPersistFile *iface)
268 _ICOM_THIS_From_IPersistFile(IExtractIconA, iface);
270 return IExtractIconA_AddRef((IExtractIconA*)This);
273 /************************************************************************
274 * IEIPersistFile_Release (IUnknown)
276 static ULONG WINAPI IEIPersistFile_fnRelease(
277 IPersistFile *iface)
279 _ICOM_THIS_From_IPersistFile(IExtractIconA, iface);
281 return IExtractIconA_Release((IExtractIconA*)This);
284 /************************************************************************
285 * IEIPersistFile_GetClassID (IPersist)
287 static HRESULT WINAPI IEIPersistFile_fnGetClassID(
288 IPersistFile *iface,
289 LPCLSID lpClassId)
291 CLSID StdFolderID = { 0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} };
293 if (lpClassId==NULL)
294 return E_POINTER;
296 memcpy(lpClassId, &StdFolderID, sizeof(StdFolderID));
298 return S_OK;
301 /************************************************************************
302 * IEIPersistFile_Load (IPersistFile)
304 static HRESULT WINAPI IEIPersistFile_fnLoad(IPersistFile* iface, LPCOLESTR pszFileName, DWORD dwMode)
306 _ICOM_THIS_From_IPersistFile(IExtractIconA, iface);
307 FIXME("%p\n", This);
308 return E_NOTIMPL;
312 static struct ICOM_VTABLE(IPersistFile) pfvt =
314 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
315 IEIPersistFile_fnQueryInterface,
316 IEIPersistFile_fnAddRef,
317 IEIPersistFile_fnRelease,
318 IEIPersistFile_fnGetClassID,
319 (void *) 0xdeadbeef /* IEIPersistFile_fnIsDirty */,
320 IEIPersistFile_fnLoad,
321 (void *) 0xdeadbeef /* IEIPersistFile_fnSave */,
322 (void *) 0xdeadbeef /* IEIPersistFile_fnSaveCompleted */,
323 (void *) 0xdeadbeef /* IEIPersistFile_fnGetCurFile */