Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "toolkit/controls/tkspinbutton.hxx"
30 : : #include "toolkit/helper/property.hxx"
31 : : #include "toolkit/helper/unopropertyarrayhelper.hxx"
32 : : #include <com/sun/star/awt/ScrollBarOrientation.hpp>
33 : :
34 : :
35 : : #include <cppuhelper/typeprovider.hxx>
36 : :
37 : : //........................................................................
38 : : namespace toolkit
39 : : {
40 : : //........................................................................
41 : :
42 : : using namespace ::com::sun::star::uno;
43 : : using namespace ::com::sun::star::awt;
44 : : using namespace ::com::sun::star::lang;
45 : : using namespace ::com::sun::star::beans;
46 : :
47 : : //====================================================================
48 : : //= UnoSpinButtonModel
49 : : //====================================================================
50 : : //--------------------------------------------------------------------
51 : 18 : UnoSpinButtonModel::UnoSpinButtonModel( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& i_factory )
52 : 18 : :UnoControlModel( i_factory )
53 : : {
54 [ + - ]: 18 : ImplRegisterProperty( BASEPROPERTY_BACKGROUNDCOLOR );
55 [ + - ]: 18 : ImplRegisterProperty( BASEPROPERTY_BORDER );
56 [ + - ]: 18 : ImplRegisterProperty( BASEPROPERTY_BORDERCOLOR );
57 [ + - ]: 18 : ImplRegisterProperty( BASEPROPERTY_DEFAULTCONTROL );
58 [ + - ]: 18 : ImplRegisterProperty( BASEPROPERTY_ENABLED );
59 [ + - ]: 18 : ImplRegisterProperty( BASEPROPERTY_ENABLEVISIBLE );
60 [ + - ]: 18 : ImplRegisterProperty( BASEPROPERTY_HELPTEXT );
61 [ + - ]: 18 : ImplRegisterProperty( BASEPROPERTY_HELPURL );
62 [ + - ]: 18 : ImplRegisterProperty( BASEPROPERTY_ORIENTATION );
63 [ + - ]: 18 : ImplRegisterProperty( BASEPROPERTY_PRINTABLE );
64 [ + - ]: 18 : ImplRegisterProperty( BASEPROPERTY_REPEAT );
65 [ + - ]: 18 : ImplRegisterProperty( BASEPROPERTY_REPEAT_DELAY );
66 [ + - ]: 18 : ImplRegisterProperty( BASEPROPERTY_SYMBOL_COLOR );
67 [ + - ]: 18 : ImplRegisterProperty( BASEPROPERTY_SPINVALUE );
68 [ + - ]: 18 : ImplRegisterProperty( BASEPROPERTY_SPINVALUE_MIN );
69 [ + - ]: 18 : ImplRegisterProperty( BASEPROPERTY_SPINVALUE_MAX );
70 [ + - ]: 18 : ImplRegisterProperty( BASEPROPERTY_SPININCREMENT );
71 [ + - ]: 18 : ImplRegisterProperty( BASEPROPERTY_TABSTOP );
72 [ + - ]: 18 : ImplRegisterProperty( BASEPROPERTY_WRITING_MODE );
73 [ + - ]: 18 : ImplRegisterProperty( BASEPROPERTY_CONTEXT_WRITING_MODE );
74 : 18 : }
75 : :
76 : : //--------------------------------------------------------------------
77 : 2 : ::rtl::OUString UnoSpinButtonModel::getServiceName( ) throw (RuntimeException)
78 : : {
79 : 2 : return ::rtl::OUString::createFromAscii( szServiceName_UnoSpinButtonModel );
80 : : }
81 : :
82 : : //--------------------------------------------------------------------
83 : 444 : Any UnoSpinButtonModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const
84 : : {
85 [ + + + + ]: 444 : switch ( nPropId )
86 : : {
87 : : case BASEPROPERTY_DEFAULTCONTROL:
88 [ + - ]: 22 : return makeAny( ::rtl::OUString::createFromAscii( szServiceName_UnoSpinButtonControl ) );
89 : :
90 : : case BASEPROPERTY_BORDER:
91 [ + - ]: 22 : return makeAny( (sal_Int16) 0 );
92 : :
93 : : case BASEPROPERTY_REPEAT:
94 [ + - ]: 22 : return makeAny( (sal_Bool)sal_True );
95 : :
96 : : default:
97 : 444 : return UnoControlModel::ImplGetDefaultValue( nPropId );
98 : : }
99 : : }
100 : :
101 : : //--------------------------------------------------------------------
102 : 3933 : ::cppu::IPropertyArrayHelper& UnoSpinButtonModel::getInfoHelper()
103 : : {
104 : : static UnoPropertyArrayHelper* pHelper = NULL;
105 [ + + ]: 3933 : if ( !pHelper )
106 : : {
107 [ + - ]: 4 : Sequence<sal_Int32> aIDs = ImplGetPropertyIds();
108 [ + - ][ + - ]: 4 : pHelper = new UnoPropertyArrayHelper( aIDs );
109 : : }
110 : 3933 : return *pHelper;
111 : : }
112 : :
113 : : //--------------------------------------------------------------------
114 : 110 : Reference< XPropertySetInfo > UnoSpinButtonModel::getPropertySetInfo( ) throw(RuntimeException)
115 : : {
116 [ + + ][ + - ]: 110 : static Reference< XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
[ + - ][ + - ]
[ # # ]
117 : 110 : return xInfo;
118 : : }
119 : :
120 : : //--------------------------------------------------------------------
121 : 8 : ::rtl::OUString SAL_CALL UnoSpinButtonModel::getImplementationName( ) throw(RuntimeException)
122 : : {
123 : 8 : return ::rtl::OUString( "com.sun.star.comp.toolkit.UnoSpinButtonModel" );
124 : : }
125 : :
126 : : //--------------------------------------------------------------------
127 : 18 : Sequence< ::rtl::OUString > SAL_CALL UnoSpinButtonModel::getSupportedServiceNames() throw(RuntimeException)
128 : : {
129 : 18 : Sequence< ::rtl::OUString > aServices( UnoControlModel::getSupportedServiceNames() );
130 [ + - ]: 18 : aServices.realloc( aServices.getLength() + 1 );
131 [ + - ]: 18 : aServices[ aServices.getLength() - 1 ] = ::rtl::OUString::createFromAscii( szServiceName_UnoSpinButtonModel );
132 : 18 : return aServices;
133 : : }
134 : :
135 : : //====================================================================
136 : : //= UnoSpinButtonControl
137 : : //====================================================================
138 : : //--------------------------------------------------------------------
139 : 2 : UnoSpinButtonControl::UnoSpinButtonControl( const Reference< XMultiServiceFactory >& i_factory )
140 : : :UnoControlBase( i_factory )
141 [ + - ]: 2 : ,maAdjustmentListeners( *this )
142 : : {
143 : 2 : }
144 : :
145 : : //--------------------------------------------------------------------
146 : 2 : ::rtl::OUString UnoSpinButtonControl::GetComponentServiceName()
147 : : {
148 : 2 : return ::rtl::OUString("SpinButton");
149 : : }
150 : :
151 : : //--------------------------------------------------------------------
152 : 62 : Any UnoSpinButtonControl::queryAggregation( const Type & rType ) throw(RuntimeException)
153 : : {
154 : 62 : Any aRet = UnoControlBase::queryAggregation( rType );
155 [ + + ]: 62 : if ( !aRet.hasValue() )
156 [ + - ]: 4 : aRet = UnoSpinButtonControl_Base::queryInterface( rType );
157 : 62 : return aRet;
158 : : }
159 : :
160 : : //--------------------------------------------------------------------
161 [ # # ][ # # ]: 0 : IMPLEMENT_FORWARD_XTYPEPROVIDER2( UnoSpinButtonControl, UnoControlBase, UnoSpinButtonControl_Base )
[ # # ]
162 : :
163 : : //--------------------------------------------------------------------
164 : 2 : void UnoSpinButtonControl::dispose() throw(RuntimeException)
165 : : {
166 [ + - ]: 2 : ::osl::ClearableMutexGuard aGuard( GetMutex() );
167 [ + - ][ - + ]: 2 : if ( maAdjustmentListeners.getLength() )
168 : : {
169 [ # # ][ # # ]: 0 : Reference< XSpinValue > xSpinnable( getPeer(), UNO_QUERY );
170 [ # # ]: 0 : if ( xSpinnable.is() )
171 [ # # ][ # # ]: 0 : xSpinnable->removeAdjustmentListener( this );
[ # # ]
172 : :
173 [ # # ]: 0 : EventObject aDisposeEvent;
174 [ # # ][ # # ]: 0 : aDisposeEvent.Source = *this;
175 : :
176 [ # # ]: 0 : aGuard.clear();
177 [ # # ][ # # ]: 0 : maAdjustmentListeners.disposeAndClear( aDisposeEvent );
178 : : }
179 : :
180 [ + - ][ + - ]: 2 : UnoControl::dispose();
181 : 2 : }
182 : :
183 : : //--------------------------------------------------------------------
184 : 2 : ::rtl::OUString SAL_CALL UnoSpinButtonControl::getImplementationName( ) throw(RuntimeException)
185 : : {
186 : 2 : return ::rtl::OUString( "com.sun.star.comp.toolkit.UnoSpinButtonControl" );
187 : : }
188 : :
189 : : //--------------------------------------------------------------------
190 : 0 : Sequence< ::rtl::OUString > SAL_CALL UnoSpinButtonControl::getSupportedServiceNames() throw(RuntimeException)
191 : : {
192 : 0 : Sequence< ::rtl::OUString > aServices( UnoControlBase::getSupportedServiceNames() );
193 [ # # ]: 0 : aServices.realloc( aServices.getLength() + 1 );
194 [ # # ]: 0 : aServices[ aServices.getLength() - 1 ] = ::rtl::OUString::createFromAscii( szServiceName_UnoSpinButtonControl );
195 : 0 : return aServices;
196 : : }
197 : :
198 : : //--------------------------------------------------------------------
199 : 4 : void UnoSpinButtonControl::createPeer( const Reference< XToolkit > & rxToolkit, const Reference< XWindowPeer > & rParentPeer ) throw(RuntimeException)
200 : : {
201 [ + - ]: 4 : UnoControl::createPeer( rxToolkit, rParentPeer );
202 : :
203 [ + - ][ + - ]: 4 : Reference < XSpinValue > xSpinnable( getPeer(), UNO_QUERY );
204 [ + - ]: 4 : if ( xSpinnable.is() )
205 [ + - ][ + - ]: 4 : xSpinnable->addAdjustmentListener( this );
[ + - ]
206 : 4 : }
207 : :
208 : : //--------------------------------------------------------------------
209 : 0 : void UnoSpinButtonControl::adjustmentValueChanged( const AdjustmentEvent& rEvent ) throw(RuntimeException)
210 : : {
211 [ # # ]: 0 : switch ( rEvent.Type )
212 : : {
213 : : case AdjustmentType_ADJUST_LINE:
214 : : case AdjustmentType_ADJUST_PAGE:
215 : : case AdjustmentType_ADJUST_ABS:
216 [ # # ][ # # ]: 0 : ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE ), makeAny( rEvent.Value ), sal_False );
217 : 0 : break;
218 : : default:
219 : : OSL_FAIL( "UnoSpinButtonControl::adjustmentValueChanged - unknown Type" );
220 : : }
221 : :
222 [ # # ]: 0 : if ( maAdjustmentListeners.getLength() )
223 : : {
224 [ # # ]: 0 : AdjustmentEvent aEvent( rEvent );
225 [ # # ][ # # ]: 0 : aEvent.Source = *this;
226 [ # # ][ # # ]: 0 : maAdjustmentListeners.adjustmentValueChanged( aEvent );
227 : : }
228 : 0 : }
229 : :
230 : : //--------------------------------------------------------------------
231 : 0 : void UnoSpinButtonControl::addAdjustmentListener( const Reference< XAdjustmentListener > & listener ) throw(RuntimeException)
232 : : {
233 [ # # ]: 0 : ::osl::MutexGuard aGuard( GetMutex() );
234 [ # # ][ # # ]: 0 : maAdjustmentListeners.addInterface( listener );
235 : 0 : }
236 : :
237 : : //--------------------------------------------------------------------
238 : 0 : void UnoSpinButtonControl::removeAdjustmentListener( const Reference< XAdjustmentListener > & listener ) throw(RuntimeException)
239 : : {
240 [ # # ]: 0 : ::osl::MutexGuard aGuard( GetMutex() );
241 [ # # ][ # # ]: 0 : maAdjustmentListeners.removeInterface( listener );
242 : 0 : }
243 : :
244 : : //--------------------------------------------------------------------
245 : 0 : void SAL_CALL UnoSpinButtonControl::setValue( sal_Int32 value ) throw (RuntimeException)
246 : : {
247 [ # # ][ # # ]: 0 : ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE ), makeAny( value ), sal_True );
248 : 0 : }
249 : :
250 : : //--------------------------------------------------------------------
251 : 0 : void SAL_CALL UnoSpinButtonControl::setValues( sal_Int32 minValue, sal_Int32 maxValue, sal_Int32 currentValue ) throw (RuntimeException)
252 : : {
253 [ # # ][ # # ]: 0 : ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE_MIN ), makeAny( minValue ), sal_True );
254 [ # # ][ # # ]: 0 : ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE_MAX ), makeAny( maxValue ), sal_True );
255 [ # # ][ # # ]: 0 : ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE ), makeAny( currentValue ), sal_True );
256 : 0 : }
257 : :
258 : : //--------------------------------------------------------------------
259 : 0 : sal_Int32 SAL_CALL UnoSpinButtonControl::getValue( ) throw (RuntimeException)
260 : : {
261 [ # # ]: 0 : ::osl::MutexGuard aGuard( GetMutex() );
262 : 0 : sal_Int32 nValue = 0;
263 : :
264 [ # # ][ # # ]: 0 : Reference< XSpinValue > xSpinnable( getPeer(), UNO_QUERY );
265 [ # # ]: 0 : if ( xSpinnable.is() )
266 [ # # ][ # # ]: 0 : nValue = xSpinnable->getValue();
267 : :
268 [ # # ]: 0 : return nValue;
269 : : }
270 : :
271 : : //--------------------------------------------------------------------
272 : 0 : void SAL_CALL UnoSpinButtonControl::setMinimum( sal_Int32 minValue ) throw (RuntimeException)
273 : : {
274 [ # # ][ # # ]: 0 : ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE_MIN ), makeAny( minValue ), sal_True );
275 : 0 : }
276 : :
277 : : //--------------------------------------------------------------------
278 : 0 : void SAL_CALL UnoSpinButtonControl::setMaximum( sal_Int32 maxValue ) throw (RuntimeException)
279 : : {
280 [ # # ][ # # ]: 0 : ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE_MAX ), makeAny( maxValue ), sal_True );
281 : 0 : }
282 : :
283 : : //--------------------------------------------------------------------
284 : 0 : sal_Int32 SAL_CALL UnoSpinButtonControl::getMinimum( ) throw (RuntimeException)
285 : : {
286 [ # # ]: 0 : ::osl::MutexGuard aGuard( GetMutex() );
287 : 0 : sal_Int32 nMin = 0;
288 : :
289 [ # # ][ # # ]: 0 : Reference< XSpinValue > xSpinnable( getPeer(), UNO_QUERY );
290 [ # # ]: 0 : if ( xSpinnable.is() )
291 [ # # ][ # # ]: 0 : nMin = xSpinnable->getMinimum();
292 : :
293 [ # # ]: 0 : return nMin;
294 : : }
295 : :
296 : : //--------------------------------------------------------------------
297 : 0 : sal_Int32 SAL_CALL UnoSpinButtonControl::getMaximum( ) throw (RuntimeException)
298 : : {
299 [ # # ]: 0 : ::osl::MutexGuard aGuard( GetMutex() );
300 : 0 : sal_Int32 nMax = 0;
301 : :
302 [ # # ][ # # ]: 0 : Reference< XSpinValue > xSpinnable( getPeer(), UNO_QUERY );
303 [ # # ]: 0 : if ( xSpinnable.is() )
304 [ # # ][ # # ]: 0 : nMax = xSpinnable->getMaximum();
305 : :
306 [ # # ]: 0 : return nMax;
307 : : }
308 : :
309 : : //--------------------------------------------------------------------
310 : 0 : void SAL_CALL UnoSpinButtonControl::setSpinIncrement( sal_Int32 spinIncrement ) throw (RuntimeException)
311 : : {
312 [ # # ][ # # ]: 0 : ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPININCREMENT ), makeAny( spinIncrement ), sal_True );
313 : 0 : }
314 : :
315 : : //--------------------------------------------------------------------
316 : 0 : sal_Int32 SAL_CALL UnoSpinButtonControl::getSpinIncrement( ) throw (RuntimeException)
317 : : {
318 [ # # ]: 0 : ::osl::MutexGuard aGuard( GetMutex() );
319 : 0 : sal_Int32 nIncrement = 0;
320 : :
321 [ # # ][ # # ]: 0 : Reference< XSpinValue > xSpinnable( getPeer(), UNO_QUERY );
322 [ # # ]: 0 : if ( xSpinnable.is() )
323 [ # # ][ # # ]: 0 : nIncrement = xSpinnable->getSpinIncrement();
324 : :
325 [ # # ]: 0 : return nIncrement;
326 : : }
327 : :
328 : : //--------------------------------------------------------------------
329 : 0 : void SAL_CALL UnoSpinButtonControl::setOrientation( sal_Int32 orientation ) throw (NoSupportException, RuntimeException)
330 : : {
331 [ # # ][ # # ]: 0 : ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_ORIENTATION ), makeAny( orientation ), sal_True );
332 : 0 : }
333 : :
334 : : //--------------------------------------------------------------------
335 : 0 : sal_Int32 SAL_CALL UnoSpinButtonControl::getOrientation( ) throw (RuntimeException)
336 : : {
337 [ # # ]: 0 : ::osl::MutexGuard aGuard( GetMutex() );
338 : 0 : sal_Int32 nOrientation = ScrollBarOrientation::HORIZONTAL;
339 : :
340 [ # # ][ # # ]: 0 : Reference< XSpinValue > xSpinnable( getPeer(), UNO_QUERY );
341 [ # # ]: 0 : if ( xSpinnable.is() )
342 [ # # ][ # # ]: 0 : nOrientation = xSpinnable->getOrientation();
343 : :
344 [ # # ]: 0 : return nOrientation;
345 : : }
346 : :
347 : : //........................................................................
348 : : } // namespace toolkit
349 : : //........................................................................
350 : :
351 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|