LCOV - code coverage report
Current view: top level - libreoffice/forms/source/component - scrollbar.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 4 106 3.8 %
Date: 2012-12-27 Functions: 3 28 10.7 %
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           3 : extern "C" void SAL_CALL createRegistryInfo_OScrollBarModel()
      27             : {
      28           3 :     static ::frm::OMultiInstanceAutoRegistration< ::frm::OScrollBarModel >   aRegisterModel;
      29           3 : }
      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 ::rtl::OUString& _rMinValueName, const ::rtl::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 :                 ::rtl::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           0 :     OScrollBarModel::OScrollBarModel( const Reference<XMultiServiceFactory>& _rxFactory )
     104             :         :OBoundControlModel( _rxFactory, VCL_CONTROLMODEL_SCROLLBAR, VCL_CONTROL_SCROLLBAR, sal_True, sal_True, sal_False )
     105           0 :         ,m_nDefaultScrollValue( 0 )
     106             :     {
     107             :         DBG_CTOR( OScrollBarModel, NULL );
     108             : 
     109           0 :         m_nClassId = FormComponentType::SCROLLBAR;
     110           0 :         initValueProperty( PROPERTY_SCROLL_VALUE, PROPERTY_ID_SCROLL_VALUE );
     111           0 :     }
     112             : 
     113             :     //--------------------------------------------------------------------
     114           0 :     OScrollBarModel::OScrollBarModel( const OScrollBarModel* _pOriginal, const Reference< XMultiServiceFactory >& _rxFactory )
     115           0 :         :OBoundControlModel( _pOriginal, _rxFactory )
     116             :     {
     117             :         DBG_CTOR( OScrollBarModel, NULL );
     118           0 :         m_nDefaultScrollValue = _pOriginal->m_nDefaultScrollValue;
     119           0 :     }
     120             : 
     121             :     //--------------------------------------------------------------------
     122           0 :     OScrollBarModel::~OScrollBarModel( )
     123             :     {
     124             :         DBG_DTOR( OScrollBarModel, NULL );
     125           0 :     }
     126             : 
     127             :     //--------------------------------------------------------------------
     128           9 :     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           0 :     IMPLEMENT_DEFAULT_CLONING( OScrollBarModel )
     136             : 
     137             :     //------------------------------------------------------------------------------
     138           0 :     void SAL_CALL OScrollBarModel::disposing()
     139             :     {
     140           0 :         OBoundControlModel::disposing();
     141           0 :     }
     142             : 
     143             :     //--------------------------------------------------------------------
     144           0 :     void OScrollBarModel::describeFixedProperties( Sequence< Property >& _rProps ) const
     145             :     {
     146           0 :         BEGIN_DESCRIBE_PROPERTIES( 3, OControlModel )
     147           0 :             DECL_PROP1( DEFAULT_SCROLL_VALUE, sal_Int32,       BOUND );
     148           0 :             DECL_PROP1( TABINDEX,             sal_Int16,       BOUND );
     149           0 :             DECL_PROP2( CONTROLSOURCEPROPERTY,::rtl::OUString, READONLY, TRANSIENT );
     150             :         END_DESCRIBE_PROPERTIES();
     151           0 :     }
     152             : 
     153             :     //------------------------------------------------------------------------------
     154           0 :     void OScrollBarModel::getFastPropertyValue( Any& _rValue, sal_Int32 _nHandle ) const
     155             :     {
     156           0 :         switch ( _nHandle )
     157             :         {
     158             :             case PROPERTY_ID_DEFAULT_SCROLL_VALUE:
     159           0 :                 _rValue <<= m_nDefaultScrollValue;
     160           0 :                 break;
     161             : 
     162             :             default:
     163           0 :                 OBoundControlModel::getFastPropertyValue( _rValue, _nHandle );
     164             :         }
     165           0 :     }
     166             : 
     167             :     //------------------------------------------------------------------------------
     168           0 :     void OScrollBarModel::setFastPropertyValue_NoBroadcast( sal_Int32 _nHandle, const Any& _rValue ) throw ( Exception )
     169             :     {
     170           0 :         switch ( _nHandle )
     171             :         {
     172             :             case PROPERTY_ID_DEFAULT_SCROLL_VALUE:
     173           0 :                 OSL_VERIFY( _rValue >>= m_nDefaultScrollValue );
     174           0 :                 resetNoBroadcast();
     175           0 :                 break;
     176             : 
     177             :             default:
     178           0 :                 OBoundControlModel::setFastPropertyValue_NoBroadcast( _nHandle, _rValue );
     179             :         }
     180           0 :     }
     181             : 
     182             :     //------------------------------------------------------------------------------
     183           0 :     sal_Bool OScrollBarModel::convertFastPropertyValue(
     184             :                 Any& _rConvertedValue, Any& _rOldValue, sal_Int32 _nHandle, const Any& _rValue )
     185             :                 throw ( IllegalArgumentException )
     186             :     {
     187           0 :         sal_Bool bModified( sal_False );
     188           0 :         switch ( _nHandle )
     189             :         {
     190             :             case PROPERTY_ID_DEFAULT_SCROLL_VALUE:
     191           0 :                 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, m_nDefaultScrollValue );
     192           0 :                 break;
     193             : 
     194             :             default:
     195           0 :                 bModified = OBoundControlModel::convertFastPropertyValue( _rConvertedValue, _rOldValue, _nHandle, _rValue );
     196           0 :                 break;
     197             :         }
     198           0 :         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           0 :     Any OScrollBarModel::getDefaultForReset() const
     236             :     {
     237           0 :         return makeAny( (sal_Int32)m_nDefaultScrollValue );
     238             :     }
     239             : 
     240             :     //--------------------------------------------------------------------
     241           0 :     ::rtl::OUString SAL_CALL OScrollBarModel::getServiceName() throw( RuntimeException )
     242             :     {
     243           0 :         return FRM_SUN_COMPONENT_SCROLLBAR;
     244             :     }
     245             : 
     246             :     //--------------------------------------------------------------------
     247           0 :     void SAL_CALL OScrollBarModel::write( const Reference< XObjectOutputStream >& _rxOutStream )
     248             :         throw( IOException, RuntimeException )
     249             :     {
     250           0 :         OBoundControlModel::write( _rxOutStream );
     251           0 :         ::osl::MutexGuard aGuard( m_aMutex );
     252             : 
     253           0 :         OStreamSection aSection( Reference< XDataOutputStream >( _rxOutStream, UNO_QUERY ) );
     254             : 
     255             :         // version
     256           0 :         _rxOutStream->writeShort( 0x0001 );
     257             : 
     258             :         // properties
     259           0 :         _rxOutStream << m_nDefaultScrollValue;
     260           0 :         writeHelpTextCompatibly( _rxOutStream );
     261           0 :     }
     262             : 
     263             :     //--------------------------------------------------------------------
     264           0 :     void SAL_CALL OScrollBarModel::read( const Reference< XObjectInputStream>& _rxInStream ) throw( IOException, RuntimeException )
     265             :     {
     266           0 :         OBoundControlModel::read( _rxInStream );
     267           0 :         ::osl::MutexGuard aGuard( m_aMutex );
     268             : 
     269             :         // version
     270             :         {
     271           0 :             OStreamSection aSection( Reference< XDataInputStream >( _rxInStream, UNO_QUERY ) );
     272             : 
     273           0 :             sal_uInt16 nVersion = _rxInStream->readShort();
     274           0 :             if ( nVersion == 0x0001 )
     275             :             {
     276           0 :                 _rxInStream >> m_nDefaultScrollValue;
     277           0 :                 readHelpTextCompatibly( _rxInStream );
     278             :             }
     279             :             else
     280           0 :                 defaultCommonProperties();
     281             : 
     282             :             // here, everything in the stream section which is left will be skipped
     283           0 :         }
     284           0 :     }
     285             : 
     286             :     //--------------------------------------------------------------------
     287           0 :     Any OScrollBarModel::translateExternalValueToControlValue( const Any& _rExternalValue ) const
     288             :     {
     289             :         return translateExternalDoubleToControlIntValue( _rExternalValue, m_xAggregateSet,
     290             :             ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ScrollValueMin" ) ),
     291           0 :             ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "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