sw/inc/redline.hxx                                      |    2 
 sw/source/core/doc/DocumentContentOperationsManager.cxx |   10 -
 sw/source/core/doc/docredln.cxx                         |  156 ++++++++--------
 sw/source/core/frmedt/fefly1.cxx                        |   12 -
 4 files changed, 89 insertions(+), 91 deletions(-)

New commits:
commit dbee0c128b75b3ea0cb527300ebcd0ad55745fb1
Author:     Noel Grandin <noelgran...@gmail.com>
AuthorDate: Fri Oct 7 12:54:39 2022 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Fri Oct 7 18:23:12 2022 +0200

    use more unique_ptr in GetAllValidRanges
    
    Change-Id: I59f6afb5b39779a58d2b0ea47b524df299e1c0d9
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141050
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sw/inc/redline.hxx b/sw/inc/redline.hxx
index 1ad8c456b56c..f2d6c31a40ac 100644
--- a/sw/inc/redline.hxx
+++ b/sw/inc/redline.hxx
@@ -338,7 +338,7 @@ class SW_DLLPUBLIC SwRedlineHint final : public SfxHint
 
 namespace sw {
 
-std::vector<SwRangeRedline*> GetAllValidRanges(std::unique_ptr<SwRangeRedline> 
p);
+std::vector<std::unique_ptr<SwRangeRedline>> 
GetAllValidRanges(std::unique_ptr<SwRangeRedline> p);
 
 } // namespace sw
 
diff --git a/sw/source/core/doc/DocumentContentOperationsManager.cxx 
b/sw/source/core/doc/DocumentContentOperationsManager.cxx
index ec52d3ec1221..677ae7f0b8fd 100644
--- a/sw/source/core/doc/DocumentContentOperationsManager.cxx
+++ b/sw/source/core/doc/DocumentContentOperationsManager.cxx
@@ -4094,12 +4094,12 @@ bool 
DocumentContentOperationsManager::DeleteAndJoinWithRedlineImpl(SwPaM & rPam
         return false; // do not add empty redlines
     }
 
-    std::vector<SwRangeRedline*> redlines;
+    std::vector<std::unique_ptr<SwRangeRedline>> redlines;
     {
         auto pRedline(std::make_unique<SwRangeRedline>(RedlineType::Delete, 
rPam));
         if (pRedline->HasValidRange())
         {
-            redlines.push_back(pRedline.release());
+            redlines.push_back(std::move(pRedline));
         }
         else // sigh ... why is such a selection even possible...
         {    // split it up so we get one SwUndoRedlineDelete per inserted RL
@@ -4160,7 +4160,7 @@ bool 
DocumentContentOperationsManager::DeleteAndJoinWithRedlineImpl(SwPaM & rPam
         m_rDoc.getIDocumentRedlineAccess().SetRedlineFlags(
             RedlineFlags::On | RedlineFlags::ShowInsert | 
RedlineFlags::ShowDelete);
 
-        for (SwRangeRedline * pRedline : redlines)
+        for (std::unique_ptr<SwRangeRedline> & pRedline : redlines)
         {
             assert(pRedline->HasValidRange());
             undos.emplace_back(std::make_unique<SwUndoRedlineDelete>(
@@ -4195,14 +4195,14 @@ bool 
DocumentContentOperationsManager::DeleteAndJoinWithRedlineImpl(SwPaM & rPam
         }
     }
 
-    for (SwRangeRedline *const pRedline : redlines)
+    for (std::unique_ptr<SwRangeRedline> & pRedline : redlines)
     {
         // note: 1. the pRedline can still be merged & deleted
         //       2. the impl. can even DeleteAndJoin the range => no plain PaM
         std::shared_ptr<SwUnoCursor> const 
pCursor(m_rDoc.CreateUnoCursor(*pRedline->GetMark()));
         pCursor->SetMark();
         *pCursor->GetPoint() = *pRedline->GetPoint();
-        m_rDoc.getIDocumentRedlineAccess().AppendRedline(pRedline, true);
+        m_rDoc.getIDocumentRedlineAccess().AppendRedline(pRedline.release(), 
true);
         // sw_redlinehide: 2 reasons why this is needed:
         // 1. it's the first redline in node => RedlineDelText was sent but 
ignored
         // 2. redline spans multiple nodes => must merge text frames
diff --git a/sw/source/core/doc/docredln.cxx b/sw/source/core/doc/docredln.cxx
index 68225e0741b7..cfd77733e331 100644
--- a/sw/source/core/doc/docredln.cxx
+++ b/sw/source/core/doc/docredln.cxx
@@ -477,9 +477,9 @@ bool SwRedlineTable::Insert(SwRangeRedline*& p, size_type& 
rP)
 
 namespace sw {
 
-std::vector<SwRangeRedline*> GetAllValidRanges(std::unique_ptr<SwRangeRedline> 
p)
+std::vector<std::unique_ptr<SwRangeRedline>> 
GetAllValidRanges(std::unique_ptr<SwRangeRedline> p)
 {
-    std::vector<SwRangeRedline*> ret;
+    std::vector<std::unique_ptr<SwRangeRedline>> ret;
     // Create valid "sub-ranges" from the Selection
     auto [pStt, pEnd] = p->StartEnd(); // SwPosition*
     SwPosition aNewStt( *pStt );
@@ -493,91 +493,90 @@ std::vector<SwRangeRedline*> 
GetAllValidRanges(std::unique_ptr<SwRangeRedline> p
             aNewStt.Assign(rNds.GetEndOfContent());
     }
 
-    SwRangeRedline* pNew = nullptr;
 
-    if( aNewStt < *pEnd )
-        do {
-            if( !pNew )
-                pNew = new SwRangeRedline( p->GetRedlineData(), aNewStt );
-            else
-            {
-                pNew->DeleteMark();
-                *pNew->GetPoint() = aNewStt;
-            }
+    if( aNewStt >= *pEnd )
+        return ret;
 
-            pNew->SetMark();
-            GoEndSection( pNew->GetPoint() );
-            // i60396: If the redlines starts before a table but the table is 
the last member
-            // of the section, the GoEndSection will end inside the table.
-            // This will result in an incorrect redline, so we've to go back
-            SwNode* pTab = 
pNew->GetPoint()->GetNode().StartOfSectionNode()->FindTableNode();
-            // We end in a table when pTab != 0
-            if( pTab && 
!pNew->GetMark()->GetNode().StartOfSectionNode()->FindTableNode() )
-            { // but our Mark was outside the table => Correction
-                do
-                {
-                    // We want to be before the table
-                    pNew->GetPoint()->Assign(*pTab);
-                    pC = GoPreviousPos( pNew->GetPoint(), false ); // here we 
are.
-                    if( pC )
-                        pNew->GetPoint()->SetContent( 0 );
-                    pTab = 
pNew->GetPoint()->GetNode().StartOfSectionNode()->FindTableNode();
-                } while( pTab ); // If there is another table we have to 
repeat our step backwards
-            }
+    std::unique_ptr<SwRangeRedline> pNew;
+    do {
+        if( !pNew )
+            pNew.reset(new SwRangeRedline( p->GetRedlineData(), aNewStt ));
+        else
+        {
+            pNew->DeleteMark();
+            *pNew->GetPoint() = aNewStt;
+        }
 
-            if( *pNew->GetPoint() > *pEnd )
+        pNew->SetMark();
+        GoEndSection( pNew->GetPoint() );
+        // i60396: If the redlines starts before a table but the table is the 
last member
+        // of the section, the GoEndSection will end inside the table.
+        // This will result in an incorrect redline, so we've to go back
+        SwNode* pTab = 
pNew->GetPoint()->GetNode().StartOfSectionNode()->FindTableNode();
+        // We end in a table when pTab != 0
+        if( pTab && 
!pNew->GetMark()->GetNode().StartOfSectionNode()->FindTableNode() )
+        { // but our Mark was outside the table => Correction
+            do
             {
-                pC = nullptr;
-                if( aNewStt.GetNode() != pEnd->GetNode() )
-                    do {
-                        SwNode& rCurNd = aNewStt.GetNode();
-                        if( rCurNd.IsStartNode() )
-                        {
-                            if( rCurNd.EndOfSectionIndex() < 
pEnd->GetNodeIndex() )
-                                aNewStt.Assign( *rCurNd.EndOfSectionNode() );
-                            else
-                                break;
-                        }
-                        else if( rCurNd.IsContentNode() )
-                            pC = rCurNd.GetContentNode();
-                        aNewStt.Adjust(SwNodeOffset(1));
-                    } while( aNewStt.GetNodeIndex() < pEnd->GetNodeIndex() );
-
-                if( aNewStt.GetNode() == pEnd->GetNode() )
-                    aNewStt.SetContent(pEnd->GetContentIndex());
-                else if( pC )
-                {
-                    aNewStt.Assign(*pC, pC->Len() );
-                }
+                // We want to be before the table
+                pNew->GetPoint()->Assign(*pTab);
+                pC = GoPreviousPos( pNew->GetPoint(), false ); // here we are.
+                if( pC )
+                    pNew->GetPoint()->SetContent( 0 );
+                pTab = 
pNew->GetPoint()->GetNode().StartOfSectionNode()->FindTableNode();
+            } while( pTab ); // If there is another table we have to repeat 
our step backwards
+        }
 
-                if( aNewStt <= *pEnd )
-                    *pNew->GetPoint() = aNewStt;
+        if( *pNew->GetPoint() > *pEnd )
+        {
+            pC = nullptr;
+            if( aNewStt.GetNode() != pEnd->GetNode() )
+                do {
+                    SwNode& rCurNd = aNewStt.GetNode();
+                    if( rCurNd.IsStartNode() )
+                    {
+                        if( rCurNd.EndOfSectionIndex() < pEnd->GetNodeIndex() )
+                            aNewStt.Assign( *rCurNd.EndOfSectionNode() );
+                        else
+                            break;
+                    }
+                    else if( rCurNd.IsContentNode() )
+                        pC = rCurNd.GetContentNode();
+                    aNewStt.Adjust(SwNodeOffset(1));
+                } while( aNewStt.GetNodeIndex() < pEnd->GetNodeIndex() );
+
+            if( aNewStt.GetNode() == pEnd->GetNode() )
+                aNewStt.SetContent(pEnd->GetContentIndex());
+            else if( pC )
+            {
+                aNewStt.Assign(*pC, pC->Len() );
             }
-            else
-                aNewStt = *pNew->GetPoint();
+
+            if( aNewStt <= *pEnd )
+                *pNew->GetPoint() = aNewStt;
+        }
+        else
+            aNewStt = *pNew->GetPoint();
 #if OSL_DEBUG_LEVEL > 0
-            CheckPosition( pNew->GetPoint(), pNew->GetMark() );
+        CheckPosition( pNew->GetPoint(), pNew->GetMark() );
 #endif
 
-            if( *pNew->GetPoint() != *pNew->GetMark() &&
-                pNew->HasValidRange())
-            {
-                ret.push_back(pNew);
-                pNew = nullptr;
-            }
+        if( *pNew->GetPoint() != *pNew->GetMark() &&
+            pNew->HasValidRange())
+        {
+            ret.push_back(std::move(pNew));
+        }
 
-            if( aNewStt >= *pEnd )
-                break;
-            pC = rNds.GoNext( &aNewStt.nNode );
-            if( !pC )
-                break;
+        if( aNewStt >= *pEnd )
+            break;
+        pC = rNds.GoNext( &aNewStt.nNode );
+        if( !pC )
+            break;
 
-            aNewStt.nContent.Assign( pC, 0 );
+        aNewStt.nContent.Assign( pC, 0 );
 
-        } while( aNewStt < *pEnd );
+    } while( aNewStt < *pEnd );
 
-    delete pNew;
-    p.reset();
     return ret;
 }
 
@@ -586,15 +585,16 @@ std::vector<SwRangeRedline*> 
GetAllValidRanges(std::unique_ptr<SwRangeRedline> p
 bool SwRedlineTable::InsertWithValidRanges(SwRangeRedline*& p, size_type* 
pInsPos)
 {
     bool bAnyIns = false;
-    std::vector<SwRangeRedline*> const redlines(
+    std::vector<std::unique_ptr<SwRangeRedline>> redlines(
             GetAllValidRanges(std::unique_ptr<SwRangeRedline>(p)));
-    for (SwRangeRedline * pRedline : redlines)
+    for (std::unique_ptr<SwRangeRedline> & pRedline : redlines)
     {
         assert(pRedline->HasValidRange());
         size_type nInsPos;
-        if (Insert(pRedline, nInsPos))
+        auto pTmpRedline = pRedline.release();
+        if (Insert(pTmpRedline, nInsPos))
         {
-            pRedline->CallDisplayFunc(nInsPos);
+            pTmpRedline->CallDisplayFunc(nInsPos);
             bAnyIns = true;
             if (pInsPos && *pInsPos < nInsPos)
             {
commit e5fc2a44a64afbf9058a01283be3834c21c7d12c
Author:     Noel Grandin <noelgran...@gmail.com>
AuthorDate: Fri Oct 7 16:41:00 2022 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Fri Oct 7 18:23:00 2022 +0200

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

diff --git a/sw/source/core/frmedt/fefly1.cxx b/sw/source/core/frmedt/fefly1.cxx
index 49c712dcc78b..c5baab23358c 100644
--- a/sw/source/core/frmedt/fefly1.cxx
+++ b/sw/source/core/frmedt/fefly1.cxx
@@ -162,7 +162,7 @@ static bool lcl_FindAnchorPos(
                 {
                     if ( SwCursorShell::PosInsideInputField( aPos ) )
                     {
-                        aPos.nContent = SwCursorShell::StartOfInputFieldAtPos( 
aPos );
+                        aPos.SetContent( 
SwCursorShell::StartOfInputFieldAtPos( aPos ) );
                     }
                 }
             }
@@ -184,8 +184,8 @@ static bool lcl_FindAnchorPos(
 
             if( pNewAnch && &rFrame != pNewAnch && !pNewAnch->IsProtected() )
             {
-                aPos.nNode = *static_cast<const 
SwFlyFrame*>(pNewAnch)->GetFormat()->GetContent().
-                                GetContentIdx();
+                aPos.Assign( *static_cast<const 
SwFlyFrame*>(pNewAnch)->GetFormat()->GetContent().
+                                GetContentIdx() );
                 aNewAnch.SetAnchor( &aPos );
                 break;
             }
@@ -555,11 +555,9 @@ Point SwFEShell::FindAnchorPos( const Point& rAbsPos, bool 
bMoveIt )
                 {
                     case RndStdIds::FLY_AT_PARA:
                     {
-                        SwPosition pos = *aAnch.GetContentAnchor();
-                        pos.nNode = pTextFrame->IsTextFrame()
+                        SwPosition pos(pTextFrame->IsTextFrame()
                             ? *static_cast<SwTextFrame 
const*>(pTextFrame)->GetTextNodeForParaProps()
-                            : *static_cast<const 
SwNoTextFrame*>(pTextFrame)->GetNode();
-                        pos.nContent.Assign(nullptr,0);
+                            : *static_cast<const 
SwNoTextFrame*>(pTextFrame)->GetNode());
                         aAnch.SetAnchor( &pos );
                         break;
                     }

Reply via email to