1 | /* $Id: iconcache.c,v 1.6 2001-06-01 08:22:09 sandervl Exp $ */
|
---|
2 | /*
|
---|
3 | * shell icon cache (SIC)
|
---|
4 | *
|
---|
5 | */
|
---|
6 | #ifdef __WIN32OS2__
|
---|
7 | #define ICOM_CINTERFACE 1
|
---|
8 | #include <odin.h>
|
---|
9 | #endif
|
---|
10 | #include <string.h>
|
---|
11 | #include <sys/types.h>
|
---|
12 | #ifndef __WIN32OS2__
|
---|
13 | #include <unistd.h>
|
---|
14 | #endif
|
---|
15 | #include "winbase.h"
|
---|
16 | #include "windef.h"
|
---|
17 | #include "wingdi.h"
|
---|
18 | #include "winuser.h"
|
---|
19 | #include "wine/winuser16.h"
|
---|
20 | #include "wine/winbase16.h"
|
---|
21 | #include "neexe.h"
|
---|
22 | #include "cursoricon.h"
|
---|
23 | #include "module.h"
|
---|
24 | #include "heap.h"
|
---|
25 | #include "debugtools.h"
|
---|
26 |
|
---|
27 | #include "shellapi.h"
|
---|
28 | #include "shlguid.h"
|
---|
29 | #include "pidl.h"
|
---|
30 | #include "shell32_main.h"
|
---|
31 | #include "wine/undocshell.h"
|
---|
32 | #include "shlwapi.h"
|
---|
33 |
|
---|
34 | DEFAULT_DEBUG_CHANNEL(shell)
|
---|
35 |
|
---|
36 | #include "pshpack1.h"
|
---|
37 |
|
---|
38 | typedef struct
|
---|
39 | {
|
---|
40 | BYTE bWidth; /* Width, in pixels, of the image */
|
---|
41 | BYTE bHeight; /* Height, in pixels, of the image */
|
---|
42 | BYTE bColorCount; /* Number of colors in image (0 if >=8bpp) */
|
---|
43 | BYTE bReserved; /* Reserved ( must be 0) */
|
---|
44 | WORD wPlanes; /* Color Planes */
|
---|
45 | WORD wBitCount; /* Bits per pixel */
|
---|
46 | DWORD dwBytesInRes; /* How many bytes in this resource? */
|
---|
47 | DWORD dwImageOffset; /* Where in the file is this image? */
|
---|
48 | } icoICONDIRENTRY, *LPicoICONDIRENTRY;
|
---|
49 |
|
---|
50 | typedef struct
|
---|
51 | {
|
---|
52 | WORD idReserved; /* Reserved (must be 0) */
|
---|
53 | WORD idType; /* Resource Type (RES_ICON or RES_CURSOR) */
|
---|
54 | WORD idCount; /* How many images */
|
---|
55 | icoICONDIRENTRY idEntries[1]; /* An entry for each image (idCount of 'em) */
|
---|
56 | } icoICONDIR, *LPicoICONDIR;
|
---|
57 |
|
---|
58 | #include "poppack.h"
|
---|
59 |
|
---|
60 | #if 0
|
---|
61 | static void dumpIcoDirEnty ( LPicoICONDIRENTRY entry )
|
---|
62 | {
|
---|
63 | TRACE("width = 0x%08x height = 0x%08x\n", entry->bWidth, entry->bHeight);
|
---|
64 | TRACE("colors = 0x%08x planes = 0x%08x\n", entry->bColorCount, entry->wPlanes);
|
---|
65 | TRACE("bitcount = 0x%08x bytesinres = 0x%08lx offset = 0x%08lx\n",
|
---|
66 | entry->wBitCount, entry->dwBytesInRes, entry->dwImageOffset);
|
---|
67 | }
|
---|
68 | static void dumpIcoDir ( LPicoICONDIR entry )
|
---|
69 | {
|
---|
70 | TRACE("type = 0x%08x count = 0x%08x\n", entry->idType, entry->idCount);
|
---|
71 | }
|
---|
72 | #endif
|
---|
73 | /*************************************************************************
|
---|
74 | * SHELL_GetResourceTable
|
---|
75 | */
|
---|
76 | #ifdef __WIN32OS2__
|
---|
77 | DWORD SHELL_GetResourceTable(HFILE hFile, LPBYTE *retptr)
|
---|
78 | #else
|
---|
79 | static DWORD SHELL_GetResourceTable(HFILE hFile, LPBYTE *retptr)
|
---|
80 | #endif
|
---|
81 | { IMAGE_DOS_HEADER mz_header;
|
---|
82 | char magic[4];
|
---|
83 | int size;
|
---|
84 |
|
---|
85 | TRACE("0x%08x %p\n", hFile, retptr);
|
---|
86 |
|
---|
87 | *retptr = NULL;
|
---|
88 | _llseek( hFile, 0, SEEK_SET );
|
---|
89 | if ((_lread(hFile,&mz_header,sizeof(mz_header)) != sizeof(mz_header)) || (mz_header.e_magic != IMAGE_DOS_SIGNATURE))
|
---|
90 | { if (mz_header.e_cblp == 1) /* .ICO file ? */
|
---|
91 | { *retptr = (LPBYTE)-1; /* ICONHEADER.idType, must be 1 */
|
---|
92 | return 1;
|
---|
93 | }
|
---|
94 | else
|
---|
95 | return 0; /* failed */
|
---|
96 | }
|
---|
97 | _llseek( hFile, mz_header.e_lfanew, SEEK_SET );
|
---|
98 |
|
---|
99 | if (_lread( hFile, magic, sizeof(magic) ) != sizeof(magic))
|
---|
100 | return 0;
|
---|
101 |
|
---|
102 | _llseek( hFile, mz_header.e_lfanew, SEEK_SET);
|
---|
103 |
|
---|
104 | if (*(DWORD*)magic == IMAGE_NT_SIGNATURE)
|
---|
105 | return IMAGE_NT_SIGNATURE;
|
---|
106 |
|
---|
107 | if (*(WORD*)magic == IMAGE_OS2_SIGNATURE)
|
---|
108 | { IMAGE_OS2_HEADER ne_header;
|
---|
109 | LPBYTE pTypeInfo = (LPBYTE)-1;
|
---|
110 |
|
---|
111 | if (_lread(hFile,&ne_header,sizeof(ne_header))!=sizeof(ne_header))
|
---|
112 | return 0;
|
---|
113 |
|
---|
114 | if (ne_header.ne_magic != IMAGE_OS2_SIGNATURE)
|
---|
115 | return 0;
|
---|
116 |
|
---|
117 | size = ne_header.ne_restab - ne_header.ne_rsrctab;
|
---|
118 |
|
---|
119 | if( size > sizeof(NE_TYPEINFO) )
|
---|
120 | { pTypeInfo = (BYTE*)HeapAlloc( GetProcessHeap(), 0, size);
|
---|
121 | if( pTypeInfo )
|
---|
122 | { _llseek(hFile, mz_header.e_lfanew+ne_header.ne_rsrctab, SEEK_SET);
|
---|
123 | if( _lread( hFile, (char*)pTypeInfo, size) != size )
|
---|
124 | { HeapFree( GetProcessHeap(), 0, pTypeInfo);
|
---|
125 | pTypeInfo = NULL;
|
---|
126 | }
|
---|
127 | }
|
---|
128 | }
|
---|
129 | *retptr = pTypeInfo;
|
---|
130 | return IMAGE_OS2_SIGNATURE;
|
---|
131 | }
|
---|
132 | return 0; /* failed */
|
---|
133 | }
|
---|
134 | /*************************************************************************
|
---|
135 | * SHELL_LoadResource
|
---|
136 | */
|
---|
137 | static BYTE * SHELL_LoadResource( HFILE hFile, NE_NAMEINFO* pNInfo, WORD sizeShift, ULONG *uSize)
|
---|
138 | { BYTE* ptr;
|
---|
139 |
|
---|
140 | TRACE("0x%08x %p 0x%08x\n", hFile, pNInfo, sizeShift);
|
---|
141 |
|
---|
142 | *uSize = (DWORD)pNInfo->length << sizeShift;
|
---|
143 | if( (ptr = (BYTE*)HeapAlloc(GetProcessHeap(),0, *uSize) ))
|
---|
144 | { _llseek( hFile, (DWORD)pNInfo->offset << sizeShift, SEEK_SET);
|
---|
145 | _lread( hFile, (char*)ptr, pNInfo->length << sizeShift);
|
---|
146 | return ptr;
|
---|
147 | }
|
---|
148 | return 0;
|
---|
149 | }
|
---|
150 |
|
---|
151 | /*************************************************************************
|
---|
152 | * ICO_LoadIcon
|
---|
153 | */
|
---|
154 | static BYTE * ICO_LoadIcon( HFILE hFile, LPicoICONDIRENTRY lpiIDE, ULONG *uSize)
|
---|
155 | { BYTE* ptr;
|
---|
156 |
|
---|
157 | TRACE("0x%08x %p\n", hFile, lpiIDE);
|
---|
158 |
|
---|
159 | *uSize = lpiIDE->dwBytesInRes;
|
---|
160 | if( (ptr = (BYTE*)HeapAlloc(GetProcessHeap(),0, *uSize)) )
|
---|
161 | { _llseek( hFile, lpiIDE->dwImageOffset, SEEK_SET);
|
---|
162 | _lread( hFile, (char*)ptr, lpiIDE->dwBytesInRes);
|
---|
163 | return ptr;
|
---|
164 | }
|
---|
165 |
|
---|
166 | return 0;
|
---|
167 | }
|
---|
168 |
|
---|
169 | /*************************************************************************
|
---|
170 | * ICO_GetIconDirectory
|
---|
171 | *
|
---|
172 | * Reads .ico file and build phony ICONDIR struct
|
---|
173 | * see http://www.microsoft.com/win32dev/ui/icons.htm
|
---|
174 | */
|
---|
175 | #define HEADER_SIZE (sizeof(CURSORICONDIR) - sizeof (CURSORICONDIRENTRY))
|
---|
176 | #define HEADER_SIZE_FILE (sizeof(icoICONDIR) - sizeof (icoICONDIRENTRY))
|
---|
177 |
|
---|
178 | static BYTE * ICO_GetIconDirectory( HFILE hFile, LPicoICONDIR* lplpiID, ULONG *uSize )
|
---|
179 | { CURSORICONDIR lpcid; /* icon resource in resource-dir format */
|
---|
180 | LPicoICONDIR lpiID; /* icon resource in file format */
|
---|
181 | int i;
|
---|
182 |
|
---|
183 | TRACE("0x%08x %p\n", hFile, lplpiID);
|
---|
184 |
|
---|
185 | _llseek( hFile, 0, SEEK_SET );
|
---|
186 | if( _lread(hFile,(char*)&lpcid, HEADER_SIZE_FILE) != HEADER_SIZE_FILE )
|
---|
187 | return 0;
|
---|
188 |
|
---|
189 | if( lpcid.idReserved || (lpcid.idType != 1) || (!lpcid.idCount) )
|
---|
190 | return 0;
|
---|
191 |
|
---|
192 | i = lpcid.idCount * sizeof(icoICONDIRENTRY);
|
---|
193 | lpiID = (LPicoICONDIR)HeapAlloc( GetProcessHeap(), 0, HEADER_SIZE_FILE + i);
|
---|
194 |
|
---|
195 | if( _lread(hFile,(char*)lpiID->idEntries,i) == i )
|
---|
196 | { CURSORICONDIR * lpID; /* icon resource in resource format */
|
---|
197 | *uSize = lpcid.idCount * sizeof(CURSORICONDIRENTRY) + HEADER_SIZE;
|
---|
198 | if( (lpID = (CURSORICONDIR*)HeapAlloc(GetProcessHeap(),0, *uSize) ))
|
---|
199 | {
|
---|
200 | /* copy the header */
|
---|
201 | lpID->idReserved = lpiID->idReserved = 0;
|
---|
202 | lpID->idType = lpiID->idType = 1;
|
---|
203 | lpID->idCount = lpiID->idCount = lpcid.idCount;
|
---|
204 |
|
---|
205 | /* copy the entrys */
|
---|
206 | for( i=0; i < lpiID->idCount; i++ )
|
---|
207 | { memcpy((void*)&(lpID->idEntries[i]),(void*)&(lpiID->idEntries[i]), sizeof(CURSORICONDIRENTRY) - 2);
|
---|
208 | lpID->idEntries[i].wResId = i;
|
---|
209 | }
|
---|
210 |
|
---|
211 | *lplpiID = lpiID;
|
---|
212 | return (BYTE *)lpID;
|
---|
213 | }
|
---|
214 | }
|
---|
215 | /* fail */
|
---|
216 |
|
---|
217 | HeapFree( GetProcessHeap(), 0, lpiID);
|
---|
218 | return 0;
|
---|
219 | }
|
---|
220 |
|
---|
221 | #ifdef __WIN32OS2__
|
---|
222 |
|
---|
223 | /*************************************************************************/
|
---|
224 |
|
---|
225 | typedef struct
|
---|
226 | {
|
---|
227 | INT nStartIndex;
|
---|
228 | UINT nIcons;
|
---|
229 | UINT cx;
|
---|
230 | UINT cy;
|
---|
231 | UINT nCurrIndex;
|
---|
232 | HICON * phIcons;
|
---|
233 | UINT nRetrieved;
|
---|
234 |
|
---|
235 | } GETICONSPROCPARAM;
|
---|
236 |
|
---|
237 | static BOOL CALLBACK GetIconsProc( HANDLE hModule,
|
---|
238 | LPCTSTR lpszType,
|
---|
239 | LPTSTR lpszName,
|
---|
240 | LONG lParam )
|
---|
241 | {
|
---|
242 | GETICONSPROCPARAM* pIcons = (GETICONSPROCPARAM *)lParam;
|
---|
243 |
|
---|
244 | if ( ( pIcons->nStartIndex == -1 ) && !pIcons->phIcons && !pIcons->nIcons )
|
---|
245 | {
|
---|
246 | /* number of icons ( RT_GROUP_ICON resources ) requested. */
|
---|
247 | pIcons->nRetrieved++;
|
---|
248 | }
|
---|
249 | else if ( pIcons->nStartIndex < 0 )
|
---|
250 | {
|
---|
251 | /* begins by extracting the icon whose resource identifier
|
---|
252 | is equal to the absolute value of nStartIndex. */
|
---|
253 |
|
---|
254 | INT iResId = abs( pIcons->nStartIndex );
|
---|
255 | if ( lpszName < 0x10000 )
|
---|
256 | {
|
---|
257 | if ( (INT)lpszName == iResId )
|
---|
258 | {
|
---|
259 | /* Found icondir with resid iResId. */
|
---|
260 | /* This is the starting index. */
|
---|
261 | pIcons->nStartIndex = pIcons->nCurrIndex;
|
---|
262 | }
|
---|
263 | }
|
---|
264 | else
|
---|
265 | {
|
---|
266 | char buffer[ 8 ];
|
---|
267 | sprintf( buffer, "#%u", iResId );
|
---|
268 | if ( strcmp( lpszName, buffer ) == 0 )
|
---|
269 | {
|
---|
270 | /* Found icondir with resid iResId. */
|
---|
271 | /* This is the starting index. */
|
---|
272 | pIcons->nStartIndex = pIcons->nCurrIndex;
|
---|
273 | }
|
---|
274 | }
|
---|
275 | }
|
---|
276 |
|
---|
277 | if ( pIcons->nStartIndex >= 0 )
|
---|
278 | {
|
---|
279 | /* extract icons by index */
|
---|
280 |
|
---|
281 | if ( pIcons->nCurrIndex >= pIcons->nStartIndex )
|
---|
282 | {
|
---|
283 | HICON hIcon = LoadImageA( hModule,
|
---|
284 | lpszName,
|
---|
285 | IMAGE_ICON,
|
---|
286 | pIcons->cx,
|
---|
287 | pIcons->cy,
|
---|
288 | LR_DEFAULTCOLOR );
|
---|
289 | *pIcons->phIcons = hIcon;
|
---|
290 | if ( hIcon )
|
---|
291 | pIcons->nRetrieved++;
|
---|
292 |
|
---|
293 | pIcons->phIcons++;
|
---|
294 | }
|
---|
295 |
|
---|
296 | if ( pIcons->nCurrIndex
|
---|
297 | == ( pIcons->nStartIndex + pIcons->nIcons - 1 ) )
|
---|
298 | {
|
---|
299 | /* done, stop enumeration */
|
---|
300 | return FALSE;
|
---|
301 | }
|
---|
302 | }
|
---|
303 |
|
---|
304 | /* continue enumeration */
|
---|
305 | pIcons->nCurrIndex++;
|
---|
306 | return TRUE;
|
---|
307 | }
|
---|
308 |
|
---|
309 | /*************************************************************************
|
---|
310 | *
|
---|
311 | * returns
|
---|
312 | * failure: 0
|
---|
313 | * success: nr of icons in file, if nIconIndex is -1,
|
---|
314 | * nr of icons successfully extracted, otherwise.
|
---|
315 | */
|
---|
316 | UINT WINAPI ICO_ExtractIconEx( LPCSTR lpszExeFileName,
|
---|
317 | HICON * RetPtr,
|
---|
318 | INT nIconIndex,
|
---|
319 | UINT n,
|
---|
320 | UINT cxDesired,
|
---|
321 | UINT cyDesired )
|
---|
322 | {
|
---|
323 | UINT nIconCount = 0;
|
---|
324 | HINSTANCE hInst = 0;
|
---|
325 |
|
---|
326 | TRACE( "file=%s, index=%d, n=%u\n", lpszExeFileName, nIconIndex, n );
|
---|
327 |
|
---|
328 | #if 0
|
---|
329 | if ( stricmp( lpszExeFileName, "shell32.dll" ) == 0 )
|
---|
330 | {
|
---|
331 | /* Use original renamed dll, if present. It contains all icons. ;-) */
|
---|
332 | hInst = LoadLibraryExA( "shell32_pe.dll", 0, LOAD_LIBRARY_AS_DATAFILE );
|
---|
333 | }
|
---|
334 |
|
---|
335 | if ( !hInst )
|
---|
336 | #endif
|
---|
337 | hInst = LoadLibraryExA( lpszExeFileName, 0, LOAD_LIBRARY_AS_DATAFILE );
|
---|
338 |
|
---|
339 | if ( hInst )
|
---|
340 | {
|
---|
341 | GETICONSPROCPARAM icons = {
|
---|
342 | nIconIndex, n, cxDesired, cyDesired, 0, RetPtr, 0 };
|
---|
343 |
|
---|
344 | EnumResourceNamesA(
|
---|
345 | hInst, RT_GROUP_ICONA, &GetIconsProc, (LONG)&icons );
|
---|
346 |
|
---|
347 | nIconCount = icons.nRetrieved;
|
---|
348 |
|
---|
349 | FreeLibrary( hInst );
|
---|
350 | }
|
---|
351 | else
|
---|
352 | {
|
---|
353 | HFILE hFile;
|
---|
354 | OFSTRUCT ofs;
|
---|
355 | DWORD sig;
|
---|
356 | LPBYTE pData;
|
---|
357 | UINT16 iconDirCount = 0,iconCount = 0;
|
---|
358 | ULONG uSize;
|
---|
359 |
|
---|
360 | if( nIconIndex!=-1 && !n )
|
---|
361 | return 0;
|
---|
362 |
|
---|
363 | hFile = OpenFile( lpszExeFileName, &ofs, OF_READ );
|
---|
364 |
|
---|
365 | if( hFile == HFILE_ERROR )
|
---|
366 | return 0;
|
---|
367 |
|
---|
368 | sig = SHELL_GetResourceTable(hFile,&pData);
|
---|
369 |
|
---|
370 | if( sig==IMAGE_OS2_SIGNATURE || sig==1 ) /* .ICO file */
|
---|
371 | {
|
---|
372 | /* NE image ( OS/2 1.x / Win 3.x ) / ico file */
|
---|
373 |
|
---|
374 | BYTE *pCIDir = 0;
|
---|
375 | NE_TYPEINFO *pTInfo = (NE_TYPEINFO*)(pData + 2);
|
---|
376 | NE_NAMEINFO *pIconStorage = NULL;
|
---|
377 | NE_NAMEINFO *pIconDir = NULL;
|
---|
378 | LPicoICONDIR lpiID = NULL;
|
---|
379 |
|
---|
380 | TRACE("-- OS2/icon Signature (0x%08lx)\n", sig);
|
---|
381 |
|
---|
382 | if( pData == (BYTE*)-1 )
|
---|
383 | {
|
---|
384 | pCIDir = ICO_GetIconDirectory(hFile, &lpiID, &uSize); /* check for .ICO file */
|
---|
385 | if( pCIDir )
|
---|
386 | {
|
---|
387 | iconDirCount = 1; iconCount = lpiID->idCount;
|
---|
388 | TRACE("-- icon found %p 0x%08lx 0x%08x 0x%08x\n", pCIDir, uSize, iconDirCount, iconCount);
|
---|
389 | }
|
---|
390 | }
|
---|
391 | else while( pTInfo->type_id && !(pIconStorage && pIconDir) )
|
---|
392 | {
|
---|
393 | if( pTInfo->type_id == NE_RSCTYPE_GROUP_ICON ) /* find icon directory and icon repository */
|
---|
394 | {
|
---|
395 | iconDirCount = pTInfo->count;
|
---|
396 | pIconDir = ((NE_NAMEINFO*)(pTInfo + 1));
|
---|
397 | TRACE("\tfound directory - %i icon families\n", iconDirCount);
|
---|
398 | }
|
---|
399 | if( pTInfo->type_id == NE_RSCTYPE_ICON )
|
---|
400 | {
|
---|
401 | iconCount = pTInfo->count;
|
---|
402 | pIconStorage = ((NE_NAMEINFO*)(pTInfo + 1));
|
---|
403 | TRACE("\ttotal icons - %i\n", iconCount);
|
---|
404 | }
|
---|
405 | pTInfo = (NE_TYPEINFO *)((char*)(pTInfo+1)+pTInfo->count*sizeof(NE_NAMEINFO));
|
---|
406 | }
|
---|
407 |
|
---|
408 | if( (pIconStorage && pIconDir) || lpiID ) /* load resources and create icons */
|
---|
409 | {
|
---|
410 | if( nIconIndex == (UINT16)-1 )
|
---|
411 | {
|
---|
412 | /* icon count requested */
|
---|
413 | nIconCount = iconDirCount;
|
---|
414 | }
|
---|
415 | else if( nIconIndex < iconDirCount )
|
---|
416 | {
|
---|
417 | UINT16 i, icon;
|
---|
418 | if( n > iconDirCount - nIconIndex )
|
---|
419 | n = iconDirCount - nIconIndex;
|
---|
420 |
|
---|
421 | for( i = nIconIndex; i < nIconIndex + n; i++ )
|
---|
422 | {
|
---|
423 | /* .ICO files have only one icon directory */
|
---|
424 |
|
---|
425 | if( lpiID == NULL ) /* *.ico */
|
---|
426 | pCIDir = SHELL_LoadResource( hFile, pIconDir + i, *(WORD*)pData, &uSize );
|
---|
427 |
|
---|
428 | RetPtr[i-nIconIndex] = pLookupIconIdFromDirectoryEx( pCIDir, TRUE, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON), 0);
|
---|
429 |
|
---|
430 | if ( RetPtr[i-nIconIndex] )
|
---|
431 | nIconCount++;
|
---|
432 |
|
---|
433 | HeapFree(GetProcessHeap(), 0, pCIDir);
|
---|
434 | }
|
---|
435 |
|
---|
436 | for( icon = nIconIndex; icon < nIconIndex + n; icon++ )
|
---|
437 | {
|
---|
438 | pCIDir = NULL;
|
---|
439 | if( lpiID )
|
---|
440 | pCIDir = ICO_LoadIcon( hFile, lpiID->idEntries + RetPtr[icon-nIconIndex], &uSize);
|
---|
441 | else
|
---|
442 | {
|
---|
443 | for( i = 0; i < iconCount; i++ )
|
---|
444 | {
|
---|
445 | if( pIconStorage[i].id == (RetPtr[icon-nIconIndex] | 0x8000) )
|
---|
446 | pCIDir = SHELL_LoadResource( hFile, pIconStorage + i,*(WORD*)pData, &uSize );
|
---|
447 | }
|
---|
448 | }
|
---|
449 | if( pCIDir )
|
---|
450 | {
|
---|
451 | RetPtr[icon-nIconIndex] = (HICON) pCreateIconFromResourceEx(pCIDir,uSize,TRUE,0x00030000, cxDesired, cyDesired, LR_DEFAULTCOLOR);
|
---|
452 | if ( RetPtr[icon-nIconIndex] )
|
---|
453 | nIconCount++;
|
---|
454 | }
|
---|
455 | else
|
---|
456 | RetPtr[icon-nIconIndex] = 0;
|
---|
457 | }
|
---|
458 | }
|
---|
459 | }
|
---|
460 | if( lpiID )
|
---|
461 | HeapFree( GetProcessHeap(), 0, lpiID);
|
---|
462 | else
|
---|
463 | HeapFree( GetProcessHeap(), 0, pData);
|
---|
464 | }
|
---|
465 | _lclose( hFile);
|
---|
466 | }
|
---|
467 | return nIconCount;
|
---|
468 | }
|
---|
469 |
|
---|
470 | #else /* ! __WIN32OS2__ */
|
---|
471 |
|
---|
472 | /*************************************************************************
|
---|
473 | *
|
---|
474 | * returns
|
---|
475 | * failure:0; success: icon handle or nr of icons (nIconIndex-1)
|
---|
476 | */
|
---|
477 | HICON WINAPI ICO_ExtractIconEx(LPCSTR lpszExeFileName, HICON * RetPtr, INT nIconIndex, UINT n, UINT cxDesired, UINT cyDesired )
|
---|
478 | { HGLOBAL hRet = 0;
|
---|
479 | LPBYTE pData;
|
---|
480 | OFSTRUCT ofs;
|
---|
481 | DWORD sig;
|
---|
482 | HFILE hFile = OpenFile( lpszExeFileName, &ofs, OF_READ );
|
---|
483 | UINT16 iconDirCount = 0,iconCount = 0;
|
---|
484 | LPBYTE peimage;
|
---|
485 | HANDLE fmapping;
|
---|
486 | ULONG uSize;
|
---|
487 |
|
---|
488 | TRACE("(file %s,start %d,extract %d\n", lpszExeFileName, nIconIndex, n);
|
---|
489 |
|
---|
490 | if( hFile == HFILE_ERROR || (nIconIndex!=-1 && !n) )
|
---|
491 | return hRet;
|
---|
492 |
|
---|
493 | sig = SHELL_GetResourceTable(hFile,&pData);
|
---|
494 |
|
---|
495 | /* ico file */
|
---|
496 | if( sig==IMAGE_OS2_SIGNATURE || sig==1 ) /* .ICO file */
|
---|
497 | { BYTE *pCIDir = 0;
|
---|
498 | NE_TYPEINFO *pTInfo = (NE_TYPEINFO*)(pData + 2);
|
---|
499 | NE_NAMEINFO *pIconStorage = NULL;
|
---|
500 | NE_NAMEINFO *pIconDir = NULL;
|
---|
501 | LPicoICONDIR lpiID = NULL;
|
---|
502 |
|
---|
503 | TRACE("-- OS2/icon Signature (0x%08lx)\n", sig);
|
---|
504 |
|
---|
505 | if( pData == (BYTE*)-1 )
|
---|
506 | { pCIDir = ICO_GetIconDirectory(hFile, &lpiID, &uSize); /* check for .ICO file */
|
---|
507 | if( pCIDir )
|
---|
508 | { iconDirCount = 1; iconCount = lpiID->idCount;
|
---|
509 | TRACE("-- icon found %p 0x%08lx 0x%08x 0x%08x\n", pCIDir, uSize, iconDirCount, iconCount);
|
---|
510 | }
|
---|
511 | }
|
---|
512 | else while( pTInfo->type_id && !(pIconStorage && pIconDir) )
|
---|
513 | { if( pTInfo->type_id == NE_RSCTYPE_GROUP_ICON ) /* find icon directory and icon repository */
|
---|
514 | { iconDirCount = pTInfo->count;
|
---|
515 | pIconDir = ((NE_NAMEINFO*)(pTInfo + 1));
|
---|
516 | TRACE("\tfound directory - %i icon families\n", iconDirCount);
|
---|
517 | }
|
---|
518 | if( pTInfo->type_id == NE_RSCTYPE_ICON )
|
---|
519 | { iconCount = pTInfo->count;
|
---|
520 | pIconStorage = ((NE_NAMEINFO*)(pTInfo + 1));
|
---|
521 | TRACE("\ttotal icons - %i\n", iconCount);
|
---|
522 | }
|
---|
523 | pTInfo = (NE_TYPEINFO *)((char*)(pTInfo+1)+pTInfo->count*sizeof(NE_NAMEINFO));
|
---|
524 | }
|
---|
525 |
|
---|
526 | if( (pIconStorage && pIconDir) || lpiID ) /* load resources and create icons */
|
---|
527 | { if( nIconIndex == (UINT16)-1 )
|
---|
528 | { RetPtr[0] = iconDirCount;
|
---|
529 | }
|
---|
530 | else if( nIconIndex < iconDirCount )
|
---|
531 | { UINT16 i, icon;
|
---|
532 | if( n > iconDirCount - nIconIndex )
|
---|
533 | n = iconDirCount - nIconIndex;
|
---|
534 |
|
---|
535 | for( i = nIconIndex; i < nIconIndex + n; i++ )
|
---|
536 | { /* .ICO files have only one icon directory */
|
---|
537 |
|
---|
538 | if( lpiID == NULL ) /* *.ico */
|
---|
539 | pCIDir = SHELL_LoadResource( hFile, pIconDir + i, *(WORD*)pData, &uSize );
|
---|
540 | RetPtr[i-nIconIndex] = pLookupIconIdFromDirectoryEx( pCIDir, TRUE, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON), 0);
|
---|
541 | HeapFree(GetProcessHeap(), 0, pCIDir);
|
---|
542 | }
|
---|
543 |
|
---|
544 | for( icon = nIconIndex; icon < nIconIndex + n; icon++ )
|
---|
545 | { pCIDir = NULL;
|
---|
546 | if( lpiID )
|
---|
547 | { pCIDir = ICO_LoadIcon( hFile, lpiID->idEntries + RetPtr[icon-nIconIndex], &uSize);
|
---|
548 | }
|
---|
549 | else
|
---|
550 | { for( i = 0; i < iconCount; i++ )
|
---|
551 | { if( pIconStorage[i].id == (RetPtr[icon-nIconIndex] | 0x8000) )
|
---|
552 | { pCIDir = SHELL_LoadResource( hFile, pIconStorage + i,*(WORD*)pData, &uSize );
|
---|
553 | }
|
---|
554 | }
|
---|
555 | }
|
---|
556 | if( pCIDir )
|
---|
557 | { RetPtr[icon-nIconIndex] = (HICON) pCreateIconFromResourceEx(pCIDir,uSize,TRUE,0x00030000, cxDesired, cyDesired, LR_DEFAULTCOLOR);
|
---|
558 | }
|
---|
559 | else
|
---|
560 | { RetPtr[icon-nIconIndex] = 0;
|
---|
561 | }
|
---|
562 | }
|
---|
563 | }
|
---|
564 | }
|
---|
565 | if( lpiID )
|
---|
566 | HeapFree( GetProcessHeap(), 0, lpiID);
|
---|
567 | else
|
---|
568 | HeapFree( GetProcessHeap(), 0, pData);
|
---|
569 | }
|
---|
570 | /* end ico file */
|
---|
571 |
|
---|
572 | /* exe/dll */
|
---|
573 | if( sig == IMAGE_NT_SIGNATURE)
|
---|
574 | { LPBYTE idata,igdata;
|
---|
575 | PIMAGE_DOS_HEADER dheader;
|
---|
576 | PIMAGE_NT_HEADERS pe_header;
|
---|
577 | PIMAGE_SECTION_HEADER pe_sections;
|
---|
578 | PIMAGE_RESOURCE_DIRECTORY rootresdir,iconresdir,icongroupresdir;
|
---|
579 | PIMAGE_RESOURCE_DATA_ENTRY idataent,igdataent;
|
---|
580 | PIMAGE_RESOURCE_DIRECTORY_ENTRY xresent;
|
---|
581 | int i,j;
|
---|
582 |
|
---|
583 | if ( !(fmapping = CreateFileMappingA(hFile,NULL,PAGE_READONLY|SEC_COMMIT,0,0,NULL)))
|
---|
584 | { WARN("failed to create filemap.\n"); /* FIXME, INVALID_HANDLE_VALUE? */
|
---|
585 | goto end_2; /* failure */
|
---|
586 | }
|
---|
587 |
|
---|
588 | if ( !(peimage = MapViewOfFile(fmapping,FILE_MAP_READ,0,0,0)))
|
---|
589 | { WARN("failed to mmap filemap.\n");
|
---|
590 | goto end_2; /* failure */
|
---|
591 | }
|
---|
592 |
|
---|
593 | dheader = (PIMAGE_DOS_HEADER)peimage;
|
---|
594 | pe_header = (PIMAGE_NT_HEADERS)(peimage+dheader->e_lfanew); /* it is a pe header, SHELL_GetResourceTable checked that */
|
---|
595 | pe_sections = (PIMAGE_SECTION_HEADER)(((char*)pe_header)+sizeof(*pe_header)); /* probably makes problems with short PE headers...*/
|
---|
596 | rootresdir = NULL;
|
---|
597 |
|
---|
598 | for (i=0;i<pe_header->FileHeader.NumberOfSections;i++)
|
---|
599 | { if (pe_sections[i].Characteristics & IMAGE_SCN_CNT_UNINITIALIZED_DATA)
|
---|
600 | continue;
|
---|
601 | /* FIXME: doesn't work when the resources are not in a seperate section */
|
---|
602 | if (pe_sections[i].VirtualAddress == pe_header->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_RESOURCE].VirtualAddress)
|
---|
603 | { rootresdir = (PIMAGE_RESOURCE_DIRECTORY)((char*)peimage+pe_sections[i].PointerToRawData);
|
---|
604 | break;
|
---|
605 | }
|
---|
606 | }
|
---|
607 |
|
---|
608 | if (!rootresdir)
|
---|
609 | { WARN("haven't found section for resource directory.\n");
|
---|
610 | goto end_3; /* failure */
|
---|
611 | }
|
---|
612 | /* search the group icon dir*/
|
---|
613 | if (!(icongroupresdir = GetResDirEntryW(rootresdir,RT_GROUP_ICONW, (DWORD)rootresdir,FALSE)))
|
---|
614 | { WARN("No Icongroupresourcedirectory!\n");
|
---|
615 | goto end_3; /* failure */
|
---|
616 | }
|
---|
617 | iconDirCount = icongroupresdir->NumberOfNamedEntries+icongroupresdir->NumberOfIdEntries;
|
---|
618 |
|
---|
619 | /* number of icons requested */
|
---|
620 | if( nIconIndex == -1 )
|
---|
621 | { hRet = iconDirCount;
|
---|
622 | goto end_3; /* success */
|
---|
623 | }
|
---|
624 |
|
---|
625 | /* (nIconIndex < 0): extract the icon by resource id */
|
---|
626 | if( nIconIndex < 0 )
|
---|
627 | {
|
---|
628 | int n = 0;
|
---|
629 | int iId = abs(nIconIndex);
|
---|
630 | PIMAGE_RESOURCE_DIRECTORY_ENTRY xprdeTmp = (PIMAGE_RESOURCE_DIRECTORY_ENTRY)(icongroupresdir+1);
|
---|
631 |
|
---|
632 | while(n<iconDirCount && xprdeTmp)
|
---|
633 | {
|
---|
634 | if(xprdeTmp->u1.Id == iId)
|
---|
635 | {
|
---|
636 | nIconIndex = n;
|
---|
637 | break;
|
---|
638 | }
|
---|
639 | n++;
|
---|
640 | xprdeTmp++;
|
---|
641 | }
|
---|
642 | if (nIconIndex < 0)
|
---|
643 | {
|
---|
644 | WARN("resource id %d not found\n", iId);
|
---|
645 | goto end_3; /* failure */
|
---|
646 | }
|
---|
647 | }
|
---|
648 |
|
---|
649 | /* check nIconIndex to be in range */
|
---|
650 | if (nIconIndex >= iconDirCount)
|
---|
651 | {
|
---|
652 | WARN("nIconIndex %d is larger than iconDirCount %d\n",nIconIndex,iconDirCount);
|
---|
653 | goto end_3; /* failure */
|
---|
654 | }
|
---|
655 |
|
---|
656 | xresent = (PIMAGE_RESOURCE_DIRECTORY_ENTRY)(icongroupresdir+1); /* caller just wanted the number of entries */
|
---|
657 |
|
---|
658 | if( n > iconDirCount - nIconIndex ) /* assure we don't get too much ... */
|
---|
659 | { n = iconDirCount - nIconIndex;
|
---|
660 | }
|
---|
661 |
|
---|
662 | xresent = xresent+nIconIndex; /* starting from specified index ... */
|
---|
663 |
|
---|
664 | for (i=0;i<n;i++,xresent++)
|
---|
665 | { PIMAGE_RESOURCE_DIRECTORY resdir;
|
---|
666 |
|
---|
667 | /* go down this resource entry, name */
|
---|
668 | resdir = (PIMAGE_RESOURCE_DIRECTORY)((DWORD)rootresdir+(xresent->u2.s.OffsetToDirectory));
|
---|
669 |
|
---|
670 | /* default language (0) */
|
---|
671 | resdir = GetResDirEntryW(resdir,(LPWSTR)0,(DWORD)rootresdir,TRUE);
|
---|
672 | igdataent = (PIMAGE_RESOURCE_DATA_ENTRY)resdir;
|
---|
673 |
|
---|
674 | /* lookup address in mapped image for virtual address */
|
---|
675 | igdata = NULL;
|
---|
676 |
|
---|
677 | for (j=0;j<pe_header->FileHeader.NumberOfSections;j++)
|
---|
678 | { if (igdataent->OffsetToData < pe_sections[j].VirtualAddress)
|
---|
679 | continue;
|
---|
680 | if (igdataent->OffsetToData+igdataent->Size > pe_sections[j].VirtualAddress+pe_sections[j].SizeOfRawData)
|
---|
681 | continue;
|
---|
682 | igdata = peimage+(igdataent->OffsetToData-pe_sections[j].VirtualAddress+pe_sections[j].PointerToRawData);
|
---|
683 | }
|
---|
684 |
|
---|
685 | if (!igdata)
|
---|
686 | { WARN("no matching real address for icongroup!\n");
|
---|
687 | goto end_3; /* failure */
|
---|
688 | }
|
---|
689 | RetPtr[i] = (HICON)pLookupIconIdFromDirectoryEx(igdata, TRUE, cxDesired, cyDesired, LR_DEFAULTCOLOR);
|
---|
690 | }
|
---|
691 |
|
---|
692 | if (!(iconresdir=GetResDirEntryW(rootresdir,RT_ICONW,(DWORD)rootresdir,FALSE)))
|
---|
693 | { WARN("No Iconresourcedirectory!\n");
|
---|
694 | goto end_3; /* failure */
|
---|
695 | }
|
---|
696 |
|
---|
697 | for (i=0;i<n;i++)
|
---|
698 | { PIMAGE_RESOURCE_DIRECTORY xresdir;
|
---|
699 | xresdir = GetResDirEntryW(iconresdir,(LPWSTR)(DWORD)RetPtr[i],(DWORD)rootresdir,FALSE);
|
---|
700 | xresdir = GetResDirEntryW(xresdir,(LPWSTR)0,(DWORD)rootresdir,TRUE);
|
---|
701 | idataent = (PIMAGE_RESOURCE_DATA_ENTRY)xresdir;
|
---|
702 | idata = NULL;
|
---|
703 |
|
---|
704 | /* map virtual to address in image */
|
---|
705 | for (j=0;j<pe_header->FileHeader.NumberOfSections;j++)
|
---|
706 | { if (idataent->OffsetToData < pe_sections[j].VirtualAddress)
|
---|
707 | continue;
|
---|
708 | if (idataent->OffsetToData+idataent->Size > pe_sections[j].VirtualAddress+pe_sections[j].SizeOfRawData)
|
---|
709 | continue;
|
---|
710 | idata = peimage+(idataent->OffsetToData-pe_sections[j].VirtualAddress+pe_sections[j].PointerToRawData);
|
---|
711 | }
|
---|
712 | if (!idata)
|
---|
713 | { WARN("no matching real address found for icondata!\n");
|
---|
714 | RetPtr[i]=0;
|
---|
715 | continue;
|
---|
716 | }
|
---|
717 | RetPtr[i] = (HICON) pCreateIconFromResourceEx(idata,idataent->Size,TRUE,0x00030000, cxDesired, cyDesired, LR_DEFAULTCOLOR);
|
---|
718 | }
|
---|
719 | hRet = RetPtr[0]; /* return first icon */
|
---|
720 | goto end_3; /* sucess */
|
---|
721 | }
|
---|
722 | goto end_1; /* unknown filetype */
|
---|
723 |
|
---|
724 | /* cleaning up (try & catch would be nicer:-) ) */
|
---|
725 | end_3: UnmapViewOfFile(peimage); /* success */
|
---|
726 | end_2: CloseHandle(fmapping);
|
---|
727 | end_1: _lclose( hFile);
|
---|
728 | return hRet;
|
---|
729 | }
|
---|
730 |
|
---|
731 | #endif /* ! __WIN32OS2__ */
|
---|
732 |
|
---|
733 | /********************** THE ICON CACHE ********************************/
|
---|
734 |
|
---|
735 | #define INVALID_INDEX -1
|
---|
736 |
|
---|
737 | typedef struct
|
---|
738 | { LPCSTR sSourceFile; /* file (not path!) containing the icon */
|
---|
739 | DWORD dwSourceIndex; /* index within the file, if it is a resoure ID it will be negated */
|
---|
740 | DWORD dwListIndex; /* index within the iconlist */
|
---|
741 | DWORD dwFlags; /* GIL_* flags */
|
---|
742 | DWORD dwAccessTime;
|
---|
743 | } SIC_ENTRY, * LPSIC_ENTRY;
|
---|
744 |
|
---|
745 | static HDPA sic_hdpa = 0;
|
---|
746 | static CRITICAL_SECTION SHELL32_SicCS = CRITICAL_SECTION_INIT;
|
---|
747 |
|
---|
748 | /*****************************************************************************
|
---|
749 | * SIC_CompareEntrys [called by comctl32.dll]
|
---|
750 | *
|
---|
751 | * NOTES
|
---|
752 | * Callback for DPA_Search
|
---|
753 | */
|
---|
754 | INT CALLBACK SIC_CompareEntrys( LPVOID p1, LPVOID p2, LPARAM lparam)
|
---|
755 | { TRACE("%p %p\n", p1, p2);
|
---|
756 |
|
---|
757 | if (((LPSIC_ENTRY)p1)->dwSourceIndex != ((LPSIC_ENTRY)p2)->dwSourceIndex) /* first the faster one*/
|
---|
758 | return 1;
|
---|
759 |
|
---|
760 | if (strcasecmp(((LPSIC_ENTRY)p1)->sSourceFile,((LPSIC_ENTRY)p2)->sSourceFile))
|
---|
761 | return 1;
|
---|
762 |
|
---|
763 | return 0;
|
---|
764 | }
|
---|
765 | /*****************************************************************************
|
---|
766 | * SIC_IconAppend [internal]
|
---|
767 | *
|
---|
768 | * NOTES
|
---|
769 | * appends a icon pair to the end of the cache
|
---|
770 | */
|
---|
771 | static INT SIC_IconAppend (LPCSTR sSourceFile, INT dwSourceIndex, HICON hSmallIcon, HICON hBigIcon)
|
---|
772 | { LPSIC_ENTRY lpsice;
|
---|
773 | INT ret, index, index1;
|
---|
774 |
|
---|
775 | TRACE("%s %i %x %x\n", sSourceFile, dwSourceIndex, hSmallIcon ,hBigIcon);
|
---|
776 |
|
---|
777 | lpsice = (LPSIC_ENTRY) SHAlloc (sizeof (SIC_ENTRY));
|
---|
778 |
|
---|
779 | lpsice->sSourceFile = HEAP_strdupA (GetProcessHeap(), 0, PathFindFileNameA(sSourceFile));
|
---|
780 | lpsice->dwSourceIndex = dwSourceIndex;
|
---|
781 |
|
---|
782 | EnterCriticalSection(&SHELL32_SicCS);
|
---|
783 |
|
---|
784 | index = pDPA_InsertPtr(sic_hdpa, 0x7fff, lpsice);
|
---|
785 | if ( INVALID_INDEX == index )
|
---|
786 | {
|
---|
787 | #ifdef __WIN32OS2__
|
---|
788 | // 2001-06-01 PH memory leak in WINE
|
---|
789 | HeapFree(GetProcessHeap(),0,lpsice->sSourceFile);
|
---|
790 | #endif
|
---|
791 | SHFree(lpsice);
|
---|
792 | ret = INVALID_INDEX;
|
---|
793 | }
|
---|
794 | else
|
---|
795 | {
|
---|
796 | index = ImageList_AddIcon (ShellSmallIconList, hSmallIcon);
|
---|
797 | index1= ImageList_AddIcon (ShellBigIconList, hBigIcon);
|
---|
798 |
|
---|
799 | if (index!=index1)
|
---|
800 | {
|
---|
801 | FIXME("iconlists out of sync 0x%x 0x%x\n", index, index1);
|
---|
802 | }
|
---|
803 | lpsice->dwListIndex = index;
|
---|
804 | ret = lpsice->dwListIndex;
|
---|
805 | }
|
---|
806 |
|
---|
807 | LeaveCriticalSection(&SHELL32_SicCS);
|
---|
808 | return ret;
|
---|
809 | }
|
---|
810 | /****************************************************************************
|
---|
811 | * SIC_LoadIcon [internal]
|
---|
812 | *
|
---|
813 | * NOTES
|
---|
814 | * gets small/big icon by number from a file
|
---|
815 | */
|
---|
816 | static INT SIC_LoadIcon (LPCSTR sSourceFile, INT dwSourceIndex)
|
---|
817 | { HICON hiconLarge=0;
|
---|
818 | HICON hiconSmall=0;
|
---|
819 |
|
---|
820 | ICO_ExtractIconEx(sSourceFile, &hiconLarge, dwSourceIndex, 1, 32, 32 );
|
---|
821 | ICO_ExtractIconEx(sSourceFile, &hiconSmall, dwSourceIndex, 1, 16, 16 );
|
---|
822 |
|
---|
823 |
|
---|
824 | if ( !hiconLarge || !hiconSmall)
|
---|
825 | {
|
---|
826 | WARN("failure loading icon %i from %s (%x %x)\n", dwSourceIndex, sSourceFile, hiconLarge, hiconSmall);
|
---|
827 | return -1;
|
---|
828 | }
|
---|
829 | return SIC_IconAppend (sSourceFile, dwSourceIndex, hiconSmall, hiconLarge);
|
---|
830 | }
|
---|
831 | /*****************************************************************************
|
---|
832 | * SIC_GetIconIndex [internal]
|
---|
833 | *
|
---|
834 | * Parameters
|
---|
835 | * sSourceFile [IN] filename of file containing the icon
|
---|
836 | * index [IN] index/resID (negated) in this file
|
---|
837 | *
|
---|
838 | * NOTES
|
---|
839 | * look in the cache for a proper icon. if not available the icon is taken
|
---|
840 | * from the file and cached
|
---|
841 | */
|
---|
842 | INT SIC_GetIconIndex (LPCSTR sSourceFile, INT dwSourceIndex )
|
---|
843 | { SIC_ENTRY sice;
|
---|
844 | INT ret, index = INVALID_INDEX;
|
---|
845 |
|
---|
846 | TRACE("%s %i\n", sSourceFile, dwSourceIndex);
|
---|
847 |
|
---|
848 | sice.sSourceFile = PathFindFileNameA(sSourceFile);
|
---|
849 | sice.dwSourceIndex = dwSourceIndex;
|
---|
850 |
|
---|
851 | EnterCriticalSection(&SHELL32_SicCS);
|
---|
852 |
|
---|
853 | if (NULL != pDPA_GetPtr (sic_hdpa, 0))
|
---|
854 | {
|
---|
855 | index = pDPA_Search (sic_hdpa, &sice, -1L, SIC_CompareEntrys, 0, 0);
|
---|
856 | }
|
---|
857 |
|
---|
858 | if ( INVALID_INDEX == index )
|
---|
859 | {
|
---|
860 | ret = SIC_LoadIcon (sSourceFile, dwSourceIndex);
|
---|
861 | }
|
---|
862 | else
|
---|
863 | {
|
---|
864 | TRACE("-- found\n");
|
---|
865 | ret = ((LPSIC_ENTRY)pDPA_GetPtr(sic_hdpa, index))->dwListIndex;
|
---|
866 | }
|
---|
867 |
|
---|
868 | LeaveCriticalSection(&SHELL32_SicCS);
|
---|
869 | return ret;
|
---|
870 | }
|
---|
871 | /****************************************************************************
|
---|
872 | * SIC_LoadIcon [internal]
|
---|
873 | *
|
---|
874 | * NOTES
|
---|
875 | * retrives the specified icon from the iconcache. if not found try's to load the icon
|
---|
876 | */
|
---|
877 | static HICON WINE_UNUSED SIC_GetIcon (LPCSTR sSourceFile, INT dwSourceIndex, BOOL bSmallIcon )
|
---|
878 | { INT index;
|
---|
879 |
|
---|
880 | TRACE("%s %i\n", sSourceFile, dwSourceIndex);
|
---|
881 |
|
---|
882 | index = SIC_GetIconIndex(sSourceFile, dwSourceIndex);
|
---|
883 |
|
---|
884 | if (INVALID_INDEX == index)
|
---|
885 | {
|
---|
886 | return INVALID_INDEX;
|
---|
887 | }
|
---|
888 |
|
---|
889 | if (bSmallIcon)
|
---|
890 | return ImageList_GetIcon(ShellSmallIconList, index, ILD_NORMAL);
|
---|
891 | return ImageList_GetIcon(ShellBigIconList, index, ILD_NORMAL);
|
---|
892 |
|
---|
893 | }
|
---|
894 | /*****************************************************************************
|
---|
895 | * SIC_Initialize [internal]
|
---|
896 | *
|
---|
897 | * NOTES
|
---|
898 | * hack to load the resources from the shell32.dll under a different dll name
|
---|
899 | * will be removed when the resource-compiler is ready
|
---|
900 | */
|
---|
901 | BOOL SIC_Initialize(void)
|
---|
902 | {
|
---|
903 | HICON hSm, hLg;
|
---|
904 | UINT index;
|
---|
905 |
|
---|
906 | TRACE("\n");
|
---|
907 |
|
---|
908 | if (sic_hdpa) /* already initialized?*/
|
---|
909 | return TRUE;
|
---|
910 |
|
---|
911 | sic_hdpa = pDPA_Create(16);
|
---|
912 |
|
---|
913 | if (!sic_hdpa)
|
---|
914 | {
|
---|
915 | return(FALSE);
|
---|
916 | }
|
---|
917 |
|
---|
918 | ShellSmallIconList = ImageList_Create(16,16,ILC_COLORDDB | ILC_MASK,0,0x20);
|
---|
919 | ShellBigIconList = ImageList_Create(32,32,ILC_COLORDDB | ILC_MASK,0,0x20);
|
---|
920 |
|
---|
921 | ImageList_SetBkColor(ShellSmallIconList, GetSysColor(COLOR_WINDOW));
|
---|
922 | ImageList_SetBkColor(ShellBigIconList, GetSysColor(COLOR_WINDOW));
|
---|
923 |
|
---|
924 | #ifndef __WIN32OS2__
|
---|
925 | /* 2001-06-01 PH pre-initializing the list takes
|
---|
926 | * a long time. On-demand loading of the icons should
|
---|
927 | * be sufficient! (7 secs on P133)
|
---|
928 | */
|
---|
929 | for (index=1; index<46; index++)
|
---|
930 | {
|
---|
931 | hSm = LoadImageA(shell32_hInstance, MAKEINTRESOURCEA(index), IMAGE_ICON, 16, 16,LR_SHARED);
|
---|
932 | hLg = LoadImageA(shell32_hInstance, MAKEINTRESOURCEA(index), IMAGE_ICON, 32, 32,LR_SHARED);
|
---|
933 |
|
---|
934 | if(!hSm)
|
---|
935 | {
|
---|
936 | hSm = LoadImageA(shell32_hInstance, MAKEINTRESOURCEA(0), IMAGE_ICON, 16, 16,LR_SHARED);
|
---|
937 | hLg = LoadImageA(shell32_hInstance, MAKEINTRESOURCEA(0), IMAGE_ICON, 32, 32,LR_SHARED);
|
---|
938 | }
|
---|
939 | SIC_IconAppend ("shell32.dll", index, hSm, hLg);
|
---|
940 | }
|
---|
941 | #endif
|
---|
942 |
|
---|
943 | TRACE("hIconSmall=%p hIconBig=%p\n",ShellSmallIconList, ShellBigIconList);
|
---|
944 |
|
---|
945 | return TRUE;
|
---|
946 | }
|
---|
947 | /*************************************************************************
|
---|
948 | * SIC_Destroy
|
---|
949 | *
|
---|
950 | * frees the cache
|
---|
951 | */
|
---|
952 | void SIC_Destroy(void)
|
---|
953 | {
|
---|
954 | LPSIC_ENTRY lpsice;
|
---|
955 | int i;
|
---|
956 |
|
---|
957 | TRACE("\n");
|
---|
958 |
|
---|
959 | EnterCriticalSection(&SHELL32_SicCS);
|
---|
960 |
|
---|
961 | if (sic_hdpa && NULL != pDPA_GetPtr (sic_hdpa, 0))
|
---|
962 | {
|
---|
963 | for (i=0; i < pDPA_GetPtrCount(sic_hdpa); ++i)
|
---|
964 | {
|
---|
965 | lpsice = pDPA_GetPtr(sic_hdpa, i);
|
---|
966 | SHFree(lpsice);
|
---|
967 | }
|
---|
968 | pDPA_Destroy(sic_hdpa);
|
---|
969 | }
|
---|
970 |
|
---|
971 | sic_hdpa = NULL;
|
---|
972 |
|
---|
973 | LeaveCriticalSection(&SHELL32_SicCS);
|
---|
974 | DeleteCriticalSection(&SHELL32_SicCS);
|
---|
975 | }
|
---|
976 | /*************************************************************************
|
---|
977 | * Shell_GetImageList [SHELL32.71]
|
---|
978 | *
|
---|
979 | * PARAMETERS
|
---|
980 | * imglist[1|2] [OUT] pointer which recive imagelist handles
|
---|
981 | *
|
---|
982 | */
|
---|
983 | BOOL WINAPI Shell_GetImageList(HIMAGELIST * lpBigList, HIMAGELIST * lpSmallList)
|
---|
984 | { TRACE("(%p,%p)\n",lpBigList,lpSmallList);
|
---|
985 | if (lpBigList)
|
---|
986 | { *lpBigList = ShellBigIconList;
|
---|
987 | }
|
---|
988 | if (lpSmallList)
|
---|
989 | { *lpSmallList = ShellSmallIconList;
|
---|
990 | }
|
---|
991 |
|
---|
992 | return TRUE;
|
---|
993 | }
|
---|
994 | /*************************************************************************
|
---|
995 | * PidlToSicIndex [INTERNAL]
|
---|
996 | *
|
---|
997 | * PARAMETERS
|
---|
998 | * sh [IN] IShellFolder
|
---|
999 | * pidl [IN]
|
---|
1000 | * bBigIcon [IN]
|
---|
1001 | * uFlags [IN] GIL_*
|
---|
1002 | * pIndex [OUT] index within the SIC
|
---|
1003 | *
|
---|
1004 | */
|
---|
1005 | BOOL PidlToSicIndex (
|
---|
1006 | IShellFolder * sh,
|
---|
1007 | LPITEMIDLIST pidl,
|
---|
1008 | BOOL bBigIcon,
|
---|
1009 | UINT uFlags,
|
---|
1010 | UINT * pIndex)
|
---|
1011 | {
|
---|
1012 | IExtractIconA *ei;
|
---|
1013 | char szIconFile[MAX_PATH]; /* file containing the icon */
|
---|
1014 | INT iSourceIndex; /* index or resID(negated) in this file */
|
---|
1015 | BOOL ret = FALSE;
|
---|
1016 | UINT dwFlags = 0;
|
---|
1017 |
|
---|
1018 | TRACE("sf=%p pidl=%p %s\n", sh, pidl, bBigIcon?"Big":"Small");
|
---|
1019 |
|
---|
1020 | if (SUCCEEDED (IShellFolder_GetUIObjectOf(sh, 0, 1, &pidl, &IID_IExtractIconA, 0, (void **)&ei)))
|
---|
1021 | {
|
---|
1022 | if (SUCCEEDED(IExtractIconA_GetIconLocation(ei, uFlags, szIconFile, MAX_PATH, &iSourceIndex, &dwFlags)))
|
---|
1023 | {
|
---|
1024 | *pIndex = SIC_GetIconIndex(szIconFile, iSourceIndex);
|
---|
1025 | ret = TRUE;
|
---|
1026 | }
|
---|
1027 | IExtractIconA_Release(ei);
|
---|
1028 | }
|
---|
1029 |
|
---|
1030 | if (INVALID_INDEX == *pIndex) /* default icon when failed */
|
---|
1031 | *pIndex = 1;
|
---|
1032 |
|
---|
1033 | return ret;
|
---|
1034 |
|
---|
1035 | }
|
---|
1036 |
|
---|
1037 | /*************************************************************************
|
---|
1038 | * SHMapPIDLToSystemImageListIndex [SHELL32.77]
|
---|
1039 | *
|
---|
1040 | * PARAMETERS
|
---|
1041 | * sh [IN] pointer to an instance of IShellFolder
|
---|
1042 | * pidl [IN]
|
---|
1043 | * pIndex [OUT][OPTIONAL] SIC index for big icon
|
---|
1044 | *
|
---|
1045 | */
|
---|
1046 | int WINAPI SHMapPIDLToSystemImageListIndex(
|
---|
1047 | LPSHELLFOLDER sh,
|
---|
1048 | LPCITEMIDLIST pidl,
|
---|
1049 | UINT * pIndex)
|
---|
1050 | {
|
---|
1051 | UINT Index;
|
---|
1052 |
|
---|
1053 | TRACE("(SF=%p,pidl=%p,%p)\n",sh,pidl,pIndex);
|
---|
1054 | pdump(pidl);
|
---|
1055 |
|
---|
1056 | if (pIndex)
|
---|
1057 | PidlToSicIndex ( sh, pidl, 1, 0, pIndex);
|
---|
1058 | PidlToSicIndex ( sh, pidl, 0, 0, &Index);
|
---|
1059 | return Index;
|
---|
1060 | }
|
---|
1061 |
|
---|
1062 | /*************************************************************************
|
---|
1063 | * Shell_GetCachedImageIndex [SHELL32.72]
|
---|
1064 | *
|
---|
1065 | */
|
---|
1066 | INT WINAPI Shell_GetCachedImageIndexA(LPCSTR szPath, INT nIndex, BOOL bSimulateDoc)
|
---|
1067 | {
|
---|
1068 | WARN("(%s,%08x,%08x) semi-stub.\n",debugstr_a(szPath), nIndex, bSimulateDoc);
|
---|
1069 | return SIC_GetIconIndex(szPath, nIndex);
|
---|
1070 | }
|
---|
1071 |
|
---|
1072 | INT WINAPI Shell_GetCachedImageIndexW(LPCWSTR szPath, INT nIndex, BOOL bSimulateDoc)
|
---|
1073 | { INT ret;
|
---|
1074 | LPSTR sTemp = HEAP_strdupWtoA (GetProcessHeap(),0,szPath);
|
---|
1075 |
|
---|
1076 | WARN("(%s,%08x,%08x) semi-stub.\n",debugstr_w(szPath), nIndex, bSimulateDoc);
|
---|
1077 |
|
---|
1078 | ret = SIC_GetIconIndex(sTemp, nIndex);
|
---|
1079 | HeapFree(GetProcessHeap(),0,sTemp);
|
---|
1080 | return ret;
|
---|
1081 | }
|
---|
1082 |
|
---|
1083 | INT WINAPI Shell_GetCachedImageIndexAW(LPCVOID szPath, INT nIndex, BOOL bSimulateDoc)
|
---|
1084 | { if( SHELL_OsIsUnicode())
|
---|
1085 | return Shell_GetCachedImageIndexW(szPath, nIndex, bSimulateDoc);
|
---|
1086 | return Shell_GetCachedImageIndexA(szPath, nIndex, bSimulateDoc);
|
---|
1087 | }
|
---|
1088 |
|
---|
1089 | #ifdef __WIN32OS2__
|
---|
1090 |
|
---|
1091 | /*************************************************************************
|
---|
1092 | * ExtractIconEx [shell32.189]
|
---|
1093 | */
|
---|
1094 | UINT WINAPI ExtractIconExAW ( LPCVOID lpszFile, INT nIconIndex, HICON * phiconLarge, HICON * phiconSmall, UINT nIcons )
|
---|
1095 | { if (SHELL_OsIsUnicode())
|
---|
1096 | return ExtractIconExW ( lpszFile, nIconIndex, phiconLarge, phiconSmall, nIcons);
|
---|
1097 | return ExtractIconExA ( lpszFile, nIconIndex, phiconLarge, phiconSmall, nIcons);
|
---|
1098 | }
|
---|
1099 | /*************************************************************************
|
---|
1100 | * ExtractIconExA [shell32.190]
|
---|
1101 | *
|
---|
1102 | * PARAMETERS
|
---|
1103 | * lpszFile [in] Pointer to a null-terminated string specifying the name
|
---|
1104 | * of an executable file, DLL, or icon file from which
|
---|
1105 | * icons will be extracted.
|
---|
1106 | *
|
---|
1107 | * nIconIndex [in] Specifies the zero-based index of the first icon to
|
---|
1108 | * extract. For example, if this value is zero, the
|
---|
1109 | * function extracts the first icon in the specified file.
|
---|
1110 | *
|
---|
1111 | * If this value is -1 and phIconLarge and phiconSmall are
|
---|
1112 | * both NULL, the function returns the total number of
|
---|
1113 | * icons in the specified file. If the file is an
|
---|
1114 | * executable file or DLL, the return value is the number
|
---|
1115 | * of RT_GROUP_ICON resources. If the file is an .ico file,
|
---|
1116 | * the return value is 1.
|
---|
1117 | *
|
---|
1118 | * Windows 95/98, Windows NT 4.0, and Windows 2000:
|
---|
1119 | * If this value is a negative number and either
|
---|
1120 | * phIconLarge or phiconSmall is not NULL, the function
|
---|
1121 | * begins by extracting the icon whose resource identifier
|
---|
1122 | * is equal to the absolute value of nIconIndex. For
|
---|
1123 | * example, use -3 to extract the icon whose resource
|
---|
1124 | * identifier is 3.
|
---|
1125 | *
|
---|
1126 | * phiconLarge [out] Pointer to an array of icon handles that receives
|
---|
1127 | * handles to the large icons extracted from the file.
|
---|
1128 | * If this parameter is NULL, no large icons are extracted
|
---|
1129 | * from the file.
|
---|
1130 | *
|
---|
1131 | * phiconSmall [out] Pointer to an array of icon handles that receives
|
---|
1132 | * handles to the small icons extracted from the file.
|
---|
1133 | * If this parameter is NULL, no small icons are extracted
|
---|
1134 | * from the file.
|
---|
1135 | *
|
---|
1136 | * nIcons [in] Specifies the number of icons to extract from the file.
|
---|
1137 | *
|
---|
1138 | * RETURNS
|
---|
1139 | * If the nIconIndex parameter is -1, the phiconLarge parameter is NULL, and
|
---|
1140 | * the phiconSmall parameter is NULL, then the return value is the number of
|
---|
1141 | * icons contained in the specified file. Otherwise, the return value is the
|
---|
1142 | * number of icons successfully extracted from the file.
|
---|
1143 | */
|
---|
1144 | UINT WINAPI ExtractIconExA ( LPCSTR lpszFile, INT nIconIndex, HICON * phiconLarge, HICON * phiconSmall, UINT nIcons )
|
---|
1145 | { UINT ret=0;
|
---|
1146 |
|
---|
1147 | TRACE("file=%s idx=%i %p %p num=%i\n", lpszFile, nIconIndex, phiconLarge, phiconSmall, nIcons );
|
---|
1148 |
|
---|
1149 | if ( ( nIconIndex == -1 ) && !phiconLarge && !phiconSmall ) /* Number of icons requested */
|
---|
1150 | return ICO_ExtractIconEx(lpszFile, NULL, -1, 0, 0, 0 );
|
---|
1151 |
|
---|
1152 | /* KSO: What, if phiconLarge and phiconSmall are given, and first call
|
---|
1153 | to ICO_ExtractIconEx returns a value other than the second one?
|
---|
1154 | */
|
---|
1155 | if (phiconLarge)
|
---|
1156 | ret = ICO_ExtractIconEx(lpszFile, phiconLarge, nIconIndex, nIcons, 32, 32 );
|
---|
1157 |
|
---|
1158 | if (phiconSmall)
|
---|
1159 | ret = ICO_ExtractIconEx(lpszFile, phiconSmall, nIconIndex, nIcons, 16, 16 );
|
---|
1160 |
|
---|
1161 | return ret;
|
---|
1162 | }
|
---|
1163 | /*************************************************************************
|
---|
1164 | * ExtractIconExW [shell32.191]
|
---|
1165 | */
|
---|
1166 | UINT WINAPI ExtractIconExW ( LPCWSTR lpszFile, INT nIconIndex, HICON * phiconLarge, HICON * phiconSmall, UINT nIcons )
|
---|
1167 | { LPSTR sFile;
|
---|
1168 | UINT ret;
|
---|
1169 |
|
---|
1170 | TRACE("file=%s idx=%i %p %p num=%i\n", debugstr_w(lpszFile), nIconIndex, phiconLarge, phiconSmall, nIcons );
|
---|
1171 |
|
---|
1172 | sFile = HEAP_strdupWtoA (GetProcessHeap(),0,lpszFile);
|
---|
1173 | ret = ExtractIconExA ( sFile, nIconIndex, phiconLarge, phiconSmall, nIcons);
|
---|
1174 | HeapFree(GetProcessHeap(),0,sFile);
|
---|
1175 | return ret;
|
---|
1176 | }
|
---|
1177 |
|
---|
1178 | #else /* ! __WIN32OS2__ */
|
---|
1179 |
|
---|
1180 | /*************************************************************************
|
---|
1181 | * ExtractIconEx [shell32.189]
|
---|
1182 | */
|
---|
1183 | HICON WINAPI ExtractIconExAW ( LPCVOID lpszFile, INT nIconIndex, HICON * phiconLarge, HICON * phiconSmall, UINT nIcons )
|
---|
1184 | { if (SHELL_OsIsUnicode())
|
---|
1185 | return ExtractIconExW ( lpszFile, nIconIndex, phiconLarge, phiconSmall, nIcons);
|
---|
1186 | return ExtractIconExA ( lpszFile, nIconIndex, phiconLarge, phiconSmall, nIcons);
|
---|
1187 | }
|
---|
1188 | /*************************************************************************
|
---|
1189 | * ExtractIconExA [shell32.190]
|
---|
1190 | * RETURNS
|
---|
1191 | * 0 no icon found
|
---|
1192 | * 1 file is not valid
|
---|
1193 | * HICON handle of a icon (phiconLarge/Small == NULL)
|
---|
1194 | */
|
---|
1195 | HICON WINAPI ExtractIconExA ( LPCSTR lpszFile, INT nIconIndex, HICON * phiconLarge, HICON * phiconSmall, UINT nIcons )
|
---|
1196 | { HICON ret=0;
|
---|
1197 |
|
---|
1198 | TRACE("file=%s idx=%i %p %p num=%i\n", lpszFile, nIconIndex, phiconLarge, phiconSmall, nIcons );
|
---|
1199 |
|
---|
1200 | if (nIconIndex==-1) /* Number of icons requested */
|
---|
1201 | return ICO_ExtractIconEx(lpszFile, NULL, -1, 0, 0, 0 );
|
---|
1202 |
|
---|
1203 |
|
---|
1204 | if (phiconLarge)
|
---|
1205 | { ret = ICO_ExtractIconEx(lpszFile, phiconLarge, nIconIndex, nIcons, 32, 32 );
|
---|
1206 | if ( nIcons==1)
|
---|
1207 | { ret = phiconLarge[0];
|
---|
1208 | }
|
---|
1209 | }
|
---|
1210 |
|
---|
1211 | /* if no pointers given and one icon expected, return the handle directly*/
|
---|
1212 | if (!phiconLarge && ! phiconSmall && nIcons==1 )
|
---|
1213 | phiconSmall = &ret;
|
---|
1214 |
|
---|
1215 | if (phiconSmall)
|
---|
1216 | { ret = ICO_ExtractIconEx(lpszFile, phiconSmall, nIconIndex, nIcons, 16, 16 );
|
---|
1217 | if ( nIcons==1 )
|
---|
1218 | { ret = phiconSmall[0];
|
---|
1219 | }
|
---|
1220 | }
|
---|
1221 |
|
---|
1222 | return ret;
|
---|
1223 | }
|
---|
1224 | /*************************************************************************
|
---|
1225 | * ExtractIconExW [shell32.191]
|
---|
1226 | */
|
---|
1227 | HICON WINAPI ExtractIconExW ( LPCWSTR lpszFile, INT nIconIndex, HICON * phiconLarge, HICON * phiconSmall, UINT nIcons )
|
---|
1228 | { LPSTR sFile;
|
---|
1229 | DWORD ret;
|
---|
1230 |
|
---|
1231 | TRACE("file=%s idx=%i %p %p num=%i\n", debugstr_w(lpszFile), nIconIndex, phiconLarge, phiconSmall, nIcons );
|
---|
1232 |
|
---|
1233 | sFile = HEAP_strdupWtoA (GetProcessHeap(),0,lpszFile);
|
---|
1234 | ret = ExtractIconExA ( sFile, nIconIndex, phiconLarge, phiconSmall, nIcons);
|
---|
1235 | HeapFree(GetProcessHeap(),0,sFile);
|
---|
1236 | return ret;
|
---|
1237 | }
|
---|
1238 |
|
---|
1239 | #endif /* ! __WIN32OS2__ */
|
---|
1240 |
|
---|