diff --git a/reactos/dll/win32/user32/resources/ocr_appstarting.cur b/reactos/dll/win32/user32/resources/ocr_appstarting.cur index 9824325bc41..ed13fd97801 100644 Binary files a/reactos/dll/win32/user32/resources/ocr_appstarting.cur and b/reactos/dll/win32/user32/resources/ocr_appstarting.cur differ diff --git a/reactos/dll/win32/user32/resources/ocr_cdautostart.cur b/reactos/dll/win32/user32/resources/ocr_cdautostart.cur index 53a8a448925..1c8966ed02b 100644 Binary files a/reactos/dll/win32/user32/resources/ocr_cdautostart.cur and b/reactos/dll/win32/user32/resources/ocr_cdautostart.cur differ diff --git a/reactos/dll/win32/user32/resources/ocr_cross.cur b/reactos/dll/win32/user32/resources/ocr_cross.cur index 63b25abba7b..1eee76ce346 100644 Binary files a/reactos/dll/win32/user32/resources/ocr_cross.cur and b/reactos/dll/win32/user32/resources/ocr_cross.cur differ diff --git a/reactos/dll/win32/user32/resources/ocr_dragobject.cur b/reactos/dll/win32/user32/resources/ocr_dragobject.cur index 45f593fb3e6..2bf0c732f20 100644 Binary files a/reactos/dll/win32/user32/resources/ocr_dragobject.cur and b/reactos/dll/win32/user32/resources/ocr_dragobject.cur differ diff --git a/reactos/dll/win32/user32/resources/ocr_hand.cur b/reactos/dll/win32/user32/resources/ocr_hand.cur index cea3d766b2c..9815d03bcc3 100644 Binary files a/reactos/dll/win32/user32/resources/ocr_hand.cur and b/reactos/dll/win32/user32/resources/ocr_hand.cur differ diff --git a/reactos/dll/win32/user32/resources/ocr_help.cur b/reactos/dll/win32/user32/resources/ocr_help.cur index 88c72904459..92f4d41402e 100644 Binary files a/reactos/dll/win32/user32/resources/ocr_help.cur and b/reactos/dll/win32/user32/resources/ocr_help.cur differ diff --git a/reactos/dll/win32/user32/resources/ocr_ibeam.cur b/reactos/dll/win32/user32/resources/ocr_ibeam.cur index 4c44e602bbe..517e1104d91 100644 Binary files a/reactos/dll/win32/user32/resources/ocr_ibeam.cur and b/reactos/dll/win32/user32/resources/ocr_ibeam.cur differ diff --git a/reactos/dll/win32/user32/resources/ocr_icon.cur b/reactos/dll/win32/user32/resources/ocr_icon.cur index b0e3dd26d14..223b3b3a814 100644 Binary files a/reactos/dll/win32/user32/resources/ocr_icon.cur and b/reactos/dll/win32/user32/resources/ocr_icon.cur differ diff --git a/reactos/dll/win32/user32/resources/ocr_no.cur b/reactos/dll/win32/user32/resources/ocr_no.cur index e636302d3ae..41de76c6da9 100644 Binary files a/reactos/dll/win32/user32/resources/ocr_no.cur and b/reactos/dll/win32/user32/resources/ocr_no.cur differ diff --git a/reactos/dll/win32/user32/resources/ocr_normal.cur b/reactos/dll/win32/user32/resources/ocr_normal.cur index 19a0b084eef..6bbf28a4bae 100644 Binary files a/reactos/dll/win32/user32/resources/ocr_normal.cur and b/reactos/dll/win32/user32/resources/ocr_normal.cur differ diff --git a/reactos/dll/win32/user32/resources/ocr_pen.cur b/reactos/dll/win32/user32/resources/ocr_pen.cur index 92e7f5b6253..b180f3d97d0 100644 Binary files a/reactos/dll/win32/user32/resources/ocr_pen.cur and b/reactos/dll/win32/user32/resources/ocr_pen.cur differ diff --git a/reactos/dll/win32/user32/resources/ocr_size.cur b/reactos/dll/win32/user32/resources/ocr_size.cur index 7ac3c07043f..d7610fa9227 100644 Binary files a/reactos/dll/win32/user32/resources/ocr_size.cur and b/reactos/dll/win32/user32/resources/ocr_size.cur differ diff --git a/reactos/dll/win32/user32/resources/ocr_sizeall.cur b/reactos/dll/win32/user32/resources/ocr_sizeall.cur index 7ac3c07043f..eab28d08f1d 100644 Binary files a/reactos/dll/win32/user32/resources/ocr_sizeall.cur and b/reactos/dll/win32/user32/resources/ocr_sizeall.cur differ diff --git a/reactos/dll/win32/user32/resources/ocr_sizenesw.cur b/reactos/dll/win32/user32/resources/ocr_sizenesw.cur index edd4bb9416b..301adb60744 100644 Binary files a/reactos/dll/win32/user32/resources/ocr_sizenesw.cur and b/reactos/dll/win32/user32/resources/ocr_sizenesw.cur differ diff --git a/reactos/dll/win32/user32/resources/ocr_sizens.cur b/reactos/dll/win32/user32/resources/ocr_sizens.cur index eb754e3d376..d227473dd12 100644 Binary files a/reactos/dll/win32/user32/resources/ocr_sizens.cur and b/reactos/dll/win32/user32/resources/ocr_sizens.cur differ diff --git a/reactos/dll/win32/user32/resources/ocr_sizenwse.cur b/reactos/dll/win32/user32/resources/ocr_sizenwse.cur index 70dcf7cd187..d0c6c256e77 100644 Binary files a/reactos/dll/win32/user32/resources/ocr_sizenwse.cur and b/reactos/dll/win32/user32/resources/ocr_sizenwse.cur differ diff --git a/reactos/dll/win32/user32/resources/ocr_sizewe.cur b/reactos/dll/win32/user32/resources/ocr_sizewe.cur index a121b0ca847..c5e3a15f83f 100644 Binary files a/reactos/dll/win32/user32/resources/ocr_sizewe.cur and b/reactos/dll/win32/user32/resources/ocr_sizewe.cur differ diff --git a/reactos/dll/win32/user32/resources/ocr_up.cur b/reactos/dll/win32/user32/resources/ocr_up.cur index 072e6d859b0..c5940471efd 100644 Binary files a/reactos/dll/win32/user32/resources/ocr_up.cur and b/reactos/dll/win32/user32/resources/ocr_up.cur differ diff --git a/reactos/dll/win32/user32/resources/ocr_wait.cur b/reactos/dll/win32/user32/resources/ocr_wait.cur index 46c7fdee3f7..2be0cbb1ac1 100644 Binary files a/reactos/dll/win32/user32/resources/ocr_wait.cur and b/reactos/dll/win32/user32/resources/ocr_wait.cur differ diff --git a/reactos/dll/win32/user32/windows/draw.c b/reactos/dll/win32/user32/windows/draw.c index 9461e295353..7ee005df653 100644 --- a/reactos/dll/win32/user32/windows/draw.c +++ b/reactos/dll/win32/user32/windows/draw.c @@ -717,123 +717,81 @@ static BOOL UITOOLS95_DFC_ButtonCheck(HDC dc, LPRECT r, UINT uFlags) return TRUE; } -/* Ported from WINE20020904 */ -/* Draw a radio/radioimage/radiomask button coming from DrawFrameControl() - * - * Does a pretty good job in emulating MS behavior. Some quirks are - * however there because MS uses a TrueType font (Marlett) to draw - * the buttons. - */ static BOOL UITOOLS95_DFC_ButtonRadio(HDC dc, LPRECT r, UINT uFlags) { - RECT myr; - int i; - int SmallDiam = UITOOLS_MakeSquareRect(r, &myr); - int BorderShrink = SmallDiam / 16; - HPEN hpsave; - HBRUSH hbsave; - int xc, yc; + RECT rc; + LOGFONT lf; + HFONT hFont, hOldFont; + int SmallDiam, i; - if(BorderShrink < 1) BorderShrink = 1; + LPCTSTR OutRight = TEXT("j"); // Outer right + LPCTSTR OutLeft = TEXT("k"); // Outer left + LPCTSTR InRight = TEXT("l"); // inner right + LPCTSTR InLeft = TEXT("m"); // inner left + LPCTSTR Center = TEXT("n"); // center - if((uFlags & 0xff) == DFCS_BUTTONRADIOIMAGE) - { - FillRect(dc, r, (HBRUSH)GetStockObject(BLACK_BRUSH)); - } + SmallDiam = UITOOLS_MakeSquareRect(r, &rc); - xc = myr.left + SmallDiam - SmallDiam/2; - yc = myr.top + SmallDiam - SmallDiam/2; - - /* Define bounding box */ - i = 14*SmallDiam/16; - myr.left = xc - i+i/2; - myr.right = xc + i/2; - myr.top = yc - i+i/2; - myr.bottom = yc + i/2; + ZeroMemory(&lf, sizeof(LOGFONT)); + lf.lfHeight = SmallDiam; + lf.lfWidth = 0; + lf.lfWeight = FW_NORMAL; + lf.lfCharSet = DEFAULT_CHARSET; + lstrcpy(lf.lfFaceName, TEXT("Marlett")); + hFont = CreateFontIndirect(&lf); + hOldFont = SelectObject(dc, hFont); if((uFlags & 0xff) == DFCS_BUTTONRADIOMASK) { - hbsave = (HBRUSH)SelectObject(dc, GetStockObject(BLACK_BRUSH)); - Ellipse(dc, myr.left, myr.top, myr.right, myr.bottom); - SelectObject(dc, hbsave); + SetBkMode(dc, OPAQUE); + SetTextColor(dc, GetSysColor(COLOR_WINDOWFRAME)); + TextOut(dc, rc.left, rc.top, Center, 1); + SetBkMode(dc, TRANSPARENT); + SetTextColor(dc, GetSysColor(COLOR_WINDOWFRAME)); + TextOut(dc, rc.left, rc.top, OutRight, 1); + SetTextColor(dc, GetSysColor(COLOR_WINDOWFRAME)); + TextOut(dc, rc.left, rc.top, OutLeft, 1); } else { - if(uFlags & (DFCS_FLAT|DFCS_MONO)) + SetBkMode(dc, TRANSPARENT); + + /* Center section, white for active, grey for inactive */ + i= !(uFlags & (DFCS_INACTIVE|DFCS_PUSHED)) ? COLOR_WINDOW : COLOR_BTNFACE; + SetTextColor(dc, GetSysColor(i)); + TextOut(dc, rc.left, rc.top, Center, 1); + + if(uFlags & (DFCS_FLAT | DFCS_MONO)) { - hpsave = (HPEN)SelectObject(dc, GetSysColorPen(COLOR_WINDOWFRAME)); - hbsave = (HBRUSH)SelectObject(dc, GetSysColorBrush(COLOR_WINDOWFRAME)); - Ellipse(dc, myr.left, myr.top, myr.right, myr.bottom); - SelectObject(dc, hbsave); - SelectObject(dc, hpsave); + SetTextColor(dc, GetSysColor(COLOR_WINDOWFRAME)); + TextOut(dc, rc.left, rc.top, OutRight, 1); + TextOut(dc, rc.left, rc.top, OutLeft, 1); + TextOut(dc, rc.left, rc.top, InRight, 1); + TextOut(dc, rc.left, rc.top, InLeft, 1); } else { - hpsave = (HPEN)SelectObject(dc, GetSysColorPen(COLOR_BTNHIGHLIGHT)); - hbsave = (HBRUSH)SelectObject(dc, GetSysColorBrush(COLOR_BTNHIGHLIGHT)); - Pie(dc, myr.left, myr.top, myr.right+1, myr.bottom+1, myr.left-1, myr.bottom, myr.right+1, myr.top); - - SelectObject(dc, GetSysColorPen(COLOR_BTNSHADOW)); - SelectObject(dc, GetSysColorBrush(COLOR_BTNSHADOW)); - Pie(dc, myr.left, myr.top, myr.right+1, myr.bottom+1, myr.right+1, myr.top, myr.left-1, myr.bottom); - - myr.left += BorderShrink; - myr.right -= BorderShrink; - myr.top += BorderShrink; - myr.bottom -= BorderShrink; - - SelectObject(dc, GetSysColorPen(COLOR_3DLIGHT)); - SelectObject(dc, GetSysColorBrush(COLOR_3DLIGHT)); - Pie(dc, myr.left, myr.top, myr.right+1, myr.bottom+1, myr.left-1, myr.bottom, myr.right+1, myr.top); - - SelectObject(dc, GetSysColorPen(COLOR_3DDKSHADOW)); - SelectObject(dc, GetSysColorBrush(COLOR_3DDKSHADOW)); - Pie(dc, myr.left, myr.top, myr.right+1, myr.bottom+1, myr.right+1, myr.top, myr.left-1, myr.bottom); - SelectObject(dc, hbsave); - SelectObject(dc, hpsave); + SetTextColor(dc, GetSysColor(COLOR_BTNSHADOW)); + TextOut(dc, rc.left, rc.top, OutRight, 1); + SetTextColor(dc, GetSysColor(COLOR_BTNHIGHLIGHT)); + TextOut(dc, rc.left, rc.top, OutLeft, 1); + SetTextColor(dc, GetSysColor(COLOR_3DDKSHADOW)); + TextOut(dc, rc.left, rc.top, InRight, 1); + SetTextColor(dc, GetSysColor(COLOR_3DLIGHT)); + TextOut(dc, rc.left, rc.top, InLeft, 1); } - - i = 10*SmallDiam/16; - myr.left = xc - i+i/2; - myr.right = xc + i/2; - myr.top = yc - i+i/2; - myr.bottom = yc + i/2; - i= !(uFlags & (DFCS_INACTIVE|DFCS_PUSHED)) ? COLOR_WINDOW : COLOR_BTNFACE; - hpsave = (HPEN)SelectObject(dc, GetSysColorPen(i)); - hbsave = (HBRUSH)SelectObject(dc, GetSysColorBrush(i)); - Ellipse(dc, myr.left, myr.top, myr.right, myr.bottom); - SelectObject(dc, hbsave); - SelectObject(dc, hpsave); } if(uFlags & DFCS_CHECKED) { - i = 6*SmallDiam/16; - i = i < 1 ? 1 : i; - myr.left = xc - i+i/2; - myr.right = xc + i/2; - myr.top = yc - i+i/2; - myr.bottom = yc + i/2; + LPCTSTR Check = TEXT("i"); - i = uFlags & DFCS_INACTIVE ? COLOR_BTNSHADOW : COLOR_WINDOWTEXT; - hbsave = (HBRUSH)SelectObject(dc, GetSysColorBrush(i)); - hpsave = (HPEN)SelectObject(dc, GetSysColorPen(i)); - Ellipse(dc, myr.left, myr.top, myr.right, myr.bottom); - SelectObject(dc, hpsave); - SelectObject(dc, hbsave); + SetTextColor(dc, GetSysColor(COLOR_WINDOWTEXT)); + TextOut(dc, rc.left, rc.top, Check, 1); } - - /* FIXME: M$ has a Polygon in the center at relative points: */ - /* 0.476, 0.476 (times SmallDiam, SmallDiam) */ - /* 0.476, 0.525 */ - /* 0.500, 0.500 */ - /* 0.500, 0.499 */ - /* when the button is unchecked. The reason for it is unknown. The */ - /* color is COLOR_BTNHIGHLIGHT, although the Polygon gets painted at */ - /* least 3 times (it looks like a clip-region when you see it happen). */ - /* I do not really see a reason why this should be implemented. If you */ - /* have a good reason, let me know. Maybe this is a quirk in the Marlett */ - /* font. */ + + SetTextColor(dc, GetSysColor(COLOR_WINDOWTEXT)); + SelectObject(dc, hOldFont); return TRUE; } diff --git a/reactos/dll/win32/user32/windows/icon.c b/reactos/dll/win32/user32/windows/icon.c index e4aa3d3315d..b965658019f 100644 --- a/reactos/dll/win32/user32/windows/icon.c +++ b/reactos/dll/win32/user32/windows/icon.c @@ -247,10 +247,10 @@ CreateIconFromResourceEx( if (! fIcon) { wXHotspot = *(WORD*)pbIconBits; - pbIconBits+=sizeof(WORD); + pbIconBits += sizeof(WORD); wYHotspot = *(WORD*)pbIconBits; - pbIconBits+=sizeof(WORD); - cbIconBits-=2*sizeof(WORD); + pbIconBits += sizeof(WORD); + cbIconBits -= 2 * sizeof(WORD); } else { @@ -266,7 +266,7 @@ CreateIconFromResourceEx( } memcpy(SafeIconImage, pbIconBits, cbIconBits); - /* take into acount the origonal height was for both the AND and XOR images */ + /* take into acount the original height was for both the AND and XOR images */ if(fIcon) SafeIconImage->icHeader.biHeight /= 2; @@ -326,7 +326,7 @@ CreateIconIndirect(PICONINFO IconInfo) return (HICON)0; } /* FIXME - does there really *have* to be a color bitmap? monochrome cursors don't have one */ - if(IconInfo->hbmColor && !GetObjectW(IconInfo->hbmColor, sizeof(BITMAP), &ColorBitmap)) + if(/*IconInfo->hbmColor &&*/ !GetObjectW(IconInfo->hbmColor, sizeof(BITMAP), &ColorBitmap)) { return (HICON)0; } @@ -440,35 +440,47 @@ LookupIconIdFromDirectory( PBYTE presbits, BOOL fIcon) { - return LookupIconIdFromDirectoryEx( presbits, fIcon, - fIcon ? GetSystemMetrics(SM_CXICON) : GetSystemMetrics(SM_CXCURSOR), - fIcon ? GetSystemMetrics(SM_CYICON) : GetSystemMetrics(SM_CYCURSOR), LR_DEFAULTCOLOR ); + return LookupIconIdFromDirectoryEx(presbits, + fIcon, + fIcon ? GetSystemMetrics(SM_CXICON) : GetSystemMetrics(SM_CXCURSOR), + fIcon ? GetSystemMetrics(SM_CYICON) : GetSystemMetrics(SM_CYCURSOR), + LR_DEFAULTCOLOR); } -/* Ported from WINE20030408 */ -GRPCURSORICONDIRENTRY* -CURSORICON_FindBestCursor( GRPCURSORICONDIR *dir, int width, int height, int colors) + + + + +/* + * The following macro function accounts for the irregularities of + * accessing cursor and icon resources in files and resource entries. + */ +typedef BOOL +(*fnGetCIEntry)(LPVOID dir, int n, int *width, int *height, int *bits ); + +/********************************************************************** + * CURSORICON_FindBestIcon + * + * Find the icon closest to the requested size and number of colors. + */ +static int +CURSORICON_FindBestIcon(LPVOID dir, + fnGetCIEntry get_entry, + int Width, + int Height, + int ColorBits) { - int i; - GRPCURSORICONDIRENTRY *entry, *bestEntry = NULL; + int i, cx, cy, Bits, BestBits = 0, BestEntry = -1; UINT iTotalDiff, iXDiff=0, iYDiff=0, iColorDiff; UINT iTempXDiff, iTempYDiff, iTempColorDiff; - if (dir->idCount < 1) - { - DPRINT("Empty directory!\n"); - return NULL; - } - if (dir->idCount == 1) - return &dir->idEntries[0]; /* No choice... */ - /* Find Best Fit */ iTotalDiff = 0xFFFFFFFF; iColorDiff = 0xFFFFFFFF; - for (i = 0, entry = &dir->idEntries[0]; i < dir->idCount; i++,entry++) + for (i = 0; get_entry(dir, i, &cx, &cy, &Bits); i++ ) { - iTempXDiff = abs(width - entry->ResInfo.icon.bWidth); - iTempYDiff = abs(height - entry->ResInfo.icon.bHeight); + iTempXDiff = abs(Width - cx); + iTempYDiff = abs(Height - cy); if(iTotalDiff > (iTempXDiff + iTempYDiff)) { @@ -479,118 +491,194 @@ CURSORICON_FindBestCursor( GRPCURSORICONDIR *dir, int width, int height, int col } /* Find Best Colors for Best Fit */ - for (i = 0, entry = &dir->idEntries[0]; i < dir->idCount; i++,entry++) + for (i = 0; get_entry(dir, i, &cx, &cy, &Bits); i++ ) { - if(abs(width - entry->ResInfo.icon.bWidth) == (int) iXDiff && - abs(height - entry->ResInfo.icon.bHeight) == (int) iYDiff) + if(abs(Width - cx) == iXDiff && abs(Height - cy) == iYDiff) { - iTempColorDiff = abs(colors - entry->ResInfo.icon.bColorCount); - - if(iColorDiff > iTempColorDiff) - { - bestEntry = entry; - iColorDiff = iTempColorDiff; - } - } - } - - return bestEntry; -} - -/* Ported from WINE20030408 */ -GRPCURSORICONDIRENTRY* -CURSORICON_FindBestIcon( GRPCURSORICONDIR *dir, int width, int height, int colorbits) -{ - int i; - GRPCURSORICONDIRENTRY *entry, *bestEntry = NULL; - UINT iTotalDiff, iXDiff=0, iYDiff=0, iColorDiff; - UINT iTempXDiff, iTempYDiff, iTempColorDiff; - - if (dir->idCount < 1) - { - DPRINT("Empty directory!\n"); - return NULL; - } - if (dir->idCount == 1) - return &dir->idEntries[0]; /* No choice... */ - - /* Find Best Fit */ - iTotalDiff = 0xFFFFFFFF; - iColorDiff = 0xFFFFFFFF; - for (i = 0, entry = &dir->idEntries[0]; i < dir->idCount; i++,entry++) - { - iTempXDiff = abs(width - entry->ResInfo.icon.bWidth); - - iTempYDiff = abs(height - entry->ResInfo.icon.bHeight); - - if(iTotalDiff > (iTempXDiff + iTempYDiff)) - { - iXDiff = iTempXDiff; - iYDiff = iTempYDiff; - iTotalDiff = iXDiff + iYDiff; - } - } - - /* Find Best Colors for Best Fit */ - for (i = 0, entry = &dir->idEntries[0]; i < dir->idCount; i++,entry++) - { - if(abs(width - entry->ResInfo.icon.bWidth) == (int) iXDiff && - abs(height - entry->ResInfo.icon.bHeight) == (int) iYDiff) - { - iTempColorDiff = abs(colorbits - entry->wBitCount); + iTempColorDiff = abs(ColorBits - Bits); if(iColorDiff > iTempColorDiff) { - bestEntry = entry; + BestEntry = i; + BestBits = Bits; iColorDiff = iTempColorDiff; } } } - return bestEntry; + DPRINT("Best Icon: ResId: %d, bits : %d\n", BestEntry, BestBits); + + return BestEntry; } -/* Ported from WINE20030408 */ -/* - * @implemented + + +/********************************************************************** + * CURSORICON_FindBestCursor + * + * Find the cursor closest to the requested size. + * FIXME: parameter 'color' ignored and entries with more than 1 bpp + * ignored too */ -INT STDCALL -LookupIconIdFromDirectoryEx( - PBYTE presbits, - BOOL fIcon, - int cxDesired, - int cyDesired, - UINT Flags) +static int +CURSORICON_FindBestCursor(LPVOID dir, + fnGetCIEntry get_entry, + int Width, + int Height, + int ColorBits) { - GRPCURSORICONDIR *dir = (GRPCURSORICONDIR*)presbits; - UINT retVal = 0; + int i, cx, cy, Bits, BestBits = 0, BestEntry = -1; + UINT iTotalDiff, iXDiff=0, iYDiff=0, iColorDiff; + UINT iTempXDiff, iTempYDiff, iTempColorDiff; - if (dir && !dir->idReserved && (IMAGE_ICON == dir->idType || IMAGE_CURSOR == dir->idType)) - { - GRPCURSORICONDIRENTRY *entry; - HDC hdc; - int ColorBits; + /* Find Best Fit */ + iTotalDiff = 0xFFFFFFFF; + iColorDiff = 0xFFFFFFFF; + for (i = 0; get_entry(dir, i, &cx, &cy, &Bits); i++ ) + { + iTempXDiff = abs(Width - cx); + iTempYDiff = abs(Height - cy); - hdc = CreateICW(NULL, NULL, NULL, NULL); - if (Flags & LR_MONOCHROME) - { - ColorBits = 1; - } - else - { - ColorBits = GetDeviceCaps(hdc, BITSPIXEL); - if (ColorBits > 8) - ColorBits = 8; - } - DeleteDC(hdc); + if(iTotalDiff > (iTempXDiff + iTempYDiff)) + { + iXDiff = iTempXDiff; + iYDiff = iTempYDiff; + iTotalDiff = iXDiff + iYDiff; + } + } - entry = CURSORICON_FindBestIcon( dir, cxDesired, cyDesired, ColorBits ); + /* Find Best Colors for Best Fit */ + for (i = 0; get_entry(dir, i, &cx, &cy, &Bits); i++ ) + { + if(abs(Width - cx) == iXDiff && abs(Height - cy) == iYDiff) + { + iTempColorDiff = abs(ColorBits - Bits); + if(iColorDiff > iTempColorDiff) + { + BestEntry = i; + BestBits = Bits; + iColorDiff = iTempColorDiff; + } + } + } - if (entry) - retVal = entry->nID; - } - else - { - DbgPrint("invalid resource directory\n"); - } - return retVal; + DPRINT("Best Cursor: ResId: %d, bits : %d\n", BestEntry, BestBits); + + return BestEntry; +} + + +static BOOL +CURSORICON_GetResIconEntry(LPVOID dir, + int n, + int *Width, + int *Height, + int *Bits) +{ + GRPCURSORICONDIR *ResDir = dir; + ICONRESDIR *Icon; + + if (ResDir->idCount <= n) + return FALSE; + + Icon = &ResDir->idEntries[n].ResInfo.icon; + *Width = Icon->bWidth; + *Height = Icon->bHeight; + *Bits = ResDir->idEntries[n].wBitCount; + return TRUE; +} + +static BOOL +CURSORICON_GetResCursorEntry(LPVOID dir, + int n, + int *Width, + int *Height, + int *Bits) +{ + GRPCURSORICONDIR *ResDir = dir; + CURSORRESDIR *Cursor; + + if (ResDir->idCount <= n) + return FALSE; + + Cursor = &ResDir->idEntries[n].ResInfo.cursor; + *Width = Cursor->wWidth; + *Height = Cursor->wHeight; + *Bits = ResDir->idEntries[n].wBitCount; + return TRUE; +} + +static GRPCURSORICONDIRENTRY * +CURSORICON_FindBestIconRes(GRPCURSORICONDIR * dir, + int Width, + int Height, + int ColorBits) +{ + int n; + n = CURSORICON_FindBestIcon(dir, + CURSORICON_GetResIconEntry, + Width, + Height, + ColorBits); + if (n < 0) + return NULL; + + return &dir->idEntries[n]; +} + +static GRPCURSORICONDIRENTRY * +CURSORICON_FindBestCursorRes(GRPCURSORICONDIR *dir, + int Width, + int Height, + int ColorBits) +{ + int n; + n = CURSORICON_FindBestCursor(dir, + CURSORICON_GetResCursorEntry, + Width, + Height, + ColorBits); + if (n < 0) + return NULL; + + return &dir->idEntries[n]; +} + + +INT WINAPI +LookupIconIdFromDirectoryEx(PBYTE xdir, + BOOL bIcon, + INT width, + INT height, + UINT cFlag) +{ + GRPCURSORICONDIR *dir = (GRPCURSORICONDIR*)xdir; + UINT retVal = 0; + if(dir && !dir->idReserved && (IMAGE_ICON == dir->idType || IMAGE_CURSOR == dir->idType)) + { + GRPCURSORICONDIRENTRY *entry = NULL; + int ColorBits; + + if (cFlag & LR_MONOCHROME) + { + ColorBits = 1; + } + else + { + HDC hdc = CreateICW(NULL, NULL, NULL, NULL); + ColorBits = GetDeviceCaps(hdc, BITSPIXEL); + DeleteDC(hdc); + } + + if(bIcon) + entry = CURSORICON_FindBestIconRes(dir, width, height, ColorBits); + else + entry = CURSORICON_FindBestCursorRes(dir, width, height, 1); + + if (entry) + retVal = entry->nID; + } + else + DPRINT1("%s() : Invalid resource directory\n", __FUNCTION__); + + return retVal; }