]> git.saurik.com Git - wxWidgets.git/commitdiff
force showing 0 in the spin control instead of leaving it empty as the native spin...
authorVadim Zeitlin <vadim@wxwidgets.org>
Mon, 26 Jun 2006 12:20:50 +0000 (12:20 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Mon, 26 Jun 2006 12:20:50 +0000 (12:20 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@39839 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/msw/spinctrl.h
src/msw/spinctrl.cpp

index b58f818c74b3bc527ed9ba28d46c109c311f4ffa..bd4e0c5f30240fabcc909ed68391cc79bbecb903 100644 (file)
@@ -65,7 +65,7 @@ public:
 
     virtual ~wxSpinCtrl();
 
-    virtual void SetValue(int val) { wxSpinButton::SetValue(val); }
+    virtual void SetValue(int val);
     virtual int  GetValue() const;
     virtual bool SetFont(const wxFont &font);
     virtual void SetFocus();
index dbc1bdd3ff8c9b95b66c475b2fb74950d35cbb85..da8bb856f66a7a26563ba0e154f380c038406415 100644 (file)
@@ -431,16 +431,34 @@ void wxSpinCtrl::SetValue(const wxString& text)
     }
 }
 
+void  wxSpinCtrl::SetValue(int val)
+{
+    wxSpinButton::SetValue(val);
+
+    // normally setting the value of the spin button is enough as it updates
+    // its buddy control automatically ...
+    if ( wxGetWindowText(m_hwndBuddy).empty() )
+    {
+        // ... but sometimes it doesn't, notably when the value is 0 and the
+        // text control is currently empty, the spin button seems to be happy
+        // 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(_T("%ld"), val));
+    }
+}
+
 int wxSpinCtrl::GetValue() const
 {
     wxString val = wxGetWindowText(m_hwndBuddy);
 
     long n;
-    if ( (wxSscanf(val, wxT("%lu"), &n) != 1) )
+    if ( (wxSscanf(val, wxT("%ld"), &n) != 1) )
         n = INT_MIN;
 
-    if (n < m_min) n = m_min;
-    if (n > m_max) n = m_max;
+    if ( n < m_min )
+        n = m_min;
+    if ( n > m_max )
+        n = m_max;
 
     return n;
 }