update dev300-m58
[ooovba.git] / toolkit / source / controls / tkspinbutton.cxx
blob4c7bc0f1c1a14dffb563d42f0dc5750069ff91f4
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tkspinbutton.cxx,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_toolkit.hxx"
33 #include "toolkit/controls/tkspinbutton.hxx"
34 #include "toolkit/helper/property.hxx"
35 #include "toolkit/helper/unopropertyarrayhelper.hxx"
36 #include <com/sun/star/awt/ScrollBarOrientation.hpp>
39 #include <cppuhelper/typeprovider.hxx>
40 #include <tools/debug.hxx>
42 //........................................................................
43 namespace toolkit
45 //........................................................................
47 using namespace ::com::sun::star::uno;
48 using namespace ::com::sun::star::awt;
49 using namespace ::com::sun::star::lang;
50 using namespace ::com::sun::star::beans;
52 //====================================================================
53 //= UnoSpinButtonModel
54 //====================================================================
55 //--------------------------------------------------------------------
56 UnoSpinButtonModel::UnoSpinButtonModel()
58 ImplRegisterProperty( BASEPROPERTY_BACKGROUNDCOLOR );
59 ImplRegisterProperty( BASEPROPERTY_BORDER );
60 ImplRegisterProperty( BASEPROPERTY_BORDERCOLOR );
61 ImplRegisterProperty( BASEPROPERTY_DEFAULTCONTROL );
62 ImplRegisterProperty( BASEPROPERTY_ENABLED );
63 ImplRegisterProperty( BASEPROPERTY_ENABLEVISIBLE );
64 ImplRegisterProperty( BASEPROPERTY_HELPTEXT );
65 ImplRegisterProperty( BASEPROPERTY_HELPURL );
66 ImplRegisterProperty( BASEPROPERTY_ORIENTATION );
67 ImplRegisterProperty( BASEPROPERTY_PRINTABLE );
68 ImplRegisterProperty( BASEPROPERTY_REPEAT );
69 ImplRegisterProperty( BASEPROPERTY_REPEAT_DELAY );
70 ImplRegisterProperty( BASEPROPERTY_SYMBOL_COLOR );
71 ImplRegisterProperty( BASEPROPERTY_SPINVALUE );
72 ImplRegisterProperty( BASEPROPERTY_SPINVALUE_MIN );
73 ImplRegisterProperty( BASEPROPERTY_SPINVALUE_MAX );
74 ImplRegisterProperty( BASEPROPERTY_SPININCREMENT );
75 ImplRegisterProperty( BASEPROPERTY_TABSTOP );
76 ImplRegisterProperty( BASEPROPERTY_WRITING_MODE );
77 ImplRegisterProperty( BASEPROPERTY_CONTEXT_WRITING_MODE );
80 //--------------------------------------------------------------------
81 ::rtl::OUString UnoSpinButtonModel::getServiceName( ) throw (RuntimeException)
83 return ::rtl::OUString::createFromAscii( szServiceName_UnoSpinButtonModel );
86 //--------------------------------------------------------------------
87 Any UnoSpinButtonModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const
89 switch ( nPropId )
91 case BASEPROPERTY_DEFAULTCONTROL:
92 return makeAny( ::rtl::OUString::createFromAscii( szServiceName_UnoSpinButtonControl ) );
94 case BASEPROPERTY_BORDER:
95 return makeAny( (sal_Int16) 0 );
97 case BASEPROPERTY_REPEAT:
98 return makeAny( (sal_Bool)sal_True );
100 default:
101 return UnoControlModel::ImplGetDefaultValue( nPropId );
105 //--------------------------------------------------------------------
106 ::cppu::IPropertyArrayHelper& UnoSpinButtonModel::getInfoHelper()
108 static UnoPropertyArrayHelper* pHelper = NULL;
109 if ( !pHelper )
111 Sequence<sal_Int32> aIDs = ImplGetPropertyIds();
112 pHelper = new UnoPropertyArrayHelper( aIDs );
114 return *pHelper;
117 //--------------------------------------------------------------------
118 Reference< XPropertySetInfo > UnoSpinButtonModel::getPropertySetInfo( ) throw(RuntimeException)
120 static Reference< XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
121 return xInfo;
124 //--------------------------------------------------------------------
125 ::rtl::OUString SAL_CALL UnoSpinButtonModel::getImplementationName( ) throw(RuntimeException)
127 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.toolkit.UnoSpinButtonModel" ) );
130 //--------------------------------------------------------------------
131 Sequence< ::rtl::OUString > SAL_CALL UnoSpinButtonModel::getSupportedServiceNames() throw(RuntimeException)
133 Sequence< ::rtl::OUString > aServices( UnoControlModel::getSupportedServiceNames() );
134 aServices.realloc( aServices.getLength() + 1 );
135 aServices[ aServices.getLength() - 1 ] = ::rtl::OUString::createFromAscii( szServiceName_UnoSpinButtonModel );
136 return aServices;
139 //====================================================================
140 //= UnoSpinButtonControl
141 //====================================================================
142 //--------------------------------------------------------------------
143 UnoSpinButtonControl::UnoSpinButtonControl()
144 :maAdjustmentListeners( *this )
148 //--------------------------------------------------------------------
149 ::rtl::OUString UnoSpinButtonControl::GetComponentServiceName()
151 return ::rtl::OUString::createFromAscii( "SpinButton" );
154 //--------------------------------------------------------------------
155 Any UnoSpinButtonControl::queryAggregation( const Type & rType ) throw(RuntimeException)
157 Any aRet = UnoControlBase::queryAggregation( rType );
158 if ( !aRet.hasValue() )
159 aRet = UnoSpinButtonControl_Base::queryInterface( rType );
160 return aRet;
163 //--------------------------------------------------------------------
164 IMPLEMENT_FORWARD_XTYPEPROVIDER2( UnoSpinButtonControl, UnoControlBase, UnoSpinButtonControl_Base )
166 //--------------------------------------------------------------------
167 void UnoSpinButtonControl::dispose() throw(RuntimeException)
169 ::osl::ClearableMutexGuard aGuard( GetMutex() );
170 if ( maAdjustmentListeners.getLength() )
172 Reference< XSpinValue > xSpinnable( getPeer(), UNO_QUERY );
173 if ( xSpinnable.is() )
174 xSpinnable->removeAdjustmentListener( this );
176 EventObject aDisposeEvent;
177 aDisposeEvent.Source = *this;
179 aGuard.clear();
180 maAdjustmentListeners.disposeAndClear( aDisposeEvent );
183 UnoControl::dispose();
186 //--------------------------------------------------------------------
187 ::rtl::OUString SAL_CALL UnoSpinButtonControl::getImplementationName( ) throw(RuntimeException)
189 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.toolkit.UnoSpinButtonControl" ) );
192 //--------------------------------------------------------------------
193 Sequence< ::rtl::OUString > SAL_CALL UnoSpinButtonControl::getSupportedServiceNames() throw(RuntimeException)
195 Sequence< ::rtl::OUString > aServices( UnoControlBase::getSupportedServiceNames() );
196 aServices.realloc( aServices.getLength() + 1 );
197 aServices[ aServices.getLength() - 1 ] = ::rtl::OUString::createFromAscii( szServiceName_UnoSpinButtonControl );
198 return aServices;
201 //--------------------------------------------------------------------
202 void UnoSpinButtonControl::createPeer( const Reference< XToolkit > & rxToolkit, const Reference< XWindowPeer > & rParentPeer ) throw(RuntimeException)
204 UnoControl::createPeer( rxToolkit, rParentPeer );
206 Reference < XSpinValue > xSpinnable( getPeer(), UNO_QUERY );
207 if ( xSpinnable.is() )
208 xSpinnable->addAdjustmentListener( this );
211 //--------------------------------------------------------------------
212 void UnoSpinButtonControl::adjustmentValueChanged( const AdjustmentEvent& rEvent ) throw(RuntimeException)
214 switch ( rEvent.Type )
216 case AdjustmentType_ADJUST_LINE:
217 case AdjustmentType_ADJUST_PAGE:
218 case AdjustmentType_ADJUST_ABS:
219 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE ), makeAny( rEvent.Value ), sal_False );
220 break;
221 default:
222 DBG_ERROR( "UnoSpinButtonControl::adjustmentValueChanged - unknown Type" );
225 if ( maAdjustmentListeners.getLength() )
227 AdjustmentEvent aEvent( rEvent );
228 aEvent.Source = *this;
229 maAdjustmentListeners.adjustmentValueChanged( aEvent );
233 //--------------------------------------------------------------------
234 void UnoSpinButtonControl::addAdjustmentListener( const Reference< XAdjustmentListener > & listener ) throw(RuntimeException)
236 ::osl::MutexGuard aGuard( GetMutex() );
237 maAdjustmentListeners.addInterface( listener );
240 //--------------------------------------------------------------------
241 void UnoSpinButtonControl::removeAdjustmentListener( const Reference< XAdjustmentListener > & listener ) throw(RuntimeException)
243 ::osl::MutexGuard aGuard( GetMutex() );
244 maAdjustmentListeners.removeInterface( listener );
247 //--------------------------------------------------------------------
248 void SAL_CALL UnoSpinButtonControl::setValue( sal_Int32 value ) throw (RuntimeException)
250 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE ), makeAny( value ), sal_True );
253 //--------------------------------------------------------------------
254 void SAL_CALL UnoSpinButtonControl::setValues( sal_Int32 minValue, sal_Int32 maxValue, sal_Int32 currentValue ) throw (RuntimeException)
256 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE_MIN ), makeAny( minValue ), sal_True );
257 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE_MAX ), makeAny( maxValue ), sal_True );
258 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE ), makeAny( currentValue ), sal_True );
261 //--------------------------------------------------------------------
262 sal_Int32 SAL_CALL UnoSpinButtonControl::getValue( ) throw (RuntimeException)
264 ::osl::MutexGuard aGuard( GetMutex() );
265 sal_Int32 nValue = 0;
267 Reference< XSpinValue > xSpinnable( getPeer(), UNO_QUERY );
268 if ( xSpinnable.is() )
269 nValue = xSpinnable->getValue();
271 return nValue;
274 //--------------------------------------------------------------------
275 void SAL_CALL UnoSpinButtonControl::setMinimum( sal_Int32 minValue ) throw (RuntimeException)
277 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE_MIN ), makeAny( minValue ), sal_True );
280 //--------------------------------------------------------------------
281 void SAL_CALL UnoSpinButtonControl::setMaximum( sal_Int32 maxValue ) throw (RuntimeException)
283 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE_MAX ), makeAny( maxValue ), sal_True );
286 //--------------------------------------------------------------------
287 sal_Int32 SAL_CALL UnoSpinButtonControl::getMinimum( ) throw (RuntimeException)
289 ::osl::MutexGuard aGuard( GetMutex() );
290 sal_Int32 nMin = 0;
292 Reference< XSpinValue > xSpinnable( getPeer(), UNO_QUERY );
293 if ( xSpinnable.is() )
294 nMin = xSpinnable->getMinimum();
296 return nMin;
299 //--------------------------------------------------------------------
300 sal_Int32 SAL_CALL UnoSpinButtonControl::getMaximum( ) throw (RuntimeException)
302 ::osl::MutexGuard aGuard( GetMutex() );
303 sal_Int32 nMax = 0;
305 Reference< XSpinValue > xSpinnable( getPeer(), UNO_QUERY );
306 if ( xSpinnable.is() )
307 nMax = xSpinnable->getMaximum();
309 return nMax;
312 //--------------------------------------------------------------------
313 void SAL_CALL UnoSpinButtonControl::setSpinIncrement( sal_Int32 spinIncrement ) throw (RuntimeException)
315 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPININCREMENT ), makeAny( spinIncrement ), sal_True );
318 //--------------------------------------------------------------------
319 sal_Int32 SAL_CALL UnoSpinButtonControl::getSpinIncrement( ) throw (RuntimeException)
321 ::osl::MutexGuard aGuard( GetMutex() );
322 sal_Int32 nIncrement = 0;
324 Reference< XSpinValue > xSpinnable( getPeer(), UNO_QUERY );
325 if ( xSpinnable.is() )
326 nIncrement = xSpinnable->getSpinIncrement();
328 return nIncrement;
331 //--------------------------------------------------------------------
332 void SAL_CALL UnoSpinButtonControl::setOrientation( sal_Int32 orientation ) throw (NoSupportException, RuntimeException)
334 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_ORIENTATION ), makeAny( orientation ), sal_True );
337 //--------------------------------------------------------------------
338 sal_Int32 SAL_CALL UnoSpinButtonControl::getOrientation( ) throw (RuntimeException)
340 ::osl::MutexGuard aGuard( GetMutex() );
341 sal_Int32 nOrientation = ScrollBarOrientation::HORIZONTAL;
343 Reference< XSpinValue > xSpinnable( getPeer(), UNO_QUERY );
344 if ( xSpinnable.is() )
345 nOrientation = xSpinnable->getOrientation();
347 return nOrientation;
350 //........................................................................
351 } // namespace toolkit
352 //........................................................................