#include <qcstring.h>
#include <qimage.h>
#include <qpainter.h>
#include <qpalette.h>
#include <qpixmap.h>
#include <qfont.h>
#include <kjs/object.h>
#include <kjsembed/global.h>
#include <kjsembed/jsobjectproxy.h>
#include <kjsembed/jsopaqueproxy.h>
#include <kjsembed/jsbinding.h>
#include <>
#include "_imp.h"
/**
* Namespace containing the KJSEmbed library.
*/
namespace KJSEmbed {
Imp::Imp( KJS::ExecState *exec, int mid, bool constructor )
: JSProxyImp(exec), id(mid), cons(constructor)
{
}
Imp::~Imp()
{
}
/**
* Adds bindings for static methods and enum constants to the specified Object.
*/
void Imp::addStaticBindings( KJS::ExecState *exec, KJS::Object &object )
{
JSProxy::MethodTable methods[] = {
_
Method_
{ , "" },
{ 0, 0 }
};
int idx = 0;
QCString lastName;
while( methods[idx].name ) {
if ( lastName != methods[idx].name ) {
Imp *meth = new Imp( exec, methods[idx].id );
object.put( exec , methods[idx].name, KJS::Object(meth) );
lastName = methods[idx].name;
}
++idx;
}
//
// Define the enum constants
//
struct EnumValue {
const char *id;
int val;
};
EnumValue enums[] = {
// enum
{ "", :: },
{ 0, 0 }
};
int enumidx = 0;
while( enums[enumidx].id ) {
object.put( exec, enums[enumidx].id, KJS::Number(enums[enumidx].val), KJS::ReadOnly );
++enumidx;
}
}
/**
* Adds bindings for instance methods to the specified Object.
*/
void Imp::addBindings( KJS::ExecState *exec, KJS::Object &object )
{
JSProxy::MethodTable methods[] = {
_
Method_
{ , "" },
{ 0, 0 }
};
int idx = 0;
QCString lastName;
while( methods[idx].name ) {
if ( lastName != methods[idx].name ) {
Imp *meth = new Imp( exec, methods[idx].id );
object.put( exec , methods[idx].name, KJS::Object(meth) );
lastName = methods[idx].name;
}
++idx;
}
}
/**
* Extract a pointer from an Object.
*/
*Imp::to( KJS::Object &self )
{
JSObjectProxy *ob = JSProxy::toObjectProxy( self.imp() );
if ( ob ) {
QObject *obj = ob->object();
if ( obj )
return dynamic_cast< *>( obj );
}
JSOpaqueProxy *op = JSProxy::toOpaqueProxy( self.imp() );
if ( !op )
return 0;
if ( op->typeName() != "" )
return 0;
return ( *)( op->toVoidStar() );
}
/**
* Select and invoke the correct constructor.
*/
KJS::Object Imp::construct( KJS::ExecState *exec, const KJS::List &args )
{
switch( id ) {
_
Constructor_
case :
return ( exec, args );
break;
default:
break;
}
QString msg = i18n("Cons has no constructor with id '%1'").arg(id);
KJS::Object err = KJS::Error::create( exec, KJS::ReferenceError, msg.utf8() );
exec->setException( err );
return err;
}
_
Constructor_
KJS::Object Imp::( KJS::ExecState *exec, const KJS::List &args )
{
#if 0 // This constructor has been disabled by the XSL template
QString arg = extractQString(exec, args, );
QString arg = extractQString(exec, args, );
QString arg = extractQString(exec, args, );
const QCString arg = (args.size() >= ) ? args[].toString(exec).ascii() : 0;
const char *arg = (args.size() >= ) ? args[].toString(exec).ascii() : 0;
int arg = extractInt(exec, args, );
uint arg = extractUInt(exec, args, );
double arg = extractDouble(exec, args, );
bool arg = extractBool(exec, args, );
QFont arg = extractQFont(exec, args, );
QPalette arg = extractQPalette(exec, args, );
QStringList arg = extractQStringList(exec, args, );
QStrList arg = extractQStrList(exec, args, );
QPoint arg = extractQPoint(exec, args, );
QRect arg = extractQRect(exec, args, );
QSize arg = extractQSize(exec, args, );
QPixmap arg = extractQPixmap(exec, args, );
QImage arg = extractQImage(exec, args, );
QColor arg = extractQColor(exec, args, );
QDate arg = extractQDate(exec, args, );
QTime arg = extractQTime(exec, args, );
QDateTime arg = extractQDateTime(exec, args, );
Qt::WFlags arg; // TODO (hack for QCanvasView)
// Unsupported parameter
return KJS::Object();
arg; // Dummy
// We should now create an instance of the object
*ret = new (
arg,
);
#endif // This constructor has been disabled by the XSL template
}
KJS::Value Imp::call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args )
{
instance = Imp::to( self );
switch( id ) {
_
Method_
case :
return ( exec, self, args );
break;
default:
break;
}
QString msg = i18n( "Imp has no method with id '%1'" ).arg( id );
KJS::Object err = KJS::Error::create( exec, KJS::ReferenceError, msg.utf8() );
exec->setException( err );
return err;
}
Imp::_
KJS::Value ( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args )
{
QString arg = extractQString(exec, args, );
QString arg = extractQString(exec, args, );
QString arg = extractQString(exec, args, );
const QCString arg = (args.size() >= ) ? args[].toString(exec).ascii() : 0;
const char *arg = (args.size() >= ) ? args[].toString(exec).ascii() : 0;
int arg = extractInt(exec, args, );
uint arg = extractUInt(exec, args, );
double arg = extractDouble(exec, args, );
bool arg = extractBool(exec, args, );
QFont arg = extractQFont(exec, args, );
QPalette arg = extractQPalette(exec, args, );
QStringList arg = extractQStringList(exec, args, );
QStrList arg = extractQStrList(exec, args, );
QPoint arg = extractQPoint(exec, args, );
QRect arg = extractQRect(exec, args, );
QSize arg = extractQSize(exec, args, );
QPixmap arg = extractQPixmap(exec, args, );
QImage arg = extractQImage(exec, args, );
QColor arg = extractQColor(exec, args, );
QDate arg = extractQDate(exec, args, );
QTime arg = extractQTime(exec, args, );
QDateTime arg = extractQDateTime(exec, args, );
QComboBox::Policy arg; // TODO (hack for combo box)
QFrame::Shape arg; // TODO (hack for frame)
QFrame::Shadow arg; // TODO (hack for frame)
FILE *arg; // TODO (hack for qfile)
QFile::Offset arg; // TODO (hack for qfile)
QFile::EncoderFn arg; // TODO (hack for qfile)
QFile::DecoderFn arg; // TODO (hack for qfile)
QCanvasSprite::FrameAnimationType arg; // TODO (hack for QCanvasSprite)
Qt::WFlags arg; // TODO (hack for QCanvasView)
QByteArray arg; // TODO (hack for qfile)
QPointArray arg; // TODO (hack for qcanvas)
QPainter arg; // TODO (hack for qcanvas)
QPainter arg; // TODO (hack for qcanvas)
QWMatrix arg; // TODO (hack for qcanvasview)
// Unsupported parameter
return KJS::Value();
arg; // Dummy
bool ret;
ret = instance->(
arg, );
return KJS::Boolean( ret );
int ret;
ret = instance->(
arg, );
return KJS::Number( ret );
uint ret;
ret = instance->(
arg, );
return KJS::Number( ret );
double ret;
ret = instance->(
arg, );
return KJS::Number( ret );
QString ret;
ret = instance->(
arg, );
return KJS::String( ret );
const char *ret;
ret = instance->(
arg, );
return KJS::String( ret );
ret;
ret = instance->(
arg, );
return convertToValue( exec, ret );
QStringList ret;
ret = instance->(
arg, );
return convertToValue( exec, ret );
instance->(
arg, );
return KJS::Value(); // Returns void
instance->(
arg, );
return KJS::Value(); // Returns ''
}
} // namespace KJSEmbed
// Local Variables:
// c-basic-offset: 4
// End: