diff options
author | Carlos Garnacho <carlosg@gnome.org> | 2015-05-23 15:51:11 +0200 |
---|---|---|
committer | Carlos Garnacho <carlosg@gnome.org> | 2015-05-24 16:58:35 +0200 |
commit | fc2830394895f236352bea2024dda0e962dd2c53 (patch) | |
tree | f23a7c27222e651a7b78c6c54e2308c1faebb68d | |
parent | eb6b72424c54e5c9ac174e02ea59dec19ebe1a16 (diff) | |
download | gtk+-fc2830394895f236352bea2024dda0e962dd2c53.tar.gz |
scrolledwindow: Refactor scroll unit guessing into a separate function
Makes it clearer, and will be used in further places.
https://bugzilla.gnome.org/show_bug.cgi?id=749770
-rw-r--r-- | gtk/gtkscrolledwindow.c | 48 |
1 files changed, 32 insertions, 16 deletions
diff --git a/gtk/gtkscrolledwindow.c b/gtk/gtkscrolledwindow.c index 24e9a6ff27..4e62efccf7 100644 --- a/gtk/gtkscrolledwindow.c +++ b/gtk/gtkscrolledwindow.c @@ -1084,6 +1084,36 @@ check_update_scrollbar_proximity (GtkScrolledWindow *sw, return indicator_close; } +static gdouble +get_scroll_unit (GtkScrolledWindow *sw, + GtkOrientation orientation) +{ + gdouble scroll_unit; + +#ifndef GDK_WINDOWING_QUARTZ + GtkScrolledWindowPrivate *priv = sw->priv; + GtkRange *scrollbar; + GtkAdjustment *adj; + gdouble page_size; + + if (orientation == GTK_ORIENTATION_HORIZONTAL) + scrollbar = GTK_RANGE (priv->hscrollbar); + else + scrollbar = GTK_RANGE (priv->vscrollbar); + + if (!scrollbar) + return 0; + + adj = gtk_range_get_adjustment (scrollbar); + page_size = gtk_adjustment_get_page_size (adj); + scroll_unit = pow (page_size, 2.0 / 3.0); +#else + scroll_unit = 1; +#endif + + return scroll_unit; +} + static gboolean captured_event_cb (GtkWidget *widget, GdkEvent *event) @@ -2976,17 +3006,10 @@ gtk_scrolled_window_scroll_event (GtkWidget *widget, { GtkAdjustment *adj; gdouble new_value; - gdouble page_size; gdouble scroll_unit; adj = gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar)); - page_size = gtk_adjustment_get_page_size (adj); - -#ifdef GDK_WINDOWING_QUARTZ - scroll_unit = 1; -#else - scroll_unit = pow (page_size, 2.0 / 3.0); -#endif + scroll_unit = get_scroll_unit (scrolled_window, GTK_ORIENTATION_HORIZONTAL); new_value = priv->unclamped_hadj_value + delta_x * scroll_unit; _gtk_scrolled_window_set_adjustment_value (scrolled_window, adj, @@ -2999,17 +3022,10 @@ gtk_scrolled_window_scroll_event (GtkWidget *widget, { GtkAdjustment *adj; gdouble new_value; - gdouble page_size; gdouble scroll_unit; adj = gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar)); - page_size = gtk_adjustment_get_page_size (adj); - -#ifdef GDK_WINDOWING_QUARTZ - scroll_unit = 1; -#else - scroll_unit = pow (page_size, 2.0 / 3.0); -#endif + scroll_unit = get_scroll_unit (scrolled_window, GTK_ORIENTATION_HORIZONTAL); new_value = priv->unclamped_vadj_value + delta_y * scroll_unit; _gtk_scrolled_window_set_adjustment_value (scrolled_window, adj, |