fixed dispatch to parent
This commit is contained in:
parent
bc8e67136f
commit
efc1ec4b20
2 changed files with 66 additions and 31 deletions
|
@ -19,10 +19,11 @@
|
||||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
// $Id: EventManager.cc,v 1.6 2003/05/17 10:40:12 fluxgen Exp $
|
// $Id: EventManager.cc,v 1.7 2003/08/23 15:44:06 fluxgen Exp $
|
||||||
|
|
||||||
#include "EventManager.hh"
|
#include "EventManager.hh"
|
||||||
#include "FbWindow.hh"
|
#include "FbWindow.hh"
|
||||||
|
#include "App.hh"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
@ -40,16 +41,44 @@ EventManager::~EventManager() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventManager::handleEvent(XEvent &ev) {
|
void EventManager::handleEvent(XEvent &ev) {
|
||||||
// find eventhandler for event window
|
dispatch(ev.xany.window, ev);
|
||||||
if (m_eventhandlers.find(ev.xany.window) == m_eventhandlers.end()) {
|
}
|
||||||
//cerr<<"Can't find window="<<ev.xany.window<<endl;
|
|
||||||
return;
|
void EventManager::add(EventHandler &ev, const FbWindow &win) {
|
||||||
|
registerEventHandler(ev, win.window());
|
||||||
|
}
|
||||||
|
|
||||||
|
void EventManager::addParent(EventHandler &ev, const FbWindow &win) {
|
||||||
|
if (win.window() != 0)
|
||||||
|
m_parent[win.window()] = &ev;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EventManager::remove(const FbWindow &win) {
|
||||||
|
unregisterEventHandler(win.window());
|
||||||
|
}
|
||||||
|
|
||||||
|
void EventManager::registerEventHandler(EventHandler &ev, Window win) {
|
||||||
|
if (win != None)
|
||||||
|
m_eventhandlers[win] = &ev;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EventManager::unregisterEventHandler(Window win) {
|
||||||
|
if (win != None) {
|
||||||
|
m_eventhandlers.erase(win);
|
||||||
|
m_parent.erase(win);
|
||||||
}
|
}
|
||||||
EventHandler *evhand = m_eventhandlers[ev.xany.window];
|
}
|
||||||
if (evhand == 0) {
|
|
||||||
cerr<<"FbTk::EventManager: Warning: evhand == 0!"<<endl;
|
void EventManager::dispatch(Window win, XEvent &ev, bool parent) {
|
||||||
|
|
||||||
|
EventHandler *evhand = 0;
|
||||||
|
if (parent)
|
||||||
|
evhand = m_parent[win];
|
||||||
|
else
|
||||||
|
evhand = m_eventhandlers[win];
|
||||||
|
|
||||||
|
if (evhand == 0)
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
switch (ev.xany.type) {
|
switch (ev.xany.type) {
|
||||||
case KeyPress:
|
case KeyPress:
|
||||||
|
@ -80,24 +109,27 @@ void EventManager::handleEvent(XEvent &ev) {
|
||||||
evhand->handleEvent(ev);
|
evhand->handleEvent(ev);
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// find out which window is the parent and
|
||||||
|
// dispatch event
|
||||||
|
Window root, parent_win, *children = 0;
|
||||||
|
unsigned int num_children;
|
||||||
|
if (XQueryTree(FbTk::App::instance()->display(), win,
|
||||||
|
&root, &parent_win, &children, &num_children) != 0 &&
|
||||||
|
parent_win != 0 &&
|
||||||
|
parent_win != root) {
|
||||||
|
|
||||||
|
if (children != 0)
|
||||||
|
XFree(children);
|
||||||
|
|
||||||
|
if (m_parent[parent_win] == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// dispatch event to parent
|
||||||
|
dispatch(parent_win, ev, true);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventManager::add(EventHandler &ev, const FbWindow &win) {
|
}; // end namespace FbTk
|
||||||
registerEventHandler(ev, win.window());
|
|
||||||
}
|
|
||||||
|
|
||||||
void EventManager::remove(const FbWindow &win) {
|
|
||||||
unregisterEventHandler(win.window());
|
|
||||||
}
|
|
||||||
|
|
||||||
void EventManager::registerEventHandler(EventHandler &ev, Window win) {
|
|
||||||
if (win != None)
|
|
||||||
m_eventhandlers[win] = &ev;
|
|
||||||
}
|
|
||||||
|
|
||||||
void EventManager::unregisterEventHandler(Window win) {
|
|
||||||
if (win != None)
|
|
||||||
m_eventhandlers.erase(win);
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
// $Id: EventManager.hh,v 1.4 2002/12/03 17:05:45 fluxgen Exp $
|
// $Id: EventManager.hh,v 1.5 2003/08/23 15:44:06 fluxgen Exp $
|
||||||
|
|
||||||
#include "EventHandler.hh"
|
#include "EventHandler.hh"
|
||||||
#include <map>
|
#include <map>
|
||||||
|
@ -36,6 +36,8 @@ public:
|
||||||
static EventManager *instance();
|
static EventManager *instance();
|
||||||
|
|
||||||
void handleEvent(XEvent &ev);
|
void handleEvent(XEvent &ev);
|
||||||
|
// adds a parent to listen to the childrens events
|
||||||
|
void addParent(EventHandler &ev, const FbWindow &parent);
|
||||||
void add(EventHandler &ev, const FbWindow &win);
|
void add(EventHandler &ev, const FbWindow &win);
|
||||||
void remove(const FbWindow &win);
|
void remove(const FbWindow &win);
|
||||||
void add(EventHandler &ev, Window win) { registerEventHandler(ev, win); }
|
void add(EventHandler &ev, Window win) { registerEventHandler(ev, win); }
|
||||||
|
@ -45,8 +47,9 @@ public:
|
||||||
private:
|
private:
|
||||||
EventManager() { }
|
EventManager() { }
|
||||||
~EventManager();
|
~EventManager();
|
||||||
|
void dispatch(Window win, XEvent &event, bool parent = false);
|
||||||
std::map<Window, EventHandler *> m_eventhandlers;
|
std::map<Window, EventHandler *> m_eventhandlers;
|
||||||
|
std::map<Window, EventHandler *> m_parent;
|
||||||
};
|
};
|
||||||
|
|
||||||
}; //end namespace FbTk
|
}; //end namespace FbTk
|
||||||
|
|
Loading…
Reference in a new issue