RESEND comctl32:toolbar: [1/2] Infrastructure CopyBitmap function

Oleg Krylov oleg.krylov at gmail.com
Tue Aug 1 06:37:31 CDT 2006


RESEND: fixed patch line wraps, sorry

This patch makes no changes to code other then adds CopyBitmap function
to avoid duplicate code changes in following patch.
Second patch in this mini series will change this function behavior.


-------------- next part --------------
diff -urN wine/dlls/comctl32/toolbar.c wineNew/dlls/comctl32/toolbar.c
--- wine/dlls/comctl32/toolbar.c	2006-05-23 15:47:38.000000000 +0300
+++ wineNew/dlls/comctl32/toolbar.c	2006-07-27 13:30:09.000000000 +0300
@@ -2567,6 +2567,37 @@
     }
 }
 
+/***********************************************************************
+ * CopyBitmap:  Create a new copy of HBITMAP.
+ *
+ */
+static HBITMAP
+CopyBitmap (HBITMAP hbm)
+{
+    BITMAP  bmp;
+    HBITMAP hOldBitmapBitmap, hOldBitmapLoad, hbmLoad;
+    HDC     hdcImage, hdcBitmap;
+
+    GetObjectW (hbm, 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, hbm);
+    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);
+    return hbmLoad;
+}
 
 /***********************************************************************
  * TOOLBAR_AddBitmap:  Add the bitmaps to the default image list.
@@ -2653,32 +2684,10 @@
     /* Add bitmaps to the default image list */
     if (lpAddBmp->hInst == NULL)
     {
-       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)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);
-
+       hbmLoad = CopyBitmap((HBITMAP)lpAddBmp->nID);
        nIndex = ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
        DeleteObject (hbmLoad);
     }
@@ -4463,32 +4472,12 @@
 
     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);
+       HBITMAP hbmLoad;
 
+       /* copy the bitmap before adding it so that the user's bitmap
+        * doesn't get modified.
+        */
+       hbmLoad = CopyBitmap(hBitmap);
        ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
        nNewBitmaps = ImageList_GetImageCount(himlDef);
        DeleteObject (hbmLoad);




More information about the wine-patches mailing list