fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / toolkit / source / controls / animatedimages.cxx
blobe2cd1d9359d9e49115450cde875f2e636e1c756a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include "toolkit/controls/animatedimages.hxx"
22 #include "toolkit/helper/servicenames.hxx"
23 #include "toolkit/helper/property.hxx"
24 #include "toolkit/helper/unopropertyarrayhelper.hxx"
26 #include <com/sun/star/lang/DisposedException.hpp>
27 #include <com/sun/star/awt/VisualEffect.hpp>
28 #include <com/sun/star/awt/ImageScaleMode.hpp>
29 #include <com/sun/star/util/XModifyListener.hpp>
31 //......................................................................................................................
32 namespace toolkit
34 //......................................................................................................................
36 using ::com::sun::star::uno::Reference;
37 using ::com::sun::star::uno::XInterface;
38 using ::com::sun::star::uno::UNO_QUERY;
39 using ::com::sun::star::uno::UNO_QUERY_THROW;
40 using ::com::sun::star::uno::UNO_SET_THROW;
41 using ::com::sun::star::uno::Exception;
42 using ::com::sun::star::uno::RuntimeException;
43 using ::com::sun::star::uno::Any;
44 using ::com::sun::star::uno::makeAny;
45 using ::com::sun::star::uno::Sequence;
46 using ::com::sun::star::uno::Type;
47 using ::com::sun::star::container::ContainerEvent;
48 using ::com::sun::star::container::XContainerListener;
49 using ::com::sun::star::beans::XPropertySetInfo;
50 using ::com::sun::star::lang::DisposedException;
51 using ::com::sun::star::lang::IndexOutOfBoundsException;
52 using ::com::sun::star::lang::EventObject;
53 using ::com::sun::star::awt::XControlModel;
54 using ::com::sun::star::awt::XAnimatedImages;
55 using ::com::sun::star::lang::IllegalArgumentException;
56 using ::com::sun::star::awt::XWindowPeer;
57 using ::com::sun::star::util::XModifyListener;
58 using ::com::sun::star::awt::XToolkit;
59 using ::com::sun::star::lang::XMultiServiceFactory;
61 namespace VisualEffect = ::com::sun::star::awt::VisualEffect;
62 namespace ImageScaleMode = ::com::sun::star::awt::ImageScaleMode;
64 //==================================================================================================================
65 //= AnimatedImagesControl
66 //==================================================================================================================
67 //------------------------------------------------------------------------------------------------------------------
68 AnimatedImagesControl::AnimatedImagesControl()
69 :AnimatedImagesControl_Base()
73 //------------------------------------------------------------------------------------------------------------------
74 OUString AnimatedImagesControl::GetComponentServiceName()
76 return OUString( "AnimatedImages" );
79 //------------------------------------------------------------------------------------------------------------------
80 void SAL_CALL AnimatedImagesControl::startAnimation( ) throw (RuntimeException)
82 Reference< XAnimation > xAnimation( getPeer(), UNO_QUERY );
83 if ( xAnimation.is() )
84 xAnimation->startAnimation();
87 //------------------------------------------------------------------------------------------------------------------
88 void SAL_CALL AnimatedImagesControl::stopAnimation( ) throw (RuntimeException)
90 Reference< XAnimation > xAnimation( getPeer(), UNO_QUERY );
91 if ( xAnimation.is() )
92 xAnimation->stopAnimation();
95 //------------------------------------------------------------------------------------------------------------------
96 ::sal_Bool SAL_CALL AnimatedImagesControl::isAnimationRunning( ) throw (RuntimeException)
98 Reference< XAnimation > xAnimation( getPeer(), UNO_QUERY );
99 if ( xAnimation.is() )
100 return xAnimation->isAnimationRunning();
101 return sal_False;
104 //------------------------------------------------------------------------------------------------------------------
105 OUString SAL_CALL AnimatedImagesControl::getImplementationName( ) throw(RuntimeException)
107 return OUString( "org.openoffice.comp.toolkit.AnimatedImagesControl" );
110 //------------------------------------------------------------------------------------------------------------------
111 Sequence< OUString > SAL_CALL AnimatedImagesControl::getSupportedServiceNames() throw(RuntimeException)
113 Sequence< OUString > aServices( AnimatedImagesControl_Base::getSupportedServiceNames() );
114 aServices.realloc( aServices.getLength() + 1 );
115 aServices[ aServices.getLength() - 1 ] = OUString::createFromAscii( szServiceName_AnimatedImagesControl );
116 return aServices;
119 //------------------------------------------------------------------------------------------------------------------
120 namespace
122 void lcl_updatePeer( Reference< XWindowPeer > const& i_peer, Reference< XControlModel > const& i_model )
124 const Reference< XModifyListener > xPeerModify( i_peer, UNO_QUERY );
125 if ( xPeerModify.is() )
127 EventObject aEvent;
128 aEvent.Source = i_model;
129 xPeerModify->modified( aEvent );
134 //------------------------------------------------------------------------------------------------------------------
135 sal_Bool SAL_CALL AnimatedImagesControl::setModel( const Reference< XControlModel >& i_rModel ) throw ( RuntimeException )
137 const Reference< XAnimatedImages > xOldContainer( getModel(), UNO_QUERY );
138 const Reference< XAnimatedImages > xNewContainer( i_rModel, UNO_QUERY );
140 if ( !AnimatedImagesControl_Base::setModel( i_rModel ) )
141 return sal_False;
143 if ( xOldContainer.is() )
144 xOldContainer->removeContainerListener( this );
146 if ( xNewContainer.is() )
147 xNewContainer->addContainerListener( this );
149 lcl_updatePeer( getPeer(), getModel() );
151 return sal_True;
154 //------------------------------------------------------------------------------------------------------------------
155 void SAL_CALL AnimatedImagesControl::createPeer( const Reference< XToolkit >& i_toolkit, const Reference< XWindowPeer >& i_parentPeer ) throw(RuntimeException)
157 AnimatedImagesControl_Base::createPeer( i_toolkit, i_parentPeer );
159 lcl_updatePeer( getPeer(), getModel() );
162 //------------------------------------------------------------------------------------------------------------------
163 void SAL_CALL AnimatedImagesControl::elementInserted( const ContainerEvent& i_event ) throw (RuntimeException)
165 const Reference< XContainerListener > xPeerListener( getPeer(), UNO_QUERY );
166 if ( xPeerListener.is() )
167 xPeerListener->elementInserted( i_event );
170 //------------------------------------------------------------------------------------------------------------------
171 void SAL_CALL AnimatedImagesControl::elementRemoved( const ContainerEvent& i_event ) throw (RuntimeException)
173 const Reference< XContainerListener > xPeerListener( getPeer(), UNO_QUERY );
174 if ( xPeerListener.is() )
175 xPeerListener->elementRemoved( i_event );
178 //------------------------------------------------------------------------------------------------------------------
179 void SAL_CALL AnimatedImagesControl::elementReplaced( const ContainerEvent& i_event ) throw (RuntimeException)
181 const Reference< XContainerListener > xPeerListener( getPeer(), UNO_QUERY );
182 if ( xPeerListener.is() )
183 xPeerListener->elementReplaced( i_event );
186 //------------------------------------------------------------------------------------------------------------------
187 void SAL_CALL AnimatedImagesControl::disposing( const EventObject& i_event ) throw (RuntimeException)
189 UnoControlBase::disposing( i_event );
192 //==================================================================================================================
193 //= AnimatedImagesControlModel_Data
194 //==================================================================================================================
195 struct AnimatedImagesControlModel_Data
197 ::std::vector< Sequence< OUString > > aImageSets;
200 namespace
202 void lcl_checkIndex( const AnimatedImagesControlModel_Data& i_data, const sal_Int32 i_index, const Reference< XInterface >& i_context,
203 const bool i_forInsert = false )
205 if ( ( i_index < 0 ) || ( size_t( i_index ) > i_data.aImageSets.size() + ( i_forInsert ? 1 : 0 ) ) )
206 throw IndexOutOfBoundsException( OUString(), i_context );
209 void lcl_notify( ::osl::ClearableMutexGuard& i_guard, ::cppu::OBroadcastHelper& i_broadcaseHelper,
210 void ( SAL_CALL XContainerListener::*i_notificationMethod )( const ContainerEvent& ),
211 const sal_Int32 i_accessor, const Sequence< OUString >& i_imageURLs, const Reference< XInterface >& i_context )
213 ::cppu::OInterfaceContainerHelper* pContainerListeners = i_broadcaseHelper.getContainer( XContainerListener::static_type() );
214 if ( pContainerListeners == NULL )
215 return;
217 ContainerEvent aEvent;
218 aEvent.Source = i_context;
219 aEvent.Accessor <<= i_accessor;
220 aEvent.Element <<= i_imageURLs;
222 i_guard.clear();
223 pContainerListeners->notifyEach( i_notificationMethod, aEvent );
227 //==================================================================================================================
228 //= AnimatedImagesControlModel
229 //==================================================================================================================
230 //------------------------------------------------------------------------------------------------------------------
231 AnimatedImagesControlModel::AnimatedImagesControlModel( Reference< com::sun::star::uno::XComponentContext > const & i_factory )
232 :AnimatedImagesControlModel_Base( i_factory )
233 ,m_pData( new AnimatedImagesControlModel_Data )
235 ImplRegisterProperty( BASEPROPERTY_AUTO_REPEAT );
236 ImplRegisterProperty( BASEPROPERTY_BORDER );
237 ImplRegisterProperty( BASEPROPERTY_BORDERCOLOR );
238 ImplRegisterProperty( BASEPROPERTY_BACKGROUNDCOLOR );
239 ImplRegisterProperty( BASEPROPERTY_DEFAULTCONTROL );
240 ImplRegisterProperty( BASEPROPERTY_ENABLEVISIBLE );
241 ImplRegisterProperty( BASEPROPERTY_HELPTEXT );
242 ImplRegisterProperty( BASEPROPERTY_HELPURL );
243 ImplRegisterProperty( BASEPROPERTY_IMAGE_SCALE_MODE );
244 ImplRegisterProperty( BASEPROPERTY_STEP_TIME );
247 //------------------------------------------------------------------------------------------------------------------
248 AnimatedImagesControlModel::AnimatedImagesControlModel( const AnimatedImagesControlModel& i_copySource )
249 :AnimatedImagesControlModel_Base( i_copySource )
250 ,m_pData( new AnimatedImagesControlModel_Data( *i_copySource.m_pData ) )
254 //------------------------------------------------------------------------------------------------------------------
255 AnimatedImagesControlModel::~AnimatedImagesControlModel()
259 //------------------------------------------------------------------------------------------------------------------
260 UnoControlModel* AnimatedImagesControlModel::Clone() const
262 return new AnimatedImagesControlModel( *this );
265 //------------------------------------------------------------------------------------------------------------------
266 Reference< XPropertySetInfo > SAL_CALL AnimatedImagesControlModel::getPropertySetInfo( ) throw(RuntimeException)
268 static Reference< XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
269 return xInfo;
272 //------------------------------------------------------------------------------------------------------------------
273 OUString SAL_CALL AnimatedImagesControlModel::getServiceName() throw(RuntimeException)
275 return OUString::createFromAscii( szServiceName_AnimatedImagesControlModel );
278 //------------------------------------------------------------------------------------------------------------------
279 OUString SAL_CALL AnimatedImagesControlModel::getImplementationName( ) throw(RuntimeException)
281 return OUString("org.openoffice.comp.toolkit.AnimatedImagesControlModel");
284 //------------------------------------------------------------------------------------------------------------------
285 Sequence< OUString > SAL_CALL AnimatedImagesControlModel::getSupportedServiceNames() throw(RuntimeException)
287 Sequence< OUString > aServiceNames(2);
288 aServiceNames[0] = OUString::createFromAscii( szServiceName_AnimatedImagesControlModel );
289 aServiceNames[1] = "com.sun.star.awt.UnoControlModel";
290 return aServiceNames;
293 //------------------------------------------------------------------------------------------------------------------
294 void SAL_CALL AnimatedImagesControlModel::setFastPropertyValue_NoBroadcast( sal_Int32 i_handle, const Any& i_value ) throw (Exception)
296 switch ( i_handle )
298 case BASEPROPERTY_IMAGE_SCALE_MODE:
300 sal_Int16 nImageScaleMode( ImageScaleMode::Anisotropic );
301 OSL_VERIFY( i_value >>= nImageScaleMode ); // convertFastPropertyValue ensures that this has the proper type
302 if ( ( nImageScaleMode != ImageScaleMode::None )
303 && ( nImageScaleMode != ImageScaleMode::Isotropic )
304 && ( nImageScaleMode != ImageScaleMode::Anisotropic )
306 throw IllegalArgumentException( OUString(), *this, 1 );
308 break;
311 AnimatedImagesControlModel_Base::setFastPropertyValue_NoBroadcast( i_handle, i_value );
314 //------------------------------------------------------------------------------------------------------------------
315 Any AnimatedImagesControlModel::ImplGetDefaultValue( sal_uInt16 i_propertyId ) const
317 switch ( i_propertyId )
319 case BASEPROPERTY_DEFAULTCONTROL:
320 return makeAny( OUString::createFromAscii( szServiceName_AnimatedImagesControl ) );
322 case BASEPROPERTY_BORDER:
323 return makeAny( VisualEffect::NONE );
325 case BASEPROPERTY_STEP_TIME:
326 return makeAny( (sal_Int32) 100 );
328 case BASEPROPERTY_AUTO_REPEAT:
329 return makeAny( (sal_Bool)sal_True );
331 case BASEPROPERTY_IMAGE_SCALE_MODE:
332 return makeAny( ImageScaleMode::None );
334 default:
335 return UnoControlModel::ImplGetDefaultValue( i_propertyId );
339 //------------------------------------------------------------------------------------------------------------------
340 ::cppu::IPropertyArrayHelper& SAL_CALL AnimatedImagesControlModel::getInfoHelper()
342 static UnoPropertyArrayHelper* pHelper = NULL;
343 if ( !pHelper )
345 Sequence< sal_Int32 > aIDs = ImplGetPropertyIds();
346 pHelper = new UnoPropertyArrayHelper( aIDs );
348 return *pHelper;
351 //------------------------------------------------------------------------------------------------------------------
352 ::sal_Int32 SAL_CALL AnimatedImagesControlModel::getStepTime() throw (RuntimeException)
354 sal_Int32 nStepTime( 100 );
355 OSL_VERIFY( getPropertyValue( GetPropertyName( BASEPROPERTY_STEP_TIME ) ) >>= nStepTime );
356 return nStepTime;
359 //------------------------------------------------------------------------------------------------------------------
360 void SAL_CALL AnimatedImagesControlModel::setStepTime( ::sal_Int32 i_stepTime ) throw (RuntimeException)
362 setPropertyValue( GetPropertyName( BASEPROPERTY_STEP_TIME ), makeAny( i_stepTime ) );
365 //------------------------------------------------------------------------------------------------------------------
366 ::sal_Bool SAL_CALL AnimatedImagesControlModel::getAutoRepeat() throw (RuntimeException)
368 sal_Bool bAutoRepeat( sal_True );
369 OSL_VERIFY( getPropertyValue( GetPropertyName( BASEPROPERTY_AUTO_REPEAT ) ) >>= bAutoRepeat );
370 return bAutoRepeat;
373 //------------------------------------------------------------------------------------------------------------------
374 void SAL_CALL AnimatedImagesControlModel::setAutoRepeat( ::sal_Bool i_autoRepeat ) throw (RuntimeException)
376 setPropertyValue( GetPropertyName( BASEPROPERTY_AUTO_REPEAT ), makeAny( i_autoRepeat ) );
379 //------------------------------------------------------------------------------------------------------------------
380 ::sal_Int16 SAL_CALL AnimatedImagesControlModel::getScaleMode() throw (RuntimeException)
382 sal_Int16 nImageScaleMode( ImageScaleMode::Anisotropic );
383 OSL_VERIFY( getPropertyValue( GetPropertyName( BASEPROPERTY_IMAGE_SCALE_MODE ) ) >>= nImageScaleMode );
384 return nImageScaleMode;
387 //------------------------------------------------------------------------------------------------------------------
388 void SAL_CALL AnimatedImagesControlModel::setScaleMode( ::sal_Int16 i_scaleMode ) throw (IllegalArgumentException, RuntimeException)
390 setPropertyValue( GetPropertyName( BASEPROPERTY_IMAGE_SCALE_MODE ), makeAny( i_scaleMode ) );
393 //------------------------------------------------------------------------------------------------------------------
394 ::sal_Int32 SAL_CALL AnimatedImagesControlModel::getImageSetCount( ) throw (RuntimeException)
396 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
397 if ( GetBroadcastHelper().bDisposed || GetBroadcastHelper().bInDispose )
398 throw DisposedException();
400 return m_pData->aImageSets.size();
403 //------------------------------------------------------------------------------------------------------------------
404 Sequence< OUString > SAL_CALL AnimatedImagesControlModel::getImageSet( ::sal_Int32 i_index ) throw (IndexOutOfBoundsException, RuntimeException)
406 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
407 if ( GetBroadcastHelper().bDisposed || GetBroadcastHelper().bInDispose )
408 throw DisposedException();
410 lcl_checkIndex( *m_pData, i_index, *this );
412 return m_pData->aImageSets[ i_index ];
415 //------------------------------------------------------------------------------------------------------------------
416 void SAL_CALL AnimatedImagesControlModel::insertImageSet( ::sal_Int32 i_index, const Sequence< OUString >& i_imageURLs ) throw (IndexOutOfBoundsException, RuntimeException)
418 ::osl::ClearableMutexGuard aGuard( GetMutex() );
419 // sanity checks
420 if ( GetBroadcastHelper().bDisposed || GetBroadcastHelper().bInDispose )
421 throw DisposedException();
423 lcl_checkIndex( *m_pData, i_index, *this, true );
425 // actaul insertion
426 m_pData->aImageSets.insert( m_pData->aImageSets.begin() + i_index, i_imageURLs );
428 // listener notification
429 lcl_notify( aGuard, BrdcstHelper, &XContainerListener::elementInserted, i_index, i_imageURLs, *this );
432 //------------------------------------------------------------------------------------------------------------------
433 void SAL_CALL AnimatedImagesControlModel::replaceImageSet( ::sal_Int32 i_index, const Sequence< OUString >& i_imageURLs ) throw (IndexOutOfBoundsException, RuntimeException)
435 ::osl::ClearableMutexGuard aGuard( GetMutex() );
436 // sanity checks
437 if ( GetBroadcastHelper().bDisposed || GetBroadcastHelper().bInDispose )
438 throw DisposedException();
440 lcl_checkIndex( *m_pData, i_index, *this );
442 // actaul insertion
443 m_pData->aImageSets[ i_index ] = i_imageURLs;
445 // listener notification
446 lcl_notify( aGuard, BrdcstHelper, &XContainerListener::elementReplaced, i_index, i_imageURLs, *this );
449 //------------------------------------------------------------------------------------------------------------------
450 void SAL_CALL AnimatedImagesControlModel::removeImageSet( ::sal_Int32 i_index ) throw (IndexOutOfBoundsException, RuntimeException)
452 ::osl::ClearableMutexGuard aGuard( GetMutex() );
453 // sanity checks
454 if ( GetBroadcastHelper().bDisposed || GetBroadcastHelper().bInDispose )
455 throw DisposedException();
457 lcl_checkIndex( *m_pData, i_index, *this );
459 // actual removal
460 ::std::vector< Sequence< OUString > >::iterator removalPos = m_pData->aImageSets.begin() + i_index;
461 Sequence< OUString > aRemovedElement( *removalPos );
462 m_pData->aImageSets.erase( removalPos );
464 // listener notification
465 lcl_notify( aGuard, BrdcstHelper, &XContainerListener::elementRemoved, i_index, aRemovedElement, *this );
468 //------------------------------------------------------------------------------------------------------------------
469 void SAL_CALL AnimatedImagesControlModel::addContainerListener( const Reference< XContainerListener >& i_listener ) throw (RuntimeException)
471 BrdcstHelper.addListener( XContainerListener::static_type(), i_listener );
474 //------------------------------------------------------------------------------------------------------------------
475 void SAL_CALL AnimatedImagesControlModel::removeContainerListener( const Reference< XContainerListener >& i_listener ) throw (RuntimeException)
477 BrdcstHelper.removeListener( XContainerListener::static_type(), i_listener );
480 //......................................................................................................................
481 } // namespace toolkit
482 //......................................................................................................................
484 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */