• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • Examples
  • File List
  • File Members

event_id.h

Go to the documentation of this file.
00001 // 
00002 //   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
00003 //   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 "string_table.h"
00026 #include "GnashKey.h"
00027 
00028 namespace gnash {
00029 
00030 
00032 //
00038 //
00043 //
00045 //
00048 class event_id
00049 {
00050 public:
00051 
00053     enum EventCode
00054     {
00055         INVALID,
00056 
00057         // These are for buttons and sprites.
00058         PRESS,
00059         RELEASE,
00060         RELEASE_OUTSIDE,
00061         ROLL_OVER,
00062         ROLL_OUT,
00063         DRAG_OVER,
00064         DRAG_OUT,
00065         KEY_PRESS,
00066 
00067         // These are for sprites only.
00068         INITIALIZE,
00069         LOAD,
00070         UNLOAD,
00071         ENTER_FRAME,
00072         MOUSE_DOWN,
00073         MOUSE_UP,
00074         MOUSE_MOVE,
00075         KEY_DOWN,
00076         KEY_UP,
00077         DATA,
00078         CONSTRUCT
00079     };
00080     
00082     //
00084     event_id()
00085         :
00086         _id(INVALID),
00087         _keyCode(key::INVALID)
00088     {}
00089 
00091     //
00095     event_id(EventCode id, key::code c = key::INVALID)
00096         :
00097         _id(id),
00098         _keyCode(c)
00099     {
00100         // We do have a testcase with _id == KEY_PRESS,
00101         // and keyCode==0(KEY_INVALID)
00102         // see key_event_test.swf(produced by Ming)
00103     }
00104 
00106     //
00109     void setKeyCode(boost::uint8_t SWFkey)
00110     {
00111         // Lookup the SWFcode in the gnash::key::code table.
00112         // Some are not unique (keypad numbers are the
00113         // same as normal numbers), so we take the first match.
00114         // As long as we can work out the SWFCode from the
00115         // gnash::key::code it's all right.
00116         int i = 0;
00117         while (key::codeMap[i][key::SWF] != SWFkey && i < key::KEYCOUNT) i++;
00118 
00119         if (i == key::KEYCOUNT) _keyCode = key::INVALID;
00120         else _keyCode = static_cast<key::code>(i);
00121     }
00122 
00124     //
00128     bool operator==(const event_id& id) const {
00129         return _id == id._id && _keyCode == id._keyCode;
00130     }
00131 
00133     bool operator< (const event_id& id) const {
00134         if ( _id < id._id ) return true;
00135         if ( _id > id._id ) return false;
00136 
00137         // Same event, check key code
00138         if (_keyCode < id._keyCode ) return true;
00139         return false;
00140     }
00141 
00144     const std::string& functionName() const;
00145 
00148     string_table::key functionKey() const;
00149     
00151     //
00153     key::code keyCode() const { return _keyCode; }
00154 
00156     EventCode id() const { return _id; }
00157 
00158 private:
00159 
00160     EventCode _id;
00161     
00162     // keyCode must be the unique gnash key identifier
00163     // gnash::key::code.
00164     // TextField has to be able to work out the
00165     // ASCII value from keyCode, while other users need 
00166     // the SWF code or the Flash key code.
00167     key::code _keyCode;
00168 
00169 
00170 };
00171 
00172 
00174 //
00177 bool isButtonEvent(const event_id& e);
00178 
00180 //
00183 bool isKeyEvent(const event_id& e);
00184 
00185 std::ostream& operator<< (std::ostream& o, const event_id& ev);
00186 
00187 } // namespace gnash
00188 
00189 
00190 #endif 
00191 
00192 
00193 // Local Variables:
00194 // mode: C++
00195 // indent-tabs-mode: t
00196 // End:

Generated on Fri Mar 16 2012 15:46:09 for Gnash by  doxygen 1.7.1