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/controls/tkspinbutton.hxx"
21 #include "toolkit/helper/property.hxx"
22 #include "toolkit/helper/unopropertyarrayhelper.hxx"
23 #include <com/sun/star/awt/ScrollBarOrientation.hpp>
26 #include <cppuhelper/typeprovider.hxx>
28 //........................................................................
31 //........................................................................
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
;
38 //====================================================================
39 //= UnoSpinButtonModel
40 //====================================================================
41 //--------------------------------------------------------------------
42 UnoSpinButtonModel::UnoSpinButtonModel( const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& i_factory
)
43 :UnoControlModel( i_factory
)
45 ImplRegisterProperty( BASEPROPERTY_BACKGROUNDCOLOR
);
46 ImplRegisterProperty( BASEPROPERTY_BORDER
);
47 ImplRegisterProperty( BASEPROPERTY_BORDERCOLOR
);
48 ImplRegisterProperty( BASEPROPERTY_DEFAULTCONTROL
);
49 ImplRegisterProperty( BASEPROPERTY_ENABLED
);
50 ImplRegisterProperty( BASEPROPERTY_ENABLEVISIBLE
);
51 ImplRegisterProperty( BASEPROPERTY_HELPTEXT
);
52 ImplRegisterProperty( BASEPROPERTY_HELPURL
);
53 ImplRegisterProperty( BASEPROPERTY_ORIENTATION
);
54 ImplRegisterProperty( BASEPROPERTY_PRINTABLE
);
55 ImplRegisterProperty( BASEPROPERTY_REPEAT
);
56 ImplRegisterProperty( BASEPROPERTY_REPEAT_DELAY
);
57 ImplRegisterProperty( BASEPROPERTY_SYMBOL_COLOR
);
58 ImplRegisterProperty( BASEPROPERTY_SPINVALUE
);
59 ImplRegisterProperty( BASEPROPERTY_SPINVALUE_MIN
);
60 ImplRegisterProperty( BASEPROPERTY_SPINVALUE_MAX
);
61 ImplRegisterProperty( BASEPROPERTY_SPININCREMENT
);
62 ImplRegisterProperty( BASEPROPERTY_TABSTOP
);
63 ImplRegisterProperty( BASEPROPERTY_WRITING_MODE
);
64 ImplRegisterProperty( BASEPROPERTY_CONTEXT_WRITING_MODE
);
67 //--------------------------------------------------------------------
68 ::rtl::OUString
UnoSpinButtonModel::getServiceName( ) throw (RuntimeException
)
70 return ::rtl::OUString::createFromAscii( szServiceName_UnoSpinButtonModel
);
73 //--------------------------------------------------------------------
74 Any
UnoSpinButtonModel::ImplGetDefaultValue( sal_uInt16 nPropId
) const
78 case BASEPROPERTY_DEFAULTCONTROL
:
79 return makeAny( ::rtl::OUString::createFromAscii( szServiceName_UnoSpinButtonControl
) );
81 case BASEPROPERTY_BORDER
:
82 return makeAny( (sal_Int16
) 0 );
84 case BASEPROPERTY_REPEAT
:
85 return makeAny( (sal_Bool
)sal_True
);
88 return UnoControlModel::ImplGetDefaultValue( nPropId
);
92 //--------------------------------------------------------------------
93 ::cppu::IPropertyArrayHelper
& UnoSpinButtonModel::getInfoHelper()
95 static UnoPropertyArrayHelper
* pHelper
= NULL
;
98 Sequence
<sal_Int32
> aIDs
= ImplGetPropertyIds();
99 pHelper
= new UnoPropertyArrayHelper( aIDs
);
104 //--------------------------------------------------------------------
105 Reference
< XPropertySetInfo
> UnoSpinButtonModel::getPropertySetInfo( ) throw(RuntimeException
)
107 static Reference
< XPropertySetInfo
> xInfo( createPropertySetInfo( getInfoHelper() ) );
111 //--------------------------------------------------------------------
112 ::rtl::OUString SAL_CALL
UnoSpinButtonModel::getImplementationName( ) throw(RuntimeException
)
114 return ::rtl::OUString( "com.sun.star.comp.toolkit.UnoSpinButtonModel" );
117 //--------------------------------------------------------------------
118 Sequence
< ::rtl::OUString
> SAL_CALL
UnoSpinButtonModel::getSupportedServiceNames() throw(RuntimeException
)
120 Sequence
< ::rtl::OUString
> aServices( UnoControlModel::getSupportedServiceNames() );
121 aServices
.realloc( aServices
.getLength() + 1 );
122 aServices
[ aServices
.getLength() - 1 ] = ::rtl::OUString::createFromAscii( szServiceName_UnoSpinButtonModel
);
126 //====================================================================
127 //= UnoSpinButtonControl
128 //====================================================================
129 //--------------------------------------------------------------------
130 UnoSpinButtonControl::UnoSpinButtonControl( const Reference
< XMultiServiceFactory
>& i_factory
)
131 :UnoControlBase( i_factory
)
132 ,maAdjustmentListeners( *this )
136 //--------------------------------------------------------------------
137 ::rtl::OUString
UnoSpinButtonControl::GetComponentServiceName()
139 return ::rtl::OUString("SpinButton");
142 //--------------------------------------------------------------------
143 Any
UnoSpinButtonControl::queryAggregation( const Type
& rType
) throw(RuntimeException
)
145 Any aRet
= UnoControlBase::queryAggregation( rType
);
146 if ( !aRet
.hasValue() )
147 aRet
= UnoSpinButtonControl_Base::queryInterface( rType
);
151 //--------------------------------------------------------------------
152 IMPLEMENT_FORWARD_XTYPEPROVIDER2( UnoSpinButtonControl
, UnoControlBase
, UnoSpinButtonControl_Base
)
154 //--------------------------------------------------------------------
155 void UnoSpinButtonControl::dispose() throw(RuntimeException
)
157 ::osl::ClearableMutexGuard
aGuard( GetMutex() );
158 if ( maAdjustmentListeners
.getLength() )
160 Reference
< XSpinValue
> xSpinnable( getPeer(), UNO_QUERY
);
161 if ( xSpinnable
.is() )
162 xSpinnable
->removeAdjustmentListener( this );
164 EventObject aDisposeEvent
;
165 aDisposeEvent
.Source
= *this;
168 maAdjustmentListeners
.disposeAndClear( aDisposeEvent
);
171 UnoControl::dispose();
174 //--------------------------------------------------------------------
175 ::rtl::OUString SAL_CALL
UnoSpinButtonControl::getImplementationName( ) throw(RuntimeException
)
177 return ::rtl::OUString( "com.sun.star.comp.toolkit.UnoSpinButtonControl" );
180 //--------------------------------------------------------------------
181 Sequence
< ::rtl::OUString
> SAL_CALL
UnoSpinButtonControl::getSupportedServiceNames() throw(RuntimeException
)
183 Sequence
< ::rtl::OUString
> aServices( UnoControlBase::getSupportedServiceNames() );
184 aServices
.realloc( aServices
.getLength() + 1 );
185 aServices
[ aServices
.getLength() - 1 ] = ::rtl::OUString::createFromAscii( szServiceName_UnoSpinButtonControl
);
189 //--------------------------------------------------------------------
190 void UnoSpinButtonControl::createPeer( const Reference
< XToolkit
> & rxToolkit
, const Reference
< XWindowPeer
> & rParentPeer
) throw(RuntimeException
)
192 UnoControl::createPeer( rxToolkit
, rParentPeer
);
194 Reference
< XSpinValue
> xSpinnable( getPeer(), UNO_QUERY
);
195 if ( xSpinnable
.is() )
196 xSpinnable
->addAdjustmentListener( this );
199 //--------------------------------------------------------------------
200 void UnoSpinButtonControl::adjustmentValueChanged( const AdjustmentEvent
& rEvent
) throw(RuntimeException
)
202 switch ( rEvent
.Type
)
204 case AdjustmentType_ADJUST_LINE
:
205 case AdjustmentType_ADJUST_PAGE
:
206 case AdjustmentType_ADJUST_ABS
:
207 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE
), makeAny( rEvent
.Value
), sal_False
);
210 OSL_FAIL( "UnoSpinButtonControl::adjustmentValueChanged - unknown Type" );
213 if ( maAdjustmentListeners
.getLength() )
215 AdjustmentEvent
aEvent( rEvent
);
216 aEvent
.Source
= *this;
217 maAdjustmentListeners
.adjustmentValueChanged( aEvent
);
221 //--------------------------------------------------------------------
222 void UnoSpinButtonControl::addAdjustmentListener( const Reference
< XAdjustmentListener
> & listener
) throw(RuntimeException
)
224 ::osl::MutexGuard
aGuard( GetMutex() );
225 maAdjustmentListeners
.addInterface( listener
);
228 //--------------------------------------------------------------------
229 void UnoSpinButtonControl::removeAdjustmentListener( const Reference
< XAdjustmentListener
> & listener
) throw(RuntimeException
)
231 ::osl::MutexGuard
aGuard( GetMutex() );
232 maAdjustmentListeners
.removeInterface( listener
);
235 //--------------------------------------------------------------------
236 void SAL_CALL
UnoSpinButtonControl::setValue( sal_Int32 value
) throw (RuntimeException
)
238 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE
), makeAny( value
), sal_True
);
241 //--------------------------------------------------------------------
242 void SAL_CALL
UnoSpinButtonControl::setValues( sal_Int32 minValue
, sal_Int32 maxValue
, sal_Int32 currentValue
) throw (RuntimeException
)
244 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE_MIN
), makeAny( minValue
), sal_True
);
245 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE_MAX
), makeAny( maxValue
), sal_True
);
246 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE
), makeAny( currentValue
), sal_True
);
249 //--------------------------------------------------------------------
250 sal_Int32 SAL_CALL
UnoSpinButtonControl::getValue( ) throw (RuntimeException
)
252 ::osl::MutexGuard
aGuard( GetMutex() );
253 sal_Int32 nValue
= 0;
255 Reference
< XSpinValue
> xSpinnable( getPeer(), UNO_QUERY
);
256 if ( xSpinnable
.is() )
257 nValue
= xSpinnable
->getValue();
262 //--------------------------------------------------------------------
263 void SAL_CALL
UnoSpinButtonControl::setMinimum( sal_Int32 minValue
) throw (RuntimeException
)
265 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE_MIN
), makeAny( minValue
), sal_True
);
268 //--------------------------------------------------------------------
269 void SAL_CALL
UnoSpinButtonControl::setMaximum( sal_Int32 maxValue
) throw (RuntimeException
)
271 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE_MAX
), makeAny( maxValue
), sal_True
);
274 //--------------------------------------------------------------------
275 sal_Int32 SAL_CALL
UnoSpinButtonControl::getMinimum( ) throw (RuntimeException
)
277 ::osl::MutexGuard
aGuard( GetMutex() );
280 Reference
< XSpinValue
> xSpinnable( getPeer(), UNO_QUERY
);
281 if ( xSpinnable
.is() )
282 nMin
= xSpinnable
->getMinimum();
287 //--------------------------------------------------------------------
288 sal_Int32 SAL_CALL
UnoSpinButtonControl::getMaximum( ) throw (RuntimeException
)
290 ::osl::MutexGuard
aGuard( GetMutex() );
293 Reference
< XSpinValue
> xSpinnable( getPeer(), UNO_QUERY
);
294 if ( xSpinnable
.is() )
295 nMax
= xSpinnable
->getMaximum();
300 //--------------------------------------------------------------------
301 void SAL_CALL
UnoSpinButtonControl::setSpinIncrement( sal_Int32 spinIncrement
) throw (RuntimeException
)
303 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPININCREMENT
), makeAny( spinIncrement
), sal_True
);
306 //--------------------------------------------------------------------
307 sal_Int32 SAL_CALL
UnoSpinButtonControl::getSpinIncrement( ) throw (RuntimeException
)
309 ::osl::MutexGuard
aGuard( GetMutex() );
310 sal_Int32 nIncrement
= 0;
312 Reference
< XSpinValue
> xSpinnable( getPeer(), UNO_QUERY
);
313 if ( xSpinnable
.is() )
314 nIncrement
= xSpinnable
->getSpinIncrement();
319 //--------------------------------------------------------------------
320 void SAL_CALL
UnoSpinButtonControl::setOrientation( sal_Int32 orientation
) throw (NoSupportException
, RuntimeException
)
322 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_ORIENTATION
), makeAny( orientation
), sal_True
);
325 //--------------------------------------------------------------------
326 sal_Int32 SAL_CALL
UnoSpinButtonControl::getOrientation( ) throw (RuntimeException
)
328 ::osl::MutexGuard
aGuard( GetMutex() );
329 sal_Int32 nOrientation
= ScrollBarOrientation::HORIZONTAL
;
331 Reference
< XSpinValue
> xSpinnable( getPeer(), UNO_QUERY
);
332 if ( xSpinnable
.is() )
333 nOrientation
= xSpinnable
->getOrientation();
338 //........................................................................
339 } // namespace toolkit
340 //........................................................................
342 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */