2004-12-14 [colin] 0.9.13cvs17
[claws.git] / src / gtk / gtkutils.c
index 95813f96ace2fc8a77f030467906423cfb4486e6..ca6cedf80928f4d5fe90860fa4b582cb25aa9af1 100644 (file)
@@ -704,3 +704,52 @@ void gtkut_set_widget_bgcolor_rgb(GtkWidget *widget, guint rgbvalue)
        gtk_widget_set_style(widget, newstyle);
 }
 
+/*!
+ *\brief       Tries to find a focused child using a lame strategy
+ */
+GtkWidget *gtkut_get_focused_child(GtkContainer *parent)
+{
+       GtkWidget *result = NULL;
+       GList *child_list = NULL;
+       GList *c;
+
+       g_return_val_if_fail(parent, NULL);
+
+       /* Get children list and see which has the focus. */
+       child_list = gtk_container_children(parent);
+       if (!child_list)
+               return NULL;
+       for (c = child_list; c != NULL; c = g_list_next(c)) {
+               if (c->data && GTK_IS_WIDGET(c->data)) {
+                       if (GTK_WIDGET_HAS_FOCUS(GTK_WIDGET(c->data))) {
+                               result = GTK_WIDGET(c->data);
+                               break;
+                       }
+               }
+       }
+       
+       /* See if the returned widget is a container itself; if it is,
+        * see if one of its children is focused. If the focused 
+        * container has no focused child, it is itself a focusable 
+        * child, and has focus. */
+       if (result && GTK_IS_CONTAINER(result)) {
+               GtkWidget *tmp =  gtkut_get_focused_child(GTK_CONTAINER(result)); 
+               
+               if (tmp) 
+                       result = tmp;
+       } else {
+               /* Try the same for each container in the chain */
+               for (c = child_list; c != NULL && !result; c = g_list_next(c)) {
+                       if (c->data && GTK_IS_WIDGET(c->data) 
+                       &&  GTK_IS_CONTAINER(c->data)) {
+                               result = gtkut_get_focused_child
+                                       (GTK_CONTAINER(c->data));
+                       }
+               }
+       
+       }
+       
+       g_list_free(child_list);
+               
+       return result;
+}