summaryrefslogtreecommitdiff
path: root/gtk
diff options
context:
space:
mode:
authorOwen Taylor <otaylor@redhat.com>2001-11-16 22:20:00 +0000
committerOwen Taylor <otaylor@src.gnome.org>2001-11-16 22:20:00 +0000
commitc344b3f905a3681c28d0ac9f9521418e25853dea (patch)
tree53db78bcea77bd4ff23d1446186723965ca9ad6b /gtk
parent0f9b242203ec9bd12e591a2c15008b4ef13ec1c9 (diff)
downloadgtk+-c344b3f905a3681c28d0ac9f9521418e25853dea.tar.gz
Propagate key press events not just to focus/window but also to
Thu Nov 15 12:54:36 2001 Owen Taylor <otaylor@redhat.com> * 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.)
Diffstat (limited to 'gtk')
-rw-r--r--gtk/gtknotebook.c42
-rw-r--r--gtk/gtknotebook.h12
-rw-r--r--gtk/gtkwindow.c30
3 files changed, 74 insertions, 10 deletions
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,