2 /// Canvas Event for event model similar to DOM Level 3 Event Model
4 // Copyright (C) 2012 Thomas Geymayer <tomgey@gmail.com>
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Library General Public
8 // License as published by the Free Software Foundation; either
9 // version 2 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Library General Public License for more details.
16 // You should have received a copy of the GNU Library General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #ifndef CANVAS_EVENT_HXX_
21 #define CANVAS_EVENT_HXX_
23 #include "canvas_fwd.hxx"
24 #include <boost/bimap.hpp>
32 * Base class for all Canvas events.
34 * The event system is closely following the specification of the DOM Level 3
42 /// Event type identifier
46 # define ENUM_MAPPING(name, str, class_name)\
47 name, /*!< class_name (type=str) */
48 # include "CanvasEventTypes.hxx"
50 CUSTOM_EVENT ///< First event type id available for user defined event
56 ElementWeakPtr target,
59 bool propagation_stopped,
64 // We need a vtable to allow nasal::Ghost to determine the dynamic type
65 // of the actual event instances.
69 * Get whether this events support bubbling
71 virtual bool canBubble() const;
76 * If no such type exists it is registered.
78 void setType(const std::string& type);
81 std::string getTypeString() const;
83 ElementWeakPtr getTarget() const;
84 ElementWeakPtr getCurrentTarget() const;
87 * Get time at which the event was generated.
89 double getTime() const;
92 * Prevent further propagation of the event during event flow.
94 * @note This does not prevent calling further event handlers registered
95 * on the current event target.
97 void stopPropagation();
100 * Cancel any default action normally taken as result of this event.
102 * @note For event handlers registered on the DesktopGroup (Nasal:
103 * canvas.getDesktop()) this stops the event from being further
104 * propagated to the normal FlightGear input event handling code.
106 void preventDefault();
109 * Get if preventDefault() has been called.
111 bool defaultPrevented() const;
113 static int getOrRegisterType(const std::string& type);
114 static int strToType(const std::string& type);
115 static std::string typeToStr(int type);
120 typedef boost::bimaps::bimap<
121 boost::bimaps::tagged<std::string, name>,
122 boost::bimaps::tagged<int, id>
125 static TypeMap& getTypeMap();
129 } // namespace canvas
130 } // namespace simgear
132 #endif /* CANVAS_EVENT_HXX_ */