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