]> git.saurik.com Git - wxWidgets.git/commitdiff
use native lines/columns per action for mouse wheel event
authorPaul Cornett <paulcor@bullseye.com>
Sat, 14 Sep 2013 18:06:54 +0000 (18:06 +0000)
committerPaul Cornett <paulcor@bullseye.com>
Sat, 14 Sep 2013 18:06:54 +0000 (18:06 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@74805 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/gtk/window.cpp

index 81b957556c9c765815c0629d75ff5a39727e760a..c07c5dbe4d6983291dad109da737f38e5a14e49f 100644 (file)
@@ -1614,30 +1614,18 @@ gtk_window_motion_notify_callback( GtkWidget * WXUNUSED(widget),
 // "scroll_event" (mouse wheel event)
 //-----------------------------------------------------------------------------
 
-static gboolean
-window_scroll_event_hscrollbar(GtkWidget*, GdkEventScroll* gdk_event, wxWindow* win)
+// Compute lines/columns per action the same way as private GTK+ function
+// _gtk_range_get_wheel_delta()
+static inline int GetWheelScrollActionDelta(GtkRange* range)
 {
-    if (gdk_event->direction != GDK_SCROLL_LEFT &&
-        gdk_event->direction != GDK_SCROLL_RIGHT)
-    {
-        return false;
-    }
-
-    GtkRange *range = win->m_scrollBar[wxWindow::ScrollDir_Horz];
-
-    if (range && gtk_widget_get_visible(GTK_WIDGET(range)))
+    int d = 3;
+    if (range)
     {
         GtkAdjustment* adj = gtk_range_get_adjustment(range);
-        double delta = gtk_adjustment_get_step_increment(adj) * 3;
-        if (gdk_event->direction == GDK_SCROLL_LEFT)
-            delta = -delta;
-
-        gtk_range_set_value(range, gtk_adjustment_get_value(adj) + delta);
-
-        return TRUE;
+        const double page_size = gtk_adjustment_get_page_size(adj);
+        d = wxRound(pow(page_size, 2.0 / 3.0));
     }
-
-    return FALSE;
+    return d;
 }
 
 static gboolean
@@ -1646,84 +1634,35 @@ window_scroll_event(GtkWidget*, GdkEventScroll* gdk_event, wxWindow* win)
     wxMouseEvent event(wxEVT_MOUSEWHEEL);
     InitMouseEvent(win, event, gdk_event);
 
-    // FIXME: Get these values from GTK or GDK
-    event.m_linesPerAction = 3;
-    event.m_columnsPerAction = 3;
     event.m_wheelDelta = 120;
 
-    // Determine the scroll direction.
-    switch (gdk_event->direction)
-    {
-        case GDK_SCROLL_UP:
-        case GDK_SCROLL_RIGHT:
-            event.m_wheelRotation = 120;
-            break;
-
-        case GDK_SCROLL_DOWN:
-        case GDK_SCROLL_LEFT:
-            event.m_wheelRotation = -120;
-            break;
-#if GTK_CHECK_VERSION(3,4,0)
-        case GDK_SCROLL_SMOOTH:
-            // TODO
-#endif
-        default:
-            return false;  // Unknown/unhandled direction
-    }
-
-    // And the scroll axis.
-    switch (gdk_event->direction)
-    {
-        case GDK_SCROLL_UP:
-        case GDK_SCROLL_DOWN:
-            event.m_wheelAxis = wxMOUSE_WHEEL_VERTICAL;
-            break;
-
-        case GDK_SCROLL_LEFT:
-        case GDK_SCROLL_RIGHT:
-            event.m_wheelAxis = wxMOUSE_WHEEL_HORIZONTAL;
-            break;
-#if GTK_CHECK_VERSION(3,4,0)
-        case GDK_SCROLL_SMOOTH:
-            // TODO
-            break;
-#endif
-    }
-
-    if (win->GTKProcessEvent(event))
-      return TRUE;
-
     GtkRange *range;
     switch (gdk_event->direction)
     {
         case GDK_SCROLL_UP:
         case GDK_SCROLL_DOWN:
             range = win->m_scrollBar[wxWindow::ScrollDir_Vert];
+            event.m_wheelAxis = wxMOUSE_WHEEL_VERTICAL;
             break;
-
         case GDK_SCROLL_LEFT:
         case GDK_SCROLL_RIGHT:
             range = win->m_scrollBar[wxWindow::ScrollDir_Horz];
+            event.m_wheelAxis = wxMOUSE_WHEEL_HORIZONTAL;
             break;
-
         default:
             return false;
     }
 
-    if (range && gtk_widget_get_visible(GTK_WIDGET(range)))
+    event.m_wheelRotation = event.m_wheelDelta;
+    if (gdk_event->direction == GDK_SCROLL_UP ||
+        gdk_event->direction == GDK_SCROLL_LEFT)
     {
-        GtkAdjustment* adj = gtk_range_get_adjustment(range);
-        double delta = gtk_adjustment_get_step_increment(adj) * 3;
-        if (gdk_event->direction == GDK_SCROLL_UP ||
-            gdk_event->direction == GDK_SCROLL_LEFT)
-            delta = -delta;
-
-        gtk_range_set_value(range, gtk_adjustment_get_value(adj) + delta);
-
-        return TRUE;
+        event.m_wheelRotation = -event.m_wheelRotation;
     }
+    event.m_linesPerAction = GetWheelScrollActionDelta(range);
+    event.m_columnsPerAction = event.m_linesPerAction;
 
-    return FALSE;
+    return win->GTKProcessEvent(event);
 }
 
 //-----------------------------------------------------------------------------
@@ -2656,7 +2595,7 @@ void wxWindowGTK::ConnectWidget( GtkWidget *widget )
                       G_CALLBACK (window_scroll_event), this);
     if (m_scrollBar[ScrollDir_Horz])
         g_signal_connect (m_scrollBar[ScrollDir_Horz], "scroll_event",
-                      G_CALLBACK (window_scroll_event_hscrollbar), this);
+                      G_CALLBACK (window_scroll_event), this);
     if (m_scrollBar[ScrollDir_Vert])
         g_signal_connect (m_scrollBar[ScrollDir_Vert], "scroll_event",
                       G_CALLBACK (window_scroll_event), this);