sc/inc/cellvalue.hxx                                   |   13 +++-
 sc/inc/dociter.hxx                                     |    4 -
 sc/source/core/data/cellvalue.cxx                      |   48 ++++++++---------
 sc/source/core/data/clipcontext.cxx                    |   18 +++---
 sc/source/core/data/column2.cxx                        |    4 -
 sc/source/core/data/column3.cxx                        |    6 +-
 sc/source/core/data/column4.cxx                        |    2 
 sc/source/core/data/conditio.cxx                       |    8 +-
 sc/source/core/data/dociter.cxx                        |   18 +++---
 sc/source/core/data/document.cxx                       |    2 
 sc/source/core/data/documentimport.cxx                 |    5 -
 sc/source/core/data/queryevaluator.cxx                 |   18 +++---
 sc/source/core/data/queryiter.cxx                      |    2 
 sc/source/core/data/table2.cxx                         |    6 +-
 sc/source/core/data/table3.cxx                         |   20 +++----
 sc/source/core/data/table4.cxx                         |   14 ++--
 sc/source/core/data/table5.cxx                         |    4 -
 sc/source/core/data/table6.cxx                         |    6 +-
 sc/source/core/data/validat.cxx                        |    2 
 sc/source/core/tool/cellform.cxx                       |    4 -
 sc/source/core/tool/chartarr.cxx                       |    2 
 sc/source/core/tool/chgtrack.cxx                       |   44 +++++++--------
 sc/source/core/tool/detfunc.cxx                        |    6 +-
 sc/source/core/tool/interpr1.cxx                       |   20 +++----
 sc/source/core/tool/interpr4.cxx                       |   48 ++++++++---------
 sc/source/core/tool/interpr5.cxx                       |   18 +++---
 sc/source/core/tool/rangeseq.cxx                       |    2 
 sc/source/filter/dif/difexp.cxx                        |    6 +-
 sc/source/filter/excel/xetable.cxx                     |    2 
 sc/source/filter/html/htmlexp.cxx                      |    4 -
 sc/source/filter/xcl97/XclExpChangeTrack.cxx           |    2 
 sc/source/filter/xml/XMLChangeTrackingExportHelper.cxx |    2 
 sc/source/filter/xml/XMLChangeTrackingImportHelper.cxx |   12 ++--
 sc/source/filter/xml/xmlcelli.cxx                      |    4 -
 sc/source/filter/xml/xmlexprt.cxx                      |    6 +-
 sc/source/ui/Accessibility/AccessibleCell.cxx          |    2 
 sc/source/ui/docshell/docsh.cxx                        |    8 +-
 sc/source/ui/docshell/docsh3.cxx                       |    4 -
 sc/source/ui/docshell/externalrefmgr.cxx               |    4 -
 sc/source/ui/docshell/impex.cxx                        |    4 -
 sc/source/ui/undo/undocell.cxx                         |    2 
 sc/source/ui/unoobj/cellsuno.cxx                       |   18 +++---
 sc/source/ui/unoobj/chart2uno.cxx                      |    2 
 sc/source/ui/view/cellsh1.cxx                          |    2 
 sc/source/ui/view/gridwin.cxx                          |    8 +-
 sc/source/ui/view/output.cxx                           |    4 -
 sc/source/ui/view/output2.cxx                          |   16 ++---
 sc/source/ui/view/tabvwsh.cxx                          |    2 
 sc/source/ui/view/tabvwsh5.cxx                         |    4 -
 sc/source/ui/view/tabvwsha.cxx                         |    2 
 sc/source/ui/view/viewfun2.cxx                         |    2 
 51 files changed, 238 insertions(+), 228 deletions(-)

New commits:
commit 20b8c7f38ae1c03dc0405a2da006ab6b2dbf3627
Author:     Noel Grandin <noelgran...@gmail.com>
AuthorDate: Fri Jun 17 19:55:58 2022 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Sat Jun 18 08:23:06 2022 +0200

    create getter for ScCellValue::mpFormula
    
    so we can assert that it has the correct tag type
    
    Change-Id: Iab13a6d6ea1783c69395f06f28732769e5fe8b18
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136059
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sc/inc/cellvalue.hxx b/sc/inc/cellvalue.hxx
index 192e499bbb25..1095d32a3d39 100644
--- a/sc/inc/cellvalue.hxx
+++ b/sc/inc/cellvalue.hxx
@@ -41,7 +41,7 @@ public:
         double mfValue1;
         svl::SharedString* mpString;
         EditTextObject* mpEditText1;
-        ScFormulaCell* mpFormula;
+        ScFormulaCell* mpFormula1;
     };
 
     ScCellValue();
@@ -72,6 +72,14 @@ public:
         mpEditText1 = nullptr;
         return p;
     }
+    ScFormulaCell* getFormula() const { assert(meType == CELLTYPE_FORMULA); 
return mpFormula1; }
+    ScFormulaCell* releaseFormula()
+    {
+        assert(meType == CELLTYPE_FORMULA);
+        auto p = mpFormula1;
+        mpFormula1 = nullptr;
+        return p;
+    }
 
     /**
      * Take cell value from specified position in specified document.
@@ -124,7 +132,7 @@ public:
         double mfValue1;
         const svl::SharedString* mpString;
         const EditTextObject* mpEditText1;
-        ScFormulaCell* mpFormula;
+        ScFormulaCell* mpFormula1;
     };
 
     ScRefCellValue();
@@ -145,6 +153,7 @@ public:
     double getDouble() const { assert(meType == CELLTYPE_VALUE); return 
mfValue1; }
     const svl::SharedString* getSharedString() const { assert(meType == 
CELLTYPE_STRING); return mpString; }
     const EditTextObject* getEditText() const { assert(meType == 
CELLTYPE_EDIT); return mpEditText1; }
+    ScFormulaCell* getFormula() const { assert(meType == CELLTYPE_FORMULA); 
return mpFormula1; }
 
     /**
      * Take cell value from specified position in specified document.
diff --git a/sc/inc/dociter.hxx b/sc/inc/dociter.hxx
index fc1609d6daab..ff58a4181e12 100644
--- a/sc/inc/dociter.hxx
+++ b/sc/inc/dociter.hxx
@@ -235,8 +235,8 @@ public:
     CellType getType() const { return maCurCell.getType();}
     OUString getString() const;
     const EditTextObject* getEditText() const { return 
maCurCell.getEditText();}
-    ScFormulaCell* getFormulaCell() { return maCurCell.mpFormula;}
-    const ScFormulaCell* getFormulaCell() const { return maCurCell.mpFormula;}
+    ScFormulaCell* getFormulaCell() { return maCurCell.getFormula();}
+    const ScFormulaCell* getFormulaCell() const { return 
maCurCell.getFormula();}
     ScCellValue getCellValue() const;
     const ScRefCellValue& getRefCellValue() const { return maCurCell;}
 
diff --git a/sc/source/core/data/cellvalue.cxx 
b/sc/source/core/data/cellvalue.cxx
index 6de2a253d72f..fa246b34d04b 100644
--- a/sc/source/core/data/cellvalue.cxx
+++ b/sc/source/core/data/cellvalue.cxx
@@ -100,7 +100,7 @@ bool equalsWithoutFormatImpl( const T& left, const T& right 
)
             return aStr1 == aStr2;
         }
         case CELLTYPE_FORMULA:
-            return equalsFormulaCells(left.mpFormula, right.mpFormula);
+            return equalsFormulaCells(left.mpFormula1, right.mpFormula1);
         default:
             ;
     }
@@ -123,7 +123,7 @@ void commitToColumn( const ScCellValue& rCell, ScColumn& 
rColumn, SCROW nRow )
         case CELLTYPE_FORMULA:
         {
             ScAddress aDestPos(rColumn.GetCol(), nRow, rColumn.GetTab());
-            rColumn.SetFormulaCell(nRow, new ScFormulaCell(*rCell.mpFormula, 
rColumn.GetDoc(), aDestPos));
+            rColumn.SetFormulaCell(nRow, new ScFormulaCell(*rCell.mpFormula1, 
rColumn.GetDoc(), aDestPos));
         }
         break;
         default:
@@ -172,7 +172,7 @@ OUString getStringImpl( const CellT& rCell, const 
ScDocument* pDoc )
                 return ScEditUtil::GetString(*rCell.mpEditText1, pDoc);
         break;
         case CELLTYPE_FORMULA:
-            return rCell.mpFormula->GetString().getString();
+            return rCell.mpFormula1->GetString().getString();
         default:
             ;
     }
@@ -193,7 +193,7 @@ OUString getRawStringImpl( const CellT& rCell, const 
ScDocument& rDoc )
                 return ScEditUtil::GetString(*rCell.mpEditText1, &rDoc);
         break;
         case CELLTYPE_FORMULA:
-            return rCell.mpFormula->GetRawString().getString();
+            return rCell.mpFormula1->GetRawString().getString();
         default:
             ;
     }
@@ -215,7 +215,7 @@ ScCellValue::ScCellValue( const ScRefCellValue& rCell ) : 
meType(rCell.getType()
             mpEditText1 = rCell.mpEditText1->Clone().release();
         break;
         case CELLTYPE_FORMULA:
-            mpFormula = rCell.mpFormula->Clone();
+            mpFormula1 = rCell.mpFormula1->Clone();
         break;
         default:
             ;
@@ -239,7 +239,7 @@ ScCellValue::ScCellValue( const ScCellValue& r ) : 
meType(r.meType), mfValue1(r.
             mpEditText1 = r.mpEditText1->Clone().release();
         break;
         case CELLTYPE_FORMULA:
-            mpFormula = r.mpFormula->Clone();
+            mpFormula1 = r.mpFormula1->Clone();
         break;
         default:
             ;
@@ -259,7 +259,7 @@ ScCellValue::ScCellValue(ScCellValue&& r) noexcept
             mpEditText1 = r.mpEditText1;
         break;
         case CELLTYPE_FORMULA:
-            mpFormula = r.mpFormula;
+            mpFormula1 = r.mpFormula1;
         break;
         default:
             ;
@@ -283,7 +283,7 @@ void ScCellValue::clear() noexcept
             delete mpEditText1;
         break;
         case CELLTYPE_FORMULA:
-            delete mpFormula;
+            delete mpFormula1;
         break;
         default:
             ;
@@ -326,7 +326,7 @@ void ScCellValue::set( ScFormulaCell* pFormula )
 {
     clear();
     meType = CELLTYPE_FORMULA;
-    mpFormula = pFormula;
+    mpFormula1 = pFormula;
 }
 
 void ScCellValue::assign( const ScDocument& rDoc, const ScAddress& rPos )
@@ -349,7 +349,7 @@ void ScCellValue::assign( const ScDocument& rDoc, const 
ScAddress& rPos )
             mfValue1 = aRefVal.mfValue1;
         break;
         case CELLTYPE_FORMULA:
-            mpFormula = aRefVal.mpFormula->Clone();
+            mpFormula1 = aRefVal.mpFormula1->Clone();
         break;
         default:
             meType = CELLTYPE_NONE; // reset to empty.
@@ -394,7 +394,7 @@ void ScCellValue::assign(const ScCellValue& rOther, 
ScDocument& rDestDoc, ScClon
         break;
         case CELLTYPE_FORMULA:
             // Switch to the destination document.
-            mpFormula = new ScFormulaCell(*rOther.mpFormula, rDestDoc, 
rOther.mpFormula->aPos, nCloneFlags);
+            mpFormula1 = new ScFormulaCell(*rOther.mpFormula1, rDestDoc, 
rOther.mpFormula1->aPos, nCloneFlags);
         break;
         default:
             meType = CELLTYPE_NONE; // reset to empty.
@@ -419,7 +419,7 @@ void ScCellValue::commit( ScDocument& rDoc, const 
ScAddress& rPos ) const
             rDoc.SetValue(rPos, mfValue1);
         break;
         case CELLTYPE_FORMULA:
-            rDoc.SetFormulaCell(rPos, mpFormula->Clone());
+            rDoc.SetFormulaCell(rPos, mpFormula1->Clone());
         break;
         default:
             rDoc.SetEmptyCell(rPos);
@@ -453,7 +453,7 @@ void ScCellValue::release( ScDocument& rDoc, const 
ScAddress& rPos )
         break;
         case CELLTYPE_FORMULA:
             // This formula cell instance is directly placed in the document 
without copying.
-            rDoc.SetFormulaCell(rPos, mpFormula);
+            rDoc.SetFormulaCell(rPos, mpFormula1);
         break;
         default:
             rDoc.SetEmptyCell(rPos);
@@ -483,7 +483,7 @@ void ScCellValue::release( ScColumn& rColumn, SCROW nRow, 
sc::StartListeningType
         break;
         case CELLTYPE_FORMULA:
             // This formula cell instance is directly placed in the document 
without copying.
-            rColumn.SetFormulaCell(nRow, mpFormula, eListenType);
+            rColumn.SetFormulaCell(nRow, mpFormula1, eListenType);
         break;
         default:
             rColumn.DeleteContent(nRow);
@@ -530,12 +530,12 @@ ScCellValue& ScCellValue::operator=(ScCellValue&& rCell) 
noexcept
             mpEditText1 = rCell.mpEditText1;
         break;
         case CELLTYPE_FORMULA:
-            mpFormula = rCell.mpFormula;
+            mpFormula1 = rCell.mpFormula1;
         break;
         default:
             ;
     }
-    //we don't need to reset mpString/mpEditText1/mpFormula if we
+    //we don't need to reset mpString/mpEditText1/mpFormula1 if we
     //set meType to NONE as the ScCellValue dtor keys off the meType
     rCell.meType = CELLTYPE_NONE;
 
@@ -562,7 +562,7 @@ ScRefCellValue::ScRefCellValue() : meType(CELLTYPE_NONE), 
mfValue1(0.0) {}
 ScRefCellValue::ScRefCellValue( double fValue ) : meType(CELLTYPE_VALUE), 
mfValue1(fValue) {}
 ScRefCellValue::ScRefCellValue( const svl::SharedString* pString ) : 
meType(CELLTYPE_STRING), mpString(pString) {}
 ScRefCellValue::ScRefCellValue( const EditTextObject* pEditText ) : 
meType(CELLTYPE_EDIT), mpEditText1(pEditText) {}
-ScRefCellValue::ScRefCellValue( ScFormulaCell* pFormula ) : 
meType(CELLTYPE_FORMULA), mpFormula(pFormula) {}
+ScRefCellValue::ScRefCellValue( ScFormulaCell* pFormula ) : 
meType(CELLTYPE_FORMULA), mpFormula1(pFormula) {}
 
 ScRefCellValue::ScRefCellValue( ScDocument& rDoc, const ScAddress& rPos )
 {
@@ -609,7 +609,7 @@ void ScRefCellValue::commit( ScDocument& rDoc, const 
ScAddress& rPos ) const
             rDoc.SetValue(rPos, mfValue1);
         break;
         case CELLTYPE_FORMULA:
-            rDoc.SetFormulaCell(rPos, new ScFormulaCell(*mpFormula, rDoc, 
rPos));
+            rDoc.SetFormulaCell(rPos, new ScFormulaCell(*mpFormula1, rDoc, 
rPos));
         break;
         default:
             rDoc.SetEmptyCell(rPos);
@@ -618,17 +618,17 @@ void ScRefCellValue::commit( ScDocument& rDoc, const 
ScAddress& rPos ) const
 
 bool ScRefCellValue::hasString() const
 {
-    return hasStringImpl(meType, mpFormula);
+    return hasStringImpl(meType, mpFormula1);
 }
 
 bool ScRefCellValue::hasNumeric() const
 {
-    return hasNumericImpl(meType, mpFormula);
+    return hasNumericImpl(meType, mpFormula1);
 }
 
 bool ScRefCellValue::hasError() const
 {
-    return meType == CELLTYPE_FORMULA && mpFormula->GetErrCode() != 
FormulaError::NONE;
+    return meType == CELLTYPE_FORMULA && mpFormula1->GetErrCode() != 
FormulaError::NONE;
 }
 
 double ScRefCellValue::getValue()
@@ -638,7 +638,7 @@ double ScRefCellValue::getValue()
         case CELLTYPE_VALUE:
             return mfValue1;
         case CELLTYPE_FORMULA:
-            return mpFormula->GetValue();
+            return mpFormula1->GetValue();
         default:
             ;
     }
@@ -652,7 +652,7 @@ double ScRefCellValue::getRawValue() const
         case CELLTYPE_VALUE:
             return mfValue1;
         case CELLTYPE_FORMULA:
-            return mpFormula->GetRawValue();
+            return mpFormula1->GetRawValue();
         default:
             ;
     }
@@ -680,7 +680,7 @@ bool ScRefCellValue::hasEmptyValue()
         return true;
 
     if (meType == CELLTYPE_FORMULA)
-        return mpFormula->IsEmpty();
+        return mpFormula1->IsEmpty();
 
     return false;
 }
diff --git a/sc/source/core/data/clipcontext.cxx 
b/sc/source/core/data/clipcontext.cxx
index 8b4f72d73c5e..ee97d315077b 100644
--- a/sc/source/core/data/clipcontext.cxx
+++ b/sc/source/core/data/clipcontext.cxx
@@ -193,7 +193,7 @@ void CopyFromClipContext::setSingleCell( const ScAddress& 
rSrcPos, const ScColum
             if (bBoolean)
             {
                 // Check if this formula cell is a boolean cell, and if so, go 
ahead and paste it.
-                const ScTokenArray* pCode = rSrcCell.mpFormula->GetCode();
+                const ScTokenArray* pCode = rSrcCell.getFormula()->GetCode();
                 if (pCode && pCode->GetLen() == 1)
                 {
                     const formula::FormulaToken* p = pCode->FirstToken();
@@ -207,7 +207,7 @@ void CopyFromClipContext::setSingleCell( const ScAddress& 
rSrcPos, const ScColum
                 // Good.
                 break;
 
-            FormulaError nErr = rSrcCell.mpFormula->GetErrCode();
+            FormulaError nErr = rSrcCell.getFormula()->GetErrCode();
             if (nErr != FormulaError::NONE)
             {
                 // error codes are cloned with values
@@ -222,12 +222,12 @@ void CopyFromClipContext::setSingleCell( const ScAddress& 
rSrcPos, const ScColum
                     rSrcCell.set(pErrCell);
                 }
             }
-            else if (rSrcCell.mpFormula->IsEmptyDisplayedAsString())
+            else if (rSrcCell.getFormula()->IsEmptyDisplayedAsString())
             {
                 // Empty stays empty and doesn't become 0.
                 rSrcCell.clear();
             }
-            else if (rSrcCell.mpFormula->IsValue())
+            else if (rSrcCell.getFormula()->IsValue())
             {
                 bool bPaste = isDateCell(rSrcCol, rSrcPos.Row()) ? bDateTime : 
bNumeric;
                 if (!bPaste)
@@ -238,11 +238,11 @@ void CopyFromClipContext::setSingleCell( const ScAddress& 
rSrcPos, const ScColum
                 }
 
                 // Turn this into a numeric cell.
-                rSrcCell.set(rSrcCell.mpFormula->GetValue());
+                rSrcCell.set(rSrcCell.getFormula()->GetValue());
             }
             else if (bString)
             {
-                svl::SharedString aStr = rSrcCell.mpFormula->GetString();
+                svl::SharedString aStr = rSrcCell.getFormula()->GetString();
                 if (aStr.isEmpty())
                 {
                     // do not clone empty string
@@ -251,18 +251,18 @@ void CopyFromClipContext::setSingleCell( const ScAddress& 
rSrcPos, const ScColum
                 }
 
                 // Turn this into a string or edit cell.
-                if (rSrcCell.mpFormula->IsMultilineResult())
+                if (rSrcCell.getFormula()->IsMultilineResult())
                 {
                     // TODO : Add shared string support to the edit engine to
                     // make this process simpler.
                     ScFieldEditEngine& rEngine = mrDestDoc.GetEditEngine();
-                    
rEngine.SetTextCurrentDefaults(rSrcCell.mpFormula->GetString().getString());
+                    
rEngine.SetTextCurrentDefaults(rSrcCell.getFormula()->GetString().getString());
                     std::unique_ptr<EditTextObject> 
pObj(rEngine.CreateTextObject());
                     pObj->NormalizeString(mrDestDoc.GetSharedStringPool());
                     rSrcCell.set(*pObj);
                 }
                 else
-                    rSrcCell.set(rSrcCell.mpFormula->GetString());
+                    rSrcCell.set(rSrcCell.getFormula()->GetString());
             }
             else
                 // We don't want to paste this.
diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx
index 208b8dac5fe3..cc806168d1ed 100644
--- a/sc/source/core/data/column2.cxx
+++ b/sc/source/core/data/column2.cxx
@@ -169,7 +169,7 @@ tools::Long ScColumn::GetNeededSize(
     bool bCellIsValue = (aCell.getType() == CELLTYPE_VALUE);
     if (aCell.getType() == CELLTYPE_FORMULA)
     {
-        ScFormulaCell* pFCell = aCell.mpFormula;
+        ScFormulaCell* pFCell = aCell.getFormula();
         bCellIsValue = pFCell->IsRunning() || pFCell->IsValue();
     }
 
@@ -282,7 +282,7 @@ tools::Long ScColumn::GetNeededSize(
     bool bEditEngine = (eCellType == CELLTYPE_EDIT ||
                         eOrient == SvxCellOrientation::Stacked ||
                         IsAmbiguousScript(nScript) ||
-                        ((eCellType == CELLTYPE_FORMULA) && 
aCell.mpFormula->IsMultilineResult()));
+                        ((eCellType == CELLTYPE_FORMULA) && 
aCell.getFormula()->IsMultilineResult()));
 
     if (!bEditEngine)                                   // direct output
     {
diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx
index 7586b000768d..019a8b58283a 100644
--- a/sc/source/core/data/column3.cxx
+++ b/sc/source/core/data/column3.cxx
@@ -2562,7 +2562,7 @@ class FilterEntriesHandler
 
             case CELLTYPE_FORMULA:
             {
-                ScFormulaCell* pFC = rCell.mpFormula;
+                ScFormulaCell* pFC = rCell.getFormula();
                 FormulaError nErr = pFC->GetErrCode();
                 if (nErr != FormulaError::NONE)
                 {
@@ -3030,7 +3030,7 @@ OUString ScColumn::GetString( const ScRefCellValue& 
aCell, SCROW nRow, const ScI
 {
     // ugly hack for ordering problem with GetNumberFormat and missing 
inherited formats
     if (aCell.getType() == CELLTYPE_FORMULA)
-        aCell.mpFormula->MaybeInterpret();
+        aCell.getFormula()->MaybeInterpret();
 
     sal_uInt32 nFormat = GetNumberFormat( pContext ? *pContext : 
GetDoc().GetNonThreadedContext(), nRow);
     const Color* pColor = nullptr;
@@ -3345,7 +3345,7 @@ class MaxNumStringLenHandler
         sal_uInt16 nCellPrecision = mnMaxGeneralPrecision;
         if (rCell.getType() == CELLTYPE_FORMULA)
         {
-            if (!rCell.mpFormula->IsValue())
+            if (!rCell.getFormula()->IsValue())
                 return;
 
             // Limit unformatted formula cell precision to precision
diff --git a/sc/source/core/data/column4.cxx b/sc/source/core/data/column4.cxx
index 7fd63d2dfa27..2c610d48d5fc 100644
--- a/sc/source/core/data/column4.cxx
+++ b/sc/source/core/data/column4.cxx
@@ -321,7 +321,7 @@ void ScColumn::CopyOneCellFromClip( 
sc::CopyFromClipContext& rCxt, SCROW nRow1,
                 std::vector<sc::RowSpan> aRanges;
                 aRanges.reserve(1);
                 aRanges.emplace_back(nRow1, nRow2);
-                CloneFormulaCell(*pBlockPos, *rSrcCell.mpFormula, rSrcAttr, 
aRanges);
+                CloneFormulaCell(*pBlockPos, *rSrcCell.getFormula(), rSrcAttr, 
aRanges);
             }
             break;
             default:
diff --git a/sc/source/core/data/conditio.cxx b/sc/source/core/data/conditio.cxx
index 7a421292e661..61fdf2fc8b87 100644
--- a/sc/source/core/data/conditio.cxx
+++ b/sc/source/core/data/conditio.cxx
@@ -735,11 +735,11 @@ static bool lcl_GetCellContent( ScRefCellValue& rCell, 
bool bIsStr1, double& rAr
         break;
         case CELLTYPE_FORMULA:
         {
-            bVal = rCell.mpFormula->IsValue();
+            bVal = rCell.getFormula()->IsValue();
             if (bVal)
-                rArg = rCell.mpFormula->GetValue();
+                rArg = rCell.getFormula()->GetValue();
             else
-                rArgStr = rCell.mpFormula->GetString().getString();
+                rArgStr = rCell.getFormula()->GetString().getString();
         }
         break;
         case CELLTYPE_STRING:
@@ -952,7 +952,7 @@ bool ScConditionEntry::IsError( const ScAddress& rPos ) 
const
 
     if (rCell.getType() == CELLTYPE_FORMULA)
     {
-        if (rCell.mpFormula->GetErrCode() != FormulaError::NONE)
+        if (rCell.getFormula()->GetErrCode() != FormulaError::NONE)
             return true;
     }
 
diff --git a/sc/source/core/data/dociter.cxx b/sc/source/core/data/dociter.cxx
index 1563a6af7e9f..2c64a22e9011 100644
--- a/sc/source/core/data/dociter.cxx
+++ b/sc/source/core/data/dociter.cxx
@@ -423,22 +423,22 @@ bool 
ScDBQueryDataIterator::DataAccessInternal::getCurrent(Value& rValue)
 
                 case CELLTYPE_FORMULA:
                 {
-                    if (aCell.mpFormula->IsValue())
+                    if (aCell.getFormula()->IsValue())
                     {
-                        rValue.mfValue = aCell.mpFormula->GetValue();
+                        rValue.mfValue = aCell.getFormula()->GetValue();
                         rValue.mbIsNumber = true;
                         mrDoc.GetNumberFormatInfo(
                             mrContext, nNumFmtType, nNumFmtIndex, 
ScAddress(nCol, nRow, nTab));
-                        rValue.mnError = aCell.mpFormula->GetErrCode();
+                        rValue.mnError = aCell.getFormula()->GetErrCode();
                         return true; // Found it!
                     }
                     else if(mpParam->mbSkipString)
                         incPos();
                     else
                     {
-                        rValue.maString = 
aCell.mpFormula->GetString().getString();
+                        rValue.maString = 
aCell.getFormula()->GetString().getString();
                         rValue.mfValue = 0.0;
-                        rValue.mnError = aCell.mpFormula->GetErrCode();
+                        rValue.mnError = aCell.getFormula()->GetErrCode();
                         rValue.mbIsNumber = false;
                         return true;
                     }
@@ -984,7 +984,7 @@ ScCellValue ScCellIterator::getCellValue() const
             return ScCellValue(maCurCell.getDouble());
         break;
         case CELLTYPE_FORMULA:
-            return ScCellValue(maCurCell.mpFormula->Clone());
+            return ScCellValue(maCurCell.getFormula()->Clone());
         break;
         default:
             return ScCellValue();
@@ -1324,10 +1324,10 @@ bool ScHorizontalValueIterator::GetNext( double& 
rValue, FormulaError& rErr )
                 break;
             case CELLTYPE_FORMULA:
                 {
-                    rErr = pCell->mpFormula->GetErrCode();
-                    if (rErr != FormulaError::NONE || 
pCell->mpFormula->IsValue())
+                    rErr = pCell->getFormula()->GetErrCode();
+                    if (rErr != FormulaError::NONE || 
pCell->getFormula()->IsValue())
                     {
-                        rValue = pCell->mpFormula->GetValue();
+                        rValue = pCell->getFormula()->GetValue();
                         bFound = true;
                     }
                 }
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index f3c34ab49493..15f44a1ef4d5 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -3612,7 +3612,7 @@ FormulaError ScDocument::GetStringForFormula( const 
ScAddress& rPos, OUString& r
         break;
         case CELLTYPE_FORMULA:
         {
-            ScFormulaCell* pFCell = aCell.mpFormula;
+            ScFormulaCell* pFCell = aCell.getFormula();
             nErr = pFCell->GetErrCode();
             if (pFCell->IsValue())
             {
diff --git a/sc/source/core/data/documentimport.cxx 
b/sc/source/core/data/documentimport.cxx
index 6134a53d032d..5a2e77e66ffb 100644
--- a/sc/source/core/data/documentimport.cxx
+++ b/sc/source/core/data/documentimport.cxx
@@ -235,10 +235,9 @@ void ScDocumentImport::setAutoInput(const ScAddress& rPos, 
const OUString& rStr,
         break;
         case CELLTYPE_FORMULA:
             if (!pStringParam)
-                mpImpl->mrDoc.CheckLinkFormulaNeedingCheck( 
*aCell.mpFormula->GetCode());
+                mpImpl->mrDoc.CheckLinkFormulaNeedingCheck( 
*aCell.getFormula()->GetCode());
             // This formula cell instance is directly placed in the document 
without copying.
-            pBlockPos->miCellPos = rCells.set(pBlockPos->miCellPos, 
rPos.Row(), aCell.mpFormula);
-            aCell.mpFormula = nullptr;
+            pBlockPos->miCellPos = rCells.set(pBlockPos->miCellPos, 
rPos.Row(), aCell.releaseFormula());
         break;
         default:
             pBlockPos->miCellPos = rCells.set_empty(pBlockPos->miCellPos, 
rPos.Row(), rPos.Row());
diff --git a/sc/source/core/data/queryevaluator.cxx 
b/sc/source/core/data/queryevaluator.cxx
index ef1ef6e1c0f3..a63084726083 100644
--- a/sc/source/core/data/queryevaluator.cxx
+++ b/sc/source/core/data/queryevaluator.cxx
@@ -158,7 +158,8 @@ bool ScQueryEvaluator::isQueryByValue(const ScQueryEntry& 
rEntry, const ScQueryE
 
 bool ScQueryEvaluator::isQueryByValueForCell(const ScRefCellValue& rCell)
 {
-    if (rCell.getType() == CELLTYPE_FORMULA && rCell.mpFormula->GetErrCode() 
!= FormulaError::NONE)
+    if (rCell.getType() == CELLTYPE_FORMULA
+        && rCell.getFormula()->GetErrCode() != FormulaError::NONE)
         // Error values are compared as string.
         return false;
 
@@ -208,7 +209,7 @@ std::pair<bool, bool> 
ScQueryEvaluator::compareByValue(const ScRefCellValue& rCe
             nCellVal = rCell.getDouble();
             break;
         case CELLTYPE_FORMULA:
-            nCellVal = rCell.mpFormula->GetValue();
+            nCellVal = rCell.getFormula()->GetValue();
             break;
         default:
             nCellVal = 0.0;
@@ -301,10 +302,11 @@ OUString ScQueryEvaluator::getCellString(const 
ScRefCellValue& rCell, SCROW nRow
                                          const ScQueryEntry& rEntry,
                                          const svl::SharedString** 
sharedString)
 {
-    if (rCell.getType() == CELLTYPE_FORMULA && rCell.mpFormula->GetErrCode() 
!= FormulaError::NONE)
+    if (rCell.getType() == CELLTYPE_FORMULA
+        && rCell.getFormula()->GetErrCode() != FormulaError::NONE)
     {
         // Error cell is evaluated as string (for now).
-        const FormulaError error = rCell.mpFormula->GetErrCode();
+        const FormulaError error = rCell.getFormula()->GetErrCode();
         auto it = mCachedSharedErrorStrings.find(error);
         if (it == mCachedSharedErrorStrings.end())
         {
@@ -685,7 +687,7 @@ std::pair<bool, bool> 
ScQueryEvaluator::compareByRangeLookup(const ScRefCellValu
     if (rItem.meType == ScQueryEntry::ByString)
     {
         if (rCell.getType() == CELLTYPE_FORMULA
-            && rCell.mpFormula->GetErrCode() != FormulaError::NONE)
+            && rCell.getFormula()->GetErrCode() != FormulaError::NONE)
             // Error values are compared as string.
             return std::pair<bool, bool>(false, bTestEqual);
 
@@ -724,10 +726,10 @@ std::pair<bool, bool> 
ScQueryEvaluator::processEntry(SCROW nRow, SCCOL nCol, ScR
         if (aCell.getType() == CELLTYPE_VALUE)
             value = aCell.getDouble();
         else if (aCell.getType() == CELLTYPE_FORMULA
-                 && aCell.mpFormula->GetErrCode() != FormulaError::NONE
-                 && aCell.mpFormula->IsValue())
+                 && aCell.getFormula()->GetErrCode() != FormulaError::NONE
+                 && aCell.getFormula()->IsValue())
         {
-            value = aCell.mpFormula->GetValue();
+            value = aCell.getFormula()->GetValue();
         }
         else
             valid = false;
diff --git a/sc/source/core/data/queryiter.cxx 
b/sc/source/core/data/queryiter.cxx
index 7d51fff4e601..5156385c4b8f 100644
--- a/sc/source/core/data/queryiter.cxx
+++ b/sc/source/core/data/queryiter.cxx
@@ -438,7 +438,7 @@ bool ScQueryCellIteratorBase< accessType, queryType 
>::BinarySearch( SCCOL col,
                 fLastInRangeValue = aCell.getDouble();
             break;
             case CELLTYPE_FORMULA :
-                fLastInRangeValue = aCell.mpFormula->GetValue();
+                fLastInRangeValue = aCell.getFormula()->GetValue();
             break;
             default:
             {
diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx
index 6ee8d4237356..a8b5882a54ea 100644
--- a/sc/source/core/data/table2.cxx
+++ b/sc/source/core/data/table2.cxx
@@ -4119,7 +4119,7 @@ void ScTable::DoAutoOutline( SCCOL nStartCol, SCROW 
nStartRow, SCCOL nEndCol, SC
             if (aCell.getType() != CELLTYPE_FORMULA)
                 continue;
 
-            if (!aCell.mpFormula->HasRefListExpressibleAsOneReference(aRef))
+            if (!aCell.getFormula()->HasRefListExpressibleAsOneReference(aRef))
                 continue;
 
             if ( aRef.aStart.Col() == nCol && aRef.aEnd.Col() == nCol &&
@@ -4179,8 +4179,8 @@ void ScTable::CopyData( SCCOL nStartCol, SCROW nStartRow, 
SCCOL nEndCol, SCROW n
                 aCxt.mnColDelta = nDestCol - nStartCol;
                 aCxt.mnRowDelta = nDestRow - nStartRow;
                 aCxt.mnTabDelta = nDestTab - nTab;
-                aCell.mpFormula->UpdateReference(aCxt);
-                aCell.mpFormula->aPos = aDest;
+                aCell.getFormula()->UpdateReference(aCxt);
+                aCell.getFormula()->aPos = aDest;
             }
 
             if (bThisTab)
diff --git a/sc/source/core/data/table3.cxx b/sc/source/core/data/table3.cxx
index 5e7e58d0184f..391d012344b7 100644
--- a/sc/source/core/data/table3.cxx
+++ b/sc/source/core/data/table3.cxx
@@ -741,13 +741,13 @@ void fillSortedColumnArray(
                     case CELLTYPE_FORMULA:
                         {
                             assert(rCell.mpAttr);
-                            ScAddress aOldPos = rCell.maCell.mpFormula->aPos;
+                            ScAddress aOldPos = 
rCell.maCell.getFormula()->aPos;
 
                             const ScAddress aCellPos(nCol1 + j, nRow, nTab);
-                            ScFormulaCell* pNew = 
rCell.maCell.mpFormula->Clone( aCellPos );
+                            ScFormulaCell* pNew = 
rCell.maCell.getFormula()->Clone( aCellPos );
                             if (pArray->IsUpdateRefs())
                             {
-                                
pNew->CopyAllBroadcasters(*rCell.maCell.mpFormula);
+                                
pNew->CopyAllBroadcasters(*rCell.maCell.getFormula());
                                 
pNew->GetCode()->AdjustReferenceOnMovedOrigin(aOldPos, aCellPos);
                             }
                             else
@@ -760,7 +760,7 @@ void fillSortedColumnArray(
                                 // Original source cells will be deleted during
                                 // sc::CellStoreType::transfer(), SvtListener 
is a base
                                 // class, so we need to replace it.
-                                auto it( ::std::find( rCellListeners.begin(), 
rCellListeners.end(), rCell.maCell.mpFormula));
+                                auto it( ::std::find( rCellListeners.begin(), 
rCellListeners.end(), rCell.maCell.getFormula()));
                                 if (it != rCellListeners.end())
                                     *it = pNew;
                             }
@@ -1539,12 +1539,12 @@ short ScTable::CompareCell(
             bool bStr1 = ( eType1 != CELLTYPE_VALUE );
             if (eType1 == CELLTYPE_FORMULA)
             {
-                if (rCell1.mpFormula->GetErrCode() != FormulaError::NONE)
+                if (rCell1.getFormula()->GetErrCode() != FormulaError::NONE)
                 {
                     bErr1 = true;
                     bStr1 = false;
                 }
-                else if (rCell1.mpFormula->IsValue())
+                else if (rCell1.getFormula()->IsValue())
                 {
                     bStr1 = false;
                 }
@@ -1554,12 +1554,12 @@ short ScTable::CompareCell(
             bool bStr2 = ( eType2 != CELLTYPE_VALUE );
             if (eType2 == CELLTYPE_FORMULA)
             {
-                if (rCell2.mpFormula->GetErrCode() != FormulaError::NONE)
+                if (rCell2.getFormula()->GetErrCode() != FormulaError::NONE)
                 {
                     bErr2 = true;
                     bStr2 = false;
                 }
-                else if (rCell2.mpFormula->IsValue())
+                else if (rCell2.getFormula()->IsValue())
                 {
                     bStr2 = false;
                 }
@@ -2611,10 +2611,10 @@ SCSIZE ScTable::Query(const ScQueryParam& rParamOrg, 
bool bKeepSub)
                 if (aCell.getType() != CELLTYPE_FORMULA)
                     continue;
 
-                if (!aCell.mpFormula->IsSubTotal())
+                if (!aCell.getFormula()->IsSubTotal())
                     continue;
 
-                if (RefVisible(aCell.mpFormula))
+                if (RefVisible(aCell.getFormula()))
                     bValid = true;
             }
         }
diff --git a/sc/source/core/data/table4.cxx b/sc/source/core/data/table4.cxx
index 71e2c6aba984..035e086ce2bb 100644
--- a/sc/source/core/data/table4.cxx
+++ b/sc/source/core/data/table4.cxx
@@ -1495,7 +1495,7 @@ OUString ScTable::GetAutoFillPreview( const ScRange& 
rSource, SCCOL nEndX, SCROW
                         nStart = aCell.getDouble();
                     break;
                     case CELLTYPE_FORMULA:
-                        nStart = aCell.mpFormula->GetValue();
+                        nStart = aCell.getFormula()->GetValue();
                     break;
                     default:
                         nStart = 0.0;
@@ -1766,7 +1766,7 @@ void ScTable::FillSeriesSimple(
             case CELLTYPE_FORMULA:
             {
                 FillFormulaVertical(
-                    *rSrcCell.mpFormula, rInner, rCol, nIMin, nIMax, 
pProgress, rProgress);
+                    *rSrcCell.getFormula(), rInner, rCol, nIMin, nIMax, 
pProgress, rProgress);
             }
             break;
             default:
@@ -1805,7 +1805,7 @@ void ScTable::FillSeriesSimple(
                     if (bHidden)
                         continue;
 
-                    FillFormula(rSrcCell.mpFormula, rCol, rRow, (rInner == 
nIMax));
+                    FillFormula(rSrcCell.getFormula(), rCol, rRow, (rInner == 
nIMax));
                     if (pProgress)
                         pProgress->SetStateOnPercent(++rProgress);
                 }
@@ -1890,7 +1890,7 @@ void ScTable::FillAutoSimple(
                     aSrcCell = GetCellValue(rCol, nSource);
                     if (nISrcStart == nISrcEnd && aSrcCell.getType() == 
CELLTYPE_FORMULA)
                     {
-                        FillFormulaVertical(*aSrcCell.mpFormula, rInner, rCol, 
nIStart, nIEnd, pProgress, rProgress);
+                        FillFormulaVertical(*aSrcCell.getFormula(), rInner, 
rCol, nIStart, nIEnd, pProgress, rProgress);
                         return;
                     }
                     const SvNumFormatType nFormatType = 
rDocument.GetFormatTable()->GetType(
@@ -1984,7 +1984,7 @@ void ScTable::FillAutoSimple(
                     break;
                 case CELLTYPE_FORMULA :
                     FillFormula(
-                        aSrcCell.mpFormula, rCol, rRow, (rInner == nIEnd));
+                        aSrcCell.getFormula(), rCol, rRow, (rInner == nIEnd));
                     if (nFormulaCounter - nActFormCnt > nMaxFormCnt)
                         nMaxFormCnt = nFormulaCounter - nActFormCnt;
                     break;
@@ -2236,7 +2236,7 @@ void ScTable::FillSeries( SCCOL nCol1, SCROW nRow1, SCCOL 
nCol2, SCROW nRow2,
             if (aSrcCell.getType() == CELLTYPE_VALUE)
                 nStartVal = aSrcCell.getDouble();
             else
-                nStartVal = aSrcCell.mpFormula->GetValue();
+                nStartVal = aSrcCell.getFormula()->GetValue();
             if (eFillCmd == FILL_LINEAR)
             {
                 if (nStepValue == 0.0)
@@ -2363,7 +2363,7 @@ void ScTable::FillSeries( SCCOL nCol1, SCROW nRow1, SCCOL 
nCol2, SCROW nRow2,
             else if (eCellType == CELLTYPE_VALUE || eCellType == 
CELLTYPE_FORMULA)
             {
                 const double nStartVal = (eCellType == CELLTYPE_VALUE ? 
aSrcCell.getDouble() :
-                        aSrcCell.mpFormula->GetValue());
+                        aSrcCell.getFormula()->GetValue());
                 double nVal = nStartVal;
                 tools::Long nIndex = 0;
 
diff --git a/sc/source/core/data/table5.cxx b/sc/source/core/data/table5.cxx
index 5de4908ee226..ad136f53bb4b 100644
--- a/sc/source/core/data/table5.cxx
+++ b/sc/source/core/data/table5.cxx
@@ -1238,7 +1238,7 @@ void ScTable::InvalidateTextWidth(const ScAddress* 
pAdrFrom, const ScAddress* pA
                     rCol.Broadcast(nRow);
                     break;
                 case CELLTYPE_FORMULA:
-                    aCell.mpFormula->SetDirty();
+                    aCell.getFormula()->SetDirty();
                     break;
                 default:
                 {
@@ -1280,7 +1280,7 @@ void ScTable::InvalidateTextWidth(const ScAddress* 
pAdrFrom, const ScAddress* pA
                         aCol[nCol].Broadcast(nRow);
                         break;
                     case CELLTYPE_FORMULA:
-                        aCell.mpFormula->SetDirty();
+                        aCell.getFormula()->SetDirty();
                         break;
                     default:
                     {
diff --git a/sc/source/core/data/table6.cxx b/sc/source/core/data/table6.cxx
index 29f7d7ef886b..6d983811af9d 100644
--- a/sc/source/core/data/table6.cxx
+++ b/sc/source/core/data/table6.cxx
@@ -88,7 +88,7 @@ bool ScTable::SearchCell(const SvxSearchItem& rSearchItem, 
SCCOL nCol, sc::Colum
         case SvxSearchCellType::FORMULA:
         {
             if ( eCellType == CELLTYPE_FORMULA )
-                aString = aCell.mpFormula->GetFormula(rDocument.GetGrammar());
+                aString = 
aCell.getFormula()->GetFormula(rDocument.GetGrammar());
             else if ( eCellType == CELLTYPE_EDIT )
                 bMultiLine = lcl_GetTextWithBreaks(*aCell.getEditText(), 
&rDocument, aString);
             else
@@ -165,7 +165,7 @@ bool ScTable::SearchCell(const SvxSearchItem& rSearchItem, 
SCCOL nCol, sc::Colum
     // Don't split the matrix, only replace Matrix formulas
     if (eCellType == CELLTYPE_FORMULA)
     {
-        cMatrixFlag = aCell.mpFormula->GetMatrixFlag();
+        cMatrixFlag = aCell.getFormula()->GetMatrixFlag();
         if(cMatrixFlag == ScMatrixMode::Reference)
             return bFound;
     }
@@ -260,7 +260,7 @@ bool ScTable::SearchCell(const SvxSearchItem& rSearchItem, 
SCCOL nCol, sc::Colum
             aString, rDocument.GetGrammar(), cMatrixFlag );
         SCCOL nMatCols;
         SCROW nMatRows;
-        aCell.mpFormula->GetMatColsRows(nMatCols, nMatRows);
+        aCell.getFormula()->GetMatColsRows(nMatCols, nMatRows);
         pFCell->SetMatColsRows( nMatCols, nMatRows );
         aCol[nCol].SetFormulaCell(nRow, pFCell);
     }
diff --git a/sc/source/core/data/validat.cxx b/sc/source/core/data/validat.cxx
index 3140a01c3978..c4ee30152af2 100644
--- a/sc/source/core/data/validat.cxx
+++ b/sc/source/core/data/validat.cxx
@@ -589,7 +589,7 @@ bool ScValidationData::IsDataValid( ScRefCellValue& rCell, 
const ScAddress& rPos
         break;
         case CELLTYPE_FORMULA:
         {
-            ScFormulaCell* pFCell = rCell.mpFormula;
+            ScFormulaCell* pFCell = rCell.getFormula();
             bIsVal = pFCell->IsValue();
             if ( bIsVal )
                 nVal  = pFCell->GetValue();
diff --git a/sc/source/core/tool/cellform.cxx b/sc/source/core/tool/cellform.cxx
index 6c06d2e279f1..3da99aec0b2f 100644
--- a/sc/source/core/tool/cellform.cxx
+++ b/sc/source/core/tool/cellform.cxx
@@ -62,7 +62,7 @@ OUString ScCellFormat::GetString( const ScRefCellValue& 
rCell, sal_uInt32 nForma
         }
         case CELLTYPE_FORMULA:
         {
-            ScFormulaCell*  pFCell = rCell.mpFormula;
+            ScFormulaCell*  pFCell = rCell.getFormula();
             if ( bFormula )
             {
                 return pFCell->GetFormula();
@@ -147,7 +147,7 @@ OUString ScCellFormat::GetInputString(
         case CELLTYPE_FORMULA:
         {
             OUString str;
-            ScFormulaCell* pFC = rCell.mpFormula;
+            ScFormulaCell* pFC = rCell.getFormula();
             if (pFC->IsEmptyDisplayedAsString())
                 ; // empty
             else if (pFC->IsValue())
diff --git a/sc/source/core/tool/chartarr.cxx b/sc/source/core/tool/chartarr.cxx
index ba2c30b17941..e9e277601fed 100644
--- a/sc/source/core/tool/chartarr.cxx
+++ b/sc/source/core/tool/chartarr.cxx
@@ -94,7 +94,7 @@ double getCellValue( ScDocument& rDoc, const ScAddress& rPos, 
double fDefault, b
         break;
         case CELLTYPE_FORMULA:
         {
-            ScFormulaCell* pFCell = aCell.mpFormula;
+            ScFormulaCell* pFCell = aCell.getFormula();
             if (pFCell && pFCell->GetErrCode() == FormulaError::NONE && 
pFCell->IsValue())
                 fRet = pFCell->GetValue();
         }
diff --git a/sc/source/core/tool/chgtrack.cxx b/sc/source/core/tool/chgtrack.cxx
index d78070de6569..29cc75e5d5a6 100644
--- a/sc/source/core/tool/chgtrack.cxx
+++ b/sc/source/core/tool/chgtrack.cxx
@@ -1368,7 +1368,7 @@ void ScChangeActionContent::SetValueString(
         rCell = ScCellValue(new ScFormulaCell(
             *pDoc, aBigRange.aStart.MakeAddress(*pDoc), rStr,
             pDoc->GetGrammar() ));
-        rCell.mpFormula->SetInChangeTrack(true);
+        rCell.getFormula()->SetInChangeTrack(true);
     }
     else
         rValue = rStr;
@@ -1441,7 +1441,7 @@ OUString ScChangeActionContent::GetRefString(
             ScBigRange aLocalBigRange( GetBigRange() );
             SCCOL nC;
             SCROW nR;
-            rCell.mpFormula->GetMatColsRows( nC, nR );
+            rCell.getFormula()->GetMatColsRows( nC, nR );
             aLocalBigRange.aEnd.IncCol( nC-1 );
             aLocalBigRange.aEnd.IncRow( nR-1 );
             return ScChangeAction::GetRefString( aLocalBigRange, rDoc, bFlag3D 
);
@@ -1570,7 +1570,7 @@ OUString ScChangeActionContent::GetStringOfCell(
                 return ScEditUtil::GetString(*rCell.getEditText(), pDoc);
             return OUString();
         case CELLTYPE_FORMULA:
-            return rCell.mpFormula->GetFormula();
+            return rCell.getFormula()->GetFormula();
         default:
             return OUString();
     }
@@ -1585,7 +1585,7 @@ ScChangeActionContentCellType 
ScChangeActionContent::GetContentCellType( const S
         case CELLTYPE_EDIT :
             return SC_CACCT_NORMAL;
         case CELLTYPE_FORMULA :
-            switch (rCell.mpFormula->GetMatrixFlag())
+            switch (rCell.getFormula()->GetMatrixFlag())
             {
                 case ScMatrixMode::NONE :
                     return SC_CACCT_NORMAL;
@@ -1610,7 +1610,7 @@ ScChangeActionContentCellType 
ScChangeActionContent::GetContentCellType( const S
             return SC_CACCT_NORMAL;
         case CELLTYPE_FORMULA:
         {
-            const ScFormulaCell* pCell = rCell.mpFormula;
+            const ScFormulaCell* pCell = rCell.getFormula();
             switch (pCell->GetMatrixFlag())
             {
                 case ScMatrixMode::NONE :
@@ -1660,7 +1660,7 @@ void ScChangeActionContent::SetValue(
             }
             break;
             case CELLTYPE_FORMULA :
-                rCell.mpFormula->SetInChangeTrack(true);
+                rCell.getFormula()->SetInChangeTrack(true);
             break;
             default:
             {
@@ -1685,7 +1685,7 @@ void ScChangeActionContent::SetCell( OUString& rStr, 
ScCellValue& rCell, sal_uLo
             pDoc->GetFormatTable()->GetInputLineString(rCell.getDouble(), 
nFormat, rStr);
         break;
         case CELLTYPE_FORMULA :
-            rCell.mpFormula->SetInChangeTrack(true);
+            rCell.getFormula()->SetInChangeTrack(true);
         break;
         default:
         {
@@ -1713,7 +1713,7 @@ OUString ScChangeActionContent::GetValueString(
         case CELLTYPE_VALUE : // Is always in rValue
             return rValue;
         case CELLTYPE_FORMULA :
-            return GetFormulaString(rCell.mpFormula);
+            return GetFormulaString(rCell.getFormula());
         case CELLTYPE_NONE:
         default:
             return OUString();
@@ -1780,7 +1780,7 @@ void ScChangeActionContent::PutValueToDoc(
         {
             SCCOL nC;
             SCROW nR;
-            rCell.mpFormula->GetMatColsRows(nC, nR);
+            rCell.getFormula()->GetMatColsRows(nC, nR);
             OSL_ENSURE( nC>0 && nR>0, "ScChangeActionContent::PutValueToDoc: 
MatColsRows?" );
             ScRange aRange( aPos );
             if ( nC > 1 )
@@ -1792,7 +1792,7 @@ void ScChangeActionContent::PutValueToDoc(
             aDestMark.SetMarkArea( aRange );
             pDoc->InsertMatrixFormula( aPos.Col(), aPos.Row(),
                 aRange.aEnd.Col(), aRange.aEnd.Row(),
-                aDestMark, OUString(), rCell.mpFormula->GetCode());
+                aDestMark, OUString(), rCell.getFormula()->GetCode());
         }
         break;
         case SC_CACCT_MATREF :
@@ -1893,9 +1893,9 @@ void ScChangeActionContent::UpdateReference( const 
ScChangeTrack* pTrack,
             // Move is Source here and Target there
             // Position needs to be adjusted before that
             if ( bOldFormula )
-                maOldCell.mpFormula->aPos = 
aBigRange.aStart.MakeAddress(pTrack->GetDocument());
+                maOldCell.getFormula()->aPos = 
aBigRange.aStart.MakeAddress(pTrack->GetDocument());
             if ( bNewFormula )
-                maNewCell.mpFormula->aPos = 
aBigRange.aStart.MakeAddress(pTrack->GetDocument());
+                maNewCell.getFormula()->aPos = 
aBigRange.aStart.MakeAddress(pTrack->GetDocument());
             if ( nDx )
             {
                 aTmpRange.aStart.IncCol( nDx );
@@ -1927,9 +1927,9 @@ void ScChangeActionContent::UpdateReference( const 
ScChangeTrack* pTrack,
     aRefCxt.mnTabDelta = nDz;
 
     if ( bOldFormula )
-        maOldCell.mpFormula->UpdateReference(aRefCxt);
+        maOldCell.getFormula()->UpdateReference(aRefCxt);
     if ( bNewFormula )
-        maNewCell.mpFormula->UpdateReference(aRefCxt);
+        maNewCell.getFormula()->UpdateReference(aRefCxt);
 
     if ( aBigRange.aStart.IsValid( pTrack->GetDocument() ) )
         return;
@@ -1942,7 +1942,7 @@ void ScChangeActionContent::UpdateReference( const 
ScChangeTrack* pTrack,
     if ( bOldFormula )
     {
         formula::FormulaToken* t;
-        ScTokenArray* pArr = maOldCell.mpFormula->GetCode();
+        ScTokenArray* pArr = maOldCell.getFormula()->GetCode();
         formula::FormulaTokenArrayPlainIterator aIter(*pArr);
         while ( ( t = aIter.GetNextReference() ) != nullptr )
             lcl_InvalidateReference( pTrack->GetDocument(), *t, rPos );
@@ -1953,7 +1953,7 @@ void ScChangeActionContent::UpdateReference( const 
ScChangeTrack* pTrack,
     if ( bNewFormula )
     {
         formula::FormulaToken* t;
-        ScTokenArray* pArr = maNewCell.mpFormula->GetCode();
+        ScTokenArray* pArr = maNewCell.getFormula()->GetCode();
         formula::FormulaTokenArrayPlainIterator aIter(*pArr);
         while ( ( t = aIter.GetNextReference() ) != nullptr )
             lcl_InvalidateReference( pTrack->GetDocument(), *t, rPos );
@@ -2537,11 +2537,11 @@ bool ScChangeTrack::IsMatrixFormulaRangeDifferent(
     nC1 = nC2 = 0;
     nR1 = nR2 = 0;
 
-    if (rOldCell.getType() == CELLTYPE_FORMULA && 
rOldCell.mpFormula->GetMatrixFlag() == ScMatrixMode::Formula)
-        rOldCell.mpFormula->GetMatColsRows(nC1, nR1);
+    if (rOldCell.getType() == CELLTYPE_FORMULA && 
rOldCell.getFormula()->GetMatrixFlag() == ScMatrixMode::Formula)
+        rOldCell.getFormula()->GetMatColsRows(nC1, nR1);
 
-    if (rNewCell.getType() == CELLTYPE_FORMULA && 
rNewCell.mpFormula->GetMatrixFlag() == ScMatrixMode::Formula)
-        rNewCell.mpFormula->GetMatColsRows(nC1, nR1);
+    if (rNewCell.getType() == CELLTYPE_FORMULA && 
rNewCell.getFormula()->GetMatrixFlag() == ScMatrixMode::Formula)
+        rNewCell.getFormula()->GetMatColsRows(nC1, nR1);
 
     return nC1 != nC2 || nR1 != nR2;
 }
@@ -2862,7 +2862,7 @@ void ScChangeTrack::Dependencies( ScChangeAction* pAct )
         if ( ScChangeActionContent::GetContentCellType(rCell) == 
SC_CACCT_MATREF )
         {
             ScAddress aOrg;
-            bool bOrgFound = rCell.mpFormula->GetMatrixOrigin(rDoc, aOrg);
+            bool bOrgFound = rCell.getFormula()->GetMatrixOrigin(rDoc, aOrg);
             ScChangeActionContent* pContent = (bOrgFound ? SearchContentAt( 
aOrg, pAct ) : nullptr);
             if ( pContent && pContent->IsMatrixOrigin() )
             {
@@ -4010,7 +4010,7 @@ bool ScChangeTrack::SelectContent( ScChangeAction* pAct, 
bool bOldest )
     {
         SCCOL nC;
         SCROW nR;
-        rCell.mpFormula->GetMatColsRows(nC, nR);
+        rCell.getFormula()->GetMatColsRows(nC, nR);
         aBigRange.aEnd.IncCol( nC-1 );
         aBigRange.aEnd.IncRow( nR-1 );
     }
diff --git a/sc/source/core/tool/detfunc.cxx b/sc/source/core/tool/detfunc.cxx
index 8cabace6a55c..a757a9edd628 100644
--- a/sc/source/core/tool/detfunc.cxx
+++ b/sc/source/core/tool/detfunc.cxx
@@ -811,7 +811,7 @@ sal_uInt16 ScDetectiveFunc::InsertPredLevel( SCCOL nCol, 
SCROW nRow, ScDetective
     if (aCell.getType() != CELLTYPE_FORMULA)
         return DET_INS_EMPTY;
 
-    ScFormulaCell* pFCell = aCell.mpFormula;
+    ScFormulaCell* pFCell = aCell.getFormula();
     if (pFCell->IsRunning())
         return DET_INS_CIRCULAR;
 
@@ -899,7 +899,7 @@ sal_uInt16 ScDetectiveFunc::FindPredLevel( SCCOL nCol, 
SCROW nRow, sal_uInt16 nL
     if (aCell.getType() != CELLTYPE_FORMULA)
         return nLevel;
 
-    ScFormulaCell* pFCell = aCell.mpFormula;
+    ScFormulaCell* pFCell = aCell.getFormula();
     if (pFCell->IsRunning())
         return nLevel;
 
@@ -956,7 +956,7 @@ sal_uInt16 ScDetectiveFunc::InsertErrorLevel( SCCOL nCol, 
SCROW nRow, ScDetectiv
     if (aCell.getType() != CELLTYPE_FORMULA)
         return DET_INS_EMPTY;
 
-    ScFormulaCell* pFCell = aCell.mpFormula;
+    ScFormulaCell* pFCell = aCell.getFormula();
     if (pFCell->IsRunning())
         return DET_INS_CIRCULAR;
 
diff --git a/sc/source/core/tool/interpr1.cxx b/sc/source/core/tool/interpr1.cxx
index b41bec6b7c3b..13745246a8b2 100644
--- a/sc/source/core/tool/interpr1.cxx
+++ b/sc/source/core/tool/interpr1.cxx
@@ -2057,7 +2057,7 @@ bool ScInterpreter::IsString()
                         bRes = true;
                         break;
                     case CELLTYPE_FORMULA :
-                        bRes = (!aCell.mpFormula->IsValue() && 
!aCell.mpFormula->IsEmpty());
+                        bRes = (!aCell.getFormula()->IsValue() && 
!aCell.getFormula()->IsEmpty());
                         break;
                     default:
                         ; // nothing
@@ -2654,7 +2654,7 @@ void ScInterpreter::ScIsValue()
                         bRes = true;
                         break;
                     case CELLTYPE_FORMULA :
-                        bRes = (aCell.mpFormula->IsValue() && 
!aCell.mpFormula->IsEmpty());
+                        bRes = (aCell.getFormula()->IsValue() && 
!aCell.getFormula()->IsEmpty());
                         break;
                     default:
                         ; // nothing
@@ -2806,7 +2806,7 @@ void ScInterpreter::ScFormula()
                         switch (aCell.getType())
                         {
                             case CELLTYPE_FORMULA :
-                                aFormula = 
aCell.mpFormula->GetFormula(formula::FormulaGrammar::GRAM_UNSPECIFIED, 
&mrContext);
+                                aFormula = 
aCell.getFormula()->GetFormula(formula::FormulaGrammar::GRAM_UNSPECIFIED, 
&mrContext);
                                 pResMat->PutString( mrStrPool.intern( 
aFormula), i,j);
                                 break;
                             default:
@@ -2832,7 +2832,7 @@ void ScInterpreter::ScFormula()
             switch (aCell.getType())
             {
                 case CELLTYPE_FORMULA :
-                    aFormula = 
aCell.mpFormula->GetFormula(formula::FormulaGrammar::GRAM_UNSPECIFIED, 
&mrContext);
+                    aFormula = 
aCell.getFormula()->GetFormula(formula::FormulaGrammar::GRAM_UNSPECIFIED, 
&mrContext);
                 break;
                 default:
                     SetError( FormulaError::NotAvailable );
@@ -3052,7 +3052,7 @@ bool ScInterpreter::IsEven()
                         bRes = true;
                     break;
                     case CELLTYPE_FORMULA :
-                        if (aCell.mpFormula->IsValue())
+                        if (aCell.getFormula()->IsValue())
                         {
                             fVal = GetCellValue(aAdr, aCell);
                             bRes = true;
@@ -3234,7 +3234,7 @@ void ScInterpreter::ScT()
                         bValue = true;
                         break;
                     case CELLTYPE_FORMULA :
-                        bValue = aCell.mpFormula->IsValue();
+                        bValue = aCell.getFormula()->IsValue();
                         break;
                     default:
                         ; // nothing
@@ -5113,7 +5113,7 @@ bool isCellContentEmpty( const ScRefCellValue& rCell )
             // OOo and LibreOffice prior to 4.4 did not treat ="" as blank in
             // COUNTBLANK(), we now do for Excel interoperability.
             /* TODO: introduce yet another compatibility option? */
-            sc::FormulaResultValue aRes = rCell.mpFormula->GetResult();
+            sc::FormulaResultValue aRes = rCell.getFormula()->GetResult();
             if (aRes.meType != sc::FormulaResultValue::String)
                 return false;
             if (!aRes.maString.isEmpty())
@@ -5297,7 +5297,7 @@ void ScInterpreter::IterateParametersIf( ScIterFuncIf 
eFunc )
                         bIsString = false;
                         break;
                     case CELLTYPE_FORMULA :
-                        if (aCell.mpFormula->IsValue())
+                        if (aCell.getFormula()->IsValue())
                         {
                             fVal = GetCellValue(aAdr, aCell);
                             bIsString = false;
@@ -5651,7 +5651,7 @@ void ScInterpreter::ScCountIf()
                     bIsString = false;
                     break;
                 case CELLTYPE_FORMULA :
-                    if (aCell.mpFormula->IsValue())
+                    if (aCell.getFormula()->IsValue())
                     {
                         fVal = GetCellValue(aAdr, aCell);
                         bIsString = false;
@@ -5921,7 +5921,7 @@ void ScInterpreter::IterateParametersIfs( 
double(*ResultFunc)( const sc::ParamIf
                             bIsString = false;
                             break;
                         case CELLTYPE_FORMULA :
-                            if (aCell.mpFormula->IsValue())
+                            if (aCell.getFormula()->IsValue())
                             {
                                 fVal = GetCellValue(aAdr, aCell);
                                 bIsString = false;
diff --git a/sc/source/core/tool/interpr4.cxx b/sc/source/core/tool/interpr4.cxx
index 4d0723140294..6f48fb96f3b2 100644
--- a/sc/source/core/tool/interpr4.cxx
+++ b/sc/source/core/tool/interpr4.cxx
@@ -133,7 +133,7 @@ sal_uInt32 ScInterpreter::GetCellNumberFormat( const 
ScAddress& rPos, ScRefCellV
     else
     {
         if (rCell.getType() == CELLTYPE_FORMULA)
-            nErr = rCell.mpFormula->GetErrCode();
+            nErr = rCell.getFormula()->GetErrCode();
         else
             nErr = FormulaError::NONE;
         nFormat = mrDoc.GetNumberFormat( mrContext, rPos );
@@ -156,7 +156,7 @@ double ScInterpreter::GetValueCellValue( const ScAddress& 
rPos, double fOrig )
 
 FormulaError ScInterpreter::GetCellErrCode( const ScRefCellValue& rCell )
 {
-    return rCell.getType() == CELLTYPE_FORMULA ? rCell.mpFormula->GetErrCode() 
: FormulaError::NONE;
+    return rCell.getType() == CELLTYPE_FORMULA ? 
rCell.getFormula()->GetErrCode() : FormulaError::NONE;
 }
 
 double ScInterpreter::ConvertStringToValue( const OUString& rStr )
@@ -193,7 +193,7 @@ double ScInterpreter::GetCellValueOrZero( const ScAddress& 
rPos, ScRefCellValue&
     {
         case CELLTYPE_FORMULA:
         {
-            ScFormulaCell* pFCell = rCell.mpFormula;
+            ScFormulaCell* pFCell = rCell.getFormula();
             FormulaError nErr = pFCell->GetErrCode();
             if( nErr == FormulaError::NONE )
             {
@@ -253,7 +253,7 @@ void ScInterpreter::GetCellString( svl::SharedString& rStr, 
ScRefCellValue& rCel
         break;
         case CELLTYPE_FORMULA:
         {
-            ScFormulaCell* pFCell = rCell.mpFormula;
+            ScFormulaCell* pFCell = rCell.getFormula();
             nErr = pFCell->GetErrCode();
             if (pFCell->IsValue())
             {
@@ -323,10 +323,10 @@ bool ScInterpreter::CreateDoubleArr(SCCOL nCol1, SCROW 
nRow1, SCTAB nTab1,
                             nVal = GetValueCellValue(aAdr, aCell.getDouble());
                             break;
                         case CELLTYPE_FORMULA :
-                            if (aCell.mpFormula->IsValue())
+                            if (aCell.getFormula()->IsValue())
                             {
-                                nErr = aCell.mpFormula->GetErrCode();
-                                nVal = aCell.mpFormula->GetValue();
+                                nErr = aCell.getFormula()->GetErrCode();
+                                nVal = aCell.getFormula()->GetValue();
                             }
                             else
                                 bOk = false;
@@ -403,10 +403,10 @@ bool ScInterpreter::CreateStringArr(SCCOL nCol1, SCROW 
nRow1, SCTAB nTab1,
                             aStr = aCell.getString(&mrDoc);
                             break;
                         case CELLTYPE_FORMULA:
-                            if (!aCell.mpFormula->IsValue())
+                            if (!aCell.getFormula()->IsValue())
                             {
-                                nErr = aCell.mpFormula->GetErrCode();
-                                aStr = 
aCell.mpFormula->GetString().getString();
+                                nErr = aCell.getFormula()->GetErrCode();
+                                aStr = 
aCell.getFormula()->GetString().getString();
                             }
                             else
                                 bOk = false;
@@ -511,11 +511,11 @@ bool ScInterpreter::CreateCellArr(SCCOL nCol1, SCROW 
nRow1, SCTAB nTab1,
                             nVal = GetValueCellValue(aAdr, aCell.getDouble());
                             break;
                         case CELLTYPE_FORMULA :
-                            nErr = aCell.mpFormula->GetErrCode();
-                            if (aCell.mpFormula->IsValue())
-                                nVal = aCell.mpFormula->GetValue();
+                            nErr = aCell.getFormula()->GetErrCode();
+                            if (aCell.getFormula()->IsValue())
+                                nVal = aCell.getFormula()->GetValue();
                             else
-                                aStr = 
aCell.mpFormula->GetString().getString();
+                                aStr = 
aCell.getFormula()->GetString().getString();
                             break;
                         default :
                             bOk = false;
@@ -698,7 +698,7 @@ void ScInterpreter::PushCellResultToken( bool 
bDisplayEmptyAsString,
 
     FormulaError nErr = FormulaError::NONE;
     if (aCell.getType() == CELLTYPE_FORMULA)
-        nErr = aCell.mpFormula->GetErrCode();
+        nErr = aCell.getFormula()->GetErrCode();
 
     if (nErr != FormulaError::NONE)
     {
@@ -1410,7 +1410,7 @@ void ScInterpreter::PopRefListPushMatrixOrRef()
                         ScAddress aAdr( nCol, nRow, nTab);
                         ScRefCellValue aCell(mrDoc, aAdr);
                         if (aCell.hasError())
-                            xMat->PutError( aCell.mpFormula->GetErrCode(), 0, 
i);
+                            xMat->PutError( aCell.getFormula()->GetErrCode(), 
0, i);
                         else if (aCell.hasEmptyValue())
                             xMat->PutEmpty( 0, i);
                         else if (aCell.hasString())
@@ -3554,16 +3554,16 @@ bool ScInterpreter::SetSbxVariable( SbxVariable* pVar, 
const ScAddress& rPos )
                 pVar->PutString(aCell.getString(&mrDoc));
             break;
             case CELLTYPE_FORMULA :
-                nErr = aCell.mpFormula->GetErrCode();
+                nErr = aCell.getFormula()->GetErrCode();
                 if( nErr == FormulaError::NONE )
                 {
-                    if (aCell.mpFormula->IsValue())
+                    if (aCell.getFormula()->IsValue())
                     {
-                        nVal = aCell.mpFormula->GetValue();
+                        nVal = aCell.getFormula()->GetValue();
                         pVar->PutDouble( nVal );
                     }
                     else
-                        
pVar->PutString(aCell.mpFormula->GetString().getString());
+                        
pVar->PutString(aCell.getFormula()->GetString().getString());
                 }
                 else
                 {
@@ -3614,7 +3614,7 @@ void ScInterpreter::ScTableOp()
         {   // emulate broadcast and indirectly collect cell pointers
             ScRefCellValue aCell(mrDoc, rPos);
             if (aCell.getType() == CELLTYPE_FORMULA)
-                aCell.mpFormula->SetTableOpDirty();
+                aCell.getFormula()->SetTableOpDirty();
         }
     }
     else
@@ -3627,7 +3627,7 @@ void ScInterpreter::ScTableOp()
 
     ScRefCellValue aCell(mrDoc, aTableOp.aFormulaPos);
     if (aCell.getType() == CELLTYPE_FORMULA)
-        aCell.mpFormula->SetDirtyVar();
+        aCell.getFormula()->SetDirtyVar();
     if (aCell.hasNumeric())
     {
         PushDouble(GetCellValue(aTableOp.aFormulaPos, aCell));
@@ -3658,8 +3658,8 @@ void ScInterpreter::ScTableOp()
 
     if (aCell.getType() == CELLTYPE_FORMULA)
     {
-        aCell.mpFormula->SetDirtyVar();
-        aCell.mpFormula->GetErrCode();     // recalculate original
+        aCell.getFormula()->SetDirtyVar();
+        aCell.getFormula()->GetErrCode();     // recalculate original
     }
 
     // Reset all dirty flags so next incarnation does really collect all cell
diff --git a/sc/source/core/tool/interpr5.cxx b/sc/source/core/tool/interpr5.cxx
index f3905eedc665..c8bd1c31a5b8 100644
--- a/sc/source/core/tool/interpr5.cxx
+++ b/sc/source/core/tool/interpr5.cxx
@@ -427,7 +427,7 @@ ScMatrixRef ScInterpreter::CreateMatrixFromDoubleRef( const 
FormulaToken* pToken
             }
             else if (aCell.hasError())
             {
-                pMat->PutError( aCell.mpFormula->GetErrCode(), nMatCol, 
nMatRow);
+                pMat->PutError( aCell.getFormula()->GetErrCode(), nMatCol, 
nMatRow);
             }
             else if (aCell.hasNumeric())
             {
@@ -650,12 +650,12 @@ void ScInterpreter::ScMatValue()
             ScRefCellValue aCell(mrDoc, aAdr);
             if (aCell.getType() == CELLTYPE_FORMULA)
             {
-                FormulaError nErrCode = aCell.mpFormula->GetErrCode();
+                FormulaError nErrCode = aCell.getFormula()->GetErrCode();
                 if (nErrCode != FormulaError::NONE)
                     PushError( nErrCode);
                 else
                 {
-                    const ScMatrix* pMat = aCell.mpFormula->GetMatrix();
+                    const ScMatrix* pMat = aCell.getFormula()->GetMatrix();
                     CalculateMatrixValue(pMat,nC,nR);
                 }
             }
@@ -3223,7 +3223,7 @@ void ScInterpreter::ScMatRef()
         return;
     }
 
-    if (aCell.mpFormula->IsRunning())
+    if (aCell.getFormula()->IsRunning())
     {
         // Twisted odd corner case where an array element's cell tries to
         // access the top left matrix while it is still running, see tdf#88737
@@ -3233,7 +3233,7 @@ void ScInterpreter::ScMatRef()
         return;
     }
 
-    const ScMatrix* pMat = aCell.mpFormula->GetMatrix();
+    const ScMatrix* pMat = aCell.getFormula()->GetMatrix();
     if (pMat)
     {
         SCSIZE nCols, nRows;
@@ -3298,14 +3298,14 @@ void ScInterpreter::ScMatRef()
         nFuncFmtType = nCurFmtType;
         nFuncFmtIndex = nCurFmtIndex;
         // If not a result matrix, obtain the cell value.
-        FormulaError nErr = aCell.mpFormula->GetErrCode();
+        FormulaError nErr = aCell.getFormula()->GetErrCode();
         if (nErr != FormulaError::NONE)
             PushError( nErr );
-        else if (aCell.mpFormula->IsValue())
-            PushDouble(aCell.mpFormula->GetValue());
+        else if (aCell.getFormula()->IsValue())
+            PushDouble(aCell.getFormula()->GetValue());
         else
         {
-            svl::SharedString aVal = aCell.mpFormula->GetString();
+            svl::SharedString aVal = aCell.getFormula()->GetString();
             PushString( aVal );
         }
     }
diff --git a/sc/source/core/tool/rangeseq.cxx b/sc/source/core/tool/rangeseq.cxx
index a014705026ce..c4ceea23d3e1 100644
--- a/sc/source/core/tool/rangeseq.cxx
+++ b/sc/source/core/tool/rangeseq.cxx
@@ -266,7 +266,7 @@ bool ScRangeToSequence::FillMixedArray( uno::Any& rAny, 
ScDocument& rDoc, const
                 continue;
             }
 
-            if (aCell.getType() == CELLTYPE_FORMULA && 
aCell.mpFormula->GetErrCode() != FormulaError::NONE)
+            if (aCell.getType() == CELLTYPE_FORMULA && 
aCell.getFormula()->GetErrCode() != FormulaError::NONE)
             {
                 // if NV is allowed, leave empty for errors
                 bHasErrors = true;
diff --git a/sc/source/filter/dif/difexp.cxx b/sc/source/filter/dif/difexp.cxx
index cff9ad812ce8..4b433c3a5704 100644
--- a/sc/source/filter/dif/difexp.cxx
+++ b/sc/source/filter/dif/difexp.cxx
@@ -173,9 +173,9 @@ void ScFormatFilterPluginImpl::ScExportDif( SvStream& rOut, 
ScDocument* pDoc,
                     bWriteStringData = true;
                 break;
                 case CELLTYPE_FORMULA:
-                    if (aCell.mpFormula->GetErrCode() != FormulaError::NONE)
+                    if (aCell.getFormula()->GetErrCode() != FormulaError::NONE)
                         aOS.append(pNumDataERROR);
-                    else if (aCell.mpFormula->IsValue())
+                    else if (aCell.getFormula()->IsValue())
                     {
                         aOS.append(pNumData);
                         aString = pDoc->GetInputString( nColCnt, nRowCnt, nTab 
);
@@ -184,7 +184,7 @@ void ScFormatFilterPluginImpl::ScExportDif( SvStream& rOut, 
ScDocument* pDoc,
                     }
                     else
                     {
-                        aString = aCell.mpFormula->GetString().getString();
+                        aString = aCell.getFormula()->GetString().getString();
                         bWriteStringData = true;
                     }
 
diff --git a/sc/source/filter/excel/xetable.cxx 
b/sc/source/filter/excel/xetable.cxx
index c2b7138f6d60..f8afeb672fa9 100644
--- a/sc/source/filter/excel/xetable.cxx
+++ b/sc/source/filter/excel/xetable.cxx
@@ -2700,7 +2700,7 @@ XclExpCellTable::XclExpCellTable( const XclExpRoot& rRoot 
) :
 
                 xCell = new XclExpFormulaCell(
                     GetRoot(), aXclPos, pPattern, nMergeBaseXFId,
-                    *rScCell.mpFormula, maArrayBfr, maShrfmlaBfr, 
maTableopBfr);
+                    *rScCell.getFormula(), maArrayBfr, maShrfmlaBfr, 
maTableopBfr);
             }
             break;
 
diff --git a/sc/source/filter/html/htmlexp.cxx 
b/sc/source/filter/html/htmlexp.cxx
index d7e8ea2c7339..a032a44de20f 100644
--- a/sc/source/filter/html/htmlexp.cxx
+++ b/sc/source/filter/html/htmlexp.cxx
@@ -1096,7 +1096,7 @@ void ScHTMLExport::WriteCell( sc::ColumnBlockPosition& 
rBlockPos, SCCOL nCol, SC
                     fVal = pDoc->RoundValueAsShown( fVal, nFormat );
                 break;
             case CELLTYPE_FORMULA:
-                fVal = aCell.mpFormula->GetValue();
+                fVal = aCell.getFormula()->GetValue();
                 break;
             default:
                 OSL_FAIL( "value data with unsupported cell type" );
@@ -1180,7 +1180,7 @@ void ScHTMLExport::WriteCell( sc::ColumnBlockPosition& 
rBlockPos, SCCOL nCol, SC
     bool bWriteHyperLink(false);
     if (aCell.getType() == CELLTYPE_FORMULA)
     {
-        ScFormulaCell* pFCell = aCell.mpFormula;
+        ScFormulaCell* pFCell = aCell.getFormula();
         if (pFCell->IsHyperLinkCell())
         {
             OUString aCellText;
diff --git a/sc/source/filter/xcl97/XclExpChangeTrack.cxx 
b/sc/source/filter/xcl97/XclExpChangeTrack.cxx
index 3ab4836a0b4b..f3ccb382e1b2 100644
--- a/sc/source/filter/xcl97/XclExpChangeTrack.cxx
+++ b/sc/source/filter/xcl97/XclExpChangeTrack.cxx
@@ -898,7 +898,7 @@ void XclExpChTrCellContent::GetCellData(
         break;
         case CELLTYPE_FORMULA:
         {
-            const ScFormulaCell* pFmlCell = rScCell.mpFormula;
+            const ScFormulaCell* pFmlCell = rScCell.getFormula();
             rpData->mpFormulaCell = pFmlCell;
 
             const ScTokenArray* pTokenArray = pFmlCell->GetCode();
diff --git a/sc/source/filter/xml/XMLChangeTrackingExportHelper.cxx 
b/sc/source/filter/xml/XMLChangeTrackingExportHelper.cxx
index c3356ea79dff..1a3b22e6aad0 100644
--- a/sc/source/filter/xml/XMLChangeTrackingExportHelper.cxx
+++ b/sc/source/filter/xml/XMLChangeTrackingExportHelper.cxx
@@ -295,7 +295,7 @@ void ScChangeTrackingExportHelper::WriteFormulaCell(const 
ScCellValue& rCell, co
 {
     assert(rCell.getType() == CELLTYPE_FORMULA);
 
-    ScFormulaCell* pFormulaCell = rCell.mpFormula;
+    ScFormulaCell* pFormulaCell = rCell.getFormula();
     OUString sAddress;
     const ScDocument* pDoc = rExport.GetDocument();
     ScRangeStringConverter::GetStringFromAddress(sAddress, pFormulaCell->aPos, 
pDoc, ::formula::FormulaGrammar::CONV_OOO);
diff --git a/sc/source/filter/xml/XMLChangeTrackingImportHelper.cxx 
b/sc/source/filter/xml/XMLChangeTrackingImportHelper.cxx
index 13d5a4906375..26e4acbf80ce 100644
--- a/sc/source/filter/xml/XMLChangeTrackingImportHelper.cxx
+++ b/sc/source/filter/xml/XMLChangeTrackingImportHelper.cxx
@@ -60,7 +60,7 @@ const ScCellValue& ScMyCellInfo::CreateCell(ScDocument& rDoc)
         sal_Int32 nOffset(0);
         ScRangeStringConverter::GetAddressFromString(aPos, sFormulaAddress, 
rDoc, ::formula::FormulaGrammar::CONV_OOO, nOffset);
         maCell.set(new ScFormulaCell(rDoc, aPos, sFormula, eGrammar, 
nMatrixFlag));
-        maCell.mpFormula->SetMatColsRows(static_cast<SCCOL>(nMatrixCols), 
static_cast<SCROW>(nMatrixRows));
+        maCell.getFormula()->SetMatColsRows(static_cast<SCCOL>(nMatrixCols), 
static_cast<SCROW>(nMatrixRows));
     }
 
     if ((nType == css::util::NumberFormat::DATE || nType == 
css::util::NumberFormat::TIME) && sInputString.isEmpty())
@@ -671,12 +671,12 @@ void ScXMLChangeTrackingImportHelper::SetNewCell(const 
ScMyContentAction* pActio
             }
             else
             {
-                ScMatrixMode nMatrixFlag = aCell.mpFormula->GetMatrixFlag();
+                ScMatrixMode nMatrixFlag = aCell.getFormula()->GetMatrixFlag();
                 // With GRAM_ODFF reference detection is faster on compilation.
                 /* FIXME: new cell should be created with a clone
                  * of the token array instead. Any reason why this
                  * wasn't done? */
-                OUString sFormula = 
aCell.mpFormula->GetFormula(formula::FormulaGrammar::GRAM_ODFF);
+                OUString sFormula = 
aCell.getFormula()->GetFormula(formula::FormulaGrammar::GRAM_ODFF);
 
                 // #i87826# [Collaboration] Rejected move destroys formulas
                 // FIXME: adjust ScFormulaCell::GetFormula(), so that the 
right formula string
@@ -696,10 +696,10 @@ void ScXMLChangeTrackingImportHelper::SetNewCell(const 
ScMyContentAction* pActio
                 {
                     SCCOL nCols;
                     SCROW nRows;
-                    aCell.mpFormula->GetMatColsRows(nCols, nRows);
-                    aNewCell.mpFormula->SetMatColsRows(nCols, nRows);
+                    aCell.getFormula()->GetMatColsRows(nCols, nRows);
+                    aNewCell.getFormula()->SetMatColsRows(nCols, nRows);
                 }
-                aNewCell.mpFormula->SetInChangeTrack(true);
+                aNewCell.getFormula()->SetInChangeTrack(true);
                 pChangeActionContent->SetNewCell(aNewCell, &rDoc, OUString());
                 // #i40704# don't overwrite the formula string via 
SetNewValue()
             }
diff --git a/sc/source/filter/xml/xmlcelli.cxx 
b/sc/source/filter/xml/xmlcelli.cxx
index ea5a463b9ab5..1ee22c93e9b5 100644
--- a/sc/source/filter/xml/xmlcelli.cxx
+++ b/sc/source/filter/xml/xmlcelli.cxx
@@ -1029,7 +1029,7 @@ void ScXMLTableRowCellContext::PutTextCell( const 
ScAddress& rCurrentPos,
         bDoIncrement = aCell.getType() == CELLTYPE_FORMULA;
         if ( bDoIncrement )
         {
-            ScFormulaCell* pFCell = aCell.mpFormula;
+            ScFormulaCell* pFCell = aCell.getFormula();
             OUString aCellString;
             if (maStringValue)
                 aCellString = *maStringValue;
@@ -1122,7 +1122,7 @@ void ScXMLTableRowCellContext::PutValueCell( const 
ScAddress& rCurrentPos )
         ScRefCellValue aCell(*rXMLImport.GetDocument(), rCurrentPos);
         if (aCell.getType() == CELLTYPE_FORMULA)
         {
-            ScFormulaCell* pFCell = aCell.mpFormula;
+            ScFormulaCell* pFCell = aCell.getFormula();
             SetFormulaCell(pFCell);
             if (pFCell)
                 pFCell->SetNeedNumberFormat( true );
diff --git a/sc/source/filter/xml/xmlexprt.cxx 
b/sc/source/filter/xml/xmlexprt.cxx
index 7c69587ddb46..57c041f7f5ee 100644
--- a/sc/source/filter/xml/xmlexprt.cxx
+++ b/sc/source/filter/xml/xmlexprt.cxx
@@ -3169,7 +3169,7 @@ void ScXMLExport::WriteCell(ScMyCell& aCell, sal_Int32 
nEqualCellCount)
                 if (aCell.maBaseCell.getType() == CELLTYPE_FORMULA)
                 {
                     const bool bIsMatrix(bIsFirstMatrixCell || 
aCell.bIsMatrixCovered);
-                    ScFormulaCell* pFormulaCell = aCell.maBaseCell.mpFormula;
+                    ScFormulaCell* pFormulaCell = 
aCell.maBaseCell.getFormula();
                     if (!bIsMatrix || bIsFirstMatrixCell)
                     {
                         if (!mpCompileFormulaCxt)
@@ -3262,9 +3262,9 @@ void ScXMLExport::WriteCell(ScMyCell& aCell, sal_Int32 
nEqualCellCount)
         {
             WriteEditCell(aCell.maBaseCell.getEditText());
         }
-        else if (aCell.maBaseCell.getType() == CELLTYPE_FORMULA && 
aCell.maBaseCell.mpFormula->IsMultilineResult())
+        else if (aCell.maBaseCell.getType() == CELLTYPE_FORMULA && 
aCell.maBaseCell.getFormula()->IsMultilineResult())
         {
-            WriteMultiLineFormulaResult(aCell.maBaseCell.mpFormula);
+            WriteMultiLineFormulaResult(aCell.maBaseCell.getFormula());
         }
         else
         {
diff --git a/sc/source/ui/Accessibility/AccessibleCell.cxx 
b/sc/source/ui/Accessibility/AccessibleCell.cxx
index 0e9c174251c1..a23b9bb10292 100644
--- a/sc/source/ui/Accessibility/AccessibleCell.cxx
+++ b/sc/source/ui/Accessibility/AccessibleCell.cxx
@@ -430,7 +430,7 @@ void 
ScAccessibleCell::FillPrecedents(utl::AccessibleRelationSetHelper* pRelatio
     ScRefCellValue aCell(*mpDoc, maCellAddress);
     if (aCell.getType() == CELLTYPE_FORMULA)
     {
-        ScFormulaCell* pCell = aCell.mpFormula;
+        ScFormulaCell* pCell = aCell.getFormula();
         ScDetectiveRefIter aIter(*mpDoc, pCell);
         ScRange aRef;
         while ( aIter.GetNextRef( aRef ) )
diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx
index 23c43335365c..e5ab8cede75c 100644
--- a/sc/source/ui/docshell/docsh.cxx
+++ b/sc/source/ui/docshell/docsh.cxx
@@ -2125,15 +2125,15 @@ void ScDocShell::AsciiSave( SvStream& rStream, const 
ScImportOptions& rAsciiOpt,
                     FormulaError nErrCode;
                     if ( bShowFormulas )
                     {
-                        aString = pCell->mpFormula->GetFormula();
+                        aString = pCell->getFormula()->GetFormula();
                         bString = true;
                     }
-                    else if ((nErrCode = pCell->mpFormula->GetErrCode()) != 
FormulaError::NONE)
+                    else if ((nErrCode = pCell->getFormula()->GetErrCode()) != 
FormulaError::NONE)
                     {
                         aString = ScGlobal::GetErrorString( nErrCode );
                         bString = true;
                     }
-                    else if (pCell->mpFormula->IsValue())
+                    else if (pCell->getFormula()->IsValue())
                     {
                         sal_uInt32 nFormat = 
m_pDocument->GetNumberFormat(aPos);
                         if ( bFixedWidth || bSaveAsShown )
@@ -2157,7 +2157,7 @@ void ScDocShell::AsciiSave( SvStream& rStream, const 
ScImportOptions& rAsciiOpt,
                             aString = ScCellFormat::GetString(*pCell, nFormat, 
&pDummy, rFormatter, *m_pDocument);
                         }
                         else
-                            aString = 
pCell->mpFormula->GetString().getString();
+                            aString = 
pCell->getFormula()->GetString().getString();
                         bString = true;
                     }
                 }
diff --git a/sc/source/ui/docshell/docsh3.cxx b/sc/source/ui/docshell/docsh3.cxx
index 7ea21893a425..803ba61f8a7a 100644
--- a/sc/source/ui/docshell/docsh3.cxx
+++ b/sc/source/ui/docshell/docsh3.cxx
@@ -985,7 +985,7 @@ void ScDocShell::MergeDocument( ScDocument& rOtherDoc, bool 
bShared, bool bCheck
                             ScMatrixMode eMatrix = ScMatrixMode::NONE;
                             const ScCellValue& rCell = static_cast<const 
ScChangeActionContent*>(pSourceAction)->GetNewCell();
                             if (rCell.getType() == CELLTYPE_FORMULA)
-                                eMatrix = rCell.mpFormula->GetMatrixFlag();
+                                eMatrix = rCell.getFormula()->GetMatrixFlag();
                             switch ( eMatrix )
                             {
                                 case ScMatrixMode::NONE :
@@ -995,7 +995,7 @@ void ScDocShell::MergeDocument( ScDocument& rOtherDoc, bool 
bShared, bool bCheck
                                 {
                                     SCCOL nCols;
                                     SCROW nRows;
-                                    rCell.mpFormula->GetMatColsRows(nCols, 
nRows);
+                                    rCell.getFormula()->GetMatColsRows(nCols, 
nRows);
                                     aSourceRange.aEnd.SetCol( aPos.Col() + 
nCols - 1 );
                                     aSourceRange.aEnd.SetRow( aPos.Row() + 
nRows - 1 );
                                     aValue = aValue.copy(1, 
aValue.getLength()-2); // remove the 1st and last characters.
diff --git a/sc/source/ui/docshell/externalrefmgr.cxx 
b/sc/source/ui/docshell/externalrefmgr.cxx
index c05a42812729..6c994b9a2a68 100644
--- a/sc/source/ui/docshell/externalrefmgr.cxx
+++ b/sc/source/ui/docshell/externalrefmgr.cxx
@@ -1521,7 +1521,7 @@ static FormulaToken* convertToToken( ScDocument& 
rHostDoc, const ScDocument& rSr
             return new formula::FormulaDoubleToken(rCell.getDouble());
         case CELLTYPE_FORMULA:
         {
-            ScFormulaCell* pFCell = rCell.mpFormula;
+            ScFormulaCell* pFCell = rCell.getFormula();
             FormulaError nError = pFCell->GetErrCode();
             if (nError != FormulaError::NONE)
                 return new FormulaErrorToken( nError);
@@ -2948,7 +2948,7 @@ public:
                 break;
                 case CELLTYPE_FORMULA:
                 {
-                    sc::FormulaResultValue aRes = aCell.mpFormula->GetResult();
+                    sc::FormulaResultValue aRes = 
aCell.getFormula()->GetResult();
                     switch (aRes.meType)
                     {
                         case sc::FormulaResultValue::Value:
diff --git a/sc/source/ui/docshell/impex.cxx b/sc/source/ui/docshell/impex.cxx
index 78fbe41cdd6d..e26af9455929 100644
--- a/sc/source/ui/docshell/impex.cxx
+++ b/sc/source/ui/docshell/impex.cxx
@@ -1948,7 +1948,7 @@ bool ScImportExport::Doc2Text( SvStream& rStrm )
                     {
                         if (bFormulas)
                         {
-                            aCellStr = aCell.mpFormula->GetFormula();
+                            aCellStr = aCell.getFormula()->GetFormula();
                             if( aCellStr.indexOf( cSep ) != -1 )
                                 lcl_WriteString( rStrm, aCellStr, cStr, cStr );
                             else
@@ -2426,7 +2426,7 @@ bool ScImportExport::Doc2Sylk( SvStream& rStrm )
                 checkformula:
                     if( bForm )
                     {
-                        const ScFormulaCell* pFCell = aCell.mpFormula;
+                        const ScFormulaCell* pFCell = aCell.getFormula();
                         switch ( pFCell->GetMatrixFlag() )
                         {
                             case ScMatrixMode::Reference :
diff --git a/sc/source/ui/undo/undocell.cxx b/sc/source/ui/undo/undocell.cxx
index 80f4298ce1bb..480238023ef5 100644
--- a/sc/source/ui/undo/undocell.cxx
+++ b/sc/source/ui/undo/undocell.cxx
@@ -471,7 +471,7 @@ void ScUndoSetCell::SetValue( const ScCellValue& rVal )
             rDoc.SetEditText(maPos, rVal.getEditText()->Clone());
         break;
         case CELLTYPE_FORMULA:
-            rDoc.SetFormulaCell(maPos, rVal.mpFormula->Clone());
+            rDoc.SetFormulaCell(maPos, rVal.getFormula()->Clone());
         break;
         default:
             ;
diff --git a/sc/source/ui/unoobj/cellsuno.cxx b/sc/source/ui/unoobj/cellsuno.cxx
index 1d30e76aa6ee..da10552151ea 100644
--- a/sc/source/ui/unoobj/cellsuno.cxx
+++ b/sc/source/ui/unoobj/cellsuno.cxx
@@ -1332,7 +1332,7 @@ static OUString lcl_GetInputString( ScDocument& rDoc, 
const ScAddress& rPos, boo
     CellType eType = aCell.getType();
     if (eType == CELLTYPE_FORMULA)
     {
-        ScFormulaCell* pForm = aCell.mpFormula;
+        ScFormulaCell* pForm = aCell.getFormula();
         return pForm->GetFormula( formula::FormulaGrammar::mapAPItoGrammar( 
bEnglish, false));
     }
 
@@ -4802,8 +4802,8 @@ OUString SAL_CALL ScCellRangeObj::getArrayFormula()
     ScRefCellValue aCell2(rDoc, aRange.aEnd);
     if (aCell1.getType() == CELLTYPE_FORMULA && aCell2.getType() == 
CELLTYPE_FORMULA)
     {
-        const ScFormulaCell* pFCell1 = aCell1.mpFormula;
-        const ScFormulaCell* pFCell2 = aCell2.mpFormula;
+        const ScFormulaCell* pFCell1 = aCell1.getFormula();
+        const ScFormulaCell* pFCell2 = aCell2.getFormula();
         ScAddress aStart1;
         ScAddress aStart2;
         if (pFCell1->GetMatrixOrigin(rDoc, aStart1) && 
pFCell2->GetMatrixOrigin(rDoc, aStart2))
@@ -4866,8 +4866,8 @@ uno::Sequence<sheet::FormulaToken> SAL_CALL 
ScCellRangeObj::getArrayTokens()
     ScRefCellValue aCell2(rDoc, aRange.aEnd);
     if (aCell1.getType() == CELLTYPE_FORMULA && aCell2.getType() == 
CELLTYPE_FORMULA)
     {
-        const ScFormulaCell* pFCell1 = aCell1.mpFormula;
-        const ScFormulaCell* pFCell2 = aCell2.mpFormula;
+        const ScFormulaCell* pFCell1 = aCell1.getFormula();
+        const ScFormulaCell* pFCell2 = aCell2.getFormula();
         ScAddress aStart1;
         ScAddress aStart2;
         if (pFCell1->GetMatrixOrigin(rDoc, aStart1) && 
pFCell2->GetMatrixOrigin(rDoc, aStart2))
@@ -6161,7 +6161,7 @@ void SAL_CALL ScCellObj::setFormulaResult( double nValue )
         ScRefCellValue aCell(pDocSh->GetDocument(), aCellPos);
         if (aCell.getType() == CELLTYPE_FORMULA)
         {
-            ScFormulaCell* pCell = aCell.mpFormula;
+            ScFormulaCell* pCell = aCell.getFormula();
             pCell->SetHybridDouble( nValue );
             pCell->ResetDirty();
             pCell->SetChanged(false);
@@ -6245,7 +6245,7 @@ table::CellContentType ScCellObj::GetContentType_Impl()
         ScRefCellValue aCell(pDocSh->GetDocument(), aCellPos);
         if (aCell.getType() == CELLTYPE_FORMULA)
         {
-            bool bValue = aCell.mpFormula->IsValue();
+            bool bValue = aCell.getFormula()->IsValue();
             return bValue ? table::CellContentType_VALUE : 
table::CellContentType_TEXT;
         }
     }
@@ -6265,7 +6265,7 @@ sal_Int32 SAL_CALL ScCellObj::getError()
     FormulaError nError = FormulaError::NONE;
     ScRefCellValue aCell(pDocSh->GetDocument(), aCellPos);
     if (aCell.getType() == CELLTYPE_FORMULA)
-        nError = aCell.mpFormula->GetErrCode();
+        nError = aCell.getFormula()->GetErrCode();
 
     return static_cast<sal_Int32>(nError);
 }
@@ -6284,7 +6284,7 @@ uno::Sequence<sheet::FormulaToken> SAL_CALL 
ScCellObj::getTokens()
     ScRefCellValue aCell(rDoc, aCellPos);
     if (aCell.getType() == CELLTYPE_FORMULA)
     {
-        ScTokenArray* pTokenArray = aCell.mpFormula->GetCode();
+        ScTokenArray* pTokenArray = aCell.getFormula()->GetCode();
         if (pTokenArray)
             ScTokenConversion::ConvertToTokenSequence(rDoc, aSequence, 
*pTokenArray);
     }
diff --git a/sc/source/ui/unoobj/chart2uno.cxx 
b/sc/source/ui/unoobj/chart2uno.cxx
index 50ee015adfb1..acbd5272b037 100644
--- a/sc/source/ui/unoobj/chart2uno.cxx
+++ b/sc/source/ui/unoobj/chart2uno.cxx
@@ -2558,7 +2558,7 @@ void ScChart2DataSequence::BuildDataCache()
                             break;
                             case CELLTYPE_FORMULA:
                             {
-                                ScFormulaCell* pFCell = aCell.mpFormula;
+                                ScFormulaCell* pFCell = aCell.getFormula();
                                 FormulaError nErr = pFCell->GetErrCode();
                                 if (nErr != FormulaError::NONE)
                                     break;
diff --git a/sc/source/ui/view/cellsh1.cxx b/sc/source/ui/view/cellsh1.cxx
index 30a796e9f646..3c8e0fa061eb 100644
--- a/sc/source/ui/view/cellsh1.cxx
+++ b/sc/source/ui/view/cellsh1.cxx
@@ -3431,7 +3431,7 @@ void ScCellShell::ExecuteFillSingleEdit()
         if (aCell.getType() == CELLTYPE_FORMULA)
         {
             aInit = "=";
-            const ScTokenArray* pCode = aCell.mpFormula->GetCode();
+            const ScTokenArray* pCode = aCell.getFormula()->GetCode();
             sc::TokenStringContext aCxt(rDoc, rDoc.GetGrammar());
             aInit += pCode->CreateString(aCxt, aCurPos);
         }
diff --git a/sc/source/ui/view/gridwin.cxx b/sc/source/ui/view/gridwin.cxx
index 3bab80f8e94e..0d585cc430df 100644
--- a/sc/source/ui/view/gridwin.cxx
+++ b/sc/source/ui/view/gridwin.cxx
@@ -288,7 +288,7 @@ static bool lcl_IsEditableMatrix( ScDocument& rDoc, const 
ScRange& rRange )
 
     ScRefCellValue aCell(rDoc, rRange.aEnd);
     ScAddress aPos;
-    return (aCell.getType() == CELLTYPE_FORMULA && 
aCell.mpFormula->GetMatrixOrigin(rDoc, aPos) && aPos == rRange.aStart);
+    return (aCell.getType() == CELLTYPE_FORMULA && 
aCell.getFormula()->GetMatrixOrigin(rDoc, aPos) && aPos == rRange.aStart);
 }
 
 static void lcl_UnLockComment( ScDrawView* pView, const Point& rPos, const 
ScViewData& rViewData )
@@ -335,7 +335,7 @@ static bool lcl_GetHyperlinkCell(
             }
             else if (rCell.getType() == CELLTYPE_EDIT)
                 bFound = true;
-            else if (rCell.getType() == CELLTYPE_FORMULA && 
rCell.mpFormula->IsHyperLinkCell())
+            else if (rCell.getType() == CELLTYPE_FORMULA && 
rCell.getFormula()->IsHyperLinkCell())
                 bFound = true;
             else
                 return false;                               // other cell
@@ -5728,7 +5728,7 @@ bool ScGridWindow::GetEditUrl( const Point& rPos,
           // cell ( or other type ? ) with a hyperlink associated with it.
     {
         if (sURL.isEmpty())
-            pTextObj = aCell.mpFormula->CreateURLObject();
+            pTextObj = aCell.getFormula()->CreateURLObject();
         else
         {
             OUString aRepres = sURL;
@@ -5737,7 +5737,7 @@ bool ScGridWindow::GetEditUrl( const Point& rPos,
             if (aCell.hasNumeric())
                 aRepres = OUString::number(aCell.getValue());
             else if (aCell.getType() == CELLTYPE_FORMULA)
-                aRepres = aCell.mpFormula->GetString().getString();
+                aRepres = aCell.getFormula()->GetString().getString();
 
             pTextObj = ScEditUtil::CreateURLObjectFromURL(rDoc, sURL, aRepres);
         }
diff --git a/sc/source/ui/view/output.cxx b/sc/source/ui/view/output.cxx
index a9bdc4c3baef..24c94fd993f2 100644
--- a/sc/source/ui/view/output.cxx
+++ b/sc/source/ui/view/output.cxx
@@ -1837,7 +1837,7 @@ void ScOutputData::FindChanged()
             if (rCell.getType() != CELLTYPE_FORMULA)
                 continue;
 
-            ScFormulaCell* pFCell = rCell.mpFormula;
+            ScFormulaCell* pFCell = rCell.getFormula();
             if (pFCell->IsRunning())
                 // still being interpreted. Skip it.
                 continue;
@@ -1886,7 +1886,7 @@ void ScOutputData::FindChanged()
                 if (rCell.getType() != CELLTYPE_FORMULA)
                     continue;
 
-                ScFormulaCell* pFCell = rCell.mpFormula;
+                ScFormulaCell* pFCell = rCell.getFormula();
                 if (pFCell->IsRunning())
                     // still being interpreted. Skip it.
                     continue;
diff --git a/sc/source/ui/view/output2.cxx b/sc/source/ui/view/output2.cxx
index 64bb99ffc098..bd757cb7581f 100644
--- a/sc/source/ui/view/output2.cxx
+++ b/sc/source/ui/view/output2.cxx
@@ -611,7 +611,7 @@ void ScDrawStringsVars::SetTextToWidthOrHash( 
ScRefCellValue& rCell, tools::Long
 
     if (eType == CELLTYPE_FORMULA)
     {
-        ScFormulaCell* pFCell = rCell.mpFormula;
+        ScFormulaCell* pFCell = rCell.getFormula();
         if (pFCell->GetErrCode() != FormulaError::NONE || 
pOutput->mbShowFormulas)
         {
             SetHashText();      // If the error string doesn't fit, always use 
"###". Also for "display formulas" (#i116691#)
@@ -864,7 +864,7 @@ static void lcl_DoHyperlinkResult( const OutputDevice* 
pDev, const tools::Rectan
     OUString aURL;
     if (rCell.getType() == CELLTYPE_FORMULA)
     {
-        ScFormulaCell* pFCell = rCell.mpFormula;
+        ScFormulaCell* pFCell = rCell.getFormula();
         OUString aCellText;
         if ( pFCell->IsHyperLinkCell() )
             pFCell->GetURLResult( aURL, aCellText );
@@ -1724,10 +1724,10 @@ tools::Rectangle ScOutputData::LayoutStrings(bool 
bPixelToLogic, bool bPaint, co
                 {
                     bool bFormulaCell = (aCell.getType() == CELLTYPE_FORMULA);
                     if ( bFormulaCell )
-                        lcl_CreateInterpretProgress(bProgress, mpDoc, 
aCell.mpFormula);
+                        lcl_CreateInterpretProgress(bProgress, mpDoc, 
aCell.getFormula());
                     if ( aVars.SetText(aCell) )
                         pOldPattern = nullptr;
-                    bUseEditEngine = aVars.HasEditCharacters() || 
(bFormulaCell && aCell.mpFormula->IsMultilineResult());
+                    bUseEditEngine = aVars.HasEditCharacters() || 
(bFormulaCell && aCell.getFormula()->IsMultilineResult());
                 }
                 tools::Long nTotalMargin = 0;
                 SvxCellHorJustify eOutHorJust = SvxCellHorJustify::Standard;
@@ -1737,7 +1737,7 @@ tools::Rectangle ScOutputData::LayoutStrings(bool 
bPixelToLogic, bool bPaint, co
                     bCellIsValue = ( eCellType == CELLTYPE_VALUE );
                     if ( eCellType == CELLTYPE_FORMULA )
                     {
-                        ScFormulaCell* pFCell = aCell.mpFormula;
+                        ScFormulaCell* pFCell = aCell.getFormula();
                         bCellIsValue = pFCell->IsRunning() || 
pFCell->IsValue();
                     }
 
@@ -2130,7 +2130,7 @@ tools::Rectangle ScOutputData::LayoutStrings(bool 
bPixelToLogic, bool bPaint, co
                         }
 
                         // PDF: whole-cell hyperlink from formula?
-                        bool bHasURL = pPDFData && aCell.getType() == 
CELLTYPE_FORMULA && aCell.mpFormula->IsHyperLinkCell();
+                        bool bHasURL = pPDFData && aCell.getType() == 
CELLTYPE_FORMULA && aCell.getFormula()->IsHyperLinkCell();
                         if (bPaint && bHasURL)
                         {
                             tools::Rectangle aURLRect( aURLStart, 
aVars.GetTextSize() );
@@ -2192,7 +2192,7 @@ static bool lcl_SafeIsValue( ScRefCellValue& rCell )
             return true;
         case CELLTYPE_FORMULA:
         {
-            ScFormulaCell* pFCell = rCell.mpFormula;
+            ScFormulaCell* pFCell = rCell.getFormula();
             if (pFCell->IsRunning() || pFCell->IsValue())
                 return true;
         }
@@ -2559,7 +2559,7 @@ bool ScOutputData::DrawEditParam::isHyperlinkCell() const
     if (maCell.getType() != CELLTYPE_FORMULA)
         return false;
 
-    return maCell.mpFormula->IsHyperLinkCell();
+    return maCell.getFormula()->IsHyperLinkCell();
 }
 
 bool ScOutputData::DrawEditParam::isVerticallyOriented() const
diff --git a/sc/source/ui/view/tabvwsh.cxx b/sc/source/ui/view/tabvwsh.cxx
index 666d07a66fc7..f948d8326002 100644
--- a/sc/source/ui/view/tabvwsh.cxx
+++ b/sc/source/ui/view/tabvwsh.cxx
@@ -112,7 +112,7 @@ OUString ScTabViewShell::GetFormula(const ScAddress& 
rAddress)
     ScRefCellValue aCell(rDoc, rAddress);
     if (!aCell.isEmpty() && aCell.getType() == CELLTYPE_FORMULA)
     {
-        return aCell.mpFormula->GetFormula();
+        return aCell.getFormula()->GetFormula();
     }
     return OUString();
 }
diff --git a/sc/source/ui/view/tabvwsh5.cxx b/sc/source/ui/view/tabvwsh5.cxx
index 6b35721986a8..b701cc327e5e 100644
--- a/sc/source/ui/view/tabvwsh5.cxx
+++ b/sc/source/ui/view/tabvwsh5.cxx
@@ -339,9 +339,9 @@ std::unique_ptr<SvxNumberInfoItem> 
ScTabViewShell::MakeNumberInfoItem( ScDocumen
 
         case CELLTYPE_FORMULA:
         {
-            if (aCell.mpFormula->IsValue())
+            if (aCell.getFormula()->IsValue())
             {
-                nCellValue = aCell.mpFormula->GetValue();
+                nCellValue = aCell.getFormula()->GetValue();
                 eValType = SvxNumberValueType::Number;
             }
             else
diff --git a/sc/source/ui/view/tabvwsha.cxx b/sc/source/ui/view/tabvwsha.cxx
index 461f31ff7d08..f559732fff74 100644
--- a/sc/source/ui/view/tabvwsha.cxx
+++ b/sc/source/ui/view/tabvwsha.cxx
@@ -708,7 +708,7 @@ void ScTabViewShell::UpdateInputHandler( bool bForce /* = 
sal_False */, bool bSt
             if (rCell.getType() == CELLTYPE_FORMULA)
             {
                 if (!bHideFormula)
-                    aString = rCell.mpFormula->GetFormula();
+                    aString = rCell.getFormula()->GetFormula();
             }
             else if (rCell.getType() == CELLTYPE_EDIT)
             {
diff --git a/sc/source/ui/view/viewfun2.cxx b/sc/source/ui/view/viewfun2.cxx
index 16230b5a17a6..30f3d3fe083f 100644
--- a/sc/source/ui/view/viewfun2.cxx
+++ b/sc/source/ui/view/viewfun2.cxx
@@ -277,7 +277,7 @@ static ScAutoSum lcl_IsAutoSumData( ScDocument& rDoc, SCCOL 
nCol, SCROW nRow,
         if (aCell.getType() == CELLTYPE_FORMULA)
         {
             ScAutoSum val = ScAutoSumNone;
-            ScTokenArray* pCode = aCell.mpFormula->GetCode();
+            ScTokenArray* pCode = aCell.getFormula()->GetCode();
             if ( pCode )
             {
                 switch( pCode->GetOuterFuncOpCode() )

Reply via email to