root / Community Core Vision / Windows / libs / poco / include / Poco / DOM / EventDispatcher.h @ 8

View | Annotate | Download (3.6 KB)

1 8 amit
//
2 8 amit
// EventDispatcher.h
3 8 amit
//
4 8 amit
// $Id: //poco/1.3/XML/include/Poco/DOM/EventDispatcher.h#1 $
5 8 amit
//
6 8 amit
// Library: XML
7 8 amit
// Package: DOM
8 8 amit
// Module:  DOMEvents
9 8 amit
//
10 8 amit
// Definition of the EventDispatcher class.
11 8 amit
//
12 8 amit
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
13 8 amit
// and Contributors.
14 8 amit
//
15 8 amit
// Permission is hereby granted, free of charge, to any person or organization
16 8 amit
// obtaining a copy of the software and accompanying documentation covered by
17 8 amit
// this license (the "Software") to use, reproduce, display, distribute,
18 8 amit
// execute, and transmit the Software, and to prepare derivative works of the
19 8 amit
// Software, and to permit third-parties to whom the Software is furnished to
20 8 amit
// do so, all subject to the following:
21 8 amit
//
22 8 amit
// The copyright notices in the Software and this entire statement, including
23 8 amit
// the above license grant, this restriction and the following disclaimer,
24 8 amit
// must be included in all copies of the Software, in whole or in part, and
25 8 amit
// all derivative works of the Software, unless such copies or derivative
26 8 amit
// works are solely in the form of machine-executable object code generated by
27 8 amit
// a source language processor.
28 8 amit
//
29 8 amit
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30 8 amit
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31 8 amit
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
32 8 amit
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
33 8 amit
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
34 8 amit
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
35 8 amit
// DEALINGS IN THE SOFTWARE.
36 8 amit
//
37 8 amit
38 8 amit
39 8 amit
#ifndef DOM_EventDispatcher_INCLUDED
40 8 amit
#define DOM_EventDispatcher_INCLUDED
41 8 amit
42 8 amit
43 8 amit
#include "Poco/XML/XML.h"
44 8 amit
#include "Poco/XML/XMLString.h"
45 8 amit
#include <list>
46 8 amit
47 8 amit
48 8 amit
namespace Poco {
49 8 amit
namespace XML {
50 8 amit
51 8 amit
52 8 amit
class Event;
53 8 amit
class EventListener;
54 8 amit
55 8 amit
56 8 amit
class XML_API EventDispatcher
57 8 amit
        /// This helper class manages event listener subscriptions
58 8 amit
        /// and event dispatching for AbstractNode.
59 8 amit
        ///
60 8 amit
        /// The EventListener list is managed in such a way that
61 8 amit
        /// event listeners can be added and removed even
62 8 amit
        /// from within an EventListener, while events are being
63 8 amit
        /// dispatched.
64 8 amit
{
65 8 amit
public:
66 8 amit
        EventDispatcher();
67 8 amit
                /// Creates the EventDispatcher.
68 8 amit
69 8 amit
        ~EventDispatcher();
70 8 amit
                /// Destroys the EventDispatcher.
71 8 amit
72 8 amit
        void addEventListener(const XMLString& type, EventListener* listener, bool useCapture);
73 8 amit
                /// Adds an EventListener to the internal list.
74 8 amit
75 8 amit
        void removeEventListener(const XMLString& type, EventListener* listener, bool useCapture);
76 8 amit
                /// Removes an EventListener from the internal list.
77 8 amit
                ///
78 8 amit
                /// If a dispatch is currently in progress, the list
79 8 amit
                /// entry is only marked for deletion.
80 8 amit
                /// If no dispatch is currently in progress, all EventListeners
81 8 amit
                /// marked for deletion are removed from the list.
82 8 amit
83 8 amit
        void dispatchEvent(Event* evt);
84 8 amit
                /// Dispatches the event.
85 8 amit
                ///
86 8 amit
                /// Also removes all EventListeners marked for deletion from the
87 8 amit
                /// event dispatcher list.
88 8 amit
89 8 amit
        void captureEvent(Event* evt);
90 8 amit
                /// Dispatches the event in its capturing phase.
91 8 amit
                ///
92 8 amit
                /// Also removes all EventListeners marked for deletion from the
93 8 amit
                /// event dispatcher list.
94 8 amit
95 8 amit
        void bubbleEvent(Event* evt);
96 8 amit
                /// Dispatches the event in its bubbling phase.
97 8 amit
                ///
98 8 amit
                /// Also removes all EventListeners marked for deletion from the
99 8 amit
                /// event dispatcher list.
100 8 amit
101 8 amit
private:
102 8 amit
        struct EventListenerItem
103 8 amit
        {
104 8 amit
                XMLString      type;
105 8 amit
                EventListener* pListener;
106 8 amit
                bool           useCapture;
107 8 amit
        };
108 8 amit
109 8 amit
        typedef std::list<EventListenerItem> EventListenerList;
110 8 amit
111 8 amit
        int               _inDispatch;
112 8 amit
        EventListenerList _listeners;
113 8 amit
};
114 8 amit
115 8 amit
116 8 amit
} } // namespace Poco::XML
117 8 amit
118 8 amit
119 8 amit
#endif // DOM_EventDispatcher_INCLUDED