xref: /aoo42x/main/sw/source/ui/wrtsh/wrtsh4.cxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_sw.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir #include <wrtsh.hxx>
33*cdf0e10cSrcweir #include <crsskip.hxx>
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir /*
37*cdf0e10cSrcweir * private Methoden, die den Cursor ueber Suchen bewegen. Das
38*cdf0e10cSrcweir * Aufheben der Selektion muss auf der Ebene darueber erfolgen.
39*cdf0e10cSrcweir */
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir /*
42*cdf0e10cSrcweir * Der Anfang eines Wortes ist das Folgen eines nicht-
43*cdf0e10cSrcweir * Trennzeichens auf Trennzeichen. Ferner das Folgen von
44*cdf0e10cSrcweir * nicht-Satztrennern auf Satztrenner. Der Absatzanfang ist
45*cdf0e10cSrcweir * ebenfalls Wortanfang.
46*cdf0e10cSrcweir */
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir sal_Bool SwWrtShell::_SttWrd()
50*cdf0e10cSrcweir {
51*cdf0e10cSrcweir 	if ( IsSttPara() )
52*cdf0e10cSrcweir 		return 1;
53*cdf0e10cSrcweir 		/*
54*cdf0e10cSrcweir 			* temporaeren Cursor ohne Selektion erzeugen
55*cdf0e10cSrcweir 			*/
56*cdf0e10cSrcweir 	Push();
57*cdf0e10cSrcweir 	ClearMark();
58*cdf0e10cSrcweir 	if( !GoStartWord() )
59*cdf0e10cSrcweir 			// nicht gefunden --> an den Absatzanfang
60*cdf0e10cSrcweir 		SwCrsrShell::MovePara( fnParaCurr, fnParaStart );
61*cdf0e10cSrcweir 	ClearMark();
62*cdf0e10cSrcweir 		// falls vorher Mark gesetzt war, zusammenfassen
63*cdf0e10cSrcweir 	Combine();
64*cdf0e10cSrcweir 	return 1;
65*cdf0e10cSrcweir }
66*cdf0e10cSrcweir /*
67*cdf0e10cSrcweir  * Das Ende eines Wortes ist das Folgen von Trennzeichen auf
68*cdf0e10cSrcweir  * nicht-Trennzeichen.	Unter dem Ende eines Wortes wird
69*cdf0e10cSrcweir  * ebenfalls die Folge von Worttrennzeichen auf Interpunktions-
70*cdf0e10cSrcweir  * zeichen verstanden. Das Absatzende ist ebenfalls Wortende.
71*cdf0e10cSrcweir  */
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir sal_Bool SwWrtShell::_EndWrd()
76*cdf0e10cSrcweir {
77*cdf0e10cSrcweir 	if ( IsEndWrd() )
78*cdf0e10cSrcweir 		return 1;
79*cdf0e10cSrcweir 		// temporaeren Cursor ohne Selektion erzeugen
80*cdf0e10cSrcweir 	Push();
81*cdf0e10cSrcweir 	ClearMark();
82*cdf0e10cSrcweir 	if( !GoEndWord() )
83*cdf0e10cSrcweir 			// nicht gefunden --> an das Absatz Ende
84*cdf0e10cSrcweir 		SwCrsrShell::MovePara(fnParaCurr, fnParaEnd);
85*cdf0e10cSrcweir 	ClearMark();
86*cdf0e10cSrcweir 		// falls vorher Mark gesetzt war, zusammenfassen
87*cdf0e10cSrcweir 	Combine();
88*cdf0e10cSrcweir 	return 1;
89*cdf0e10cSrcweir }
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir sal_Bool SwWrtShell::_NxtWrd()
94*cdf0e10cSrcweir {
95*cdf0e10cSrcweir     sal_Bool bRet = sal_False;
96*cdf0e10cSrcweir 	while( IsEndPara() )				// wenn schon am Ende, dann naechsten ???
97*cdf0e10cSrcweir 	{
98*cdf0e10cSrcweir 		if(!SwCrsrShell::Right(1,CRSR_SKIP_CHARS))	// Document - Ende ??
99*cdf0e10cSrcweir 		{
100*cdf0e10cSrcweir 			Pop( sal_False );
101*cdf0e10cSrcweir 			return bRet;
102*cdf0e10cSrcweir 		}
103*cdf0e10cSrcweir         bRet = IsStartWord();
104*cdf0e10cSrcweir 	}
105*cdf0e10cSrcweir 	Push();
106*cdf0e10cSrcweir 	ClearMark();
107*cdf0e10cSrcweir     while( !bRet )
108*cdf0e10cSrcweir     {
109*cdf0e10cSrcweir         if( !GoNextWord() )
110*cdf0e10cSrcweir         {
111*cdf0e10cSrcweir             if( (!IsEndPara() && !SwCrsrShell::MovePara( fnParaCurr, fnParaEnd ) )
112*cdf0e10cSrcweir                 || !SwCrsrShell::Right(1,CRSR_SKIP_CHARS) )
113*cdf0e10cSrcweir                 break;
114*cdf0e10cSrcweir             bRet = IsStartWord();
115*cdf0e10cSrcweir         }
116*cdf0e10cSrcweir         else
117*cdf0e10cSrcweir             bRet = sal_True;
118*cdf0e10cSrcweir     }
119*cdf0e10cSrcweir 	ClearMark();
120*cdf0e10cSrcweir 	Combine();
121*cdf0e10cSrcweir 	return bRet;
122*cdf0e10cSrcweir }
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir sal_Bool SwWrtShell::_PrvWrd()
125*cdf0e10cSrcweir {
126*cdf0e10cSrcweir     sal_Bool bRet = sal_False;
127*cdf0e10cSrcweir 	while( IsSttPara() )
128*cdf0e10cSrcweir 	{								// wenn schon am Anfang, dann naechsten ???
129*cdf0e10cSrcweir 		if(!SwCrsrShell::Left(1,CRSR_SKIP_CHARS))
130*cdf0e10cSrcweir 		{							// Document - Anfang ??
131*cdf0e10cSrcweir 			Pop( sal_False );
132*cdf0e10cSrcweir 			return bRet;
133*cdf0e10cSrcweir 		}
134*cdf0e10cSrcweir 		bRet = IsStartWord();
135*cdf0e10cSrcweir 	}
136*cdf0e10cSrcweir 	Push();
137*cdf0e10cSrcweir 	ClearMark();
138*cdf0e10cSrcweir     while( !bRet )
139*cdf0e10cSrcweir     {
140*cdf0e10cSrcweir         if( !GoPrevWord() )
141*cdf0e10cSrcweir         {
142*cdf0e10cSrcweir             if( (!IsSttPara() && !SwCrsrShell::MovePara( fnParaCurr, fnParaStart ) )
143*cdf0e10cSrcweir                 || !SwCrsrShell::Left(1,CRSR_SKIP_CHARS) )
144*cdf0e10cSrcweir                 break;
145*cdf0e10cSrcweir             bRet = IsStartWord();
146*cdf0e10cSrcweir         }
147*cdf0e10cSrcweir         else
148*cdf0e10cSrcweir             bRet = sal_True;
149*cdf0e10cSrcweir     }
150*cdf0e10cSrcweir 	ClearMark();
151*cdf0e10cSrcweir 	Combine();
152*cdf0e10cSrcweir 	return bRet;
153*cdf0e10cSrcweir }
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir // --> OD 2008-08-06 #i92468#
156*cdf0e10cSrcweir // method code of <SwWrtShell::_NxtWrd()> before fix for issue i72162
157*cdf0e10cSrcweir sal_Bool SwWrtShell::_NxtWrdForDelete()
158*cdf0e10cSrcweir {
159*cdf0e10cSrcweir     if ( IsEndPara() )
160*cdf0e10cSrcweir     {
161*cdf0e10cSrcweir         if ( !SwCrsrShell::Right(1,CRSR_SKIP_CHARS) )
162*cdf0e10cSrcweir         {
163*cdf0e10cSrcweir             Pop( sal_False );
164*cdf0e10cSrcweir             return sal_False;
165*cdf0e10cSrcweir         }
166*cdf0e10cSrcweir         return sal_True;
167*cdf0e10cSrcweir     }
168*cdf0e10cSrcweir     Push();
169*cdf0e10cSrcweir     ClearMark();
170*cdf0e10cSrcweir     if ( !GoNextWord() )
171*cdf0e10cSrcweir     {
172*cdf0e10cSrcweir         SwCrsrShell::MovePara( fnParaCurr, fnParaEnd );
173*cdf0e10cSrcweir     }
174*cdf0e10cSrcweir     ClearMark();
175*cdf0e10cSrcweir     Combine();
176*cdf0e10cSrcweir     return sal_True;
177*cdf0e10cSrcweir }
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir // method code of <SwWrtShell::_PrvWrd()> before fix for issue i72162
180*cdf0e10cSrcweir sal_Bool SwWrtShell::_PrvWrdForDelete()
181*cdf0e10cSrcweir {
182*cdf0e10cSrcweir     if ( IsSttPara() )
183*cdf0e10cSrcweir     {
184*cdf0e10cSrcweir         if ( !SwCrsrShell::Left(1,CRSR_SKIP_CHARS) )
185*cdf0e10cSrcweir         {
186*cdf0e10cSrcweir             Pop( sal_False );
187*cdf0e10cSrcweir             return sal_False;
188*cdf0e10cSrcweir         }
189*cdf0e10cSrcweir         return sal_True;
190*cdf0e10cSrcweir     }
191*cdf0e10cSrcweir     Push();
192*cdf0e10cSrcweir     ClearMark();
193*cdf0e10cSrcweir     if( !GoPrevWord() )
194*cdf0e10cSrcweir     {
195*cdf0e10cSrcweir         SwCrsrShell::MovePara( fnParaCurr, fnParaStart );
196*cdf0e10cSrcweir     }
197*cdf0e10cSrcweir     ClearMark();
198*cdf0e10cSrcweir     Combine();
199*cdf0e10cSrcweir     return sal_True;
200*cdf0e10cSrcweir }
201*cdf0e10cSrcweir // <--
202*cdf0e10cSrcweir 
203*cdf0e10cSrcweir 
204*cdf0e10cSrcweir sal_Bool SwWrtShell::_FwdSentence()
205*cdf0e10cSrcweir {
206*cdf0e10cSrcweir 	Push();
207*cdf0e10cSrcweir 	ClearMark();
208*cdf0e10cSrcweir 	if(!SwCrsrShell::Right(1,CRSR_SKIP_CHARS))
209*cdf0e10cSrcweir 	{
210*cdf0e10cSrcweir 		Pop(sal_False);
211*cdf0e10cSrcweir 		return 0;
212*cdf0e10cSrcweir 	}
213*cdf0e10cSrcweir 	if( !GoNextSentence() && !IsEndPara() )
214*cdf0e10cSrcweir 		SwCrsrShell::MovePara(fnParaCurr, fnParaEnd);
215*cdf0e10cSrcweir 
216*cdf0e10cSrcweir 	ClearMark();
217*cdf0e10cSrcweir 	Combine();
218*cdf0e10cSrcweir 	return 1;
219*cdf0e10cSrcweir }
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir 
222*cdf0e10cSrcweir 
223*cdf0e10cSrcweir sal_Bool SwWrtShell::_BwdSentence()
224*cdf0e10cSrcweir {
225*cdf0e10cSrcweir 	Push();
226*cdf0e10cSrcweir 	ClearMark();
227*cdf0e10cSrcweir 	if(!SwCrsrShell::Left(1,CRSR_SKIP_CHARS))
228*cdf0e10cSrcweir 	{
229*cdf0e10cSrcweir 		Pop(sal_False);
230*cdf0e10cSrcweir 		return 0;
231*cdf0e10cSrcweir 	}
232*cdf0e10cSrcweir 	if(IsSttPara())
233*cdf0e10cSrcweir 	{
234*cdf0e10cSrcweir 		Pop();
235*cdf0e10cSrcweir 		return 1;
236*cdf0e10cSrcweir 	}
237*cdf0e10cSrcweir 	if( !GoPrevSentence()  && !IsSttPara() )
238*cdf0e10cSrcweir 			// nicht gefunden --> an den Absatz Anfang
239*cdf0e10cSrcweir 		SwCrsrShell::MovePara( fnParaCurr, fnParaStart );
240*cdf0e10cSrcweir 	ClearMark();
241*cdf0e10cSrcweir 	Combine();
242*cdf0e10cSrcweir 	return 1;
243*cdf0e10cSrcweir }
244*cdf0e10cSrcweir 
245*cdf0e10cSrcweir 
246*cdf0e10cSrcweir sal_Bool SwWrtShell::_FwdPara()
247*cdf0e10cSrcweir {
248*cdf0e10cSrcweir 	Push();
249*cdf0e10cSrcweir 	ClearMark();
250*cdf0e10cSrcweir     // --> OD 2009-01-06 #i81824#
251*cdf0e10cSrcweir     // going right and back again left not needed and causes too much
252*cdf0e10cSrcweir     // accessibility events due to the cursor movements.
253*cdf0e10cSrcweir //    if(!SwCrsrShell::Right(1,CRSR_SKIP_CHARS))
254*cdf0e10cSrcweir //    {
255*cdf0e10cSrcweir //        Pop(sal_False);
256*cdf0e10cSrcweir //        return 0;
257*cdf0e10cSrcweir //    }
258*cdf0e10cSrcweir //    SwCrsrShell::Left(1,CRSR_SKIP_CHARS);
259*cdf0e10cSrcweir     // <--
260*cdf0e10cSrcweir 	sal_Bool bRet = SwCrsrShell::MovePara(fnParaNext, fnParaStart);
261*cdf0e10cSrcweir 
262*cdf0e10cSrcweir 	ClearMark();
263*cdf0e10cSrcweir 	Combine();
264*cdf0e10cSrcweir 	return bRet;
265*cdf0e10cSrcweir }
266*cdf0e10cSrcweir 
267*cdf0e10cSrcweir 
268*cdf0e10cSrcweir sal_Bool SwWrtShell::_BwdPara()
269*cdf0e10cSrcweir {
270*cdf0e10cSrcweir 	Push();
271*cdf0e10cSrcweir 	ClearMark();
272*cdf0e10cSrcweir     // --> OD 2009-01-06 #i81824#
273*cdf0e10cSrcweir     // going left and back again right not needed and causes too much
274*cdf0e10cSrcweir     // accessibility events due to the cursor movements.
275*cdf0e10cSrcweir //    if(!SwCrsrShell::Left(1,CRSR_SKIP_CHARS))
276*cdf0e10cSrcweir //    {
277*cdf0e10cSrcweir //        Pop(sal_False);
278*cdf0e10cSrcweir //        return 0;
279*cdf0e10cSrcweir //    }
280*cdf0e10cSrcweir //    SwCrsrShell::Right(1,CRSR_SKIP_CHARS);
281*cdf0e10cSrcweir     // <--
282*cdf0e10cSrcweir     // --> OD 2009-01-06 #i81824#
283*cdf0e10cSrcweir     // going to start of paragraph only needed, if move to previous paragraph
284*cdf0e10cSrcweir     // does not happen. Otherwise, useless accessibility events are triggered
285*cdf0e10cSrcweir     // due to cursor movements.
286*cdf0e10cSrcweir //    if(!IsSttOfPara())
287*cdf0e10cSrcweir //        SttPara();
288*cdf0e10cSrcweir 	sal_Bool bRet = SwCrsrShell::MovePara(fnParaPrev, fnParaStart);
289*cdf0e10cSrcweir     if ( !bRet && !IsSttOfPara() )
290*cdf0e10cSrcweir     {
291*cdf0e10cSrcweir         SttPara();
292*cdf0e10cSrcweir     }
293*cdf0e10cSrcweir     // <--
294*cdf0e10cSrcweir 
295*cdf0e10cSrcweir 	ClearMark();
296*cdf0e10cSrcweir 	Combine();
297*cdf0e10cSrcweir 	return bRet;
298*cdf0e10cSrcweir }
299*cdf0e10cSrcweir 
300*cdf0e10cSrcweir 
301