[gtk/wip/baedert/single-node-window: 8/11] main: Inline propagate_{down, up} in propagate_internal()



commit 3afc2bcf3f5b016ac76f93a5aad6f2df0d6d8917
Author: Timm Bäder <mail baedert org>
Date:   Fri May 8 10:32:57 2020 +0200

    main: Inline propagate_{down,up} in propagate_internal()
    
    Don't have to worry about anyone calling the up/down variants on their
    own this way.

 gtk/gtkmain.c | 94 ++++++++++++++++++++---------------------------------------
 1 file changed, 31 insertions(+), 63 deletions(-)
---
diff --git a/gtk/gtkmain.c b/gtk/gtkmain.c
index aad1e0b683..787abd4b23 100644
--- a/gtk/gtkmain.c
+++ b/gtk/gtkmain.c
@@ -2097,55 +2097,10 @@ gtk_get_event_widget (GdkEvent *event)
   return NULL;
 }
 
-static gboolean
-propagate_event_up (GtkWidget *widget,
-                    GdkEvent  *event,
-                    GtkWidget *topmost)
-{
-  gboolean handled_event = FALSE;
-  GtkWidget *target = widget;
-
-  /* Propagate event up the widget tree so that
-   * parents can see the button and motion
-   * events of the children.
-   */
-  while (TRUE)
-    {
-      GtkWidget *tmp;
-
-      g_object_ref (widget);
-
-      /* Scroll events are special cased here because it
-       * feels wrong when scrolling a GtkViewport, say,
-       * to have children of the viewport eat the scroll
-       * event
-       */
-      if (!_gtk_widget_is_sensitive (widget))
-        handled_event = gdk_event_get_event_type (event) != GDK_SCROLL;
-      else if (_gtk_widget_get_realized (widget))
-        handled_event = gtk_widget_event (widget, event, target);
-
-      handled_event |= !_gtk_widget_get_realized (widget);
-
-      tmp = _gtk_widget_get_parent (widget);
-      g_object_unref (widget);
-
-      if (widget == topmost)
-        break;
-
-      widget = tmp;
-
-      if (handled_event || !widget)
-        break;
-    }
-
-  return handled_event;
-}
-
-static gboolean
-propagate_event_down (GtkWidget *widget,
-                      GdkEvent  *event,
-                      GtkWidget *topmost)
+gboolean
+gtk_propagate_event_internal (GtkWidget *widget,
+                              GdkEvent  *event,
+                              GtkWidget *topmost)
 {
   gint handled_event = FALSE;
   GtkWidget *target = widget;
@@ -2153,6 +2108,7 @@ propagate_event_down (GtkWidget *widget,
   GtkWidget *stack_widgets[16];
   int i;
 
+  /* First, propagate event down */
   gtk_array_init (&widget_array, (void**)stack_widgets, 16);
   gtk_array_add (&widget_array, g_object_ref (widget));
 
@@ -2197,24 +2153,36 @@ propagate_event_down (GtkWidget *widget,
       i--;
     }
 
-  gtk_array_free (&widget_array, g_object_unref);
+  /* If not yet handled, also propagate down */
+  if (!handled_event)
+    {
+      /* Propagate event up the widget tree so that
+       * parents can see the button and motion
+       * events of the children.
+       */
+      for (i = 0; i < widget_array.len; i++)
+        {
+          widget = gtk_array_index (&widget_array, i);
 
-  return handled_event;
-}
+          /* Scroll events are special cased here because it
+           * feels wrong when scrolling a GtkViewport, say,
+           * to have children of the viewport eat the scroll
+           * event
+           */
+          if (!_gtk_widget_is_sensitive (widget))
+            handled_event = gdk_event_get_event_type (event) != GDK_SCROLL;
+          else if (_gtk_widget_get_realized (widget))
+            handled_event = gtk_widget_event (widget, event, target);
 
-gboolean
-gtk_propagate_event_internal (GtkWidget *widget,
-                              GdkEvent  *event,
-                              GtkWidget *topmost)
-{
-  /* Propagate the event down and up */
-  if (propagate_event_down (widget, event, topmost))
-    return TRUE;
+          handled_event |= !_gtk_widget_get_realized (widget);
 
-  if (propagate_event_up (widget, event, topmost))
-    return TRUE;
+          if (handled_event)
+            break;
+        }
+    }
 
-  return FALSE;
+  gtk_array_free (&widget_array, g_object_unref);
+  return handled_event;
 }
 
 /**


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