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