[glade] Bug 351645 - glade-utils.[ch]: Add glade_util_remove_scroll_events()



commit 7f67005a6000a3fd5acf5bfc27074fc23e3623e6
Author: Tristan Van Berkom <tristan vanberkom codethink co uk>
Date:   Sat Oct 29 18:23:08 2016 +0900

    Bug 351645 - glade-utils.[ch]: Add glade_util_remove_scroll_events()
    
    Allow plugins to use the event propagation hack we use to avoid
    scroll events in a scrolled window being eaten up by child widgets.
    
    From patch contributed by Lukas K <lu 0x83 eu>

 gladeui/glade-utils.c |   34 ++++++++++++++++++++++++++++++++++
 gladeui/glade-utils.h |    2 ++
 2 files changed, 36 insertions(+), 0 deletions(-)
---
diff --git a/gladeui/glade-utils.c b/gladeui/glade-utils.c
index 6fbc5d2..dcfd9d6 100644
--- a/gladeui/glade-utils.c
+++ b/gladeui/glade-utils.c
@@ -2023,3 +2023,37 @@ glade_utils_get_pointer (GtkWidget *widget,
   if (y)
     *y = final_y;
 }
+
+/* Use this to disable scroll events on property editors,
+ * we dont want them handling scroll because they are inside
+ * a scrolled window and interrupt workflow causing unexpected
+ * results when scrolled.
+ */
+static gint
+abort_scroll_events (GtkWidget *widget,
+                    GdkEvent  *event,
+                    gpointer   user_data)
+{
+  GtkWidget *parent = gtk_widget_get_parent (widget);
+
+  /* Removing the events from the mask doesnt work for
+   * stubborn combo boxes which call gtk_widget_add_events()
+   * in it's gtk_combo_box_init() - so handle the event and propagate
+   * it up the tree so the scrollwindow still handles the scroll event.
+   */
+  gtk_propagate_event (parent, event);
+
+  return TRUE;
+}
+
+void
+glade_util_remove_scroll_events (GtkWidget *widget)
+{
+  gint events = gtk_widget_get_events (widget);
+
+  events &= ~(GDK_SCROLL_MASK | GDK_SMOOTH_SCROLL_MASK);
+  gtk_widget_set_events (widget, events);
+
+  g_signal_connect (G_OBJECT (widget), "scroll-event",
+                   G_CALLBACK (abort_scroll_events), NULL);
+}
diff --git a/gladeui/glade-utils.h b/gladeui/glade-utils.h
index ca02a5b..9c8839c 100644
--- a/gladeui/glade-utils.h
+++ b/gladeui/glade-utils.h
@@ -132,6 +132,8 @@ void              glade_utils_get_pointer (GtkWidget *widget,
                                           gint      *y);
 
 
+void glade_util_remove_scroll_events (GtkWidget *widget);
+
 G_END_DECLS
 
 #endif /* __GLADE_UTILS_H__ */


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