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 _LINGU2_SPELLIMP_HXX_
29 #define _LINGU2_SPELLIMP_HXX_
30 
31 #include <uno/lbnames.h>			// CPPU_CURRENT_LANGUAGE_BINDING_NAME macro, which specify the environment type
32 #include <cppuhelper/implbase1.hxx>	// helper for implementations
33 #include <cppuhelper/implbase6.hxx>	// helper for implementations
34 #include <com/sun/star/lang/XComponent.hpp>
35 #include <com/sun/star/lang/XInitialization.hpp>
36 #include <com/sun/star/lang/XServiceDisplayName.hpp>
37 #include <com/sun/star/beans/XPropertySet.hpp>
38 #include <com/sun/star/beans/PropertyValues.hpp>
39 #include <com/sun/star/lang/XServiceInfo.hpp>
40 #include <com/sun/star/linguistic2/XSpellChecker.hpp>
41 #include <com/sun/star/linguistic2/XSearchableDictionaryList.hpp>
42 #include <com/sun/star/linguistic2/XLinguServiceEventBroadcaster.hpp>
43 #include <tools/table.hxx>
44 
45 #include "linguistic/misc.hxx"
46 #include "sprophelp.hxx"
47 
48 using namespace ::rtl;
49 using namespace ::com::sun::star::uno;
50 using namespace ::com::sun::star::beans;
51 using namespace ::com::sun::star::lang;
52 using namespace ::com::sun::star::linguistic2;
53 
54 
55 #define A2OU(x)	::rtl::OUString::createFromAscii( x )
56 
57 ///////////////////////////////////////////////////////////////////////////
58 
59 
60 class SpellChecker :
61 	public cppu::WeakImplHelper6
62 	<
63 		XSpellChecker,
64 		XLinguServiceEventBroadcaster,
65 		XInitialization,
66 		XComponent,
67 		XServiceInfo,
68 		XServiceDisplayName
69 	>
70 {
71 	Sequence< Locale >						aSuppLocales;
72 	::cppu::OInterfaceContainerHelper		aEvtListeners;
73 	Reference< XPropertyChangeListener >	xPropHelper;
74 	PropertyHelper_Spell *			 		pPropHelper;
75 	BOOL									bDisposing;
76 
77 	// disallow copy-constructor and assignment-operator for now
78 	SpellChecker(const SpellChecker &);
79 	SpellChecker & operator = (const SpellChecker &);
80 
81 	PropertyHelper_Spell &	GetPropHelper_Impl();
82 	PropertyHelper_Spell &	GetPropHelper()
83 	{
84 		return pPropHelper ? *pPropHelper : GetPropHelper_Impl();
85 	}
86 
87 	INT16	GetSpellFailure( const OUString &rWord, const Locale &rLocale );
88 	Reference< XSpellAlternatives >
89 			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
97 		getLocales()
98 			throw(RuntimeException);
99     virtual sal_Bool SAL_CALL
100 		hasLocale( const Locale& rLocale )
101 			throw(RuntimeException);
102 
103 	// XSpellChecker
104     virtual sal_Bool SAL_CALL
105 		isValid( const OUString& rWord, const Locale& rLocale,
106 				const PropertyValues& rProperties )
107 			throw(IllegalArgumentException,
108 				  RuntimeException);
109     virtual Reference< XSpellAlternatives > SAL_CALL
110 		spell( const OUString& rWord, const Locale& rLocale,
111 				const PropertyValues& rProperties )
112 			throw(IllegalArgumentException,
113 				  RuntimeException);
114 
115     // XLinguServiceEventBroadcaster
116     virtual sal_Bool SAL_CALL
117 		addLinguServiceEventListener(
118 			const Reference< XLinguServiceEventListener >& rxLstnr )
119 			throw(RuntimeException);
120     virtual sal_Bool SAL_CALL
121 		removeLinguServiceEventListener(
122 			const Reference< XLinguServiceEventListener >& rxLstnr )
123 			throw(RuntimeException);
124 
125 	// XServiceDisplayName
126     virtual OUString SAL_CALL
127 		getServiceDisplayName( const Locale& rLocale )
128 			throw(RuntimeException);
129 
130 	// XInitialization
131     virtual void SAL_CALL
132 		initialize( const Sequence< Any >& rArguments )
133 			throw(Exception, RuntimeException);
134 
135 	// XComponent
136 	virtual void SAL_CALL
137 		dispose()
138 			throw(RuntimeException);
139     virtual void SAL_CALL
140 		addEventListener( const Reference< XEventListener >& rxListener )
141 			throw(RuntimeException);
142     virtual void SAL_CALL
143 		removeEventListener( const Reference< XEventListener >& rxListener )
144 			throw(RuntimeException);
145 
146 	////////////////////////////////////////////////////////////
147 	// Service specific part
148 	//
149 
150 	// XServiceInfo
151     virtual OUString SAL_CALL
152 		getImplementationName()
153 			throw(RuntimeException);
154     virtual sal_Bool SAL_CALL
155 		supportsService( const OUString& rServiceName )
156 			throw(RuntimeException);
157     virtual Sequence< OUString > SAL_CALL
158 		getSupportedServiceNames()
159 			throw(RuntimeException);
160 
161 
162 	static inline OUString
163 		getImplementationName_Static() throw();
164     static Sequence< OUString >
165 		getSupportedServiceNames_Static() throw();
166 };
167 
168 inline OUString SpellChecker::getImplementationName_Static() throw()
169 {
170 	return A2OU( "com.sun.star.lingu.examples.SpellChecker" );
171 }
172 
173 
174 ///////////////////////////////////////////////////////////////////////////
175 
176 #endif
177 
178