LCOV - code coverage report
Current view: top level - forms/source/component - spinbutton.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 68 87 78.2 %
Date: 2014-04-11 Functions: 20 26 76.9 %
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 "spinbutton.hxx"
      21             : #include <comphelper/streamsection.hxx>
      22             : #include <comphelper/basicio.hxx>
      23             : 
      24             : 
      25          17 : extern "C" void SAL_CALL createRegistryInfo_OSpinButtonModel()
      26             : {
      27          17 :     static ::frm::OMultiInstanceAutoRegistration< ::frm::OSpinButtonModel >   aRegisterModel;
      28          17 : }
      29             : 
      30             : 
      31             : namespace frm
      32             : {
      33             : 
      34             : 
      35             :     using namespace ::com::sun::star::uno;
      36             :     using namespace ::com::sun::star::beans;
      37             :     using namespace ::com::sun::star::form;
      38             :     using namespace ::com::sun::star::awt;
      39             :     using namespace ::com::sun::star::lang;
      40             :     using namespace ::com::sun::star::util;
      41             :     using namespace ::com::sun::star::io;
      42             :     using namespace ::com::sun::star::form::binding;
      43             : 
      44             : 
      45             :     //= OSpinButtonModel
      46             : 
      47             :     // implemented elsewhere
      48             :     Any translateExternalDoubleToControlIntValue(
      49             :         const Any& _rExternalValue, const Reference< XPropertySet >& _rxProperties,
      50             :         const OUString& _rMinValueName, const OUString& _rMaxValueName );
      51             :     Any translateControlIntToExternalDoubleValue( const Any& _rControlIntValue );
      52             : 
      53             : 
      54             :     //= OSpinButtonModel
      55             : 
      56             : 
      57             : 
      58           6 :     OSpinButtonModel::OSpinButtonModel( const Reference<XComponentContext>& _rxFactory )
      59             :         :OBoundControlModel( _rxFactory, VCL_CONTROLMODEL_SPINBUTTON, VCL_CONTROL_SPINBUTTON, sal_True, sal_True, sal_False )
      60           6 :         ,m_nDefaultSpinValue( 0 )
      61             :     {
      62             : 
      63           6 :         m_nClassId = FormComponentType::SPINBUTTON;
      64           6 :         initValueProperty( PROPERTY_SPIN_VALUE, PROPERTY_ID_SPIN_VALUE );
      65           6 :     }
      66             : 
      67             : 
      68           1 :     OSpinButtonModel::OSpinButtonModel( const OSpinButtonModel* _pOriginal, const Reference< XComponentContext >& _rxFactory )
      69           1 :         :OBoundControlModel( _pOriginal, _rxFactory )
      70             :     {
      71           1 :         m_nDefaultSpinValue = _pOriginal->m_nDefaultSpinValue;
      72           1 :     }
      73             : 
      74             : 
      75          14 :     OSpinButtonModel::~OSpinButtonModel( )
      76             :     {
      77          14 :     }
      78             : 
      79             : 
      80          81 :     IMPLEMENT_SERVICE_REGISTRATION_2( OSpinButtonModel, OControlModel, FRM_SUN_COMPONENT_SPINBUTTON, BINDABLE_INTEGER_VALUE_RANGE )
      81             :         // note that we're passing OControlModel as "base class". This is because
      82             :         // OBoundControlModel, our real base class, claims to support the DataAwareControlModel
      83             :         // service, which isn't really true for us. We only derive from this class
      84             :         // to benefit from the functionality for binding to spreadsheet cells
      85             : 
      86             : 
      87           1 :     IMPLEMENT_DEFAULT_CLONING( OSpinButtonModel )
      88             : 
      89             : 
      90           7 :     void SAL_CALL OSpinButtonModel::disposing()
      91             :     {
      92           7 :         OBoundControlModel::disposing();
      93           7 :     }
      94             : 
      95             : 
      96           8 :     void OSpinButtonModel::describeFixedProperties( Sequence< Property >& _rProps ) const
      97             :     {
      98           8 :         BEGIN_DESCRIBE_PROPERTIES( 3, OControlModel )
      99           8 :             DECL_PROP1( DEFAULT_SPIN_VALUE,   sal_Int32,       BOUND );
     100           8 :             DECL_PROP1( TABINDEX,             sal_Int16,       BOUND );
     101           8 :             DECL_PROP2( CONTROLSOURCEPROPERTY,OUString, READONLY, TRANSIENT );
     102             :         END_DESCRIBE_PROPERTIES();
     103           8 :     }
     104             : 
     105             : 
     106        1063 :     void OSpinButtonModel::getFastPropertyValue( Any& _rValue, sal_Int32 _nHandle ) const
     107             :     {
     108        1063 :         switch ( _nHandle )
     109             :         {
     110             :             case PROPERTY_ID_DEFAULT_SPIN_VALUE:
     111          44 :                 _rValue <<= m_nDefaultSpinValue;
     112          44 :                 break;
     113             : 
     114             :             default:
     115        1019 :                 OBoundControlModel::getFastPropertyValue( _rValue, _nHandle );
     116             :         }
     117        1063 :     }
     118             : 
     119             : 
     120          72 :     void OSpinButtonModel::setFastPropertyValue_NoBroadcast( sal_Int32 _nHandle, const Any& _rValue ) throw ( Exception, std::exception )
     121             :     {
     122          72 :         switch ( _nHandle )
     123             :         {
     124             :             case PROPERTY_ID_DEFAULT_SPIN_VALUE:
     125           9 :                 OSL_VERIFY( _rValue >>= m_nDefaultSpinValue );
     126           9 :                 resetNoBroadcast();
     127           9 :                 break;
     128             : 
     129             :             default:
     130          63 :                 OBoundControlModel::setFastPropertyValue_NoBroadcast( _nHandle, _rValue );
     131             :         }
     132          72 :     }
     133             : 
     134             : 
     135         220 :     sal_Bool OSpinButtonModel::convertFastPropertyValue(
     136             :                 Any& _rConvertedValue, Any& _rOldValue, sal_Int32 _nHandle, const Any& _rValue )
     137             :                 throw ( IllegalArgumentException )
     138             :     {
     139         220 :         sal_Bool bModified( sal_False );
     140         220 :         switch ( _nHandle )
     141             :         {
     142             :             case PROPERTY_ID_DEFAULT_SPIN_VALUE:
     143          30 :                 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, m_nDefaultSpinValue );
     144          30 :                 break;
     145             : 
     146             :             default:
     147         190 :                 bModified = OBoundControlModel::convertFastPropertyValue( _rConvertedValue, _rOldValue, _nHandle, _rValue );
     148         190 :                 break;
     149             :         }
     150         220 :         return bModified;
     151             :     }
     152             : 
     153             : 
     154           0 :     Any OSpinButtonModel::getPropertyDefaultByHandle( sal_Int32 _nHandle ) const
     155             :     {
     156           0 :         Any aReturn;
     157             : 
     158           0 :         switch ( _nHandle )
     159             :         {
     160             :         case PROPERTY_ID_DEFAULT_SPIN_VALUE:
     161           0 :             aReturn <<= (sal_Int32)0;
     162           0 :             break;
     163             : 
     164             :         default:
     165           0 :             aReturn = OBoundControlModel::getPropertyDefaultByHandle( _nHandle );
     166           0 :             break;
     167             :         }
     168             : 
     169           0 :         return aReturn;
     170             :     }
     171             : 
     172             : 
     173           0 :     Any OSpinButtonModel::translateDbColumnToControlValue( )
     174             :     {
     175             :         OSL_FAIL( "OSpinButtonModel::commitControlValueToDbColumn: never to be called (we're not bound)!" );
     176           0 :         return Any();
     177             :     }
     178             : 
     179             : 
     180           0 :     sal_Bool OSpinButtonModel::commitControlValueToDbColumn( bool /*_bPostReset*/ )
     181             :     {
     182             :         OSL_FAIL( "OSpinButtonModel::commitControlValueToDbColumn: never to be called (we're not bound)!" );
     183           0 :         return sal_True;
     184             :     }
     185             : 
     186             : 
     187          11 :     Any OSpinButtonModel::getDefaultForReset() const
     188             :     {
     189          11 :         return makeAny( (sal_Int32)m_nDefaultSpinValue );
     190             :     }
     191             : 
     192             : 
     193           1 :     OUString SAL_CALL OSpinButtonModel::getServiceName() throw( RuntimeException, std::exception )
     194             :     {
     195           1 :         return OUString(FRM_SUN_COMPONENT_SPINBUTTON);
     196             :     }
     197             : 
     198             : 
     199           1 :     void SAL_CALL OSpinButtonModel::write( const Reference< XObjectOutputStream >& _rxOutStream )
     200             :         throw( IOException, RuntimeException, std::exception )
     201             :     {
     202           1 :         OBoundControlModel::write( _rxOutStream );
     203           1 :         ::osl::MutexGuard aGuard( m_aMutex );
     204             : 
     205           2 :         OStreamSection aSection( _rxOutStream );
     206             : 
     207             :         // version
     208           1 :         _rxOutStream->writeShort( 0x0001 );
     209             : 
     210             :         // properties
     211           1 :         _rxOutStream << m_nDefaultSpinValue;
     212           2 :         writeHelpTextCompatibly( _rxOutStream );
     213           1 :     }
     214             : 
     215             : 
     216           1 :     void SAL_CALL OSpinButtonModel::read( const Reference< XObjectInputStream>& _rxInStream ) throw( IOException, RuntimeException, std::exception )
     217             :     {
     218           1 :         OBoundControlModel::read( _rxInStream );
     219           1 :         ::osl::MutexGuard aGuard( m_aMutex );
     220             : 
     221             :         // version
     222             :         {
     223           1 :             OStreamSection aSection( _rxInStream );
     224             : 
     225           1 :             sal_uInt16 nVersion = _rxInStream->readShort();
     226           1 :             if ( nVersion == 0x0001 )
     227             :             {
     228           1 :                 _rxInStream >> m_nDefaultSpinValue;
     229           1 :                 readHelpTextCompatibly( _rxInStream );
     230             :             }
     231             :             else
     232           0 :                 defaultCommonProperties();
     233             : 
     234             :             // here, everything in the stream section which is left will be skipped
     235           1 :         }
     236           1 :     }
     237             : 
     238             : 
     239           0 :     Any OSpinButtonModel::translateExternalValueToControlValue( const Any& _rExternalValue ) const
     240             :     {
     241             :         return translateExternalDoubleToControlIntValue( _rExternalValue, m_xAggregateSet,
     242             :             OUString( "SpinValueMin" ),
     243           0 :             OUString( "SpinValueMax" ) );
     244             :     }
     245             : 
     246             : 
     247           0 :     Any OSpinButtonModel::translateControlValueToExternalValue( ) const
     248             :     {
     249             :         // by definition, the base class simply obtains the property value
     250           0 :         return translateControlIntToExternalDoubleValue( OBoundControlModel::translateControlValueToExternalValue() );
     251             :     }
     252             : 
     253             : 
     254           0 :     Sequence< Type > OSpinButtonModel::getSupportedBindingTypes()
     255             :     {
     256           0 :         return Sequence< Type >( &::getCppuType( static_cast< double* >( NULL ) ), 1 );
     257             :     }
     258             : 
     259             : 
     260             : }   // namespace frm
     261             : 
     262             : 
     263             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10