summaryrefslogtreecommitdiffstats
path: root/kjsembed/builtins/stdaction_imp.cpp
blob: 7950161e3a223a264c5643616ef61abdb09e6151 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
 *  Copyright (C) 2003, Richard J. Moore <rich@kde.org>
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Library General Public
 *  License as published by the Free Software Foundation; either
 *  version 2 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Library General Public License for more details.
 *
 *  You should have received a copy of the GNU Library General Public License
 *  along with this library; see the file COPYING.LIB.  If not, write to
 *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 *  Boston, MA 02110-1301, USA.
 */

#include <tdeaction.h>
#include <kdebug.h>
#include <kstdaction.h>

#include <jsfactory.h>
#include <jsobjectproxy.h>

#include "stdaction_imp.h"

namespace KJSEmbed {
namespace BuiltIns {

StdActionImp::StdActionImp( KJS::ExecState *exec, JSFactory *fact, uint actid )
    : JSProxyImp(exec), id(actid), jsfact( fact )
{
}

StdActionImp::~StdActionImp()
{
}

static uint KSTDACTION_START = KStdAction::New;
static uint KSTDACTION_END = KStdAction::ConfigureNotifications+1;

const char *factoryMethodNames[] = {
    "START_MARKER",
    "fileNew", "open", "openRecent", "save", "saveAs", "revert", "close",
    "print", "printPreview", "mail", "quit",
    "undo", "redo", "cut", "copy", "paste", "selectAll", "deselect", "find", "findNext", "findPrev",
    "replace",
    "actualSize", "fitToPage", "fitToWidth", "fitToHeight", "zoomIn", "zoomOut",
    "zoom", "redisplay",
    "up", "back", "forward", "home", "prior", "next", "goGoto", "gotoPage", "gotoLine",
    "firstPage", "lastPage",
    "addBookmark", "editBookmarks",
    "spelling",
    "showMenubar", "showToolbar", "showStatusbar", "saveOptions", "keyBindings",
    "preferences", "configureToolbars",
    "help", "helpContents", "whatsThis", "reportBug", "aboutApp", "aboutKDE",
    "tipofDay",
    "configureNotifications",
    "END_MARKER"
};

void StdActionImp::addBindings( JSFactory *fact, KJS::ExecState *exec, KJS::Object &parent )
{
    for ( uint i = KSTDACTION_START; i < KSTDACTION_END; i++ ) {
	StdActionImp *sai = new StdActionImp( exec, fact, i );
	parent.put( exec, factoryMethodNames[i], KJS::Object( sai ) );
    }
}

KJS::Value StdActionImp::call( KJS::ExecState *exec, KJS::Object &/*self*/, const KJS::List &args )
{
    if ( ( args.size() < 3 ) || ( args.size() > 4 ) )
	return KJS::Null();

    // recv, slot, parent, name?
    TQObject *recv = extractTQObject( exec, args, 0);

    TQString sl = extractTQString( exec, args, 1 );
    const char *slc = sl.isNull() ? "" : sl.ascii();

    TQObject *parentobj = extractTQObject( exec, args, 2 );
    TDEActionCollection *parent = parentobj ? dynamic_cast<TDEActionCollection *>( parentobj ) : 0;

    KStdAction::StdAction actid = static_cast<KStdAction::StdAction>(id);
    const char *arg3 = (args.size() == 4) ? args[3].toString(exec).ascii() : KStdAction::name( actid );

    // Create the object
    TDEAction *act = KStdAction::create( actid, arg3, recv, slc, parent );
    return jsfact->createProxy( exec, act );
}

} // namespace KJSEmbed::BuiltIns
} // namespace KJSEmbed

// Local Variables:
// c-basic-offset: 4
// End: