sc/qa/unit/copy_paste_test.cxx                                    |    4 
 sc/source/ui/Accessibility/AccessibleText.cxx                     |    2 
 sc/source/ui/StatisticsDialogs/AnalysisOfVarianceDialog.cxx       |    4 
 sc/source/ui/StatisticsDialogs/ChiSquareTestDialog.cxx            |    4 
 sc/source/ui/StatisticsDialogs/DescriptiveStatisticsDialog.cxx    |    4 
 sc/source/ui/StatisticsDialogs/ExponentialSmoothingDialog.cxx     |    4 
 sc/source/ui/StatisticsDialogs/FTestDialog.cxx                    |    4 
 sc/source/ui/StatisticsDialogs/FourierAnalysisDialog.cxx          |    4 
 sc/source/ui/StatisticsDialogs/MatrixComparisonGenerator.cxx      |    4 
 sc/source/ui/StatisticsDialogs/MovingAverageDialog.cxx            |    4 
 sc/source/ui/StatisticsDialogs/RandomNumberGeneratorDialog.cxx    |    8 
 sc/source/ui/StatisticsDialogs/RegressionDialog.cxx               |    4 
 sc/source/ui/StatisticsDialogs/SamplingDialog.cxx                 |   12 
 sc/source/ui/StatisticsDialogs/StatisticsInputOutputDialog.cxx    |    8 
 sc/source/ui/StatisticsDialogs/StatisticsTwoVariableDialog.cxx    |    8 
 sc/source/ui/StatisticsDialogs/TTestDialog.cxx                    |    4 
 sc/source/ui/StatisticsDialogs/TableFillingAndNavigationTools.cxx |   18 
 sc/source/ui/StatisticsDialogs/ZTestDialog.cxx                    |    4 
 sc/source/ui/app/client.cxx                                       |    4 
 sc/source/ui/app/inputhdl.cxx                                     |   56 -
 sc/source/ui/app/inputwin.cxx                                     |    8 
 sc/source/ui/app/seltrans.cxx                                     |   18 
 sc/source/ui/app/transobj.cxx                                     |    3 
 sc/source/ui/condformat/condformatdlg.cxx                         |    4 
 sc/source/ui/condformat/condformateasydlg.cxx                     |    2 
 sc/source/ui/dbgui/PivotLayoutDialog.cxx                          |    2 
 sc/source/ui/dbgui/dbnamdlg.cxx                                   |    2 
 sc/source/ui/dbgui/filtdlg.cxx                                    |    2 
 sc/source/ui/dbgui/sfiltdlg.cxx                                   |    2 
 sc/source/ui/dialogs/SparklineDataRangeDialog.cxx                 |    2 
 sc/source/ui/dialogs/SparklineDialog.cxx                          |    2 
 sc/source/ui/docshell/docfunc.cxx                                 |    2 
 sc/source/ui/docshell/docsh.cxx                                   |    2 
 sc/source/ui/docshell/docsh3.cxx                                  |    2 
 sc/source/ui/docshell/docsh4.cxx                                  |    2 
 sc/source/ui/docshell/docsh6.cxx                                  |    2 
 sc/source/ui/docshell/externalrefmgr.cxx                          |    4 
 sc/source/ui/drawfunc/drawsh2.cxx                                 |    2 
 sc/source/ui/drawfunc/drawsh5.cxx                                 |   20 
 sc/source/ui/drawfunc/drtxtob.cxx                                 |    4 
 sc/source/ui/drawfunc/drtxtob1.cxx                                |    2 
 sc/source/ui/drawfunc/fudraw.cxx                                  |    2 
 sc/source/ui/drawfunc/fuins2.cxx                                  |   18 
 sc/source/ui/drawfunc/fusel.cxx                                   |    4 
 sc/source/ui/drawfunc/fusel2.cxx                                  |    4 
 sc/source/ui/drawfunc/futext3.cxx                                 |    8 
 sc/source/ui/formdlg/formula.cxx                                  |    2 
 sc/source/ui/inc/AnalysisOfVarianceDialog.hxx                     |    2 
 sc/source/ui/inc/ChiSquareTestDialog.hxx                          |    2 
 sc/source/ui/inc/DescriptiveStatisticsDialog.hxx                  |    2 
 sc/source/ui/inc/ExponentialSmoothingDialog.hxx                   |    2 
 sc/source/ui/inc/FTestDialog.hxx                                  |    2 
 sc/source/ui/inc/FourierAnalysisDialog.hxx                        |    2 
 sc/source/ui/inc/MatrixComparisonGenerator.hxx                    |    2 
 sc/source/ui/inc/MovingAverageDialog.hxx                          |    2 
 sc/source/ui/inc/RegressionDialog.hxx                             |    2 
 sc/source/ui/inc/StatisticsInputOutputDialog.hxx                  |    2 
 sc/source/ui/inc/StatisticsTwoVariableDialog.hxx                  |    2 
 sc/source/ui/inc/TTestDialog.hxx                                  |    2 
 sc/source/ui/inc/TableFillingAndNavigationTools.hxx               |    4 
 sc/source/ui/inc/ZTestDialog.hxx                                  |    2 
 sc/source/ui/inc/namedefdlg.hxx                                   |    2 
 sc/source/ui/inc/optsolver.hxx                                    |    4 
 sc/source/ui/inc/sharedocdlg.hxx                                  |    2 
 sc/source/ui/inc/viewdata.hxx                                     |    6 
 sc/source/ui/miscdlgs/acredlin.cxx                                |   38 -
 sc/source/ui/miscdlgs/crnrdlg.cxx                                 |    6 
 sc/source/ui/miscdlgs/datafdlg.cxx                                |   14 
 sc/source/ui/miscdlgs/highred.cxx                                 |    2 
 sc/source/ui/miscdlgs/instbdlg.cxx                                |    2 
 sc/source/ui/miscdlgs/optsolver.cxx                               |   24 
 sc/source/ui/miscdlgs/sharedocdlg.cxx                             |   17 
 sc/source/ui/namedlg/namedefdlg.cxx                               |    8 
 sc/source/ui/undo/undocell.cxx                                    |    2 
 sc/source/ui/unoobj/dispuno.cxx                                   |    2 
 sc/source/ui/unoobj/docuno.cxx                                    |    4 
 sc/source/ui/unoobj/viewuno.cxx                                   |   74 +-
 sc/source/ui/view/SparklineShell.cxx                              |    2 
 sc/source/ui/view/auditsh.cxx                                     |    2 
 sc/source/ui/view/cellsh.cxx                                      |   24 
 sc/source/ui/view/cellsh1.cxx                                     |   38 -
 sc/source/ui/view/cellsh2.cxx                                     |   24 
 sc/source/ui/view/cellsh3.cxx                                     |    4 
 sc/source/ui/view/dbfunc.cxx                                      |   64 +-
 sc/source/ui/view/dbfunc3.cxx                                     |   96 +--
 sc/source/ui/view/drawvie3.cxx                                    |    4 
 sc/source/ui/view/drawvie4.cxx                                    |   36 -
 sc/source/ui/view/drawview.cxx                                    |   23 
 sc/source/ui/view/editsh.cxx                                      |   12 
 sc/source/ui/view/formatsh.cxx                                    |    8 
 sc/source/ui/view/gridwin.cxx                                     |  140 ++--
 sc/source/ui/view/gridwin2.cxx                                    |   22 
 sc/source/ui/view/gridwin4.cxx                                    |   16 
 sc/source/ui/view/pgbrksh.cxx                                     |    2 
 sc/source/ui/view/pivotsh.cxx                                     |   10 
 sc/source/ui/view/printfun.cxx                                    |    3 
 sc/source/ui/view/select.cxx                                      |   10 
 sc/source/ui/view/spelldialog.cxx                                 |    2 
 sc/source/ui/view/spelleng.cxx                                    |    4 
 sc/source/ui/view/tabcont.cxx                                     |   12 
 sc/source/ui/view/tabview.cxx                                     |   15 
 sc/source/ui/view/tabview2.cxx                                    |   22 
 sc/source/ui/view/tabview3.cxx                                    |   19 
 sc/source/ui/view/tabview4.cxx                                    |    8 
 sc/source/ui/view/tabview5.cxx                                    |    8 
 sc/source/ui/view/tabvwsh3.cxx                                    |   28 
 sc/source/ui/view/tabvwsh4.cxx                                    |  112 +--
 sc/source/ui/view/tabvwsh5.cxx                                    |    6 
 sc/source/ui/view/tabvwsh9.cxx                                    |    2 
 sc/source/ui/view/tabvwsha.cxx                                    |   99 +--
 sc/source/ui/view/tabvwshb.cxx                                    |   36 -
 sc/source/ui/view/tabvwshd.cxx                                    |    4 
 sc/source/ui/view/tabvwshf.cxx                                    |   24 
 sc/source/ui/view/tabvwshh.cxx                                    |    2 
 sc/source/ui/view/viewdata.cxx                                    |   19 
 sc/source/ui/view/viewfun2.cxx                                    |  292 
+++++-----
 sc/source/ui/view/viewfun3.cxx                                    |  136 ++--
 sc/source/ui/view/viewfun4.cxx                                    |   52 -
 sc/source/ui/view/viewfun5.cxx                                    |    8 
 sc/source/ui/view/viewfun6.cxx                                    |   62 +-
 sc/source/ui/view/viewfun7.cxx                                    |    8 
 sc/source/ui/view/viewfunc.cxx                                    |  271 
++++-----
 122 files changed, 1170 insertions(+), 1149 deletions(-)

New commits:
commit ae69d423086a5e27795d8d9895607d9e9de3efba
Author:     Xisco Fauli <[email protected]>
AuthorDate: Thu Nov 27 17:17:30 2025 +0100
Commit:     Xisco Fauli <[email protected]>
CommitDate: Thu Nov 27 22:09:34 2025 +0100

    tdf#168850, tdf#167075, tdf#168850: Revert "ScViewData: pass ScDocShell by 
ref"
    
    This reverts commit d8ab8992bd35aedfc1d2b0debebab0d623aa8d09
    
    Unfortunately I had to revert the fix for tdf#167075
    in ea940b7985921883f8f75009186cae24846b1bd4
    "tdf#169554: Revert "tdf#167075: init doc shell before pasting as png/bmp 
(take 2)""
    because of tdf#169554, which I can't reproduce, so
    reverting the original commit that introduced tdf#167075
    It also fixes other similar issues reported in Bugzilla
    
    Change-Id: I88dfa08f2086b88cff168eff2df8b4faf4067439
    Signed-off-by: Xisco Fauli <[email protected]>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/194726
    Tested-by: Jenkins

diff --git a/sc/qa/unit/copy_paste_test.cxx b/sc/qa/unit/copy_paste_test.cxx
index 9ca6b4296fe7..ce12d0b88aa7 100644
--- a/sc/qa/unit/copy_paste_test.cxx
+++ b/sc/qa/unit/copy_paste_test.cxx
@@ -458,8 +458,8 @@ void 
ScCopyPasteTest::testTdf88782_autofillLinearNumbersInMergedCells()
     // merge the yellow cells
     ScCellMergeOption aMergeOptions(9, 11, 10, 13);     //J12:K14
     aMergeOptions.maTabs.insert(0);
-    ScDocShell& rDocSh = pViewShell->GetViewData().GetDocShell();
-    rDocSh.GetDocFunc().MergeCells(aMergeOptions, false, true, true, false);
+    ScDocShell* pDocSh = pViewShell->GetViewData().GetDocShell();
+    pDocSh->GetDocFunc().MergeCells(aMergeOptions, false, true, true, false);
 
     // fillauto numbers, these areas contain mostly merged cells
     pViewShell->FillAuto(FILL_TO_BOTTOM, 1, 8, 3, 14, 7);    // B9:D15 ->  
B9:D22
diff --git a/sc/source/ui/Accessibility/AccessibleText.cxx 
b/sc/source/ui/Accessibility/AccessibleText.cxx
index 4248bb4127af..221eea10f4fe 100644
--- a/sc/source/ui/Accessibility/AccessibleText.cxx
+++ b/sc/source/ui/Accessibility/AccessibleText.cxx
@@ -649,7 +649,7 @@ ScDocShell* 
ScAccessibleCellTextData::GetDocShell(ScTabViewShell* pViewShell)
 {
     ScDocShell* pDocSh = nullptr;
     if (pViewShell)
-        pDocSh = &pViewShell->GetViewData().GetDocShell();
+        pDocSh = pViewShell->GetViewData().GetDocShell();
     return pDocSh;
 }
 
diff --git a/sc/source/ui/StatisticsDialogs/AnalysisOfVarianceDialog.cxx 
b/sc/source/ui/StatisticsDialogs/AnalysisOfVarianceDialog.cxx
index ee8e93a054f0..acfab698b601 100644
--- a/sc/source/ui/StatisticsDialogs/AnalysisOfVarianceDialog.cxx
+++ b/sc/source/ui/StatisticsDialogs/AnalysisOfVarianceDialog.cxx
@@ -538,9 +538,9 @@ void 
ScAnalysisOfVarianceDialog::AnovaTwoFactor(AddressWalkerWriter& output, For
     }
 }
 
-ScRange ScAnalysisOfVarianceDialog::ApplyOutput(ScDocShell& rDocShell)
+ScRange ScAnalysisOfVarianceDialog::ApplyOutput(ScDocShell* pDocShell)
 {
-    AddressWalkerWriter output(mOutputAddress, rDocShell, mDocument,
+    AddressWalkerWriter output(mOutputAddress, pDocShell, mDocument,
         
formula::FormulaGrammar::mergeToGrammar(formula::FormulaGrammar::GRAM_ENGLISH, 
mAddressDetails.eConv));
     FormulaTemplate aTemplate(&mDocument);
 
diff --git a/sc/source/ui/StatisticsDialogs/ChiSquareTestDialog.cxx 
b/sc/source/ui/StatisticsDialogs/ChiSquareTestDialog.cxx
index 32505d6c2269..5c1ada025aa8 100644
--- a/sc/source/ui/StatisticsDialogs/ChiSquareTestDialog.cxx
+++ b/sc/source/ui/StatisticsDialogs/ChiSquareTestDialog.cxx
@@ -37,9 +37,9 @@ TranslateId ScChiSquareTestDialog::GetUndoNameId()
     return STR_CHI_SQUARE_TEST;
 }
 
-ScRange ScChiSquareTestDialog::ApplyOutput(ScDocShell& rDocShell)
+ScRange ScChiSquareTestDialog::ApplyOutput(ScDocShell* pDocShell)
 {
-    AddressWalkerWriter aOutput(mOutputAddress, rDocShell, mDocument,
+    AddressWalkerWriter aOutput(mOutputAddress, pDocShell, mDocument,
             formula::FormulaGrammar::mergeToGrammar( 
formula::FormulaGrammar::GRAM_ENGLISH, mAddressDetails.eConv));
     FormulaTemplate aTemplate(&mDocument);
 
diff --git a/sc/source/ui/StatisticsDialogs/DescriptiveStatisticsDialog.cxx 
b/sc/source/ui/StatisticsDialogs/DescriptiveStatisticsDialog.cxx
index c1e298ef53f7..d82d7fa0e957 100644
--- a/sc/source/ui/StatisticsDialogs/DescriptiveStatisticsDialog.cxx
+++ b/sc/source/ui/StatisticsDialogs/DescriptiveStatisticsDialog.cxx
@@ -68,9 +68,9 @@ TranslateId ScDescriptiveStatisticsDialog::GetUndoNameId()
     return STR_DESCRIPTIVE_STATISTICS_UNDO_NAME;
 }
 
-ScRange ScDescriptiveStatisticsDialog::ApplyOutput(ScDocShell& rDocShell)
+ScRange ScDescriptiveStatisticsDialog::ApplyOutput(ScDocShell* pDocShell)
 {
-    AddressWalkerWriter aOutput(mOutputAddress, rDocShell, mDocument,
+    AddressWalkerWriter aOutput(mOutputAddress, pDocShell, mDocument,
             formula::FormulaGrammar::mergeToGrammar( 
formula::FormulaGrammar::GRAM_ENGLISH, mAddressDetails.eConv));
     FormulaTemplate aTemplate(&mDocument);
 
diff --git a/sc/source/ui/StatisticsDialogs/ExponentialSmoothingDialog.cxx 
b/sc/source/ui/StatisticsDialogs/ExponentialSmoothingDialog.cxx
index b610ab580cdd..d7fe7c872167 100644
--- a/sc/source/ui/StatisticsDialogs/ExponentialSmoothingDialog.cxx
+++ b/sc/source/ui/StatisticsDialogs/ExponentialSmoothingDialog.cxx
@@ -41,9 +41,9 @@ TranslateId ScExponentialSmoothingDialog::GetUndoNameId()
     return STR_EXPONENTIAL_SMOOTHING_UNDO_NAME;
 }
 
-ScRange ScExponentialSmoothingDialog::ApplyOutput(ScDocShell& rDocShell)
+ScRange ScExponentialSmoothingDialog::ApplyOutput(ScDocShell* pDocShell)
 {
-    AddressWalkerWriter output(mOutputAddress, rDocShell, mDocument,
+    AddressWalkerWriter output(mOutputAddress, pDocShell, mDocument,
             formula::FormulaGrammar::mergeToGrammar( 
formula::FormulaGrammar::GRAM_ENGLISH, mAddressDetails.eConv));
     FormulaTemplate aTemplate(&mDocument);
 
diff --git a/sc/source/ui/StatisticsDialogs/FTestDialog.cxx 
b/sc/source/ui/StatisticsDialogs/FTestDialog.cxx
index cc6382400c06..b52e72b6e8db 100644
--- a/sc/source/ui/StatisticsDialogs/FTestDialog.cxx
+++ b/sc/source/ui/StatisticsDialogs/FTestDialog.cxx
@@ -39,9 +39,9 @@ TranslateId ScFTestDialog::GetUndoNameId()
     return STR_FTEST_UNDO_NAME;
 }
 
-ScRange ScFTestDialog::ApplyOutput(ScDocShell& rDocShell)
+ScRange ScFTestDialog::ApplyOutput(ScDocShell* pDocShell)
 {
-    AddressWalkerWriter aOutput(mOutputAddress, rDocShell, mDocument,
+    AddressWalkerWriter aOutput(mOutputAddress, pDocShell, mDocument,
             
formula::FormulaGrammar::mergeToGrammar(formula::FormulaGrammar::GRAM_ENGLISH, 
mAddressDetails.eConv));
     FormulaTemplate aTemplate(&mDocument);
 
diff --git a/sc/source/ui/StatisticsDialogs/FourierAnalysisDialog.cxx 
b/sc/source/ui/StatisticsDialogs/FourierAnalysisDialog.cxx
index 5092d0426b90..94564358b9f0 100644
--- a/sc/source/ui/StatisticsDialogs/FourierAnalysisDialog.cxx
+++ b/sc/source/ui/StatisticsDialogs/FourierAnalysisDialog.cxx
@@ -51,10 +51,10 @@ void ScFourierAnalysisDialog::Close()
 
 TranslateId ScFourierAnalysisDialog::GetUndoNameId() { return 
STR_FOURIER_ANALYSIS_UNDO_NAME; }
 
-ScRange ScFourierAnalysisDialog::ApplyOutput(ScDocShell& rDocShell)
+ScRange ScFourierAnalysisDialog::ApplyOutput(ScDocShell* pDocShell)
 {
     getOptions();
-    AddressWalkerWriter aOutput(mOutputAddress, rDocShell, mDocument,
+    AddressWalkerWriter aOutput(mOutputAddress, pDocShell, mDocument,
                                 formula::FormulaGrammar::mergeToGrammar(
                                     formula::FormulaGrammar::GRAM_ENGLISH, 
mAddressDetails.eConv));
     FormulaTemplate aTemplate(&mDocument);
diff --git a/sc/source/ui/StatisticsDialogs/MatrixComparisonGenerator.cxx 
b/sc/source/ui/StatisticsDialogs/MatrixComparisonGenerator.cxx
index a90c95369e7e..f2059ff822a8 100644
--- a/sc/source/ui/StatisticsDialogs/MatrixComparisonGenerator.cxx
+++ b/sc/source/ui/StatisticsDialogs/MatrixComparisonGenerator.cxx
@@ -55,9 +55,9 @@ TranslateId ScMatrixComparisonGenerator::GetUndoNameId()
     return STR_CORRELATION_UNDO_NAME;
 }
 
-ScRange ScMatrixComparisonGenerator::ApplyOutput(ScDocShell& rDocShell)
+ScRange ScMatrixComparisonGenerator::ApplyOutput(ScDocShell* pDocShell)
 {
-    AddressWalkerWriter output(mOutputAddress, rDocShell, mDocument,
+    AddressWalkerWriter output(mOutputAddress, pDocShell, mDocument,
             formula::FormulaGrammar::mergeToGrammar( 
formula::FormulaGrammar::GRAM_ENGLISH, mAddressDetails.eConv));
     FormulaTemplate aTemplate(&mDocument);
 
diff --git a/sc/source/ui/StatisticsDialogs/MovingAverageDialog.cxx 
b/sc/source/ui/StatisticsDialogs/MovingAverageDialog.cxx
index 246103a7ad62..4cbe9343e200 100644
--- a/sc/source/ui/StatisticsDialogs/MovingAverageDialog.cxx
+++ b/sc/source/ui/StatisticsDialogs/MovingAverageDialog.cxx
@@ -42,9 +42,9 @@ TranslateId ScMovingAverageDialog::GetUndoNameId()
     return STR_MOVING_AVERAGE_UNDO_NAME;
 }
 
-ScRange ScMovingAverageDialog::ApplyOutput(ScDocShell& rDocShell)
+ScRange ScMovingAverageDialog::ApplyOutput(ScDocShell* pDocShell)
 {
-    AddressWalkerWriter output(mOutputAddress, rDocShell, mDocument,
+    AddressWalkerWriter output(mOutputAddress, pDocShell, mDocument,
             formula::FormulaGrammar::mergeToGrammar( 
formula::FormulaGrammar::GRAM_ENGLISH, mAddressDetails.eConv));
     FormulaTemplate aTemplate(&mDocument);
 
diff --git a/sc/source/ui/StatisticsDialogs/RandomNumberGeneratorDialog.cxx 
b/sc/source/ui/StatisticsDialogs/RandomNumberGeneratorDialog.cxx
index 6d953affb021..8ab3a384a098 100644
--- a/sc/source/ui/StatisticsDialogs/RandomNumberGeneratorDialog.cxx
+++ b/sc/source/ui/StatisticsDialogs/RandomNumberGeneratorDialog.cxx
@@ -254,8 +254,8 @@ void ScRandomNumberGeneratorDialog::GenerateNumbers(DIST& 
distribution, std::mt1
     OUString aDistributionName = ScResId(pDistributionStringId);
     aUndo = aUndo.replaceAll("%1",  aDistributionName);
 
-    ScDocShell& rDocShell = mrViewData.GetDocShell();
-    SfxUndoManager* pUndoManager = rDocShell.GetUndoManager();
+    ScDocShell* pDocShell = mrViewData.GetDocShell();
+    SfxUndoManager* pUndoManager = pDocShell->GetUndoManager();
     pUndoManager->EnterListAction( aUndo, aUndo, 0, 
mrViewData.GetViewShell()->GetViewShellId() );
 
     SCROW nRowStart = maInputRange.aStart.Row();
@@ -284,13 +284,13 @@ void ScRandomNumberGeneratorDialog::GenerateNumbers(DIST& 
distribution, std::mt1
                     aVals.push_back(distribution(seed));
             }
 
-            rDocShell.GetDocFunc().SetValueCells(aPos, aVals, true);
+            pDocShell->GetDocFunc().SetValueCells(aPos, aVals, true);
         }
     }
 
     pUndoManager->LeaveListAction();
 
-    rDocShell.PostPaint( maInputRange, PaintPartFlags::Grid );
+    pDocShell->PostPaint( maInputRange, PaintPartFlags::Grid );
 }
 
 IMPL_LINK_NOARG( ScRandomNumberGeneratorDialog, OkClicked, weld::Button&, void 
)
diff --git a/sc/source/ui/StatisticsDialogs/RegressionDialog.cxx 
b/sc/source/ui/StatisticsDialogs/RegressionDialog.cxx
index 03d0fbdbc3a4..402a7ca0d183 100644
--- a/sc/source/ui/StatisticsDialogs/RegressionDialog.cxx
+++ b/sc/source/ui/StatisticsDialogs/RegressionDialog.cxx
@@ -171,9 +171,9 @@ TranslateId ScRegressionDialog::GetUndoNameId()
     return STR_REGRESSION_UNDO_NAME;
 }
 
-ScRange ScRegressionDialog::ApplyOutput(ScDocShell& rDocShell)
+ScRange ScRegressionDialog::ApplyOutput(ScDocShell* pDocShell)
 {
-    AddressWalkerWriter aOutput(mOutputAddress, rDocShell, mDocument,
+    AddressWalkerWriter aOutput(mOutputAddress, pDocShell, mDocument,
             formula::FormulaGrammar::mergeToGrammar( 
formula::FormulaGrammar::GRAM_ENGLISH, mAddressDetails.eConv));
     FormulaTemplate aTemplate(&mDocument);
     aTemplate.autoReplaceUses3D(mbUse3DAddresses);
diff --git a/sc/source/ui/StatisticsDialogs/SamplingDialog.cxx 
b/sc/source/ui/StatisticsDialogs/SamplingDialog.cxx
index 97d83283463b..932ae743ca65 100644
--- a/sc/source/ui/StatisticsDialogs/SamplingDialog.cxx
+++ b/sc/source/ui/StatisticsDialogs/SamplingDialog.cxx
@@ -333,8 +333,8 @@ ScRange 
ScSamplingDialog::PerformRandomSamplingKeepOrder(ScDocShell& rDocShell)
 void ScSamplingDialog::PerformSampling()
 {
     OUString aUndo(ScResId(STR_SAMPLING_UNDO_NAME));
-    ScDocShell& rDocShell = mViewData.GetDocShell();
-    SfxUndoManager* pUndoManager = rDocShell.GetUndoManager();
+    ScDocShell* pDocShell = mViewData.GetDocShell();
+    SfxUndoManager* pUndoManager = pDocShell->GetUndoManager();
 
     ScRange aModifiedRange;
 
@@ -343,17 +343,17 @@ void ScSamplingDialog::PerformSampling()
     if (mxRandomMethodRadio->get_active())
     {
         if (mxKeepOrder->get_sensitive() && mxKeepOrder->get_active())
-            aModifiedRange = PerformRandomSamplingKeepOrder(rDocShell);
+            aModifiedRange = PerformRandomSamplingKeepOrder(*pDocShell);
         else
-            aModifiedRange = PerformRandomSampling(rDocShell);
+            aModifiedRange = PerformRandomSampling(*pDocShell);
     }
     else if (mxPeriodicMethodRadio->get_active())
     {
-        aModifiedRange = PerformPeriodicSampling(rDocShell);
+        aModifiedRange = PerformPeriodicSampling(*pDocShell);
     }
 
     pUndoManager->LeaveListAction();
-    rDocShell.PostPaint(aModifiedRange, PaintPartFlags::Grid);
+    pDocShell->PostPaint(aModifiedRange, PaintPartFlags::Grid);
 }
 
 sal_Int64 ScSamplingDialog::GetPopulationSize() const
diff --git a/sc/source/ui/StatisticsDialogs/StatisticsInputOutputDialog.cxx 
b/sc/source/ui/StatisticsDialogs/StatisticsInputOutputDialog.cxx
index 7e866b3be2cc..3af68a8b3e40 100644
--- a/sc/source/ui/StatisticsDialogs/StatisticsInputOutputDialog.cxx
+++ b/sc/source/ui/StatisticsDialogs/StatisticsInputOutputDialog.cxx
@@ -281,14 +281,14 @@ IMPL_LINK_NOARG( ScStatisticsInputOutputDialog, 
RefInputModifyHandler, formula::
 void ScStatisticsInputOutputDialog::CalculateInputAndWriteToOutput()
 {
     OUString aUndo(ScResId(GetUndoNameId()));
-    ScDocShell& rDocShell = mViewData.GetDocShell();
-    SfxUndoManager* pUndoManager = rDocShell.GetUndoManager();
+    ScDocShell* pDocShell = mViewData.GetDocShell();
+    SfxUndoManager* pUndoManager = pDocShell->GetUndoManager();
     pUndoManager->EnterListAction( aUndo, aUndo, 0, 
mViewData.GetViewShell()->GetViewShellId() );
 
-    ScRange aOutputRange = ApplyOutput(rDocShell);
+    ScRange aOutputRange = ApplyOutput(pDocShell);
 
     pUndoManager->LeaveListAction();
-    rDocShell.PostPaint( aOutputRange, PaintPartFlags::Grid );
+    pDocShell->PostPaint( aOutputRange, PaintPartFlags::Grid );
 }
 
 bool ScStatisticsInputOutputDialog::InputRangesValid()
diff --git a/sc/source/ui/StatisticsDialogs/StatisticsTwoVariableDialog.cxx 
b/sc/source/ui/StatisticsDialogs/StatisticsTwoVariableDialog.cxx
index 950506022429..f9d9899d9162 100644
--- a/sc/source/ui/StatisticsDialogs/StatisticsTwoVariableDialog.cxx
+++ b/sc/source/ui/StatisticsDialogs/StatisticsTwoVariableDialog.cxx
@@ -323,14 +323,14 @@ IMPL_LINK_NOARG( ScStatisticsTwoVariableDialog, 
RefInputModifyHandler, formula::
 void ScStatisticsTwoVariableDialog::CalculateInputAndWriteToOutput()
 {
     OUString aUndo(ScResId(GetUndoNameId()));
-    ScDocShell& rDocShell = mViewData.GetDocShell();
-    SfxUndoManager* pUndoManager = rDocShell.GetUndoManager();
+    ScDocShell* pDocShell = mViewData.GetDocShell();
+    SfxUndoManager* pUndoManager = pDocShell->GetUndoManager();
     pUndoManager->EnterListAction( aUndo, aUndo, 0, 
mViewData.GetViewShell()->GetViewShellId() );
 
-    ScRange aOutputRange = ApplyOutput(rDocShell);
+    ScRange aOutputRange = ApplyOutput(pDocShell);
 
     pUndoManager->LeaveListAction();
-    rDocShell.PostPaint( aOutputRange, PaintPartFlags::Grid );
+    pDocShell->PostPaint( aOutputRange, PaintPartFlags::Grid );
 }
 
 bool ScStatisticsTwoVariableDialog::InputRangesValid()
diff --git a/sc/source/ui/StatisticsDialogs/TTestDialog.cxx 
b/sc/source/ui/StatisticsDialogs/TTestDialog.cxx
index c3207eb0043c..96c173aab7d2 100644
--- a/sc/source/ui/StatisticsDialogs/TTestDialog.cxx
+++ b/sc/source/ui/StatisticsDialogs/TTestDialog.cxx
@@ -39,9 +39,9 @@ TranslateId ScTTestDialog::GetUndoNameId()
     return STR_TTEST_UNDO_NAME;
 }
 
-ScRange ScTTestDialog::ApplyOutput(ScDocShell& rDocShell)
+ScRange ScTTestDialog::ApplyOutput(ScDocShell* pDocShell)
 {
-    AddressWalkerWriter aOutput(mOutputAddress, rDocShell, mDocument,
+    AddressWalkerWriter aOutput(mOutputAddress, pDocShell, mDocument,
             formula::FormulaGrammar::mergeToGrammar( 
formula::FormulaGrammar::GRAM_ENGLISH, mAddressDetails.eConv));
     FormulaTemplate aTemplate(&mDocument);
 
diff --git a/sc/source/ui/StatisticsDialogs/TableFillingAndNavigationTools.cxx 
b/sc/source/ui/StatisticsDialogs/TableFillingAndNavigationTools.cxx
index 32a06e183d4c..4ed3cb2e0ecd 100644
--- a/sc/source/ui/StatisticsDialogs/TableFillingAndNavigationTools.cxx
+++ b/sc/source/ui/StatisticsDialogs/TableFillingAndNavigationTools.cxx
@@ -154,17 +154,17 @@ void AddressWalker::push(SCCOL aRelativeCol, SCROW 
aRelativeRow, SCTAB aRelative
     mAddressStack.push_back(mCurrentAddress);
 }
 
-AddressWalkerWriter::AddressWalkerWriter(const ScAddress& aInitialAddress, 
ScDocShell& rDocShell, ScDocument& rDocument,
+AddressWalkerWriter::AddressWalkerWriter(const ScAddress& aInitialAddress, 
ScDocShell* pDocShell, ScDocument& rDocument,
         formula::FormulaGrammar::Grammar eGrammar ) :
     AddressWalker(aInitialAddress),
-    mrDocShell(rDocShell),
+    mpDocShell(pDocShell),
     mrDocument(rDocument),
     meGrammar(eGrammar)
 {}
 
 void AddressWalkerWriter::writeFormula(const OUString& aFormula)
 {
-    mrDocShell.GetDocFunc().SetFormulaCell(mCurrentAddress,
+    mpDocShell->GetDocFunc().SetFormulaCell(mCurrentAddress,
             new ScFormulaCell(mrDocument, mCurrentAddress, aFormula, 
meGrammar), true);
 }
 
@@ -174,7 +174,7 @@ void AddressWalkerWriter::writeFormulas(const 
std::vector<OUString>& rFormulas)
     if (!nLength)
         return;
 
-    const size_t nMaxLen = mrDocShell.GetDocument().MaxRow() - 
mCurrentAddress.Row() + 1;
+    const size_t nMaxLen = mpDocShell->GetDocument().MaxRow() - 
mCurrentAddress.Row() + 1;
     // If not done already, trim the length to fit.
     if (nLength > nMaxLen)
         nLength = nMaxLen;
@@ -187,7 +187,7 @@ void AddressWalkerWriter::writeFormulas(const 
std::vector<OUString>& rFormulas)
         aAddr.IncRow(1);
     }
 
-    mrDocShell.GetDocFunc().SetFormulaCells(mCurrentAddress, aFormulaCells, 
true);
+    mpDocShell->GetDocFunc().SetFormulaCells(mCurrentAddress, aFormulaCells, 
true);
 }
 
 void AddressWalkerWriter::writeMatrixFormula(const OUString& aFormula, SCCOL 
nCols, SCROW nRows)
@@ -199,12 +199,12 @@ void AddressWalkerWriter::writeMatrixFormula(const 
OUString& aFormula, SCCOL nCo
         aRange.aEnd.IncCol(nCols - 1);
     if (nRows > 1)
         aRange.aEnd.IncRow(nRows - 1);
-    mrDocShell.GetDocFunc().EnterMatrix(aRange, nullptr, nullptr, aFormula, 
false, false, OUString(), meGrammar );
+    mpDocShell->GetDocFunc().EnterMatrix(aRange, nullptr, nullptr, aFormula, 
false, false, OUString(), meGrammar );
 }
 
 void AddressWalkerWriter::writeString(const OUString& aString)
 {
-    mrDocShell.GetDocFunc().SetStringCell(mCurrentAddress, aString, true);
+    mpDocShell->GetDocFunc().SetStringCell(mCurrentAddress, aString, true);
 }
 
 void AddressWalkerWriter::writeString(const char* aCharArray)
@@ -223,12 +223,12 @@ void AddressWalkerWriter::writeBoldString(const OUString& 
aString)
     aItemSet.Put(aJustify);
     rEngine.QuickSetAttribs(aItemSet, ESelection(0, 0, 0, aString.getLength()) 
);
     std::unique_ptr<EditTextObject> pEditText(rEngine.CreateTextObject());
-    mrDocShell.GetDocFunc().SetEditCell(mCurrentAddress, *pEditText, true);
+    mpDocShell->GetDocFunc().SetEditCell(mCurrentAddress, *pEditText, true);
 }
 
 void AddressWalkerWriter::writeValue(double aValue)
 {
-    mrDocShell.GetDocFunc().SetValueCell(mCurrentAddress, aValue, true);
+    mpDocShell->GetDocFunc().SetValueCell(mCurrentAddress, aValue, true);
 }
 
 // Applies a column header format to the current cell and subsequent (nCols - 
1) columns
diff --git a/sc/source/ui/StatisticsDialogs/ZTestDialog.cxx 
b/sc/source/ui/StatisticsDialogs/ZTestDialog.cxx
index a849453073c4..3877e5d5e604 100644
--- a/sc/source/ui/StatisticsDialogs/ZTestDialog.cxx
+++ b/sc/source/ui/StatisticsDialogs/ZTestDialog.cxx
@@ -39,9 +39,9 @@ TranslateId ScZTestDialog::GetUndoNameId()
     return STR_ZTEST_UNDO_NAME;
 }
 
-ScRange ScZTestDialog::ApplyOutput(ScDocShell& rDocShell)
+ScRange ScZTestDialog::ApplyOutput(ScDocShell* pDocShell)
 {
-    AddressWalkerWriter aOutput(mOutputAddress, rDocShell, mDocument,
+    AddressWalkerWriter aOutput(mOutputAddress, pDocShell, mDocument,
             formula::FormulaGrammar::mergeToGrammar( 
formula::FormulaGrammar::GRAM_ENGLISH, mAddressDetails.eConv));
     FormulaTemplate aTemplate(&mDocument);
 
diff --git a/sc/source/ui/app/client.cxx b/sc/source/ui/app/client.cxx
index c5f6400e39d7..cbb00c3c9ddd 100644
--- a/sc/source/ui/app/client.cxx
+++ b/sc/source/ui/app/client.cxx
@@ -168,7 +168,7 @@ void ScClient::ObjectAreaChanged()
     pDrawObj->setSuppressSetVisAreaSize(false);
 
     //  set document modified (SdrModel::SetChanged is not used)
-    pViewSh->GetViewData().GetDocShell().SetDrawModified();
+    pViewSh->GetViewData().GetDocShell()->SetDrawModified();
     pViewSh->ScrollToObject(pDrawObj);
 }
 
@@ -232,7 +232,7 @@ void ScClient::ViewChanged()
             pDrawObj->SetLogicRect( aLogicRect );
 
             // set document modified (SdrModel::SetChanged is not used)
-            pViewSh->GetViewData().GetDocShell().SetDrawModified();
+            pViewSh->GetViewData().GetDocShell()->SetDrawModified();
         }
     }
 }
diff --git a/sc/source/ui/app/inputhdl.cxx b/sc/source/ui/app/inputhdl.cxx
index 3c9ad6d65f13..7b8a6ed5c94c 100644
--- a/sc/source/ui/app/inputhdl.cxx
+++ b/sc/source/ui/app/inputhdl.cxx
@@ -359,8 +359,8 @@ void ScInputHandler::InitRangeFinder( const OUString& 
rFormula )
     DeleteRangeFinder();
     if (!pActiveViewSh || !ScModule::get()->GetInputOptions().GetRangeFinder())
         return;
-    ScDocShell& rDocSh = pActiveViewSh->GetViewData().GetDocShell();
-    ScDocument& rDoc = rDocSh.GetDocument();
+    ScDocShell* pDocSh = pActiveViewSh->GetViewData().GetDocShell();
+    ScDocument& rDoc = pDocSh->GetDocument();
     const sal_Unicode cSheetSep = rDoc.GetSheetSeparator();
 
     OUString aDelimiters = ScEditUtil::ModifyDelimiters(u" !~%\"       
"_ustr);
@@ -457,7 +457,7 @@ handle_r1c1:
                 if (!nCount)
                 {
                     mpEditEngine->SetUpdateLayout( false );
-                    pRangeFindList.reset(new ScRangeFindList( 
rDocSh.GetTitle() ));
+                    pRangeFindList.reset(new ScRangeFindList( 
pDocSh->GetTitle() ));
                 }
 
                 Color nColor = pRangeFindList->Insert( ScRangeFindData( 
aRange, nFlags, aSel));
@@ -478,7 +478,7 @@ handle_r1c1:
     {
         mpEditEngine->SetUpdateLayout( true );
 
-        rDocSh.Broadcast( SfxHint( SfxHintId::ScShowRangeFinder ) );
+        pDocSh->Broadcast( SfxHint( SfxHintId::ScShowRangeFinder ) );
     }
 }
 
@@ -549,7 +549,7 @@ void ScInputHandler::UpdateLokReferenceMarks()
         return;
 
     ScViewData& rViewData = pShell->GetViewData();
-    ScDocShell& rDocSh = rViewData.GetDocShell();
+    ScDocShell* pDocSh = rViewData.GetDocShell();
     ScRangeFindList* pRangeFinder = GetRangeFindList();
 
     if ( !pRangeFinder && !rViewData.IsRefMode() )
@@ -576,7 +576,7 @@ void ScInputHandler::UpdateLokReferenceMarks()
         PutInOrder(nX1, nX2);
         PutInOrder(nY1, nY2);
 
-        aReferenceMarks[0] = ScInputHandler::GetReferenceMark( rViewData, 
rDocSh,
+        aReferenceMarks[0] = ScInputHandler::GetReferenceMark( rViewData, 
*pDocSh,
                                                    nX1, nX2, nY1, nY2,
                                                    nTab, aRefColor );
     }
@@ -586,7 +586,7 @@ void ScInputHandler::UpdateLokReferenceMarks()
     aReferenceMarks.resize( nCount );
 
     if ( nCount && pRangeFinder && !pRangeFinder->IsHidden() &&
-         pRangeFinder->GetDocName() == rDocSh.GetTitle() )
+         pRangeFinder->GetDocName() == pDocSh->GetTitle() )
     {
         for (sal_uInt16 i = 0; i < nCount - nAdditionalMarks; i++)
         {
@@ -600,7 +600,7 @@ void ScInputHandler::UpdateLokReferenceMarks()
             tools::Long nY2 = aRef.aEnd.Row();
             tools::Long nTab = aRef.aStart.Tab();
 
-            aReferenceMarks[i + nAdditionalMarks] = 
ScInputHandler::GetReferenceMark( rViewData, rDocSh,
+            aReferenceMarks[i + nAdditionalMarks] = 
ScInputHandler::GetReferenceMark( rViewData, *pDocSh,
                                                                           nX1, 
nX2, nY1, nY2,
                                                                           
nTab, rData.nColor );
 
@@ -705,9 +705,9 @@ void ScInputHandler::DeleteRangeFinder()
     ScTabViewShell* pPaintView = pRefViewSh ? pRefViewSh : pActiveViewSh;
     if ( pRangeFindList && pPaintView )
     {
-        ScDocShell& rDocSh = pActiveViewSh->GetViewData().GetDocShell();
+        ScDocShell* pDocSh = pActiveViewSh->GetViewData().GetDocShell();
         pRangeFindList->SetHidden(true);
-        rDocSh.Broadcast( SfxHint( SfxHintId::ScShowRangeFinder ) );  // Steal
+        pDocSh->Broadcast( SfxHint( SfxHintId::ScShowRangeFinder ) );  // Steal
         pRangeFindList.reset();
     }
 }
@@ -924,7 +924,7 @@ void ScInputHandler::ImplCreateEditEngine()
 
     // we cannot create a properly initialised EditEngine until we have a 
document
     assert( pActiveViewSh );
-    ScDocument& rDoc = 
pActiveViewSh->GetViewData().GetDocShell().GetDocument();
+    ScDocument& rDoc = 
pActiveViewSh->GetViewData().GetDocShell()->GetDocument();
     mpEditEngine = std::make_unique<ScFieldEditEngine>(&rDoc, 
rDoc.GetEditEnginePool());
     mpEditEngine->SetWordDelimiters( ScEditUtil::ModifyDelimiters( 
mpEditEngine->GetWordDelimiters() ) );
     UpdateRefDevice();      // also sets MapMode
@@ -1013,7 +1013,7 @@ void ScInputHandler::GetFormulaData()
     if ( !pActiveViewSh )
         return;
 
-    ScDocument& rDoc = 
pActiveViewSh->GetViewData().GetDocShell().GetDocument();
+    ScDocument& rDoc = 
pActiveViewSh->GetViewData().GetDocShell()->GetDocument();
 
     if ( pFormulaData )
         pFormulaData->clear();
@@ -1129,9 +1129,9 @@ void ScInputHandler::ShowArgumentsTip( OUString& rSelText 
)
     if ( !pActiveViewSh )
         return;
 
-    ScDocShell& rDocSh = pActiveViewSh->GetViewData().GetDocShell();
+    ScDocShell* pDocSh = pActiveViewSh->GetViewData().GetDocShell();
     const sal_Unicode cSep = ScCompiler::GetNativeSymbolChar(ocSep);
-    const sal_Unicode cSheetSep = rDocSh.GetDocument().GetSheetSeparator();
+    const sal_Unicode cSheetSep = pDocSh->GetDocument().GetSheetSeparator();
     FormulaHelper aHelper(ScGlobal::GetStarCalcFunctionMgr());
     bool bFound = false;
     while( !bFound )
@@ -1860,7 +1860,7 @@ void ScTabViewShell::LOKSendFormulabarUpdate(const 
EditView* pActiveView,
     maSendFormulabarUpdate.m_nTimeStamp = now;
 
     ScViewData& rViewData = this->GetViewData();
-    const ScDocument& rDoc = rViewData.GetDocShell().GetDocument();
+    const ScDocument& rDoc = rViewData.GetDocShell()->GetDocument();
     const ScPatternAttr* pPattern = rDoc.GetPattern(rViewData.GetCurX(), 
rViewData.GetCurY(), rViewData.GetRefTabNo());
 
     if (pPattern)
@@ -1956,7 +1956,7 @@ void ScInputHandler::FormulaPreview()
         OUString aPart = pActiveView->GetSelected();
         if (aPart.isEmpty())
             aPart = mpEditEngine->GetText(0);
-        ScDocument& rDoc = 
pActiveViewSh->GetViewData().GetDocShell().GetDocument();
+        ScDocument& rDoc = 
pActiveViewSh->GetViewData().GetDocShell()->GetDocument();
         aValue = lcl_Calculate( aPart, rDoc, aCursorPos );
     }
 
@@ -2088,7 +2088,7 @@ void ScInputHandler::GetColData()
     if ( !pActiveViewSh )
         return;
 
-    ScDocument& rDoc = 
pActiveViewSh->GetViewData().GetDocShell().GetDocument();
+    ScDocument& rDoc = 
pActiveViewSh->GetViewData().GetDocShell()->GetDocument();
 
     if ( pColumnData )
         pColumnData->clear();
@@ -2431,7 +2431,7 @@ void ScInputHandler::UpdateAdjust( sal_Unicode cTyped )
                     bNumber = (cTyped>='0' && cTyped<='9');     // Only 
ciphers are numbers
                 else if ( pActiveViewSh )
                 {
-                    ScDocument& rDoc = 
pActiveViewSh->GetViewData().GetDocShell().GetDocument();
+                    ScDocument& rDoc = 
pActiveViewSh->GetViewData().GetDocShell()->GetDocument();
                     bNumber = ( rDoc.GetCellType( aCursorPos ) == 
CELLTYPE_VALUE );
                 }
                 eSvxAdjust = bNumber ? SvxAdjust::Right : SvxAdjust::Left;
@@ -2511,7 +2511,7 @@ bool ScInputHandler::StartTable( sal_Unicode cTyped, bool 
bFromCommand, bool bIn
 
     if (pActiveViewSh)
     {
-        ScDocument& rDoc = 
pActiveViewSh->GetViewData().GetDocShell().GetDocument();
+        ScDocument& rDoc = 
pActiveViewSh->GetViewData().GetDocShell()->GetDocument();
 
         if (!rDoc.ValidCol(aCursorPos.Col()))
             return false;
@@ -2539,7 +2539,7 @@ bool ScInputHandler::StartTable( sal_Unicode cTyped, bool 
bFromCommand, bool bIn
             // activation is requested (double-click or F2) or a click in input
             // line.
             bool bShowError = (!bInputActivated || !aTester.GetMessageId() || 
aTester.GetMessageId() != STR_PROTECTIONERR) &&
-                !pActiveViewSh->GetViewData().GetDocShell().IsReadOnly();
+                !pActiveViewSh->GetViewData().GetDocShell()->IsReadOnly();
             if (bShowError)
             {
                 eMode = SC_INPUT_NONE;
@@ -3052,7 +3052,7 @@ void ScInputHandler::SetMode( ScInputMode eNewMode, const 
OUString* pInitText, S
         {
             if (StartTable(0, false, eMode == SC_INPUT_TABLE, pTopEngine))
             {
-                
pActiveViewSh->GetViewData().GetDocShell().PostEditView(*mpEditEngine, 
aCursorPos);
+                
pActiveViewSh->GetViewData().GetDocShell()->PostEditView(*mpEditEngine, 
aCursorPos);
             }
         }
 
@@ -3977,7 +3977,7 @@ bool ScInputHandler::KeyInput( const KeyEvent& rKEvt, 
bool bStartEdit /* = false
             if (bNewView )                          // Create anew
             {
                 if (pActiveViewSh)
-                    
pActiveViewSh->GetViewData().GetDocShell().PostEditView(*mpEditEngine, 
aCursorPos);
+                    
pActiveViewSh->GetViewData().GetDocShell()->PostEditView(*mpEditEngine, 
aCursorPos);
                 UpdateActiveView();
                 if (eMode==SC_INPUT_NONE)
                     if (pTableView || pTopView)
@@ -4100,8 +4100,8 @@ bool ScInputHandler::KeyInput( const KeyEvent& rKEvt, 
bool bStartEdit /* = false
             // right away at the start of the edit, so that the content is
             // saved even when the user leaves the document before hitting
             // Enter
-            if (comphelper::LibreOfficeKit::isActive() && bSetModified && 
pActiveViewSh && !pActiveViewSh->GetViewData().GetDocShell().IsModified())
-                pActiveViewSh->GetViewData().GetDocShell().SetModified();
+            if (comphelper::LibreOfficeKit::isActive() && bSetModified && 
pActiveViewSh && !pActiveViewSh->GetViewData().GetDocShell()->IsModified())
+                pActiveViewSh->GetViewData().GetDocShell()->SetModified();
 
             InvalidateAttribs();        //! in DataChanged?
         }
@@ -4211,7 +4211,7 @@ void ScInputHandler::InputCommand( const CommandEvent& 
rCEvt )
         {
             if (bNewView)                           // create new edit view
             {
-                
pActiveViewSh->GetViewData().GetDocShell().PostEditView(*mpEditEngine, 
aCursorPos);
+                
pActiveViewSh->GetViewData().GetDocShell()->PostEditView(*mpEditEngine, 
aCursorPos);
                 UpdateActiveView();
                 if (eMode==SC_INPUT_NONE)
                     if (pTableView || pTopView)
@@ -4335,8 +4335,8 @@ void ScInputHandler::NotifyChange( const ScInputHdlState* 
pState,
                 const EditTextObject*   pData   = pState->GetEditData();
                 OUString aString = pState->GetString();
                 bool bTxtMod = false;
-                ScDocShell& rDocSh = 
pActiveViewSh->GetViewData().GetDocShell();
-                ScDocument& rDoc = rDocSh.GetDocument();
+                ScDocShell* pDocSh = 
pActiveViewSh->GetViewData().GetDocShell();
+                ScDocument& rDoc = pDocSh->GetDocument();
 
                 aCursorPos  = pState->GetPos();
 
@@ -4574,7 +4574,7 @@ void ScInputHandler::InputChanged( const EditView* pView, 
bool bFromNotify )
     {
         ScViewData& rViewData = pActiveViewSh->GetViewData();
         if ( bNewView )
-            rViewData.GetDocShell().PostEditView(*mpEditEngine, aCursorPos);
+            rViewData.GetDocShell()->PostEditView(*mpEditEngine, aCursorPos);
 
         rViewData.EditGrowY();
         rViewData.EditGrowX();
diff --git a/sc/source/ui/app/inputwin.cxx b/sc/source/ui/app/inputwin.cxx
index 67e3482c31e4..6dd2d679627a 100644
--- a/sc/source/ui/app/inputwin.cxx
+++ b/sc/source/ui/app/inputwin.cxx
@@ -1533,7 +1533,7 @@ void ScTextWnd::InitEditEngine()
     ScDocShell* pDocSh = nullptr;
     if ( mpViewShell )
     {
-        pDocSh = &mpViewShell->GetViewData().GetDocShell();
+        pDocSh = mpViewShell->GetViewData().GetDocShell();
         ScDocument& rDoc = mpViewShell->GetViewData().GetDocument();
         pNew = std::make_unique<ScFieldEditEngine>(&rDoc, 
rDoc.GetEditEnginePool());
     }
@@ -2607,8 +2607,8 @@ void ScPosWnd::DoEnter()
             if ( pViewSh )
             {
                 ScViewData& rViewData = pViewSh->GetViewData();
-                ScDocShell& rDocShell = rViewData.GetDocShell();
-                ScDocument& rDoc = rDocShell.GetDocument();
+                ScDocShell* pDocShell = rViewData.GetDocShell();
+                ScDocument& rDoc = pDocShell->GetDocument();
 
                 ScNameInputType eType = lcl_GetInputType( aText );
                 if ( eType == SC_NAME_INPUT_BAD_NAME || eType == 
SC_NAME_INPUT_BAD_SELECTION )
@@ -2629,7 +2629,7 @@ void ScPosWnd::DoEnter()
                         ScRangeData* pNew = new ScRangeData( rDoc, aText, 
aContent, aCursor );
                         if ( aNewRanges.insert(pNew) )
                         {
-                            rDocShell.GetDocFunc().ModifyRangeNames( 
aNewRanges );
+                            pDocShell->GetDocFunc().ModifyRangeNames( 
aNewRanges );
                             pViewSh->UpdateInputHandler(true);
                         }
                     }
diff --git a/sc/source/ui/app/seltrans.cxx b/sc/source/ui/app/seltrans.cxx
index 94275e8771cc..1382b769c1ca 100644
--- a/sc/source/ui/app/seltrans.cxx
+++ b/sc/source/ui/app/seltrans.cxx
@@ -262,11 +262,11 @@ void ScSelectionTransferObj::CreateCellData()
         //  similar to ScViewFunctionSet::BeginDrag
         if ( aNewMark.IsMarked() && !aNewMark.IsMultiMarked() )
         {
-            ScDocShell& rDocSh = rViewData.GetDocShell();
+            ScDocShell* pDocSh = rViewData.GetDocShell();
 
             const ScRange& aSelRange = aNewMark.GetMarkArea();
             ScDocShellRef aDragShellRef;
-            if ( rDocSh.GetDocument().HasOLEObjectsInArea( aSelRange, 
&aNewMark ) )
+            if ( pDocSh->GetDocument().HasOLEObjectsInArea( aSelRange, 
&aNewMark ) )
             {
                 aDragShellRef = new ScDocShell;     // DocShell needs a Ref 
immediately
                 aDragShellRef->DoInitNew();
@@ -284,8 +284,8 @@ void ScSelectionTransferObj::CreateCellData()
             if ( bCopied )
             {
                 TransferableObjectDescriptor aObjDesc;
-                rDocSh.FillTransferableObjectDescriptor( aObjDesc );
-                aObjDesc.maDisplayName = 
rDocSh.GetMedium()->GetURLObject().GetURLNoPass();
+                pDocSh->FillTransferableObjectDescriptor( aObjDesc );
+                aObjDesc.maDisplayName = 
pDocSh->GetMedium()->GetURLObject().GetURLNoPass();
                 // maSize is set in ScTransferObj ctor
 
                 rtl::Reference<ScTransferObj> xTransferObj = new 
ScTransferObj( std::move(pClipDoc), std::move(aObjDesc) );
@@ -295,7 +295,7 @@ void ScSelectionTransferObj::CreateCellData()
 
                 xTransferObj->SetDrawPersist(aDragShellRef); // keep persist 
for ole objects alive
 
-                xTransferObj->SetDragSource( &rDocSh, aNewMark );
+                xTransferObj->SetDragSource( pDocSh, aNewMark );
 
                 mxCellData = std::move(xTransferObj);
             }
@@ -330,14 +330,14 @@ void ScSelectionTransferObj::CreateDrawData()
             ScDrawLayer::SetGlobalDrawPersist(nullptr);
 
             ScViewData& rViewData = pView->GetViewData();
-            ScDocShell& rDocSh = rViewData.GetDocShell();
+            ScDocShell* pDocSh = rViewData.GetDocShell();
 
             TransferableObjectDescriptor aObjDesc;
-            rDocSh.FillTransferableObjectDescriptor( aObjDesc );
-            aObjDesc.maDisplayName = 
rDocSh.GetMedium()->GetURLObject().GetURLNoPass();
+            pDocSh->FillTransferableObjectDescriptor( aObjDesc );
+            aObjDesc.maDisplayName = 
pDocSh->GetMedium()->GetURLObject().GetURLNoPass();
             // maSize is set in ScDrawTransferObj ctor
 
-            rtl::Reference<ScDrawTransferObj> pTransferObj = new 
ScDrawTransferObj( std::move(pModel), rDocSh, std::move(aObjDesc) );
+            rtl::Reference<ScDrawTransferObj> pTransferObj = new 
ScDrawTransferObj( std::move(pModel), *pDocSh, std::move(aObjDesc) );
 
             pTransferObj->SetDrawPersist(aDragShellRef); // keep persist for 
ole objects alive
             pTransferObj->SetDragSource( pDrawView );       // copies selection
diff --git a/sc/source/ui/app/transobj.cxx b/sc/source/ui/app/transobj.cxx
index 981786150d3e..3388901b111b 100644
--- a/sc/source/ui/app/transobj.cxx
+++ b/sc/source/ui/app/transobj.cxx
@@ -100,9 +100,6 @@ void ScTransferObj::GetAreaSize( const ScDocument& rDoc, 
SCTAB nTab1, SCTAB nTab
 void ScTransferObj::PaintToDev( OutputDevice* pDev, ScDocument& rDoc, double 
nPrintFactor,
                                 const ScRange& rBlock )
 {
-    if (!rDoc.GetDocumentShell())
-        return;
-
     tools::Rectangle aBound( Point(), pDev->GetOutputSize() );      //! use 
size from clip area?
 
     ScViewData aViewData(rDoc);
diff --git a/sc/source/ui/condformat/condformatdlg.cxx 
b/sc/source/ui/condformat/condformatdlg.cxx
index de01c3f14fa4..d02253f81a92 100644
--- a/sc/source/ui/condformat/condformatdlg.cxx
+++ b/sc/source/ui/condformat/condformatdlg.cxx
@@ -625,11 +625,11 @@ void ScCondFormatDlg::OkPressed()
         if(pFormat)
         {
             auto& rRangeList = pFormat->GetRange();
-            
mrViewData.GetDocShell().GetDocFunc().ReplaceConditionalFormat(mnKey,
+            
mrViewData.GetDocShell()->GetDocFunc().ReplaceConditionalFormat(mnKey,
                     std::move(pFormat), maPos.Tab(), rRangeList);
         }
         else
-            
mrViewData.GetDocShell().GetDocFunc().ReplaceConditionalFormat(mnKey,
+            
mrViewData.GetDocShell()->GetDocFunc().ReplaceConditionalFormat(mnKey,
                     nullptr, maPos.Tab(), ScRangeList());
     }
     else
diff --git a/sc/source/ui/condformat/condformateasydlg.cxx 
b/sc/source/ui/condformat/condformateasydlg.cxx
index 11ebbd142602..2a6d8951b014 100644
--- a/sc/source/ui/condformat/condformateasydlg.cxx
+++ b/sc/source/ui/condformat/condformateasydlg.cxx
@@ -271,7 +271,7 @@ IMPL_LINK(ConditionalFormatEasyDialog, ButtonPressed, 
weld::Button&, rButton, vo
             pFormat->AddEntry(pEntry.release());
             pFormat->SetRange(aRange);
             auto& rRangeList = pFormat->GetRange();
-            mrViewData.GetDocShell().GetDocFunc().ReplaceConditionalFormat(
+            mrViewData.GetDocShell()->GetDocFunc().ReplaceConditionalFormat(
                 0, std::move(pFormat), maPosition.Tab(), rRangeList);
         }
         m_xDialog->response(RET_OK);
diff --git a/sc/source/ui/dbgui/PivotLayoutDialog.cxx 
b/sc/source/ui/dbgui/PivotLayoutDialog.cxx
index fbdabc3e5a46..9f76f67d528c 100644
--- a/sc/source/ui/dbgui/PivotLayoutDialog.cxx
+++ b/sc/source/ui/dbgui/PivotLayoutDialog.cxx
@@ -504,7 +504,7 @@ void ScPivotLayoutDialog::ApplyChanges()
             }
             if (pDPObj)
             {
-                ScDBDocFunc aFunc( mrViewData.GetDocShell() );
+                ScDBDocFunc aFunc( *mrViewData.GetDocShell() );
                 aFunc.RemovePivotTable( *pDPObj, true, false);
                 mrViewData.GetView()->CursorPosChanged();
             }
diff --git a/sc/source/ui/dbgui/dbnamdlg.cxx b/sc/source/ui/dbgui/dbnamdlg.cxx
index 154d49d68caf..7c23f950140b 100644
--- a/sc/source/ui/dbgui/dbnamdlg.cxx
+++ b/sc/source/ui/dbgui/dbnamdlg.cxx
@@ -375,7 +375,7 @@ IMPL_LINK_NOARG(ScDbNameDlg, OkBtnHdl, weld::Button&, void)
     // be created at this point:
     if (!bInvalid)
     {
-        ScDBDocFunc aFunc(m_rViewData.GetDocShell());
+        ScDBDocFunc aFunc(*m_rViewData.GetDocShell());
         aFunc.ModifyAllDBData(aLocalDbCol, aRemoveList);
         response(RET_OK);
     }
diff --git a/sc/source/ui/dbgui/filtdlg.cxx b/sc/source/ui/dbgui/filtdlg.cxx
index 260d97eec7fd..31a6b56aed0b 100644
--- a/sc/source/ui/dbgui/filtdlg.cxx
+++ b/sc/source/ui/dbgui/filtdlg.cxx
@@ -399,7 +399,7 @@ void ScFilterDlg::Init()
 
 void ScFilterDlg::Close()
 {
-    rViewData.GetDocShell().CancelAutoDBRange();
+    rViewData.GetDocShell()->CancelAutoDBRange();
 
     DoClose( ScFilterDlgWrapper::GetChildWindowId() );
 }
diff --git a/sc/source/ui/dbgui/sfiltdlg.cxx b/sc/source/ui/dbgui/sfiltdlg.cxx
index 49af1ff92e3d..5f7dce8f4bba 100644
--- a/sc/source/ui/dbgui/sfiltdlg.cxx
+++ b/sc/source/ui/dbgui/sfiltdlg.cxx
@@ -177,7 +177,7 @@ void ScSpecialFilterDlg::Init( const SfxItemSet& rArgSet )
 
 void ScSpecialFilterDlg::Close()
 {
-    rViewData.GetDocShell().CancelAutoDBRange();
+    rViewData.GetDocShell()->CancelAutoDBRange();
 
     DoClose( ScSpecialFilterDlgWrapper::GetChildWindowId() );
 }
diff --git a/sc/source/ui/dialogs/SparklineDataRangeDialog.cxx 
b/sc/source/ui/dialogs/SparklineDataRangeDialog.cxx
index 15150b5349f5..dedaf0faa742 100644
--- a/sc/source/ui/dialogs/SparklineDataRangeDialog.cxx
+++ b/sc/source/ui/dialogs/SparklineDataRangeDialog.cxx
@@ -193,7 +193,7 @@ void SparklineDataRangeDialog::perform()
 {
     ScRangeList aList{ maDataRange };
 
-    auto& rDocFunc = mrViewData.GetDocShell().GetDocFunc();
+    auto& rDocFunc = mrViewData.GetDocShell()->GetDocFunc();
     rDocFunc.ChangeSparkline(mpSparkline, mrViewData.CurrentTabForData(), 
aList);
 }
 
diff --git a/sc/source/ui/dialogs/SparklineDialog.cxx 
b/sc/source/ui/dialogs/SparklineDialog.cxx
index 5ce8d2f6c3da..ad092b6659e2 100644
--- a/sc/source/ui/dialogs/SparklineDialog.cxx
+++ b/sc/source/ui/dialogs/SparklineDialog.cxx
@@ -534,7 +534,7 @@ void SparklineDialog::perform()
     
maAttributes.setColorFirst(mxColorFirst->GetSelectedEntry().getComplexColor());
     
maAttributes.setColorLast(mxColorLast->GetSelectedEntry().getComplexColor());
 
-    auto& rDocFunc = mrViewData.GetDocShell().GetDocFunc();
+    auto& rDocFunc = mrViewData.GetDocShell()->GetDocFunc();
 
     if (mpSparklineGroup)
     {
diff --git a/sc/source/ui/docshell/docfunc.cxx 
b/sc/source/ui/docshell/docfunc.cxx
index 691cc30310c9..c30e8d8197af 100644
--- a/sc/source/ui/docshell/docfunc.cxx
+++ b/sc/source/ui/docshell/docfunc.cxx
@@ -1169,7 +1169,7 @@ bool ScDocFunc::SetFormulaCells( const ScAddress& rPos, 
std::vector<ScFormulaCel
 void ScDocFunc::NotifyInputHandler( const ScAddress& rPos )
 {
     ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell();
-    if ( !(pViewSh && &pViewSh->GetViewData().GetDocShell() == &rDocShell) )
+    if ( !(pViewSh && pViewSh->GetViewData().GetDocShell() == &rDocShell) )
         return;
 
     ScInputHandler* pInputHdl = ScModule::get()->GetInputHdl();
diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx
index e7dcf4607d3a..de2c6c164863 100644
--- a/sc/source/ui/docshell/docsh.cxx
+++ b/sc/source/ui/docshell/docsh.cxx
@@ -249,7 +249,7 @@ std::shared_ptr<model::ColorSet> 
ScDocShell::GetThemeColors()
 void ScDocShell::DoEnterHandler()
 {
     ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell();
-    if (pViewSh && &pViewSh->GetViewData().GetDocShell() == this)
+    if (pViewSh && pViewSh->GetViewData().GetDocShell() == this)
         ScModule::get()->InputEnterHandler();
 }
 
diff --git a/sc/source/ui/docshell/docsh3.cxx b/sc/source/ui/docshell/docsh3.cxx
index 3583984ec4ea..701240a7b553 100644
--- a/sc/source/ui/docshell/docsh3.cxx
+++ b/sc/source/ui/docshell/docsh3.cxx
@@ -83,7 +83,7 @@ void ScDocShell::PostEditView( ScEditEngineDefaulter& 
rEditEngine, const ScAddre
         //  Test: only active ViewShell
 
     ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell();
-    if (pViewSh && &pViewSh->GetViewData().GetDocShell() == this)
+    if (pViewSh && pViewSh->GetViewData().GetDocShell() == this)
     {
         ScEditViewHint aHint(rEditEngine, rCursorPos);
         pViewSh->Notify( *this, aHint );
diff --git a/sc/source/ui/docshell/docsh4.cxx b/sc/source/ui/docshell/docsh4.cxx
index 143c8f26f272..f2e8c08ba80c 100644
--- a/sc/source/ui/docshell/docsh4.cxx
+++ b/sc/source/ui/docshell/docsh4.cxx
@@ -3055,7 +3055,7 @@ ScTabViewShell* ScDocShell::GetBestViewShell( bool 
bOnlyVisible )
 {
     ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell();
     // wrong Doc?
-    if( pViewSh && &pViewSh->GetViewData().GetDocShell() != this )
+    if( pViewSh && pViewSh->GetViewData().GetDocShell() != this )
         pViewSh = nullptr;
     if( !pViewSh )
     {
diff --git a/sc/source/ui/docshell/docsh6.cxx b/sc/source/ui/docshell/docsh6.cxx
index 716e772dff3e..6d83fdf0d286 100644
--- a/sc/source/ui/docshell/docsh6.cxx
+++ b/sc/source/ui/docshell/docsh6.cxx
@@ -124,7 +124,7 @@ void ScDocShell::SetVisAreaOrSize( const tools::Rectangle& 
rVisArea )
         ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell();
         if (pViewSh)
         {
-            if (&pViewSh->GetViewData().GetDocShell() == this)
+            if (pViewSh->GetViewData().GetDocShell() == this)
                 pViewSh->UpdateOleZoom();
         }
     }
diff --git a/sc/source/ui/docshell/externalrefmgr.cxx 
b/sc/source/ui/docshell/externalrefmgr.cxx
index 05e5a64219e7..d9f6639f1794 100644
--- a/sc/source/ui/docshell/externalrefmgr.cxx
+++ b/sc/source/ui/docshell/externalrefmgr.cxx
@@ -1476,8 +1476,8 @@ void ScExternalRefLink::Closed()
         if (!pViewData)
             return ERROR_GENERAL;
 
-        ScDocShell& rDocShell = pViewData->GetDocShell();
-        ScDocShellModificator aMod(rDocShell);
+        ScDocShell* pDocShell = pViewData->GetDocShell();
+        ScDocShellModificator aMod(*pDocShell);
         pMgr->switchSrcFile(mnFileId, aFile, aFilter);
         aMod.SetDocumentModified();
     }
diff --git a/sc/source/ui/drawfunc/drawsh2.cxx 
b/sc/source/ui/drawfunc/drawsh2.cxx
index a91927310e97..a82741dbb51f 100644
--- a/sc/source/ui/drawfunc/drawsh2.cxx
+++ b/sc/source/ui/drawfunc/drawsh2.cxx
@@ -70,7 +70,7 @@ ScDrawShell::ScDrawShell( ScViewData& rData ) :
             pFrame->GetFrame().GetController(),
             vcl::EnumContext::Context::Cell);
     SetPool( &rViewData.GetScDrawView()->GetModel().GetItemPool() );
-    SfxUndoManager* pMgr = rViewData.GetSfxDocShell().GetUndoManager();
+    SfxUndoManager* pMgr = rViewData.GetSfxDocShell()->GetUndoManager();
     SetUndoManager( pMgr );
     if ( !rViewData.GetDocument().IsUndoEnabled() )
     {
diff --git a/sc/source/ui/drawfunc/drawsh5.cxx 
b/sc/source/ui/drawfunc/drawsh5.cxx
index 1031db8dbbbb..51235d7a0696 100644
--- a/sc/source/ui/drawfunc/drawsh5.cxx
+++ b/sc/source/ui/drawfunc/drawsh5.cxx
@@ -185,7 +185,7 @@ void ScDrawShell::ExecuteHLink( const SfxRequest& rReq )
                                         xPropSet->setPropertyValue( 
sPropLabel, uno::Any(rName) );
                                     }
 
-                                    OUString aTmp = INetURLObject::GetAbsURL( 
rViewData.GetDocShell().GetMedium()->GetBaseURL(), rURL );
+                                    OUString aTmp = INetURLObject::GetAbsURL( 
rViewData.GetDocShell()->GetMedium()->GetBaseURL(), rURL );
                                     xPropSet->setPropertyValue( 
sPropTargetURL, uno::Any(aTmp) );
 
                                     if( !rTarget.isEmpty() && 
xInfo->hasPropertyByName( sPropTargetFrame ) )
@@ -199,7 +199,7 @@ void ScDrawShell::ExecuteHLink( const SfxRequest& rReq )
                                     }
 
                                     //! Undo ???
-                                    
rViewData.GetDocShell().SetDocumentModified();
+                                    
rViewData.GetDocShell()->SetDocumentModified();
                                     bDone = true;
                                 }
                             }
@@ -516,7 +516,7 @@ void ScDrawShell::ExecDrawFunc( SfxRequest& rReq )
                             {
                                 if (nResult == RET_OK)
                                 {
-                                    ScDocShell& rDocSh = 
rViewData.GetDocShell();
+                                    ScDocShell* pDocSh = 
rViewData.GetDocShell();
                                     OUString aNewName = pDlg->GetName();
 
                                     if (aNewName != pSelected->GetName())
@@ -545,8 +545,8 @@ void ScDrawShell::ExecDrawFunc( SfxRequest& rReq )
 
                                             if(!aPersistName.isEmpty())
                                             {
-                                                
rDocSh.GetUndoManager()->AddUndoAction(
-                                                    
std::make_unique<ScUndoRenameObject>(rDocSh, aPersistName, 
pSelected->GetName(), aNewName));
+                                                
pDocSh->GetUndoManager()->AddUndoAction(
+                                                    
std::make_unique<ScUndoRenameObject>(*pDocSh, aPersistName, 
pSelected->GetName(), aNewName));
                                             }
                                         }
 
@@ -555,8 +555,8 @@ void ScDrawShell::ExecDrawFunc( SfxRequest& rReq )
                                     }
 
                                     // ChartListenerCollectionNeedsUpdate is 
needed for Navigator update
-                                    
rDocSh.GetDocument().SetChartListenerCollectionNeedsUpdate( true );
-                                    rDocSh.SetDrawModified();
+                                    
pDocSh->GetDocument().SetChartListenerCollectionNeedsUpdate( true );
+                                    pDocSh->SetDrawModified();
                                 }
                                 pDlg->disposeOnce();
                             }
@@ -591,7 +591,7 @@ void ScDrawShell::ExecDrawFunc( SfxRequest& rReq )
                             {
                                 if (nResult == RET_OK)
                                 {
-                                    ScDocShell& rDocSh = 
rViewData.GetDocShell();
+                                    ScDocShell* pDocSh = 
rViewData.GetDocShell();
 
                                     // handle Title and Description
                                     pSelected->SetTitle(pDlg->GetTitle());
@@ -599,8 +599,8 @@ void ScDrawShell::ExecDrawFunc( SfxRequest& rReq )
                                     
pSelected->SetDecorative(pDlg->IsDecorative());
 
                                     // ChartListenerCollectionNeedsUpdate is 
needed for Navigator update
-                                    
rDocSh.GetDocument().SetChartListenerCollectionNeedsUpdate( true );
-                                    rDocSh.SetDrawModified();
+                                    
pDocSh->GetDocument().SetChartListenerCollectionNeedsUpdate( true );
+                                    pDocSh->SetDrawModified();
                                 }
                                 pDlg->disposeOnce();
                             }
diff --git a/sc/source/ui/drawfunc/drtxtob.cxx 
b/sc/source/ui/drawfunc/drtxtob.cxx
index ed3c04f6a3a8..1dd8e2fbde04 100644
--- a/sc/source/ui/drawfunc/drtxtob.cxx
+++ b/sc/source/ui/drawfunc/drtxtob.cxx
@@ -119,7 +119,7 @@ ScDrawTextObjectBar::ScDrawTextObjectBar(ScViewData& rData) 
:
     SetPool( mrViewData.GetScDrawView()->GetDefaultAttr().GetPool() );
 
     //  At the switching-over the UndoManager is changed to edit mode
-    SfxUndoManager* pMgr = mrViewData.GetSfxDocShell().GetUndoManager();
+    SfxUndoManager* pMgr = mrViewData.GetSfxDocShell()->GetUndoManager();
     SetUndoManager( pMgr );
     if ( !mrViewData.GetDocument().IsUndoEnabled() )
     {
@@ -944,7 +944,7 @@ void ScDrawTextObjectBar::ExecuteAttr( SfxRequest &rReq )
             {
                 const sal_uInt16 nEEWhich = 
GetPool().GetWhichIDFromSlotID(nSlot);
                 const std::optional<NamedColor> oColor
-                    = mrViewData.GetDocShell().GetRecentColor(nSlot);
+                    = mrViewData.GetDocShell()->GetRecentColor(nSlot);
                 if (oColor.has_value())
                 {
                     const model::ComplexColor aCol = 
(*oColor).getComplexColor();
diff --git a/sc/source/ui/drawfunc/drtxtob1.cxx 
b/sc/source/ui/drawfunc/drtxtob1.cxx
index 4f5727918d44..69cab28cfc6f 100644
--- a/sc/source/ui/drawfunc/drtxtob1.cxx
+++ b/sc/source/ui/drawfunc/drtxtob1.cxx
@@ -43,7 +43,7 @@ bool ScDrawTextObjectBar::ExecuteCharDlg( const SfxItemSet& 
rArgs,
     ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
     ScopedVclPtr<SfxAbstractTabDialog> pDlg(pFact->CreateScCharDlg(
         mrViewData.GetDialogParent(), &rArgs,
-        &mrViewData.GetSfxDocShell(), true));
+        mrViewData.GetSfxDocShell(), true));
     if (nSlot == SID_CHAR_DLG_EFFECT)
     {
         pDlg->SetCurPageId(u"fonteffects"_ustr);
diff --git a/sc/source/ui/drawfunc/fudraw.cxx b/sc/source/ui/drawfunc/fudraw.cxx
index ae863da42032..76c1824d7398 100644
--- a/sc/source/ui/drawfunc/fudraw.cxx
+++ b/sc/source/ui/drawfunc/fudraw.cxx
@@ -438,7 +438,7 @@ bool FuDraw::KeyInput(const KeyEvent& rKEvt)
                     nY = 0;
                 }
 
-                bool bReadOnly = rViewData.GetDocShell().IsReadOnly();
+                bool bReadOnly = rViewData.GetDocShell()->IsReadOnly();
 
                 if(!rKEvt.GetKeyCode().IsMod1() && !bReadOnly)
                 {
diff --git a/sc/source/ui/drawfunc/fuins2.cxx b/sc/source/ui/drawfunc/fuins2.cxx
index 264a69adc7e3..262334be9ad1 100644
--- a/sc/source/ui/drawfunc/fuins2.cxx
+++ b/sc/source/ui/drawfunc/fuins2.cxx
@@ -83,8 +83,8 @@ namespace
 void lcl_ChartInit(const uno::Reference <embed::XEmbeddedObject>& xObj, 
ScViewData* pViewData,
                    const OUString& rRangeParam, bool bRangeIsPivotTable)
 {
-    ScDocShell& rDocShell = pViewData->GetDocShell();
-    ScDocument& rScDoc = rDocShell.GetDocument();
+    ScDocShell* pDocShell = pViewData->GetDocShell();
+    ScDocument& rScDoc = pDocShell->GetDocument();
 
     OUString aRangeString(rRangeParam);
 
@@ -142,7 +142,7 @@ void lcl_ChartInit(const uno::Reference 
<embed::XEmbeddedObject>& xObj, ScViewDa
 
     xReceiver->attachDataProvider(xDataProvider);
 
-    uno::Reference< util::XNumberFormatsSupplier > xNumberFormatsSupplier( 
getXWeak(rDocShell.GetModel()), uno::UNO_QUERY );
+    uno::Reference< util::XNumberFormatsSupplier > xNumberFormatsSupplier( 
getXWeak(pDocShell->GetModel()), uno::UNO_QUERY );
     xReceiver->attachNumberFormatsSupplier( xNumberFormatsSupplier );
 
     // Same behavior as with old chart: Always assume data series in columns
@@ -524,8 +524,8 @@ FuInsertChart::FuInsertChart(ScTabViewShell& rViewSh, 
vcl::Window* pWin, ScDrawV
     }
 
     ScViewData& rData = rViewSh.GetViewData();
-    ScDocShell& rScDocSh = rData.GetDocShell();
-    ScDocument& rScDoc   = rScDocSh.GetDocument();
+    ScDocShell* pScDocSh = rData.GetDocShell();
+    ScDocument& rScDoc   = pScDocSh->GetDocument();
     bool bUndo (rScDoc.IsUndoEnabled());
 
     if( pReqArgs )
@@ -566,14 +566,14 @@ FuInsertChart::FuInsertChart(ScTabViewShell& rViewSh, 
vcl::Window* pWin, ScDrawV
             {
                 if (bUndo)
                 {
-                    rScDocSh.GetUndoManager()->AddUndoAction(
-                        std::make_unique<ScUndoInsertTab>( rScDocSh, nNewTab,
+                    pScDocSh->GetUndoManager()->AddUndoAction(
+                        std::make_unique<ScUndoInsertTab>( *pScDocSh, nNewTab,
                                              true/*bAppend*/, aTabName ) );
                 }
 
-                rScDocSh.Broadcast( ScTablesHint( SC_TAB_INSERTED, nNewTab ) );
+                pScDocSh->Broadcast( ScTablesHint( SC_TAB_INSERTED, nNewTab ) 
);
                 rViewSh.SetTabNo( nNewTab, true );
-                rScDocSh.PostPaintExtras();            //! done afterwards ???
+                pScDocSh->PostPaintExtras();            //! done afterwards ???
             }
             else
             {
diff --git a/sc/source/ui/drawfunc/fusel.cxx b/sc/source/ui/drawfunc/fusel.cxx
index b30825b80696..5b0b7188608e 100644
--- a/sc/source/ui/drawfunc/fusel.cxx
+++ b/sc/source/ui/drawfunc/fusel.cxx
@@ -543,8 +543,8 @@ bool FuSelection::MouseButtonUp(const MouseEvent& rMEvt)
 
     if ( bCopy && pPage )
     {
-        ScDocShell& rDocShell = rViewData.GetDocShell();
-        ScModelObj* pModelObj = rDocShell.GetModel();
+        ScDocShell* pDocShell = rViewData.GetDocShell();
+        ScModelObj* pModelObj = pDocShell ? pDocShell->GetModel() : nullptr;
         if ( pModelObj )
         {
             SCTAB nTab = rViewData.CurrentTabForData();
diff --git a/sc/source/ui/drawfunc/fusel2.cxx b/sc/source/ui/drawfunc/fusel2.cxx
index 1a0a5b4822b4..d63c08467ad2 100644
--- a/sc/source/ui/drawfunc/fusel2.cxx
+++ b/sc/source/ui/drawfunc/fusel2.cxx
@@ -121,8 +121,8 @@ bool FuSelection::IsNoteCaptionClicked( const Point& rPos ) 
const
         const ScViewData& rViewData = rViewShell.GetViewData();
         ScDocument& rDoc = rViewData.GetDocument();
         SCTAB nTab = rViewData.CurrentTabForData();
-        ScDocShell& rDocSh = rViewData.GetDocShell();
-        bool bProtectDoc =  rDoc.IsTabProtected( nTab ) || rDocSh.IsReadOnly();
+        ScDocShell* pDocSh = rViewData.GetDocShell();
+        bool bProtectDoc =  rDoc.IsTabProtected( nTab ) || (pDocSh && 
pDocSh->IsReadOnly());
 
         // search the last object (on top) in the object list
         SdrObjListIter aIter( pPageView->GetObjList(), 
SdrIterMode::DeepNoGroups, true );
diff --git a/sc/source/ui/drawfunc/futext3.cxx 
b/sc/source/ui/drawfunc/futext3.cxx
index e6048de37860..5345fa7c5737 100644
--- a/sc/source/ui/drawfunc/futext3.cxx
+++ b/sc/source/ui/drawfunc/futext3.cxx
@@ -62,8 +62,8 @@ void FuText::StopEditMode()
         OSL_ENSURE( pNote && (pNote->GetCaption() == pObject), 
"FuText::StopEditMode - missing or invalid cell note" );
     }
 
-    ScDocShell& rDocShell = rViewData.GetDocShell();
-    SfxUndoManager* pUndoMgr = rDoc.IsUndoEnabled() ? 
rDocShell.GetUndoManager() : nullptr;
+    ScDocShell* pDocShell = rViewData.GetDocShell();
+    SfxUndoManager* pUndoMgr = rDoc.IsUndoEnabled() ? 
pDocShell->GetUndoManager() : nullptr;
     if (pUndoMgr && !pUndoMgr->GetMaxUndoActionCount()) // tdf#134308 if max 
undo is 0, treat as if no undo
         pUndoMgr = nullptr;
     bool bNewNote = false;
@@ -85,7 +85,7 @@ void FuText::StopEditMode()
 
             // create a "insert note" undo action if needed
             if( bNewNote )
-                pUndoMgr->AddUndoAction( std::make_unique<ScUndoReplaceNote>( 
rDocShell, aNotePos, pNote->GetNoteData(), true, std::move(pCalcUndo) ) );
+                pUndoMgr->AddUndoAction( std::make_unique<ScUndoReplaceNote>( 
*pDocShell, aNotePos, pNote->GetNoteData(), true, std::move(pCalcUndo) ) );
             else
                 pUndoMgr->AddUndoAction( std::move(pCalcUndo) );
         }
@@ -139,7 +139,7 @@ void FuText::StopEditMode()
             // delete note from document (removes caption, but does not delete 
it)
             rDoc.ReleaseNote(aNotePos);
             // create undo action for removed note
-            pUndoMgr->AddUndoAction( std::make_unique<ScUndoReplaceNote>( 
rDocShell, aNotePos, aNoteData, false, pDrawLayer->GetCalcUndo() ) );
+            pUndoMgr->AddUndoAction( std::make_unique<ScUndoReplaceNote>( 
*pDocShell, aNotePos, aNoteData, false, pDrawLayer->GetCalcUndo() ) );
         }
         else
         {
diff --git a/sc/source/ui/formdlg/formula.cxx b/sc/source/ui/formdlg/formula.cxx
index fe4bd74c126f..e3fe69879197 100644
--- a/sc/source/ui/formdlg/formula.cxx
+++ b/sc/source/ui/formdlg/formula.cxx
@@ -119,7 +119,7 @@ ScFormulaDlg::ScFormulaDlg(SfxBindings* pB, SfxChildWindow* 
pCW,
     SCTAB nTab = rViewData.CurrentTabForData();
     m_CursorPos = ScAddress( nCol, nRow, nTab );
 
-    m_pViewShell->InitFormEditData(rViewData.GetDocShell()); // create new
+    m_pViewShell->InitFormEditData(*rViewData.GetDocShell()); // create new
     pData = m_pViewShell->GetFormEditData();
     pData->SetInputHandler(pInputHdl);
 
diff --git a/sc/source/ui/inc/AnalysisOfVarianceDialog.hxx 
b/sc/source/ui/inc/AnalysisOfVarianceDialog.hxx
index b620db2929ce..35c53e72778f 100644
--- a/sc/source/ui/inc/AnalysisOfVarianceDialog.hxx
+++ b/sc/source/ui/inc/AnalysisOfVarianceDialog.hxx
@@ -55,7 +55,7 @@ public:
 
 protected:
     virtual TranslateId GetUndoNameId() override;
-    virtual ScRange ApplyOutput(ScDocShell& rDocShell) override;
+    virtual ScRange ApplyOutput(ScDocShell* pDocShell) override;
 };
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/inc/ChiSquareTestDialog.hxx 
b/sc/source/ui/inc/ChiSquareTestDialog.hxx
index 4813ae207327..20e7d696c95f 100644
--- a/sc/source/ui/inc/ChiSquareTestDialog.hxx
+++ b/sc/source/ui/inc/ChiSquareTestDialog.hxx
@@ -25,7 +25,7 @@ public:
 
 protected:
     virtual TranslateId GetUndoNameId() override;
-    virtual ScRange ApplyOutput(ScDocShell& rDocShell) override;
+    virtual ScRange ApplyOutput(ScDocShell* pDocShell) override;
 };
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/inc/DescriptiveStatisticsDialog.hxx 
b/sc/source/ui/inc/DescriptiveStatisticsDialog.hxx
index 1cf80291fa7d..dd2488450beb 100644
--- a/sc/source/ui/inc/DescriptiveStatisticsDialog.hxx
+++ b/sc/source/ui/inc/DescriptiveStatisticsDialog.hxx
@@ -25,7 +25,7 @@ public:
 
 protected:
     virtual TranslateId GetUndoNameId() override;
-    virtual ScRange ApplyOutput(ScDocShell& rDocShell) override;
+    virtual ScRange ApplyOutput(ScDocShell* pDocShell) override;
 };
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/inc/ExponentialSmoothingDialog.hxx 
b/sc/source/ui/inc/ExponentialSmoothingDialog.hxx
index ceb16891a572..54b877167805 100644
--- a/sc/source/ui/inc/ExponentialSmoothingDialog.hxx
+++ b/sc/source/ui/inc/ExponentialSmoothingDialog.hxx
@@ -31,7 +31,7 @@ public:
 
 protected:
     virtual TranslateId GetUndoNameId() override;
-    virtual ScRange ApplyOutput(ScDocShell& rDocShell) override;
+    virtual ScRange ApplyOutput(ScDocShell* pDocShell) override;
 };
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/inc/FTestDialog.hxx b/sc/source/ui/inc/FTestDialog.hxx
index 71fb8dcd28b1..efd477ce08bb 100644
--- a/sc/source/ui/inc/FTestDialog.hxx
+++ b/sc/source/ui/inc/FTestDialog.hxx
@@ -25,7 +25,7 @@ public:
 
 protected:
     virtual TranslateId GetUndoNameId() override;
-    virtual ScRange ApplyOutput(ScDocShell& rDocShell) override;
+    virtual ScRange ApplyOutput(ScDocShell* pDocShell) override;
 };
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/inc/FourierAnalysisDialog.hxx 
b/sc/source/ui/inc/FourierAnalysisDialog.hxx
index 1427a27c472d..f839b274e4d8 100644
--- a/sc/source/ui/inc/FourierAnalysisDialog.hxx
+++ b/sc/source/ui/inc/FourierAnalysisDialog.hxx
@@ -42,7 +42,7 @@ public:
 
 protected:
     virtual TranslateId GetUndoNameId() override;
-    virtual ScRange ApplyOutput(ScDocShell& rDocShell) override;
+    virtual ScRange ApplyOutput(ScDocShell* pDocShell) override;
     virtual bool InputRangesValid() override;
 
 private:
diff --git a/sc/source/ui/inc/MatrixComparisonGenerator.hxx 
b/sc/source/ui/inc/MatrixComparisonGenerator.hxx
index c38f9dd24b6b..ab1e51d7a9b4 100644
--- a/sc/source/ui/inc/MatrixComparisonGenerator.hxx
+++ b/sc/source/ui/inc/MatrixComparisonGenerator.hxx
@@ -27,7 +27,7 @@ public:
 
 protected:
     virtual TranslateId GetUndoNameId() override;
-    virtual ScRange ApplyOutput(ScDocShell& rDocShell) override;
+    virtual ScRange ApplyOutput(ScDocShell* pDocShell) override;
 
     virtual OUString getLabel() = 0;
     virtual OUString getTemplate() = 0;
diff --git a/sc/source/ui/inc/MovingAverageDialog.hxx 
b/sc/source/ui/inc/MovingAverageDialog.hxx
index 08f400b709c7..216b67c8b400 100644
--- a/sc/source/ui/inc/MovingAverageDialog.hxx
+++ b/sc/source/ui/inc/MovingAverageDialog.hxx
@@ -32,7 +32,7 @@ public:
 
 protected:
     virtual TranslateId GetUndoNameId() override;
-    virtual ScRange ApplyOutput(ScDocShell& rDocShell) override;
+    virtual ScRange ApplyOutput(ScDocShell* pDocShell) override;
 };
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/inc/RegressionDialog.hxx 
b/sc/source/ui/inc/RegressionDialog.hxx
index 38f98a1a261d..f3783c36c91d 100644
--- a/sc/source/ui/inc/RegressionDialog.hxx
+++ b/sc/source/ui/inc/RegressionDialog.hxx
@@ -40,7 +40,7 @@ public:
 
 protected:
     virtual TranslateId GetUndoNameId() override;
-    virtual ScRange ApplyOutput(ScDocShell& rDocShell) override;
+    virtual ScRange ApplyOutput(ScDocShell* pDocShell) override;
     virtual bool InputRangesValid() override;
 
 private:
diff --git a/sc/source/ui/inc/StatisticsInputOutputDialog.hxx 
b/sc/source/ui/inc/StatisticsInputOutputDialog.hxx
index ca596ae12e8a..e831772c8451 100644
--- a/sc/source/ui/inc/StatisticsInputOutputDialog.hxx
+++ b/sc/source/ui/inc/StatisticsInputOutputDialog.hxx
@@ -36,7 +36,7 @@ public:
 protected:
     void CalculateInputAndWriteToOutput();
 
-    virtual ScRange ApplyOutput(ScDocShell& rDocShell) = 0;
+    virtual ScRange ApplyOutput(ScDocShell* pDocShell) = 0;
     virtual TranslateId GetUndoNameId() = 0;
     virtual bool InputRangesValid();
     void ValidateDialogInput();
diff --git a/sc/source/ui/inc/StatisticsTwoVariableDialog.hxx 
b/sc/source/ui/inc/StatisticsTwoVariableDialog.hxx
index 0ed7d6b242e9..f848f8ccc3b1 100644
--- a/sc/source/ui/inc/StatisticsTwoVariableDialog.hxx
+++ b/sc/source/ui/inc/StatisticsTwoVariableDialog.hxx
@@ -35,7 +35,7 @@ public:
 protected:
     void CalculateInputAndWriteToOutput();
 
-    virtual ScRange ApplyOutput(ScDocShell& rDocShell) = 0;
+    virtual ScRange ApplyOutput(ScDocShell* pDocShell) = 0;
     virtual TranslateId GetUndoNameId() = 0;
     virtual bool InputRangesValid();
     void ValidateDialogInput();
diff --git a/sc/source/ui/inc/TTestDialog.hxx b/sc/source/ui/inc/TTestDialog.hxx
index 234054ec6ba3..0ed370dce2d4 100644
--- a/sc/source/ui/inc/TTestDialog.hxx
+++ b/sc/source/ui/inc/TTestDialog.hxx
@@ -25,7 +25,7 @@ public:
 
 protected:
     virtual TranslateId GetUndoNameId() override;
-    virtual ScRange ApplyOutput(ScDocShell& rDocShell) override;
+    virtual ScRange ApplyOutput(ScDocShell* pDocShell) override;
 };
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/inc/TableFillingAndNavigationTools.hxx 
b/sc/source/ui/inc/TableFillingAndNavigationTools.hxx
index 4171d413fb90..0e678e3f4482 100644
--- a/sc/source/ui/inc/TableFillingAndNavigationTools.hxx
+++ b/sc/source/ui/inc/TableFillingAndNavigationTools.hxx
@@ -71,12 +71,12 @@ public:
 
 class AddressWalkerWriter : public AddressWalker
 {
-    ScDocShell&                         mrDocShell;
+    ScDocShell*                         mpDocShell;
     ScDocument&                         mrDocument;
     formula::FormulaGrammar::Grammar    meGrammar;
 
 public:
-    AddressWalkerWriter(const ScAddress& aInitialAddress, ScDocShell& 
rDocShell, ScDocument& rDocument,
+    AddressWalkerWriter(const ScAddress& aInitialAddress, ScDocShell* 
pDocShell, ScDocument& rDocument,
             formula::FormulaGrammar::Grammar eGrammar );
 
     void writeFormula(const OUString& aFormula);
diff --git a/sc/source/ui/inc/ZTestDialog.hxx b/sc/source/ui/inc/ZTestDialog.hxx
index d0a19c657cc9..2476c38f32a7 100644
--- a/sc/source/ui/inc/ZTestDialog.hxx
+++ b/sc/source/ui/inc/ZTestDialog.hxx
@@ -25,7 +25,7 @@ public:
 
 protected:
     virtual TranslateId GetUndoNameId() override;
-    virtual ScRange ApplyOutput(ScDocShell& rDocShell) override;
+    virtual ScRange ApplyOutput(ScDocShell* pDocShell) override;
 };
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/inc/namedefdlg.hxx b/sc/source/ui/inc/namedefdlg.hxx
index 0007a3322768..63afb02645e3 100644
--- a/sc/source/ui/inc/namedefdlg.hxx
+++ b/sc/source/ui/inc/namedefdlg.hxx
@@ -23,7 +23,7 @@ class ScNameDefDlg : public ScAnyRefDlgController
 private:
     bool mbUndo; //if true we need to add an undo action after creating a 
range name
     ScDocument& mrDoc;
-    ScDocShell& mrDocShell;
+    ScDocShell* mpDocShell;
 
     ScAddress maCursorPos;
     OUString maStrInfoDefault;
diff --git a/sc/source/ui/inc/optsolver.hxx b/sc/source/ui/inc/optsolver.hxx
index a26c63b26bff..35570f7d09d4 100644
--- a/sc/source/ui/inc/optsolver.hxx
+++ b/sc/source/ui/inc/optsolver.hxx
@@ -52,7 +52,7 @@ class ScOptSolverDlg : public ScAnyRefDlgController
 {
 public:
     ScOptSolverDlg( SfxBindings* pB, SfxChildWindow* pCW, weld::Window* 
pParent,
-                 ScDocShell& rDocSh, const ScAddress& aCursorPos );
+                 ScDocShell* pDocSh, const ScAddress& aCursorPos );
     virtual ~ScOptSolverDlg() override;
 
     virtual void    SetReference( const ScRange& rRef, ScDocument& rDoc ) 
override;
@@ -64,7 +64,7 @@ private:
     OUString        maInputError;
     OUString        maConditionError;
 
-    ScDocShell&     mrDocShell;
+    ScDocShell*     mpDocShell;
     ScDocument&     mrDoc;
     const SCTAB     mnCurTab;
     bool            mbDlgLostFocus;
diff --git a/sc/source/ui/inc/sharedocdlg.hxx b/sc/source/ui/inc/sharedocdlg.hxx
index 967e15e98759..ba83b1787b84 100644
--- a/sc/source/ui/inc/sharedocdlg.hxx
+++ b/sc/source/ui/inc/sharedocdlg.hxx
@@ -32,7 +32,7 @@ private:
     OUString            m_aStrUnknownUser;
     OUString            m_aStrExclusiveAccess;
 
-    ScDocShell&         mrDocShell;
+    ScDocShell*         mpDocShell;
 
     std::unique_ptr<weld::CheckButton> m_xCbShare;
     std::unique_ptr<weld::Label> m_xFtWarning;
diff --git a/sc/source/ui/inc/viewdata.hxx b/sc/source/ui/inc/viewdata.hxx
index 6edc8dcdf2da..6d1e42f7b17f 100644
--- a/sc/source/ui/inc/viewdata.hxx
+++ b/sc/source/ui/inc/viewdata.hxx
@@ -279,7 +279,7 @@ private:
     ScMarkData          maMarkData;
     ScMarkData          maHighlightData;
     ScViewDataTable* pThisTab;                   // Data of the displayed sheet
-    ScDocShell&         mrDocShell;
+    ScDocShell*         pDocShell;
     ScDocument&         mrDoc;
     ScTabViewShell*     pView;
     std::unique_ptr<EditView> pEditView[4];               // Belongs to the 
window
@@ -361,11 +361,11 @@ public:
     ScViewData( ScDocument& rDoc );
     ~ScViewData() COVERITY_NOEXCEPT_FALSE;
 
-    ScDocShell&     GetDocShell() const     { return mrDocShell; }
+    ScDocShell*     GetDocShell() const     { return pDocShell; }
     ScDocFunc&      GetDocFunc() const;
     SC_DLLPUBLIC ScDBFunc* GetView() const;
     ScTabViewShell* GetViewShell() const    { return pView; }
-    SfxObjectShell& GetSfxDocShell() const  { return mrDocShell; }
+    SfxObjectShell* GetSfxDocShell() const  { return pDocShell; }
     SfxBindings&    GetBindings();          // from ViewShell's ViewFrame
     SC_DLLPUBLIC SfxDispatcher& GetDispatcher();        // from ViewShell's 
ViewFrame
 
diff --git a/sc/source/ui/miscdlgs/acredlin.cxx 
b/sc/source/ui/miscdlgs/acredlin.cxx
index e056fdad1569..a137609d2f94 100644
--- a/sc/source/ui/miscdlgs/acredlin.cxx
+++ b/sc/source/ui/miscdlgs/acredlin.cxx
@@ -865,11 +865,11 @@ IMPL_LINK( ScAcceptChgDlg, RejectHandle, SvxTPView*, 
pRef, void )
             }
             return false;
         });
-        ScDocShell& rDocSh=pViewData->GetDocShell();
-        rDocSh.PostPaintExtras();
-        rDocSh.PostPaintGridAll();
-        rDocSh.GetUndoManager()->Clear();
-        rDocSh.SetDocumentModified();
+        ScDocShell* pDocSh=pViewData->GetDocShell();
+        pDocSh->PostPaintExtras();
+        pDocSh->PostPaintGridAll();
+        pDocSh->GetUndoManager()->Clear();
+        pDocSh->SetDocumentModified();
         ClearView();
         UpdateView();
     }
@@ -905,10 +905,10 @@ IMPL_LINK( ScAcceptChgDlg, AcceptHandle, SvxTPView*, 
pRef, void )
             }
             return false;
         });
-        ScDocShell& rDocSh=pViewData->GetDocShell();
-        rDocSh.PostPaintExtras();
-        rDocSh.PostPaintGridAll();
-        rDocSh.SetDocumentModified();
+        ScDocShell* pDocSh=pViewData->GetDocShell();
+        pDocSh->PostPaintExtras();
+        pDocSh->PostPaintGridAll();
+        pDocSh->SetDocumentModified();
         ClearView();
         UpdateView();
     }
@@ -967,11 +967,11 @@ IMPL_LINK_NOARG(ScAcceptChgDlg, RejectAllHandle, 
SvxTPView*, void)
 
         pViewData->SetTabNo(0);
 
-        ScDocShell& rDocSh=pViewData->GetDocShell();
-        rDocSh.PostPaintExtras();
-        rDocSh.PostPaintGridAll();
-        rDocSh.GetUndoManager()->Clear();
-        rDocSh.SetDocumentModified();
+        ScDocShell* pDocSh=pViewData->GetDocShell();
+        pDocSh->PostPaintExtras();
+        pDocSh->PostPaintGridAll();
+        pDocSh->GetUndoManager()->Clear();
+        pDocSh->SetDocumentModified();
         ClearView();
         UpdateView();
     }
@@ -993,10 +993,10 @@ IMPL_LINK_NOARG(ScAcceptChgDlg, AcceptAllHandle, 
SvxTPView*, void)
         else
             pChanges->AcceptAll();
 
-        ScDocShell& rDocSh=pViewData->GetDocShell();
-        rDocSh.PostPaintExtras();
-        rDocSh.PostPaintGridAll();
-        rDocSh.SetDocumentModified();
+        ScDocShell* pDocSh=pViewData->GetDocShell();
+        pDocSh->PostPaintExtras();
+        pDocSh->PostPaintGridAll();
+        pDocSh->SetDocumentModified();
         ClearView();
         UpdateView();
     }
@@ -1614,7 +1614,7 @@ IMPL_LINK(ScAcceptChgDlg, CommandHdl, const 
CommandEvent&, rCEvt, bool)
                 if (pEntryData)
                 {
                     ScChangeAction* pScChangeAction = 
static_cast<ScChangeAction*>(pEntryData->pData);
-                    
pViewData->GetDocShell().ExecuteChangeCommentDialog(pScChangeAction, 
m_xDialog.get(), false);
+                    
pViewData->GetDocShell()->ExecuteChangeCommentDialog(pScChangeAction, 
m_xDialog.get(), false);
                 }
             }
         }
diff --git a/sc/source/ui/miscdlgs/crnrdlg.cxx 
b/sc/source/ui/miscdlgs/crnrdlg.cxx
index 13f47a4d04b5..38e0f2f3806d 100644
--- a/sc/source/ui/miscdlgs/crnrdlg.cxx
+++ b/sc/source/ui/miscdlgs/crnrdlg.cxx
@@ -485,9 +485,9 @@ IMPL_LINK_NOARG(ScColRowNameRangesDlg, OkBtnHdl, 
weld::Button&, void)
     rDoc.GetRowNameRangesRef() = xRowNameRanges;
     // changed ranges need to take effect
     rDoc.CompileColRowNameFormula();
-    ScDocShell& rDocShell = m_rViewData.GetDocShell();
-    rDocShell.PostPaint(ScRange(0, 0, 0, rDoc.MaxCol(), rDoc.MaxRow(), 
MAXTAB), PaintPartFlags::Grid);
-    rDocShell.SetDocumentModified();
+    ScDocShell* pDocShell = m_rViewData.GetDocShell();
+    pDocShell->PostPaint(ScRange(0, 0, 0, rDoc.MaxCol(), rDoc.MaxRow(), 
MAXTAB), PaintPartFlags::Grid);
+    pDocShell->SetDocumentModified();
 
     response(RET_OK);
 }
diff --git a/sc/source/ui/miscdlgs/datafdlg.cxx 
b/sc/source/ui/miscdlgs/datafdlg.cxx
index 6346363c7e25..3f89ed5cec89 100644
--- a/sc/source/ui/miscdlgs/datafdlg.cxx
+++ b/sc/source/ui/miscdlgs/datafdlg.cxx
@@ -227,7 +227,7 @@ IMPL_LINK( ScDataFormDlg, Impl_DataModifyHdl, weld::Entry&, 
rEdit, void)
 IMPL_LINK_NOARG(ScDataFormDlg, Impl_NewHdl, weld::Button&, void)
 {
     ScViewData& rViewData = m_rTabViewShell.GetViewData();
-    ScDocShell& rDocSh = rViewData.GetDocShell();
+    ScDocShell* pDocSh = rViewData.GetDocShell();
 
     bool bHasData = std::any_of(m_aEntries.begin(), m_aEntries.end(),
         [](const std::unique_ptr<ScDataFormFragment>& rElem) { return (rElem 
!= nullptr) && (!rElem->m_xEdit->get_text().isEmpty()); });
@@ -245,8 +245,8 @@ IMPL_LINK_NOARG(ScDataFormDlg, Impl_NewHdl, weld::Button&, 
void)
     }
     SetButtonState();
     FillCtrls();
-    rDocSh.SetDocumentModified();
-    rDocSh.PostPaintGridAll();
+    pDocSh->SetDocumentModified();
+    pDocSh->PostPaintGridAll();
 }
 
 IMPL_LINK_NOARG(ScDataFormDlg, Impl_PrevHdl, weld::Button&, void)
@@ -275,18 +275,18 @@ IMPL_LINK_NOARG(ScDataFormDlg, Impl_RestoreHdl, 
weld::Button&, void)
 IMPL_LINK_NOARG(ScDataFormDlg, Impl_DeleteHdl, weld::Button&, void)
 {
     ScViewData& rViewData = m_rTabViewShell.GetViewData();
-    ScDocShell& rDocSh = rViewData.GetDocShell();
+    ScDocShell* pDocSh = rViewData.GetDocShell();
 
     ScRange aRange(m_nStartCol, m_nCurrentRow, m_nTab, m_nEndCol, 
m_nCurrentRow, m_nTab);
     m_rDoc.DeleteRow(aRange);
     m_nEndRow--;
 
     SetButtonState();
-    rDocSh.GetUndoManager()->Clear();
+    pDocSh->GetUndoManager()->Clear();
 
     FillCtrls();
-    rDocSh.SetDocumentModified();
-    rDocSh.PostPaintGridAll();
+    pDocSh->SetDocumentModified();
+    pDocSh->PostPaintGridAll();
 }
 
 IMPL_LINK_NOARG(ScDataFormDlg, Impl_CloseHdl, weld::Button&, void)
diff --git a/sc/source/ui/miscdlgs/highred.cxx 
b/sc/source/ui/miscdlgs/highred.cxx
index 654bc0040ee9..742828c70cff 100644
--- a/sc/source/ui/miscdlgs/highred.cxx
+++ b/sc/source/ui/miscdlgs/highred.cxx
@@ -214,7 +214,7 @@ IMPL_LINK_NOARG(ScHighlightChgDlg, OKBtnHdl, weld::Button&, 
void)
     aChangeViewSet.SetTheRangeList(aLocalRangeList);
     aChangeViewSet.AdjustDateMode( rDoc );
     rDoc.SetChangeViewSettings(aChangeViewSet);
-    m_rViewData.GetDocShell().PostPaintGridAll();
+    m_rViewData.GetDocShell()->PostPaintGridAll();
     response(RET_OK);
 }
 
diff --git a/sc/source/ui/miscdlgs/instbdlg.cxx 
b/sc/source/ui/miscdlgs/instbdlg.cxx
index 1945b9ce9470..3dfa986be326 100644
--- a/sc/source/ui/miscdlgs/instbdlg.cxx
+++ b/sc/source/ui/miscdlgs/instbdlg.cxx
@@ -93,7 +93,7 @@ void ScInsertTableDlg::Init_Impl( bool bFromFile )
         m_xEdName->set_sensitive(false);
     }
 
-    bool bShared = rViewData.GetDocShell().IsDocShared();
+    bool bShared = rViewData.GetDocShell() && 
rViewData.GetDocShell()->IsDocShared();
 
     if ( !bFromFile || bShared )
     {
diff --git a/sc/source/ui/miscdlgs/optsolver.cxx 
b/sc/source/ui/miscdlgs/optsolver.cxx
index fa0f00f54aac..070298e6aec9 100644
--- a/sc/source/ui/miscdlgs/optsolver.cxx
+++ b/sc/source/ui/miscdlgs/optsolver.cxx
@@ -138,13 +138,13 @@ IMPL_LINK(ScCursorRefEdit, KeyInputHdl, const KeyEvent&, 
rKEvt, bool)
 }
 
 ScOptSolverDlg::ScOptSolverDlg(SfxBindings* pB, SfxChildWindow* pCW, 
weld::Window* pParent,
-                               ScDocShell& rDocSh, const ScAddress& aCursorPos)
+                               ScDocShell* pDocSh, const ScAddress& aCursorPos)
     : ScAnyRefDlgController(pB, pCW, pParent, 
u"modules/scalc/ui/solverdlg.ui"_ustr, u"SolverDialog"_ustr)
     , maInputError(ScResId(STR_INVALIDINPUT))
     , maConditionError(ScResId(STR_INVALIDCONDITION))
 
-    , mrDocShell(rDocSh)
-    , mrDoc(rDocSh.GetDocument())
+    , mpDocShell(pDocSh)
+    , mrDoc(pDocSh->GetDocument())
     , mnCurTab(aCursorPos.Tab())
     , mbDlgLostFocus(false)
     , nScrollPos(0)
@@ -948,7 +948,7 @@ bool ScOptSolverDlg::CallSolver()       // return true -> 
close dialog after cal
 
     ReadConditions();
 
-    rtl::Reference<ScModelObj> xDocument( mrDocShell.GetModel() );
+    rtl::Reference<ScModelObj> xDocument( mpDocShell->GetModel() );
 
     ScRange aObjRange;
     if ( !ParseRef( aObjRange, m_xEdObjectiveCell->GetText(), false ) )
@@ -1153,15 +1153,15 @@ bool ScOptSolverDlg::CallSolver()       // return true 
-> close dialog after cal
         uno::Sequence<double> aSolution = xSolver->getSolution();
         if ( aSolution.getLength() == nVarCount )
         {
-            mrDocShell.LockPaint();
-            ScDocFunc &rFunc = mrDocShell.GetDocFunc();
+            mpDocShell->LockPaint();
+            ScDocFunc &rFunc = mpDocShell->GetDocFunc();
             for (nVarPos=0; nVarPos<nVarCount; ++nVarPos)
             {
                 ScAddress aCellPos;
                 ScUnoConversion::FillScAddress(aCellPos, aVariables[nVarPos]);
                 rFunc.SetValueCell(aCellPos, aSolution[nVarPos], false);
             }
-            mrDocShell.UnlockPaint();
+            mpDocShell->UnlockPaint();
         }
         //! else error?
 
@@ -1190,15 +1190,15 @@ bool ScOptSolverDlg::CallSolver()       // return true 
-> close dialog after cal
 
     if ( bRestore )         // restore old values
     {
-        mrDocShell.LockPaint();
-        ScDocFunc &rFunc = mrDocShell.GetDocFunc();
+        mpDocShell->LockPaint();
+        ScDocFunc &rFunc = mpDocShell->GetDocFunc();
         for (nVarPos=0; nVarPos<nVarCount; ++nVarPos)
         {
             ScAddress aCellPos;
             ScUnoConversion::FillScAddress( aCellPos, aVariables[nVarPos] );
             rFunc.SetValueCell(aCellPos, aOldValues[nVarPos], false);
         }
-        mrDocShell.UnlockPaint();
+        mpDocShell->UnlockPaint();
     }
 
     // Generate sensitivity report if user wants it
@@ -1236,7 +1236,7 @@ bool ScOptSolverDlg::CallSolver()       // return true -> 
close dialog after cal
             }
 
             // Insert new sheet to the document and start writing the report
-            ScDocFunc &rFunc = mrDocShell.GetDocFunc();
+            ScDocFunc &rFunc = mpDocShell->GetDocFunc();
             rFunc.InsertTable(mnCurTab + 1, sNewTabName, false, false);
             SCTAB nReportTab;
             if (!mrDoc.GetTable(sNewTabName, nReportTab))
@@ -1248,7 +1248,7 @@ bool ScOptSolverDlg::CallSolver()       // return true -> 
close dialog after cal
             // Used to input data in the new sheet
             ScAddress aOutputAddress(0, 0, nReportTab);
             ScAddress::Details mAddressDetails(mrDoc, aOutputAddress);
-            AddressWalkerWriter aOutput(aOutputAddress, mrDocShell, mrDoc,
+            AddressWalkerWriter aOutput(aOutputAddress, mpDocShell, mrDoc,
                                         
formula::FormulaGrammar::mergeToGrammar(formula::FormulaGrammar::GRAM_ENGLISH, 
mAddressDetails.eConv));
             aOutput.writeBoldString(ScResId(STR_SENSITIVITY_TITLE));
             aOutput.newLine();
diff --git a/sc/source/ui/miscdlgs/sharedocdlg.cxx 
b/sc/source/ui/miscdlgs/sharedocdlg.cxx
index cff5871f6e89..072e83562707 100644
--- a/sc/source/ui/miscdlgs/sharedocdlg.cxx
+++ b/sc/source/ui/miscdlgs/sharedocdlg.cxx
@@ -55,11 +55,13 @@ ScShareDocumentDlg::ScShareDocumentDlg(weld::Window* 
pParent, ScViewData& rViewD
     , m_aStrNoUserData(ScResId(STR_NO_USER_DATA_AVAILABLE))
     , m_aStrUnknownUser(ScResId(STR_UNKNOWN_USER_CONFLICT))
     , m_aStrExclusiveAccess(ScResId(STR_EXCLUSIVE_ACCESS))
-    , mrDocShell(rViewData.GetDocShell())
+    , mpDocShell(rViewData.GetDocShell())
     , m_xCbShare(m_xBuilder->weld_check_button(u"share"_ustr))
     , m_xFtWarning(m_xBuilder->weld_label(u"warning"_ustr))
     , m_xLbUsers(m_xBuilder->weld_tree_view(u"users"_ustr))
 {
+    OSL_ENSURE( mpDocShell, "ScShareDocumentDlg CTOR: mpDocShell is null!" );
+
     std::vector<int> aWidths
     {
         o3tl::narrowing<int>(m_xLbUsers->get_approximate_digit_width() * 25)
@@ -69,7 +71,7 @@ ScShareDocumentDlg::ScShareDocumentDlg(weld::Window* pParent, 
ScViewData& rViewD
     m_xLbUsers->set_size_request(-1, m_xLbUsers->get_height_rows(9));
     m_xLbUsers->connect_size_allocate(LINK(this, ScShareDocumentDlg, 
SizeAllocated));
 
-    bool bIsDocShared = mrDocShell.IsDocShared();
+    bool bIsDocShared = mpDocShell && mpDocShell->IsDocShared();
     m_xCbShare->set_active(bIsDocShared);
     m_xCbShare->connect_toggled( LINK( this, ScShareDocumentDlg, ToggleHandle 
) );
     m_xFtWarning->set_sensitive(bIsDocShared);
@@ -95,11 +97,16 @@ bool ScShareDocumentDlg::IsShareDocumentChecked() const
 
 void ScShareDocumentDlg::UpdateView()
 {
-    if ( mrDocShell.IsDocShared() )
+    if ( !mpDocShell )
+    {
+        return;
+    }
+
+    if ( mpDocShell->IsDocShared() )
     {
         try
         {
-            ::svt::ShareControlFile aControlFile( 
mrDocShell.GetSharedFileURL() );
+            ::svt::ShareControlFile aControlFile( 
mpDocShell->GetSharedFileURL() );
             std::vector<LockFileEntry> aUsersData = 
aControlFile.GetUsersData();
             sal_Int32 nLength = aUsersData.size();
 
@@ -185,7 +192,7 @@ void ScShareDocumentDlg::UpdateView()
         }
         aUser += " " + m_aStrExclusiveAccess;
 
-        uno::Reference<document::XDocumentProperties> xDocProps = 
mrDocShell.GetModel()->getDocumentProperties();
+        uno::Reference<document::XDocumentProperties> xDocProps = 
mpDocShell->GetModel()->getDocumentProperties();
 
         util::DateTime uDT(xDocProps->getModificationDate());
         DateTime aDateTime(uDT);
diff --git a/sc/source/ui/namedlg/namedefdlg.cxx 
b/sc/source/ui/namedlg/namedefdlg.cxx
index 93edb5b83adb..09ed2ebf5304 100644
--- a/sc/source/ui/namedlg/namedefdlg.cxx
+++ b/sc/source/ui/namedlg/namedefdlg.cxx
@@ -30,7 +30,7 @@ ScNameDefDlg::ScNameDefDlg( SfxBindings* pB, SfxChildWindow* 
pCW, weld::Window*
     : ScAnyRefDlgController( pB, pCW, pParent, 
u"modules/scalc/ui/definename.ui"_ustr, u"DefineNameDialog"_ustr)
     , mbUndo( bUndo )
     , mrDoc(rViewData.GetDocument())
-    , mrDocShell ( rViewData.GetDocShell() )
+    , mpDocShell ( rViewData.GetDocShell() )
     , maCursorPos( aCursorPos )
     , maGlobalNameStr  ( ScResId(STR_GLOBAL_SCOPE) )
     , maErrInvalidNameStr( ScResId(STR_ERR_NAME_INVALID))
@@ -267,15 +267,15 @@ void ScNameDefDlg::AddPushed()
 
                 assert( pNewEntry);     // undo of no insertion smells fishy
                 if (pNewEntry)
-                    mrDocShell.GetUndoManager()->AddUndoAction(
-                            std::make_unique<ScUndoAddRangeData>( mrDocShell, 
pNewEntry, nTab) );
+                    mpDocShell->GetUndoManager()->AddUndoAction(
+                            std::make_unique<ScUndoAddRangeData>( *mpDocShell, 
pNewEntry, nTab) );
 
                 // set table stream invalid, otherwise RangeName won't be 
saved if no other
                 // call invalidates the stream
                 if (nTab != -1)
                     mrDoc.SetStreamValid(nTab, false);
                 SfxGetpApp()->Broadcast( SfxHint( SfxHintId::ScAreasChanged ) 
);
-                mrDocShell.SetDocumentModified();
+                mpDocShell->SetDocumentModified();
                 Close();
             }
             else
diff --git a/sc/source/ui/undo/undocell.cxx b/sc/source/ui/undo/undocell.cxx
index c55d5b6b5a54..a17110edcdcb 100644
--- a/sc/source/ui/undo/undocell.cxx
+++ b/sc/source/ui/undo/undocell.cxx
@@ -632,7 +632,7 @@ void ScUndoPrintZoom::Repeat(SfxRepeatTarget& rTarget)
     {
         ScTabViewShell& rViewShell = pViewTarget->GetViewShell();
         ScViewData& rViewData = rViewShell.GetViewData();
-        rViewData.GetDocShell().SetPrintZoom( rViewData.CurrentTabForData(), 
nNewScale, nNewPages );
+        rViewData.GetDocShell()->SetPrintZoom( rViewData.CurrentTabForData(), 
nNewScale, nNewPages );
     }
 }
 
diff --git a/sc/source/ui/unoobj/dispuno.cxx b/sc/source/ui/unoobj/dispuno.cxx
index eb52ab1ca59c..c5edbabfd5e1 100644
--- a/sc/source/ui/unoobj/dispuno.cxx
+++ b/sc/source/ui/unoobj/dispuno.cxx
@@ -211,7 +211,7 @@ void SAL_CALL ScDispatch::dispatch( const util::URL& aURL,
         ScViewData& rViewData = pViewShell->GetViewData();
         ScAddress aPos( rViewData.GetCurX(), rViewData.GetCurY(), 
rViewData.CurrentTabForData() );
 
-        ScDBDocFunc aFunc( rViewData.GetDocShell() );
+        ScDBDocFunc aFunc( *rViewData.GetDocShell() );
         aFunc.DoImportUno( aPos, aArgs );
         bDone = true;
     }
diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx
index a001f4930815..2924e0615b60 100644
--- a/sc/source/ui/unoobj/docuno.cxx
+++ b/sc/source/ui/unoobj/docuno.cxx
@@ -1087,8 +1087,8 @@ bool ScModelObj::isMimeTypeSupported()
 
 static void lcl_sendLOKDocumentBackground(const ScViewData* pViewData)
 {
-    ScDocShell& rDocSh = pViewData->GetDocShell();
-    ScDocument& rDoc = rDocSh.GetDocument();
+    ScDocShell* pDocSh = pViewData->GetDocShell();
+    ScDocument& rDoc = pDocSh->GetDocument();
     const SfxPoolItem& 
rItem(rDoc.getCellAttributeHelper().getDefaultCellAttribute().GetItem(ATTR_BACKGROUND));
     const SvxBrushItem& rBackground = static_cast<const SvxBrushItem&>(rItem);
     const Color& rColor = rBackground.GetColor();
diff --git a/sc/source/ui/unoobj/viewuno.cxx b/sc/source/ui/unoobj/viewuno.cxx
index bc6fbb4d61c0..34384201c7f1 100644
--- a/sc/source/ui/unoobj/viewuno.cxx
+++ b/sc/source/ui/unoobj/viewuno.cxx
@@ -286,15 +286,15 @@ uno::Reference<table::XCellRange> SAL_CALL 
ScViewPaneBase::getReferredCells()
     SolarMutexGuard aGuard;
     if (pViewShell)
     {
-        ScDocShell& rDocSh = pViewShell->GetViewData().GetDocShell();
+        ScDocShell* pDocSh = pViewShell->GetViewData().GetDocShell();
 
         table::CellRangeAddress aAdr(getVisibleRange());        //! helper 
function with ScRange?
         ScRange aRange( static_cast<SCCOL>(aAdr.StartColumn), 
static_cast<SCROW>(aAdr.StartRow), aAdr.Sheet,
                         static_cast<SCCOL>(aAdr.EndColumn), 
static_cast<SCROW>(aAdr.EndRow), aAdr.Sheet );
         if ( aRange.aStart == aRange.aEnd )
-            return new ScCellObj( &rDocSh, aRange.aStart );
+            return new ScCellObj( pDocSh, aRange.aStart );
         else
-            return new ScCellRangeObj( &rDocSh, aRange );
+            return new ScCellRangeObj( pDocSh, aRange );
     }
 
     return nullptr;
@@ -510,9 +510,9 @@ void SAL_CALL ScTabViewObj::release() noexcept
     SfxBaseController::release();
 }
 
-static void lcl_CallActivate( ScDocShell& rDocSh, SCTAB nTab, ScSheetEventId 
nEvent )
+static void lcl_CallActivate( ScDocShell* pDocSh, SCTAB nTab, ScSheetEventId 
nEvent )
 {
-    ScDocument& rDoc = rDocSh.GetDocument();
+    ScDocument& rDoc = pDocSh->GetDocument();
     // when deleting a sheet, nPreviousTab can be invalid
     // (could be handled with reference updates)
     if (!rDoc.HasTable(nTab))
@@ -528,7 +528,7 @@ static void lcl_CallActivate( ScDocShell& rDocSh, SCTAB 
nTab, ScSheetEventId nEv
             uno::Sequence<uno::Any> aParams;
             uno::Sequence<sal_Int16> aOutArgsIndex;
             uno::Sequence<uno::Any> aOutArgs;
-            /*ErrCode eRet =*/ rDocSh.CallXScript( *pScript, aParams, aRet, 
aOutArgsIndex, aOutArgs );
+            /*ErrCode eRet =*/ pDocSh->CallXScript( *pScript, aParams, aRet, 
aOutArgsIndex, aOutArgs );
         }
     }
 
@@ -551,13 +551,13 @@ void ScTabViewObj::SheetChanged( bool bSameTabButMoved )
         return;
 
     ScViewData& rViewData = GetViewShell()->GetViewData();
-    ScDocShell& rDocSh = rViewData.GetDocShell();
+    ScDocShell* pDocSh = rViewData.GetDocShell();
     if (!aActivationListeners.empty())
     {
         sheet::ActivationEvent aEvent;
         uno::Reference< sheet::XSpreadsheetView > xView(this);
         aEvent.Source.set(xView, uno::UNO_QUERY);
-        aEvent.ActiveSheet = new ScTableSheetObj(&rDocSh, 
rViewData.CurrentTabForData());
+        aEvent.ActiveSheet = new ScTableSheetObj(pDocSh, 
rViewData.CurrentTabForData());
         // Listener's handler may remove it from the listeners list
         for (size_t i = aActivationListeners.size(); i > 0; --i)
         {
@@ -577,8 +577,8 @@ void ScTabViewObj::SheetChanged( bool bSameTabButMoved )
     SCTAB nNewTab = rViewData.CurrentTabForData();
     if ( !bSameTabButMoved && (nNewTab != nPreviousTab) )
     {
-        lcl_CallActivate( rDocSh, nPreviousTab, ScSheetEventId::UNFOCUS );
-        lcl_CallActivate( rDocSh, nNewTab, ScSheetEventId::FOCUS );
+        lcl_CallActivate( pDocSh, nPreviousTab, ScSheetEventId::UNFOCUS );
+        lcl_CallActivate( pDocSh, nNewTab, ScSheetEventId::FOCUS );
     }
     nPreviousTab = nNewTab;
 }
@@ -700,7 +700,7 @@ sal_Bool SAL_CALL ScTabViewObj::select( const uno::Any& 
aSelection )
     if (pRangesImp)                                     // Cell ranges
     {
         ScViewData& rViewData = pViewSh->GetViewData();
-        if ( &rViewData.GetDocShell() == pRangesImp->GetDocShell() )
+        if ( rViewData.GetDocShell() == pRangesImp->GetDocShell() )
         {
             //  perhaps remove drawing selection first
             //  (MarkListHasChanged removes sheet selection)
@@ -742,7 +742,7 @@ sal_Bool SAL_CALL ScTabViewObj::select( const uno::Any& 
aSelection )
                 pViewSh->InitOwnBlockMode( rFirst );    /* TODO: or even the 
overall range? */
                 rViewData.GetMarkData().MarkFromRangeList( rRanges, true );
                 pViewSh->MarkDataChanged();
-                rViewData.GetDocShell().PostPaintGridAll();   // Marks 
(old&new)
+                rViewData.GetDocShell()->PostPaintGridAll();   // Marks 
(old&new)
                 pViewSh->AlignToCursor( rFirst.aStart.Col(), 
rFirst.aStart.Row(),
                                             SC_FOLLOW_JUMP );
                 pViewSh->SetCursor( rFirst.aStart.Col(), rFirst.aStart.Row() );
@@ -876,7 +876,7 @@ uno::Any SAL_CALL ScTabViewObj::getSelection()
         //  otherwise sheet (cell) selection
 
         ScViewData& rViewData = pViewSh->GetViewData();
-        ScDocShell& rDocSh = rViewData.GetDocShell();
+        ScDocShell* pDocSh = rViewData.GetDocShell();
 
         const ScMarkData& rMark = rViewData.GetMarkData();
         SCTAB nTabs = rMark.GetSelectCount();
@@ -886,7 +886,7 @@ uno::Any SAL_CALL ScTabViewObj::getSelection()
         if ( nTabs == 1 && (eMarkType == SC_MARK_SIMPLE) )
         {
             // tdf#154803 - check if range is entirely merged
-            ScDocument& rDoc = rDocSh.GetDocument();
+            ScDocument& rDoc = pDocSh->GetDocument();
             const ScMergeAttr& rMergeAttr = rDoc.GetAttr(aRange.aStart, 
ATTR_MERGE);
             SCCOL nColSpan = 1;
             SCROW nRowSpan = 1;
@@ -899,14 +899,14 @@ uno::Any SAL_CALL ScTabViewObj::getSelection()
             if (aRange.aStart == aRange.aEnd
                 || (aRange.aEnd.Col() - aRange.aStart.Col() == nColSpan - 1
                     && aRange.aEnd.Row() - aRange.aStart.Row() == nRowSpan - 
1))
-                pObj = new ScCellObj( &rDocSh, aRange.aStart );
+                pObj = new ScCellObj( pDocSh, aRange.aStart );
             else
-                pObj = new ScCellRangeObj( &rDocSh, aRange );
+                pObj = new ScCellRangeObj( pDocSh, aRange );
         }
         else if ( nTabs == 1 && (eMarkType == SC_MARK_SIMPLE_FILTERED) )
         {
             ScMarkData aFilteredMark( rMark );
-            ScViewUtil::UnmarkFiltered( aFilteredMark, rDocSh.GetDocument());
+            ScViewUtil::UnmarkFiltered( aFilteredMark, pDocSh->GetDocument());
             ScRangeList aRangeList;
             aFilteredMark.FillRangeListWithMarks( &aRangeList, false);
             // Theoretically a selection may start and end on a filtered row.
@@ -915,19 +915,19 @@ uno::Any SAL_CALL ScTabViewObj::getSelection()
                 case 0:
                     // No unfiltered row, we have to return some object, so
                     // here is one with no ranges.
-                    pObj = new ScCellRangesObj( &rDocSh, aRangeList );
+                    pObj = new ScCellRangesObj( pDocSh, aRangeList );
                     break;
                 case 1:
                     {
                         const ScRange& rRange = aRangeList[ 0 ];
                         if (rRange.aStart == rRange.aEnd)
-                            pObj = new ScCellObj( &rDocSh, rRange.aStart );
+                            pObj = new ScCellObj( pDocSh, rRange.aStart );
                         else
-                            pObj = new ScCellRangeObj( &rDocSh, rRange );
+                            pObj = new ScCellRangeObj( pDocSh, rRange );
                     }
                     break;
                 default:
-                    pObj = new ScCellRangesObj( &rDocSh, aRangeList );
+                    pObj = new ScCellRangesObj( pDocSh, aRangeList );
             }
         }
         else            //  multiselection
@@ -940,7 +940,7 @@ uno::Any SAL_CALL ScTabViewObj::getSelection()
             if ( nTabs > 1 )
                 rMark.ExtendRangeListTables( xRanges.get() );
 
-            pObj = new ScCellRangesObj( &rDocSh, *xRanges );
+            pObj = new ScCellRangesObj( pDocSh, *xRanges );
         }
 
         if ( !rMark.IsMarked() && !rMark.IsMultiMarked() )
@@ -957,8 +957,8 @@ uno::Any SAL_CALL ScTabViewObj::getSelection()
 
 uno::Any SAL_CALL ScTabViewObj::getSelectionFromString( const OUString& 
aStrRange )
 {
-    ScDocShell& rDocSh = GetViewShell()->GetViewData().GetDocShell();
-    const sal_Int16 nTabCount = rDocSh.GetDocument().GetTableCount();
+    ScDocShell* pDocSh = GetViewShell()->GetViewData().GetDocShell();
+    const sal_Int16 nTabCount = pDocSh->GetDocument().GetTableCount();
 
     StringRangeEnumerator aRangeEnum(aStrRange , 0, nTabCount-1);
 
@@ -976,7 +976,7 @@ uno::Any SAL_CALL ScTabViewObj::getSelectionFromString( 
const OUString& aStrRang
         ++aIter;
     }
 
-    rtl::Reference<ScCellRangesBase> pObj = new ScCellRangesObj(&rDocSh, 
*aRangeList);
+    rtl::Reference<ScCellRangesBase> pObj = new ScCellRangesObj(pDocSh, 
*aRangeList);
 
     // SetCursorOnly tells the range the specific cells selected are 
irrelevant - maybe could rename?
     pObj->SetCursorOnly(true);
@@ -1089,7 +1089,7 @@ uno::Reference<sheet::XSpreadsheet> SAL_CALL 
ScTabViewObj::getActiveSheet()
     {
         ScViewData& rViewData = pViewSh->GetViewData();
         SCTAB nTab = rViewData.CurrentTabForData();
-        return new ScTableSheetObj( &rViewData.GetDocShell(), nTab );
+        return new ScTableSheetObj( rViewData.GetDocShell(), nTab );
     }
     return nullptr;
 }
@@ -1107,7 +1107,7 @@ void SAL_CALL ScTabViewObj::setActiveSheet( const 
uno::Reference<sheet::XSpreads
     //  XSpreadsheet and ScCellRangesBase -> has to be the same sheet
 
     ScCellRangesBase* pRangesImp = dynamic_cast<ScCellRangesBase*>( 
xActiveSheet.get() );
-    if ( pRangesImp && &pViewSh->GetViewData().GetDocShell() == 
pRangesImp->GetDocShell() )
+    if ( pRangesImp && pViewSh->GetViewData().GetDocShell() == 
pRangesImp->GetDocShell() )
     {
         const ScRangeList& rRanges = pRangesImp->GetRangeList();
         if ( rRanges.size() == 1 )
@@ -1132,7 +1132,7 @@ uno::Reference< uno::XInterface > 
ScTabViewObj::GetClickedObject(const Point& rP
         rData.GetPosFromPixel( rPoint.X(), rPoint.Y(), eSplitMode, nX, nY);
 
         ScAddress aCellPos (nX, nY, nTab);
-        rtl::Reference<ScCellObj> pCellObj = new 
ScCellObj(&rData.GetDocShell(), aCellPos);
-e 
... etc. - the rest is truncated

Reply via email to