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 _LINGU2_SPELLIMP_HXX_
25 #define _LINGU2_SPELLIMP_HXX_
26 
27 #include <uno/lbnames.h>			// CPPU_CURRENT_LANGUAGE_BINDING_NAME macro, which specify the environment type
28 #include <cppuhelper/implbase1.hxx>	// helper for implementations
29 #include <cppuhelper/implbase6.hxx>	// helper for implementations
30 #include <com/sun/star/lang/XComponent.hpp>
31 #include <com/sun/star/lang/XInitialization.hpp>
32 #include <com/sun/star/lang/XServiceDisplayName.hpp>
33 #include <com/sun/star/beans/XPropertySet.hpp>
34 #include <com/sun/star/beans/PropertyValues.hpp>
35 #include <com/sun/star/lang/XServiceInfo.hpp>
36 #include <com/sun/star/linguistic2/XSpellChecker.hpp>
37 #include <com/sun/star/linguistic2/XSearchableDictionaryList.hpp>
38 #include <com/sun/star/linguistic2/XLinguServiceEventBroadcaster.hpp>
39 #include <tools/table.hxx>
40 
41 #include <linguistic/misc.hxx>
42 #include <linguistic/lngprophelp.hxx>
43 
44 #include <lingutil.hxx>
45 
46 using namespace ::rtl;
47 using namespace ::com::sun::star::uno;
48 using namespace ::com::sun::star::beans;
49 using namespace ::com::sun::star::lang;
50 using namespace ::com::sun::star::linguistic2;
51 
52 
53 ///////////////////////////////////////////////////////////////////////////
54 
55 
56 class SpellChecker :
57 	public cppu::WeakImplHelper6
58 	<
59 		XSpellChecker,
60 		XLinguServiceEventBroadcaster,
61 		XInitialization,
62 		XComponent,
63 		XServiceInfo,
64 		XServiceDisplayName
65 	>
66 {
67 	Sequence< Locale >                 aSuppLocales;
68     Hunspell **                        aDicts;
69     rtl_TextEncoding *                 aDEncs;
70     Locale *                           aDLocs;
71     OUString *                         aDNames;
72     sal_Int32                          numdict;
73 
74 	::cppu::OInterfaceContainerHelper		aEvtListeners;
75 	Reference< XPropertyChangeListener >	xPropHelper;
76     linguistic::PropertyHelper_Spell *      pPropHelper;
77 	sal_Bool									bDisposing;
78 
79 	// disallow copy-constructor and assignment-operator for now
80 	SpellChecker(const SpellChecker &);
81 	SpellChecker & operator = (const SpellChecker &);
82 
83     linguistic::PropertyHelper_Spell &  GetPropHelper_Impl();
GetPropHelper()84     linguistic::PropertyHelper_Spell &  GetPropHelper()
85 	{
86 		return pPropHelper ? *pPropHelper : GetPropHelper_Impl();
87 	}
88 
89 	sal_Int16	GetSpellFailure( const OUString &rWord, const Locale &rLocale );
90     Reference< XSpellAlternatives > GetProposals( const OUString &rWord, const Locale &rLocale );
91 
92 public:
93 	SpellChecker();
94 	virtual ~SpellChecker();
95 
96 	// XSupportedLocales (for XSpellChecker)
97     virtual Sequence< Locale > SAL_CALL getLocales() throw(RuntimeException);
98     virtual sal_Bool SAL_CALL hasLocale( const Locale& rLocale ) throw(RuntimeException);
99 
100 	// XSpellChecker
101     virtual sal_Bool SAL_CALL isValid( const OUString& rWord, const Locale& rLocale, const PropertyValues& rProperties ) throw(IllegalArgumentException, RuntimeException);
102     virtual Reference< XSpellAlternatives > SAL_CALL spell( const OUString& rWord, const Locale& rLocale, const PropertyValues& rProperties ) throw(IllegalArgumentException, RuntimeException);
103 
104     // XLinguServiceEventBroadcaster
105     virtual sal_Bool SAL_CALL addLinguServiceEventListener( const Reference< XLinguServiceEventListener >& rxLstnr ) throw(RuntimeException);
106     virtual sal_Bool SAL_CALL removeLinguServiceEventListener( const Reference< XLinguServiceEventListener >& rxLstnr ) throw(RuntimeException);
107 
108 	// XServiceDisplayName
109     virtual OUString SAL_CALL getServiceDisplayName( const Locale& rLocale ) throw(RuntimeException);
110 
111 	// XInitialization
112     virtual void SAL_CALL initialize( const Sequence< Any >& rArguments ) throw(Exception, RuntimeException);
113 
114 	// XComponent
115     virtual void SAL_CALL dispose() throw(RuntimeException);
116     virtual void SAL_CALL addEventListener( const Reference< XEventListener >& rxListener ) throw(RuntimeException);
117     virtual void SAL_CALL removeEventListener( const Reference< XEventListener >& rxListener ) throw(RuntimeException);
118 
119 	// XServiceInfo
120     virtual OUString SAL_CALL getImplementationName() throw(RuntimeException);
121     virtual sal_Bool SAL_CALL supportsService( const OUString& rServiceName ) throw(RuntimeException);
122     virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() throw(RuntimeException);
123 
124 
125     static inline OUString  getImplementationName_Static() throw();
126     static Sequence< OUString > getSupportedServiceNames_Static() throw();
127 };
128 
getImplementationName_Static()129 inline OUString SpellChecker::getImplementationName_Static() throw()
130 {
131 	return A2OU( "org.openoffice.lingu.MySpellSpellChecker" );
132 }
133 
134 
135 ///////////////////////////////////////////////////////////////////////////
136 
137 #endif
138 
139