Gnash  0.8.10
event_id.h
Go to the documentation of this file.
00001 // 
00002 //   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
00003 //   Free Software Foundation, Inc
00004 // 
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation; either version 3 of the License, or
00008 // (at your option) any later version.
00009 // 
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 // 
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018 //
00019 
00020 
00021 #ifndef GNASH_EVENT_ID_H
00022 #define GNASH_EVENT_ID_H
00023 
00024 #include <string>
00025 #include "GnashKey.h"
00026 
00027 // Forward declarations
00028 namespace gnash {
00029     struct ObjectURI;
00030 }
00031 
00032 namespace gnash {
00033 
00034 
00036 //
00042 //
00047 //
00049 //
00052 class event_id
00053 {
00054 public:
00055 
00057     enum EventCode
00058     {
00059         INVALID,
00060 
00061         // These are for buttons and sprites.
00062         PRESS,
00063         RELEASE,
00064         RELEASE_OUTSIDE,
00065         ROLL_OVER,
00066         ROLL_OUT,
00067         DRAG_OVER,
00068         DRAG_OUT,
00069         KEY_PRESS,
00070 
00071         // These are for sprites only.
00072         INITIALIZE,
00073         LOAD,
00074         UNLOAD,
00075         ENTER_FRAME,
00076         MOUSE_DOWN,
00077         MOUSE_UP,
00078         MOUSE_MOVE,
00079         KEY_DOWN,
00080         KEY_UP,
00081         DATA,
00082         CONSTRUCT
00083     };
00084     
00086     //
00088     event_id()
00089         :
00090         _id(INVALID),
00091         _keyCode(key::INVALID)
00092     {}
00093 
00095     //
00099     explicit event_id(EventCode id, key::code c = key::INVALID)
00100         :
00101         _id(id),
00102         _keyCode(c)
00103     {
00104         // We do have a testcase with _id == KEY_PRESS,
00105         // and keyCode==0(KEY_INVALID)
00106         // see key_event_test.swf(produced by Ming)
00107     }
00108 
00110     //
00113     void setKeyCode(boost::uint8_t SWFkey)
00114     {
00115         // Lookup the SWFcode in the gnash::key::code table.
00116         // Some are not unique (keypad numbers are the
00117         // same as normal numbers), so we take the first match.
00118         // As long as we can work out the SWFCode from the
00119         // gnash::key::code it's all right.
00120         int i = 0;
00121         while (key::codeMap[i][key::SWF] != SWFkey && i < key::KEYCOUNT) i++;
00122 
00123         if (i == key::KEYCOUNT) _keyCode = key::INVALID;
00124         else _keyCode = static_cast<key::code>(i);
00125     }
00126 
00129     const std::string& functionName() const;
00130 
00133     const ObjectURI& functionURI() const;
00134     
00136     //
00138     key::code keyCode() const { return _keyCode; }
00139 
00141     EventCode id() const { return _id; }
00142 
00143 private:
00144 
00145     EventCode _id;
00146     
00147     // keyCode must be the unique gnash key identifier
00148     // gnash::key::code.
00149     // TextField has to be able to work out the
00150     // ASCII value from keyCode, while other users need 
00151     // the SWF code or the Flash key code.
00152     key::code _keyCode;
00153 
00154 
00155 };
00156 
00158 //
00162 inline bool
00163 operator==(const event_id& a, const event_id& b)
00164 {
00165     return a.id() == b.id() && a.keyCode() == b.keyCode();
00166 }
00167 
00169 inline bool
00170 operator<(const event_id& a, const event_id& b)
00171 {
00172     if (a.id() == b.id()) return a.keyCode() < b.keyCode();
00173     return a.id() < b.id();
00174 }
00175 
00176 
00178 //
00181 bool isButtonEvent(const event_id& e);
00182 
00184 //
00187 bool isKeyEvent(const event_id& e);
00188 
00189 std::ostream& operator<< (std::ostream& o, const event_id& ev);
00190 
00191 } // namespace gnash
00192 
00193 
00194 #endif 
00195 
00196 
00197 // Local Variables:
00198 // mode: C++
00199 // indent-tabs-mode: t
00200 // End: