bool EventManager::duplicateAccelerator(const std::string& key, const std::string& modifiers, const IEventPtr& event) { AcceleratorList accelList = findAccelerator(key, modifiers); for (AcceleratorList::iterator i = accelList.begin(); i != accelList.end(); i++) { // If one of the accelerators in the list matches the event, return true if (i->match(event)) { return true; } } return false; }
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; }
EventManager::AcceleratorList EventManager::findAccelerator(guint keyVal, const unsigned int modifierFlags) { AcceleratorList returnList; // Cycle through the accelerators and check for matches for (AcceleratorList::iterator i = _accelerators.begin(); i != _accelerators.end(); i++) { if (i->match(keyVal, modifierFlags)) { // Add the pointer to the found accelerators returnList.push_back((*i)); } } return returnList; }
IEventPtr EventManager::findEvent(GdkEventKey* event) { // Retrieve the accelerators for this eventkey AcceleratorList accelList = findAccelerator(event); // Did we find any matching accelerators? if (accelList.size() > 0) { // Take the first found accelerator Accelerator& accel = *accelList.begin(); return accel.getEvent(); } else { // No accelerators found return _emptyEvent; } }
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; } }