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