LCOV - code coverage report
Current view: top level - toolkit/source/awt - vclxspinbutton.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 81 144 56.2 %
Date: 2014-11-03 Functions: 18 30 60.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 "toolkit/awt/vclxspinbutton.hxx"
      21             : #include "toolkit/helper/property.hxx"
      22             : #include <com/sun/star/awt/ScrollBarOrientation.hpp>
      23             : 
      24             : #include <vcl/spin.hxx>
      25             : #include <vcl/svapp.hxx>
      26             : #include "vclxwindows_internal.hxx"
      27             : 
      28             : namespace toolkit
      29             : {
      30             : 
      31             : 
      32             :     using namespace ::com::sun::star::uno;
      33             :     using namespace ::com::sun::star::awt;
      34             :     using namespace ::com::sun::star::lang;
      35             :     using namespace ::com::sun::star::beans;
      36             : 
      37             : 
      38             :     namespace
      39             :     {
      40           2 :         void lcl_modifyStyle( vcl::Window* _pWindow, WinBits _nStyleBits, bool _bShouldBePresent )
      41             :         {
      42           2 :             WinBits nStyle = _pWindow->GetStyle();
      43           2 :             if ( _bShouldBePresent )
      44           2 :                 nStyle |= _nStyleBits;
      45             :             else
      46           0 :                 nStyle &= ~_nStyleBits;
      47           2 :             _pWindow->SetStyle( nStyle );
      48           2 :         }
      49             :     }
      50             : 
      51           2 :     VCLXSpinButton::VCLXSpinButton()
      52           2 :         :maAdjustmentListeners( *this )
      53             :     {
      54           2 :     }
      55             : 
      56             : 
      57           4 :     VCLXSpinButton::~VCLXSpinButton()
      58             :     {
      59           4 :     }
      60             : 
      61             : 
      62         982 :     IMPLEMENT_FORWARD_XINTERFACE2( VCLXSpinButton, VCLXWindow, VCLXSpinButton_Base )
      63             : 
      64             : 
      65           0 :     IMPLEMENT_FORWARD_XTYPEPROVIDER2( VCLXSpinButton, VCLXWindow, VCLXSpinButton_Base )
      66             : 
      67             : 
      68           4 :     void SAL_CALL VCLXSpinButton::dispose( ) throw(RuntimeException, std::exception)
      69             :     {
      70             :         {
      71           4 :             SolarMutexGuard aGuard;
      72             : 
      73           8 :             EventObject aDisposeEvent;
      74           4 :             aDisposeEvent.Source = *this;
      75           8 :             maAdjustmentListeners.disposeAndClear( aDisposeEvent );
      76             :         }
      77             : 
      78           4 :         VCLXWindow::dispose();
      79           4 :     }
      80             : 
      81             : 
      82           4 :     void SAL_CALL VCLXSpinButton::addAdjustmentListener( const Reference< XAdjustmentListener >& listener ) throw (RuntimeException, std::exception)
      83             :     {
      84           4 :         if ( listener.is() )
      85           4 :             maAdjustmentListeners.addInterface( listener );
      86           4 :     }
      87             : 
      88             : 
      89           0 :     void SAL_CALL VCLXSpinButton::removeAdjustmentListener( const Reference< XAdjustmentListener >& listener ) throw (RuntimeException, std::exception)
      90             :     {
      91           0 :         if ( listener.is() )
      92           0 :             maAdjustmentListeners.removeInterface( listener );
      93           0 :     }
      94             : 
      95             :     namespace
      96             :     {
      97             :         typedef void (SpinButton::*SetSpinButtonValue) (long);
      98             :         typedef long (SpinButton::*GetSpinButtonValue) (void) const;
      99             : 
     100             : 
     101           8 :         void lcl_setSpinButtonValue(vcl::Window* _pWindow, SetSpinButtonValue _pSetter, sal_Int32 _nValue )
     102             :         {
     103           8 :             SolarMutexGuard aGuard;
     104           8 :             SpinButton* pSpinButton = static_cast< SpinButton* >( _pWindow );
     105           8 :             if ( pSpinButton )
     106           8 :                 (pSpinButton->*_pSetter)( _nValue );
     107           8 :         }
     108             : 
     109             : 
     110           0 :         sal_Int32 lcl_getSpinButtonValue(const vcl::Window* _pWindow, GetSpinButtonValue _pGetter )
     111             :         {
     112           0 :             SolarMutexGuard aGuard;
     113             : 
     114           0 :             sal_Int32 nValue = 0;
     115             : 
     116           0 :             const SpinButton* pSpinButton = static_cast< const SpinButton* >( _pWindow );
     117           0 :             if ( pSpinButton )
     118           0 :                 nValue = (pSpinButton->*_pGetter)( );
     119           0 :             return nValue;
     120             :         }
     121             :     }
     122             : 
     123             : 
     124           2 :     void SAL_CALL VCLXSpinButton::setValue( sal_Int32 n ) throw (RuntimeException, std::exception)
     125             :     {
     126           2 :         lcl_setSpinButtonValue( GetWindow(), &SpinButton::SetValue, n );
     127           2 :     }
     128             : 
     129             : 
     130           0 :     void SAL_CALL VCLXSpinButton::setValues( sal_Int32 minValue, sal_Int32 maxValue, sal_Int32 currentValue ) throw (RuntimeException, std::exception)
     131             :     {
     132           0 :         SolarMutexGuard aGuard;
     133             : 
     134           0 :         setMinimum( minValue );
     135           0 :         setMaximum( maxValue );
     136           0 :         setValue( currentValue );
     137           0 :     }
     138             : 
     139             : 
     140           0 :     sal_Int32 SAL_CALL VCLXSpinButton::getValue(  ) throw (RuntimeException, std::exception)
     141             :     {
     142           0 :         return lcl_getSpinButtonValue( GetWindow(), &SpinButton::GetValue );
     143             :     }
     144             : 
     145             : 
     146           2 :     void SAL_CALL VCLXSpinButton::setMinimum( sal_Int32 minValue ) throw (RuntimeException, std::exception)
     147             :     {
     148           2 :         lcl_setSpinButtonValue( GetWindow(), &SpinButton::SetRangeMin, minValue );
     149           2 :     }
     150             : 
     151             : 
     152           2 :     void SAL_CALL VCLXSpinButton::setMaximum( sal_Int32 maxValue ) throw (RuntimeException, std::exception)
     153             :     {
     154           2 :         lcl_setSpinButtonValue( GetWindow(), &SpinButton::SetRangeMax, maxValue );
     155           2 :     }
     156             : 
     157             : 
     158           0 :     sal_Int32 SAL_CALL VCLXSpinButton::getMinimum(  ) throw (RuntimeException, std::exception)
     159             :     {
     160           0 :         return lcl_getSpinButtonValue( GetWindow(), &SpinButton::GetRangeMin );
     161             :     }
     162             : 
     163             : 
     164           0 :     sal_Int32 SAL_CALL VCLXSpinButton::getMaximum(  ) throw (RuntimeException, std::exception)
     165             :     {
     166           0 :         return lcl_getSpinButtonValue( GetWindow(), &SpinButton::GetRangeMax );
     167             :     }
     168             : 
     169             : 
     170           2 :     void SAL_CALL VCLXSpinButton::setSpinIncrement( sal_Int32 spinIncrement ) throw (RuntimeException, std::exception)
     171             :     {
     172           2 :         lcl_setSpinButtonValue( GetWindow(), &SpinButton::SetValueStep, spinIncrement );
     173           2 :     }
     174             : 
     175             : 
     176           0 :     sal_Int32 SAL_CALL VCLXSpinButton::getSpinIncrement(  ) throw (RuntimeException, std::exception)
     177             :     {
     178           0 :         return lcl_getSpinButtonValue( GetWindow(), &SpinButton::GetValueStep );
     179             :     }
     180             : 
     181             : 
     182           0 :     void SAL_CALL VCLXSpinButton::setOrientation( sal_Int32 orientation ) throw (NoSupportException, RuntimeException, std::exception)
     183             :     {
     184           0 :         SolarMutexGuard aGuard;
     185             : 
     186           0 :         lcl_modifyStyle( GetWindow(), WB_HSCROLL, orientation == ScrollBarOrientation::HORIZONTAL );
     187           0 :     }
     188             : 
     189             : 
     190           0 :     sal_Int32 SAL_CALL VCLXSpinButton::getOrientation(  ) throw (RuntimeException, std::exception)
     191             :     {
     192           0 :         return  ( 0 != ( GetWindow()->GetStyle() & WB_HSCROLL ) )
     193             :             ?   ScrollBarOrientation::HORIZONTAL
     194           0 :             :   ScrollBarOrientation::VERTICAL;
     195             :     }
     196             : 
     197             : 
     198          20 :     void VCLXSpinButton::ProcessWindowEvent( const VclWindowEvent& _rVclWindowEvent )
     199             :     {
     200          20 :         SolarMutexClearableGuard aGuard;
     201          40 :         Reference< XSpinValue > xKeepAlive( this );
     202          20 :         SpinButton* pSpinButton = static_cast< SpinButton* >( GetWindow() );
     203          20 :         if ( !pSpinButton )
     204          20 :             return;
     205             : 
     206          20 :         switch ( _rVclWindowEvent.GetId() )
     207             :         {
     208             :             case VCLEVENT_SPINBUTTON_UP:
     209             :             case VCLEVENT_SPINBUTTON_DOWN:
     210           0 :                 if ( maAdjustmentListeners.getLength() )
     211             :                 {
     212           0 :                     AdjustmentEvent aEvent;
     213           0 :                     aEvent.Source = *this;
     214           0 :                     aEvent.Value = pSpinButton->GetValue();
     215             : 
     216           0 :                     aGuard.clear();
     217           0 :                     maAdjustmentListeners.adjustmentValueChanged( aEvent );
     218             :                 }
     219           0 :                 break;
     220             : 
     221             :             default:
     222          20 :                 xKeepAlive.clear();
     223          20 :                 aGuard.clear();
     224          20 :                 VCLXWindow::ProcessWindowEvent( _rVclWindowEvent );
     225          20 :                 break;
     226          20 :         }
     227             :     }
     228             : 
     229             : 
     230          60 :     void SAL_CALL VCLXSpinButton::setProperty( const OUString& PropertyName, const Any& Value ) throw(RuntimeException, std::exception)
     231             :     {
     232          60 :         SolarMutexGuard aGuard;
     233             : 
     234          60 :         sal_Int32 nValue = 0;
     235          60 :         bool  bIsLongValue = ( Value >>= nValue );
     236             : 
     237          60 :         if ( GetWindow() )
     238             :         {
     239          60 :             sal_uInt16 nPropertyId = GetPropertyId( PropertyName );
     240          60 :             switch ( nPropertyId )
     241             :             {
     242             :             case BASEPROPERTY_BACKGROUNDCOLOR:
     243             :                 // the default implementation of the base class doesn't work here, since our
     244             :                 // interpretation for this property is slightly different
     245           2 :                 setButtonLikeFaceColor( GetWindow(), Value);
     246           2 :                 break;
     247             : 
     248             :             case BASEPROPERTY_SPINVALUE:
     249           2 :                 if ( bIsLongValue )
     250           2 :                     setValue( nValue );
     251           2 :                 break;
     252             : 
     253             :             case BASEPROPERTY_SPINVALUE_MIN:
     254           2 :                 if ( bIsLongValue )
     255           2 :                     setMinimum( nValue );
     256           2 :                 break;
     257             : 
     258             :             case BASEPROPERTY_SPINVALUE_MAX:
     259           2 :                 if ( bIsLongValue )
     260           2 :                     setMaximum( nValue );
     261           2 :                 break;
     262             : 
     263             :             case BASEPROPERTY_SPININCREMENT:
     264           2 :                 if ( bIsLongValue )
     265           2 :                     setSpinIncrement( nValue );
     266           2 :                 break;
     267             : 
     268             :             case BASEPROPERTY_ORIENTATION:
     269           2 :                 if ( bIsLongValue )
     270           2 :                     lcl_modifyStyle( GetWindow(), WB_HSCROLL, nValue == ScrollBarOrientation::HORIZONTAL );
     271           2 :                 break;
     272             : 
     273             :             default:
     274          48 :                 VCLXWindow::setProperty( PropertyName, Value );
     275             :             }
     276          60 :         }
     277          60 :     }
     278             : 
     279             : 
     280           0 :     Any SAL_CALL VCLXSpinButton::getProperty( const OUString& PropertyName ) throw(RuntimeException, std::exception)
     281             :     {
     282           0 :         SolarMutexGuard aGuard;
     283             : 
     284           0 :         Any aReturn;
     285             : 
     286           0 :         if ( GetWindow() )
     287             :         {
     288           0 :             sal_uInt16 nPropertyId = GetPropertyId( PropertyName );
     289           0 :             switch ( nPropertyId )
     290             :             {
     291             :             case BASEPROPERTY_BACKGROUNDCOLOR:
     292             :                 // the default implementation of the base class doesn't work here, since our
     293             :                 // interpretation for this property is slightly different
     294           0 :                 aReturn = getButtonLikeFaceColor( GetWindow() );
     295           0 :                 break;
     296             : 
     297             :             case BASEPROPERTY_SPINVALUE:
     298           0 :                 aReturn <<= (sal_Int32)getValue( );
     299           0 :                 break;
     300             : 
     301             :             case BASEPROPERTY_SPINVALUE_MIN:
     302           0 :                 aReturn <<= (sal_Int32)getMinimum( );
     303           0 :                 break;
     304             : 
     305             :             case BASEPROPERTY_SPINVALUE_MAX:
     306           0 :                 aReturn <<= (sal_Int32)getMaximum( );
     307           0 :                 break;
     308             : 
     309             :             case BASEPROPERTY_SPININCREMENT:
     310           0 :                 aReturn <<= (sal_Int32)getSpinIncrement( );
     311           0 :                 break;
     312             : 
     313             :             case BASEPROPERTY_ORIENTATION:
     314           0 :                 aReturn <<= (sal_Int32)
     315           0 :                     (   ( 0 != ( GetWindow()->GetStyle() & WB_HSCROLL ) )
     316             :                     ?   ScrollBarOrientation::HORIZONTAL
     317             :                     :   ScrollBarOrientation::VERTICAL
     318           0 :                     );
     319           0 :                 break;
     320             : 
     321             :             default:
     322           0 :                 aReturn = VCLXWindow::getProperty( PropertyName );
     323             :             }
     324             :         }
     325           0 :         return aReturn;
     326             :     }
     327             : 
     328             : 
     329        1227 : }   // namespace toolkit
     330             : 
     331             : 
     332             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10