diff --git a/panda/src/event/eventHandler.cxx b/panda/src/event/eventHandler.cxx index dd68adc4ae..29147d7298 100644 --- a/panda/src/event/eventHandler.cxx +++ b/panda/src/event/eventHandler.cxx @@ -163,10 +163,37 @@ add_hook(const string &event_name, EventFunction *function) { //////////////////////////////////////////////////////////////////// bool EventHandler:: add_hook(const string &event_name, EventCallbackFunction *function, - void *data) { + void *data) { return _cbhooks[event_name].insert(CallbackFunction(function, data)).second; } +//////////////////////////////////////////////////////////////////// +// Function: EventHandler::has_hook +// Access: Public +// Description: Returns true if there is any hook added on the +// indicated event name, false otherwise. +//////////////////////////////////////////////////////////////////// +bool EventHandler:: +has_hook(const string &event_name) const { + Hooks::const_iterator hi; + hi = _hooks.find(event_name); + if (hi != _hooks.end()) { + if (!(*hi).second.empty()) { + return true; + } + } + + CallbackHooks::const_iterator chi; + chi = _cbhooks.find(event_name); + if (chi != _cbhooks.end()) { + if (!(*chi).second.empty()) { + return true; + } + } + + return false; +} + //////////////////////////////////////////////////////////////////// // Function: EventHandler::remove_hook @@ -191,7 +218,7 @@ remove_hook(const string &event_name, EventFunction *function) { //////////////////////////////////////////////////////////////////// bool EventHandler:: remove_hook(const string &event_name, EventCallbackFunction *function, - void *data) { + void *data) { return _cbhooks[event_name].erase(CallbackFunction(function, data)) != 0; } diff --git a/panda/src/event/eventHandler.h b/panda/src/event/eventHandler.h index 714a0b0e77..8ad409f024 100644 --- a/panda/src/event/eventHandler.h +++ b/panda/src/event/eventHandler.h @@ -45,7 +45,7 @@ class EXPCL_PANDAEXPRESS EventHandler : public TypedObject { public: // Define a function type suitable for receiving events. typedef void EventFunction(CPT_Event); - typedef void EventCallbackFunction(CPT(Event), void*); + typedef void EventCallbackFunction(CPT_Event, void *); PUBLISHED: EventHandler(EventQueue *queue); @@ -59,10 +59,11 @@ PUBLISHED: public: bool add_hook(const string &event_name, EventFunction *function); bool add_hook(const string &event_name, EventCallbackFunction *function, - void*); + void *data); + bool has_hook(const string &event_name) const; bool remove_hook(const string &event_name, EventFunction *function); bool remove_hook(const string &event_name, EventCallbackFunction *function, - void*); + void *data); void remove_all_hooks();