LCOV - code coverage report
Current view: top level - toolkit/source/awt - vclxspinbutton.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 80 143 55.9 %
Date: 2015-06-13 12:38:46 Functions: 16 28 57.1 %
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           1 :         void lcl_modifyStyle( vcl::Window* _pWindow, WinBits _nStyleBits, bool _bShouldBePresent )
      41             :         {
      42           1 :             WinBits nStyle = _pWindow->GetStyle();
      43           1 :             if ( _bShouldBePresent )
      44           1 :                 nStyle |= _nStyleBits;
      45             :             else
      46           0 :                 nStyle &= ~_nStyleBits;
      47           1 :             _pWindow->SetStyle( nStyle );
      48           1 :         }
      49             :     }
      50             : 
      51           1 :     VCLXSpinButton::VCLXSpinButton()
      52           1 :         :maAdjustmentListeners( *this )
      53             :     {
      54           1 :     }
      55             : 
      56             : 
      57           2 :     VCLXSpinButton::~VCLXSpinButton()
      58             :     {
      59           2 :     }
      60             : 
      61             : 
      62         539 :     IMPLEMENT_FORWARD_XINTERFACE2( VCLXSpinButton, VCLXWindow, VCLXSpinButton_Base )
      63             : 
      64             : 
      65           0 :     IMPLEMENT_FORWARD_XTYPEPROVIDER2( VCLXSpinButton, VCLXWindow, VCLXSpinButton_Base )
      66             : 
      67             : 
      68           2 :     void SAL_CALL VCLXSpinButton::dispose( ) throw(RuntimeException, std::exception)
      69             :     {
      70             :         {
      71           2 :             SolarMutexGuard aGuard;
      72             : 
      73           4 :             EventObject aDisposeEvent;
      74           2 :             aDisposeEvent.Source = *this;
      75           4 :             maAdjustmentListeners.disposeAndClear( aDisposeEvent );
      76             :         }
      77             : 
      78           2 :         VCLXWindow::dispose();
      79           2 :     }
      80             : 
      81             : 
      82           2 :     void SAL_CALL VCLXSpinButton::addAdjustmentListener( const Reference< XAdjustmentListener >& listener ) throw (RuntimeException, std::exception)
      83             :     {
      84           2 :         if ( listener.is() )
      85           2 :             maAdjustmentListeners.addInterface( listener );
      86           2 :     }
      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           4 :         void lcl_setSpinButtonValue(vcl::Window* _pWindow, SetSpinButtonValue _pSetter, sal_Int32 _nValue )
     102             :         {
     103           4 :             SolarMutexGuard aGuard;
     104           4 :             SpinButton* pSpinButton = static_cast< SpinButton* >( _pWindow );
     105           4 :             if ( pSpinButton )
     106           4 :                 (pSpinButton->*_pSetter)( _nValue );
     107           4 :         }
     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           1 :     void SAL_CALL VCLXSpinButton::setValue( sal_Int32 n ) throw (RuntimeException, std::exception)
     125             :     {
     126           1 :         lcl_setSpinButtonValue( GetWindow(), &SpinButton::SetValue, n );
     127           1 :     }
     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           1 :     void SAL_CALL VCLXSpinButton::setMinimum( sal_Int32 minValue ) throw (RuntimeException, std::exception)
     147             :     {
     148           1 :         lcl_setSpinButtonValue( GetWindow(), &SpinButton::SetRangeMin, minValue );
     149           1 :     }
     150             : 
     151             : 
     152           1 :     void SAL_CALL VCLXSpinButton::setMaximum( sal_Int32 maxValue ) throw (RuntimeException, std::exception)
     153             :     {
     154           1 :         lcl_setSpinButtonValue( GetWindow(), &SpinButton::SetRangeMax, maxValue );
     155           1 :     }
     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           1 :     void SAL_CALL VCLXSpinButton::setSpinIncrement( sal_Int32 spinIncrement ) throw (RuntimeException, std::exception)
     171             :     {
     172           1 :         lcl_setSpinButtonValue( GetWindow(), &SpinButton::SetValueStep, spinIncrement );
     173           1 :     }
     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          10 :     void VCLXSpinButton::ProcessWindowEvent( const VclWindowEvent& _rVclWindowEvent )
     199             :     {
     200          10 :         SolarMutexClearableGuard aGuard;
     201          20 :         Reference< XSpinValue > xKeepAlive( this );
     202          20 :         VclPtr<SpinButton> pSpinButton = GetAs<SpinButton>();
     203          10 :         if ( !pSpinButton )
     204          10 :             return;
     205             : 
     206          10 :         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          10 :                 xKeepAlive.clear();
     223          10 :                 aGuard.clear();
     224          10 :                 VCLXWindow::ProcessWindowEvent( _rVclWindowEvent );
     225          10 :                 break;
     226          10 :         }
     227             :     }
     228             : 
     229             : 
     230          30 :     void SAL_CALL VCLXSpinButton::setProperty( const OUString& PropertyName, const Any& Value ) throw(RuntimeException, std::exception)
     231             :     {
     232          30 :         SolarMutexGuard aGuard;
     233             : 
     234          30 :         sal_Int32 nValue = 0;
     235          30 :         bool  bIsLongValue = ( Value >>= nValue );
     236             : 
     237          30 :         if ( GetWindow() )
     238             :         {
     239          30 :             sal_uInt16 nPropertyId = GetPropertyId( PropertyName );
     240          30 :             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           1 :                 setButtonLikeFaceColor( GetWindow(), Value);
     246           1 :                 break;
     247             : 
     248             :             case BASEPROPERTY_SPINVALUE:
     249           1 :                 if ( bIsLongValue )
     250           1 :                     setValue( nValue );
     251           1 :                 break;
     252             : 
     253             :             case BASEPROPERTY_SPINVALUE_MIN:
     254           1 :                 if ( bIsLongValue )
     255           1 :                     setMinimum( nValue );
     256           1 :                 break;
     257             : 
     258             :             case BASEPROPERTY_SPINVALUE_MAX:
     259           1 :                 if ( bIsLongValue )
     260           1 :                     setMaximum( nValue );
     261           1 :                 break;
     262             : 
     263             :             case BASEPROPERTY_SPININCREMENT:
     264           1 :                 if ( bIsLongValue )
     265           1 :                     setSpinIncrement( nValue );
     266           1 :                 break;
     267             : 
     268             :             case BASEPROPERTY_ORIENTATION:
     269           1 :                 if ( bIsLongValue )
     270           1 :                     lcl_modifyStyle( GetWindow(), WB_HSCROLL, nValue == ScrollBarOrientation::HORIZONTAL );
     271           1 :                 break;
     272             : 
     273             :             default:
     274          24 :                 VCLXWindow::setProperty( PropertyName, Value );
     275             :             }
     276          30 :         }
     277          30 :     }
     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             : }   // namespace toolkit
     330             : 
     331             : 
     332             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11