[gtk/wip/otte/boxes: 44/52] widget: Add a GtkWidget::root property and gtk_widget_get_root()



commit ddf2a3681d8629c042e0a081b6c0a21f01b60676
Author: Benjamin Otte <otte redhat com>
Date:   Sun Jul 29 03:40:52 2018 +0200

    widget: Add a GtkWidget::root property and gtk_widget_get_root()
    
    The property is just for API completeness, the getter is meant to
    replace toplevel usage.

 gtk/gtkwidget.c        | 40 ++++++++++++++++++++++++++++++++++++++++
 gtk/gtkwidget.h        |  7 +++++--
 gtk/gtkwidgetprivate.h |  6 ++++++
 3 files changed, 51 insertions(+), 2 deletions(-)
---
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 23ac98c154..96b932c4a1 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -507,6 +507,7 @@ enum {
   PROP_0,
   PROP_NAME,
   PROP_PARENT,
+  PROP_ROOT,
   PROP_WIDTH_REQUEST,
   PROP_HEIGHT_REQUEST,
   PROP_VISIBLE,
@@ -964,6 +965,19 @@ gtk_widget_class_init (GtkWidgetClass *klass)
                            GTK_TYPE_WIDGET,
                            GTK_PARAM_READABLE|G_PARAM_EXPLICIT_NOTIFY);
 
+  /**
+   * GtkWidget:root:
+   *
+   * The #GtkRoot widget of the widget tree containing this widget or %NULL if
+   * the widget is not contained in a root widget.
+   */
+  widget_props[PROP_ROOT] =
+      g_param_spec_object ("root",
+                           P_("Root widget"),
+                           P_("The root widget in the widget tree."),
+                           GTK_TYPE_ROOT,
+                           GTK_PARAM_READABLE|G_PARAM_EXPLICIT_NOTIFY);
+
   widget_props[PROP_WIDTH_REQUEST] =
       g_param_spec_int ("width-request",
                         P_("Width request"),
@@ -2384,6 +2398,9 @@ gtk_widget_get_property (GObject         *object,
     case PROP_PARENT:
       g_value_set_object (value, priv->parent);
       break;
+    case PROP_ROOT:
+      g_value_set_object (value, priv->root);
+      break;
     case PROP_WIDTH_REQUEST:
       {
         int w;
@@ -3031,6 +3048,8 @@ gtk_widget_root (GtkWidget *widget)
   priv->root = priv->parent->priv->root;
 
   GTK_WIDGET_GET_CLASS (widget)->root (widget);
+
+  g_object_notify_by_pspec (G_OBJECT (widget), widget_props[PROP_ROOT]);
 }
 
 static void
@@ -3048,6 +3067,8 @@ gtk_widget_unroot (GtkWidget *widget)
   GTK_WIDGET_GET_CLASS (widget)->unroot (widget);
 
   priv->root = NULL;
+
+  g_object_notify_by_pspec (G_OBJECT (widget), widget_props[PROP_ROOT]);
 }
 
 /**
@@ -6736,6 +6757,25 @@ gtk_widget_get_parent (GtkWidget *widget)
   return priv->parent;
 }
 
+/**
+ * gtk_widget_get_root:
+ * @widget: a #GtkWidget
+ *
+ * Returns the #GtkRoot widget of @widget or %NULL if the widget is not contained
+ * inside a widget tree with a root widget.
+ *
+ * #GtkRoot widgets will return themselves here.
+ *
+ * Returns: (transfer none) (nullable): the root widget of @widget, or %NULL
+ **/
+GtkRoot *
+gtk_widget_get_root (GtkWidget *widget)
+{
+  g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
+
+  return _gtk_widget_get_root (widget);
+}
+
 static void
 gtk_widget_real_direction_changed (GtkWidget        *widget,
                                    GtkTextDirection  previous_direction)
diff --git a/gtk/gtkwidget.h b/gtk/gtkwidget.h
index 7afc676351..7e6b91b041 100644
--- a/gtk/gtkwidget.h
+++ b/gtk/gtkwidget.h
@@ -564,13 +564,16 @@ GDK_AVAILABLE_IN_ALL
 void                  gtk_widget_set_parent             (GtkWidget    *widget,
                                                          GtkWidget    *parent);
 GDK_AVAILABLE_IN_ALL
-GtkWidget           * gtk_widget_get_parent             (GtkWidget    *widget);
+GtkWidget *           gtk_widget_get_parent             (GtkWidget    *widget);
+
+GDK_AVAILABLE_IN_ALL
+GtkRoot *             gtk_widget_get_root               (GtkWidget    *widget);
 
 GDK_AVAILABLE_IN_ALL
 void                  gtk_widget_set_parent_surface     (GtkWidget    *widget,
                                                          GdkSurface    *parent_surface);
 GDK_AVAILABLE_IN_ALL
-GdkSurface           * gtk_widget_get_parent_surface    (GtkWidget    *widget);
+GdkSurface *          gtk_widget_get_parent_surface    (GtkWidget    *widget);
 
 GDK_AVAILABLE_IN_ALL
 void                  gtk_widget_set_child_visible      (GtkWidget    *widget,
diff --git a/gtk/gtkwidgetprivate.h b/gtk/gtkwidgetprivate.h
index acc8eca031..14e23a16ea 100644
--- a/gtk/gtkwidgetprivate.h
+++ b/gtk/gtkwidgetprivate.h
@@ -422,6 +422,12 @@ _gtk_widget_get_toplevel (GtkWidget *widget)
   return widget;
 }
 
+static inline GtkRoot *
+_gtk_widget_get_root (GtkWidget *widget)
+{
+  return widget->priv->root;
+}
+
 static inline GdkDisplay *
 _gtk_widget_get_display (GtkWidget *widget)
 {


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