+ reset_focus();
+ return FALSE;
+}
+
+/* recursively unset widget flags */
+
+void unset_flags(GtkWidget *w, gpointer flag)
+{
+ GTK_WIDGET_UNSET_FLAGS(w, (GtkWidgetFlags)flag);
+ if(GTK_IS_CONTAINER(w))
+ gtk_container_forall(GTK_CONTAINER(w), unset_flags, flag);
+}
+
+/* reset focus when a key or button press event reaches someone, or when the
+ page-number spin button should relinquish control... */
+
+gboolean intercept_activate_events(GtkWidget *w, GdkEvent *ev, gpointer data)
+{
+ if (w == GET_COMPONENT("hbox1")) {
+ /* the event won't be processed since the hbox1 doesn't know what to do with it,
+ so we might as well kill it and avoid confusing ourselves when it gets
+ propagated further ... */
+ return TRUE;
+ }
+ if (w == GET_COMPONENT("spinPageNo")) {
+ /* we let the spin button take care of itself, and don't steal its focus,
+ unless the user presses Esc or Tab (in those cases we intervene) */
+ if (ev->type != GDK_KEY_PRESS) return FALSE;
+ if (ev->key.keyval == GDK_Escape)
+ gtk_spin_button_set_value(GTK_SPIN_BUTTON(w), ui.pageno+1); // abort
+ else if (ev->key.keyval != GDK_Tab && ev->key.keyval != GDK_ISO_Left_Tab)
+ return FALSE; // let the spin button process it
+ }
+
+ // otherwise, we want to make sure the canvas or text item gets focus back...
+ reset_focus();
+ return FALSE;
+}
+
+void install_focus_hooks(GtkWidget *w, gpointer data)
+{
+ if (w == NULL) return;
+ g_signal_connect(w, "key-press-event", G_CALLBACK(intercept_activate_events), data);
+ g_signal_connect(w, "button-press-event", G_CALLBACK(intercept_activate_events), data);
+ if (GTK_IS_MENU_ITEM(w)) {
+ g_signal_connect(w, "activate", G_CALLBACK(intercept_activate_events), data);
+ install_focus_hooks(gtk_menu_item_get_submenu(GTK_MENU_ITEM(w)), data);
+ }
+ if(GTK_IS_CONTAINER(w))
+ gtk_container_forall(GTK_CONTAINER(w), install_focus_hooks, data);