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