X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/5b8a521e5993217b027e8045f0a211957cba945d..3ebcfb769f52c756018de75dacf3218ff60a8768:/src/gtk/slider.cpp diff --git a/src/gtk/slider.cpp b/src/gtk/slider.cpp index 778407f9ed..00a061af9e 100644 --- a/src/gtk/slider.cpp +++ b/src/gtk/slider.cpp @@ -61,7 +61,8 @@ static void gtk_slider_callback( GtkAdjustment *adjust, wxSlider *win ) else if (range->scroll_type == GTK_SCROLL_PAGE_BACKWARD) command = wxEVT_SCROLL_PAGEUP; else if (range->scroll_type == GTK_SCROLL_PAGE_FORWARD) command = wxEVT_SCROLL_PAGEDOWN; - int value = (int)ceil(adjust->value); + double dvalue = adjust->value; + int value = (int)(dvalue < 0 ? dvalue - 0.5 : dvalue + 0.5); int orient = wxHORIZONTAL; if ( (win->GetWindowStyleFlag() & wxSB_VERTICAL) == wxSB_VERTICAL) @@ -73,6 +74,7 @@ static void gtk_slider_callback( GtkAdjustment *adjust, wxSlider *win ) wxCommandEvent cevent( wxEVT_COMMAND_SLIDER_UPDATED, win->GetId() ); cevent.SetEventObject( win ); + cevent.SetInt( value ); win->GetEventHandler()->ProcessEvent( cevent ); } @@ -94,7 +96,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; @@ -107,7 +109,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 */ @@ -156,7 +158,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 ) @@ -183,6 +188,8 @@ void wxSlider::SetRange( int minValue, int maxValue ) m_adjust->lower = fmin; m_adjust->upper = fmax; + m_adjust->step_increment = 1.0; + m_adjust->page_increment = ceil((fmax-fmin) / 10.0); gtk_signal_emit_by_name( GTK_OBJECT(m_adjust), "changed" ); }