From eeea41abbcda4a2078014dc12f9d48242a21df89 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 26 Jun 2006 12:20:50 +0000 Subject: [PATCH] force showing 0 in the spin control instead of leaving it empty as the native spin button seems to be content to do git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@39839 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/msw/spinctrl.h | 2 +- src/msw/spinctrl.cpp | 24 +++++++++++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/include/wx/msw/spinctrl.h b/include/wx/msw/spinctrl.h index b58f818c74..bd4e0c5f30 100644 --- a/include/wx/msw/spinctrl.h +++ b/include/wx/msw/spinctrl.h @@ -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(); diff --git a/src/msw/spinctrl.cpp b/src/msw/spinctrl.cpp index dbc1bdd3ff..da8bb856f6 100644 --- a/src/msw/spinctrl.cpp +++ b/src/msw/spinctrl.cpp @@ -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; } -- 2.45.2