1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 #ifndef _LINGUISTIC_LNGSVCMGR_HXX_
25 #define _LINGUISTIC_LNGSVCMGR_HXX_
26
27 #include <uno/lbnames.h> // CPPU_CURRENT_LANGUAGE_BINDING_NAME macro, which specify the environment type
28 #include <cppuhelper/implbase4.hxx> // helper for implementations
29 #include <cppuhelper/interfacecontainer.h> //OMultiTypeInterfaceContainerHelper
30
31
32 #include <com/sun/star/uno/Reference.h>
33 #include <com/sun/star/lang/XServiceInfo.hpp>
34 #include <com/sun/star/lang/XComponent.hpp>
35 #include <com/sun/star/linguistic2/XLinguServiceManager.hpp>
36 #include <com/sun/star/linguistic2/XAvailableLocales.hpp>
37 #include <unotools/configitem.hxx>
38
39 //#include <vcl/timer.hxx>
40
41 #include "linguistic/misc.hxx"
42 #include "defs.hxx"
43
44 class SpellCheckerDispatcher;
45 class HyphenatorDispatcher;
46 class ThesaurusDispatcher;
47 class GrammarCheckingIterator;
48 class LngSvcMgrListenerHelper;
49 struct SvcInfo;
50
51 namespace com { namespace sun { namespace star { namespace linguistic2 {
52 class XLinguServiceEventBroadcaster;
53 class XSpellChecker;
54 class XProofreader;
55 class XProofreadingIterator;
56 class XHyphenator;
57 class XThesaurus;
58 } } } }
59
60 ///////////////////////////////////////////////////////////////////////////
61
62
63 class LngSvcMgr :
64 public cppu::WeakImplHelper4
65 <
66 com::sun::star::linguistic2::XLinguServiceManager,
67 com::sun::star::linguistic2::XAvailableLocales,
68 com::sun::star::lang::XComponent,
69 com::sun::star::lang::XServiceInfo
70 >,
71 private utl::ConfigItem
72 {
73 friend class LngSvcMgrListenerHelper;
74
75 ::cppu::OInterfaceContainerHelper aEvtListeners;
76
77 com::sun::star::uno::Reference<
78 ::com::sun::star::linguistic2::XSpellChecker > xSpellDsp;
79 com::sun::star::uno::Reference<
80 ::com::sun::star::linguistic2::XProofreadingIterator > xGrammarDsp;
81 com::sun::star::uno::Reference<
82 ::com::sun::star::linguistic2::XHyphenator > xHyphDsp;
83 com::sun::star::uno::Reference<
84 ::com::sun::star::linguistic2::XThesaurus > xThesDsp;
85
86 com::sun::star::uno::Reference<
87 ::com::sun::star::lang::XEventListener > xListenerHelper;
88
89 com::sun::star::uno::Sequence<
90 com::sun::star::lang::Locale > aAvailSpellLocales;
91 com::sun::star::uno::Sequence<
92 com::sun::star::lang::Locale > aAvailGrammarLocales;
93 com::sun::star::uno::Sequence<
94 com::sun::star::lang::Locale > aAvailHyphLocales;
95 com::sun::star::uno::Sequence<
96 com::sun::star::lang::Locale > aAvailThesLocales;
97
98 SpellCheckerDispatcher * pSpellDsp;
99 GrammarCheckingIterator * pGrammarDsp;
100 HyphenatorDispatcher * pHyphDsp;
101 ThesaurusDispatcher * pThesDsp;
102
103 LngSvcMgrListenerHelper * pListenerHelper;
104
105 typedef std::vector< SvcInfo * > SvcInfoArray;
106 SvcInfoArray * pAvailSpellSvcs;
107 SvcInfoArray * pAvailGrammarSvcs;
108 SvcInfoArray * pAvailHyphSvcs;
109 SvcInfoArray * pAvailThesSvcs;
110
111 sal_Bool bDisposing;
112 sal_Bool bHasAvailSpellLocales;
113 sal_Bool bHasAvailGrammarLocales;
114 sal_Bool bHasAvailHyphLocales;
115 sal_Bool bHasAvailThesLocales;
116
117 // disallow copy-constructor and assignment-operator for now
118 LngSvcMgr(const LngSvcMgr &);
119 LngSvcMgr & operator = (const LngSvcMgr &);
120
121 void GetAvailableSpellSvcs_Impl();
122 void GetAvailableGrammarSvcs_Impl();
123 void GetAvailableHyphSvcs_Impl();
124 void GetAvailableThesSvcs_Impl();
125 void GetListenerHelper_Impl();
126
127 void GetSpellCheckerDsp_Impl( sal_Bool bSetSvcList = sal_True );
128 void GetGrammarCheckerDsp_Impl( sal_Bool bSetSvcList = sal_True );
129 void GetHyphenatorDsp_Impl( sal_Bool bSetSvcList = sal_True );
130 void GetThesaurusDsp_Impl( sal_Bool bSetSvcList = sal_True );
131
132 void SetCfgServiceLists( SpellCheckerDispatcher &rSpellDsp );
133 void SetCfgServiceLists( GrammarCheckingIterator &rGrammarDsp );
134 void SetCfgServiceLists( HyphenatorDispatcher &rHyphDsp );
135 void SetCfgServiceLists( ThesaurusDispatcher &rThesDsp );
136
137 sal_Bool SaveCfgSvcs( const String &rServiceName );
138
139 void SetAvailableCfgServiceLists( LinguDispatcher &rDispatcher,
140 const SvcInfoArray &rAvailSvcs );
141
142 static void clearSvcInfoArray(SvcInfoArray *pInfo);
143
144 // utl::ConfigItem (to allow for listening of changes of relevant properties)
145 virtual void Notify( const com::sun::star::uno::Sequence< rtl::OUString > &rPropertyNames );
146 virtual void Commit();
147
148 public:
149 LngSvcMgr();
150 virtual ~LngSvcMgr();
151
152 // XLinguServiceManager
153 virtual ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XSpellChecker > SAL_CALL getSpellChecker( ) throw (::com::sun::star::uno::RuntimeException);
154 virtual ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XHyphenator > SAL_CALL getHyphenator( ) throw (::com::sun::star::uno::RuntimeException);
155 virtual ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XThesaurus > SAL_CALL getThesaurus( ) throw (::com::sun::star::uno::RuntimeException);
156 virtual ::sal_Bool SAL_CALL addLinguServiceManagerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException);
157 virtual ::sal_Bool SAL_CALL removeLinguServiceManagerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException);
158 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getAvailableServices( const ::rtl::OUString& aServiceName, const ::com::sun::star::lang::Locale& aLocale ) throw (::com::sun::star::uno::RuntimeException);
159 virtual void SAL_CALL setConfiguredServices( const ::rtl::OUString& aServiceName, const ::com::sun::star::lang::Locale& aLocale, const ::com::sun::star::uno::Sequence< ::rtl::OUString >& aServiceImplNames ) throw (::com::sun::star::uno::RuntimeException);
160 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getConfiguredServices( const ::rtl::OUString& aServiceName, const ::com::sun::star::lang::Locale& aLocale ) throw (::com::sun::star::uno::RuntimeException);
161
162 // XAvailableLocales
163 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::lang::Locale > SAL_CALL getAvailableLocales( const ::rtl::OUString& aServiceName ) throw (::com::sun::star::uno::RuntimeException);
164
165 // XComponent
166 virtual void SAL_CALL dispose( ) throw (::com::sun::star::uno::RuntimeException);
167 virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException);
168 virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw (::com::sun::star::uno::RuntimeException);
169
170 // XServiceInfo
171 virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw (::com::sun::star::uno::RuntimeException);
172 virtual ::sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException);
173 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException);
174
175
176 static inline ::rtl::OUString getImplementationName_Static();
177 static ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_Static() throw();
178
179 sal_Bool AddLngSvcEvtBroadcaster(
180 const ::com::sun::star::uno::Reference<
181 ::com::sun::star::linguistic2::XLinguServiceEventBroadcaster > &rxBroadcaster );
182 sal_Bool RemoveLngSvcEvtBroadcaster(
183 const ::com::sun::star::uno::Reference<
184 ::com::sun::star::linguistic2::XLinguServiceEventBroadcaster > &rxBroadcaster );
185 };
186
187
getImplementationName_Static()188 inline ::rtl::OUString LngSvcMgr::getImplementationName_Static()
189 {
190 return A2OU( "com.sun.star.lingu2.LngSvcMgr" );
191 }
192
193
194 ///////////////////////////////////////////////////////////////////////////
195
196 #endif
197
198