From 467724410dc470ec259131f97abd836fe9b021a1 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Tue, 26 Sep 2017 12:01:53 +0200 Subject: loplugin:flatten in toolkit..vbahelper Change-Id: I6d4be3e1cc29b2b91d5c39b757ff3b903c47112d Reviewed-on: https://gerrit.libreoffice.org/42794 Tested-by: Jenkins Reviewed-by: Noel Grandin --- vbahelper/source/msforms/vbacontrols.cxx | 22 ++++++------ vbahelper/source/vbahelper/vbaapplicationbase.cxx | 40 ++++++++++------------ .../source/vbahelper/vbacommandbarcontrols.cxx | 8 ++--- vbahelper/source/vbahelper/vbacommandbars.cxx | 30 ++++++++-------- vbahelper/source/vbahelper/vbahelper.cxx | 6 ++-- 5 files changed, 49 insertions(+), 57 deletions(-) (limited to 'vbahelper/source') diff --git a/vbahelper/source/msforms/vbacontrols.cxx b/vbahelper/source/msforms/vbacontrols.cxx index 2bf5e9adfb2a..3bf6a5549f29 100644 --- a/vbahelper/source/msforms/vbacontrols.cxx +++ b/vbahelper/source/msforms/vbacontrols.cxx @@ -408,19 +408,17 @@ uno::Any SAL_CALL ScVbaControls::Add( const uno::Any& Object, const uno::Any& St } } - if ( xNewControl.is() ) - { - UpdateCollectionIndex( lcl_controlsWrapper( mxDialog ) ); - aResult <<= xNewControl; - aResult = createCollectionObject( aResult ); - uno::Reference< msforms::XControl > xVBAControl( aResult, uno::UNO_QUERY_THROW ); - if( fDefWidth > 0.0 ) - xVBAControl->setWidth( fDefWidth ); - if( fDefHeight > 0.0 ) - xVBAControl->setHeight( fDefHeight ); - } - else + if ( !xNewControl.is() ) throw uno::RuntimeException(); + + UpdateCollectionIndex( lcl_controlsWrapper( mxDialog ) ); + aResult <<= xNewControl; + aResult = createCollectionObject( aResult ); + uno::Reference< msforms::XControl > xVBAControl( aResult, uno::UNO_QUERY_THROW ); + if( fDefWidth > 0.0 ) + xVBAControl->setWidth( fDefWidth ); + if( fDefHeight > 0.0 ) + xVBAControl->setHeight( fDefHeight ); } catch (const uno::RuntimeException&) { diff --git a/vbahelper/source/vbahelper/vbaapplicationbase.cxx b/vbahelper/source/vbahelper/vbaapplicationbase.cxx index da33cbcaf673..b3a53214295e 100644 --- a/vbahelper/source/vbahelper/vbaapplicationbase.cxx +++ b/vbahelper/source/vbahelper/vbaapplicationbase.cxx @@ -319,35 +319,33 @@ uno::Any SAL_CALL VbaApplicationBase::Run( const OUString& MacroName, const uno: xModel = getCurrentDocument(); MacroResolvedInfo aMacroInfo = resolveVBAMacro( getSfxObjShell( xModel ), aMacroName ); - if( aMacroInfo.mbFound ) + if( !aMacroInfo.mbFound ) { - // handle the arguments - const uno::Any* aArgsPtrArray[] = { &varg1, &varg2, &varg3, &varg4, &varg5, &varg6, &varg7, &varg8, &varg9, &varg10, &varg11, &varg12, &varg13, &varg14, &varg15, &varg16, &varg17, &varg18, &varg19, &varg20, &varg21, &varg22, &varg23, &varg24, &varg25, &varg26, &varg27, &varg28, &varg29, &varg30 }; + throw uno::RuntimeException( "The macro doesn't exist" ); + } - int nArg = SAL_N_ELEMENTS( aArgsPtrArray ); - uno::Sequence< uno::Any > aArgs( nArg ); + // handle the arguments + const uno::Any* aArgsPtrArray[] = { &varg1, &varg2, &varg3, &varg4, &varg5, &varg6, &varg7, &varg8, &varg9, &varg10, &varg11, &varg12, &varg13, &varg14, &varg15, &varg16, &varg17, &varg18, &varg19, &varg20, &varg21, &varg22, &varg23, &varg24, &varg25, &varg26, &varg27, &varg28, &varg29, &varg30 }; - const uno::Any** pArg = aArgsPtrArray; - const uno::Any** pArgEnd = ( aArgsPtrArray + nArg ); + int nArg = SAL_N_ELEMENTS( aArgsPtrArray ); + uno::Sequence< uno::Any > aArgs( nArg ); - sal_Int32 nArgProcessed = 0; + const uno::Any** pArg = aArgsPtrArray; + const uno::Any** pArgEnd = ( aArgsPtrArray + nArg ); - for ( ; pArg != pArgEnd; ++pArg, ++nArgProcessed ) - aArgs[ nArgProcessed ] = **pArg; + sal_Int32 nArgProcessed = 0; - // resize array to position of last param with value - aArgs.realloc( nArgProcessed + 1 ); + for ( ; pArg != pArgEnd; ++pArg, ++nArgProcessed ) + aArgs[ nArgProcessed ] = **pArg; - uno::Any aRet; - uno::Any aDummyCaller; - executeMacro( aMacroInfo.mpDocContext, aMacroInfo.msResolvedMacro, aArgs, aRet, aDummyCaller ); + // resize array to position of last param with value + aArgs.realloc( nArgProcessed + 1 ); - return aRet; - } - else - { - throw uno::RuntimeException( "The macro doesn't exist" ); - } + uno::Any aRet; + uno::Any aDummyCaller; + executeMacro( aMacroInfo.mpDocContext, aMacroInfo.msResolvedMacro, aArgs, aRet, aDummyCaller ); + + return aRet; } void SAL_CALL VbaApplicationBase::OnTime( const uno::Any& aEarliestTime, const OUString& aFunction, const uno::Any& aLatestTime, const uno::Any& aSchedule ) diff --git a/vbahelper/source/vbahelper/vbacommandbarcontrols.cxx b/vbahelper/source/vbahelper/vbacommandbarcontrols.cxx index 915913586798..cded9f7c309e 100644 --- a/vbahelper/source/vbahelper/vbacommandbarcontrols.cxx +++ b/vbahelper/source/vbahelper/vbacommandbarcontrols.cxx @@ -38,12 +38,10 @@ public: } virtual uno::Any SAL_CALL nextElement() override { - if( hasMoreElements() ) - { - return m_pCommandBarControls->createCollectionObject( uno::makeAny( m_nCurrentPosition++ ) ); - } - else + if( !hasMoreElements() ) throw container::NoSuchElementException(); + + return m_pCommandBarControls->createCollectionObject( uno::makeAny( m_nCurrentPosition++ ) ); } }; diff --git a/vbahelper/source/vbahelper/vbacommandbars.cxx b/vbahelper/source/vbahelper/vbacommandbars.cxx index 27340c9e4873..dfd0f2fa565e 100644 --- a/vbahelper/source/vbahelper/vbacommandbars.cxx +++ b/vbahelper/source/vbahelper/vbacommandbars.cxx @@ -55,23 +55,21 @@ public: virtual uno::Any SAL_CALL nextElement() override { // FIXME: should be add menubar - if( hasMoreElements() ) - { - OUString sResourceUrl( m_sNames[ m_nCurrentPosition++ ] ); - if( sResourceUrl.indexOf( "private:resource/toolbar/" ) != -1 ) - { - uno::Reference< container::XIndexAccess > xCBarSetting = m_pCBarHelper->getSettings( sResourceUrl ); - uno::Reference< XCommandBar > xCommandBar( new ScVbaCommandBar( m_xParent, m_xContext, m_pCBarHelper, xCBarSetting, sResourceUrl, false ) ); - // Strange, shouldn't the Enumeration support match/share the - // iteration code? ( e.g. ScVbaCommandBars::Item(...) ) - // and we at least should return here ( something ) it seems - return uno::makeAny( xCommandBar ); - } - else - return nextElement(); - } - else + if( !hasMoreElements() ) throw container::NoSuchElementException(); + + OUString sResourceUrl( m_sNames[ m_nCurrentPosition++ ] ); + if( sResourceUrl.indexOf( "private:resource/toolbar/" ) != -1 ) + { + uno::Reference< container::XIndexAccess > xCBarSetting = m_pCBarHelper->getSettings( sResourceUrl ); + uno::Reference< XCommandBar > xCommandBar( new ScVbaCommandBar( m_xParent, m_xContext, m_pCBarHelper, xCBarSetting, sResourceUrl, false ) ); + // Strange, shouldn't the Enumeration support match/share the + // iteration code? ( e.g. ScVbaCommandBars::Item(...) ) + // and we at least should return here ( something ) it seems + return uno::makeAny( xCommandBar ); + } + else + return nextElement(); } }; diff --git a/vbahelper/source/vbahelper/vbahelper.cxx b/vbahelper/source/vbahelper/vbahelper.cxx index e313088635e2..ff0c5f591cba 100644 --- a/vbahelper/source/vbahelper/vbahelper.cxx +++ b/vbahelper/source/vbahelper/vbahelper.cxx @@ -741,10 +741,10 @@ void setDefaultPropByIntrospection( const uno::Any& aObj, const uno::Any& aValue if ( xUnoAccess.is() ) xPropSet.set( xUnoAccess->queryAdapter( cppu::UnoType::get()), uno::UNO_QUERY); - if ( xPropSet.is() ) - xPropSet->setPropertyValue( xDflt->getDefaultPropertyName(), aValue ); - else + if ( !xPropSet.is() ) throw uno::RuntimeException(); + + xPropSet->setPropertyValue( xDflt->getDefaultPropertyName(), aValue ); } uno::Any getPropertyValue( const uno::Sequence< beans::PropertyValue >& aProp, const OUString& aName ) -- cgit