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