From ef7a25a73ef4215454d6d8e3bad63bdf5b4339a0 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 14 Dec 2000 15:48:30 +0000 Subject: [PATCH] merged in fix for GetValue() from the 2.2 branch git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@8923 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/gtk/slider.cpp | 9 ++++++--- src/gtk1/slider.cpp | 9 ++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/gtk/slider.cpp b/src/gtk/slider.cpp index 838a5d2549..58aa39db81 100644 --- a/src/gtk/slider.cpp +++ b/src/gtk/slider.cpp @@ -95,7 +95,7 @@ bool wxSlider::Create(wxWindow *parent, wxWindowID id, !CreateBase( parent, id, pos, size, style, validator, name )) { wxFAIL_MSG( wxT("wxSlider creation failed") ); - return FALSE; + return FALSE; } m_oldPos = 0.0; @@ -108,7 +108,7 @@ bool wxSlider::Create(wxWindow *parent, wxWindowID id, if (style & wxSL_LABELS) { gtk_scale_set_draw_value( GTK_SCALE( m_widget ), TRUE ); - gtk_scale_set_digits( GTK_SCALE( m_widget ), 0 ); + gtk_scale_set_digits( GTK_SCALE( m_widget ), 0 ); /* labels need more space and too small window will cause junk to appear on the dialog */ @@ -157,7 +157,10 @@ bool wxSlider::Create(wxWindow *parent, wxWindowID id, int wxSlider::GetValue() const { - return (int)(m_adjust->value+0.5); + // we want to round to the nearest integer, i.e. 0.9 is rounded to 1 and + // -0.9 is rounded to -1 + double val = m_adjust->value; + return (int)(val >= 0 ? val - 0.5 : val + 0.5); } void wxSlider::SetValue( int value ) diff --git a/src/gtk1/slider.cpp b/src/gtk1/slider.cpp index 838a5d2549..58aa39db81 100644 --- a/src/gtk1/slider.cpp +++ b/src/gtk1/slider.cpp @@ -95,7 +95,7 @@ bool wxSlider::Create(wxWindow *parent, wxWindowID id, !CreateBase( parent, id, pos, size, style, validator, name )) { wxFAIL_MSG( wxT("wxSlider creation failed") ); - return FALSE; + return FALSE; } m_oldPos = 0.0; @@ -108,7 +108,7 @@ bool wxSlider::Create(wxWindow *parent, wxWindowID id, if (style & wxSL_LABELS) { gtk_scale_set_draw_value( GTK_SCALE( m_widget ), TRUE ); - gtk_scale_set_digits( GTK_SCALE( m_widget ), 0 ); + gtk_scale_set_digits( GTK_SCALE( m_widget ), 0 ); /* labels need more space and too small window will cause junk to appear on the dialog */ @@ -157,7 +157,10 @@ bool wxSlider::Create(wxWindow *parent, wxWindowID id, int wxSlider::GetValue() const { - return (int)(m_adjust->value+0.5); + // we want to round to the nearest integer, i.e. 0.9 is rounded to 1 and + // -0.9 is rounded to -1 + double val = m_adjust->value; + return (int)(val >= 0 ? val - 0.5 : val + 0.5); } void wxSlider::SetValue( int value ) -- 2.45.2