LCOV - code coverage report
Current view: top level - forms/source/component - spinbutton.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 69 87 79.3 %
Date: 2012-08-25 Functions: 20 26 76.9 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 56 122 45.9 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include "spinbutton.hxx"
      30                 :            : #include <comphelper/streamsection.hxx>
      31                 :            : #include <comphelper/basicio.hxx>
      32                 :            : 
      33                 :            : //--------------------------------------------------------------------------
      34                 :         30 : extern "C" void SAL_CALL createRegistryInfo_OSpinButtonModel()
      35                 :            : {
      36 [ +  - ][ +  - ]:         30 :     static ::frm::OMultiInstanceAutoRegistration< ::frm::OSpinButtonModel >   aRegisterModel;
         [ +  - ][ #  # ]
      37                 :         30 : }
      38                 :            : 
      39                 :            : //........................................................................
      40                 :            : namespace frm
      41                 :            : {
      42                 :            : //........................................................................
      43                 :            : 
      44                 :            :     using namespace ::com::sun::star::uno;
      45                 :            :     using namespace ::com::sun::star::beans;
      46                 :            :     using namespace ::com::sun::star::form;
      47                 :            :     using namespace ::com::sun::star::awt;
      48                 :            :     using namespace ::com::sun::star::lang;
      49                 :            :     using namespace ::com::sun::star::util;
      50                 :            :     using namespace ::com::sun::star::io;
      51                 :            :     using namespace ::com::sun::star::form::binding;
      52                 :            : 
      53                 :            :     //====================================================================
      54                 :            :     //= OSpinButtonModel
      55                 :            :     //====================================================================
      56                 :            :     // implemented elsewhere
      57                 :            :     Any translateExternalDoubleToControlIntValue(
      58                 :            :         const Any& _rExternalValue, const Reference< XPropertySet >& _rxProperties,
      59                 :            :         const ::rtl::OUString& _rMinValueName, const ::rtl::OUString& _rMaxValueName );
      60                 :            :     Any translateControlIntToExternalDoubleValue( const Any& _rControlIntValue );
      61                 :            : 
      62                 :            :     //====================================================================
      63                 :            :     //= OSpinButtonModel
      64                 :            :     //====================================================================
      65                 :            :     //--------------------------------------------------------------------
      66                 :            :     DBG_NAME( OSpinButtonModel )
      67                 :            :     //--------------------------------------------------------------------
      68                 :         12 :     OSpinButtonModel::OSpinButtonModel( const Reference<XMultiServiceFactory>& _rxFactory )
      69                 :            :         :OBoundControlModel( _rxFactory, VCL_CONTROLMODEL_SPINBUTTON, VCL_CONTROL_SPINBUTTON, sal_True, sal_True, sal_False )
      70 [ +  - ][ +  - ]:         12 :         ,m_nDefaultSpinValue( 0 )
      71                 :            :     {
      72                 :            :         DBG_CTOR( OSpinButtonModel, NULL );
      73                 :            : 
      74                 :         12 :         m_nClassId = FormComponentType::SPINBUTTON;
      75 [ +  - ][ +  - ]:         12 :         initValueProperty( PROPERTY_SPIN_VALUE, PROPERTY_ID_SPIN_VALUE );
      76                 :         12 :     }
      77                 :            : 
      78                 :            :     //--------------------------------------------------------------------
      79                 :          2 :     OSpinButtonModel::OSpinButtonModel( const OSpinButtonModel* _pOriginal, const Reference< XMultiServiceFactory >& _rxFactory )
      80                 :          2 :         :OBoundControlModel( _pOriginal, _rxFactory )
      81                 :            :     {
      82                 :            :         DBG_CTOR( OSpinButtonModel, NULL );
      83                 :          2 :         m_nDefaultSpinValue = _pOriginal->m_nDefaultSpinValue;
      84                 :          2 :     }
      85                 :            : 
      86                 :            :     //--------------------------------------------------------------------
      87                 :         14 :     OSpinButtonModel::~OSpinButtonModel( )
      88                 :            :     {
      89                 :            :         DBG_DTOR( OSpinButtonModel, NULL );
      90         [ -  + ]:         28 :     }
      91                 :            : 
      92                 :            :     //--------------------------------------------------------------------
      93 [ +  - ][ +  - ]:        150 :     IMPLEMENT_SERVICE_REGISTRATION_2( OSpinButtonModel, OControlModel, FRM_SUN_COMPONENT_SPINBUTTON, BINDABLE_INTEGER_VALUE_RANGE )
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
      94                 :            :         // note that we're passing OControlModel as "base class". This is because
      95                 :            :         // OBoundControlModel, our real base class, claims to support the DataAwareControlModel
      96                 :            :         // service, which isn't really true for us. We only derive from this class
      97                 :            :         // to benefit from the functionality for binding to spreadsheet cells
      98                 :            : 
      99                 :            :     //------------------------------------------------------------------------------
     100 [ +  - ][ +  - ]:          2 :     IMPLEMENT_DEFAULT_CLONING( OSpinButtonModel )
     101                 :            : 
     102                 :            :     //------------------------------------------------------------------------------
     103                 :         14 :     void SAL_CALL OSpinButtonModel::disposing()
     104                 :            :     {
     105                 :         14 :         OBoundControlModel::disposing();
     106                 :         14 :     }
     107                 :            : 
     108                 :            :     //--------------------------------------------------------------------
     109                 :         16 :     void OSpinButtonModel::describeFixedProperties( Sequence< Property >& _rProps ) const
     110                 :            :     {
     111                 :         16 :         BEGIN_DESCRIBE_PROPERTIES( 3, OControlModel )
     112         [ +  - ]:         16 :             DECL_PROP1( DEFAULT_SPIN_VALUE,   sal_Int32,       BOUND );
     113         [ +  - ]:         16 :             DECL_PROP1( TABINDEX,             sal_Int16,       BOUND );
     114 [ +  - ][ +  - ]:         16 :             DECL_PROP2( CONTROLSOURCEPROPERTY,::rtl::OUString, READONLY, TRANSIENT );
     115                 :            :         END_DESCRIBE_PROPERTIES();
     116                 :         16 :     }
     117                 :            : 
     118                 :            :     //------------------------------------------------------------------------------
     119                 :       1874 :     void OSpinButtonModel::getFastPropertyValue( Any& _rValue, sal_Int32 _nHandle ) const
     120                 :            :     {
     121         [ +  + ]:       1874 :         switch ( _nHandle )
     122                 :            :         {
     123                 :            :             case PROPERTY_ID_DEFAULT_SPIN_VALUE:
     124                 :         84 :                 _rValue <<= m_nDefaultSpinValue;
     125                 :         84 :                 break;
     126                 :            : 
     127                 :            :             default:
     128                 :       1790 :                 OBoundControlModel::getFastPropertyValue( _rValue, _nHandle );
     129                 :            :         }
     130                 :       1874 :     }
     131                 :            : 
     132                 :            :     //------------------------------------------------------------------------------
     133                 :        117 :     void OSpinButtonModel::setFastPropertyValue_NoBroadcast( sal_Int32 _nHandle, const Any& _rValue ) throw ( Exception )
     134                 :            :     {
     135         [ +  + ]:        117 :         switch ( _nHandle )
     136                 :            :         {
     137                 :            :             case PROPERTY_ID_DEFAULT_SPIN_VALUE:
     138                 :         18 :                 OSL_VERIFY( _rValue >>= m_nDefaultSpinValue );
     139                 :         18 :                 resetNoBroadcast();
     140                 :         18 :                 break;
     141                 :            : 
     142                 :            :             default:
     143                 :         99 :                 OBoundControlModel::setFastPropertyValue_NoBroadcast( _nHandle, _rValue );
     144                 :            :         }
     145                 :        117 :     }
     146                 :            : 
     147                 :            :     //------------------------------------------------------------------------------
     148                 :        307 :     sal_Bool OSpinButtonModel::convertFastPropertyValue(
     149                 :            :                 Any& _rConvertedValue, Any& _rOldValue, sal_Int32 _nHandle, const Any& _rValue )
     150                 :            :                 throw ( IllegalArgumentException )
     151                 :            :     {
     152                 :        307 :         sal_Bool bModified( sal_False );
     153         [ +  + ]:        307 :         switch ( _nHandle )
     154                 :            :         {
     155                 :            :             case PROPERTY_ID_DEFAULT_SPIN_VALUE:
     156                 :         56 :                 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, m_nDefaultSpinValue );
     157                 :         56 :                 break;
     158                 :            : 
     159                 :            :             default:
     160                 :        251 :                 bModified = OBoundControlModel::convertFastPropertyValue( _rConvertedValue, _rOldValue, _nHandle, _rValue );
     161                 :        251 :                 break;
     162                 :            :         }
     163                 :        307 :         return bModified;
     164                 :            :     }
     165                 :            : 
     166                 :            :     //--------------------------------------------------------------------
     167                 :          0 :     Any OSpinButtonModel::getPropertyDefaultByHandle( sal_Int32 _nHandle ) const
     168                 :            :     {
     169                 :          0 :         Any aReturn;
     170                 :            : 
     171         [ #  # ]:          0 :         switch ( _nHandle )
     172                 :            :         {
     173                 :            :         case PROPERTY_ID_DEFAULT_SPIN_VALUE:
     174         [ #  # ]:          0 :             aReturn <<= (sal_Int32)0;
     175                 :          0 :             break;
     176                 :            : 
     177                 :            :         default:
     178         [ #  # ]:          0 :             aReturn = OBoundControlModel::getPropertyDefaultByHandle( _nHandle );
     179                 :          0 :             break;
     180                 :            :         }
     181                 :            : 
     182                 :          0 :         return aReturn;
     183                 :            :     }
     184                 :            : 
     185                 :            :     //------------------------------------------------------------------------------
     186                 :          0 :     Any OSpinButtonModel::translateDbColumnToControlValue( )
     187                 :            :     {
     188                 :            :         OSL_FAIL( "OSpinButtonModel::commitControlValueToDbColumn: never to be called (we're not bound)!" );
     189                 :          0 :         return Any();
     190                 :            :     }
     191                 :            : 
     192                 :            :     //------------------------------------------------------------------------------
     193                 :          0 :     sal_Bool OSpinButtonModel::commitControlValueToDbColumn( bool /*_bPostReset*/ )
     194                 :            :     {
     195                 :            :         OSL_FAIL( "OSpinButtonModel::commitControlValueToDbColumn: never to be called (we're not bound)!" );
     196                 :          0 :         return sal_True;
     197                 :            :     }
     198                 :            : 
     199                 :            :     //------------------------------------------------------------------------------
     200                 :         22 :     Any OSpinButtonModel::getDefaultForReset() const
     201                 :            :     {
     202         [ +  - ]:         22 :         return makeAny( (sal_Int32)m_nDefaultSpinValue );
     203                 :            :     }
     204                 :            : 
     205                 :            :     //--------------------------------------------------------------------
     206                 :          2 :     ::rtl::OUString SAL_CALL OSpinButtonModel::getServiceName() throw( RuntimeException )
     207                 :            :     {
     208                 :          2 :         return FRM_SUN_COMPONENT_SPINBUTTON;
     209                 :            :     }
     210                 :            : 
     211                 :            :     //--------------------------------------------------------------------
     212                 :          2 :     void SAL_CALL OSpinButtonModel::write( const Reference< XObjectOutputStream >& _rxOutStream )
     213                 :            :         throw( IOException, RuntimeException )
     214                 :            :     {
     215         [ +  - ]:          2 :         OBoundControlModel::write( _rxOutStream );
     216         [ +  - ]:          2 :         ::osl::MutexGuard aGuard( m_aMutex );
     217                 :            : 
     218 [ +  - ][ +  - ]:          2 :         OStreamSection aSection( Reference< XDataOutputStream >( _rxOutStream, UNO_QUERY ) );
     219                 :            : 
     220                 :            :         // version
     221 [ +  - ][ +  - ]:          2 :         _rxOutStream->writeShort( 0x0001 );
     222                 :            : 
     223                 :            :         // properties
     224         [ +  - ]:          2 :         _rxOutStream << m_nDefaultSpinValue;
     225 [ +  - ][ +  - ]:          2 :         writeHelpTextCompatibly( _rxOutStream );
                 [ +  - ]
     226                 :          2 :     }
     227                 :            : 
     228                 :            :     //--------------------------------------------------------------------
     229                 :          2 :     void SAL_CALL OSpinButtonModel::read( const Reference< XObjectInputStream>& _rxInStream ) throw( IOException, RuntimeException )
     230                 :            :     {
     231         [ +  - ]:          2 :         OBoundControlModel::read( _rxInStream );
     232         [ +  - ]:          2 :         ::osl::MutexGuard aGuard( m_aMutex );
     233                 :            : 
     234                 :            :         // version
     235                 :            :         {
     236 [ +  - ][ +  - ]:          2 :             OStreamSection aSection( Reference< XDataInputStream >( _rxInStream, UNO_QUERY ) );
     237                 :            : 
     238 [ +  - ][ +  - ]:          2 :             sal_uInt16 nVersion = _rxInStream->readShort();
     239         [ +  - ]:          2 :             if ( nVersion == 0x0001 )
     240                 :            :             {
     241         [ +  - ]:          2 :                 _rxInStream >> m_nDefaultSpinValue;
     242         [ +  - ]:          2 :                 readHelpTextCompatibly( _rxInStream );
     243                 :            :             }
     244                 :            :             else
     245 [ #  # ][ +  - ]:          2 :                 defaultCommonProperties();
     246                 :            : 
     247                 :            :             // here, everything in the stream section which is left will be skipped
     248         [ +  - ]:          2 :         }
     249                 :          2 :     }
     250                 :            : 
     251                 :            :     //--------------------------------------------------------------------
     252                 :          0 :     Any OSpinButtonModel::translateExternalValueToControlValue( const Any& _rExternalValue ) const
     253                 :            :     {
     254                 :            :         return translateExternalDoubleToControlIntValue( _rExternalValue, m_xAggregateSet,
     255                 :            :             ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SpinValueMin" ) ),
     256 [ #  # ][ #  # ]:          0 :             ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SpinValueMax" ) ) );
     257                 :            :     }
     258                 :            : 
     259                 :            :     //--------------------------------------------------------------------
     260                 :          0 :     Any OSpinButtonModel::translateControlValueToExternalValue( ) const
     261                 :            :     {
     262                 :            :         // by definition, the base class simply obtains the property value
     263         [ #  # ]:          0 :         return translateControlIntToExternalDoubleValue( OBoundControlModel::translateControlValueToExternalValue() );
     264                 :            :     }
     265                 :            : 
     266                 :            :     //--------------------------------------------------------------------
     267                 :          0 :     Sequence< Type > OSpinButtonModel::getSupportedBindingTypes()
     268                 :            :     {
     269                 :          0 :         return Sequence< Type >( &::getCppuType( static_cast< double* >( NULL ) ), 1 );
     270                 :            :     }
     271                 :            : 
     272                 :            : //........................................................................
     273                 :            : }   // namespace frm
     274                 :            : //........................................................................
     275                 :            : 
     276                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10