void wxGridBagSizer::RecalcSizes() { if (m_children.GetCount() == 0) return; wxPoint pt( GetPosition() ); wxSize sz( GetSize() ); m_rows = m_rowHeights.GetCount(); m_cols = m_colWidths.GetCount(); int idx, width, height; AdjustForGrowables(sz, m_calculatedMinSize, m_rows, m_cols); // Find the start positions on the window of the rows and columns wxArrayInt rowpos; rowpos.Add(0, m_rows); int y = pt.y; for (idx=0; idx < m_rows; idx++) { height = m_rowHeights[idx] + m_vgap; rowpos[idx] = y; y += height; } wxArrayInt colpos; colpos.Add(0, m_cols); int x = pt.x; for (idx=0; idx < m_cols; idx++) { width = m_colWidths[idx] + m_hgap; colpos[idx] = x; x += width; } // Now iterate the children, setting each child's dimensions wxSizerItemList::compatibility_iterator node = m_children.GetFirst(); while (node) { int row, col, endrow, endcol; wxGBSizerItem* item = (wxGBSizerItem*)node->GetData(); item->GetPos(row, col); item->GetEndPos(endrow, endcol); height = 0; for(idx=row; idx <= endrow; idx++) height += m_rowHeights[idx]; height += (endrow - row) * m_vgap; // add a vgap for every row spanned width = 0; for (idx=col; idx <= endcol; idx++) width += m_colWidths[idx]; width += (endcol - col) * m_hgap; // add a hgap for every col spanned SetItemBounds(item, colpos[col], rowpos[row], width, height); node = node->GetNext(); } }
void wxGridBagSizer::RepositionChildren(const wxSize& minSize) { // We can't lay out our elements if we don't have at least a single row and // a single column. Notice that this may happen even if we have some // children but all of them are hidden, so checking for m_children being // non-empty is not enough, see #15475. if ( m_rowHeights.empty() || m_colWidths.empty() ) return; wxPoint pt( GetPosition() ); wxSize sz( GetSize() ); m_rows = m_rowHeights.GetCount(); m_cols = m_colWidths.GetCount(); int idx, width, height; AdjustForGrowables(sz, minSize); // Find the start positions on the window of the rows and columns wxArrayInt rowpos; rowpos.Add(0, m_rows); int y = pt.y; for (idx=0; idx < m_rows; idx++) { height = m_rowHeights[idx] + m_vgap; rowpos[idx] = y; y += height; } wxArrayInt colpos; colpos.Add(0, m_cols); int x = pt.x; for (idx=0; idx < m_cols; idx++) { width = m_colWidths[idx] + m_hgap; colpos[idx] = x; x += width; } // Now iterate the children, setting each child's dimensions wxSizerItemList::compatibility_iterator node = m_children.GetFirst(); while (node) { wxGBSizerItem* item = (wxGBSizerItem*)node->GetData(); if ( item->IsShown() ) { int row, col, endrow, endcol; item->GetPos(row, col); item->GetEndPos(endrow, endcol); height = 0; for(idx=row; idx <= endrow; idx++) height += m_rowHeights[idx]; height += (endrow - row) * m_vgap; // add a vgap for every row spanned width = 0; for (idx=col; idx <= endcol; idx++) width += m_colWidths[idx]; width += (endcol - col) * m_hgap; // add a hgap for every col spanned SetItemBounds(item, colpos[col], rowpos[row], width, height); } node = node->GetNext(); } }