From 7e4952db837344e369ff9ccc7ece1f7b8c207cf1 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 22 Mar 2009 09:18:46 +0000 Subject: [PATCH] add alignment flags support to wxSpinCtrl[Double] (closes #10621) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@59719 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/generic/spinctlg.h | 12 ++++----- include/wx/gtk/spinctrl.h | 10 +++---- include/wx/msw/spinctrl.h | 4 +-- include/wx/osx/spinctrl.h | 8 +++--- interface/wx/spinctrl.h | 7 +++++ samples/widgets/spinbtn.cpp | 50 +++++++++++++++++++++++++++++++++-- src/generic/spinctlg.cpp | 8 +++--- src/gtk/spinctrl.cpp | 10 +++++++ src/msw/spinctrl.cpp | 8 +++++- src/osx/spinctrl_osx.cpp | 2 +- src/xrc/xh_spin.cpp | 5 +++- 11 files changed, 98 insertions(+), 26 deletions(-) diff --git a/include/wx/generic/spinctlg.h b/include/wx/generic/spinctlg.h index dbae5a17f0..dfec89c230 100644 --- a/include/wx/generic/spinctlg.h +++ b/include/wx/generic/spinctlg.h @@ -50,7 +50,7 @@ public: const wxString& value = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, - long style = wxSP_ARROW_KEYS, + long style = wxSP_ARROW_KEYS | wxTE_RIGHT, double min = 0, double max = 100, double initial = 0, double inc = 1, const wxString& name = _T("wxSpinCtrl")); @@ -157,7 +157,7 @@ public: const wxString& value = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, - long style = wxSP_ARROW_KEYS, + long style = wxSP_ARROW_KEYS | wxTE_RIGHT, double min = 0, double max = 100, double initial = 0, double inc = 1, const wxString& name = _T("wxSpinCtrl")) { @@ -232,7 +232,7 @@ public: const wxString& value = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, - long style = wxSP_ARROW_KEYS, + long style = wxSP_ARROW_KEYS | wxTE_RIGHT, int min = 0, int max = 100, int initial = 0, const wxString& name = _T("wxSpinCtrl")) { @@ -244,7 +244,7 @@ public: const wxString& value = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, - long style = wxSP_ARROW_KEYS, + long style = wxSP_ARROW_KEYS | wxTE_RIGHT, int min = 0, int max = 100, int initial = 0, const wxString& name = _T("wxSpinCtrl")) { @@ -285,7 +285,7 @@ public: const wxString& value = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, - long style = wxSP_ARROW_KEYS, + long style = wxSP_ARROW_KEYS | wxTE_RIGHT, double min = 0, double max = 100, double initial = 0, double inc = 1, const wxString& name = _T("wxSpinCtrlDouble")) { @@ -298,7 +298,7 @@ public: const wxString& value = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, - long style = wxSP_ARROW_KEYS, + long style = wxSP_ARROW_KEYS | wxTE_RIGHT, double min = 0, double max = 100, double initial = 0, double inc = 1, const wxString& name = _T("wxSpinCtrlDouble")) { diff --git a/include/wx/gtk/spinctrl.h b/include/wx/gtk/spinctrl.h index 2cc0254253..a4c5753238 100644 --- a/include/wx/gtk/spinctrl.h +++ b/include/wx/gtk/spinctrl.h @@ -30,7 +30,7 @@ public: const wxString& value = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, - long style = wxSP_ARROW_KEYS, + long style = wxSP_ARROW_KEYS | wxTE_RIGHT, double min = 0, double max = 100, double initial = 0, double inc = 1, const wxString& name = _T("wxSpinCtrlGTKBase")); @@ -101,7 +101,7 @@ public: const wxString& value = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, - long style = wxSP_ARROW_KEYS, + long style = wxSP_ARROW_KEYS | wxTE_RIGHT, int min = 0, int max = 100, int initial = 0, const wxString& name = _T("wxSpinCtrl")) { @@ -113,7 +113,7 @@ public: const wxString& value = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, - long style = wxSP_ARROW_KEYS, + long style = wxSP_ARROW_KEYS | wxTE_RIGHT, int min = 0, int max = 100, int initial = 0, const wxString& name = _T("wxSpinCtrl")) { @@ -149,7 +149,7 @@ public: const wxString& value = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, - long style = wxSP_ARROW_KEYS, + long style = wxSP_ARROW_KEYS | wxTE_RIGHT, double min = 0, double max = 100, double initial = 0, double inc = 1, const wxString& name = _T("wxSpinCtrlDouble")) { @@ -161,7 +161,7 @@ public: const wxString& value = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, - long style = wxSP_ARROW_KEYS, + long style = wxSP_ARROW_KEYS | wxTE_RIGHT, double min = 0, double max = 100, double initial = 0, double inc = 1, const wxString& name = _T("wxSpinCtrlDouble")) { diff --git a/include/wx/msw/spinctrl.h b/include/wx/msw/spinctrl.h index 036ac2b1f3..cedd0601e5 100644 --- a/include/wx/msw/spinctrl.h +++ b/include/wx/msw/spinctrl.h @@ -37,7 +37,7 @@ public: const wxString& value = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, - long style = wxSP_ARROW_KEYS, + long style = wxSP_ARROW_KEYS | wxTE_RIGHT, int min = 0, int max = 100, int initial = 0, const wxString& name = _T("wxSpinCtrl")) { @@ -49,7 +49,7 @@ public: const wxString& value = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, - long style = wxSP_ARROW_KEYS, + long style = wxSP_ARROW_KEYS | wxTE_RIGHT, int min = 0, int max = 100, int initial = 0, const wxString& name = _T("wxSpinCtrl")); diff --git a/include/wx/osx/spinctrl.h b/include/wx/osx/spinctrl.h index 38fd7a9bff..a2f0c6223a 100644 --- a/include/wx/osx/spinctrl.h +++ b/include/wx/osx/spinctrl.h @@ -43,7 +43,7 @@ public: const wxString& value = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, - long style = wxSP_ARROW_KEYS, + long style = wxSP_ARROW_KEYS | wxTE_RIGHT, int min = 0, int max = 100, int initial = 0, const wxString& name = _T("wxSpinCtrl")) { @@ -56,7 +56,7 @@ public: const wxString& value = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, - long style = wxSP_ARROW_KEYS, + long style = wxSP_ARROW_KEYS | wxTE_RIGHT, int min = 0, int max = 100, int initial = 0, const wxString& name = _T("wxSpinCtrl")); @@ -135,7 +135,7 @@ public: const wxString& value = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, - long style = wxSP_ARROW_KEYS, + long style = wxSP_ARROW_KEYS | wxTE_RIGHT, int min = 0, int max = 100, int initial = 0, const wxString& name = _T("wxSpinCtrl")) { @@ -147,7 +147,7 @@ public: const wxString& value = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, - long style = wxSP_ARROW_KEYS, + long style = wxSP_ARROW_KEYS | wxTE_RIGHT, int min = 0, int max = 100, int initial = 0, const wxString& name = _T("wxSpinCtrl")) { diff --git a/interface/wx/spinctrl.h b/interface/wx/spinctrl.h index 80701178c3..877aa32007 100644 --- a/interface/wx/spinctrl.h +++ b/interface/wx/spinctrl.h @@ -21,6 +21,13 @@ events. Using this style will prevent the user from using the Enter key for dialog navigation (e.g. activating the default button in the dialog) under MSW. + @style{wxTE_LEFT} + Same as for wxTextCtrl: the text is left aligned. + @style{wxTE_CENTER} + Same as for wxTextCtrl: the text is centered. + @style{wxTE_RIGHT} + Same as for wxTextCtrl: the text is right aligned (this is the + default). @endStyleTable diff --git a/samples/widgets/spinbtn.cpp b/samples/widgets/spinbtn.cpp index bf396d7cb7..ec4b310301 100644 --- a/samples/widgets/spinbtn.cpp +++ b/samples/widgets/spinbtn.cpp @@ -67,6 +67,14 @@ enum SpinBtnPage_SpinCtrlDouble }; +// alignment radiobox values +enum +{ + Align_Left, + Align_Centre, + Align_Right +}; + // ---------------------------------------------------------------------------- // SpinBtnWidgetsPage // ---------------------------------------------------------------------------- @@ -130,6 +138,7 @@ protected: *m_chkArrowKeys, *m_chkWrap, *m_chkProcessEnter; + wxRadioBox *m_radioAlign; // the spinbtn and the spinctrl and the sizer containing them wxSpinButton *m_spinbtn; @@ -199,6 +208,7 @@ SpinBtnWidgetsPage::SpinBtnWidgetsPage(WidgetsBookCtrl *book, m_chkArrowKeys = NULL; m_chkWrap = NULL; m_chkProcessEnter = NULL; + m_radioAlign = NULL; m_spinbtn = NULL; m_spinctrl = NULL; m_spinctrldbl = NULL; @@ -228,6 +238,21 @@ void SpinBtnWidgetsPage::CreateContent() sizerLeft->Add(5, 5, 0, wxGROW | wxALL, 5); // spacer + static const wxString halign[] = + { + _T("left"), + _T("centre"), + _T("right"), + }; + + m_radioAlign = new wxRadioBox(this, wxID_ANY, _T("&Text alignment"), + wxDefaultPosition, wxDefaultSize, + WXSIZEOF(halign), halign, 1); + + sizerLeft->Add(m_radioAlign, 0, wxGROW | wxALL, 5); + + sizerLeft->Add(5, 5, 0, wxGROW | wxALL, 5); // spacer + wxButton *btn = new wxButton(this, SpinBtnPage_Reset, _T("&Reset")); sizerLeft->Add(btn, 0, wxALIGN_CENTRE_HORIZONTAL | wxALL, 15); @@ -291,6 +316,7 @@ void SpinBtnWidgetsPage::Reset() m_chkArrowKeys->SetValue(true); m_chkWrap->SetValue(false); m_chkProcessEnter->SetValue(false); + m_radioAlign->SetSelection(Align_Right); } void SpinBtnWidgetsPage::CreateSpin() @@ -312,6 +338,26 @@ void SpinBtnWidgetsPage::CreateSpin() if ( m_chkProcessEnter->GetValue() ) flags |= wxTE_PROCESS_ENTER; + int textFlags = 0; + switch ( m_radioAlign->GetSelection() ) + { + default: + wxFAIL_MSG(_T("unexpected radiobox selection")); + // fall through + + case Align_Left: + textFlags |= wxALIGN_LEFT; // no-op + break; + + case Align_Centre: + textFlags |= wxALIGN_CENTRE_HORIZONTAL; + break; + + case Align_Right: + textFlags |= wxALIGN_RIGHT; + break; + } + int val = m_min; if ( m_spinbtn ) { @@ -334,13 +380,13 @@ void SpinBtnWidgetsPage::CreateSpin() m_spinctrl = new wxSpinCtrl(this, SpinBtnPage_SpinCtrl, wxString::Format(_T("%d"), val), wxDefaultPosition, wxDefaultSize, - flags, + flags | textFlags, m_min, m_max, val); m_spinctrldbl = new wxSpinCtrlDouble(this, SpinBtnPage_SpinCtrlDouble, wxString::Format(_T("%d"), val), wxDefaultPosition, wxDefaultSize, - flags, + flags | textFlags, m_min, m_max, val, 0.1); // Add spacers, labels and spin controls to the sizer. diff --git a/src/generic/spinctlg.cpp b/src/generic/spinctlg.cpp index 853b967500..8fc9dadc29 100644 --- a/src/generic/spinctlg.cpp +++ b/src/generic/spinctlg.cpp @@ -58,9 +58,9 @@ static const wxCoord MARGIN = 2; class wxSpinCtrlTextGeneric : public wxTextCtrl { public: - wxSpinCtrlTextGeneric(wxSpinCtrlGenericBase *spin, const wxString& value) - : wxTextCtrl(spin->GetParent(), wxID_ANY, value, wxDefaultPosition, - wxDefaultSize, wxTE_NOHIDESEL|wxTE_PROCESS_ENTER) + wxSpinCtrlTextGeneric(wxSpinCtrlGenericBase *spin, const wxString& value, long style=0) + : wxTextCtrl(spin->GetParent(), wxID_ANY, value, wxDefaultPosition, wxDefaultSize, + ( style & wxALIGN_MASK ) | wxTE_NOHIDESEL | wxTE_PROCESS_ENTER) { m_spin = spin; @@ -197,7 +197,7 @@ bool wxSpinCtrlGenericBase::Create(wxWindow *parent, m_max = max; m_increment = increment; - m_textCtrl = new wxSpinCtrlTextGeneric(this, value); + m_textCtrl = new wxSpinCtrlTextGeneric(this, value, style); m_spinButton = new wxSpinCtrlButtonGeneric(this, style); m_spin_value = m_spinButton->GetValue(); diff --git a/src/gtk/spinctrl.cpp b/src/gtk/spinctrl.cpp index 698e6f1365..5d1e3c18e3 100644 --- a/src/gtk/spinctrl.cpp +++ b/src/gtk/spinctrl.cpp @@ -118,6 +118,16 @@ bool wxSpinCtrlGTKBase::Create(wxWindow *parent, wxWindowID id, gtk_spin_button_set_value( GTK_SPIN_BUTTON(m_widget), initial); m_value = gtk_spin_button_get_value( GTK_SPIN_BUTTON(m_widget)); + gfloat align; + if ( HasFlag(wxTE_RIGHT) ) + align = 1.0; + else if ( HasFlag(wxTE_CENTRE) ) + align = 0.5; + else + align = 0.0; + + gtk_entry_set_alignment(GTK_ENTRY(m_widget), align); + gtk_spin_button_set_wrap( GTK_SPIN_BUTTON(m_widget), (int)(m_windowStyle & wxSP_WRAP) ); diff --git a/src/msw/spinctrl.cpp b/src/msw/spinctrl.cpp index 05965d0c3d..298319ad2d 100644 --- a/src/msw/spinctrl.cpp +++ b/src/msw/spinctrl.cpp @@ -335,10 +335,16 @@ bool wxSpinCtrl::Create(wxWindow *parent, WXDWORD exStyle = 0; WXDWORD msStyle = MSWGetStyle(GetWindowStyle(), & exStyle) ; + // propagate text alignment style to text ctrl + if ( style & wxTE_RIGHT ) + msStyle |= ES_RIGHT; + else if ( style & wxTE_CENTER ) + msStyle |= ES_CENTER; + // this control is used for numeric entry so normally using these flags by // default shouldn't be a problem, if it is we can always add a style such // as wxSP_NON_NUMERIC later - msStyle |= ES_RIGHT | ES_NUMBER; + msStyle |= ES_NUMBER; // calculate the sizes: the size given is the total size for both controls // and we need to fit them both in the given width (height is the same) diff --git a/src/osx/spinctrl_osx.cpp b/src/osx/spinctrl_osx.cpp index a5849cde3f..2704bdf773 100644 --- a/src/osx/spinctrl_osx.cpp +++ b/src/osx/spinctrl_osx.cpp @@ -250,7 +250,7 @@ bool wxSpinCtrl::Create(wxWindow *parent, } wxSize csize = size ; - m_text = new wxSpinCtrlText(this, value, style & wxTE_PROCESS_ENTER ? wxTE_PROCESS_ENTER : 0 ); + m_text = new wxSpinCtrlText(this, value, style & ( wxTE_PROCESS_ENTER | wxALIGN_MASK ) ); m_btn = new wxSpinCtrlButton(this, style); m_btn->SetRange(min, max); diff --git a/src/xrc/xh_spin.cpp b/src/xrc/xh_spin.cpp index 7ac87fe3ab..5115b639d7 100644 --- a/src/xrc/xh_spin.cpp +++ b/src/xrc/xh_spin.cpp @@ -77,6 +77,9 @@ wxSpinCtrlXmlHandler::wxSpinCtrlXmlHandler() XRC_ADD_STYLE(wxSP_VERTICAL); XRC_ADD_STYLE(wxSP_ARROW_KEYS); XRC_ADD_STYLE(wxSP_WRAP); + XRC_ADD_STYLE(wxTE_LEFT); + XRC_ADD_STYLE(wxTE_CENTER); + XRC_ADD_STYLE(wxTE_RIGHT); } wxObject *wxSpinCtrlXmlHandler::DoCreateResource() @@ -87,7 +90,7 @@ wxObject *wxSpinCtrlXmlHandler::DoCreateResource() GetID(), GetText(wxT("value")), GetPosition(), GetSize(), - GetStyle(wxT("style"), wxSP_ARROW_KEYS), + GetStyle(wxT("style"), wxSP_ARROW_KEYS | wxTE_RIGHT), GetLong(wxT("min"), DEFAULT_MIN), GetLong(wxT("max"), DEFAULT_MAX), GetLong(wxT("value"), DEFAULT_VALUE), -- 2.47.2