EventManager::AcceleratorList EventManager::findAccelerator(
	const std::string& key, const std::string& modifierStr)
{
	guint keyVal = getGDKCode(key);
	unsigned int modifierFlags = _modifiers.getModifierFlags(modifierStr);

	return findAccelerator(keyVal, modifierFlags);
}
// Returns the pointer to the accelerator for the given GdkEvent, but convert the key to uppercase before passing it
EventManager::AcceleratorList EventManager::findAccelerator(GdkEventKey* event) {
	unsigned int keyval = gdk_keyval_to_upper(event->keyval);

	// greebo: I saw this in the original GTKRadiant code, maybe this is necessary to catch GTK_ISO_Left_Tab...
	if (keyval == GDK_ISO_Left_Tab) {
		keyval = GDK_Tab;
	}

	return findAccelerator(keyval, _modifiers.getKeyboardFlags(event->state));
}
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;
}
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;
	}
}
Beispiel #6
0
	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;
		}
	}
Beispiel #7
0
static void mh_updateLabel (menu* m, wchar_t* label, int flags, int key) {
BOOL alloced = FALSE;
if (!label) {
alloced=TRUE;
label = mh_getLabel(m);
}
if (flags==-1 && key==-1) findAccelerator(m->command, &flags, &key) ;
if (flags!=0 && key!=0) {
const wchar_t* z = mh_buildLabel(label, flags, key);
if (alloced) free(label);
label = z;
}
int flg2 = MF_BYCOMMAND | (m->sub? MF_POPUP : MF_STRING);
ModifyMenu(m->parent, m->command, flg2, m->command, label);
if (alloced || (flags!=0 && key!=0))  free(label);
}
std::string EventManager::getAcceleratorStr(const IEventPtr& event, bool forMenu) {
	std::string returnValue = "";

	IAccelerator& accelerator = findAccelerator(event);

	unsigned int keyVal = accelerator.getKey();
	const std::string keyStr = (keyVal != 0) ? gdk_keyval_name(keyVal) : "";

	if (keyStr != "") {
		// Return a modifier string for a menu
		const std::string modifierStr = getModifierStr(accelerator.getModifiers(), forMenu);

		const std::string connector = (forMenu) ? "-" : "+";

		returnValue = modifierStr;
		returnValue += (modifierStr != "") ? connector : "";
		returnValue += keyStr;
	}

	return returnValue;
}
Beispiel #9
0
static int mh_index (lua_State* l) {
menu* m = lua_touserdata(l,1);
if (lua_isnumber(l,2)) {
if (!m->sub) return 0;
int n = lua_tointeger(l,2);
if (n==0) n=-1;
if (n<0) n += GetMenuItemCount(m->menu);
else n--;
MENUITEMINFO mii;
mii.cbSize = sizeof(MENUITEMINFO);
mii.fMask = MIIM_ID | MIIM_SUBMENU;
if (!GetMenuItemInfo(m->menu, n, TRUE, &mii)) return 0;
menu x;
x.sub = mii.hSubMenu!=0;
x.origin = m->origin;
x.parent = m->menu;
x.position = n;
if (mii.hSubMenu!=0) x.menu = mii.hSubMenu;
else x.command = mii.wID;
lua_settop(l,0);
lua_pushfulluserdata(l, &x, sizeof(x), "menuhandle");
return 1;
}
const char* nm = luaL_checkstring(l,2);
if (streq(nm, "checked")) {
if (m->sub) luaL_error(l, "unsupported operation");
MENUITEMINFO mii;
mii.cbSize = sizeof(MENUITEMINFO);
mii.fMask = MIIM_STATE | MIIM_FTYPE;
if (!GetMenuItemInfo(m->parent, m->command, FALSE, &mii)) return 0;
lua_pushboolean(l, 0!=(mii.fState&MFS_CHECKED));
return 1;
}
else if (streq(nm, "radio")) {
if (m->sub) luaL_error(l, "unsupported operation");
MENUITEMINFO mii;
mii.cbSize = sizeof(MENUITEMINFO);
mii.fMask = MIIM_FTYPE;
if (!GetMenuItemInfo(m->parent, m->command, FALSE, &mii)) return 0;
lua_pushboolean(l, 0!=(mii.fType&MFT_RADIOCHECK));
return 1;
}
else if (streq(nm, "enabled")) {
if (m->sub) luaL_error(l, "unsupported operation");
MENUITEMINFO mii;
mii.cbSize = sizeof(MENUITEMINFO);
mii.fMask = MIIM_STATE;
if (!GetMenuItemInfo(m->parent, m->command, FALSE, &mii)) return 0;
lua_settop(l,0);
lua_pushboolean(l, 0==(mii.fState&MFS_DISABLED));
return 1;
}
else if (streq(nm, "text")) {
const wchar_t* wc = mh_getLabel(m);
const char* mbc = strcvt(wc, CP_UTF16, CP_UTF8, NULL);
lua_pushstring(l, mbc);
free(mbc); 
free(wc);
return 1;
}
else if (streq(nm, "name")) {
const char* menuName = GetMenuName(m->parent, m->position);
lua_settop(l,0);
lua_pushstring(l,menuName);
return 1;
}
else if (streq(nm, "accelerator")) {
int f, k;
if (!(m->sub) && findAccelerator(m->command, &f, &k)) {
const wchar_t* wkn = getKeyName(f,k,0);
const char* kn = strcvt(wkn, CP_UTF16, CP_UTF8, NULL);
lua_pushstring(l,kn);
free(kn);
free(wkn);
return 1;
}
return 0;
}
else if (streq(nm, "onAction")) {
if (m->sub) return 0;
if (m->command>=IDM_CUSTOMCOMMAND) lua_pushluafunction(l, *getCustomCommand(m->command - IDM_CUSTOMCOMMAND));
else {
lua_pushinteger(l, m->command);
lua_pushcclosure(l, mh_commandclosure, 1);
}
return 1;
}
else if (streq(nm, "builtIn")) {
if (m->sub) return 0;
lua_pushboolean(l, m->command<IDM_CUSTOMCOMMAND);
return 1;
}
else if (streq(nm, "parent")) {
menu x;
x.sub = TRUE;
x.parent = GetParentMenu(m->parent, m->origin, &(x.position));
x.menu = m->parent;
x.origin = m->origin;
if (!x.parent) return 0;
lua_settop(l,0);
lua_pushfulluserdata(l, &x, sizeof(x), "menuhandle");
return 1;
}
else if (streq(nm, "parentHandle")) {
lua_pushlightuserdata(l, m->parent);
return 1;
}
else if (streq(nm, "handle") || streq(nm, "command")) {
if (m->sub) lua_pushlightuserdata(l, m->command);
else lua_pushinteger(l, m->command);
return 1;
}
//SUITE
else if (luaL_getmetafield(l, 1, nm)) return 1;
else if (m->sub) {
MENUITEMINFO mii;
mii.cbSize = sizeof(MENUITEMINFO);
mii.fMask = MIIM_ID | MIIM_SUBMENU | MIIM_DATA;
for (int i=0, n=GetMenuItemCount(m->menu); i<n; i++) {
if (!GetMenuItemInfo(m->menu, i, TRUE, &mii)) continue;
if (mii.dwItemData && streq(nm, mii.dwItemData)) {
menu x;
x.sub = mii.hSubMenu!=0;
x.parent = m->menu;
x.origin = m->origin;
x.position = i;
if (mii.hSubMenu!=0) x.menu = mii.hSubMenu;
else x.command = mii.wID;
lua_settop(l,0);
lua_pushfulluserdata(l, &x, sizeof(x), "menuhandle");
return 1;
}}}
return 0;
}