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
21 #include "wine/port.h"
31 #include "undocshell.h"
34 #include "wine/debug.h"
38 #include "shell32_main.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(shell);
42 /***********************************************************************
43 * IExtractIconW implementation
47 ICOM_VFIELD(IExtractIconW);
49 ICOM_VTABLE(IPersistFile)* lpvtblPersistFile;
50 ICOM_VTABLE(IExtractIconA)* lpvtblExtractIconA;
54 static struct ICOM_VTABLE(IExtractIconA) eiavt;
55 static struct ICOM_VTABLE(IExtractIconW) eivt;
56 static struct ICOM_VTABLE(IPersistFile) pfvt;
58 #define _IPersistFile_Offset ((int)(&(((IExtractIconWImpl*)0)->lpvtblPersistFile)))
59 #define _ICOM_THIS_From_IPersistFile(class, name) class* This = (class*)(((char*)name)-_IPersistFile_Offset);
61 #define _IExtractIconA_Offset ((int)(&(((IExtractIconWImpl*)0)->lpvtblExtractIconA)))
62 #define _ICOM_THIS_From_IExtractIconA(class, name) class* This = (class*)(((char*)name)-_IExtractIconA_Offset);
64 /**************************************************************************
65 * IExtractIconW_Constructor
67 IExtractIconW* IExtractIconW_Constructor(LPCITEMIDLIST pidl)
69 IExtractIconWImpl* ei;
73 ei = (IExtractIconWImpl*)HeapAlloc(GetProcessHeap(),0,sizeof(IExtractIconWImpl));
76 ei->lpvtblPersistFile = &pfvt;
77 ei->lpvtblExtractIconA = &eiavt;
78 ei->pidl=ILClone(pidl);
83 return (IExtractIconW *)ei;
85 /**************************************************************************
86 * IExtractIconW_QueryInterface
88 static HRESULT WINAPI IExtractIconW_fnQueryInterface(IExtractIconW *iface, REFIID riid, LPVOID *ppvObj)
90 ICOM_THIS(IExtractIconWImpl, iface);
92 TRACE("(%p)->(\n\tIID:\t%s,%p)\n", This, debugstr_guid(riid), ppvObj);
96 if (IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
100 else if (IsEqualIID(riid, &IID_IPersistFile)) /*IExtractIcon*/
102 *ppvObj = (IPersistFile*)&(This->lpvtblPersistFile);
104 else if (IsEqualIID(riid, &IID_IExtractIconA)) /*IExtractIcon*/
106 *ppvObj = (IExtractIconA*)&(This->lpvtblExtractIconA);
108 else if (IsEqualIID(riid, &IID_IExtractIconW)) /*IExtractIcon*/
110 *ppvObj = (IExtractIconW*)This;
115 IExtractIconW_AddRef((IExtractIconW*) *ppvObj);
116 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
119 TRACE("-- Interface: E_NOINTERFACE\n");
120 return E_NOINTERFACE;
123 /**************************************************************************
124 * IExtractIconW_AddRef
126 static ULONG WINAPI IExtractIconW_fnAddRef(IExtractIconW * iface)
128 ICOM_THIS(IExtractIconWImpl, iface);
130 TRACE("(%p)->(count=%lu)\n",This, This->ref );
132 return ++(This->ref);
134 /**************************************************************************
135 * IExtractIconW_Release
137 static ULONG WINAPI IExtractIconW_fnRelease(IExtractIconW * iface)
139 ICOM_THIS(IExtractIconWImpl, iface);
141 TRACE("(%p)->()\n",This);
145 TRACE(" destroying IExtractIcon(%p)\n",This);
147 HeapFree(GetProcessHeap(),0,This);
153 WCHAR swShell32Name[MAX_PATH];
155 /**************************************************************************
156 * IExtractIconW_GetIconLocation
158 * mapping filetype to icon
160 static HRESULT WINAPI IExtractIconW_fnGetIconLocation(
161 IExtractIconW * iface,
162 UINT uFlags, /* GIL_ flags */
166 UINT * pwFlags) /* returned GIL_ flags */
168 ICOM_THIS(IExtractIconWImpl, iface);
170 char sTemp[MAX_PATH];
173 LPITEMIDLIST pSimplePidl = ILFindLastID(This->pidl);
175 TRACE("(%p) (flags=%u %p %u %p %p)\n", This, uFlags, szIconFile, cchMax, piIndex, pwFlags);
180 if (_ILIsDesktop(pSimplePidl))
182 lstrcpynW(szIconFile, swShell32Name, cchMax);
186 /* my computer and other shell extensions */
187 else if ((riid = _ILGetGUIDPointer(pSimplePidl)))
191 sprintf(xriid, "CLSID\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
192 riid->Data1, riid->Data2, riid->Data3,
193 riid->Data4[0], riid->Data4[1], riid->Data4[2], riid->Data4[3],
194 riid->Data4[4], riid->Data4[5], riid->Data4[6], riid->Data4[7]);
196 if (HCR_GetDefaultIconA(xriid, sTemp, MAX_PATH, &dwNr))
198 MultiByteToWideChar(CP_ACP, 0, sTemp, -1, szIconFile, cchMax);
203 lstrcpynW(szIconFile, swShell32Name, cchMax);
208 else if (_ILIsDrive (pSimplePidl))
210 if (HCR_GetDefaultIconA("Drive", sTemp, MAX_PATH, &dwNr))
212 MultiByteToWideChar(CP_ACP, 0, sTemp, -1, szIconFile, cchMax);
217 lstrcpynW(szIconFile, swShell32Name, cchMax);
221 else if (_ILIsFolder (pSimplePidl))
223 if (HCR_GetDefaultIconA("Folder", sTemp, MAX_PATH, &dwNr))
225 MultiByteToWideChar(CP_ACP, 0, sTemp, -1, szIconFile, cchMax);
229 lstrcpynW(szIconFile, swShell32Name, cchMax);
232 *piIndex = (uFlags & GIL_OPENICON) ? dwNr + 1 : dwNr;
234 else /* object is file */
236 if (_ILGetExtension(pSimplePidl, sTemp, MAX_PATH)
237 && HCR_MapTypeToValueA(sTemp, sTemp, MAX_PATH, TRUE)
238 && HCR_GetDefaultIconA(sTemp, sTemp, MAX_PATH, &dwNr))
240 if (!lstrcmpA("%1", sTemp)) /* icon is in the file */
242 SHGetPathFromIDListW(This->pidl, szIconFile);
247 MultiByteToWideChar(CP_ACP, 0, sTemp, -1, szIconFile, cchMax);
251 else /* default icon */
253 lstrcpynW(szIconFile, swShell32Name, cchMax);
258 TRACE("-- %s %x\n", debugstr_w(szIconFile), *piIndex);
261 /**************************************************************************
262 * IExtractIconW_Extract
264 static HRESULT WINAPI IExtractIconW_fnExtract(IExtractIconW * iface, LPCWSTR pszFile, UINT nIconIndex, HICON *phiconLarge, HICON *phiconSmall, UINT nIconSize)
266 ICOM_THIS(IExtractIconWImpl, iface);
268 FIXME("(%p) (file=%p index=%u %p %p size=%u) semi-stub\n", This, debugstr_w(pszFile), nIconIndex, phiconLarge, phiconSmall, nIconSize);
271 *phiconLarge = ImageList_GetIcon(ShellBigIconList, nIconIndex, ILD_TRANSPARENT);
274 *phiconSmall = ImageList_GetIcon(ShellSmallIconList, nIconIndex, ILD_TRANSPARENT);
279 static struct ICOM_VTABLE(IExtractIconW) eivt =
281 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
282 IExtractIconW_fnQueryInterface,
283 IExtractIconW_fnAddRef,
284 IExtractIconW_fnRelease,
285 IExtractIconW_fnGetIconLocation,
286 IExtractIconW_fnExtract
289 /**************************************************************************
290 * IExtractIconA_Constructor
292 IExtractIconA* IExtractIconA_Constructor(LPCITEMIDLIST pidl)
294 ICOM_THIS(IExtractIconWImpl, IExtractIconW_Constructor(pidl));
295 IExtractIconA *eia = (IExtractIconA *)&This->lpvtblExtractIconA;
297 TRACE("(%p)->(%p)\n", This, eia);
300 /**************************************************************************
301 * IExtractIconA_QueryInterface
303 static HRESULT WINAPI IExtractIconA_fnQueryInterface(IExtractIconA * iface, REFIID riid, LPVOID *ppvObj)
305 _ICOM_THIS_From_IExtractIconA(IExtractIconW, iface);
307 return IExtractIconW_QueryInterface(This, riid, ppvObj);
310 /**************************************************************************
311 * IExtractIconA_AddRef
313 static ULONG WINAPI IExtractIconA_fnAddRef(IExtractIconA * iface)
315 _ICOM_THIS_From_IExtractIconA(IExtractIconW, iface);
317 return IExtractIconW_AddRef(This);
319 /**************************************************************************
320 * IExtractIconA_Release
322 static ULONG WINAPI IExtractIconA_fnRelease(IExtractIconA * iface)
324 _ICOM_THIS_From_IExtractIconA(IExtractIconW, iface);
326 return IExtractIconW_AddRef(This);
328 /**************************************************************************
329 * IExtractIconA_GetIconLocation
331 * mapping filetype to icon
333 static HRESULT WINAPI IExtractIconA_fnGetIconLocation(
334 IExtractIconA * iface,
342 LPWSTR lpwstrFile = HeapAlloc(GetProcessHeap(), 0, cchMax * sizeof(WCHAR));
343 _ICOM_THIS_From_IExtractIconA(IExtractIconW, iface);
345 TRACE("(%p) (flags=%u %p %u %p %p)\n", This, uFlags, szIconFile, cchMax, piIndex, pwFlags);
347 ret = IExtractIconW_GetIconLocation(This, uFlags, lpwstrFile, cchMax, piIndex, pwFlags);
348 WideCharToMultiByte(CP_ACP, 0, lpwstrFile, -1, szIconFile, cchMax, NULL, NULL);
349 HeapFree(GetProcessHeap(), 0, lpwstrFile);
351 TRACE("-- %s %x\n", szIconFile, *piIndex);
354 /**************************************************************************
355 * IExtractIconA_Extract
357 static HRESULT WINAPI IExtractIconA_fnExtract(IExtractIconA * iface, LPCSTR pszFile, UINT nIconIndex, HICON *phiconLarge, HICON *phiconSmall, UINT nIconSize)
360 INT len = MultiByteToWideChar(CP_ACP, 0, pszFile, -1, NULL, 0);
361 LPWSTR lpwstrFile = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
362 _ICOM_THIS_From_IExtractIconA(IExtractIconW, iface);
364 TRACE("(%p) (file=%p index=%u %p %p size=%u)\n", This, pszFile, nIconIndex, phiconLarge, phiconSmall, nIconSize);
366 MultiByteToWideChar(CP_ACP, 0, pszFile, -1, lpwstrFile, len);
367 ret = IExtractIconW_Extract(This, lpwstrFile, nIconIndex, phiconLarge, phiconSmall, nIconSize);
368 HeapFree(GetProcessHeap(), 0, lpwstrFile);
372 static struct ICOM_VTABLE(IExtractIconA) eiavt =
374 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
375 IExtractIconA_fnQueryInterface,
376 IExtractIconA_fnAddRef,
377 IExtractIconA_fnRelease,
378 IExtractIconA_fnGetIconLocation,
379 IExtractIconA_fnExtract
382 /************************************************************************
383 * IEIPersistFile_QueryInterface (IUnknown)
385 static HRESULT WINAPI IEIPersistFile_fnQueryInterface(
390 _ICOM_THIS_From_IPersistFile(IExtractIconW, iface);
392 return IExtractIconW_QueryInterface(This, iid, ppvObj);
395 /************************************************************************
396 * IEIPersistFile_AddRef (IUnknown)
398 static ULONG WINAPI IEIPersistFile_fnAddRef(
401 _ICOM_THIS_From_IPersistFile(IExtractIconW, iface);
403 return IExtractIconW_AddRef(This);
406 /************************************************************************
407 * IEIPersistFile_Release (IUnknown)
409 static ULONG WINAPI IEIPersistFile_fnRelease(
412 _ICOM_THIS_From_IPersistFile(IExtractIconW, iface);
414 return IExtractIconW_Release(This);
417 /************************************************************************
418 * IEIPersistFile_GetClassID (IPersist)
420 static HRESULT WINAPI IEIPersistFile_fnGetClassID(
424 CLSID StdFolderID = { 0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} };
429 memcpy(lpClassId, &StdFolderID, sizeof(StdFolderID));
434 /************************************************************************
435 * IEIPersistFile_Load (IPersistFile)
437 static HRESULT WINAPI IEIPersistFile_fnLoad(IPersistFile* iface, LPCOLESTR pszFileName, DWORD dwMode)
439 _ICOM_THIS_From_IPersistFile(IExtractIconW, iface);
445 static struct ICOM_VTABLE(IPersistFile) pfvt =
447 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
448 IEIPersistFile_fnQueryInterface,
449 IEIPersistFile_fnAddRef,
450 IEIPersistFile_fnRelease,
451 IEIPersistFile_fnGetClassID,
452 (void *) 0xdeadbeef /* IEIPersistFile_fnIsDirty */,
453 IEIPersistFile_fnLoad,
454 (void *) 0xdeadbeef /* IEIPersistFile_fnSave */,
455 (void *) 0xdeadbeef /* IEIPersistFile_fnSaveCompleted */,
456 (void *) 0xdeadbeef /* IEIPersistFile_fnGetCurFile */