From ccd1d40dd9565c11cd3fabf8c19bec4f29669cf7 Mon Sep 17 00:00:00 2001 From: Paul Cornett Date: Mon, 12 Dec 2016 10:55:19 -0800 Subject: [PATCH] Avoid generating scroll event when our scrollbar is disabled by other software webkitgtk apparently manipulates our scrollbar GtkAdjustment directly, setting all members to zero to disable it. Since we never do that, those values were unexpected. This is a better fix for the problem papered over by 45d66f592 --- src/gtk/window.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index 0f6b23e5fd..e7710e3940 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -5117,9 +5117,7 @@ int wxWindowGTK::GetScrollRange( int orient ) const // difference due to possible inexactness in floating point arithmetic static inline bool IsScrollIncrement(double increment, double x) { - wxASSERT(increment >= 0); - if ( increment == 0. ) - return false; + wxASSERT(increment > 0); const double tolerance = 1.0 / 1024; return fabs(increment - fabs(x)) < tolerance; } @@ -5130,14 +5128,18 @@ wxEventType wxWindowGTK::GTKGetScrollEventType(GtkRange* range) const int barIndex = range == m_scrollBar[1]; - const double value = gtk_range_get_value(range); + GtkAdjustment* adj = gtk_range_get_adjustment(range); + const double value = gtk_adjustment_get_value(adj); // save previous position const double oldPos = m_scrollPos[barIndex]; // update current position m_scrollPos[barIndex] = value; // If event should be ignored, or integral position has not changed - if (g_blockEventsOnDrag || wxRound(value) == wxRound(oldPos)) + // or scrollbar is disabled (webkitgtk is known to cause a "value-changed" + // by setting the GtkAdjustment to all zeros) + if (g_blockEventsOnDrag || wxRound(value) == wxRound(oldPos) || + gtk_adjustment_get_upper(adj) <= gtk_adjustment_get_page_size(adj)) { return wxEVT_NULL; } @@ -5149,7 +5151,6 @@ wxEventType wxWindowGTK::GTKGetScrollEventType(GtkRange* range) const double diff = value - oldPos; const bool isDown = diff > 0; - GtkAdjustment* adj = gtk_range_get_adjustment(range); if (IsScrollIncrement(gtk_adjustment_get_step_increment(adj), diff)) { eventType = isDown ? wxEVT_SCROLL_LINEDOWN : wxEVT_SCROLL_LINEUP;