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