tdf#107870 sw: don't jump to cursor setting Record Changes

Using Edit->Track Changes->Record or Record Tracked Changes on
Track Changes toolbar scrolled the pages back to the text
cursor, breaking the review process of the document.

Change-Id: I890e845ff94b636dd6edae19969d913e8d7a7b65
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107005
Tested-by: László Németh <nemeth@numbertext.org>
Reviewed-by: László Németh <nemeth@numbertext.org>
(cherry picked from commit 1fd0919d92e792fa4af209a0fc7fde55c9958d1a)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107103
Tested-by: Jenkins
diff --git a/include/sfx2/objsh.hxx b/include/sfx2/objsh.hxx
index 40ab5b4..ee3d3d6 100644
--- a/include/sfx2/objsh.hxx
+++ b/include/sfx2/objsh.hxx
@@ -671,7 +671,7 @@ public:
    // slots used for Calc:         FID_CHG_RECORD, SID_CHG_PROTECT
    virtual bool    IsChangeRecording() const;
    virtual bool    HasChangeRecordProtection() const;
    virtual void    SetChangeRecording( bool bActivate );
    virtual void    SetChangeRecording( bool bActivate, bool bLockAllViews = false );
    virtual void    SetProtectionPassword( const OUString &rPassword );
    virtual bool    GetProtectionHash( /*out*/ css::uno::Sequence< sal_Int8 > &rPasswordHash );

diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx
index 0d7345e..91020db 100644
--- a/sc/source/ui/docshell/docsh.cxx
+++ b/sc/source/ui/docshell/docsh.cxx
@@ -3190,7 +3190,7 @@ bool ScDocShell::HasChangeRecordProtection() const
    return bRes;
}

void ScDocShell::SetChangeRecording( bool bActivate )
void ScDocShell::SetChangeRecording( bool bActivate, bool /*bLockAllViews*/ )
{
    bool bOldChangeRecording = IsChangeRecording();

diff --git a/sc/source/ui/inc/docsh.hxx b/sc/source/ui/inc/docsh.hxx
index bfdaf85a..41c0b30 100644
--- a/sc/source/ui/inc/docsh.hxx
+++ b/sc/source/ui/inc/docsh.hxx
@@ -418,7 +418,7 @@ public:
    // see also:    FID_CHG_RECORD, SID_CHG_PROTECT
    virtual bool    IsChangeRecording() const override;
    virtual bool    HasChangeRecordProtection() const override;
    virtual void    SetChangeRecording( bool bActivate ) override;
    virtual void    SetChangeRecording( bool bActivate, bool bLockAllViews = false ) override;
    virtual void    SetProtectionPassword( const OUString &rPassword ) override;
    virtual bool    GetProtectionHash( /*out*/ css::uno::Sequence< sal_Int8 > &rPasswordHash ) override;

diff --git a/sfx2/source/doc/objxtor.cxx b/sfx2/source/doc/objxtor.cxx
index d977314..a746d1a 100644
--- a/sfx2/source/doc/objxtor.cxx
+++ b/sfx2/source/doc/objxtor.cxx
@@ -1092,7 +1092,7 @@ bool SfxObjectShell::HasChangeRecordProtection() const
}


void SfxObjectShell::SetChangeRecording( bool /*bActivate*/ )
void SfxObjectShell::SetChangeRecording( bool /*bActivate*/, bool /*bLockAllViews*/ )
{
    // currently this function needs to be overwritten by Writer and Calc only
    SAL_WARN( "sfx.doc", "function not implemented" );
diff --git a/sw/inc/docsh.hxx b/sw/inc/docsh.hxx
index d58a3fd..0700333 100644
--- a/sw/inc/docsh.hxx
+++ b/sw/inc/docsh.hxx
@@ -311,7 +311,7 @@ public:
     see also:    FN_REDLINE_ON, FN_REDLINE_ON */
    virtual bool    IsChangeRecording() const override;
    virtual bool    HasChangeRecordProtection() const override;
    virtual void    SetChangeRecording( bool bActivate ) override;
    virtual void    SetChangeRecording( bool bActivate, bool bLockAllViews = false ) override;
    virtual void    SetProtectionPassword( const OUString &rPassword ) override;
    virtual bool    GetProtectionHash( /*out*/ css::uno::Sequence< sal_Int8 > &rPasswordHash ) override;

diff --git a/sw/source/uibase/app/docsh.cxx b/sw/source/uibase/app/docsh.cxx
index 64564cb..7a9620b 100644
--- a/sw/source/uibase/app/docsh.cxx
+++ b/sw/source/uibase/app/docsh.cxx
@@ -1339,11 +1339,20 @@ bool SwDocShell::HasChangeRecordProtection() const
    return m_pWrtShell->getIDocumentRedlineAccess().GetRedlinePassword().hasElements();
}

void SwDocShell::SetChangeRecording( bool bActivate )
void SwDocShell::SetChangeRecording( bool bActivate, bool bLockAllViews )
{
    RedlineFlags nOn = bActivate ? RedlineFlags::On : RedlineFlags::NONE;
    RedlineFlags nMode = m_pWrtShell->GetRedlineFlags();
    m_pWrtShell->SetRedlineFlagsAndCheckInsMode( (nMode & ~RedlineFlags::On) | nOn );
    if (bLockAllViews)
    {
        // tdf#107870: prevent jumping to cursor
        auto aViewGuard(LockAllViews());
        m_pWrtShell->SetRedlineFlagsAndCheckInsMode( (nMode & ~RedlineFlags::On) | nOn );
    }
    else
    {
        m_pWrtShell->SetRedlineFlagsAndCheckInsMode( (nMode & ~RedlineFlags::On) | nOn );
    }
}

void SwDocShell::SetProtectionPassword( const OUString &rNewPassword )
diff --git a/sw/source/uibase/uiview/view2.cxx b/sw/source/uibase/uiview/view2.cxx
index 4b83a3d..e449253 100644
--- a/sw/source/uibase/uiview/view2.cxx
+++ b/sw/source/uibase/uiview/view2.cxx
@@ -673,13 +673,10 @@ void SwView::Execute(SfxRequest &rReq)
                    }
                }

                const RedlineFlags nOn = static_cast<const SfxBoolItem*>(pItem)->GetValue()
                    ? RedlineFlags::On : RedlineFlags::NONE;
                const RedlineFlags nMode = m_pWrtShell->GetRedlineFlags();
                m_pWrtShell->SetRedlineFlagsAndCheckInsMode( (nMode & ~RedlineFlags::On) | nOn);
                SwDocShell* pDocShell = GetDocShell();
                pDocShell->SetChangeRecording( static_cast<const SfxBoolItem*>(pItem)->GetValue(), /*bLockAllViews=*/true );

                // Notify all view shells of this document, as the track changes mode is document-global.
                SwDocShell* pDocShell = GetDocShell();
                for (SfxViewFrame* pViewFrame = SfxViewFrame::GetFirst(pDocShell); pViewFrame; pViewFrame = SfxViewFrame::GetNext(*pViewFrame, pDocShell))
                {
                    pViewFrame->GetBindings().Invalidate(FN_REDLINE_ON);