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