Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <tools/debug.hxx>
31 : : #include <sal/macros.h>
32 : :
33 : : #include <com/sun/star/linguistic2/LinguServiceEvent.hpp>
34 : : #include <com/sun/star/linguistic2/LinguServiceEventFlags.hpp>
35 : : #include <com/sun/star/linguistic2/XLinguServiceEventListener.hpp>
36 : : #include <com/sun/star/beans/XPropertySet.hpp>
37 : : #include <osl/mutex.hxx>
38 : :
39 : : #include <linguistic/misc.hxx>
40 : : #include <linguistic/lngprops.hxx>
41 : :
42 : : #include <linguistic/lngprophelp.hxx>
43 : :
44 : : using namespace osl;
45 : : using namespace com::sun::star;
46 : : using namespace com::sun::star::beans;
47 : : using namespace com::sun::star::lang;
48 : : using namespace com::sun::star::uno;
49 : : using namespace com::sun::star::linguistic2;
50 : : using namespace linguistic;
51 : :
52 : : using ::rtl::OUString;
53 : :
54 : : namespace linguistic
55 : : {
56 : :
57 : :
58 : : static const char *aCH[] =
59 : : {
60 : : UPN_IS_IGNORE_CONTROL_CHARACTERS,
61 : : UPN_IS_USE_DICTIONARY_LIST,
62 : : };
63 : :
64 : : static int nCHCount = sizeof(aCH) / sizeof(aCH[0]);
65 : :
66 : :
67 : 49 : PropertyChgHelper::PropertyChgHelper(
68 : : const Reference< XInterface > &rxSource,
69 : : Reference< XPropertySet > &rxPropSet,
70 : : int nAllowedEvents ) :
71 : : PropertyChgHelperBase(),
72 : : aPropNames (nCHCount),
73 : : xMyEvtObj (rxSource),
74 [ + - ]: 49 : aLngSvcEvtListeners (GetLinguMutex()),
75 : : xPropSet (rxPropSet),
76 [ + - ][ + - ]: 98 : nEvtFlags (nAllowedEvents)
77 : : {
78 [ + - ]: 49 : OUString *pName = aPropNames.getArray();
79 [ + + ]: 147 : for (sal_Int32 i = 0; i < nCHCount; ++i)
80 : : {
81 : 98 : pName[i] = ::rtl::OUString::createFromAscii( aCH[i] );
82 : : }
83 : :
84 : 49 : SetDefaultValues();
85 : 49 : }
86 : :
87 : :
88 : 0 : PropertyChgHelper::PropertyChgHelper( const PropertyChgHelper &rHelper ) :
89 : : PropertyChgHelperBase(),
90 [ # # ][ # # ]: 0 : aLngSvcEvtListeners (GetLinguMutex())
[ # # ]
91 : : {
92 [ # # ]: 0 : RemoveAsPropListener();
93 [ # # ]: 0 : aPropNames = rHelper.aPropNames;
94 [ # # ]: 0 : xMyEvtObj = rHelper.xMyEvtObj;
95 [ # # ]: 0 : xPropSet = rHelper.xPropSet;
96 : 0 : nEvtFlags = rHelper.nEvtFlags;
97 [ # # ]: 0 : AddAsPropListener();
98 : :
99 : 0 : SetDefaultValues();
100 [ # # ]: 0 : GetCurrentValues();
101 : 0 : }
102 : :
103 : :
104 [ + - ][ + - ]: 49 : PropertyChgHelper::~PropertyChgHelper()
105 : : {
106 [ - + ]: 49 : }
107 : :
108 : :
109 : 49 : void PropertyChgHelper::AddPropNames( const char *pNewNames[], sal_Int32 nCount )
110 : : {
111 [ + - ][ + - ]: 49 : if (pNewNames && nCount)
112 : : {
113 : 49 : sal_Int32 nLen = GetPropNames().getLength();
114 : 49 : GetPropNames().realloc( nLen + nCount );
115 : 49 : OUString *pName = GetPropNames().getArray();
116 [ + + ]: 196 : for (sal_Int32 i = 0; i < nCount; ++i)
117 : : {
118 : 147 : pName[ nLen + i ] = ::rtl::OUString::createFromAscii( pNewNames[ i ] );
119 : :
120 : : }
121 : : }
122 : 49 : }
123 : :
124 : :
125 : 98 : void PropertyChgHelper::SetDefaultValues()
126 : : {
127 : 98 : bResIsIgnoreControlCharacters = bIsIgnoreControlCharacters = sal_True;
128 : 98 : bResIsUseDictionaryList = bIsUseDictionaryList = sal_True;
129 : 98 : }
130 : :
131 : :
132 : 49 : void PropertyChgHelper::GetCurrentValues()
133 : : {
134 : 49 : sal_Int32 nLen = GetPropNames().getLength();
135 [ + - ][ + - ]: 49 : if (GetPropSet().is() && nLen)
[ + - ]
136 : : {
137 : 49 : const OUString *pPropName = GetPropNames().getConstArray();
138 [ + + ]: 294 : for (sal_Int32 i = 0; i < nLen; ++i)
139 : : {
140 : 245 : sal_Bool *pbVal = NULL,
141 : 245 : *pbResVal = NULL;
142 : :
143 [ + + ]: 245 : if ( pPropName[i] == UPN_IS_IGNORE_CONTROL_CHARACTERS )
144 : : {
145 : 49 : pbVal = &bIsIgnoreControlCharacters;
146 : 49 : pbResVal = &bResIsIgnoreControlCharacters;
147 : : }
148 [ + + ]: 196 : else if ( pPropName[i] == UPN_IS_USE_DICTIONARY_LIST )
149 : : {
150 : 49 : pbVal = &bIsUseDictionaryList;
151 : 49 : pbResVal = &bResIsUseDictionaryList;
152 : : }
153 : :
154 [ + + ][ + - ]: 245 : if (pbVal && pbResVal)
155 : : {
156 : 98 : GetPropSet()->getPropertyValue( pPropName[i] ) >>= *pbVal;
157 : 98 : *pbResVal = *pbVal;
158 : : }
159 : : }
160 : : }
161 : 49 : }
162 : :
163 : :
164 : 48400 : void PropertyChgHelper::SetTmpPropVals( const PropertyValues &rPropVals )
165 : : {
166 : : // return value is default value unless there is an explicitly supplied
167 : : // temporary value
168 : 48400 : bResIsIgnoreControlCharacters = bIsIgnoreControlCharacters;
169 : 48400 : bResIsUseDictionaryList = bIsUseDictionaryList;
170 : :
171 : 48400 : sal_Int32 nLen = rPropVals.getLength();
172 [ - + ]: 48400 : if (nLen)
173 : : {
174 : 0 : const PropertyValue *pVal = rPropVals.getConstArray();
175 [ # # ]: 0 : for (sal_Int32 i = 0; i < nLen; ++i)
176 : : {
177 : 0 : sal_Bool *pbResVal = NULL;
178 [ # # # ]: 0 : switch (pVal[i].Handle)
179 : : {
180 : : case UPH_IS_IGNORE_CONTROL_CHARACTERS :
181 : 0 : pbResVal = &bResIsIgnoreControlCharacters; break;
182 : : case UPH_IS_USE_DICTIONARY_LIST :
183 : 0 : pbResVal = &bResIsUseDictionaryList; break;
184 : : default:
185 : : ;
186 : : }
187 [ # # ]: 0 : if (pbResVal)
188 : 0 : pVal[i].Value >>= *pbResVal;
189 : : }
190 : : }
191 : 48400 : }
192 : :
193 : :
194 : 0 : sal_Bool PropertyChgHelper::propertyChange_Impl( const PropertyChangeEvent& rEvt )
195 : : {
196 : 0 : sal_Bool bRes = sal_False;
197 : :
198 [ # # ][ # # ]: 0 : if (GetPropSet().is() && rEvt.Source == GetPropSet())
[ # # ]
199 : : {
200 : : sal_Int16 nLngSvcFlags = (nEvtFlags & AE_HYPHENATOR) ?
201 [ # # ]: 0 : LinguServiceEventFlags::HYPHENATE_AGAIN : 0;
202 : 0 : sal_Bool bSCWA = sal_False, // SPELL_CORRECT_WORDS_AGAIN ?
203 : 0 : bSWWA = sal_False; // SPELL_WRONG_WORDS_AGAIN ?
204 : :
205 : 0 : sal_Bool *pbVal = NULL;
206 [ # # # ]: 0 : switch (rEvt.PropertyHandle)
207 : : {
208 : : case UPH_IS_IGNORE_CONTROL_CHARACTERS :
209 : : {
210 : 0 : pbVal = &bIsIgnoreControlCharacters;
211 : 0 : nLngSvcFlags = 0;
212 : 0 : break;
213 : : }
214 : : case UPH_IS_USE_DICTIONARY_LIST :
215 : : {
216 : 0 : pbVal = &bIsUseDictionaryList;
217 : 0 : bSCWA = bSWWA = sal_True;
218 : 0 : break;
219 : : }
220 : : default:
221 : : {
222 : 0 : bRes = sal_False;
223 : : }
224 : : }
225 [ # # ]: 0 : if (pbVal)
226 : 0 : rEvt.NewValue >>= *pbVal;
227 : :
228 : 0 : bRes = 0 != pbVal; // sth changed?
229 [ # # ]: 0 : if (bRes)
230 : : {
231 : 0 : sal_Bool bSpellEvts = (nEvtFlags & AE_SPELLCHECKER) ? sal_True : sal_False;
232 [ # # ][ # # ]: 0 : if (bSCWA && bSpellEvts)
233 : 0 : nLngSvcFlags |= LinguServiceEventFlags::SPELL_CORRECT_WORDS_AGAIN;
234 [ # # ][ # # ]: 0 : if (bSWWA && bSpellEvts)
235 : 0 : nLngSvcFlags |= LinguServiceEventFlags::SPELL_WRONG_WORDS_AGAIN;
236 [ # # ]: 0 : if (nLngSvcFlags)
237 : : {
238 [ # # ]: 0 : LinguServiceEvent aEvt( GetEvtObj(), nLngSvcFlags );
239 [ # # ][ # # ]: 0 : LaunchEvent( aEvt );
240 : : }
241 : : }
242 : : }
243 : :
244 : 0 : return bRes;
245 : : }
246 : :
247 : :
248 : : void SAL_CALL
249 : 0 : PropertyChgHelper::propertyChange( const PropertyChangeEvent& rEvt )
250 : : throw(RuntimeException)
251 : : {
252 [ # # ][ # # ]: 0 : MutexGuard aGuard( GetLinguMutex() );
253 [ # # ][ # # ]: 0 : propertyChange_Impl( rEvt );
254 : 0 : }
255 : :
256 : :
257 : 49 : void PropertyChgHelper::AddAsPropListener()
258 : : {
259 [ + - ]: 49 : if (xPropSet.is())
260 : : {
261 : 49 : sal_Int32 nLen = aPropNames.getLength();
262 : 49 : const OUString *pPropName = aPropNames.getConstArray();
263 [ + + ]: 294 : for (sal_Int32 i = 0; i < nLen; ++i)
264 : : {
265 [ + - ]: 245 : if (!pPropName[i].isEmpty())
266 [ + - ]: 245 : xPropSet->addPropertyChangeListener( pPropName[i], this );
267 : : }
268 : : }
269 : 49 : }
270 : :
271 : 49 : void PropertyChgHelper::RemoveAsPropListener()
272 : : {
273 [ + - ]: 49 : if (xPropSet.is())
274 : : {
275 : 49 : sal_Int32 nLen = aPropNames.getLength();
276 : 49 : const OUString *pPropName = aPropNames.getConstArray();
277 [ + + ]: 294 : for (sal_Int32 i = 0; i < nLen; ++i)
278 : : {
279 [ + - ]: 245 : if (!pPropName[i].isEmpty())
280 [ + - ]: 245 : xPropSet->removePropertyChangeListener( pPropName[i], this );
281 : : }
282 : : }
283 : 49 : }
284 : :
285 : :
286 : 0 : void PropertyChgHelper::LaunchEvent( const LinguServiceEvent &rEvt )
287 : : {
288 [ # # ]: 0 : cppu::OInterfaceIteratorHelper aIt( aLngSvcEvtListeners );
289 [ # # ]: 0 : while (aIt.hasMoreElements())
290 : : {
291 [ # # ][ # # ]: 0 : Reference< XLinguServiceEventListener > xRef( aIt.next(), UNO_QUERY );
292 [ # # ]: 0 : if (xRef.is())
293 [ # # ][ # # ]: 0 : xRef->processLinguServiceEvent( rEvt );
294 [ # # ]: 0 : }
295 : 0 : }
296 : :
297 : :
298 : 0 : void SAL_CALL PropertyChgHelper::disposing( const EventObject& rSource )
299 : : throw(RuntimeException)
300 : : {
301 [ # # ][ # # ]: 0 : MutexGuard aGuard( GetLinguMutex() );
302 [ # # ][ # # ]: 0 : if (rSource.Source == xPropSet)
303 : : {
304 [ # # ]: 0 : RemoveAsPropListener();
305 [ # # ]: 0 : xPropSet = NULL;
306 [ # # ]: 0 : aPropNames.realloc( 0 );
307 [ # # ]: 0 : }
308 : 0 : }
309 : :
310 : :
311 : : sal_Bool SAL_CALL
312 : 49 : PropertyChgHelper::addLinguServiceEventListener(
313 : : const Reference< XLinguServiceEventListener >& rxListener )
314 : : throw(RuntimeException)
315 : : {
316 [ + - ][ + - ]: 49 : MutexGuard aGuard( GetLinguMutex() );
317 : :
318 : 49 : sal_Bool bRes = sal_False;
319 [ + - ]: 49 : if (rxListener.is())
320 : : {
321 [ + - ]: 49 : sal_Int32 nCount = aLngSvcEvtListeners.getLength();
322 [ + - ]: 49 : bRes = aLngSvcEvtListeners.addInterface( rxListener ) != nCount;
323 : : }
324 [ + - ]: 49 : return bRes;
325 : : }
326 : :
327 : :
328 : : sal_Bool SAL_CALL
329 : 0 : PropertyChgHelper::removeLinguServiceEventListener(
330 : : const Reference< XLinguServiceEventListener >& rxListener )
331 : : throw(RuntimeException)
332 : : {
333 [ # # ][ # # ]: 0 : MutexGuard aGuard( GetLinguMutex() );
334 : :
335 : 0 : sal_Bool bRes = sal_False;
336 [ # # ]: 0 : if (rxListener.is())
337 : : {
338 [ # # ]: 0 : sal_Int32 nCount = aLngSvcEvtListeners.getLength();
339 [ # # ]: 0 : bRes = aLngSvcEvtListeners.removeInterface( rxListener ) != nCount;
340 : : }
341 [ # # ]: 0 : return bRes;
342 : : }
343 : :
344 : :
345 : :
346 : 0 : PropertyHelper_Thes::PropertyHelper_Thes(
347 : : const Reference< XInterface > &rxSource,
348 : : Reference< XPropertySet > &rxPropSet ) :
349 : 0 : PropertyChgHelper ( rxSource, rxPropSet, 0 )
350 : : {
351 : 0 : SetDefaultValues();
352 [ # # ]: 0 : GetCurrentValues();
353 : 0 : }
354 : :
355 : :
356 : 0 : PropertyHelper_Thes::~PropertyHelper_Thes()
357 : : {
358 [ # # ]: 0 : }
359 : :
360 : :
361 : : void SAL_CALL
362 : 0 : PropertyHelper_Thes::propertyChange( const PropertyChangeEvent& rEvt )
363 : : throw(RuntimeException)
364 : : {
365 [ # # ][ # # ]: 0 : MutexGuard aGuard( GetLinguMutex() );
366 [ # # ][ # # ]: 0 : PropertyChgHelper::propertyChange_Impl( rEvt );
367 : 0 : }
368 : :
369 : :
370 : :
371 : : // list of properties from the property set to be used
372 : : // and listened to
373 : : static const char *aSP[] =
374 : : {
375 : : UPN_IS_SPELL_UPPER_CASE,
376 : : UPN_IS_SPELL_WITH_DIGITS,
377 : : UPN_IS_SPELL_CAPITALIZATION
378 : : };
379 : :
380 : :
381 : 40 : PropertyHelper_Spell::PropertyHelper_Spell(
382 : : const Reference< XInterface > & rxSource,
383 : : Reference< XPropertySet > &rxPropSet ) :
384 : 40 : PropertyChgHelper ( rxSource, rxPropSet, AE_SPELLCHECKER )
385 : : {
386 [ + - ]: 40 : AddPropNames( aSP, sizeof(aSP) / sizeof(aSP[0]) );
387 [ + - ]: 40 : SetDefaultValues();
388 [ + - ]: 40 : GetCurrentValues();
389 : :
390 [ + - ]: 40 : nResMaxNumberOfSuggestions = GetDefaultNumberOfSuggestions();
391 : 40 : }
392 : :
393 : :
394 : 40 : PropertyHelper_Spell::~PropertyHelper_Spell()
395 : : {
396 [ - + ]: 80 : }
397 : :
398 : :
399 : 40 : void PropertyHelper_Spell::SetDefaultValues()
400 : : {
401 : 40 : PropertyChgHelper::SetDefaultValues();
402 : :
403 : 40 : bResIsSpellUpperCase = bIsSpellUpperCase = sal_False;
404 : 40 : bResIsSpellWithDigits = bIsSpellWithDigits = sal_False;
405 : 40 : bResIsSpellCapitalization = bIsSpellCapitalization = sal_True;
406 : 40 : }
407 : :
408 : :
409 : 40 : void PropertyHelper_Spell::GetCurrentValues()
410 : : {
411 : 40 : PropertyChgHelper::GetCurrentValues();
412 : :
413 : 40 : sal_Int32 nLen = GetPropNames().getLength();
414 [ + - ][ + - ]: 40 : if (GetPropSet().is() && nLen)
[ + - ]
415 : : {
416 : 40 : const OUString *pPropName = GetPropNames().getConstArray();
417 [ + + ]: 240 : for (sal_Int32 i = 0; i < nLen; ++i)
418 : : {
419 : 200 : sal_Bool *pbVal = NULL,
420 : 200 : *pbResVal = NULL;
421 : :
422 [ + + ]: 200 : if ( pPropName[i] == UPN_IS_SPELL_UPPER_CASE )
423 : : {
424 : 40 : pbVal = &bIsSpellUpperCase;
425 : 40 : pbResVal = &bResIsSpellUpperCase;
426 : : }
427 [ + + ]: 160 : else if ( pPropName[i] == UPN_IS_SPELL_WITH_DIGITS )
428 : : {
429 : 40 : pbVal = &bIsSpellWithDigits;
430 : 40 : pbResVal = &bResIsSpellWithDigits;
431 : : }
432 [ + + ]: 120 : else if ( pPropName[i] == UPN_IS_SPELL_CAPITALIZATION )
433 : : {
434 : 40 : pbVal = &bIsSpellCapitalization;
435 : 40 : pbResVal = &bResIsSpellCapitalization;
436 : : }
437 : :
438 [ + + ][ + - ]: 200 : if (pbVal && pbResVal)
439 : : {
440 : 120 : GetPropSet()->getPropertyValue( pPropName[i] ) >>= *pbVal;
441 : 120 : *pbResVal = *pbVal;
442 : : }
443 : : }
444 : : }
445 : 40 : }
446 : :
447 : :
448 : 0 : sal_Bool PropertyHelper_Spell::propertyChange_Impl( const PropertyChangeEvent& rEvt )
449 : : {
450 : 0 : sal_Bool bRes = PropertyChgHelper::propertyChange_Impl( rEvt );
451 : :
452 [ # # ][ # # ]: 0 : if (!bRes && GetPropSet().is() && rEvt.Source == GetPropSet())
[ # # ][ # # ]
453 : : {
454 : 0 : sal_Bool bSCWA = sal_False, // SPELL_CORRECT_WORDS_AGAIN ?
455 : 0 : bSWWA = sal_False; // SPELL_WRONG_WORDS_AGAIN ?
456 : :
457 : 0 : sal_Bool *pbVal = NULL;
458 [ # # # # ]: 0 : switch (rEvt.PropertyHandle)
459 : : {
460 : : case UPH_IS_SPELL_UPPER_CASE :
461 : : {
462 : 0 : pbVal = &bIsSpellUpperCase;
463 : 0 : bSCWA = sal_False == *pbVal; // sal_False->sal_True change?
464 : 0 : bSWWA = !bSCWA; // sal_True->sal_False change?
465 : 0 : break;
466 : : }
467 : : case UPH_IS_SPELL_WITH_DIGITS :
468 : : {
469 : 0 : pbVal = &bIsSpellWithDigits;
470 : 0 : bSCWA = sal_False == *pbVal; // sal_False->sal_True change?
471 : 0 : bSWWA = !bSCWA; // sal_True->sal_False change?
472 : 0 : break;
473 : : }
474 : : case UPH_IS_SPELL_CAPITALIZATION :
475 : : {
476 : 0 : pbVal = &bIsSpellCapitalization;
477 : 0 : bSCWA = sal_False == *pbVal; // sal_False->sal_True change?
478 : 0 : bSWWA = !bSCWA; // sal_True->sal_False change?
479 : 0 : break;
480 : : }
481 : : default:
482 : : DBG_ASSERT( 0, "unknown property" );
483 : : }
484 [ # # ]: 0 : if (pbVal)
485 : 0 : rEvt.NewValue >>= *pbVal;
486 : :
487 : 0 : bRes = (pbVal != 0);
488 [ # # ]: 0 : if (bRes)
489 : : {
490 : 0 : sal_Int16 nLngSvcFlags = 0;
491 [ # # ]: 0 : if (bSCWA)
492 : 0 : nLngSvcFlags |= LinguServiceEventFlags::SPELL_CORRECT_WORDS_AGAIN;
493 [ # # ]: 0 : if (bSWWA)
494 : 0 : nLngSvcFlags |= LinguServiceEventFlags::SPELL_WRONG_WORDS_AGAIN;
495 [ # # ]: 0 : if (nLngSvcFlags)
496 : : {
497 [ # # ]: 0 : LinguServiceEvent aEvt( GetEvtObj(), nLngSvcFlags );
498 [ # # ][ # # ]: 0 : LaunchEvent( aEvt );
499 : : }
500 : : }
501 : : }
502 : :
503 : 0 : return bRes;
504 : : }
505 : :
506 : :
507 : : void SAL_CALL
508 : 0 : PropertyHelper_Spell::propertyChange( const PropertyChangeEvent& rEvt )
509 : : throw(RuntimeException)
510 : : {
511 [ # # ][ # # ]: 0 : MutexGuard aGuard( GetLinguMutex() );
512 [ # # ][ # # ]: 0 : propertyChange_Impl( rEvt );
513 : 0 : }
514 : :
515 : :
516 : 14797 : void PropertyHelper_Spell::SetTmpPropVals( const PropertyValues &rPropVals )
517 : : {
518 : 14797 : PropertyChgHelper::SetTmpPropVals( rPropVals );
519 : :
520 : : // return value is default value unless there is an explicitly supplied
521 : : // temporary value
522 : 14797 : nResMaxNumberOfSuggestions = GetDefaultNumberOfSuggestions();
523 : 14797 : bResIsSpellWithDigits = bIsSpellWithDigits;
524 : 14797 : bResIsSpellCapitalization = bIsSpellCapitalization;
525 : 14797 : bResIsSpellUpperCase = bIsSpellUpperCase;
526 : :
527 : 14797 : sal_Int32 nLen = rPropVals.getLength();
528 [ - + ]: 14797 : if (nLen)
529 : : {
530 : 0 : const PropertyValue *pVal = rPropVals.getConstArray();
531 [ # # ]: 0 : for (sal_Int32 i = 0; i < nLen; ++i)
532 : : {
533 [ # # ]: 0 : if ( pVal[i].Name == UPN_MAX_NUMBER_OF_SUGGESTIONS )
534 : : {
535 : 0 : pVal[i].Value >>= nResMaxNumberOfSuggestions;
536 : : }
537 : : else
538 : : {
539 : 0 : sal_Bool *pbResVal = NULL;
540 [ # # # # ]: 0 : switch (pVal[i].Handle)
541 : : {
542 : 0 : case UPH_IS_SPELL_UPPER_CASE : pbResVal = &bResIsSpellUpperCase; break;
543 : 0 : case UPH_IS_SPELL_WITH_DIGITS : pbResVal = &bResIsSpellWithDigits; break;
544 : 0 : case UPH_IS_SPELL_CAPITALIZATION : pbResVal = &bResIsSpellCapitalization; break;
545 : : default:
546 : : DBG_ASSERT( 0, "unknown property" );
547 : : }
548 [ # # ]: 0 : if (pbResVal)
549 : 0 : pVal[i].Value >>= *pbResVal;
550 : : }
551 : : }
552 : : }
553 : 14797 : }
554 : :
555 : 14837 : sal_Int16 PropertyHelper_Spell::GetDefaultNumberOfSuggestions() const
556 : : {
557 : 14837 : return 16;
558 : : }
559 : :
560 : :
561 : : static const char *aHP[] =
562 : : {
563 : : UPN_HYPH_MIN_LEADING,
564 : : UPN_HYPH_MIN_TRAILING,
565 : : UPN_HYPH_MIN_WORD_LENGTH
566 : : };
567 : :
568 : :
569 : 9 : PropertyHelper_Hyphen::PropertyHelper_Hyphen(
570 : : const Reference< XInterface > & rxSource,
571 : : Reference< XPropertySet > &rxPropSet ) :
572 : 9 : PropertyChgHelper ( rxSource, rxPropSet, AE_HYPHENATOR )
573 : : {
574 [ + - ]: 9 : AddPropNames( aHP, sizeof(aHP) / sizeof(aHP[0]) );
575 : 9 : SetDefaultValues();
576 [ + - ]: 9 : GetCurrentValues();
577 : 9 : }
578 : :
579 : :
580 : 9 : PropertyHelper_Hyphen::~PropertyHelper_Hyphen()
581 : : {
582 [ - + ]: 18 : }
583 : :
584 : :
585 : 9 : void PropertyHelper_Hyphen::SetDefaultValues()
586 : : {
587 : 9 : PropertyChgHelper::SetDefaultValues();
588 : :
589 : 9 : nResHyphMinLeading = nHyphMinLeading = 2;
590 : 9 : nResHyphMinTrailing = nHyphMinTrailing = 2;
591 : 9 : nResHyphMinWordLength = nHyphMinWordLength = 0;
592 : 9 : }
593 : :
594 : :
595 : 9 : void PropertyHelper_Hyphen::GetCurrentValues()
596 : : {
597 : 9 : PropertyChgHelper::GetCurrentValues();
598 : :
599 : 9 : sal_Int32 nLen = GetPropNames().getLength();
600 [ + - ][ + - ]: 9 : if (GetPropSet().is() && nLen)
[ + - ]
601 : : {
602 : 9 : const OUString *pPropName = GetPropNames().getConstArray();
603 [ + + ]: 54 : for (sal_Int32 i = 0; i < nLen; ++i)
604 : : {
605 : 45 : sal_Int16 *pnVal = NULL,
606 : 45 : *pnResVal = NULL;
607 : :
608 [ + + ]: 45 : if ( pPropName[i] == UPN_HYPH_MIN_LEADING )
609 : : {
610 : 9 : pnVal = &nHyphMinLeading;
611 : 9 : pnResVal = &nResHyphMinLeading;
612 : : }
613 [ + + ]: 36 : else if ( pPropName[i] == UPN_HYPH_MIN_TRAILING )
614 : : {
615 : 9 : pnVal = &nHyphMinTrailing;
616 : 9 : pnResVal = &nResHyphMinTrailing;
617 : : }
618 [ + + ]: 27 : else if ( pPropName[i] == UPN_HYPH_MIN_WORD_LENGTH )
619 : : {
620 : 9 : pnVal = &nHyphMinWordLength;
621 : 9 : pnResVal = &nResHyphMinWordLength;
622 : : }
623 : :
624 [ + + ][ + - ]: 45 : if (pnVal && pnResVal)
625 : : {
626 : 27 : GetPropSet()->getPropertyValue( pPropName[i] ) >>= *pnVal;
627 : 27 : *pnResVal = *pnVal;
628 : : }
629 : : }
630 : : }
631 : 9 : }
632 : :
633 : :
634 : 0 : sal_Bool PropertyHelper_Hyphen::propertyChange_Impl( const PropertyChangeEvent& rEvt )
635 : : {
636 : 0 : sal_Bool bRes = PropertyChgHelper::propertyChange_Impl( rEvt );
637 : :
638 [ # # ][ # # ]: 0 : if (!bRes && GetPropSet().is() && rEvt.Source == GetPropSet())
[ # # ][ # # ]
639 : : {
640 : 0 : sal_Int16 nLngSvcFlags = LinguServiceEventFlags::HYPHENATE_AGAIN;
641 : :
642 : 0 : sal_Int16 *pnVal = NULL;
643 [ # # # # ]: 0 : switch (rEvt.PropertyHandle)
644 : : {
645 : 0 : case UPH_HYPH_MIN_LEADING : pnVal = &nHyphMinLeading; break;
646 : 0 : case UPH_HYPH_MIN_TRAILING : pnVal = &nHyphMinTrailing; break;
647 : 0 : case UPH_HYPH_MIN_WORD_LENGTH : pnVal = &nHyphMinWordLength; break;
648 : : default:
649 : : DBG_ASSERT( 0, "unknown property" );
650 : : }
651 [ # # ]: 0 : if (pnVal)
652 : 0 : rEvt.NewValue >>= *pnVal;
653 : :
654 : 0 : bRes = (pnVal != 0);
655 [ # # ]: 0 : if (bRes)
656 : : {
657 [ # # ]: 0 : if (nLngSvcFlags)
658 : : {
659 [ # # ]: 0 : LinguServiceEvent aEvt( GetEvtObj(), nLngSvcFlags );
660 [ # # ][ # # ]: 0 : LaunchEvent( aEvt );
661 : : }
662 : : }
663 : : }
664 : :
665 : 0 : return bRes;
666 : : }
667 : :
668 : :
669 : : void SAL_CALL
670 : 0 : PropertyHelper_Hyphen::propertyChange( const PropertyChangeEvent& rEvt )
671 : : throw(RuntimeException)
672 : : {
673 [ # # ][ # # ]: 0 : MutexGuard aGuard( GetLinguMutex() );
674 [ # # ][ # # ]: 0 : propertyChange_Impl( rEvt );
675 : 0 : }
676 : :
677 : :
678 : 33603 : void PropertyHelper_Hyphen::SetTmpPropVals( const PropertyValues &rPropVals )
679 : : {
680 : 33603 : PropertyChgHelper::SetTmpPropVals( rPropVals );
681 : :
682 : : // return value is default value unless there is an explicitly supplied
683 : : // temporary value
684 : 33603 : nResHyphMinLeading = nHyphMinLeading;
685 : 33603 : nResHyphMinTrailing = nHyphMinTrailing;
686 : 33603 : nResHyphMinWordLength = nHyphMinWordLength;
687 : :
688 : 33603 : sal_Int32 nLen = rPropVals.getLength();
689 : :
690 [ - + ]: 33603 : if (nLen)
691 : : {
692 : 0 : const PropertyValue *pVal = rPropVals.getConstArray();
693 [ # # ]: 0 : for (sal_Int32 i = 0; i < nLen; ++i)
694 : : {
695 : 0 : sal_Int16 *pnResVal = NULL;
696 : :
697 [ # # ]: 0 : if ( pVal[i].Name == UPN_HYPH_MIN_LEADING )
698 : 0 : pnResVal = &nResHyphMinLeading;
699 [ # # ]: 0 : else if ( pVal[i].Name == UPN_HYPH_MIN_TRAILING )
700 : 0 : pnResVal = &nResHyphMinTrailing;
701 [ # # ]: 0 : else if ( pVal[i].Name == UPN_HYPH_MIN_WORD_LENGTH )
702 : 0 : pnResVal = &nResHyphMinWordLength;
703 : :
704 : : DBG_ASSERT( pnResVal, "unknown property" );
705 : :
706 [ # # ]: 0 : if (pnResVal)
707 : 0 : pVal[i].Value >>= *pnResVal;
708 : : }
709 : : }
710 : 33603 : }
711 : :
712 : 0 : PropertyHelper_Thesaurus::PropertyHelper_Thesaurus(
713 : : const ::com::sun::star::uno::Reference<
714 : : ::com::sun::star::uno::XInterface > &rxSource,
715 : : ::com::sun::star::uno::Reference<
716 : 0 : ::com::sun::star::beans::XPropertySet > &rxPropSet )
717 : : {
718 [ # # ]: 0 : pInst = new PropertyHelper_Thes( rxSource, rxPropSet );
719 [ # # ][ # # ]: 0 : xPropHelper = pInst;
720 : 0 : }
721 : :
722 : 0 : PropertyHelper_Thesaurus::~PropertyHelper_Thesaurus()
723 : : {
724 : 0 : }
725 : :
726 : 0 : void PropertyHelper_Thesaurus::AddAsPropListener()
727 : : {
728 : 0 : pInst->AddAsPropListener();
729 : 0 : }
730 : :
731 : 0 : void PropertyHelper_Thesaurus::RemoveAsPropListener()
732 : : {
733 : 0 : pInst->RemoveAsPropListener();
734 : 0 : }
735 : :
736 : 0 : void PropertyHelper_Thesaurus::SetTmpPropVals( const com::sun::star::beans::PropertyValues &rPropVals )
737 : : {
738 : 0 : pInst->SetTmpPropVals( rPropVals );
739 : 0 : }
740 : :
741 : 9 : PropertyHelper_Hyphenation::PropertyHelper_Hyphenation(
742 : : const ::com::sun::star::uno::Reference<
743 : : ::com::sun::star::uno::XInterface > &rxSource,
744 : : ::com::sun::star::uno::Reference<
745 : 9 : ::com::sun::star::beans::XPropertySet > &rxPropSet)
746 : : {
747 [ + - ]: 9 : pInst = new PropertyHelper_Hyphen( rxSource, rxPropSet );
748 [ + - ][ + - ]: 9 : xPropHelper = pInst;
749 : 9 : }
750 : :
751 : 9 : PropertyHelper_Hyphenation::~PropertyHelper_Hyphenation()
752 : : {
753 : 9 : }
754 : :
755 : 9 : void PropertyHelper_Hyphenation::AddAsPropListener()
756 : : {
757 : 9 : pInst->AddAsPropListener();
758 : 9 : }
759 : :
760 : 9 : void PropertyHelper_Hyphenation::RemoveAsPropListener()
761 : : {
762 : 9 : pInst->RemoveAsPropListener();
763 : 9 : }
764 : :
765 : 33603 : void PropertyHelper_Hyphenation::SetTmpPropVals( const com::sun::star::beans::PropertyValues &rPropVals )
766 : : {
767 : 33603 : pInst->SetTmpPropVals( rPropVals );
768 : 33603 : }
769 : :
770 : 33603 : sal_Int16 PropertyHelper_Hyphenation::GetMinLeading() const
771 : : {
772 : 33603 : return pInst->GetMinLeading();
773 : : }
774 : :
775 : 33603 : sal_Int16 PropertyHelper_Hyphenation::GetMinTrailing() const
776 : : {
777 : 33603 : return pInst->GetMinTrailing();
778 : : }
779 : :
780 : 33603 : sal_Int16 PropertyHelper_Hyphenation::GetMinWordLength() const
781 : : {
782 : 33603 : return pInst->GetMinWordLength();
783 : : }
784 : :
785 : 9 : sal_Bool PropertyHelper_Hyphenation::addLinguServiceEventListener(
786 : : const ::com::sun::star::uno::Reference<
787 : : ::com::sun::star::linguistic2::XLinguServiceEventListener >& rxListener )
788 : : throw(::com::sun::star::uno::RuntimeException)
789 : : {
790 : 9 : return pInst->addLinguServiceEventListener( rxListener );
791 : : }
792 : :
793 : 0 : sal_Bool PropertyHelper_Hyphenation::removeLinguServiceEventListener(
794 : : const ::com::sun::star::uno::Reference<
795 : : ::com::sun::star::linguistic2::XLinguServiceEventListener >& rxListener )
796 : : throw(::com::sun::star::uno::RuntimeException)
797 : : {
798 : 0 : return pInst->removeLinguServiceEventListener( rxListener );
799 : : }
800 : :
801 : 40 : PropertyHelper_Spelling::PropertyHelper_Spelling(
802 : : const ::com::sun::star::uno::Reference<
803 : : ::com::sun::star::uno::XInterface > &rxSource,
804 : : ::com::sun::star::uno::Reference<
805 : 40 : ::com::sun::star::beans::XPropertySet > &rxPropSet )
806 : : {
807 [ + - ]: 40 : pInst = new PropertyHelper_Spell( rxSource, rxPropSet );
808 [ + - ][ + - ]: 40 : xPropHelper = pInst;
809 : 40 : }
810 : :
811 : 40 : PropertyHelper_Spelling::~PropertyHelper_Spelling()
812 : : {
813 : 40 : }
814 : :
815 : 40 : void PropertyHelper_Spelling::AddAsPropListener()
816 : : {
817 : 40 : pInst->AddAsPropListener();
818 : 40 : }
819 : :
820 : 40 : void PropertyHelper_Spelling::RemoveAsPropListener()
821 : : {
822 : 40 : pInst->RemoveAsPropListener();
823 : 40 : }
824 : :
825 : 14797 : void PropertyHelper_Spelling::SetTmpPropVals( const com::sun::star::beans::PropertyValues &rPropVals )
826 : : {
827 : 14797 : pInst->SetTmpPropVals( rPropVals );
828 : 14797 : }
829 : :
830 : 12613 : sal_Bool PropertyHelper_Spelling::IsSpellUpperCase() const
831 : : {
832 : 12613 : return pInst->IsSpellUpperCase();
833 : : }
834 : :
835 : 12449 : sal_Bool PropertyHelper_Spelling::IsSpellWithDigits() const
836 : : {
837 : 12449 : return pInst->IsSpellWithDigits();
838 : : }
839 : :
840 : 4096 : sal_Bool PropertyHelper_Spelling::IsSpellCapitalization() const
841 : : {
842 : 4096 : return pInst->IsSpellCapitalization();
843 : : }
844 : :
845 : 40 : sal_Bool PropertyHelper_Spelling::addLinguServiceEventListener(
846 : : const ::com::sun::star::uno::Reference<
847 : : ::com::sun::star::linguistic2::XLinguServiceEventListener >& rxListener )
848 : : throw(::com::sun::star::uno::RuntimeException)
849 : : {
850 : 40 : return pInst->addLinguServiceEventListener( rxListener );
851 : : }
852 : :
853 : 0 : sal_Bool PropertyHelper_Spelling::removeLinguServiceEventListener(
854 : : const ::com::sun::star::uno::Reference<
855 : : ::com::sun::star::linguistic2::XLinguServiceEventListener >& rxListener )
856 : : throw(::com::sun::star::uno::RuntimeException)
857 : : {
858 : 0 : return pInst->removeLinguServiceEventListener( rxListener );
859 : : }
860 : :
861 : : } // namespace linguistic
862 : :
863 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|