PATCH: Toolbar bitmaps are corrupted

Adam Gundy arg at cyberscience.com
Wed Mar 5 08:36:09 CST 2003


Hi. Adding or replacing bitmaps in the toolbar was corrupting the bitmaps
(all masked pixels were made black). Caused by using ImageList_AddMasked()
without working around its bizarre (but correct!) behaviour.

Cyberscience disclaims all copyright and responsibility... ;-)

Changelog:

        * dlls/comctl32/toolbar.c: Adam Gundy <arg at cyberscience.com>
        TOOLBAR_AddBitmap() and TOOLBAR_ReplaceBitmap() are not supposed
        to modify the bitmap - we call ImageList_AddMasked() which turns
        all masked pixels black. Fixed by making a copy of the
        bitmap to give to ImageList_AddMasked().

diff -u -r wine-20030219/dlls/comctl32/toolbar.c wine-20030219-new/dlls/comctl32/toolbar.c
--- wine-20030219/dlls/comctl32/toolbar.c       Wed Jan  8 21:09:27 2003
+++ wine-20030219-new/dlls/comctl32/toolbar.c   Wed Mar  5 11:02:21 2003
@@ -2227,9 +2227,34 @@
     /* Add bitmaps to the default image list */
     if (lpAddBmp->hInst == NULL)
     {
-       nIndex =
-           ImageList_AddMasked (himlDef, (HBITMAP)lpAddBmp->nID,
-                                CLR_DEFAULT);
+       BITMAP  bmp;
+       HBITMAP hOldBitmapBitmap, hOldBitmapLoad;
+       HDC     hdcImage, hdcBitmap;
+
+       /* copy the bitmap before adding it so that the user's bitmap
+        * doesn't get modified.
+        */
+       GetObjectA ((HBITMAP)lpAddBmp->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)lpAddBmp->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);
+
+       nIndex = ImageList_AddMasked (himlDef, hbmLoad, CLR_DEFAULT);
+       DeleteObject (hbmLoad);
     }
     else if (lpAddBmp->hInst == HINST_COMMCTRL)
     {
@@ -3803,12 +3828,41 @@
     /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
 
 
-       himlDef = GETDEFIMAGELIST(infoPtr, 0);
+    himlDef = GETDEFIMAGELIST(infoPtr, 0);
     for (i = pos + nOldButtons - 1; i >= pos; i--) {
         ImageList_Remove(himlDef, i);
     }
 
-    ImageList_AddMasked(himlDef, hBitmap, CLR_DEFAULT);
+    {
+       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.
+        */
+       GetObjectA (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, CLR_DEFAULT);
+       DeleteObject (hbmLoad);
+    }
 
     InvalidateRect(hwnd, NULL, FALSE);
 


Seeya,
 Adam
--
Real Programmers don't comment their code. If it was hard to write,
it should be hard to read, and even harder to modify.
These are all my own opinions.




More information about the wine-patches mailing list