[nautilus-actions] na_gtk_utils_find_widget_by_type(): new function



commit 8c11225b11fa5087ea5b0f03ac59a62a23f4c461
Author: Pierre Wieser <pwieser trychlos org>
Date:   Fri Dec 23 19:30:34 2011 +0100

    na_gtk_utils_find_widget_by_type(): new function

 ChangeLog               |    5 +++++
 src/core/na-gtk-utils.c |   31 +++++++++++++++++++++++++++++++
 src/core/na-gtk-utils.h |    1 +
 3 files changed, 37 insertions(+), 0 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 368ce9d..20be08d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -11,6 +11,11 @@
 	* src/nact/nact-application.c:
 	* src/nact/nact-application.h (nact_application_new): Have an empty constructor.
 
+2011-12-23 Pierre Wieser <pwieser trychlos org>
+
+	* src/core/na-gtk-utils.c:
+	* src/core/na-gtk-utils.h (na_gtk_utils_find_widget_by_type): New function.
+
 2011-12-22 Pierre Wieser <pwieser trychlos org>
 
 	* src/core/na-export-format.c: Remove superfluous gdk-pixbuf.h include.
diff --git a/src/core/na-gtk-utils.c b/src/core/na-gtk-utils.c
index 0dbd1b6..d707d02 100644
--- a/src/core/na-gtk-utils.c
+++ b/src/core/na-gtk-utils.c
@@ -42,6 +42,37 @@ static GList *position_to_int_list( gint x, gint y, gint width, gint height );
 static void   free_int_list( GList *list );
 
 /*
+ * na_gtk_utils_find_widget_by_type:
+ * @container: a #GtkContainer, usually the #GtkWindow toplevel.
+ * @type: the searched #GType.
+ *
+ * Returns: the first child widget which is of @type type.
+ */
+GtkWidget *
+na_gtk_utils_find_widget_by_type( GtkContainer *container, GType type )
+{
+	GList *children = gtk_container_get_children( container );
+	GList *ic;
+	GtkWidget *found = NULL;
+	GtkWidget *child;
+	const gchar *child_name;
+
+	for( ic = children ; ic && !found ; ic = ic->next ){
+
+		if( GTK_IS_WIDGET( ic->data )){
+			if( G_OBJECT_TYPE( ic->data ) == type ){
+				found = GTK_WIDGET( ic->data );
+			} else if( GTK_IS_CONTAINER( child )){
+				found = na_gtk_utils_find_widget_by_type( GTK_CONTAINER( child ), type );
+			}
+		}
+	}
+
+	g_list_free( children );
+	return( found );
+}
+
+/*
  * na_gtk_utils_search_for_child_widget:
  * @container: a #GtkContainer, usually the #GtkWindow toplevel.
  * @name: the name of the searched widget.
diff --git a/src/core/na-gtk-utils.h b/src/core/na-gtk-utils.h
index 4f496c3..e3b929d 100644
--- a/src/core/na-gtk-utils.h
+++ b/src/core/na-gtk-utils.h
@@ -40,6 +40,7 @@
 
 G_BEGIN_DECLS
 
+GtkWidget *na_gtk_utils_find_widget_by_type    ( GtkContainer *container, GType type );
 GtkWidget *na_gtk_utils_search_for_child_widget( GtkContainer *container, const gchar *name );
 
 #ifdef NA_MAINTAINER_MODE



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