X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/8e3e14c4871f6c3b783eb12989262e076845c8e3..2028c33ab5a39a12bd410ac953731a56ad6377ba:/src/gtk1/slider.cpp?ds=sidebyside diff --git a/src/gtk1/slider.cpp b/src/gtk1/slider.cpp index ba70dee257..7a7a4f0e6b 100644 --- a/src/gtk1/slider.cpp +++ b/src/gtk1/slider.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: gtk/slider.cpp +// Name: src/gtk1/slider.cpp // Purpose: // Author: Robert Roebling // Id: $Id$ @@ -10,13 +10,16 @@ // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" +#if wxUSE_SLIDER + #include "wx/slider.h" -#if wxUSE_SLIDER +#ifndef WX_PRECOMP + #include "wx/utils.h" + #include "wx/math.h" +#endif -#include "wx/utils.h" -#include "wx/math.h" -#include "wx/gtk/private.h" +#include "wx/gtk1/private.h" //----------------------------------------------------------------------------- // idle system @@ -41,13 +44,6 @@ static inline bool AreSameAdjustValues(double x, double y) return fabs(x - y) < 0.02; } -static inline int AdjustValueToInt(double x) -{ - // we want to round to the nearest integer, i.e. 0.9 is rounded to 1 and - // -0.9 is rounded to -1 - return (int)(x < 0 ? x - 0.5 : x + 0.5); -} - // process a scroll event static void ProcessScrollEvent(wxSlider *win, wxEventType evtType, double dvalue) @@ -58,19 +54,19 @@ ProcessScrollEvent(wxSlider *win, wxEventType evtType, double dvalue) int value = (int)(dvalue < 0 ? dvalue - 0.5 : dvalue + 0.5); wxScrollEvent event( evtType, win->GetId(), value, orient ); event.SetEventObject( win ); - win->GetEventHandler()->ProcessEvent( event ); + win->HandleWindowEvent( event ); if ( evtType != wxEVT_SCROLL_THUMBTRACK ) { wxScrollEvent event2(wxEVT_SCROLL_CHANGED, win->GetId(), value, orient); event2.SetEventObject( win ); - win->GetEventHandler()->ProcessEvent( event2 ); + win->HandleWindowEvent( event2 ); } wxCommandEvent cevent( wxEVT_COMMAND_SLIDER_UPDATED, win->GetId() ); cevent.SetEventObject( win ); cevent.SetInt( value ); - win->GetEventHandler()->ProcessEvent( cevent ); + win->HandleWindowEvent( cevent ); } //----------------------------------------------------------------------------- @@ -93,25 +89,7 @@ static void gtk_slider_callback( GtkAdjustment *adjust, return; wxEventType evtType; -#ifdef __WXGTK20__ - if ( win->m_isScrolling ) - evtType = wxEVT_SCROLL_THUMBTRACK; - // it could seem that UP/DOWN are inversed but this is what wxMSW does - else if ( AreSameAdjustValues(diff, adjust->step_increment) ) - evtType = wxEVT_SCROLL_LINEDOWN; - else if ( AreSameAdjustValues(diff, -adjust->step_increment) ) - evtType = wxEVT_SCROLL_LINEUP; - else if ( AreSameAdjustValues(diff, adjust->page_increment) ) - evtType = wxEVT_SCROLL_PAGEDOWN; - else if ( AreSameAdjustValues(diff, -adjust->page_increment) ) - evtType = wxEVT_SCROLL_PAGEUP; - else if ( AreSameAdjustValues(adjust->value, adjust->lower) ) - evtType = wxEVT_SCROLL_TOP; - else if ( AreSameAdjustValues(adjust->value, adjust->upper) ) - evtType = wxEVT_SCROLL_BOTTOM; -#else evtType = GtkScrollTypeToWx(GET_SCROLL_TYPE(win->m_widget)); -#endif ProcessScrollEvent(win, evtType, dvalue); @@ -154,22 +132,22 @@ bool wxSlider::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator, const wxString& name ) { - m_acceptsFocus = TRUE; - m_needParent = TRUE; + m_acceptsFocus = true; + m_needParent = true; if (!PreCreation( parent, pos, size ) || !CreateBase( parent, id, pos, size, style, validator, name )) { wxFAIL_MSG( wxT("wxSlider creation failed") ); - return FALSE; + return false; } m_oldPos = 0.0; if (style & wxSL_VERTICAL) - m_widget = gtk_vscale_new( (GtkAdjustment *) NULL ); + m_widget = gtk_vscale_new( NULL ); else - m_widget = gtk_hscale_new( (GtkAdjustment *) NULL ); + m_widget = gtk_hscale_new( NULL ); if (style & wxSL_LABELS) { @@ -202,11 +180,6 @@ bool wxSlider::Create(wxWindow *parent, wxWindowID id, m_adjust = gtk_range_get_adjustment( GTK_RANGE(m_widget) ); -#ifdef __WXGTK20__ - if (style & wxSL_INVERSE) - gtk_range_set_inverted( GTK_RANGE(m_widget), TRUE ); -#endif - GtkEnableEvents(); gtk_signal_connect( GTK_OBJECT(m_widget), "button_press_event", @@ -224,12 +197,12 @@ bool wxSlider::Create(wxWindow *parent, wxWindowID id, PostCreation(size); - return TRUE; + return true; } int wxSlider::GetValue() const { - return AdjustValueToInt(m_adjust->value); + return wxRound(m_adjust->value); } void wxSlider::SetValue( int value ) @@ -333,15 +306,11 @@ int wxSlider::GetLineSize() const bool wxSlider::IsOwnGtkWindow( GdkWindow *window ) { GtkRange *range = GTK_RANGE(m_widget); -#ifdef __WXGTK20__ - return (range->event_window == window); -#else return ( (window == GTK_WIDGET(range)->window) || (window == range->trough) || (window == range->slider) || (window == range->step_forw) || (window == range->step_back) ); -#endif } void wxSlider::GtkDisableEvents() @@ -366,4 +335,4 @@ wxSlider::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) return GetDefaultAttributesFromGTKWidget(gtk_vscale_new); } -#endif +#endif // wxUSE_SLIDER