From b23effe8305ea94602e8b249b1806c402fa7b869 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Thu, 3 Apr 2008 02:45:07 +0000 Subject: [PATCH] Fix for potential layout glitches in wxGridBagSizer when items span cells but some other item affects the size of one of spanned rows/cols. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@52986 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/gbsizer.h | 3 ++ src/common/gbsizer.cpp | 93 ++++++++++++++++++++++++++++++++++++++++++ version-script.in | 1 + 3 files changed, 97 insertions(+) diff --git a/include/wx/gbsizer.h b/include/wx/gbsizer.h index 6ceeb9311f..23cf11388e 100644 --- a/include/wx/gbsizer.h +++ b/include/wx/gbsizer.h @@ -286,6 +286,9 @@ public: protected: wxGBPosition FindEmptyCell(); +#if wxABI_VERSION >= 20808 + void AdjustForOverflow(); +#endif wxSize m_emptyCellSize; diff --git a/src/common/gbsizer.cpp b/src/common/gbsizer.cpp index 37840ba6e6..9e50c7aea4 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