LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/forms/source/component - refvaluecomponent.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 90 117 76.9 %
Date: 2013-07-09 Functions: 12 14 85.7 %
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             : #include "refvaluecomponent.hxx"
      21             : 
      22             : #include <tools/diagnose_ex.h>
      23             : 
      24             : #include <list>
      25             : 
      26             : //........................................................................
      27             : namespace frm
      28             : {
      29             : //........................................................................
      30             : 
      31             :     using namespace ::com::sun::star::uno;
      32             :     using namespace ::com::sun::star::lang;
      33             :     using namespace ::com::sun::star::beans;
      34             :     using namespace ::com::sun::star::form::binding;
      35             : 
      36             :     //====================================================================
      37             :     //=
      38             :     //====================================================================
      39             :     //--------------------------------------------------------------------
      40          38 :     OReferenceValueComponent::OReferenceValueComponent( const Reference< XComponentContext >& _rxFactory, const OUString& _rUnoControlModelTypeName, const OUString& _rDefault, sal_Bool _bSupportNoCheckRefValue )
      41             :         :OBoundControlModel( _rxFactory, _rUnoControlModelTypeName, _rDefault, sal_False, sal_True, sal_True )
      42             :         ,m_eDefaultChecked( STATE_NOCHECK )
      43          38 :         ,m_bSupportSecondRefValue( _bSupportNoCheckRefValue )
      44             :     {
      45          38 :     }
      46             : 
      47             :     //--------------------------------------------------------------------
      48           2 :     OReferenceValueComponent::OReferenceValueComponent( const OReferenceValueComponent* _pOriginal, const Reference< XComponentContext>& _rxFactory )
      49           2 :         :OBoundControlModel( _pOriginal, _rxFactory )
      50             :     {
      51           2 :         m_sReferenceValue           = _pOriginal->m_sReferenceValue;
      52           2 :         m_sNoCheckReferenceValue    = _pOriginal->m_sNoCheckReferenceValue;
      53           2 :         m_eDefaultChecked           = _pOriginal->m_eDefaultChecked;
      54           2 :         m_bSupportSecondRefValue    = _pOriginal->m_bSupportSecondRefValue;
      55             : 
      56           2 :         calculateExternalValueType();
      57           2 :     }
      58             : 
      59             :     //--------------------------------------------------------------------
      60          37 :     OReferenceValueComponent::~OReferenceValueComponent()
      61             :     {
      62          37 :     }
      63             : 
      64             :     //--------------------------------------------------------------------
      65           2 :     void OReferenceValueComponent::setReferenceValue( const OUString& _rRefValue )
      66             :     {
      67           2 :         m_sReferenceValue = _rRefValue;
      68           2 :         calculateExternalValueType();
      69           2 :     }
      70             : 
      71             :     //--------------------------------------------------------------------
      72        8444 :     void SAL_CALL OReferenceValueComponent::getFastPropertyValue( Any& _rValue, sal_Int32 _nHandle ) const
      73             :     {
      74        8444 :         switch ( _nHandle )
      75             :         {
      76         175 :         case PROPERTY_ID_REFVALUE:          _rValue <<= m_sReferenceValue; break;
      77         177 :         case PROPERTY_ID_DEFAULT_STATE:    _rValue <<= (sal_Int16)m_eDefaultChecked; break;
      78             : 
      79             :         case PROPERTY_ID_UNCHECKED_REFVALUE:
      80             :             OSL_ENSURE( m_bSupportSecondRefValue, "OReferenceValueComponent::getFastPropertyValue: not supported!" );
      81         175 :             _rValue <<= m_sNoCheckReferenceValue;
      82         175 :             break;
      83             : 
      84             :         default:
      85        7917 :             OBoundControlModel::getFastPropertyValue( _rValue, _nHandle );
      86             :         }
      87        8444 :     }
      88             : 
      89             :     //--------------------------------------------------------------------
      90         309 :     void SAL_CALL OReferenceValueComponent::setFastPropertyValue_NoBroadcast( sal_Int32 _nHandle, const Any& _rValue ) throw (Exception)
      91             :     {
      92         309 :         switch ( _nHandle )
      93             :         {
      94             :         case PROPERTY_ID_REFVALUE :
      95          22 :             OSL_VERIFY( _rValue >>= m_sReferenceValue );
      96          22 :             calculateExternalValueType();
      97          22 :             break;
      98             : 
      99             :         case PROPERTY_ID_UNCHECKED_REFVALUE:
     100             :             OSL_ENSURE( m_bSupportSecondRefValue, "OReferenceValueComponent::setFastPropertyValue_NoBroadcast: not supported!" );
     101          22 :             OSL_VERIFY( _rValue >>= m_sNoCheckReferenceValue );
     102          22 :             break;
     103             : 
     104             :         case PROPERTY_ID_DEFAULT_STATE:
     105             :         {
     106          25 :             sal_Int16 nDefaultChecked( (sal_Int16)STATE_NOCHECK );
     107          25 :             OSL_VERIFY( _rValue >>= nDefaultChecked );
     108          25 :             m_eDefaultChecked = (ToggleState)nDefaultChecked;
     109          25 :             resetNoBroadcast();
     110             :         }
     111          25 :         break;
     112             : 
     113             :         default:
     114         240 :             OBoundControlModel::setFastPropertyValue_NoBroadcast( _nHandle, _rValue );
     115             :         }
     116         309 :     }
     117             : 
     118             :     //--------------------------------------------------------------------
     119        1308 :     sal_Bool SAL_CALL OReferenceValueComponent::convertFastPropertyValue( Any& _rConvertedValue, Any& _rOldValue, sal_Int32 _nHandle, const Any& _rValue ) throw (IllegalArgumentException)
     120             :     {
     121        1308 :         sal_Bool bModified = sal_False;
     122        1308 :         switch ( _nHandle )
     123             :         {
     124             :         case PROPERTY_ID_REFVALUE:
     125         112 :             bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, m_sReferenceValue );
     126         112 :             break;
     127             : 
     128             :         case PROPERTY_ID_UNCHECKED_REFVALUE:
     129             :             OSL_ENSURE( m_bSupportSecondRefValue, "OReferenceValueComponent::convertFastPropertyValue: not supported!" );
     130         112 :             bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, m_sNoCheckReferenceValue );
     131         112 :             break;
     132             : 
     133             :         case PROPERTY_ID_DEFAULT_STATE:
     134         120 :             bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, (sal_Int16)m_eDefaultChecked );
     135         120 :             break;
     136             : 
     137             :         default:
     138         964 :             bModified = OBoundControlModel::convertFastPropertyValue( _rConvertedValue, _rOldValue, _nHandle, _rValue );
     139         964 :             break;
     140             :         }
     141        1308 :         return bModified;
     142             :     }
     143             : 
     144             :     //------------------------------------------------------------------------------
     145          30 :     Any OReferenceValueComponent::getDefaultForReset() const
     146             :     {
     147          30 :         return makeAny( (sal_Int16)m_eDefaultChecked );
     148             :     }
     149             : 
     150             :     //--------------------------------------------------------------------
     151          42 :     void OReferenceValueComponent::describeFixedProperties( Sequence< Property >& _rProps ) const
     152             :     {
     153          42 :         BEGIN_DESCRIBE_PROPERTIES( m_bSupportSecondRefValue ? 3 : 2, OBoundControlModel )
     154          42 :             DECL_PROP1( REFVALUE,       OUString,    BOUND );
     155          42 :             DECL_PROP1( DEFAULT_STATE, sal_Int16,          BOUND );
     156          42 :             if ( m_bSupportSecondRefValue )
     157             :             {
     158          42 :                 DECL_PROP1( UNCHECKED_REFVALUE, OUString,    BOUND );
     159             :             }
     160             :         END_DESCRIBE_PROPERTIES();
     161          42 :     }
     162             : 
     163             :     //-----------------------------------------------------------------------------
     164          10 :     Sequence< Type > OReferenceValueComponent::getSupportedBindingTypes()
     165             :     {
     166          10 :         ::std::list< Type > aTypes;
     167          10 :         aTypes.push_back( ::getCppuType( static_cast< sal_Bool* >( NULL ) ) );
     168             : 
     169          10 :         if ( !m_sReferenceValue.isEmpty() )
     170           0 :             aTypes.push_front( ::getCppuType( static_cast< OUString* >( NULL ) ) );
     171             :             // push_front, because this is the preferred type
     172             : 
     173          10 :         Sequence< Type > aTypesRet( aTypes.size() );
     174          10 :         ::std::copy( aTypes.begin(), aTypes.end(), aTypesRet.getArray() );
     175          10 :         return aTypesRet;
     176             :     }
     177             : 
     178             :     //-----------------------------------------------------------------------------
     179           5 :     Any OReferenceValueComponent::translateExternalValueToControlValue( const Any& _rExternalValue ) const
     180             :     {
     181           5 :         sal_Int16 nState = STATE_DONTKNOW;
     182             : 
     183           5 :         sal_Bool bExternalState = sal_False;
     184           5 :         OUString sExternalValue;
     185           5 :         if ( _rExternalValue >>= bExternalState )
     186             :         {
     187           1 :             nState = ::sal::static_int_cast< sal_Int16 >( bExternalState ? STATE_CHECK : STATE_NOCHECK );
     188             :         }
     189           4 :         else if ( _rExternalValue >>= sExternalValue )
     190             :         {
     191           4 :             if ( sExternalValue == m_sReferenceValue )
     192           0 :                 nState = STATE_CHECK;
     193             :             else
     194             :             {
     195           4 :                 if ( !m_bSupportSecondRefValue || ( sExternalValue == m_sNoCheckReferenceValue ) )
     196           0 :                     nState = STATE_NOCHECK;
     197             :                 else
     198           4 :                     nState = STATE_DONTKNOW;
     199             :             }
     200             :         }
     201           0 :         else if ( !_rExternalValue.hasValue() )
     202             :         {
     203           0 :             nState = STATE_DONTKNOW;
     204             :         }
     205             :         else
     206             :         {
     207             :             OSL_FAIL( "OReferenceValueComponent::translateExternalValueToControlValue: unexpected value type!" );
     208             :         }
     209             : 
     210           5 :         return makeAny( nState );
     211             :     }
     212             : 
     213             :     //-----------------------------------------------------------------------------
     214           0 :     Any OReferenceValueComponent::translateControlValueToExternalValue( ) const
     215             :     {
     216           0 :         Any aExternalValue;
     217             : 
     218             :         try
     219             :         {
     220           0 :             Any aControlValue( m_xAggregateSet->getPropertyValue( PROPERTY_STATE ) );
     221           0 :             sal_Int16 nControlValue = STATE_DONTKNOW;
     222           0 :             aControlValue >>= nControlValue;
     223             : 
     224           0 :             bool bBooleanExchange = getExternalValueType().getTypeClass() == TypeClass_BOOLEAN;
     225           0 :             bool bStringExchange = getExternalValueType().getTypeClass() == TypeClass_STRING;
     226             :             OSL_ENSURE( bBooleanExchange || bStringExchange,
     227             :                 "OReferenceValueComponent::translateControlValueToExternalValue: unexpected value exchange type!" );
     228             : 
     229           0 :             switch( nControlValue )
     230             :             {
     231             :             case STATE_CHECK:
     232           0 :                 if ( bBooleanExchange )
     233             :                 {
     234           0 :                     aExternalValue <<= (sal_Bool)sal_True;
     235             :                 }
     236           0 :                 else if ( bStringExchange )
     237             :                 {
     238           0 :                     aExternalValue <<= m_sReferenceValue;
     239             :                 }
     240           0 :                 break;
     241             : 
     242             :             case STATE_NOCHECK:
     243           0 :                 if ( bBooleanExchange )
     244             :                 {
     245           0 :                     aExternalValue <<= (sal_Bool)sal_False;
     246             :                 }
     247           0 :                 else if ( bStringExchange )
     248             :                 {
     249           0 :                     aExternalValue <<= (m_bSupportSecondRefValue ? m_sNoCheckReferenceValue : OUString());
     250             :                 }
     251           0 :                 break;
     252           0 :             }
     253             :         }
     254           0 :         catch( const Exception& )
     255             :         {
     256             :             OSL_FAIL( "OReferenceValueComponent::translateControlValueToExternalValue: caught an exception!" );
     257             :         }
     258             : 
     259           0 :         return aExternalValue;
     260             :     }
     261             : 
     262             :     //-----------------------------------------------------------------------------
     263          23 :     Any OReferenceValueComponent::translateControlValueToValidatableValue( ) const
     264             :     {
     265          23 :         if ( !m_xAggregateSet.is() )
     266           0 :             return Any();
     267             : 
     268          23 :         Any aControlValue( m_xAggregateSet->getPropertyValue( PROPERTY_STATE ) );
     269          23 :         sal_Int16 nControlValue = STATE_DONTKNOW;
     270          23 :         aControlValue >>= nControlValue;
     271             : 
     272          46 :         Any aValidatableValue;
     273          23 :         switch ( nControlValue )
     274             :         {
     275             :         case STATE_CHECK:
     276           4 :             aValidatableValue <<= (sal_Bool)sal_True;
     277           4 :             break;
     278             :         case STATE_NOCHECK:
     279           8 :             aValidatableValue <<= (sal_Bool)sal_False;
     280           8 :             break;
     281             :         }
     282          46 :         return aValidatableValue;
     283             :     }
     284             : 
     285             : //........................................................................
     286             : } // namespace frm
     287             : //........................................................................
     288             : 
     289             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10