sw/inc/pam.hxx | 5 +++++ sw/source/core/crsr/pam.cxx | 17 +++++++++++++++++ sw/source/core/doc/docnum.cxx | 3 +-- sw/source/core/doc/docsort.cxx | 6 ++---- sw/source/core/docnode/ndsect.cxx | 4 ++-- sw/source/core/edit/acorrect.cxx | 3 +-- sw/source/core/frmedt/tblsel.cxx | 2 +- sw/source/core/undo/undobj.cxx | 3 +-- sw/source/core/undo/unredln.cxx | 8 +++----- sw/source/core/unocore/unotext.cxx | 3 +-- sw/source/filter/ww8/wrtww8.cxx | 2 +- sw/source/filter/ww8/ww8par.cxx | 2 +- 12 files changed, 36 insertions(+), 22 deletions(-)
New commits: commit 6816a4d4aff1bcac91d2d5e33160b76a89a47f40 Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Tue Aug 2 16:14:56 2022 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Thu Aug 4 08:38:51 2022 +0200 introduce SwPosition::Assign as part of the process of hiding the internals of SwPosition And use it in a handful of places where it is obviously correct to do so (leaving all the hard stuff for later) Change-Id: Ic1b8e80072f45acc8d2f08264662611168b1dd85 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137736 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/sw/inc/pam.hxx b/sw/inc/pam.hxx index fef6206cb95e..a0b7124d58dd 100644 --- a/sw/inc/pam.hxx +++ b/sw/inc/pam.hxx @@ -81,6 +81,11 @@ struct SAL_WARN_UNUSED SW_DLLPUBLIC SwPosition sal_Int32 GetContentIndex() const { return nContent.GetIndex(); } void SetMark(const sw::mark::IMark* pMark) { nContent.SetMark(pMark); } void SetRedline(SwRangeRedline* pRangeRedline) { nContent.SetRedline(pRangeRedline); } + + /// These all set both nNode and nContent + void Assign( const SwNode& rNd, SwNodeOffset nDelta, sal_Int32 nContentOffset = 0 ); + void Assign( SwNodeOffset nNodeOffset, sal_Int32 nContentOffset = 0 ); + void Assign( const SwNode& rNd ); }; SW_DLLPUBLIC std::ostream &operator <<(std::ostream& s, const SwPosition& position); diff --git a/sw/source/core/crsr/pam.cxx b/sw/source/core/crsr/pam.cxx index 9a37b1867587..99d53c2e72b3 100644 --- a/sw/source/core/crsr/pam.cxx +++ b/sw/source/core/crsr/pam.cxx @@ -208,6 +208,23 @@ void SwPosition::dumpAsXml(xmlTextWriterPtr pWriter) const (void)xmlTextWriterEndElement(pWriter); } +void SwPosition::Assign( const SwNode& rNd, SwNodeOffset nDelta, sal_Int32 nContentOffset ) +{ + nNode.Assign(rNd, nDelta); + assert((nNode.GetNode().GetContentNode() || nContentOffset == 0) && "setting contentoffset, but node is not SwContentNode"); + nContent.Assign(nNode.GetNode().GetContentNode(), nContentOffset); +} +void SwPosition::Assign( SwNodeOffset nNodeOffset, sal_Int32 nContentOffset ) +{ + nNode = nNodeOffset; + nContent.Assign(nNode.GetNode().GetContentNode(), nContentOffset); +} +void SwPosition::Assign( const SwNode& rNd ) +{ + nNode.Assign(rNd); + nContent.Assign(rNd.GetContentNode(), 0); +} + std::ostream &operator <<(std::ostream& s, const SwPosition& position) { return s << "SwPosition (node " << position.GetNodeIndex() << ", offset " << position.GetContentIndex() << ")"; diff --git a/sw/source/core/doc/docnum.cxx b/sw/source/core/doc/docnum.cxx index 4b6e4d1b0152..9fff2306da69 100644 --- a/sw/source/core/doc/docnum.cxx +++ b/sw/source/core/doc/docnum.cxx @@ -1598,8 +1598,7 @@ static bool lcl_GotoNextPrevNum( SwPosition& rPos, bool bNext, } else { - rPos.nNode.Assign( *pLast ); - rPos.nContent.Assign( pLast, 0 ); + rPos.Assign( *pLast ); } bRet = true; } diff --git a/sw/source/core/doc/docsort.cxx b/sw/source/core/doc/docsort.cxx index c5dee367da90..bf3d0353df41 100644 --- a/sw/source/core/doc/docsort.cxx +++ b/sw/source/core/doc/docsort.cxx @@ -340,10 +340,8 @@ bool SwDoc::SortText(const SwPaM& rPaM, const SwSortOptions& rOpt) getIDocumentRedlineAccess().DeleteRedline( *pRedlPam, true, RedlineType::Any ); pRedlPam->GetMark()->nNode.Assign( pEnd->GetNode(), 1 ); - pCNd = pRedlPam->GetContentNode( false ); - pRedlPam->GetMark()->nContent.Assign( pCNd, 0 ); - pRedlPam->GetPoint()->nNode.Assign( aEndIdx.GetNode() ); + pRedlPam->GetPoint()->Assign( aEndIdx.GetNode() ); pCNd = pRedlPam->GetContentNode(); sal_Int32 nCLen = 0; if( !pCNd ) @@ -352,7 +350,7 @@ bool SwDoc::SortText(const SwPaM& rPaM, const SwSortOptions& rOpt) if( pCNd ) { nCLen = pCNd->Len(); - pRedlPam->GetPoint()->nNode.Assign( *pCNd ); + pRedlPam->GetPoint()->Assign( *pCNd ); } } pRedlPam->GetPoint()->nContent.Assign( pCNd, nCLen ); diff --git a/sw/source/core/docnode/ndsect.cxx b/sw/source/core/docnode/ndsect.cxx index e619cb333cfb..99b628691121 100644 --- a/sw/source/core/docnode/ndsect.cxx +++ b/sw/source/core/docnode/ndsect.cxx @@ -253,7 +253,7 @@ SwDoc::InsertSwSection(SwPaM const& rRange, SwSectionData & rNewData, if( pPrvNd && 1 == nRegionRet ) { - pSttPos->nNode.Assign( *pPrvNd ); + pSttPos->Assign( *pPrvNd ); pSttPos->nContent.Assign( pSttPos->GetNode().GetContentNode(), 0 ); } else if( pSttPos->GetContentIndex() ) @@ -263,7 +263,7 @@ SwDoc::InsertSwSection(SwPaM const& rRange, SwSectionData & rNewData, if( pPrvNd && 2 == nRegionRet ) { - pEndPos->nNode.Assign( *pPrvNd ); + pEndPos->Assign( *pPrvNd ); pEndPos->nContent.Assign( pEndPos->GetNode().GetContentNode(), 0 ); } else diff --git a/sw/source/core/edit/acorrect.cxx b/sw/source/core/edit/acorrect.cxx index f915d462a305..fe202c35f679 100644 --- a/sw/source/core/edit/acorrect.cxx +++ b/sw/source/core/edit/acorrect.cxx @@ -471,8 +471,7 @@ bool SwAutoCorrDoc::ChgAutoCorrWord( sal_Int32& rSttPos, sal_Int32 nEndPos, const SwTableNode* pTableNd = pContentNd->FindTableNode(); if( pTableNd ) { - aCpyPam.GetPoint()->nContent.Assign( nullptr, 0 ); - aCpyPam.GetPoint()->nNode = *pTableNd; + aCpyPam.GetPoint()->Assign( *pTableNd ); } aCpyPam.SetMark(); diff --git a/sw/source/core/frmedt/tblsel.cxx b/sw/source/core/frmedt/tblsel.cxx index 9518177c5fd7..15f12182916f 100644 --- a/sw/source/core/frmedt/tblsel.cxx +++ b/sw/source/core/frmedt/tblsel.cxx @@ -1357,7 +1357,7 @@ void GetMergeSel( const SwPaM& rPam, SwSelBoxes& rBoxes, for( const auto &rPt : aPosArr ) { - aPam.GetPoint()->nNode.Assign( *rPt.pSelBox->GetSttNd()-> + aPam.GetPoint()->Assign( *rPt.pSelBox->GetSttNd()-> EndOfSectionNode(), SwNodeOffset(-1) ); SwContentNode* pCNd = aPam.GetContentNode(); aPam.GetPoint()->nContent.Assign( pCNd, pCNd ? pCNd->Len() : 0 ); diff --git a/sw/source/core/undo/undobj.cxx b/sw/source/core/undo/undobj.cxx index 0cb620362a36..3730ec84f41d 100644 --- a/sw/source/core/undo/undobj.cxx +++ b/sw/source/core/undo/undobj.cxx @@ -789,8 +789,7 @@ void SwUndoSaveContent::MoveFromUndoNds( SwDoc& rDoc, SwNodeOffset nNodeIdx, if (!pEndNdIdx && pTextNd) { aPaM.SetMark(); - aPaM.GetPoint()->nNode = nNodeIdx; - aPaM.GetPoint()->nContent.Assign(aPaM.GetContentNode(), 0); + aPaM.GetPoint()->Assign(nNodeIdx, 0); SaveRedlEndPosForRestore aRedlRest( rInsPos.nNode, rInsPos.GetContentIndex() ); diff --git a/sw/source/core/undo/unredln.cxx b/sw/source/core/undo/unredln.cxx index 8fab5741ab7a..48327e653551 100644 --- a/sw/source/core/undo/unredln.cxx +++ b/sw/source/core/undo/unredln.cxx @@ -365,13 +365,11 @@ void SwUndoRedlineSort::UndoRedlineImpl(SwDoc & rDoc, SwPaM & rPam) SwPaM *const pPam = & rPam; pPam->DeleteMark(); - pPam->GetPoint()->nNode.Assign( aPrevIdx.GetNode(), +1 ); - SwContentNode* pCNd = pPam->GetContentNode(); - pPam->GetPoint()->nContent.Assign(pCNd, 0 ); + pPam->GetPoint()->Assign( aPrevIdx.GetNode(), SwNodeOffset(+1) ); pPam->SetMark(); pPam->GetPoint()->nNode += nOffsetTemp; - pCNd = pPam->GetContentNode(); + SwContentNode* pCNd = pPam->GetContentNode(); pPam->GetPoint()->nContent.Assign( pCNd, pCNd->Len() ); SetValues( *pPam ); @@ -391,7 +389,7 @@ void SwUndoRedlineSort::RedoRedlineImpl(SwDoc & rDoc, SwPaM & rPam) rDoc.SortText(rPam, *m_pOpt); pPam->DeleteMark(); - pPam->GetPoint()->nNode.Assign( aPrevIdx.GetNode(), +1 ); + pPam->GetPoint()->Assign( aPrevIdx.GetNode(), SwNodeOffset(+1) ); SwContentNode* pCNd = pPam->GetContentNode(); sal_Int32 nLen = pCNd->Len(); if( nLen > nCntStt ) diff --git a/sw/source/core/unocore/unotext.cxx b/sw/source/core/unocore/unotext.cxx index 6b400f6f3ea1..5fed8c91de5d 100644 --- a/sw/source/core/unocore/unotext.cxx +++ b/sw/source/core/unocore/unotext.cxx @@ -1396,8 +1396,7 @@ SwXText::insertTextPortion( SwUnoCursorHelper::DocInsertStringSplitCR( *m_pImpl->m_pDoc, rCursor, rText, false); SwUnoCursorHelper::SelectPam(rCursor, true); - rCursor.GetPoint()->nNode.Assign(nodeIndex.GetNode(), +1); - rCursor.GetPoint()->nContent = nContentPos; + rCursor.GetPoint()->Assign(nodeIndex.GetNode(), SwNodeOffset(+1), nContentPos); } try diff --git a/sw/source/filter/ww8/wrtww8.cxx b/sw/source/filter/ww8/wrtww8.cxx index a7c5cd8d1382..f6d5160cd92e 100644 --- a/sw/source/filter/ww8/wrtww8.cxx +++ b/sw/source/filter/ww8/wrtww8.cxx @@ -2917,7 +2917,7 @@ void MSWordExportBase::WriteText() } if (pNextNode != nullptr) - m_pCurPam->GetPoint()->nNode.Assign(*pNextNode); + m_pCurPam->GetPoint()->Assign(*pNextNode); else ++m_pCurPam->GetPoint()->nNode; diff --git a/sw/source/filter/ww8/ww8par.cxx b/sw/source/filter/ww8/ww8par.cxx index 802762987863..442634a3cbc6 100644 --- a/sw/source/filter/ww8/ww8par.cxx +++ b/sw/source/filter/ww8/ww8par.cxx @@ -4615,7 +4615,7 @@ void wwSectionManager::InsertSegments() mrReader.m_rDoc.GetNodes().MakeTextNode(aAnchor, mrReader.m_rDoc.getIDocumentStylePoolAccess().GetTextCollFromPool( RES_POOLCOLL_TEXT )); - aSectPaM.GetPoint()->nNode.Assign(*pTextNd); + aSectPaM.GetPoint()->Assign(*pTextNd); aSectPaM.GetPoint()->nContent.Assign( aSectPaM.GetContentNode(), 0); }