update copyright date
[gnash.git] / libcore / asobj / Mouse_as.cpp
blob406b8f69a925faf04416a31cc0b0955bebed7db7
1 // Mouse.cpp: ActionScript "Mouse" input device class, for Gnash.
2 //
3 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010,
4 // 2011 Free Software 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
21 #include "namedStrings.h"
22 #include "Mouse_as.h"
23 #include "as_object.h" // for inheritance
24 #include "log.h"
25 #include "fn_call.h"
26 #include "Global_as.h"
27 #include "smart_ptr.h" // for boost intrusive_ptr
28 #include "NativeFunction.h"
29 #include "VM.h" // for registerNative
30 #include "AsBroadcaster.h" // for initializing self as a broadcaster
31 #include "movie_root.h" // for GUI callback
33 namespace gnash {
35 // Forward declarations
36 namespace {
37 as_value mouse_hide(const fn_call& fn);
38 as_value mouse_show(const fn_call& fn);
40 void attachMouseInterface(as_object& o);
43 /// Mouse isn't a proper class in AS
45 /// Gnash's Mouse_as just has static methods.
46 void
47 Mouse_as::registerNative(as_object& o)
49 VM& vm = getVM(o);
51 vm.registerNative(mouse_show, 5, 0);
52 vm.registerNative(mouse_hide, 5, 1);
56 // extern (used by Global.cpp)
57 void
58 mouse_class_init(as_object& where, const ObjectURI& uri)
60 registerBuiltinObject(where, attachMouseInterface, uri);
64 namespace {
66 void
67 attachMouseInterface(as_object& o)
69 VM& vm = getVM(o);
71 const int flags = PropFlags::dontEnum |
72 PropFlags::dontDelete |
73 PropFlags::readOnly;
75 o.init_member("show", vm.getNative(5, 0), flags);
76 o.init_member("hide", vm.getNative(5, 1), flags);
78 // Mouse is always initialized as an AsBroadcaster, even for
79 // SWF5.
80 AsBroadcaster::initialize(o);
82 Global_as& gl = getGlobal(o);
83 as_object* null = 0;
84 callMethod(&gl, NSV::PROP_AS_SET_PROP_FLAGS, &o, null, 7);
87 /// Returns whether the mouse was visible before the call.
89 /// The return is not a boolean, but rather 1 or 0.
90 as_value
91 mouse_hide(const fn_call& fn)
93 movie_root& m = getRoot(fn);
94 const int success =
95 m.callInterface<bool>(HostMessage(HostMessage::SHOW_MOUSE, false));
97 // returns 1 if mouse was visible before call.
98 return as_value(success);
101 /// Returns whether the mouse was visible before the call.
103 /// The return is not a boolean, but rather 1 or 0.
104 as_value
105 mouse_show(const fn_call& fn)
107 movie_root& m = getRoot(fn);
108 const int success =
109 m.callInterface<bool>(HostMessage(HostMessage::SHOW_MOUSE, true));
111 // returns 1 if Mouse was visible before call.
112 return as_value(success);
115 } // anonymous namespace
116 } // end of gnash namespace