Added DebugBreak.
[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
13 #include "debugtools.h"
14 #include "winerror.h"
15
16 #include "pidl.h"
17 #include "shell32_main.h"
18
19 DEFAULT_DEBUG_CHANNEL(shell)
20
21
22 /***********************************************************************
23 *   IExtractIconA implementation
24 */
25
26 typedef struct 
27 {       ICOM_VTABLE(IExtractIconA)*     lpvtbl;
28         DWORD   ref;
29         ICOM_VTABLE(IPersistFile)*      lpvtblPersistFile;
30         LPITEMIDLIST    pidl;
31 } IExtractIconAImpl;
32
33 static struct ICOM_VTABLE(IExtractIconA) eivt;
34 static struct ICOM_VTABLE(IPersistFile) pfvt;
35
36 #define _IPersistFile_Offset ((int)(&(((IExtractIconAImpl*)0)->lpvtblPersistFile)))
37 #define _ICOM_THIS_From_IPersistFile(class, name) class* This = (class*)(((char*)name)-_IPersistFile_Offset);
38
39 /**************************************************************************
40 *  IExtractIconA_Constructor
41 */
42 IExtractIconA* IExtractIconA_Constructor(LPCITEMIDLIST pidl)
43 {
44         IExtractIconAImpl* ei;
45
46         ei=(IExtractIconAImpl*)HeapAlloc(GetProcessHeap(),0,sizeof(IExtractIconAImpl));
47         ei->ref=1;
48         ei->lpvtbl = &eivt;
49         ei->lpvtblPersistFile = &pfvt;
50         ei->pidl=ILClone(pidl);
51
52         pdump(pidl);
53
54         TRACE("(%p)\n",ei);
55         shell32_ObjCount++;
56         return (IExtractIconA *)ei;
57 }
58 /**************************************************************************
59  *  IExtractIconA_QueryInterface
60  */
61 static HRESULT WINAPI IExtractIconA_fnQueryInterface( IExtractIconA * iface, REFIID riid, LPVOID *ppvObj)
62 {
63         ICOM_THIS(IExtractIconAImpl,iface);
64
65         char    xriid[50];
66          WINE_StringFromCLSID((LPCLSID)riid,xriid);
67          TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,xriid,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 static HRESULT WINAPI IExtractIconA_fnGetIconLocation(
126         IExtractIconA * iface,
127         UINT uFlags,
128         LPSTR szIconFile,
129         UINT cchMax,
130         int * piIndex,
131         UINT * pwFlags)
132 {
133         ICOM_THIS(IExtractIconAImpl,iface);
134
135         char    sTemp[MAX_PATH];
136         DWORD   ret = S_FALSE, dwNr;
137         LPITEMIDLIST    pSimplePidl = ILFindLastID(This->pidl);
138                         
139         TRACE("(%p) (flags=%u %p %u %p %p)\n", This, uFlags, szIconFile, cchMax, piIndex, pwFlags);
140
141         if (pwFlags)
142           *pwFlags = 0;
143
144         if (_ILIsDesktop(pSimplePidl))
145         { strncpy(szIconFile, "shell32.dll", cchMax);
146           *piIndex = 34;
147           ret = NOERROR;
148         }
149         else if (_ILIsMyComputer(pSimplePidl))
150         { if (HCR_GetDefaultIcon("CLSID\\{20D04FE0-3AEA-1069-A2D8-08002B30309D}", sTemp, MAX_PATH, &dwNr))
151           { strncpy(szIconFile, sTemp, cchMax);
152             *piIndex = dwNr;
153           }
154           else
155           { strncpy(szIconFile, "shell32.dll", cchMax);
156             *piIndex = 15;
157           }
158           ret = NOERROR;
159         }
160         else if (_ILIsDrive (pSimplePidl))
161         { if (HCR_GetDefaultIcon("Drive", sTemp, MAX_PATH, &dwNr))
162           { strncpy(szIconFile, sTemp, cchMax);
163             *piIndex = dwNr;
164           }
165           else
166           { strncpy(szIconFile, "shell32.dll", cchMax);
167             *piIndex = 8;
168           }
169           ret = NOERROR;
170         }
171         else if (_ILIsFolder (pSimplePidl))
172         { if (HCR_GetDefaultIcon("Folder", sTemp, MAX_PATH, &dwNr))
173           { strncpy(szIconFile, sTemp, cchMax);
174             *piIndex = dwNr;
175           }
176           else
177           { strncpy(szIconFile, "shell32.dll", cchMax);
178             *piIndex = 3;
179           }
180           ret = NOERROR;
181         }
182         else
183         { if (_ILGetExtension (pSimplePidl, sTemp, MAX_PATH))           /* object is file */
184           { if ( HCR_MapTypeToValue(sTemp, sTemp, MAX_PATH))
185             { if (HCR_GetDefaultIcon(sTemp, sTemp, MAX_PATH, &dwNr))
186               { if (!strcmp("%1",sTemp))                                        /* icon is in the file */
187                 { _ILGetPidlPath(This->pidl, sTemp, MAX_PATH);
188                   dwNr = 0;
189                 }
190                 strncpy(szIconFile, sTemp, cchMax);
191                 *piIndex = dwNr;
192                 ret = NOERROR;
193               }
194             }
195           }
196         }
197
198         TRACE("-- %s %x\n", (ret==NOERROR)?debugstr_a(szIconFile):"[error]", *piIndex);
199         return ret;
200 }
201 /**************************************************************************
202 *  IExtractIconA_Extract
203 */
204 static HRESULT WINAPI IExtractIconA_fnExtract(IExtractIconA * iface, LPCSTR pszFile, UINT nIconIndex, HICON *phiconLarge, HICON *phiconSmall, UINT nIconSize)
205 {
206         ICOM_THIS(IExtractIconAImpl,iface);
207
208         FIXME("(%p) (file=%p index=%u %p %p size=%u) semi-stub\n", This, pszFile, nIconIndex, phiconLarge, phiconSmall, nIconSize);
209
210         if (phiconLarge)
211           *phiconLarge = pImageList_GetIcon(ShellBigIconList, nIconIndex, ILD_TRANSPARENT);
212
213         if (phiconSmall)
214           *phiconSmall = pImageList_GetIcon(ShellSmallIconList, nIconIndex, ILD_TRANSPARENT);
215
216         return S_OK;
217 }
218
219 static struct ICOM_VTABLE(IExtractIconA) eivt = 
220 {       
221         ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
222         IExtractIconA_fnQueryInterface,
223         IExtractIconA_fnAddRef,
224         IExtractIconA_fnRelease,
225         IExtractIconA_fnGetIconLocation,
226         IExtractIconA_fnExtract
227 };
228
229 /************************************************************************
230  * IEIPersistFile_QueryInterface (IUnknown)
231  */
232 static HRESULT WINAPI IEIPersistFile_fnQueryInterface(
233         IPersistFile    *iface,
234         REFIID          iid,
235         LPVOID          *ppvObj)
236 {
237         _ICOM_THIS_From_IPersistFile(IExtractIconA, iface);
238
239         return IShellFolder_QueryInterface((IExtractIconA*)This, iid, ppvObj);
240 }
241
242 /************************************************************************
243  * IEIPersistFile_AddRef (IUnknown)
244  */
245 static ULONG WINAPI IEIPersistFile_fnAddRef(
246         IPersistFile    *iface)
247 {
248         _ICOM_THIS_From_IPersistFile(IExtractIconA, iface);
249
250         return IExtractIconA_AddRef((IExtractIconA*)This);
251 }
252
253 /************************************************************************
254  * IEIPersistFile_Release (IUnknown)
255  */
256 static ULONG WINAPI IEIPersistFile_fnRelease(
257         IPersistFile    *iface)
258 {
259         _ICOM_THIS_From_IPersistFile(IExtractIconA, iface);
260
261         return IExtractIconA_Release((IExtractIconA*)This);
262 }
263
264 /************************************************************************
265  * IEIPersistFile_GetClassID (IPersist)
266  */
267 static HRESULT WINAPI IEIPersistFile_fnGetClassID(
268         const IPersistFile      *iface,
269         LPCLSID                 lpClassId)
270 {
271         CLSID StdFolderID = { 0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} };
272
273         if (lpClassId==NULL)
274           return E_POINTER;
275
276         memcpy(lpClassId, &StdFolderID, sizeof(StdFolderID));
277
278         return S_OK;
279 }
280
281 /************************************************************************
282  * IEIPersistFile_Load (IPersistFile)
283  */
284 static HRESULT WINAPI IEIPersistFile_fnLoad(IPersistFile* iface, LPCOLESTR pszFileName, DWORD dwMode)
285 {
286         _ICOM_THIS_From_IPersistFile(IExtractIconA, iface);
287         FIXME("%p\n", This);
288         return E_NOTIMPL;
289
290 }
291
292 static struct ICOM_VTABLE(IPersistFile) pfvt =
293 {
294         ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
295         IEIPersistFile_fnQueryInterface,
296         IEIPersistFile_fnAddRef,
297         IEIPersistFile_fnRelease,
298         IEIPersistFile_fnGetClassID,
299         (void *) 0xdeadbeef /* IEIPersistFile_fnIsDirty */,
300         IEIPersistFile_fnLoad,
301         (void *) 0xdeadbeef /* IEIPersistFile_fnSave */,
302         (void *) 0xdeadbeef /* IEIPersistFile_fnSaveCompleted */,
303         (void *) 0xdeadbeef /* IEIPersistFile_fnGetCurFile */
304 };
305