void TextStreamImp::addBindings( KJS::ExecState *exec, KJS::Object &parent )
{
    kdDebug() << "TextStreamImp::addBindings()" << endl;

    JSOpaqueProxy *op = JSProxy::toOpaqueProxy( parent.imp() );
    if ( !op ) {
	kdWarning() << "TextStreamImp::addBindings() failed, not a JSOpaqueProxy" << endl;
	return;
    }

    QTextStream *ts = op->toTextStream();
    if ( !ts ) {
	kdWarning() << "TextStreamImp::addBindings() failed, type is " << op->typeName() << endl;
	return;
    }

    JSProxy::MethodTable methods[] = { 
	{ MethodIsReadable, "isReadable" },
	{ MethodIsWritable, "isWritable" },
	{ MethodPrint, "print" },
	{ MethodPrintLn, "println" },
	{ MethodReadLine, "readLine" },
	{ MethodFlush, "flush" },
	{ 0, 0 }
    };

    int idx = 0;
    do {
	TextStreamImp *tsi = new TextStreamImp( exec, idx, ts );
	parent.put( exec , methods[idx].name, KJS::Object(tsi) );
	++idx;
    } while( methods[idx].id );
}
    void JSObjectProxy::addBindingsClass( KJS::ExecState *exec, KJS::Object & /*object*/ ) {
        KJS::Identifier clazzid;
        QObject *o = obj;
        Bindings::BindingObject *bo = dynamic_cast<Bindings::BindingObject *>( o );
        if ( bo ) {
            clazzid = KJS::Identifier( bo->jsClassName() ? bo->jsClassName() : obj->className() );
        } else {
            clazzid = KJS::Identifier( obj->className() );
        }

        KJS::Object global = js->globalObject();
        if ( global.hasProperty( exec, clazzid ) ) {
            kdDebug( 80001 ) << "addBindingsClass() " << clazzid.qstring() << " already known" << endl;

            KJS::Object clazz = global.get( exec, clazzid ).toObject( exec );
            Bindings::JSFactoryImp *imp = dynamic_cast<Bindings::JSFactoryImp *>( clazz.imp() );
            if ( !imp ) {
                kdWarning() << "addBindingsClass() Class was not created by normal means" << endl;
                return ;
            }

            kdDebug( 80001 ) << "addBindingsClass() Adding enums" << endl;
            imp->setDefaultValue( js->builtinObject().construct( exec, KJS::List() ) );
            addBindingsEnum( exec, clazz );
        } else {
            kdWarning() << "addBindingsClass() " << clazzid.qstring() << " not known" << endl;
        }
    }
Пример #3
0
  KJS::Value Point::call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ) {
    if( !JSProxy::checkType(self, JSProxy::ValueProxy, "QPoint") ) return KJS::Value();
    JSValueProxy *vp = JSProxy::toValueProxy( self.imp() );
    KJS::Value retValue = KJS::Value();
    QPoint val = vp->toVariant().toPoint();

    switch ( mid ) { 
      case Methodx:
	retValue = KJS::Number(val.x());
       break;
      case MethodsetX:
	val.setX(extractInt(exec,args,0));
	break;
      case  Methody:
	retValue = KJS::Number(val.y());
	break;
      case  MethodsetY:
	val.setY(extractInt(exec,args,0));
	break;
      case  MethodmanhattanLength:
	retValue = KJS::Number(val.manhattanLength());
	break;
      default:
	QString msg = i18n( "Point has no method %1" ).arg(mid);
  return throwError(exec, msg);
	break;
    }

    vp->setValue(val);
    return retValue;
  }
void KJSEmbed::Bindings::KFileItemImp::addBindings( KJS::ExecState * exec, KJS::Object & object )
{

	JSOpaqueProxy *op = JSProxy::toOpaqueProxy( object.imp() );
	if ( !op ) 
	{
		kdWarning() << "KFileItemImp::addBindings() failed, not a JSOpaqueProxy" << endl;
		return;
	}
	
	if ( op->typeName() != "KFileItem" ) 
	{
		kdWarning() << "KFileItemImp::addBindings() failed, type is " << op->typeName() <<
	endl;
		return;
	}
	
	JSProxy::MethodTable methods[] = {
		{ Methodrefresh, "refresh"},
		{ MethodrefreshMimeType, "refreshMimeType"},
		{ Methodurl, "url"},
		{ MethodsetUrl, "setUrl"},
		{ MethodsetName, "setName"},
		{ MethodpermissionsString, "permissionsString"},
		{ Methoduser, "user"},
		{ Methodgroup, "group"},
		{ MethodisLink, "isLink"},
		{ MethodisDir, "isDir"},
		{ MethodisFile, "isFile"},
		{ MethodisReadable, "isReadable"},
		{ MethodlinkDest, "linkDest"},
		{ MethodtimeString, "timeString"}, 
		{ MethodisLocalFile, "isLocalFile"},
		{ Methodtext, "text"},
		{ Methodname, "name"}, 
		{ MethodmimeType, "mimeType"},
		{ MethodisMimeTypeKnown, "isMimeTypeKnown"},
		{ MethodmimeComment, "mimeComment"},
		{ MethodiconName, "iconName"},
		{ Methodpixmap, "pixmap"},
		{ Methodoverlays, "overlays"},
		{ MethodgetStatusBarInfo, "getStatusBarInfo"},
		{ MethodgetToolTipText, "getToolTipText"}, 
		{ Methodrun, "run"},
		{ 0, 0 }
	};
	
	int idx = 0;
	do {
		KFileItemImp *meth = new KFileItemImp( exec, methods[idx].id );
		object.put( exec , methods[idx].name, KJS::Object(meth) );
		++idx;
	} while( methods[idx].id );

}
Пример #5
0
KJS::Value KstBindWindow::call(KJS::ExecState *exec, KJS::Object& self, const KJS::List& args) {
  int id = this->id();
  if (id <= 0) {
    return createInternalError(exec);
  }

  KstBindWindow *imp = dynamic_cast<KstBindWindow*>(self.imp());
  if (!imp) {
    return createInternalError(exec);
  }

  return (imp->*windowBindings[id - 1].method)(exec, args);
}
void MyCustomObjectImp::addBindings( KJS::ExecState *exec, KJS::Object &object ) {

    kdDebug() << "MyCustomObjectImp::addBindings()" << endl;
    JSOpaqueProxy *op = JSProxy::toOpaqueProxy( object.imp() );
    if ( !op ) {
        kdWarning() << "MyCustomObjectImp::addBindings() failed, not a JSOpaqueProxy" << endl;
        return;
    }

    if ( op->typeName() != "MyCustomObject" ) {
	kdWarning() << "MyCustomObjectImp::addBindings() failed, type is " << op->typeName() << endl;
	return;
    }

    JSProxy::MethodTable methods[] = {
	{ Methodmode, "mode"},
	{ MethodsetMode, "setMode"},
	{ Methodthing,  "thing"},
	{ MethodsetThing, "setThing"},
	{ 0, 0 }
    };

    int idx = 0;
    do {
        MyCustomObjectImp *meth = new MyCustomObjectImp( exec, methods[idx].id );
        object.put( exec , methods[idx].name, KJS::Object(meth) );
        ++idx;
    } while( methods[idx].id );

    //
    // Define the enum constants
    //
    struct EnumValue {
	const char *id;
	int val;
    };

    EnumValue enums[] = {
	// MyCustomObject::mode
	{ "On", 0 },
	{ "Off", 1 },
	{ 0, 0 }
    };

    int enumidx = 0;
    do {
        object.put( exec, enums[enumidx].id, KJS::Number(enums[enumidx].val), KJS::ReadOnly );
        ++enumidx;
    } while( enums[enumidx].id );
}
KJS::Value KstBindTimeInterpretation::call(KJS::ExecState *exec, KJS::Object& self, const KJS::List& args) {
  int id = this->id();
  if (id <= 0) {
    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
    exec->setException(eobj);
    return KJS::Undefined();
  }

  KstBindTimeInterpretation *imp = dynamic_cast<KstBindTimeInterpretation*>(self.imp());
  if (!imp) {
    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
    exec->setException(eobj);
    return KJS::Undefined();
  }

  return (imp->*timeInterpretationBindings[id - 1].method)(exec, args);
}
KJS::Value MyCustomObjectImp::call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ) {

    kdDebug() << "MyCustomObjectImp::call() " << mid << endl;
    JSOpaqueProxy *op = JSProxy::toOpaqueProxy( self.imp() );
    if ( !op ) {
        kdWarning() << "MyCustomObjectImp::call() failed, not a JSOpaqueProxy" << endl;
        return KJS::Value();
    }

    if ( op->typeName() != "MyCustomObject" ) {
	kdWarning() << "MyCustomObjectImp::call() failed, type is " << op->typeName() << endl;
	return KJS::Value();
    }

    MyCustomObject *obj = op->toNative<MyCustomObject>();

    KJS::Value retValue = KJS::Value();
    switch ( mid ) {
    case Methodthing:
    {
	retValue = KJS::String(obj->thing);
	break;
    }
    case MethodsetThing:
    {
	obj->thing = extractString(exec, args, 0);
	break;
    }
    case Methodmode:
    {
	retValue = KJS::Number( (int)obj->mode );
	break;
    }
    case MethodsetMode:
    {
	obj->mode = (MyCustomObject::Mode) extractInt(exec, args, 0);
	break;
    }
    default:
        kdWarning() << "MyCustomObject has no method " << mid << endl;
        break;
    }

    op->setValue((void*) obj, "MyCustomObject");
    return retValue;
}
Пример #9
0
KJS::Value KstBindPlot::call(KJS::ExecState *exec, KJS::Object& self, const KJS::List& args) {
  int id = this->id();
  if (id <= 0) {
    return createInternalError(exec);
  }

  int start = KstBindBorderedViewObject::methodCount();
  if (id > start) {
    KstBindPlot *imp = dynamic_cast<KstBindPlot*>(self.imp());
    if (!imp) {
      return createInternalError(exec);
    }
    return (imp->*plotBindings[id - start - 1].method)(exec, args);
  }

  return KstBindBorderedViewObject::call(exec, self, args);
}
KJS::Value KstBindEllipse::call(KJS::ExecState *exec, KJS::Object& self, const KJS::List& args) {
  int id = this->id();
  if (id <= 0) {
    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
    exec->setException(eobj);
    return KJS::Undefined();
  }

  int start = KstBindViewObject::methodCount();
  if (id > start) {
    KstBindEllipse *imp = dynamic_cast<KstBindEllipse*>(self.imp());
    if (!imp) {
      KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
      exec->setException(eobj);
      return KJS::Undefined();
    }

    return (imp->*ellipseBindings[id - start - 1].method)(exec, args);
  } 

  return KstBindViewObject::call(exec, self, args);
}
Пример #11
0
KJS::Value BrushImp::call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ) {
 
    if( !JSProxy::checkType(self, JSProxy::ValueProxy, "QBrush") ) return KJS::Value();
    JSValueProxy *op = JSProxy::toValueProxy( self.imp() );
    QBrush brush = op->toVariant().toBrush();

    KJS::Value retValue = KJS::Value();
    switch ( mid ) {
    case Methodstyle:
    {
    	return KJS::Number((int) brush.style() );
	break;
    }
    case MethodsetStyle:
    {
    	int style = extractInt(exec, args, 0);
	brush.setStyle((Qt::BrushStyle)style);
	break;
    }
    case MethodColor:
    {
    	return convertToValue(exec, brush.color());
	break;
    }
    case MethodsetColor:
    {
    	QColor color = extractQColor(exec, args, 0);
	brush.setColor(color);
	break;
    }
    default:
        kdWarning() << "Brush has no method " << mid << endl;
        break;
    }

    op->setValue(brush);
    return retValue;
}
KJS::Value KJSEmbed::Bindings::KFileItemImp::call( KJS::ExecState * exec, KJS::Object & self, const KJS::List & args )
{
	kdDebug() << "KFileItemImp::call() " << mid << endl;
	JSOpaqueProxy *op = JSProxy::toOpaqueProxy( self.imp() );
	if ( !op ) {
		kdWarning() << "KFileItemImp::call() failed, not a JSOpaqueProxy" << endl;
		return KJS::Value();
	}
	
	if ( op->typeName() != "KFileItem" ) {
		kdWarning() << "KFileItemImp::call() failed, type is " << op->typeName() << endl;
		return KJS::Value();
	}
	
	KFileItem *obj = op->toNative<KFileItem >();
	
	KJS::Value retValue = KJS::Value();
	switch ( mid ) {
	case Methodrefresh:
		obj->refresh();
		break;
	case MethodrefreshMimeType:
		obj->refreshMimeType(); 
		break;
	case Methodurl:
	{
		QString url = obj->url().url();
		retValue = KJS::String(url);
		break;
	}
	case MethodsetUrl:
	{
		QString url = extractQString(exec, args, 0);
		obj->setURL(url);
		break;
	}
	case MethodsetName: 
	case MethodpermissionsString: 
	case Methoduser: 
	case Methodgroup: 
	case MethodisLink: 
	case MethodisDir: 
	case MethodisFile: 
	case MethodisReadable: 
	case MethodlinkDest: 
	case MethodtimeString: 
	case MethodisLocalFile: 
	case Methodtext:
	{
		retValue = convertToValue(exec, obj->text() );
		break;
	} 
	case Methodname:  
	case MethodmimeType: 
	case MethodisMimeTypeKnown: 
	case MethodmimeComment: 
	case MethodiconName: 
	{
		retValue = convertToValue( exec, obj->iconName() );
		break;
	}
	case Methodpixmap:
	{
		int size = extractInt(exec, args, 0);
		int state = extractInt(exec, args, 1);
		retValue = convertToValue(exec, obj->pixmap(size, state));
		break;
	}
	case Methodoverlays: 
	{
		retValue = convertToValue(exec, obj->overlays());
		break;
	}
	case MethodgetStatusBarInfo: 
	{
		retValue = KJS::String( obj->getStatusBarInfo() );
		break;
	}
	case MethodgetToolTipText:
	{
		int maxcount = extractInt(exec, args, 0);
		retValue = KJS::String(obj->getToolTipText(maxcount));
		break;
	}
	case Methodrun:
		obj->run();
		break;
	default:
		kdWarning() << "KFileItemImp has no method " << mid << endl;
		break;
	}
	
	op->setValue((void*) obj, "KFileItem");
	return retValue;

} 
KJS::Object KJSEmbedPart::bind( QObject *obj )
{
    KJS::Object jsobj = jsfactory->createProxy( js->globalExec(), obj );
    JSProxy::toObjectProxy(jsobj.imp() )->setOwner(JSProxy::Native);
    return jsobj;
}
Пример #14
0
KJS::Value Pixmap::call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ) {

    if( !JSProxy::checkType( self, JSProxy::ValueProxy, "QPixmap") )
        return KJS::Value();

    JSValueProxy *op = JSProxy::toValueProxy( self.imp() );
    pix = op->toVariant().toPixmap();

    KJS::Value retValue = KJS::Value();
    switch ( mid ) {
    case Methodwidth:
        retValue = KJS::Number(width());
        break;
    case Methodheight:
        retValue = KJS::Number(height());
        break;
    case Methoddepth:
        retValue = KJS::Number(depth());
        break;
    case MethodisNull:
        retValue = KJS::Boolean(isNull());
        break;
    case Methodsize:
        retValue = convertToValue(exec, size());
        break;
    case Methodrect:
        retValue = convertToValue(exec, rect());
        break;
    case Methodresize:
    {
        if( args.size() == 2)
		resize(extractInt(exec, args, 0), extractInt(exec, args, 1));
	else if( args.size() == 1)
	    resize(extractQSize(exec, args, 0) );
	break;
    }
    case Methodfill:
        fill( extractQColor(exec, args, 0));
        break;
    case Methodmask:
    {
        retValue = convertToValue(exec, mask() );
        break;
    }
    case MethodsetMask:
    {
       setMask(extractQPixmap(exec, args, 0));
       break;
    }
    case MethodcreateHeuristicMask:
    {
       retValue = convertToValue(exec, createHeuristicMask(extractBool(exec, args, 0)));
       break;
    }
    case MethodgrabWindow:
    {
    	int winid = extractInt(exec, args,0);
	int x = extractInt(exec, args,1);
	int y = extractInt(exec, args,2);
	int w = extractInt(exec, args,3);
	int h = extractInt(exec, args,4);
    	grabWindow(winid,x,y,w,h);
	break;
    }
    default:
        kdWarning() << "Image has no method " << mid << endl;
        break;
    }

    op->setValue(pix);
    return retValue;
}
Пример #15
0
KJS::Value QDirImp::call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args )
{
    JSOpaqueProxy *op = JSProxy::toOpaqueProxy( self.imp() );
    if ( !op ) {
        kdWarning() << "QDirImp::call() failed, not a JSOpaqueProxy" << endl;
        return KJS::Value();
    }

    if ( op->typeName() != "QDir" ) {
        kdWarning() << "QDirImp::call() failed, type is " << op->typeName() << endl;
	return KJS::Value();
    }

    instance =  op->toNative<QDir>();

    switch( mid ) {

    case Method_setPath_7:
        return setPath_7( exec, self, args );
        break;

    case Method_path_8:
        return path_8( exec, self, args );
        break;

    case Method_absPath_9:
        return absPath_9( exec, self, args );
        break;

    case Method_canonicalPath_10:
        return canonicalPath_10( exec, self, args );
        break;

    case Method_dirName_11:
        return dirName_11( exec, self, args );
        break;

    case Method_filePath_12:
        return filePath_12( exec, self, args );
        break;

    case Method_absFilePath_13:
        return absFilePath_13( exec, self, args );
        break;

    case Method_cd_14:
        return cd_14( exec, self, args );
        break;

    case Method_cdUp_15:
        return cdUp_15( exec, self, args );
        break;

    case Method_nameFilter_16:
        return nameFilter_16( exec, self, args );
        break;

    case Method_setNameFilter_17:
        return setNameFilter_17( exec, self, args );
        break;

    case Method_filter_18:
        return filter_18( exec, self, args );
        break;

    case Method_setFilter_19:
        return setFilter_19( exec, self, args );
        break;

    case Method_sorting_20:
        return sorting_20( exec, self, args );
        break;

    case Method_setSorting_21:
        return setSorting_21( exec, self, args );
        break;

    case Method_matchAllDirs_22:
        return matchAllDirs_22( exec, self, args );
        break;

    case Method_setMatchAllDirs_23:
        return setMatchAllDirs_23( exec, self, args );
        break;

    case Method_count_24:
        return count_24( exec, self, args );
        break;

    case Method_encodedEntryList_26:
        return encodedEntryList_26( exec, self, args );
        break;

    case Method_encodedEntryList_27:
        return encodedEntryList_27( exec, self, args );
        break;

    case Method_entryList_28:
        return entryList_28( exec, self, args );
        break;

    case Method_entryList_29:
        return entryList_29( exec, self, args );
        break;

    case Method_entryInfoList_30:
        return entryInfoList_30( exec, self, args );
        break;

    case Method_entryInfoList_31:
        return entryInfoList_31( exec, self, args );
        break;

    case Method_mkdir_32:
        return mkdir_32( exec, self, args );
        break;

    case Method_rmdir_33:
        return rmdir_33( exec, self, args );
        break;

    case Method_isReadable_34:
        return isReadable_34( exec, self, args );
        break;

    case Method_exists_35:
        return exists_35( exec, self, args );
        break;

    case Method_isRoot_36:
        return isRoot_36( exec, self, args );
        break;

    case Method_isRelative_37:
        return isRelative_37( exec, self, args );
        break;

    case Method_convertToAbs_38:
        return convertToAbs_38( exec, self, args );
        break;

    case Method_remove_41:
        return remove_41( exec, self, args );
        break;

    case Method_rename_42:
        return rename_42( exec, self, args );
        break;

    case Method_exists_43:
        return exists_43( exec, self, args );
        break;

    case Method_refresh_44:
        return refresh_44( exec, self, args );
        break;

    case Method_convertSeparators_45:
        return convertSeparators_45( exec, self, args );
        break;

    case Method_drives_46:
        return drives_46( exec, self, args );
        break;

    case Method_separator_47:
        return separator_47( exec, self, args );
        break;

    case Method_setCurrent_48:
        return setCurrent_48( exec, self, args );
        break;

    case Method_current_49:
        return current_49( exec, self, args );
        break;

    case Method_home_50:
        return home_50( exec, self, args );
        break;

    case Method_root_51:
        return root_51( exec, self, args );
        break;

    case Method_currentDirPath_52:
        return currentDirPath_52( exec, self, args );
        break;

    case Method_homeDirPath_53:
        return homeDirPath_53( exec, self, args );
        break;

    case Method_rootDirPath_54:
        return rootDirPath_54( exec, self, args );
        break;

    case Method_match_55:
        return match_55( exec, self, args );
        break;

    case Method_match_56:
        return match_56( exec, self, args );
        break;

    case Method_cleanDirPath_57:
        return cleanDirPath_57( exec, self, args );
        break;

    case Method_isRelativePath_58:
        return isRelativePath_58( exec, self, args );
        break;

    default:
        break;
    }

    QString msg = i18n( "QDirImp has no method with id '%1'." ).arg( mid );
    return throwError(exec, msg,KJS::ReferenceError);
}