LibreOffice Module toolkit (master) 1
animatedimages.cxx
Go to the documentation of this file.
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
22#include <helper/property.hxx>
23
24#include <com/sun/star/lang/DisposedException.hpp>
25#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
26#include <com/sun/star/awt/VisualEffect.hpp>
27#include <com/sun/star/awt/ImageScaleMode.hpp>
28#include <com/sun/star/awt/XAnimation.hpp>
29#include <com/sun/star/awt/XAnimatedImages.hpp>
30#include <com/sun/star/beans/XPropertySetInfo.hpp>
31#include <com/sun/star/container/XContainerListener.hpp>
32#include <com/sun/star/uno/XComponentContext.hpp>
33#include <com/sun/star/util/XModifyListener.hpp>
34#include <o3tl/safeint.hxx>
37
39
41
42using namespace css::awt;
43using namespace css::container;
44using namespace css::lang;
45using namespace css::uno;
46
47namespace {
48
50 , css::awt::XAnimation
51 , css::container::XContainerListener
52 > AnimatedImagesControl_Base;
53
54class AnimatedImagesControl : public AnimatedImagesControl_Base
55{
56public:
57 AnimatedImagesControl();
58 OUString GetComponentServiceName() const override;
59
60 // XAnimation
61 virtual void SAL_CALL startAnimation( ) override;
62 virtual void SAL_CALL stopAnimation( ) override;
63 virtual sal_Bool SAL_CALL isAnimationRunning( ) override;
64
65 // XServiceInfo
66 OUString SAL_CALL getImplementationName( ) override;
67 css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
68
69 // XControl
70 sal_Bool SAL_CALL setModel( const css::uno::Reference< css::awt::XControlModel >& i_rModel ) override;
71 void SAL_CALL createPeer( const css::uno::Reference< css::awt::XToolkit >& i_toolkit, const css::uno::Reference< css::awt::XWindowPeer >& i_parentPeer ) override;
72
73
74 // XContainerListener
75 virtual void SAL_CALL elementInserted( const css::container::ContainerEvent& Event ) override;
76 virtual void SAL_CALL elementRemoved( const css::container::ContainerEvent& Event ) override;
77 virtual void SAL_CALL elementReplaced( const css::container::ContainerEvent& Event ) override;
78
79 // XEventListener
80 virtual void SAL_CALL disposing( const css::lang::EventObject& i_event ) override;
81};
82
83 AnimatedImagesControl::AnimatedImagesControl()
84 {
85 }
86
87
88 OUString AnimatedImagesControl::GetComponentServiceName() const
89 {
90 return "AnimatedImages";
91 }
92
93
94 void SAL_CALL AnimatedImagesControl::startAnimation( )
95 {
96 Reference< XAnimation > xAnimation( getPeer(), UNO_QUERY );
97 if ( xAnimation.is() )
98 xAnimation->startAnimation();
99 }
100
101
102 void SAL_CALL AnimatedImagesControl::stopAnimation( )
103 {
104 Reference< XAnimation > xAnimation( getPeer(), UNO_QUERY );
105 if ( xAnimation.is() )
106 xAnimation->stopAnimation();
107 }
108
109
110 sal_Bool SAL_CALL AnimatedImagesControl::isAnimationRunning( )
111 {
112 Reference< XAnimation > xAnimation( getPeer(), UNO_QUERY );
113 if ( xAnimation.is() )
114 return xAnimation->isAnimationRunning();
115 return false;
116 }
117
118
119 OUString SAL_CALL AnimatedImagesControl::getImplementationName( )
120 {
121 return "org.openoffice.comp.toolkit.AnimatedImagesControl";
122 }
123
124
125 Sequence< OUString > SAL_CALL AnimatedImagesControl::getSupportedServiceNames()
126 {
127 Sequence< OUString > aServices( AnimatedImagesControl_Base::getSupportedServiceNames() );
128 aServices.realloc( aServices.getLength() + 1 );
129 aServices.getArray()[ aServices.getLength() - 1 ] = "com.sun.star.awt.AnimatedImagesControl";
130 return aServices;
131 }
132
133 void lcl_updatePeer( Reference< XWindowPeer > const& i_peer, Reference< XControlModel > const& i_model )
134 {
135 const Reference< css::util::XModifyListener > xPeerModify( i_peer, UNO_QUERY );
136 if ( xPeerModify.is() )
137 {
138 EventObject aEvent;
139 aEvent.Source = i_model;
140 xPeerModify->modified( aEvent );
141 }
142 }
143
144 sal_Bool SAL_CALL AnimatedImagesControl::setModel( const Reference< XControlModel >& i_rModel )
145 {
146 const Reference< XAnimatedImages > xOldContainer( getModel(), UNO_QUERY );
147 const Reference< XAnimatedImages > xNewContainer( i_rModel, UNO_QUERY );
148
149 if ( !AnimatedImagesControl_Base::setModel( i_rModel ) )
150 return false;
151
152 if ( xOldContainer.is() )
153 xOldContainer->removeContainerListener( this );
154
155 if ( xNewContainer.is() )
156 xNewContainer->addContainerListener( this );
157
158 lcl_updatePeer( getPeer(), getModel() );
159
160 return true;
161 }
162
163
164 void SAL_CALL AnimatedImagesControl::createPeer( const Reference< XToolkit >& i_toolkit, const Reference< XWindowPeer >& i_parentPeer )
165 {
166 AnimatedImagesControl_Base::createPeer( i_toolkit, i_parentPeer );
167
168 lcl_updatePeer( getPeer(), getModel() );
169 }
170
171
172 void SAL_CALL AnimatedImagesControl::elementInserted( const ContainerEvent& i_event )
173 {
174 const Reference< XContainerListener > xPeerListener( getPeer(), UNO_QUERY );
175 if ( xPeerListener.is() )
176 xPeerListener->elementInserted( i_event );
177 }
178
179
180 void SAL_CALL AnimatedImagesControl::elementRemoved( const ContainerEvent& i_event )
181 {
182 const Reference< XContainerListener > xPeerListener( getPeer(), UNO_QUERY );
183 if ( xPeerListener.is() )
184 xPeerListener->elementRemoved( i_event );
185 }
186
187
188 void SAL_CALL AnimatedImagesControl::elementReplaced( const ContainerEvent& i_event )
189 {
190 const Reference< XContainerListener > xPeerListener( getPeer(), UNO_QUERY );
191 if ( xPeerListener.is() )
192 xPeerListener->elementReplaced( i_event );
193 }
194
195
196 void SAL_CALL AnimatedImagesControl::disposing( const EventObject& i_event )
197 {
198 UnoControlBase::disposing( i_event );
199 }
200
201}
202
203namespace toolkit {
204
205 namespace
206 {
207 void lcl_checkIndex( const std::vector< css::uno::Sequence< OUString > > & rImageSets, const sal_Int32 i_index, const Reference< XInterface >& i_context,
208 const bool i_forInsert = false )
209 {
210 if ( ( i_index < 0 ) || ( o3tl::make_unsigned( i_index ) > rImageSets.size() + ( i_forInsert ? 1 : 0 ) ) )
211 throw IndexOutOfBoundsException( OUString(), i_context );
212 }
213
214 void lcl_notify( std::unique_lock<std::mutex>& i_guard, comphelper::OInterfaceContainerHelper4<XContainerListener>& rContainer,
215 void ( SAL_CALL XContainerListener::*i_notificationMethod )( const ContainerEvent& ),
216 const sal_Int32 i_accessor, const Sequence< OUString >& i_imageURLs, const Reference< XInterface >& i_context )
217 {
218 if ( !rContainer.getLength(i_guard) )
219 return;
220
221 ContainerEvent aEvent;
222 aEvent.Source = i_context;
223 aEvent.Accessor <<= i_accessor;
224 aEvent.Element <<= i_imageURLs;
225
226 rContainer.notifyEach( i_guard, i_notificationMethod, aEvent );
227 }
228 }
229
230
231 AnimatedImagesControlModel::AnimatedImagesControlModel( Reference< css::uno::XComponentContext > const & i_factory )
233 {
234 ImplRegisterProperty( BASEPROPERTY_AUTO_REPEAT );
235 ImplRegisterProperty( BASEPROPERTY_BORDER );
236 ImplRegisterProperty( BASEPROPERTY_BORDERCOLOR );
237 ImplRegisterProperty( BASEPROPERTY_BACKGROUNDCOLOR );
238 ImplRegisterProperty( BASEPROPERTY_DEFAULTCONTROL );
239 ImplRegisterProperty( BASEPROPERTY_ENABLEVISIBLE );
240 ImplRegisterProperty( BASEPROPERTY_HELPTEXT );
241 ImplRegisterProperty( BASEPROPERTY_HELPURL );
242 ImplRegisterProperty( BASEPROPERTY_IMAGE_SCALE_MODE );
243 ImplRegisterProperty( BASEPROPERTY_STEP_TIME );
244 }
245
246
247 AnimatedImagesControlModel::AnimatedImagesControlModel( const AnimatedImagesControlModel& i_copySource )
248 :AnimatedImagesControlModel_Base( i_copySource )
249 ,maImageSets( i_copySource.maImageSets )
250 {
251 }
252
253
255 {
256 }
257
258
260 {
261 return new AnimatedImagesControlModel( *this );
262 }
263
264
265 Reference< css::beans::XPropertySetInfo > SAL_CALL AnimatedImagesControlModel::getPropertySetInfo( )
266 {
267 static Reference< css::beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
268 return xInfo;
269 }
270
271
273 {
274 return "com.sun.star.awt.AnimatedImagesControlModel";
275 }
276
277
279 {
280 return "org.openoffice.comp.toolkit.AnimatedImagesControlModel";
281 }
282
283
285 {
286 return { "com.sun.star.awt.AnimatedImagesControlModel", "com.sun.star.awt.UnoControlModel" };
287 }
288
289
290 void AnimatedImagesControlModel::setFastPropertyValue_NoBroadcast( std::unique_lock<std::mutex>& rGuard, sal_Int32 i_handle, const Any& i_value )
291 {
292 switch ( i_handle )
293 {
295 {
296 sal_Int16 nImageScaleMode( ImageScaleMode::ANISOTROPIC );
297 OSL_VERIFY( i_value >>= nImageScaleMode ); // convertFastPropertyValue ensures that this has the proper type
298 if ( ( nImageScaleMode != ImageScaleMode::NONE )
299 && ( nImageScaleMode != ImageScaleMode::ISOTROPIC )
300 && ( nImageScaleMode != ImageScaleMode::ANISOTROPIC )
301 )
302 throw IllegalArgumentException( OUString(), *this, 1 );
303 }
304 break;
305 }
306
307 AnimatedImagesControlModel_Base::setFastPropertyValue_NoBroadcast( rGuard, i_handle, i_value );
308 }
309
310
312 {
313 switch ( i_propertyId )
314 {
316 return Any( OUString("com.sun.star.awt.AnimatedImagesControl") );
317
319 return Any( css::awt::VisualEffect::NONE );
320
322 return Any( sal_Int32(100) );
323
325 return Any( true );
326
328 return Any( ImageScaleMode::NONE );
329
330 default:
331 return UnoControlModel::ImplGetDefaultValue( i_propertyId );
332 }
333 }
334
335
337 {
338 static UnoPropertyArrayHelper aHelper( ImplGetPropertyIds() );
339 return aHelper;
340 }
341
342
344 {
345 sal_Int32 nStepTime( 100 );
346 OSL_VERIFY( getPropertyValue( GetPropertyName( BASEPROPERTY_STEP_TIME ) ) >>= nStepTime );
347 return nStepTime;
348 }
349
350
351 void SAL_CALL AnimatedImagesControlModel::setStepTime( ::sal_Int32 i_stepTime )
352 {
354 }
355
356
358 {
359 bool bAutoRepeat( true );
360 OSL_VERIFY( getPropertyValue( GetPropertyName( BASEPROPERTY_AUTO_REPEAT ) ) >>= bAutoRepeat );
361 return bAutoRepeat;
362 }
363
364
366 {
368 }
369
370
372 {
373 sal_Int16 nImageScaleMode( ImageScaleMode::ANISOTROPIC );
374 OSL_VERIFY( getPropertyValue( GetPropertyName( BASEPROPERTY_IMAGE_SCALE_MODE ) ) >>= nImageScaleMode );
375 return nImageScaleMode;
376 }
377
378
379 void SAL_CALL AnimatedImagesControlModel::setScaleMode( ::sal_Int16 i_scaleMode )
380 {
382 }
383
384
386 {
387 std::unique_lock aGuard( m_aMutex );
388 if ( m_bDisposed )
389 throw DisposedException();
390
391 return maImageSets.size();
392 }
393
394
395 Sequence< OUString > SAL_CALL AnimatedImagesControlModel::getImageSet( ::sal_Int32 i_index )
396 {
397 std::unique_lock aGuard( m_aMutex );
398 if ( m_bDisposed )
399 throw DisposedException();
400
401 lcl_checkIndex( maImageSets, i_index, *this );
402
403 return maImageSets[ i_index ];
404 }
405
406
407 void SAL_CALL AnimatedImagesControlModel::insertImageSet( ::sal_Int32 i_index, const Sequence< OUString >& i_imageURLs )
408 {
409 std::unique_lock aGuard( m_aMutex );
410 // sanity checks
411 if ( m_bDisposed )
412 throw DisposedException();
413
414 lcl_checkIndex( maImageSets, i_index, *this, true );
415
416 // actual insertion
417 maImageSets.insert( maImageSets.begin() + i_index, i_imageURLs );
418
419 // listener notification
420 lcl_notify( aGuard, maContainerListeners, &XContainerListener::elementInserted, i_index, i_imageURLs, *this );
421 }
422
423
424 void SAL_CALL AnimatedImagesControlModel::replaceImageSet( ::sal_Int32 i_index, const Sequence< OUString >& i_imageURLs )
425 {
426 std::unique_lock aGuard( m_aMutex );
427 // sanity checks
428 if ( m_bDisposed )
429 throw DisposedException();
430
431 lcl_checkIndex( maImageSets, i_index, *this );
432
433 // actual insertion
434 maImageSets[ i_index ] = i_imageURLs;
435
436 // listener notification
437 lcl_notify( aGuard, maContainerListeners, &XContainerListener::elementReplaced, i_index, i_imageURLs, *this );
438 }
439
440
441 void SAL_CALL AnimatedImagesControlModel::removeImageSet( ::sal_Int32 i_index )
442 {
443 std::unique_lock aGuard( m_aMutex );
444 // sanity checks
445 if ( m_bDisposed )
446 throw DisposedException();
447
448 lcl_checkIndex( maImageSets, i_index, *this );
449
450 // actual removal
451 ::std::vector< Sequence< OUString > >::iterator removalPos = maImageSets.begin() + i_index;
452 Sequence< OUString > aRemovedElement( *removalPos );
453 maImageSets.erase( removalPos );
454
455 // listener notification
456 lcl_notify( aGuard, maContainerListeners, &XContainerListener::elementRemoved, i_index, aRemovedElement, *this );
457 }
458
459
460 void SAL_CALL AnimatedImagesControlModel::addContainerListener( const Reference< XContainerListener >& i_listener )
461 {
462 std::unique_lock aGuard( m_aMutex );
463 maContainerListeners.addInterface( aGuard, i_listener );
464 }
465
466
467 void SAL_CALL AnimatedImagesControlModel::removeContainerListener( const Reference< XContainerListener >& i_listener )
468 {
469 std::unique_lock aGuard( m_aMutex );
470 maContainerListeners.removeInterface( aGuard, i_listener );
471 }
472
473}
474
475extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
477 css::uno::XComponentContext *,
478 css::uno::Sequence<css::uno::Any> const &)
479{
480 return cppu::acquire(new AnimatedImagesControl());
481}
482
483extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
485 css::uno::XComponentContext *context,
486 css::uno::Sequence<css::uno::Any> const &)
487{
488 return cppu::acquire(new toolkit::AnimatedImagesControlModel(context));
489}
490
491/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * org_openoffice_comp_toolkit_AnimatedImagesControlModel_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * org_openoffice_comp_toolkit_AnimatedImagesControl_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
AnyEventRef aEvent
virtual css::uno::Any ImplGetDefaultValue(sal_uInt16 nPropId) const
void SAL_CALL disposing(const css::lang::EventObject &Source) override
Definition: unocontrol.cxx:654
sal_Int32 addInterface(std::unique_lock< std::mutex > &rGuard, const css::uno::Reference< ListenerT > &rxIFace)
void notifyEach(std::unique_lock< std::mutex > &rGuard, void(SAL_CALL ListenerT::*NotificationMethod)(const EventT &), const EventT &Event) const
sal_Int32 getLength(std::unique_lock< std::mutex > &rGuard) const
sal_Int32 removeInterface(std::unique_lock< std::mutex > &rGuard, const css::uno::Reference< ListenerT > &rxIFace)
virtual ::sal_Int16 SAL_CALL getScaleMode() override
virtual css::uno::Sequence< OUString > SAL_CALL getImageSet(::sal_Int32 i_index) override
::cppu::IPropertyArrayHelper & getInfoHelper() override
virtual void SAL_CALL addContainerListener(const css::uno::Reference< css::container::XContainerListener > &i_listener) override
virtual ::sal_Int32 SAL_CALL getStepTime() override
virtual void SAL_CALL replaceImageSet(::sal_Int32 i_index, const css::uno::Sequence< OUString > &i_imageURLs) override
virtual ~AnimatedImagesControlModel() override
virtual ::sal_Int32 SAL_CALL getImageSetCount() override
virtual void SAL_CALL insertImageSet(::sal_Int32 i_index, const css::uno::Sequence< OUString > &i_imageURLs) override
virtual void SAL_CALL removeContainerListener(const css::uno::Reference< css::container::XContainerListener > &i_listener) override
virtual void SAL_CALL setStepTime(::sal_Int32 _steptime) override
comphelper::OInterfaceContainerHelper4< css::container::XContainerListener > maContainerListeners
css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual void SAL_CALL setAutoRepeat(sal_Bool _autorepeat) override
void setFastPropertyValue_NoBroadcast(std::unique_lock< std::mutex > &rGuard, sal_Int32 nHandle, const css::uno::Any &rValue) override
virtual void SAL_CALL removeImageSet(::sal_Int32 i_index) override
virtual sal_Bool SAL_CALL getAutoRepeat() override
css::uno::Any ImplGetDefaultValue(sal_uInt16 nPropId) const override
css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
OUString SAL_CALL getServiceName() override
virtual void SAL_CALL setScaleMode(::sal_Int16 _scalemode) override
virtual rtl::Reference< UnoControlModel > Clone() const override
OUString SAL_CALL getImplementationName() override
std::vector< css::uno::Sequence< OUString > > maImageSets
AnimatedImagesControlModel(css::uno::Reference< css::uno::XComponentContext > const &i_factory)
Any aHelper
bool m_bDisposed
std::mutex m_aMutex
void SAL_CALL elementReplaced(const css::container::ContainerEvent &Event) override
void SAL_CALL elementRemoved(const css::container::ContainerEvent &Event) override
DECL_LISTENERMULTIPLEXER_END void SAL_CALL elementInserted(const css::container::ContainerEvent &Event) override
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
VBAHELPER_DLLPUBLIC bool setPropertyValue(css::uno::Sequence< css::beans::PropertyValue > &aProp, const OUString &aName, const css::uno::Any &aValue)
bool getPropertyValue(ValueType &rValue, css::uno::Reference< css::beans::XPropertySet > const &xPropSet, OUString const &propName)
::cppu::AggImplInheritanceHelper1< UnoControlModel, css::awt::XAnimatedImages > AnimatedImagesControlModel_Base
const OUString & GetPropertyName(sal_uInt16 nPropertyId)
Definition: property.cxx:295
#define BASEPROPERTY_STEP_TIME
Definition: property.hxx:151
#define BASEPROPERTY_BORDER
Definition: property.hxx:39
#define BASEPROPERTY_HELPURL
Definition: property.hxx:91
#define BASEPROPERTY_BACKGROUNDCOLOR
Definition: property.hxx:35
#define BASEPROPERTY_AUTO_REPEAT
Definition: property.hxx:193
#define BASEPROPERTY_DEFAULTCONTROL
Definition: property.hxx:52
#define BASEPROPERTY_BORDERCOLOR
Definition: property.hxx:145
#define BASEPROPERTY_ENABLEVISIBLE
Definition: property.hxx:180
#define BASEPROPERTY_HELPTEXT
Definition: property.hxx:106
#define BASEPROPERTY_IMAGE_SCALE_MODE
Definition: property.hxx:172
unsigned char sal_Bool