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



commit a0c4380c5c171ca5a11e7e19e238e0c91baf3fbc
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 026479e..70c5c76 100644
--- a/gtk/gtkrange.c
+++ b/gtk/gtkrange.c
@@ -2285,18 +2285,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)
 {
@@ -2304,18 +2293,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 fcfd861..907fb7d 100644
--- a/gtk/gtkrangeprivate.h
+++ b/gtk/gtkrangeprivate.h
@@ -32,8 +32,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 07bd5ec..13268f0 100644
--- a/gtk/gtkscrollbar.c
+++ b/gtk/gtkscrollbar.c
@@ -316,3 +316,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 e20c18b..5b817ad 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"
@@ -3262,11 +3261,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]