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
This commit is contained in:
Robin Dunn 2008-04-03 02:50:15 +00:00
parent d7bf6c20fd
commit 6a079bc1f0
2 changed files with 94 additions and 0 deletions

View File

@ -286,6 +286,7 @@ public:
protected:
wxGBPosition FindEmptyCell();
void AdjustForOverflow();
wxSize m_emptyCellSize;

View File

@ -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; row<m_rowHeights.GetCount(); row++)
{
int rowExtra=INT_MAX;
int rowHeight = m_rowHeights[row];
for (col=0; col<m_colWidths.GetCount(); col++)
{
wxGBPosition pos(row,col);
wxGBSizerItem* item = FindItemAtPosition(pos);
if ( !item )
continue;
int endrow, endcol;
item->GetEndPos(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(); r<row; r++)
itemHeight -= (m_rowHeights[r] + GetHGap());
if ( itemHeight < 0 )
itemHeight = 0;
// and check how much is left
rowExtra = wxMin(rowExtra, rowHeight - itemHeight);
}
}
if ( rowExtra && rowExtra != INT_MAX )
m_rowHeights[row] -= rowExtra;
}
// Now do the same thing for columns
for (col=0; col<m_colWidths.GetCount(); col++)
{
int colExtra=INT_MAX;
int colWidth = m_colWidths[col];
for (row=0; row<m_rowHeights.GetCount(); row++)
{
wxGBPosition pos(row,col);
wxGBSizerItem* item = FindItemAtPosition(pos);
if ( !item )
continue;
int endrow, endcol;
item->GetEndPos(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<col; c++)
itemWidth -= (m_colWidths[c] + GetVGap());
if ( itemWidth < 0 )
itemWidth = 0;
colExtra = wxMin(colExtra, colWidth - itemWidth);
}
}
if ( colExtra && colExtra != INT_MAX )
m_colWidths[col] -= colExtra;
}
}
//---------------------------------------------------------------------------