Prepare for removal of non-const operator[] from Sequence in vbahelper

Change-Id: I2450faf4b3e093b2046034e2a5e5657ff5144d98
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/124410
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
This commit is contained in:
Mike Kaganski
2021-10-29 10:24:13 +03:00
parent 2e29906567
commit 951c4ceb2e
10 changed files with 47 additions and 57 deletions

View File

@@ -532,7 +532,7 @@ void SAL_CALL ScVbaControl::fireEvent( const script::ScriptEvent& rEvt )
evt.ScriptCode = xNameQuery->getCodeNameForObject( xIf ); evt.ScriptCode = xNameQuery->getCodeNameForObject( xIf );
// handle if we passed in our own arguments // handle if we passed in our own arguments
if ( !rEvt.Arguments.hasElements() ) if ( !rEvt.Arguments.hasElements() )
evt.Arguments[ 0 ] <<= aEvt; evt.Arguments.getArray()[ 0 ] <<= aEvt;
xScriptListener->firing( evt ); xScriptListener->firing( evt );
} }
else else
@@ -546,7 +546,7 @@ void SAL_CALL ScVbaControl::fireEvent( const script::ScriptEvent& rEvt )
evt.Source = xThisControl; evt.Source = xThisControl;
aEvt.Source = xControl; aEvt.Source = xControl;
evt.ScriptCode = m_sLibraryAndCodeName; evt.ScriptCode = m_sLibraryAndCodeName;
evt.Arguments[ 0 ] <<= aEvt; evt.Arguments.getArray()[ 0 ] <<= aEvt;
xScriptListener->firing( evt ); xScriptListener->firing( evt );
} }
} }

View File

@@ -61,7 +61,7 @@ private:
if ( nIndex >= msNames.getLength() ) if ( nIndex >= msNames.getLength() )
msNames.realloc( nIndex ); msNames.realloc( nIndex );
msNames[ nIndex ] = getControlName( xCtrl ); msNames.getArray()[ nIndex ] = getControlName( xCtrl );
mControls.push_back( xCtrl ); mControls.push_back( xCtrl );
mIndices[ msNames[ nIndex ] ] = nIndex; mIndices[ msNames[ nIndex ] ] = nIndex;
} }
@@ -382,8 +382,7 @@ uno::Any SAL_CALL ScVbaControls::Add( const uno::Any& Object, const uno::Any& St
{ {
uno::Reference< script::XInvocation > xControlInvoke( xNewControl, uno::UNO_QUERY_THROW ); uno::Reference< script::XInvocation > xControlInvoke( xNewControl, uno::UNO_QUERY_THROW );
uno::Sequence< uno::Any > aArgs( 1 ); uno::Sequence< uno::Any > aArgs{ uno::Any(aComServiceName) };
aArgs[0] <<= aComServiceName;
uno::Sequence< sal_Int16 > aOutIDDummy; uno::Sequence< sal_Int16 > aOutIDDummy;
uno::Sequence< uno::Any > aOutDummy; uno::Sequence< uno::Any > aOutDummy;
xControlInvoke->invoke( "SOAddAXControl" , aArgs, aOutIDDummy, aOutDummy ); xControlInvoke->invoke( "SOAddAXControl" , aArgs, aOutIDDummy, aOutDummy );

View File

@@ -187,9 +187,10 @@ ScVbaListBox::setValueEvent( const uno::Any& value )
{ {
if( !bValue ) if( !bValue )
{ {
auto pList = nList.getArray();
for( ; i < nLength - 1; i++ ) for( ; i < nLength - 1; i++ )
{ {
nList[i] = nList[i + 1]; pList[i] = nList[i + 1];
} }
nList.realloc( nLength - 1 ); nList.realloc( nLength - 1 );
//m_xProps->setPropertyValue( sSourceName, uno::makeAny( nList ) ); //m_xProps->setPropertyValue( sSourceName, uno::makeAny( nList ) );
@@ -205,12 +206,11 @@ ScVbaListBox::setValueEvent( const uno::Any& value )
if( getMultiSelect() ) if( getMultiSelect() )
{ {
nList.realloc( nLength + 1 ); nList.realloc( nLength + 1 );
nList[nLength] = nIndex; nList.getArray()[nLength] = nIndex;
} }
else else
{ {
nList.realloc( 1 ); nList = { nIndex };
nList[0] = nIndex;
} }
//m_xProps->setPropertyValue( sSourceName, uno::makeAny( nList ) ); //m_xProps->setPropertyValue( sSourceName, uno::makeAny( nList ) );
fireClickEvent(); fireClickEvent();

View File

@@ -75,10 +75,11 @@ uno::Any ListPropListener::getValueEvent()
else // List() ( e.g. no args ) else // List() ( e.g. no args )
{ {
uno::Sequence< uno::Sequence< OUString > > sReturnArray( nLength ); uno::Sequence< uno::Sequence< OUString > > sReturnArray( nLength );
auto pReturnArray = sReturnArray.getArray();
for ( sal_Int32 i = 0; i < nLength; ++i ) for ( sal_Int32 i = 0; i < nLength; ++i )
{ {
sReturnArray[ i ].realloc( 10 ); pReturnArray[ i ].realloc( 10 );
sReturnArray[ i ][ 0 ] = sList[ i ]; pReturnArray[ i ].getArray()[ 0 ] = sList[ i ];
} }
aRet <<= sReturnArray; aRet <<= sReturnArray;
} }
@@ -107,7 +108,7 @@ ListControlHelper::AddItem( const uno::Any& pvargItem, const uno::Any& pvargInde
{ {
sal_Int32 nOldSize = sList.getLength(); sal_Int32 nOldSize = sList.getLength();
sList.realloc( nOldSize + 1 ); sList.realloc( nOldSize + 1 );
sList[ nOldSize ] = sString; sList.getArray()[ nOldSize ] = sString;
} }
else else
{ {

View File

@@ -357,6 +357,7 @@ uno::Any SAL_CALL VbaApplicationBase::Run( const OUString& MacroName, const uno:
int nArg = SAL_N_ELEMENTS( aArgsPtrArray ); int nArg = SAL_N_ELEMENTS( aArgsPtrArray );
uno::Sequence< uno::Any > aArgs( nArg ); uno::Sequence< uno::Any > aArgs( nArg );
auto pArgs = aArgs.getArray();
const uno::Any** pArg = aArgsPtrArray; const uno::Any** pArg = aArgsPtrArray;
const uno::Any** pArgEnd = aArgsPtrArray + nArg; const uno::Any** pArgEnd = aArgsPtrArray + nArg;
@@ -364,7 +365,7 @@ uno::Any SAL_CALL VbaApplicationBase::Run( const OUString& MacroName, const uno:
sal_Int32 nArgProcessed = 0; sal_Int32 nArgProcessed = 0;
for ( ; pArg != pArgEnd; ++pArg, ++nArgProcessed ) for ( ; pArg != pArgEnd; ++pArg, ++nArgProcessed )
aArgs[ nArgProcessed ] = **pArg; pArgs[ nArgProcessed ] = **pArg;
// resize array to position of last param with value // resize array to position of last param with value
aArgs.realloc( nArgProcessed + 1 ); aArgs.realloc( nArgProcessed + 1 );
@@ -418,8 +419,7 @@ uno::Any SAL_CALL VbaApplicationBase::getVBE()
try // return empty object on error try // return empty object on error
{ {
// "VBE" object does not have a parent, but pass document model to be able to determine application type // "VBE" object does not have a parent, but pass document model to be able to determine application type
uno::Sequence< uno::Any > aArgs( 1 ); uno::Sequence< uno::Any > aArgs{ uno::Any(getCurrentDocument()) };
aArgs[ 0 ] <<= getCurrentDocument();
uno::Reference< lang::XMultiComponentFactory > xServiceManager( mxContext->getServiceManager(), uno::UNO_SET_THROW ); uno::Reference< lang::XMultiComponentFactory > xServiceManager( mxContext->getServiceManager(), uno::UNO_SET_THROW );
uno::Reference< uno::XInterface > xVBE = xServiceManager->createInstanceWithArgumentsAndContext( uno::Reference< uno::XInterface > xVBE = xServiceManager->createInstanceWithArgumentsAndContext(
"ooo.vba.vbide.VBE" , aArgs, mxContext ); "ooo.vba.vbide.VBE" , aArgs, mxContext );

View File

@@ -19,6 +19,8 @@
#include "vbacommandbarcontrols.hxx" #include "vbacommandbarcontrols.hxx"
#include "vbacommandbarcontrol.hxx" #include "vbacommandbarcontrol.hxx"
#include <com/sun/star/lang/XSingleComponentFactory.hpp> #include <com/sun/star/lang/XSingleComponentFactory.hpp>
#include <comphelper/propertyvalue.hxx>
#include <rtl/ref.hxx> #include <rtl/ref.hxx>
using namespace com::sun::star; using namespace com::sun::star;
@@ -63,22 +65,15 @@ uno::Sequence< beans::PropertyValue > ScVbaCommandBarControls::CreateMenuItemDat
bool isVisible, bool isVisible,
bool isEnabled ) bool isEnabled )
{ {
uno::Sequence< beans::PropertyValue > aProps(7); uno::Sequence< beans::PropertyValue > aProps{
comphelper::makePropertyValue(ITEM_DESCRIPTOR_COMMANDURL, sCommandURL),
aProps[0].Name = ITEM_DESCRIPTOR_COMMANDURL; comphelper::makePropertyValue(ITEM_DESCRIPTOR_HELPURL, sHelpURL),
aProps[0].Value <<= sCommandURL; comphelper::makePropertyValue(ITEM_DESCRIPTOR_LABEL, sLabel),
aProps[1].Name = ITEM_DESCRIPTOR_HELPURL; comphelper::makePropertyValue(ITEM_DESCRIPTOR_TYPE, nType),
aProps[1].Value <<= sHelpURL; comphelper::makePropertyValue(ITEM_DESCRIPTOR_CONTAINER, aSubMenu),
aProps[2].Name = ITEM_DESCRIPTOR_LABEL; comphelper::makePropertyValue(ITEM_DESCRIPTOR_ISVISIBLE, isVisible),
aProps[2].Value <<= sLabel; comphelper::makePropertyValue(ITEM_DESCRIPTOR_ENABLED, isEnabled)
aProps[3].Name = ITEM_DESCRIPTOR_TYPE; };
aProps[3].Value <<= nType;
aProps[4].Name = ITEM_DESCRIPTOR_CONTAINER;
aProps[4].Value = aSubMenu;
aProps[5].Name = ITEM_DESCRIPTOR_ISVISIBLE;
aProps[5].Value <<= isVisible;
aProps[6].Name = ITEM_DESCRIPTOR_ENABLED;
aProps[6].Value <<= isEnabled;
return aProps; return aProps;
} }
@@ -91,22 +86,15 @@ uno::Sequence< beans::PropertyValue > ScVbaCommandBarControls::CreateToolbarItem
bool isVisible, bool isVisible,
sal_Int32 nStyle ) sal_Int32 nStyle )
{ {
uno::Sequence< beans::PropertyValue > aProps(7); uno::Sequence< beans::PropertyValue > aProps{
comphelper::makePropertyValue(ITEM_DESCRIPTOR_COMMANDURL, sCommandURL),
aProps[0].Name = ITEM_DESCRIPTOR_COMMANDURL; comphelper::makePropertyValue(ITEM_DESCRIPTOR_HELPURL, sHelpURL),
aProps[0].Value <<= sCommandURL; comphelper::makePropertyValue(ITEM_DESCRIPTOR_LABEL, sLabel),
aProps[1].Name = ITEM_DESCRIPTOR_HELPURL; comphelper::makePropertyValue(ITEM_DESCRIPTOR_TYPE, nType),
aProps[1].Value <<= sHelpURL; comphelper::makePropertyValue(ITEM_DESCRIPTOR_CONTAINER, aSubMenu),
aProps[2].Name = ITEM_DESCRIPTOR_LABEL; comphelper::makePropertyValue(ITEM_DESCRIPTOR_ISVISIBLE, isVisible),
aProps[2].Value <<= sLabel; comphelper::makePropertyValue(ITEM_DESCRIPTOR_STYLE, nStyle)
aProps[3].Name = ITEM_DESCRIPTOR_TYPE; };
aProps[3].Value <<= nType;
aProps[4].Name = ITEM_DESCRIPTOR_CONTAINER;
aProps[4].Value = aSubMenu;
aProps[5].Name = ITEM_DESCRIPTOR_ISVISIBLE;
aProps[5].Value <<= isVisible;
aProps[6].Name = ITEM_DESCRIPTOR_STYLE;
aProps[6].Value <<= nStyle;
return aProps; return aProps;
} }

View File

@@ -278,9 +278,8 @@ VbaDocumentBase::getVBProject()
{ {
uno::Reference< XApplicationBase > xApp( Application(), uno::UNO_QUERY_THROW ); uno::Reference< XApplicationBase > xApp( Application(), uno::UNO_QUERY_THROW );
uno::Reference< XInterface > xVBE( xApp->getVBE(), uno::UNO_QUERY_THROW ); uno::Reference< XInterface > xVBE( xApp->getVBE(), uno::UNO_QUERY_THROW );
uno::Sequence< uno::Any > aArgs( 2 ); uno::Sequence< uno::Any > aArgs{ uno::Any(xVBE), // the VBE
aArgs[ 0 ] <<= xVBE; // the VBE uno::Any(getModel()) }; // document model for script container access
aArgs[ 1 ] <<= getModel(); // document model for script container access
uno::Reference< lang::XMultiComponentFactory > xServiceManager( mxContext->getServiceManager(), uno::UNO_SET_THROW ); uno::Reference< lang::XMultiComponentFactory > xServiceManager( mxContext->getServiceManager(), uno::UNO_SET_THROW );
mxVBProject = xServiceManager->createInstanceWithArgumentsAndContext( mxVBProject = xServiceManager->createInstanceWithArgumentsAndContext(
"ooo.vba.vbide.VBProject", aArgs, mxContext ); "ooo.vba.vbide.VBProject", aArgs, mxContext );

View File

@@ -288,8 +288,9 @@ uno::Any VbaDocumentsBase::openDocument( const OUString& rFileName, const uno::A
uno::Sequence< beans::PropertyValue > sProps( rProps ); uno::Sequence< beans::PropertyValue > sProps( rProps );
sProps.realloc( sProps.getLength() + 1 ); sProps.realloc( sProps.getLength() + 1 );
sProps[ sProps.getLength() - 1 ].Name = "MacroExecutionMode"; auto pProps = sProps.getArray();
sProps[ sProps.getLength() - 1 ].Value <<= document::MacroExecMode::ALWAYS_EXECUTE_NO_WARN; pProps[ sProps.getLength() - 1 ].Name = "MacroExecutionMode";
pProps[ sProps.getLength() - 1 ].Value <<= document::MacroExecMode::ALWAYS_EXECUTE_NO_WARN;
if ( ReadOnly.hasValue() ) if ( ReadOnly.hasValue() )
{ {
@@ -298,8 +299,9 @@ uno::Any VbaDocumentsBase::openDocument( const OUString& rFileName, const uno::A
if ( bIsReadOnly ) if ( bIsReadOnly )
{ {
sProps.realloc( sProps.getLength() + 1 ); sProps.realloc( sProps.getLength() + 1 );
sProps[ sProps.getLength() - 1 ].Name = "ReadOnly"; pProps = sProps.getArray();
sProps[ sProps.getLength() - 1 ].Value <<= true; pProps[ sProps.getLength() - 1 ].Name = "ReadOnly";
pProps[ sProps.getLength() - 1 ].Value <<= true;
} }
} }

View File

@@ -107,7 +107,7 @@ sal_Bool SAL_CALL VbaEventsHelperBase::processVbaEvent( sal_Int32 nEventId, cons
{ {
if( rInfo.mnCancelIndex >= aVbaArgs.getLength() ) if( rInfo.mnCancelIndex >= aVbaArgs.getLength() )
throw lang::IllegalArgumentException(); throw lang::IllegalArgumentException();
aVbaArgs[ rInfo.mnCancelIndex ] <<= bCancel; aVbaArgs.getArray()[ rInfo.mnCancelIndex ] <<= bCancel;
} }
// execute the event handler // execute the event handler
uno::Any aRet, aCaller; uno::Any aRet, aCaller;

View File

@@ -752,8 +752,9 @@ void setOrAppendPropertyValue( uno::Sequence< beans::PropertyValue >& aProp, con
// append the property // append the property
sal_Int32 nLength = aProp.getLength(); sal_Int32 nLength = aProp.getLength();
aProp.realloc( nLength + 1 ); aProp.realloc( nLength + 1 );
aProp[ nLength ].Name = aName; auto pProp = aProp.getArray();
aProp[ nLength ].Value = aValue; pProp[ nLength ].Name = aName;
pProp[ nLength ].Value = aValue;
} }
// ====UserFormGeomentryHelper==== // ====UserFormGeomentryHelper====