xref: /aoo41x/main/editeng/source/misc/splwrap.cxx (revision 190118d0)
1*190118d0SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*190118d0SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*190118d0SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*190118d0SAndrew Rist  * distributed with this work for additional information
6*190118d0SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*190118d0SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*190118d0SAndrew Rist  * "License"); you may not use this file except in compliance
9*190118d0SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*190118d0SAndrew Rist  *
11*190118d0SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*190118d0SAndrew Rist  *
13*190118d0SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*190118d0SAndrew Rist  * software distributed under the License is distributed on an
15*190118d0SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*190118d0SAndrew Rist  * KIND, either express or implied.  See the License for the
17*190118d0SAndrew Rist  * specific language governing permissions and limitations
18*190118d0SAndrew Rist  * under the License.
19*190118d0SAndrew Rist  *
20*190118d0SAndrew Rist  *************************************************************/
21*190118d0SAndrew Rist 
22*190118d0SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_editeng.hxx"
26cdf0e10cSrcweir #include<rtl/ustring.hxx>
27cdf0e10cSrcweir #include <tools/shl.hxx>
28cdf0e10cSrcweir #include <vcl/wrkwin.hxx>
29cdf0e10cSrcweir #include <vcl/svapp.hxx>
30cdf0e10cSrcweir #include <vcl/msgbox.hxx>
31cdf0e10cSrcweir #include <tools/debug.hxx>
32cdf0e10cSrcweir #include <svtools/langtab.hxx>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #ifndef __RSC
35cdf0e10cSrcweir #include <tools/errinf.hxx>
36cdf0e10cSrcweir #endif
37cdf0e10cSrcweir #include <editeng/unolingu.hxx>
38cdf0e10cSrcweir #include <linguistic/lngprops.hxx>
39cdf0e10cSrcweir #include <com/sun/star/frame/XStorable.hpp>
40cdf0e10cSrcweir 
41cdf0e10cSrcweir #include <map>
42cdf0e10cSrcweir 
43cdf0e10cSrcweir #include <editeng/svxenum.hxx>
44cdf0e10cSrcweir #include <editeng/splwrap.hxx>      // Der Wrapper
45cdf0e10cSrcweir #include <editeng/edtdlg.hxx>
46cdf0e10cSrcweir #include <editeng/eerdll.hxx>
47cdf0e10cSrcweir #include <editeng/editrids.hrc>
48cdf0e10cSrcweir #include <editeng/editids.hrc>
49cdf0e10cSrcweir #include <editeng/editerr.hxx>
50cdf0e10cSrcweir 
51cdf0e10cSrcweir #define WAIT_ON() if(pWin != NULL) { pWin->EnterWait(); }
52cdf0e10cSrcweir 
53cdf0e10cSrcweir #define WAIT_OFF() if(pWin != NULL) { pWin->LeaveWait(); }
54cdf0e10cSrcweir 
55cdf0e10cSrcweir using namespace ::com::sun::star;
56cdf0e10cSrcweir using namespace ::com::sun::star::uno;
57cdf0e10cSrcweir using namespace ::com::sun::star::beans;
58cdf0e10cSrcweir using namespace ::com::sun::star::linguistic2;
59cdf0e10cSrcweir 
60cdf0e10cSrcweir 
61cdf0e10cSrcweir // misc functions ---------------------------------------------
62cdf0e10cSrcweir 
63cdf0e10cSrcweir void SvxPrepareAutoCorrect( String &rOldText, String &rNewText )
64cdf0e10cSrcweir {
65cdf0e10cSrcweir 	// This function should be used to strip (or add) trailing '.' from
66cdf0e10cSrcweir 	// the strings before passing them on to the autocorrect function in
67cdf0e10cSrcweir 	// order that the autocorrect function will hopefully
68cdf0e10cSrcweir 	// works properly with normal words and abbreviations (with trailing '.')
69cdf0e10cSrcweir 	// independ of if they are at the end of the sentence or not.
70cdf0e10cSrcweir 	//
71cdf0e10cSrcweir 	// rOldText: text to be replaced
72cdf0e10cSrcweir 	// rNewText: replacement text
73cdf0e10cSrcweir 
74cdf0e10cSrcweir 	xub_StrLen	nOldLen = rOldText.Len(),
75cdf0e10cSrcweir 				nNewLen = rNewText.Len();
76cdf0e10cSrcweir 	if (nOldLen && nNewLen)
77cdf0e10cSrcweir 	{
78cdf0e10cSrcweir 		sal_Bool bOldHasDot = sal_Unicode( '.' ) == rOldText.GetChar( nOldLen - 1 ),
79cdf0e10cSrcweir 			 bNewHasDot = sal_Unicode( '.' ) == rNewText.GetChar( nNewLen - 1 );
80cdf0e10cSrcweir 		if (bOldHasDot && !bNewHasDot
81cdf0e10cSrcweir 			/*this is: !(bOldHasDot && bNewHasDot) && bOldHasDot*/)
82cdf0e10cSrcweir 			rOldText.Erase( nOldLen - 1 );
83cdf0e10cSrcweir 	}
84cdf0e10cSrcweir }
85cdf0e10cSrcweir 
86cdf0e10cSrcweir // -----------------------------------------------------------------------
87cdf0e10cSrcweir 
88cdf0e10cSrcweir #define SVX_LANG_NEED_CHECK			0
89cdf0e10cSrcweir #define SVX_LANG_OK					1
90cdf0e10cSrcweir #define SVX_LANG_MISSING			2
91cdf0e10cSrcweir #define SVX_LANG_MISSING_DO_WARN	3
92cdf0e10cSrcweir 
93cdf0e10cSrcweir #define SVX_FLAGS_NEW
94cdf0e10cSrcweir 
95cdf0e10cSrcweir 
96cdf0e10cSrcweir struct lt_LanguageType
97cdf0e10cSrcweir {
98cdf0e10cSrcweir     bool operator()( LanguageType n1, LanguageType n2 ) const
99cdf0e10cSrcweir     {
100cdf0e10cSrcweir         return n1 < n2;
101cdf0e10cSrcweir     }
102cdf0e10cSrcweir };
103cdf0e10cSrcweir 
104cdf0e10cSrcweir typedef std::map< LanguageType, sal_uInt16, lt_LanguageType >   LangCheckState_map_t;
105cdf0e10cSrcweir 
106cdf0e10cSrcweir static LangCheckState_map_t & GetLangCheckState()
107cdf0e10cSrcweir {
108cdf0e10cSrcweir     static LangCheckState_map_t aLangCheckState;
109cdf0e10cSrcweir     return aLangCheckState;
110cdf0e10cSrcweir }
111cdf0e10cSrcweir 
112cdf0e10cSrcweir void SvxSpellWrapper::ShowLanguageErrors()
113cdf0e10cSrcweir {
114cdf0e10cSrcweir     // display message boxes for languages not available for
115cdf0e10cSrcweir     // spellchecking or hyphenation
116cdf0e10cSrcweir     LangCheckState_map_t &rLCS = GetLangCheckState();
117cdf0e10cSrcweir     LangCheckState_map_t::iterator aIt( rLCS.begin() );
118cdf0e10cSrcweir     while (aIt != rLCS.end())
119cdf0e10cSrcweir 	{
120cdf0e10cSrcweir         LanguageType nLang = aIt->first;
121cdf0e10cSrcweir         sal_uInt16   nVal  = aIt->second;
122cdf0e10cSrcweir 		sal_uInt16 nTmpSpell = nVal & 0x00FF;
123cdf0e10cSrcweir 		sal_uInt16 nTmpHyph  = (nVal >> 8) & 0x00FF;
124cdf0e10cSrcweir 
125cdf0e10cSrcweir 		if (SVX_LANG_MISSING_DO_WARN == nTmpSpell)
126cdf0e10cSrcweir 		{
127cdf0e10cSrcweir 			String aErr( SvtLanguageTable::GetLanguageString( nLang ) );
128cdf0e10cSrcweir 			ErrorHandler::HandleError(
129cdf0e10cSrcweir 				*new StringErrorInfo( ERRCODE_SVX_LINGU_LANGUAGENOTEXISTS, aErr ) );
130cdf0e10cSrcweir 			nTmpSpell = SVX_LANG_MISSING;
131cdf0e10cSrcweir 		}
132cdf0e10cSrcweir 		if (SVX_LANG_MISSING_DO_WARN == nTmpHyph)
133cdf0e10cSrcweir 		{
134cdf0e10cSrcweir 			String aErr( SvtLanguageTable::GetLanguageString( nLang ) );
135cdf0e10cSrcweir 			ErrorHandler::HandleError(
136cdf0e10cSrcweir 				*new StringErrorInfo( ERRCODE_SVX_LINGU_LANGUAGENOTEXISTS, aErr ) );
137cdf0e10cSrcweir 			nTmpHyph = SVX_LANG_MISSING;
138cdf0e10cSrcweir 		}
139cdf0e10cSrcweir 
140cdf0e10cSrcweir         rLCS[ nLang ] = (nTmpHyph << 8) | nTmpSpell;
141cdf0e10cSrcweir         ++aIt;
142cdf0e10cSrcweir 	}
143cdf0e10cSrcweir 
144cdf0e10cSrcweir }
145cdf0e10cSrcweir 
146cdf0e10cSrcweir SvxSpellWrapper::~SvxSpellWrapper()
147cdf0e10cSrcweir {
148cdf0e10cSrcweir }
149cdf0e10cSrcweir 
150cdf0e10cSrcweir /*--------------------------------------------------------------------
151cdf0e10cSrcweir  *	Beschreibung: Ctor, die Pruefreihenfolge wird festgelegt
152cdf0e10cSrcweir  *
153cdf0e10cSrcweir  *  !bStart && !bOtherCntnt:	BODY_END,	BODY_START,	OTHER
154cdf0e10cSrcweir  *  !bStart && bOtherCntnt:		OTHER,		BODY
155cdf0e10cSrcweir  *  bStart && !bOtherCntnt:		BODY_END,	OTHER
156cdf0e10cSrcweir  *  bStart && bOtherCntnt:		OTHER
157cdf0e10cSrcweir  *
158cdf0e10cSrcweir  --------------------------------------------------------------------*/
159cdf0e10cSrcweir 
160cdf0e10cSrcweir SvxSpellWrapper::SvxSpellWrapper( Window* pWn,
161cdf0e10cSrcweir 	Reference< XSpellChecker1 >  &xSpellChecker,
162cdf0e10cSrcweir 	const sal_Bool bStart, const sal_Bool bIsAllRight,
163cdf0e10cSrcweir 	const sal_Bool bOther, const sal_Bool bRevAllow ) :
164cdf0e10cSrcweir 
165cdf0e10cSrcweir 	pWin		( pWn ),
166cdf0e10cSrcweir 	xSpell		( xSpellChecker ),
167cdf0e10cSrcweir 	bOtherCntnt	( bOther ),
168cdf0e10cSrcweir 	bDialog		( sal_False ),
169cdf0e10cSrcweir 	bHyphen		( sal_False ),
170cdf0e10cSrcweir 	bAuto		( sal_False ),
171cdf0e10cSrcweir 	bStartChk	( bOther ),
172cdf0e10cSrcweir     bRevAllowed ( bRevAllow ),
173cdf0e10cSrcweir     bAllRight   ( bIsAllRight )
174cdf0e10cSrcweir {
175cdf0e10cSrcweir 	Reference< beans::XPropertySet >  xProp( SvxGetLinguPropertySet() );
176cdf0e10cSrcweir 	sal_Bool bWrapReverse = xProp.is() ?
177cdf0e10cSrcweir 		*(sal_Bool*)xProp->getPropertyValue(
178cdf0e10cSrcweir 			::rtl::OUString::createFromAscii(UPN_IS_WRAP_REVERSE) ).getValue()
179cdf0e10cSrcweir 		: sal_False;
180cdf0e10cSrcweir 	bReverse = bRevAllow && bWrapReverse;
181cdf0e10cSrcweir 	bStartDone = bOther || ( !bReverse && bStart );
182cdf0e10cSrcweir 	bEndDone   = bReverse && bStart && !bOther;
183cdf0e10cSrcweir }
184cdf0e10cSrcweir 
185cdf0e10cSrcweir // -----------------------------------------------------------------------
186cdf0e10cSrcweir 
187cdf0e10cSrcweir SvxSpellWrapper::SvxSpellWrapper( Window* pWn,
188cdf0e10cSrcweir 		Reference< XHyphenator >  &xHyphenator,
189cdf0e10cSrcweir 		const sal_Bool bStart, const sal_Bool bOther ) :
190cdf0e10cSrcweir 	pWin		( pWn ),
191cdf0e10cSrcweir 	xHyph		( xHyphenator ),
192cdf0e10cSrcweir 	bOtherCntnt	( bOther ),
193cdf0e10cSrcweir 	bDialog		( sal_False ),
194cdf0e10cSrcweir 	bHyphen		( sal_False ),
195cdf0e10cSrcweir 	bAuto		( sal_False ),
196cdf0e10cSrcweir 	bReverse	( sal_False ),
197cdf0e10cSrcweir 	bStartDone	( bOther || ( !bReverse && bStart ) ),
198cdf0e10cSrcweir 	bEndDone	( bReverse && bStart && !bOther ),
199cdf0e10cSrcweir 	bStartChk	( bOther ),
200cdf0e10cSrcweir     bRevAllowed ( sal_False ),
201cdf0e10cSrcweir     bAllRight   ( sal_True )
202cdf0e10cSrcweir {
203cdf0e10cSrcweir }
204cdf0e10cSrcweir 
205cdf0e10cSrcweir // -----------------------------------------------------------------------
206cdf0e10cSrcweir 
207cdf0e10cSrcweir sal_Int16 SvxSpellWrapper::CheckSpellLang(
208cdf0e10cSrcweir 		Reference< XSpellChecker1 > xSpell, sal_Int16 nLang)
209cdf0e10cSrcweir {
210cdf0e10cSrcweir     LangCheckState_map_t &rLCS = GetLangCheckState();
211cdf0e10cSrcweir 
212cdf0e10cSrcweir     LangCheckState_map_t::iterator aIt( rLCS.find( nLang ) );
213cdf0e10cSrcweir     sal_uInt16 nVal = aIt == rLCS.end() ? SVX_LANG_NEED_CHECK : aIt->second;
214cdf0e10cSrcweir 
215cdf0e10cSrcweir     if (aIt == rLCS.end())
216cdf0e10cSrcweir         rLCS[ nLang ] = nVal;
217cdf0e10cSrcweir 
218cdf0e10cSrcweir 	if (SVX_LANG_NEED_CHECK == (nVal & 0x00FF))
219cdf0e10cSrcweir 	{
220cdf0e10cSrcweir 		sal_uInt16 nTmpVal = SVX_LANG_MISSING_DO_WARN;
221cdf0e10cSrcweir 		if (xSpell.is()  &&  xSpell->hasLanguage( nLang ))
222cdf0e10cSrcweir 			nTmpVal = SVX_LANG_OK;
223cdf0e10cSrcweir 		nVal &= 0xFF00;
224cdf0e10cSrcweir 		nVal |= nTmpVal;
225cdf0e10cSrcweir 
226cdf0e10cSrcweir         rLCS[ nLang ] = nVal;
227cdf0e10cSrcweir 	}
228cdf0e10cSrcweir 
229cdf0e10cSrcweir     return (sal_Int16) nVal;
230cdf0e10cSrcweir }
231cdf0e10cSrcweir 
232cdf0e10cSrcweir sal_Int16 SvxSpellWrapper::CheckHyphLang(
233cdf0e10cSrcweir 		Reference< XHyphenator >  xHyph, sal_Int16 nLang)
234cdf0e10cSrcweir {
235cdf0e10cSrcweir     LangCheckState_map_t &rLCS = GetLangCheckState();
236cdf0e10cSrcweir 
237cdf0e10cSrcweir     LangCheckState_map_t::iterator aIt( rLCS.find( nLang ) );
238cdf0e10cSrcweir     sal_uInt16 nVal = aIt == rLCS.end() ? 0 : aIt->second;
239cdf0e10cSrcweir 
240cdf0e10cSrcweir     if (aIt == rLCS.end())
241cdf0e10cSrcweir         rLCS[ nLang ] = nVal;
242cdf0e10cSrcweir 
243cdf0e10cSrcweir 	if (SVX_LANG_NEED_CHECK == ((nVal >> 8) & 0x00FF))
244cdf0e10cSrcweir 	{
245cdf0e10cSrcweir 		sal_uInt16 nTmpVal = SVX_LANG_MISSING_DO_WARN;
246cdf0e10cSrcweir 		if (xHyph.is()  &&  xHyph->hasLocale( SvxCreateLocale( nLang ) ))
247cdf0e10cSrcweir 			nTmpVal = SVX_LANG_OK;
248cdf0e10cSrcweir 		nVal &= 0x00FF;
249cdf0e10cSrcweir 		nVal |= nTmpVal << 8;
250cdf0e10cSrcweir 
251cdf0e10cSrcweir         rLCS[ nLang ] = nVal;
252cdf0e10cSrcweir 	}
253cdf0e10cSrcweir 
254cdf0e10cSrcweir     return (sal_Int16) nVal;
255cdf0e10cSrcweir }
256cdf0e10cSrcweir 
257cdf0e10cSrcweir // -----------------------------------------------------------------------
258cdf0e10cSrcweir 
259cdf0e10cSrcweir 
260cdf0e10cSrcweir void SvxSpellWrapper::SpellStart( SvxSpellArea /*eSpell*/ )
261cdf0e10cSrcweir {	// Hier muessen die notwendigen Vorbereitungen fuer SpellContinue
262cdf0e10cSrcweir }	// im uebergebenen Bereich getroffen werden.
263cdf0e10cSrcweir 
264cdf0e10cSrcweir // -----------------------------------------------------------------------
265cdf0e10cSrcweir 
266cdf0e10cSrcweir 
267cdf0e10cSrcweir sal_Bool SvxSpellWrapper::HasOtherCnt()
268cdf0e10cSrcweir {
269cdf0e10cSrcweir 	return sal_False; // Gibt es ueberhaupt einen Sonderbereich?
270cdf0e10cSrcweir }
271cdf0e10cSrcweir 
272cdf0e10cSrcweir // -----------------------------------------------------------------------
273cdf0e10cSrcweir 
274cdf0e10cSrcweir 
275cdf0e10cSrcweir sal_Bool SvxSpellWrapper::SpellMore()
276cdf0e10cSrcweir {
277cdf0e10cSrcweir 	return sal_False; // Sollen weitere Dokumente geprueft werden?
278cdf0e10cSrcweir }
279cdf0e10cSrcweir 
280cdf0e10cSrcweir // -----------------------------------------------------------------------
281cdf0e10cSrcweir 
282cdf0e10cSrcweir 
283cdf0e10cSrcweir void SvxSpellWrapper::SpellEnd()
284cdf0e10cSrcweir {	// Bereich ist abgeschlossen, ggf. Aufraeumen
285cdf0e10cSrcweir 
286cdf0e10cSrcweir     // display error for last language not found
287cdf0e10cSrcweir     ShowLanguageErrors();
288cdf0e10cSrcweir }
289cdf0e10cSrcweir 
290cdf0e10cSrcweir // -----------------------------------------------------------------------
291cdf0e10cSrcweir 
292cdf0e10cSrcweir 
293cdf0e10cSrcweir sal_Bool SvxSpellWrapper::SpellContinue()
294cdf0e10cSrcweir {
295cdf0e10cSrcweir 	return sal_False;
296cdf0e10cSrcweir }
297cdf0e10cSrcweir 
298cdf0e10cSrcweir // -----------------------------------------------------------------------
299cdf0e10cSrcweir 
300cdf0e10cSrcweir void SvxSpellWrapper::AutoCorrect( const String&, const String& )
301cdf0e10cSrcweir {
302cdf0e10cSrcweir }
303cdf0e10cSrcweir 
304cdf0e10cSrcweir // -----------------------------------------------------------------------
305cdf0e10cSrcweir 
306cdf0e10cSrcweir 
307cdf0e10cSrcweir void SvxSpellWrapper::ScrollArea()
308cdf0e10cSrcweir {	// Scrollarea einstellen
309cdf0e10cSrcweir }
310cdf0e10cSrcweir 
311cdf0e10cSrcweir // -----------------------------------------------------------------------
312cdf0e10cSrcweir 
313cdf0e10cSrcweir 
314cdf0e10cSrcweir void SvxSpellWrapper::ChangeWord( const String&, const sal_uInt16 )
315cdf0e10cSrcweir {	// Wort ersetzen
316cdf0e10cSrcweir }
317cdf0e10cSrcweir 
318cdf0e10cSrcweir // -----------------------------------------------------------------------
319cdf0e10cSrcweir 
320cdf0e10cSrcweir 
321cdf0e10cSrcweir String SvxSpellWrapper::GetThesWord()
322cdf0e10cSrcweir {
323cdf0e10cSrcweir 	// Welches Wort soll nachgeschlagen werden?
324cdf0e10cSrcweir 	return String();
325cdf0e10cSrcweir }
326cdf0e10cSrcweir 
327cdf0e10cSrcweir // -----------------------------------------------------------------------
328cdf0e10cSrcweir 
329cdf0e10cSrcweir 
330cdf0e10cSrcweir void SvxSpellWrapper::ChangeThesWord( const String& )
331cdf0e10cSrcweir {
332cdf0e10cSrcweir 	// Wort wg. Thesaurus ersetzen
333cdf0e10cSrcweir }
334cdf0e10cSrcweir 
335cdf0e10cSrcweir // -----------------------------------------------------------------------
336cdf0e10cSrcweir 
337cdf0e10cSrcweir void SvxSpellWrapper::StartThesaurus( const String &rWord, sal_uInt16 nLanguage )
338cdf0e10cSrcweir {
339cdf0e10cSrcweir 	Reference< XThesaurus >  xThes( SvxGetThesaurus() );
340cdf0e10cSrcweir 	if (!xThes.is())
341cdf0e10cSrcweir 	{
342cdf0e10cSrcweir 		InfoBox( pWin, EE_RESSTR( RID_SVXSTR_HMERR_THESAURUS ) ).Execute();
343cdf0e10cSrcweir 		return;
344cdf0e10cSrcweir 	}
345cdf0e10cSrcweir 
346cdf0e10cSrcweir 	WAIT_ON();	// while looking up for initial word
347cdf0e10cSrcweir 	EditAbstractDialogFactory* pFact = EditAbstractDialogFactory::Create();
348cdf0e10cSrcweir 	AbstractThesaurusDialog* pDlg = pFact->CreateThesaurusDialog( pWin, xThes, rWord, nLanguage );
349cdf0e10cSrcweir 	WAIT_OFF();
350cdf0e10cSrcweir 	if ( pDlg->Execute()== RET_OK )
351cdf0e10cSrcweir 	{
352cdf0e10cSrcweir 		ChangeThesWord( pDlg->GetWord() );
353cdf0e10cSrcweir 	}
354cdf0e10cSrcweir 	delete pDlg;
355cdf0e10cSrcweir }
356cdf0e10cSrcweir 
357cdf0e10cSrcweir // -----------------------------------------------------------------------
358cdf0e10cSrcweir 
359cdf0e10cSrcweir void SvxSpellWrapper::ReplaceAll( const String &, sal_Int16 )
360cdf0e10cSrcweir {	// Wort aus der Replace-Liste ersetzen
361cdf0e10cSrcweir }
362cdf0e10cSrcweir 
363cdf0e10cSrcweir // -----------------------------------------------------------------------
364cdf0e10cSrcweir 
365cdf0e10cSrcweir 
366cdf0e10cSrcweir void SvxSpellWrapper::SetLanguage( const sal_uInt16 )
367cdf0e10cSrcweir {	// Sprache aendern
368cdf0e10cSrcweir }
369cdf0e10cSrcweir 
370cdf0e10cSrcweir // -----------------------------------------------------------------------
371cdf0e10cSrcweir 
372cdf0e10cSrcweir 
373cdf0e10cSrcweir void SvxSpellWrapper::InsertHyphen( const sal_uInt16 )
374cdf0e10cSrcweir {	// Hyphen einfuegen bzw. loeschen
375cdf0e10cSrcweir }
376cdf0e10cSrcweir 
377cdf0e10cSrcweir // -----------------------------------------------------------------------
378cdf0e10cSrcweir // Pruefung der Dokumentbereiche in der durch die Flags angegebenen Reihenfolge
379cdf0e10cSrcweir 
380cdf0e10cSrcweir 
381cdf0e10cSrcweir void SvxSpellWrapper::SpellDocument( )
382cdf0e10cSrcweir {
383cdf0e10cSrcweir 	if ( bOtherCntnt )
384cdf0e10cSrcweir 	{
385cdf0e10cSrcweir 		bReverse = sal_False;
386cdf0e10cSrcweir 		SpellStart( SVX_SPELL_OTHER );
387cdf0e10cSrcweir 	}
388cdf0e10cSrcweir 	else
389cdf0e10cSrcweir 	{
390cdf0e10cSrcweir 		bStartChk = bReverse;
391cdf0e10cSrcweir 		SpellStart( bReverse ? SVX_SPELL_BODY_START : SVX_SPELL_BODY_END );
392cdf0e10cSrcweir 	}
393cdf0e10cSrcweir 
394cdf0e10cSrcweir 	if ( FindSpellError() )
395cdf0e10cSrcweir 	{
396cdf0e10cSrcweir 		Reference< XSpellAlternatives >  	xAlt( GetLast(), UNO_QUERY );
397cdf0e10cSrcweir 		Reference< XHyphenatedWord > 		xHyphWord( GetLast(), UNO_QUERY );
398cdf0e10cSrcweir 
399cdf0e10cSrcweir 		Window *pOld = pWin;
400cdf0e10cSrcweir 		bDialog = sal_True;
401cdf0e10cSrcweir 		if (xHyphWord.is())
402cdf0e10cSrcweir 		{
403cdf0e10cSrcweir 			EditAbstractDialogFactory* pFact = EditAbstractDialogFactory::Create();
404cdf0e10cSrcweir 			AbstractHyphenWordDialog* pDlg = pFact->CreateHyphenWordDialog( pWin,
405cdf0e10cSrcweir 							xHyphWord->getWord(),
406cdf0e10cSrcweir 							SvxLocaleToLanguage( xHyphWord->getLocale() ),
407cdf0e10cSrcweir 							xHyph, this );
408cdf0e10cSrcweir 			pWin = pDlg->GetWindow();
409cdf0e10cSrcweir 			pDlg->Execute();
410cdf0e10cSrcweir 			delete pDlg;
411cdf0e10cSrcweir 		}
412cdf0e10cSrcweir 		bDialog = sal_False;
413cdf0e10cSrcweir 		pWin = pOld;
414cdf0e10cSrcweir 	};
415cdf0e10cSrcweir }
416cdf0e10cSrcweir 
417cdf0e10cSrcweir // -----------------------------------------------------------------------
418cdf0e10cSrcweir // Naechsten Bereich auswaehlen
419cdf0e10cSrcweir 
420cdf0e10cSrcweir 
421cdf0e10cSrcweir sal_Bool SvxSpellWrapper::SpellNext( )
422cdf0e10cSrcweir {
423cdf0e10cSrcweir 	Reference< beans::XPropertySet >  xProp( SvxGetLinguPropertySet() );
424cdf0e10cSrcweir 	sal_Bool bWrapReverse = xProp.is() ?
425cdf0e10cSrcweir 			*(sal_Bool*)xProp->getPropertyValue(
426cdf0e10cSrcweir 				::rtl::OUString::createFromAscii(UPN_IS_WRAP_REVERSE) ).getValue()
427cdf0e10cSrcweir 			: sal_False;
428cdf0e10cSrcweir 	sal_Bool bActRev = bRevAllowed && bWrapReverse;
429cdf0e10cSrcweir 
430cdf0e10cSrcweir 	// bActRev ist die Richtung nach dem Spellen, bReverse die am Anfang.
431cdf0e10cSrcweir 	if( bActRev == bReverse )
432cdf0e10cSrcweir 	{   						// Keine Richtungsaenderung, also ist
433cdf0e10cSrcweir 		if( bStartChk )         // der gewuenschte Bereich ( bStartChk )
434cdf0e10cSrcweir 			bStartDone = sal_True;  // vollstaendig abgearbeitet.
435cdf0e10cSrcweir 		else
436cdf0e10cSrcweir 			bEndDone = sal_True;
437cdf0e10cSrcweir 	}
438cdf0e10cSrcweir 	else if( bReverse == bStartChk ) // Bei einer Richtungsaenderung kann
439cdf0e10cSrcweir 	{ 						   // u.U. auch ein Bereich abgearbeitet sein.
440cdf0e10cSrcweir 		if( bStartChk )        // Sollte der vordere Teil rueckwaerts gespellt
441cdf0e10cSrcweir 			bEndDone = sal_True;   // werden und wir kehren unterwegs um, so ist
442cdf0e10cSrcweir 		else				   // der hintere Teil abgearbeitet (und umgekehrt).
443cdf0e10cSrcweir 			bStartDone = sal_True;
444cdf0e10cSrcweir 	}
445cdf0e10cSrcweir 
446cdf0e10cSrcweir 	bReverse = bActRev;
447cdf0e10cSrcweir 	if( bOtherCntnt && bStartDone && bEndDone ) // Dokument komplett geprueft?
448cdf0e10cSrcweir 	{
449cdf0e10cSrcweir 		if ( SpellMore() )  // ein weiteres Dokument pruefen?
450cdf0e10cSrcweir 		{
451cdf0e10cSrcweir 			bOtherCntnt = sal_False;
452cdf0e10cSrcweir 			bStartDone = !bReverse;
453cdf0e10cSrcweir 			bEndDone  = bReverse;
454cdf0e10cSrcweir 			SpellStart( SVX_SPELL_BODY );
455cdf0e10cSrcweir 			return sal_True;
456cdf0e10cSrcweir 		}
457cdf0e10cSrcweir 		return sal_False;
458cdf0e10cSrcweir 	}
459cdf0e10cSrcweir 
460cdf0e10cSrcweir 	sal_Bool bGoOn = sal_False;
461cdf0e10cSrcweir 
462cdf0e10cSrcweir 	if ( bOtherCntnt )
463cdf0e10cSrcweir 	{
464cdf0e10cSrcweir 		bStartChk = sal_False;
465cdf0e10cSrcweir 		SpellStart( SVX_SPELL_BODY );
466cdf0e10cSrcweir 		bGoOn = sal_True;
467cdf0e10cSrcweir 	}
468cdf0e10cSrcweir 	else if ( bStartDone && bEndDone )
469cdf0e10cSrcweir 	{
470cdf0e10cSrcweir 		sal_Bool bIsSpellSpecial = xProp.is() ?
471cdf0e10cSrcweir 			*(sal_Bool*)xProp->getPropertyValue(
472cdf0e10cSrcweir 				::rtl::OUString::createFromAscii(UPN_IS_SPELL_SPECIAL) ).getValue()
473cdf0e10cSrcweir 			: sal_False;
474cdf0e10cSrcweir 		// Bodybereich erledigt, Frage nach Sonderbereich
475cdf0e10cSrcweir 		if( !IsHyphen() && bIsSpellSpecial && HasOtherCnt() )
476cdf0e10cSrcweir 		{
477cdf0e10cSrcweir 			SpellStart( SVX_SPELL_OTHER );
478cdf0e10cSrcweir 			bOtherCntnt = bGoOn = sal_True;
479cdf0e10cSrcweir 		}
480cdf0e10cSrcweir 		else if ( SpellMore() )  // ein weiteres Dokument pruefen?
481cdf0e10cSrcweir 		{
482cdf0e10cSrcweir 			bOtherCntnt = sal_False;
483cdf0e10cSrcweir 			bStartDone = !bReverse;
484cdf0e10cSrcweir 			bEndDone  = bReverse;
485cdf0e10cSrcweir 			SpellStart( SVX_SPELL_BODY );
486cdf0e10cSrcweir 			return sal_True;
487cdf0e10cSrcweir 		}
488cdf0e10cSrcweir 	}
489cdf0e10cSrcweir 	else
490cdf0e10cSrcweir 	{
491cdf0e10cSrcweir 		// Ein BODY_Bereich erledigt, Frage nach dem anderen BODY_Bereich
492cdf0e10cSrcweir 		WAIT_OFF();
493cdf0e10cSrcweir 
494cdf0e10cSrcweir // Sobald im Dialog das DontWrapAround gesetzt werden kann, kann der
495cdf0e10cSrcweir // folgende #ifdef-Zweig aktiviert werden ...
496cdf0e10cSrcweir #ifdef USED
497cdf0e10cSrcweir 		sal_Bool bDontWrapAround = IsHyphen() ?
498cdf0e10cSrcweir 			pSpell->GetOptions() & DONT_WRAPAROUND :
499cdf0e10cSrcweir 			pSpell->GetHyphOptions() & HYPH_DONT_WRAPAROUND;
500cdf0e10cSrcweir 		if( bDontWrapAround )
501cdf0e10cSrcweir #else
502cdf0e10cSrcweir 		sal_uInt16 nResId = bReverse ? RID_SVXQB_BW_CONTINUE : RID_SVXQB_CONTINUE;
503cdf0e10cSrcweir 		QueryBox aBox( pWin, EditResId( nResId ) );
504cdf0e10cSrcweir 		if ( aBox.Execute() != RET_YES )
505cdf0e10cSrcweir #endif
506cdf0e10cSrcweir 
507cdf0e10cSrcweir 		{
508cdf0e10cSrcweir 			// Verzicht auf den anderen Bereich, ggf. Frage nach Sonderbereich
509cdf0e10cSrcweir 			WAIT_ON();
510cdf0e10cSrcweir 			bStartDone = bEndDone = sal_True;
511cdf0e10cSrcweir 			return SpellNext();
512cdf0e10cSrcweir 		}
513cdf0e10cSrcweir 		else
514cdf0e10cSrcweir 		{
515cdf0e10cSrcweir 			bStartChk = !bStartDone;
516cdf0e10cSrcweir 			SpellStart( bStartChk ? SVX_SPELL_BODY_START : SVX_SPELL_BODY_END );
517cdf0e10cSrcweir 			bGoOn = sal_True;
518cdf0e10cSrcweir 		}
519cdf0e10cSrcweir 		WAIT_ON();
520cdf0e10cSrcweir 	}
521cdf0e10cSrcweir 	return bGoOn;
522cdf0e10cSrcweir }
523cdf0e10cSrcweir 
524cdf0e10cSrcweir // -----------------------------------------------------------------------
525cdf0e10cSrcweir 
526cdf0e10cSrcweir Reference< XDictionary >  SvxSpellWrapper::GetAllRightDic() const
527cdf0e10cSrcweir {
528cdf0e10cSrcweir     Reference< XDictionary >  xDic;
529cdf0e10cSrcweir 
530cdf0e10cSrcweir 	Reference< XDictionaryList >  xDicList( SvxGetDictionaryList() );
531cdf0e10cSrcweir 	if (xDicList.is())
532cdf0e10cSrcweir 	{
533cdf0e10cSrcweir 		Sequence< Reference< XDictionary >  > aDics( xDicList->getDictionaries() );
534cdf0e10cSrcweir 		const Reference< XDictionary >  *pDic = aDics.getConstArray();
535cdf0e10cSrcweir 		sal_Int32 nCount = aDics.getLength();
536cdf0e10cSrcweir 
537cdf0e10cSrcweir 		sal_Int32 i = 0;
538cdf0e10cSrcweir 		while (!xDic.is()  &&  i < nCount)
539cdf0e10cSrcweir 		{
540cdf0e10cSrcweir             Reference< XDictionary >  xTmp( pDic[i], UNO_QUERY );
541cdf0e10cSrcweir 			if (xTmp.is())
542cdf0e10cSrcweir 			{
543cdf0e10cSrcweir 				if ( xTmp->isActive() &&
544cdf0e10cSrcweir 					 xTmp->getDictionaryType() != DictionaryType_NEGATIVE &&
545cdf0e10cSrcweir                      SvxLocaleToLanguage( xTmp->getLocale() ) == LANGUAGE_NONE )
546cdf0e10cSrcweir 				{
547cdf0e10cSrcweir 					Reference< frame::XStorable >  xStor( xTmp, UNO_QUERY );
548cdf0e10cSrcweir 					if (xStor.is() && xStor->hasLocation() && !xStor->isReadonly())
549cdf0e10cSrcweir 					{
550cdf0e10cSrcweir 						xDic = xTmp;
551cdf0e10cSrcweir 					}
552cdf0e10cSrcweir 				}
553cdf0e10cSrcweir 			}
554cdf0e10cSrcweir 			++i;
555cdf0e10cSrcweir 		}
556cdf0e10cSrcweir 
557cdf0e10cSrcweir 		if (!xDic.is())
558cdf0e10cSrcweir 		{
559cdf0e10cSrcweir 			xDic = SvxGetOrCreatePosDic( xDicList );
560cdf0e10cSrcweir 			if (xDic.is())
561cdf0e10cSrcweir 				xDic->setActive( sal_True );
562cdf0e10cSrcweir 		}
563cdf0e10cSrcweir 	}
564cdf0e10cSrcweir 
565cdf0e10cSrcweir 	return xDic;
566cdf0e10cSrcweir }
567cdf0e10cSrcweir 
568cdf0e10cSrcweir // -----------------------------------------------------------------------
569cdf0e10cSrcweir 
570cdf0e10cSrcweir sal_Bool SvxSpellWrapper::FindSpellError()
571cdf0e10cSrcweir {
572cdf0e10cSrcweir     ShowLanguageErrors();
573cdf0e10cSrcweir 
574cdf0e10cSrcweir  	Reference< XInterface > 	xRef;
575cdf0e10cSrcweir 
576cdf0e10cSrcweir 	WAIT_ON();
577cdf0e10cSrcweir 	sal_Bool bSpell = sal_True;
578cdf0e10cSrcweir 
579cdf0e10cSrcweir     Reference< XDictionary >  xAllRightDic;
580cdf0e10cSrcweir 	if (IsAllRight())
581cdf0e10cSrcweir 		xAllRightDic = GetAllRightDic();
582cdf0e10cSrcweir 
583cdf0e10cSrcweir 	while ( bSpell )
584cdf0e10cSrcweir 	{
585cdf0e10cSrcweir 		SpellContinue();
586cdf0e10cSrcweir 
587cdf0e10cSrcweir 		Reference< XSpellAlternatives >  	xAlt( GetLast(), UNO_QUERY );
588cdf0e10cSrcweir 		Reference< XHyphenatedWord > 		xHyphWord( GetLast(), UNO_QUERY );
589cdf0e10cSrcweir 
590cdf0e10cSrcweir 		if (xAlt.is())
591cdf0e10cSrcweir 		{
592cdf0e10cSrcweir 			if (IsAllRight() && xAllRightDic.is())
593cdf0e10cSrcweir 			{
594cdf0e10cSrcweir 				xAllRightDic->add( xAlt->getWord(), sal_False, ::rtl::OUString() );
595cdf0e10cSrcweir 			}
596cdf0e10cSrcweir 			else
597cdf0e10cSrcweir 			{
598cdf0e10cSrcweir 				// look up in ChangeAllList for misspelled word
599cdf0e10cSrcweir                 Reference< XDictionary >    xChangeAllList(
600cdf0e10cSrcweir 						SvxGetChangeAllList(), UNO_QUERY );
601cdf0e10cSrcweir 				Reference< XDictionaryEntry > 	xEntry;
602cdf0e10cSrcweir 				if (xChangeAllList.is())
603cdf0e10cSrcweir 					xEntry = xChangeAllList->getEntry( xAlt->getWord() );
604cdf0e10cSrcweir 
605cdf0e10cSrcweir 				if (xEntry.is())
606cdf0e10cSrcweir 				{
607cdf0e10cSrcweir 					// replace word without asking
608cdf0e10cSrcweir 					ReplaceAll( xEntry->getReplacementText(),
609cdf0e10cSrcweir 								SvxLocaleToLanguage( xAlt->getLocale() ) );
610cdf0e10cSrcweir 				}
611cdf0e10cSrcweir 				else
612cdf0e10cSrcweir 					bSpell = sal_False;
613cdf0e10cSrcweir 			}
614cdf0e10cSrcweir 		}
615cdf0e10cSrcweir 		else if (xHyphWord.is())
616cdf0e10cSrcweir 			bSpell = sal_False;
617cdf0e10cSrcweir 		else
618cdf0e10cSrcweir 		{
619cdf0e10cSrcweir 			SpellEnd();
620cdf0e10cSrcweir 			bSpell = SpellNext();
621cdf0e10cSrcweir 		}
622cdf0e10cSrcweir 	}
623cdf0e10cSrcweir 	WAIT_OFF();
624cdf0e10cSrcweir 	return GetLast().is();
625cdf0e10cSrcweir }
626cdf0e10cSrcweir 
627cdf0e10cSrcweir 
628cdf0e10cSrcweir 
629