LibreOffice Module toolkit (master) 1
tkspinbutton.cxx
Go to the documentation of this file.
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>
29#include <helper/property.hxx>
30
32
33using namespace ::com::sun::star::uno;
34using namespace ::com::sun::star::awt;
35using namespace ::com::sun::star::lang;
36using namespace ::com::sun::star::beans;
37
38namespace {
39
40class UnoSpinButtonModel : public UnoControlModel
41{
42protected:
43 css::uno::Any ImplGetDefaultValue( sal_uInt16 nPropId ) const override;
45
46public:
47 explicit UnoSpinButtonModel( const css::uno::Reference< css::uno::XComponentContext >& i_factory );
48 UnoSpinButtonModel(const UnoSpinButtonModel & rOther) : UnoControlModel(rOther) {}
49
50 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
67typedef ::cppu::ImplHelper2 < css::awt::XAdjustmentListener
68 , css::awt::XSpinValue
69 > UnoSpinButtonControl_Base;
70
71class UnoSpinButtonControl :public UnoControlBase
72 ,public UnoSpinButtonControl_Base
73{
74private:
75 AdjustmentListenerMultiplexer maAdjustmentListeners;
76
77public:
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 void SAL_CALL disposing( const css::lang::EventObject& Source ) override { UnoControlBase::disposing( Source ); }
86 void SAL_CALL dispose( ) override;
87
88 // 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 :UnoControlModel( i_factory )
120 {
121 ImplRegisterProperty( BASEPROPERTY_BACKGROUNDCOLOR );
122 ImplRegisterProperty( BASEPROPERTY_BORDER );
123 ImplRegisterProperty( BASEPROPERTY_BORDERCOLOR );
124 ImplRegisterProperty( BASEPROPERTY_DEFAULTCONTROL );
125 ImplRegisterProperty( BASEPROPERTY_ENABLED );
126 ImplRegisterProperty( BASEPROPERTY_ENABLEVISIBLE );
127 ImplRegisterProperty( BASEPROPERTY_HELPTEXT );
128 ImplRegisterProperty( BASEPROPERTY_HELPURL );
129 ImplRegisterProperty( BASEPROPERTY_ORIENTATION );
130 ImplRegisterProperty( BASEPROPERTY_PRINTABLE );
131 ImplRegisterProperty( BASEPROPERTY_REPEAT );
132 ImplRegisterProperty( BASEPROPERTY_REPEAT_DELAY );
133 ImplRegisterProperty( BASEPROPERTY_SYMBOL_COLOR );
134 ImplRegisterProperty( BASEPROPERTY_SPINVALUE );
135 ImplRegisterProperty( BASEPROPERTY_SPINVALUE_MIN );
136 ImplRegisterProperty( BASEPROPERTY_SPINVALUE_MAX );
137 ImplRegisterProperty( BASEPROPERTY_SPININCREMENT );
138 ImplRegisterProperty( BASEPROPERTY_TABSTOP );
139 ImplRegisterProperty( BASEPROPERTY_WRITING_MODE );
140 ImplRegisterProperty( BASEPROPERTY_CONTEXT_WRITING_MODE );
141 }
142
143
144 OUString UnoSpinButtonModel::getServiceName( )
145 {
146 return "com.sun.star.awt.UnoControlSpinButtonModel";
147 }
148
149
150 Any UnoSpinButtonModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const
151 {
152 switch ( nPropId )
153 {
155 return Any( OUString("com.sun.star.awt.UnoControlSpinButton") );
156
158 return Any( sal_Int16(0) );
159
161 return Any( true );
162
163 default:
164 return UnoControlModel::ImplGetDefaultValue( nPropId );
165 }
166 }
167
168
169 ::cppu::IPropertyArrayHelper& UnoSpinButtonModel::getInfoHelper()
170 {
171 static UnoPropertyArrayHelper aHelper( ImplGetPropertyIds() );
172 return aHelper;
173 }
174
175
176 Reference< XPropertySetInfo > UnoSpinButtonModel::getPropertySetInfo( )
177 {
178 static Reference< XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
179 return xInfo;
180 }
181
182
183 OUString SAL_CALL UnoSpinButtonModel::getImplementationName( )
184 {
185 return "stardiv.Toolkit.UnoSpinButtonModel";
186 }
187
188
189 Sequence< OUString > SAL_CALL UnoSpinButtonModel::getSupportedServiceNames()
190 {
191 const css::uno::Sequence<OUString> vals { "com.sun.star.awt.UnoControlSpinButtonModel" };
193 }
194
195
196 //= UnoSpinButtonControl
197
198
199 UnoSpinButtonControl::UnoSpinButtonControl()
200 :maAdjustmentListeners( *this )
201 {
202 }
203
204
205 OUString UnoSpinButtonControl::GetComponentServiceName() const
206 {
207 return "SpinButton";
208 }
209
210
211 Any UnoSpinButtonControl::queryAggregation( const Type & rType )
212 {
214 if ( !aRet.hasValue() )
215 aRet = UnoSpinButtonControl_Base::queryInterface( rType );
216 return aRet;
217 }
218
219
220 IMPLEMENT_FORWARD_XTYPEPROVIDER2( UnoSpinButtonControl, UnoControlBase, UnoSpinButtonControl_Base )
221
222
223 void UnoSpinButtonControl::dispose()
224 {
225 ::osl::ClearableMutexGuard aGuard( GetMutex() );
226 if ( maAdjustmentListeners.getLength() )
227 {
228 Reference< XSpinValue > xSpinnable( getPeer(), UNO_QUERY );
229 if ( xSpinnable.is() )
230 xSpinnable->removeAdjustmentListener( this );
231
232 EventObject aDisposeEvent;
233 aDisposeEvent.Source = *this;
234
235 aGuard.clear();
236 maAdjustmentListeners.disposeAndClear( aDisposeEvent );
237 }
238
240 }
241
242
243 OUString SAL_CALL UnoSpinButtonControl::getImplementationName( )
244 {
245 return "stardiv.Toolkit.UnoSpinButtonControl";
246 }
247
248
249 Sequence< OUString > SAL_CALL UnoSpinButtonControl::getSupportedServiceNames()
250 {
251 const css::uno::Sequence<OUString> vals { "com.sun.star.awt.UnoControlSpinButton" };
253 }
254
255
256 void UnoSpinButtonControl::createPeer( const Reference< XToolkit > & rxToolkit, const Reference< XWindowPeer > & rParentPeer )
257 {
258 UnoControl::createPeer( rxToolkit, rParentPeer );
259
260 Reference < XSpinValue > xSpinnable( getPeer(), UNO_QUERY );
261 if ( xSpinnable.is() )
262 xSpinnable->addAdjustmentListener( this );
263 }
264
265
266 void UnoSpinButtonControl::adjustmentValueChanged( const AdjustmentEvent& rEvent )
267 {
268 switch ( rEvent.Type )
269 {
270 case AdjustmentType_ADJUST_LINE:
271 case AdjustmentType_ADJUST_PAGE:
272 case AdjustmentType_ADJUST_ABS:
273 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE ), Any( rEvent.Value ), false );
274 break;
275 default:
276 OSL_FAIL( "UnoSpinButtonControl::adjustmentValueChanged - unknown Type" );
277 }
278
279 if ( maAdjustmentListeners.getLength() )
280 {
281 AdjustmentEvent aEvent( rEvent );
282 aEvent.Source = *this;
283 maAdjustmentListeners.adjustmentValueChanged( aEvent );
284 }
285 }
286
287
288 void UnoSpinButtonControl::addAdjustmentListener( const Reference< XAdjustmentListener > & listener )
289 {
290 ::osl::MutexGuard aGuard( GetMutex() );
291 maAdjustmentListeners.addInterface( listener );
292 }
293
294
295 void UnoSpinButtonControl::removeAdjustmentListener( const Reference< XAdjustmentListener > & listener )
296 {
297 ::osl::MutexGuard aGuard( GetMutex() );
298 maAdjustmentListeners.removeInterface( listener );
299 }
300
301
302 void SAL_CALL UnoSpinButtonControl::setValue( sal_Int32 value )
303 {
304 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE ), Any( value ), true );
305 }
306
307
308 void SAL_CALL UnoSpinButtonControl::setValues( sal_Int32 minValue, sal_Int32 maxValue, sal_Int32 currentValue )
309 {
310 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE_MIN ), Any( minValue ), true );
311 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE_MAX ), Any( maxValue ), true );
312 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE ), Any( currentValue ), true );
313 }
314
315
316 sal_Int32 SAL_CALL UnoSpinButtonControl::getValue( )
317 {
318 ::osl::MutexGuard aGuard( GetMutex() );
319 sal_Int32 nValue = 0;
320
321 Reference< XSpinValue > xSpinnable( getPeer(), UNO_QUERY );
322 if ( xSpinnable.is() )
323 nValue = xSpinnable->getValue();
324
325 return nValue;
326 }
327
328
329 void SAL_CALL UnoSpinButtonControl::setMinimum( sal_Int32 minValue )
330 {
331 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE_MIN ), Any( minValue ), true );
332 }
333
334
335 void SAL_CALL UnoSpinButtonControl::setMaximum( sal_Int32 maxValue )
336 {
337 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE_MAX ), Any( maxValue ), true );
338 }
339
340
341 sal_Int32 SAL_CALL UnoSpinButtonControl::getMinimum( )
342 {
343 ::osl::MutexGuard aGuard( GetMutex() );
344 sal_Int32 nMin = 0;
345
346 Reference< XSpinValue > xSpinnable( getPeer(), UNO_QUERY );
347 if ( xSpinnable.is() )
348 nMin = xSpinnable->getMinimum();
349
350 return nMin;
351 }
352
353
354 sal_Int32 SAL_CALL UnoSpinButtonControl::getMaximum( )
355 {
356 ::osl::MutexGuard aGuard( GetMutex() );
357 sal_Int32 nMax = 0;
358
359 Reference< XSpinValue > xSpinnable( getPeer(), UNO_QUERY );
360 if ( xSpinnable.is() )
361 nMax = xSpinnable->getMaximum();
362
363 return nMax;
364 }
365
366
367 void SAL_CALL UnoSpinButtonControl::setSpinIncrement( sal_Int32 spinIncrement )
368 {
369 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPININCREMENT ), Any( spinIncrement ), true );
370 }
371
372
373 sal_Int32 SAL_CALL UnoSpinButtonControl::getSpinIncrement( )
374 {
375 ::osl::MutexGuard aGuard( GetMutex() );
376 sal_Int32 nIncrement = 0;
377
378 Reference< XSpinValue > xSpinnable( getPeer(), UNO_QUERY );
379 if ( xSpinnable.is() )
380 nIncrement = xSpinnable->getSpinIncrement();
381
382 return nIncrement;
383 }
384
385
386 void SAL_CALL UnoSpinButtonControl::setOrientation( sal_Int32 orientation )
387 {
388 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_ORIENTATION ), Any( orientation ), true );
389 }
390
391
392 sal_Int32 SAL_CALL UnoSpinButtonControl::getOrientation( )
393 {
394 ::osl::MutexGuard aGuard( GetMutex() );
395 sal_Int32 nOrientation = ScrollBarOrientation::HORIZONTAL;
396
397 Reference< XSpinValue > xSpinnable( getPeer(), UNO_QUERY );
398 if ( xSpinnable.is() )
399 nOrientation = xSpinnable->getOrientation();
400
401 return nOrientation;
402 }
403
404}
405
406extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
408 css::uno::XComponentContext *context,
409 css::uno::Sequence<css::uno::Any> const &)
410{
411 return cppu::acquire(new UnoSpinButtonModel(context));
412}
413
414extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
416 css::uno::XComponentContext *,
417 css::uno::Sequence<css::uno::Any> const &)
418{
419 return cppu::acquire(new UnoSpinButtonControl());
420}
421
422/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
AnyEventRef aEvent
virtual css::uno::Any ImplGetDefaultValue(sal_uInt16 nPropId) const
::cppu::IPropertyArrayHelper & getInfoHelper() override=0
css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
void SAL_CALL dispose() override
Definition: unocontrol.cxx:346
void SAL_CALL disposing(const css::lang::EventObject &Source) override
Definition: unocontrol.cxx:654
virtual OUString GetComponentServiceName() const
Definition: unocontrol.cxx:155
css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
void SAL_CALL createPeer(const css::uno::Reference< css::awt::XToolkit > &Toolkit, const css::uno::Reference< css::awt::XWindowPeer > &Parent) override
virtual css::uno::Any SAL_CALL queryAggregation(css::uno::Type const &rType) SAL_OVERRIDE
Any aHelper
sal_Int16 nValue
DECL_LISTENERMULTIPLEXER_END void SAL_CALL adjustmentValueChanged(const css::awt::AdjustmentEvent &rEvent) override
css::uno::Sequence< T > concatSequences(const css::uno::Sequence< T > &rS1, const Ss &... rSn)
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
Type
orientation
css::uno::Reference< css::animations::XAnimationNode > Clone(const css::uno::Reference< css::animations::XAnimationNode > &xSourceNode, const SdPage *pSource=nullptr, const SdPage *pTarget=nullptr)
const OUString & GetPropertyName(sal_uInt16 nPropertyId)
Definition: property.cxx:295
#define BASEPROPERTY_SPININCREMENT
Definition: property.hxx:133
#define BASEPROPERTY_SPINVALUE
Definition: property.hxx:130
#define BASEPROPERTY_BORDER
Definition: property.hxx:39
#define BASEPROPERTY_ORIENTATION
Definition: property.hxx:115
#define BASEPROPERTY_CONTEXT_WRITING_MODE
Definition: property.hxx:174
#define BASEPROPERTY_HELPURL
Definition: property.hxx:91
#define BASEPROPERTY_REPEAT
Definition: property.hxx:134
#define BASEPROPERTY_SYMBOL_COLOR
Definition: property.hxx:129
#define BASEPROPERTY_BACKGROUNDCOLOR
Definition: property.hxx:35
#define BASEPROPERTY_SPINVALUE_MAX
Definition: property.hxx:132
#define BASEPROPERTY_TABSTOP
Definition: property.hxx:47
#define BASEPROPERTY_ENABLED
Definition: property.hxx:77
#define BASEPROPERTY_DEFAULTCONTROL
Definition: property.hxx:52
#define BASEPROPERTY_WRITING_MODE
Definition: property.hxx:173
#define BASEPROPERTY_BORDERCOLOR
Definition: property.hxx:145
#define BASEPROPERTY_ENABLEVISIBLE
Definition: property.hxx:180
#define BASEPROPERTY_HELPTEXT
Definition: property.hxx:106
#define BASEPROPERTY_REPEAT_DELAY
Definition: property.hxx:128
#define BASEPROPERTY_PRINTABLE
Definition: property.hxx:78
#define BASEPROPERTY_SPINVALUE_MIN
Definition: property.hxx:131
IMPLEMENT_FORWARD_XTYPEPROVIDER2(ORoadmapEntry, ORoadmapEntry_Base, ::comphelper::OPropertyContainer)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * stardiv_Toolkit_UnoSpinButtonControl_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * stardiv_Toolkit_UnoSpinButtonModel_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
#define DECLARE_XTYPEPROVIDER()
#define DECLARE_UNO3_AGG_DEFAULTS(classname, baseclass)