[gnome-photos/wip/rishi/zoom: 4/9] utils: Add convenience API for GtkScrolledWindow



commit 82d27aba079ac2cf419bc9328948773c2440611a
Author: Debarshi Ray <debarshir gnome org>
Date:   Tue May 16 20:21:02 2017 +0200

    utils: Add convenience API for GtkScrolledWindow
    
    These will be used to scroll a zoomed image in PhotosImageView.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=742662

 src/photos-utils.c |   69 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/photos-utils.h |    6 ++++
 2 files changed, 75 insertions(+), 0 deletions(-)
---
diff --git a/src/photos-utils.c b/src/photos-utils.c
index e12c336..1c1c231 100644
--- a/src/photos-utils.c
+++ b/src/photos-utils.c
@@ -1217,6 +1217,75 @@ photos_utils_object_list_free_full (GList *objects)
 }
 
 
+static gboolean
+photos_utils_adjustment_can_scroll (GtkAdjustment *adjustment)
+{
+  gdouble lower;
+  gdouble page_size;
+  gdouble upper;
+
+  g_return_val_if_fail (GTK_IS_ADJUSTMENT (adjustment), FALSE);
+
+  lower = gtk_adjustment_get_lower (adjustment);
+  page_size = gtk_adjustment_get_page_size (adjustment);
+  upper = gtk_adjustment_get_upper (adjustment);
+
+  return upper - lower > page_size;
+}
+
+
+gboolean
+photos_utils_scrolled_window_can_scroll (GtkScrolledWindow *scrolled_window)
+{
+  GtkAdjustment *adjustment;
+  gboolean ret_val = TRUE;
+
+  g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), FALSE);
+
+  adjustment = gtk_scrolled_window_get_hadjustment (scrolled_window);
+  if (photos_utils_adjustment_can_scroll (adjustment))
+    goto out;
+
+  adjustment = gtk_scrolled_window_get_vadjustment (scrolled_window);
+  if (photos_utils_adjustment_can_scroll (adjustment))
+    goto out;
+
+  ret_val = FALSE;
+
+ out:
+  return ret_val;
+}
+
+
+static void
+photos_utils_adjustment_scroll (GtkAdjustment *adjustment, gdouble delta)
+{
+  gdouble value;
+
+  g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
+
+  value = gtk_adjustment_get_value (adjustment);
+  value += delta;
+  gtk_adjustment_set_value (adjustment, value);
+}
+
+
+void
+photos_utils_scrolled_window_scroll (GtkScrolledWindow *scrolled_window, gdouble delta_x, gdouble delta_y)
+{
+  GtkAdjustment *adjustment;
+
+  g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
+  g_return_if_fail (photos_utils_scrolled_window_can_scroll (scrolled_window));
+
+  adjustment = gtk_scrolled_window_get_hadjustment (scrolled_window);
+  photos_utils_adjustment_scroll (adjustment, delta_x);
+
+  adjustment = gtk_scrolled_window_get_vadjustment (scrolled_window);
+  photos_utils_adjustment_scroll (adjustment, delta_y);
+}
+
+
 static void
 photos_utils_update_executed (GObject *source_object, GAsyncResult *res, gpointer user_data)
 {
diff --git a/src/photos-utils.h b/src/photos-utils.h
index 5ec8bd3..9bb9de1 100644
--- a/src/photos-utils.h
+++ b/src/photos-utils.h
@@ -159,6 +159,12 @@ void             photos_utils_list_box_header_func        (GtkListBoxRow *row,
 
 void             photos_utils_object_list_free_full       (GList *objects);
 
+gboolean         photos_utils_scrolled_window_can_scroll  (GtkScrolledWindow *scrolled_window);
+
+void             photos_utils_scrolled_window_scroll      (GtkScrolledWindow *scrolled_window,
+                                                           gdouble delta_x,
+                                                           gdouble delta_y);
+
 void             photos_utils_set_edited_name             (const gchar *urn, const gchar *title);
 
 void             photos_utils_set_favorite                (const gchar *urn, gboolean is_favorite);


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