Exemplo n.º 1
0
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;
}
Exemplo n.º 2
0
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;
}