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