1 // Canvas Event for event model similar to DOM Level 3 Event Model
3 // Copyright (C) 2012 Thomas Geymayer <tomgey@gmail.com>
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Library General Public
7 // License as published by the Free Software Foundation; either
8 // version 2 of the License, or (at your option) any later version.
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Library General Public License for more details.
15 // You should have received a copy of the GNU Library General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include "CanvasEvent.hxx"
26 //----------------------------------------------------------------------------
30 propagation_stopped(false),
31 default_prevented(false)
36 //----------------------------------------------------------------------------
42 //----------------------------------------------------------------------------
43 bool Event::canBubble() const
48 //----------------------------------------------------------------------------
49 int Event::getType() const
54 //----------------------------------------------------------------------------
55 std::string Event::getTypeString() const
57 return typeToStr(type);
60 //----------------------------------------------------------------------------
61 ElementWeakPtr Event::getTarget() const
66 //----------------------------------------------------------------------------
67 ElementWeakPtr Event::getCurrentTarget() const
69 return current_target;
72 //----------------------------------------------------------------------------
73 double Event::getTime() const
78 //----------------------------------------------------------------------------
79 void Event::stopPropagation()
81 propagation_stopped = true;
84 //----------------------------------------------------------------------------
85 void Event::preventDefault()
87 default_prevented = true;
90 //----------------------------------------------------------------------------
91 bool Event::defaultPrevented() const
93 return default_prevented;
96 //----------------------------------------------------------------------------
97 int Event::getOrRegisterType(const std::string& type_str)
99 int type = strToType(type_str);
101 if( type == UNKNOWN )
104 TypeMap& type_map = getTypeMap();
105 type = type_map.size() + 1; // ids start with 1 (after UNKNOWN)
106 type_map.insert(TypeMap::value_type(type_str, type));
112 //----------------------------------------------------------------------------
113 int Event::strToType(const std::string& str)
115 TypeMap const& type_map = getTypeMap();
117 TypeMap::map_by<name>::const_iterator it = type_map.by<name>().find(str);
118 if( it == type_map.by<name>().end() )
123 //----------------------------------------------------------------------------
124 std::string Event::typeToStr(int type)
126 TypeMap const& type_map = getTypeMap();
128 TypeMap::map_by<id>::const_iterator it = type_map.by<id>().find(type);
129 if( it == type_map.by<id>().end() )
134 //----------------------------------------------------------------------------
135 Event::TypeMap& Event::getTypeMap()
137 static TypeMap type_map;
139 if( type_map.empty() )
141 # define ENUM_MAPPING(type, str, class_name)\
142 type_map.insert(TypeMap::value_type(str, type));
143 # include "CanvasEventTypes.hxx"
150 } // namespace canvas
151 } // namespace simgear