From 077cbb5faecf75b333531afad04d2c9622a47c91 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Mon, 15 Aug 2022 10:44:50 +0200 Subject: pass SwNode and sal_Int32 to deleteMarks instead of SwNodeIndex and SwContentIndex. Part of the process of hiding the implementation of SwPosition. Change-Id: I290fbc14d738d1bbf5d3f613eae6d114fc7cda17 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138271 Tested-by: Jenkins Reviewed-by: Noel Grandin --- sw/inc/IDocumentMarkAccess.hxx | 8 +- .../core/doc/DocumentContentOperationsManager.cxx | 6 +- sw/source/core/doc/docbm.cxx | 102 +++++++++++---------- sw/source/core/inc/MarkManager.hxx | 6 +- sw/source/core/inc/mvsave.hxx | 8 +- sw/source/filter/html/htmltab.cxx | 2 +- 6 files changed, 73 insertions(+), 59 deletions(-) diff --git a/sw/inc/IDocumentMarkAccess.hxx b/sw/inc/IDocumentMarkAccess.hxx index 0790a27ef1ea..98037c7917e3 100644 --- a/sw/inc/IDocumentMarkAccess.hxx +++ b/sw/inc/IDocumentMarkAccess.hxx @@ -225,11 +225,11 @@ class IDocumentMarkAccess */ virtual void deleteMarks( - const SwNodeIndex& rStt, - const SwNodeIndex& rEnd, + const SwNode& rStt, + const SwNode& rEnd, std::vector< ::sw::mark::SaveBookmark>* pSaveBkmk, // Ugly: SaveBookmark is core-internal - const SwContentIndex* pSttIdx, - const SwContentIndex* pEndIdx) =0; + std::optional oStartContentIdx, + std::optional oEndContentIdx) =0; /** Deletes a mark. diff --git a/sw/source/core/doc/DocumentContentOperationsManager.cxx b/sw/source/core/doc/DocumentContentOperationsManager.cxx index 1972be388df2..91534b7e6863 100644 --- a/sw/source/core/doc/DocumentContentOperationsManager.cxx +++ b/sw/source/core/doc/DocumentContentOperationsManager.cxx @@ -2524,8 +2524,8 @@ bool DocumentContentOperationsManager::MoveRange( SwPaM& rPaM, SwPosition& rPos, for(auto& rBkmk : aSaveBkmks) rBkmk.SetInDoc( &m_rDoc, - rPaM.GetMark()->nNode, - &rPaM.GetMark()->nContent); + rPaM.GetMark()->GetNode(), + rPaM.GetMark()->GetContentIndex()); *rPaM.GetPoint() = *aSavePam.End(); // Move the Flys to the new position. @@ -2645,7 +2645,7 @@ bool DocumentContentOperationsManager::MoveNodeRange( SwNodeRange& rRange, SwNod // Add the Bookmarks back to the Document for(auto& rBkmk : aSaveBkmks) - rBkmk.SetInDoc(&m_rDoc, aIdx); + rBkmk.SetInDoc(&m_rDoc, aIdx.GetNode()); if( !aSavRedlInsPosArr.empty() ) { diff --git a/sw/source/core/doc/docbm.cxx b/sw/source/core/doc/docbm.cxx index 914e1374554c..512c139b41fe 100644 --- a/sw/source/core/doc/docbm.cxx +++ b/sw/source/core/doc/docbm.cxx @@ -185,12 +185,12 @@ bool IDocumentMarkAccess::iterator::operator>=(iterator const& rOther) const namespace { - bool lcl_GreaterThan( const SwPosition& rPos, const SwNodeIndex& rNdIdx, const SwContentIndex* pIdx ) + bool lcl_GreaterThan( const SwPosition& rPos, const SwNode& rNdIdx, std::optional oContentIdx ) { - return pIdx != nullptr + return oContentIdx.has_value() ? ( rPos.nNode > rNdIdx || ( rPos.nNode == rNdIdx - && rPos.nContent >= pIdx->GetIndex() ) ) + && rPos.nContent >= *oContentIdx ) ) : rPos.nNode >= rNdIdx; } @@ -202,6 +202,14 @@ namespace && rPos.nContent < pIdx->GetIndex() ); } + bool lcl_Lower( const SwPosition& rPos, const SwNode& rNdIdx, std::optional oContentIdx ) + { + return rPos.nNode < rNdIdx + || ( oContentIdx.has_value() + && rPos.nNode == rNdIdx + && rPos.nContent < *oContentIdx ); + } + bool lcl_MarkOrderingByStart(const ::sw::mark::MarkBase *const pFirst, const ::sw::mark::MarkBase *const pSecond) { @@ -246,7 +254,7 @@ namespace void lcl_PositionFromContentNode( std::optional& rFoundPos, - SwContentNode * const pContentNode, + const SwContentNode * const pContentNode, const bool bAtEnd) { rFoundPos.emplace(*pContentNode); @@ -259,21 +267,21 @@ namespace // else set it to the ContentNode of the Pos outside the Range void lcl_FindExpelPosition( std::optional& rFoundPos, - const SwNodeIndex& rStt, - const SwNodeIndex& rEnd, + const SwNode& rStt, + const SwNode& rEnd, const SwPosition& rOtherPosition) { - SwContentNode * pNode = rEnd.GetNode().GetContentNode(); + const SwContentNode * pNode = rEnd.GetContentNode(); bool bPosAtEndOfNode = false; if ( pNode == nullptr) { - SwNodeIndex aEnd = rEnd; + SwNodeIndex aEnd(rEnd); pNode = rEnd.GetNodes().GoNext( &aEnd ); bPosAtEndOfNode = false; } if ( pNode == nullptr ) { - SwNodeIndex aStt = rStt; + SwNodeIndex aStt(rStt); pNode = SwNodes::GoPrevious(&aStt); bPosAtEndOfNode = true; } @@ -973,10 +981,10 @@ namespace sw::mark static bool isDeleteMark( ::sw::mark::MarkBase const*const pMark, - SwNodeIndex const& rStt, - SwNodeIndex const& rEnd, - SwContentIndex const*const pSttIdx, - SwContentIndex const*const pEndIdx, + SwNode const& rStt, + SwNode const& rEnd, + std::optional oStartContentIdx, + std::optional oEndContentIdx, bool & rbIsPosInRange, bool & rbIsOtherPosInRange) { @@ -989,20 +997,20 @@ namespace sw::mark } // on position ?? - rbIsPosInRange = lcl_GreaterThan(pMark->GetMarkPos(), rStt, pSttIdx) - && lcl_Lower(pMark->GetMarkPos(), rEnd, pEndIdx); + rbIsPosInRange = lcl_GreaterThan(pMark->GetMarkPos(), rStt, oStartContentIdx) + && lcl_Lower(pMark->GetMarkPos(), rEnd, oEndContentIdx); rbIsOtherPosInRange = pMark->IsExpanded() - && lcl_GreaterThan(pMark->GetOtherMarkPos(), rStt, pSttIdx) - && lcl_Lower(pMark->GetOtherMarkPos(), rEnd, pEndIdx); + && lcl_GreaterThan(pMark->GetOtherMarkPos(), rStt, oStartContentIdx) + && lcl_Lower(pMark->GetOtherMarkPos(), rEnd, oEndContentIdx); // special case: completely in range, touching the end? - if ( pEndIdx != nullptr + if ( oEndContentIdx.has_value() && ( ( rbIsOtherPosInRange && pMark->GetMarkPos().nNode == rEnd - && pMark->GetMarkPos().nContent == *pEndIdx ) + && pMark->GetMarkPos().nContent == *oEndContentIdx ) || ( rbIsPosInRange && pMark->IsExpanded() && pMark->GetOtherMarkPos().nNode == rEnd - && pMark->GetOtherMarkPos().nContent == *pEndIdx ) ) ) + && pMark->GetOtherMarkPos().nContent == *oEndContentIdx ) ) ) { rbIsPosInRange = true; rbIsOtherPosInRange = true; @@ -1021,15 +1029,15 @@ namespace sw::mark case IDocumentMarkAccess::MarkType::CROSSREF_HEADING_BOOKMARK: case IDocumentMarkAccess::MarkType::CROSSREF_NUMITEM_BOOKMARK: // no delete of cross-reference bookmarks, if range is inside one paragraph - bDeleteMark = rStt != rEnd; + bDeleteMark = &rStt != &rEnd; break; case IDocumentMarkAccess::MarkType::UNO_BOOKMARK: // no delete of UNO mark, if it is not expanded and only touches the start of the range bDeleteMark = rbIsOtherPosInRange || pMark->IsExpanded() - || pSttIdx == nullptr + || !oStartContentIdx.has_value() || pMark->GetMarkPos().nNode != rStt - || pMark->GetMarkPos().nContent != *pSttIdx; + || pMark->GetMarkPos().nContent != *oStartContentIdx; break; default: bDeleteMark = true; @@ -1052,7 +1060,7 @@ namespace sw::mark bool bIsPosInRange(false); bool bIsOtherPosInRange(false); bool const bDeleteMark = isDeleteMark(*ppMark, - rStart.nNode, rEnd.nNode, &rStart.nContent, &rEnd.nContent, + rStart.GetNode(), rEnd.GetNode(), rStart.GetContentIndex(), rEnd.GetContentIndex(), bIsPosInRange, bIsOtherPosInRange); if (bDeleteMark && IDocumentMarkAccess::GetType(**ppMark) == MarkType::BOOKMARK) @@ -1064,11 +1072,11 @@ namespace sw::mark } void MarkManager::deleteMarks( - const SwNodeIndex& rStt, - const SwNodeIndex& rEnd, + const SwNode& rStt, + const SwNode& rEnd, std::vector* pSaveBkmk, - const SwContentIndex* pSttIdx, - const SwContentIndex* pEndIdx ) + std::optional oStartContentIdx, + std::optional oEndContentIdx ) { std::vector vMarksToDelete; bool bIsSortingNeeded = false; @@ -1087,7 +1095,7 @@ namespace sw::mark ::sw::mark::MarkBase *const pMark = *ppMark; bool bIsPosInRange(false); bool bIsOtherPosInRange(false); - bool const bDeleteMark = isDeleteMark(pMark, rStt, rEnd, pSttIdx, pEndIdx, bIsPosInRange, bIsOtherPosInRange); + bool const bDeleteMark = isDeleteMark(pMark, rStt, rEnd, oStartContentIdx, oEndContentIdx, bIsPosInRange, bIsOtherPosInRange); if ( bIsPosInRange && ( bIsOtherPosInRange @@ -1097,7 +1105,7 @@ namespace sw::mark { if ( pSaveBkmk ) { - pSaveBkmk->push_back( SaveBookmark( *pMark, rStt, pSttIdx ) ); + pSaveBkmk->push_back( SaveBookmark( *pMark, rStt, oStartContentIdx ) ); } vMarksToDelete.emplace_back(ppMark); } @@ -1112,9 +1120,9 @@ namespace sw::mark // move position of that is in the range out of it std::optional< SwPosition > oNewPos; - if ( pEndIdx != nullptr ) + if ( oEndContentIdx ) { - oNewPos.emplace( rEnd, *pEndIdx ); + oNewPos.emplace( *rEnd.GetContentNode(), *oEndContentIdx ); } else { @@ -1795,8 +1803,8 @@ const IDocumentMarkAccess* SwDoc::getIDocumentMarkAccess() const SaveBookmark::SaveBookmark( const IMark& rBkmk, - const SwNodeIndex & rMvPos, - const SwContentIndex* pIdx) + const SwNode& rMvPos, + std::optional oContentIdx) : m_aName(rBkmk.GetName()) , m_bHidden(false) , m_eOrigBkmType(IDocumentMarkAccess::GetType(rBkmk)) @@ -1820,8 +1828,8 @@ SaveBookmark::SaveBookmark( m_nContent1 = rBkmk.GetMarkPos().GetContentIndex(); m_nNode1 -= rMvPos.GetIndex(); - if(pIdx && !m_nNode1) - m_nContent1 -= pIdx->GetIndex(); + if(oContentIdx && !m_nNode1) + m_nContent1 -= *oContentIdx; if(rBkmk.IsExpanded()) { @@ -1829,8 +1837,8 @@ SaveBookmark::SaveBookmark( m_nContent2 = rBkmk.GetOtherMarkPos().GetContentIndex(); m_nNode2 -= rMvPos.GetIndex(); - if(pIdx && !m_nNode2) - m_nContent2 -= pIdx->GetIndex(); + if(oContentIdx && !m_nNode2) + m_nContent2 -= *oContentIdx; } else { @@ -1841,19 +1849,19 @@ SaveBookmark::SaveBookmark( void SaveBookmark::SetInDoc( SwDoc* pDoc, - const SwNodeIndex& rNewPos, - const SwContentIndex* pIdx) + const SwNode& rNewPos, + std::optional oContentIdx) { - SwPaM aPam(rNewPos.GetNode()); - if(pIdx) - aPam.GetPoint()->nContent = *pIdx; + SwPaM aPam(rNewPos); + if(oContentIdx) + aPam.GetPoint()->nContent = *oContentIdx; if(NODE_OFFSET_MAX != m_nNode2) { aPam.SetMark(); aPam.GetMark()->nNode += m_nNode2; - if(pIdx && !m_nNode2) + if(oContentIdx && !m_nNode2) aPam.GetMark()->nContent += m_nContent2; else aPam.GetMark()->nContent.Assign(aPam.GetMarkContentNode(), m_nContent2); @@ -1861,7 +1869,7 @@ void SaveBookmark::SetInDoc( aPam.GetPoint()->nNode += m_nNode1; - if(pIdx && !m_nNode1) + if(oContentIdx && !m_nNode1) aPam.GetPoint()->nContent += m_nContent1; else aPam.GetPoint()->nContent.Assign(aPam.GetPointContentNode(), m_nContent1); @@ -1908,7 +1916,9 @@ void DelBookmarks( return; SwDoc& rDoc = rStt.GetNode().GetDoc(); - rDoc.getIDocumentMarkAccess()->deleteMarks(rStt, rEnd, pSaveBkmk, pSttIdx, pEndIdx); + rDoc.getIDocumentMarkAccess()->deleteMarks(rStt.GetNode(), rEnd.GetNode(), pSaveBkmk, + pSttIdx ? std::optional{pSttIdx->GetIndex()} : std::nullopt, + pEndIdx ? std::optional{pEndIdx->GetIndex()} : std::nullopt); // Copy all Redlines which are in the move area into an array // which holds all position information as offset. diff --git a/sw/source/core/inc/MarkManager.hxx b/sw/source/core/inc/MarkManager.hxx index 44f1b1deb389..2af05601867c 100644 --- a/sw/source/core/inc/MarkManager.hxx +++ b/sw/source/core/inc/MarkManager.hxx @@ -63,7 +63,11 @@ namespace sw::mark { virtual void correctMarksAbsolute(const SwNodeIndex& rOldNode, const SwPosition& rNewPos, const sal_Int32 nOffset) override; virtual void correctMarksRelative(const SwNodeIndex& rOldNode, const SwPosition& rNewPos, const sal_Int32 nOffset) override; - virtual void deleteMarks(const SwNodeIndex& rStt, const SwNodeIndex& rEnd, std::vector< ::sw::mark::SaveBookmark>* pSaveBkmk, const SwContentIndex* pSttIdx, const SwContentIndex* pEndIdx) override; + virtual void deleteMarks(const SwNode& rStt, + const SwNode& rEnd, + std::vector< ::sw::mark::SaveBookmark>* pSaveBkmk, + std::optional oStartContentIdx, + std::optional oEndContentIdx) override; // deleters virtual std::unique_ptr diff --git a/sw/source/core/inc/mvsave.hxx b/sw/source/core/inc/mvsave.hxx index 896a2228311f..6ef3f92edfb1 100644 --- a/sw/source/core/inc/mvsave.hxx +++ b/sw/source/core/inc/mvsave.hxx @@ -50,11 +50,11 @@ namespace sw::mark public: SaveBookmark( const ::sw::mark::IMark& rBkmk, - const SwNodeIndex& rMvPos, - const SwContentIndex* pIdx); + const SwNode& rMvPos, + std::optional oContentIdx); void SetInDoc(SwDoc* pDoc, - const SwNodeIndex&, - const SwContentIndex* pIdx =nullptr); + const SwNode&, + std::optional oContentIdx = std::nullopt); private: OUString m_aName; diff --git a/sw/source/filter/html/htmltab.cxx b/sw/source/filter/html/htmltab.cxx index 5d8b4b5aea29..88b8c9e0663d 100644 --- a/sw/source/filter/html/htmltab.cxx +++ b/sw/source/filter/html/htmltab.cxx @@ -4913,7 +4913,7 @@ void SwHTMLParser::ClearFootnotesMarksInRange(const SwNodeIndex& rMkNdIdx, const //ofz#9733 drop bookmarks in this range IDocumentMarkAccess* const pMarkAccess = rDoc.getIDocumentMarkAccess(); - pMarkAccess->deleteMarks(rMkNdIdx, SwNodeIndex(rPtNdIdx, 1), nullptr, nullptr, nullptr); + pMarkAccess->deleteMarks(rMkNdIdx.GetNode(), SwNodeIndex(rPtNdIdx, 1).GetNode(), nullptr, std::nullopt, std::nullopt); SwFrameFormats& rTable = *rDoc.GetSpzFrameFormats(); for ( auto i = rTable.size(); i; ) -- cgit