/src/libreoffice/toolkit/source/controls/tkspinbutton.cxx
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
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/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
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 . |
18 | | */ |
19 | | |
20 | | #include <com/sun/star/awt/ScrollBarOrientation.hpp> |
21 | | #include <com/sun/star/awt/XSpinValue.hpp> |
22 | | #include <com/sun/star/awt/XAdjustmentListener.hpp> |
23 | | #include <com/sun/star/uno/XComponentContext.hpp> |
24 | | |
25 | | #include <comphelper/uno3.hxx> |
26 | | #include <cppuhelper/implbase2.hxx> |
27 | | #include <toolkit/controls/unocontrolmodel.hxx> |
28 | | #include <toolkit/controls/unocontrolbase.hxx> |
29 | | #include <helper/property.hxx> |
30 | | |
31 | | #include <helper/unopropertyarrayhelper.hxx> |
32 | | |
33 | | using namespace ::com::sun::star::uno; |
34 | | using namespace ::com::sun::star::awt; |
35 | | using namespace ::com::sun::star::lang; |
36 | | using namespace ::com::sun::star::beans; |
37 | | |
38 | | namespace { |
39 | | |
40 | | class UnoSpinButtonModel : public UnoControlModel |
41 | | { |
42 | | protected: |
43 | | css::uno::Any ImplGetDefaultValue( sal_uInt16 nPropId ) const override; |
44 | | ::cppu::IPropertyArrayHelper& getInfoHelper() override; |
45 | | |
46 | | public: |
47 | | explicit UnoSpinButtonModel( const css::uno::Reference< css::uno::XComponentContext >& i_factory ); |
48 | 0 | UnoSpinButtonModel(const UnoSpinButtonModel & rOther) : UnoControlModel(rOther) {} |
49 | | |
50 | 0 | rtl::Reference<UnoControlModel> Clone() const override { return new UnoSpinButtonModel( *this ); } |
51 | | |
52 | | // XMultiPropertySet |
53 | | css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) override; |
54 | | |
55 | | // XPersistObject |
56 | | OUString SAL_CALL getServiceName() override; |
57 | | |
58 | | // XServiceInfo |
59 | | OUString SAL_CALL getImplementationName( ) override; |
60 | | css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override; |
61 | | }; |
62 | | |
63 | | |
64 | | //= UnoSpinButtonControl |
65 | | |
66 | | |
67 | | typedef ::cppu::ImplHelper2 < css::awt::XAdjustmentListener |
68 | | , css::awt::XSpinValue |
69 | | > UnoSpinButtonControl_Base; |
70 | | |
71 | | class UnoSpinButtonControl :public UnoControlBase |
72 | | ,public UnoSpinButtonControl_Base |
73 | | { |
74 | | private: |
75 | | AdjustmentListenerMultiplexer maAdjustmentListeners; |
76 | | |
77 | | public: |
78 | | UnoSpinButtonControl(); |
79 | | OUString GetComponentServiceName() const override; |
80 | | |
81 | | DECLARE_UNO3_AGG_DEFAULTS( UnoSpinButtonControl, UnoControlBase ) |
82 | | css::uno::Any SAL_CALL queryAggregation( const css::uno::Type & rType ) override; |
83 | | |
84 | | void SAL_CALL createPeer( const css::uno::Reference< css::awt::XToolkit >& Toolkit, const css::uno::Reference< css::awt::XWindowPeer >& Parent ) override; |
85 | 0 | void SAL_CALL disposing( const css::lang::EventObject& Source ) override { UnoControlBase::disposing( Source ); } |
86 | | void SAL_CALL dispose( ) override; |
87 | | |
88 | | // XTypeProvider |
89 | | DECLARE_XTYPEPROVIDER() |
90 | | |
91 | | // XAdjustmentListener |
92 | | void SAL_CALL adjustmentValueChanged( const css::awt::AdjustmentEvent& rEvent ) override; |
93 | | |
94 | | // XSpinValue |
95 | | virtual void SAL_CALL addAdjustmentListener( const css::uno::Reference< css::awt::XAdjustmentListener >& listener ) override; |
96 | | virtual void SAL_CALL removeAdjustmentListener( const css::uno::Reference< css::awt::XAdjustmentListener >& listener ) override; |
97 | | virtual void SAL_CALL setValue( sal_Int32 value ) override; |
98 | | virtual void SAL_CALL setValues( sal_Int32 minValue, sal_Int32 maxValue, sal_Int32 currentValue ) override; |
99 | | virtual sal_Int32 SAL_CALL getValue( ) override; |
100 | | virtual void SAL_CALL setMinimum( sal_Int32 minValue ) override; |
101 | | virtual void SAL_CALL setMaximum( sal_Int32 maxValue ) override; |
102 | | virtual sal_Int32 SAL_CALL getMinimum( ) override; |
103 | | virtual sal_Int32 SAL_CALL getMaximum( ) override; |
104 | | virtual void SAL_CALL setSpinIncrement( sal_Int32 spinIncrement ) override; |
105 | | virtual sal_Int32 SAL_CALL getSpinIncrement( ) override; |
106 | | virtual void SAL_CALL setOrientation( sal_Int32 orientation ) override; |
107 | | virtual sal_Int32 SAL_CALL getOrientation( ) override; |
108 | | |
109 | | // XServiceInfo |
110 | | OUString SAL_CALL getImplementationName( ) override; |
111 | | css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override; |
112 | | }; |
113 | | |
114 | | |
115 | | //= UnoSpinButtonModel |
116 | | |
117 | | |
118 | | UnoSpinButtonModel::UnoSpinButtonModel( const css::uno::Reference< css::uno::XComponentContext >& i_factory ) |
119 | 0 | :UnoControlModel( i_factory ) |
120 | 0 | { |
121 | 0 | ImplRegisterProperty( BASEPROPERTY_BACKGROUNDCOLOR ); |
122 | 0 | ImplRegisterProperty( BASEPROPERTY_BORDER ); |
123 | 0 | ImplRegisterProperty( BASEPROPERTY_BORDERCOLOR ); |
124 | 0 | ImplRegisterProperty( BASEPROPERTY_DEFAULTCONTROL ); |
125 | 0 | ImplRegisterProperty( BASEPROPERTY_ENABLED ); |
126 | 0 | ImplRegisterProperty( BASEPROPERTY_ENABLEVISIBLE ); |
127 | 0 | ImplRegisterProperty( BASEPROPERTY_HELPTEXT ); |
128 | 0 | ImplRegisterProperty( BASEPROPERTY_HELPURL ); |
129 | 0 | ImplRegisterProperty( BASEPROPERTY_ORIENTATION ); |
130 | 0 | ImplRegisterProperty( BASEPROPERTY_PRINTABLE ); |
131 | 0 | ImplRegisterProperty( BASEPROPERTY_REPEAT ); |
132 | 0 | ImplRegisterProperty( BASEPROPERTY_REPEAT_DELAY ); |
133 | 0 | ImplRegisterProperty( BASEPROPERTY_SYMBOL_COLOR ); |
134 | 0 | ImplRegisterProperty( BASEPROPERTY_SPINVALUE ); |
135 | 0 | ImplRegisterProperty( BASEPROPERTY_SPINVALUE_MIN ); |
136 | 0 | ImplRegisterProperty( BASEPROPERTY_SPINVALUE_MAX ); |
137 | 0 | ImplRegisterProperty( BASEPROPERTY_SPININCREMENT ); |
138 | 0 | ImplRegisterProperty( BASEPROPERTY_TABSTOP ); |
139 | 0 | ImplRegisterProperty( BASEPROPERTY_WRITING_MODE ); |
140 | 0 | ImplRegisterProperty( BASEPROPERTY_CONTEXT_WRITING_MODE ); |
141 | 0 | } |
142 | | |
143 | | |
144 | | OUString UnoSpinButtonModel::getServiceName( ) |
145 | 0 | { |
146 | 0 | return u"com.sun.star.awt.UnoControlSpinButtonModel"_ustr; |
147 | 0 | } |
148 | | |
149 | | |
150 | | Any UnoSpinButtonModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const |
151 | 0 | { |
152 | 0 | switch ( nPropId ) |
153 | 0 | { |
154 | 0 | case BASEPROPERTY_DEFAULTCONTROL: |
155 | 0 | return Any( u"com.sun.star.awt.UnoControlSpinButton"_ustr ); |
156 | | |
157 | 0 | case BASEPROPERTY_BORDER: |
158 | 0 | return Any( sal_Int16(0) ); |
159 | | |
160 | 0 | case BASEPROPERTY_REPEAT: |
161 | 0 | return Any( true ); |
162 | | |
163 | 0 | default: |
164 | 0 | return UnoControlModel::ImplGetDefaultValue( nPropId ); |
165 | 0 | } |
166 | 0 | } |
167 | | |
168 | | |
169 | | ::cppu::IPropertyArrayHelper& UnoSpinButtonModel::getInfoHelper() |
170 | 0 | { |
171 | 0 | static UnoPropertyArrayHelper aHelper( ImplGetPropertyIds() ); |
172 | 0 | return aHelper; |
173 | 0 | } |
174 | | |
175 | | |
176 | | Reference< XPropertySetInfo > UnoSpinButtonModel::getPropertySetInfo( ) |
177 | 0 | { |
178 | 0 | static Reference< XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); |
179 | 0 | return xInfo; |
180 | 0 | } |
181 | | |
182 | | |
183 | | OUString SAL_CALL UnoSpinButtonModel::getImplementationName( ) |
184 | 0 | { |
185 | 0 | return u"stardiv.Toolkit.UnoSpinButtonModel"_ustr; |
186 | 0 | } |
187 | | |
188 | | |
189 | | Sequence< OUString > SAL_CALL UnoSpinButtonModel::getSupportedServiceNames() |
190 | 0 | { |
191 | 0 | const css::uno::Sequence<OUString> vals { u"com.sun.star.awt.UnoControlSpinButtonModel"_ustr }; |
192 | 0 | return comphelper::concatSequences( UnoControlModel::getSupportedServiceNames(), vals ); |
193 | 0 | } |
194 | | |
195 | | |
196 | | //= UnoSpinButtonControl |
197 | | |
198 | | |
199 | | UnoSpinButtonControl::UnoSpinButtonControl() |
200 | 0 | :maAdjustmentListeners( *this ) |
201 | 0 | { |
202 | 0 | } |
203 | | |
204 | | |
205 | | OUString UnoSpinButtonControl::GetComponentServiceName() const |
206 | 0 | { |
207 | 0 | return u"SpinButton"_ustr; |
208 | 0 | } |
209 | | |
210 | | |
211 | | Any UnoSpinButtonControl::queryAggregation( const Type & rType ) |
212 | 0 | { |
213 | 0 | Any aRet = UnoControlBase::queryAggregation( rType ); |
214 | 0 | if ( !aRet.hasValue() ) |
215 | 0 | aRet = UnoSpinButtonControl_Base::queryInterface( rType ); |
216 | 0 | return aRet; |
217 | 0 | } |
218 | | |
219 | | |
220 | | IMPLEMENT_FORWARD_XTYPEPROVIDER2( UnoSpinButtonControl, UnoControlBase, UnoSpinButtonControl_Base ) |
221 | | |
222 | | |
223 | | void UnoSpinButtonControl::dispose() |
224 | 0 | { |
225 | 0 | ::osl::ClearableMutexGuard aGuard( GetMutex() ); |
226 | 0 | if ( maAdjustmentListeners.getLength() ) |
227 | 0 | { |
228 | 0 | Reference< XSpinValue > xSpinnable( getPeer(), UNO_QUERY ); |
229 | 0 | if ( xSpinnable.is() ) |
230 | 0 | xSpinnable->removeAdjustmentListener( this ); |
231 | |
|
232 | 0 | EventObject aDisposeEvent; |
233 | 0 | aDisposeEvent.Source = *this; |
234 | |
|
235 | 0 | aGuard.clear(); |
236 | 0 | maAdjustmentListeners.disposeAndClear( aDisposeEvent ); |
237 | 0 | } |
238 | |
|
239 | 0 | UnoControl::dispose(); |
240 | 0 | } |
241 | | |
242 | | |
243 | | OUString SAL_CALL UnoSpinButtonControl::getImplementationName( ) |
244 | 0 | { |
245 | 0 | return u"stardiv.Toolkit.UnoSpinButtonControl"_ustr; |
246 | 0 | } |
247 | | |
248 | | |
249 | | Sequence< OUString > SAL_CALL UnoSpinButtonControl::getSupportedServiceNames() |
250 | 0 | { |
251 | 0 | const css::uno::Sequence<OUString> vals { u"com.sun.star.awt.UnoControlSpinButton"_ustr }; |
252 | 0 | return comphelper::concatSequences( UnoControlBase::getSupportedServiceNames(), vals ); |
253 | 0 | } |
254 | | |
255 | | |
256 | | void UnoSpinButtonControl::createPeer( const Reference< XToolkit > & rxToolkit, const Reference< XWindowPeer > & rParentPeer ) |
257 | 0 | { |
258 | 0 | UnoControl::createPeer( rxToolkit, rParentPeer ); |
259 | |
|
260 | 0 | Reference < XSpinValue > xSpinnable( getPeer(), UNO_QUERY ); |
261 | 0 | if ( xSpinnable.is() ) |
262 | 0 | xSpinnable->addAdjustmentListener( this ); |
263 | 0 | } |
264 | | |
265 | | |
266 | | void UnoSpinButtonControl::adjustmentValueChanged( const AdjustmentEvent& rEvent ) |
267 | 0 | { |
268 | 0 | switch ( rEvent.Type ) |
269 | 0 | { |
270 | 0 | case AdjustmentType_ADJUST_LINE: |
271 | 0 | case AdjustmentType_ADJUST_PAGE: |
272 | 0 | case AdjustmentType_ADJUST_ABS: |
273 | 0 | ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE ), Any( rEvent.Value ), false ); |
274 | 0 | break; |
275 | 0 | default: |
276 | 0 | OSL_FAIL( "UnoSpinButtonControl::adjustmentValueChanged - unknown Type" ); |
277 | 0 | } |
278 | | |
279 | 0 | if ( maAdjustmentListeners.getLength() ) |
280 | 0 | { |
281 | 0 | AdjustmentEvent aEvent( rEvent ); |
282 | 0 | aEvent.Source = *this; |
283 | 0 | maAdjustmentListeners.adjustmentValueChanged( aEvent ); |
284 | 0 | } |
285 | 0 | } |
286 | | |
287 | | |
288 | | void UnoSpinButtonControl::addAdjustmentListener( const Reference< XAdjustmentListener > & listener ) |
289 | 0 | { |
290 | 0 | ::osl::MutexGuard aGuard( GetMutex() ); |
291 | 0 | maAdjustmentListeners.addInterface( listener ); |
292 | 0 | } |
293 | | |
294 | | |
295 | | void UnoSpinButtonControl::removeAdjustmentListener( const Reference< XAdjustmentListener > & listener ) |
296 | 0 | { |
297 | 0 | ::osl::MutexGuard aGuard( GetMutex() ); |
298 | 0 | maAdjustmentListeners.removeInterface( listener ); |
299 | 0 | } |
300 | | |
301 | | |
302 | | void SAL_CALL UnoSpinButtonControl::setValue( sal_Int32 value ) |
303 | 0 | { |
304 | 0 | ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE ), Any( value ), true ); |
305 | 0 | } |
306 | | |
307 | | |
308 | | void SAL_CALL UnoSpinButtonControl::setValues( sal_Int32 minValue, sal_Int32 maxValue, sal_Int32 currentValue ) |
309 | 0 | { |
310 | 0 | ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE_MIN ), Any( minValue ), true ); |
311 | 0 | ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE_MAX ), Any( maxValue ), true ); |
312 | 0 | ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE ), Any( currentValue ), true ); |
313 | 0 | } |
314 | | |
315 | | |
316 | | sal_Int32 SAL_CALL UnoSpinButtonControl::getValue( ) |
317 | 0 | { |
318 | 0 | ::osl::MutexGuard aGuard( GetMutex() ); |
319 | 0 | sal_Int32 nValue = 0; |
320 | |
|
321 | 0 | Reference< XSpinValue > xSpinnable( getPeer(), UNO_QUERY ); |
322 | 0 | if ( xSpinnable.is() ) |
323 | 0 | nValue = xSpinnable->getValue(); |
324 | |
|
325 | 0 | return nValue; |
326 | 0 | } |
327 | | |
328 | | |
329 | | void SAL_CALL UnoSpinButtonControl::setMinimum( sal_Int32 minValue ) |
330 | 0 | { |
331 | 0 | ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE_MIN ), Any( minValue ), true ); |
332 | 0 | } |
333 | | |
334 | | |
335 | | void SAL_CALL UnoSpinButtonControl::setMaximum( sal_Int32 maxValue ) |
336 | 0 | { |
337 | 0 | ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE_MAX ), Any( maxValue ), true ); |
338 | 0 | } |
339 | | |
340 | | |
341 | | sal_Int32 SAL_CALL UnoSpinButtonControl::getMinimum( ) |
342 | 0 | { |
343 | 0 | ::osl::MutexGuard aGuard( GetMutex() ); |
344 | 0 | sal_Int32 nMin = 0; |
345 | |
|
346 | 0 | Reference< XSpinValue > xSpinnable( getPeer(), UNO_QUERY ); |
347 | 0 | if ( xSpinnable.is() ) |
348 | 0 | nMin = xSpinnable->getMinimum(); |
349 | |
|
350 | 0 | return nMin; |
351 | 0 | } |
352 | | |
353 | | |
354 | | sal_Int32 SAL_CALL UnoSpinButtonControl::getMaximum( ) |
355 | 0 | { |
356 | 0 | ::osl::MutexGuard aGuard( GetMutex() ); |
357 | 0 | sal_Int32 nMax = 0; |
358 | |
|
359 | 0 | Reference< XSpinValue > xSpinnable( getPeer(), UNO_QUERY ); |
360 | 0 | if ( xSpinnable.is() ) |
361 | 0 | nMax = xSpinnable->getMaximum(); |
362 | |
|
363 | 0 | return nMax; |
364 | 0 | } |
365 | | |
366 | | |
367 | | void SAL_CALL UnoSpinButtonControl::setSpinIncrement( sal_Int32 spinIncrement ) |
368 | 0 | { |
369 | 0 | ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPININCREMENT ), Any( spinIncrement ), true ); |
370 | 0 | } |
371 | | |
372 | | |
373 | | sal_Int32 SAL_CALL UnoSpinButtonControl::getSpinIncrement( ) |
374 | 0 | { |
375 | 0 | ::osl::MutexGuard aGuard( GetMutex() ); |
376 | 0 | sal_Int32 nIncrement = 0; |
377 | |
|
378 | 0 | Reference< XSpinValue > xSpinnable( getPeer(), UNO_QUERY ); |
379 | 0 | if ( xSpinnable.is() ) |
380 | 0 | nIncrement = xSpinnable->getSpinIncrement(); |
381 | |
|
382 | 0 | return nIncrement; |
383 | 0 | } |
384 | | |
385 | | |
386 | | void SAL_CALL UnoSpinButtonControl::setOrientation( sal_Int32 orientation ) |
387 | 0 | { |
388 | 0 | ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_ORIENTATION ), Any( orientation ), true ); |
389 | 0 | } |
390 | | |
391 | | |
392 | | sal_Int32 SAL_CALL UnoSpinButtonControl::getOrientation( ) |
393 | 0 | { |
394 | 0 | ::osl::MutexGuard aGuard( GetMutex() ); |
395 | 0 | sal_Int32 nOrientation = ScrollBarOrientation::HORIZONTAL; |
396 | |
|
397 | 0 | Reference< XSpinValue > xSpinnable( getPeer(), UNO_QUERY ); |
398 | 0 | if ( xSpinnable.is() ) |
399 | 0 | nOrientation = xSpinnable->getOrientation(); |
400 | |
|
401 | 0 | return nOrientation; |
402 | 0 | } |
403 | | |
404 | | } |
405 | | |
406 | | extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * |
407 | | stardiv_Toolkit_UnoSpinButtonModel_get_implementation( |
408 | | css::uno::XComponentContext *context, |
409 | | css::uno::Sequence<css::uno::Any> const &) |
410 | 0 | { |
411 | 0 | return cppu::acquire(new UnoSpinButtonModel(context)); |
412 | 0 | } |
413 | | |
414 | | extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * |
415 | | stardiv_Toolkit_UnoSpinButtonControl_get_implementation( |
416 | | css::uno::XComponentContext *, |
417 | | css::uno::Sequence<css::uno::Any> const &) |
418 | 0 | { |
419 | 0 | return cppu::acquire(new UnoSpinButtonControl()); |
420 | 0 | } |
421 | | |
422 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |