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)
35 //----------------------------------------------------------------------------
41 //----------------------------------------------------------------------------
42 bool Event::canBubble() const
47 //----------------------------------------------------------------------------
48 int Event::getType() const
53 //----------------------------------------------------------------------------
54 std::string Event::getTypeString() const
56 return typeToStr(type);
59 //----------------------------------------------------------------------------
60 ElementWeakPtr Event::getTarget() const
65 //----------------------------------------------------------------------------
66 ElementWeakPtr Event::getCurrentTarget() const
68 return current_target;
71 //----------------------------------------------------------------------------
72 double Event::getTime() const
77 //----------------------------------------------------------------------------
78 void Event::stopPropagation()
80 propagation_stopped = true;
83 //----------------------------------------------------------------------------
84 int Event::getOrRegisterType(const std::string& type_str)
86 int type = strToType(type_str);
91 TypeMap& type_map = getTypeMap();
92 type = type_map.size() + 1; // ids start with 1 (after UNKNOWN)
93 type_map.insert(TypeMap::value_type(type_str, type));
99 //----------------------------------------------------------------------------
100 int Event::strToType(const std::string& str)
102 TypeMap const& type_map = getTypeMap();
104 TypeMap::map_by<name>::const_iterator it = type_map.by<name>().find(str);
105 if( it == type_map.by<name>().end() )
110 //----------------------------------------------------------------------------
111 std::string Event::typeToStr(int type)
113 TypeMap const& type_map = getTypeMap();
115 TypeMap::map_by<id>::const_iterator it = type_map.by<id>().find(type);
116 if( it == type_map.by<id>().end() )
121 //----------------------------------------------------------------------------
122 Event::TypeMap& Event::getTypeMap()
124 static TypeMap type_map;
126 if( type_map.empty() )
128 # define ENUM_MAPPING(type, str)\
129 type_map.insert(TypeMap::value_type(str, type));
130 # include "CanvasEventTypes.hxx"
137 } // namespace canvas
138 } // namespace simgear