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
= SwNodes::GoNextSection(&aIdx
, true, !bInReadOnly
);
82 rCurrentCursor
.GetPoint()->SetContent( 0 );
86 aIdx
= *pNd
->EndOfSectionNode();
87 SwContentNode
* pCNd
= SwNodes::GoPrevSection( &aIdx
,
91 aIdx
.Assign( *pNd
, - 1 );
94 rCurrentCursor
.GetPoint()->SetContent( pCNd
->Len() );
96 rCurrentCursor
.GetPoint()->Assign( aIdx
);
101 // the flow is such that it is not possible to get here
105 bool GotoNextRegion( SwPaM
& rCurrentCursor
, SwMoveFnCollection
const & fnPosRegion
,
108 SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::Empty
);
109 SwNodeIndex
aIdx( rCurrentCursor
.GetPoint()->GetNode() );
110 SwSectionNode
* pNd
= aIdx
.GetNode().FindSectionNode();
112 aIdx
.Assign( *pNd
->EndOfSectionNode(), - 1 );
114 SwNodeIndex aOldIdx
= aIdx
;
115 SwNodeOffset nEndCount
= aIdx
.GetNode().GetNodes().Count() - 1;
117 while( aIdx
.GetIndex() < nEndCount
)
119 pNd
= aIdx
.GetNode().GetSectionNode();
123 if ( aIdx
== aOldIdx
)
125 SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::NavElementNotFound
);
130 if ( aIdx
.GetIndex() == nEndCount
)
132 SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::EndWrapped
);
133 aIdx
= SwNodeOffset(0);
137 assert( pNd
); // coverity, should never be nullptr
139 if( pNd
->GetSection().IsHiddenFlag() ||
141 pNd
->GetSection().IsProtectFlag() ))
143 // skip protected or hidden ones
144 aIdx
.Assign( *pNd
->EndOfSectionNode(), +1 );
147 else if( &fnPosRegion
== &fnMoveForward
)
150 SwContentNode
* pCNd
= SwNodes::GoNextSection(&aIdx
, true, !bInReadOnly
);
153 aIdx
.Assign( *pNd
->EndOfSectionNode(), +1 );
156 rCurrentCursor
.GetPoint()->SetContent( 0 );
160 aIdx
= *pNd
->EndOfSectionNode();
161 SwContentNode
* pCNd
= SwNodes::GoPrevSection( &aIdx
,
162 true, !bInReadOnly
);
168 rCurrentCursor
.GetPoint()->SetContent( pCNd
->Len() );
170 rCurrentCursor
.GetPoint()->Assign( aIdx
);
175 // the flow is such that it is not possible to get here
179 bool GotoCurrRegionAndSkip( SwPaM
& rCurrentCursor
, SwMoveFnCollection
const & fnPosRegion
,
182 SwNode
& rCurrNd
= rCurrentCursor
.GetPointNode();
183 SwSectionNode
* pNd
= rCurrNd
.FindSectionNode();
187 SwPosition
* pPos
= rCurrentCursor
.GetPoint();
188 const sal_Int32 nCurrCnt
= pPos
->GetContentIndex();
189 bool bMoveBackward
= &fnPosRegion
== &fnMoveBackward
;
193 if( bMoveBackward
) // to the end of the section
195 SwNodeIndex
aIdx( *pNd
->EndOfSectionNode() );
196 pCNd
= SwNodes::GoPrevSection( &aIdx
, true, !bInReadOnly
);
199 pPos
->Assign( aIdx
);
203 SwNodeIndex
aIdx( *pNd
);
204 pCNd
= SwNodes::GoNextSection(&aIdx
, true, !bInReadOnly
);
207 pPos
->Assign( aIdx
);
210 pPos
->SetContent( bMoveBackward
? pCNd
->Len() : 0 );
212 if( &pPos
->GetNode() != &rCurrNd
||
213 pPos
->GetContentIndex() != nCurrCnt
)
214 // there was a change
217 // try also the parent of this section
218 SwSection
* pParent
= pNd
->GetSection().GetParent();
219 pNd
= pParent
? pParent
->GetFormat()->GetSectionNode() : nullptr;
224 bool SwCursor::MoveRegion( SwWhichRegion fnWhichRegion
, SwMoveFnCollection
const & fnPosRegion
)
226 SwCursorSaveState
aSaveState( *this );
227 return !dynamic_cast<SwTableCursor
*>(this) &&
228 (*fnWhichRegion
)( *this, fnPosRegion
, IsReadOnlyAvailable() ) &&
230 (GetPoint()->GetNodeIndex() != m_vSavePos
.back().nNode
||
231 GetPoint()->GetContentIndex() != m_vSavePos
.back().nContent
);
234 bool SwCursorShell::MoveRegion( SwWhichRegion fnWhichRegion
, SwMoveFnCollection
const & fnPosRegion
)
236 SwCallLink
aLk( *this ); // watch Cursor-Moves;call Link if needed
237 bool bRet
= !m_pTableCursor
&& m_pCurrentCursor
->MoveRegion( fnWhichRegion
, fnPosRegion
);
243 bool SwCursor::GotoRegion( std::u16string_view rName
)
246 const SwSectionFormats
& rFormats
= GetDoc().GetSections();
247 for( SwSectionFormats::size_type n
= rFormats
.size(); n
; )
249 const SwSectionFormat
* pFormat
= rFormats
[ --n
];
250 const SwSection
* pSect
= pFormat
->GetSection();
251 if( pSect
&& pSect
->GetSectionName() == rName
)
253 const SwNodeIndex
* pIdx
= pFormat
->GetContent().GetContentIdx();
254 if( pIdx
&& pIdx
->GetNode().GetNodes().IsDocNodes() )
256 // area in normal nodes array
257 SwCursorSaveState
aSaveState( *this );
259 GetPoint()->Assign( *pIdx
);
260 Move( fnMoveForward
, GoInContent
);
268 bool SwCursorShell::GotoRegion( std::u16string_view rName
)
270 SwCallLink
aLk( *this ); // watch Cursor-Moves;call Link if needed
271 bool bRet
= !m_pTableCursor
&& m_pCurrentCursor
->GotoRegion( rName
);
273 UpdateCursor( SwCursorShell::SCROLLWIN
| SwCursorShell::CHKRANGE
|
274 SwCursorShell::READONLY
);
278 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */