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:1256
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:1876
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:192
@ READONLY
make visible in spite of Readonly
Definition: crsrsh.hxx:166
@ CHKRANGE
check overlapping PaMs
Definition: crsrsh.hxx:165
@ SCROLLWIN
scroll window
Definition: crsrsh.hxx:164
bool GotoRegion(std::u16string_view rName)
Definition: trvlreg.cxx:270
SwShellCursor * m_pCurrentCursor
current cursor
Definition: crsrsh.hxx:186
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:1356
SwNodes & GetNodes()
Definition: doc.hxx:422
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
SwNode & GetNode() const
Definition: ndindex.hxx:123
SwNodeOffset GetIndex() const
Definition: ndindex.hxx:111
SwNodeIndex & Assign(SwNodes const &rNds, SwNodeOffset nIdx)
Definition: ndindex.hxx:114
Base class of the Writer document model elements.
Definition: node.hxx:98
SwSectionNode * GetSectionNode()
Definition: node.hxx:658
SwNodes & GetNodes()
Node is in which nodes-array/doc?
Definition: node.hxx:706
SwSectionNode * FindSectionNode()
Search section node, in which it is.
Definition: ndsect.cxx:968
const SwStartNode * StartOfSectionNode() const
Definition: node.hxx:153
const SwEndNode * EndOfSectionNode() const
Definition: node.hxx:695
bool IsDocNodes() const
Is the NodesArray the regular one of Doc? (and not the UndoNds, ...) Implementation in doc....
Definition: nodes.cxx:2555
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:1948
static SwContentNode * GoPrevSection(SwNodeIndex *, bool bSkipHidden=true, bool bSkipProtect=true)
Definition: nodes.cxx:2064
SwNodeOffset Count() const
Definition: ndarr.hxx:142
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:188
SwNode & GetPointNode() const
Definition: pam.hxx:275
bool Move(SwMoveFnCollection const &fnMove=fnMoveForward, SwGoInDoc fnGo=GoInContent)
Movement of cursor.
Definition: pam.cxx:657
SwDoc & GetDoc() const
Definition: pam.hxx:291
const SwPosition * GetPoint() const
Definition: pam.hxx:253
SwSection * GetSection() const
Definition: section.cxx:646
SwSectionNode * GetSectionNode()
Definition: section.cxx:923
Array of Undo-history.
Definition: docary.hxx:193
A section node represents the start of a section on the UI, i.e.
Definition: node.hxx:575
const SwSection & GetSection() const
Definition: node.hxx:590
bool IsProtectFlag() const
Definition: section.hxx:191
bool IsHiddenFlag() const
Definition: section.hxx:190
SwSection * GetParent() const
Definition: section.hxx:351
const OUString & GetSectionName() const
Definition: section.hxx:171
SwSectionFormat * GetFormat()
Definition: section.hxx:341
std::vector< SwSectionFormat * >::size_type size_type
Definition: docary.hxx:67
size_t size() const
Definition: docary.hxx:88
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:1203
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:38
SwNode & GetNode() const
Definition: pam.hxx:81
void Assign(const SwNode &rNd, SwNodeOffset nDelta, sal_Int32 nContentOffset=0)
These all set both nNode and nContent.
Definition: pam.cxx:231
void SetContent(sal_Int32 nContentIndex)
Set content index, only valid to call this if the position points to a SwContentNode subclass.
Definition: pam.cxx:267
SwNodeOffset GetNodeIndex() const
Definition: pam.hxx:78
sal_Int32 GetContentIndex() const
Definition: pam.hxx:85
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