X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/acf2ac3757581e8d272d2bdb427a4fc0bbed4cf7..2b1d737b3e9413217302cde932cbc3af91d79024:/src/common/sizer.cpp diff --git a/src/common/sizer.cpp b/src/common/sizer.cpp index 307ab3adc8..703882151e 100644 --- a/src/common/sizer.cpp +++ b/src/common/sizer.cpp @@ -21,19 +21,21 @@ #pragma hdrstop #endif +#ifndef WX_PRECOMP + #include "wx/string.h" + #include "wx/intl.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 -#ifdef __WXMAC__ -# include "wx/mac/uma.h" -#endif - //--------------------------------------------------------------------------- IMPLEMENT_CLASS(wxSizerItem, wxObject) @@ -44,7 +46,9 @@ IMPLEMENT_CLASS(wxBoxSizer, wxSizer) #if wxUSE_STATBOX IMPLEMENT_CLASS(wxStaticBoxSizer, wxBoxSizer) #endif +#if wxUSE_BUTTON IMPLEMENT_CLASS(wxStdDialogButtonSizer, wxBoxSizer) +#endif WX_DEFINE_EXPORTED_LIST( wxSizerItemList ); @@ -91,7 +95,7 @@ void wxSizerItem::Init() m_sizer = NULL; m_show = true; m_userData = NULL; - m_zoneRect = wxRect( 0, 0, 0, 0 ); + m_zoneRect = wxRect(0,0,0,0); } void wxSizerItem::Init(const wxSizerFlags& flags) @@ -111,7 +115,7 @@ wxSizerItem::wxSizerItem( int width, int height, int proportion, int flag, int b , m_proportion( proportion ) , m_border( border ) , m_flag( flag ) - , m_zoneRect( 0, 0, 0, 0 ) + , m_zoneRect() , m_show( true ) , m_userData( userData ) { @@ -124,7 +128,7 @@ wxSizerItem::wxSizerItem( wxWindow *window, int proportion, int flag, int border , m_proportion( proportion ) , m_border( border ) , m_flag( flag ) - , m_zoneRect( 0, 0, 0, 0 ) + , m_zoneRect() , m_show( true ) , m_userData( userData ) { @@ -144,7 +148,7 @@ wxSizerItem::wxSizerItem( wxSizer *sizer, int proportion, int flag, int border, , m_proportion( proportion ) , m_border( border ) , m_flag( flag ) - , m_zoneRect( 0, 0, 0, 0 ) + , m_zoneRect() , m_show( true ) , m_ratio( 0.0 ) , m_userData( userData ) @@ -355,7 +359,7 @@ int wxSizerItem::GetOption() const //--------------------------------------------------------------------------- wxSizer::wxSizer() - : m_minSize( wxSize( 0, 0 ) ) + :m_minSize() { } @@ -1123,9 +1127,11 @@ void wxFlexGridSizer::RecalcSizes() SetItemBounds( node->GetData(), x, y, w, h); } - y = y + m_rowHeights[r] + m_vgap; + if (m_rowHeights[r] != -1) + y = y + m_rowHeights[r] + m_vgap; } - x = x + m_colWidths[c] + m_hgap; + if (m_colWidths[c] != -1) + x = x + m_colWidths[c] + m_hgap; } } @@ -1179,12 +1185,16 @@ wxSize wxFlexGridSizer::CalcMin() int width = 0; for (int col = 0; col < ncols; col++) if ( m_colWidths[ col ] != -1 ) - width += m_colWidths[ col ] + ( col == ncols-1 ? 0 : m_hgap ); + width += m_colWidths[ col ] + m_hgap; + if (width > 0) + width -= m_hgap; int height = 0; for (int row = 0; row < nrows; row++) if ( m_rowHeights[ row ] != -1 ) - height += m_rowHeights[ row ] + ( row == nrows-1 ? 0 : m_vgap ); + height += m_rowHeights[ row ] + m_vgap; + if (height > 0) + height -= m_vgap; m_calculatedMinSize = wxSize( width, height ); return m_calculatedMinSize; @@ -1556,49 +1566,19 @@ wxStaticBoxSizer::wxStaticBoxSizer( wxStaticBox *box, int orient ) wxASSERT_MSG( box, wxT("wxStaticBoxSizer needs a static box") ); } +wxStaticBoxSizer::wxStaticBoxSizer(int orient, wxWindow *win, const wxString& s) + : wxBoxSizer(orient), + m_staticBox(new wxStaticBox(win, wxID_ANY, s)) +{ +} + static void GetStaticBoxBorders( wxStaticBox *box, int *borderTop, int *borderOther) { // this has to be done platform by platform as there is no way to // guess the thickness of a wxStaticBox border -#ifdef __WXCOCOA__ - box->GetBordersForSizer(borderTop,borderOther); -#elif defined(__WXMAC__) - - static int extraTop = -1; // Uninitted - static int other = 5; - - if ( extraTop == -1 ) - { - // The minimal border used for the top. Later on the staticbox' - // font height is added to this. - extraTop = 0; - - if ( UMAGetSystemVersion() >= 0x1030 /*Panther*/ ) - { - // As indicated by the HIG, Panther needs an extra border of 11 - // pixels (otherwise overlapping occurs at the top). The "other" - // border has to be 11. - extraTop = 11; - other = 11; - } - - } - - *borderTop = extraTop + box->GetCharHeight(); - *borderOther = other; - -#else -#ifdef __WXGTK__ - if ( box->GetLabel().empty() ) - *borderTop = 5; - else -#endif // __WXGTK__ - *borderTop = box->GetCharHeight(); - - *borderOther = 5; -#endif // __WXCOCOA__ + box->GetBordersForSizer(borderTop, borderOther); } void wxStaticBoxSizer::RecalcSizes() @@ -1641,16 +1621,24 @@ void wxStaticBoxSizer::ShowItems( bool show ) #endif // wxUSE_STATBOX +#if wxUSE_BUTTON + wxStdDialogButtonSizer::wxStdDialogButtonSizer() : wxBoxSizer(wxHORIZONTAL) { + // Vertical buttons with lots of space on either side + // looks rubbish on WinCE, so let's not do this for now. + // If we are going to use vertical buttons, we should + // put the sizer to the right of other controls in the dialog, + // and that's beyond the scope of this sizer. +#ifndef __WXWINCE__ bool is_pda = (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA); - - // If we have a PDA screen, put yes/no button over + // If we have a PDA screen, put yes/no button over // all other buttons, otherwise on the left side. if (is_pda) m_orient = wxVERTICAL; - +#endif + m_buttonAffirmative = NULL; m_buttonApply = NULL; m_buttonNegative = NULL; @@ -1677,6 +1665,7 @@ void wxStdDialogButtonSizer::AddButton(wxButton *mybutton) m_buttonCancel = mybutton; break; case wxID_HELP: + case wxID_CONTEXT_HELP: m_buttonHelp = mybutton; break; default: @@ -1684,66 +1673,81 @@ void wxStdDialogButtonSizer::AddButton(wxButton *mybutton) } } -void wxStdDialogButtonSizer::Finalise() +void wxStdDialogButtonSizer::SetAffirmativeButton( wxButton *button ) +{ + m_buttonAffirmative = button; +} + +void wxStdDialogButtonSizer::SetNegativeButton( wxButton *button ) +{ + m_buttonNegative = button; +} + +void wxStdDialogButtonSizer::SetCancelButton( wxButton *button ) +{ + m_buttonCancel = button; +} + +void wxStdDialogButtonSizer::Realize() { #ifdef __WXMAC__ Add(0, 0, 0, wxLEFT, 6); if (m_buttonHelp) - Add((wxWindow*)m_buttonHelp, 0, wxALIGN_CENTRE | wxLEFT | wxRIGHT, 6); - + Add((wxWindow*)m_buttonHelp, 0, wxALIGN_CENTRE | wxLEFT | wxRIGHT, 6); + if (m_buttonNegative){ // HIG POLICE BULLETIN - destructive buttons need extra padding // 24 pixels on either side Add((wxWindow*)m_buttonNegative, 0, wxALIGN_CENTRE | wxLEFT | wxRIGHT, 12); } - + // extra whitespace between help/negative and cancel/ok buttons - Add(0, 0, 1, wxEXPAND, 0); - + Add(0, 0, 1, wxEXPAND, 0); + if (m_buttonCancel){ Add((wxWindow*)m_buttonCancel, 0, wxALIGN_CENTRE | wxLEFT | wxRIGHT, 6); // Cancel or help should be default // m_buttonCancel->SetDefaultButton(); } - - // Ugh, Mac doesn't really have apply dialogs, so I'll just + + // Ugh, Mac doesn't really have apply dialogs, so I'll just // figure the best place is between Cancel and OK if (m_buttonApply) Add((wxWindow*)m_buttonApply, 0, wxALIGN_CENTRE | wxLEFT | wxRIGHT, 6); - + if (m_buttonAffirmative){ Add((wxWindow*)m_buttonAffirmative, 0, wxALIGN_CENTRE | wxLEFT, 6); - + 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")); } } - + // Extra space around and at the right Add(12, 24); #elif defined(__WXGTK20__) Add(0, 0, 0, wxLEFT, 9); if (m_buttonHelp) - Add((wxWindow*)m_buttonHelp, 0, wxALIGN_CENTRE | wxLEFT | wxRIGHT, 3); - + Add((wxWindow*)m_buttonHelp, 0, wxALIGN_CENTRE | wxLEFT | wxRIGHT, 3); + // extra whitespace between help and cancel/ok buttons - Add(0, 0, 1, wxEXPAND, 0); - + Add(0, 0, 1, wxEXPAND, 0); + if (m_buttonNegative){ Add((wxWindow*)m_buttonNegative, 0, wxALIGN_CENTRE | wxLEFT | wxRIGHT, 3); } - + if (m_buttonCancel){ Add((wxWindow*)m_buttonCancel, 0, wxALIGN_CENTRE | wxLEFT | wxRIGHT, 3); // Cancel or help should be default // m_buttonCancel->SetDefaultButton(); } - + if (m_buttonApply) Add((wxWindow*)m_buttonApply, 0, wxALIGN_CENTRE | wxLEFT | wxRIGHT, 3); - + if (m_buttonAffirmative) Add((wxWindow*)m_buttonAffirmative, 0, wxALIGN_CENTRE | wxLEFT, 6); #else @@ -1752,31 +1756,33 @@ void wxStdDialogButtonSizer::Finalise() // Windows style Add(0, 0, 0, wxLEFT, 9); if (m_buttonHelp) - Add((wxWindow*)m_buttonHelp, 0, wxALIGN_CENTRE | wxLEFT | wxRIGHT, m_buttonHelp->ConvertDialogToPixels(wxSize(4, 0)).x); - + Add((wxWindow*)m_buttonHelp, 0, wxALIGN_CENTRE | wxLEFT | wxRIGHT, m_buttonHelp->ConvertDialogToPixels(wxSize(4, 0)).x); + // extra whitespace between help and cancel/ok buttons - Add(0, 0, 1, wxEXPAND, 0); + Add(0, 0, 1, wxEXPAND, 0); if (m_buttonApply) Add((wxWindow*)m_buttonApply, 0, wxALIGN_CENTRE | wxLEFT | wxRIGHT, m_buttonApply->ConvertDialogToPixels(wxSize(4, 0)).x); - + if (m_buttonAffirmative){ Add((wxWindow*)m_buttonAffirmative, 0, wxALIGN_CENTRE | wxLEFT | wxRIGHT, m_buttonAffirmative->ConvertDialogToPixels(wxSize(4, 0)).x); } - + if (m_buttonNegative){ Add((wxWindow*)m_buttonNegative, 0, wxALIGN_CENTRE | wxLEFT | wxRIGHT, m_buttonNegative->ConvertDialogToPixels(wxSize(4, 0)).x); } - + if (m_buttonCancel){ Add((wxWindow*)m_buttonCancel, 0, wxALIGN_CENTRE | wxLEFT, m_buttonCancel->ConvertDialogToPixels(wxSize(4, 0)).x); // Cancel or help should be default // m_buttonCancel->SetDefaultButton(); } - + #endif } +#endif // wxUSE_BUTTON + #if WXWIN_COMPATIBILITY_2_4 // ---------------------------------------------------------------------------- @@ -1805,7 +1811,7 @@ void wxBookCtrlSizer::RecalcSizes() wxSize wxBookCtrlSizer::CalcMin() { - wxSize sizeBorder = m_bookctrl->CalcSizeFromPage(wxSize(0, 0)); + wxSize sizeBorder = m_bookctrl->CalcSizeFromPage(wxSize(0,0)); sizeBorder.x += 5; sizeBorder.y += 5;