xref: /trunk/main/sw/source/core/crsr/trvlreg.cxx (revision efeef26f)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26 
27 
28 #include <crsrsh.hxx>
29 #include <doc.hxx>
30 #include <swcrsr.hxx>
31 #include <docary.hxx>
32 #include <fmtcntnt.hxx>
33 #include <viscrs.hxx>
34 #include <callnk.hxx>
35 #include <pamtyp.hxx>
36 #include <section.hxx>
37 
38 
39 
GotoPrevRegion(SwPaM & rCurCrsr,SwPosRegion fnPosRegion,sal_Bool bInReadOnly)40 sal_Bool GotoPrevRegion( SwPaM& rCurCrsr, SwPosRegion fnPosRegion,
41 						sal_Bool bInReadOnly )
42 {
43 	SwNodeIndex aIdx( rCurCrsr.GetPoint()->nNode );
44 	SwSectionNode* pNd = aIdx.GetNode().FindSectionNode();
45 	if( pNd )
46 		aIdx.Assign( *pNd, - 1 );
47 
48 	do {
49 		while( aIdx.GetIndex() &&
50             0 == ( pNd = aIdx.GetNode().StartOfSectionNode()->GetSectionNode()) )
51 			aIdx--;
52 
53 		if( pNd )		// gibt einen weiteren SectionNode ?
54 		{
55 			if( pNd->GetSection().IsHiddenFlag() ||
56 				( !bInReadOnly &&
57 				  pNd->GetSection().IsProtectFlag() ))
58 			{
59 				// geschuetzte/versteckte ueberspringen wir
60 				aIdx.Assign( *pNd, - 1 );
61 			}
62 			else if( fnPosRegion == fnMoveForward )
63 			{
64 				aIdx = *pNd;
65 				SwCntntNode* pCNd = pNd->GetNodes().GoNextSection( &aIdx,
66 												sal_True, !bInReadOnly );
67 				if( !pCNd )
68 				{
69 					aIdx--;
70 					continue;
71 				}
72 				rCurCrsr.GetPoint()->nContent.Assign( pCNd, 0 );
73 			}
74 			else
75 			{
76 				aIdx = *pNd->EndOfSectionNode();
77 				SwCntntNode* pCNd = pNd->GetNodes().GoPrevSection( &aIdx,
78 												sal_True, !bInReadOnly );
79 				if( !pCNd )
80 				{
81 					aIdx.Assign( *pNd, - 1 );
82 					continue;
83 				}
84 				rCurCrsr.GetPoint()->nContent.Assign( pCNd, pCNd->Len() );
85 			}
86 
87 			rCurCrsr.GetPoint()->nNode = aIdx;
88 			return sal_True;
89 		}
90 	} while( pNd );
91 	return sal_False;
92 }
93 
94 
GotoNextRegion(SwPaM & rCurCrsr,SwPosRegion fnPosRegion,sal_Bool bInReadOnly)95 sal_Bool GotoNextRegion( SwPaM& rCurCrsr, SwPosRegion fnPosRegion,
96 						sal_Bool bInReadOnly )
97 {
98 	SwNodeIndex aIdx( rCurCrsr.GetPoint()->nNode );
99 	SwSectionNode* pNd = aIdx.GetNode().FindSectionNode();
100 	if( pNd )
101 		aIdx.Assign( *pNd->EndOfSectionNode(), - 1 );
102 
103 	sal_uLong nEndCount = aIdx.GetNode().GetNodes().Count()-1;
104 	do {
105 		while( aIdx.GetIndex() < nEndCount &&
106 				0 == ( pNd = aIdx.GetNode().GetSectionNode()) )
107 			aIdx++;
108 
109 		if( pNd )		// gibt einen weiteren SectionNode ?
110 		{
111 			if( pNd->GetSection().IsHiddenFlag() ||
112 				( !bInReadOnly &&
113 				  pNd->GetSection().IsProtectFlag() ))
114 			{
115 				// geschuetzte/versteckte ueberspringen wir
116 				aIdx.Assign( *pNd->EndOfSectionNode(), +1 );
117 			}
118 			else if( fnPosRegion == fnMoveForward )
119 			{
120 				aIdx = *pNd;
121 				SwCntntNode* pCNd = pNd->GetNodes().GoNextSection( &aIdx,
122 												sal_True, !bInReadOnly );
123 				if( !pCNd )
124 				{
125 					aIdx.Assign( *pNd->EndOfSectionNode(), +1 );
126 					continue;
127 				}
128 				rCurCrsr.GetPoint()->nContent.Assign( pCNd, 0 );
129 			}
130 			else
131 			{
132 				aIdx = *pNd->EndOfSectionNode();
133 				SwCntntNode* pCNd = pNd->GetNodes().GoPrevSection( &aIdx,
134 												sal_True, !bInReadOnly );
135 				if( !pCNd )
136 				{
137 					aIdx++;
138 					continue;
139 				}
140 				rCurCrsr.GetPoint()->nContent.Assign( pCNd, pCNd->Len() );
141 			}
142 
143 			rCurCrsr.GetPoint()->nNode = aIdx;
144 			return sal_True;
145 		}
146 	} while( pNd );
147 	return sal_False;
148 }
149 
150 
GotoCurrRegion(SwPaM & rCurCrsr,SwPosRegion fnPosRegion,sal_Bool bInReadOnly)151 sal_Bool GotoCurrRegion( SwPaM& rCurCrsr, SwPosRegion fnPosRegion,
152 						sal_Bool bInReadOnly )
153 {
154 	SwSectionNode* pNd = rCurCrsr.GetNode()->FindSectionNode();
155 	if( !pNd )
156 		return sal_False;
157 
158 	SwPosition* pPos = rCurCrsr.GetPoint();
159 	sal_Bool bMoveBackward = fnPosRegion == fnMoveBackward;
160 
161 	SwCntntNode* pCNd;
162 	if( bMoveBackward )
163 	{
164 		SwNodeIndex aIdx( *pNd->EndOfSectionNode() );
165 		pCNd = pNd->GetNodes().GoPrevSection( &aIdx, sal_True, !bInReadOnly );
166 	}
167 	else
168 	{
169 		SwNodeIndex aIdx( *pNd );
170 		pCNd = pNd->GetNodes().GoNextSection( &aIdx, sal_True, !bInReadOnly );
171 	}
172 
173 	if( pCNd )
174 	{
175 		pPos->nNode = *pCNd;
176 		xub_StrLen nTmpPos = bMoveBackward ? pCNd->Len() : 0;
177 		pPos->nContent.Assign( pCNd, nTmpPos );
178 	}
179 	return 0 != pCNd;
180 }
181 
182 
GotoCurrRegionAndSkip(SwPaM & rCurCrsr,SwPosRegion fnPosRegion,sal_Bool bInReadOnly)183 sal_Bool GotoCurrRegionAndSkip( SwPaM& rCurCrsr, SwPosRegion fnPosRegion,
184 								sal_Bool bInReadOnly )
185 {
186 	SwNode* pCurrNd = rCurCrsr.GetNode();
187 	SwSectionNode* pNd = pCurrNd->FindSectionNode();
188 	if( !pNd )
189 		return sal_False;
190 
191 	SwPosition* pPos = rCurCrsr.GetPoint();
192 	xub_StrLen nCurrCnt = pPos->nContent.GetIndex();
193 	sal_Bool bMoveBackward = fnPosRegion == fnMoveBackward;
194 
195 	do {
196 		SwCntntNode* pCNd;
197 		if( bMoveBackward )	// ans Ende vom Bereich
198 		{
199 			SwNodeIndex aIdx( *pNd->EndOfSectionNode() );
200 			pCNd = pNd->GetNodes().GoPrevSection( &aIdx, sal_True, !bInReadOnly );
201 			if( !pCNd )
202 				return sal_False;
203 			pPos->nNode = aIdx;
204 		}
205 		else
206 		{
207 			SwNodeIndex aIdx( *pNd );
208 			pCNd = pNd->GetNodes().GoNextSection( &aIdx, sal_True, !bInReadOnly );
209 			if( !pCNd )
210 				return sal_False;
211 			pPos->nNode = aIdx;
212 		}
213 
214 		xub_StrLen nTmpPos = bMoveBackward ? pCNd->Len() : 0;
215 		pPos->nContent.Assign( pCNd, nTmpPos );
216 
217 		if( &pPos->nNode.GetNode() != pCurrNd ||
218 			pPos->nContent.GetIndex() != nCurrCnt )
219 			// es gab eine Veraenderung
220 			return sal_True;
221 
222 		// dann versuche mal den "Parent" dieser Section
223 		SwSection* pParent = pNd->GetSection().GetParent();
224 		pNd = pParent ? pParent->GetFmt()->GetSectionNode() : 0;
225 	} while( pNd );
226 	return sal_False;
227 }
228 
229 
230 
MoveRegion(SwWhichRegion fnWhichRegion,SwPosRegion fnPosRegion)231 sal_Bool SwCursor::MoveRegion( SwWhichRegion fnWhichRegion, SwPosRegion fnPosRegion )
232 {
233 	SwCrsrSaveState aSaveState( *this );
234     return !dynamic_cast<SwTableCursor*>(this) &&
235 			(*fnWhichRegion)( *this, fnPosRegion, IsReadOnlyAvailable()  ) &&
236 			!IsSelOvr() &&
237 			( GetPoint()->nNode.GetIndex() != pSavePos->nNode ||
238 				GetPoint()->nContent.GetIndex() != pSavePos->nCntnt );
239 }
240 
MoveRegion(SwWhichRegion fnWhichRegion,SwPosRegion fnPosRegion)241 sal_Bool SwCrsrShell::MoveRegion( SwWhichRegion fnWhichRegion, SwPosRegion fnPosRegion )
242 {
243 	SwCallLink aLk( *this );		// Crsr-Moves ueberwachen, evt. Link callen
244 	sal_Bool bRet = !pTblCrsr && pCurCrsr->MoveRegion( fnWhichRegion, fnPosRegion );
245 	if( bRet )
246 		UpdateCrsr();
247 	return bRet;
248 }
249 
250 
GotoRegion(const String & rName)251 sal_Bool SwCursor::GotoRegion( const String& rName )
252 {
253 	sal_Bool bRet = sal_False;
254 	const SwSectionFmts& rFmts = GetDoc()->GetSections();
255 	for( sal_uInt16 n = rFmts.Count(); n; )
256 	{
257 		const SwSectionFmt* pFmt = rFmts[ --n ];
258 		const SwNodeIndex* pIdx;
259 		const SwSection* pSect;
260 		if( 0 != ( pSect = pFmt->GetSection() ) &&
261             pSect->GetSectionName() == rName &&
262 			0 != ( pIdx = pFmt->GetCntnt().GetCntntIdx() ) &&
263 			pIdx->GetNode().GetNodes().IsDocNodes() )
264 		{
265 			// ein Bereich im normalen NodesArr
266 			SwCrsrSaveState aSaveState( *this );
267 
268 			GetPoint()->nNode = *pIdx;
269 			Move( fnMoveForward, fnGoCntnt );
270 			bRet = !IsSelOvr();
271 		}
272 	}
273 	return bRet;
274 }
275 
GotoRegion(const String & rName)276 sal_Bool SwCrsrShell::GotoRegion( const String& rName )
277 {
278 	SwCallLink aLk( *this );		// Crsr-Moves ueberwachen,
279 	sal_Bool bRet = !pTblCrsr && pCurCrsr->GotoRegion( rName );
280 	if( bRet )
281 		UpdateCrsr( SwCrsrShell::SCROLLWIN | SwCrsrShell::CHKRANGE |
282 					SwCrsrShell::READONLY ); // und den akt. Updaten
283 	return bRet;
284 }
285 
286 
287 
288