Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #ifndef _LINGUISTIC_LNGSVCMGR_HXX_
21 : #define _LINGUISTIC_LNGSVCMGR_HXX_
22 :
23 : #include <uno/lbnames.h> // CPPU_CURRENT_LANGUAGE_BINDING_NAME macro, which specify the environment type
24 : #include <cppuhelper/implbase3.hxx> // helper for implementations
25 : #include <cppuhelper/interfacecontainer.h> //OMultiTypeInterfaceContainerHelper
26 :
27 :
28 : #include <com/sun/star/uno/Reference.h>
29 : #include <com/sun/star/lang/XServiceInfo.hpp>
30 : #include <com/sun/star/linguistic2/XLinguServiceManager2.hpp>
31 : #include <com/sun/star/util/XModifyBroadcaster.hpp>
32 : #include <com/sun/star/util/XModifyListener.hpp>
33 : #include <unotools/configitem.hxx>
34 : #include <vcl/timer.hxx>
35 : #include <boost/ptr_container/ptr_vector.hpp>
36 :
37 : #include "linguistic/misc.hxx"
38 : #include "defs.hxx"
39 :
40 : class SpellCheckerDispatcher;
41 : class HyphenatorDispatcher;
42 : class ThesaurusDispatcher;
43 : class GrammarCheckingIterator;
44 : class LngSvcMgrListenerHelper;
45 : struct SvcInfo;
46 :
47 : namespace com { namespace sun { namespace star { namespace linguistic2 {
48 : class XLinguServiceEventBroadcaster;
49 : class XSpellChecker;
50 : class XProofreadingIterator;
51 : class XHyphenator;
52 : class XThesaurus;
53 : } } } }
54 :
55 :
56 :
57 : class LngSvcMgr :
58 : public cppu::WeakImplHelper3
59 : <
60 : com::sun::star::linguistic2::XLinguServiceManager2,
61 : com::sun::star::lang::XServiceInfo,
62 : com::sun::star::util::XModifyListener
63 : >,
64 : private utl::ConfigItem
65 : {
66 : friend class LngSvcMgrListenerHelper;
67 :
68 : ::cppu::OInterfaceContainerHelper aEvtListeners;
69 :
70 : com::sun::star::uno::Reference<
71 : ::com::sun::star::linguistic2::XSpellChecker > xSpellDsp;
72 : com::sun::star::uno::Reference<
73 : ::com::sun::star::linguistic2::XProofreadingIterator > xGrammarDsp;
74 : com::sun::star::uno::Reference<
75 : ::com::sun::star::linguistic2::XHyphenator > xHyphDsp;
76 : com::sun::star::uno::Reference<
77 : ::com::sun::star::linguistic2::XThesaurus > xThesDsp;
78 :
79 : com::sun::star::uno::Reference<
80 : ::com::sun::star::lang::XEventListener > xListenerHelper;
81 :
82 : com::sun::star::uno::Reference<
83 : ::com::sun::star::util::XModifyBroadcaster> xMB;
84 :
85 : Timer aUpdateTimer;
86 :
87 :
88 : com::sun::star::uno::Sequence<
89 : com::sun::star::lang::Locale > aAvailSpellLocales;
90 : com::sun::star::uno::Sequence<
91 : com::sun::star::lang::Locale > aAvailGrammarLocales;
92 : com::sun::star::uno::Sequence<
93 : com::sun::star::lang::Locale > aAvailHyphLocales;
94 : com::sun::star::uno::Sequence<
95 : com::sun::star::lang::Locale > aAvailThesLocales;
96 :
97 : SpellCheckerDispatcher * pSpellDsp;
98 : GrammarCheckingIterator * pGrammarDsp;
99 : HyphenatorDispatcher * pHyphDsp;
100 : ThesaurusDispatcher * pThesDsp;
101 :
102 : LngSvcMgrListenerHelper * pListenerHelper;
103 :
104 : typedef boost::ptr_vector< SvcInfo > SvcInfoArray;
105 : SvcInfoArray * pAvailSpellSvcs;
106 : SvcInfoArray * pAvailGrammarSvcs;
107 : SvcInfoArray * pAvailHyphSvcs;
108 : SvcInfoArray * pAvailThesSvcs;
109 :
110 : sal_Bool bDisposing;
111 :
112 : // disallow copy-constructor and assignment-operator for now
113 : LngSvcMgr(const LngSvcMgr &);
114 : LngSvcMgr & operator = (const LngSvcMgr &);
115 :
116 : void GetAvailableSpellSvcs_Impl();
117 : void GetAvailableGrammarSvcs_Impl();
118 : void GetAvailableHyphSvcs_Impl();
119 : void GetAvailableThesSvcs_Impl();
120 : void GetListenerHelper_Impl();
121 :
122 : void GetSpellCheckerDsp_Impl( sal_Bool bSetSvcList = sal_True );
123 : void GetGrammarCheckerDsp_Impl( sal_Bool bSetSvcList = sal_True );
124 : void GetHyphenatorDsp_Impl( sal_Bool bSetSvcList = sal_True );
125 : void GetThesaurusDsp_Impl( sal_Bool bSetSvcList = sal_True );
126 :
127 : void SetCfgServiceLists( SpellCheckerDispatcher &rSpellDsp );
128 : void SetCfgServiceLists( GrammarCheckingIterator &rGrammarDsp );
129 : void SetCfgServiceLists( HyphenatorDispatcher &rHyphDsp );
130 : void SetCfgServiceLists( ThesaurusDispatcher &rThesDsp );
131 :
132 : sal_Bool SaveCfgSvcs( const String &rServiceName );
133 :
134 : static void clearSvcInfoArray(SvcInfoArray *&rpInfo);
135 :
136 : // utl::ConfigItem (to allow for listening of changes of relevant properties)
137 : virtual void Notify( const com::sun::star::uno::Sequence< OUString > &rPropertyNames );
138 : virtual void Commit();
139 :
140 : void UpdateAll();
141 : void stopListening();
142 : DECL_LINK( updateAndBroadcast, void* );
143 :
144 : public:
145 : LngSvcMgr();
146 : virtual ~LngSvcMgr();
147 :
148 : // XLinguServiceManager
149 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XSpellChecker > SAL_CALL getSpellChecker( ) throw (::com::sun::star::uno::RuntimeException);
150 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XHyphenator > SAL_CALL getHyphenator( ) throw (::com::sun::star::uno::RuntimeException);
151 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XThesaurus > SAL_CALL getThesaurus( ) throw (::com::sun::star::uno::RuntimeException);
152 : virtual ::sal_Bool SAL_CALL addLinguServiceManagerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException);
153 : virtual ::sal_Bool SAL_CALL removeLinguServiceManagerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException);
154 : virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getAvailableServices( const OUString& aServiceName, const ::com::sun::star::lang::Locale& aLocale ) throw (::com::sun::star::uno::RuntimeException);
155 : virtual void SAL_CALL setConfiguredServices( const OUString& aServiceName, const ::com::sun::star::lang::Locale& aLocale, const ::com::sun::star::uno::Sequence< OUString >& aServiceImplNames ) throw (::com::sun::star::uno::RuntimeException);
156 : virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getConfiguredServices( const OUString& aServiceName, const ::com::sun::star::lang::Locale& aLocale ) throw (::com::sun::star::uno::RuntimeException);
157 :
158 : // XAvailableLocales
159 : virtual ::com::sun::star::uno::Sequence< ::com::sun::star::lang::Locale > SAL_CALL getAvailableLocales( const OUString& aServiceName ) throw (::com::sun::star::uno::RuntimeException);
160 :
161 : // XComponent
162 : virtual void SAL_CALL dispose( ) throw (::com::sun::star::uno::RuntimeException);
163 : virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException);
164 : virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw (::com::sun::star::uno::RuntimeException);
165 :
166 : // XServiceInfo
167 : virtual OUString SAL_CALL getImplementationName( ) throw (::com::sun::star::uno::RuntimeException);
168 : virtual ::sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException);
169 : virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException);
170 :
171 : // XEventListener
172 : virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& rSource ) throw(::com::sun::star::uno::RuntimeException);
173 :
174 : // XModifyListener
175 : virtual void SAL_CALL modified( const ::com::sun::star::lang::EventObject& rEvent ) throw(::com::sun::star::uno::RuntimeException);
176 :
177 : static inline OUString getImplementationName_Static();
178 : static ::com::sun::star::uno::Sequence< OUString > getSupportedServiceNames_Static() throw();
179 :
180 : sal_Bool AddLngSvcEvtBroadcaster(
181 : const ::com::sun::star::uno::Reference<
182 : ::com::sun::star::linguistic2::XLinguServiceEventBroadcaster > &rxBroadcaster );
183 : };
184 :
185 :
186 136 : inline OUString LngSvcMgr::getImplementationName_Static()
187 : {
188 136 : return OUString( "com.sun.star.lingu2.LngSvcMgr" );
189 : }
190 :
191 :
192 :
193 : #endif
194 :
195 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|