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;
// 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;
}
// 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();
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