sw/inc/pam.hxx                           |    2 ++
 sw/source/core/crsr/pam.cxx              |    5 +++++
 sw/source/uibase/dochdl/swdtflvr.cxx     |    5 ++---
 sw/source/uibase/docvw/AnnotationWin.cxx |   12 ++++--------
 sw/source/uibase/docvw/edtwin.cxx        |   16 +++++++---------
 5 files changed, 20 insertions(+), 20 deletions(-)

New commits:
commit 0de37cdd0251a7fc080bc6b95ac8708833bd0552
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Tue Aug 23 15:19:58 2022 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Tue Aug 23 19:05:21 2022 +0200

    Use more SwPosition::Adjust
    
    to keep the internal fields of SwPosition in sync.
    
    Change-Id: I46dbb7e562cf41dcceab57e2f5bf1e19babb955a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138731
    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 69d960c2881c..971090296173 100644
--- a/sw/inc/pam.hxx
+++ b/sw/inc/pam.hxx
@@ -99,6 +99,8 @@ struct SAL_WARN_UNUSED SW_DLLPUBLIC SwPosition
     void Adjust( SwNodeOffset nDelta );
     /// Adjust content index, only valid to call this if the position points 
to a SwContentNode subclass
     void AdjustContent( sal_Int32 nDelta );
+    /// Set content index, only valid to call this if the position points to a 
SwContentNode subclass
+    void SetContent( sal_Int32 nContentIndex );
 };
 
 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 96a1336bd03a..1b03eed95e8d 100644
--- a/sw/source/core/crsr/pam.cxx
+++ b/sw/source/core/crsr/pam.cxx
@@ -256,6 +256,11 @@ void SwPosition::AdjustContent( sal_Int32 nDelta )
     assert(nNode.GetNode().GetContentNode() && "only valid to call this if we 
point to an SwContentNode");
     nContent += nDelta;
 }
+void SwPosition::SetContent( sal_Int32 nContentIndex )
+{
+    assert(nNode.GetNode().GetContentNode() && "only valid to call this if we 
point to an SwContentNode");
+    nContent = nContentIndex;
+}
 void SwPosition::AssignStartIndex( const SwContentNode& rNd )
 {
     nNode = rNd;
diff --git a/sw/source/uibase/dochdl/swdtflvr.cxx 
b/sw/source/uibase/dochdl/swdtflvr.cxx
index a735c9dffc73..c6610e387ca0 100644
--- a/sw/source/uibase/dochdl/swdtflvr.cxx
+++ b/sw/source/uibase/dochdl/swdtflvr.cxx
@@ -1339,14 +1339,13 @@ SwPasteContext::~SwPasteContext()
                 *m_oPaM->GetMark() = *pCursor->GetPoint();
 
                 // Restore point.
-                ++m_oPaM->GetPoint()->nNode;
+                m_oPaM->GetPoint()->Adjust(SwNodeOffset(1));
                 SwNode& rNode = m_oPaM->GetPointNode();
                 if (!rNode.IsTextNode())
                     // Starting point is no longer text.
                     return;
 
-                
m_oPaM->GetPoint()->nContent.Assign(static_cast<SwContentNode*>(&rNode),
-                                                    m_nStartContent);
+                m_oPaM->GetPoint()->SetContent(m_nStartContent);
 
                 aPropertyValue.Name = "TextRange";
                 const uno::Reference<text::XTextRange> xTextRange = 
SwXTextRange::CreateXTextRange(
diff --git a/sw/source/uibase/docvw/AnnotationWin.cxx 
b/sw/source/uibase/docvw/AnnotationWin.cxx
index d10cb89b2ef4..685dcbb5ce94 100644
--- a/sw/source/uibase/docvw/AnnotationWin.cxx
+++ b/sw/source/uibase/docvw/AnnotationWin.cxx
@@ -294,8 +294,7 @@ void SwAnnotationWin::UpdateData()
         if (rUndoRedo.DoesUndo())
         {
             SwTextField *const pTextField = mpFormatField->GetTextField();
-            SwPosition aPosition( pTextField->GetTextNode() );
-            aPosition.nContent = pTextField->GetStart();
+            SwPosition aPosition( pTextField->GetTextNode(), 
pTextField->GetStart() );
             rUndoRedo.AppendUndo(
                 std::make_unique<SwUndoFieldFromDoc>(aPosition, *pOldField, 
*mpField, nullptr, true));
         }
@@ -353,8 +352,7 @@ sal_uInt32 SwAnnotationWin::MoveCaret()
 sal_uInt32 SwAnnotationWin::CalcParent()
 {
     SwTextField* pTextField = mpFormatField->GetTextField();
-    SwPosition aPosition( pTextField->GetTextNode() );
-    aPosition.nContent = pTextField->GetStart();
+    SwPosition aPosition( pTextField->GetTextNode(), pTextField->GetStart() );
     SwTextAttr * const pTextAttr =
         pTextField->GetTextNode().GetTextAttrForCharAt(
             aPosition.GetContentIndex() - 1,
@@ -374,8 +372,7 @@ sal_uInt32 SwAnnotationWin::CountFollowing()
 {
     sal_uInt32 aCount = 1;  // we start with 1, so we have to subtract one at 
the end again
     SwTextField* pTextField = mpFormatField->GetTextField();
-    SwPosition aPosition( pTextField->GetTextNode() );
-    aPosition.nContent = pTextField->GetStart();
+    SwPosition aPosition( pTextField->GetTextNode(), pTextField->GetStart() );
 
     SwTextAttr * pTextAttr = pTextField->GetTextNode().GetTextAttrForCharAt(
                                         aPosition.GetContentIndex() + 1,
@@ -450,8 +447,7 @@ void SwAnnotationWin::InitAnswer(OutlinerParaObject const & 
rText)
     if (rUndoRedo.DoesUndo())
     {
         SwTextField *const pTextField = mpFormatField->GetTextField();
-        SwPosition aPosition( pTextField->GetTextNode() );
-        aPosition.nContent = pTextField->GetStart();
+        SwPosition aPosition( pTextField->GetTextNode(), 
pTextField->GetStart() );
         rUndoRedo.AppendUndo(
             std::make_unique<SwUndoFieldFromDoc>(aPosition, *pOldField, 
*mpField, nullptr, true));
     }
diff --git a/sw/source/uibase/docvw/edtwin.cxx 
b/sw/source/uibase/docvw/edtwin.cxx
index 919364816ebb..2f166579a27c 100644
--- a/sw/source/uibase/docvw/edtwin.cxx
+++ b/sw/source/uibase/docvw/edtwin.cxx
@@ -982,7 +982,7 @@ void SwEditWin::FlushInBuffer()
         {
             if (!rCursor.HasMark())
                 rCursor.SetMark();
-            rCursor.Start()->nContent -= nExpandSelection;
+            rCursor.Start()->AdjustContent( -nExpandSelection );
         }
     }
 
@@ -5794,9 +5794,9 @@ void SwEditWin::Command( const CommandEvent& rCEvt )
             const CommandSelectionChangeData *pData = 
rCEvt.GetSelectionChangeData();
             rSh.SttCursorMove();
             rSh.GoStartSentence();
-            rSh.GetCursor()->GetPoint()->nContent += 
sal::static_int_cast<sal_uInt16, sal_uLong>(pData->GetStart());
+            
rSh.GetCursor()->GetPoint()->AdjustContent(sal::static_int_cast<sal_uInt16, 
sal_uLong>(pData->GetStart()));
             rSh.SetMark();
-            rSh.GetCursor()->GetMark()->nContent += 
sal::static_int_cast<sal_uInt16, sal_uLong>(pData->GetEnd() - 
pData->GetStart());
+            
rSh.GetCursor()->GetMark()->AdjustContent(sal::static_int_cast<sal_uInt16, 
sal_uLong>(pData->GetEnd() - pData->GetStart()));
             rSh.EndCursorMove( true );
         }
         break;
@@ -5834,9 +5834,8 @@ void SwEditWin::Command( const CommandEvent& rCEvt )
                 if( nPosNodeIdx < nMarkNodeIdx )
                 {
                     rSh.GetCursor()->GetPoint()->Assign(nPosNodeIdx, nPosIdx);
-                    rSh.GetCursor()->GetMark()->nNode = nPosNodeIdx;
-                    rSh.GetCursor()->GetMark()->nContent =
-                        rSh.GetCursor()->GetPointContentNode()->Len();
+                    rSh.GetCursor()->GetMark()->Assign(nPosNodeIdx,
+                        rSh.GetCursor()->GetPointContentNode()->Len());
                 }
                 else if( nPosNodeIdx == nMarkNodeIdx )
                 {
@@ -5846,9 +5845,8 @@ void SwEditWin::Command( const CommandEvent& rCEvt )
                 else
                 {
                     rSh.GetCursor()->GetMark()->Assign(nMarkNodeIdx, nMarkIdx);
-                    rSh.GetCursor()->GetPoint()->nNode = nMarkNodeIdx;
-                    rSh.GetCursor()->GetPoint()->nContent =
-                        rSh.GetCursor()->GetMarkContentNode()->Len();
+                    rSh.GetCursor()->GetPoint()->Assign(nMarkNodeIdx,
+                        rSh.GetCursor()->GetMarkContentNode()->Len());
                 }
 
                 rSh.EndCursorMove( true );

Reply via email to