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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
33 #include "wine/debug.h"
36 #include "shell32_main.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
42 /***********************************************************************
43 * IExtractIconW implementation
47 IExtractIconW IExtractIconW_iface
;
48 IExtractIconA IExtractIconA_iface
;
49 IPersistFile IPersistFile_iface
;
54 static inline IExtractIconWImpl
*impl_from_IExtractIconW(IExtractIconW
*iface
)
56 return CONTAINING_RECORD(iface
, IExtractIconWImpl
, IExtractIconW_iface
);
59 static inline IExtractIconWImpl
*impl_from_IExtractIconA(IExtractIconA
*iface
)
61 return CONTAINING_RECORD(iface
, IExtractIconWImpl
, IExtractIconA_iface
);
64 static inline IExtractIconWImpl
*impl_from_IPersistFile(IPersistFile
*iface
)
66 return CONTAINING_RECORD(iface
, IExtractIconWImpl
, IPersistFile_iface
);
70 /**************************************************************************
71 * IExtractIconW::QueryInterface
73 static HRESULT WINAPI
IExtractIconW_fnQueryInterface(IExtractIconW
*iface
, REFIID riid
,
76 IExtractIconWImpl
*This
= impl_from_IExtractIconW(iface
);
78 TRACE("(%p)->(\n\tIID:\t%s,%p)\n", This
, debugstr_guid(riid
), ppv
);
81 if (IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IExtractIconW
))
83 else if (IsEqualIID(riid
, &IID_IPersistFile
))
84 *ppv
= &This
->IPersistFile_iface
;
85 else if (IsEqualIID(riid
, &IID_IExtractIconA
))
86 *ppv
= &This
->IExtractIconA_iface
;
90 IUnknown_AddRef((IUnknown
*)*ppv
);
91 TRACE("-- Interface: (%p)->(%p)\n", ppv
, *ppv
);
94 TRACE("-- Interface: E_NOINTERFACE\n");
98 /**************************************************************************
99 * IExtractIconW::AddRef
101 static ULONG WINAPI
IExtractIconW_fnAddRef(IExtractIconW
* iface
)
103 IExtractIconWImpl
*This
= impl_from_IExtractIconW(iface
);
104 ULONG refCount
= InterlockedIncrement(&This
->ref
);
106 TRACE("(%p)->(count=%lu)\n", This
, refCount
- 1);
110 /**************************************************************************
111 * IExtractIconW::Release
113 static ULONG WINAPI
IExtractIconW_fnRelease(IExtractIconW
* iface
)
115 IExtractIconWImpl
*This
= impl_from_IExtractIconW(iface
);
116 ULONG refCount
= InterlockedDecrement(&This
->ref
);
118 TRACE("(%p)->(count=%lu)\n", This
, refCount
+ 1);
122 TRACE(" destroying IExtractIcon(%p)\n",This
);
129 static HRESULT
getIconLocationForFolder(IExtractIconWImpl
*This
, UINT uFlags
, LPWSTR szIconFile
,
130 UINT cchMax
, int *piIndex
, UINT
*pwFlags
)
133 WCHAR wszPath
[MAX_PATH
];
134 WCHAR wszCLSIDValue
[CHARS_IN_GUID
];
136 if (SHELL32_GetCustomFolderAttribute(This
->pidl
, L
".ShellClassInfo", L
"IconFile",
139 WCHAR wszIconIndex
[10];
140 SHELL32_GetCustomFolderAttribute(This
->pidl
, L
".ShellClassInfo", L
"IconIndex",
142 *piIndex
= wcstol(wszIconIndex
, NULL
, 10);
144 else if (SHELL32_GetCustomFolderAttribute(This
->pidl
, L
".ShellClassInfo", L
"CLSID",
145 wszCLSIDValue
, CHARS_IN_GUID
) &&
146 HCR_GetDefaultIconW(wszCLSIDValue
, szIconFile
, cchMax
, &icon_idx
))
150 else if (SHELL32_GetCustomFolderAttribute(This
->pidl
, L
".ShellClassInfo", L
"CLSID2",
151 wszCLSIDValue
, CHARS_IN_GUID
) &&
152 HCR_GetDefaultIconW(wszCLSIDValue
, szIconFile
, cchMax
, &icon_idx
))
158 if (!HCR_GetDefaultIconW(L
"Folder", szIconFile
, cchMax
, &icon_idx
))
160 lstrcpynW(szIconFile
, swShell32Name
, cchMax
);
161 icon_idx
= -IDI_SHELL_FOLDER
;
164 if (uFlags
& GIL_OPENICON
)
165 *piIndex
= icon_idx
<0? icon_idx
-1: icon_idx
+1;
173 WCHAR swShell32Name
[MAX_PATH
];
175 /**************************************************************************
176 * IExtractIconW::GetIconLocation
178 * mapping filetype to icon
180 static HRESULT WINAPI
IExtractIconW_fnGetIconLocation(IExtractIconW
* iface
, UINT uFlags
,
181 LPWSTR szIconFile
, UINT cchMax
, int * piIndex
, UINT
* pwFlags
)
183 IExtractIconWImpl
*This
= impl_from_IExtractIconW(iface
);
184 char sTemp
[MAX_PATH
];
187 LPITEMIDLIST pSimplePidl
= ILFindLastID(This
->pidl
);
189 TRACE("(%p) (flags=%u, %p, %u, %p, %p)\n", This
, uFlags
, szIconFile
,
190 cchMax
, piIndex
, pwFlags
);
195 if (_ILIsDesktop(pSimplePidl
))
197 lstrcpynW(szIconFile
, swShell32Name
, cchMax
);
198 *piIndex
= -IDI_SHELL_DESKTOP
;
201 /* my computer and other shell extensions */
202 else if ((riid
= _ILGetGUIDPointer(pSimplePidl
)))
206 swprintf(xriid
, ARRAY_SIZE(xriid
), L
"CLSID\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
207 riid
->Data1
, riid
->Data2
, riid
->Data3
,
208 riid
->Data4
[0], riid
->Data4
[1], riid
->Data4
[2], riid
->Data4
[3],
209 riid
->Data4
[4], riid
->Data4
[5], riid
->Data4
[6], riid
->Data4
[7]);
211 if (HCR_GetDefaultIconW(xriid
, szIconFile
, cchMax
, &icon_idx
))
217 lstrcpynW(szIconFile
, swShell32Name
, cchMax
);
218 if(IsEqualGUID(riid
, &CLSID_MyComputer
))
219 *piIndex
= -IDI_SHELL_MY_COMPUTER
;
220 else if(IsEqualGUID(riid
, &CLSID_MyDocuments
))
221 *piIndex
= -IDI_SHELL_MY_DOCUMENTS
;
222 else if(IsEqualGUID(riid
, &CLSID_NetworkPlaces
))
223 *piIndex
= -IDI_SHELL_MY_NETWORK_PLACES
;
224 else if(IsEqualGUID(riid
, &CLSID_UnixFolder
) ||
225 IsEqualGUID(riid
, &CLSID_UnixDosFolder
))
226 *piIndex
= -IDI_SHELL_DRIVE
;
228 *piIndex
= -IDI_SHELL_FOLDER
;
232 else if (_ILIsDrive (pSimplePidl
))
236 if (_ILGetDrive(pSimplePidl
, sTemp
, MAX_PATH
))
238 switch(GetDriveTypeA(sTemp
))
240 case DRIVE_REMOVABLE
: icon_idx
= IDI_SHELL_FLOPPY
; break;
241 case DRIVE_CDROM
: icon_idx
= IDI_SHELL_OPTICAL_DRIVE
; break;
242 case DRIVE_REMOTE
: icon_idx
= IDI_SHELL_NETDRIVE
; break;
243 case DRIVE_RAMDISK
: icon_idx
= IDI_SHELL_RAMDISK
; break;
249 lstrcpynW(szIconFile
, swShell32Name
, cchMax
);
250 *piIndex
= -icon_idx
;
254 if (HCR_GetDefaultIconW(L
"Drive", szIconFile
, cchMax
, &icon_idx
))
260 lstrcpynW(szIconFile
, swShell32Name
, cchMax
);
261 *piIndex
= -IDI_SHELL_DRIVE
;
265 else if (_ILIsFolder (pSimplePidl
))
267 getIconLocationForFolder(This
, uFlags
, szIconFile
, cchMax
, piIndex
, pwFlags
);
273 if (_ILIsCPanelStruct(pSimplePidl
))
275 if (SUCCEEDED(CPanel_GetIconLocationW(pSimplePidl
, szIconFile
, cchMax
, piIndex
)))
278 else if (_ILGetExtension(pSimplePidl
, sTemp
, MAX_PATH
))
280 if (HCR_MapTypeToValueA(sTemp
, sTemp
, MAX_PATH
, TRUE
)
281 && HCR_GetDefaultIconA(sTemp
, sTemp
, MAX_PATH
, &icon_idx
))
283 if (!lstrcmpA("%1", sTemp
)) /* icon is in the file */
285 SHGetPathFromIDListW(This
->pidl
, szIconFile
);
290 MultiByteToWideChar(CP_ACP
, 0, sTemp
, -1, szIconFile
, cchMax
);
296 else if (!lstrcmpiA(sTemp
, "lnkfile"))
298 /* extract icon from shell shortcut */
302 if (SUCCEEDED(SHGetDesktopFolder(&dsf
)))
304 HRESULT hr
= IShellFolder_GetUIObjectOf(dsf
, NULL
, 1, (LPCITEMIDLIST
*)&This
->pidl
, &IID_IShellLinkW
, NULL
, (LPVOID
*)&psl
);
308 hr
= IShellLinkW_GetIconLocation(psl
, szIconFile
, cchMax
, piIndex
);
310 if (SUCCEEDED(hr
) && *szIconFile
)
313 IShellLinkW_Release(psl
);
316 IShellFolder_Release(dsf
);
321 if (!found
) /* default icon */
323 lstrcpynW(szIconFile
, swShell32Name
, cchMax
);
328 TRACE("-- %s %x\n", debugstr_w(szIconFile
), *piIndex
);
332 /**************************************************************************
333 * IExtractIconW::Extract
335 static HRESULT WINAPI
IExtractIconW_fnExtract(IExtractIconW
* iface
, LPCWSTR pszFile
,
336 UINT nIconIndex
, HICON
*phiconLarge
, HICON
*phiconSmall
, UINT nIconSize
)
338 IExtractIconWImpl
*This
= impl_from_IExtractIconW(iface
);
340 HIMAGELIST big_icons
, small_icons
;
342 FIXME("(%p) (file=%s index=%d %p %p size=%08x) semi-stub\n", This
, debugstr_w(pszFile
),
343 (signed)nIconIndex
, phiconLarge
, phiconSmall
, nIconSize
);
345 index
= SIC_GetIconIndex(pszFile
, nIconIndex
, 0);
346 Shell_GetImageLists( &big_icons
, &small_icons
);
348 *phiconLarge
= ImageList_GetIcon(big_icons
, index
, ILD_TRANSPARENT
);
351 *phiconSmall
= ImageList_GetIcon(small_icons
, index
, ILD_TRANSPARENT
);
356 static const IExtractIconWVtbl eivt
=
358 IExtractIconW_fnQueryInterface
,
359 IExtractIconW_fnAddRef
,
360 IExtractIconW_fnRelease
,
361 IExtractIconW_fnGetIconLocation
,
362 IExtractIconW_fnExtract
365 /**************************************************************************
366 * IExtractIconA::QueryInterface
368 static HRESULT WINAPI
IExtractIconA_fnQueryInterface(IExtractIconA
* iface
, REFIID riid
,
371 IExtractIconWImpl
*This
= impl_from_IExtractIconA(iface
);
373 return IExtractIconW_QueryInterface(&This
->IExtractIconW_iface
, riid
, ppv
);
376 /**************************************************************************
377 * IExtractIconA::AddRef
379 static ULONG WINAPI
IExtractIconA_fnAddRef(IExtractIconA
* iface
)
381 IExtractIconWImpl
*This
= impl_from_IExtractIconA(iface
);
383 return IExtractIconW_AddRef(&This
->IExtractIconW_iface
);
385 /**************************************************************************
386 * IExtractIconA::Release
388 static ULONG WINAPI
IExtractIconA_fnRelease(IExtractIconA
* iface
)
390 IExtractIconWImpl
*This
= impl_from_IExtractIconA(iface
);
392 return IExtractIconW_Release(&This
->IExtractIconW_iface
);
394 /**************************************************************************
395 * IExtractIconA::GetIconLocation
397 * mapping filetype to icon
399 static HRESULT WINAPI
IExtractIconA_fnGetIconLocation(IExtractIconA
* iface
, UINT uFlags
,
400 LPSTR szIconFile
, UINT cchMax
, int * piIndex
, UINT
* pwFlags
)
402 IExtractIconWImpl
*This
= impl_from_IExtractIconA(iface
);
404 WCHAR
*lpwstrFile
= malloc(cchMax
* sizeof(WCHAR
));
406 TRACE("(%p) (flags=%u %p %u %p %p)\n", This
, uFlags
, szIconFile
, cchMax
, piIndex
, pwFlags
);
408 ret
= IExtractIconW_GetIconLocation(&This
->IExtractIconW_iface
, uFlags
, lpwstrFile
, cchMax
,
410 WideCharToMultiByte(CP_ACP
, 0, lpwstrFile
, -1, szIconFile
, cchMax
, NULL
, NULL
);
413 TRACE("-- %s %x\n", szIconFile
, *piIndex
);
416 /**************************************************************************
417 * IExtractIconA::Extract
419 static HRESULT WINAPI
IExtractIconA_fnExtract(IExtractIconA
* iface
, LPCSTR pszFile
,
420 UINT nIconIndex
, HICON
*phiconLarge
, HICON
*phiconSmall
, UINT nIconSize
)
422 IExtractIconWImpl
*This
= impl_from_IExtractIconA(iface
);
424 INT len
= MultiByteToWideChar(CP_ACP
, 0, pszFile
, -1, NULL
, 0);
425 WCHAR
*lpwstrFile
= malloc(len
* sizeof(WCHAR
));
427 TRACE("(%p) (file=%p index=%u %p %p size=%u)\n", This
, pszFile
, nIconIndex
, phiconLarge
, phiconSmall
, nIconSize
);
429 MultiByteToWideChar(CP_ACP
, 0, pszFile
, -1, lpwstrFile
, len
);
430 ret
= IExtractIconW_Extract(&This
->IExtractIconW_iface
, lpwstrFile
, nIconIndex
, phiconLarge
,
431 phiconSmall
, nIconSize
);
436 static const IExtractIconAVtbl eiavt
=
438 IExtractIconA_fnQueryInterface
,
439 IExtractIconA_fnAddRef
,
440 IExtractIconA_fnRelease
,
441 IExtractIconA_fnGetIconLocation
,
442 IExtractIconA_fnExtract
445 /************************************************************************
446 * IEIPersistFile::QueryInterface
448 static HRESULT WINAPI
IEIPersistFile_fnQueryInterface(IPersistFile
*iface
, REFIID iid
,
451 IExtractIconWImpl
*This
= impl_from_IPersistFile(iface
);
453 return IExtractIconW_QueryInterface(&This
->IExtractIconW_iface
, iid
, ppv
);
456 /************************************************************************
457 * IEIPersistFile::AddRef
459 static ULONG WINAPI
IEIPersistFile_fnAddRef(IPersistFile
*iface
)
461 IExtractIconWImpl
*This
= impl_from_IPersistFile(iface
);
463 return IExtractIconW_AddRef(&This
->IExtractIconW_iface
);
466 /************************************************************************
467 * IEIPersistFile::Release
469 static ULONG WINAPI
IEIPersistFile_fnRelease(IPersistFile
*iface
)
471 IExtractIconWImpl
*This
= impl_from_IPersistFile(iface
);
473 return IExtractIconW_Release(&This
->IExtractIconW_iface
);
476 /************************************************************************
477 * IEIPersistFile::GetClassID
479 static HRESULT WINAPI
IEIPersistFile_fnGetClassID(IPersistFile
*iface
, LPCLSID lpClassId
)
481 CLSID StdFolderID
= { 0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} };
486 *lpClassId
= StdFolderID
;
491 /************************************************************************
492 * IEIPersistFile_Load
494 static HRESULT WINAPI
IEIPersistFile_fnLoad(IPersistFile
* iface
, LPCOLESTR pszFileName
,
497 IExtractIconWImpl
*This
= impl_from_IPersistFile(iface
);
503 static const IPersistFileVtbl pfvt
=
505 IEIPersistFile_fnQueryInterface
,
506 IEIPersistFile_fnAddRef
,
507 IEIPersistFile_fnRelease
,
508 IEIPersistFile_fnGetClassID
,
509 (void *) 0xdeadbeef /* IEIPersistFile_fnIsDirty */,
510 IEIPersistFile_fnLoad
,
511 (void *) 0xdeadbeef /* IEIPersistFile_fnSave */,
512 (void *) 0xdeadbeef /* IEIPersistFile_fnSaveCompleted */,
513 (void *) 0xdeadbeef /* IEIPersistFile_fnGetCurFile */
516 static IExtractIconWImpl
*extracticon_create(LPCITEMIDLIST pidl
)
518 IExtractIconWImpl
*ei
;
522 ei
= malloc(sizeof(*ei
));
524 ei
->IExtractIconW_iface
.lpVtbl
= &eivt
;
525 ei
->IExtractIconA_iface
.lpVtbl
= &eiavt
;
526 ei
->IPersistFile_iface
.lpVtbl
= &pfvt
;
527 ei
->pidl
=ILClone(pidl
);
535 IExtractIconW
*IExtractIconW_Constructor(LPCITEMIDLIST pidl
)
537 IExtractIconWImpl
*ei
= extracticon_create(pidl
);
539 return &ei
->IExtractIconW_iface
;
542 IExtractIconA
*IExtractIconA_Constructor(LPCITEMIDLIST pidl
)
544 IExtractIconWImpl
*ei
= extracticon_create(pidl
);
546 return &ei
->IExtractIconA_iface
;