#include "wx/sizer.h"
#include "wx/utils.h"
#include "wx/statbox.h"
-#include "wx/notebook.h"
#include "wx/listimpl.cpp"
+#if WXWIN_COMPATIBILITY_2_4
+ #include "wx/notebook.h"
+#endif
#ifdef __WXMAC__
# include "wx/mac/uma.h"
#if wxUSE_STATBOX
IMPLEMENT_CLASS(wxStaticBoxSizer, wxBoxSizer)
#endif
-#if wxUSE_BOOKCTRL
-IMPLEMENT_CLASS(wxBookCtrlSizer, wxSizer)
-#if wxUSE_NOTEBOOK
-IMPLEMENT_CLASS(wxNotebookSizer, wxBookCtrlSizer)
-#endif // wxUSE_NOTEBOOK
-#endif // wxUSE_BOOKCTRL
WX_DEFINE_EXPORTED_LIST( wxSizerItemList );
wxSizerItem::wxSizerItem( wxWindow *window, int proportion, int flag, int border, wxObject* userData )
: m_window( window )
, m_sizer( NULL )
- , m_minSize( window->GetSize() ) // minimal size is the initial size
, m_proportion( proportion )
, m_border( border )
, m_flag( flag )
, m_show( true )
, m_userData( userData )
{
+ if (flag & wxFIXED_MINSIZE)
+ window->SetMinSize(window->GetSize());
+ m_minSize = window->GetSize();
+
// aspect ratio calculated from initial size
SetRatio( m_minSize );
wxSize wxSizerItem::CalcMin()
{
- wxSize ret;
if (IsSizer())
{
- ret = m_sizer->GetMinSize();
+ m_minSize = m_sizer->GetMinSize();
// if we have to preserve aspect ratio _AND_ this is
// the first-time calculation, consider ret to be initial size
if ((m_flag & wxSHAPED) && !m_ratio)
- SetRatio(ret);
+ SetRatio(m_minSize);
}
- else
+ else if ( IsWindow() )
{
- if ( IsWindow() && (m_flag & wxADJUST_MINSIZE) )
- {
- // By user request, keep the minimal size for this item
- // in sync with the largest of BestSize and any user supplied
- // minimum size hint. Useful in cases where the item is
- // changeable -- static text labels, etc.
- m_minSize = m_window->GetAdjustedBestSize();
- }
-
- ret = m_minSize;
+ // Since the size of the window may change during runtime, we
+ // should use the current minimal/best size.
+ m_minSize = m_window->GetBestFittingSize();
}
+ return GetMinSizeWithBorder();
+}
+
+wxSize wxSizerItem::GetMinSizeWithBorder() const
+{
+ wxSize ret = m_minSize;
+
if (m_flag & wxWEST)
ret.x += m_border;
if (m_flag & wxEAST)
ret.y += m_border;
if (m_flag & wxSOUTH)
ret.y += m_border;
-
+
return ret;
}
+
void wxSizerItem::SetDimension( wxPoint pos, wxSize size )
{
if (m_flag & wxSHAPED)
void wxSizerItem::DeleteWindows()
{
if (m_window)
+ {
m_window->Destroy();
+ m_window = NULL;
+ }
if (m_sizer)
m_sizer->DeleteWindows();
item->GetWindow()->SetContainingSizer( this );
}
+void wxSizer::AddSpacer(int size)
+{
+ Add(size, size);
+}
+
+void wxSizer::AddStretchSpacer(int prop)
+{
+ Add(0, 0, prop);
+}
+
void wxSizer::Prepend( wxWindow *window, int proportion, int flag, int border, wxObject* userData )
{
m_children.Insert( new wxSizerItem( window, proportion, flag, border, userData ) );
item->GetWindow()->SetContainingSizer( this );
}
+void wxSizer::PrependSpacer(int size)
+{
+ Prepend(size, size);
+}
+
+void wxSizer::PrependStretchSpacer(int prop)
+{
+ Prepend(0, 0, prop);
+}
+
void wxSizer::Insert( size_t index,
wxWindow *window,
int proportion,
item->GetWindow()->SetContainingSizer( this );
}
+void wxSizer::InsertSpacer(size_t index, int size)
+{
+ Insert(index, size, size);
+}
+
+void wxSizer::InsertStretchSpacer(size_t index, int prop)
+{
+ Insert(index, 0, 0, prop);
+}
+
bool wxSizer::Remove( wxWindow *window )
{
return Detach( window );
void wxSizer::Layout()
{
+ // (re)calculates minimums needed for each item and other preparations
+ // for layout
CalcMin();
+
+ // Applies the layout and repositions/resizes the items
RecalcSizes();
}
minSize.y+size.y-client_size.y );
}
+// TODO on mac we need a function that determines how much free space this
+// min size contains, in order to make sure that we have 20 pixels of free
+// space around the controls
+
// Return a window size that will fit within the screens dimensions
wxSize wxSizer::FitSize( wxWindow *window )
{
if (item->GetWindow() == window)
{
- item->SetInitSize( width, height );
+ item->SetMinSize( width, height );
return true;
}
node = node->GetNext();
}
else
{
- // ... but the minimal size of spacers and windows in stored in them
- item->SetInitSize( width, height );
+ // ... but the minimal size of spacers and windows is stored via the item
+ item->SetMinSize( width, height );
}
return true;
void wxGridSizer::SetItemBounds( wxSizerItem *item, int x, int y, int w, int h )
{
wxPoint pt( x,y );
- wxSize sz( item->CalcMin() );
+ wxSize sz( item->GetMinSizeWithBorder() );
int flag = item->GetFlag();
if ((flag & wxEXPAND) || (flag & wxSHAPED))
wxPoint pt( GetPosition() );
wxSize sz( GetSize() );
- wxSize minsz( CalcMin() );
- AdjustForGrowables(sz, minsz, nrows, ncols);
+ AdjustForGrowables(sz, m_calculatedMinSize, nrows, ncols);
sz = wxSize( pt.x + sz.x, pt.y + sz.y );
m_rowHeights.SetCount(nrows);
m_colWidths.SetCount(ncols);
- // We have to recalcuate the sizes in case an item has wxADJUST_MINSIZE, has changed
- // minimum size since the previous layout, or has been hidden using wxSizer::Show().
- // If all the items in a row/column are hidden, the final dimension of the row/column
- // will be -1, indicating that the column itself is hidden.
+ // We have to recalcuate the sizes in case the item minimum size has
+ // changed since the previous layout, or the item has been hidden using
+ // wxSizer::Show(). If all the items in a row/column are hidden, the final
+ // dimension of the row/column will be -1, indicating that the column
+ // itself is hidden.
for( s = m_rowHeights.GetCount(), i = 0; i < s; ++i )
m_rowHeights[ i ] = -1;
for( s = m_colWidths.GetCount(), i = 0; i < s; ++i )
if ( m_rowHeights[ row ] != -1 )
height += m_rowHeights[ row ] + ( row == nrows-1 ? 0 : m_vgap );
- return wxSize( width, height );
+ m_calculatedMinSize = wxSize( width, height );
+ return m_calculatedMinSize;
}
void wxFlexGridSizer::AdjustForFlexDirection()
if (item->IsShown())
{
- wxSize size( item->CalcMin() );
+ wxSize size( item->GetMinSizeWithBorder() );
if (m_orient == wxVERTICAL)
{
m_fixedWidth = 0;
m_fixedHeight = 0;
+ // precalc item minsizes and count proportions
wxSizerItemList::compatibility_iterator node = m_children.GetFirst();
while (node)
{
wxSizerItem *item = node->GetData();
+ if (item->IsShown())
+ item->CalcMin(); // result is stored in the item
+
if (item->IsShown() && item->GetProportion() != 0)
m_stretchable += item->GetProportion();
if (item->IsShown() && item->GetProportion() != 0)
{
int stretch = item->GetProportion();
- wxSize size( item->CalcMin() );
+ wxSize size( item->GetMinSizeWithBorder() );
int minSize;
// Integer division rounded up is (a + b - 1) / b
if (item->IsShown())
{
- wxSize size( item->CalcMin() );
+ wxSize size( item->GetMinSizeWithBorder() );
if (item->GetProportion() != 0)
{
if (m_orient == wxHORIZONTAL)
return ret;
}
+void wxStaticBoxSizer::ShowItems( bool show )
+{
+ m_staticBox->Show( show );
+ wxBoxSizer::ShowItems( show );
+}
+
#endif // wxUSE_STATBOX
+
+#if WXWIN_COMPATIBILITY_2_4
+
// ----------------------------------------------------------------------------
// wxNotebookSizer
// ----------------------------------------------------------------------------
+#if wxUSE_BOOKCTRL
+IMPLEMENT_CLASS(wxBookCtrlSizer, wxSizer)
+#if wxUSE_NOTEBOOK
+IMPLEMENT_CLASS(wxNotebookSizer, wxBookCtrlSizer)
+#endif // wxUSE_NOTEBOOK
+#endif // wxUSE_BOOKCTRL
+
#if wxUSE_BOOKCTRL
wxBookCtrlSizer::wxBookCtrlSizer(wxBookCtrl *bookctrl)
return wxSize( maxX, maxY ) + sizeBorder;
}
-
#if wxUSE_NOTEBOOK
wxNotebookSizer::wxNotebookSizer(wxNotebook *nb)
- : wxBookCtrlSizer(nb)
{
+ wxASSERT_MSG( nb, wxT("wxNotebookSizer needs a control") );
+ m_bookctrl = nb;
}
#endif // wxUSE_NOTEBOOOK
#endif // wxUSE_BOOKCTRL
+#endif // WXWIN_COMPATIBILITY_2_4