Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
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>
24 :
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>
32 :
33 : #include "helper/unopropertyarrayhelper.hxx"
34 :
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;
39 :
40 : namespace {
41 :
42 44 : class UnoSpinButtonModel : public UnoControlModel
43 : {
44 : protected:
45 : css::uno::Any ImplGetDefaultValue( sal_uInt16 nPropId ) const SAL_OVERRIDE;
46 : ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper() SAL_OVERRIDE;
47 :
48 : public:
49 : UnoSpinButtonModel( const css::uno::Reference< css::uno::XComponentContext >& i_factory );
50 4 : UnoSpinButtonModel( const UnoSpinButtonModel& rModel ) : UnoControlModel( rModel ) {;}
51 :
52 4 : UnoControlModel* Clone() const SAL_OVERRIDE { return new UnoSpinButtonModel( *this ); }
53 :
54 : // XMultiPropertySet
55 : css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
56 :
57 : // XPersistObject
58 : OUString SAL_CALL getServiceName() throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
59 :
60 : // XServiceInfo
61 : OUString SAL_CALL getImplementationName( ) throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
62 : css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
63 : };
64 :
65 :
66 : //= UnoSpinButtonControl
67 :
68 :
69 : typedef ::cppu::ImplHelper2 < css::awt::XAdjustmentListener
70 : , css::awt::XSpinValue
71 : > UnoSpinButtonControl_Base;
72 :
73 4 : class UnoSpinButtonControl :public UnoControlBase
74 : ,public UnoSpinButtonControl_Base
75 : {
76 : private:
77 : AdjustmentListenerMultiplexer maAdjustmentListeners;
78 :
79 : public:
80 : UnoSpinButtonControl();
81 : OUString GetComponentServiceName() SAL_OVERRIDE;
82 :
83 514 : DECLARE_UNO3_AGG_DEFAULTS( UnoSpinButtonControl, UnoControlBase )
84 : css::uno::Any SAL_CALL queryAggregation( const css::uno::Type & rType ) throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
85 :
86 : void SAL_CALL createPeer( const css::uno::Reference< css::awt::XToolkit >& Toolkit, const css::uno::Reference< css::awt::XWindowPeer >& Parent ) throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
87 4 : void SAL_CALL disposing( const css::lang::EventObject& Source ) throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE { UnoControlBase::disposing( Source ); }
88 : void SAL_CALL dispose( ) throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
89 :
90 : // XTypeProvider
91 : DECLARE_XTYPEPROVIDER()
92 :
93 : // XAdjustmentListener
94 : void SAL_CALL adjustmentValueChanged( const css::awt::AdjustmentEvent& rEvent ) throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
95 :
96 : // XSpinValue
97 : virtual void SAL_CALL addAdjustmentListener( const css::uno::Reference< css::awt::XAdjustmentListener >& listener ) throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
98 : virtual void SAL_CALL removeAdjustmentListener( const css::uno::Reference< css::awt::XAdjustmentListener >& listener ) throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
99 : virtual void SAL_CALL setValue( sal_Int32 value ) throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
100 : virtual void SAL_CALL setValues( sal_Int32 minValue, sal_Int32 maxValue, sal_Int32 currentValue ) throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
101 : virtual sal_Int32 SAL_CALL getValue( ) throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
102 : virtual void SAL_CALL setMinimum( sal_Int32 minValue ) throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
103 : virtual void SAL_CALL setMaximum( sal_Int32 maxValue ) throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
104 : virtual sal_Int32 SAL_CALL getMinimum( ) throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
105 : virtual sal_Int32 SAL_CALL getMaximum( ) throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
106 : virtual void SAL_CALL setSpinIncrement( sal_Int32 spinIncrement ) throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
107 : virtual sal_Int32 SAL_CALL getSpinIncrement( ) throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
108 : virtual void SAL_CALL setOrientation( sal_Int32 orientation ) throw (css::lang::NoSupportException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
109 : virtual sal_Int32 SAL_CALL getOrientation( ) throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
110 :
111 : // XServiceInfo
112 : OUString SAL_CALL getImplementationName( ) throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
113 : css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
114 : };
115 :
116 :
117 : //= UnoSpinButtonModel
118 :
119 :
120 18 : UnoSpinButtonModel::UnoSpinButtonModel( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& i_factory )
121 18 : :UnoControlModel( i_factory )
122 : {
123 18 : ImplRegisterProperty( BASEPROPERTY_BACKGROUNDCOLOR );
124 18 : ImplRegisterProperty( BASEPROPERTY_BORDER );
125 18 : ImplRegisterProperty( BASEPROPERTY_BORDERCOLOR );
126 18 : ImplRegisterProperty( BASEPROPERTY_DEFAULTCONTROL );
127 18 : ImplRegisterProperty( BASEPROPERTY_ENABLED );
128 18 : ImplRegisterProperty( BASEPROPERTY_ENABLEVISIBLE );
129 18 : ImplRegisterProperty( BASEPROPERTY_HELPTEXT );
130 18 : ImplRegisterProperty( BASEPROPERTY_HELPURL );
131 18 : ImplRegisterProperty( BASEPROPERTY_ORIENTATION );
132 18 : ImplRegisterProperty( BASEPROPERTY_PRINTABLE );
133 18 : ImplRegisterProperty( BASEPROPERTY_REPEAT );
134 18 : ImplRegisterProperty( BASEPROPERTY_REPEAT_DELAY );
135 18 : ImplRegisterProperty( BASEPROPERTY_SYMBOL_COLOR );
136 18 : ImplRegisterProperty( BASEPROPERTY_SPINVALUE );
137 18 : ImplRegisterProperty( BASEPROPERTY_SPINVALUE_MIN );
138 18 : ImplRegisterProperty( BASEPROPERTY_SPINVALUE_MAX );
139 18 : ImplRegisterProperty( BASEPROPERTY_SPININCREMENT );
140 18 : ImplRegisterProperty( BASEPROPERTY_TABSTOP );
141 18 : ImplRegisterProperty( BASEPROPERTY_WRITING_MODE );
142 18 : ImplRegisterProperty( BASEPROPERTY_CONTEXT_WRITING_MODE );
143 18 : }
144 :
145 :
146 2 : OUString UnoSpinButtonModel::getServiceName( ) throw (RuntimeException, std::exception)
147 : {
148 2 : return OUString("com.sun.star.awt.UnoControlSpinButtonModel");
149 : }
150 :
151 :
152 444 : Any UnoSpinButtonModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const
153 : {
154 444 : switch ( nPropId )
155 : {
156 : case BASEPROPERTY_DEFAULTCONTROL:
157 22 : return makeAny( OUString("com.sun.star.awt.UnoControlSpinButton") );
158 :
159 : case BASEPROPERTY_BORDER:
160 22 : return makeAny( (sal_Int16) 0 );
161 :
162 : case BASEPROPERTY_REPEAT:
163 22 : return makeAny( true );
164 :
165 : default:
166 378 : return UnoControlModel::ImplGetDefaultValue( nPropId );
167 : }
168 : }
169 :
170 :
171 3997 : ::cppu::IPropertyArrayHelper& UnoSpinButtonModel::getInfoHelper()
172 : {
173 : static UnoPropertyArrayHelper* pHelper = NULL;
174 3997 : if ( !pHelper )
175 : {
176 4 : Sequence<sal_Int32> aIDs = ImplGetPropertyIds();
177 4 : pHelper = new UnoPropertyArrayHelper( aIDs );
178 : }
179 3997 : return *pHelper;
180 : }
181 :
182 :
183 110 : Reference< XPropertySetInfo > UnoSpinButtonModel::getPropertySetInfo( ) throw(RuntimeException, std::exception)
184 : {
185 110 : static Reference< XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
186 110 : return xInfo;
187 : }
188 :
189 :
190 8 : OUString SAL_CALL UnoSpinButtonModel::getImplementationName( ) throw(RuntimeException, std::exception)
191 : {
192 8 : return OUString( "com.sun.star.comp.toolkit.UnoSpinButtonModel" );
193 : }
194 :
195 :
196 18 : Sequence< OUString > SAL_CALL UnoSpinButtonModel::getSupportedServiceNames() throw(RuntimeException, std::exception)
197 : {
198 18 : Sequence< OUString > aServices( UnoControlModel::getSupportedServiceNames() );
199 18 : aServices.realloc( aServices.getLength() + 1 );
200 18 : aServices[ aServices.getLength() - 1 ] = OUString("com.sun.star.awt.UnoControlSpinButtonModel");
201 18 : return aServices;
202 : }
203 :
204 :
205 : //= UnoSpinButtonControl
206 :
207 :
208 2 : UnoSpinButtonControl::UnoSpinButtonControl()
209 : :UnoControlBase()
210 2 : ,maAdjustmentListeners( *this )
211 : {
212 2 : }
213 :
214 :
215 2 : OUString UnoSpinButtonControl::GetComponentServiceName()
216 : {
217 2 : return OUString("SpinButton");
218 : }
219 :
220 :
221 60 : Any UnoSpinButtonControl::queryAggregation( const Type & rType ) throw(RuntimeException, std::exception)
222 : {
223 60 : Any aRet = UnoControlBase::queryAggregation( rType );
224 60 : if ( !aRet.hasValue() )
225 4 : aRet = UnoSpinButtonControl_Base::queryInterface( rType );
226 60 : return aRet;
227 : }
228 :
229 :
230 0 : IMPLEMENT_FORWARD_XTYPEPROVIDER2( UnoSpinButtonControl, UnoControlBase, UnoSpinButtonControl_Base )
231 :
232 :
233 2 : void UnoSpinButtonControl::dispose() throw(RuntimeException, std::exception)
234 : {
235 2 : ::osl::ClearableMutexGuard aGuard( GetMutex() );
236 2 : if ( maAdjustmentListeners.getLength() )
237 : {
238 0 : Reference< XSpinValue > xSpinnable( getPeer(), UNO_QUERY );
239 0 : if ( xSpinnable.is() )
240 0 : xSpinnable->removeAdjustmentListener( this );
241 :
242 0 : EventObject aDisposeEvent;
243 0 : aDisposeEvent.Source = *this;
244 :
245 0 : aGuard.clear();
246 0 : maAdjustmentListeners.disposeAndClear( aDisposeEvent );
247 : }
248 :
249 2 : UnoControl::dispose();
250 2 : }
251 :
252 :
253 2 : OUString SAL_CALL UnoSpinButtonControl::getImplementationName( ) throw(RuntimeException, std::exception)
254 : {
255 2 : return OUString( "com.sun.star.comp.toolkit.UnoSpinButtonControl" );
256 : }
257 :
258 :
259 0 : Sequence< OUString > SAL_CALL UnoSpinButtonControl::getSupportedServiceNames() throw(RuntimeException, std::exception)
260 : {
261 0 : Sequence< OUString > aServices( UnoControlBase::getSupportedServiceNames() );
262 0 : aServices.realloc( aServices.getLength() + 1 );
263 0 : aServices[ aServices.getLength() - 1 ] = OUString("com.sun.star.awt.UnoControlSpinButton");
264 0 : return aServices;
265 : }
266 :
267 :
268 4 : void UnoSpinButtonControl::createPeer( const Reference< XToolkit > & rxToolkit, const Reference< XWindowPeer > & rParentPeer ) throw(RuntimeException, std::exception)
269 : {
270 4 : UnoControl::createPeer( rxToolkit, rParentPeer );
271 :
272 4 : Reference < XSpinValue > xSpinnable( getPeer(), UNO_QUERY );
273 4 : if ( xSpinnable.is() )
274 4 : xSpinnable->addAdjustmentListener( this );
275 4 : }
276 :
277 :
278 0 : void UnoSpinButtonControl::adjustmentValueChanged( const AdjustmentEvent& rEvent ) throw(RuntimeException, std::exception)
279 : {
280 0 : switch ( rEvent.Type )
281 : {
282 : case AdjustmentType_ADJUST_LINE:
283 : case AdjustmentType_ADJUST_PAGE:
284 : case AdjustmentType_ADJUST_ABS:
285 0 : ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE ), makeAny( rEvent.Value ), false );
286 0 : break;
287 : default:
288 : OSL_FAIL( "UnoSpinButtonControl::adjustmentValueChanged - unknown Type" );
289 : }
290 :
291 0 : if ( maAdjustmentListeners.getLength() )
292 : {
293 0 : AdjustmentEvent aEvent( rEvent );
294 0 : aEvent.Source = *this;
295 0 : maAdjustmentListeners.adjustmentValueChanged( aEvent );
296 : }
297 0 : }
298 :
299 :
300 0 : void UnoSpinButtonControl::addAdjustmentListener( const Reference< XAdjustmentListener > & listener ) throw(RuntimeException, std::exception)
301 : {
302 0 : ::osl::MutexGuard aGuard( GetMutex() );
303 0 : maAdjustmentListeners.addInterface( listener );
304 0 : }
305 :
306 :
307 0 : void UnoSpinButtonControl::removeAdjustmentListener( const Reference< XAdjustmentListener > & listener ) throw(RuntimeException, std::exception)
308 : {
309 0 : ::osl::MutexGuard aGuard( GetMutex() );
310 0 : maAdjustmentListeners.removeInterface( listener );
311 0 : }
312 :
313 :
314 0 : void SAL_CALL UnoSpinButtonControl::setValue( sal_Int32 value ) throw (RuntimeException, std::exception)
315 : {
316 0 : ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE ), makeAny( value ), true );
317 0 : }
318 :
319 :
320 0 : void SAL_CALL UnoSpinButtonControl::setValues( sal_Int32 minValue, sal_Int32 maxValue, sal_Int32 currentValue ) throw (RuntimeException, std::exception)
321 : {
322 0 : ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE_MIN ), makeAny( minValue ), true );
323 0 : ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE_MAX ), makeAny( maxValue ), true );
324 0 : ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE ), makeAny( currentValue ), true );
325 0 : }
326 :
327 :
328 0 : sal_Int32 SAL_CALL UnoSpinButtonControl::getValue( ) throw (RuntimeException, std::exception)
329 : {
330 0 : ::osl::MutexGuard aGuard( GetMutex() );
331 0 : sal_Int32 nValue = 0;
332 :
333 0 : Reference< XSpinValue > xSpinnable( getPeer(), UNO_QUERY );
334 0 : if ( xSpinnable.is() )
335 0 : nValue = xSpinnable->getValue();
336 :
337 0 : return nValue;
338 : }
339 :
340 :
341 0 : void SAL_CALL UnoSpinButtonControl::setMinimum( sal_Int32 minValue ) throw (RuntimeException, std::exception)
342 : {
343 0 : ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE_MIN ), makeAny( minValue ), true );
344 0 : }
345 :
346 :
347 0 : void SAL_CALL UnoSpinButtonControl::setMaximum( sal_Int32 maxValue ) throw (RuntimeException, std::exception)
348 : {
349 0 : ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE_MAX ), makeAny( maxValue ), true );
350 0 : }
351 :
352 :
353 0 : sal_Int32 SAL_CALL UnoSpinButtonControl::getMinimum( ) throw (RuntimeException, std::exception)
354 : {
355 0 : ::osl::MutexGuard aGuard( GetMutex() );
356 0 : sal_Int32 nMin = 0;
357 :
358 0 : Reference< XSpinValue > xSpinnable( getPeer(), UNO_QUERY );
359 0 : if ( xSpinnable.is() )
360 0 : nMin = xSpinnable->getMinimum();
361 :
362 0 : return nMin;
363 : }
364 :
365 :
366 0 : sal_Int32 SAL_CALL UnoSpinButtonControl::getMaximum( ) throw (RuntimeException, std::exception)
367 : {
368 0 : ::osl::MutexGuard aGuard( GetMutex() );
369 0 : sal_Int32 nMax = 0;
370 :
371 0 : Reference< XSpinValue > xSpinnable( getPeer(), UNO_QUERY );
372 0 : if ( xSpinnable.is() )
373 0 : nMax = xSpinnable->getMaximum();
374 :
375 0 : return nMax;
376 : }
377 :
378 :
379 0 : void SAL_CALL UnoSpinButtonControl::setSpinIncrement( sal_Int32 spinIncrement ) throw (RuntimeException, std::exception)
380 : {
381 0 : ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPININCREMENT ), makeAny( spinIncrement ), true );
382 0 : }
383 :
384 :
385 0 : sal_Int32 SAL_CALL UnoSpinButtonControl::getSpinIncrement( ) throw (RuntimeException, std::exception)
386 : {
387 0 : ::osl::MutexGuard aGuard( GetMutex() );
388 0 : sal_Int32 nIncrement = 0;
389 :
390 0 : Reference< XSpinValue > xSpinnable( getPeer(), UNO_QUERY );
391 0 : if ( xSpinnable.is() )
392 0 : nIncrement = xSpinnable->getSpinIncrement();
393 :
394 0 : return nIncrement;
395 : }
396 :
397 :
398 0 : void SAL_CALL UnoSpinButtonControl::setOrientation( sal_Int32 orientation ) throw (NoSupportException, RuntimeException, std::exception)
399 : {
400 0 : ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_ORIENTATION ), makeAny( orientation ), true );
401 0 : }
402 :
403 :
404 0 : sal_Int32 SAL_CALL UnoSpinButtonControl::getOrientation( ) throw (RuntimeException, std::exception)
405 : {
406 0 : ::osl::MutexGuard aGuard( GetMutex() );
407 0 : sal_Int32 nOrientation = ScrollBarOrientation::HORIZONTAL;
408 :
409 0 : Reference< XSpinValue > xSpinnable( getPeer(), UNO_QUERY );
410 0 : if ( xSpinnable.is() )
411 0 : nOrientation = xSpinnable->getOrientation();
412 :
413 0 : return nOrientation;
414 : }
415 :
416 : }
417 :
418 : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
419 18 : stardiv_Toolkit_UnoSpinButtonModel_get_implementation(
420 : css::uno::XComponentContext *context,
421 : css::uno::Sequence<css::uno::Any> const &)
422 : {
423 18 : return cppu::acquire(new UnoSpinButtonModel(context));
424 : }
425 :
426 : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
427 2 : stardiv_Toolkit_UnoSpinButtonControl_get_implementation(
428 : css::uno::XComponentContext *,
429 : css::uno::Sequence<css::uno::Any> const &)
430 : {
431 2 : return cppu::acquire(new UnoSpinButtonControl());
432 : }
433 :
434 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|