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

Generated by: LCOV version 1.11