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