X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7f0cbaaa4ab3037587fa796d38e7eaf16ed54933..b85b06e13d22e7fc1604ec1a49caa1227a1b3d36:/src/generic/spinctlg.cpp diff --git a/src/generic/spinctlg.cpp b/src/generic/spinctlg.cpp index 1235d9819c..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; @@ -186,7 +186,8 @@ bool wxSpinCtrlGenericBase::Create(wxWindow *parent, // the text control borders (but we might want to use style border bits to // select the text control style) if ( !wxControl::Create(parent, id, wxDefaultPosition, wxDefaultSize, - wxBORDER_NONE, wxDefaultValidator, name) ) + (style & ~wxBORDER_MASK) | wxBORDER_NONE, + wxDefaultValidator, name) ) { return false; } @@ -196,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(); @@ -337,11 +338,7 @@ void wxSpinCtrlGenericBase::OnSpinButton(wxSpinEvent& event) if (((spin_value >= 0) && (m_spin_value >= 0)) || ((spin_value <= 0) && (m_spin_value <= 0))) step *= abs(spin_value - m_spin_value); - double value = m_value + step*m_increment; - - // we can always reach the ends using the spinbutton - if (value < m_min) value = m_min; - if (value > m_max) value = m_max; + double value = AdjustToFitInRange(m_value + step*m_increment); // Ignore the edges when it wraps since the up/down event may be opposite // They are in GTK and Mac @@ -353,7 +350,7 @@ void wxSpinCtrlGenericBase::OnSpinButton(wxSpinEvent& event) m_spin_value = spin_value; - if (InRange(value) && DoSetValue(value)) + if ( DoSetValue(value) ) DoSendEvent(); } @@ -366,6 +363,12 @@ void wxSpinCtrlGenericBase::OnTextEnter(wxCommandEvent& event) void wxSpinCtrlGenericBase::OnTextChar(wxKeyEvent& event) { + if ( !HasFlag(wxSP_ARROW_KEYS) ) + { + event.Skip(); + return; + } + double value = m_value; switch ( event.GetKeyCode() ) { @@ -390,6 +393,8 @@ void wxSpinCtrlGenericBase::OnTextChar(wxKeyEvent& event) return; } + value = AdjustToFitInRange(value); + if ( m_textCtrl && m_textCtrl->IsModified() ) SyncSpinToText(); @@ -480,6 +485,16 @@ bool wxSpinCtrlGenericBase::DoSetValue(double val) return false; } +double wxSpinCtrlGenericBase::AdjustToFitInRange(double value) const +{ + if (value < m_min) + value = HasFlag(wxSP_WRAP) ? m_max : m_min; + if (value > m_max) + value = HasFlag(wxSP_WRAP) ? m_min : m_max; + + return value; +} + void wxSpinCtrlGenericBase::DoSetRange(double min, double max) { m_min = min;