From 74f21995ca01018e5aa83420bfa232dae58ee558 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 7 Mar 2014 01:19:13 +0000 Subject: [PATCH] Make stretchable spacers work in vertical toolbars too in wxMSW. Replace the old implementation of stretchable spacers based on changing the size of the separators used as spacers as the toolbar size itself changed with a new one, simply replacing the old separator with the new one of the correct size, as it also works for the vertical toolbars, unlike the old approach. Closes #13673. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@76092 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 1 + src/msw/toolbar.cpp | 79 ++++++++++++++++++++++++++++++++------------- 2 files changed, 58 insertions(+), 22 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index eaa1f2a749..04c318080a 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -47,6 +47,7 @@ wxMSW: - Fix handling of selected images in wxBitmapButton (Artur Wieczorek). - Fix loading of bitmap with non-pre-multiplied alpha (Artur Wieczorek). - Support multiline strings in wxDC::DrawRotatedText() (Artur Wieczorek). +- Fix stretchable spacers in vertical toolbars (Artur Wieczorek). wxOSX/Cocoa: diff --git a/src/msw/toolbar.cpp b/src/msw/toolbar.cpp index 959672519b..9a94aed819 100644 --- a/src/msw/toolbar.cpp +++ b/src/msw/toolbar.cpp @@ -1254,19 +1254,34 @@ bool wxToolBar::Realize() InvalidateBestSize(); UpdateSize(); + if ( IsVertical() ) + { + // For vertical toolbar heights of buttons are incorrect + // unless TB_AUTOSIZE in invoked. + // We need to recalculate fixed elements size again. + m_totalFixedSize = 0; + toolIndex = 0; + for ( node = m_tools.GetFirst(); node; node = node->GetNext(), toolIndex++ ) + { + wxToolBarTool * const tool = (wxToolBarTool*)node->GetData(); + if ( !tool->IsStretchableSpace() ) + { + const RECT r = wxGetTBItemRect(GetHwnd(), toolIndex); + if ( !IsVertical() ) + m_totalFixedSize += r.right - r.left; + else if ( !tool->IsControl() ) + m_totalFixedSize += r.bottom - r.top; + } + } + // Enforce invoking UpdateStretchableSpacersSize() with correct value of fixed elements size. + UpdateSize(); + } + return true; } void wxToolBar::UpdateStretchableSpacersSize() { -#ifdef TB_SETBUTTONINFO - // we can't resize the spacers if TB_SETBUTTONINFO is not supported (we - // could try to do it with multiple separators as for the controls but this - // is too painful and it just doesn't seem to be worth doing for the - // ancient systems) - if ( wxApp::GetComCtl32Version() < 471 ) - return; - // check if we have any stretchable spacers in the first place unsigned numSpaces = 0; wxToolBarToolsList::compatibility_iterator node; @@ -1314,23 +1329,38 @@ void wxToolBar::UpdateStretchableSpacersSize() const RECT rcOld = wxGetTBItemRect(GetHwnd(), toolIndex); - WinStruct tbbi; - tbbi.dwMask = TBIF_SIZE; - tbbi.cx = --numSpaces ? sizeSpacer : sizeLastSpacer; + const int oldSize = IsVertical()? (rcOld.bottom - rcOld.top): (rcOld.right - rcOld.left); + const int newSize = --numSpaces ? sizeSpacer : sizeLastSpacer; + if ( newSize != oldSize) + { + if ( !::SendMessage(GetHwnd(), TB_DELETEBUTTON, toolIndex, 0) ) + { + wxLogLastError(wxT("TB_DELETEBUTTON (separator)")); + } + else + { + TBBUTTON button; + wxZeroMemory(button); - if ( !::SendMessage(GetHwnd(), TB_SETBUTTONINFO, - tool->GetId(), (LPARAM)&tbbi) ) - { - wxLogLastError(wxT("TB_SETBUTTONINFO")); - } - else - { - // we successfully resized this one, move all the controls after it - // by the corresponding amount (may be positive or negative) - offset += tbbi.cx - (rcOld.right - rcOld.left); + button.idCommand = tool->GetId(); + button.iBitmap = newSize; // set separator width/height + button.fsState = TBSTATE_ENABLED; + button.fsStyle = TBSTYLE_SEP; + if ( IsVertical() ) + button.fsState |= TBSTATE_WRAP; + if ( !::SendMessage(GetHwnd(), TB_INSERTBUTTON, toolIndex, (LPARAM)&button) ) + { + wxLogLastError(wxT("TB_INSERTBUTTON (separator)")); + } + else + { + // We successfully replaced this seprator, move all the controls after it + // by the corresponding amount (may be positive or negative) + offset += newSize - oldSize; + } + } } } -#endif // TB_SETBUTTONINFO } // ---------------------------------------------------------------------------- @@ -1843,6 +1873,11 @@ bool wxToolBar::HandlePaint(WXWPARAM wParam, WXLPARAM lParam) rcItem.bottom = rectTotal.height; } + // Apparently, regions of height < 3 are not taken into account + // in clipping so we need to extend them for this purpose. + if ( rcItem.bottom - rcItem.top > 0 && rcItem.bottom - rcItem.top < 3 ) + rcItem.bottom = rcItem.top + 3; + rgnDummySeps.Union(wxRectFromRECT(rcItem)); } }