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"
34 #include "undocshell.h"
38 #include "wine/debug.h"
41 #include "shell32_main.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(shell);
47 /***********************************************************************
48 * IExtractIconW implementation
52 IExtractIconWVtbl *lpVtbl;
54 IPersistFileVtbl *lpvtblPersistFile;
55 IExtractIconAVtbl *lpvtblExtractIconA;
59 static struct IExtractIconAVtbl eiavt;
60 static struct IExtractIconWVtbl eivt;
61 static struct IPersistFileVtbl pfvt;
63 #define _IPersistFile_Offset ((int)(&(((IExtractIconWImpl*)0)->lpvtblPersistFile)))
64 #define _ICOM_THIS_From_IPersistFile(class, name) class* This = (class*)(((char*)name)-_IPersistFile_Offset);
66 #define _IExtractIconA_Offset ((int)(&(((IExtractIconWImpl*)0)->lpvtblExtractIconA)))
67 #define _ICOM_THIS_From_IExtractIconA(class, name) class* This = (class*)(((char*)name)-_IExtractIconA_Offset);
69 /**************************************************************************
70 * IExtractIconW_Constructor
72 IExtractIconW* IExtractIconW_Constructor(LPCITEMIDLIST pidl)
74 IExtractIconWImpl* ei;
78 ei = HeapAlloc(GetProcessHeap(),0,sizeof(IExtractIconWImpl));
81 ei->lpvtblPersistFile = &pfvt;
82 ei->lpvtblExtractIconA = &eiavt;
83 ei->pidl=ILClone(pidl);
88 return (IExtractIconW *)ei;
90 /**************************************************************************
91 * IExtractIconW_QueryInterface
93 static HRESULT WINAPI IExtractIconW_fnQueryInterface(IExtractIconW *iface, REFIID riid, LPVOID *ppvObj)
95 IExtractIconWImpl *This = (IExtractIconWImpl *)iface;
97 TRACE("(%p)->(\n\tIID:\t%s,%p)\n", This, debugstr_guid(riid), ppvObj);
101 if (IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
105 else if (IsEqualIID(riid, &IID_IPersistFile)) /*IExtractIcon*/
107 *ppvObj = (IPersistFile*)&(This->lpvtblPersistFile);
109 else if (IsEqualIID(riid, &IID_IExtractIconA)) /*IExtractIcon*/
111 *ppvObj = (IExtractIconA*)&(This->lpvtblExtractIconA);
113 else if (IsEqualIID(riid, &IID_IExtractIconW)) /*IExtractIcon*/
115 *ppvObj = (IExtractIconW*)This;
120 IExtractIconW_AddRef((IExtractIconW*) *ppvObj);
121 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
124 TRACE("-- Interface: E_NOINTERFACE\n");
125 return E_NOINTERFACE;
128 /**************************************************************************
129 * IExtractIconW_AddRef
131 static ULONG WINAPI IExtractIconW_fnAddRef(IExtractIconW * iface)
133 IExtractIconWImpl *This = (IExtractIconWImpl *)iface;
134 ULONG refCount = InterlockedIncrement(&This->ref);
136 TRACE("(%p)->(count=%lu)\n", This, refCount - 1);
140 /**************************************************************************
141 * IExtractIconW_Release
143 static ULONG WINAPI IExtractIconW_fnRelease(IExtractIconW * iface)
145 IExtractIconWImpl *This = (IExtractIconWImpl *)iface;
146 ULONG refCount = InterlockedDecrement(&This->ref);
148 TRACE("(%p)->(count=%lu)\n", This, refCount + 1);
152 TRACE(" destroying IExtractIcon(%p)\n",This);
154 HeapFree(GetProcessHeap(),0,This);
160 static HRESULT getIconLocationForFolder(IExtractIconW *iface, UINT uFlags,
161 LPWSTR szIconFile, UINT cchMax, int *piIndex, UINT *pwFlags)
163 IExtractIconWImpl *This = (IExtractIconWImpl *)iface;
165 WCHAR wszPath[MAX_PATH];
166 WCHAR wszCLSIDValue[CHARS_IN_GUID];
167 static const WCHAR shellClassInfo[] = { '.','S','h','e','l','l','C','l','a','s','s','I','n','f','o',0 };
168 static const WCHAR iconFile[] = { 'I','c','o','n','F','i','l','e',0 };
169 static const WCHAR clsid[] = { 'C','L','S','I','D',0 };
170 static const WCHAR clsid2[] = { 'C','L','S','I','D','2',0 };
171 static const WCHAR iconIndex[] = { 'I','c','o','n','I','n','d','e','x',0 };
173 if (SHELL32_GetCustomFolderAttribute(This->pidl, shellClassInfo, iconFile,
176 WCHAR wszIconIndex[10];
177 SHELL32_GetCustomFolderAttribute(This->pidl, shellClassInfo, iconIndex,
179 *piIndex = atoiW(wszIconIndex);
181 else if (SHELL32_GetCustomFolderAttribute(This->pidl, shellClassInfo, clsid,
182 wszCLSIDValue, CHARS_IN_GUID) &&
183 HCR_GetDefaultIconW(wszCLSIDValue, szIconFile, cchMax, &dwNr))
187 else if (SHELL32_GetCustomFolderAttribute(This->pidl, shellClassInfo, clsid2,
188 wszCLSIDValue, CHARS_IN_GUID) &&
189 HCR_GetDefaultIconW(wszCLSIDValue, szIconFile, cchMax, &dwNr))
195 static const WCHAR folder[] = { 'F','o','l','d','e','r',0 };
197 if (!HCR_GetDefaultIconW(folder, szIconFile, cchMax, &dwNr))
199 lstrcpynW(szIconFile, swShell32Name, cchMax);
200 dwNr = IDI_SHELL_FOLDER;
202 *piIndex = -((uFlags & GIL_OPENICON) ? dwNr + 1 : dwNr);
207 WCHAR swShell32Name[MAX_PATH];
209 /**************************************************************************
210 * IExtractIconW_GetIconLocation
212 * mapping filetype to icon
214 static HRESULT WINAPI IExtractIconW_fnGetIconLocation(
215 IExtractIconW * iface,
216 UINT uFlags, /* GIL_ flags */
220 UINT * pwFlags) /* returned GIL_ flags */
222 IExtractIconWImpl *This = (IExtractIconWImpl *)iface;
224 char sTemp[MAX_PATH];
227 LPITEMIDLIST pSimplePidl = ILFindLastID(This->pidl);
229 TRACE("(%p) (flags=%u %p %u %p %p)\n", This, uFlags, szIconFile, cchMax, piIndex, pwFlags);
234 if (_ILIsDesktop(pSimplePidl))
236 lstrcpynW(szIconFile, swShell32Name, cchMax);
237 *piIndex = -IDI_SHELL_DESKTOP;
240 /* my computer and other shell extensions */
241 else if ((riid = _ILGetGUIDPointer(pSimplePidl)))
243 static const WCHAR fmt[] = { 'C','L','S','I','D','\\',
244 '{','%','0','8','l','x','-','%','0','4','x','-','%','0','4','x','-',
245 '%','0','2','x','%','0','2','x','-','%','0','2','x', '%','0','2','x',
246 '%','0','2','x','%','0','2','x','%','0','2','x','%','0','2','x','}',0 };
250 riid->Data1, riid->Data2, riid->Data3,
251 riid->Data4[0], riid->Data4[1], riid->Data4[2], riid->Data4[3],
252 riid->Data4[4], riid->Data4[5], riid->Data4[6], riid->Data4[7]);
254 if (HCR_GetDefaultIconW(xriid, szIconFile, cchMax, &dwNr))
260 lstrcpynW(szIconFile, swShell32Name, cchMax);
261 *piIndex = -IDI_SHELL_MYCOMPUTER;
265 else if (_ILIsDrive (pSimplePidl))
267 static const WCHAR drive[] = { 'D','r','i','v','e',0 };
271 if (_ILGetDrive(pSimplePidl, sTemp, MAX_PATH))
273 switch(GetDriveTypeA(sTemp))
275 case DRIVE_REMOVABLE: icon_idx = IDI_SHELL_FLOPPY; break;
276 case DRIVE_CDROM: icon_idx = IDI_SHELL_CDROM; break;
277 case DRIVE_REMOTE: icon_idx = IDI_SHELL_NETDRIVE; break;
278 case DRIVE_RAMDISK: icon_idx = IDI_SHELL_RAMDISK; break;
284 lstrcpynW(szIconFile, swShell32Name, cchMax);
285 *piIndex = -icon_idx;
289 if (HCR_GetDefaultIconW(drive, szIconFile, cchMax, &dwNr))
295 lstrcpynW(szIconFile, swShell32Name, cchMax);
296 *piIndex = -IDI_SHELL_DRIVE;
300 else if (_ILIsFolder (pSimplePidl))
302 getIconLocationForFolder(iface, uFlags, szIconFile, cchMax, piIndex,
309 if (_ILIsCPanelStruct(pSimplePidl))
311 if (SUCCEEDED(CPanel_GetIconLocationW(pSimplePidl, szIconFile, cchMax, piIndex)))
314 else if (_ILGetExtension(pSimplePidl, sTemp, MAX_PATH))
316 if (HCR_MapTypeToValueA(sTemp, sTemp, MAX_PATH, TRUE)
317 && HCR_GetDefaultIconA(sTemp, sTemp, MAX_PATH, &dwNr))
319 if (!lstrcmpA("%1", sTemp)) /* icon is in the file */
321 SHGetPathFromIDListW(This->pidl, szIconFile);
326 MultiByteToWideChar(CP_ACP, 0, sTemp, -1, szIconFile, cchMax);
332 else if (!lstrcmpiA(sTemp, "lnkfile"))
334 /* extract icon from shell shortcut */
338 if (SUCCEEDED(SHGetDesktopFolder(&dsf)))
340 HRESULT hr = IShellFolder_GetUIObjectOf(dsf, NULL, 1, (LPCITEMIDLIST*)&This->pidl, &IID_IShellLinkW, NULL, (LPVOID*)&psl);
344 hr = IShellLinkW_GetIconLocation(psl, szIconFile, MAX_PATH, piIndex);
346 if (SUCCEEDED(hr) && *szIconFile)
349 IShellLinkW_Release(psl);
352 IShellFolder_Release(dsf);
357 if (!found) /* default icon */
359 lstrcpynW(szIconFile, swShell32Name, cchMax);
364 TRACE("-- %s %x\n", debugstr_w(szIconFile), *piIndex);
368 /**************************************************************************
369 * IExtractIconW_Extract
371 static HRESULT WINAPI IExtractIconW_fnExtract(IExtractIconW * iface, LPCWSTR pszFile, UINT nIconIndex, HICON *phiconLarge, HICON *phiconSmall, UINT nIconSize)
373 IExtractIconWImpl *This = (IExtractIconWImpl *)iface;
376 FIXME("(%p) (file=%p index=%d %p %p size=%08x) semi-stub\n", This, debugstr_w(pszFile), (signed)nIconIndex,
377 phiconLarge, phiconSmall, nIconSize);
379 index = SIC_GetIconIndex(pszFile, nIconIndex);
382 *phiconLarge = ImageList_GetIcon(ShellBigIconList, index, ILD_TRANSPARENT);
385 *phiconSmall = ImageList_GetIcon(ShellSmallIconList, index, ILD_TRANSPARENT);
390 static struct IExtractIconWVtbl eivt =
392 IExtractIconW_fnQueryInterface,
393 IExtractIconW_fnAddRef,
394 IExtractIconW_fnRelease,
395 IExtractIconW_fnGetIconLocation,
396 IExtractIconW_fnExtract
399 /**************************************************************************
400 * IExtractIconA_Constructor
402 IExtractIconA* IExtractIconA_Constructor(LPCITEMIDLIST pidl)
404 IExtractIconWImpl *This = (IExtractIconWImpl *)IExtractIconW_Constructor(pidl);
405 IExtractIconA *eia = (IExtractIconA *)&This->lpvtblExtractIconA;
407 TRACE("(%p)->(%p)\n", This, eia);
410 /**************************************************************************
411 * IExtractIconA_QueryInterface
413 static HRESULT WINAPI IExtractIconA_fnQueryInterface(IExtractIconA * iface, REFIID riid, LPVOID *ppvObj)
415 _ICOM_THIS_From_IExtractIconA(IExtractIconW, iface);
417 return IExtractIconW_QueryInterface(This, riid, ppvObj);
420 /**************************************************************************
421 * IExtractIconA_AddRef
423 static ULONG WINAPI IExtractIconA_fnAddRef(IExtractIconA * iface)
425 _ICOM_THIS_From_IExtractIconA(IExtractIconW, iface);
427 return IExtractIconW_AddRef(This);
429 /**************************************************************************
430 * IExtractIconA_Release
432 static ULONG WINAPI IExtractIconA_fnRelease(IExtractIconA * iface)
434 _ICOM_THIS_From_IExtractIconA(IExtractIconW, iface);
436 return IExtractIconW_AddRef(This);
438 /**************************************************************************
439 * IExtractIconA_GetIconLocation
441 * mapping filetype to icon
443 static HRESULT WINAPI IExtractIconA_fnGetIconLocation(
444 IExtractIconA * iface,
452 LPWSTR lpwstrFile = HeapAlloc(GetProcessHeap(), 0, cchMax * sizeof(WCHAR));
453 _ICOM_THIS_From_IExtractIconA(IExtractIconW, iface);
455 TRACE("(%p) (flags=%u %p %u %p %p)\n", This, uFlags, szIconFile, cchMax, piIndex, pwFlags);
457 ret = IExtractIconW_GetIconLocation(This, uFlags, lpwstrFile, cchMax, piIndex, pwFlags);
458 WideCharToMultiByte(CP_ACP, 0, lpwstrFile, -1, szIconFile, cchMax, NULL, NULL);
459 HeapFree(GetProcessHeap(), 0, lpwstrFile);
461 TRACE("-- %s %x\n", szIconFile, *piIndex);
464 /**************************************************************************
465 * IExtractIconA_Extract
467 static HRESULT WINAPI IExtractIconA_fnExtract(IExtractIconA * iface, LPCSTR pszFile, UINT nIconIndex, HICON *phiconLarge, HICON *phiconSmall, UINT nIconSize)
470 INT len = MultiByteToWideChar(CP_ACP, 0, pszFile, -1, NULL, 0);
471 LPWSTR lpwstrFile = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
472 _ICOM_THIS_From_IExtractIconA(IExtractIconW, iface);
474 TRACE("(%p) (file=%p index=%u %p %p size=%u)\n", This, pszFile, nIconIndex, phiconLarge, phiconSmall, nIconSize);
476 MultiByteToWideChar(CP_ACP, 0, pszFile, -1, lpwstrFile, len);
477 ret = IExtractIconW_Extract(This, lpwstrFile, nIconIndex, phiconLarge, phiconSmall, nIconSize);
478 HeapFree(GetProcessHeap(), 0, lpwstrFile);
482 static struct IExtractIconAVtbl eiavt =
484 IExtractIconA_fnQueryInterface,
485 IExtractIconA_fnAddRef,
486 IExtractIconA_fnRelease,
487 IExtractIconA_fnGetIconLocation,
488 IExtractIconA_fnExtract
491 /************************************************************************
492 * IEIPersistFile_QueryInterface (IUnknown)
494 static HRESULT WINAPI IEIPersistFile_fnQueryInterface(
499 _ICOM_THIS_From_IPersistFile(IExtractIconW, iface);
501 return IExtractIconW_QueryInterface(This, iid, ppvObj);
504 /************************************************************************
505 * IEIPersistFile_AddRef (IUnknown)
507 static ULONG WINAPI IEIPersistFile_fnAddRef(
510 _ICOM_THIS_From_IPersistFile(IExtractIconW, iface);
512 return IExtractIconW_AddRef(This);
515 /************************************************************************
516 * IEIPersistFile_Release (IUnknown)
518 static ULONG WINAPI IEIPersistFile_fnRelease(
521 _ICOM_THIS_From_IPersistFile(IExtractIconW, iface);
523 return IExtractIconW_Release(This);
526 /************************************************************************
527 * IEIPersistFile_GetClassID (IPersist)
529 static HRESULT WINAPI IEIPersistFile_fnGetClassID(
533 CLSID StdFolderID = { 0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} };
538 memcpy(lpClassId, &StdFolderID, sizeof(StdFolderID));
543 /************************************************************************
544 * IEIPersistFile_Load (IPersistFile)
546 static HRESULT WINAPI IEIPersistFile_fnLoad(IPersistFile* iface, LPCOLESTR pszFileName, DWORD dwMode)
548 _ICOM_THIS_From_IPersistFile(IExtractIconW, iface);
554 static struct IPersistFileVtbl pfvt =
556 IEIPersistFile_fnQueryInterface,
557 IEIPersistFile_fnAddRef,
558 IEIPersistFile_fnRelease,
559 IEIPersistFile_fnGetClassID,
560 (void *) 0xdeadbeef /* IEIPersistFile_fnIsDirty */,
561 IEIPersistFile_fnLoad,
562 (void *) 0xdeadbeef /* IEIPersistFile_fnSave */,
563 (void *) 0xdeadbeef /* IEIPersistFile_fnSaveCompleted */,
564 (void *) 0xdeadbeef /* IEIPersistFile_fnGetCurFile */