2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
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.
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.
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
27 // Forward declarations
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
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.
56 /// The types of events that are handled by DisplayObjects.
61 // These are for buttons and sprites.
71 // These are for sprites only.
85 /// Construct an invalid event_id.
87 /// This is not useful until its values have been set.
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
)
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(boost::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.
121 while (key::codeMap
[i
][key::SWF
] != SWFkey
&& i
< key::KEYCOUNT
) 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
; }
147 // keyCode must be the unique gnash key identifier
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.
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
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.
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
);
199 // indent-tabs-mode: t