comctl32[2/2]: toolbar: if wParam in TB_ADDBUTTON is large, enlarge the bitmap before ImageList_AddMasked rather then call ImageList_SetImagesCount after

Mikołaj Zalewski mikolaj at zalewski.pl
Thu Sep 21 15:18:04 CDT 2006


This will make the new images transparent and in the case when the 
bitmap size is not divisible by the icon size we will see the part of 
the last icon (currently we see it too but only because of bugs in our 
ImageList implementation)
-------------- next part --------------
diff --git a/dlls/comctl32/comctl32.h b/dlls/comctl32/comctl32.h
index f6d233f..66a0973 100644
--- a/dlls/comctl32/comctl32.h
+++ b/dlls/comctl32/comctl32.h
@@ -143,6 +143,7 @@ extern COMCTL32_SysColor  comctl32_color
 HWND COMCTL32_CreateToolTip (HWND);
 VOID COMCTL32_RefreshSysColors(void);
 void COMCTL32_DrawInsertMark(HDC hDC, const RECT *lpRect, COLORREF clrInsertMark, BOOL bHorizontal);
+void COMCTL32_EnsureBitmapSize(HBITMAP *pBitmap, int cxMinWidth, int cyMinHeight, COLORREF crBackground);
 INT  Str_GetPtrWtoA (LPCWSTR lpSrc, LPSTR lpDest, INT nMaxLen);
 BOOL Str_SetPtrAtoW (LPWSTR *lppDest, LPCSTR lpSrc);
 BOOL Str_SetPtrWtoA (LPSTR *lppDest, LPCWSTR lpSrc);
diff --git a/dlls/comctl32/commctrl.c b/dlls/comctl32/commctrl.c
index 5cfc24c..81f5f86 100644
--- a/dlls/comctl32/commctrl.c
+++ b/dlls/comctl32/commctrl.c
@@ -1449,6 +1449,67 @@ void COMCTL32_DrawInsertMark(HDC hDC, co
 }
 
 /***********************************************************************
+ * COMCTL32_EnsureBitmapSize [internal]
+ *
+ * If needed enlarge the bitmap so that the width is at least cxMinWidth
+ * the height is at least cyMinHeight. If the bitmap already have these
+ * dimensions nothing changes.
+ *
+ * PARAMS
+ *     hBitmap       [I/O] Bitmap to modify. The handle may change
+ *     cxMinWidth    [I]   If the width of the bitmap is smaller then it will
+ *                         be enlarged to this value
+ *     cyMinHeight   [I]   If the height of the bitmap is smaller then it will
+ *                         be enlarged to this value
+ *     cyBackground  [I]   The color with which the new area will be filled
+ *
+ * RETURNS
+ *     none
+ */
+void COMCTL32_EnsureBitmapSize(HBITMAP *pBitmap, int cxMinWidth, int cyMinHeight, COLORREF crBackground)
+{
+    int cxNew, cyNew;
+    BITMAP bmp;
+    HBITMAP hNewBitmap;
+    HBITMAP hNewDCBitmap, hOldDCBitmap;
+    HBRUSH hNewDCBrush;
+    HDC hdcNew, hdcOld;
+
+    if (!GetObjectW(*pBitmap, sizeof(BITMAP), &bmp))
+        return;
+    cxNew = (cxMinWidth > bmp.bmWidth ? cxMinWidth : bmp.bmWidth);
+    cyNew = (cyMinHeight > bmp.bmHeight ? cyMinHeight : bmp.bmHeight);
+    if (cxNew == bmp.bmWidth && cyNew == bmp.bmHeight)
+        return;
+
+    hdcNew = CreateCompatibleDC(NULL);
+    hNewBitmap = CreateBitmap(cxNew, cyNew, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
+    hNewDCBitmap = SelectObject(hdcNew, hNewBitmap);
+    hNewDCBrush = SelectObject(hdcNew, CreateSolidBrush(crBackground));
+
+    hdcOld = CreateCompatibleDC(NULL);
+    hOldDCBitmap = SelectObject(hdcOld, *pBitmap);
+
+    BitBlt(hdcNew, 0, 0, bmp.bmWidth, bmp.bmHeight, hdcOld, 0, 0, SRCCOPY);
+    if (bmp.bmWidth < cxMinWidth)
+        PatBlt(hdcNew, bmp.bmWidth, 0, cxNew, bmp.bmHeight, PATCOPY);
+    if (bmp.bmHeight < cyMinHeight)
+        PatBlt(hdcNew, 0, bmp.bmHeight, bmp.bmWidth, cyNew, PATCOPY);
+    if (bmp.bmWidth < cxMinWidth && bmp.bmHeight < cyMinHeight)
+        PatBlt(hdcNew, bmp.bmWidth, bmp.bmHeight, cxNew, cyNew, PATCOPY);
+
+    SelectObject(hdcNew, hNewDCBitmap);
+    DeleteObject(SelectObject(hdcNew, hNewDCBrush));
+    DeleteDC(hdcNew);
+    SelectObject(hdcOld, hOldDCBitmap);
+    DeleteDC(hdcOld);
+
+    DeleteObject(*pBitmap);    
+    *pBitmap = hNewBitmap;
+    return;
+}
+
+/***********************************************************************
  * MirrorIcon [COMCTL32.414]
  *
  * Mirrors an icon so that it will appear correctly on a mirrored DC.
diff --git a/dlls/comctl32/toolbar.c b/dlls/comctl32/toolbar.c
index 164a2fe..fe26ac1 100644
--- a/dlls/comctl32/toolbar.c
+++ b/dlls/comctl32/toolbar.c
@@ -2578,6 +2578,7 @@ TOOLBAR_AddBitmapToImageList(TOOLBAR_INF
     HBITMAP hbmLoad;
     INT nCountBefore = ImageList_GetImageCount(himlDef);
     INT nCountAfter;
+    INT cxIcon, cyIcon;
     INT nAdded;
     INT nIndex;
 
@@ -2613,6 +2614,10 @@ TOOLBAR_AddBitmapToImageList(TOOLBAR_INF
     }
     else
         hbmLoad = CreateMappedBitmap(bitmap->hInst, bitmap->nID, 0, NULL, 0);
+
+    /* enlarge the bitmap if needed */
+    ImageList_GetIconSize(himlDef, &cxIcon, &cyIcon);
+    COMCTL32_EnsureBitmapSize(&hbmLoad, cxIcon*(INT)bitmap->nButtons, cyIcon, comctl32_color.clrBtnFace);
     
     nIndex = ImageList_AddMasked(himlDef, hbmLoad, comctl32_color.clrBtnFace);
     DeleteObject(hbmLoad);
@@ -2624,8 +2629,6 @@ TOOLBAR_AddBitmapToImageList(TOOLBAR_INF
     if (bitmap->nButtons == 0) /* wParam == 0 is special and means add only one image */
     {
         ImageList_SetImageCount(himlDef, nCountBefore + 1);
-    } else if (nAdded < (INT)bitmap->nButtons) {    /* if not enough buttons, grow the list */
-        ImageList_SetImageCount(himlDef, nCountBefore + bitmap->nButtons);
     } else if (nAdded > (INT)bitmap->nButtons) {
         TRACE("Added more images than wParam: Previous image number %i added %i while wParam %i. Images in list %i\n",
             nCountBefore, nAdded, bitmap->nButtons, nCountAfter);
-- 
1.4.1


More information about the wine-patches mailing list