LCOV - code coverage report
Current view: top level - forms/source/component - scrollbar.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 68 106 64.2 %
Date: 2014-04-11 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          17 : extern "C" void SAL_CALL createRegistryInfo_OScrollBarModel()
      27             : {
      28          17 :     static ::frm::OMultiInstanceAutoRegistration< ::frm::OScrollBarModel >   aRegisterModel;
      29          17 : }
      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             : 
     102           6 :     OScrollBarModel::OScrollBarModel( const Reference<XComponentContext>& _rxFactory )
     103             :         :OBoundControlModel( _rxFactory, VCL_CONTROLMODEL_SCROLLBAR, VCL_CONTROL_SCROLLBAR, sal_True, sal_True, sal_False )
     104           6 :         ,m_nDefaultScrollValue( 0 )
     105             :     {
     106             : 
     107           6 :         m_nClassId = FormComponentType::SCROLLBAR;
     108           6 :         initValueProperty( PROPERTY_SCROLL_VALUE, PROPERTY_ID_SCROLL_VALUE );
     109           6 :     }
     110             : 
     111             : 
     112           1 :     OScrollBarModel::OScrollBarModel( const OScrollBarModel* _pOriginal, const Reference< XComponentContext >& _rxFactory )
     113           1 :         :OBoundControlModel( _pOriginal, _rxFactory )
     114             :     {
     115           1 :         m_nDefaultScrollValue = _pOriginal->m_nDefaultScrollValue;
     116           1 :     }
     117             : 
     118             : 
     119          14 :     OScrollBarModel::~OScrollBarModel( )
     120             :     {
     121          14 :     }
     122             : 
     123             : 
     124          79 :     IMPLEMENT_SERVICE_REGISTRATION_2( OScrollBarModel, OControlModel, FRM_SUN_COMPONENT_SCROLLBAR, BINDABLE_INTEGER_VALUE_RANGE )
     125             :         // note that we're passing OControlModel as "base class". This is because
     126             :         // OBoundControlModel, our real base class, claims to support the DataAwareControlModel
     127             :         // service, which isn't really true for us. We only derive from this class
     128             :         // to benefit from the functionality for binding to spreadsheet cells
     129             : 
     130             : 
     131           1 :     IMPLEMENT_DEFAULT_CLONING( OScrollBarModel )
     132             : 
     133             : 
     134           7 :     void SAL_CALL OScrollBarModel::disposing()
     135             :     {
     136           7 :         OBoundControlModel::disposing();
     137           7 :     }
     138             : 
     139             : 
     140           8 :     void OScrollBarModel::describeFixedProperties( Sequence< Property >& _rProps ) const
     141             :     {
     142           8 :         BEGIN_DESCRIBE_PROPERTIES( 3, OControlModel )
     143           8 :             DECL_PROP1( DEFAULT_SCROLL_VALUE, sal_Int32,       BOUND );
     144           8 :             DECL_PROP1( TABINDEX,             sal_Int16,       BOUND );
     145           8 :             DECL_PROP2( CONTROLSOURCEPROPERTY,OUString, READONLY, TRANSIENT );
     146             :         END_DESCRIBE_PROPERTIES();
     147           8 :     }
     148             : 
     149             : 
     150        1073 :     void OScrollBarModel::getFastPropertyValue( Any& _rValue, sal_Int32 _nHandle ) const
     151             :     {
     152        1073 :         switch ( _nHandle )
     153             :         {
     154             :             case PROPERTY_ID_DEFAULT_SCROLL_VALUE:
     155          44 :                 _rValue <<= m_nDefaultScrollValue;
     156          44 :                 break;
     157             : 
     158             :             default:
     159        1029 :                 OBoundControlModel::getFastPropertyValue( _rValue, _nHandle );
     160             :         }
     161        1073 :     }
     162             : 
     163             : 
     164          72 :     void OScrollBarModel::setFastPropertyValue_NoBroadcast( sal_Int32 _nHandle, const Any& _rValue ) throw ( Exception, std::exception )
     165             :     {
     166          72 :         switch ( _nHandle )
     167             :         {
     168             :             case PROPERTY_ID_DEFAULT_SCROLL_VALUE:
     169           9 :                 OSL_VERIFY( _rValue >>= m_nDefaultScrollValue );
     170           9 :                 resetNoBroadcast();
     171           9 :                 break;
     172             : 
     173             :             default:
     174          63 :                 OBoundControlModel::setFastPropertyValue_NoBroadcast( _nHandle, _rValue );
     175             :         }
     176          72 :     }
     177             : 
     178             : 
     179         220 :     sal_Bool OScrollBarModel::convertFastPropertyValue(
     180             :                 Any& _rConvertedValue, Any& _rOldValue, sal_Int32 _nHandle, const Any& _rValue )
     181             :                 throw ( IllegalArgumentException )
     182             :     {
     183         220 :         sal_Bool bModified( sal_False );
     184         220 :         switch ( _nHandle )
     185             :         {
     186             :             case PROPERTY_ID_DEFAULT_SCROLL_VALUE:
     187          30 :                 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, m_nDefaultScrollValue );
     188          30 :                 break;
     189             : 
     190             :             default:
     191         190 :                 bModified = OBoundControlModel::convertFastPropertyValue( _rConvertedValue, _rOldValue, _nHandle, _rValue );
     192         190 :                 break;
     193             :         }
     194         220 :         return bModified;
     195             :     }
     196             : 
     197             : 
     198           0 :     Any OScrollBarModel::getPropertyDefaultByHandle( sal_Int32 _nHandle ) const
     199             :     {
     200           0 :         Any aReturn;
     201             : 
     202           0 :         switch ( _nHandle )
     203             :         {
     204             :         case PROPERTY_ID_DEFAULT_SCROLL_VALUE:
     205           0 :             aReturn <<= (sal_Int32)0;
     206           0 :             break;
     207             : 
     208             :         default:
     209           0 :             aReturn = OBoundControlModel::getPropertyDefaultByHandle( _nHandle );
     210           0 :             break;
     211             :         }
     212             : 
     213           0 :         return aReturn;
     214             :     }
     215             : 
     216             : 
     217           0 :     Any OScrollBarModel::translateDbColumnToControlValue( )
     218             :     {
     219             :         OSL_FAIL( "OScrollBarModel::commitControlValueToDbColumn: never to be called (we're not bound)!" );
     220           0 :         return Any();
     221             :     }
     222             : 
     223             : 
     224           0 :     sal_Bool OScrollBarModel::commitControlValueToDbColumn( bool /*_bPostReset*/ )
     225             :     {
     226             :         OSL_FAIL( "OScrollBarModel::commitControlValueToDbColumn: never to be called (we're not bound)!" );
     227           0 :         return sal_True;
     228             :     }
     229             : 
     230             : 
     231          11 :     Any OScrollBarModel::getDefaultForReset() const
     232             :     {
     233          11 :         return makeAny( (sal_Int32)m_nDefaultScrollValue );
     234             :     }
     235             : 
     236             : 
     237           1 :     OUString SAL_CALL OScrollBarModel::getServiceName() throw( RuntimeException, std::exception )
     238             :     {
     239           1 :         return OUString(FRM_SUN_COMPONENT_SCROLLBAR);
     240             :     }
     241             : 
     242             : 
     243           1 :     void SAL_CALL OScrollBarModel::write( const Reference< XObjectOutputStream >& _rxOutStream )
     244             :         throw( IOException, RuntimeException, std::exception )
     245             :     {
     246           1 :         OBoundControlModel::write( _rxOutStream );
     247           1 :         ::osl::MutexGuard aGuard( m_aMutex );
     248             : 
     249           2 :         OStreamSection aSection( _rxOutStream );
     250             : 
     251             :         // version
     252           1 :         _rxOutStream->writeShort( 0x0001 );
     253             : 
     254             :         // properties
     255           1 :         _rxOutStream << m_nDefaultScrollValue;
     256           2 :         writeHelpTextCompatibly( _rxOutStream );
     257           1 :     }
     258             : 
     259             : 
     260           1 :     void SAL_CALL OScrollBarModel::read( const Reference< XObjectInputStream>& _rxInStream ) throw( IOException, RuntimeException, std::exception )
     261             :     {
     262           1 :         OBoundControlModel::read( _rxInStream );
     263           1 :         ::osl::MutexGuard aGuard( m_aMutex );
     264             : 
     265             :         // version
     266             :         {
     267           1 :             OStreamSection aSection( _rxInStream );
     268             : 
     269           1 :             sal_uInt16 nVersion = _rxInStream->readShort();
     270           1 :             if ( nVersion == 0x0001 )
     271             :             {
     272           1 :                 _rxInStream >> m_nDefaultScrollValue;
     273           1 :                 readHelpTextCompatibly( _rxInStream );
     274             :             }
     275             :             else
     276           0 :                 defaultCommonProperties();
     277             : 
     278             :             // here, everything in the stream section which is left will be skipped
     279           1 :         }
     280           1 :     }
     281             : 
     282             : 
     283           0 :     Any OScrollBarModel::translateExternalValueToControlValue( const Any& _rExternalValue ) const
     284             :     {
     285             :         return translateExternalDoubleToControlIntValue( _rExternalValue, m_xAggregateSet,
     286             :             OUString( "ScrollValueMin" ),
     287           0 :             OUString( "ScrollValueMax" ) );
     288             :     }
     289             : 
     290             : 
     291           0 :     Any OScrollBarModel::translateControlValueToExternalValue( ) const
     292             :     {
     293             :         // by definition, the base class simply obtains the property value
     294           0 :         return translateControlIntToExternalDoubleValue( OBoundControlModel::translateControlValueToExternalValue() );
     295             :     }
     296             : 
     297             : 
     298           0 :     Sequence< Type > OScrollBarModel::getSupportedBindingTypes()
     299             :     {
     300           0 :         return Sequence< Type >( &::getCppuType( static_cast< double* >( NULL ) ), 1 );
     301             :     }
     302             : 
     303             : 
     304             : }   // namespace frm
     305             : 
     306             : 
     307             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10