summaryrefslogtreecommitdiff
path: root/gtk/gtkwindow.c
diff options
context:
space:
mode:
authorOwen Taylor <otaylor@redhat.com>2000-12-11 17:47:24 +0000
committerOwen Taylor <otaylor@src.gnome.org>2000-12-11 17:47:24 +0000
commit0cdc00ec0b5364bcbe9b0567be64bd9efdda3074 (patch)
tree7c15c586d752ed8976d6e22492d00082fc62477a /gtk/gtkwindow.c
parent5a188a9f13cd4fd4b4ae243796c92cb771313f64 (diff)
downloadgdk-pixbuf-0cdc00ec0b5364bcbe9b0567be64bd9efdda3074.tar.gz
Add a function to determine if a window is the focus widget within its
Wed Oct 25 14:17:43 2000 Owen Taylor <otaylor@redhat.com> * gtk/gtkwidget.[ch] (gtk_widget_is_focus): Add a function to determine if a window is the focus widget within its toplevel. * gtk/gtkcontainer.[ch]: Fix the return type of ::focus to be boolean. * gtk/gtkcontainer.c (gtk_container_real_focus): Move handling of the case where the container CAN_FOCUS to here instead of having it in each individual move-the-focus place. * gtk/gtkcontainer.c: Rewrite handling of left-right and up-down focusing to be geometric in a much more obvious sense. Arrowing around is still non-intuitive because it isn't perfect and because entries, etc, grab the arrow keys, but it at least usually will do what you expect now. * gtk/gtknotebook.[ch]: Many cleanups. Moved docs inline in this file. * gtk/gtknotebook.c: Change tabs to be a single item in the focus chain. Make movement of focus on tabs with arrow keys wrap around. * gtk/gtknotebook.c (gtk_notebook_find_child): Add CHECK_FIND_CHILD macro to give informative error messages instead of silent returns. * gtk/gtknotebook.c (gtk_notebook_init): Set the RECEIVES_DEFAULT flag since we handle GdkReturn on the tabs. * gtk/gtknotebook.c (gtk_notebook_expose_tabs): Invalidate windows rather than sending expose events directly. * gtk/gtknotebook.[ch] docs/Changes-2.0.txt: Move structure definition for GtkNotebookPage into .c file, since it is private. * gtk/testgtk.c (create_notebook): Add option for testing borderless notebook. * gtk/testgtk.c (page_switch): Removed egregious poking around in GTK+ internals. * docs/widget-system.txt: Remove references to GTK_REDRAW_PENDING. * gtk/gtkclist.[ch]: Remove key press handler, handle focusing properly through gtk_clist_focus. Make the title headers a single item in the tab-focus chain, and make left-right wrap around. * gtk/gtkwindow.c (gtk_window_focus): Add a custom focus method so that wrapping around works properly. * gtk/gtktreeview.c: Remove calls to gtk_container_set_focus_child() - that is handled for the widget now.
Diffstat (limited to 'gtk/gtkwindow.c')
-rw-r--r--gtk/gtkwindow.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index 7860ef937..bea9bb646 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -126,6 +126,8 @@ static gint gtk_window_focus_out_event (GtkWidget *widget,
static gint gtk_window_client_event (GtkWidget *widget,
GdkEventClient *event);
static void gtk_window_check_resize (GtkContainer *container);
+static gint gtk_window_focus (GtkContainer *container,
+ GtkDirectionType direction);
static void gtk_window_real_set_focus (GtkWindow *window,
GtkWidget *focus);
@@ -261,6 +263,7 @@ gtk_window_class_init (GtkWindowClass *klass)
widget_class->expose_event = gtk_window_expose;
container_class->check_resize = gtk_window_check_resize;
+ container_class->focus = gtk_window_focus;
klass->set_focus = gtk_window_real_set_focus;
}
@@ -1579,6 +1582,60 @@ gtk_window_check_resize (GtkContainer *container)
gtk_window_move_resize (window);
}
+static gboolean
+gtk_window_focus (GtkContainer *container,
+ GtkDirectionType direction)
+{
+ GtkBin *bin = GTK_BIN (container);
+ GtkWindow *window = GTK_WINDOW (container);
+ GtkWidget *old_focus_child = container->focus_child;
+ GtkWidget *parent;
+
+ /* We need a special implementation here to deal properly with wrapping
+ * around in the tab chain without the danger of going into an
+ * infinite loop.
+ */
+ if (old_focus_child)
+ {
+ if (GTK_IS_CONTAINER (old_focus_child) &&
+ GTK_WIDGET_DRAWABLE (old_focus_child) &&
+ GTK_WIDGET_IS_SENSITIVE (old_focus_child) &&
+ gtk_container_focus (GTK_CONTAINER (old_focus_child), direction))
+ return TRUE;
+ }
+
+ if (window->focus_widget)
+ {
+ /* Wrapped off the end, clear the focus setting for the toplpevel */
+ parent = window->focus_widget->parent;
+ while (parent)
+ {
+ gtk_container_set_focus_child (GTK_CONTAINER (parent), NULL);
+ parent = GTK_WIDGET (parent)->parent;
+ }
+
+ gtk_window_set_focus (GTK_WINDOW (container), NULL);
+ }
+
+ /* Now try to focus the first widget in the window */
+ if (GTK_WIDGET_DRAWABLE (bin->child) &&
+ GTK_WIDGET_IS_SENSITIVE (bin->child))
+ {
+ if (GTK_IS_CONTAINER (bin->child))
+ {
+ if (gtk_container_focus (GTK_CONTAINER (bin->child), direction))
+ return TRUE;
+ }
+ else if (GTK_WIDGET_CAN_FOCUS (bin->child))
+ {
+ gtk_widget_grab_focus (bin->child);
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
static void
gtk_window_real_set_focus (GtkWindow *window,
GtkWidget *focus)