summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2022-08-04 11:07:20 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2022-08-04 14:45:55 +0200
commit502357eef1a6d74a0aeb0b3f2ed956cb6f671008 (patch)
tree9e9041fcc65124f22e4b31f7410f5f04b4b53265
parenta999b8dc83a9ee1749502eb909794cddc6f34f84 (diff)
introduce SwPosition::AssignStartIndex and AssignEndIndex
as part of the process of hiding the internals of SwPosition Change-Id: I496a0e24257a1ec6653a3becef4889b6fdf5339b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137788 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r--sw/inc/pam.hxx4
-rw-r--r--sw/source/core/crsr/pam.cxx20
-rw-r--r--sw/source/core/crsr/swcrsr.cxx6
-rw-r--r--sw/source/core/doc/DocumentContentOperationsManager.cxx9
-rw-r--r--sw/source/core/fields/expfld.cxx3
-rw-r--r--sw/source/core/frmedt/fecopy.cxx2
-rw-r--r--sw/source/core/layout/trvlfrm.cxx11
-rw-r--r--sw/source/core/undo/undobj.cxx6
-rw-r--r--sw/source/core/unocore/unotext.cxx4
-rw-r--r--sw/source/filter/writer/writer.cxx3
10 files changed, 37 insertions, 31 deletions
diff --git a/sw/inc/pam.hxx b/sw/inc/pam.hxx
index 0b40c03a7733..f9cb439d0407 100644
--- a/sw/inc/pam.hxx
+++ b/sw/inc/pam.hxx
@@ -88,6 +88,10 @@ struct SAL_WARN_UNUSED SW_DLLPUBLIC SwPosition
void Assign( const SwContentNode& rNode, sal_Int32 nContentOffset = 0 );
void Assign( const SwNode& rNd );
void Assign( const SwNodeIndex& rNdIdx );
+ /// Set nNode to rNd, and nContent to the beginning of rNd
+ void AssignStartIndex( const SwContentNode& rNd );
+ /// Set nNode to rNd, and nContent to the end of rNd
+ void AssignEndIndex( const SwContentNode& rNd );
/// Adjust node position, and resets content position to zero
void Adjust( SwNodeOffset nDelta );
};
diff --git a/sw/source/core/crsr/pam.cxx b/sw/source/core/crsr/pam.cxx
index e734b1cd9aa0..bf90bc847719 100644
--- a/sw/source/core/crsr/pam.cxx
+++ b/sw/source/core/crsr/pam.cxx
@@ -239,6 +239,16 @@ void SwPosition::Adjust( SwNodeOffset nDelta )
nNode += nDelta;
nContent.Assign(nNode.GetNode().GetContentNode(), 0);
}
+void SwPosition::AssignStartIndex( const SwContentNode& rNd )
+{
+ nNode = rNd;
+ nContent.Assign(&rNd, 0);
+}
+void SwPosition::AssignEndIndex( const SwContentNode& rNd )
+{
+ nNode = rNd;
+ nContent.Assign(&rNd, rNd.Len());
+}
std::ostream &operator <<(std::ostream& s, const SwPosition& position)
@@ -1016,7 +1026,7 @@ void GoStartDoc( SwPosition * pPos )
// we always need to find a ContentNode!
SwContentNode* pCNd = rNodes.GoNext( &pPos->nNode );
if( pCNd )
- pCNd->MakeStartIndex( &pPos->nContent );
+ pPos->AssignStartIndex(*pCNd);
}
void GoEndDoc( SwPosition * pPos )
@@ -1025,7 +1035,7 @@ void GoEndDoc( SwPosition * pPos )
pPos->nNode = rNodes.GetEndOfContent();
SwContentNode* pCNd = GoPreviousNds( &pPos->nNode, true );
if( pCNd )
- pCNd->MakeEndIndex( &pPos->nContent );
+ pPos->AssignEndIndex(*pCNd);
}
void GoStartSection( SwPosition * pPos )
@@ -1038,7 +1048,7 @@ void GoStartSection( SwPosition * pPos )
do { SwNodes::GoStartOfSection( &pPos->nNode ); } while( nLevel-- );
// already on a ContentNode
- pPos->GetNode().GetContentNode()->MakeStartIndex( &pPos->nContent );
+ pPos->AssignStartIndex(*pPos->GetNode().GetContentNode());
}
/// go to the end of the current base section
@@ -1052,8 +1062,8 @@ void GoEndSection( SwPosition * pPos )
do { SwNodes::GoEndOfSection( &pPos->nNode ); } while( nLevel-- );
// now on an EndNode, thus to the previous ContentNode
- if( GoPreviousNds( &pPos->nNode, true ) )
- pPos->GetNode().GetContentNode()->MakeEndIndex( &pPos->nContent );
+ if( SwContentNode* pCNd = GoPreviousNds( &pPos->nNode, true ) )
+ pPos->AssignEndIndex(*pCNd);
}
bool GoInDoc( SwPaM & rPam, SwMoveFnCollection const & fnMove )
diff --git a/sw/source/core/crsr/swcrsr.cxx b/sw/source/core/crsr/swcrsr.cxx
index 45ff8a132d6c..5d962d9e2e3e 100644
--- a/sw/source/core/crsr/swcrsr.cxx
+++ b/sw/source/core/crsr/swcrsr.cxx
@@ -901,7 +901,7 @@ static bool lcl_MakeSelFwrd( const SwNode& rSttNd, const SwNode& rEndNd,
pCNd = rNds.GoNext( &rPam.GetPoint()->nNode );
if( !pCNd )
return false;
- pCNd->MakeStartIndex( &rPam.GetPoint()->nContent );
+ rPam.GetPoint()->AssignStartIndex(*pCNd);
}
else if( rSttNd.GetIndex() > rPam.GetPoint()->GetNodeIndex() ||
rPam.GetPoint()->GetNodeIndex() >= rEndNd.GetIndex() )
@@ -913,7 +913,7 @@ static bool lcl_MakeSelFwrd( const SwNode& rSttNd, const SwNode& rEndNd,
pCNd = SwNodes::GoPrevious( &rPam.GetPoint()->nNode );
if( !pCNd )
return false;
- pCNd->MakeEndIndex( &rPam.GetPoint()->nContent );
+ rPam.GetPoint()->AssignEndIndex(*pCNd);
return *rPam.GetMark() < *rPam.GetPoint();
}
@@ -933,7 +933,7 @@ static bool lcl_MakeSelBkwrd( const SwNode& rSttNd, const SwNode& rEndNd,
pCNd = SwNodes::GoPrevious( &rPam.GetPoint()->nNode );
if( !pCNd )
return false;
- pCNd->MakeEndIndex( &rPam.GetPoint()->nContent );
+ rPam.GetPoint()->AssignEndIndex(*pCNd);
}
else if( rEndNd.GetIndex() > rPam.GetPoint()->GetNodeIndex() ||
rPam.GetPoint()->GetNodeIndex() >= rSttNd.GetIndex() )
diff --git a/sw/source/core/doc/DocumentContentOperationsManager.cxx b/sw/source/core/doc/DocumentContentOperationsManager.cxx
index c5dca681c9eb..a5c2941979cc 100644
--- a/sw/source/core/doc/DocumentContentOperationsManager.cxx
+++ b/sw/source/core/doc/DocumentContentOperationsManager.cxx
@@ -2164,11 +2164,11 @@ bool DocumentContentOperationsManager::DelFullPara( SwPaM& rPam )
}
if (SwTextNode *const pNode = temp.Start()->GetNode().GetTextNode())
{ // rPam may not have nContent set but IsFieldmarkOverlap requires it
- pNode->MakeStartIndex(&temp.Start()->nContent);
+ temp.Start()->AssignStartIndex(*pNode);
}
if (SwTextNode *const pNode = temp.End()->GetNode().GetTextNode())
{
- pNode->MakeEndIndex(&temp.End()->nContent);
+ temp.End()->AssignEndIndex(*pNode);
}
if (sw::mark::IsFieldmarkOverlap(temp))
{ // a bit of a problem: we want to completely remove the nodes
@@ -5290,14 +5290,13 @@ bool DocumentContentOperationsManager::CopyImplImpl(SwPaM& rPam, SwPosition& rPo
if( rPos.nNode != aInsPos )
{
- pCopyPam->GetMark()->nNode = aInsPos;
if (aInsPos < rPos.nNode)
{ // tdf#134250 decremented in (pEndTextNd && !pDestTextNd) above
- pCopyPam->GetContentNode(false)->MakeEndIndex(&pCopyPam->GetMark()->nContent);
+ pCopyPam->GetMark()->AssignEndIndex(*aInsPos.GetNode().GetContentNode());
}
else // incremented in (!pSttTextNd && pDestTextNd) above
{
- pCopyPam->GetMark()->nContent.Assign(pCopyPam->GetContentNode(false), 0);
+ pCopyPam->GetMark()->Assign(aInsPos);
}
rPos = *pCopyPam->GetMark();
}
diff --git a/sw/source/core/fields/expfld.cxx b/sw/source/core/fields/expfld.cxx
index 383fb8d1a778..f0a0f474312c 100644
--- a/sw/source/core/fields/expfld.cxx
+++ b/sw/source/core/fields/expfld.cxx
@@ -191,8 +191,7 @@ const SwTextNode* GetBodyTextNode( const SwDoc& rDoc, SwPosition& rPos,
pTextNode = rPos.GetNode().GetTextNode();
if ( RndStdIds::FLY_AT_PARA == rAnchor.GetAnchorId() )
{
- const_cast<SwTextNode*>(pTextNode)->MakeStartIndex(
- &rPos.nContent );
+ rPos.AssignStartIndex(*pTextNode);
}
// do not break yet, might be as well in Header/Footer/Footnote/Fly
diff --git a/sw/source/core/frmedt/fecopy.cxx b/sw/source/core/frmedt/fecopy.cxx
index bc7388ce56ba..2a23f31eb3bc 100644
--- a/sw/source/core/frmedt/fecopy.cxx
+++ b/sw/source/core/frmedt/fecopy.cxx
@@ -838,7 +838,7 @@ bool SwFEShell::Paste(SwDoc& rClpDoc, bool bNestedTable)
SwPaM aCpyPam(aIdx, SwNodeIndex(rClpDoc.GetNodes().GetEndOfContent(), -1));
if (SwContentNode *const pAtEnd = aCpyPam.GetNode(true).GetContentNode())
{
- pAtEnd->MakeEndIndex(&aCpyPam.GetPoint()->nContent);
+ aCpyPam.GetPoint()->AssignEndIndex(*pAtEnd);
}
// If there are table formulas in the area, then display the table first
diff --git a/sw/source/core/layout/trvlfrm.cxx b/sw/source/core/layout/trvlfrm.cxx
index 37e7b77dc775..b5247220de5d 100644
--- a/sw/source/core/layout/trvlfrm.cxx
+++ b/sw/source/core/layout/trvlfrm.cxx
@@ -617,8 +617,7 @@ bool SwNoTextFrame::LeftMargin(SwPaM *pPam) const
{
if( &pPam->GetNode() != GetNode() )
return false;
- const_cast<SwContentNode*>(GetNode())->
- MakeStartIndex(&pPam->GetPoint()->nContent);
+ pPam->GetPoint()->AssignStartIndex(*GetNode());
return true;
}
@@ -626,8 +625,7 @@ bool SwNoTextFrame::RightMargin(SwPaM *pPam, bool) const
{
if( &pPam->GetNode() != GetNode() )
return false;
- const_cast<SwContentNode*>(GetNode())->
- MakeEndIndex(&pPam->GetPoint()->nContent);
+ pPam->GetPoint()->AssignEndIndex(*GetNode());
return true;
}
@@ -953,11 +951,10 @@ static bool lcl_UpDown( SwPaM *pPam, const SwContentFrame *pStart,
{ // set the Point on the Content-Node
assert(pCnt->IsNoTextFrame());
SwContentNode *const pCNd = const_cast<SwContentNode*>(static_cast<SwNoTextFrame const*>(pCnt)->GetNode());
- pPam->GetPoint()->nNode = *pCNd;
if ( fnNxtPrv == lcl_GetPrvCnt )
- pCNd->MakeEndIndex( &pPam->GetPoint()->nContent );
+ pPam->GetPoint()->AssignEndIndex(*pCNd);
else
- pCNd->MakeStartIndex( &pPam->GetPoint()->nContent );
+ pPam->GetPoint()->AssignStartIndex(*pCNd);
}
return true;
}
diff --git a/sw/source/core/undo/undobj.cxx b/sw/source/core/undo/undobj.cxx
index dfa4fc114ba3..dce1ef41d575 100644
--- a/sw/source/core/undo/undobj.cxx
+++ b/sw/source/core/undo/undobj.cxx
@@ -842,11 +842,9 @@ void SwUndoSaveContent::MovePtForward( SwPaM& rPam, bool bMvBkwrd )
rPam.Move( fnMoveForward );
else
{
- ++rPam.GetPoint()->nNode;
+ rPam.GetPoint()->Adjust(SwNodeOffset(1));
SwContentNode* pCNd = rPam.GetContentNode();
- if( pCNd )
- pCNd->MakeStartIndex( &rPam.GetPoint()->nContent );
- else
+ if( !pCNd )
rPam.Move( fnMoveForward );
}
}
diff --git a/sw/source/core/unocore/unotext.cxx b/sw/source/core/unocore/unotext.cxx
index f4033be51050..2cb69face648 100644
--- a/sw/source/core/unocore/unotext.cxx
+++ b/sw/source/core/unocore/unotext.cxx
@@ -2390,11 +2390,11 @@ SwXText::copyText(
pFirstNode = temp.GetMark()->GetNode().GetTextNode();
if (pFirstNode)
{
- pFirstNode->MakeStartIndex(&temp.GetMark()->nContent);
+ temp.GetMark()->AssignStartIndex(*pFirstNode);
}
if (SwTextNode *const pNode = temp.GetPoint()->GetNode().GetTextNode())
{
- pNode->MakeEndIndex(&temp.GetPoint()->nContent);
+ temp.GetPoint()->AssignEndIndex(*pNode);
}
// Explicitly request copy text mode, so
// sw::DocumentContentOperationsManager::CopyFlyInFlyImpl() will copy shapes anchored to
diff --git a/sw/source/filter/writer/writer.cxx b/sw/source/filter/writer/writer.cxx
index a810ff47e3e0..640cec57bcc9 100644
--- a/sw/source/filter/writer/writer.cxx
+++ b/sw/source/filter/writer/writer.cxx
@@ -206,8 +206,7 @@ Writer::NewUnoCursor(SwDoc & rDoc, SwNodeOffset const nStartIdx, SwNodeOffset co
if (!pCNode)
pCNode = SwNodes::GoPrevious(&aStt);
assert(pCNode && "No more ContentNode at StartPos");
- pCNode->MakeEndIndex( &pNew->GetPoint()->nContent );
- pNew->GetPoint()->nNode = aStt;
+ pNew->GetPoint()->AssignEndIndex( *pCNode );
return pNew;
}