diff --git a/src/msw/toolbar.cpp b/src/msw/toolbar.cpp index 56f983086b..3a1c8d66aa 100644 --- a/src/msw/toolbar.cpp +++ b/src/msw/toolbar.cpp @@ -1828,13 +1828,37 @@ bool wxToolBar::HandleSize(WXWPARAM WXUNUSED(wParam), WXLPARAM lParam) // calculate our minor dimension ourselves - we're confusing the standard // logic (TB_AUTOSIZE) with our horizontal toolbars and other hacks - // Find bounding box for any toolbar item. + // Find bounding box for all rows. RECT r; ::SetRectEmpty(&r); + // Bounding box for single (current) row + RECT rcRow; + ::SetRectEmpty(&rcRow); + int rowPosX = INT_MIN; wxToolBarToolsList::compatibility_iterator node; int i = 0; for ( node = m_tools.GetFirst(); node; node = node->GetNext(), i++) { + // Skip hidden buttons + const RECT rcItem = wxGetTBItemRect(GetHwnd(), i); + if ( ::IsRectEmpty(&rcItem) ) + continue; + + if ( rcItem.top > rowPosX ) + { + // We have the next row. + rowPosX = rcItem.top; + + // Shift origin to (0, 0) to make it the same as for the total rect. + ::OffsetRect(&rcRow, -rcRow.left, -rcRow.top); + + // And update the bounding box for all rows. + ::UnionRect(&r, &r, &rcRow); + + // Reset the current row bounding box for the next row. + ::SetRectEmpty(&rcRow); + } + wxToolBarTool * const tool = (wxToolBarTool*)node->GetData(); // Separators shouldn't be taken into account as they are sometimes @@ -1843,12 +1867,15 @@ bool wxToolBar::HandleSize(WXWPARAM WXUNUSED(wParam), WXLPARAM lParam) // any case, so just skip them. if( !tool->IsSeparator() ) { - RECT ritem = wxGetTBItemRect(GetHwnd(), i); - ::OffsetRect(&ritem, -ritem.left, -ritem.top); // Shift origin to (0,0) - ::UnionRect(&r, &r, &ritem); + // Update bounding box of current row + ::UnionRect(&rcRow, &rcRow, &rcItem); } } + // Take into account the last row rectangle too. + ::OffsetRect(&rcRow, -rcRow.left, -rcRow.top); + ::UnionRect(&r, &r, &rcRow); + if ( !r.right ) return false; @@ -1857,10 +1884,6 @@ bool wxToolBar::HandleSize(WXWPARAM WXUNUSED(wParam), WXLPARAM lParam) if ( IsVertical() ) { w = r.right - r.left; - if ( m_maxRows ) - { - w *= (m_nButtons + m_maxRows - 1)/m_maxRows; - } h = HIWORD(lParam); } else