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