1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
31 void setButtonLikeFaceColor( Window
* _pWindow
, const ::com::sun::star::uno::Any
& _rColorValue
);
32 ::com::sun::star::uno::Any
getButtonLikeFaceColor( const Window
* _pWindow
);
35 //........................................................................
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 //--------------------------------------------------------------------
48 void lcl_modifyStyle( Window
* _pWindow
, WinBits _nStyleBits
, sal_Bool _bShouldBePresent
)
50 WinBits nStyle
= _pWindow
->GetStyle();
51 if ( _bShouldBePresent
)
52 nStyle
|= _nStyleBits
;
54 nStyle
&= ~_nStyleBits
;
55 _pWindow
->SetStyle( nStyle
);
59 //====================================================================
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
)
100 maAdjustmentListeners
.addInterface( listener
);
103 //--------------------------------------------------------------------
104 void SAL_CALL
VCLXSpinButton::removeAdjustmentListener( const Reference
< XAdjustmentListener
>& listener
) throw (RuntimeException
)
107 maAdjustmentListeners
.removeInterface( listener
);
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
);
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
);
133 nValue
= (pSpinButton
->*_pGetter
)( );
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() );
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();
232 maAdjustmentListeners
.adjustmentValueChanged( aEvent
);
239 VCLXWindow::ProcessWindowEvent( _rVclWindowEvent
);
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
);
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
);
263 case BASEPROPERTY_SPINVALUE
:
268 case BASEPROPERTY_SPINVALUE_MIN
:
270 setMinimum( nValue
);
273 case BASEPROPERTY_SPINVALUE_MAX
:
275 setMaximum( nValue
);
278 case BASEPROPERTY_SPININCREMENT
:
280 setSpinIncrement( nValue
);
283 case BASEPROPERTY_ORIENTATION
:
285 lcl_modifyStyle( GetWindow(), WB_HSCROLL
, nValue
== ScrollBarOrientation::HORIZONTAL
);
289 VCLXWindow::setProperty( PropertyName
, Value
);
294 //--------------------------------------------------------------------
295 Any SAL_CALL
VCLXSpinButton::getProperty( const ::rtl::OUString
& PropertyName
) throw(RuntimeException
)
297 SolarMutexGuard aGuard
;
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() );
312 case BASEPROPERTY_SPINVALUE
:
313 aReturn
<<= (sal_Int32
)getValue( );
316 case BASEPROPERTY_SPINVALUE_MIN
:
317 aReturn
<<= (sal_Int32
)getMinimum( );
320 case BASEPROPERTY_SPINVALUE_MAX
:
321 aReturn
<<= (sal_Int32
)getMaximum( );
324 case BASEPROPERTY_SPININCREMENT
:
325 aReturn
<<= (sal_Int32
)getSpinIncrement( );
328 case BASEPROPERTY_ORIENTATION
:
329 aReturn
<<= (sal_Int32
)
330 ( ( 0 != ( GetWindow()->GetStyle() & WB_HSCROLL
) )
331 ? ScrollBarOrientation::HORIZONTAL
332 : ScrollBarOrientation::VERTICAL
337 aReturn
= VCLXWindow::getProperty( PropertyName
);
343 //........................................................................
344 } // namespace toolkit
345 //........................................................................
347 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */