sc: prefix members of ScDocShell

Change-Id: I7c2a4e5e850b26da515719f7df869f12c49b0ad3
Reviewed-on: https://gerrit.libreoffice.org/55148
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Henry Castro <hcastro@collabora.com>
diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx
index 362ddbd..d32eb81 100644
--- a/sc/source/ui/docshell/docsh.cxx
+++ b/sc/source/ui/docshell/docsh.cxx
@@ -209,7 +209,7 @@ void ScDocShell::FillClass( SvGlobalName* pClassName,

std::set<Color> ScDocShell::GetDocColors()
{
    return aDocument.GetDocColors();
    return m_aDocument.GetDocColors();
}

void ScDocShell::DoEnterHandler()
@@ -239,16 +239,16 @@ HiddenInformation ScDocShell::GetHiddenInformationState( HiddenInformation nStat

    if ( nStates & HiddenInformation::RECORDEDCHANGES )
    {
        if ( aDocument.GetChangeTrack() && aDocument.GetChangeTrack()->GetFirst() )
        if ( m_aDocument.GetChangeTrack() && m_aDocument.GetChangeTrack()->GetFirst() )
          nState |= HiddenInformation::RECORDEDCHANGES;
    }
    if ( nStates & HiddenInformation::NOTES )
    {
        SCTAB nTableCount = aDocument.GetTableCount();
        SCTAB nTableCount = m_aDocument.GetTableCount();
        bool bFound = false;
        for (SCTAB nTab = 0; nTab < nTableCount && !bFound; ++nTab)
        {
            if (aDocument.HasTabNotes(nTab)) //TODO:
            if (m_aDocument.HasTabNotes(nTab)) //TODO:
                bFound = true;
        }

@@ -261,17 +261,17 @@ HiddenInformation ScDocShell::GetHiddenInformationState( HiddenInformation nStat

void ScDocShell::BeforeXMLLoading()
{
    aDocument.EnableIdle(false);
    m_aDocument.EnableIdle(false);

    // prevent unnecessary broadcasts and updates
    OSL_ENSURE(pModificator == nullptr, "The Modificator should not exist");
    pModificator = new ScDocShellModificator( *this );
    OSL_ENSURE(m_pModificator == nullptr, "The Modificator should not exist");
    m_pModificator = new ScDocShellModificator( *this );

    aDocument.SetImportingXML( true );
    aDocument.EnableExecuteLink( false );   // #i101304# to be safe, prevent nested loading from external references
    aDocument.EnableUndo( false );
    m_aDocument.SetImportingXML( true );
    m_aDocument.EnableExecuteLink( false );   // #i101304# to be safe, prevent nested loading from external references
    m_aDocument.EnableUndo( false );
    // prevent unnecessary broadcasts and "half way listeners"
    aDocument.SetInsertingFromOtherDoc( true );
    m_aDocument.SetInsertingFromOtherDoc( true );
}

void ScDocShell::AfterXMLLoading(bool bRet)
@@ -280,22 +280,22 @@ void ScDocShell::AfterXMLLoading(bool bRet)
    {
        UpdateLinks();
        // don't prevent establishing of listeners anymore
        aDocument.SetInsertingFromOtherDoc( false );
        m_aDocument.SetInsertingFromOtherDoc( false );
        if ( bRet )
        {
            ScChartListenerCollection* pChartListener = aDocument.GetChartListenerCollection();
            ScChartListenerCollection* pChartListener = m_aDocument.GetChartListenerCollection();
            if (pChartListener)
                pChartListener->UpdateDirtyCharts();

            // #95582#; set the table names of linked tables to the new path
            SCTAB nTabCount = aDocument.GetTableCount();
            SCTAB nTabCount = m_aDocument.GetTableCount();
            for (SCTAB i = 0; i < nTabCount; ++i)
            {
                if (aDocument.IsLinked( i ))
                if (m_aDocument.IsLinked( i ))
                {
                    OUString aName;
                    aDocument.GetName(i, aName);
                    OUString aLinkTabName = aDocument.GetLinkTab(i);
                    m_aDocument.GetName(i, aName);
                    OUString aLinkTabName = m_aDocument.GetLinkTab(i);
                    sal_Int32 nLinkTabNameLength = aLinkTabName.getLength();
                    sal_Int32 nNameLength = aName.getLength();
                    if (nLinkTabNameLength < nNameLength)
@@ -326,8 +326,8 @@ void ScDocShell::AfterXMLLoading(bool bRet)
                                    (aName[nIndex - 1] == '#') && // before the table name should be the # char
                                    !aINetURLObject.HasError()) // the docname should be a valid URL
                                {
                                    aName = ScGlobal::GetDocTabName( aDocument.GetLinkDoc( i ), aDocument.GetLinkTab( i ) );
                                    aDocument.RenameTab(i, aName, true/*bExternalDocument*/);
                                    aName = ScGlobal::GetDocTabName( m_aDocument.GetLinkDoc( i ), m_aDocument.GetLinkTab( i ) );
                                    m_aDocument.RenameTab(i, aName, true/*bExternalDocument*/);
                                }
                                // else;  nothing has to happen, because it is a user given name
                            }
@@ -341,7 +341,7 @@ void ScDocShell::AfterXMLLoading(bool bRet)

            // #i94570# DataPilot table names have to be unique, or the tables can't be accessed by API.
            // If no name (or an invalid name, skipped in ScXMLDataPilotTableContext::EndElement) was set, create a new name.
            ScDPCollection* pDPCollection = aDocument.GetDPCollection();
            ScDPCollection* pDPCollection = m_aDocument.GetDPCollection();
            if ( pDPCollection )
            {
                size_t nDPCount = pDPCollection->GetCount();
@@ -355,31 +355,31 @@ void ScDocShell::AfterXMLLoading(bool bRet)
        }
    }
    else
        aDocument.SetInsertingFromOtherDoc( false );
        m_aDocument.SetInsertingFromOtherDoc( false );

    aDocument.SetImportingXML( false );
    aDocument.EnableExecuteLink( true );
    aDocument.EnableUndo( true );
    bIsEmpty = false;
    m_aDocument.SetImportingXML( false );
    m_aDocument.EnableExecuteLink( true );
    m_aDocument.EnableUndo( true );
    m_bIsEmpty = false;

    if (pModificator)
    if (m_pModificator)
    {
        ScDocument::HardRecalcState eRecalcState = aDocument.GetHardRecalcState();
        ScDocument::HardRecalcState eRecalcState = m_aDocument.GetHardRecalcState();
        // Temporarily set hard-recalc to prevent calling
        // ScFormulaCell::Notify() during destruction of the Modificator which
        // will set the cells dirty.
        if (eRecalcState == ScDocument::HardRecalcState::OFF)
            aDocument.SetHardRecalcState(ScDocument::HardRecalcState::TEMPORARY);
        delete pModificator;
        pModificator = nullptr;
        aDocument.SetHardRecalcState(eRecalcState);
            m_aDocument.SetHardRecalcState(ScDocument::HardRecalcState::TEMPORARY);
        delete m_pModificator;
        m_pModificator = nullptr;
        m_aDocument.SetHardRecalcState(eRecalcState);
    }
    else
    {
        OSL_FAIL("The Modificator should exist");
    }

    aDocument.EnableIdle(true);
    m_aDocument.EnableIdle(true);
}

namespace {
@@ -474,7 +474,7 @@ public:

bool ScDocShell::LoadXML( SfxMedium* pLoadMedium, const css::uno::Reference< css::embed::XStorage >& xStor )
{
    LoadMediumGuard aLoadGuard(&aDocument);
    LoadMediumGuard aLoadGuard(&m_aDocument);

    //  MacroCallMode is no longer needed, state is kept in SfxObjectShell now

@@ -486,7 +486,7 @@ bool ScDocShell::LoadXML( SfxMedium* pLoadMedium, const css::uno::Reference< css

    bool bRet = false;
    ErrCode nError = ERRCODE_NONE;
    aDocument.LockAdjustHeight();
    m_aDocument.LockAdjustHeight();
    if (GetCreateMode() == SfxObjectCreateMode::ORGANIZER)
        bRet = aImport.Import(ImportFlags::Styles, nError);
    else
@@ -511,7 +511,7 @@ bool ScDocShell::LoadXML( SfxMedium* pLoadMedium, const css::uno::Reference< css
    if (nRecalcMode == RECALC_ASK)
    {
        OUString sProductName(utl::ConfigManager::getProductName());
        if (aDocument.IsUserInteractionEnabled() && xDocProps->getGenerator().indexOf(sProductName) == -1)
        if (m_aDocument.IsUserInteractionEnabled() && xDocProps->getGenerator().indexOf(sProductName) == -1)
        {
            // Generator is not LibreOffice.  Ask if the user wants to perform
            // full re-calculation.
@@ -547,18 +547,18 @@ bool ScDocShell::LoadXML( SfxMedium* pLoadMedium, const css::uno::Reference< css
    else
    {
        // still need to recalc volatile formula cells.
        aDocument.Broadcast(ScHint(SfxHintId::ScDataChanged, BCA_BRDCST_ALWAYS));
        m_aDocument.Broadcast(ScHint(SfxHintId::ScDataChanged, BCA_BRDCST_ALWAYS));
    }

    AfterXMLLoading(bRet);

    aDocument.UnlockAdjustHeight();
    m_aDocument.UnlockAdjustHeight();
    return bRet;
}

bool ScDocShell::SaveXML( SfxMedium* pSaveMedium, const css::uno::Reference< css::embed::XStorage >& xStor )
{
    aDocument.EnableIdle(false);
    m_aDocument.EnableIdle(false);

    ScXMLImportWrapper aImport(*this, pSaveMedium, xStor);
    bool bRet(false);
@@ -567,7 +567,7 @@ bool ScDocShell::SaveXML( SfxMedium* pSaveMedium, const css::uno::Reference< css
    else
        bRet = aImport.Export(true);

    aDocument.EnableIdle(true);
    m_aDocument.EnableIdle(true);

    return bRet;
}
@@ -597,8 +597,8 @@ bool ScDocShell::SaveCurrentChart( SfxMedium& rMedium )

bool ScDocShell::Load( SfxMedium& rMedium )
{
    LoadMediumGuard aLoadGuard(&aDocument);
    ScRefreshTimerProtector aProt( aDocument.GetRefreshTimerControlAddress() );
    LoadMediumGuard aLoadGuard(&m_aDocument);
    ScRefreshTimerProtector aProt( m_aDocument.GetRefreshTimerControlAddress() );

    //  only the latin script language is loaded
    //  -> initialize the others from options (before loading)
@@ -608,8 +608,8 @@ bool ScDocShell::Load( SfxMedium& rMedium )
    // for tdf#99729 (if required, it will be overridden in *::ReadUserDataSequence())
    if (IsOwnStorageFormat(rMedium))
    {
        if (aDocument.GetDrawLayer())
            aDocument.GetDrawLayer()->SetAnchoredTextOverflowLegacy(true);
        if (m_aDocument.GetDrawLayer())
            m_aDocument.GetDrawLayer()->SetAnchoredTextOverflowLegacy(true);
    }

    GetUndoManager()->Clear();
@@ -623,17 +623,17 @@ bool ScDocShell::Load( SfxMedium& rMedium )
        if (GetMedium())
        {
            const SfxUInt16Item* pUpdateDocItem = SfxItemSet::GetItem<SfxUInt16Item>(rMedium.GetItemSet(), SID_UPDATEDOCMODE, false);
            nCanUpdate = pUpdateDocItem ? pUpdateDocItem->GetValue() : css::document::UpdateDocMode::NO_UPDATE;
            m_nCanUpdate = pUpdateDocItem ? pUpdateDocItem->GetValue() : css::document::UpdateDocMode::NO_UPDATE;
        }

        {
            //  prepare a valid document for XML filter
            //  (for ConvertFrom, InitNew is called before)
            aDocument.MakeTable(0);
            aDocument.GetStyleSheetPool()->CreateStandardStyles();
            aDocument.UpdStlShtPtrsFrmNms();
            m_aDocument.MakeTable(0);
            m_aDocument.GetStyleSheetPool()->CreateStandardStyles();
            m_aDocument.UpdStlShtPtrsFrmNms();

            if (!mbUcalcTest)
            if (!m_bUcalcTest)
            {
                /* Create styles that are imported through Orcus */

@@ -647,8 +647,8 @@ bool ScDocShell::Load( SfxMedium& rMedium )

                if (pOrcus)
                {
                    pOrcus->importODS_Styles(aDocument, aPath);
                    aDocument.GetStyleSheetPool()->setAllStandard();
                    pOrcus->importODS_Styles(m_aDocument, aPath);
                    m_aDocument.GetStyleSheetPool()->setAllStandard();
                }
            }

@@ -667,9 +667,9 @@ bool ScDocShell::Load( SfxMedium& rMedium )

    // invalidate eventually temporary table areas
    if ( bRet )
        aDocument.InvalidateTableArea();
        m_aDocument.InvalidateTableArea();

    bIsEmpty = false;
    m_bIsEmpty = false;
    FinishedLoading();
    return bRet;
}
@@ -681,7 +681,7 @@ void ScDocShell::Notify( SfxBroadcaster&, const SfxHint& rHint )
    {
        if (pScHint->GetTablesHintId() == SC_TAB_INSERTED)
        {
            uno::Reference< script::vba::XVBAEventProcessor > xVbaEvents = aDocument.GetVbaEventProcessor();
            uno::Reference< script::vba::XVBAEventProcessor > xVbaEvents = m_aDocument.GetVbaEventProcessor();
            if ( xVbaEvents.is() ) try
            {
                uno::Sequence< uno::Any > aArgs( 1 );
@@ -710,9 +710,9 @@ void ScDocShell::Notify( SfxBroadcaster&, const SfxHint& rHint )
        const OUString& aName2 = rStlHint.GetStyle2();
        sal_uInt32 nTimeout = rStlHint.GetTimeout();

        if (!pAutoStyleList)
            pAutoStyleList = new ScAutoStyleList(this);
        pAutoStyleList->AddInitial( aRange, aName1, nTimeout, aName2 );
        if (!m_pAutoStyleList)
            m_pAutoStyleList = new ScAutoStyleList(this);
        m_pAutoStyleList->AddInitial( aRange, aName1, nTimeout, aName2 );
    }
    else if ( dynamic_cast<const SfxEventHint*>(&rHint) )
    {
@@ -922,12 +922,12 @@ void ScDocShell::Notify( SfxBroadcaster&, const SfxHint& rHint )
                                        if ( bSaveToShared )
                                        {
                                            bool bChangedViewSettings = false;
                                            ScChangeViewSettings* pChangeViewSet = aDocument.GetChangeViewSettings();
                                            ScChangeViewSettings* pChangeViewSet = m_aDocument.GetChangeViewSettings();
                                            if ( pChangeViewSet && pChangeViewSet->ShowChanges() )
                                            {
                                                pChangeViewSet->SetShowChanges( false );
                                                pChangeViewSet->SetShowAccepted( false );
                                                aDocument.SetChangeViewSettings( *pChangeViewSet );
                                                m_aDocument.SetChangeViewSettings( *pChangeViewSet );
                                                bChangedViewSettings = true;
                                            }

@@ -953,7 +953,7 @@ void ScDocShell::Notify( SfxBroadcaster&, const SfxHint& rHint )
                                            {
                                                pChangeViewSet->SetShowChanges( true );
                                                pChangeViewSet->SetShowAccepted( true );
                                                aDocument.SetChangeViewSettings( *pChangeViewSet );
                                                m_aDocument.SetChangeViewSettings( *pChangeViewSet );
                                            }
                                        }

@@ -1007,8 +1007,8 @@ void ScDocShell::Notify( SfxBroadcaster&, const SfxHint& rHint )
                    }
#endif

                    if (pSheetSaveData)
                        pSheetSaveData->SetInSupportedSave(true);
                    if (m_pSheetSaveData)
                        m_pSheetSaveData->SetInSupportedSave(true);
                }
                break;
            case SfxEventHintId::SaveAsDoc:
@@ -1030,8 +1030,8 @@ void ScDocShell::Notify( SfxBroadcaster&, const SfxHint& rHint )
                // #i108978# If no event is sent before saving, there will also be no "...DONE" event,
                // and SAVE/SAVEAS can't be distinguished from SAVETO. So stream copying is only enabled
                // if there is a SAVE/SAVEAS/SAVETO event first.
                if (pSheetSaveData)
                    pSheetSaveData->SetInSupportedSave(true);
                if (m_pSheetSaveData)
                    m_pSheetSaveData->SetInSupportedSave(true);
                break;
            case SfxEventHintId::SaveDocDone:
            case SfxEventHintId::SaveAsDocDone:
@@ -1042,8 +1042,8 @@ void ScDocShell::Notify( SfxBroadcaster&, const SfxHint& rHint )
                }
            case SfxEventHintId::SaveToDocDone:
                // only reset the flag, don't use the new positions
                if (pSheetSaveData)
                    pSheetSaveData->SetInSupportedSave(false);
                if (m_pSheetSaveData)
                    m_pSheetSaveData->SetInSupportedSave(false);
                break;
            default:
                {
@@ -1053,7 +1053,7 @@ void ScDocShell::Notify( SfxBroadcaster&, const SfxHint& rHint )
    }
    else if (rHint.GetId() == SfxHintId::TitleChanged) // Without parameter
    {
        aDocument.SetName( SfxShell::GetName() );
        m_aDocument.SetName( SfxShell::GetName() );
        //  RegisterNewTargetNames doesn't exist any longer
        SfxGetpApp()->Broadcast(SfxHint( SfxHintId::ScDocNameChanged )); // Navigator
    }
@@ -1068,7 +1068,7 @@ void ScDocShell::Notify( SfxBroadcaster&, const SfxHint& rHint )
        }
#endif

        if (aDocument.IsClipboardSource())
        if (m_aDocument.IsClipboardSource())
        {
            // Notes copied to the clipboard have a raw SdrCaptionObj pointer
            // copied from this document, forget it as it references this
@@ -1112,8 +1112,8 @@ void ScDocShell::Notify( SfxBroadcaster&, const SfxHint& rHint )
// Load contents for organizer
bool ScDocShell::LoadFrom( SfxMedium& rMedium )
{
    LoadMediumGuard aLoadGuard(&aDocument);
    ScRefreshTimerProtector aProt( aDocument.GetRefreshTimerControlAddress() );
    LoadMediumGuard aLoadGuard(&m_aDocument);
    ScRefreshTimerProtector aProt( m_aDocument.GetRefreshTimerControlAddress() );

    WaitObject aWait( GetActiveDialogParent() );

@@ -1122,7 +1122,7 @@ bool ScDocShell::LoadFrom( SfxMedium& rMedium )
    if (GetMedium())
    {
        const SfxUInt16Item* pUpdateDocItem = SfxItemSet::GetItem<SfxUInt16Item>(rMedium.GetItemSet(), SID_UPDATEDOCMODE, false);
        nCanUpdate = pUpdateDocItem ? pUpdateDocItem->GetValue() : css::document::UpdateDocMode::NO_UPDATE;
        m_nCanUpdate = pUpdateDocItem ? pUpdateDocItem->GetValue() : css::document::UpdateDocMode::NO_UPDATE;
    }

    //  until loading/saving only the styles in XML is implemented,
@@ -1167,12 +1167,12 @@ static void lcl_parseHtmlFilterOption(const OUString& rOption, LanguageType& rLa

bool ScDocShell::ConvertFrom( SfxMedium& rMedium )
{
    LoadMediumGuard aLoadGuard(&aDocument);
    LoadMediumGuard aLoadGuard(&m_aDocument);

    bool bRet = false; // sal_False means user quit!
                           // On error: Set error at stream

    ScRefreshTimerProtector aProt( aDocument.GetRefreshTimerControlAddress() );
    ScRefreshTimerProtector aProt( m_aDocument.GetRefreshTimerControlAddress() );

    GetUndoManager()->Clear();

@@ -1191,7 +1191,7 @@ bool ScDocShell::ConvertFrom( SfxMedium& rMedium )
    rMedium.GetPhysicalName();  //! Call CreateFileStream directly, if available

    const SfxUInt16Item* pUpdateDocItem = SfxItemSet::GetItem<SfxUInt16Item>(rMedium.GetItemSet(), SID_UPDATEDOCMODE, false);
    nCanUpdate = pUpdateDocItem ? pUpdateDocItem->GetValue() : css::document::UpdateDocMode::NO_UPDATE;
    m_nCanUpdate = pUpdateDocItem ? pUpdateDocItem->GetValue() : css::document::UpdateDocMode::NO_UPDATE;

    std::shared_ptr<const SfxFilter> pFilter = rMedium.GetFilter();
    if (pFilter)
@@ -1201,7 +1201,7 @@ bool ScDocShell::ConvertFrom( SfxMedium& rMedium )
        bool bCalc3 = aFltName == "StarCalc 3.0";
        bool bCalc4 = aFltName == "StarCalc 4.0";
        if (!bCalc3 && !bCalc4)
            aDocument.SetInsertingFromOtherDoc( true );
            m_aDocument.SetInsertingFromOtherDoc( true );

        if (aFltName == pFilterXML)
            bRet = LoadXML( &rMedium, nullptr );
@@ -1223,7 +1223,7 @@ bool ScDocShell::ConvertFrom( SfxMedium& rMedium )
                sItStr = ScGlobal::GetCharsetString( RTL_TEXTENCODING_IBM_437 );
            }

            ErrCode eError = ScFormatFilter::Get().ScImportLotus123( rMedium, &aDocument,
            ErrCode eError = ScFormatFilter::Get().ScImportLotus123( rMedium, &m_aDocument,
                                                ScGlobal::GetCharsetValue(sItStr));
            if (eError != ERRCODE_NONE)
            {
@@ -1254,13 +1254,13 @@ bool ScDocShell::ConvertFrom( SfxMedium& rMedium )

            MakeDrawLayer(); //! In the filter
            CalcOutputFactor(); // prepare update of row height
            ErrCode eError = ScFormatFilter::Get().ScImportExcel( rMedium, &aDocument, eFormat );
            aDocument.UpdateFontCharSet();
            if ( aDocument.IsChartListenerCollectionNeedsUpdate() )
                aDocument.UpdateChartListenerCollection(); //! For all imports?
            ErrCode eError = ScFormatFilter::Get().ScImportExcel( rMedium, &m_aDocument, eFormat );
            m_aDocument.UpdateFontCharSet();
            if ( m_aDocument.IsChartListenerCollectionNeedsUpdate() )
                m_aDocument.UpdateChartListenerCollection(); //! For all imports?

            // all graphics objects must have names
            aDocument.EnsureGraphicNames();
            m_aDocument.EnsureGraphicNames();

            if (eError == SCWARN_IMPORT_RANGE_OVERFLOW)
            {
@@ -1282,7 +1282,7 @@ bool ScDocShell::ConvertFrom( SfxMedium& rMedium )
            if (!pOrcus)
                return false;

            bRet = pOrcus->importGnumeric(aDocument, rMedium);
            bRet = pOrcus->importGnumeric(m_aDocument, rMedium);
        }
        else if (aFltName == "MS Excel 2003 XML Orcus")
        {
@@ -1290,7 +1290,7 @@ bool ScDocShell::ConvertFrom( SfxMedium& rMedium )
            if (!pOrcus)
                return false;

            bRet = pOrcus->importExcel2003XML(aDocument, rMedium);
            bRet = pOrcus->importExcel2003XML(m_aDocument, rMedium);
        }
        else if (aFltName == pFilterAscii)
        {
@@ -1322,7 +1322,7 @@ bool ScDocShell::ConvertFrom( SfxMedium& rMedium )

            if( ! rMedium.IsStorage() )
            {
                ScImportExport  aImpEx( &aDocument );
                ScImportExport  aImpEx( &m_aDocument );
                aImpEx.SetExtOptions( aOptions );

                SvStream* pInStream = rMedium.GetInStream();
@@ -1332,9 +1332,9 @@ bool ScDocShell::ConvertFrom( SfxMedium& rMedium )
                    pInStream->Seek( 0 );
                    bRet = aImpEx.ImportStream( *pInStream, rMedium.GetBaseURL(), SotClipboardFormatId::STRING );
                    eError = bRet ? ERRCODE_NONE : SCERR_IMPORT_CONNECT;
                    aDocument.StartAllListeners();
                    m_aDocument.StartAllListeners();
                    sc::SetFormulaDirtyContext aCxt;
                    aDocument.SetAllFormulasDirty(aCxt);
                    m_aDocument.SetAllFormulasDirty(aCxt);

                    // The same resulting name has to be handled in
                    // ScExternalRefCache::initializeDoc() and related, hence
@@ -1346,7 +1346,7 @@ bool ScDocShell::ConvertFrom( SfxMedium& rMedium )
                    // corresponding places of the external references
                    // manager/cache. Likely then we'd also need a method to
                    // compose a name excluding such characters.
                    aDocument.RenameTab( 0, INetURLObject( rMedium.GetName()).GetBase(), true/*bExternalDocument*/);
                    m_aDocument.RenameTab( 0, INetURLObject( rMedium.GetName()).GetBase(), true/*bExternalDocument*/);

                    bOverflowRow = aImpEx.IsOverflowRow();
                    bOverflowCol = aImpEx.IsOverflowCol();
@@ -1434,7 +1434,7 @@ bool ScDocShell::ConvertFrom( SfxMedium& rMedium )
                    sItStr = ScGlobal::GetCharsetString( RTL_TEXTENCODING_MS_1252 );
                }

                eError = ScFormatFilter::Get().ScImportDif( *pStream, &aDocument, ScAddress(0,0,0),
                eError = ScFormatFilter::Get().ScImportDif( *pStream, &m_aDocument, ScAddress(0,0,0),
                                    ScGlobal::GetCharsetValue(sItStr));
                if (eError != ERRCODE_NONE)
                {
@@ -1458,7 +1458,7 @@ bool ScDocShell::ConvertFrom( SfxMedium& rMedium )
            bOverflowRow = bOverflowCol = bOverflowCell = false;
            if( !rMedium.IsStorage() )
            {
                ScImportExport aImpEx( &aDocument );
                ScImportExport aImpEx( &m_aDocument );

                SvStream* pInStream = rMedium.GetInStream();
                if (pInStream)
@@ -1466,9 +1466,9 @@ bool ScDocShell::ConvertFrom( SfxMedium& rMedium )
                    pInStream->Seek( 0 );
                    bRet = aImpEx.ImportStream( *pInStream, rMedium.GetBaseURL(), SotClipboardFormatId::SYLK );
                    eError = bRet ? ERRCODE_NONE : SCERR_IMPORT_UNKNOWN;
                    aDocument.StartAllListeners();
                    m_aDocument.StartAllListeners();
                    sc::SetFormulaDirtyContext aCxt;
                    aDocument.SetAllFormulasDirty(aCxt);
                    m_aDocument.SetAllFormulasDirty(aCxt);

                    bOverflowRow = aImpEx.IsOverflowRow();
                    bOverflowCol = aImpEx.IsOverflowCol();
@@ -1496,7 +1496,7 @@ bool ScDocShell::ConvertFrom( SfxMedium& rMedium )
        }
        else if (aFltName == pFilterQPro6)
        {
            ErrCode eError = ScFormatFilter::Get().ScImportQuattroPro(rMedium.GetInStream(), &aDocument);
            ErrCode eError = ScFormatFilter::Get().ScImportQuattroPro(rMedium.GetInStream(), &m_aDocument);
            if (eError != ERRCODE_NONE)
            {
                if (!GetError())
@@ -1522,7 +1522,7 @@ bool ScDocShell::ConvertFrom( SfxMedium& rMedium )
                {
                    pInStream->Seek( 0 );
                    ScRange aRange;
                    eError = ScFormatFilter::Get().ScImportRTF( *pInStream, rMedium.GetBaseURL(), &aDocument, aRange );
                    eError = ScFormatFilter::Get().ScImportRTF( *pInStream, rMedium.GetBaseURL(), &m_aDocument, aRange );
                    if (eError != ERRCODE_NONE)
                    {
                        if (!GetError())
@@ -1533,9 +1533,9 @@ bool ScDocShell::ConvertFrom( SfxMedium& rMedium )
                    }
                    else
                        bRet = true;
                    aDocument.StartAllListeners();
                    m_aDocument.StartAllListeners();
                    sc::SetFormulaDirtyContext aCxt;
                    aDocument.SetAllFormulasDirty(aCxt);
                    m_aDocument.SetAllFormulasDirty(aCxt);
                    bSetColWidths = true;
                    bSetRowHeights = true;
                }
@@ -1573,7 +1573,7 @@ bool ScDocShell::ConvertFrom( SfxMedium& rMedium )
                    // HTML does its own ColWidth/RowHeight
                    CalcOutputFactor();
                    SvNumberFormatter aNumFormatter( comphelper::getProcessComponentContext(), eLang);
                    eError = ScFormatFilter::Get().ScImportHTML( *pInStream, rMedium.GetBaseURL(), &aDocument, aRange,
                    eError = ScFormatFilter::Get().ScImportHTML( *pInStream, rMedium.GetBaseURL(), &m_aDocument, aRange,
                                            GetOutputFactor(), !bWebQuery, &aNumFormatter, bDateConvert );
                    if (eError != ERRCODE_NONE)
                    {
@@ -1585,10 +1585,10 @@ bool ScDocShell::ConvertFrom( SfxMedium& rMedium )
                    }
                    else
                        bRet = true;
                    aDocument.StartAllListeners();
                    m_aDocument.StartAllListeners();

                    sc::SetFormulaDirtyContext aCxt;
                    aDocument.SetAllFormulasDirty(aCxt);
                    m_aDocument.SetAllFormulasDirty(aCxt);
                }
                else
                {
@@ -1609,7 +1609,7 @@ bool ScDocShell::ConvertFrom( SfxMedium& rMedium )
        }

        if (!bCalc3)
            aDocument.SetInsertingFromOtherDoc( false );
            m_aDocument.SetInsertingFromOtherDoc( false );
    }
    else
    {
@@ -1625,12 +1625,12 @@ bool ScDocShell::ConvertFrom( SfxMedium& rMedium )
        double nPPTY = ScGlobal::nScreenPPTY * static_cast<double>(aZoom);
        ScopedVclPtrInstance< VirtualDevice > pVirtDev;
        //  all sheets (for Excel import)
        SCTAB nTabCount = aDocument.GetTableCount();
        SCTAB nTabCount = m_aDocument.GetTableCount();
        for (SCTAB nTab=0; nTab<nTabCount; nTab++)
        {
            SCCOL nEndCol;
            SCROW nEndRow;
            aDocument.GetCellArea( nTab, nEndCol, nEndRow );
            m_aDocument.GetCellArea( nTab, nEndCol, nEndRow );
            aColWidthRange.aEnd.SetCol( nEndCol );
            aColWidthRange.aEnd.SetRow( nEndRow );
            ScMarkData aMark;
@@ -1645,10 +1645,10 @@ bool ScDocShell::ConvertFrom( SfxMedium& rMedium )
                    if (!bSetSimpleTextColWidths)
                        aColWidthParam[nCol].mbSimpleText = false;

                    sal_uInt16 nWidth = aDocument.GetOptimalColWidth(
                    sal_uInt16 nWidth = m_aDocument.GetOptimalColWidth(
                        nCol, nTab, pVirtDev, nPPTX, nPPTY, aZoom, aZoom, false, &aMark,
                        &aColWidthParam[nCol] );
                    aDocument.SetColWidth( nCol, nTab,
                    m_aDocument.SetColWidth( nCol, nTab,
                        nWidth + static_cast<sal_uInt16>(ScGlobal::nLastColWidthExtra) );
                }
            }
@@ -1658,14 +1658,14 @@ bool ScDocShell::ConvertFrom( SfxMedium& rMedium )
        {
            // Update all rows in all tables.
            ScSizeDeviceProvider aProv(this);
            ScDocRowHeightUpdater aUpdater(aDocument, aProv.GetDevice(), aProv.GetPPTX(), aProv.GetPPTY(), nullptr);
            ScDocRowHeightUpdater aUpdater(m_aDocument, aProv.GetDevice(), aProv.GetPPTX(), aProv.GetPPTY(), nullptr);
            aUpdater.update();
        }
        else if (!aRecalcRowRangesArray.empty())
        {
            // Update only specified row ranges for better performance.
            ScSizeDeviceProvider aProv(this);
            ScDocRowHeightUpdater aUpdater(aDocument, aProv.GetDevice(), aProv.GetPPTX(), aProv.GetPPTY(), &aRecalcRowRangesArray);
            ScDocRowHeightUpdater aUpdater(m_aDocument, aProv.GetDevice(), aProv.GetPPTX(), aProv.GetPPTY(), &aRecalcRowRangesArray);
            aUpdater.update();
        }
    }
@@ -1673,9 +1673,9 @@ bool ScDocShell::ConvertFrom( SfxMedium& rMedium )

    // invalidate eventually temporary table areas
    if ( bRet )
        aDocument.InvalidateTableArea();
        m_aDocument.InvalidateTableArea();

    bIsEmpty = false;
    m_bIsEmpty = false;

    return bRet;
}
@@ -1695,22 +1695,22 @@ bool ScDocShell::LoadExternal( SfxMedium& rMed )
        const OUString& rFilterName = pFilter->GetName();
        if (rFilterName == "gnumeric")
        {
            if (!pOrcus->importGnumeric(aDocument, rMed))
            if (!pOrcus->importGnumeric(m_aDocument, rMed))
                return false;
        }
        else if (rFilterName == "csv")
        {
            if (!pOrcus->importCSV(aDocument, rMed))
            if (!pOrcus->importCSV(m_aDocument, rMed))
                return false;
        }
        else if (rFilterName == "xlsx")
        {
            if (!pOrcus->importXLSX(aDocument, rMed))
            if (!pOrcus->importXLSX(m_aDocument, rMed))
                return false;
        }
        else if (rFilterName == "ods")
        {
            if (!pOrcus->importODS(aDocument, rMed))
            if (!pOrcus->importODS(m_aDocument, rMed))
                return false;
        }

@@ -1726,19 +1726,19 @@ ScDocShell::PrepareSaveGuard::PrepareSaveGuard( ScDocShell& rDocShell )
{
    // DoEnterHandler not here (because of AutoSave), is in ExecuteSave.

    ScChartListenerCollection* pCharts = mrDocShell.aDocument.GetChartListenerCollection();
    ScChartListenerCollection* pCharts = mrDocShell.m_aDocument.GetChartListenerCollection();
    if (pCharts)
        pCharts->UpdateDirtyCharts();                           // Charts to be updated.
    mrDocShell.aDocument.StopTemporaryChartLock();
    if (mrDocShell.pAutoStyleList)
        mrDocShell.pAutoStyleList->ExecuteAllNow();             // Execute template timeouts now.
    if (mrDocShell.aDocument.HasExternalRefManager())
    mrDocShell.m_aDocument.StopTemporaryChartLock();
    if (mrDocShell.m_pAutoStyleList)
        mrDocShell.m_pAutoStyleList->ExecuteAllNow();             // Execute template timeouts now.
    if (mrDocShell.m_aDocument.HasExternalRefManager())
    {
        ScExternalRefManager* pRefMgr = mrDocShell.aDocument.GetExternalRefManager();
        ScExternalRefManager* pRefMgr = mrDocShell.m_aDocument.GetExternalRefManager();
        if (pRefMgr && pRefMgr->hasExternalData())
        {
            pRefMgr->setAllCacheTableReferencedStati( false);
            mrDocShell.aDocument.MarkUsedExternalReferences();  // Mark tables of external references to be written.
            mrDocShell.m_aDocument.MarkUsedExternalReferences();  // Mark tables of external references to be written.
        }
    }
    if (mrDocShell.GetCreateMode()== SfxObjectCreateMode::STANDARD)
@@ -1747,9 +1747,9 @@ ScDocShell::PrepareSaveGuard::PrepareSaveGuard( ScDocShell& rDocShell )

ScDocShell::PrepareSaveGuard::~PrepareSaveGuard()
{
    if (mrDocShell.aDocument.HasExternalRefManager())
    if (mrDocShell.m_aDocument.HasExternalRefManager())
    {
        ScExternalRefManager* pRefMgr = mrDocShell.aDocument.GetExternalRefManager();
        ScExternalRefManager* pRefMgr = mrDocShell.m_aDocument.GetExternalRefManager();
        if (pRefMgr && pRefMgr->hasExternalData())
        {
            // Prevent accidental data loss due to lack of knowledge.
@@ -1760,7 +1760,7 @@ ScDocShell::PrepareSaveGuard::~PrepareSaveGuard()

bool ScDocShell::Save()
{
    ScRefreshTimerProtector aProt( aDocument.GetRefreshTimerControlAddress() );
    ScRefreshTimerProtector aProt( m_aDocument.GetRefreshTimerControlAddress() );

    PrepareSaveGuard aPrepareGuard( *this);

@@ -1820,18 +1820,18 @@ bool ScDocShell::SaveAs( SfxMedium& rMedium )
        if (!aRel.isEmpty())
        {
            // Directory path will change before and after the save.
            aDocument.InvalidateStreamOnSave();
            m_aDocument.InvalidateStreamOnSave();
        }
    }

    ScTabViewShell* pViewShell = GetBestViewShell();
    bool bNeedsRehash = ScPassHashHelper::needsPassHashRegen(aDocument, PASSHASH_SHA1);
    bool bNeedsRehash = ScPassHashHelper::needsPassHashRegen(m_aDocument, PASSHASH_SHA1);
    if (bNeedsRehash)
        // legacy xls hash double-hashed by SHA1 is also supported.
        bNeedsRehash = ScPassHashHelper::needsPassHashRegen(aDocument, PASSHASH_XL, PASSHASH_SHA1);
        bNeedsRehash = ScPassHashHelper::needsPassHashRegen(m_aDocument, PASSHASH_XL, PASSHASH_SHA1);
    if (bNeedsRehash)
    {   // SHA256 explicitly supported in ODF 1.2, implicitly in ODF 1.1
        bNeedsRehash = ScPassHashHelper::needsPassHashRegen(aDocument, PASSHASH_SHA256);
        bNeedsRehash = ScPassHashHelper::needsPassHashRegen(m_aDocument, PASSHASH_SHA256);
    }

    if (pViewShell && bNeedsRehash)
@@ -1841,7 +1841,7 @@ bool ScDocShell::SaveAs( SfxMedium& rMedium )
            return false;
    }

    ScRefreshTimerProtector aProt( aDocument.GetRefreshTimerControlAddress() );
    ScRefreshTimerProtector aProt( m_aDocument.GetRefreshTimerControlAddress() );

    PrepareSaveGuard aPrepareGuard( *this);

@@ -2016,13 +2016,13 @@ void ScDocShell::AsciiSave( SvStream& rStream, const ScImportOptions& rAsciiOpt 
    SCTAB nTab = GetSaveTab();
    SCCOL nEndCol;
    SCROW nEndRow;
    aDocument.GetCellArea( nTab, nEndCol, nEndRow );
    m_aDocument.GetCellArea( nTab, nEndCol, nEndRow );

    ScProgress aProgress( this, ScResId( STR_SAVE_DOC ), nEndRow, true );

    OUString aString;

    bool bTabProtect = aDocument.IsTabProtected( nTab );
    bool bTabProtect = m_aDocument.IsTabProtected( nTab );

    SCCOL nCol;
    SCROW nRow;
@@ -2030,9 +2030,9 @@ void ScDocShell::AsciiSave( SvStream& rStream, const ScImportOptions& rAsciiOpt 
    SCROW nNextRow = nStartRow;
    SCCOL nEmptyCol;
    SCROW nEmptyRow;
    SvNumberFormatter& rFormatter = *aDocument.GetFormatTable();
    SvNumberFormatter& rFormatter = *m_aDocument.GetFormatTable();

    ScHorizontalCellIterator aIter( &aDocument, nTab, nStartCol, nStartRow,
    ScHorizontalCellIterator aIter( &m_aDocument, nTab, nStartCol, nStartRow,
        nEndCol, nEndRow );
    ScRefCellValue* pCell;
    while ( ( pCell = aIter.GetNext( nCol, nRow ) ) != nullptr )
@@ -2045,7 +2045,7 @@ void ScDocShell::AsciiSave( SvStream& rStream, const ScImportOptions& rAsciiOpt 
            {   // remaining columns of last row
                if ( bFixedWidth )
                    lcl_ScDocShell_WriteEmptyFixedWidthString( rStream,
                            aDocument, nTab, nEmptyCol );
                            m_aDocument, nTab, nEmptyCol );
                else if ( cDelim != 0 )
                    rStream.WriteUniOrByteChar( cDelim );
            }
@@ -2057,7 +2057,7 @@ void ScDocShell::AsciiSave( SvStream& rStream, const ScImportOptions& rAsciiOpt 
                {
                    if ( bFixedWidth )
                        lcl_ScDocShell_WriteEmptyFixedWidthString( rStream,
                                aDocument, nTab, nEmptyCol );
                                m_aDocument, nTab, nEmptyCol );
                    else if ( cDelim != 0 )
                        rStream.WriteUniOrByteChar( cDelim );
                }
@@ -2067,7 +2067,7 @@ void ScDocShell::AsciiSave( SvStream& rStream, const ScImportOptions& rAsciiOpt 
            {   // empty columns at beginning of row
                if ( bFixedWidth )
                    lcl_ScDocShell_WriteEmptyFixedWidthString( rStream,
                            aDocument, nTab, nEmptyCol );
                            m_aDocument, nTab, nEmptyCol );
                else if ( cDelim != 0 )
                    rStream.WriteUniOrByteChar( cDelim );
            }
@@ -2079,7 +2079,7 @@ void ScDocShell::AsciiSave( SvStream& rStream, const ScImportOptions& rAsciiOpt 
            {   // columns in between
                if ( bFixedWidth )
                    lcl_ScDocShell_WriteEmptyFixedWidthString( rStream,
                            aDocument, nTab, nEmptyCol );
                            m_aDocument, nTab, nEmptyCol );
                else if ( cDelim != 0 )
                    rStream.WriteUniOrByteChar( cDelim );
            }
@@ -2098,7 +2098,7 @@ void ScDocShell::AsciiSave( SvStream& rStream, const ScImportOptions& rAsciiOpt 
        if ( bTabProtect )
        {
            const ScProtectionAttr* pProtAttr =
                aDocument.GetAttr( nCol, nRow, nTab, ATTR_PROTECTION );
                m_aDocument.GetAttr( nCol, nRow, nTab, ATTR_PROTECTION );
            if ( pProtAttr->GetHideCell() ||
                    ( eType == CELLTYPE_FORMULA && bShowFormulas &&
                      pProtAttr->GetHideFormula() ) )
@@ -2126,16 +2126,16 @@ void ScDocShell::AsciiSave( SvStream& rStream, const ScImportOptions& rAsciiOpt 
                    }
                    else if (pCell->mpFormula->IsValue())
                    {
                        sal_uInt32 nFormat = aDocument.GetNumberFormat(aPos);
                        sal_uInt32 nFormat = m_aDocument.GetNumberFormat(aPos);
                        if ( bFixedWidth || bSaveAsShown )
                        {
                            Color* pDummy;
                            ScCellFormat::GetString(*pCell, nFormat, aString, &pDummy, rFormatter, &aDocument);
                            ScCellFormat::GetString(*pCell, nFormat, aString, &pDummy, rFormatter, &m_aDocument);
                            bString = bSaveAsShown && rFormatter.IsTextFormat( nFormat);
                        }
                        else
                        {
                            ScCellFormat::GetInputString(*pCell, nFormat, aString, rFormatter, &aDocument);
                            ScCellFormat::GetInputString(*pCell, nFormat, aString, rFormatter, &m_aDocument);
                            bString = false;
                        }
                    }
@@ -2143,9 +2143,9 @@ void ScDocShell::AsciiSave( SvStream& rStream, const ScImportOptions& rAsciiOpt 
                    {
                        if ( bSaveAsShown )
                        {
                            sal_uInt32 nFormat = aDocument.GetNumberFormat(aPos);
                            sal_uInt32 nFormat = m_aDocument.GetNumberFormat(aPos);
                            Color* pDummy;
                            ScCellFormat::GetString(*pCell, nFormat, aString, &pDummy, rFormatter, &aDocument);
                            ScCellFormat::GetString(*pCell, nFormat, aString, &pDummy, rFormatter, &m_aDocument);
                        }
                        else
                            aString = pCell->mpFormula->GetString().getString();
@@ -2156,9 +2156,9 @@ void ScDocShell::AsciiSave( SvStream& rStream, const ScImportOptions& rAsciiOpt 
            case CELLTYPE_STRING :
                if ( bSaveAsShown )
                {
                    sal_uInt32 nFormat = aDocument.GetNumberFormat(aPos);
                    sal_uInt32 nFormat = m_aDocument.GetNumberFormat(aPos);
                    Color* pDummy;
                    ScCellFormat::GetString(*pCell, nFormat, aString, &pDummy, rFormatter, &aDocument);
                    ScCellFormat::GetString(*pCell, nFormat, aString, &pDummy, rFormatter, &m_aDocument);
                }
                else
                    aString = pCell->mpString->getString();
@@ -2167,7 +2167,7 @@ void ScDocShell::AsciiSave( SvStream& rStream, const ScImportOptions& rAsciiOpt 
            case CELLTYPE_EDIT :
                {
                    const EditTextObject* pObj = pCell->mpEditText;
                    EditEngine& rEngine = aDocument.GetEditEngine();
                    EditEngine& rEngine = m_aDocument.GetEditEngine();
                    rEngine.SetText( *pObj);
                    aString = rEngine.GetText();  // including LF
                    bString = true;
@@ -2176,16 +2176,16 @@ void ScDocShell::AsciiSave( SvStream& rStream, const ScImportOptions& rAsciiOpt 
            case CELLTYPE_VALUE :
                {
                    sal_uInt32 nFormat;
                    aDocument.GetNumberFormat( nCol, nRow, nTab, nFormat );
                    m_aDocument.GetNumberFormat( nCol, nRow, nTab, nFormat );
                    if ( bFixedWidth || bSaveAsShown )
                    {
                        Color* pDummy;
                        ScCellFormat::GetString(*pCell, nFormat, aString, &pDummy, rFormatter, &aDocument);
                        ScCellFormat::GetString(*pCell, nFormat, aString, &pDummy, rFormatter, &m_aDocument);
                        bString = bSaveAsShown && rFormatter.IsTextFormat( nFormat);
                    }
                    else
                    {
                        ScCellFormat::GetInputString(*pCell, nFormat, aString, rFormatter, &aDocument);
                        ScCellFormat::GetInputString(*pCell, nFormat, aString, rFormatter, &m_aDocument);
                        bString = false;
                    }
                }
@@ -2199,8 +2199,8 @@ void ScDocShell::AsciiSave( SvStream& rStream, const ScImportOptions& rAsciiOpt 
        if ( bFixedWidth )
        {
            SvxCellHorJustify eHorJust =
                aDocument.GetAttr( nCol, nRow, nTab, ATTR_HOR_JUSTIFY )->GetValue();
            lcl_ScDocShell_GetFixedWidthString( aString, aDocument, nTab, nCol,
                m_aDocument.GetAttr( nCol, nRow, nTab, ATTR_HOR_JUSTIFY )->GetValue();
            lcl_ScDocShell_GetFixedWidthString( aString, m_aDocument, nTab, nCol,
                    !bString, eHorJust );
            rStream.WriteUnicodeOrByteText( aString );
        }
@@ -2322,7 +2322,7 @@ void ScDocShell::AsciiSave( SvStream& rStream, const ScImportOptions& rAsciiOpt 
        {   // remaining empty columns of last row
            if ( bFixedWidth )
                lcl_ScDocShell_WriteEmptyFixedWidthString( rStream,
                        aDocument, nTab, nEmptyCol );
                        m_aDocument, nTab, nEmptyCol );
            else if ( cDelim != 0 )
                rStream.WriteUniOrByteChar( cDelim );
        }
@@ -2335,7 +2335,7 @@ void ScDocShell::AsciiSave( SvStream& rStream, const ScImportOptions& rAsciiOpt 
        {
            if ( bFixedWidth )
                lcl_ScDocShell_WriteEmptyFixedWidthString( rStream,
                        aDocument, nTab, nEmptyCol );
                        m_aDocument, nTab, nEmptyCol );
            else if ( cDelim != 0 )
                rStream.WriteUniOrByteChar( cDelim );
        }
@@ -2348,13 +2348,13 @@ void ScDocShell::AsciiSave( SvStream& rStream, const ScImportOptions& rAsciiOpt 

bool ScDocShell::ConvertTo( SfxMedium &rMed )
{
    ScRefreshTimerProtector aProt( aDocument.GetRefreshTimerControlAddress() );
    ScRefreshTimerProtector aProt( m_aDocument.GetRefreshTimerControlAddress() );

    //  #i6500# don't call DoEnterHandler here (doesn't work with AutoSave),
    //  it's already in ExecuteSave (as for Save and SaveAs)

    if (pAutoStyleList)
        pAutoStyleList->ExecuteAllNow(); // Execute template timeouts now
    if (m_pAutoStyleList)
        m_pAutoStyleList->ExecuteAllNow(); // Execute template timeouts now
    if (GetCreateMode()== SfxObjectCreateMode::STANDARD)
        SfxObjectShell::SetVisArea( tools::Rectangle() ); // Edited normally -> no VisArea

@@ -2378,9 +2378,9 @@ bool ScDocShell::ConvertTo( SfxMedium &rMed )
        bool bDoSave = true;
        if( ScTabViewShell* pViewShell = GetBestViewShell() )
        {
            ScExtDocOptions* pExtDocOpt = aDocument.GetExtDocOptions();
            ScExtDocOptions* pExtDocOpt = m_aDocument.GetExtDocOptions();
            if( !pExtDocOpt )
                aDocument.SetExtDocOptions( pExtDocOpt = new ScExtDocOptions );
                m_aDocument.SetExtDocOptions( pExtDocOpt = new ScExtDocOptions );
            pViewShell->GetViewData().WriteExtOptions( *pExtDocOpt );

            /*  #i104990# If the imported document contains a medium
@@ -2401,7 +2401,7 @@ bool ScDocShell::ConvertTo( SfxMedium &rMed )

            if( bDoSave )
            {
                bool bNeedRetypePassDlg = ScPassHashHelper::needsPassHashRegen( aDocument, PASSHASH_XL );
                bool bNeedRetypePassDlg = ScPassHashHelper::needsPassHashRegen( m_aDocument, PASSHASH_XL );
                bDoSave = !bNeedRetypePassDlg || pViewShell->ExecuteRetypePassDlg( PASSHASH_XL );
            }
        }
@@ -2411,7 +2411,7 @@ bool ScDocShell::ConvertTo( SfxMedium &rMed )
            ExportFormatExcel eFormat = ExpBiff5;
            if( aFltName == pFilterExcel97 || aFltName == pFilterEx97Temp )
                eFormat = ExpBiff8;
            ErrCode eError = ScFormatFilter::Get().ScExportExcel5( rMed, &aDocument, eFormat, RTL_TEXTENCODING_MS_1252 );
            ErrCode eError = ScFormatFilter::Get().ScExportExcel5( rMed, &m_aDocument, eFormat, RTL_TEXTENCODING_MS_1252 );

            if( eError && !GetError() )
                SetError(eError);
@@ -2453,7 +2453,7 @@ bool ScDocShell::ConvertTo( SfxMedium &rMed )
            AsciiSave( *pStream, aOptions );
            bRet = true;

            if (aDocument.GetTableCount() > 1)
            if (m_aDocument.GetTableCount() > 1)
                if (!rMed.GetError())
                    rMed.SetError(SCWARN_EXPORT_ASCII);
        }
@@ -2550,11 +2550,11 @@ bool ScDocShell::ConvertTo( SfxMedium &rMed )
            }

            WaitObject aWait( GetActiveDialogParent() );
            ScFormatFilter::Get().ScExportDif( *pStream, &aDocument, ScAddress(0,0,0),
            ScFormatFilter::Get().ScExportDif( *pStream, &m_aDocument, ScAddress(0,0,0),
                ScGlobal::GetCharsetValue(sItStr) );
            bRet = true;

            if (aDocument.GetTableCount() > 1)
            if (m_aDocument.GetTableCount() > 1)
                if (!rMed.GetError())
                    rMed.SetError(SCWARN_EXPORT_ASCII);
        }
@@ -2568,10 +2568,10 @@ bool ScDocShell::ConvertTo( SfxMedium &rMed )

            SCCOL nEndCol;
            SCROW nEndRow;
            aDocument.GetCellArea( 0, nEndCol, nEndRow );
            m_aDocument.GetCellArea( 0, nEndCol, nEndRow );
            ScRange aRange( 0,0,0, nEndCol,nEndRow,0 );

            ScImportExport aImExport( &aDocument, aRange );
            ScImportExport aImExport( &m_aDocument, aRange );
            aImExport.SetFormulas( true );
            bRet = aImExport.ExportStream( *pStream, rMed.GetBaseURL( true ), SotClipboardFormatId::SYLK );
        }
@@ -2589,7 +2589,7 @@ bool ScDocShell::ConvertTo( SfxMedium &rMed )
                sFilterOptions = static_cast<const SfxStringItem*>(pItem)->GetValue();

            WaitObject aWait(GetActiveDialogParent());
            ScImportExport aImExport(&aDocument);
            ScImportExport aImExport(&m_aDocument);
            aImExport.SetStreamPath(rMed.GetName());
            aImExport.SetFilterOptions(sFilterOptions);
            bRet = aImExport.ExportStream(*pStream, rMed.GetBaseURL(true), SotClipboardFormatId::HTML);
@@ -2644,7 +2644,7 @@ bool ScDocShell::QuerySlotExecutable( sal_uInt16 nSlotId )
    bool bSlotExecutable = true;
    if( nVbaEventId != VBAEventId::NO_EVENT ) try
    {
        uno::Reference< XVBAEventProcessor > xEventProcessor( aDocument.GetVbaEventProcessor(), uno::UNO_QUERY_THROW );
        uno::Reference< XVBAEventProcessor > xEventProcessor( m_aDocument.GetVbaEventProcessor(), uno::UNO_QUERY_THROW );
        xEventProcessor->processVbaEvent( nVbaEventId, aArgs );
    }
    catch( util::VetoException& )
@@ -2675,7 +2675,7 @@ bool ScDocShell::PrepareClose( bool bUI )

        return false;
    }
    if ( aDocument.IsInLinkUpdate() || aDocument.IsInInterpreter() )
    if ( m_aDocument.IsInLinkUpdate() || m_aDocument.IsInInterpreter() )
    {
        ErrorMessage(STR_CLOSE_ERROR_LINK);
        return false;
@@ -2688,7 +2688,7 @@ bool ScDocShell::PrepareClose( bool bUI )
    {
        try
        {
            uno::Reference< script::vba::XVBAEventProcessor > xVbaEvents( aDocument.GetVbaEventProcessor(), uno::UNO_SET_THROW );
            uno::Reference< script::vba::XVBAEventProcessor > xVbaEvents( m_aDocument.GetVbaEventProcessor(), uno::UNO_SET_THROW );
            uno::Sequence< uno::Any > aArgs;
            xVbaEvents->processVbaEvent( script::vba::VBAEventId::WORKBOOK_BEFORECLOSE, aArgs );
        }
@@ -2705,7 +2705,7 @@ bool ScDocShell::PrepareClose( bool bUI )

    bool bRet = SfxObjectShell::PrepareClose( bUI );
    if (bRet) // true == close
        aDocument.EnableIdle(false); // Do not mess around with it anymore!
        m_aDocument.EnableIdle(false); // Do not mess around with it anymore!

    return bRet;
}
@@ -2720,7 +2720,7 @@ void ScDocShell::PrepareReload()
    //  This causes a hang.
    //
    //  Thus: Disconnect the DDE Links of the old Document before Reload
    aDocument.GetDocLinkManager().disconnectDdeLinks();
    m_aDocument.GetDocLinkManager().disconnectDdeLinks();
}

OUString ScDocShell::GetOwnFilterName()
@@ -2784,85 +2784,85 @@ ScDocShell::ScDocShell( const ScDocShell& rShell ) :
    SotObject(),
    SfxObjectShell( rShell.GetCreateMode() ),
    SfxListener(),
    aDocument       ( SCDOCMODE_DOCUMENT, this ),
    aDdeTextFmt(OUString("TEXT")),
    nPrtToScreenFactor( 1.0 ),
    pImpl           ( new DocShell_Impl ),
    bHeaderOn       ( true ),
    bFooterOn       ( true ),
    bIsEmpty        ( true ),
    bIsInUndo       ( false ),
    bDocumentModifiedPending( false ),
    bUpdateEnabled  ( true ),
    mbUcalcTest(rShell.mbUcalcTest),
    nDocumentLock   ( 0 ),
    nCanUpdate (css::document::UpdateDocMode::ACCORDING_TO_CONFIG),
    pOldAutoDBRange ( nullptr ),
    pAutoStyleList  ( nullptr ),
    pPaintLockData  ( nullptr ),
    pSolverSaveData ( nullptr ),
    pSheetSaveData  ( nullptr ),
    mpFormatSaveData( nullptr ),
    pModificator    ( nullptr )
    m_aDocument       ( SCDOCMODE_DOCUMENT, this ),
    m_aDdeTextFmt(OUString("TEXT")),
    m_nPrtToScreenFactor( 1.0 ),
    m_pImpl           ( new DocShell_Impl ),
    m_bHeaderOn       ( true ),
    m_bFooterOn       ( true ),
    m_bIsEmpty        ( true ),
    m_bIsInUndo       ( false ),
    m_bDocumentModifiedPending( false ),
    m_bUpdateEnabled  ( true ),
    m_bUcalcTest(rShell.m_bUcalcTest),
    m_nDocumentLock   ( 0 ),
    m_nCanUpdate (css::document::UpdateDocMode::ACCORDING_TO_CONFIG),
    m_pOldAutoDBRange ( nullptr ),
    m_pAutoStyleList  ( nullptr ),
    m_pPaintLockData  ( nullptr ),
    m_pSolverSaveData ( nullptr ),
    m_pSheetSaveData  ( nullptr ),
    m_pFormatSaveData( nullptr ),
    m_pModificator    ( nullptr )
{
    SetPool( &SC_MOD()->GetPool() );

    bIsInplace = rShell.bIsInplace;
    m_bIsInplace = rShell.m_bIsInplace;

    pDocFunc = CreateDocFunc();
    m_pDocFunc = CreateDocFunc();

    //  SetBaseModel needs exception handling
    ScModelObj::CreateAndSet( this );

    StartListening(*this);
    SfxStyleSheetPool* pStlPool = aDocument.GetStyleSheetPool();
    SfxStyleSheetPool* pStlPool = m_aDocument.GetStyleSheetPool();
    if (pStlPool)
        StartListening(*pStlPool);

    GetPageOnFromPageStyleSet( nullptr, 0, bHeaderOn, bFooterOn );
    GetPageOnFromPageStyleSet( nullptr, 0, m_bHeaderOn, m_bFooterOn );

    // InitItems and CalcOutputFactor are called now in Load/ConvertFrom/InitNew
}

ScDocShell::ScDocShell( const SfxModelFlags i_nSfxCreationFlags ) :
    SfxObjectShell( i_nSfxCreationFlags ),
    aDocument       ( SCDOCMODE_DOCUMENT, this ),
    aDdeTextFmt(OUString("TEXT")),
    nPrtToScreenFactor( 1.0 ),
    pImpl           ( new DocShell_Impl ),
    bHeaderOn       ( true ),
    bFooterOn       ( true ),
    bIsEmpty        ( true ),
    bIsInUndo       ( false ),
    bDocumentModifiedPending( false ),
    bUpdateEnabled  ( true ),
    mbUcalcTest     ( false ),
    nDocumentLock   ( 0 ),
    nCanUpdate (css::document::UpdateDocMode::ACCORDING_TO_CONFIG),
    pOldAutoDBRange ( nullptr ),
    pAutoStyleList  ( nullptr ),
    pPaintLockData  ( nullptr ),
    pSolverSaveData ( nullptr ),
    pSheetSaveData  ( nullptr ),
    mpFormatSaveData( nullptr ),
    pModificator    ( nullptr )
    m_aDocument       ( SCDOCMODE_DOCUMENT, this ),
    m_aDdeTextFmt(OUString("TEXT")),
    m_nPrtToScreenFactor( 1.0 ),
    m_pImpl           ( new DocShell_Impl ),
    m_bHeaderOn       ( true ),
    m_bFooterOn       ( true ),
    m_bIsEmpty        ( true ),
    m_bIsInUndo       ( false ),
    m_bDocumentModifiedPending( false ),
    m_bUpdateEnabled  ( true ),
    m_bUcalcTest     ( false ),
    m_nDocumentLock   ( 0 ),
    m_nCanUpdate (css::document::UpdateDocMode::ACCORDING_TO_CONFIG),
    m_pOldAutoDBRange ( nullptr ),
    m_pAutoStyleList  ( nullptr ),
    m_pPaintLockData  ( nullptr ),
    m_pSolverSaveData ( nullptr ),
    m_pSheetSaveData  ( nullptr ),
    m_pFormatSaveData( nullptr ),
    m_pModificator    ( nullptr )
{
    SetPool( &SC_MOD()->GetPool() );

    bIsInplace = (GetCreateMode() == SfxObjectCreateMode::EMBEDDED);
    m_bIsInplace = (GetCreateMode() == SfxObjectCreateMode::EMBEDDED);
    //  Will be reset if not in place

    pDocFunc = CreateDocFunc();
    m_pDocFunc = CreateDocFunc();

    //  SetBaseModel needs exception handling
    ScModelObj::CreateAndSet( this );

    StartListening(*this);
    SfxStyleSheetPool* pStlPool = aDocument.GetStyleSheetPool();
    SfxStyleSheetPool* pStlPool = m_aDocument.GetStyleSheetPool();
    if (pStlPool)
        StartListening(*pStlPool);

    aDocument.GetDBCollection()->SetRefreshHandler(
    m_aDocument.GetDBCollection()->SetRefreshHandler(
        LINK( this, ScDocShell, RefreshDBDataHdl ) );

    // InitItems and CalcOutputFactor are called now in Load/ConvertFrom/InitNew
@@ -2872,39 +2872,39 @@ ScDocShell::~ScDocShell()
{
    ResetDrawObjectShell(); // If the Drawing Layer still tries to access it, access it

    SfxStyleSheetPool* pStlPool = aDocument.GetStyleSheetPool();
    SfxStyleSheetPool* pStlPool = m_aDocument.GetStyleSheetPool();
    if (pStlPool)
        EndListening(*pStlPool);
    EndListening(*this);

    delete pAutoStyleList;
    delete m_pAutoStyleList;

    SfxApplication *pSfxApp = SfxGetpApp();
    if ( pSfxApp->GetDdeService() ) // Delete DDE for Document
        pSfxApp->RemoveDdeTopic( this );

    delete pDocFunc;
    delete aDocument.mpUndoManager;
    aDocument.mpUndoManager = nullptr;
    delete pImpl;
    delete m_pDocFunc;
    delete m_aDocument.mpUndoManager;
    m_aDocument.mpUndoManager = nullptr;
    delete m_pImpl;

    delete pPaintLockData;
    delete m_pPaintLockData;

    delete pSolverSaveData;
    delete pSheetSaveData;
    delete mpFormatSaveData;
    delete pOldAutoDBRange;
    delete m_pSolverSaveData;
    delete m_pSheetSaveData;
    delete m_pFormatSaveData;
    delete m_pOldAutoDBRange;

    if (pModificator)
    if (m_pModificator)
    {
        OSL_FAIL("The Modificator should not exist");
        delete pModificator;
        delete m_pModificator;
    }
}

::svl::IUndoManager* ScDocShell::GetUndoManager()
{
    return aDocument.GetUndoManager();
    return m_aDocument.GetUndoManager();
}

void ScDocShell::SetModified( bool bModified )
@@ -2922,32 +2922,32 @@ void ScDocShell::SetDocumentModified()
    //  FIXME: Also for SetDrawModified, if Drawing is connected
    //  FIXME: Then own Hint?

    if ( pPaintLockData )
    if ( m_pPaintLockData )
    {
        // #i115009# broadcast BCA_BRDCST_ALWAYS, so a component can read recalculated results
        // of RecalcModeAlways formulas (like OFFSET) after modifying cells
        aDocument.Broadcast(ScHint(SfxHintId::ScDataChanged, BCA_BRDCST_ALWAYS));
        aDocument.InvalidateTableArea();    // #i105279# needed here
        aDocument.BroadcastUno( SfxHint( SfxHintId::DataChanged ) );
        m_aDocument.Broadcast(ScHint(SfxHintId::ScDataChanged, BCA_BRDCST_ALWAYS));
        m_aDocument.InvalidateTableArea();    // #i105279# needed here
        m_aDocument.BroadcastUno( SfxHint( SfxHintId::DataChanged ) );

        pPaintLockData->SetModified(); // Later on ...
        m_pPaintLockData->SetModified(); // Later on ...
        return;
    }

    SetDrawModified();

    if ( aDocument.IsAutoCalcShellDisabled() )
    if ( m_aDocument.IsAutoCalcShellDisabled() )
        SetDocumentModifiedPending( true );
    else
    {
        SetDocumentModifiedPending( false );
        aDocument.InvalidateStyleSheetUsage();
        aDocument.InvalidateTableArea();
        aDocument.InvalidateLastTableOpParams();
        aDocument.Broadcast(ScHint(SfxHintId::ScDataChanged, BCA_BRDCST_ALWAYS));
        if ( aDocument.IsForcedFormulaPending() && aDocument.GetAutoCalc() )
            aDocument.CalcFormulaTree( true );
        aDocument.RefreshDirtyTableColumnNames();
        m_aDocument.InvalidateStyleSheetUsage();
        m_aDocument.InvalidateTableArea();
        m_aDocument.InvalidateLastTableOpParams();
        m_aDocument.Broadcast(ScHint(SfxHintId::ScDataChanged, BCA_BRDCST_ALWAYS));
        if ( m_aDocument.IsForcedFormulaPending() && m_aDocument.GetAutoCalc() )
            m_aDocument.CalcFormulaTree( true );
        m_aDocument.RefreshDirtyTableColumnNames();
        PostDataChanged();

        //  Detective AutoUpdate:
@@ -2955,17 +2955,17 @@ void ScDocShell::SetDocumentModified()
        //  "Trace Error" entries (Trace Error can look completely different
        //  after changes to non-formula cells).

        ScDetOpList* pList = aDocument.GetDetOpList();
        if ( pList && ( aDocument.IsDetectiveDirty() || pList->HasAddError() ) &&
        ScDetOpList* pList = m_aDocument.GetDetOpList();
        if ( pList && ( m_aDocument.IsDetectiveDirty() || pList->HasAddError() ) &&
             pList->Count() && !IsInUndo() && SC_MOD()->GetAppOptions().GetDetectiveAuto() )
        {
            GetDocFunc().DetectiveRefresh(true);    // sal_True = caused by automatic update
        }
        aDocument.SetDetectiveDirty(false);         // always reset, also if not refreshed
        m_aDocument.SetDetectiveDirty(false);         // always reset, also if not refreshed
    }

    // notify UNO objects after BCA_BRDCST_ALWAYS etc.
    aDocument.BroadcastUno( SfxHint( SfxHintId::DataChanged ) );
    m_aDocument.BroadcastUno( SfxHint( SfxHintId::DataChanged ) );
}

/**
@@ -3000,9 +3000,9 @@ void ScDocShell::SetDrawModified()
        pBindings->Invalidate( SID_REPEAT );
    }

    if ( aDocument.IsChartListenerCollectionNeedsUpdate() )
    if ( m_aDocument.IsChartListenerCollectionNeedsUpdate() )
    {
        aDocument.UpdateChartListenerCollection();
        m_aDocument.UpdateChartListenerCollection();
        SfxGetpApp()->Broadcast(SfxHint( SfxHintId::ScDrawChanged ));    // Navigator
    }
    SC_MOD()->AnythingChanged();
@@ -3010,14 +3010,14 @@ void ScDocShell::SetDrawModified()

void ScDocShell::SetInUndo(bool bSet)
{
    bIsInUndo = bSet;
    m_bIsInUndo = bSet;
}

void ScDocShell::GetDocStat( ScDocStat& rDocStat )
{
    SfxPrinter* pPrinter = GetPrinter();

    aDocument.GetDocStat( rDocStat );
    m_aDocument.GetDocStat( rDocStat );
    rDocStat.nPageCount = 0;

    if ( pPrinter )
@@ -3058,24 +3058,24 @@ vcl::Window* ScDocShell::GetActiveDialogParent()

void ScDocShell::SetSolverSaveData( const ScOptSolverSave& rData )
{
    delete pSolverSaveData;
    pSolverSaveData = new ScOptSolverSave( rData );
    delete m_pSolverSaveData;
    m_pSolverSaveData = new ScOptSolverSave( rData );
}

ScSheetSaveData* ScDocShell::GetSheetSaveData()
{
    if (!pSheetSaveData)
        pSheetSaveData = new ScSheetSaveData;
    if (!m_pSheetSaveData)
        m_pSheetSaveData = new ScSheetSaveData;

    return pSheetSaveData;
    return m_pSheetSaveData;
}

ScFormatSaveData* ScDocShell::GetFormatSaveData()
{
    if (!mpFormatSaveData)
        mpFormatSaveData = new ScFormatSaveData;
    if (!m_pFormatSaveData)
        m_pFormatSaveData = new ScFormatSaveData;

    return mpFormatSaveData;
    return m_pFormatSaveData;
}

namespace {
@@ -3215,15 +3215,15 @@ void ScDocShell::ResetKeyBindings( ScOptionsUtil::KeyBindingType eType )

void ScDocShell::UseSheetSaveEntries()
{
    if (pSheetSaveData)
    if (m_pSheetSaveData)
    {
        pSheetSaveData->UseSaveEntries();   // use positions from saved file for next saving
        m_pSheetSaveData->UseSaveEntries();   // use positions from saved file for next saving

        bool bHasEntries = false;
        SCTAB nTabCount = aDocument.GetTableCount();
        SCTAB nTabCount = m_aDocument.GetTableCount();
        SCTAB nTab;
        for (nTab = 0; nTab < nTabCount; ++nTab)
            if (pSheetSaveData->HasStreamPos(nTab))
            if (m_pSheetSaveData->HasStreamPos(nTab))
                bHasEntries = true;

        if (!bHasEntries)
@@ -3231,7 +3231,7 @@ void ScDocShell::UseSheetSaveEntries()
            // if no positions were set (for example, export to other format),
            // reset all "valid" flags
            for (nTab = 0; nTab < nTabCount; ++nTab)
                aDocument.SetStreamValid(nTab, false);
                m_aDocument.SetStreamValid(nTab, false);
        }
    }
}
@@ -3281,14 +3281,14 @@ void ScDocShellModificator::SetDocumentModified()

bool ScDocShell::IsChangeRecording() const
{
    ScChangeTrack* pChangeTrack = aDocument.GetChangeTrack();
    ScChangeTrack* pChangeTrack = m_aDocument.GetChangeTrack();
    return pChangeTrack != nullptr;
}

bool ScDocShell::HasChangeRecordProtection() const
{
    bool bRes = false;
    ScChangeTrack* pChangeTrack = aDocument.GetChangeTrack();
    ScChangeTrack* pChangeTrack = m_aDocument.GetChangeTrack();
    if (pChangeTrack)
        bRes = pChangeTrack->IsProtected();
    return bRes;
@@ -3300,14 +3300,14 @@ void ScDocShell::SetChangeRecording( bool bActivate )

    if (bActivate)
    {
        aDocument.StartChangeTracking();
        m_aDocument.StartChangeTracking();
        ScChangeViewSettings aChangeViewSet;
        aChangeViewSet.SetShowChanges(true);
        aDocument.SetChangeViewSettings(aChangeViewSet);
        m_aDocument.SetChangeViewSettings(aChangeViewSet);
    }
    else
    {
        aDocument.EndChangeTracking();
        m_aDocument.EndChangeTracking();
        PostPaintGridAll();
    }

@@ -3323,7 +3323,7 @@ void ScDocShell::SetChangeRecording( bool bActivate )

void ScDocShell::SetProtectionPassword( const OUString &rNewPassword )
{
    ScChangeTrack* pChangeTrack = aDocument.GetChangeTrack();
    ScChangeTrack* pChangeTrack = m_aDocument.GetChangeTrack();
    if (pChangeTrack)
    {
        bool bProtected = pChangeTrack->IsProtected();
@@ -3353,7 +3353,7 @@ void ScDocShell::SetProtectionPassword( const OUString &rNewPassword )
bool ScDocShell::GetProtectionHash( /*out*/ css::uno::Sequence< sal_Int8 > &rPasswordHash )
{
    bool bRes = false;
    ScChangeTrack* pChangeTrack = aDocument.GetChangeTrack();
    ScChangeTrack* pChangeTrack = m_aDocument.GetChangeTrack();
    if (pChangeTrack && pChangeTrack->IsProtected())
    {
        rPasswordHash = pChangeTrack->GetProtection();
@@ -3364,7 +3364,7 @@ bool ScDocShell::GetProtectionHash( /*out*/ css::uno::Sequence< sal_Int8 > &rPas

void ScDocShell::SetIsInUcalc()
{
    mbUcalcTest = true;
    m_bUcalcTest = true;
}

void ScDocShell::RegisterAutomationWorkbookObject(css::uno::Reference< ooo::vba::excel::XWorkbook > const& xWorkbook)
diff --git a/sc/source/ui/docshell/docsh2.cxx b/sc/source/ui/docshell/docsh2.cxx
index 568e800..e4f4eaa 100644
--- a/sc/source/ui/docshell/docsh2.cxx
+++ b/sc/source/ui/docshell/docsh2.cxx
@@ -43,7 +43,7 @@ bool ScDocShell::InitNew( const uno::Reference < embed::XStorage >& xStor )
{
    bool bRet = SfxObjectShell::InitNew( xStor );

    aDocument.MakeTable(0);
    m_aDocument.MakeTable(0);

    //  Additional tables are created by the first View, if bIsEmpty is still sal_True
    if( bRet )
@@ -57,10 +57,10 @@ bool ScDocShell::InitNew( const uno::Reference < embed::XStorage >& xStor )
    // InitOptions sets the document languages, must be called before CreateStandardStyles
    InitOptions(false);

    aDocument.GetStyleSheetPool()->CreateStandardStyles();
    aDocument.UpdStlShtPtrsFrmNms();
    m_aDocument.GetStyleSheetPool()->CreateStandardStyles();
    m_aDocument.UpdStlShtPtrsFrmNms();

    if (!mbUcalcTest)
    if (!m_bUcalcTest)
    {
        /* Create styles that are imported through Orcus */

@@ -73,8 +73,8 @@ bool ScDocShell::InitNew( const uno::Reference < embed::XStorage >& xStor )
        ScOrcusFilters* pOrcus = ScFormatFilter::Get().GetOrcusFilters();
        if (pOrcus)
        {
            pOrcus->importODS_Styles(aDocument, aPath);
            aDocument.GetStyleSheetPool()->setAllStandard();
            pOrcus->importODS_Styles(m_aDocument, aPath);
            m_aDocument.GetStyleSheetPool()->setAllStandard();
        }
    }

@@ -87,7 +87,7 @@ bool ScDocShell::InitNew( const uno::Reference < embed::XStorage >& xStor )

void ScDocShell::SetEmpty(bool bSet)
{
    bIsEmpty = bSet;
    m_bIsEmpty = bSet;
}

void ScDocShell::InitItems()
@@ -96,7 +96,7 @@ void ScDocShell::InitItems()
    // Printer Options are set in GetPrinter when printing
    UpdateFontList();

    ScDrawLayer* pDrawLayer = aDocument.GetDrawLayer();
    ScDrawLayer* pDrawLayer = m_aDocument.GetDrawLayer();
    if (pDrawLayer)
    {
        PutItem( SvxColorListItem  ( pDrawLayer->GetColorList(), SID_COLOR_TABLE ) );
@@ -108,7 +108,7 @@ void ScDocShell::InitItems()
        PutItem( SvxLineEndListItem ( pDrawLayer->GetLineEndList(), SID_LINEEND_LIST ) );

        // Other modifications after creation of the DrawLayer
        pDrawLayer->SetNotifyUndoActionHdl( LINK( pDocFunc, ScDocFunc, NotifyDrawUndo ) );
        pDrawLayer->SetNotifyUndoActionHdl( LINK( m_pDocFunc, ScDocFunc, NotifyDrawUndo ) );
    }
    else if (!utl::ConfigManager::IsFuzzing())
    {
@@ -117,12 +117,12 @@ void ScDocShell::InitItems()
    }

    if (!utl::ConfigManager::IsFuzzing() &&
        (!aDocument.GetForbiddenCharacters() || !aDocument.IsValidAsianCompression() || !aDocument.IsValidAsianKerning()))
        (!m_aDocument.GetForbiddenCharacters() || !m_aDocument.IsValidAsianCompression() || !m_aDocument.IsValidAsianKerning()))
    {
        //  get settings from SvxAsianConfig
        SvxAsianConfig aAsian;

        if (!aDocument.GetForbiddenCharacters())
        if (!m_aDocument.GetForbiddenCharacters())
        {
            // set forbidden characters if necessary
            uno::Sequence<lang::Locale> aLocales = aAsian.GetStartEndCharLocales();
@@ -141,41 +141,41 @@ void ScDocShell::InitItems()
                    xForbiddenTable->SetForbiddenCharacters( eLang, aForbidden );
                }

                aDocument.SetForbiddenCharacters( xForbiddenTable );
                m_aDocument.SetForbiddenCharacters( xForbiddenTable );
            }
        }

        if ( !aDocument.IsValidAsianCompression() )
        if ( !m_aDocument.IsValidAsianCompression() )
        {
            // set compression mode from configuration if not already set (e.g. XML import)
            aDocument.SetAsianCompression( aAsian.GetCharDistanceCompression() );
            m_aDocument.SetAsianCompression( aAsian.GetCharDistanceCompression() );
        }

        if ( !aDocument.IsValidAsianKerning() )
        if ( !m_aDocument.IsValidAsianKerning() )
        {
            // set asian punctuation kerning from configuration if not already set (e.g. XML import)
            aDocument.SetAsianKerning( !aAsian.IsKerningWesternTextOnly() );    // reversed
            m_aDocument.SetAsianKerning( !aAsian.IsKerningWesternTextOnly() );    // reversed
        }
    }
}

void ScDocShell::ResetDrawObjectShell()
{
    ScDrawLayer* pDrawLayer = aDocument.GetDrawLayer();
    ScDrawLayer* pDrawLayer = m_aDocument.GetDrawLayer();
    if (pDrawLayer)
        pDrawLayer->SetObjectShell( nullptr );
}

ScDrawLayer* ScDocShell::MakeDrawLayer()
{
    ScDrawLayer* pDrawLayer = aDocument.GetDrawLayer();
    ScDrawLayer* pDrawLayer = m_aDocument.GetDrawLayer();
    if (!pDrawLayer)
    {
        aDocument.InitDrawLayer(this);
        pDrawLayer = aDocument.GetDrawLayer();
        m_aDocument.InitDrawLayer(this);
        pDrawLayer = m_aDocument.GetDrawLayer();
        InitItems(); // including Undo and Basic
        Broadcast( SfxHint( SfxHintId::ScDrawLayerNew ) );
        if (nDocumentLock)
        if (m_nDocumentLock)
            pDrawLayer->setLock(true);
    }
    return pDrawLayer;
diff --git a/sc/source/ui/docshell/docsh3.cxx b/sc/source/ui/docshell/docsh3.cxx
index 37c28e0..028e24d 100644
--- a/sc/source/ui/docshell/docsh3.cxx
+++ b/sc/source/ui/docshell/docsh3.cxx
@@ -87,7 +87,7 @@ void ScDocShell::PostDataChanged()
{
    Broadcast( SfxHint( SfxHintId::ScDataChanged ) );
    SfxGetpApp()->Broadcast(SfxHint( SfxHintId::ScAnyDataChanged ));      // Navigator
    aDocument.PrepareFormulaCalc();
    m_aDocument.PrepareFormulaCalc();
    //! notify navigator directly!
}

@@ -114,7 +114,7 @@ void ScDocShell::PostPaint( const ScRangeList& rRanges, PaintPartFlags nPart, sa
        if (!ValidCol(nCol2)) nCol2 = MAXCOL;
        if (!ValidRow(nRow2)) nRow2 = MAXROW;

        if ( pPaintLockData )
        if ( m_pPaintLockData )
        {
            // #i54081# PaintPartFlags::Extras still has to be broadcast because it changes the
            // current sheet if it's invalid. All other flags added to pPaintLockData.
@@ -122,7 +122,7 @@ void ScDocShell::PostPaint( const ScRangeList& rRanges, PaintPartFlags nPart, sa
            if ( nLockPart != PaintPartFlags::NONE )
            {
                //! nExtFlags ???
                pPaintLockData->AddRange( ScRange( nCol1, nRow1, nTab1,
                m_pPaintLockData->AddRange( ScRange( nCol1, nRow1, nTab1,
                                                   nCol2, nRow2, nTab2 ), nLockPart );
            }

@@ -142,7 +142,7 @@ void ScDocShell::PostPaint( const ScRangeList& rRanges, PaintPartFlags nPart, sa

                                                // expand for the merged ones
        if (nExtFlags & SC_PF_TESTMERGE)
            aDocument.ExtendMerge( nCol1, nRow1, nCol2, nRow2, nTab1 );
            m_aDocument.ExtendMerge( nCol1, nRow1, nCol2, nRow2, nTab1 );

        if ( nCol1 != 0 || nCol2 != MAXCOL )
        {
@@ -152,7 +152,7 @@ void ScDocShell::PostPaint( const ScRangeList& rRanges, PaintPartFlags nPart, sa
            //  support of right-aligned text.

            if ( ( nExtFlags & SC_PF_WHOLEROWS ) ||
                 aDocument.HasAttrib( nCol1,nRow1,nTab1,
                 m_aDocument.HasAttrib( nCol1,nRow1,nTab1,
                                      MAXCOL,nRow2,nTab2, HasAttrFlags::Rotate | HasAttrFlags::RightOrCenter ) )
            {
                nCol1 = 0;
@@ -200,7 +200,7 @@ void ScDocShell::PostPaintExtras()
void ScDocShell::UpdatePaintExt( sal_uInt16& rExtFlags, const ScRange& rRange )
{
    if ( ( rExtFlags & SC_PF_LINES ) == 0 &&
         aDocument.HasAttrib( rRange, HasAttrFlags::Lines | HasAttrFlags::Shadow | HasAttrFlags::Conditional ) )
         m_aDocument.HasAttrib( rRange, HasAttrFlags::Lines | HasAttrFlags::Shadow | HasAttrFlags::Conditional ) )
    {
        //  If the range contains lines, shadow or conditional formats,
        //  set SC_PF_LINES to include one extra cell in all directions.
@@ -210,7 +210,7 @@ void ScDocShell::UpdatePaintExt( sal_uInt16& rExtFlags, const ScRange& rRange )

    if ( ( rExtFlags & SC_PF_WHOLEROWS ) == 0 &&
         ( rRange.aStart.Col() != 0 || rRange.aEnd.Col() != MAXCOL ) &&
         aDocument.HasAttrib( rRange, HasAttrFlags::Rotate | HasAttrFlags::RightOrCenter ) )
         m_aDocument.HasAttrib( rRange, HasAttrFlags::Rotate | HasAttrFlags::RightOrCenter ) )
    {
        //  If the range contains (logically) right- or center-aligned cells,
        //  or rotated cells, set SC_PF_WHOLEROWS to paint the whole rows.
@@ -230,23 +230,23 @@ void ScDocShell::UpdatePaintExt( sal_uInt16& rExtFlags, SCCOL nStartCol, SCROW n

void ScDocShell::LockPaint_Impl(bool bDoc)
{
    if ( !pPaintLockData )
        pPaintLockData = new ScPaintLockData;
    pPaintLockData->IncLevel(bDoc);
    if ( !m_pPaintLockData )
        m_pPaintLockData = new ScPaintLockData;
    m_pPaintLockData->IncLevel(bDoc);
}

void ScDocShell::UnlockPaint_Impl(bool bDoc)
{
    if ( pPaintLockData )
    if ( m_pPaintLockData )
    {
        if ( pPaintLockData->GetLevel(bDoc) )
            pPaintLockData->DecLevel(bDoc);
        if (!pPaintLockData->GetLevel(!bDoc) && !pPaintLockData->GetLevel(bDoc))
        if ( m_pPaintLockData->GetLevel(bDoc) )
            m_pPaintLockData->DecLevel(bDoc);
        if (!m_pPaintLockData->GetLevel(!bDoc) && !m_pPaintLockData->GetLevel(bDoc))
        {
            //     Execute Paint now

            ScPaintLockData* pPaint = pPaintLockData;
            pPaintLockData = nullptr;                      // don't continue collecting
            ScPaintLockData* pPaint = m_pPaintLockData;
            m_pPaintLockData = nullptr;                      // don't continue collecting

            ScRangeListRef xRangeList = pPaint->GetRangeList();
            if ( xRangeList.is() )
@@ -276,21 +276,21 @@ void ScDocShell::UnlockPaint_Impl(bool bDoc)

void ScDocShell::LockDocument_Impl(sal_uInt16 nNew)
{
    if (!nDocumentLock)
    if (!m_nDocumentLock)
    {
        ScDrawLayer* pDrawLayer = aDocument.GetDrawLayer();
        ScDrawLayer* pDrawLayer = m_aDocument.GetDrawLayer();
        if (pDrawLayer)
            pDrawLayer->setLock(true);
    }
    nDocumentLock = nNew;
    m_nDocumentLock = nNew;
}

void ScDocShell::UnlockDocument_Impl(sal_uInt16 nNew)
{
    nDocumentLock = nNew;
    if (!nDocumentLock)
    m_nDocumentLock = nNew;
    if (!m_nDocumentLock)
    {
        ScDrawLayer* pDrawLayer = aDocument.GetDrawLayer();
        ScDrawLayer* pDrawLayer = m_aDocument.GetDrawLayer();
        if (pDrawLayer)
            pDrawLayer->setLock(false);
    }
@@ -300,14 +300,14 @@ void ScDocShell::SetLockCount(sal_uInt16 nNew)
{
    if (nNew)                   // set
    {
        if ( !pPaintLockData )
            pPaintLockData = new ScPaintLockData;
        pPaintLockData->SetDocLevel(nNew-1);
        if ( !m_pPaintLockData )
            m_pPaintLockData = new ScPaintLockData;
        m_pPaintLockData->SetDocLevel(nNew-1);
        LockDocument_Impl(nNew);
    }
    else if (pPaintLockData)    // delete
    else if (m_pPaintLockData)    // delete
    {
        pPaintLockData->SetDocLevel(0);  // at unlock, execute immediately
        m_pPaintLockData->SetDocLevel(0);  // at unlock, execute immediately
        UnlockPaint_Impl(true);                 // now
        UnlockDocument_Impl(0);
    }
@@ -326,15 +326,15 @@ void ScDocShell::UnlockPaint()
void ScDocShell::LockDocument()
{
    LockPaint_Impl(true);
    LockDocument_Impl(nDocumentLock + 1);
    LockDocument_Impl(m_nDocumentLock + 1);
}

void ScDocShell::UnlockDocument()
{
    if (nDocumentLock)
    if (m_nDocumentLock)
    {
        UnlockPaint_Impl(true);
        UnlockDocument_Impl(nDocumentLock - 1);
        UnlockDocument_Impl(m_nDocumentLock - 1);
    }
    else
    {
@@ -344,25 +344,25 @@ void ScDocShell::UnlockDocument()

void ScDocShell::SetInplace( bool bInplace )
{
    if (bIsInplace != bInplace)
    if (m_bIsInplace != bInplace)
    {
        bIsInplace = bInplace;
        m_bIsInplace = bInplace;
        CalcOutputFactor();
    }
}

void ScDocShell::CalcOutputFactor()
{
    if (bIsInplace)
    if (m_bIsInplace)
    {
        nPrtToScreenFactor = 1.0;           // otherwise it does not match the inactive display
        m_nPrtToScreenFactor = 1.0;           // otherwise it does not match the inactive display
        return;
    }

    bool bTextWysiwyg = SC_MOD()->GetInputOptions().GetTextWysiwyg();
    if (bTextWysiwyg)
    {
        nPrtToScreenFactor = 1.0;
        m_nPrtToScreenFactor = 1.0;
        return;
    }

@@ -370,7 +370,7 @@ void ScDocShell::CalcOutputFactor()
            "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890123456789");
    long nPrinterWidth = 0;
    long nWindowWidth = 0;
    const ScPatternAttr* pPattern = &aDocument.GetPool()->GetDefaultItem(ATTR_PATTERN);
    const ScPatternAttr* pPattern = &m_aDocument.GetPool()->GetDefaultItem(ATTR_PATTERN);

    vcl::Font aDefFont;
    OutputDevice* pRefDev = GetRefDevice();
@@ -392,11 +392,11 @@ void ScDocShell::CalcOutputFactor()
    nWindowWidth = static_cast<long>( nWindowWidth / ScGlobal::nScreenPPTX * HMM_PER_TWIPS );

    if (nPrinterWidth && nWindowWidth)
        nPrtToScreenFactor = nPrinterWidth / static_cast<double>(nWindowWidth);
        m_nPrtToScreenFactor = nPrinterWidth / static_cast<double>(nWindowWidth);
    else
    {
        OSL_FAIL("GetTextSize returns 0 ??");
        nPrtToScreenFactor = 1.0;
        m_nPrtToScreenFactor = 1.0;
    }
}

@@ -431,30 +431,30 @@ void ScDocShell::InitOptions(bool bForLoading)      // called from InitNew and L
        aDocOpt.SetDate( 30, 12, 1899);
    }

    aDocument.SetDocOptions( aDocOpt );
    aDocument.SetViewOptions( aViewOpt );
    m_aDocument.SetDocOptions( aDocOpt );
    m_aDocument.SetViewOptions( aViewOpt );
    SetFormulaOptions( aFormulaOpt, bForLoading );

    //  print options are now set directly before the printing

    aDocument.SetLanguage( nDefLang, nCjkLang, nCtlLang );
    m_aDocument.SetLanguage( nDefLang, nCjkLang, nCtlLang );
}

Printer* ScDocShell::GetDocumentPrinter()       // for OLE
{
    return aDocument.GetPrinter();
    return m_aDocument.GetPrinter();
}

SfxPrinter* ScDocShell::GetPrinter(bool bCreateIfNotExist)
{
    return aDocument.GetPrinter(bCreateIfNotExist);
    return m_aDocument.GetPrinter(bCreateIfNotExist);
}

void ScDocShell::UpdateFontList()
{
    // pImpl->pFontList = new FontList( GetPrinter(), Application::GetDefaultDevice() );
    pImpl->pFontList.reset(new FontList(GetRefDevice(), nullptr));
    SvxFontListItem aFontListItem( pImpl->pFontList.get(), SID_ATTR_CHAR_FONTLIST );
    m_pImpl->pFontList.reset(new FontList(GetRefDevice(), nullptr));
    SvxFontListItem aFontListItem( m_pImpl->pFontList.get(), SID_ATTR_CHAR_FONTLIST );
    PutItem( aFontListItem );

    CalcOutputFactor();
@@ -462,21 +462,21 @@ void ScDocShell::UpdateFontList()

OutputDevice* ScDocShell::GetRefDevice()
{
    return aDocument.GetRefDevice();
    return m_aDocument.GetRefDevice();
}

sal_uInt16 ScDocShell::SetPrinter( VclPtr<SfxPrinter> const & pNewPrinter, SfxPrinterChangeFlags nDiffFlags )
{
    SfxPrinter *pOld = aDocument.GetPrinter( false );
    SfxPrinter *pOld = m_aDocument.GetPrinter( false );
    if ( pOld && pOld->IsPrinting() )
        return SFX_PRINTERROR_BUSY;

    if (nDiffFlags & SfxPrinterChangeFlags::PRINTER)
    {
        if ( aDocument.GetPrinter() != pNewPrinter )
        if ( m_aDocument.GetPrinter() != pNewPrinter )
        {
            aDocument.SetPrinter( pNewPrinter );
            aDocument.SetPrintOptions();
            m_aDocument.SetPrinter( pNewPrinter );
            m_aDocument.SetPrintOptions();

            // MT: Use UpdateFontList: Will use Printer fonts only if needed!
            /*
@@ -507,7 +507,7 @@ sal_uInt16 ScDocShell::SetPrinter( VclPtr<SfxPrinter> const & pNewPrinter, SfxPr
    }
    else if (nDiffFlags & SfxPrinterChangeFlags::JOBSETUP)
    {
        SfxPrinter* pOldPrinter = aDocument.GetPrinter();
        SfxPrinter* pOldPrinter = m_aDocument.GetPrinter();
        if (pOldPrinter)
        {
            pOldPrinter->SetJobSetup( pNewPrinter->GetJobSetup() );
@@ -515,20 +515,20 @@ sal_uInt16 ScDocShell::SetPrinter( VclPtr<SfxPrinter> const & pNewPrinter, SfxPr
            //  #i6706# Call SetPrinter with the old printer again, so the drawing layer
            //  RefDevice is set (calling ReformatAllTextObjects and rebuilding charts),
            //  because the JobSetup (printer device settings) may affect text layout.
            aDocument.SetPrinter( pOldPrinter );
            m_aDocument.SetPrinter( pOldPrinter );
            CalcOutputFactor();                         // also with the new settings
        }
    }

    if (nDiffFlags & SfxPrinterChangeFlags::OPTIONS)
    {
        aDocument.SetPrintOptions();        //! from new printer ???
        m_aDocument.SetPrintOptions();        //! from new printer ???
    }

    if (nDiffFlags & (SfxPrinterChangeFlags::CHG_ORIENTATION | SfxPrinterChangeFlags::CHG_SIZE))
    {
        OUString aStyle = aDocument.GetPageStyle( GetCurTab() );
        ScStyleSheetPool* pStPl = aDocument.GetStyleSheetPool();
        OUString aStyle = m_aDocument.GetPageStyle( GetCurTab() );
        ScStyleSheetPool* pStPl = m_aDocument.GetStyleSheetPool();
        SfxStyleSheet* pStyleSheet = static_cast<SfxStyleSheet*>(pStPl->Find(aStyle, SfxStyleFamily::Page));
        if (pStyleSheet)
        {
@@ -657,17 +657,17 @@ void ScDocShell::ExecuteChangeCommentDialog( ScChangeAction* pAction, weld::Wind

void ScDocShell::CompareDocument( ScDocument& rOtherDoc )
{
    ScChangeTrack* pTrack = aDocument.GetChangeTrack();
    ScChangeTrack* pTrack = m_aDocument.GetChangeTrack();
    if ( pTrack && pTrack->GetFirst() )
    {
        //! there are changes -> inquiry if needs to be deleted
    }

    aDocument.EndChangeTracking();
    aDocument.StartChangeTracking();
    m_aDocument.EndChangeTracking();
    m_aDocument.StartChangeTracking();

    OUString aOldUser;
    pTrack = aDocument.GetChangeTrack();
    pTrack = m_aDocument.GetChangeTrack();
    if ( pTrack )
    {
        aOldUser = pTrack->GetUser();
@@ -706,9 +706,9 @@ void ScDocShell::CompareDocument( ScDocument& rOtherDoc )
        }
    }

    aDocument.CompareDocument( rOtherDoc );
    m_aDocument.CompareDocument( rOtherDoc );

    pTrack = aDocument.GetChangeTrack();
    pTrack = m_aDocument.GetChangeTrack();
    if ( pTrack )
        pTrack->SetUser( aOldUser );

@@ -774,18 +774,18 @@ void ScDocShell::MergeDocument( ScDocument& rOtherDoc, bool bShared, bool bCheck
    if (!pSourceTrack)
        return;             //! nothing to do - error notification?

    ScChangeTrack* pThisTrack = aDocument.GetChangeTrack();
    ScChangeTrack* pThisTrack = m_aDocument.GetChangeTrack();
    if ( !pThisTrack )
    {   // turn on
        aDocument.StartChangeTracking();
        pThisTrack = aDocument.GetChangeTrack();
        m_aDocument.StartChangeTracking();
        pThisTrack = m_aDocument.GetChangeTrack();
        OSL_ENSURE(pThisTrack,"ChangeTracking not enabled?");
        if ( !bShared )
        {
            // turn on visual RedLining
            ScChangeViewSettings aChangeViewSet;
            aChangeViewSet.SetShowChanges(true);
            aDocument.SetChangeViewSettings(aChangeViewSet);
            m_aDocument.SetChangeViewSettings(aChangeViewSet);
        }
    }

@@ -892,7 +892,7 @@ void ScDocShell::MergeDocument( ScDocument& rOtherDoc, bool bShared, bool bCheck
        bool bMergeAction = false;
        if ( bShared )
        {
            if ( !bCheckDuplicates || !lcl_FindAction( &rOtherDoc, pSourceAction, &aDocument, pFirstSearchAction, pLastSearchAction, bIgnore100Sec ) )
            if ( !bCheckDuplicates || !lcl_FindAction( &rOtherDoc, pSourceAction, &m_aDocument, pFirstSearchAction, pLastSearchAction, bIgnore100Sec ) )
            {
                bMergeAction = true;
            }
@@ -920,7 +920,7 @@ void ScDocShell::MergeDocument( ScDocument& rOtherDoc, bool bShared, bool bCheck
#if OSL_DEBUG_LEVEL > 0
                OUString aValue;
                if ( eSourceType == SC_CAT_CONTENT )
                    static_cast<const ScChangeActionContent*>(pSourceAction)->GetNewString( aValue, &aDocument );
                    static_cast<const ScChangeActionContent*>(pSourceAction)->GetNewString( aValue, &m_aDocument );
                SAL_WARN( "sc", aValue << " omitted");
#endif
            }
@@ -982,7 +982,7 @@ void ScDocShell::MergeDocument( ScDocument& rOtherDoc, bool bShared, bool bCheck
                            OSL_ENSURE( aSourceRange.aStart == aSourceRange.aEnd, "huch?" );
                            ScAddress aPos = aSourceRange.aStart;
                            OUString aValue;
                            static_cast<const ScChangeActionContent*>(pSourceAction)->GetNewString( aValue, &aDocument );
                            static_cast<const ScChangeActionContent*>(pSourceAction)->GetNewString( aValue, &m_aDocument );
                            ScMatrixMode eMatrix = ScMatrixMode::NONE;
                            const ScCellValue& rCell = static_cast<const ScChangeActionContent*>(pSourceAction)->GetNewCell();
                            if (rCell.meType == CELLTYPE_FORMULA)
@@ -1013,7 +1013,7 @@ void ScDocShell::MergeDocument( ScDocument& rOtherDoc, bool bShared, bool bCheck
                        case SC_CAT_INSERT_TABS :
                        {
                            OUString aName;
                            aDocument.CreateValidTabName( aName );
                            m_aDocument.CreateValidTabName( aName );
                            (void)GetDocFunc().InsertTable( aSourceRange.aStart.Tab(), aName, true, false );
                        }
                        break;
@@ -1141,7 +1141,7 @@ bool ScDocShell::MergeSharedDocument( ScDocShell* pSharedDocShell )
        return false;
    }

    ScChangeTrack* pThisTrack = aDocument.GetChangeTrack();
    ScChangeTrack* pThisTrack = m_aDocument.GetChangeTrack();
    if ( !pThisTrack )
    {
        return false;
@@ -1157,7 +1157,7 @@ bool ScDocShell::MergeSharedDocument( ScDocShell* pSharedDocShell )
    // reset show changes
    ScChangeViewSettings aChangeViewSet;
    aChangeViewSet.SetShowChanges( false );
    aDocument.SetChangeViewSettings( aChangeViewSet );
    m_aDocument.SetChangeViewSettings( aChangeViewSet );

    // find first merge action in this document
    bool bIgnore100Sec = !pThisTrack->IsTimeNanoSeconds() || !pSharedTrack->IsTimeNanoSeconds();
@@ -1177,13 +1177,13 @@ bool ScDocShell::MergeSharedDocument( ScDocShell* pSharedDocShell )
            sal_uLong nActStartShared = pSharedAction->GetActionNumber();
            sal_uLong nActEndShared = pSharedTrack->GetActionMax();
            ScDocument* pTmpDoc = new ScDocument;
            for ( sal_Int32 nIndex = 0; nIndex < aDocument.GetTableCount(); ++nIndex )
            for ( sal_Int32 nIndex = 0; nIndex < m_aDocument.GetTableCount(); ++nIndex )
            {
                OUString sTabName;
                pTmpDoc->CreateValidTabName( sTabName );
                pTmpDoc->InsertTab( SC_TAB_APPEND, sTabName );
            }
            aDocument.GetChangeTrack()->Clone( pTmpDoc );
            m_aDocument.GetChangeTrack()->Clone( pTmpDoc );
            ScChangeActionMergeMap aOwnInverseMergeMap;
            pSharedDocShell->MergeDocument( *pTmpDoc, true, true, 0, &aOwnInverseMergeMap, true );
            delete pTmpDoc;
@@ -1225,7 +1225,7 @@ bool ScDocShell::MergeSharedDocument( ScDocShell* pSharedDocShell )

            // clone change track for merging into own document
            pTmpDoc = new ScDocument;
            for ( sal_Int32 nIndex = 0; nIndex < aDocument.GetTableCount(); ++nIndex )
            for ( sal_Int32 nIndex = 0; nIndex < m_aDocument.GetTableCount(); ++nIndex )
            {
                OUString sTabName;
                pTmpDoc->CreateValidTabName( sTabName );
@@ -1270,7 +1270,7 @@ bool ScDocShell::MergeSharedDocument( ScDocShell* pSharedDocShell )
            aChangeViewSet.SetShowAccepted( true );
            aChangeViewSet.SetHasActionRange();
            aChangeViewSet.SetTheActionRange( nStartShared, nEndShared );
            aDocument.SetChangeViewSettings( aChangeViewSet );
            m_aDocument.SetChangeViewSettings( aChangeViewSet );

            // merge own changes back into own document
            sal_uLong nStartOwn = nEndShared + 1;
@@ -1313,7 +1313,7 @@ bool ScDocShell::MergeSharedDocument( ScDocShell* pSharedDocShell )
            aChangeViewSet.SetShowAccepted( true );
            aChangeViewSet.SetHasActionRange();
            aChangeViewSet.SetTheActionRange( nStartShared, nEndShared );
            aDocument.SetChangeViewSettings( aChangeViewSet );
            m_aDocument.SetChangeViewSettings( aChangeViewSet );
        }

        // update view
diff --git a/sc/source/ui/docshell/docsh4.cxx b/sc/source/ui/docshell/docsh4.cxx
index 5d341c6..47992f8e 100644
--- a/sc/source/ui/docshell/docsh4.cxx
+++ b/sc/source/ui/docshell/docsh4.cxx
@@ -116,26 +116,26 @@ using namespace ::com::sun::star;

void ScDocShell::ReloadAllLinks()
{
    aDocument.SetLinkFormulaNeedingCheck(false);
    m_aDocument.SetLinkFormulaNeedingCheck(false);
    getEmbeddedObjectContainer().setUserAllowsLinkUpdate(true);

    ReloadTabLinks();
    vcl::Window *pDialogParent = GetActiveDialogParent();
    aDocument.UpdateExternalRefLinks(pDialogParent);
    m_aDocument.UpdateExternalRefLinks(pDialogParent);

    bool bAnyDde = aDocument.GetDocLinkManager().updateDdeOrOleOrWebServiceLinks(pDialogParent ? pDialogParent->GetFrameWeld() : nullptr);
    bool bAnyDde = m_aDocument.GetDocLinkManager().updateDdeOrOleOrWebServiceLinks(pDialogParent ? pDialogParent->GetFrameWeld() : nullptr);

    if (bAnyDde)
    {
        //  calculate formulas and paint like in the TrackTimeHdl
        aDocument.TrackFormulas();
        m_aDocument.TrackFormulas();
        Broadcast(SfxHint(SfxHintId::ScDataChanged));

        //  Should FID_DATACHANGED become asynchronous some time
        //  (e.g., with Invalidate at Window), an update needs to be forced here.
    }

    aDocument.UpdateAreaLinks();
    m_aDocument.UpdateAreaLinks();
}

IMPL_LINK_NOARG( ScDocShell, ReloadAllLinksHdl, Button*, void )
@@ -153,7 +153,7 @@ void ScDocShell::Execute( SfxRequest& rReq )
{
    const SfxItemSet* pReqArgs = rReq.GetArgs();
    SfxBindings* pBindings = GetViewBindings();
    bool bUndo (aDocument.IsUndoEnabled());
    bool bUndo (m_aDocument.IsUndoEnabled());

    sal_uInt16 nSlot = rReq.GetSlot();
    switch ( nSlot )
@@ -174,13 +174,13 @@ void ScDocShell::Execute( SfxRequest& rReq )
                SCROW nRow = static_cast<const SfxInt32Item*>(pRowItem)->GetValue() - 1;
                SCTAB nTab = static_cast<const SfxInt16Item*>(pTabItem)->GetValue() - 1;

                SCTAB nTabCount = aDocument.GetTableCount();
                SCTAB nTabCount = m_aDocument.GetTableCount();
                if ( ValidCol(nCol) && ValidRow(nRow) && ValidTab(nTab,nTabCount) )
                {
                    if ( aDocument.IsBlockEditable( nTab, nCol,nRow, nCol, nRow ) )
                    if ( m_aDocument.IsBlockEditable( nTab, nCol,nRow, nCol, nRow ) )
                    {
                        OUString aVal = static_cast<const SfxStringItem*>(pTextItem)->GetValue();
                        aDocument.SetString( nCol, nRow, nTab, aVal );
                        m_aDocument.SetString( nCol, nRow, nTab, aVal );

                        PostPaintCell( nCol, nRow, nTab );
                        SetDocumentModified();
@@ -229,11 +229,11 @@ void ScDocShell::Execute( SfxRequest& rReq )
                bool bMakeArea = false;
                if (bIsNewArea)
                {
                    ScDBCollection* pDBColl = aDocument.GetDBCollection();
                    ScDBCollection* pDBColl = m_aDocument.GetDBCollection();
                    if ( !pDBColl || !pDBColl->getNamedDBs().findByUpperName(ScGlobal::pCharClass->uppercase(sTarget)) )
                    {
                        ScAddress aPos;
                        if ( aPos.Parse( sTarget, &aDocument, aDocument.GetAddressConvention() ) & ScRefFlags::VALID )
                        if ( aPos.Parse( sTarget, &m_aDocument, m_aDocument.GetAddressConvention() ) & ScRefFlags::VALID )
                        {
                            bMakeArea = true;
                            if (bUndo)
@@ -352,13 +352,13 @@ void ScDocShell::Execute( SfxRequest& rReq )

                    //! limit always or not at all ???
                    if (!bMultiRange)
                        aDocument.LimitChartArea( nTab, nCol1,nRow1, nCol2,nRow2 );
                        m_aDocument.LimitChartArea( nTab, nCol1,nRow1, nCol2,nRow2 );

                                        // Dialog for column/row headers
                    bool bOk = true;
                    if ( !bAddRange && ( !bColInit || !bRowInit ) )
                    {
                        ScChartPositioner aChartPositioner( &aDocument, nTab, nCol1,nRow1, nCol2,nRow2 );
                        ScChartPositioner aChartPositioner( &m_aDocument, nTab, nCol1,nRow1, nCol2,nRow2 );
                        if (!bColInit)
                            bColHeaders = aChartPositioner.HasColHeaders();
                        if (!bRowInit)
@@ -391,7 +391,7 @@ void ScDocShell::Execute( SfxRequest& rReq )
                                    new ScUndoChartData( this, aChartName, aRangeListRef,
                                                            bColHeaders, bRowHeaders, bAddRange ) );
                            }
                            aDocument.UpdateChartArea( aChartName, aRangeListRef,
                            m_aDocument.UpdateChartArea( aChartName, aRangeListRef,
                                                        bColHeaders, bRowHeaders, bAddRange );
                        }
                        else
@@ -403,7 +403,7 @@ void ScDocShell::Execute( SfxRequest& rReq )
                                    new ScUndoChartData( this, aChartName, aNewRange,
                                                            bColHeaders, bRowHeaders, bAddRange ) );
                            }
                            aDocument.UpdateChartArea( aChartName, aNewRange,
                            m_aDocument.UpdateChartArea( aChartName, aNewRange,
                                                        bColHeaders, bRowHeaders, bAddRange );
                        }
                    }
@@ -427,8 +427,8 @@ void ScDocShell::Execute( SfxRequest& rReq )
                if ( pReqArgs && SfxItemState::SET == pReqArgs->GetItemState( nSlot, true, &pItem ) )
                    bNewVal = static_cast<const SfxBoolItem*>(pItem)->GetValue();
                else
                    bNewVal = !aDocument.GetAutoCalc();     // Toggle for menu
                aDocument.SetAutoCalc( bNewVal );
                    bNewVal = !m_aDocument.GetAutoCalc();     // Toggle for menu
                m_aDocument.SetAutoCalc( bNewVal );
                SetDocumentModified();
                if (pBindings)
                {
@@ -458,9 +458,9 @@ void ScDocShell::Execute( SfxRequest& rReq )
                    nSet=aAppOptions.GetLinkMode();
                }

                if (nCanUpdate == css::document::UpdateDocMode::NO_UPDATE)
                if (m_nCanUpdate == css::document::UpdateDocMode::NO_UPDATE)
                    nSet = LM_NEVER;
                else if (nCanUpdate == css::document::UpdateDocMode::FULL_UPDATE)
                else if (m_nCanUpdate == css::document::UpdateDocMode::FULL_UPDATE)
                    nSet = LM_ALWAYS;

                if (nSet == LM_ALWAYS
@@ -471,7 +471,7 @@ void ScDocShell::Execute( SfxRequest& rReq )
                {
                    nSet = LM_ON_DEMAND;
                }
                if (nCanUpdate == css::document::UpdateDocMode::QUIET_UPDATE
                if (m_nCanUpdate == css::document::UpdateDocMode::QUIET_UPDATE
                    && nSet == LM_ON_DEMAND)
                {
                    nSet = LM_NEVER;
@@ -514,10 +514,10 @@ void ScDocShell::Execute( SfxRequest& rReq )
                //  Is called after loading if there are DB areas with omitted data

                bool bDone = false;
                ScDBCollection* pDBColl = aDocument.GetDBCollection();
                ScDBCollection* pDBColl = m_aDocument.GetDBCollection();

                if ((nCanUpdate != css::document::UpdateDocMode::NO_UPDATE) &&
                   (nCanUpdate != css::document::UpdateDocMode::QUIET_UPDATE))
                if ((m_nCanUpdate != css::document::UpdateDocMode::NO_UPDATE) &&
                   (m_nCanUpdate != css::document::UpdateDocMode::QUIET_UPDATE))
                {
                    ScRange aRange;
                    ScTabViewShell* pViewSh = GetBestViewShell();
@@ -578,7 +578,7 @@ void ScDocShell::Execute( SfxRequest& rReq )
                    //  if not, but then update the dependent formulas
                    //! also for individual ranges, which cannot be updated

                    aDocument.CalcAll();        //! only for the dependent
                    m_aDocument.CalcAll();        //! only for the dependent
                    PostDataChanged();
                }

@@ -681,8 +681,8 @@ void ScDocShell::Execute( SfxRequest& rReq )
        case SID_DOCUMENT_COMPARE:
            {
                bool bDo = true;
                ScChangeTrack* pChangeTrack = aDocument.GetChangeTrack();
                if ( pChangeTrack && !pImpl->bIgnoreLostRedliningWarning )
                ScChangeTrack* pChangeTrack = m_aDocument.GetChangeTrack();
                if ( pChangeTrack && !m_pImpl->bIgnoreLostRedliningWarning )
                {
                    if ( nSlot == SID_DOCUMENT_COMPARE )
                    {   //! old changes trace will be lost
@@ -763,16 +763,16 @@ void ScDocShell::Execute( SfxRequest& rReq )
                        ? sfx2::DocumentInserter::Mode::Compare
                        : sfx2::DocumentInserter::Mode::Merge};
                    // start file dialog asynchronous
                    pImpl->bIgnoreLostRedliningWarning = true;
                    pImpl->pRequest.reset(new SfxRequest( rReq ));
                    pImpl->pDocInserter.reset();
                    m_pImpl->bIgnoreLostRedliningWarning = true;
                    m_pImpl->pRequest.reset(new SfxRequest( rReq ));
                    m_pImpl->pDocInserter.reset();

                    ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell();
                    vcl::Window* pParent = pViewSh ? pViewSh->GetDialogParent() : nullptr;

                    pImpl->pDocInserter.reset( new ::sfx2::DocumentInserter(pParent ? pParent->GetFrameWeld() : nullptr,
                    m_pImpl->pDocInserter.reset( new ::sfx2::DocumentInserter(pParent ? pParent->GetFrameWeld() : nullptr,
                        ScDocShell::Factory().GetFactoryName(), mode ) );
                    pImpl->pDocInserter->StartExecuteModal( LINK( this, ScDocShell, DialogClosedHdl ) );
                    m_pImpl->pDocInserter->StartExecuteModal( LINK( this, ScDocShell, DialogClosedHdl ) );
                    return ;
                }

@@ -790,7 +790,7 @@ void ScDocShell::Execute( SfxRequest& rReq )

                    if ( !pOtherDocSh->GetError() )                 // only errors
                    {
                        bool bHadTrack = ( aDocument.GetChangeTrack() != nullptr );
                        bool bHadTrack = ( m_aDocument.GetChangeTrack() != nullptr );
#if HAVE_FEATURE_MULTIUSER_ENVIRONMENT
                        sal_uLong nStart = 0;
                        if ( nSlot == SID_DOCUMENT_MERGE && pChangeTrack )
@@ -823,12 +823,12 @@ void ScDocShell::Execute( SfxRequest& rReq )

                        if (!bHadTrack)         //  newly turned on -> show as well
                        {
                            ScChangeViewSettings* pOldSet = aDocument.GetChangeViewSettings();
                            ScChangeViewSettings* pOldSet = m_aDocument.GetChangeViewSettings();
                            if ( !pOldSet || !pOldSet->ShowChanges() )
                            {
                                ScChangeViewSettings aChangeViewSet;
                                aChangeViewSet.SetShowChanges(true);
                                aDocument.SetChangeViewSettings(aChangeViewSet);
                                m_aDocument.SetChangeViewSettings(aChangeViewSet);
                            }
                        }
#if HAVE_FEATURE_MULTIUSER_ENVIRONMENT
@@ -843,7 +843,7 @@ void ScDocShell::Execute( SfxRequest& rReq )
                                aChangeViewSet.SetShowAccepted( true );
                                aChangeViewSet.SetHasActionRange();
                                aChangeViewSet.SetTheActionRange( nStart, nEnd );
                                aDocument.SetChangeViewSettings( aChangeViewSet );
                                m_aDocument.SetChangeViewSettings( aChangeViewSet );

                                // update view
                                PostPaintExtras();
@@ -867,7 +867,7 @@ void ScDocShell::Execute( SfxRequest& rReq )
                    {
                        OUString aName = pStringItem->GetValue();
                        SCTAB nTab;
                        if (aDocument.GetTable( aName, nTab ))
                        if (m_aDocument.GetTable( aName, nTab ))
                        {
                            //  move DeleteTable from viewfunc to docfunc!

@@ -895,14 +895,14 @@ void ScDocShell::Execute( SfxRequest& rReq )
                    {
                        OUString aName = pStringItem->GetValue();
                        SCTAB nTab;
                        if (aDocument.GetTable( aName, nTab ))
                        if (m_aDocument.GetTable( aName, nTab ))
                        {
                            if (aDocument.IsScenario(nTab))
                            if (m_aDocument.IsScenario(nTab))
                            {
                                OUString aComment;
                                Color aColor;
                                ScScenarioFlags nFlags;
                                aDocument.GetScenarioData( nTab, aComment, aColor, nFlags );
                                m_aDocument.GetScenarioData( nTab, aComment, aColor, nFlags );

                                // Determine if the Sheet that the Scenario was created on
                                // is protected. But first we need to find that Sheet.
@@ -912,8 +912,8 @@ void ScDocShell::Execute( SfxRequest& rReq )
                                {
                                    nActualTab--;
                                }
                                while(aDocument.IsScenario(nActualTab));
                                bool bSheetProtected = aDocument.IsTabProtected(nActualTab);
                                while(m_aDocument.IsScenario(nActualTab));
                                bool bSheetProtected = m_aDocument.IsTabProtected(nActualTab);

                                ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
                                OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
@@ -945,9 +945,9 @@ void ScDocShell::Execute( SfxRequest& rReq )
                    // set always to DocOptions, so that it is also saved for S050
                    // (and all inquiries run up until now on it as well).
                    // SetDocOptions propagates that to the NumberFormatter
                    ScDocOptions aDocOpt( aDocument.GetDocOptions() );
                    ScDocOptions aDocOpt( m_aDocument.GetDocOptions() );
                    aDocOpt.SetYear2000( nY2k );
                    aDocument.SetDocOptions( aDocOpt );
                    m_aDocument.SetDocOptions( aDocOpt );
                    // the FormShell shall notice it as well
                    ScTabViewShell* pSh = GetBestViewShell();
                    if ( pSh )
@@ -1274,7 +1274,7 @@ void UpdateAcceptChangesDialog()
bool ScDocShell::ExecuteChangeProtectionDialog( bool bJustQueryIfProtected )
{
    bool bDone = false;
    ScChangeTrack* pChangeTrack = aDocument.GetChangeTrack();
    ScChangeTrack* pChangeTrack = m_aDocument.GetChangeTrack();
    if ( pChangeTrack )
    {
        bool bProtected = pChangeTrack->IsProtected();
@@ -1358,20 +1358,20 @@ void ScDocShell::DoRecalc( bool bApi )
        if ( pHdl )
        {
            // tdf97897 set current cell to Dirty to force recalculation of cell
            ScFormulaCell* pFC = aDocument.GetFormulaCell( pHdl->GetCursorPos());
            ScFormulaCell* pFC = m_aDocument.GetFormulaCell( pHdl->GetCursorPos());
            if (pFC)
                pFC->SetDirty();
        }
        aDocument.CalcFormulaTree();
        m_aDocument.CalcFormulaTree();
        if ( pSh )
            pSh->UpdateCharts(true);

        aDocument.BroadcastUno( SfxHint( SfxHintId::DataChanged ) );
        m_aDocument.BroadcastUno( SfxHint( SfxHintId::DataChanged ) );

        //  If there are charts, then paint everything, so that PostDataChanged
        //  and the charts do not come one after the other and parts are painted twice.

        ScChartListenerCollection* pCharts = aDocument.GetChartListenerCollection();
        ScChartListenerCollection* pCharts = m_aDocument.GetChartListenerCollection();
        if ( pCharts && pCharts->hasListeners() )
            PostPaintGridAll();
        else
@@ -1389,27 +1389,27 @@ void ScDocShell::DoHardRecalc()
        ScTabView::UpdateInputLine();     // InputEnterHandler
        pSh->UpdateInputHandler();
    }
    aDocument.CalcAll();
    m_aDocument.CalcAll();
    GetDocFunc().DetectiveRefresh();    // creates own Undo
    if ( pSh )
        pSh->UpdateCharts(true);

    // set notification flags for "calculate" event (used in SfxHintId::DataChanged broadcast)
    // (might check for the presence of any formulas on each sheet)
    SCTAB nTabCount = aDocument.GetTableCount();
    if (aDocument.HasAnySheetEventScript( ScSheetEventId::CALCULATE, true )) // search also for VBA handler
    SCTAB nTabCount = m_aDocument.GetTableCount();
    if (m_aDocument.HasAnySheetEventScript( ScSheetEventId::CALCULATE, true )) // search also for VBA handler
        for (SCTAB nTab=0; nTab<nTabCount; nTab++)
            aDocument.SetCalcNotification(nTab);
            m_aDocument.SetCalcNotification(nTab);

    // CalcAll doesn't broadcast value changes, so SfxHintId::ScCalcAll is broadcasted globally
    // in addition to SfxHintId::DataChanged.
    aDocument.BroadcastUno( SfxHint( SfxHintId::ScCalcAll ) );
    aDocument.BroadcastUno( SfxHint( SfxHintId::DataChanged ) );
    m_aDocument.BroadcastUno( SfxHint( SfxHintId::ScCalcAll ) );
    m_aDocument.BroadcastUno( SfxHint( SfxHintId::DataChanged ) );

    // use hard recalc also to disable stream-copying of all sheets
    // (somewhat consistent with charts)
    for (SCTAB nTab=0; nTab<nTabCount; nTab++)
        aDocument.SetStreamValid(nTab, false);
        m_aDocument.SetStreamValid(nTab, false);

    PostPaintGridAll();
    auto end = std::chrono::steady_clock::now();
@@ -1418,7 +1418,7 @@ void ScDocShell::DoHardRecalc()

void ScDocShell::DoAutoStyle( const ScRange& rRange, const OUString& rStyle )
{
    ScStyleSheetPool* pStylePool = aDocument.GetStyleSheetPool();
    ScStyleSheetPool* pStylePool = m_aDocument.GetStyleSheetPool();
    ScStyleSheet* pStyleSheet =
        pStylePool->FindCaseIns( rStyle, SfxStyleFamily::Para );
    if (!pStyleSheet)
@@ -1433,8 +1433,8 @@ void ScDocShell::DoAutoStyle( const ScRange& rRange, const OUString& rStyle )
        SCROW nStartRow = rRange.aStart.Row();
        SCCOL nEndCol = rRange.aEnd.Col();
        SCROW nEndRow = rRange.aEnd.Row();
        aDocument.ApplyStyleAreaTab( nStartCol, nStartRow, nEndCol, nEndRow, nTab, *pStyleSheet );
        aDocument.ExtendMerge( nStartCol, nStartRow, nEndCol, nEndRow, nTab );
        m_aDocument.ApplyStyleAreaTab( nStartCol, nStartRow, nEndCol, nEndRow, nTab, *pStyleSheet );
        m_aDocument.ExtendMerge( nStartCol, nStartRow, nEndCol, nEndRow, nTab );
        PostPaint( nStartCol, nStartRow, nTab, nEndCol, nEndRow, nTab, PaintPartFlags::Grid );
    }
}
@@ -1459,13 +1459,13 @@ void ScDocShell::NotifyStyle( const SfxStyleSheetHint& rHint )
                aOldName = pExtendedHint->GetOldName();

            if ( aNewName != aOldName )
                aDocument.RenamePageStyleInUse( aOldName, aNewName );
                m_aDocument.RenamePageStyleInUse( aOldName, aNewName );

            SCTAB nTabCount = aDocument.GetTableCount();
            SCTAB nTabCount = m_aDocument.GetTableCount();
            for (SCTAB nTab=0; nTab<nTabCount; nTab++)
                if (aDocument.GetPageStyle(nTab) == aNewName)   // already adjusted to new
                if (m_aDocument.GetPageStyle(nTab) == aNewName)   // already adjusted to new
                {
                    aDocument.PageStyleModified( nTab, aNewName );
                    m_aDocument.PageStyleModified( nTab, aNewName );
                    ScPrintFunc aPrintFunc( this, GetPrinter(), nTab );
                    aPrintFunc.UpdatePages();
                }
@@ -1497,9 +1497,9 @@ void ScDocShell::NotifyStyle( const SfxStyleSheetHint& rHint )
                aOldName = pExtendedHint->GetOldName();
            if ( aNewName != aOldName )
            {
                for(SCTAB i = 0; i < aDocument.GetTableCount(); ++i)
                for(SCTAB i = 0; i < m_aDocument.GetTableCount(); ++i)
                {
                    ScConditionalFormatList* pList = aDocument.GetCondFormList(i);
                    ScConditionalFormatList* pList = m_aDocument.GetCondFormList(i);
                    if (pList)
                        pList->RenameCellStyle( aOldName,aNewName );
                }
@@ -1515,8 +1515,8 @@ void ScDocShell::NotifyStyle( const SfxStyleSheetHint& rHint )

void ScDocShell::SetPrintZoom( SCTAB nTab, sal_uInt16 nScale, sal_uInt16 nPages )
{
    OUString aStyleName = aDocument.GetPageStyle( nTab );
    ScStyleSheetPool* pStylePool = aDocument.GetStyleSheetPool();
    OUString aStyleName = m_aDocument.GetPageStyle( nTab );
    ScStyleSheetPool* pStylePool = m_aDocument.GetStyleSheetPool();
    SfxStyleSheetBase* pStyleSheet = pStylePool->Find( aStyleName, SfxStyleFamily::Page );
    OSL_ENSURE( pStyleSheet, "PageStyle not found" );
    if ( pStyleSheet )
@@ -1524,7 +1524,7 @@ void ScDocShell::SetPrintZoom( SCTAB nTab, sal_uInt16 nScale, sal_uInt16 nPages 
        ScDocShellModificator aModificator( *this );

        SfxItemSet& rSet = pStyleSheet->GetItemSet();
        const bool bUndo(aDocument.IsUndoEnabled());
        const bool bUndo(m_aDocument.IsUndoEnabled());
        if (bUndo)
        {
            sal_uInt16 nOldScale = rSet.Get(ATTR_PAGE_SCALE).GetValue();
@@ -1551,8 +1551,8 @@ bool ScDocShell::AdjustPrintZoom( const ScRange& rRange )
    bool bChange = false;
    SCTAB nTab = rRange.aStart.Tab();

    OUString aStyleName = aDocument.GetPageStyle( nTab );
    ScStyleSheetPool* pStylePool = aDocument.GetStyleSheetPool();
    OUString aStyleName = m_aDocument.GetPageStyle( nTab );
    ScStyleSheetPool* pStylePool = m_aDocument.GetStyleSheetPool();
    SfxStyleSheetBase* pStyleSheet = pStylePool->Find( aStyleName, SfxStyleFamily::Page );
    OSL_ENSURE( pStyleSheet, "PageStyle not found" );
    if ( pStyleSheet )
@@ -1561,8 +1561,8 @@ bool ScDocShell::AdjustPrintZoom( const ScRange& rRange )
        bool bHeaders = rSet.Get(ATTR_PAGE_HEADERS).GetValue();
        sal_uInt16 nOldScale = rSet.Get(ATTR_PAGE_SCALE).GetValue();
        sal_uInt16 nOldPages = rSet.Get(ATTR_PAGE_SCALETOPAGES).GetValue();
        const ScRange* pRepeatCol = aDocument.GetRepeatColRange( nTab );
        const ScRange* pRepeatRow = aDocument.GetRepeatRowRange( nTab );
        const ScRange* pRepeatCol = m_aDocument.GetRepeatColRange( nTab );
        const ScRange* pRepeatRow = m_aDocument.GetRepeatRowRange( nTab );

        //  calculate needed scaling for selection

@@ -1576,14 +1576,14 @@ bool ScDocShell::AdjustPrintZoom( const ScRange& rRange )
        if ( pRepeatCol && nStartCol >= pRepeatCol->aStart.Col() )
        {
            for (SCCOL i=pRepeatCol->aStart.Col(); i<=pRepeatCol->aEnd.Col(); i++ )
                nBlkTwipsX += aDocument.GetColWidth( i, nTab );
                nBlkTwipsX += m_aDocument.GetColWidth( i, nTab );
            if ( nStartCol <= pRepeatCol->aEnd.Col() )
                nStartCol = pRepeatCol->aEnd.Col() + 1;
        }
        // legacy compilers' own scope for i
        {
            for ( SCCOL i=nStartCol; i<=nEndCol; i++ )
                nBlkTwipsX += aDocument.GetColWidth( i, nTab );
                nBlkTwipsX += m_aDocument.GetColWidth( i, nTab );
        }

        long nBlkTwipsY = 0;
@@ -1593,12 +1593,12 @@ bool ScDocShell::AdjustPrintZoom( const ScRange& rRange )
        SCROW nEndRow = rRange.aEnd.Row();
        if ( pRepeatRow && nStartRow >= pRepeatRow->aStart.Row() )
        {
            nBlkTwipsY += aDocument.GetRowHeight( pRepeatRow->aStart.Row(),
            nBlkTwipsY += m_aDocument.GetRowHeight( pRepeatRow->aStart.Row(),
                    pRepeatRow->aEnd.Row(), nTab );
            if ( nStartRow <= pRepeatRow->aEnd.Row() )
                nStartRow = pRepeatRow->aEnd.Row() + 1;
        }
        nBlkTwipsY += aDocument.GetRowHeight( nStartRow, nEndRow, nTab );
        nBlkTwipsY += m_aDocument.GetRowHeight( nStartRow, nEndRow, nTab );

        Size aPhysPage;
        long nHdr, nFtr;
@@ -1629,11 +1629,11 @@ void ScDocShell::PageStyleModified( const OUString& rStyleName, bool bApi )
{
    ScDocShellModificator aModificator( *this );

    SCTAB nTabCount = aDocument.GetTableCount();
    SCTAB nTabCount = m_aDocument.GetTableCount();
    SCTAB nUseTab = MAXTAB+1;
    for (SCTAB nTab=0; nTab<nTabCount && nUseTab>MAXTAB; nTab++)
        if ( aDocument.GetPageStyle(nTab) == rStyleName &&
                ( !bApi || aDocument.GetPageSize(nTab).Width() ) )
        if ( m_aDocument.GetPageStyle(nTab) == rStyleName &&
                ( !bApi || m_aDocument.GetPageSize(nTab).Width() ) )
            nUseTab = nTab;
                                // at bApi only if breaks already shown

@@ -1680,8 +1680,8 @@ void ScDocShell::ExecutePageStyle( const SfxViewShell& rCaller,
            {
                if ( pReqArgs == nullptr )
                {
                    OUString aOldName = aDocument.GetPageStyle( nCurTab );
                    ScStyleSheetPool* pStylePool = aDocument.GetStyleSheetPool();
                    OUString aOldName = m_aDocument.GetPageStyle( nCurTab );
                    ScStyleSheetPool* pStylePool = m_aDocument.GetStyleSheetPool();
                    SfxStyleSheetBase* pStyleSheet
                        = pStylePool->Find( aOldName, SfxStyleFamily::Page );

@@ -1690,7 +1690,7 @@ void ScDocShell::ExecutePageStyle( const SfxViewShell& rCaller,
                    if ( pStyleSheet )
                    {
                        ScStyleSaveData aOldData;
                        const bool bUndo(aDocument.IsUndoEnabled());
                        const bool bUndo(m_aDocument.IsUndoEnabled());
                        if (bUndo)
                            aOldData.InitFromStyle( pStyleSheet );

@@ -1710,7 +1710,7 @@ void ScDocShell::ExecutePageStyle( const SfxViewShell& rCaller,

                            OUString aNewName = pStyleSheet->GetName();
                            if ( aNewName != aOldName &&
                                aDocument.RenamePageStyleInUse( aOldName, aNewName ) )
                                m_aDocument.RenamePageStyleInUse( aOldName, aNewName ) )
                            {
                                SfxBindings* pBindings = GetViewBindings();
                                if (pBindings)
@@ -1721,10 +1721,10 @@ void ScDocShell::ExecutePageStyle( const SfxViewShell& rCaller,
                            }

                            if ( pOutSet )
                                aDocument.ModifyStyleSheet( *pStyleSheet, *pOutSet );
                                m_aDocument.ModifyStyleSheet( *pStyleSheet, *pOutSet );

                            // memorizing for GetState():
                            GetPageOnFromPageStyleSet( &rStyleSet, nCurTab, bHeaderOn, bFooterOn );
                            GetPageOnFromPageStyleSet( &rStyleSet, nCurTab, m_bHeaderOn, m_bFooterOn );
                            rCaller.GetViewFrame()->GetBindings().Invalidate( SID_HFEDIT );

                            ScStyleSaveData aNewData;
@@ -1749,10 +1749,10 @@ void ScDocShell::ExecutePageStyle( const SfxViewShell& rCaller,
            {
                if ( pReqArgs == nullptr )
                {
                    OUString aStr( aDocument.GetPageStyle( nCurTab ) );
                    OUString aStr( m_aDocument.GetPageStyle( nCurTab ) );

                    ScStyleSheetPool* pStylePool
                        = aDocument.GetStyleSheetPool();
                        = m_aDocument.GetStyleSheetPool();

                    SfxStyleSheetBase* pStyleSheet
                        = pStylePool->Find( aStr, SfxStyleFamily::Page );
@@ -1781,23 +1781,23 @@ void ScDocShell::ExecutePageStyle( const SfxViewShell& rCaller,
                            case SvxPageUsage::Left:
                            case SvxPageUsage::Right:
                            {
                                if ( bHeaderOn && bFooterOn )
                                if ( m_bHeaderOn && m_bFooterOn )
                                    nResId = RID_SCDLG_HFEDIT;
                                else if ( SvxPageUsage::Right == eUsage )
                                {
                                    if ( !bHeaderOn && bFooterOn )
                                    if ( !m_bHeaderOn && m_bFooterOn )
                                        nResId = RID_SCDLG_HFEDIT_RIGHTFOOTER;
                                    else if ( bHeaderOn && !bFooterOn )
                                    else if ( m_bHeaderOn && !m_bFooterOn )
                                        nResId = RID_SCDLG_HFEDIT_RIGHTHEADER;
                                }
                                else
                                {
                                    //  #69193a# respect "shared" setting
                                    if ( !bHeaderOn && bFooterOn )
                                    if ( !m_bHeaderOn && m_bFooterOn )
                                        nResId = bShareFooter ?
                                                    RID_SCDLG_HFEDIT_RIGHTFOOTER :
                                                    RID_SCDLG_HFEDIT_LEFTFOOTER;
                                    else if ( bHeaderOn && !bFooterOn )
                                    else if ( m_bHeaderOn && !m_bFooterOn )
                                        nResId = bShareHeader ?
                                                    RID_SCDLG_HFEDIT_RIGHTHEADER :
                                                    RID_SCDLG_HFEDIT_LEFTHEADER;
@@ -1811,41 +1811,41 @@ void ScDocShell::ExecutePageStyle( const SfxViewShell& rCaller,
                            {
                                if ( !bShareHeader && !bShareFooter )
                                {
                                    if ( bHeaderOn && bFooterOn )
                                    if ( m_bHeaderOn && m_bFooterOn )
                                        nResId = RID_SCDLG_HFEDIT_ALL;
                                    else if ( !bHeaderOn && bFooterOn )
                                    else if ( !m_bHeaderOn && m_bFooterOn )
                                        nResId = RID_SCDLG_HFEDIT_FOOTER;
                                    else if ( bHeaderOn && !bFooterOn )
                                    else if ( m_bHeaderOn && !m_bFooterOn )
                                        nResId = RID_SCDLG_HFEDIT_HEADER;
                                }
                                else if ( bShareHeader && bShareFooter )
                                {
                                    if ( bHeaderOn && bFooterOn )
                                    if ( m_bHeaderOn && m_bFooterOn )
                                        nResId = RID_SCDLG_HFEDIT;
                                    else
                                    {
                                        if ( !bHeaderOn && bFooterOn )
                                        if ( !m_bHeaderOn && m_bFooterOn )
                                            nResId = RID_SCDLG_HFEDIT_RIGHTFOOTER;
                                        else if ( bHeaderOn && !bFooterOn )
                                        else if ( m_bHeaderOn && !m_bFooterOn )
                                            nResId = RID_SCDLG_HFEDIT_RIGHTHEADER;
                                    }
                                }
                                else if ( !bShareHeader &&  bShareFooter )
                                {
                                    if ( bHeaderOn && bFooterOn )
                                    if ( m_bHeaderOn && m_bFooterOn )
                                        nResId = RID_SCDLG_HFEDIT_SFTR;
                                    else if ( !bHeaderOn && bFooterOn )
                                    else if ( !m_bHeaderOn && m_bFooterOn )
                                        nResId = RID_SCDLG_HFEDIT_RIGHTFOOTER;
                                    else if ( bHeaderOn && !bFooterOn )
                                    else if ( m_bHeaderOn && !m_bFooterOn )
                                        nResId = RID_SCDLG_HFEDIT_HEADER;
                                }
                                else if (  bShareHeader && !bShareFooter )
                                {
                                    if ( bHeaderOn && bFooterOn )
                                    if ( m_bHeaderOn && m_bFooterOn )
                                        nResId = RID_SCDLG_HFEDIT_SHDR;
                                    else if ( !bHeaderOn && bFooterOn )
                                    else if ( !m_bHeaderOn && m_bFooterOn )
                                        nResId = RID_SCDLG_HFEDIT_FOOTER;
                                    else if ( bHeaderOn && !bFooterOn )
                                    else if ( m_bHeaderOn && !m_bFooterOn )
                                        nResId = RID_SCDLG_HFEDIT_RIGHTHEADER;
                                }
                            }
@@ -1865,7 +1865,7 @@ void ScDocShell::ExecutePageStyle( const SfxViewShell& rCaller,
                            const SfxItemSet* pOutSet = pDlg->GetOutputItemSet();

                            if ( pOutSet )
                                aDocument.ModifyStyleSheet( *pStyleSheet, *pOutSet );
                                m_aDocument.ModifyStyleSheet( *pStyleSheet, *pOutSet );

                            SetDocumentModified();
                            rReq.Done();
@@ -1890,13 +1890,13 @@ void ScDocShell::GetStatePageStyle( SfxItemSet&     rSet,
        switch (nWhich)
        {
            case SID_STATUS_PAGESTYLE:
                rSet.Put( SfxStringItem( nWhich, aDocument.GetPageStyle( nCurTab ) ) );
                rSet.Put( SfxStringItem( nWhich, m_aDocument.GetPageStyle( nCurTab ) ) );
                break;

            case SID_HFEDIT:
                {
                    OUString            aStr        = aDocument.GetPageStyle( nCurTab );
                    ScStyleSheetPool*   pStylePool  = aDocument.GetStyleSheetPool();
                    OUString            aStr        = m_aDocument.GetPageStyle( nCurTab );
                    ScStyleSheetPool*   pStylePool  = m_aDocument.GetStyleSheetPool();
                    SfxStyleSheetBase*  pStyleSheet = pStylePool->Find( aStr, SfxStyleFamily::Page );

                    OSL_ENSURE( pStyleSheet, "PageStyle not found! :-/" );
@@ -1904,9 +1904,9 @@ void ScDocShell::GetStatePageStyle( SfxItemSet&     rSet,
                    if ( pStyleSheet )
                    {
                        SfxItemSet& rStyleSet = pStyleSheet->GetItemSet();
                        GetPageOnFromPageStyleSet( &rStyleSet, nCurTab, bHeaderOn, bFooterOn );
                        GetPageOnFromPageStyleSet( &rStyleSet, nCurTab, m_bHeaderOn, m_bFooterOn );

                        if ( !bHeaderOn && !bFooterOn )
                        if ( !m_bHeaderOn && !m_bFooterOn )
                            rSet.DisableItem( nWhich );
                    }
                }
@@ -1933,10 +1933,10 @@ void ScDocShell::GetState( SfxItemSet &rSet )
        switch (nWhich)
        {
            case FID_AUTO_CALC:
                if ( aDocument.GetHardRecalcState() != ScDocument::HardRecalcState::OFF )
                if ( m_aDocument.GetHardRecalcState() != ScDocument::HardRecalcState::OFF )
                    rSet.DisableItem( nWhich );
                else
                    rSet.Put( SfxBoolItem( nWhich, aDocument.GetAutoCalc() ) );
                    rSet.Put( SfxBoolItem( nWhich, m_aDocument.GetAutoCalc() ) );
                break;

            case FID_CHG_RECORD:
@@ -1944,12 +1944,12 @@ void ScDocShell::GetState( SfxItemSet &rSet )
                    rSet.DisableItem( nWhich );
                else
                    rSet.Put( SfxBoolItem( nWhich,
                        aDocument.GetChangeTrack() != nullptr ) );
                        m_aDocument.GetChangeTrack() != nullptr ) );
                break;

            case SID_CHG_PROTECT:
                {
                    ScChangeTrack* pChangeTrack = aDocument.GetChangeTrack();
                    ScChangeTrack* pChangeTrack = m_aDocument.GetChangeTrack();
                    if ( pChangeTrack && !IsDocShared() )
                        rSet.Put( SfxBoolItem( nWhich,
                            pChangeTrack->IsProtected() ) );
@@ -1972,12 +1972,12 @@ void ScDocShell::GetState( SfxItemSet &rSet )
            //  always enabled because of another bug.

            case SID_TABLES_COUNT:
                rSet.Put( SfxInt16Item( nWhich, aDocument.GetTableCount() ) );
                rSet.Put( SfxInt16Item( nWhich, m_aDocument.GetTableCount() ) );
                break;

            case SID_ATTR_YEAR2000 :
                rSet.Put( SfxUInt16Item( nWhich,
                    aDocument.GetDocOptions().GetYear2000() ) );
                    m_aDocument.GetDocOptions().GetYear2000() ) );
            break;

            case SID_SHARE_DOC:
@@ -1990,7 +1990,7 @@ void ScDocShell::GetState( SfxItemSet &rSet )
                break;

            case SID_ATTR_CHAR_FONTLIST:
                rSet.Put( SvxFontListItem( pImpl->pFontList.get(), nWhich ) );
                rSet.Put( SvxFontListItem( m_pImpl->pFontList.get(), nWhich ) );
                break;

            case SID_NOTEBOOKBAR:
@@ -2024,8 +2024,8 @@ void ScDocShell::GetState( SfxItemSet &rSet )
void ScDocShell::Draw( OutputDevice* pDev, const JobSetup & /* rSetup */, sal_uInt16 nAspect )
{

    SCTAB nVisTab = aDocument.GetVisibleTab();
    if (!aDocument.HasTable(nVisTab))
    SCTAB nVisTab = m_aDocument.GetVisibleTab();
    if (!m_aDocument.HasTable(nVisTab))
        return;

    ComplexTextLayoutFlags nOldLayoutMode = pDev->GetLayoutMode();
@@ -2038,7 +2038,7 @@ void ScDocShell::Draw( OutputDevice* pDev, const JobSetup & /* rSetup */, sal_uI
        aTmpData.SetTabNo(nVisTab);
        SnapVisArea( aBoundRect );
        aTmpData.SetScreen( aBoundRect );
        ScPrintFunc::DrawToDev( &aDocument, pDev, 1.0, aBoundRect, &aTmpData, true );
        ScPrintFunc::DrawToDev( &m_aDocument, pDev, 1.0, aBoundRect, &aTmpData, true );
    }
    else
    {
@@ -2047,7 +2047,7 @@ void ScDocShell::Draw( OutputDevice* pDev, const JobSetup & /* rSetup */, sal_uI
        aTmpData.SetTabNo(nVisTab);
        SnapVisArea( aBoundRect );
        aTmpData.SetScreen( aBoundRect );
        ScPrintFunc::DrawToDev( &aDocument, pDev, 1.0, aBoundRect, &aTmpData, true );
        ScPrintFunc::DrawToDev( &m_aDocument, pDev, 1.0, aBoundRect, &aTmpData, true );
    }

    pDev->SetLayoutMode( nOldLayoutMode );
@@ -2065,13 +2065,13 @@ tools::Rectangle ScDocShell::GetVisArea( sal_uInt16 nAspect ) const

    if( nAspect == ASPECT_THUMBNAIL )
    {
        SCTAB nVisTab = aDocument.GetVisibleTab();
        if (!aDocument.HasTable(nVisTab))
        SCTAB nVisTab = m_aDocument.GetVisibleTab();
        if (!m_aDocument.HasTable(nVisTab))
        {
            nVisTab = 0;
            const_cast<ScDocShell*>(this)->aDocument.SetVisibleTab(nVisTab);
            const_cast<ScDocShell*>(this)->m_aDocument.SetVisibleTab(nVisTab);
        }
        Size aSize = aDocument.GetPageSize(nVisTab);
        Size aSize = m_aDocument.GetPageSize(nVisTab);
        const long SC_PREVIEW_SIZE_X = 10000;
        const long SC_PREVIEW_SIZE_Y = 12400;
        tools::Rectangle aArea( 0,0, SC_PREVIEW_SIZE_X, SC_PREVIEW_SIZE_Y);
@@ -2081,7 +2081,7 @@ tools::Rectangle ScDocShell::GetVisArea( sal_uInt16 nAspect ) const
            aArea.SetBottom( SC_PREVIEW_SIZE_X );
        }

        bool bNegativePage = aDocument.IsNegativePage( aDocument.GetVisibleTab() );
        bool bNegativePage = m_aDocument.IsNegativePage( m_aDocument.GetVisibleTab() );
        if ( bNegativePage )
            ScDrawLayer::MirrorRectRTL( aArea );
        SnapVisArea( aArea );
@@ -2091,23 +2091,23 @@ tools::Rectangle ScDocShell::GetVisArea( sal_uInt16 nAspect ) const
    {
        //  fetch visarea like after loading

        SCTAB nVisTab = aDocument.GetVisibleTab();
        if (!aDocument.HasTable(nVisTab))
        SCTAB nVisTab = m_aDocument.GetVisibleTab();
        if (!m_aDocument.HasTable(nVisTab))
        {
            nVisTab = 0;
            const_cast<ScDocShell*>(this)->aDocument.SetVisibleTab(nVisTab);
            const_cast<ScDocShell*>(this)->m_aDocument.SetVisibleTab(nVisTab);
        }
        SCCOL nStartCol;
        SCROW nStartRow;
        aDocument.GetDataStart( nVisTab, nStartCol, nStartRow );
        m_aDocument.GetDataStart( nVisTab, nStartCol, nStartRow );
        SCCOL nEndCol;
        SCROW nEndRow;
        aDocument.GetPrintArea( nVisTab, nEndCol, nEndRow );
        m_aDocument.GetPrintArea( nVisTab, nEndCol, nEndRow );
        if (nStartCol>nEndCol)
            nStartCol = nEndCol;
        if (nStartRow>nEndRow)
            nStartRow = nEndRow;
        tools::Rectangle aNewArea = aDocument
        tools::Rectangle aNewArea = m_aDocument
                                .GetMMRect( nStartCol,nStartRow, nEndCol,nEndRow, nVisTab );
        //TODO/LATER: different methods for setting VisArea?!
        const_cast<ScDocShell*>(this)->SfxObjectShell::SetVisArea( aNewArea );
@@ -2183,20 +2183,20 @@ long SnapVertical( const ScDocument& rDoc, SCTAB nTab, long nVal, SCROW& rStartR

void ScDocShell::SnapVisArea( tools::Rectangle& rRect ) const
{
    SCTAB nTab = aDocument.GetVisibleTab();
    bool bNegativePage = aDocument.IsNegativePage( nTab );
    SCTAB nTab = m_aDocument.GetVisibleTab();
    bool bNegativePage = m_aDocument.IsNegativePage( nTab );
    if ( bNegativePage )
        ScDrawLayer::MirrorRectRTL( rRect );        // calculate with positive (LTR) values

    SCCOL nCol = 0;
    rRect.SetLeft( SnapHorizontal( aDocument, nTab, rRect.Left(), nCol ) );
    rRect.SetLeft( SnapHorizontal( m_aDocument, nTab, rRect.Left(), nCol ) );
    ++nCol;                                         // at least one column
    rRect.SetRight( SnapHorizontal( aDocument, nTab, rRect.Right(), nCol ) );
    rRect.SetRight( SnapHorizontal( m_aDocument, nTab, rRect.Right(), nCol ) );

    SCROW nRow = 0;
    rRect.SetTop( SnapVertical( aDocument, nTab, rRect.Top(), nRow ) );
    rRect.SetTop( SnapVertical( m_aDocument, nTab, rRect.Top(), nRow ) );
    ++nRow;                                         // at least one row
    rRect.SetBottom( SnapVertical( aDocument, nTab, rRect.Bottom(), nRow ) );
    rRect.SetBottom( SnapVertical( m_aDocument, nTab, rRect.Bottom(), nRow ) );

    if ( bNegativePage )
        ScDrawLayer::MirrorRectRTL( rRect );        // back to real rectangle
@@ -2209,9 +2209,9 @@ void ScDocShell::GetPageOnFromPageStyleSet( const SfxItemSet* pStyleSet,
{
    if ( !pStyleSet )
    {
        ScStyleSheetPool*  pStylePool  = aDocument.GetStyleSheetPool();
        ScStyleSheetPool*  pStylePool  = m_aDocument.GetStyleSheetPool();
        SfxStyleSheetBase* pStyleSheet = pStylePool->
                                            Find( aDocument.GetPageStyle( nCurTab ),
                                            Find( m_aDocument.GetPageStyle( nCurTab ),
                                                  SfxStyleFamily::Page );

        OSL_ENSURE( pStyleSheet, "PageStyle not found! :-/" );
@@ -2248,21 +2248,21 @@ bool ScDocShell::DdeGetData( const OUString& rItem,
    {
        if( rItem.equalsIgnoreAsciiCase( "Format" ) )
        {
            OString aFmtByte(OUStringToOString(aDdeTextFmt,
            OString aFmtByte(OUStringToOString(m_aDdeTextFmt,
                osl_getThreadTextEncoding()));
            rValue <<= css::uno::Sequence< sal_Int8 >(
                                        reinterpret_cast<const sal_Int8*>(aFmtByte.getStr()),
                                        aFmtByte.getLength() + 1 );
            return true;
        }
        ScImportExport aObj( &aDocument, rItem );
        ScImportExport aObj( &m_aDocument, rItem );
        if ( !aObj.IsRef() )
            return false;                           // invalid range

        if( aDdeTextFmt[0] == 'F' )
        if( m_aDdeTextFmt[0] == 'F' )
            aObj.SetFormulas( true );
        if( aDdeTextFmt == "SYLK" ||
            aDdeTextFmt == "FSYLK" )
        if( m_aDdeTextFmt == "SYLK" ||
            m_aDdeTextFmt == "FSYLK" )
        {
            OString aData;
            if( aObj.ExportByteString( aData, osl_getThreadTextEncoding(),
@@ -2276,14 +2276,14 @@ bool ScDocShell::DdeGetData( const OUString& rItem,
            else
                return false;
        }
        if( aDdeTextFmt == "CSV" ||
            aDdeTextFmt == "FCSV" )
        if( m_aDdeTextFmt == "CSV" ||
            m_aDdeTextFmt == "FCSV" )
            aObj.SetSeparator( ',' );
        aObj.SetExportTextOptions( ScExportTextOptions( ScExportTextOptions::ToSpace, 0, false ) );
        return aObj.ExportData( rMimeType, rValue );
    }

    ScImportExport aObj( &aDocument, rItem );
    ScImportExport aObj( &m_aDocument, rItem );
    aObj.SetExportTextOptions( ScExportTextOptions( ScExportTextOptions::ToSpace, 0, false ) );
    return aObj.IsRef() && aObj.ExportData( rMimeType, rValue );
}
@@ -2297,18 +2297,18 @@ bool ScDocShell::DdeSetData( const OUString& rItem,
    {
        if( rItem.equalsIgnoreAsciiCase( "Format" ) )
        {
            if ( ScByteSequenceToString::GetString( aDdeTextFmt, rValue, osl_getThreadTextEncoding() ) )
            if ( ScByteSequenceToString::GetString( m_aDdeTextFmt, rValue, osl_getThreadTextEncoding() ) )
            {
                aDdeTextFmt = aDdeTextFmt.toAsciiUpperCase();
                m_aDdeTextFmt = m_aDdeTextFmt.toAsciiUpperCase();
                return true;
            }
            return false;
        }
        ScImportExport aObj( &aDocument, rItem );
        if( aDdeTextFmt[0] == 'F' )
        ScImportExport aObj( &m_aDocument, rItem );
        if( m_aDdeTextFmt[0] == 'F' )
            aObj.SetFormulas( true );
        if( aDdeTextFmt == "SYLK" ||
            aDdeTextFmt == "FSYLK" )
        if( m_aDdeTextFmt == "SYLK" ||
            m_aDdeTextFmt == "FSYLK" )
        {
            OUString aData;
            if ( ScByteSequenceToString::GetString( aData, rValue, osl_getThreadTextEncoding() ) )
@@ -2317,8 +2317,8 @@ bool ScDocShell::DdeSetData( const OUString& rItem,
            }
            return false;
        }
        if( aDdeTextFmt == "CSV" ||
            aDdeTextFmt == "FCSV" )
        if( m_aDdeTextFmt == "CSV" ||
            m_aDdeTextFmt == "FCSV" )
            aObj.SetSeparator( ',' );
        OSL_ENSURE( false, "Implementation is missing" );
        return false;
@@ -2336,7 +2336,7 @@ bool ScDocShell::DdeSetData( const OUString& rItem,

    //  named range?
    OUString aPos = rItem;
    ScRangeName* pRange = aDocument.GetRangeName();
    ScRangeName* pRange = m_aDocument.GetRangeName();
    if( pRange )
    {
        const ScRangeData* pData = pRange->findByUpperName(ScGlobal::pCharClass->uppercase(aPos));
@@ -2354,8 +2354,8 @@ bool ScDocShell::DdeSetData( const OUString& rItem,
    // because the address item in a DDE entry is *not* normalized when saved
    // into ODF.
    ScRange aRange;
    bool bValid = ( (aRange.Parse(aPos, &aDocument, formula::FormulaGrammar::CONV_OOO ) & ScRefFlags::VALID) ||
                    (aRange.aStart.Parse(aPos, &aDocument, formula::FormulaGrammar::CONV_OOO) & ScRefFlags::VALID) );
    bool bValid = ( (aRange.Parse(aPos, &m_aDocument, formula::FormulaGrammar::CONV_OOO ) & ScRefFlags::VALID) ||
                    (aRange.aStart.Parse(aPos, &m_aDocument, formula::FormulaGrammar::CONV_OOO) & ScRefFlags::VALID) );

    ScServerObject* pObj = nullptr;            // NULL = error
    if ( bValid )
@@ -2490,24 +2490,24 @@ ScDocShell* ScDocShell::GetShellByNum( sal_uInt16 nDocNo )      // static
IMPL_LINK( ScDocShell, DialogClosedHdl, sfx2::FileDialogHelper*, _pFileDlg, void )
{
    OSL_ENSURE( _pFileDlg, "ScDocShell::DialogClosedHdl(): no file dialog" );
    OSL_ENSURE( pImpl->pDocInserter, "ScDocShell::DialogClosedHdl(): no document inserter" );
    OSL_ENSURE( m_pImpl->pDocInserter, "ScDocShell::DialogClosedHdl(): no document inserter" );

    if ( ERRCODE_NONE == _pFileDlg->GetError() )
    {
        sal_uInt16 nSlot = pImpl->pRequest->GetSlot();
        SfxMedium* pMed = pImpl->pDocInserter->CreateMedium();
        sal_uInt16 nSlot = m_pImpl->pRequest->GetSlot();
        SfxMedium* pMed = m_pImpl->pDocInserter->CreateMedium();
        // #i87094# If a .odt was selected pMed is NULL.
        if (pMed)
        {
            pImpl->pRequest->AppendItem( SfxStringItem( SID_FILE_NAME, pMed->GetName() ) );
            m_pImpl->pRequest->AppendItem( SfxStringItem( SID_FILE_NAME, pMed->GetName() ) );
            if ( SID_DOCUMENT_COMPARE == nSlot )
            {
                if ( pMed->GetFilter() )
                    pImpl->pRequest->AppendItem(
                    m_pImpl->pRequest->AppendItem(
                            SfxStringItem( SID_FILTER_NAME, pMed->GetFilter()->GetFilterName() ) );
                OUString sOptions = ScDocumentLoader::GetOptions( *pMed );
                if ( !sOptions.isEmpty() )
                    pImpl->pRequest->AppendItem( SfxStringItem( SID_FILE_FILTEROPTIONS, sOptions ) );
                    m_pImpl->pRequest->AppendItem( SfxStringItem( SID_FILE_FILTEROPTIONS, sOptions ) );
            }
            const SfxPoolItem* pItem = nullptr;
            const SfxInt16Item* pInt16Item(nullptr);
@@ -2518,14 +2518,14 @@ IMPL_LINK( ScDocShell, DialogClosedHdl, sfx2::FileDialogHelper*, _pFileDlg, void
            }
            if (pInt16Item)
            {
                pImpl->pRequest->AppendItem( *pItem );
                m_pImpl->pRequest->AppendItem( *pItem );
            }

            Execute( *(pImpl->pRequest) );
            Execute( *(m_pImpl->pRequest) );
        }
    }

    pImpl->bIgnoreLostRedliningWarning = false;
    m_pImpl->bIgnoreLostRedliningWarning = false;
}

#if HAVE_FEATURE_MULTIUSER_ENVIRONMENT
@@ -2536,8 +2536,8 @@ void ScDocShell::EnableSharedSettings( bool bEnable )

    if ( bEnable )
    {
        aDocument.EndChangeTracking();
        aDocument.StartChangeTracking();
        m_aDocument.EndChangeTracking();
        m_aDocument.StartChangeTracking();

        // hide accept or reject changes dialog
        sal_uInt16 nId = ScAcceptChgDlgWrapper::GetChildWindowId();
@@ -2554,12 +2554,12 @@ void ScDocShell::EnableSharedSettings( bool bEnable )
    }
    else
    {
        aDocument.EndChangeTracking();
        m_aDocument.EndChangeTracking();
    }

    ScChangeViewSettings aChangeViewSet;
    aChangeViewSet.SetShowChanges( false );
    aDocument.SetChangeViewSettings( aChangeViewSet );
    m_aDocument.SetChangeViewSettings( aChangeViewSet );
}

uno::Reference< frame::XModel > ScDocShell::LoadSharedDocument()
diff --git a/sc/source/ui/docshell/docsh5.cxx b/sc/source/ui/docshell/docsh5.cxx
index d42e44d..386f512 100644
--- a/sc/source/ui/docshell/docsh5.cxx
+++ b/sc/source/ui/docshell/docsh5.cxx
@@ -97,18 +97,18 @@ bool ScDocShell::IsEditable() const
    // import into read-only document is possible - must be extended if other filters use api
    // #i108547# MSOOXML filter uses "IsChangeReadOnlyEnabled" property

    return !IsReadOnly() || aDocument.IsImportingXML() || aDocument.IsChangeReadOnlyEnabled();
    return !IsReadOnly() || m_aDocument.IsImportingXML() || m_aDocument.IsChangeReadOnlyEnabled();
}

void ScDocShell::DBAreaDeleted( SCTAB nTab, SCCOL nX1, SCROW nY1, SCCOL nX2 )
{
    ScDocShellModificator aModificator( *this );
    // the auto-filter is in the first row of the area
    aDocument.RemoveFlagsTab( nX1, nY1, nX2, nY1, nTab, ScMF::Auto );
    m_aDocument.RemoveFlagsTab( nX1, nY1, nX2, nY1, nTab, ScMF::Auto );
    PostPaint( nX1, nY1, nTab, nX2, nY1, nTab, PaintPartFlags::Grid );
    // No SetDocumentModified, as the unnamed database range might have to be restored later.
    // The UNO hint is broadcast directly instead, to keep UNO objects in valid state.
    aDocument.BroadcastUno( SfxHint( SfxHintId::DataChanged ) );
    m_aDocument.BroadcastUno( SfxHint( SfxHintId::DataChanged ) );
}

ScDBData* ScDocShell::GetDBData( const ScRange& rMarked, ScGetDBMode eMode, ScGetDBSelection eSel )
@@ -124,8 +124,8 @@ ScDBData* ScDocShell::GetDBData( const ScRange& rMarked, ScGetDBMode eMode, ScGe
    SCROW nEndRow = rMarked.aEnd.Row();
    //  Not simply GetDBAtCursor: The continuous data range for "unnamed" (GetDataArea) may be
    //  located next to the cursor; so a named DB range needs to be searched for there as well.
    ScDBCollection* pColl = aDocument.GetDBCollection();
    ScDBData* pData = aDocument.GetDBAtArea( nTab, nStartCol, nStartRow, nEndCol, nEndRow );
    ScDBCollection* pColl = m_aDocument.GetDBCollection();
    ScDBData* pData = m_aDocument.GetDBAtArea( nTab, nStartCol, nStartRow, nEndCol, nEndRow );
    if (!pData)
        pData = pColl->GetDBNearCursor(nCol, nRow, nTab );

@@ -165,7 +165,7 @@ ScDBData* ScDocShell::GetDBData( const ScRange& rMarked, ScGetDBMode eMode, ScGe
                    nEndCol = nStartCol;
                    nEndRow = nStartRow;
                }
                aDocument.GetDataArea( nTab, nStartCol, nStartRow, nEndCol, nEndRow, false, bOnlyDown );
                m_aDocument.GetDataArea( nTab, nStartCol, nStartRow, nEndCol, nEndRow, false, bOnlyDown );
                if ( nOldCol1 != nStartCol || nOldCol2 != nEndCol || nOldRow1 != nStartRow )
                    bUseThis = false;               // doesn't fit at all
                else if ( nOldRow2 != nEndRow )
@@ -214,12 +214,12 @@ ScDBData* ScDocShell::GetDBData( const ScRange& rMarked, ScGetDBMode eMode, ScGe
                nEndCol = nStartCol;
                nEndRow = nStartRow;
            }
            aDocument.GetDataArea( nTab, nStartCol, nStartRow, nEndCol, nEndRow, false, bOnlyDown );
            m_aDocument.GetDataArea( nTab, nStartCol, nStartRow, nEndCol, nEndRow, false, bOnlyDown );
        }

        bool bHasHeader = aDocument.HasColHeader( nStartCol,nStartRow, nEndCol,nEndRow, nTab );
        bool bHasHeader = m_aDocument.HasColHeader( nStartCol,nStartRow, nEndCol,nEndRow, nTab );

        ScDBData* pNoNameData = aDocument.GetAnonymousDBData(nTab);
        ScDBData* pNoNameData = m_aDocument.GetAnonymousDBData(nTab);
        if ( eMode != SC_DB_IMPORT && pNoNameData)
        {
            // Do not reset AutoFilter range during temporary operations on
@@ -230,30 +230,30 @@ ScDBData* ScDocShell::GetDBData( const ScRange& rMarked, ScGetDBMode eMode, ScGe
            if (eMode != SC_DB_AUTOFILTER && pNoNameData->HasAutoFilter())
            {
                bSheetLocal = false;
                pNoNameData = aDocument.GetAnonymousDBData();
                pNoNameData = m_aDocument.GetAnonymousDBData();
                if (!pNoNameData)
                {
                    aDocument.SetAnonymousDBData( std::unique_ptr<ScDBData>(new ScDBData( STR_DB_LOCAL_NONAME,
                    m_aDocument.SetAnonymousDBData( std::unique_ptr<ScDBData>(new ScDBData( STR_DB_LOCAL_NONAME,
                            nTab, nStartCol, nStartRow, nEndCol, nEndRow, true, bHasHeader) ) );
                    pNoNameData = aDocument.GetAnonymousDBData();
                    pNoNameData = m_aDocument.GetAnonymousDBData();
                }
                // ScDocShell::CancelAutoDBRange() would restore the
                // sheet-local anonymous DBData from pOldAutoDBRange, unset so
                // that won't happen with data of a previous sheet-local
                // DBData.
                delete pOldAutoDBRange;
                pOldAutoDBRange = nullptr;
                delete m_pOldAutoDBRange;
                m_pOldAutoDBRange = nullptr;
            }
            else if (!pOldAutoDBRange)
            else if (!m_pOldAutoDBRange)
            {
                // store the old unnamed database range with its settings for undo
                // (store at the first change, get the state before all changes)
                pOldAutoDBRange = new ScDBData( *pNoNameData );
                m_pOldAutoDBRange = new ScDBData( *pNoNameData );
            }
            else if (pOldAutoDBRange->GetTab() != pNoNameData->GetTab())
            else if (m_pOldAutoDBRange->GetTab() != pNoNameData->GetTab())
            {
                // Different sheet-local unnamed DB range than the previous one.
                *pOldAutoDBRange = *pNoNameData;
                *m_pOldAutoDBRange = *pNoNameData;
            }

            SCCOL nOldX1;                                   // take old range away cleanly
@@ -291,7 +291,7 @@ ScDBData* ScDocShell::GetDBData( const ScRange& rMarked, ScGetDBMode eMode, ScGe

            if (eMode==SC_DB_IMPORT)
            {
                aDocument.PreprocessDBDataUpdate();
                m_aDocument.PreprocessDBDataUpdate();
                pUndoColl = new ScDBCollection( *pColl );   // Undo for import range

                OUString aImport = ScResId( STR_DBNAME_IMPORT );
@@ -317,12 +317,12 @@ ScDBData* ScDocShell::GetDBData( const ScRange& rMarked, ScGetDBMode eMode, ScGe
                pNoNameData = new ScDBData(STR_DB_LOCAL_NONAME, nTab,
                                nStartCol,nStartRow, nEndCol,nEndRow,
                                true, bHasHeader );
                aDocument.SetAnonymousDBData(nTab, std::unique_ptr<ScDBData>(pNoNameData));
                m_aDocument.SetAnonymousDBData(nTab, std::unique_ptr<ScDBData>(pNoNameData));
            }

            if ( pUndoColl )
            {
                aDocument.CompileHybridFormula();
                m_aDocument.CompileHybridFormula();

                ScDBCollection* pRedoColl = new ScDBCollection( *pColl );
                GetUndoManager()->AddUndoAction( new ScUndoDBData( this, pUndoColl, pRedoColl ) );
@@ -342,7 +342,7 @@ ScDBData* ScDocShell::GetDBData( const ScRange& rMarked, ScGetDBMode eMode, ScGe

ScDBData* ScDocShell::GetAnonymousDBData(const ScRange& rRange)
{
    ScDBCollection* pColl = aDocument.GetDBCollection();
    ScDBCollection* pColl = m_aDocument.GetDBCollection();
    if (!pColl)
        return nullptr;

@@ -352,7 +352,7 @@ ScDBData* ScDocShell::GetAnonymousDBData(const ScRange& rRange)

    if (!pData->HasHeader())
    {
        bool bHasHeader = aDocument.HasColHeader(
        bool bHasHeader = m_aDocument.HasColHeader(
                rRange.aStart.Col(), rRange.aStart.Row(), rRange.aEnd.Col(), rRange.aEnd.Row(), rRange.aStart.Tab());
        pData->SetHeader(bHasHeader);
    }
@@ -362,8 +362,8 @@ ScDBData* ScDocShell::GetAnonymousDBData(const ScRange& rRange)

ScDBData* ScDocShell::GetOldAutoDBRange()
{
    ScDBData* pRet = pOldAutoDBRange;
    pOldAutoDBRange = nullptr;
    ScDBData* pRet = m_pOldAutoDBRange;
    m_pOldAutoDBRange = nullptr;
    return pRet;                    // has to be deleted by caller!
}

@@ -371,10 +371,10 @@ void ScDocShell::CancelAutoDBRange()
{
    // called when dialog is cancelled
//moggi:TODO
    if ( pOldAutoDBRange )
    if ( m_pOldAutoDBRange )
    {
        SCTAB nTab = GetCurTab();
        ScDBData* pDBData = aDocument.GetAnonymousDBData(nTab);
        ScDBData* pDBData = m_aDocument.GetAnonymousDBData(nTab);
        if ( pDBData )
        {
            SCCOL nRangeX1;
@@ -385,19 +385,19 @@ void ScDocShell::CancelAutoDBRange()
            pDBData->GetArea( nRangeTab, nRangeX1, nRangeY1, nRangeX2, nRangeY2 );
            DBAreaDeleted( nRangeTab, nRangeX1, nRangeY1, nRangeX2 );

            *pDBData = *pOldAutoDBRange;    // restore old settings
            *pDBData = *m_pOldAutoDBRange;    // restore old settings

            if ( pOldAutoDBRange->HasAutoFilter() )
            if ( m_pOldAutoDBRange->HasAutoFilter() )
            {
                // restore AutoFilter buttons
                pOldAutoDBRange->GetArea( nRangeTab, nRangeX1, nRangeY1, nRangeX2, nRangeY2 );
                aDocument.ApplyFlagsTab( nRangeX1, nRangeY1, nRangeX2, nRangeY1, nRangeTab, ScMF::Auto );
                m_pOldAutoDBRange->GetArea( nRangeTab, nRangeX1, nRangeY1, nRangeX2, nRangeY2 );
                m_aDocument.ApplyFlagsTab( nRangeX1, nRangeY1, nRangeX2, nRangeY1, nRangeTab, ScMF::Auto );
                PostPaint( nRangeX1, nRangeY1, nRangeTab, nRangeX2, nRangeY1, nRangeTab, PaintPartFlags::Grid );
            }
        }

        delete pOldAutoDBRange;
        pOldAutoDBRange = nullptr;
        delete m_pOldAutoDBRange;
        m_pOldAutoDBRange = nullptr;
    }
}

@@ -409,12 +409,12 @@ bool ScDocShell::AdjustRowHeight( SCROW nStartRow, SCROW nEndRow, SCTAB nTab )
    ScSizeDeviceProvider aProv(this);
    Fraction aZoom(1,1);
    sc::RowHeightContext aCxt(aProv.GetPPTX(), aProv.GetPPTY(), aZoom, aZoom, aProv.GetDevice());
    bool bChange = aDocument.SetOptimalHeight(aCxt, nStartRow,nEndRow, nTab);
    bool bChange = m_aDocument.SetOptimalHeight(aCxt, nStartRow,nEndRow, nTab);

    if (bChange)
    {
        // tdf#76183: recalculate objects' positions
        aDocument.SetDrawPageSize(nTab);
        m_aDocument.SetDrawPageSize(nTab);

        PostPaint( 0,nStartRow,nTab, MAXCOL,MAXROW,nTab, PaintPartFlags::Grid|PaintPartFlags::Left );
    }
@@ -429,24 +429,24 @@ void ScDocShell::UpdateAllRowHeights( const ScMarkData* pTabMark )
    ScSizeDeviceProvider aProv(this);
    Fraction aZoom(1,1);
    sc::RowHeightContext aCxt(aProv.GetPPTX(), aProv.GetPPTY(), aZoom, aZoom, aProv.GetDevice());
    aDocument.UpdateAllRowHeights(aCxt, pTabMark);
    m_aDocument.UpdateAllRowHeights(aCxt, pTabMark);
}

void ScDocShell::UpdatePendingRowHeights( SCTAB nUpdateTab, bool bBefore )
{
    bool bIsUndoEnabled = aDocument.IsUndoEnabled();
    aDocument.EnableUndo( false );
    aDocument.LockStreamValid( true );      // ignore draw page size (but not formula results)
    bool bIsUndoEnabled = m_aDocument.IsUndoEnabled();
    m_aDocument.EnableUndo( false );
    m_aDocument.LockStreamValid( true );      // ignore draw page size (but not formula results)
    if ( bBefore )          // check all sheets up to nUpdateTab
    {
        SCTAB nTabCount = aDocument.GetTableCount();
        SCTAB nTabCount = m_aDocument.GetTableCount();
        if ( nUpdateTab >= nTabCount )
            nUpdateTab = nTabCount-1;     // nUpdateTab is inclusive

        ScMarkData aUpdateSheets;
        SCTAB nTab;
        for (nTab=0; nTab<=nUpdateTab; ++nTab)
            if ( aDocument.IsPendingRowHeights( nTab ) )
            if ( m_aDocument.IsPendingRowHeights( nTab ) )
                aUpdateSheets.SelectTable( nTab, true );

        if (aUpdateSheets.GetSelectCount())
@@ -455,26 +455,26 @@ void ScDocShell::UpdatePendingRowHeights( SCTAB nUpdateTab, bool bBefore )
        for (nTab=0; nTab<=nUpdateTab; ++nTab)
            if ( aUpdateSheets.GetTableSelect( nTab ) )
            {
                aDocument.UpdatePageBreaks( nTab );
                aDocument.SetPendingRowHeights( nTab, false );
                m_aDocument.UpdatePageBreaks( nTab );
                m_aDocument.SetPendingRowHeights( nTab, false );
            }
    }
    else                    // only nUpdateTab
    {
        if ( aDocument.IsPendingRowHeights( nUpdateTab ) )
        if ( m_aDocument.IsPendingRowHeights( nUpdateTab ) )
        {
            AdjustRowHeight( 0, MAXROW, nUpdateTab );
            aDocument.UpdatePageBreaks( nUpdateTab );
            aDocument.SetPendingRowHeights( nUpdateTab, false );
            m_aDocument.UpdatePageBreaks( nUpdateTab );
            m_aDocument.SetPendingRowHeights( nUpdateTab, false );
        }
    }
    aDocument.LockStreamValid( false );
    aDocument.EnableUndo( bIsUndoEnabled );
    m_aDocument.LockStreamValid( false );
    m_aDocument.EnableUndo( bIsUndoEnabled );
}

void ScDocShell::RefreshPivotTables( const ScRange& rSource )
{
    ScDPCollection* pColl = aDocument.GetDPCollection();
    ScDPCollection* pColl = m_aDocument.GetDPCollection();
    if (!pColl)
        return;

@@ -537,7 +537,7 @@ void ScDocShell::DoConsolidate( const ScConsolidateParam& rParam, bool bRecord )
    ScDocShellModificator aModificator( *this );

    ScRange aOldDest;
    ScDBData* pDestData = aDocument.GetDBAtCursor( rParam.nCol, rParam.nRow, rParam.nTab, ScDBDataPortion::TOP_LEFT );
    ScDBData* pDestData = m_aDocument.GetDBAtCursor( rParam.nCol, rParam.nRow, rParam.nTab, ScDBDataPortion::TOP_LEFT );
    if (pDestData)
        pDestData->GetArea(aOldDest);

@@ -547,16 +547,16 @@ void ScDocShell::DoConsolidate( const ScConsolidateParam& rParam, bool bRecord )
        for (nPos=0; nPos<rParam.nDataAreaCount; nPos++)
        {
            ScArea* pArea = rParam.ppDataAreas[nPos];
            aData.AddFields( &aDocument, pArea->nTab, pArea->nColStart, pArea->nRowStart,
            aData.AddFields( &m_aDocument, pArea->nTab, pArea->nColStart, pArea->nRowStart,
                                                        pArea->nColEnd, pArea->nRowEnd );
        }
    aData.DoneFields();
    for (nPos=0; nPos<rParam.nDataAreaCount; nPos++)
    {
        ScArea* pArea = rParam.ppDataAreas[nPos];
        aData.AddData( &aDocument, pArea->nTab, pArea->nColStart, pArea->nRowStart,
        aData.AddData( &m_aDocument, pArea->nTab, pArea->nColStart, pArea->nRowStart,
                                                    pArea->nColEnd, pArea->nRowEnd );
        aData.AddName( lcl_GetAreaName(&aDocument,pArea) );
        aData.AddName( lcl_GetAreaName(&m_aDocument,pArea) );
    }

    aData.GetSize( nColSize, nRowSize );
@@ -572,32 +572,32 @@ void ScDocShell::DoConsolidate( const ScConsolidateParam& rParam, bool bRecord )

        if (rParam.bReferenceData)
        {
            SCTAB nTabCount = aDocument.GetTableCount();
            SCTAB nTabCount = m_aDocument.GetTableCount();
            SCROW nInsertCount = aData.GetInsertCount();

            // old outlines
            ScOutlineTable* pTable = aDocument.GetOutlineTable( nDestTab );
            ScOutlineTable* pTable = m_aDocument.GetOutlineTable( nDestTab );
            ScOutlineTable* pUndoTab = pTable ? new ScOutlineTable( *pTable ) : nullptr;

            ScDocument* pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
            pUndoDoc->InitUndo( &aDocument, 0, nTabCount-1, false, true );
            pUndoDoc->InitUndo( &m_aDocument, 0, nTabCount-1, false, true );

            // row state
            aDocument.CopyToDocument(0, 0, nDestTab, MAXCOL, MAXROW, nDestTab,
            m_aDocument.CopyToDocument(0, 0, nDestTab, MAXCOL, MAXROW, nDestTab,
                                     InsertDeleteFlags::NONE, false, *pUndoDoc);

            // all formulas
            aDocument.CopyToDocument(0, 0, 0, MAXCOL, MAXROW, nTabCount-1,
            m_aDocument.CopyToDocument(0, 0, 0, MAXCOL, MAXROW, nTabCount-1,
                                     InsertDeleteFlags::FORMULA, false, *pUndoDoc);

            // complete output rows
            aDocument.CopyToDocument(0, aDestArea.nRowStart, nDestTab,
            m_aDocument.CopyToDocument(0, aDestArea.nRowStart, nDestTab,
                                     MAXCOL,aDestArea.nRowEnd, nDestTab,
                                     InsertDeleteFlags::ALL, false, *pUndoDoc);

            // old output range
            if (pDestData)
                aDocument.CopyToDocument(aOldDest, InsertDeleteFlags::ALL, false, *pUndoDoc);
                m_aDocument.CopyToDocument(aOldDest, InsertDeleteFlags::ALL, false, *pUndoDoc);

            GetUndoManager()->AddUndoAction(
                    new ScUndoConsolidate( this, aDestArea, rParam, pUndoDoc,
@@ -606,15 +606,15 @@ void ScDocShell::DoConsolidate( const ScConsolidateParam& rParam, bool bRecord )
        else
        {
            ScDocument* pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
            pUndoDoc->InitUndo( &aDocument, aDestArea.nTab, aDestArea.nTab );
            pUndoDoc->InitUndo( &m_aDocument, aDestArea.nTab, aDestArea.nTab );

            aDocument.CopyToDocument(aDestArea.nColStart, aDestArea.nRowStart, aDestArea.nTab,
            m_aDocument.CopyToDocument(aDestArea.nColStart, aDestArea.nRowStart, aDestArea.nTab,
                                     aDestArea.nColEnd, aDestArea.nRowEnd, aDestArea.nTab,
                                     InsertDeleteFlags::ALL, false, *pUndoDoc);

            // old output range
            if (pDestData)
                aDocument.CopyToDocument(aOldDest, InsertDeleteFlags::ALL, false, *pUndoDoc);
                m_aDocument.CopyToDocument(aOldDest, InsertDeleteFlags::ALL, false, *pUndoDoc);

            GetUndoManager()->AddUndoAction(
                    new ScUndoConsolidate( this, aDestArea, rParam, pUndoDoc,
@@ -624,13 +624,13 @@ void ScDocShell::DoConsolidate( const ScConsolidateParam& rParam, bool bRecord )

    if (pDestData)                                      // delete / adjust destination range
    {
        aDocument.DeleteAreaTab(aOldDest, InsertDeleteFlags::CONTENTS);
        m_aDocument.DeleteAreaTab(aOldDest, InsertDeleteFlags::CONTENTS);
        pDestData->SetArea( rParam.nTab, rParam.nCol, rParam.nRow,
                            rParam.nCol + nColSize - 1, rParam.nRow + nRowSize - 1 );
        pDestData->SetHeader( rParam.bByRow );
    }

    aData.OutputToDocument( &aDocument, rParam.nCol, rParam.nRow, rParam.nTab );
    aData.OutputToDocument( &m_aDocument, rParam.nCol, rParam.nRow, rParam.nTab );

    SCCOL nPaintStartCol = rParam.nCol;
    SCROW nPaintStartRow = rParam.nRow;
@@ -662,29 +662,29 @@ void ScDocShell::DoConsolidate( const ScConsolidateParam& rParam, bool bRecord )

void ScDocShell::UseScenario( SCTAB nTab, const OUString& rName, bool bRecord )
{
    if (!aDocument.IsScenario(nTab))
    if (!m_aDocument.IsScenario(nTab))
    {
        SCTAB   nTabCount = aDocument.GetTableCount();
        SCTAB   nTabCount = m_aDocument.GetTableCount();
        SCTAB   nSrcTab = SCTAB_MAX;
        SCTAB   nEndTab = nTab;
        OUString aCompare;
        while ( nEndTab+1 < nTabCount && aDocument.IsScenario(nEndTab+1) )
        while ( nEndTab+1 < nTabCount && m_aDocument.IsScenario(nEndTab+1) )
        {
            ++nEndTab;
            if (nSrcTab > MAXTAB)           // still searching for the scenario?
            {
                aDocument.GetName( nEndTab, aCompare );
                m_aDocument.GetName( nEndTab, aCompare );
                if (aCompare == rName)
                    nSrcTab = nEndTab;      // found
            }
        }
        if (ValidTab(nSrcTab))
        {
            if ( aDocument.TestCopyScenario( nSrcTab, nTab ) )          // test cell protection
            if ( m_aDocument.TestCopyScenario( nSrcTab, nTab ) )          // test cell protection
            {
                ScDocShellModificator aModificator( *this );
                ScMarkData aScenMark;
                aDocument.MarkScenario( nSrcTab, nTab, aScenMark );
                m_aDocument.MarkScenario( nSrcTab, nTab, aScenMark );
                ScRange aMultiRange;
                aScenMark.GetMultiMarkArea( aMultiRange );
                SCCOL nStartCol = aMultiRange.aStart.Col();
@@ -695,9 +695,9 @@ void ScDocShell::UseScenario( SCTAB nTab, const OUString& rName, bool bRecord )
                if (bRecord)
                {
                    ScDocument* pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
                    pUndoDoc->InitUndo( &aDocument, nTab,nEndTab );             // also all scenarios
                    pUndoDoc->InitUndo( &m_aDocument, nTab,nEndTab );             // also all scenarios
                    //  shown table:
                    aDocument.CopyToDocument(nStartCol, nStartRow, nTab,
                    m_aDocument.CopyToDocument(nStartCol, nStartRow, nTab,
                                             nEndCol, nEndRow, nTab, InsertDeleteFlags::ALL,
                                             true, *pUndoDoc, &aScenMark);
                    //  scenarios
@@ -707,13 +707,13 @@ void ScDocShell::UseScenario( SCTAB nTab, const OUString& rName, bool bRecord )
                        OUString aComment;
                        Color  aColor;
                        ScScenarioFlags nScenFlags;
                        aDocument.GetScenarioData( i, aComment, aColor, nScenFlags );
                        m_aDocument.GetScenarioData( i, aComment, aColor, nScenFlags );
                        pUndoDoc->SetScenarioData( i, aComment, aColor, nScenFlags );
                        bool bActive = aDocument.IsActiveScenario( i );
                        bool bActive = m_aDocument.IsActiveScenario( i );
                        pUndoDoc->SetActiveScenario( i, bActive );
                        //  At copy-back scenarios also contents
                        if ( nScenFlags & ScScenarioFlags::TwoWay )
                            aDocument.CopyToDocument(0, 0, i, MAXCOL, MAXROW, i,
                            m_aDocument.CopyToDocument(0, 0, i, MAXCOL, MAXROW, i,
                                                     InsertDeleteFlags::ALL, false, *pUndoDoc );
                    }

@@ -723,10 +723,10 @@ void ScDocShell::UseScenario( SCTAB nTab, const OUString& rName, bool bRecord )
                                        pUndoDoc, rName ) );
                }

                aDocument.CopyScenario( nSrcTab, nTab );
                m_aDocument.CopyScenario( nSrcTab, nTab );

                sc::SetFormulaDirtyContext aCxt;
                aDocument.SetAllFormulasDirty(aCxt);
                m_aDocument.SetAllFormulasDirty(aCxt);

                //  paint all, because the active scenario may be modified in other ranges;
                //! only if there are visible frames?
@@ -762,11 +762,11 @@ void ScDocShell::ModifyScenario( SCTAB nTab, const OUString& rName, const OUStri
{
    //  Undo
    OUString aOldName;
    aDocument.GetName( nTab, aOldName );
    m_aDocument.GetName( nTab, aOldName );
    OUString aOldComment;
    Color aOldColor;
    ScScenarioFlags nOldFlags;
    aDocument.GetScenarioData( nTab, aOldComment, aOldColor, nOldFlags );
    m_aDocument.GetScenarioData( nTab, aOldComment, aOldColor, nOldFlags );
    GetUndoManager()->AddUndoAction(
        new ScUndoScenarioFlags(this, nTab,
                aOldName, rName, aOldComment, rComment,
@@ -774,8 +774,8 @@ void ScDocShell::ModifyScenario( SCTAB nTab, const OUString& rName, const OUStri

    //  execute
    ScDocShellModificator aModificator( *this );
    aDocument.RenameTab( nTab, rName );
    aDocument.SetScenarioData( nTab, rComment, rColor, nFlags );
    m_aDocument.RenameTab( nTab, rName );
    m_aDocument.SetScenarioData( nTab, rComment, rColor, nFlags );
    PostPaintGridAll();
    aModificator.SetDocumentModified();

@@ -795,7 +795,7 @@ SCTAB ScDocShell::MakeScenario( SCTAB nTab, const OUString& rName, const OUStrin
    if (rMark.IsMultiMarked())
    {
        SCTAB nNewTab = nTab + 1;
        while (aDocument.IsScenario(nNewTab))
        while (m_aDocument.IsScenario(nNewTab))
            ++nNewTab;

        bool bCopyAll = ( (nFlags & ScScenarioFlags::CopyAll) != ScScenarioFlags::NONE );
@@ -806,9 +806,9 @@ SCTAB ScDocShell::MakeScenario( SCTAB nTab, const OUString& rName, const OUStrin
        ScDocShellModificator aModificator( *this );

        if (bRecord)
            aDocument.BeginDrawUndo();      // drawing layer must do its own undo actions
            m_aDocument.BeginDrawUndo();      // drawing layer must do its own undo actions

        if (aDocument.CopyTab( nTab, nNewTab, pCopyMark ))
        if (m_aDocument.CopyTab( nTab, nNewTab, pCopyMark ))
        {
            if (bRecord)
            {
@@ -817,29 +817,29 @@ SCTAB ScDocShell::MakeScenario( SCTAB nTab, const OUString& rName, const OUStrin
                                                rName, rComment, rColor, nFlags, rMark ));
            }

            aDocument.RenameTab( nNewTab, rName);
            aDocument.SetScenario( nNewTab, true );
            aDocument.SetScenarioData( nNewTab, rComment, rColor, nFlags );
            m_aDocument.RenameTab( nNewTab, rName);
            m_aDocument.SetScenario( nNewTab, true );
            m_aDocument.SetScenarioData( nNewTab, rComment, rColor, nFlags );

            ScMarkData aDestMark = rMark;
            aDestMark.SelectOneTable( nNewTab );

            //!     test for filter / buttons / merging

            ScPatternAttr aProtPattern( aDocument.GetPool() );
            ScPatternAttr aProtPattern( m_aDocument.GetPool() );
            aProtPattern.GetItemSet().Put( ScProtectionAttr( true ) );
            aDocument.ApplyPatternAreaTab( 0,0, MAXCOL,MAXROW, nNewTab, aProtPattern );
            m_aDocument.ApplyPatternAreaTab( 0,0, MAXCOL,MAXROW, nNewTab, aProtPattern );

            ScPatternAttr aPattern( aDocument.GetPool() );
            ScPatternAttr aPattern( m_aDocument.GetPool() );
            aPattern.GetItemSet().Put( ScMergeFlagAttr( ScMF::Scenario ) );
            aPattern.GetItemSet().Put( ScProtectionAttr( true ) );
            aDocument.ApplySelectionPattern( aPattern, aDestMark );
            m_aDocument.ApplySelectionPattern( aPattern, aDestMark );

            if (!bCopyAll)
                aDocument.SetVisible( nNewTab, false );
                m_aDocument.SetVisible( nNewTab, false );

            //  this is the active scenario, then
            aDocument.CopyScenario( nNewTab, nTab, true );  // sal_True - don't copy anything from scenario
            m_aDocument.CopyScenario( nNewTab, nTab, true );  // sal_True - don't copy anything from scenario

            if (nFlags & ScScenarioFlags::ShowFrame)
                PostPaint( 0,0,nTab, MAXCOL,MAXROW,nTab, PaintPartFlags::Grid );  // paint frames
@@ -869,12 +869,12 @@ sal_uLong ScDocShell::TransferTab( ScDocShell& rSrcDocShell, SCTAB nSrcPos,
    aParam.maRanges.push_back(aRange);
    rSrcDoc.SetClipParam(aParam);

    sal_uLong nErrVal =  aDocument.TransferTab( &rSrcDoc, nSrcPos, nDestPos,
    sal_uLong nErrVal =  m_aDocument.TransferTab( &rSrcDoc, nSrcPos, nDestPos,
                    bInsertNew );       // no insert

    // TransferTab doesn't copy drawing objects with bInsertNew=FALSE
    if ( nErrVal > 0 && !bInsertNew)
        aDocument.TransferDrawPage( &rSrcDoc, nSrcPos, nDestPos );
        m_aDocument.TransferDrawPage( &rSrcDoc, nSrcPos, nDestPos );

    if(nErrVal>0 && rSrcDoc.IsScenario( nSrcPos ))
    {
@@ -883,18 +883,18 @@ sal_uLong ScDocShell::TransferTab( ScDocShell& rSrcDocShell, SCTAB nSrcPos,
        ScScenarioFlags nFlags;

        rSrcDoc.GetScenarioData( nSrcPos, aComment,aColor, nFlags);
        aDocument.SetScenario(nDestPos,true);
        aDocument.SetScenarioData(nDestPos,aComment,aColor,nFlags);
        m_aDocument.SetScenario(nDestPos,true);
        m_aDocument.SetScenarioData(nDestPos,aComment,aColor,nFlags);
        bool bActive = rSrcDoc.IsActiveScenario(nSrcPos);
        aDocument.SetActiveScenario(nDestPos, bActive );
        m_aDocument.SetActiveScenario(nDestPos, bActive );

        bool bVisible = rSrcDoc.IsVisible(nSrcPos);
        aDocument.SetVisible(nDestPos,bVisible );
        m_aDocument.SetVisible(nDestPos,bVisible );

    }

    if ( nErrVal > 0 && rSrcDoc.IsTabProtected( nSrcPos ) )
        aDocument.SetTabProtection(nDestPos, rSrcDoc.GetTabProtection(nSrcPos));
        m_aDocument.SetTabProtection(nDestPos, rSrcDoc.GetTabProtection(nSrcPos));
    if ( bNotifyAndPaint )
    {
            Broadcast( ScTablesHint( SC_TAB_INSERTED, nDestPos ) );
@@ -910,17 +910,17 @@ bool ScDocShell::MoveTable( SCTAB nSrcTab, SCTAB nDestTab, bool bCopy, bool bRec

    // #i92477# be consistent with ScDocFunc::InsertTable: any index past the last sheet means "append"
    // #i101139# nDestTab must be the target position, not APPEND (for CopyTabProtection etc.)
    if ( nDestTab >= aDocument.GetTableCount() )
        nDestTab = aDocument.GetTableCount();
    if ( nDestTab >= m_aDocument.GetTableCount() )
        nDestTab = m_aDocument.GetTableCount();

    if (bCopy)
    {
        if (bRecord)
            aDocument.BeginDrawUndo();          // drawing layer must do its own undo actions
            m_aDocument.BeginDrawUndo();          // drawing layer must do its own undo actions

        OUString sSrcCodeName;
        aDocument.GetCodeName( nSrcTab, sSrcCodeName );
        if (!aDocument.CopyTab( nSrcTab, nDestTab ))
        m_aDocument.GetCodeName( nSrcTab, sSrcCodeName );
        if (!m_aDocument.CopyTab( nSrcTab, nDestTab ))
        {
            //! EndDrawUndo?
            return false;
@@ -931,8 +931,8 @@ bool ScDocShell::MoveTable( SCTAB nSrcTab, SCTAB nDestTab, bool bCopy, bool bRec
            if ( nDestTab <= nSrcTab )
                ++nAdjSource;               // new position of source table after CopyTab

            if ( aDocument.IsTabProtected( nAdjSource ) )
                aDocument.CopyTabProtection(nAdjSource, nDestTab);
            if ( m_aDocument.IsTabProtected( nAdjSource ) )
                m_aDocument.CopyTabProtection(nAdjSource, nDestTab);

            if (bRecord)
            {
@@ -942,7 +942,7 @@ bool ScDocShell::MoveTable( SCTAB nSrcTab, SCTAB nDestTab, bool bCopy, bool bRec
                        new ScUndoCopyTab(this, pSrcList.release(), pDestList.release()));
            }

            bool bVbaEnabled = aDocument.IsInVBAMode();
            bool bVbaEnabled = m_aDocument.IsInVBAMode();
            if ( bVbaEnabled )
            {
                OUString aLibName( "Standard" );
@@ -956,7 +956,7 @@ bool ScDocShell::MoveTable( SCTAB nSrcTab, SCTAB nDestTab, bool bCopy, bool bRec

                SCTAB nTabToUse = nDestTab;
                if ( nDestTab == SC_TAB_APPEND )
                    nTabToUse = aDocument.GetMaxTableNumber() - 1;
                    nTabToUse = m_aDocument.GetMaxTableNumber() - 1;
                OUString sSource;
                try
                {
@@ -974,14 +974,14 @@ bool ScDocShell::MoveTable( SCTAB nSrcTab, SCTAB nDestTab, bool bCopy, bool bRec
                catch ( const css::uno::Exception& )
                {
                }
                VBA_InsertModule( aDocument, nTabToUse, sSource );
                VBA_InsertModule( m_aDocument, nTabToUse, sSource );
            }
        }
        Broadcast( ScTablesHint( SC_TAB_COPIED, nSrcTab, nDestTab ) );
    }
    else
    {
        if ( aDocument.GetChangeTrack() )
        if ( m_aDocument.GetChangeTrack() )
            return false;

        if ( nSrcTab<nDestTab && nDestTab!=SC_TAB_APPEND )
@@ -994,8 +994,8 @@ bool ScDocShell::MoveTable( SCTAB nSrcTab, SCTAB nDestTab, bool bCopy, bool bRec
        }

        ScProgress* pProgress = new ScProgress(this, ScResId(STR_UNDO_MOVE_TAB),
                                                aDocument.GetCodeCount(), true);
        bool bDone = aDocument.MoveTab( nSrcTab, nDestTab, pProgress );
                                                m_aDocument.GetCodeCount(), true);
        bool bDone = m_aDocument.MoveTab( nSrcTab, nDestTab, pProgress );
        delete pProgress;
        if (!bDone)
        {
diff --git a/sc/source/ui/docshell/docsh6.cxx b/sc/source/ui/docshell/docsh6.cxx
index cd05ca1..e0a8727 100644
--- a/sc/source/ui/docshell/docsh6.cxx
+++ b/sc/source/ui/docshell/docsh6.cxx
@@ -74,12 +74,12 @@ static void lcl_SetTopRight( tools::Rectangle& rRect, const Point& rPos )

void ScDocShell::SetVisAreaOrSize( const tools::Rectangle& rVisArea )
{
    bool bNegativePage = aDocument.IsNegativePage( aDocument.GetVisibleTab() );
    bool bNegativePage = m_aDocument.IsNegativePage( m_aDocument.GetVisibleTab() );

    tools::Rectangle aArea = rVisArea;
    // when loading, don't check for negative values, because the sheet orientation
    // might be set later
    if ( !aDocument.IsImportingXML() )
    if ( !m_aDocument.IsImportingXML() )
    {
        if ( ( bNegativePage ? (aArea.Right() > 0) : (aArea.Left() < 0) ) || aArea.Top() < 0 )
        {
@@ -105,7 +105,7 @@ void ScDocShell::SetVisAreaOrSize( const tools::Rectangle& rVisArea )

    //  when loading an ole object, the VisArea is set from the document's
    //  view settings and must be used as-is (document content may not be complete yet).
    if ( !aDocument.IsImportingXML() )
    if ( !m_aDocument.IsImportingXML() )
        SnapVisArea( aArea );

    //TODO/LATER: it's unclear which IPEnv is used here
@@ -121,7 +121,7 @@ void ScDocShell::SetVisAreaOrSize( const tools::Rectangle& rVisArea )
    //TODO/LATER: formerly in SvInplaceObject
    SfxObjectShell::SetVisArea( aArea );

    if (bIsInplace)                     // adjust zoom in the InPlace View
    if (m_bIsInplace)                     // adjust zoom in the InPlace View
    {
        ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell();
        if (pViewSh)
@@ -131,13 +131,13 @@ void ScDocShell::SetVisAreaOrSize( const tools::Rectangle& rVisArea )
        }
    }

    if (aDocument.IsEmbedded())
    if (m_aDocument.IsEmbedded())
    {
        ScRange aOld;
        aDocument.GetEmbedded( aOld);
        aDocument.SetEmbedded( aDocument.GetVisibleTab(), aArea );
        m_aDocument.GetEmbedded( aOld);
        m_aDocument.SetEmbedded( m_aDocument.GetVisibleTab(), aArea );
        ScRange aNew;
        aDocument.GetEmbedded( aNew);
        m_aDocument.GetEmbedded( aNew);
        if (aOld != aNew)
            PostPaint(0,0,0,MAXCOL,MAXROW,MAXTAB,PaintPartFlags::Grid);

@@ -164,19 +164,19 @@ void ScDocShell::UpdateOle( const ScViewData* pViewData, bool bSnapSize )
    tools::Rectangle aOldArea = SfxObjectShell::GetVisArea();
    tools::Rectangle aNewArea = aOldArea;

    bool bEmbedded = aDocument.IsEmbedded();
    bool bEmbedded = m_aDocument.IsEmbedded();
    if (bEmbedded)
        aNewArea = aDocument.GetEmbeddedRect();
        aNewArea = m_aDocument.GetEmbeddedRect();
    else
    {
        SCTAB nTab = pViewData->GetTabNo();
        if ( nTab != aDocument.GetVisibleTab() )
            aDocument.SetVisibleTab( nTab );
        if ( nTab != m_aDocument.GetVisibleTab() )
            m_aDocument.SetVisibleTab( nTab );

        bool bNegativePage = aDocument.IsNegativePage( nTab );
        bool bNegativePage = m_aDocument.IsNegativePage( nTab );
        SCCOL nX = pViewData->GetPosX(SC_SPLIT_LEFT);
        SCROW nY = pViewData->GetPosY(SC_SPLIT_BOTTOM);
        tools::Rectangle aMMRect = aDocument.GetMMRect( nX,nY, nX,nY, nTab );
        tools::Rectangle aMMRect = m_aDocument.GetMMRect( nX,nY, nX,nY, nTab );
        if (bNegativePage)
            lcl_SetTopRight( aNewArea, aMMRect.TopRight() );
        else
@@ -193,7 +193,7 @@ void ScDocShell::UpdateOle( const ScViewData* pViewData, bool bSnapSize )

SfxStyleSheetBasePool* ScDocShell::GetStyleSheetPool()
{
    return static_cast<SfxStyleSheetBasePool*>(aDocument.GetStyleSheetPool());
    return static_cast<SfxStyleSheetBasePool*>(m_aDocument.GetStyleSheetPool());
}

//  After loading styles from another document (LoadStyles, Insert), the SetItems
@@ -230,12 +230,12 @@ static void lcl_AdjustPool( SfxStyleSheetBasePool* pStylePool )

void ScDocShell::LoadStyles( SfxObjectShell &rSource )
{
    aDocument.StylesToNames();
    m_aDocument.StylesToNames();

    SfxObjectShell::LoadStyles(rSource);
    lcl_AdjustPool( GetStyleSheetPool() );      // adjust SetItems

    aDocument.UpdStlShtPtrsFrmNms();
    m_aDocument.UpdStlShtPtrsFrmNms();

    UpdateAllRowHeights();

@@ -252,7 +252,7 @@ void ScDocShell::LoadStylesArgs( ScDocShell& rSource, bool bReplace, bool bCellS
        return;

    ScStyleSheetPool* pSourcePool = rSource.GetDocument().GetStyleSheetPool();
    ScStyleSheetPool* pDestPool = aDocument.GetStyleSheetPool();
    ScStyleSheetPool* pDestPool = m_aDocument.GetStyleSheetPool();

    SfxStyleFamily eFamily = bCellStyles ?
            ( bPageStyles ? SfxStyleFamily::All : SfxStyleFamily::Para ) :
@@ -310,7 +310,7 @@ void ScDocShell::LoadStylesArgs( ScDocShell& rSource, bool bReplace, bool bCellS

void ScDocShell::ReconnectDdeLink(SfxObjectShell& rServer)
{
    ::sfx2::LinkManager* pLinkManager = aDocument.GetLinkManager();
    ::sfx2::LinkManager* pLinkManager = m_aDocument.GetLinkManager();
    if (!pLinkManager)
        return;

@@ -321,7 +321,7 @@ void ScDocShell::UpdateLinks()
{
    typedef std::unordered_set<OUString> StrSetType;

    sfx2::LinkManager* pLinkManager = aDocument.GetLinkManager();
    sfx2::LinkManager* pLinkManager = m_aDocument.GetLinkManager();
    StrSetType aNames;

    // out with the no longer used links
@@ -345,23 +345,23 @@ void ScDocShell::UpdateLinks()

    // enter new links

    SCTAB nTabCount = aDocument.GetTableCount();
    SCTAB nTabCount = m_aDocument.GetTableCount();
    for (SCTAB i = 0; i < nTabCount; ++i)
    {
        if (!aDocument.IsLinked(i))
        if (!m_aDocument.IsLinked(i))
            continue;

        OUString aDocName = aDocument.GetLinkDoc(i);
        OUString aFltName = aDocument.GetLinkFlt(i);
        OUString aOptions = aDocument.GetLinkOpt(i);
        sal_uLong nRefresh  = aDocument.GetLinkRefreshDelay(i);
        OUString aDocName = m_aDocument.GetLinkDoc(i);
        OUString aFltName = m_aDocument.GetLinkFlt(i);
        OUString aOptions = m_aDocument.GetLinkOpt(i);
        sal_uLong nRefresh  = m_aDocument.GetLinkRefreshDelay(i);
        bool bThere = false;
        for (SCTAB j = 0; j < i && !bThere; ++j)                // several times in the document?
        {
            if (aDocument.IsLinked(j)
                    && aDocument.GetLinkDoc(j) == aDocName
                    && aDocument.GetLinkFlt(j) == aFltName
                    && aDocument.GetLinkOpt(j) == aOptions)
            if (m_aDocument.IsLinked(j)
                    && m_aDocument.GetLinkDoc(j) == aDocName
                    && m_aDocument.GetLinkFlt(j) == aFltName
                    && m_aDocument.GetLinkOpt(j) == aOptions)
                    // Ignore refresh delay in compare, it should be the
                    // same for identical links and we don't want dupes
                    // if it ain't.
@@ -387,7 +387,7 @@ void ScDocShell::UpdateLinks()

void ScDocShell::ReloadTabLinks()
{
    sfx2::LinkManager* pLinkManager = aDocument.GetLinkManager();
    sfx2::LinkManager* pLinkManager = m_aDocument.GetLinkManager();

    bool bAny = false;
    size_t nCount = pLinkManager->GetLinks().size();
@@ -420,7 +420,7 @@ void ScDocShell::ReloadTabLinks()

void ScDocShell::SetFormulaOptions( const ScFormulaOptions& rOpt, bool bForLoading )
{
    aDocument.SetGrammar( rOpt.GetFormulaSyntax() );
    m_aDocument.SetGrammar( rOpt.GetFormulaSyntax() );

    // This is nasty because it resets module globals from within a docshell!
    // For actual damage caused see fdo#82183 where an unconditional
@@ -468,7 +468,7 @@ void ScDocShell::SetFormulaOptions( const ScFormulaOptions& rOpt, bool bForLoadi
    }

    // Per document interpreter settings.
    aDocument.SetCalcConfig( rOpt.GetCalcConfig() );
    m_aDocument.SetCalcConfig( rOpt.GetCalcConfig() );
}

void ScDocShell::CheckConfigOptions()
diff --git a/sc/source/ui/docshell/docsh8.cxx b/sc/source/ui/docshell/docsh8.cxx
index d9631c8..3c5c7b4 100644
--- a/sc/source/ui/docshell/docsh8.cxx
+++ b/sc/source/ui/docshell/docsh8.cxx
@@ -378,10 +378,10 @@ ErrCode ScDocShell::DBaseImport( const OUString& rFullFileName, rtl_TextEncoding
                    break;
            }

            aDocument.SetString( static_cast<SCCOL>(i), 0, 0, aHeader );
            m_aDocument.SetString( static_cast<SCCOL>(i), 0, 0, aHeader );
        }

        lcl_setScalesToColumns(aDocument, aScales);
        lcl_setScalesToColumns(m_aDocument, aScales);

        SCROW nRow = 1;     // 0 is column titles
        bool bEnd = false;
@@ -394,7 +394,7 @@ ErrCode ScDocShell::DBaseImport( const OUString& rFullFileName, rtl_TextEncoding
                for (i=0; i<nColCount; i++)
                {
                    ScDatabaseDocUtil::StrData aStrData;
                    ScDatabaseDocUtil::PutData( &aDocument, nCol, nRow, 0,
                    ScDatabaseDocUtil::PutData( &m_aDocument, nCol, nRow, 0,
                                                xRow, i+1, pTypeArr[i], false,
                                                &aStrData );

@@ -751,20 +751,20 @@ ErrCode ScDocShell::DBaseExport( const OUString& rFullFileName, rtl_TextEncoding
    SCCOL nFirstCol, nLastCol;
    SCROW  nFirstRow, nLastRow;
    SCTAB nTab = GetSaveTab();
    aDocument.GetDataStart( nTab, nFirstCol, nFirstRow );
    aDocument.GetCellArea( nTab, nLastCol, nLastRow );
    m_aDocument.GetDataStart( nTab, nFirstCol, nFirstRow );
    m_aDocument.GetCellArea( nTab, nLastCol, nLastRow );
    if ( nFirstCol > nLastCol )
        nFirstCol = nLastCol;
    if ( nFirstRow > nLastRow )
        nFirstRow = nLastRow;
    ScProgress aProgress( this, ScResId( STR_SAVE_DOC ),
                                                    nLastRow - nFirstRow, true );
    SvNumberFormatter* pNumFmt = aDocument.GetFormatTable();
    SvNumberFormatter* pNumFmt = m_aDocument.GetFormatTable();

    bool bHasFieldNames = true;
    for ( SCCOL nDocCol = nFirstCol; nDocCol <= nLastCol && bHasFieldNames; nDocCol++ )
    {   // only Strings in first row => are field names
        if ( !aDocument.HasStringData( nDocCol, nFirstRow, nTab ) )
        if ( !m_aDocument.HasStringData( nDocCol, nFirstRow, nTab ) )
            bHasFieldNames = false;
    }

@@ -781,7 +781,7 @@ ErrCode ScDocShell::DBaseExport( const OUString& rFullFileName, rtl_TextEncoding
                        bHasMemo, eCharSet );
    // also needed for exception catch
    SCROW nDocRow = 0;
    ScFieldEditEngine aEditEngine(&aDocument, aDocument.GetEditPool());
    ScFieldEditEngine aEditEngine(&m_aDocument, m_aDocument.GetEditPool());
    OUString aString;
    OUString aTabName;

@@ -908,7 +908,7 @@ ErrCode ScDocShell::DBaseExport( const OUString& rFullFileName, rtl_TextEncoding
                {
                    case sdbc::DataType::LONGVARCHAR:
                    {
                        ScRefCellValue aCell(aDocument, ScAddress(nDocCol, nDocRow, nTab));
                        ScRefCellValue aCell(m_aDocument, ScAddress(nDocCol, nDocRow, nTab));
                        if (!aCell.isEmpty())
                        {
                            if (aCell.meType == CELLTYPE_EDIT)
@@ -918,7 +918,7 @@ ErrCode ScDocShell::DBaseExport( const OUString& rFullFileName, rtl_TextEncoding
                            else
                            {
                                lcl_getLongVarCharString(
                                    aString, aDocument, nDocCol, nDocRow, nTab, *pNumFmt);
                                    aString, m_aDocument, nDocCol, nDocRow, nTab, *pNumFmt);
                            }
                            xRowUpdate->updateString( nCol+1, aString );
                        }
@@ -928,7 +928,7 @@ ErrCode ScDocShell::DBaseExport( const OUString& rFullFileName, rtl_TextEncoding
                    break;

                    case sdbc::DataType::VARCHAR:
                        aString = aDocument.GetString(nDocCol, nDocRow, nTab);
                        aString = m_aDocument.GetString(nDocCol, nDocRow, nTab);
                        xRowUpdate->updateString( nCol+1, aString );
                        if ( nErr == ERRCODE_NONE && pColLengths[nCol] < aString.getLength() )
                            nErr = SCWARN_EXPORT_DATALOST;
@@ -936,16 +936,16 @@ ErrCode ScDocShell::DBaseExport( const OUString& rFullFileName, rtl_TextEncoding

                    case sdbc::DataType::DATE:
                        {
                            aDocument.GetValue( nDocCol, nDocRow, nTab, fVal );
                            m_aDocument.GetValue( nDocCol, nDocRow, nTab, fVal );
                            // differentiate between 0 with value and 0 no-value
                            bool bIsNull = (fVal == 0.0);
                            if ( bIsNull )
                                bIsNull = !aDocument.HasValueData( nDocCol, nDocRow, nTab );
                                bIsNull = !m_aDocument.HasValueData( nDocCol, nDocRow, nTab );
                            if ( bIsNull )
                            {
                                xRowUpdate->updateNull( nCol+1 );
                                if ( nErr == ERRCODE_NONE &&
                                        aDocument.HasStringData( nDocCol, nDocRow, nTab ) )
                                        m_aDocument.HasStringData( nDocCol, nDocRow, nTab ) )
                                    nErr = SCWARN_EXPORT_DATALOST;
                            }
                            else
@@ -959,9 +959,9 @@ ErrCode ScDocShell::DBaseExport( const OUString& rFullFileName, rtl_TextEncoding

                    case sdbc::DataType::DECIMAL:
                    case sdbc::DataType::BIT:
                        aDocument.GetValue( nDocCol, nDocRow, nTab, fVal );
                        m_aDocument.GetValue( nDocCol, nDocRow, nTab, fVal );
                        if ( fVal == 0.0 && nErr == ERRCODE_NONE &&
                                            aDocument.HasStringData( nDocCol, nDocRow, nTab ) )
                                            m_aDocument.HasStringData( nDocCol, nDocRow, nTab ) )
                            nErr = SCWARN_EXPORT_DATALOST;
                        if ( pColTypes[nCol] == sdbc::DataType::BIT )
                            xRowUpdate->updateBoolean( nCol+1, ( fVal != 0.0 ) );
@@ -973,7 +973,7 @@ ErrCode ScDocShell::DBaseExport( const OUString& rFullFileName, rtl_TextEncoding
                        OSL_FAIL( "ScDocShell::DBaseExport: unknown FieldType" );
                        if ( nErr == ERRCODE_NONE )
                            nErr = SCWARN_EXPORT_DATALOST;
                        aDocument.GetValue( nDocCol, nDocRow, nTab, fVal );
                        m_aDocument.GetValue( nDocCol, nDocRow, nTab, fVal );
                        xRowUpdate->updateDouble( nCol+1, fVal );
                }
            }
@@ -1005,7 +1005,7 @@ ErrCode ScDocShell::DBaseExport( const OUString& rFullFileName, rtl_TextEncoding
            SCCOL nDocCol = nFirstCol;
            const sal_Int32* pColTypes = aColTypes.getConstArray();
            const sal_Int32* pColLengths = aColLengths.getConstArray();
            ScHorizontalCellIterator aIter( &aDocument, nTab, nFirstCol,
            ScHorizontalCellIterator aIter( &m_aDocument, nTab, nFirstCol,
                    nDocRow, nLastCol, nDocRow);
            ScRefCellValue* pCell = nullptr;
            bool bTest = true;
@@ -1020,12 +1020,12 @@ ErrCode ScDocShell::DBaseExport( const OUString& rFullFileName, rtl_TextEncoding
                                lcl_getLongVarCharEditString(aString, *pCell, aEditEngine);
                            else
                                lcl_getLongVarCharString(
                                    aString, aDocument, nDocCol, nDocRow, nTab, *pNumFmt);
                                    aString, m_aDocument, nDocCol, nDocRow, nTab, *pNumFmt);
                        }
                        break;

                    case sdbc::DataType::VARCHAR:
                        aString = aDocument.GetString(nDocCol, nDocRow, nTab);
                        aString = m_aDocument.GetString(nDocCol, nDocRow, nTab);
                        break;

                    // NOTE: length of DECIMAL fields doesn't need to be
diff --git a/sc/source/ui/inc/docsh.hxx b/sc/source/ui/inc/docsh.hxx
index 55cbdb9..f8f5c33 100644
--- a/sc/source/ui/inc/docsh.hxx
+++ b/sc/source/ui/inc/docsh.hxx
@@ -85,34 +85,34 @@ enum class LOKCommentNotificationType { Add, Modify, Remove };

class SC_DLLPUBLIC ScDocShell final: public SfxObjectShell, public SfxListener
{
    ScDocument          aDocument;
    ScDocument          m_aDocument;

    OUString            aDdeTextFmt;
    OUString            m_aDdeTextFmt;

    double              nPrtToScreenFactor;
    DocShell_Impl*      pImpl;
    ScDocFunc*          pDocFunc;
    double              m_nPrtToScreenFactor;
    DocShell_Impl*      m_pImpl;
    ScDocFunc*          m_pDocFunc;

    bool                bHeaderOn;
    bool                bFooterOn;
    bool                bIsInplace:1;         // Is set by the View
    bool                bIsEmpty:1;
    bool                bIsInUndo:1;
    bool                bDocumentModifiedPending:1;
    bool                bUpdateEnabled:1;
    bool                mbUcalcTest:1; // avoid loading the styles in the ucalc test
    sal_uInt16          nDocumentLock;
    sal_Int16           nCanUpdate;  // stores the UpdateDocMode from loading a document till update links
    bool                m_bHeaderOn;
    bool                m_bFooterOn;
    bool                m_bIsInplace:1;         // Is set by the View
    bool                m_bIsEmpty:1;
    bool                m_bIsInUndo:1;
    bool                m_bDocumentModifiedPending:1;
    bool                m_bUpdateEnabled:1;
    bool                m_bUcalcTest:1; // avoid loading the styles in the ucalc test
    sal_uInt16          m_nDocumentLock;
    sal_Int16           m_nCanUpdate;  // stores the UpdateDocMode from loading a document till update links

    ScDBData*           pOldAutoDBRange;
    ScDBData*           m_pOldAutoDBRange;

    ScAutoStyleList*    pAutoStyleList;
    ScPaintLockData*    pPaintLockData;
    ScOptSolverSave*    pSolverSaveData;
    ScSheetSaveData*    pSheetSaveData;
    ScFormatSaveData*   mpFormatSaveData;
    ScAutoStyleList*    m_pAutoStyleList;
    ScPaintLockData*    m_pPaintLockData;
    ScOptSolverSave*    m_pSolverSaveData;
    ScSheetSaveData*    m_pSheetSaveData;
    ScFormatSaveData*   m_pFormatSaveData;

    ScDocShellModificator* pModificator; // #109979#; is used to load XML (created in BeforeXMLLoading and destroyed in AfterXMLLoading)
    ScDocShellModificator* m_pModificator; // #109979#; is used to load XML (created in BeforeXMLLoading and destroyed in AfterXMLLoading)

    css::uno::Reference< ooo::vba::excel::XWorkbook> mxAutomationWorkbookObject;

@@ -223,8 +223,8 @@ public:

    void    GetDocStat( ScDocStat& rDocStat );

    ScDocument&     GetDocument()   { return aDocument; }
    ScDocFunc&      GetDocFunc()    { return *pDocFunc; }
    ScDocument&     GetDocument()   { return m_aDocument; }
    ScDocFunc&      GetDocFunc()    { return *m_pDocFunc; }

    css::uno::Reference<css::datatransfer::XTransferable2> GetClipData() { return m_xClipData; }
    void SetClipData(const css::uno::Reference<css::datatransfer::XTransferable2>& xTransferable) { m_xClipData = xTransferable; }
@@ -325,7 +325,7 @@ public:
    void            PostPaintGridAll();
    void            PostPaintExtras();

    bool            IsPaintLocked() const { return pPaintLockData != nullptr; }
    bool            IsPaintLocked() const { return m_pPaintLockData != nullptr; }

    void            PostDataChanged();

@@ -338,7 +338,7 @@ public:

    void            LockPaint();
    void            UnlockPaint();
    sal_uInt16          GetLockCount() const { return nDocumentLock;}
    sal_uInt16          GetLockCount() const { return m_nDocumentLock;}
    void            SetLockCount(sal_uInt16 nNew);

    void            LockDocument();
@@ -350,14 +350,14 @@ public:
    virtual SfxStyleSheetBasePool*  GetStyleSheetPool() override;

    void            SetInplace( bool bInplace );
    bool            IsEmpty() const { return bIsEmpty; }
    bool            IsEmpty() const { return m_bIsEmpty; }
    void            SetEmpty(bool bSet);

    bool            IsInUndo() const                { return bIsInUndo; }
    bool            IsInUndo() const                { return m_bIsInUndo; }
    void            SetInUndo(bool bSet);

    void            CalcOutputFactor();
    double          GetOutputFactor() const { return nPrtToScreenFactor;}
    double          GetOutputFactor() const { return m_nPrtToScreenFactor;}
    void            GetPageOnFromPageStyleSet( const SfxItemSet* pStyleSet,
                                               SCTAB             nCurTab,
                                               bool&             rbHeader,
@@ -372,21 +372,21 @@ public:

    virtual ::sfx2::SvLinkSource* DdeCreateLinkSource( const OUString& rItem ) override;

    const OUString& GetDdeTextFmt() const { return aDdeTextFmt; }
    const OUString& GetDdeTextFmt() const { return m_aDdeTextFmt; }

    SfxBindings*    GetViewBindings();

    ScTabViewShell* GetBestViewShell( bool bOnlyVisible = true );

    void            SetDocumentModifiedPending( bool bVal )
                        { bDocumentModifiedPending = bVal; }
                        { m_bDocumentModifiedPending = bVal; }
    bool            IsDocumentModifiedPending() const
                        { return bDocumentModifiedPending; }
                        { return m_bDocumentModifiedPending; }

    bool            IsUpdateEnabled() const
                        { return bUpdateEnabled; }
                        { return m_bUpdateEnabled; }
    void            SetUpdateEnabled(bool bValue)
                        { bUpdateEnabled = bValue; }
                        { m_bUpdateEnabled = bValue; }

    OutputDevice*   GetRefDevice(); // WYSIWYG: Printer, otherwise VirtualDevice...

@@ -411,7 +411,7 @@ public:

    virtual HiddenInformation GetHiddenInformationState( HiddenInformation nStates ) override;

    const ScOptSolverSave* GetSolverSaveData() const    { return pSolverSaveData; }     // may be null
    const ScOptSolverSave* GetSolverSaveData() const    { return m_pSolverSaveData; }     // may be null
    void            SetSolverSaveData( const ScOptSolverSave& rData );
    ScSheetSaveData* GetSheetSaveData();
    ScFormatSaveData* GetFormatSaveData();