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 linguistic::PropertyHelper_Spelling* pPropHelper;
76 sal_Bool bDisposing;
77
78 // disallow copy-constructor and assignment-operator for now
79 SpellChecker(const SpellChecker &);
80 SpellChecker & operator = (const SpellChecker &);
81
82 linguistic::PropertyHelper_Spelling& GetPropHelper_Impl();
GetPropHelper()83 linguistic::PropertyHelper_Spelling& GetPropHelper()
84 {
85 return pPropHelper ? *pPropHelper : GetPropHelper_Impl();
86 }
87
88 sal_Int16 GetSpellFailure( const OUString &rWord, const Locale &rLocale );
89 Reference< XSpellAlternatives > GetProposals( const OUString &rWord, const Locale &rLocale );
90
91 public:
92 SpellChecker();
93 virtual ~SpellChecker();
94
95 // XSupportedLocales (for XSpellChecker)
96 virtual Sequence< Locale > SAL_CALL getLocales() throw(RuntimeException);
97 virtual sal_Bool SAL_CALL hasLocale( const Locale& rLocale ) throw(RuntimeException);
98
99 // XSpellChecker
100 virtual sal_Bool SAL_CALL isValid( const OUString& rWord, const Locale& rLocale, const PropertyValues& rProperties ) throw(IllegalArgumentException, RuntimeException);
101 virtual Reference< XSpellAlternatives > SAL_CALL spell( const OUString& rWord, const Locale& rLocale, const PropertyValues& rProperties ) throw(IllegalArgumentException, RuntimeException);
102
103 // XLinguServiceEventBroadcaster
104 virtual sal_Bool SAL_CALL addLinguServiceEventListener( const Reference< XLinguServiceEventListener >& rxLstnr ) throw(RuntimeException);
105 virtual sal_Bool SAL_CALL removeLinguServiceEventListener( const Reference< XLinguServiceEventListener >& rxLstnr ) throw(RuntimeException);
106
107 // XServiceDisplayName
108 virtual OUString SAL_CALL getServiceDisplayName( const Locale& rLocale ) throw(RuntimeException);
109
110 // XInitialization
111 virtual void SAL_CALL initialize( const Sequence< Any >& rArguments ) throw(Exception, RuntimeException);
112
113 // XComponent
114 virtual void SAL_CALL dispose() throw(RuntimeException);
115 virtual void SAL_CALL addEventListener( const Reference< XEventListener >& rxListener ) throw(RuntimeException);
116 virtual void SAL_CALL removeEventListener( const Reference< XEventListener >& rxListener ) throw(RuntimeException);
117
118 // XServiceInfo
119 virtual OUString SAL_CALL getImplementationName() throw(RuntimeException);
120 virtual sal_Bool SAL_CALL supportsService( const OUString& rServiceName ) throw(RuntimeException);
121 virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() throw(RuntimeException);
122
123
124 static inline OUString getImplementationName_Static() throw();
125 static Sequence< OUString > getSupportedServiceNames_Static() throw();
126 };
127
getImplementationName_Static()128 inline OUString SpellChecker::getImplementationName_Static() throw()
129 {
130 return A2OU( "org.openoffice.lingu.MySpellSpellChecker" );
131 }
132
133
134 ///////////////////////////////////////////////////////////////////////////
135
136 #endif
137
138