aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/EventManager.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/FbTk/EventManager.cc')
-rw-r--r--src/FbTk/EventManager.cc102
1 files changed, 102 insertions, 0 deletions
diff --git a/src/FbTk/EventManager.cc b/src/FbTk/EventManager.cc
new file mode 100644
index 0000000..3f28464
--- /dev/null
+++ b/src/FbTk/EventManager.cc
@@ -0,0 +1,102 @@
1// EventManager.cc
2// Copyright (c) 2002 Henrik Kinnunen (fluxgen at linuxmail.org)
3//
4// Permission is hereby granted, free of charge, to any person obtaining a
5// copy of this software and associated documentation files (the "Software"),
6// to deal in the Software without restriction, including without limitation
7// the rights to use, copy, modify, merge, publish, distribute, sublicense,
8// and/or sell copies of the Software, and to permit persons to whom the
9// Software is furnished to do so, subject to the following conditions:
10//
11// The above copyright notice and this permission notice shall be included in
12// all copies or substantial portions of the Software.
13//
14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE.
21
22// $Id: EventManager.cc,v 1.5 2003/03/03 21:51:13 rathnor Exp $
23
24#include "EventManager.hh"
25#include "FbWindow.hh"
26
27#include <iostream>
28using namespace std;
29
30namespace FbTk {
31
32EventManager *EventManager::instance() {
33 static EventManager ev;
34 return &ev;
35}
36
37EventManager::~EventManager() {
38 if (m_eventhandlers.size() != 0)
39 cerr<<"FbTk::EventManager: Warning: unregistered eventhandlers!"<<endl;
40}
41
42void EventManager::handleEvent(XEvent &ev) {
43 // find eventhandler for event window
44 if (m_eventhandlers.find(ev.xany.window) == m_eventhandlers.end()) {
45 //cerr<<"Can't find window="<<ev.xany.window<<endl;
46 return;
47 }
48 EventHandler *evhand = m_eventhandlers[ev.xany.window];
49 if (evhand == 0) {
50 cerr<<"FbTk::EventManager: Warning: evhand == 0!"<<endl;
51 return;
52 }
53
54 switch (ev.xany.type) {
55 case KeyPress:
56 evhand->keyPressEvent(ev.xkey);
57 break;
58 case KeyRelease:
59 evhand->keyReleaseEvent(ev.xkey);
60 break;
61 case ButtonPress:
62 evhand->buttonPressEvent(ev.xbutton);
63 break;
64 case ButtonRelease:
65 evhand->buttonReleaseEvent(ev.xbutton);
66 break;
67 case MotionNotify:
68 evhand->motionNotifyEvent(ev.xmotion);
69 break;
70 case Expose:
71 evhand->exposeEvent(ev.xexpose);
72 break;
73 case EnterNotify:
74 evhand->enterNotifyEvent(ev.xcrossing);
75 break;
76 case LeaveNotify:
77 evhand->leaveNotifyEvent(ev.xcrossing);
78 break;
79 default:
80 evhand->handleEvent(ev);
81 break;
82 };
83}
84
85void EventManager::add(EventHandler &ev, const FbWindow &win) {
86 registerEventHandler(ev, win.window());
87}
88
89void EventManager::remove(const FbWindow &win) {
90 unregisterEventHandler(win.window());
91}
92
93void EventManager::registerEventHandler(EventHandler &ev, Window win) {
94 m_eventhandlers[win] = &ev;
95}
96
97void EventManager::unregisterEventHandler(Window win) {
98 if (win != None)
99 m_eventhandlers.erase(win);
100}
101
102};