X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f7dd07f64d344e5b84c8dbe278ce4ad9da2a3c67..f2f0e4bea115b95ce6cc2b93c17b6d790ebe9cd0:/src/msw/spinctrl.cpp diff --git a/src/msw/spinctrl.cpp b/src/msw/spinctrl.cpp index 71c1221f49..94baaf3809 100644 --- a/src/msw/spinctrl.cpp +++ b/src/msw/spinctrl.cpp @@ -298,6 +298,10 @@ bool wxSpinCtrl::Create(wxWindow *parent, WXDWORD exStyle = 0; WXDWORD msStyle = MSWGetStyle(GetWindowStyle(), & exStyle) ; + // Scroll text automatically if there is not enough space to show all of + // it, this is better than not allowing to enter more digits at all. + msStyle |= ES_AUTOHSCROLL; + // propagate text alignment style to text ctrl if ( style & wxALIGN_RIGHT ) msStyle |= ES_RIGHT; @@ -389,22 +393,25 @@ bool wxSpinCtrl::Create(wxWindow *parent, // associate the text window with the spin button (void)::SendMessage(GetHwnd(), UDM_SETBUDDY, (WPARAM)m_hwndBuddy, 0); + // If the initial text value is actually a number, it overrides the + // "initial" argument specified later. + long initialFromText; + if ( value.ToLong(&initialFromText) ) + initial = initialFromText; + SetValue(initial); + m_oldValue = initial; + // Set the range in the native control SetRange(min, max); - // If necessary, set the textual value. Don't do it if it's the same as the - // numeric value though. - if ( value != wxString::Format("%d", initial) ) - { + // Also set the text part of the control if it was specified independently + // but don't generate an event for this, it would be unexpected. + m_blockEvent = true; + if ( !value.empty() ) SetValue(value); - m_oldValue = (int) wxAtol(value); - } - else - { - m_oldValue = initial; - } + m_blockEvent = false; return true; } @@ -445,7 +452,7 @@ void wxSpinCtrl::SetValue(int val) // to leave it like this, while we really want to always show the // current value in the control, so do it manually ::SetWindowText(GetBuddyHwnd(), - wxString::Format(wxT("%d"), val).wx_str()); + wxString::Format(wxT("%d"), val).t_str()); } m_oldValue = GetValue(); @@ -487,6 +494,14 @@ void wxSpinCtrl::SetSelection(long from, long to) void wxSpinCtrl::SetRange(int minVal, int maxVal) { + // Manually adjust the old value to avoid an event being sent from + // NormalizeValue() called from inside the base class SetRange() as we're + // not supposed to generate any events from here. + if ( m_oldValue < minVal ) + m_oldValue = minVal; + else if ( m_oldValue > maxVal ) + m_oldValue = maxVal; + wxSpinButton::SetRange(minVal, maxVal); // this control is used for numeric entry so restrict the input to numeric