diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-08-09 11:55:27 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-08-09 19:05:46 +0200 |
commit | a7c8c5f49af7ad8c1101a4c73dbe7a83b7ba8cb5 (patch) | |
tree | 90d160a8a62ca714bcaff71d6d6c9285828f9a2f /sc | |
parent | 8c505204f25b509daa586c2d308fb870325c59b9 (diff) |
loplugin:flatten in sc/ui/vba
Change-Id: I9015274bdc71baac2bbef9d34e3d69557533d92e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/100399
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sc')
-rw-r--r-- | sc/source/ui/vba/excelvbahelper.cxx | 200 | ||||
-rw-r--r-- | sc/source/ui/vba/vbaapplication.cxx | 66 | ||||
-rw-r--r-- | sc/source/ui/vba/vbaaxes.cxx | 40 | ||||
-rw-r--r-- | sc/source/ui/vba/vbaeventshelper.cxx | 28 | ||||
-rw-r--r-- | sc/source/ui/vba/vbaname.cxx | 21 | ||||
-rw-r--r-- | sc/source/ui/vba/vbarange.cxx | 208 | ||||
-rw-r--r-- | sc/source/ui/vba/vbasheetobject.cxx | 26 | ||||
-rw-r--r-- | sc/source/ui/vba/vbaworksheet.cxx | 56 | ||||
-rw-r--r-- | sc/source/ui/vba/vbaworksheets.cxx | 72 |
9 files changed, 358 insertions, 359 deletions
diff --git a/sc/source/ui/vba/excelvbahelper.cxx b/sc/source/ui/vba/excelvbahelper.cxx index f251517cf415..db12c6bab9ca 100644 --- a/sc/source/ui/vba/excelvbahelper.cxx +++ b/sc/source/ui/vba/excelvbahelper.cxx @@ -173,18 +173,18 @@ implnCopy( const uno::Reference< frame::XModel>& xModel ) { ScTabViewShell* pViewShell = getBestViewShell( xModel ); ScDocShell* pDocShell = getDocShell( xModel ); - if ( pViewShell && pDocShell ) - { - pViewShell->CopyToClip(nullptr,false,false,true); + if ( !(pViewShell && pDocShell) ) + return; - // mark the copied transfer object so it is used in ScVbaRange::Insert - uno::Reference<datatransfer::XTransferable2> xTransferable(ScTabViewShell::GetClipData(pViewShell->GetViewData().GetActiveWin())); - ScTransferObj* pClipObj = ScTransferObj::GetOwnClipboard(xTransferable); - if (pClipObj) - { - pClipObj->SetUseInApi( true ); - pDocShell->SetClipData(xTransferable); - } + pViewShell->CopyToClip(nullptr,false,false,true); + + // mark the copied transfer object so it is used in ScVbaRange::Insert + uno::Reference<datatransfer::XTransferable2> xTransferable(ScTabViewShell::GetClipData(pViewShell->GetViewData().GetActiveWin())); + ScTransferObj* pClipObj = ScTransferObj::GetOwnClipboard(xTransferable); + if (pClipObj) + { + pClipObj->SetUseInApi( true ); + pDocShell->SetClipData(xTransferable); } } @@ -193,18 +193,18 @@ implnCut( const uno::Reference< frame::XModel>& xModel ) { ScTabViewShell* pViewShell = getBestViewShell( xModel ); ScDocShell* pDocShell = getDocShell( xModel ); - if ( pViewShell && pDocShell ) - { - pViewShell->CutToClip(); + if ( !(pViewShell && pDocShell) ) + return; - // mark the copied transfer object so it is used in ScVbaRange::Insert - uno::Reference<datatransfer::XTransferable2> xTransferable(ScTabViewShell::GetClipData(pViewShell->GetViewData().GetActiveWin())); - ScTransferObj* pClipObj = ScTransferObj::GetOwnClipboard(xTransferable); - if (pClipObj) - { - pClipObj->SetUseInApi( true ); - pDocShell->SetClipData(xTransferable); - } + pViewShell->CutToClip(); + + // mark the copied transfer object so it is used in ScVbaRange::Insert + uno::Reference<datatransfer::XTransferable2> xTransferable(ScTabViewShell::GetClipData(pViewShell->GetViewData().GetActiveWin())); + ScTransferObj* pClipObj = ScTransferObj::GetOwnClipboard(xTransferable); + if (pClipObj) + { + pClipObj->SetUseInApi( true ); + pDocShell->SetClipData(xTransferable); } } @@ -214,21 +214,21 @@ void implnPasteSpecial( const uno::Reference< frame::XModel>& xModel, InsertDele ScTabViewShell* pTabViewShell = getBestViewShell( xModel ); ScDocShell* pDocShell = getDocShell( xModel ); - if ( pTabViewShell && pDocShell ) + if ( !(pTabViewShell && pDocShell) ) + return; + + ScViewData& rView = pTabViewShell->GetViewData(); + vcl::Window* pWin = rView.GetActiveWin(); + if (pWin) { - ScViewData& rView = pTabViewShell->GetViewData(); - vcl::Window* pWin = rView.GetActiveWin(); - if (pWin) - { - const ScTransferObj* pOwnClip = ScTransferObj::GetOwnClipboard(pDocShell->GetClipData()); - ScDocument* pDoc = nullptr; - if ( pOwnClip ) - pDoc = pOwnClip->GetDocument(); - pTabViewShell->PasteFromClip( nFlags, pDoc, - nFunction, bSkipEmpty, bTranspose, false, - INS_NONE, InsertDeleteFlags::NONE, true ); - pTabViewShell->CellContentChanged(); - } + const ScTransferObj* pOwnClip = ScTransferObj::GetOwnClipboard(pDocShell->GetClipData()); + ScDocument* pDoc = nullptr; + if ( pOwnClip ) + pDoc = pOwnClip->GetDocument(); + pTabViewShell->PasteFromClip( nFlags, pDoc, + nFunction, bSkipEmpty, bTranspose, false, + INS_NONE, InsertDeleteFlags::NONE, true ); + pTabViewShell->CellContentChanged(); } } @@ -314,78 +314,78 @@ void setUpDocumentModules( const uno::Reference< sheet::XSpreadsheetDocument >& { uno::Reference< frame::XModel > xModel( xDoc, uno::UNO_QUERY ); ScDocShell* pShell = excel::getDocShell( xModel ); - if ( pShell ) - { - OUString aPrjName( "Standard" ); - pShell->GetBasicManager()->SetName( aPrjName ); + if ( !pShell ) + return; + + OUString aPrjName( "Standard" ); + pShell->GetBasicManager()->SetName( aPrjName ); - /* Set library container to VBA compatibility mode. This will create - the VBA Globals object and store it in the Basic manager of the - document. */ - uno::Reference<script::XLibraryContainer> xLibContainer = pShell->GetBasicContainer(); - uno::Reference<script::vba::XVBACompatibility> xVBACompat( xLibContainer, uno::UNO_QUERY_THROW ); - xVBACompat->setVBACompatibilityMode( true ); + /* Set library container to VBA compatibility mode. This will create + the VBA Globals object and store it in the Basic manager of the + document. */ + uno::Reference<script::XLibraryContainer> xLibContainer = pShell->GetBasicContainer(); + uno::Reference<script::vba::XVBACompatibility> xVBACompat( xLibContainer, uno::UNO_QUERY_THROW ); + xVBACompat->setVBACompatibilityMode( true ); - if( xLibContainer.is() ) + if( xLibContainer.is() ) + { + if( !xLibContainer->hasByName( aPrjName ) ) + xLibContainer->createLibrary( aPrjName ); + uno::Any aLibAny = xLibContainer->getByName( aPrjName ); + uno::Reference< container::XNameContainer > xLib; + aLibAny >>= xLib; + if( xLib.is() ) { - if( !xLibContainer->hasByName( aPrjName ) ) - xLibContainer->createLibrary( aPrjName ); - uno::Any aLibAny = xLibContainer->getByName( aPrjName ); - uno::Reference< container::XNameContainer > xLib; - aLibAny >>= xLib; - if( xLib.is() ) + uno::Reference< script::vba::XVBAModuleInfo > xVBAModuleInfo( xLib, uno::UNO_QUERY_THROW ); + uno::Reference< lang::XMultiServiceFactory> xSF( pShell->GetModel(), uno::UNO_QUERY_THROW); + uno::Reference< container::XNameAccess > xVBACodeNamedObjectAccess( xSF->createInstance("ooo.vba.VBAObjectModuleObjectProvider"), uno::UNO_QUERY_THROW ); + // set up the module info for the workbook and sheets in the newly created + // spreadsheet + ScDocument& rDoc = pShell->GetDocument(); + OUString sCodeName = rDoc.GetCodeName(); + if ( sCodeName.isEmpty() ) { - uno::Reference< script::vba::XVBAModuleInfo > xVBAModuleInfo( xLib, uno::UNO_QUERY_THROW ); - uno::Reference< lang::XMultiServiceFactory> xSF( pShell->GetModel(), uno::UNO_QUERY_THROW); - uno::Reference< container::XNameAccess > xVBACodeNamedObjectAccess( xSF->createInstance("ooo.vba.VBAObjectModuleObjectProvider"), uno::UNO_QUERY_THROW ); - // set up the module info for the workbook and sheets in the newly created - // spreadsheet - ScDocument& rDoc = pShell->GetDocument(); - OUString sCodeName = rDoc.GetCodeName(); - if ( sCodeName.isEmpty() ) - { - sCodeName = "ThisWorkbook"; - rDoc.SetCodeName( sCodeName ); - } - - std::vector< OUString > sDocModuleNames; - sDocModuleNames.push_back( sCodeName ); - - for ( SCTAB index = 0; index < rDoc.GetTableCount(); index++) - { - OUString aName; - rDoc.GetCodeName( index, aName ); - sDocModuleNames.push_back( aName ); - } - - for ( const auto& rName : sDocModuleNames ) - { - script::ModuleInfo sModuleInfo; - - uno::Any aName= xVBACodeNamedObjectAccess->getByName( rName ); - sModuleInfo.ModuleObject.set( aName, uno::UNO_QUERY ); - sModuleInfo.ModuleType = script::ModuleType::DOCUMENT; - xVBAModuleInfo->insertModuleInfo( rName, sModuleInfo ); - if( xLib->hasByName( rName ) ) - xLib->replaceByName( rName, uno::makeAny( OUString( "Option VBASupport 1\n") ) ); - else - xLib->insertByName( rName, uno::makeAny( OUString( "Option VBASupport 1\n" ) ) ); - } + sCodeName = "ThisWorkbook"; + rDoc.SetCodeName( sCodeName ); } - } - /* Trigger the Workbook_Open event, event processor will register - itself as listener for specific events. */ - try - { - uno::Reference< script::vba::XVBAEventProcessor > xVbaEvents( pShell->GetDocument().GetVbaEventProcessor(), uno::UNO_SET_THROW ); - uno::Sequence< uno::Any > aArgs; - xVbaEvents->processVbaEvent( script::vba::VBAEventId::WORKBOOK_OPEN, aArgs ); - } - catch( uno::Exception& ) - { + std::vector< OUString > sDocModuleNames; + sDocModuleNames.push_back( sCodeName ); + + for ( SCTAB index = 0; index < rDoc.GetTableCount(); index++) + { + OUString aName; + rDoc.GetCodeName( index, aName ); + sDocModuleNames.push_back( aName ); + } + + for ( const auto& rName : sDocModuleNames ) + { + script::ModuleInfo sModuleInfo; + + uno::Any aName= xVBACodeNamedObjectAccess->getByName( rName ); + sModuleInfo.ModuleObject.set( aName, uno::UNO_QUERY ); + sModuleInfo.ModuleType = script::ModuleType::DOCUMENT; + xVBAModuleInfo->insertModuleInfo( rName, sModuleInfo ); + if( xLib->hasByName( rName ) ) + xLib->replaceByName( rName, uno::makeAny( OUString( "Option VBASupport 1\n") ) ); + else + xLib->insertByName( rName, uno::makeAny( OUString( "Option VBASupport 1\n" ) ) ); + } } } + + /* Trigger the Workbook_Open event, event processor will register + itself as listener for specific events. */ + try + { + uno::Reference< script::vba::XVBAEventProcessor > xVbaEvents( pShell->GetDocument().GetVbaEventProcessor(), uno::UNO_SET_THROW ); + uno::Sequence< uno::Any > aArgs; + xVbaEvents->processVbaEvent( script::vba::VBAEventId::WORKBOOK_OPEN, aArgs ); + } + catch( uno::Exception& ) + { + } } SfxItemSet* diff --git a/sc/source/ui/vba/vbaapplication.cxx b/sc/source/ui/vba/vbaapplication.cxx index af9af62e5d3d..c4cac4b68471 100644 --- a/sc/source/ui/vba/vbaapplication.cxx +++ b/sc/source/ui/vba/vbaapplication.cxx @@ -995,18 +995,18 @@ typedef ::std::list< ScRange > ListOfScRange; */ void lclAddToListOfScRange( ListOfScRange& rList, const uno::Any& rArg ) { - if( rArg.hasValue() ) + if( !rArg.hasValue() ) + return; + + uno::Reference< excel::XRange > xRange( rArg, uno::UNO_QUERY_THROW ); + uno::Reference< XCollection > xCol( xRange->Areas( uno::Any() ), uno::UNO_QUERY_THROW ); + for( sal_Int32 nIdx = 1, nCount = xCol->getCount(); nIdx <= nCount; ++nIdx ) { - uno::Reference< excel::XRange > xRange( rArg, uno::UNO_QUERY_THROW ); - uno::Reference< XCollection > xCol( xRange->Areas( uno::Any() ), uno::UNO_QUERY_THROW ); - for( sal_Int32 nIdx = 1, nCount = xCol->getCount(); nIdx <= nCount; ++nIdx ) - { - uno::Reference< excel::XRange > xAreaRange( xCol->Item( uno::Any( nIdx ), uno::Any() ), uno::UNO_QUERY_THROW ); - uno::Reference< sheet::XCellRangeAddressable > xAddressable( xAreaRange->getCellRange(), uno::UNO_QUERY_THROW ); - ScRange aScRange; - ScUnoConversion::FillScRange( aScRange, xAddressable->getRangeAddress() ); - rList.push_back( aScRange ); - } + uno::Reference< excel::XRange > xAreaRange( xCol->Item( uno::Any( nIdx ), uno::Any() ), uno::UNO_QUERY_THROW ); + uno::Reference< sheet::XCellRangeAddressable > xAddressable( xAreaRange->getCellRange(), uno::UNO_QUERY_THROW ); + ScRange aScRange; + ScUnoConversion::FillScRange( aScRange, xAddressable->getRangeAddress() ); + rList.push_back( aScRange ); } } @@ -1105,34 +1105,34 @@ void lclIntersectRanges( ListOfScRange& rList, const uno::Any& rArg ) ListOfScRange aList2; lclAddToListOfScRange( aList2, rArg ); // do nothing, if the passed list is already empty - if( !rList.empty() && !aList2.empty() ) + if( rList.empty() || aList2.empty() ) + return; + + // save original list in a local + ListOfScRange aList1; + aList1.swap( rList ); + // join ranges from passed argument + lclJoinRanges( aList2 ); + // calculate intersection of the ranges in both lists + for( const auto& rOuterItem : aList1 ) { - // save original list in a local - ListOfScRange aList1; - aList1.swap( rList ); - // join ranges from passed argument - lclJoinRanges( aList2 ); - // calculate intersection of the ranges in both lists - for( const auto& rOuterItem : aList1 ) + for( const auto& rInnerItem : aList2 ) { - for( const auto& rInnerItem : aList2 ) + if( rOuterItem.Intersects( rInnerItem ) ) { - if( rOuterItem.Intersects( rInnerItem ) ) - { - ScRange aIsectRange( - std::max( rOuterItem.aStart.Col(), rInnerItem.aStart.Col() ), - std::max( rOuterItem.aStart.Row(), rInnerItem.aStart.Row() ), - std::max( rOuterItem.aStart.Tab(), rInnerItem.aStart.Tab() ), - std::min( rOuterItem.aEnd.Col(), rInnerItem.aEnd.Col() ), - std::min( rOuterItem.aEnd.Row(), rInnerItem.aEnd.Row() ), - std::min( rOuterItem.aEnd.Tab(), rInnerItem.aEnd.Tab() ) ); - rList.push_back( aIsectRange ); - } + ScRange aIsectRange( + std::max( rOuterItem.aStart.Col(), rInnerItem.aStart.Col() ), + std::max( rOuterItem.aStart.Row(), rInnerItem.aStart.Row() ), + std::max( rOuterItem.aStart.Tab(), rInnerItem.aStart.Tab() ), + std::min( rOuterItem.aEnd.Col(), rInnerItem.aEnd.Col() ), + std::min( rOuterItem.aEnd.Row(), rInnerItem.aEnd.Row() ), + std::min( rOuterItem.aEnd.Tab(), rInnerItem.aEnd.Tab() ) ); + rList.push_back( aIsectRange ); } } - // again, join the result ranges - lclJoinRanges( rList ); } + // again, join the result ranges + lclJoinRanges( rList ); } /** Creates a VBA Range object from the passed list of ranges. diff --git a/sc/source/ui/vba/vbaaxes.cxx b/sc/source/ui/vba/vbaaxes.cxx index 6a750f7656b6..61d09208751e 100644 --- a/sc/source/ui/vba/vbaaxes.cxx +++ b/sc/source/ui/vba/vbaaxes.cxx @@ -95,26 +95,26 @@ class AxisIndexWrapper : public ::cppu::WeakImplHelper< container::XIndexAccess public: AxisIndexWrapper( const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< excel::XChart >& xChart ) : mxContext( xContext ), mxChart( xChart ) { - if ( mxChart.is() ) - { - ScVbaChart* pChart = static_cast< ScVbaChart* >( mxChart.get() ); - // primary - bool bBool = false; - uno::Reference< beans::XPropertySet > xDiagramPropertySet( pChart->xDiagramPropertySet() ); - if ( ( xDiagramPropertySet->getPropertyValue("HasXAxis") >>= bBool ) && bBool ) - mCoordinates.emplace_back( xlPrimary, xlCategory ); - if ( ( xDiagramPropertySet->getPropertyValue("HasYAxis") >>= bBool ) && bBool ) - mCoordinates.emplace_back( xlPrimary, xlSeriesAxis ); - - if ( pChart->is3D() ) - mCoordinates.emplace_back( xlPrimary, xlValue ); - - // secondary - if ( ( xDiagramPropertySet->getPropertyValue("HasSecondaryXAxis") >>= bBool ) && bBool ) - mCoordinates.emplace_back( xlSecondary, xlCategory ); - if ( ( xDiagramPropertySet->getPropertyValue("HasSecondaryYAxis") >>= bBool ) && bBool ) - mCoordinates.emplace_back( xlSecondary, xlSeriesAxis ); - } + if ( !mxChart.is() ) + return; + + ScVbaChart* pChart = static_cast< ScVbaChart* >( mxChart.get() ); + // primary + bool bBool = false; + uno::Reference< beans::XPropertySet > xDiagramPropertySet( pChart->xDiagramPropertySet() ); + if ( ( xDiagramPropertySet->getPropertyValue("HasXAxis") >>= bBool ) && bBool ) + mCoordinates.emplace_back( xlPrimary, xlCategory ); + if ( ( xDiagramPropertySet->getPropertyValue("HasYAxis") >>= bBool ) && bBool ) + mCoordinates.emplace_back( xlPrimary, xlSeriesAxis ); + + if ( pChart->is3D() ) + mCoordinates.emplace_back( xlPrimary, xlValue ); + + // secondary + if ( ( xDiagramPropertySet->getPropertyValue("HasSecondaryXAxis") >>= bBool ) && bBool ) + mCoordinates.emplace_back( xlSecondary, xlCategory ); + if ( ( xDiagramPropertySet->getPropertyValue("HasSecondaryYAxis") >>= bBool ) && bBool ) + mCoordinates.emplace_back( xlSecondary, xlSeriesAxis ); } virtual ::sal_Int32 SAL_CALL getCount() override { return mCoordinates.size(); } diff --git a/sc/source/ui/vba/vbaeventshelper.cxx b/sc/source/ui/vba/vbaeventshelper.cxx index 51e2d9edd728..536423a957ca 100644 --- a/sc/source/ui/vba/vbaeventshelper.cxx +++ b/sc/source/ui/vba/vbaeventshelper.cxx @@ -278,20 +278,20 @@ void SAL_CALL ScVbaEventListener::windowActivated( const lang::EventObject& rEve { ::osl::MutexGuard aGuard( maMutex ); - if( !mbDisposed ) - { - uno::Reference< awt::XWindow > xWindow( rEvent.Source, uno::UNO_QUERY ); - VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( xWindow ); - // do not fire activation event multiple time for the same window - if( pWindow && (pWindow != mpActiveWindow) ) - { - // if another window is active, fire deactivation event first - if( mpActiveWindow ) - processWindowActivateEvent( mpActiveWindow, false ); - // fire activation event for the new window - processWindowActivateEvent( pWindow, true ); - mpActiveWindow = pWindow; - } + if( mbDisposed ) + return; + + uno::Reference< awt::XWindow > xWindow( rEvent.Source, uno::UNO_QUERY ); + VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( xWindow ); + // do not fire activation event multiple time for the same window + if( pWindow && (pWindow != mpActiveWindow) ) + { + // if another window is active, fire deactivation event first + if( mpActiveWindow ) + processWindowActivateEvent( mpActiveWindow, false ); + // fire activation event for the new window + processWindowActivateEvent( pWindow, true ); + mpActiveWindow = pWindow; } } diff --git a/sc/source/ui/vba/vbaname.cxx b/sc/source/ui/vba/vbaname.cxx index 6d2072f97ba5..45e88a4c1395 100644 --- a/sc/source/ui/vba/vbaname.cxx +++ b/sc/source/ui/vba/vbaname.cxx @@ -106,18 +106,17 @@ void ScVbaName::setContent( const OUString& rContent, const formula::FormulaGra // We should be able to do the below by just setting calling SetCode on pNamedRange // right? - if ( pNamedRange && pNamedRange->pDocShell ) - { + if ( !(pNamedRange && pNamedRange->pDocShell) ) + return; - ScDocument& rDoc = pNamedRange->pDocShell->GetDocument(); - ScRangeData* pOldData = pNamedRange->GetRangeData_Impl(); - if (pOldData) - { - // Shorter way of doing this ? - ScCompiler aComp( &rDoc, pOldData->GetPos(), eGrammar ); - std::unique_ptr<ScTokenArray> pArray(aComp.CompileString(sContent)); - pOldData->SetCode(*pArray); - } + ScDocument& rDoc = pNamedRange->pDocShell->GetDocument(); + ScRangeData* pOldData = pNamedRange->GetRangeData_Impl(); + if (pOldData) + { + // Shorter way of doing this ? + ScCompiler aComp( &rDoc, pOldData->GetPos(), eGrammar ); + std::unique_ptr<ScTokenArray> pArray(aComp.CompileString(sContent)); + pOldData->SetCode(*pArray); } } diff --git a/sc/source/ui/vba/vbarange.cxx b/sc/source/ui/vba/vbarange.cxx index 91f6956a267d..37c40d7f5c13 100644 --- a/sc/source/ui/vba/vbarange.cxx +++ b/sc/source/ui/vba/vbarange.cxx @@ -250,19 +250,19 @@ SfxItemSet* ScVbaRange::getCurrentDataSet( ) void ScVbaRange::fireChangeEvent() { - if( ScVbaApplication::getDocumentEventsEnabled() ) + if( !ScVbaApplication::getDocumentEventsEnabled() ) + return; + + ScDocument& rDoc = getScDocument(); + const uno::Reference< script::vba::XVBAEventProcessor >& xVBAEvents = rDoc.GetVbaEventProcessor(); + if( xVBAEvents.is() ) try + { + uno::Sequence< uno::Any > aArgs( 1 ); + aArgs[ 0 ] <<= uno::Reference< excel::XRange >( this ); + xVBAEvents->processVbaEvent( script::vba::VBAEventId::WORKSHEET_CHANGE, aArgs ); + } + catch( uno::Exception& ) { - ScDocument& rDoc = getScDocument(); - const uno::Reference< script::vba::XVBAEventProcessor >& xVBAEvents = rDoc.GetVbaEventProcessor(); - if( xVBAEvents.is() ) try - { - uno::Sequence< uno::Any > aArgs( 1 ); - aArgs[ 0 ] <<= uno::Reference< excel::XRange >( this ); - xVBAEvents->processVbaEvent( script::vba::VBAEventId::WORKSHEET_CHANGE, aArgs ); - } - catch( uno::Exception& ) - { - } } } @@ -1313,21 +1313,21 @@ void lclExpandAndMerge( const uno::Reference< table::XCellRange >& rxCellRange, uno::Reference< util::XMergeable > xMerge( lclExpandToMerged( rxCellRange, true ), uno::UNO_QUERY_THROW ); // Calc cannot merge over merged ranges, always unmerge first xMerge->merge( false ); - if( bMerge ) - { - // clear all contents of the covered cells (not the top-left cell) - table::CellRangeAddress aRangeAddr = lclGetRangeAddress( rxCellRange ); - sal_Int32 nLastColIdx = aRangeAddr.EndColumn - aRangeAddr.StartColumn; - sal_Int32 nLastRowIdx = aRangeAddr.EndRow - aRangeAddr.StartRow; - // clear cells of top row, right of top-left cell - if( nLastColIdx > 0 ) - lclClearRange( rxCellRange->getCellRangeByPosition( 1, 0, nLastColIdx, 0 ) ); - // clear all rows below top row - if( nLastRowIdx > 0 ) - lclClearRange( rxCellRange->getCellRangeByPosition( 0, 1, nLastColIdx, nLastRowIdx ) ); - // merge the range - xMerge->merge( true ); - } + if( !bMerge ) + return; + + // clear all contents of the covered cells (not the top-left cell) + table::CellRangeAddress aRangeAddr = lclGetRangeAddress( rxCellRange ); + sal_Int32 nLastColIdx = aRangeAddr.EndColumn - aRangeAddr.StartColumn; + sal_Int32 nLastRowIdx = aRangeAddr.EndRow - aRangeAddr.StartRow; + // clear cells of top row, right of top-left cell + if( nLastColIdx > 0 ) + lclClearRange( rxCellRange->getCellRangeByPosition( 1, 0, nLastColIdx, 0 ) ); + // clear all rows below top row + if( nLastRowIdx > 0 ) + lclClearRange( rxCellRange->getCellRangeByPosition( 0, 1, nLastColIdx, nLastRowIdx ) ); + // merge the range + xMerge->merge( true ); } /// @throws uno::RuntimeException @@ -2239,26 +2239,26 @@ ScVbaRange::Select() if ( !pUnoRangesBase ) throw uno::RuntimeException("Failed to access underlying uno range object" ); ScDocShell* pShell = pUnoRangesBase->GetDocShell(); - if ( pShell ) + if ( !pShell ) + return; + + uno::Reference< frame::XModel > xModel( pShell->GetModel(), uno::UNO_SET_THROW ); + uno::Reference< view::XSelectionSupplier > xSelection( xModel->getCurrentController(), uno::UNO_QUERY_THROW ); + if ( mxRanges.is() ) + xSelection->select( uno::Any( lclExpandToMerged( mxRanges ) ) ); + else + xSelection->select( uno::Any( lclExpandToMerged( mxRange, true ) ) ); + // set focus on document e.g. + // ThisComponent.CurrentController.Frame.getContainerWindow.SetFocus + try + { + uno::Reference< frame::XController > xController( xModel->getCurrentController(), uno::UNO_SET_THROW ); + uno::Reference< frame::XFrame > xFrame( xController->getFrame(), uno::UNO_SET_THROW ); + uno::Reference< awt::XWindow > xWin( xFrame->getContainerWindow(), uno::UNO_SET_THROW ); + xWin->setFocus(); + } + catch( uno::Exception& ) { - uno::Reference< frame::XModel > xModel( pShell->GetModel(), uno::UNO_SET_THROW ); - uno::Reference< view::XSelectionSupplier > xSelection( xModel->getCurrentController(), uno::UNO_QUERY_THROW ); - if ( mxRanges.is() ) - xSelection->select( uno::Any( lclExpandToMerged( mxRanges ) ) ); - else - xSelection->select( uno::Any( lclExpandToMerged( mxRange, true ) ) ); - // set focus on document e.g. - // ThisComponent.CurrentController.Frame.getContainerWindow.SetFocus - try - { - uno::Reference< frame::XController > xController( xModel->getCurrentController(), uno::UNO_SET_THROW ); - uno::Reference< frame::XFrame > xFrame( xController->getFrame(), uno::UNO_SET_THROW ); - uno::Reference< awt::XWindow > xWin( xFrame->getContainerWindow(), uno::UNO_SET_THROW ); - xWin->setFocus(); - } - catch( uno::Exception& ) - { - } } } @@ -3806,19 +3806,19 @@ ScVbaRange::setColumnWidth( const uno::Any& _columnwidth ) _columnwidth >>= nColWidth; nColWidth = lcl_Round2DecPlaces( nColWidth ); ScDocShell* pDocShell = getScDocShell(); - if ( pDocShell ) - { - if ( nColWidth != 0.0 ) - nColWidth = ( nColWidth + fExtraWidth ) * getDefaultCharWidth( pDocShell ); - RangeHelper thisRange( mxRange ); - table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress(); - sal_uInt16 nTwips = lcl_pointsToTwips( nColWidth ); + if ( !pDocShell ) + return; - std::vector<sc::ColRowSpan> aColArr(1, sc::ColRowSpan(thisAddress.StartColumn, thisAddress.EndColumn)); - // #163561# use mode SC_SIZE_DIRECT: hide for width 0, show for other values - pDocShell->GetDocFunc().SetWidthOrHeight( - true, aColArr, thisAddress.Sheet, SC_SIZE_DIRECT, nTwips, true, true); - } + if ( nColWidth != 0.0 ) + nColWidth = ( nColWidth + fExtraWidth ) * getDefaultCharWidth( pDocShell ); + RangeHelper thisRange( mxRange ); + table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress(); + sal_uInt16 nTwips = lcl_pointsToTwips( nColWidth ); + + std::vector<sc::ColRowSpan> aColArr(1, sc::ColRowSpan(thisAddress.StartColumn, thisAddress.EndColumn)); + // #163561# use mode SC_SIZE_DIRECT: hide for width 0, show for other values + pDocShell->GetDocFunc().SetWidthOrHeight( + true, aColArr, thisAddress.Sheet, SC_SIZE_DIRECT, nTwips, true, true); } uno::Any SAL_CALL @@ -4022,27 +4022,27 @@ ScVbaRange::setPageBreak( const uno::Any& _pagebreak) _pagebreak >>= nPageBreak; ScDocShell* pShell = getDocShellFromRange( mxRange ); - if ( pShell ) - { - RangeHelper thisRange( mxRange ); - table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress(); - if ((thisAddress.StartColumn==0) && (thisAddress.StartRow==0)) - return; - bool bColumn = false; + if ( !pShell ) + return; - if (thisAddress.StartRow==0) - bColumn = true; + RangeHelper thisRange( mxRange ); + table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress(); + if ((thisAddress.StartColumn==0) && (thisAddress.StartRow==0)) + return; + bool bColumn = false; - ScAddress aAddr( static_cast<SCCOL>(thisAddress.StartColumn), thisAddress.StartRow, thisAddress.Sheet ); - uno::Reference< frame::XModel > xModel = pShell->GetModel(); - if ( xModel.is() ) - { - ScTabViewShell* pViewShell = excel::getBestViewShell( xModel ); - if ( nPageBreak == excel::XlPageBreak::xlPageBreakManual ) - pViewShell->InsertPageBreak( bColumn, true, &aAddr); - else if ( nPageBreak == excel::XlPageBreak::xlPageBreakNone ) - pViewShell->DeletePageBreak( bColumn, true, &aAddr); - } + if (thisAddress.StartRow==0) + bColumn = true; + + ScAddress aAddr( static_cast<SCCOL>(thisAddress.StartColumn), thisAddress.StartRow, thisAddress.Sheet ); + uno::Reference< frame::XModel > xModel = pShell->GetModel(); + if ( xModel.is() ) + { + ScTabViewShell* pViewShell = excel::getBestViewShell( xModel ); + if ( nPageBreak == excel::XlPageBreak::xlPageBreakManual ) + pViewShell->InsertPageBreak( bColumn, true, &aAddr); + else if ( nPageBreak == excel::XlPageBreak::xlPageBreakNone ) + pViewShell->DeletePageBreak( bColumn, true, &aAddr); } } @@ -4250,19 +4250,19 @@ static ScDBData* lcl_GetDBData_Impl( ScDocShell* pDocShell, sal_Int16 nSheet ) static void lcl_SelectAll( ScDocShell* pDocShell, const ScQueryParam& aParam ) { - if ( pDocShell ) + if ( !pDocShell ) + return; + + ScViewData* pViewData = ScDocShell::GetViewData(); + if ( !pViewData ) { - ScViewData* pViewData = ScDocShell::GetViewData(); - if ( !pViewData ) - { - ScTabViewShell* pViewSh = pDocShell->GetBestViewShell( true ); - pViewData = pViewSh ? &pViewSh->GetViewData() : nullptr; - } + ScTabViewShell* pViewSh = pDocShell->GetBestViewShell( true ); + pViewData = pViewSh ? &pViewSh->GetViewData() : nullptr; + } - if ( pViewData ) - { - pViewData->GetView()->Query( aParam, nullptr, true ); - } + if ( pViewData ) + { + pViewData->GetView()->Query( aParam, nullptr, true ); } } @@ -4721,28 +4721,28 @@ ScVbaRange::Autofit() } return; } - // if the range is a not a row or column range autofit will - // throw an error + // if the range is a not a row or column range autofit will + // throw an error if ( !( mbIsColumns || mbIsRows ) ) DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, OUString()); ScDocShell* pDocShell = getDocShellFromRange( mxRange ); - if ( pDocShell ) - { - RangeHelper thisRange( mxRange ); - table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress(); + if ( !pDocShell ) + return; - std::vector<sc::ColRowSpan> aColArr(1, sc::ColRowSpan(thisAddress.StartColumn,thisAddress.EndColumn)); - bool bDirection = true; - if ( mbIsRows ) - { - bDirection = false; - aColArr[0].mnStart = thisAddress.StartRow; - aColArr[0].mnEnd = thisAddress.EndRow; - } - pDocShell->GetDocFunc().SetWidthOrHeight( - bDirection, aColArr, thisAddress.Sheet, SC_SIZE_OPTIMAL, 0, true, true); + RangeHelper thisRange( mxRange ); + table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress(); + + std::vector<sc::ColRowSpan> aColArr(1, sc::ColRowSpan(thisAddress.StartColumn,thisAddress.EndColumn)); + bool bDirection = true; + if ( mbIsRows ) + { + bDirection = false; + aColArr[0].mnStart = thisAddress.StartRow; + aColArr[0].mnEnd = thisAddress.EndRow; } + pDocShell->GetDocFunc().SetWidthOrHeight( + bDirection, aColArr, thisAddress.Sheet, SC_SIZE_OPTIMAL, 0, true, true); } uno::Any SAL_CALL diff --git a/sc/source/ui/vba/vbasheetobject.cxx b/sc/source/ui/vba/vbasheetobject.cxx index b5fdcd159c10..f7e1a45cee2d 100644 --- a/sc/source/ui/vba/vbasheetobject.cxx +++ b/sc/source/ui/vba/vbasheetobject.cxx @@ -353,19 +353,19 @@ void SAL_CALL ScVbaControlObjectBase::setOnAction( const OUString& rMacroName ) try { xEventMgr->revokeScriptEvent( nIndex, gaListenerType, gaEventMethod, OUString() ); } catch( uno::Exception& ) {} // if a macro name has been passed, try to attach it to the event - if( !rMacroName.isEmpty() ) - { - MacroResolvedInfo aResolvedMacro = resolveVBAMacro( getSfxObjShell( mxModel ), rMacroName ); - if( !aResolvedMacro.mbFound ) - throw uno::RuntimeException(); - script::ScriptEventDescriptor aDescriptor; - aDescriptor.ListenerType = gaListenerType; - aDescriptor.EventMethod = gaEventMethod; - aDescriptor.ScriptType = "Script"; - aDescriptor.ScriptCode = makeMacroURL( aResolvedMacro.msResolvedMacro ); - NotifyMacroEventRead(); - xEventMgr->registerScriptEvent( nIndex, aDescriptor ); - } + if( rMacroName.isEmpty() ) + return; + + MacroResolvedInfo aResolvedMacro = resolveVBAMacro( getSfxObjShell( mxModel ), rMacroName ); + if( !aResolvedMacro.mbFound ) + throw uno::RuntimeException(); + script::ScriptEventDescriptor aDescriptor; + aDescriptor.ListenerType = gaListenerType; + aDescriptor.EventMethod = gaEventMethod; + aDescriptor.ScriptType = "Script"; + aDescriptor.ScriptCode = makeMacroURL( aResolvedMacro.msResolvedMacro ); + NotifyMacroEventRead(); + xEventMgr->registerScriptEvent( nIndex, aDescriptor ); } sal_Bool SAL_CALL ScVbaControlObjectBase::getPrintObject() diff --git a/sc/source/ui/vba/vbaworksheet.cxx b/sc/source/ui/vba/vbaworksheet.cxx index 4b66c0a776ff..57aca4796e41 100644 --- a/sc/source/ui/vba/vbaworksheet.cxx +++ b/sc/source/ui/vba/vbaworksheet.cxx @@ -101,20 +101,20 @@ static void removeAllSheets( const uno::Reference <sheet::XSpreadsheetDocument>& uno::Reference<sheet::XSpreadsheets> xSheets = xSpreadDoc->getSheets(); uno::Reference <container::XIndexAccess> xIndex( xSheets, uno::UNO_QUERY ); - if ( xIndex.is() ) - { - uno::Reference<container::XNameContainer> xNameContainer(xSheets,uno::UNO_QUERY_THROW); - for (sal_Int32 i = xIndex->getCount() -1; i>= 1; i--) - { - uno::Reference< sheet::XSpreadsheet > xSheet(xIndex->getByIndex(i), uno::UNO_QUERY); - uno::Reference< container::XNamed > xNamed( xSheet, uno::UNO_QUERY_THROW ); - xNameContainer->removeByName(xNamed->getName()); - } + if ( !xIndex.is() ) + return; - uno::Reference< sheet::XSpreadsheet > xSheet(xIndex->getByIndex(0), uno::UNO_QUERY); + uno::Reference<container::XNameContainer> xNameContainer(xSheets,uno::UNO_QUERY_THROW); + for (sal_Int32 i = xIndex->getCount() -1; i>= 1; i--) + { + uno::Reference< sheet::XSpreadsheet > xSheet(xIndex->getByIndex(i), uno::UNO_QUERY); uno::Reference< container::XNamed > xNamed( xSheet, uno::UNO_QUERY_THROW ); - xNamed->setName(aSheetName); + xNameContainer->removeByName(xNamed->getName()); } + + uno::Reference< sheet::XSpreadsheet > xSheet(xIndex->getByIndex(0), uno::UNO_QUERY); + uno::Reference< container::XNamed > xNamed( xSheet, uno::UNO_QUERY_THROW ); + xNamed->setName(aSheetName); } static uno::Reference<frame::XModel> @@ -381,23 +381,23 @@ void SAL_CALL ScVbaWorksheet::setAutoFilterMode( sal_Bool bAutoFilterMode ) ScDocShell* pDocShell = excel::getDocShell( xModel ); ScDocument& rDoc = pDocShell->GetDocument(); ScDBData* pDBData = rDoc.GetAnonymousDBData(getSheetID()); - if (pDBData) - { - pDBData->SetAutoFilter(bAutoFilterMode); - ScRange aRange; - pDBData->GetArea(aRange); - if (bAutoFilterMode) - rDoc.ApplyFlagsTab( aRange.aStart.Col(), aRange.aStart.Row(), - aRange.aEnd.Col(), aRange.aStart.Row(), - aRange.aStart.Tab(), ScMF::Auto ); - else if (!bAutoFilterMode) - rDoc.RemoveFlagsTab(aRange.aStart.Col(), aRange.aStart.Row(), - aRange.aEnd.Col(), aRange.aStart.Row(), - aRange.aStart.Tab(), ScMF::Auto ); - ScRange aPaintRange(aRange.aStart, aRange.aEnd); - aPaintRange.aEnd.SetRow(aPaintRange.aStart.Row()); - pDocShell->PostPaint(aPaintRange, PaintPartFlags::Grid); - } + if (!pDBData) + return; + + pDBData->SetAutoFilter(bAutoFilterMode); + ScRange aRange; + pDBData->GetArea(aRange); + if (bAutoFilterMode) + rDoc.ApplyFlagsTab( aRange.aStart.Col(), aRange.aStart.Row(), + aRange.aEnd.Col(), aRange.aStart.Row(), + aRange.aStart.Tab(), ScMF::Auto ); + else if (!bAutoFilterMode) + rDoc.RemoveFlagsTab(aRange.aStart.Col(), aRange.aStart.Row(), + aRange.aEnd.Col(), aRange.aStart.Row(), + aRange.aStart.Tab(), ScMF::Auto ); + ScRange aPaintRange(aRange.aStart, aRange.aEnd); + aPaintRange.aEnd.SetRow(aPaintRange.aStart.Row()); + pDocShell->PostPaint(aPaintRange, PaintPartFlags::Grid); } uno::Reference< excel::XRange > diff --git a/sc/source/ui/vba/vbaworksheets.cxx b/sc/source/ui/vba/vbaworksheets.cxx index be76009bc351..3953cb881815 100644 --- a/sc/source/ui/vba/vbaworksheets.cxx +++ b/sc/source/ui/vba/vbaworksheets.cxx @@ -491,44 +491,44 @@ void ScVbaWorksheets::PrintPreview( const css::uno::Any& /*EnableChanges*/ ) SfxViewFrame* pViewFrame = nullptr; if ( pViewShell ) pViewFrame = pViewShell->GetViewFrame(); - if ( pViewFrame ) - { - if ( !pViewFrame->GetFrame().IsInPlace() ) - { - dispatchExecute( pViewShell, SID_VIEWSHELL1 ); - SfxViewShell* pShell = SfxViewShell::Get( pViewFrame->GetFrame().GetFrameInterface()->getController() ); + if ( !pViewFrame ) + return; - if ( dynamic_cast<const ScPreviewShell*>( pShell) != nullptr ) - { - ScPreviewShell* pPrvShell = static_cast< ScPreviewShell* >( pShell ); - ScPreview* pPrvView = pPrvShell->GetPreview(); - const ScDocument& rDoc = *pViewShell->GetViewData().GetDocument(); - ScMarkData aMarkData(rDoc.GetSheetLimits()); - sal_Int32 nElems = getCount(); - for ( sal_Int32 nItem = 1; nItem <= nElems; ++nItem ) - { - uno::Reference< excel::XWorksheet > xSheet( Item( uno::makeAny( nItem ), uno::Any() ), uno::UNO_QUERY_THROW ); - ScVbaWorksheet* pSheet = excel::getImplFromDocModuleWrapper<ScVbaWorksheet>( xSheet ); - if ( pSheet ) - aMarkData.SelectTable(static_cast< SCTAB >( pSheet->getSheetID() ), true ); - } - // save old selection, setting the selectedtabs in the preview - // can affect the current selection when preview has been - // closed - ScMarkData::MarkedTabsType aOldTabs = pPrvView->GetSelectedTabs(); - pPrvView->SetSelectedTabs( aMarkData ); - // force update - pPrvView->DataChanged(false); - // set sensible first page - long nPage = pPrvView->GetFirstPage( 1 ); - pPrvView->SetPageNo( nPage ); - WaitUntilPreviewIsClosed( pViewFrame ); - // restore old tab selection - pViewShell = excel::getBestViewShell( mxModel ); - pViewShell->GetViewData().GetMarkData().SetSelectedTabs(aOldTabs); - } - } + if ( pViewFrame->GetFrame().IsInPlace() ) + return; + + dispatchExecute( pViewShell, SID_VIEWSHELL1 ); + SfxViewShell* pShell = SfxViewShell::Get( pViewFrame->GetFrame().GetFrameInterface()->getController() ); + + if ( dynamic_cast<const ScPreviewShell*>( pShell) == nullptr ) + return; + + ScPreviewShell* pPrvShell = static_cast< ScPreviewShell* >( pShell ); + ScPreview* pPrvView = pPrvShell->GetPreview(); + const ScDocument& rDoc = *pViewShell->GetViewData().GetDocument(); + ScMarkData aMarkData(rDoc.GetSheetLimits()); + sal_Int32 nElems = getCount(); + for ( sal_Int32 nItem = 1; nItem <= nElems; ++nItem ) + { + uno::Reference< excel::XWorksheet > xSheet( Item( uno::makeAny( nItem ), uno::Any() ), uno::UNO_QUERY_THROW ); + ScVbaWorksheet* pSheet = excel::getImplFromDocModuleWrapper<ScVbaWorksheet>( xSheet ); + if ( pSheet ) + aMarkData.SelectTable(static_cast< SCTAB >( pSheet->getSheetID() ), true ); } + // save old selection, setting the selectedtabs in the preview + // can affect the current selection when preview has been + // closed + ScMarkData::MarkedTabsType aOldTabs = pPrvView->GetSelectedTabs(); + pPrvView->SetSelectedTabs( aMarkData ); + // force update + pPrvView->DataChanged(false); + // set sensible first page + long nPage = pPrvView->GetFirstPage( 1 ); + pPrvView->SetPageNo( nPage ); + WaitUntilPreviewIsClosed( pViewFrame ); + // restore old tab selection + pViewShell = excel::getBestViewShell( mxModel ); + pViewShell->GetViewData().GetMarkData().SetSelectedTabs(aOldTabs); } |