X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/be2577e4e650993fe49f18955972e5360840dad2..55dfa8d3eadbcad32bb7a779f10286dd49b60ce1:/src/common/sizer.cpp diff --git a/src/common/sizer.cpp b/src/common/sizer.cpp index ea20ee7168..1acfd70e61 100644 --- a/src/common/sizer.cpp +++ b/src/common/sizer.cpp @@ -23,6 +23,7 @@ #include "wx/sizer.h" #include "wx/utils.h" #include "wx/statbox.h" +#include "wx/notebook.h" //--------------------------------------------------------------------------- @@ -30,6 +31,9 @@ IMPLEMENT_ABSTRACT_CLASS(wxSizerItem, wxObject); IMPLEMENT_ABSTRACT_CLASS(wxSizer, wxObject); IMPLEMENT_ABSTRACT_CLASS(wxBoxSizer, wxSizer); IMPLEMENT_ABSTRACT_CLASS(wxStaticBoxSizer, wxBoxSizer); +#if wxUSE_NOTEBOOK +IMPLEMENT_ABSTRACT_CLASS(wxNotebookSizer, wxSizer); +#endif //--------------------------------------------------------------------------- // wxSizerItem @@ -202,7 +206,7 @@ void wxSizerItem::SetDimension( wxPoint pos, wxSize size ) m_sizer->SetDimension( pos.x, pos.y, size.x, size.y ); if (IsWindow()) - m_window->SetSize( pos.x, pos.y, size.x, size.y ); + m_window->SetSize( pos.x, pos.y, size.x, size.y, wxSIZE_ALLOW_MINUS_ONE ); m_size = size; } @@ -265,6 +269,21 @@ void wxSizer::Prepend( int width, int height, int option, int flag, int border, m_children.Insert( new wxSizerItem( width, height, option, flag, border, userData ) ); } +void wxSizer::Insert( int before, wxWindow *window, int option, int flag, int border, wxObject* userData ) +{ + m_children.Insert( before, new wxSizerItem( window, option, flag, border, userData ) ); +} + +void wxSizer::Insert( int before, wxSizer *sizer, int option, int flag, int border, wxObject* userData ) +{ + m_children.Insert( before, new wxSizerItem( sizer, option, flag, border, userData ) ); +} + +void wxSizer::Insert( int before, int width, int height, int option, int flag, int border, wxObject* userData ) +{ + m_children.Insert( before, new wxSizerItem( width, height, option, flag, border, userData ) ); +} + bool wxSizer::Remove( wxWindow *window ) { wxASSERT( window ); @@ -273,11 +292,11 @@ bool wxSizer::Remove( wxWindow *window ) while (node) { wxSizerItem *item = (wxSizerItem*)node->Data(); - if (item->GetWindow() == window) - { + if (item->GetWindow() == window) + { m_children.DeleteNode( node ); - return TRUE; - } + return TRUE; + } node = node->Next(); } @@ -292,11 +311,11 @@ bool wxSizer::Remove( wxSizer *sizer ) while (node) { wxSizerItem *item = (wxSizerItem*)node->Data(); - if (item->GetSizer() == sizer) - { + if (item->GetSizer() == sizer) + { m_children.DeleteNode( node ); - return TRUE; - } + return TRUE; + } node = node->Next(); } @@ -371,12 +390,12 @@ void wxBoxSizer::RecalcSizes() { delta = (m_size.x - m_fixedWidth) / m_stretchable; extra = (m_size.x - m_fixedWidth) % m_stretchable; - } - else - { + } + else + { delta = (m_size.y - m_fixedHeight) / m_stretchable; extra = (m_size.y - m_fixedHeight) % m_stretchable; - } + } } wxPoint pt( m_position ); @@ -386,71 +405,71 @@ void wxBoxSizer::RecalcSizes() { wxSizerItem *item = (wxSizerItem*) node->Data(); - int weight = 1; - if (item->GetOption()) - weight = item->GetOption(); + int weight = 1; + if (item->GetOption()) + weight = item->GetOption(); - wxSize size( item->CalcMin() ); + wxSize size( item->CalcMin() ); - if (m_orient == wxVERTICAL) - { - long height = size.y; - if (item->GetOption()) + if (m_orient == wxVERTICAL) { - height = (delta * weight) + extra; - extra = 0; // only the first item will get the remainder as extra size + wxCoord 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() & (wxEXPAND | wxSHAPED)) + child_size.x = m_size.x; + else if (item->GetFlag() & wxALIGN_RIGHT) + child_pos.x += m_size.x - size.x; + else if (item->GetFlag() & (wxCENTER | wxALIGN_CENTER_HORIZONTAL)) + // XXX wxCENTER is added for backward compatibility; + // wxALIGN_CENTER should be used in new code + child_pos.x += (m_size.x - size.x) / 2; + + item->SetDimension( child_pos, child_size ); + + pt.y += height; } - - wxPoint child_pos( pt ); - wxSize child_size( wxSize( size.x, height) ); - - if (item->GetFlag() & (wxEXPAND | wxSHAPED)) - child_size.x = m_size.x; - else if (item->GetFlag() & wxALIGN_RIGHT) - child_pos.x += m_size.x - size.x; - else if (item->GetFlag() & (wxCENTER | wxALIGN_CENTER_HORIZONTAL)) - // XXX wxCENTER is added for backward compatibility; - // wxALIGN_CENTER should be used in new code - child_pos.x += (m_size.x - size.x) / 2; - - item->SetDimension( child_pos, child_size ); - - pt.y += height; - } - else - { - long width = size.x; - if (item->GetOption()) + else { - width = (delta * weight) + extra; - extra = 0; // only the first item will get the remainder as extra size + wxCoord 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() & (wxEXPAND | wxSHAPED)) + child_size.y = m_size.y; + else if (item->GetFlag() & wxALIGN_BOTTOM) + child_pos.y += m_size.y - size.y; + else if (item->GetFlag() & (wxCENTER | wxALIGN_CENTER_VERTICAL)) + // XXX wxCENTER is added for backward compatibility; + // wxALIGN_CENTER should be used in new code + child_pos.y += (m_size.y - size.y) / 2; + + item->SetDimension( child_pos, child_size ); + + pt.x += width; } - wxPoint child_pos( pt ); - wxSize child_size( wxSize(width, size.y) ); - - if (item->GetFlag() & (wxEXPAND | wxSHAPED)) - child_size.y = m_size.y; - else if (item->GetFlag() & wxALIGN_BOTTOM) - child_pos.y += m_size.y - size.y; - else if (item->GetFlag() & (wxCENTER | wxALIGN_CENTER_VERTICAL)) - // XXX wxCENTER is added for backward compatibility; - // wxALIGN_CENTER should be used in new code - child_pos.y += (m_size.y - size.y) / 2; - - item->SetDimension( child_pos, child_size ); - - pt.x += width; - } - - node = node->Next(); + node = node->Next(); } } wxSize wxBoxSizer::CalcMin() { if (m_children.GetCount() == 0) - return wxSize(2,2); + return wxSize(10,10); m_stretchable = 0; m_minWidth = 0; @@ -463,42 +482,42 @@ wxSize wxBoxSizer::CalcMin() { 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) + int weight = 1; + if (item->GetOption()) + weight = item->GetOption(); + + wxSize size( item->CalcMin() ); + + if (m_orient == wxHORIZONTAL) { - m_fixedHeight += size.y; - m_fixedWidth = wxMax( m_fixedWidth, size.x ); + m_minWidth += (size.x * weight); + m_minHeight = wxMax( m_minHeight, size.y ); } else { - m_fixedWidth += size.x; - m_fixedHeight = wxMax( m_fixedHeight, size.y ); + m_minHeight += (size.y * weight); + m_minWidth = wxMax( m_minWidth, size.x ); } - } - node = node->Next(); + 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 ); @@ -542,16 +561,81 @@ void wxStaticBoxSizer::RecalcSizes() wxSize wxStaticBoxSizer::CalcMin() { - // this will have to be done platform by platform + // This will have to be done platform by platform // as there is no way to guess the thickness of - // a wxStaticBox border + // 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.x += 2*other_border; ret.y += other_border + top_border; return ret; } + +//--------------------------------------------------------------------------- +// wxNotebookSizer +//--------------------------------------------------------------------------- + +#if wxUSE_NOTEBOOK + +wxNotebookSizer::wxNotebookSizer( wxNotebook *nb ) +{ + wxASSERT_MSG( nb, wxT("wxNotebookSizer needs a notebook") ); + + m_notebook = nb; +} + +void wxNotebookSizer::RecalcSizes() +{ + m_notebook->SetSize( m_position.x, m_position.y, m_size.x, m_size.y ); +} + +wxSize wxNotebookSizer::CalcMin() +{ + // This will have to be done platform by platform + // as there is no way to guess the thickness of + // the wxNotebook tabs and border. + + int borderX = 5; + int borderY = 5; + if ((m_notebook->HasFlag(wxNB_RIGHT)) || + (m_notebook->HasFlag(wxNB_LEFT))) + { + borderX += 70; // improvements later.. + } + else + { + borderY += 35; // improvements later.. + } + + if (m_notebook->GetChildren().GetCount() == 0) + return wxSize(borderX + 10, borderY + 10); + + int maxX = 0; + int maxY = 0; + + wxWindowList::Node *node = m_notebook->GetChildren().GetFirst(); + while (node) + { + wxWindow *item = node->GetData(); + wxSizer *itemsizer = item->GetSizer(); + + if (itemsizer) + { + wxSize subsize( itemsizer->CalcMin() ); + + if (subsize.x > maxX) maxX = subsize.x; + if (subsize.y > maxY) maxY = subsize.y; + } + + node = node->GetNext(); + } + + return wxSize( borderX + maxX, borderY + maxY ); +} + +#endif // wxUSE_NOTEBOOK