xref: /aoo41x/main/sw/source/core/edit/edlingu.cxx (revision dec99bbd)
1efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3efeef26fSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4efeef26fSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5efeef26fSAndrew Rist  * distributed with this work for additional information
6efeef26fSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7efeef26fSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8efeef26fSAndrew Rist  * "License"); you may not use this file except in compliance
9efeef26fSAndrew Rist  * with the License.  You may obtain a copy of the License at
10efeef26fSAndrew Rist  *
11efeef26fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12efeef26fSAndrew Rist  *
13efeef26fSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14efeef26fSAndrew Rist  * software distributed under the License is distributed on an
15efeef26fSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16efeef26fSAndrew Rist  * KIND, either express or implied.  See the License for the
17efeef26fSAndrew Rist  * specific language governing permissions and limitations
18efeef26fSAndrew Rist  * under the License.
19efeef26fSAndrew Rist  *
20efeef26fSAndrew Rist  *************************************************************/
21efeef26fSAndrew Rist 
22efeef26fSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sw.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <com/sun/star/linguistic2/ProofreadingResult.hpp>
28cdf0e10cSrcweir #include <com/sun/star/linguistic2/XProofreader.hpp>
29cdf0e10cSrcweir #include <com/sun/star/linguistic2/XProofreadingIterator.hpp>
30cdf0e10cSrcweir #include <com/sun/star/text/XFlatParagraph.hpp>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #include <unoflatpara.hxx>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include <comcore.hrc>
35cdf0e10cSrcweir #include <hintids.hxx>
36cdf0e10cSrcweir #include <linguistic/lngprops.hxx>
37cdf0e10cSrcweir #include <vcl/msgbox.hxx>
38cdf0e10cSrcweir #include <editeng/unolingu.hxx>
39cdf0e10cSrcweir #include <editeng/svxacorr.hxx>
40cdf0e10cSrcweir #include <editeng/langitem.hxx>
41cdf0e10cSrcweir #include <editeng/SpellPortions.hxx>
42cdf0e10cSrcweir #include <editeng/scripttypeitem.hxx>
43cdf0e10cSrcweir #include <charatr.hxx>
44cdf0e10cSrcweir #include <editsh.hxx>
45cdf0e10cSrcweir #include <doc.hxx>
46cdf0e10cSrcweir #include <IDocumentUndoRedo.hxx>
47cdf0e10cSrcweir #include <rootfrm.hxx>      // SwRootFrm
48cdf0e10cSrcweir #include <pam.hxx>
49cdf0e10cSrcweir #include <swundo.hxx>		// fuer die UndoIds
50cdf0e10cSrcweir #include <ndtxt.hxx>        // AdjHyphPos
51cdf0e10cSrcweir #include <viewopt.hxx>      // HyphStart/End
52cdf0e10cSrcweir #include <viscrs.hxx>		// SwShellCrsr
53cdf0e10cSrcweir #include <SwGrammarMarkUp.hxx>		// SwWrongList
54cdf0e10cSrcweir #include <mdiexp.hxx>		// Statusanzeige
55cdf0e10cSrcweir #include <statstr.hrc>      // StatLine-String
56cdf0e10cSrcweir #include <cntfrm.hxx>
57cdf0e10cSrcweir #include <crsskip.hxx>
58cdf0e10cSrcweir #include <splargs.hxx>
59cdf0e10cSrcweir #include <redline.hxx>      // SwRedline
60cdf0e10cSrcweir #include <docary.hxx>       // SwRedlineTbl
61cdf0e10cSrcweir #include <docsh.hxx>
62cdf0e10cSrcweir #include <txatbase.hxx>
63cdf0e10cSrcweir #include <txtfrm.hxx>
64cdf0e10cSrcweir 
65cdf0e10cSrcweir using namespace ::svx;
66cdf0e10cSrcweir using namespace ::com::sun::star;
67cdf0e10cSrcweir using namespace ::com::sun::star::uno;
68cdf0e10cSrcweir using namespace ::com::sun::star::beans;
69cdf0e10cSrcweir using namespace ::com::sun::star::linguistic2;
70cdf0e10cSrcweir 
71cdf0e10cSrcweir #define C2U(cChar) rtl::OUString::createFromAscii(cChar)
72cdf0e10cSrcweir 
73cdf0e10cSrcweir /*************************************************************************
74cdf0e10cSrcweir  *					   class SwLinguIter
75cdf0e10cSrcweir  *************************************************************************/
76cdf0e10cSrcweir 
77cdf0e10cSrcweir class SwLinguIter
78cdf0e10cSrcweir {
79cdf0e10cSrcweir 	SwEditShell *pSh;
80cdf0e10cSrcweir 	SwPosition	*pStart;
81cdf0e10cSrcweir 	SwPosition	*pEnd;
82cdf0e10cSrcweir 	SwPosition	*pCurr;
83cdf0e10cSrcweir 	SwPosition	*pCurrX;
84cdf0e10cSrcweir 	sal_uInt16 nCrsrCnt;
85cdf0e10cSrcweir public:
86cdf0e10cSrcweir 	SwLinguIter();
87cdf0e10cSrcweir 
GetSh()88cdf0e10cSrcweir 	inline SwEditShell *GetSh() 			{ return pSh; }
GetSh() const89cdf0e10cSrcweir 	inline const SwEditShell *GetSh() const { return pSh; }
90cdf0e10cSrcweir 
GetEnd() const91cdf0e10cSrcweir 	inline const SwPosition *GetEnd() const { return pEnd; }
SetEnd(SwPosition * pNew)92cdf0e10cSrcweir 	inline void SetEnd( SwPosition* pNew ){ delete pEnd; pEnd = pNew; }
93cdf0e10cSrcweir 
GetStart() const94cdf0e10cSrcweir 	inline const SwPosition *GetStart() const { return pStart; }
SetStart(SwPosition * pNew)95cdf0e10cSrcweir 	inline void SetStart( SwPosition* pNew ){ delete pStart; pStart = pNew; }
96cdf0e10cSrcweir 
GetCurr() const97cdf0e10cSrcweir 	inline const SwPosition *GetCurr() const { return pCurr; }
SetCurr(SwPosition * pNew)98cdf0e10cSrcweir 	inline void SetCurr( SwPosition* pNew ){ delete pCurr; pCurr = pNew; }
99cdf0e10cSrcweir 
GetCurrX() const100cdf0e10cSrcweir 	inline const SwPosition *GetCurrX() const { return pCurrX; }
SetCurrX(SwPosition * pNew)101cdf0e10cSrcweir 	inline void SetCurrX( SwPosition* pNew ){ delete pCurrX; pCurrX = pNew; }
102cdf0e10cSrcweir 
GetCrsrCnt()103cdf0e10cSrcweir 	inline sal_uInt16& GetCrsrCnt(){ return nCrsrCnt; }
104cdf0e10cSrcweir 
105cdf0e10cSrcweir 	// Der UI-Bauchladen:
106cdf0e10cSrcweir 	void _Start( SwEditShell *pSh, SwDocPositions eStart,
107cdf0e10cSrcweir                 SwDocPositions eEnd );
108cdf0e10cSrcweir     void _End(bool bRestoreSelection = true);
109cdf0e10cSrcweir };
110cdf0e10cSrcweir 
111cdf0e10cSrcweir /*************************************************************************
112cdf0e10cSrcweir  *					   class SwSpellIter
113cdf0e10cSrcweir  *************************************************************************/
114cdf0e10cSrcweir 
115cdf0e10cSrcweir // #i18881# to be able to identify the postions of the changed words
116cdf0e10cSrcweir // the content positions of each portion need to be saved
117cdf0e10cSrcweir struct SpellContentPosition
118cdf0e10cSrcweir {
119cdf0e10cSrcweir     sal_uInt16 nLeft;
120cdf0e10cSrcweir     sal_uInt16 nRight;
121cdf0e10cSrcweir };
122cdf0e10cSrcweir typedef std::vector<SpellContentPosition>  SpellContentPositions;
123cdf0e10cSrcweir class SwSpellIter : public SwLinguIter
124cdf0e10cSrcweir {
125cdf0e10cSrcweir 	uno::Reference< XSpellChecker1 > 	xSpeller;
126cdf0e10cSrcweir     ::svx::SpellPortions                aLastPortions;
127cdf0e10cSrcweir 
128cdf0e10cSrcweir     SpellContentPositions               aLastPositions;
129cdf0e10cSrcweir     bool                                bBackToStartOfSentence;
130cdf0e10cSrcweir     bool                                bMoveToEndOfSentence;
131cdf0e10cSrcweir 
132cdf0e10cSrcweir 
133cdf0e10cSrcweir     void    CreatePortion(uno::Reference< XSpellAlternatives > xAlt,
134cdf0e10cSrcweir                 linguistic2::ProofreadingResult* pGrammarResult,
135cdf0e10cSrcweir                 bool bIsField, bool bIsHidden);
136cdf0e10cSrcweir 
137cdf0e10cSrcweir     void    AddPortion(uno::Reference< XSpellAlternatives > xAlt,
138cdf0e10cSrcweir                        linguistic2::ProofreadingResult* pGrammarResult,
139cdf0e10cSrcweir                        const SpellContentPositions& rDeletedRedlines);
140cdf0e10cSrcweir public:
SwSpellIter()141cdf0e10cSrcweir     SwSpellIter() :
142cdf0e10cSrcweir         bBackToStartOfSentence(false), bMoveToEndOfSentence(false) {}
143cdf0e10cSrcweir 
144cdf0e10cSrcweir 	void Start( SwEditShell *pSh, SwDocPositions eStart, SwDocPositions eEnd );
145cdf0e10cSrcweir 
146cdf0e10cSrcweir     uno::Any    Continue( sal_uInt16* pPageCnt, sal_uInt16* pPageSt );
147cdf0e10cSrcweir 
148cdf0e10cSrcweir     bool                                SpellSentence(::svx::SpellPortions& rPortions, bool bIsGrammarCheck);
149cdf0e10cSrcweir     void                                ToSentenceStart();
GetLastPortions()150cdf0e10cSrcweir     const ::svx::SpellPortions          GetLastPortions(){ return aLastPortions;}
GetLastPositions()151cdf0e10cSrcweir     SpellContentPositions               GetLastPositions() {return aLastPositions;}
ContinueAfterThisSentence()152cdf0e10cSrcweir     void                                ContinueAfterThisSentence() { bMoveToEndOfSentence = true; }
153cdf0e10cSrcweir };
154cdf0e10cSrcweir 
155cdf0e10cSrcweir /*************************************************************************
156cdf0e10cSrcweir  *                     class SwConvIter
157cdf0e10cSrcweir  * used for text conversion
158cdf0e10cSrcweir  *************************************************************************/
159cdf0e10cSrcweir 
160cdf0e10cSrcweir class SwConvIter : public SwLinguIter
161cdf0e10cSrcweir {
162cdf0e10cSrcweir     SwConversionArgs &rArgs;
163cdf0e10cSrcweir public:
SwConvIter(SwConversionArgs & rConvArgs)164cdf0e10cSrcweir     SwConvIter( SwConversionArgs &rConvArgs ) :
165cdf0e10cSrcweir         rArgs( rConvArgs )
166cdf0e10cSrcweir     {}
167cdf0e10cSrcweir 
168cdf0e10cSrcweir     void Start( SwEditShell *pSh, SwDocPositions eStart, SwDocPositions eEnd );
169cdf0e10cSrcweir 
170cdf0e10cSrcweir     uno::Any    Continue( sal_uInt16* pPageCnt, sal_uInt16* pPageSt );
171cdf0e10cSrcweir };
172cdf0e10cSrcweir 
173cdf0e10cSrcweir /*************************************************************************
174cdf0e10cSrcweir  *					   class SwHyphIter
175cdf0e10cSrcweir  *************************************************************************/
176cdf0e10cSrcweir 
177cdf0e10cSrcweir class SwHyphIter : public SwLinguIter
178cdf0e10cSrcweir {
179cdf0e10cSrcweir 	sal_Bool bOldIdle;
180cdf0e10cSrcweir 	void DelSoftHyph( SwPaM &rPam );
181cdf0e10cSrcweir 
182cdf0e10cSrcweir public:
SwHyphIter()183cdf0e10cSrcweir 	SwHyphIter() : bOldIdle(sal_False) {}
184cdf0e10cSrcweir 
185cdf0e10cSrcweir 	void Start( SwEditShell *pSh, SwDocPositions eStart, SwDocPositions eEnd );
186cdf0e10cSrcweir 	void End();
187cdf0e10cSrcweir 
188cdf0e10cSrcweir 	void Ignore();
189cdf0e10cSrcweir 
190cdf0e10cSrcweir     uno::Any    Continue( sal_uInt16* pPageCnt, sal_uInt16* pPageSt );
191cdf0e10cSrcweir 
192cdf0e10cSrcweir 	sal_Bool IsAuto();
193cdf0e10cSrcweir 	void InsertSoftHyph( const xub_StrLen nHyphPos );
194cdf0e10cSrcweir 	void ShowSelection();
195cdf0e10cSrcweir };
196cdf0e10cSrcweir 
197cdf0e10cSrcweir static SwSpellIter*	pSpellIter = 0;
198cdf0e10cSrcweir static SwConvIter*  pConvIter = 0;
199cdf0e10cSrcweir static SwHyphIter*	pHyphIter = 0;
200cdf0e10cSrcweir 
201cdf0e10cSrcweir // Wir ersparen uns in Hyphenate ein GetFrm()
202cdf0e10cSrcweir // Achtung: in txtedt.cxx stehen extern-Deklarationen auf diese Pointer!
203cdf0e10cSrcweir const SwTxtNode *pLinguNode;
204cdf0e10cSrcweir 	  SwTxtFrm  *pLinguFrm;
205cdf0e10cSrcweir 
206cdf0e10cSrcweir /*************************************************************************
207cdf0e10cSrcweir  *						SwLinguIter::SwLinguIter
208cdf0e10cSrcweir  *************************************************************************/
209cdf0e10cSrcweir 
SwLinguIter()210cdf0e10cSrcweir SwLinguIter::SwLinguIter()
211cdf0e10cSrcweir 	: pSh( 0 ), pStart( 0 ), pEnd( 0 ), pCurr( 0 ), pCurrX( 0 )
212cdf0e10cSrcweir {
213cdf0e10cSrcweir 	// @@@ es fehlt: Sicherstellen der Reentrance, ASSERTs etc.
214cdf0e10cSrcweir }
215cdf0e10cSrcweir 
216cdf0e10cSrcweir /*************************************************************************
217cdf0e10cSrcweir  *						SwLinguIter::Start
218cdf0e10cSrcweir  *************************************************************************/
219cdf0e10cSrcweir 
220cdf0e10cSrcweir 
221cdf0e10cSrcweir 
_Start(SwEditShell * pShell,SwDocPositions eStart,SwDocPositions eEnd)222cdf0e10cSrcweir void SwLinguIter::_Start( SwEditShell *pShell, SwDocPositions eStart,
223cdf0e10cSrcweir                             SwDocPositions eEnd )
224cdf0e10cSrcweir {
225cdf0e10cSrcweir 	// es fehlt: Sicherstellen der Reentrance, Locking
226cdf0e10cSrcweir 	if( pSh )
227cdf0e10cSrcweir 		return;
228cdf0e10cSrcweir 
229cdf0e10cSrcweir 	sal_Bool bSetCurr;
230cdf0e10cSrcweir 
231cdf0e10cSrcweir 	pSh = pShell;
232cdf0e10cSrcweir 
233cdf0e10cSrcweir 	SET_CURR_SHELL( pSh );
234cdf0e10cSrcweir 
235cdf0e10cSrcweir 	ASSERT( !pEnd, "LinguStart ohne End?");
236cdf0e10cSrcweir 
237cdf0e10cSrcweir 	SwPaM *pCrsr = pSh->GetCrsr();
238cdf0e10cSrcweir 
239cdf0e10cSrcweir 	// pStk->SetCurCrsr();
240cdf0e10cSrcweir //	if( pCrsr->HasMark() || pCrsr != pCrsr->GetNext() )
241cdf0e10cSrcweir 	if( pShell->HasSelection() || pCrsr != pCrsr->GetNext() )
242cdf0e10cSrcweir 	{
243cdf0e10cSrcweir 		bSetCurr = 0 != GetCurr();
244cdf0e10cSrcweir 		nCrsrCnt = pSh->GetCrsrCnt();
245cdf0e10cSrcweir 		if( pSh->IsTableMode() )
246cdf0e10cSrcweir 			pSh->TblCrsrToCursor();
247cdf0e10cSrcweir 
248cdf0e10cSrcweir 		pSh->Push();
249cdf0e10cSrcweir 		sal_uInt16 n;
250cdf0e10cSrcweir 		for( n = 0; n < nCrsrCnt; ++n )
251cdf0e10cSrcweir 		{
252cdf0e10cSrcweir 			pSh->Push();
253cdf0e10cSrcweir 			pSh->DestroyCrsr();
254cdf0e10cSrcweir 		}
255cdf0e10cSrcweir 		pSh->Pop( sal_False );
256cdf0e10cSrcweir 	}
257cdf0e10cSrcweir 	else
258cdf0e10cSrcweir 	{
259cdf0e10cSrcweir 		bSetCurr = sal_False;
260cdf0e10cSrcweir 		nCrsrCnt = 1;
261cdf0e10cSrcweir 		pSh->Push();
262cdf0e10cSrcweir 		pSh->SetLinguRange( eStart, eEnd );
263cdf0e10cSrcweir 	}
264cdf0e10cSrcweir 
265cdf0e10cSrcweir 	pCrsr = pSh->GetCrsr();
266cdf0e10cSrcweir 	if ( *pCrsr->GetPoint() > *pCrsr->GetMark() )
267cdf0e10cSrcweir 		pCrsr->Exchange();
268cdf0e10cSrcweir 
269cdf0e10cSrcweir 	pStart = new SwPosition( *pCrsr->GetPoint() );
270cdf0e10cSrcweir 	pEnd = new SwPosition( *pCrsr->GetMark() );
271cdf0e10cSrcweir 	if( bSetCurr )
272cdf0e10cSrcweir 	{
273cdf0e10cSrcweir         SwPosition* pNew = new SwPosition( *GetStart() );
274cdf0e10cSrcweir 		SetCurr( pNew );
275cdf0e10cSrcweir 		pNew = new SwPosition( *pNew );
276cdf0e10cSrcweir 		SetCurrX( pNew );
277cdf0e10cSrcweir 	}
278cdf0e10cSrcweir 
279cdf0e10cSrcweir 	pCrsr->SetMark();
280cdf0e10cSrcweir 
281cdf0e10cSrcweir 	pLinguFrm = 0;
282cdf0e10cSrcweir 	pLinguNode = 0;
283cdf0e10cSrcweir }
284cdf0e10cSrcweir 
285cdf0e10cSrcweir /*************************************************************************
286cdf0e10cSrcweir  *						SwLinguIter::End
287cdf0e10cSrcweir  *************************************************************************/
288cdf0e10cSrcweir 
289cdf0e10cSrcweir 
290cdf0e10cSrcweir 
_End(bool bRestoreSelection)291cdf0e10cSrcweir void SwLinguIter::_End(bool bRestoreSelection)
292cdf0e10cSrcweir {
293cdf0e10cSrcweir 	if( !pSh )
294cdf0e10cSrcweir 		return;
295cdf0e10cSrcweir 
296cdf0e10cSrcweir 	ASSERT( pEnd, "SwEditShell::SpellEnd() ohne Start?");
297cdf0e10cSrcweir     if(bRestoreSelection)
298cdf0e10cSrcweir     {
299cdf0e10cSrcweir         while( nCrsrCnt-- )
300cdf0e10cSrcweir 		    pSh->Pop( sal_False );
301cdf0e10cSrcweir 
302cdf0e10cSrcweir 	    pSh->KillPams();
303cdf0e10cSrcweir 	    pSh->ClearMark();
304cdf0e10cSrcweir     }
305cdf0e10cSrcweir 	DELETEZ(pStart);
306cdf0e10cSrcweir 	DELETEZ(pEnd);
307cdf0e10cSrcweir 	DELETEZ(pCurr);
308cdf0e10cSrcweir 	DELETEZ(pCurrX);
309cdf0e10cSrcweir 
310cdf0e10cSrcweir 	pSh = 0;
311cdf0e10cSrcweir 
312cdf0e10cSrcweir #ifdef LINGU_STATISTIK
313cdf0e10cSrcweir 	aSwLinguStat.Flush();
314cdf0e10cSrcweir #endif
315cdf0e10cSrcweir }
316cdf0e10cSrcweir 
317cdf0e10cSrcweir /*************************************************************************
318cdf0e10cSrcweir  *				 virtual SwSpellIter::Start()
319cdf0e10cSrcweir  *************************************************************************/
320cdf0e10cSrcweir 
321cdf0e10cSrcweir 
322cdf0e10cSrcweir 
Start(SwEditShell * pShell,SwDocPositions eStart,SwDocPositions eEnd)323cdf0e10cSrcweir void SwSpellIter::Start( SwEditShell *pShell, SwDocPositions eStart,
324cdf0e10cSrcweir 						SwDocPositions eEnd )
325cdf0e10cSrcweir {
326cdf0e10cSrcweir 	if( GetSh() )
327cdf0e10cSrcweir 		return;
328cdf0e10cSrcweir 
329cdf0e10cSrcweir  	uno::Reference< beans::XPropertySet >  xProp( ::GetLinguPropertySet() );
330cdf0e10cSrcweir 	xSpeller = ::GetSpellChecker();
331cdf0e10cSrcweir 	if ( xSpeller.is() )
332cdf0e10cSrcweir         _Start( pShell, eStart, eEnd );
333cdf0e10cSrcweir     aLastPortions.clear();
334cdf0e10cSrcweir     aLastPositions.clear();
335cdf0e10cSrcweir }
336cdf0e10cSrcweir 
337cdf0e10cSrcweir /*************************************************************************
338cdf0e10cSrcweir  *					 SwSpellIter::Continue
339cdf0e10cSrcweir  *************************************************************************/
340cdf0e10cSrcweir 
341cdf0e10cSrcweir // SwSpellIter::Continue ist das alte Original von
342cdf0e10cSrcweir // SwEditShell::SpellContinue()
343cdf0e10cSrcweir 
Continue(sal_uInt16 * pPageCnt,sal_uInt16 * pPageSt)344cdf0e10cSrcweir uno::Any SwSpellIter::Continue( sal_uInt16* pPageCnt, sal_uInt16* pPageSt )
345cdf0e10cSrcweir {
346cdf0e10cSrcweir     //!!
347cdf0e10cSrcweir     //!! Please check SwConvIter also when modifying this
348cdf0e10cSrcweir     //!!
349cdf0e10cSrcweir 
350cdf0e10cSrcweir     uno::Any    aSpellRet;
351cdf0e10cSrcweir     SwEditShell *pMySh = GetSh();
352cdf0e10cSrcweir     if( !pMySh )
353cdf0e10cSrcweir         return aSpellRet;
354cdf0e10cSrcweir 
355cdf0e10cSrcweir //	const SwPosition *pEnd = GetEnd();
356cdf0e10cSrcweir 
357cdf0e10cSrcweir 	ASSERT( GetEnd(), "SwEditShell::SpellContinue() ohne Start?");
358cdf0e10cSrcweir 
359cdf0e10cSrcweir     uno::Reference< uno::XInterface >  xSpellRet;
360cdf0e10cSrcweir 	sal_Bool bGoOn = sal_True;
361cdf0e10cSrcweir 	do {
362cdf0e10cSrcweir         SwPaM *pCrsr = pMySh->GetCrsr();
363cdf0e10cSrcweir 		if ( !pCrsr->HasMark() )
364cdf0e10cSrcweir 			pCrsr->SetMark();
365cdf0e10cSrcweir 
366cdf0e10cSrcweir 		uno::Reference< beans::XPropertySet >  xProp( GetLinguPropertySet() );
367cdf0e10cSrcweir         *pMySh->GetCrsr()->GetPoint() = *GetCurr();
368cdf0e10cSrcweir         *pMySh->GetCrsr()->GetMark() = *GetEnd();
369cdf0e10cSrcweir         pMySh->GetDoc()->Spell(*pMySh->GetCrsr(),
370cdf0e10cSrcweir                     xSpeller, pPageCnt, pPageSt, false ) >>= xSpellRet;
371cdf0e10cSrcweir 		bGoOn = GetCrsrCnt() > 1;
372cdf0e10cSrcweir 		if( xSpellRet.is() )
373cdf0e10cSrcweir 		{
374cdf0e10cSrcweir 			bGoOn = sal_False;
375cdf0e10cSrcweir 			SwPosition* pNewPoint = new SwPosition( *pCrsr->GetPoint() );
376cdf0e10cSrcweir 			SwPosition* pNewMark = new SwPosition( *pCrsr->GetMark() );
377cdf0e10cSrcweir             SetCurr( pNewPoint );
378cdf0e10cSrcweir             SetCurrX( pNewMark );
379cdf0e10cSrcweir 		}
380cdf0e10cSrcweir 		if( bGoOn )
381cdf0e10cSrcweir 		{
382cdf0e10cSrcweir             pMySh->Pop( sal_False );
383cdf0e10cSrcweir             pCrsr = pMySh->GetCrsr();
384cdf0e10cSrcweir 			if ( *pCrsr->GetPoint() > *pCrsr->GetMark() )
385cdf0e10cSrcweir 				pCrsr->Exchange();
386cdf0e10cSrcweir 			SwPosition* pNew = new SwPosition( *pCrsr->GetPoint() );
387cdf0e10cSrcweir 			SetStart( pNew );
388cdf0e10cSrcweir 			pNew = new SwPosition( *pCrsr->GetMark() );
389cdf0e10cSrcweir 			SetEnd( pNew );
390cdf0e10cSrcweir             pNew = new SwPosition( *GetStart() );
391cdf0e10cSrcweir 			SetCurr( pNew );
392cdf0e10cSrcweir 			pNew = new SwPosition( *pNew );
393cdf0e10cSrcweir 			SetCurrX( pNew );
394cdf0e10cSrcweir 			pCrsr->SetMark();
395cdf0e10cSrcweir 			--GetCrsrCnt();
396cdf0e10cSrcweir 		}
397cdf0e10cSrcweir 	}while ( bGoOn );
398cdf0e10cSrcweir     aSpellRet <<= xSpellRet;
399cdf0e10cSrcweir     return aSpellRet;
400cdf0e10cSrcweir }
401cdf0e10cSrcweir 
402cdf0e10cSrcweir /*************************************************************************
403cdf0e10cSrcweir  *               virtual SwConvIter::Start()
404cdf0e10cSrcweir  *************************************************************************/
405cdf0e10cSrcweir 
406cdf0e10cSrcweir 
407cdf0e10cSrcweir 
Start(SwEditShell * pShell,SwDocPositions eStart,SwDocPositions eEnd)408cdf0e10cSrcweir void SwConvIter::Start( SwEditShell *pShell, SwDocPositions eStart,
409cdf0e10cSrcweir                         SwDocPositions eEnd )
410cdf0e10cSrcweir {
411cdf0e10cSrcweir     if( GetSh() )
412cdf0e10cSrcweir         return;
413cdf0e10cSrcweir     _Start( pShell, eStart, eEnd );
414cdf0e10cSrcweir }
415cdf0e10cSrcweir 
416cdf0e10cSrcweir /*************************************************************************
417cdf0e10cSrcweir  *                   SwConvIter::Continue
418cdf0e10cSrcweir  *************************************************************************/
419cdf0e10cSrcweir 
Continue(sal_uInt16 * pPageCnt,sal_uInt16 * pPageSt)420cdf0e10cSrcweir uno::Any SwConvIter::Continue( sal_uInt16* pPageCnt, sal_uInt16* pPageSt )
421cdf0e10cSrcweir {
422cdf0e10cSrcweir     //!!
423cdf0e10cSrcweir     //!! Please check SwSpellIter also when modifying this
424cdf0e10cSrcweir     //!!
425cdf0e10cSrcweir 
426cdf0e10cSrcweir     uno::Any    aConvRet( makeAny( rtl::OUString() ) );
427cdf0e10cSrcweir     SwEditShell *pMySh = GetSh();
428cdf0e10cSrcweir     if( !pMySh )
429cdf0e10cSrcweir         return aConvRet;
430cdf0e10cSrcweir 
431cdf0e10cSrcweir //  const SwPosition *pEnd = GetEnd();
432cdf0e10cSrcweir 
433cdf0e10cSrcweir     ASSERT( GetEnd(), "SwConvIter::Continue() ohne Start?");
434cdf0e10cSrcweir 
435cdf0e10cSrcweir     rtl::OUString aConvText;
436cdf0e10cSrcweir     sal_Bool bGoOn = sal_True;
437cdf0e10cSrcweir     do {
438cdf0e10cSrcweir         SwPaM *pCrsr = pMySh->GetCrsr();
439cdf0e10cSrcweir         if ( !pCrsr->HasMark() )
440cdf0e10cSrcweir             pCrsr->SetMark();
441cdf0e10cSrcweir 
442cdf0e10cSrcweir         *pMySh->GetCrsr()->GetPoint() = *GetCurr();
443cdf0e10cSrcweir         *pMySh->GetCrsr()->GetMark() = *GetEnd();
444cdf0e10cSrcweir 
445cdf0e10cSrcweir         // call function to find next text portion to be converted
446cdf0e10cSrcweir         uno::Reference< linguistic2::XSpellChecker1 > xEmpty;
447cdf0e10cSrcweir         pMySh->GetDoc()->Spell( *pMySh->GetCrsr(),
448cdf0e10cSrcweir                     xEmpty, pPageCnt, pPageSt, false, &rArgs ) >>= aConvText;
449cdf0e10cSrcweir 
450cdf0e10cSrcweir         bGoOn = GetCrsrCnt() > 1;
451cdf0e10cSrcweir         if( aConvText.getLength() )
452cdf0e10cSrcweir         {
453cdf0e10cSrcweir             bGoOn = sal_False;
454cdf0e10cSrcweir             SwPosition* pNewPoint = new SwPosition( *pCrsr->GetPoint() );
455cdf0e10cSrcweir             SwPosition* pNewMark = new SwPosition( *pCrsr->GetMark() );
456cdf0e10cSrcweir 
457cdf0e10cSrcweir             SetCurr( pNewPoint );
458cdf0e10cSrcweir             SetCurrX( pNewMark );
459cdf0e10cSrcweir         }
460cdf0e10cSrcweir         if( bGoOn )
461cdf0e10cSrcweir         {
462cdf0e10cSrcweir             pMySh->Pop( sal_False );
463cdf0e10cSrcweir             pCrsr = pMySh->GetCrsr();
464cdf0e10cSrcweir             if ( *pCrsr->GetPoint() > *pCrsr->GetMark() )
465cdf0e10cSrcweir                 pCrsr->Exchange();
466cdf0e10cSrcweir             SwPosition* pNew = new SwPosition( *pCrsr->GetPoint() );
467cdf0e10cSrcweir             SetStart( pNew );
468cdf0e10cSrcweir             pNew = new SwPosition( *pCrsr->GetMark() );
469cdf0e10cSrcweir             SetEnd( pNew );
470cdf0e10cSrcweir             pNew = new SwPosition( *GetStart() );
471cdf0e10cSrcweir             SetCurr( pNew );
472cdf0e10cSrcweir             pNew = new SwPosition( *pNew );
473cdf0e10cSrcweir             SetCurrX( pNew );
474cdf0e10cSrcweir             pCrsr->SetMark();
475cdf0e10cSrcweir             --GetCrsrCnt();
476cdf0e10cSrcweir         }
477cdf0e10cSrcweir     }while ( bGoOn );
478cdf0e10cSrcweir     return makeAny( aConvText );
479cdf0e10cSrcweir }
480cdf0e10cSrcweir 
481cdf0e10cSrcweir 
482cdf0e10cSrcweir /*************************************************************************
483cdf0e10cSrcweir  *                   SwHyphIter
484cdf0e10cSrcweir  *************************************************************************/
485cdf0e10cSrcweir 
486cdf0e10cSrcweir 
IsAuto()487cdf0e10cSrcweir sal_Bool SwHyphIter::IsAuto()
488cdf0e10cSrcweir {
489cdf0e10cSrcweir 	uno::Reference< beans::XPropertySet >  xProp( ::GetLinguPropertySet() );
490cdf0e10cSrcweir 	return xProp.is() ? *(sal_Bool*)xProp->getPropertyValue(
491cdf0e10cSrcweir                                 C2U(UPN_IS_HYPH_AUTO) ).getValue()
492cdf0e10cSrcweir 					  : sal_False;
493cdf0e10cSrcweir }
494cdf0e10cSrcweir 
495cdf0e10cSrcweir 
ShowSelection()496cdf0e10cSrcweir void SwHyphIter::ShowSelection()
497cdf0e10cSrcweir {
498cdf0e10cSrcweir     SwEditShell *pMySh = GetSh();
499cdf0e10cSrcweir     if( pMySh )
500cdf0e10cSrcweir 	{
501cdf0e10cSrcweir         pMySh->StartAction();
502cdf0e10cSrcweir 		// Ganz fatal: durch das EndAction() werden Formatierungen
503cdf0e10cSrcweir 		// angeregt, die dazu fuehren koennen, dass im Hyphenator
504cdf0e10cSrcweir 		// neue Worte eingestellt werden. Deswegen sichern!
505cdf0e10cSrcweir         pMySh->EndAction();
506cdf0e10cSrcweir 	}
507cdf0e10cSrcweir }
508cdf0e10cSrcweir 
509cdf0e10cSrcweir /*************************************************************************
510cdf0e10cSrcweir  *				 virtual SwHyphIter::Start()
511cdf0e10cSrcweir  *************************************************************************/
512cdf0e10cSrcweir 
513cdf0e10cSrcweir 
514cdf0e10cSrcweir 
Start(SwEditShell * pShell,SwDocPositions eStart,SwDocPositions eEnd)515cdf0e10cSrcweir void SwHyphIter::Start( SwEditShell *pShell, SwDocPositions eStart, SwDocPositions eEnd )
516cdf0e10cSrcweir {
517cdf0e10cSrcweir 	// robust
518cdf0e10cSrcweir 	if( GetSh() || GetEnd() )
519cdf0e10cSrcweir 	{
520cdf0e10cSrcweir 		ASSERT( !GetSh(), "+SwEditShell::HyphStart: missing HyphEnd()" );
521cdf0e10cSrcweir 		return;
522cdf0e10cSrcweir 	}
523cdf0e10cSrcweir 
524cdf0e10cSrcweir // nothing to be done (at least not in the way as in the "else" part)
525cdf0e10cSrcweir 	bOldIdle = pShell->GetViewOptions()->IsIdle();
526cdf0e10cSrcweir 	((SwViewOption*)pShell->GetViewOptions())->SetIdle( sal_False );
527cdf0e10cSrcweir 	_Start( pShell, eStart, eEnd );
528cdf0e10cSrcweir }
529cdf0e10cSrcweir 
530cdf0e10cSrcweir /*************************************************************************
531cdf0e10cSrcweir  *				   virtual SwHyphIter::End
532cdf0e10cSrcweir  *************************************************************************/
533cdf0e10cSrcweir 
534cdf0e10cSrcweir // Selektionen wiederherstellen
535cdf0e10cSrcweir 
536cdf0e10cSrcweir 
537cdf0e10cSrcweir 
End()538cdf0e10cSrcweir void SwHyphIter::End()
539cdf0e10cSrcweir {
540cdf0e10cSrcweir 	if( !GetSh() )
541cdf0e10cSrcweir 		return;
542cdf0e10cSrcweir 	((SwViewOption*)GetSh()->GetViewOptions())->SetIdle( bOldIdle );
543cdf0e10cSrcweir 	_End();
544cdf0e10cSrcweir }
545cdf0e10cSrcweir 
546cdf0e10cSrcweir /*************************************************************************
547cdf0e10cSrcweir  *					 SwHyphIter::Continue
548cdf0e10cSrcweir  *************************************************************************/
549cdf0e10cSrcweir 
Continue(sal_uInt16 * pPageCnt,sal_uInt16 * pPageSt)550cdf0e10cSrcweir uno::Any SwHyphIter::Continue( sal_uInt16* pPageCnt, sal_uInt16* pPageSt )
551cdf0e10cSrcweir {
552cdf0e10cSrcweir     uno::Any    aHyphRet;
553cdf0e10cSrcweir     SwEditShell *pMySh = GetSh();
554cdf0e10cSrcweir     if( !pMySh )
555cdf0e10cSrcweir         return aHyphRet;
556cdf0e10cSrcweir 
557cdf0e10cSrcweir 	const sal_Bool bAuto = IsAuto();
558cdf0e10cSrcweir 	 uno::Reference< XHyphenatedWord >  xHyphWord;
559cdf0e10cSrcweir 	sal_uInt16 nRet;
560cdf0e10cSrcweir 	sal_Bool bGoOn = sal_False;
561cdf0e10cSrcweir 	do {
562cdf0e10cSrcweir 		SwPaM *pCrsr;
563cdf0e10cSrcweir 		do {
564cdf0e10cSrcweir 			ASSERT( GetEnd(), "SwEditShell::SpellContinue() ohne Start?" );
565cdf0e10cSrcweir             pCrsr = pMySh->GetCrsr();
566cdf0e10cSrcweir 			if ( !pCrsr->HasMark() )
567cdf0e10cSrcweir 				pCrsr->SetMark();
568cdf0e10cSrcweir 			if ( *pCrsr->GetPoint() < *pCrsr->GetMark() )
569cdf0e10cSrcweir 			{
570cdf0e10cSrcweir 				pCrsr->Exchange();
571cdf0e10cSrcweir 				pCrsr->SetMark();
572cdf0e10cSrcweir 			}
573cdf0e10cSrcweir 
574cdf0e10cSrcweir 			// geraten BUG:
575cdf0e10cSrcweir 			if ( *pCrsr->End() > *GetEnd() )
576cdf0e10cSrcweir 				nRet = 0;
577cdf0e10cSrcweir 			else
578cdf0e10cSrcweir 			{
579cdf0e10cSrcweir 				*pCrsr->GetMark() = *GetEnd();
580cdf0e10cSrcweir 
581cdf0e10cSrcweir 				// Muss an der aktuellen Cursorpos das Wort getrennt werden ?
582cdf0e10cSrcweir                 const Point aCrsrPos( pMySh->GetCharRect().Pos() );
583cdf0e10cSrcweir                 xHyphWord = pMySh->GetDoc()->Hyphenate( pCrsr, aCrsrPos,
584cdf0e10cSrcweir 						 							  pPageCnt, pPageSt );
585cdf0e10cSrcweir 			}
586cdf0e10cSrcweir 
587cdf0e10cSrcweir 			if( bAuto && xHyphWord.is() )
588cdf0e10cSrcweir 			{
589cdf0e10cSrcweir                 pMySh->InsertSoftHyph( xHyphWord->getHyphenationPos() + 1);
590cdf0e10cSrcweir 			}
591cdf0e10cSrcweir 		} while( bAuto && xHyphWord.is() );	//end of do-while
592cdf0e10cSrcweir 		bGoOn = !xHyphWord.is() && GetCrsrCnt() > 1;
593cdf0e10cSrcweir 
594cdf0e10cSrcweir 		if( bGoOn )
595cdf0e10cSrcweir 		{
596cdf0e10cSrcweir             pMySh->Pop( sal_False );
597cdf0e10cSrcweir             pCrsr = pMySh->GetCrsr();
598cdf0e10cSrcweir 			if ( *pCrsr->GetPoint() > *pCrsr->GetMark() )
599cdf0e10cSrcweir 				pCrsr->Exchange();
600cdf0e10cSrcweir 			SwPosition* pNew = new SwPosition(*pCrsr->End());
601cdf0e10cSrcweir 			SetEnd( pNew );
602cdf0e10cSrcweir 			pCrsr->SetMark();
603cdf0e10cSrcweir 			--GetCrsrCnt();
604cdf0e10cSrcweir 		}
605cdf0e10cSrcweir 	} while ( bGoOn );
606cdf0e10cSrcweir     aHyphRet <<= xHyphWord;
607cdf0e10cSrcweir     return aHyphRet;
608cdf0e10cSrcweir }
609cdf0e10cSrcweir 
610cdf0e10cSrcweir /*************************************************************************
611cdf0e10cSrcweir  *					SwHyphIter::HyphIgnore
612cdf0e10cSrcweir  *************************************************************************/
613cdf0e10cSrcweir 
614cdf0e10cSrcweir // Beschreibung: Trennstelle ignorieren
615cdf0e10cSrcweir 
Ignore()616cdf0e10cSrcweir void SwHyphIter::Ignore()
617cdf0e10cSrcweir {
618cdf0e10cSrcweir     SwEditShell *pMySh = GetSh();
619cdf0e10cSrcweir     SwPaM *pCrsr = pMySh->GetCrsr();
620cdf0e10cSrcweir 
621cdf0e10cSrcweir 	// Alten SoftHyphen loeschen
622cdf0e10cSrcweir 	DelSoftHyph( *pCrsr );
623cdf0e10cSrcweir 
624cdf0e10cSrcweir 	// und weiter
625cdf0e10cSrcweir 	pCrsr->Start()->nContent = pCrsr->End()->nContent;
626cdf0e10cSrcweir 	pCrsr->SetMark();
627cdf0e10cSrcweir }
628cdf0e10cSrcweir 
629cdf0e10cSrcweir /*************************************************************************
630cdf0e10cSrcweir  *						  SwHyphIter::DelSoftHyph
631cdf0e10cSrcweir  *************************************************************************/
632cdf0e10cSrcweir 
DelSoftHyph(SwPaM & rPam)633cdf0e10cSrcweir void SwHyphIter::DelSoftHyph( SwPaM &rPam )
634cdf0e10cSrcweir {
635cdf0e10cSrcweir 	const SwPosition* pStt = rPam.Start();
636cdf0e10cSrcweir 	const xub_StrLen nStart = pStt->nContent.GetIndex();
637cdf0e10cSrcweir 	const xub_StrLen nEnd   = rPam.End()->nContent.GetIndex();
638cdf0e10cSrcweir 	SwTxtNode *pNode = pStt->nNode.GetNode().GetTxtNode();
639cdf0e10cSrcweir 	pNode->DelSoftHyph( nStart, nEnd );
640cdf0e10cSrcweir }
641cdf0e10cSrcweir 
642cdf0e10cSrcweir /*************************************************************************
643cdf0e10cSrcweir  *					SwHyphIter::InsertSoftHyph
644cdf0e10cSrcweir  *************************************************************************/
645cdf0e10cSrcweir 
646cdf0e10cSrcweir 
InsertSoftHyph(const xub_StrLen nHyphPos)647cdf0e10cSrcweir void SwHyphIter::InsertSoftHyph( const xub_StrLen nHyphPos )
648cdf0e10cSrcweir {
649cdf0e10cSrcweir     SwEditShell *pMySh = GetSh();
650cdf0e10cSrcweir     ASSERT( pMySh,  "+SwEditShell::InsertSoftHyph: missing HyphStart()");
651cdf0e10cSrcweir     if( !pMySh )
652cdf0e10cSrcweir 		return;
653cdf0e10cSrcweir 
654cdf0e10cSrcweir     SwPaM *pCrsr = pMySh->GetCrsr();
655cdf0e10cSrcweir     SwPosition* pSttPos = pCrsr->Start();
656cdf0e10cSrcweir     SwPosition* pEndPos = pCrsr->End();
657cdf0e10cSrcweir 
658cdf0e10cSrcweir 	xub_StrLen nLastHyphLen = GetEnd()->nContent.GetIndex() -
659cdf0e10cSrcweir                           pSttPos->nContent.GetIndex();
660cdf0e10cSrcweir 
661cdf0e10cSrcweir     if( pSttPos->nNode != pEndPos->nNode || !nLastHyphLen )
662cdf0e10cSrcweir 	{
663cdf0e10cSrcweir         ASSERT( pSttPos->nNode == pEndPos->nNode,
664cdf0e10cSrcweir 				"+SwEditShell::InsertSoftHyph: node warp during hyphenation" );
665cdf0e10cSrcweir 		ASSERT(nLastHyphLen, "+SwEditShell::InsertSoftHyph: missing HyphContinue()");
666cdf0e10cSrcweir         *pSttPos = *pEndPos;
667cdf0e10cSrcweir 		return;
668cdf0e10cSrcweir 	}
669cdf0e10cSrcweir 
670cdf0e10cSrcweir     pMySh->StartAction();
671cdf0e10cSrcweir 	{
672cdf0e10cSrcweir         SwDoc *pDoc = pMySh->GetDoc();
673cdf0e10cSrcweir 		DelSoftHyph( *pCrsr );
674cdf0e10cSrcweir         pSttPos->nContent += nHyphPos;
675cdf0e10cSrcweir         SwPaM aRg( *pSttPos );
676cdf0e10cSrcweir         pDoc->InsertString( aRg, CHAR_SOFTHYPHEN );
677cdf0e10cSrcweir 		// Durch das Einfuegen des SoftHyphs ist ein Zeichen hinzugekommen
678cdf0e10cSrcweir //JP 18.07.95: warum, ist doch ein SwIndex, dieser wird doch mitverschoben !!
679cdf0e10cSrcweir //        pSttPos->nContent++;
680cdf0e10cSrcweir 	}
681cdf0e10cSrcweir 	// Die Selektion wird wieder aufgehoben
682cdf0e10cSrcweir 	pCrsr->DeleteMark();
683cdf0e10cSrcweir     pMySh->EndAction();
684cdf0e10cSrcweir 	pCrsr->SetMark();
685cdf0e10cSrcweir }
686cdf0e10cSrcweir 
687cdf0e10cSrcweir // --------------------- Methoden der SwEditShell ------------------------
688cdf0e10cSrcweir 
HasLastSentenceGotGrammarChecked() const689cdf0e10cSrcweir bool SwEditShell::HasLastSentenceGotGrammarChecked() const
690cdf0e10cSrcweir {
691cdf0e10cSrcweir     bool bTextWasGrammarChecked = false;
692cdf0e10cSrcweir     if (pSpellIter)
693cdf0e10cSrcweir     {
694cdf0e10cSrcweir         ::svx::SpellPortions aLastPortions( pSpellIter->GetLastPortions() );
695cdf0e10cSrcweir         for (size_t i = 0;  i < aLastPortions.size() && !bTextWasGrammarChecked;  ++i)
696cdf0e10cSrcweir         {
697cdf0e10cSrcweir             // bIsGrammarError is also true if the text was only checked but no
698cdf0e10cSrcweir             // grammar error was found. (That is if a ProofreadingResult was obtained in
699cdf0e10cSrcweir             // SwDoc::Spell and in turn bIsGrammarError was set in SwSpellIter::CreatePortion)
700cdf0e10cSrcweir             if (aLastPortions[i].bIsGrammarError)
701cdf0e10cSrcweir                 bTextWasGrammarChecked = true;
702cdf0e10cSrcweir         }
703cdf0e10cSrcweir     }
704cdf0e10cSrcweir     return bTextWasGrammarChecked;
705cdf0e10cSrcweir }
706cdf0e10cSrcweir 
707cdf0e10cSrcweir /*************************************************************************
708cdf0e10cSrcweir  *                      SwEditShell::HasConvIter
709cdf0e10cSrcweir  *************************************************************************/
710cdf0e10cSrcweir 
HasConvIter() const711cdf0e10cSrcweir sal_Bool SwEditShell::HasConvIter() const
712cdf0e10cSrcweir {
713cdf0e10cSrcweir     return 0 != pConvIter;
714cdf0e10cSrcweir }
715cdf0e10cSrcweir 
716cdf0e10cSrcweir /*************************************************************************
717cdf0e10cSrcweir  *                      SwEditShell::HasHyphIter
718cdf0e10cSrcweir  *************************************************************************/
719cdf0e10cSrcweir 
HasHyphIter() const720cdf0e10cSrcweir sal_Bool SwEditShell::HasHyphIter() const
721cdf0e10cSrcweir {
722cdf0e10cSrcweir 	return 0 != pHyphIter;
723cdf0e10cSrcweir }
724cdf0e10cSrcweir 
725cdf0e10cSrcweir /*************************************************************************
726cdf0e10cSrcweir  *                      SwEditShell::SetFindRange
727cdf0e10cSrcweir  *************************************************************************/
728cdf0e10cSrcweir 
SetLinguRange(SwDocPositions eStart,SwDocPositions eEnd)729cdf0e10cSrcweir void SwEditShell::SetLinguRange( SwDocPositions eStart, SwDocPositions eEnd )
730cdf0e10cSrcweir {
731cdf0e10cSrcweir 	SwPaM *pCrsr = GetCrsr();
732cdf0e10cSrcweir 	MakeFindRange( static_cast<sal_uInt16>(eStart), static_cast<sal_uInt16>(eEnd), pCrsr );
733cdf0e10cSrcweir 	if( *pCrsr->GetPoint() > *pCrsr->GetMark() )
734cdf0e10cSrcweir 		pCrsr->Exchange();
735cdf0e10cSrcweir }
736cdf0e10cSrcweir 
737cdf0e10cSrcweir /*************************************************************************
738cdf0e10cSrcweir  *                  SwEditShell::SpellStart
739cdf0e10cSrcweir  *************************************************************************/
740cdf0e10cSrcweir 
SpellStart(SwDocPositions eStart,SwDocPositions eEnd,SwDocPositions eCurr,SwConversionArgs * pConvArgs)741cdf0e10cSrcweir void SwEditShell::SpellStart(
742cdf0e10cSrcweir         SwDocPositions eStart, SwDocPositions eEnd, SwDocPositions eCurr,
743cdf0e10cSrcweir         SwConversionArgs *pConvArgs )
744cdf0e10cSrcweir {
745cdf0e10cSrcweir     SwLinguIter *pLinguIter = 0;
746cdf0e10cSrcweir 
747cdf0e10cSrcweir 	// do not spell if interactive spelling is active elsewhere
748cdf0e10cSrcweir     if (!pConvArgs && !pSpellIter)
749cdf0e10cSrcweir 	{
750cdf0e10cSrcweir 		ASSERT( !pSpellIter, "wer ist da schon am spellen?" );
751cdf0e10cSrcweir 		pSpellIter = new SwSpellIter;
752cdf0e10cSrcweir         pLinguIter = pSpellIter;
753cdf0e10cSrcweir 	}
754cdf0e10cSrcweir     // do not do text conversion if it is active elsewhere
755cdf0e10cSrcweir     if (pConvArgs && !pConvIter)
756cdf0e10cSrcweir     {
757cdf0e10cSrcweir         ASSERT( !pConvIter, "text conversion already active!" );
758cdf0e10cSrcweir         pConvIter = new SwConvIter( *pConvArgs );
759cdf0e10cSrcweir         pLinguIter = pConvIter;
760cdf0e10cSrcweir     }
761cdf0e10cSrcweir 
762cdf0e10cSrcweir     if (pLinguIter)
763cdf0e10cSrcweir     {
764cdf0e10cSrcweir         SwCursor* pSwCrsr = GetSwCrsr();
765cdf0e10cSrcweir 
766cdf0e10cSrcweir         SwPosition *pTmp = new SwPosition( *pSwCrsr->GetPoint() );
767cdf0e10cSrcweir         pSwCrsr->FillFindPos( eCurr, *pTmp );
768cdf0e10cSrcweir         pLinguIter->SetCurr( pTmp );
769cdf0e10cSrcweir 
770cdf0e10cSrcweir         pTmp = new SwPosition( *pTmp );
771cdf0e10cSrcweir         pLinguIter->SetCurrX( pTmp );
772cdf0e10cSrcweir     }
773cdf0e10cSrcweir 
774cdf0e10cSrcweir     if (!pConvArgs && pSpellIter)
775cdf0e10cSrcweir         pSpellIter->Start( this, eStart, eEnd );
776cdf0e10cSrcweir     if (pConvArgs && pConvIter)
777cdf0e10cSrcweir         pConvIter->Start( this, eStart, eEnd );
778cdf0e10cSrcweir }
779cdf0e10cSrcweir 
780cdf0e10cSrcweir /*************************************************************************
781cdf0e10cSrcweir  *                  SwEditShell::SpellEnd
782cdf0e10cSrcweir  *************************************************************************/
783cdf0e10cSrcweir 
SpellEnd(SwConversionArgs * pConvArgs,bool bRestoreSelection)784cdf0e10cSrcweir void SwEditShell::SpellEnd( SwConversionArgs *pConvArgs, bool bRestoreSelection )
785cdf0e10cSrcweir {
786cdf0e10cSrcweir     if (!pConvArgs && pSpellIter && pSpellIter->GetSh() == this)
787cdf0e10cSrcweir 	{
788cdf0e10cSrcweir 		ASSERT( pSpellIter, "wo ist mein Iterator?" );
789cdf0e10cSrcweir 		pSpellIter->_End(bRestoreSelection);
790cdf0e10cSrcweir 		delete pSpellIter, pSpellIter = 0;
791cdf0e10cSrcweir 	}
792cdf0e10cSrcweir     if (pConvArgs && pConvIter && pConvIter->GetSh() == this)
793cdf0e10cSrcweir     {
794cdf0e10cSrcweir         ASSERT( pConvIter, "wo ist mein Iterator?" );
795cdf0e10cSrcweir         pConvIter->_End();
796cdf0e10cSrcweir         delete pConvIter, pConvIter = 0;
797cdf0e10cSrcweir     }
798cdf0e10cSrcweir }
799cdf0e10cSrcweir 
800cdf0e10cSrcweir /*************************************************************************
801cdf0e10cSrcweir  *                  SwEditShell::SpellContinue
802cdf0e10cSrcweir  *************************************************************************/
803cdf0e10cSrcweir 
804cdf0e10cSrcweir // liefert Rueckgabewerte entsprechend SPL_ in splchk.hxx
805cdf0e10cSrcweir 
SpellContinue(sal_uInt16 * pPageCnt,sal_uInt16 * pPageSt,SwConversionArgs * pConvArgs)806cdf0e10cSrcweir uno::Any SwEditShell::SpellContinue(
807cdf0e10cSrcweir         sal_uInt16* pPageCnt, sal_uInt16* pPageSt,
808cdf0e10cSrcweir         SwConversionArgs *pConvArgs )
809cdf0e10cSrcweir {
810cdf0e10cSrcweir     uno::Any aRes;
811cdf0e10cSrcweir 
812cdf0e10cSrcweir     if ((!pConvArgs && pSpellIter->GetSh() != this) ||
813cdf0e10cSrcweir         ( pConvArgs && pConvIter->GetSh() != this))
814cdf0e10cSrcweir         return aRes;
815cdf0e10cSrcweir 
816cdf0e10cSrcweir 	if( pPageCnt && !*pPageCnt )
817cdf0e10cSrcweir 	{
818cdf0e10cSrcweir 		sal_uInt16 nEndPage = GetLayout()->GetPageNum();
819cdf0e10cSrcweir 		nEndPage += nEndPage * 10 / 100;
820cdf0e10cSrcweir 		*pPageCnt = nEndPage;
821cdf0e10cSrcweir 		if( nEndPage )
822cdf0e10cSrcweir 			::StartProgress( STR_STATSTR_SPELL, 0, nEndPage, GetDoc()->GetDocShell() );
823cdf0e10cSrcweir 	}
824cdf0e10cSrcweir 
825cdf0e10cSrcweir     ASSERT(  pConvArgs || pSpellIter, "SpellIter missing" );
826cdf0e10cSrcweir     ASSERT( !pConvArgs || pConvIter,  "ConvIter missing" );
827cdf0e10cSrcweir 	//JP 18.07.95: verhinder bei Fehlermeldungen die Anzeige der Selektionen
828cdf0e10cSrcweir 	//				KEIN StartAction, da damit auch die Paints abgeschaltet
829cdf0e10cSrcweir 	//				werden !!!!!
830cdf0e10cSrcweir 	++nStartAction;
831cdf0e10cSrcweir     rtl::OUString aRet;
832cdf0e10cSrcweir     uno::Reference< uno::XInterface >  xRet;
833cdf0e10cSrcweir     if (pConvArgs)
834cdf0e10cSrcweir     {
835cdf0e10cSrcweir         pConvIter->Continue( pPageCnt, pPageSt ) >>= aRet;
836cdf0e10cSrcweir         aRes <<= aRet;
837cdf0e10cSrcweir     }
838cdf0e10cSrcweir     else
839cdf0e10cSrcweir     {
840cdf0e10cSrcweir         pSpellIter->Continue( pPageCnt, pPageSt ) >>= xRet;
841cdf0e10cSrcweir         aRes <<= xRet;
842cdf0e10cSrcweir     }
843cdf0e10cSrcweir 	--nStartAction;
844cdf0e10cSrcweir 
845cdf0e10cSrcweir     if( aRet.getLength() || xRet.is() )
846cdf0e10cSrcweir 	{
847cdf0e10cSrcweir 		// dann die awt::Selection sichtbar machen
848cdf0e10cSrcweir 		StartAction();
849cdf0e10cSrcweir 		EndAction();
850cdf0e10cSrcweir 	}
851cdf0e10cSrcweir     return aRes;
852cdf0e10cSrcweir }
853cdf0e10cSrcweir /*************************************************************************
854cdf0e10cSrcweir  *					SwEditShell::HyphStart
855cdf0e10cSrcweir  *************************************************************************/
856cdf0e10cSrcweir 
857cdf0e10cSrcweir /* Interaktive Trennung, BP 10.03.93
858cdf0e10cSrcweir  *
859cdf0e10cSrcweir  * 1) HyphStart
860cdf0e10cSrcweir  *    - Aufheben aller Selektionen
861cdf0e10cSrcweir  *    - Sichern des aktuellen Cursors
862cdf0e10cSrcweir  *	  - falls keine Selektion vorhanden:
863cdf0e10cSrcweir  *		- neue Selektion bis zum Dokumentende
864cdf0e10cSrcweir  * 2) HyphContinue
865cdf0e10cSrcweir  *	  - nLastHyphLen wird auf den Selektionsstart addiert
866cdf0e10cSrcweir  *	  - iteriert ueber alle selektierten Bereiche
867cdf0e10cSrcweir  *		- pDoc->Hyphenate() iteriert ueber alle Nodes der Selektion
868cdf0e10cSrcweir  *			- pTxtNode->Hyphenate() ruft das SwTxtFrm::Hyphenate zur EditShell
869cdf0e10cSrcweir  *				- SwTxtFrm:Hyphenate() iteriert ueber die Zeilen des Pams
870cdf0e10cSrcweir  *					- LineIter::Hyphenate() stellt den Hyphenator
871cdf0e10cSrcweir  *					  und den Pam auf das zu trennende Wort ein.
872cdf0e10cSrcweir  *	  - Es gibt nur zwei Returnwerte sal_True, wenn eine Trennstelle anliegt
873cdf0e10cSrcweir  *		und sal_False, wenn der Pam abgearbeitet wurde.
874cdf0e10cSrcweir  *	  - Bei sal_True wird das selektierte Wort zur Anzeige gebracht und
875cdf0e10cSrcweir  *		nLastHyphLen gesetzt.
876cdf0e10cSrcweir  *	  - Bei sal_False wird die aktuelle Selektion geloescht und die naechste
877cdf0e10cSrcweir  *		zur aktuellen gewaehlt. Return HYPH_OK, wenn keine mehr vorhanden.
878cdf0e10cSrcweir  * 3) InsertSoftHyph (wird ggf. von der UI gerufen)
879cdf0e10cSrcweir  *	  - Der aktuelle Cursor wird plaziert und das Attribut eingefuegt.
880cdf0e10cSrcweir  * 4) HyphEnd
881cdf0e10cSrcweir  *	  - Wiederherstellen des alten Cursors, EndAction
882cdf0e10cSrcweir  */
883cdf0e10cSrcweir 
884cdf0e10cSrcweir 
885cdf0e10cSrcweir 
HyphStart(SwDocPositions eStart,SwDocPositions eEnd)886cdf0e10cSrcweir void SwEditShell::HyphStart( SwDocPositions eStart, SwDocPositions eEnd )
887cdf0e10cSrcweir {
888cdf0e10cSrcweir 	// do not hyphenate if interactive hyphenationg is active elsewhere
889cdf0e10cSrcweir 	if (!pHyphIter)
890cdf0e10cSrcweir 	{
891cdf0e10cSrcweir 		ASSERT( !pHyphIter, "wer ist da schon am hyphinieren?" );
892cdf0e10cSrcweir 		pHyphIter = new SwHyphIter;
893cdf0e10cSrcweir 		pHyphIter->Start( this, eStart, eEnd );
894cdf0e10cSrcweir 	}
895cdf0e10cSrcweir }
896cdf0e10cSrcweir 
897cdf0e10cSrcweir /*************************************************************************
898cdf0e10cSrcweir  *					SwEditShell::HyphEnd
899cdf0e10cSrcweir  *************************************************************************/
900cdf0e10cSrcweir 
901cdf0e10cSrcweir // Selektionen wiederherstellen
902cdf0e10cSrcweir 
903cdf0e10cSrcweir 
904cdf0e10cSrcweir 
HyphEnd()905cdf0e10cSrcweir void SwEditShell::HyphEnd()
906cdf0e10cSrcweir {
907cdf0e10cSrcweir 	if (pHyphIter->GetSh() == this)
908cdf0e10cSrcweir 	{
909cdf0e10cSrcweir 		ASSERT( pHyphIter, "wo ist mein Iterator?" );
910cdf0e10cSrcweir 		pHyphIter->End();
911cdf0e10cSrcweir 		delete pHyphIter, pHyphIter = 0;
912cdf0e10cSrcweir 	}
913cdf0e10cSrcweir }
914cdf0e10cSrcweir 
915cdf0e10cSrcweir /*************************************************************************
916cdf0e10cSrcweir  *					SwEditShell::HyphContinue
917cdf0e10cSrcweir  *************************************************************************/
918cdf0e10cSrcweir 
919cdf0e10cSrcweir // Returnwerte: (BP: ich wuerde es genau umdrehen, aber die UI wuenscht es so)
920cdf0e10cSrcweir // HYPH_CONTINUE, wenn eine Trennstelle anliegt
921cdf0e10cSrcweir // HYPH_OK, wenn der selektierte Bereich abgearbeitet wurde.
922cdf0e10cSrcweir 
923cdf0e10cSrcweir 
924cdf0e10cSrcweir uno::Reference< uno::XInterface >
HyphContinue(sal_uInt16 * pPageCnt,sal_uInt16 * pPageSt)925cdf0e10cSrcweir 	SwEditShell::HyphContinue( sal_uInt16* pPageCnt, sal_uInt16* pPageSt )
926cdf0e10cSrcweir {
927cdf0e10cSrcweir 	if (pHyphIter->GetSh() != this)
928cdf0e10cSrcweir 		return 0;
929cdf0e10cSrcweir 
930cdf0e10cSrcweir 	if( pPageCnt && !*pPageCnt && !*pPageSt )
931cdf0e10cSrcweir 	{
932cdf0e10cSrcweir 		sal_uInt16 nEndPage = GetLayout()->GetPageNum();
933cdf0e10cSrcweir 		nEndPage += nEndPage * 10 / 100;
934cdf0e10cSrcweir 		if( nEndPage > 14 )
935cdf0e10cSrcweir 		{
936cdf0e10cSrcweir 			*pPageCnt = nEndPage;
937cdf0e10cSrcweir 			::StartProgress( STR_STATSTR_HYPHEN, 0, nEndPage, GetDoc()->GetDocShell());
938cdf0e10cSrcweir 		}
939cdf0e10cSrcweir 		else				// Hiermit unterdruecken wir ein fuer allemal
940cdf0e10cSrcweir 			*pPageSt = 1;	// das StatLineStartPercent
941cdf0e10cSrcweir 	}
942cdf0e10cSrcweir 
943cdf0e10cSrcweir 	ASSERT( pHyphIter, "wo ist mein Iterator?" );
944cdf0e10cSrcweir 	//JP 18.07.95: verhinder bei Fehlermeldungen die Anzeige der Selektionen
945cdf0e10cSrcweir 	//				KEIN StartAction, da damit auch die Paints abgeschaltet
946cdf0e10cSrcweir 	//				werden !!!!!
947cdf0e10cSrcweir 	++nStartAction;
948cdf0e10cSrcweir     uno::Reference< uno::XInterface >  xRet;
949cdf0e10cSrcweir     pHyphIter->Continue( pPageCnt, pPageSt ) >>= xRet;
950cdf0e10cSrcweir 	--nStartAction;
951cdf0e10cSrcweir 
952cdf0e10cSrcweir 	if( xRet.is() )
953cdf0e10cSrcweir 		pHyphIter->ShowSelection();
954cdf0e10cSrcweir 
955cdf0e10cSrcweir 	return xRet;
956cdf0e10cSrcweir }
957cdf0e10cSrcweir 
958cdf0e10cSrcweir 
959cdf0e10cSrcweir /*************************************************************************
960cdf0e10cSrcweir  *					SwEditShell::InsertSoftHyph
961cdf0e10cSrcweir  *************************************************************************/
962cdf0e10cSrcweir 
963cdf0e10cSrcweir // Zum Einfuegen des SoftHyphens, Position ist der Offset
964cdf0e10cSrcweir // innerhalb des getrennten Wortes.
965cdf0e10cSrcweir 
966cdf0e10cSrcweir 
InsertSoftHyph(const xub_StrLen nHyphPos)967cdf0e10cSrcweir void SwEditShell::InsertSoftHyph( const xub_StrLen nHyphPos )
968cdf0e10cSrcweir {
969cdf0e10cSrcweir 	ASSERT( pHyphIter, "wo ist mein Iterator?" );
970cdf0e10cSrcweir 	pHyphIter->InsertSoftHyph( nHyphPos );
971cdf0e10cSrcweir }
972cdf0e10cSrcweir 
973cdf0e10cSrcweir 
974cdf0e10cSrcweir /*************************************************************************
975cdf0e10cSrcweir  *					SwEditShell::HyphIgnore
976cdf0e10cSrcweir  *************************************************************************/
977cdf0e10cSrcweir 
978cdf0e10cSrcweir // Beschreibung: Trennstelle ignorieren
979cdf0e10cSrcweir 
HyphIgnore()980cdf0e10cSrcweir void SwEditShell::HyphIgnore()
981cdf0e10cSrcweir {
982cdf0e10cSrcweir 	ASSERT( pHyphIter, "wo ist mein Iterator?" );
983cdf0e10cSrcweir 	//JP 18.07.95: verhinder bei Fehlermeldungen die Anzeige der Selektionen
984cdf0e10cSrcweir 	//				KEIN StartAction, da damit auch die Paints abgeschaltet
985cdf0e10cSrcweir 	//				werden !!!!!
986cdf0e10cSrcweir 	++nStartAction;
987cdf0e10cSrcweir 	pHyphIter->Ignore();
988cdf0e10cSrcweir 	--nStartAction;
989cdf0e10cSrcweir 
990cdf0e10cSrcweir 	pHyphIter->ShowSelection();
991cdf0e10cSrcweir }
992cdf0e10cSrcweir 
993cdf0e10cSrcweir /*************************************************************************
994cdf0e10cSrcweir  *					SwEditShell::GetCorrection()
995cdf0e10cSrcweir  * liefert eine Liste von Vorschlaegen fuer falsch geschriebene Worte,
996cdf0e10cSrcweir  * ein NULL-Pointer signalisiert, dass das Wort richtig geschrieben ist,
997cdf0e10cSrcweir  * eine leere Liste, dass das Wort zwar unbekannt ist, aber keine Alternativen
998cdf0e10cSrcweir  * geliefert werden koennen.
999cdf0e10cSrcweir  *************************************************************************/
1000cdf0e10cSrcweir 
1001cdf0e10cSrcweir 
1002cdf0e10cSrcweir uno::Reference< XSpellAlternatives >
GetCorrection(const Point * pPt,SwRect & rSelectRect)1003cdf0e10cSrcweir     SwEditShell::GetCorrection( const Point* pPt, SwRect& rSelectRect )
1004cdf0e10cSrcweir {
1005cdf0e10cSrcweir  	uno::Reference< XSpellAlternatives >  xSpellAlt;
1006cdf0e10cSrcweir 
1007cdf0e10cSrcweir 	if( IsTableMode() )
1008cdf0e10cSrcweir 		return NULL;
1009cdf0e10cSrcweir 	SwPaM* pCrsr = GetCrsr();
1010cdf0e10cSrcweir 	SwPosition aPos( *pCrsr->GetPoint() );
1011cdf0e10cSrcweir  	Point aPt( *pPt );
1012cdf0e10cSrcweir 	SwCrsrMoveState eTmpState( MV_SETONLYTEXT );
1013cdf0e10cSrcweir 	SwTxtNode *pNode;
1014cdf0e10cSrcweir 	SwWrongList *pWrong;
1015cdf0e10cSrcweir 	if( GetLayout()->GetCrsrOfst( &aPos, aPt, &eTmpState ) &&
1016cdf0e10cSrcweir 		0 != (pNode = aPos.nNode.GetNode().GetTxtNode()) &&
1017cdf0e10cSrcweir 		0 != (pWrong = pNode->GetWrong()) &&
1018cdf0e10cSrcweir 		!pNode->IsInProtectSect() )
1019cdf0e10cSrcweir 	{
1020cdf0e10cSrcweir 		xub_StrLen nBegin = aPos.nContent.GetIndex();
1021cdf0e10cSrcweir 		xub_StrLen nLen = 1;
1022cdf0e10cSrcweir 		if(	pWrong->InWrongWord(nBegin,nLen) && !pNode->IsSymbol(nBegin) )
1023cdf0e10cSrcweir 		{
1024cdf0e10cSrcweir 			String aText( pNode->GetTxt().Copy( nBegin, nLen ) );
1025cdf0e10cSrcweir 			String aWord( aText );
1026cdf0e10cSrcweir 			aWord.EraseAllChars( CH_TXTATR_BREAKWORD ).EraseAllChars( CH_TXTATR_INWORD );
1027cdf0e10cSrcweir 
1028cdf0e10cSrcweir             uno::Reference< XSpellChecker1 >  xSpell( ::GetSpellChecker() );
1029cdf0e10cSrcweir 			if( xSpell.is() )
1030cdf0e10cSrcweir 			{
1031cdf0e10cSrcweir                 LanguageType eActLang = (LanguageType)pNode->GetLang( nBegin, nLen );
1032cdf0e10cSrcweir 				if( xSpell->hasLanguage( eActLang ))
1033cdf0e10cSrcweir                 {
1034cdf0e10cSrcweir                     // restrict the maximal number of suggestions displayed
1035cdf0e10cSrcweir                     // in the context menu.
1036cdf0e10cSrcweir                     // Note: That could of course be done by clipping the
1037cdf0e10cSrcweir                     // resulting sequence but the current third party
1038cdf0e10cSrcweir                     // implementations result differs greatly if the number of
1039cdf0e10cSrcweir                     // suggestions to be retuned gets changed. Statistically
1040cdf0e10cSrcweir                     // it gets much better if told to return e.g. only 7 strings
1041cdf0e10cSrcweir                     // than returning e.g. 16 suggestions and using only the
1042cdf0e10cSrcweir                     // first 7. Thus we hand down the value to use to that
1043cdf0e10cSrcweir                     // implementation here by providing an additional parameter.
1044cdf0e10cSrcweir                     Sequence< PropertyValue > aPropVals(1);
1045cdf0e10cSrcweir                     PropertyValue &rVal = aPropVals.getArray()[0];
1046cdf0e10cSrcweir                     rVal.Name = C2U( UPN_MAX_NUMBER_OF_SUGGESTIONS );
1047cdf0e10cSrcweir                     rVal.Value <<= (sal_Int16) 7;
1048cdf0e10cSrcweir 
1049cdf0e10cSrcweir                     xSpellAlt = xSpell->spell( aWord, eActLang, aPropVals );
1050cdf0e10cSrcweir                 }
1051cdf0e10cSrcweir 			}
1052cdf0e10cSrcweir 
1053cdf0e10cSrcweir             if ( xSpellAlt.is() )   // error found?
1054cdf0e10cSrcweir 			{
1055cdf0e10cSrcweir                 //save the start and end positons of the line and the starting point
1056cdf0e10cSrcweir                 Push();
1057cdf0e10cSrcweir                 LeftMargin();
1058cdf0e10cSrcweir                 xub_StrLen nLineStart = GetCrsr()->GetPoint()->nContent.GetIndex();
1059cdf0e10cSrcweir                 RightMargin();
1060cdf0e10cSrcweir                 xub_StrLen nLineEnd = GetCrsr()->GetPoint()->nContent.GetIndex();
1061cdf0e10cSrcweir                 Pop(sal_False);
1062cdf0e10cSrcweir 
1063cdf0e10cSrcweir 				// make sure the selection build later from the
1064cdf0e10cSrcweir 				// data below does not include footnotes and other
1065cdf0e10cSrcweir 				// "in word" character to the left and right in order
1066cdf0e10cSrcweir 				// to preserve those. Therefore count those "in words"
1067cdf0e10cSrcweir 				// in order to modify the selection accordingly.
1068cdf0e10cSrcweir 				const sal_Unicode* pChar = aText.GetBuffer();
1069cdf0e10cSrcweir 				xub_StrLen nLeft = 0;
1070cdf0e10cSrcweir 				while (pChar && *pChar++ == CH_TXTATR_INWORD)
1071cdf0e10cSrcweir 					++nLeft;
1072cdf0e10cSrcweir 				pChar = aText.Len() ? aText.GetBuffer() + aText.Len() - 1 : 0;
1073cdf0e10cSrcweir 				xub_StrLen nRight = 0;
1074cdf0e10cSrcweir 				while (pChar && *pChar-- == CH_TXTATR_INWORD)
1075cdf0e10cSrcweir 					++nRight;
1076cdf0e10cSrcweir 
1077cdf0e10cSrcweir 				aPos.nContent = nBegin + nLeft;
1078cdf0e10cSrcweir                 pCrsr = GetCrsr();
1079cdf0e10cSrcweir 				*pCrsr->GetPoint() = aPos;
1080cdf0e10cSrcweir 				pCrsr->SetMark();
1081cdf0e10cSrcweir 				ExtendSelection( sal_True, nLen - nLeft - nRight );
1082cdf0e10cSrcweir                 //no determine the rectangle in the current line
1083cdf0e10cSrcweir                 xub_StrLen nWordStart = (nBegin + nLeft) < nLineStart ? nLineStart : nBegin + nLeft;
1084cdf0e10cSrcweir                 //take one less than the line end - otherwise the next line would be calculated
1085cdf0e10cSrcweir                 xub_StrLen nWordEnd = (nBegin + nLen - nLeft - nRight) > nLineEnd ? nLineEnd - 1: (nBegin + nLen - nLeft - nRight);
1086cdf0e10cSrcweir                 Push();
1087cdf0e10cSrcweir                 pCrsr->DeleteMark();
1088cdf0e10cSrcweir                 SwIndex& rContent = GetCrsr()->GetPoint()->nContent;
1089cdf0e10cSrcweir                 rContent = nWordStart;
1090cdf0e10cSrcweir                 SwRect aStartRect;
1091cdf0e10cSrcweir                 SwCrsrMoveState aState;
1092cdf0e10cSrcweir                 aState.bRealWidth = sal_True;
1093cdf0e10cSrcweir                 SwCntntNode* pCntntNode = pCrsr->GetCntntNode();
1094cdf0e10cSrcweir                 SwCntntFrm *pCntntFrame = pCntntNode->getLayoutFrm( GetLayout(), pPt, pCrsr->GetPoint(), sal_False);
1095cdf0e10cSrcweir 
1096cdf0e10cSrcweir                 pCntntFrame->GetCharRect( aStartRect, *pCrsr->GetPoint(), &aState );
1097cdf0e10cSrcweir                 rContent = nWordEnd;
1098cdf0e10cSrcweir                 SwRect aEndRect;
1099cdf0e10cSrcweir                 pCntntFrame->GetCharRect( aEndRect, *pCrsr->GetPoint(),&aState );
1100cdf0e10cSrcweir                 rSelectRect = aStartRect.Union( aEndRect );
1101cdf0e10cSrcweir                 Pop(sal_False);
1102cdf0e10cSrcweir             }
1103cdf0e10cSrcweir 		}
1104cdf0e10cSrcweir 	}
1105cdf0e10cSrcweir 	return xSpellAlt;
1106cdf0e10cSrcweir }
1107cdf0e10cSrcweir 
1108cdf0e10cSrcweir /*-------------------------------------------------------------------------
1109cdf0e10cSrcweir 
1110cdf0e10cSrcweir   -----------------------------------------------------------------------*/
1111cdf0e10cSrcweir 
GetGrammarCorrection(linguistic2::ProofreadingResult & rResult,sal_Int32 & rErrorPosInText,sal_Int32 & rErrorIndexInResult,uno::Sequence<rtl::OUString> & rSuggestions,const Point * pPt,SwRect & rSelectRect)1112cdf0e10cSrcweir bool SwEditShell::GetGrammarCorrection(
1113cdf0e10cSrcweir     linguistic2::ProofreadingResult /*out*/ &rResult,    // the complete result
1114cdf0e10cSrcweir     sal_Int32 /*out*/ &rErrorPosInText,                     // offset of error position in string that was grammar checked...
1115cdf0e10cSrcweir     sal_Int32 /*out*/ &rErrorIndexInResult,                 // index of error in rResult.aGrammarErrors
1116cdf0e10cSrcweir     uno::Sequence< rtl::OUString > /*out*/ &rSuggestions,   // suggestions to be used for the error found
1117cdf0e10cSrcweir     const Point *pPt, SwRect &rSelectRect )
1118cdf0e10cSrcweir {
1119cdf0e10cSrcweir     bool bRes = false;
1120cdf0e10cSrcweir 
1121cdf0e10cSrcweir     if( IsTableMode() )
1122cdf0e10cSrcweir         return bRes;
1123cdf0e10cSrcweir 
1124cdf0e10cSrcweir     SwPaM* pCrsr = GetCrsr();
1125cdf0e10cSrcweir     SwPosition aPos( *pCrsr->GetPoint() );
1126cdf0e10cSrcweir     Point aPt( *pPt );
1127cdf0e10cSrcweir     SwCrsrMoveState eTmpState( MV_SETONLYTEXT );
1128cdf0e10cSrcweir     SwTxtNode *pNode;
1129cdf0e10cSrcweir     SwGrammarMarkUp *pWrong;
1130cdf0e10cSrcweir     if( GetLayout()->GetCrsrOfst( &aPos, aPt, &eTmpState ) &&
1131cdf0e10cSrcweir         0 != (pNode = aPos.nNode.GetNode().GetTxtNode()) &&
1132cdf0e10cSrcweir         0 != (pWrong = pNode->GetGrammarCheck()) &&
1133cdf0e10cSrcweir         !pNode->IsInProtectSect() )
1134cdf0e10cSrcweir     {
1135cdf0e10cSrcweir         xub_StrLen nBegin = aPos.nContent.GetIndex();
1136cdf0e10cSrcweir         xub_StrLen nLen = 1;
1137cdf0e10cSrcweir         if (pWrong->InWrongWord(nBegin, nLen))
1138cdf0e10cSrcweir         {
1139cdf0e10cSrcweir             String aText( pNode->GetTxt().Copy( nBegin, nLen ) );
1140cdf0e10cSrcweir             String aWord( aText );
1141cdf0e10cSrcweir             aWord.EraseAllChars( CH_TXTATR_BREAKWORD ).EraseAllChars( CH_TXTATR_INWORD );
1142cdf0e10cSrcweir 
1143cdf0e10cSrcweir             uno::Reference< linguistic2::XProofreadingIterator >  xGCIterator( pDoc->GetGCIterator() );
1144cdf0e10cSrcweir             if (xGCIterator.is())
1145cdf0e10cSrcweir             {
1146cdf0e10cSrcweir //                LanguageType eActLang = (LanguageType)pNode->GetLang( nBegin, nLen );
1147cdf0e10cSrcweir                 uno::Reference< lang::XComponent > xDoc( pDoc->GetDocShell()->GetBaseModel(), uno::UNO_QUERY );
1148cdf0e10cSrcweir 
1149cdf0e10cSrcweir                 // Expand the string:
1150cdf0e10cSrcweir                 rtl::OUString aExpandText;
1151cdf0e10cSrcweir                 const ModelToViewHelper::ConversionMap* pConversionMap =
1152cdf0e10cSrcweir                         pNode->BuildConversionMap( aExpandText );
1153cdf0e10cSrcweir                 // get XFlatParagraph to use...
1154cdf0e10cSrcweir                 uno::Reference< text::XFlatParagraph > xFlatPara = new SwXFlatParagraph( *pNode, aExpandText, pConversionMap );
1155cdf0e10cSrcweir 
1156cdf0e10cSrcweir                 // get error position of cursor in XFlatParagraph
1157cdf0e10cSrcweir                 rErrorPosInText = ModelToViewHelper::ConvertToViewPosition( pConversionMap, nBegin );
1158cdf0e10cSrcweir 
1159cdf0e10cSrcweir                 sal_Int32 nStartOfSentence = ModelToViewHelper::ConvertToViewPosition( pConversionMap, pWrong->getSentenceStart( nBegin ) );
1160cdf0e10cSrcweir                 sal_Int32 nEndOfSentence = ModelToViewHelper::ConvertToViewPosition( pConversionMap, pWrong->getSentenceEnd( nBegin ) );
1161cdf0e10cSrcweir                 if( nEndOfSentence == STRING_LEN )
1162cdf0e10cSrcweir                 {
1163cdf0e10cSrcweir /*                    if( nStartOfSentence == 0 )
1164cdf0e10cSrcweir                     {
1165cdf0e10cSrcweir                         nStartOfSentence = -1;
1166cdf0e10cSrcweir                         nEndOfSentence = -1;
1167cdf0e10cSrcweir                     }
1168cdf0e10cSrcweir                     else */
1169cdf0e10cSrcweir                         nEndOfSentence = aExpandText.getLength();
1170cdf0e10cSrcweir                 }
1171cdf0e10cSrcweir 
1172cdf0e10cSrcweir                 rResult = xGCIterator->checkSentenceAtPosition(
1173cdf0e10cSrcweir                         xDoc, xFlatPara, aExpandText, lang::Locale(), nStartOfSentence, nEndOfSentence, rErrorPosInText );
1174cdf0e10cSrcweir                 bRes = true;
1175cdf0e10cSrcweir 
1176cdf0e10cSrcweir                 // get suggestions to use for the specific error position
1177cdf0e10cSrcweir                 sal_Int32 nErrors = rResult.aErrors.getLength();
1178cdf0e10cSrcweir                 rSuggestions.realloc( 0 );
1179cdf0e10cSrcweir                 for (sal_Int32 i = 0;  i < nErrors; ++i )
1180cdf0e10cSrcweir                 {
1181cdf0e10cSrcweir                     // return suggestions for first error that includes the given error position
1182cdf0e10cSrcweir                     const linguistic2::SingleProofreadingError &rError = rResult.aErrors[i];
11837a52731cSHerbert Dürr                     if( (rError.nErrorStart <= rErrorPosInText) &&
1184c02206c9SAriel Constenla-Haile                         (rErrorPosInText + nLen <= rError.nErrorStart + rError.nErrorLength))
1185cdf0e10cSrcweir                     {
1186cdf0e10cSrcweir                         rSuggestions = rError.aSuggestions;
1187cdf0e10cSrcweir                         rErrorIndexInResult = i;
1188cdf0e10cSrcweir                         break;
1189cdf0e10cSrcweir                     }
1190cdf0e10cSrcweir                 }
1191cdf0e10cSrcweir             }
1192cdf0e10cSrcweir 
1193cdf0e10cSrcweir             if (rResult.aErrors.getLength() > 0)    // error found?
1194cdf0e10cSrcweir             {
1195cdf0e10cSrcweir                 //save the start and end positons of the line and the starting point
1196cdf0e10cSrcweir                 Push();
1197cdf0e10cSrcweir                 LeftMargin();
1198cdf0e10cSrcweir                 xub_StrLen nLineStart = GetCrsr()->GetPoint()->nContent.GetIndex();
1199cdf0e10cSrcweir                 RightMargin();
1200cdf0e10cSrcweir                 xub_StrLen nLineEnd = GetCrsr()->GetPoint()->nContent.GetIndex();
1201cdf0e10cSrcweir                 Pop(sal_False);
1202cdf0e10cSrcweir 
1203cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
1204cdf0e10cSrcweir //                pNode->GetGrammarCheck()->Invalidate( 0, STRING_LEN );
1205cdf0e10cSrcweir //                pNode->SetGrammarCheckDirty( true );
1206cdf0e10cSrcweir #endif
1207cdf0e10cSrcweir                 // make sure the selection build later from the
1208cdf0e10cSrcweir                 // data below does not include footnotes and other
1209cdf0e10cSrcweir                 // "in word" character to the left and right in order
1210cdf0e10cSrcweir                 // to preserve those. Therefore count those "in words"
1211cdf0e10cSrcweir                 // in order to modify the selection accordingly.
1212cdf0e10cSrcweir                 const sal_Unicode* pChar = aText.GetBuffer();
1213cdf0e10cSrcweir                 xub_StrLen nLeft = 0;
1214cdf0e10cSrcweir                 while (pChar && *pChar++ == CH_TXTATR_INWORD)
1215cdf0e10cSrcweir                     ++nLeft;
1216cdf0e10cSrcweir                 pChar = aText.Len() ? aText.GetBuffer() + aText.Len() - 1 : 0;
1217cdf0e10cSrcweir                 xub_StrLen nRight = 0;
1218cdf0e10cSrcweir                 while (pChar && *pChar-- == CH_TXTATR_INWORD)
1219cdf0e10cSrcweir                     ++nRight;
1220cdf0e10cSrcweir 
1221cdf0e10cSrcweir                 aPos.nContent = nBegin + nLeft;
1222cdf0e10cSrcweir                 pCrsr = GetCrsr();
1223cdf0e10cSrcweir                 *pCrsr->GetPoint() = aPos;
1224cdf0e10cSrcweir                 pCrsr->SetMark();
1225cdf0e10cSrcweir                 ExtendSelection( sal_True, nLen - nLeft - nRight );
1226cdf0e10cSrcweir                 //no determine the rectangle in the current line
1227cdf0e10cSrcweir                 xub_StrLen nWordStart = (nBegin + nLeft) < nLineStart ? nLineStart : nBegin + nLeft;
1228cdf0e10cSrcweir                 //take one less than the line end - otherwise the next line would be calculated
1229cdf0e10cSrcweir                 xub_StrLen nWordEnd = (nBegin + nLen - nLeft - nRight) > nLineEnd ? nLineEnd - 1: (nBegin + nLen - nLeft - nRight);
1230cdf0e10cSrcweir                 Push();
1231cdf0e10cSrcweir                 pCrsr->DeleteMark();
1232cdf0e10cSrcweir                 SwIndex& rContent = GetCrsr()->GetPoint()->nContent;
1233cdf0e10cSrcweir                 rContent = nWordStart;
1234cdf0e10cSrcweir                 SwRect aStartRect;
1235cdf0e10cSrcweir                 SwCrsrMoveState aState;
1236cdf0e10cSrcweir                 aState.bRealWidth = sal_True;
1237cdf0e10cSrcweir                 SwCntntNode* pCntntNode = pCrsr->GetCntntNode();
1238cdf0e10cSrcweir                 SwCntntFrm *pCntntFrame = pCntntNode->getLayoutFrm( GetLayout(), pPt, pCrsr->GetPoint(), sal_False);
1239cdf0e10cSrcweir 
1240cdf0e10cSrcweir                 pCntntFrame->GetCharRect( aStartRect, *pCrsr->GetPoint(), &aState );
1241cdf0e10cSrcweir                 rContent = nWordEnd;
1242cdf0e10cSrcweir                 SwRect aEndRect;
1243cdf0e10cSrcweir                 pCntntFrame->GetCharRect( aEndRect, *pCrsr->GetPoint(),&aState );
1244cdf0e10cSrcweir                 rSelectRect = aStartRect.Union( aEndRect );
1245cdf0e10cSrcweir                 Pop(sal_False);
1246cdf0e10cSrcweir             }
1247cdf0e10cSrcweir         }
1248cdf0e10cSrcweir     }
1249cdf0e10cSrcweir 
1250cdf0e10cSrcweir     return bRes;
1251cdf0e10cSrcweir }
1252cdf0e10cSrcweir 
1253cdf0e10cSrcweir /*-- 18.09.2003 15:08:18---------------------------------------------------
1254cdf0e10cSrcweir 
1255cdf0e10cSrcweir   -----------------------------------------------------------------------*/
SpellSentence(::svx::SpellPortions & rPortions,bool bIsGrammarCheck)1256cdf0e10cSrcweir bool SwEditShell::SpellSentence(::svx::SpellPortions& rPortions, bool bIsGrammarCheck)
1257cdf0e10cSrcweir {
1258cdf0e10cSrcweir     ASSERT(  pSpellIter, "SpellIter missing" );
1259cdf0e10cSrcweir     if(!pSpellIter)
1260cdf0e10cSrcweir         return false;
1261cdf0e10cSrcweir     bool bRet = pSpellIter->SpellSentence(rPortions, bIsGrammarCheck);
1262cdf0e10cSrcweir 
1263cdf0e10cSrcweir     // make Selection visible - this should simply move the
1264cdf0e10cSrcweir     // cursor to the end of the sentence
1265cdf0e10cSrcweir     StartAction();
1266cdf0e10cSrcweir     EndAction();
1267cdf0e10cSrcweir     return bRet;
1268cdf0e10cSrcweir }
1269cdf0e10cSrcweir /*-- 08.09.2008 09:35:19---------------------------------------------------
1270cdf0e10cSrcweir     make SpellIter start with the current sentence when called next time
1271cdf0e10cSrcweir   -----------------------------------------------------------------------*/
PutSpellingToSentenceStart()1272cdf0e10cSrcweir void SwEditShell::PutSpellingToSentenceStart()
1273cdf0e10cSrcweir {
1274cdf0e10cSrcweir     ASSERT(  pSpellIter, "SpellIter missing" );
1275cdf0e10cSrcweir     if(!pSpellIter)
1276cdf0e10cSrcweir         return;
1277cdf0e10cSrcweir     pSpellIter->ToSentenceStart();
1278cdf0e10cSrcweir }
1279cdf0e10cSrcweir /*-- 02.02.2005 14:34:41---------------------------------------------------
1280cdf0e10cSrcweir 
1281cdf0e10cSrcweir   -----------------------------------------------------------------------*/
lcl_CountRedlines(const::svx::SpellPortions & rLastPortions)1282cdf0e10cSrcweir sal_uInt32 lcl_CountRedlines(
1283cdf0e10cSrcweir                             const ::svx::SpellPortions& rLastPortions)
1284cdf0e10cSrcweir {
1285cdf0e10cSrcweir     sal_uInt32 nRet = 0;
1286cdf0e10cSrcweir     SpellPortions::const_iterator aIter = rLastPortions.begin();
1287cdf0e10cSrcweir     for( ; aIter != rLastPortions.end(); ++aIter)
1288cdf0e10cSrcweir     {
1289cdf0e10cSrcweir         if( aIter->bIsHidden )
1290cdf0e10cSrcweir             ++nRet;
1291cdf0e10cSrcweir     }
1292cdf0e10cSrcweir     return nRet;
1293cdf0e10cSrcweir }
1294cdf0e10cSrcweir /*-- 18.09.2003 15:08:20---------------------------------------------------
1295cdf0e10cSrcweir 
1296cdf0e10cSrcweir   -----------------------------------------------------------------------*/
1297cdf0e10cSrcweir 
MoveContinuationPosToEndOfCheckedSentence()1298cdf0e10cSrcweir void SwEditShell::MoveContinuationPosToEndOfCheckedSentence()
1299cdf0e10cSrcweir {
1300cdf0e10cSrcweir     // give hint that continuation position for spell/grammar checking is
1301cdf0e10cSrcweir     // at the end of this sentence
1302cdf0e10cSrcweir     if (pSpellIter)
1303cdf0e10cSrcweir     {
1304cdf0e10cSrcweir         pSpellIter->SetCurr( new SwPosition( *pSpellIter->GetCurrX() ) );
1305cdf0e10cSrcweir         pSpellIter->ContinueAfterThisSentence();
1306cdf0e10cSrcweir     }
1307cdf0e10cSrcweir }
1308cdf0e10cSrcweir 
1309cdf0e10cSrcweir 
ApplyChangedSentence(const::svx::SpellPortions & rNewPortions,bool bRecheck)1310cdf0e10cSrcweir void SwEditShell::ApplyChangedSentence(const ::svx::SpellPortions& rNewPortions, bool bRecheck)
1311cdf0e10cSrcweir {
1312cdf0e10cSrcweir     // Note: rNewPortions.size() == 0 is valid and happens when the whole
1313cdf0e10cSrcweir     // sentence got removed in the dialog
1314cdf0e10cSrcweir 
1315cdf0e10cSrcweir     ASSERT(  pSpellIter, "SpellIter missing" );
1316cdf0e10cSrcweir     if(pSpellIter &&
1317cdf0e10cSrcweir        pSpellIter->GetLastPortions().size() > 0)    // no portions -> no text to be changed
1318cdf0e10cSrcweir     {
1319cdf0e10cSrcweir         const SpellPortions& rLastPortions = pSpellIter->GetLastPortions();
1320cdf0e10cSrcweir         const SpellContentPositions  rLastPositions = pSpellIter->GetLastPositions();
1321cdf0e10cSrcweir         ASSERT(rLastPortions.size() > 0 &&
1322cdf0e10cSrcweir                 rLastPortions.size() == rLastPositions.size(),
1323cdf0e10cSrcweir                 "last vectors of spelling results are not set or not equal")
1324cdf0e10cSrcweir 
1325cdf0e10cSrcweir         // iterate over the new portions, beginning at the end to take advantage of the previously
1326cdf0e10cSrcweir         // saved content positions
1327cdf0e10cSrcweir 
1328cdf0e10cSrcweir         pDoc->GetIDocumentUndoRedo().StartUndo( UNDO_OVERWRITE, NULL );
1329cdf0e10cSrcweir         StartAction();
1330cdf0e10cSrcweir 
1331cdf0e10cSrcweir         SwPaM *pCrsr = GetCrsr();
1332cdf0e10cSrcweir         // save cursor position (which should be at the end of the current sentence)
1333cdf0e10cSrcweir         // for later restoration
1334cdf0e10cSrcweir         Push();
1335cdf0e10cSrcweir 
1336cdf0e10cSrcweir         sal_uInt32 nRedlinePortions = lcl_CountRedlines(rLastPortions);
1337cdf0e10cSrcweir         if((rLastPortions.size() - nRedlinePortions) == rNewPortions.size())
1338cdf0e10cSrcweir         {
1339cdf0e10cSrcweir             DBG_ASSERT( rNewPortions.size() > 0, "rNewPortions should not be empty here" );
1340cdf0e10cSrcweir             DBG_ASSERT( rLastPortions.size() > 0, "rLastPortions should not be empty here" );
1341cdf0e10cSrcweir             DBG_ASSERT( rLastPositions.size() > 0, "rLastPositions should not be empty here" );
1342cdf0e10cSrcweir 
1343cdf0e10cSrcweir             //the simple case: the same number of elements on both sides
1344cdf0e10cSrcweir             //each changed element has to be applied to the corresponding source element
1345cdf0e10cSrcweir             svx::SpellPortions::const_iterator aCurrentNewPortion = rNewPortions.end();
1346cdf0e10cSrcweir             SpellPortions::const_iterator aCurrentOldPortion = rLastPortions.end();
1347cdf0e10cSrcweir             SpellContentPositions::const_iterator aCurrentOldPosition = rLastPositions.end();
1348cdf0e10cSrcweir             do
1349cdf0e10cSrcweir             {
1350cdf0e10cSrcweir                 --aCurrentNewPortion;
1351cdf0e10cSrcweir                 --aCurrentOldPortion;
1352cdf0e10cSrcweir                 --aCurrentOldPosition;
1353cdf0e10cSrcweir                 //jump over redline portions
1354cdf0e10cSrcweir                 while(aCurrentOldPortion->bIsHidden)
1355cdf0e10cSrcweir                 {
1356cdf0e10cSrcweir                     if (aCurrentOldPortion  != rLastPortions.begin() &&
1357cdf0e10cSrcweir                         aCurrentOldPosition != rLastPositions.begin())
1358cdf0e10cSrcweir                     {
1359cdf0e10cSrcweir                         --aCurrentOldPortion;
1360cdf0e10cSrcweir                         --aCurrentOldPosition;
1361cdf0e10cSrcweir                     }
1362cdf0e10cSrcweir                     else
1363cdf0e10cSrcweir                     {
1364cdf0e10cSrcweir                         DBG_ASSERT( 0, "ApplyChangedSentence: iterator positions broken" );
1365cdf0e10cSrcweir                         break;
1366cdf0e10cSrcweir                     }
1367cdf0e10cSrcweir                 }
1368cdf0e10cSrcweir 				if ( !pCrsr->HasMark() )
1369cdf0e10cSrcweir 					pCrsr->SetMark();
1370cdf0e10cSrcweir                 pCrsr->GetPoint()->nContent = aCurrentOldPosition->nLeft;
1371cdf0e10cSrcweir                 pCrsr->GetMark()->nContent = aCurrentOldPosition->nRight;
1372cdf0e10cSrcweir                 sal_uInt16 nScriptType = GetI18NScriptTypeOfLanguage( aCurrentNewPortion->eLanguage );
1373cdf0e10cSrcweir                 sal_uInt16 nLangWhichId = RES_CHRATR_LANGUAGE;
1374cdf0e10cSrcweir                 switch(nScriptType)
1375cdf0e10cSrcweir                 {
1376cdf0e10cSrcweir                     case SCRIPTTYPE_ASIAN : nLangWhichId = RES_CHRATR_CJK_LANGUAGE; break;
1377cdf0e10cSrcweir                     case SCRIPTTYPE_COMPLEX : nLangWhichId = RES_CHRATR_CTL_LANGUAGE; break;
1378cdf0e10cSrcweir                 }
1379cdf0e10cSrcweir                 if(aCurrentNewPortion->sText != aCurrentOldPortion->sText)
1380cdf0e10cSrcweir                 {
1381cdf0e10cSrcweir                     //change text ...
1382cdf0e10cSrcweir                     pDoc->DeleteAndJoin(*pCrsr);
1383cdf0e10cSrcweir                     // ... and apply language if necessary
1384cdf0e10cSrcweir                     if(aCurrentNewPortion->eLanguage != aCurrentOldPortion->eLanguage)
138569a74367SOliver-Rainer Wittmann                         SetAttrItem( SvxLanguageItem(aCurrentNewPortion->eLanguage, nLangWhichId), nLangWhichId );
1386cdf0e10cSrcweir                     pDoc->InsertString(*pCrsr, aCurrentNewPortion->sText);
1387cdf0e10cSrcweir                 }
1388cdf0e10cSrcweir                 else if(aCurrentNewPortion->eLanguage != aCurrentOldPortion->eLanguage)
1389cdf0e10cSrcweir                 {
1390cdf0e10cSrcweir                     //apply language
139169a74367SOliver-Rainer Wittmann                     SetAttrItem( SvxLanguageItem(aCurrentNewPortion->eLanguage, nLangWhichId), nLangWhichId );
1392cdf0e10cSrcweir                 }
1393cdf0e10cSrcweir                 else if( aCurrentNewPortion->bIgnoreThisError )
1394cdf0e10cSrcweir                 {
1395cdf0e10cSrcweir                     //add the 'ignore' markup to the TextNode's grammar ignore markup list
1396cdf0e10cSrcweir                     IgnoreGrammarErrorAt( *pCrsr );
1397cdf0e10cSrcweir                     DBG_ERROR("TODO: add ignore mark to text node");
1398cdf0e10cSrcweir                 }
1399cdf0e10cSrcweir                 if(aCurrentNewPortion == rNewPortions.begin())
1400cdf0e10cSrcweir                     break;
1401cdf0e10cSrcweir             }
1402cdf0e10cSrcweir             while(aCurrentNewPortion != rNewPortions.begin());
1403cdf0e10cSrcweir         }
1404cdf0e10cSrcweir         else
1405cdf0e10cSrcweir         {
1406cdf0e10cSrcweir             DBG_ASSERT( rLastPositions.size() > 0, "rLastPositions should not be empty here" );
1407cdf0e10cSrcweir 
1408cdf0e10cSrcweir             //select the complete sentence
1409cdf0e10cSrcweir             SpellContentPositions::const_iterator aCurrentEndPosition = rLastPositions.end();
1410cdf0e10cSrcweir             --aCurrentEndPosition;
1411cdf0e10cSrcweir             SpellContentPositions::const_iterator aCurrentStartPosition = rLastPositions.begin();
1412cdf0e10cSrcweir             pCrsr->GetPoint()->nContent = aCurrentStartPosition->nLeft;
1413cdf0e10cSrcweir             pCrsr->GetMark()->nContent = aCurrentEndPosition->nRight;
1414cdf0e10cSrcweir 
1415cdf0e10cSrcweir             //delete the sentence completely
1416cdf0e10cSrcweir             pDoc->DeleteAndJoin(*pCrsr);
1417cdf0e10cSrcweir             svx::SpellPortions::const_iterator aCurrentNewPortion = rNewPortions.begin();
1418cdf0e10cSrcweir             while(aCurrentNewPortion != rNewPortions.end())
1419cdf0e10cSrcweir             {
1420cdf0e10cSrcweir                 //set the language attribute
1421cdf0e10cSrcweir                 sal_uInt16 nScriptType = GetScriptType();
1422cdf0e10cSrcweir                 sal_uInt16 nLangWhichId = RES_CHRATR_LANGUAGE;
1423cdf0e10cSrcweir                 switch(nScriptType)
1424cdf0e10cSrcweir                 {
1425cdf0e10cSrcweir                     case SCRIPTTYPE_ASIAN : nLangWhichId = RES_CHRATR_CJK_LANGUAGE; break;
1426cdf0e10cSrcweir                     case SCRIPTTYPE_COMPLEX : nLangWhichId = RES_CHRATR_CTL_LANGUAGE; break;
1427cdf0e10cSrcweir                 }
1428cdf0e10cSrcweir                 SfxItemSet aSet(GetAttrPool(), nLangWhichId, nLangWhichId, 0);
1429cdf0e10cSrcweir                 GetCurAttr( aSet );
1430cdf0e10cSrcweir                 const SvxLanguageItem& rLang = static_cast<const SvxLanguageItem& >(aSet.Get(nLangWhichId));
1431cdf0e10cSrcweir                 if(rLang.GetLanguage() != aCurrentNewPortion->eLanguage)
143269a74367SOliver-Rainer Wittmann 					SetAttrItem( SvxLanguageItem(aCurrentNewPortion->eLanguage, nLangWhichId) );
1433cdf0e10cSrcweir                 //insert the new string
1434cdf0e10cSrcweir                 pDoc->InsertString(*pCrsr, aCurrentNewPortion->sText);
1435cdf0e10cSrcweir 
1436cdf0e10cSrcweir                 //set the cursor to the end of the inserted string
1437cdf0e10cSrcweir                 *pCrsr->Start() = *pCrsr->End();
1438cdf0e10cSrcweir                 ++aCurrentNewPortion;
1439cdf0e10cSrcweir             }
1440cdf0e10cSrcweir         }
1441cdf0e10cSrcweir 
1442cdf0e10cSrcweir         // restore cursor to the end of the sentence
1443cdf0e10cSrcweir         // (will work also if the sentence length has changed,
1444cdf0e10cSrcweir         // since cursors get updated automatically!)
1445cdf0e10cSrcweir         Pop( sal_False );
1446cdf0e10cSrcweir 
1447cdf0e10cSrcweir         // collapse cursor to the end of the modified sentence
1448cdf0e10cSrcweir         *pCrsr->Start() = *pCrsr->End();
1449cdf0e10cSrcweir         if (bRecheck)
1450cdf0e10cSrcweir         {
1451cdf0e10cSrcweir             //in grammar check the current sentence has to be checked again
1452cdf0e10cSrcweir             GoStartSentence();
1453cdf0e10cSrcweir         }
1454cdf0e10cSrcweir         // set continuation position for spell/grammar checking to the end of this sentence
1455cdf0e10cSrcweir         pSpellIter->SetCurr( new SwPosition( *pCrsr->Start() ) );
1456cdf0e10cSrcweir 
1457cdf0e10cSrcweir         pDoc->GetIDocumentUndoRedo().EndUndo( UNDO_OVERWRITE, NULL );
1458cdf0e10cSrcweir         EndAction();
1459cdf0e10cSrcweir     }
1460cdf0e10cSrcweir }
1461cdf0e10cSrcweir /*-- 02.02.2005 10:46:45---------------------------------------------------
1462cdf0e10cSrcweir     collect all deleted redlines of the current text node beginning at the
1463cdf0e10cSrcweir     start of the cursor position
1464cdf0e10cSrcweir   -----------------------------------------------------------------------*/
lcl_CollectDeletedRedlines(SwEditShell * pSh)1465cdf0e10cSrcweir SpellContentPositions lcl_CollectDeletedRedlines(SwEditShell* pSh)
1466cdf0e10cSrcweir {
1467cdf0e10cSrcweir     SpellContentPositions aRedlines;
1468cdf0e10cSrcweir     SwDoc* pDoc = pSh->GetDoc();
1469cdf0e10cSrcweir     const bool bShowChg = IDocumentRedlineAccess::IsShowChanges( pDoc->GetRedlineMode() );
1470cdf0e10cSrcweir     if ( bShowChg )
1471cdf0e10cSrcweir     {
1472cdf0e10cSrcweir         SwPaM *pCrsr = pSh->GetCrsr();
1473cdf0e10cSrcweir         const SwPosition* pStartPos = pCrsr->Start();
1474cdf0e10cSrcweir         const SwTxtNode* pTxtNode = pCrsr->GetNode()->GetTxtNode();
1475cdf0e10cSrcweir 
1476cdf0e10cSrcweir         sal_uInt16 nAct = pDoc->GetRedlinePos( *pTxtNode, USHRT_MAX );
1477cdf0e10cSrcweir         const xub_StrLen nStartIndex = pStartPos->nContent.GetIndex();
1478cdf0e10cSrcweir         for ( ; nAct < pDoc->GetRedlineTbl().Count(); nAct++ )
1479cdf0e10cSrcweir         {
1480cdf0e10cSrcweir             const SwRedline* pRed = pDoc->GetRedlineTbl()[ nAct ];
1481cdf0e10cSrcweir 
1482cdf0e10cSrcweir             if ( pRed->Start()->nNode > pTxtNode->GetIndex() )
1483cdf0e10cSrcweir                 break;
1484cdf0e10cSrcweir 
1485cdf0e10cSrcweir             if( nsRedlineType_t::REDLINE_DELETE == pRed->GetType() )
1486cdf0e10cSrcweir             {
1487cdf0e10cSrcweir                 xub_StrLen nStart, nEnd;
1488cdf0e10cSrcweir                 pRed->CalcStartEnd( pTxtNode->GetIndex(), nStart, nEnd );
1489cdf0e10cSrcweir                 if(nStart >= nStartIndex || nEnd >= nStartIndex)
1490cdf0e10cSrcweir                 {
1491cdf0e10cSrcweir                     SpellContentPosition aAdd;
1492cdf0e10cSrcweir                     aAdd.nLeft = nStart;
1493cdf0e10cSrcweir                     aAdd.nRight = nEnd;
1494cdf0e10cSrcweir                     aRedlines.push_back(aAdd);
1495cdf0e10cSrcweir                 }
1496cdf0e10cSrcweir             }
1497cdf0e10cSrcweir         }
1498cdf0e10cSrcweir     }
1499cdf0e10cSrcweir     return aRedlines;
1500cdf0e10cSrcweir }
1501cdf0e10cSrcweir /*-- 02.02.2005 11:06:12---------------------------------------------------
1502cdf0e10cSrcweir     remove the redline positions after the current selection
1503cdf0e10cSrcweir   -----------------------------------------------------------------------*/
lcl_CutRedlines(SpellContentPositions & aDeletedRedlines,SwEditShell * pSh)1504cdf0e10cSrcweir void lcl_CutRedlines( SpellContentPositions& aDeletedRedlines, SwEditShell* pSh )
1505cdf0e10cSrcweir {
1506cdf0e10cSrcweir     if(!aDeletedRedlines.empty())
1507cdf0e10cSrcweir     {
1508cdf0e10cSrcweir         SwPaM *pCrsr = pSh->GetCrsr();
1509cdf0e10cSrcweir         const SwPosition* pEndPos = pCrsr->End();
1510cdf0e10cSrcweir         xub_StrLen nEnd = pEndPos->nContent.GetIndex();
1511cdf0e10cSrcweir         while(!aDeletedRedlines.empty() &&
1512cdf0e10cSrcweir                 aDeletedRedlines.back().nLeft > nEnd)
1513cdf0e10cSrcweir         {
1514cdf0e10cSrcweir             aDeletedRedlines.pop_back();
1515cdf0e10cSrcweir         }
1516cdf0e10cSrcweir     }
1517cdf0e10cSrcweir }
1518cdf0e10cSrcweir /*-- 02.02.2005 11:43:00---------------------------------------------------
1519cdf0e10cSrcweir 
1520cdf0e10cSrcweir   -----------------------------------------------------------------------*/
lcl_FindNextDeletedRedline(const SpellContentPositions & rDeletedRedlines,xub_StrLen nSearchFrom)1521cdf0e10cSrcweir SpellContentPosition  lcl_FindNextDeletedRedline(
1522cdf0e10cSrcweir         const SpellContentPositions& rDeletedRedlines,
1523cdf0e10cSrcweir         xub_StrLen nSearchFrom )
1524cdf0e10cSrcweir {
1525cdf0e10cSrcweir     SpellContentPosition aRet;
1526cdf0e10cSrcweir     aRet.nLeft = aRet.nRight = STRING_MAXLEN;
1527cdf0e10cSrcweir     if(!rDeletedRedlines.empty())
1528cdf0e10cSrcweir     {
1529cdf0e10cSrcweir         SpellContentPositions::const_iterator aIter = rDeletedRedlines.begin();
1530cdf0e10cSrcweir         for( ; aIter != rDeletedRedlines.end(); ++aIter)
1531cdf0e10cSrcweir         {
1532cdf0e10cSrcweir             if(aIter->nLeft < nSearchFrom)
1533cdf0e10cSrcweir                 continue;
1534cdf0e10cSrcweir             aRet = *aIter;
1535cdf0e10cSrcweir             break;
1536cdf0e10cSrcweir         }
1537cdf0e10cSrcweir     }
1538cdf0e10cSrcweir     return aRet;
1539cdf0e10cSrcweir }
1540cdf0e10cSrcweir /*-- 18.09.2003 15:08:20---------------------------------------------------
1541cdf0e10cSrcweir 
1542cdf0e10cSrcweir   -----------------------------------------------------------------------*/
SpellSentence(::svx::SpellPortions & rPortions,bool bIsGrammarCheck)1543cdf0e10cSrcweir bool SwSpellIter::SpellSentence(::svx::SpellPortions& rPortions, bool bIsGrammarCheck)
1544cdf0e10cSrcweir {
1545cdf0e10cSrcweir     bool bRet = false;
1546cdf0e10cSrcweir     aLastPortions.clear();
1547cdf0e10cSrcweir     aLastPositions.clear();
1548cdf0e10cSrcweir 
1549cdf0e10cSrcweir     SwEditShell *pMySh = GetSh();
1550cdf0e10cSrcweir     if( !pMySh )
1551cdf0e10cSrcweir         return false;
1552cdf0e10cSrcweir 
1553cdf0e10cSrcweir     ASSERT( GetEnd(), "SwEditShell::SpellSentence() ohne Start?");
1554cdf0e10cSrcweir 
1555cdf0e10cSrcweir     uno::Reference< XSpellAlternatives >  xSpellRet;
1556cdf0e10cSrcweir     linguistic2::ProofreadingResult aGrammarResult;
1557cdf0e10cSrcweir     sal_Bool bGoOn = sal_True;
1558cdf0e10cSrcweir     bool bGrammarErrorFound = false;
1559cdf0e10cSrcweir     do {
1560cdf0e10cSrcweir         SwPaM *pCrsr = pMySh->GetCrsr();
1561cdf0e10cSrcweir         if ( !pCrsr->HasMark() )
1562cdf0e10cSrcweir             pCrsr->SetMark();
1563cdf0e10cSrcweir 
1564cdf0e10cSrcweir         *pCrsr->GetPoint() = *GetCurr();
1565cdf0e10cSrcweir         *pCrsr->GetMark() = *GetEnd();
1566cdf0e10cSrcweir 
1567cdf0e10cSrcweir         if( bBackToStartOfSentence )
1568cdf0e10cSrcweir         {
1569cdf0e10cSrcweir             pMySh->GoStartSentence();
1570cdf0e10cSrcweir             bBackToStartOfSentence = false;
1571cdf0e10cSrcweir         }
1572cdf0e10cSrcweir         uno::Any aSpellRet =
1573cdf0e10cSrcweir         pMySh->GetDoc()->Spell(*pCrsr,
1574cdf0e10cSrcweir                     xSpeller, 0, 0, bIsGrammarCheck );
1575cdf0e10cSrcweir         aSpellRet >>= xSpellRet;
1576cdf0e10cSrcweir         aSpellRet >>= aGrammarResult;
1577cdf0e10cSrcweir         bGoOn = GetCrsrCnt() > 1;
1578cdf0e10cSrcweir         bGrammarErrorFound = aGrammarResult.aErrors.getLength() > 0;
1579cdf0e10cSrcweir         if( xSpellRet.is() || bGrammarErrorFound )
1580cdf0e10cSrcweir         {
1581cdf0e10cSrcweir             bGoOn = sal_False;
1582cdf0e10cSrcweir             SwPosition* pNewPoint = new SwPosition( *pCrsr->GetPoint() );
1583cdf0e10cSrcweir             SwPosition* pNewMark = new SwPosition( *pCrsr->GetMark() );
1584cdf0e10cSrcweir 
1585cdf0e10cSrcweir             SetCurr( pNewPoint );
1586cdf0e10cSrcweir             SetCurrX( pNewMark );
1587cdf0e10cSrcweir         }
1588cdf0e10cSrcweir         if( bGoOn )
1589cdf0e10cSrcweir         {
1590cdf0e10cSrcweir             pMySh->Pop( sal_False );
1591cdf0e10cSrcweir             pCrsr = pMySh->GetCrsr();
1592cdf0e10cSrcweir             if ( *pCrsr->GetPoint() > *pCrsr->GetMark() )
1593cdf0e10cSrcweir                 pCrsr->Exchange();
1594cdf0e10cSrcweir             SwPosition* pNew = new SwPosition( *pCrsr->GetPoint() );
1595cdf0e10cSrcweir             SetStart( pNew );
1596cdf0e10cSrcweir             pNew = new SwPosition( *pCrsr->GetMark() );
1597cdf0e10cSrcweir             SetEnd( pNew );
1598cdf0e10cSrcweir             pNew = new SwPosition( *GetStart() );
1599cdf0e10cSrcweir             SetCurr( pNew );
1600cdf0e10cSrcweir             pNew = new SwPosition( *pNew );
1601cdf0e10cSrcweir             SetCurrX( pNew );
1602cdf0e10cSrcweir             pCrsr->SetMark();
1603cdf0e10cSrcweir             --GetCrsrCnt();
1604cdf0e10cSrcweir         }
1605cdf0e10cSrcweir     }
1606cdf0e10cSrcweir     while ( bGoOn );
1607cdf0e10cSrcweir     if(xSpellRet.is() || bGrammarErrorFound)
1608cdf0e10cSrcweir     {
1609cdf0e10cSrcweir         //an error has been found
1610cdf0e10cSrcweir         //To fill the spell portions the beginning of the sentence has to be found
1611cdf0e10cSrcweir         SwPaM *pCrsr = pMySh->GetCrsr();
1612cdf0e10cSrcweir         //set the mark to the right if necessary
1613cdf0e10cSrcweir         if ( *pCrsr->GetPoint() > *pCrsr->GetMark() )
1614cdf0e10cSrcweir             pCrsr->Exchange();
1615cdf0e10cSrcweir         //the cursor has to be collapsed on the left to go to the start of the sentence - if sentence ends inside of the error
1616cdf0e10cSrcweir         pCrsr->DeleteMark();
1617cdf0e10cSrcweir         pCrsr->SetMark();
1618cdf0e10cSrcweir         sal_Bool bStartSent = 0 != pMySh->GoStartSentence();
1619cdf0e10cSrcweir         SpellContentPositions aDeletedRedlines = lcl_CollectDeletedRedlines(pMySh);
1620cdf0e10cSrcweir         if(bStartSent)
1621cdf0e10cSrcweir         {
1622cdf0e10cSrcweir             //create a portion from the start part
1623cdf0e10cSrcweir             AddPortion(0, 0, aDeletedRedlines);
1624cdf0e10cSrcweir         }
1625cdf0e10cSrcweir         //Set the cursor to the error already found
1626cdf0e10cSrcweir         *pCrsr->GetPoint() = *GetCurrX();
1627cdf0e10cSrcweir         *pCrsr->GetMark() = *GetCurr();
1628cdf0e10cSrcweir         AddPortion(xSpellRet, &aGrammarResult, aDeletedRedlines);
1629cdf0e10cSrcweir 
1630cdf0e10cSrcweir 
1631cdf0e10cSrcweir         //save the end position of the error to continue from here
1632cdf0e10cSrcweir         SwPosition aSaveStartPos = *pCrsr->End();
1633cdf0e10cSrcweir         //determine the end of the current sentence
1634cdf0e10cSrcweir         if ( *pCrsr->GetPoint() < *pCrsr->GetMark() )
1635cdf0e10cSrcweir             pCrsr->Exchange();
1636cdf0e10cSrcweir         //again collapse to start marking after the end of the error
1637cdf0e10cSrcweir         pCrsr->DeleteMark();
1638cdf0e10cSrcweir         pCrsr->SetMark();
1639cdf0e10cSrcweir 
1640cdf0e10cSrcweir         pMySh->GoEndSentence();
1641cdf0e10cSrcweir         if( bGrammarErrorFound )
1642cdf0e10cSrcweir         {
1643cdf0e10cSrcweir             rtl::OUString aExpandText;
1644cdf0e10cSrcweir             const ModelToViewHelper::ConversionMap* pConversionMap = ((SwTxtNode*)pCrsr->GetNode())->BuildConversionMap( aExpandText );
1645cdf0e10cSrcweir             xub_StrLen nSentenceEnd = (xub_StrLen)ModelToViewHelper::ConvertToViewPosition( pConversionMap, aGrammarResult.nBehindEndOfSentencePosition );
1646cdf0e10cSrcweir             // remove trailing space
1647cdf0e10cSrcweir             if( aExpandText[nSentenceEnd - 1] == ' ' )
1648cdf0e10cSrcweir                 --nSentenceEnd;
1649cdf0e10cSrcweir             if( pCrsr->End()->nContent.GetIndex() < nSentenceEnd )
1650cdf0e10cSrcweir             {
1651cdf0e10cSrcweir                 pCrsr->End()->nContent.Assign(
1652cdf0e10cSrcweir                     pCrsr->End()->nNode.GetNode().GetCntntNode(), nSentenceEnd);
1653cdf0e10cSrcweir             }
1654cdf0e10cSrcweir         }
1655cdf0e10cSrcweir 
1656cdf0e10cSrcweir         lcl_CutRedlines( aDeletedRedlines, pMySh );
1657cdf0e10cSrcweir         //save the 'global' end of the spellchecking
1658cdf0e10cSrcweir         const SwPosition aSaveEndPos = *GetEnd();
1659cdf0e10cSrcweir         //set the sentence end as 'local' end
1660cdf0e10cSrcweir         SetEnd( new SwPosition( *pCrsr->End() ));
1661cdf0e10cSrcweir 
1662cdf0e10cSrcweir         *pCrsr->GetPoint() = aSaveStartPos;
1663cdf0e10cSrcweir         *pCrsr->GetMark() = *GetEnd();
1664cdf0e10cSrcweir         //now the rest of the sentence has to be searched for errors
1665cdf0e10cSrcweir         // for each error the non-error text between the current and the last error has
1666cdf0e10cSrcweir         // to be added to the portions - if necessary broken into same-language-portions
1667cdf0e10cSrcweir         if( !bGrammarErrorFound ) //in grammar check there's only one error returned
1668cdf0e10cSrcweir         {
1669cdf0e10cSrcweir             do
1670cdf0e10cSrcweir             {
1671cdf0e10cSrcweir                 xSpellRet = 0;
1672cdf0e10cSrcweir                 // don't search for grammar errors here anymore!
1673cdf0e10cSrcweir                 pMySh->GetDoc()->Spell(*pCrsr,
1674cdf0e10cSrcweir                             xSpeller, 0, 0, false ) >>= xSpellRet;
1675cdf0e10cSrcweir                 if ( *pCrsr->GetPoint() > *pCrsr->GetMark() )
1676cdf0e10cSrcweir                     pCrsr->Exchange();
1677cdf0e10cSrcweir                 SetCurr( new SwPosition( *pCrsr->GetPoint() ));
1678cdf0e10cSrcweir                 SetCurrX( new SwPosition( *pCrsr->GetMark() ));
1679cdf0e10cSrcweir 
1680cdf0e10cSrcweir                 //if an error has been found go back to the text
1681cdf0e10cSrcweir                 //preceeding the error
1682cdf0e10cSrcweir                 if(xSpellRet.is())
1683cdf0e10cSrcweir                 {
1684cdf0e10cSrcweir                     *pCrsr->GetPoint() = aSaveStartPos;
1685cdf0e10cSrcweir                     *pCrsr->GetMark() = *GetCurr();
1686cdf0e10cSrcweir                 }
1687cdf0e10cSrcweir                 //add the portion
1688cdf0e10cSrcweir                 AddPortion(0, 0, aDeletedRedlines);
1689cdf0e10cSrcweir 
1690cdf0e10cSrcweir                 if(xSpellRet.is())
1691cdf0e10cSrcweir                 {
1692cdf0e10cSrcweir                     *pCrsr->GetPoint() = *GetCurr();
1693cdf0e10cSrcweir                     *pCrsr->GetMark() = *GetCurrX();
1694cdf0e10cSrcweir                     AddPortion(xSpellRet, 0, aDeletedRedlines);
1695cdf0e10cSrcweir                     //move the cursor to the end of the error string
1696cdf0e10cSrcweir                     *pCrsr->GetPoint() = *GetCurrX();
1697cdf0e10cSrcweir                     //and save the end of the error as new start position
1698cdf0e10cSrcweir                     aSaveStartPos = *GetCurrX();
1699cdf0e10cSrcweir                     //and the end of the sentence
1700cdf0e10cSrcweir                     *pCrsr->GetMark() = *GetEnd();
1701cdf0e10cSrcweir                 }
1702cdf0e10cSrcweir                 // if the end of the sentence has already been reached then break here
1703cdf0e10cSrcweir                 if(*GetCurrX() >= *GetEnd())
1704cdf0e10cSrcweir                     break;
1705cdf0e10cSrcweir             }
1706cdf0e10cSrcweir             while(xSpellRet.is());
1707cdf0e10cSrcweir         }
1708cdf0e10cSrcweir         else
1709cdf0e10cSrcweir         {
1710cdf0e10cSrcweir             //go to the end of sentence as the grammar check returned it
1711cdf0e10cSrcweir             // at this time the Point is behind the grammar error
1712cdf0e10cSrcweir             // and the mark points to the sentence end as
1713cdf0e10cSrcweir             if ( *pCrsr->GetPoint() < *pCrsr->GetMark() )
1714cdf0e10cSrcweir                 pCrsr->Exchange();
1715cdf0e10cSrcweir         }
1716cdf0e10cSrcweir 
1717cdf0e10cSrcweir         // the part between the last error and the end of the sentence has to be added
1718cdf0e10cSrcweir         *pMySh->GetCrsr()->GetPoint() = *GetEnd();
1719cdf0e10cSrcweir         if(*GetCurrX() < *GetEnd())
1720cdf0e10cSrcweir         {
1721cdf0e10cSrcweir             AddPortion(0, 0, aDeletedRedlines);
1722cdf0e10cSrcweir         }
1723cdf0e10cSrcweir         //set the shell cursor to the end of the sentence to prevent a visible selection
1724cdf0e10cSrcweir         *pCrsr->GetMark() = *GetEnd();
1725cdf0e10cSrcweir 		if( !bIsGrammarCheck )
1726cdf0e10cSrcweir         {
1727cdf0e10cSrcweir             //set the current position to the end of the sentence
1728cdf0e10cSrcweir             SetCurr( new SwPosition(*GetEnd()) );
1729cdf0e10cSrcweir         }
1730cdf0e10cSrcweir         //restore the 'global' end
1731cdf0e10cSrcweir         SetEnd( new SwPosition(aSaveEndPos) );
1732cdf0e10cSrcweir         rPortions = aLastPortions;
1733cdf0e10cSrcweir         bRet = true;
1734cdf0e10cSrcweir     }
1735cdf0e10cSrcweir     else
1736cdf0e10cSrcweir     {
1737cdf0e10cSrcweir         //if no error could be found the selection has to be corrected - at least if it's not in the body
1738cdf0e10cSrcweir         *pMySh->GetCrsr()->GetPoint() = *GetEnd();
1739cdf0e10cSrcweir         pMySh->GetCrsr()->DeleteMark();
1740cdf0e10cSrcweir     }
1741cdf0e10cSrcweir 
1742cdf0e10cSrcweir     return bRet;
1743cdf0e10cSrcweir }
1744cdf0e10cSrcweir 
1745cdf0e10cSrcweir /*-- 08.09.2008 09:37:15---------------------------------------------------
1746cdf0e10cSrcweir 
1747cdf0e10cSrcweir   -----------------------------------------------------------------------*/
ToSentenceStart()1748cdf0e10cSrcweir void SwSpellIter::ToSentenceStart()
1749cdf0e10cSrcweir {
1750cdf0e10cSrcweir     bBackToStartOfSentence = true;
1751cdf0e10cSrcweir }
1752cdf0e10cSrcweir /*-- 08.10.2003 08:49:56---------------------------------------------------
1753cdf0e10cSrcweir 
1754cdf0e10cSrcweir   -----------------------------------------------------------------------*/
lcl_GetLanguage(SwEditShell & rSh)1755cdf0e10cSrcweir LanguageType lcl_GetLanguage(SwEditShell& rSh)
1756cdf0e10cSrcweir {
1757cdf0e10cSrcweir     sal_uInt16 nScriptType = rSh.GetScriptType();
1758cdf0e10cSrcweir     sal_uInt16 nLangWhichId = RES_CHRATR_LANGUAGE;
1759cdf0e10cSrcweir 
1760cdf0e10cSrcweir     switch(nScriptType)
1761cdf0e10cSrcweir     {
1762cdf0e10cSrcweir         case SCRIPTTYPE_ASIAN : nLangWhichId = RES_CHRATR_CJK_LANGUAGE; break;
1763cdf0e10cSrcweir         case SCRIPTTYPE_COMPLEX : nLangWhichId = RES_CHRATR_CTL_LANGUAGE; break;
1764cdf0e10cSrcweir     }
1765cdf0e10cSrcweir     SfxItemSet aSet(rSh.GetAttrPool(), nLangWhichId, nLangWhichId, 0);
1766cdf0e10cSrcweir     rSh.GetCurAttr( aSet );
1767cdf0e10cSrcweir     const SvxLanguageItem& rLang = static_cast<const SvxLanguageItem& >(aSet.Get(nLangWhichId));
1768cdf0e10cSrcweir     return rLang.GetLanguage();
1769cdf0e10cSrcweir }
1770cdf0e10cSrcweir /*-- 08.10.2003 08:53:27---------------------------------------------------
1771cdf0e10cSrcweir     create a text portion at the given position
1772cdf0e10cSrcweir   -----------------------------------------------------------------------*/
CreatePortion(uno::Reference<XSpellAlternatives> xAlt,linguistic2::ProofreadingResult * pGrammarResult,bool bIsField,bool bIsHidden)1773cdf0e10cSrcweir void SwSpellIter::CreatePortion(uno::Reference< XSpellAlternatives > xAlt,
1774cdf0e10cSrcweir                         linguistic2::ProofreadingResult* pGrammarResult,
1775cdf0e10cSrcweir         bool bIsField, bool bIsHidden)
1776cdf0e10cSrcweir {
1777cdf0e10cSrcweir     svx::SpellPortion aPortion;
1778cdf0e10cSrcweir     String sText;
1779cdf0e10cSrcweir     GetSh()->GetSelectedText( sText );
1780cdf0e10cSrcweir 	if(sText.Len())
1781cdf0e10cSrcweir 	{
1782cdf0e10cSrcweir         //in case of redlined deletions the selection of an error is not
1783cdf0e10cSrcweir         //the same as the _real_ word
1784cdf0e10cSrcweir         if(xAlt.is())
1785cdf0e10cSrcweir             aPortion.sText = xAlt->getWord();
1786cdf0e10cSrcweir         else if(pGrammarResult)
1787cdf0e10cSrcweir         {
1788cdf0e10cSrcweir             aPortion.bIsGrammarError = true;
1789cdf0e10cSrcweir             if(pGrammarResult->aErrors.getLength())
1790cdf0e10cSrcweir             {
1791cdf0e10cSrcweir                 aPortion.aGrammarError = pGrammarResult->aErrors[0];
1792cdf0e10cSrcweir                 aPortion.sText = pGrammarResult->aText.copy( aPortion.aGrammarError.nErrorStart, aPortion.aGrammarError.nErrorLength );
1793cdf0e10cSrcweir                 aPortion.xGrammarChecker = pGrammarResult->xProofreader;
1794cdf0e10cSrcweir                 const beans::PropertyValue* pProperties = pGrammarResult->aProperties.getConstArray();
1795cdf0e10cSrcweir                 for( sal_Int32 nProp = 0; nProp < pGrammarResult->aProperties.getLength(); ++nProp )
1796cdf0e10cSrcweir                 {
1797cdf0e10cSrcweir                     if( pProperties->Name.equalsAscii("DialogTitle") )
1798cdf0e10cSrcweir                     {
1799cdf0e10cSrcweir                         pProperties->Value >>= aPortion.sDialogTitle;
1800cdf0e10cSrcweir                         break;
1801cdf0e10cSrcweir                     }
1802cdf0e10cSrcweir                 }
1803cdf0e10cSrcweir             }
1804cdf0e10cSrcweir         }
1805cdf0e10cSrcweir         else
1806cdf0e10cSrcweir             aPortion.sText = sText;
1807cdf0e10cSrcweir 		aPortion.eLanguage = lcl_GetLanguage(*GetSh());
1808cdf0e10cSrcweir 		aPortion.bIsField = bIsField;
1809cdf0e10cSrcweir         aPortion.bIsHidden = bIsHidden;
1810cdf0e10cSrcweir 		aPortion.xAlternatives = xAlt;
1811cdf0e10cSrcweir 		SpellContentPosition aPosition;
1812cdf0e10cSrcweir 		SwPaM *pCrsr = GetSh()->GetCrsr();
1813cdf0e10cSrcweir 		aPosition.nLeft = pCrsr->Start()->nContent.GetIndex();
1814cdf0e10cSrcweir 		aPosition.nRight = pCrsr->End()->nContent.GetIndex();
1815cdf0e10cSrcweir 		aLastPortions.push_back(aPortion);
1816cdf0e10cSrcweir 		aLastPositions.push_back(aPosition);
1817cdf0e10cSrcweir 	}
1818cdf0e10cSrcweir }
1819cdf0e10cSrcweir /*-- 19.09.2003 13:05:43---------------------------------------------------
1820cdf0e10cSrcweir 
1821cdf0e10cSrcweir   -----------------------------------------------------------------------*/
AddPortion(uno::Reference<XSpellAlternatives> xAlt,linguistic2::ProofreadingResult * pGrammarResult,const SpellContentPositions & rDeletedRedlines)1822cdf0e10cSrcweir void    SwSpellIter::AddPortion(uno::Reference< XSpellAlternatives > xAlt,
1823cdf0e10cSrcweir                                 linguistic2::ProofreadingResult* pGrammarResult,
1824cdf0e10cSrcweir                                 const SpellContentPositions& rDeletedRedlines)
1825cdf0e10cSrcweir {
1826cdf0e10cSrcweir     SwEditShell *pMySh = GetSh();
1827cdf0e10cSrcweir     String sText;
1828cdf0e10cSrcweir     pMySh->GetSelectedText( sText );
1829cdf0e10cSrcweir     if(sText.Len())
1830cdf0e10cSrcweir     {
1831cdf0e10cSrcweir         if(xAlt.is() || pGrammarResult != 0)
1832cdf0e10cSrcweir         {
1833cdf0e10cSrcweir             CreatePortion(xAlt, pGrammarResult, false, false);
1834cdf0e10cSrcweir         }
1835cdf0e10cSrcweir         else
1836cdf0e10cSrcweir         {
1837cdf0e10cSrcweir             SwPaM *pCrsr = GetSh()->GetCrsr();
1838cdf0e10cSrcweir             if ( *pCrsr->GetPoint() > *pCrsr->GetMark() )
1839cdf0e10cSrcweir                 pCrsr->Exchange();
1840cdf0e10cSrcweir             //save the start and end positions
1841cdf0e10cSrcweir             SwPosition aStart(*pCrsr->GetPoint());
1842cdf0e10cSrcweir             SwPosition aEnd(*pCrsr->GetMark());
1843cdf0e10cSrcweir             //iterate over the text to find changes in language
1844cdf0e10cSrcweir             //set the mark equal to the point
1845cdf0e10cSrcweir             *pCrsr->GetMark() = aStart;
1846cdf0e10cSrcweir             SwTxtNode* pTxtNode = pCrsr->GetNode()->GetTxtNode();
1847cdf0e10cSrcweir             LanguageType eStartLanguage = lcl_GetLanguage(*GetSh());
1848cdf0e10cSrcweir             SpellContentPosition  aNextRedline = lcl_FindNextDeletedRedline(
1849cdf0e10cSrcweir                         rDeletedRedlines, aStart.nContent.GetIndex() );
1850cdf0e10cSrcweir             if( aNextRedline.nLeft == aStart.nContent.GetIndex() )
1851cdf0e10cSrcweir             {
1852cdf0e10cSrcweir                 //select until the end of the current redline
1853cdf0e10cSrcweir                 xub_StrLen nEnd = aEnd.nContent.GetIndex() < aNextRedline.nRight ?
1854cdf0e10cSrcweir                             aEnd.nContent.GetIndex() : aNextRedline.nRight;
1855cdf0e10cSrcweir                 pCrsr->GetPoint()->nContent.Assign( pTxtNode, nEnd );
1856cdf0e10cSrcweir                 CreatePortion(xAlt, pGrammarResult, false, true);
1857cdf0e10cSrcweir                 aStart = *pCrsr->End();
1858cdf0e10cSrcweir                 //search for next redline
1859cdf0e10cSrcweir                 aNextRedline = lcl_FindNextDeletedRedline(
1860cdf0e10cSrcweir                             rDeletedRedlines, aStart.nContent.GetIndex() );
1861cdf0e10cSrcweir             }
1862cdf0e10cSrcweir             while(*pCrsr->GetPoint() < aEnd)
1863cdf0e10cSrcweir             {
1864cdf0e10cSrcweir                 //#125786 in table cell with fixed row height the cursor might not move forward
1865cdf0e10cSrcweir                 if(!GetSh()->Right(1, CRSR_SKIP_CELLS))
1866cdf0e10cSrcweir                     break;
1867cdf0e10cSrcweir 
1868cdf0e10cSrcweir                 bool bField = false;
1869cdf0e10cSrcweir                 //read the character at the current position to check if it's a field
1870cdf0e10cSrcweir                 xub_Unicode cChar = pTxtNode->GetTxt().GetChar( pCrsr->GetMark()->nContent.GetIndex() );
1871cdf0e10cSrcweir                 if( CH_TXTATR_BREAKWORD == cChar || CH_TXTATR_INWORD == cChar)
1872cdf0e10cSrcweir                 {
1873cdf0e10cSrcweir                     const SwTxtAttr* pTxtAttr = pTxtNode->GetTxtAttrForCharAt(
1874cdf0e10cSrcweir                         pCrsr->GetMark()->nContent.GetIndex() );
1875cdf0e10cSrcweir                     const sal_uInt16 nWhich = pTxtAttr
1876cdf0e10cSrcweir                         ? pTxtAttr->Which()
1877cdf0e10cSrcweir                         : static_cast<sal_uInt16>(RES_TXTATR_END);
1878cdf0e10cSrcweir                     switch (nWhich)
1879cdf0e10cSrcweir                     {
1880cdf0e10cSrcweir                         case RES_TXTATR_FIELD:
1881*dec99bbdSOliver-Rainer Wittmann                         case RES_TXTATR_ANNOTATION:
1882cdf0e10cSrcweir                         case RES_TXTATR_FTN:
1883cdf0e10cSrcweir                         case RES_TXTATR_FLYCNT:
1884cdf0e10cSrcweir                             bField = true;
1885cdf0e10cSrcweir                             break;
1886cdf0e10cSrcweir                     }
1887cdf0e10cSrcweir                 }
1888cdf0e10cSrcweir 
1889cdf0e10cSrcweir                 LanguageType eCurLanguage = lcl_GetLanguage(*GetSh());
1890cdf0e10cSrcweir                 bool bRedline = aNextRedline.nLeft == pCrsr->GetPoint()->nContent.GetIndex();
1891cdf0e10cSrcweir                 // create a portion if the next character
1892cdf0e10cSrcweir                 //  - is a field,
1893cdf0e10cSrcweir                 //  - is at the beginning of a deleted redline
1894cdf0e10cSrcweir                 //  - has a different language
1895cdf0e10cSrcweir                 if(bField || bRedline || eCurLanguage != eStartLanguage)
1896cdf0e10cSrcweir                 {
1897cdf0e10cSrcweir                     eStartLanguage = eCurLanguage;
1898cdf0e10cSrcweir                     //go one step back - the cursor currently selects the first character
1899cdf0e10cSrcweir                     //with a different language
1900cdf0e10cSrcweir                     //in the case of redlining it's different
1901cdf0e10cSrcweir                     if(eCurLanguage != eStartLanguage || bField)
1902cdf0e10cSrcweir                         *pCrsr->GetPoint() = *pCrsr->GetMark();
1903cdf0e10cSrcweir                     //set to the last start
1904cdf0e10cSrcweir                     *pCrsr->GetMark() = aStart;
1905cdf0e10cSrcweir                     //create portion should only be called if a selection exists
1906cdf0e10cSrcweir                     //there's no selection if there's a field at the beginning
1907cdf0e10cSrcweir                     if(*pCrsr->Start() != *pCrsr->End())
1908cdf0e10cSrcweir                         CreatePortion(xAlt, pGrammarResult, false, false);
1909cdf0e10cSrcweir                     aStart = *pCrsr->End();
1910cdf0e10cSrcweir                     //now export the field - if there is any
1911cdf0e10cSrcweir                     if(bField)
1912cdf0e10cSrcweir                     {
1913cdf0e10cSrcweir                         *pCrsr->GetMark() = *pCrsr->GetPoint();
1914cdf0e10cSrcweir                         GetSh()->Right(1, CRSR_SKIP_CELLS);
1915cdf0e10cSrcweir                         CreatePortion(xAlt, pGrammarResult, true, false);
1916cdf0e10cSrcweir                         aStart = *pCrsr->End();
1917cdf0e10cSrcweir                     }
1918cdf0e10cSrcweir                 }
1919cdf0e10cSrcweir                 // if a redline start then create a portion for it
1920cdf0e10cSrcweir                 if(bRedline)
1921cdf0e10cSrcweir                 {
1922cdf0e10cSrcweir                     *pCrsr->GetMark() = *pCrsr->GetPoint();
1923cdf0e10cSrcweir                     //select until the end of the current redline
1924cdf0e10cSrcweir                     xub_StrLen nEnd = aEnd.nContent.GetIndex() < aNextRedline.nRight ?
1925cdf0e10cSrcweir                                 aEnd.nContent.GetIndex() : aNextRedline.nRight;
1926cdf0e10cSrcweir                     pCrsr->GetPoint()->nContent.Assign( pTxtNode, nEnd );
1927cdf0e10cSrcweir                     CreatePortion(xAlt, pGrammarResult, false, true);
1928cdf0e10cSrcweir                     aStart = *pCrsr->End();
1929cdf0e10cSrcweir                     //search for next redline
1930cdf0e10cSrcweir                     aNextRedline = lcl_FindNextDeletedRedline(
1931cdf0e10cSrcweir                                 rDeletedRedlines, aStart.nContent.GetIndex() );
1932cdf0e10cSrcweir                 }
1933cdf0e10cSrcweir                 *pCrsr->GetMark() = *pCrsr->GetPoint();
1934cdf0e10cSrcweir             }
1935cdf0e10cSrcweir             pCrsr->SetMark();
1936cdf0e10cSrcweir             *pCrsr->GetMark() = aStart;
1937cdf0e10cSrcweir             CreatePortion(xAlt, pGrammarResult, false, false);
1938cdf0e10cSrcweir         }
1939cdf0e10cSrcweir     }
1940cdf0e10cSrcweir }
1941cdf0e10cSrcweir /*-- 07.08.2008 15:01:25---------------------------------------------------
1942cdf0e10cSrcweir 
1943cdf0e10cSrcweir   -----------------------------------------------------------------------*/
IgnoreGrammarErrorAt(SwPaM & rErrorPosition)1944cdf0e10cSrcweir void SwEditShell::IgnoreGrammarErrorAt( SwPaM& rErrorPosition )
1945cdf0e10cSrcweir {
1946cdf0e10cSrcweir     SwTxtNode *pNode;
1947cdf0e10cSrcweir     SwWrongList *pWrong;
1948cdf0e10cSrcweir     SwNodeIndex aIdx = rErrorPosition.Start()->nNode;
1949cdf0e10cSrcweir     SwNodeIndex aEndIdx = rErrorPosition.Start()->nNode;
1950cdf0e10cSrcweir     xub_StrLen nStart = rErrorPosition.Start()->nContent.GetIndex();
1951cdf0e10cSrcweir     xub_StrLen nEnd = STRING_LEN;
1952cdf0e10cSrcweir     while( aIdx <= aEndIdx )
1953cdf0e10cSrcweir     {
1954cdf0e10cSrcweir         pNode = aIdx.GetNode().GetTxtNode();
1955cdf0e10cSrcweir         if( pNode ) {
1956cdf0e10cSrcweir             if( aIdx == aEndIdx )
1957cdf0e10cSrcweir                 nEnd = rErrorPosition.End()->nContent.GetIndex();
1958cdf0e10cSrcweir             pWrong = pNode->GetGrammarCheck();
1959cdf0e10cSrcweir             if( pWrong )
1960cdf0e10cSrcweir                 pWrong->RemoveEntry( nStart, nEnd );
1961cdf0e10cSrcweir             pWrong = pNode->GetWrong();
1962cdf0e10cSrcweir             if( pWrong )
1963cdf0e10cSrcweir                 pWrong->RemoveEntry( nStart, nEnd );
1964cdf0e10cSrcweir             SwTxtFrm::repaintTextFrames( *pNode );
1965cdf0e10cSrcweir         }
1966cdf0e10cSrcweir         ++aIdx;
1967cdf0e10cSrcweir         nStart = 0;
1968cdf0e10cSrcweir     }
1969cdf0e10cSrcweir }
1970cdf0e10cSrcweir 
1971cdf0e10cSrcweir 
1972