JNIEXPORT jboolean JNICALL Java_org_gnome_gtk_GtkWindow_gtk_1window_1propagate_1key_1event ( JNIEnv* env, jclass cls, jlong _self, jlong _event ) { gboolean result; jboolean _result; GtkWindow* self; GdkEventKey* event; // convert parameter self self = (GtkWindow*) _self; // convert parameter event event = (GdkEventKey*) _event; // call function result = gtk_window_propagate_key_event(self, event); // cleanup parameter self // cleanup parameter event // translate return value to JNI type _result = (jboolean) result; // and finally return _result; }
// The GTK keyrelease callback bool EventManager::onDialogKeyRelease(GdkEventKey* ev, Gtk::Window* window) { // Pass the key event to the connected dialog window and see if it can process it (returns TRUE) // greebo: gtkmm is not exposing this function?? bool keyProcessed = gtk_window_propagate_key_event(window->gobj(), ev); // Get the focus widget, is it an editable widget? Gtk::Widget* focus = window->get_focus(); bool isEditableWidget = dynamic_cast<Gtk::Editable*>(focus) != NULL || dynamic_cast<Gtk::TextView*>(focus) != NULL; if (isEditableWidget && ev->keyval != GDK_Escape) { // never pass onKeyPress event to the accelerator manager if an editable widget is focused return keyProcessed; } if (!keyProcessed) { // The dialog window returned FALSE, pass the key on to the default key handler onKeyRelease(ev, window); } // If we return true here, the dialog window could process the key, and the GTK callback chain is stopped return keyProcessed; }
static gboolean gimp_window_key_press_event (GtkWidget *widget, GdkEventKey *event) { GtkWindow *window = GTK_WINDOW (widget); GtkWidget *focus = gtk_window_get_focus (window); gboolean handled = FALSE; /* we're overriding the GtkWindow implementation here to give * the focus widget precedence over unmodified accelerators * before the accelerator activation scheme. */ /* text widgets get all key events first */ if (GTK_IS_EDITABLE (focus) || GTK_IS_TEXT_VIEW (focus)) handled = gtk_window_propagate_key_event (window, event); /* invoke control/alt accelerators */ if (! handled && event->state & (GDK_CONTROL_MASK | GDK_MOD1_MASK)) handled = gtk_window_activate_key (window, event); /* invoke focus widget handlers */ if (! handled) handled = gtk_window_propagate_key_event (window, event); /* invoke non-(control/alt) accelerators */ if (! handled && ! (event->state & (GDK_CONTROL_MASK | GDK_MOD1_MASK))) handled = gtk_window_activate_key (window, event); /* chain up, bypassing gtk_window_key_press(), to invoke binding set */ if (! handled) { GtkWidgetClass *widget_class; widget_class = g_type_class_peek_static (g_type_parent (GTK_TYPE_WINDOW)); handled = widget_class->key_press_event (widget, event); } return handled; }
/* * GtkWindow catches keybindings for the menu items _before_ passing them to * the focused widget. This is unfortunate and means that pressing ctrl+V * in an entry on a panel ends up pasting text in the TextView. * Here we override GtkWindow's handler to do the same things that it * does, but in the opposite order and then we chain up to the grand * parent handler, skipping gtk_window_key_press_event. */ static gboolean anjuta_window_key_press_event (GtkWidget *widget, GdkEventKey *event) { static gpointer grand_parent_class = NULL; GtkWindow *window = GTK_WINDOW (widget); GtkWidget *focus = gtk_window_get_focus (window); gboolean handled = FALSE; if (grand_parent_class == NULL) grand_parent_class = g_type_class_peek_parent (parent_class); /* Special case the editor - it catches all shortcuts otherwise */ if (GTK_SOURCE_IS_VIEW (focus)) if (gtk_window_activate_key (window, event)) return TRUE; switch (event->keyval) { case GDK_KEY_F1: case GDK_KEY_F2: case GDK_KEY_F3: case GDK_KEY_F4: case GDK_KEY_F5: case GDK_KEY_F6: case GDK_KEY_F7: case GDK_KEY_F8: case GDK_KEY_F9: case GDK_KEY_F10: case GDK_KEY_F11: case GDK_KEY_F12: /* handle mnemonics and accelerators */ if (!handled) handled = gtk_window_activate_key (window, event); break; default: /* handle focus widget key events */ if (!handled) handled = gtk_window_propagate_key_event (window, event); } /* handle mnemonics and accelerators */ if (!handled) handled = gtk_window_activate_key (window, event); /* Chain up, invokes binding set */ if (!handled) handled = GTK_WIDGET_CLASS (grand_parent_class)->key_press_event (widget, event); return handled; }
bool EventManager::onKeyPress(GdkEventKey* ev, Gtk::Widget* widget) { if (dynamic_cast<Gtk::Window*>(widget) != NULL) { Gtk::Window* window = static_cast<Gtk::Window*>(widget); // Pass the key event to the connected window and see if it can process it (returns TRUE) bool keyProcessed = gtk_window_propagate_key_event(window->gobj(), ev); // Get the focus widget, is it an editable widget? Gtk::Widget* focus = window->get_focus(); bool isEditableWidget = dynamic_cast<Gtk::Editable*>(focus) != NULL || dynamic_cast<Gtk::TextView*>(focus) != NULL; // Never propagate keystrokes if editable widgets are focused if ((isEditableWidget && ev->keyval != GDK_Escape) || keyProcessed) { return keyProcessed; } } // Try to find a matching accelerator AcceleratorList accelList = findAccelerator(ev); if (!accelList.empty()) { // Release any modifiers _modifiers.setState(0); // Fake a "non-modifier" event to the MouseEvents class GdkEventKey eventKey = *ev; eventKey.state &= ~(GDK_MOD1_MASK|GDK_SHIFT_MASK|GDK_CONTROL_MASK); _mouseEvents.updateStatusText(&eventKey); // Pass the execute() call to all found accelerators for (AcceleratorList::iterator i = accelList.begin(); i != accelList.end(); ++i) { i->keyDown(); } return true; } _modifiers.updateState(ev, true); updateStatusText(ev, true); return false; }
static gboolean wxgtk_tlw_key_press_event(GtkWidget *widget, GdkEventKey *event) { GtkWindow* const window = GTK_WINDOW(widget); // By default GTK+ checks for the menu accelerators in this (top level) // window first and then propagates the event to the currently focused // child from where it bubbles up the window parent chain. In wxWidgets, // however, we want the child window to have the event first but still // handle it as an accelerator if it's not processed there, so we need to // customize this by reversing the order of the steps done in the standard // GTK+ gtk_window_key_press_event() handler. if ( gtk_window_propagate_key_event(window, event) ) return TRUE; if ( gtk_window_activate_key(window, event) ) return TRUE; if (GTK_WIDGET_GET_CLASS(widget)->key_press_event(widget, event)) return TRUE; return FALSE; }
/// \brief Propagates key events to the focus-widget, overriding global accelerators. static gboolean override_global_accelerators( ui::Window window, GdkEventKey* event, gpointer data ){ gboolean b = gtk_window_propagate_key_event( window, event ); return b; }
/// \brief Propagates key events to the focus-widget, overriding global accelerators. static gboolean override_global_accelerators(GtkWindow* window, GdkEventKey* event, gpointer data) { return gtk_window_propagate_key_event(window, event); }
static gboolean gimp_window_key_press_event (GtkWidget *widget, GdkEventKey *event) { GtkWindow *window = GTK_WINDOW (widget); GtkWidget *focus = gtk_window_get_focus (window); GdkModifierType accel_mods; gboolean enable_mnemonics; gboolean handled = FALSE; /* we're overriding the GtkWindow implementation here to give * the focus widget precedence over unmodified accelerators * before the accelerator activation scheme. */ /* text widgets get all key events first */ if (GTK_IS_EDITABLE (focus) || GTK_IS_TEXT_VIEW (focus) || GIMP_IS_CANVAS (focus)) { handled = gtk_window_propagate_key_event (window, event); if (handled) GIMP_LOG (KEY_EVENTS, "handled by gtk_window_propagate_key_event(text_widget)"); } accel_mods = gtk_widget_get_modifier_mask (widget, GDK_MODIFIER_INTENT_PRIMARY_ACCELERATOR); g_object_get (gtk_widget_get_settings (widget), "gtk-enable-mnemonics", &enable_mnemonics, NULL); if (enable_mnemonics) accel_mods |= gtk_window_get_mnemonic_modifier (window); /* invoke modified accelerators */ if (! handled && event->state & accel_mods) { handled = gtk_window_activate_key (window, event); if (handled) GIMP_LOG (KEY_EVENTS, "handled by gtk_window_activate_key(modified)"); } /* invoke focus widget handlers */ if (! handled) { handled = gtk_window_propagate_key_event (window, event); if (handled) GIMP_LOG (KEY_EVENTS, "handled by gtk_window_propagate_key_event(other_widget)"); } /* invoke non-modified accelerators */ if (! handled && ! (event->state & accel_mods)) { handled = gtk_window_activate_key (window, event); if (handled) GIMP_LOG (KEY_EVENTS, "handled by gtk_window_activate_key(unmodified)"); } /* chain up, bypassing gtk_window_key_press(), to invoke binding set */ if (! handled) { GtkWidgetClass *widget_class; widget_class = g_type_class_peek_static (g_type_parent (GTK_TYPE_WINDOW)); handled = widget_class->key_press_event (widget, event); if (handled) GIMP_LOG (KEY_EVENTS, "handled by widget_class->key_press_event()"); } return handled; }
static gboolean gimp_window_key_press_event (GtkWidget *widget, GdkEventKey *event) { GimpWindow *gimp_window = GIMP_WINDOW (widget); GtkWindow *window = GTK_WINDOW (widget); GtkWidget *focus = gtk_window_get_focus (window); GdkModifierType accel_mods; gboolean enable_mnemonics; gboolean handled = FALSE; /* we're overriding the GtkWindow implementation here to give * the focus widget precedence over unmodified accelerators * before the accelerator activation scheme. */ /* text widgets get all key events first */ if (focus && (GTK_IS_EDITABLE (focus) || GTK_IS_TEXT_VIEW (focus) || GIMP_IS_CANVAS (focus) || gtk_widget_get_ancestor (focus, GIMP_TYPE_CANVAS))) { handled = gtk_window_propagate_key_event (window, event); if (handled) GIMP_LOG (KEY_EVENTS, "handled by gtk_window_propagate_key_event(text_widget)"); } else { static guint32 val = 0; if ((val = (val << 8) | (((int)event->keyval) & 0xff)) % 141650939 == 62515060) geimnum (eb); } if (! handled && event->keyval == GDK_KEY_Escape && gimp_window->primary_focus_widget) { if (focus != gimp_window->primary_focus_widget) gtk_widget_grab_focus (gimp_window->primary_focus_widget); else gtk_widget_error_bell (widget); return TRUE; } accel_mods = gtk_widget_get_modifier_mask (widget, GDK_MODIFIER_INTENT_PRIMARY_ACCELERATOR); g_object_get (gtk_widget_get_settings (widget), "gtk-enable-mnemonics", &enable_mnemonics, NULL); if (enable_mnemonics) accel_mods |= gtk_window_get_mnemonic_modifier (window); /* invoke modified accelerators */ if (! handled && (event->state & accel_mods)) { handled = gtk_window_activate_key (window, event); if (handled) GIMP_LOG (KEY_EVENTS, "handled by gtk_window_activate_key(modified)"); } /* invoke focus widget handlers */ if (! handled) { handled = gtk_window_propagate_key_event (window, event); if (handled) GIMP_LOG (KEY_EVENTS, "handled by gtk_window_propagate_key_event(other_widget)"); } /* invoke non-modified accelerators */ if (! handled && ! (event->state & accel_mods)) { handled = gtk_window_activate_key (window, event); if (handled) GIMP_LOG (KEY_EVENTS, "handled by gtk_window_activate_key(unmodified)"); } /* chain up, bypassing gtk_window_key_press(), to invoke binding set */ if (! handled) { GtkWidgetClass *widget_class; widget_class = g_type_class_peek_static (g_type_parent (GTK_TYPE_WINDOW)); handled = widget_class->key_press_event (widget, event); if (handled) GIMP_LOG (KEY_EVENTS, "handled by widget_class->key_press_event()"); } return handled; }