From 6fa9ffda8e6e89ad39f1750941859bf2aebf7133 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 9 Mar 2014 20:55:54 +0000 Subject: [PATCH] Disable stretchable spaces in multi-row toolbars in wxMSW. Stretchable separators simply don't work correctly when the space they are supposed to stretch onto is distributed across several different toolbar rows or columns, so just disable them for multi-row (or column, for vertical toolbars) case. See #13579. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_3_0_BRANCH@76104 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/msw/toolbar.cpp | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/src/msw/toolbar.cpp b/src/msw/toolbar.cpp index 00cd5d7d50..81b5772245 100644 --- a/src/msw/toolbar.cpp +++ b/src/msw/toolbar.cpp @@ -1292,11 +1292,17 @@ void wxToolBar::UpdateStretchableSpacersSize() // check if we have any stretchable spacers in the first place unsigned numSpaces = 0; wxToolBarToolsList::compatibility_iterator node; - for ( node = m_tools.GetFirst(); node; node = node->GetNext() ) + int toolIndex = 0; + for ( node = m_tools.GetFirst(); node; node = node->GetNext(), toolIndex++ ) { wxToolBarTool * const tool = (wxToolBarTool*)node->GetData(); if ( tool->IsStretchableSpace() ) - numSpaces++; + { + // Count only enabled items + const RECT rcItem = wxGetTBItemRect(GetHwnd(), toolIndex); + if ( !::IsRectEmpty(&rcItem) ) + numSpaces++; + } } if ( !numSpaces ) @@ -1319,7 +1325,7 @@ void wxToolBar::UpdateStretchableSpacersSize() // move the controls manually ourselves to ensure they remain at the // correct place int offset = 0; - int toolIndex = 0; + toolIndex = 0; for ( node = m_tools.GetFirst(); node; node = node->GetNext(), toolIndex++ ) { wxToolBarTool * const tool = (wxToolBarTool*)node->GetData(); @@ -1518,6 +1524,26 @@ void wxToolBar::SetRows(int nRows) m_maxRows = nRows; + // Enable stretchable spacers only for single-row horizontal toobar or + // single-column vertical toolbar, they don't work correctly when the extra + // space can be redistributed among multiple columns or rows at any moment. + const bool enable = (!IsVertical() && m_maxRows == 1) || + (IsVertical() && (size_t)m_maxRows == m_nButtons); + + const LPARAM state = MAKELONG(enable ? TBSTATE_ENABLED : TBSTATE_HIDDEN, 0); + wxToolBarToolsList::compatibility_iterator node; + for ( node = m_tools.GetFirst(); node; node = node->GetNext() ) + { + wxToolBarTool * const tool = (wxToolBarTool*)node->GetData(); + if ( tool->IsStretchableSpace() ) + { + if ( !::SendMessage(GetHwnd(), TB_SETSTATE, tool->GetId(), state) ) + { + wxLogLastError(wxT("TB_SETSTATE (stretchable spacer)")); + } + } + } + UpdateSize(); } @@ -1848,6 +1874,11 @@ bool wxToolBar::HandlePaint(WXWPARAM wParam, WXLPARAM lParam) // shorter than the full window size (at least under Windows 7) // but we need to erase the full width/height below RECT rcItem = wxGetTBItemRect(GetHwnd(), toolIndex); + + // Skip hidden buttons + if ( ::IsRectEmpty(&rcItem) ) + continue; + if ( IsVertical() ) { rcItem.left = 0;