diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx index a91270f94bad..43fe3a7960ef 100644 --- a/desktop/qa/desktop_lib/test_desktop_lib.cxx +++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx @@ -180,7 +180,6 @@ public: void testBinaryCallback(); void testInput(); void testRedlineWriter(); - void testTrackChanges(); void testRedlineCalc(); void testPaintPartTile(); void testPaintPartTileDifferentSchemes(); @@ -253,7 +252,6 @@ public: CPPUNIT_TEST(testBinaryCallback); CPPUNIT_TEST(testInput); CPPUNIT_TEST(testRedlineWriter); - CPPUNIT_TEST(testTrackChanges); CPPUNIT_TEST(testRedlineCalc); CPPUNIT_TEST(testPaintPartTile); CPPUNIT_TEST(testPaintPartTileDifferentSchemes); @@ -1039,26 +1037,6 @@ void DesktopLOKTest::testWriterComments() CPPUNIT_ASSERT_EQUAL(u"test"_ustr, xTextField->getPropertyValue(u"Content"_ustr).get()); } -void DesktopLOKTest::testTrackChanges() -{ - // Load a document and create two views. - LibLibreOffice_Impl aOffice; - LibLODocument_Impl* pDocument = loadDoc("blank_text.odt"); - pDocument->pClass->initializeForRendering(pDocument, nullptr); - pDocument->pClass->registerCallback(pDocument, &DesktopLOKTest::callback, this); - pDocument->pClass->createView(pDocument); - pDocument->pClass->initializeForRendering(pDocument, nullptr); - pDocument->pClass->registerCallback(pDocument, &DesktopLOKTest::callback, this); - Scheduler::ProcessEventsToIdle(); - - // Enable track changes and assert that both views get notified. - m_nTrackChanges = 0; - pDocument->pClass->postUnoCommand(pDocument, ".uno:TrackChanges", nullptr, false); - Scheduler::ProcessEventsToIdle(); - // This was 1, only the active view was notified. - CPPUNIT_ASSERT_EQUAL(2, m_nTrackChanges); -} - void DesktopLOKTest::testSheetOperations() { LibLODocument_Impl* pDocument = loadDoc("sheets.ods"); diff --git a/include/sfx2/objsh.hxx b/include/sfx2/objsh.hxx index b06768294cd0..10b85c9964f3 100644 --- a/include/sfx2/objsh.hxx +++ b/include/sfx2/objsh.hxx @@ -694,7 +694,7 @@ public: // change recording and respective passwword protection for Writer and Calc // slots available for Writer: FN_REDLINE_ON, FN_REDLINE_ON // slots used for Calc: FID_CHG_RECORD, SID_CHG_PROTECT - virtual bool IsChangeRecording() const; + virtual bool IsChangeRecording(SfxViewShell* pViewShell = nullptr) const; virtual bool HasChangeRecordProtection() const; virtual void SetChangeRecording( bool bActivate, bool bLockAllViews = false ); virtual void SetProtectionPassword( const OUString &rPassword ); diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx index 1756c5d2b3ca..2157fb18a5aa 100644 --- a/sc/source/ui/docshell/docsh.cxx +++ b/sc/source/ui/docshell/docsh.cxx @@ -3394,7 +3394,7 @@ void ScDocShellModificator::SetDocumentModified() } } -bool ScDocShell::IsChangeRecording() const +bool ScDocShell::IsChangeRecording(SfxViewShell* /*pViewShell*/) const { ScChangeTrack* pChangeTrack = m_pDocument->GetChangeTrack(); return pChangeTrack != nullptr; diff --git a/sc/source/ui/inc/docsh.hxx b/sc/source/ui/inc/docsh.hxx index 046cf75ea3a3..cbab1f0d8c40 100644 --- a/sc/source/ui/inc/docsh.hxx +++ b/sc/source/ui/inc/docsh.hxx @@ -425,7 +425,7 @@ public: // password protection for Calc (derived from SfxObjectShell) // see also: FID_CHG_RECORD, SID_CHG_PROTECT - virtual bool IsChangeRecording() const override; + virtual bool IsChangeRecording(SfxViewShell* pViewShell = nullptr) const override; virtual bool HasChangeRecordProtection() const override; virtual void SetChangeRecording( bool bActivate, bool bLockAllViews = false ) override; virtual void SetProtectionPassword( const OUString &rPassword ) override; diff --git a/sfx2/source/doc/objxtor.cxx b/sfx2/source/doc/objxtor.cxx index 2ff3be238f14..106743ee1850 100644 --- a/sfx2/source/doc/objxtor.cxx +++ b/sfx2/source/doc/objxtor.cxx @@ -1124,7 +1124,7 @@ void SfxObjectShell::SetInitialized_Impl( const bool i_fromInitNew ) } -bool SfxObjectShell::IsChangeRecording() const +bool SfxObjectShell::IsChangeRecording(SfxViewShell* /*pViewShell*/) const { // currently this function needs to be overwritten by Writer and Calc only SAL_WARN( "sfx.doc", "function not implemented" ); diff --git a/sw/inc/IDocumentRedlineAccess.hxx b/sw/inc/IDocumentRedlineAccess.hxx index eeb793530337..ede30c26d39e 100644 --- a/sw/inc/IDocumentRedlineAccess.hxx +++ b/sw/inc/IDocumentRedlineAccess.hxx @@ -38,6 +38,7 @@ class SwPaM; struct SwPosition; class SwStartNode; class SwNode; +class SwViewShell; enum class RedlineFlags { @@ -99,7 +100,7 @@ public: @returns the currently set redline mode */ - virtual RedlineFlags GetRedlineFlags() const = 0; + virtual RedlineFlags GetRedlineFlags(const SwViewShell* pViewShell = nullptr) const = 0; /** Set a new redline mode. diff --git a/sw/inc/docsh.hxx b/sw/inc/docsh.hxx index d755d14e9b67..8bbc54837363 100644 --- a/sw/inc/docsh.hxx +++ b/sw/inc/docsh.hxx @@ -321,7 +321,7 @@ public: /** passwword protection for Writer (derived from SfxObjectShell) see also: FN_REDLINE_ON, FN_REDLINE_ON */ - virtual bool IsChangeRecording() const override; + virtual bool IsChangeRecording(SfxViewShell* pViewShell = nullptr) const override; virtual bool HasChangeRecordProtection() const override; virtual void SetChangeRecording( bool bActivate, bool bLockAllViews = false ) override; virtual void SetProtectionPassword( const OUString &rPassword ) override; diff --git a/sw/qa/extras/tiledrendering/tiledrendering2.cxx b/sw/qa/extras/tiledrendering/tiledrendering2.cxx index dc8f7e733b5c..8da396a393bb 100644 --- a/sw/qa/extras/tiledrendering/tiledrendering2.cxx +++ b/sw/qa/extras/tiledrendering/tiledrendering2.cxx @@ -358,6 +358,156 @@ CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, testLoadVisibleArea) SwPageFrame* pPage3 = pPage2->GetNext()->DynCastPageFrame(); CPPUNIT_ASSERT(pPage3->IsInvalidContent()); } + +std::vector FilterStateChanges(const std::vector& rChanges, + std::string_view rPrefix) +{ + std::vector aRet; + for (const auto& rChange : rChanges) + { + if (rChange.startsWith(rPrefix)) + { + aRet.push_back(rChange); + } + } + return aRet; +} + +CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, testTrackChangesPerViewEnableOne) +{ + // Given a document with two views: + SwXTextDocument* pXTextDocument = createDoc(); + CPPUNIT_ASSERT(pXTextDocument); + SwTestViewCallback aView1; + int nView1 = SfxLokHelper::getView(); + SfxLokHelper::createView(); + SwTestViewCallback aView2; + int nView2 = SfxLokHelper::getView(); + + // When recording changes in view1: + SfxLokHelper::setView(nView1); + aView1.m_aStateChanges.clear(); + aView2.m_aStateChanges.clear(); + comphelper::dispatchCommand(".uno:TrackChanges", {}); + + // Then make sure view1 gets a state track changes state change, but not view2: + // Filter out .uno:ModifiedStatus=true, which is not interesting here. + std::vector aRecord1 = FilterStateChanges(aView1.m_aStateChanges, ".uno:TrackChanges"); + CPPUNIT_ASSERT(!aRecord1.empty()); + std::vector aRecord2 = FilterStateChanges(aView2.m_aStateChanges, ".uno:TrackChanges"); + CPPUNIT_ASSERT(aRecord2.empty()); + + // And given a reset state (both view1 and view2 recording is disabled): + comphelper::dispatchCommand(".uno:TrackChanges", {}); + + // When recording changes in view2: + SfxLokHelper::setView(nView2); + aView1.m_aStateChanges.clear(); + aView2.m_aStateChanges.clear(); + comphelper::dispatchCommand(".uno:TrackChanges", {}); + + // Then make sure view2 gets a state track changes state change, but not view1: + CPPUNIT_ASSERT(aView1.m_aStateChanges.empty()); + CPPUNIT_ASSERT(!aView2.m_aStateChanges.empty()); +} + +CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, testTrackChangesPerViewEnableBoth) +{ + // Given a document with 2 views, view1 record changes: + SwXTextDocument* pXTextDocument = createDoc(); + CPPUNIT_ASSERT(pXTextDocument); + SwTestViewCallback aView1; + int nView1 = SfxLokHelper::getView(); + SwWrtShell* pWrtShell1 = pXTextDocument->GetDocShell()->GetWrtShell(); + SfxLokHelper::createView(); + SwTestViewCallback aView2; + int nView2 = SfxLokHelper::getView(); + SwWrtShell* pWrtShell2 = pXTextDocument->GetDocShell()->GetWrtShell(); + SfxLokHelper::setView(nView1); + comphelper::dispatchCommand(".uno:TrackChanges", {}); + SfxLokHelper::setView(nView2); + CPPUNIT_ASSERT(pWrtShell1->GetViewOptions()->IsRedlineRecordingOn()); + CPPUNIT_ASSERT(!pWrtShell2->GetViewOptions()->IsRedlineRecordingOn()); + + // When turning on track changes for view2: + comphelper::dispatchCommand(".uno:TrackChanges", {}); + + // Then make sure both views have track changes turned on: + CPPUNIT_ASSERT(pWrtShell1->GetViewOptions()->IsRedlineRecordingOn()); + // Without the accompanying fix in place, this test would have failed, .uno:TrackChanges in + // view2 was ignored when view1 already tracked changes. + CPPUNIT_ASSERT(pWrtShell2->GetViewOptions()->IsRedlineRecordingOn()); +} + +CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, testTrackChangesPerViewInsert) +{ + // Given 2 views, view 1 records changes, view does not record changes: + SwXTextDocument* pXTextDocument = createDoc(); + CPPUNIT_ASSERT(pXTextDocument); + SwTestViewCallback aView1; + int nView1 = SfxLokHelper::getView(); + SwWrtShell* pWrtShell1 = pXTextDocument->GetDocShell()->GetWrtShell(); + pWrtShell1->Insert(u"X"_ustr); + SfxLokHelper::createView(); + SwTestViewCallback aView2; + int nView2 = SfxLokHelper::getView(); + SwWrtShell* pWrtShell2 = pXTextDocument->GetDocShell()->GetWrtShell(); + SfxLokHelper::setView(nView1); + comphelper::dispatchCommand(".uno:TrackChanges", {}); + + // When view 1 types: + pWrtShell1->SttEndDoc(/*bStt=*/true); + pWrtShell1->Insert(u"A"_ustr); + // Then make sure a redline is created: + CPPUNIT_ASSERT_EQUAL(static_cast(1), pWrtShell1->GetRedlineCount()); + + // When view 2 types: + SfxLokHelper::setView(nView2); + pWrtShell2->SttEndDoc(/*bStt=*/false); + pWrtShell2->Insert(u"Z"_ustr); + // Then make sure no redline is created: + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 1 + // - Actual : 2 + // i.e. the insertion in view 2 was recorded. + CPPUNIT_ASSERT_EQUAL(static_cast(1), pWrtShell2->GetRedlineCount()); +} + +CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, testTrackChangesPerViewDelete) +{ + // Given 2 views, view 1 records changes, view does not record changes: + SwXTextDocument* pXTextDocument = createDoc(); + CPPUNIT_ASSERT(pXTextDocument); + SwTestViewCallback aView1; + int nView1 = SfxLokHelper::getView(); + SwWrtShell* pWrtShell1 = pXTextDocument->GetDocShell()->GetWrtShell(); + pWrtShell1->Insert(u"test"_ustr); + SfxLokHelper::createView(); + SwTestViewCallback aView2; + int nView2 = SfxLokHelper::getView(); + SwWrtShell* pWrtShell2 = pXTextDocument->GetDocShell()->GetWrtShell(); + SfxLokHelper::setView(nView1); + comphelper::dispatchCommand(".uno:TrackChanges", {}); + + // When view 1 deletes: + pWrtShell1->SttEndDoc(/*bStt=*/true); + pWrtShell1->Right(SwCursorSkipMode::Chars, /*bSelect=*/true, 1, /*bBasicCall=*/false); + pWrtShell1->DelRight(); + // Then make sure a redline is created: + CPPUNIT_ASSERT_EQUAL(static_cast(1), pWrtShell1->GetRedlineCount()); + + // When view 2 deletes: + SfxLokHelper::setView(nView2); + pWrtShell2->SttEndDoc(/*bStt=*/false); + pWrtShell2->Left(SwCursorSkipMode::Chars, /*bSelect=*/true, 1, /*bBasicCall=*/false); + pWrtShell2->DelLeft(); + // Then make sure no redline is created: + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 1 + // - Actual : 2 + // i.e. the deletion in view 2 was recorded. + CPPUNIT_ASSERT_EQUAL(static_cast(1), pWrtShell2->GetRedlineCount()); +} } CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sw/source/core/doc/DocumentRedlineManager.cxx b/sw/source/core/doc/DocumentRedlineManager.cxx index 6763d2ba1ece..d61b134cbb36 100644 --- a/sw/source/core/doc/DocumentRedlineManager.cxx +++ b/sw/source/core/doc/DocumentRedlineManager.cxx @@ -1145,17 +1145,38 @@ DocumentRedlineManager::DocumentRedlineManager(SwDoc& i_rSwdoc) { } -RedlineFlags DocumentRedlineManager::GetRedlineFlags() const +RedlineFlags DocumentRedlineManager::GetRedlineFlags(const SwViewShell* pViewShell) const { - return meRedlineFlags; + if (!pViewShell) + { + SwDocShell* pDocShell = m_rDoc.GetDocShell(); + if (pDocShell) + { + pViewShell = pDocShell->GetWrtShell(); + } + } + + RedlineFlags eRedlineFlags = meRedlineFlags; + + if (pViewShell) + { + // Recording can be per-view, the rest is per-document. + eRedlineFlags = eRedlineFlags & ~RedlineFlags::On; + if (pViewShell->GetViewOptions()->IsRedlineRecordingOn()) + { + eRedlineFlags |= RedlineFlags::On; + } + } + + return eRedlineFlags; } void DocumentRedlineManager::SetRedlineFlags( RedlineFlags eMode ) { - if( meRedlineFlags == eMode ) + if( GetRedlineFlags() == eMode ) return; - if( (RedlineFlags::ShowMask & meRedlineFlags) != (RedlineFlags::ShowMask & eMode) + if( (RedlineFlags::ShowMask & GetRedlineFlags()) != (RedlineFlags::ShowMask & eMode) || !(RedlineFlags::ShowMask & eMode) ) { bool bSaveInXMLImportFlag = m_rDoc.IsInXMLImport(); @@ -1231,27 +1252,27 @@ void DocumentRedlineManager::SetRedlineFlags( RedlineFlags eMode ) bool DocumentRedlineManager::IsRedlineOn() const { - return IDocumentRedlineAccess::IsRedlineOn(meRedlineFlags); + return IDocumentRedlineAccess::IsRedlineOn(GetRedlineFlags()); } bool DocumentRedlineManager::IsIgnoreRedline() const { - return bool(RedlineFlags::Ignore & meRedlineFlags); + return bool(RedlineFlags::Ignore & GetRedlineFlags()); } void DocumentRedlineManager::SetRedlineFlags_intern(RedlineFlags eMode) { SwDocShell* pDocShell = m_rDoc.GetDocShell(); - SwWrtShell* pWrtShell = pDocShell ? pDocShell->GetWrtShell() : nullptr; - if (pWrtShell) + SwViewShell* pViewShell = pDocShell ? pDocShell->GetWrtShell() : nullptr; + if (pViewShell) { // Recording can be per-view, the rest is per-document. auto bRedlineRecordingOn = bool(eMode & RedlineFlags::On); - SwViewOption aOpt(*pWrtShell->GetViewOptions()); + SwViewOption aOpt(*pViewShell->GetViewOptions()); if (aOpt.IsRedlineRecordingOn() != bRedlineRecordingOn) { aOpt.SetRedlineRecordingOn(bRedlineRecordingOn); - pWrtShell->ApplyViewOptions(aOpt); + pViewShell->ApplyViewOptions(aOpt); } } @@ -1331,11 +1352,11 @@ DocumentRedlineManager::AppendRedline(SwRangeRedline* pNewRedl, bool const bCall { CHECK_REDLINE( *this ) - if (!IsRedlineOn() || IsShowOriginal(meRedlineFlags)) + if (!IsRedlineOn() || IsShowOriginal(GetRedlineFlags())) { if( bCallDelete && RedlineType::Delete == pNewRedl->GetType() ) { - RedlineFlags eOld = meRedlineFlags; + RedlineFlags eOld = GetRedlineFlags(); // Set to NONE, so that the Delete::Redo merges the Redline data correctly! // The ShowMode needs to be retained! SetRedlineFlags_intern(eOld & ~RedlineFlags(RedlineFlags::On | RedlineFlags::Ignore)); @@ -1772,7 +1793,7 @@ DocumentRedlineManager::AppendRedline(SwRangeRedline* pNewRedl, bool const bCall if( pRedl->IsOwnRedline( *pNewRedl ) && pRedl->CanCombine( *pNewRedl ) ) { - if( IsHideChanges( meRedlineFlags )) + if( IsHideChanges( GetRedlineFlags() )) { // Before we can merge, we make it visible! // We insert temporarily so that pNew is @@ -1820,7 +1841,7 @@ DocumentRedlineManager::AppendRedline(SwRangeRedline* pNewRedl, bool const bCall { // b62341295: Do not throw away redlines // even if they are not allowed to be combined - RedlineFlags eOld = meRedlineFlags; + RedlineFlags eOld = GetRedlineFlags(); if( !( eOld & RedlineFlags::DontCombineRedlines ) && pRedl->IsOwnRedline( *pNewRedl ) && // tdf#116084 tdf#121176 don't combine anonymized deletion @@ -1956,7 +1977,7 @@ DocumentRedlineManager::AppendRedline(SwRangeRedline* pNewRedl, bool const bCall pRedl->PushData( *pNewRedl ); delete pNewRedl; pNewRedl = nullptr; - if( IsHideChanges( meRedlineFlags )) + if( IsHideChanges( GetRedlineFlags() )) { pRedl->Hide(0, maRedlineTable.GetPos(pRedl)); } @@ -2032,7 +2053,7 @@ DocumentRedlineManager::AppendRedline(SwRangeRedline* pNewRedl, bool const bCall { pRedl->PushData( *pNewRedl ); pNewRedl->SetEnd( *pRStt, pEnd ); - if( IsHideChanges( meRedlineFlags )) + if( IsHideChanges( GetRedlineFlags() )) { maRedlineTable.Insert(pNewRedl); pRedl->Hide(0, maRedlineTable.GetPos(pRedl)); @@ -2060,7 +2081,7 @@ DocumentRedlineManager::AppendRedline(SwRangeRedline* pNewRedl, bool const bCall { pRedl->PushData( *pNewRedl ); pNewRedl->SetStart( *pREnd, pStart ); - if( IsHideChanges( meRedlineFlags )) + if( IsHideChanges( GetRedlineFlags() )) { maRedlineTable.Insert( pNewRedl ); pRedl->Hide(0, maRedlineTable.GetPos(pRedl)); @@ -2483,7 +2504,7 @@ bool DocumentRedlineManager::AppendTableRowRedline( SwTableRowRedline* pNewRedl CHECK_REDLINE( this ) */ - if (IsRedlineOn() && !IsShowOriginal(meRedlineFlags)) + if (IsRedlineOn() && !IsShowOriginal(GetRedlineFlags())) { // #TODO - equivalent for 'SwTableRowRedline' /* @@ -2500,7 +2521,7 @@ bool DocumentRedlineManager::AppendTableRowRedline( SwTableRowRedline* pNewRedl /* if( bCallDelete && RedlineType::Delete == pNewRedl->GetType() ) { - RedlineFlags eOld = meRedlineFlags; + RedlineFlags eOld = GetRedlineFlags(); // Set to NONE, so that the Delete::Redo merges the Redline data correctly! // The ShowMode needs to be retained! SetRedlineFlags_intern(eOld & ~(RedlineFlags::On | RedlineFlags::Ignore)); @@ -2525,7 +2546,7 @@ bool DocumentRedlineManager::AppendTableCellRedline( SwTableCellRedline* pNewRed CHECK_REDLINE( this ) */ - if (IsRedlineOn() && !IsShowOriginal(meRedlineFlags)) + if (IsRedlineOn() && !IsShowOriginal(GetRedlineFlags())) { // #TODO - equivalent for 'SwTableCellRedline' /* @@ -2542,7 +2563,7 @@ bool DocumentRedlineManager::AppendTableCellRedline( SwTableCellRedline* pNewRed /* if( bCallDelete && RedlineType::Delete == pNewRedl->GetType() ) { - RedlineFlags eOld = meRedlineFlags; + RedlineFlags eOld = GetRedlineFlags(); // Set to NONE, so that the Delete::Redo merges the Redline data correctly! // The ShowMode needs to be retained! SetRedlineFlags_intern(eOld & ~(RedlineFlags::On | RedlineFlags::Ignore)); @@ -2565,7 +2586,7 @@ void DocumentRedlineManager::CompressRedlines(size_t nStartIndex) CHECK_REDLINE( *this ) void (SwRangeRedline::*pFnc)(sal_uInt16, size_t, bool) = nullptr; - RedlineFlags eShow = RedlineFlags::ShowMask & meRedlineFlags; + RedlineFlags eShow = RedlineFlags::ShowMask & GetRedlineFlags(); if( eShow == (RedlineFlags::ShowInsert | RedlineFlags::ShowDelete)) pFnc = &SwRangeRedline::Show; else if (eShow == RedlineFlags::ShowInsert) @@ -3175,8 +3196,8 @@ bool DocumentRedlineManager::AcceptRedline(SwRedlineTable::size_type nPos, bool // Switch to visible in any case if( (RedlineFlags::ShowInsert | RedlineFlags::ShowDelete) != - (RedlineFlags::ShowMask & meRedlineFlags) ) - SetRedlineFlags( RedlineFlags::ShowInsert | RedlineFlags::ShowDelete | meRedlineFlags ); + (RedlineFlags::ShowMask & GetRedlineFlags()) ) + SetRedlineFlags( RedlineFlags::ShowInsert | RedlineFlags::ShowDelete | GetRedlineFlags() ); SwRangeRedline* pTmp = maRedlineTable[ nPos ]; bool bAnonym = pTmp->GetRedlineData(0).IsAnonymized(); @@ -3269,8 +3290,8 @@ bool DocumentRedlineManager::AcceptRedline( const SwPaM& rPam, bool bCallDelete, { // Switch to visible in any case if( (RedlineFlags::ShowInsert | RedlineFlags::ShowDelete) != - (RedlineFlags::ShowMask & meRedlineFlags) ) - SetRedlineFlags( RedlineFlags::ShowInsert | RedlineFlags::ShowDelete | meRedlineFlags ); + (RedlineFlags::ShowMask & GetRedlineFlags()) ) + SetRedlineFlags( RedlineFlags::ShowInsert | RedlineFlags::ShowDelete | GetRedlineFlags() ); // The Selection is only in the ContentSection. If there are Redlines // to Non-ContentNodes before or after that, then the Selections @@ -3465,8 +3486,8 @@ bool DocumentRedlineManager::RejectRedline(SwRedlineTable::size_type nPos, // Switch to visible in any case if( (RedlineFlags::ShowInsert | RedlineFlags::ShowDelete) != - (RedlineFlags::ShowMask & meRedlineFlags) ) - SetRedlineFlags( RedlineFlags::ShowInsert | RedlineFlags::ShowDelete | meRedlineFlags ); + (RedlineFlags::ShowMask & GetRedlineFlags()) ) + SetRedlineFlags( RedlineFlags::ShowInsert | RedlineFlags::ShowDelete | GetRedlineFlags() ); SwRangeRedline* pTmp = maRedlineTable[ nPos ]; bool bAnonym = pTmp->GetRedlineData(0).IsAnonymized(); @@ -3559,8 +3580,8 @@ bool DocumentRedlineManager::RejectRedline( const SwPaM& rPam, bool bCallDelete, { // Switch to visible in any case if( (RedlineFlags::ShowInsert | RedlineFlags::ShowDelete) != - (RedlineFlags::ShowMask & meRedlineFlags) ) - SetRedlineFlags( RedlineFlags::ShowInsert | RedlineFlags::ShowDelete | meRedlineFlags ); + (RedlineFlags::ShowMask & GetRedlineFlags()) ) + SetRedlineFlags( RedlineFlags::ShowInsert | RedlineFlags::ShowDelete | GetRedlineFlags() ); // The Selection is only in the ContentSection. If there are Redlines // to Non-ContentNodes before or after that, then the Selections diff --git a/sw/source/core/edit/edredln.cxx b/sw/source/core/edit/edredln.cxx index 1778745f57e4..76f529dff7b0 100644 --- a/sw/source/core/edit/edredln.cxx +++ b/sw/source/core/edit/edredln.cxx @@ -26,7 +26,7 @@ RedlineFlags SwEditShell::GetRedlineFlags() const { - return GetDoc()->getIDocumentRedlineAccess().GetRedlineFlags(); + return GetDoc()->getIDocumentRedlineAccess().GetRedlineFlags(this); } void SwEditShell::SetRedlineFlags( RedlineFlags eMode ) diff --git a/sw/source/core/inc/DocumentRedlineManager.hxx b/sw/source/core/inc/DocumentRedlineManager.hxx index 48bc454f2fd9..5476c34e5407 100644 --- a/sw/source/core/inc/DocumentRedlineManager.hxx +++ b/sw/source/core/inc/DocumentRedlineManager.hxx @@ -34,9 +34,9 @@ public: /** * Replaced by SwRootFrame::IsHideRedlines() (this is model-level redline - * hiding). + * hiding) for hide/show. */ - virtual RedlineFlags GetRedlineFlags() const override; + virtual RedlineFlags GetRedlineFlags(const SwViewShell* pViewShell = nullptr) const override; virtual void SetRedlineFlags_intern(/*[in]*/RedlineFlags eMode) override; diff --git a/sw/source/uibase/app/docsh.cxx b/sw/source/uibase/app/docsh.cxx index 539d056eac6f..15e4e6e79c84 100644 --- a/sw/source/uibase/app/docsh.cxx +++ b/sw/source/uibase/app/docsh.cxx @@ -1355,11 +1355,22 @@ const ::sfx2::IXmlIdRegistry* SwDocShell::GetXmlIdRegistry() const return m_xDoc ? &m_xDoc->GetXmlIdRegistry() : nullptr; } -bool SwDocShell::IsChangeRecording() const +bool SwDocShell::IsChangeRecording(SfxViewShell* pViewShell) const { - if (!m_pWrtShell) + SwWrtShell* pWrtShell = nullptr; + auto pView = dynamic_cast(pViewShell); + if (pView) + { + pWrtShell = pView->GetWrtShellPtr(); + } + if (!pWrtShell) + { + pWrtShell = m_pWrtShell; + } + + if (!pWrtShell) return false; - return bool(m_pWrtShell->GetRedlineFlags() & RedlineFlags::On); + return bool(pWrtShell->GetRedlineFlags() & RedlineFlags::On); } bool SwDocShell::HasChangeRecordProtection() const diff --git a/sw/source/uibase/uiview/viewstat.cxx b/sw/source/uibase/uiview/viewstat.cxx index fceb163232fa..691158242ed3 100644 --- a/sw/source/uibase/uiview/viewstat.cxx +++ b/sw/source/uibase/uiview/viewstat.cxx @@ -332,7 +332,7 @@ void SwView::GetState(SfxItemSet &rSet) } break; case FN_REDLINE_ON: - rSet.Put( SfxBoolItem( nWhich, GetDocShell()->IsChangeRecording() ) ); + rSet.Put( SfxBoolItem( nWhich, GetDocShell()->IsChangeRecording(this) ) ); // When the view is new (e.g. on load), show the Hidden Track Changes infobar // if Show Changes is disabled, but recording of changes is enabled // or hidden tracked changes are there already in the document. @@ -340,7 +340,7 @@ void SwView::GetState(SfxItemSet &rSet) // enabled, see in sfx2. if ( m_bForceChangesToolbar && m_pWrtShell->GetLayout()->IsHideRedlines() ) { - bool isRecording = GetDocShell()->IsChangeRecording(); + bool isRecording = GetDocShell()->IsChangeRecording(this); bool hasRecorded = m_pWrtShell->GetDoc()->getIDocumentRedlineAccess().GetRedlineTable().size(); if ( isRecording || hasRecorded )