[Libreoffice-commits] core.git: 2 commits - sc/source

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Sun Aug 9 17:06:24 UTC 2020


 sc/source/core/opencl/formulagroupcl.cxx                       |    7 
 sc/source/core/opencl/op_statistical.cxx                       | 1044 ++++------
 sc/source/core/opencl/opbase.cxx                               |   31 
 sc/source/core/tool/formulalogger.cxx                          |   24 
 sc/source/ui/StatisticsDialogs/RandomNumberGeneratorDialog.cxx |   20 
 sc/source/ui/app/inputhdl.cxx                                  |   74 
 sc/source/ui/dbgui/pfiltdlg.cxx                                |  122 -
 sc/source/ui/dbgui/tpsort.cxx                                  |  227 +-
 sc/source/ui/dbgui/tpsubt.cxx                                  |   82 
 sc/source/ui/docshell/docsh.cxx                                |  121 -
 sc/source/ui/drawfunc/fuconrec.cxx                             |  198 -
 sc/source/ui/drawfunc/fudraw.cxx                               |   96 
 sc/source/ui/drawfunc/fuins1.cxx                               |   40 
 sc/source/ui/drawfunc/fuins2.cxx                               |  166 -
 sc/source/ui/drawfunc/futext.cxx                               |  116 -
 sc/source/ui/drawfunc/futext3.cxx                              |  118 -
 sc/source/ui/drawfunc/mediash.cxx                              |   44 
 sc/source/ui/formdlg/formula.cxx                               |  268 +-
 sc/source/ui/namedlg/namedlg.cxx                               |   56 
 sc/source/ui/navipi/content.cxx                                |  254 +-
 sc/source/ui/navipi/navipi.cxx                                 |  110 -
 sc/source/ui/optdlg/tpusrlst.cxx                               |   30 
 sc/source/ui/pagedlg/areasdlg.cxx                              |   48 
 sc/source/ui/pagedlg/scuitphfedit.cxx                          |   22 
 sc/source/ui/pagedlg/tphfedit.cxx                              |   64 
 sc/source/ui/undo/areasave.cxx                                 |   24 
 sc/source/ui/undo/undobase.cxx                                 |   70 
 sc/source/ui/undo/undoblk.cxx                                  |  121 -
 sc/source/ui/undo/undocell.cxx                                 |   22 
 sc/source/ui/undo/undodat.cxx                                  |   30 
 sc/source/ui/undo/undoutil.cxx                                 |   24 
 sc/source/ui/vba/excelvbahelper.cxx                            |  200 -
 sc/source/ui/vba/vbaapplication.cxx                            |   66 
 sc/source/ui/vba/vbaaxes.cxx                                   |   40 
 sc/source/ui/vba/vbaeventshelper.cxx                           |   28 
 sc/source/ui/vba/vbaname.cxx                                   |   21 
 sc/source/ui/vba/vbarange.cxx                                  |  208 -
 sc/source/ui/vba/vbasheetobject.cxx                            |   26 
 sc/source/ui/vba/vbaworksheet.cxx                              |   56 
 sc/source/ui/vba/vbaworksheets.cxx                             |   72 
 40 files changed, 2194 insertions(+), 2196 deletions(-)

New commits:
commit a7c8c5f49af7ad8c1101a4c73dbe7a83b7ba8cb5
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Sun Aug 9 11:55:27 2020 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Sun Aug 9 19:05:46 2020 +0200

    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 at collabora.co.uk>

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);
 
 }
 
commit 8c505204f25b509daa586c2d308fb870325c59b9
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Sun Aug 9 11:59:30 2020 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Sun Aug 9 19:05:34 2020 +0200

    loplugin:flatten in sc
    
    Change-Id: Iedb6ca37d1b006131d1fc77eca3303a12ccb60c9
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/100401
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/sc/source/core/opencl/formulagroupcl.cxx b/sc/source/core/opencl/formulagroupcl.cxx
index 459de3fae64b..59e4ff1480bf 100644
--- a/sc/source/core/opencl/formulagroupcl.cxx
+++ b/sc/source/core/opencl/formulagroupcl.cxx
@@ -2737,11 +2737,12 @@ DynamicKernelSoPArguments::DynamicKernelSoPArguments(const ScCalcConfig& config,
                     // explicitly claims it will handle this situation properly.
                     if( pDVR->GetArrays().size() > 1 )
                     {
-                        if( pCodeGen->canHandleMultiVector())
-                            SAL_INFO("sc.opencl", "multi-column DoubleRef");
-                        else
+                        if( !pCodeGen->canHandleMultiVector())
                             throw UnhandledToken(("Function '" + pCodeGen->BinFuncName()
                                 + "' cannot handle multi-column DoubleRef").c_str(), __FILE__, __LINE__);
+
+                        SAL_INFO("sc.opencl", "multi-column DoubleRef");
+
                     }
 
                     // FIXME: The Right Thing to do would be to compare the accumulated kernel
diff --git a/sc/source/core/opencl/op_statistical.cxx b/sc/source/core/opencl/op_statistical.cxx
index 94415b39e41a..273f37dcc204 100644
--- a/sc/source/core/opencl/op_statistical.cxx
+++ b/sc/source/core/opencl/op_statistical.cxx
@@ -494,167 +494,73 @@ void OpTTest::GenSlidingWindowFunction(std::stringstream &ss,
         ss << "}\n";
         return ;
     }
-    if(vSubArguments.size() == 4)
+    if(vSubArguments.size() != 4)
+        return;
+
+    FormulaToken *pCur  = vSubArguments[0]->GetFormulaToken();
+    FormulaToken *pCur1 = vSubArguments[1]->GetFormulaToken();
+    FormulaToken *pCur2 = vSubArguments[2]->GetFormulaToken();
+    FormulaToken *pCur3 = vSubArguments[3]->GetFormulaToken();
+    assert(pCur);
+    assert(pCur1);
+    assert(pCur2);
+    assert(pCur3);
+    if(ocPush == vSubArguments[2]->GetFormulaToken()->GetOpCode())
     {
-        FormulaToken *pCur  = vSubArguments[0]->GetFormulaToken();
-        FormulaToken *pCur1 = vSubArguments[1]->GetFormulaToken();
-        FormulaToken *pCur2 = vSubArguments[2]->GetFormulaToken();
-        FormulaToken *pCur3 = vSubArguments[3]->GetFormulaToken();
-        assert(pCur);
-        assert(pCur1);
-        assert(pCur2);
-        assert(pCur3);
-        if(ocPush == vSubArguments[2]->GetFormulaToken()->GetOpCode())
+        if(pCur2->GetType() == formula::svSingleVectorRef)
         {
-            if(pCur2->GetType() == formula::svSingleVectorRef)
-            {
-                const formula::SingleVectorRefToken* pSVR =
-                    static_cast< const formula::SingleVectorRefToken*>(pCur2);
-                ss << "    if (gid0 < " << pSVR->GetArrayLength() << ")\n";
-                ss << "    {\n";
-                ss << "        mode = " ;
-                ss << vSubArguments[2]->GenSlidingWindowDeclRef() << ";\n";
-                ss << "        if (isnan(mode))\n";
-                ss << "            mode = 0.0;\n";
-                ss << "        else\n";
-                ss << "            mode = floor(mode);\n";
-                ss << "    }\n";
-            }
-            else if(pCur2->GetType() == formula::svDouble)
-            {
-                ss << "    mode = floor(convert_double(";
-                ss << pCur2->GetDouble() << "));\n";
-            }
-            else
-            {
-                ss << "    return DBL_MAX;\n";
-                ss << "}\n";
-                return ;
-            }
+            const formula::SingleVectorRefToken* pSVR =
+                static_cast< const formula::SingleVectorRefToken*>(pCur2);
+            ss << "    if (gid0 < " << pSVR->GetArrayLength() << ")\n";
+            ss << "    {\n";
+            ss << "        mode = " ;
+            ss << vSubArguments[2]->GenSlidingWindowDeclRef() << ";\n";
+            ss << "        if (isnan(mode))\n";
+            ss << "            mode = 0.0;\n";
+            ss << "        else\n";
+            ss << "            mode = floor(mode);\n";
+            ss << "    }\n";
         }
-        else
+        else if(pCur2->GetType() == formula::svDouble)
         {
-            ss << "    mode = floor(" ;
-            ss << vSubArguments[2]->GenSlidingWindowDeclRef() << ");\n";
+            ss << "    mode = floor(convert_double(";
+            ss << pCur2->GetDouble() << "));\n";
         }
-        ss << "    if(!(mode == 1.0 || mode == 2.0))\n";
-        ss << "        return DBL_MAX;\n";
-        if(ocPush==vSubArguments[3]->GetFormulaToken()->GetOpCode())
+        else
         {
-            if(pCur3->GetType() == formula::svSingleVectorRef)
-            {
-                const formula::SingleVectorRefToken* pSVR =
-                    static_cast< const formula::SingleVectorRefToken*>(pCur3);
-                assert(pSVR);
-                ss << "    if (gid0 < " << pSVR->GetArrayLength() << ")\n";
-                ss << "    {\n";
-                ss << "        if (isnan(";
-                ss << vSubArguments[3]->GenSlidingWindowDeclRef() << "))\n";
-                ss << "            type=0.0;\n";
-                ss << "        else\n";
-                ss << "            type=floor(";
-                ss << vSubArguments[3]->GenSlidingWindowDeclRef() << ");\n";
-                ss << "    }\n";
-            }
-            else if(pCur3->GetType() == formula::svDouble)
-            {
-                ss << "    type = floor(convert_double(" << pCur3->GetDouble() <<
-                "));\n";
-            }
-            else
-            {
-                ss << "    return DBL_MAX;\n";
-                ss << "}\n";
-                return ;
-            }
+            ss << "    return DBL_MAX;\n";
+            ss << "}\n";
+            return ;
         }
-        else
+    }
+    else
+    {
+        ss << "    mode = floor(" ;
+        ss << vSubArguments[2]->GenSlidingWindowDeclRef() << ");\n";
+    }
+    ss << "    if(!(mode == 1.0 || mode == 2.0))\n";
+    ss << "        return DBL_MAX;\n";
+    if(ocPush==vSubArguments[3]->GetFormulaToken()->GetOpCode())
+    {
+        if(pCur3->GetType() == formula::svSingleVectorRef)
         {
-            ss << "    type=floor(";
+            const formula::SingleVectorRefToken* pSVR =
+                static_cast< const formula::SingleVectorRefToken*>(pCur3);
+            assert(pSVR);
+            ss << "    if (gid0 < " << pSVR->GetArrayLength() << ")\n";
+            ss << "    {\n";
+            ss << "        if (isnan(";
+            ss << vSubArguments[3]->GenSlidingWindowDeclRef() << "))\n";
+            ss << "            type=0.0;\n";
+            ss << "        else\n";
+            ss << "            type=floor(";
             ss << vSubArguments[3]->GenSlidingWindowDeclRef() << ");\n";
+            ss << "    }\n";
         }
-        ss << "    if(!(type == 1.0||type == 2.0||type == 3.0))\n";
-        ss << "        return DBL_MAX;\n";
-
-        if(pCur->GetType() == formula::svDoubleVectorRef &&
-               pCur1->GetType() == formula::svDoubleVectorRef)
+        else if(pCur3->GetType() == formula::svDouble)
         {
-            const formula::DoubleVectorRefToken* pDVR =
-                static_cast<const formula::DoubleVectorRefToken *>(pCur);
-            const formula::DoubleVectorRefToken* pDVR1 =
-                static_cast<const formula::DoubleVectorRefToken *>(pCur1);
-
-            size_t nCurWindowSize  = pDVR->GetRefRowSize();
-            size_t nCurWindowSize1 = pDVR1->GetRefRowSize();
-
-            if(nCurWindowSize == nCurWindowSize1)
-            {
-                ss << "    if(type == 1.0)\n";
-                ss << "    {\n";
-                ss << "        for (int i = ";
-                if ((!pDVR->IsStartFixed() && pDVR->IsEndFixed()) &&
-                         (!pDVR1->IsStartFixed() && pDVR1->IsEndFixed()))
-                {
-                    ss << "gid0; i < " << pDVR->GetArrayLength();
-                    ss << " && i < " << nCurWindowSize  << "; i++)\n";
-                    ss << "        {\n";
-                }
-                else if ((pDVR->IsStartFixed() && !pDVR->IsEndFixed()) &&
-                             (pDVR1->IsStartFixed() && !pDVR1->IsEndFixed()))
-                {
-                    ss << "0; i < " << pDVR->GetArrayLength();
-                    ss << " && i < gid0+"<< nCurWindowSize << "; i++)\n";
-                    ss << "        {\n";
-                }
-                else if ((!pDVR->IsStartFixed() && !pDVR->IsEndFixed()) &&
-                             (!pDVR1->IsStartFixed() && !pDVR1->IsEndFixed()))
-                {
-                    ss << "0; i + gid0 < " << pDVR->GetArrayLength();
-                    ss << " &&  i < " << nCurWindowSize << "; i++)\n";
-                    ss << "        {\n";
-                }
-                else if ((pDVR->IsStartFixed() && pDVR->IsEndFixed()) &&
-                             (pDVR1->IsStartFixed() && pDVR1->IsEndFixed()))
-                {
-                    ss << "0; i < " << nCurWindowSize << "; i++)\n";
-                    ss << "        {\n";
-                }
-                else
-                {
-                    ss << "0; i < " << nCurWindowSize << "; i++)\n";
-                    ss << "        {\n";
-                    ss << "            break;\n";
-                    ss << "        }";
-                    ss << "        return DBL_MAX;\n";
-                    ss << "    }\n";
-                    ss << "}\n";
-                    return ;
-                }
-
-                ss << "            arg1 = ";
-                ss << vSubArguments[0]->GenSlidingWindowDeclRef(true) << ";\n";
-                ss << "            arg2 = ";
-                ss << vSubArguments[1]->GenSlidingWindowDeclRef(true) << ";\n";
-                ss << "            if (isnan(arg1)||isnan(arg2))\n";
-                ss << "                continue;\n";
-                ss << "            fSum1 += arg1;\n";
-                ss << "            fSum2 += arg2;\n";
-                ss << "            fSumSqr1 += (arg1 - arg2)*(arg1 - arg2);\n";
-                ss << "            fCount1 += 1;\n";
-                ss << "        }\n";
-                ss << "        if(fCount1 < 1.0)\n";
-                ss << "            return DBL_MAX;\n";
-                ss << "        fT = sqrt(fCount1-1.0) * fabs(fSum1 - fSum2)\n";
-                ss << "            /sqrt(fCount1 * fSumSqr1 - (fSum1-fSum2)\n";
-                ss << "             *(fSum1-fSum2));\n";
-                ss << "        fF = fCount1 - 1.0;\n";
-            }
-            else
-            {
-                ss << "    return DBL_MAX;\n";
-                ss << "}\n";
-                return ;
-            }
+            ss << "    type = floor(convert_double(" << pCur3->GetDouble() <<
+            "));\n";
         }
         else
         {
@@ -662,131 +568,225 @@ void OpTTest::GenSlidingWindowFunction(std::stringstream &ss,
             ss << "}\n";
             return ;
         }
-        ss << "    }\n";
-        ss << "    if(type == 2.0 || type == 3.0)\n";
-        ss << "    {\n";
+    }
+    else
+    {
+        ss << "    type=floor(";
+        ss << vSubArguments[3]->GenSlidingWindowDeclRef() << ");\n";
+    }
+    ss << "    if(!(type == 1.0||type == 2.0||type == 3.0))\n";
+    ss << "        return DBL_MAX;\n";
 
-        if(pCur->GetType() == formula::svDoubleVectorRef &&
-               pCur1->GetType() == formula::svDoubleVectorRef)
-        {
-            const formula::DoubleVectorRefToken* pDVR =
-                static_cast<const formula::DoubleVectorRefToken *>(pCur);
-            const formula::DoubleVectorRefToken* pDVR1 =
-                static_cast<const formula::DoubleVectorRefToken *>(pCur1);
+    if(pCur->GetType() == formula::svDoubleVectorRef &&
+           pCur1->GetType() == formula::svDoubleVectorRef)
+    {
+        const formula::DoubleVectorRefToken* pDVR =
+            static_cast<const formula::DoubleVectorRefToken *>(pCur);
+        const formula::DoubleVectorRefToken* pDVR1 =
+            static_cast<const formula::DoubleVectorRefToken *>(pCur1);
+
+        size_t nCurWindowSize  = pDVR->GetRefRowSize();
+        size_t nCurWindowSize1 = pDVR1->GetRefRowSize();
 
-            size_t nCurWindowSize  = pDVR->GetRefRowSize();
-            size_t nCurWindowSize1 = pDVR1->GetRefRowSize();
+        if(nCurWindowSize == nCurWindowSize1)
+        {
+            ss << "    if(type == 1.0)\n";
+            ss << "    {\n";
             ss << "        for (int i = ";
-            if (!pDVR->IsStartFixed() && pDVR->IsEndFixed())
+            if ((!pDVR->IsStartFixed() && pDVR->IsEndFixed()) &&
+                     (!pDVR1->IsStartFixed() && pDVR1->IsEndFixed()))
             {
                 ss << "gid0; i < " << pDVR->GetArrayLength();
                 ss << " && i < " << nCurWindowSize  << "; i++)\n";
                 ss << "        {\n";
             }
-            else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed())
+            else if ((pDVR->IsStartFixed() && !pDVR->IsEndFixed()) &&
+                         (pDVR1->IsStartFixed() && !pDVR1->IsEndFixed()))
             {
                 ss << "0; i < " << pDVR->GetArrayLength();
                 ss << " && i < gid0+"<< nCurWindowSize << "; i++)\n";
                 ss << "        {\n";
             }
-            else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed())
+            else if ((!pDVR->IsStartFixed() && !pDVR->IsEndFixed()) &&
+                         (!pDVR1->IsStartFixed() && !pDVR1->IsEndFixed()))
             {
                 ss << "0; i + gid0 < " << pDVR->GetArrayLength();
                 ss << " &&  i < " << nCurWindowSize << "; i++)\n";
                 ss << "        {\n";
             }
-            else
+            else if ((pDVR->IsStartFixed() && pDVR->IsEndFixed()) &&
+                         (pDVR1->IsStartFixed() && pDVR1->IsEndFixed()))
             {
                 ss << "0; i < " << nCurWindowSize << "; i++)\n";
                 ss << "        {\n";
             }
-
-            ss << "            arg1 = ";
-            ss << vSubArguments[0]->GenSlidingWindowDeclRef(true) << ";\n";
-            ss << "            if (isnan(arg1))\n";
-            ss << "                continue;\n";
-            ss << "            fSum1 += arg1;\n";
-            ss << "            fSumSqr1 += arg1 * arg1;\n";
-            ss << "            fCount1 += 1;\n";
-            ss << "        }\n";
-
-            ss << "        for (int i = ";
-            if (!pDVR1->IsStartFixed() && pDVR1->IsEndFixed())
-            {
-                ss << "gid0; i < " << pDVR1->GetArrayLength();
-                ss << " && i < " << nCurWindowSize1  << "; i++)\n";
-                ss << "        {\n";
-            }
-            else if (pDVR1->IsStartFixed() && !pDVR1->IsEndFixed())
-            {
-                ss << "0; i < " << pDVR1->GetArrayLength();
-                ss << " && i < gid0+"<< nCurWindowSize1 << "; i++)\n";
-                ss << "        {\n";
-            }
-            else if (!pDVR1->IsStartFixed() && !pDVR1->IsEndFixed())
-            {
-                ss << "0; i + gid0 < " << pDVR1->GetArrayLength();
-                ss << " &&  i < " << nCurWindowSize1 << "; i++)\n";
-                ss << "        {\n";
-            }
             else
             {
-                ss << "0; i < " << nCurWindowSize1 << "; i++)\n";
+                ss << "0; i < " << nCurWindowSize << "; i++)\n";
                 ss << "        {\n";
+                ss << "            break;\n";
+                ss << "        }";
+                ss << "        return DBL_MAX;\n";
+                ss << "    }\n";
+                ss << "}\n";
+                return ;
             }
+
+            ss << "            arg1 = ";
+            ss << vSubArguments[0]->GenSlidingWindowDeclRef(true) << ";\n";
             ss << "            arg2 = ";
             ss << vSubArguments[1]->GenSlidingWindowDeclRef(true) << ";\n";
-            ss << "            if (isnan(arg2))\n";
+            ss << "            if (isnan(arg1)||isnan(arg2))\n";
             ss << "                continue;\n";
+            ss << "            fSum1 += arg1;\n";
             ss << "            fSum2 += arg2;\n";
-            ss << "            fSumSqr2 += arg2 * arg2;\n";
-            ss << "            fCount2 += 1;\n";
+            ss << "            fSumSqr1 += (arg1 - arg2)*(arg1 - arg2);\n";
+            ss << "            fCount1 += 1;\n";
             ss << "        }\n";
+            ss << "        if(fCount1 < 1.0)\n";
+            ss << "            return DBL_MAX;\n";
+            ss << "        fT = sqrt(fCount1-1.0) * fabs(fSum1 - fSum2)\n";
+            ss << "            /sqrt(fCount1 * fSumSqr1 - (fSum1-fSum2)\n";
+            ss << "             *(fSum1-fSum2));\n";
+            ss << "        fF = fCount1 - 1.0;\n";
         }
         else
         {
-            ss << "        return DBL_MAX;\n";
-            ss << "    }\n";
+            ss << "    return DBL_MAX;\n";
             ss << "}\n";
             return ;
         }
-        ss << "        if (fCount1 < 2.0 || fCount2 < 2.0)\n";
-        ss << "            return DBL_MAX;\n";
-        ss << "    }\n";
-        ss << "    if(type == 3.0)\n";
-        ss << "    {\n";
-        ss << "        double fS1 = (fSumSqr1-fSum1*fSum1/fCount1)\n";
-        ss << "            /(fCount1-1.0)/fCount1;\n";
-        ss << "        double fS2 = (fSumSqr2-fSum2*fSum2/fCount2)\n";
-        ss << "            /(fCount2-1.0)/fCount2;\n";
-        ss << "        if (fS1 + fS2 == 0.0)\n";
-        ss << "            return DBL_MAX;\n";
-        ss << "        fT = fabs(fSum1/fCount1 - fSum2/fCount2)\n";
-        ss << "             /sqrt(fS1+fS2);\n";
-        ss << "        double c = fS1/(fS1+fS2);\n";
-        ss << "        fF = 1.0/(c*c/(fCount1-1.0)+(1.0-c)*(1.0-c)\n";
-        ss << "             /(fCount2-1.0));\n";
-        ss << "    }\n";
-        ss << "    if(type == 2.0)\n";
-        ss << "    {\n";
-        ss << "        double fS1 = (fSumSqr1 - fSum1*fSum1/fCount1)\n";
-        ss << "             /(fCount1 - 1.0);\n";
-        ss << "        double fS2 = (fSumSqr2 - fSum2*fSum2/fCount2)\n";
-        ss << "             /(fCount2 - 1.0);\n";
-        ss << "        fT = fabs( fSum1/fCount1 - fSum2/fCount2 )\n";
-        ss << "            /sqrt( (fCount1-1.0)*fS1 + (fCount2-1.0)*fS2 )\n";
-        ss << "            *sqrt( fCount1*fCount2*(fCount1+fCount2-2)\n";
-        ss << "            /(fCount1+fCount2) );\n";
-        ss << "        fF = fCount1 + fCount2 - 2;\n";
-        ss << "    }\n";
+    }
+    else
+    {
+        ss << "    return DBL_MAX;\n";
+        ss << "}\n";
+        return ;
+    }
+    ss << "    }\n";
+    ss << "    if(type == 2.0 || type == 3.0)\n";
+    ss << "    {\n";
 
-        ss << "    double tdist=GetTDist(fT, fF);\n";
-        ss << "    if (mode==1)\n";
-        ss << "        return tdist;\n";
-        ss << "    else\n";
-        ss << "        return 2.0*tdist;\n";
+    if(pCur->GetType() == formula::svDoubleVectorRef &&
+           pCur1->GetType() == formula::svDoubleVectorRef)
+    {
+        const formula::DoubleVectorRefToken* pDVR =
+            static_cast<const formula::DoubleVectorRefToken *>(pCur);
+        const formula::DoubleVectorRefToken* pDVR1 =
+            static_cast<const formula::DoubleVectorRefToken *>(pCur1);
+
+        size_t nCurWindowSize  = pDVR->GetRefRowSize();
+        size_t nCurWindowSize1 = pDVR1->GetRefRowSize();
+        ss << "        for (int i = ";
+        if (!pDVR->IsStartFixed() && pDVR->IsEndFixed())
+        {
+            ss << "gid0; i < " << pDVR->GetArrayLength();
+            ss << " && i < " << nCurWindowSize  << "; i++)\n";
+            ss << "        {\n";
+        }
+        else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed())
+        {
+            ss << "0; i < " << pDVR->GetArrayLength();
+            ss << " && i < gid0+"<< nCurWindowSize << "; i++)\n";
+            ss << "        {\n";
+        }
+        else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed())
+        {
+            ss << "0; i + gid0 < " << pDVR->GetArrayLength();
+            ss << " &&  i < " << nCurWindowSize << "; i++)\n";
+            ss << "        {\n";
+        }
+        else
+        {
+            ss << "0; i < " << nCurWindowSize << "; i++)\n";
+            ss << "        {\n";
+        }
+
+        ss << "            arg1 = ";
+        ss << vSubArguments[0]->GenSlidingWindowDeclRef(true) << ";\n";
+        ss << "            if (isnan(arg1))\n";
+        ss << "                continue;\n";
+        ss << "            fSum1 += arg1;\n";
+        ss << "            fSumSqr1 += arg1 * arg1;\n";
+        ss << "            fCount1 += 1;\n";
+        ss << "        }\n";
+
+        ss << "        for (int i = ";
+        if (!pDVR1->IsStartFixed() && pDVR1->IsEndFixed())
+        {
+            ss << "gid0; i < " << pDVR1->GetArrayLength();
+            ss << " && i < " << nCurWindowSize1  << "; i++)\n";
+            ss << "        {\n";
+        }
+        else if (pDVR1->IsStartFixed() && !pDVR1->IsEndFixed())
+        {
+            ss << "0; i < " << pDVR1->GetArrayLength();
+            ss << " && i < gid0+"<< nCurWindowSize1 << "; i++)\n";
+            ss << "        {\n";
+        }
+        else if (!pDVR1->IsStartFixed() && !pDVR1->IsEndFixed())
+        {
+            ss << "0; i + gid0 < " << pDVR1->GetArrayLength();
+            ss << " &&  i < " << nCurWindowSize1 << "; i++)\n";
+            ss << "        {\n";
+        }
+        else
+        {
+            ss << "0; i < " << nCurWindowSize1 << "; i++)\n";
+            ss << "        {\n";
+        }
+        ss << "            arg2 = ";
+        ss << vSubArguments[1]->GenSlidingWindowDeclRef(true) << ";\n";
+        ss << "            if (isnan(arg2))\n";
+        ss << "                continue;\n";
+        ss << "            fSum2 += arg2;\n";
+        ss << "            fSumSqr2 += arg2 * arg2;\n";
+        ss << "            fCount2 += 1;\n";
+        ss << "        }\n";
+    }
+    else
+    {
+        ss << "        return DBL_MAX;\n";
+        ss << "    }\n";
         ss << "}\n";
+        return ;
     }
+    ss << "        if (fCount1 < 2.0 || fCount2 < 2.0)\n";
+    ss << "            return DBL_MAX;\n";
+    ss << "    }\n";
+    ss << "    if(type == 3.0)\n";
+    ss << "    {\n";
+    ss << "        double fS1 = (fSumSqr1-fSum1*fSum1/fCount1)\n";
+    ss << "            /(fCount1-1.0)/fCount1;\n";
+    ss << "        double fS2 = (fSumSqr2-fSum2*fSum2/fCount2)\n";
+    ss << "            /(fCount2-1.0)/fCount2;\n";
+    ss << "        if (fS1 + fS2 == 0.0)\n";
+    ss << "            return DBL_MAX;\n";
+    ss << "        fT = fabs(fSum1/fCount1 - fSum2/fCount2)\n";
+    ss << "             /sqrt(fS1+fS2);\n";
+    ss << "        double c = fS1/(fS1+fS2);\n";
+    ss << "        fF = 1.0/(c*c/(fCount1-1.0)+(1.0-c)*(1.0-c)\n";
+    ss << "             /(fCount2-1.0));\n";
+    ss << "    }\n";
+    ss << "    if(type == 2.0)\n";
+    ss << "    {\n";
+    ss << "        double fS1 = (fSumSqr1 - fSum1*fSum1/fCount1)\n";
+    ss << "             /(fCount1 - 1.0);\n";
+    ss << "        double fS2 = (fSumSqr2 - fSum2*fSum2/fCount2)\n";
+    ss << "             /(fCount2 - 1.0);\n";
+    ss << "        fT = fabs( fSum1/fCount1 - fSum2/fCount2 )\n";
+    ss << "            /sqrt( (fCount1-1.0)*fS1 + (fCount2-1.0)*fS2 )\n";
+    ss << "            *sqrt( fCount1*fCount2*(fCount1+fCount2-2)\n";
+    ss << "            /(fCount1+fCount2) );\n";
+    ss << "        fF = fCount1 + fCount2 - 2;\n";
+    ss << "    }\n";
+
+    ss << "    double tdist=GetTDist(fT, fF);\n";
+    ss << "    if (mode==1)\n";
+    ss << "        return tdist;\n";
+    ss << "    else\n";
+    ss << "        return 2.0*tdist;\n";
+    ss << "}\n";
 }
 void OpVarP::GenSlidingWindowFunction(std::stringstream &ss,
             const std::string &sSymName, SubArguments &vSubArguments)
@@ -2572,122 +2572,121 @@ void OpSlope::GenSlidingWindowFunction(std::stringstream &ss,
     FormulaToken *pCur1 = vSubArguments[0]->GetFormulaToken();
     assert(pCur);
     assert(pCur1);
-    if (pCur->GetType() == formula::svDoubleVectorRef&&
-        pCur1->GetType() == formula::svDoubleVectorRef)
+    if (pCur->GetType() != formula::svDoubleVectorRef ||
+        pCur1->GetType() != formula::svDoubleVectorRef)
     {
-        const formula::DoubleVectorRefToken* pDVR =
-            static_cast<const formula::DoubleVectorRefToken *>(pCur);
-        const formula::DoubleVectorRefToken* pDVR1 =
-            static_cast<const formula::DoubleVectorRefToken *>(pCur1);
-
-        size_t nCurWindowSize = pDVR->GetRefRowSize();
-        size_t nCurWindowSize1 = pDVR1->GetRefRowSize();
-        size_t arrayLength = pDVR->GetArrayLength()<
-               pDVR1->GetArrayLength() ? pDVR->GetArrayLength():
-                    pDVR1->GetArrayLength();
-        if(nCurWindowSize != nCurWindowSize1)
-            throw Unhandled(__FILE__, __LINE__);
-        ss << "    for (int i = ";
-        if ((!pDVR->IsStartFixed() && pDVR->IsEndFixed())
-            &&(!pDVR1->IsStartFixed() && pDVR1->IsEndFixed()))
-        {
-            ss << "gid0; i < " << arrayLength;
-            ss << " && i < " << nCurWindowSize  << "; i++)\n";
-            ss << "    {\n";
-        }
-        else if ((pDVR->IsStartFixed() && !pDVR->IsEndFixed())
-            &&(pDVR1->IsStartFixed() && !pDVR1->IsEndFixed()))
-        {
-            ss << "0; i < " << arrayLength ;
-            ss << " && i < gid0+" << nCurWindowSize << "; i++)\n";
-            ss << "    {\n";
-        }
-        else if ((!pDVR->IsStartFixed() && !pDVR->IsEndFixed())
-            &&(!pDVR1->IsStartFixed() && !pDVR1->IsEndFixed()))
-        {
-            ss << "0; i + gid0 < " << arrayLength;
-            ss << " &&  i < " << nCurWindowSize << "; i++)\n";
-            ss << "    {\n";
-        }
-        else if ((pDVR->IsStartFixed() && pDVR->IsEndFixed())
-            &&(pDVR1->IsStartFixed() && pDVR1->IsEndFixed()))
-        {
-            ss << "0; i < " << arrayLength << "; i++)\n";
-            ss << "    {\n";
-        }
-        else
-        {
-            throw Unhandled(__FILE__, __LINE__);
-        }
+        throw Unhandled(__FILE__, __LINE__);
+    }
 
-        ss << "        argX = ";
-        ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n";
-        ss << "        argY = ";
-        ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
-        ss << "        if (isnan(argX) || isnan(argY))\n";
-        ss << "            continue;\n";
-        ss << "        fSumX += argX;\n";
-        ss << "        fSumY += argY;\n";
-        ss << "        fCount += 1.0;\n";
-        ss << "    }\n";
+    const formula::DoubleVectorRefToken* pDVR =
+        static_cast<const formula::DoubleVectorRefToken *>(pCur);
+    const formula::DoubleVectorRefToken* pDVR1 =
+        static_cast<const formula::DoubleVectorRefToken *>(pCur1);
 
-        ss << "    if (fCount < 1.0)\n";
-        ss << "        return CreateDoubleError(NoValue);\n";
-        ss << "    else\n";
+    size_t nCurWindowSize = pDVR->GetRefRowSize();
+    size_t nCurWindowSize1 = pDVR1->GetRefRowSize();
+    size_t arrayLength = pDVR->GetArrayLength()<
+           pDVR1->GetArrayLength() ? pDVR->GetArrayLength():
+                pDVR1->GetArrayLength();
+    if(nCurWindowSize != nCurWindowSize1)
+        throw Unhandled(__FILE__, __LINE__);
+    ss << "    for (int i = ";
+    if ((!pDVR->IsStartFixed() && pDVR->IsEndFixed())
+        &&(!pDVR1->IsStartFixed() && pDVR1->IsEndFixed()))
+    {
+        ss << "gid0; i < " << arrayLength;
+        ss << " && i < " << nCurWindowSize  << "; i++)\n";
         ss << "    {\n";
-        ss << "        fMeanX = fSumX * pow(fCount,-1.0);\n";
-        ss << "        fMeanY = fSumY * pow(fCount,-1.0);\n";
+    }
+    else if ((pDVR->IsStartFixed() && !pDVR->IsEndFixed())
+        &&(pDVR1->IsStartFixed() && !pDVR1->IsEndFixed()))
+    {
+        ss << "0; i < " << arrayLength ;
+        ss << " && i < gid0+" << nCurWindowSize << "; i++)\n";
+        ss << "    {\n";
+    }
+    else if ((!pDVR->IsStartFixed() && !pDVR->IsEndFixed())
+        &&(!pDVR1->IsStartFixed() && !pDVR1->IsEndFixed()))
+    {
+        ss << "0; i + gid0 < " << arrayLength;
+        ss << " &&  i < " << nCurWindowSize << "; i++)\n";
+        ss << "    {\n";
+    }
+    else if ((pDVR->IsStartFixed() && pDVR->IsEndFixed())
+        &&(pDVR1->IsStartFixed() && pDVR1->IsEndFixed()))
+    {
+        ss << "0; i < " << arrayLength << "; i++)\n";
+        ss << "    {\n";
+    }
+    else
+    {
+        throw Unhandled(__FILE__, __LINE__);
+    }
 
-        ss << "        for (int i = ";
-        if ((!pDVR->IsStartFixed() && pDVR->IsEndFixed())
-            &&(!pDVR1->IsStartFixed() && pDVR1->IsEndFixed()))
-        {
-            ss << "gid0; i < " << arrayLength;
-            ss << " && i < " << nCurWindowSize  << "; i++)\n";
-            ss << "        {\n";
-        }
-        else if ((pDVR->IsStartFixed() && !pDVR->IsEndFixed())
-            &&(pDVR1->IsStartFixed() && !pDVR1->IsEndFixed()))
-        {
-            ss << "0; i < " << arrayLength ;
-            ss << " && i < gid0+" << nCurWindowSize << "; i++)\n";
-            ss << "        {\n";
-        }
-        else if ((!pDVR->IsStartFixed() && !pDVR->IsEndFixed())
-            &&(!pDVR1->IsStartFixed() && !pDVR1->IsEndFixed()))
-        {
-            ss << "0; i + gid0 < " << arrayLength;
-            ss << " &&  i < " << nCurWindowSize << "; i++)\n";
-            ss << "        {\n";
-        }
-        else
-        {
-            ss << "0; i < " << arrayLength << "; i++)\n";
-            ss << "        {\n";
-        }
+    ss << "        argX = ";
+    ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n";
+    ss << "        argY = ";
+    ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
+    ss << "        if (isnan(argX) || isnan(argY))\n";
+    ss << "            continue;\n";
+    ss << "        fSumX += argX;\n";
+    ss << "        fSumY += argY;\n";
+    ss << "        fCount += 1.0;\n";
+    ss << "    }\n";
 
-        ss << "            argX = ";
-        ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n";
-        ss << "            argY = ";
-        ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
-        ss << "            if (isnan(argX) || isnan(argY))\n";
-        ss << "                 continue;\n";
-        ss << "            fSumDeltaXDeltaY += (argX-fMeanX)*(argY-fMeanY);\n";
-        ss << "            fSumSqrDeltaX += (argX-fMeanX) * (argX-fMeanX);\n";
-        ss << "        }\n";
-        ss << "        if(fSumSqrDeltaX == 0.0)\n";
-        ss << "            return CreateDoubleError(DivisionByZero);\n";
-        ss << "        else\n";
+    ss << "    if (fCount < 1.0)\n";
+    ss << "        return CreateDoubleError(NoValue);\n";
+    ss << "    else\n";
+    ss << "    {\n";
+    ss << "        fMeanX = fSumX * pow(fCount,-1.0);\n";
+    ss << "        fMeanY = fSumY * pow(fCount,-1.0);\n";
+
+    ss << "        for (int i = ";
+    if ((!pDVR->IsStartFixed() && pDVR->IsEndFixed())
+        &&(!pDVR1->IsStartFixed() && pDVR1->IsEndFixed()))
+    {
+        ss << "gid0; i < " << arrayLength;
+        ss << " && i < " << nCurWindowSize  << "; i++)\n";
+        ss << "        {\n";
+    }
+    else if ((pDVR->IsStartFixed() && !pDVR->IsEndFixed())
+        &&(pDVR1->IsStartFixed() && !pDVR1->IsEndFixed()))
+    {
+        ss << "0; i < " << arrayLength ;
+        ss << " && i < gid0+" << nCurWindowSize << "; i++)\n";
+        ss << "        {\n";
+    }
+    else if ((!pDVR->IsStartFixed() && !pDVR->IsEndFixed())
+        &&(!pDVR1->IsStartFixed() && !pDVR1->IsEndFixed()))
+    {
+        ss << "0; i + gid0 < " << arrayLength;
+        ss << " &&  i < " << nCurWindowSize << "; i++)\n";
         ss << "        {\n";
-        ss << "            return fSumDeltaXDeltaY*pow(fSumSqrDeltaX,-1.0);\n";
-        ss << "        }\n";
-        ss << "    }\n";
-        ss << "}\n";
     }
     else
     {
-        throw Unhandled(__FILE__, __LINE__);
+        ss << "0; i < " << arrayLength << "; i++)\n";
+        ss << "        {\n";
     }
+
+    ss << "            argX = ";
+    ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n";
+    ss << "            argY = ";
+    ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
+    ss << "            if (isnan(argX) || isnan(argY))\n";
+    ss << "                 continue;\n";
+    ss << "            fSumDeltaXDeltaY += (argX-fMeanX)*(argY-fMeanY);\n";
+    ss << "            fSumSqrDeltaX += (argX-fMeanX) * (argX-fMeanX);\n";
+    ss << "        }\n";
+    ss << "        if(fSumSqrDeltaX == 0.0)\n";
+    ss << "            return CreateDoubleError(DivisionByZero);\n";
+    ss << "        else\n";
+    ss << "        {\n";
+    ss << "            return fSumDeltaXDeltaY*pow(fSumSqrDeltaX,-1.0);\n";
+    ss << "        }\n";
+    ss << "    }\n";
+    ss << "}\n";
+
 }
 void OpSTEYX::GenSlidingWindowFunction(std::stringstream &ss,
             const std::string &sSymName, SubArguments &vSubArguments)
@@ -6874,193 +6873,192 @@ void OpCovar::GenSlidingWindowFunction(std::stringstream& ss,
             static_cast<const formula::DoubleVectorRefToken* >(pCurY);
         size_t nCurWindowSizeX = pCurDVRX->GetRefRowSize();
         size_t nCurWindowSizeY = pCurDVRY->GetRefRowSize();
-        if(nCurWindowSizeX == nCurWindowSizeY)
-        {
-            ss << "    for( ";
-            if (!pCurDVRX->IsStartFixed() && pCurDVRX->IsEndFixed()) {
-                ss << "int i = gid0; i < " << nCurWindowSizeX;
-                ss << " && i < " << pCurDVRX->GetArrayLength() << " && i < ";
-                ss << pCurDVRY->GetArrayLength() << "; i++){\n";
-                ss << "        if(isnan(";
-                ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ") ||";
-                ss << " isnan("<< vSubArguments[1]->GenSlidingWindowDeclRef();
-                ss << ")) {\n";
-                ss << "            arg0 = 0.0;\n";
-                ss << "            arg1 = 0.0;\n";
-                ss << "            --cnt;\n";
-                ss << "        }\n";
-                ss << "else{\n";
-                ss << "        arg0 = ";
-                ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
-                ss << "        arg1 = ";
-                ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n";
-                ss << "}\n";
-                ss << "        ++cnt;\n";
-                ss << "        vSum0 += arg0;\n";
-                ss << "        vSum1 += arg1;\n";
-                ss << "    }\n";
-            }
-            else if (pCurDVRX->IsStartFixed() && !pCurDVRX->IsEndFixed()) {
-                ss << "int i = 0; i < gid0 + " << nCurWindowSizeX << " && ";
-                ss << " i < " << pCurDVRX->GetArrayLength() << " && ";
-                ss << " i < " << pCurDVRY->GetArrayLength() << "; i++) {\n";
-                ss << "        if(isnan(";
-                ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ") ||";
-                ss << " isnan(" << vSubArguments[1]->GenSlidingWindowDeclRef();
-                ss << ")) {\n";
-                ss << "            arg0 = 0.0;\n";
-                ss << "            arg1 = 0.0;\n";
-                ss << "            --cnt;\n";
-                ss << "        }\n";
-                ss << "else{\n";
-                ss << "        arg0 = ";
-                ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
-                ss << "        arg1 = ";
-                ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";}\n";
-                ss << "        ++cnt;\n";
-                ss << "        vSum0 += arg0;\n";
-                ss << "        vSum1 += arg1;\n";
-                ss << "    }\n";
-            }
-            else if (pCurDVRX->IsStartFixed() && pCurDVRX->IsEndFixed()) {
-                ss << "int i = 0; i < " << nCurWindowSizeX << " && i < ";
-                ss << pCurDVRX->GetArrayLength() << " && i < ";
-                ss << pCurDVRY->GetArrayLength() << "; i++) {\n";
-                ss << "        if(isnan(";
-                ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ") ||";
-                ss << " isnan(" << vSubArguments[1]->GenSlidingWindowDeclRef();
-                ss << ")) {\n";
-                ss << "            arg0 = 0.0;\n";
-                ss << "            arg1 = 0.0;\n";
-                ss << "            --cnt;\n";
-                ss << "        }\n";
-                ss << "else{\n";
-                ss << "        arg0 = ";
-                ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
-                ss << "        arg1 = ";
-                ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";}\n";
-                ss << "        ++cnt;\n";
-                ss << "        vSum0 += arg0;\n";
-                ss << "        vSum1 += arg1;\n";
-                ss << "    }\n";
-            }
-            else {
-                ss << "int i = 0; i < " << nCurWindowSizeX << " && ";
-                ss << " i + gid0 < " << pCurDVRX->GetArrayLength();
-                ss << " && i + gid0 < " << pCurDVRY->GetArrayLength();
-                ss << "; i++) {\n";
-                ss << "if ((isnan(";
-                ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ")) || ";
-                ss << "(isnan("<< vSubArguments[1]->GenSlidingWindowDeclRef();
-                ss << ")))  {\n";
-                ss << "            arg0 = 0.0;\n";
-                ss << "            arg1 = 0.0;\n";
-                ss << "            --cnt;\n";
-                ss << "        }\n";
-                ss << "        else {\n";
-                ss << "            arg0 = ";
-                ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
-                ss << "            arg1 = ";
-                ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n";
-                ss << "        }\n";
-                ss << "        ++cnt;\n";
-                ss << "        vSum0 += arg0;\n";
-                ss << "        vSum1 += arg1;\n";
-                ss << "    }\n";
-            }
-            ss << "    if(cnt < 1) {\n";
-            ss << "        return CreateDoubleError(NoValue);\n";
+        if(nCurWindowSizeX != nCurWindowSizeY)
+        {
+            throw Unhandled(__FILE__, __LINE__);
+        }
+
+        ss << "    for( ";
+        if (!pCurDVRX->IsStartFixed() && pCurDVRX->IsEndFixed()) {
+            ss << "int i = gid0; i < " << nCurWindowSizeX;
+            ss << " && i < " << pCurDVRX->GetArrayLength() << " && i < ";
+            ss << pCurDVRY->GetArrayLength() << "; i++){\n";
+            ss << "        if(isnan(";
+            ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ") ||";
+            ss << " isnan("<< vSubArguments[1]->GenSlidingWindowDeclRef();
+            ss << ")) {\n";
+            ss << "            arg0 = 0.0;\n";
+            ss << "            arg1 = 0.0;\n";
+            ss << "            --cnt;\n";
+            ss << "        }\n";
+            ss << "else{\n";
+            ss << "        arg0 = ";
+            ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
+            ss << "        arg1 = ";
+            ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n";
+            ss << "}\n";
+            ss << "        ++cnt;\n";
+            ss << "        vSum0 += arg0;\n";
+            ss << "        vSum1 += arg1;\n";
             ss << "    }\n";
-            ss << "    else {\n";
-            ss << "        vMean0 = vSum0 / cnt;\n";
-            ss << "        vMean1 = vSum1 / cnt;\n";
-            ss << "    for(";
-            if (!pCurDVRX->IsStartFixed() && pCurDVRX->IsEndFixed()) {
-                ss << "int i = gid0; i < " << nCurWindowSizeX;
-                ss << " && i < " << pCurDVRX->GetArrayLength() << " && i < ";
-                ss << pCurDVRY->GetArrayLength() << "; i++){\n";
-                ss << "        if(isnan(";
-                ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ") ||";
-                ss << " isnan(" << vSubArguments[1]->GenSlidingWindowDeclRef();
-                ss << ")){\n";
-                ss << "            arg0 = vMean0;\n";
-                ss << "            arg1 = vMean1;\n";
-                ss << "        }\n";
-                ss << "        else{\n";
-                ss << "            arg0 = ";
-                ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
-                ss << "            arg1 = ";
-                ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";}\n";
-                ss << "        vSum += (arg0 - vMean0) * (arg1 - vMean1);\n";
-                ss << "    }\n";
-            }
-            else if (pCurDVRX->IsStartFixed() && !pCurDVRX->IsEndFixed()) {
-                ss << "int i = 0; i < gid0 + " << nCurWindowSizeX << " && ";
-                ss << " i < " << pCurDVRX->GetArrayLength() << " && ";
-                ss << " i < " << pCurDVRY->GetArrayLength() << "; i++) {\n";
-                ss << "        if(isnan(";
-                ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ") || ";
-                ss << "isnan(" << vSubArguments[1]->GenSlidingWindowDeclRef();
-                ss << ")) {\n";
-                ss << "            arg0 = vMean0;\n";
-                ss << "            arg1 = vMean1;\n";
-                ss << "        }\n";
-                ss << "else{\n";
-                ss << "        arg0 = ";
-                ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
-                ss << "        arg1 = ";
-                ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";}\n";
-                ss << "        vSum += (arg0 - vMean0) * (arg1 - vMean1);\n";
-                ss << "    }\n";
-            }
-            else if (pCurDVRX->IsStartFixed() && pCurDVRX->IsEndFixed()) {
-                ss << "int i = 0; i < " << nCurWindowSizeX << " && i < ";
-                ss << pCurDVRX->GetArrayLength() << " && i < ";
-                ss << pCurDVRY->GetArrayLength() << "; i++) {\n";
-                ss << "        if(isnan(";
-                ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ") || ";
-                ss << "isnan(" << vSubArguments[1]->GenSlidingWindowDeclRef();
-                ss << ")) {\n";
-                ss << "            arg0 = vMean0;\n";
-                ss << "            arg1 = vMean1;\n";
-                ss << "        }\n";
-                ss << "else{\n";
-                ss << "        arg0 = ";
-                ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
-                ss << "        arg1 = ";
-                ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";}\n";
-                ss << "        vSum += (arg0 - vMean0) * (arg1 - vMean1);\n";
-                ss << "    }\n";
-            }
-            else {
-                ss << "int i = 0; i < " << nCurWindowSizeX << " && ";
-                ss << " i + gid0 < " << pCurDVRX->GetArrayLength();
-                ss << " && i + gid0 < " << pCurDVRX->GetArrayLength();
-                ss << "; i++) {\n";
-                ss << "if((isnan(";
-                ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ")) || ";
-                ss << "(isnan(" << vSubArguments[1]->GenSlidingWindowDeclRef();
-                ss << ")))  {\n";
-                ss << "            arg0 = vMean0;\n";
-                ss << "            arg1 = vMean1;\n";
-                ss << "        }\n";
-                ss << "        else{\n";
-                ss << "            arg0 = ";
-                ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
-                ss << "            arg1 = ";
-                ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n";
-                ss << "        }\n";
-                ss << "        vSum += (arg0 - vMean0) * (arg1 - vMean1);\n";
-                ss << "    }\n";
-            }
-            ss << "    return vSum / cnt;\n";
+        }
+        else if (pCurDVRX->IsStartFixed() && !pCurDVRX->IsEndFixed()) {
+            ss << "int i = 0; i < gid0 + " << nCurWindowSizeX << " && ";
+            ss << " i < " << pCurDVRX->GetArrayLength() << " && ";
+            ss << " i < " << pCurDVRY->GetArrayLength() << "; i++) {\n";
+            ss << "        if(isnan(";
+            ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ") ||";
+            ss << " isnan(" << vSubArguments[1]->GenSlidingWindowDeclRef();
+            ss << ")) {\n";
+            ss << "            arg0 = 0.0;\n";
+            ss << "            arg1 = 0.0;\n";
+            ss << "            --cnt;\n";
+            ss << "        }\n";
+            ss << "else{\n";
+            ss << "        arg0 = ";
+            ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
+            ss << "        arg1 = ";
+            ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";}\n";
+            ss << "        ++cnt;\n";
+            ss << "        vSum0 += arg0;\n";
+            ss << "        vSum1 += arg1;\n";
             ss << "    }\n";
-            ss << "}";
         }
-        else
-        {
-            throw Unhandled(__FILE__, __LINE__);
+        else if (pCurDVRX->IsStartFixed() && pCurDVRX->IsEndFixed()) {
+            ss << "int i = 0; i < " << nCurWindowSizeX << " && i < ";
+            ss << pCurDVRX->GetArrayLength() << " && i < ";
+            ss << pCurDVRY->GetArrayLength() << "; i++) {\n";
+            ss << "        if(isnan(";
+            ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ") ||";
+            ss << " isnan(" << vSubArguments[1]->GenSlidingWindowDeclRef();
+            ss << ")) {\n";
+            ss << "            arg0 = 0.0;\n";
+            ss << "            arg1 = 0.0;\n";
+            ss << "            --cnt;\n";
+            ss << "        }\n";
+            ss << "else{\n";
+            ss << "        arg0 = ";
+            ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
+            ss << "        arg1 = ";
+            ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";}\n";
+            ss << "        ++cnt;\n";
+            ss << "        vSum0 += arg0;\n";
+            ss << "        vSum1 += arg1;\n";
+            ss << "    }\n";
         }
+        else {
+            ss << "int i = 0; i < " << nCurWindowSizeX << " && ";
+            ss << " i + gid0 < " << pCurDVRX->GetArrayLength();
+            ss << " && i + gid0 < " << pCurDVRY->GetArrayLength();
+            ss << "; i++) {\n";
+            ss << "if ((isnan(";
+            ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ")) || ";
+            ss << "(isnan("<< vSubArguments[1]->GenSlidingWindowDeclRef();
+            ss << ")))  {\n";
+            ss << "            arg0 = 0.0;\n";
+            ss << "            arg1 = 0.0;\n";
+            ss << "            --cnt;\n";
+            ss << "        }\n";
+            ss << "        else {\n";
+            ss << "            arg0 = ";
+            ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
+            ss << "            arg1 = ";
+            ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n";
+            ss << "        }\n";
+            ss << "        ++cnt;\n";
+            ss << "        vSum0 += arg0;\n";
+            ss << "        vSum1 += arg1;\n";
+            ss << "    }\n";
+        }
+        ss << "    if(cnt < 1) {\n";
+        ss << "        return CreateDoubleError(NoValue);\n";
+        ss << "    }\n";
+        ss << "    else {\n";
+        ss << "        vMean0 = vSum0 / cnt;\n";
+        ss << "        vMean1 = vSum1 / cnt;\n";
+        ss << "    for(";
+        if (!pCurDVRX->IsStartFixed() && pCurDVRX->IsEndFixed()) {
+            ss << "int i = gid0; i < " << nCurWindowSizeX;
+            ss << " && i < " << pCurDVRX->GetArrayLength() << " && i < ";
+            ss << pCurDVRY->GetArrayLength() << "; i++){\n";
+            ss << "        if(isnan(";
+            ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ") ||";
+            ss << " isnan(" << vSubArguments[1]->GenSlidingWindowDeclRef();
+            ss << ")){\n";
+            ss << "            arg0 = vMean0;\n";
+            ss << "            arg1 = vMean1;\n";
+            ss << "        }\n";
+            ss << "        else{\n";
+            ss << "            arg0 = ";
+            ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
+            ss << "            arg1 = ";
+            ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";}\n";
+            ss << "        vSum += (arg0 - vMean0) * (arg1 - vMean1);\n";
+            ss << "    }\n";
+        }
+        else if (pCurDVRX->IsStartFixed() && !pCurDVRX->IsEndFixed()) {
+            ss << "int i = 0; i < gid0 + " << nCurWindowSizeX << " && ";
+            ss << " i < " << pCurDVRX->GetArrayLength() << " && ";
+            ss << " i < " << pCurDVRY->GetArrayLength() << "; i++) {\n";
+            ss << "        if(isnan(";
+            ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ") || ";
+            ss << "isnan(" << vSubArguments[1]->GenSlidingWindowDeclRef();
+            ss << ")) {\n";
+            ss << "            arg0 = vMean0;\n";
+            ss << "            arg1 = vMean1;\n";
+            ss << "        }\n";
+            ss << "else{\n";
+            ss << "        arg0 = ";
+            ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
+            ss << "        arg1 = ";
+            ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";}\n";
+            ss << "        vSum += (arg0 - vMean0) * (arg1 - vMean1);\n";
+            ss << "    }\n";
+        }
+        else if (pCurDVRX->IsStartFixed() && pCurDVRX->IsEndFixed()) {
+            ss << "int i = 0; i < " << nCurWindowSizeX << " && i < ";
+            ss << pCurDVRX->GetArrayLength() << " && i < ";
+            ss << pCurDVRY->GetArrayLength() << "; i++) {\n";
+            ss << "        if(isnan(";
+            ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ") || ";
+            ss << "isnan(" << vSubArguments[1]->GenSlidingWindowDeclRef();
+            ss << ")) {\n";
+            ss << "            arg0 = vMean0;\n";
+            ss << "            arg1 = vMean1;\n";
+            ss << "        }\n";
+            ss << "else{\n";
+            ss << "        arg0 = ";
+            ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
+            ss << "        arg1 = ";
+            ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";}\n";
+            ss << "        vSum += (arg0 - vMean0) * (arg1 - vMean1);\n";
+            ss << "    }\n";
+        }
+        else {
+            ss << "int i = 0; i < " << nCurWindowSizeX << " && ";
+            ss << " i + gid0 < " << pCurDVRX->GetArrayLength();
+            ss << " && i + gid0 < " << pCurDVRX->GetArrayLength();
+            ss << "; i++) {\n";
+            ss << "if((isnan(";
+            ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ")) || ";
+            ss << "(isnan(" << vSubArguments[1]->GenSlidingWindowDeclRef();
+            ss << ")))  {\n";
+            ss << "            arg0 = vMean0;\n";
+            ss << "            arg1 = vMean1;\n";
+            ss << "        }\n";
+            ss << "        else{\n";
+            ss << "            arg0 = ";
+            ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
+            ss << "            arg1 = ";
+            ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n";
+            ss << "        }\n";
+            ss << "        vSum += (arg0 - vMean0) * (arg1 - vMean1);\n";
+            ss << "    }\n";
+        }
+        ss << "    return vSum / cnt;\n";
+        ss << "    }\n";
+        ss << "}";
+
         }
         else {
         ss << "    int cnt0 = 0,cnt1 = 0;\n";
diff --git a/sc/source/core/opencl/opbase.cxx b/sc/source/core/opencl/opbase.cxx
index 7755610a14f3..e197ea002bb3 100644
--- a/sc/source/core/opencl/opbase.cxx
+++ b/sc/source/core/opencl/opbase.cxx
@@ -251,23 +251,22 @@ void CheckVariables::CheckSubArgumentIsNan( std::stringstream& ss,
         ss << vSubArguments[i]->GenSlidingWindowDeclRef();
         ss << ";\n";
     }
-    if (vSubArguments[i]->GetFormulaToken()->GetType() == formula::svDouble ||
-        vSubArguments[i]->GetFormulaToken()->GetOpCode() != ocPush)
-    {
-        ss << "    if(";
-        ss << "isnan(";
-        ss << vSubArguments[i]->GenSlidingWindowDeclRef();
-        ss << "))\n";
-        ss << "        tmp";
-        ss << i;
-        ss << "=0;\n    else \n";
-        ss << "        tmp";
-        ss << i;
-        ss << "=";
-        ss << vSubArguments[i]->GenSlidingWindowDeclRef();
-        ss << ";\n";
+    if (vSubArguments[i]->GetFormulaToken()->GetType() != formula::svDouble &&
+        vSubArguments[i]->GetFormulaToken()->GetOpCode() == ocPush)
+        return;
 
-    }
+    ss << "    if(";
+    ss << "isnan(";
+    ss << vSubArguments[i]->GenSlidingWindowDeclRef();
+    ss << "))\n";
+    ss << "        tmp";
+    ss << i;
+    ss << "=0;\n    else \n";
+    ss << "        tmp";
+    ss << i;
+    ss << "=";
+    ss << vSubArguments[i]->GenSlidingWindowDeclRef();
+    ss << ";\n";
 
 }
 
diff --git a/sc/source/core/tool/formulalogger.cxx b/sc/source/core/tool/formulalogger.cxx
index cb072c7a4ef8..3f600cdb9743 100644
--- a/sc/source/core/tool/formulalogger.cxx
+++ b/sc/source/core/tool/formulalogger.cxx
@@ -75,20 +75,20 @@ struct FormulaLogger::GroupScope::Impl
     {
         ++mrLogger.mnNestLevel;
 
-        if (mbOutputEnabled)
-        {
-            sc::TokenStringContext aCxt(&rDoc, rDoc.GetGrammar());
-            OUString aFormula = rCell.GetCode()->CreateString(aCxt, rCell.aPos);
+        if (!mbOutputEnabled)
+            return;
 
-            mrLogger.write(maPrefix);
-            mrLogger.writeNestLevel();
+        sc::TokenStringContext aCxt(&rDoc, rDoc.GetGrammar());
+        OUString aFormula = rCell.GetCode()->CreateString(aCxt, rCell.aPos);
 
-            mrLogger.writeAscii("-- enter (formula='");
-            mrLogger.write(aFormula);
-            mrLogger.writeAscii("', size=");
-            mrLogger.write(rCell.GetSharedLength());
-            mrLogger.writeAscii(")\n");
-        }
+        mrLogger.write(maPrefix);
+        mrLogger.writeNestLevel();
+
+        mrLogger.writeAscii("-- enter (formula='");
+        mrLogger.write(aFormula);
+        mrLogger.writeAscii("', size=");
+        mrLogger.write(rCell.GetSharedLength());
+        mrLogger.writeAscii(")\n");
     }
 
     ~Impl()
diff --git a/sc/source/ui/StatisticsDialogs/RandomNumberGeneratorDialog.cxx b/sc/source/ui/StatisticsDialogs/RandomNumberGeneratorDialog.cxx
index 9127f879d17a..dea6561288a6 100644
--- a/sc/source/ui/StatisticsDialogs/RandomNumberGeneratorDialog.cxx
+++ b/sc/source/ui/StatisticsDialogs/RandomNumberGeneratorDialog.cxx
@@ -132,19 +132,19 @@ void ScRandomNumberGeneratorDialog::Close()
 
 void ScRandomNumberGeneratorDialog::SetReference( const ScRange& rReferenceRange, ScDocument& rDoc )
 {
-    if (mxInputRangeEdit->GetWidget()->get_sensitive())
-    {
-        if ( rReferenceRange.aStart != rReferenceRange.aEnd )
-            RefInputStart(mxInputRangeEdit.get());
+    if (!mxInputRangeEdit->GetWidget()->get_sensitive())
+        return;
 
-        maInputRange = rReferenceRange;
+    if ( rReferenceRange.aStart != rReferenceRange.aEnd )
+        RefInputStart(mxInputRangeEdit.get());
 
-        OUString aReferenceString(maInputRange.Format(rDoc, ScRefFlags::RANGE_ABS_3D, rDoc.GetAddressConvention()));
-        mxInputRangeEdit->SetRefString( aReferenceString );
+    maInputRange = rReferenceRange;
 
-        mxButtonApply->set_sensitive(true);
-        mxButtonOk->set_sensitive(true);
-    }

... etc. - the rest is truncated


More information about the Libreoffice-commits mailing list