summaryrefslogtreecommitdiff
path: root/vbahelper
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2020-08-02 20:08:42 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2020-08-03 09:22:08 +0200
commit5ec8d154bf0b01ee8f338b89eb5c1369b33b86da (patch)
treeb55e9c39c15fa1e08522c69d9239ef0fdbffd23c /vbahelper
parente865acdcc9321a08fac00bd1fb2c27a7580d3cec (diff)
loplugin:flatten in vbahelper
Change-Id: I05ecaf86cd92dd764a3c19a62ce911eef632a0b6 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/99967 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'vbahelper')
-rw-r--r--vbahelper/source/msforms/vbacombobox.cxx26
-rw-r--r--vbahelper/source/msforms/vbalistbox.cxx28
-rw-r--r--vbahelper/source/msforms/vbalistcontrolhelper.cxx90
-rw-r--r--vbahelper/source/msforms/vbauserform.cxx22
-rw-r--r--vbahelper/source/vbahelper/vbadocumentbase.cxx68
-rw-r--r--vbahelper/source/vbahelper/vbaeventshelperbase.cxx4
-rw-r--r--vbahelper/source/vbahelper/vbaglobalbase.cxx38
-rw-r--r--vbahelper/source/vbahelper/vbahelper.cxx20
8 files changed, 149 insertions, 147 deletions
diff --git a/vbahelper/source/msforms/vbacombobox.cxx b/vbahelper/source/msforms/vbacombobox.cxx
index 07c937ccbb05..dc10964bf3cf 100644
--- a/vbahelper/source/msforms/vbacombobox.cxx
+++ b/vbahelper/source/msforms/vbacombobox.cxx
@@ -66,21 +66,21 @@ void SAL_CALL
ScVbaComboBox::setListIndex( const uno::Any& _value )
{
sal_Int16 nIndex = 0;
- if( _value >>= nIndex )
+ if( !(_value >>= nIndex) )
+ return;
+
+ sal_Int32 nOldIndex = -1;
+ getListIndex() >>= nOldIndex;
+ uno::Sequence< OUString > sItems;
+ m_xProps->getPropertyValue( "StringItemList" ) >>= sItems;
+ if( ( nIndex >= 0 ) && ( sItems.getLength() > nIndex ) )
{
- sal_Int32 nOldIndex = -1;
- getListIndex() >>= nOldIndex;
- uno::Sequence< OUString > sItems;
- m_xProps->getPropertyValue( "StringItemList" ) >>= sItems;
- if( ( nIndex >= 0 ) && ( sItems.getLength() > nIndex ) )
- {
- OUString sText = sItems[ nIndex ];
- m_xProps->setPropertyValue( "Text", uno::makeAny( sText ) );
+ OUString sText = sItems[ nIndex ];
+ m_xProps->setPropertyValue( "Text", uno::makeAny( sText ) );
- // fire the _Change event
- if( nOldIndex != nIndex )
- fireClickEvent();
- }
+ // fire the _Change event
+ if( nOldIndex != nIndex )
+ fireClickEvent();
}
}
diff --git a/vbahelper/source/msforms/vbalistbox.cxx b/vbahelper/source/msforms/vbalistbox.cxx
index f4af24a5b34f..8c2ea52332db 100644
--- a/vbahelper/source/msforms/vbalistbox.cxx
+++ b/vbahelper/source/msforms/vbalistbox.cxx
@@ -200,22 +200,22 @@ ScVbaListBox::setValueEvent( const uno::Any& value )
return;
}
}
- if( bValue )
+ if( !bValue )
+ return;
+
+ if( getMultiSelect() )
{
- if( getMultiSelect() )
- {
- nList.realloc( nLength + 1 );
- nList[nLength] = nIndex;
- }
- else
- {
- nList.realloc( 1 );
- nList[0] = nIndex;
- }
- //m_xProps->setPropertyValue( sSourceName, uno::makeAny( nList ) );
- fireClickEvent();
- m_xProps->setPropertyValue( "SelectedItems", uno::makeAny( nList ) );
+ nList.realloc( nLength + 1 );
+ nList[nLength] = nIndex;
+ }
+ else
+ {
+ nList.realloc( 1 );
+ nList[0] = nIndex;
}
+ //m_xProps->setPropertyValue( sSourceName, uno::makeAny( nList ) );
+ fireClickEvent();
+ m_xProps->setPropertyValue( "SelectedItems", uno::makeAny( nList ) );
}
// this is called when something like the following vba code is used
diff --git a/vbahelper/source/msforms/vbalistcontrolhelper.cxx b/vbahelper/source/msforms/vbalistcontrolhelper.cxx
index 07187e56b621..58884dbf62fc 100644
--- a/vbahelper/source/msforms/vbalistcontrolhelper.cxx
+++ b/vbahelper/source/msforms/vbalistcontrolhelper.cxx
@@ -88,47 +88,47 @@ uno::Any ListPropListener::getValueEvent()
void
ListControlHelper::AddItem( const uno::Any& pvargItem, const uno::Any& pvargIndex )
{
- if ( pvargItem.hasValue() )
- {
- uno::Sequence< OUString > sList;
- m_xProps->getPropertyValue( "StringItemList" ) >>= sList;
+ if ( !pvargItem.hasValue() )
+ return;
- sal_Int32 nIndex = sList.getLength();
+ uno::Sequence< OUString > sList;
+ m_xProps->getPropertyValue( "StringItemList" ) >>= sList;
- if ( pvargIndex.hasValue() )
- pvargIndex >>= nIndex;
+ sal_Int32 nIndex = sList.getLength();
- OUString sString = getAnyAsString( pvargItem );
+ if ( pvargIndex.hasValue() )
+ pvargIndex >>= nIndex;
- // if no index specified or item is to be appended to end of
- // list just realloc the array and set the last item
- if ( nIndex == sList.getLength() )
- {
- sal_Int32 nOldSize = sList.getLength();
- sList.realloc( nOldSize + 1 );
- sList[ nOldSize ] = sString;
- }
- else
- {
- // just copy those elements above the one to be inserted
- std::vector< OUString > sVec;
- // reserve just the amount we need to copy
- sVec.reserve( sList.getLength() - nIndex + 1);
+ OUString sString = getAnyAsString( pvargItem );
- // insert the new element
- sVec.push_back( sString );
+ // if no index specified or item is to be appended to end of
+ // list just realloc the array and set the last item
+ if ( nIndex == sList.getLength() )
+ {
+ sal_Int32 nOldSize = sList.getLength();
+ sList.realloc( nOldSize + 1 );
+ sList[ nOldSize ] = sString;
+ }
+ else
+ {
+ // just copy those elements above the one to be inserted
+ std::vector< OUString > sVec;
+ // reserve just the amount we need to copy
+ sVec.reserve( sList.getLength() - nIndex + 1);
- // point at first element to copy
- sVec.insert( sVec.end(), std::next(sList.begin(), nIndex), sList.end() );
+ // insert the new element
+ sVec.push_back( sString );
- sList.realloc( sList.getLength() + 1 );
+ // point at first element to copy
+ sVec.insert( sVec.end(), std::next(sList.begin(), nIndex), sList.end() );
- // point at first element to be overwritten
- std::copy(sVec.begin(), sVec.end(), std::next(sList.begin(), nIndex));
- }
+ sList.realloc( sList.getLength() + 1 );
- m_xProps->setPropertyValue( "StringItemList", uno::makeAny( sList ) );
+ // point at first element to be overwritten
+ std::copy(sVec.begin(), sVec.end(), std::next(sList.begin(), nIndex));
}
+
+ m_xProps->setPropertyValue( "StringItemList", uno::makeAny( sList ) );
}
void
@@ -136,25 +136,25 @@ ListControlHelper::removeItem( const uno::Any& index )
{
sal_Int32 nIndex = 0;
// for int index
- if ( index >>= nIndex )
+ if ( !(index >>= nIndex) )
+ return;
+
+ uno::Sequence< OUString > sList;
+ m_xProps->getPropertyValue( "StringItemList" ) >>= sList;
+ if( nIndex < 0 || nIndex > ( sList.getLength() - 1 ) )
+ throw uno::RuntimeException( "Invalid index" , uno::Reference< uno::XInterface > () );
+ if( sList.hasElements() )
{
- uno::Sequence< OUString > sList;
- m_xProps->getPropertyValue( "StringItemList" ) >>= sList;
- if( nIndex < 0 || nIndex > ( sList.getLength() - 1 ) )
- throw uno::RuntimeException( "Invalid index" , uno::Reference< uno::XInterface > () );
- if( sList.hasElements() )
+ if( sList.getLength() == 1 )
{
- if( sList.getLength() == 1 )
- {
- Clear();
- return;
- }
-
- comphelper::removeElementAt(sList, nIndex);
+ Clear();
+ return;
}
- m_xProps->setPropertyValue( "StringItemList", uno::makeAny( sList ) );
+ comphelper::removeElementAt(sList, nIndex);
}
+
+ m_xProps->setPropertyValue( "StringItemList", uno::makeAny( sList ) );
}
void
diff --git a/vbahelper/source/msforms/vbauserform.cxx b/vbahelper/source/msforms/vbauserform.cxx
index a76f67543d61..8f3c158c4e5a 100644
--- a/vbahelper/source/msforms/vbauserform.cxx
+++ b/vbahelper/source/msforms/vbauserform.cxx
@@ -85,18 +85,18 @@ ScVbaUserForm::Show( )
aRet = m_xDialog->execute();
}
SAL_INFO("vbahelper", "ScVbaUserForm::Show() execute returned " << aRet);
- if ( mbDispose )
+ if ( !mbDispose )
+ return;
+
+ try
+ {
+ uno::Reference< lang::XComponent > xComp( m_xDialog, uno::UNO_QUERY_THROW );
+ m_xDialog = nullptr;
+ xComp->dispose();
+ mbDispose = false;
+ }
+ catch( uno::Exception& )
{
- try
- {
- uno::Reference< lang::XComponent > xComp( m_xDialog, uno::UNO_QUERY_THROW );
- m_xDialog = nullptr;
- xComp->dispose();
- mbDispose = false;
- }
- catch( uno::Exception& )
- {
- }
}
}
diff --git a/vbahelper/source/vbahelper/vbadocumentbase.cxx b/vbahelper/source/vbahelper/vbadocumentbase.cxx
index 58210a3358bf..bf199764b0c4 100644
--- a/vbahelper/source/vbahelper/vbadocumentbase.cxx
+++ b/vbahelper/source/vbahelper/vbadocumentbase.cxx
@@ -163,44 +163,44 @@ VbaDocumentBase::Close( const uno::Any &rSaveArg, const uno::Any &rFileArg,
{
}
- if ( !bUIClose )
+ if ( bUIClose )
+ return;
+
+ // if it is not possible to use UI dispatch, try to close the model directly
+ bool bCloseable = false;
+ uno::Reference< frame::XModel > xModel = getModel();
+ try
{
- // if it is not possible to use UI dispatch, try to close the model directly
- bool bCloseable = false;
- uno::Reference< frame::XModel > xModel = getModel();
- try
- {
- uno::Reference< util::XCloseable > xCloseable( xModel, uno::UNO_QUERY );
-
- // use close(boolean DeliverOwnership)
- // The boolean parameter DeliverOwnership tells objects vetoing the close
- // process that they may assume ownership if they object the closure by
- // throwing a CloseVetoException. Here we give up ownership. To be on the
- // safe side, catch possible veto exception anyway.
- if ( xCloseable.is() )
- {
- bCloseable = true;
- xCloseable->close(true);
- }
- }
- catch (const uno::Exception &)
- {
- // vetoed
- }
- if (!bCloseable)
+ uno::Reference< util::XCloseable > xCloseable( xModel, uno::UNO_QUERY );
+
+ // use close(boolean DeliverOwnership)
+ // The boolean parameter DeliverOwnership tells objects vetoing the close
+ // process that they may assume ownership if they object the closure by
+ // throwing a CloseVetoException. Here we give up ownership. To be on the
+ // safe side, catch possible veto exception anyway.
+ if ( xCloseable.is() )
{
- try {
- // If close is not supported by this model - try to dispose it.
- // But if the model disagree with a reset request for the modify state
- // we shouldn't do so. Otherwise some strange things can happen.
- uno::Reference< lang::XComponent > xDisposable ( xModel, uno::UNO_QUERY_THROW );
- xDisposable->dispose();
- }
- catch(const uno::Exception&)
- {
- }
+ bCloseable = true;
+ xCloseable->close(true);
}
}
+ catch (const uno::Exception &)
+ {
+ // vetoed
+ }
+ if (bCloseable)
+ return;
+
+ try {
+ // If close is not supported by this model - try to dispose it.
+ // But if the model disagree with a reset request for the modify state
+ // we shouldn't do so. Otherwise some strange things can happen.
+ uno::Reference< lang::XComponent > xDisposable ( xModel, uno::UNO_QUERY_THROW );
+ xDisposable->dispose();
+ }
+ catch(const uno::Exception&)
+ {
+ }
}
void
diff --git a/vbahelper/source/vbahelper/vbaeventshelperbase.cxx b/vbahelper/source/vbahelper/vbaeventshelperbase.cxx
index 83b047ea836c..1396c93cd616 100644
--- a/vbahelper/source/vbahelper/vbaeventshelperbase.cxx
+++ b/vbahelper/source/vbahelper/vbaeventshelperbase.cxx
@@ -289,7 +289,9 @@ OUString VbaEventsHelperBase::getEventHandlerPath( const EventHandlerInfo& rInfo
void VbaEventsHelperBase::ensureVBALibrary()
{
- if( !mxModuleInfos.is() ) try
+ if( mxModuleInfos.is() ) return;
+
+ try
{
maLibraryName = getDefaultProjectName( mpShell );
if( maLibraryName.isEmpty() )
diff --git a/vbahelper/source/vbahelper/vbaglobalbase.cxx b/vbahelper/source/vbahelper/vbaglobalbase.cxx
index ba7e6425106e..2648d6f58369 100644
--- a/vbahelper/source/vbahelper/vbaglobalbase.cxx
+++ b/vbahelper/source/vbahelper/vbaglobalbase.cxx
@@ -60,26 +60,26 @@ const uno::Reference< uno::XComponentContext >& xContext, const OUString& sDocCt
mxContext = ::cppu::createComponentContext(
aHandlerContextInfo,
SAL_N_ELEMENTS( aHandlerContextInfo ), nullptr );
- if ( aSrvMgr.is() )
+ if ( !aSrvMgr.is() )
+ return;
+
+ try
{
- try
- {
- uno::Reference< beans::XPropertySet >(
- aSrvMgr, uno::UNO_QUERY_THROW )->
- setPropertyValue( "DefaultContext", uno::makeAny( mxContext ) );
- }
- catch ( uno::RuntimeException & )
- {
- throw;
- }
- catch ( uno::Exception & )
- {
- uno::Any e(cppu::getCaughtException());
- throw lang::WrappedTargetRuntimeException(
- ("VbaGlobalsBase ctor, setting OServiceManagerWrapper"
- " DefaultContext failed"),
- uno::Reference< uno::XInterface >(), e);
- }
+ uno::Reference< beans::XPropertySet >(
+ aSrvMgr, uno::UNO_QUERY_THROW )->
+ setPropertyValue( "DefaultContext", uno::makeAny( mxContext ) );
+ }
+ catch ( uno::RuntimeException & )
+ {
+ throw;
+ }
+ catch ( uno::Exception & )
+ {
+ uno::Any e(cppu::getCaughtException());
+ throw lang::WrappedTargetRuntimeException(
+ ("VbaGlobalsBase ctor, setting OServiceManagerWrapper"
+ " DefaultContext failed"),
+ uno::Reference< uno::XInterface >(), e);
}
}
diff --git a/vbahelper/source/vbahelper/vbahelper.cxx b/vbahelper/source/vbahelper/vbahelper.cxx
index 7071a1b90b37..e7dafba16ffc 100644
--- a/vbahelper/source/vbahelper/vbahelper.cxx
+++ b/vbahelper/source/vbahelper/vbahelper.cxx
@@ -392,21 +392,21 @@ void PrintOutHelper( SfxViewShell const * pViewShell, const uno::Any& From, cons
aArgs.Put( sfxAsync, sfxAsync.Which() );
SfxDispatcher* pDispatcher = pViewFrame->GetDispatcher();
- if ( pDispatcher )
+ if ( !pDispatcher )
+ return;
+
+ if ( bPreview )
{
- if ( bPreview )
+ if ( !pViewFrame->GetFrame().IsInPlace() )
{
- if ( !pViewFrame->GetFrame().IsInPlace() )
- {
- // #TODO is this necessary ( calc specific )
+ // #TODO is this necessary ( calc specific )
// SC_MOD()->InputEnterHandler();
- pViewFrame->GetDispatcher()->Execute( SID_VIEWSHELL1, SfxCallMode::SYNCHRON );
- WaitUntilPreviewIsClosed( pViewFrame );
- }
+ pViewFrame->GetDispatcher()->Execute( SID_VIEWSHELL1, SfxCallMode::SYNCHRON );
+ WaitUntilPreviewIsClosed( pViewFrame );
}
- else
- pDispatcher->Execute( sal_uInt16(SID_PRINTDOC), SfxCallMode::SYNCHRON, aArgs );
}
+ else
+ pDispatcher->Execute( sal_uInt16(SID_PRINTDOC), SfxCallMode::SYNCHRON, aArgs );
// #FIXME #TODO