Make automated FSCommand invocation tests show player-side output.
[gnash.git] / libcore / event_id.h
blob14d2bde4f3961deb8bea58fb3c4bb20f97fe7c2f
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
21 #ifndef GNASH_EVENT_ID_H
22 #define GNASH_EVENT_ID_H
24 #include <string>
25 #include "GnashKey.h"
27 // Forward declarations
28 namespace gnash {
29 struct ObjectURI;
32 namespace gnash {
35 /// A class to identify 'static' SWF events (system events).
37 /// The event process in a SWF comprises the raising of the event itself and
38 /// its receipt by a handler. Events may be either dynamically or statically
39 /// defined. A dynamic event is handled in ActionScript: an AS-defined
40 /// function is called when the event is raised. Dynamic events do not need
41 /// event_id.
43 /// Event handlers may also be defined statically, for instance in a
44 /// PlaceObject2 tag, or by default. System events such as mouse handling,
45 /// load milestones, or keyboard events should be sent to appropriate
46 /// DisplayObjects. This process uses event_id.
48 /// Static events may additionally be handled dynamically (using ActionScript).
50 /// The event_id class is used as an identifier for actual events and
51 /// and for the signature of an expected event.
52 class event_id
54 public:
56 /// The types of events that are handled by DisplayObjects.
57 enum EventCode
59 INVALID,
61 // These are for buttons and sprites.
62 PRESS,
63 RELEASE,
64 RELEASE_OUTSIDE,
65 ROLL_OVER,
66 ROLL_OUT,
67 DRAG_OVER,
68 DRAG_OUT,
69 KEY_PRESS,
71 // These are for sprites only.
72 INITIALIZE,
73 LOAD,
74 UNLOAD,
75 ENTER_FRAME,
76 MOUSE_DOWN,
77 MOUSE_UP,
78 MOUSE_MOVE,
79 KEY_DOWN,
80 KEY_UP,
81 DATA,
82 CONSTRUCT
85 /// Construct an invalid event_id.
87 /// This is not useful until its values have been set.
88 event_id()
90 _id(INVALID),
91 _keyCode(key::INVALID)
94 /// Construct an event_id.
96 /// @param id The type of event
97 /// @param c The key associated with an event (only if this
98 /// is a keyboard event).
99 explicit event_id(EventCode id, key::code c = key::INVALID)
101 _id(id),
102 _keyCode(c)
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)
109 /// Set the key associated with this event.
111 /// @param SWFKey The SWF code matched to the event. This
112 /// must be converted to a unique gnash::key::code.
113 void setKeyCode(std::uint8_t SWFkey)
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++;
123 if (i == key::KEYCOUNT) _keyCode = key::INVALID;
124 else _keyCode = static_cast<key::code>(i);
127 /// Return the name of a method-handler function
128 /// corresponding to this event.
129 const std::string& functionName() const;
131 /// Return the ObjectURI of a method-handler function
132 /// corresponding to this event.
133 const ObjectURI& functionURI() const;
135 /// Return the keycode associated with this event_id.
137 /// This should be key::INVALID if the event_id is not a keyboard event.
138 key::code keyCode() const { return _keyCode; }
140 /// Return the identifier for this event type.
141 EventCode id() const { return _id; }
143 private:
145 EventCode _id;
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;
157 /// Return whether two event_ids are equal
159 /// event_ids are equal if both id and keycode match. Keycode is only
160 /// relevant for keyboard events, and must be key::INVALID for other
161 /// event types.
162 inline bool
163 operator==(const event_id& a, const event_id& b)
165 return a.id() == b.id() && a.keyCode() == b.keyCode();
168 /// Comparator for use in stdlib containers.
169 inline bool
170 operator<(const event_id& a, const event_id& b)
172 if (a.id() == b.id()) return a.keyCode() < b.keyCode();
173 return a.id() < b.id();
177 /// Check whether an event is a button-like event.
179 /// @param e The event to check
180 /// @return True if it is
181 bool isButtonEvent(const event_id& e);
183 /// Check whether an event is a keyboard event.
185 /// @param e The event to check
186 /// @return True if it is
187 bool isKeyEvent(const event_id& e);
189 std::ostream& operator<< (std::ostream& o, const event_id& ev);
191 } // namespace gnash
194 #endif
197 // Local Variables:
198 // mode: C++
199 // indent-tabs-mode: t
200 // End: