From efc1ec4b206f3e24c1fd9ca29096f23735f2e7ae Mon Sep 17 00:00:00 2001 From: fluxgen Date: Sat, 23 Aug 2003 15:44:06 +0000 Subject: fixed dispatch to parent --- src/FbTk/EventManager.cc | 82 +++++++++++++++++++++++++++++++++--------------- src/FbTk/EventManager.hh | 7 +++-- 2 files changed, 62 insertions(+), 27 deletions(-) diff --git a/src/FbTk/EventManager.cc b/src/FbTk/EventManager.cc index 1f2aef1..cd23416 100644 --- a/src/FbTk/EventManager.cc +++ b/src/FbTk/EventManager.cc @@ -19,10 +19,11 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // 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 "FbWindow.hh" +#include "App.hh" #include using namespace std; @@ -40,17 +41,45 @@ EventManager::~EventManager() { } void EventManager::handleEvent(XEvent &ev) { - // find eventhandler for event window - if (m_eventhandlers.find(ev.xany.window) == m_eventhandlers.end()) { - //cerr<<"Can't find window="<keyPressEvent(ev.xkey); @@ -80,24 +109,27 @@ void EventManager::handleEvent(XEvent &ev) { evhand->handleEvent(ev); break; }; -} -void EventManager::add(EventHandler &ev, const FbWindow &win) { - registerEventHandler(ev, win.window()); -} + // 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) { -void EventManager::remove(const FbWindow &win) { - unregisterEventHandler(win.window()); -} + if (children != 0) + XFree(children); -void EventManager::registerEventHandler(EventHandler &ev, Window win) { - if (win != None) - m_eventhandlers[win] = &ev; -} + if (m_parent[parent_win] == 0) + return; + + // dispatch event to parent + dispatch(parent_win, ev, true); + + } -void EventManager::unregisterEventHandler(Window win) { - if (win != None) - m_eventhandlers.erase(win); } -}; +}; // end namespace FbTk diff --git a/src/FbTk/EventManager.hh b/src/FbTk/EventManager.hh index 7d67331..7d1562e 100644 --- a/src/FbTk/EventManager.hh +++ b/src/FbTk/EventManager.hh @@ -19,7 +19,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // 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 @@ -36,6 +36,8 @@ public: static EventManager *instance(); 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 remove(const FbWindow &win); void add(EventHandler &ev, Window win) { registerEventHandler(ev, win); } @@ -45,8 +47,9 @@ public: private: EventManager() { } ~EventManager(); - + void dispatch(Window win, XEvent &event, bool parent = false); std::map m_eventhandlers; + std::map m_parent; }; }; //end namespace FbTk -- cgit v0.11.2