sw/source/core/txtnode/atrflyin.cxx |   25 +++++++------------------
 1 file changed, 7 insertions(+), 18 deletions(-)

New commits:
commit a1ea7bee33ed53ecdc1a68acf554680e5c88804f
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Thu Sep 1 09:35:55 2022 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Thu Sep 1 11:31:33 2022 +0200

    use more SwPosition::Assign
    
    part of hiding the internals of SwPosition
    
    Change-Id: Id4d02e2b5c156ff7a93ce5d2d974c4594052bac3
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139145
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sw/source/core/txtnode/atrflyin.cxx 
b/sw/source/core/txtnode/atrflyin.cxx
index e46487004633..8216c96805c4 100644
--- a/sw/source/core/txtnode/atrflyin.cxx
+++ b/sw/source/core/txtnode/atrflyin.cxx
@@ -110,17 +110,7 @@ void SwTextFlyCnt::CopyFlyFormat( SwDoc& rDoc )
         if( !pCNd )
             pCNd = rDoc.GetNodes().GoNext( &aIdx );
 
-        SwPosition pos = *aAnchor.GetContentAnchor();
-        pos.nNode = aIdx;
-        if (RndStdIds::FLY_AS_CHAR == aAnchor.GetAnchorId())
-        {
-            pos.nContent.Assign( pCNd, 0 );
-        }
-        else
-        {
-            pos.nContent.Assign( nullptr, 0 );
-            assert(false);
-        }
+        SwPosition pos(aIdx.GetNode());
         aAnchor.SetAnchor( &pos );
     }
 
@@ -139,26 +129,25 @@ void SwTextFlyCnt::SetAnchor( const SwTextNode *pNode )
 
     SwDoc& rDoc = const_cast<SwDoc&>(pNode->GetDoc());
 
-    SwContentIndex aIdx( pNode, GetStart() );
-    SwPosition aPos( *pNode->StartOfSectionNode(), aIdx );
     SwFrameFormat* pFormat = GetFlyCnt().GetFrameFormat();
     SwFormatAnchor aAnchor( pFormat->GetAnchor() );
     SwNode *const pOldNode(aAnchor.GetContentAnchor()
             ? &aAnchor.GetContentAnchor()->GetNode()
             : nullptr);
 
+    std::optional<SwPosition> oPos;
     if (!pOldNode || !pOldNode->GetNodes().IsDocNodes() ||
         pOldNode != static_cast<SwNode const *>(pNode))
     {
-        aPos.nNode = *pNode;
+        oPos.emplace( *pNode, GetStart() );
     }
     else
     {
-        aPos.nNode = *pOldNode;
+        oPos.emplace( *pOldNode, pOldNode->GetContentNode(), GetStart() );
     }
 
     aAnchor.SetType( RndStdIds::FLY_AS_CHAR );        // default!
-    aAnchor.SetAnchor( &aPos );
+    aAnchor.SetAnchor( &*oPos );
 
     // in case of anchor change, delete all FlyFrames
     // JP 25.04.95: if the Frames can be moved within SplitNode, they don't
@@ -188,7 +177,7 @@ void SwTextFlyCnt::SetAnchor( const SwTextNode *pNode )
         // tdf#91228 must notify the anchor nodes despite LockModify
         assert(pOldNode);
         pOldNode->RemoveAnchoredFly(pFormat);
-        aPos.GetNode().AddAnchoredFly(pFormat);
+        oPos->GetNode().AddAnchoredFly(pFormat);
         pFormat->UnlockModify();
     }
     else
@@ -229,7 +218,7 @@ void SwTextFlyCnt::SetAnchor( const SwTextNode *pNode )
             if (bIsInSplitNode)
             {
                 pOldNode->RemoveAnchoredFly(pTextBox);
-                aPos.GetNode().AddAnchoredFly(pTextBox);
+                oPos->GetNode().AddAnchoredFly(pTextBox);
                 pTextBox->UnlockModify();
             }
             else

Reply via email to