+//---------------------------------------------------------------------------
+// wxBoxSizer
+//---------------------------------------------------------------------------
+
+wxBoxSizer::wxBoxSizer( int orient )
+{
+ m_orient = orient;
+}
+
+void wxBoxSizer::RecalcSizes()
+{
+ if (m_children.GetCount() == 0)
+ return;
+
+ int delta = 0;
+ int extra = 0;
+ if (m_stretchable)
+ {
+ if (m_orient == wxHORIZONTAL)
+ {
+ delta = (m_size.x - m_fixedWidth) / m_stretchable;
+ extra = (m_size.x - m_fixedWidth) % m_stretchable;
+ }
+ else
+ {
+ delta = (m_size.y - m_fixedHeight) / m_stretchable;
+ extra = (m_size.y - m_fixedHeight) % m_stretchable;
+ }
+ }
+
+ wxPoint pt( m_position );
+
+ wxNode *node = m_children.GetFirst();
+ while (node)
+ {
+ wxSizerItem *item = (wxSizerItem*) node->Data();
+
+ int weight = 1;
+ if (item->GetOption())
+ weight = item->GetOption();
+
+ wxSize size( item->CalcMin() );
+
+ if (m_orient == wxVERTICAL)
+ {
+ long height = size.y;
+ if (item->GetOption())
+ {
+ height = (delta * weight) + extra;
+ extra = 0; // only the first item will get the remainder as extra size
+ }
+
+ wxPoint child_pos( pt );
+ wxSize child_size( wxSize( size.x, height) );
+
+ if (item->GetFlag() & wxALIGN_RIGHT)
+ child_pos.x += m_size.x - size.x;
+ else if (item->GetFlag() & wxCENTER)
+ child_pos.x += (m_size.x - size.x) / 2;
+ else if (item->GetFlag() & wxEXPAND)
+ child_size.x = m_size.x;
+
+ item->SetDimension( child_pos, child_size );
+
+ pt.y += height;
+ }
+ else
+ {
+ long width = size.x;
+ if (item->GetOption())
+ {
+ width = (delta * weight) + extra;
+ extra = 0; // only the first item will get the remainder as extra size
+ }
+
+ wxPoint child_pos( pt );
+ wxSize child_size( wxSize(width, size.y) );
+
+ if (item->GetFlag() & wxALIGN_BOTTOM)
+ child_pos.y += m_size.y - size.y;
+ else if (item->GetFlag() & wxCENTER)
+ child_pos.y += (m_size.y - size.y) / 2;
+ else if (item->GetFlag() & wxEXPAND)
+ child_size.y = m_size.y;
+
+ item->SetDimension( child_pos, child_size );
+
+ pt.x += width;
+ }
+
+ node = node->Next();
+ }
+}
+
+wxSize wxBoxSizer::CalcMin()
+{
+ if (m_children.GetCount() == 0)
+ return wxSize(2,2);
+
+ m_stretchable = 0;
+ m_minWidth = 0;
+ m_minHeight = 0;
+ m_fixedWidth = 0;
+ m_fixedHeight = 0;
+
+ wxNode *node = m_children.GetFirst();
+ while (node)
+ {
+ wxSizerItem *item = (wxSizerItem*) node->Data();
+
+ int weight = 1;
+ if (item->GetOption())
+ weight = item->GetOption();
+
+ wxSize size( item->CalcMin() );
+
+ if (m_orient == wxHORIZONTAL)
+ {
+ m_minWidth += (size.x * weight);
+ m_minHeight = wxMax( m_minHeight, size.y );
+ }
+ else
+ {
+ m_minHeight += (size.y * weight);
+ m_minWidth = wxMax( m_minWidth, size.x );
+ }
+
+ if (item->GetOption())
+ {
+ m_stretchable += weight;
+ }
+ else
+ {
+ if (m_orient == wxVERTICAL)
+ {
+ m_fixedHeight += size.y;
+ m_fixedWidth = wxMax( m_fixedWidth, size.x );
+ }
+ else
+ {
+ m_fixedWidth += size.x;
+ m_fixedHeight = wxMax( m_fixedHeight, size.y );
+ }
+ }
+
+ node = node->Next();
+ }
+
+ return wxSize( m_minWidth, m_minHeight );
+}
+
+//---------------------------------------------------------------------------
+// wxStaticBoxSizer
+//---------------------------------------------------------------------------
+
+wxStaticBoxSizer::wxStaticBoxSizer( wxStaticBox *box, int orient )
+ : wxBoxSizer( orient )
+{
+ wxASSERT_MSG( box, wxT("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;
+}