[gtk+/wip/baedert/drawing] scrollbar: Add accessor for wheel delta



commit 49525e0647e60f5f8d9ead546b9700a47f8a3e22
Author: Timm Bäder <mail baedert org>
Date:   Wed May 10 19:38:17 2017 +0200

    scrollbar: Add accessor for wheel delta
    
    Make the one in gtkrange.c static since it was only ever used from
    GtkScrolledWindow.

 gtk/gtkrange.c          |   20 ++------------------
 gtk/gtkrangeprivate.h   |    2 --
 gtk/gtkscrollbar.c      |   40 ++++++++++++++++++++++++++++++++++++++++
 gtk/gtkscrollbar.h      |    3 +++
 gtk/gtkscrolledwindow.c |    7 +------
 5 files changed, 46 insertions(+), 26 deletions(-)
---
diff --git a/gtk/gtkrange.c b/gtk/gtkrange.c
index d452766..fcb2247 100644
--- a/gtk/gtkrange.c
+++ b/gtk/gtkrange.c
@@ -2343,18 +2343,7 @@ stop_scrolling (GtkRange *range)
   remove_autoscroll (range);
 }
 
-/**
- * _gtk_range_get_wheel_delta:
- * @range: a #GtkRange
- * @event: A #GdkEventScroll
- *
- * Returns a good step value for the mouse wheel.
- *
- * Returns: A good step value for the mouse wheel.
- *
- * Since: 2.4
- **/
-gdouble
+static gdouble
 _gtk_range_get_wheel_delta (GtkRange       *range,
                             GdkEventScroll *event)
 {
@@ -2362,18 +2351,13 @@ _gtk_range_get_wheel_delta (GtkRange       *range,
   GtkAdjustment *adjustment = priv->adjustment;
   gdouble dx, dy;
   gdouble delta = 0;
-  gdouble page_size;
   gdouble page_increment;
   gdouble scroll_unit;
   GdkScrollDirection direction;
 
-  page_size = gtk_adjustment_get_page_size (adjustment);
   page_increment = gtk_adjustment_get_page_increment (adjustment);
 
-  if (GTK_IS_SCROLLBAR (range))
-    scroll_unit = pow (page_size, 2.0 / 3.0);
-  else
-    scroll_unit = page_increment;
+  scroll_unit = page_increment;
 
   if (gdk_event_get_scroll_deltas ((GdkEvent *) event, &dx, &dy))
     {
diff --git a/gtk/gtkrangeprivate.h b/gtk/gtkrangeprivate.h
index 8b1b25e..61ee88e 100644
--- a/gtk/gtkrangeprivate.h
+++ b/gtk/gtkrangeprivate.h
@@ -33,8 +33,6 @@
 
 G_BEGIN_DECLS
 
-gdouble            _gtk_range_get_wheel_delta              (GtkRange       *range,
-                                                            GdkEventScroll *event);
 void               _gtk_range_set_has_origin               (GtkRange      *range,
                                                             gboolean       has_origin);
 gboolean           _gtk_range_get_has_origin               (GtkRange      *range);
diff --git a/gtk/gtkscrollbar.c b/gtk/gtkscrollbar.c
index d79bc9a..4642276 100644
--- a/gtk/gtkscrollbar.c
+++ b/gtk/gtkscrollbar.c
@@ -296,3 +296,43 @@ gtk_scrollbar_get_adjustment (GtkScrollbar  *self)
 
   return gtk_range_get_adjustment (GTK_RANGE (priv->range));
 }
+
+double
+gtk_scrollbar_get_wheel_delta (GtkScrollbar         *self,
+                               const GdkEventScroll *event)
+{
+  GtkScrollbarPrivate *priv = gtk_scrollbar_get_instance_private (self);
+  GtkAdjustment *adjustment;
+  gdouble dx, dy;
+  gdouble delta = 0;
+  gdouble page_size;
+  gdouble scroll_unit;
+  GdkScrollDirection direction;
+
+  adjustment = gtk_scrollbar_get_adjustment (self);
+  page_size = gtk_adjustment_get_page_size (adjustment);
+
+  scroll_unit = pow (page_size, 2.0 / 3.0);
+
+  if (gdk_event_get_scroll_deltas ((GdkEvent *) event, &dx, &dy))
+    {
+#ifdef GDK_WINDOWING_QUARTZ
+      scroll_unit = 1;
+#endif
+
+      if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
+        delta = - (dx ? dx : dy) * scroll_unit;
+      else
+        delta = dy * scroll_unit;
+    }
+  else if (gdk_event_get_scroll_direction ((GdkEvent *) event, &direction))
+    {
+      if (direction == GDK_SCROLL_UP ||
+          direction == GDK_SCROLL_LEFT)
+        delta = - scroll_unit;
+      else
+        delta = scroll_unit;
+    }
+
+  return delta;
+}
diff --git a/gtk/gtkscrollbar.h b/gtk/gtkscrollbar.h
index ec6307c..1844c53 100644
--- a/gtk/gtkscrollbar.h
+++ b/gtk/gtkscrollbar.h
@@ -73,6 +73,9 @@ void           gtk_scrollbar_set_adjustment (GtkScrollbar  *self,
                                              GtkAdjustment *adjustment);
 GDK_AVAILABLE_IN_3_92
 GtkAdjustment *gtk_scrollbar_get_adjustment (GtkScrollbar  *self);
+GDK_AVAILABLE_IN_3_92
+double         gtk_scrollbar_get_wheel_delta (GtkScrollbar         *self,
+                                              const GdkEventScroll *event);
 
 G_END_DECLS
 
diff --git a/gtk/gtkscrolledwindow.c b/gtk/gtkscrolledwindow.c
index 8a044ee..058a288 100644
--- a/gtk/gtkscrolledwindow.c
+++ b/gtk/gtkscrolledwindow.c
@@ -36,7 +36,6 @@
 #include "gtkprivate.h"
 #include "gtkscrollable.h"
 #include "gtkscrollbar.h"
-#include "gtkrangeprivate.h"
 #include "gtktypebuiltins.h"
 #include "gtkviewport.h"
 #include "gtkwidgetprivate.h"
@@ -3345,11 +3344,7 @@ gtk_scrolled_window_scroll_event (GtkWidget      *widget,
           gdouble new_value;
           gdouble delta;
 
-#if 0
-TODO: What to do here with the new scrollbars?
-          delta = _gtk_range_get_wheel_delta (GTK_SCROLLBAR (range), event);
-#endif
-          delta = 1;
+          delta = gtk_scrollbar_get_wheel_delta (GTK_SCROLLBAR (range), event);
 
           new_value = CLAMP (gtk_adjustment_get_value (adj) + delta,
                              gtk_adjustment_get_lower (adj),


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]