~ubuntu-branches/ubuntu/saucy/gnash/saucy-proposed

« back to all changes in this revision

Viewing changes to libcore/asobj/ContextMenu.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alexander Sack
  • Date: 2008-10-13 14:29:49 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20081013142949-f6qdvnu4mn05ltdc
Tags: 0.8.4~~bzr9980-0ubuntu1
* new upstream release 0.8.4 (LP: #240325)
* ship new lib usr/lib/gnash/libmozsdk.so.* in mozilla-plugin-gnash
  - update debian/mozilla-plugin-gnash.install
* ship new lib usr/lib/gnash/libgnashnet.so.* in gnash-common
  - update debian/gnash-common.install
* add basic debian/build_head script to build latest CVS head packages.
  - add debian/build_head
* new sound architecture requires build depend on libsdl1.2-dev
  - update debian/control
* head build script now has been completely migrated to bzr (upstream +
  ubuntu)
  - update debian/build_head
* disable kde gui until klash/qt4 has been fixed; keep kde packages as empty
  packages for now.
  - update debian/rules
  - debian/klash.install
  - debian/klash.links
  - debian/klash.manpages
  - debian/konqueror-plugin-gnash.install
* drop libkonq5-dev build dependency accordingly
  - update debian/control
* don't install headers manually anymore. gnash doesnt provide a -dev
  package after all
  - update debian/rules
* update libs installed in gnash-common; libgnashserver-*.so is not available
  anymore (removed); in turn we add the new libgnashcore-*.so
  - update debian/gnash-common.install
* use -Os for optimization and properly pass CXXFLAGS=$(CFLAGS) to configure
  - update debian/rules
* touch firefox .autoreg in postinst of mozilla plugin
  - update debian/mozilla-plugin-gnash.postinst
* link gnash in ubufox plugins directory for the plugin alternative switcher
  - add debian/mozilla-plugin-gnash.links
* suggest ubufox accordingly
  - update debian/control
* add new required build-depends on libgif-dev
  - update debian/control
* add Xb-Npp-Description and Xb-Npp-File as new plugin database meta data
  - update debian/control

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// ContextMenu.cpp:  ActionScript ContextMenu class, for Gnash.
 
2
// 
 
3
//   Copyright (C) 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
 
4
//
 
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.
 
9
//
 
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.
 
14
//
 
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
 
18
//
 
19
 
 
20
#ifdef HAVE_CONFIG_H
 
21
#include "gnashconfig.h"
 
22
#endif
 
23
 
 
24
#include "ContextMenu.h"
 
25
#include "as_object.h" // for inheritance
 
26
#include "log.h"
 
27
#include "fn_call.h"
 
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
 
34
 
 
35
namespace gnash {
 
36
 
 
37
class ContextMenu: public as_object
 
38
{
 
39
 
 
40
public:
 
41
 
 
42
        ContextMenu()
 
43
                :
 
44
                as_object(getExportedInterface())
 
45
        {}
 
46
 
 
47
        ContextMenu(const as_value& callback)
 
48
                :
 
49
                as_object(getExportedInterface())
 
50
        {
 
51
                setCallback(callback);
 
52
        }
 
53
 
 
54
        ContextMenu(as_function* callback)
 
55
                :
 
56
                as_object(getExportedInterface())
 
57
        {
 
58
                setCallback(callback);
 
59
        }
 
60
 
 
61
        static void registerConstructor(as_object& global);
 
62
 
 
63
        // override from as_object ?
 
64
        //std::string get_text_value() const { return "ContextMenu"; }
 
65
 
 
66
        // override from as_object ?
 
67
        //double get_numeric_value() const { return 0; }
 
68
 
 
69
private:
 
70
 
 
71
        /// Get the callback to call when user invokes the context menu.
 
72
        //
 
73
        /// If NULL, no action will be taken on select.
 
74
        ///
 
75
        as_function* getCallback() 
 
76
        {
 
77
                as_value tmp;
 
78
                if (get_member(NSV::PROP_ON_SELECT, &tmp))
 
79
                        return tmp.to_as_function();
 
80
                else return NULL;
 
81
        }
 
82
 
 
83
        /// Set the callback to call when user invokes the context menu.
 
84
        //
 
85
        /// @param callback
 
86
        ///     The function to call. If the value is not a function, no
 
87
        ///     action will be taken on select.
 
88
        ///
 
89
        void setCallback(const as_value& callback)
 
90
        {
 
91
                set_member(NSV::PROP_ON_SELECT, callback);
 
92
        }
 
93
 
 
94
        /// Attach the exported interface of this ActionScript class
 
95
        /// to the given object.
 
96
        static void attachExportedInterface(as_object& o);
 
97
 
 
98
        /// Get the ContextMenu.prototype ActionScript object
 
99
        static as_object* getExportedInterface();
 
100
 
 
101
        static as_value ctor_method(const fn_call& fn);
 
102
 
 
103
        static as_value hideBuiltInItems_method(const fn_call& fn);
 
104
 
 
105
        static as_value copy_method(const fn_call& fn);
 
106
};
 
107
 
 
108
/* static private */
 
109
void
 
110
ContextMenu::attachExportedInterface(as_object& o)
 
111
{
 
112
        o.init_member("copy", new builtin_function(ContextMenu::copy_method));
 
113
        o.init_member("hideBuiltInItems", new builtin_function(ContextMenu::hideBuiltInItems_method));
 
114
}
 
115
 
 
116
/* static private */
 
117
as_object*
 
118
ContextMenu::getExportedInterface()
 
119
{
 
120
        static boost::intrusive_ptr<as_object> o;
 
121
        if ( ! o )
 
122
        {
 
123
                o = new as_object(getObjectInterface());
 
124
                attachExportedInterface(*o);
 
125
        }
 
126
        return o.get();
 
127
}
 
128
 
 
129
 
 
130
/* static private */
 
131
as_value
 
132
ContextMenu::copy_method(const fn_call& fn)
 
133
{
 
134
        boost::intrusive_ptr<ContextMenu> ptr = ensureType<ContextMenu>(fn.this_ptr);
 
135
        UNUSED(ptr);
 
136
        log_unimpl (__FUNCTION__);
 
137
        return as_value();
 
138
}
 
139
 
 
140
/* static private */
 
141
as_value
 
142
ContextMenu::hideBuiltInItems_method(const fn_call& fn)
 
143
{
 
144
        boost::intrusive_ptr<ContextMenu> ptr = ensureType<ContextMenu>(fn.this_ptr);
 
145
        UNUSED(ptr);
 
146
        log_unimpl (__FUNCTION__);
 
147
        return as_value();
 
148
}
 
149
 
 
150
/* static private */
 
151
as_value
 
152
ContextMenu::ctor_method(const fn_call& fn)
 
153
{
 
154
        boost::intrusive_ptr<as_object> obj;
 
155
        if ( fn.nargs > 0 )
 
156
                obj = new ContextMenu(fn.arg(0));
 
157
        else
 
158
                obj = new ContextMenu();
 
159
        
 
160
        return as_value(obj.get()); // will keep alive
 
161
}
 
162
 
 
163
/* static public */
 
164
void
 
165
ContextMenu::registerConstructor(as_object& global)
 
166
{
 
167
        // This is going to be the global ContextMenu "class"/"function"
 
168
        static boost::intrusive_ptr<builtin_function> cl;
 
169
 
 
170
        if ( cl == NULL )
 
171
        {
 
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);
 
176
                     
 
177
        }
 
178
 
 
179
        // Register _global.ContextMenu
 
180
        global.init_member("ContextMenu", cl.get());
 
181
 
 
182
}
 
183
 
 
184
// extern (used by Global.cpp)
 
185
void contextmenu_class_init(as_object& global)
 
186
{
 
187
        ContextMenu::registerConstructor(global);
 
188
}
 
189
 
 
190
 
 
191
} // end of gnash namespace