diff --git a/dlls/comctl32/tests/toolbar.c b/dlls/comctl32/tests/toolbar.c index 7b9697e0cd4..daa8d5b0153 100644 --- a/dlls/comctl32/tests/toolbar.c +++ b/dlls/comctl32/tests/toolbar.c @@ -37,6 +37,10 @@ BOOL g_fBlockHotItemChange; BOOL g_fReceivedHotItemChange; BOOL g_fExpectedHotItemOld; BOOL g_fExpectedHotItemNew; + +#define check_rect(name, val, exp) ok(val.top == exp.top && val.bottom == exp.bottom && \ + val.left == exp.left && val.right == exp.right, "invalid rect (" name ") (%d,%d) (%d,%d) - expected (%d,%d) (%d,%d)\n", \ + val.left, val.top, val.right, val.bottom, exp.left, exp.top, exp.right, exp.bottom); #define compare(val, exp, format) ok((val) == (exp), #val " value " format " expected " format "\n", (val), (exp)); @@ -140,6 +144,7 @@ static void rebuild_toolbar(HWND *hToolbar) ok(*hToolbar != NULL, "Toolbar creation problem\n"); ok(SendMessage(*hToolbar, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0) == 0, "TB_BUTTONSTRUCTSIZE failed\n"); ok(SendMessage(*hToolbar, TB_AUTOSIZE, 0, 0) == 0, "TB_AUTOSIZE failed\n"); + ok(SendMessage(*hToolbar, WM_SETFONT, (WPARAM)GetStockObject(SYSTEM_FONT), 0)==1, "WM_SETFONT\n"); } void rebuild_toolbar_with_buttons(HWND *hToolbar) @@ -151,18 +156,23 @@ void rebuild_toolbar_with_buttons(HWND *hToolbar) buttons[0].idCommand = 1; buttons[0].fsStyle = BTNS_BUTTON; buttons[0].fsState = TBSTATE_ENABLED; + buttons[0].iString = -1; buttons[1].idCommand = 3; buttons[1].fsStyle = BTNS_BUTTON; buttons[1].fsState = TBSTATE_ENABLED; + buttons[1].iString = -1; buttons[2].idCommand = 5; buttons[2].fsStyle = BTNS_SEP; buttons[2].fsState = TBSTATE_ENABLED; + buttons[2].iString = -1; buttons[3].idCommand = 7; buttons[3].fsStyle = BTNS_BUTTON; buttons[3].fsState = TBSTATE_ENABLED; + buttons[3].iString = -1; buttons[4].idCommand = 9; buttons[4].fsStyle = BTNS_BUTTON; buttons[4].fsState = 0; /* disabled */ + buttons[4].iString = -1; ok(SendMessage(*hToolbar, TB_ADDBUTTONS, 5, (LPARAM)buttons) == 1, "TB_ADDBUTTONS failed\n"); ok(SendMessage(*hToolbar, TB_AUTOSIZE, 0, 0) == 0, "TB_AUTOSIZE failed\n"); } @@ -431,6 +441,8 @@ void test_add_string() CHECK_STRING_TABLE(14, ret7); SendMessageA(hToolbar, TB_ADDBUTTONSA, 1, (LPARAM)&button); CHECK_STRING_TABLE(14, ret7); + + DestroyWindow(hToolbar); } static void expect_hot_notify(int idold, int idnew) @@ -534,6 +546,317 @@ void test_hotitem() ok(ret == 1, "TB_SETHOTITEM returned %ld, expected 1\n", ret); ok(g_fReceivedHotItemChange == FALSE, "Unexpected TBN_HOTITEMCHANGE\n"); + DestroyWindow(hToolbar); +} + +#if 0 /* use this to generate more tests*/ + +void dump_sizes(HWND hToolbar) +{ + SIZE sz; + RECT r; + int count = SendMessage(hToolbar, TB_BUTTONCOUNT, 0, 0); + int i; + + GetClientRect(hToolbar, &r); + SendMessageA(hToolbar, TB_GETMAXSIZE, 0, &sz); + printf(" { {%d, %d, %d, %d}, {%d, %d}, %d, {", r.left, r.top, r.right, r.bottom, + sz.cx, sz.cy, count); + for (i=0; ircClient);*/ \ + buttonCount = SendMessage(hToolbar, TB_BUTTONCOUNT, 0, 0); \ + compare(buttonCount, res->nButtons, "%d"); \ + for (i=0; inButtons); i++) { \ + ok(SendMessageA(hToolbar, TB_GETITEMRECT, i, (LPARAM)&rc) == 1, "TB_GETITEMRECT\n"); \ + if (!(mask&1)) { \ + check_rect("button", rc, res->rcButtons[i]); \ + } else {\ + todo_wine { check_rect("button", rc, res->rcButtons[i]); } \ + } \ + mask >>= 1; \ + } \ + tbsize_numtests++; \ + } + +#define check_sizes() check_sizes_todo(0) + +#endif + +TBBUTTON buttons1[] = { + {0, 10, TBSTATE_WRAP|TBSTATE_ENABLED, 0, {0, }, 0, -1}, + {0, 11, 0, 0, {0, }, 0, -1}, +}; +TBBUTTON buttons2[] = { + {0, 20, TBSTATE_ENABLED, 0, {0, }, 0, -1}, + {0, 21, TBSTATE_ENABLED, 0, {0, }, 0, -1}, +}; +TBBUTTON buttons3[] = { + {0, 30, TBSTATE_ENABLED, 0, {0, }, 0, 0}, + {0, 31, TBSTATE_ENABLED, 0, {0, }, 0, 1}, + {0, 32, TBSTATE_ENABLED, BTNS_AUTOSIZE, {0, }, 0, 1}, + {0, 33, TBSTATE_ENABLED, BTNS_AUTOSIZE, {0, }, 0, (UINT_PTR)"Tst"} +}; + +void test_sizes() +{ + HWND hToolbar = NULL; + int style; + int i; + + rebuild_toolbar_with_buttons(&hToolbar); + style = GetWindowLong(hToolbar, GWL_STYLE); + ok(style == (WS_CHILD|WS_VISIBLE|CCS_TOP), "Invalid style %x\n", style); + check_sizes(); + /* the TBSTATE_WRAP makes a second row */ + SendMessageA(hToolbar, TB_ADDBUTTONS, 2, (LPARAM)buttons1); + check_sizes(); + SendMessageA(hToolbar, TB_AUTOSIZE, 0, 0); + check_sizes(); + /* after setting the TBSTYLE_WRAPABLE the TBSTATE_WRAP is ignored */ + SetWindowLong(hToolbar, GWL_STYLE, style|TBSTYLE_WRAPABLE); + check_sizes(); + /* adding new buttons with TBSTYLE_WRAPABLE doesn't add a new row */ + SendMessageA(hToolbar, TB_ADDBUTTONS, 2, (LPARAM)buttons1); + check_sizes(); + /* only after adding enough buttons the bar will be wrapped on a + * separator and then on the first button */ + for (i=0; i<15; i++) + SendMessageA(hToolbar, TB_ADDBUTTONS, 2, (LPARAM)buttons1); + check_sizes_todo(0x4); + + rebuild_toolbar_with_buttons(&hToolbar); + SendMessageA(hToolbar, TB_ADDBUTTONS, 2, (LPARAM)buttons1); + /* setting the buttons vertical will only change the window client size */ + SetWindowLong(hToolbar, GWL_STYLE, style | CCS_VERT); + SendMessage(hToolbar, TB_AUTOSIZE, 0, 0); + check_sizes_todo(0x3c); + /* with a TBSTYLE_WRAPABLE a wrapping will occure on the separator */ + SetWindowLong(hToolbar, GWL_STYLE, style | TBSTYLE_WRAPABLE | CCS_VERT); + SendMessage(hToolbar, TB_AUTOSIZE, 0, 0); + check_sizes_todo(0x7c); + + rebuild_toolbar_with_buttons(&hToolbar); + SendMessageA(hToolbar, TB_ADDBUTTONS, 2, (LPARAM)buttons1); + /* a TB_SETBITMAPSIZE changes button sizes*/ + SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(24, 24)); + check_sizes(); + + /* setting a TBSTYLE_FLAT doesn't change anything - even after a TB_AUTOSIZE */ + SetWindowLong(hToolbar, GWL_STYLE, style | TBSTYLE_FLAT); + SendMessageA(hToolbar, TB_AUTOSIZE, 0, 0); + check_sizes(); + /* but after a TB_SETBITMAPSIZE the top margins is changed */ + SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(20, 20)); + SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(24, 24)); + check_sizes(); + /* some vertical toolbar sizes */ + SetWindowLong(hToolbar, GWL_STYLE, style | TBSTYLE_FLAT | TBSTYLE_WRAPABLE | CCS_VERT); + check_sizes_todo(0x7c); + + rebuild_toolbar_with_buttons(&hToolbar); + SetWindowLong(hToolbar, GWL_STYLE, style | TBSTYLE_FLAT); + /* newly added buttons will be use the previous margin */ + SendMessageA(hToolbar, TB_ADDBUTTONS, 2, (LPARAM)buttons2); + check_sizes(); + /* TB_SETBUTTONSIZE can't be used to reduce the size of a button below the default */ + ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(23, 22), "Unexpected button size\n"); + ok(SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(22, 21))==1, "TB_SETBUTTONSIZE\n"); + ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(23, 22), "Unexpected button size\n"); + ok(SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(5, 100))==1, "TB_SETBUTTONSIZE\n"); + ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(23, 100), "Unexpected button size\n"); + ok(SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(3, 3))==1, "TB_SETBUTTONSIZE\n"); + ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(23, 22), "Unexpected button size\n"); + ok(SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(5, 100))==1, "TB_SETBUTTONSIZE\n"); + ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(23, 100), "Unexpected button size\n"); + check_sizes(); + /* add some buttons with non-default sizes */ + SendMessageA(hToolbar, TB_ADDBUTTONS, 2, (LPARAM)buttons2); + SendMessageA(hToolbar, TB_INSERTBUTTON, -1, (LPARAM)&buttons2[0]); + check_sizes(); + SendMessageA(hToolbar, TB_ADDBUTTONS, 1, (LPARAM)&buttons3[0]); + /* TB_ADDSTRING resets the size */ + SendMessageA(hToolbar, TB_ADDSTRING, 0, (LPARAM)"A\0MMMMMMMMMMMMM\0"); + ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(23, 39), "Unexpected button size\n"); + check_sizes(); + /* TB_SETBUTTONSIZE can be used to crop the text */ + SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(3, 3)); + ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(23, 22), "Unexpected button size\n"); + check_sizes(); + /* except for the first size, the default size is bitmap size + padding */ + SendMessageA(hToolbar, TB_SETPADDING, 0, MAKELONG(1, 1)); + SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(3, 3)); + ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(17, 17), "Unexpected button size\n"); + SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(3, 3)); + SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(3, 3)); + ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(4, 4), "Unexpected button size\n"); + + rebuild_toolbar(&hToolbar); + /* sending a TB_SETBITMAPSIZE with the same sizes is enough to make the button smaller */ + 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"); + + rebuild_toolbar(&hToolbar); + SendMessageA(hToolbar, TB_ADDSTRINGA, 0, (LPARAM)"A\0MMMMMMMMMMMMM\0"); + /* the height is increased after a TB_ADDSTRING */ + ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(23, 39), "Unexpected button size\n"); + SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(100, 100)); + /* if a string is in the pool, even adding a button without a string resets the size */ + SendMessageA(hToolbar, TB_ADDBUTTONS, 1, (LPARAM)&buttons2[0]); + ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(23, 22), "Unexpected button size\n"); + SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(100, 100)); + /* an BTNS_AUTOSIZE button is also considered when computing the new size */ + SendMessageA(hToolbar, TB_ADDBUTTONS, 1, (LPARAM)&buttons3[2]); + ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(163, 39), "Unexpected button size\n"); + SendMessageA(hToolbar, TB_ADDBUTTONS, 1, (LPARAM)&buttons3[0]); + check_sizes(); + /* delete button doesn't change the buttons size */ + SendMessageA(hToolbar, TB_DELETEBUTTON, 2, 0); + SendMessageA(hToolbar, TB_DELETEBUTTON, 1, 0); + ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(163, 39), "Unexpected button size"); + /* TB_INSERTBUTTONS will */ + SendMessageA(hToolbar, TB_INSERTBUTTON, 1, (LPARAM)&buttons2[0]); + ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(23, 22), "Unexpected button size"); + + rebuild_toolbar(&hToolbar); + 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); + ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(27, 39), "Unexpected button size\n"); + + DestroyWindow(hToolbar); } START_TEST(toolbar) @@ -565,6 +888,7 @@ START_TEST(toolbar) test_add_bitmap(); test_add_string(); test_hotitem(); + test_sizes(); PostQuitMessage(0); while(GetMessageA(&msg,0,0,0)) {