1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: vclxspinbutton.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_toolkit.hxx"
33 #include "toolkit/awt/vclxspinbutton.hxx"
34 #include "toolkit/helper/property.hxx"
35 #include <com/sun/star/awt/ScrollBarOrientation.hpp>
38 #include <tools/debug.hxx>
39 #include <vcl/spin.hxx>
43 void setButtonLikeFaceColor( Window
* _pWindow
, const ::com::sun::star::uno::Any
& _rColorValue
);
44 ::com::sun::star::uno::Any
getButtonLikeFaceColor( const Window
* _pWindow
);
47 //........................................................................
50 //........................................................................
52 using namespace ::com::sun::star::uno
;
53 using namespace ::com::sun::star::awt
;
54 using namespace ::com::sun::star::lang
;
55 using namespace ::com::sun::star::beans
;
57 //--------------------------------------------------------------------
60 void lcl_modifyStyle( Window
* _pWindow
, WinBits _nStyleBits
, sal_Bool _bShouldBePresent
)
62 WinBits nStyle
= _pWindow
->GetStyle();
63 if ( _bShouldBePresent
)
64 nStyle
|= _nStyleBits
;
66 nStyle
&= ~_nStyleBits
;
67 _pWindow
->SetStyle( nStyle
);
71 //====================================================================
73 //====================================================================
74 DBG_NAME( VCLXSpinButton
)
75 //--------------------------------------------------------------------
76 VCLXSpinButton::VCLXSpinButton()
77 :maAdjustmentListeners( *this )
79 DBG_CTOR( VCLXSpinButton
, NULL
);
82 //--------------------------------------------------------------------
83 VCLXSpinButton::~VCLXSpinButton()
85 DBG_DTOR( VCLXSpinButton
, NULL
);
88 //--------------------------------------------------------------------
89 IMPLEMENT_FORWARD_XINTERFACE2( VCLXSpinButton
, VCLXWindow
, VCLXSpinButton_Base
)
91 //--------------------------------------------------------------------
92 IMPLEMENT_FORWARD_XTYPEPROVIDER2( VCLXSpinButton
, VCLXWindow
, VCLXSpinButton_Base
)
94 //--------------------------------------------------------------------
95 void SAL_CALL
VCLXSpinButton::dispose( ) throw(RuntimeException
)
98 ::vos::OGuard
aGuard( GetMutex() );
100 EventObject aDisposeEvent
;
101 aDisposeEvent
.Source
= *this;
102 maAdjustmentListeners
.disposeAndClear( aDisposeEvent
);
105 VCLXWindow::dispose();
108 //--------------------------------------------------------------------
109 void SAL_CALL
VCLXSpinButton::addAdjustmentListener( const Reference
< XAdjustmentListener
>& listener
) throw (RuntimeException
)
112 maAdjustmentListeners
.addInterface( listener
);
115 //--------------------------------------------------------------------
116 void SAL_CALL
VCLXSpinButton::removeAdjustmentListener( const Reference
< XAdjustmentListener
>& listener
) throw (RuntimeException
)
119 maAdjustmentListeners
.removeInterface( listener
);
124 typedef void (SpinButton::*SetSpinButtonValue
) (long);
125 typedef long (SpinButton::*GetSpinButtonValue
) (void) const;
127 //................................................................
128 void lcl_setSpinButtonValue( ::vos::IMutex
& _rMutex
, Window
* _pWindow
, SetSpinButtonValue _pSetter
, sal_Int32 _nValue
)
130 ::vos::OGuard
aGuard( _rMutex
);
132 SpinButton
* pSpinButton
= static_cast< SpinButton
* >( _pWindow
);
134 (pSpinButton
->*_pSetter
)( _nValue
);
137 //................................................................
138 sal_Int32
lcl_getSpinButtonValue( ::vos::IMutex
& _rMutex
, const Window
* _pWindow
, GetSpinButtonValue _pGetter
)
140 ::vos::OGuard
aGuard( _rMutex
);
142 sal_Int32 nValue
= 0;
144 const SpinButton
* pSpinButton
= static_cast< const SpinButton
* >( _pWindow
);
146 nValue
= (pSpinButton
->*_pGetter
)( );
151 //--------------------------------------------------------------------
152 void SAL_CALL
VCLXSpinButton::setValue( sal_Int32 n
) throw (RuntimeException
)
154 lcl_setSpinButtonValue( GetMutex(), GetWindow(), &SpinButton::SetValue
, n
);
157 //--------------------------------------------------------------------
158 void SAL_CALL
VCLXSpinButton::setValues( sal_Int32 minValue
, sal_Int32 maxValue
, sal_Int32 currentValue
) throw (RuntimeException
)
160 ::vos::OGuard
aGuard( GetMutex() );
162 setMinimum( minValue
);
163 setMaximum( maxValue
);
164 setValue( currentValue
);
167 //--------------------------------------------------------------------
168 sal_Int32 SAL_CALL
VCLXSpinButton::getValue( ) throw (RuntimeException
)
170 return lcl_getSpinButtonValue( GetMutex(), GetWindow(), &SpinButton::GetValue
);
173 //--------------------------------------------------------------------
174 void SAL_CALL
VCLXSpinButton::setMinimum( sal_Int32 minValue
) throw (RuntimeException
)
176 lcl_setSpinButtonValue( GetMutex(), GetWindow(), &SpinButton::SetRangeMin
, minValue
);
179 //--------------------------------------------------------------------
180 void SAL_CALL
VCLXSpinButton::setMaximum( sal_Int32 maxValue
) throw (RuntimeException
)
182 lcl_setSpinButtonValue( GetMutex(), GetWindow(), &SpinButton::SetRangeMax
, maxValue
);
185 //--------------------------------------------------------------------
186 sal_Int32 SAL_CALL
VCLXSpinButton::getMinimum( ) throw (RuntimeException
)
188 return lcl_getSpinButtonValue( GetMutex(), GetWindow(), &SpinButton::GetRangeMin
);
191 //--------------------------------------------------------------------
192 sal_Int32 SAL_CALL
VCLXSpinButton::getMaximum( ) throw (RuntimeException
)
194 return lcl_getSpinButtonValue( GetMutex(), GetWindow(), &SpinButton::GetRangeMax
);
197 //--------------------------------------------------------------------
198 void SAL_CALL
VCLXSpinButton::setSpinIncrement( sal_Int32 spinIncrement
) throw (RuntimeException
)
200 lcl_setSpinButtonValue( GetMutex(), GetWindow(), &SpinButton::SetValueStep
, spinIncrement
);
203 //--------------------------------------------------------------------
204 sal_Int32 SAL_CALL
VCLXSpinButton::getSpinIncrement( ) throw (RuntimeException
)
206 return lcl_getSpinButtonValue( GetMutex(), GetWindow(), &SpinButton::GetValueStep
);
209 //--------------------------------------------------------------------
210 void SAL_CALL
VCLXSpinButton::setOrientation( sal_Int32 orientation
) throw (NoSupportException
, RuntimeException
)
212 ::vos::OGuard
aGuard( GetMutex() );
214 lcl_modifyStyle( GetWindow(), WB_HSCROLL
, orientation
== ScrollBarOrientation::HORIZONTAL
);
217 //--------------------------------------------------------------------
218 sal_Int32 SAL_CALL
VCLXSpinButton::getOrientation( ) throw (RuntimeException
)
220 return ( 0 != ( GetWindow()->GetStyle() & WB_HSCROLL
) )
221 ? ScrollBarOrientation::HORIZONTAL
222 : ScrollBarOrientation::VERTICAL
;
225 //--------------------------------------------------------------------
226 void VCLXSpinButton::ProcessWindowEvent( const VclWindowEvent
& _rVclWindowEvent
)
228 ::vos::OClearableGuard
aGuard( GetMutex() );
229 Reference
< XSpinValue
> xKeepAlive( this );
230 SpinButton
* pSpinButton
= static_cast< SpinButton
* >( GetWindow() );
234 switch ( _rVclWindowEvent
.GetId() )
236 case VCLEVENT_SPINBUTTON_UP
:
237 case VCLEVENT_SPINBUTTON_DOWN
:
238 if ( maAdjustmentListeners
.getLength() )
240 AdjustmentEvent aEvent
;
241 aEvent
.Source
= *this;
242 aEvent
.Value
= pSpinButton
->GetValue();
245 maAdjustmentListeners
.adjustmentValueChanged( aEvent
);
252 VCLXWindow::ProcessWindowEvent( _rVclWindowEvent
);
257 //--------------------------------------------------------------------
258 void SAL_CALL
VCLXSpinButton::setProperty( const ::rtl::OUString
& PropertyName
, const Any
& Value
) throw(RuntimeException
)
260 ::vos::OGuard
aGuard( GetMutex() );
262 sal_Int32 nValue
= 0;
263 sal_Bool bIsLongValue
= ( Value
>>= nValue
);
267 sal_uInt16 nPropertyId
= GetPropertyId( PropertyName
);
268 switch ( nPropertyId
)
270 case BASEPROPERTY_BACKGROUNDCOLOR
:
271 // the default implementation of the base class doesn't work here, since our
272 // interpretation for this property is slightly different
273 setButtonLikeFaceColor( GetWindow(), Value
);
276 case BASEPROPERTY_SPINVALUE
:
281 case BASEPROPERTY_SPINVALUE_MIN
:
283 setMinimum( nValue
);
286 case BASEPROPERTY_SPINVALUE_MAX
:
288 setMaximum( nValue
);
291 case BASEPROPERTY_SPININCREMENT
:
293 setSpinIncrement( nValue
);
296 case BASEPROPERTY_ORIENTATION
:
298 lcl_modifyStyle( GetWindow(), WB_HSCROLL
, nValue
== ScrollBarOrientation::HORIZONTAL
);
302 VCLXWindow::setProperty( PropertyName
, Value
);
307 //--------------------------------------------------------------------
308 Any SAL_CALL
VCLXSpinButton::getProperty( const ::rtl::OUString
& PropertyName
) throw(RuntimeException
)
310 ::vos::OGuard
aGuard( GetMutex() );
316 sal_uInt16 nPropertyId
= GetPropertyId( PropertyName
);
317 switch ( nPropertyId
)
319 case BASEPROPERTY_BACKGROUNDCOLOR
:
320 // the default implementation of the base class doesn't work here, since our
321 // interpretation for this property is slightly different
322 aReturn
= getButtonLikeFaceColor( GetWindow() );
325 case BASEPROPERTY_SPINVALUE
:
326 aReturn
<<= (sal_Int32
)getValue( );
329 case BASEPROPERTY_SPINVALUE_MIN
:
330 aReturn
<<= (sal_Int32
)getMinimum( );
333 case BASEPROPERTY_SPINVALUE_MAX
:
334 aReturn
<<= (sal_Int32
)getMaximum( );
337 case BASEPROPERTY_SPININCREMENT
:
338 aReturn
<<= (sal_Int32
)getSpinIncrement( );
341 case BASEPROPERTY_ORIENTATION
:
342 aReturn
<<= (sal_Int32
)
343 ( ( 0 != ( GetWindow()->GetStyle() & WB_HSCROLL
) )
344 ? ScrollBarOrientation::HORIZONTAL
345 : ScrollBarOrientation::VERTICAL
350 aReturn
= VCLXWindow::getProperty( PropertyName
);
356 //........................................................................
357 } // namespace toolkit
358 //........................................................................