2 * shell icon cache (SIC)
4 * Copyright 1998, 1999 Juergen Schmied
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "wine/port.h"
26 #include <sys/types.h>
38 #include "wine/debug.h"
43 #include "shell32_main.h"
44 #include "undocshell.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
49 /********************** THE ICON CACHE ********************************/
51 #define INVALID_INDEX -1
55 LPWSTR sSourceFile
; /* file (not path!) containing the icon */
56 DWORD dwSourceIndex
; /* index within the file, if it is a resource ID it will be negated */
57 DWORD dwListIndex
; /* index within the iconlist */
58 DWORD dwFlags
; /* GIL_* flags */
60 } SIC_ENTRY
, * LPSIC_ENTRY
;
63 static INIT_ONCE sic_init_once
= INIT_ONCE_STATIC_INIT
;
64 static HIMAGELIST shell_imagelists
[SHIL_SYSSMALL
+1];
66 static CRITICAL_SECTION SHELL32_SicCS
;
67 static CRITICAL_SECTION_DEBUG critsect_debug
=
70 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
71 0, 0, { (DWORD_PTR
)(__FILE__
": SHELL32_SicCS") }
73 static CRITICAL_SECTION SHELL32_SicCS
= { &critsect_debug
, -1, 0, 0, 0, 0 };
76 static const WCHAR WindowMetrics
[] = {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','D','e','s','k','t','o','p','\\',
77 'W','i','n','d','o','w','M','e','t','r','i','c','s',0};
78 static const WCHAR ShellIconSize
[] = {'S','h','e','l','l',' ','I','c','o','n',' ','S','i','z','e',0};
80 #define SIC_COMPARE_LISTINDEX 1
82 /*****************************************************************************
86 * Callback for DPA_Search
88 static INT CALLBACK
SIC_CompareEntries( LPVOID p1
, LPVOID p2
, LPARAM lparam
)
90 LPSIC_ENTRY e1
= p1
, e2
= p2
;
92 TRACE("%p %p %8lx\n", p1
, p2
, lparam
);
94 /* Icons in the cache are keyed by the name of the file they are
95 * loaded from, their resource index and the fact if they have a shortcut
96 * icon overlay or not.
99 if (lparam
& SIC_COMPARE_LISTINDEX
)
100 return e1
->dwListIndex
!= e2
->dwListIndex
;
102 if (e1
->dwSourceIndex
!= e2
->dwSourceIndex
|| /* first the faster one */
103 (e1
->dwFlags
& GIL_FORSHORTCUT
) != (e2
->dwFlags
& GIL_FORSHORTCUT
))
106 if (strcmpiW(e1
->sSourceFile
,e2
->sSourceFile
))
112 /**************************************************************************************
115 * Returns the source file and resource index of an icon with the given imagelist index
117 HRESULT
SIC_get_location( int list_idx
, WCHAR
*file
, DWORD
*size
, int *res_idx
)
119 SIC_ENTRY seek
, *found
;
121 HRESULT hr
= E_INVALIDARG
;
124 seek
.dwListIndex
= list_idx
;
126 EnterCriticalSection( &SHELL32_SicCS
);
128 dpa_idx
= DPA_Search( sic_hdpa
, &seek
, 0, SIC_CompareEntries
, SIC_COMPARE_LISTINDEX
, 0 );
131 found
= DPA_GetPtr( sic_hdpa
, dpa_idx
);
132 needed
= (strlenW( found
->sSourceFile
) + 1) * sizeof(WCHAR
);
135 memcpy( file
, found
->sSourceFile
, needed
);
136 *res_idx
= found
->dwSourceIndex
;
142 hr
= E_NOT_SUFFICIENT_BUFFER
;
145 LeaveCriticalSection( &SHELL32_SicCS
);
150 /* declare SIC_LoadOverlayIcon() */
151 static int SIC_LoadOverlayIcon(int icon_idx
);
153 /*****************************************************************************
154 * SIC_OverlayShortcutImage [internal]
157 * Creates a new icon as a copy of the passed-in icon, overlaid with a
160 static HICON
SIC_OverlayShortcutImage(HICON SourceIcon
, int type
)
162 ICONINFO SourceIconInfo
, ShortcutIconInfo
, TargetIconInfo
;
163 HICON ShortcutIcon
, TargetIcon
;
164 BITMAP SourceBitmapInfo
, ShortcutBitmapInfo
;
169 HBITMAP OldSourceBitmap
= NULL
,
170 OldShortcutBitmap
= NULL
,
171 OldTargetBitmap
= NULL
;
173 static int s_imgListIdx
= -1;
175 /* Get information about the source icon and shortcut overlay */
176 if (! GetIconInfo(SourceIcon
, &SourceIconInfo
)
177 || 0 == GetObjectW(SourceIconInfo
.hbmColor
, sizeof(BITMAP
), &SourceBitmapInfo
))
182 /* search for the shortcut icon only once */
183 if (s_imgListIdx
== -1)
184 s_imgListIdx
= SIC_LoadOverlayIcon(- IDI_SHELL_SHORTCUT
);
185 /* FIXME should use icon index 29 instead of the
186 resource id, but not all icons are present yet
187 so we can't use icon indices */
189 if (s_imgListIdx
!= -1)
190 ShortcutIcon
= ImageList_GetIcon(shell_imagelists
[type
], s_imgListIdx
, ILD_TRANSPARENT
);
194 if (NULL
== ShortcutIcon
|| ! GetIconInfo(ShortcutIcon
, &ShortcutIconInfo
)
195 || 0 == GetObjectW(ShortcutIconInfo
.hbmColor
, sizeof(BITMAP
), &ShortcutBitmapInfo
))
200 TargetIconInfo
= SourceIconInfo
;
201 TargetIconInfo
.hbmMask
= NULL
;
202 TargetIconInfo
.hbmColor
= NULL
;
204 /* Setup the source, shortcut and target masks */
205 SourceDC
= CreateCompatibleDC(NULL
);
206 if (NULL
== SourceDC
) goto fail
;
207 OldSourceBitmap
= SelectObject(SourceDC
, SourceIconInfo
.hbmMask
);
208 if (NULL
== OldSourceBitmap
) goto fail
;
210 ShortcutDC
= CreateCompatibleDC(NULL
);
211 if (NULL
== ShortcutDC
) goto fail
;
212 OldShortcutBitmap
= SelectObject(ShortcutDC
, ShortcutIconInfo
.hbmMask
);
213 if (NULL
== OldShortcutBitmap
) goto fail
;
215 TargetDC
= CreateCompatibleDC(NULL
);
216 if (NULL
== TargetDC
) goto fail
;
217 TargetIconInfo
.hbmMask
= CreateCompatibleBitmap(TargetDC
, SourceBitmapInfo
.bmWidth
,
218 SourceBitmapInfo
.bmHeight
);
219 if (NULL
== TargetIconInfo
.hbmMask
) goto fail
;
220 ScreenDC
= GetDC(NULL
);
221 if (NULL
== ScreenDC
) goto fail
;
222 TargetIconInfo
.hbmColor
= CreateCompatibleBitmap(ScreenDC
, SourceBitmapInfo
.bmWidth
,
223 SourceBitmapInfo
.bmHeight
);
224 ReleaseDC(NULL
, ScreenDC
);
225 if (NULL
== TargetIconInfo
.hbmColor
) goto fail
;
226 OldTargetBitmap
= SelectObject(TargetDC
, TargetIconInfo
.hbmMask
);
227 if (NULL
== OldTargetBitmap
) goto fail
;
229 /* Create the target mask by ANDing the source and shortcut masks */
230 if (! BitBlt(TargetDC
, 0, 0, SourceBitmapInfo
.bmWidth
, SourceBitmapInfo
.bmHeight
,
231 SourceDC
, 0, 0, SRCCOPY
) ||
232 ! BitBlt(TargetDC
, 0, SourceBitmapInfo
.bmHeight
- ShortcutBitmapInfo
.bmHeight
,
233 ShortcutBitmapInfo
.bmWidth
, ShortcutBitmapInfo
.bmHeight
,
234 ShortcutDC
, 0, 0, SRCAND
))
239 /* Setup the source and target xor bitmap */
240 if (NULL
== SelectObject(SourceDC
, SourceIconInfo
.hbmColor
) ||
241 NULL
== SelectObject(TargetDC
, TargetIconInfo
.hbmColor
))
246 /* Copy the source xor bitmap to the target and clear out part of it by using
248 if (! BitBlt(TargetDC
, 0, 0, SourceBitmapInfo
.bmWidth
, SourceBitmapInfo
.bmHeight
,
249 SourceDC
, 0, 0, SRCCOPY
) ||
250 ! BitBlt(TargetDC
, 0, SourceBitmapInfo
.bmHeight
- ShortcutBitmapInfo
.bmHeight
,
251 ShortcutBitmapInfo
.bmWidth
, ShortcutBitmapInfo
.bmHeight
,
252 ShortcutDC
, 0, 0, SRCAND
))
257 if (NULL
== SelectObject(ShortcutDC
, ShortcutIconInfo
.hbmColor
)) goto fail
;
259 /* Now put in the shortcut xor mask */
260 if (! BitBlt(TargetDC
, 0, SourceBitmapInfo
.bmHeight
- ShortcutBitmapInfo
.bmHeight
,
261 ShortcutBitmapInfo
.bmWidth
, ShortcutBitmapInfo
.bmHeight
,
262 ShortcutDC
, 0, 0, SRCINVERT
))
267 /* Clean up, we're not goto'ing to 'fail' after this so we can be lazy and not set
269 SelectObject(TargetDC
, OldTargetBitmap
);
270 DeleteObject(TargetDC
);
271 SelectObject(ShortcutDC
, OldShortcutBitmap
);
272 DeleteObject(ShortcutDC
);
273 SelectObject(SourceDC
, OldSourceBitmap
);
274 DeleteObject(SourceDC
);
276 /* Create the icon using the bitmaps prepared earlier */
277 TargetIcon
= CreateIconIndirect(&TargetIconInfo
);
279 /* CreateIconIndirect copies the bitmaps, so we can release our bitmaps now */
280 DeleteObject(TargetIconInfo
.hbmColor
);
281 DeleteObject(TargetIconInfo
.hbmMask
);
286 /* Clean up scratch resources we created */
287 if (NULL
!= OldTargetBitmap
) SelectObject(TargetDC
, OldTargetBitmap
);
288 if (NULL
!= TargetIconInfo
.hbmColor
) DeleteObject(TargetIconInfo
.hbmColor
);
289 if (NULL
!= TargetIconInfo
.hbmMask
) DeleteObject(TargetIconInfo
.hbmMask
);
290 if (NULL
!= TargetDC
) DeleteObject(TargetDC
);
291 if (NULL
!= OldShortcutBitmap
) SelectObject(ShortcutDC
, OldShortcutBitmap
);
292 if (NULL
!= ShortcutDC
) DeleteObject(ShortcutDC
);
293 if (NULL
!= OldSourceBitmap
) SelectObject(SourceDC
, OldSourceBitmap
);
294 if (NULL
!= SourceDC
) DeleteObject(SourceDC
);
299 /*****************************************************************************
300 * SIC_IconAppend [internal]
302 static INT
SIC_IconAppend (const WCHAR
*sourcefile
, INT src_index
, HICON
*hicons
, DWORD flags
)
304 INT ret
, index
, index1
;
305 WCHAR path
[MAX_PATH
];
309 TRACE("%s %i %p %#x\n", debugstr_w(sourcefile
), src_index
, hicons
, flags
);
311 entry
= SHAlloc(sizeof(*entry
));
313 GetFullPathNameW(sourcefile
, MAX_PATH
, path
, NULL
);
314 entry
->sSourceFile
= heap_alloc( (strlenW(path
)+1)*sizeof(WCHAR
) );
315 strcpyW( entry
->sSourceFile
, path
);
317 entry
->dwSourceIndex
= src_index
;
318 entry
->dwFlags
= flags
;
320 EnterCriticalSection(&SHELL32_SicCS
);
322 index
= DPA_InsertPtr(sic_hdpa
, 0x7fff, entry
);
323 if ( INVALID_INDEX
== index
)
325 heap_free(entry
->sSourceFile
);
332 for (i
= 0; i
< ARRAY_SIZE(shell_imagelists
); i
++)
334 index1
= ImageList_AddIcon(shell_imagelists
[i
], hicons
[i
]);
335 if (index
!= -1 && index1
!= index
)
336 WARN("Imagelists out of sync, list %d.\n", i
);
340 entry
->dwListIndex
= index
;
341 ret
= entry
->dwListIndex
;
344 LeaveCriticalSection(&SHELL32_SicCS
);
348 static BOOL
get_imagelist_icon_size(int list
, SIZE
*size
)
350 if (list
< 0 || list
>= ARRAY_SIZE(shell_imagelists
)) return FALSE
;
352 return ImageList_GetIconSize( shell_imagelists
[list
], &size
->cx
, &size
->cy
);
355 /****************************************************************************
356 * SIC_LoadIcon [internal]
359 * gets icons by index from the file
361 static INT
SIC_LoadIcon (const WCHAR
*sourcefile
, INT index
, DWORD flags
)
363 HICON hicons
[ARRAY_SIZE(shell_imagelists
)] = { 0 };
364 HICON hshortcuts
[ARRAY_SIZE(hicons
)] = { 0 };
369 for (i
= 0; i
< ARRAY_SIZE(hicons
); i
++)
371 get_imagelist_icon_size( i
, &size
);
372 if (!PrivateExtractIconsW( sourcefile
, index
, size
.cx
, size
.cy
, &hicons
[i
], 0, 1, 0 ))
373 WARN("Failed to load icon %d from %s.\n", index
, debugstr_w(sourcefile
));
376 if (flags
& GIL_FORSHORTCUT
)
380 for (i
= 0; i
< ARRAY_SIZE(hshortcuts
); i
++)
382 if (!(hshortcuts
[i
] = SIC_OverlayShortcutImage(hicons
[i
], i
)))
384 WARN("Failed to create shortcut overlaid icons.\n");
391 for (i
= 0; i
< ARRAY_SIZE(hshortcuts
); i
++)
392 DestroyIcon(hshortcuts
[i
]);
393 flags
&= ~GIL_FORSHORTCUT
;
397 for (i
= 0; i
< ARRAY_SIZE(hicons
); i
++)
399 DestroyIcon(hicons
[i
]);
400 hicons
[i
] = hshortcuts
[i
];
405 ret
= SIC_IconAppend( sourcefile
, index
, hicons
, flags
);
406 for (i
= 0; i
< ARRAY_SIZE(hicons
); i
++)
407 DestroyIcon(hicons
[i
]);
411 static int get_shell_icon_size(void)
414 DWORD value
= 32, size
= sizeof(buf
), type
;
417 if (!RegOpenKeyW( HKEY_CURRENT_USER
, WindowMetrics
, &key
))
419 if (!RegQueryValueExW( key
, ShellIconSize
, NULL
, &type
, (BYTE
*)buf
, &size
) && type
== REG_SZ
)
421 if (size
== sizeof(buf
)) buf
[size
/ sizeof(WCHAR
) - 1] = 0;
422 value
= atoiW( buf
);
429 /*****************************************************************************
430 * SIC_Initialize [internal]
432 static BOOL WINAPI
SIC_Initialize( INIT_ONCE
*once
, void *param
, void **context
)
434 HICON hicons
[ARRAY_SIZE(shell_imagelists
)];
435 SIZE sizes
[ARRAY_SIZE(shell_imagelists
)];
439 if (!IsProcessDPIAware())
441 sizes
[SHIL_LARGE
].cx
= sizes
[SHIL_LARGE
].cy
= get_shell_icon_size();
442 sizes
[SHIL_SMALL
].cx
= GetSystemMetrics( SM_CXSMICON
);
443 sizes
[SHIL_SMALL
].cy
= GetSystemMetrics( SM_CYSMICON
);
447 sizes
[SHIL_LARGE
].cx
= GetSystemMetrics( SM_CXICON
);
448 sizes
[SHIL_LARGE
].cy
= GetSystemMetrics( SM_CYICON
);
449 sizes
[SHIL_SMALL
].cx
= sizes
[SHIL_LARGE
].cx
/ 2;
450 sizes
[SHIL_SMALL
].cy
= sizes
[SHIL_LARGE
].cy
/ 2;
453 sizes
[SHIL_EXTRALARGE
].cx
= (GetSystemMetrics( SM_CXICON
) * 3) / 2;
454 sizes
[SHIL_EXTRALARGE
].cy
= (GetSystemMetrics( SM_CYICON
) * 3) / 2;
455 sizes
[SHIL_SYSSMALL
].cx
= GetSystemMetrics( SM_CXSMICON
);
456 sizes
[SHIL_SYSSMALL
].cy
= GetSystemMetrics( SM_CYSMICON
);
458 TRACE("large %dx%d small %dx%d\n", sizes
[SHIL_LARGE
].cx
, sizes
[SHIL_LARGE
].cy
, sizes
[SHIL_SMALL
].cx
, sizes
[SHIL_SMALL
].cy
);
460 sic_hdpa
= DPA_Create(16);
464 for (i
= 0; i
< ARRAY_SIZE(shell_imagelists
); i
++)
466 shell_imagelists
[i
] = ImageList_Create(sizes
[i
].cx
, sizes
[i
].cy
, ILC_COLOR32
| ILC_MASK
, 0, 0x20);
467 ImageList_SetBkColor(shell_imagelists
[i
], CLR_NONE
);
469 /* Load the document icon, which is used as the default if an icon isn't found. */
470 if (!(hicons
[i
] = LoadImageA(shell32_hInstance
, MAKEINTRESOURCEA(IDI_SHELL_DOCUMENT
),
471 IMAGE_ICON
, sizes
[i
].cx
, sizes
[i
].cy
, LR_SHARED
)))
479 FIXME("Failed to load IDI_SHELL_DOCUMENT icon!\n");
483 SIC_IconAppend(swShell32Name
, IDI_SHELL_DOCUMENT
- 1, hicons
, 0);
484 SIC_IconAppend(swShell32Name
, -IDI_SHELL_DOCUMENT
, hicons
, 0);
486 TRACE("small list=%p, large list=%p\n", shell_imagelists
[SHIL_SMALL
], shell_imagelists
[SHIL_LARGE
]);
491 /*************************************************************************
496 static INT CALLBACK
sic_free( LPVOID ptr
, LPVOID lparam
)
498 heap_free(((LPSIC_ENTRY
)ptr
)->sSourceFile
);
503 void SIC_Destroy(void)
509 EnterCriticalSection(&SHELL32_SicCS
);
511 if (sic_hdpa
) DPA_DestroyCallback(sic_hdpa
, sic_free
, NULL
);
513 for (i
= 0; i
< ARRAY_SIZE(shell_imagelists
); i
++)
515 if (shell_imagelists
[i
])
516 ImageList_Destroy(shell_imagelists
[i
]);
519 LeaveCriticalSection(&SHELL32_SicCS
);
520 DeleteCriticalSection(&SHELL32_SicCS
);
523 /*****************************************************************************
524 * SIC_GetIconIndex [internal]
527 * sSourceFile [IN] filename of file containing the icon
528 * index [IN] index/resID (negated) in this file
531 * look in the cache for a proper icon. if not available the icon is taken
532 * from the file and cached
534 INT
SIC_GetIconIndex (LPCWSTR sSourceFile
, INT dwSourceIndex
, DWORD dwFlags
)
537 INT ret
, index
= INVALID_INDEX
;
538 WCHAR path
[MAX_PATH
];
540 TRACE("%s %i\n", debugstr_w(sSourceFile
), dwSourceIndex
);
542 GetFullPathNameW(sSourceFile
, MAX_PATH
, path
, NULL
);
543 sice
.sSourceFile
= path
;
544 sice
.dwSourceIndex
= dwSourceIndex
;
545 sice
.dwFlags
= dwFlags
;
547 InitOnceExecuteOnce( &sic_init_once
, SIC_Initialize
, NULL
, NULL
);
549 EnterCriticalSection(&SHELL32_SicCS
);
551 if (NULL
!= DPA_GetPtr (sic_hdpa
, 0))
553 /* search linear from position 0*/
554 index
= DPA_Search (sic_hdpa
, &sice
, 0, SIC_CompareEntries
, 0, 0);
557 if ( INVALID_INDEX
== index
)
559 ret
= SIC_LoadIcon (sSourceFile
, dwSourceIndex
, dwFlags
);
564 ret
= ((LPSIC_ENTRY
)DPA_GetPtr(sic_hdpa
, index
))->dwListIndex
;
567 LeaveCriticalSection(&SHELL32_SicCS
);
571 /*****************************************************************************
572 * SIC_LoadOverlayIcon [internal]
574 * Load a shell overlay icon and return its icon cache index.
576 static int SIC_LoadOverlayIcon(int icon_idx
)
578 WCHAR buffer
[1024], wszIdx
[8];
583 static const WCHAR wszShellIcons
[] = {
584 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
585 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
586 'E','x','p','l','o','r','e','r','\\','S','h','e','l','l',' ','I','c','o','n','s',0
588 static const WCHAR wszNumFmt
[] = {'%','d',0};
590 iconPath
= swShell32Name
; /* default: load icon from shell32.dll */
593 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
, wszShellIcons
, 0, KEY_READ
, &hKeyShellIcons
) == ERROR_SUCCESS
)
595 DWORD count
= sizeof(buffer
);
597 sprintfW(wszIdx
, wszNumFmt
, icon_idx
);
599 /* read icon path and index */
600 if (RegQueryValueExW(hKeyShellIcons
, wszIdx
, NULL
, NULL
, (LPBYTE
)buffer
, &count
) == ERROR_SUCCESS
)
602 LPWSTR p
= strchrW(buffer
, ',');
606 ERR("Icon index in %s/%s corrupted, no comma.\n", debugstr_w(wszShellIcons
),debugstr_w(wszIdx
));
607 RegCloseKey(hKeyShellIcons
);
615 RegCloseKey(hKeyShellIcons
);
618 InitOnceExecuteOnce( &sic_init_once
, SIC_Initialize
, NULL
, NULL
);
620 return SIC_LoadIcon(iconPath
, iconIdx
, 0);
623 /*************************************************************************
624 * Shell_GetImageLists [SHELL32.71]
627 * imglist[1|2] [OUT] pointer which receives imagelist handles
630 BOOL WINAPI
Shell_GetImageLists(HIMAGELIST
*large_list
, HIMAGELIST
*small_list
)
632 TRACE("(%p, %p)\n", large_list
, small_list
);
634 InitOnceExecuteOnce( &sic_init_once
, SIC_Initialize
, NULL
, NULL
);
635 if (large_list
) *large_list
= shell_imagelists
[SHIL_LARGE
];
636 if (small_list
) *small_list
= shell_imagelists
[SHIL_SMALL
];
640 /*************************************************************************
641 * PidlToSicIndex [INTERNAL]
644 * sh [IN] IShellFolder
648 * pIndex [OUT] index within the SIC
651 BOOL
PidlToSicIndex (
659 WCHAR szIconFile
[MAX_PATH
]; /* file containing the icon */
660 INT iSourceIndex
; /* index or resID(negated) in this file */
663 int iShortcutDefaultIndex
= INVALID_INDEX
;
665 TRACE("sf=%p pidl=%p %s\n", sh
, pidl
, bBigIcon
?"Big":"Small");
667 InitOnceExecuteOnce( &sic_init_once
, SIC_Initialize
, NULL
, NULL
);
669 if (SUCCEEDED (IShellFolder_GetUIObjectOf(sh
, 0, 1, &pidl
, &IID_IExtractIconW
, 0, (void **)&ei
)))
671 if (SUCCEEDED(IExtractIconW_GetIconLocation(ei
, uFlags
, szIconFile
, MAX_PATH
, &iSourceIndex
, &dwFlags
)))
673 *pIndex
= SIC_GetIconIndex(szIconFile
, iSourceIndex
, uFlags
);
676 IExtractIconW_Release(ei
);
679 if (INVALID_INDEX
== *pIndex
) /* default icon when failed */
681 if (0 == (uFlags
& GIL_FORSHORTCUT
))
687 if (INVALID_INDEX
== iShortcutDefaultIndex
)
689 iShortcutDefaultIndex
= SIC_LoadIcon(swShell32Name
, 0, GIL_FORSHORTCUT
);
691 *pIndex
= (INVALID_INDEX
!= iShortcutDefaultIndex
? iShortcutDefaultIndex
: 0);
699 /*************************************************************************
700 * SHMapPIDLToSystemImageListIndex [SHELL32.77]
703 * sh [IN] pointer to an instance of IShellFolder
705 * pIndex [OUT][OPTIONAL] SIC index for big icon
708 int WINAPI
SHMapPIDLToSystemImageListIndex(
716 TRACE("(SF=%p,pidl=%p,%p)\n",sh
,pidl
,pIndex
);
719 if (SHELL_IsShortcut(pidl
))
720 uGilFlags
|= GIL_FORSHORTCUT
;
723 if (!PidlToSicIndex ( sh
, pidl
, 1, uGilFlags
, pIndex
))
726 if (!PidlToSicIndex ( sh
, pidl
, 0, uGilFlags
, &Index
))
732 /*************************************************************************
733 * SHMapIDListToImageListIndexAsync [SHELL32.148]
735 HRESULT WINAPI
SHMapIDListToImageListIndexAsync(IUnknown
*pts
, IShellFolder
*psf
,
736 LPCITEMIDLIST pidl
, UINT flags
,
737 void *pfn
, void *pvData
, void *pvHint
,
738 int *piIndex
, int *piIndexSel
)
740 FIXME("(%p, %p, %p, 0x%08x, %p, %p, %p, %p, %p)\n",
741 pts
, psf
, pidl
, flags
, pfn
, pvData
, pvHint
, piIndex
, piIndexSel
);
745 /*************************************************************************
746 * Shell_GetCachedImageIndex [SHELL32.72]
749 static INT
Shell_GetCachedImageIndexA(LPCSTR szPath
, INT nIndex
, BOOL bSimulateDoc
)
754 WARN("(%s,%08x,%08x) semi-stub.\n",debugstr_a(szPath
), nIndex
, bSimulateDoc
);
756 len
= MultiByteToWideChar( CP_ACP
, 0, szPath
, -1, NULL
, 0 );
757 szTemp
= heap_alloc( len
* sizeof(WCHAR
) );
758 MultiByteToWideChar( CP_ACP
, 0, szPath
, -1, szTemp
, len
);
760 ret
= SIC_GetIconIndex( szTemp
, nIndex
, 0 );
767 static INT
Shell_GetCachedImageIndexW(LPCWSTR szPath
, INT nIndex
, BOOL bSimulateDoc
)
769 WARN("(%s,%08x,%08x) semi-stub.\n",debugstr_w(szPath
), nIndex
, bSimulateDoc
);
771 return SIC_GetIconIndex(szPath
, nIndex
, 0);
774 INT WINAPI
Shell_GetCachedImageIndexAW(LPCVOID szPath
, INT nIndex
, BOOL bSimulateDoc
)
775 { if( SHELL_OsIsUnicode())
776 return Shell_GetCachedImageIndexW(szPath
, nIndex
, bSimulateDoc
);
777 return Shell_GetCachedImageIndexA(szPath
, nIndex
, bSimulateDoc
);
780 /*************************************************************************
781 * ExtractIconExW [SHELL32.@]
784 * -1 file is not valid
785 * or number of icons extracted
787 UINT WINAPI
ExtractIconExW(LPCWSTR lpszFile
, INT nIconIndex
, HICON
* phiconLarge
, HICON
* phiconSmall
, UINT nIcons
)
789 TRACE("%s %i %p %p %i\n", debugstr_w(lpszFile
), nIconIndex
, phiconLarge
, phiconSmall
, nIcons
);
791 return PrivateExtractIconExW(lpszFile
, nIconIndex
, phiconLarge
, phiconSmall
, nIcons
);
794 /*************************************************************************
795 * ExtractIconExA [SHELL32.@]
797 UINT WINAPI
ExtractIconExA(LPCSTR lpszFile
, INT nIconIndex
, HICON
* phiconLarge
, HICON
* phiconSmall
, UINT nIcons
)
800 INT len
= MultiByteToWideChar(CP_ACP
, 0, lpszFile
, -1, NULL
, 0);
801 LPWSTR lpwstrFile
= heap_alloc( len
* sizeof(WCHAR
));
803 TRACE("%s %i %p %p %i\n", lpszFile
, nIconIndex
, phiconLarge
, phiconSmall
, nIcons
);
807 MultiByteToWideChar(CP_ACP
, 0, lpszFile
, -1, lpwstrFile
, len
);
808 ret
= ExtractIconExW(lpwstrFile
, nIconIndex
, phiconLarge
, phiconSmall
, nIcons
);
809 heap_free(lpwstrFile
);
814 /*************************************************************************
815 * ExtractAssociatedIconA (SHELL32.@)
817 * Return icon for given file (either from file itself or from associated
818 * executable) and patch parameters if needed.
820 HICON WINAPI
ExtractAssociatedIconA(HINSTANCE hInst
, LPSTR lpIconPath
, LPWORD lpiIcon
)
823 INT len
= MultiByteToWideChar(CP_ACP
, 0, lpIconPath
, -1, NULL
, 0);
824 /* Note that we need to allocate MAX_PATH, since we are supposed to fill
825 * the correct executable if there is no icon in lpIconPath directly.
826 * lpIconPath itself is supposed to be large enough, so make sure lpIconPathW
827 * is large enough too. Yes, I am puking too.
829 LPWSTR lpIconPathW
= heap_alloc(MAX_PATH
* sizeof(WCHAR
));
831 TRACE("%p %s %p\n", hInst
, debugstr_a(lpIconPath
), lpiIcon
);
835 MultiByteToWideChar(CP_ACP
, 0, lpIconPath
, -1, lpIconPathW
, len
);
836 hIcon
= ExtractAssociatedIconW(hInst
, lpIconPathW
, lpiIcon
);
837 WideCharToMultiByte(CP_ACP
, 0, lpIconPathW
, -1, lpIconPath
, MAX_PATH
, NULL
, NULL
);
838 heap_free(lpIconPathW
);
843 /*************************************************************************
844 * ExtractAssociatedIconW (SHELL32.@)
846 * Return icon for given file (either from file itself or from associated
847 * executable) and patch parameters if needed.
849 HICON WINAPI
ExtractAssociatedIconW(HINSTANCE hInst
, LPWSTR lpIconPath
, LPWORD lpiIcon
)
854 TRACE("%p %s %p\n", hInst
, debugstr_w(lpIconPath
), lpiIcon
);
857 lpiIcon
= &wDummyIcon
;
859 hIcon
= ExtractIconW(hInst
, lpIconPath
, *lpiIcon
);
861 if( hIcon
< (HICON
)2 )
862 { if( hIcon
== (HICON
)1 ) /* no icons found in given file */
863 { WCHAR tempPath
[MAX_PATH
];
864 HINSTANCE uRet
= FindExecutableW(lpIconPath
,NULL
,tempPath
);
866 if( uRet
> (HINSTANCE
)32 && tempPath
[0] )
867 { lstrcpyW(lpIconPath
,tempPath
);
868 hIcon
= ExtractIconW(hInst
, lpIconPath
, *lpiIcon
);
869 if( hIcon
> (HICON
)2 )
874 if( hIcon
== (HICON
)1 )
875 *lpiIcon
= 2; /* MSDOS icon - we found .exe but no icons in it */
877 *lpiIcon
= 6; /* generic icon - found nothing */
879 if (GetModuleFileNameW(hInst
, lpIconPath
, MAX_PATH
))
880 hIcon
= LoadIconW(hInst
, MAKEINTRESOURCEW(*lpiIcon
));
885 /*************************************************************************
886 * ExtractAssociatedIconExW (SHELL32.@)
888 * Return icon for given file (either from file itself or from associated
889 * executable) and patch parameters if needed.
891 HICON WINAPI
ExtractAssociatedIconExW(HINSTANCE hInst
, LPWSTR lpIconPath
, LPWORD lpiIconIdx
, LPWORD lpiIconId
)
893 FIXME("%p %s %p %p): stub\n", hInst
, debugstr_w(lpIconPath
), lpiIconIdx
, lpiIconId
);
897 /*************************************************************************
898 * ExtractAssociatedIconExA (SHELL32.@)
900 * Return icon for given file (either from file itself or from associated
901 * executable) and patch parameters if needed.
903 HICON WINAPI
ExtractAssociatedIconExA(HINSTANCE hInst
, LPSTR lpIconPath
, LPWORD lpiIconIdx
, LPWORD lpiIconId
)
906 INT len
= MultiByteToWideChar( CP_ACP
, 0, lpIconPath
, -1, NULL
, 0 );
907 LPWSTR lpwstrFile
= heap_alloc( len
* sizeof(WCHAR
) );
909 TRACE("%p %s %p %p)\n", hInst
, lpIconPath
, lpiIconIdx
, lpiIconId
);
911 MultiByteToWideChar( CP_ACP
, 0, lpIconPath
, -1, lpwstrFile
, len
);
912 ret
= ExtractAssociatedIconExW(hInst
, lpwstrFile
, lpiIconIdx
, lpiIconId
);
913 heap_free(lpwstrFile
);
918 /****************************************************************************
919 * SHDefExtractIconW [SHELL32.@]
921 HRESULT WINAPI
SHDefExtractIconW(LPCWSTR pszIconFile
, int iIndex
, UINT uFlags
,
922 HICON
* phiconLarge
, HICON
* phiconSmall
, UINT nIconSize
)
926 WARN("%s %d 0x%08x %p %p %d, semi-stub\n", debugstr_w(pszIconFile
), iIndex
, uFlags
, phiconLarge
, phiconSmall
, nIconSize
);
928 ret
= PrivateExtractIconsW(pszIconFile
, iIndex
, nIconSize
, nIconSize
, hIcons
, NULL
, 2, LR_DEFAULTCOLOR
);
929 /* FIXME: deal with uFlags parameter which contains GIL_ flags */
930 if (ret
== 0xFFFFFFFF)
934 *phiconLarge
= hIcons
[0];
936 DestroyIcon(hIcons
[0]);
938 *phiconSmall
= hIcons
[1];
940 DestroyIcon(hIcons
[1]);
946 /****************************************************************************
947 * SHDefExtractIconA [SHELL32.@]
949 HRESULT WINAPI
SHDefExtractIconA(LPCSTR pszIconFile
, int iIndex
, UINT uFlags
,
950 HICON
* phiconLarge
, HICON
* phiconSmall
, UINT nIconSize
)
953 INT len
= MultiByteToWideChar(CP_ACP
, 0, pszIconFile
, -1, NULL
, 0);
954 LPWSTR lpwstrFile
= heap_alloc(len
* sizeof(WCHAR
));
956 TRACE("%s %d 0x%08x %p %p %d\n", pszIconFile
, iIndex
, uFlags
, phiconLarge
, phiconSmall
, nIconSize
);
958 MultiByteToWideChar(CP_ACP
, 0, pszIconFile
, -1, lpwstrFile
, len
);
959 ret
= SHDefExtractIconW(lpwstrFile
, iIndex
, uFlags
, phiconLarge
, phiconSmall
, nIconSize
);
960 heap_free(lpwstrFile
);
965 /****************************************************************************
966 * SHGetIconOverlayIndexA [SHELL32.@]
968 * Returns the index of the overlay icon in the system image list.
970 INT WINAPI
SHGetIconOverlayIndexA(LPCSTR pszIconPath
, INT iIconIndex
)
972 FIXME("%s, %d\n", debugstr_a(pszIconPath
), iIconIndex
);
977 /****************************************************************************
978 * SHGetIconOverlayIndexW [SHELL32.@]
980 * Returns the index of the overlay icon in the system image list.
982 INT WINAPI
SHGetIconOverlayIndexW(LPCWSTR pszIconPath
, INT iIconIndex
)
984 FIXME("%s, %d\n", debugstr_w(pszIconPath
), iIconIndex
);
989 /****************************************************************************
990 * SHGetStockIconInfo [SHELL32.@]
992 * Receive information for builtin icons
995 * id [I] selected icon-id to get information for
996 * flags [I] selects the information to receive
997 * sii [IO] SHSTOCKICONINFO structure to fill
1001 * Failure: A HRESULT failure code
1004 HRESULT WINAPI
SHGetStockIconInfo(SHSTOCKICONID id
, UINT flags
, SHSTOCKICONINFO
*sii
)
1006 static const WCHAR shell32dll
[] = {'\\','s','h','e','l','l','3','2','.','d','l','l',0};
1008 FIXME("(%d, 0x%x, %p) semi-stub\n", id
, flags
, sii
);
1009 if ((id
< 0) || (id
>= SIID_MAX_ICONS
) || !sii
|| (sii
->cbSize
!= sizeof(SHSTOCKICONINFO
))) {
1010 return E_INVALIDARG
;
1013 GetSystemDirectoryW(sii
->szPath
, MAX_PATH
);
1015 /* no icons defined: use default */
1016 sii
->iIcon
= -IDI_SHELL_DOCUMENT
;
1017 lstrcatW(sii
->szPath
, shell32dll
);
1020 FIXME("flags 0x%x not implemented\n", flags
);
1023 sii
->iSysImageIndex
= -1;
1025 TRACE("%3d: returning %s (%d)\n", id
, debugstr_w(sii
->szPath
), sii
->iIcon
);
1030 /*************************************************************************
1031 * SHGetImageList (SHELL32.727)
1033 * Returns a copy of a shell image list.
1036 * Windows XP features 4 sizes of image list, and Vista 5. Wine currently
1037 * only supports the traditional small and large image lists, so requests
1038 * for the others will currently fail.
1040 HRESULT WINAPI
SHGetImageList(int iImageList
, REFIID riid
, void **ppv
)
1042 if (iImageList
< 0 || iImageList
> SHIL_SYSSMALL
)
1044 FIXME("Unsupported image list %i requested\n", iImageList
);
1048 InitOnceExecuteOnce( &sic_init_once
, SIC_Initialize
, NULL
, NULL
);
1049 return HIMAGELIST_QueryInterface(shell_imagelists
[iImageList
], riid
, ppv
);