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 <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>
25 #include <comphelper/uno3.hxx>
26 #include <cppuhelper/implbase2.hxx>
27 #include <cppuhelper/typeprovider.hxx>
28 #include <toolkit/controls/unocontrolmodel.hxx>
29 #include <toolkit/controls/unocontrolbase.hxx>
30 #include <toolkit/helper/macros.hxx>
31 #include <toolkit/helper/property.hxx>
33 #include "helper/unopropertyarrayhelper.hxx"
35 using namespace ::com::sun::star::uno
;
36 using namespace ::com::sun::star::awt
;
37 using namespace ::com::sun::star::lang
;
38 using namespace ::com::sun::star::beans
;
42 class UnoSpinButtonModel
: public UnoControlModel
45 css::uno::Any
ImplGetDefaultValue( sal_uInt16 nPropId
) const override
;
46 ::cppu::IPropertyArrayHelper
& SAL_CALL
getInfoHelper() override
;
49 explicit UnoSpinButtonModel( const css::uno::Reference
< css::uno::XComponentContext
>& i_factory
);
50 UnoSpinButtonModel( const UnoSpinButtonModel
& rModel
) : UnoControlModel( rModel
) {}
52 UnoControlModel
* Clone() const override
{ return new UnoSpinButtonModel( *this ); }
55 css::uno::Reference
< css::beans::XPropertySetInfo
> SAL_CALL
getPropertySetInfo( ) override
;
58 OUString SAL_CALL
getServiceName() override
;
61 OUString SAL_CALL
getImplementationName( ) override
;
62 css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
66 //= UnoSpinButtonControl
69 typedef ::cppu::ImplHelper2
< css::awt::XAdjustmentListener
70 , css::awt::XSpinValue
71 > UnoSpinButtonControl_Base
;
73 class UnoSpinButtonControl
:public UnoControlBase
74 ,public UnoSpinButtonControl_Base
77 AdjustmentListenerMultiplexer maAdjustmentListeners
;
80 UnoSpinButtonControl();
81 OUString
GetComponentServiceName() override
;
83 DECLARE_UNO3_AGG_DEFAULTS( UnoSpinButtonControl
, UnoControlBase
)
84 css::uno::Any SAL_CALL
queryAggregation( const css::uno::Type
& rType
) override
;
86 void SAL_CALL
createPeer( const css::uno::Reference
< css::awt::XToolkit
>& Toolkit
, const css::uno::Reference
< css::awt::XWindowPeer
>& Parent
) override
;
87 void SAL_CALL
disposing( const css::lang::EventObject
& Source
) override
{ UnoControlBase::disposing( Source
); }
88 void SAL_CALL
dispose( ) override
;
91 DECLARE_XTYPEPROVIDER()
93 // XAdjustmentListener
94 void SAL_CALL
adjustmentValueChanged( const css::awt::AdjustmentEvent
& rEvent
) override
;
97 virtual void SAL_CALL
addAdjustmentListener( const css::uno::Reference
< css::awt::XAdjustmentListener
>& listener
) override
;
98 virtual void SAL_CALL
removeAdjustmentListener( const css::uno::Reference
< css::awt::XAdjustmentListener
>& listener
) override
;
99 virtual void SAL_CALL
setValue( sal_Int32 value
) override
;
100 virtual void SAL_CALL
setValues( sal_Int32 minValue
, sal_Int32 maxValue
, sal_Int32 currentValue
) override
;
101 virtual sal_Int32 SAL_CALL
getValue( ) override
;
102 virtual void SAL_CALL
setMinimum( sal_Int32 minValue
) override
;
103 virtual void SAL_CALL
setMaximum( sal_Int32 maxValue
) override
;
104 virtual sal_Int32 SAL_CALL
getMinimum( ) override
;
105 virtual sal_Int32 SAL_CALL
getMaximum( ) override
;
106 virtual void SAL_CALL
setSpinIncrement( sal_Int32 spinIncrement
) override
;
107 virtual sal_Int32 SAL_CALL
getSpinIncrement( ) override
;
108 virtual void SAL_CALL
setOrientation( sal_Int32 orientation
) override
;
109 virtual sal_Int32 SAL_CALL
getOrientation( ) override
;
112 OUString SAL_CALL
getImplementationName( ) override
;
113 css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
117 //= UnoSpinButtonModel
120 UnoSpinButtonModel::UnoSpinButtonModel( const css::uno::Reference
< css::uno::XComponentContext
>& i_factory
)
121 :UnoControlModel( i_factory
)
123 ImplRegisterProperty( BASEPROPERTY_BACKGROUNDCOLOR
);
124 ImplRegisterProperty( BASEPROPERTY_BORDER
);
125 ImplRegisterProperty( BASEPROPERTY_BORDERCOLOR
);
126 ImplRegisterProperty( BASEPROPERTY_DEFAULTCONTROL
);
127 ImplRegisterProperty( BASEPROPERTY_ENABLED
);
128 ImplRegisterProperty( BASEPROPERTY_ENABLEVISIBLE
);
129 ImplRegisterProperty( BASEPROPERTY_HELPTEXT
);
130 ImplRegisterProperty( BASEPROPERTY_HELPURL
);
131 ImplRegisterProperty( BASEPROPERTY_ORIENTATION
);
132 ImplRegisterProperty( BASEPROPERTY_PRINTABLE
);
133 ImplRegisterProperty( BASEPROPERTY_REPEAT
);
134 ImplRegisterProperty( BASEPROPERTY_REPEAT_DELAY
);
135 ImplRegisterProperty( BASEPROPERTY_SYMBOL_COLOR
);
136 ImplRegisterProperty( BASEPROPERTY_SPINVALUE
);
137 ImplRegisterProperty( BASEPROPERTY_SPINVALUE_MIN
);
138 ImplRegisterProperty( BASEPROPERTY_SPINVALUE_MAX
);
139 ImplRegisterProperty( BASEPROPERTY_SPININCREMENT
);
140 ImplRegisterProperty( BASEPROPERTY_TABSTOP
);
141 ImplRegisterProperty( BASEPROPERTY_WRITING_MODE
);
142 ImplRegisterProperty( BASEPROPERTY_CONTEXT_WRITING_MODE
);
146 OUString
UnoSpinButtonModel::getServiceName( )
148 return OUString("com.sun.star.awt.UnoControlSpinButtonModel");
152 Any
UnoSpinButtonModel::ImplGetDefaultValue( sal_uInt16 nPropId
) const
156 case BASEPROPERTY_DEFAULTCONTROL
:
157 return makeAny( OUString("com.sun.star.awt.UnoControlSpinButton") );
159 case BASEPROPERTY_BORDER
:
160 return makeAny( (sal_Int16
) 0 );
162 case BASEPROPERTY_REPEAT
:
163 return makeAny( true );
166 return UnoControlModel::ImplGetDefaultValue( nPropId
);
171 ::cppu::IPropertyArrayHelper
& UnoSpinButtonModel::getInfoHelper()
173 static UnoPropertyArrayHelper
* pHelper
= nullptr;
176 Sequence
<sal_Int32
> aIDs
= ImplGetPropertyIds();
177 pHelper
= new UnoPropertyArrayHelper( aIDs
);
183 Reference
< XPropertySetInfo
> UnoSpinButtonModel::getPropertySetInfo( )
185 static Reference
< XPropertySetInfo
> xInfo( createPropertySetInfo( getInfoHelper() ) );
190 OUString SAL_CALL
UnoSpinButtonModel::getImplementationName( )
192 return OUString( "stardiv.Toolkit.UnoSpinButtonModel" );
196 Sequence
< OUString
> SAL_CALL
UnoSpinButtonModel::getSupportedServiceNames()
198 Sequence
< OUString
> aServices( UnoControlModel::getSupportedServiceNames() );
199 aServices
.realloc( aServices
.getLength() + 1 );
200 aServices
[ aServices
.getLength() - 1 ] = "com.sun.star.awt.UnoControlSpinButtonModel";
205 //= UnoSpinButtonControl
208 UnoSpinButtonControl::UnoSpinButtonControl()
210 ,maAdjustmentListeners( *this )
215 OUString
UnoSpinButtonControl::GetComponentServiceName()
217 return OUString("SpinButton");
221 Any
UnoSpinButtonControl::queryAggregation( const Type
& rType
)
223 Any aRet
= UnoControlBase::queryAggregation( rType
);
224 if ( !aRet
.hasValue() )
225 aRet
= UnoSpinButtonControl_Base::queryInterface( rType
);
230 IMPLEMENT_FORWARD_XTYPEPROVIDER2( UnoSpinButtonControl
, UnoControlBase
, UnoSpinButtonControl_Base
)
233 void UnoSpinButtonControl::dispose()
235 ::osl::ClearableMutexGuard
aGuard( GetMutex() );
236 if ( maAdjustmentListeners
.getLength() )
238 Reference
< XSpinValue
> xSpinnable( getPeer(), UNO_QUERY
);
239 if ( xSpinnable
.is() )
240 xSpinnable
->removeAdjustmentListener( this );
242 EventObject aDisposeEvent
;
243 aDisposeEvent
.Source
= *this;
246 maAdjustmentListeners
.disposeAndClear( aDisposeEvent
);
249 UnoControl::dispose();
253 OUString SAL_CALL
UnoSpinButtonControl::getImplementationName( )
255 return OUString( "stardiv.Toolkit.UnoSpinButtonControl" );
259 Sequence
< OUString
> SAL_CALL
UnoSpinButtonControl::getSupportedServiceNames()
261 Sequence
< OUString
> aServices( UnoControlBase::getSupportedServiceNames() );
262 aServices
.realloc( aServices
.getLength() + 1 );
263 aServices
[ aServices
.getLength() - 1 ] = "com.sun.star.awt.UnoControlSpinButton";
268 void UnoSpinButtonControl::createPeer( const Reference
< XToolkit
> & rxToolkit
, const Reference
< XWindowPeer
> & rParentPeer
)
270 UnoControl::createPeer( rxToolkit
, rParentPeer
);
272 Reference
< XSpinValue
> xSpinnable( getPeer(), UNO_QUERY
);
273 if ( xSpinnable
.is() )
274 xSpinnable
->addAdjustmentListener( this );
278 void UnoSpinButtonControl::adjustmentValueChanged( const AdjustmentEvent
& rEvent
)
280 switch ( rEvent
.Type
)
282 case AdjustmentType_ADJUST_LINE
:
283 case AdjustmentType_ADJUST_PAGE
:
284 case AdjustmentType_ADJUST_ABS
:
285 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE
), makeAny( rEvent
.Value
), false );
288 OSL_FAIL( "UnoSpinButtonControl::adjustmentValueChanged - unknown Type" );
291 if ( maAdjustmentListeners
.getLength() )
293 AdjustmentEvent
aEvent( rEvent
);
294 aEvent
.Source
= *this;
295 maAdjustmentListeners
.adjustmentValueChanged( aEvent
);
300 void UnoSpinButtonControl::addAdjustmentListener( const Reference
< XAdjustmentListener
> & listener
)
302 ::osl::MutexGuard
aGuard( GetMutex() );
303 maAdjustmentListeners
.addInterface( listener
);
307 void UnoSpinButtonControl::removeAdjustmentListener( const Reference
< XAdjustmentListener
> & listener
)
309 ::osl::MutexGuard
aGuard( GetMutex() );
310 maAdjustmentListeners
.removeInterface( listener
);
314 void SAL_CALL
UnoSpinButtonControl::setValue( sal_Int32 value
)
316 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE
), makeAny( value
), true );
320 void SAL_CALL
UnoSpinButtonControl::setValues( sal_Int32 minValue
, sal_Int32 maxValue
, sal_Int32 currentValue
)
322 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE_MIN
), makeAny( minValue
), true );
323 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE_MAX
), makeAny( maxValue
), true );
324 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE
), makeAny( currentValue
), true );
328 sal_Int32 SAL_CALL
UnoSpinButtonControl::getValue( )
330 ::osl::MutexGuard
aGuard( GetMutex() );
331 sal_Int32 nValue
= 0;
333 Reference
< XSpinValue
> xSpinnable( getPeer(), UNO_QUERY
);
334 if ( xSpinnable
.is() )
335 nValue
= xSpinnable
->getValue();
341 void SAL_CALL
UnoSpinButtonControl::setMinimum( sal_Int32 minValue
)
343 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE_MIN
), makeAny( minValue
), true );
347 void SAL_CALL
UnoSpinButtonControl::setMaximum( sal_Int32 maxValue
)
349 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE_MAX
), makeAny( maxValue
), true );
353 sal_Int32 SAL_CALL
UnoSpinButtonControl::getMinimum( )
355 ::osl::MutexGuard
aGuard( GetMutex() );
358 Reference
< XSpinValue
> xSpinnable( getPeer(), UNO_QUERY
);
359 if ( xSpinnable
.is() )
360 nMin
= xSpinnable
->getMinimum();
366 sal_Int32 SAL_CALL
UnoSpinButtonControl::getMaximum( )
368 ::osl::MutexGuard
aGuard( GetMutex() );
371 Reference
< XSpinValue
> xSpinnable( getPeer(), UNO_QUERY
);
372 if ( xSpinnable
.is() )
373 nMax
= xSpinnable
->getMaximum();
379 void SAL_CALL
UnoSpinButtonControl::setSpinIncrement( sal_Int32 spinIncrement
)
381 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPININCREMENT
), makeAny( spinIncrement
), true );
385 sal_Int32 SAL_CALL
UnoSpinButtonControl::getSpinIncrement( )
387 ::osl::MutexGuard
aGuard( GetMutex() );
388 sal_Int32 nIncrement
= 0;
390 Reference
< XSpinValue
> xSpinnable( getPeer(), UNO_QUERY
);
391 if ( xSpinnable
.is() )
392 nIncrement
= xSpinnable
->getSpinIncrement();
398 void SAL_CALL
UnoSpinButtonControl::setOrientation( sal_Int32 orientation
)
400 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_ORIENTATION
), makeAny( orientation
), true );
404 sal_Int32 SAL_CALL
UnoSpinButtonControl::getOrientation( )
406 ::osl::MutexGuard
aGuard( GetMutex() );
407 sal_Int32 nOrientation
= ScrollBarOrientation::HORIZONTAL
;
409 Reference
< XSpinValue
> xSpinnable( getPeer(), UNO_QUERY
);
410 if ( xSpinnable
.is() )
411 nOrientation
= xSpinnable
->getOrientation();
418 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
* SAL_CALL
419 stardiv_Toolkit_UnoSpinButtonModel_get_implementation(
420 css::uno::XComponentContext
*context
,
421 css::uno::Sequence
<css::uno::Any
> const &)
423 return cppu::acquire(new UnoSpinButtonModel(context
));
426 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
* SAL_CALL
427 stardiv_Toolkit_UnoSpinButtonControl_get_implementation(
428 css::uno::XComponentContext
*,
429 css::uno::Sequence
<css::uno::Any
> const &)
431 return cppu::acquire(new UnoSpinButtonControl());
434 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */