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"
25 DEFAULT_DEBUG_CHANNEL(shell
)
31 BYTE bWidth
; /* Width, in pixels, of the image */
32 BYTE bHeight
; /* Height, in pixels, of the image */
33 BYTE bColorCount
; /* Number of colors in image (0 if >=8bpp) */
34 BYTE bReserved
; /* Reserved ( must be 0) */
35 WORD wPlanes
; /* Color Planes */
36 WORD wBitCount
; /* Bits per pixel */
37 DWORD dwBytesInRes
; /* How many bytes in this resource? */
38 DWORD dwImageOffset
; /* Where in the file is this image? */
39 } icoICONDIRENTRY
, *LPicoICONDIRENTRY
;
43 WORD idReserved
; /* Reserved (must be 0) */
44 WORD idType
; /* Resource Type (RES_ICON or RES_CURSOR) */
45 WORD idCount
; /* How many images */
46 icoICONDIRENTRY idEntries
[1]; /* An entry for each image (idCount of 'em) */
47 } icoICONDIR
, *LPicoICONDIR
;
52 static void dumpIcoDirEnty ( LPicoICONDIRENTRY entry
)
54 TRACE("width = 0x%08x height = 0x%08x\n", entry
->bWidth
, entry
->bHeight
);
55 TRACE("colors = 0x%08x planes = 0x%08x\n", entry
->bColorCount
, entry
->wPlanes
);
56 TRACE("bitcount = 0x%08x bytesinres = 0x%08lx offset = 0x%08lx\n",
57 entry
->wBitCount
, entry
->dwBytesInRes
, entry
->dwImageOffset
);
59 static void dumpIcoDir ( LPicoICONDIR entry
)
61 TRACE("type = 0x%08x count = 0x%08x\n", entry
->idType
, entry
->idCount
);
64 /*************************************************************************
65 * SHELL_GetResourceTable
67 static DWORD
SHELL_GetResourceTable(HFILE hFile
, LPBYTE
*retptr
)
68 { IMAGE_DOS_HEADER mz_header
;
72 TRACE("0x%08x %p\n", hFile
, retptr
);
75 _llseek( hFile
, 0, SEEK_SET
);
76 if ((_lread(hFile
,&mz_header
,sizeof(mz_header
)) != sizeof(mz_header
)) || (mz_header
.e_magic
!= IMAGE_DOS_SIGNATURE
))
77 { if (mz_header
.e_cblp
== 1) /* .ICO file ? */
78 { *retptr
= (LPBYTE
)-1; /* ICONHEADER.idType, must be 1 */
82 return 0; /* failed */
84 _llseek( hFile
, mz_header
.e_lfanew
, SEEK_SET
);
86 if (_lread( hFile
, magic
, sizeof(magic
) ) != sizeof(magic
))
89 _llseek( hFile
, mz_header
.e_lfanew
, SEEK_SET
);
91 if (*(DWORD
*)magic
== IMAGE_NT_SIGNATURE
)
92 return IMAGE_NT_SIGNATURE
;
94 if (*(WORD
*)magic
== IMAGE_OS2_SIGNATURE
)
95 { IMAGE_OS2_HEADER ne_header
;
96 LPBYTE pTypeInfo
= (LPBYTE
)-1;
98 if (_lread(hFile
,&ne_header
,sizeof(ne_header
))!=sizeof(ne_header
))
101 if (ne_header
.ne_magic
!= IMAGE_OS2_SIGNATURE
)
104 size
= ne_header
.rname_tab_offset
- ne_header
.resource_tab_offset
;
106 if( size
> sizeof(NE_TYPEINFO
) )
107 { pTypeInfo
= (BYTE
*)HeapAlloc( GetProcessHeap(), 0, size
);
109 { _llseek(hFile
, mz_header
.e_lfanew
+ne_header
.resource_tab_offset
, SEEK_SET
);
110 if( _lread( hFile
, (char*)pTypeInfo
, size
) != size
)
111 { HeapFree( GetProcessHeap(), 0, pTypeInfo
);
117 return IMAGE_OS2_SIGNATURE
;
119 return 0; /* failed */
121 /*************************************************************************
124 static BYTE
* SHELL_LoadResource( HFILE hFile
, NE_NAMEINFO
* pNInfo
, WORD sizeShift
, ULONG
*uSize
)
127 TRACE("0x%08x %p 0x%08x\n", hFile
, pNInfo
, sizeShift
);
129 *uSize
= (DWORD
)pNInfo
->length
<< sizeShift
;
130 if( (ptr
= (BYTE
*)HeapAlloc(GetProcessHeap(),0, *uSize
) ))
131 { _llseek( hFile
, (DWORD
)pNInfo
->offset
<< sizeShift
, SEEK_SET
);
132 _lread( hFile
, (char*)ptr
, pNInfo
->length
<< sizeShift
);
138 /*************************************************************************
141 static BYTE
* ICO_LoadIcon( HFILE hFile
, LPicoICONDIRENTRY lpiIDE
, ULONG
*uSize
)
144 TRACE("0x%08x %p\n", hFile
, lpiIDE
);
146 *uSize
= lpiIDE
->dwBytesInRes
;
147 if( (ptr
= (BYTE
*)HeapAlloc(GetProcessHeap(),0, *uSize
)) )
148 { _llseek( hFile
, lpiIDE
->dwImageOffset
, SEEK_SET
);
149 _lread( hFile
, (char*)ptr
, lpiIDE
->dwBytesInRes
);
156 /*************************************************************************
157 * ICO_GetIconDirectory
159 * Reads .ico file and build phony ICONDIR struct
160 * see http://www.microsoft.com/win32dev/ui/icons.htm
162 #define HEADER_SIZE (sizeof(CURSORICONDIR) - sizeof (CURSORICONDIRENTRY))
163 #define HEADER_SIZE_FILE (sizeof(icoICONDIR) - sizeof (icoICONDIRENTRY))
165 static BYTE
* ICO_GetIconDirectory( HFILE hFile
, LPicoICONDIR
* lplpiID
, ULONG
*uSize
)
166 { CURSORICONDIR lpcid
; /* icon resource in resource-dir format */
167 LPicoICONDIR lpiID
; /* icon resource in file format */
170 TRACE("0x%08x %p\n", hFile
, lplpiID
);
172 _llseek( hFile
, 0, SEEK_SET
);
173 if( _lread(hFile
,(char*)&lpcid
, HEADER_SIZE_FILE
) != HEADER_SIZE_FILE
)
176 if( lpcid
.idReserved
|| (lpcid
.idType
!= 1) || (!lpcid
.idCount
) )
179 i
= lpcid
.idCount
* sizeof(icoICONDIRENTRY
);
180 lpiID
= (LPicoICONDIR
)HeapAlloc( GetProcessHeap(), 0, HEADER_SIZE_FILE
+ i
);
182 if( _lread(hFile
,(char*)lpiID
->idEntries
,i
) == i
)
183 { CURSORICONDIR
* lpID
; /* icon resource in resource format */
184 *uSize
= lpcid
.idCount
* sizeof(CURSORICONDIRENTRY
) + HEADER_SIZE
;
185 if( (lpID
= (CURSORICONDIR
*)HeapAlloc(GetProcessHeap(),0, *uSize
) ))
187 /* copy the header */
188 lpID
->idReserved
= lpiID
->idReserved
= 0;
189 lpID
->idType
= lpiID
->idType
= 1;
190 lpID
->idCount
= lpiID
->idCount
= lpcid
.idCount
;
192 /* copy the entrys */
193 for( i
=0; i
< lpiID
->idCount
; i
++ )
194 { memcpy((void*)&(lpID
->idEntries
[i
]),(void*)&(lpiID
->idEntries
[i
]), sizeof(CURSORICONDIRENTRY
) - 2);
195 lpID
->idEntries
[i
].wResId
= i
;
204 HeapFree( GetProcessHeap(), 0, lpiID
);
208 /*************************************************************************
211 * failure:0; success: icon handle or nr of icons (nIconIndex-1)
213 HICON WINAPI
ICO_ExtractIconEx(LPCSTR lpszExeFileName
, HICON
* RetPtr
, UINT nIconIndex
, UINT n
, UINT cxDesired
, UINT cyDesired
)
218 HFILE hFile
= OpenFile( lpszExeFileName
, &ofs
, OF_READ
);
219 UINT16 iconDirCount
= 0,iconCount
= 0;
224 TRACE("(file %s,start %d,extract %d\n", lpszExeFileName
, nIconIndex
, n
);
226 if( hFile
== HFILE_ERROR
|| (nIconIndex
!=-1 && !n
) )
229 sig
= SHELL_GetResourceTable(hFile
,&pData
);
232 if( sig
==IMAGE_OS2_SIGNATURE
|| sig
==1 ) /* .ICO file */
234 NE_TYPEINFO
*pTInfo
= (NE_TYPEINFO
*)(pData
+ 2);
235 NE_NAMEINFO
*pIconStorage
= NULL
;
236 NE_NAMEINFO
*pIconDir
= NULL
;
237 LPicoICONDIR lpiID
= NULL
;
239 TRACE("-- OS2/icon Signature (0x%08lx)\n", sig
);
241 if( pData
== (BYTE
*)-1 )
242 { pCIDir
= ICO_GetIconDirectory(hFile
, &lpiID
, &uSize
); /* check for .ICO file */
244 { iconDirCount
= 1; iconCount
= lpiID
->idCount
;
245 TRACE("-- icon found %p 0x%08lx 0x%08x 0x%08x\n", pCIDir
, uSize
, iconDirCount
, iconCount
);
248 else while( pTInfo
->type_id
&& !(pIconStorage
&& pIconDir
) )
249 { if( pTInfo
->type_id
== NE_RSCTYPE_GROUP_ICON
) /* find icon directory and icon repository */
250 { iconDirCount
= pTInfo
->count
;
251 pIconDir
= ((NE_NAMEINFO
*)(pTInfo
+ 1));
252 TRACE("\tfound directory - %i icon families\n", iconDirCount
);
254 if( pTInfo
->type_id
== NE_RSCTYPE_ICON
)
255 { iconCount
= pTInfo
->count
;
256 pIconStorage
= ((NE_NAMEINFO
*)(pTInfo
+ 1));
257 TRACE("\ttotal icons - %i\n", iconCount
);
259 pTInfo
= (NE_TYPEINFO
*)((char*)(pTInfo
+1)+pTInfo
->count
*sizeof(NE_NAMEINFO
));
262 if( (pIconStorage
&& pIconDir
) || lpiID
) /* load resources and create icons */
263 { if( nIconIndex
== (UINT16
)-1 )
264 { RetPtr
[0] = iconDirCount
;
266 else if( nIconIndex
< iconDirCount
)
268 if( n
> iconDirCount
- nIconIndex
)
269 n
= iconDirCount
- nIconIndex
;
271 for( i
= nIconIndex
; i
< nIconIndex
+ n
; i
++ )
272 { /* .ICO files have only one icon directory */
274 if( lpiID
== NULL
) /* *.ico */
275 pCIDir
= SHELL_LoadResource( hFile
, pIconDir
+ i
, *(WORD
*)pData
, &uSize
);
276 RetPtr
[i
-nIconIndex
] = pLookupIconIdFromDirectoryEx( pCIDir
, TRUE
, GetSystemMetrics(SM_CXICON
), GetSystemMetrics(SM_CYICON
), 0);
277 HeapFree(GetProcessHeap(), 0, pCIDir
);
280 for( icon
= nIconIndex
; icon
< nIconIndex
+ n
; icon
++ )
283 { pCIDir
= ICO_LoadIcon( hFile
, lpiID
->idEntries
+ RetPtr
[icon
-nIconIndex
], &uSize
);
286 { for( i
= 0; i
< iconCount
; i
++ )
287 { if( pIconStorage
[i
].id
== (RetPtr
[icon
-nIconIndex
] | 0x8000) )
288 { pCIDir
= SHELL_LoadResource( hFile
, pIconStorage
+ i
,*(WORD
*)pData
, &uSize
);
293 { RetPtr
[icon
-nIconIndex
] = (HICON
) pCreateIconFromResourceEx(pCIDir
,uSize
,TRUE
,0x00030000, cxDesired
, cyDesired
, LR_DEFAULTCOLOR
);
296 { RetPtr
[icon
-nIconIndex
] = 0;
302 HeapFree( GetProcessHeap(), 0, lpiID
);
304 HeapFree( GetProcessHeap(), 0, pData
);
309 if( sig
== IMAGE_NT_SIGNATURE
)
310 { LPBYTE idata
,igdata
;
311 PIMAGE_DOS_HEADER dheader
;
312 PIMAGE_NT_HEADERS pe_header
;
313 PIMAGE_SECTION_HEADER pe_sections
;
314 PIMAGE_RESOURCE_DIRECTORY rootresdir
,iconresdir
,icongroupresdir
;
315 PIMAGE_RESOURCE_DATA_ENTRY idataent
,igdataent
;
316 PIMAGE_RESOURCE_DIRECTORY_ENTRY xresent
;
319 if ( !(fmapping
= CreateFileMappingA(hFile
,NULL
,PAGE_READONLY
|SEC_COMMIT
,0,0,NULL
)))
320 { WARN("failed to create filemap.\n"); /* FIXME, INVALID_HANDLE_VALUE? */
321 goto end_2
; /* failure */
324 if ( !(peimage
= MapViewOfFile(fmapping
,FILE_MAP_READ
,0,0,0)))
325 { WARN("failed to mmap filemap.\n");
326 goto end_2
; /* failure */
329 dheader
= (PIMAGE_DOS_HEADER
)peimage
;
330 pe_header
= (PIMAGE_NT_HEADERS
)(peimage
+dheader
->e_lfanew
); /* it is a pe header, SHELL_GetResourceTable checked that */
331 pe_sections
= (PIMAGE_SECTION_HEADER
)(((char*)pe_header
)+sizeof(*pe_header
)); /* probably makes problems with short PE headers...*/
334 for (i
=0;i
<pe_header
->FileHeader
.NumberOfSections
;i
++)
335 { if (pe_sections
[i
].Characteristics
& IMAGE_SCN_CNT_UNINITIALIZED_DATA
)
337 /* FIXME: doesn't work when the resources are not in a seperate section */
338 if (pe_sections
[i
].VirtualAddress
== pe_header
->OptionalHeader
.DataDirectory
[IMAGE_DIRECTORY_ENTRY_RESOURCE
].VirtualAddress
)
339 { rootresdir
= (PIMAGE_RESOURCE_DIRECTORY
)((char*)peimage
+pe_sections
[i
].PointerToRawData
);
345 { WARN("haven't found section for resource directory.\n");
346 goto end_3
; /* failure */
348 /* search the group icon dir*/
349 if (!(icongroupresdir
= GetResDirEntryW(rootresdir
,RT_GROUP_ICONW
, (DWORD
)rootresdir
,FALSE
)))
350 { WARN("No Icongroupresourcedirectory!\n");
351 goto end_3
; /* failure */
353 iconDirCount
= icongroupresdir
->NumberOfNamedEntries
+icongroupresdir
->NumberOfIdEntries
;
355 /* number of icons requested */
356 if( nIconIndex
== -1 )
357 { hRet
= iconDirCount
;
358 goto end_3
; /* success */
361 if (nIconIndex
>= iconDirCount
)
362 { WARN("nIconIndex %d is larger than iconDirCount %d\n",nIconIndex
,iconDirCount
);
363 goto end_3
; /* failure */
366 xresent
= (PIMAGE_RESOURCE_DIRECTORY_ENTRY
)(icongroupresdir
+1); /* caller just wanted the number of entries */
368 if( n
> iconDirCount
- nIconIndex
) /* assure we don't get too much ... */
369 { n
= iconDirCount
- nIconIndex
;
372 xresent
= xresent
+nIconIndex
; /* starting from specified index ... */
374 for (i
=0;i
<n
;i
++,xresent
++)
375 { PIMAGE_RESOURCE_DIRECTORY resdir
;
377 /* go down this resource entry, name */
378 resdir
= (PIMAGE_RESOURCE_DIRECTORY
)((DWORD
)rootresdir
+(xresent
->u2
.s
.OffsetToDirectory
));
380 /* default language (0) */
381 resdir
= GetResDirEntryW(resdir
,(LPWSTR
)0,(DWORD
)rootresdir
,TRUE
);
382 igdataent
= (PIMAGE_RESOURCE_DATA_ENTRY
)resdir
;
384 /* lookup address in mapped image for virtual address */
387 for (j
=0;j
<pe_header
->FileHeader
.NumberOfSections
;j
++)
388 { if (igdataent
->OffsetToData
< pe_sections
[j
].VirtualAddress
)
390 if (igdataent
->OffsetToData
+igdataent
->Size
> pe_sections
[j
].VirtualAddress
+pe_sections
[j
].SizeOfRawData
)
392 igdata
= peimage
+(igdataent
->OffsetToData
-pe_sections
[j
].VirtualAddress
+pe_sections
[j
].PointerToRawData
);
396 { WARN("no matching real address for icongroup!\n");
397 goto end_3
; /* failure */
399 RetPtr
[i
] = (HICON
)pLookupIconIdFromDirectoryEx(igdata
, TRUE
, cxDesired
, cyDesired
, LR_DEFAULTCOLOR
);
402 if (!(iconresdir
=GetResDirEntryW(rootresdir
,RT_ICONW
,(DWORD
)rootresdir
,FALSE
)))
403 { WARN("No Iconresourcedirectory!\n");
404 goto end_3
; /* failure */
408 { PIMAGE_RESOURCE_DIRECTORY xresdir
;
409 xresdir
= GetResDirEntryW(iconresdir
,(LPWSTR
)(DWORD
)RetPtr
[i
],(DWORD
)rootresdir
,FALSE
);
410 xresdir
= GetResDirEntryW(xresdir
,(LPWSTR
)0,(DWORD
)rootresdir
,TRUE
);
411 idataent
= (PIMAGE_RESOURCE_DATA_ENTRY
)xresdir
;
414 /* map virtual to address in image */
415 for (j
=0;j
<pe_header
->FileHeader
.NumberOfSections
;j
++)
416 { if (idataent
->OffsetToData
< pe_sections
[j
].VirtualAddress
)
418 if (idataent
->OffsetToData
+idataent
->Size
> pe_sections
[j
].VirtualAddress
+pe_sections
[j
].SizeOfRawData
)
420 idata
= peimage
+(idataent
->OffsetToData
-pe_sections
[j
].VirtualAddress
+pe_sections
[j
].PointerToRawData
);
423 { WARN("no matching real address found for icondata!\n");
427 RetPtr
[i
] = (HICON
) pCreateIconFromResourceEx(idata
,idataent
->Size
,TRUE
,0x00030000, cxDesired
, cyDesired
, LR_DEFAULTCOLOR
);
429 hRet
= RetPtr
[0]; /* return first icon */
430 goto end_3
; /* sucess */
432 goto end_1
; /* unknown filetype */
434 /* cleaning up (try & catch would be nicer:-) ) */
435 end_3
: UnmapViewOfFile(peimage
); /* success */
436 end_2
: CloseHandle(fmapping
);
437 end_1
: _lclose( hFile
);
441 /********************** THE ICON CACHE ********************************/
443 #define INVALID_INDEX -1
446 { LPCSTR sSourceFile
; /* file (not path!) containing the icon */
447 DWORD dwSourceIndex
; /* index within the file, if it is a resoure ID it will be negated */
448 DWORD dwListIndex
; /* index within the iconlist */
449 DWORD dwFlags
; /* GIL_* flags */
451 } SIC_ENTRY
, * LPSIC_ENTRY
;
453 static HDPA sic_hdpa
= 0;
454 static CRITICAL_SECTION SHELL32_SicCS
;
456 /*****************************************************************************
457 * SIC_CompareEntrys [called by comctl32.dll]
460 * Callback for DPA_Search
462 INT CALLBACK
SIC_CompareEntrys( LPVOID p1
, LPVOID p2
, LPARAM lparam
)
463 { TRACE("%p %p\n", p1
, p2
);
465 if (((LPSIC_ENTRY
)p1
)->dwSourceIndex
!= ((LPSIC_ENTRY
)p2
)->dwSourceIndex
) /* first the faster one*/
468 if (strcasecmp(((LPSIC_ENTRY
)p1
)->sSourceFile
,((LPSIC_ENTRY
)p2
)->sSourceFile
))
473 /*****************************************************************************
474 * SIC_IconAppend [internal]
477 * appends a icon pair to the end of the cache
479 static INT
SIC_IconAppend (LPCSTR sSourceFile
, INT dwSourceIndex
, HICON hSmallIcon
, HICON hBigIcon
)
480 { LPSIC_ENTRY lpsice
;
481 INT ret
, index
, index1
;
483 TRACE("%s %i %x %x\n", sSourceFile
, dwSourceIndex
, hSmallIcon
,hBigIcon
);
485 lpsice
= (LPSIC_ENTRY
) SHAlloc (sizeof (SIC_ENTRY
));
487 lpsice
->sSourceFile
= HEAP_strdupA (GetProcessHeap(), 0, PathFindFilenameA(sSourceFile
));
488 lpsice
->dwSourceIndex
= dwSourceIndex
;
490 EnterCriticalSection(&SHELL32_SicCS
);
492 index
= pDPA_InsertPtr(sic_hdpa
, 0x7fff, lpsice
);
493 if ( INVALID_INDEX
== index
)
500 index
= pImageList_AddIcon (ShellSmallIconList
, hSmallIcon
);
501 index1
= pImageList_AddIcon (ShellBigIconList
, hBigIcon
);
505 FIXME("iconlists out of sync 0x%x 0x%x\n", index
, index1
);
507 lpsice
->dwListIndex
= index
;
508 ret
= lpsice
->dwListIndex
;
511 LeaveCriticalSection(&SHELL32_SicCS
);
514 /****************************************************************************
515 * SIC_LoadIcon [internal]
518 * gets small/big icon by number from a file
520 static INT
SIC_LoadIcon (LPCSTR sSourceFile
, INT dwSourceIndex
)
521 { HICON hiconLarge
=0;
524 ICO_ExtractIconEx(sSourceFile
, &hiconLarge
, dwSourceIndex
, 1, 32, 32 );
525 ICO_ExtractIconEx(sSourceFile
, &hiconSmall
, dwSourceIndex
, 1, 16, 16 );
528 if ( !hiconLarge
|| !hiconSmall
)
530 WARN("failure loading icon %i from %s (%x %x)\n", dwSourceIndex
, sSourceFile
, hiconLarge
, hiconSmall
);
533 return SIC_IconAppend (sSourceFile
, dwSourceIndex
, hiconSmall
, hiconLarge
);
535 /*****************************************************************************
536 * SIC_GetIconIndex [internal]
539 * sSourceFile [IN] filename of file containing the icon
540 * index [IN] index/resID (negated) in this file
543 * look in the cache for a proper icon. if not available the icon is taken
544 * from the file and cached
546 INT
SIC_GetIconIndex (LPCSTR sSourceFile
, INT dwSourceIndex
)
548 INT ret
, index
= INVALID_INDEX
;
550 TRACE("%s %i\n", sSourceFile
, dwSourceIndex
);
552 sice
.sSourceFile
= PathFindFilenameA(sSourceFile
);
553 sice
.dwSourceIndex
= dwSourceIndex
;
555 EnterCriticalSection(&SHELL32_SicCS
);
557 if (NULL
!= pDPA_GetPtr (sic_hdpa
, 0))
559 index
= pDPA_Search (sic_hdpa
, &sice
, -1L, SIC_CompareEntrys
, 0, 0);
562 if ( INVALID_INDEX
== index
)
564 ret
= SIC_LoadIcon (sSourceFile
, dwSourceIndex
);
569 ret
= ((LPSIC_ENTRY
)pDPA_GetPtr(sic_hdpa
, index
))->dwListIndex
;
572 LeaveCriticalSection(&SHELL32_SicCS
);
575 /****************************************************************************
576 * SIC_LoadIcon [internal]
579 * retrives the specified icon from the iconcache. if not found try's to load the icon
581 static HICON WINE_UNUSED
SIC_GetIcon (LPCSTR sSourceFile
, INT dwSourceIndex
, BOOL bSmallIcon
)
584 TRACE("%s %i\n", sSourceFile
, dwSourceIndex
);
586 index
= SIC_GetIconIndex(sSourceFile
, dwSourceIndex
);
588 if (INVALID_INDEX
== index
)
590 return INVALID_INDEX
;
594 return pImageList_GetIcon(ShellSmallIconList
, index
, ILD_NORMAL
);
595 return pImageList_GetIcon(ShellBigIconList
, index
, ILD_NORMAL
);
598 /*****************************************************************************
599 * SIC_Initialize [internal]
602 * hack to load the resources from the shell32.dll under a different dll name
603 * will be removed when the resource-compiler is ready
605 BOOL
SIC_Initialize(void)
612 if (sic_hdpa
) /* already initialized?*/
615 InitializeCriticalSection(&SHELL32_SicCS
);
616 MakeCriticalSectionGlobal(&SHELL32_SicCS
);
618 sic_hdpa
= pDPA_Create(16);
625 ShellSmallIconList
= pImageList_Create(16,16,ILC_COLORDDB
| ILC_MASK
,0,0x20);
626 ShellBigIconList
= pImageList_Create(32,32,ILC_COLORDDB
| ILC_MASK
,0,0x20);
628 pImageList_SetBkColor(ShellSmallIconList
, GetSysColor(COLOR_WINDOW
));
629 pImageList_SetBkColor(ShellBigIconList
, GetSysColor(COLOR_WINDOW
));
631 for (index
=1; index
<39; index
++)
633 hSm
= LoadImageA(shell32_hInstance
, MAKEINTRESOURCEA(index
), IMAGE_ICON
, 16, 16,LR_SHARED
);
634 hLg
= LoadImageA(shell32_hInstance
, MAKEINTRESOURCEA(index
), IMAGE_ICON
, 32, 32,LR_SHARED
);
638 hSm
= LoadImageA(shell32_hInstance
, MAKEINTRESOURCEA(0), IMAGE_ICON
, 16, 16,LR_SHARED
);
639 hLg
= LoadImageA(shell32_hInstance
, MAKEINTRESOURCEA(0), IMAGE_ICON
, 32, 32,LR_SHARED
);
641 SIC_IconAppend ("shell32.dll", index
, hSm
, hLg
);
644 TRACE("hIconSmall=%p hIconBig=%p\n",ShellSmallIconList
, ShellBigIconList
);
648 /*************************************************************************
653 void SIC_Destroy(void)
660 EnterCriticalSection(&SHELL32_SicCS
);
662 if (sic_hdpa
&& NULL
!= pDPA_GetPtr (sic_hdpa
, 0))
664 for (i
=0; i
< pDPA_GetPtrCount(sic_hdpa
); ++i
)
666 lpsice
= pDPA_GetPtr(sic_hdpa
, i
);
669 pDPA_Destroy(sic_hdpa
);
674 LeaveCriticalSection(&SHELL32_SicCS
);
675 DeleteCriticalSection(&SHELL32_SicCS
);
677 /*************************************************************************
678 * Shell_GetImageList [SHELL32.71]
681 * imglist[1|2] [OUT] pointer which recive imagelist handles
684 BOOL WINAPI
Shell_GetImageList(HIMAGELIST
* lpBigList
, HIMAGELIST
* lpSmallList
)
685 { TRACE("(%p,%p)\n",lpBigList
,lpSmallList
);
687 { *lpBigList
= ShellBigIconList
;
690 { *lpSmallList
= ShellSmallIconList
;
695 /*************************************************************************
696 * PidlToSicIndex [INTERNAL]
699 * sh [IN] IShellFolder
703 * pIndex [OUT] index within the SIC
706 BOOL
PidlToSicIndex (
714 char szIconFile
[MAX_PATH
]; /* file containing the icon */
715 INT iSourceIndex
; /* index or resID(negated) in this file */
719 TRACE("sf=%p pidl=%p %s\n", sh
, pidl
, bBigIcon
?"Big":"Small");
721 if (SUCCEEDED (IShellFolder_GetUIObjectOf(sh
, 0, 1, &pidl
, &IID_IExtractIconA
, 0, (void **)&ei
)))
723 if (SUCCEEDED(IExtractIconA_GetIconLocation(ei
, uFlags
, szIconFile
, MAX_PATH
, &iSourceIndex
, &dwFlags
)))
725 *pIndex
= SIC_GetIconIndex(szIconFile
, iSourceIndex
);
728 IExtractIconA_Release(ei
);
731 if (INVALID_INDEX
== *pIndex
) /* default icon when failed */
738 /*************************************************************************
739 * SHMapPIDLToSystemImageListIndex [SHELL32.77]
742 * sh [IN] pointer to an instance of IShellFolder
744 * pIndex [OUT][OPTIONAL] SIC index for big icon
747 UINT WINAPI
SHMapPIDLToSystemImageListIndex(LPSHELLFOLDER sh
, LPITEMIDLIST pidl
, UINT
* pIndex
)
751 TRACE("(SF=%p,pidl=%p,%p)\n",sh
,pidl
,pIndex
);
755 PidlToSicIndex ( sh
, pidl
, 1, 0, pIndex
);
756 PidlToSicIndex ( sh
, pidl
, 0, 0, &Index
);
760 /*************************************************************************
761 * Shell_GetCachedImageIndex [SHELL32.72]
764 INT WINAPI
Shell_GetCachedImageIndexA(LPCSTR szPath
, INT nIndex
, BOOL bSimulateDoc
)
766 WARN("(%s,%08x,%08x) semi-stub.\n",debugstr_a(szPath
), nIndex
, bSimulateDoc
);
767 return SIC_GetIconIndex(szPath
, nIndex
);
770 INT WINAPI
Shell_GetCachedImageIndexW(LPCWSTR szPath
, INT nIndex
, BOOL bSimulateDoc
)
772 LPSTR sTemp
= HEAP_strdupWtoA (GetProcessHeap(),0,szPath
);
774 WARN("(%s,%08x,%08x) semi-stub.\n",debugstr_w(szPath
), nIndex
, bSimulateDoc
);
776 ret
= SIC_GetIconIndex(sTemp
, nIndex
);
777 HeapFree(GetProcessHeap(),0,sTemp
);
781 INT WINAPI
Shell_GetCachedImageIndexAW(LPCVOID szPath
, INT nIndex
, BOOL bSimulateDoc
)
782 { if( VERSION_OsIsUnicode())
783 return Shell_GetCachedImageIndexW(szPath
, nIndex
, bSimulateDoc
);
784 return Shell_GetCachedImageIndexA(szPath
, nIndex
, bSimulateDoc
);
787 /*************************************************************************
788 * ExtractIconEx [shell32.189]
790 HICON WINAPI
ExtractIconExAW ( LPCVOID lpszFile
, INT nIconIndex
, HICON
* phiconLarge
, HICON
* phiconSmall
, UINT nIcons
)
791 { if (VERSION_OsIsUnicode())
792 return ExtractIconExW ( lpszFile
, nIconIndex
, phiconLarge
, phiconSmall
, nIcons
);
793 return ExtractIconExA ( lpszFile
, nIconIndex
, phiconLarge
, phiconSmall
, nIcons
);
795 /*************************************************************************
796 * ExtractIconExA [shell32.190]
799 * 1 file is not valid
800 * HICON handle of a icon (phiconLarge/Small == NULL)
802 HICON WINAPI
ExtractIconExA ( LPCSTR lpszFile
, INT nIconIndex
, HICON
* phiconLarge
, HICON
* phiconSmall
, UINT nIcons
)
805 TRACE("file=%s idx=%i %p %p num=%i\n", lpszFile
, nIconIndex
, phiconLarge
, phiconSmall
, nIcons
);
807 if (nIconIndex
==-1) /* Number of icons requested */
808 return ICO_ExtractIconEx(lpszFile
, NULL
, -1, 0, 0, 0 );
812 { ret
= ICO_ExtractIconEx(lpszFile
, phiconLarge
, nIconIndex
, nIcons
, 32, 32 );
814 { ret
= phiconLarge
[0];
818 /* if no pointers given and one icon expected, return the handle directly*/
819 if (!phiconLarge
&& ! phiconSmall
&& nIcons
==1 )
823 { ret
= ICO_ExtractIconEx(lpszFile
, phiconSmall
, nIconIndex
, nIcons
, 16, 16 );
825 { ret
= phiconSmall
[0];
831 /*************************************************************************
832 * ExtractIconExW [shell32.191]
834 HICON WINAPI
ExtractIconExW ( LPCWSTR lpszFile
, INT nIconIndex
, HICON
* phiconLarge
, HICON
* phiconSmall
, UINT nIcons
)
838 TRACE("file=%s idx=%i %p %p num=%i\n", debugstr_w(lpszFile
), nIconIndex
, phiconLarge
, phiconSmall
, nIcons
);
840 sFile
= HEAP_strdupWtoA (GetProcessHeap(),0,lpszFile
);
841 ret
= ExtractIconExA ( sFile
, nIconIndex
, phiconLarge
, phiconSmall
, nIcons
);
842 HeapFree(GetProcessHeap(),0,sFile
);