xref: /AOO41X/main/editeng/source/misc/svxacorr.cxx (revision 79aad27f7f29270c03e208e3d687e8e3850af11d)
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
10cdf0e10cSrcweir  *
11*190118d0SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
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.
19cdf0e10cSrcweir  *
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 
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include <com/sun/star/io/XStream.hpp>
29cdf0e10cSrcweir #include <com/sun/star/lang/Locale.hpp>
30cdf0e10cSrcweir #include <tools/urlobj.hxx>
31cdf0e10cSrcweir #include <tools/table.hxx>
32cdf0e10cSrcweir #include <i18npool/mslangid.hxx>
33cdf0e10cSrcweir #include <vcl/svapp.hxx>
34cdf0e10cSrcweir #include <sot/storinfo.hxx>
35cdf0e10cSrcweir // fuer die Sort-String-Arrays aus dem SVMEM.HXX
36cdf0e10cSrcweir #define _SVSTDARR_STRINGSISORTDTOR
37cdf0e10cSrcweir #define _SVSTDARR_STRINGSDTOR
38cdf0e10cSrcweir #include <svl/svstdarr.hxx>
39cdf0e10cSrcweir #include <svl/fstathelper.hxx>
40cdf0e10cSrcweir #include <svtools/helpopt.hxx>
41cdf0e10cSrcweir #include <svl/urihelper.hxx>
42cdf0e10cSrcweir #include <unotools/charclass.hxx>
43cdf0e10cSrcweir #include <com/sun/star/i18n/UnicodeType.hdl>
44cdf0e10cSrcweir #include <unotools/collatorwrapper.hxx>
45cdf0e10cSrcweir #include <com/sun/star/i18n/CollatorOptions.hpp>
46cdf0e10cSrcweir #include <com/sun/star/i18n/UnicodeScript.hpp>
47cdf0e10cSrcweir #include <unotools/localedatawrapper.hxx>
48cdf0e10cSrcweir #include <unotools/transliterationwrapper.hxx>
49cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
50cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
51cdf0e10cSrcweir #include <com/sun/star/io/XActiveDataSource.hpp>
52cdf0e10cSrcweir #include <editeng/editids.hrc>
53cdf0e10cSrcweir #include <sot/storage.hxx>
54cdf0e10cSrcweir #include <comphelper/storagehelper.hxx>
55cdf0e10cSrcweir #include <editeng/udlnitem.hxx>
56cdf0e10cSrcweir #include <editeng/wghtitem.hxx>
57cdf0e10cSrcweir #include <editeng/escpitem.hxx>
58cdf0e10cSrcweir #include <editeng/svxacorr.hxx>
59cdf0e10cSrcweir #include <editeng/unolingu.hxx>
60cdf0e10cSrcweir #include <helpid.hrc>
61cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
62cdf0e10cSrcweir #include <com/sun/star/xml/sax/InputSource.hpp>
63cdf0e10cSrcweir #include <com/sun/star/xml/sax/XParser.hpp>
64cdf0e10cSrcweir #include <unotools/streamwrap.hxx>
65cdf0e10cSrcweir #include <SvXMLAutoCorrectImport.hxx>
66cdf0e10cSrcweir #include <SvXMLAutoCorrectExport.hxx>
67cdf0e10cSrcweir #include <ucbhelper/content.hxx>
68cdf0e10cSrcweir #include <com/sun/star/ucb/XCommandEnvironment.hpp>
69cdf0e10cSrcweir #include <com/sun/star/ucb/TransferInfo.hpp>
70cdf0e10cSrcweir #include <com/sun/star/ucb/NameClash.hpp>
71cdf0e10cSrcweir #include <xmloff/xmltoken.hxx>
72cdf0e10cSrcweir #include <vcl/help.hxx>
73cdf0e10cSrcweir 
74cdf0e10cSrcweir #define CHAR_HARDBLANK		((sal_Unicode)0x00A0)
75cdf0e10cSrcweir 
76cdf0e10cSrcweir using namespace ::com::sun::star::ucb;
77cdf0e10cSrcweir using namespace ::com::sun::star::uno;
78cdf0e10cSrcweir using namespace ::com::sun::star;
79cdf0e10cSrcweir using namespace ::xmloff::token;
80cdf0e10cSrcweir using namespace ::rtl;
81cdf0e10cSrcweir using namespace ::utl;
82cdf0e10cSrcweir 
83cdf0e10cSrcweir const int C_NONE 				= 0x00;
84cdf0e10cSrcweir const int C_FULL_STOP 			= 0x01;
85cdf0e10cSrcweir const int C_EXCLAMATION_MARK	= 0x02;
86cdf0e10cSrcweir const int C_QUESTION_MARK		= 0x04;
87cdf0e10cSrcweir 
88cdf0e10cSrcweir static const sal_Char pImplWrdStt_ExcptLstStr[]    = "WordExceptList";
89cdf0e10cSrcweir static const sal_Char pImplCplStt_ExcptLstStr[]    = "SentenceExceptList";
90cdf0e10cSrcweir static const sal_Char pImplAutocorr_ListStr[]      = "DocumentList";
91cdf0e10cSrcweir static const sal_Char pXMLImplWrdStt_ExcptLstStr[] = "WordExceptList.xml";
92cdf0e10cSrcweir static const sal_Char pXMLImplCplStt_ExcptLstStr[] = "SentenceExceptList.xml";
93cdf0e10cSrcweir static const sal_Char pXMLImplAutocorr_ListStr[]   = "DocumentList.xml";
94cdf0e10cSrcweir 
95cdf0e10cSrcweir static const sal_Char
96cdf0e10cSrcweir 	/* auch bei diesen Anfaengen - Klammern auf und alle Arten von Anf.Zei. */
97cdf0e10cSrcweir 	sImplSttSkipChars[]	= "\"\'([{\x83\x84\x89\x91\x92\x93\x94",
98cdf0e10cSrcweir 	/* auch bei diesen Ende - Klammern auf und alle Arten von Anf.Zei. */
99cdf0e10cSrcweir 	sImplEndSkipChars[]	= "\"\')]}\x83\x84\x89\x91\x92\x93\x94";
100cdf0e10cSrcweir 
101cdf0e10cSrcweir // diese Zeichen sind in Worten erlaubt: (fuer FnCptlSttSntnc)
102cdf0e10cSrcweir static const sal_Char sImplWordChars[] = "-'";
103cdf0e10cSrcweir 
104cdf0e10cSrcweir void EncryptBlockName_Imp( String& rName );
105cdf0e10cSrcweir void DecryptBlockName_Imp( String& rName );
106cdf0e10cSrcweir 
107cdf0e10cSrcweir 
108cdf0e10cSrcweir // FileVersions Nummern fuer die Ersetzungs-/Ausnahmelisten getrennt
109cdf0e10cSrcweir #define WORDLIST_VERSION_358	1
110cdf0e10cSrcweir #define EXEPTLIST_VERSION_358	0
111cdf0e10cSrcweir 
112cdf0e10cSrcweir 
113cdf0e10cSrcweir _SV_IMPL_SORTAR_ALG( SvxAutocorrWordList, SvxAutocorrWordPtr )
114cdf0e10cSrcweir TYPEINIT0(SvxAutoCorrect)
115cdf0e10cSrcweir 
116cdf0e10cSrcweir typedef SvxAutoCorrectLanguageLists* SvxAutoCorrectLanguageListsPtr;
DECLARE_TABLE(SvxAutoCorrLanguageTable_Impl,SvxAutoCorrectLanguageListsPtr)117cdf0e10cSrcweir DECLARE_TABLE( SvxAutoCorrLanguageTable_Impl,  SvxAutoCorrectLanguageListsPtr)
118cdf0e10cSrcweir 
119cdf0e10cSrcweir DECLARE_TABLE( SvxAutoCorrLastFileAskTable_Impl, long )
120cdf0e10cSrcweir 
121cdf0e10cSrcweir 
122cdf0e10cSrcweir inline int IsWordDelim( const sal_Unicode c )
123cdf0e10cSrcweir {
124cdf0e10cSrcweir 	return ' ' == c || '\t' == c || 0x0a == c ||
125cdf0e10cSrcweir             0xA0 == c || 0x2011 == c || 0x1 == c;
126cdf0e10cSrcweir }
127cdf0e10cSrcweir 
IsLowerLetter(sal_Int32 nCharType)128cdf0e10cSrcweir inline int IsLowerLetter( sal_Int32 nCharType )
129cdf0e10cSrcweir {
130cdf0e10cSrcweir 	return CharClass::isLetterType( nCharType ) &&
131cdf0e10cSrcweir 			0 == ( ::com::sun::star::i18n::KCharacterType::UPPER & nCharType);
132cdf0e10cSrcweir }
IsUpperLetter(sal_Int32 nCharType)133cdf0e10cSrcweir inline int IsUpperLetter( sal_Int32 nCharType )
134cdf0e10cSrcweir {
135cdf0e10cSrcweir 	return CharClass::isLetterType( nCharType ) &&
136cdf0e10cSrcweir 			0 == ( ::com::sun::star::i18n::KCharacterType::LOWER & nCharType);
137cdf0e10cSrcweir }
138cdf0e10cSrcweir 
lcl_IsUnsupportedUnicodeChar(CharClass & rCC,const String & rTxt,xub_StrLen nStt,xub_StrLen nEnd)139cdf0e10cSrcweir bool lcl_IsUnsupportedUnicodeChar( CharClass& rCC, const String& rTxt,
140cdf0e10cSrcweir 				   		xub_StrLen nStt, xub_StrLen nEnd )
141cdf0e10cSrcweir {
142cdf0e10cSrcweir 	for( ; nStt < nEnd; ++nStt )
143cdf0e10cSrcweir 	{
144cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
145cdf0e10cSrcweir 		sal_Int32 nCharType;
146cdf0e10cSrcweir 		sal_Int32 nChType;
147cdf0e10cSrcweir 		nCharType = rCC.getCharacterType( rTxt, nStt );
148cdf0e10cSrcweir 		nChType = rCC.getType( rTxt, nStt );
149cdf0e10cSrcweir #endif
150cdf0e10cSrcweir         short nScript = rCC.getScript( rTxt, nStt );
151cdf0e10cSrcweir         switch( nScript )
152cdf0e10cSrcweir         {
153cdf0e10cSrcweir             case ::com::sun::star::i18n::UnicodeScript_kCJKRadicalsSupplement:
154cdf0e10cSrcweir             case ::com::sun::star::i18n::UnicodeScript_kHangulJamo:
155cdf0e10cSrcweir             case ::com::sun::star::i18n::UnicodeScript_kCJKSymbolPunctuation:
156cdf0e10cSrcweir             case ::com::sun::star::i18n::UnicodeScript_kHiragana:
157cdf0e10cSrcweir             case ::com::sun::star::i18n::UnicodeScript_kKatakana:
158cdf0e10cSrcweir             case ::com::sun::star::i18n::UnicodeScript_kHangulCompatibilityJamo:
159cdf0e10cSrcweir             case ::com::sun::star::i18n::UnicodeScript_kEnclosedCJKLetterMonth:
160cdf0e10cSrcweir             case ::com::sun::star::i18n::UnicodeScript_kCJKCompatibility:
161cdf0e10cSrcweir             case ::com::sun::star::i18n::UnicodeScript_k_CJKUnifiedIdeographsExtensionA:
162cdf0e10cSrcweir             case ::com::sun::star::i18n::UnicodeScript_kCJKUnifiedIdeograph:
163cdf0e10cSrcweir             case ::com::sun::star::i18n::UnicodeScript_kHangulSyllable:
164cdf0e10cSrcweir             case ::com::sun::star::i18n::UnicodeScript_kCJKCompatibilityIdeograph:
165cdf0e10cSrcweir             case ::com::sun::star::i18n::UnicodeScript_kHalfwidthFullwidthForm:
166cdf0e10cSrcweir                 return true;
167cdf0e10cSrcweir             default: ; //do nothing
168cdf0e10cSrcweir         }
169cdf0e10cSrcweir 
170cdf0e10cSrcweir 	}
171cdf0e10cSrcweir 	return false;
172cdf0e10cSrcweir }
173cdf0e10cSrcweir 
lcl_IsSymbolChar(CharClass & rCC,const String & rTxt,xub_StrLen nStt,xub_StrLen nEnd)174cdf0e10cSrcweir sal_Bool lcl_IsSymbolChar( CharClass& rCC, const String& rTxt,
175cdf0e10cSrcweir 				   		xub_StrLen nStt, xub_StrLen nEnd )
176cdf0e10cSrcweir {
177cdf0e10cSrcweir 	for( ; nStt < nEnd; ++nStt )
178cdf0e10cSrcweir 	{
179cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
180cdf0e10cSrcweir 		sal_Int32 nCharType;
181cdf0e10cSrcweir 		sal_Int32 nChType;
182cdf0e10cSrcweir 		nCharType = rCC.getCharacterType( rTxt, nStt );
183cdf0e10cSrcweir 		nChType = rCC.getType( rTxt, nStt );
184cdf0e10cSrcweir #endif
185cdf0e10cSrcweir 		if( ::com::sun::star::i18n::UnicodeType::PRIVATE_USE ==
186cdf0e10cSrcweir 				rCC.getType( rTxt, nStt ))
187cdf0e10cSrcweir 			return sal_True;
188cdf0e10cSrcweir 	}
189cdf0e10cSrcweir 	return sal_False;
190cdf0e10cSrcweir }
191cdf0e10cSrcweir 
192cdf0e10cSrcweir 
lcl_IsInAsciiArr(const sal_Char * pArr,const sal_Unicode c)193cdf0e10cSrcweir static sal_Bool lcl_IsInAsciiArr( const sal_Char* pArr, const sal_Unicode c )
194cdf0e10cSrcweir {
195cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
196cdf0e10cSrcweir 	for( ; *pArr; ++pArr )
197cdf0e10cSrcweir 		if( *pArr == c )
198cdf0e10cSrcweir 		{
199cdf0e10cSrcweir 			bRet = sal_True;
200cdf0e10cSrcweir 			break;
201cdf0e10cSrcweir 		}
202cdf0e10cSrcweir 	return bRet;
203cdf0e10cSrcweir }
204cdf0e10cSrcweir 
~SvxAutoCorrDoc()205cdf0e10cSrcweir SvxAutoCorrDoc::~SvxAutoCorrDoc()
206cdf0e10cSrcweir {
207cdf0e10cSrcweir }
208cdf0e10cSrcweir 
209cdf0e10cSrcweir 
210cdf0e10cSrcweir 	// wird nach dem austauschen der Zeichen von den Funktionen
211cdf0e10cSrcweir 	//	- FnCptlSttWrd
212cdf0e10cSrcweir 	// 	- FnCptlSttSntnc
213cdf0e10cSrcweir 	// gerufen. Dann koennen die Worte ggfs. in die Ausnahmelisten
214cdf0e10cSrcweir 	// aufgenommen werden.
SaveCpltSttWord(sal_uLong,xub_StrLen,const String &,sal_Unicode)215cdf0e10cSrcweir void SvxAutoCorrDoc::SaveCpltSttWord( sal_uLong, xub_StrLen, const String&,
216cdf0e10cSrcweir 										sal_Unicode )
217cdf0e10cSrcweir {
218cdf0e10cSrcweir }
219cdf0e10cSrcweir 
GetLanguage(xub_StrLen,sal_Bool) const220cdf0e10cSrcweir LanguageType SvxAutoCorrDoc::GetLanguage( xub_StrLen , sal_Bool ) const
221cdf0e10cSrcweir {
222cdf0e10cSrcweir 	return LANGUAGE_SYSTEM;
223cdf0e10cSrcweir }
224cdf0e10cSrcweir 
225cdf0e10cSrcweir static ::com::sun::star::uno::Reference<
GetProcessFact()226cdf0e10cSrcweir 			::com::sun::star::lang::XMultiServiceFactory >& GetProcessFact()
227cdf0e10cSrcweir {
228cdf0e10cSrcweir 	static ::com::sun::star::uno::Reference<
229cdf0e10cSrcweir 			::com::sun::star::lang::XMultiServiceFactory > xMSF =
230cdf0e10cSrcweir 									::comphelper::getProcessServiceFactory();
231cdf0e10cSrcweir 	return xMSF;
232cdf0e10cSrcweir }
233cdf0e10cSrcweir 
GetAppLang()234cdf0e10cSrcweir static sal_uInt16 GetAppLang()
235cdf0e10cSrcweir {
236cdf0e10cSrcweir 	return Application::GetSettings().GetLanguage();
237cdf0e10cSrcweir }
GetLocaleDataWrapper(sal_uInt16 nLang)238cdf0e10cSrcweir static LocaleDataWrapper& GetLocaleDataWrapper( sal_uInt16 nLang )
239cdf0e10cSrcweir {
240cdf0e10cSrcweir 	static LocaleDataWrapper aLclDtWrp( GetProcessFact(),
241cdf0e10cSrcweir 										SvxCreateLocale( GetAppLang() ) );
242cdf0e10cSrcweir 	::com::sun::star::lang::Locale aLcl( SvxCreateLocale( nLang ));
243cdf0e10cSrcweir 	const ::com::sun::star::lang::Locale& rLcl = aLclDtWrp.getLoadedLocale();
244cdf0e10cSrcweir 	if( aLcl.Language != rLcl.Language ||
245cdf0e10cSrcweir 		aLcl.Country != rLcl.Country ||
246cdf0e10cSrcweir 		aLcl.Variant != rLcl.Variant )
247cdf0e10cSrcweir 		aLclDtWrp.setLocale( aLcl );
248cdf0e10cSrcweir 	return aLclDtWrp;
249cdf0e10cSrcweir }
GetIgnoreTranslWrapper()250cdf0e10cSrcweir static TransliterationWrapper& GetIgnoreTranslWrapper()
251cdf0e10cSrcweir {
252cdf0e10cSrcweir 	static int bIsInit = 0;
253cdf0e10cSrcweir 	static TransliterationWrapper aWrp( GetProcessFact(),
254cdf0e10cSrcweir 				::com::sun::star::i18n::TransliterationModules_IGNORE_KANA |
255cdf0e10cSrcweir 				::com::sun::star::i18n::TransliterationModules_IGNORE_WIDTH );
256cdf0e10cSrcweir 	if( !bIsInit )
257cdf0e10cSrcweir 	{
258cdf0e10cSrcweir 		aWrp.loadModuleIfNeeded( GetAppLang() );
259cdf0e10cSrcweir 		bIsInit = 1;
260cdf0e10cSrcweir 	}
261cdf0e10cSrcweir 	return aWrp;
262cdf0e10cSrcweir }
GetCollatorWrapper()263cdf0e10cSrcweir static CollatorWrapper& GetCollatorWrapper()
264cdf0e10cSrcweir {
265cdf0e10cSrcweir 	static int bIsInit = 0;
266cdf0e10cSrcweir 	static CollatorWrapper aCollWrp( GetProcessFact() );
267cdf0e10cSrcweir 	if( !bIsInit )
268cdf0e10cSrcweir 	{
269cdf0e10cSrcweir 		aCollWrp.loadDefaultCollator( SvxCreateLocale( GetAppLang() ), 0 );
270cdf0e10cSrcweir 		bIsInit = 1;
271cdf0e10cSrcweir 	}
272cdf0e10cSrcweir 	return aCollWrp;
273cdf0e10cSrcweir }
274cdf0e10cSrcweir 
275cdf0e10cSrcweir 
DeleteAndDestroy(sal_uInt16 nP,sal_uInt16 nL)276cdf0e10cSrcweir void SvxAutocorrWordList::DeleteAndDestroy( sal_uInt16 nP, sal_uInt16 nL )
277cdf0e10cSrcweir {
278cdf0e10cSrcweir 	if( nL )
279cdf0e10cSrcweir 	{
280cdf0e10cSrcweir 		DBG_ASSERT( nP < nA && nP + nL <= nA, "ERR_VAR_DEL" );
281cdf0e10cSrcweir 		for( sal_uInt16 n=nP; n < nP + nL; n++ )
282cdf0e10cSrcweir 			delete *((SvxAutocorrWordPtr*)pData+n);
283cdf0e10cSrcweir 		SvPtrarr::Remove( nP, nL );
284cdf0e10cSrcweir 	}
285cdf0e10cSrcweir }
286cdf0e10cSrcweir 
287cdf0e10cSrcweir 
Seek_Entry(const SvxAutocorrWordPtr aE,sal_uInt16 * pP) const288cdf0e10cSrcweir sal_Bool SvxAutocorrWordList::Seek_Entry( const SvxAutocorrWordPtr aE, sal_uInt16* pP ) const
289cdf0e10cSrcweir {
290cdf0e10cSrcweir 	register sal_uInt16 nO  = SvxAutocorrWordList_SAR::Count(),
291cdf0e10cSrcweir 			nM,
292cdf0e10cSrcweir 			nU = 0;
293cdf0e10cSrcweir 	if( nO > 0 )
294cdf0e10cSrcweir 	{
295cdf0e10cSrcweir 		CollatorWrapper& rCmp = ::GetCollatorWrapper();
296cdf0e10cSrcweir 		nO--;
297cdf0e10cSrcweir 		while( nU <= nO )
298cdf0e10cSrcweir 		{
299cdf0e10cSrcweir 			nM = nU + ( nO - nU ) / 2;
300cdf0e10cSrcweir 			long nCmp = rCmp.compareString( aE->GetShort(),
301cdf0e10cSrcweir 						(*((SvxAutocorrWordPtr*)pData + nM))->GetShort() );
302cdf0e10cSrcweir 			if( 0 == nCmp )
303cdf0e10cSrcweir 			{
304cdf0e10cSrcweir 				if( pP ) *pP = nM;
305cdf0e10cSrcweir 				return sal_True;
306cdf0e10cSrcweir 			}
307cdf0e10cSrcweir 			else if( 0 < nCmp )
308cdf0e10cSrcweir 				nU = nM + 1;
309cdf0e10cSrcweir 			else if( nM == 0 )
310cdf0e10cSrcweir 			{
311cdf0e10cSrcweir 				if( pP ) *pP = nU;
312cdf0e10cSrcweir 				return sal_False;
313cdf0e10cSrcweir 			}
314cdf0e10cSrcweir 			else
315cdf0e10cSrcweir 				nO = nM - 1;
316cdf0e10cSrcweir 		}
317cdf0e10cSrcweir 	}
318cdf0e10cSrcweir 	if( pP ) *pP = nU;
319cdf0e10cSrcweir 	return sal_False;
320cdf0e10cSrcweir }
321cdf0e10cSrcweir 
322cdf0e10cSrcweir /* -----------------18.11.98 15:28-------------------
323cdf0e10cSrcweir  *
324cdf0e10cSrcweir  * --------------------------------------------------*/
lcl_ClearTable(SvxAutoCorrLanguageTable_Impl & rLangTable)325cdf0e10cSrcweir void lcl_ClearTable(SvxAutoCorrLanguageTable_Impl& rLangTable)
326cdf0e10cSrcweir {
327cdf0e10cSrcweir 	SvxAutoCorrectLanguageListsPtr pLists = rLangTable.Last();
328cdf0e10cSrcweir 	while(pLists)
329cdf0e10cSrcweir 	{
330cdf0e10cSrcweir 		delete pLists;
331cdf0e10cSrcweir 		pLists = rLangTable.Prev();
332cdf0e10cSrcweir 	}
333cdf0e10cSrcweir 	rLangTable.Clear();
334cdf0e10cSrcweir }
335cdf0e10cSrcweir 
336cdf0e10cSrcweir /* -----------------03.11.06 10:15-------------------
337cdf0e10cSrcweir  *
338cdf0e10cSrcweir  * --------------------------------------------------*/
339cdf0e10cSrcweir 
IsAutoCorrectChar(sal_Unicode cChar)340cdf0e10cSrcweir sal_Bool SvxAutoCorrect::IsAutoCorrectChar( sal_Unicode cChar )
341cdf0e10cSrcweir {
342cdf0e10cSrcweir     return  cChar == '\0' || cChar == '\t' || cChar == 0x0a ||
343cdf0e10cSrcweir             cChar == ' '  || cChar == '\'' || cChar == '\"' ||
344cdf0e10cSrcweir             cChar == '*'  || cChar == '_'  ||
345cdf0e10cSrcweir             cChar == '.'  || cChar == ','  || cChar == ';' ||
346cdf0e10cSrcweir             cChar == ':'  || cChar == '?' || cChar == '!' || cChar == '/';
347cdf0e10cSrcweir }
348cdf0e10cSrcweir 
NeedsHardspaceAutocorr(sal_Unicode cChar)349cdf0e10cSrcweir sal_Bool SvxAutoCorrect::NeedsHardspaceAutocorr( sal_Unicode cChar )
350cdf0e10cSrcweir {
351cdf0e10cSrcweir     return cChar == ';' || cChar == ':'  || cChar == '?' || cChar == '!' ||
352cdf0e10cSrcweir         cChar == '/' /*case for the urls exception*/;
353cdf0e10cSrcweir }
354cdf0e10cSrcweir 
355cdf0e10cSrcweir /* -----------------19.11.98 10:15-------------------
356cdf0e10cSrcweir  *
357cdf0e10cSrcweir  * --------------------------------------------------*/
GetDefaultFlags()358cdf0e10cSrcweir long SvxAutoCorrect::GetDefaultFlags()
359cdf0e10cSrcweir {
360cdf0e10cSrcweir 	long nRet = Autocorrect
361cdf0e10cSrcweir 					| CptlSttSntnc
362cdf0e10cSrcweir 					| CptlSttWrd
363cdf0e10cSrcweir 					| ChgOrdinalNumber
364cdf0e10cSrcweir 					| ChgToEnEmDash
365cdf0e10cSrcweir                     | AddNonBrkSpace
366cdf0e10cSrcweir 					| ChgWeightUnderl
367cdf0e10cSrcweir 					| SetINetAttr
368cdf0e10cSrcweir 					| ChgQuotes
369cdf0e10cSrcweir 					| SaveWordCplSttLst
370cdf0e10cSrcweir 					| SaveWordWrdSttLst;
371cdf0e10cSrcweir 	LanguageType eLang = GetAppLang();
372cdf0e10cSrcweir 	switch( eLang )
373cdf0e10cSrcweir 	{
374cdf0e10cSrcweir 	case LANGUAGE_ENGLISH:
375cdf0e10cSrcweir 	case LANGUAGE_ENGLISH_US:
376cdf0e10cSrcweir 	case LANGUAGE_ENGLISH_UK:
377cdf0e10cSrcweir 	case LANGUAGE_ENGLISH_AUS:
378cdf0e10cSrcweir 	case LANGUAGE_ENGLISH_CAN:
379cdf0e10cSrcweir 	case LANGUAGE_ENGLISH_NZ:
380cdf0e10cSrcweir 	case LANGUAGE_ENGLISH_EIRE:
381cdf0e10cSrcweir 	case LANGUAGE_ENGLISH_SAFRICA:
382cdf0e10cSrcweir 	case LANGUAGE_ENGLISH_JAMAICA:
383cdf0e10cSrcweir 	case LANGUAGE_ENGLISH_CARRIBEAN:
384cdf0e10cSrcweir 		nRet &= ~(ChgQuotes|ChgSglQuotes);
385cdf0e10cSrcweir 		break;
386cdf0e10cSrcweir 	}
387cdf0e10cSrcweir 	return nRet;
388cdf0e10cSrcweir }
389cdf0e10cSrcweir 
390cdf0e10cSrcweir 
SvxAutoCorrect(const String & rShareAutocorrFile,const String & rUserAutocorrFile)391cdf0e10cSrcweir SvxAutoCorrect::SvxAutoCorrect( const String& rShareAutocorrFile,
392cdf0e10cSrcweir 								const String& rUserAutocorrFile )
393cdf0e10cSrcweir 	: sShareAutoCorrFile( rShareAutocorrFile ),
394cdf0e10cSrcweir 	sUserAutoCorrFile( rUserAutocorrFile ),
395cdf0e10cSrcweir 	pLangTable( new SvxAutoCorrLanguageTable_Impl ),
396cdf0e10cSrcweir 	pLastFileTable( new SvxAutoCorrLastFileAskTable_Impl ),
397cdf0e10cSrcweir 	pCharClass( 0 ), bRunNext( false ),
398cdf0e10cSrcweir 	cStartDQuote( 0 ), cEndDQuote( 0 ), cStartSQuote( 0 ), cEndSQuote( 0 )
399cdf0e10cSrcweir {
400cdf0e10cSrcweir 	nFlags = SvxAutoCorrect::GetDefaultFlags();
401cdf0e10cSrcweir 
402cdf0e10cSrcweir 	cEmDash = ByteString::ConvertToUnicode( '\x97', RTL_TEXTENCODING_MS_1252 );
403cdf0e10cSrcweir 	cEnDash = ByteString::ConvertToUnicode( '\x96', RTL_TEXTENCODING_MS_1252 );
404cdf0e10cSrcweir }
405cdf0e10cSrcweir 
SvxAutoCorrect(const SvxAutoCorrect & rCpy)406cdf0e10cSrcweir SvxAutoCorrect::SvxAutoCorrect( const SvxAutoCorrect& rCpy )
407cdf0e10cSrcweir :	sShareAutoCorrFile( rCpy.sShareAutoCorrFile ),
408cdf0e10cSrcweir 	sUserAutoCorrFile( rCpy.sUserAutoCorrFile ),
409cdf0e10cSrcweir 
410cdf0e10cSrcweir 	aSwFlags( rCpy.aSwFlags ),
411cdf0e10cSrcweir 
412cdf0e10cSrcweir 	pLangTable( new SvxAutoCorrLanguageTable_Impl ),
413cdf0e10cSrcweir 	pLastFileTable( new SvxAutoCorrLastFileAskTable_Impl ),
414cdf0e10cSrcweir 	pCharClass( 0 ), bRunNext( false ),
415cdf0e10cSrcweir 
416cdf0e10cSrcweir 	nFlags( rCpy.nFlags & ~(ChgWordLstLoad|CplSttLstLoad|WrdSttLstLoad)),
417cdf0e10cSrcweir 	cStartDQuote( rCpy.cStartDQuote ), cEndDQuote( rCpy.cEndDQuote ),
418cdf0e10cSrcweir 	cStartSQuote( rCpy.cStartSQuote ), cEndSQuote( rCpy.cEndSQuote ),
419cdf0e10cSrcweir 	cEmDash( rCpy.cEmDash ), cEnDash( rCpy.cEnDash )
420cdf0e10cSrcweir {
421cdf0e10cSrcweir }
422cdf0e10cSrcweir 
423cdf0e10cSrcweir 
~SvxAutoCorrect()424cdf0e10cSrcweir SvxAutoCorrect::~SvxAutoCorrect()
425cdf0e10cSrcweir {
426cdf0e10cSrcweir 	lcl_ClearTable(*pLangTable);
427cdf0e10cSrcweir 	delete pLangTable;
428cdf0e10cSrcweir 	delete pLastFileTable;
429cdf0e10cSrcweir 	delete pCharClass;
430cdf0e10cSrcweir }
431cdf0e10cSrcweir 
_GetCharClass(LanguageType eLang)432cdf0e10cSrcweir void SvxAutoCorrect::_GetCharClass( LanguageType eLang )
433cdf0e10cSrcweir {
434cdf0e10cSrcweir 	delete pCharClass;
435cdf0e10cSrcweir 	pCharClass = new CharClass( SvxCreateLocale( eLang ));
436cdf0e10cSrcweir 	eCharClassLang = eLang;
437cdf0e10cSrcweir }
438cdf0e10cSrcweir 
SetAutoCorrFlag(long nFlag,sal_Bool bOn)439cdf0e10cSrcweir void SvxAutoCorrect::SetAutoCorrFlag( long nFlag, sal_Bool bOn )
440cdf0e10cSrcweir {
441cdf0e10cSrcweir 	long nOld = nFlags;
442cdf0e10cSrcweir 	nFlags = bOn ? nFlags | nFlag
443cdf0e10cSrcweir 				 : nFlags & ~nFlag;
444cdf0e10cSrcweir 
445cdf0e10cSrcweir 	if( !bOn )
446cdf0e10cSrcweir 	{
447cdf0e10cSrcweir 		if( (nOld & CptlSttSntnc) != (nFlags & CptlSttSntnc) )
448cdf0e10cSrcweir 			nFlags &= ~CplSttLstLoad;
449cdf0e10cSrcweir 		if( (nOld & CptlSttWrd) != (nFlags & CptlSttWrd) )
450cdf0e10cSrcweir 			nFlags &= ~WrdSttLstLoad;
451cdf0e10cSrcweir 		if( (nOld & Autocorrect) != (nFlags & Autocorrect) )
452cdf0e10cSrcweir 			nFlags &= ~ChgWordLstLoad;
453cdf0e10cSrcweir 	}
454cdf0e10cSrcweir }
455cdf0e10cSrcweir 
456cdf0e10cSrcweir 
457cdf0e10cSrcweir 	// Zwei Grossbuchstaben am Wort-Anfang ??
FnCptlSttWrd(SvxAutoCorrDoc & rDoc,const String & rTxt,xub_StrLen nSttPos,xub_StrLen nEndPos,LanguageType eLang)458cdf0e10cSrcweir sal_Bool SvxAutoCorrect::FnCptlSttWrd( SvxAutoCorrDoc& rDoc, const String& rTxt,
459cdf0e10cSrcweir 									xub_StrLen nSttPos, xub_StrLen nEndPos,
460cdf0e10cSrcweir 									LanguageType eLang )
461cdf0e10cSrcweir {
462cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
463cdf0e10cSrcweir 	CharClass& rCC = GetCharClass( eLang );
464cdf0e10cSrcweir 
465cdf0e10cSrcweir 	// loesche alle nicht alpanum. Zeichen am Wortanfang/-ende und
466cdf0e10cSrcweir 	// teste dann ( erkennt: "(min.", "/min.", usw.)
467cdf0e10cSrcweir 	for( ; nSttPos < nEndPos; ++nSttPos )
468cdf0e10cSrcweir 		if( rCC.isLetterNumeric( rTxt, nSttPos ))
469cdf0e10cSrcweir 			break;
470cdf0e10cSrcweir 	for( ; nSttPos < nEndPos; --nEndPos )
471cdf0e10cSrcweir 		if( rCC.isLetterNumeric( rTxt, nEndPos - 1 ))
472cdf0e10cSrcweir 			break;
473cdf0e10cSrcweir 
474cdf0e10cSrcweir 	// Zwei Grossbuchstaben am Wort-Anfang ??
475cdf0e10cSrcweir 	if( nSttPos+2 < nEndPos &&
476cdf0e10cSrcweir 		IsUpperLetter( rCC.getCharacterType( rTxt, nSttPos )) &&
477cdf0e10cSrcweir 		IsUpperLetter( rCC.getCharacterType( rTxt, ++nSttPos )) &&
478cdf0e10cSrcweir 		// ist das 3. Zeichen ein klein geschiebenes Alpha-Zeichen
479cdf0e10cSrcweir 		IsLowerLetter( rCC.getCharacterType( rTxt, nSttPos +1 )) &&
480cdf0e10cSrcweir 		// keine Sonder-Attribute ersetzen
481cdf0e10cSrcweir 		0x1 != rTxt.GetChar( nSttPos ) && 0x2 != rTxt.GetChar( nSttPos ))
482cdf0e10cSrcweir 	{
483cdf0e10cSrcweir 		// teste ob das Wort in einer Ausnahmeliste steht
484cdf0e10cSrcweir 		String sWord( rTxt.Copy( nSttPos - 1, nEndPos - nSttPos + 1 ));
485cdf0e10cSrcweir 		if( !FindInWrdSttExceptList(eLang, sWord) )
486cdf0e10cSrcweir 		{
487cdf0e10cSrcweir 			sal_Unicode cSave = rTxt.GetChar( nSttPos );
488cdf0e10cSrcweir 			String sChar( cSave );
489cdf0e10cSrcweir 			rCC.toLower( sChar );
490cdf0e10cSrcweir 			if( sChar.GetChar(0) != cSave && rDoc.ReplaceRange( nSttPos, 1, sChar ))
491cdf0e10cSrcweir 			{
492cdf0e10cSrcweir 				if( SaveWordWrdSttLst & nFlags )
493cdf0e10cSrcweir 					rDoc.SaveCpltSttWord( CptlSttWrd, nSttPos, sWord, cSave );
494cdf0e10cSrcweir 				bRet = sal_True;
495cdf0e10cSrcweir 			}
496cdf0e10cSrcweir 		}
497cdf0e10cSrcweir 	}
498cdf0e10cSrcweir 	return bRet;
499cdf0e10cSrcweir }
500cdf0e10cSrcweir 
501cdf0e10cSrcweir 
FnChgOrdinalNumber(SvxAutoCorrDoc & rDoc,const String & rTxt,xub_StrLen nSttPos,xub_StrLen nEndPos,LanguageType eLang)502cdf0e10cSrcweir sal_Bool SvxAutoCorrect::FnChgOrdinalNumber(
503cdf0e10cSrcweir 								SvxAutoCorrDoc& rDoc, const String& rTxt,
504cdf0e10cSrcweir 								xub_StrLen nSttPos, xub_StrLen nEndPos,
505cdf0e10cSrcweir 								LanguageType eLang )
506cdf0e10cSrcweir {
507cdf0e10cSrcweir // 1st, 2nd, 3rd, 4 - 0th
508cdf0e10cSrcweir // 201th oder 201st
509cdf0e10cSrcweir // 12th oder 12nd
510cdf0e10cSrcweir 	CharClass& rCC = GetCharClass( eLang );
511cdf0e10cSrcweir 	sal_Bool bChg = sal_False;
512cdf0e10cSrcweir 
513cdf0e10cSrcweir 	for( ; nSttPos < nEndPos; ++nSttPos )
514cdf0e10cSrcweir 		if( !lcl_IsInAsciiArr( sImplSttSkipChars, rTxt.GetChar( nSttPos ) ))
515cdf0e10cSrcweir 			break;
516cdf0e10cSrcweir 	for( ; nSttPos < nEndPos; --nEndPos )
517cdf0e10cSrcweir 		if( !lcl_IsInAsciiArr( sImplEndSkipChars, rTxt.GetChar( nEndPos - 1 ) ))
518cdf0e10cSrcweir 			break;
519cdf0e10cSrcweir 
520cdf0e10cSrcweir 	if( 2 < nEndPos - nSttPos &&
521cdf0e10cSrcweir 		rCC.isDigit( rTxt, nEndPos - 3 ) )
522cdf0e10cSrcweir 	{
523cdf0e10cSrcweir 		static sal_Char __READONLY_DATA
524cdf0e10cSrcweir 			sAll[]		= "th",			/* rest */
525cdf0e10cSrcweir 			sFirst[]	= "st",      	/* 1 */
526cdf0e10cSrcweir 			sSecond[]	= "nd",       	/* 2 */
527cdf0e10cSrcweir 			sThird[]	= "rd";       	/* 3 */
528cdf0e10cSrcweir 		static const sal_Char* __READONLY_DATA aNumberTab[ 4 ] =
529cdf0e10cSrcweir 		{
530cdf0e10cSrcweir 			sAll, sFirst, sSecond, sThird
531cdf0e10cSrcweir 		};
532cdf0e10cSrcweir 
533cdf0e10cSrcweir 		sal_Unicode c = rTxt.GetChar( nEndPos - 3 );
534cdf0e10cSrcweir 		if( ( c -= '0' ) > 3 )
535cdf0e10cSrcweir 			c = 0;
536cdf0e10cSrcweir 
537cdf0e10cSrcweir 		bChg = ( ((sal_Unicode)*((aNumberTab[ c ])+0)) ==
538cdf0e10cSrcweir 										rTxt.GetChar( nEndPos - 2 ) &&
539cdf0e10cSrcweir 				 ((sal_Unicode)*((aNumberTab[ c ])+1)) ==
540cdf0e10cSrcweir 				 						rTxt.GetChar( nEndPos - 1 )) ||
541cdf0e10cSrcweir 			   ( 3 < nEndPos - nSttPos &&
542cdf0e10cSrcweir 				( ((sal_Unicode)*(sAll+0)) == rTxt.GetChar( nEndPos - 2 ) &&
543cdf0e10cSrcweir 				  ((sal_Unicode)*(sAll+1)) == rTxt.GetChar( nEndPos - 1 )));
544cdf0e10cSrcweir 
545cdf0e10cSrcweir 		if( bChg )
546cdf0e10cSrcweir 		{
547cdf0e10cSrcweir 			// dann pruefe mal, ob alle bis zum Start alle Zahlen sind
548cdf0e10cSrcweir 			for( xub_StrLen n = nEndPos - 3; nSttPos < n; )
549cdf0e10cSrcweir 				if( !rCC.isDigit( rTxt, --n ) )
550cdf0e10cSrcweir 				{
551cdf0e10cSrcweir 					bChg = !rCC.isLetter( rTxt, n );
552cdf0e10cSrcweir 					break;
553cdf0e10cSrcweir 				}
554cdf0e10cSrcweir 
555cdf0e10cSrcweir 			if( bChg )		// dann setze mal das Escapement Attribut
556cdf0e10cSrcweir 			{
557cdf0e10cSrcweir 				SvxEscapementItem aSvxEscapementItem( DFLT_ESC_AUTO_SUPER,
558cdf0e10cSrcweir                                                     DFLT_ESC_PROP, SID_ATTR_CHAR_ESCAPEMENT );
559cdf0e10cSrcweir 				rDoc.SetAttr( nEndPos - 2, nEndPos,
560cdf0e10cSrcweir 								SID_ATTR_CHAR_ESCAPEMENT,
561cdf0e10cSrcweir 								aSvxEscapementItem);
562cdf0e10cSrcweir 			}
563cdf0e10cSrcweir 		}
564cdf0e10cSrcweir 
565cdf0e10cSrcweir 	}
566cdf0e10cSrcweir 	return bChg;
567cdf0e10cSrcweir }
568cdf0e10cSrcweir 
569cdf0e10cSrcweir 
FnChgToEnEmDash(SvxAutoCorrDoc & rDoc,const String & rTxt,xub_StrLen nSttPos,xub_StrLen nEndPos,LanguageType eLang)570cdf0e10cSrcweir sal_Bool SvxAutoCorrect::FnChgToEnEmDash(
571cdf0e10cSrcweir 								SvxAutoCorrDoc& rDoc, const String& rTxt,
572cdf0e10cSrcweir 								xub_StrLen nSttPos, xub_StrLen nEndPos,
573cdf0e10cSrcweir 								LanguageType eLang )
574cdf0e10cSrcweir {
575cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
576cdf0e10cSrcweir 	CharClass& rCC = GetCharClass( eLang );
577cdf0e10cSrcweir     if (eLang == LANGUAGE_SYSTEM)
578cdf0e10cSrcweir         eLang = GetAppLang();
579cdf0e10cSrcweir     bool bAlwaysUseEmDash = (cEmDash && (eLang == LANGUAGE_RUSSIAN || eLang == LANGUAGE_UKRAINIAN));
580cdf0e10cSrcweir 
581cdf0e10cSrcweir 	// ersetze " - " oder " --" durch "enDash"
582cdf0e10cSrcweir 	if( cEnDash && 1 < nSttPos && 1 <= nEndPos - nSttPos )
583cdf0e10cSrcweir 	{
584cdf0e10cSrcweir 		sal_Unicode cCh = rTxt.GetChar( nSttPos );
585cdf0e10cSrcweir 		if( '-' == cCh )
586cdf0e10cSrcweir 		{
587cdf0e10cSrcweir 			if( ' ' == rTxt.GetChar( nSttPos-1 ) &&
588cdf0e10cSrcweir 				'-' == rTxt.GetChar( nSttPos+1 ))
589cdf0e10cSrcweir 			{
590cdf0e10cSrcweir 				xub_StrLen n;
591cdf0e10cSrcweir 				for( n = nSttPos+2; n < nEndPos && lcl_IsInAsciiArr(
592cdf0e10cSrcweir 							sImplSttSkipChars,(cCh = rTxt.GetChar( n )));
593cdf0e10cSrcweir 						++n )
594cdf0e10cSrcweir 					;
595cdf0e10cSrcweir 
596cdf0e10cSrcweir 				// found: " --[<AnySttChars>][A-z0-9]
597cdf0e10cSrcweir 				if( rCC.isLetterNumeric( cCh ) )
598cdf0e10cSrcweir 				{
599cdf0e10cSrcweir 					for( n = nSttPos-1; n && lcl_IsInAsciiArr(
600cdf0e10cSrcweir 							sImplEndSkipChars,(cCh = rTxt.GetChar( --n ))); )
601cdf0e10cSrcweir 						;
602cdf0e10cSrcweir 
603cdf0e10cSrcweir 					// found: "[A-z0-9][<AnyEndChars>] --[<AnySttChars>][A-z0-9]
604cdf0e10cSrcweir 					if( rCC.isLetterNumeric( cCh ))
605cdf0e10cSrcweir 					{
606cdf0e10cSrcweir 						rDoc.Delete( nSttPos, nSttPos + 2 );
607cdf0e10cSrcweir                         rDoc.Insert( nSttPos, bAlwaysUseEmDash ? cEmDash : cEnDash );
608cdf0e10cSrcweir 						bRet = sal_True;
609cdf0e10cSrcweir 					}
610cdf0e10cSrcweir 				}
611cdf0e10cSrcweir 			}
612cdf0e10cSrcweir 		}
613cdf0e10cSrcweir 		else if( 3 < nSttPos &&
614cdf0e10cSrcweir 				 ' ' == rTxt.GetChar( nSttPos-1 ) &&
615cdf0e10cSrcweir 				 '-' == rTxt.GetChar( nSttPos-2 ))
616cdf0e10cSrcweir 		{
617cdf0e10cSrcweir 			xub_StrLen n, nLen = 1, nTmpPos = nSttPos - 2;
618cdf0e10cSrcweir 			if( '-' == ( cCh = rTxt.GetChar( nTmpPos-1 )) )
619cdf0e10cSrcweir 			{
620cdf0e10cSrcweir 				--nTmpPos;
621cdf0e10cSrcweir 				++nLen;
622cdf0e10cSrcweir 				cCh = rTxt.GetChar( nTmpPos-1 );
623cdf0e10cSrcweir 			}
624cdf0e10cSrcweir 			if( ' ' == cCh )
625cdf0e10cSrcweir 			{
626cdf0e10cSrcweir 				for( n = nSttPos; n < nEndPos && lcl_IsInAsciiArr(
627cdf0e10cSrcweir 							sImplSttSkipChars,(cCh = rTxt.GetChar( n )));
628cdf0e10cSrcweir 						++n )
629cdf0e10cSrcweir 					;
630cdf0e10cSrcweir 
631cdf0e10cSrcweir 				// found: " - [<AnySttChars>][A-z0-9]
632cdf0e10cSrcweir 				if( rCC.isLetterNumeric( cCh ) )
633cdf0e10cSrcweir 				{
634cdf0e10cSrcweir 					cCh = ' ';
635cdf0e10cSrcweir 					for( n = nTmpPos-1; n && lcl_IsInAsciiArr(
636cdf0e10cSrcweir 							sImplEndSkipChars,(cCh = rTxt.GetChar( --n ))); )
637cdf0e10cSrcweir 							;
638cdf0e10cSrcweir 					// found: "[A-z0-9][<AnyEndChars>] - [<AnySttChars>][A-z0-9]
639cdf0e10cSrcweir 					if( rCC.isLetterNumeric( cCh ))
640cdf0e10cSrcweir 					{
641cdf0e10cSrcweir 						rDoc.Delete( nTmpPos, nTmpPos + nLen );
642cdf0e10cSrcweir                         rDoc.Insert( nTmpPos, bAlwaysUseEmDash ? cEmDash : cEnDash );
643cdf0e10cSrcweir 						bRet = sal_True;
644cdf0e10cSrcweir 					}
645cdf0e10cSrcweir 				}
646cdf0e10cSrcweir 			}
647cdf0e10cSrcweir 		}
648cdf0e10cSrcweir 	}
649cdf0e10cSrcweir 
650cdf0e10cSrcweir     // Replace [A-z0-9]--[A-z0-9] double dash with "emDash" or "enDash".
651cdf0e10cSrcweir     // Finnish and Hungarian use enDash instead of emDash.
652cdf0e10cSrcweir     bool bEnDash = (eLang == LANGUAGE_HUNGARIAN || eLang == LANGUAGE_FINNISH);
653cdf0e10cSrcweir     if( ((cEmDash && !bEnDash) || (cEnDash && bEnDash)) && 4 <= nEndPos - nSttPos )
654cdf0e10cSrcweir 	{
655cdf0e10cSrcweir 		String sTmp( rTxt.Copy( nSttPos, nEndPos - nSttPos ) );
656cdf0e10cSrcweir 		xub_StrLen nFndPos = sTmp.SearchAscii( "--" );
657cdf0e10cSrcweir 		if( STRING_NOTFOUND != nFndPos && nFndPos &&
658cdf0e10cSrcweir 			nFndPos + 2 < sTmp.Len() &&
659cdf0e10cSrcweir 			( rCC.isLetterNumeric( sTmp, nFndPos - 1 ) ||
660cdf0e10cSrcweir 			  lcl_IsInAsciiArr( sImplEndSkipChars, rTxt.GetChar( nFndPos - 1 ) )) &&
661cdf0e10cSrcweir 			( rCC.isLetterNumeric( sTmp, nFndPos + 2 ) ||
662cdf0e10cSrcweir 			lcl_IsInAsciiArr( sImplSttSkipChars, rTxt.GetChar( nFndPos + 2 ) )))
663cdf0e10cSrcweir 		{
664cdf0e10cSrcweir 			nSttPos = nSttPos + nFndPos;
665cdf0e10cSrcweir 			rDoc.Delete( nSttPos, nSttPos + 2 );
666cdf0e10cSrcweir             rDoc.Insert( nSttPos, (bEnDash ? cEnDash : cEmDash) );
667cdf0e10cSrcweir 			bRet = sal_True;
668cdf0e10cSrcweir 		}
669cdf0e10cSrcweir 	}
670cdf0e10cSrcweir 	return bRet;
671cdf0e10cSrcweir }
672cdf0e10cSrcweir 
FnAddNonBrkSpace(SvxAutoCorrDoc & rDoc,const String & rTxt,xub_StrLen,xub_StrLen nEndPos,LanguageType eLang)673cdf0e10cSrcweir sal_Bool SvxAutoCorrect::FnAddNonBrkSpace(
674cdf0e10cSrcweir                                 SvxAutoCorrDoc& rDoc, const String& rTxt,
675cdf0e10cSrcweir                                 xub_StrLen, xub_StrLen nEndPos,
676cdf0e10cSrcweir                                 LanguageType eLang )
677cdf0e10cSrcweir {
678cdf0e10cSrcweir     bool bRet = false;
679cdf0e10cSrcweir 
680cdf0e10cSrcweir     CharClass& rCC = GetCharClass( eLang );
681cdf0e10cSrcweir     const lang::Locale rLocale = rCC.getLocale( );
682cdf0e10cSrcweir 
683cdf0e10cSrcweir     if ( rLocale.Language == OUString::createFromAscii( "fr" ) )
684cdf0e10cSrcweir     {
685cdf0e10cSrcweir         bool bFrCA = rLocale.Country == OUString::createFromAscii( "CA" );
686cdf0e10cSrcweir         OUString allChars = OUString::createFromAscii( ":;!?" );
687cdf0e10cSrcweir         OUString chars( allChars );
688cdf0e10cSrcweir         if ( bFrCA )
689cdf0e10cSrcweir             chars = OUString::createFromAscii( ":" );
690cdf0e10cSrcweir 
691cdf0e10cSrcweir         sal_Unicode cChar = rTxt.GetChar( nEndPos );
692cdf0e10cSrcweir         bool bHasSpace = chars.indexOf( sal_Unicode( cChar ) ) != -1;
693cdf0e10cSrcweir         bool bIsSpecial = allChars.indexOf( sal_Unicode( cChar ) ) != -1;
694cdf0e10cSrcweir         if ( bIsSpecial )
695cdf0e10cSrcweir         {
696cdf0e10cSrcweir             // Get the last word delimiter position
697cdf0e10cSrcweir             xub_StrLen nSttWdPos = nEndPos;
698cdf0e10cSrcweir             while( nSttWdPos && !IsWordDelim( rTxt.GetChar( --nSttWdPos )))
699cdf0e10cSrcweir                 ;
700cdf0e10cSrcweir 
701cdf0e10cSrcweir             // Check the presence of "://" in the word
702cdf0e10cSrcweir             xub_StrLen nStrPos = rTxt.Search( String::CreateFromAscii( "://" ), nSttWdPos + 1 );
703cdf0e10cSrcweir             if ( STRING_NOTFOUND == nStrPos && nEndPos > 0 )
704cdf0e10cSrcweir             {
705cdf0e10cSrcweir                 // Check the previous char
706cdf0e10cSrcweir                 sal_Unicode cPrevChar = rTxt.GetChar( nEndPos - 1 );
707cdf0e10cSrcweir                 if ( ( chars.indexOf( sal_Unicode( cPrevChar ) ) == -1 ) && cPrevChar != '\t' )
708cdf0e10cSrcweir                 {
709cdf0e10cSrcweir                     // Remove any previous normal space
710cdf0e10cSrcweir                     xub_StrLen nPos = nEndPos - 1;
711cdf0e10cSrcweir                     while ( cPrevChar == ' ' || cPrevChar == CHAR_HARDBLANK )
712cdf0e10cSrcweir                     {
713cdf0e10cSrcweir                         if ( nPos == 0 ) break;
714cdf0e10cSrcweir                         nPos--;
715cdf0e10cSrcweir                         cPrevChar = rTxt.GetChar( nPos );
716cdf0e10cSrcweir                     }
717cdf0e10cSrcweir 
718cdf0e10cSrcweir                     if ( nPos != 0 )
719cdf0e10cSrcweir                     {
720cdf0e10cSrcweir                         nPos++;
721cdf0e10cSrcweir                         if ( nEndPos - nPos > 0 )
722cdf0e10cSrcweir                             rDoc.Delete( nPos, nEndPos );
723cdf0e10cSrcweir 
724cdf0e10cSrcweir                         // Add the non-breaking space at the end pos
725cdf0e10cSrcweir                         if ( bHasSpace )
726cdf0e10cSrcweir                             rDoc.Insert( nPos, CHAR_HARDBLANK );
727cdf0e10cSrcweir                         bRunNext = true;
728cdf0e10cSrcweir                         bRet = true;
729cdf0e10cSrcweir                     }
730cdf0e10cSrcweir                 }
731cdf0e10cSrcweir                 else if ( chars.indexOf( sal_Unicode( cPrevChar ) ) != -1 )
732cdf0e10cSrcweir                     bRunNext = true;
733cdf0e10cSrcweir             }
734cdf0e10cSrcweir         }
735cdf0e10cSrcweir         else if ( cChar == '/' && nEndPos > 1 && rTxt.Len() > (nEndPos - 1) )
736cdf0e10cSrcweir         {
737cdf0e10cSrcweir             // Remove the hardspace right before to avoid formatting URLs
738cdf0e10cSrcweir             sal_Unicode cPrevChar = rTxt.GetChar( nEndPos - 1 );
739cdf0e10cSrcweir             sal_Unicode cMaybeSpaceChar = rTxt.GetChar( nEndPos - 2 );
740cdf0e10cSrcweir             if ( cPrevChar == ':' && cMaybeSpaceChar == CHAR_HARDBLANK )
741cdf0e10cSrcweir             {
742cdf0e10cSrcweir                 rDoc.Delete( nEndPos - 2, nEndPos - 1 );
743cdf0e10cSrcweir                 bRet = true;
744cdf0e10cSrcweir             }
745cdf0e10cSrcweir         }
746cdf0e10cSrcweir     }
747cdf0e10cSrcweir 
748cdf0e10cSrcweir     return bRet;
749cdf0e10cSrcweir }
750cdf0e10cSrcweir 
FnSetINetAttr(SvxAutoCorrDoc & rDoc,const String & rTxt,xub_StrLen nSttPos,xub_StrLen nEndPos,LanguageType eLang)751cdf0e10cSrcweir sal_Bool SvxAutoCorrect::FnSetINetAttr( SvxAutoCorrDoc& rDoc, const String& rTxt,
752cdf0e10cSrcweir 									xub_StrLen nSttPos, xub_StrLen nEndPos,
753cdf0e10cSrcweir 									LanguageType eLang )
754cdf0e10cSrcweir {
755cdf0e10cSrcweir 	String sURL( URIHelper::FindFirstURLInText( rTxt, nSttPos, nEndPos,
756cdf0e10cSrcweir 												GetCharClass( eLang ) ));
757cdf0e10cSrcweir 	sal_Bool bRet = 0 != sURL.Len();
758cdf0e10cSrcweir 	if( bRet )			// also Attribut setzen:
759cdf0e10cSrcweir 		rDoc.SetINetAttr( nSttPos, nEndPos, sURL );
760cdf0e10cSrcweir 	return bRet;
761cdf0e10cSrcweir }
762cdf0e10cSrcweir 
763cdf0e10cSrcweir 
FnChgWeightUnderl(SvxAutoCorrDoc & rDoc,const String & rTxt,xub_StrLen,xub_StrLen nEndPos,LanguageType eLang)764cdf0e10cSrcweir sal_Bool SvxAutoCorrect::FnChgWeightUnderl( SvxAutoCorrDoc& rDoc, const String& rTxt,
765cdf0e10cSrcweir 										xub_StrLen, xub_StrLen nEndPos,
766cdf0e10cSrcweir 										LanguageType eLang )
767cdf0e10cSrcweir {
768cdf0e10cSrcweir 	// Bedingung:
769cdf0e10cSrcweir 	//	Am Anfang:	_ oder * hinter Space mit nachfolgenden !Space
770cdf0e10cSrcweir 	//	Am Ende:	_ oder * vor Space (Worttrenner?)
771cdf0e10cSrcweir 
772cdf0e10cSrcweir 	sal_Unicode c, cInsChar = rTxt.GetChar( nEndPos );	// unterstreichen oder fett
773cdf0e10cSrcweir 	if( ++nEndPos != rTxt.Len() &&
774cdf0e10cSrcweir 		!IsWordDelim( rTxt.GetChar( nEndPos ) ) )
775cdf0e10cSrcweir 		return sal_False;
776cdf0e10cSrcweir 
777cdf0e10cSrcweir 	--nEndPos;
778cdf0e10cSrcweir 
779cdf0e10cSrcweir 	sal_Bool bAlphaNum = sal_False;
780cdf0e10cSrcweir 	xub_StrLen nPos = nEndPos, nFndPos = STRING_NOTFOUND;
781cdf0e10cSrcweir 	CharClass& rCC = GetCharClass( eLang );
782cdf0e10cSrcweir 
783cdf0e10cSrcweir 	while( nPos )
784cdf0e10cSrcweir 	{
785cdf0e10cSrcweir 		switch( c = rTxt.GetChar( --nPos ) )
786cdf0e10cSrcweir 		{
787cdf0e10cSrcweir 		case '_':
788cdf0e10cSrcweir 		case '*':
789cdf0e10cSrcweir 			if( c == cInsChar )
790cdf0e10cSrcweir 			{
791cdf0e10cSrcweir 				if( bAlphaNum && nPos+1 < nEndPos && ( !nPos ||
792cdf0e10cSrcweir 					IsWordDelim( rTxt.GetChar( nPos-1 ))) &&
793cdf0e10cSrcweir 					!IsWordDelim( rTxt.GetChar( nPos+1 )))
794cdf0e10cSrcweir 						nFndPos = nPos;
795cdf0e10cSrcweir 				else
796cdf0e10cSrcweir 					// Bedingung ist nicht erfuellt, also abbrechen
797cdf0e10cSrcweir 					nFndPos = STRING_NOTFOUND;
798cdf0e10cSrcweir 				nPos = 0;
799cdf0e10cSrcweir 			}
800cdf0e10cSrcweir 			break;
801cdf0e10cSrcweir 		default:
802cdf0e10cSrcweir 			if( !bAlphaNum )
803cdf0e10cSrcweir 				bAlphaNum = rCC.isLetterNumeric( rTxt, nPos );
804cdf0e10cSrcweir 		}
805cdf0e10cSrcweir 	}
806cdf0e10cSrcweir 
807cdf0e10cSrcweir 	if( STRING_NOTFOUND != nFndPos )
808cdf0e10cSrcweir 	{
809cdf0e10cSrcweir 		// ueber den gefundenen Bereich das Attribut aufspannen und
810cdf0e10cSrcweir 		// das gefunde und am Ende stehende Zeichen loeschen
811cdf0e10cSrcweir 		if( '*' == cInsChar )			// Fett
812cdf0e10cSrcweir 		{
813cdf0e10cSrcweir             SvxWeightItem aSvxWeightItem( WEIGHT_BOLD, SID_ATTR_CHAR_WEIGHT );
814cdf0e10cSrcweir 			rDoc.SetAttr( nFndPos + 1, nEndPos,
815cdf0e10cSrcweir 							SID_ATTR_CHAR_WEIGHT,
816cdf0e10cSrcweir 							aSvxWeightItem);
817cdf0e10cSrcweir 		}
818cdf0e10cSrcweir 		else							// unterstrichen
819cdf0e10cSrcweir 		{
820cdf0e10cSrcweir             SvxUnderlineItem aSvxUnderlineItem( UNDERLINE_SINGLE, SID_ATTR_CHAR_UNDERLINE );
821cdf0e10cSrcweir 			rDoc.SetAttr( nFndPos + 1, nEndPos,
822cdf0e10cSrcweir 							SID_ATTR_CHAR_UNDERLINE,
823cdf0e10cSrcweir 							aSvxUnderlineItem);
824cdf0e10cSrcweir 		}
825cdf0e10cSrcweir 		rDoc.Delete( nEndPos, nEndPos + 1 );
826cdf0e10cSrcweir 		rDoc.Delete( nFndPos, nFndPos + 1 );
827cdf0e10cSrcweir 	}
828cdf0e10cSrcweir 
829cdf0e10cSrcweir 	return STRING_NOTFOUND != nFndPos;
830cdf0e10cSrcweir }
831cdf0e10cSrcweir 
832cdf0e10cSrcweir 
FnCptlSttSntnc(SvxAutoCorrDoc & rDoc,const String & rTxt,sal_Bool bNormalPos,xub_StrLen nSttPos,xub_StrLen nEndPos,LanguageType eLang)833cdf0e10cSrcweir sal_Bool SvxAutoCorrect::FnCptlSttSntnc( SvxAutoCorrDoc& rDoc,
834cdf0e10cSrcweir 									const String& rTxt, sal_Bool bNormalPos,
835cdf0e10cSrcweir 									xub_StrLen nSttPos, xub_StrLen nEndPos,
836cdf0e10cSrcweir 									LanguageType eLang )
837cdf0e10cSrcweir {
838cdf0e10cSrcweir 	// Grossbuchstabe am Satz-Anfang ??
839cdf0e10cSrcweir 	if( !rTxt.Len() || nEndPos <= nSttPos )
840cdf0e10cSrcweir 		return sal_False;
841cdf0e10cSrcweir 
842cdf0e10cSrcweir  	CharClass& rCC = GetCharClass( eLang );
843cdf0e10cSrcweir 	String aText( rTxt );
844cdf0e10cSrcweir 	const sal_Unicode *pStart = aText.GetBuffer(),
845cdf0e10cSrcweir 					  *pStr = pStart + nEndPos,
846cdf0e10cSrcweir 					  *pWordStt = 0,
847cdf0e10cSrcweir 					  *pDelim = 0;
848cdf0e10cSrcweir 
849cdf0e10cSrcweir 	sal_Bool bAtStart = sal_False, bPrevPara = sal_False;
850cdf0e10cSrcweir 	do {
851cdf0e10cSrcweir 		--pStr;
852cdf0e10cSrcweir 		if( rCC.isLetter(
853cdf0e10cSrcweir                 aText, sal::static_int_cast< xub_StrLen >( pStr - pStart ) ) )
854cdf0e10cSrcweir 		{
855cdf0e10cSrcweir 			if( !pWordStt )
856cdf0e10cSrcweir 				pDelim = pStr+1;
857cdf0e10cSrcweir 			pWordStt = pStr;
858cdf0e10cSrcweir 		}
859cdf0e10cSrcweir 		else if( pWordStt &&
860cdf0e10cSrcweir                  !rCC.isDigit(
861cdf0e10cSrcweir                      aText,
862cdf0e10cSrcweir                      sal::static_int_cast< xub_StrLen >( pStr - pStart ) ) )
863cdf0e10cSrcweir 		{
864cdf0e10cSrcweir 			if( lcl_IsInAsciiArr( sImplWordChars, *pStr ) &&
865cdf0e10cSrcweir 				pWordStt - 1 == pStr &&
866cdf0e10cSrcweir                 // --> FME 2005-02-14 #i38971#
867cdf0e10cSrcweir                 // l'intallazione at beginning of paragraph. Replaced < by <=
868cdf0e10cSrcweir 				(long)(pStart + 1) <= (long)pStr &&
869cdf0e10cSrcweir                 // <--
870cdf0e10cSrcweir 				rCC.isLetter(
871cdf0e10cSrcweir                     aText,
872cdf0e10cSrcweir                     sal::static_int_cast< xub_StrLen >( pStr-1 - pStart ) ) )
873cdf0e10cSrcweir 				pWordStt = --pStr;
874cdf0e10cSrcweir 			else
875cdf0e10cSrcweir 				break;
876cdf0e10cSrcweir 		}
877cdf0e10cSrcweir 	} while( 0 == ( bAtStart = (pStart == pStr)) );
878cdf0e10cSrcweir 
879cdf0e10cSrcweir 
880cdf0e10cSrcweir 	if(	!pWordStt ||
881cdf0e10cSrcweir 		rCC.isDigit(
882cdf0e10cSrcweir             aText, sal::static_int_cast< xub_StrLen >( pStr - pStart ) ) ||
883cdf0e10cSrcweir 		IsUpperLetter(
884cdf0e10cSrcweir             rCC.getCharacterType(
885cdf0e10cSrcweir                 aText,
886cdf0e10cSrcweir                 sal::static_int_cast< xub_StrLen >( pWordStt - pStart ) ) ) ||
887cdf0e10cSrcweir 		0x1 == *pWordStt || 0x2 == *pWordStt )
888cdf0e10cSrcweir 		return sal_False;		// kein zu ersetzendes Zeichen, oder schon ok
889cdf0e10cSrcweir 
890cdf0e10cSrcweir 	// JP 27.10.97: wenn das Wort weniger als 3 Zeichen hat und der Trenner
891cdf0e10cSrcweir 	//				ein "Num"-Trenner ist, dann nicht ersetzen!
892cdf0e10cSrcweir 	//				Damit wird ein "a.",  "a)", "a-a" nicht ersetzt!
893cdf0e10cSrcweir 	if( *pDelim && 2 >= pDelim - pWordStt &&
894cdf0e10cSrcweir 		lcl_IsInAsciiArr( ".-)>", *pDelim ) )
895cdf0e10cSrcweir 		return sal_False;
896cdf0e10cSrcweir 
897cdf0e10cSrcweir 	if( !bAtStart )	// noch kein Absatz Anfang ?
898cdf0e10cSrcweir 	{
899cdf0e10cSrcweir         if ( IsWordDelim( *pStr ) )
900cdf0e10cSrcweir         {
901cdf0e10cSrcweir             while( 0 == ( bAtStart = (pStart == pStr--) ) && IsWordDelim( *pStr ))
902cdf0e10cSrcweir                 ;
903cdf0e10cSrcweir         }
904cdf0e10cSrcweir         // Asian full stop, full width full stop, full width exclamation mark
905cdf0e10cSrcweir         // and full width question marks are treated as word delimiters
906cdf0e10cSrcweir         else if ( 0x3002 != *pStr && 0xFF0E != *pStr && 0xFF01 != *pStr &&
907cdf0e10cSrcweir                   0xFF1F != *pStr )
908cdf0e10cSrcweir             return sal_False; // kein gueltiger Trenner -> keine Ersetzung
909cdf0e10cSrcweir     }
910cdf0e10cSrcweir 
911cdf0e10cSrcweir 	if( bAtStart )	// am Absatz Anfang ?
912cdf0e10cSrcweir 	{
913cdf0e10cSrcweir 		// Ueberpruefe den vorherigen Absatz, wenn es diesen gibt.
914cdf0e10cSrcweir 		// Wenn ja, dann pruefe auf SatzTrenner am Ende.
915cdf0e10cSrcweir 		const String* pPrevPara = rDoc.GetPrevPara( bNormalPos );
916cdf0e10cSrcweir 		if( !pPrevPara )
917cdf0e10cSrcweir 		{
918cdf0e10cSrcweir 			// gueltiger Trenner -> Ersetze
919cdf0e10cSrcweir 			String sChar( *pWordStt );
920cdf0e10cSrcweir 			rCC.toUpper( sChar );
921cdf0e10cSrcweir 			return  sChar != *pWordStt &&
922cdf0e10cSrcweir 					rDoc.ReplaceRange( xub_StrLen( pWordStt - pStart ), 1, sChar );
923cdf0e10cSrcweir 		}
924cdf0e10cSrcweir 
925cdf0e10cSrcweir 		aText = *pPrevPara;
926cdf0e10cSrcweir 		bPrevPara = sal_True;
927cdf0e10cSrcweir 		bAtStart = sal_False;
928cdf0e10cSrcweir 		pStart = aText.GetBuffer();
929cdf0e10cSrcweir 		pStr = pStart + aText.Len();
930cdf0e10cSrcweir 
931cdf0e10cSrcweir 		do {			// alle Blanks ueberlesen
932cdf0e10cSrcweir 			--pStr;
933cdf0e10cSrcweir 			if( !IsWordDelim( *pStr ))
934cdf0e10cSrcweir 				break;
935cdf0e10cSrcweir 		} while( 0 == ( bAtStart = (pStart == pStr)) );
936cdf0e10cSrcweir 
937cdf0e10cSrcweir 		if( bAtStart )
938cdf0e10cSrcweir 			return sal_False;		// kein gueltiger Trenner -> keine Ersetzung
939cdf0e10cSrcweir 	}
940cdf0e10cSrcweir 
941cdf0e10cSrcweir 	// bis hierhier wurde [ \t]+[A-Z0-9]+ gefunden. Test jetzt auf den
942cdf0e10cSrcweir 	// Satztrenner. Es koennen alle 3 vorkommen, aber nicht mehrfach !!
943cdf0e10cSrcweir 	const sal_Unicode* pExceptStt = 0;
944cdf0e10cSrcweir 	if( !bAtStart )
945cdf0e10cSrcweir 	{
946cdf0e10cSrcweir 		sal_Bool bWeiter = sal_True;
947cdf0e10cSrcweir 		int nFlag = C_NONE;
948cdf0e10cSrcweir 		do {
949cdf0e10cSrcweir 			switch( *pStr )
950cdf0e10cSrcweir 			{
951cdf0e10cSrcweir             // Western and Asian full stop
952cdf0e10cSrcweir 			case '.':
953cdf0e10cSrcweir             case 0x3002 :
954cdf0e10cSrcweir             case 0xFF0E :
955cdf0e10cSrcweir 				{
956cdf0e10cSrcweir 					if( nFlag & C_FULL_STOP )
957cdf0e10cSrcweir 						return sal_False;		// kein gueltiger Trenner -> keine Ersetzung
958cdf0e10cSrcweir 					nFlag |= C_FULL_STOP;
959cdf0e10cSrcweir 					pExceptStt = pStr;
960cdf0e10cSrcweir 				}
961cdf0e10cSrcweir 				break;
962cdf0e10cSrcweir 			case '!':
963cdf0e10cSrcweir             case 0xFF01 :
964cdf0e10cSrcweir 				{
965cdf0e10cSrcweir 					if( nFlag & C_EXCLAMATION_MARK )
966cdf0e10cSrcweir 						return sal_False; 	// kein gueltiger Trenner -> keine Ersetzung
967cdf0e10cSrcweir 					nFlag |= C_EXCLAMATION_MARK;
968cdf0e10cSrcweir 				}
969cdf0e10cSrcweir 				break;
970cdf0e10cSrcweir 			case '?':
971cdf0e10cSrcweir             case 0xFF1F :
972cdf0e10cSrcweir 				{
973cdf0e10cSrcweir 					if( nFlag & C_QUESTION_MARK)
974cdf0e10cSrcweir 						return sal_False;		// kein gueltiger Trenner -> keine Ersetzung
975cdf0e10cSrcweir 					nFlag |= C_QUESTION_MARK;
976cdf0e10cSrcweir 				}
977cdf0e10cSrcweir 				break;
978cdf0e10cSrcweir 			default:
979cdf0e10cSrcweir 				if( !nFlag )
980cdf0e10cSrcweir 					return sal_False;		// kein gueltiger Trenner -> keine Ersetzung
981cdf0e10cSrcweir 				else
982cdf0e10cSrcweir 					bWeiter = sal_False;
983cdf0e10cSrcweir 				break;
984cdf0e10cSrcweir 			}
985cdf0e10cSrcweir 
986cdf0e10cSrcweir 			if( bWeiter && pStr-- == pStart )
987cdf0e10cSrcweir 			{
988cdf0e10cSrcweir // !!! wenn am Anfang, dann nie ersetzen.
989cdf0e10cSrcweir //				if( !nFlag )
990cdf0e10cSrcweir 					return sal_False;		// kein gueltiger Trenner -> keine Ersetzung
991cdf0e10cSrcweir //				++pStr;
992cdf0e10cSrcweir //				break;		// Schleife beenden
993cdf0e10cSrcweir 			}
994cdf0e10cSrcweir 		} while( bWeiter );
995cdf0e10cSrcweir 		if( C_FULL_STOP != nFlag )
996cdf0e10cSrcweir 			pExceptStt = 0;
997cdf0e10cSrcweir 	}
998cdf0e10cSrcweir 
999cdf0e10cSrcweir 	if( 2 > ( pStr - pStart ) )
1000cdf0e10cSrcweir 		return sal_False;
1001cdf0e10cSrcweir 
1002cdf0e10cSrcweir 	if( !rCC.isLetterNumeric(
1003cdf0e10cSrcweir             aText, sal::static_int_cast< xub_StrLen >( pStr-- - pStart ) ) )
1004cdf0e10cSrcweir 	{
1005cdf0e10cSrcweir 		sal_Bool bValid = sal_False, bAlphaFnd = sal_False;
1006cdf0e10cSrcweir 		const sal_Unicode* pTmpStr = pStr;
1007cdf0e10cSrcweir 		while( !bValid )
1008cdf0e10cSrcweir 		{
1009cdf0e10cSrcweir 			if( rCC.isDigit(
1010cdf0e10cSrcweir                     aText,
1011cdf0e10cSrcweir                     sal::static_int_cast< xub_StrLen >( pTmpStr - pStart ) ) )
1012cdf0e10cSrcweir 			{
1013cdf0e10cSrcweir 				bValid = sal_True;
1014cdf0e10cSrcweir 				pStr = pTmpStr - 1;
1015cdf0e10cSrcweir 			}
1016cdf0e10cSrcweir 			else if( rCC.isLetter(
1017cdf0e10cSrcweir                          aText,
1018cdf0e10cSrcweir                          sal::static_int_cast< xub_StrLen >(
1019cdf0e10cSrcweir                              pTmpStr - pStart ) ) )
1020cdf0e10cSrcweir 			{
1021cdf0e10cSrcweir 				if( bAlphaFnd )
1022cdf0e10cSrcweir 				{
1023cdf0e10cSrcweir 					bValid = sal_True;
1024cdf0e10cSrcweir 					pStr = pTmpStr;
1025cdf0e10cSrcweir 				}
1026cdf0e10cSrcweir 				else
1027cdf0e10cSrcweir 					bAlphaFnd = sal_True;
1028cdf0e10cSrcweir 			}
1029cdf0e10cSrcweir 			else if( bAlphaFnd || IsWordDelim( *pTmpStr ) )
1030cdf0e10cSrcweir 				break;
1031cdf0e10cSrcweir 
1032cdf0e10cSrcweir 			if( pTmpStr == pStart )
1033cdf0e10cSrcweir 				break;
1034cdf0e10cSrcweir 
1035cdf0e10cSrcweir 			--pTmpStr;
1036cdf0e10cSrcweir 		}
1037cdf0e10cSrcweir 
1038cdf0e10cSrcweir 		if( !bValid )
1039cdf0e10cSrcweir 			return sal_False;		// kein gueltiger Trenner -> keine Ersetzung
1040cdf0e10cSrcweir 	}
1041cdf0e10cSrcweir 
1042cdf0e10cSrcweir 	sal_Bool bNumericOnly = '0' <= *(pStr+1) && *(pStr+1) <= '9';
1043cdf0e10cSrcweir 
1044cdf0e10cSrcweir 	// suche den Anfang vom Wort
1045cdf0e10cSrcweir 	while( !IsWordDelim( *pStr ))
1046cdf0e10cSrcweir 	{
1047cdf0e10cSrcweir 		if( bNumericOnly &&
1048cdf0e10cSrcweir             rCC.isLetter(
1049cdf0e10cSrcweir                 aText, sal::static_int_cast< xub_StrLen >( pStr - pStart ) ) )
1050cdf0e10cSrcweir 			bNumericOnly = sal_False;
1051cdf0e10cSrcweir 
1052cdf0e10cSrcweir 		if( pStart == pStr )
1053cdf0e10cSrcweir 			break;
1054cdf0e10cSrcweir 
1055cdf0e10cSrcweir 		--pStr;
1056cdf0e10cSrcweir 	}
1057cdf0e10cSrcweir 
1058cdf0e10cSrcweir 	if( bNumericOnly )		// besteht nur aus Zahlen, dann nicht
1059cdf0e10cSrcweir 		return sal_False;
1060cdf0e10cSrcweir 
1061cdf0e10cSrcweir 	if( IsWordDelim( *pStr ))
1062cdf0e10cSrcweir 		++pStr;
1063cdf0e10cSrcweir 
1064cdf0e10cSrcweir 	String sWord;
1065cdf0e10cSrcweir 
1066cdf0e10cSrcweir 	// ueberpruefe anhand der Exceptionliste
1067cdf0e10cSrcweir 	if( pExceptStt )
1068cdf0e10cSrcweir 	{
1069cdf0e10cSrcweir 		sWord = String(
1070cdf0e10cSrcweir             pStr, sal::static_int_cast< xub_StrLen >( pExceptStt - pStr + 1 ) );
1071cdf0e10cSrcweir 		if( FindInCplSttExceptList(eLang, sWord) )
1072cdf0e10cSrcweir 			return sal_False;
1073cdf0e10cSrcweir 
1074cdf0e10cSrcweir 		// loesche alle nicht alpanum. Zeichen am Wortanfang/-ende und
1075cdf0e10cSrcweir 		// teste dann noch mal ( erkennt: "(min.", "/min.", usw.)
1076cdf0e10cSrcweir 		String sTmp( sWord );
1077cdf0e10cSrcweir 		while( sTmp.Len() &&
1078cdf0e10cSrcweir 				!rCC.isLetterNumeric( sTmp, 0 ) )
1079cdf0e10cSrcweir 			sTmp.Erase( 0, 1 );
1080cdf0e10cSrcweir 
1081cdf0e10cSrcweir 		// alle hinteren nicht alphanumerische Zeichen bis auf das
1082cdf0e10cSrcweir 		// Letzte entfernen
1083cdf0e10cSrcweir 		xub_StrLen nLen = sTmp.Len();
1084cdf0e10cSrcweir 		while( nLen && !rCC.isLetterNumeric( sTmp, nLen-1 ) )
1085cdf0e10cSrcweir 			--nLen;
1086cdf0e10cSrcweir 		if( nLen + 1 < sTmp.Len() )
1087cdf0e10cSrcweir 			sTmp.Erase( nLen + 1 );
1088cdf0e10cSrcweir 
1089cdf0e10cSrcweir 		if( sTmp.Len() && sTmp.Len() != sWord.Len() &&
1090cdf0e10cSrcweir 			FindInCplSttExceptList(eLang, sTmp))
1091cdf0e10cSrcweir 			return sal_False;
1092cdf0e10cSrcweir 
1093cdf0e10cSrcweir 		if(FindInCplSttExceptList(eLang, sWord, sal_True))
1094cdf0e10cSrcweir 			return sal_False;
1095cdf0e10cSrcweir 	}
1096cdf0e10cSrcweir 
1097cdf0e10cSrcweir 	// Ok, dann ersetze mal
1098cdf0e10cSrcweir 	sal_Unicode cSave = *pWordStt;
1099cdf0e10cSrcweir 	nSttPos = sal::static_int_cast< xub_StrLen >( pWordStt - rTxt.GetBuffer() );
1100cdf0e10cSrcweir 	String sChar( cSave );
1101cdf0e10cSrcweir 	rCC.toUpper( sChar );
1102cdf0e10cSrcweir     sal_Bool bRet = sChar.GetChar(0) != cSave && rDoc.ReplaceRange( nSttPos, 1, sChar );
1103cdf0e10cSrcweir 
1104cdf0e10cSrcweir 	// das Wort will vielleicht jemand haben
1105cdf0e10cSrcweir 	if( bRet && SaveWordCplSttLst & nFlags )
1106cdf0e10cSrcweir 		rDoc.SaveCpltSttWord( CptlSttSntnc, nSttPos, sWord, cSave );
1107cdf0e10cSrcweir 
1108cdf0e10cSrcweir 	return bRet;
1109cdf0e10cSrcweir }
1110cdf0e10cSrcweir //The method below is renamed from _GetQuote to GetQuote by BerryJia for Bug95846 Time:2002-8-13 15:50
GetQuote(sal_Unicode cInsChar,sal_Bool bSttQuote,LanguageType eLang) const1111cdf0e10cSrcweir sal_Unicode SvxAutoCorrect::GetQuote( sal_Unicode cInsChar, sal_Bool bSttQuote,
1112cdf0e10cSrcweir 										LanguageType eLang ) const
1113cdf0e10cSrcweir {
1114cdf0e10cSrcweir 	sal_Unicode cRet = bSttQuote ? ( '\"' == cInsChar
1115cdf0e10cSrcweir 									? GetStartDoubleQuote()
1116cdf0e10cSrcweir 									: GetStartSingleQuote() )
1117cdf0e10cSrcweir 						  		 : ( '\"' == cInsChar
1118cdf0e10cSrcweir 									? GetEndDoubleQuote()
1119cdf0e10cSrcweir 									: GetEndSingleQuote() );
1120cdf0e10cSrcweir 	if( !cRet )
1121cdf0e10cSrcweir 	{
1122cdf0e10cSrcweir 		// dann ueber die Language das richtige Zeichen heraussuchen
1123cdf0e10cSrcweir 		if( LANGUAGE_NONE == eLang )
1124cdf0e10cSrcweir 			cRet = cInsChar;
1125cdf0e10cSrcweir 		else
1126cdf0e10cSrcweir 		{
1127cdf0e10cSrcweir 			LocaleDataWrapper& rLcl = GetLocaleDataWrapper( eLang );
1128cdf0e10cSrcweir 			String sRet( bSttQuote
1129cdf0e10cSrcweir 							? ( '\"' == cInsChar
1130cdf0e10cSrcweir 								? rLcl.getDoubleQuotationMarkStart()
1131cdf0e10cSrcweir 								: rLcl.getQuotationMarkStart() )
1132cdf0e10cSrcweir 							: ( '\"' == cInsChar
1133cdf0e10cSrcweir 								? rLcl.getDoubleQuotationMarkEnd()
1134cdf0e10cSrcweir 								: rLcl.getQuotationMarkEnd() ));
1135cdf0e10cSrcweir 			cRet = sRet.Len() ? sRet.GetChar( 0 ) : cInsChar;
1136cdf0e10cSrcweir 		}
1137cdf0e10cSrcweir 	}
1138cdf0e10cSrcweir 	return cRet;
1139cdf0e10cSrcweir }
1140cdf0e10cSrcweir 
InsertQuote(SvxAutoCorrDoc & rDoc,xub_StrLen nInsPos,sal_Unicode cInsChar,sal_Bool bSttQuote,sal_Bool bIns)1141cdf0e10cSrcweir void SvxAutoCorrect::InsertQuote( SvxAutoCorrDoc& rDoc, xub_StrLen nInsPos,
1142cdf0e10cSrcweir 									sal_Unicode cInsChar, sal_Bool bSttQuote,
1143cdf0e10cSrcweir 									sal_Bool bIns )
1144cdf0e10cSrcweir {
1145cdf0e10cSrcweir 	LanguageType eLang = rDoc.GetLanguage( nInsPos, sal_False );
1146cdf0e10cSrcweir 	sal_Unicode cRet = GetQuote( cInsChar, bSttQuote, eLang );
1147cdf0e10cSrcweir 
1148cdf0e10cSrcweir 	//JP 13.02.99: damit beim Undo das "einfuegte" Zeichen wieder erscheint,
1149cdf0e10cSrcweir 	//				wird es erstmal eingefuegt und dann ueberschrieben
1150cdf0e10cSrcweir 	String sChg( cInsChar );
1151cdf0e10cSrcweir 	if( bIns )
1152cdf0e10cSrcweir 		rDoc.Insert( nInsPos, sChg );
1153cdf0e10cSrcweir 	else
1154cdf0e10cSrcweir 		rDoc.Replace( nInsPos, sChg );
1155cdf0e10cSrcweir 
1156cdf0e10cSrcweir 	//JP 13.08.97: Bug 42477 - bei doppelten Anfuehrungszeichen muss bei
1157cdf0e10cSrcweir 	//				franzoesischer Sprache an Anfang ein Leerzeichen dahinter
1158cdf0e10cSrcweir 	//				und am Ende ein Leerzeichen dahinter eingefuegt werden.
1159cdf0e10cSrcweir 	sChg = cRet;
1160cdf0e10cSrcweir 
1161cdf0e10cSrcweir 	if( '\"' == cInsChar )
1162cdf0e10cSrcweir 	{
1163cdf0e10cSrcweir 		if( LANGUAGE_SYSTEM == eLang )
1164cdf0e10cSrcweir 			eLang = GetAppLang();
1165cdf0e10cSrcweir 		switch( eLang )
1166cdf0e10cSrcweir 		{
1167cdf0e10cSrcweir 		case LANGUAGE_FRENCH:
1168cdf0e10cSrcweir 		case LANGUAGE_FRENCH_BELGIAN:
1169cdf0e10cSrcweir 		case LANGUAGE_FRENCH_CANADIAN:
1170cdf0e10cSrcweir 		case LANGUAGE_FRENCH_SWISS:
1171cdf0e10cSrcweir 		case LANGUAGE_FRENCH_LUXEMBOURG:
1172cdf0e10cSrcweir 			// JP 09.02.99: das zusaetzliche Zeichen immer per Insert einfuegen.
1173cdf0e10cSrcweir 			//				Es ueberschreibt nichts!
1174cdf0e10cSrcweir 			{
1175cdf0e10cSrcweir 				String s( static_cast< sal_Unicode >(0xA0) );
1176cdf0e10cSrcweir                     // UNICODE code for no break space
1177cdf0e10cSrcweir 				if( rDoc.Insert( bSttQuote ? nInsPos+1 : nInsPos, s ))
1178cdf0e10cSrcweir 				{
1179cdf0e10cSrcweir 					if( !bSttQuote )
1180cdf0e10cSrcweir 						++nInsPos;
1181cdf0e10cSrcweir 				}
1182cdf0e10cSrcweir 			}
1183cdf0e10cSrcweir 			break;
1184cdf0e10cSrcweir 		}
1185cdf0e10cSrcweir 	}
1186cdf0e10cSrcweir 
1187cdf0e10cSrcweir 	rDoc.Replace( nInsPos, sChg );
1188cdf0e10cSrcweir }
1189cdf0e10cSrcweir 
GetQuote(SvxAutoCorrDoc & rDoc,xub_StrLen nInsPos,sal_Unicode cInsChar,sal_Bool bSttQuote)1190cdf0e10cSrcweir String SvxAutoCorrect::GetQuote( SvxAutoCorrDoc& rDoc, xub_StrLen nInsPos,
1191cdf0e10cSrcweir 								sal_Unicode cInsChar, sal_Bool bSttQuote )
1192cdf0e10cSrcweir {
1193cdf0e10cSrcweir 	LanguageType eLang = rDoc.GetLanguage( nInsPos, sal_False );
1194cdf0e10cSrcweir 	sal_Unicode cRet = GetQuote( cInsChar, bSttQuote, eLang );
1195cdf0e10cSrcweir 
1196cdf0e10cSrcweir 	String sRet( cRet );
1197cdf0e10cSrcweir 	//JP 13.08.97: Bug 42477 - bei doppelten Anfuehrungszeichen muss bei
1198cdf0e10cSrcweir 	//				franzoesischer Sprache an Anfang ein Leerzeichen dahinter
1199cdf0e10cSrcweir 	//				und am Ende ein Leerzeichen dahinter eingefuegt werden.
1200cdf0e10cSrcweir 	if( '\"' == cInsChar )
1201cdf0e10cSrcweir 	{
1202cdf0e10cSrcweir 		if( LANGUAGE_SYSTEM == eLang )
1203cdf0e10cSrcweir 			eLang = GetAppLang();
1204cdf0e10cSrcweir 		switch( eLang )
1205cdf0e10cSrcweir 		{
1206cdf0e10cSrcweir 		case LANGUAGE_FRENCH:
1207cdf0e10cSrcweir 		case LANGUAGE_FRENCH_BELGIAN:
1208cdf0e10cSrcweir 		case LANGUAGE_FRENCH_CANADIAN:
1209cdf0e10cSrcweir 		case LANGUAGE_FRENCH_SWISS:
1210cdf0e10cSrcweir 		case LANGUAGE_FRENCH_LUXEMBOURG:
1211cdf0e10cSrcweir 			if( bSttQuote )
1212cdf0e10cSrcweir 				sRet += ' ';
1213cdf0e10cSrcweir 			else
1214cdf0e10cSrcweir 				sRet.Insert( ' ', 0 );
1215cdf0e10cSrcweir 			break;
1216cdf0e10cSrcweir 		}
1217cdf0e10cSrcweir 	}
1218cdf0e10cSrcweir 	return sRet;
1219cdf0e10cSrcweir }
1220cdf0e10cSrcweir 
AutoCorrect(SvxAutoCorrDoc & rDoc,const String & rTxt,xub_StrLen nInsPos,sal_Unicode cChar,sal_Bool bInsert)1221cdf0e10cSrcweir sal_uLong SvxAutoCorrect::AutoCorrect( SvxAutoCorrDoc& rDoc, const String& rTxt,
1222cdf0e10cSrcweir 									xub_StrLen nInsPos, sal_Unicode cChar,
1223cdf0e10cSrcweir 									sal_Bool bInsert )
1224cdf0e10cSrcweir {
1225cdf0e10cSrcweir 	sal_uLong nRet = 0;
1226cdf0e10cSrcweir     bool bIsNextRun = bRunNext;
1227cdf0e10cSrcweir     bRunNext = false;  // if it was set, then it has to be turned off
1228cdf0e10cSrcweir 
1229cdf0e10cSrcweir 	do{		                            // only for middle check loop !!
1230cdf0e10cSrcweir 		if( cChar )
1231cdf0e10cSrcweir 		{
1232cdf0e10cSrcweir 			//JP 10.02.97: doppelte Spaces verhindern
1233cdf0e10cSrcweir 			if( nInsPos && ' ' == cChar &&
1234cdf0e10cSrcweir 				IsAutoCorrFlag( IgnoreDoubleSpace ) &&
1235cdf0e10cSrcweir 				' ' == rTxt.GetChar( nInsPos - 1 ) )
1236cdf0e10cSrcweir 			{
1237cdf0e10cSrcweir 				nRet = IgnoreDoubleSpace;
1238cdf0e10cSrcweir 				break;
1239cdf0e10cSrcweir 			}
1240cdf0e10cSrcweir 
1241cdf0e10cSrcweir 			sal_Bool bSingle = '\'' == cChar;
1242cdf0e10cSrcweir 			sal_Bool bIsReplaceQuote =
1243cdf0e10cSrcweir 						(IsAutoCorrFlag( ChgQuotes ) && ('\"' == cChar )) ||
1244cdf0e10cSrcweir 						(IsAutoCorrFlag( ChgSglQuotes ) && bSingle );
1245cdf0e10cSrcweir 			if( bIsReplaceQuote )
1246cdf0e10cSrcweir 			{
1247cdf0e10cSrcweir 				sal_Unicode cPrev;
1248cdf0e10cSrcweir 				sal_Bool bSttQuote = !nInsPos ||
1249cdf0e10cSrcweir 						IsWordDelim( ( cPrev = rTxt.GetChar( nInsPos-1 ))) ||
1250cdf0e10cSrcweir // os: #56034# - Warum kein schliessendes Anfuehrungszeichen nach dem Bindestrich?
1251cdf0e10cSrcweir //						strchr( "-([{", cPrev ) ||
1252cdf0e10cSrcweir 						lcl_IsInAsciiArr( "([{", cPrev ) ||
1253cdf0e10cSrcweir 						( cEmDash && cEmDash == cPrev ) ||
1254cdf0e10cSrcweir 						( cEnDash && cEnDash == cPrev );
1255cdf0e10cSrcweir 
1256cdf0e10cSrcweir 				InsertQuote( rDoc, nInsPos, cChar, bSttQuote, bInsert );
1257cdf0e10cSrcweir 				nRet = bSingle ? ChgSglQuotes : ChgQuotes;
1258cdf0e10cSrcweir 				break;
1259cdf0e10cSrcweir 			}
1260cdf0e10cSrcweir 
1261cdf0e10cSrcweir 			if( bInsert )
1262cdf0e10cSrcweir 				rDoc.Insert( nInsPos, cChar );
1263cdf0e10cSrcweir 			else
1264cdf0e10cSrcweir 				rDoc.Replace( nInsPos, cChar );
1265cdf0e10cSrcweir 
1266cdf0e10cSrcweir             // Hardspaces autocorrection
1267cdf0e10cSrcweir             if ( IsAutoCorrFlag( AddNonBrkSpace ) )
1268cdf0e10cSrcweir             {
1269cdf0e10cSrcweir                 if ( NeedsHardspaceAutocorr( cChar ) &&
1270cdf0e10cSrcweir                     FnAddNonBrkSpace( rDoc, rTxt, 0, nInsPos, rDoc.GetLanguage( nInsPos, sal_False ) ) )
1271cdf0e10cSrcweir                 {
1272cdf0e10cSrcweir                     nRet = AddNonBrkSpace;
1273cdf0e10cSrcweir                 }
1274cdf0e10cSrcweir                 else if ( bIsNextRun && !IsAutoCorrectChar( cChar ) )
1275cdf0e10cSrcweir                 {
1276cdf0e10cSrcweir                     // Remove the NBSP if it wasn't an autocorrection
1277cdf0e10cSrcweir                     if ( nInsPos != 0 && NeedsHardspaceAutocorr( rTxt.GetChar( nInsPos - 1 ) ) &&
1278cdf0e10cSrcweir                             cChar != ' ' && cChar != '\t' && cChar != CHAR_HARDBLANK )
1279cdf0e10cSrcweir                     {
1280cdf0e10cSrcweir                         // Look for the last HARD_SPACE
1281cdf0e10cSrcweir                         xub_StrLen nPos = nInsPos - 1;
1282cdf0e10cSrcweir                         bool bContinue = true;
1283cdf0e10cSrcweir                         while ( bContinue )
1284cdf0e10cSrcweir                         {
1285cdf0e10cSrcweir                             const sal_Unicode cTmpChar = rTxt.GetChar( nPos );
1286cdf0e10cSrcweir                             if ( cTmpChar == CHAR_HARDBLANK )
1287cdf0e10cSrcweir                             {
1288cdf0e10cSrcweir                                 rDoc.Delete( nPos, nPos + 1 );
1289cdf0e10cSrcweir                                 nRet = AddNonBrkSpace;
1290cdf0e10cSrcweir                                 bContinue = false;
1291cdf0e10cSrcweir                             }
1292cdf0e10cSrcweir                             else if ( !NeedsHardspaceAutocorr( cTmpChar ) || nPos == 0 )
1293cdf0e10cSrcweir                                 bContinue = false;
1294cdf0e10cSrcweir                             nPos--;
1295cdf0e10cSrcweir                         }
1296cdf0e10cSrcweir                     }
1297cdf0e10cSrcweir                 }
1298cdf0e10cSrcweir             }
1299cdf0e10cSrcweir 		}
1300cdf0e10cSrcweir 
1301cdf0e10cSrcweir 		if( !nInsPos )
1302cdf0e10cSrcweir 			break;
1303cdf0e10cSrcweir 
1304cdf0e10cSrcweir 		xub_StrLen nPos = nInsPos - 1;
1305cdf0e10cSrcweir 
1306cdf0e10cSrcweir 		// Bug 19286: nur direkt hinter dem "Wort" aufsetzen
1307cdf0e10cSrcweir 		if( IsWordDelim( rTxt.GetChar( nPos )))
1308cdf0e10cSrcweir 			break;
1309cdf0e10cSrcweir 
1310cdf0e10cSrcweir 		// automatisches Fett oder Unterstreichen setzen?
1311cdf0e10cSrcweir 		if( '*' == cChar || '_' == cChar )
1312cdf0e10cSrcweir 		{
1313cdf0e10cSrcweir 			if( IsAutoCorrFlag( ChgWeightUnderl ) &&
1314cdf0e10cSrcweir 				FnChgWeightUnderl( rDoc, rTxt, 0, nPos+1 ) )
1315cdf0e10cSrcweir 				nRet = ChgWeightUnderl;
1316cdf0e10cSrcweir 			break;
1317cdf0e10cSrcweir 		}
1318cdf0e10cSrcweir 
1319cdf0e10cSrcweir 		while( nPos && !IsWordDelim( rTxt.GetChar( --nPos )))
1320cdf0e10cSrcweir 			;
1321cdf0e10cSrcweir 
1322cdf0e10cSrcweir 		// Absatz-Anfang oder ein Blank gefunden, suche nach dem Wort
1323cdf0e10cSrcweir 		// Kuerzel im Auto
1324cdf0e10cSrcweir 		xub_StrLen nCapLttrPos = nPos+1;		// auf das 1. Zeichen
1325cdf0e10cSrcweir 		if( !nPos && !IsWordDelim( rTxt.GetChar( 0 )))
1326cdf0e10cSrcweir 			--nCapLttrPos;			// Absatz Anfang und kein Blank !
1327cdf0e10cSrcweir 
1328cdf0e10cSrcweir 		LanguageType eLang = rDoc.GetLanguage( nCapLttrPos, sal_False );
1329cdf0e10cSrcweir 		if( LANGUAGE_SYSTEM == eLang )
1330cdf0e10cSrcweir 			eLang = MsLangId::getSystemLanguage();
1331cdf0e10cSrcweir 		CharClass& rCC = GetCharClass( eLang );
1332cdf0e10cSrcweir 
1333cdf0e10cSrcweir 		// no symbol characters
1334cdf0e10cSrcweir 		if( lcl_IsSymbolChar( rCC, rTxt, nCapLttrPos, nInsPos ))
1335cdf0e10cSrcweir 			break;
1336cdf0e10cSrcweir 
1337cdf0e10cSrcweir 		if( IsAutoCorrFlag( Autocorrect ) )
1338cdf0e10cSrcweir 		{
1339cdf0e10cSrcweir 			const String* pPara = 0;
1340cdf0e10cSrcweir 			const String** ppPara = IsAutoCorrFlag(CptlSttSntnc) ? &pPara : 0;
1341cdf0e10cSrcweir 
1342cdf0e10cSrcweir 			sal_Bool bChgWord = rDoc.ChgAutoCorrWord( nCapLttrPos, nInsPos,
1343cdf0e10cSrcweir 													*this, ppPara );
1344cdf0e10cSrcweir 			if( !bChgWord )
1345cdf0e10cSrcweir 			{
1346cdf0e10cSrcweir 				// JP 16.06.98: dann versuche mal alle !AlphaNum. Zeichen los zu
1347cdf0e10cSrcweir 				//				werden und teste dann nochmals
1348cdf0e10cSrcweir 				//JP 22.04.99: Bug 63883 - entferne nur die "Klammern Start/-Anfaenge",
1349cdf0e10cSrcweir 				//				alle anderen Zeichen muessen drin bleiben.
1350cdf0e10cSrcweir 				xub_StrLen nCapLttrPos1 = nCapLttrPos, nInsPos1 = nInsPos;
1351cdf0e10cSrcweir 				while( nCapLttrPos1 < nInsPos &&
1352cdf0e10cSrcweir 						lcl_IsInAsciiArr( sImplSttSkipChars, rTxt.GetChar( nCapLttrPos1 ) )
1353cdf0e10cSrcweir 						)
1354cdf0e10cSrcweir 						++nCapLttrPos1;
1355cdf0e10cSrcweir 				while( nCapLttrPos1 < nInsPos1 && nInsPos1 &&
1356cdf0e10cSrcweir 						lcl_IsInAsciiArr( sImplEndSkipChars, rTxt.GetChar( nInsPos1-1 ) )
1357cdf0e10cSrcweir 						)
1358cdf0e10cSrcweir 						--nInsPos1;
1359cdf0e10cSrcweir 
1360cdf0e10cSrcweir 				if( (nCapLttrPos1 != nCapLttrPos || nInsPos1 != nInsPos ) &&
1361cdf0e10cSrcweir 					nCapLttrPos1 < nInsPos1 &&
1362cdf0e10cSrcweir 					rDoc.ChgAutoCorrWord( nCapLttrPos1, nInsPos1, *this, ppPara ))
1363cdf0e10cSrcweir 				{
1364cdf0e10cSrcweir 					bChgWord = sal_True;
1365cdf0e10cSrcweir 					nCapLttrPos = nCapLttrPos1;
1366cdf0e10cSrcweir 				}
1367cdf0e10cSrcweir 			}
1368cdf0e10cSrcweir 
1369cdf0e10cSrcweir 			if( bChgWord )
1370cdf0e10cSrcweir 			{
1371cdf0e10cSrcweir 				nRet = Autocorrect;
1372cdf0e10cSrcweir 				if( pPara )
1373cdf0e10cSrcweir 				{
1374cdf0e10cSrcweir 					xub_StrLen nEnd = nCapLttrPos;
1375cdf0e10cSrcweir 					while( nEnd < pPara->Len() &&
1376cdf0e10cSrcweir 							!IsWordDelim( pPara->GetChar( nEnd )))
1377cdf0e10cSrcweir 						++nEnd;
1378cdf0e10cSrcweir 
1379cdf0e10cSrcweir 					// Grossbuchstabe am Satz-Anfang ??
1380cdf0e10cSrcweir 					if( IsAutoCorrFlag( CptlSttSntnc ) &&
1381cdf0e10cSrcweir 						FnCptlSttSntnc( rDoc, *pPara, sal_False,
1382cdf0e10cSrcweir 												nCapLttrPos, nEnd, eLang ) )
1383cdf0e10cSrcweir 						nRet |= CptlSttSntnc;
1384cdf0e10cSrcweir 
1385cdf0e10cSrcweir 					if( IsAutoCorrFlag( ChgToEnEmDash ) &&
1386cdf0e10cSrcweir 						FnChgToEnEmDash( rDoc, rTxt, nCapLttrPos, nEnd, eLang ) )
1387cdf0e10cSrcweir 						nRet |= ChgToEnEmDash;
1388cdf0e10cSrcweir 				}
1389cdf0e10cSrcweir 				break;
1390cdf0e10cSrcweir 			}
1391cdf0e10cSrcweir 		}
1392cdf0e10cSrcweir 
1393cdf0e10cSrcweir 		if( ( IsAutoCorrFlag( nRet = ChgOrdinalNumber ) &&
1394cdf0e10cSrcweir 				FnChgOrdinalNumber( rDoc, rTxt, nCapLttrPos, nInsPos, eLang ) ) ||
1395cdf0e10cSrcweir 			( IsAutoCorrFlag( nRet = SetINetAttr ) &&
1396cdf0e10cSrcweir 				( ' ' == cChar || '\t' == cChar || 0x0a == cChar || !cChar ) &&
1397cdf0e10cSrcweir 				FnSetINetAttr( rDoc, rTxt, nCapLttrPos, nInsPos, eLang ) ) )
1398cdf0e10cSrcweir 			;
1399cdf0e10cSrcweir 		else
1400cdf0e10cSrcweir 		{
1401cdf0e10cSrcweir 			nRet = 0;
1402cdf0e10cSrcweir 			bool bUnsupported = lcl_IsUnsupportedUnicodeChar( rCC, rTxt, nCapLttrPos, nInsPos );
1403cdf0e10cSrcweir             // Grossbuchstabe am Satz-Anfang ??
1404cdf0e10cSrcweir 			if( !bUnsupported &&
1405cdf0e10cSrcweir                 IsAutoCorrFlag( CptlSttSntnc ) &&
1406cdf0e10cSrcweir                 FnCptlSttSntnc( rDoc, rTxt, sal_True, nCapLttrPos, nInsPos, eLang ) )
1407cdf0e10cSrcweir 				nRet |= CptlSttSntnc;
1408cdf0e10cSrcweir 
1409cdf0e10cSrcweir 			// Zwei Grossbuchstaben am Wort-Anfang ??
1410cdf0e10cSrcweir 			if( !bUnsupported &&
1411cdf0e10cSrcweir                 IsAutoCorrFlag( CptlSttWrd ) &&
1412cdf0e10cSrcweir 				FnCptlSttWrd( rDoc, rTxt, nCapLttrPos, nInsPos, eLang ) )
1413cdf0e10cSrcweir 				nRet |= CptlSttWrd;
1414cdf0e10cSrcweir 
1415cdf0e10cSrcweir 			if( IsAutoCorrFlag( ChgToEnEmDash ) &&
1416cdf0e10cSrcweir 				FnChgToEnEmDash( rDoc, rTxt, nCapLttrPos, nInsPos, eLang ) )
1417cdf0e10cSrcweir 				nRet |= ChgToEnEmDash;
1418cdf0e10cSrcweir 		}
1419cdf0e10cSrcweir 
1420cdf0e10cSrcweir 	} while( sal_False );
1421cdf0e10cSrcweir 
1422cdf0e10cSrcweir 	if( nRet )
1423cdf0e10cSrcweir 	{
1424cdf0e10cSrcweir         const char* aHelpIds[] =
1425cdf0e10cSrcweir         {
1426cdf0e10cSrcweir             HID_AUTOCORR_HELP_WORD,
1427cdf0e10cSrcweir             HID_AUTOCORR_HELP_SENT,
1428cdf0e10cSrcweir             HID_AUTOCORR_HELP_SENTWORD,
1429cdf0e10cSrcweir             HID_AUTOCORR_HELP_ACORWORD,
1430cdf0e10cSrcweir             "",
1431cdf0e10cSrcweir             HID_AUTOCORR_HELP_ACORSENTWORD,
1432cdf0e10cSrcweir             "",
1433cdf0e10cSrcweir             HID_AUTOCORR_HELP_CHGTOENEMDASH,
1434cdf0e10cSrcweir             HID_AUTOCORR_HELP_WORDENEMDASH,
1435cdf0e10cSrcweir             HID_AUTOCORR_HELP_SENTENEMDASH,
1436cdf0e10cSrcweir             HID_AUTOCORR_HELP_SENTWORDENEMDASH,
1437cdf0e10cSrcweir             HID_AUTOCORR_HELP_ACORWORDENEMDASH,
1438cdf0e10cSrcweir             "",
1439cdf0e10cSrcweir             HID_AUTOCORR_HELP_ACORSENTWORDENEMDASH,
1440cdf0e10cSrcweir             "",
1441cdf0e10cSrcweir             HID_AUTOCORR_HELP_CHGQUOTES,
1442cdf0e10cSrcweir             HID_AUTOCORR_HELP_CHGSGLQUOTES,
1443cdf0e10cSrcweir             HID_AUTOCORR_HELP_SETINETATTR,
1444cdf0e10cSrcweir             HID_AUTOCORR_HELP_INGNOREDOUBLESPACE,
1445cdf0e10cSrcweir             HID_AUTOCORR_HELP_CHGWEIGHTUNDERL,
1446cdf0e10cSrcweir             HID_AUTOCORR_HELP_CHGFRACTIONSYMBOL,
1447cdf0e10cSrcweir             HID_AUTOCORR_HELP_CHGORDINALNUMBER
1448cdf0e10cSrcweir         };
1449cdf0e10cSrcweir 
1450cdf0e10cSrcweir 		sal_uLong nHelpId = 0;
1451cdf0e10cSrcweir 		if( nRet & ( Autocorrect|CptlSttSntnc|CptlSttWrd|ChgToEnEmDash ) )
1452cdf0e10cSrcweir 		{
1453cdf0e10cSrcweir 			// von 0 - 15
1454cdf0e10cSrcweir 			if( nRet & ChgToEnEmDash )
1455cdf0e10cSrcweir 				nHelpId += 8;
1456cdf0e10cSrcweir 			if( nRet & Autocorrect )
1457cdf0e10cSrcweir 				nHelpId += 4;
1458cdf0e10cSrcweir 			if( nRet & CptlSttSntnc )
1459cdf0e10cSrcweir 				nHelpId += 2;
1460cdf0e10cSrcweir 			if( nRet & CptlSttWrd )
1461cdf0e10cSrcweir 				nHelpId += 1;
1462cdf0e10cSrcweir 		}
1463cdf0e10cSrcweir 		else
1464cdf0e10cSrcweir 		{
1465cdf0e10cSrcweir 			     if( nRet & ChgQuotes) 			nHelpId = 16;
1466cdf0e10cSrcweir 			else if( nRet & ChgSglQuotes) 		nHelpId = 17;
1467cdf0e10cSrcweir 			else if( nRet & SetINetAttr) 		nHelpId = 18;
1468cdf0e10cSrcweir 			else if( nRet & IgnoreDoubleSpace)  nHelpId = 19;
1469cdf0e10cSrcweir 			else if( nRet & ChgWeightUnderl) 	nHelpId = 20;
1470cdf0e10cSrcweir             else if( nRet & AddNonBrkSpace)     nHelpId = 21;
1471cdf0e10cSrcweir 			else if( nRet & ChgOrdinalNumber)	nHelpId = 22;
1472cdf0e10cSrcweir 		}
1473cdf0e10cSrcweir 
1474cdf0e10cSrcweir 		if( nHelpId )
1475cdf0e10cSrcweir 		{
1476cdf0e10cSrcweir 			nHelpId -= 1;
1477cdf0e10cSrcweir 			Application::GetHelp()->OpenHelpAgent( aHelpIds[nHelpId] );
1478cdf0e10cSrcweir 		}
1479cdf0e10cSrcweir 	}
1480cdf0e10cSrcweir 
1481cdf0e10cSrcweir 
1482cdf0e10cSrcweir 	return nRet;
1483cdf0e10cSrcweir }
1484cdf0e10cSrcweir 
_GetLanguageList(LanguageType eLang)1485cdf0e10cSrcweir SvxAutoCorrectLanguageLists& SvxAutoCorrect::_GetLanguageList(
1486cdf0e10cSrcweir 														LanguageType eLang )
1487cdf0e10cSrcweir {
1488cdf0e10cSrcweir 	if( !pLangTable->IsKeyValid( sal_uLong( eLang )))
1489cdf0e10cSrcweir 		CreateLanguageFile( eLang, sal_True);
1490cdf0e10cSrcweir 	return *pLangTable->Seek( sal_uLong( eLang ) );
1491cdf0e10cSrcweir }
1492cdf0e10cSrcweir 
SaveCplSttExceptList(LanguageType eLang)1493cdf0e10cSrcweir void SvxAutoCorrect::SaveCplSttExceptList( LanguageType eLang )
1494cdf0e10cSrcweir {
1495cdf0e10cSrcweir 	if( pLangTable->IsKeyValid( sal_uLong( eLang )))
1496cdf0e10cSrcweir 	{
1497cdf0e10cSrcweir 		SvxAutoCorrectLanguageListsPtr pLists = pLangTable->Seek(sal_uLong(eLang));
1498cdf0e10cSrcweir 		if( pLists )
1499cdf0e10cSrcweir 			pLists->SaveCplSttExceptList();
1500cdf0e10cSrcweir 	}
1501cdf0e10cSrcweir #ifdef DBG_UTIL
1502cdf0e10cSrcweir 	else
1503cdf0e10cSrcweir 	{
1504cdf0e10cSrcweir 		DBG_ERROR("speichern einer leeren Liste?");
1505cdf0e10cSrcweir 	}
1506cdf0e10cSrcweir #endif
1507cdf0e10cSrcweir }
1508cdf0e10cSrcweir 
SaveWrdSttExceptList(LanguageType eLang)1509cdf0e10cSrcweir void SvxAutoCorrect::SaveWrdSttExceptList(LanguageType eLang)
1510cdf0e10cSrcweir {
1511cdf0e10cSrcweir 	if(pLangTable->IsKeyValid(sal_uLong(eLang)))
1512cdf0e10cSrcweir 	{
1513cdf0e10cSrcweir 		SvxAutoCorrectLanguageListsPtr pLists = pLangTable->Seek(sal_uLong(eLang));
1514cdf0e10cSrcweir 		if(pLists)
1515cdf0e10cSrcweir 			pLists->SaveWrdSttExceptList();
1516cdf0e10cSrcweir 	}
1517cdf0e10cSrcweir #ifdef DBG_UTIL
1518cdf0e10cSrcweir 	else
1519cdf0e10cSrcweir 	{
1520cdf0e10cSrcweir 		DBG_ERROR("speichern einer leeren Liste?");
1521cdf0e10cSrcweir 	}
1522cdf0e10cSrcweir #endif
1523cdf0e10cSrcweir }
1524cdf0e10cSrcweir 
1525cdf0e10cSrcweir 
1526cdf0e10cSrcweir 	// fuegt ein einzelnes Wort hinzu. Die Liste wird sofort
1527cdf0e10cSrcweir 	// in die Datei geschrieben!
AddCplSttException(const String & rNew,LanguageType eLang)1528cdf0e10cSrcweir sal_Bool SvxAutoCorrect::AddCplSttException( const String& rNew,
1529cdf0e10cSrcweir 										LanguageType eLang )
1530cdf0e10cSrcweir {
1531cdf0e10cSrcweir 	SvxAutoCorrectLanguageListsPtr pLists = 0;
1532cdf0e10cSrcweir 	//entweder die richtige Sprache ist vorhanden oder es kommt in die allg. Liste
1533cdf0e10cSrcweir 	if( pLangTable->IsKeyValid(sal_uLong(eLang)))
1534cdf0e10cSrcweir 		pLists = pLangTable->Seek(sal_uLong(eLang));
1535cdf0e10cSrcweir 	else if(pLangTable->IsKeyValid(sal_uLong(LANGUAGE_DONTKNOW))||
1536cdf0e10cSrcweir 			CreateLanguageFile(LANGUAGE_DONTKNOW, sal_True))
1537cdf0e10cSrcweir 	{
1538cdf0e10cSrcweir 		pLists = pLangTable->Seek(sal_uLong(LANGUAGE_DONTKNOW));
1539cdf0e10cSrcweir 	}
1540cdf0e10cSrcweir 	DBG_ASSERT(pLists, "keine Autokorrekturdatei");
1541cdf0e10cSrcweir 	return pLists->AddToCplSttExceptList(rNew);
1542cdf0e10cSrcweir }
1543cdf0e10cSrcweir 
1544cdf0e10cSrcweir 
1545cdf0e10cSrcweir 	// fuegt ein einzelnes Wort hinzu. Die Liste wird sofort
1546cdf0e10cSrcweir 	// in die Datei geschrieben!
AddWrtSttException(const String & rNew,LanguageType eLang)1547cdf0e10cSrcweir sal_Bool SvxAutoCorrect::AddWrtSttException( const String& rNew,
1548cdf0e10cSrcweir 										 LanguageType eLang )
1549cdf0e10cSrcweir {
1550cdf0e10cSrcweir 	SvxAutoCorrectLanguageListsPtr pLists = 0;
1551cdf0e10cSrcweir 	//entweder die richtige Sprache ist vorhanden oder es kommt in die allg. Liste
1552cdf0e10cSrcweir 	if(pLangTable->IsKeyValid(sal_uLong(eLang)))
1553cdf0e10cSrcweir 		pLists = pLangTable->Seek(sal_uLong(eLang));
1554cdf0e10cSrcweir 	else if(pLangTable->IsKeyValid(sal_uLong(LANGUAGE_DONTKNOW))||
1555cdf0e10cSrcweir 			CreateLanguageFile(LANGUAGE_DONTKNOW, sal_True))
1556cdf0e10cSrcweir 		pLists = pLangTable->Seek(sal_uLong(LANGUAGE_DONTKNOW));
1557cdf0e10cSrcweir 	DBG_ASSERT(pLists, "keine Autokorrekturdatei");
1558cdf0e10cSrcweir 	return pLists->AddToWrdSttExceptList(rNew);
1559cdf0e10cSrcweir }
1560cdf0e10cSrcweir 
1561cdf0e10cSrcweir 
1562cdf0e10cSrcweir 
1563cdf0e10cSrcweir 
SetUserAutoCorrFileName(const String & rNew)1564cdf0e10cSrcweir void SvxAutoCorrect::SetUserAutoCorrFileName( const String& rNew )
1565cdf0e10cSrcweir {
1566cdf0e10cSrcweir 	if( sUserAutoCorrFile != rNew )
1567cdf0e10cSrcweir 	{
1568cdf0e10cSrcweir 		sUserAutoCorrFile = rNew;
1569cdf0e10cSrcweir 
1570cdf0e10cSrcweir 		// sind die Listen gesetzt sind, so muessen sie jetzt geloescht
1571cdf0e10cSrcweir 		// werden
1572cdf0e10cSrcweir 		lcl_ClearTable(*pLangTable);
1573cdf0e10cSrcweir 		nFlags &= ~(CplSttLstLoad | WrdSttLstLoad | ChgWordLstLoad );
1574cdf0e10cSrcweir 	}
1575cdf0e10cSrcweir }
1576cdf0e10cSrcweir 
SetShareAutoCorrFileName(const String & rNew)1577cdf0e10cSrcweir void SvxAutoCorrect::SetShareAutoCorrFileName( const String& rNew )
1578cdf0e10cSrcweir {
1579cdf0e10cSrcweir 	if( sShareAutoCorrFile != rNew )
1580cdf0e10cSrcweir 	{
1581cdf0e10cSrcweir 		sShareAutoCorrFile = rNew;
1582cdf0e10cSrcweir 
1583cdf0e10cSrcweir 		// sind die Listen gesetzt sind, so muessen sie jetzt geloescht
1584cdf0e10cSrcweir 		// werden
1585cdf0e10cSrcweir 		lcl_ClearTable(*pLangTable);
1586cdf0e10cSrcweir 		nFlags &= ~(CplSttLstLoad | WrdSttLstLoad | ChgWordLstLoad );
1587cdf0e10cSrcweir 	}
1588cdf0e10cSrcweir }
1589cdf0e10cSrcweir 
1590cdf0e10cSrcweir 
GetPrevAutoCorrWord(SvxAutoCorrDoc & rDoc,const String & rTxt,xub_StrLen nPos,String & rWord) const1591cdf0e10cSrcweir sal_Bool SvxAutoCorrect::GetPrevAutoCorrWord( SvxAutoCorrDoc& rDoc,
1592cdf0e10cSrcweir 										const String& rTxt, xub_StrLen nPos,
1593cdf0e10cSrcweir 										String& rWord ) const
1594cdf0e10cSrcweir {
1595cdf0e10cSrcweir 	if( !nPos )
1596cdf0e10cSrcweir 		return sal_False;
1597cdf0e10cSrcweir 
1598cdf0e10cSrcweir 	xub_StrLen nEnde = nPos;
1599cdf0e10cSrcweir 
1600cdf0e10cSrcweir 	// dahinter muss ein Blank oder Tab folgen!
1601cdf0e10cSrcweir 	if( ( nPos < rTxt.Len() &&
1602cdf0e10cSrcweir 		!IsWordDelim( rTxt.GetChar( nPos ))) ||
1603cdf0e10cSrcweir 		IsWordDelim( rTxt.GetChar( --nPos )))
1604cdf0e10cSrcweir 		return sal_False;
1605cdf0e10cSrcweir 
1606cdf0e10cSrcweir 	while( nPos && !IsWordDelim( rTxt.GetChar( --nPos )))
1607cdf0e10cSrcweir 		;
1608cdf0e10cSrcweir 
1609cdf0e10cSrcweir 	// Absatz-Anfang oder ein Blank gefunden, suche nach dem Wort
1610cdf0e10cSrcweir 	// Kuerzel im Auto
1611cdf0e10cSrcweir 	xub_StrLen nCapLttrPos = nPos+1;		// auf das 1. Zeichen
1612cdf0e10cSrcweir 	if( !nPos && !IsWordDelim( rTxt.GetChar( 0 )))
1613cdf0e10cSrcweir 		--nCapLttrPos;			// Absatz Anfang und kein Blank !
1614cdf0e10cSrcweir 
1615cdf0e10cSrcweir 	while( lcl_IsInAsciiArr( sImplSttSkipChars, rTxt.GetChar( nCapLttrPos )) )
1616cdf0e10cSrcweir 		if( ++nCapLttrPos >= nEnde )
1617cdf0e10cSrcweir 			return sal_False;
1618cdf0e10cSrcweir 
1619cdf0e10cSrcweir 	// Bug 19285: Symbolzeichen nicht anfassen
1620cdf0e10cSrcweir 	// Interresant erst ab 3 Zeichen
1621cdf0e10cSrcweir 	if( 3 > nEnde - nCapLttrPos )
1622cdf0e10cSrcweir 		return sal_False;
1623cdf0e10cSrcweir 
1624cdf0e10cSrcweir 	LanguageType eLang = rDoc.GetLanguage( nCapLttrPos, sal_False );
1625cdf0e10cSrcweir 	if( LANGUAGE_SYSTEM == eLang )
1626cdf0e10cSrcweir 		eLang = MsLangId::getSystemLanguage();
1627cdf0e10cSrcweir 
1628cdf0e10cSrcweir 	SvxAutoCorrect* pThis = (SvxAutoCorrect*)this;
1629cdf0e10cSrcweir 	CharClass& rCC = pThis->GetCharClass( eLang );
1630cdf0e10cSrcweir 
1631cdf0e10cSrcweir 	if( lcl_IsSymbolChar( rCC, rTxt, nCapLttrPos, nEnde ))
1632cdf0e10cSrcweir 		return sal_False;
1633cdf0e10cSrcweir 
1634cdf0e10cSrcweir 	rWord = rTxt.Copy( nCapLttrPos, nEnde - nCapLttrPos );
1635cdf0e10cSrcweir 	return sal_True;
1636cdf0e10cSrcweir }
1637cdf0e10cSrcweir 
CreateLanguageFile(LanguageType eLang,sal_Bool bNewFile)1638cdf0e10cSrcweir sal_Bool SvxAutoCorrect::CreateLanguageFile( LanguageType eLang, sal_Bool bNewFile )
1639cdf0e10cSrcweir {
1640cdf0e10cSrcweir 	DBG_ASSERT(!pLangTable->IsKeyValid(sal_uLong(eLang)), "Sprache ist bereits vorhanden");
1641cdf0e10cSrcweir 
1642cdf0e10cSrcweir 	String sUserDirFile( GetAutoCorrFileName( eLang, sal_True, sal_False )),
1643cdf0e10cSrcweir 		   sShareDirFile( sUserDirFile );
1644cdf0e10cSrcweir 	SvxAutoCorrectLanguageListsPtr pLists = 0;
1645cdf0e10cSrcweir 
1646cdf0e10cSrcweir 	Time nMinTime( 0, 2 ), nAktTime, nLastCheckTime;
1647cdf0e10cSrcweir 	sal_uLong nFndPos;
1648cdf0e10cSrcweir 	if( TABLE_ENTRY_NOTFOUND !=
1649cdf0e10cSrcweir 					pLastFileTable->SearchKey( sal_uLong( eLang ), &nFndPos ) &&
1650cdf0e10cSrcweir 		( nLastCheckTime.SetTime( pLastFileTable->GetObject( nFndPos )),
1651cdf0e10cSrcweir 			nLastCheckTime < nAktTime ) &&
1652cdf0e10cSrcweir 		( nAktTime - nLastCheckTime ) < nMinTime )
1653cdf0e10cSrcweir 	{
1654cdf0e10cSrcweir 		// no need to test the file, because the last check is not older then
1655cdf0e10cSrcweir 		// 2 minutes.
1656cdf0e10cSrcweir 		if( bNewFile )
1657cdf0e10cSrcweir 		{
1658cdf0e10cSrcweir 			sShareDirFile = sUserDirFile;
1659cdf0e10cSrcweir 			pLists = new SvxAutoCorrectLanguageLists( *this, sShareDirFile,
1660cdf0e10cSrcweir 														sUserDirFile, eLang );
1661cdf0e10cSrcweir 			pLangTable->Insert( sal_uLong(eLang), pLists );
1662cdf0e10cSrcweir 			pLastFileTable->Remove( sal_uLong( eLang ) );
1663cdf0e10cSrcweir 		}
1664cdf0e10cSrcweir 	}
1665cdf0e10cSrcweir 	else if( ( FStatHelper::IsDocument( sUserDirFile ) ||
1666cdf0e10cSrcweir 		 	   FStatHelper::IsDocument( sShareDirFile =
1667cdf0e10cSrcweir 		  					GetAutoCorrFileName( eLang, sal_False, sal_False ) ) ) ||
1668cdf0e10cSrcweir 		( sShareDirFile = sUserDirFile, bNewFile ))
1669cdf0e10cSrcweir 	{
1670cdf0e10cSrcweir 		pLists = new SvxAutoCorrectLanguageLists( *this, sShareDirFile,
1671cdf0e10cSrcweir 													sUserDirFile, eLang );
1672cdf0e10cSrcweir 		pLangTable->Insert( sal_uLong(eLang), pLists );
1673cdf0e10cSrcweir 		pLastFileTable->Remove( sal_uLong( eLang ) );
1674cdf0e10cSrcweir 	}
1675cdf0e10cSrcweir 	else if( !bNewFile )
1676cdf0e10cSrcweir 	{
1677cdf0e10cSrcweir 		if( !pLastFileTable->Insert( sal_uLong( eLang ), nAktTime.GetTime() ))
1678cdf0e10cSrcweir 			pLastFileTable->Replace( sal_uLong( eLang ), nAktTime.GetTime() );
1679cdf0e10cSrcweir 	}
1680cdf0e10cSrcweir 	return pLists != 0;
1681cdf0e10cSrcweir }
1682cdf0e10cSrcweir 
PutText(const String & rShort,const String & rLong,LanguageType eLang)1683cdf0e10cSrcweir sal_Bool SvxAutoCorrect::PutText( const String& rShort, const String& rLong,
1684cdf0e10cSrcweir 								LanguageType eLang )
1685cdf0e10cSrcweir {
1686cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
1687cdf0e10cSrcweir 	if( pLangTable->IsKeyValid( sal_uLong(eLang)) || CreateLanguageFile(eLang) )
1688cdf0e10cSrcweir 		bRet = pLangTable->Seek( sal_uLong(eLang) )->PutText(rShort, rLong);
1689cdf0e10cSrcweir 	return bRet;
1690cdf0e10cSrcweir }
1691cdf0e10cSrcweir 
1692cdf0e10cSrcweir 
1693cdf0e10cSrcweir 	//	- loesche einen Eintrag
DeleteText(const String & rShort,LanguageType eLang)1694cdf0e10cSrcweir sal_Bool SvxAutoCorrect::DeleteText( const String& rShort, LanguageType eLang )
1695cdf0e10cSrcweir {
1696cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
1697cdf0e10cSrcweir 	if( pLangTable->IsKeyValid( sal_uLong( eLang )) )
1698cdf0e10cSrcweir 		bRet = pLangTable->Seek( sal_uLong( eLang ))->DeleteText( rShort );
1699cdf0e10cSrcweir 	return bRet;
1700cdf0e10cSrcweir }
1701cdf0e10cSrcweir 
1702cdf0e10cSrcweir 
1703cdf0e10cSrcweir 	//	- return den Ersetzungstext (nur fuer SWG-Format, alle anderen
1704cdf0e10cSrcweir 	//		koennen aus der Wortliste herausgeholt werden!)
GetLongText(const com::sun::star::uno::Reference<com::sun::star::embed::XStorage> &,const String &,const String &,String &)1705cdf0e10cSrcweir sal_Bool SvxAutoCorrect::GetLongText( const com::sun::star::uno::Reference < com::sun::star::embed::XStorage >&, const String&, const String& , String& )
1706cdf0e10cSrcweir {
1707cdf0e10cSrcweir 	return sal_False;
1708cdf0e10cSrcweir }
1709cdf0e10cSrcweir 
1710cdf0e10cSrcweir 	//	- Text mit Attributierung (kann nur der SWG - SWG-Format!)
PutText(const com::sun::star::uno::Reference<com::sun::star::embed::XStorage> &,const String &,const String &,SfxObjectShell &,String &)1711cdf0e10cSrcweir sal_Bool SvxAutoCorrect::PutText( const com::sun::star::uno::Reference < com::sun::star::embed::XStorage >&, const String&, const String&, SfxObjectShell&,
1712cdf0e10cSrcweir 								String& )
1713cdf0e10cSrcweir {
1714cdf0e10cSrcweir 	return sal_False;
1715cdf0e10cSrcweir }
1716cdf0e10cSrcweir 
EncryptBlockName_Imp(String & rName)1717cdf0e10cSrcweir void EncryptBlockName_Imp( String& rName )
1718cdf0e10cSrcweir {
1719cdf0e10cSrcweir 	xub_StrLen nLen, nPos = 1;
1720cdf0e10cSrcweir 	rName.Insert( '#', 0 );
1721cdf0e10cSrcweir 	sal_Unicode* pName = rName.GetBufferAccess();
1722cdf0e10cSrcweir 	for ( nLen = rName.Len(), ++pName; nPos < nLen; ++nPos, ++pName )
1723cdf0e10cSrcweir 	{
1724cdf0e10cSrcweir 		if( lcl_IsInAsciiArr( "!/:.\\", *pName ))
1725cdf0e10cSrcweir 			*pName &= 0x0f;
1726cdf0e10cSrcweir 	}
1727cdf0e10cSrcweir }
1728cdf0e10cSrcweir 
1729cdf0e10cSrcweir /* This code is copied from SwXMLTextBlocks::GeneratePackageName */
GeneratePackageName(const String & rShort,String & rPackageName)1730cdf0e10cSrcweir void GeneratePackageName ( const String& rShort, String& rPackageName )
1731cdf0e10cSrcweir {
1732cdf0e10cSrcweir 	rPackageName = rShort;
1733cdf0e10cSrcweir 	xub_StrLen nPos = 0;
1734cdf0e10cSrcweir 	sal_Unicode pDelims[] = { '!', '/', ':', '.', '\\', 0 };
1735cdf0e10cSrcweir 	ByteString sByte ( rPackageName, RTL_TEXTENCODING_UTF7);
1736cdf0e10cSrcweir 	rPackageName = String (sByte, RTL_TEXTENCODING_ASCII_US);
1737cdf0e10cSrcweir 	while( STRING_NOTFOUND != ( nPos = rPackageName.SearchChar( pDelims, nPos )))
1738cdf0e10cSrcweir 	{
1739cdf0e10cSrcweir 		rPackageName.SetChar( nPos, '_' );
1740cdf0e10cSrcweir 		++nPos;
1741cdf0e10cSrcweir 	}
1742cdf0e10cSrcweir }
1743cdf0e10cSrcweir 
DecryptBlockName_Imp(String & rName)1744cdf0e10cSrcweir void DecryptBlockName_Imp( String& rName )
1745cdf0e10cSrcweir {
1746cdf0e10cSrcweir 	if( '#' == rName.GetChar( 0 ) )
1747cdf0e10cSrcweir 	{
1748cdf0e10cSrcweir 		rName.Erase( 0, 1 );
1749cdf0e10cSrcweir 		sal_Unicode* pName = rName.GetBufferAccess();
1750cdf0e10cSrcweir 		xub_StrLen nLen, nPos;
1751cdf0e10cSrcweir 		for ( nLen = rName.Len(), nPos = 0; nPos < nLen; ++nPos, ++pName )
1752cdf0e10cSrcweir 			switch( *pName )
1753cdf0e10cSrcweir 			{
1754cdf0e10cSrcweir 			case 0x01:	*pName = '!';	break;
1755cdf0e10cSrcweir 			case 0x0A:	*pName = ':';	break;
1756cdf0e10cSrcweir 			case 0x0C:	*pName = '\\';	break;
1757cdf0e10cSrcweir 			case 0x0E:	*pName = '.';	break;
1758cdf0e10cSrcweir 			case 0x0F:	*pName = '/';	break;
1759cdf0e10cSrcweir 			}
1760cdf0e10cSrcweir 	}
1761cdf0e10cSrcweir }
1762cdf0e10cSrcweir 
1763cdf0e10cSrcweir 
1764cdf0e10cSrcweir /* -----------------18.11.98 16:00-------------------
1765cdf0e10cSrcweir  *
1766cdf0e10cSrcweir  * --------------------------------------------------*/
lcl_SearchWordsInList(SvxAutoCorrectLanguageListsPtr pList,const String & rTxt,xub_StrLen & rStt,xub_StrLen nEndPos,SvxAutoCorrDoc &)1767cdf0e10cSrcweir const SvxAutocorrWord* lcl_SearchWordsInList(
1768cdf0e10cSrcweir 				SvxAutoCorrectLanguageListsPtr pList, const String& rTxt,
1769cdf0e10cSrcweir 				xub_StrLen& rStt, xub_StrLen nEndPos, SvxAutoCorrDoc& )
1770cdf0e10cSrcweir {
1771cdf0e10cSrcweir 	const SvxAutocorrWordList* pAutoCorrWordList = pList->GetAutocorrWordList();
1772cdf0e10cSrcweir 	TransliterationWrapper& rCmp = GetIgnoreTranslWrapper();
1773cdf0e10cSrcweir 	for( xub_StrLen nPos = 0; nPos < pAutoCorrWordList->Count(); ++nPos )
1774cdf0e10cSrcweir 	{
1775cdf0e10cSrcweir 		const SvxAutocorrWord* pFnd = (*pAutoCorrWordList)[ nPos ];
1776cdf0e10cSrcweir 		const String& rChk = pFnd->GetShort();
1777cdf0e10cSrcweir 		if( nEndPos >= rChk.Len() )
1778cdf0e10cSrcweir 		{
1779cdf0e10cSrcweir 			xub_StrLen nCalcStt = nEndPos - rChk.Len();
1780cdf0e10cSrcweir 			if( ( !nCalcStt || nCalcStt == rStt ||
1781cdf0e10cSrcweir 				( nCalcStt < rStt &&
1782cdf0e10cSrcweir 					IsWordDelim( rTxt.GetChar(nCalcStt - 1 ) ))) )
1783cdf0e10cSrcweir 			{
1784cdf0e10cSrcweir 				String sWord( rTxt.GetBuffer() + nCalcStt, rChk.Len() );
1785cdf0e10cSrcweir 				if( rCmp.isEqual( rChk, sWord ))
1786cdf0e10cSrcweir 				{
1787cdf0e10cSrcweir 					rStt = nCalcStt;
1788cdf0e10cSrcweir 					return pFnd;
1789cdf0e10cSrcweir 				}
1790cdf0e10cSrcweir 			}
1791cdf0e10cSrcweir 		}
1792cdf0e10cSrcweir 	}
1793cdf0e10cSrcweir 	return 0;
1794cdf0e10cSrcweir }
1795cdf0e10cSrcweir 
1796cdf0e10cSrcweir 
1797cdf0e10cSrcweir // suche das oder die Worte in der ErsetzungsTabelle
SearchWordsInList(const String & rTxt,xub_StrLen & rStt,xub_StrLen nEndPos,SvxAutoCorrDoc & rDoc,LanguageType & rLang)1798cdf0e10cSrcweir const SvxAutocorrWord* SvxAutoCorrect::SearchWordsInList(
1799cdf0e10cSrcweir 				const String& rTxt, xub_StrLen& rStt, xub_StrLen nEndPos,
1800cdf0e10cSrcweir 				SvxAutoCorrDoc& rDoc, LanguageType& rLang )
1801cdf0e10cSrcweir {
1802cdf0e10cSrcweir 	LanguageType eLang = rLang;
1803cdf0e10cSrcweir 	const SvxAutocorrWord* pRet = 0;
1804cdf0e10cSrcweir 	if( LANGUAGE_SYSTEM == eLang )
1805cdf0e10cSrcweir 		eLang = MsLangId::getSystemLanguage();
1806cdf0e10cSrcweir 
1807cdf0e10cSrcweir 	// zuerst nach eLang suchen, dann nach der Obersprache
1808cdf0e10cSrcweir 	// US-Englisch -> Englisch und zuletzt in LANGUAGE_DONTKNOW
1809cdf0e10cSrcweir 
1810cdf0e10cSrcweir 	if( pLangTable->IsKeyValid( sal_uLong( eLang ) ) ||
1811cdf0e10cSrcweir 		CreateLanguageFile( eLang, sal_False ))
1812cdf0e10cSrcweir 	{
1813cdf0e10cSrcweir 		//die Sprache ist vorhanden - also her damit
1814cdf0e10cSrcweir 		SvxAutoCorrectLanguageListsPtr pList = pLangTable->Seek(sal_uLong(eLang));
1815cdf0e10cSrcweir 		pRet = lcl_SearchWordsInList(  pList, rTxt, rStt, nEndPos, rDoc );
1816cdf0e10cSrcweir 		if( pRet )
1817cdf0e10cSrcweir 		{
1818cdf0e10cSrcweir 			rLang = eLang;
1819cdf0e10cSrcweir 			return pRet;
1820cdf0e10cSrcweir 		}
1821cdf0e10cSrcweir 	}
1822cdf0e10cSrcweir 
1823cdf0e10cSrcweir 	// wenn es hier noch nicht gefunden werden konnte, dann weitersuchen
1824cdf0e10cSrcweir 	sal_uLong nTmpKey1 = eLang & 0x7ff, // die Hauptsprache in vielen Faellen u.B. DE
1825cdf0e10cSrcweir 		  nTmpKey2 = eLang & 0x3ff, // sonst z.B. EN
1826cdf0e10cSrcweir 		  nTmp;
1827cdf0e10cSrcweir 
1828cdf0e10cSrcweir 	if( ((nTmp = nTmpKey1) != (sal_uLong)eLang &&
1829cdf0e10cSrcweir 		 ( pLangTable->IsKeyValid( nTmpKey1 ) ||
1830cdf0e10cSrcweir 		   CreateLanguageFile( LanguageType( nTmpKey1 ), sal_False ) )) ||
1831cdf0e10cSrcweir 		(( nTmp = nTmpKey2) != (sal_uLong)eLang &&
1832cdf0e10cSrcweir 		 ( pLangTable->IsKeyValid( nTmpKey2 ) ||
1833cdf0e10cSrcweir 		   CreateLanguageFile( LanguageType( nTmpKey2 ), sal_False ) )) )
1834cdf0e10cSrcweir 	{
1835cdf0e10cSrcweir 		//die Sprache ist vorhanden - also her damit
1836cdf0e10cSrcweir 		SvxAutoCorrectLanguageListsPtr pList = pLangTable->Seek( nTmp );
1837cdf0e10cSrcweir 		pRet = lcl_SearchWordsInList( pList, rTxt, rStt, nEndPos, rDoc);
1838cdf0e10cSrcweir 		if( pRet )
1839cdf0e10cSrcweir 		{
1840cdf0e10cSrcweir 			rLang = LanguageType( nTmp );
1841cdf0e10cSrcweir 			return pRet;
1842cdf0e10cSrcweir 		}
1843cdf0e10cSrcweir 	}
1844cdf0e10cSrcweir 	if( pLangTable->IsKeyValid( sal_uLong( LANGUAGE_DONTKNOW ) ) ||
1845cdf0e10cSrcweir 		CreateLanguageFile( LANGUAGE_DONTKNOW, sal_False ) )
1846cdf0e10cSrcweir 	{
1847cdf0e10cSrcweir 		//die Sprache ist vorhanden - also her damit
1848cdf0e10cSrcweir 		SvxAutoCorrectLanguageListsPtr pList = pLangTable->Seek(sal_uLong(LANGUAGE_DONTKNOW));
1849cdf0e10cSrcweir 		pRet = lcl_SearchWordsInList( pList, rTxt, rStt, nEndPos, rDoc);
1850cdf0e10cSrcweir 		if( pRet )
1851cdf0e10cSrcweir 		{
1852cdf0e10cSrcweir 			rLang = LANGUAGE_DONTKNOW;
1853cdf0e10cSrcweir 			return pRet;
1854cdf0e10cSrcweir 		}
1855cdf0e10cSrcweir 	}
1856cdf0e10cSrcweir 	return 0;
1857cdf0e10cSrcweir }
1858cdf0e10cSrcweir /* -----------------18.11.98 13:46-------------------
1859cdf0e10cSrcweir  *
1860cdf0e10cSrcweir  * --------------------------------------------------*/
FindInWrdSttExceptList(LanguageType eLang,const String & sWord)1861cdf0e10cSrcweir sal_Bool SvxAutoCorrect::FindInWrdSttExceptList( LanguageType eLang,
1862cdf0e10cSrcweir 											 const String& sWord )
1863cdf0e10cSrcweir {
1864cdf0e10cSrcweir 	//zuerst nach eLang suchen, dann nach der Obersprace US-Englisch -> Englisch
1865cdf0e10cSrcweir 	//und zuletzt in LANGUAGE_DONTKNOW
1866cdf0e10cSrcweir 	sal_uLong nTmpKey1 = eLang & 0x7ff; // die Hauptsprache in vielen Faellen u.B. DE
1867cdf0e10cSrcweir 	sal_uLong nTmpKey2 = eLang & 0x3ff; // sonst z.B. EN
1868cdf0e10cSrcweir 	String sTemp(sWord);
1869cdf0e10cSrcweir 	if( pLangTable->IsKeyValid( sal_uLong( eLang )) ||
1870cdf0e10cSrcweir 		CreateLanguageFile( eLang, sal_False ) )
1871cdf0e10cSrcweir 	{
1872cdf0e10cSrcweir 		//die Sprache ist vorhanden - also her damit
1873cdf0e10cSrcweir 		SvxAutoCorrectLanguageListsPtr pList = pLangTable->Seek(sal_uLong(eLang));
1874cdf0e10cSrcweir 		String _sTemp(sWord);
1875cdf0e10cSrcweir 		if(pList->GetWrdSttExceptList()->Seek_Entry(&_sTemp))
1876cdf0e10cSrcweir 			return sal_True;
1877cdf0e10cSrcweir 
1878cdf0e10cSrcweir 	}
1879cdf0e10cSrcweir 	// wenn es hier noch nicht gefunden werden konnte, dann weitersuchen
1880cdf0e10cSrcweir 	sal_uLong nTmp;
1881cdf0e10cSrcweir 	if( ((nTmp = nTmpKey1) != (sal_uLong)eLang &&
1882cdf0e10cSrcweir 		 ( pLangTable->IsKeyValid( nTmpKey1 ) ||
1883cdf0e10cSrcweir 		   CreateLanguageFile( LanguageType( nTmpKey1 ), sal_False ) )) ||
1884cdf0e10cSrcweir 		(( nTmp = nTmpKey2) != (sal_uLong)eLang &&
1885cdf0e10cSrcweir 		 ( pLangTable->IsKeyValid( nTmpKey2 ) ||
1886cdf0e10cSrcweir 		   CreateLanguageFile( LanguageType( nTmpKey2 ), sal_False ) )) )
1887cdf0e10cSrcweir 	{
1888cdf0e10cSrcweir 		//die Sprache ist vorhanden - also her damit
1889cdf0e10cSrcweir 		SvxAutoCorrectLanguageListsPtr pList = pLangTable->Seek(nTmp);
1890cdf0e10cSrcweir 		if(pList->GetWrdSttExceptList()->Seek_Entry(&sTemp))
1891cdf0e10cSrcweir 			return sal_True;
1892cdf0e10cSrcweir 	}
1893cdf0e10cSrcweir 	if(pLangTable->IsKeyValid(sal_uLong(LANGUAGE_DONTKNOW))|| CreateLanguageFile(LANGUAGE_DONTKNOW, sal_False))
1894cdf0e10cSrcweir 	{
1895cdf0e10cSrcweir 		//die Sprache ist vorhanden - also her damit
1896cdf0e10cSrcweir 		SvxAutoCorrectLanguageListsPtr pList = pLangTable->Seek(sal_uLong(LANGUAGE_DONTKNOW));
1897cdf0e10cSrcweir 		if(pList->GetWrdSttExceptList()->Seek_Entry(&sTemp))
1898cdf0e10cSrcweir 			return sal_True;
1899cdf0e10cSrcweir 	}
1900cdf0e10cSrcweir 	return sal_False;
1901cdf0e10cSrcweir }
1902cdf0e10cSrcweir /* -----------------18.11.98 14:28-------------------
1903cdf0e10cSrcweir  *
1904cdf0e10cSrcweir  * --------------------------------------------------*/
lcl_FindAbbreviation(const SvStringsISortDtor * pList,const String & sWord)1905cdf0e10cSrcweir sal_Bool lcl_FindAbbreviation( const SvStringsISortDtor* pList, const String& sWord)
1906cdf0e10cSrcweir {
1907cdf0e10cSrcweir 	String sAbk( '~' );
1908cdf0e10cSrcweir 	sal_uInt16 nPos;
1909cdf0e10cSrcweir 	pList->Seek_Entry( &sAbk, &nPos );
1910cdf0e10cSrcweir 	if( nPos < pList->Count() )
1911cdf0e10cSrcweir 	{
1912cdf0e10cSrcweir 		String sLowerWord( sWord ); sLowerWord.ToLowerAscii();
1913cdf0e10cSrcweir 		const String* pAbk;
1914cdf0e10cSrcweir 		for( sal_uInt16 n = nPos;
1915cdf0e10cSrcweir 				n < pList->Count() &&
1916cdf0e10cSrcweir 				'~' == ( pAbk = (*pList)[ n ])->GetChar( 0 );
1917cdf0e10cSrcweir 			++n )
1918cdf0e10cSrcweir 		{
1919cdf0e10cSrcweir 			// ~ und ~. sind nicht erlaubt!
1920cdf0e10cSrcweir 			if( 2 < pAbk->Len() && pAbk->Len() - 1 <= sWord.Len() )
1921cdf0e10cSrcweir 			{
1922cdf0e10cSrcweir 				String sLowerAbk( *pAbk ); sLowerAbk.ToLowerAscii();
1923cdf0e10cSrcweir 				for( xub_StrLen i = sLowerAbk.Len(), ii = sLowerWord.Len(); i; )
1924cdf0e10cSrcweir 				{
1925cdf0e10cSrcweir 					if( !--i )		// stimmt ueberein
1926cdf0e10cSrcweir 						return sal_True;
1927cdf0e10cSrcweir 
1928cdf0e10cSrcweir 					if( sLowerAbk.GetChar( i ) != sLowerWord.GetChar( --ii ))
1929cdf0e10cSrcweir 						break;
1930cdf0e10cSrcweir 				}
1931cdf0e10cSrcweir 			}
1932cdf0e10cSrcweir 		}
1933cdf0e10cSrcweir 	}
1934cdf0e10cSrcweir 	DBG_ASSERT( !(nPos && '~' == (*pList)[ --nPos ]->GetChar( 0 ) ),
1935cdf0e10cSrcweir 			"falsch sortierte ExeptionListe?" );
1936cdf0e10cSrcweir 	return sal_False;
1937cdf0e10cSrcweir }
1938cdf0e10cSrcweir /* -----------------18.11.98 14:49-------------------
1939cdf0e10cSrcweir  *
1940cdf0e10cSrcweir  * --------------------------------------------------*/
FindInCplSttExceptList(LanguageType eLang,const String & sWord,sal_Bool bAbbreviation)1941cdf0e10cSrcweir sal_Bool SvxAutoCorrect::FindInCplSttExceptList(LanguageType eLang,
1942cdf0e10cSrcweir 								const String& sWord, sal_Bool bAbbreviation)
1943cdf0e10cSrcweir {
1944cdf0e10cSrcweir 	//zuerst nach eLang suchen, dann nach der Obersprace US-Englisch -> Englisch
1945cdf0e10cSrcweir 	//und zuletzt in LANGUAGE_DONTKNOW
1946cdf0e10cSrcweir 	sal_uLong nTmpKey1 = eLang & 0x7ff; // die Hauptsprache in vielen Faellen u.B. DE
1947cdf0e10cSrcweir 	sal_uLong nTmpKey2 = eLang & 0x3ff; // sonst z.B. EN
1948cdf0e10cSrcweir 	String sTemp( sWord );
1949cdf0e10cSrcweir 	if( pLangTable->IsKeyValid( sal_uLong( eLang )) ||
1950cdf0e10cSrcweir 		CreateLanguageFile( eLang, sal_False ))
1951cdf0e10cSrcweir 	{
1952cdf0e10cSrcweir 		//die Sprache ist vorhanden - also her damit
1953cdf0e10cSrcweir 		SvxAutoCorrectLanguageListsPtr pLists = pLangTable->Seek(sal_uLong(eLang));
1954cdf0e10cSrcweir 		const SvStringsISortDtor* pList = pLists->GetCplSttExceptList();
1955cdf0e10cSrcweir 		if(bAbbreviation ? lcl_FindAbbreviation( pList, sWord)
1956cdf0e10cSrcweir 						 : pList->Seek_Entry( &sTemp ) )
1957cdf0e10cSrcweir 			return sal_True;
1958cdf0e10cSrcweir 	}
1959cdf0e10cSrcweir 	// wenn es hier noch nicht gefunden werden konnte, dann weitersuchen
1960cdf0e10cSrcweir 	sal_uLong nTmp;
1961cdf0e10cSrcweir 
1962cdf0e10cSrcweir 	if( ((nTmp = nTmpKey1) != (sal_uLong)eLang &&
1963cdf0e10cSrcweir 		 ( pLangTable->IsKeyValid( nTmpKey1 ) ||
1964cdf0e10cSrcweir 		   CreateLanguageFile( LanguageType( nTmpKey1 ), sal_False ) )) ||
1965cdf0e10cSrcweir 		(( nTmp = nTmpKey2) != (sal_uLong)eLang &&
1966cdf0e10cSrcweir 		 ( pLangTable->IsKeyValid( nTmpKey2 ) ||
1967cdf0e10cSrcweir 		   CreateLanguageFile( LanguageType( nTmpKey2 ), sal_False ) )) )
1968cdf0e10cSrcweir 	{
1969cdf0e10cSrcweir 		//die Sprache ist vorhanden - also her damit
1970cdf0e10cSrcweir 		SvxAutoCorrectLanguageListsPtr pLists = pLangTable->Seek(nTmp);
1971cdf0e10cSrcweir 		const SvStringsISortDtor* pList = pLists->GetCplSttExceptList();
1972cdf0e10cSrcweir 		if(bAbbreviation ? lcl_FindAbbreviation( pList, sWord)
1973cdf0e10cSrcweir 						 : pList->Seek_Entry( &sTemp ) )
1974cdf0e10cSrcweir 			return sal_True;
1975cdf0e10cSrcweir 	}
1976cdf0e10cSrcweir 	if(pLangTable->IsKeyValid(sal_uLong(LANGUAGE_DONTKNOW))|| CreateLanguageFile(LANGUAGE_DONTKNOW, sal_False))
1977cdf0e10cSrcweir 	{
1978cdf0e10cSrcweir 		//die Sprache ist vorhanden - also her damit
1979cdf0e10cSrcweir 		SvxAutoCorrectLanguageListsPtr pLists = pLangTable->Seek(LANGUAGE_DONTKNOW);
1980cdf0e10cSrcweir 		const SvStringsISortDtor* pList = pLists->GetCplSttExceptList();
1981cdf0e10cSrcweir 		if(bAbbreviation ? lcl_FindAbbreviation( pList, sWord)
1982cdf0e10cSrcweir 						 : pList->Seek_Entry( &sTemp ) )
1983cdf0e10cSrcweir 			return sal_True;
1984cdf0e10cSrcweir 	}
1985cdf0e10cSrcweir 	return sal_False;
1986cdf0e10cSrcweir 
1987cdf0e10cSrcweir }
1988cdf0e10cSrcweir 
1989cdf0e10cSrcweir /* -----------------20.11.98 11:53-------------------
1990cdf0e10cSrcweir  *
1991cdf0e10cSrcweir  * --------------------------------------------------*/
GetAutoCorrFileName(LanguageType eLang,sal_Bool bNewFile,sal_Bool bTst) const1992cdf0e10cSrcweir String SvxAutoCorrect::GetAutoCorrFileName( LanguageType eLang,
1993cdf0e10cSrcweir 											sal_Bool bNewFile, sal_Bool bTst ) const
1994cdf0e10cSrcweir {
1995cdf0e10cSrcweir     String sRet, sExt( MsLangId::convertLanguageToIsoString( eLang ) );
1996cdf0e10cSrcweir     sExt.Insert('_', 0);
1997cdf0e10cSrcweir     sExt.AppendAscii( ".dat" );
1998cdf0e10cSrcweir 	if( bNewFile )
1999cdf0e10cSrcweir         ( sRet = sUserAutoCorrFile )  += sExt;
2000cdf0e10cSrcweir 	else if( !bTst )
2001cdf0e10cSrcweir         ( sRet = sShareAutoCorrFile )  += sExt;
2002cdf0e10cSrcweir 	else
2003cdf0e10cSrcweir 	{
2004cdf0e10cSrcweir 		// test first in the user directory - if not exist, then
2005cdf0e10cSrcweir         ( sRet = sUserAutoCorrFile ) += sExt;
2006cdf0e10cSrcweir 		if( !FStatHelper::IsDocument( sRet ))
2007cdf0e10cSrcweir             ( sRet = sShareAutoCorrFile ) += sExt;
2008cdf0e10cSrcweir 	}
2009cdf0e10cSrcweir 	return sRet;
2010cdf0e10cSrcweir }
2011cdf0e10cSrcweir 
2012cdf0e10cSrcweir /* -----------------18.11.98 11:16-------------------
2013cdf0e10cSrcweir  *
2014cdf0e10cSrcweir  * --------------------------------------------------*/
SvxAutoCorrectLanguageLists(SvxAutoCorrect & rParent,const String & rShareAutoCorrectFile,const String & rUserAutoCorrectFile,LanguageType eLang)2015cdf0e10cSrcweir SvxAutoCorrectLanguageLists::SvxAutoCorrectLanguageLists(
2016cdf0e10cSrcweir 				SvxAutoCorrect& rParent,
2017cdf0e10cSrcweir 				const String& rShareAutoCorrectFile,
2018cdf0e10cSrcweir 				const String& rUserAutoCorrectFile,
2019cdf0e10cSrcweir 				LanguageType eLang)
2020cdf0e10cSrcweir :	sShareAutoCorrFile( rShareAutoCorrectFile ),
2021cdf0e10cSrcweir 	sUserAutoCorrFile( rUserAutoCorrectFile ),
2022cdf0e10cSrcweir 	eLanguage(eLang),
2023cdf0e10cSrcweir 	pCplStt_ExcptLst( 0 ),
2024cdf0e10cSrcweir 	pWrdStt_ExcptLst( 0 ),
2025cdf0e10cSrcweir 	pAutocorr_List( 0 ),
2026cdf0e10cSrcweir 	rAutoCorrect(rParent),
2027cdf0e10cSrcweir 	nFlags(0)
2028cdf0e10cSrcweir {
2029cdf0e10cSrcweir }
2030cdf0e10cSrcweir 
2031cdf0e10cSrcweir /* -----------------18.11.98 11:16-------------------
2032cdf0e10cSrcweir  *
2033cdf0e10cSrcweir  * --------------------------------------------------*/
~SvxAutoCorrectLanguageLists()2034cdf0e10cSrcweir SvxAutoCorrectLanguageLists::~SvxAutoCorrectLanguageLists()
2035cdf0e10cSrcweir {
2036cdf0e10cSrcweir 	delete pCplStt_ExcptLst;
2037cdf0e10cSrcweir 	delete pWrdStt_ExcptLst;
2038cdf0e10cSrcweir 	delete pAutocorr_List;
2039cdf0e10cSrcweir }
2040cdf0e10cSrcweir 
2041cdf0e10cSrcweir /* -----------------18.11.98 11:26-------------------
2042cdf0e10cSrcweir  *
2043cdf0e10cSrcweir  * --------------------------------------------------*/
IsFileChanged_Imp()2044cdf0e10cSrcweir sal_Bool SvxAutoCorrectLanguageLists::IsFileChanged_Imp()
2045cdf0e10cSrcweir {
2046cdf0e10cSrcweir 	// nur alle 2 Minuten aufs FileSystem zugreifen um den
2047cdf0e10cSrcweir 	// Dateistempel zu ueberpruefen
2048cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
2049cdf0e10cSrcweir 
2050cdf0e10cSrcweir 	Time nMinTime( 0, 2 );
2051cdf0e10cSrcweir 	Time nAktTime;
2052cdf0e10cSrcweir 	if( aLastCheckTime > nAktTime ||	   				// ueberlauf ?
2053cdf0e10cSrcweir 		( nAktTime -= aLastCheckTime ) > nMinTime )		// min Zeit vergangen
2054cdf0e10cSrcweir 	{
2055cdf0e10cSrcweir 		Date aTstDate; Time aTstTime;
2056cdf0e10cSrcweir 		if( FStatHelper::GetModifiedDateTimeOfFile( sShareAutoCorrFile,
2057cdf0e10cSrcweir 											&aTstDate, &aTstTime ) &&
2058cdf0e10cSrcweir 			( aModifiedDate != aTstDate || aModifiedTime != aTstTime ))
2059cdf0e10cSrcweir 		{
2060cdf0e10cSrcweir 			bRet = sal_True;
2061cdf0e10cSrcweir 			// dann mal schnell alle Listen entfernen!
2062cdf0e10cSrcweir 			if( CplSttLstLoad & nFlags && pCplStt_ExcptLst )
2063cdf0e10cSrcweir 				delete pCplStt_ExcptLst, pCplStt_ExcptLst = 0;
2064cdf0e10cSrcweir 			if( WrdSttLstLoad & nFlags && pWrdStt_ExcptLst )
2065cdf0e10cSrcweir 				delete pWrdStt_ExcptLst, pWrdStt_ExcptLst = 0;
2066cdf0e10cSrcweir 			if( ChgWordLstLoad & nFlags && pAutocorr_List )
2067cdf0e10cSrcweir 				delete pAutocorr_List, pAutocorr_List = 0;
2068cdf0e10cSrcweir 			nFlags &= ~(CplSttLstLoad | WrdSttLstLoad | ChgWordLstLoad );
2069cdf0e10cSrcweir 		}
2070cdf0e10cSrcweir 		aLastCheckTime = Time();
2071cdf0e10cSrcweir 	}
2072cdf0e10cSrcweir 	return bRet;
2073cdf0e10cSrcweir }
2074cdf0e10cSrcweir 
LoadXMLExceptList_Imp(SvStringsISortDtor * & rpLst,const sal_Char * pStrmName,SotStorageRef & rStg)2075cdf0e10cSrcweir void SvxAutoCorrectLanguageLists::LoadXMLExceptList_Imp(
2076cdf0e10cSrcweir 										SvStringsISortDtor*& rpLst,
2077cdf0e10cSrcweir 										const sal_Char* pStrmName,
2078cdf0e10cSrcweir                                         SotStorageRef& rStg)
2079cdf0e10cSrcweir {
2080cdf0e10cSrcweir 	if( rpLst )
2081cdf0e10cSrcweir 		rpLst->DeleteAndDestroy( 0, rpLst->Count() );
2082cdf0e10cSrcweir 	else
2083cdf0e10cSrcweir 		rpLst = new SvStringsISortDtor( 16, 16 );
2084cdf0e10cSrcweir 
2085cdf0e10cSrcweir 	{
2086cdf0e10cSrcweir 		String sStrmName( pStrmName, RTL_TEXTENCODING_MS_1252 );
2087cdf0e10cSrcweir 		String sTmp( sStrmName );
2088cdf0e10cSrcweir 
2089cdf0e10cSrcweir 		if( rStg.Is() && rStg->IsStream( sStrmName ) )
2090cdf0e10cSrcweir 		{
2091cdf0e10cSrcweir 			SvStorageStreamRef xStrm = rStg->OpenSotStream( sTmp,
2092cdf0e10cSrcweir 				( STREAM_READ | STREAM_SHARE_DENYWRITE | STREAM_NOCREATE ) );
2093cdf0e10cSrcweir 			if( SVSTREAM_OK != xStrm->GetError())
2094cdf0e10cSrcweir 			{
2095cdf0e10cSrcweir 				xStrm.Clear();
2096cdf0e10cSrcweir 				rStg.Clear();
2097cdf0e10cSrcweir 				RemoveStream_Imp( sStrmName );
2098cdf0e10cSrcweir 			}
2099cdf0e10cSrcweir 			else
2100cdf0e10cSrcweir 			{
2101cdf0e10cSrcweir 				uno::Reference< lang::XMultiServiceFactory > xServiceFactory =
2102cdf0e10cSrcweir 					comphelper::getProcessServiceFactory();
2103cdf0e10cSrcweir 				DBG_ASSERT( xServiceFactory.is(),
2104cdf0e10cSrcweir 					"XMLReader::Read: got no service manager" );
2105cdf0e10cSrcweir 				if( !xServiceFactory.is() )
2106cdf0e10cSrcweir 				{
2107cdf0e10cSrcweir 					// Throw an exception ?
2108cdf0e10cSrcweir 				}
2109cdf0e10cSrcweir 
2110cdf0e10cSrcweir 				xml::sax::InputSource aParserInput;
2111cdf0e10cSrcweir 				aParserInput.sSystemId = sStrmName;
2112cdf0e10cSrcweir 
2113cdf0e10cSrcweir 				xStrm->Seek( 0L );
2114cdf0e10cSrcweir 				xStrm->SetBufferSize( 8 * 1024 );
2115cdf0e10cSrcweir 				aParserInput.aInputStream = new utl::OInputStreamWrapper( *xStrm );
2116cdf0e10cSrcweir 
2117cdf0e10cSrcweir 				// get parser
2118cdf0e10cSrcweir 				uno::Reference< XInterface > xXMLParser = xServiceFactory->createInstance(
2119cdf0e10cSrcweir 					OUString::createFromAscii("com.sun.star.xml.sax.Parser") );
2120cdf0e10cSrcweir 				DBG_ASSERT( xXMLParser.is(),
2121cdf0e10cSrcweir 					"XMLReader::Read: com.sun.star.xml.sax.Parser service missing" );
2122cdf0e10cSrcweir 				if( !xXMLParser.is() )
2123cdf0e10cSrcweir 				{
2124cdf0e10cSrcweir 					// Maybe throw an exception?
2125cdf0e10cSrcweir 				}
2126cdf0e10cSrcweir 
2127cdf0e10cSrcweir 				// get filter
2128cdf0e10cSrcweir 				// #110680#
2129cdf0e10cSrcweir 				// uno::Reference< xml::sax::XDocumentHandler > xFilter = new SvXMLExceptionListImport ( *rpLst );
2130cdf0e10cSrcweir 				uno::Reference< xml::sax::XDocumentHandler > xFilter = new SvXMLExceptionListImport ( xServiceFactory, *rpLst );
2131cdf0e10cSrcweir 
2132cdf0e10cSrcweir 				// connect parser and filter
2133cdf0e10cSrcweir 				uno::Reference< xml::sax::XParser > xParser( xXMLParser, UNO_QUERY );
2134cdf0e10cSrcweir 				xParser->setDocumentHandler( xFilter );
2135cdf0e10cSrcweir 
2136cdf0e10cSrcweir 				// parse
2137cdf0e10cSrcweir 				try
2138cdf0e10cSrcweir 				{
2139cdf0e10cSrcweir 					xParser->parseStream( aParserInput );
2140cdf0e10cSrcweir 				}
2141cdf0e10cSrcweir 				catch( xml::sax::SAXParseException&  )
2142cdf0e10cSrcweir 				{
2143cdf0e10cSrcweir 					// re throw ?
2144cdf0e10cSrcweir 				}
2145cdf0e10cSrcweir 				catch( xml::sax::SAXException&  )
2146cdf0e10cSrcweir 				{
2147cdf0e10cSrcweir 					// re throw ?
2148cdf0e10cSrcweir 				}
2149cdf0e10cSrcweir 				catch( io::IOException& )
2150cdf0e10cSrcweir 				{
2151cdf0e10cSrcweir 					// re throw ?
2152cdf0e10cSrcweir 				}
2153cdf0e10cSrcweir 			}
2154cdf0e10cSrcweir 		}
2155cdf0e10cSrcweir 
2156cdf0e10cSrcweir 		// Zeitstempel noch setzen
2157cdf0e10cSrcweir 		FStatHelper::GetModifiedDateTimeOfFile( sShareAutoCorrFile,
2158cdf0e10cSrcweir 										&aModifiedDate, &aModifiedTime );
2159cdf0e10cSrcweir 		aLastCheckTime = Time();
2160cdf0e10cSrcweir 	}
2161cdf0e10cSrcweir 
2162cdf0e10cSrcweir }
2163cdf0e10cSrcweir /* -----------------18.11.98 11:26-------------------
2164cdf0e10cSrcweir  *
2165cdf0e10cSrcweir  * --------------------------------------------------*/
SaveExceptList_Imp(const SvStringsISortDtor & rLst,const sal_Char * pStrmName,SotStorageRef & rStg,sal_Bool bConvert)2166cdf0e10cSrcweir void SvxAutoCorrectLanguageLists::SaveExceptList_Imp(
2167cdf0e10cSrcweir 							const SvStringsISortDtor& rLst,
2168cdf0e10cSrcweir 							const sal_Char* pStrmName,
2169cdf0e10cSrcweir                             SotStorageRef &rStg,
2170cdf0e10cSrcweir 							sal_Bool bConvert )
2171cdf0e10cSrcweir {
2172cdf0e10cSrcweir 	if( rStg.Is() )
2173cdf0e10cSrcweir 	{
2174cdf0e10cSrcweir 		String sStrmName( pStrmName, RTL_TEXTENCODING_MS_1252 );
2175cdf0e10cSrcweir 		if( !rLst.Count() )
2176cdf0e10cSrcweir 		{
2177cdf0e10cSrcweir 			rStg->Remove( sStrmName );
2178cdf0e10cSrcweir 			rStg->Commit();
2179cdf0e10cSrcweir 		}
2180cdf0e10cSrcweir 		else
2181cdf0e10cSrcweir 		{
2182cdf0e10cSrcweir             SotStorageStreamRef xStrm = rStg->OpenSotStream( sStrmName,
2183cdf0e10cSrcweir 					( STREAM_READ | STREAM_WRITE | STREAM_SHARE_DENYWRITE ) );
2184cdf0e10cSrcweir 			if( xStrm.Is() )
2185cdf0e10cSrcweir 			{
2186cdf0e10cSrcweir 				xStrm->SetSize( 0 );
2187cdf0e10cSrcweir 				xStrm->SetBufferSize( 8192 );
2188cdf0e10cSrcweir 				String aPropName( String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM("MediaType") ) );
2189cdf0e10cSrcweir 				OUString aMime( RTL_CONSTASCII_USTRINGPARAM("text/xml") );
2190cdf0e10cSrcweir 				uno::Any aAny;
2191cdf0e10cSrcweir 				aAny <<= aMime;
2192cdf0e10cSrcweir 				xStrm->SetProperty( aPropName, aAny );
2193cdf0e10cSrcweir 
2194cdf0e10cSrcweir 
2195cdf0e10cSrcweir 				uno::Reference< lang::XMultiServiceFactory > xServiceFactory =
2196cdf0e10cSrcweir 					comphelper::getProcessServiceFactory();
2197cdf0e10cSrcweir 				DBG_ASSERT( xServiceFactory.is(),
2198cdf0e10cSrcweir 							"XMLReader::Read: got no service manager" );
2199cdf0e10cSrcweir 				if( !xServiceFactory.is() )
2200cdf0e10cSrcweir 				{
2201cdf0e10cSrcweir 					// Throw an exception ?
2202cdf0e10cSrcweir 				}
2203cdf0e10cSrcweir 
2204cdf0e10cSrcweir    			 	uno::Reference < XInterface > xWriter (xServiceFactory->createInstance(
2205cdf0e10cSrcweir    			    	 OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.xml.sax.Writer"))));
2206cdf0e10cSrcweir    			 	DBG_ASSERT(xWriter.is(),"com.sun.star.xml.sax.Writer service missing");
2207cdf0e10cSrcweir 				uno::Reference < io::XOutputStream> xOut = new utl::OOutputStreamWrapper( *xStrm );
2208cdf0e10cSrcweir    			 	uno::Reference<io::XActiveDataSource> xSrc(xWriter, uno::UNO_QUERY);
2209cdf0e10cSrcweir    			 	xSrc->setOutputStream(xOut);
2210cdf0e10cSrcweir 
2211cdf0e10cSrcweir    			 	uno::Reference<xml::sax::XDocumentHandler> xHandler(xWriter, uno::UNO_QUERY);
2212cdf0e10cSrcweir 
2213cdf0e10cSrcweir 				// #110680#
2214cdf0e10cSrcweir    			 	// SvXMLExceptionListExport aExp(rLst, sStrmName, xHandler);
2215cdf0e10cSrcweir    			 	SvXMLExceptionListExport aExp( xServiceFactory, rLst, sStrmName, xHandler );
2216cdf0e10cSrcweir 
2217cdf0e10cSrcweir 				aExp.exportDoc( XML_BLOCK_LIST );
2218cdf0e10cSrcweir 
2219cdf0e10cSrcweir 				xStrm->Commit();
2220cdf0e10cSrcweir 				if( xStrm->GetError() == SVSTREAM_OK )
2221cdf0e10cSrcweir 				{
2222cdf0e10cSrcweir 					xStrm.Clear();
2223cdf0e10cSrcweir 					if (!bConvert)
2224cdf0e10cSrcweir 					{
2225cdf0e10cSrcweir 						rStg->Commit();
2226cdf0e10cSrcweir 						if( SVSTREAM_OK != rStg->GetError() )
2227cdf0e10cSrcweir 						{
2228cdf0e10cSrcweir 							rStg->Remove( sStrmName );
2229cdf0e10cSrcweir 							rStg->Commit();
2230cdf0e10cSrcweir 						}
2231cdf0e10cSrcweir 					}
2232cdf0e10cSrcweir 				}
2233cdf0e10cSrcweir 			}
2234cdf0e10cSrcweir 		}
2235cdf0e10cSrcweir 	}
2236cdf0e10cSrcweir }
2237cdf0e10cSrcweir /* -----------------18.11.98 11:26-------------------
2238cdf0e10cSrcweir  *
2239cdf0e10cSrcweir  * --------------------------------------------------*/
LoadAutocorrWordList()2240cdf0e10cSrcweir SvxAutocorrWordList* SvxAutoCorrectLanguageLists::LoadAutocorrWordList()
2241cdf0e10cSrcweir {
2242cdf0e10cSrcweir 	if( pAutocorr_List )
2243cdf0e10cSrcweir 		pAutocorr_List->DeleteAndDestroy( 0, pAutocorr_List->Count() );
2244cdf0e10cSrcweir 	else
2245cdf0e10cSrcweir 		pAutocorr_List = new SvxAutocorrWordList( 16, 16 );
2246cdf0e10cSrcweir 
2247cdf0e10cSrcweir 	SvStringsDtor aRemoveArr;
2248cdf0e10cSrcweir     try
2249cdf0e10cSrcweir     {
2250cdf0e10cSrcweir         uno::Reference < embed::XStorage > xStg = comphelper::OStorageHelper::GetStorageFromURL( sShareAutoCorrFile, embed::ElementModes::READ );
2251cdf0e10cSrcweir         String aXMLWordListName( pXMLImplAutocorr_ListStr, RTL_TEXTENCODING_MS_1252 );
2252cdf0e10cSrcweir         uno::Reference < io::XStream > xStrm = xStg->openStreamElement( aXMLWordListName, embed::ElementModes::READ );
2253cdf0e10cSrcweir         uno::Reference< lang::XMultiServiceFactory > xServiceFactory = comphelper::getProcessServiceFactory();
2254cdf0e10cSrcweir 
2255cdf0e10cSrcweir         xml::sax::InputSource aParserInput;
2256cdf0e10cSrcweir         aParserInput.sSystemId = aXMLWordListName;
2257cdf0e10cSrcweir         aParserInput.aInputStream = xStrm->getInputStream();
2258cdf0e10cSrcweir 
2259cdf0e10cSrcweir         // get parser
2260cdf0e10cSrcweir         uno::Reference< XInterface > xXMLParser = xServiceFactory->createInstance( OUString::createFromAscii("com.sun.star.xml.sax.Parser") );
2261cdf0e10cSrcweir         DBG_ASSERT( xXMLParser.is(), "XMLReader::Read: com.sun.star.xml.sax.Parser service missing" );
2262cdf0e10cSrcweir         if( xXMLParser.is() )
2263cdf0e10cSrcweir         {
2264cdf0e10cSrcweir             uno::Reference< xml::sax::XDocumentHandler > xFilter = new SvXMLAutoCorrectImport( xServiceFactory, pAutocorr_List, rAutoCorrect, xStg );
2265cdf0e10cSrcweir 
2266cdf0e10cSrcweir             // connect parser and filter
2267cdf0e10cSrcweir             uno::Reference< xml::sax::XParser > xParser( xXMLParser, UNO_QUERY );
2268cdf0e10cSrcweir             xParser->setDocumentHandler( xFilter );
2269cdf0e10cSrcweir 
2270cdf0e10cSrcweir             // parse
2271cdf0e10cSrcweir             xParser->parseStream( aParserInput );
2272cdf0e10cSrcweir         }
2273cdf0e10cSrcweir     }
2274cdf0e10cSrcweir     catch ( uno::Exception& )
2275cdf0e10cSrcweir     {
2276cdf0e10cSrcweir     }
2277cdf0e10cSrcweir 
2278cdf0e10cSrcweir     // Zeitstempel noch setzen
2279cdf0e10cSrcweir     FStatHelper::GetModifiedDateTimeOfFile( sShareAutoCorrFile,
2280cdf0e10cSrcweir                                     &aModifiedDate, &aModifiedTime );
2281cdf0e10cSrcweir     aLastCheckTime = Time();
2282cdf0e10cSrcweir 
2283cdf0e10cSrcweir 	return pAutocorr_List;
2284cdf0e10cSrcweir }
2285cdf0e10cSrcweir 
2286cdf0e10cSrcweir /* -----------------18.11.98 11:26-------------------
2287cdf0e10cSrcweir  *
2288cdf0e10cSrcweir  * --------------------------------------------------*/
2289cdf0e10cSrcweir 
SetAutocorrWordList(SvxAutocorrWordList * pList)2290cdf0e10cSrcweir void SvxAutoCorrectLanguageLists::SetAutocorrWordList( SvxAutocorrWordList* pList )
2291cdf0e10cSrcweir {
2292cdf0e10cSrcweir 	if( pAutocorr_List && pList != pAutocorr_List )
2293cdf0e10cSrcweir 		delete pAutocorr_List;
2294cdf0e10cSrcweir 	pAutocorr_List = pList;
2295cdf0e10cSrcweir 	if( !pAutocorr_List )
2296cdf0e10cSrcweir 	{
2297cdf0e10cSrcweir 		DBG_ASSERT( !this, "keine gueltige Liste" );
2298cdf0e10cSrcweir 		pAutocorr_List = new SvxAutocorrWordList( 16, 16 );
2299cdf0e10cSrcweir 	}
2300cdf0e10cSrcweir 	nFlags |= ChgWordLstLoad;
2301cdf0e10cSrcweir }
2302cdf0e10cSrcweir 
2303cdf0e10cSrcweir /* -----------------18.11.98 11:26-------------------
2304cdf0e10cSrcweir  *
2305cdf0e10cSrcweir  * --------------------------------------------------*/
GetAutocorrWordList()2306cdf0e10cSrcweir const SvxAutocorrWordList* SvxAutoCorrectLanguageLists::GetAutocorrWordList()
2307cdf0e10cSrcweir {
2308cdf0e10cSrcweir 	if( !( ChgWordLstLoad & nFlags ) || IsFileChanged_Imp() )
2309cdf0e10cSrcweir 		SetAutocorrWordList( LoadAutocorrWordList() );
2310cdf0e10cSrcweir 	return pAutocorr_List;
2311cdf0e10cSrcweir }
2312cdf0e10cSrcweir /* -----------------18.11.98 11:26-------------------
2313cdf0e10cSrcweir  *
2314cdf0e10cSrcweir  * --------------------------------------------------*/
GetCplSttExceptList()2315cdf0e10cSrcweir SvStringsISortDtor* SvxAutoCorrectLanguageLists::GetCplSttExceptList()
2316cdf0e10cSrcweir {
2317cdf0e10cSrcweir 	if( !( CplSttLstLoad & nFlags ) || IsFileChanged_Imp() )
2318cdf0e10cSrcweir 		SetCplSttExceptList( LoadCplSttExceptList() );
2319cdf0e10cSrcweir 	return pCplStt_ExcptLst;
2320cdf0e10cSrcweir }
2321cdf0e10cSrcweir /* -----------------18.11.98 11:26-------------------
2322cdf0e10cSrcweir  *
2323cdf0e10cSrcweir  * --------------------------------------------------*/
AddToCplSttExceptList(const String & rNew)2324cdf0e10cSrcweir sal_Bool SvxAutoCorrectLanguageLists::AddToCplSttExceptList(const String& rNew)
2325cdf0e10cSrcweir {
2326cdf0e10cSrcweir 	String* pNew = new String( rNew );
2327cdf0e10cSrcweir     if( rNew.Len() && GetCplSttExceptList()->Insert( pNew ) )
2328cdf0e10cSrcweir 	{
2329cdf0e10cSrcweir 		MakeUserStorage_Impl();
2330cdf0e10cSrcweir         SotStorageRef xStg = new SotStorage( sUserAutoCorrFile, STREAM_READWRITE, sal_True );
2331cdf0e10cSrcweir 
2332cdf0e10cSrcweir 		SaveExceptList_Imp( *pCplStt_ExcptLst, pXMLImplCplStt_ExcptLstStr, xStg );
2333cdf0e10cSrcweir 
2334cdf0e10cSrcweir 		xStg = 0;
2335cdf0e10cSrcweir 		// Zeitstempel noch setzen
2336cdf0e10cSrcweir 		FStatHelper::GetModifiedDateTimeOfFile( sUserAutoCorrFile,
2337cdf0e10cSrcweir 											&aModifiedDate, &aModifiedTime );
2338cdf0e10cSrcweir 		aLastCheckTime = Time();
2339cdf0e10cSrcweir 	}
2340cdf0e10cSrcweir 	else
2341cdf0e10cSrcweir 		delete pNew, pNew = 0;
2342cdf0e10cSrcweir 	return 0 != pNew;
2343cdf0e10cSrcweir }
2344cdf0e10cSrcweir /* -----------------18.11.98 15:20-------------------
2345cdf0e10cSrcweir  *
2346cdf0e10cSrcweir  * --------------------------------------------------*/
AddToWrdSttExceptList(const String & rNew)2347cdf0e10cSrcweir sal_Bool SvxAutoCorrectLanguageLists::AddToWrdSttExceptList(const String& rNew)
2348cdf0e10cSrcweir {
2349cdf0e10cSrcweir 	String* pNew = new String( rNew );
2350cdf0e10cSrcweir 	SvStringsISortDtor* pExceptList = LoadWrdSttExceptList();
2351cdf0e10cSrcweir 	if( rNew.Len() && pExceptList && pExceptList->Insert( pNew ) )
2352cdf0e10cSrcweir 	{
2353cdf0e10cSrcweir 		MakeUserStorage_Impl();
2354cdf0e10cSrcweir         SotStorageRef xStg = new SotStorage( sUserAutoCorrFile, STREAM_READWRITE, sal_True );
2355cdf0e10cSrcweir 
2356cdf0e10cSrcweir 		SaveExceptList_Imp( *pWrdStt_ExcptLst, pXMLImplWrdStt_ExcptLstStr, xStg );
2357cdf0e10cSrcweir 
2358cdf0e10cSrcweir 		xStg = 0;
2359cdf0e10cSrcweir 		// Zeitstempel noch setzen
2360cdf0e10cSrcweir 		FStatHelper::GetModifiedDateTimeOfFile( sUserAutoCorrFile,
2361cdf0e10cSrcweir 											&aModifiedDate, &aModifiedTime );
2362cdf0e10cSrcweir 		aLastCheckTime = Time();
2363cdf0e10cSrcweir 	}
2364cdf0e10cSrcweir 	else
2365cdf0e10cSrcweir 		delete pNew, pNew = 0;
2366cdf0e10cSrcweir 	return 0 != pNew;
2367cdf0e10cSrcweir }
2368cdf0e10cSrcweir 
2369cdf0e10cSrcweir /* -----------------18.11.98 11:26-------------------
2370cdf0e10cSrcweir  *
2371cdf0e10cSrcweir  * --------------------------------------------------*/
LoadCplSttExceptList()2372cdf0e10cSrcweir SvStringsISortDtor* SvxAutoCorrectLanguageLists::LoadCplSttExceptList()
2373cdf0e10cSrcweir {
2374cdf0e10cSrcweir 	SotStorageRef xStg = new SotStorage( sShareAutoCorrFile, STREAM_READ | STREAM_SHARE_DENYNONE, sal_True );
2375cdf0e10cSrcweir 	String sTemp ( RTL_CONSTASCII_USTRINGPARAM ( pXMLImplCplStt_ExcptLstStr ) );
2376cdf0e10cSrcweir 	if( xStg.Is() && xStg->IsContained( sTemp ) )
2377cdf0e10cSrcweir 		LoadXMLExceptList_Imp( pCplStt_ExcptLst, pXMLImplCplStt_ExcptLstStr, xStg );
2378cdf0e10cSrcweir 
2379cdf0e10cSrcweir 	return pCplStt_ExcptLst;
2380cdf0e10cSrcweir }
2381cdf0e10cSrcweir 
2382cdf0e10cSrcweir /* -----------------18.11.98 11:26-------------------
2383cdf0e10cSrcweir  *
2384cdf0e10cSrcweir  * --------------------------------------------------*/
SaveCplSttExceptList()2385cdf0e10cSrcweir void SvxAutoCorrectLanguageLists::SaveCplSttExceptList()
2386cdf0e10cSrcweir {
2387cdf0e10cSrcweir 	MakeUserStorage_Impl();
2388cdf0e10cSrcweir     SotStorageRef xStg = new SotStorage( sUserAutoCorrFile, STREAM_READWRITE, sal_True );
2389cdf0e10cSrcweir 
2390cdf0e10cSrcweir 	SaveExceptList_Imp( *pCplStt_ExcptLst, pXMLImplCplStt_ExcptLstStr, xStg );
2391cdf0e10cSrcweir 
2392cdf0e10cSrcweir 	xStg = 0;
2393cdf0e10cSrcweir 
2394cdf0e10cSrcweir     // Zeitstempel noch setzen
2395cdf0e10cSrcweir 	FStatHelper::GetModifiedDateTimeOfFile( sUserAutoCorrFile,
2396cdf0e10cSrcweir 											&aModifiedDate, &aModifiedTime );
2397cdf0e10cSrcweir 	aLastCheckTime = Time();
2398cdf0e10cSrcweir }
2399cdf0e10cSrcweir 
2400cdf0e10cSrcweir /* -----------------18.11.98 11:26-------------------
2401cdf0e10cSrcweir  *
2402cdf0e10cSrcweir  * --------------------------------------------------*/
SetCplSttExceptList(SvStringsISortDtor * pList)2403cdf0e10cSrcweir void SvxAutoCorrectLanguageLists::SetCplSttExceptList( SvStringsISortDtor* pList )
2404cdf0e10cSrcweir {
2405cdf0e10cSrcweir 	if( pCplStt_ExcptLst && pList != pCplStt_ExcptLst )
2406cdf0e10cSrcweir 		delete pCplStt_ExcptLst;
2407cdf0e10cSrcweir 
2408cdf0e10cSrcweir 	pCplStt_ExcptLst = pList;
2409cdf0e10cSrcweir 	if( !pCplStt_ExcptLst )
2410cdf0e10cSrcweir 	{
2411cdf0e10cSrcweir 		DBG_ASSERT( !this, "keine gueltige Liste" );
2412cdf0e10cSrcweir 		pCplStt_ExcptLst = new SvStringsISortDtor( 16, 16 );
2413cdf0e10cSrcweir 	}
2414cdf0e10cSrcweir 	nFlags |= CplSttLstLoad;
2415cdf0e10cSrcweir }
2416cdf0e10cSrcweir /* -----------------18.11.98 11:26-------------------
2417cdf0e10cSrcweir  *
2418cdf0e10cSrcweir  * --------------------------------------------------*/
LoadWrdSttExceptList()2419cdf0e10cSrcweir SvStringsISortDtor* SvxAutoCorrectLanguageLists::LoadWrdSttExceptList()
2420cdf0e10cSrcweir {
2421cdf0e10cSrcweir 	SotStorageRef xStg = new SotStorage( sShareAutoCorrFile, STREAM_READ | STREAM_SHARE_DENYNONE, sal_True );
2422cdf0e10cSrcweir 	String sTemp ( RTL_CONSTASCII_USTRINGPARAM ( pXMLImplWrdStt_ExcptLstStr ) );
2423cdf0e10cSrcweir 	if( xStg.Is() && xStg->IsContained( sTemp ) )
2424cdf0e10cSrcweir 		LoadXMLExceptList_Imp( pWrdStt_ExcptLst, pXMLImplWrdStt_ExcptLstStr, xStg );
2425cdf0e10cSrcweir 	return pWrdStt_ExcptLst;
2426cdf0e10cSrcweir }
2427cdf0e10cSrcweir /* -----------------18.11.98 11:26-------------------
2428cdf0e10cSrcweir  *
2429cdf0e10cSrcweir  * --------------------------------------------------*/
SaveWrdSttExceptList()2430cdf0e10cSrcweir void SvxAutoCorrectLanguageLists::SaveWrdSttExceptList()
2431cdf0e10cSrcweir {
2432cdf0e10cSrcweir 	MakeUserStorage_Impl();
2433cdf0e10cSrcweir     SotStorageRef xStg = new SotStorage( sUserAutoCorrFile, STREAM_READWRITE, sal_True );
2434cdf0e10cSrcweir 
2435cdf0e10cSrcweir 	SaveExceptList_Imp( *pWrdStt_ExcptLst, pXMLImplWrdStt_ExcptLstStr, xStg );
2436cdf0e10cSrcweir 
2437cdf0e10cSrcweir 	xStg = 0;
2438cdf0e10cSrcweir 	// Zeitstempel noch setzen
2439cdf0e10cSrcweir 	FStatHelper::GetModifiedDateTimeOfFile( sUserAutoCorrFile,
2440cdf0e10cSrcweir 											&aModifiedDate, &aModifiedTime );
2441cdf0e10cSrcweir 	aLastCheckTime = Time();
2442cdf0e10cSrcweir }
2443cdf0e10cSrcweir /* -----------------18.11.98 11:26-------------------
2444cdf0e10cSrcweir  *
2445cdf0e10cSrcweir  * --------------------------------------------------*/
SetWrdSttExceptList(SvStringsISortDtor * pList)2446cdf0e10cSrcweir void SvxAutoCorrectLanguageLists::SetWrdSttExceptList( SvStringsISortDtor* pList )
2447cdf0e10cSrcweir {
2448cdf0e10cSrcweir 	if( pWrdStt_ExcptLst && pList != pWrdStt_ExcptLst )
2449cdf0e10cSrcweir 		delete pWrdStt_ExcptLst;
2450cdf0e10cSrcweir 	pWrdStt_ExcptLst = pList;
2451cdf0e10cSrcweir 	if( !pWrdStt_ExcptLst )
2452cdf0e10cSrcweir 	{
2453cdf0e10cSrcweir 		DBG_ASSERT( !this, "keine gueltige Liste" );
2454cdf0e10cSrcweir 		pWrdStt_ExcptLst = new SvStringsISortDtor( 16, 16 );
2455cdf0e10cSrcweir 	}
2456cdf0e10cSrcweir 	nFlags |= WrdSttLstLoad;
2457cdf0e10cSrcweir }
2458cdf0e10cSrcweir /* -----------------18.11.98 11:26-------------------
2459cdf0e10cSrcweir  *
2460cdf0e10cSrcweir  * --------------------------------------------------*/
GetWrdSttExceptList()2461cdf0e10cSrcweir SvStringsISortDtor* SvxAutoCorrectLanguageLists::GetWrdSttExceptList()
2462cdf0e10cSrcweir {
2463cdf0e10cSrcweir 	if( !( WrdSttLstLoad & nFlags ) || IsFileChanged_Imp() )
2464cdf0e10cSrcweir 		SetWrdSttExceptList( LoadWrdSttExceptList() );
2465cdf0e10cSrcweir 	return pWrdStt_ExcptLst;
2466cdf0e10cSrcweir }
2467cdf0e10cSrcweir /* -----------------18.11.98 11:26-------------------
2468cdf0e10cSrcweir  *
2469cdf0e10cSrcweir  * --------------------------------------------------*/
RemoveStream_Imp(const String & rName)2470cdf0e10cSrcweir void SvxAutoCorrectLanguageLists::RemoveStream_Imp( const String& rName )
2471cdf0e10cSrcweir {
2472cdf0e10cSrcweir 	if( sShareAutoCorrFile != sUserAutoCorrFile )
2473cdf0e10cSrcweir 	{
2474cdf0e10cSrcweir         SotStorageRef xStg = new SotStorage( sUserAutoCorrFile, STREAM_READWRITE, sal_True );
2475cdf0e10cSrcweir 		if( xStg.Is() && SVSTREAM_OK == xStg->GetError() &&
2476cdf0e10cSrcweir 			xStg->IsStream( rName ) )
2477cdf0e10cSrcweir 		{
2478cdf0e10cSrcweir 			xStg->Remove( rName );
2479cdf0e10cSrcweir 			xStg->Commit();
2480cdf0e10cSrcweir 
2481cdf0e10cSrcweir 			xStg = 0;
2482cdf0e10cSrcweir 		}
2483cdf0e10cSrcweir 	}
2484cdf0e10cSrcweir }
2485cdf0e10cSrcweir 
MakeUserStorage_Impl()2486cdf0e10cSrcweir void SvxAutoCorrectLanguageLists::MakeUserStorage_Impl()
2487cdf0e10cSrcweir {
2488cdf0e10cSrcweir 	// The conversion needs to happen if the file is already in the user
2489cdf0e10cSrcweir 	// directory and is in the old format. Additionally it needs to
2490cdf0e10cSrcweir 	// happen when the file is being copied from share to user.
2491cdf0e10cSrcweir 
2492cdf0e10cSrcweir 	sal_Bool bError = sal_False, bConvert = sal_False, bCopy = sal_False;
2493cdf0e10cSrcweir 	INetURLObject aDest;
2494cdf0e10cSrcweir 	INetURLObject aSource;
2495cdf0e10cSrcweir 
2496cdf0e10cSrcweir //	String sDestPath = sUserAutoCorrFile.Copy ( 0, sUserAutoCorrFile.Len()-3);
2497cdf0e10cSrcweir //	sDestPath.AppendAscii ("bak");
2498cdf0e10cSrcweir 
2499cdf0e10cSrcweir 
2500cdf0e10cSrcweir 	if (sUserAutoCorrFile != sShareAutoCorrFile )
2501cdf0e10cSrcweir 	{
2502cdf0e10cSrcweir 		aSource = INetURLObject ( sShareAutoCorrFile ); //aSource.setFSysPath ( sShareAutoCorrFile, INetURLObject::FSYS_DETECT );
2503cdf0e10cSrcweir 		aDest = INetURLObject ( sUserAutoCorrFile );
2504cdf0e10cSrcweir 		if ( SotStorage::IsOLEStorage ( sShareAutoCorrFile ) )
2505cdf0e10cSrcweir 		{
2506cdf0e10cSrcweir 			aDest.SetExtension ( String::CreateFromAscii ( "bak" ) );
2507cdf0e10cSrcweir 			bConvert = sal_True;
2508cdf0e10cSrcweir 		}
2509cdf0e10cSrcweir 		bCopy = sal_True;
2510cdf0e10cSrcweir 	}
2511cdf0e10cSrcweir 	else if ( SotStorage::IsOLEStorage ( sUserAutoCorrFile ) )
2512cdf0e10cSrcweir 	{
2513cdf0e10cSrcweir 		aSource = INetURLObject ( sUserAutoCorrFile );
2514cdf0e10cSrcweir 		aDest = INetURLObject ( sUserAutoCorrFile );
2515cdf0e10cSrcweir 		aDest.SetExtension ( String::CreateFromAscii ( "bak" ) );
2516cdf0e10cSrcweir 		bCopy = bConvert = sal_True;
2517cdf0e10cSrcweir 	}
2518cdf0e10cSrcweir 	if (bCopy)
2519cdf0e10cSrcweir 	{
2520cdf0e10cSrcweir 		try
2521cdf0e10cSrcweir 		{
2522cdf0e10cSrcweir 			String sMain(aDest.GetMainURL( INetURLObject::DECODE_TO_IURI ));
2523cdf0e10cSrcweir 			sal_Unicode cSlash = '/';
2524cdf0e10cSrcweir 			xub_StrLen nSlashPos = sMain.SearchBackward(cSlash);
2525cdf0e10cSrcweir 			sMain.Erase(nSlashPos);
2526cdf0e10cSrcweir 			::ucbhelper::Content aNewContent(	sMain, uno::Reference< XCommandEnvironment > ());
2527cdf0e10cSrcweir 			Any aAny;
2528cdf0e10cSrcweir 			TransferInfo aInfo;
2529cdf0e10cSrcweir 			aInfo.NameClash = NameClash::OVERWRITE;
2530cdf0e10cSrcweir 			aInfo.NewTitle  = aDest.GetName();
2531cdf0e10cSrcweir 			aInfo.SourceURL = aSource.GetMainURL( INetURLObject::DECODE_TO_IURI );
2532cdf0e10cSrcweir 			aInfo.MoveData  = sal_False;
2533cdf0e10cSrcweir 			aAny <<= aInfo;
2534cdf0e10cSrcweir 			aNewContent.executeCommand( OUString ( RTL_CONSTASCII_USTRINGPARAM( "transfer" ) ), aAny);
2535cdf0e10cSrcweir 		}
2536cdf0e10cSrcweir 		catch (...)
2537cdf0e10cSrcweir 		{
2538cdf0e10cSrcweir 			bError = sal_True;
2539cdf0e10cSrcweir 		}
2540cdf0e10cSrcweir 	}
2541cdf0e10cSrcweir 	if (bConvert && !bError)
2542cdf0e10cSrcweir 	{
2543cdf0e10cSrcweir         SotStorageRef xSrcStg = new SotStorage( aDest.GetMainURL( INetURLObject::DECODE_TO_IURI ), STREAM_READ, sal_True );
2544cdf0e10cSrcweir         SotStorageRef xDstStg = new SotStorage( sUserAutoCorrFile, STREAM_WRITE, sal_True );
2545cdf0e10cSrcweir 
2546cdf0e10cSrcweir 		if( xSrcStg.Is() && xDstStg.Is() )
2547cdf0e10cSrcweir 		{
2548cdf0e10cSrcweir 			String sWord 	    ( RTL_CONSTASCII_USTRINGPARAM ( pImplWrdStt_ExcptLstStr ) );
2549cdf0e10cSrcweir 			String sSentence    ( RTL_CONSTASCII_USTRINGPARAM ( pImplCplStt_ExcptLstStr ) );
2550cdf0e10cSrcweir 			String sXMLWord     ( RTL_CONSTASCII_USTRINGPARAM ( pXMLImplWrdStt_ExcptLstStr ) );
2551cdf0e10cSrcweir 			String sXMLSentence ( RTL_CONSTASCII_USTRINGPARAM ( pXMLImplCplStt_ExcptLstStr ) );
2552cdf0e10cSrcweir 			SvStringsISortDtor 	*pTmpWordList = NULL;
2553cdf0e10cSrcweir 
2554cdf0e10cSrcweir             if (xSrcStg->IsContained( sXMLWord ) )
2555cdf0e10cSrcweir 				LoadXMLExceptList_Imp( pTmpWordList, pXMLImplWrdStt_ExcptLstStr, xSrcStg );
2556cdf0e10cSrcweir 
2557cdf0e10cSrcweir 			if (pTmpWordList)
2558cdf0e10cSrcweir 			{
2559cdf0e10cSrcweir 				SaveExceptList_Imp( *pTmpWordList, pXMLImplWrdStt_ExcptLstStr, xDstStg, sal_True );
2560cdf0e10cSrcweir 		        pTmpWordList->DeleteAndDestroy( 0, pTmpWordList->Count() );
2561cdf0e10cSrcweir 				pTmpWordList = NULL;
2562cdf0e10cSrcweir 			}
2563cdf0e10cSrcweir 
2564cdf0e10cSrcweir 
2565cdf0e10cSrcweir             if (xSrcStg->IsContained( sXMLSentence ) )
2566cdf0e10cSrcweir 				LoadXMLExceptList_Imp( pTmpWordList, pXMLImplCplStt_ExcptLstStr, xSrcStg );
2567cdf0e10cSrcweir 
2568cdf0e10cSrcweir 			if (pTmpWordList)
2569cdf0e10cSrcweir             {
2570cdf0e10cSrcweir 				SaveExceptList_Imp( *pTmpWordList, pXMLImplCplStt_ExcptLstStr, xDstStg, sal_True );
2571cdf0e10cSrcweir 		        pTmpWordList->DeleteAndDestroy( 0, pTmpWordList->Count() );
2572cdf0e10cSrcweir             }
2573cdf0e10cSrcweir 
2574cdf0e10cSrcweir 			GetAutocorrWordList();
2575cdf0e10cSrcweir 			MakeBlocklist_Imp( *xDstStg );
2576cdf0e10cSrcweir 			// xDstStg is committed in MakeBlocklist_Imp
2577cdf0e10cSrcweir 			/*xSrcStg->CopyTo( &xDstStg );*/
2578cdf0e10cSrcweir 			sShareAutoCorrFile = sUserAutoCorrFile;
2579cdf0e10cSrcweir 			xDstStg = 0;
2580cdf0e10cSrcweir 			try
2581cdf0e10cSrcweir 			{
2582cdf0e10cSrcweir 				::ucbhelper::Content aContent ( aDest.GetMainURL( INetURLObject::DECODE_TO_IURI ), uno::Reference < XCommandEnvironment > ());
2583cdf0e10cSrcweir 				aContent.executeCommand ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "delete" ) ), makeAny ( sal_Bool (sal_True ) ) );
2584cdf0e10cSrcweir 			}
2585cdf0e10cSrcweir 			catch (...)
2586cdf0e10cSrcweir 			{
2587cdf0e10cSrcweir 			}
2588cdf0e10cSrcweir 		}
2589cdf0e10cSrcweir 	}
2590cdf0e10cSrcweir 	else if( bCopy && !bError )
2591cdf0e10cSrcweir 		sShareAutoCorrFile = sUserAutoCorrFile;
2592cdf0e10cSrcweir }
2593cdf0e10cSrcweir 
2594cdf0e10cSrcweir /* -----------------18.11.98 11:26-------------------
2595cdf0e10cSrcweir  *
2596cdf0e10cSrcweir  * --------------------------------------------------*/
MakeBlocklist_Imp(SvStorage & rStg)2597cdf0e10cSrcweir sal_Bool SvxAutoCorrectLanguageLists::MakeBlocklist_Imp( SvStorage& rStg )
2598cdf0e10cSrcweir {
2599cdf0e10cSrcweir 	String sStrmName( pXMLImplAutocorr_ListStr, RTL_TEXTENCODING_MS_1252 );
2600cdf0e10cSrcweir 	sal_Bool bRet = sal_True, bRemove = !pAutocorr_List || !pAutocorr_List->Count();
2601cdf0e10cSrcweir 	if( !bRemove )
2602cdf0e10cSrcweir 	{
2603cdf0e10cSrcweir 		/*
2604cdf0e10cSrcweir 		if ( rStg.IsContained( sStrmName) )
2605cdf0e10cSrcweir 		{
2606cdf0e10cSrcweir 			rStg.Remove ( sStrmName );
2607cdf0e10cSrcweir 			rStg.Commit();
2608cdf0e10cSrcweir 		}
2609cdf0e10cSrcweir 		*/
2610cdf0e10cSrcweir 		SvStorageStreamRef refList = rStg.OpenSotStream( sStrmName,
2611cdf0e10cSrcweir 					( STREAM_READ | STREAM_WRITE | STREAM_SHARE_DENYWRITE ) );
2612cdf0e10cSrcweir 		if( refList.Is() )
2613cdf0e10cSrcweir 		{
2614cdf0e10cSrcweir 			refList->SetSize( 0 );
2615cdf0e10cSrcweir 			refList->SetBufferSize( 8192 );
2616cdf0e10cSrcweir 			String aPropName( String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM("MediaType") ) );
2617cdf0e10cSrcweir 			OUString aMime( RTL_CONSTASCII_USTRINGPARAM("text/xml") );
2618cdf0e10cSrcweir 			uno::Any aAny;
2619cdf0e10cSrcweir 			aAny <<= aMime;
2620cdf0e10cSrcweir 			refList->SetProperty( aPropName, aAny );
2621cdf0e10cSrcweir 
2622cdf0e10cSrcweir 			uno::Reference< lang::XMultiServiceFactory > xServiceFactory =
2623cdf0e10cSrcweir 				comphelper::getProcessServiceFactory();
2624cdf0e10cSrcweir 			DBG_ASSERT( xServiceFactory.is(),
2625cdf0e10cSrcweir 						"XMLReader::Read: got no service manager" );
2626cdf0e10cSrcweir 			if( !xServiceFactory.is() )
2627cdf0e10cSrcweir 			{
2628cdf0e10cSrcweir 				// Throw an exception ?
2629cdf0e10cSrcweir 			}
2630cdf0e10cSrcweir 
2631cdf0e10cSrcweir    		 	uno::Reference < XInterface > xWriter (xServiceFactory->createInstance(
2632cdf0e10cSrcweir    		    	 OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.xml.sax.Writer"))));
2633cdf0e10cSrcweir    		 	DBG_ASSERT(xWriter.is(),"com.sun.star.xml.sax.Writer service missing");
2634cdf0e10cSrcweir 			uno::Reference < io::XOutputStream> xOut = new utl::OOutputStreamWrapper( *refList );
2635cdf0e10cSrcweir    		 	uno::Reference<io::XActiveDataSource> xSrc(xWriter, uno::UNO_QUERY);
2636cdf0e10cSrcweir    		 	xSrc->setOutputStream(xOut);
2637cdf0e10cSrcweir 
2638cdf0e10cSrcweir    		 	uno::Reference<xml::sax::XDocumentHandler> xHandler(xWriter, uno::UNO_QUERY);
2639cdf0e10cSrcweir 
2640cdf0e10cSrcweir 			// #110680#
2641cdf0e10cSrcweir    		 	// SvXMLAutoCorrectExport aExp(pAutocorr_List, sStrmName, xHandler);
2642cdf0e10cSrcweir    		 	SvXMLAutoCorrectExport aExp( xServiceFactory, pAutocorr_List, sStrmName, xHandler );
2643cdf0e10cSrcweir 
2644cdf0e10cSrcweir 			aExp.exportDoc( XML_BLOCK_LIST );
2645cdf0e10cSrcweir 
2646cdf0e10cSrcweir 			refList->Commit();
2647cdf0e10cSrcweir 			bRet = SVSTREAM_OK == refList->GetError();
2648cdf0e10cSrcweir 			if( bRet )
2649cdf0e10cSrcweir 			{
2650cdf0e10cSrcweir 				refList.Clear();
2651cdf0e10cSrcweir 				rStg.Commit();
2652cdf0e10cSrcweir 				if( SVSTREAM_OK != rStg.GetError() )
2653cdf0e10cSrcweir 				{
2654cdf0e10cSrcweir 					bRemove = sal_True;
2655cdf0e10cSrcweir 					bRet = sal_False;
2656cdf0e10cSrcweir 				}
2657cdf0e10cSrcweir 			}
2658cdf0e10cSrcweir 
2659cdf0e10cSrcweir 			/*
2660cdf0e10cSrcweir 			refList->SetSize( 0 );
2661cdf0e10cSrcweir 			refList->SetBufferSize( 8192 );
2662cdf0e10cSrcweir 			rtl_TextEncoding eEncoding = gsl_getSystemTextEncoding();
2663cdf0e10cSrcweir 
2664cdf0e10cSrcweir 			String aDummy;				// Erkennungszeichen fuer neue Streams
2665cdf0e10cSrcweir 			refList->WriteByteString( aDummy, RTL_TEXTENCODING_MS_1252 )
2666cdf0e10cSrcweir 					 << (sal_uInt8)	4		// Laenge des Headers (ohne den Leerstring)
2667cdf0e10cSrcweir 					 << (sal_uInt16)WORDLIST_VERSION_358	// Version des Streams
2668cdf0e10cSrcweir 					 << (sal_uInt8)eEncoding;				// der Zeichensatz
2669cdf0e10cSrcweir 
2670cdf0e10cSrcweir 			for( sal_uInt16 i = 0; i < pAutocorr_List->Count() &&
2671cdf0e10cSrcweir 								SVSTREAM_OK == refList->GetError(); ++i )
2672cdf0e10cSrcweir 			{
2673cdf0e10cSrcweir 				SvxAutocorrWord* p = pAutocorr_List->GetObject( i );
2674cdf0e10cSrcweir 				refList->WriteByteString( p->GetShort(), eEncoding ).
2675cdf0e10cSrcweir 						WriteByteString(  p->IsTextOnly()
2676cdf0e10cSrcweir 											? p->GetLong()
2677cdf0e10cSrcweir 											: p->GetShort(), eEncoding );
2678cdf0e10cSrcweir 			}
2679cdf0e10cSrcweir 			refList->Commit();
2680cdf0e10cSrcweir 			bRet = SVSTREAM_OK == refList->GetError();
2681cdf0e10cSrcweir 			if( bRet )
2682cdf0e10cSrcweir 			{
2683cdf0e10cSrcweir 				refList.Clear();
2684cdf0e10cSrcweir 				rStg.Commit();
2685cdf0e10cSrcweir 				if( SVSTREAM_OK != rStg.GetError() )
2686cdf0e10cSrcweir 				{
2687cdf0e10cSrcweir 					bRemove = sal_True;
2688cdf0e10cSrcweir 					bRet = sal_False;
2689cdf0e10cSrcweir 				}
2690cdf0e10cSrcweir 			}
2691cdf0e10cSrcweir 			*/
2692cdf0e10cSrcweir 		}
2693cdf0e10cSrcweir 		else
2694cdf0e10cSrcweir 			bRet = sal_False;
2695cdf0e10cSrcweir 	}
2696cdf0e10cSrcweir 
2697cdf0e10cSrcweir 	if( bRemove )
2698cdf0e10cSrcweir 	{
2699cdf0e10cSrcweir 		rStg.Remove( sStrmName );
2700cdf0e10cSrcweir 		rStg.Commit();
2701cdf0e10cSrcweir 	}
2702cdf0e10cSrcweir 
2703cdf0e10cSrcweir 	return bRet;
2704cdf0e10cSrcweir }
2705cdf0e10cSrcweir 
2706cdf0e10cSrcweir /* -----------------18.11.98 11:26-------------------
2707cdf0e10cSrcweir  *
2708cdf0e10cSrcweir  * --------------------------------------------------*/
PutText(const String & rShort,const String & rLong)2709cdf0e10cSrcweir sal_Bool SvxAutoCorrectLanguageLists::PutText( const String& rShort,
2710cdf0e10cSrcweir 										   const String& rLong )
2711cdf0e10cSrcweir {
2712cdf0e10cSrcweir 	// erstmal akt. Liste besorgen!
2713cdf0e10cSrcweir 	GetAutocorrWordList();
2714cdf0e10cSrcweir 
2715cdf0e10cSrcweir 	MakeUserStorage_Impl();
2716cdf0e10cSrcweir     SotStorageRef xStg = new SotStorage( sUserAutoCorrFile, STREAM_READWRITE, sal_True );
2717cdf0e10cSrcweir 
2718cdf0e10cSrcweir 	sal_Bool bRet = xStg.Is() && SVSTREAM_OK == xStg->GetError();
2719cdf0e10cSrcweir 
2720cdf0e10cSrcweir /*	if( bRet )
2721cdf0e10cSrcweir 	{
2722cdf0e10cSrcweir 		// PutText( *xStg, rShort );
2723cdf0e10cSrcweir 	}
2724cdf0e10cSrcweir */
2725cdf0e10cSrcweir 	// die Wortliste aktualisieren
2726cdf0e10cSrcweir 	if( bRet )
2727cdf0e10cSrcweir 	{
2728cdf0e10cSrcweir 		sal_uInt16 nPos;
2729cdf0e10cSrcweir 		SvxAutocorrWord* pNew = new SvxAutocorrWord( rShort, rLong, sal_True );
2730cdf0e10cSrcweir 		if( pAutocorr_List->Seek_Entry( pNew, &nPos ) )
2731cdf0e10cSrcweir 		{
2732cdf0e10cSrcweir 			if( !(*pAutocorr_List)[ nPos ]->IsTextOnly() )
2733cdf0e10cSrcweir 			{
2734cdf0e10cSrcweir 				// dann ist der Storage noch zu entfernen
2735cdf0e10cSrcweir 				String sStgNm( rShort );
2736cdf0e10cSrcweir 				if (xStg->IsOLEStorage())
2737cdf0e10cSrcweir 					EncryptBlockName_Imp( sStgNm );
2738cdf0e10cSrcweir 				else
2739cdf0e10cSrcweir 					GeneratePackageName ( rShort, sStgNm);
2740cdf0e10cSrcweir 
2741cdf0e10cSrcweir 				if( xStg->IsContained( sStgNm ) )
2742cdf0e10cSrcweir 					xStg->Remove( sStgNm );
2743cdf0e10cSrcweir 			}
2744cdf0e10cSrcweir 			pAutocorr_List->DeleteAndDestroy( nPos );
2745cdf0e10cSrcweir 		}
2746cdf0e10cSrcweir 
2747cdf0e10cSrcweir 		if( pAutocorr_List->Insert( pNew ) )
2748cdf0e10cSrcweir 		{
2749cdf0e10cSrcweir 			bRet = MakeBlocklist_Imp( *xStg );
2750cdf0e10cSrcweir 			xStg = 0;
2751cdf0e10cSrcweir 		}
2752cdf0e10cSrcweir 		else
2753cdf0e10cSrcweir 		{
2754cdf0e10cSrcweir 			delete pNew;
2755cdf0e10cSrcweir 			bRet = sal_False;
2756cdf0e10cSrcweir 		}
2757cdf0e10cSrcweir 	}
2758cdf0e10cSrcweir 	return bRet;
2759cdf0e10cSrcweir }
2760cdf0e10cSrcweir /* -----------------18.11.98 11:26-------------------
2761cdf0e10cSrcweir  *
2762cdf0e10cSrcweir  * --------------------------------------------------*/
2763cdf0e10cSrcweir 	//	- Text mit Attributierung (kann nur der SWG - SWG-Format!)
PutText(const String & rShort,SfxObjectShell & rShell)2764cdf0e10cSrcweir sal_Bool SvxAutoCorrectLanguageLists::PutText( const String& rShort,
2765cdf0e10cSrcweir 										SfxObjectShell& rShell )
2766cdf0e10cSrcweir {
2767cdf0e10cSrcweir 	// erstmal akt. Liste besorgen!
2768cdf0e10cSrcweir 	GetAutocorrWordList();
2769cdf0e10cSrcweir 
2770cdf0e10cSrcweir 	MakeUserStorage_Impl();
2771cdf0e10cSrcweir 
2772cdf0e10cSrcweir     sal_Bool bRet = sal_False;
2773cdf0e10cSrcweir 	String sLong;
2774cdf0e10cSrcweir     try
2775cdf0e10cSrcweir     {
2776cdf0e10cSrcweir         uno::Reference < embed::XStorage > xStg = comphelper::OStorageHelper::GetStorageFromURL( sUserAutoCorrFile, embed::ElementModes::READWRITE );
2777cdf0e10cSrcweir //		String aName( rShort );
2778cdf0e10cSrcweir //		EncryptBlockName_Imp( aName );
2779cdf0e10cSrcweir //		bRet = PutText( *xStg, aName, rShell, sLong );
2780cdf0e10cSrcweir         bRet = rAutoCorrect.PutText( xStg, sUserAutoCorrFile, rShort, rShell, sLong );
2781cdf0e10cSrcweir         xStg = 0;
2782cdf0e10cSrcweir 
2783cdf0e10cSrcweir         // die Wortliste aktualisieren
2784cdf0e10cSrcweir         if( bRet )
2785cdf0e10cSrcweir         {
2786cdf0e10cSrcweir             SvxAutocorrWord* pNew = new SvxAutocorrWord( rShort, sLong, sal_False );
2787cdf0e10cSrcweir             if( pAutocorr_List->Insert( pNew ) )
2788cdf0e10cSrcweir             {
2789cdf0e10cSrcweir                 SotStorageRef xStor = new SotStorage( sUserAutoCorrFile, STREAM_READWRITE, sal_True );
2790cdf0e10cSrcweir                 MakeBlocklist_Imp( *xStor );
2791cdf0e10cSrcweir             }
2792cdf0e10cSrcweir             else
2793cdf0e10cSrcweir                 delete pNew;
2794cdf0e10cSrcweir         }
2795cdf0e10cSrcweir     }
2796cdf0e10cSrcweir     catch ( uno::Exception& )
2797cdf0e10cSrcweir     {
2798cdf0e10cSrcweir     }
2799cdf0e10cSrcweir 
2800cdf0e10cSrcweir 	return bRet;
2801cdf0e10cSrcweir }
2802cdf0e10cSrcweir 
2803cdf0e10cSrcweir /* -----------------18.11.98 11:26-------------------
2804cdf0e10cSrcweir  *
2805cdf0e10cSrcweir  * --------------------------------------------------*/
2806cdf0e10cSrcweir 	//	- loesche einen Eintrag
DeleteText(const String & rShort)2807cdf0e10cSrcweir sal_Bool SvxAutoCorrectLanguageLists::DeleteText( const String& rShort )
2808cdf0e10cSrcweir {
2809cdf0e10cSrcweir 	// erstmal akt. Liste besorgen!
2810cdf0e10cSrcweir 	GetAutocorrWordList();
2811cdf0e10cSrcweir 
2812cdf0e10cSrcweir 	MakeUserStorage_Impl();
2813cdf0e10cSrcweir 
2814cdf0e10cSrcweir     SotStorageRef xStg = new SotStorage( sUserAutoCorrFile, STREAM_READWRITE, sal_True );
2815cdf0e10cSrcweir 	sal_Bool bRet = xStg.Is() && SVSTREAM_OK == xStg->GetError();
2816cdf0e10cSrcweir 	if( bRet )
2817cdf0e10cSrcweir 	{
2818cdf0e10cSrcweir 		sal_uInt16 nPos;
2819cdf0e10cSrcweir 		SvxAutocorrWord aTmp( rShort, rShort );
2820cdf0e10cSrcweir 		if( pAutocorr_List->Seek_Entry( &aTmp, &nPos ) )
2821cdf0e10cSrcweir 		{
2822cdf0e10cSrcweir 			SvxAutocorrWord* pFnd = (*pAutocorr_List)[ nPos ];
2823cdf0e10cSrcweir 			if( !pFnd->IsTextOnly() )
2824cdf0e10cSrcweir 			{
2825cdf0e10cSrcweir 				String aName( rShort );
2826cdf0e10cSrcweir 				if (xStg->IsOLEStorage())
2827cdf0e10cSrcweir 					EncryptBlockName_Imp( aName );
2828cdf0e10cSrcweir 				else
2829cdf0e10cSrcweir 					GeneratePackageName ( rShort, aName );
2830cdf0e10cSrcweir 				if( xStg->IsContained( aName ) )
2831cdf0e10cSrcweir 				{
2832cdf0e10cSrcweir 					xStg->Remove( aName );
2833cdf0e10cSrcweir 					bRet = xStg->Commit();
2834cdf0e10cSrcweir 				}
2835cdf0e10cSrcweir 
2836cdf0e10cSrcweir 			}
2837cdf0e10cSrcweir 			// die Wortliste aktualisieren
2838cdf0e10cSrcweir 			pAutocorr_List->DeleteAndDestroy( nPos );
2839cdf0e10cSrcweir 			MakeBlocklist_Imp( *xStg );
2840cdf0e10cSrcweir 			xStg = 0;
2841cdf0e10cSrcweir 		}
2842cdf0e10cSrcweir 		else
2843cdf0e10cSrcweir 			bRet = sal_False;
2844cdf0e10cSrcweir 	}
2845cdf0e10cSrcweir 	return bRet;
2846cdf0e10cSrcweir }
2847