EventDispatcher.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. //
  2. // EventDispatcher.h
  3. //
  4. // Library: XML
  5. // Package: DOM
  6. // Module: DOMEvents
  7. //
  8. // Definition of the EventDispatcher class.
  9. //
  10. // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
  11. // and Contributors.
  12. //
  13. // SPDX-License-Identifier: BSL-1.0
  14. //
  15. #ifndef DOM_EventDispatcher_INCLUDED
  16. #define DOM_EventDispatcher_INCLUDED
  17. #include "Poco/XML/XML.h"
  18. #include "Poco/XML/XMLString.h"
  19. #include <list>
  20. namespace Poco {
  21. namespace XML {
  22. class Event;
  23. class EventListener;
  24. class XML_API EventDispatcher
  25. /// This helper class manages event listener subscriptions
  26. /// and event dispatching for AbstractNode.
  27. ///
  28. /// The EventListener list is managed in such a way that
  29. /// event listeners can be added and removed even
  30. /// from within an EventListener, while events are being
  31. /// dispatched.
  32. {
  33. public:
  34. EventDispatcher();
  35. /// Creates the EventDispatcher.
  36. ~EventDispatcher();
  37. /// Destroys the EventDispatcher.
  38. void addEventListener(const XMLString& type, EventListener* listener, bool useCapture);
  39. /// Adds an EventListener to the internal list.
  40. void removeEventListener(const XMLString& type, EventListener* listener, bool useCapture);
  41. /// Removes an EventListener from the internal list.
  42. ///
  43. /// If a dispatch is currently in progress, the list
  44. /// entry is only marked for deletion.
  45. /// If no dispatch is currently in progress, all EventListeners
  46. /// marked for deletion are removed from the list.
  47. void dispatchEvent(Event* evt);
  48. /// Dispatches the event.
  49. ///
  50. /// Also removes all EventListeners marked for deletion from the
  51. /// event dispatcher list.
  52. void captureEvent(Event* evt);
  53. /// Dispatches the event in its capturing phase.
  54. ///
  55. /// Also removes all EventListeners marked for deletion from the
  56. /// event dispatcher list.
  57. void bubbleEvent(Event* evt);
  58. /// Dispatches the event in its bubbling phase.
  59. ///
  60. /// Also removes all EventListeners marked for deletion from the
  61. /// event dispatcher list.
  62. private:
  63. struct EventListenerItem
  64. {
  65. XMLString type;
  66. EventListener* pListener;
  67. bool useCapture;
  68. };
  69. typedef std::list<EventListenerItem> EventListenerList;
  70. int _inDispatch;
  71. EventListenerList _listeners;
  72. };
  73. } } // namespace Poco::XML
  74. #endif // DOM_EventDispatcher_INCLUDED