2 * shell icon cache (SIC)
12 #include "wine/winuser16.h"
13 #include "wine/winbase16.h"
15 #include "cursoricon.h"
18 #include "debugtools.h"
19 #include "winversion.h"
23 #include "shell32_main.h"
24 #include "wine/undocshell.h"
27 DEFAULT_DEBUG_CHANNEL(shell
)
33 BYTE bWidth
; /* Width, in pixels, of the image */
34 BYTE bHeight
; /* Height, in pixels, of the image */
35 BYTE bColorCount
; /* Number of colors in image (0 if >=8bpp) */
36 BYTE bReserved
; /* Reserved ( must be 0) */
37 WORD wPlanes
; /* Color Planes */
38 WORD wBitCount
; /* Bits per pixel */
39 DWORD dwBytesInRes
; /* How many bytes in this resource? */
40 DWORD dwImageOffset
; /* Where in the file is this image? */
41 } icoICONDIRENTRY
, *LPicoICONDIRENTRY
;
45 WORD idReserved
; /* Reserved (must be 0) */
46 WORD idType
; /* Resource Type (RES_ICON or RES_CURSOR) */
47 WORD idCount
; /* How many images */
48 icoICONDIRENTRY idEntries
[1]; /* An entry for each image (idCount of 'em) */
49 } icoICONDIR
, *LPicoICONDIR
;
54 static void dumpIcoDirEnty ( LPicoICONDIRENTRY entry
)
56 TRACE("width = 0x%08x height = 0x%08x\n", entry
->bWidth
, entry
->bHeight
);
57 TRACE("colors = 0x%08x planes = 0x%08x\n", entry
->bColorCount
, entry
->wPlanes
);
58 TRACE("bitcount = 0x%08x bytesinres = 0x%08lx offset = 0x%08lx\n",
59 entry
->wBitCount
, entry
->dwBytesInRes
, entry
->dwImageOffset
);
61 static void dumpIcoDir ( LPicoICONDIR entry
)
63 TRACE("type = 0x%08x count = 0x%08x\n", entry
->idType
, entry
->idCount
);
66 /*************************************************************************
67 * SHELL_GetResourceTable
69 static DWORD
SHELL_GetResourceTable(HFILE hFile
, LPBYTE
*retptr
)
70 { IMAGE_DOS_HEADER mz_header
;
74 TRACE("0x%08x %p\n", hFile
, retptr
);
77 _llseek( hFile
, 0, SEEK_SET
);
78 if ((_lread(hFile
,&mz_header
,sizeof(mz_header
)) != sizeof(mz_header
)) || (mz_header
.e_magic
!= IMAGE_DOS_SIGNATURE
))
79 { if (mz_header
.e_cblp
== 1) /* .ICO file ? */
80 { *retptr
= (LPBYTE
)-1; /* ICONHEADER.idType, must be 1 */
84 return 0; /* failed */
86 _llseek( hFile
, mz_header
.e_lfanew
, SEEK_SET
);
88 if (_lread( hFile
, magic
, sizeof(magic
) ) != sizeof(magic
))
91 _llseek( hFile
, mz_header
.e_lfanew
, SEEK_SET
);
93 if (*(DWORD
*)magic
== IMAGE_NT_SIGNATURE
)
94 return IMAGE_NT_SIGNATURE
;
96 if (*(WORD
*)magic
== IMAGE_OS2_SIGNATURE
)
97 { IMAGE_OS2_HEADER ne_header
;
98 LPBYTE pTypeInfo
= (LPBYTE
)-1;
100 if (_lread(hFile
,&ne_header
,sizeof(ne_header
))!=sizeof(ne_header
))
103 if (ne_header
.ne_magic
!= IMAGE_OS2_SIGNATURE
)
106 size
= ne_header
.ne_restab
- ne_header
.ne_rsrctab
;
108 if( size
> sizeof(NE_TYPEINFO
) )
109 { pTypeInfo
= (BYTE
*)HeapAlloc( GetProcessHeap(), 0, size
);
111 { _llseek(hFile
, mz_header
.e_lfanew
+ne_header
.ne_rsrctab
, SEEK_SET
);
112 if( _lread( hFile
, (char*)pTypeInfo
, size
) != size
)
113 { HeapFree( GetProcessHeap(), 0, pTypeInfo
);
119 return IMAGE_OS2_SIGNATURE
;
121 return 0; /* failed */
123 /*************************************************************************
126 static BYTE
* SHELL_LoadResource( HFILE hFile
, NE_NAMEINFO
* pNInfo
, WORD sizeShift
, ULONG
*uSize
)
129 TRACE("0x%08x %p 0x%08x\n", hFile
, pNInfo
, sizeShift
);
131 *uSize
= (DWORD
)pNInfo
->length
<< sizeShift
;
132 if( (ptr
= (BYTE
*)HeapAlloc(GetProcessHeap(),0, *uSize
) ))
133 { _llseek( hFile
, (DWORD
)pNInfo
->offset
<< sizeShift
, SEEK_SET
);
134 _lread( hFile
, (char*)ptr
, pNInfo
->length
<< sizeShift
);
140 /*************************************************************************
143 static BYTE
* ICO_LoadIcon( HFILE hFile
, LPicoICONDIRENTRY lpiIDE
, ULONG
*uSize
)
146 TRACE("0x%08x %p\n", hFile
, lpiIDE
);
148 *uSize
= lpiIDE
->dwBytesInRes
;
149 if( (ptr
= (BYTE
*)HeapAlloc(GetProcessHeap(),0, *uSize
)) )
150 { _llseek( hFile
, lpiIDE
->dwImageOffset
, SEEK_SET
);
151 _lread( hFile
, (char*)ptr
, lpiIDE
->dwBytesInRes
);
158 /*************************************************************************
159 * ICO_GetIconDirectory
161 * Reads .ico file and build phony ICONDIR struct
162 * see http://www.microsoft.com/win32dev/ui/icons.htm
164 #define HEADER_SIZE (sizeof(CURSORICONDIR) - sizeof (CURSORICONDIRENTRY))
165 #define HEADER_SIZE_FILE (sizeof(icoICONDIR) - sizeof (icoICONDIRENTRY))
167 static BYTE
* ICO_GetIconDirectory( HFILE hFile
, LPicoICONDIR
* lplpiID
, ULONG
*uSize
)
168 { CURSORICONDIR lpcid
; /* icon resource in resource-dir format */
169 LPicoICONDIR lpiID
; /* icon resource in file format */
172 TRACE("0x%08x %p\n", hFile
, lplpiID
);
174 _llseek( hFile
, 0, SEEK_SET
);
175 if( _lread(hFile
,(char*)&lpcid
, HEADER_SIZE_FILE
) != HEADER_SIZE_FILE
)
178 if( lpcid
.idReserved
|| (lpcid
.idType
!= 1) || (!lpcid
.idCount
) )
181 i
= lpcid
.idCount
* sizeof(icoICONDIRENTRY
);
182 lpiID
= (LPicoICONDIR
)HeapAlloc( GetProcessHeap(), 0, HEADER_SIZE_FILE
+ i
);
184 if( _lread(hFile
,(char*)lpiID
->idEntries
,i
) == i
)
185 { CURSORICONDIR
* lpID
; /* icon resource in resource format */
186 *uSize
= lpcid
.idCount
* sizeof(CURSORICONDIRENTRY
) + HEADER_SIZE
;
187 if( (lpID
= (CURSORICONDIR
*)HeapAlloc(GetProcessHeap(),0, *uSize
) ))
189 /* copy the header */
190 lpID
->idReserved
= lpiID
->idReserved
= 0;
191 lpID
->idType
= lpiID
->idType
= 1;
192 lpID
->idCount
= lpiID
->idCount
= lpcid
.idCount
;
194 /* copy the entrys */
195 for( i
=0; i
< lpiID
->idCount
; i
++ )
196 { memcpy((void*)&(lpID
->idEntries
[i
]),(void*)&(lpiID
->idEntries
[i
]), sizeof(CURSORICONDIRENTRY
) - 2);
197 lpID
->idEntries
[i
].wResId
= i
;
206 HeapFree( GetProcessHeap(), 0, lpiID
);
210 /*************************************************************************
213 * failure:0; success: icon handle or nr of icons (nIconIndex-1)
215 HICON WINAPI
ICO_ExtractIconEx(LPCSTR lpszExeFileName
, HICON
* RetPtr
, INT nIconIndex
, UINT n
, UINT cxDesired
, UINT cyDesired
)
220 HFILE hFile
= OpenFile( lpszExeFileName
, &ofs
, OF_READ
);
221 UINT16 iconDirCount
= 0,iconCount
= 0;
226 TRACE("(file %s,start %d,extract %d\n", lpszExeFileName
, nIconIndex
, n
);
228 if( hFile
== HFILE_ERROR
|| (nIconIndex
!=-1 && !n
) )
231 sig
= SHELL_GetResourceTable(hFile
,&pData
);
234 if( sig
==IMAGE_OS2_SIGNATURE
|| sig
==1 ) /* .ICO file */
236 NE_TYPEINFO
*pTInfo
= (NE_TYPEINFO
*)(pData
+ 2);
237 NE_NAMEINFO
*pIconStorage
= NULL
;
238 NE_NAMEINFO
*pIconDir
= NULL
;
239 LPicoICONDIR lpiID
= NULL
;
241 TRACE("-- OS2/icon Signature (0x%08lx)\n", sig
);
243 if( pData
== (BYTE
*)-1 )
244 { pCIDir
= ICO_GetIconDirectory(hFile
, &lpiID
, &uSize
); /* check for .ICO file */
246 { iconDirCount
= 1; iconCount
= lpiID
->idCount
;
247 TRACE("-- icon found %p 0x%08lx 0x%08x 0x%08x\n", pCIDir
, uSize
, iconDirCount
, iconCount
);
250 else while( pTInfo
->type_id
&& !(pIconStorage
&& pIconDir
) )
251 { if( pTInfo
->type_id
== NE_RSCTYPE_GROUP_ICON
) /* find icon directory and icon repository */
252 { iconDirCount
= pTInfo
->count
;
253 pIconDir
= ((NE_NAMEINFO
*)(pTInfo
+ 1));
254 TRACE("\tfound directory - %i icon families\n", iconDirCount
);
256 if( pTInfo
->type_id
== NE_RSCTYPE_ICON
)
257 { iconCount
= pTInfo
->count
;
258 pIconStorage
= ((NE_NAMEINFO
*)(pTInfo
+ 1));
259 TRACE("\ttotal icons - %i\n", iconCount
);
261 pTInfo
= (NE_TYPEINFO
*)((char*)(pTInfo
+1)+pTInfo
->count
*sizeof(NE_NAMEINFO
));
264 if( (pIconStorage
&& pIconDir
) || lpiID
) /* load resources and create icons */
265 { if( nIconIndex
== (UINT16
)-1 )
266 { RetPtr
[0] = iconDirCount
;
268 else if( nIconIndex
< iconDirCount
)
270 if( n
> iconDirCount
- nIconIndex
)
271 n
= iconDirCount
- nIconIndex
;
273 for( i
= nIconIndex
; i
< nIconIndex
+ n
; i
++ )
274 { /* .ICO files have only one icon directory */
276 if( lpiID
== NULL
) /* *.ico */
277 pCIDir
= SHELL_LoadResource( hFile
, pIconDir
+ i
, *(WORD
*)pData
, &uSize
);
278 RetPtr
[i
-nIconIndex
] = pLookupIconIdFromDirectoryEx( pCIDir
, TRUE
, GetSystemMetrics(SM_CXICON
), GetSystemMetrics(SM_CYICON
), 0);
279 HeapFree(GetProcessHeap(), 0, pCIDir
);
282 for( icon
= nIconIndex
; icon
< nIconIndex
+ n
; icon
++ )
285 { pCIDir
= ICO_LoadIcon( hFile
, lpiID
->idEntries
+ RetPtr
[icon
-nIconIndex
], &uSize
);
288 { for( i
= 0; i
< iconCount
; i
++ )
289 { if( pIconStorage
[i
].id
== (RetPtr
[icon
-nIconIndex
] | 0x8000) )
290 { pCIDir
= SHELL_LoadResource( hFile
, pIconStorage
+ i
,*(WORD
*)pData
, &uSize
);
295 { RetPtr
[icon
-nIconIndex
] = (HICON
) pCreateIconFromResourceEx(pCIDir
,uSize
,TRUE
,0x00030000, cxDesired
, cyDesired
, LR_DEFAULTCOLOR
);
298 { RetPtr
[icon
-nIconIndex
] = 0;
304 HeapFree( GetProcessHeap(), 0, lpiID
);
306 HeapFree( GetProcessHeap(), 0, pData
);
311 if( sig
== IMAGE_NT_SIGNATURE
)
312 { LPBYTE idata
,igdata
;
313 PIMAGE_DOS_HEADER dheader
;
314 PIMAGE_NT_HEADERS pe_header
;
315 PIMAGE_SECTION_HEADER pe_sections
;
316 PIMAGE_RESOURCE_DIRECTORY rootresdir
,iconresdir
,icongroupresdir
;
317 PIMAGE_RESOURCE_DATA_ENTRY idataent
,igdataent
;
318 PIMAGE_RESOURCE_DIRECTORY_ENTRY xresent
;
321 if ( !(fmapping
= CreateFileMappingA(hFile
,NULL
,PAGE_READONLY
|SEC_COMMIT
,0,0,NULL
)))
322 { WARN("failed to create filemap.\n"); /* FIXME, INVALID_HANDLE_VALUE? */
323 goto end_2
; /* failure */
326 if ( !(peimage
= MapViewOfFile(fmapping
,FILE_MAP_READ
,0,0,0)))
327 { WARN("failed to mmap filemap.\n");
328 goto end_2
; /* failure */
331 dheader
= (PIMAGE_DOS_HEADER
)peimage
;
332 pe_header
= (PIMAGE_NT_HEADERS
)(peimage
+dheader
->e_lfanew
); /* it is a pe header, SHELL_GetResourceTable checked that */
333 pe_sections
= (PIMAGE_SECTION_HEADER
)(((char*)pe_header
)+sizeof(*pe_header
)); /* probably makes problems with short PE headers...*/
336 for (i
=0;i
<pe_header
->FileHeader
.NumberOfSections
;i
++)
337 { if (pe_sections
[i
].Characteristics
& IMAGE_SCN_CNT_UNINITIALIZED_DATA
)
339 /* FIXME: doesn't work when the resources are not in a seperate section */
340 if (pe_sections
[i
].VirtualAddress
== pe_header
->OptionalHeader
.DataDirectory
[IMAGE_DIRECTORY_ENTRY_RESOURCE
].VirtualAddress
)
341 { rootresdir
= (PIMAGE_RESOURCE_DIRECTORY
)((char*)peimage
+pe_sections
[i
].PointerToRawData
);
347 { WARN("haven't found section for resource directory.\n");
348 goto end_3
; /* failure */
350 /* search the group icon dir*/
351 if (!(icongroupresdir
= GetResDirEntryW(rootresdir
,RT_GROUP_ICONW
, (DWORD
)rootresdir
,FALSE
)))
352 { WARN("No Icongroupresourcedirectory!\n");
353 goto end_3
; /* failure */
355 iconDirCount
= icongroupresdir
->NumberOfNamedEntries
+icongroupresdir
->NumberOfIdEntries
;
357 /* number of icons requested */
358 if( nIconIndex
== -1 )
359 { hRet
= iconDirCount
;
360 goto end_3
; /* success */
363 /* (nIconIndex < 0): extract the icon by resource id */
367 int iId
= abs(nIconIndex
);
368 PIMAGE_RESOURCE_DIRECTORY_ENTRY xprdeTmp
= (PIMAGE_RESOURCE_DIRECTORY_ENTRY
)(icongroupresdir
+1);
370 while(n
<iconDirCount
&& xprdeTmp
)
372 if(xprdeTmp
->u1
.Id
== iId
)
382 WARN("resource id %d not found\n", iId
);
383 goto end_3
; /* failure */
387 /* check nIconIndex to be in range */
388 if (nIconIndex
>= iconDirCount
)
390 WARN("nIconIndex %d is larger than iconDirCount %d\n",nIconIndex
,iconDirCount
);
391 goto end_3
; /* failure */
394 xresent
= (PIMAGE_RESOURCE_DIRECTORY_ENTRY
)(icongroupresdir
+1); /* caller just wanted the number of entries */
396 if( n
> iconDirCount
- nIconIndex
) /* assure we don't get too much ... */
397 { n
= iconDirCount
- nIconIndex
;
400 xresent
= xresent
+nIconIndex
; /* starting from specified index ... */
402 for (i
=0;i
<n
;i
++,xresent
++)
403 { PIMAGE_RESOURCE_DIRECTORY resdir
;
405 /* go down this resource entry, name */
406 resdir
= (PIMAGE_RESOURCE_DIRECTORY
)((DWORD
)rootresdir
+(xresent
->u2
.s
.OffsetToDirectory
));
408 /* default language (0) */
409 resdir
= GetResDirEntryW(resdir
,(LPWSTR
)0,(DWORD
)rootresdir
,TRUE
);
410 igdataent
= (PIMAGE_RESOURCE_DATA_ENTRY
)resdir
;
412 /* lookup address in mapped image for virtual address */
415 for (j
=0;j
<pe_header
->FileHeader
.NumberOfSections
;j
++)
416 { if (igdataent
->OffsetToData
< pe_sections
[j
].VirtualAddress
)
418 if (igdataent
->OffsetToData
+igdataent
->Size
> pe_sections
[j
].VirtualAddress
+pe_sections
[j
].SizeOfRawData
)
420 igdata
= peimage
+(igdataent
->OffsetToData
-pe_sections
[j
].VirtualAddress
+pe_sections
[j
].PointerToRawData
);
424 { WARN("no matching real address for icongroup!\n");
425 goto end_3
; /* failure */
427 RetPtr
[i
] = (HICON
)pLookupIconIdFromDirectoryEx(igdata
, TRUE
, cxDesired
, cyDesired
, LR_DEFAULTCOLOR
);
430 if (!(iconresdir
=GetResDirEntryW(rootresdir
,RT_ICONW
,(DWORD
)rootresdir
,FALSE
)))
431 { WARN("No Iconresourcedirectory!\n");
432 goto end_3
; /* failure */
436 { PIMAGE_RESOURCE_DIRECTORY xresdir
;
437 xresdir
= GetResDirEntryW(iconresdir
,(LPWSTR
)(DWORD
)RetPtr
[i
],(DWORD
)rootresdir
,FALSE
);
438 xresdir
= GetResDirEntryW(xresdir
,(LPWSTR
)0,(DWORD
)rootresdir
,TRUE
);
439 idataent
= (PIMAGE_RESOURCE_DATA_ENTRY
)xresdir
;
442 /* map virtual to address in image */
443 for (j
=0;j
<pe_header
->FileHeader
.NumberOfSections
;j
++)
444 { if (idataent
->OffsetToData
< pe_sections
[j
].VirtualAddress
)
446 if (idataent
->OffsetToData
+idataent
->Size
> pe_sections
[j
].VirtualAddress
+pe_sections
[j
].SizeOfRawData
)
448 idata
= peimage
+(idataent
->OffsetToData
-pe_sections
[j
].VirtualAddress
+pe_sections
[j
].PointerToRawData
);
451 { WARN("no matching real address found for icondata!\n");
455 RetPtr
[i
] = (HICON
) pCreateIconFromResourceEx(idata
,idataent
->Size
,TRUE
,0x00030000, cxDesired
, cyDesired
, LR_DEFAULTCOLOR
);
457 hRet
= RetPtr
[0]; /* return first icon */
458 goto end_3
; /* sucess */
460 goto end_1
; /* unknown filetype */
462 /* cleaning up (try & catch would be nicer:-) ) */
463 end_3
: UnmapViewOfFile(peimage
); /* success */
464 end_2
: CloseHandle(fmapping
);
465 end_1
: _lclose( hFile
);
469 /********************** THE ICON CACHE ********************************/
471 #define INVALID_INDEX -1
474 { LPCSTR sSourceFile
; /* file (not path!) containing the icon */
475 DWORD dwSourceIndex
; /* index within the file, if it is a resoure ID it will be negated */
476 DWORD dwListIndex
; /* index within the iconlist */
477 DWORD dwFlags
; /* GIL_* flags */
479 } SIC_ENTRY
, * LPSIC_ENTRY
;
481 static HDPA sic_hdpa
= 0;
482 static CRITICAL_SECTION SHELL32_SicCS
= CRITICAL_SECTION_INIT
;
484 /*****************************************************************************
485 * SIC_CompareEntrys [called by comctl32.dll]
488 * Callback for DPA_Search
490 INT CALLBACK
SIC_CompareEntrys( LPVOID p1
, LPVOID p2
, LPARAM lparam
)
491 { TRACE("%p %p\n", p1
, p2
);
493 if (((LPSIC_ENTRY
)p1
)->dwSourceIndex
!= ((LPSIC_ENTRY
)p2
)->dwSourceIndex
) /* first the faster one*/
496 if (strcasecmp(((LPSIC_ENTRY
)p1
)->sSourceFile
,((LPSIC_ENTRY
)p2
)->sSourceFile
))
501 /*****************************************************************************
502 * SIC_IconAppend [internal]
505 * appends a icon pair to the end of the cache
507 static INT
SIC_IconAppend (LPCSTR sSourceFile
, INT dwSourceIndex
, HICON hSmallIcon
, HICON hBigIcon
)
508 { LPSIC_ENTRY lpsice
;
509 INT ret
, index
, index1
;
511 TRACE("%s %i %x %x\n", sSourceFile
, dwSourceIndex
, hSmallIcon
,hBigIcon
);
513 lpsice
= (LPSIC_ENTRY
) SHAlloc (sizeof (SIC_ENTRY
));
515 lpsice
->sSourceFile
= HEAP_strdupA (GetProcessHeap(), 0, PathFindFileNameA(sSourceFile
));
516 lpsice
->dwSourceIndex
= dwSourceIndex
;
518 EnterCriticalSection(&SHELL32_SicCS
);
520 index
= pDPA_InsertPtr(sic_hdpa
, 0x7fff, lpsice
);
521 if ( INVALID_INDEX
== index
)
528 index
= pImageList_AddIcon (ShellSmallIconList
, hSmallIcon
);
529 index1
= pImageList_AddIcon (ShellBigIconList
, hBigIcon
);
533 FIXME("iconlists out of sync 0x%x 0x%x\n", index
, index1
);
535 lpsice
->dwListIndex
= index
;
536 ret
= lpsice
->dwListIndex
;
539 LeaveCriticalSection(&SHELL32_SicCS
);
542 /****************************************************************************
543 * SIC_LoadIcon [internal]
546 * gets small/big icon by number from a file
548 static INT
SIC_LoadIcon (LPCSTR sSourceFile
, INT dwSourceIndex
)
549 { HICON hiconLarge
=0;
552 ICO_ExtractIconEx(sSourceFile
, &hiconLarge
, dwSourceIndex
, 1, 32, 32 );
553 ICO_ExtractIconEx(sSourceFile
, &hiconSmall
, dwSourceIndex
, 1, 16, 16 );
556 if ( !hiconLarge
|| !hiconSmall
)
558 WARN("failure loading icon %i from %s (%x %x)\n", dwSourceIndex
, sSourceFile
, hiconLarge
, hiconSmall
);
561 return SIC_IconAppend (sSourceFile
, dwSourceIndex
, hiconSmall
, hiconLarge
);
563 /*****************************************************************************
564 * SIC_GetIconIndex [internal]
567 * sSourceFile [IN] filename of file containing the icon
568 * index [IN] index/resID (negated) in this file
571 * look in the cache for a proper icon. if not available the icon is taken
572 * from the file and cached
574 INT
SIC_GetIconIndex (LPCSTR sSourceFile
, INT dwSourceIndex
)
576 INT ret
, index
= INVALID_INDEX
;
578 TRACE("%s %i\n", sSourceFile
, dwSourceIndex
);
580 sice
.sSourceFile
= PathFindFileNameA(sSourceFile
);
581 sice
.dwSourceIndex
= dwSourceIndex
;
583 EnterCriticalSection(&SHELL32_SicCS
);
585 if (NULL
!= pDPA_GetPtr (sic_hdpa
, 0))
587 index
= pDPA_Search (sic_hdpa
, &sice
, -1L, SIC_CompareEntrys
, 0, 0);
590 if ( INVALID_INDEX
== index
)
592 ret
= SIC_LoadIcon (sSourceFile
, dwSourceIndex
);
597 ret
= ((LPSIC_ENTRY
)pDPA_GetPtr(sic_hdpa
, index
))->dwListIndex
;
600 LeaveCriticalSection(&SHELL32_SicCS
);
603 /****************************************************************************
604 * SIC_LoadIcon [internal]
607 * retrives the specified icon from the iconcache. if not found try's to load the icon
609 static HICON WINE_UNUSED
SIC_GetIcon (LPCSTR sSourceFile
, INT dwSourceIndex
, BOOL bSmallIcon
)
612 TRACE("%s %i\n", sSourceFile
, dwSourceIndex
);
614 index
= SIC_GetIconIndex(sSourceFile
, dwSourceIndex
);
616 if (INVALID_INDEX
== index
)
618 return INVALID_INDEX
;
622 return pImageList_GetIcon(ShellSmallIconList
, index
, ILD_NORMAL
);
623 return pImageList_GetIcon(ShellBigIconList
, index
, ILD_NORMAL
);
626 /*****************************************************************************
627 * SIC_Initialize [internal]
630 * hack to load the resources from the shell32.dll under a different dll name
631 * will be removed when the resource-compiler is ready
633 BOOL
SIC_Initialize(void)
640 if (sic_hdpa
) /* already initialized?*/
643 sic_hdpa
= pDPA_Create(16);
650 ShellSmallIconList
= pImageList_Create(16,16,ILC_COLORDDB
| ILC_MASK
,0,0x20);
651 ShellBigIconList
= pImageList_Create(32,32,ILC_COLORDDB
| ILC_MASK
,0,0x20);
653 pImageList_SetBkColor(ShellSmallIconList
, GetSysColor(COLOR_WINDOW
));
654 pImageList_SetBkColor(ShellBigIconList
, GetSysColor(COLOR_WINDOW
));
656 for (index
=1; index
<39; index
++)
658 hSm
= LoadImageA(shell32_hInstance
, MAKEINTRESOURCEA(index
), IMAGE_ICON
, 16, 16,LR_SHARED
);
659 hLg
= LoadImageA(shell32_hInstance
, MAKEINTRESOURCEA(index
), IMAGE_ICON
, 32, 32,LR_SHARED
);
663 hSm
= LoadImageA(shell32_hInstance
, MAKEINTRESOURCEA(0), IMAGE_ICON
, 16, 16,LR_SHARED
);
664 hLg
= LoadImageA(shell32_hInstance
, MAKEINTRESOURCEA(0), IMAGE_ICON
, 32, 32,LR_SHARED
);
666 SIC_IconAppend ("shell32.dll", index
, hSm
, hLg
);
669 TRACE("hIconSmall=%p hIconBig=%p\n",ShellSmallIconList
, ShellBigIconList
);
673 /*************************************************************************
678 void SIC_Destroy(void)
685 EnterCriticalSection(&SHELL32_SicCS
);
687 if (sic_hdpa
&& NULL
!= pDPA_GetPtr (sic_hdpa
, 0))
689 for (i
=0; i
< pDPA_GetPtrCount(sic_hdpa
); ++i
)
691 lpsice
= pDPA_GetPtr(sic_hdpa
, i
);
694 pDPA_Destroy(sic_hdpa
);
699 LeaveCriticalSection(&SHELL32_SicCS
);
700 DeleteCriticalSection(&SHELL32_SicCS
);
702 /*************************************************************************
703 * Shell_GetImageList [SHELL32.71]
706 * imglist[1|2] [OUT] pointer which recive imagelist handles
709 BOOL WINAPI
Shell_GetImageList(HIMAGELIST
* lpBigList
, HIMAGELIST
* lpSmallList
)
710 { TRACE("(%p,%p)\n",lpBigList
,lpSmallList
);
712 { *lpBigList
= ShellBigIconList
;
715 { *lpSmallList
= ShellSmallIconList
;
720 /*************************************************************************
721 * PidlToSicIndex [INTERNAL]
724 * sh [IN] IShellFolder
728 * pIndex [OUT] index within the SIC
731 BOOL
PidlToSicIndex (
739 char szIconFile
[MAX_PATH
]; /* file containing the icon */
740 INT iSourceIndex
; /* index or resID(negated) in this file */
744 TRACE("sf=%p pidl=%p %s\n", sh
, pidl
, bBigIcon
?"Big":"Small");
746 if (SUCCEEDED (IShellFolder_GetUIObjectOf(sh
, 0, 1, &pidl
, &IID_IExtractIconA
, 0, (void **)&ei
)))
748 if (SUCCEEDED(IExtractIconA_GetIconLocation(ei
, uFlags
, szIconFile
, MAX_PATH
, &iSourceIndex
, &dwFlags
)))
750 *pIndex
= SIC_GetIconIndex(szIconFile
, iSourceIndex
);
753 IExtractIconA_Release(ei
);
756 if (INVALID_INDEX
== *pIndex
) /* default icon when failed */
763 /*************************************************************************
764 * SHMapPIDLToSystemImageListIndex [SHELL32.77]
767 * sh [IN] pointer to an instance of IShellFolder
769 * pIndex [OUT][OPTIONAL] SIC index for big icon
772 int WINAPI
SHMapPIDLToSystemImageListIndex(
779 TRACE("(SF=%p,pidl=%p,%p)\n",sh
,pidl
,pIndex
);
783 PidlToSicIndex ( sh
, pidl
, 1, 0, pIndex
);
784 PidlToSicIndex ( sh
, pidl
, 0, 0, &Index
);
788 /*************************************************************************
789 * Shell_GetCachedImageIndex [SHELL32.72]
792 INT WINAPI
Shell_GetCachedImageIndexA(LPCSTR szPath
, INT nIndex
, BOOL bSimulateDoc
)
794 WARN("(%s,%08x,%08x) semi-stub.\n",debugstr_a(szPath
), nIndex
, bSimulateDoc
);
795 return SIC_GetIconIndex(szPath
, nIndex
);
798 INT WINAPI
Shell_GetCachedImageIndexW(LPCWSTR szPath
, INT nIndex
, BOOL bSimulateDoc
)
800 LPSTR sTemp
= HEAP_strdupWtoA (GetProcessHeap(),0,szPath
);
802 WARN("(%s,%08x,%08x) semi-stub.\n",debugstr_w(szPath
), nIndex
, bSimulateDoc
);
804 ret
= SIC_GetIconIndex(sTemp
, nIndex
);
805 HeapFree(GetProcessHeap(),0,sTemp
);
809 INT WINAPI
Shell_GetCachedImageIndexAW(LPCVOID szPath
, INT nIndex
, BOOL bSimulateDoc
)
810 { if( VERSION_OsIsUnicode())
811 return Shell_GetCachedImageIndexW(szPath
, nIndex
, bSimulateDoc
);
812 return Shell_GetCachedImageIndexA(szPath
, nIndex
, bSimulateDoc
);
815 /*************************************************************************
816 * ExtractIconEx [shell32.189]
818 HICON WINAPI
ExtractIconExAW ( LPCVOID lpszFile
, INT nIconIndex
, HICON
* phiconLarge
, HICON
* phiconSmall
, UINT nIcons
)
819 { if (VERSION_OsIsUnicode())
820 return ExtractIconExW ( lpszFile
, nIconIndex
, phiconLarge
, phiconSmall
, nIcons
);
821 return ExtractIconExA ( lpszFile
, nIconIndex
, phiconLarge
, phiconSmall
, nIcons
);
823 /*************************************************************************
824 * ExtractIconExA [shell32.190]
827 * 1 file is not valid
828 * HICON handle of a icon (phiconLarge/Small == NULL)
830 HICON WINAPI
ExtractIconExA ( LPCSTR lpszFile
, INT nIconIndex
, HICON
* phiconLarge
, HICON
* phiconSmall
, UINT nIcons
)
833 TRACE("file=%s idx=%i %p %p num=%i\n", lpszFile
, nIconIndex
, phiconLarge
, phiconSmall
, nIcons
);
835 if (nIconIndex
==-1) /* Number of icons requested */
836 return ICO_ExtractIconEx(lpszFile
, NULL
, -1, 0, 0, 0 );
840 { ret
= ICO_ExtractIconEx(lpszFile
, phiconLarge
, nIconIndex
, nIcons
, 32, 32 );
842 { ret
= phiconLarge
[0];
846 /* if no pointers given and one icon expected, return the handle directly*/
847 if (!phiconLarge
&& ! phiconSmall
&& nIcons
==1 )
851 { ret
= ICO_ExtractIconEx(lpszFile
, phiconSmall
, nIconIndex
, nIcons
, 16, 16 );
853 { ret
= phiconSmall
[0];
859 /*************************************************************************
860 * ExtractIconExW [shell32.191]
862 HICON WINAPI
ExtractIconExW ( LPCWSTR lpszFile
, INT nIconIndex
, HICON
* phiconLarge
, HICON
* phiconSmall
, UINT nIcons
)
866 TRACE("file=%s idx=%i %p %p num=%i\n", debugstr_w(lpszFile
), nIconIndex
, phiconLarge
, phiconSmall
, nIcons
);
868 sFile
= HEAP_strdupWtoA (GetProcessHeap(),0,lpszFile
);
869 ret
= ExtractIconExA ( sFile
, nIconIndex
, phiconLarge
, phiconSmall
, nIcons
);
870 HeapFree(GetProcessHeap(),0,sFile
);