[gnc-gtk-utils] new: gnc_get_dialog_widget_from_id

This commit is contained in:
Christopher Lam 2022-06-18 16:36:13 +08:00
parent 263f007d5c
commit 46ac60bda1
2 changed files with 37 additions and 0 deletions

View File

@ -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);
}

View File

@ -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 */