From 797f42699e86a0e4e3468b55f88e7b8e6d06f323 Mon Sep 17 00:00:00 2001 From: Huw Davies Date: Tue, 19 May 2015 12:51:56 +0100 Subject: [PATCH] comctl32: Wrap the buttons inside the toolbar's client rect. The toolbar need not be the same width as the parent. --- dlls/comctl32/tests/toolbar.c | 56 +++++++++++++++++++++++++++++++++++++++++++ dlls/comctl32/toolbar.c | 17 +------------ 2 files changed, 57 insertions(+), 16 deletions(-) diff --git a/dlls/comctl32/tests/toolbar.c b/dlls/comctl32/tests/toolbar.c index 4bbffd31a1d..20412162d1e 100644 --- a/dlls/comctl32/tests/toolbar.c +++ b/dlls/comctl32/tests/toolbar.c @@ -2024,6 +2024,61 @@ static void test_TB_GET_SET_EXTENDEDSTYLE(void) DestroyWindow(hwnd); } +static void test_noresize(void) +{ + HWND wnd; + int i; + TBBUTTON button = {0, 10, TBSTATE_ENABLED, 0, {0, }, 0, -1}; + + wnd = CreateWindowExA(0, TOOLBARCLASSNAMEA, NULL, WS_CHILD | WS_VISIBLE | CCS_NORESIZE | TBSTYLE_WRAPABLE, 0, 0, 100, 20, + hMainWnd, (HMENU)5, GetModuleHandleA(NULL), NULL); + SendMessageA(wnd, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0); + + for (i=0; i<30; i++) + { + button.idCommand = 10 + i; + SendMessageA(wnd, TB_ADDBUTTONSA, 1, (LPARAM)&button); + } + + SendMessageA(wnd, TB_SETSTATE, 10, TBSTATE_WRAP|TBSTATE_ENABLED); + + /* autosize clears the wrap on button 0 */ + SendMessageA(wnd, TB_AUTOSIZE, 0, 0); + for (i=0; i<30; i++) + { + SendMessageA(wnd, TB_GETBUTTON, i, (LPARAM)&button); + if (i % 4 == 3) + ok(button.fsState == (TBSTATE_WRAP|TBSTATE_ENABLED), "%d: got %08x\n", i, button.fsState); + else + ok(button.fsState == TBSTATE_ENABLED, "%d: got %08x\n", i, button.fsState); + } + + /* changing the parent doesn't do anything */ + MoveWindow(hMainWnd, 0,0, 400, 200, FALSE); + for (i=0; i<30; i++) + { + SendMessageA(wnd, TB_GETBUTTON, i, (LPARAM)&button); + if (i % 4 == 3) + ok(button.fsState == (TBSTATE_WRAP|TBSTATE_ENABLED), "%d: got %08x\n", i, button.fsState); + else + ok(button.fsState == TBSTATE_ENABLED, "%d: got %08x\n", i, button.fsState); + } + + /* again nothing here */ + SendMessageA(wnd, TB_AUTOSIZE, 0, 0); + for (i=0; i<30; i++) + { + SendMessageA(wnd, TB_GETBUTTON, i, (LPARAM)&button); + if (i % 4 == 3) + ok(button.fsState == (TBSTATE_WRAP|TBSTATE_ENABLED), "%d: got %08x\n", i, button.fsState); + else + ok(button.fsState == TBSTATE_ENABLED, "%d: got %08x\n", i, button.fsState); + } + + DestroyWindow(wnd); + +} + START_TEST(toolbar) { WNDCLASSA wc; @@ -2066,6 +2121,7 @@ START_TEST(toolbar) test_get_set_style(); test_create(); test_TB_GET_SET_EXTENDEDSTYLE(); + test_noresize(); PostQuitMessage(0); while(GetMessageA(&msg,0,0,0)) { diff --git a/dlls/comctl32/toolbar.c b/dlls/comctl32/toolbar.c index 97d509e8837..9f70063d63f 100644 --- a/dlls/comctl32/toolbar.c +++ b/dlls/comctl32/toolbar.c @@ -1282,7 +1282,6 @@ TOOLBAR_WrapToolbar(TOOLBAR_INFO *infoPtr) { TBUTTON_INFO *btnPtr; INT x, cx, i, j, width; - RECT rc; BOOL bButtonWrap; /* When the toolbar window style is not TBSTYLE_WRAPABLE, */ @@ -1293,21 +1292,7 @@ TOOLBAR_WrapToolbar(TOOLBAR_INFO *infoPtr) btnPtr = infoPtr->buttons; x = infoPtr->nIndent; - - if (GetParent(infoPtr->hwndSelf)) - { - /* this can get the parents width, to know how far we can extend - * this toolbar. We cannot use its height, as there may be multiple - * toolbars in a rebar control - */ - GetClientRect( GetParent(infoPtr->hwndSelf), &rc ); - width = rc.right - rc.left; - } - else - { - GetWindowRect( infoPtr->hwndSelf, &rc ); - width = rc.right - rc.left; - } + width = infoPtr->client_rect.right - infoPtr->client_rect.left; bButtonWrap = FALSE; -- 2.11.4.GIT