From 6a079bc1f092f865c9fd5ef37f207ab5e525c1b1 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Thu, 3 Apr 2008 02:50:15 +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/trunk@52987 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/gbsizer.h | 1 + src/common/gbsizer.cpp | 93 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) 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