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>
24 #include <vcl/spin.hxx>
25 #include <vcl/svapp.hxx>
26 #include "vclxwindows_internal.hxx"
32 using namespace ::com::sun::star::uno
;
33 using namespace ::com::sun::star::awt
;
34 using namespace ::com::sun::star::lang
;
35 using namespace ::com::sun::star::beans
;
40 void lcl_modifyStyle( vcl::Window
* _pWindow
, WinBits _nStyleBits
, bool _bShouldBePresent
)
42 WinBits nStyle
= _pWindow
->GetStyle();
43 if ( _bShouldBePresent
)
44 nStyle
|= _nStyleBits
;
46 nStyle
&= ~_nStyleBits
;
47 _pWindow
->SetStyle( nStyle
);
51 VCLXSpinButton::VCLXSpinButton()
52 :maAdjustmentListeners( *this )
57 VCLXSpinButton::~VCLXSpinButton()
62 IMPLEMENT_FORWARD_XINTERFACE2( VCLXSpinButton
, VCLXWindow
, VCLXSpinButton_Base
)
65 IMPLEMENT_FORWARD_XTYPEPROVIDER2( VCLXSpinButton
, VCLXWindow
, VCLXSpinButton_Base
)
68 void SAL_CALL
VCLXSpinButton::dispose( )
71 SolarMutexGuard aGuard
;
73 EventObject aDisposeEvent
;
74 aDisposeEvent
.Source
= *this;
75 maAdjustmentListeners
.disposeAndClear( aDisposeEvent
);
78 VCLXWindow::dispose();
82 void SAL_CALL
VCLXSpinButton::addAdjustmentListener( const Reference
< XAdjustmentListener
>& listener
)
85 maAdjustmentListeners
.addInterface( listener
);
89 void SAL_CALL
VCLXSpinButton::removeAdjustmentListener( const Reference
< XAdjustmentListener
>& listener
)
92 maAdjustmentListeners
.removeInterface( listener
);
97 typedef void (SpinButton::*SetSpinButtonValue
) (long);
98 typedef long (SpinButton::*GetSpinButtonValue
) () const;
101 void lcl_setSpinButtonValue(vcl::Window
* _pWindow
, SetSpinButtonValue _pSetter
, sal_Int32 _nValue
)
103 SolarMutexGuard aGuard
;
104 SpinButton
* pSpinButton
= static_cast< SpinButton
* >( _pWindow
);
106 (pSpinButton
->*_pSetter
)( _nValue
);
110 sal_Int32
lcl_getSpinButtonValue(const vcl::Window
* _pWindow
, GetSpinButtonValue _pGetter
)
112 SolarMutexGuard aGuard
;
114 sal_Int32 nValue
= 0;
116 const SpinButton
* pSpinButton
= static_cast< const SpinButton
* >( _pWindow
);
118 nValue
= (pSpinButton
->*_pGetter
)( );
124 void SAL_CALL
VCLXSpinButton::setValue( sal_Int32 n
)
126 lcl_setSpinButtonValue( GetWindow(), &SpinButton::SetValue
, n
);
130 void SAL_CALL
VCLXSpinButton::setValues( sal_Int32 minValue
, sal_Int32 maxValue
, sal_Int32 currentValue
)
132 SolarMutexGuard aGuard
;
134 setMinimum( minValue
);
135 setMaximum( maxValue
);
136 setValue( currentValue
);
140 sal_Int32 SAL_CALL
VCLXSpinButton::getValue( )
142 return lcl_getSpinButtonValue( GetWindow(), &SpinButton::GetValue
);
146 void SAL_CALL
VCLXSpinButton::setMinimum( sal_Int32 minValue
)
148 lcl_setSpinButtonValue( GetWindow(), &SpinButton::SetRangeMin
, minValue
);
152 void SAL_CALL
VCLXSpinButton::setMaximum( sal_Int32 maxValue
)
154 lcl_setSpinButtonValue( GetWindow(), &SpinButton::SetRangeMax
, maxValue
);
158 sal_Int32 SAL_CALL
VCLXSpinButton::getMinimum( )
160 return lcl_getSpinButtonValue( GetWindow(), &SpinButton::GetRangeMin
);
164 sal_Int32 SAL_CALL
VCLXSpinButton::getMaximum( )
166 return lcl_getSpinButtonValue( GetWindow(), &SpinButton::GetRangeMax
);
170 void SAL_CALL
VCLXSpinButton::setSpinIncrement( sal_Int32 spinIncrement
)
172 lcl_setSpinButtonValue( GetWindow(), &SpinButton::SetValueStep
, spinIncrement
);
176 sal_Int32 SAL_CALL
VCLXSpinButton::getSpinIncrement( )
178 return lcl_getSpinButtonValue( GetWindow(), &SpinButton::GetValueStep
);
182 void SAL_CALL
VCLXSpinButton::setOrientation( sal_Int32 orientation
)
184 SolarMutexGuard aGuard
;
186 lcl_modifyStyle( GetWindow(), WB_HSCROLL
, orientation
== ScrollBarOrientation::HORIZONTAL
);
190 sal_Int32 SAL_CALL
VCLXSpinButton::getOrientation( )
192 return ( 0 != ( GetWindow()->GetStyle() & WB_HSCROLL
) )
193 ? ScrollBarOrientation::HORIZONTAL
194 : ScrollBarOrientation::VERTICAL
;
198 void VCLXSpinButton::ProcessWindowEvent( const VclWindowEvent
& _rVclWindowEvent
)
200 SolarMutexClearableGuard aGuard
;
201 Reference
< XSpinValue
> xKeepAlive( this );
202 VclPtr
<SpinButton
> pSpinButton
= GetAs
<SpinButton
>();
206 switch ( _rVclWindowEvent
.GetId() )
208 case VclEventId::SpinbuttonUp
:
209 case VclEventId::SpinbuttonDown
:
210 if ( maAdjustmentListeners
.getLength() )
212 AdjustmentEvent aEvent
;
213 aEvent
.Source
= *this;
214 aEvent
.Value
= pSpinButton
->GetValue();
217 maAdjustmentListeners
.adjustmentValueChanged( aEvent
);
224 VCLXWindow::ProcessWindowEvent( _rVclWindowEvent
);
230 void SAL_CALL
VCLXSpinButton::setProperty( const OUString
& PropertyName
, const Any
& Value
)
232 SolarMutexGuard aGuard
;
234 sal_Int32 nValue
= 0;
235 bool bIsLongValue
= ( Value
>>= nValue
);
239 sal_uInt16 nPropertyId
= GetPropertyId( PropertyName
);
240 switch ( nPropertyId
)
242 case BASEPROPERTY_BACKGROUNDCOLOR
:
243 // the default implementation of the base class doesn't work here, since our
244 // interpretation for this property is slightly different
245 setButtonLikeFaceColor( GetWindow(), Value
);
248 case BASEPROPERTY_SPINVALUE
:
253 case BASEPROPERTY_SPINVALUE_MIN
:
255 setMinimum( nValue
);
258 case BASEPROPERTY_SPINVALUE_MAX
:
260 setMaximum( nValue
);
263 case BASEPROPERTY_SPININCREMENT
:
265 setSpinIncrement( nValue
);
268 case BASEPROPERTY_ORIENTATION
:
270 lcl_modifyStyle( GetWindow(), WB_HSCROLL
, nValue
== ScrollBarOrientation::HORIZONTAL
);
274 VCLXWindow::setProperty( PropertyName
, Value
);
280 Any SAL_CALL
VCLXSpinButton::getProperty( const OUString
& PropertyName
)
282 SolarMutexGuard aGuard
;
288 sal_uInt16 nPropertyId
= GetPropertyId( PropertyName
);
289 switch ( nPropertyId
)
291 case BASEPROPERTY_BACKGROUNDCOLOR
:
292 // the default implementation of the base class doesn't work here, since our
293 // interpretation for this property is slightly different
294 aReturn
= getButtonLikeFaceColor( GetWindow() );
297 case BASEPROPERTY_SPINVALUE
:
298 aReturn
<<= getValue( );
301 case BASEPROPERTY_SPINVALUE_MIN
:
302 aReturn
<<= getMinimum( );
305 case BASEPROPERTY_SPINVALUE_MAX
:
306 aReturn
<<= getMaximum( );
309 case BASEPROPERTY_SPININCREMENT
:
310 aReturn
<<= getSpinIncrement( );
313 case BASEPROPERTY_ORIENTATION
:
314 aReturn
<<= static_cast<sal_Int32
>( ( 0 != ( GetWindow()->GetStyle() & WB_HSCROLL
) )
315 ? ScrollBarOrientation::HORIZONTAL
316 : ScrollBarOrientation::VERTICAL
321 aReturn
= VCLXWindow::getProperty( PropertyName
);
328 } // namespace toolkit
331 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */