xref: /AOO41X/main/toolkit/source/controls/tkspinbutton.cxx (revision b0724fc6948542b2496e16ea247f985ee5987cfe)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_toolkit.hxx"
26 #include "toolkit/controls/tkspinbutton.hxx"
27 #include "toolkit/helper/property.hxx"
28 #include "toolkit/helper/unopropertyarrayhelper.hxx"
29 #include <com/sun/star/awt/ScrollBarOrientation.hpp>
30 
31 
32 #include <cppuhelper/typeprovider.hxx>
33 #include <tools/debug.hxx>
34 
35 //........................................................................
36 namespace toolkit
37 {
38 //........................................................................
39 
40     using namespace ::com::sun::star::uno;
41     using namespace ::com::sun::star::awt;
42     using namespace ::com::sun::star::lang;
43     using namespace ::com::sun::star::beans;
44 
45     //====================================================================
46     //= UnoSpinButtonModel
47     //====================================================================
48     //--------------------------------------------------------------------
UnoSpinButtonModel(const::com::sun::star::uno::Reference<::com::sun::star::lang::XMultiServiceFactory> & i_factory)49     UnoSpinButtonModel::UnoSpinButtonModel( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& i_factory )
50         :UnoControlModel( i_factory )
51     {
52         ImplRegisterProperty( BASEPROPERTY_BACKGROUNDCOLOR );
53         ImplRegisterProperty( BASEPROPERTY_BORDER );
54         ImplRegisterProperty( BASEPROPERTY_BORDERCOLOR );
55         ImplRegisterProperty( BASEPROPERTY_DEFAULTCONTROL );
56         ImplRegisterProperty( BASEPROPERTY_ENABLED );
57         ImplRegisterProperty( BASEPROPERTY_ENABLEVISIBLE );
58         ImplRegisterProperty( BASEPROPERTY_HELPTEXT );
59         ImplRegisterProperty( BASEPROPERTY_HELPURL );
60         ImplRegisterProperty( BASEPROPERTY_ORIENTATION );
61         ImplRegisterProperty( BASEPROPERTY_PRINTABLE );
62         ImplRegisterProperty( BASEPROPERTY_REPEAT );
63         ImplRegisterProperty( BASEPROPERTY_REPEAT_DELAY );
64         ImplRegisterProperty( BASEPROPERTY_SYMBOL_COLOR );
65         ImplRegisterProperty( BASEPROPERTY_SPINVALUE );
66         ImplRegisterProperty( BASEPROPERTY_SPINVALUE_MIN );
67         ImplRegisterProperty( BASEPROPERTY_SPINVALUE_MAX );
68         ImplRegisterProperty( BASEPROPERTY_SPININCREMENT );
69         ImplRegisterProperty( BASEPROPERTY_TABSTOP );
70         ImplRegisterProperty( BASEPROPERTY_WRITING_MODE );
71         ImplRegisterProperty( BASEPROPERTY_CONTEXT_WRITING_MODE );
72     }
73 
74     //--------------------------------------------------------------------
getServiceName()75     ::rtl::OUString UnoSpinButtonModel::getServiceName( ) throw (RuntimeException)
76     {
77         return ::rtl::OUString::createFromAscii( szServiceName_UnoSpinButtonModel );
78     }
79 
80     //--------------------------------------------------------------------
ImplGetDefaultValue(sal_uInt16 nPropId) const81     Any UnoSpinButtonModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const
82     {
83         switch ( nPropId )
84         {
85         case BASEPROPERTY_DEFAULTCONTROL:
86             return makeAny( ::rtl::OUString::createFromAscii( szServiceName_UnoSpinButtonControl ) );
87 
88         case BASEPROPERTY_BORDER:
89             return makeAny( (sal_Int16) 0 );
90 
91         case BASEPROPERTY_REPEAT:
92             return makeAny( (sal_Bool)sal_True );
93 
94         default:
95             return UnoControlModel::ImplGetDefaultValue( nPropId );
96         }
97     }
98 
99     //--------------------------------------------------------------------
getInfoHelper()100     ::cppu::IPropertyArrayHelper& UnoSpinButtonModel::getInfoHelper()
101     {
102         static UnoPropertyArrayHelper* pHelper = NULL;
103         if ( !pHelper )
104         {
105             Sequence<sal_Int32> aIDs = ImplGetPropertyIds();
106             pHelper = new UnoPropertyArrayHelper( aIDs );
107         }
108         return *pHelper;
109     }
110 
111     //--------------------------------------------------------------------
getPropertySetInfo()112     Reference< XPropertySetInfo > UnoSpinButtonModel::getPropertySetInfo(  ) throw(RuntimeException)
113     {
114         static Reference< XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
115         return xInfo;
116     }
117 
118     //--------------------------------------------------------------------
getImplementationName()119     ::rtl::OUString SAL_CALL UnoSpinButtonModel::getImplementationName(  ) throw(RuntimeException)
120     {
121         return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.toolkit.UnoSpinButtonModel" ) );
122     }
123 
124     //--------------------------------------------------------------------
getSupportedServiceNames()125     Sequence< ::rtl::OUString > SAL_CALL UnoSpinButtonModel::getSupportedServiceNames() throw(RuntimeException)
126     {
127         Sequence< ::rtl::OUString > aServices( UnoControlModel::getSupportedServiceNames() );
128         aServices.realloc( aServices.getLength() + 1 );
129         aServices[ aServices.getLength() - 1 ] = ::rtl::OUString::createFromAscii( szServiceName_UnoSpinButtonModel );
130         return aServices;
131     }
132 
133     //====================================================================
134     //= UnoSpinButtonControl
135     //====================================================================
136     //--------------------------------------------------------------------
UnoSpinButtonControl(const Reference<XMultiServiceFactory> & i_factory)137     UnoSpinButtonControl::UnoSpinButtonControl( const Reference< XMultiServiceFactory >& i_factory )
138         :UnoControlBase( i_factory )
139         ,maAdjustmentListeners( *this )
140     {
141     }
142 
143     //--------------------------------------------------------------------
GetComponentServiceName()144     ::rtl::OUString UnoSpinButtonControl::GetComponentServiceName()
145     {
146         return ::rtl::OUString::createFromAscii( "SpinButton" );
147     }
148 
149     //--------------------------------------------------------------------
queryAggregation(const Type & rType)150     Any UnoSpinButtonControl::queryAggregation( const Type & rType ) throw(RuntimeException)
151     {
152         Any aRet = UnoControlBase::queryAggregation( rType );
153         if ( !aRet.hasValue() )
154             aRet = UnoSpinButtonControl_Base::queryInterface( rType );
155         return aRet;
156     }
157 
158     //--------------------------------------------------------------------
IMPLEMENT_FORWARD_XTYPEPROVIDER2(UnoSpinButtonControl,UnoControlBase,UnoSpinButtonControl_Base)159     IMPLEMENT_FORWARD_XTYPEPROVIDER2( UnoSpinButtonControl, UnoControlBase, UnoSpinButtonControl_Base )
160 
161     //--------------------------------------------------------------------
162     void UnoSpinButtonControl::dispose() throw(RuntimeException)
163     {
164         ::osl::ClearableMutexGuard aGuard( GetMutex() );
165         if ( maAdjustmentListeners.getLength() )
166         {
167             Reference< XSpinValue > xSpinnable( getPeer(), UNO_QUERY );
168             if ( xSpinnable.is() )
169                 xSpinnable->removeAdjustmentListener( this );
170 
171             EventObject aDisposeEvent;
172             aDisposeEvent.Source = *this;
173 
174             aGuard.clear();
175             maAdjustmentListeners.disposeAndClear( aDisposeEvent );
176         }
177 
178         UnoControl::dispose();
179     }
180 
181     //--------------------------------------------------------------------
getImplementationName()182     ::rtl::OUString SAL_CALL UnoSpinButtonControl::getImplementationName(  ) throw(RuntimeException)
183     {
184         return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.toolkit.UnoSpinButtonControl" ) );
185     }
186 
187     //--------------------------------------------------------------------
getSupportedServiceNames()188     Sequence< ::rtl::OUString > SAL_CALL UnoSpinButtonControl::getSupportedServiceNames() throw(RuntimeException)
189     {
190         Sequence< ::rtl::OUString > aServices( UnoControlBase::getSupportedServiceNames() );
191         aServices.realloc( aServices.getLength() + 1 );
192         aServices[ aServices.getLength() - 1 ] = ::rtl::OUString::createFromAscii( szServiceName_UnoSpinButtonControl );
193         return aServices;
194     }
195 
196     //--------------------------------------------------------------------
createPeer(const Reference<XToolkit> & rxToolkit,const Reference<XWindowPeer> & rParentPeer)197     void UnoSpinButtonControl::createPeer( const Reference< XToolkit > & rxToolkit, const Reference< XWindowPeer >  & rParentPeer ) throw(RuntimeException)
198     {
199         UnoControl::createPeer( rxToolkit, rParentPeer );
200 
201         Reference < XSpinValue > xSpinnable( getPeer(), UNO_QUERY );
202         if ( xSpinnable.is() )
203             xSpinnable->addAdjustmentListener( this );
204     }
205 
206     //--------------------------------------------------------------------
adjustmentValueChanged(const AdjustmentEvent & rEvent)207     void UnoSpinButtonControl::adjustmentValueChanged( const AdjustmentEvent& rEvent ) throw(RuntimeException)
208     {
209         switch ( rEvent.Type )
210         {
211             case AdjustmentType_ADJUST_LINE:
212             case AdjustmentType_ADJUST_PAGE:
213             case AdjustmentType_ADJUST_ABS:
214                 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE ), makeAny( rEvent.Value ), sal_False );
215                 break;
216             default:
217                 DBG_ERROR( "UnoSpinButtonControl::adjustmentValueChanged - unknown Type" );
218         }
219 
220         if ( maAdjustmentListeners.getLength() )
221         {
222             AdjustmentEvent aEvent( rEvent );
223             aEvent.Source = *this;
224             maAdjustmentListeners.adjustmentValueChanged( aEvent );
225         }
226     }
227 
228     //--------------------------------------------------------------------
addAdjustmentListener(const Reference<XAdjustmentListener> & listener)229     void UnoSpinButtonControl::addAdjustmentListener( const Reference< XAdjustmentListener > & listener ) throw(RuntimeException)
230     {
231         ::osl::MutexGuard aGuard( GetMutex() );
232         maAdjustmentListeners.addInterface( listener );
233     }
234 
235     //--------------------------------------------------------------------
removeAdjustmentListener(const Reference<XAdjustmentListener> & listener)236     void UnoSpinButtonControl::removeAdjustmentListener( const Reference< XAdjustmentListener > & listener ) throw(RuntimeException)
237     {
238         ::osl::MutexGuard aGuard( GetMutex() );
239         maAdjustmentListeners.removeInterface( listener );
240     }
241 
242     //--------------------------------------------------------------------
setValue(sal_Int32 value)243     void SAL_CALL UnoSpinButtonControl::setValue( sal_Int32 value ) throw (RuntimeException)
244     {
245         ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE ), makeAny( value ), sal_True );
246     }
247 
248     //--------------------------------------------------------------------
setValues(sal_Int32 minValue,sal_Int32 maxValue,sal_Int32 currentValue)249     void SAL_CALL UnoSpinButtonControl::setValues( sal_Int32 minValue, sal_Int32 maxValue, sal_Int32 currentValue ) throw (RuntimeException)
250     {
251         ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE_MIN ), makeAny( minValue ), sal_True );
252         ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE_MAX ), makeAny( maxValue ), sal_True );
253         ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE ), makeAny( currentValue ), sal_True );
254     }
255 
256     //--------------------------------------------------------------------
getValue()257     sal_Int32 SAL_CALL UnoSpinButtonControl::getValue(  ) throw (RuntimeException)
258     {
259         ::osl::MutexGuard aGuard( GetMutex() );
260         sal_Int32 nValue = 0;
261 
262         Reference< XSpinValue > xSpinnable( getPeer(), UNO_QUERY );
263         if ( xSpinnable.is() )
264             nValue = xSpinnable->getValue();
265 
266         return nValue;
267     }
268 
269     //--------------------------------------------------------------------
setMinimum(sal_Int32 minValue)270     void SAL_CALL UnoSpinButtonControl::setMinimum( sal_Int32 minValue ) throw (RuntimeException)
271     {
272         ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE_MIN ), makeAny( minValue ), sal_True );
273     }
274 
275     //--------------------------------------------------------------------
setMaximum(sal_Int32 maxValue)276     void SAL_CALL UnoSpinButtonControl::setMaximum( sal_Int32 maxValue ) throw (RuntimeException)
277     {
278         ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE_MAX ), makeAny( maxValue ), sal_True );
279     }
280 
281     //--------------------------------------------------------------------
getMinimum()282     sal_Int32 SAL_CALL UnoSpinButtonControl::getMinimum(  ) throw (RuntimeException)
283     {
284         ::osl::MutexGuard aGuard( GetMutex() );
285         sal_Int32 nMin = 0;
286 
287         Reference< XSpinValue > xSpinnable( getPeer(), UNO_QUERY );
288         if ( xSpinnable.is() )
289             nMin = xSpinnable->getMinimum();
290 
291         return nMin;
292     }
293 
294     //--------------------------------------------------------------------
getMaximum()295     sal_Int32 SAL_CALL UnoSpinButtonControl::getMaximum(  ) throw (RuntimeException)
296     {
297         ::osl::MutexGuard aGuard( GetMutex() );
298         sal_Int32 nMax = 0;
299 
300         Reference< XSpinValue > xSpinnable( getPeer(), UNO_QUERY );
301         if ( xSpinnable.is() )
302             nMax = xSpinnable->getMaximum();
303 
304         return nMax;
305     }
306 
307     //--------------------------------------------------------------------
setSpinIncrement(sal_Int32 spinIncrement)308     void SAL_CALL UnoSpinButtonControl::setSpinIncrement( sal_Int32 spinIncrement ) throw (RuntimeException)
309     {
310         ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPININCREMENT ), makeAny( spinIncrement ), sal_True );
311     }
312 
313     //--------------------------------------------------------------------
getSpinIncrement()314     sal_Int32 SAL_CALL UnoSpinButtonControl::getSpinIncrement(  ) throw (RuntimeException)
315     {
316         ::osl::MutexGuard aGuard( GetMutex() );
317         sal_Int32 nIncrement = 0;
318 
319         Reference< XSpinValue > xSpinnable( getPeer(), UNO_QUERY );
320         if ( xSpinnable.is() )
321             nIncrement = xSpinnable->getSpinIncrement();
322 
323         return nIncrement;
324     }
325 
326     //--------------------------------------------------------------------
setOrientation(sal_Int32 orientation)327     void SAL_CALL UnoSpinButtonControl::setOrientation( sal_Int32 orientation ) throw (NoSupportException, RuntimeException)
328     {
329         ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_ORIENTATION ), makeAny( orientation ), sal_True );
330     }
331 
332     //--------------------------------------------------------------------
getOrientation()333     sal_Int32 SAL_CALL UnoSpinButtonControl::getOrientation(  ) throw (RuntimeException)
334     {
335         ::osl::MutexGuard aGuard( GetMutex() );
336         sal_Int32 nOrientation = ScrollBarOrientation::HORIZONTAL;
337 
338         Reference< XSpinValue > xSpinnable( getPeer(), UNO_QUERY );
339         if ( xSpinnable.is() )
340             nOrientation = xSpinnable->getOrientation();
341 
342         return nOrientation;
343     }
344 
345 //........................................................................
346 }  // namespace toolkit
347 //........................................................................
348 
349