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.
This commit is contained in:
Vadim Zeitlin
2020-11-15 01:02:09 +01:00
parent f65caa3183
commit bd05aea6c1

View File

@@ -1450,6 +1450,15 @@ void wxToolBar::UpdateStretchableSpacersSize()
const int newSize = --numSpaces ? sizeSpacer : sizeLastSpacer;
if ( newSize != oldSize)
{
// 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() )
{
// Just update in place.
WinStruct<TBBUTTONINFO> tbbi;
tbbi.dwMask = TBIF_BYINDEX | TBIF_SIZE;
tbbi.cx = newSize;
@@ -1458,14 +1467,35 @@ void wxToolBar::UpdateStretchableSpacersSize()
{
wxLogLastError(wxT("TB_SETBUTTONINFO (separator)"));
}
}
else // Vertical case, use the workaround.
{
if ( !::SendMessage(GetHwnd(), TB_DELETEBUTTON, toolIndex, 0) )
{
wxLogLastError(wxT("TB_DELETEBUTTON (separator)"));
}
else
{
// We successfully updated the separator width, move all the
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++;
}