summaryrefslogtreecommitdiffstats
path: root/kjsembed/slotproxy.cpp
blob: dc5d7c2ba75c6c2bfecad80d54aa8d5f4e80ebab (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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
/*
 *  Copyright (C) 2003-2004, 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 <kjs/interpreter.h>

#ifndef QT_ONLY
#include <kurl.h>
#else
#include "qtstubs.h"
#endif // QT_ONLY

#include "jsopaqueproxy.h"
#include "global.h"
#include "jsbinding.h"
#include "jsfactory.h"
#include "jsobjectproxy.h"
#include "slotproxy.h"

#include "kjsembedpart.h"

#ifndef QT_ONLY
#include "slotproxy.moc"
#endif // QT_ONLY

namespace KJSEmbed {

JSSlotProxy::JSSlotProxy( TQObject *parent, const char *name )
    : TQObject( parent, name ? name : "slot_proxy" ),
      proxy(0), js(0)
{
}

JSSlotProxy::JSSlotProxy( TQObject *parent, const char *name, JSObjectProxy *prx )
    : TQObject( parent, name ? name : "slot_proxy" ),
      proxy(prx), js( prx ? prx->interpreter() : 0 )
{
}

JSSlotProxy::~JSSlotProxy()
{
}

void JSSlotProxy::slot_void()
{
    execute( KJS::List() );
}

void JSSlotProxy::slot_bool( bool b )
{
    KJS::List args;
    args.append( KJS::Boolean(b) );
    execute( args );
}

void JSSlotProxy::slot_string( const TQString &s )
{
    KJS::List args;
    args.append( KJS::String(s) );
    execute( args );
}

void JSSlotProxy::slot_int( int i )
{
    KJS::List args;
    args.append( KJS::Number(i) );
    execute( args );
}

void JSSlotProxy::slot_uint( uint i )
{
    KJS::List args;
    args.append( KJS::Number(i) );
    execute( args );
}

void JSSlotProxy::slot_long( long i )
{
    KJS::List args;
    args.append( KJS::Number(i) );
    execute( args );
}

void JSSlotProxy::slot_ulong( ulong i )
{
    KJS::List args;
    args.append( KJS::Number(i) );
    execute( args );
}

void JSSlotProxy::slot_double( double d )
{
    KJS::List args;
    args.append( KJS::Number(d) );
    execute( args );
}

void JSSlotProxy::slot_color( const TQColor &color )
{
    KJS::List args;
    args.append( convertToValue(js->globalExec(), color) );
    execute( args );
}

void JSSlotProxy::slot_font( const TQFont &font )
{
    KJS::List args;
    args.append( convertToValue(js->globalExec(), font) );
    execute( args );
}
}// namespace KJSEmbed


void KJSEmbed::JSSlotProxy::slot_point( const TQPoint & point )
{
    KJS::List args;
    args.append( convertToValue(js->globalExec(), point) );
    execute( args );
}

void KJSEmbed::JSSlotProxy::slot_rect( const TQRect & rec )
{
    KJS::List args;
    args.append( convertToValue(js->globalExec(), rec) );
    execute( args );
}

void KJSEmbed::JSSlotProxy::slot_size( const TQSize & size )
{
    KJS::List args;
    args.append( convertToValue(js->globalExec(), size) );
    execute( args );
}

void KJSEmbed::JSSlotProxy::slot_pixmap( const TQPixmap & pix )
{
    KJS::List args;
    args.append( convertToValue(js->globalExec(), TQVariant( pix ) ) );
    execute( args );
}

void KJSEmbed::JSSlotProxy::slot_url( const KURL & url )
{
    KJS::List args;
#ifndef QT_ONLY
    args.append( convertToValue(js->globalExec(), url.prettyURL() ));
#else // QT_ONLY
    args.append( convertToValue(js->globalExec(), url.toString() ));
#endif // QT_ONLY
    execute( args );
}

void KJSEmbed::JSSlotProxy::slot_intint( int arg, int arg1)
{
    KJS::List args;
    args.append( convertToValue(js->globalExec(), arg ));
    args.append( convertToValue(js->globalExec(), arg1 ));
    execute( args );
}
void KJSEmbed::JSSlotProxy::slot_intbool( int arg, bool arg1)
{
    KJS::List args;
    args.append( convertToValue(js->globalExec(), arg ));
    args.append( convertToValue(js->globalExec(), arg1 ));
    execute( args );
}

void KJSEmbed::JSSlotProxy::slot_intintint( int arg, int arg1, int arg2)
{
    KJS::List args;
    args.append( convertToValue(js->globalExec(), arg ));
    args.append( convertToValue(js->globalExec(), arg1 ));
    args.append( convertToValue(js->globalExec(), arg2 ));
    execute( args );
}

void KJSEmbed::JSSlotProxy::execute( const KJS::List &args )
{
    KJS::ExecState *exec = js->globalExec();
    KJS::Value val = obj.get( exec, KJS::Identifier(KJS::UString(method)) );
    KJS::Object fun = val.toObject( exec );

    if ( !fun.implementsCall() ) {
	kdDebug(80001) << "Target does not support call, class "
		       << fun.toString(exec).qstring() << " method " << method << endl;
	return;
    }

    fun.call( exec, obj, args );

    if ( exec->hadException() ) {
	kdWarning( 80001 ) << "Exception in slot function '" << method << "', "
			   << exec->exception().toString(exec).qstring() << endl;

	exec->clearException();
    }
}

void KJSEmbed::JSSlotProxy::slot_widget( TQWidget * widget )
{
    KJS::List args;
    if ( widget )
	args.append( proxy->part()->factory()->createProxy( js->globalExec(), widget ) );
    else
	args.append( KJS::Null() );

    execute( args );
}

void KJSEmbed::JSSlotProxy::slot_datetime( const TQDateTime & dateTime )
{
    KJS::List args;
    args.append( convertToValue(js->globalExec(), TQVariant( dateTime ) ));
    execute( args );
}

void KJSEmbed::JSSlotProxy::slot_datedate( const TQDate & date1, const TQDate & date2 )
{
    KJS::List args;
    args.append( convertToValue(js->globalExec(), TQVariant( date1 ) ));
    args.append( convertToValue(js->globalExec(), TQVariant( date2 ) ));
    execute( args );
}

void KJSEmbed::JSSlotProxy::slot_colorstring( const TQColor & color, const TQString & string )
{
    KJS::List args;
    args.append( convertToValue(js->globalExec(), color ));
    args.append( convertToValue(js->globalExec(), string ));
    execute( args );
}

void KJSEmbed::JSSlotProxy::slot_image( const TQImage & image )
{
    KJS::List args;
    args.append( convertToValue(js->globalExec(), TQVariant( image ) ));
    execute( args );
}

void KJSEmbed::JSSlotProxy::slot_date( const TQDate & date )
{
    KJS::List args;
    args.append( convertToValue(js->globalExec(), TQVariant( date ) ));
    execute( args );
}

void KJSEmbed::JSSlotProxy::slot_time( const TQTime &time )
{
    KJS::List args;
    args.append( convertToValue(js->globalExec(), TQVariant( time ) ));
    execute( args );
}

void KJSEmbed::JSSlotProxy::slot_variant( const TQVariant & variant )
{
    KJS::List args;
    args.append( convertToValue(js->globalExec(), variant ) );
    execute( args );
}