comctl32: toolbar[3/8]: fix buttons heights (fixes the last item in bug #4947)

Mikołaj Zalewski mikolaj at zalewski.pl
Wed Nov 1 15:57:31 CST 2006


The one pixel of space between the bitmap and string should be included 
only if there is a string. Also by defaults the toolbar has a 16x15 
imagelist but treats it as 16x16 when computing the button sizes. (it 
seems to be a hack for default bitmaps and not a part of a bigger 
mechanism). Theoretically this could be split into two patches but 
applying only one of them would break the default button sizes.

Changing the nButtonWidth in TOOLBAR_Create is currently a no-op as it's 
overwritten by a call to TOOLBAR_CalcToolbar but 23 is the correct value.
-------------- next part --------------
From f84e04859ef580a8ed2394e84b65e70ab6994d7c Mon Sep 17 00:00:00 2001
From: =?utf-8?q?Miko=C5=82aj_Zalewski?= <mikolaj at zalewski.pl>
Date: Wed, 1 Nov 2006 21:35:31 +0100
Subject: [PATCH] comctl32: toolbar: fix buttons heights (fixes the last item in bug #4947)

---
 dlls/comctl32/toolbar.c |   19 +++++++++++++------
 1 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/dlls/comctl32/toolbar.c b/dlls/comctl32/toolbar.c
index 2024314..22ba6c9 100644
--- a/dlls/comctl32/toolbar.c
+++ b/dlls/comctl32/toolbar.c
@@ -125,6 +125,7 @@ typedef struct
     INT      nButtonHeight;
     INT      nButtonWidth;
     INT      nBitmapHeight;
+    INT      nVBitmapHeight;  /* see TOOLBAR_Create for an explanation */
     INT      nBitmapWidth;
     INT      nIndent;
     INT      nRows;           /* number of button rows */
@@ -1553,7 +1554,7 @@ static inline SIZE TOOLBAR_MeasureButton
     if (infoPtr->dwStyle & TBSTYLE_LIST)
     {
         /* set button height from bitmap / text height... */
-        sizeButton.cy = max((bHasBitmap ? infoPtr->nBitmapHeight : 0),
+        sizeButton.cy = max((bHasBitmap ? infoPtr->nVBitmapHeight : 0),
             sizeString.cy);
 
         /* ... add on the necessary padding */
@@ -1582,8 +1583,9 @@ static inline SIZE TOOLBAR_MeasureButton
     {
         if (bHasBitmap)
         {
-            sizeButton.cy = infoPtr->nBitmapHeight + 1 +
-                sizeString.cy + DEFPAD_CY;
+            sizeButton.cy = infoPtr->nVBitmapHeight + DEFPAD_CY;
+            if (sizeString.cy > 0)
+                sizeButton.cy += 1 + sizeString.cy;
             sizeButton.cx = infoPtr->szPadding.cx +
                 max(sizeString.cx, infoPtr->nBitmapWidth);
         }
@@ -4472,8 +4474,7 @@ TOOLBAR_SetBitmapSize (HWND hwnd, WPARAM
              LOWORD(lParam), HIWORD(lParam));
 
     infoPtr->nBitmapWidth = (INT)LOWORD(lParam);
-    infoPtr->nBitmapHeight = (INT)HIWORD(lParam);
-
+    infoPtr->nVBitmapHeight = infoPtr->nBitmapHeight = (INT)HIWORD(lParam);
 
     if ((himlDef == infoPtr->himlInt) &&
         (ImageList_GetImageCount(infoPtr->himlInt) == 0))
@@ -4873,6 +4874,7 @@ TOOLBAR_SetImageList (HWND hwnd, WPARAM 
         infoPtr->nBitmapWidth = 1;
         infoPtr->nBitmapHeight = 1;
     }
+    infoPtr->nVBitmapHeight = infoPtr->nBitmapHeight;
 
     TRACE("hwnd %p, new himl=%p, id = %d, count=%d, bitmap w=%d, h=%d\n",
 	  hwnd, infoPtr->himlDef, id, infoPtr->nNumBitmaps,
@@ -5338,10 +5340,15 @@ TOOLBAR_Create (HWND hwnd, WPARAM wParam
     TRACE("hwnd = %p\n", hwnd);
 
     /* initialize info structure */
+    infoPtr->nButtonWidth = 23;
     infoPtr->nButtonHeight = 22;
-    infoPtr->nButtonWidth = 24;
     infoPtr->nBitmapHeight = 15;
     infoPtr->nBitmapWidth = 16;
+    /* By default Windows creates an image list with 16x15 icons but computes the button size as
+     * if the icons were 16x16. That's why we keep infoPtr->nVBitmapHeight. After a call to
+     * TB_SETBITMAPSIZE or TB_SETIMAGELIST the nVBitmapHeight = nBitmapHeight.
+     */
+    infoPtr->nVBitmapHeight = 16;
 
     infoPtr->nMaxTextRows = 1;
     infoPtr->cxMin = -1;
-- 
1.4.2.3


More information about the wine-patches mailing list