#pragma hdrstop
#endif
+#include "wx/display.h"
#include "wx/sizer.h"
#ifndef WX_PRECOMP
#include "wx/listimpl.cpp"
-#if WXWIN_COMPATIBILITY_2_4
- #include "wx/notebook.h"
-#endif
//---------------------------------------------------------------------------
m_proportion = 0;
m_border = 0;
m_flag = 0;
-
- m_kind = Item_None;
}
// window item
-void wxSizerItem::SetWindow(wxWindow *window)
+void wxSizerItem::DoSetWindow(wxWindow *window)
{
wxCHECK_RET( window, _T("NULL window in wxSizerItem::SetWindow()") );
int flag,
int border,
wxObject* userData)
- : m_proportion(proportion),
+ : m_kind(Item_None),
+ m_proportion(proportion),
m_border(border),
m_flag(flag),
m_userData(userData)
{
- SetWindow(window);
+ DoSetWindow(window);
}
// sizer item
-void wxSizerItem::SetSizer(wxSizer *sizer)
+void wxSizerItem::DoSetSizer(wxSizer *sizer)
{
m_kind = Item_Sizer;
m_sizer = sizer;
int flag,
int border,
wxObject* userData)
- : m_proportion(proportion),
+ : m_kind(Item_None),
+ m_sizer(NULL),
+ m_proportion(proportion),
m_border(border),
m_flag(flag),
m_ratio(0.0),
m_userData(userData)
{
- SetSizer(sizer);
+ DoSetSizer(sizer);
// m_minSize is set later
}
// spacer item
-void wxSizerItem::SetSpacer(const wxSize& size)
+void wxSizerItem::DoSetSpacer(const wxSize& size)
{
m_kind = Item_Spacer;
m_spacer = new wxSizerSpacer(size);
int flag,
int border,
wxObject* userData)
- : m_minSize(width, height), // minimal size is the initial size
+ : m_kind(Item_None),
+ m_sizer(NULL),
+ m_minSize(width, height), // minimal size is the initial size
m_proportion(proportion),
m_border(border),
m_flag(flag),
m_userData(userData)
{
- SetSpacer(width, height);
+ DoSetSpacer(wxSize(width, height));
}
wxSizerItem::~wxSizerItem()
{
delete m_userData;
+ Free();
+}
+void wxSizerItem::Free()
+{
switch ( m_kind )
{
case Item_None:
default:
wxFAIL_MSG( _T("unexpected wxSizerItem::m_kind") );
}
+
+ m_kind = Item_None;
}
wxSize wxSizerItem::GetSpacer() const
// shown, so are we (this arbitrariness is the reason for
// deprecating this function)
{
+ // Some apps (such as dialog editors) depend on an empty sizer still
+ // being laid out correctly and reporting the correct size and position.
+ if (m_sizer->GetChildren().GetCount() == 0)
+ return true;
+
for ( wxSizerItemList::compatibility_iterator
node = m_sizer->GetChildren().GetFirst();
node;
wxCHECK_MSG( node, false, _T("Failed to find child node") );
- wxSizerItem *item = node->GetData();
-
- if ( item->IsWindow() )
- item->GetWindow()->SetContainingSizer( NULL );
-
- delete item;
+ delete node->GetData();
m_children.Erase( node );
+
return true;
}
if (item->GetWindow() == window)
{
- item->GetWindow()->SetContainingSizer( NULL );
delete item;
m_children.Erase( node );
return true;
if ( item->IsSizer() )
item->DetachSizer();
- else if ( item->IsWindow() )
- item->GetWindow()->SetContainingSizer( NULL );
delete item;
m_children.Erase( node );
if (item->GetWindow() == oldwin)
{
- item->GetWindow()->SetContainingSizer( NULL );
- item->SetWindow(newwin);
+ item->AssignWindow(newwin);
newwin->SetContainingSizer( this );
return true;
}
if (item->GetSizer() == oldsz)
{
- wxSizer *old = item->GetSizer();
- item->SetSizer(newsz);
- delete old;
+ item->AssignSizer(newsz);
return true;
}
else if (recursive && item->IsSizer())
wxSize wxSizer::Fit( wxWindow *window )
{
- wxSize size(window->IsTopLevel() ? FitSize(window)
- : GetMinWindowSize(window));
+ // take the min size by default and limit it by max size
+ wxSize size = GetMinWindowSize(window);
+ wxSize sizeMax = GetMaxWindowSize(window);
+
+ wxTopLevelWindow *tlw = wxDynamicCast(window, wxTopLevelWindow);
+ if ( tlw )
+ {
+ // hack for small screen devices where TLWs are always full screen
+ if ( tlw->IsAlwaysMaximized() )
+ {
+ size = tlw->GetSize();
+ }
+ else // normal situation
+ {
+ // limit the window to the size of the display it is on
+ int disp = wxDisplay::GetFromWindow(window);
+ if ( disp == wxNOT_FOUND )
+ {
+ // or, if we don't know which one it is, of the main one
+ disp = 0;
+ }
+
+ sizeMax = wxDisplay(disp).GetClientArea().GetSize();
+ }
+ }
+
+ if ( sizeMax.x != wxDefaultCoord && size.x > sizeMax.x )
+ size.x = sizeMax.x;
+ if ( sizeMax.y != wxDefaultCoord && size.y > sizeMax.y )
+ size.y = sizeMax.y;
+
window->SetSize( size );
// 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 ( window->IsTopLevel() )
- {
- wxTopLevelWindow *tlw = wxDynamicCast(window, wxTopLevelWindow);
- if ( tlw && tlw->IsAlwaysMaximized() )
- {
- return tlw->GetClientSize();
- }
- }
-
- wxSize size = GetMinWindowSize( window );
- wxSize sizeMax = GetMaxWindowSize( window );
-
- // Limit the size if sizeMax != wxDefaultSize
-
- if ( size.x > sizeMax.x && sizeMax.x != wxDefaultCoord )
- size.x = sizeMax.x;
- if ( size.y > sizeMax.y && sizeMax.y != wxDefaultCoord )
- size.y = sizeMax.y;
-
- return size;
-}
-
wxSize wxSizer::GetMaxClientSize( wxWindow *window ) const
{
wxSize maxSize( window->GetMaxSize() );
if (m_buttonAffirmative->GetId() == wxID_SAVE){
// these buttons have set labels under Mac so we should use them
m_buttonAffirmative->SetLabel(_("Save"));
- m_buttonNegative->SetLabel(_("Don't Save"));
+ if (m_buttonNegative)
+ m_buttonNegative->SetLabel(_("Don't Save"));
}
}
}
#endif // wxUSE_BUTTON
-
-#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
-
-#if WXWIN_COMPATIBILITY_2_6
-
-wxBookCtrlSizer::wxBookCtrlSizer(wxBookCtrlBase *bookctrl)
- : m_bookctrl(bookctrl)
-{
- wxASSERT_MSG( bookctrl, wxT("wxBookCtrlSizer needs a control") );
-}
-
-#endif // WXWIN_COMPATIBILITY_2_6
-
-void wxBookCtrlSizer::RecalcSizes()
-{
- m_bookctrl->SetSize( m_position.x, m_position.y, m_size.x, m_size.y );
-}
-
-wxSize wxBookCtrlSizer::CalcMin()
-{
- wxSize sizeBorder = m_bookctrl->CalcSizeFromPage(wxSize(0,0));
-
- sizeBorder.x += 5;
- sizeBorder.y += 5;
-
- if ( m_bookctrl->GetPageCount() == 0 )
- {
- return wxSize(sizeBorder.x + 10, sizeBorder.y + 10);
- }
-
- int maxX = 0;
- int maxY = 0;
-
- wxWindowList::compatibility_iterator
- node = m_bookctrl->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( maxX, maxY ) + sizeBorder;
-}
-
-#if wxUSE_NOTEBOOK
-
-#if WXWIN_COMPATIBILITY_2_6
-
-wxNotebookSizer::wxNotebookSizer(wxNotebook *nb)
-{
- wxASSERT_MSG( nb, wxT("wxNotebookSizer needs a control") );
- m_bookctrl = nb;
-}
-
-#endif // WXWIN_COMPATIBILITY_2_6
-
-#endif // wxUSE_NOTEBOOOK
-#endif // wxUSE_BOOKCTRL
-
-#endif // WXWIN_COMPATIBILITY_2_4