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_linguistic.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <tools/debug.hxx> 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir #include <com/sun/star/linguistic2/LinguServiceEvent.hpp> 34*cdf0e10cSrcweir #include <com/sun/star/linguistic2/LinguServiceEventFlags.hpp> 35*cdf0e10cSrcweir #include <com/sun/star/linguistic2/XLinguServiceEventListener.hpp> 36*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 37*cdf0e10cSrcweir #include <osl/mutex.hxx> 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir #include <linguistic/misc.hxx> 40*cdf0e10cSrcweir #include <linguistic/lngprops.hxx> 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir #include <linguistic/lngprophelp.hxx> 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir //using namespace utl; 46*cdf0e10cSrcweir using namespace osl; 47*cdf0e10cSrcweir using namespace rtl; 48*cdf0e10cSrcweir using namespace com::sun::star; 49*cdf0e10cSrcweir using namespace com::sun::star::beans; 50*cdf0e10cSrcweir using namespace com::sun::star::lang; 51*cdf0e10cSrcweir using namespace com::sun::star::uno; 52*cdf0e10cSrcweir using namespace com::sun::star::linguistic2; 53*cdf0e10cSrcweir using namespace linguistic; 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir namespace linguistic 56*cdf0e10cSrcweir { 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir /////////////////////////////////////////////////////////////////////////// 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir static const char *aCH[] = 61*cdf0e10cSrcweir { 62*cdf0e10cSrcweir UPN_IS_IGNORE_CONTROL_CHARACTERS, 63*cdf0e10cSrcweir UPN_IS_USE_DICTIONARY_LIST, 64*cdf0e10cSrcweir }; 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir static int nCHCount = sizeof(aCH) / sizeof(aCH[0]); 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir PropertyChgHelper::PropertyChgHelper( 70*cdf0e10cSrcweir const Reference< XInterface > &rxSource, 71*cdf0e10cSrcweir Reference< XPropertySet > &rxPropSet, 72*cdf0e10cSrcweir int nAllowedEvents ) : 73*cdf0e10cSrcweir PropertyChgHelperBase(), 74*cdf0e10cSrcweir aPropNames (nCHCount), 75*cdf0e10cSrcweir xMyEvtObj (rxSource), 76*cdf0e10cSrcweir aLngSvcEvtListeners (GetLinguMutex()), 77*cdf0e10cSrcweir xPropSet (rxPropSet), 78*cdf0e10cSrcweir nEvtFlags (nAllowedEvents) 79*cdf0e10cSrcweir { 80*cdf0e10cSrcweir OUString *pName = aPropNames.getArray(); 81*cdf0e10cSrcweir for (sal_Int32 i = 0; i < nCHCount; ++i) 82*cdf0e10cSrcweir { 83*cdf0e10cSrcweir pName[i] = A2OU( aCH[i] ); 84*cdf0e10cSrcweir } 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir SetDefaultValues(); 87*cdf0e10cSrcweir } 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir PropertyChgHelper::PropertyChgHelper( const PropertyChgHelper &rHelper ) : 91*cdf0e10cSrcweir PropertyChgHelperBase(), 92*cdf0e10cSrcweir aLngSvcEvtListeners (GetLinguMutex()) 93*cdf0e10cSrcweir { 94*cdf0e10cSrcweir RemoveAsPropListener(); 95*cdf0e10cSrcweir aPropNames = rHelper.aPropNames; 96*cdf0e10cSrcweir xMyEvtObj = rHelper.xMyEvtObj; 97*cdf0e10cSrcweir xPropSet = rHelper.xPropSet; 98*cdf0e10cSrcweir nEvtFlags = rHelper.nEvtFlags; 99*cdf0e10cSrcweir AddAsPropListener(); 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir SetDefaultValues(); 102*cdf0e10cSrcweir GetCurrentValues(); 103*cdf0e10cSrcweir } 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir PropertyChgHelper::~PropertyChgHelper() 107*cdf0e10cSrcweir { 108*cdf0e10cSrcweir } 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir void PropertyChgHelper::AddPropNames( const char *pNewNames[], sal_Int32 nCount ) 112*cdf0e10cSrcweir { 113*cdf0e10cSrcweir if (pNewNames && nCount) 114*cdf0e10cSrcweir { 115*cdf0e10cSrcweir sal_Int32 nLen = GetPropNames().getLength(); 116*cdf0e10cSrcweir GetPropNames().realloc( nLen + nCount ); 117*cdf0e10cSrcweir OUString *pName = GetPropNames().getArray(); 118*cdf0e10cSrcweir for (sal_Int32 i = 0; i < nCount; ++i) 119*cdf0e10cSrcweir { 120*cdf0e10cSrcweir pName[ nLen + i ] = A2OU( pNewNames[ i ] ); 121*cdf0e10cSrcweir } 122*cdf0e10cSrcweir } 123*cdf0e10cSrcweir } 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir void PropertyChgHelper::SetDefaultValues() 127*cdf0e10cSrcweir { 128*cdf0e10cSrcweir bResIsIgnoreControlCharacters = bIsIgnoreControlCharacters = sal_True; 129*cdf0e10cSrcweir bResIsUseDictionaryList = bIsUseDictionaryList = sal_True; 130*cdf0e10cSrcweir } 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir void PropertyChgHelper::GetCurrentValues() 134*cdf0e10cSrcweir { 135*cdf0e10cSrcweir sal_Int32 nLen = GetPropNames().getLength(); 136*cdf0e10cSrcweir if (GetPropSet().is() && nLen) 137*cdf0e10cSrcweir { 138*cdf0e10cSrcweir const OUString *pPropName = GetPropNames().getConstArray(); 139*cdf0e10cSrcweir for (sal_Int32 i = 0; i < nLen; ++i) 140*cdf0e10cSrcweir { 141*cdf0e10cSrcweir sal_Bool *pbVal = NULL, 142*cdf0e10cSrcweir *pbResVal = NULL; 143*cdf0e10cSrcweir 144*cdf0e10cSrcweir if (pPropName[i].equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( UPN_IS_IGNORE_CONTROL_CHARACTERS ) )) 145*cdf0e10cSrcweir { 146*cdf0e10cSrcweir pbVal = &bIsIgnoreControlCharacters; 147*cdf0e10cSrcweir pbResVal = &bResIsIgnoreControlCharacters; 148*cdf0e10cSrcweir } 149*cdf0e10cSrcweir else if (pPropName[i].equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( UPN_IS_USE_DICTIONARY_LIST ) )) 150*cdf0e10cSrcweir { 151*cdf0e10cSrcweir pbVal = &bIsUseDictionaryList; 152*cdf0e10cSrcweir pbResVal = &bResIsUseDictionaryList; 153*cdf0e10cSrcweir } 154*cdf0e10cSrcweir 155*cdf0e10cSrcweir if (pbVal && pbResVal) 156*cdf0e10cSrcweir { 157*cdf0e10cSrcweir GetPropSet()->getPropertyValue( pPropName[i] ) >>= *pbVal; 158*cdf0e10cSrcweir *pbResVal = *pbVal; 159*cdf0e10cSrcweir } 160*cdf0e10cSrcweir } 161*cdf0e10cSrcweir } 162*cdf0e10cSrcweir } 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir void PropertyChgHelper::SetTmpPropVals( const PropertyValues &rPropVals ) 166*cdf0e10cSrcweir { 167*cdf0e10cSrcweir // return value is default value unless there is an explicitly supplied 168*cdf0e10cSrcweir // temporary value 169*cdf0e10cSrcweir bResIsIgnoreControlCharacters = bIsIgnoreControlCharacters; 170*cdf0e10cSrcweir bResIsUseDictionaryList = bIsUseDictionaryList; 171*cdf0e10cSrcweir // 172*cdf0e10cSrcweir sal_Int32 nLen = rPropVals.getLength(); 173*cdf0e10cSrcweir if (nLen) 174*cdf0e10cSrcweir { 175*cdf0e10cSrcweir const PropertyValue *pVal = rPropVals.getConstArray(); 176*cdf0e10cSrcweir for (sal_Int32 i = 0; i < nLen; ++i) 177*cdf0e10cSrcweir { 178*cdf0e10cSrcweir sal_Bool *pbResVal = NULL; 179*cdf0e10cSrcweir switch (pVal[i].Handle) 180*cdf0e10cSrcweir { 181*cdf0e10cSrcweir case UPH_IS_IGNORE_CONTROL_CHARACTERS : 182*cdf0e10cSrcweir pbResVal = &bResIsIgnoreControlCharacters; break; 183*cdf0e10cSrcweir case UPH_IS_USE_DICTIONARY_LIST : 184*cdf0e10cSrcweir pbResVal = &bResIsUseDictionaryList; break; 185*cdf0e10cSrcweir default: 186*cdf0e10cSrcweir ; 187*cdf0e10cSrcweir //DBG_ASSERT( 0, "unknown property" ); 188*cdf0e10cSrcweir } 189*cdf0e10cSrcweir if (pbResVal) 190*cdf0e10cSrcweir pVal[i].Value >>= *pbResVal; 191*cdf0e10cSrcweir } 192*cdf0e10cSrcweir } 193*cdf0e10cSrcweir } 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir 196*cdf0e10cSrcweir sal_Bool PropertyChgHelper::propertyChange_Impl( const PropertyChangeEvent& rEvt ) 197*cdf0e10cSrcweir { 198*cdf0e10cSrcweir sal_Bool bRes = sal_False; 199*cdf0e10cSrcweir 200*cdf0e10cSrcweir if (GetPropSet().is() && rEvt.Source == GetPropSet()) 201*cdf0e10cSrcweir { 202*cdf0e10cSrcweir sal_Int16 nLngSvcFlags = (nEvtFlags & AE_HYPHENATOR) ? 203*cdf0e10cSrcweir LinguServiceEventFlags::HYPHENATE_AGAIN : 0; 204*cdf0e10cSrcweir sal_Bool bSCWA = sal_False, // SPELL_CORRECT_WORDS_AGAIN ? 205*cdf0e10cSrcweir bSWWA = sal_False; // SPELL_WRONG_WORDS_AGAIN ? 206*cdf0e10cSrcweir 207*cdf0e10cSrcweir sal_Bool *pbVal = NULL; 208*cdf0e10cSrcweir switch (rEvt.PropertyHandle) 209*cdf0e10cSrcweir { 210*cdf0e10cSrcweir case UPH_IS_IGNORE_CONTROL_CHARACTERS : 211*cdf0e10cSrcweir { 212*cdf0e10cSrcweir pbVal = &bIsIgnoreControlCharacters; 213*cdf0e10cSrcweir nLngSvcFlags = 0; 214*cdf0e10cSrcweir break; 215*cdf0e10cSrcweir } 216*cdf0e10cSrcweir case UPH_IS_USE_DICTIONARY_LIST : 217*cdf0e10cSrcweir { 218*cdf0e10cSrcweir pbVal = &bIsUseDictionaryList; 219*cdf0e10cSrcweir bSCWA = bSWWA = sal_True; 220*cdf0e10cSrcweir break; 221*cdf0e10cSrcweir } 222*cdf0e10cSrcweir default: 223*cdf0e10cSrcweir { 224*cdf0e10cSrcweir bRes = sal_False; 225*cdf0e10cSrcweir //DBG_ASSERT( 0, "unknown property" ); 226*cdf0e10cSrcweir } 227*cdf0e10cSrcweir } 228*cdf0e10cSrcweir if (pbVal) 229*cdf0e10cSrcweir rEvt.NewValue >>= *pbVal; 230*cdf0e10cSrcweir 231*cdf0e10cSrcweir bRes = 0 != pbVal; // sth changed? 232*cdf0e10cSrcweir if (bRes) 233*cdf0e10cSrcweir { 234*cdf0e10cSrcweir sal_Bool bSpellEvts = (nEvtFlags & AE_SPELLCHECKER) ? sal_True : sal_False; 235*cdf0e10cSrcweir if (bSCWA && bSpellEvts) 236*cdf0e10cSrcweir nLngSvcFlags |= LinguServiceEventFlags::SPELL_CORRECT_WORDS_AGAIN; 237*cdf0e10cSrcweir if (bSWWA && bSpellEvts) 238*cdf0e10cSrcweir nLngSvcFlags |= LinguServiceEventFlags::SPELL_WRONG_WORDS_AGAIN; 239*cdf0e10cSrcweir if (nLngSvcFlags) 240*cdf0e10cSrcweir { 241*cdf0e10cSrcweir LinguServiceEvent aEvt( GetEvtObj(), nLngSvcFlags ); 242*cdf0e10cSrcweir LaunchEvent( aEvt ); 243*cdf0e10cSrcweir } 244*cdf0e10cSrcweir } 245*cdf0e10cSrcweir } 246*cdf0e10cSrcweir 247*cdf0e10cSrcweir return bRes; 248*cdf0e10cSrcweir } 249*cdf0e10cSrcweir 250*cdf0e10cSrcweir 251*cdf0e10cSrcweir void SAL_CALL 252*cdf0e10cSrcweir PropertyChgHelper::propertyChange( const PropertyChangeEvent& rEvt ) 253*cdf0e10cSrcweir throw(RuntimeException) 254*cdf0e10cSrcweir { 255*cdf0e10cSrcweir MutexGuard aGuard( GetLinguMutex() ); 256*cdf0e10cSrcweir propertyChange_Impl( rEvt ); 257*cdf0e10cSrcweir } 258*cdf0e10cSrcweir 259*cdf0e10cSrcweir 260*cdf0e10cSrcweir void PropertyChgHelper::AddAsPropListener() 261*cdf0e10cSrcweir { 262*cdf0e10cSrcweir if (xPropSet.is()) 263*cdf0e10cSrcweir { 264*cdf0e10cSrcweir sal_Int32 nLen = aPropNames.getLength(); 265*cdf0e10cSrcweir const OUString *pPropName = aPropNames.getConstArray(); 266*cdf0e10cSrcweir for (sal_Int32 i = 0; i < nLen; ++i) 267*cdf0e10cSrcweir { 268*cdf0e10cSrcweir if (pPropName[i].getLength()) 269*cdf0e10cSrcweir xPropSet->addPropertyChangeListener( pPropName[i], this ); 270*cdf0e10cSrcweir } 271*cdf0e10cSrcweir } 272*cdf0e10cSrcweir } 273*cdf0e10cSrcweir 274*cdf0e10cSrcweir void PropertyChgHelper::RemoveAsPropListener() 275*cdf0e10cSrcweir { 276*cdf0e10cSrcweir if (xPropSet.is()) 277*cdf0e10cSrcweir { 278*cdf0e10cSrcweir sal_Int32 nLen = aPropNames.getLength(); 279*cdf0e10cSrcweir const OUString *pPropName = aPropNames.getConstArray(); 280*cdf0e10cSrcweir for (sal_Int32 i = 0; i < nLen; ++i) 281*cdf0e10cSrcweir { 282*cdf0e10cSrcweir if (pPropName[i].getLength()) 283*cdf0e10cSrcweir xPropSet->removePropertyChangeListener( pPropName[i], this ); 284*cdf0e10cSrcweir } 285*cdf0e10cSrcweir } 286*cdf0e10cSrcweir } 287*cdf0e10cSrcweir 288*cdf0e10cSrcweir 289*cdf0e10cSrcweir void PropertyChgHelper::LaunchEvent( const LinguServiceEvent &rEvt ) 290*cdf0e10cSrcweir { 291*cdf0e10cSrcweir cppu::OInterfaceIteratorHelper aIt( aLngSvcEvtListeners ); 292*cdf0e10cSrcweir while (aIt.hasMoreElements()) 293*cdf0e10cSrcweir { 294*cdf0e10cSrcweir Reference< XLinguServiceEventListener > xRef( aIt.next(), UNO_QUERY ); 295*cdf0e10cSrcweir if (xRef.is()) 296*cdf0e10cSrcweir xRef->processLinguServiceEvent( rEvt ); 297*cdf0e10cSrcweir } 298*cdf0e10cSrcweir } 299*cdf0e10cSrcweir 300*cdf0e10cSrcweir 301*cdf0e10cSrcweir void SAL_CALL PropertyChgHelper::disposing( const EventObject& rSource ) 302*cdf0e10cSrcweir throw(RuntimeException) 303*cdf0e10cSrcweir { 304*cdf0e10cSrcweir MutexGuard aGuard( GetLinguMutex() ); 305*cdf0e10cSrcweir if (rSource.Source == xPropSet) 306*cdf0e10cSrcweir { 307*cdf0e10cSrcweir RemoveAsPropListener(); 308*cdf0e10cSrcweir xPropSet = NULL; 309*cdf0e10cSrcweir aPropNames.realloc( 0 ); 310*cdf0e10cSrcweir } 311*cdf0e10cSrcweir } 312*cdf0e10cSrcweir 313*cdf0e10cSrcweir 314*cdf0e10cSrcweir sal_Bool SAL_CALL 315*cdf0e10cSrcweir PropertyChgHelper::addLinguServiceEventListener( 316*cdf0e10cSrcweir const Reference< XLinguServiceEventListener >& rxListener ) 317*cdf0e10cSrcweir throw(RuntimeException) 318*cdf0e10cSrcweir { 319*cdf0e10cSrcweir MutexGuard aGuard( GetLinguMutex() ); 320*cdf0e10cSrcweir 321*cdf0e10cSrcweir sal_Bool bRes = sal_False; 322*cdf0e10cSrcweir if (rxListener.is()) 323*cdf0e10cSrcweir { 324*cdf0e10cSrcweir sal_Int32 nCount = aLngSvcEvtListeners.getLength(); 325*cdf0e10cSrcweir bRes = aLngSvcEvtListeners.addInterface( rxListener ) != nCount; 326*cdf0e10cSrcweir } 327*cdf0e10cSrcweir return bRes; 328*cdf0e10cSrcweir } 329*cdf0e10cSrcweir 330*cdf0e10cSrcweir 331*cdf0e10cSrcweir sal_Bool SAL_CALL 332*cdf0e10cSrcweir PropertyChgHelper::removeLinguServiceEventListener( 333*cdf0e10cSrcweir const Reference< XLinguServiceEventListener >& rxListener ) 334*cdf0e10cSrcweir throw(RuntimeException) 335*cdf0e10cSrcweir { 336*cdf0e10cSrcweir MutexGuard aGuard( GetLinguMutex() ); 337*cdf0e10cSrcweir 338*cdf0e10cSrcweir sal_Bool bRes = sal_False; 339*cdf0e10cSrcweir if (rxListener.is()) 340*cdf0e10cSrcweir { 341*cdf0e10cSrcweir sal_Int32 nCount = aLngSvcEvtListeners.getLength(); 342*cdf0e10cSrcweir bRes = aLngSvcEvtListeners.removeInterface( rxListener ) != nCount; 343*cdf0e10cSrcweir } 344*cdf0e10cSrcweir return bRes; 345*cdf0e10cSrcweir } 346*cdf0e10cSrcweir 347*cdf0e10cSrcweir /////////////////////////////////////////////////////////////////////////// 348*cdf0e10cSrcweir 349*cdf0e10cSrcweir 350*cdf0e10cSrcweir PropertyHelper_Thes::PropertyHelper_Thes( 351*cdf0e10cSrcweir const Reference< XInterface > &rxSource, 352*cdf0e10cSrcweir Reference< XPropertySet > &rxPropSet ) : 353*cdf0e10cSrcweir PropertyChgHelper ( rxSource, rxPropSet, 0 ) 354*cdf0e10cSrcweir { 355*cdf0e10cSrcweir SetDefaultValues(); 356*cdf0e10cSrcweir GetCurrentValues(); 357*cdf0e10cSrcweir } 358*cdf0e10cSrcweir 359*cdf0e10cSrcweir 360*cdf0e10cSrcweir PropertyHelper_Thes::~PropertyHelper_Thes() 361*cdf0e10cSrcweir { 362*cdf0e10cSrcweir } 363*cdf0e10cSrcweir 364*cdf0e10cSrcweir 365*cdf0e10cSrcweir void SAL_CALL 366*cdf0e10cSrcweir PropertyHelper_Thes::propertyChange( const PropertyChangeEvent& rEvt ) 367*cdf0e10cSrcweir throw(RuntimeException) 368*cdf0e10cSrcweir { 369*cdf0e10cSrcweir MutexGuard aGuard( GetLinguMutex() ); 370*cdf0e10cSrcweir PropertyChgHelper::propertyChange_Impl( rEvt ); 371*cdf0e10cSrcweir } 372*cdf0e10cSrcweir 373*cdf0e10cSrcweir 374*cdf0e10cSrcweir /////////////////////////////////////////////////////////////////////////// 375*cdf0e10cSrcweir 376*cdf0e10cSrcweir // list of properties from the property set to be used 377*cdf0e10cSrcweir // and listened to 378*cdf0e10cSrcweir static const char *aSP[] = 379*cdf0e10cSrcweir { 380*cdf0e10cSrcweir UPN_IS_SPELL_UPPER_CASE, 381*cdf0e10cSrcweir UPN_IS_SPELL_WITH_DIGITS, 382*cdf0e10cSrcweir UPN_IS_SPELL_CAPITALIZATION 383*cdf0e10cSrcweir }; 384*cdf0e10cSrcweir 385*cdf0e10cSrcweir 386*cdf0e10cSrcweir PropertyHelper_Spell::PropertyHelper_Spell( 387*cdf0e10cSrcweir const Reference< XInterface > & rxSource, 388*cdf0e10cSrcweir Reference< XPropertySet > &rxPropSet ) : 389*cdf0e10cSrcweir PropertyChgHelper ( rxSource, rxPropSet, AE_SPELLCHECKER ) 390*cdf0e10cSrcweir { 391*cdf0e10cSrcweir AddPropNames( aSP, sizeof(aSP) / sizeof(aSP[0]) ); 392*cdf0e10cSrcweir SetDefaultValues(); 393*cdf0e10cSrcweir GetCurrentValues(); 394*cdf0e10cSrcweir 395*cdf0e10cSrcweir nResMaxNumberOfSuggestions = GetDefaultNumberOfSuggestions(); 396*cdf0e10cSrcweir } 397*cdf0e10cSrcweir 398*cdf0e10cSrcweir 399*cdf0e10cSrcweir PropertyHelper_Spell::~PropertyHelper_Spell() 400*cdf0e10cSrcweir { 401*cdf0e10cSrcweir } 402*cdf0e10cSrcweir 403*cdf0e10cSrcweir 404*cdf0e10cSrcweir void PropertyHelper_Spell::SetDefaultValues() 405*cdf0e10cSrcweir { 406*cdf0e10cSrcweir PropertyChgHelper::SetDefaultValues(); 407*cdf0e10cSrcweir 408*cdf0e10cSrcweir bResIsSpellUpperCase = bIsSpellUpperCase = sal_False; 409*cdf0e10cSrcweir bResIsSpellWithDigits = bIsSpellWithDigits = sal_False; 410*cdf0e10cSrcweir bResIsSpellCapitalization = bIsSpellCapitalization = sal_True; 411*cdf0e10cSrcweir } 412*cdf0e10cSrcweir 413*cdf0e10cSrcweir 414*cdf0e10cSrcweir void PropertyHelper_Spell::GetCurrentValues() 415*cdf0e10cSrcweir { 416*cdf0e10cSrcweir PropertyChgHelper::GetCurrentValues(); 417*cdf0e10cSrcweir 418*cdf0e10cSrcweir sal_Int32 nLen = GetPropNames().getLength(); 419*cdf0e10cSrcweir if (GetPropSet().is() && nLen) 420*cdf0e10cSrcweir { 421*cdf0e10cSrcweir const OUString *pPropName = GetPropNames().getConstArray(); 422*cdf0e10cSrcweir for (sal_Int32 i = 0; i < nLen; ++i) 423*cdf0e10cSrcweir { 424*cdf0e10cSrcweir sal_Bool *pbVal = NULL, 425*cdf0e10cSrcweir *pbResVal = NULL; 426*cdf0e10cSrcweir 427*cdf0e10cSrcweir if (pPropName[i].equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( UPN_IS_SPELL_UPPER_CASE ) )) 428*cdf0e10cSrcweir { 429*cdf0e10cSrcweir pbVal = &bIsSpellUpperCase; 430*cdf0e10cSrcweir pbResVal = &bResIsSpellUpperCase; 431*cdf0e10cSrcweir } 432*cdf0e10cSrcweir else if (pPropName[i].equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( UPN_IS_SPELL_WITH_DIGITS ) )) 433*cdf0e10cSrcweir { 434*cdf0e10cSrcweir pbVal = &bIsSpellWithDigits; 435*cdf0e10cSrcweir pbResVal = &bResIsSpellWithDigits; 436*cdf0e10cSrcweir } 437*cdf0e10cSrcweir else if (pPropName[i].equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( UPN_IS_SPELL_CAPITALIZATION ) )) 438*cdf0e10cSrcweir { 439*cdf0e10cSrcweir pbVal = &bIsSpellCapitalization; 440*cdf0e10cSrcweir pbResVal = &bResIsSpellCapitalization; 441*cdf0e10cSrcweir } 442*cdf0e10cSrcweir 443*cdf0e10cSrcweir if (pbVal && pbResVal) 444*cdf0e10cSrcweir { 445*cdf0e10cSrcweir GetPropSet()->getPropertyValue( pPropName[i] ) >>= *pbVal; 446*cdf0e10cSrcweir *pbResVal = *pbVal; 447*cdf0e10cSrcweir } 448*cdf0e10cSrcweir } 449*cdf0e10cSrcweir } 450*cdf0e10cSrcweir } 451*cdf0e10cSrcweir 452*cdf0e10cSrcweir 453*cdf0e10cSrcweir sal_Bool PropertyHelper_Spell::propertyChange_Impl( const PropertyChangeEvent& rEvt ) 454*cdf0e10cSrcweir { 455*cdf0e10cSrcweir sal_Bool bRes = PropertyChgHelper::propertyChange_Impl( rEvt ); 456*cdf0e10cSrcweir 457*cdf0e10cSrcweir if (!bRes && GetPropSet().is() && rEvt.Source == GetPropSet()) 458*cdf0e10cSrcweir { 459*cdf0e10cSrcweir sal_Int16 nLngSvcFlags = 0; 460*cdf0e10cSrcweir sal_Bool bSCWA = sal_False, // SPELL_CORRECT_WORDS_AGAIN ? 461*cdf0e10cSrcweir bSWWA = sal_False; // SPELL_WRONG_WORDS_AGAIN ? 462*cdf0e10cSrcweir 463*cdf0e10cSrcweir sal_Bool *pbVal = NULL; 464*cdf0e10cSrcweir switch (rEvt.PropertyHandle) 465*cdf0e10cSrcweir { 466*cdf0e10cSrcweir case UPH_IS_SPELL_UPPER_CASE : 467*cdf0e10cSrcweir { 468*cdf0e10cSrcweir pbVal = &bIsSpellUpperCase; 469*cdf0e10cSrcweir bSCWA = sal_False == *pbVal; // sal_False->sal_True change? 470*cdf0e10cSrcweir bSWWA = !bSCWA; // sal_True->sal_False change? 471*cdf0e10cSrcweir break; 472*cdf0e10cSrcweir } 473*cdf0e10cSrcweir case UPH_IS_SPELL_WITH_DIGITS : 474*cdf0e10cSrcweir { 475*cdf0e10cSrcweir pbVal = &bIsSpellWithDigits; 476*cdf0e10cSrcweir bSCWA = sal_False == *pbVal; // sal_False->sal_True change? 477*cdf0e10cSrcweir bSWWA = !bSCWA; // sal_True->sal_False change? 478*cdf0e10cSrcweir break; 479*cdf0e10cSrcweir } 480*cdf0e10cSrcweir case UPH_IS_SPELL_CAPITALIZATION : 481*cdf0e10cSrcweir { 482*cdf0e10cSrcweir pbVal = &bIsSpellCapitalization; 483*cdf0e10cSrcweir bSCWA = sal_False == *pbVal; // sal_False->sal_True change? 484*cdf0e10cSrcweir bSWWA = !bSCWA; // sal_True->sal_False change? 485*cdf0e10cSrcweir break; 486*cdf0e10cSrcweir } 487*cdf0e10cSrcweir default: 488*cdf0e10cSrcweir DBG_ASSERT( 0, "unknown property" ); 489*cdf0e10cSrcweir } 490*cdf0e10cSrcweir if (pbVal) 491*cdf0e10cSrcweir rEvt.NewValue >>= *pbVal; 492*cdf0e10cSrcweir 493*cdf0e10cSrcweir bRes = (pbVal != 0); 494*cdf0e10cSrcweir if (bRes) 495*cdf0e10cSrcweir { 496*cdf0e10cSrcweir if (bSCWA) 497*cdf0e10cSrcweir nLngSvcFlags |= LinguServiceEventFlags::SPELL_CORRECT_WORDS_AGAIN; 498*cdf0e10cSrcweir if (bSWWA) 499*cdf0e10cSrcweir nLngSvcFlags |= LinguServiceEventFlags::SPELL_WRONG_WORDS_AGAIN; 500*cdf0e10cSrcweir if (nLngSvcFlags) 501*cdf0e10cSrcweir { 502*cdf0e10cSrcweir LinguServiceEvent aEvt( GetEvtObj(), nLngSvcFlags ); 503*cdf0e10cSrcweir LaunchEvent( aEvt ); 504*cdf0e10cSrcweir } 505*cdf0e10cSrcweir } 506*cdf0e10cSrcweir } 507*cdf0e10cSrcweir 508*cdf0e10cSrcweir return bRes; 509*cdf0e10cSrcweir } 510*cdf0e10cSrcweir 511*cdf0e10cSrcweir 512*cdf0e10cSrcweir void SAL_CALL 513*cdf0e10cSrcweir PropertyHelper_Spell::propertyChange( const PropertyChangeEvent& rEvt ) 514*cdf0e10cSrcweir throw(RuntimeException) 515*cdf0e10cSrcweir { 516*cdf0e10cSrcweir MutexGuard aGuard( GetLinguMutex() ); 517*cdf0e10cSrcweir propertyChange_Impl( rEvt ); 518*cdf0e10cSrcweir } 519*cdf0e10cSrcweir 520*cdf0e10cSrcweir 521*cdf0e10cSrcweir void PropertyHelper_Spell::SetTmpPropVals( const PropertyValues &rPropVals ) 522*cdf0e10cSrcweir { 523*cdf0e10cSrcweir PropertyChgHelper::SetTmpPropVals( rPropVals ); 524*cdf0e10cSrcweir 525*cdf0e10cSrcweir // return value is default value unless there is an explicitly supplied 526*cdf0e10cSrcweir // temporary value 527*cdf0e10cSrcweir nResMaxNumberOfSuggestions = GetDefaultNumberOfSuggestions(); 528*cdf0e10cSrcweir bResIsSpellWithDigits = bIsSpellWithDigits; 529*cdf0e10cSrcweir bResIsSpellCapitalization = bIsSpellCapitalization; 530*cdf0e10cSrcweir // 531*cdf0e10cSrcweir sal_Int32 nLen = rPropVals.getLength(); 532*cdf0e10cSrcweir if (nLen) 533*cdf0e10cSrcweir { 534*cdf0e10cSrcweir const PropertyValue *pVal = rPropVals.getConstArray(); 535*cdf0e10cSrcweir for (sal_Int32 i = 0; i < nLen; ++i) 536*cdf0e10cSrcweir { 537*cdf0e10cSrcweir if (pVal[i].Name.equalsAscii( UPN_MAX_NUMBER_OF_SUGGESTIONS )) 538*cdf0e10cSrcweir { 539*cdf0e10cSrcweir pVal[i].Value >>= nResMaxNumberOfSuggestions; 540*cdf0e10cSrcweir } 541*cdf0e10cSrcweir else 542*cdf0e10cSrcweir { 543*cdf0e10cSrcweir sal_Bool *pbResVal = NULL; 544*cdf0e10cSrcweir switch (pVal[i].Handle) 545*cdf0e10cSrcweir { 546*cdf0e10cSrcweir case UPH_IS_SPELL_UPPER_CASE : pbResVal = &bResIsSpellUpperCase; break; 547*cdf0e10cSrcweir case UPH_IS_SPELL_WITH_DIGITS : pbResVal = &bResIsSpellWithDigits; break; 548*cdf0e10cSrcweir case UPH_IS_SPELL_CAPITALIZATION : pbResVal = &bResIsSpellCapitalization; break; 549*cdf0e10cSrcweir default: 550*cdf0e10cSrcweir DBG_ASSERT( 0, "unknown property" ); 551*cdf0e10cSrcweir } 552*cdf0e10cSrcweir if (pbResVal) 553*cdf0e10cSrcweir pVal[i].Value >>= *pbResVal; 554*cdf0e10cSrcweir } 555*cdf0e10cSrcweir } 556*cdf0e10cSrcweir } 557*cdf0e10cSrcweir } 558*cdf0e10cSrcweir 559*cdf0e10cSrcweir sal_Int16 PropertyHelper_Spell::GetDefaultNumberOfSuggestions() const 560*cdf0e10cSrcweir { 561*cdf0e10cSrcweir return 16; 562*cdf0e10cSrcweir } 563*cdf0e10cSrcweir 564*cdf0e10cSrcweir /////////////////////////////////////////////////////////////////////////// 565*cdf0e10cSrcweir 566*cdf0e10cSrcweir static const char *aHP[] = 567*cdf0e10cSrcweir { 568*cdf0e10cSrcweir UPN_HYPH_MIN_LEADING, 569*cdf0e10cSrcweir UPN_HYPH_MIN_TRAILING, 570*cdf0e10cSrcweir UPN_HYPH_MIN_WORD_LENGTH 571*cdf0e10cSrcweir }; 572*cdf0e10cSrcweir 573*cdf0e10cSrcweir 574*cdf0e10cSrcweir PropertyHelper_Hyphen::PropertyHelper_Hyphen( 575*cdf0e10cSrcweir const Reference< XInterface > & rxSource, 576*cdf0e10cSrcweir Reference< XPropertySet > &rxPropSet ) : 577*cdf0e10cSrcweir PropertyChgHelper ( rxSource, rxPropSet, AE_HYPHENATOR ) 578*cdf0e10cSrcweir { 579*cdf0e10cSrcweir AddPropNames( aHP, sizeof(aHP) / sizeof(aHP[0]) ); 580*cdf0e10cSrcweir SetDefaultValues(); 581*cdf0e10cSrcweir GetCurrentValues(); 582*cdf0e10cSrcweir } 583*cdf0e10cSrcweir 584*cdf0e10cSrcweir 585*cdf0e10cSrcweir PropertyHelper_Hyphen::~PropertyHelper_Hyphen() 586*cdf0e10cSrcweir { 587*cdf0e10cSrcweir } 588*cdf0e10cSrcweir 589*cdf0e10cSrcweir 590*cdf0e10cSrcweir void PropertyHelper_Hyphen::SetDefaultValues() 591*cdf0e10cSrcweir { 592*cdf0e10cSrcweir PropertyChgHelper::SetDefaultValues(); 593*cdf0e10cSrcweir 594*cdf0e10cSrcweir nResHyphMinLeading = nHyphMinLeading = 2; 595*cdf0e10cSrcweir nResHyphMinTrailing = nHyphMinTrailing = 2; 596*cdf0e10cSrcweir nResHyphMinWordLength = nHyphMinWordLength = 0; 597*cdf0e10cSrcweir } 598*cdf0e10cSrcweir 599*cdf0e10cSrcweir 600*cdf0e10cSrcweir void PropertyHelper_Hyphen::GetCurrentValues() 601*cdf0e10cSrcweir { 602*cdf0e10cSrcweir PropertyChgHelper::GetCurrentValues(); 603*cdf0e10cSrcweir 604*cdf0e10cSrcweir sal_Int32 nLen = GetPropNames().getLength(); 605*cdf0e10cSrcweir if (GetPropSet().is() && nLen) 606*cdf0e10cSrcweir { 607*cdf0e10cSrcweir const OUString *pPropName = GetPropNames().getConstArray(); 608*cdf0e10cSrcweir for (sal_Int32 i = 0; i < nLen; ++i) 609*cdf0e10cSrcweir { 610*cdf0e10cSrcweir sal_Int16 *pnVal = NULL, 611*cdf0e10cSrcweir *pnResVal = NULL; 612*cdf0e10cSrcweir 613*cdf0e10cSrcweir if (pPropName[i].equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( UPN_HYPH_MIN_LEADING ) )) 614*cdf0e10cSrcweir { 615*cdf0e10cSrcweir pnVal = &nHyphMinLeading; 616*cdf0e10cSrcweir pnResVal = &nResHyphMinLeading; 617*cdf0e10cSrcweir } 618*cdf0e10cSrcweir else if (pPropName[i].equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( UPN_HYPH_MIN_TRAILING ) )) 619*cdf0e10cSrcweir { 620*cdf0e10cSrcweir pnVal = &nHyphMinTrailing; 621*cdf0e10cSrcweir pnResVal = &nResHyphMinTrailing; 622*cdf0e10cSrcweir } 623*cdf0e10cSrcweir else if (pPropName[i].equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( UPN_HYPH_MIN_WORD_LENGTH ) )) 624*cdf0e10cSrcweir { 625*cdf0e10cSrcweir pnVal = &nHyphMinWordLength; 626*cdf0e10cSrcweir pnResVal = &nResHyphMinWordLength; 627*cdf0e10cSrcweir } 628*cdf0e10cSrcweir 629*cdf0e10cSrcweir if (pnVal && pnResVal) 630*cdf0e10cSrcweir { 631*cdf0e10cSrcweir GetPropSet()->getPropertyValue( pPropName[i] ) >>= *pnVal; 632*cdf0e10cSrcweir *pnResVal = *pnVal; 633*cdf0e10cSrcweir } 634*cdf0e10cSrcweir } 635*cdf0e10cSrcweir } 636*cdf0e10cSrcweir } 637*cdf0e10cSrcweir 638*cdf0e10cSrcweir 639*cdf0e10cSrcweir sal_Bool PropertyHelper_Hyphen::propertyChange_Impl( const PropertyChangeEvent& rEvt ) 640*cdf0e10cSrcweir { 641*cdf0e10cSrcweir sal_Bool bRes = PropertyChgHelper::propertyChange_Impl( rEvt ); 642*cdf0e10cSrcweir 643*cdf0e10cSrcweir if (!bRes && GetPropSet().is() && rEvt.Source == GetPropSet()) 644*cdf0e10cSrcweir { 645*cdf0e10cSrcweir sal_Int16 nLngSvcFlags = LinguServiceEventFlags::HYPHENATE_AGAIN; 646*cdf0e10cSrcweir 647*cdf0e10cSrcweir sal_Int16 *pnVal = NULL; 648*cdf0e10cSrcweir switch (rEvt.PropertyHandle) 649*cdf0e10cSrcweir { 650*cdf0e10cSrcweir case UPH_HYPH_MIN_LEADING : pnVal = &nHyphMinLeading; break; 651*cdf0e10cSrcweir case UPH_HYPH_MIN_TRAILING : pnVal = &nHyphMinTrailing; break; 652*cdf0e10cSrcweir case UPH_HYPH_MIN_WORD_LENGTH : pnVal = &nHyphMinWordLength; break; 653*cdf0e10cSrcweir default: 654*cdf0e10cSrcweir DBG_ASSERT( 0, "unknown property" ); 655*cdf0e10cSrcweir } 656*cdf0e10cSrcweir if (pnVal) 657*cdf0e10cSrcweir rEvt.NewValue >>= *pnVal; 658*cdf0e10cSrcweir 659*cdf0e10cSrcweir bRes = (pnVal != 0); 660*cdf0e10cSrcweir if (bRes) 661*cdf0e10cSrcweir { 662*cdf0e10cSrcweir if (nLngSvcFlags) 663*cdf0e10cSrcweir { 664*cdf0e10cSrcweir LinguServiceEvent aEvt( GetEvtObj(), nLngSvcFlags ); 665*cdf0e10cSrcweir LaunchEvent( aEvt ); 666*cdf0e10cSrcweir } 667*cdf0e10cSrcweir } 668*cdf0e10cSrcweir } 669*cdf0e10cSrcweir 670*cdf0e10cSrcweir return bRes; 671*cdf0e10cSrcweir } 672*cdf0e10cSrcweir 673*cdf0e10cSrcweir 674*cdf0e10cSrcweir void SAL_CALL 675*cdf0e10cSrcweir PropertyHelper_Hyphen::propertyChange( const PropertyChangeEvent& rEvt ) 676*cdf0e10cSrcweir throw(RuntimeException) 677*cdf0e10cSrcweir { 678*cdf0e10cSrcweir MutexGuard aGuard( GetLinguMutex() ); 679*cdf0e10cSrcweir propertyChange_Impl( rEvt ); 680*cdf0e10cSrcweir } 681*cdf0e10cSrcweir 682*cdf0e10cSrcweir 683*cdf0e10cSrcweir void PropertyHelper_Hyphen::SetTmpPropVals( const PropertyValues &rPropVals ) 684*cdf0e10cSrcweir { 685*cdf0e10cSrcweir PropertyChgHelper::SetTmpPropVals( rPropVals ); 686*cdf0e10cSrcweir 687*cdf0e10cSrcweir // return value is default value unless there is an explicitly supplied 688*cdf0e10cSrcweir // temporary value 689*cdf0e10cSrcweir nResHyphMinLeading = nHyphMinLeading; 690*cdf0e10cSrcweir nResHyphMinTrailing = nHyphMinTrailing; 691*cdf0e10cSrcweir nResHyphMinWordLength = nHyphMinWordLength; 692*cdf0e10cSrcweir // 693*cdf0e10cSrcweir sal_Int32 nLen = rPropVals.getLength(); 694*cdf0e10cSrcweir if (nLen) 695*cdf0e10cSrcweir { 696*cdf0e10cSrcweir const PropertyValue *pVal = rPropVals.getConstArray(); 697*cdf0e10cSrcweir for (sal_Int32 i = 0; i < nLen; ++i) 698*cdf0e10cSrcweir { 699*cdf0e10cSrcweir sal_Int16 *pnResVal = NULL; 700*cdf0e10cSrcweir switch (pVal[i].Handle) 701*cdf0e10cSrcweir { 702*cdf0e10cSrcweir case UPH_HYPH_MIN_LEADING : pnResVal = &nResHyphMinLeading; break; 703*cdf0e10cSrcweir case UPH_HYPH_MIN_TRAILING : pnResVal = &nResHyphMinTrailing; break; 704*cdf0e10cSrcweir case UPH_HYPH_MIN_WORD_LENGTH : pnResVal = &nResHyphMinWordLength; break; 705*cdf0e10cSrcweir default: 706*cdf0e10cSrcweir DBG_ASSERT( 0, "unknown property" ); 707*cdf0e10cSrcweir } 708*cdf0e10cSrcweir if (pnResVal) 709*cdf0e10cSrcweir pVal[i].Value >>= *pnResVal; 710*cdf0e10cSrcweir } 711*cdf0e10cSrcweir } 712*cdf0e10cSrcweir } 713*cdf0e10cSrcweir 714*cdf0e10cSrcweir /////////////////////////////////////////////////////////////////////////// 715*cdf0e10cSrcweir 716*cdf0e10cSrcweir } // namespace linguistic 717*cdf0e10cSrcweir 718