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_LNGPROPHELP_HXX_
29 #define _LINGUISTIC_LNGPROPHELP_HXX_
30 
31 #include <tools/solar.h>
32 
33 #include <uno/lbnames.h>
34 #include <cppuhelper/implbase2.hxx>
35 #include <cppuhelper/interfacecontainer.h>
36 #include <com/sun/star/beans/XPropertyChangeListener.hpp>
37 #include <com/sun/star/beans/PropertyValues.hpp>
38 
39 #include <com/sun/star/linguistic2/XLinguServiceEventBroadcaster.hpp>
40 
41 namespace com { namespace sun { namespace star { namespace beans {
42 	class	XPropertySet;
43 }}}}
44 
45 namespace com { namespace sun { namespace star { namespace linguistic2 {
46 	struct	LinguServiceEvent;
47 }}}}
48 
49 
50 namespace linguistic
51 {
52 
53 ///////////////////////////////////////////////////////////////////////////
54 // PropertyChgHelper
55 // Base class for all XPropertyChangeListener members of the
56 // various lingu services.
57 
58 
59 // Flags for type of events allowed to be launched
60 #define	AE_SPELLCHECKER	1
61 #define	AE_HYPHENATOR 	2
62 //#define	AE_THESAURUS	4
63 
64 typedef cppu::WeakImplHelper2
65 <
66     ::com::sun::star::beans::XPropertyChangeListener,
67     ::com::sun::star::linguistic2::XLinguServiceEventBroadcaster
68 > PropertyChgHelperBase;
69 
70 class PropertyChgHelper :
71     public PropertyChgHelperBase
72 {
73 	::com::sun::star::uno::Sequence< ::rtl::OUString >  aPropNames;
74 	::com::sun::star::uno::Reference<
75 		::com::sun::star::uno::XInterface >				xMyEvtObj;
76 	::cppu::OInterfaceContainerHelper					aLngSvcEvtListeners;
77 	::com::sun::star::uno::Reference<
78 		::com::sun::star::beans::XPropertySet >			xPropSet;
79 
80 	int		nEvtFlags;	// flags for event types allowed to be launched
81 
82 	// default values
83 	sal_Bool	bIsIgnoreControlCharacters;
84 	sal_Bool	bIsUseDictionaryList;
85 
86 	// return values, will be set to default value or current temporary value
87 	sal_Bool	bResIsIgnoreControlCharacters;
88 	sal_Bool	bResIsUseDictionaryList;
89 
90 
91 	// disallow use of copy-constructor and assignment-operator
92 	PropertyChgHelper( const PropertyChgHelper & );
93 	PropertyChgHelper & operator = ( const PropertyChgHelper & );
94 
95 protected:
96 	virtual void	SetDefaultValues();
97 	virtual void	GetCurrentValues();
98 
99 	::com::sun::star::uno::Sequence< ::rtl::OUString > &
100 			GetPropNames()	{ return aPropNames; }
101 	::com::sun::star::uno::Reference<
102 		::com::sun::star::beans::XPropertySet > &
103 			GetPropSet()	{ return xPropSet; }
104 
105 	void	AddPropNames( const char *pNewNames[], sal_Int32 nCount );
106 
107 	virtual sal_Bool	propertyChange_Impl(
108 							const ::com::sun::star::beans::PropertyChangeEvent& rEvt );
109 
110 public:
111 	PropertyChgHelper(
112 			const ::com::sun::star::uno::Reference<
113 				::com::sun::star::uno::XInterface > &rxSource,
114 			::com::sun::star::uno::Reference<
115 				::com::sun::star::beans::XPropertySet > &rxPropSet,
116 			int nAllowedEvents );
117 	virtual ~PropertyChgHelper();
118 
119 	virtual void	SetTmpPropVals( const com::sun::star::beans::PropertyValues &rPropVals );
120 
121 	// XEventListener
122 	virtual void SAL_CALL
123 		disposing( const ::com::sun::star::lang::EventObject& rSource )
124 			throw(::com::sun::star::uno::RuntimeException);
125 
126 	// XPropertyChangeListener
127 	virtual void SAL_CALL
128 		propertyChange( const ::com::sun::star::beans::PropertyChangeEvent& rEvt )
129 			throw(::com::sun::star::uno::RuntimeException);
130 
131 	// XLinguServiceEventBroadcaster
132     virtual sal_Bool SAL_CALL
133 		addLinguServiceEventListener(
134 				const ::com::sun::star::uno::Reference<
135 					::com::sun::star::linguistic2::XLinguServiceEventListener >& rxListener )
136 			throw(::com::sun::star::uno::RuntimeException);
137     virtual sal_Bool SAL_CALL
138 		removeLinguServiceEventListener(
139 				const ::com::sun::star::uno::Reference<
140 					::com::sun::star::linguistic2::XLinguServiceEventListener >& rxListener )
141 			throw(::com::sun::star::uno::RuntimeException);
142 
143 	// non-UNO functions
144 	void 	AddAsPropListener();
145 	void	RemoveAsPropListener();
146 	void	LaunchEvent(
147 				const ::com::sun::star::linguistic2::LinguServiceEvent& rEvt );
148 
149 	const ::com::sun::star::uno::Sequence< ::rtl::OUString > &
150 			GetPropNames() const	{ return aPropNames; }
151 	const ::com::sun::star::uno::Reference<
152 		::com::sun::star::beans::XPropertySet >	&
153 			GetPropSet() const		{ return xPropSet; }
154 	const ::com::sun::star::uno::Reference<
155 		::com::sun::star::uno::XInterface > &
156 			GetEvtObj() const		{ return xMyEvtObj; }
157 
158 	sal_Bool	IsIgnoreControlCharacters() const	{ return bResIsIgnoreControlCharacters; }
159 	sal_Bool	IsUseDictionaryList() const			{ return bResIsUseDictionaryList; }
160 };
161 
162 
163 ///////////////////////////////////////////////////////////////////////////
164 
165 class PropertyHelper_Thes :
166 	public PropertyChgHelper
167 {
168 	// disallow use of copy-constructor and assignment-operator
169 	PropertyHelper_Thes( const PropertyHelper_Thes & );
170 	PropertyHelper_Thes & operator = ( const PropertyHelper_Thes & );
171 
172 public:
173 	PropertyHelper_Thes(
174 			const ::com::sun::star::uno::Reference<
175 				::com::sun::star::uno::XInterface > &rxSource,
176 			::com::sun::star::uno::Reference<
177 				::com::sun::star::beans::XPropertySet > &rxPropSet );
178 	virtual ~PropertyHelper_Thes();
179 
180 	// XPropertyChangeListener
181 	virtual void SAL_CALL
182 		propertyChange( const ::com::sun::star::beans::PropertyChangeEvent& rEvt )
183 			throw(::com::sun::star::uno::RuntimeException);
184 };
185 
186 ///////////////////////////////////////////////////////////////////////////
187 
188 class PropertyHelper_Spell :
189 	public PropertyChgHelper
190 {
191 	// default values
192 	sal_Bool	bIsSpellUpperCase;
193 	sal_Bool	bIsSpellWithDigits;
194 	sal_Bool	bIsSpellCapitalization;
195 
196 	// return values, will be set to default value or current temporary value
197     sal_Int16   nResMaxNumberOfSuggestions; // special value that is not part of the property set and thus needs to be handled differently
198 	sal_Bool	bResIsSpellUpperCase;
199 	sal_Bool	bResIsSpellWithDigits;
200 	sal_Bool	bResIsSpellCapitalization;
201 
202 
203 	// disallow use of copy-constructor and assignment-operator
204 	PropertyHelper_Spell( const PropertyHelper_Spell & );
205 	PropertyHelper_Spell & operator = ( const PropertyHelper_Spell & );
206 
207 protected:
208 	// PropertyChgHelper
209 	virtual void	SetDefaultValues();
210 	virtual void	GetCurrentValues();
211 	virtual sal_Bool	propertyChange_Impl(
212 							const ::com::sun::star::beans::PropertyChangeEvent& rEvt );
213 
214 public:
215 	PropertyHelper_Spell(
216 			const ::com::sun::star::uno::Reference<
217 				::com::sun::star::uno::XInterface > &rxSource,
218 			::com::sun::star::uno::Reference<
219 				::com::sun::star::beans::XPropertySet > &rxPropSet );
220 	virtual ~PropertyHelper_Spell();
221 
222 	virtual void	SetTmpPropVals( const com::sun::star::beans::PropertyValues &rPropVals );
223 
224 	// XPropertyChangeListener
225 	virtual void SAL_CALL
226 		propertyChange( const ::com::sun::star::beans::PropertyChangeEvent& rEvt )
227 			throw(::com::sun::star::uno::RuntimeException);
228 
229     virtual sal_Int16   GetDefaultNumberOfSuggestions() const;
230 
231     sal_Int16   GetMaxNumberOfSuggestions() const   { return nResMaxNumberOfSuggestions; }
232 	sal_Bool	IsSpellUpperCase() const			{ return bResIsSpellUpperCase; }
233 	sal_Bool	IsSpellWithDigits() const			{ return bResIsSpellWithDigits; }
234 	sal_Bool	IsSpellCapitalization() const		{ return bResIsSpellCapitalization; }
235 };
236 
237 ///////////////////////////////////////////////////////////////////////////
238 
239 class PropertyHelper_Hyphen :
240 	public PropertyChgHelper
241 {
242 	// default values
243 	sal_Int16	nHyphMinLeading,
244 			nHyphMinTrailing,
245 			nHyphMinWordLength;
246 
247 	// return values, will be set to default value or current temporary value
248 	sal_Int16	nResHyphMinLeading,
249 			nResHyphMinTrailing,
250 			nResHyphMinWordLength;
251 
252 	// disallow use of copy-constructor and assignment-operator
253     PropertyHelper_Hyphen( const PropertyHelper_Hyphen & );
254     PropertyHelper_Hyphen & operator = ( const PropertyHelper_Hyphen & );
255 
256 protected:
257 	// PropertyChgHelper
258 	virtual void	SetDefaultValues();
259 	virtual void	GetCurrentValues();
260 	virtual sal_Bool	propertyChange_Impl(
261 							const ::com::sun::star::beans::PropertyChangeEvent& rEvt );
262 
263 public:
264     PropertyHelper_Hyphen(
265 			const ::com::sun::star::uno::Reference<
266 				::com::sun::star::uno::XInterface > &rxSource,
267 			::com::sun::star::uno::Reference<
268 				::com::sun::star::beans::XPropertySet > &rxPropSet);
269     virtual ~PropertyHelper_Hyphen();
270 
271 	virtual void	SetTmpPropVals( const com::sun::star::beans::PropertyValues &rPropVals );
272 
273 	// XPropertyChangeListener
274 	virtual void SAL_CALL
275 		propertyChange( const ::com::sun::star::beans::PropertyChangeEvent& rEvt )
276 			throw(::com::sun::star::uno::RuntimeException);
277 
278 	sal_Int16	GetMinLeading() const				{ return nResHyphMinLeading; }
279 	sal_Int16	GetMinTrailing() const				{ return nResHyphMinTrailing; }
280 	sal_Int16	GetMinWordLength() const			{ return nResHyphMinWordLength; }
281 };
282 
283 ///////////////////////////////////////////////////////////////////////////
284 
285 }   // namespace linguistic
286 
287 #endif
288 
289