2 * Copyright 1997 Marcus Meissner
3 * Copyright 1998 Juergen Schmied
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.
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.
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
28 #include "undocshell.h"
31 #include "wine/debug.h"
35 #include "shell32_main.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
39 /***********************************************************************
40 * IExtractIconW implementation
44 ICOM_VFIELD(IExtractIconW
);
46 ICOM_VTABLE(IPersistFile
)* lpvtblPersistFile
;
47 ICOM_VTABLE(IExtractIconA
)* lpvtblExtractIconA
;
51 static struct ICOM_VTABLE(IExtractIconA
) eiavt
;
52 static struct ICOM_VTABLE(IExtractIconW
) eivt
;
53 static struct ICOM_VTABLE(IPersistFile
) pfvt
;
55 #define _IPersistFile_Offset ((int)(&(((IExtractIconWImpl*)0)->lpvtblPersistFile)))
56 #define _ICOM_THIS_From_IPersistFile(class, name) class* This = (class*)(((char*)name)-_IPersistFile_Offset);
58 #define _IExtractIconA_Offset ((int)(&(((IExtractIconWImpl*)0)->lpvtblExtractIconA)))
59 #define _ICOM_THIS_From_IExtractIconA(class, name) class* This = (class*)(((char*)name)-_IExtractIconA_Offset);
61 /**************************************************************************
62 * IExtractIconW_Constructor
64 IExtractIconW
* IExtractIconW_Constructor(LPCITEMIDLIST pidl
)
66 IExtractIconWImpl
* ei
;
70 ei
= (IExtractIconWImpl
*)HeapAlloc(GetProcessHeap(),0,sizeof(IExtractIconWImpl
));
73 ei
->lpvtblPersistFile
= &pfvt
;
74 ei
->lpvtblExtractIconA
= &eiavt
;
75 ei
->pidl
=ILClone(pidl
);
80 return (IExtractIconW
*)ei
;
82 /**************************************************************************
83 * IExtractIconW_QueryInterface
85 static HRESULT WINAPI
IExtractIconW_fnQueryInterface(IExtractIconW
*iface
, REFIID riid
, LPVOID
*ppvObj
)
87 ICOM_THIS(IExtractIconWImpl
, iface
);
89 TRACE("(%p)->(\n\tIID:\t%s,%p)\n", This
, debugstr_guid(riid
), ppvObj
);
93 if (IsEqualIID(riid
, &IID_IUnknown
)) /*IUnknown*/
97 else if (IsEqualIID(riid
, &IID_IPersistFile
)) /*IExtractIcon*/
99 *ppvObj
= (IPersistFile
*)&(This
->lpvtblPersistFile
);
101 else if (IsEqualIID(riid
, &IID_IExtractIconA
)) /*IExtractIcon*/
103 *ppvObj
= (IExtractIconA
*)&(This
->lpvtblExtractIconA
);
105 else if (IsEqualIID(riid
, &IID_IExtractIconW
)) /*IExtractIcon*/
107 *ppvObj
= (IExtractIconW
*)This
;
112 IExtractIconW_AddRef((IExtractIconW
*) *ppvObj
);
113 TRACE("-- Interface: (%p)->(%p)\n",ppvObj
,*ppvObj
);
116 TRACE("-- Interface: E_NOINTERFACE\n");
117 return E_NOINTERFACE
;
120 /**************************************************************************
121 * IExtractIconW_AddRef
123 static ULONG WINAPI
IExtractIconW_fnAddRef(IExtractIconW
* iface
)
125 ICOM_THIS(IExtractIconWImpl
, iface
);
127 TRACE("(%p)->(count=%lu)\n",This
, This
->ref
);
129 return ++(This
->ref
);
131 /**************************************************************************
132 * IExtractIconW_Release
134 static ULONG WINAPI
IExtractIconW_fnRelease(IExtractIconW
* iface
)
136 ICOM_THIS(IExtractIconWImpl
, iface
);
138 TRACE("(%p)->()\n",This
);
142 TRACE(" destroying IExtractIcon(%p)\n",This
);
144 HeapFree(GetProcessHeap(),0,This
);
150 static WCHAR swShell32Name
[] = {'s','h','e','l','l','3','2','.','d','l','l',0};
152 /**************************************************************************
153 * IExtractIconW_GetIconLocation
155 * mapping filetype to icon
157 static HRESULT WINAPI
IExtractIconW_fnGetIconLocation(
158 IExtractIconW
* iface
,
159 UINT uFlags
, /* GIL_ flags */
163 UINT
* pwFlags
) /* returned GIL_ flags */
165 ICOM_THIS(IExtractIconWImpl
, iface
);
167 char sTemp
[MAX_PATH
];
170 LPITEMIDLIST pSimplePidl
= ILFindLastID(This
->pidl
);
172 TRACE("(%p) (flags=%u %p %u %p %p)\n", This
, uFlags
, szIconFile
, cchMax
, piIndex
, pwFlags
);
177 if (_ILIsDesktop(pSimplePidl
))
179 lstrcpynW(szIconFile
, swShell32Name
, cchMax
);
183 /* my computer and other shell extensions */
184 else if ((riid
= _ILGetGUIDPointer(pSimplePidl
)))
188 sprintf(xriid
, "CLSID\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
189 riid
->Data1
, riid
->Data2
, riid
->Data3
,
190 riid
->Data4
[0], riid
->Data4
[1], riid
->Data4
[2], riid
->Data4
[3],
191 riid
->Data4
[4], riid
->Data4
[5], riid
->Data4
[6], riid
->Data4
[7]);
193 if (HCR_GetDefaultIconA(xriid
, sTemp
, MAX_PATH
, &dwNr
))
195 MultiByteToWideChar(CP_ACP
, 0, sTemp
, -1, szIconFile
, cchMax
);
200 lstrcpynW(szIconFile
, swShell32Name
, cchMax
);
205 else if (_ILIsDrive (pSimplePidl
))
207 if (HCR_GetDefaultIconA("Drive", sTemp
, MAX_PATH
, &dwNr
))
209 MultiByteToWideChar(CP_ACP
, 0, sTemp
, -1, szIconFile
, cchMax
);
214 lstrcpynW(szIconFile
, swShell32Name
, cchMax
);
218 else if (_ILIsFolder (pSimplePidl
))
220 if (HCR_GetDefaultIconA("Folder", sTemp
, MAX_PATH
, &dwNr
))
222 MultiByteToWideChar(CP_ACP
, 0, sTemp
, -1, szIconFile
, cchMax
);
226 lstrcpynW(szIconFile
, swShell32Name
, cchMax
);
229 *piIndex
= (uFlags
& GIL_OPENICON
) ? dwNr
+ 1 : dwNr
;
231 else /* object is file */
233 if (_ILGetExtension(pSimplePidl
, sTemp
, MAX_PATH
)
234 && HCR_MapTypeToValueA(sTemp
, sTemp
, MAX_PATH
, TRUE
)
235 && HCR_GetDefaultIconA(sTemp
, sTemp
, MAX_PATH
, &dwNr
))
237 if (!lstrcmpA("%1", sTemp
)) /* icon is in the file */
239 SHGetPathFromIDListW(This
->pidl
, szIconFile
);
244 MultiByteToWideChar(CP_ACP
, 0, sTemp
, -1, szIconFile
, cchMax
);
248 else /* default icon */
250 lstrcpynW(szIconFile
, swShell32Name
, cchMax
);
255 TRACE("-- %s %x\n", debugstr_w(szIconFile
), *piIndex
);
258 /**************************************************************************
259 * IExtractIconW_Extract
261 static HRESULT WINAPI
IExtractIconW_fnExtract(IExtractIconW
* iface
, LPCWSTR pszFile
, UINT nIconIndex
, HICON
*phiconLarge
, HICON
*phiconSmall
, UINT nIconSize
)
263 ICOM_THIS(IExtractIconWImpl
, iface
);
265 FIXME("(%p) (file=%p index=%u %p %p size=%u) semi-stub\n", This
, debugstr_w(pszFile
), nIconIndex
, phiconLarge
, phiconSmall
, nIconSize
);
268 *phiconLarge
= ImageList_GetIcon(ShellBigIconList
, nIconIndex
, ILD_TRANSPARENT
);
271 *phiconSmall
= ImageList_GetIcon(ShellSmallIconList
, nIconIndex
, ILD_TRANSPARENT
);
276 static struct ICOM_VTABLE(IExtractIconW
) eivt
=
278 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
279 IExtractIconW_fnQueryInterface
,
280 IExtractIconW_fnAddRef
,
281 IExtractIconW_fnRelease
,
282 IExtractIconW_fnGetIconLocation
,
283 IExtractIconW_fnExtract
286 /**************************************************************************
287 * IExtractIconA_Constructor
289 IExtractIconA
* IExtractIconA_Constructor(LPCITEMIDLIST pidl
)
291 ICOM_THIS(IExtractIconWImpl
, IExtractIconW_Constructor(pidl
));
292 IExtractIconA
*eia
= (IExtractIconA
*)&This
->lpvtblExtractIconA
;
294 TRACE("(%p)->(%p)\n", This
, eia
);
297 /**************************************************************************
298 * IExtractIconA_QueryInterface
300 static HRESULT WINAPI
IExtractIconA_fnQueryInterface(IExtractIconA
* iface
, REFIID riid
, LPVOID
*ppvObj
)
302 _ICOM_THIS_From_IExtractIconA(IExtractIconW
, iface
);
304 return IExtractIconW_QueryInterface(This
, riid
, ppvObj
);
307 /**************************************************************************
308 * IExtractIconA_AddRef
310 static ULONG WINAPI
IExtractIconA_fnAddRef(IExtractIconA
* iface
)
312 _ICOM_THIS_From_IExtractIconA(IExtractIconW
, iface
);
314 return IExtractIconW_AddRef(This
);
316 /**************************************************************************
317 * IExtractIconA_Release
319 static ULONG WINAPI
IExtractIconA_fnRelease(IExtractIconA
* iface
)
321 _ICOM_THIS_From_IExtractIconA(IExtractIconW
, iface
);
323 return IExtractIconW_AddRef(This
);
325 /**************************************************************************
326 * IExtractIconA_GetIconLocation
328 * mapping filetype to icon
330 static HRESULT WINAPI
IExtractIconA_fnGetIconLocation(
331 IExtractIconA
* iface
,
339 LPWSTR lpwstrFile
= HeapAlloc(GetProcessHeap(), 0, cchMax
* sizeof(WCHAR
));
340 _ICOM_THIS_From_IExtractIconA(IExtractIconW
, iface
);
342 TRACE("(%p) (flags=%u %p %u %p %p)\n", This
, uFlags
, szIconFile
, cchMax
, piIndex
, pwFlags
);
344 ret
= IExtractIconW_GetIconLocation(This
, uFlags
, lpwstrFile
, cchMax
, piIndex
, pwFlags
);
345 WideCharToMultiByte(CP_ACP
, 0, lpwstrFile
, -1, szIconFile
, cchMax
, NULL
, NULL
);
346 HeapFree(GetProcessHeap(), 0, lpwstrFile
);
348 TRACE("-- %s %x\n", szIconFile
, *piIndex
);
351 /**************************************************************************
352 * IExtractIconA_Extract
354 static HRESULT WINAPI
IExtractIconA_fnExtract(IExtractIconA
* iface
, LPCSTR pszFile
, UINT nIconIndex
, HICON
*phiconLarge
, HICON
*phiconSmall
, UINT nIconSize
)
357 INT len
= MultiByteToWideChar(CP_ACP
, 0, pszFile
, -1, NULL
, 0);
358 LPWSTR lpwstrFile
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
359 _ICOM_THIS_From_IExtractIconA(IExtractIconW
, iface
);
361 TRACE("(%p) (file=%p index=%u %p %p size=%u)\n", This
, pszFile
, nIconIndex
, phiconLarge
, phiconSmall
, nIconSize
);
363 MultiByteToWideChar(CP_ACP
, 0, pszFile
, -1, lpwstrFile
, len
);
364 ret
= IExtractIconW_Extract(This
, lpwstrFile
, nIconIndex
, phiconLarge
, phiconSmall
, nIconSize
);
365 HeapFree(GetProcessHeap(), 0, lpwstrFile
);
369 static struct ICOM_VTABLE(IExtractIconA
) eiavt
=
371 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
372 IExtractIconA_fnQueryInterface
,
373 IExtractIconA_fnAddRef
,
374 IExtractIconA_fnRelease
,
375 IExtractIconA_fnGetIconLocation
,
376 IExtractIconA_fnExtract
379 /************************************************************************
380 * IEIPersistFile_QueryInterface (IUnknown)
382 static HRESULT WINAPI
IEIPersistFile_fnQueryInterface(
387 _ICOM_THIS_From_IPersistFile(IExtractIconW
, iface
);
389 return IExtractIconW_QueryInterface(This
, iid
, ppvObj
);
392 /************************************************************************
393 * IEIPersistFile_AddRef (IUnknown)
395 static ULONG WINAPI
IEIPersistFile_fnAddRef(
398 _ICOM_THIS_From_IPersistFile(IExtractIconW
, iface
);
400 return IExtractIconW_AddRef(This
);
403 /************************************************************************
404 * IEIPersistFile_Release (IUnknown)
406 static ULONG WINAPI
IEIPersistFile_fnRelease(
409 _ICOM_THIS_From_IPersistFile(IExtractIconW
, iface
);
411 return IExtractIconW_Release(This
);
414 /************************************************************************
415 * IEIPersistFile_GetClassID (IPersist)
417 static HRESULT WINAPI
IEIPersistFile_fnGetClassID(
421 CLSID StdFolderID
= { 0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} };
426 memcpy(lpClassId
, &StdFolderID
, sizeof(StdFolderID
));
431 /************************************************************************
432 * IEIPersistFile_Load (IPersistFile)
434 static HRESULT WINAPI
IEIPersistFile_fnLoad(IPersistFile
* iface
, LPCOLESTR pszFileName
, DWORD dwMode
)
436 _ICOM_THIS_From_IPersistFile(IExtractIconW
, iface
);
442 static struct ICOM_VTABLE(IPersistFile
) pfvt
=
444 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
445 IEIPersistFile_fnQueryInterface
,
446 IEIPersistFile_fnAddRef
,
447 IEIPersistFile_fnRelease
,
448 IEIPersistFile_fnGetClassID
,
449 (void *) 0xdeadbeef /* IEIPersistFile_fnIsDirty */,
450 IEIPersistFile_fnLoad
,
451 (void *) 0xdeadbeef /* IEIPersistFile_fnSave */,
452 (void *) 0xdeadbeef /* IEIPersistFile_fnSaveCompleted */,
453 (void *) 0xdeadbeef /* IEIPersistFile_fnGetCurFile */