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 <com/sun/star/registry/XRegistryKey.hpp> 32*cdf0e10cSrcweir #include <com/sun/star/container/XContentEnumerationAccess.hpp> 33*cdf0e10cSrcweir #include <com/sun/star/container/XEnumeration.hpp> 34*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp> 35*cdf0e10cSrcweir #include <com/sun/star/linguistic2/XSupportedLocales.hpp> 36*cdf0e10cSrcweir #include <com/sun/star/linguistic2/DictionaryListEventFlags.hpp> 37*cdf0e10cSrcweir #include <com/sun/star/linguistic2/LinguServiceEventFlags.hpp> 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir #include <tools/solar.h> 40*cdf0e10cSrcweir #include <unotools/lingucfg.hxx> 41*cdf0e10cSrcweir #include <unotools/processfactory.hxx> 42*cdf0e10cSrcweir #include <i18npool/lang.h> 43*cdf0e10cSrcweir #include <i18npool/mslangid.hxx> 44*cdf0e10cSrcweir #include <cppuhelper/factory.hxx> 45*cdf0e10cSrcweir #include <comphelper/extract.hxx> 46*cdf0e10cSrcweir #include <rtl/logfile.hxx> 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir #include <boost/checked_delete.hpp> 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir #include "lngsvcmgr.hxx" 51*cdf0e10cSrcweir #include "lngopt.hxx" 52*cdf0e10cSrcweir #include "linguistic/misc.hxx" 53*cdf0e10cSrcweir #include "spelldsp.hxx" 54*cdf0e10cSrcweir #include "hyphdsp.hxx" 55*cdf0e10cSrcweir #include "thesdsp.hxx" 56*cdf0e10cSrcweir #include "gciterator.hxx" 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir using namespace com::sun::star; 60*cdf0e10cSrcweir using namespace linguistic; 61*cdf0e10cSrcweir using ::rtl::OUString; 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir // forward declarations 64*cdf0e10cSrcweir uno::Sequence< OUString > static GetLangSvcList( const uno::Any &rVal ); 65*cdf0e10cSrcweir uno::Sequence< OUString > static GetLangSvc( const uno::Any &rVal ); 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir /////////////////////////////////////////////////////////////////////////// 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir static sal_Bool lcl_SeqHasString( const uno::Sequence< OUString > &rSeq, const OUString &rText ) 70*cdf0e10cSrcweir { 71*cdf0e10cSrcweir sal_Bool bRes = sal_False; 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir sal_Int32 nLen = rSeq.getLength(); 74*cdf0e10cSrcweir if (nLen == 0 || rText.getLength() == 0) 75*cdf0e10cSrcweir return bRes; 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir const OUString *pSeq = rSeq.getConstArray(); 78*cdf0e10cSrcweir for (sal_Int32 i = 0; i < nLen && !bRes; ++i) 79*cdf0e10cSrcweir { 80*cdf0e10cSrcweir if (rText == pSeq[i]) 81*cdf0e10cSrcweir bRes = sal_True; 82*cdf0e10cSrcweir } 83*cdf0e10cSrcweir return bRes; 84*cdf0e10cSrcweir } 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir /////////////////////////////////////////////////////////////////////////// 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir static uno::Sequence< lang::Locale > GetAvailLocales( 89*cdf0e10cSrcweir const uno::Sequence< OUString > &rSvcImplNames ) 90*cdf0e10cSrcweir { 91*cdf0e10cSrcweir uno::Sequence< lang::Locale > aRes; 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir uno::Reference< lang::XMultiServiceFactory > xFac( utl::getProcessServiceFactory() ); 94*cdf0e10cSrcweir sal_Int32 nNames = rSvcImplNames.getLength(); 95*cdf0e10cSrcweir if (nNames && xFac.is()) 96*cdf0e10cSrcweir { 97*cdf0e10cSrcweir std::set< LanguageType > aLanguages; 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir //! since we're going to create one-instance services we have to 100*cdf0e10cSrcweir //! supply their arguments even if we would not need them here... 101*cdf0e10cSrcweir uno::Sequence< uno::Any > aArgs(2); 102*cdf0e10cSrcweir aArgs.getArray()[0] <<= GetLinguProperties(); 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir // check all services for the supported languages and new 105*cdf0e10cSrcweir // languages to the result 106*cdf0e10cSrcweir const OUString *pImplNames = rSvcImplNames.getConstArray(); 107*cdf0e10cSrcweir sal_Int32 i; 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir for (i = 0; i < nNames; ++i) 110*cdf0e10cSrcweir { 111*cdf0e10cSrcweir uno::Reference< linguistic2::XSupportedLocales > xSuppLoc; 112*cdf0e10cSrcweir try 113*cdf0e10cSrcweir { 114*cdf0e10cSrcweir xSuppLoc = uno::Reference< linguistic2::XSupportedLocales >( 115*cdf0e10cSrcweir xFac->createInstanceWithArguments( pImplNames[i], aArgs ), uno::UNO_QUERY ); 116*cdf0e10cSrcweir } 117*cdf0e10cSrcweir catch (uno::Exception &) 118*cdf0e10cSrcweir { 119*cdf0e10cSrcweir DBG_ASSERT( 0, "createInstanceWithArguments failed" ); 120*cdf0e10cSrcweir } 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir if (xSuppLoc.is()) 123*cdf0e10cSrcweir { 124*cdf0e10cSrcweir uno::Sequence< lang::Locale > aLoc( xSuppLoc->getLocales() ); 125*cdf0e10cSrcweir sal_Int32 nLoc = aLoc.getLength(); 126*cdf0e10cSrcweir for (sal_Int32 k = 0; k < nLoc; ++k) 127*cdf0e10cSrcweir { 128*cdf0e10cSrcweir const lang::Locale *pLoc = aLoc.getConstArray(); 129*cdf0e10cSrcweir LanguageType nLang = LocaleToLanguage( pLoc[k] ); 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir // language not already added? 132*cdf0e10cSrcweir if (aLanguages.find( nLang ) == aLanguages.end()) 133*cdf0e10cSrcweir aLanguages.insert( nLang ); 134*cdf0e10cSrcweir } 135*cdf0e10cSrcweir } 136*cdf0e10cSrcweir else 137*cdf0e10cSrcweir { 138*cdf0e10cSrcweir DBG_ASSERT( 0, "interface not supported by service" ); 139*cdf0e10cSrcweir } 140*cdf0e10cSrcweir } 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir // build return sequence 143*cdf0e10cSrcweir sal_Int32 nLanguages = static_cast< sal_Int32 >(aLanguages.size()); 144*cdf0e10cSrcweir aRes.realloc( nLanguages ); 145*cdf0e10cSrcweir lang::Locale *pRes = aRes.getArray(); 146*cdf0e10cSrcweir std::set< LanguageType >::const_iterator aIt( aLanguages.begin() ); 147*cdf0e10cSrcweir for (i = 0; aIt != aLanguages.end(); ++aIt, ++i) 148*cdf0e10cSrcweir { 149*cdf0e10cSrcweir LanguageType nLang = *aIt; 150*cdf0e10cSrcweir pRes[i] = CreateLocale( nLang ); 151*cdf0e10cSrcweir } 152*cdf0e10cSrcweir } 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir return aRes; 155*cdf0e10cSrcweir } 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir /////////////////////////////////////////////////////////////////////////// 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir struct SvcInfo 160*cdf0e10cSrcweir { 161*cdf0e10cSrcweir const OUString aSvcImplName; 162*cdf0e10cSrcweir const uno::Sequence< sal_Int16 > aSuppLanguages; 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir SvcInfo( const OUString &rSvcImplName, 165*cdf0e10cSrcweir const uno::Sequence< sal_Int16 > &rSuppLanguages ) : 166*cdf0e10cSrcweir aSvcImplName (rSvcImplName), 167*cdf0e10cSrcweir aSuppLanguages (rSuppLanguages) 168*cdf0e10cSrcweir { 169*cdf0e10cSrcweir } 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir sal_Bool HasLanguage( sal_Int16 nLanguage ) const; 172*cdf0e10cSrcweir }; 173*cdf0e10cSrcweir 174*cdf0e10cSrcweir 175*cdf0e10cSrcweir sal_Bool SvcInfo::HasLanguage( sal_Int16 nLanguage ) const 176*cdf0e10cSrcweir { 177*cdf0e10cSrcweir sal_Int32 nCnt = aSuppLanguages.getLength(); 178*cdf0e10cSrcweir const sal_Int16 *pLang = aSuppLanguages.getConstArray(); 179*cdf0e10cSrcweir sal_Int32 i; 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir for ( i = 0; i < nCnt; ++i) 182*cdf0e10cSrcweir { 183*cdf0e10cSrcweir if (nLanguage == pLang[i]) 184*cdf0e10cSrcweir break; 185*cdf0e10cSrcweir } 186*cdf0e10cSrcweir return i < nCnt; 187*cdf0e10cSrcweir } 188*cdf0e10cSrcweir 189*cdf0e10cSrcweir 190*cdf0e10cSrcweir /////////////////////////////////////////////////////////////////////////// 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir 193*cdf0e10cSrcweir void LngSvcMgr::SetAvailableCfgServiceLists( LinguDispatcher &rDispatcher, 194*cdf0e10cSrcweir const SvcInfoArray &rAvailSvcs ) 195*cdf0e10cSrcweir { 196*cdf0e10cSrcweir // get list of nodenames to look at for their service list 197*cdf0e10cSrcweir const char *pEntryName = 0; 198*cdf0e10cSrcweir sal_Bool bHasLangSvcList = sal_True; 199*cdf0e10cSrcweir switch (rDispatcher.GetDspType()) 200*cdf0e10cSrcweir { 201*cdf0e10cSrcweir case LinguDispatcher::DSP_SPELL : pEntryName = "ServiceManager/SpellCheckerList"; break; 202*cdf0e10cSrcweir case LinguDispatcher::DSP_GRAMMAR : pEntryName = "ServiceManager/GrammarCheckerList"; 203*cdf0e10cSrcweir bHasLangSvcList = sal_False; 204*cdf0e10cSrcweir break; 205*cdf0e10cSrcweir case LinguDispatcher::DSP_HYPH : pEntryName = "ServiceManager/HyphenatorList"; 206*cdf0e10cSrcweir bHasLangSvcList = sal_False; 207*cdf0e10cSrcweir break; 208*cdf0e10cSrcweir case LinguDispatcher::DSP_THES : pEntryName = "ServiceManager/ThesaurusList"; break; 209*cdf0e10cSrcweir default : 210*cdf0e10cSrcweir DBG_ASSERT( 0, "unexpected case" ); 211*cdf0e10cSrcweir } 212*cdf0e10cSrcweir String aNode( String::CreateFromAscii( pEntryName ) ); 213*cdf0e10cSrcweir uno::Sequence < OUString > aNodeNames( /*aCfg.*/GetNodeNames( aNode ) ); 214*cdf0e10cSrcweir 215*cdf0e10cSrcweir 216*cdf0e10cSrcweir sal_Int32 nLen = aNodeNames.getLength(); 217*cdf0e10cSrcweir const OUString *pNodeNames = aNodeNames.getConstArray(); 218*cdf0e10cSrcweir for (sal_Int32 i = 0; i < nLen; ++i) 219*cdf0e10cSrcweir { 220*cdf0e10cSrcweir uno::Sequence< OUString > aSvcImplNames; 221*cdf0e10cSrcweir 222*cdf0e10cSrcweir uno::Sequence< OUString > aNames( 1 ); 223*cdf0e10cSrcweir OUString *pNames = aNames.getArray(); 224*cdf0e10cSrcweir 225*cdf0e10cSrcweir OUString aPropName( aNode ); 226*cdf0e10cSrcweir aPropName += OUString::valueOf( (sal_Unicode) '/' ); 227*cdf0e10cSrcweir aPropName += pNodeNames[i]; 228*cdf0e10cSrcweir pNames[0] = aPropName; 229*cdf0e10cSrcweir 230*cdf0e10cSrcweir uno::Sequence< uno::Any > aValues = /*aCfg.*/GetProperties( aNames ); 231*cdf0e10cSrcweir if (aValues.getLength()) 232*cdf0e10cSrcweir { 233*cdf0e10cSrcweir // get list of configured service names for the 234*cdf0e10cSrcweir // current node (language) 235*cdf0e10cSrcweir const uno::Any &rValue = aValues.getConstArray()[0]; 236*cdf0e10cSrcweir if (bHasLangSvcList) 237*cdf0e10cSrcweir aSvcImplNames = GetLangSvcList( rValue ); 238*cdf0e10cSrcweir else 239*cdf0e10cSrcweir aSvcImplNames = GetLangSvc( rValue ); 240*cdf0e10cSrcweir 241*cdf0e10cSrcweir sal_Int32 nSvcs = aSvcImplNames.getLength(); 242*cdf0e10cSrcweir if (nSvcs) 243*cdf0e10cSrcweir { 244*cdf0e10cSrcweir const OUString *pImplNames = aSvcImplNames.getConstArray(); 245*cdf0e10cSrcweir 246*cdf0e10cSrcweir LanguageType nLang = MsLangId::convertIsoStringToLanguage( pNodeNames[i] ); 247*cdf0e10cSrcweir 248*cdf0e10cSrcweir // build list of available services from those 249*cdf0e10cSrcweir sal_Int32 nCnt = 0; 250*cdf0e10cSrcweir uno::Sequence< OUString > aAvailSvcs( nSvcs ); 251*cdf0e10cSrcweir OUString *pAvailSvcs = aAvailSvcs.getArray(); 252*cdf0e10cSrcweir for (sal_Int32 k = 0; k < nSvcs; ++k) 253*cdf0e10cSrcweir { 254*cdf0e10cSrcweir // check for availability of the service 255*cdf0e10cSrcweir size_t nAvailSvcs = rAvailSvcs.size(); 256*cdf0e10cSrcweir for (size_t m = 0; m < nAvailSvcs; ++m) 257*cdf0e10cSrcweir { 258*cdf0e10cSrcweir const SvcInfo &rSvcInfo = *rAvailSvcs[m]; 259*cdf0e10cSrcweir if (rSvcInfo.aSvcImplName == pImplNames[k] && 260*cdf0e10cSrcweir rSvcInfo.HasLanguage( nLang )) 261*cdf0e10cSrcweir { 262*cdf0e10cSrcweir pAvailSvcs[ nCnt++ ] = rSvcInfo.aSvcImplName; 263*cdf0e10cSrcweir break; 264*cdf0e10cSrcweir } 265*cdf0e10cSrcweir } 266*cdf0e10cSrcweir } 267*cdf0e10cSrcweir 268*cdf0e10cSrcweir if (nCnt) 269*cdf0e10cSrcweir { 270*cdf0e10cSrcweir aAvailSvcs.realloc( nCnt ); 271*cdf0e10cSrcweir rDispatcher.SetServiceList( CreateLocale( nLang ), aAvailSvcs ); 272*cdf0e10cSrcweir } 273*cdf0e10cSrcweir } 274*cdf0e10cSrcweir } 275*cdf0e10cSrcweir } 276*cdf0e10cSrcweir } 277*cdf0e10cSrcweir 278*cdf0e10cSrcweir 279*cdf0e10cSrcweir /////////////////////////////////////////////////////////////////////////// 280*cdf0e10cSrcweir 281*cdf0e10cSrcweir 282*cdf0e10cSrcweir class LngSvcMgrListenerHelper : 283*cdf0e10cSrcweir public cppu::WeakImplHelper2 284*cdf0e10cSrcweir < 285*cdf0e10cSrcweir linguistic2::XLinguServiceEventListener, 286*cdf0e10cSrcweir linguistic2::XDictionaryListEventListener 287*cdf0e10cSrcweir > 288*cdf0e10cSrcweir { 289*cdf0e10cSrcweir LngSvcMgr &rMyManager; 290*cdf0e10cSrcweir // Timer aLaunchTimer; 291*cdf0e10cSrcweir 292*cdf0e10cSrcweir //cppu::OMultiTypeInterfaceContainerHelper aListeners; 293*cdf0e10cSrcweir ::cppu::OInterfaceContainerHelper aLngSvcMgrListeners; 294*cdf0e10cSrcweir ::cppu::OInterfaceContainerHelper aLngSvcEvtBroadcasters; 295*cdf0e10cSrcweir uno::Reference< linguistic2::XDictionaryList > xDicList; 296*cdf0e10cSrcweir uno::Reference< uno::XInterface > xMyEvtObj; 297*cdf0e10cSrcweir 298*cdf0e10cSrcweir sal_Int16 nCombinedLngSvcEvt; 299*cdf0e10cSrcweir 300*cdf0e10cSrcweir // disallow copy-constructor and assignment-operator for now 301*cdf0e10cSrcweir LngSvcMgrListenerHelper(const LngSvcMgrListenerHelper &); 302*cdf0e10cSrcweir LngSvcMgrListenerHelper & operator = (const LngSvcMgrListenerHelper &); 303*cdf0e10cSrcweir 304*cdf0e10cSrcweir void LaunchEvent( sal_Int16 nLngSvcEvtFlags ); 305*cdf0e10cSrcweir 306*cdf0e10cSrcweir // DECL_LINK( TimeOut, Timer* ); 307*cdf0e10cSrcweir long Timeout(); 308*cdf0e10cSrcweir 309*cdf0e10cSrcweir public: 310*cdf0e10cSrcweir LngSvcMgrListenerHelper( LngSvcMgr &rLngSvcMgr, 311*cdf0e10cSrcweir const uno::Reference< uno::XInterface > &rxSource, 312*cdf0e10cSrcweir const uno::Reference< linguistic2::XDictionaryList > &rxDicList ); 313*cdf0e10cSrcweir 314*cdf0e10cSrcweir // lang::XEventListener 315*cdf0e10cSrcweir virtual void SAL_CALL 316*cdf0e10cSrcweir disposing( const lang::EventObject& rSource ) 317*cdf0e10cSrcweir throw(uno::RuntimeException); 318*cdf0e10cSrcweir 319*cdf0e10cSrcweir // linguistic2::XLinguServiceEventListener 320*cdf0e10cSrcweir virtual void SAL_CALL 321*cdf0e10cSrcweir processLinguServiceEvent( const linguistic2::LinguServiceEvent& aLngSvcEvent ) 322*cdf0e10cSrcweir throw(uno::RuntimeException); 323*cdf0e10cSrcweir 324*cdf0e10cSrcweir // linguistic2::XDictionaryListEventListener 325*cdf0e10cSrcweir virtual void SAL_CALL 326*cdf0e10cSrcweir processDictionaryListEvent( 327*cdf0e10cSrcweir const linguistic2::DictionaryListEvent& rDicListEvent ) 328*cdf0e10cSrcweir throw(uno::RuntimeException); 329*cdf0e10cSrcweir 330*cdf0e10cSrcweir inline sal_Bool AddLngSvcMgrListener( 331*cdf0e10cSrcweir const uno::Reference< lang::XEventListener >& rxListener ); 332*cdf0e10cSrcweir inline sal_Bool RemoveLngSvcMgrListener( 333*cdf0e10cSrcweir const uno::Reference< lang::XEventListener >& rxListener ); 334*cdf0e10cSrcweir void DisposeAndClear( const lang::EventObject &rEvtObj ); 335*cdf0e10cSrcweir sal_Bool AddLngSvcEvtBroadcaster( 336*cdf0e10cSrcweir const uno::Reference< linguistic2::XLinguServiceEventBroadcaster > &rxBroadcaster ); 337*cdf0e10cSrcweir sal_Bool RemoveLngSvcEvtBroadcaster( 338*cdf0e10cSrcweir const uno::Reference< linguistic2::XLinguServiceEventBroadcaster > &rxBroadcaster ); 339*cdf0e10cSrcweir 340*cdf0e10cSrcweir void AddLngSvcEvt( sal_Int16 nLngSvcEvt ); 341*cdf0e10cSrcweir }; 342*cdf0e10cSrcweir 343*cdf0e10cSrcweir 344*cdf0e10cSrcweir LngSvcMgrListenerHelper::LngSvcMgrListenerHelper( 345*cdf0e10cSrcweir LngSvcMgr &rLngSvcMgr, 346*cdf0e10cSrcweir const uno::Reference< uno::XInterface > &rxSource, 347*cdf0e10cSrcweir const uno::Reference< linguistic2::XDictionaryList > &rxDicList ) : 348*cdf0e10cSrcweir rMyManager ( rLngSvcMgr ), 349*cdf0e10cSrcweir aLngSvcMgrListeners ( GetLinguMutex() ), 350*cdf0e10cSrcweir aLngSvcEvtBroadcasters ( GetLinguMutex() ), 351*cdf0e10cSrcweir xDicList ( rxDicList ), 352*cdf0e10cSrcweir xMyEvtObj ( rxSource ) 353*cdf0e10cSrcweir { 354*cdf0e10cSrcweir if (xDicList.is()) 355*cdf0e10cSrcweir { 356*cdf0e10cSrcweir xDicList->addDictionaryListEventListener( 357*cdf0e10cSrcweir (linguistic2::XDictionaryListEventListener *) this, sal_False ); 358*cdf0e10cSrcweir } 359*cdf0e10cSrcweir 360*cdf0e10cSrcweir //! The timer is used to 'sum up' different events in order to reduce the 361*cdf0e10cSrcweir //! number of events forwarded. 362*cdf0e10cSrcweir //! (This may happen already if a property was changed that has several 363*cdf0e10cSrcweir //! listeners, and each of them is launching an event of it's own!) 364*cdf0e10cSrcweir //! Thus this behaviour is necessary to avoid unecessary actions of 365*cdf0e10cSrcweir //! this objects listeners! 366*cdf0e10cSrcweir // aLaunchTimer.SetTimeout( 2000 ); 367*cdf0e10cSrcweir // aLaunchTimer.SetTimeoutHdl( LINK( this, LngSvcMgrListenerHelper, TimeOut ) ); 368*cdf0e10cSrcweir nCombinedLngSvcEvt = 0; 369*cdf0e10cSrcweir } 370*cdf0e10cSrcweir 371*cdf0e10cSrcweir 372*cdf0e10cSrcweir void SAL_CALL LngSvcMgrListenerHelper::disposing( const lang::EventObject& rSource ) 373*cdf0e10cSrcweir throw(uno::RuntimeException) 374*cdf0e10cSrcweir { 375*cdf0e10cSrcweir osl::MutexGuard aGuard( GetLinguMutex() ); 376*cdf0e10cSrcweir 377*cdf0e10cSrcweir uno::Reference< uno::XInterface > xRef( rSource.Source ); 378*cdf0e10cSrcweir if ( xRef.is() ) 379*cdf0e10cSrcweir { 380*cdf0e10cSrcweir aLngSvcMgrListeners .removeInterface( xRef ); 381*cdf0e10cSrcweir aLngSvcEvtBroadcasters.removeInterface( xRef ); 382*cdf0e10cSrcweir if (xDicList == xRef) 383*cdf0e10cSrcweir xDicList = 0; 384*cdf0e10cSrcweir } 385*cdf0e10cSrcweir } 386*cdf0e10cSrcweir 387*cdf0e10cSrcweir 388*cdf0e10cSrcweir //IMPL_LINK( LngSvcMgrListenerHelper, TimeOut, Timer*, pTimer ) 389*cdf0e10cSrcweir long LngSvcMgrListenerHelper::Timeout() 390*cdf0e10cSrcweir { 391*cdf0e10cSrcweir osl::MutexGuard aGuard( GetLinguMutex() ); 392*cdf0e10cSrcweir 393*cdf0e10cSrcweir // if (&aLaunchTimer == pTimer) 394*cdf0e10cSrcweir { 395*cdf0e10cSrcweir // change event source to LinguServiceManager since the listeners 396*cdf0e10cSrcweir // probably do not know (and need not to know) about the specific 397*cdf0e10cSrcweir // SpellChecker's or Hyphenator's. 398*cdf0e10cSrcweir linguistic2::LinguServiceEvent aEvtObj( xMyEvtObj, nCombinedLngSvcEvt ); 399*cdf0e10cSrcweir nCombinedLngSvcEvt = 0; 400*cdf0e10cSrcweir 401*cdf0e10cSrcweir if (rMyManager.pSpellDsp) 402*cdf0e10cSrcweir rMyManager.pSpellDsp->FlushSpellCache(); 403*cdf0e10cSrcweir 404*cdf0e10cSrcweir // pass event on to linguistic2::XLinguServiceEventListener's 405*cdf0e10cSrcweir cppu::OInterfaceIteratorHelper aIt( aLngSvcMgrListeners ); 406*cdf0e10cSrcweir while (aIt.hasMoreElements()) 407*cdf0e10cSrcweir { 408*cdf0e10cSrcweir uno::Reference< linguistic2::XLinguServiceEventListener > xRef( aIt.next(), uno::UNO_QUERY ); 409*cdf0e10cSrcweir if (xRef.is()) 410*cdf0e10cSrcweir xRef->processLinguServiceEvent( aEvtObj ); 411*cdf0e10cSrcweir } 412*cdf0e10cSrcweir } 413*cdf0e10cSrcweir return 0; 414*cdf0e10cSrcweir } 415*cdf0e10cSrcweir 416*cdf0e10cSrcweir 417*cdf0e10cSrcweir void LngSvcMgrListenerHelper::AddLngSvcEvt( sal_Int16 nLngSvcEvt ) 418*cdf0e10cSrcweir { 419*cdf0e10cSrcweir nCombinedLngSvcEvt |= nLngSvcEvt; 420*cdf0e10cSrcweir // aLaunchTimer.Start(); 421*cdf0e10cSrcweir Timeout(); 422*cdf0e10cSrcweir } 423*cdf0e10cSrcweir 424*cdf0e10cSrcweir 425*cdf0e10cSrcweir void SAL_CALL 426*cdf0e10cSrcweir LngSvcMgrListenerHelper::processLinguServiceEvent( 427*cdf0e10cSrcweir const linguistic2::LinguServiceEvent& rLngSvcEvent ) 428*cdf0e10cSrcweir throw(uno::RuntimeException) 429*cdf0e10cSrcweir { 430*cdf0e10cSrcweir osl::MutexGuard aGuard( GetLinguMutex() ); 431*cdf0e10cSrcweir AddLngSvcEvt( rLngSvcEvent.nEvent ); 432*cdf0e10cSrcweir } 433*cdf0e10cSrcweir 434*cdf0e10cSrcweir 435*cdf0e10cSrcweir void SAL_CALL 436*cdf0e10cSrcweir LngSvcMgrListenerHelper::processDictionaryListEvent( 437*cdf0e10cSrcweir const linguistic2::DictionaryListEvent& rDicListEvent ) 438*cdf0e10cSrcweir throw(uno::RuntimeException) 439*cdf0e10cSrcweir { 440*cdf0e10cSrcweir osl::MutexGuard aGuard( GetLinguMutex() ); 441*cdf0e10cSrcweir 442*cdf0e10cSrcweir sal_Int16 nDlEvt = rDicListEvent.nCondensedEvent; 443*cdf0e10cSrcweir if (0 == nDlEvt) 444*cdf0e10cSrcweir return; 445*cdf0e10cSrcweir 446*cdf0e10cSrcweir // we do keep the original event source here though... 447*cdf0e10cSrcweir 448*cdf0e10cSrcweir // pass event on to linguistic2::XDictionaryListEventListener's 449*cdf0e10cSrcweir cppu::OInterfaceIteratorHelper aIt( aLngSvcMgrListeners ); 450*cdf0e10cSrcweir while (aIt.hasMoreElements()) 451*cdf0e10cSrcweir { 452*cdf0e10cSrcweir uno::Reference< linguistic2::XDictionaryListEventListener > xRef( aIt.next(), uno::UNO_QUERY ); 453*cdf0e10cSrcweir if (xRef.is()) 454*cdf0e10cSrcweir xRef->processDictionaryListEvent( rDicListEvent ); 455*cdf0e10cSrcweir } 456*cdf0e10cSrcweir 457*cdf0e10cSrcweir // 458*cdf0e10cSrcweir // "translate" DictionaryList event into linguistic2::LinguServiceEvent 459*cdf0e10cSrcweir // 460*cdf0e10cSrcweir sal_Int16 nLngSvcEvt = 0; 461*cdf0e10cSrcweir // 462*cdf0e10cSrcweir sal_Int16 nSpellCorrectFlags = 463*cdf0e10cSrcweir linguistic2::DictionaryListEventFlags::ADD_NEG_ENTRY | 464*cdf0e10cSrcweir linguistic2::DictionaryListEventFlags::DEL_POS_ENTRY | 465*cdf0e10cSrcweir linguistic2::DictionaryListEventFlags::ACTIVATE_NEG_DIC | 466*cdf0e10cSrcweir linguistic2::DictionaryListEventFlags::DEACTIVATE_POS_DIC; 467*cdf0e10cSrcweir if (0 != (nDlEvt & nSpellCorrectFlags)) 468*cdf0e10cSrcweir nLngSvcEvt |= linguistic2::LinguServiceEventFlags::SPELL_CORRECT_WORDS_AGAIN; 469*cdf0e10cSrcweir // 470*cdf0e10cSrcweir sal_Int16 nSpellWrongFlags = 471*cdf0e10cSrcweir linguistic2::DictionaryListEventFlags::ADD_POS_ENTRY | 472*cdf0e10cSrcweir linguistic2::DictionaryListEventFlags::DEL_NEG_ENTRY | 473*cdf0e10cSrcweir linguistic2::DictionaryListEventFlags::ACTIVATE_POS_DIC | 474*cdf0e10cSrcweir linguistic2::DictionaryListEventFlags::DEACTIVATE_NEG_DIC; 475*cdf0e10cSrcweir if (0 != (nDlEvt & nSpellWrongFlags)) 476*cdf0e10cSrcweir nLngSvcEvt |= linguistic2::LinguServiceEventFlags::SPELL_WRONG_WORDS_AGAIN; 477*cdf0e10cSrcweir // 478*cdf0e10cSrcweir sal_Int16 nHyphenateFlags = 479*cdf0e10cSrcweir linguistic2::DictionaryListEventFlags::ADD_POS_ENTRY | 480*cdf0e10cSrcweir linguistic2::DictionaryListEventFlags::DEL_POS_ENTRY | 481*cdf0e10cSrcweir linguistic2::DictionaryListEventFlags::ACTIVATE_POS_DIC | 482*cdf0e10cSrcweir linguistic2::DictionaryListEventFlags::ACTIVATE_NEG_DIC; 483*cdf0e10cSrcweir if (0 != (nDlEvt & nHyphenateFlags)) 484*cdf0e10cSrcweir nLngSvcEvt |= linguistic2::LinguServiceEventFlags::HYPHENATE_AGAIN; 485*cdf0e10cSrcweir 486*cdf0e10cSrcweir if (rMyManager.pSpellDsp) 487*cdf0e10cSrcweir rMyManager.pSpellDsp->FlushSpellCache(); 488*cdf0e10cSrcweir if (nLngSvcEvt) 489*cdf0e10cSrcweir LaunchEvent( nLngSvcEvt ); 490*cdf0e10cSrcweir } 491*cdf0e10cSrcweir 492*cdf0e10cSrcweir 493*cdf0e10cSrcweir void LngSvcMgrListenerHelper::LaunchEvent( sal_Int16 nLngSvcEvtFlags ) 494*cdf0e10cSrcweir { 495*cdf0e10cSrcweir linguistic2::LinguServiceEvent aEvt( xMyEvtObj, nLngSvcEvtFlags ); 496*cdf0e10cSrcweir 497*cdf0e10cSrcweir // pass event on to linguistic2::XLinguServiceEventListener's 498*cdf0e10cSrcweir cppu::OInterfaceIteratorHelper aIt( aLngSvcMgrListeners ); 499*cdf0e10cSrcweir while (aIt.hasMoreElements()) 500*cdf0e10cSrcweir { 501*cdf0e10cSrcweir uno::Reference< linguistic2::XLinguServiceEventListener > xRef( aIt.next(), uno::UNO_QUERY ); 502*cdf0e10cSrcweir if (xRef.is()) 503*cdf0e10cSrcweir xRef->processLinguServiceEvent( aEvt ); 504*cdf0e10cSrcweir } 505*cdf0e10cSrcweir } 506*cdf0e10cSrcweir 507*cdf0e10cSrcweir 508*cdf0e10cSrcweir inline sal_Bool LngSvcMgrListenerHelper::AddLngSvcMgrListener( 509*cdf0e10cSrcweir const uno::Reference< lang::XEventListener >& rxListener ) 510*cdf0e10cSrcweir { 511*cdf0e10cSrcweir aLngSvcMgrListeners.addInterface( rxListener ); 512*cdf0e10cSrcweir return sal_True; 513*cdf0e10cSrcweir } 514*cdf0e10cSrcweir 515*cdf0e10cSrcweir 516*cdf0e10cSrcweir inline sal_Bool LngSvcMgrListenerHelper::RemoveLngSvcMgrListener( 517*cdf0e10cSrcweir const uno::Reference< lang::XEventListener >& rxListener ) 518*cdf0e10cSrcweir { 519*cdf0e10cSrcweir aLngSvcMgrListeners.removeInterface( rxListener ); 520*cdf0e10cSrcweir return sal_True; 521*cdf0e10cSrcweir } 522*cdf0e10cSrcweir 523*cdf0e10cSrcweir 524*cdf0e10cSrcweir void LngSvcMgrListenerHelper::DisposeAndClear( const lang::EventObject &rEvtObj ) 525*cdf0e10cSrcweir { 526*cdf0e10cSrcweir // call "disposing" for all listeners and clear list 527*cdf0e10cSrcweir aLngSvcMgrListeners .disposeAndClear( rEvtObj ); 528*cdf0e10cSrcweir 529*cdf0e10cSrcweir // remove references to this object hold by the broadcasters 530*cdf0e10cSrcweir cppu::OInterfaceIteratorHelper aIt( aLngSvcEvtBroadcasters ); 531*cdf0e10cSrcweir while (aIt.hasMoreElements()) 532*cdf0e10cSrcweir { 533*cdf0e10cSrcweir uno::Reference< linguistic2::XLinguServiceEventBroadcaster > xRef( aIt.next(), uno::UNO_QUERY ); 534*cdf0e10cSrcweir if (xRef.is()) 535*cdf0e10cSrcweir RemoveLngSvcEvtBroadcaster( xRef ); 536*cdf0e10cSrcweir } 537*cdf0e10cSrcweir 538*cdf0e10cSrcweir // remove refernce to this object hold by the dictionary-list 539*cdf0e10cSrcweir if (xDicList.is()) 540*cdf0e10cSrcweir { 541*cdf0e10cSrcweir xDicList->removeDictionaryListEventListener( 542*cdf0e10cSrcweir (linguistic2::XDictionaryListEventListener *) this ); 543*cdf0e10cSrcweir xDicList = 0; 544*cdf0e10cSrcweir } 545*cdf0e10cSrcweir } 546*cdf0e10cSrcweir 547*cdf0e10cSrcweir 548*cdf0e10cSrcweir sal_Bool LngSvcMgrListenerHelper::AddLngSvcEvtBroadcaster( 549*cdf0e10cSrcweir const uno::Reference< linguistic2::XLinguServiceEventBroadcaster > &rxBroadcaster ) 550*cdf0e10cSrcweir { 551*cdf0e10cSrcweir sal_Bool bRes = sal_False; 552*cdf0e10cSrcweir if (rxBroadcaster.is()) 553*cdf0e10cSrcweir { 554*cdf0e10cSrcweir aLngSvcEvtBroadcasters.addInterface( rxBroadcaster ); 555*cdf0e10cSrcweir rxBroadcaster->addLinguServiceEventListener( 556*cdf0e10cSrcweir (linguistic2::XLinguServiceEventListener *) this ); 557*cdf0e10cSrcweir } 558*cdf0e10cSrcweir return bRes; 559*cdf0e10cSrcweir } 560*cdf0e10cSrcweir 561*cdf0e10cSrcweir 562*cdf0e10cSrcweir sal_Bool LngSvcMgrListenerHelper::RemoveLngSvcEvtBroadcaster( 563*cdf0e10cSrcweir const uno::Reference< linguistic2::XLinguServiceEventBroadcaster > &rxBroadcaster ) 564*cdf0e10cSrcweir { 565*cdf0e10cSrcweir sal_Bool bRes = sal_False; 566*cdf0e10cSrcweir if (rxBroadcaster.is()) 567*cdf0e10cSrcweir { 568*cdf0e10cSrcweir aLngSvcEvtBroadcasters.removeInterface( rxBroadcaster ); 569*cdf0e10cSrcweir rxBroadcaster->removeLinguServiceEventListener( 570*cdf0e10cSrcweir (linguistic2::XLinguServiceEventListener *) this ); 571*cdf0e10cSrcweir } 572*cdf0e10cSrcweir return bRes; 573*cdf0e10cSrcweir } 574*cdf0e10cSrcweir 575*cdf0e10cSrcweir 576*cdf0e10cSrcweir /////////////////////////////////////////////////////////////////////////// 577*cdf0e10cSrcweir 578*cdf0e10cSrcweir 579*cdf0e10cSrcweir LngSvcMgr::LngSvcMgr() : 580*cdf0e10cSrcweir utl::ConfigItem( String::CreateFromAscii( "Office.Linguistic" ) ), 581*cdf0e10cSrcweir aEvtListeners ( GetLinguMutex() ) 582*cdf0e10cSrcweir { 583*cdf0e10cSrcweir bHasAvailSpellLocales = 584*cdf0e10cSrcweir bHasAvailGrammarLocales = 585*cdf0e10cSrcweir bHasAvailHyphLocales = 586*cdf0e10cSrcweir bHasAvailThesLocales = 587*cdf0e10cSrcweir bDisposing = sal_False; 588*cdf0e10cSrcweir 589*cdf0e10cSrcweir pSpellDsp = 0; 590*cdf0e10cSrcweir pGrammarDsp = 0; 591*cdf0e10cSrcweir pHyphDsp = 0; 592*cdf0e10cSrcweir pThesDsp = 0; 593*cdf0e10cSrcweir 594*cdf0e10cSrcweir pAvailSpellSvcs = 0; 595*cdf0e10cSrcweir pAvailGrammarSvcs = 0; 596*cdf0e10cSrcweir pAvailHyphSvcs = 0; 597*cdf0e10cSrcweir pAvailThesSvcs = 0; 598*cdf0e10cSrcweir pListenerHelper = 0; 599*cdf0e10cSrcweir 600*cdf0e10cSrcweir // request notify events when properties (i.e. something in the subtree) changes 601*cdf0e10cSrcweir uno::Sequence< OUString > aNames(4); 602*cdf0e10cSrcweir OUString *pNames = aNames.getArray(); 603*cdf0e10cSrcweir pNames[0] = A2OU( "ServiceManager/SpellCheckerList" ); 604*cdf0e10cSrcweir pNames[1] = A2OU( "ServiceManager/GrammarCheckerList" ); 605*cdf0e10cSrcweir pNames[2] = A2OU( "ServiceManager/HyphenatorList" ); 606*cdf0e10cSrcweir pNames[3] = A2OU( "ServiceManager/ThesaurusList" ); 607*cdf0e10cSrcweir EnableNotification( aNames ); 608*cdf0e10cSrcweir } 609*cdf0e10cSrcweir 610*cdf0e10cSrcweir void LngSvcMgr::clearSvcInfoArray(SvcInfoArray* pInfo) 611*cdf0e10cSrcweir { 612*cdf0e10cSrcweir if (pInfo) 613*cdf0e10cSrcweir { 614*cdf0e10cSrcweir std::for_each(pInfo->begin(), pInfo->end(), boost::checked_deleter<SvcInfo>()); 615*cdf0e10cSrcweir delete pInfo; 616*cdf0e10cSrcweir } 617*cdf0e10cSrcweir } 618*cdf0e10cSrcweir 619*cdf0e10cSrcweir LngSvcMgr::~LngSvcMgr() 620*cdf0e10cSrcweir { 621*cdf0e10cSrcweir // memory for pSpellDsp, pHyphDsp, pThesDsp, pListenerHelper 622*cdf0e10cSrcweir // will be freed in the destructor of the respective Reference's 623*cdf0e10cSrcweir // xSpellDsp, xGrammarDsp, xHyphDsp, xThesDsp 624*cdf0e10cSrcweir 625*cdf0e10cSrcweir clearSvcInfoArray(pAvailSpellSvcs); 626*cdf0e10cSrcweir clearSvcInfoArray(pAvailGrammarSvcs); 627*cdf0e10cSrcweir clearSvcInfoArray(pAvailHyphSvcs); 628*cdf0e10cSrcweir clearSvcInfoArray(pAvailThesSvcs); 629*cdf0e10cSrcweir } 630*cdf0e10cSrcweir 631*cdf0e10cSrcweir 632*cdf0e10cSrcweir void LngSvcMgr::Notify( const uno::Sequence< OUString > &rPropertyNames ) 633*cdf0e10cSrcweir { 634*cdf0e10cSrcweir const OUString aSpellCheckerList( A2OU("ServiceManager/SpellCheckerList") ); 635*cdf0e10cSrcweir const OUString aGrammarCheckerList( A2OU("ServiceManager/GrammarCheckerList") ); 636*cdf0e10cSrcweir const OUString aHyphenatorList( A2OU("ServiceManager/HyphenatorList") ); 637*cdf0e10cSrcweir const OUString aThesaurusList( A2OU("ServiceManager/ThesaurusList") ); 638*cdf0e10cSrcweir 639*cdf0e10cSrcweir const uno::Sequence< OUString > aSpellCheckerListEntries( GetNodeNames( aSpellCheckerList ) ); 640*cdf0e10cSrcweir const uno::Sequence< OUString > aGrammarCheckerListEntries( GetNodeNames( aGrammarCheckerList ) ); 641*cdf0e10cSrcweir const uno::Sequence< OUString > aHyphenatorListEntries( GetNodeNames( aHyphenatorList ) ); 642*cdf0e10cSrcweir const uno::Sequence< OUString > aThesaurusListEntries( GetNodeNames( aThesaurusList ) ); 643*cdf0e10cSrcweir 644*cdf0e10cSrcweir uno::Sequence< uno::Any > aValues; 645*cdf0e10cSrcweir uno::Sequence< OUString > aNames( 1 ); 646*cdf0e10cSrcweir OUString *pNames = aNames.getArray(); 647*cdf0e10cSrcweir 648*cdf0e10cSrcweir sal_Int32 nLen = rPropertyNames.getLength(); 649*cdf0e10cSrcweir const OUString *pPropertyNames = rPropertyNames.getConstArray(); 650*cdf0e10cSrcweir for (sal_Int32 i = 0; i < nLen; ++i) 651*cdf0e10cSrcweir { 652*cdf0e10cSrcweir // property names look like 653*cdf0e10cSrcweir // "ServiceManager/ThesaurusList/de-CH" 654*cdf0e10cSrcweir 655*cdf0e10cSrcweir const OUString &rName = pPropertyNames[i]; 656*cdf0e10cSrcweir sal_Int32 nKeyStart; 657*cdf0e10cSrcweir nKeyStart = rName.lastIndexOf( '/' ); 658*cdf0e10cSrcweir OUString aKeyText; 659*cdf0e10cSrcweir if (nKeyStart != -1) 660*cdf0e10cSrcweir aKeyText = rName.copy( nKeyStart + 1 ); 661*cdf0e10cSrcweir DBG_ASSERT( aKeyText.getLength() != 0, "unexpected key (lang::Locale) string" ); 662*cdf0e10cSrcweir if (0 == rName.compareTo( aSpellCheckerList, aSpellCheckerList.getLength() )) 663*cdf0e10cSrcweir { 664*cdf0e10cSrcweir // delete old cached data, needs to be acquired new on demand 665*cdf0e10cSrcweir clearSvcInfoArray(pAvailSpellSvcs); pAvailSpellSvcs = 0; 666*cdf0e10cSrcweir 667*cdf0e10cSrcweir OUString aNode( aSpellCheckerList ); 668*cdf0e10cSrcweir if (lcl_SeqHasString( aSpellCheckerListEntries, aKeyText )) 669*cdf0e10cSrcweir { 670*cdf0e10cSrcweir OUString aPropName( aNode ); 671*cdf0e10cSrcweir aPropName += OUString::valueOf( (sal_Unicode) '/' ); 672*cdf0e10cSrcweir aPropName += aKeyText; 673*cdf0e10cSrcweir pNames[0] = aPropName; 674*cdf0e10cSrcweir aValues = /*aCfg.*/GetProperties( aNames ); 675*cdf0e10cSrcweir uno::Sequence< OUString > aSvcImplNames; 676*cdf0e10cSrcweir if (aValues.getLength()) 677*cdf0e10cSrcweir aSvcImplNames = GetLangSvcList( aValues.getConstArray()[0] ); 678*cdf0e10cSrcweir 679*cdf0e10cSrcweir LanguageType nLang = LANGUAGE_NONE; 680*cdf0e10cSrcweir if (0 != aKeyText.getLength()) 681*cdf0e10cSrcweir nLang = MsLangId::convertIsoStringToLanguage( aKeyText ); 682*cdf0e10cSrcweir 683*cdf0e10cSrcweir GetSpellCheckerDsp_Impl( sal_False ); // don't set service list, it will be done below 684*cdf0e10cSrcweir pSpellDsp->SetServiceList( CreateLocale(nLang), aSvcImplNames ); 685*cdf0e10cSrcweir } 686*cdf0e10cSrcweir } 687*cdf0e10cSrcweir else if (0 == rName.compareTo( aGrammarCheckerList, aGrammarCheckerList.getLength() )) 688*cdf0e10cSrcweir { 689*cdf0e10cSrcweir // delete old cached data, needs to be acquired new on demand 690*cdf0e10cSrcweir clearSvcInfoArray(pAvailGrammarSvcs); pAvailGrammarSvcs = 0; 691*cdf0e10cSrcweir 692*cdf0e10cSrcweir OUString aNode( aGrammarCheckerList ); 693*cdf0e10cSrcweir if (lcl_SeqHasString( aGrammarCheckerListEntries, aKeyText )) 694*cdf0e10cSrcweir { 695*cdf0e10cSrcweir OUString aPropName( aNode ); 696*cdf0e10cSrcweir aPropName += OUString::valueOf( (sal_Unicode) '/' ); 697*cdf0e10cSrcweir aPropName += aKeyText; 698*cdf0e10cSrcweir pNames[0] = aPropName; 699*cdf0e10cSrcweir aValues = /*aCfg.*/GetProperties( aNames ); 700*cdf0e10cSrcweir uno::Sequence< OUString > aSvcImplNames; 701*cdf0e10cSrcweir if (aValues.getLength()) 702*cdf0e10cSrcweir aSvcImplNames = GetLangSvc( aValues.getConstArray()[0] ); 703*cdf0e10cSrcweir 704*cdf0e10cSrcweir LanguageType nLang = LANGUAGE_NONE; 705*cdf0e10cSrcweir if (0 != aKeyText.getLength()) 706*cdf0e10cSrcweir nLang = MsLangId::convertIsoStringToLanguage( aKeyText ); 707*cdf0e10cSrcweir 708*cdf0e10cSrcweir if (SvtLinguConfig().HasGrammarChecker()) 709*cdf0e10cSrcweir { 710*cdf0e10cSrcweir GetGrammarCheckerDsp_Impl( sal_False ); // don't set service list, it will be done below 711*cdf0e10cSrcweir pGrammarDsp->SetServiceList( CreateLocale(nLang), aSvcImplNames ); 712*cdf0e10cSrcweir } 713*cdf0e10cSrcweir } 714*cdf0e10cSrcweir } 715*cdf0e10cSrcweir else if (0 == rName.compareTo( aHyphenatorList, aHyphenatorList.getLength() )) 716*cdf0e10cSrcweir { 717*cdf0e10cSrcweir // delete old cached data, needs to be acquired new on demand 718*cdf0e10cSrcweir clearSvcInfoArray(pAvailHyphSvcs); pAvailHyphSvcs = 0; 719*cdf0e10cSrcweir 720*cdf0e10cSrcweir OUString aNode( aHyphenatorList ); 721*cdf0e10cSrcweir if (lcl_SeqHasString( aHyphenatorListEntries, aKeyText )) 722*cdf0e10cSrcweir { 723*cdf0e10cSrcweir OUString aPropName( aNode ); 724*cdf0e10cSrcweir aPropName += OUString::valueOf( (sal_Unicode) '/' ); 725*cdf0e10cSrcweir aPropName += aKeyText; 726*cdf0e10cSrcweir pNames[0] = aPropName; 727*cdf0e10cSrcweir aValues = /*aCfg.*/GetProperties( aNames ); 728*cdf0e10cSrcweir uno::Sequence< OUString > aSvcImplNames; 729*cdf0e10cSrcweir if (aValues.getLength()) 730*cdf0e10cSrcweir aSvcImplNames = GetLangSvc( aValues.getConstArray()[0] ); 731*cdf0e10cSrcweir 732*cdf0e10cSrcweir LanguageType nLang = LANGUAGE_NONE; 733*cdf0e10cSrcweir if (0 != aKeyText.getLength()) 734*cdf0e10cSrcweir nLang = MsLangId::convertIsoStringToLanguage( aKeyText ); 735*cdf0e10cSrcweir 736*cdf0e10cSrcweir GetHyphenatorDsp_Impl( sal_False ); // don't set service list, it will be done below 737*cdf0e10cSrcweir pHyphDsp->SetServiceList( CreateLocale(nLang), aSvcImplNames ); 738*cdf0e10cSrcweir } 739*cdf0e10cSrcweir } 740*cdf0e10cSrcweir else if (0 == rName.compareTo( aThesaurusList, aThesaurusList.getLength() )) 741*cdf0e10cSrcweir { 742*cdf0e10cSrcweir // delete old cached data, needs to be acquired new on demand 743*cdf0e10cSrcweir clearSvcInfoArray(pAvailThesSvcs); pAvailThesSvcs = 0; 744*cdf0e10cSrcweir 745*cdf0e10cSrcweir OUString aNode( aThesaurusList ); 746*cdf0e10cSrcweir if (lcl_SeqHasString( aThesaurusListEntries, aKeyText )) 747*cdf0e10cSrcweir { 748*cdf0e10cSrcweir OUString aPropName( aNode ); 749*cdf0e10cSrcweir aPropName += OUString::valueOf( (sal_Unicode) '/' ); 750*cdf0e10cSrcweir aPropName += aKeyText; 751*cdf0e10cSrcweir pNames[0] = aPropName; 752*cdf0e10cSrcweir aValues = /*aCfg.*/GetProperties( aNames ); 753*cdf0e10cSrcweir uno::Sequence< OUString > aSvcImplNames; 754*cdf0e10cSrcweir if (aValues.getLength()) 755*cdf0e10cSrcweir aSvcImplNames = GetLangSvcList( aValues.getConstArray()[0] ); 756*cdf0e10cSrcweir 757*cdf0e10cSrcweir LanguageType nLang = LANGUAGE_NONE; 758*cdf0e10cSrcweir if (0 != aKeyText.getLength()) 759*cdf0e10cSrcweir nLang = MsLangId::convertIsoStringToLanguage( aKeyText ); 760*cdf0e10cSrcweir 761*cdf0e10cSrcweir GetThesaurusDsp_Impl( sal_False ); // don't set service list, it will be done below 762*cdf0e10cSrcweir pThesDsp->SetServiceList( CreateLocale(nLang), aSvcImplNames ); 763*cdf0e10cSrcweir } 764*cdf0e10cSrcweir } 765*cdf0e10cSrcweir else 766*cdf0e10cSrcweir { 767*cdf0e10cSrcweir DBG_ASSERT( 0, "nofified for unexpected property" ); 768*cdf0e10cSrcweir } 769*cdf0e10cSrcweir } 770*cdf0e10cSrcweir } 771*cdf0e10cSrcweir 772*cdf0e10cSrcweir 773*cdf0e10cSrcweir void LngSvcMgr::Commit() 774*cdf0e10cSrcweir { 775*cdf0e10cSrcweir // everything necessary should have already been done by 'SaveCfgSvcs' 776*cdf0e10cSrcweir // called from within 'setConfiguredServices'. 777*cdf0e10cSrcweir // Also this class usually exits only when the Office i sbeing shutdown. 778*cdf0e10cSrcweir } 779*cdf0e10cSrcweir 780*cdf0e10cSrcweir 781*cdf0e10cSrcweir void LngSvcMgr::GetListenerHelper_Impl() 782*cdf0e10cSrcweir { 783*cdf0e10cSrcweir if (!pListenerHelper) 784*cdf0e10cSrcweir { 785*cdf0e10cSrcweir pListenerHelper = new LngSvcMgrListenerHelper( *this, 786*cdf0e10cSrcweir (XLinguServiceManager *) this, linguistic::GetDictionaryList() ); 787*cdf0e10cSrcweir xListenerHelper = (linguistic2::XLinguServiceEventListener *) pListenerHelper; 788*cdf0e10cSrcweir } 789*cdf0e10cSrcweir } 790*cdf0e10cSrcweir 791*cdf0e10cSrcweir 792*cdf0e10cSrcweir void LngSvcMgr::GetSpellCheckerDsp_Impl( sal_Bool bSetSvcList ) 793*cdf0e10cSrcweir { 794*cdf0e10cSrcweir if (!pSpellDsp) 795*cdf0e10cSrcweir { 796*cdf0e10cSrcweir pSpellDsp = new SpellCheckerDispatcher( *this ); 797*cdf0e10cSrcweir xSpellDsp = pSpellDsp; 798*cdf0e10cSrcweir if (bSetSvcList) 799*cdf0e10cSrcweir SetCfgServiceLists( *pSpellDsp ); 800*cdf0e10cSrcweir } 801*cdf0e10cSrcweir } 802*cdf0e10cSrcweir 803*cdf0e10cSrcweir 804*cdf0e10cSrcweir void LngSvcMgr::GetGrammarCheckerDsp_Impl( sal_Bool bSetSvcList ) 805*cdf0e10cSrcweir { 806*cdf0e10cSrcweir if (!pGrammarDsp && SvtLinguConfig().HasGrammarChecker()) 807*cdf0e10cSrcweir { 808*cdf0e10cSrcweir //! since the grammar checking iterator needs to be a one instance service 809*cdf0e10cSrcweir //! we need to create it the correct way! 810*cdf0e10cSrcweir uno::Reference< linguistic2::XProofreadingIterator > xGCI; 811*cdf0e10cSrcweir try 812*cdf0e10cSrcweir { 813*cdf0e10cSrcweir uno::Reference< lang::XMultiServiceFactory > xMgr( 814*cdf0e10cSrcweir utl::getProcessServiceFactory(), uno::UNO_QUERY_THROW ); 815*cdf0e10cSrcweir xGCI = uno::Reference< linguistic2::XProofreadingIterator >( 816*cdf0e10cSrcweir xMgr->createInstance( A2OU( SN_GRAMMARCHECKINGITERATOR ) ), uno::UNO_QUERY_THROW ); 817*cdf0e10cSrcweir } 818*cdf0e10cSrcweir catch (uno::Exception &) 819*cdf0e10cSrcweir { 820*cdf0e10cSrcweir } 821*cdf0e10cSrcweir DBG_ASSERT( xGCI.is(), "instantiating grammar checking iterator failed" ); 822*cdf0e10cSrcweir 823*cdf0e10cSrcweir if (xGCI.is()) 824*cdf0e10cSrcweir { 825*cdf0e10cSrcweir pGrammarDsp = dynamic_cast< GrammarCheckingIterator * >(xGCI.get()); 826*cdf0e10cSrcweir xGrammarDsp = xGCI; 827*cdf0e10cSrcweir DBG_ASSERT( pGrammarDsp, "failed to get implementation" ); 828*cdf0e10cSrcweir if (bSetSvcList) 829*cdf0e10cSrcweir SetCfgServiceLists( *pGrammarDsp ); 830*cdf0e10cSrcweir } 831*cdf0e10cSrcweir } 832*cdf0e10cSrcweir } 833*cdf0e10cSrcweir 834*cdf0e10cSrcweir 835*cdf0e10cSrcweir void LngSvcMgr::GetHyphenatorDsp_Impl( sal_Bool bSetSvcList ) 836*cdf0e10cSrcweir { 837*cdf0e10cSrcweir if (!pHyphDsp) 838*cdf0e10cSrcweir { 839*cdf0e10cSrcweir pHyphDsp = new HyphenatorDispatcher( *this ); 840*cdf0e10cSrcweir xHyphDsp = pHyphDsp; 841*cdf0e10cSrcweir if (bSetSvcList) 842*cdf0e10cSrcweir SetCfgServiceLists( *pHyphDsp ); 843*cdf0e10cSrcweir } 844*cdf0e10cSrcweir } 845*cdf0e10cSrcweir 846*cdf0e10cSrcweir 847*cdf0e10cSrcweir void LngSvcMgr::GetThesaurusDsp_Impl( sal_Bool bSetSvcList ) 848*cdf0e10cSrcweir { 849*cdf0e10cSrcweir if (!pThesDsp) 850*cdf0e10cSrcweir { 851*cdf0e10cSrcweir pThesDsp = new ThesaurusDispatcher; 852*cdf0e10cSrcweir xThesDsp = pThesDsp; 853*cdf0e10cSrcweir if (bSetSvcList) 854*cdf0e10cSrcweir SetCfgServiceLists( *pThesDsp ); 855*cdf0e10cSrcweir } 856*cdf0e10cSrcweir } 857*cdf0e10cSrcweir 858*cdf0e10cSrcweir 859*cdf0e10cSrcweir void LngSvcMgr::GetAvailableSpellSvcs_Impl() 860*cdf0e10cSrcweir { 861*cdf0e10cSrcweir if (!pAvailSpellSvcs) 862*cdf0e10cSrcweir { 863*cdf0e10cSrcweir pAvailSpellSvcs = new SvcInfoArray; 864*cdf0e10cSrcweir 865*cdf0e10cSrcweir uno::Reference< lang::XMultiServiceFactory > xFac( utl::getProcessServiceFactory() ); 866*cdf0e10cSrcweir if (xFac.is()) 867*cdf0e10cSrcweir { 868*cdf0e10cSrcweir uno::Reference< container::XContentEnumerationAccess > xEnumAccess( xFac, uno::UNO_QUERY ); 869*cdf0e10cSrcweir uno::Reference< container::XEnumeration > xEnum; 870*cdf0e10cSrcweir if (xEnumAccess.is()) 871*cdf0e10cSrcweir xEnum = xEnumAccess->createContentEnumeration( 872*cdf0e10cSrcweir A2OU( SN_SPELLCHECKER ) ); 873*cdf0e10cSrcweir 874*cdf0e10cSrcweir if (xEnum.is()) 875*cdf0e10cSrcweir { 876*cdf0e10cSrcweir while (xEnum->hasMoreElements()) 877*cdf0e10cSrcweir { 878*cdf0e10cSrcweir uno::Any aCurrent = xEnum->nextElement(); 879*cdf0e10cSrcweir uno::Reference< lang::XSingleComponentFactory > xCompFactory; 880*cdf0e10cSrcweir uno::Reference< lang::XSingleServiceFactory > xFactory; 881*cdf0e10cSrcweir 882*cdf0e10cSrcweir uno::Reference< linguistic2::XSpellChecker > xSvc; 883*cdf0e10cSrcweir if ( cppu::extractInterface( xCompFactory, aCurrent ) || ::cppu::extractInterface( xFactory, aCurrent ) ) 884*cdf0e10cSrcweir { 885*cdf0e10cSrcweir try 886*cdf0e10cSrcweir { 887*cdf0e10cSrcweir uno::Reference < uno::XComponentContext > xContext; 888*cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xProps( xFac, uno::UNO_QUERY ); 889*cdf0e10cSrcweir 890*cdf0e10cSrcweir xProps->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ))) >>= xContext; 891*cdf0e10cSrcweir xSvc = uno::Reference< linguistic2::XSpellChecker >( ( xCompFactory.is() ? xCompFactory->createInstanceWithContext( xContext ) : xFactory->createInstance() ), uno::UNO_QUERY ); 892*cdf0e10cSrcweir } 893*cdf0e10cSrcweir catch (uno::Exception &rEx) 894*cdf0e10cSrcweir { 895*cdf0e10cSrcweir (void) rEx; 896*cdf0e10cSrcweir DBG_ASSERT( 0, "createInstance failed" ); 897*cdf0e10cSrcweir } 898*cdf0e10cSrcweir } 899*cdf0e10cSrcweir 900*cdf0e10cSrcweir if (xSvc.is()) 901*cdf0e10cSrcweir { 902*cdf0e10cSrcweir OUString aImplName; 903*cdf0e10cSrcweir uno::Sequence< sal_Int16 > aLanguages; 904*cdf0e10cSrcweir uno::Reference< XServiceInfo > xInfo( xSvc, uno::UNO_QUERY ); 905*cdf0e10cSrcweir if (xInfo.is()) 906*cdf0e10cSrcweir aImplName = xInfo->getImplementationName(); 907*cdf0e10cSrcweir DBG_ASSERT( aImplName.getLength(), 908*cdf0e10cSrcweir "empty implementation name" ); 909*cdf0e10cSrcweir uno::Reference< linguistic2::XSupportedLocales > xSuppLoc( xSvc, uno::UNO_QUERY ); 910*cdf0e10cSrcweir DBG_ASSERT( xSuppLoc.is(), "interfaces not supported" ); 911*cdf0e10cSrcweir if (xSuppLoc.is()) { 912*cdf0e10cSrcweir uno::Sequence<lang::Locale> aLocaleSequence(xSuppLoc->getLocales()); 913*cdf0e10cSrcweir aLanguages = LocaleSeqToLangSeq( aLocaleSequence ); 914*cdf0e10cSrcweir } 915*cdf0e10cSrcweir 916*cdf0e10cSrcweir pAvailSpellSvcs->push_back( new SvcInfo( aImplName, aLanguages ) ); 917*cdf0e10cSrcweir } 918*cdf0e10cSrcweir } 919*cdf0e10cSrcweir } 920*cdf0e10cSrcweir } 921*cdf0e10cSrcweir } 922*cdf0e10cSrcweir } 923*cdf0e10cSrcweir 924*cdf0e10cSrcweir 925*cdf0e10cSrcweir void LngSvcMgr::GetAvailableGrammarSvcs_Impl() 926*cdf0e10cSrcweir { 927*cdf0e10cSrcweir if (!pAvailGrammarSvcs) 928*cdf0e10cSrcweir { 929*cdf0e10cSrcweir pAvailGrammarSvcs = new SvcInfoArray; 930*cdf0e10cSrcweir 931*cdf0e10cSrcweir uno::Reference< lang::XMultiServiceFactory > xFac( utl::getProcessServiceFactory() ); 932*cdf0e10cSrcweir if (xFac.is()) 933*cdf0e10cSrcweir { 934*cdf0e10cSrcweir uno::Reference< container::XContentEnumerationAccess > xEnumAccess( xFac, uno::UNO_QUERY ); 935*cdf0e10cSrcweir uno::Reference< container::XEnumeration > xEnum; 936*cdf0e10cSrcweir if (xEnumAccess.is()) 937*cdf0e10cSrcweir xEnum = xEnumAccess->createContentEnumeration( 938*cdf0e10cSrcweir A2OU( SN_GRAMMARCHECKER ) ); 939*cdf0e10cSrcweir 940*cdf0e10cSrcweir if (xEnum.is()) 941*cdf0e10cSrcweir { 942*cdf0e10cSrcweir while (xEnum->hasMoreElements()) 943*cdf0e10cSrcweir { 944*cdf0e10cSrcweir uno::Any aCurrent = xEnum->nextElement(); 945*cdf0e10cSrcweir uno::Reference< lang::XSingleComponentFactory > xCompFactory; 946*cdf0e10cSrcweir uno::Reference< lang::XSingleServiceFactory > xFactory; 947*cdf0e10cSrcweir 948*cdf0e10cSrcweir uno::Reference< linguistic2::XProofreader > xSvc; 949*cdf0e10cSrcweir if ( cppu::extractInterface( xCompFactory, aCurrent ) || ::cppu::extractInterface( xFactory, aCurrent ) ) 950*cdf0e10cSrcweir { 951*cdf0e10cSrcweir try 952*cdf0e10cSrcweir { 953*cdf0e10cSrcweir uno::Reference < uno::XComponentContext > xContext; 954*cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xProps( xFac, uno::UNO_QUERY ); 955*cdf0e10cSrcweir 956*cdf0e10cSrcweir xProps->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ))) >>= xContext; 957*cdf0e10cSrcweir xSvc = uno::Reference< linguistic2::XProofreader >( ( xCompFactory.is() ? xCompFactory->createInstanceWithContext( xContext ) : xFactory->createInstance() ), uno::UNO_QUERY ); 958*cdf0e10cSrcweir } 959*cdf0e10cSrcweir catch (uno::Exception &rEx) 960*cdf0e10cSrcweir { 961*cdf0e10cSrcweir (void) rEx; 962*cdf0e10cSrcweir DBG_ASSERT( 0, "createInstance failed" ); 963*cdf0e10cSrcweir } 964*cdf0e10cSrcweir } 965*cdf0e10cSrcweir 966*cdf0e10cSrcweir if (xSvc.is()) 967*cdf0e10cSrcweir { 968*cdf0e10cSrcweir OUString aImplName; 969*cdf0e10cSrcweir uno::Sequence< sal_Int16 > aLanguages; 970*cdf0e10cSrcweir uno::Reference< XServiceInfo > xInfo( xSvc, uno::UNO_QUERY ); 971*cdf0e10cSrcweir if (xInfo.is()) 972*cdf0e10cSrcweir aImplName = xInfo->getImplementationName(); 973*cdf0e10cSrcweir DBG_ASSERT( aImplName.getLength(), 974*cdf0e10cSrcweir "empty implementation name" ); 975*cdf0e10cSrcweir uno::Reference< linguistic2::XSupportedLocales > xSuppLoc( xSvc, uno::UNO_QUERY ); 976*cdf0e10cSrcweir DBG_ASSERT( xSuppLoc.is(), "interfaces not supported" ); 977*cdf0e10cSrcweir if (xSuppLoc.is()) { 978*cdf0e10cSrcweir uno::Sequence<lang::Locale> aLocaleSequence(xSuppLoc->getLocales()); 979*cdf0e10cSrcweir aLanguages = LocaleSeqToLangSeq( aLocaleSequence ); 980*cdf0e10cSrcweir } 981*cdf0e10cSrcweir 982*cdf0e10cSrcweir pAvailGrammarSvcs->push_back( new SvcInfo( aImplName, aLanguages ) ); 983*cdf0e10cSrcweir } 984*cdf0e10cSrcweir } 985*cdf0e10cSrcweir } 986*cdf0e10cSrcweir } 987*cdf0e10cSrcweir } 988*cdf0e10cSrcweir } 989*cdf0e10cSrcweir 990*cdf0e10cSrcweir 991*cdf0e10cSrcweir void LngSvcMgr::GetAvailableHyphSvcs_Impl() 992*cdf0e10cSrcweir { 993*cdf0e10cSrcweir if (!pAvailHyphSvcs) 994*cdf0e10cSrcweir { 995*cdf0e10cSrcweir pAvailHyphSvcs = new SvcInfoArray; 996*cdf0e10cSrcweir uno::Reference< lang::XMultiServiceFactory > xFac( utl::getProcessServiceFactory() ); 997*cdf0e10cSrcweir if (xFac.is()) 998*cdf0e10cSrcweir { 999*cdf0e10cSrcweir uno::Reference< container::XContentEnumerationAccess > xEnumAccess( xFac, uno::UNO_QUERY ); 1000*cdf0e10cSrcweir uno::Reference< container::XEnumeration > xEnum; 1001*cdf0e10cSrcweir if (xEnumAccess.is()) 1002*cdf0e10cSrcweir xEnum = xEnumAccess->createContentEnumeration( A2OU( SN_HYPHENATOR ) ); 1003*cdf0e10cSrcweir 1004*cdf0e10cSrcweir if (xEnum.is()) 1005*cdf0e10cSrcweir { 1006*cdf0e10cSrcweir while (xEnum->hasMoreElements()) 1007*cdf0e10cSrcweir { 1008*cdf0e10cSrcweir uno::Any aCurrent = xEnum->nextElement(); 1009*cdf0e10cSrcweir uno::Reference< lang::XSingleComponentFactory > xCompFactory; 1010*cdf0e10cSrcweir uno::Reference< lang::XSingleServiceFactory > xFactory; 1011*cdf0e10cSrcweir 1012*cdf0e10cSrcweir uno::Reference< linguistic2::XHyphenator > xSvc; 1013*cdf0e10cSrcweir if ( cppu::extractInterface( xCompFactory, aCurrent ) || ::cppu::extractInterface( xFactory, aCurrent ) ) 1014*cdf0e10cSrcweir { 1015*cdf0e10cSrcweir try 1016*cdf0e10cSrcweir { 1017*cdf0e10cSrcweir uno::Reference < uno::XComponentContext > xContext; 1018*cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xProps( xFac, uno::UNO_QUERY ); 1019*cdf0e10cSrcweir 1020*cdf0e10cSrcweir xProps->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ))) >>= xContext; 1021*cdf0e10cSrcweir xSvc = uno::Reference< linguistic2::XHyphenator >( ( xCompFactory.is() ? xCompFactory->createInstanceWithContext( xContext ) : xFactory->createInstance() ), uno::UNO_QUERY ); 1022*cdf0e10cSrcweir 1023*cdf0e10cSrcweir } 1024*cdf0e10cSrcweir catch (uno::Exception &rEx) 1025*cdf0e10cSrcweir { 1026*cdf0e10cSrcweir (void) rEx; 1027*cdf0e10cSrcweir DBG_ASSERT( 0, "createInstance failed" ); 1028*cdf0e10cSrcweir } 1029*cdf0e10cSrcweir } 1030*cdf0e10cSrcweir 1031*cdf0e10cSrcweir if (xSvc.is()) 1032*cdf0e10cSrcweir { 1033*cdf0e10cSrcweir OUString aImplName; 1034*cdf0e10cSrcweir uno::Sequence< sal_Int16 > aLanguages; 1035*cdf0e10cSrcweir uno::Reference< XServiceInfo > xInfo( xSvc, uno::UNO_QUERY ); 1036*cdf0e10cSrcweir if (xInfo.is()) 1037*cdf0e10cSrcweir aImplName = xInfo->getImplementationName(); 1038*cdf0e10cSrcweir DBG_ASSERT( aImplName.getLength(), 1039*cdf0e10cSrcweir "empty implementation name" ); 1040*cdf0e10cSrcweir uno::Reference< linguistic2::XSupportedLocales > xSuppLoc( xSvc, uno::UNO_QUERY ); 1041*cdf0e10cSrcweir DBG_ASSERT( xSuppLoc.is(), "interfaces not supported" ); 1042*cdf0e10cSrcweir if (xSuppLoc.is()) { 1043*cdf0e10cSrcweir uno::Sequence<lang::Locale> aLocaleSequence(xSuppLoc->getLocales()); 1044*cdf0e10cSrcweir aLanguages = LocaleSeqToLangSeq( aLocaleSequence ); 1045*cdf0e10cSrcweir } 1046*cdf0e10cSrcweir 1047*cdf0e10cSrcweir pAvailHyphSvcs->push_back( new SvcInfo( aImplName, aLanguages ) ); 1048*cdf0e10cSrcweir } 1049*cdf0e10cSrcweir } 1050*cdf0e10cSrcweir } 1051*cdf0e10cSrcweir } 1052*cdf0e10cSrcweir } 1053*cdf0e10cSrcweir } 1054*cdf0e10cSrcweir 1055*cdf0e10cSrcweir 1056*cdf0e10cSrcweir void LngSvcMgr::GetAvailableThesSvcs_Impl() 1057*cdf0e10cSrcweir { 1058*cdf0e10cSrcweir if (!pAvailThesSvcs) 1059*cdf0e10cSrcweir { 1060*cdf0e10cSrcweir pAvailThesSvcs = new SvcInfoArray; 1061*cdf0e10cSrcweir 1062*cdf0e10cSrcweir uno::Reference< lang::XMultiServiceFactory > xFac( utl::getProcessServiceFactory() ); 1063*cdf0e10cSrcweir if (xFac.is()) 1064*cdf0e10cSrcweir { 1065*cdf0e10cSrcweir uno::Reference< container::XContentEnumerationAccess > xEnumAccess( xFac, uno::UNO_QUERY ); 1066*cdf0e10cSrcweir uno::Reference< container::XEnumeration > xEnum; 1067*cdf0e10cSrcweir if (xEnumAccess.is()) 1068*cdf0e10cSrcweir xEnum = xEnumAccess->createContentEnumeration( 1069*cdf0e10cSrcweir A2OU( SN_THESAURUS ) ); 1070*cdf0e10cSrcweir 1071*cdf0e10cSrcweir if (xEnum.is()) 1072*cdf0e10cSrcweir { 1073*cdf0e10cSrcweir while (xEnum->hasMoreElements()) 1074*cdf0e10cSrcweir { 1075*cdf0e10cSrcweir uno::Any aCurrent = xEnum->nextElement(); 1076*cdf0e10cSrcweir 1077*cdf0e10cSrcweir uno::Reference< lang::XSingleComponentFactory > xCompFactory; 1078*cdf0e10cSrcweir uno::Reference< lang::XSingleServiceFactory > xFactory; 1079*cdf0e10cSrcweir 1080*cdf0e10cSrcweir uno::Reference< linguistic2::XThesaurus > xSvc; 1081*cdf0e10cSrcweir if ( cppu::extractInterface( xCompFactory, aCurrent ) || ::cppu::extractInterface( xFactory, aCurrent ) ) 1082*cdf0e10cSrcweir { 1083*cdf0e10cSrcweir try 1084*cdf0e10cSrcweir { 1085*cdf0e10cSrcweir uno::Reference < uno::XComponentContext > xContext; 1086*cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xProps( xFac, uno::UNO_QUERY ); 1087*cdf0e10cSrcweir 1088*cdf0e10cSrcweir xProps->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ))) >>= xContext; 1089*cdf0e10cSrcweir xSvc = uno::Reference< linguistic2::XThesaurus >( ( xCompFactory.is() ? xCompFactory->createInstanceWithContext( xContext ) : xFactory->createInstance() ), uno::UNO_QUERY ); 1090*cdf0e10cSrcweir } 1091*cdf0e10cSrcweir catch (uno::Exception &rEx) 1092*cdf0e10cSrcweir { 1093*cdf0e10cSrcweir (void) rEx; 1094*cdf0e10cSrcweir DBG_ASSERT( 0, "createInstance failed" ); 1095*cdf0e10cSrcweir } 1096*cdf0e10cSrcweir } 1097*cdf0e10cSrcweir 1098*cdf0e10cSrcweir if (xSvc.is()) 1099*cdf0e10cSrcweir { 1100*cdf0e10cSrcweir OUString aImplName; 1101*cdf0e10cSrcweir uno::Sequence< sal_Int16 > aLanguages; 1102*cdf0e10cSrcweir uno::Reference< XServiceInfo > xInfo( xSvc, uno::UNO_QUERY ); 1103*cdf0e10cSrcweir if (xInfo.is()) 1104*cdf0e10cSrcweir aImplName = xInfo->getImplementationName(); 1105*cdf0e10cSrcweir DBG_ASSERT( aImplName.getLength(), 1106*cdf0e10cSrcweir "empty implementation name" ); 1107*cdf0e10cSrcweir uno::Reference< linguistic2::XSupportedLocales > xSuppLoc( xSvc, uno::UNO_QUERY ); 1108*cdf0e10cSrcweir DBG_ASSERT( xSuppLoc.is(), "interfaces not supported" ); 1109*cdf0e10cSrcweir if (xSuppLoc.is()) { 1110*cdf0e10cSrcweir uno::Sequence<lang::Locale> aLocaleSequence(xSuppLoc->getLocales()); 1111*cdf0e10cSrcweir aLanguages = LocaleSeqToLangSeq( aLocaleSequence ); 1112*cdf0e10cSrcweir } 1113*cdf0e10cSrcweir 1114*cdf0e10cSrcweir pAvailThesSvcs->push_back( new SvcInfo( aImplName, aLanguages ) ); 1115*cdf0e10cSrcweir } 1116*cdf0e10cSrcweir } 1117*cdf0e10cSrcweir } 1118*cdf0e10cSrcweir } 1119*cdf0e10cSrcweir } 1120*cdf0e10cSrcweir } 1121*cdf0e10cSrcweir 1122*cdf0e10cSrcweir 1123*cdf0e10cSrcweir void LngSvcMgr::SetCfgServiceLists( SpellCheckerDispatcher &rSpellDsp ) 1124*cdf0e10cSrcweir { 1125*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "linguistic: LngSvcMgr::SetCfgServiceLists - Spell" ); 1126*cdf0e10cSrcweir 1127*cdf0e10cSrcweir String aNode( String::CreateFromAscii( "ServiceManager/SpellCheckerList" ) ); 1128*cdf0e10cSrcweir uno::Sequence< OUString > aNames( /*aCfg.*/GetNodeNames( aNode ) ); 1129*cdf0e10cSrcweir OUString *pNames = aNames.getArray(); 1130*cdf0e10cSrcweir sal_Int32 nLen = aNames.getLength(); 1131*cdf0e10cSrcweir 1132*cdf0e10cSrcweir // append path prefix need for 'GetProperties' call below 1133*cdf0e10cSrcweir String aPrefix( aNode ); 1134*cdf0e10cSrcweir aPrefix.Append( (sal_Unicode) '/' ); 1135*cdf0e10cSrcweir for (int i = 0; i < nLen; ++i) 1136*cdf0e10cSrcweir { 1137*cdf0e10cSrcweir OUString aTmp( aPrefix ); 1138*cdf0e10cSrcweir aTmp += pNames[i]; 1139*cdf0e10cSrcweir pNames[i] = aTmp; 1140*cdf0e10cSrcweir } 1141*cdf0e10cSrcweir 1142*cdf0e10cSrcweir uno::Sequence< uno::Any > aValues( /*aCfg.*/GetProperties( aNames ) ); 1143*cdf0e10cSrcweir if (nLen && nLen == aValues.getLength()) 1144*cdf0e10cSrcweir { 1145*cdf0e10cSrcweir const uno::Any *pValues = aValues.getConstArray(); 1146*cdf0e10cSrcweir for (sal_Int32 i = 0; i < nLen; ++i) 1147*cdf0e10cSrcweir { 1148*cdf0e10cSrcweir uno::Sequence< OUString > aSvcImplNames; 1149*cdf0e10cSrcweir if (pValues[i] >>= aSvcImplNames) 1150*cdf0e10cSrcweir { 1151*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1 1152*cdf0e10cSrcweir // sal_Int32 nSvcs = aSvcImplNames.getLength(); 1153*cdf0e10cSrcweir // const OUString *pSvcImplNames = aSvcImplNames.getConstArray(); 1154*cdf0e10cSrcweir #endif 1155*cdf0e10cSrcweir String aLocaleStr( pNames[i] ); 1156*cdf0e10cSrcweir xub_StrLen nSeperatorPos = aLocaleStr.SearchBackward( sal_Unicode( '/' ) ); 1157*cdf0e10cSrcweir aLocaleStr = aLocaleStr.Copy( nSeperatorPos + 1 ); 1158*cdf0e10cSrcweir lang::Locale aLocale( CreateLocale( MsLangId::convertIsoStringToLanguage(aLocaleStr) ) ); 1159*cdf0e10cSrcweir rSpellDsp.SetServiceList( aLocale, aSvcImplNames ); 1160*cdf0e10cSrcweir } 1161*cdf0e10cSrcweir } 1162*cdf0e10cSrcweir } 1163*cdf0e10cSrcweir } 1164*cdf0e10cSrcweir 1165*cdf0e10cSrcweir 1166*cdf0e10cSrcweir void LngSvcMgr::SetCfgServiceLists( GrammarCheckingIterator &rGrammarDsp ) 1167*cdf0e10cSrcweir { 1168*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "linguistic: LngSvcMgr::SetCfgServiceLists - Grammar" ); 1169*cdf0e10cSrcweir 1170*cdf0e10cSrcweir String aNode( String::CreateFromAscii( "ServiceManager/GrammarCheckerList" ) ); 1171*cdf0e10cSrcweir uno::Sequence< OUString > aNames( /*aCfg.*/GetNodeNames( aNode ) ); 1172*cdf0e10cSrcweir OUString *pNames = aNames.getArray(); 1173*cdf0e10cSrcweir sal_Int32 nLen = aNames.getLength(); 1174*cdf0e10cSrcweir 1175*cdf0e10cSrcweir // append path prefix need for 'GetProperties' call below 1176*cdf0e10cSrcweir String aPrefix( aNode ); 1177*cdf0e10cSrcweir aPrefix.Append( (sal_Unicode) '/' ); 1178*cdf0e10cSrcweir for (int i = 0; i < nLen; ++i) 1179*cdf0e10cSrcweir { 1180*cdf0e10cSrcweir OUString aTmp( aPrefix ); 1181*cdf0e10cSrcweir aTmp += pNames[i]; 1182*cdf0e10cSrcweir pNames[i] = aTmp; 1183*cdf0e10cSrcweir } 1184*cdf0e10cSrcweir 1185*cdf0e10cSrcweir uno::Sequence< uno::Any > aValues( /*aCfg.*/GetProperties( aNames ) ); 1186*cdf0e10cSrcweir if (nLen && nLen == aValues.getLength()) 1187*cdf0e10cSrcweir { 1188*cdf0e10cSrcweir const uno::Any *pValues = aValues.getConstArray(); 1189*cdf0e10cSrcweir for (sal_Int32 i = 0; i < nLen; ++i) 1190*cdf0e10cSrcweir { 1191*cdf0e10cSrcweir uno::Sequence< OUString > aSvcImplNames; 1192*cdf0e10cSrcweir if (pValues[i] >>= aSvcImplNames) 1193*cdf0e10cSrcweir { 1194*cdf0e10cSrcweir // there should only be one grammar checker in use per language... 1195*cdf0e10cSrcweir if (aSvcImplNames.getLength() > 1) 1196*cdf0e10cSrcweir aSvcImplNames.realloc(1); 1197*cdf0e10cSrcweir 1198*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1 1199*cdf0e10cSrcweir // sal_Int32 nSvcs = aSvcImplNames.getLength(); 1200*cdf0e10cSrcweir // const OUString *pSvcImplNames = aSvcImplNames.getConstArray(); 1201*cdf0e10cSrcweir #endif 1202*cdf0e10cSrcweir String aLocaleStr( pNames[i] ); 1203*cdf0e10cSrcweir xub_StrLen nSeperatorPos = aLocaleStr.SearchBackward( sal_Unicode( '/' ) ); 1204*cdf0e10cSrcweir aLocaleStr = aLocaleStr.Copy( nSeperatorPos + 1 ); 1205*cdf0e10cSrcweir lang::Locale aLocale( CreateLocale( MsLangId::convertIsoStringToLanguage(aLocaleStr) ) ); 1206*cdf0e10cSrcweir rGrammarDsp.SetServiceList( aLocale, aSvcImplNames ); 1207*cdf0e10cSrcweir } 1208*cdf0e10cSrcweir } 1209*cdf0e10cSrcweir } 1210*cdf0e10cSrcweir } 1211*cdf0e10cSrcweir 1212*cdf0e10cSrcweir 1213*cdf0e10cSrcweir void LngSvcMgr::SetCfgServiceLists( HyphenatorDispatcher &rHyphDsp ) 1214*cdf0e10cSrcweir { 1215*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "linguistic: LngSvcMgr::SetCfgServiceLists - Hyph" ); 1216*cdf0e10cSrcweir 1217*cdf0e10cSrcweir String aNode( String::CreateFromAscii( "ServiceManager/HyphenatorList" ) ); 1218*cdf0e10cSrcweir uno::Sequence< OUString > aNames( /*aCfg.*/GetNodeNames( aNode ) ); 1219*cdf0e10cSrcweir OUString *pNames = aNames.getArray(); 1220*cdf0e10cSrcweir sal_Int32 nLen = aNames.getLength(); 1221*cdf0e10cSrcweir 1222*cdf0e10cSrcweir // append path prefix need for 'GetProperties' call below 1223*cdf0e10cSrcweir String aPrefix( aNode ); 1224*cdf0e10cSrcweir aPrefix.Append( (sal_Unicode) '/' ); 1225*cdf0e10cSrcweir for (int i = 0; i < nLen; ++i) 1226*cdf0e10cSrcweir { 1227*cdf0e10cSrcweir OUString aTmp( aPrefix ); 1228*cdf0e10cSrcweir aTmp += pNames[i]; 1229*cdf0e10cSrcweir pNames[i] = aTmp; 1230*cdf0e10cSrcweir } 1231*cdf0e10cSrcweir 1232*cdf0e10cSrcweir uno::Sequence< uno::Any > aValues( /*aCfg.*/GetProperties( aNames ) ); 1233*cdf0e10cSrcweir if (nLen && nLen == aValues.getLength()) 1234*cdf0e10cSrcweir { 1235*cdf0e10cSrcweir const uno::Any *pValues = aValues.getConstArray(); 1236*cdf0e10cSrcweir for (sal_Int32 i = 0; i < nLen; ++i) 1237*cdf0e10cSrcweir { 1238*cdf0e10cSrcweir uno::Sequence< OUString > aSvcImplNames; 1239*cdf0e10cSrcweir if (pValues[i] >>= aSvcImplNames) 1240*cdf0e10cSrcweir { 1241*cdf0e10cSrcweir // there should only be one hyphenator in use per language... 1242*cdf0e10cSrcweir if (aSvcImplNames.getLength() > 1) 1243*cdf0e10cSrcweir aSvcImplNames.realloc(1); 1244*cdf0e10cSrcweir 1245*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1 1246*cdf0e10cSrcweir // sal_Int32 nSvcs = aSvcImplNames.getLength(); 1247*cdf0e10cSrcweir // const OUString *pSvcImplNames = aSvcImplNames.getConstArray(); 1248*cdf0e10cSrcweir #endif 1249*cdf0e10cSrcweir String aLocaleStr( pNames[i] ); 1250*cdf0e10cSrcweir xub_StrLen nSeperatorPos = aLocaleStr.SearchBackward( sal_Unicode( '/' ) ); 1251*cdf0e10cSrcweir aLocaleStr = aLocaleStr.Copy( nSeperatorPos + 1 ); 1252*cdf0e10cSrcweir lang::Locale aLocale( CreateLocale( MsLangId::convertIsoStringToLanguage(aLocaleStr) ) ); 1253*cdf0e10cSrcweir rHyphDsp.SetServiceList( aLocale, aSvcImplNames ); 1254*cdf0e10cSrcweir } 1255*cdf0e10cSrcweir } 1256*cdf0e10cSrcweir } 1257*cdf0e10cSrcweir } 1258*cdf0e10cSrcweir 1259*cdf0e10cSrcweir 1260*cdf0e10cSrcweir void LngSvcMgr::SetCfgServiceLists( ThesaurusDispatcher &rThesDsp ) 1261*cdf0e10cSrcweir { 1262*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "linguistic: LngSvcMgr::SetCfgServiceLists - Thes" ); 1263*cdf0e10cSrcweir 1264*cdf0e10cSrcweir String aNode( String::CreateFromAscii( "ServiceManager/ThesaurusList" ) ); 1265*cdf0e10cSrcweir uno::Sequence< OUString > aNames( /*aCfg.*/GetNodeNames( aNode ) ); 1266*cdf0e10cSrcweir OUString *pNames = aNames.getArray(); 1267*cdf0e10cSrcweir sal_Int32 nLen = aNames.getLength(); 1268*cdf0e10cSrcweir 1269*cdf0e10cSrcweir // append path prefix need for 'GetProperties' call below 1270*cdf0e10cSrcweir String aPrefix( aNode ); 1271*cdf0e10cSrcweir aPrefix.Append( (sal_Unicode) '/' ); 1272*cdf0e10cSrcweir for (int i = 0; i < nLen; ++i) 1273*cdf0e10cSrcweir { 1274*cdf0e10cSrcweir OUString aTmp( aPrefix ); 1275*cdf0e10cSrcweir aTmp += pNames[i]; 1276*cdf0e10cSrcweir pNames[i] = aTmp; 1277*cdf0e10cSrcweir } 1278*cdf0e10cSrcweir 1279*cdf0e10cSrcweir uno::Sequence< uno::Any > aValues( /*aCfg.*/GetProperties( aNames ) ); 1280*cdf0e10cSrcweir if (nLen && nLen == aValues.getLength()) 1281*cdf0e10cSrcweir { 1282*cdf0e10cSrcweir const uno::Any *pValues = aValues.getConstArray(); 1283*cdf0e10cSrcweir for (sal_Int32 i = 0; i < nLen; ++i) 1284*cdf0e10cSrcweir { 1285*cdf0e10cSrcweir uno::Sequence< OUString > aSvcImplNames; 1286*cdf0e10cSrcweir if (pValues[i] >>= aSvcImplNames) 1287*cdf0e10cSrcweir { 1288*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1 1289*cdf0e10cSrcweir // sal_Int32 nSvcs = aSvcImplNames.getLength(); 1290*cdf0e10cSrcweir // const OUString *pSvcImplNames = aSvcImplNames.getConstArray(); 1291*cdf0e10cSrcweir #endif 1292*cdf0e10cSrcweir String aLocaleStr( pNames[i] ); 1293*cdf0e10cSrcweir xub_StrLen nSeperatorPos = aLocaleStr.SearchBackward( sal_Unicode( '/' ) ); 1294*cdf0e10cSrcweir aLocaleStr = aLocaleStr.Copy( nSeperatorPos + 1 ); 1295*cdf0e10cSrcweir lang::Locale aLocale( CreateLocale( MsLangId::convertIsoStringToLanguage(aLocaleStr) ) ); 1296*cdf0e10cSrcweir rThesDsp.SetServiceList( aLocale, aSvcImplNames ); 1297*cdf0e10cSrcweir } 1298*cdf0e10cSrcweir } 1299*cdf0e10cSrcweir } 1300*cdf0e10cSrcweir } 1301*cdf0e10cSrcweir 1302*cdf0e10cSrcweir 1303*cdf0e10cSrcweir uno::Reference< linguistic2::XSpellChecker > SAL_CALL 1304*cdf0e10cSrcweir LngSvcMgr::getSpellChecker() 1305*cdf0e10cSrcweir throw(uno::RuntimeException) 1306*cdf0e10cSrcweir { 1307*cdf0e10cSrcweir osl::MutexGuard aGuard( GetLinguMutex() ); 1308*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1 1309*cdf0e10cSrcweir getAvailableLocales( A2OU( SN_SPELLCHECKER )); 1310*cdf0e10cSrcweir #endif 1311*cdf0e10cSrcweir 1312*cdf0e10cSrcweir uno::Reference< linguistic2::XSpellChecker > xRes; 1313*cdf0e10cSrcweir if (!bDisposing) 1314*cdf0e10cSrcweir { 1315*cdf0e10cSrcweir if (!xSpellDsp.is()) 1316*cdf0e10cSrcweir GetSpellCheckerDsp_Impl(); 1317*cdf0e10cSrcweir xRes = xSpellDsp; 1318*cdf0e10cSrcweir } 1319*cdf0e10cSrcweir return xRes; 1320*cdf0e10cSrcweir } 1321*cdf0e10cSrcweir 1322*cdf0e10cSrcweir 1323*cdf0e10cSrcweir uno::Reference< linguistic2::XHyphenator > SAL_CALL 1324*cdf0e10cSrcweir LngSvcMgr::getHyphenator() 1325*cdf0e10cSrcweir throw(uno::RuntimeException) 1326*cdf0e10cSrcweir { 1327*cdf0e10cSrcweir osl::MutexGuard aGuard( GetLinguMutex() ); 1328*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1 1329*cdf0e10cSrcweir getAvailableLocales( A2OU( SN_HYPHENATOR )); 1330*cdf0e10cSrcweir #endif 1331*cdf0e10cSrcweir 1332*cdf0e10cSrcweir uno::Reference< linguistic2::XHyphenator > xRes; 1333*cdf0e10cSrcweir if (!bDisposing) 1334*cdf0e10cSrcweir { 1335*cdf0e10cSrcweir if (!xHyphDsp.is()) 1336*cdf0e10cSrcweir GetHyphenatorDsp_Impl(); 1337*cdf0e10cSrcweir xRes = xHyphDsp; 1338*cdf0e10cSrcweir } 1339*cdf0e10cSrcweir return xRes; 1340*cdf0e10cSrcweir } 1341*cdf0e10cSrcweir 1342*cdf0e10cSrcweir 1343*cdf0e10cSrcweir uno::Reference< linguistic2::XThesaurus > SAL_CALL 1344*cdf0e10cSrcweir LngSvcMgr::getThesaurus() 1345*cdf0e10cSrcweir throw(uno::RuntimeException) 1346*cdf0e10cSrcweir { 1347*cdf0e10cSrcweir osl::MutexGuard aGuard( GetLinguMutex() ); 1348*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1 1349*cdf0e10cSrcweir getAvailableLocales( A2OU( SN_THESAURUS )); 1350*cdf0e10cSrcweir #endif 1351*cdf0e10cSrcweir 1352*cdf0e10cSrcweir uno::Reference< linguistic2::XThesaurus > xRes; 1353*cdf0e10cSrcweir if (!bDisposing) 1354*cdf0e10cSrcweir { 1355*cdf0e10cSrcweir if (!xThesDsp.is()) 1356*cdf0e10cSrcweir GetThesaurusDsp_Impl(); 1357*cdf0e10cSrcweir xRes = xThesDsp; 1358*cdf0e10cSrcweir } 1359*cdf0e10cSrcweir return xRes; 1360*cdf0e10cSrcweir } 1361*cdf0e10cSrcweir 1362*cdf0e10cSrcweir 1363*cdf0e10cSrcweir sal_Bool SAL_CALL 1364*cdf0e10cSrcweir LngSvcMgr::addLinguServiceManagerListener( 1365*cdf0e10cSrcweir const uno::Reference< lang::XEventListener >& xListener ) 1366*cdf0e10cSrcweir throw(uno::RuntimeException) 1367*cdf0e10cSrcweir { 1368*cdf0e10cSrcweir osl::MutexGuard aGuard( GetLinguMutex() ); 1369*cdf0e10cSrcweir 1370*cdf0e10cSrcweir sal_Bool bRes = sal_False; 1371*cdf0e10cSrcweir if (!bDisposing && xListener.is()) 1372*cdf0e10cSrcweir { 1373*cdf0e10cSrcweir if (!pListenerHelper) 1374*cdf0e10cSrcweir GetListenerHelper_Impl(); 1375*cdf0e10cSrcweir bRes = pListenerHelper->AddLngSvcMgrListener( xListener ); 1376*cdf0e10cSrcweir } 1377*cdf0e10cSrcweir return bRes; 1378*cdf0e10cSrcweir } 1379*cdf0e10cSrcweir 1380*cdf0e10cSrcweir 1381*cdf0e10cSrcweir sal_Bool SAL_CALL 1382*cdf0e10cSrcweir LngSvcMgr::removeLinguServiceManagerListener( 1383*cdf0e10cSrcweir const uno::Reference< lang::XEventListener >& xListener ) 1384*cdf0e10cSrcweir throw(uno::RuntimeException) 1385*cdf0e10cSrcweir { 1386*cdf0e10cSrcweir osl::MutexGuard aGuard( GetLinguMutex() ); 1387*cdf0e10cSrcweir 1388*cdf0e10cSrcweir sal_Bool bRes = sal_False; 1389*cdf0e10cSrcweir if (!bDisposing && xListener.is()) 1390*cdf0e10cSrcweir { 1391*cdf0e10cSrcweir DBG_ASSERT( pListenerHelper, "listener removed without being added" ); 1392*cdf0e10cSrcweir if (!pListenerHelper) 1393*cdf0e10cSrcweir GetListenerHelper_Impl(); 1394*cdf0e10cSrcweir bRes = pListenerHelper->RemoveLngSvcMgrListener( xListener ); 1395*cdf0e10cSrcweir } 1396*cdf0e10cSrcweir return bRes; 1397*cdf0e10cSrcweir } 1398*cdf0e10cSrcweir 1399*cdf0e10cSrcweir 1400*cdf0e10cSrcweir uno::Sequence< OUString > SAL_CALL 1401*cdf0e10cSrcweir LngSvcMgr::getAvailableServices( 1402*cdf0e10cSrcweir const OUString& rServiceName, 1403*cdf0e10cSrcweir const lang::Locale& rLocale ) 1404*cdf0e10cSrcweir throw(uno::RuntimeException) 1405*cdf0e10cSrcweir { 1406*cdf0e10cSrcweir osl::MutexGuard aGuard( GetLinguMutex() ); 1407*cdf0e10cSrcweir 1408*cdf0e10cSrcweir uno::Sequence< OUString > aRes; 1409*cdf0e10cSrcweir const SvcInfoArray *pInfoArray = 0; 1410*cdf0e10cSrcweir 1411*cdf0e10cSrcweir if (0 == rServiceName.compareToAscii( SN_SPELLCHECKER )) 1412*cdf0e10cSrcweir { 1413*cdf0e10cSrcweir // don't used cached data here (force re-evaluation in order to have downloaded dictionaries 1414*cdf0e10cSrcweir // already found without the need to restart the office 1415*cdf0e10cSrcweir clearSvcInfoArray(pAvailSpellSvcs); pAvailSpellSvcs = 0; 1416*cdf0e10cSrcweir GetAvailableSpellSvcs_Impl(); 1417*cdf0e10cSrcweir pInfoArray = pAvailSpellSvcs; 1418*cdf0e10cSrcweir } 1419*cdf0e10cSrcweir else if (0 == rServiceName.compareToAscii( SN_GRAMMARCHECKER )) 1420*cdf0e10cSrcweir { 1421*cdf0e10cSrcweir // don't used cached data here (force re-evaluation in order to have downloaded dictionaries 1422*cdf0e10cSrcweir // already found without the need to restart the office 1423*cdf0e10cSrcweir clearSvcInfoArray(pAvailGrammarSvcs); pAvailGrammarSvcs = 0; 1424*cdf0e10cSrcweir GetAvailableGrammarSvcs_Impl(); 1425*cdf0e10cSrcweir pInfoArray = pAvailGrammarSvcs; 1426*cdf0e10cSrcweir } 1427*cdf0e10cSrcweir else if (0 == rServiceName.compareToAscii( SN_HYPHENATOR )) 1428*cdf0e10cSrcweir { 1429*cdf0e10cSrcweir // don't used cached data here (force re-evaluation in order to have downloaded dictionaries 1430*cdf0e10cSrcweir // already found without the need to restart the office 1431*cdf0e10cSrcweir clearSvcInfoArray(pAvailHyphSvcs); pAvailHyphSvcs = 0; 1432*cdf0e10cSrcweir GetAvailableHyphSvcs_Impl(); 1433*cdf0e10cSrcweir pInfoArray = pAvailHyphSvcs; 1434*cdf0e10cSrcweir } 1435*cdf0e10cSrcweir else if (0 == rServiceName.compareToAscii( SN_THESAURUS )) 1436*cdf0e10cSrcweir { 1437*cdf0e10cSrcweir // don't used cached data here (force re-evaluation in order to have downloaded dictionaries 1438*cdf0e10cSrcweir // already found without the need to restart the office 1439*cdf0e10cSrcweir clearSvcInfoArray(pAvailThesSvcs); pAvailThesSvcs = 0; 1440*cdf0e10cSrcweir GetAvailableThesSvcs_Impl(); 1441*cdf0e10cSrcweir pInfoArray = pAvailThesSvcs; 1442*cdf0e10cSrcweir } 1443*cdf0e10cSrcweir 1444*cdf0e10cSrcweir if (pInfoArray) 1445*cdf0e10cSrcweir { 1446*cdf0e10cSrcweir // resize to max number of entries 1447*cdf0e10cSrcweir size_t nMaxCnt = pInfoArray->size(); 1448*cdf0e10cSrcweir aRes.realloc( nMaxCnt ); 1449*cdf0e10cSrcweir OUString *pImplName = aRes.getArray(); 1450*cdf0e10cSrcweir 1451*cdf0e10cSrcweir sal_uInt16 nCnt = 0; 1452*cdf0e10cSrcweir LanguageType nLanguage = LocaleToLanguage( rLocale ); 1453*cdf0e10cSrcweir for (size_t i = 0; i < nMaxCnt; ++i) 1454*cdf0e10cSrcweir { 1455*cdf0e10cSrcweir const SvcInfo *pInfo = (*pInfoArray)[i]; 1456*cdf0e10cSrcweir if (LANGUAGE_NONE == nLanguage 1457*cdf0e10cSrcweir || (pInfo && pInfo->HasLanguage( nLanguage ))) 1458*cdf0e10cSrcweir { 1459*cdf0e10cSrcweir pImplName[ nCnt++ ] = pInfo->aSvcImplName; 1460*cdf0e10cSrcweir } 1461*cdf0e10cSrcweir } 1462*cdf0e10cSrcweir 1463*cdf0e10cSrcweir // resize to actual number of entries 1464*cdf0e10cSrcweir if (nCnt != nMaxCnt) 1465*cdf0e10cSrcweir aRes.realloc( nCnt ); 1466*cdf0e10cSrcweir } 1467*cdf0e10cSrcweir 1468*cdf0e10cSrcweir return aRes; 1469*cdf0e10cSrcweir } 1470*cdf0e10cSrcweir 1471*cdf0e10cSrcweir 1472*cdf0e10cSrcweir uno::Sequence< lang::Locale > SAL_CALL 1473*cdf0e10cSrcweir LngSvcMgr::getAvailableLocales( 1474*cdf0e10cSrcweir const OUString& rServiceName ) 1475*cdf0e10cSrcweir throw(uno::RuntimeException) 1476*cdf0e10cSrcweir { 1477*cdf0e10cSrcweir osl::MutexGuard aGuard( GetLinguMutex() ); 1478*cdf0e10cSrcweir 1479*cdf0e10cSrcweir uno::Sequence< lang::Locale > aRes; 1480*cdf0e10cSrcweir 1481*cdf0e10cSrcweir uno::Sequence< lang::Locale > *pAvailLocales = NULL; 1482*cdf0e10cSrcweir sal_Bool *pHasAvailLocales = NULL; 1483*cdf0e10cSrcweir if (0 == rServiceName.compareToAscii( SN_SPELLCHECKER )) 1484*cdf0e10cSrcweir { 1485*cdf0e10cSrcweir pAvailLocales = &aAvailSpellLocales; 1486*cdf0e10cSrcweir pHasAvailLocales = &bHasAvailSpellLocales; 1487*cdf0e10cSrcweir } 1488*cdf0e10cSrcweir else if (0 == rServiceName.compareToAscii( SN_GRAMMARCHECKER )) 1489*cdf0e10cSrcweir { 1490*cdf0e10cSrcweir pAvailLocales = &aAvailGrammarLocales; 1491*cdf0e10cSrcweir pHasAvailLocales = &bHasAvailGrammarLocales; 1492*cdf0e10cSrcweir } 1493*cdf0e10cSrcweir else if (0 == rServiceName.compareToAscii( SN_HYPHENATOR )) 1494*cdf0e10cSrcweir { 1495*cdf0e10cSrcweir pAvailLocales = &aAvailHyphLocales; 1496*cdf0e10cSrcweir pHasAvailLocales = &bHasAvailHyphLocales; 1497*cdf0e10cSrcweir } 1498*cdf0e10cSrcweir else if (0 == rServiceName.compareToAscii( SN_THESAURUS )) 1499*cdf0e10cSrcweir { 1500*cdf0e10cSrcweir pAvailLocales = &aAvailThesLocales; 1501*cdf0e10cSrcweir pHasAvailLocales = &bHasAvailThesLocales; 1502*cdf0e10cSrcweir } 1503*cdf0e10cSrcweir 1504*cdf0e10cSrcweir // about pHasAvailLocales: nowadays (with OOo lingu in SO) we want to know immediately about 1505*cdf0e10cSrcweir // new downloaded dictionaries and have them ready right away if the Tools/Options... 1506*cdf0e10cSrcweir // is used to activate them. Thus we can not rely anymore on buffered data. 1507*cdf0e10cSrcweir if (pAvailLocales /*&& pHasAvailLocales */) 1508*cdf0e10cSrcweir { 1509*cdf0e10cSrcweir // if (!*pHasAvailLocales) 1510*cdf0e10cSrcweir // { 1511*cdf0e10cSrcweir *pAvailLocales = GetAvailLocales( 1512*cdf0e10cSrcweir getAvailableServices( rServiceName, lang::Locale() ) ); 1513*cdf0e10cSrcweir // *pHasAvailLocales = sal_True; 1514*cdf0e10cSrcweir // } 1515*cdf0e10cSrcweir aRes = *pAvailLocales; 1516*cdf0e10cSrcweir } 1517*cdf0e10cSrcweir 1518*cdf0e10cSrcweir return aRes; 1519*cdf0e10cSrcweir } 1520*cdf0e10cSrcweir 1521*cdf0e10cSrcweir static sal_Bool IsEqSvcList( const uno::Sequence< OUString > &rList1, 1522*cdf0e10cSrcweir const uno::Sequence< OUString > &rList2 ) 1523*cdf0e10cSrcweir { 1524*cdf0e10cSrcweir // returns sal_True iff both sequences are equal 1525*cdf0e10cSrcweir 1526*cdf0e10cSrcweir sal_Bool bRes = sal_False; 1527*cdf0e10cSrcweir sal_Int32 nLen = rList1.getLength(); 1528*cdf0e10cSrcweir if (rList2.getLength() == nLen) 1529*cdf0e10cSrcweir { 1530*cdf0e10cSrcweir const OUString *pStr1 = rList1.getConstArray(); 1531*cdf0e10cSrcweir const OUString *pStr2 = rList2.getConstArray(); 1532*cdf0e10cSrcweir bRes = sal_True; 1533*cdf0e10cSrcweir for (sal_Int32 i = 0; i < nLen && bRes; ++i) 1534*cdf0e10cSrcweir { 1535*cdf0e10cSrcweir if (*pStr1++ != *pStr2++) 1536*cdf0e10cSrcweir bRes = sal_False; 1537*cdf0e10cSrcweir } 1538*cdf0e10cSrcweir } 1539*cdf0e10cSrcweir return bRes; 1540*cdf0e10cSrcweir } 1541*cdf0e10cSrcweir 1542*cdf0e10cSrcweir 1543*cdf0e10cSrcweir void SAL_CALL 1544*cdf0e10cSrcweir LngSvcMgr::setConfiguredServices( 1545*cdf0e10cSrcweir const OUString& rServiceName, 1546*cdf0e10cSrcweir const lang::Locale& rLocale, 1547*cdf0e10cSrcweir const uno::Sequence< OUString >& rServiceImplNames ) 1548*cdf0e10cSrcweir throw(uno::RuntimeException) 1549*cdf0e10cSrcweir { 1550*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "linguistic: LngSvcMgr::setConfiguredServices" ); 1551*cdf0e10cSrcweir 1552*cdf0e10cSrcweir osl::MutexGuard aGuard( GetLinguMutex() ); 1553*cdf0e10cSrcweir 1554*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1 1555*cdf0e10cSrcweir // const OUString *pImplNames = rServiceImplNames.getConstArray(); 1556*cdf0e10cSrcweir #endif 1557*cdf0e10cSrcweir 1558*cdf0e10cSrcweir LanguageType nLanguage = LocaleToLanguage( rLocale ); 1559*cdf0e10cSrcweir if (LANGUAGE_NONE != nLanguage) 1560*cdf0e10cSrcweir { 1561*cdf0e10cSrcweir if (0 == rServiceName.compareToAscii( SN_SPELLCHECKER )) 1562*cdf0e10cSrcweir { 1563*cdf0e10cSrcweir if (!xSpellDsp.is()) 1564*cdf0e10cSrcweir GetSpellCheckerDsp_Impl(); 1565*cdf0e10cSrcweir sal_Bool bChanged = !IsEqSvcList( rServiceImplNames, 1566*cdf0e10cSrcweir pSpellDsp->GetServiceList( rLocale ) ); 1567*cdf0e10cSrcweir if (bChanged) 1568*cdf0e10cSrcweir { 1569*cdf0e10cSrcweir pSpellDsp->SetServiceList( rLocale, rServiceImplNames ); 1570*cdf0e10cSrcweir SaveCfgSvcs( A2OU( SN_SPELLCHECKER ) ); 1571*cdf0e10cSrcweir 1572*cdf0e10cSrcweir if (pListenerHelper && bChanged) 1573*cdf0e10cSrcweir pListenerHelper->AddLngSvcEvt( 1574*cdf0e10cSrcweir linguistic2::LinguServiceEventFlags::SPELL_CORRECT_WORDS_AGAIN | 1575*cdf0e10cSrcweir linguistic2::LinguServiceEventFlags::SPELL_WRONG_WORDS_AGAIN ); 1576*cdf0e10cSrcweir } 1577*cdf0e10cSrcweir } 1578*cdf0e10cSrcweir else if (0 == rServiceName.compareToAscii( SN_GRAMMARCHECKER )) 1579*cdf0e10cSrcweir { 1580*cdf0e10cSrcweir if (!xGrammarDsp.is()) 1581*cdf0e10cSrcweir GetGrammarCheckerDsp_Impl(); 1582*cdf0e10cSrcweir sal_Bool bChanged = !IsEqSvcList( rServiceImplNames, 1583*cdf0e10cSrcweir pGrammarDsp->GetServiceList( rLocale ) ); 1584*cdf0e10cSrcweir if (bChanged) 1585*cdf0e10cSrcweir { 1586*cdf0e10cSrcweir pGrammarDsp->SetServiceList( rLocale, rServiceImplNames ); 1587*cdf0e10cSrcweir SaveCfgSvcs( A2OU( SN_GRAMMARCHECKER ) ); 1588*cdf0e10cSrcweir 1589*cdf0e10cSrcweir if (pListenerHelper && bChanged) 1590*cdf0e10cSrcweir pListenerHelper->AddLngSvcEvt( 1591*cdf0e10cSrcweir linguistic2::LinguServiceEventFlags::PROOFREAD_AGAIN ); 1592*cdf0e10cSrcweir } 1593*cdf0e10cSrcweir } 1594*cdf0e10cSrcweir else if (0 == rServiceName.compareToAscii( SN_HYPHENATOR )) 1595*cdf0e10cSrcweir { 1596*cdf0e10cSrcweir if (!xHyphDsp.is()) 1597*cdf0e10cSrcweir GetHyphenatorDsp_Impl(); 1598*cdf0e10cSrcweir sal_Bool bChanged = !IsEqSvcList( rServiceImplNames, 1599*cdf0e10cSrcweir pHyphDsp->GetServiceList( rLocale ) ); 1600*cdf0e10cSrcweir if (bChanged) 1601*cdf0e10cSrcweir { 1602*cdf0e10cSrcweir pHyphDsp->SetServiceList( rLocale, rServiceImplNames ); 1603*cdf0e10cSrcweir SaveCfgSvcs( A2OU( SN_HYPHENATOR ) ); 1604*cdf0e10cSrcweir 1605*cdf0e10cSrcweir if (pListenerHelper && bChanged) 1606*cdf0e10cSrcweir pListenerHelper->AddLngSvcEvt( 1607*cdf0e10cSrcweir linguistic2::LinguServiceEventFlags::HYPHENATE_AGAIN ); 1608*cdf0e10cSrcweir } 1609*cdf0e10cSrcweir } 1610*cdf0e10cSrcweir else if (0 == rServiceName.compareToAscii( SN_THESAURUS )) 1611*cdf0e10cSrcweir { 1612*cdf0e10cSrcweir if (!xThesDsp.is()) 1613*cdf0e10cSrcweir GetThesaurusDsp_Impl(); 1614*cdf0e10cSrcweir sal_Bool bChanged = !IsEqSvcList( rServiceImplNames, 1615*cdf0e10cSrcweir pThesDsp->GetServiceList( rLocale ) ); 1616*cdf0e10cSrcweir if (bChanged) 1617*cdf0e10cSrcweir { 1618*cdf0e10cSrcweir pThesDsp->SetServiceList( rLocale, rServiceImplNames ); 1619*cdf0e10cSrcweir SaveCfgSvcs( A2OU( SN_THESAURUS ) ); 1620*cdf0e10cSrcweir } 1621*cdf0e10cSrcweir } 1622*cdf0e10cSrcweir } 1623*cdf0e10cSrcweir } 1624*cdf0e10cSrcweir 1625*cdf0e10cSrcweir 1626*cdf0e10cSrcweir sal_Bool LngSvcMgr::SaveCfgSvcs( const String &rServiceName ) 1627*cdf0e10cSrcweir { 1628*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "linguistic: LngSvcMgr::SaveCfgSvcs" ); 1629*cdf0e10cSrcweir 1630*cdf0e10cSrcweir sal_Bool bRes = sal_False; 1631*cdf0e10cSrcweir 1632*cdf0e10cSrcweir LinguDispatcher *pDsp = 0; 1633*cdf0e10cSrcweir uno::Sequence< lang::Locale > aLocales; 1634*cdf0e10cSrcweir 1635*cdf0e10cSrcweir if (0 == rServiceName.CompareToAscii( SN_SPELLCHECKER )) 1636*cdf0e10cSrcweir { 1637*cdf0e10cSrcweir if (!pSpellDsp) 1638*cdf0e10cSrcweir GetSpellCheckerDsp_Impl(); 1639*cdf0e10cSrcweir pDsp = pSpellDsp; 1640*cdf0e10cSrcweir aLocales = getAvailableLocales( A2OU( SN_SPELLCHECKER ) ); 1641*cdf0e10cSrcweir } 1642*cdf0e10cSrcweir else if (0 == rServiceName.CompareToAscii( SN_GRAMMARCHECKER )) 1643*cdf0e10cSrcweir { 1644*cdf0e10cSrcweir if (!pGrammarDsp) 1645*cdf0e10cSrcweir GetGrammarCheckerDsp_Impl(); 1646*cdf0e10cSrcweir pDsp = pGrammarDsp; 1647*cdf0e10cSrcweir aLocales = getAvailableLocales( A2OU( SN_GRAMMARCHECKER ) ); 1648*cdf0e10cSrcweir } 1649*cdf0e10cSrcweir else if (0 == rServiceName.CompareToAscii( SN_HYPHENATOR )) 1650*cdf0e10cSrcweir { 1651*cdf0e10cSrcweir if (!pHyphDsp) 1652*cdf0e10cSrcweir GetHyphenatorDsp_Impl(); 1653*cdf0e10cSrcweir pDsp = pHyphDsp; 1654*cdf0e10cSrcweir aLocales = getAvailableLocales( A2OU( SN_HYPHENATOR ) ); 1655*cdf0e10cSrcweir } 1656*cdf0e10cSrcweir else if (0 == rServiceName.CompareToAscii( SN_THESAURUS )) 1657*cdf0e10cSrcweir { 1658*cdf0e10cSrcweir if (!pThesDsp) 1659*cdf0e10cSrcweir GetThesaurusDsp_Impl(); 1660*cdf0e10cSrcweir pDsp = pThesDsp; 1661*cdf0e10cSrcweir aLocales = getAvailableLocales( A2OU( SN_THESAURUS ) ); 1662*cdf0e10cSrcweir } 1663*cdf0e10cSrcweir 1664*cdf0e10cSrcweir if (pDsp && aLocales.getLength()) 1665*cdf0e10cSrcweir { 1666*cdf0e10cSrcweir sal_Int32 nLen = aLocales.getLength(); 1667*cdf0e10cSrcweir const lang::Locale *pLocale = aLocales.getConstArray(); 1668*cdf0e10cSrcweir 1669*cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > aValues( nLen ); 1670*cdf0e10cSrcweir beans::PropertyValue *pValues = aValues.getArray(); 1671*cdf0e10cSrcweir beans::PropertyValue *pValue = pValues; 1672*cdf0e10cSrcweir 1673*cdf0e10cSrcweir // get node name to be used 1674*cdf0e10cSrcweir const char *pNodeName = NULL; 1675*cdf0e10cSrcweir if (pDsp == pSpellDsp) 1676*cdf0e10cSrcweir pNodeName = "ServiceManager/SpellCheckerList"; 1677*cdf0e10cSrcweir else if (pDsp == pGrammarDsp) 1678*cdf0e10cSrcweir pNodeName = "ServiceManager/GrammarCheckerList"; 1679*cdf0e10cSrcweir else if (pDsp == pHyphDsp) 1680*cdf0e10cSrcweir pNodeName = "ServiceManager/HyphenatorList"; 1681*cdf0e10cSrcweir else if (pDsp == pThesDsp) 1682*cdf0e10cSrcweir pNodeName = "ServiceManager/ThesaurusList"; 1683*cdf0e10cSrcweir else 1684*cdf0e10cSrcweir { 1685*cdf0e10cSrcweir DBG_ASSERT( 0, "node name missing" ); 1686*cdf0e10cSrcweir } 1687*cdf0e10cSrcweir OUString aNodeName( A2OU(pNodeName) ); 1688*cdf0e10cSrcweir 1689*cdf0e10cSrcweir for (sal_Int32 i = 0; i < nLen; ++i) 1690*cdf0e10cSrcweir { 1691*cdf0e10cSrcweir uno::Sequence< OUString > aSvcImplNames; 1692*cdf0e10cSrcweir aSvcImplNames = pDsp->GetServiceList( pLocale[i] ); 1693*cdf0e10cSrcweir 1694*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1 1695*cdf0e10cSrcweir sal_Int32 nSvcs = aSvcImplNames.getLength(); 1696*cdf0e10cSrcweir const OUString *pSvcImplName = aSvcImplNames.getConstArray(); 1697*cdf0e10cSrcweir for (sal_Int32 j = 0; j < nSvcs; ++j) 1698*cdf0e10cSrcweir { 1699*cdf0e10cSrcweir OUString aImplName( pSvcImplName[j] ); 1700*cdf0e10cSrcweir } 1701*cdf0e10cSrcweir #endif 1702*cdf0e10cSrcweir // build value to be written back to configuration 1703*cdf0e10cSrcweir uno::Any aCfgAny; 1704*cdf0e10cSrcweir if ((pDsp == pHyphDsp || pDsp == pGrammarDsp) && aSvcImplNames.getLength() > 1) 1705*cdf0e10cSrcweir aSvcImplNames.realloc(1); // there should be only one entry for hyphenators or grammar checkers (because they are not chained) 1706*cdf0e10cSrcweir aCfgAny <<= aSvcImplNames; 1707*cdf0e10cSrcweir DBG_ASSERT( aCfgAny.hasValue(), "missing value for 'Any' type" ); 1708*cdf0e10cSrcweir 1709*cdf0e10cSrcweir OUString aCfgLocaleStr( MsLangId::convertLanguageToIsoString( 1710*cdf0e10cSrcweir LocaleToLanguage( pLocale[i] ) ) ); 1711*cdf0e10cSrcweir pValue->Value = aCfgAny; 1712*cdf0e10cSrcweir pValue->Name = aNodeName; 1713*cdf0e10cSrcweir pValue->Name += OUString::valueOf( (sal_Unicode) '/' ); 1714*cdf0e10cSrcweir pValue->Name += aCfgLocaleStr; 1715*cdf0e10cSrcweir pValue++; 1716*cdf0e10cSrcweir } 1717*cdf0e10cSrcweir { 1718*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "linguistic: LngSvcMgr::SaveCfgSvcs - ReplaceSetProperties" ); 1719*cdf0e10cSrcweir // change, add new or replace existing entries. 1720*cdf0e10cSrcweir bRes |= /*aCfg.*/ReplaceSetProperties( aNodeName, aValues ); 1721*cdf0e10cSrcweir } 1722*cdf0e10cSrcweir } 1723*cdf0e10cSrcweir 1724*cdf0e10cSrcweir return bRes; 1725*cdf0e10cSrcweir } 1726*cdf0e10cSrcweir 1727*cdf0e10cSrcweir 1728*cdf0e10cSrcweir static uno::Sequence< OUString > GetLangSvcList( const uno::Any &rVal ) 1729*cdf0e10cSrcweir { 1730*cdf0e10cSrcweir uno::Sequence< OUString > aRes; 1731*cdf0e10cSrcweir 1732*cdf0e10cSrcweir if (rVal.hasValue()) 1733*cdf0e10cSrcweir { 1734*cdf0e10cSrcweir rVal >>= aRes; 1735*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1 1736*cdf0e10cSrcweir sal_Int32 nSvcs = aRes.getLength(); 1737*cdf0e10cSrcweir if (nSvcs) 1738*cdf0e10cSrcweir { 1739*cdf0e10cSrcweir const OUString *pSvcName = aRes.getConstArray(); 1740*cdf0e10cSrcweir for (sal_Int32 j = 0; j < nSvcs; ++j) 1741*cdf0e10cSrcweir { 1742*cdf0e10cSrcweir OUString aImplName( pSvcName[j] ); 1743*cdf0e10cSrcweir DBG_ASSERT( aImplName.getLength(), "service impl-name missing" ); 1744*cdf0e10cSrcweir } 1745*cdf0e10cSrcweir } 1746*cdf0e10cSrcweir #endif 1747*cdf0e10cSrcweir } 1748*cdf0e10cSrcweir 1749*cdf0e10cSrcweir return aRes; 1750*cdf0e10cSrcweir } 1751*cdf0e10cSrcweir 1752*cdf0e10cSrcweir 1753*cdf0e10cSrcweir static uno::Sequence< OUString > GetLangSvc( const uno::Any &rVal ) 1754*cdf0e10cSrcweir { 1755*cdf0e10cSrcweir uno::Sequence< OUString > aRes; 1756*cdf0e10cSrcweir if (!rVal.hasValue()) 1757*cdf0e10cSrcweir return aRes; 1758*cdf0e10cSrcweir 1759*cdf0e10cSrcweir // allowing for a sequence here as well (even though it should only 1760*cdf0e10cSrcweir // be a string) makes coding easier in other places since one needs 1761*cdf0e10cSrcweir // not make a special case for writing a string only and not a 1762*cdf0e10cSrcweir // sequence of strings. 1763*cdf0e10cSrcweir if (rVal >>= aRes) 1764*cdf0e10cSrcweir { 1765*cdf0e10cSrcweir // but only the first string should be used. 1766*cdf0e10cSrcweir if (aRes.getLength() > 1) 1767*cdf0e10cSrcweir aRes.realloc(1); 1768*cdf0e10cSrcweir } 1769*cdf0e10cSrcweir else 1770*cdf0e10cSrcweir { 1771*cdf0e10cSrcweir OUString aImplName; 1772*cdf0e10cSrcweir if ((rVal >>= aImplName) && aImplName.getLength() != 0) 1773*cdf0e10cSrcweir { 1774*cdf0e10cSrcweir aRes.realloc(1); 1775*cdf0e10cSrcweir aRes.getArray()[0] = aImplName; 1776*cdf0e10cSrcweir } 1777*cdf0e10cSrcweir else 1778*cdf0e10cSrcweir { 1779*cdf0e10cSrcweir DBG_ASSERT( 0, "GetLangSvc: unexpected type encountered" ); 1780*cdf0e10cSrcweir } 1781*cdf0e10cSrcweir } 1782*cdf0e10cSrcweir 1783*cdf0e10cSrcweir return aRes; 1784*cdf0e10cSrcweir } 1785*cdf0e10cSrcweir 1786*cdf0e10cSrcweir 1787*cdf0e10cSrcweir /////////////////////////////////////////////////////////////////////////// 1788*cdf0e10cSrcweir 1789*cdf0e10cSrcweir uno::Sequence< OUString > SAL_CALL 1790*cdf0e10cSrcweir LngSvcMgr::getConfiguredServices( 1791*cdf0e10cSrcweir const OUString& rServiceName, 1792*cdf0e10cSrcweir const lang::Locale& rLocale ) 1793*cdf0e10cSrcweir throw(uno::RuntimeException) 1794*cdf0e10cSrcweir { 1795*cdf0e10cSrcweir osl::MutexGuard aGuard( GetLinguMutex() ); 1796*cdf0e10cSrcweir 1797*cdf0e10cSrcweir uno::Sequence< OUString > aSvcImplNames; 1798*cdf0e10cSrcweir 1799*cdf0e10cSrcweir LanguageType nLanguage = LocaleToLanguage( rLocale ); 1800*cdf0e10cSrcweir OUString aCfgLocale( MsLangId::convertLanguageToIsoString( nLanguage ) ); 1801*cdf0e10cSrcweir 1802*cdf0e10cSrcweir uno::Sequence< uno::Any > aValues; 1803*cdf0e10cSrcweir uno::Sequence< OUString > aNames( 1 ); 1804*cdf0e10cSrcweir OUString *pNames = aNames.getArray(); 1805*cdf0e10cSrcweir if ( 0 == rServiceName.compareToAscii( SN_SPELLCHECKER ) ) 1806*cdf0e10cSrcweir { 1807*cdf0e10cSrcweir OUString aNode( OUString::createFromAscii( "ServiceManager/SpellCheckerList" )); 1808*cdf0e10cSrcweir const uno::Sequence< OUString > aNodeEntries( GetNodeNames( aNode ) ); 1809*cdf0e10cSrcweir if (lcl_SeqHasString( aNodeEntries, aCfgLocale )) 1810*cdf0e10cSrcweir { 1811*cdf0e10cSrcweir OUString aPropName( aNode ); 1812*cdf0e10cSrcweir aPropName += OUString::valueOf( (sal_Unicode) '/' ); 1813*cdf0e10cSrcweir aPropName += aCfgLocale; 1814*cdf0e10cSrcweir pNames[0] = aPropName; 1815*cdf0e10cSrcweir aValues = /*aCfg.*/GetProperties( aNames ); 1816*cdf0e10cSrcweir if (aValues.getLength()) 1817*cdf0e10cSrcweir aSvcImplNames = GetLangSvcList( aValues.getConstArray()[0] ); 1818*cdf0e10cSrcweir } 1819*cdf0e10cSrcweir } 1820*cdf0e10cSrcweir else if ( 0 == rServiceName.compareToAscii( SN_GRAMMARCHECKER ) ) 1821*cdf0e10cSrcweir { 1822*cdf0e10cSrcweir OUString aNode( OUString::createFromAscii( "ServiceManager/GrammarCheckerList" )); 1823*cdf0e10cSrcweir const uno::Sequence< OUString > aNodeEntries( GetNodeNames( aNode ) ); 1824*cdf0e10cSrcweir if (lcl_SeqHasString( aNodeEntries, aCfgLocale )) 1825*cdf0e10cSrcweir { 1826*cdf0e10cSrcweir OUString aPropName( aNode ); 1827*cdf0e10cSrcweir aPropName += OUString::valueOf( (sal_Unicode) '/' ); 1828*cdf0e10cSrcweir aPropName += aCfgLocale; 1829*cdf0e10cSrcweir pNames[0] = aPropName; 1830*cdf0e10cSrcweir aValues = /*aCfg.*/GetProperties( aNames ); 1831*cdf0e10cSrcweir if (aValues.getLength()) 1832*cdf0e10cSrcweir aSvcImplNames = GetLangSvc( aValues.getConstArray()[0] ); 1833*cdf0e10cSrcweir } 1834*cdf0e10cSrcweir } 1835*cdf0e10cSrcweir else if ( 0 == rServiceName.compareToAscii( SN_HYPHENATOR ) ) 1836*cdf0e10cSrcweir { 1837*cdf0e10cSrcweir OUString aNode( OUString::createFromAscii( "ServiceManager/HyphenatorList" )); 1838*cdf0e10cSrcweir const uno::Sequence< OUString > aNodeEntries( GetNodeNames( aNode ) ); 1839*cdf0e10cSrcweir if (lcl_SeqHasString( aNodeEntries, aCfgLocale )) 1840*cdf0e10cSrcweir { 1841*cdf0e10cSrcweir OUString aPropName( aNode ); 1842*cdf0e10cSrcweir aPropName += OUString::valueOf( (sal_Unicode) '/' ); 1843*cdf0e10cSrcweir aPropName += aCfgLocale; 1844*cdf0e10cSrcweir pNames[0] = aPropName; 1845*cdf0e10cSrcweir aValues = /*aCfg.*/GetProperties( aNames ); 1846*cdf0e10cSrcweir if (aValues.getLength()) 1847*cdf0e10cSrcweir aSvcImplNames = GetLangSvc( aValues.getConstArray()[0] ); 1848*cdf0e10cSrcweir } 1849*cdf0e10cSrcweir } 1850*cdf0e10cSrcweir else if ( 0 == rServiceName.compareToAscii( SN_THESAURUS ) ) 1851*cdf0e10cSrcweir { 1852*cdf0e10cSrcweir OUString aNode( OUString::createFromAscii( "ServiceManager/ThesaurusList" )); 1853*cdf0e10cSrcweir const uno::Sequence< OUString > aNodeEntries( GetNodeNames( aNode ) ); 1854*cdf0e10cSrcweir if (lcl_SeqHasString( aNodeEntries, aCfgLocale )) 1855*cdf0e10cSrcweir { 1856*cdf0e10cSrcweir OUString aPropName( aNode ); 1857*cdf0e10cSrcweir aPropName += OUString::valueOf( (sal_Unicode) '/' ); 1858*cdf0e10cSrcweir aPropName += aCfgLocale; 1859*cdf0e10cSrcweir pNames[0] = aPropName; 1860*cdf0e10cSrcweir aValues = /*aCfg.*/GetProperties( aNames ); 1861*cdf0e10cSrcweir if (aValues.getLength()) 1862*cdf0e10cSrcweir aSvcImplNames = GetLangSvcList( aValues.getConstArray()[0] ); 1863*cdf0e10cSrcweir } 1864*cdf0e10cSrcweir } 1865*cdf0e10cSrcweir 1866*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1 1867*cdf0e10cSrcweir const OUString *pImplNames = aSvcImplNames.getConstArray(); 1868*cdf0e10cSrcweir (void) pImplNames; 1869*cdf0e10cSrcweir #endif 1870*cdf0e10cSrcweir return aSvcImplNames; 1871*cdf0e10cSrcweir } 1872*cdf0e10cSrcweir 1873*cdf0e10cSrcweir 1874*cdf0e10cSrcweir void SAL_CALL 1875*cdf0e10cSrcweir LngSvcMgr::dispose() 1876*cdf0e10cSrcweir throw(uno::RuntimeException) 1877*cdf0e10cSrcweir { 1878*cdf0e10cSrcweir osl::MutexGuard aGuard( GetLinguMutex() ); 1879*cdf0e10cSrcweir 1880*cdf0e10cSrcweir if (!bDisposing) 1881*cdf0e10cSrcweir { 1882*cdf0e10cSrcweir bDisposing = sal_True; 1883*cdf0e10cSrcweir 1884*cdf0e10cSrcweir // require listeners to release this object 1885*cdf0e10cSrcweir lang::EventObject aEvtObj( (XLinguServiceManager *) this ); 1886*cdf0e10cSrcweir aEvtListeners.disposeAndClear( aEvtObj ); 1887*cdf0e10cSrcweir 1888*cdf0e10cSrcweir if (pListenerHelper) 1889*cdf0e10cSrcweir pListenerHelper->DisposeAndClear( aEvtObj ); 1890*cdf0e10cSrcweir } 1891*cdf0e10cSrcweir } 1892*cdf0e10cSrcweir 1893*cdf0e10cSrcweir 1894*cdf0e10cSrcweir void SAL_CALL 1895*cdf0e10cSrcweir LngSvcMgr::addEventListener( 1896*cdf0e10cSrcweir const uno::Reference< lang::XEventListener >& xListener ) 1897*cdf0e10cSrcweir throw(uno::RuntimeException) 1898*cdf0e10cSrcweir { 1899*cdf0e10cSrcweir osl::MutexGuard aGuard( GetLinguMutex() ); 1900*cdf0e10cSrcweir 1901*cdf0e10cSrcweir if (!bDisposing && xListener.is()) 1902*cdf0e10cSrcweir { 1903*cdf0e10cSrcweir aEvtListeners.addInterface( xListener ); 1904*cdf0e10cSrcweir } 1905*cdf0e10cSrcweir } 1906*cdf0e10cSrcweir 1907*cdf0e10cSrcweir 1908*cdf0e10cSrcweir void SAL_CALL 1909*cdf0e10cSrcweir LngSvcMgr::removeEventListener( 1910*cdf0e10cSrcweir const uno::Reference< lang::XEventListener >& xListener ) 1911*cdf0e10cSrcweir throw(uno::RuntimeException) 1912*cdf0e10cSrcweir { 1913*cdf0e10cSrcweir osl::MutexGuard aGuard( GetLinguMutex() ); 1914*cdf0e10cSrcweir 1915*cdf0e10cSrcweir if (xListener.is()) 1916*cdf0e10cSrcweir { 1917*cdf0e10cSrcweir aEvtListeners.removeInterface( xListener ); 1918*cdf0e10cSrcweir } 1919*cdf0e10cSrcweir } 1920*cdf0e10cSrcweir 1921*cdf0e10cSrcweir 1922*cdf0e10cSrcweir sal_Bool LngSvcMgr::AddLngSvcEvtBroadcaster( 1923*cdf0e10cSrcweir const uno::Reference< linguistic2::XLinguServiceEventBroadcaster > &rxBroadcaster ) 1924*cdf0e10cSrcweir { 1925*cdf0e10cSrcweir sal_Bool bRes = sal_False; 1926*cdf0e10cSrcweir if (rxBroadcaster.is()) 1927*cdf0e10cSrcweir { 1928*cdf0e10cSrcweir if (!pListenerHelper) 1929*cdf0e10cSrcweir GetListenerHelper_Impl(); 1930*cdf0e10cSrcweir bRes = pListenerHelper->AddLngSvcEvtBroadcaster( rxBroadcaster ); 1931*cdf0e10cSrcweir } 1932*cdf0e10cSrcweir return bRes; 1933*cdf0e10cSrcweir } 1934*cdf0e10cSrcweir 1935*cdf0e10cSrcweir 1936*cdf0e10cSrcweir sal_Bool LngSvcMgr::RemoveLngSvcEvtBroadcaster( 1937*cdf0e10cSrcweir const uno::Reference< linguistic2::XLinguServiceEventBroadcaster > &rxBroadcaster ) 1938*cdf0e10cSrcweir { 1939*cdf0e10cSrcweir sal_Bool bRes = sal_False; 1940*cdf0e10cSrcweir if (rxBroadcaster.is()) 1941*cdf0e10cSrcweir { 1942*cdf0e10cSrcweir DBG_ASSERT( pListenerHelper, "pListenerHelper non existent" ); 1943*cdf0e10cSrcweir if (!pListenerHelper) 1944*cdf0e10cSrcweir GetListenerHelper_Impl(); 1945*cdf0e10cSrcweir bRes = pListenerHelper->RemoveLngSvcEvtBroadcaster( rxBroadcaster ); 1946*cdf0e10cSrcweir } 1947*cdf0e10cSrcweir return bRes; 1948*cdf0e10cSrcweir } 1949*cdf0e10cSrcweir 1950*cdf0e10cSrcweir 1951*cdf0e10cSrcweir OUString SAL_CALL 1952*cdf0e10cSrcweir LngSvcMgr::getImplementationName() 1953*cdf0e10cSrcweir throw(uno::RuntimeException) 1954*cdf0e10cSrcweir { 1955*cdf0e10cSrcweir osl::MutexGuard aGuard( GetLinguMutex() ); 1956*cdf0e10cSrcweir return getImplementationName_Static(); 1957*cdf0e10cSrcweir } 1958*cdf0e10cSrcweir 1959*cdf0e10cSrcweir 1960*cdf0e10cSrcweir sal_Bool SAL_CALL 1961*cdf0e10cSrcweir LngSvcMgr::supportsService( const OUString& ServiceName ) 1962*cdf0e10cSrcweir throw(uno::RuntimeException) 1963*cdf0e10cSrcweir { 1964*cdf0e10cSrcweir osl::MutexGuard aGuard( GetLinguMutex() ); 1965*cdf0e10cSrcweir 1966*cdf0e10cSrcweir uno::Sequence< OUString > aSNL = getSupportedServiceNames(); 1967*cdf0e10cSrcweir const OUString * pArray = aSNL.getConstArray(); 1968*cdf0e10cSrcweir for( sal_Int32 i = 0; i < aSNL.getLength(); i++ ) 1969*cdf0e10cSrcweir if( pArray[i] == ServiceName ) 1970*cdf0e10cSrcweir return sal_True; 1971*cdf0e10cSrcweir return sal_False; 1972*cdf0e10cSrcweir } 1973*cdf0e10cSrcweir 1974*cdf0e10cSrcweir 1975*cdf0e10cSrcweir uno::Sequence< OUString > SAL_CALL 1976*cdf0e10cSrcweir LngSvcMgr::getSupportedServiceNames() 1977*cdf0e10cSrcweir throw(uno::RuntimeException) 1978*cdf0e10cSrcweir { 1979*cdf0e10cSrcweir osl::MutexGuard aGuard( GetLinguMutex() ); 1980*cdf0e10cSrcweir return getSupportedServiceNames_Static(); 1981*cdf0e10cSrcweir } 1982*cdf0e10cSrcweir 1983*cdf0e10cSrcweir 1984*cdf0e10cSrcweir uno::Sequence< OUString > LngSvcMgr::getSupportedServiceNames_Static() 1985*cdf0e10cSrcweir throw() 1986*cdf0e10cSrcweir { 1987*cdf0e10cSrcweir osl::MutexGuard aGuard( GetLinguMutex() ); 1988*cdf0e10cSrcweir 1989*cdf0e10cSrcweir uno::Sequence< OUString > aSNS( 1 ); // auch mehr als 1 Service moeglich 1990*cdf0e10cSrcweir aSNS.getArray()[0] = A2OU( SN_LINGU_SERVCICE_MANAGER ); 1991*cdf0e10cSrcweir return aSNS; 1992*cdf0e10cSrcweir } 1993*cdf0e10cSrcweir 1994*cdf0e10cSrcweir 1995*cdf0e10cSrcweir uno::Reference< uno::XInterface > SAL_CALL LngSvcMgr_CreateInstance( 1996*cdf0e10cSrcweir const uno::Reference< lang::XMultiServiceFactory > & /*rSMgr*/ ) 1997*cdf0e10cSrcweir throw(uno::Exception) 1998*cdf0e10cSrcweir { 1999*cdf0e10cSrcweir uno::Reference< uno::XInterface > xService = (cppu::OWeakObject*) new LngSvcMgr; 2000*cdf0e10cSrcweir return xService; 2001*cdf0e10cSrcweir } 2002*cdf0e10cSrcweir 2003*cdf0e10cSrcweir void * SAL_CALL LngSvcMgr_getFactory( 2004*cdf0e10cSrcweir const sal_Char * pImplName, 2005*cdf0e10cSrcweir lang::XMultiServiceFactory * pServiceManager, 2006*cdf0e10cSrcweir void * /*pRegistryKey*/ ) 2007*cdf0e10cSrcweir { 2008*cdf0e10cSrcweir 2009*cdf0e10cSrcweir void * pRet = 0; 2010*cdf0e10cSrcweir if ( !LngSvcMgr::getImplementationName_Static().compareToAscii( pImplName ) ) 2011*cdf0e10cSrcweir { 2012*cdf0e10cSrcweir uno::Reference< lang::XSingleServiceFactory > xFactory = 2013*cdf0e10cSrcweir cppu::createOneInstanceFactory( 2014*cdf0e10cSrcweir pServiceManager, 2015*cdf0e10cSrcweir LngSvcMgr::getImplementationName_Static(), 2016*cdf0e10cSrcweir LngSvcMgr_CreateInstance, 2017*cdf0e10cSrcweir LngSvcMgr::getSupportedServiceNames_Static()); 2018*cdf0e10cSrcweir // acquire, because we return an interface pointer instead of a reference 2019*cdf0e10cSrcweir xFactory->acquire(); 2020*cdf0e10cSrcweir pRet = xFactory.get(); 2021*cdf0e10cSrcweir } 2022*cdf0e10cSrcweir return pRet; 2023*cdf0e10cSrcweir } 2024*cdf0e10cSrcweir 2025*cdf0e10cSrcweir 2026*cdf0e10cSrcweir /////////////////////////////////////////////////////////////////////////// 2027*cdf0e10cSrcweir 2028