Beispiel #1
0
static gboolean _GuiGtkDrawingArea_keyCallback (GuiObject widget, GdkEvent *gevent, gpointer void_me) {
	iam (GuiDrawingArea);
	//Melder_casual ("_GuiGtkDrawingArea_keyCallback");
	if (my keyCallback && gevent -> type == GDK_KEY_PRESS) {
		struct structGuiDrawingAreaKeyEvent event = { widget, 0 };
		GdkEventKey *gkeyEvent = (GdkEventKey *) gevent;
		event. key = gkeyEvent -> keyval;
		/*
		 * Translate with the help of /usr/include/gtk-2.0/gdk/gdkkeysyms.h
		 */
		if (event. key == GDK_Escape) event. key = 27;
		if (event. key == GDK_Left) event. key = 0x2190;
		if (event. key == GDK_Up) event. key = 0x2191;
		if (event. key == GDK_Right) event. key = 0x2192;
		if (event. key == GDK_Down) event. key = 0x2193;
		event. shiftKeyPressed = (gkeyEvent -> state & GDK_SHIFT_MASK) != 0;
		event. commandKeyPressed = (gkeyEvent -> state & GDK_CONTROL_MASK) != 0;
		event. optionKeyPressed = (gkeyEvent -> state & GDK_MOD1_MASK) != 0;
		event. extraControlKeyPressed = false;
		my keyCallback (my keyBoss, & event);
		/*
		 * FIXME: here we should empty the type-ahead buffer
		 */
		return TRUE;
	}
	return FALSE;   // if the drawing area has no keyCallback, the system will send the key press to a text field.
}
Beispiel #2
0
bool XMLParser::parseActiveKey(bool closed) {
	bool ignore = false;
	assert(_activeKey.empty() == false);

	ParserNode *key = _activeKey.top();

	if (key->name == "xml" && key->header == true) {
		assert(closed);
		return parseXMLHeader(key) && closeKey();
	}

	XMLKeyLayout *layout = (_activeKey.size() == 1) ? _XMLkeys : getParentNode(key)->layout;

	if (layout->children.contains(key->name)) {
		key->layout = layout->children[key->name];

		Common::StringMap localMap = key->values;
		int keyCount = localMap.size();

		for (Common::List<XMLKeyLayout::XMLKeyProperty>::const_iterator i = key->layout->properties.begin(); i != key->layout->properties.end(); ++i) {
			if (i->required && !localMap.contains(i->name))
				return parserError("Missing required property '%s' inside key '%s'", i->name.c_str(), key->name.c_str());
			else if (localMap.contains(i->name))
				keyCount--;
		}

		if (keyCount > 0)
			return parserError("Unhandled property inside key '%s'.", key->name.c_str());

	} else {
		return parserError("Unexpected key in the active scope ('%s').", key->name.c_str());
	}

	// check if any of the parents must be ignored.
	// if a parent is ignored, all children are too.
	for (int i = _activeKey.size() - 1; i >= 0; --i) {
		if (_activeKey[i]->ignore)
			ignore = true;
	}

	if (ignore == false && keyCallback(key) == false) {
		// HACK:  People may be stupid and overlook the fact that
		// when keyCallback() fails, a parserError() must be set.
		// We set it manually in that case.
		if (_state != kParserError)
			parserError("Unhandled exception when parsing '%s' key.", key->name.c_str());

		return false;
	}

	if (closed)
		return closeKey();

	return true;
}
	void _GuiWinDrawingArea_handleKey (GuiObject widget, TCHAR kar) {   // TODO: event?
		iam_drawingarea;
		if (my keyCallback) {
			struct structGuiDrawingAreaKeyEvent event = { widget, 0 };
			event. key = kar;
			if (event. key == VK_LEFT) event. key = 0x2190;
			if (event. key == VK_RIGHT) event. key = 0x2192;
			if (event. key == VK_UP) event. key = 0x2191;
			if (event. key == VK_DOWN) event. key = 0x2193;
			event. shiftKeyPressed = GetKeyState (VK_SHIFT) < 0;   // TODO: event -> key?
			try {
				my keyCallback (my keyBoss, & event);
			} catch (MelderError) {
				Melder_flushError ("Key press not completely handled.");
			}
		}
	}
		bool _GuiMacDrawingArea_tryToHandleKey (GuiObject widget, EventRecord *macEvent) {
			iam_drawingarea;
			if (my keyCallback) {
				struct structGuiDrawingAreaKeyEvent event = { widget, 0 };
				event. key = macEvent -> message & charCodeMask;
				if (event. key == 28) event. key = 0x2190;
				if (event. key == 29) event. key = 0x2192;
				if (event. key == 30) event. key = 0x2191;
				if (event. key == 31) event. key = 0x2193;
				event. shiftKeyPressed = (macEvent -> modifiers & shiftKey) != 0;
				event. commandKeyPressed = (macEvent -> modifiers & cmdKey) != 0;
				event. optionKeyPressed = (macEvent -> modifiers & optionKey) != 0;
				event. extraControlKeyPressed = (macEvent -> modifiers & controlKey) != 0;
				try {
					my keyCallback (my keyBoss, & event);
				} catch (MelderError) {
					Melder_flushError ("Key press not completely handled.");
				}
				return true;
			}
			return false;
		}