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