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; }
IEvent* findEvent(GdkEventKey* event) { // Retrieve the accelerators for this eventkey AcceleratorList accelList = findAccelerator(event); // Did we find any matching accelerators? if (!accelList.empty()) { // Take the first found accelerator Accelerator* accel = *accelList.begin(); return accel->getEvent(); } else { // No accelerators found return NULL; } }