comctl32: toolbar: TB_SETIMAGELIST should try to preserve button width (fixes bug #8393)

Mikołaj Zalewski mikolaj at zalewski.pl
Tue May 15 11:55:37 CDT 2007


-------------- next part --------------
From 7fedea94ca76bd33628365266170864fe34069de Mon Sep 17 00:00:00 2001
From: =?utf-8?q?Miko=C5=82aj_Zalewski?= <mikolaj at zalewski.pl>
Date: Tue, 15 May 2007 18:54:03 +0200
Subject: [PATCH] comctl32: toolbar: TB_SETIMAGELIST should try to preserve button width (fixes bug #8393)

---
 dlls/comctl32/tests/toolbar.c |   38 ++++++++++++++++++++++++++++++++++++++
 dlls/comctl32/toolbar.c       |    3 +++
 2 files changed, 41 insertions(+), 0 deletions(-)

diff --git a/dlls/comctl32/tests/toolbar.c b/dlls/comctl32/tests/toolbar.c
index e2d5095..f997b61 100644
--- a/dlls/comctl32/tests/toolbar.c
+++ b/dlls/comctl32/tests/toolbar.c
@@ -678,6 +678,14 @@ static tbsize_result_t tbsize_results[] =
   { {0, 0, 672, 26}, {489, 39}, 3, {
     {  0,   2, 163,  41}, {163,   2, 330,  41}, {330,   2, 493,  41},
   }, },
+  { {0, 0, 672, 104}, {978, 24}, 6, {
+    {  0,   2, 163,  26}, {163,   2, 326,  26}, {326,   2, 489,  26},
+    {489,   2, 652,  26}, {652,   2, 819,  26}, {819,   2, 850,  26},
+  }, },
+  { {0, 0, 672, 28}, {978, 38}, 6, {
+    {  0,   0, 163,  38}, {163,   0, 326,  38}, {326,   0, 489,  38},
+    {489,   0, 652,  38}, {652,   0, 819,  38}, {819,   0, 850,  38},
+  }, },
 };
 
 static int tbsize_numtests = 0;
@@ -725,6 +733,7 @@ static TBBUTTON buttons3[] = {
 static void test_sizes(void)
 {
     HWND hToolbar = NULL;
+    HIMAGELIST himl;
     int style;
     int i;
 
@@ -855,7 +864,36 @@ static void test_sizes(void)
     ok(SendMessageA(hToolbar, TB_SETSTATE, 20, TBSTATE_ENABLED), "TB_SETSTATE failed\n");
     ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(23, 22), "Unexpected button size\n");
 
+    /* TB_SETIMAGELIST always changes the height but the width only if necessary */
+    SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(100, 100));
+    himl = ImageList_LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP_80x15), 20, 2, CLR_NONE, IMAGE_BITMAP, LR_DEFAULTCOLOR);
+    ok(SendMessageA(hToolbar, TB_SETIMAGELIST, 0, (LPARAM)himl) == 0, "TB_SETIMAGELIST failed\n");
+    ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(100, 21), "Unexpected button size\n");
+    SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(100, 100));
+    ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(100, 100), "Unexpected button size\n");
+    SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(1, 1));
+    ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(27, 21), "Unexpected button size\n");
+    ok(SendMessageA(hToolbar, TB_SETIMAGELIST, 0, 0) == (LRESULT)himl, "TB_SETIMAGELIST failed\n");
+    ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(27, 7), "Unexpected button size\n");
+    SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(1, 1));
+    ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(8, 7), "Unexpected button size\n");
+    ok(SendMessageA(hToolbar, TB_SETIMAGELIST, 0, (LPARAM)himl) == 0, "TB_SETIMAGELIST failed\n");
+    ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(27, 21), "Unexpected button size\n");
+    /* the text is taken into account */
+    SendMessageA(hToolbar, TB_ADDSTRINGA, 0, (LPARAM)"A\0MMMMMMMMMMMMM\0");
+    SendMessageA(hToolbar, TB_ADDBUTTONS, 4, (LPARAM)buttons3);
+    ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(163, 38), "Unexpected button size\n");
+    ok(SendMessageA(hToolbar, TB_SETIMAGELIST, 0, 0) == (LRESULT)himl, "TB_SETIMAGELIST failed\n");
+    ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(163, 24), "Unexpected button size\n");
+    /* the style change also comes into effect */
+    check_sizes();
+    SetWindowLong(hToolbar, GWL_STYLE, GetWindowLong(hToolbar, GWL_STYLE) | TBSTYLE_FLAT);
+    ok(SendMessageA(hToolbar, TB_SETIMAGELIST, 0, (LPARAM)himl) == 0, "TB_SETIMAGELIST failed\n");
+    check_sizes_todo(0x30);     /* some small problems with BTNS_AUTOSIZE button sizes */
+
     rebuild_toolbar(&hToolbar);
+    ImageList_Destroy(himl);
+
     SendMessageA(hToolbar, TB_ADDBUTTONS, 1, (LPARAM)&buttons3[3]);
     ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(27, 39), "Unexpected button size\n");
     SendMessageA(hToolbar, TB_DELETEBUTTON, 0, 0);
diff --git a/dlls/comctl32/toolbar.c b/dlls/comctl32/toolbar.c
index 89037c4..9be48ea 100644
--- a/dlls/comctl32/toolbar.c
+++ b/dlls/comctl32/toolbar.c
@@ -4791,6 +4791,7 @@ TOOLBAR_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
     TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
     HIMAGELIST himlTemp;
     HIMAGELIST himl = (HIMAGELIST)lParam;
+    INT oldButtonWidth = infoPtr->nButtonWidth;
     INT i, id = 0;
 
     if (infoPtr->iVersion >= 5)
@@ -4810,6 +4811,8 @@ TOOLBAR_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
         infoPtr->nBitmapHeight = 1;
     }
     TOOLBAR_CalcToolbar(hwnd);
+    if (infoPtr->nButtonWidth < oldButtonWidth)
+        TOOLBAR_SetButtonSize(hwnd, 0, MAKELONG(oldButtonWidth, infoPtr->nButtonHeight));
 
     TRACE("hwnd %p, new himl=%p, id = %d, count=%d, bitmap w=%d, h=%d\n",
 	  hwnd, infoPtr->himlDef, id, infoPtr->nNumBitmaps,
-- 
1.4.4.2


More information about the wine-patches mailing list