1
// ContextMenu.cpp: ActionScript ContextMenu class, for Gnash.
3
// Copyright (C) 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
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
#include "gnashconfig.h"
24
#include "ContextMenu.h"
25
#include "as_object.h" // for inheritance
28
#include "smart_ptr.h" // for boost intrusive_ptr
29
#include "builtin_function.h" // need builtin_function
30
#include "GnashException.h"
31
#include "Object.h" // for getObjectInterface
32
#include "namedStrings.h"
33
#include "utility.h" // UNUSED
37
class ContextMenu: public as_object
44
as_object(getExportedInterface())
47
ContextMenu(const as_value& callback)
49
as_object(getExportedInterface())
51
setCallback(callback);
54
ContextMenu(as_function* callback)
56
as_object(getExportedInterface())
58
setCallback(callback);
61
static void registerConstructor(as_object& global);
63
// override from as_object ?
64
//std::string get_text_value() const { return "ContextMenu"; }
66
// override from as_object ?
67
//double get_numeric_value() const { return 0; }
71
/// Get the callback to call when user invokes the context menu.
73
/// If NULL, no action will be taken on select.
75
as_function* getCallback()
78
if (get_member(NSV::PROP_ON_SELECT, &tmp))
79
return tmp.to_as_function();
83
/// Set the callback to call when user invokes the context menu.
86
/// The function to call. If the value is not a function, no
87
/// action will be taken on select.
89
void setCallback(const as_value& callback)
91
set_member(NSV::PROP_ON_SELECT, callback);
94
/// Attach the exported interface of this ActionScript class
95
/// to the given object.
96
static void attachExportedInterface(as_object& o);
98
/// Get the ContextMenu.prototype ActionScript object
99
static as_object* getExportedInterface();
101
static as_value ctor_method(const fn_call& fn);
103
static as_value hideBuiltInItems_method(const fn_call& fn);
105
static as_value copy_method(const fn_call& fn);
110
ContextMenu::attachExportedInterface(as_object& o)
112
o.init_member("copy", new builtin_function(ContextMenu::copy_method));
113
o.init_member("hideBuiltInItems", new builtin_function(ContextMenu::hideBuiltInItems_method));
118
ContextMenu::getExportedInterface()
120
static boost::intrusive_ptr<as_object> o;
123
o = new as_object(getObjectInterface());
124
attachExportedInterface(*o);
132
ContextMenu::copy_method(const fn_call& fn)
134
boost::intrusive_ptr<ContextMenu> ptr = ensureType<ContextMenu>(fn.this_ptr);
136
log_unimpl (__FUNCTION__);
142
ContextMenu::hideBuiltInItems_method(const fn_call& fn)
144
boost::intrusive_ptr<ContextMenu> ptr = ensureType<ContextMenu>(fn.this_ptr);
146
log_unimpl (__FUNCTION__);
152
ContextMenu::ctor_method(const fn_call& fn)
154
boost::intrusive_ptr<as_object> obj;
156
obj = new ContextMenu(fn.arg(0));
158
obj = new ContextMenu();
160
return as_value(obj.get()); // will keep alive
165
ContextMenu::registerConstructor(as_object& global)
167
// This is going to be the global ContextMenu "class"/"function"
168
static boost::intrusive_ptr<builtin_function> cl;
172
cl=new builtin_function(ContextMenu::ctor_method, ContextMenu::getExportedInterface());
173
// replicate all interface to class, to be able to access
174
// all methods as static functions
175
ContextMenu::attachExportedInterface(*cl);
179
// Register _global.ContextMenu
180
global.init_member("ContextMenu", cl.get());
184
// extern (used by Global.cpp)
185
void contextmenu_class_init(as_object& global)
187
ContextMenu::registerConstructor(global);
191
} // end of gnash namespace