LCOV - code coverage report
Current view: top level - forms/source/component - refvaluecomponent.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 117 0.0 %
Date: 2014-04-14 Functions: 0 14 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             : #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           0 :     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( TRISTATE_FALSE )
      43           0 :         ,m_bSupportSecondRefValue( _bSupportNoCheckRefValue )
      44             :     {
      45           0 :     }
      46             : 
      47             : 
      48           0 :     OReferenceValueComponent::OReferenceValueComponent( const OReferenceValueComponent* _pOriginal, const Reference< XComponentContext>& _rxFactory )
      49           0 :         :OBoundControlModel( _pOriginal, _rxFactory )
      50             :     {
      51           0 :         m_sReferenceValue           = _pOriginal->m_sReferenceValue;
      52           0 :         m_sNoCheckReferenceValue    = _pOriginal->m_sNoCheckReferenceValue;
      53           0 :         m_eDefaultChecked           = _pOriginal->m_eDefaultChecked;
      54           0 :         m_bSupportSecondRefValue    = _pOriginal->m_bSupportSecondRefValue;
      55             : 
      56           0 :         calculateExternalValueType();
      57           0 :     }
      58             : 
      59             : 
      60           0 :     OReferenceValueComponent::~OReferenceValueComponent()
      61             :     {
      62           0 :     }
      63             : 
      64             : 
      65           0 :     void OReferenceValueComponent::setReferenceValue( const OUString& _rRefValue )
      66             :     {
      67           0 :         m_sReferenceValue = _rRefValue;
      68           0 :         calculateExternalValueType();
      69           0 :     }
      70             : 
      71             : 
      72           0 :     void SAL_CALL OReferenceValueComponent::getFastPropertyValue( Any& _rValue, sal_Int32 _nHandle ) const
      73             :     {
      74           0 :         switch ( _nHandle )
      75             :         {
      76           0 :         case PROPERTY_ID_REFVALUE:          _rValue <<= m_sReferenceValue; break;
      77           0 :         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           0 :             _rValue <<= m_sNoCheckReferenceValue;
      82           0 :             break;
      83             : 
      84             :         default:
      85           0 :             OBoundControlModel::getFastPropertyValue( _rValue, _nHandle );
      86             :         }
      87           0 :     }
      88             : 
      89             : 
      90           0 :     void SAL_CALL OReferenceValueComponent::setFastPropertyValue_NoBroadcast( sal_Int32 _nHandle, const Any& _rValue ) throw (Exception, std::exception)
      91             :     {
      92           0 :         switch ( _nHandle )
      93             :         {
      94             :         case PROPERTY_ID_REFVALUE :
      95           0 :             OSL_VERIFY( _rValue >>= m_sReferenceValue );
      96           0 :             calculateExternalValueType();
      97           0 :             break;
      98             : 
      99             :         case PROPERTY_ID_UNCHECKED_REFVALUE:
     100             :             OSL_ENSURE( m_bSupportSecondRefValue, "OReferenceValueComponent::setFastPropertyValue_NoBroadcast: not supported!" );
     101           0 :             OSL_VERIFY( _rValue >>= m_sNoCheckReferenceValue );
     102           0 :             break;
     103             : 
     104             :         case PROPERTY_ID_DEFAULT_STATE:
     105             :         {
     106           0 :             sal_Int16 nDefaultChecked( (sal_Int16)TRISTATE_FALSE );
     107           0 :             OSL_VERIFY( _rValue >>= nDefaultChecked );
     108           0 :             m_eDefaultChecked = (ToggleState)nDefaultChecked;
     109           0 :             resetNoBroadcast();
     110             :         }
     111           0 :         break;
     112             : 
     113             :         default:
     114           0 :             OBoundControlModel::setFastPropertyValue_NoBroadcast( _nHandle, _rValue );
     115             :         }
     116           0 :     }
     117             : 
     118             : 
     119           0 :     sal_Bool SAL_CALL OReferenceValueComponent::convertFastPropertyValue( Any& _rConvertedValue, Any& _rOldValue, sal_Int32 _nHandle, const Any& _rValue ) throw (IllegalArgumentException)
     120             :     {
     121           0 :         sal_Bool bModified = sal_False;
     122           0 :         switch ( _nHandle )
     123             :         {
     124             :         case PROPERTY_ID_REFVALUE:
     125           0 :             bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, m_sReferenceValue );
     126           0 :             break;
     127             : 
     128             :         case PROPERTY_ID_UNCHECKED_REFVALUE:
     129             :             OSL_ENSURE( m_bSupportSecondRefValue, "OReferenceValueComponent::convertFastPropertyValue: not supported!" );
     130           0 :             bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, m_sNoCheckReferenceValue );
     131           0 :             break;
     132             : 
     133             :         case PROPERTY_ID_DEFAULT_STATE:
     134           0 :             bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, (sal_Int16)m_eDefaultChecked );
     135           0 :             break;
     136             : 
     137             :         default:
     138           0 :             bModified = OBoundControlModel::convertFastPropertyValue( _rConvertedValue, _rOldValue, _nHandle, _rValue );
     139           0 :             break;
     140             :         }
     141           0 :         return bModified;
     142             :     }
     143             : 
     144             : 
     145           0 :     Any OReferenceValueComponent::getDefaultForReset() const
     146             :     {
     147           0 :         return makeAny( (sal_Int16)m_eDefaultChecked );
     148             :     }
     149             : 
     150             : 
     151           0 :     void OReferenceValueComponent::describeFixedProperties( Sequence< Property >& _rProps ) const
     152             :     {
     153           0 :         BEGIN_DESCRIBE_PROPERTIES( m_bSupportSecondRefValue ? 3 : 2, OBoundControlModel )
     154           0 :             DECL_PROP1( REFVALUE,       OUString,    BOUND );
     155           0 :             DECL_PROP1( DEFAULT_STATE, sal_Int16,          BOUND );
     156           0 :             if ( m_bSupportSecondRefValue )
     157             :             {
     158           0 :                 DECL_PROP1( UNCHECKED_REFVALUE, OUString,    BOUND );
     159             :             }
     160             :         END_DESCRIBE_PROPERTIES();
     161           0 :     }
     162             : 
     163             : 
     164           0 :     Sequence< Type > OReferenceValueComponent::getSupportedBindingTypes()
     165             :     {
     166           0 :         ::std::list< Type > aTypes;
     167           0 :         aTypes.push_back( ::getCppuType( static_cast< sal_Bool* >( NULL ) ) );
     168             : 
     169           0 :         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           0 :         Sequence< Type > aTypesRet( aTypes.size() );
     174           0 :         ::std::copy( aTypes.begin(), aTypes.end(), aTypesRet.getArray() );
     175           0 :         return aTypesRet;
     176             :     }
     177             : 
     178             : 
     179           0 :     Any OReferenceValueComponent::translateExternalValueToControlValue( const Any& _rExternalValue ) const
     180             :     {
     181           0 :         sal_Int16 nState = TRISTATE_INDET;
     182             : 
     183           0 :         sal_Bool bExternalState = sal_False;
     184           0 :         OUString sExternalValue;
     185           0 :         if ( _rExternalValue >>= bExternalState )
     186             :         {
     187           0 :             nState = ::sal::static_int_cast< sal_Int16 >( bExternalState ? TRISTATE_TRUE : TRISTATE_FALSE );
     188             :         }
     189           0 :         else if ( _rExternalValue >>= sExternalValue )
     190             :         {
     191           0 :             if ( sExternalValue == m_sReferenceValue )
     192           0 :                 nState = TRISTATE_TRUE;
     193             :             else
     194             :             {
     195           0 :                 if ( !m_bSupportSecondRefValue || ( sExternalValue == m_sNoCheckReferenceValue ) )
     196           0 :                     nState = TRISTATE_FALSE;
     197             :                 else
     198           0 :                     nState = TRISTATE_INDET;
     199             :             }
     200             :         }
     201           0 :         else if ( !_rExternalValue.hasValue() )
     202             :         {
     203           0 :             nState = TRISTATE_INDET;
     204             :         }
     205             :         else
     206             :         {
     207             :             OSL_FAIL( "OReferenceValueComponent::translateExternalValueToControlValue: unexpected value type!" );
     208             :         }
     209             : 
     210           0 :         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 = TRISTATE_INDET;
     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 TRISTATE_TRUE:
     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 TRISTATE_FALSE:
     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           0 :     Any OReferenceValueComponent::translateControlValueToValidatableValue( ) const
     264             :     {
     265           0 :         if ( !m_xAggregateSet.is() )
     266           0 :             return Any();
     267             : 
     268           0 :         Any aControlValue( m_xAggregateSet->getPropertyValue( PROPERTY_STATE ) );
     269           0 :         sal_Int16 nControlValue = TRISTATE_INDET;
     270           0 :         aControlValue >>= nControlValue;
     271             : 
     272           0 :         Any aValidatableValue;
     273           0 :         switch ( nControlValue )
     274             :         {
     275             :         case TRISTATE_TRUE:
     276           0 :             aValidatableValue <<= (sal_Bool)sal_True;
     277           0 :             break;
     278             :         case TRISTATE_FALSE:
     279           0 :             aValidatableValue <<= (sal_Bool)sal_False;
     280           0 :             break;
     281             :         }
     282           0 :         return aValidatableValue;
     283             :     }
     284             : 
     285             : 
     286             : } // namespace frm
     287             : 
     288             : 
     289             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10