scrollbar: Add accessor for wheel delta

Make the one in gtkrange.c static since it was only ever used from
GtkScrolledWindow.
This commit is contained in:
Timm Bäder 2017-05-10 19:38:17 +02:00 committed by Matthias Clasen
parent 706bc08b68
commit 753e915f87
5 changed files with 46 additions and 26 deletions

View File

@ -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))
{

View File

@ -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);

View File

@ -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;
}

View File

@ -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

View File

@ -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),