/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
Any BasicScriptImpl::invoke( const Sequence< Any >& aParams, Sequence< sal_Int16 >& aOutParamIndex, Sequence< Any >& aOutParam )
{ // TODO: throw CannotConvertException // TODO: check length of aOutParamIndex, aOutParam
SolarMutexGuard aGuard;
Any aReturn;
if ( m_xMethod.is() )
{ // check if compiled
SbModule* pModule = static_cast< SbModule* >( m_xMethod->GetParent() ); if ( pModule && !pModule->IsCompiled() )
pModule->Compile();
// check number of parameters
sal_Int32 nParamsCount = aParams.getLength();
SbxInfo* pInfo = m_xMethod->GetInfo(); if ( pInfo )
{
sal_Int32 nSbxOptional = 0;
sal_uInt16 n = 1; for ( const SbxParamInfo* pParamInfo = pInfo->GetParam( n ); pParamInfo; pParamInfo = pInfo->GetParam( ++n ) )
{ if ( pParamInfo->nFlags & SbxFlagBits::Optional )
++nSbxOptional; else
nSbxOptional = 0;
}
sal_Int32 nSbxCount = n - 1; if ( nParamsCount < nSbxCount - nSbxOptional )
{ throw provider::ScriptFrameworkErrorException(
u"wrong number of parameters!"_ustr,
Reference< XInterface >(),
m_funcName,
u"Basic"_ustr,
provider::ScriptFrameworkErrorType::NO_SUCH_SCRIPT );
}
}
// set parameters
SbxArrayRef xSbxParams; if ( nParamsCount > 0 )
{
xSbxParams = new SbxArray; for ( sal_Int32 i = 0; i < nParamsCount; ++i )
{
SbxVariableRef xSbxVar = new SbxVariable( SbxVARIANT );
unoToSbxValue(xSbxVar.get(), aParams[i]);
xSbxParams->Put(xSbxVar.get(), static_cast<sal_uInt32>(i) + 1);
if (pInfo)
{ if (auto* p = pInfo->GetParam(static_cast<sal_uInt16>(i) + 1))
{
SbxDataType t = static_cast<SbxDataType>(p->eType & 0x0FFF); // tdf#133889 Revert the downcasting performed in sbxToUnoValueImpl // to allow passing by reference.
SbxDataType a = xSbxVar->GetType(); if (t == SbxSINGLE && (a == SbxINTEGER || a == SbxLONG))
{
sal_Int32 val = xSbxVar->GetLong(); if (val >= -16777216 && val <= 16777215)
ChangeTypeKeepingValue(*xSbxVar, t);
} elseif (t == SbxDOUBLE && (a == SbxINTEGER || a == SbxLONG))
ChangeTypeKeepingValue(*xSbxVar, t); elseif (t == SbxLONG && a == SbxINTEGER)
ChangeTypeKeepingValue(*xSbxVar, t); elseif (t == SbxULONG && a == SbxUSHORT)
ChangeTypeKeepingValue(*xSbxVar, t); // Enable passing by ref if (t != SbxVARIANT)
xSbxVar->SetFlag(SbxFlagBits::Fixed);
}
}
}
} if ( xSbxParams.is() )
m_xMethod->SetParameters( xSbxParams.get() );
// if it's a document-based script, temporarily reset ThisComponent to the script invocation context
Any aOldThisComponent; if ( m_documentBasicManager && m_xDocumentScriptContext.is() )
m_documentBasicManager->SetGlobalUNOConstant( u"ThisComponent"_ustr, Any( m_xDocumentScriptContext ), &aOldThisComponent );
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.