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

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Wed Aug 12 07:58:50 UTC 2020


 sc/source/ui/view/cellsh3.cxx         |  138 ++---
 sc/source/ui/view/dbfunc.cxx          |   88 +--
 sc/source/ui/view/dbfunc3.cxx         |  336 ++++++------
 sc/source/ui/view/drawvie3.cxx        |  118 ++--
 sc/source/ui/view/drawvie4.cxx        |   64 +-
 sc/source/ui/view/drawview.cxx        |  214 ++++----
 sc/source/ui/view/editsh.cxx          |   26 
 sc/source/ui/view/gridmerg.cxx        |   60 +-
 sc/source/ui/view/gridwin.cxx         |  642 ++++++++++++------------
 sc/source/ui/view/gridwin3.cxx        |   22 
 sc/source/ui/view/gridwin4.cxx        |  536 ++++++++++----------
 sc/source/ui/view/gridwin_dbgutil.cxx |   34 -
 sc/source/ui/view/hdrcont.cxx         |   64 +-
 sc/source/ui/view/invmerge.cxx        |   65 +-
 sc/source/ui/view/notemark.cxx        |   90 +--
 sc/source/ui/view/olinewin.cxx        |   38 -
 sc/source/ui/view/output.cxx          |  420 ++++++++--------
 sc/source/ui/view/output2.cxx         |   92 +--
 sc/source/ui/view/preview.cxx         |  498 +++++++++----------
 sc/source/ui/view/prevloc.cxx         |   84 +--
 sc/source/ui/view/prevwsh.cxx         |   64 +-
 sc/source/ui/view/printfun.cxx        |  253 ++++-----
 sc/source/ui/view/select.cxx          |   94 +--
 sc/source/ui/view/tabcont.cxx         |   70 +-
 sc/source/ui/view/tabview.cxx         |  252 ++++-----
 sc/source/ui/view/tabview2.cxx        |  300 +++++------
 sc/source/ui/view/tabview3.cxx        |  888 +++++++++++++++++-----------------
 sc/source/ui/view/tabview4.cxx        |  134 ++---
 sc/source/ui/view/tabview5.cxx        |  307 +++++------
 sc/source/ui/view/tabvwsh2.cxx        |  102 +--
 sc/source/ui/view/tabvwsh4.cxx        |  376 +++++++-------
 sc/source/ui/view/tabvwshb.cxx        |   76 +-
 sc/source/ui/view/tabvwshc.cxx        |   46 -
 sc/source/ui/view/viewdata.cxx        |  212 ++++----
 sc/source/ui/view/viewfun2.cxx        |  561 ++++++++++-----------
 sc/source/ui/view/viewfun3.cxx        |  114 ++--
 sc/source/ui/view/viewfun6.cxx        |   58 +-
 sc/source/ui/view/viewfunc.cxx        |   75 +-
 38 files changed, 3805 insertions(+), 3806 deletions(-)

New commits:
commit df37937018fe8e87dad5dd97689632044ba56de3
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Sun Aug 9 11:59:18 2020 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Wed Aug 12 09:58:12 2020 +0200

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

diff --git a/sc/source/ui/view/cellsh3.cxx b/sc/source/ui/view/cellsh3.cxx
index df42b593bc3d..c7a40214c053 100644
--- a/sc/source/ui/view/cellsh3.cxx
+++ b/sc/source/ui/view/cellsh3.cxx
@@ -70,85 +70,85 @@ OString escapeJSON(const OUString &aStr)
 void lcl_lokGetWholeFunctionList()
 {
     const SfxViewShell* pViewShell = SfxViewShell::Current();
-    if (comphelper::LibreOfficeKit::isActive()
-        && pViewShell && pViewShell->isLOKMobilePhone())
+    if (!(comphelper::LibreOfficeKit::isActive()
+        && pViewShell && pViewShell->isLOKMobilePhone()))
+        return;
+
+    const ScFunctionList* pFuncList = ScGlobal::GetStarCalcFunctionList();
+    sal_uInt32 nListCount = pFuncList->GetCount();
+    std::set<OUString> aFuncNameOrderedSet;
+    for(sal_uInt32 i = 0; i < nListCount; ++i)
     {
-        const ScFunctionList* pFuncList = ScGlobal::GetStarCalcFunctionList();
-        sal_uInt32 nListCount = pFuncList->GetCount();
-        std::set<OUString> aFuncNameOrderedSet;
-        for(sal_uInt32 i = 0; i < nListCount; ++i)
+        const ScFuncDesc* pDesc = pFuncList->GetFunction( i );
+        if ( pDesc->mxFuncName )
         {
-            const ScFuncDesc* pDesc = pFuncList->GetFunction( i );
-            if ( pDesc->mxFuncName )
-            {
-                aFuncNameOrderedSet.insert(*pDesc->mxFuncName);
-            }
+            aFuncNameOrderedSet.insert(*pDesc->mxFuncName);
         }
-        ScFunctionMgr* pFuncManager = ScGlobal::GetStarCalcFunctionMgr();
-        if (pFuncManager && aFuncNameOrderedSet.size())
-        {
-            OStringBuffer aPayload;
-            aPayload.append("{ \"wholeList\": true, ");
-            aPayload.append("\"categories\": [ ");
+    }
+    ScFunctionMgr* pFuncManager = ScGlobal::GetStarCalcFunctionMgr();
+    if (!(pFuncManager && aFuncNameOrderedSet.size()))
+        return;
 
-            formula::FormulaHelper aHelper(pFuncManager);
-            sal_uInt32 nCategoryCount = pFuncManager->getCount();
-            for (sal_uInt32 i = 0; i < nCategoryCount; ++i)
-            {
-                OUString sCategoryName = ScFunctionMgr::GetCategoryName(i);
-                aPayload.append("{");
-                aPayload.append("\"name\": \"");
-                aPayload.append(escapeJSON(sCategoryName));
-                aPayload.append("\"}, ");
-            }
-            sal_Int32 nLen = aPayload.getLength();
-            aPayload[nLen - 2] = ' ';
-            aPayload[nLen - 1] = ']';
-            aPayload.append(", ");
-
-            OUString aDescFuncNameStr;
-            aPayload.append("\"functions\": [ ");
-            sal_uInt32 nCurIndex = 0;
-            for (const OUString& aFuncNameStr : aFuncNameOrderedSet)
+    OStringBuffer aPayload;
+    aPayload.append("{ \"wholeList\": true, ");
+    aPayload.append("\"categories\": [ ");
+
+    formula::FormulaHelper aHelper(pFuncManager);
+    sal_uInt32 nCategoryCount = pFuncManager->getCount();
+    for (sal_uInt32 i = 0; i < nCategoryCount; ++i)
+    {
+        OUString sCategoryName = ScFunctionMgr::GetCategoryName(i);
+        aPayload.append("{");
+        aPayload.append("\"name\": \"");
+        aPayload.append(escapeJSON(sCategoryName));
+        aPayload.append("\"}, ");
+    }
+    sal_Int32 nLen = aPayload.getLength();
+    aPayload[nLen - 2] = ' ';
+    aPayload[nLen - 1] = ']';
+    aPayload.append(", ");
+
+    OUString aDescFuncNameStr;
+    aPayload.append("\"functions\": [ ");
+    sal_uInt32 nCurIndex = 0;
+    for (const OUString& aFuncNameStr : aFuncNameOrderedSet)
+    {
+        aDescFuncNameStr = aFuncNameStr + "()";
+        sal_Int32 nNextFStart = 0;
+        const formula::IFunctionDescription* ppFDesc;
+        ::std::vector< OUString > aArgs;
+        OUString eqPlusFuncName = "=" + aDescFuncNameStr;
+        if ( aHelper.GetNextFunc( eqPlusFuncName, false, nNextFStart, nullptr, &ppFDesc, &aArgs ) )
+        {
+            if ( ppFDesc && !ppFDesc->getFunctionName().isEmpty() )
             {
-                aDescFuncNameStr = aFuncNameStr + "()";
-                sal_Int32 nNextFStart = 0;
-                const formula::IFunctionDescription* ppFDesc;
-                ::std::vector< OUString > aArgs;
-                OUString eqPlusFuncName = "=" + aDescFuncNameStr;
-                if ( aHelper.GetNextFunc( eqPlusFuncName, false, nNextFStart, nullptr, &ppFDesc, &aArgs ) )
+                if (ppFDesc->getCategory())
                 {
-                    if ( ppFDesc && !ppFDesc->getFunctionName().isEmpty() )
-                    {
-                        if (ppFDesc->getCategory())
-                        {
-                            aPayload.append("{");
-                            aPayload.append("\"index\": ");
-                            aPayload.append(OString::number(nCurIndex));
-                            aPayload.append(", ");
-                            aPayload.append("\"category\": ");
-                            aPayload.append(OString::number(ppFDesc->getCategory()->getNumber()));
-                            aPayload.append(", ");
-                            aPayload.append("\"signature\": \"");
-                            aPayload.append(escapeJSON(ppFDesc->getSignature()));
-                            aPayload.append("\", ");
-                            aPayload.append("\"description\": \"");
-                            aPayload.append(escapeJSON(ppFDesc->getDescription()));
-                            aPayload.append("\"}, ");
-                        }
-                    }
+                    aPayload.append("{");
+                    aPayload.append("\"index\": ");
+                    aPayload.append(OString::number(nCurIndex));
+                    aPayload.append(", ");
+                    aPayload.append("\"category\": ");
+                    aPayload.append(OString::number(ppFDesc->getCategory()->getNumber()));
+                    aPayload.append(", ");
+                    aPayload.append("\"signature\": \"");
+                    aPayload.append(escapeJSON(ppFDesc->getSignature()));
+                    aPayload.append("\", ");
+                    aPayload.append("\"description\": \"");
+                    aPayload.append(escapeJSON(ppFDesc->getDescription()));
+                    aPayload.append("\"}, ");
                 }
-                ++nCurIndex;
             }
-            nLen = aPayload.getLength();
-            aPayload[nLen - 2] = ' ';
-            aPayload[nLen - 1] = ']';
-            aPayload.append(" }");
-
-            OString s = aPayload.makeStringAndClear();
-            pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_CALC_FUNCTION_LIST, s.getStr());
         }
+        ++nCurIndex;
     }
+    nLen = aPayload.getLength();
+    aPayload[nLen - 2] = ' ';
+    aPayload[nLen - 1] = ']';
+    aPayload.append(" }");
+
+    OString s = aPayload.makeStringAndClear();
+    pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_CALC_FUNCTION_LIST, s.getStr());
 }
 
 } // end namespace
diff --git a/sc/source/ui/view/dbfunc.cxx b/sc/source/ui/view/dbfunc.cxx
index ba99e9185a8c..2f559ddea045 100644
--- a/sc/source/ui/view/dbfunc.cxx
+++ b/sc/source/ui/view/dbfunc.cxx
@@ -55,24 +55,24 @@ void ScDBFunc::GotoDBArea( const OUString& rDBName )
     ScDocument* pDoc = GetViewData().GetDocument();
     ScDBCollection* pDBCol = pDoc->GetDBCollection();
     ScDBData* pData = pDBCol->getNamedDBs().findByUpperName(ScGlobal::getCharClassPtr()->uppercase(rDBName));
-    if (pData)
-    {
-        SCTAB nTab = 0;
-        SCCOL nStartCol = 0;
-        SCROW nStartRow = 0;
-        SCCOL nEndCol = 0;
-        SCROW nEndRow = 0;
-
-        pData->GetArea( nTab, nStartCol, nStartRow, nEndCol, nEndRow );
-        SetTabNo( nTab );
-
-        MoveCursorAbs( nStartCol, nStartRow, SC_FOLLOW_JUMP,
-                       false, false );  // bShift,bControl
-        DoneBlockMode();
-        InitBlockMode( nStartCol, nStartRow, nTab );
-        MarkCursor( nEndCol, nEndRow, nTab );
-        SelectionChanged();
-    }
+    if (!pData)
+        return;
+
+    SCTAB nTab = 0;
+    SCCOL nStartCol = 0;
+    SCROW nStartRow = 0;
+    SCCOL nEndCol = 0;
+    SCROW nEndRow = 0;
+
+    pData->GetArea( nTab, nStartCol, nStartRow, nEndCol, nEndRow );
+    SetTabNo( nTab );
+
+    MoveCursorAbs( nStartCol, nStartRow, SC_FOLLOW_JUMP,
+                   false, false );  // bShift,bControl
+    DoneBlockMode();
+    InitBlockMode( nStartCol, nStartRow, nTab );
+    MarkCursor( nEndCol, nEndRow, nTab );
+    SelectionChanged();
 }
 
 //  search current datarange for sort / filter
@@ -237,37 +237,37 @@ void ScDBFunc::Query( const ScQueryParam& rQueryParam, const ScRange* pAdvSource
     ScDBDocFunc aDBDocFunc( *pDocSh );
     bool bSuccess = aDBDocFunc.Query( nTab, rQueryParam, pAdvSource, bRecord, false );
 
-    if (bSuccess)
-    {
-        bool bCopy = !rQueryParam.bInplace;
-        if (bCopy)
-        {
-            //  mark target range (data base range has been set up if applicable)
-            ScDocument& rDoc = pDocSh->GetDocument();
-            ScDBData* pDestData = rDoc.GetDBAtCursor(
-                                            rQueryParam.nDestCol, rQueryParam.nDestRow,
-                                            rQueryParam.nDestTab, ScDBDataPortion::TOP_LEFT );
-            if (pDestData)
-            {
-                ScRange aDestRange;
-                pDestData->GetArea(aDestRange);
-                MarkRange( aDestRange );
-            }
-        }
+    if (!bSuccess)
+        return;
 
-        if (!bCopy)
+    bool bCopy = !rQueryParam.bInplace;
+    if (bCopy)
+    {
+        //  mark target range (data base range has been set up if applicable)
+        ScDocument& rDoc = pDocSh->GetDocument();
+        ScDBData* pDestData = rDoc.GetDBAtCursor(
+                                        rQueryParam.nDestCol, rQueryParam.nDestRow,
+                                        rQueryParam.nDestTab, ScDBDataPortion::TOP_LEFT );
+        if (pDestData)
         {
-            ScTabViewShell::notifyAllViewsSheetGeomInvalidation(
-                GetViewData().GetViewShell(),
-                false /* bColumns */, true /* bRows */,
-                false /* bSizes*/, true /* bHidden */, true /* bFiltered */,
-                false /* bGroups */, nTab);
-            UpdateScrollBars(ROW_HEADER);
-            SelectionChanged();     // for attribute states (filtered rows are ignored)
+            ScRange aDestRange;
+            pDestData->GetArea(aDestRange);
+            MarkRange( aDestRange );
         }
+    }
 
-        GetViewData().GetBindings().Invalidate( SID_UNFILTER );
+    if (!bCopy)
+    {
+        ScTabViewShell::notifyAllViewsSheetGeomInvalidation(
+            GetViewData().GetViewShell(),
+            false /* bColumns */, true /* bRows */,
+            false /* bSizes*/, true /* bHidden */, true /* bFiltered */,
+            false /* bGroups */, nTab);
+        UpdateScrollBars(ROW_HEADER);
+        SelectionChanged();     // for attribute states (filtered rows are ignored)
     }
+
+    GetViewData().GetBindings().Invalidate( SID_UNFILTER );
 }
 
 //  autofilter-buttons show / hide
diff --git a/sc/source/ui/view/dbfunc3.cxx b/sc/source/ui/view/dbfunc3.cxx
index 429725af03dd..5f19e0f7af59 100644
--- a/sc/source/ui/view/dbfunc3.cxx
+++ b/sc/source/ui/view/dbfunc3.cxx
@@ -475,128 +475,128 @@ void ScDBFunc::DoSubTotals( const ScSubTotalParam& rParam, bool bRecord,
         }
     }
 
-    if (bOk)
-    {
-        ScDocShellModificator aModificator( *pDocSh );
-
-        ScSubTotalParam aNewParam( rParam );        // change end of range
-        ScDocumentUniquePtr pUndoDoc;
-        std::unique_ptr<ScOutlineTable> pUndoTab;
-        std::unique_ptr<ScRangeName> pUndoRange;
-        std::unique_ptr<ScDBCollection> pUndoDB;
-
-        if (bRecord)                                        // record old data
-        {
-            bool bOldFilter = bDo && rParam.bDoSort;
-            SCTAB nTabCount = rDoc.GetTableCount();
-            pUndoDoc.reset(new ScDocument( SCDOCMODE_UNDO ));
-            ScOutlineTable* pTable = rDoc.GetOutlineTable( nTab );
-            if (pTable)
-            {
-                pUndoTab.reset(new ScOutlineTable( *pTable ));
-
-                SCCOLROW nOutStartCol;                          // row/column status
-                SCCOLROW nOutStartRow;
-                SCCOLROW nOutEndCol;
-                SCCOLROW nOutEndRow;
-                pTable->GetColArray().GetRange( nOutStartCol, nOutEndCol );
-                pTable->GetRowArray().GetRange( nOutStartRow, nOutEndRow );
-
-                pUndoDoc->InitUndo( &rDoc, nTab, nTab, true, true );
-                rDoc.CopyToDocument( static_cast<SCCOL>(nOutStartCol), 0, nTab, static_cast<SCCOL>(nOutEndCol), rDoc.MaxRow(), nTab, InsertDeleteFlags::NONE, false, *pUndoDoc );
-                rDoc.CopyToDocument( 0, nOutStartRow, nTab, rDoc.MaxCol(), nOutEndRow, nTab, InsertDeleteFlags::NONE, false, *pUndoDoc );
-            }
-            else
-                pUndoDoc->InitUndo( &rDoc, nTab, nTab, false, bOldFilter );
+    if (!bOk)
+        return;
 
-            // record data range - including filter results
-            rDoc.CopyToDocument( 0,rParam.nRow1+1,nTab, rDoc.MaxCol(),rParam.nRow2,nTab,
-                                    InsertDeleteFlags::ALL, false, *pUndoDoc );
+    ScDocShellModificator aModificator( *pDocSh );
 
-            // all formulas for reference
-            rDoc.CopyToDocument( 0,0,0, rDoc.MaxCol(),rDoc.MaxRow(),nTabCount-1,
-                                        InsertDeleteFlags::FORMULA, false, *pUndoDoc );
+    ScSubTotalParam aNewParam( rParam );        // change end of range
+    ScDocumentUniquePtr pUndoDoc;
+    std::unique_ptr<ScOutlineTable> pUndoTab;
+    std::unique_ptr<ScRangeName> pUndoRange;
+    std::unique_ptr<ScDBCollection> pUndoDB;
 
-            // database and other ranges
-            ScRangeName* pDocRange = rDoc.GetRangeName();
-            if (!pDocRange->empty())
-                pUndoRange.reset(new ScRangeName( *pDocRange ));
-            ScDBCollection* pDocDB = rDoc.GetDBCollection();
-            if (!pDocDB->empty())
-                pUndoDB.reset(new ScDBCollection( *pDocDB ));
+    if (bRecord)                                        // record old data
+    {
+        bool bOldFilter = bDo && rParam.bDoSort;
+        SCTAB nTabCount = rDoc.GetTableCount();
+        pUndoDoc.reset(new ScDocument( SCDOCMODE_UNDO ));
+        ScOutlineTable* pTable = rDoc.GetOutlineTable( nTab );
+        if (pTable)
+        {
+            pUndoTab.reset(new ScOutlineTable( *pTable ));
+
+            SCCOLROW nOutStartCol;                          // row/column status
+            SCCOLROW nOutStartRow;
+            SCCOLROW nOutEndCol;
+            SCCOLROW nOutEndRow;
+            pTable->GetColArray().GetRange( nOutStartCol, nOutEndCol );
+            pTable->GetRowArray().GetRange( nOutStartRow, nOutEndRow );
+
+            pUndoDoc->InitUndo( &rDoc, nTab, nTab, true, true );
+            rDoc.CopyToDocument( static_cast<SCCOL>(nOutStartCol), 0, nTab, static_cast<SCCOL>(nOutEndCol), rDoc.MaxRow(), nTab, InsertDeleteFlags::NONE, false, *pUndoDoc );
+            rDoc.CopyToDocument( 0, nOutStartRow, nTab, rDoc.MaxCol(), nOutEndRow, nTab, InsertDeleteFlags::NONE, false, *pUndoDoc );
         }
+        else
+            pUndoDoc->InitUndo( &rDoc, nTab, nTab, false, bOldFilter );
+
+        // record data range - including filter results
+        rDoc.CopyToDocument( 0,rParam.nRow1+1,nTab, rDoc.MaxCol(),rParam.nRow2,nTab,
+                                InsertDeleteFlags::ALL, false, *pUndoDoc );
+
+        // all formulas for reference
+        rDoc.CopyToDocument( 0,0,0, rDoc.MaxCol(),rDoc.MaxRow(),nTabCount-1,
+                                    InsertDeleteFlags::FORMULA, false, *pUndoDoc );
+
+        // database and other ranges
+        ScRangeName* pDocRange = rDoc.GetRangeName();
+        if (!pDocRange->empty())
+            pUndoRange.reset(new ScRangeName( *pDocRange ));
+        ScDBCollection* pDocDB = rDoc.GetDBCollection();
+        if (!pDocDB->empty())
+            pUndoDB.reset(new ScDBCollection( *pDocDB ));
+    }
 
-        ScOutlineTable* pOut = rDoc.GetOutlineTable( nTab );
-        if (pOut)
+    ScOutlineTable* pOut = rDoc.GetOutlineTable( nTab );
+    if (pOut)
+    {
+        // Remove all existing outlines in the specified range.
+        ScOutlineArray& rRowArray = pOut->GetRowArray();
+        sal_uInt16 nDepth = rRowArray.GetDepth();
+        for (sal_uInt16 i = 0; i < nDepth; ++i)
         {
-            // Remove all existing outlines in the specified range.
-            ScOutlineArray& rRowArray = pOut->GetRowArray();
-            sal_uInt16 nDepth = rRowArray.GetDepth();
-            for (sal_uInt16 i = 0; i < nDepth; ++i)
-            {
-                bool bSize;
-                rRowArray.Remove(aNewParam.nRow1, aNewParam.nRow2, bSize);
-            }
+            bool bSize;
+            rRowArray.Remove(aNewParam.nRow1, aNewParam.nRow2, bSize);
         }
+    }
 
-        if (rParam.bReplace)
-            rDoc.RemoveSubTotals( nTab, aNewParam );
-        bool bSuccess = true;
-        if (bDo)
+    if (rParam.bReplace)
+        rDoc.RemoveSubTotals( nTab, aNewParam );
+    bool bSuccess = true;
+    if (bDo)
+    {
+        // Sort
+        if ( rParam.bDoSort || pForceNewSort )
         {
-            // Sort
-            if ( rParam.bDoSort || pForceNewSort )
-            {
-                pDBData->SetArea( nTab, aNewParam.nCol1,aNewParam.nRow1, aNewParam.nCol2,aNewParam.nRow2 );
+            pDBData->SetArea( nTab, aNewParam.nCol1,aNewParam.nRow1, aNewParam.nCol2,aNewParam.nRow2 );
 
-                // set subtotal fields before sorting
-                // (duplicate values are dropped, so that they can be called again)
+            // set subtotal fields before sorting
+            // (duplicate values are dropped, so that they can be called again)
 
-                ScSortParam aOldSort;
-                pDBData->GetSortParam( aOldSort );
-                ScSortParam aSortParam( aNewParam, pForceNewSort ? *pForceNewSort : aOldSort );
-                Sort( aSortParam, false, false );
-            }
-
-            bSuccess = rDoc.DoSubTotals( nTab, aNewParam );
+            ScSortParam aOldSort;
+            pDBData->GetSortParam( aOldSort );
+            ScSortParam aSortParam( aNewParam, pForceNewSort ? *pForceNewSort : aOldSort );
+            Sort( aSortParam, false, false );
         }
-        ScRange aDirtyRange( aNewParam.nCol1, aNewParam.nRow1, nTab,
-            aNewParam.nCol2, aNewParam.nRow2, nTab );
-        rDoc.SetDirty( aDirtyRange, true );
 
-        if (bRecord)
-        {
-            pDocSh->GetUndoManager()->AddUndoAction(
-                std::make_unique<ScUndoSubTotals>( pDocSh, nTab,
-                                        rParam, aNewParam.nRow2,
-                                        std::move(pUndoDoc), std::move(pUndoTab), // pUndoDBData,
-                                        std::move(pUndoRange), std::move(pUndoDB) ) );
-        }
+        bSuccess = rDoc.DoSubTotals( nTab, aNewParam );
+    }
+    ScRange aDirtyRange( aNewParam.nCol1, aNewParam.nRow1, nTab,
+        aNewParam.nCol2, aNewParam.nRow2, nTab );
+    rDoc.SetDirty( aDirtyRange, true );
 
-        if (!bSuccess)
-        {
-            // "Can not insert any rows"
-            ErrorMessage(STR_MSSG_DOSUBTOTALS_2);
-        }
+    if (bRecord)
+    {
+        pDocSh->GetUndoManager()->AddUndoAction(
+            std::make_unique<ScUndoSubTotals>( pDocSh, nTab,
+                                    rParam, aNewParam.nRow2,
+                                    std::move(pUndoDoc), std::move(pUndoTab), // pUndoDBData,
+                                    std::move(pUndoRange), std::move(pUndoDB) ) );
+    }
 
-                                                    // store
-        pDBData->SetSubTotalParam( aNewParam );
-        pDBData->SetArea( nTab, aNewParam.nCol1,aNewParam.nRow1, aNewParam.nCol2,aNewParam.nRow2 );
-        rDoc.CompileDBFormula();
+    if (!bSuccess)
+    {
+        // "Can not insert any rows"
+        ErrorMessage(STR_MSSG_DOSUBTOTALS_2);
+    }
 
-        DoneBlockMode();
-        InitOwnBlockMode();
-        rMark.SetMarkArea( ScRange( aNewParam.nCol1,aNewParam.nRow1,nTab,
-                                    aNewParam.nCol2,aNewParam.nRow2,nTab ) );
-        MarkDataChanged();
+                                                // store
+    pDBData->SetSubTotalParam( aNewParam );
+    pDBData->SetArea( nTab, aNewParam.nCol1,aNewParam.nRow1, aNewParam.nCol2,aNewParam.nRow2 );
+    rDoc.CompileDBFormula();
 
-        pDocSh->PostPaint(ScRange(0, 0, nTab, rDoc.MaxCol(), rDoc.MaxRow(), nTab),
-                          PaintPartFlags::Grid | PaintPartFlags::Left | PaintPartFlags::Top | PaintPartFlags::Size);
+    DoneBlockMode();
+    InitOwnBlockMode();
+    rMark.SetMarkArea( ScRange( aNewParam.nCol1,aNewParam.nRow1,nTab,
+                                aNewParam.nCol2,aNewParam.nRow2,nTab ) );
+    MarkDataChanged();
 
-        aModificator.SetDocumentModified();
+    pDocSh->PostPaint(ScRange(0, 0, nTab, rDoc.MaxCol(), rDoc.MaxRow(), nTab),
+                      PaintPartFlags::Grid | PaintPartFlags::Left | PaintPartFlags::Top | PaintPartFlags::Size);
 
-        SelectionChanged();
-    }
+    aModificator.SetDocumentModified();
+
+    SelectionChanged();
 }
 
 // consolidate
@@ -1945,86 +1945,86 @@ void ScDBFunc::SetDataPilotDetails(bool bShow, const OUString* pNewDimensionName
 {
     ScDPObject* pDPObj = GetViewData().GetDocument()->GetDPAtCursor( GetViewData().GetCurX(),
                                         GetViewData().GetCurY(), GetViewData().GetTabNo() );
-    if ( pDPObj )
-    {
-        ScDPUniqueStringSet aEntries;
-        long nSelectDimension = -1;
-        GetSelectedMemberList( aEntries, nSelectDimension );
+    if ( !pDPObj )
+        return;
 
-        if (!aEntries.empty())
-        {
-            bool bIsDataLayout;
-            OUString aDimName = pDPObj->GetDimName( nSelectDimension, bIsDataLayout );
-            if ( !bIsDataLayout )
-            {
-                ScDPSaveData aData( *pDPObj->GetSaveData() );
-                ScDPSaveDimension* pDim = aData.GetDimensionByName( aDimName );
+    ScDPUniqueStringSet aEntries;
+    long nSelectDimension = -1;
+    GetSelectedMemberList( aEntries, nSelectDimension );
 
-                if ( bShow && pNewDimensionName )
-                {
-                    //  add the new dimension with the same orientation, at the end
+    if (aEntries.empty())
+        return;
 
-                    ScDPSaveDimension* pNewDim = aData.GetDimensionByName( *pNewDimensionName );
-                    ScDPSaveDimension* pDuplicated = nullptr;
-                    if ( pNewDim->GetOrientation() == sheet::DataPilotFieldOrientation_DATA )
-                    {
-                        // Need to duplicate the dimension, create column/row in addition to data:
-                        // The duplicated dimension inherits the existing settings, pNewDim is modified below.
-                        pDuplicated = aData.DuplicateDimension( *pNewDimensionName );
-                    }
+    bool bIsDataLayout;
+    OUString aDimName = pDPObj->GetDimName( nSelectDimension, bIsDataLayout );
+    if ( bIsDataLayout )
+        return;
 
-                    css::sheet::DataPilotFieldOrientation nOrientation = pDim->GetOrientation();
-                    pNewDim->SetOrientation( nOrientation );
+    ScDPSaveData aData( *pDPObj->GetSaveData() );
+    ScDPSaveDimension* pDim = aData.GetDimensionByName( aDimName );
 
-                    long nPosition = LONG_MAX;
-                    aData.SetPosition( pNewDim, nPosition );
+    if ( bShow && pNewDimensionName )
+    {
+        //  add the new dimension with the same orientation, at the end
 
-                    ScDPSaveDimension* pDataLayout = aData.GetDataLayoutDimension();
-                    if ( pDataLayout->GetOrientation() == nOrientation &&
-                         aData.GetDataDimensionCount() <= 1 )
-                    {
-                        // If there is only one data dimension, the data layout dimension
-                        // must still be the last one in its orientation.
-                        aData.SetPosition( pDataLayout, nPosition );
-                    }
+        ScDPSaveDimension* pNewDim = aData.GetDimensionByName( *pNewDimensionName );
+        ScDPSaveDimension* pDuplicated = nullptr;
+        if ( pNewDim->GetOrientation() == sheet::DataPilotFieldOrientation_DATA )
+        {
+            // Need to duplicate the dimension, create column/row in addition to data:
+            // The duplicated dimension inherits the existing settings, pNewDim is modified below.
+            pDuplicated = aData.DuplicateDimension( *pNewDimensionName );
+        }
 
-                    if ( pDuplicated )
-                    {
-                        // The duplicated (data) dimension needs to be behind the original dimension
-                        aData.SetPosition( pDuplicated, nPosition );
-                    }
+        css::sheet::DataPilotFieldOrientation nOrientation = pDim->GetOrientation();
+        pNewDim->SetOrientation( nOrientation );
 
-                    //  Hide details for all visible members (selected are changed below).
-                    //! Use all members from source level instead (including non-visible)?
+        long nPosition = LONG_MAX;
+        aData.SetPosition( pNewDim, nPosition );
 
-                    ScDPUniqueStringSet aVisibleEntries;
-                    pDPObj->GetMemberResultNames( aVisibleEntries, nSelectDimension );
+        ScDPSaveDimension* pDataLayout = aData.GetDataLayoutDimension();
+        if ( pDataLayout->GetOrientation() == nOrientation &&
+             aData.GetDataDimensionCount() <= 1 )
+        {
+            // If there is only one data dimension, the data layout dimension
+            // must still be the last one in its orientation.
+            aData.SetPosition( pDataLayout, nPosition );
+        }
 
-                    for (const OUString& aVisName : aVisibleEntries)
-                    {
-                        ScDPSaveMember* pMember = pDim->GetMemberByName( aVisName );
-                        pMember->SetShowDetails( false );
-                    }
-                }
+        if ( pDuplicated )
+        {
+            // The duplicated (data) dimension needs to be behind the original dimension
+            aData.SetPosition( pDuplicated, nPosition );
+        }
 
-                for (const auto& rEntry : aEntries)
-                {
-                    ScDPSaveMember* pMember = pDim->GetMemberByName(rEntry);
-                    pMember->SetShowDetails( bShow );
-                }
+        //  Hide details for all visible members (selected are changed below).
+        //! Use all members from source level instead (including non-visible)?
 
-                // apply changes
-                ScDBDocFunc aFunc( *GetViewData().GetDocShell() );
-                std::unique_ptr<ScDPObject> pNewObj(new ScDPObject( *pDPObj ));
-                pNewObj->SetSaveData( aData );
-                aFunc.DataPilotUpdate( pDPObj, pNewObj.get(), true, false );
-                pNewObj.reset();
+        ScDPUniqueStringSet aVisibleEntries;
+        pDPObj->GetMemberResultNames( aVisibleEntries, nSelectDimension );
 
-                // unmark cell selection
-                Unmark();
-            }
+        for (const OUString& aVisName : aVisibleEntries)
+        {
+            ScDPSaveMember* pMember = pDim->GetMemberByName( aVisName );
+            pMember->SetShowDetails( false );
         }
     }
+
+    for (const auto& rEntry : aEntries)
+    {
+        ScDPSaveMember* pMember = pDim->GetMemberByName(rEntry);
+        pMember->SetShowDetails( bShow );
+    }
+
+    // apply changes
+    ScDBDocFunc aFunc( *GetViewData().GetDocShell() );
+    std::unique_ptr<ScDPObject> pNewObj(new ScDPObject( *pDPObj ));
+    pNewObj->SetSaveData( aData );
+    aFunc.DataPilotUpdate( pDPObj, pNewObj.get(), true, false );
+    pNewObj.reset();
+
+    // unmark cell selection
+    Unmark();
 }
 
 void ScDBFunc::ShowDataPilotSourceData( ScDPObject& rDPObj, const Sequence<sheet::DataPilotFieldFilter>& rFilters )
diff --git a/sc/source/ui/view/drawvie3.cxx b/sc/source/ui/view/drawvie3.cxx
index 9a657ddb7361..83dcd0305fc5 100644
--- a/sc/source/ui/view/drawvie3.cxx
+++ b/sc/source/ui/view/drawvie3.cxx
@@ -57,27 +57,27 @@ ScDrawView::ScDrawView(
 
 void ScDrawView::SetPageAnchored()
 {
-    if( AreObjectsMarked() )
-    {
-        const SdrMarkList* pMark = &GetMarkedObjectList();
-        const size_t nCount = pMark->GetMarkCount();
-
-        BegUndo(ScResId(SCSTR_UNDO_PAGE_ANCHOR));
-        for( size_t i=0; i<nCount; ++i )
-        {
-            SdrObject* pObj = pMark->GetMark(i)->GetMarkedSdrObj();
-            AddUndo (std::make_unique<ScUndoAnchorData>( pObj, pDoc, nTab ));
-            ScDrawLayer::SetPageAnchored( *pObj );
-        }
-        EndUndo();
+    if( !AreObjectsMarked() )
+        return;
 
-        if ( pViewData )
-            pViewData->GetDocShell()->SetDrawModified();
+    const SdrMarkList* pMark = &GetMarkedObjectList();
+    const size_t nCount = pMark->GetMarkCount();
 
-        // Remove the anchor object.
-        maHdlList.RemoveAllByKind(SdrHdlKind::Anchor);
-        maHdlList.RemoveAllByKind(SdrHdlKind::Anchor_TR);
+    BegUndo(ScResId(SCSTR_UNDO_PAGE_ANCHOR));
+    for( size_t i=0; i<nCount; ++i )
+    {
+        SdrObject* pObj = pMark->GetMark(i)->GetMarkedSdrObj();
+        AddUndo (std::make_unique<ScUndoAnchorData>( pObj, pDoc, nTab ));
+        ScDrawLayer::SetPageAnchored( *pObj );
     }
+    EndUndo();
+
+    if ( pViewData )
+        pViewData->GetDocShell()->SetDrawModified();
+
+    // Remove the anchor object.
+    maHdlList.RemoveAllByKind(SdrHdlKind::Anchor);
+    maHdlList.RemoveAllByKind(SdrHdlKind::Anchor_TR);
 }
 
 void ScDrawView::SetCellAnchored(bool bResizeWithCell)
@@ -85,27 +85,27 @@ void ScDrawView::SetCellAnchored(bool bResizeWithCell)
     if (!pDoc)
         return;
 
-    if( AreObjectsMarked() )
-    {
-        const SdrMarkList* pMark = &GetMarkedObjectList();
-        const size_t nCount = pMark->GetMarkCount();
+    if( !AreObjectsMarked() )
+        return;
 
-        BegUndo(ScResId(SCSTR_UNDO_CELL_ANCHOR));
-        for( size_t i=0; i<nCount; ++i )
-        {
-            SdrObject* pObj = pMark->GetMark(i)->GetMarkedSdrObj();
-            AddUndo (std::make_unique<ScUndoAnchorData>( pObj, pDoc, nTab ));
-            ScDrawLayer::SetCellAnchoredFromPosition(*pObj, *pDoc, nTab, bResizeWithCell);
-        }
-        EndUndo();
+    const SdrMarkList* pMark = &GetMarkedObjectList();
+    const size_t nCount = pMark->GetMarkCount();
 
-        if ( pViewData )
-        {
-            pViewData->GetDocShell()->SetDrawModified();
+    BegUndo(ScResId(SCSTR_UNDO_CELL_ANCHOR));
+    for( size_t i=0; i<nCount; ++i )
+    {
+        SdrObject* pObj = pMark->GetMark(i)->GetMarkedSdrObj();
+        AddUndo (std::make_unique<ScUndoAnchorData>( pObj, pDoc, nTab ));
+        ScDrawLayer::SetCellAnchoredFromPosition(*pObj, *pDoc, nTab, bResizeWithCell);
+    }
+    EndUndo();
 
-            // Set the anchor object.
-            AddCustomHdl();
-        }
+    if ( pViewData )
+    {
+        pViewData->GetDocShell()->SetDrawModified();
+
+        // Set the anchor object.
+        AddCustomHdl();
     }
 }
 
@@ -204,32 +204,32 @@ void ScDrawView::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
 
 void ScDrawView::UpdateIMap( SdrObject* pObj )
 {
-    if ( pViewData &&
+    if ( !(pViewData &&
          pViewData->GetViewShell()->GetViewFrame()->HasChildWindow( ScIMapChildWindowId() ) &&
-         pObj && ( dynamic_cast<const SdrGrafObj*>( pObj) != nullptr || dynamic_cast<const SdrOle2Obj*>( pObj) != nullptr ) )
-    {
-        Graphic     aGraphic;
-        TargetList  aTargetList;
-        SvxIMapInfo* pIMapInfo = SvxIMapInfo::GetIMapInfo( pObj );
-        const ImageMap* pImageMap = nullptr;
-        if ( pIMapInfo )
-            pImageMap = &pIMapInfo->GetImageMap();
-
-        // handle target list
-        SfxViewFrame::GetTargetList( aTargetList );
-
-        // handle graphics from object
-        if ( dynamic_cast<const SdrGrafObj*>( pObj) !=  nullptr )
-            aGraphic = static_cast<SdrGrafObj*>(pObj)->GetGraphic();
-        else
-        {
-            const Graphic* pGraphic = static_cast<const SdrOle2Obj*>(pObj)->GetGraphic();
-            if ( pGraphic )
-                aGraphic = *pGraphic;
-        }
+         pObj && ( dynamic_cast<const SdrGrafObj*>( pObj) != nullptr || dynamic_cast<const SdrOle2Obj*>( pObj) != nullptr )) )
+        return;
+
+    Graphic     aGraphic;
+    TargetList  aTargetList;
+    SvxIMapInfo* pIMapInfo = SvxIMapInfo::GetIMapInfo( pObj );
+    const ImageMap* pImageMap = nullptr;
+    if ( pIMapInfo )
+        pImageMap = &pIMapInfo->GetImageMap();
 
-        ScIMapDlgSet( aGraphic, pImageMap, &aTargetList, pObj );    // from imapwrap
+    // handle target list
+    SfxViewFrame::GetTargetList( aTargetList );
+
+    // handle graphics from object
+    if ( dynamic_cast<const SdrGrafObj*>( pObj) !=  nullptr )
+        aGraphic = static_cast<SdrGrafObj*>(pObj)->GetGraphic();
+    else
+    {
+        const Graphic* pGraphic = static_cast<const SdrOle2Obj*>(pObj)->GetGraphic();
+        if ( pGraphic )
+            aGraphic = *pGraphic;
     }
+
+    ScIMapDlgSet( aGraphic, pImageMap, &aTargetList, pObj );    // from imapwrap
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/view/drawvie4.cxx b/sc/source/ui/view/drawvie4.cxx
index 178f43c45f24..5c6364850308 100644
--- a/sc/source/ui/view/drawvie4.cxx
+++ b/sc/source/ui/view/drawvie4.cxx
@@ -56,48 +56,48 @@ Point aDragStartDiff;
 
 void ScDrawView::BeginDrag( vcl::Window* pWindow, const Point& rStartPos )
 {
-    if ( AreObjectsMarked() )
-    {
-        BrkAction();
+    if ( !AreObjectsMarked() )
+        return;
 
-        tools::Rectangle aMarkedRect = GetAllMarkedRect();
+    BrkAction();
 
-        aDragStartDiff = rStartPos - aMarkedRect.TopLeft();
+    tools::Rectangle aMarkedRect = GetAllMarkedRect();
 
-        bool bAnyOle, bOneOle;
-        const SdrMarkList& rMarkList = GetMarkedObjectList();
-        CheckOle( rMarkList, bAnyOle, bOneOle );
+    aDragStartDiff = rStartPos - aMarkedRect.TopLeft();
 
-        ScDocShellRef aDragShellRef;
-        if (bAnyOle)
-        {
-            aDragShellRef = new ScDocShell;     // DocShell needs a Ref immediately
-            aDragShellRef->DoInitNew();
-        }
-        ScDrawLayer::SetGlobalDrawPersist( aDragShellRef.get() );
-        std::unique_ptr<SdrModel> pModel(CreateMarkedObjModel());
-        ScDrawLayer::SetGlobalDrawPersist(nullptr);
+    bool bAnyOle, bOneOle;
+    const SdrMarkList& rMarkList = GetMarkedObjectList();
+    CheckOle( rMarkList, bAnyOle, bOneOle );
 
-        //  Charts now always copy their data in addition to the source reference, so
-        //  there's no need to call SchDLL::Update for the charts in the clipboard doc.
-        //  Update with the data (including NumberFormatter) from the live document would
-        //  also store the NumberFormatter in the clipboard chart (#88749#)
+    ScDocShellRef aDragShellRef;
+    if (bAnyOle)
+    {
+        aDragShellRef = new ScDocShell;     // DocShell needs a Ref immediately
+        aDragShellRef->DoInitNew();
+    }
+    ScDrawLayer::SetGlobalDrawPersist( aDragShellRef.get() );
+    std::unique_ptr<SdrModel> pModel(CreateMarkedObjModel());
+    ScDrawLayer::SetGlobalDrawPersist(nullptr);
 
-        ScDocShell* pDocSh = pViewData->GetDocShell();
+    //  Charts now always copy their data in addition to the source reference, so
+    //  there's no need to call SchDLL::Update for the charts in the clipboard doc.
+    //  Update with the data (including NumberFormatter) from the live document would
+    //  also store the NumberFormatter in the clipboard chart (#88749#)
 
-        TransferableObjectDescriptor aObjDesc;
-        pDocSh->FillTransferableObjectDescriptor( aObjDesc );
-        aObjDesc.maDisplayName = pDocSh->GetMedium()->GetURLObject().GetURLNoPass();
-        // maSize is set in ScDrawTransferObj ctor
+    ScDocShell* pDocSh = pViewData->GetDocShell();
 
-        rtl::Reference<ScDrawTransferObj> pTransferObj = new ScDrawTransferObj( std::move(pModel), pDocSh, aObjDesc );
+    TransferableObjectDescriptor aObjDesc;
+    pDocSh->FillTransferableObjectDescriptor( aObjDesc );
+    aObjDesc.maDisplayName = pDocSh->GetMedium()->GetURLObject().GetURLNoPass();
+    // maSize is set in ScDrawTransferObj ctor
 
-        pTransferObj->SetDrawPersist( aDragShellRef.get() );    // keep persist for ole objects alive
-        pTransferObj->SetDragSource( this );               // copies selection
+    rtl::Reference<ScDrawTransferObj> pTransferObj = new ScDrawTransferObj( std::move(pModel), pDocSh, aObjDesc );
 
-        SC_MOD()->SetDragObject( nullptr, pTransferObj.get() );     // for internal D&D
-        pTransferObj->StartDrag( pWindow, DND_ACTION_COPYMOVE | DND_ACTION_LINK );
-    }
+    pTransferObj->SetDrawPersist( aDragShellRef.get() );    // keep persist for ole objects alive
+    pTransferObj->SetDragSource( this );               // copies selection
+
+    SC_MOD()->SetDragObject( nullptr, pTransferObj.get() );     // for internal D&D
+    pTransferObj->StartDrag( pWindow, DND_ACTION_COPYMOVE | DND_ACTION_LINK );
 }
 
 namespace {
diff --git a/sc/source/ui/view/drawview.cxx b/sc/source/ui/view/drawview.cxx
index f15b6c57c310..4fe6c0cbdc76 100644
--- a/sc/source/ui/view/drawview.cxx
+++ b/sc/source/ui/view/drawview.cxx
@@ -209,34 +209,34 @@ void ScDrawView::InvalidateDrawTextAttrs()
 
 void ScDrawView::SetMarkedToLayer( SdrLayerID nLayerNo )
 {
-    if (AreObjectsMarked())
-    {
-        //  #i11702# use SdrUndoObjectLayerChange for undo
-        //  STR_UNDO_SELATTR is "Attributes" - should use a different text later
-        BegUndo( ScResId( STR_UNDO_SELATTR ) );
+    if (!AreObjectsMarked())
+        return;
+
+    //  #i11702# use SdrUndoObjectLayerChange for undo
+    //  STR_UNDO_SELATTR is "Attributes" - should use a different text later
+    BegUndo( ScResId( STR_UNDO_SELATTR ) );
 
-        const SdrMarkList& rMark = GetMarkedObjectList();
-        const size_t nCount = rMark.GetMarkCount();
-        for (size_t i=0; i<nCount; ++i)
+    const SdrMarkList& rMark = GetMarkedObjectList();
+    const size_t nCount = rMark.GetMarkCount();
+    for (size_t i=0; i<nCount; ++i)
+    {
+        SdrObject* pObj = rMark.GetMark(i)->GetMarkedSdrObj();
+        if ( dynamic_cast<const SdrUnoObj*>( pObj) ==  nullptr && (pObj->GetLayer() != SC_LAYER_INTERN) )
         {
-            SdrObject* pObj = rMark.GetMark(i)->GetMarkedSdrObj();
-            if ( dynamic_cast<const SdrUnoObj*>( pObj) ==  nullptr && (pObj->GetLayer() != SC_LAYER_INTERN) )
-            {
-                AddUndo( std::make_unique<SdrUndoObjectLayerChange>( *pObj, pObj->GetLayer(), nLayerNo) );
-                pObj->SetLayer( nLayerNo );
-            }
+            AddUndo( std::make_unique<SdrUndoObjectLayerChange>( *pObj, pObj->GetLayer(), nLayerNo) );
+            pObj->SetLayer( nLayerNo );
         }
+    }
 
-        EndUndo();
+    EndUndo();
 
-        //  repaint is done in SetLayer
+    //  repaint is done in SetLayer
 
-        pViewData->GetDocShell()->SetDrawModified();
+    pViewData->GetDocShell()->SetDrawModified();
 
-        //  check mark list now instead of later in a timer
-        CheckMarked();
-        MarkListHasChanged();
-    }
+    //  check mark list now instead of later in a timer
+    CheckMarked();
+    MarkListHasChanged();
 }
 
 bool ScDrawView::HasMarkedControl() const
@@ -332,17 +332,17 @@ void ScDrawView::RecalcScale()
     resetGridOffsetsForAllSdrPageViews();
 
     SdrPageView* pPV = GetSdrPageView();
-    if ( pViewData && pPV )
+    if ( !(pViewData && pPV) )
+        return;
+
+    if ( SdrPage* pPage = pPV->GetPage() )
     {
-        if ( SdrPage* pPage = pPV->GetPage() )
+        const size_t nCount = pPage->GetObjCount();
+        for ( size_t i = 0; i < nCount; ++i )
         {
-            const size_t nCount = pPage->GetObjCount();
-            for ( size_t i = 0; i < nCount; ++i )
-            {
-                SdrObject* pObj = pPage->GetObj( i );
-                // Align objects to nearest grid position
-                SyncForGrid( pObj );
-            }
+            SdrObject* pObj = pPage->GetObj( i );
+            // Align objects to nearest grid position
+            SyncForGrid( pObj );
         }
     }
 }
@@ -623,26 +623,26 @@ void ScDrawView::ModelHasChanged()
 
 void ScDrawView::UpdateUserViewOptions()
 {
-    if (pViewData)
-    {
-        const ScViewOptions&    rOpt = pViewData->GetOptions();
-        const ScGridOptions&    rGrid = rOpt.GetGridOptions();
+    if (!pViewData)
+        return;
 
-        SetDragStripes( rOpt.GetOption( VOPT_HELPLINES ) );
-        SetMarkHdlSizePixel( SC_HANDLESIZE_BIG );
+    const ScViewOptions&    rOpt = pViewData->GetOptions();
+    const ScGridOptions&    rGrid = rOpt.GetGridOptions();
 
-        SetGridVisible( rGrid.GetGridVisible() );
-        SetSnapEnabled( rGrid.GetUseGridSnap() );
-        SetGridSnap( rGrid.GetUseGridSnap() );
+    SetDragStripes( rOpt.GetOption( VOPT_HELPLINES ) );
+    SetMarkHdlSizePixel( SC_HANDLESIZE_BIG );
 
-        Fraction aFractX( rGrid.GetFieldDrawX(), rGrid.GetFieldDivisionX() + 1 );
-        Fraction aFractY( rGrid.GetFieldDrawY(), rGrid.GetFieldDivisionY() + 1 );
-        SetSnapGridWidth( aFractX, aFractY );
+    SetGridVisible( rGrid.GetGridVisible() );
+    SetSnapEnabled( rGrid.GetUseGridSnap() );
+    SetGridSnap( rGrid.GetUseGridSnap() );
 
-        SetGridCoarse( Size( rGrid.GetFieldDrawX(), rGrid.GetFieldDrawY() ) );
-        SetGridFine( Size( rGrid.GetFieldDrawX() / (rGrid.GetFieldDivisionX() + 1),
-                           rGrid.GetFieldDrawY() / (rGrid.GetFieldDivisionY() + 1) ) );
-    }
+    Fraction aFractX( rGrid.GetFieldDrawX(), rGrid.GetFieldDivisionX() + 1 );
+    Fraction aFractY( rGrid.GetFieldDrawY(), rGrid.GetFieldDivisionY() + 1 );
+    SetSnapGridWidth( aFractX, aFractY );
+
+    SetGridCoarse( Size( rGrid.GetFieldDrawX(), rGrid.GetFieldDrawY() ) );
+    SetGridFine( Size( rGrid.GetFieldDrawX() / (rGrid.GetFieldDivisionX() + 1),
+                       rGrid.GetFieldDrawY() / (rGrid.GetFieldDivisionY() + 1) ) );
 }
 
 SdrObject* ScDrawView::GetObjectByName(const OUString& rName)
@@ -705,26 +705,26 @@ void ScDrawView::SelectCurrentViewObject( const OUString& rName )
             }
         }
     }
-    if ( pFound )
+    if ( !pFound )
+        return;
+
+    ScTabView* pView = pViewData->GetView();
+    if ( nObjectTab != nTab )                               // switch sheet
+        pView->SetTabNo( nObjectTab );
+    DBG_ASSERT( nTab == nObjectTab, "Switching sheets did not work" );
+    pView->ScrollToObject( pFound );
+    if ( pFound->GetLayer() == SC_LAYER_BACK &&
+            !pViewData->GetViewShell()->IsDrawSelMode() &&
+            !pDoc->IsTabProtected( nTab ) &&
+            !pViewData->GetSfxDocShell()->IsReadOnly() )
     {
-        ScTabView* pView = pViewData->GetView();
-        if ( nObjectTab != nTab )                               // switch sheet
-            pView->SetTabNo( nObjectTab );
-        DBG_ASSERT( nTab == nObjectTab, "Switching sheets did not work" );
-        pView->ScrollToObject( pFound );
-        if ( pFound->GetLayer() == SC_LAYER_BACK &&
-                !pViewData->GetViewShell()->IsDrawSelMode() &&
-                !pDoc->IsTabProtected( nTab ) &&
-                !pViewData->GetSfxDocShell()->IsReadOnly() )
-        {
-            SdrLayer* pLayer = GetModel()->GetLayerAdmin().GetLayerPerID(SC_LAYER_BACK);
-            if (pLayer)
-                SetLayerLocked( pLayer->GetName(), false );
-        }
-        SdrPageView* pPV = GetSdrPageView();
-        const bool bUnMark = IsObjMarked(pFound);
-        MarkObj( pFound, pPV, bUnMark);
+        SdrLayer* pLayer = GetModel()->GetLayerAdmin().GetLayerPerID(SC_LAYER_BACK);
+        if (pLayer)
+            SetLayerLocked( pLayer->GetName(), false );
     }
+    SdrPageView* pPV = GetSdrPageView();
+    const bool bUnMark = IsObjMarked(pFound);
+    MarkObj( pFound, pPV, bUnMark);
 }
 
 bool ScDrawView::SelectObject( const OUString& rName )
@@ -933,61 +933,61 @@ void ScDrawView::SyncForGrid( SdrObject* pObj )
     ScSplitPos eWhich = pViewData->GetActivePart();
     ScGridWindow* pGridWin = pViewData->GetActiveWin();
     ScDrawObjData* pData = ScDrawLayer::GetObjData( pObj );
-    if ( pGridWin )
+    if ( !pGridWin )
+        return;
+
+    ScAddress aOldStt;
+    if( pData && pData->maStart.IsValid())
     {
-        ScAddress aOldStt;
-        if( pData && pData->maStart.IsValid())
-        {
-            aOldStt = pData->maStart;
-        }
-        else
-        {
-            // Page anchored object so...
-            // synthesise an anchor ( but don't attach it to
-            // the object as we want to maintain page anchoring )
-            ScDrawObjData aAnchor;
-            const tools::Rectangle aObjRect(pObj->GetLogicRect());
-            ScDrawLayer::GetCellAnchorFromPosition(
-                aObjRect,
-                aAnchor,
-                *pDoc,
-                GetTab());
-            aOldStt = aAnchor.maStart;
-        }
-        MapMode aDrawMode = pGridWin->GetDrawMapMode();
-        // find pos anchor position
-        Point aOldPos( pDoc->GetColOffset( aOldStt.Col(), aOldStt.Tab()  ), pDoc->GetRowOffset( aOldStt.Row(), aOldStt.Tab() ) );
-        aOldPos.setX( sc::TwipsToHMM( aOldPos.X() ) );
-        aOldPos.setY( sc::TwipsToHMM( aOldPos.Y() ) );
-        // find position of same point on the screen ( e.g. grid )
-        Point aCurPos =  pViewData->GetScrPos(  aOldStt.Col(), aOldStt.Row(), eWhich, true );
-        Point aCurPosHmm = pGridWin->PixelToLogic(aCurPos, aDrawMode );
-        Point aGridOff = aCurPosHmm - aOldPos;
-        // fdo#63878 Fix the X position for RTL Sheet
-        if( pDoc->IsNegativePage( GetTab() ) )
-            aGridOff.setX( aCurPosHmm.getX() + aOldPos.getX() );
+        aOldStt = pData->maStart;
     }
+    else
+    {
+        // Page anchored object so...
+        // synthesise an anchor ( but don't attach it to
+        // the object as we want to maintain page anchoring )
+        ScDrawObjData aAnchor;
+        const tools::Rectangle aObjRect(pObj->GetLogicRect());
+        ScDrawLayer::GetCellAnchorFromPosition(
+            aObjRect,
+            aAnchor,
+            *pDoc,
+            GetTab());
+        aOldStt = aAnchor.maStart;
+    }
+    MapMode aDrawMode = pGridWin->GetDrawMapMode();
+    // find pos anchor position
+    Point aOldPos( pDoc->GetColOffset( aOldStt.Col(), aOldStt.Tab()  ), pDoc->GetRowOffset( aOldStt.Row(), aOldStt.Tab() ) );
+    aOldPos.setX( sc::TwipsToHMM( aOldPos.X() ) );
+    aOldPos.setY( sc::TwipsToHMM( aOldPos.Y() ) );
+    // find position of same point on the screen ( e.g. grid )
+    Point aCurPos =  pViewData->GetScrPos(  aOldStt.Col(), aOldStt.Row(), eWhich, true );
+    Point aCurPosHmm = pGridWin->PixelToLogic(aCurPos, aDrawMode );
+    Point aGridOff = aCurPosHmm - aOldPos;
+    // fdo#63878 Fix the X position for RTL Sheet
+    if( pDoc->IsNegativePage( GetTab() ) )
+        aGridOff.setX( aCurPosHmm.getX() + aOldPos.getX() );
 }
 
 void ScDrawView::resetGridOffsetsForAllSdrPageViews()
 {
     SdrPageView* pPageView(GetSdrPageView());
 
-    if(nullptr != pPageView)
+    if(nullptr == pPageView)
+        return;
+
+    for(sal_uInt32 a(0); a < pPageView->PageWindowCount(); a++)
     {
-        for(sal_uInt32 a(0); a < pPageView->PageWindowCount(); a++)
+        SdrPageWindow* pPageWindow(pPageView->GetPageWindow(a));
+        assert(pPageWindow && "SdrView::SetMasterPagePaintCaching: Corrupt SdrPageWindow list (!)");
+
+        if(nullptr != pPageWindow)
         {
-            SdrPageWindow* pPageWindow(pPageView->GetPageWindow(a));
-            assert(pPageWindow && "SdrView::SetMasterPagePaintCaching: Corrupt SdrPageWindow list (!)");
+            sdr::contact::ObjectContact& rObjectContact(pPageWindow->GetObjectContact());
 
-            if(nullptr != pPageWindow)
+            if(rObjectContact.supportsGridOffsets())
             {
-                sdr::contact::ObjectContact& rObjectContact(pPageWindow->GetObjectContact());
-
-                if(rObjectContact.supportsGridOffsets())
-                {
-                    rObjectContact.resetAllGridOffsets();
-                }
+                rObjectContact.resetAllGridOffsets();
             }
         }
     }
diff --git a/sc/source/ui/view/editsh.cxx b/sc/source/ui/view/editsh.cxx
index 8460a59fb79d..11a100da976c 100644
--- a/sc/source/ui/view/editsh.cxx
+++ b/sc/source/ui/view/editsh.cxx
@@ -1330,23 +1330,23 @@ void ScEditShell::GetUndoState(SfxItemSet &rSet)
 void ScEditShell::ExecuteTrans( const SfxRequest& rReq )
 {
     TransliterationFlags nType = ScViewUtil::GetTransliterationType( rReq.GetSlot() );
-    if ( nType != TransliterationFlags::NONE )
-    {
-        ScInputHandler* pHdl = GetMyInputHdl();
-        assert(pHdl && "no ScInputHandler");
+    if ( nType == TransliterationFlags::NONE )
+        return;
 
-        EditView* pTopView   = pHdl->GetTopView();
-        EditView* pTableView = pHdl->GetTableView();
-        assert(pTableView && "no EditView");
+    ScInputHandler* pHdl = GetMyInputHdl();
+    assert(pHdl && "no ScInputHandler");
+
+    EditView* pTopView   = pHdl->GetTopView();
+    EditView* pTableView = pHdl->GetTableView();
+    assert(pTableView && "no EditView");
 
-        pHdl->DataChanging();
+    pHdl->DataChanging();
 
-        pTableView->TransliterateText( nType );
-        if (pTopView)
-            pTopView->TransliterateText( nType );
+    pTableView->TransliterateText( nType );
+    if (pTopView)
+        pTopView->TransliterateText( nType );
 
-        pHdl->DataChanged();
-    }
+    pHdl->DataChanged();
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/view/gridmerg.cxx b/sc/source/ui/view/gridmerg.cxx
index 5ab7ef8e266d..a07937207dc4 100644
--- a/sc/source/ui/view/gridmerg.cxx
+++ b/sc/source/ui/view/gridmerg.cxx
@@ -183,45 +183,45 @@ void ScGridMerger::AddVerLine(bool bWorksInPixels, long nX, long nY1, long nY2,
 
 void ScGridMerger::Flush()
 {
-    if (nCount)
+    if (!nCount)
+        return;
+
+    if (bVertical)
     {
-        if (bVertical)
+        if ( nCount == 1 )
+            pDev->DrawLine( Point( nVarStart, nFixStart ), Point( nVarStart, nFixEnd ) );
+        else
         {
-            if ( nCount == 1 )
-                pDev->DrawLine( Point( nVarStart, nFixStart ), Point( nVarStart, nFixEnd ) );
-            else
+            long nVarEnd = nVarStart + ( nCount - 1 ) * nVarDiff;
+            if ( nVarDiff < 0 )
             {
-                long nVarEnd = nVarStart + ( nCount - 1 ) * nVarDiff;
-                if ( nVarDiff < 0 )
-                {
-                    //  nVarDiff is negative in RTL layout mode
-                    //  Change the positions so DrawGrid is called with a positive distance
-                    //  (nVarStart / nVarDiff can be modified, aren't used after Flush)
-
-                    nVarDiff = -nVarDiff;
-                    long nTemp = nVarStart;
-                    nVarStart = nVarEnd;
-                    nVarEnd = nTemp;
-                }
-                pDev->DrawGrid( tools::Rectangle( nVarStart, nFixStart, nVarEnd, nFixEnd ),
-                                Size( nVarDiff, nFixEnd - nFixStart ),
-                                DrawGridFlags::VertLines );
+                //  nVarDiff is negative in RTL layout mode
+                //  Change the positions so DrawGrid is called with a positive distance
+                //  (nVarStart / nVarDiff can be modified, aren't used after Flush)
+
+                nVarDiff = -nVarDiff;
+                long nTemp = nVarStart;
+                nVarStart = nVarEnd;
+                nVarEnd = nTemp;
             }
+            pDev->DrawGrid( tools::Rectangle( nVarStart, nFixStart, nVarEnd, nFixEnd ),
+                            Size( nVarDiff, nFixEnd - nFixStart ),
+                            DrawGridFlags::VertLines );
         }
+    }
+    else
+    {
+        if ( nCount == 1 )
+            pDev->DrawLine( Point( nFixStart, nVarStart ), Point( nFixEnd, nVarStart ) );
         else
         {
-            if ( nCount == 1 )
-                pDev->DrawLine( Point( nFixStart, nVarStart ), Point( nFixEnd, nVarStart ) );
-            else
-            {
-                long nVarEnd = nVarStart + ( nCount - 1 ) * nVarDiff;
-                pDev->DrawGrid( tools::Rectangle( nFixStart, nVarStart, nFixEnd, nVarEnd ),
-                                Size( nFixEnd - nFixStart, nVarDiff ),
-                                DrawGridFlags::HorzLines );
-            }
+            long nVarEnd = nVarStart + ( nCount - 1 ) * nVarDiff;
+            pDev->DrawGrid( tools::Rectangle( nFixStart, nVarStart, nFixEnd, nVarEnd ),
+                            Size( nFixEnd - nFixStart, nVarDiff ),
+                            DrawGridFlags::HorzLines );
         }
-        nCount = 0;
     }
+    nCount = 0;
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/view/gridwin.cxx b/sc/source/ui/view/gridwin.cxx
index 0b07934fb0f6..887903286ca3 100644
--- a/sc/source/ui/view/gridwin.cxx
+++ b/sc/source/ui/view/gridwin.cxx
@@ -1832,26 +1832,26 @@ void ScGridWindow::HandleMouseButtonDown( const MouseEvent& rMEvt, MouseEventSta
 
             //      Gridwin - Selection Engine
 
-    if ( rMEvt.IsLeft() )
-    {
-        ScViewSelectionEngine* pSelEng = pViewData->GetView()->GetSelEngine();
-        pSelEng->SetWindow(this);
-        pSelEng->SetWhich(eWhich);
-        pSelEng->SetVisibleArea( tools::Rectangle(Point(), GetOutputSizePixel()) );
+    if ( !rMEvt.IsLeft() )
+        return;
 
-        //  SelMouseButtonDown on the View is still setting the bMoveIsShift flag
-        if ( pViewData->GetView()->SelMouseButtonDown( rMEvt ) )
+    ScViewSelectionEngine* pSelEng = pViewData->GetView()->GetSelEngine();
+    pSelEng->SetWindow(this);
+    pSelEng->SetWhich(eWhich);
+    pSelEng->SetVisibleArea( tools::Rectangle(Point(), GetOutputSizePixel()) );
+
+    //  SelMouseButtonDown on the View is still setting the bMoveIsShift flag
+    if ( pViewData->GetView()->SelMouseButtonDown( rMEvt ) )
+    {
+        if (IsMouseCaptured())
         {
-            if (IsMouseCaptured())
-            {
-                //  Tracking instead of CaptureMouse, so it can be canceled cleanly
-                //! Someday SelectionEngine should call StartTracking on its own!?!
-                ReleaseMouse();
-                StartTracking();
-            }
-            pViewData->GetMarkData().SetMarking(true);
-            return;
+            //  Tracking instead of CaptureMouse, so it can be canceled cleanly
+            //! Someday SelectionEngine should call StartTracking on its own!?!
+            ReleaseMouse();
+            StartTracking();
         }
+        pViewData->GetMarkData().SetMarking(true);
+        return;
     }
 }
 
@@ -2315,57 +2315,57 @@ void ScGridWindow::MouseButtonUp( const MouseEvent& rMEvt )
     //  SelMouseButtonDown is called only for left button, but SelMouseButtonUp would return
     //  sal_True for any call, so IsLeft must be checked here, too.
 
-    if ( rMEvt.IsLeft() && pViewData->GetView()->GetSelEngine()->SelMouseButtonUp( rMEvt ) )
-    {
-        pViewData->GetView()->SelectionChanged();
+    if ( !(rMEvt.IsLeft() && pViewData->GetView()->GetSelEngine()->SelMouseButtonUp( rMEvt )) )
+        return;
 
-        SfxDispatcher* pDisp = pViewData->GetViewShell()->GetDispatcher();
-        bool bFormulaMode = pScMod->IsFormulaMode();
-        OSL_ENSURE( pDisp || bFormulaMode, "Cursor moved on inactive View ?" );
+    pViewData->GetView()->SelectionChanged();
 
-        //  #i14927# execute SID_CURRENTCELL (for macro recording) only if there is no
-        //  multiple selection, so the argument string completely describes the selection,
-        //  and executing the slot won't change the existing selection (executing the slot
-        //  here and from a recorded macro is treated equally)
-        if ( pDisp && !bFormulaMode && !rMark.IsMultiMarked() )
-        {
-            OUString aAddr;                               // CurrentCell
-            if( rMark.IsMarked() )
-            {
-                ScRange aScRange;
-                rMark.GetMarkArea( aScRange );
-                aAddr = aScRange.Format(*pDoc, ScRefFlags::RANGE_ABS);
-                if ( aScRange.aStart == aScRange.aEnd )
-                {
-                    //  make sure there is a range selection string even for a single cell
-                    aAddr += ":" + aAddr;
-                }
+    SfxDispatcher* pDisp = pViewData->GetViewShell()->GetDispatcher();
+    bool bFormulaMode = pScMod->IsFormulaMode();
+    OSL_ENSURE( pDisp || bFormulaMode, "Cursor moved on inactive View ?" );
 
-                //! SID_MARKAREA does not exist anymore ???
-                //! What happens when selecting with the cursor ???
-            }
-            else                                        // only move cursor
+    //  #i14927# execute SID_CURRENTCELL (for macro recording) only if there is no
+    //  multiple selection, so the argument string completely describes the selection,
+    //  and executing the slot won't change the existing selection (executing the slot
+    //  here and from a recorded macro is treated equally)
+    if ( pDisp && !bFormulaMode && !rMark.IsMultiMarked() )
+    {
+        OUString aAddr;                               // CurrentCell
+        if( rMark.IsMarked() )
+        {
+            ScRange aScRange;
+            rMark.GetMarkArea( aScRange );
+            aAddr = aScRange.Format(*pDoc, ScRefFlags::RANGE_ABS);
+            if ( aScRange.aStart == aScRange.aEnd )
             {
-                ScAddress aScAddress( pViewData->GetCurX(), pViewData->GetCurY(), 0 );
-                aAddr = aScAddress.Format(ScRefFlags::ADDR_ABS);
+                //  make sure there is a range selection string even for a single cell
+                aAddr += ":" + aAddr;
             }
 
-            SfxStringItem aPosItem( SID_CURRENTCELL, aAddr );
-            // We don't want to align to the cursor position because if the
-            // cell cursor isn't visible after making selection, it would jump
-            // back to the origin of the selection where the cell cursor is.
-            SfxBoolItem aAlignCursorItem( FN_PARAM_2, false );
-            pDisp->ExecuteList(SID_CURRENTCELL,
-                    SfxCallMode::SLOT | SfxCallMode::RECORD,
-                    { &aPosItem, &aAlignCursorItem });
+            //! SID_MARKAREA does not exist anymore ???
+            //! What happens when selecting with the cursor ???
+        }
+        else                                        // only move cursor
+        {
+            ScAddress aScAddress( pViewData->GetCurX(), pViewData->GetCurY(), 0 );
+            aAddr = aScAddress.Format(ScRefFlags::ADDR_ABS);
+        }
 
-            pViewData->GetView()->InvalidateAttribs();
+        SfxStringItem aPosItem( SID_CURRENTCELL, aAddr );
+        // We don't want to align to the cursor position because if the
+        // cell cursor isn't visible after making selection, it would jump
+        // back to the origin of the selection where the cell cursor is.
+        SfxBoolItem aAlignCursorItem( FN_PARAM_2, false );
+        pDisp->ExecuteList(SID_CURRENTCELL,
+                SfxCallMode::SLOT | SfxCallMode::RECORD,
+                { &aPosItem, &aAlignCursorItem });
 
-        }
-        pViewData->GetViewShell()->SelectionChanged();
+        pViewData->GetView()->InvalidateAttribs();
 
-        return;
     }
+    pViewData->GetViewShell()->SelectionChanged();
+
+    return;
 }
 
 void ScGridWindow::FakeButtonUp()
@@ -2877,174 +2877,174 @@ void ScGridWindow::Command( const CommandEvent& rCEvt )
     if (bDisable)
         return;
 
-    if ( nCmd == CommandEventId::ContextMenu && !SC_MOD()->GetIsWaterCan() )
-    {
-        bool bMouse = rCEvt.IsMouseEvent();
-        if ( bMouse && nMouseStatus == SC_GM_IGNORE )
-            return;
+    if (nCmd != CommandEventId::ContextMenu || SC_MOD()->GetIsWaterCan())
+        return;
 
-        if (pViewData->IsAnyFillMode())
-        {
-            pViewData->GetView()->StopRefMode();
-            pViewData->ResetFillMode();
-        }
-        ReleaseMouse();
-        StopMarking();
+    bool bMouse = rCEvt.IsMouseEvent();
+    if ( bMouse && nMouseStatus == SC_GM_IGNORE )
+        return;
+
+    if (pViewData->IsAnyFillMode())
+    {
+        pViewData->GetView()->StopRefMode();
+        pViewData->ResetFillMode();
+    }
+    ReleaseMouse();
+    StopMarking();
 
-        Point aPosPixel = rCEvt.GetMousePosPixel();
-        Point aMenuPos = aPosPixel;
+    Point aPosPixel = rCEvt.GetMousePosPixel();
+    Point aMenuPos = aPosPixel;
 
-        SCCOL nCellX = -1;
-        SCROW nCellY = -1;
-        pViewData->GetPosFromPixel(aPosPixel.X(), aPosPixel.Y(), eWhich, nCellX, nCellY);
+    SCCOL nCellX = -1;
+    SCROW nCellY = -1;
+    pViewData->GetPosFromPixel(aPosPixel.X(), aPosPixel.Y(), eWhich, nCellX, nCellY);
 
-        bool bSpellError = false;
-        SCCOL nColSpellError = nCellX;
+    bool bSpellError = false;
+    SCCOL nColSpellError = nCellX;
 
-        if ( bMouse )
+    if ( bMouse )
+    {
+        ScDocument* pDoc = pViewData->GetDocument();
+        SCTAB nTab = pViewData->GetTabNo();
+        const ScTableProtection* pProtect = pDoc->GetTabProtection(nTab);
+        bool bSelectAllowed = true;
+        if ( pProtect && pProtect->isProtected() )
         {
-            ScDocument* pDoc = pViewData->GetDocument();
-            SCTAB nTab = pViewData->GetTabNo();
-            const ScTableProtection* pProtect = pDoc->GetTabProtection(nTab);
-            bool bSelectAllowed = true;
-            if ( pProtect && pProtect->isProtected() )
-            {
-                // This sheet is protected.  Check if a context menu is allowed on this cell.
-                bool bCellProtected = pDoc->HasAttrib(nCellX, nCellY, nTab, nCellX, nCellY, nTab, HasAttrFlags::Protected);
-                bool bSelProtected   = pProtect->isOptionEnabled(ScTableProtection::SELECT_LOCKED_CELLS);
-                bool bSelUnprotected = pProtect->isOptionEnabled(ScTableProtection::SELECT_UNLOCKED_CELLS);
+            // This sheet is protected.  Check if a context menu is allowed on this cell.
+            bool bCellProtected = pDoc->HasAttrib(nCellX, nCellY, nTab, nCellX, nCellY, nTab, HasAttrFlags::Protected);
+            bool bSelProtected   = pProtect->isOptionEnabled(ScTableProtection::SELECT_LOCKED_CELLS);
+            bool bSelUnprotected = pProtect->isOptionEnabled(ScTableProtection::SELECT_UNLOCKED_CELLS);
 
-                if (bCellProtected)
-                    bSelectAllowed = bSelProtected;
-                else
-                    bSelectAllowed = bSelUnprotected;
-            }
-            if (!bSelectAllowed)
-                // Selecting this cell is not allowed, neither is context menu.
-                return;
+            if (bCellProtected)
+                bSelectAllowed = bSelProtected;
+            else
+                bSelectAllowed = bSelUnprotected;
+        }
+        if (!bSelectAllowed)
+            // Selecting this cell is not allowed, neither is context menu.
+            return;
 
-            if (mpSpellCheckCxt)
+        if (mpSpellCheckCxt)
+        {
+            // Find the first string to the left for spell checking in case the current cell is empty.
+            ScAddress aPos(nCellX, nCellY, nTab);
+            ScRefCellValue aSpellCheckCell(*pDoc, aPos);
+            while (aSpellCheckCell.meType == CELLTYPE_NONE)
             {
-                // Find the first string to the left for spell checking in case the current cell is empty.
-                ScAddress aPos(nCellX, nCellY, nTab);
-                ScRefCellValue aSpellCheckCell(*pDoc, aPos);
-                while (aSpellCheckCell.meType == CELLTYPE_NONE)
-                {
-                    // Loop until we get the first non-empty cell in the row.
-                    aPos.IncCol(-1);
-                    if (aPos.Col() < 0)
-                        break;
+                // Loop until we get the first non-empty cell in the row.
+                aPos.IncCol(-1);
+                if (aPos.Col() < 0)
+                    break;
 
-                    aSpellCheckCell.assign(*pDoc, aPos);
-                }
+                aSpellCheckCell.assign(*pDoc, aPos);
+            }
 
-                if (aPos.Col() >= 0 && (aSpellCheckCell.meType == CELLTYPE_STRING || aSpellCheckCell.meType == CELLTYPE_EDIT))
-                    nColSpellError = aPos.Col();
+            if (aPos.Col() >= 0 && (aSpellCheckCell.meType == CELLTYPE_STRING || aSpellCheckCell.meType == CELLTYPE_EDIT))
+                nColSpellError = aPos.Col();
 
-                bSpellError = (mpSpellCheckCxt->isMisspelled(nColSpellError, nCellY));
-                if (bSpellError)
-                {
-                    // Check and see if a misspelled word is under the mouse pointer.
-                    bSpellError = IsSpellErrorAtPos(aPosPixel, nColSpellError, nCellY);
-                }
+            bSpellError = (mpSpellCheckCxt->isMisspelled(nColSpellError, nCellY));
+            if (bSpellError)
+            {
+                // Check and see if a misspelled word is under the mouse pointer.
+                bSpellError = IsSpellErrorAtPos(aPosPixel, nColSpellError, nCellY);
             }
-
-            //  #i18735# First select the item under the mouse pointer.
-            //  This can change the selection, and the view state (edit mode, etc).
-            SelectForContextMenu(aPosPixel, bSpellError ? nColSpellError : nCellX, nCellY);
         }
 
-        bool bDone = false;
-        bool bEdit = pViewData->HasEditView(eWhich);
+        //  #i18735# First select the item under the mouse pointer.
+        //  This can change the selection, and the view state (edit mode, etc).
+        SelectForContextMenu(aPosPixel, bSpellError ? nColSpellError : nCellX, nCellY);
+    }
 
-        if ( !bEdit )
+    bool bDone = false;
+    bool bEdit = pViewData->HasEditView(eWhich);
+
+    if ( !bEdit )
+    {
+            // Edit cell with spelling errors ?
+        if (bMouse && (GetEditUrl(aPosPixel) || bSpellError))
         {
-                // Edit cell with spelling errors ?
-            if (bMouse && (GetEditUrl(aPosPixel) || bSpellError))
-            {
-                //  GetEditUrlOrError has already moved the Cursor
+            //  GetEditUrlOrError has already moved the Cursor
 
-                pScMod->SetInputMode( SC_INPUT_TABLE );
-                bEdit = pViewData->HasEditView(eWhich);     // Did it work?
+            pScMod->SetInputMode( SC_INPUT_TABLE );
+            bEdit = pViewData->HasEditView(eWhich);     // Did it work?
 
-                OSL_ENSURE( bEdit, "Can not be switched in edit mode" );
-            }
+            OSL_ENSURE( bEdit, "Can not be switched in edit mode" );
         }
-        if ( bEdit )
-        {
-            EditView* pEditView = pViewData->GetEditView( eWhich );     // is then not 0
+    }
+    if ( bEdit )
+    {
+        EditView* pEditView = pViewData->GetEditView( eWhich );     // is then not 0
 
-            if ( !bMouse )
+        if ( !bMouse )
+        {
+            vcl::Cursor* pCur = pEditView->GetCursor();
+            if ( pCur )
             {
-                vcl::Cursor* pCur = pEditView->GetCursor();
-                if ( pCur )
-                {
-                    Point aLogicPos = pCur->GetPos();
-                    //  use the position right of the cursor (spell popup is opened if
-                    //  the cursor is before the word, but not if behind it)
-                    aLogicPos.AdjustX(pCur->GetWidth() );
-                    aLogicPos.AdjustY(pCur->GetHeight() / 2 );     // center vertically
-                    aMenuPos = LogicToPixel( aLogicPos );
-                }
+                Point aLogicPos = pCur->GetPos();
+                //  use the position right of the cursor (spell popup is opened if
+                //  the cursor is before the word, but not if behind it)
+                aLogicPos.AdjustX(pCur->GetWidth() );
+                aLogicPos.AdjustY(pCur->GetHeight() / 2 );     // center vertically
+                aMenuPos = LogicToPixel( aLogicPos );
             }
+        }
 
-            //  if edit mode was just started above, online spelling may be incomplete
-            pEditView->GetEditEngine()->CompleteOnlineSpelling();
+        //  if edit mode was just started above, online spelling may be incomplete
+        pEditView->GetEditEngine()->CompleteOnlineSpelling();
 
-            //  IsCursorAtWrongSpelledWord could be used for !bMouse
-            //  if there was a corresponding ExecuteSpellPopup call
+        //  IsCursorAtWrongSpelledWord could be used for !bMouse
+        //  if there was a corresponding ExecuteSpellPopup call
 
-            if (bSpellError)
-            {
-                // On OS/2 when clicking next to the Popup menu, the MouseButtonDown
-                // comes before the end of menu execute, thus the SetModified has to
-                // be done prior to this (Bug #40968#)
-                ScInputHandler* pHdl = pScMod->GetInputHdl();
-                if (pHdl)
-                    pHdl->SetModified();
+        if (bSpellError)
+        {
+            // On OS/2 when clicking next to the Popup menu, the MouseButtonDown
+            // comes before the end of menu execute, thus the SetModified has to
+            // be done prior to this (Bug #40968#)
+            ScInputHandler* pHdl = pScMod->GetInputHdl();
+            if (pHdl)
+                pHdl->SetModified();
 
-                Link<SpellCallbackInfo&,void> aLink = LINK( this, ScGridWindow, PopupSpellingHdl );
-                pEditView->ExecuteSpellPopup( aMenuPos, &aLink );
+            Link<SpellCallbackInfo&,void> aLink = LINK( this, ScGridWindow, PopupSpellingHdl );
+            pEditView->ExecuteSpellPopup( aMenuPos, &aLink );
 
-                bDone = true;
-            }
+            bDone = true;
         }
-        else if ( !bMouse )
-        {
-            //  non-edit menu by keyboard -> use lower right of cell cursor position
-            ScDocument* aDoc = pViewData->GetDocument();
-            SCTAB nTabNo = pViewData->GetTabNo();
-            bool bLayoutIsRTL = aDoc->IsLayoutRTL(nTabNo);
+    }
+    else if ( !bMouse )
+    {
+        //  non-edit menu by keyboard -> use lower right of cell cursor position
+        ScDocument* aDoc = pViewData->GetDocument();
+        SCTAB nTabNo = pViewData->GetTabNo();
+        bool bLayoutIsRTL = aDoc->IsLayoutRTL(nTabNo);
 
-            SCCOL nCurX = pViewData->GetCurX();
-            SCROW nCurY = pViewData->GetCurY();
-            aMenuPos = pViewData->GetScrPos( nCurX, nCurY, eWhich, true );
-            long nSizeXPix;
-            long nSizeYPix;
-            pViewData->GetMergeSizePixel( nCurX, nCurY, nSizeXPix, nSizeYPix );
-            // fdo#55432 take the correct position for RTL sheet
-            aMenuPos.AdjustX(bLayoutIsRTL ? -nSizeXPix : nSizeXPix );
-            aMenuPos.AdjustY(nSizeYPix );
+        SCCOL nCurX = pViewData->GetCurX();
+        SCROW nCurY = pViewData->GetCurY();
+        aMenuPos = pViewData->GetScrPos( nCurX, nCurY, eWhich, true );
+        long nSizeXPix;
+        long nSizeYPix;
+        pViewData->GetMergeSizePixel( nCurX, nCurY, nSizeXPix, nSizeYPix );
+        // fdo#55432 take the correct position for RTL sheet
+        aMenuPos.AdjustX(bLayoutIsRTL ? -nSizeXPix : nSizeXPix );
+        aMenuPos.AdjustY(nSizeYPix );
 
-            ScTabViewShell* pViewSh = pViewData->GetViewShell();
-            if (pViewSh)
-            {
-                //  Is a draw object selected?
+        ScTabViewShell* pViewSh = pViewData->GetViewShell();
+        if (pViewSh)
+        {
+            //  Is a draw object selected?
 
-                SdrView* pDrawView = pViewSh->GetScDrawView();
-                if (pDrawView && pDrawView->AreObjectsMarked())
-                {
-                    // #100442#; the context menu should open in the middle of the selected objects
-                    tools::Rectangle aSelectRect(LogicToPixel(pDrawView->GetAllMarkedBoundRect()));
-                    aMenuPos = aSelectRect.Center();
-                }
+            SdrView* pDrawView = pViewSh->GetScDrawView();
+            if (pDrawView && pDrawView->AreObjectsMarked())
+            {
+                // #100442#; the context menu should open in the middle of the selected objects
+                tools::Rectangle aSelectRect(LogicToPixel(pDrawView->GetAllMarkedBoundRect()));
+                aMenuPos = aSelectRect.Center();
             }
         }
+    }
 
-        if (!bDone)
-        {
-            SfxDispatcher::ExecutePopup( this, &aMenuPos );
-        }
+    if (!bDone)
+    {
+        SfxDispatcher::ExecutePopup( this, &aMenuPos );
     }
 }
 
@@ -3178,26 +3178,26 @@ void ScGridWindow::SelectForContextMenu( const Point& rPosPixel, SCCOL nCellX, S
 
     //  select drawing object or move cell cursor
 
-    if ( !bHitSelected )
+    if ( bHitSelected )
+        return;
+
+    bool bWasDraw = ( pDrawView && pDrawView->AreObjectsMarked() );
+    bool bHitDraw = false;
+    if ( pDrawView )
     {
-        bool bWasDraw = ( pDrawView && pDrawView->AreObjectsMarked() );
-        bool bHitDraw = false;
-        if ( pDrawView )
-        {
-            pDrawView->UnmarkAllObj();
-            // Unlock the Internal Layer in order to activate the context menu.
-            // re-lock in ScDrawView::MarkListHasChanged()
-            lcl_UnLockComment( pDrawView, aLogicPos ,pViewData);
-            bHitDraw = pDrawView->MarkObj( aLogicPos );
-            // draw shell is activated in MarkListHasChanged
-        }
-        if ( !bHitDraw )
-        {
-            pView->Unmark();
-            pView->SetCursor(nCellX, nCellY);
-            if ( bWasDraw )
-                pViewData->GetViewShell()->SetDrawShell( false );   // switch shells
-        }
+        pDrawView->UnmarkAllObj();
+        // Unlock the Internal Layer in order to activate the context menu.
+        // re-lock in ScDrawView::MarkListHasChanged()
+        lcl_UnLockComment( pDrawView, aLogicPos ,pViewData);
+        bHitDraw = pDrawView->MarkObj( aLogicPos );
+        // draw shell is activated in MarkListHasChanged
+    }
+    if ( !bHitDraw )
+    {
+        pView->Unmark();
+        pView->SetCursor(nCellX, nCellY);
+        if ( bWasDraw )
+            pViewData->GetViewShell()->SetDrawShell( false );   // switch shells
     }
 }
 
@@ -4524,55 +4524,55 @@ void ScGridWindow::PasteSelection( const Point& rPosPixel )
 
 void ScGridWindow::UpdateEditViewPos()
 {
-    if (pViewData->HasEditView(eWhich))
-    {
-        EditView* pView;
-        SCCOL nCol;
-        SCROW nRow;
-        pViewData->GetEditView( eWhich, pView, nCol, nRow );
-        SCCOL nEndCol = pViewData->GetEditEndCol();
-        SCROW nEndRow = pViewData->GetEditEndRow();
+    if (!pViewData->HasEditView(eWhich))
+        return;
+
+    EditView* pView;
+    SCCOL nCol;
+    SCROW nRow;
+    pViewData->GetEditView( eWhich, pView, nCol, nRow );
+    SCCOL nEndCol = pViewData->GetEditEndCol();
+    SCROW nEndRow = pViewData->GetEditEndRow();
+
+    //  hide EditView?
 
-        //  hide EditView?
+    bool bHide = ( nEndCol<pViewData->GetPosX(eHWhich) || nEndRow<pViewData->GetPosY(eVWhich) );
+    if ( SC_MOD()->IsFormulaMode() )
+        if ( pViewData->GetTabNo() != pViewData->GetRefTabNo() )
+            bHide = true;
 
-        bool bHide = ( nEndCol<pViewData->GetPosX(eHWhich) || nEndRow<pViewData->GetPosY(eVWhich) );
-        if ( SC_MOD()->IsFormulaMode() )
-            if ( pViewData->GetTabNo() != pViewData->GetRefTabNo() )
-                bHide = true;
+    if (bHide)
+    {
+        tools::Rectangle aRect = pView->GetOutputArea();
+        long nHeight = aRect.Bottom() - aRect.Top();
+        aRect.SetTop( PixelToLogic(GetOutputSizePixel(), pViewData->GetLogicMode()).
+                        Height() * 2 );
+        aRect.SetBottom( aRect.Top() + nHeight );
+        pView->SetOutputArea( aRect );
+        pView->HideCursor();
+    }
+    else
+    {
+        // bForceToTop = sal_True for editing
+        tools::Rectangle aPixRect = pViewData->GetEditArea( eWhich, nCol, nRow, this, nullptr, true );
 
-        if (bHide)
+        if (comphelper::LibreOfficeKit::isActive() &&
+            comphelper::LibreOfficeKit::isCompatFlagSet(
+                comphelper::LibreOfficeKit::Compat::scPrintTwipsMsgs))
         {
-            tools::Rectangle aRect = pView->GetOutputArea();
-            long nHeight = aRect.Bottom() - aRect.Top();
-            aRect.SetTop( PixelToLogic(GetOutputSizePixel(), pViewData->GetLogicMode()).
-                            Height() * 2 );
-            aRect.SetBottom( aRect.Top() + nHeight );
-            pView->SetOutputArea( aRect );
-            pView->HideCursor();
+            tools::Rectangle aPTwipsRect = pViewData->GetEditArea(eWhich, nCol, nRow, this, nullptr,
+                    true, true /* bInPrintTwips */);
+            tools::Rectangle aOutputAreaPTwips = pView->GetLOKSpecialOutputArea();
+            aOutputAreaPTwips.SetPos(aPTwipsRect.TopLeft());
+            pView->SetLOKSpecialOutputArea(aOutputAreaPTwips);
         }
-        else
-        {
-            // bForceToTop = sal_True for editing
-            tools::Rectangle aPixRect = pViewData->GetEditArea( eWhich, nCol, nRow, this, nullptr, true );
-
-            if (comphelper::LibreOfficeKit::isActive() &&
-                comphelper::LibreOfficeKit::isCompatFlagSet(
-                    comphelper::LibreOfficeKit::Compat::scPrintTwipsMsgs))
-            {
-                tools::Rectangle aPTwipsRect = pViewData->GetEditArea(eWhich, nCol, nRow, this, nullptr,
-                        true, true /* bInPrintTwips */);
-                tools::Rectangle aOutputAreaPTwips = pView->GetLOKSpecialOutputArea();
-                aOutputAreaPTwips.SetPos(aPTwipsRect.TopLeft());
-                pView->SetLOKSpecialOutputArea(aOutputAreaPTwips);
-            }
 
-            Point aScrPos = PixelToLogic( aPixRect.TopLeft(), pViewData->GetLogicMode() );
+        Point aScrPos = PixelToLogic( aPixRect.TopLeft(), pViewData->GetLogicMode() );
 
-            tools::Rectangle aRect = pView->GetOutputArea();
-            aRect.SetPos( aScrPos );
-            pView->SetOutputArea( aRect );
-            pView->ShowCursor();
-        }
+        tools::Rectangle aRect = pView->GetOutputArea();
+        aRect.SetPos( aScrPos );
+        pView->SetOutputArea( aRect );
+        pView->ShowCursor();
     }
 }
 
@@ -4734,19 +4734,19 @@ void ScGridWindow::UpdateListValPos( bool bVisible, const ScAddress& rPos )
             }
         }
     }
-    if ( bOldButton )
+    if ( !bOldButton )
+        return;
+
+    if ( !bListValButton || aListValPos != aOldPos )
     {
-        if ( !bListValButton || aListValPos != aOldPos )
+        // paint area of old button
+        if ( comphelper::LibreOfficeKit::isActive() )
         {
-            // paint area of old button
-            if ( comphelper::LibreOfficeKit::isActive() )
-            {
-                updateLOKValListButton( false, aOldPos );
-            }
-            else
-            {
-                Invalidate( PixelToLogic( GetListValButtonRect( aOldPos ) ) );
-            }
+            updateLOKValListButton( false, aOldPos );
+        }
+        else
+        {
+            Invalidate( PixelToLogic( GetListValButtonRect( aOldPos ) ) );
         }
     }
 }
@@ -6417,78 +6417,78 @@ void ScGridWindow::UpdateAutoFillOverlay()
 
     //  get the AutoFill handle rectangle in pixels
 
-    if ( bAutoMarkVisible && aAutoMarkPos.Tab() == pViewData->GetTabNo() &&
-         !pViewData->HasEditView(eWhich) && pViewData->IsActive() )
-    {
-        SCCOL nX = aAutoMarkPos.Col();
-        SCROW nY = aAutoMarkPos.Row();
+    if ( !(bAutoMarkVisible && aAutoMarkPos.Tab() == pViewData->GetTabNo() &&
+         !pViewData->HasEditView(eWhich) && pViewData->IsActive()) )
+        return;
 
-        if (!maVisibleRange.isInside(nX, nY) && !comphelper::LibreOfficeKit::isActive())
-        {
-            // Autofill mark is not visible.  Bail out.
-            return;
-        }
+    SCCOL nX = aAutoMarkPos.Col();
+    SCROW nY = aAutoMarkPos.Row();
 
-        SCTAB nTab = pViewData->GetTabNo();
-        ScDocument* pDoc = pViewData->GetDocument();
-        bool bLayoutRTL = pDoc->IsLayoutRTL( nTab );
+    if (!maVisibleRange.isInside(nX, nY) && !comphelper::LibreOfficeKit::isActive())
+    {
+        // Autofill mark is not visible.  Bail out.
+        return;
+    }
 
-        float fScaleFactor = GetDPIScaleFactor();
-        // Size should be even
-        Size aFillHandleSize(6 * fScaleFactor, 6 * fScaleFactor);
+    SCTAB nTab = pViewData->GetTabNo();
+    ScDocument* pDoc = pViewData->GetDocument();
+    bool bLayoutRTL = pDoc->IsLayoutRTL( nTab );
 
-        Point aFillPos = pViewData->GetScrPos( nX, nY, eWhich, true );
-        long nSizeXPix;
-        long nSizeYPix;
-        pViewData->GetMergeSizePixel( nX, nY, nSizeXPix, nSizeYPix );
+    float fScaleFactor = GetDPIScaleFactor();
+    // Size should be even
+    Size aFillHandleSize(6 * fScaleFactor, 6 * fScaleFactor);
 
-        if (bLayoutRTL)
-            aFillPos.AdjustX( -(nSizeXPix - 2 + (aFillHandleSize.Width() / 2)) );
-        else
-            aFillPos.AdjustX(nSizeXPix - (aFillHandleSize.Width() / 2) );
+    Point aFillPos = pViewData->GetScrPos( nX, nY, eWhich, true );
+    long nSizeXPix;
+    long nSizeYPix;
+    pViewData->GetMergeSizePixel( nX, nY, nSizeXPix, nSizeYPix );
 
-        aFillPos.AdjustY(nSizeYPix );
-        aFillPos.AdjustY( -(aFillHandleSize.Height() / 2) );
+    if (bLayoutRTL)
+        aFillPos.AdjustX( -(nSizeXPix - 2 + (aFillHandleSize.Width() / 2)) );
+    else
+        aFillPos.AdjustX(nSizeXPix - (aFillHandleSize.Width() / 2) );
 
-        tools::Rectangle aFillRect(aFillPos, aFillHandleSize);
+    aFillPos.AdjustY(nSizeYPix );
+    aFillPos.AdjustY( -(aFillHandleSize.Height() / 2) );
 
-        // expand rect to increase hit area
-        mpAutoFillRect = aFillRect;
-        mpAutoFillRect->expand(fScaleFactor);
+    tools::Rectangle aFillRect(aFillPos, aFillHandleSize);
 
-        // #i70788# get the OverlayManager safely
-        rtl::Reference<sdr::overlay::OverlayManager> xOverlayManager = getOverlayManager();
-        if (comphelper::LibreOfficeKit::isActive()) // notify the LibreOfficeKit
-        {
-            updateLibreOfficeKitAutoFill(pViewData, aFillRect);
-        }
-        else if (xOverlayManager.is())
-        {
-            Color aHandleColor( SC_MOD()->GetColorConfig().GetColorValue(svtools::FONTCOLOR).nColor );
-            if (pViewData->GetActivePart() != eWhich)
-                // non-active pane uses a different color.
-                aHandleColor = SC_MOD()->GetColorConfig().GetColorValue(svtools::CALCPAGEBREAKAUTOMATIC).nColor;
-            std::vector< basegfx::B2DRange > aRanges;
-            const basegfx::B2DHomMatrix aTransform(GetInverseViewTransformation());
-            basegfx::B2DRange aRB = vcl::unotools::b2DRectangleFromRectangle(aFillRect);
+    // expand rect to increase hit area
+    mpAutoFillRect = aFillRect;
+    mpAutoFillRect->expand(fScaleFactor);
 
-            aRB.transform(aTransform);
-            aRanges.push_back(aRB);
+    // #i70788# get the OverlayManager safely
+    rtl::Reference<sdr::overlay::OverlayManager> xOverlayManager = getOverlayManager();
+    if (comphelper::LibreOfficeKit::isActive()) // notify the LibreOfficeKit
+    {
+        updateLibreOfficeKitAutoFill(pViewData, aFillRect);
+    }
+    else if (xOverlayManager.is())
+    {
+        Color aHandleColor( SC_MOD()->GetColorConfig().GetColorValue(svtools::FONTCOLOR).nColor );
+        if (pViewData->GetActivePart() != eWhich)
+            // non-active pane uses a different color.
+            aHandleColor = SC_MOD()->GetColorConfig().GetColorValue(svtools::CALCPAGEBREAKAUTOMATIC).nColor;
+        std::vector< basegfx::B2DRange > aRanges;
+        const basegfx::B2DHomMatrix aTransform(GetInverseViewTransformation());
+        basegfx::B2DRange aRB = vcl::unotools::b2DRectangleFromRectangle(aFillRect);
 
-            std::unique_ptr<sdr::overlay::OverlayObject> pOverlay(new sdr::overlay::OverlaySelection(
-                sdr::overlay::OverlayType::Solid,
-                aHandleColor,
-                aRanges,
-                false));
+        aRB.transform(aTransform);
+        aRanges.push_back(aRB);
 
-            xOverlayManager->add(*pOverlay);
-            mpOOAutoFill.reset(new sdr::overlay::OverlayObjectList);
-            mpOOAutoFill->append(std::move(pOverlay));
-        }
+        std::unique_ptr<sdr::overlay::OverlayObject> pOverlay(new sdr::overlay::OverlaySelection(
+            sdr::overlay::OverlayType::Solid,
+            aHandleColor,
+            aRanges,
+            false));
 
-        if ( aOldMode != aDrawMode )
-            SetMapMode( aOldMode );
+        xOverlayManager->add(*pOverlay);
+        mpOOAutoFill.reset(new sdr::overlay::OverlayObjectList);
+        mpOOAutoFill->append(std::move(pOverlay));
     }
+
+    if ( aOldMode != aDrawMode )
+        SetMapMode( aOldMode );
 }
 
 void ScGridWindow::DeleteDragRectOverlay()
diff --git a/sc/source/ui/view/gridwin3.cxx b/sc/source/ui/view/gridwin3.cxx
index fbb1bee09641..7c80764221a5 100644
--- a/sc/source/ui/view/gridwin3.cxx
+++ b/sc/source/ui/view/gridwin3.cxx
@@ -209,20 +209,20 @@ void ScGridWindow::DrawRedraw( ScOutputData& rOutputData, SdrLayerID nLayer )
     const bool bDrawChart(VOBJ_MODE_SHOW == rOpts.GetObjMode(VOBJ_TYPE_CHART));
     const bool bDrawDraw(VOBJ_MODE_SHOW == rOpts.GetObjMode(VOBJ_TYPE_DRAW));
 
-    if(bDrawOle || bDrawChart || bDrawDraw)
-    {
-        ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
+    if(!(bDrawOle || bDrawChart || bDrawDraw))
+        return;
 
-        if(pDrView)
-        {
-            pDrView->setHideOle(!bDrawOle);
-            pDrView->setHideChart(!bDrawChart);
-            pDrView->setHideDraw(!bDrawDraw);
-            pDrView->setHideFormControl(!bDrawDraw);
-        }
+    ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
 
-        rOutputData.DrawSelectiveObjects(nLayer);
+    if(pDrView)
+    {
+        pDrView->setHideOle(!bDrawOle);
+        pDrView->setHideChart(!bDrawChart);
+        pDrView->setHideDraw(!bDrawDraw);
+        pDrView->setHideFormControl(!bDrawDraw);
     }
+
+    rOutputData.DrawSelectiveObjects(nLayer);
 }
 
 void ScGridWindow::DrawSdrGrid( const tools::Rectangle& rDrawingRect, OutputDevice* pContentDev )
diff --git a/sc/source/ui/view/gridwin4.cxx b/sc/source/ui/view/gridwin4.cxx
index f31de4542bb6..1ebdf95b60c5 100644
--- a/sc/source/ui/view/gridwin4.cxx
+++ b/sc/source/ui/view/gridwin4.cxx
@@ -190,71 +190,71 @@ static void lcl_DrawScenarioFrames( OutputDevice* pDev, ScViewData* pViewData, S
     ScDocument* pDoc = pViewData->GetDocument();
     SCTAB nTab = pViewData->GetTabNo();
     SCTAB nTabCount = pDoc->GetTableCount();
-    if ( nTab+1<nTabCount && pDoc->IsScenario(nTab+1) && !pDoc->IsScenario(nTab) )
-    {
-        if ( nX1 > 0 ) --nX1;
-        if ( nY1>=2 ) nY1 -= 2;             // Hack: Header row affects two cells
-        else if ( nY1 > 0 ) --nY1;
-        if ( nX2 < pDoc->MaxCol() ) ++nX2;
-        if ( nY2 < pDoc->MaxRow()-1 ) nY2 += 2;     // Hack: Header row affects two cells
-        else if ( nY2 < pDoc->MaxRow() ) ++nY2;
-        ScRange aViewRange( nX1,nY1,nTab, nX2,nY2,nTab );
-
-        //! cache the ranges in table!!!!
-
-        ScMarkData aMarks(pDoc->GetSheetLimits());
-        for (SCTAB i=nTab+1; i<nTabCount && pDoc->IsScenario(i); i++)
-            pDoc->MarkScenario( i, nTab, aMarks, false, ScScenarioFlags::ShowFrame );
-        ScRangeListRef xRanges = new ScRangeList;
-        aMarks.FillRangeListWithMarks( xRanges.get(), false );
-
-        bool bLayoutRTL = pDoc->IsLayoutRTL( nTab );
-        long nLayoutSign = bLayoutRTL ? -1 : 1;
+    if ( nTab+1 >= nTabCount || !pDoc->IsScenario(nTab+1) || pDoc->IsScenario(nTab) )
+        return;
 
-        for (size_t j = 0, n = xRanges->size(); j < n; ++j)
-        {
-            ScRange aRange = (*xRanges)[j];
-            // Always extend scenario frame to merged cells where no new non-covered cells
-            // are framed
-            pDoc->ExtendTotalMerge( aRange );
+    if ( nX1 > 0 ) --nX1;
+    if ( nY1>=2 ) nY1 -= 2;             // Hack: Header row affects two cells
+    else if ( nY1 > 0 ) --nY1;
+    if ( nX2 < pDoc->MaxCol() ) ++nX2;
+    if ( nY2 < pDoc->MaxRow()-1 ) nY2 += 2;     // Hack: Header row affects two cells
+    else if ( nY2 < pDoc->MaxRow() ) ++nY2;
+    ScRange aViewRange( nX1,nY1,nTab, nX2,nY2,nTab );
 
-            //! -> Extend repaint when merging !!!
+    //! cache the ranges in table!!!!
 
-            if ( aRange.Intersects( aViewRange ) )          //! Space for Text/Button?
-            {
-                Point aStartPos = pViewData->GetScrPos(
-                                    aRange.aStart.Col(), aRange.aStart.Row(), eWhich, true );
-                Point aEndPos = pViewData->GetScrPos(
-                                    aRange.aEnd.Col()+1, aRange.aEnd.Row()+1, eWhich, true );
-                //  on the grid:
-                aStartPos.AdjustX( -nLayoutSign );
-                aStartPos.AdjustY( -1 );
-                aEndPos.AdjustX( -nLayoutSign );
-                aEndPos.AdjustY( -1 );
-
-                bool bTextBelow = ( aRange.aStart.Row() == 0 );
-
-                OUString aCurrent;
-                Color aColor( COL_LIGHTGRAY );
-                for (SCTAB nAct=nTab+1; nAct<nTabCount && pDoc->IsScenario(nAct); nAct++)
-                    if ( pDoc->IsActiveScenario(nAct) && pDoc->HasScenarioRange(nAct,aRange) )
-                    {
-                        OUString aDummyComment;
-                        ScScenarioFlags nDummyFlags;
-                        pDoc->GetName( nAct, aCurrent );
-                        pDoc->GetScenarioData( nAct, aDummyComment, aColor, nDummyFlags );
-                    }
+    ScMarkData aMarks(pDoc->GetSheetLimits());
+    for (SCTAB i=nTab+1; i<nTabCount && pDoc->IsScenario(i); i++)
+        pDoc->MarkScenario( i, nTab, aMarks, false, ScScenarioFlags::ShowFrame );
+    ScRangeListRef xRanges = new ScRangeList;
+    aMarks.FillRangeListWithMarks( xRanges.get(), false );
+
+    bool bLayoutRTL = pDoc->IsLayoutRTL( nTab );
+    long nLayoutSign = bLayoutRTL ? -1 : 1;
 
-                if (aCurrent.isEmpty())
-                    aCurrent = ScResId( STR_EMPTYDATA );
+    for (size_t j = 0, n = xRanges->size(); j < n; ++j)
+    {
+        ScRange aRange = (*xRanges)[j];
+        // Always extend scenario frame to merged cells where no new non-covered cells
+        // are framed
+        pDoc->ExtendTotalMerge( aRange );
 
-                //! Own text "(None)" instead of "(Empty)" ???
+        //! -> Extend repaint when merging !!!
 
-                lcl_DrawOneFrame( pDev, tools::Rectangle( aStartPos, aEndPos ),
-                                    aCurrent, aColor, bTextBelow,
-                                    pViewData->GetPPTX(), pViewData->GetPPTY(), pViewData->GetZoomY(),
-                                    pDoc, pViewData, bLayoutRTL );
-            }
+        if ( aRange.Intersects( aViewRange ) )          //! Space for Text/Button?
+        {
+            Point aStartPos = pViewData->GetScrPos(
+                                aRange.aStart.Col(), aRange.aStart.Row(), eWhich, true );
+            Point aEndPos = pViewData->GetScrPos(
+                                aRange.aEnd.Col()+1, aRange.aEnd.Row()+1, eWhich, true );
+            //  on the grid:
+            aStartPos.AdjustX( -nLayoutSign );
+            aStartPos.AdjustY( -1 );
+            aEndPos.AdjustX( -nLayoutSign );
+            aEndPos.AdjustY( -1 );
+
+            bool bTextBelow = ( aRange.aStart.Row() == 0 );
+
+            OUString aCurrent;
+            Color aColor( COL_LIGHTGRAY );
+            for (SCTAB nAct=nTab+1; nAct<nTabCount && pDoc->IsScenario(nAct); nAct++)
+                if ( pDoc->IsActiveScenario(nAct) && pDoc->HasScenarioRange(nAct,aRange) )
+                {
+                    OUString aDummyComment;
+                    ScScenarioFlags nDummyFlags;
+                    pDoc->GetName( nAct, aCurrent );
+                    pDoc->GetScenarioData( nAct, aDummyComment, aColor, nDummyFlags );
+                }
+
+            if (aCurrent.isEmpty())
+                aCurrent = ScResId( STR_EMPTYDATA );
+
+            //! Own text "(None)" instead of "(Empty)" ???
+
+            lcl_DrawOneFrame( pDev, tools::Rectangle( aStartPos, aEndPos ),
+                                aCurrent, aColor, bTextBelow,
+                                pViewData->GetPPTX(), pViewData->GetPPTY(), pViewData->GetZoomY(),
+                                pDoc, pViewData, bLayoutRTL );
         }
     }
 }
@@ -1561,219 +1561,219 @@ void ScGridWindow::CheckNeedsRepaint()
 {
     //  called at the end of painting, and from timer after background text width calculation
 
-    if (bNeedsRepaint)
-    {
-        bNeedsRepaint = false;
-        if (aRepaintPixel.IsEmpty())
-            Invalidate();
-        else
-            Invalidate(PixelToLogic(aRepaintPixel));
-        aRepaintPixel = tools::Rectangle();
-
-        // selection function in status bar might also be invalid
-        SfxBindings& rBindings = pViewData->GetBindings();
-        rBindings.Invalidate( SID_STATUS_SUM );
-        rBindings.Invalidate( SID_ATTR_SIZE );
-        rBindings.Invalidate( SID_TABLE_CELL );
-    }
+    if (!bNeedsRepaint)
+        return;
+
+    bNeedsRepaint = false;
+    if (aRepaintPixel.IsEmpty())
+        Invalidate();
+    else
+        Invalidate(PixelToLogic(aRepaintPixel));
+    aRepaintPixel = tools::Rectangle();
+
+    // selection function in status bar might also be invalid
+    SfxBindings& rBindings = pViewData->GetBindings();
+    rBindings.Invalidate( SID_STATUS_SUM );
+    rBindings.Invalidate( SID_ATTR_SIZE );
+    rBindings.Invalidate( SID_TABLE_CELL );
 }
 
 void ScGridWindow::DrawPagePreview( SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2, vcl::RenderContext& rRenderContext)
 {
     ScPageBreakData* pPageData = pViewData->GetView()->GetPageBreakData();
-    if (pPageData)
+    if (!pPageData)
+        return;
+
+    ScDocument* pDoc = pViewData->GetDocument();
+    SCTAB nTab = pViewData->GetTabNo();
+    Size aWinSize = GetOutputSizePixel();
+    const svtools::ColorConfig& rColorCfg = SC_MOD()->GetColorConfig();
+    Color aManual( rColorCfg.GetColorValue(svtools::CALCPAGEBREAKMANUAL).nColor );
+    Color aAutomatic( rColorCfg.GetColorValue(svtools::CALCPAGEBREAK).nColor );
+
+    OUString aPageStr = ScResId( STR_PGNUM );
+    if ( nPageScript == SvtScriptType::NONE )
     {
-        ScDocument* pDoc = pViewData->GetDocument();
-        SCTAB nTab = pViewData->GetTabNo();
-        Size aWinSize = GetOutputSizePixel();
-        const svtools::ColorConfig& rColorCfg = SC_MOD()->GetColorConfig();
-        Color aManual( rColorCfg.GetColorValue(svtools::CALCPAGEBREAKMANUAL).nColor );
-        Color aAutomatic( rColorCfg.GetColorValue(svtools::CALCPAGEBREAK).nColor );
+        //  get script type of translated "Page" string only once
+        nPageScript = pDoc->GetStringScriptType( aPageStr );
+        if (nPageScript == SvtScriptType::NONE)
+            nPageScript = ScGlobal::GetDefaultScriptType();
+    }
 
-        OUString aPageStr = ScResId( STR_PGNUM );
-        if ( nPageScript == SvtScriptType::NONE )
-        {
-            //  get script type of translated "Page" string only once
-            nPageScript = pDoc->GetStringScriptType( aPageStr );
-            if (nPageScript == SvtScriptType::NONE)
-                nPageScript = ScGlobal::GetDefaultScriptType();
-        }
+    vcl::Font aFont;
+    std::unique_ptr<ScEditEngineDefaulter> pEditEng;
+    const ScPatternAttr& rDefPattern = pDoc->GetPool()->GetDefaultItem(ATTR_PATTERN);
+    if ( nPageScript == SvtScriptType::LATIN )
+    {
+        //  use single font and call DrawText directly
+        rDefPattern.GetFont( aFont, SC_AUTOCOL_BLACK );
+        aFont.SetColor( COL_LIGHTGRAY );
+        //  font size is set as needed
+    }
+    else
+    {
+        //  use EditEngine to draw mixed-script string
+        pEditEng.reset(new ScEditEngineDefaulter( EditEngine::CreatePool(), true ));
+        pEditEng->SetRefMapMode(rRenderContext.GetMapMode());
+        auto pEditDefaults = std::make_unique<SfxItemSet>( pEditEng->GetEmptyItemSet() );
+        rDefPattern.FillEditItemSet( pEditDefaults.get() );
+        pEditDefaults->Put( SvxColorItem( COL_LIGHTGRAY, EE_CHAR_COLOR ) );
+        pEditEng->SetDefaults( std::move(pEditDefaults) );
+    }
 
-        vcl::Font aFont;
-        std::unique_ptr<ScEditEngineDefaulter> pEditEng;
-        const ScPatternAttr& rDefPattern = pDoc->GetPool()->GetDefaultItem(ATTR_PATTERN);
-        if ( nPageScript == SvtScriptType::LATIN )
-        {
-            //  use single font and call DrawText directly
-            rDefPattern.GetFont( aFont, SC_AUTOCOL_BLACK );
-            aFont.SetColor( COL_LIGHTGRAY );
-            //  font size is set as needed
-        }
-        else
+    sal_uInt16 nCount = sal::static_int_cast<sal_uInt16>( pPageData->GetCount() );
+    for (sal_uInt16 nPos=0; nPos<nCount; nPos++)
+    {
+        ScPrintRangeData& rData = pPageData->GetData(nPos);
+        ScRange aRange = rData.GetPrintRange();
+        if ( aRange.aStart.Col() <= nX2+1  && aRange.aEnd.Col()+1 >= nX1 &&
+             aRange.aStart.Row() <= nY2+1 && aRange.aEnd.Row()+1 >= nY1 )
         {
-            //  use EditEngine to draw mixed-script string
-            pEditEng.reset(new ScEditEngineDefaulter( EditEngine::CreatePool(), true ));
-            pEditEng->SetRefMapMode(rRenderContext.GetMapMode());
-            auto pEditDefaults = std::make_unique<SfxItemSet>( pEditEng->GetEmptyItemSet() );
-            rDefPattern.FillEditItemSet( pEditDefaults.get() );
-            pEditDefaults->Put( SvxColorItem( COL_LIGHTGRAY, EE_CHAR_COLOR ) );
-            pEditEng->SetDefaults( std::move(pEditDefaults) );
-        }

... etc. - the rest is truncated


More information about the Libreoffice-commits mailing list