From c344b3f905a3681c28d0ac9f9521418e25853dea Mon Sep 17 00:00:00 2001 From: Owen Taylor Date: Fri, 16 Nov 2001 22:20:00 +0000 Subject: [PATCH] Propagate key press events not just to focus/window but also to Thu Nov 15 12:54:36 2001 Owen Taylor * gtk/gtkwindow.c (gtk_window_key_press_event): Propagate key press events not just to focus/window but also to intermediate widgets. * gtk/gtknotebook.c: Handle Ctrl-PageUp/Ctrl-PageDown to switch pages. (Needs some work on handling focus when switching pages.) --- ChangeLog | 10 ++++++++++ ChangeLog.pre-2-0 | 10 ++++++++++ ChangeLog.pre-2-10 | 10 ++++++++++ ChangeLog.pre-2-2 | 10 ++++++++++ ChangeLog.pre-2-4 | 10 ++++++++++ ChangeLog.pre-2-6 | 10 ++++++++++ ChangeLog.pre-2-8 | 10 ++++++++++ gtk/gtknotebook.c | 42 ++++++++++++++++++++++++++++++++++++++++++ gtk/gtknotebook.h | 12 ++++++------ gtk/gtkwindow.c | 30 ++++++++++++++++++++++++++---- 10 files changed, 144 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 832843e729..24e92b497d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +Thu Nov 15 12:54:36 2001 Owen Taylor + + * gtk/gtkwindow.c (gtk_window_key_press_event): Propagate + key press events not just to focus/window but also to + intermediate widgets. + + * gtk/gtknotebook.c: Handle Ctrl-PageUp/Ctrl-PageDown + to switch pages. (Needs some work on handling focus + when switching pages.) + Fri Nov 16 14:06:31 2001 Owen Taylor * gtk/gtknotebook.c: Fix child allocations to be relative to diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index 832843e729..24e92b497d 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,3 +1,13 @@ +Thu Nov 15 12:54:36 2001 Owen Taylor + + * gtk/gtkwindow.c (gtk_window_key_press_event): Propagate + key press events not just to focus/window but also to + intermediate widgets. + + * gtk/gtknotebook.c: Handle Ctrl-PageUp/Ctrl-PageDown + to switch pages. (Needs some work on handling focus + when switching pages.) + Fri Nov 16 14:06:31 2001 Owen Taylor * gtk/gtknotebook.c: Fix child allocations to be relative to diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 832843e729..24e92b497d 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,13 @@ +Thu Nov 15 12:54:36 2001 Owen Taylor + + * gtk/gtkwindow.c (gtk_window_key_press_event): Propagate + key press events not just to focus/window but also to + intermediate widgets. + + * gtk/gtknotebook.c: Handle Ctrl-PageUp/Ctrl-PageDown + to switch pages. (Needs some work on handling focus + when switching pages.) + Fri Nov 16 14:06:31 2001 Owen Taylor * gtk/gtknotebook.c: Fix child allocations to be relative to diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index 832843e729..24e92b497d 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,13 @@ +Thu Nov 15 12:54:36 2001 Owen Taylor + + * gtk/gtkwindow.c (gtk_window_key_press_event): Propagate + key press events not just to focus/window but also to + intermediate widgets. + + * gtk/gtknotebook.c: Handle Ctrl-PageUp/Ctrl-PageDown + to switch pages. (Needs some work on handling focus + when switching pages.) + Fri Nov 16 14:06:31 2001 Owen Taylor * gtk/gtknotebook.c: Fix child allocations to be relative to diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 832843e729..24e92b497d 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,13 @@ +Thu Nov 15 12:54:36 2001 Owen Taylor + + * gtk/gtkwindow.c (gtk_window_key_press_event): Propagate + key press events not just to focus/window but also to + intermediate widgets. + + * gtk/gtknotebook.c: Handle Ctrl-PageUp/Ctrl-PageDown + to switch pages. (Needs some work on handling focus + when switching pages.) + Fri Nov 16 14:06:31 2001 Owen Taylor * gtk/gtknotebook.c: Fix child allocations to be relative to diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 832843e729..24e92b497d 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,13 @@ +Thu Nov 15 12:54:36 2001 Owen Taylor + + * gtk/gtkwindow.c (gtk_window_key_press_event): Propagate + key press events not just to focus/window but also to + intermediate widgets. + + * gtk/gtknotebook.c: Handle Ctrl-PageUp/Ctrl-PageDown + to switch pages. (Needs some work on handling focus + when switching pages.) + Fri Nov 16 14:06:31 2001 Owen Taylor * gtk/gtknotebook.c: Fix child allocations to be relative to diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 832843e729..24e92b497d 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,13 @@ +Thu Nov 15 12:54:36 2001 Owen Taylor + + * gtk/gtkwindow.c (gtk_window_key_press_event): Propagate + key press events not just to focus/window but also to + intermediate widgets. + + * gtk/gtknotebook.c: Handle Ctrl-PageUp/Ctrl-PageDown + to switch pages. (Needs some work on handling focus + when switching pages.) + Fri Nov 16 14:06:31 2001 Owen Taylor * gtk/gtknotebook.c: Fix child allocations to be relative to diff --git a/gtk/gtknotebook.c b/gtk/gtknotebook.c index 0bf40fc84d..ee96b4ae09 100644 --- a/gtk/gtknotebook.c +++ b/gtk/gtknotebook.c @@ -49,6 +49,7 @@ enum { SWITCH_PAGE, FOCUS_TAB, SELECT_PAGE, + CHANGE_CURRENT_PAGE, LAST_SIGNAL }; @@ -117,6 +118,9 @@ static void gtk_notebook_select_page (GtkNotebook *notebook, gboolean move_focus); static void gtk_notebook_focus_tab (GtkNotebook *notebook, GtkNotebookTab type); +static void gtk_notebook_change_current_page (GtkNotebook *notebook, + gint offset); + /*** GtkObject Methods ***/ static void gtk_notebook_destroy (GtkObject *object); @@ -315,6 +319,7 @@ gtk_notebook_class_init (GtkNotebookClass *class) class->focus_tab = gtk_notebook_focus_tab; class->select_page = gtk_notebook_select_page; + class->change_current_page = gtk_notebook_change_current_page; g_object_class_install_property (gobject_class, PROP_PAGE, @@ -454,6 +459,15 @@ gtk_notebook_class_init (GtkNotebookClass *class) gtk_marshal_VOID__BOOLEAN, G_TYPE_NONE, 1, G_TYPE_BOOLEAN); + notebook_signals[CHANGE_CURRENT_PAGE] = + g_signal_new ("change_current_page", + G_TYPE_FROM_CLASS (object_class), + G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, + G_STRUCT_OFFSET (GtkNotebookClass, change_current_page), + NULL, NULL, + gtk_marshal_VOID__INT, + G_TYPE_NONE, 1, + G_TYPE_INT); binding_set = gtk_binding_set_by_class (object_class); gtk_binding_entry_add_signal (binding_set, @@ -489,6 +503,15 @@ gtk_notebook_class_init (GtkNotebookClass *class) GDK_KP_End, 0, "focus_tab", 1, GTK_TYPE_NOTEBOOK_TAB, GTK_NOTEBOOK_TAB_LAST); + + gtk_binding_entry_add_signal (binding_set, + GDK_Page_Up, GDK_CONTROL_MASK, + "change_current_page", 1, + G_TYPE_INT, -1); + gtk_binding_entry_add_signal (binding_set, + GDK_Page_Down, GDK_CONTROL_MASK, + "change_current_page", 1, + G_TYPE_INT, 1); } static void @@ -547,6 +570,25 @@ gtk_notebook_focus_tab (GtkNotebook *notebook, } } +static void +gtk_notebook_change_current_page (GtkNotebook *notebook, + gint offset) +{ + GList *current = NULL; + + if (notebook->cur_page) + current = g_list_find (notebook->children, notebook->cur_page); + + while (offset != 0) + { + current = gtk_notebook_search_page (notebook, current, offset < 0 ? STEP_PREV : STEP_NEXT, TRUE); + offset += offset < 0 ? 1 : -1; + } + + if (current) + gtk_notebook_switch_page (notebook, current->data, -1); +} + /** * gtk_notebook_new: * diff --git a/gtk/gtknotebook.h b/gtk/gtknotebook.h index 68ff3ad904..c4cbbf3a20 100644 --- a/gtk/gtknotebook.h +++ b/gtk/gtknotebook.h @@ -94,12 +94,12 @@ struct _GtkNotebookClass guint page_num); /* Action signals for keybindings */ - void (* select_page) (GtkNotebook *notebook, - gboolean move_focus); - - void (* focus_tab) (GtkNotebook *notebook, - GtkNotebookTab type); - + void (* select_page) (GtkNotebook *notebook, + gboolean move_focus); + void (* focus_tab) (GtkNotebook *notebook, + GtkNotebookTab type); + void (* change_current_page) (GtkNotebook *notebook, + gint offset); }; /*********************************************************** diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c index bc608030b5..77c18503dd 100644 --- a/gtk/gtkwindow.c +++ b/gtk/gtkwindow.c @@ -3485,6 +3485,7 @@ gtk_window_key_press_event (GtkWidget *widget, GdkEventKey *event) { GtkWindow *window; + GtkWidget *focus; gboolean handled; g_return_val_if_fail (GTK_IS_WINDOW (widget), FALSE); @@ -3493,10 +3494,31 @@ gtk_window_key_press_event (GtkWidget *widget, window = GTK_WINDOW (widget); handled = FALSE; - - if (window->focus_widget && window->focus_widget != widget && - GTK_WIDGET_IS_SENSITIVE (window->focus_widget)) - handled = gtk_widget_event (window->focus_widget, (GdkEvent*) event); + + focus = window->focus_widget; + if (focus) + g_object_ref (focus); + + while (!handled && + focus && focus != widget && + gtk_widget_get_toplevel (focus) == widget) + { + GtkWidget *parent; + + if (GTK_WIDGET_IS_SENSITIVE (focus)) + handled = gtk_widget_event (focus, (GdkEvent*) event); + + parent = focus->parent; + if (parent) + g_object_ref (parent); + + g_object_unref (focus); + + focus = parent; + } + + if (focus) + g_object_unref (focus); if (!handled) handled = gtk_window_mnemonic_activate (window,