From 5b1da3b4397606654c31fd221215b25faee93770 Mon Sep 17 00:00:00 2001 From: Christopher James Lahey Date: Mon, 7 Aug 2000 20:20:37 +0000 Subject: Added e_container_change_tab_order. 2000-08-07 Christopher James Lahey * e-gui-utils.c, e-gui-utils.c: Added e_container_change_tab_order. svn path=/trunk/; revision=4580 --- e-util/ChangeLog | 5 +++ e-util/e-gui-utils.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++ e-util/e-gui-utils.h | 3 +- widgets/misc/e-gui-utils.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++ widgets/misc/e-gui-utils.h | 3 +- 5 files changed, 171 insertions(+), 2 deletions(-) diff --git a/e-util/ChangeLog b/e-util/ChangeLog index e3f3f89943..d315be574f 100644 --- a/e-util/ChangeLog +++ b/e-util/ChangeLog @@ -1,3 +1,8 @@ +2000-08-07 Christopher James Lahey + + * e-gui-utils.c, e-gui-utils.c: Added + e_container_change_tab_order. + 2000-07-27 Peter Williams * e-canvas.c (e_canvas_destroy): Chain the diff --git a/e-util/e-gui-utils.c b/e-util/e-gui-utils.c index 5d53c64d35..2e31eb101b 100644 --- a/e-util/e-gui-utils.c +++ b/e-util/e-gui-utils.c @@ -136,3 +136,84 @@ e_container_foreach_leaf(GtkContainer *container, callback_closure.closure = closure; gtk_container_foreach(container, (GtkCallback) e_container_foreach_leaf_callback, &callback_closure); } + +static void +e_container_change_tab_order_destroy_notify(gpointer data) +{ + GList *list = data; + g_list_foreach(list, (GFunc) gtk_object_unref, NULL); + g_list_free(list); +} + + +static gint +e_container_change_tab_order_callback(GtkContainer *container, + GtkDirectionType direction, + GList *children) +{ + GtkWidget *focus_child; + GtkWidget *child; + + if (direction != GTK_DIR_TAB_FORWARD && + direction != GTK_DIR_TAB_BACKWARD) + return FALSE; + + focus_child = container->focus_child; + + if (direction == GTK_DIR_TAB_BACKWARD) { + children = g_list_last(children); + } + + while (children) { + child = children->data; + if (direction == GTK_DIR_TAB_FORWARD) + children = children->next; + else + children = children->prev; + + if (!child) + continue; + + if (focus_child) { + if (focus_child == child) { + focus_child = NULL; + + if (GTK_WIDGET_DRAWABLE (child) && + GTK_IS_CONTAINER (child) && + !GTK_WIDGET_HAS_FOCUS (child)) + if (gtk_container_focus (GTK_CONTAINER (child), direction)) { + gtk_signal_emit_stop_by_name(GTK_OBJECT(container), "focus"); + return TRUE; + } + } + } + else if (GTK_WIDGET_DRAWABLE (child)) { + if (GTK_IS_CONTAINER (child)) { + if (gtk_container_focus (GTK_CONTAINER (child), direction)) { + gtk_signal_emit_stop_by_name(GTK_OBJECT(container), "focus"); + return TRUE; + } + } + else if (GTK_WIDGET_CAN_FOCUS (child)) { + gtk_widget_grab_focus (child); + gtk_signal_emit_stop_by_name(GTK_OBJECT(container), "focus"); + return TRUE; + } + } + } + + return FALSE; +} + +gint +e_container_change_tab_order(GtkContainer *container, GList *widgets) +{ + GList *list; + list = g_list_copy(widgets); + g_list_foreach(list, (GFunc) gtk_object_ref, NULL); + return gtk_signal_connect_full(GTK_OBJECT(container), "focus", + GTK_SIGNAL_FUNC(e_container_change_tab_order_callback), + NULL, list, + e_container_change_tab_order_destroy_notify, + FALSE, FALSE); +} diff --git a/e-util/e-gui-utils.h b/e-util/e-gui-utils.h index c1958879aa..1d47a7b514 100644 --- a/e-util/e-gui-utils.h +++ b/e-util/e-gui-utils.h @@ -13,6 +13,7 @@ GtkWidget *e_create_image_widget (gchar *name, gchar *string1, gchar *string void e_container_foreach_leaf (GtkContainer *container, GtkCallback callback, gpointer closure); - +gint e_container_change_tab_order (GtkContainer *container, + GList *widgets); #endif /* E_GUI_UTILS_H */ diff --git a/widgets/misc/e-gui-utils.c b/widgets/misc/e-gui-utils.c index 5d53c64d35..2e31eb101b 100644 --- a/widgets/misc/e-gui-utils.c +++ b/widgets/misc/e-gui-utils.c @@ -136,3 +136,84 @@ e_container_foreach_leaf(GtkContainer *container, callback_closure.closure = closure; gtk_container_foreach(container, (GtkCallback) e_container_foreach_leaf_callback, &callback_closure); } + +static void +e_container_change_tab_order_destroy_notify(gpointer data) +{ + GList *list = data; + g_list_foreach(list, (GFunc) gtk_object_unref, NULL); + g_list_free(list); +} + + +static gint +e_container_change_tab_order_callback(GtkContainer *container, + GtkDirectionType direction, + GList *children) +{ + GtkWidget *focus_child; + GtkWidget *child; + + if (direction != GTK_DIR_TAB_FORWARD && + direction != GTK_DIR_TAB_BACKWARD) + return FALSE; + + focus_child = container->focus_child; + + if (direction == GTK_DIR_TAB_BACKWARD) { + children = g_list_last(children); + } + + while (children) { + child = children->data; + if (direction == GTK_DIR_TAB_FORWARD) + children = children->next; + else + children = children->prev; + + if (!child) + continue; + + if (focus_child) { + if (focus_child == child) { + focus_child = NULL; + + if (GTK_WIDGET_DRAWABLE (child) && + GTK_IS_CONTAINER (child) && + !GTK_WIDGET_HAS_FOCUS (child)) + if (gtk_container_focus (GTK_CONTAINER (child), direction)) { + gtk_signal_emit_stop_by_name(GTK_OBJECT(container), "focus"); + return TRUE; + } + } + } + else if (GTK_WIDGET_DRAWABLE (child)) { + if (GTK_IS_CONTAINER (child)) { + if (gtk_container_focus (GTK_CONTAINER (child), direction)) { + gtk_signal_emit_stop_by_name(GTK_OBJECT(container), "focus"); + return TRUE; + } + } + else if (GTK_WIDGET_CAN_FOCUS (child)) { + gtk_widget_grab_focus (child); + gtk_signal_emit_stop_by_name(GTK_OBJECT(container), "focus"); + return TRUE; + } + } + } + + return FALSE; +} + +gint +e_container_change_tab_order(GtkContainer *container, GList *widgets) +{ + GList *list; + list = g_list_copy(widgets); + g_list_foreach(list, (GFunc) gtk_object_ref, NULL); + return gtk_signal_connect_full(GTK_OBJECT(container), "focus", + GTK_SIGNAL_FUNC(e_container_change_tab_order_callback), + NULL, list, + e_container_change_tab_order_destroy_notify, + FALSE, FALSE); +} diff --git a/widgets/misc/e-gui-utils.h b/widgets/misc/e-gui-utils.h index c1958879aa..1d47a7b514 100644 --- a/widgets/misc/e-gui-utils.h +++ b/widgets/misc/e-gui-utils.h @@ -13,6 +13,7 @@ GtkWidget *e_create_image_widget (gchar *name, gchar *string1, gchar *string void e_container_foreach_leaf (GtkContainer *container, GtkCallback callback, gpointer closure); - +gint e_container_change_tab_order (GtkContainer *container, + GList *widgets); #endif /* E_GUI_UTILS_H */ -- cgit v1.2.3