X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/caa2490c0fb8053b1d416117a9619695d75af9e4..78c91815008ef5888231c6c7f3678872e9e35ff6:/src/common/sizer.cpp?ds=sidebyside diff --git a/src/common/sizer.cpp b/src/common/sizer.cpp index 36c63f9e10..894a190d7b 100644 --- a/src/common/sizer.cpp +++ b/src/common/sizer.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: sizer.cpp +// Name: src/common/sizer.cpp // Purpose: provide new wxSizer class for layout // Author: Robert Roebling and Robin Dunn, contributions by // Dirk Holtwick, Ron Lee @@ -10,10 +10,6 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) -#pragma implementation "sizer.h" -#endif - // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" @@ -24,14 +20,15 @@ #ifndef WX_PRECOMP #include "wx/string.h" #include "wx/intl.h" + #include "wx/math.h" + #include "wx/utils.h" #endif // WX_PRECOMP #include "wx/sizer.h" -#include "wx/utils.h" #include "wx/statbox.h" #include "wx/settings.h" #include "wx/listimpl.cpp" -#include "wx/intl.h" + #if WXWIN_COMPATIBILITY_2_4 #include "wx/notebook.h" #endif @@ -50,7 +47,7 @@ IMPLEMENT_CLASS(wxStaticBoxSizer, wxBoxSizer) IMPLEMENT_CLASS(wxStdDialogButtonSizer, wxBoxSizer) #endif -WX_DEFINE_EXPORTED_LIST( wxSizerItemList ); +WX_DEFINE_EXPORTED_LIST( wxSizerItemList ) /* TODO PROPERTIES @@ -269,7 +266,7 @@ wxSize wxSizerItem::CalcMin() // 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) + if ( (m_flag & wxSHAPED) && wxIsNullDouble(m_ratio) ) SetRatio(m_minSize); } else if ( IsWindow() ) @@ -299,8 +296,10 @@ wxSize wxSizerItem::GetMinSizeWithBorder() const } -void wxSizerItem::SetDimension( wxPoint pos, wxSize size ) +void wxSizerItem::SetDimension( const wxPoint& pos_, const wxSize& size_ ) { + wxPoint pos = pos_; + wxSize size = size_; if (m_flag & wxSHAPED) { // adjust aspect ratio @@ -395,7 +394,7 @@ void wxSizerItem::DeleteWindows() m_window->Destroy(); //Putting this after the switch will result in a spacer //not being deleted properly on destruction - m_kind = Item_None; + m_kind = Item_None; break; case Item_Sizer: @@ -440,14 +439,28 @@ bool wxSizerItem::IsShown() const switch ( m_kind ) { case Item_None: - wxFAIL_MSG( _T("uninitialized sizer item") ); + // we may be called from CalcMin(), just return false so that we're + // not used break; case Item_Window: return m_window->IsShown(); case Item_Sizer: - return m_sizer->IsShown(); + // arbitrarily decide that if at least one of our elements is + // shown, so are we (this arbitrariness is the reason for + // deprecating this function) + { + for ( wxSizerItemList::compatibility_iterator + node = m_sizer->GetChildren().GetFirst(); + node; + node = node->GetNext() ) + { + if ( node->GetData()->IsShown() ) + return true; + } + } + return false; case Item_Spacer: return m_spacer->IsShown(); @@ -460,6 +473,7 @@ bool wxSizerItem::IsShown() const return false; } +#if WXWIN_COMPATIBILITY_2_6 void wxSizerItem::SetOption( int option ) { SetProportion( option ); @@ -469,17 +483,13 @@ int wxSizerItem::GetOption() const { return GetProportion(); } +#endif // WXWIN_COMPATIBILITY_2_6 //--------------------------------------------------------------------------- // wxSizer //--------------------------------------------------------------------------- -wxSizer::wxSizer() -{ - m_isShown = true; -} - wxSizer::~wxSizer() { WX_CLEAR_LIST(wxSizerItemList, m_children); @@ -495,10 +505,12 @@ wxSizerItem* wxSizer::Insert( size_t index, wxSizerItem *item ) return item; } +#if WXWIN_COMPATIBILITY_2_6 bool wxSizer::Remove( wxWindow *window ) { return Detach( window ); } +#endif // WXWIN_COMPATIBILITY_2_6 bool wxSizer::Remove( wxSizer *sizer ) { @@ -720,6 +732,15 @@ wxSize wxSizer::GetMinWindowSize( wxWindow *window ) // 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 ); @@ -1053,23 +1074,19 @@ bool wxSizer::IsShown( size_t index ) const //--------------------------------------------------------------------------- wxGridSizer::wxGridSizer( int rows, int cols, int vgap, int hgap ) - : m_rows( rows ) + : m_rows( ( cols == 0 && rows == 0 ) ? 1 : rows ) , m_cols( cols ) , m_vgap( vgap ) , m_hgap( hgap ) { - if (m_rows == 0 && m_cols == 0) - m_rows = 1; } wxGridSizer::wxGridSizer( int cols, int vgap, int hgap ) - : m_rows( 0 ) + : m_rows( cols == 0 ? 1 : 0 ) , m_cols( cols ) , m_vgap( vgap ) , m_hgap( hgap ) { - if (m_rows == 0 && m_cols == 0) - m_rows = 1; } int wxGridSizer::CalcRowsCols(int& nrows, int& ncols) const @@ -1328,10 +1345,12 @@ void wxFlexGridSizer::AdjustForFlexDirection() wxArrayInt& array = m_flexDirection == wxVERTICAL ? m_colWidths : m_rowHeights; - const int count = array.GetCount(); + const size_t count = array.GetCount(); // find the largest value in this array - int n, largest = 0; + size_t n; + int largest = 0; + for ( n = 0; n < count; ++n ) { if ( array[n] > largest ) @@ -1868,10 +1887,31 @@ void wxStdDialogButtonSizer::Realize() if (m_buttonAffirmative) Add((wxWindow*)m_buttonAffirmative, 0, wxALIGN_CENTRE | wxLEFT, 6); +#elif defined(__WXMSW__) + // Windows + + // right-justify buttons + Add(0, 0, 1, wxEXPAND, 0); + + if (m_buttonAffirmative){ + Add((wxWindow*)m_buttonAffirmative, 0, wxALIGN_CENTRE | wxLEFT | wxRIGHT, m_buttonAffirmative->ConvertDialogToPixels(wxSize(2, 0)).x); + } + + if (m_buttonNegative){ + Add((wxWindow*)m_buttonNegative, 0, wxALIGN_CENTRE | wxLEFT | wxRIGHT, m_buttonNegative->ConvertDialogToPixels(wxSize(2, 0)).x); + } + + if (m_buttonCancel){ + Add((wxWindow*)m_buttonCancel, 0, wxALIGN_CENTRE | wxLEFT | wxRIGHT, m_buttonCancel->ConvertDialogToPixels(wxSize(2, 0)).x); + } + if (m_buttonApply) + Add((wxWindow*)m_buttonApply, 0, wxALIGN_CENTRE | wxLEFT | wxRIGHT, m_buttonApply->ConvertDialogToPixels(wxSize(2, 0)).x); + + if (m_buttonHelp) + Add((wxWindow*)m_buttonHelp, 0, wxALIGN_CENTRE | wxLEFT | wxRIGHT, m_buttonHelp->ConvertDialogToPixels(wxSize(2, 0)).x); #else - // do the same thing for GTK1 and Windows platforms - // and assume any platform not accounted for here will use - // Windows style + // GTK+1 and any other platform + // Add(0, 0, 0, wxLEFT, 5); // Not sure what this was for but it unbalances the dialog if (m_buttonHelp) Add((wxWindow*)m_buttonHelp, 0, wxALIGN_CENTRE | wxLEFT | wxRIGHT, m_buttonHelp->ConvertDialogToPixels(wxSize(4, 0)).x); @@ -1916,12 +1956,16 @@ IMPLEMENT_CLASS(wxNotebookSizer, wxBookCtrlSizer) #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 ); @@ -1967,12 +2011,16 @@ wxSize wxBookCtrlSizer::CalcMin() #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