[gtk+/wip/baedert/drawing: 15/37] scrollbar: Add accessor for wheel delta
- From: Timm Bäder <baedert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/baedert/drawing: 15/37] scrollbar: Add accessor for wheel delta
- Date: Sun, 14 May 2017 17:20:17 +0000 (UTC)
commit 3f351474e00ab85252fbeae5487f9d00e4806707
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 4815198..a0f1f04 100644
--- a/gtk/gtkrange.c
+++ b/gtk/gtkrange.c
@@ -2354,18 +2354,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)
{
@@ -2373,18 +2362,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 50c4a70..555ed9c 100644
--- a/gtk/gtkscrollbar.c
+++ b/gtk/gtkscrollbar.c
@@ -301,3 +301,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]