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

Generated by: LCOV version 1.10