diff --git a/src/msw/toolbar.cpp b/src/msw/toolbar.cpp index 3e5e55d2c1..3dbff0f32b 100644 --- a/src/msw/toolbar.cpp +++ b/src/msw/toolbar.cpp @@ -1317,11 +1317,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 ) @@ -1344,7 +1350,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(); @@ -1564,6 +1570,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(); } @@ -1894,6 +1920,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;