Commit a658b220 authored by Benjamin Otte's avatar Benjamin Otte
Browse files

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.
parent 34b33bf0
......@@ -505,6 +505,7 @@ enum {
PROP_0,
PROP_NAME,
PROP_PARENT,
PROP_ROOT,
PROP_WIDTH_REQUEST,
PROP_HEIGHT_REQUEST,
PROP_VISIBLE,
......@@ -966,6 +967,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"),
......@@ -2393,6 +2407,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;
......@@ -3043,6 +3060,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
......@@ -3060,6 +3079,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]);
}
/**
......@@ -6851,6 +6872,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)
......
......@@ -570,13 +570,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,
......
......@@ -420,6 +420,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)
{
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment