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.
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:
Definition: GnashKey.h:147
key::code keyCode() const
Return the keycode associated with this event_id.
Definition: event_id.h:138
bool isButtonEvent(const event_id &e)
Check whether an event is a button-like event.
Definition: event_id.cpp:118
event_id()
Construct an invalid event_id.
Definition: event_id.h:88
Definition: event_id.h:81
Definition: event_id.h:78
Definition: event_id.h:77
const ObjectURI & functionURI() const
Definition: event_id.cpp:68
Definition: GnashKey.h:45
Definition: event_id.h:65
bool operator==(const event_id &a, const event_id &b)
Return whether two event_ids are equal.
Definition: event_id.h:163
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:40
Definition: event_id.h:59
event_id(EventCode id, key::code c=key::INVALID)
Construct an event_id.
Definition: event_id.h:99
Definition: event_id.h:69
Definition: GnashKey.h:149
Definition: GnashKey.h:326
Definition: GnashKey.h:161
EventCode
The types of events that are handled by DisplayObjects.
Definition: event_id.h:57
Definition: event_id.h:63
A URI for describing as_objects.
Definition: ObjectURI.h:44
code
Definition: GnashKey.h:43
std::ostream & operator<<(std::ostream &o, const URL &u)
Definition: URL.cpp:447
Definition: event_id.h:82
Definition: event_id.h:76
Definition: event_id.h:73
const std::string & functionName() const
Definition: event_id.cpp:36
Definition: event_id.h:74
Definition: event_id.h:79
Definition: event_id.h:75
bool isKeyEvent(const event_id &e)
Check whether an event is a keyboard event.
Definition: event_id.cpp:104
void setKeyCode(std::uint8_t SWFkey)
Set the key associated with this event.
Definition: event_id.h:113
const unsigned char codeMap[KEYCOUNT][TYPES]
Definition: GnashKey.h:337
Definition: GnashKey.h:148
Definition: event_id.h:66
bool operator<(const event_id &a, const event_id &b)
Comparator for use in stdlib containers.
Definition: event_id.h:170
Definition: event_id.h:68
Definition: event_id.h:80
Definition: GnashKey.h:155
Definition: GnashKey.h:151
EventCode id() const
Return the identifier for this event type.
Definition: event_id.h:141
A class to identify &#39;static&#39; SWF events (system events).
Definition: event_id.h:52
Definition: event_id.h:67
Definition: event_id.h:72
Definition: event_id.h:64
Definition: GnashKey.h:331
Definition: event_id.h:62