Version 4.0.2.1, tag libreoffice-4.0.2.1
[LibreOffice.git] / toolkit / source / awt / vclxspinbutton.cxx
blobf3384dee51459c4df8854fdee7415ad3a8a6f37c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "toolkit/awt/vclxspinbutton.hxx"
21 #include "toolkit/helper/property.hxx"
22 #include <com/sun/star/awt/ScrollBarOrientation.hpp>
25 #include <tools/debug.hxx>
26 #include <vcl/spin.hxx>
27 #include <vcl/svapp.hxx>
29 namespace toolkit
31 void setButtonLikeFaceColor( Window* _pWindow, const ::com::sun::star::uno::Any& _rColorValue );
32 ::com::sun::star::uno::Any getButtonLikeFaceColor( const Window* _pWindow );
35 //........................................................................
36 namespace toolkit
38 //........................................................................
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;
45 //--------------------------------------------------------------------
46 namespace
48 void lcl_modifyStyle( Window* _pWindow, WinBits _nStyleBits, sal_Bool _bShouldBePresent )
50 WinBits nStyle = _pWindow->GetStyle();
51 if ( _bShouldBePresent )
52 nStyle |= _nStyleBits;
53 else
54 nStyle &= ~_nStyleBits;
55 _pWindow->SetStyle( nStyle );
59 //====================================================================
60 //= VCLXSpinButton
61 //====================================================================
62 DBG_NAME( VCLXSpinButton )
63 //--------------------------------------------------------------------
64 VCLXSpinButton::VCLXSpinButton()
65 :maAdjustmentListeners( *this )
67 DBG_CTOR( VCLXSpinButton, NULL );
70 //--------------------------------------------------------------------
71 VCLXSpinButton::~VCLXSpinButton()
73 DBG_DTOR( VCLXSpinButton, NULL );
76 //--------------------------------------------------------------------
77 IMPLEMENT_FORWARD_XINTERFACE2( VCLXSpinButton, VCLXWindow, VCLXSpinButton_Base )
79 //--------------------------------------------------------------------
80 IMPLEMENT_FORWARD_XTYPEPROVIDER2( VCLXSpinButton, VCLXWindow, VCLXSpinButton_Base )
82 //--------------------------------------------------------------------
83 void SAL_CALL VCLXSpinButton::dispose( ) throw(RuntimeException)
86 SolarMutexGuard aGuard;
88 EventObject aDisposeEvent;
89 aDisposeEvent.Source = *this;
90 maAdjustmentListeners.disposeAndClear( aDisposeEvent );
93 VCLXWindow::dispose();
96 //--------------------------------------------------------------------
97 void SAL_CALL VCLXSpinButton::addAdjustmentListener( const Reference< XAdjustmentListener >& listener ) throw (RuntimeException)
99 if ( listener.is() )
100 maAdjustmentListeners.addInterface( listener );
103 //--------------------------------------------------------------------
104 void SAL_CALL VCLXSpinButton::removeAdjustmentListener( const Reference< XAdjustmentListener >& listener ) throw (RuntimeException)
106 if ( listener.is() )
107 maAdjustmentListeners.removeInterface( listener );
110 namespace
112 typedef void (SpinButton::*SetSpinButtonValue) (long);
113 typedef long (SpinButton::*GetSpinButtonValue) (void) const;
115 //................................................................
116 void lcl_setSpinButtonValue(Window* _pWindow, SetSpinButtonValue _pSetter, sal_Int32 _nValue )
118 SolarMutexGuard aGuard;
119 SpinButton* pSpinButton = static_cast< SpinButton* >( _pWindow );
120 if ( pSpinButton )
121 (pSpinButton->*_pSetter)( _nValue );
124 //................................................................
125 sal_Int32 lcl_getSpinButtonValue(const Window* _pWindow, GetSpinButtonValue _pGetter )
127 SolarMutexGuard aGuard;
129 sal_Int32 nValue = 0;
131 const SpinButton* pSpinButton = static_cast< const SpinButton* >( _pWindow );
132 if ( pSpinButton )
133 nValue = (pSpinButton->*_pGetter)( );
134 return nValue;
138 //--------------------------------------------------------------------
139 void SAL_CALL VCLXSpinButton::setValue( sal_Int32 n ) throw (RuntimeException)
141 lcl_setSpinButtonValue( GetWindow(), &SpinButton::SetValue, n );
144 //--------------------------------------------------------------------
145 void SAL_CALL VCLXSpinButton::setValues( sal_Int32 minValue, sal_Int32 maxValue, sal_Int32 currentValue ) throw (RuntimeException)
147 SolarMutexGuard aGuard;
149 setMinimum( minValue );
150 setMaximum( maxValue );
151 setValue( currentValue );
154 //--------------------------------------------------------------------
155 sal_Int32 SAL_CALL VCLXSpinButton::getValue( ) throw (RuntimeException)
157 return lcl_getSpinButtonValue( GetWindow(), &SpinButton::GetValue );
160 //--------------------------------------------------------------------
161 void SAL_CALL VCLXSpinButton::setMinimum( sal_Int32 minValue ) throw (RuntimeException)
163 lcl_setSpinButtonValue( GetWindow(), &SpinButton::SetRangeMin, minValue );
166 //--------------------------------------------------------------------
167 void SAL_CALL VCLXSpinButton::setMaximum( sal_Int32 maxValue ) throw (RuntimeException)
169 lcl_setSpinButtonValue( GetWindow(), &SpinButton::SetRangeMax, maxValue );
172 //--------------------------------------------------------------------
173 sal_Int32 SAL_CALL VCLXSpinButton::getMinimum( ) throw (RuntimeException)
175 return lcl_getSpinButtonValue( GetWindow(), &SpinButton::GetRangeMin );
178 //--------------------------------------------------------------------
179 sal_Int32 SAL_CALL VCLXSpinButton::getMaximum( ) throw (RuntimeException)
181 return lcl_getSpinButtonValue( GetWindow(), &SpinButton::GetRangeMax );
184 //--------------------------------------------------------------------
185 void SAL_CALL VCLXSpinButton::setSpinIncrement( sal_Int32 spinIncrement ) throw (RuntimeException)
187 lcl_setSpinButtonValue( GetWindow(), &SpinButton::SetValueStep, spinIncrement );
190 //--------------------------------------------------------------------
191 sal_Int32 SAL_CALL VCLXSpinButton::getSpinIncrement( ) throw (RuntimeException)
193 return lcl_getSpinButtonValue( GetWindow(), &SpinButton::GetValueStep );
196 //--------------------------------------------------------------------
197 void SAL_CALL VCLXSpinButton::setOrientation( sal_Int32 orientation ) throw (NoSupportException, RuntimeException)
199 SolarMutexGuard aGuard;
201 lcl_modifyStyle( GetWindow(), WB_HSCROLL, orientation == ScrollBarOrientation::HORIZONTAL );
204 //--------------------------------------------------------------------
205 sal_Int32 SAL_CALL VCLXSpinButton::getOrientation( ) throw (RuntimeException)
207 return ( 0 != ( GetWindow()->GetStyle() & WB_HSCROLL ) )
208 ? ScrollBarOrientation::HORIZONTAL
209 : ScrollBarOrientation::VERTICAL;
212 //--------------------------------------------------------------------
213 void VCLXSpinButton::ProcessWindowEvent( const VclWindowEvent& _rVclWindowEvent )
215 SolarMutexClearableGuard aGuard;
216 Reference< XSpinValue > xKeepAlive( this );
217 SpinButton* pSpinButton = static_cast< SpinButton* >( GetWindow() );
218 if ( !pSpinButton )
219 return;
221 switch ( _rVclWindowEvent.GetId() )
223 case VCLEVENT_SPINBUTTON_UP:
224 case VCLEVENT_SPINBUTTON_DOWN:
225 if ( maAdjustmentListeners.getLength() )
227 AdjustmentEvent aEvent;
228 aEvent.Source = *this;
229 aEvent.Value = pSpinButton->GetValue();
231 aGuard.clear();
232 maAdjustmentListeners.adjustmentValueChanged( aEvent );
234 break;
236 default:
237 xKeepAlive.clear();
238 aGuard.clear();
239 VCLXWindow::ProcessWindowEvent( _rVclWindowEvent );
240 break;
244 //--------------------------------------------------------------------
245 void SAL_CALL VCLXSpinButton::setProperty( const ::rtl::OUString& PropertyName, const Any& Value ) throw(RuntimeException)
247 SolarMutexGuard aGuard;
249 sal_Int32 nValue = 0;
250 sal_Bool bIsLongValue = ( Value >>= nValue );
252 if ( GetWindow() )
254 sal_uInt16 nPropertyId = GetPropertyId( PropertyName );
255 switch ( nPropertyId )
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 setButtonLikeFaceColor( GetWindow(), Value);
261 break;
263 case BASEPROPERTY_SPINVALUE:
264 if ( bIsLongValue )
265 setValue( nValue );
266 break;
268 case BASEPROPERTY_SPINVALUE_MIN:
269 if ( bIsLongValue )
270 setMinimum( nValue );
271 break;
273 case BASEPROPERTY_SPINVALUE_MAX:
274 if ( bIsLongValue )
275 setMaximum( nValue );
276 break;
278 case BASEPROPERTY_SPININCREMENT:
279 if ( bIsLongValue )
280 setSpinIncrement( nValue );
281 break;
283 case BASEPROPERTY_ORIENTATION:
284 if ( bIsLongValue )
285 lcl_modifyStyle( GetWindow(), WB_HSCROLL, nValue == ScrollBarOrientation::HORIZONTAL );
286 break;
288 default:
289 VCLXWindow::setProperty( PropertyName, Value );
294 //--------------------------------------------------------------------
295 Any SAL_CALL VCLXSpinButton::getProperty( const ::rtl::OUString& PropertyName ) throw(RuntimeException)
297 SolarMutexGuard aGuard;
299 Any aReturn;
301 if ( GetWindow() )
303 sal_uInt16 nPropertyId = GetPropertyId( PropertyName );
304 switch ( nPropertyId )
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 aReturn = getButtonLikeFaceColor( GetWindow() );
310 break;
312 case BASEPROPERTY_SPINVALUE:
313 aReturn <<= (sal_Int32)getValue( );
314 break;
316 case BASEPROPERTY_SPINVALUE_MIN:
317 aReturn <<= (sal_Int32)getMinimum( );
318 break;
320 case BASEPROPERTY_SPINVALUE_MAX:
321 aReturn <<= (sal_Int32)getMaximum( );
322 break;
324 case BASEPROPERTY_SPININCREMENT:
325 aReturn <<= (sal_Int32)getSpinIncrement( );
326 break;
328 case BASEPROPERTY_ORIENTATION:
329 aReturn <<= (sal_Int32)
330 ( ( 0 != ( GetWindow()->GetStyle() & WB_HSCROLL ) )
331 ? ScrollBarOrientation::HORIZONTAL
332 : ScrollBarOrientation::VERTICAL
334 break;
336 default:
337 aReturn = VCLXWindow::getProperty( PropertyName );
340 return aReturn;
343 //........................................................................
344 } // namespace toolkit
345 //........................................................................
347 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */