+ const int i = orient == wxVERTICAL;
+ return int(m_scrollBar[i]->adjustment->upper);
+}
+
+// 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;
+}
+
+wxEventType wxWindow::GetScrollEventType(GtkRange* range)
+{
+ DEBUG_MAIN_THREAD
+
+ if (g_isIdle)
+ wxapp_install_idle_handler();
+
+ wxASSERT(range == m_scrollBar[0] || range == m_scrollBar[1]);
+
+ const int barIndex = range == m_scrollBar[1];
+ GtkAdjustment* adj = range->adjustment;
+ const int value = int(adj->value + 0.5);
+ // save previous position
+ const double oldPos = m_scrollPos[barIndex];
+ // update current position
+ m_scrollPos[barIndex] = adj->value;
+ // If event should be ignored, or integral position has not changed
+ if (!m_hasVMT || g_blockEventsOnDrag || m_blockScrollEvent || value == int(oldPos + 0.5))
+ {
+ return wxEVT_NULL;
+ }
+
+ wxEventType eventType = wxEVT_SCROLL_THUMBTRACK;
+ if (!m_isScrolling)
+ {
+ // Difference from last change event
+ const double diff = adj->value - oldPos;
+ const bool isDown = diff > 0;
+
+ if (IsScrollIncrement(adj->step_increment, diff))
+ {
+ eventType = isDown ? wxEVT_SCROLL_LINEDOWN : wxEVT_SCROLL_LINEUP;
+ }
+ else if (IsScrollIncrement(adj->page_increment, diff))
+ {
+ eventType = isDown ? wxEVT_SCROLL_PAGEDOWN : wxEVT_SCROLL_PAGEUP;
+ }
+ else if (m_mouseButtonDown)
+ {
+ // Assume track event
+ m_isScrolling = true;
+ }
+ }
+ return eventType;