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"
36 #include "wine/debug.h"
40 #include "shell32_main.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
44 /***********************************************************************
45 * IExtractIconW implementation
49 IExtractIconWVtbl
*lpVtbl
;
51 IPersistFileVtbl
*lpvtblPersistFile
;
52 IExtractIconAVtbl
*lpvtblExtractIconA
;
56 static struct IExtractIconAVtbl eiavt
;
57 static struct IExtractIconWVtbl eivt
;
58 static struct IPersistFileVtbl pfvt
;
60 #define _IPersistFile_Offset ((int)(&(((IExtractIconWImpl*)0)->lpvtblPersistFile)))
61 #define _ICOM_THIS_From_IPersistFile(class, name) class* This = (class*)(((char*)name)-_IPersistFile_Offset);
63 #define _IExtractIconA_Offset ((int)(&(((IExtractIconWImpl*)0)->lpvtblExtractIconA)))
64 #define _ICOM_THIS_From_IExtractIconA(class, name) class* This = (class*)(((char*)name)-_IExtractIconA_Offset);
66 /**************************************************************************
67 * IExtractIconW_Constructor
69 IExtractIconW
* IExtractIconW_Constructor(LPCITEMIDLIST pidl
)
71 IExtractIconWImpl
* ei
;
75 ei
= (IExtractIconWImpl
*)HeapAlloc(GetProcessHeap(),0,sizeof(IExtractIconWImpl
));
78 ei
->lpvtblPersistFile
= &pfvt
;
79 ei
->lpvtblExtractIconA
= &eiavt
;
80 ei
->pidl
=ILClone(pidl
);
85 return (IExtractIconW
*)ei
;
87 /**************************************************************************
88 * IExtractIconW_QueryInterface
90 static HRESULT WINAPI
IExtractIconW_fnQueryInterface(IExtractIconW
*iface
, REFIID riid
, LPVOID
*ppvObj
)
92 ICOM_THIS(IExtractIconWImpl
, iface
);
94 TRACE("(%p)->(\n\tIID:\t%s,%p)\n", This
, debugstr_guid(riid
), ppvObj
);
98 if (IsEqualIID(riid
, &IID_IUnknown
)) /*IUnknown*/
102 else if (IsEqualIID(riid
, &IID_IPersistFile
)) /*IExtractIcon*/
104 *ppvObj
= (IPersistFile
*)&(This
->lpvtblPersistFile
);
106 else if (IsEqualIID(riid
, &IID_IExtractIconA
)) /*IExtractIcon*/
108 *ppvObj
= (IExtractIconA
*)&(This
->lpvtblExtractIconA
);
110 else if (IsEqualIID(riid
, &IID_IExtractIconW
)) /*IExtractIcon*/
112 *ppvObj
= (IExtractIconW
*)This
;
117 IExtractIconW_AddRef((IExtractIconW
*) *ppvObj
);
118 TRACE("-- Interface: (%p)->(%p)\n",ppvObj
,*ppvObj
);
121 TRACE("-- Interface: E_NOINTERFACE\n");
122 return E_NOINTERFACE
;
125 /**************************************************************************
126 * IExtractIconW_AddRef
128 static ULONG WINAPI
IExtractIconW_fnAddRef(IExtractIconW
* iface
)
130 ICOM_THIS(IExtractIconWImpl
, iface
);
132 TRACE("(%p)->(count=%lu)\n",This
, This
->ref
);
134 return ++(This
->ref
);
136 /**************************************************************************
137 * IExtractIconW_Release
139 static ULONG WINAPI
IExtractIconW_fnRelease(IExtractIconW
* iface
)
141 ICOM_THIS(IExtractIconWImpl
, iface
);
143 TRACE("(%p)->()\n",This
);
147 TRACE(" destroying IExtractIcon(%p)\n",This
);
149 HeapFree(GetProcessHeap(),0,This
);
155 static HRESULT
getIconLocationForFolder(IExtractIconW
*iface
, UINT uFlags
,
156 LPWSTR szIconFile
, UINT cchMax
, int *piIndex
, UINT
*pwFlags
)
158 ICOM_THIS(IExtractIconWImpl
, iface
);
160 WCHAR path
[MAX_PATH
];
164 if (SUCCEEDED(SHGetPathFromIDListW(This
->pidl
, path
)))
166 static const WCHAR desktopIni
[] = { 'D','e','s','k','t','o','p','.',
170 PathAppendW(path
, desktopIni
);
171 if ((hFile
= CreateFileW(path
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
172 OPEN_EXISTING
, 0, NULL
)) != INVALID_HANDLE_VALUE
)
174 static const WCHAR shellClassInfo
[] = { '.','S','h','e','l','l',
175 'C','l','a','s','s','I','n','f','o',0 };
176 static const WCHAR iconFile
[] =
177 { 'I','c','o','n','F','i','l','e',0 };
178 static const WCHAR clsid
[] = { 'C','L','S','I','D',0 };
179 static const WCHAR clsid2
[] = { 'C','L','S','I','D','2',0 };
180 static const WCHAR defStr
[] = { 0 };
184 if (GetPrivateProfileStringW(shellClassInfo
, iconFile
, defStr
,
185 szIconFile
, cchMax
, path
) && strlenW(szIconFile
))
187 static const WCHAR iconIndex
[] = { 'I','c','o','n',
188 'I','n','d','e','x',0 };
191 *piIndex
= (int)GetPrivateProfileIntW(shellClassInfo
, iconIndex
,
194 else if (GetPrivateProfileStringW(shellClassInfo
, clsid
, defStr
,
195 clsidStr
, sizeof(clsidStr
) / sizeof(WCHAR
), path
) &&
198 if (HCR_GetDefaultIconW(clsidStr
, szIconFile
, cchMax
, &dwNr
))
204 else if (GetPrivateProfileStringW(shellClassInfo
, clsid2
, defStr
,
205 clsidStr
, sizeof(clsidStr
) / sizeof(WCHAR
), path
) &&
208 if (HCR_GetDefaultIconW(clsidStr
, szIconFile
, cchMax
, &dwNr
))
218 static const WCHAR folder
[] = { 'F','o','l','d','e','r',0 };
220 if (!HCR_GetDefaultIconW(folder
, szIconFile
, cchMax
, &dwNr
))
222 lstrcpynW(szIconFile
, swShell32Name
, cchMax
);
225 *piIndex
= (uFlags
& GIL_OPENICON
) ? dwNr
+ 1 : dwNr
;
230 WCHAR swShell32Name
[MAX_PATH
];
232 /**************************************************************************
233 * IExtractIconW_GetIconLocation
235 * mapping filetype to icon
237 static HRESULT WINAPI
IExtractIconW_fnGetIconLocation(
238 IExtractIconW
* iface
,
239 UINT uFlags
, /* GIL_ flags */
243 UINT
* pwFlags
) /* returned GIL_ flags */
245 ICOM_THIS(IExtractIconWImpl
, iface
);
247 char sTemp
[MAX_PATH
];
250 LPITEMIDLIST pSimplePidl
= ILFindLastID(This
->pidl
);
252 TRACE("(%p) (flags=%u %p %u %p %p)\n", This
, uFlags
, szIconFile
, cchMax
, piIndex
, pwFlags
);
257 if (_ILIsDesktop(pSimplePidl
))
259 lstrcpynW(szIconFile
, swShell32Name
, cchMax
);
263 /* my computer and other shell extensions */
264 else if ((riid
= _ILGetGUIDPointer(pSimplePidl
)))
266 static const WCHAR fmt
[] = { 'C','L','S','I','D','\\',
267 '{','%','0','8','l','x','-','%','0','4','x','-','%','0','4','x','-',
268 '%','0','2','x','%','0','2','x','-','%','0','2','x', '%','0','2','x',
269 '%','0','2','x','%','0','2','x','%','0','2','x','%','0','2','x','}',0 };
273 riid
->Data1
, riid
->Data2
, riid
->Data3
,
274 riid
->Data4
[0], riid
->Data4
[1], riid
->Data4
[2], riid
->Data4
[3],
275 riid
->Data4
[4], riid
->Data4
[5], riid
->Data4
[6], riid
->Data4
[7]);
277 if (HCR_GetDefaultIconW(xriid
, szIconFile
, cchMax
, &dwNr
))
283 lstrcpynW(szIconFile
, swShell32Name
, cchMax
);
288 else if (_ILIsDrive (pSimplePidl
))
290 static const WCHAR drive
[] = { 'D','r','i','v','e',0 };
292 if (HCR_GetDefaultIconW(drive
, szIconFile
, cchMax
, &dwNr
))
298 lstrcpynW(szIconFile
, swShell32Name
, cchMax
);
302 else if (_ILIsFolder (pSimplePidl
))
304 getIconLocationForFolder(iface
, uFlags
, szIconFile
, cchMax
, piIndex
,
311 if (_ILIsCPanelStruct(pSimplePidl
))
313 if (SUCCEEDED(CPanel_GetIconLocationW(pSimplePidl
, szIconFile
, cchMax
, piIndex
)))
316 else if (_ILGetExtension(pSimplePidl
, sTemp
, MAX_PATH
))
318 if (HCR_MapTypeToValueA(sTemp
, sTemp
, MAX_PATH
, TRUE
)
319 && HCR_GetDefaultIconA(sTemp
, sTemp
, MAX_PATH
, &dwNr
))
321 if (!lstrcmpA("%1", sTemp
)) /* icon is in the file */
323 SHGetPathFromIDListW(This
->pidl
, szIconFile
);
328 MultiByteToWideChar(CP_ACP
, 0, sTemp
, -1, szIconFile
, cchMax
);
334 else if (!strcasecmp(sTemp
, "lnkfile"))
336 /* extract icon from shell shortcut */
340 if (SUCCEEDED(SHGetDesktopFolder(&dsf
)))
342 HRESULT hr
= IShellFolder_GetUIObjectOf(dsf
, NULL
, 1, (LPCITEMIDLIST
*)&This
->pidl
, &IID_IShellLinkW
, NULL
, (LPVOID
*)&psl
);
346 hr
= IShellLinkW_GetIconLocation(psl
, szIconFile
, MAX_PATH
, piIndex
);
348 if (SUCCEEDED(hr
) && *szIconFile
)
351 IShellLinkW_Release(psl
);
354 IShellFolder_Release(dsf
);
359 if (!found
) /* default icon */
361 lstrcpynW(szIconFile
, swShell32Name
, cchMax
);
366 TRACE("-- %s %x\n", debugstr_w(szIconFile
), *piIndex
);
370 /**************************************************************************
371 * IExtractIconW_Extract
373 static HRESULT WINAPI
IExtractIconW_fnExtract(IExtractIconW
* iface
, LPCWSTR pszFile
, UINT nIconIndex
, HICON
*phiconLarge
, HICON
*phiconSmall
, UINT nIconSize
)
375 ICOM_THIS(IExtractIconWImpl
, iface
);
377 FIXME("(%p) (file=%p index=%u %p %p size=%u) semi-stub\n", This
, debugstr_w(pszFile
), nIconIndex
, phiconLarge
, phiconSmall
, nIconSize
);
380 *phiconLarge
= ImageList_GetIcon(ShellBigIconList
, nIconIndex
, ILD_TRANSPARENT
);
383 *phiconSmall
= ImageList_GetIcon(ShellSmallIconList
, nIconIndex
, ILD_TRANSPARENT
);
388 static struct IExtractIconWVtbl eivt
=
390 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
391 IExtractIconW_fnQueryInterface
,
392 IExtractIconW_fnAddRef
,
393 IExtractIconW_fnRelease
,
394 IExtractIconW_fnGetIconLocation
,
395 IExtractIconW_fnExtract
398 /**************************************************************************
399 * IExtractIconA_Constructor
401 IExtractIconA
* IExtractIconA_Constructor(LPCITEMIDLIST pidl
)
403 ICOM_THIS(IExtractIconWImpl
, IExtractIconW_Constructor(pidl
));
404 IExtractIconA
*eia
= (IExtractIconA
*)&This
->lpvtblExtractIconA
;
406 TRACE("(%p)->(%p)\n", This
, eia
);
409 /**************************************************************************
410 * IExtractIconA_QueryInterface
412 static HRESULT WINAPI
IExtractIconA_fnQueryInterface(IExtractIconA
* iface
, REFIID riid
, LPVOID
*ppvObj
)
414 _ICOM_THIS_From_IExtractIconA(IExtractIconW
, iface
);
416 return IExtractIconW_QueryInterface(This
, riid
, ppvObj
);
419 /**************************************************************************
420 * IExtractIconA_AddRef
422 static ULONG WINAPI
IExtractIconA_fnAddRef(IExtractIconA
* iface
)
424 _ICOM_THIS_From_IExtractIconA(IExtractIconW
, iface
);
426 return IExtractIconW_AddRef(This
);
428 /**************************************************************************
429 * IExtractIconA_Release
431 static ULONG WINAPI
IExtractIconA_fnRelease(IExtractIconA
* iface
)
433 _ICOM_THIS_From_IExtractIconA(IExtractIconW
, iface
);
435 return IExtractIconW_AddRef(This
);
437 /**************************************************************************
438 * IExtractIconA_GetIconLocation
440 * mapping filetype to icon
442 static HRESULT WINAPI
IExtractIconA_fnGetIconLocation(
443 IExtractIconA
* iface
,
451 LPWSTR lpwstrFile
= HeapAlloc(GetProcessHeap(), 0, cchMax
* sizeof(WCHAR
));
452 _ICOM_THIS_From_IExtractIconA(IExtractIconW
, iface
);
454 TRACE("(%p) (flags=%u %p %u %p %p)\n", This
, uFlags
, szIconFile
, cchMax
, piIndex
, pwFlags
);
456 ret
= IExtractIconW_GetIconLocation(This
, uFlags
, lpwstrFile
, cchMax
, piIndex
, pwFlags
);
457 WideCharToMultiByte(CP_ACP
, 0, lpwstrFile
, -1, szIconFile
, cchMax
, NULL
, NULL
);
458 HeapFree(GetProcessHeap(), 0, lpwstrFile
);
460 TRACE("-- %s %x\n", szIconFile
, *piIndex
);
463 /**************************************************************************
464 * IExtractIconA_Extract
466 static HRESULT WINAPI
IExtractIconA_fnExtract(IExtractIconA
* iface
, LPCSTR pszFile
, UINT nIconIndex
, HICON
*phiconLarge
, HICON
*phiconSmall
, UINT nIconSize
)
469 INT len
= MultiByteToWideChar(CP_ACP
, 0, pszFile
, -1, NULL
, 0);
470 LPWSTR lpwstrFile
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
471 _ICOM_THIS_From_IExtractIconA(IExtractIconW
, iface
);
473 TRACE("(%p) (file=%p index=%u %p %p size=%u)\n", This
, pszFile
, nIconIndex
, phiconLarge
, phiconSmall
, nIconSize
);
475 MultiByteToWideChar(CP_ACP
, 0, pszFile
, -1, lpwstrFile
, len
);
476 ret
= IExtractIconW_Extract(This
, lpwstrFile
, nIconIndex
, phiconLarge
, phiconSmall
, nIconSize
);
477 HeapFree(GetProcessHeap(), 0, lpwstrFile
);
481 static struct IExtractIconAVtbl eiavt
=
483 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
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 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
557 IEIPersistFile_fnQueryInterface
,
558 IEIPersistFile_fnAddRef
,
559 IEIPersistFile_fnRelease
,
560 IEIPersistFile_fnGetClassID
,
561 (void *) 0xdeadbeef /* IEIPersistFile_fnIsDirty */,
562 IEIPersistFile_fnLoad
,
563 (void *) 0xdeadbeef /* IEIPersistFile_fnSave */,
564 (void *) 0xdeadbeef /* IEIPersistFile_fnSaveCompleted */,
565 (void *) 0xdeadbeef /* IEIPersistFile_fnGetCurFile */