Changed ressource dir structures.

Adapted FindBestIccon/FindBestCursor.
This commit is contained in:
Juergen Schmied 1999-04-11 11:46:32 +00:00 committed by Alexandre Julliard
parent d0d1f1505e
commit c45bbee66b
2 changed files with 78 additions and 89 deletions

View File

@ -17,26 +17,23 @@ typedef struct
BYTE bHeight; BYTE bHeight;
BYTE bColorCount; BYTE bColorCount;
BYTE bReserved; BYTE bReserved;
WORD wPlanes; } ICONRESDIR;
WORD wBitCount;
DWORD dwBytesInRes;
WORD wResId;
} ICONDIRENTRY;
typedef struct typedef struct
{ {
WORD wWidth; WORD wWidth;
WORD wHeight; WORD wHeight;
} CURSORDIR;
typedef struct
{ union
{ ICONRESDIR icon;
CURSORDIR cursor;
} ResInfo;
WORD wPlanes; WORD wPlanes;
WORD wBitCount; WORD wBitCount;
DWORD dwBytesInRes; DWORD dwBytesInRes;
WORD wResId; WORD wResId;
} CURSORDIRENTRY;
typedef union
{
ICONDIRENTRY icon;
CURSORDIRENTRY cursor;
} CURSORICONDIRENTRY; } CURSORICONDIRENTRY;
typedef struct typedef struct

View File

@ -188,55 +188,55 @@ void CURSORICON_FreeModuleIcons( HMODULE hModule )
* *
* Find the icon closest to the requested size and number of colors. * Find the icon closest to the requested size and number of colors.
*/ */
static ICONDIRENTRY *CURSORICON_FindBestIcon( CURSORICONDIR *dir, int width, static CURSORICONDIRENTRY *CURSORICON_FindBestIcon( CURSORICONDIR *dir, int width,
int height, int colors ) int height, int colors )
{ {
int i, maxcolors, maxwidth, maxheight; int i, maxcolors, maxwidth, maxheight;
ICONDIRENTRY *entry, *bestEntry = NULL; CURSORICONDIRENTRY *entry, *bestEntry = NULL;
if (dir->idCount < 1) if (dir->idCount < 1)
{ {
WARN(icon, "Empty directory!\n" ); WARN(icon, "Empty directory!\n" );
return NULL; return NULL;
} }
if (dir->idCount == 1) return &dir->idEntries[0].icon; /* No choice... */ if (dir->idCount == 1) return &dir->idEntries[0]; /* No choice... */
/* First find the exact size with less colors */ /* First find the exact size with less colors */
maxcolors = 0; maxcolors = 0;
for (i = 0, entry = &dir->idEntries[0].icon; i < dir->idCount; i++,entry++) for (i = 0, entry = &dir->idEntries[0]; i < dir->idCount; i++,entry++)
if ((entry->bWidth == width) && (entry->bHeight == height) && if ((entry->ResInfo.icon.bWidth == width) && (entry->ResInfo.icon.bHeight == height) &&
(entry->bColorCount <= colors) && (entry->bColorCount > maxcolors)) (entry->ResInfo.icon.bColorCount <= colors) && (entry->ResInfo.icon.bColorCount > maxcolors))
{ {
bestEntry = entry; bestEntry = entry;
maxcolors = entry->bColorCount; maxcolors = entry->ResInfo.icon.bColorCount;
} }
if (bestEntry) return bestEntry; if (bestEntry) return bestEntry;
/* First find the exact size with more colors */ /* First find the exact size with more colors */
maxcolors = 255; maxcolors = 255;
for (i = 0, entry = &dir->idEntries[0].icon; i < dir->idCount; i++,entry++) for (i = 0, entry = &dir->idEntries[0]; i < dir->idCount; i++,entry++)
if ((entry->bWidth == width) && (entry->bHeight == height) && if ((entry->ResInfo.icon.bWidth == width) && (entry->ResInfo.icon.bHeight == height) &&
(entry->bColorCount > colors) && (entry->bColorCount <= maxcolors)) (entry->ResInfo.icon.bColorCount > colors) && (entry->ResInfo.icon.bColorCount <= maxcolors))
{ {
bestEntry = entry; bestEntry = entry;
maxcolors = entry->bColorCount; maxcolors = entry->ResInfo.icon.bColorCount;
} }
if (bestEntry) return bestEntry; if (bestEntry) return bestEntry;
/* Now find a smaller one with less colors */ /* Now find a smaller one with less colors */
maxcolors = maxwidth = maxheight = 0; maxcolors = maxwidth = maxheight = 0;
for (i = 0, entry = &dir->idEntries[0].icon; i < dir->idCount; i++,entry++) for (i = 0, entry = &dir->idEntries[0]; i < dir->idCount; i++,entry++)
if ((entry->bWidth <= width) && (entry->bHeight <= height) && if ((entry->ResInfo.icon.bWidth <= width) && (entry->ResInfo.icon.bHeight <= height) &&
(entry->bWidth >= maxwidth) && (entry->bHeight >= maxheight) && (entry->ResInfo.icon.bWidth >= maxwidth) && (entry->ResInfo.icon.bHeight >= maxheight) &&
(entry->bColorCount <= colors) && (entry->bColorCount > maxcolors)) (entry->ResInfo.icon.bColorCount <= colors) && (entry->ResInfo.icon.bColorCount > maxcolors))
{ {
bestEntry = entry; bestEntry = entry;
maxwidth = entry->bWidth; maxwidth = entry->ResInfo.icon.bWidth;
maxheight = entry->bHeight; maxheight = entry->ResInfo.icon.bHeight;
maxcolors = entry->bColorCount; maxcolors = entry->ResInfo.icon.bColorCount;
} }
if (bestEntry) return bestEntry; if (bestEntry) return bestEntry;
@ -244,15 +244,15 @@ static ICONDIRENTRY *CURSORICON_FindBestIcon( CURSORICONDIR *dir, int width,
maxcolors = 255; maxcolors = 255;
maxwidth = maxheight = 0; maxwidth = maxheight = 0;
for (i = 0, entry = &dir->idEntries[0].icon; i < dir->idCount; i++,entry++) for (i = 0, entry = &dir->idEntries[0]; i < dir->idCount; i++,entry++)
if ((entry->bWidth <= width) && (entry->bHeight <= height) && if ((entry->ResInfo.icon.bWidth <= width) && (entry->ResInfo.icon.bHeight <= height) &&
(entry->bWidth >= maxwidth) && (entry->bHeight >= maxheight) && (entry->ResInfo.icon.bWidth >= maxwidth) && (entry->ResInfo.icon.bHeight >= maxheight) &&
(entry->bColorCount > colors) && (entry->bColorCount <= maxcolors)) (entry->ResInfo.icon.bColorCount > colors) && (entry->ResInfo.icon.bColorCount <= maxcolors))
{ {
bestEntry = entry; bestEntry = entry;
maxwidth = entry->bWidth; maxwidth = entry->ResInfo.icon.bWidth;
maxheight = entry->bHeight; maxheight = entry->ResInfo.icon.bHeight;
maxcolors = entry->bColorCount; maxcolors = entry->ResInfo.icon.bColorCount;
} }
if (bestEntry) return bestEntry; if (bestEntry) return bestEntry;
@ -260,28 +260,28 @@ static ICONDIRENTRY *CURSORICON_FindBestIcon( CURSORICONDIR *dir, int width,
maxcolors = 0; maxcolors = 0;
maxwidth = maxheight = 255; maxwidth = maxheight = 255;
for (i = 0, entry = &dir->idEntries[0].icon; i < dir->idCount; i++,entry++) for (i = 0, entry = &dir->idEntries[0]; i < dir->idCount; i++,entry++)
if ((entry->bWidth <= maxwidth) && (entry->bHeight <= maxheight) && if ((entry->ResInfo.icon.bWidth <= maxwidth) && (entry->ResInfo.icon.bHeight <= maxheight) &&
(entry->bColorCount <= colors) && (entry->bColorCount > maxcolors)) (entry->ResInfo.icon.bColorCount <= colors) && (entry->ResInfo.icon.bColorCount > maxcolors))
{ {
bestEntry = entry; bestEntry = entry;
maxwidth = entry->bWidth; maxwidth = entry->ResInfo.icon.bWidth;
maxheight = entry->bHeight; maxheight = entry->ResInfo.icon.bHeight;
maxcolors = entry->bColorCount; maxcolors = entry->ResInfo.icon.bColorCount;
} }
if (bestEntry) return bestEntry; if (bestEntry) return bestEntry;
/* Now find a larger one with more colors */ /* Now find a larger one with more colors */
maxcolors = maxwidth = maxheight = 255; maxcolors = maxwidth = maxheight = 255;
for (i = 0, entry = &dir->idEntries[0].icon; i < dir->idCount; i++,entry++) for (i = 0, entry = &dir->idEntries[0]; i < dir->idCount; i++,entry++)
if ((entry->bWidth <= maxwidth) && (entry->bHeight <= maxheight) && if ((entry->ResInfo.icon.bWidth <= maxwidth) && (entry->ResInfo.icon.bHeight <= maxheight) &&
(entry->bColorCount > colors) && (entry->bColorCount <= maxcolors)) (entry->ResInfo.icon.bColorCount > colors) && (entry->ResInfo.icon.bColorCount <= maxcolors))
{ {
bestEntry = entry; bestEntry = entry;
maxwidth = entry->bWidth; maxwidth = entry->ResInfo.icon.bWidth;
maxheight = entry->bHeight; maxheight = entry->ResInfo.icon.bHeight;
maxcolors = entry->bColorCount; maxcolors = entry->ResInfo.icon.bColorCount;
} }
return bestEntry; return bestEntry;
@ -295,43 +295,43 @@ static ICONDIRENTRY *CURSORICON_FindBestIcon( CURSORICONDIR *dir, int width,
* FIXME: parameter 'color' ignored and entries with more than 1 bpp * FIXME: parameter 'color' ignored and entries with more than 1 bpp
* ignored too * ignored too
*/ */
static CURSORDIRENTRY *CURSORICON_FindBestCursor( CURSORICONDIR *dir, static CURSORICONDIRENTRY *CURSORICON_FindBestCursor( CURSORICONDIR *dir,
int width, int height, int color) int width, int height, int color)
{ {
int i, maxwidth, maxheight; int i, maxwidth, maxheight;
CURSORDIRENTRY *entry, *bestEntry = NULL; CURSORICONDIRENTRY *entry, *bestEntry = NULL;
if (dir->idCount < 1) if (dir->idCount < 1)
{ {
WARN(cursor, "Empty directory!\n" ); WARN(cursor, "Empty directory!\n" );
return NULL; return NULL;
} }
if (dir->idCount == 1) return &dir->idEntries[0].cursor; /* No choice... */ if (dir->idCount == 1) return &dir->idEntries[0]; /* No choice... */
/* First find the largest one smaller than or equal to the requested size*/ /* First find the largest one smaller than or equal to the requested size*/
maxwidth = maxheight = 0; maxwidth = maxheight = 0;
for(i = 0,entry = &dir->idEntries[0].cursor; i < dir->idCount; i++,entry++) for(i = 0,entry = &dir->idEntries[0]; i < dir->idCount; i++,entry++)
if ((entry->wWidth <= width) && (entry->wHeight <= height) && if ((entry->ResInfo.cursor.wWidth <= width) && (entry->ResInfo.cursor.wHeight <= height) &&
(entry->wWidth > maxwidth) && (entry->wHeight > maxheight) && (entry->ResInfo.cursor.wWidth > maxwidth) && (entry->ResInfo.cursor.wHeight > maxheight) &&
(entry->wBitCount == 1)) (entry->wBitCount == 1))
{ {
bestEntry = entry; bestEntry = entry;
maxwidth = entry->wWidth; maxwidth = entry->ResInfo.cursor.wWidth;
maxheight = entry->wHeight; maxheight = entry->ResInfo.cursor.wHeight;
} }
if (bestEntry) return bestEntry; if (bestEntry) return bestEntry;
/* Now find the smallest one larger than the requested size */ /* Now find the smallest one larger than the requested size */
maxwidth = maxheight = 255; maxwidth = maxheight = 255;
for(i = 0,entry = &dir->idEntries[0].cursor; i < dir->idCount; i++,entry++) for(i = 0,entry = &dir->idEntries[0]; i < dir->idCount; i++,entry++)
if ((entry->wWidth < maxwidth) && (entry->wHeight < maxheight) && if ((entry->ResInfo.cursor.wWidth < maxwidth) && (entry->ResInfo.cursor.wHeight < maxheight) &&
(entry->wBitCount == 1)) (entry->wBitCount == 1))
{ {
bestEntry = entry; bestEntry = entry;
maxwidth = entry->wWidth; maxwidth = entry->ResInfo.cursor.wWidth;
maxheight = entry->wHeight; maxheight = entry->ResInfo.cursor.wHeight;
} }
return bestEntry; return bestEntry;
@ -396,29 +396,25 @@ BOOL CURSORICON_SimulateLoadingFromResourceW( LPWSTR filename, BOOL fCursor,
{ {
((LPBYTE*)(*ptr))[i] = _free; ((LPBYTE*)(*ptr))[i] = _free;
if (fCursor) { if (fCursor) {
(*res)->idEntries[i].cursor.wWidth=bits->idEntries[i].bWidth; (*res)->idEntries[i].ResInfo.cursor.wWidth=bits->idEntries[i].bWidth;
(*res)->idEntries[i].cursor.wHeight=bits->idEntries[i].bHeight; (*res)->idEntries[i].ResInfo.cursor.wHeight=bits->idEntries[i].bHeight;
(*res)->idEntries[i].cursor.wPlanes=1;
(*res)->idEntries[i].cursor.wBitCount = ((LPBITMAPINFOHEADER)((LPBYTE)bits +
bits->idEntries[i].dwDIBOffset))->biBitCount;
(*res)->idEntries[i].cursor.dwBytesInRes = bits->idEntries[i].dwDIBSize;
(*res)->idEntries[i].cursor.wResId=i+1;
((LPPOINT16)_free)->x=bits->idEntries[i].xHotspot; ((LPPOINT16)_free)->x=bits->idEntries[i].xHotspot;
((LPPOINT16)_free)->y=bits->idEntries[i].yHotspot; ((LPPOINT16)_free)->y=bits->idEntries[i].yHotspot;
_free+=sizeof(POINT16); _free+=sizeof(POINT16);
} else { } else {
(*res)->idEntries[i].icon.bWidth=bits->idEntries[i].bWidth; (*res)->idEntries[i].ResInfo.icon.bWidth=bits->idEntries[i].bWidth;
(*res)->idEntries[i].icon.bHeight=bits->idEntries[i].bHeight; (*res)->idEntries[i].ResInfo.icon.bHeight=bits->idEntries[i].bHeight;
(*res)->idEntries[i].icon.bColorCount = bits->idEntries[i].bColorCount; (*res)->idEntries[i].ResInfo.icon.bColorCount = bits->idEntries[i].bColorCount;
(*res)->idEntries[i].icon.wPlanes=1;
(*res)->idEntries[i].icon.wBitCount= ((LPBITMAPINFOHEADER)((LPBYTE)bits +
bits->idEntries[i].dwDIBOffset))->biBitCount;
(*res)->idEntries[i].icon.dwBytesInRes = bits->idEntries[i].dwDIBSize;
(*res)->idEntries[i].icon.wResId=i+1;
} }
(*res)->idEntries[i].wPlanes=1;
(*res)->idEntries[i].wBitCount = ((LPBITMAPINFOHEADER)((LPBYTE)bits +
bits->idEntries[i].dwDIBOffset))->biBitCount;
(*res)->idEntries[i].dwBytesInRes = bits->idEntries[i].dwDIBSize;
(*res)->idEntries[i].wResId=i+1;
memcpy(_free,(LPBYTE)bits +bits->idEntries[i].dwDIBOffset, memcpy(_free,(LPBYTE)bits +bits->idEntries[i].dwDIBOffset,
(*res)->idEntries[i].icon.dwBytesInRes); (*res)->idEntries[i].dwBytesInRes);
_free += (*res)->idEntries[i].icon.dwBytesInRes; _free += (*res)->idEntries[i].dwBytesInRes;
} }
UnmapViewOfFile( bits ); UnmapViewOfFile( bits );
return TRUE; return TRUE;
@ -685,8 +681,8 @@ HGLOBAL CURSORICON_Load( HINSTANCE hInstance, LPCWSTR name,
dirEntry = (CURSORICONDIRENTRY *)CURSORICON_FindBestCursor(dir, width, height, 1); dirEntry = (CURSORICONDIRENTRY *)CURSORICON_FindBestCursor(dir, width, height, 1);
else else
dirEntry = (CURSORICONDIRENTRY *)CURSORICON_FindBestIcon(dir, width, height, colors); dirEntry = (CURSORICONDIRENTRY *)CURSORICON_FindBestIcon(dir, width, height, colors);
bits = ptr[dirEntry->icon.wResId-1]; bits = ptr[dirEntry->wResId-1];
h = CURSORICON_CreateFromResource( 0, 0, bits, dirEntry->icon.dwBytesInRes, h = CURSORICON_CreateFromResource( 0, 0, bits, dirEntry->dwBytesInRes,
!fCursor, 0x00030000, width, height, loadflags); !fCursor, 0x00030000, width, height, loadflags);
HeapFree( GetProcessHeap(), 0, dir ); HeapFree( GetProcessHeap(), 0, dir );
HeapFree( GetProcessHeap(), 0, ptr ); HeapFree( GetProcessHeap(), 0, ptr );
@ -757,8 +753,8 @@ HGLOBAL CURSORICON_Load( HINSTANCE hInstance, LPCWSTR name,
dirEntry = (CURSORICONDIRENTRY *)CURSORICON_FindBestIcon( dir, dirEntry = (CURSORICONDIRENTRY *)CURSORICON_FindBestIcon( dir,
width, height, colors ); width, height, colors );
if (!dirEntry) return 0; if (!dirEntry) return 0;
wResId = dirEntry->icon.wResId; wResId = dirEntry->wResId;
dwBytesInRes = dirEntry->icon.dwBytesInRes; dwBytesInRes = dirEntry->dwBytesInRes;
FreeResource( handle ); FreeResource( handle );
/* Load the resource */ /* Load the resource */
@ -1382,20 +1378,16 @@ INT16 WINAPI LookupIconIdFromDirectoryEx16( LPBYTE xdir, BOOL16 bIcon,
HDC hdc = GetDC(0); HDC hdc = GetDC(0);
UINT palEnts = GetSystemPaletteEntries(hdc, 0, 0, NULL); UINT palEnts = GetSystemPaletteEntries(hdc, 0, 0, NULL);
int colors = (cFlag & LR_MONOCHROME) ? 2 : palEnts; int colors = (cFlag & LR_MONOCHROME) ? 2 : palEnts;
CURSORICONDIRENTRY* entry;
ReleaseDC(0, hdc); ReleaseDC(0, hdc);
if( bIcon ) if( bIcon )
{
ICONDIRENTRY* entry;
entry = CURSORICON_FindBestIcon( dir, width, height, colors ); entry = CURSORICON_FindBestIcon( dir, width, height, colors );
if( entry ) retVal = entry->wResId;
}
else else
{
CURSORDIRENTRY* entry;
entry = CURSORICON_FindBestCursor( dir, width, height, 1); entry = CURSORICON_FindBestCursor( dir, width, height, 1);
if( entry ) retVal = entry->wResId;
} if( entry ) retVal = entry->wResId;
} }
else WARN(cursor, "invalid resource directory\n"); else WARN(cursor, "invalid resource directory\n");
return retVal; return retVal;