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

Generated by: LCOV version 1.10