From bd05aea6c1753b780e5f3a49d95d6bd94fb8114d Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 15 Nov 2020 01:02:09 +0100 Subject: [PATCH] Fix stretchable separators in vertical toolbars under MSW This partially reverts 44d732b8a5 (Use TB_SETBUTTONINFO when updating stretchable toolbar separators, 2019-02-24) and restores the behaviour before this commit for the vertical toolbars only, as the new code doesn't work for them, even though like it seems it should (and we don't get any error when using it). Still keep the simpler path for horizontal toolbars, as there doesn't seem to be any problems with it in this case. --- src/msw/toolbar.cpp | 52 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 41 insertions(+), 11 deletions(-) diff --git a/src/msw/toolbar.cpp b/src/msw/toolbar.cpp index 8950c398dc..af6dbc1ca1 100644 --- a/src/msw/toolbar.cpp +++ b/src/msw/toolbar.cpp @@ -1450,21 +1450,51 @@ void wxToolBar::UpdateStretchableSpacersSize() const int newSize = --numSpaces ? sizeSpacer : sizeLastSpacer; if ( newSize != oldSize) { - WinStruct tbbi; - tbbi.dwMask = TBIF_BYINDEX | TBIF_SIZE; - tbbi.cx = newSize; - if ( !::SendMessage(GetHwnd(), TB_SETBUTTONINFO, - toolIndex, (LPARAM)&tbbi) ) + // For horizontal toolbars we can just update the separator in + // place, but for some unknown reason this just doesn't do anything + // in the vertical case, so we have to delete the separator and it + // back with the correct size then. This has its own problems and + // may mess up toolbars idea of its best size, so do this only when + // necessary. + if ( !IsVertical() ) { - wxLogLastError(wxT("TB_SETBUTTONINFO (separator)")); + // Just update in place. + WinStruct tbbi; + tbbi.dwMask = TBIF_BYINDEX | TBIF_SIZE; + tbbi.cx = newSize; + if ( !::SendMessage(GetHwnd(), TB_SETBUTTONINFO, + toolIndex, (LPARAM)&tbbi) ) + { + wxLogLastError(wxT("TB_SETBUTTONINFO (separator)")); + } } - else + else // Vertical case, use the workaround. { - // We successfully updated the separator width, move all the - // controls appearing after it by the corresponding amount - // (which may be positive or negative) - offset += newSize - oldSize; + if ( !::SendMessage(GetHwnd(), TB_DELETEBUTTON, toolIndex, 0) ) + { + wxLogLastError(wxT("TB_DELETEBUTTON (separator)")); + } + else + { + TBBUTTON button; + wxZeroMemory(button); + + button.idCommand = tool->GetId(); + button.iBitmap = newSize; // set separator height + button.fsState = TBSTATE_ENABLED | TBSTATE_WRAP; + button.fsStyle = TBSTYLE_SEP; + if ( !::SendMessage(GetHwnd(), TB_INSERTBUTTON, + toolIndex, (LPARAM)&button) ) + { + wxLogLastError(wxT("TB_INSERTBUTTON (separator)")); + } + } } + + // After updating the separator width, move all the + // controls appearing after it by the corresponding amount + // (which may be positive or negative) + offset += newSize - oldSize; } toolIndex++;