+// ----------------------------------------------------------------------------
+// helper functions
+// ----------------------------------------------------------------------------
+
+// process a scroll event
+static void
+ProcessScrollEvent(wxSlider *win, wxEventType evtType)
+{
+ const int orient = win->HasFlag(wxSL_VERTICAL) ? wxVERTICAL
+ : wxHORIZONTAL;
+
+ const int value = win->GetValue();
+
+ // if we have any "special" event (i.e. the value changed by a line or a
+ // page), send this specific event first
+ if ( evtType != wxEVT_NULL )
+ {
+ wxScrollEvent event( evtType, win->GetId(), value, orient );
+ event.SetEventObject( win );
+ win->HandleWindowEvent( event );
+ }
+
+ // but, in any case, except if we're dragging the slider (and so the change
+ // is not definitive), send a generic "changed" event
+ if ( evtType != wxEVT_SCROLL_THUMBTRACK )
+ {
+ wxScrollEvent event(wxEVT_SCROLL_CHANGED, win->GetId(), value, orient);
+ event.SetEventObject( win );
+ win->HandleWindowEvent( event );
+ }
+
+ // and also generate a command event for compatibility
+ wxCommandEvent event( wxEVT_SLIDER, win->GetId() );
+ event.SetEventObject( win );
+ event.SetInt( value );
+ win->HandleWindowEvent( event );
+}
+
+static inline wxEventType GtkScrollTypeToWx(int scrollType)
+{
+ wxEventType eventType;
+ switch (scrollType)
+ {
+ case GTK_SCROLL_STEP_BACKWARD:
+ case GTK_SCROLL_STEP_LEFT:
+ case GTK_SCROLL_STEP_UP:
+ eventType = wxEVT_SCROLL_LINEUP;
+ break;
+ case GTK_SCROLL_STEP_DOWN:
+ case GTK_SCROLL_STEP_FORWARD:
+ case GTK_SCROLL_STEP_RIGHT:
+ eventType = wxEVT_SCROLL_LINEDOWN;
+ break;
+ case GTK_SCROLL_PAGE_BACKWARD:
+ case GTK_SCROLL_PAGE_LEFT:
+ case GTK_SCROLL_PAGE_UP:
+ eventType = wxEVT_SCROLL_PAGEUP;
+ break;
+ case GTK_SCROLL_PAGE_DOWN:
+ case GTK_SCROLL_PAGE_FORWARD:
+ case GTK_SCROLL_PAGE_RIGHT:
+ eventType = wxEVT_SCROLL_PAGEDOWN;
+ break;
+ case GTK_SCROLL_START:
+ eventType = wxEVT_SCROLL_TOP;
+ break;
+ case GTK_SCROLL_END:
+ eventType = wxEVT_SCROLL_BOTTOM;
+ break;
+ case GTK_SCROLL_JUMP:
+ eventType = wxEVT_SCROLL_THUMBTRACK;
+ break;
+ default:
+ wxFAIL_MSG(wxT("Unknown GtkScrollType"));
+ eventType = wxEVT_NULL;
+ break;
+ }
+ return eventType;
+}
+
+// Determine if increment is the same as +/-x, allowing for some small
+// difference due to possible inexactness in floating point arithmetic
+static inline bool IsScrollIncrement(double increment, double x)
+{
+ wxASSERT(increment > 0);
+ const double tolerance = 1.0 / 1024;
+ return fabs(increment - fabs(x)) < tolerance;
+}