1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_toolkit.hxx" 30*cdf0e10cSrcweir #include "toolkit/awt/vclxspinbutton.hxx" 31*cdf0e10cSrcweir #include "toolkit/helper/property.hxx" 32*cdf0e10cSrcweir #include <com/sun/star/awt/ScrollBarOrientation.hpp> 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir #include <tools/debug.hxx> 36*cdf0e10cSrcweir #include <vcl/spin.hxx> 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir namespace toolkit 39*cdf0e10cSrcweir { 40*cdf0e10cSrcweir void setButtonLikeFaceColor( Window* _pWindow, const ::com::sun::star::uno::Any& _rColorValue ); 41*cdf0e10cSrcweir ::com::sun::star::uno::Any getButtonLikeFaceColor( const Window* _pWindow ); 42*cdf0e10cSrcweir } 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir //........................................................................ 45*cdf0e10cSrcweir namespace toolkit 46*cdf0e10cSrcweir { 47*cdf0e10cSrcweir //........................................................................ 48*cdf0e10cSrcweir 49*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 50*cdf0e10cSrcweir using namespace ::com::sun::star::awt; 51*cdf0e10cSrcweir using namespace ::com::sun::star::lang; 52*cdf0e10cSrcweir using namespace ::com::sun::star::beans; 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir //-------------------------------------------------------------------- 55*cdf0e10cSrcweir namespace 56*cdf0e10cSrcweir { 57*cdf0e10cSrcweir void lcl_modifyStyle( Window* _pWindow, WinBits _nStyleBits, sal_Bool _bShouldBePresent ) 58*cdf0e10cSrcweir { 59*cdf0e10cSrcweir WinBits nStyle = _pWindow->GetStyle(); 60*cdf0e10cSrcweir if ( _bShouldBePresent ) 61*cdf0e10cSrcweir nStyle |= _nStyleBits; 62*cdf0e10cSrcweir else 63*cdf0e10cSrcweir nStyle &= ~_nStyleBits; 64*cdf0e10cSrcweir _pWindow->SetStyle( nStyle ); 65*cdf0e10cSrcweir } 66*cdf0e10cSrcweir } 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir //==================================================================== 69*cdf0e10cSrcweir //= VCLXSpinButton 70*cdf0e10cSrcweir //==================================================================== 71*cdf0e10cSrcweir DBG_NAME( VCLXSpinButton ) 72*cdf0e10cSrcweir //-------------------------------------------------------------------- 73*cdf0e10cSrcweir VCLXSpinButton::VCLXSpinButton() 74*cdf0e10cSrcweir :maAdjustmentListeners( *this ) 75*cdf0e10cSrcweir { 76*cdf0e10cSrcweir DBG_CTOR( VCLXSpinButton, NULL ); 77*cdf0e10cSrcweir } 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir //-------------------------------------------------------------------- 80*cdf0e10cSrcweir VCLXSpinButton::~VCLXSpinButton() 81*cdf0e10cSrcweir { 82*cdf0e10cSrcweir DBG_DTOR( VCLXSpinButton, NULL ); 83*cdf0e10cSrcweir } 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir //-------------------------------------------------------------------- 86*cdf0e10cSrcweir IMPLEMENT_FORWARD_XINTERFACE2( VCLXSpinButton, VCLXWindow, VCLXSpinButton_Base ) 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir //-------------------------------------------------------------------- 89*cdf0e10cSrcweir IMPLEMENT_FORWARD_XTYPEPROVIDER2( VCLXSpinButton, VCLXWindow, VCLXSpinButton_Base ) 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir //-------------------------------------------------------------------- 92*cdf0e10cSrcweir void SAL_CALL VCLXSpinButton::dispose( ) throw(RuntimeException) 93*cdf0e10cSrcweir { 94*cdf0e10cSrcweir { 95*cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() ); 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir EventObject aDisposeEvent; 98*cdf0e10cSrcweir aDisposeEvent.Source = *this; 99*cdf0e10cSrcweir maAdjustmentListeners.disposeAndClear( aDisposeEvent ); 100*cdf0e10cSrcweir } 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir VCLXWindow::dispose(); 103*cdf0e10cSrcweir } 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir //-------------------------------------------------------------------- 106*cdf0e10cSrcweir void SAL_CALL VCLXSpinButton::addAdjustmentListener( const Reference< XAdjustmentListener >& listener ) throw (RuntimeException) 107*cdf0e10cSrcweir { 108*cdf0e10cSrcweir if ( listener.is() ) 109*cdf0e10cSrcweir maAdjustmentListeners.addInterface( listener ); 110*cdf0e10cSrcweir } 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir //-------------------------------------------------------------------- 113*cdf0e10cSrcweir void SAL_CALL VCLXSpinButton::removeAdjustmentListener( const Reference< XAdjustmentListener >& listener ) throw (RuntimeException) 114*cdf0e10cSrcweir { 115*cdf0e10cSrcweir if ( listener.is() ) 116*cdf0e10cSrcweir maAdjustmentListeners.removeInterface( listener ); 117*cdf0e10cSrcweir } 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir namespace 120*cdf0e10cSrcweir { 121*cdf0e10cSrcweir typedef void (SpinButton::*SetSpinButtonValue) (long); 122*cdf0e10cSrcweir typedef long (SpinButton::*GetSpinButtonValue) (void) const; 123*cdf0e10cSrcweir 124*cdf0e10cSrcweir //................................................................ 125*cdf0e10cSrcweir void lcl_setSpinButtonValue( ::vos::IMutex& _rMutex, Window* _pWindow, SetSpinButtonValue _pSetter, sal_Int32 _nValue ) 126*cdf0e10cSrcweir { 127*cdf0e10cSrcweir ::vos::OGuard aGuard( _rMutex ); 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir SpinButton* pSpinButton = static_cast< SpinButton* >( _pWindow ); 130*cdf0e10cSrcweir if ( pSpinButton ) 131*cdf0e10cSrcweir (pSpinButton->*_pSetter)( _nValue ); 132*cdf0e10cSrcweir } 133*cdf0e10cSrcweir 134*cdf0e10cSrcweir //................................................................ 135*cdf0e10cSrcweir sal_Int32 lcl_getSpinButtonValue( ::vos::IMutex& _rMutex, const Window* _pWindow, GetSpinButtonValue _pGetter ) 136*cdf0e10cSrcweir { 137*cdf0e10cSrcweir ::vos::OGuard aGuard( _rMutex ); 138*cdf0e10cSrcweir 139*cdf0e10cSrcweir sal_Int32 nValue = 0; 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir const SpinButton* pSpinButton = static_cast< const SpinButton* >( _pWindow ); 142*cdf0e10cSrcweir if ( pSpinButton ) 143*cdf0e10cSrcweir nValue = (pSpinButton->*_pGetter)( ); 144*cdf0e10cSrcweir return nValue; 145*cdf0e10cSrcweir } 146*cdf0e10cSrcweir } 147*cdf0e10cSrcweir 148*cdf0e10cSrcweir //-------------------------------------------------------------------- 149*cdf0e10cSrcweir void SAL_CALL VCLXSpinButton::setValue( sal_Int32 n ) throw (RuntimeException) 150*cdf0e10cSrcweir { 151*cdf0e10cSrcweir lcl_setSpinButtonValue( GetMutex(), GetWindow(), &SpinButton::SetValue, n ); 152*cdf0e10cSrcweir } 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir //-------------------------------------------------------------------- 155*cdf0e10cSrcweir void SAL_CALL VCLXSpinButton::setValues( sal_Int32 minValue, sal_Int32 maxValue, sal_Int32 currentValue ) throw (RuntimeException) 156*cdf0e10cSrcweir { 157*cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() ); 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir setMinimum( minValue ); 160*cdf0e10cSrcweir setMaximum( maxValue ); 161*cdf0e10cSrcweir setValue( currentValue ); 162*cdf0e10cSrcweir } 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir //-------------------------------------------------------------------- 165*cdf0e10cSrcweir sal_Int32 SAL_CALL VCLXSpinButton::getValue( ) throw (RuntimeException) 166*cdf0e10cSrcweir { 167*cdf0e10cSrcweir return lcl_getSpinButtonValue( GetMutex(), GetWindow(), &SpinButton::GetValue ); 168*cdf0e10cSrcweir } 169*cdf0e10cSrcweir 170*cdf0e10cSrcweir //-------------------------------------------------------------------- 171*cdf0e10cSrcweir void SAL_CALL VCLXSpinButton::setMinimum( sal_Int32 minValue ) throw (RuntimeException) 172*cdf0e10cSrcweir { 173*cdf0e10cSrcweir lcl_setSpinButtonValue( GetMutex(), GetWindow(), &SpinButton::SetRangeMin, minValue ); 174*cdf0e10cSrcweir } 175*cdf0e10cSrcweir 176*cdf0e10cSrcweir //-------------------------------------------------------------------- 177*cdf0e10cSrcweir void SAL_CALL VCLXSpinButton::setMaximum( sal_Int32 maxValue ) throw (RuntimeException) 178*cdf0e10cSrcweir { 179*cdf0e10cSrcweir lcl_setSpinButtonValue( GetMutex(), GetWindow(), &SpinButton::SetRangeMax, maxValue ); 180*cdf0e10cSrcweir } 181*cdf0e10cSrcweir 182*cdf0e10cSrcweir //-------------------------------------------------------------------- 183*cdf0e10cSrcweir sal_Int32 SAL_CALL VCLXSpinButton::getMinimum( ) throw (RuntimeException) 184*cdf0e10cSrcweir { 185*cdf0e10cSrcweir return lcl_getSpinButtonValue( GetMutex(), GetWindow(), &SpinButton::GetRangeMin ); 186*cdf0e10cSrcweir } 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir //-------------------------------------------------------------------- 189*cdf0e10cSrcweir sal_Int32 SAL_CALL VCLXSpinButton::getMaximum( ) throw (RuntimeException) 190*cdf0e10cSrcweir { 191*cdf0e10cSrcweir return lcl_getSpinButtonValue( GetMutex(), GetWindow(), &SpinButton::GetRangeMax ); 192*cdf0e10cSrcweir } 193*cdf0e10cSrcweir 194*cdf0e10cSrcweir //-------------------------------------------------------------------- 195*cdf0e10cSrcweir void SAL_CALL VCLXSpinButton::setSpinIncrement( sal_Int32 spinIncrement ) throw (RuntimeException) 196*cdf0e10cSrcweir { 197*cdf0e10cSrcweir lcl_setSpinButtonValue( GetMutex(), GetWindow(), &SpinButton::SetValueStep, spinIncrement ); 198*cdf0e10cSrcweir } 199*cdf0e10cSrcweir 200*cdf0e10cSrcweir //-------------------------------------------------------------------- 201*cdf0e10cSrcweir sal_Int32 SAL_CALL VCLXSpinButton::getSpinIncrement( ) throw (RuntimeException) 202*cdf0e10cSrcweir { 203*cdf0e10cSrcweir return lcl_getSpinButtonValue( GetMutex(), GetWindow(), &SpinButton::GetValueStep ); 204*cdf0e10cSrcweir } 205*cdf0e10cSrcweir 206*cdf0e10cSrcweir //-------------------------------------------------------------------- 207*cdf0e10cSrcweir void SAL_CALL VCLXSpinButton::setOrientation( sal_Int32 orientation ) throw (NoSupportException, RuntimeException) 208*cdf0e10cSrcweir { 209*cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() ); 210*cdf0e10cSrcweir 211*cdf0e10cSrcweir lcl_modifyStyle( GetWindow(), WB_HSCROLL, orientation == ScrollBarOrientation::HORIZONTAL ); 212*cdf0e10cSrcweir } 213*cdf0e10cSrcweir 214*cdf0e10cSrcweir //-------------------------------------------------------------------- 215*cdf0e10cSrcweir sal_Int32 SAL_CALL VCLXSpinButton::getOrientation( ) throw (RuntimeException) 216*cdf0e10cSrcweir { 217*cdf0e10cSrcweir return ( 0 != ( GetWindow()->GetStyle() & WB_HSCROLL ) ) 218*cdf0e10cSrcweir ? ScrollBarOrientation::HORIZONTAL 219*cdf0e10cSrcweir : ScrollBarOrientation::VERTICAL; 220*cdf0e10cSrcweir } 221*cdf0e10cSrcweir 222*cdf0e10cSrcweir //-------------------------------------------------------------------- 223*cdf0e10cSrcweir void VCLXSpinButton::ProcessWindowEvent( const VclWindowEvent& _rVclWindowEvent ) 224*cdf0e10cSrcweir { 225*cdf0e10cSrcweir ::vos::OClearableGuard aGuard( GetMutex() ); 226*cdf0e10cSrcweir Reference< XSpinValue > xKeepAlive( this ); 227*cdf0e10cSrcweir SpinButton* pSpinButton = static_cast< SpinButton* >( GetWindow() ); 228*cdf0e10cSrcweir if ( !pSpinButton ) 229*cdf0e10cSrcweir return; 230*cdf0e10cSrcweir 231*cdf0e10cSrcweir switch ( _rVclWindowEvent.GetId() ) 232*cdf0e10cSrcweir { 233*cdf0e10cSrcweir case VCLEVENT_SPINBUTTON_UP: 234*cdf0e10cSrcweir case VCLEVENT_SPINBUTTON_DOWN: 235*cdf0e10cSrcweir if ( maAdjustmentListeners.getLength() ) 236*cdf0e10cSrcweir { 237*cdf0e10cSrcweir AdjustmentEvent aEvent; 238*cdf0e10cSrcweir aEvent.Source = *this; 239*cdf0e10cSrcweir aEvent.Value = pSpinButton->GetValue(); 240*cdf0e10cSrcweir 241*cdf0e10cSrcweir aGuard.clear(); 242*cdf0e10cSrcweir maAdjustmentListeners.adjustmentValueChanged( aEvent ); 243*cdf0e10cSrcweir } 244*cdf0e10cSrcweir break; 245*cdf0e10cSrcweir 246*cdf0e10cSrcweir default: 247*cdf0e10cSrcweir xKeepAlive.clear(); 248*cdf0e10cSrcweir aGuard.clear(); 249*cdf0e10cSrcweir VCLXWindow::ProcessWindowEvent( _rVclWindowEvent ); 250*cdf0e10cSrcweir break; 251*cdf0e10cSrcweir } 252*cdf0e10cSrcweir } 253*cdf0e10cSrcweir 254*cdf0e10cSrcweir //-------------------------------------------------------------------- 255*cdf0e10cSrcweir void SAL_CALL VCLXSpinButton::setProperty( const ::rtl::OUString& PropertyName, const Any& Value ) throw(RuntimeException) 256*cdf0e10cSrcweir { 257*cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() ); 258*cdf0e10cSrcweir 259*cdf0e10cSrcweir sal_Int32 nValue = 0; 260*cdf0e10cSrcweir sal_Bool bIsLongValue = ( Value >>= nValue ); 261*cdf0e10cSrcweir 262*cdf0e10cSrcweir if ( GetWindow() ) 263*cdf0e10cSrcweir { 264*cdf0e10cSrcweir sal_uInt16 nPropertyId = GetPropertyId( PropertyName ); 265*cdf0e10cSrcweir switch ( nPropertyId ) 266*cdf0e10cSrcweir { 267*cdf0e10cSrcweir case BASEPROPERTY_BACKGROUNDCOLOR: 268*cdf0e10cSrcweir // the default implementation of the base class doesn't work here, since our 269*cdf0e10cSrcweir // interpretation for this property is slightly different 270*cdf0e10cSrcweir setButtonLikeFaceColor( GetWindow(), Value); 271*cdf0e10cSrcweir break; 272*cdf0e10cSrcweir 273*cdf0e10cSrcweir case BASEPROPERTY_SPINVALUE: 274*cdf0e10cSrcweir if ( bIsLongValue ) 275*cdf0e10cSrcweir setValue( nValue ); 276*cdf0e10cSrcweir break; 277*cdf0e10cSrcweir 278*cdf0e10cSrcweir case BASEPROPERTY_SPINVALUE_MIN: 279*cdf0e10cSrcweir if ( bIsLongValue ) 280*cdf0e10cSrcweir setMinimum( nValue ); 281*cdf0e10cSrcweir break; 282*cdf0e10cSrcweir 283*cdf0e10cSrcweir case BASEPROPERTY_SPINVALUE_MAX: 284*cdf0e10cSrcweir if ( bIsLongValue ) 285*cdf0e10cSrcweir setMaximum( nValue ); 286*cdf0e10cSrcweir break; 287*cdf0e10cSrcweir 288*cdf0e10cSrcweir case BASEPROPERTY_SPININCREMENT: 289*cdf0e10cSrcweir if ( bIsLongValue ) 290*cdf0e10cSrcweir setSpinIncrement( nValue ); 291*cdf0e10cSrcweir break; 292*cdf0e10cSrcweir 293*cdf0e10cSrcweir case BASEPROPERTY_ORIENTATION: 294*cdf0e10cSrcweir if ( bIsLongValue ) 295*cdf0e10cSrcweir lcl_modifyStyle( GetWindow(), WB_HSCROLL, nValue == ScrollBarOrientation::HORIZONTAL ); 296*cdf0e10cSrcweir break; 297*cdf0e10cSrcweir 298*cdf0e10cSrcweir default: 299*cdf0e10cSrcweir VCLXWindow::setProperty( PropertyName, Value ); 300*cdf0e10cSrcweir } 301*cdf0e10cSrcweir } 302*cdf0e10cSrcweir } 303*cdf0e10cSrcweir 304*cdf0e10cSrcweir //-------------------------------------------------------------------- 305*cdf0e10cSrcweir Any SAL_CALL VCLXSpinButton::getProperty( const ::rtl::OUString& PropertyName ) throw(RuntimeException) 306*cdf0e10cSrcweir { 307*cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() ); 308*cdf0e10cSrcweir 309*cdf0e10cSrcweir Any aReturn; 310*cdf0e10cSrcweir 311*cdf0e10cSrcweir if ( GetWindow() ) 312*cdf0e10cSrcweir { 313*cdf0e10cSrcweir sal_uInt16 nPropertyId = GetPropertyId( PropertyName ); 314*cdf0e10cSrcweir switch ( nPropertyId ) 315*cdf0e10cSrcweir { 316*cdf0e10cSrcweir case BASEPROPERTY_BACKGROUNDCOLOR: 317*cdf0e10cSrcweir // the default implementation of the base class doesn't work here, since our 318*cdf0e10cSrcweir // interpretation for this property is slightly different 319*cdf0e10cSrcweir aReturn = getButtonLikeFaceColor( GetWindow() ); 320*cdf0e10cSrcweir break; 321*cdf0e10cSrcweir 322*cdf0e10cSrcweir case BASEPROPERTY_SPINVALUE: 323*cdf0e10cSrcweir aReturn <<= (sal_Int32)getValue( ); 324*cdf0e10cSrcweir break; 325*cdf0e10cSrcweir 326*cdf0e10cSrcweir case BASEPROPERTY_SPINVALUE_MIN: 327*cdf0e10cSrcweir aReturn <<= (sal_Int32)getMinimum( ); 328*cdf0e10cSrcweir break; 329*cdf0e10cSrcweir 330*cdf0e10cSrcweir case BASEPROPERTY_SPINVALUE_MAX: 331*cdf0e10cSrcweir aReturn <<= (sal_Int32)getMaximum( ); 332*cdf0e10cSrcweir break; 333*cdf0e10cSrcweir 334*cdf0e10cSrcweir case BASEPROPERTY_SPININCREMENT: 335*cdf0e10cSrcweir aReturn <<= (sal_Int32)getSpinIncrement( ); 336*cdf0e10cSrcweir break; 337*cdf0e10cSrcweir 338*cdf0e10cSrcweir case BASEPROPERTY_ORIENTATION: 339*cdf0e10cSrcweir aReturn <<= (sal_Int32) 340*cdf0e10cSrcweir ( ( 0 != ( GetWindow()->GetStyle() & WB_HSCROLL ) ) 341*cdf0e10cSrcweir ? ScrollBarOrientation::HORIZONTAL 342*cdf0e10cSrcweir : ScrollBarOrientation::VERTICAL 343*cdf0e10cSrcweir ); 344*cdf0e10cSrcweir break; 345*cdf0e10cSrcweir 346*cdf0e10cSrcweir default: 347*cdf0e10cSrcweir aReturn = VCLXWindow::getProperty( PropertyName ); 348*cdf0e10cSrcweir } 349*cdf0e10cSrcweir } 350*cdf0e10cSrcweir return aReturn; 351*cdf0e10cSrcweir } 352*cdf0e10cSrcweir 353*cdf0e10cSrcweir //........................................................................ 354*cdf0e10cSrcweir } // namespace toolkit 355*cdf0e10cSrcweir //........................................................................ 356