sw/inc/ndarr.hxx                  |    6 +++---
 sw/source/core/crsr/crsrsh.cxx    |    5 ++---
 sw/source/core/docnode/ndsect.cxx |    3 +--
 sw/source/core/docnode/ndtbl.cxx  |   13 ++++++++-----
 sw/source/core/docnode/nodes.cxx  |   34 ++++++++++++----------------------
 sw/source/core/layout/frmtool.cxx |    5 ++---
 sw/source/core/txtnode/ndtxt.cxx  |    3 +--
 7 files changed, 29 insertions(+), 40 deletions(-)

New commits:
commit cfa942249162d5503b8a34d5813fddfb1182283a
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Wed Aug 24 14:11:01 2022 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Wed Aug 24 16:20:31 2022 +0200

    pass SwNode to FindPrvNxtFrameNode instead of SwNodeIndex
    
    part of the process of hiding the internals of SwPosition
    
    Change-Id: Ib0c24ca1179f9c8dd92e9b327daea8a5079cead1
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138765
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sw/inc/ndarr.hxx b/sw/inc/ndarr.hxx
index 902f227800c3..0dabda23ec9f 100644
--- a/sw/inc/ndarr.hxx
+++ b/sw/inc/ndarr.hxx
@@ -311,10 +311,10 @@ public:
     const   SwDoc& GetDoc() const   { return m_rMyDoc; }
 
     /** Search previous / next content node or table node with frames.
-     Search is started backward with the one before rFrameIdx and
+     Search is started backward with the one before rFrameNd and
      forward after pEnd.
-     If no valid node is found, return 0. rFrameIdx points to the node with 
frames. **/
-    SwNode* FindPrvNxtFrameNode( SwNodeIndex& rFrameIdx,
+     If no valid node is found, return nullptr. **/
+    SwNode* FindPrvNxtFrameNode( const SwNode& rFrameNd,
                                 const SwNode* pEnd,
                                 SwRootFrame const* pLayout = nullptr) const;
 
diff --git a/sw/source/core/crsr/crsrsh.cxx b/sw/source/core/crsr/crsrsh.cxx
index 2e34d4696be2..bcc0b2433c1f 100644
--- a/sw/source/core/crsr/crsrsh.cxx
+++ b/sw/source/core/crsr/crsrsh.cxx
@@ -1517,12 +1517,11 @@ static bool lcl_CheckHiddenSection( SwNodeIndex& rIdx )
     const SwSectionNode* pSectNd = rIdx.GetNode().FindSectionNode();
     if( pSectNd && pSectNd->GetSection().IsHiddenFlag() )
     {
-        SwNodeIndex aTmp( *pSectNd );
         const SwNode* pFrameNd =
-            rIdx.GetNodes().FindPrvNxtFrameNode( aTmp, 
pSectNd->EndOfSectionNode() );
+            rIdx.GetNodes().FindPrvNxtFrameNode( *pSectNd, 
pSectNd->EndOfSectionNode() );
         bOk = pFrameNd != nullptr;
         SAL_WARN_IF(!bOk, "sw.core", "found no Node with Frames");
-        rIdx = aTmp;
+        rIdx = *(bOk ? pFrameNd : pSectNd);
     }
     return bOk;
 }
diff --git a/sw/source/core/docnode/ndsect.cxx 
b/sw/source/core/docnode/ndsect.cxx
index 5fb4438bb438..d97c08d278ff 100644
--- a/sw/source/core/docnode/ndsect.cxx
+++ b/sw/source/core/docnode/ndsect.cxx
@@ -919,8 +919,7 @@ SwSectionNode* SwNodes::InsertTextSection(SwNode& rNd,
     std::optional<SwNode2LayoutSaveUpperFrames> oNode2Layout;
     if( bInsFrame )
     {
-        SwNodeIndex aTmp( *pSectNd );
-        if( !pSectNd->GetNodes().FindPrvNxtFrameNode( aTmp, 
pSectNd->EndOfSectionNode() ) )
+        if( !pSectNd->GetNodes().FindPrvNxtFrameNode( *pSectNd, 
pSectNd->EndOfSectionNode() ) )
             // Collect all Uppers
             oNode2Layout.emplace(*pSectNd);
     }
diff --git a/sw/source/core/docnode/ndtbl.cxx b/sw/source/core/docnode/ndtbl.cxx
index 556f9a11a869..fe2fc3b6822b 100644
--- a/sw/source/core/docnode/ndtbl.cxx
+++ b/sw/source/core/docnode/ndtbl.cxx
@@ -1583,8 +1583,8 @@ bool SwNodes::TableToText( const SwNodeRange& rRange, 
sal_Unicode cCh,
 
     // If the Table was alone in a Section, create the Frames via the Table's 
Upper
     std::optional<SwNode2LayoutSaveUpperFrames> oNode2Layout;
-    SwNodeIndex aFrameIdx( rRange.aStart );
-    SwNode* pFrameNd = FindPrvNxtFrameNode( aFrameIdx, &rRange.aEnd.GetNode() 
);
+    SwNode* pFrameNd = FindPrvNxtFrameNode( rRange.aStart.GetNode(), 
&rRange.aEnd.GetNode() );
+    SwNodeIndex aFrameIdx( pFrameNd ? *pFrameNd: rRange.aStart.GetNode() );
     if( !pFrameNd )
         // Collect all Uppers
         oNode2Layout.emplace(*pTableNd);
@@ -2382,10 +2382,13 @@ void 
SwTableNode::MakeFramesForAdjacentContentNode(const SwNodeIndex & rIdx)
 void SwTableNode::MakeOwnFrames(SwNodeIndex* pIdxBehind)
 {
     OSL_ENSURE( pIdxBehind, "No Index" );
-    *pIdxBehind = *this;
-    SwNode *pNd = GetNodes().FindPrvNxtFrameNode( *pIdxBehind, 
EndOfSectionNode() );
+    SwNode *pNd = GetNodes().FindPrvNxtFrameNode( *this, EndOfSectionNode() );
     if( !pNd )
-        return ;
+    {
+        *pIdxBehind = *this;
+        return;
+    }
+    *pIdxBehind = *pNd;
 
     SwFrame *pFrame( nullptr );
     SwLayoutFrame *pUpper( nullptr );
diff --git a/sw/source/core/docnode/nodes.cxx b/sw/source/core/docnode/nodes.cxx
index 48c135861686..93384c28d12a 100644
--- a/sw/source/core/docnode/nodes.cxx
+++ b/sw/source/core/docnode/nodes.cxx
@@ -366,8 +366,7 @@ void SwNodes::ChgNode( SwNodeIndex const & rDelPos, 
SwNodeOffset nSz,
 
     // get the frames:
     SwNodeIndex aIdx( *pPrevInsNd, 1 );
-    SwNodeIndex aFrameNdIdx( aIdx );
-    SwNode* pFrameNd = rNds.FindPrvNxtFrameNode( aFrameNdIdx,
+    SwNode* pFrameNd = rNds.FindPrvNxtFrameNode( aIdx.GetNode(),
                                     rNds[ rInsPos.GetIndex() - 1 ] );
 
     if( !pFrameNd )
@@ -2182,16 +2181,16 @@ SwContentNode* SwNodes::GoPrevSection( SwPosition * 
pIdx,
 
 //TODO: The inventor of the "single responsibility principle" will be crying 
if you ever show this code to him!
 /** find the next/previous ContentNode or table node that should have layout
- * frames that are siblings to the ones of the node at rFrameIdx.
+ * frames that are siblings to the ones of the node at rFrameNd.
  *
- * Search is started backward with the one before rFrameIdx and
+ * Search is started backward with the one before rFrameNd and
  * forward after pEnd.
  *
- * @param rFrameIdx in: node with frames to search in; out: found node
- * @param pEnd last node after rFrameIdx that should be excluded from search
+ * @param rFrameNd in: node with frames to search in; out: found node
+ * @param pEnd last node after rFrameNd that should be excluded from search
  * @return result node; 0 if not found
  */
-SwNode* SwNodes::FindPrvNxtFrameNode( SwNodeIndex& rFrameIdx,
+SwNode* SwNodes::FindPrvNxtFrameNode( const SwNode& rFrameNd,
         SwNode const*const pEnd,
         SwRootFrame const*const pLayout) const
 {
@@ -2202,20 +2201,20 @@ SwNode* SwNodes::FindPrvNxtFrameNode( SwNodeIndex& 
rFrameIdx,
     // no layout -> skip
     if( GetDoc().getIDocumentLayoutAccess().GetCurrentViewShell() )
     {
-        SwNode *const pSttNd = &rFrameIdx.GetNode();
+        const SwNode *const pSttNd = &rFrameNd;
 
         // inside a hidden section?
-        SwSectionNode *const pSectNd = pSttNd->IsSectionNode()
+        const SwSectionNode *const pSectNd = pSttNd->IsSectionNode()
                     ? pSttNd->StartOfSectionNode()->FindSectionNode()
                     : pSttNd->FindSectionNode();
         if( !( pSectNd && pSectNd->GetSection().CalcHiddenFlag() ) )
         {
             // in a table in table situation we have to assure that we don't 
leave the
             // outer table cell when the inner table is looking for a PrvNxt...
-            SwTableNode *const pTableNd = pSttNd->IsTableNode()
+            const SwTableNode *const pTableNd = pSttNd->IsTableNode()
                     ? pSttNd->StartOfSectionNode()->FindTableNode()
                     : pSttNd->FindTableNode();
-            SwNodeIndex aIdx( rFrameIdx );
+            SwNodeIndex aIdx( rFrameNd );
 
             // search backward for a content or table node
 
@@ -2227,7 +2226,6 @@ SwNode* SwNodes::FindPrvNxtFrameNode( SwNodeIndex& 
rFrameIdx,
                 if (pFrameNd->IsContentNode())
                 {
                     // TODO why does this not check for nested tables like 
forward direction
-                    rFrameIdx = aIdx;
                     return pFrameNd;
                 }
                 else if (pFrameNd->IsEndNode() && 
pFrameNd->StartOfSectionNode()->IsTableNode())
@@ -2237,7 +2235,6 @@ SwNode* SwNodes::FindPrvNxtFrameNode( SwNodeIndex& 
rFrameIdx,
                         || 
pFrameNd->StartOfSectionNode()->GetRedlineMergeFlag() != SwNode::Merge::Hidden)
                     {
                         pFrameNd = pFrameNd->StartOfSectionNode();
-                        rFrameIdx = *pFrameNd;
                         return pFrameNd;
                     }
                     else
@@ -2251,7 +2248,7 @@ SwNode* SwNodes::FindPrvNxtFrameNode( SwNodeIndex& 
rFrameIdx,
                 {
                     pFrameNd = GoPrevSection( &aIdx, true, false );
                     if ( nullptr != pFrameNd && !(
-                            ::CheckNodesRange( aIdx.GetNode(), 
rFrameIdx.GetNode(), true ) &&
+                            ::CheckNodesRange( aIdx.GetNode(), rFrameNd, true 
) &&
                             // Never out of the table at the start
                             pFrameNd->FindTableNode() == pTableNd &&
                             // Bug 37652: Never out of the table at the end
@@ -2286,11 +2283,6 @@ SwNode* SwNodes::FindPrvNxtFrameNode( SwNodeIndex& 
rFrameIdx,
                         pTableNode != 
pSttNd->StartOfSectionNode()->FindTableNode())
                     {
                         pFrameNd = pTableNode;
-                        rFrameIdx = *pFrameNd;
-                    }
-                    else
-                    {
-                        rFrameIdx = aIdx;
                     }
                     return pFrameNd;
                 }
@@ -2300,7 +2292,6 @@ SwNode* SwNodes::FindPrvNxtFrameNode( SwNodeIndex& 
rFrameIdx,
                         || !pLayout->HasMergedParas()
                         || pFrameNd->GetRedlineMergeFlag() != 
SwNode::Merge::Hidden)
                     {
-                        rFrameIdx = *pFrameNd;
                         return pFrameNd;
                     }
                     else
@@ -2315,7 +2306,7 @@ SwNode* SwNodes::FindPrvNxtFrameNode( SwNodeIndex& 
rFrameIdx,
                     pFrameNd = GoNextSection( &aIdx, true, false );
                     // NEVER leave the section when doing this!
                     if (pFrameNd
-                        && !(::CheckNodesRange(aIdx.GetNode(), 
rFrameIdx.GetNode(), true)
+                        && !(::CheckNodesRange(aIdx.GetNode(), rFrameNd, true)
                              && (pFrameNd->FindTableNode() == pTableNd &&
                                 // NEVER go out of the table cell at the end
                                 (!pFrameNd->FindTableNode() || 
pFrameNd->FindTableBoxStartNode()
@@ -2352,7 +2343,6 @@ SwNode* SwNodes::FindPrvNxtFrameNode( SwNodeIndex& 
rFrameIdx,
                         }
                         if( aIdx.GetNode().IsTableNode() )
                         {
-                            rFrameIdx = aIdx;
                             pFrameNd = &aIdx.GetNode();
                             assert(!"this isn't dead code?");
                         }
diff --git a/sw/source/core/layout/frmtool.cxx 
b/sw/source/core/layout/frmtool.cxx
index 5052badaffa5..4c535d18c9b8 100644
--- a/sw/source/core/layout/frmtool.cxx
+++ b/sw/source/core/layout/frmtool.cxx
@@ -2014,15 +2014,14 @@ void MakeFrames( SwDoc *pDoc, SwNode &rSttIdx, SwNode 
&rEndIdx )
 {
     bObjsDirect = false;
 
-    SwNodeIndex aTmp( rSttIdx );
     SwNodeOffset nEndIdx = rEndIdx.GetIndex();
     // TODO for multiple layouts there should be a loop here
-    SwNode* pNd = pDoc->GetNodes().FindPrvNxtFrameNode( aTmp,
+    SwNode* pNd = pDoc->GetNodes().FindPrvNxtFrameNode( rSttIdx,
                     pDoc->GetNodes()[ nEndIdx-1 ],
                     pDoc->getIDocumentLayoutAccess().GetCurrentLayout());
     if ( pNd )
     {
-        bool bApres = aTmp < rSttIdx;
+        bool bApres = *pNd < rSttIdx;
         SwNode2Layout aNode2Layout( *pNd, rSttIdx.GetIndex() );
         SwFrame* pFrame;
         sw::FrameMode eMode = sw::FrameMode::Existing;
diff --git a/sw/source/core/txtnode/ndtxt.cxx b/sw/source/core/txtnode/ndtxt.cxx
index a1dd438f4562..ecaecb08f30f 100644
--- a/sw/source/core/txtnode/ndtxt.cxx
+++ b/sw/source/core/txtnode/ndtxt.cxx
@@ -134,8 +134,7 @@ SwTextNode *SwNodes::MakeTextNode( SwNode& rWhere,
             if( static_cast<SwSectionNode*>(pNd)->GetSection().IsHidden() ||
                 static_cast<SwSectionNode*>(pNd)->IsContentHidden() )
             {
-                SwNodeIndex aTmpIdx( *pNode );
-                pNd = FindPrvNxtFrameNode( aTmpIdx, pNode );
+                pNd = FindPrvNxtFrameNode( *pNode, pNode );
                 if( !pNd )
                     return pNode;
                 aTmp = *pNd;

Reply via email to