summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2022-08-05 11:34:03 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2022-08-05 13:48:49 +0200
commit063d7fda7e3942706ca8818abe7f2758a7991b92 (patch)
tree8c69fc910b5e5e9592371b36f14e97fa86dd3f8e
parent8a4271e168f70f9147b567189c1770a243e7fcb1 (diff)
introduce GoNextSection(SwPosition... and similar
as part of the process of hiding the internals of SwPosition No functional change intended Change-Id: Ia34d7f19685308ff2b9bddcfc40f9d13df348b16 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137849 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r--sw/inc/ndarr.hxx4
-rw-r--r--sw/source/core/crsr/crstrvl.cxx3
-rw-r--r--sw/source/core/crsr/pam.cxx7
-rw-r--r--sw/source/core/crsr/swcrsr.cxx8
-rw-r--r--sw/source/core/crsr/trvlfnfl.cxx3
-rw-r--r--sw/source/core/docnode/nodes.cxx121
-rw-r--r--sw/source/core/unocore/unoobj.cxx8
7 files changed, 137 insertions, 17 deletions
diff --git a/sw/inc/ndarr.hxx b/sw/inc/ndarr.hxx
index 0bf1f69f63fd..683cfde170bf 100644
--- a/sw/inc/ndarr.hxx
+++ b/sw/inc/ndarr.hxx
@@ -191,8 +191,12 @@ public:
(Both set FALSE ==> GoNext/GoPrevious!!!). */
SwContentNode* GoNextSection( SwNodeIndex *, bool bSkipHidden = true,
bool bSkipProtect = true ) const;
+ SwContentNode* GoNextSection( SwPosition *, bool bSkipHidden = true,
+ bool bSkipProtect = true ) const;
static SwContentNode* GoPrevSection( SwNodeIndex *, bool bSkipHidden = true,
bool bSkipProtect = true );
+ static SwContentNode* GoPrevSection( SwPosition *, bool bSkipHidden = true,
+ bool bSkipProtect = true );
/** Create an empty section of Start- and EndNote. It may be called
only if a new section with content is to be created,
diff --git a/sw/source/core/crsr/crstrvl.cxx b/sw/source/core/crsr/crstrvl.cxx
index 498e99795eb7..089314a4b302 100644
--- a/sw/source/core/crsr/crstrvl.cxx
+++ b/sw/source/core/crsr/crstrvl.cxx
@@ -1557,12 +1557,11 @@ bool SwCursorShell::GetContentAtPos( const Point& rPt,
SwCursorSaveState aSaveState( *m_pCurrentCursor );
m_pCurrentCursor->GetPoint()->nNode = *static_cast<SwTextFootnote*>(pTextAttr)->GetStartNode();
SwContentNode* pCNd = GetDoc()->GetNodes().GoNextSection(
- &m_pCurrentCursor->GetPoint()->nNode,
+ m_pCurrentCursor->GetPoint(),
true, !IsReadOnlyAvailable() );
if( pCNd )
{
- m_pCurrentCursor->GetPoint()->nContent.Assign( pCNd, 0 );
if( m_pCurrentCursor->IsSelOvr( SwCursorSelOverFlags::CheckNodeSection |
SwCursorSelOverFlags::Toggle ))
bRet = false;
diff --git a/sw/source/core/crsr/pam.cxx b/sw/source/core/crsr/pam.cxx
index 589d1427d701..3fd8e5ffa072 100644
--- a/sw/source/core/crsr/pam.cxx
+++ b/sw/source/core/crsr/pam.cxx
@@ -988,11 +988,12 @@ SwContentNode* GetNode( SwPaM & rPam, bool& rbFirst, SwMoveFnCollection const &
}
pNd = bSrchForward
- ? rNodes.GoNextSection( &aPos.nNode, true, !bInReadOnly )
- : SwNodes::GoPrevSection( &aPos.nNode, true, !bInReadOnly );
+ ? rNodes.GoNextSection( &aPos, true, !bInReadOnly )
+ : SwNodes::GoPrevSection( &aPos, true, !bInReadOnly );
if( pNd )
{
- aPos.nContent.Assign( pNd, ::GetSttOrEnd( bSrchForward,*pNd ));
+ if (!bSrchForward)
+ aPos.AssignEndIndex( *pNd );
// is the position still in the area
if( (aPos.*fnMove.fnCmpOp)( *rPam.GetMark() ) )
{
diff --git a/sw/source/core/crsr/swcrsr.cxx b/sw/source/core/crsr/swcrsr.cxx
index a0004bf47650..9a9361b3957b 100644
--- a/sw/source/core/crsr/swcrsr.cxx
+++ b/sw/source/core/crsr/swcrsr.cxx
@@ -2501,12 +2501,12 @@ SwCursor* SwTableCursor::MakeBoxSels( SwCursor* pCurrentCursor )
pNew->SetMark();
SwPosition* pPos = pNew->GetPoint();
- pPos->nNode.Assign( *pSttNd->EndOfSectionNode(), - 1 );
+ pPos->Assign( *pSttNd->EndOfSectionNode(), - 1 );
pNd = &pPos->GetNode();
if( !pNd->IsContentNode() )
- pNd = SwNodes::GoPrevSection( &pPos->nNode, true, false );
-
- pPos->nContent.Assign(static_cast<SwContentNode*>(pNd), pNd ? static_cast<SwContentNode*>(pNd)->Len() : 0);
+ pNd = SwNodes::GoPrevSection( pPos, true, false );
+ if (pNd)
+ pPos->AssignEndIndex(*static_cast<SwContentNode*>(pNd));
}
}
return pCurrentCursor;
diff --git a/sw/source/core/crsr/trvlfnfl.cxx b/sw/source/core/crsr/trvlfnfl.cxx
index 62f0abe444ab..714750477d14 100644
--- a/sw/source/core/crsr/trvlfnfl.cxx
+++ b/sw/source/core/crsr/trvlfnfl.cxx
@@ -75,11 +75,10 @@ bool SwCursor::GotoFootnoteText()
GetPoint()->nNode = *static_cast<SwTextFootnote*>(pFootnote)->GetStartNode();
SwContentNode* pCNd = GetDoc().GetNodes().GoNextSection(
- &GetPoint()->nNode,
+ GetPoint(),
true, !IsReadOnlyAvailable() );
if( pCNd )
{
- GetPoint()->nContent.Assign( pCNd, 0 );
bRet = !IsSelOvr( SwCursorSelOverFlags::CheckNodeSection |
SwCursorSelOverFlags::Toggle );
}
diff --git a/sw/source/core/docnode/nodes.cxx b/sw/source/core/docnode/nodes.cxx
index 474aa2fd12c0..114ceca86524 100644
--- a/sw/source/core/docnode/nodes.cxx
+++ b/sw/source/core/docnode/nodes.cxx
@@ -1998,6 +1998,70 @@ SwContentNode* SwNodes::GoNextSection( SwNodeIndex * pIdx,
return nullptr;
}
+//TODO: provide better documentation
+/** go to next section that is not protected nor hidden
+ *
+ * @note if !bSkipHidden and !bSkipProtect, use GoNext/GoPrevious
+ *
+ * @param pIdx
+ * @param bSkipHidden
+ * @param bSkipProtect
+ * @return
+ * @see SwNodes::GoNext
+ * @see SwNodes::GoPrevious
+ * @see SwNodes::GoNextSection (TODO: seems to be C&P programming here)
+*/
+SwContentNode* SwNodes::GoNextSection( SwPosition * pIdx,
+ bool bSkipHidden, bool bSkipProtect ) const
+{
+ bool bFirst = true;
+ SwNodeIndex aTmp( pIdx->GetNode() );
+ const SwNode* pNd;
+ while( aTmp < Count() - 1 )
+ {
+ pNd = & aTmp.GetNode();
+ if (SwNodeType::Section == pNd->GetNodeType())
+ {
+ const SwSection& rSect = static_cast<const SwSectionNode*>(pNd)->GetSection();
+ if( (bSkipHidden && rSect.IsHiddenFlag()) ||
+ (bSkipProtect && rSect.IsProtectFlag()) )
+ // than skip the section
+ aTmp = *pNd->EndOfSectionNode();
+ }
+ else if( bFirst )
+ {
+ if( pNd->m_pStartOfSection->IsSectionNode() )
+ {
+ const SwSection& rSect = static_cast<SwSectionNode*>(pNd->
+ m_pStartOfSection)->GetSection();
+ if( (bSkipHidden && rSect.IsHiddenFlag()) ||
+ (bSkipProtect && rSect.IsProtectFlag()) )
+ // than skip the section
+ aTmp = *pNd->EndOfSectionNode();
+ }
+ }
+ else if( SwNodeType::ContentMask & pNd->GetNodeType() )
+ {
+ const SwSectionNode* pSectNd;
+ if( ( bSkipHidden || bSkipProtect ) &&
+ nullptr != (pSectNd = pNd->FindSectionNode() ) &&
+ ( ( bSkipHidden && pSectNd->GetSection().IsHiddenFlag() ) ||
+ ( bSkipProtect && pSectNd->GetSection().IsProtectFlag() )) )
+ {
+ aTmp = *pSectNd->EndOfSectionNode();
+ }
+ else
+ {
+ pIdx->Assign(aTmp);
+ return const_cast<SwContentNode*>(static_cast<const SwContentNode*>(pNd));
+ }
+ }
+ ++aTmp;
+ bFirst = false;
+ }
+ return nullptr;
+}
+
///@see SwNodes::GoNextSection (TODO: seems to be C&P programming here)
SwContentNode* SwNodes::GoPrevSection( SwNodeIndex * pIdx,
bool bSkipHidden, bool bSkipProtect )
@@ -2055,6 +2119,63 @@ SwContentNode* SwNodes::GoPrevSection( SwNodeIndex * pIdx,
return nullptr;
}
+///@see SwNodes::GoNextSection (TODO: seems to be C&P programming here)
+SwContentNode* SwNodes::GoPrevSection( SwPosition * pIdx,
+ bool bSkipHidden, bool bSkipProtect )
+{
+ bool bFirst = true;
+ SwNodeIndex aTmp( pIdx->GetNode() );
+ const SwNode* pNd;
+ while( aTmp > SwNodeOffset(0) )
+ {
+ pNd = & aTmp.GetNode();
+ if (SwNodeType::End == pNd->GetNodeType())
+ {
+ if( pNd->m_pStartOfSection->IsSectionNode() )
+ {
+ const SwSection& rSect = static_cast<SwSectionNode*>(pNd->
+ m_pStartOfSection)->GetSection();
+ if( (bSkipHidden && rSect.IsHiddenFlag()) ||
+ (bSkipProtect && rSect.IsProtectFlag()) )
+ // than skip section
+ aTmp = *pNd->StartOfSectionNode();
+ }
+ bFirst = false;
+ }
+ else if( bFirst )
+ {
+ bFirst = false;
+ if( pNd->m_pStartOfSection->IsSectionNode() )
+ {
+ const SwSection& rSect = static_cast<SwSectionNode*>(pNd->
+ m_pStartOfSection)->GetSection();
+ if( (bSkipHidden && rSect.IsHiddenFlag()) ||
+ (bSkipProtect && rSect.IsProtectFlag()) )
+ // than skip section
+ aTmp = *pNd->StartOfSectionNode();
+ }
+ }
+ else if( SwNodeType::ContentMask & pNd->GetNodeType() )
+ {
+ const SwSectionNode* pSectNd;
+ if( ( bSkipHidden || bSkipProtect ) &&
+ nullptr != (pSectNd = pNd->FindSectionNode() ) &&
+ ( ( bSkipHidden && pSectNd->GetSection().IsHiddenFlag() ) ||
+ ( bSkipProtect && pSectNd->GetSection().IsProtectFlag() )) )
+ {
+ aTmp = *pSectNd;
+ }
+ else
+ {
+ pIdx->Assign(aTmp);
+ return const_cast<SwContentNode*>(static_cast<const SwContentNode*>(pNd));
+ }
+ }
+ --aTmp;
+ }
+ return nullptr;
+}
+
//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.
diff --git a/sw/source/core/unocore/unoobj.cxx b/sw/source/core/unocore/unoobj.cxx
index 3f0d1708984e..34b594a0d1d7 100644
--- a/sw/source/core/unocore/unoobj.cxx
+++ b/sw/source/core/unocore/unoobj.cxx
@@ -1004,12 +1004,8 @@ SwXTextCursor::gotoStart(sal_Bool Expand)
static_cast<SwSectionNode const*>(pTmp);
if (pSectionStartNode->GetSection().IsHiddenFlag())
{
- SwContentNode* pCNode = GetDoc()->GetNodes().GoNextSection(
- &rUnoCursor.GetPoint()->nNode, true, false);
- if (pCNode)
- {
- rUnoCursor.GetPoint()->nContent.Assign(pCNode, 0);
- }
+ GetDoc()->GetNodes().GoNextSection(
+ rUnoCursor.GetPoint(), true, false);
}
}
}