Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
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.
15 : : *
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).
21 : : *
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.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "toolkit/awt/vclxspinbutton.hxx"
30 : : #include "toolkit/helper/property.hxx"
31 : : #include <com/sun/star/awt/ScrollBarOrientation.hpp>
32 : :
33 : :
34 : : #include <tools/debug.hxx>
35 : : #include <vcl/spin.hxx>
36 : : #include <vcl/svapp.hxx>
37 : :
38 : : namespace toolkit
39 : : {
40 : : void setButtonLikeFaceColor( Window* _pWindow, const ::com::sun::star::uno::Any& _rColorValue );
41 : : ::com::sun::star::uno::Any getButtonLikeFaceColor( const Window* _pWindow );
42 : : }
43 : :
44 : : //........................................................................
45 : : namespace toolkit
46 : : {
47 : : //........................................................................
48 : :
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;
53 : :
54 : : //--------------------------------------------------------------------
55 : : namespace
56 : : {
57 : 2 : void lcl_modifyStyle( Window* _pWindow, WinBits _nStyleBits, sal_Bool _bShouldBePresent )
58 : : {
59 : 2 : WinBits nStyle = _pWindow->GetStyle();
60 [ + - ]: 2 : if ( _bShouldBePresent )
61 : 2 : nStyle |= _nStyleBits;
62 : : else
63 : 0 : nStyle &= ~_nStyleBits;
64 : 2 : _pWindow->SetStyle( nStyle );
65 : 2 : }
66 : : }
67 : :
68 : : //====================================================================
69 : : //= VCLXSpinButton
70 : : //====================================================================
71 : : DBG_NAME( VCLXSpinButton )
72 : : //--------------------------------------------------------------------
73 : 2 : VCLXSpinButton::VCLXSpinButton()
74 [ + - ]: 2 : :maAdjustmentListeners( *this )
75 : : {
76 : : DBG_CTOR( VCLXSpinButton, NULL );
77 : 2 : }
78 : :
79 : : //--------------------------------------------------------------------
80 [ + - ]: 2 : VCLXSpinButton::~VCLXSpinButton()
81 : : {
82 : : DBG_DTOR( VCLXSpinButton, NULL );
83 [ - + ]: 4 : }
84 : :
85 : : //--------------------------------------------------------------------
86 [ + + ][ + - ]: 1155 : IMPLEMENT_FORWARD_XINTERFACE2( VCLXSpinButton, VCLXWindow, VCLXSpinButton_Base )
87 : :
88 : : //--------------------------------------------------------------------
89 [ # # ][ # # ]: 0 : IMPLEMENT_FORWARD_XTYPEPROVIDER2( VCLXSpinButton, VCLXWindow, VCLXSpinButton_Base )
[ # # ]
90 : :
91 : : //--------------------------------------------------------------------
92 : 4 : void SAL_CALL VCLXSpinButton::dispose( ) throw(RuntimeException)
93 : : {
94 : : {
95 [ + - ]: 4 : SolarMutexGuard aGuard;
96 : :
97 [ + - ]: 4 : EventObject aDisposeEvent;
98 [ + - ][ + - ]: 4 : aDisposeEvent.Source = *this;
99 [ + - ][ + - ]: 4 : maAdjustmentListeners.disposeAndClear( aDisposeEvent );
[ + - ]
100 : : }
101 : :
102 : 4 : VCLXWindow::dispose();
103 : 4 : }
104 : :
105 : : //--------------------------------------------------------------------
106 : 4 : void SAL_CALL VCLXSpinButton::addAdjustmentListener( const Reference< XAdjustmentListener >& listener ) throw (RuntimeException)
107 : : {
108 [ + - ]: 4 : if ( listener.is() )
109 : 4 : maAdjustmentListeners.addInterface( listener );
110 : 4 : }
111 : :
112 : : //--------------------------------------------------------------------
113 : 0 : void SAL_CALL VCLXSpinButton::removeAdjustmentListener( const Reference< XAdjustmentListener >& listener ) throw (RuntimeException)
114 : : {
115 [ # # ]: 0 : if ( listener.is() )
116 : 0 : maAdjustmentListeners.removeInterface( listener );
117 : 0 : }
118 : :
119 : : namespace
120 : : {
121 : : typedef void (SpinButton::*SetSpinButtonValue) (long);
122 : : typedef long (SpinButton::*GetSpinButtonValue) (void) const;
123 : :
124 : : //................................................................
125 : 8 : void lcl_setSpinButtonValue(Window* _pWindow, SetSpinButtonValue _pSetter, sal_Int32 _nValue )
126 : : {
127 [ + - ]: 8 : SolarMutexGuard aGuard;
128 : 8 : SpinButton* pSpinButton = static_cast< SpinButton* >( _pWindow );
129 [ + - ]: 8 : if ( pSpinButton )
130 [ + - ][ + - ]: 8 : (pSpinButton->*_pSetter)( _nValue );
[ + - ]
131 : 8 : }
132 : :
133 : : //................................................................
134 : 0 : sal_Int32 lcl_getSpinButtonValue(const Window* _pWindow, GetSpinButtonValue _pGetter )
135 : : {
136 [ # # ]: 0 : SolarMutexGuard aGuard;
137 : :
138 : 0 : sal_Int32 nValue = 0;
139 : :
140 : 0 : const SpinButton* pSpinButton = static_cast< const SpinButton* >( _pWindow );
141 [ # # ]: 0 : if ( pSpinButton )
142 [ # # ][ # # ]: 0 : nValue = (pSpinButton->*_pGetter)( );
143 [ # # ]: 0 : return nValue;
144 : : }
145 : : }
146 : :
147 : : //--------------------------------------------------------------------
148 : 2 : void SAL_CALL VCLXSpinButton::setValue( sal_Int32 n ) throw (RuntimeException)
149 : : {
150 : 2 : lcl_setSpinButtonValue( GetWindow(), &SpinButton::SetValue, n );
151 : 2 : }
152 : :
153 : : //--------------------------------------------------------------------
154 : 0 : void SAL_CALL VCLXSpinButton::setValues( sal_Int32 minValue, sal_Int32 maxValue, sal_Int32 currentValue ) throw (RuntimeException)
155 : : {
156 [ # # ]: 0 : SolarMutexGuard aGuard;
157 : :
158 [ # # ]: 0 : setMinimum( minValue );
159 [ # # ]: 0 : setMaximum( maxValue );
160 [ # # ][ # # ]: 0 : setValue( currentValue );
161 : 0 : }
162 : :
163 : : //--------------------------------------------------------------------
164 : 0 : sal_Int32 SAL_CALL VCLXSpinButton::getValue( ) throw (RuntimeException)
165 : : {
166 : 0 : return lcl_getSpinButtonValue( GetWindow(), &SpinButton::GetValue );
167 : : }
168 : :
169 : : //--------------------------------------------------------------------
170 : 2 : void SAL_CALL VCLXSpinButton::setMinimum( sal_Int32 minValue ) throw (RuntimeException)
171 : : {
172 : 2 : lcl_setSpinButtonValue( GetWindow(), &SpinButton::SetRangeMin, minValue );
173 : 2 : }
174 : :
175 : : //--------------------------------------------------------------------
176 : 2 : void SAL_CALL VCLXSpinButton::setMaximum( sal_Int32 maxValue ) throw (RuntimeException)
177 : : {
178 : 2 : lcl_setSpinButtonValue( GetWindow(), &SpinButton::SetRangeMax, maxValue );
179 : 2 : }
180 : :
181 : : //--------------------------------------------------------------------
182 : 0 : sal_Int32 SAL_CALL VCLXSpinButton::getMinimum( ) throw (RuntimeException)
183 : : {
184 : 0 : return lcl_getSpinButtonValue( GetWindow(), &SpinButton::GetRangeMin );
185 : : }
186 : :
187 : : //--------------------------------------------------------------------
188 : 0 : sal_Int32 SAL_CALL VCLXSpinButton::getMaximum( ) throw (RuntimeException)
189 : : {
190 : 0 : return lcl_getSpinButtonValue( GetWindow(), &SpinButton::GetRangeMax );
191 : : }
192 : :
193 : : //--------------------------------------------------------------------
194 : 2 : void SAL_CALL VCLXSpinButton::setSpinIncrement( sal_Int32 spinIncrement ) throw (RuntimeException)
195 : : {
196 : 2 : lcl_setSpinButtonValue( GetWindow(), &SpinButton::SetValueStep, spinIncrement );
197 : 2 : }
198 : :
199 : : //--------------------------------------------------------------------
200 : 0 : sal_Int32 SAL_CALL VCLXSpinButton::getSpinIncrement( ) throw (RuntimeException)
201 : : {
202 : 0 : return lcl_getSpinButtonValue( GetWindow(), &SpinButton::GetValueStep );
203 : : }
204 : :
205 : : //--------------------------------------------------------------------
206 : 0 : void SAL_CALL VCLXSpinButton::setOrientation( sal_Int32 orientation ) throw (NoSupportException, RuntimeException)
207 : : {
208 [ # # ]: 0 : SolarMutexGuard aGuard;
209 : :
210 [ # # ][ # # ]: 0 : lcl_modifyStyle( GetWindow(), WB_HSCROLL, orientation == ScrollBarOrientation::HORIZONTAL );
211 : 0 : }
212 : :
213 : : //--------------------------------------------------------------------
214 : 0 : sal_Int32 SAL_CALL VCLXSpinButton::getOrientation( ) throw (RuntimeException)
215 : : {
216 : 0 : return ( 0 != ( GetWindow()->GetStyle() & WB_HSCROLL ) )
217 : : ? ScrollBarOrientation::HORIZONTAL
218 [ # # ]: 0 : : ScrollBarOrientation::VERTICAL;
219 : : }
220 : :
221 : : //--------------------------------------------------------------------
222 : 22 : void VCLXSpinButton::ProcessWindowEvent( const VclWindowEvent& _rVclWindowEvent )
223 : : {
224 [ + - ]: 22 : SolarMutexClearableGuard aGuard;
225 [ + - ]: 22 : Reference< XSpinValue > xKeepAlive( this );
226 : 22 : SpinButton* pSpinButton = static_cast< SpinButton* >( GetWindow() );
227 [ - + ]: 22 : if ( !pSpinButton )
228 : 22 : return;
229 : :
230 [ - + ]: 22 : switch ( _rVclWindowEvent.GetId() )
231 : : {
232 : : case VCLEVENT_SPINBUTTON_UP:
233 : : case VCLEVENT_SPINBUTTON_DOWN:
234 [ # # ][ # # ]: 0 : if ( maAdjustmentListeners.getLength() )
235 : : {
236 [ # # ]: 0 : AdjustmentEvent aEvent;
237 [ # # ][ # # ]: 0 : aEvent.Source = *this;
238 : 0 : aEvent.Value = pSpinButton->GetValue();
239 : :
240 [ # # ]: 0 : aGuard.clear();
241 [ # # ][ # # ]: 0 : maAdjustmentListeners.adjustmentValueChanged( aEvent );
242 : : }
243 : 0 : break;
244 : :
245 : : default:
246 : 22 : xKeepAlive.clear();
247 [ + - ]: 22 : aGuard.clear();
248 [ + - ]: 22 : VCLXWindow::ProcessWindowEvent( _rVclWindowEvent );
249 : 22 : break;
250 [ - + ][ + - ]: 22 : }
[ + - ]
251 : : }
252 : :
253 : : //--------------------------------------------------------------------
254 : 56 : void SAL_CALL VCLXSpinButton::setProperty( const ::rtl::OUString& PropertyName, const Any& Value ) throw(RuntimeException)
255 : : {
256 [ + - ]: 56 : SolarMutexGuard aGuard;
257 : :
258 : 56 : sal_Int32 nValue = 0;
259 : 56 : sal_Bool bIsLongValue = ( Value >>= nValue );
260 : :
261 [ + - ]: 56 : if ( GetWindow() )
262 : : {
263 [ + - ]: 56 : sal_uInt16 nPropertyId = GetPropertyId( PropertyName );
264 [ + + + + : 56 : switch ( nPropertyId )
+ + + ]
265 : : {
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 [ + - ]: 2 : setButtonLikeFaceColor( GetWindow(), Value);
270 : 2 : break;
271 : :
272 : : case BASEPROPERTY_SPINVALUE:
273 [ + - ]: 2 : if ( bIsLongValue )
274 [ + - ]: 2 : setValue( nValue );
275 : 2 : break;
276 : :
277 : : case BASEPROPERTY_SPINVALUE_MIN:
278 [ + - ]: 2 : if ( bIsLongValue )
279 [ + - ]: 2 : setMinimum( nValue );
280 : 2 : break;
281 : :
282 : : case BASEPROPERTY_SPINVALUE_MAX:
283 [ + - ]: 2 : if ( bIsLongValue )
284 [ + - ]: 2 : setMaximum( nValue );
285 : 2 : break;
286 : :
287 : : case BASEPROPERTY_SPININCREMENT:
288 [ + - ]: 2 : if ( bIsLongValue )
289 [ + - ]: 2 : setSpinIncrement( nValue );
290 : 2 : break;
291 : :
292 : : case BASEPROPERTY_ORIENTATION:
293 [ + - ]: 2 : if ( bIsLongValue )
294 [ + - ]: 2 : lcl_modifyStyle( GetWindow(), WB_HSCROLL, nValue == ScrollBarOrientation::HORIZONTAL );
295 : 2 : break;
296 : :
297 : : default:
298 [ + - ]: 56 : VCLXWindow::setProperty( PropertyName, Value );
299 : : }
300 [ + - ]: 56 : }
301 : 56 : }
302 : :
303 : : //--------------------------------------------------------------------
304 : 0 : Any SAL_CALL VCLXSpinButton::getProperty( const ::rtl::OUString& PropertyName ) throw(RuntimeException)
305 : : {
306 [ # # ]: 0 : SolarMutexGuard aGuard;
307 : :
308 : 0 : Any aReturn;
309 : :
310 [ # # ]: 0 : if ( GetWindow() )
311 : : {
312 [ # # ]: 0 : sal_uInt16 nPropertyId = GetPropertyId( PropertyName );
313 [ # # # # : 0 : switch ( nPropertyId )
# # # ]
314 : : {
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 [ # # ]: 0 : aReturn = getButtonLikeFaceColor( GetWindow() );
319 : 0 : break;
320 : :
321 : : case BASEPROPERTY_SPINVALUE:
322 [ # # ][ # # ]: 0 : aReturn <<= (sal_Int32)getValue( );
323 : 0 : break;
324 : :
325 : : case BASEPROPERTY_SPINVALUE_MIN:
326 [ # # ][ # # ]: 0 : aReturn <<= (sal_Int32)getMinimum( );
327 : 0 : break;
328 : :
329 : : case BASEPROPERTY_SPINVALUE_MAX:
330 [ # # ][ # # ]: 0 : aReturn <<= (sal_Int32)getMaximum( );
331 : 0 : break;
332 : :
333 : : case BASEPROPERTY_SPININCREMENT:
334 [ # # ][ # # ]: 0 : aReturn <<= (sal_Int32)getSpinIncrement( );
335 : 0 : break;
336 : :
337 : : case BASEPROPERTY_ORIENTATION:
338 : : aReturn <<= (sal_Int32)
339 [ # # ]: 0 : ( ( 0 != ( GetWindow()->GetStyle() & WB_HSCROLL ) )
340 : : ? ScrollBarOrientation::HORIZONTAL
341 : : : ScrollBarOrientation::VERTICAL
342 [ # # ][ # # ]: 0 : );
343 : 0 : break;
344 : :
345 : : default:
346 [ # # ]: 0 : aReturn = VCLXWindow::getProperty( PropertyName );
347 : : }
348 : : }
349 [ # # ]: 0 : return aReturn;
350 : : }
351 : :
352 : : //........................................................................
353 : : } // namespace toolkit
354 : : //........................................................................
355 : :
356 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|