X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3417c2cd3d5cb05451270b5a09fe2355406158a3..5b4f8dd5c0fe1bf44fb7971c669b036d4ad6eebe:/src/common/sizer.cpp diff --git a/src/common/sizer.cpp b/src/common/sizer.cpp index 9a140fd684..fcac0711a7 100644 --- a/src/common/sizer.cpp +++ b/src/common/sizer.cpp @@ -22,6 +22,7 @@ #include "wx/sizer.h" #include "wx/utils.h" +#include "wx/statbox.h" //--------------------------------------------------------------------------- // wxSizerItem @@ -196,6 +197,69 @@ void wxSizer::Add( int width, int height, int option, int flag, int border ) m_children.Append( new wxSizerItem( width, height, option, flag, border ) ); } +void wxSizer::Prepend( wxWindow *window, int option, int flag, int border ) +{ + m_children.Insert( new wxSizerItem( window, option, flag, border ) ); +} + +void wxSizer::Prepend( wxSizer *sizer, int option, int flag, int border ) +{ + m_children.Insert( new wxSizerItem( sizer, option, flag, border ) ); +} + +void wxSizer::Prepend( int width, int height, int option, int flag, int border ) +{ + m_children.Insert( new wxSizerItem( width, height, option, flag, border ) ); +} + +bool wxSizer::Remove( wxWindow *window ) +{ + wxASSERT( window ); + + wxNode *node = m_children.First(); + while (node) + { + wxSizerItem *item = (wxSizerItem*)node->Data(); + if (item->GetWindow() == window) + { + m_children.DeleteNode( node ); + return TRUE; + } + node = node->Next(); + } + + return FALSE; +} + +bool wxSizer::Remove( wxSizer *sizer ) +{ + wxASSERT( sizer ); + + wxNode *node = m_children.First(); + while (node) + { + wxSizerItem *item = (wxSizerItem*)node->Data(); + if (item->GetSizer() == sizer) + { + m_children.DeleteNode( node ); + return TRUE; + } + node = node->Next(); + } + + return FALSE; +} + +bool wxSizer::Remove( int pos ) +{ + wxNode *node = m_children.Nth( pos ); + if (!node) return FALSE; + + m_children.DeleteNode( node ); + + return TRUE; +} + void wxSizer::Fit( wxWindow *window ) { window->SetSize( GetMinWindowSize( window ) ); @@ -203,7 +267,7 @@ void wxSizer::Fit( wxWindow *window ) void wxSizer::Layout() { - m_size = CalcMin(); + CalcMin(); RecalcSizes(); } @@ -228,25 +292,23 @@ void wxSizer::SetDimension( int x, int y, int width, int height ) m_position.y = y; m_size.x = width; m_size.y = height; + CalcMin(); RecalcSizes(); } //--------------------------------------------------------------------------- -// wxBox +// wxBoxSizer //--------------------------------------------------------------------------- -wxBox::wxBox( int orient ) +wxBoxSizer::wxBoxSizer( int orient ) { m_orient = orient; } -void wxBox::RecalcSizes() +void wxBoxSizer::RecalcSizes() { if (m_children.GetCount() == 0) - { - SetDimension( m_position.x, m_position.y, 2, 2 ); return; - } int delta = 0; int extra = 0; @@ -328,7 +390,7 @@ void wxBox::RecalcSizes() } } -wxSize wxBox::CalcMin() +wxSize wxBoxSizer::CalcMin() { if (m_children.GetCount() == 0) return wxSize(2,2); @@ -384,3 +446,55 @@ wxSize wxBox::CalcMin() return wxSize( m_minWidth, m_minHeight ); } + +//--------------------------------------------------------------------------- +// wxStaticBoxSizer +//--------------------------------------------------------------------------- + +wxStaticBoxSizer::wxStaticBoxSizer( wxStaticBox *box, int orient ) + : wxBoxSizer( orient ) +{ + wxASSERT_MSG( box, _T("wxStaticBoxSizer needs a static box") ); + + m_staticBox = box; +} + +void wxStaticBoxSizer::RecalcSizes() +{ + // this will have to be done platform by platform + // as there is no way to guess the thickness of + // a wxStaticBox border + int top_border = 15; + if (m_staticBox->GetLabel().IsEmpty()) top_border = 5; + int other_border = 5; + + m_staticBox->SetSize( m_position.x, m_position.y, m_size.x, m_size.y ); + + wxPoint old_pos( m_position ); + m_position.x += other_border; + m_position.y += top_border; + wxSize old_size( m_size ); + m_size.x -= 2*other_border; + m_size.y -= top_border + other_border; + + wxBoxSizer::RecalcSizes(); + + m_position = old_pos; + m_size = old_size; +} + +wxSize wxStaticBoxSizer::CalcMin() +{ + // this will have to be done platform by platform + // as there is no way to guess the thickness of + // a wxStaticBox border + int top_border = 15; + if (m_staticBox->GetLabel().IsEmpty()) top_border = 5; + int other_border = 5; + + wxSize ret( wxBoxSizer::CalcMin() ); + ret.x += 2*top_border; + ret.y += other_border + top_border; + + return ret; +}