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