[PATCH] comctl32: toolbar: TB_SETBITMAPSIZE should not change a coordinate when passed -1 (with testcase)

Mikołaj Zalewski mikolaj at zalewski.pl
Tue Jul 22 07:29:27 CDT 2008


---
 dlls/comctl32/tests/toolbar.c |   19 +++++++++++++++++++
 dlls/comctl32/toolbar.c       |   34 +++++++++++++++++++++++-----------
 2 files changed, 42 insertions(+), 11 deletions(-)

diff --git a/dlls/comctl32/tests/toolbar.c b/dlls/comctl32/tests/toolbar.c
index 2693025..4b6d3c3 100644
--- a/dlls/comctl32/tests/toolbar.c
+++ b/dlls/comctl32/tests/toolbar.c
@@ -203,6 +203,13 @@ static void rebuild_toolbar_with_buttons(HWND *hToolbar)
     ok(SendMessage(*hToolbar, TB_AUTOSIZE, 0, 0) == 0, "TB_AUTOSIZE failed\n");
 }
 
+static void add_128x15_bitmap(HWND hToolbar, int nCmds)
+{
+    TBADDBITMAP bmp128;
+    bmp128.hInst = GetModuleHandle(NULL);
+    bmp128.nID = IDB_BITMAP_128x15;
+    ok(SendMessageA(hToolbar, TB_ADDBITMAP, nCmds, (LPARAM)&bmp128) == 0, "TB_ADDBITMAP - unexpected return\n");
+}
 
 #define CHECK_IMAGELIST(count, dx, dy) { \
     int cx, cy; \
@@ -854,6 +861,18 @@ static void test_sizes(void)
     ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(23, 22), "Unexpected button size\n");
     SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(16, 15));
     ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(23, 21), "Unexpected button size\n");
+    /* -1 in TB_SETBITMAPSIZE is a special code meaning that the coordinate shouldn't be changed */
+    add_128x15_bitmap(hToolbar, 16);
+    ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(14, -1)), "TB_SETBITMAPSIZE failed\n");
+    compare((int)SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0), MAKELONG(21, 21), "%x");
+    ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(-1, 12)), "TB_SETBITMAPSIZE failed\n");
+    compare((int)SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0), MAKELONG(21, 18), "%x");
+    ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(-1, -1)), "TB_SETBITMAPSIZE failed\n");
+    compare((int)SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0), MAKELONG(21, 18), "%x");
+    /* check the imagelist */
+    InvalidateRect(hToolbar, NULL, TRUE);
+    UpdateWindow(hToolbar);
+    CHECK_IMAGELIST(16, 14, 12);
 
     rebuild_toolbar(&hToolbar);
     SendMessageA(hToolbar, TB_ADDSTRINGA, 0, (LPARAM)"A\0MMMMMMMMMMMMM\0");
diff --git a/dlls/comctl32/toolbar.c b/dlls/comctl32/toolbar.c
index 15e65b3..0beb2c6 100644
--- a/dlls/comctl32/toolbar.c
+++ b/dlls/comctl32/toolbar.c
@@ -4374,26 +4374,38 @@ TOOLBAR_SetBitmapSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
 {
     TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
     HIMAGELIST himlDef = GETDEFIMAGELIST(infoPtr, 0);
+    short width = (short)LOWORD(lParam);
+    short height = (short)HIWORD(lParam);
 
     TRACE("hwnd=%p, wParam=%ld, lParam=%ld\n", hwnd, wParam, lParam);
 
     if (wParam != 0)
         FIXME("wParam is %ld. Perhaps image list index?\n", wParam);
 
-    if (LOWORD(lParam) == 0)
-        lParam = MAKELPARAM(1, HIWORD(lParam));
-
-    if (HIWORD(lParam)==0)
-        lParam = MAKELPARAM(LOWORD(lParam), 1);
+    /* 0 width or height is changed to 1 */
+    if (width == 0)
+        width = 1;
+    if (height == 0)
+        height = 1;
 
     if (infoPtr->nNumButtons > 0)
-        WARN("%d buttons, undoc increase to bitmap size : %d-%d -> %d-%d\n",
-             infoPtr->nNumButtons,
-             infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
-             LOWORD(lParam), HIWORD(lParam));
+        TRACE("%d buttons, undoc change to bitmap size : %d-%d -> %d-%d\n",
+              infoPtr->nNumButtons,
+              infoPtr->nBitmapWidth, infoPtr->nBitmapHeight, width, height);
+
+    if (width < -1 || height < -1)
+    {
+        /* Windows destroys the imagelist and seems to actually use negative
+         * values to compute button sizes */
+        FIXME("Negative bitmap sizes not supported (%d, %d)\n", width, height);
+        return FALSE;
+    }
 
-    infoPtr->nBitmapWidth = (INT)LOWORD(lParam);
-    infoPtr->nBitmapHeight = (INT)HIWORD(lParam);
+    /* width or height of -1 means no change */
+    if (width != -1)
+        infoPtr->nBitmapWidth = width;
+    if (height != -1)
+        infoPtr->nBitmapHeight = height;
 
     if ((himlDef == infoPtr->himlInt) &&
         (ImageList_GetImageCount(infoPtr->himlInt) == 0))
-- 
1.5.4


--------------090508020501000705020302--



More information about the wine-patches mailing list