/* * Copyright (c) 2012 Yoann Blein * Licensed under the simplified BSD license. * See Documentation/Licenses/BSD-simplified.txt for more information. */ #include #include #include namespace Swift { void InputEventParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) { if (level == 0) { // tag InputEventPayload::ref payload = getPayloadInternal(); payload->setAction(actionFromString(attributes.getAttributeValue("action").get_value_or(""))); } else if (level == 1) { // tag } else if (level == 2) { InputEventPayload::Event event(eventTypeFromString(element)); switch (event.type) { case InputEventPayload::Event::MouseMove: try { event.realArg1 = boost::lexical_cast(attributes.getAttributeValue("x").get_value_or("0")); event.realArg2 = boost::lexical_cast(attributes.getAttributeValue("y").get_value_or("0")); } catch (boost::bad_lexical_cast &) {} break; case InputEventPayload::Event::MouseWheel: case InputEventPayload::Event::MousePress: case InputEventPayload::Event::MouseRelease: case InputEventPayload::Event::KeyType: case InputEventPayload::Event::KeyPress: case InputEventPayload::Event::KeyRelease: try { event.integerArg = boost::lexical_cast(attributes.getEntries().front().getValue()); } catch (boost::bad_lexical_cast &) {} default: break; } } ++level; } void InputEventParser::handleEndElement(const std::string&, const std::string&) { --level; } void InputEventParser::handleCharacterData(const std::string&){ } InputEventPayload::Action InputEventParser::actionFromString(const std::string& action) { if (action == "notify") return InputEventPayload::Notify; return InputEventPayload::Unknown; } InputEventPayload::Event::EventType InputEventParser::eventTypeFromString(const std::string& eventType) { if (eventType == "mouse-move") return InputEventPayload::Event::MouseMove; else if (eventType == "mouse-wheel") return InputEventPayload::Event::MouseWheel; else if (eventType == "mouse-press") return InputEventPayload::Event::MousePress; else if (eventType == "mouse-release") return InputEventPayload::Event::MouseRelease; else if (eventType == "key-type") return InputEventPayload::Event::KeyType; else if (eventType == "key-press") return InputEventPayload::Event::KeyPress; else if (eventType == "key-release") return InputEventPayload::Event::KeyRelease; return InputEventPayload::Event::Unknown; } }