gbsizer.cpp
来自「A*算法 A*算法 A*算法 A*算法A*算法A*算法」· C++ 代码 · 共 695 行 · 第 1/2 页
CPP
695 行
}
bool wxGridBagSizer::SetItemSpan(size_t index, const wxGBSpan& span)
{
wxSizerItemList::compatibility_iterator node = m_children.Item( index );
wxCHECK_MSG( node, false, _T("Failed to find item.") );
wxGBSizerItem* item = (wxGBSizerItem*)node->GetData();
return item->SetSpan(span);
}
wxGBSizerItem* wxGridBagSizer::FindItem(wxWindow* window)
{
wxSizerItemList::compatibility_iterator node = m_children.GetFirst();
while (node)
{
wxGBSizerItem* item = (wxGBSizerItem*)node->GetData();
if ( item->GetWindow() == window )
return item;
node = node->GetNext();
}
return NULL;
}
wxGBSizerItem* wxGridBagSizer::FindItem(wxSizer* sizer)
{
wxSizerItemList::compatibility_iterator node = m_children.GetFirst();
while (node)
{
wxGBSizerItem* item = (wxGBSizerItem*)node->GetData();
if ( item->GetSizer() == sizer )
return item;
node = node->GetNext();
}
return NULL;
}
wxGBSizerItem* wxGridBagSizer::FindItemAtPosition(const wxGBPosition& pos)
{
wxSizerItemList::compatibility_iterator node = m_children.GetFirst();
while (node)
{
wxGBSizerItem* item = (wxGBSizerItem*)node->GetData();
if ( item->Intersects(pos, wxDefaultSpan) )
return item;
node = node->GetNext();
}
return NULL;
}
wxGBSizerItem* wxGridBagSizer::FindItemAtPoint(const wxPoint& pt)
{
wxSizerItemList::compatibility_iterator node = m_children.GetFirst();
while (node)
{
wxGBSizerItem* item = (wxGBSizerItem*)node->GetData();
wxRect rect(item->GetPosition(), item->GetSize());
rect.Inflate(m_hgap, m_vgap);
if ( rect.Inside(pt) )
return item;
node = node->GetNext();
}
return NULL;
}
wxGBSizerItem* wxGridBagSizer::FindItemWithData(const wxObject* userData)
{
wxSizerItemList::compatibility_iterator node = m_children.GetFirst();
while (node)
{
wxGBSizerItem* item = (wxGBSizerItem*)node->GetData();
if ( item->GetUserData() == userData )
return item;
node = node->GetNext();
}
return NULL;
}
//---------------------------------------------------------------------------
// Figure out what all the min row heights and col widths are, and calculate
// min size from that.
wxSize wxGridBagSizer::CalcMin()
{
int idx;
if (m_children.GetCount() == 0)
return m_emptyCellSize;
m_rowHeights.Empty();
m_colWidths.Empty();
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);
// fill heights and widths upto this item if needed
while ( m_rowHeights.GetCount() <= (size_t)endrow )
m_rowHeights.Add(m_emptyCellSize.GetHeight());
while ( m_colWidths.GetCount() <= (size_t)endcol )
m_colWidths.Add(m_emptyCellSize.GetWidth());
// See if this item increases the size of its row(s) or col(s)
wxSize size(item->CalcMin());
for (idx=row; idx <= endrow; idx++)
m_rowHeights[idx] = wxMax(m_rowHeights[idx], size.GetHeight() / (endrow-row+1));
for (idx=col; idx <= endcol; idx++)
m_colWidths[idx] = wxMax(m_colWidths[idx], size.GetWidth() / (endcol-col+1));
}
node = node->GetNext();
}
AdjustForFlexDirection();
// Now traverse the heights and widths arrays calcing the totals, including gaps
int width = 0;
m_cols = m_colWidths.GetCount();
for (idx=0; idx < m_cols; idx++)
width += m_colWidths[idx] + ( idx == m_cols-1 ? 0 : m_hgap );
int height = 0;
m_rows = m_rowHeights.GetCount();
for (idx=0; idx < m_rows; idx++)
height += m_rowHeights[idx] + ( idx == m_rows-1 ? 0 : m_vgap );
m_calculatedMinSize = wxSize(width, height);
return m_calculatedMinSize;
}
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();
}
}
//---------------------------------------------------------------------------
bool wxGridBagSizer::CheckForIntersection(wxGBSizerItem* item, wxGBSizerItem* excludeItem)
{
return CheckForIntersection(item->GetPos(), item->GetSpan(), excludeItem);
}
bool wxGridBagSizer::CheckForIntersection(const wxGBPosition& pos, const wxGBSpan& span, wxGBSizerItem* excludeItem)
{
wxSizerItemList::compatibility_iterator node = m_children.GetFirst();
while (node)
{
wxGBSizerItem* item = (wxGBSizerItem*)node->GetData();
node = node->GetNext();
if ( excludeItem && item == excludeItem )
continue;
if ( item->Intersects(pos, span) )
return true;
}
return false;
}
// Assumes a 10x10 grid, and returns the first empty cell found. This is
// really stupid but it is only used by the Add methods that match the base
// class virtuals, which should normally not be used anyway...
wxGBPosition wxGridBagSizer::FindEmptyCell()
{
int row, col;
for (row=0; row<10; row++)
for (col=0; col<10; col++)
{
wxGBPosition pos(row, col);
if ( !CheckForIntersection(pos, wxDefaultSpan) )
return pos;
}
return wxGBPosition(-1, -1);
}
//---------------------------------------------------------------------------
// The Add base class virtuals should not be used with this class, but
// we'll try to make them automatically select a location for the item
// anyway.
wxSizerItem* wxGridBagSizer::Add( wxWindow *window, int, int flag, int border, wxObject* userData )
{
return Add(window, FindEmptyCell(), wxDefaultSpan, flag, border, userData);
}
wxSizerItem* wxGridBagSizer::Add( wxSizer *sizer, int, int flag, int border, wxObject* userData )
{
return Add(sizer, FindEmptyCell(), wxDefaultSpan, flag, border, userData);
}
wxSizerItem* wxGridBagSizer::Add( int width, int height, int, int flag, int border, wxObject* userData )
{
return Add(width, height, FindEmptyCell(), wxDefaultSpan, flag, border, userData);
}
// The Insert nad Prepend base class virtuals that are not appropriate for
// this class and should not be used. Their implementation in this class
// simply fails.
wxSizerItem* wxGridBagSizer::Add( wxSizerItem * )
{
wxFAIL_MSG(wxT("Invalid Add form called."));
return (wxSizerItem*)NULL;
}
wxSizerItem* wxGridBagSizer::Prepend( wxWindow *, int, int, int, wxObject* )
{
wxFAIL_MSG(wxT("Prepend should not be used with wxGridBagSizer."));
return (wxSizerItem*)NULL;
}
wxSizerItem* wxGridBagSizer::Prepend( wxSizer *, int, int, int, wxObject* )
{
wxFAIL_MSG(wxT("Prepend should not be used with wxGridBagSizer."));
return (wxSizerItem*)NULL;
}
wxSizerItem* wxGridBagSizer::Prepend( int, int, int, int, int, wxObject* )
{
wxFAIL_MSG(wxT("Prepend should not be used with wxGridBagSizer."));
return (wxSizerItem*)NULL;
}
wxSizerItem* wxGridBagSizer::Prepend( wxSizerItem * )
{
wxFAIL_MSG(wxT("Prepend should not be used with wxGridBagSizer."));
return (wxSizerItem*)NULL;
}
wxSizerItem* wxGridBagSizer::Insert( size_t, wxWindow *, int, int, int, wxObject* )
{
wxFAIL_MSG(wxT("Insert should not be used with wxGridBagSizer."));
return (wxSizerItem*)NULL;
}
wxSizerItem* wxGridBagSizer::Insert( size_t, wxSizer *, int, int, int, wxObject* )
{
wxFAIL_MSG(wxT("Insert should not be used with wxGridBagSizer."));
return (wxSizerItem*)NULL;
}
wxSizerItem* wxGridBagSizer::Insert( size_t, int, int, int, int, int, wxObject* )
{
wxFAIL_MSG(wxT("Insert should not be used with wxGridBagSizer."));
return (wxSizerItem*)NULL;
}
wxSizerItem* wxGridBagSizer::Insert( size_t, wxSizerItem * )
{
wxFAIL_MSG(wxT("Insert should not be used with wxGridBagSizer."));
return (wxSizerItem*)NULL;
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?