fix typo, add instructions about lowercase named strings
[gnash.git] / libcore / event_id.cpp
blob471d66f321d34b88b0f3546c850785b694a7cd95
1 // event_id.cpp: static ActionScript events for Gnash.
2 //
3 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
4 // Foundation, Inc
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 3 of the License, or
9 // (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "log.h"
23 #include "event_id.h"
24 #include "namedStrings.h"
26 #include <map>
27 #include <string>
28 #include <algorithm>
29 #include <boost/format.hpp>
30 #include <cassert>
31 #include <boost/assign/list_of.hpp>
33 namespace gnash {
35 const std::string&
36 event_id::functionName() const
38 typedef std::map<EventCode, std::string> EventFunctionNameMap;
39 static const EventFunctionNameMap e = boost::assign::map_list_of
40 (INVALID, "INVALID")
41 (PRESS, "onPress")
42 (RELEASE, "onRelease")
43 (RELEASE_OUTSIDE, "onReleaseOutside")
44 (ROLL_OVER, "onRollOver")
45 (ROLL_OUT, "onRollOut")
46 (DRAG_OVER, "onDragOver")
47 (DRAG_OUT, "onDragOut")
48 (KEY_PRESS, "onKeyPress")
49 (INITIALIZE, "onInitialize")
50 (LOAD, "onLoad")
51 (UNLOAD, "onUnload")
52 (ENTER_FRAME, "onEnterFrame")
53 (MOUSE_DOWN, "onMouseDown")
54 (MOUSE_UP, "onMouseUp")
55 (MOUSE_MOVE, "onMouseMove")
56 (KEY_DOWN, "onKeyDown")
57 (KEY_UP, "onKeyUp")
58 (DATA, "onData")
59 (CONSTRUCT, "onConstruct");
61 EventFunctionNameMap::const_iterator it = e.find(_id);
62 assert(it != e.end());
63 return it->second;
66 string_table::key
67 event_id::functionKey() const
69 typedef std::map<EventCode, string_table::key> EventFunctionMap;
70 static const EventFunctionMap e = boost::assign::map_list_of
71 (PRESS, NSV::PROP_ON_PRESS)
72 (RELEASE, NSV::PROP_ON_RELEASE)
73 (RELEASE_OUTSIDE, NSV::PROP_ON_RELEASE_OUTSIDE)
74 (ROLL_OVER, NSV::PROP_ON_ROLL_OVER )
75 (ROLL_OUT, NSV::PROP_ON_ROLL_OUT)
76 (DRAG_OVER, NSV::PROP_ON_DRAG_OVER)
77 (DRAG_OUT, NSV::PROP_ON_DRAG_OUT)
78 (KEY_PRESS, NSV::PROP_ON_KEY_PRESS)
79 (INITIALIZE, NSV::PROP_ON_INITIALIZE)
80 (LOAD, NSV::PROP_ON_LOAD)
81 (UNLOAD, NSV::PROP_ON_UNLOAD)
82 (ENTER_FRAME, NSV::PROP_ON_ENTER_FRAME)
83 (MOUSE_DOWN, NSV::PROP_ON_MOUSE_DOWN)
84 (MOUSE_UP, NSV::PROP_ON_MOUSE_UP)
85 (MOUSE_MOVE, NSV::PROP_ON_MOUSE_MOVE)
86 (KEY_DOWN, NSV::PROP_ON_KEY_DOWN)
87 (KEY_UP, NSV::PROP_ON_KEY_UP)
88 (DATA, NSV::PROP_ON_DATA)
89 (CONSTRUCT, NSV::PROP_ON_CONSTRUCT);
91 EventFunctionMap::const_iterator it = e.find(_id);
92 assert(it != e.end());
93 return it->second;
96 bool
97 isKeyEvent(const event_id& e)
99 switch (e.id())
101 case event_id::KEY_DOWN:
102 case event_id::KEY_PRESS:
103 case event_id::KEY_UP:
104 return true;
105 default:
106 return false;
110 bool
111 isButtonEvent(const event_id& e)
113 switch (e.id())
115 case event_id::PRESS:
116 case event_id::RELEASE:
117 case event_id::RELEASE_OUTSIDE:
118 case event_id::ROLL_OVER:
119 case event_id::ROLL_OUT:
120 case event_id::DRAG_OVER:
121 case event_id::DRAG_OUT:
122 case event_id::KEY_PRESS:
123 return true;
124 default:
125 return false;
129 std::ostream& operator<< (std::ostream& o, const event_id& ev)
131 return (o << ev.functionName());
134 } // end of namespace gnash
136 // Local Variables:
137 // mode: C++
138 // indent-tabs-mode: t
139 // End: