comctl32: toolbar: copy bitmaps with CopyImage so that it works also
for DIBs (based on a patch by Oleg Krylov, fixes bug #1715)
Mikołaj Zalewski
mikolaj at zalewski.pl
Tue Feb 6 16:12:46 CST 2007
If the user passes a DIB to TB_ADDBITMAP, the current code to copy
bitmaps will fail. There were patches that improved that code to handle
DIBs
(http://www.winehq.org/pipermail/wine-patches/2006-July/029085.html) but
they weren't accepted. My patch uses the standard CopyImage from user32
to achive that goal.
-------------- next part --------------
From 315dd61ea469c03df1f1d021eec8a67a3e4bce07 Mon Sep 17 00:00:00 2001
From: =?utf-8?q?Miko=C5=82aj_Zalewski?= <mikolaj at zalewski.pl>
Date: Tue, 6 Feb 2007 17:53:57 +0100
Subject: [PATCH] comctl32: toolbar: copy bitmaps with CopyImage so that it works also for DIBs (based on a patch by Oleg Krylov, fixes bug #1715)
---
dlls/comctl32/toolbar.c | 82 ++++++----------------------------------------
1 files changed, 11 insertions(+), 71 deletions(-)
diff --git a/dlls/comctl32/toolbar.c b/dlls/comctl32/toolbar.c
index 2dca16e..a60bf09 100644
--- a/dlls/comctl32/toolbar.c
+++ b/dlls/comctl32/toolbar.c
@@ -2664,33 +2664,7 @@ TOOLBAR_AddBitmapToImageList(TOOLBAR_INFO *infoPtr, HIMAGELIST himlDef, const TB
TRACE("adding hInst=%p nID=%d nButtons=%d\n", bitmap->hInst, bitmap->nID, bitmap->nButtons);
/* Add bitmaps to the default image list */
if (bitmap->hInst == NULL) /* a handle was passed */
- {
- BITMAP bmp;
- HBITMAP hOldBitmapBitmap, hOldBitmapLoad;
- HDC hdcImage, hdcBitmap;
-
- /* copy the bitmap before adding it so that the user's bitmap
- * doesn't get modified.
- */
- GetObjectW ((HBITMAP)bitmap->nID, sizeof(BITMAP), (LPVOID)&bmp);
-
- hdcImage = CreateCompatibleDC(0);
- hdcBitmap = CreateCompatibleDC(0);
-
- /* create new bitmap */
- hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
- hOldBitmapBitmap = SelectObject(hdcBitmap, (HBITMAP)bitmap->nID);
- hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
-
- /* Copy the user's image */
- BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
- hdcBitmap, 0, 0, SRCCOPY);
-
- SelectObject (hdcImage, hOldBitmapLoad);
- SelectObject (hdcBitmap, hOldBitmapBitmap);
- DeleteDC (hdcImage);
- DeleteDC (hdcBitmap);
- }
+ hbmLoad = (HBITMAP)CopyImage((HBITMAP)bitmap->nID, IMAGE_BITMAP, 0, 0, 0);
else
hbmLoad = CreateMappedBitmap(bitmap->hInst, bitmap->nID, 0, NULL, 0);
@@ -4175,7 +4149,6 @@ TOOLBAR_ReplaceBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
LPTBREPLACEBITMAP lpReplace = (LPTBREPLACEBITMAP) lParam;
HBITMAP hBitmap;
- HBITMAP hbmLoad = NULL;
int i = 0, nOldButtons = 0, pos = 0;
int nOldBitmaps, nNewBitmaps = 0;
HIMAGELIST himlDef = 0;
@@ -4192,16 +4165,6 @@ TOOLBAR_ReplaceBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
else if (lpReplace->hInstOld != 0)
FIXME("resources not in the current module not implemented\n");
- if (lpReplace->hInstNew)
- {
- hbmLoad = LoadBitmapW(lpReplace->hInstNew,(LPWSTR)lpReplace->nIDNew);
- hBitmap = hbmLoad;
- }
- else
- {
- hBitmap = (HBITMAP) lpReplace->nIDNew;
- }
-
TRACE("To be replaced hInstOld %p nIDOld %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
for (i = 0; i < infoPtr->nNumBitmapInfos; i++) {
TBITMAP_INFO *tbi = &infoPtr->bitmaps[i];
@@ -4222,11 +4185,17 @@ TOOLBAR_ReplaceBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
if (nOldButtons == 0)
{
WARN("No hinst/bitmap found! hInst %p nID %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
- if (hbmLoad)
- DeleteObject (hbmLoad);
return FALSE;
}
+ /* copy the bitmap before adding it as ImageList_AddMasked modifies the
+ * bitmap
+ */
+ if (lpReplace->hInstNew)
+ hBitmap = LoadBitmapW(lpReplace->hInstNew,(LPWSTR)lpReplace->nIDNew);
+ else
+ hBitmap = CopyImage((HBITMAP)lpReplace->nIDNew, IMAGE_BITMAP, 0, 0, 0);
+
himlDef = GETDEFIMAGELIST(infoPtr, 0); /* fixme: correct? */
nOldBitmaps = ImageList_GetImageCount(himlDef);
@@ -4237,35 +4206,9 @@ TOOLBAR_ReplaceBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
if (hBitmap)
{
- BITMAP bmp;
- HBITMAP hOldBitmapBitmap, hOldBitmapLoad, hbmLoad;
- HDC hdcImage, hdcBitmap;
-
- /* copy the bitmap before adding it so that the user's bitmap
- * doesn't get modified.
- */
- GetObjectW (hBitmap, sizeof(BITMAP), (LPVOID)&bmp);
-
- hdcImage = CreateCompatibleDC(0);
- hdcBitmap = CreateCompatibleDC(0);
-
- /* create new bitmap */
- hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
- hOldBitmapBitmap = SelectObject(hdcBitmap, hBitmap);
- hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
-
- /* Copy the user's image */
- BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
- hdcBitmap, 0, 0, SRCCOPY);
-
- SelectObject (hdcImage, hOldBitmapLoad);
- SelectObject (hdcBitmap, hOldBitmapBitmap);
- DeleteDC (hdcImage);
- DeleteDC (hdcBitmap);
-
- ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
+ ImageList_AddMasked (himlDef, hBitmap, comctl32_color.clrBtnFace);
nNewBitmaps = ImageList_GetImageCount(himlDef);
- DeleteObject (hbmLoad);
+ DeleteObject(hBitmap);
}
infoPtr->nNumBitmaps = infoPtr->nNumBitmaps - nOldBitmaps + nNewBitmaps;
@@ -4274,9 +4217,6 @@ TOOLBAR_ReplaceBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
pos, nOldBitmaps, nNewBitmaps);
InvalidateRect(hwnd, NULL, TRUE);
-
- if (hbmLoad)
- DeleteObject (hbmLoad);
return TRUE;
}
--
1.4.4.2
More information about the wine-patches
mailing list