LCOV - code coverage report
Current view: top level - libreoffice/toolkit/source/awt - vclxspinbutton.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 142 0.0 %
Date: 2012-12-27 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 "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           0 :         void lcl_modifyStyle( Window* _pWindow, WinBits _nStyleBits, sal_Bool _bShouldBePresent )
      49             :         {
      50           0 :             WinBits nStyle = _pWindow->GetStyle();
      51           0 :             if ( _bShouldBePresent )
      52           0 :                 nStyle |= _nStyleBits;
      53             :             else
      54           0 :                 nStyle &= ~_nStyleBits;
      55           0 :             _pWindow->SetStyle( nStyle );
      56           0 :         }
      57             :     }
      58             : 
      59             :     //====================================================================
      60             :     //= VCLXSpinButton
      61             :     //====================================================================
      62             :     DBG_NAME( VCLXSpinButton )
      63             :     //--------------------------------------------------------------------
      64           0 :     VCLXSpinButton::VCLXSpinButton()
      65           0 :         :maAdjustmentListeners( *this )
      66             :     {
      67             :         DBG_CTOR( VCLXSpinButton, NULL );
      68           0 :     }
      69             : 
      70             :     //--------------------------------------------------------------------
      71           0 :     VCLXSpinButton::~VCLXSpinButton()
      72             :     {
      73             :         DBG_DTOR( VCLXSpinButton, NULL );
      74           0 :     }
      75             : 
      76             :     //--------------------------------------------------------------------
      77           0 :     IMPLEMENT_FORWARD_XINTERFACE2( VCLXSpinButton, VCLXWindow, VCLXSpinButton_Base )
      78             : 
      79             :     //--------------------------------------------------------------------
      80           0 :     IMPLEMENT_FORWARD_XTYPEPROVIDER2( VCLXSpinButton, VCLXWindow, VCLXSpinButton_Base )
      81             : 
      82             :     //--------------------------------------------------------------------
      83           0 :     void SAL_CALL VCLXSpinButton::dispose( ) throw(RuntimeException)
      84             :     {
      85             :         {
      86           0 :             SolarMutexGuard aGuard;
      87             : 
      88           0 :             EventObject aDisposeEvent;
      89           0 :             aDisposeEvent.Source = *this;
      90           0 :             maAdjustmentListeners.disposeAndClear( aDisposeEvent );
      91             :         }
      92             : 
      93           0 :         VCLXWindow::dispose();
      94           0 :     }
      95             : 
      96             :     //--------------------------------------------------------------------
      97           0 :     void SAL_CALL VCLXSpinButton::addAdjustmentListener( const Reference< XAdjustmentListener >& listener ) throw (RuntimeException)
      98             :     {
      99           0 :         if ( listener.is() )
     100           0 :             maAdjustmentListeners.addInterface( listener );
     101           0 :     }
     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           0 :         void lcl_setSpinButtonValue(Window* _pWindow, SetSpinButtonValue _pSetter, sal_Int32 _nValue )
     117             :         {
     118           0 :             SolarMutexGuard aGuard;
     119           0 :             SpinButton* pSpinButton = static_cast< SpinButton* >( _pWindow );
     120           0 :             if ( pSpinButton )
     121           0 :                 (pSpinButton->*_pSetter)( _nValue );
     122           0 :         }
     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           0 :     void SAL_CALL VCLXSpinButton::setValue( sal_Int32 n ) throw (RuntimeException)
     140             :     {
     141           0 :         lcl_setSpinButtonValue( GetWindow(), &SpinButton::SetValue, n );
     142           0 :     }
     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           0 :     void SAL_CALL VCLXSpinButton::setMinimum( sal_Int32 minValue ) throw (RuntimeException)
     162             :     {
     163           0 :         lcl_setSpinButtonValue( GetWindow(), &SpinButton::SetRangeMin, minValue );
     164           0 :     }
     165             : 
     166             :     //--------------------------------------------------------------------
     167           0 :     void SAL_CALL VCLXSpinButton::setMaximum( sal_Int32 maxValue ) throw (RuntimeException)
     168             :     {
     169           0 :         lcl_setSpinButtonValue( GetWindow(), &SpinButton::SetRangeMax, maxValue );
     170           0 :     }
     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           0 :     void SAL_CALL VCLXSpinButton::setSpinIncrement( sal_Int32 spinIncrement ) throw (RuntimeException)
     186             :     {
     187           0 :         lcl_setSpinButtonValue( GetWindow(), &SpinButton::SetValueStep, spinIncrement );
     188           0 :     }
     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           0 :     void VCLXSpinButton::ProcessWindowEvent( const VclWindowEvent& _rVclWindowEvent )
     214             :     {
     215           0 :         SolarMutexClearableGuard aGuard;
     216           0 :         Reference< XSpinValue > xKeepAlive( this );
     217           0 :         SpinButton* pSpinButton = static_cast< SpinButton* >( GetWindow() );
     218           0 :         if ( !pSpinButton )
     219           0 :             return;
     220             : 
     221           0 :         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           0 :                 xKeepAlive.clear();
     238           0 :                 aGuard.clear();
     239           0 :                 VCLXWindow::ProcessWindowEvent( _rVclWindowEvent );
     240           0 :                 break;
     241           0 :         }
     242             :     }
     243             : 
     244             :     //--------------------------------------------------------------------
     245           0 :     void SAL_CALL VCLXSpinButton::setProperty( const ::rtl::OUString& PropertyName, const Any& Value ) throw(RuntimeException)
     246             :     {
     247           0 :         SolarMutexGuard aGuard;
     248             : 
     249           0 :         sal_Int32 nValue = 0;
     250           0 :         sal_Bool  bIsLongValue = ( Value >>= nValue );
     251             : 
     252           0 :         if ( GetWindow() )
     253             :         {
     254           0 :             sal_uInt16 nPropertyId = GetPropertyId( PropertyName );
     255           0 :             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           0 :                 setButtonLikeFaceColor( GetWindow(), Value);
     261           0 :                 break;
     262             : 
     263             :             case BASEPROPERTY_SPINVALUE:
     264           0 :                 if ( bIsLongValue )
     265           0 :                     setValue( nValue );
     266           0 :                 break;
     267             : 
     268             :             case BASEPROPERTY_SPINVALUE_MIN:
     269           0 :                 if ( bIsLongValue )
     270           0 :                     setMinimum( nValue );
     271           0 :                 break;
     272             : 
     273             :             case BASEPROPERTY_SPINVALUE_MAX:
     274           0 :                 if ( bIsLongValue )
     275           0 :                     setMaximum( nValue );
     276           0 :                 break;
     277             : 
     278             :             case BASEPROPERTY_SPININCREMENT:
     279           0 :                 if ( bIsLongValue )
     280           0 :                     setSpinIncrement( nValue );
     281           0 :                 break;
     282             : 
     283             :             case BASEPROPERTY_ORIENTATION:
     284           0 :                 if ( bIsLongValue )
     285           0 :                     lcl_modifyStyle( GetWindow(), WB_HSCROLL, nValue == ScrollBarOrientation::HORIZONTAL );
     286           0 :                 break;
     287             : 
     288             :             default:
     289           0 :                 VCLXWindow::setProperty( PropertyName, Value );
     290             :             }
     291           0 :         }
     292           0 :     }
     293             : 
     294             :     //--------------------------------------------------------------------
     295           0 :     Any SAL_CALL VCLXSpinButton::getProperty( const ::rtl::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             :                 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             : }   // namespace toolkit
     345             : //........................................................................
     346             : 
     347             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10