Gnash  0.8.11dev
event_id.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
3 // Free Software Foundation, Inc
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program 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
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 //
19 
20 
21 #ifndef GNASH_EVENT_ID_H
22 #define GNASH_EVENT_ID_H
23 
24 #include <string>
25 #include "GnashKey.h"
26 
27 // Forward declarations
28 namespace gnash {
29  struct ObjectURI;
30 }
31 
32 namespace gnash {
33 
34 
36 //
42 //
47 //
49 //
52 class event_id
53 {
54 public:
55 
57  enum EventCode
58  {
60 
61  // These are for buttons and sprites.
70 
71  // These are for sprites only.
82  CONSTRUCT
83  };
84 
86  //
89  :
90  _id(INVALID),
91  _keyCode(key::INVALID)
92  {}
93 
95  //
100  :
101  _id(id),
102  _keyCode(c)
103  {
104  // We do have a testcase with _id == KEY_PRESS,
105  // and keyCode==0(KEY_INVALID)
106  // see key_event_test.swf(produced by Ming)
107  }
108 
110  //
113  void setKeyCode(std::uint8_t SWFkey)
114  {
115  // Lookup the SWFcode in the gnash::key::code table.
116  // Some are not unique (keypad numbers are the
117  // same as normal numbers), so we take the first match.
118  // As long as we can work out the SWFCode from the
119  // gnash::key::code it's all right.
120  int i = 0;
121  while (i < key::KEYCOUNT && key::codeMap[i][key::SWF] != SWFkey) i++;
122 
123  if (i == key::KEYCOUNT) _keyCode = key::INVALID;
124  else _keyCode = static_cast<key::code>(i);
125  }
126 
129  const std::string& functionName() const;
130 
133  const ObjectURI& functionURI() const;
134 
136  //
138  key::code keyCode() const { return _keyCode; }
139 
141  EventCode id() const { return _id; }
142 
143 private:
144 
145  EventCode _id;
146 
147  // keyCode must be the unique gnash key identifier
148  // gnash::key::code.
149  // TextField has to be able to work out the
150  // ASCII value from keyCode, while other users need
151  // the SWF code or the Flash key code.
152  key::code _keyCode;
153 
154 
155 };
156 
158 //
162 inline bool
163 operator==(const event_id& a, const event_id& b)
164 {
165  return a.id() == b.id() && a.keyCode() == b.keyCode();
166 }
167 
169 inline bool
170 operator<(const event_id& a, const event_id& b)
171 {
172  if (a.id() == b.id()) return a.keyCode() < b.keyCode();
173  return a.id() < b.id();
174 }
175 
176 
178 //
181 bool isButtonEvent(const event_id& e);
182 
184 //
187 bool isKeyEvent(const event_id& e);
188 
189 std::ostream& operator<< (std::ostream& o, const event_id& ev);
190 
191 } // namespace gnash
192 
193 
194 #endif
195 
196 
197 // Local Variables:
198 // mode: C++
199 // indent-tabs-mode: t
200 // End:
gnash::NSV::PROP_ON_LOAD
@ PROP_ON_LOAD
Definition: namedStrings.h:160
gnash::NSV::PROP_ON_ENTER_FRAME
@ PROP_ON_ENTER_FRAME
Definition: namedStrings.h:153
gnash::NSV::PROP_ON_MOUSE_MOVE
@ PROP_ON_MOUSE_MOVE
Definition: namedStrings.h:167
gnash::NSV::PROP_ON_PRESS
@ PROP_ON_PRESS
Definition: namedStrings.h:169
gnash::NSV::PROP_ON_MOUSE_DOWN
@ PROP_ON_MOUSE_DOWN
Definition: namedStrings.h:166
gnash::NSV::PROP_ON_KEY_DOWN
@ PROP_ON_KEY_DOWN
Definition: namedStrings.h:156
gnash::isKeyEvent
bool isKeyEvent(const event_id &e)
Check whether an event is a keyboard event.
Definition: event_id.cpp:104
ObjectURI.h
gnash::event_id::LOAD
@ LOAD
Definition: event_id.h:73
gnash::event_id::MOUSE_UP
@ MOUSE_UP
Definition: event_id.h:77
gnash::key::i
@ i
Definition: GnashKey.h:155
gnash::NSV::PROP_ON_UNLOAD
@ PROP_ON_UNLOAD
Definition: namedStrings.h:181
gnash::event_id::functionURI
const ObjectURI & functionURI() const
Definition: event_id.cpp:68
gnash::event_id
A class to identify 'static' SWF events (system events).
Definition: event_id.h:53
gnash::EventCode
Event code.
Definition: ExecutableCode.h:85
gnash
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:41
gnash::event_id::id
EventCode id() const
Return the identifier for this event type.
Definition: event_id.h:141
gnash::event_id::ROLL_OVER
@ ROLL_OVER
Definition: event_id.h:65
GnashKey.h
gnash::event_id::setKeyCode
void setKeyCode(std::uint8_t SWFkey)
Set the key associated with this event.
Definition: event_id.h:113
gnash::NSV::PROP_ON_KEY_PRESS
@ PROP_ON_KEY_PRESS
Definition: namedStrings.h:157
event_id.h
gnash::isButtonEvent
bool isButtonEvent(const event_id &e)
Check whether an event is a button-like event.
Definition: event_id.cpp:118
gnash::event_id::DRAG_OVER
@ DRAG_OVER
Definition: event_id.h:67
gnash::event_id::ROLL_OUT
@ ROLL_OUT
Definition: event_id.h:66
gnash::event_id::DATA
@ DATA
Definition: event_id.h:81
gnash::event_id::RELEASE
@ RELEASE
Definition: event_id.h:63
gnash::key::a
@ a
Definition: GnashKey.h:147
gnash::event_id::EventCode
EventCode
The types of events that are handled by DisplayObjects.
Definition: event_id.h:58
gnash::key::codeMap
const unsigned char codeMap[KEYCOUNT][TYPES]
Definition: GnashKey.h:337
gnash::event_id::INVALID
@ INVALID
Definition: event_id.h:59
gnash::key::code
code
Definition: GnashKey.h:44
gnash::NSV::PROP_ON_DRAG_OVER
@ PROP_ON_DRAG_OVER
Definition: namedStrings.h:152
gnash::key::INVALID
@ INVALID
Definition: GnashKey.h:45
gnash::key::KEYCOUNT
@ KEYCOUNT
Definition: GnashKey.h:326
gnash::event_id::UNLOAD
@ UNLOAD
Definition: event_id.h:74
gnash::event_id::PRESS
@ PRESS
Definition: event_id.h:62
gnash::event_id::event_id
event_id()
Construct an invalid event_id.
Definition: event_id.h:88
log.h
gnash::NSV::PROP_ON_DATA
@ PROP_ON_DATA
Definition: namedStrings.h:150
gnash::event_id::MOUSE_DOWN
@ MOUSE_DOWN
Definition: event_id.h:76
gnash::NSV::PROP_ON_KEY_UP
@ PROP_ON_KEY_UP
Definition: namedStrings.h:158
gnash::event_id::KEY_DOWN
@ KEY_DOWN
Definition: event_id.h:79
gnash::NSV::PROP_ON_RELEASE_OUTSIDE
@ PROP_ON_RELEASE_OUTSIDE
Definition: namedStrings.h:171
gnash::NSV::PROP_ON_RELEASE
@ PROP_ON_RELEASE
Definition: namedStrings.h:170
gnash::NSV::PROP_ON_MOUSE_UP
@ PROP_ON_MOUSE_UP
Definition: namedStrings.h:168
namedStrings.h
gnash::operator<
bool operator<(const event_id &a, const event_id &b)
Comparator for use in stdlib containers.
Definition: event_id.h:170
gnash::key::c
@ c
Definition: GnashKey.h:149
gnash::NSV::PROP_ON_ROLL_OVER
@ PROP_ON_ROLL_OVER
Definition: namedStrings.h:175
gnash::NSV::PROP_ON_INITIALIZE
@ PROP_ON_INITIALIZE
Definition: namedStrings.h:155
gnash::NSV::PROP_ON_ROLL_OUT
@ PROP_ON_ROLL_OUT
Definition: namedStrings.h:174
gnash::event_id::INITIALIZE
@ INITIALIZE
Definition: event_id.h:72
gnash::event_id::event_id
event_id(EventCode id, key::code c=key::INVALID)
Construct an event_id.
Definition: event_id.h:99
gnash::event_id::CONSTRUCT
@ CONSTRUCT
Definition: event_id.h:82
gnash::event_id::RELEASE_OUTSIDE
@ RELEASE_OUTSIDE
Definition: event_id.h:64
gnash::NSV::PROP_ON_DRAG_OUT
@ PROP_ON_DRAG_OUT
Definition: namedStrings.h:151
gnash::operator==
bool operator==(const event_id &a, const event_id &b)
Return whether two event_ids are equal.
Definition: event_id.h:163
gnash::key::o
@ o
Definition: GnashKey.h:161
gnash::event_id::ENTER_FRAME
@ ENTER_FRAME
Definition: event_id.h:75
gnash::key::SWF
@ SWF
Definition: GnashKey.h:331
gnash::ObjectURI
A URI for describing as_objects.
Definition: ObjectURI.h:45
gnash::event_id::KEY_UP
@ KEY_UP
Definition: event_id.h:80
gnash::event_id::MOUSE_MOVE
@ MOUSE_MOVE
Definition: event_id.h:78
gnash::event_id::functionName
const std::string & functionName() const
Definition: event_id.cpp:36
gnash::key::b
@ b
Definition: GnashKey.h:148
gnash::key::e
@ e
Definition: GnashKey.h:151
gnash::event_id::KEY_PRESS
@ KEY_PRESS
Definition: event_id.h:69
gnash::event_id::keyCode
key::code keyCode() const
Return the keycode associated with this event_id.
Definition: event_id.h:138
gnash::NSV::PROP_ON_CONSTRUCT
@ PROP_ON_CONSTRUCT
Definition: namedStrings.h:149
gnash::event_id::DRAG_OUT
@ DRAG_OUT
Definition: event_id.h:68
gnash::operator<<
std::ostream & operator<<(std::ostream &o, const URL &u)
Definition: URL.cpp:447