diff --git a/include/wx/gbsizer.h b/include/wx/gbsizer.h index 2779243f52..3bfa9a1947 100644 --- a/include/wx/gbsizer.h +++ b/include/wx/gbsizer.h @@ -286,6 +286,7 @@ public: protected: wxGBPosition FindEmptyCell(); + void AdjustForOverflow(); wxSize m_emptyCellSize; diff --git a/src/common/gbsizer.cpp b/src/common/gbsizer.cpp index b4b50b2842..7d1faa5fe4 100644 --- a/src/common/gbsizer.cpp +++ b/src/common/gbsizer.cpp @@ -476,6 +476,7 @@ wxSize wxGridBagSizer::CalcMin() node = node->GetNext(); } + AdjustForOverflow(); AdjustForFlexDirection(); // Now traverse the heights and widths arrays calcing the totals, including gaps @@ -561,6 +562,98 @@ void wxGridBagSizer::RecalcSizes() } +// Sometimes CalcMin can result in some rows or cols having too much space in +// them because as it traverses the items it makes some assumptions when +// items span to other cells. But those assumptions can become invalid later +// on when other items are fitted into the same rows or columns that the +// spanning item occupies. This method tries to find those situations and +// fixes them. +void wxGridBagSizer::AdjustForOverflow() +{ + int row, col; + + for (row=0; rowGetEndPos(endrow, endcol); + + // If the item starts in this position and doesn't span rows, then + // just look at the whole item height + if ( item->GetPos() == pos && endrow == row ) + { + int itemHeight = item->GetSize().GetHeight(); + rowExtra = wxMin(rowExtra, rowHeight - itemHeight); + continue; + } + + // Otherwise, only look at spanning items if they end on this row + if ( endrow == row ) + { + // first deduct the portions of the item that are on prior rows + int itemHeight = item->GetSize().GetHeight(); + for (int r=item->GetPos().GetRow(); rGetEndPos(endrow, endcol); + + if ( item->GetPos() == pos && endcol == col ) + { + int itemWidth = item->GetSize().GetWidth(); + colExtra = wxMin(colExtra, colWidth - itemWidth); + continue; + } + + if ( endcol == col ) + { + int itemWidth = item->GetSize().GetWidth(); + for (int c=item->GetPos().GetCol(); c