From e53fbcf092c40b22ccc4c5f23795e12c9862c338 Mon Sep 17 00:00:00 2001 From: Marius Nita Date: Sat, 16 Nov 2002 02:11:44 +0000 Subject: event handling classes --- otk/eventdispatcher.cc | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 otk/eventdispatcher.cc (limited to 'otk/eventdispatcher.cc') diff --git a/otk/eventdispatcher.cc b/otk/eventdispatcher.cc new file mode 100644 index 00000000..0d861b36 --- /dev/null +++ b/otk/eventdispatcher.cc @@ -0,0 +1,49 @@ +#include "eventdispatcher.hh" +#include "display.hh" + +namespace otk { + +OtkEventDispatcher::OtkEventDispatcher() +{ +} + +OtkEventDispatcher::~OtkEventDispatcher() +{ +} + +void OtkEventDispatcher::clearAllHandlers(void) +{ + _map.clear(); +} + +void OtkEventDispatcher::registerHandler(Window id, OtkEventHandler *handler) +{ + _map.insert(std::pair(id, handler)); +} + +void OtkEventDispatcher::clearHandler(Window id) +{ + _map.erase(id); +} + +void OtkEventDispatcher::dispatchEvents(void) +{ + XEvent e; + OtkEventHandler *handler; + OtkEventMap::iterator it; + + while (XPending(OBDisplay::display)) { + XNextEvent(OBDisplay::display, &e); + it = _map.find(e.xany.window); + + if (it == _map.end()) + handler = _fallback; + else + handler = it->second; + + if (handler) + handler->handle(e); + } +} + +} -- cgit v1.2.3