void KstBindTimeInterpretation::setActive(KJS::ExecState *exec, const KJS::Value& value) {
  if (!_d) {
    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
    exec->setException(eobj);
    return;
  }
  if (value.type() != KJS::BooleanType) {
    KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError);
    exec->setException(eobj);
    return;
  }
  KstWriteLocker wl(_d->_d);
  bool isIt;
  KstAxisInterpretation interp;
  KstAxisDisplay disp;
  if (_d->_xAxis) {
    _d->_d->getXAxisInterpretation(isIt, interp, disp);
    _d->_d->setXAxisInterpretation(value.toBoolean(exec), interp, disp);
  } else {
    _d->_d->getYAxisInterpretation(isIt, interp, disp);
    _d->_d->setYAxisInterpretation(value.toBoolean(exec), interp, disp);
  }
  _d->_d->setDirty();
  KstApp::inst()->paintAll(KstPainter::P_PAINT);
}
bool SaxHandler::startElement( const QString &ns, const QString &ln, const QString &qn,
			       const QXmlAttributes &attrs )
{
    if ( !jshandler.isValid() ) {
	error = ErrorNoHandler;
	return false;
    }

    KJS::Identifier funName("startElement");
    if ( !jshandler.hasProperty(exec, funName) )
	return QXmlDefaultHandler::startElement( ns, ln, qn, attrs );

    KJS::Object fun = jshandler.get(exec, funName).toObject( exec );
    if ( !fun.implementsCall() ) {
	error = ErrorNotCallable;
	return false;
    }

    KJS::List args;
    args.append( KJS::String(ns) );
    args.append( KJS::String(ln) );
    args.append( KJS::String(qn) );
    // TODO: XmlAttributes not yet supported

    KJS::Value ret = fun.call( exec, jshandler, args );
    return ret.toBoolean( exec );
}
// Variant value must be released with NPReleaseVariantValue()
void convertValueToNPVariant (KJS::ExecState *exec, const KJS::Value &value, NPVariant *result)
{
    Type type = value.type();

    if (type == StringType) {
        UString ustring = value.toString(exec);
        CString cstring = ustring.UTF8String();
        NPString string = { (const NPUTF8 *)cstring.c_str(), cstring.size() };
        NPN_InitializeVariantWithStringCopy (result, &string );
    }
    else if (type == NumberType) {
        NPN_InitializeVariantWithDouble (result, value.toNumber(exec));
    }
    else if (type == BooleanType) {
        NPN_InitializeVariantWithBool (result, value.toBoolean(exec));
    }
    else if (type == UnspecifiedType) {
        NPN_InitializeVariantAsUndefined(result);
    }
    else if (type == NullType) {
        NPN_InitializeVariantAsNull(result);
    }
    else if (type == ObjectType) {
        KJS::ObjectImp *objectImp = static_cast<KJS::ObjectImp*>(value.imp());
        if (objectImp->classInfo() == &KJS::RuntimeObjectImp::info) {
            KJS::RuntimeObjectImp *imp = static_cast<KJS::RuntimeObjectImp *>(value.imp());
            CInstance *instance = static_cast<CInstance*>(imp->getInternalInstance());
            NPN_InitializeVariantWithObject (result, instance->getObject());
        }
        else {

            KJS::Interpreter *originInterpreter = exec->interpreter();
            const Bindings::RootObject *originExecutionContext = rootForInterpreter(originInterpreter);

            KJS::Interpreter *interpreter = 0;
            if (originInterpreter->isGlobalObject(value)) {
                interpreter = originInterpreter->interpreterForGlobalObject (value.imp());
            }

            if (!interpreter)
                interpreter = originInterpreter;

            const Bindings::RootObject *executionContext = rootForInterpreter(interpreter);
            if (!executionContext) {
                Bindings::RootObject *newExecutionContext = new KJS::Bindings::RootObject(0);
                newExecutionContext->setInterpreter (interpreter);
                executionContext = newExecutionContext;
            }

            NPObject *obj = (NPObject *)exec->interpreter()->createLanguageInstanceForValue (exec, Instance::CLanguage, value.toObject(exec), originExecutionContext, executionContext);
            NPN_InitializeVariantWithObject (result, obj);
            _NPN_ReleaseObject (obj);
        }
    }
    else
        NPN_InitializeVariantAsUndefined(result);
}
Example #4
0
void KstBindLegend::setVertical(KJS::ExecState *exec, const KJS::Value& value) {
  if (value.type() != KJS::BooleanType) {
    return createPropertyTypeError(exec);
  }
  KstViewLegendPtr d = makeLegend(_d);
  if (d) {
    KstWriteLocker wl(d);
    d->setVertical(value.toBoolean(exec));
    KstApp::inst()->paintAll(KstPainter::P_PAINT);
  }
}
Example #5
0
void KstBindPlot::setTied(KJS::ExecState *exec, const KJS::Value& value) {
  if (value.type() != KJS::BooleanType) {
    return createPropertyTypeError(exec);
  }
  Kst2DPlotPtr d = makePlot(_d);
  if (d) {
    KstWriteLocker wl(d);
    d->setTied(value.toBoolean(exec));
    KstApp::inst()->paintAll(KstPainter::P_PAINT);
  }
}
Example #6
0
void KstBindCurve::setHasBars(KJS::ExecState *exec, const KJS::Value& value) {
  if (value.type() != KJS::BooleanType) {
    KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError);
    exec->setException(eobj);
    return;
  }
  KstVCurvePtr d = makeCurve(_d);
  if (d) {
    KstWriteLocker wl(d);
    d->setHasBars(value.toBoolean(exec));
  }
}
void KstBindPowerSpectrum::setAverage(KJS::ExecState *exec, const KJS::Value& value) {
  if (value.type() != KJS::BooleanType) {
    KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError);
    exec->setException(eobj);
    return;
  }
  KstPSDPtr d = makePSD(_d);
  if (d) {
    KstWriteLocker wl(d);
    d->setAverage(value.toBoolean(exec));
  }
}
bool SaxHandler::endDocument()
{
    if ( !jshandler.isValid() ) {
	error = ErrorNoHandler;
	return false;
    }

    KJS::Identifier funName("endDocument");
    if ( !jshandler.hasProperty(exec, funName) )
	return QXmlDefaultHandler::endDocument();

    KJS::Object fun = jshandler.get(exec, funName).toObject( exec );
    if ( !fun.implementsCall() ) {
	error = ErrorNotCallable;
	return false;
    }

    KJS::Value ret = fun.call( exec, jshandler, KJS::List() );
    return ret.toBoolean( exec );
}
bool SaxHandler::characters( const QString &chars )
{
    if ( !jshandler.isValid() ) {
	error = ErrorNoHandler;
	return false;
    }

    KJS::Identifier funName("characters");
    if ( !jshandler.hasProperty(exec, funName) )
	return QXmlDefaultHandler::characters( chars );

    KJS::Object fun = jshandler.get(exec, funName).toObject( exec );
    if ( !fun.implementsCall() ) {
	error = ErrorNotCallable;
	return false;
    }

    KJS::List args;
    args.append( KJS::String(chars) );

    KJS::Value ret = fun.call( exec, jshandler, args );
    return ret.toBoolean( exec );
}