2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2004 Hiroyuki Yamamoto
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 #include <gdk/gdkkeysyms.h>
27 #include <gtk/gtkwidget.h>
28 #include <gtk/gtkhbbox.h>
29 #include <gtk/gtkbutton.h>
30 #include <gtk/gtkctree.h>
31 #include <gtk/gtkcombo.h>
32 #include <gtk/gtkbindings.h>
33 #include <gtk/gtkitemfactory.h>
38 #if (HAVE_WCTYPE_H && HAVE_WCHAR_H)
46 #include "gtksctree.h"
48 #include "stock_pixmap.h"
50 #include "prefs_account.h"
53 gboolean gtkut_get_font_size(GtkWidget *widget,
54 gint *width, gint *height)
57 const gchar *str = "Abcdef";
59 g_return_val_if_fail(GTK_IS_WIDGET(widget), FALSE);
61 layout = gtk_widget_create_pango_layout(widget, str);
62 g_return_val_if_fail(layout, FALSE);
63 pango_layout_get_pixel_size(layout, width, height);
65 *width = *width / g_utf8_strlen(str, -1);
66 g_object_unref(layout);
71 void gtkut_convert_int_to_gdk_color(gint rgbvalue, GdkColor *color)
73 g_return_if_fail(color != NULL);
76 color->red = (int) (((gdouble)((rgbvalue & 0xff0000) >> 16) / 255.0) * 65535.0);
77 color->green = (int) (((gdouble)((rgbvalue & 0x00ff00) >> 8) / 255.0) * 65535.0);
78 color->blue = (int) (((gdouble) (rgbvalue & 0x0000ff) / 255.0) * 65535.0);
81 void gtkut_button_set_create(GtkWidget **bbox,
82 GtkWidget **button1, const gchar *label1,
83 GtkWidget **button2, const gchar *label2,
84 GtkWidget **button3, const gchar *label3)
86 g_return_if_fail(bbox != NULL);
87 g_return_if_fail(button1 != NULL);
89 *bbox = gtk_hbutton_box_new();
90 gtk_button_box_set_layout(GTK_BUTTON_BOX(*bbox), GTK_BUTTONBOX_END);
91 gtk_box_set_spacing(GTK_BOX(*bbox), 5);
93 *button1 = gtk_button_new_with_label(label1);
94 GTK_WIDGET_SET_FLAGS(*button1, GTK_CAN_DEFAULT);
95 gtk_box_pack_start(GTK_BOX(*bbox), *button1, TRUE, TRUE, 0);
96 gtk_widget_show(*button1);
99 *button2 = gtk_button_new_with_label(label2);
100 GTK_WIDGET_SET_FLAGS(*button2, GTK_CAN_DEFAULT);
101 gtk_box_pack_start(GTK_BOX(*bbox), *button2, TRUE, TRUE, 0);
102 gtk_widget_show(*button2);
106 *button3 = gtk_button_new_with_label(label3);
107 GTK_WIDGET_SET_FLAGS(*button3, GTK_CAN_DEFAULT);
108 gtk_box_pack_start(GTK_BOX(*bbox), *button3, TRUE, TRUE, 0);
109 gtk_widget_show(*button3);
113 static void combo_button_size_request(GtkWidget *widget,
114 GtkRequisition *requisition,
117 ComboButton *combo = (ComboButton *)data;
119 if (combo->arrow->allocation.height != requisition->height)
120 gtk_widget_set_usize(combo->arrow, -1, requisition->height);
123 static void combo_button_enter(GtkWidget *widget, gpointer data)
125 ComboButton *combo = (ComboButton *)data;
127 if (GTK_WIDGET_STATE(combo->arrow) != GTK_STATE_PRELIGHT) {
128 gtk_widget_set_state(combo->arrow, GTK_STATE_PRELIGHT);
129 gtk_widget_queue_draw(combo->arrow);
131 if (GTK_WIDGET_STATE(combo->button) != GTK_STATE_PRELIGHT) {
132 gtk_widget_set_state(combo->button, GTK_STATE_PRELIGHT);
133 gtk_widget_queue_draw(combo->button);
137 static void combo_button_leave(GtkWidget *widget, gpointer data)
139 ComboButton *combo = (ComboButton *)data;
141 if (GTK_WIDGET_STATE(combo->arrow) != GTK_STATE_NORMAL) {
142 gtk_widget_set_state(combo->arrow, GTK_STATE_NORMAL);
143 gtk_widget_queue_draw(combo->arrow);
145 if (GTK_WIDGET_STATE(combo->button) != GTK_STATE_NORMAL) {
146 gtk_widget_set_state(combo->button, GTK_STATE_NORMAL);
147 gtk_widget_queue_draw(combo->button);
151 static gint combo_button_arrow_pressed(GtkWidget *widget, GdkEventButton *event,
154 ComboButton *combo = (ComboButton *)data;
156 if (!event) return FALSE;
158 gtk_menu_popup(GTK_MENU(combo->menu), NULL, NULL,
159 menu_button_position, combo->button,
160 event->button, event->time);
165 static void combo_button_destroy(GtkWidget *widget, gpointer data)
167 ComboButton *combo = (ComboButton *)data;
169 gtk_object_destroy(GTK_OBJECT(combo->factory));
173 ComboButton *gtkut_combo_button_create(GtkWidget *button,
174 GtkItemFactoryEntry *entries,
175 gint n_entries, const gchar *path,
181 combo = g_new0(ComboButton, 1);
183 combo->arrow = gtk_button_new();
184 arrow = gtk_arrow_new(GTK_ARROW_DOWN, GTK_SHADOW_OUT);
185 gtk_container_add(GTK_CONTAINER(combo->arrow), arrow);
186 GTK_WIDGET_UNSET_FLAGS(combo->arrow, GTK_CAN_FOCUS);
187 gtk_widget_show_all(combo->arrow);
189 combo->button = button;
190 combo->menu = menu_create_items(entries, n_entries, path,
191 &combo->factory, data);
194 g_signal_connect(G_OBJECT(combo->button), "size_request",
195 G_CALLBACK(combo_button_size_request), combo);
196 g_signal_connect(G_OBJECT(combo->button), "enter",
197 G_CALLBACK(combo_button_enter), combo);
198 g_signal_connect(G_OBJECT(combo->button), "leave",
199 G_CALLBACK(combo_button_leave), combo);
200 g_signal_connect(G_OBJECT(combo->arrow), "enter",
201 G_CALLBACK(combo_button_enter), combo);
202 g_signal_connect(G_OBJECT(combo->arrow), "leave",
203 G_CALLBACK(combo_button_leave), combo);
204 g_signal_connect(G_OBJECT(combo->arrow), "button_press_event",
205 G_CALLBACK(combo_button_arrow_pressed), combo);
206 g_signal_connect(G_OBJECT(combo->arrow), "destroy",
207 G_CALLBACK(combo_button_destroy), combo);
212 #define CELL_SPACING 1
213 #define ROW_TOP_YPIXEL(clist, row) (((clist)->row_height * (row)) + \
214 (((row) + 1) * CELL_SPACING) + \
216 #define ROW_FROM_YPIXEL(clist, y) (((y) - (clist)->voffset) / \
217 ((clist)->row_height + CELL_SPACING))
219 void gtkut_ctree_node_move_if_on_the_edge(GtkCTree *ctree, GtkCTreeNode *node)
221 GtkCList *clist = GTK_CLIST(ctree);
223 GtkVisibility row_visibility, prev_row_visibility, next_row_visibility;
225 g_return_if_fail(ctree != NULL);
226 g_return_if_fail(node != NULL);
228 row = g_list_position(clist->row_list, (GList *)node);
229 if (row < 0 || row >= clist->rows || clist->row_height == 0) return;
230 row_visibility = gtk_clist_row_is_visible(clist, row);
231 prev_row_visibility = gtk_clist_row_is_visible(clist, row - 1);
232 next_row_visibility = gtk_clist_row_is_visible(clist, row + 1);
234 if (row_visibility == GTK_VISIBILITY_NONE) {
235 gtk_clist_moveto(clist, row, -1, 0.5, 0);
238 if (row_visibility == GTK_VISIBILITY_FULL &&
239 prev_row_visibility == GTK_VISIBILITY_FULL &&
240 next_row_visibility == GTK_VISIBILITY_FULL)
242 if (prev_row_visibility != GTK_VISIBILITY_FULL &&
243 next_row_visibility != GTK_VISIBILITY_FULL)
246 if (prev_row_visibility != GTK_VISIBILITY_FULL) {
247 gtk_clist_moveto(clist, row, -1, 0.2, 0);
250 if (next_row_visibility != GTK_VISIBILITY_FULL) {
251 gtk_clist_moveto(clist, row, -1, 0.8, 0);
257 #undef ROW_TOP_YPIXEL
258 #undef ROW_FROM_YPIXEL
260 gint gtkut_ctree_get_nth_from_node(GtkCTree *ctree, GtkCTreeNode *node)
262 g_return_val_if_fail(ctree != NULL, -1);
263 g_return_val_if_fail(node != NULL, -1);
265 return g_list_position(GTK_CLIST(ctree)->row_list, (GList *)node);
268 /* get the next node, including the invisible one */
269 GtkCTreeNode *gtkut_ctree_node_next(GtkCTree *ctree, GtkCTreeNode *node)
271 GtkCTreeNode *parent;
273 if (!node) return NULL;
275 if (GTK_CTREE_ROW(node)->children)
276 return GTK_CTREE_ROW(node)->children;
278 if (GTK_CTREE_ROW(node)->sibling)
279 return GTK_CTREE_ROW(node)->sibling;
281 for (parent = GTK_CTREE_ROW(node)->parent; parent != NULL;
282 parent = GTK_CTREE_ROW(parent)->parent) {
283 if (GTK_CTREE_ROW(parent)->sibling)
284 return GTK_CTREE_ROW(parent)->sibling;
290 /* get the previous node, including the invisible one */
291 GtkCTreeNode *gtkut_ctree_node_prev(GtkCTree *ctree, GtkCTreeNode *node)
296 if (!node) return NULL;
298 prev = GTK_CTREE_NODE_PREV(node);
299 if (prev == GTK_CTREE_ROW(node)->parent)
303 while (GTK_CTREE_ROW(child)->children != NULL) {
304 child = GTK_CTREE_ROW(child)->children;
305 while (GTK_CTREE_ROW(child)->sibling != NULL)
306 child = GTK_CTREE_ROW(child)->sibling;
312 gboolean gtkut_ctree_node_is_selected(GtkCTree *ctree, GtkCTreeNode *node)
314 GtkCList *clist = GTK_CLIST(ctree);
317 for (cur = clist->selection; cur != NULL; cur = cur->next) {
318 if (node == GTK_CTREE_NODE(cur->data))
325 GtkCTreeNode *gtkut_ctree_find_collapsed_parent(GtkCTree *ctree,
328 if (!node) return NULL;
330 while ((node = GTK_CTREE_ROW(node)->parent) != NULL) {
331 if (!GTK_CTREE_ROW(node)->expanded)
338 void gtkut_ctree_expand_parent_all(GtkCTree *ctree, GtkCTreeNode *node)
340 while ((node = gtkut_ctree_find_collapsed_parent(ctree, node)) != NULL)
341 gtk_ctree_expand(ctree, node);
344 gboolean gtkut_ctree_node_is_parent(GtkCTreeNode *parent, GtkCTreeNode *node)
347 g_return_val_if_fail(node != NULL, FALSE);
348 g_return_val_if_fail(parent != NULL, FALSE);
352 if(GTK_CTREE_ROW(tmp)->parent && GTK_CTREE_ROW(tmp)->parent == parent)
354 tmp = GTK_CTREE_ROW(tmp)->parent;
360 void gtkut_ctree_set_focus_row(GtkCTree *ctree, GtkCTreeNode *node)
362 gtkut_clist_set_focus_row(GTK_CLIST(ctree),
363 gtkut_ctree_get_nth_from_node(ctree, node));
366 void gtkut_clist_set_focus_row(GtkCList *clist, gint row)
368 clist->focus_row = row;
369 GTKUT_CTREE_REFRESH(clist);
372 void gtkut_combo_set_items(GtkCombo *combo, const gchar *str1, ...)
376 GList *combo_items = NULL;
378 g_return_if_fail(str1 != NULL);
380 combo_items = g_list_append(combo_items, (gpointer)str1);
381 va_start(args, str1);
382 s = va_arg(args, gchar*);
384 combo_items = g_list_append(combo_items, (gpointer)s);
385 s = va_arg(args, gchar*);
389 gtk_combo_set_popdown_strings(combo, combo_items);
391 g_list_free(combo_items);
394 gchar *gtkut_editable_get_selection(GtkEditable *editable)
396 guint start_pos, end_pos;
399 g_return_val_if_fail(GTK_IS_EDITABLE(editable), NULL);
401 found = gtk_editable_get_selection_bounds(editable,
402 &start_pos, &end_pos);
404 return gtk_editable_get_chars(editable, start_pos, end_pos);
409 void gtkut_editable_disable_im(GtkEditable *editable)
411 g_return_if_fail(editable != NULL);
415 gdk_ic_destroy(editable->ic);
418 if (editable->ic_attr) {
419 gdk_ic_attr_destroy(editable->ic_attr);
420 editable->ic_attr = NULL;
426 * Walk through the widget tree and disclaim the selection from all currently
427 * realized GtkEditable widgets.
429 static void gtkut_check_before_remove(GtkWidget *widget, gpointer unused)
431 g_return_if_fail(widget != NULL);
433 if (!GTK_WIDGET_REALIZED(widget))
434 return; /* all nested widgets must be unrealized too */
435 if (GTK_IS_CONTAINER(widget))
436 gtk_container_forall(GTK_CONTAINER(widget),
437 gtkut_check_before_remove, NULL);
440 if (GTK_IS_EDITABLE(widget))
441 gtk_editable_claim_selection(GTK_EDITABLE(widget),
442 FALSE, GDK_CURRENT_TIME);
447 * Wrapper around gtk_container_remove to work around a bug in GtkText and
448 * GtkEntry (in all GTK+ versions up to and including at least 1.2.10).
450 * The problem is that unrealizing a GtkText or GtkEntry widget which has the
451 * active selection completely messes up selection handling, leading to
452 * non-working selections and crashes. Removing a widget from its container
453 * implies unrealizing it and all its child widgets; this triggers the bug if
454 * the removed widget or any of its children is GtkText or GtkEntry. As a
455 * workaround, this function walks through the widget subtree before removing
456 * and disclaims the selection from all GtkEditable widgets found.
458 * A similar workaround may be needed for gtk_widget_reparent(); currently it
459 * is not necessary because Sylpheed does not use gtk_widget_reparent() for
460 * GtkEditable widgets or containers holding such widgets.
462 void gtkut_container_remove(GtkContainer *container, GtkWidget *widget)
464 gtkut_check_before_remove(widget, NULL);
465 gtk_container_remove(container, widget);
468 void gtkut_window_popup(GtkWidget *window)
470 gint x, y, sx, sy, new_x, new_y;
472 g_return_if_fail(window != NULL);
473 g_return_if_fail(window->window != NULL);
475 sx = gdk_screen_width();
476 sy = gdk_screen_height();
478 gdk_window_get_origin(window->window, &x, &y);
479 new_x = x % sx; if (new_x < 0) new_x = 0;
480 new_y = y % sy; if (new_y < 0) new_y = 0;
481 if (new_x != x || new_y != y)
482 gdk_window_move(window->window, new_x, new_y);
484 gdk_window_raise(window->window);
485 gdk_window_show(window->window);
488 void gtkut_widget_get_uposition(GtkWidget *widget, gint *px, gint *py)
493 g_return_if_fail(widget != NULL);
494 g_return_if_fail(widget->window != NULL);
496 sx = gdk_screen_width();
497 sy = gdk_screen_height();
499 /* gdk_window_get_root_origin ever return *rootwindow*'s position */
500 gdk_window_get_root_origin(widget->window, &x, &y);
502 x %= sx; if (x < 0) x = 0;
503 y %= sy; if (y < 0) y = 0;
508 void gtkut_widget_disable_theme_engine(GtkWidget *widget)
512 GtkStyle *style, *new_style;
514 style = gtk_widget_get_style(widget);
517 GtkThemeEngine *engine;
519 engine = style->engine;
520 style->engine = NULL;
521 new_style = gtk_style_copy(style);
522 style->engine = engine;
523 gtk_widget_set_style(widget, new_style);
528 void gtkut_widget_wait_for_draw(GtkWidget *widget)
530 if (!GTK_WIDGET_DRAWABLE(widget)) return;
532 while (gtk_events_pending())
533 gtk_main_iteration();
536 static void gtkut_clist_bindings_add(GtkWidget *clist)
538 GtkBindingSet *binding_set;
540 binding_set = gtk_binding_set_by_class
541 (GTK_CLIST_GET_CLASS(clist));
543 gtk_binding_entry_add_signal(binding_set, GDK_n, GDK_CONTROL_MASK,
544 "scroll_vertical", 2,
545 G_TYPE_ENUM, GTK_SCROLL_STEP_FORWARD,
547 gtk_binding_entry_add_signal(binding_set, GDK_p, GDK_CONTROL_MASK,
548 "scroll_vertical", 2,
549 G_TYPE_ENUM, GTK_SCROLL_STEP_BACKWARD,
553 void gtkut_widget_init(void)
557 clist = gtk_clist_new(1);
558 g_object_ref(G_OBJECT(clist));
559 gtk_object_sink(GTK_OBJECT(clist));
560 gtkut_clist_bindings_add(clist);
561 g_object_unref(G_OBJECT(clist));
563 clist = gtk_ctree_new(1, 0);
564 g_object_ref(G_OBJECT(clist));
565 gtk_object_sink(GTK_OBJECT(clist));
566 gtkut_clist_bindings_add(clist);
567 g_object_unref(G_OBJECT(clist));
569 clist = gtk_sctree_new_with_titles(1, 0, NULL);
570 g_object_ref(G_OBJECT(clist));
571 gtk_object_sink(GTK_OBJECT(clist));
572 gtkut_clist_bindings_add(clist);
573 g_object_unref(G_OBJECT(clist));
576 void gtkut_widget_set_app_icon(GtkWidget *widget)
578 #include "pixmaps/sylpheed.xpm"
579 static GdkPixmap *sylpheedxpm;
580 static GdkBitmap *sylpheedxpmmask;
582 g_return_if_fail(widget != NULL);
583 g_return_if_fail(widget->window != NULL);
585 PIXMAP_CREATE(widget, sylpheedxpm, sylpheedxpmmask, sylpheed_xpm);
587 gdk_window_set_icon(widget->window, NULL, sylpheedxpm, sylpheedxpmmask);
590 void gtkut_widget_set_composer_icon(GtkWidget *widget)
592 static GdkPixmap *xpm;
593 static GdkBitmap *bmp;
595 g_return_if_fail(widget != NULL);
596 g_return_if_fail(widget->window != NULL);
598 stock_pixmap_gdk(widget, STOCK_PIXMAP_MAIL_COMPOSE, &xpm, &bmp);
600 gdk_window_set_icon(widget->window, NULL, xpm, bmp);
603 GtkWidget *gtkut_account_menu_new(GList *ac_list,
610 g_return_val_if_fail(ac_list != NULL, NULL);
612 menu = gtk_menu_new();
614 for (cur_ac = ac_list; cur_ac != NULL; cur_ac = cur_ac->next) {
617 PrefsAccount *account;
619 account = (PrefsAccount *) cur_ac->data;
621 name = g_strdup_printf("%s: %s <%s>",
622 account->account_name,
626 name = g_strdup_printf("%s: %s",
627 account->account_name,
629 MENUITEM_ADD(menu, menuitem, name, account->account_id);
631 if (callback != NULL)
632 g_signal_connect(G_OBJECT(menuitem), "activate",
638 void gtkut_set_widget_bgcolor_rgb(GtkWidget *widget, guint rgbvalue)
643 gtkut_convert_int_to_gdk_color(rgbvalue, &gdk_color);
644 newstyle = gtk_style_copy(gtk_widget_get_default_style());
645 newstyle->bg[GTK_STATE_NORMAL] = gdk_color;
646 newstyle->bg[GTK_STATE_PRELIGHT] = gdk_color;
647 newstyle->bg[GTK_STATE_ACTIVE] = gdk_color;
648 gtk_widget_set_style(widget, newstyle);
651 gboolean gtkut_text_buffer_match_string(GtkTextBuffer *textbuf, gint pos, gunichar *wcs,
652 gint len, gboolean case_sens)
654 GtkTextIter start_iter, end_iter;
656 gint match_count = 0;
658 gtk_text_buffer_get_iter_at_offset(textbuf, &start_iter, pos);
659 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter, pos + len);
661 utf8str = gtk_text_buffer_get_text(textbuf, &start_iter, &end_iter, FALSE);
662 if (!utf8str) return FALSE;
664 if ((gint) g_utf8_strlen(utf8str, -1) != len) {
669 for (; match_count < len; pos++, match_count++) {
670 gchar *ptr = g_utf8_offset_to_pointer(utf8str, match_count);
674 ch = g_utf8_get_char(ptr);
677 if (ch != wcs[match_count])
680 if (g_unichar_tolower(ch) !=
681 g_unichar_tolower(wcs[match_count]))
688 if (match_count == len)
694 guint gtkut_text_buffer_str_compare_n(GtkTextBuffer *textbuf,
695 guint pos1, guint pos2,
696 guint len, guint text_len)
700 for (i = 0; i < len && pos1 + i < text_len && pos2 + i < text_len; i++) {
701 GtkTextIter start_iter, end_iter;
702 gchar *utf8str1, *utf8str2;
704 gtk_text_buffer_get_iter_at_offset(textbuf, &start_iter,
706 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
708 utf8str1 = gtk_text_buffer_get_text(textbuf,
713 gtk_text_buffer_get_iter_at_offset(textbuf, &start_iter,
715 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
717 utf8str2 = gtk_text_buffer_get_text(textbuf,
722 if (!utf8str1 || !utf8str2 || strcmp(utf8str1, utf8str2)) {
735 guint gtkut_text_buffer_str_compare(GtkTextBuffer *textbuf,
736 guint start_pos, guint text_len,
741 glong items_read = 0, items_written = 0;
743 GError *error = NULL;
747 wcs = g_utf8_to_ucs4(str, -1, &items_read, &items_written, &error);
749 g_warning("An error occured while converting a string from UTF-8 to UCS-4: %s\n",
753 if (!wcs || items_written <= 0) return 0;
754 len = (guint) items_written;
756 if (len > text_len - start_pos)
759 result = gtkut_text_buffer_match_string(textbuf, start_pos,
765 return result ? len : 0;
768 gboolean gtkut_text_buffer_is_uri_string(GtkTextBuffer *textbuf,
769 guint start_pos, guint text_len)
771 if (gtkut_text_buffer_str_compare(textbuf, start_pos, text_len, "http://") ||
772 gtkut_text_buffer_str_compare(textbuf, start_pos, text_len, "ftp://") ||
773 gtkut_text_buffer_str_compare(textbuf, start_pos, text_len, "https://") ||
774 gtkut_text_buffer_str_compare(textbuf, start_pos, text_len, "www."))
780 gchar *gtkut_text_view_get_selection(GtkTextView *textview)
782 GtkTextBuffer *buffer;
783 GtkTextIter start_iter, end_iter;
786 g_return_val_if_fail(GTK_IS_TEXT_VIEW(textview), NULL);
788 buffer = gtk_text_view_get_buffer(textview);
789 found = gtk_text_buffer_get_selection_bounds(buffer,
793 return gtk_text_buffer_get_text(buffer, &start_iter, &end_iter,
800 *\brief Tries to find a focused child using a lame strategy
802 GtkWidget *gtkut_get_focused_child(GtkContainer *parent)
804 GtkWidget *result = NULL;
805 GList *child_list = NULL;
808 g_return_val_if_fail(parent, NULL);
810 /* Get children list and see which has the focus. */
811 child_list = gtk_container_get_children(parent);
815 for (c = child_list; c != NULL; c = g_list_next(c)) {
816 if (c->data && GTK_IS_WIDGET(c->data)) {
817 if (GTK_WIDGET_HAS_FOCUS(GTK_WIDGET(c->data))) {
818 result = GTK_WIDGET(c->data);
824 /* See if the returned widget is a container itself; if it is,
825 * see if one of its children is focused. If the focused
826 * container has no focused child, it is itself a focusable
827 * child, and has focus. */
828 if (result && GTK_IS_CONTAINER(result)) {
829 GtkWidget *tmp = gtkut_get_focused_child(GTK_CONTAINER(result));
834 /* Try the same for each container in the chain */
835 for (c = child_list; c != NULL && !result; c = g_list_next(c)) {
836 if (c->data && GTK_IS_WIDGET(c->data)
837 && GTK_IS_CONTAINER(c->data)) {
838 result = gtkut_get_focused_child
839 (GTK_CONTAINER(c->data));
845 g_list_free(child_list);