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