LCOV - code coverage report
Current view: top level - libreoffice/linguistic/source - lngprophelp.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 390 0.0 %
Date: 2012-12-27 Functions: 0 62 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10