~ubuntu-branches/ubuntu/maverick/gnash/maverick

« back to all changes in this revision

Viewing changes to libcore/asobj/flash/ui/ContextMenuItem_as.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Sindhudweep Narayan Sarkar
  • Date: 2009-10-07 00:06:10 UTC
  • mfrom: (1.1.12 upstream)
  • Revision ID: james.westby@ubuntu.com-20091007000610-mj9rwqe774gizn1j
Tags: 0.8.6-0ubuntu1
new upstream release 0.8.6 (LP: #435897)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// as_object.cpp:  ActionScript "ContextMenuItem" class, for Gnash.
 
2
//
 
3
//   Copyright (C) 2009 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 "ui/ContextMenuItem_as.h"
 
25
#include "log.h"
 
26
#include "fn_call.h"
 
27
#include "Global_as.h"
 
28
#include "smart_ptr.h" // for boost intrusive_ptr
 
29
#include "builtin_function.h" // need builtin_function
 
30
#include "Object.h" 
 
31
 
 
32
namespace gnash {
 
33
 
 
34
// Forward declarations
 
35
namespace {
 
36
    as_value contextmenuitem_ctor(const fn_call& fn);
 
37
    as_value contextmenuitem_copy(const fn_call& fn);
 
38
    void attachContextMenuItemInterface(as_object& o);
 
39
 
 
40
}
 
41
 
 
42
// extern (used by Global.cpp)
 
43
void
 
44
contextmenuitem_class_init(as_object& where, const ObjectURI& uri)
 
45
{
 
46
    registerBuiltinClass(where, contextmenuitem_ctor,
 
47
            attachContextMenuItemInterface, 0, uri);
 
48
}
 
49
 
 
50
namespace {
 
51
 
 
52
void
 
53
attachContextMenuItemInterface(as_object& o)
 
54
{
 
55
    const int flags = PropFlags::dontEnum |
 
56
                      PropFlags::dontDelete |
 
57
                      PropFlags::onlySWF7Up;
 
58
 
 
59
    Global_as* gl = getGlobal(o);
 
60
    o.init_member("copy", gl->createFunction(contextmenuitem_copy), flags);
 
61
}
 
62
 
 
63
as_value
 
64
contextmenuitem_copy(const fn_call& fn)
 
65
{
 
66
    boost::intrusive_ptr<as_object> ptr = ensureType<as_object>(fn.this_ptr);
 
67
 
 
68
    Global_as* gl = getGlobal(fn);
 
69
    string_table& st = getStringTable(fn);
 
70
 
 
71
    as_function* ctor =
 
72
        gl->getMember(st.find("ContextMenuItem")).to_as_function();
 
73
 
 
74
    if (!ctor) return as_value();
 
75
 
 
76
    fn_call::Args args;
 
77
    args += ptr->getMember(st.find("caption")),
 
78
        ptr->getMember(NSV::PROP_ON_SELECT),
 
79
        ptr->getMember(st.find("separatorBefore")),
 
80
        ptr->getMember(NSV::PROP_ENABLED),
 
81
        ptr->getMember(st.find("visible"));
 
82
 
 
83
    return ctor->constructInstance(fn.env(), args);
 
84
}
 
85
 
 
86
 
 
87
as_value
 
88
contextmenuitem_ctor(const fn_call& fn)
 
89
{
 
90
    as_object* obj = fn.this_ptr;
 
91
 
 
92
    string_table& st = getStringTable(fn);
 
93
 
 
94
    obj->set_member(st.find("caption"), fn.nargs ? fn.arg(0) : as_value());
 
95
    obj->set_member(NSV::PROP_ON_SELECT, fn.nargs > 1 ? fn.arg(1) : as_value());
 
96
    obj->set_member(st.find("separatorBefore"), fn.nargs > 2 ?
 
97
            fn.arg(2) : false);
 
98
    obj->set_member(NSV::PROP_ENABLED, fn.nargs > 3 ? fn.arg(3) : true);
 
99
    obj->set_member(st.find("visible"), fn.nargs > 4 ? fn.arg(4) : true);
 
100
 
 
101
    return as_value(); 
 
102
}
 
103
 
 
104
} // anonymous namespace 
 
105
} // gnash namespace
 
106
 
 
107
// local Variables:
 
108
// mode: C++
 
109
// indent-tabs-mode: t
 
110
// End:
 
111