Cleaned up dll startup routines now that we have separate address
[wine] / dlls / shell32 / folders.c
1 /*
2  *      Copyright 1997  Marcus Meissner
3  *      Copyright 1998  Juergen Schmied
4  *
5  */
6
7 #include <stdlib.h>
8 #include <stdio.h>
9 #include <string.h>
10
11 #include "windef.h"
12 #include "wine/obj_base.h"
13 #include "wine/obj_extracticon.h"
14 #include "wine/undocshell.h"
15 #include "shlguid.h"
16
17 #include "debugtools.h"
18 #include "winerror.h"
19
20 #include "pidl.h"
21 #include "shell32_main.h"
22
23 DEFAULT_DEBUG_CHANNEL(shell);
24
25
26 /***********************************************************************
27 *   IExtractIconA implementation
28 */
29
30 typedef struct 
31 {       ICOM_VFIELD(IExtractIconA);
32         DWORD   ref;
33         ICOM_VTABLE(IPersistFile)*      lpvtblPersistFile;
34         LPITEMIDLIST    pidl;
35 } IExtractIconAImpl;
36
37 static struct ICOM_VTABLE(IExtractIconA) eivt;
38 static struct ICOM_VTABLE(IPersistFile) pfvt;
39
40 #define _IPersistFile_Offset ((int)(&(((IExtractIconAImpl*)0)->lpvtblPersistFile)))
41 #define _ICOM_THIS_From_IPersistFile(class, name) class* This = (class*)(((char*)name)-_IPersistFile_Offset);
42
43 /**************************************************************************
44 *  IExtractIconA_Constructor
45 */
46 IExtractIconA* IExtractIconA_Constructor(LPCITEMIDLIST pidl)
47 {
48         IExtractIconAImpl* ei;
49
50         ei=(IExtractIconAImpl*)HeapAlloc(GetProcessHeap(),0,sizeof(IExtractIconAImpl));
51         ei->ref=1;
52         ICOM_VTBL(ei) = &eivt;
53         ei->lpvtblPersistFile = &pfvt;
54         ei->pidl=ILClone(pidl);
55
56         pdump(pidl);
57
58         TRACE("(%p)\n",ei);
59         shell32_ObjCount++;
60         return (IExtractIconA *)ei;
61 }
62 /**************************************************************************
63  *  IExtractIconA_QueryInterface
64  */
65 static HRESULT WINAPI IExtractIconA_fnQueryInterface( IExtractIconA * iface, REFIID riid, LPVOID *ppvObj)
66 {
67         ICOM_THIS(IExtractIconAImpl,iface);
68
69          TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
70
71         *ppvObj = NULL;
72
73         if(IsEqualIID(riid, &IID_IUnknown))             /*IUnknown*/
74         { *ppvObj = This; 
75         }
76         else if(IsEqualIID(riid, &IID_IPersistFile))    /*IExtractIcon*/
77         {    *ppvObj = (IPersistFile*)&(This->lpvtblPersistFile);
78         }
79         else if(IsEqualIID(riid, &IID_IExtractIconA))   /*IExtractIcon*/
80         {    *ppvObj = (IExtractIconA*)This;
81         }
82
83         if(*ppvObj)
84         { IExtractIconA_AddRef((IExtractIconA*) *ppvObj);       
85           TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
86           return S_OK;
87         }
88         TRACE("-- Interface: E_NOINTERFACE\n");
89         return E_NOINTERFACE;
90 }
91
92 /**************************************************************************
93 *  IExtractIconA_AddRef
94 */
95 static ULONG WINAPI IExtractIconA_fnAddRef(IExtractIconA * iface)
96 {
97         ICOM_THIS(IExtractIconAImpl,iface);
98
99         TRACE("(%p)->(count=%lu)\n",This, This->ref );
100
101         shell32_ObjCount++;
102
103         return ++(This->ref);
104 }
105 /**************************************************************************
106 *  IExtractIconA_Release
107 */
108 static ULONG WINAPI IExtractIconA_fnRelease(IExtractIconA * iface)
109 {
110         ICOM_THIS(IExtractIconAImpl,iface);
111
112         TRACE("(%p)->()\n",This);
113
114         shell32_ObjCount--;
115
116         if (!--(This->ref)) 
117         { TRACE(" destroying IExtractIcon(%p)\n",This);
118           SHFree(This->pidl);
119           HeapFree(GetProcessHeap(),0,This);
120           return 0;
121         }
122         return This->ref;
123 }
124 /**************************************************************************
125 *  IExtractIconA_GetIconLocation
126 *
127 * mapping filetype to icon
128 */
129 static HRESULT WINAPI IExtractIconA_fnGetIconLocation(
130         IExtractIconA * iface,
131         UINT uFlags,
132         LPSTR szIconFile,
133         UINT cchMax,
134         int * piIndex,
135         UINT * pwFlags)
136 {
137         ICOM_THIS(IExtractIconAImpl,iface);
138
139         char    sTemp[MAX_PATH];
140         DWORD   dwNr;
141         GUID const * riid;
142         LPITEMIDLIST    pSimplePidl = ILFindLastID(This->pidl);
143                         
144         TRACE("(%p) (flags=%u %p %u %p %p)\n", This, uFlags, szIconFile, cchMax, piIndex, pwFlags);
145
146         if (pwFlags)
147           *pwFlags = 0;
148
149         if (_ILIsDesktop(pSimplePidl))
150         {
151           lstrcpynA(szIconFile, "shell32.dll", cchMax);
152           *piIndex = 34;
153         }
154
155         /* my computer and other shell extensions */
156         else if ( (riid = _ILGetGUIDPointer(pSimplePidl)) )
157         { 
158           char xriid[50];
159           sprintf( xriid, "CLSID\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
160                    riid->Data1, riid->Data2, riid->Data3,
161                    riid->Data4[0], riid->Data4[1], riid->Data4[2], riid->Data4[3],
162                    riid->Data4[4], riid->Data4[5], riid->Data4[6], riid->Data4[7] );
163
164           if (HCR_GetDefaultIcon(xriid, sTemp, MAX_PATH, &dwNr))
165           {
166             lstrcpynA(szIconFile, sTemp, cchMax);
167             *piIndex = dwNr;
168           }
169           else
170           {
171             lstrcpynA(szIconFile, "shell32.dll", cchMax);
172             *piIndex = 15;
173           }
174         }
175
176         else if (_ILIsDrive (pSimplePidl))
177         {
178           if (HCR_GetDefaultIcon("Drive", sTemp, MAX_PATH, &dwNr))
179           {
180             lstrcpynA(szIconFile, sTemp, cchMax);
181             *piIndex = dwNr;
182           }
183           else
184           {
185             lstrcpynA(szIconFile, "shell32.dll", cchMax);
186             *piIndex = 8;
187           }
188         }
189         else if (_ILIsFolder (pSimplePidl))
190         {
191           if (HCR_GetDefaultIcon("Folder", sTemp, MAX_PATH, &dwNr))
192           {
193             lstrcpynA(szIconFile, sTemp, cchMax);
194             *piIndex = dwNr;
195           }
196           else
197           {
198             lstrcpynA(szIconFile, "shell32.dll", cchMax);
199             *piIndex = (uFlags & GIL_OPENICON)? 4 : 3;
200           }
201         }
202         else    /* object is file */
203         {
204           if (_ILGetExtension (pSimplePidl, sTemp, MAX_PATH)
205               && HCR_MapTypeToValue(sTemp, sTemp, MAX_PATH, TRUE)
206               && HCR_GetDefaultIcon(sTemp, sTemp, MAX_PATH, &dwNr))
207           {
208             if (!strcmp("%1",sTemp))            /* icon is in the file */
209             {
210               SHGetPathFromIDListA(This->pidl, sTemp);
211               dwNr = 0;
212             }
213             lstrcpynA(szIconFile, sTemp, cchMax);
214             *piIndex = dwNr;
215           }
216           else                                  /* default icon */
217           {
218             lstrcpynA(szIconFile, "shell32.dll", cchMax);
219             *piIndex = 0;
220           }
221         }
222
223         TRACE("-- %s %x\n", szIconFile, *piIndex);
224         return NOERROR;
225 }
226 /**************************************************************************
227 *  IExtractIconA_Extract
228 */
229 static HRESULT WINAPI IExtractIconA_fnExtract(IExtractIconA * iface, LPCSTR pszFile, UINT nIconIndex, HICON *phiconLarge, HICON *phiconSmall, UINT nIconSize)
230 {
231         ICOM_THIS(IExtractIconAImpl,iface);
232
233         FIXME("(%p) (file=%p index=%u %p %p size=%u) semi-stub\n", This, pszFile, nIconIndex, phiconLarge, phiconSmall, nIconSize);
234
235         if (phiconLarge)
236           *phiconLarge = pImageList_GetIcon(ShellBigIconList, nIconIndex, ILD_TRANSPARENT);
237
238         if (phiconSmall)
239           *phiconSmall = pImageList_GetIcon(ShellSmallIconList, nIconIndex, ILD_TRANSPARENT);
240
241         return S_OK;
242 }
243
244 static struct ICOM_VTABLE(IExtractIconA) eivt = 
245 {       
246         ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
247         IExtractIconA_fnQueryInterface,
248         IExtractIconA_fnAddRef,
249         IExtractIconA_fnRelease,
250         IExtractIconA_fnGetIconLocation,
251         IExtractIconA_fnExtract
252 };
253
254 /************************************************************************
255  * IEIPersistFile_QueryInterface (IUnknown)
256  */
257 static HRESULT WINAPI IEIPersistFile_fnQueryInterface(
258         IPersistFile    *iface,
259         REFIID          iid,
260         LPVOID          *ppvObj)
261 {
262         _ICOM_THIS_From_IPersistFile(IExtractIconA, iface);
263
264         return IShellFolder_QueryInterface((IExtractIconA*)This, iid, ppvObj);
265 }
266
267 /************************************************************************
268  * IEIPersistFile_AddRef (IUnknown)
269  */
270 static ULONG WINAPI IEIPersistFile_fnAddRef(
271         IPersistFile    *iface)
272 {
273         _ICOM_THIS_From_IPersistFile(IExtractIconA, iface);
274
275         return IExtractIconA_AddRef((IExtractIconA*)This);
276 }
277
278 /************************************************************************
279  * IEIPersistFile_Release (IUnknown)
280  */
281 static ULONG WINAPI IEIPersistFile_fnRelease(
282         IPersistFile    *iface)
283 {
284         _ICOM_THIS_From_IPersistFile(IExtractIconA, iface);
285
286         return IExtractIconA_Release((IExtractIconA*)This);
287 }
288
289 /************************************************************************
290  * IEIPersistFile_GetClassID (IPersist)
291  */
292 static HRESULT WINAPI IEIPersistFile_fnGetClassID(
293         IPersistFile    *iface,
294         LPCLSID         lpClassId)
295 {
296         CLSID StdFolderID = { 0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} };
297
298         if (lpClassId==NULL)
299           return E_POINTER;
300
301         memcpy(lpClassId, &StdFolderID, sizeof(StdFolderID));
302
303         return S_OK;
304 }
305
306 /************************************************************************
307  * IEIPersistFile_Load (IPersistFile)
308  */
309 static HRESULT WINAPI IEIPersistFile_fnLoad(IPersistFile* iface, LPCOLESTR pszFileName, DWORD dwMode)
310 {
311         _ICOM_THIS_From_IPersistFile(IExtractIconA, iface);
312         FIXME("%p\n", This);
313         return E_NOTIMPL;
314
315 }
316
317 static struct ICOM_VTABLE(IPersistFile) pfvt =
318 {
319         ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
320         IEIPersistFile_fnQueryInterface,
321         IEIPersistFile_fnAddRef,
322         IEIPersistFile_fnRelease,
323         IEIPersistFile_fnGetClassID,
324         (void *) 0xdeadbeef /* IEIPersistFile_fnIsDirty */,
325         IEIPersistFile_fnLoad,
326         (void *) 0xdeadbeef /* IEIPersistFile_fnSave */,
327         (void *) 0xdeadbeef /* IEIPersistFile_fnSaveCompleted */,
328         (void *) 0xdeadbeef /* IEIPersistFile_fnGetCurFile */
329 };
330