LibreOffice Module sw (master) 1
trvlreg.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <crsrsh.hxx>
21#include <doc.hxx>
22#include <swcrsr.hxx>
23#include <docary.hxx>
24#include <fmtcntnt.hxx>
25#include <viscrs.hxx>
26#include "callnk.hxx"
27#include <pamtyp.hxx>
28#include <section.hxx>
29#include <svx/srchdlg.hxx>
30
31bool GotoPrevRegion( SwPaM& rCurrentCursor, SwMoveFnCollection const & fnPosRegion,
32 bool bInReadOnly )
33{
34 SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::Empty );
35 SwNodeIndex aIdx( rCurrentCursor.GetPoint()->GetNode() );
37 if( pNd )
38 aIdx.Assign( *pNd, -1 );
39
40 SwNodeIndex aOldIdx = aIdx;
41 SwNodeOffset nLastNd(rCurrentCursor.GetDoc().GetNodes().Count() - 1);
42 do {
43 while( aIdx.GetIndex() )
44 {
46 if (pNd)
47 break;
48 --aIdx;
49 if ( aIdx == aOldIdx )
50 {
51 SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::NavElementNotFound );
52 return false;
53 }
54 }
55
56 if ( !aIdx.GetIndex() )
57 {
58 SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::StartWrapped );
59 aIdx = nLastNd;
60 continue;
61 }
62
63 assert( pNd ); // coverity, should never be nullptr
64 {
65 if( pNd->GetSection().IsHiddenFlag() ||
66 ( !bInReadOnly &&
67 pNd->GetSection().IsProtectFlag() ))
68 {
69 // skip protected or hidden ones
70 aIdx.Assign( *pNd, - 1 );
71 continue;
72 }
73 else if( &fnPosRegion == &fnMoveForward )
74 {
75 aIdx = *pNd;
76 SwContentNode* pCNd = pNd->GetNodes().GoNextSection( &aIdx,
77 true, !bInReadOnly );
78 if( !pCNd )
79 {
80 --aIdx;
81 continue;
82 }
83 rCurrentCursor.GetPoint()->SetContent( 0 );
84 }
85 else
86 {
87 aIdx = *pNd->EndOfSectionNode();
89 true, !bInReadOnly );
90 if( !pCNd )
91 {
92 aIdx.Assign( *pNd, - 1 );
93 continue;
94 }
95 rCurrentCursor.GetPoint()->SetContent( pCNd->Len() );
96 }
97 rCurrentCursor.GetPoint()->Assign( aIdx );
98 return true;
99 }
100 } while( true );
101
102 // the flow is such that it is not possible to get here
103 return false;
104}
105
106bool GotoNextRegion( SwPaM& rCurrentCursor, SwMoveFnCollection const & fnPosRegion,
107 bool bInReadOnly )
108{
109 SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::Empty );
110 SwNodeIndex aIdx( rCurrentCursor.GetPoint()->GetNode() );
111 SwSectionNode* pNd = aIdx.GetNode().FindSectionNode();
112 if( pNd )
113 aIdx.Assign( *pNd->EndOfSectionNode(), - 1 );
114
115 SwNodeIndex aOldIdx = aIdx;
116 SwNodeOffset nEndCount = aIdx.GetNode().GetNodes().Count() - 1;
117 do {
118 while( aIdx.GetIndex() < nEndCount )
119 {
120 pNd = aIdx.GetNode().GetSectionNode();
121 if (pNd)
122 break;
123 ++aIdx;
124 if ( aIdx == aOldIdx )
125 {
126 SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::NavElementNotFound );
127 return false;
128 }
129 }
130
131 if ( aIdx.GetIndex() == nEndCount )
132 {
133 SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::EndWrapped );
134 aIdx = SwNodeOffset(0);
135 continue;
136 }
137
138 assert( pNd ); // coverity, should never be nullptr
139 {
140 if( pNd->GetSection().IsHiddenFlag() ||
141 ( !bInReadOnly &&
142 pNd->GetSection().IsProtectFlag() ))
143 {
144 // skip protected or hidden ones
145 aIdx.Assign( *pNd->EndOfSectionNode(), +1 );
146 continue;
147 }
148 else if( &fnPosRegion == &fnMoveForward )
149 {
150 aIdx = *pNd;
151 SwContentNode* pCNd = pNd->GetNodes().GoNextSection( &aIdx,
152 true, !bInReadOnly );
153 if( !pCNd )
154 {
155 aIdx.Assign( *pNd->EndOfSectionNode(), +1 );
156 continue;
157 }
158 rCurrentCursor.GetPoint()->SetContent( 0 );
159 }
160 else
161 {
162 aIdx = *pNd->EndOfSectionNode();
164 true, !bInReadOnly );
165 if( !pCNd )
166 {
167 ++aIdx;
168 continue;
169 }
170 rCurrentCursor.GetPoint()->SetContent( pCNd->Len() );
171 }
172 rCurrentCursor.GetPoint()->Assign( aIdx );
173 return true;
174 }
175 } while( true );
176
177 // the flow is such that it is not possible to get here
178 return false;
179}
180
181bool GotoCurrRegionAndSkip( SwPaM& rCurrentCursor, SwMoveFnCollection const & fnPosRegion,
182 bool bInReadOnly )
183{
184 SwNode& rCurrNd = rCurrentCursor.GetPointNode();
185 SwSectionNode* pNd = rCurrNd.FindSectionNode();
186 if( !pNd )
187 return false;
188
189 SwPosition* pPos = rCurrentCursor.GetPoint();
190 const sal_Int32 nCurrCnt = pPos->GetContentIndex();
191 bool bMoveBackward = &fnPosRegion == &fnMoveBackward;
192
193 do {
194 SwContentNode* pCNd;
195 if( bMoveBackward ) // to the end of the section
196 {
197 SwNodeIndex aIdx( *pNd->EndOfSectionNode() );
198 pCNd = SwNodes::GoPrevSection( &aIdx, true, !bInReadOnly );
199 if( !pCNd )
200 return false;
201 pPos->Assign( aIdx );
202 }
203 else
204 {
205 SwNodeIndex aIdx( *pNd );
206 pCNd = pNd->GetNodes().GoNextSection( &aIdx, true, !bInReadOnly );
207 if( !pCNd )
208 return false;
209 pPos->Assign( aIdx );
210 }
211
212 pPos->SetContent( bMoveBackward ? pCNd->Len() : 0 );
213
214 if( &pPos->GetNode() != &rCurrNd ||
215 pPos->GetContentIndex() != nCurrCnt )
216 // there was a change
217 return true;
218
219 // try also the parent of this section
220 SwSection* pParent = pNd->GetSection().GetParent();
221 pNd = pParent ? pParent->GetFormat()->GetSectionNode() : nullptr;
222 } while( pNd );
223 return false;
224}
225
226bool SwCursor::MoveRegion( SwWhichRegion fnWhichRegion, SwMoveFnCollection const & fnPosRegion )
227{
228 SwCursorSaveState aSaveState( *this );
229 return !dynamic_cast<SwTableCursor*>(this) &&
230 (*fnWhichRegion)( *this, fnPosRegion, IsReadOnlyAvailable() ) &&
231 !IsSelOvr() &&
232 (GetPoint()->GetNodeIndex() != m_vSavePos.back().nNode ||
233 GetPoint()->GetContentIndex() != m_vSavePos.back().nContent);
234}
235
236bool SwCursorShell::MoveRegion( SwWhichRegion fnWhichRegion, SwMoveFnCollection const & fnPosRegion )
237{
238 SwCallLink aLk( *this ); // watch Cursor-Moves;call Link if needed
239 bool bRet = !m_pTableCursor && m_pCurrentCursor->MoveRegion( fnWhichRegion, fnPosRegion );
240 if( bRet )
241 UpdateCursor();
242 return bRet;
243}
244
245bool SwCursor::GotoRegion( std::u16string_view rName )
246{
247 bool bRet = false;
248 const SwSectionFormats& rFormats = GetDoc().GetSections();
249 for( SwSectionFormats::size_type n = rFormats.size(); n; )
250 {
251 const SwSectionFormat* pFormat = rFormats[ --n ];
252 const SwSection* pSect = pFormat->GetSection();
253 if( pSect && pSect->GetSectionName() == rName )
254 {
255 const SwNodeIndex* pIdx = pFormat->GetContent().GetContentIdx();
256 if( pIdx && pIdx->GetNode().GetNodes().IsDocNodes() )
257 {
258 // area in normal nodes array
259 SwCursorSaveState aSaveState( *this );
260
261 GetPoint()->Assign( *pIdx );
263 bRet = !IsSelOvr();
264 }
265 }
266 }
267 return bRet;
268}
269
270bool SwCursorShell::GotoRegion( std::u16string_view rName )
271{
272 SwCallLink aLk( *this ); // watch Cursor-Moves;call Link if needed
273 bool bRet = !m_pTableCursor && m_pCurrentCursor->GotoRegion( rName );
274 if( bRet )
277 return bRet;
278}
279
280/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static void SetSearchLabel(const SearchLabel &rSL)
virtual sal_Int32 Len() const
Definition: node.cxx:1257
A helper class to save cursor state (position).
Definition: swcrsr.hxx:233
SAL_DLLPRIVATE void UpdateCursor(sal_uInt16 eFlags=SwCursorShell::SCROLLWIN|SwCursorShell::CHKRANGE, bool bIdleEnd=false)
Definition: crsrsh.cxx:1571
bool MoveRegion(SwWhichRegion, SwMoveFnCollection const &)
Definition: trvlreg.cxx:236
SwShellTableCursor * m_pTableCursor
table Cursor; only in tables when the selection lays over 2 columns
Definition: crsrsh.hxx:190
@ READONLY
make visible in spite of Readonly
Definition: crsrsh.hxx:164
@ CHKRANGE
check overlapping PaMs
Definition: crsrsh.hxx:163
@ SCROLLWIN
scroll window
Definition: crsrsh.hxx:162
bool GotoRegion(std::u16string_view rName)
Definition: trvlreg.cxx:270
SwShellCursor * m_pCurrentCursor
current cursor
Definition: crsrsh.hxx:184
std::vector< SwCursor_SavePos > m_vSavePos
Definition: swcrsr.hxx:74
bool MoveRegion(SwWhichRegion, SwMoveFnCollection const &)
Definition: trvlreg.cxx:226
bool GotoRegion(std::u16string_view rName)
Definition: trvlreg.cxx:245
virtual bool IsSelOvr(SwCursorSelOverFlags eFlags=SwCursorSelOverFlags::CheckNodeSection|SwCursorSelOverFlags::Toggle|SwCursorSelOverFlags::ChangePos)
Definition: swcrsr.cxx:222
virtual bool IsReadOnlyAvailable() const
Definition: swcrsr.cxx:150
SwSectionFormats & GetSections()
Definition: doc.hxx:1341
SwNodes & GetNodes()
Definition: doc.hxx:413
const SwNodeIndex * GetContentIdx() const
Definition: fmtcntnt.hxx:46
const SwFormatContent & GetContent(bool=true) const
Definition: fmtcntnt.hxx:55
Marks a node in the document model.
Definition: ndindex.hxx:31
SwNodeIndex & Assign(SwNodes const &rNds, SwNodeOffset)
Definition: ndindex.hxx:291
SwNode & GetNode() const
Definition: ndindex.hxx:136
SwNodeOffset GetIndex() const
Definition: ndindex.hxx:171
Base class of the Writer document model elements.
Definition: node.hxx:84
SwSectionNode * GetSectionNode()
Definition: node.hxx:636
SwNodes & GetNodes()
Node is in which nodes-array/doc?
Definition: node.hxx:722
SwSectionNode * FindSectionNode()
Search section node, in which it is.
Definition: ndsect.cxx:981
const SwStartNode * StartOfSectionNode() const
Definition: node.hxx:137
const SwEndNode * EndOfSectionNode() const
Definition: node.hxx:711
bool IsDocNodes() const
Is the NodesArray the regular one of Doc? (and not the UndoNds, ...) Implementation in doc....
Definition: nodes.cxx:2531
SwContentNode * GoNextSection(SwNodeIndex *, bool bSkipHidden=true, bool bSkipProtect=true) const
Go to next content-node that is not protected or hidden (Both set FALSE ==> GoNext/GoPrevious!...
Definition: nodes.cxx:1952
static SwContentNode * GoPrevSection(SwNodeIndex *, bool bSkipHidden=true, bool bSkipProtect=true)
Definition: nodes.cxx:2068
SwNodeOffset Count() const
Definition: ndarr.hxx:142
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:187
SwNode & GetPointNode() const
Definition: pam.hxx:283
bool Move(SwMoveFnCollection const &fnMove=fnMoveForward, SwGoInDoc fnGo=GoInContent)
Movement of cursor.
Definition: pam.cxx:668
SwDoc & GetDoc() const
Definition: pam.hxx:299
const SwPosition * GetPoint() const
Definition: pam.hxx:261
SwSection * GetSection() const
Definition: section.cxx:638
SwSectionNode * GetSectionNode()
Definition: section.cxx:923
Array of Undo-history.
Definition: docary.hxx:192
const SwSection & GetSection() const
Definition: node.hxx:568
bool IsProtectFlag() const
Definition: section.hxx:189
bool IsHiddenFlag() const
Definition: section.hxx:188
SwSection * GetParent() const
Definition: section.hxx:347
const OUString & GetSectionName() const
Definition: section.hxx:169
SwSectionFormat * GetFormat()
Definition: section.hxx:337
std::vector< SwSectionFormat * >::size_type size_type
Definition: docary.hxx:66
size_t size() const
Definition: docary.hxx:87
bool(* SwWhichRegion)(SwPaM &, SwMoveFnCollection const &, bool bInReadOnly)
Definition: cshtyp.hxx:75
sal_Int64 n
o3tl::strong_int< sal_Int32, struct Tag_SwNodeOffset > SwNodeOffset
Definition: nodeoffset.hxx:16
bool GoInContent(SwPaM &rPam, SwMoveFnCollection const &fnMove)
Definition: pam.cxx:1172
SwMoveFnCollection const & fnMoveBackward
Definition: paminit.cxx:60
SwMoveFnCollection const & fnMoveForward
SwPam::Move()/Find() default argument.
Definition: paminit.cxx:61
Marks a position in the document model.
Definition: pam.hxx:37
SwNode & GetNode() const
Definition: pam.hxx:80
void Assign(const SwNode &rNd, SwNodeOffset nDelta, sal_Int32 nContentOffset=0)
These all set both nNode and nContent.
Definition: pam.cxx:230
void SetContent(sal_Int32 nContentIndex)
Set content index, only valid to call this if the position points to a SwContentNode subclass.
Definition: pam.cxx:266
SwNodeOffset GetNodeIndex() const
Definition: pam.hxx:77
sal_Int32 GetContentIndex() const
Definition: pam.hxx:84
bool GotoCurrRegionAndSkip(SwPaM &rCurrentCursor, SwMoveFnCollection const &fnPosRegion, bool bInReadOnly)
Definition: trvlreg.cxx:181
bool GotoNextRegion(SwPaM &rCurrentCursor, SwMoveFnCollection const &fnPosRegion, bool bInReadOnly)
Definition: trvlreg.cxx:106
bool GotoPrevRegion(SwPaM &rCurrentCursor, SwMoveFnCollection const &fnPosRegion, bool bInReadOnly)
Definition: trvlreg.cxx:31