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

Generated by: LCOV version 1.10