comctl32: Use DrawIconEx to copy icon bits and use the correct background color.

This commit is contained in:
Alexandre Julliard 2011-12-16 14:19:38 +01:00
parent 65b7eb2635
commit 40cf298c75

View File

@ -2531,7 +2531,6 @@ done:
INT WINAPI INT WINAPI
ImageList_ReplaceIcon (HIMAGELIST himl, INT nIndex, HICON hIcon) ImageList_ReplaceIcon (HIMAGELIST himl, INT nIndex, HICON hIcon)
{ {
HDC hdcImage;
HICON hBestFitIcon; HICON hBestFitIcon;
ICONINFO ii; ICONINFO ii;
BITMAP bmp; BITMAP bmp;
@ -2563,23 +2562,6 @@ ImageList_ReplaceIcon (HIMAGELIST himl, INT nIndex, HICON hIcon)
if (!hBestFitIcon) if (!hBestFitIcon)
return -1; return -1;
ret = GetIconInfo (hBestFitIcon, &ii);
if (!ret) {
DestroyIcon(hBestFitIcon);
return -1;
}
ret = GetObjectW (ii.hbmMask, sizeof(BITMAP), &bmp);
if (!ret) {
ERR("couldn't get mask bitmap info\n");
if (ii.hbmColor)
DeleteObject (ii.hbmColor);
if (ii.hbmMask)
DeleteObject (ii.hbmMask);
DestroyIcon(hBestFitIcon);
return -1;
}
if (nIndex == -1) { if (nIndex == -1) {
if (himl->cCurImage + 1 > himl->cMaxImage) if (himl->cCurImage + 1 > himl->cMaxImage)
IMAGELIST_InternalExpandBitmaps(himl, 1); IMAGELIST_InternalExpandBitmaps(himl, 1);
@ -2588,13 +2570,11 @@ ImageList_ReplaceIcon (HIMAGELIST himl, INT nIndex, HICON hIcon)
himl->cCurImage++; himl->cCurImage++;
} }
hdcImage = CreateCompatibleDC (0); if (himl->has_alpha && GetIconInfo (hBestFitIcon, &ii))
TRACE("hdcImage=%p\n", hdcImage);
if (hdcImage == 0)
ERR("invalid hdcImage!\n");
if (himl->has_alpha)
{ {
HDC hdcImage = CreateCompatibleDC( 0 );
GetObjectW (ii.hbmMask, sizeof(BITMAP), &bmp);
if (!ii.hbmColor) if (!ii.hbmColor)
{ {
UINT height = bmp.bmHeight / 2; UINT height = bmp.bmHeight / 2;
@ -2606,48 +2586,38 @@ ImageList_ReplaceIcon (HIMAGELIST himl, INT nIndex, HICON hIcon)
ret = add_with_alpha( himl, hdcImage, nIndex, 1, bmp.bmWidth, height, color, ii.hbmMask ); ret = add_with_alpha( himl, hdcImage, nIndex, 1, bmp.bmWidth, height, color, ii.hbmMask );
DeleteDC( hdcMask ); DeleteDC( hdcMask );
DeleteObject( color ); DeleteObject( color );
if (ret) goto done;
} }
else if (add_with_alpha( himl, hdcImage, nIndex, 1, bmp.bmWidth, bmp.bmHeight, else ret = add_with_alpha( himl, hdcImage, nIndex, 1, bmp.bmWidth, bmp.bmHeight,
ii.hbmColor, ii.hbmMask )) goto done; ii.hbmColor, ii.hbmMask );
DeleteDC( hdcImage );
DeleteObject (ii.hbmMask);
if (ii.hbmColor) DeleteObject (ii.hbmColor);
if (ret) goto done;
} }
imagelist_point_from_index(himl, nIndex, &pt); imagelist_point_from_index(himl, nIndex, &pt);
SetTextColor(himl->hdcImage, RGB(0,0,0)); if (himl->hbmMask)
SetBkColor (himl->hdcImage, RGB(255,255,255));
if (ii.hbmColor)
{ {
SelectObject (hdcImage, ii.hbmColor); DrawIconEx( himl->hdcImage, pt.x, pt.y, hBestFitIcon, himl->cx, himl->cy, 0, 0, DI_IMAGE );
StretchBlt (himl->hdcImage, pt.x, pt.y, himl->cx, himl->cy, PatBlt( himl->hdcMask, pt.x, pt.y, himl->cx, himl->cy, WHITENESS );
hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY); DrawIconEx( himl->hdcMask, pt.x, pt.y, hBestFitIcon, himl->cx, himl->cy, 0, 0, DI_MASK );
if (himl->hbmMask)
{
SelectObject (hdcImage, ii.hbmMask);
StretchBlt (himl->hdcMask, pt.x, pt.y, himl->cx, himl->cy,
hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY);
}
} }
else else
{ {
UINT height = bmp.bmHeight / 2; COLORREF color = himl->clrBk != CLR_NONE ? himl->clrBk : comctl32_color.clrWindow;
SelectObject (hdcImage, ii.hbmMask); HBRUSH brush = CreateSolidBrush( GetNearestColor( himl->hdcImage, color ));
StretchBlt (himl->hdcImage, pt.x, pt.y, himl->cx, himl->cy,
hdcImage, 0, height, bmp.bmWidth, height, SRCCOPY); SelectObject( himl->hdcImage, brush );
if (himl->hbmMask) PatBlt( himl->hdcImage, pt.x, pt.y, himl->cx, himl->cy, PATCOPY );
StretchBlt (himl->hdcMask, pt.x, pt.y, himl->cx, himl->cy, SelectObject( himl->hdcImage, GetStockObject(BLACK_BRUSH) );
hdcImage, 0, 0, bmp.bmWidth, height, SRCCOPY); DeleteObject( brush );
DrawIconEx( himl->hdcImage, pt.x, pt.y, hBestFitIcon, himl->cx, himl->cy, 0, 0, DI_NORMAL );
} }
done: done:
DestroyIcon(hBestFitIcon); DestroyIcon(hBestFitIcon);
if (hdcImage)
DeleteDC (hdcImage);
if (ii.hbmColor)
DeleteObject (ii.hbmColor);
if (ii.hbmMask)
DeleteObject (ii.hbmMask);
TRACE("Insert index = %d, himl->cCurImage = %d\n", nIndex, himl->cCurImage); TRACE("Insert index = %d, himl->cCurImage = %d\n", nIndex, himl->cCurImage);
return nIndex; return nIndex;