|
|
|
/*
|
|
|
|
* Copyright (C) 2001-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 <tqobject.h>
|
|
|
|
#include <tqobjectlist.h>
|
|
|
|
#include <tqdialog.h>
|
|
|
|
#include <tqlistbox.h>
|
|
|
|
#include <tqlistview.h>
|
|
|
|
#include <tqmetaobject.h>
|
|
|
|
#include <tqregexp.h>
|
|
|
|
#include <tqsignal.h>
|
|
|
|
#include <tqstrlist.h>
|
|
|
|
#include <tqtimer.h>
|
|
|
|
#include <tqvariant.h>
|
|
|
|
#include <tqdatetime.h>
|
|
|
|
#include <tqstringlist.h>
|
|
|
|
|
|
|
|
#include <private/qucom_p.h>
|
|
|
|
#include <private/qucomextra_p.h>
|
|
|
|
|
|
|
|
#ifndef QT_ONLY
|
|
|
|
#include <klistview.h>
|
|
|
|
#include <kurl.h>
|
|
|
|
#else // QT_ONLY
|
|
|
|
#include "qtstubs.h"
|
|
|
|
#endif // QT_ONLY
|
|
|
|
|
|
|
|
#include <kjs/interpreter.h>
|
|
|
|
#include <kjs/types.h>
|
|
|
|
#include <kjs/ustring.h>
|
|
|
|
|
|
|
|
#include "kjsembedpart.h"
|
|
|
|
#include "jssecuritypolicy.h"
|
|
|
|
|
|
|
|
#include "global.h"
|
|
|
|
#include "jsfactory.h"
|
|
|
|
#include "slotproxy.h"
|
|
|
|
#include "jsvalueproxy.h"
|
|
|
|
#include "jsopaqueproxy.h"
|
|
|
|
|
|
|
|
#include "jsobjectproxy_imp.h"
|
|
|
|
|
|
|
|
#include "slotutils.h"
|
|
|
|
|
|
|
|
namespace KJSEmbed {
|
|
|
|
namespace Bindings {
|
|
|
|
|
|
|
|
JSSlotUtils::JSSlotUtils()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
JSSlotUtils::~JSSlotUtils()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool JSSlotUtils::connect( TTQObject *sender, const char *sig, TTQObject *recv, const char *dest )
|
|
|
|
{
|
|
|
|
if ( (!sender) || (!recv) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Source
|
|
|
|
TTQString si = TTQString("2%1").arg(sig);
|
|
|
|
const char *sigc = si.ascii();
|
|
|
|
|
|
|
|
// Connect to slot
|
|
|
|
if ( recv->metaObject()->findSlot(dest, true) >= 0 ) {
|
|
|
|
TTQString sl = TTQString("1%1").arg(dest);
|
|
|
|
const char *slotc = sl.ascii();
|
|
|
|
|
|
|
|
//kdDebug(80001) << "connect: "<<sender->name()<<" "<<sigc<<", slot "<<recv->name()<<" "<<slotc<< endl;
|
|
|
|
bool ok = TTQObject::connect( sender, sigc, recv, slotc );
|
|
|
|
if (ok)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Connect to signal
|
|
|
|
if ( recv->metaObject()->findSignal(dest, true) >= 0 ) {
|
|
|
|
TTQString si2 = TTQString("2%1").arg(dest);
|
|
|
|
const char *sig2c = si2.ascii();
|
|
|
|
|
|
|
|
kdDebug(80001) << "connect: "<<sender->name()<<" "<<sigc<<", sig "<<recv->name()<<" "<<sig2c<< endl;
|
|
|
|
bool ok = TTQObject::connect( sender, sigc, recv, sig2c );
|
|
|
|
if (ok)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
KJS::Boolean JSSlotUtils::disconnect( KJS::ExecState */*exec*/, KJS::Object &/*self*/,
|
|
|
|
TTQObject *sender, const char *sig,
|
|
|
|
TTQObject *recv, const char *dest )
|
|
|
|
{
|
|
|
|
if ( (!sender) || (!recv) )
|
|
|
|
return KJS::Boolean(false);
|
|
|
|
|
|
|
|
bool ok;
|
|
|
|
|
|
|
|
// Source
|
|
|
|
TTQString si = TTQString("2%1").arg(sig);
|
|
|
|
const char *sigc = si.ascii();
|
|
|
|
|
|
|
|
// Disconnect from slot
|
|
|
|
if ( recv->metaObject()->findSlot(dest, true) >= 0 ) {
|
|
|
|
TTQString sl = TTQString("1%1").arg(dest);
|
|
|
|
const char *slotc = sl.ascii();
|
|
|
|
|
|
|
|
//kdDebug(80001) << "disconnect: "<<sender->name()<<" "<<sigc<<", slot "<<recv->name()<<" "<<slotc<< endl;
|
|
|
|
ok = TTQObject::disconnect( sender, sigc, recv, slotc );
|
|
|
|
if (ok)
|
|
|
|
return KJS::Boolean(ok);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Disonnect to signal
|
|
|
|
if ( recv->metaObject()->findSignal(dest, true) >= 0 ) {
|
|
|
|
TTQString si2("2");
|
|
|
|
si2 = si2 + dest;
|
|
|
|
const char *sig2c = si2.ascii();
|
|
|
|
|
|
|
|
//kdDebug(80001)<< "disconnect: "<<sender->name()<<" "<<sigc<<", sig "<<recv->name()<<" "<<sig2c<< endl;
|
|
|
|
ok = TTQObject::disconnect( sender, sigc, recv, sig2c );
|
|
|
|
if (ok)
|
|
|
|
return KJS::Boolean(ok);
|
|
|
|
}
|
|
|
|
|
|
|
|
return KJS::Boolean(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
KJS::Value JSSlotUtils::extractValue( KJS::ExecState *exec, TQUObject *uo, JSObjectProxy *parent )
|
|
|
|
{
|
|
|
|
TTQCString typenm( uo->type->desc() );
|
|
|
|
kdDebug(80001) << "JSSlotUtils:extractValue() " << typenm << endl;
|
|
|
|
|
|
|
|
if ( typenm == "null" )
|
|
|
|
return KJS::Null();
|
|
|
|
else if ( typenm == "bool" )
|
|
|
|
return KJS::Boolean( static_QUType_bool.get(uo) );
|
|
|
|
else if ( typenm == "int" )
|
|
|
|
return KJS::Number( static_QUType_int.get(uo) );
|
|
|
|
else if ( typenm == "double" )
|
|
|
|
return KJS::Number( static_QUType_double.get(uo) );
|
|
|
|
else if ( typenm == "charstar" )
|
|
|
|
return KJS::String( static_QUType_charstar.get(uo) );
|
|
|
|
else if ( typenm == "TTQString" )
|
|
|
|
return KJS::String( static_QUType_TQString.get(uo) );
|
|
|
|
else if ( typenm == "TTQVariant" )
|
|
|
|
return convertToValue( exec, static_QUType_TQVariant.get(uo) );
|
|
|
|
else if ( typenm == "ptr" ) {
|
|
|
|
void *ptr = static_QUType_ptr.get(uo);
|
|
|
|
|
|
|
|
// If it's a TTQObject and we know the parent
|
|
|
|
if ( ptr && parent ) {
|
|
|
|
TTQObject *qobj = (TTQObject *)(ptr); // Crash in kst
|
|
|
|
return parent->part()->factory()->createProxy( exec, qobj, parent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
kdWarning(80001) << "JSSlotUtils:extractValue() Failed (" << typenm << ")" << endl;
|
|
|
|
TTQString msg = i18n( "Value of type (%1) is not supported." ).arg( typenm );
|
|
|
|
throwError(exec, msg,KJS::TypeError);
|
|
|
|
return KJS::Null();
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Add a value to a TQUObject.
|
|
|
|
//
|
|
|
|
|
|
|
|
void JSSlotUtils::implantInt( KJS::ExecState *exec, TQUObject *uo, const KJS::Value &v )
|
|
|
|
{
|
|
|
|
static_QUType_int.set( uo, v.toInteger( exec ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void JSSlotUtils::implantCharStar( KJS::ExecState *exec, TQUObject *uo, const KJS::Value &v )
|
|
|
|
{
|
|
|
|
static_QUType_charstar.set( uo, v.toString( exec ).ascii() );
|
|
|
|
}
|
|
|
|
|
|
|
|
void JSSlotUtils::implantBool( KJS::ExecState *exec, TQUObject *uo, const KJS::Value &v )
|
|
|
|
{
|
|
|
|
static_QUType_bool.set( uo, v.toBoolean( exec ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void JSSlotUtils::implantDouble( KJS::ExecState *exec, TQUObject *uo, const KJS::Value &v )
|
|
|
|
{
|
|
|
|
static_QUType_double.set( uo, v.toNumber( exec ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void JSSlotUtils::implantTQString( KJS::ExecState *exec, TQUObject *uo, const KJS::Value &v )
|
|
|
|
{
|
|
|
|
static_QUType_TQString.set( uo, v.toString(exec).qstring() );
|
|
|
|
}
|
|
|
|
|
|
|
|
void JSSlotUtils::implantCString( KJS::ExecState *exec, TQUObject *uo, const KJS::Value &v )
|
|
|
|
{
|
|
|
|
static_QUType_charstar.set( uo, v.toString(exec).ascii() );
|
|
|
|
}
|
|
|
|
|
|
|
|
void JSSlotUtils::implantURL( KJS::ExecState *exec, TQUObject *uo, const KJS::Value &v,KURL *url )
|
|
|
|
{
|
|
|
|
*url = TTQString( v.toString(exec).qstring() );
|
|
|
|
static_QUType_ptr.set( uo, url );
|
|
|
|
}
|
|
|
|
|
|
|
|
void JSSlotUtils::implantColor( KJS::ExecState *exec, TQUObject *uo, const KJS::Value &v, TTQColor *color )
|
|
|
|
{
|
|
|
|
bool ok;
|
|
|
|
TTQString s( v.toString(exec).qstring() );
|
|
|
|
|
|
|
|
if ( s.startsWith("#") ) {
|
|
|
|
|
|
|
|
TTQRegExp re("#([0-9a-f][0-9a-f]){3,4}");
|
|
|
|
re.setCaseSensitive( false );
|
|
|
|
|
|
|
|
if ( re.search(s) != -1 ) {
|
|
|
|
uint r = re.cap(1).toUInt(&ok, 16);
|
|
|
|
uint g = re.cap(2).toUInt(&ok, 16);
|
|
|
|
uint b = re.cap(3).toUInt(&ok, 16);
|
|
|
|
|
|
|
|
if ( re.numCaptures() == 3 )
|
|
|
|
*color = TTQColor(r,g,b);
|
|
|
|
else if ( re.numCaptures() == 4 ) {
|
|
|
|
uint a = re.cap(4).toUInt(&ok, 16);
|
|
|
|
uint pix = r;
|
|
|
|
pix = pix << 8;
|
|
|
|
pix = pix | g;
|
|
|
|
pix = pix << 8;
|
|
|
|
pix = pix | b;
|
|
|
|
pix = pix << 8;
|
|
|
|
pix = pix | a;
|
|
|
|
|
|
|
|
*color = TTQColor( qRgba(r,g,b,a), pix );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Try for a named color
|
|
|
|
*color = TTQColor( s );
|
|
|
|
}
|
|
|
|
|
|
|
|
static_QUType_ptr.set( uo, color );
|
|
|
|
}
|
|
|
|
|
|
|
|
void JSSlotUtils::implantPoint( KJS::ExecState *exec, TQUObject *uo, const KJS::Value &v, TTQPoint *point )
|
|
|
|
{
|
|
|
|
KJS::Object o = v.toObject( exec );
|
|
|
|
if ( !o.isValid() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
int x, y;
|
|
|
|
KJS::Identifier zero("0"), one("1"), ex("x"), wi("y");
|
|
|
|
|
|
|
|
if ( o.hasProperty(exec, zero) && o.hasProperty(exec, one) ) {
|
|
|
|
x = o.get( exec, zero ).toInteger(exec);
|
|
|
|
y = o.get( exec, one ).toInteger(exec);
|
|
|
|
}
|
|
|
|
else if ( o.hasProperty(exec, ex) && o.hasProperty(exec, wi) ) {
|
|
|
|
x = o.get( exec, ex ).toInteger(exec);
|
|
|
|
y = o.get( exec, wi ).toInteger(exec);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
|
|
|
|
*point = TTQPoint( x, y );
|
|
|
|
static_QUType_ptr.set( uo, point );
|
|
|
|
}
|
|
|
|
|
|
|
|
void JSSlotUtils::implantSize( KJS::ExecState *exec, TQUObject *uo, const KJS::Value &v, TTQSize *size )
|
|
|
|
{
|
|
|
|
KJS::Object o = v.toObject( exec );
|
|
|
|
if ( !o.isValid() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
int w, h;
|
|
|
|
KJS::Identifier zero("0"), one("1"), wid("width"), hih("height");
|
|
|
|
|
|
|
|
if ( o.hasProperty(exec, zero) && o.hasProperty(exec, one) ) {
|
|
|
|
w = o.get( exec, zero ).toInteger(exec);
|
|
|
|
h = o.get( exec, one ).toInteger(exec);
|
|
|
|
}
|
|
|
|
else if ( o.hasProperty(exec, wid) && o.hasProperty(exec, hih) ) {
|
|
|
|
w = o.get( exec, wid ).toInteger(exec);
|
|
|
|
h = o.get( exec, hih ).toInteger(exec);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
|
|
|
|
*size = TTQSize( w, h );
|
|
|
|
static_QUType_ptr.set( uo, size );
|
|
|
|
}
|
|
|
|
|
|
|
|
void JSSlotUtils::implantRect( KJS::ExecState *exec, TQUObject *uo, const KJS::Value &v, TTQRect *rect )
|
|
|
|
{
|
|
|
|
KJS::Object o = v.toObject( exec );
|
|
|
|
if ( !o.isValid() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
int x, y, w, h;
|
|
|
|
KJS::Identifier zero("0"), one("1"), two("2"), three("3");
|
|
|
|
KJS::Identifier ex("x"), wi("y"), wid("width"), hih("height");
|
|
|
|
|
|
|
|
if ( o.hasProperty(exec, zero) && o.hasProperty(exec, one)
|
|
|
|
&& o.hasProperty(exec, two) && o.hasProperty(exec, three) ) {
|
|
|
|
x = o.get( exec, zero ).toInteger(exec);
|
|
|
|
y = o.get( exec, one ).toInteger(exec);
|
|
|
|
w = o.get( exec, two ).toInteger(exec);
|
|
|
|
h = o.get( exec, three ).toInteger(exec);
|
|
|
|
}
|
|
|
|
else if ( o.hasProperty(exec, ex) && o.hasProperty(exec, wi)
|
|
|
|
&& o.hasProperty(exec, wid) && o.hasProperty(exec, hih) ) {
|
|
|
|
x = o.get( exec, ex ).toInteger(exec);
|
|
|
|
y = o.get( exec, wi ).toInteger(exec);
|
|
|
|
w = o.get( exec, wid ).toInteger(exec);
|
|
|
|
h = o.get( exec, hih ).toInteger(exec);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
|
|
|
|
*rect = TTQRect( x, y, w, h );
|
|
|
|
static_QUType_ptr.set( uo, rect );
|
|
|
|
}
|
|
|
|
|
|
|
|
void JSSlotUtils::implantDate( KJS::ExecState *exec, TQUObject *uo, const KJS::Value &v, TTQDate *date )
|
|
|
|
{
|
|
|
|
TTQDateTime jsDate = convertDateToDateTime(exec, v);
|
|
|
|
date->setYMD( jsDate.date().year(), jsDate.date().month(), jsDate.date().day() );
|
|
|
|
static_QUType_ptr.set( uo, date );
|
|
|
|
}
|
|
|
|
|
|
|
|
void JSSlotUtils::implantStringList(KJS::ExecState *exec, TQUObject *uo, const KJS::Value &v, TTQStringList *lst )
|
|
|
|
{
|
|
|
|
*lst = convertArrayToStringList(exec,v);
|
|
|
|
static_QUType_ptr.set(uo,lst);
|
|
|
|
}
|
|
|
|
|
|
|
|
void JSSlotUtils::implantTime( KJS::ExecState *exec, TQUObject *uo, const KJS::Value &v, TTQTime *time )
|
|
|
|
{
|
|
|
|
TTQDateTime jsDate = convertDateToDateTime(exec, v);
|
|
|
|
time->setHMS( jsDate.time().hour(), jsDate.time().minute(), jsDate.time().second() );
|
|
|
|
static_QUType_ptr.set( uo, time );
|
|
|
|
}
|
|
|
|
|
|
|
|
void JSSlotUtils::implantDateTime( KJS::ExecState *exec, TQUObject *uo, const KJS::Value &v, TTQDateTime *datetime )
|
|
|
|
{
|
|
|
|
TTQDateTime jsDate = convertDateToDateTime(exec, v);
|
|
|
|
datetime->setDate( jsDate.date() );
|
|
|
|
datetime->setTime( jsDate.time() );
|
|
|
|
static_QUType_ptr.set( uo, datetime );
|
|
|
|
}
|
|
|
|
|
|
|
|
void JSSlotUtils::implantPixmap( KJS::ExecState *exec, TQUObject *uo, const KJS::Value &v, TTQPixmap *pix )
|
|
|
|
{
|
|
|
|
*pix = convertToVariant(exec, v).toPixmap() ;
|
|
|
|
static_QUType_ptr.set( uo, pix );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool JSSlotUtils::implantTQVariant( KJS::ExecState *, TQUObject *uo, const KJS::Value &v)
|
|
|
|
{
|
|
|
|
JSValueProxy *prx = JSProxy::toValueProxy( v.imp() );
|
|
|
|
if ( !prx )
|
|
|
|
return false;
|
|
|
|
kdDebug(80001) << "We got a " << prx->typeName() << endl;
|
|
|
|
|
|
|
|
static_QUType_TQVariant.set( uo, prx->toVariant() );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool JSSlotUtils::implantValueProxy( KJS::ExecState *, TQUObject *uo,
|
|
|
|
const KJS::Value &val, const TTQString &clazz )
|
|
|
|
{
|
|
|
|
JSValueProxy *prx = JSProxy::toValueProxy( val.imp() );
|
|
|
|
if ( !prx )
|
|
|
|
return false;
|
|
|
|
if ( prx->typeName() != clazz )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
kdDebug(80001) << "We got a " << prx->typeName() << " and is valid " << prx->toVariant().isValid() << endl;
|
|
|
|
TTQVariant var = prx->toVariant();
|
|
|
|
kdDebug(80001) << "We got a " << var.typeName()<< " and is valid " << var.isValid() << endl;
|
|
|
|
static_QUType_TQVariant.set( uo, var );
|
|
|
|
return var.isValid();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool JSSlotUtils::implantOpaqueProxy( KJS::ExecState *, TQUObject *uo,
|
|
|
|
const KJS::Value &v, const TTQString &clazz )
|
|
|
|
{
|
|
|
|
JSOpaqueProxy *prx = JSProxy::toOpaqueProxy( v.imp() );
|
|
|
|
if ( !prx )
|
|
|
|
return false;
|
|
|
|
if ( prx->typeName() != clazz )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
static_QUType_ptr.set( uo, prx->toNative<void>() );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool JSSlotUtils::implantObjectProxy( KJS::ExecState *, TQUObject *uo,
|
|
|
|
const KJS::Value &v, const TTQString &clazz )
|
|
|
|
{
|
|
|
|
JSObjectProxy *prx = JSProxy::toObjectProxy( v.imp() );
|
|
|
|
if ( !prx )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if ( !prx->object()->inherits( clazz.latin1() ) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
static_QUType_ptr.set( uo, prx->toObjectProxy()->object() );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
int JSSlotUtils::findSignature( const TTQString &sig )
|
|
|
|
{
|
|
|
|
// No args
|
|
|
|
if ( sig.contains("()") )
|
|
|
|
return SignatureNone;
|
|
|
|
|
|
|
|
// One arg
|
|
|
|
if ( sig.contains("(int)") )
|
|
|
|
return SignatureInt;
|
|
|
|
else if ( sig.contains("(uint)") )
|
|
|
|
return SignatureUInt;
|
|
|
|
else if ( sig.contains("(long)") )
|
|
|
|
return SignatureLong;
|
|
|
|
else if ( sig.contains("(ulong)") )
|
|
|
|
return SignatureULong;
|
|
|
|
else if ( sig.contains("(bool)") )
|
|
|
|
return SignatureBool;
|
|
|
|
else if ( sig.contains("(double)") )
|
|
|
|
return SignatureDouble;
|
|
|
|
|
|
|
|
else if ( sig.contains("(const TTQString&)") )
|
|
|
|
return SignatureString;
|
|
|
|
else if ( sig.contains("(const TTQCString&)") )
|
|
|
|
return SignatureCString;
|
|
|
|
else if ( sig.contains("(const char*)") )
|
|
|
|
return SignatureCString;
|
|
|
|
else if ( sig.contains("(const KURL&)") )
|
|
|
|
return SignatureURL;
|
|
|
|
else if ( sig.contains("(const TTQColor&)") )
|
|
|
|
return SignatureColor;
|
|
|
|
else if ( sig.contains("(const TTQPoint&)") )
|
|
|
|
return SignaturePoint;
|
|
|
|
else if ( sig.contains("(const TTQRect&)") )
|
|
|
|
return SignatureRect;
|
|
|
|
else if ( sig.contains("(const TTQSize&)") )
|
|
|
|
return SignatureSize;
|
|
|
|
else if ( sig.contains("(const TTQPixmap&)") )
|
|
|
|
return SignaturePixmap;
|
|
|
|
else if ( sig.contains("(const TTQFont&)") )
|
|
|
|
return SignatureFont;
|
|
|
|
else if ( sig.contains("(const TTQDate&)") )
|
|
|
|
return SignatureDate;
|
|
|
|
else if ( sig.contains("(const TTQTime&)") )
|
|
|
|
return SignatureTime;
|
|
|
|
else if ( sig.contains("(const TTQDateTime&)") )
|
|
|
|
return SignatureDateTime;
|
|
|
|
else if ( sig.contains("(const TTQImage&)") )
|
|
|
|
return SignatureImage;
|
|
|
|
else if ( sig.contains("(TTQWidget*)") )
|
|
|
|
return SignatureTQWidget;
|
|
|
|
// Two args
|
|
|
|
else if ( sig.contains("(const TTQDate&, const TTQDate&)") )
|
|
|
|
return SignatureDateDate;
|
|
|
|
else if ( sig.contains("(const TTQColor&, const TTQString&)") )
|
|
|
|
return SignatureColorString;
|
|
|
|
|
|
|
|
else if ( sig.contains("(const TTQString&,const TTQString&,const TTQString&)") )
|
|
|
|
return SignatureStringStringString;
|
|
|
|
|
|
|
|
else if ( sig.contains("(const TTQString&,const TTQString&)") )
|
|
|
|
return SignatureStringString;
|
|
|
|
else if ( sig.contains("(int,int)") )
|
|
|
|
return SignatureIntInt;
|
|
|
|
else if ( sig.contains("(int,int,int,int)") )
|
|
|
|
return SignatureIntIntIntInt;
|
|
|
|
else if ( sig.contains("(int,int,int,int,int)") )
|
|
|
|
return SignatureIntIntIntIntInt;
|
|
|
|
else if ( sig.contains("(int,int,int,int,bool)") )
|
|
|
|
return SignatureIntIntIntIntBool;
|
|
|
|
|
|
|
|
else if ( sig.contains("(const TTQString&,int)") )
|
|
|
|
return SignatureStringInt;
|
|
|
|
else if ( sig.contains("(const TTQString&,uint)") )
|
|
|
|
return SignatureStringInt;
|
|
|
|
|
|
|
|
else if ( sig.contains("(const KURL&,const KURL&)") )
|
|
|
|
return SignatureURLURL;
|
|
|
|
else if ( sig.contains("(const KURL&,const TTQString&)") )
|
|
|
|
return SignatureURLString;
|
|
|
|
else if ( sig.contains("(const TTQString&,const KURL&)") )
|
|
|
|
return SignatureStringURL;
|
|
|
|
else if ( sig.contains("(const TTQRect&,bool)") )
|
|
|
|
return SignatureRectBool;
|
|
|
|
else if ( sig.contains("(const TTQString&,bool)") )
|
|
|
|
return SignatureStringBool;
|
|
|
|
else if ( sig.contains("(int,bool)") )
|
|
|
|
return SignatureIntBool;
|
|
|
|
else if ( sig.contains("(int,int,bool)") )
|
|
|
|
return SignatureIntIntBool;
|
|
|
|
else if ( sig.contains("(int,int,const TTQString&)") )
|
|
|
|
return SignatureIntIntString;
|
|
|
|
else if ( sig.contains("(const TTQString&,bool,int)") )
|
|
|
|
return SignatureStringBoolInt;
|
|
|
|
else if ( sig.contains("(const TTQString&,bool,bool)") )
|
|
|
|
return SignatureStringBoolBool;
|
|
|
|
else if ( sig.contains("(const TTQString&,int,int)") )
|
|
|
|
return SignatureStringIntInt;
|
|
|
|
else if ( sig.contains("(int,const TTQColor&,bool)") )
|
|
|
|
return SignatureIntColorBool;
|
|
|
|
else if ( sig.contains("(int,const TTQColor&)") )
|
|
|
|
return SignatureIntColor;
|
|
|
|
|
|
|
|
else if ( sig.contains("(int,int,float,float)") )
|
|
|
|
return SignatureIntIntFloatFloat;
|
|
|
|
else if ( sig.contains("(const TTQString&,bool,bool,bool)") )
|
|
|
|
return SignatureStringBoolBoolBool;
|
|
|
|
else if ( sig.contains("(int,int,int,int,int,int)") )
|
|
|
|
return SignatureIntIntIntIntIntInt;
|
|
|
|
|
|
|
|
// Handle anything that falls through
|
|
|
|
if ( sig.contains("TTQString") || sig.contains("TTQColor") ||
|
|
|
|
sig.contains("int") || sig.contains("bool") ||
|
|
|
|
sig.contains("float") || sig.contains("KURL") ||
|
|
|
|
sig.contains("TTQVariant") || sig.contains("TTQSize") ||
|
|
|
|
sig.contains("TTQRect") || sig.contains("TTQPixmap") ||
|
|
|
|
sig.contains("TTQCString") || sig.contains("TTQPoint") ||
|
|
|
|
sig.contains("double") || sig.contains("TTQFont") ||
|
|
|
|
sig.contains("TTQDate") || sig.contains("TTQTime") ||
|
|
|
|
sig.contains("TTQDateTime") || sig.contains("TTQStringList") ||
|
|
|
|
sig.contains("TTQWidget") || sig.contains("TTQObject") ||
|
|
|
|
sig.contains("TTQPen") || sig.contains("TTQImage") )
|
|
|
|
return SignatureCustom;
|
|
|
|
|
|
|
|
kdWarning(80001) << "findSignature: not supported type " << sig << endl;
|
|
|
|
return SignatureNotSupported;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define MAX_SUPPORTED_ARGS (12)
|
|
|
|
|
|
|
|
KJS::Value JSSlotUtils::invokeSlot( KJS::ExecState *exec, KJS::Object &, const KJS::List &args,
|
|
|
|
JSObjectProxyImp *proxyimp )
|
|
|
|
{
|
|
|
|
TQUObject uo[ MAX_SUPPORTED_ARGS ] = { TQUObject(), TQUObject(), TQUObject(),
|
|
|
|
TQUObject(), TQUObject(), TQUObject(),
|
|
|
|
TQUObject(), TQUObject(), TQUObject(),
|
|
|
|
TQUObject(), TQUObject(), TQUObject() };
|
|
|
|
|
|
|
|
KJS::Value retValue;
|
|
|
|
JSObjectProxy *proxy = proxyimp->objectProxy();
|
|
|
|
TTQCString slotname( proxyimp->slotName() );
|
|
|
|
int sigid = proxyimp->signature();
|
|
|
|
TTQPtrList<uint> uintlist;
|
|
|
|
uintlist.setAutoDelete(true);
|
|
|
|
TTQObject *obj = proxy->object();
|
|
|
|
int slotid = obj->metaObject()->findSlot( slotname, true );
|
|
|
|
if ( slotid == -1 )
|
|
|
|
{
|
|
|
|
TTQString msg = i18n( "Slot %1 was not found." ).arg( slotname );
|
|
|
|
return throwError(exec, msg,KJS::ReferenceError);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( args.size() > MAX_SUPPORTED_ARGS )
|
|
|
|
{
|
|
|
|
TTQString msg = i18n( "Slots with more than %1 arguments are not supported." ).arg( MAX_SUPPORTED_ARGS );
|
|
|
|
return throwError(exec, msg,KJS::ReferenceError);
|
|
|
|
}
|
|
|
|
// Keep args in scope for duration of the method.
|
|
|
|
KURL url[MAX_SUPPORTED_ARGS];
|
|
|
|
TTQColor color[MAX_SUPPORTED_ARGS];
|
|
|
|
TTQPoint point[MAX_SUPPORTED_ARGS];
|
|
|
|
TTQSize size[MAX_SUPPORTED_ARGS];
|
|
|
|
TTQRect rect[MAX_SUPPORTED_ARGS];
|
|
|
|
TTQDate date[MAX_SUPPORTED_ARGS];
|
|
|
|
TTQDateTime datetime[MAX_SUPPORTED_ARGS];
|
|
|
|
TTQTime time[MAX_SUPPORTED_ARGS];
|
|
|
|
TTQPixmap pix[MAX_SUPPORTED_ARGS];
|
|
|
|
TTQStringList slst[MAX_SUPPORTED_ARGS];
|
|
|
|
|
|
|
|
bool notsupported = true;
|
|
|
|
|
|
|
|
if ( args.size() == 1 ) {
|
|
|
|
//kdDebug( 80001 ) << "One Arg" << endl;
|
|
|
|
switch (sigid) {
|
|
|
|
case SignatureInt:
|
|
|
|
implantInt( exec, uo+1, args[0] );
|
|
|
|
break;
|
|
|
|
case SignatureBool:
|
|
|
|
implantBool( exec, uo+1, args[0] );
|
|
|
|
break;
|
|
|
|
case SignatureString:
|
|
|
|
implantTQString( exec, uo+1, args[0] );
|
|
|
|
break;
|
|
|
|
case SignatureCString:
|
|
|
|
implantCString( exec, uo+1, args[0] );
|
|
|
|
break;
|
|
|
|
case SignatureDouble:
|
|
|
|
implantDouble( exec, uo+1, args[0] );
|
|
|
|
break;
|
|
|
|
case SignatureURL:
|
|
|
|
implantURL( exec, uo+1, args[0], &url[0] );
|
|
|
|
break;
|
|
|
|
case SignatureColor:
|
|
|
|
implantColor( exec, uo+1, args[0], &color[0] );
|
|
|
|
break;
|
|
|
|
case SignaturePoint:
|
|
|
|
implantPoint( exec, uo+1, args[0], &point[0] );
|
|
|
|
break;
|
|
|
|
case SignatureSize:
|
|
|
|
implantSize( exec, uo+1, args[0], &size[0] );
|
|
|
|
break;
|
|
|
|
case SignatureRect:
|
|
|
|
implantRect( exec, uo+1, args[0], &rect[0] );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
notsupported = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if ( args.size() == 2 ) {
|
|
|
|
//kdDebug( 80001 ) << "Two Args" << endl;
|
|
|
|
switch (sigid) {
|
|
|
|
case SignatureIntInt:
|
|
|
|
implantInt( exec, uo+1, args[0] );
|
|
|
|
implantInt( exec, uo+2, args[1] );
|
|
|
|
break;
|
|
|
|
case SignatureStringInt:
|
|
|
|
implantTQString( exec, uo+1, args[0] );
|
|
|
|
implantInt( exec, uo+2, args[1] );
|
|
|
|
break;
|
|
|
|
case SignatureRectBool:
|
|
|
|
implantRect( exec, uo+1, args[0], &rect[0] );
|
|
|
|
implantBool( exec, uo+2, args[1] );
|
|
|
|
break;
|
|
|
|
case SignatureStringString:
|
|
|
|
implantTQString( exec, uo+1, args[0] );
|
|
|
|
implantTQString( exec, uo+2, args[1] );
|
|
|
|
break;
|
|
|
|
case SignatureStringBool:
|
|
|
|
implantTQString( exec, uo+1, args[0] );
|
|
|
|
implantBool( exec, uo+2, args[1] );
|
|
|
|
break;
|
|
|
|
case SignatureIntColor:
|
|
|
|
implantInt( exec, uo+1, args[0] );
|
|
|
|
implantColor( exec, uo+2, args[1], &color[0] );
|
|
|
|
break;
|
|
|
|
case SignatureURLURL:
|
|
|
|
implantURL( exec, uo+1, args[0], &url[0] );
|
|
|
|
implantURL( exec, uo+2, args[1], &url[1] );
|
|
|
|
break;
|
|
|
|
case SignatureURLString:
|
|
|
|
implantURL( exec, uo+1, args[0], &url[0] );
|
|
|
|
implantTQString( exec, uo+2, args[1] );
|
|
|
|
break;
|
|
|
|
case SignatureStringURL:
|
|
|
|
implantTQString( exec, uo+1, args[0] );
|
|
|
|
implantURL( exec, uo+2, args[1], &url[0] );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
notsupported = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
//kdDebug( 80001 ) << args.size() << " Args" << endl;
|
|
|
|
notsupported = false;
|
|
|
|
switch (sigid) {
|
|
|
|
case SignatureNone:
|
|
|
|
break;
|
|
|
|
case SignatureStringStringString:
|
|
|
|
if ( args.size() != 3 )
|
|
|
|
return KJS::Null();
|
|
|
|
implantTQString( exec, uo+1, args[0] );
|
|
|
|
implantTQString( exec, uo+2, args[1] );
|
|
|
|
implantTQString( exec, uo+3, args[2] );
|
|
|
|
break;
|
|
|
|
case SignatureIntIntString:
|
|
|
|
if ( args.size() != 3 )
|
|
|
|
return KJS::Null();
|
|
|
|
implantInt( exec, uo+1, args[0] );
|
|
|
|
implantInt( exec, uo+2, args[1] );
|
|
|
|
implantTQString( exec, uo+3, args[2] );
|
|
|
|
break;
|
|
|
|
case SignatureIntIntIntInt:
|
|
|
|
if ( args.size() != 4 )
|
|
|
|
return KJS::Null();
|
|
|
|
implantInt( exec, uo+1, args[0] );
|
|
|
|
implantInt( exec, uo+2, args[1] );
|
|
|
|
implantInt( exec, uo+3, args[2] );
|
|
|
|
implantInt( exec, uo+4, args[3] );
|
|
|
|
break;
|
|
|
|
case SignatureIntIntIntIntBool:
|
|
|
|
if ( args.size() != 5 )
|
|
|
|
return KJS::Null();
|
|
|
|
implantInt( exec, uo+1, args[0] );
|
|
|
|
implantInt( exec, uo+2, args[1] );
|
|
|
|
implantInt( exec, uo+3, args[2] );
|
|
|
|
implantInt( exec, uo+4, args[3] );
|
|
|
|
implantBool( exec, uo+5, args[4] );
|
|
|
|
break;
|
|
|
|
case SignatureIntIntIntIntIntInt:
|
|
|
|
if ( args.size() != 6 )
|
|
|
|
return KJS::Null();
|
|
|
|
implantInt( exec, uo+1, args[0] );
|
|
|
|
implantInt( exec, uo+2, args[1] );
|
|
|
|
implantInt( exec, uo+3, args[2] );
|
|
|
|
implantInt( exec, uo+4, args[3] );
|
|
|
|
implantInt( exec, uo+5, args[4] );
|
|
|
|
implantInt( exec, uo+6, args[5] );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
notsupported = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( notsupported ) {
|
|
|
|
//kdDebug( 80001 ) << "Trying method 2" << endl;
|
|
|
|
// Rip apart the call signature to get the args slow but effective.
|
|
|
|
notsupported = false;
|
|
|
|
int argsStart = slotname.find('(');
|
|
|
|
int argsEnd = slotname.find(')');
|
|
|
|
TTQString fargs = slotname.mid( argsStart+1, argsEnd-argsStart-1 );
|
|
|
|
|
|
|
|
// Iterate over the parameters
|
|
|
|
TTQStringList argList = TTQStringList::split(',', fargs, true);
|
|
|
|
uint count = TQMIN( argList.count(), MAX_SUPPORTED_ARGS );
|
|
|
|
|
|
|
|
kdDebug( 80001 ) << "======== arg count " << count << endl;
|
|
|
|
for( uint idx = 0; idx < count; idx++ ) {
|
|
|
|
kdDebug( 80001 ) << "======== Handling arg " << idx << endl;
|
|
|
|
|
|
|
|
TTQString arg = argList[idx];
|
|
|
|
arg = arg.replace("const", "");
|
|
|
|
arg = arg.replace("&", "");
|
|
|
|
arg = arg.simplifyWhiteSpace();
|
|
|
|
kdDebug( 80001 ) << "Testing " << arg.latin1() << endl;
|
|
|
|
|
|
|
|
if(arg.contains("uint") == 1) {
|
|
|
|
unsigned int *unsignedint=new uint;
|
|
|
|
*unsignedint=args[idx].toUInt32(exec);
|
|
|
|
uintlist.append(unsignedint);
|
|
|
|
static_QUType_ptr.set( uo+1+idx, unsignedint) ;
|
|
|
|
}
|
|
|
|
else if( arg.contains("int") == 1 )
|
|
|
|
implantInt( exec, uo+1+idx, args[idx] );
|
|
|
|
else if ( arg.contains("double") == 1 )
|
|
|
|
implantDouble(exec, uo+1+idx, args[idx]);
|
|
|
|
else if ( arg.contains("TTQStringList") == 1 )
|
|
|
|
implantStringList( exec, uo+1+idx, args[idx], &slst[idx] );
|
|
|
|
else if ( arg.contains("TTQString") == 1 )
|
|
|
|
implantTQString(exec, uo+1+idx, args[idx] );
|
|
|
|
else if ( arg.contains("TTQCString") == 1 )
|
|
|
|
implantCString(exec, uo+1+idx, args[idx] );
|
|
|
|
else if ( arg.contains("bool") == 1 )
|
|
|
|
implantBool( exec, uo+1+idx, args[idx] );
|
|
|
|
else if ( arg.contains("KURL") == 1 )
|
|
|
|
implantURL( exec, uo+1+idx, args[idx], &url[idx] );
|
|
|
|
else if ( arg.contains("TTQColor") == 1 )
|
|
|
|
implantColor( exec, uo+1+idx, args[idx], &color[idx] );
|
|
|
|
else if ( arg.contains("TTQPoint") == 1 )
|
|
|
|
implantPoint( exec, uo+1+idx, args[idx], &point[idx] );
|
|
|
|
else if ( arg.contains("TTQSize") == 1 )
|
|
|
|
implantSize( exec, uo+1+idx, args[idx], &size[idx] );
|
|
|
|
else if ( arg.contains("TTQRect") == 1 )
|
|
|
|
implantRect( exec, uo+1+idx, args[idx], &rect[idx] );
|
|
|
|
else if ( arg.contains("TTQDate") == 1 )
|
|
|
|
implantDate( exec, uo+1+idx, args[idx], &date[idx] );
|
|
|
|
else if ( arg.contains("TTQTime") == 1 )
|
|
|
|
implantTime( exec, uo+1+idx, args[idx], &time[idx] );
|
|
|
|
else if ( arg.contains("TTQDateTime") == 1 )
|
|
|
|
implantDateTime( exec, uo+1+idx, args[idx], &datetime[idx] );
|
|
|
|
else if ( arg.contains("TTQPixmap") == 1 )
|
|
|
|
implantPixmap( exec, uo+1+idx, args[idx], &pix[idx] );
|
|
|
|
else if ( arg.contains("char") == 1)
|
|
|
|
implantCharStar( exec, uo+1+idx, args[idx] );
|
|
|
|
else if ( ( arg.contains("TTQObject") == 1 ) || ( arg.contains("TTQWidget") == 1 ) )
|
|
|
|
{
|
|
|
|
kdDebug( 80001 ) << "Doing a TTQObject" << endl;
|
|
|
|
notsupported = !implantObjectProxy( exec, uo+1+idx, args[idx], "TTQObject" );
|
|
|
|
}
|
|
|
|
else if ( TTQVariant::nameToType(arg.latin1()) != TTQVariant::Invalid ) {
|
|
|
|
bool ok = implantValueProxy( exec, uo+1+idx, args[idx], arg );
|
|
|
|
if ( !ok ) {
|
|
|
|
notsupported = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
kdDebug( 80001 ) << "Implanted the variant " << static_QUType_TQVariant.get(uo+1+idx).isValid() << endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* else if ( ( arg.contains("TTQVariant") == 1 ) ||
|
|
|
|
( arg.contains("TTQPen") == 1 ) || (arg.contains("TTQFont") == 1 ) ||
|
|
|
|
( arg.contains("TTQBrush") == 1 ))
|
|
|
|
if(!implantTQVariant(exec, uo+1+idx, args[idx] )){
|
|
|
|
notsupported = true;
|
|
|
|
break;
|
|
|
|
} */
|
|
|
|
else if ( arg.contains("*") == 1 ) {
|
|
|
|
TTQRegExp re("(\\w+)\\*");
|
|
|
|
if ( re.search(arg) >= 0 ) {
|
|
|
|
bool ok = implantObjectProxy( exec, uo+1+idx, args[idx], re.cap(1) );
|
|
|
|
if ( !ok ) {
|
|
|
|
ok = implantOpaqueProxy( exec, uo+1+idx, args[idx], re.cap(1) );
|
|
|
|
if ( !ok ) {
|
|
|
|
notsupported = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
notsupported = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
notsupported = true;
|
|
|
|
break; // Abort on the first unsupported parameter
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( notsupported ) {
|
|
|
|
kdWarning(80001) << "Signature " << slotname << " has not been implemented" << endl;
|
|
|
|
return KJS::Null();
|
|
|
|
} else {
|
|
|
|
kdDebug(80001) << "Call Signature: " << slotname << endl;
|
|
|
|
|
|
|
|
obj->qt_invoke( slotid, uo );
|
|
|
|
}
|
|
|
|
// Handle return types
|
|
|
|
TTQCString ret( proxyimp->returnType() );
|
|
|
|
if ( ret.isEmpty() ) {
|
|
|
|
// Basic type (void, int etc.)
|
|
|
|
return extractValue( exec, uo );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Object type
|
|
|
|
kdDebug(80001) << "Handling a pointer return of type " << ret << endl;
|
|
|
|
|
|
|
|
if ( proxy->part()->factory()->isTQObject(ret) ) {
|
|
|
|
kdDebug(80001) << "Return type is TTQObject " << ret << endl;
|
|
|
|
return extractValue( exec, uo, proxy );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Opaque type
|
|
|
|
kdDebug(80001) << "Return type is opaque " << ret << endl;
|
|
|
|
|
|
|
|
JSOpaqueProxy *opaque = new JSOpaqueProxy(static_QUType_ptr.get(uo), ret.data());
|
|
|
|
//opaque->setValue( );
|
|
|
|
|
|
|
|
KJS::Object opaqueObj( opaque );
|
|
|
|
opaque->addBindings( exec, opaqueObj );
|
|
|
|
|
|
|
|
return opaqueObj;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace KJSEmbed::Bindings
|
|
|
|
} // namespace KJSEmbed
|
|
|
|
|
|
|
|
// Local Variables:
|
|
|
|
// c-basic-offset: 4
|
|
|
|
// End:
|
|
|
|
|