LCOV - code coverage report
Current view: top level - forms/source/component - scrollbar.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 69 106 65.1 %
Date: 2012-08-25 Functions: 20 28 71.4 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 56 146 38.4 %

           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 "scrollbar.hxx"
      30                 :            : #include <comphelper/streamsection.hxx>
      31                 :            : #include <comphelper/basicio.hxx>
      32                 :            : #include <rtl/math.hxx>
      33                 :            : 
      34                 :            : //--------------------------------------------------------------------------
      35                 :         30 : extern "C" void SAL_CALL createRegistryInfo_OScrollBarModel()
      36                 :            : {
      37 [ +  - ][ +  - ]:         30 :     static ::frm::OMultiInstanceAutoRegistration< ::frm::OScrollBarModel >   aRegisterModel;
         [ +  - ][ #  # ]
      38                 :         30 : }
      39                 :            : 
      40                 :            : //........................................................................
      41                 :            : namespace frm
      42                 :            : {
      43                 :            : //........................................................................
      44                 :            : 
      45                 :            :     using namespace ::com::sun::star::uno;
      46                 :            :     using namespace ::com::sun::star::beans;
      47                 :            :     using namespace ::com::sun::star::form;
      48                 :            :     using namespace ::com::sun::star::awt;
      49                 :            :     using namespace ::com::sun::star::lang;
      50                 :            :     using namespace ::com::sun::star::util;
      51                 :            :     using namespace ::com::sun::star::io;
      52                 :            :     using namespace ::com::sun::star::form::binding;
      53                 :            : 
      54                 :            :     //====================================================================
      55                 :            :     //= helper
      56                 :            :     //====================================================================
      57                 :            :     //--------------------------------------------------------------------
      58                 :          0 :     Any translateExternalDoubleToControlIntValue(
      59                 :            :         const Any& _rExternalValue, const Reference< XPropertySet >& _rxProperties,
      60                 :            :         const ::rtl::OUString& _rMinValueName, const ::rtl::OUString& _rMaxValueName )
      61                 :            :     {
      62                 :            :         OSL_ENSURE( _rxProperties.is(), "translateExternalDoubleToControlIntValue: no aggregate!?" );
      63                 :            : 
      64                 :          0 :         sal_Int32 nControlValue( 0 );
      65                 :          0 :         double nExternalValue = 0;
      66         [ #  # ]:          0 :         if ( _rExternalValue >>= nExternalValue )
      67                 :            :         {
      68         [ #  # ]:          0 :             if ( ::rtl::math::isInf( nExternalValue ) )
      69                 :            :             {
      70                 :            :                 // set the minimum or maximum of the scroll values
      71                 :          0 :                 ::rtl::OUString sLimitPropertyName = ::rtl::math::isSignBitSet( nExternalValue )
      72         [ #  # ]:          0 :                     ? _rMinValueName : _rMaxValueName;
      73         [ #  # ]:          0 :                 if ( _rxProperties.is() )
      74 [ #  # ][ #  # ]:          0 :                     _rxProperties->getPropertyValue( sLimitPropertyName ) >>= nControlValue;
      75                 :            :             }
      76                 :            :             else
      77                 :            :             {
      78                 :          0 :                 nControlValue = (sal_Int32)::rtl::math::round( nExternalValue );
      79                 :            :             }
      80                 :            :         }
      81                 :            :         else
      82                 :            :         {
      83         [ #  # ]:          0 :             if ( _rxProperties.is() )
      84 [ #  # ][ #  # ]:          0 :                 _rxProperties->getPropertyValue( _rMinValueName ) >>= nControlValue;
      85                 :            :         }
      86                 :            : 
      87         [ #  # ]:          0 :         return makeAny( nControlValue );
      88                 :            :     }
      89                 :            : 
      90                 :            :     //--------------------------------------------------------------------
      91                 :          0 :     Any translateControlIntToExternalDoubleValue( const Any& _rControlIntValue )
      92                 :            :     {
      93                 :          0 :         Any aExternalDoubleValue;
      94                 :          0 :         sal_Int32 nScrollValue = 0;
      95         [ #  # ]:          0 :         if ( _rControlIntValue >>= nScrollValue )
      96         [ #  # ]:          0 :             aExternalDoubleValue <<= (double)nScrollValue;
      97                 :            :         else
      98                 :            :         {
      99                 :            :             OSL_FAIL( "translateControlIntToExternalDoubleValue: no integer scroll value!" );
     100                 :            :             // aExternalDoubleValue is void here, which is okay for this purpose ...
     101                 :            :         }
     102                 :            : 
     103                 :          0 :         return aExternalDoubleValue;
     104                 :            :     }
     105                 :            : 
     106                 :            :     //====================================================================
     107                 :            :     //= OScrollBarModel
     108                 :            :     //====================================================================
     109                 :            :     //--------------------------------------------------------------------
     110                 :            :     DBG_NAME( OScrollBarModel )
     111                 :            :     //--------------------------------------------------------------------
     112                 :         12 :     OScrollBarModel::OScrollBarModel( const Reference<XMultiServiceFactory>& _rxFactory )
     113                 :            :         :OBoundControlModel( _rxFactory, VCL_CONTROLMODEL_SCROLLBAR, VCL_CONTROL_SCROLLBAR, sal_True, sal_True, sal_False )
     114 [ +  - ][ +  - ]:         12 :         ,m_nDefaultScrollValue( 0 )
     115                 :            :     {
     116                 :            :         DBG_CTOR( OScrollBarModel, NULL );
     117                 :            : 
     118                 :         12 :         m_nClassId = FormComponentType::SCROLLBAR;
     119 [ +  - ][ +  - ]:         12 :         initValueProperty( PROPERTY_SCROLL_VALUE, PROPERTY_ID_SCROLL_VALUE );
     120                 :         12 :     }
     121                 :            : 
     122                 :            :     //--------------------------------------------------------------------
     123                 :          2 :     OScrollBarModel::OScrollBarModel( const OScrollBarModel* _pOriginal, const Reference< XMultiServiceFactory >& _rxFactory )
     124                 :          2 :         :OBoundControlModel( _pOriginal, _rxFactory )
     125                 :            :     {
     126                 :            :         DBG_CTOR( OScrollBarModel, NULL );
     127                 :          2 :         m_nDefaultScrollValue = _pOriginal->m_nDefaultScrollValue;
     128                 :          2 :     }
     129                 :            : 
     130                 :            :     //--------------------------------------------------------------------
     131                 :         14 :     OScrollBarModel::~OScrollBarModel( )
     132                 :            :     {
     133                 :            :         DBG_DTOR( OScrollBarModel, NULL );
     134         [ -  + ]:         28 :     }
     135                 :            : 
     136                 :            :     //--------------------------------------------------------------------
     137 [ +  - ][ +  - ]:        146 :     IMPLEMENT_SERVICE_REGISTRATION_2( OScrollBarModel, OControlModel, FRM_SUN_COMPONENT_SCROLLBAR, BINDABLE_INTEGER_VALUE_RANGE )
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     138                 :            :         // note that we're passing OControlModel as "base class". This is because
     139                 :            :         // OBoundControlModel, our real base class, claims to support the DataAwareControlModel
     140                 :            :         // service, which isn't really true for us. We only derive from this class
     141                 :            :         // to benefit from the functionality for binding to spreadsheet cells
     142                 :            : 
     143                 :            :     //------------------------------------------------------------------------------
     144 [ +  - ][ +  - ]:          2 :     IMPLEMENT_DEFAULT_CLONING( OScrollBarModel )
     145                 :            : 
     146                 :            :     //------------------------------------------------------------------------------
     147                 :         14 :     void SAL_CALL OScrollBarModel::disposing()
     148                 :            :     {
     149                 :         14 :         OBoundControlModel::disposing();
     150                 :         14 :     }
     151                 :            : 
     152                 :            :     //--------------------------------------------------------------------
     153                 :         16 :     void OScrollBarModel::describeFixedProperties( Sequence< Property >& _rProps ) const
     154                 :            :     {
     155                 :         16 :         BEGIN_DESCRIBE_PROPERTIES( 3, OControlModel )
     156         [ +  - ]:         16 :             DECL_PROP1( DEFAULT_SCROLL_VALUE, sal_Int32,       BOUND );
     157         [ +  - ]:         16 :             DECL_PROP1( TABINDEX,             sal_Int16,       BOUND );
     158 [ +  - ][ +  - ]:         16 :             DECL_PROP2( CONTROLSOURCEPROPERTY,::rtl::OUString, READONLY, TRANSIENT );
     159                 :            :         END_DESCRIBE_PROPERTIES();
     160                 :         16 :     }
     161                 :            : 
     162                 :            :     //------------------------------------------------------------------------------
     163                 :       1891 :     void OScrollBarModel::getFastPropertyValue( Any& _rValue, sal_Int32 _nHandle ) const
     164                 :            :     {
     165         [ +  + ]:       1891 :         switch ( _nHandle )
     166                 :            :         {
     167                 :            :             case PROPERTY_ID_DEFAULT_SCROLL_VALUE:
     168                 :         84 :                 _rValue <<= m_nDefaultScrollValue;
     169                 :         84 :                 break;
     170                 :            : 
     171                 :            :             default:
     172                 :       1807 :                 OBoundControlModel::getFastPropertyValue( _rValue, _nHandle );
     173                 :            :         }
     174                 :       1891 :     }
     175                 :            : 
     176                 :            :     //------------------------------------------------------------------------------
     177                 :        116 :     void OScrollBarModel::setFastPropertyValue_NoBroadcast( sal_Int32 _nHandle, const Any& _rValue ) throw ( Exception )
     178                 :            :     {
     179         [ +  + ]:        116 :         switch ( _nHandle )
     180                 :            :         {
     181                 :            :             case PROPERTY_ID_DEFAULT_SCROLL_VALUE:
     182                 :         18 :                 OSL_VERIFY( _rValue >>= m_nDefaultScrollValue );
     183                 :         18 :                 resetNoBroadcast();
     184                 :         18 :                 break;
     185                 :            : 
     186                 :            :             default:
     187                 :         98 :                 OBoundControlModel::setFastPropertyValue_NoBroadcast( _nHandle, _rValue );
     188                 :            :         }
     189                 :        116 :     }
     190                 :            : 
     191                 :            :     //------------------------------------------------------------------------------
     192                 :        306 :     sal_Bool OScrollBarModel::convertFastPropertyValue(
     193                 :            :                 Any& _rConvertedValue, Any& _rOldValue, sal_Int32 _nHandle, const Any& _rValue )
     194                 :            :                 throw ( IllegalArgumentException )
     195                 :            :     {
     196                 :        306 :         sal_Bool bModified( sal_False );
     197         [ +  + ]:        306 :         switch ( _nHandle )
     198                 :            :         {
     199                 :            :             case PROPERTY_ID_DEFAULT_SCROLL_VALUE:
     200                 :         56 :                 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, m_nDefaultScrollValue );
     201                 :         56 :                 break;
     202                 :            : 
     203                 :            :             default:
     204                 :        250 :                 bModified = OBoundControlModel::convertFastPropertyValue( _rConvertedValue, _rOldValue, _nHandle, _rValue );
     205                 :        250 :                 break;
     206                 :            :         }
     207                 :        306 :         return bModified;
     208                 :            :     }
     209                 :            : 
     210                 :            :     //--------------------------------------------------------------------
     211                 :          0 :     Any OScrollBarModel::getPropertyDefaultByHandle( sal_Int32 _nHandle ) const
     212                 :            :     {
     213                 :          0 :         Any aReturn;
     214                 :            : 
     215         [ #  # ]:          0 :         switch ( _nHandle )
     216                 :            :         {
     217                 :            :         case PROPERTY_ID_DEFAULT_SCROLL_VALUE:
     218         [ #  # ]:          0 :             aReturn <<= (sal_Int32)0;
     219                 :          0 :             break;
     220                 :            : 
     221                 :            :         default:
     222         [ #  # ]:          0 :             aReturn = OBoundControlModel::getPropertyDefaultByHandle( _nHandle );
     223                 :          0 :             break;
     224                 :            :         }
     225                 :            : 
     226                 :          0 :         return aReturn;
     227                 :            :     }
     228                 :            : 
     229                 :            :     //------------------------------------------------------------------------------
     230                 :          0 :     Any OScrollBarModel::translateDbColumnToControlValue( )
     231                 :            :     {
     232                 :            :         OSL_FAIL( "OScrollBarModel::commitControlValueToDbColumn: never to be called (we're not bound)!" );
     233                 :          0 :         return Any();
     234                 :            :     }
     235                 :            : 
     236                 :            :     //------------------------------------------------------------------------------
     237                 :          0 :     sal_Bool OScrollBarModel::commitControlValueToDbColumn( bool /*_bPostReset*/ )
     238                 :            :     {
     239                 :            :         OSL_FAIL( "OScrollBarModel::commitControlValueToDbColumn: never to be called (we're not bound)!" );
     240                 :          0 :         return sal_True;
     241                 :            :     }
     242                 :            : 
     243                 :            :     //------------------------------------------------------------------------------
     244                 :         22 :     Any OScrollBarModel::getDefaultForReset() const
     245                 :            :     {
     246         [ +  - ]:         22 :         return makeAny( (sal_Int32)m_nDefaultScrollValue );
     247                 :            :     }
     248                 :            : 
     249                 :            :     //--------------------------------------------------------------------
     250                 :          2 :     ::rtl::OUString SAL_CALL OScrollBarModel::getServiceName() throw( RuntimeException )
     251                 :            :     {
     252                 :          2 :         return FRM_SUN_COMPONENT_SCROLLBAR;
     253                 :            :     }
     254                 :            : 
     255                 :            :     //--------------------------------------------------------------------
     256                 :          2 :     void SAL_CALL OScrollBarModel::write( const Reference< XObjectOutputStream >& _rxOutStream )
     257                 :            :         throw( IOException, RuntimeException )
     258                 :            :     {
     259         [ +  - ]:          2 :         OBoundControlModel::write( _rxOutStream );
     260         [ +  - ]:          2 :         ::osl::MutexGuard aGuard( m_aMutex );
     261                 :            : 
     262 [ +  - ][ +  - ]:          2 :         OStreamSection aSection( Reference< XDataOutputStream >( _rxOutStream, UNO_QUERY ) );
     263                 :            : 
     264                 :            :         // version
     265 [ +  - ][ +  - ]:          2 :         _rxOutStream->writeShort( 0x0001 );
     266                 :            : 
     267                 :            :         // properties
     268         [ +  - ]:          2 :         _rxOutStream << m_nDefaultScrollValue;
     269 [ +  - ][ +  - ]:          2 :         writeHelpTextCompatibly( _rxOutStream );
                 [ +  - ]
     270                 :          2 :     }
     271                 :            : 
     272                 :            :     //--------------------------------------------------------------------
     273                 :          2 :     void SAL_CALL OScrollBarModel::read( const Reference< XObjectInputStream>& _rxInStream ) throw( IOException, RuntimeException )
     274                 :            :     {
     275         [ +  - ]:          2 :         OBoundControlModel::read( _rxInStream );
     276         [ +  - ]:          2 :         ::osl::MutexGuard aGuard( m_aMutex );
     277                 :            : 
     278                 :            :         // version
     279                 :            :         {
     280 [ +  - ][ +  - ]:          2 :             OStreamSection aSection( Reference< XDataInputStream >( _rxInStream, UNO_QUERY ) );
     281                 :            : 
     282 [ +  - ][ +  - ]:          2 :             sal_uInt16 nVersion = _rxInStream->readShort();
     283         [ +  - ]:          2 :             if ( nVersion == 0x0001 )
     284                 :            :             {
     285         [ +  - ]:          2 :                 _rxInStream >> m_nDefaultScrollValue;
     286         [ +  - ]:          2 :                 readHelpTextCompatibly( _rxInStream );
     287                 :            :             }
     288                 :            :             else
     289 [ #  # ][ +  - ]:          2 :                 defaultCommonProperties();
     290                 :            : 
     291                 :            :             // here, everything in the stream section which is left will be skipped
     292         [ +  - ]:          2 :         }
     293                 :          2 :     }
     294                 :            : 
     295                 :            :     //--------------------------------------------------------------------
     296                 :          0 :     Any OScrollBarModel::translateExternalValueToControlValue( const Any& _rExternalValue ) const
     297                 :            :     {
     298                 :            :         return translateExternalDoubleToControlIntValue( _rExternalValue, m_xAggregateSet,
     299                 :            :             ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ScrollValueMin" ) ),
     300 [ #  # ][ #  # ]:          0 :             ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ScrollValueMax" ) ) );
     301                 :            :     }
     302                 :            : 
     303                 :            :     //--------------------------------------------------------------------
     304                 :          0 :     Any OScrollBarModel::translateControlValueToExternalValue( ) const
     305                 :            :     {
     306                 :            :         // by definition, the base class simply obtains the property value
     307         [ #  # ]:          0 :         return translateControlIntToExternalDoubleValue( OBoundControlModel::translateControlValueToExternalValue() );
     308                 :            :     }
     309                 :            : 
     310                 :            :     //--------------------------------------------------------------------
     311                 :          0 :     Sequence< Type > OScrollBarModel::getSupportedBindingTypes()
     312                 :            :     {
     313                 :          0 :         return Sequence< Type >( &::getCppuType( static_cast< double* >( NULL ) ), 1 );
     314                 :            :     }
     315                 :            : 
     316                 :            : //........................................................................
     317                 :            : }   // namespace frm
     318                 :            : //........................................................................
     319                 :            : 
     320                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10