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