[libdazzle] util: add helper to get relative widget
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libdazzle] util: add helper to get relative widget
- Date: Mon, 10 Jul 2017 01:28:14 +0000 (UTC)
commit 9d5a95512fc38c5cd5764cd44bc480ae6d6108f1
Author: Christian Hergert <chergert redhat com>
Date: Sun Jul 9 18:26:55 2017 -0700
util: add helper to get relative widget
This is useful when you want to look through the semantic
hierarchy rather than the real ->parent hierarchy.
src/util/dzl-gtk.c | 30 ++++++++++++++++++++++++++++++
src/util/dzl-gtk.h | 2 ++
2 files changed, 32 insertions(+), 0 deletions(-)
---
diff --git a/src/util/dzl-gtk.c b/src/util/dzl-gtk.c
index 107861d..ee4fbbf 100644
--- a/src/util/dzl-gtk.c
+++ b/src/util/dzl-gtk.c
@@ -648,3 +648,33 @@ dzl_gtk_widget_is_ancestor_or_relative (GtkWidget *widget,
return FALSE;
}
+
+/**
+ * dzl_gtk_widget_get_relative:
+ * @widget: a #GtkWidget
+ * @relative_type: the type of widget to locate
+ *
+ * This is similar to gtk_widget_get_ancestor(), but looks for relatives
+ * via properties such as #GtkPopover:relative-to and others.
+ *
+ * Returns: (transfer none) (nullable): A #GtkWidget or %NULL.
+ */
+GtkWidget *
+dzl_gtk_widget_get_relative (GtkWidget *widget,
+ GType relative_type)
+{
+ g_return_val_if_fail (!widget || GTK_IS_WIDGET (widget), NULL);
+ g_return_val_if_fail (g_type_is_a (relative_type, GTK_TYPE_WIDGET), NULL);
+
+ if (widget == NULL)
+ return FALSE;
+
+ do
+ {
+ if (g_type_is_a (G_OBJECT_TYPE (widget), relative_type))
+ return widget;
+ }
+ while (NULL != (widget = get_parent_or_relative (widget)));
+
+ return NULL;
+}
diff --git a/src/util/dzl-gtk.h b/src/util/dzl-gtk.h
index 4956fea..42a0a0f 100644
--- a/src/util/dzl-gtk.h
+++ b/src/util/dzl-gtk.h
@@ -56,6 +56,8 @@ void dzl_gtk_list_store_insert_sorted (GtkListStore *s
guint compare_column,
GCompareDataFunc compare_func,
gpointer compare_data);
+GtkWidget *dzl_gtk_widget_get_relative (GtkWidget *widget,
+ GType relative_type);
gboolean dzl_gtk_widget_is_ancestor_or_relative (GtkWidget *widget,
GtkWidget *ancestor);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]