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

Generated by: LCOV version 1.10