xref: /aoo42x/main/linguistic/source/lngsvcmgr.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _LINGUISTIC_LNGSVCMGR_HXX_
29 #define _LINGUISTIC_LNGSVCMGR_HXX_
30 
31 #include <uno/lbnames.h>			// CPPU_CURRENT_LANGUAGE_BINDING_NAME macro, which specify the environment type
32 #include <cppuhelper/implbase4.hxx>	// helper for implementations
33 #include <cppuhelper/interfacecontainer.h>	//OMultiTypeInterfaceContainerHelper
34 
35 
36 #include <com/sun/star/uno/Reference.h>
37 #include <com/sun/star/lang/XServiceInfo.hpp>
38 #include <com/sun/star/lang/XComponent.hpp>
39 #include <com/sun/star/linguistic2/XLinguServiceManager.hpp>
40 #include <com/sun/star/linguistic2/XAvailableLocales.hpp>
41 #include <unotools/configitem.hxx>
42 
43 //#include <vcl/timer.hxx>
44 
45 #include "linguistic/misc.hxx"
46 #include "defs.hxx"
47 
48 class SpellCheckerDispatcher;
49 class HyphenatorDispatcher;
50 class ThesaurusDispatcher;
51 class GrammarCheckingIterator;
52 class LngSvcMgrListenerHelper;
53 struct SvcInfo;
54 
55 namespace com { namespace sun { namespace star { namespace linguistic2 {
56 	class XLinguServiceEventBroadcaster;
57 	class XSpellChecker;
58     class XProofreader;
59     class XProofreadingIterator;
60 	class XHyphenator;
61 	class XThesaurus;
62 } } } }
63 
64 ///////////////////////////////////////////////////////////////////////////
65 
66 
67 class LngSvcMgr :
68 	public cppu::WeakImplHelper4
69 	<
70 		com::sun::star::linguistic2::XLinguServiceManager,
71 		com::sun::star::linguistic2::XAvailableLocales,
72 		com::sun::star::lang::XComponent,
73 		com::sun::star::lang::XServiceInfo
74     >,
75     private utl::ConfigItem
76 {
77     friend class LngSvcMgrListenerHelper;
78 
79 	::cppu::OInterfaceContainerHelper					aEvtListeners;
80 
81 	com::sun::star::uno::Reference<
82         ::com::sun::star::linguistic2::XSpellChecker >              xSpellDsp;
83     com::sun::star::uno::Reference<
84         ::com::sun::star::linguistic2::XProofreadingIterator >   	xGrammarDsp;
85 	com::sun::star::uno::Reference<
86         ::com::sun::star::linguistic2::XHyphenator >                xHyphDsp;
87 	com::sun::star::uno::Reference<
88         ::com::sun::star::linguistic2::XThesaurus >                 xThesDsp;
89 
90 	com::sun::star::uno::Reference<
91 		::com::sun::star::lang::XEventListener >		xListenerHelper;
92 
93 	com::sun::star::uno::Sequence<
94 		com::sun::star::lang::Locale >					aAvailSpellLocales;
95     com::sun::star::uno::Sequence<
96         com::sun::star::lang::Locale >                  aAvailGrammarLocales;
97 	com::sun::star::uno::Sequence<
98 		com::sun::star::lang::Locale >					aAvailHyphLocales;
99 	com::sun::star::uno::Sequence<
100 		com::sun::star::lang::Locale >					aAvailThesLocales;
101 
102 	SpellCheckerDispatcher *							pSpellDsp;
103     GrammarCheckingIterator *                           pGrammarDsp;
104 	HyphenatorDispatcher *								pHyphDsp;
105 	ThesaurusDispatcher *								pThesDsp;
106 
107 	LngSvcMgrListenerHelper *							pListenerHelper;
108 
109     typedef std::vector< SvcInfo * >    SvcInfoArray;
110 	SvcInfoArray *										pAvailSpellSvcs;
111     SvcInfoArray *                                      pAvailGrammarSvcs;
112 	SvcInfoArray *										pAvailHyphSvcs;
113 	SvcInfoArray *										pAvailThesSvcs;
114 
115 	sal_Bool bDisposing;
116 	sal_Bool bHasAvailSpellLocales;
117     sal_Bool bHasAvailGrammarLocales;
118 	sal_Bool bHasAvailHyphLocales;
119 	sal_Bool bHasAvailThesLocales;
120 
121 	// disallow copy-constructor and assignment-operator for now
122 	LngSvcMgr(const LngSvcMgr &);
123 	LngSvcMgr & operator = (const LngSvcMgr &);
124 
125 	void	GetAvailableSpellSvcs_Impl();
126     void    GetAvailableGrammarSvcs_Impl();
127 	void	GetAvailableHyphSvcs_Impl();
128 	void	GetAvailableThesSvcs_Impl();
129 	void	GetListenerHelper_Impl();
130 
131     void    GetSpellCheckerDsp_Impl( sal_Bool bSetSvcList = sal_True );
132     void    GetGrammarCheckerDsp_Impl( sal_Bool bSetSvcList = sal_True );
133     void    GetHyphenatorDsp_Impl( sal_Bool bSetSvcList = sal_True );
134     void    GetThesaurusDsp_Impl( sal_Bool bSetSvcList = sal_True );
135 
136 	void	SetCfgServiceLists( SpellCheckerDispatcher &rSpellDsp );
137     void    SetCfgServiceLists( GrammarCheckingIterator &rGrammarDsp );
138 	void	SetCfgServiceLists( HyphenatorDispatcher &rHyphDsp );
139 	void	SetCfgServiceLists( ThesaurusDispatcher &rThesDsp );
140 
141 	sal_Bool	SaveCfgSvcs( const String &rServiceName );
142 
143     void    SetAvailableCfgServiceLists( LinguDispatcher &rDispatcher,
144                     const SvcInfoArray &rAvailSvcs );
145 
146     static void clearSvcInfoArray(SvcInfoArray *pInfo);
147 
148     // utl::ConfigItem (to allow for listening of changes of relevant properties)
149     virtual void    Notify( const com::sun::star::uno::Sequence< rtl::OUString > &rPropertyNames );
150     virtual void    Commit();
151 
152 public:
153 	LngSvcMgr();
154 	virtual ~LngSvcMgr();
155 
156 	// XLinguServiceManager
157     virtual ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XSpellChecker > SAL_CALL getSpellChecker(  ) throw (::com::sun::star::uno::RuntimeException);
158     virtual ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XHyphenator > SAL_CALL getHyphenator(  ) throw (::com::sun::star::uno::RuntimeException);
159     virtual ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XThesaurus > SAL_CALL getThesaurus(  ) throw (::com::sun::star::uno::RuntimeException);
160     virtual ::sal_Bool SAL_CALL addLinguServiceManagerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException);
161     virtual ::sal_Bool SAL_CALL removeLinguServiceManagerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException);
162     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);
163     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);
164     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);
165 
166 	// XAvailableLocales
167     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::lang::Locale > SAL_CALL getAvailableLocales( const ::rtl::OUString& aServiceName ) throw (::com::sun::star::uno::RuntimeException);
168 
169 	// XComponent
170     virtual void SAL_CALL dispose(  ) throw (::com::sun::star::uno::RuntimeException);
171     virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException);
172     virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw (::com::sun::star::uno::RuntimeException);
173 
174 	// XServiceInfo
175     virtual ::rtl::OUString SAL_CALL getImplementationName(  ) throw (::com::sun::star::uno::RuntimeException);
176     virtual ::sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException);
177     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  ) throw (::com::sun::star::uno::RuntimeException);
178 
179 
180     static inline ::rtl::OUString   getImplementationName_Static();
181     static ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_Static() throw();
182 
183 	sal_Bool	AddLngSvcEvtBroadcaster(
184 				const ::com::sun::star::uno::Reference<
185 					::com::sun::star::linguistic2::XLinguServiceEventBroadcaster > &rxBroadcaster );
186 	sal_Bool	RemoveLngSvcEvtBroadcaster(
187 				const ::com::sun::star::uno::Reference<
188 					::com::sun::star::linguistic2::XLinguServiceEventBroadcaster > &rxBroadcaster );
189 };
190 
191 
192 inline ::rtl::OUString LngSvcMgr::getImplementationName_Static()
193 {
194 	return A2OU( "com.sun.star.lingu2.LngSvcMgr" );
195 }
196 
197 
198 ///////////////////////////////////////////////////////////////////////////
199 
200 #endif
201 
202