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
16
17#ifndef DOM_EventDispatcher_INCLUDED
18#define DOM_EventDispatcher_INCLUDED
19
20
21#include "Poco/XML/XML.h"
22#include "Poco/XML/XMLString.h"
23#include <list>
24
25
26namespace Poco {
27namespace XML {
28
29
30class Event;
31class EventListener;
32
33
34class XML_API EventDispatcher
35 /// This helper class manages event listener subscriptions
36 /// and event dispatching for AbstractNode.
37 ///
38 /// The EventListener list is managed in such a way that
39 /// event listeners can be added and removed even
40 /// from within an EventListener, while events are being
41 /// dispatched.
42{
43public:
44 EventDispatcher();
45 /// Creates the EventDispatcher.
46
47 ~EventDispatcher();
48 /// Destroys the EventDispatcher.
49
50 void addEventListener(const XMLString& type, EventListener* listener, bool useCapture);
51 /// Adds an EventListener to the internal list.
52
53 void removeEventListener(const XMLString& type, EventListener* listener, bool useCapture);
54 /// Removes an EventListener from the internal list.
55 ///
56 /// If a dispatch is currently in progress, the list
57 /// entry is only marked for deletion.
58 /// If no dispatch is currently in progress, all EventListeners
59 /// marked for deletion are removed from the list.
60
61 void dispatchEvent(Event* evt);
62 /// Dispatches the event.
63 ///
64 /// Also removes all EventListeners marked for deletion from the
65 /// event dispatcher list.
66
67 void captureEvent(Event* evt);
68 /// Dispatches the event in its capturing phase.
69 ///
70 /// Also removes all EventListeners marked for deletion from the
71 /// event dispatcher list.
72
73 void bubbleEvent(Event* evt);
74 /// Dispatches the event in its bubbling phase.
75 ///
76 /// Also removes all EventListeners marked for deletion from the
77 /// event dispatcher list.
78
79private:
80 struct EventListenerItem
81 {
82 XMLString type;
83 EventListener* pListener;
84 bool useCapture;
85 };
86
87 typedef std::list<EventListenerItem> EventListenerList;
88
89 int _inDispatch;
90 EventListenerList _listeners;
91};
92
93
94} } // namespace Poco::XML
95
96
97#endif // DOM_EventDispatcher_INCLUDED
98