Version 3.6.0.2, tag libreoffice-3.6.0.2
[LibreOffice.git] / toolkit / source / awt / vclxspinbutton.cxx
blobeb8e9975ca0d8d0c683ed046e62498bd60cabac5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "toolkit/awt/vclxspinbutton.hxx"
30 #include "toolkit/helper/property.hxx"
31 #include <com/sun/star/awt/ScrollBarOrientation.hpp>
34 #include <tools/debug.hxx>
35 #include <vcl/spin.hxx>
36 #include <vcl/svapp.hxx>
38 namespace toolkit
40 void setButtonLikeFaceColor( Window* _pWindow, const ::com::sun::star::uno::Any& _rColorValue );
41 ::com::sun::star::uno::Any getButtonLikeFaceColor( const Window* _pWindow );
44 //........................................................................
45 namespace toolkit
47 //........................................................................
49 using namespace ::com::sun::star::uno;
50 using namespace ::com::sun::star::awt;
51 using namespace ::com::sun::star::lang;
52 using namespace ::com::sun::star::beans;
54 //--------------------------------------------------------------------
55 namespace
57 void lcl_modifyStyle( Window* _pWindow, WinBits _nStyleBits, sal_Bool _bShouldBePresent )
59 WinBits nStyle = _pWindow->GetStyle();
60 if ( _bShouldBePresent )
61 nStyle |= _nStyleBits;
62 else
63 nStyle &= ~_nStyleBits;
64 _pWindow->SetStyle( nStyle );
68 //====================================================================
69 //= VCLXSpinButton
70 //====================================================================
71 DBG_NAME( VCLXSpinButton )
72 //--------------------------------------------------------------------
73 VCLXSpinButton::VCLXSpinButton()
74 :maAdjustmentListeners( *this )
76 DBG_CTOR( VCLXSpinButton, NULL );
79 //--------------------------------------------------------------------
80 VCLXSpinButton::~VCLXSpinButton()
82 DBG_DTOR( VCLXSpinButton, NULL );
85 //--------------------------------------------------------------------
86 IMPLEMENT_FORWARD_XINTERFACE2( VCLXSpinButton, VCLXWindow, VCLXSpinButton_Base )
88 //--------------------------------------------------------------------
89 IMPLEMENT_FORWARD_XTYPEPROVIDER2( VCLXSpinButton, VCLXWindow, VCLXSpinButton_Base )
91 //--------------------------------------------------------------------
92 void SAL_CALL VCLXSpinButton::dispose( ) throw(RuntimeException)
95 SolarMutexGuard aGuard;
97 EventObject aDisposeEvent;
98 aDisposeEvent.Source = *this;
99 maAdjustmentListeners.disposeAndClear( aDisposeEvent );
102 VCLXWindow::dispose();
105 //--------------------------------------------------------------------
106 void SAL_CALL VCLXSpinButton::addAdjustmentListener( const Reference< XAdjustmentListener >& listener ) throw (RuntimeException)
108 if ( listener.is() )
109 maAdjustmentListeners.addInterface( listener );
112 //--------------------------------------------------------------------
113 void SAL_CALL VCLXSpinButton::removeAdjustmentListener( const Reference< XAdjustmentListener >& listener ) throw (RuntimeException)
115 if ( listener.is() )
116 maAdjustmentListeners.removeInterface( listener );
119 namespace
121 typedef void (SpinButton::*SetSpinButtonValue) (long);
122 typedef long (SpinButton::*GetSpinButtonValue) (void) const;
124 //................................................................
125 void lcl_setSpinButtonValue(Window* _pWindow, SetSpinButtonValue _pSetter, sal_Int32 _nValue )
127 SolarMutexGuard aGuard;
128 SpinButton* pSpinButton = static_cast< SpinButton* >( _pWindow );
129 if ( pSpinButton )
130 (pSpinButton->*_pSetter)( _nValue );
133 //................................................................
134 sal_Int32 lcl_getSpinButtonValue(const Window* _pWindow, GetSpinButtonValue _pGetter )
136 SolarMutexGuard aGuard;
138 sal_Int32 nValue = 0;
140 const SpinButton* pSpinButton = static_cast< const SpinButton* >( _pWindow );
141 if ( pSpinButton )
142 nValue = (pSpinButton->*_pGetter)( );
143 return nValue;
147 //--------------------------------------------------------------------
148 void SAL_CALL VCLXSpinButton::setValue( sal_Int32 n ) throw (RuntimeException)
150 lcl_setSpinButtonValue( GetWindow(), &SpinButton::SetValue, n );
153 //--------------------------------------------------------------------
154 void SAL_CALL VCLXSpinButton::setValues( sal_Int32 minValue, sal_Int32 maxValue, sal_Int32 currentValue ) throw (RuntimeException)
156 SolarMutexGuard aGuard;
158 setMinimum( minValue );
159 setMaximum( maxValue );
160 setValue( currentValue );
163 //--------------------------------------------------------------------
164 sal_Int32 SAL_CALL VCLXSpinButton::getValue( ) throw (RuntimeException)
166 return lcl_getSpinButtonValue( GetWindow(), &SpinButton::GetValue );
169 //--------------------------------------------------------------------
170 void SAL_CALL VCLXSpinButton::setMinimum( sal_Int32 minValue ) throw (RuntimeException)
172 lcl_setSpinButtonValue( GetWindow(), &SpinButton::SetRangeMin, minValue );
175 //--------------------------------------------------------------------
176 void SAL_CALL VCLXSpinButton::setMaximum( sal_Int32 maxValue ) throw (RuntimeException)
178 lcl_setSpinButtonValue( GetWindow(), &SpinButton::SetRangeMax, maxValue );
181 //--------------------------------------------------------------------
182 sal_Int32 SAL_CALL VCLXSpinButton::getMinimum( ) throw (RuntimeException)
184 return lcl_getSpinButtonValue( GetWindow(), &SpinButton::GetRangeMin );
187 //--------------------------------------------------------------------
188 sal_Int32 SAL_CALL VCLXSpinButton::getMaximum( ) throw (RuntimeException)
190 return lcl_getSpinButtonValue( GetWindow(), &SpinButton::GetRangeMax );
193 //--------------------------------------------------------------------
194 void SAL_CALL VCLXSpinButton::setSpinIncrement( sal_Int32 spinIncrement ) throw (RuntimeException)
196 lcl_setSpinButtonValue( GetWindow(), &SpinButton::SetValueStep, spinIncrement );
199 //--------------------------------------------------------------------
200 sal_Int32 SAL_CALL VCLXSpinButton::getSpinIncrement( ) throw (RuntimeException)
202 return lcl_getSpinButtonValue( GetWindow(), &SpinButton::GetValueStep );
205 //--------------------------------------------------------------------
206 void SAL_CALL VCLXSpinButton::setOrientation( sal_Int32 orientation ) throw (NoSupportException, RuntimeException)
208 SolarMutexGuard aGuard;
210 lcl_modifyStyle( GetWindow(), WB_HSCROLL, orientation == ScrollBarOrientation::HORIZONTAL );
213 //--------------------------------------------------------------------
214 sal_Int32 SAL_CALL VCLXSpinButton::getOrientation( ) throw (RuntimeException)
216 return ( 0 != ( GetWindow()->GetStyle() & WB_HSCROLL ) )
217 ? ScrollBarOrientation::HORIZONTAL
218 : ScrollBarOrientation::VERTICAL;
221 //--------------------------------------------------------------------
222 void VCLXSpinButton::ProcessWindowEvent( const VclWindowEvent& _rVclWindowEvent )
224 SolarMutexClearableGuard aGuard;
225 Reference< XSpinValue > xKeepAlive( this );
226 SpinButton* pSpinButton = static_cast< SpinButton* >( GetWindow() );
227 if ( !pSpinButton )
228 return;
230 switch ( _rVclWindowEvent.GetId() )
232 case VCLEVENT_SPINBUTTON_UP:
233 case VCLEVENT_SPINBUTTON_DOWN:
234 if ( maAdjustmentListeners.getLength() )
236 AdjustmentEvent aEvent;
237 aEvent.Source = *this;
238 aEvent.Value = pSpinButton->GetValue();
240 aGuard.clear();
241 maAdjustmentListeners.adjustmentValueChanged( aEvent );
243 break;
245 default:
246 xKeepAlive.clear();
247 aGuard.clear();
248 VCLXWindow::ProcessWindowEvent( _rVclWindowEvent );
249 break;
253 //--------------------------------------------------------------------
254 void SAL_CALL VCLXSpinButton::setProperty( const ::rtl::OUString& PropertyName, const Any& Value ) throw(RuntimeException)
256 SolarMutexGuard aGuard;
258 sal_Int32 nValue = 0;
259 sal_Bool bIsLongValue = ( Value >>= nValue );
261 if ( GetWindow() )
263 sal_uInt16 nPropertyId = GetPropertyId( PropertyName );
264 switch ( nPropertyId )
266 case BASEPROPERTY_BACKGROUNDCOLOR:
267 // the default implementation of the base class doesn't work here, since our
268 // interpretation for this property is slightly different
269 setButtonLikeFaceColor( GetWindow(), Value);
270 break;
272 case BASEPROPERTY_SPINVALUE:
273 if ( bIsLongValue )
274 setValue( nValue );
275 break;
277 case BASEPROPERTY_SPINVALUE_MIN:
278 if ( bIsLongValue )
279 setMinimum( nValue );
280 break;
282 case BASEPROPERTY_SPINVALUE_MAX:
283 if ( bIsLongValue )
284 setMaximum( nValue );
285 break;
287 case BASEPROPERTY_SPININCREMENT:
288 if ( bIsLongValue )
289 setSpinIncrement( nValue );
290 break;
292 case BASEPROPERTY_ORIENTATION:
293 if ( bIsLongValue )
294 lcl_modifyStyle( GetWindow(), WB_HSCROLL, nValue == ScrollBarOrientation::HORIZONTAL );
295 break;
297 default:
298 VCLXWindow::setProperty( PropertyName, Value );
303 //--------------------------------------------------------------------
304 Any SAL_CALL VCLXSpinButton::getProperty( const ::rtl::OUString& PropertyName ) throw(RuntimeException)
306 SolarMutexGuard aGuard;
308 Any aReturn;
310 if ( GetWindow() )
312 sal_uInt16 nPropertyId = GetPropertyId( PropertyName );
313 switch ( nPropertyId )
315 case BASEPROPERTY_BACKGROUNDCOLOR:
316 // the default implementation of the base class doesn't work here, since our
317 // interpretation for this property is slightly different
318 aReturn = getButtonLikeFaceColor( GetWindow() );
319 break;
321 case BASEPROPERTY_SPINVALUE:
322 aReturn <<= (sal_Int32)getValue( );
323 break;
325 case BASEPROPERTY_SPINVALUE_MIN:
326 aReturn <<= (sal_Int32)getMinimum( );
327 break;
329 case BASEPROPERTY_SPINVALUE_MAX:
330 aReturn <<= (sal_Int32)getMaximum( );
331 break;
333 case BASEPROPERTY_SPININCREMENT:
334 aReturn <<= (sal_Int32)getSpinIncrement( );
335 break;
337 case BASEPROPERTY_ORIENTATION:
338 aReturn <<= (sal_Int32)
339 ( ( 0 != ( GetWindow()->GetStyle() & WB_HSCROLL ) )
340 ? ScrollBarOrientation::HORIZONTAL
341 : ScrollBarOrientation::VERTICAL
343 break;
345 default:
346 aReturn = VCLXWindow::getProperty( PropertyName );
349 return aReturn;
352 //........................................................................
353 } // namespace toolkit
354 //........................................................................
356 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */