From 46ac60bda1986b1639a0edbe59af435d1d271058 Mon Sep 17 00:00:00 2001 From: Christopher Lam Date: Sat, 18 Jun 2022 16:36:13 +0800 Subject: [PATCH] [gnc-gtk-utils] new: gnc_get_dialog_widget_from_id --- gnucash/gnome-utils/gnc-gtk-utils.c | 35 +++++++++++++++++++++++++++++ gnucash/gnome-utils/gnc-gtk-utils.h | 2 ++ 2 files changed, 37 insertions(+) diff --git a/gnucash/gnome-utils/gnc-gtk-utils.c b/gnucash/gnome-utils/gnc-gtk-utils.c index 2dca606f59..9b69141866 100644 --- a/gnucash/gnome-utils/gnc-gtk-utils.c +++ b/gnucash/gnome-utils/gnc-gtk-utils.c @@ -297,3 +297,38 @@ gnc_style_context_get_border_color (GtkStyleContext *context, *color = *c; gdk_rgba_free (c); } + +static gpointer +find_widget_func (GtkWidget *widget, const gchar *id) +{ + const gchar *name = gtk_buildable_get_name (GTK_BUILDABLE(widget)); + GtkWidget *ret = NULL; + + if (g_strcmp0 (name, id) == 0) + return widget; + + if (GTK_IS_CONTAINER(widget)) + { + GList *container_list = gtk_container_get_children (GTK_CONTAINER(widget)); + for (GList *n = container_list; !ret && n; n = n->next) + ret = find_widget_func (n->data, id); + g_list_free (container_list); + } + + return ret; +} + +/** Find the Widget defined by 'id' in the dialog + * + * @param dialog The dialog to search for 'id'. + * + * @param id The widget name to find in the dialog. + * + * @returns The widget defined by id in the dialog or NULL. + */ +GtkWidget * +gnc_get_dialog_widget_from_id (GtkDialog *dialog, const gchar *id) +{ + GtkWidget *content_area = gtk_dialog_get_content_area (dialog); + return find_widget_func (content_area, id); +} diff --git a/gnucash/gnome-utils/gnc-gtk-utils.h b/gnucash/gnome-utils/gnc-gtk-utils.h index 6651f76f0c..b227eec0c8 100644 --- a/gnucash/gnome-utils/gnc-gtk-utils.h +++ b/gnucash/gnome-utils/gnc-gtk-utils.h @@ -53,6 +53,8 @@ void gnc_style_context_get_border_color (GtkStyleContext *context, GtkStateFlags state, GdkRGBA *color); +GtkWidget *gnc_get_dialog_widget_from_id (GtkDialog *dialog, const gchar *id); + /** @} */ #endif /* GNC_GTK_UTILS_H */