1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
24 #include <fmtcntnt.hxx>
28 #include <section.hxx>
29 #include <svx/srchdlg.hxx>
31 bool GotoPrevRegion( SwPaM
& rCurrentCursor
, SwMoveFnCollection
const & fnPosRegion
,
34 SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::Empty
);
35 SwNodeIndex
aIdx( rCurrentCursor
.GetPoint()->GetNode() );
36 SwSectionNode
* pNd
= aIdx
.GetNode().FindSectionNode();
38 aIdx
.Assign( *pNd
, -1 );
40 SwNodeIndex aOldIdx
= aIdx
;
41 SwNodeOffset
nLastNd(rCurrentCursor
.GetDoc().GetNodes().Count() - 1);
43 while( aIdx
.GetIndex() )
45 pNd
= aIdx
.GetNode().StartOfSectionNode()->GetSectionNode();
49 if ( aIdx
== aOldIdx
)
51 SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::NavElementNotFound
);
56 if ( !aIdx
.GetIndex() )
58 SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::StartWrapped
);
63 assert( pNd
); // coverity, should never be nullptr
65 if( pNd
->GetSection().IsHiddenFlag() ||
67 pNd
->GetSection().IsProtectFlag() ))
69 // skip protected or hidden ones
70 aIdx
.Assign( *pNd
, - 1 );
73 else if( &fnPosRegion
== &fnMoveForward
)
76 SwContentNode
* pCNd
= pNd
->GetNodes().GoNextSection( &aIdx
,
83 rCurrentCursor
.GetPoint()->SetContent( 0 );
87 aIdx
= *pNd
->EndOfSectionNode();
88 SwContentNode
* pCNd
= SwNodes::GoPrevSection( &aIdx
,
92 aIdx
.Assign( *pNd
, - 1 );
95 rCurrentCursor
.GetPoint()->SetContent( pCNd
->Len() );
97 rCurrentCursor
.GetPoint()->Assign( aIdx
);
102 // the flow is such that it is not possible to get here
106 bool GotoNextRegion( SwPaM
& rCurrentCursor
, SwMoveFnCollection
const & fnPosRegion
,
109 SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::Empty
);
110 SwNodeIndex
aIdx( rCurrentCursor
.GetPoint()->GetNode() );
111 SwSectionNode
* pNd
= aIdx
.GetNode().FindSectionNode();
113 aIdx
.Assign( *pNd
->EndOfSectionNode(), - 1 );
115 SwNodeIndex aOldIdx
= aIdx
;
116 SwNodeOffset nEndCount
= aIdx
.GetNode().GetNodes().Count() - 1;
118 while( aIdx
.GetIndex() < nEndCount
)
120 pNd
= aIdx
.GetNode().GetSectionNode();
124 if ( aIdx
== aOldIdx
)
126 SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::NavElementNotFound
);
131 if ( aIdx
.GetIndex() == nEndCount
)
133 SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::EndWrapped
);
134 aIdx
= SwNodeOffset(0);
138 assert( pNd
); // coverity, should never be nullptr
140 if( pNd
->GetSection().IsHiddenFlag() ||
142 pNd
->GetSection().IsProtectFlag() ))
144 // skip protected or hidden ones
145 aIdx
.Assign( *pNd
->EndOfSectionNode(), +1 );
148 else if( &fnPosRegion
== &fnMoveForward
)
151 SwContentNode
* pCNd
= pNd
->GetNodes().GoNextSection( &aIdx
,
152 true, !bInReadOnly
);
155 aIdx
.Assign( *pNd
->EndOfSectionNode(), +1 );
158 rCurrentCursor
.GetPoint()->SetContent( 0 );
162 aIdx
= *pNd
->EndOfSectionNode();
163 SwContentNode
* pCNd
= SwNodes::GoPrevSection( &aIdx
,
164 true, !bInReadOnly
);
170 rCurrentCursor
.GetPoint()->SetContent( pCNd
->Len() );
172 rCurrentCursor
.GetPoint()->Assign( aIdx
);
177 // the flow is such that it is not possible to get here
181 bool GotoCurrRegionAndSkip( SwPaM
& rCurrentCursor
, SwMoveFnCollection
const & fnPosRegion
,
184 SwNode
& rCurrNd
= rCurrentCursor
.GetPointNode();
185 SwSectionNode
* pNd
= rCurrNd
.FindSectionNode();
189 SwPosition
* pPos
= rCurrentCursor
.GetPoint();
190 const sal_Int32 nCurrCnt
= pPos
->GetContentIndex();
191 bool bMoveBackward
= &fnPosRegion
== &fnMoveBackward
;
195 if( bMoveBackward
) // to the end of the section
197 SwNodeIndex
aIdx( *pNd
->EndOfSectionNode() );
198 pCNd
= SwNodes::GoPrevSection( &aIdx
, true, !bInReadOnly
);
201 pPos
->Assign( aIdx
);
205 SwNodeIndex
aIdx( *pNd
);
206 pCNd
= pNd
->GetNodes().GoNextSection( &aIdx
, true, !bInReadOnly
);
209 pPos
->Assign( aIdx
);
212 pPos
->SetContent( bMoveBackward
? pCNd
->Len() : 0 );
214 if( &pPos
->GetNode() != &rCurrNd
||
215 pPos
->GetContentIndex() != nCurrCnt
)
216 // there was a change
219 // try also the parent of this section
220 SwSection
* pParent
= pNd
->GetSection().GetParent();
221 pNd
= pParent
? pParent
->GetFormat()->GetSectionNode() : nullptr;
226 bool SwCursor::MoveRegion( SwWhichRegion fnWhichRegion
, SwMoveFnCollection
const & fnPosRegion
)
228 SwCursorSaveState
aSaveState( *this );
229 return !dynamic_cast<SwTableCursor
*>(this) &&
230 (*fnWhichRegion
)( *this, fnPosRegion
, IsReadOnlyAvailable() ) &&
232 (GetPoint()->GetNodeIndex() != m_vSavePos
.back().nNode
||
233 GetPoint()->GetContentIndex() != m_vSavePos
.back().nContent
);
236 bool SwCursorShell::MoveRegion( SwWhichRegion fnWhichRegion
, SwMoveFnCollection
const & fnPosRegion
)
238 SwCallLink
aLk( *this ); // watch Cursor-Moves;call Link if needed
239 bool bRet
= !m_pTableCursor
&& m_pCurrentCursor
->MoveRegion( fnWhichRegion
, fnPosRegion
);
245 bool SwCursor::GotoRegion( std::u16string_view rName
)
248 const SwSectionFormats
& rFormats
= GetDoc().GetSections();
249 for( SwSectionFormats::size_type n
= rFormats
.size(); n
; )
251 const SwSectionFormat
* pFormat
= rFormats
[ --n
];
252 const SwSection
* pSect
= pFormat
->GetSection();
253 if( pSect
&& pSect
->GetSectionName() == rName
)
255 const SwNodeIndex
* pIdx
= pFormat
->GetContent().GetContentIdx();
256 if( pIdx
&& pIdx
->GetNode().GetNodes().IsDocNodes() )
258 // area in normal nodes array
259 SwCursorSaveState
aSaveState( *this );
261 GetPoint()->Assign( *pIdx
);
262 Move( fnMoveForward
, GoInContent
);
270 bool SwCursorShell::GotoRegion( std::u16string_view rName
)
272 SwCallLink
aLk( *this ); // watch Cursor-Moves;call Link if needed
273 bool bRet
= !m_pTableCursor
&& m_pCurrentCursor
->GotoRegion( rName
);
275 UpdateCursor( SwCursorShell::SCROLLWIN
| SwCursorShell::CHKRANGE
|
276 SwCursorShell::READONLY
);
280 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */