bump product version to 6.3.0.0.beta1
[LibreOffice.git] / sd / source / ui / unoidl / randomnode.cxx
blob61f514af10f7e2bbf450a1101f0b819af9b493b4
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 .
20 #include <com/sun/star/animations/XTimeContainer.hpp>
21 #include <com/sun/star/presentation/ParagraphTarget.hpp>
22 #include <com/sun/star/animations/AnimationFill.hpp>
23 #include <com/sun/star/animations/AnimationNodeType.hpp>
24 #include <com/sun/star/animations/XAnimate.hpp>
25 #include <com/sun/star/animations/AnimationRestart.hpp>
26 #include <com/sun/star/animations/ParallelTimeContainer.hpp>
27 #include <com/sun/star/lang/IllegalArgumentException.hpp>
28 #include <com/sun/star/lang/XServiceInfo.hpp>
29 #include <com/sun/star/lang/XInitialization.hpp>
30 #include <com/sun/star/container/XEnumerationAccess.hpp>
31 #include <com/sun/star/util/XCloneable.hpp>
32 #include <comphelper/processfactory.hxx>
34 #include <cppuhelper/implbase.hxx>
35 #include <cppuhelper/supportsservice.hxx>
36 #include <osl/mutex.hxx>
37 #include <CustomAnimationPreset.hxx>
38 #include <facreg.hxx>
39 #include <randomnode.hxx>
41 using ::osl::Mutex;
42 using ::osl::Guard;
44 using ::com::sun::star::uno::Reference;
45 using ::com::sun::star::uno::RuntimeException;
46 using ::com::sun::star::uno::Exception;
47 using ::com::sun::star::uno::Sequence;
48 using ::com::sun::star::uno::Any;
49 using ::com::sun::star::uno::UNO_QUERY;
50 using ::com::sun::star::uno::XInterface;
51 using ::com::sun::star::beans::NamedValue;
52 using ::com::sun::star::lang::IllegalArgumentException;
53 using ::com::sun::star::container::NoSuchElementException;
54 using ::com::sun::star::lang::WrappedTargetException;
55 using ::com::sun::star::container::XEnumeration;
56 using ::com::sun::star::container::XEnumerationAccess;
57 using ::com::sun::star::util::XCloneable;
58 using ::com::sun::star::lang::XServiceInfo;
59 using ::com::sun::star::lang::XInitialization;
60 using ::com::sun::star::uno::Type;
61 using ::com::sun::star::uno::XWeak;
62 using ::com::sun::star::presentation::ParagraphTarget;
63 using ::com::sun::star::drawing::XShape;
65 using namespace ::com::sun::star::animations;
66 namespace sd
69 typedef ::cppu::WeakImplHelper< XTimeContainer, XEnumerationAccess, XCloneable, XServiceInfo, XInitialization > RandomAnimationNodeBase;
70 class RandomAnimationNode : public RandomAnimationNodeBase
72 public:
73 RandomAnimationNode( const RandomAnimationNode& rNode );
74 explicit RandomAnimationNode( sal_Int16 nPresetClass );
75 RandomAnimationNode();
77 void init( sal_Int16 nPresetClass );
79 // XInitialization
80 void SAL_CALL initialize( const Sequence< Any >& aArguments ) override;
82 // XChild
83 Reference< XInterface > SAL_CALL getParent( ) override;
84 void SAL_CALL setParent( const Reference< XInterface >& Parent ) override;
86 // XCloneable
87 virtual Reference< XCloneable > SAL_CALL createClone() override;
89 // XServiceInfo
90 OUString SAL_CALL getImplementationName() override;
91 Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
92 sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override;
94 // XAnimationNode
95 ::sal_Int16 SAL_CALL getType() override;
96 Any SAL_CALL getBegin() override;
97 void SAL_CALL setBegin( const Any& _begin ) override;
98 Any SAL_CALL getDuration() override;
99 void SAL_CALL setDuration( const Any& _duration ) override;
100 Any SAL_CALL getEnd() override;
101 void SAL_CALL setEnd( const Any& _end ) override;
102 Any SAL_CALL getEndSync() override;
103 void SAL_CALL setEndSync( const Any& _endsync ) override;
104 Any SAL_CALL getRepeatCount() override;
105 void SAL_CALL setRepeatCount( const Any& _repeatcount ) override;
106 Any SAL_CALL getRepeatDuration() override;
107 void SAL_CALL setRepeatDuration( const Any& _repeatduration ) override;
108 ::sal_Int16 SAL_CALL getFill() override;
109 void SAL_CALL setFill( ::sal_Int16 _fill ) override;
110 ::sal_Int16 SAL_CALL getFillDefault() override;
111 void SAL_CALL setFillDefault( ::sal_Int16 _filldefault ) override;
112 ::sal_Int16 SAL_CALL getRestart() override;
113 void SAL_CALL setRestart( ::sal_Int16 _restart ) override;
114 ::sal_Int16 SAL_CALL getRestartDefault() override;
115 void SAL_CALL setRestartDefault( ::sal_Int16 _restartdefault ) override;
116 double SAL_CALL getAcceleration() override;
117 void SAL_CALL setAcceleration( double _acceleration ) override;
118 double SAL_CALL getDecelerate() override;
119 void SAL_CALL setDecelerate( double _decelerate ) override;
120 sal_Bool SAL_CALL getAutoReverse() override;
121 void SAL_CALL setAutoReverse( sal_Bool _autoreverse ) override;
122 Sequence< NamedValue > SAL_CALL getUserData() override;
123 void SAL_CALL setUserData( const Sequence< NamedValue >& _userdata ) override;
125 // XElementAccess
126 virtual Type SAL_CALL getElementType() override;
127 virtual sal_Bool SAL_CALL hasElements() override;
129 // XEnumerationAccess
130 virtual Reference< XEnumeration > SAL_CALL createEnumeration() override;
132 // XTimeContainer
133 Reference< XAnimationNode > SAL_CALL insertBefore( const Reference< XAnimationNode >& newChild, const Reference< XAnimationNode >& refChild ) override;
134 Reference< XAnimationNode > SAL_CALL insertAfter( const Reference< XAnimationNode >& newChild, const Reference< XAnimationNode >& refChild ) override;
135 Reference< XAnimationNode > SAL_CALL replaceChild( const Reference< XAnimationNode >& newChild, const Reference< XAnimationNode >& oldChild ) override;
136 Reference< XAnimationNode > SAL_CALL removeChild( const Reference< XAnimationNode >& oldChild ) override;
137 Reference< XAnimationNode > SAL_CALL appendChild( const Reference< XAnimationNode >& newChild ) override;
139 private:
140 // our first, last and only protection from multi-threads!
141 Mutex maMutex;
143 sal_Int16 mnPresetClass;
144 Reference< XInterface > mxParent;
146 Any maBegin, maDuration, maEnd, maEndSync, maRepeatCount, maRepeatDuration, maTarget;
147 sal_Int16 mnFill, mnFillDefault, mnRestart, mnRestartDefault;
148 double mfAcceleration, mfDecelerate;
149 bool mbAutoReverse;
150 Sequence< NamedValue > maUserData;
152 Reference< XAnimate > mxFirstNode;
155 Reference< XInterface > RandomAnimationNode_createInstance( sal_Int16 nPresetClass )
157 Reference< XInterface > xInt( static_cast<XWeak*>( new RandomAnimationNode( nPresetClass ) ) );
158 return xInt;
161 RandomAnimationNode::RandomAnimationNode( const RandomAnimationNode& rNode )
162 : RandomAnimationNodeBase(rNode),
163 mnPresetClass( rNode.mnPresetClass ),
164 maBegin( rNode.maBegin ),
165 maDuration( rNode.maDuration ),
166 maEnd( rNode.maEnd ),
167 maEndSync( rNode.maEndSync ),
168 maRepeatCount( rNode.maRepeatCount ),
169 maRepeatDuration( rNode.maRepeatDuration ),
170 maTarget( rNode.maTarget ),
171 mnFill( rNode.mnFill ),
172 mnFillDefault( rNode.mnFillDefault ),
173 mnRestart( rNode.mnRestart ),
174 mnRestartDefault( rNode.mnRestartDefault ),
175 mfAcceleration( rNode.mfAcceleration ),
176 mfDecelerate( rNode.mfDecelerate ),
177 mbAutoReverse( rNode.mbAutoReverse ),
178 maUserData( rNode.maUserData )
182 RandomAnimationNode::RandomAnimationNode( sal_Int16 nPresetClass )
184 init( nPresetClass );
187 RandomAnimationNode::RandomAnimationNode()
189 init( 1 );
192 void RandomAnimationNode::init( sal_Int16 nPresetClass )
194 mnPresetClass = nPresetClass;
195 mnFill = AnimationFill::DEFAULT;
196 mnFillDefault = AnimationFill::INHERIT;
197 mnRestart = AnimationRestart::DEFAULT;
198 mnRestartDefault = AnimationRestart::INHERIT;
199 mfAcceleration = 0.0;
200 mfDecelerate = 0.0;
201 mbAutoReverse = false;
204 // XInitialization
205 void SAL_CALL RandomAnimationNode::initialize( const Sequence< Any >& aArguments )
207 if( aArguments.getLength() != 1 )
208 throw IllegalArgumentException();
210 if( aArguments[0].getValueType() == ::cppu::UnoType<sal_Int16>::get() )
212 aArguments[0] >>= mnPresetClass;
214 else if( aArguments[0].getValueType() != ::cppu::UnoType<ParagraphTarget>::get() )
216 Reference< XShape > xShape;
217 aArguments[0] >>= xShape;
218 if( !xShape.is() )
219 throw IllegalArgumentException();
221 maTarget = aArguments[0];
224 // XAnimationNode
225 sal_Int16 SAL_CALL RandomAnimationNode::getType()
227 Guard< Mutex > aGuard( maMutex );
228 return css::animations::AnimationNodeType::PAR;
231 // XAnimationNode
232 Any SAL_CALL RandomAnimationNode::getBegin()
234 Guard< Mutex > aGuard( maMutex );
235 return maBegin;
238 // XAnimationNode
239 void SAL_CALL RandomAnimationNode::setBegin( const Any& _begin )
241 Guard< Mutex > aGuard( maMutex );
242 maBegin = _begin;
245 // XAnimationNode
246 Any SAL_CALL RandomAnimationNode::getDuration()
248 Guard< Mutex > aGuard( maMutex );
249 return maDuration;
252 // XAnimationNode
253 void SAL_CALL RandomAnimationNode::setDuration( const Any& _duration )
255 Guard< Mutex > aGuard( maMutex );
256 maDuration = _duration;
259 // XAnimationNode
260 Any SAL_CALL RandomAnimationNode::getEnd()
262 Guard< Mutex > aGuard( maMutex );
263 return maEnd;
266 // XAnimationNode
267 void SAL_CALL RandomAnimationNode::setEnd( const Any& _end )
269 Guard< Mutex > aGuard( maMutex );
270 maEnd = _end;
273 // XAnimationNode
274 Any SAL_CALL RandomAnimationNode::getEndSync()
276 Guard< Mutex > aGuard( maMutex );
277 return maEndSync;
280 // XAnimationNode
281 void SAL_CALL RandomAnimationNode::setEndSync( const Any& _endsync )
283 Guard< Mutex > aGuard( maMutex );
284 maEndSync = _endsync;
287 // XAnimationNode
288 Any SAL_CALL RandomAnimationNode::getRepeatCount()
290 Guard< Mutex > aGuard( maMutex );
291 return maRepeatCount;
294 // XAnimationNode
295 void SAL_CALL RandomAnimationNode::setRepeatCount( const Any& _repeatcount )
297 Guard< Mutex > aGuard( maMutex );
298 maRepeatCount = _repeatcount;
301 // XAnimationNode
302 Any SAL_CALL RandomAnimationNode::getRepeatDuration()
304 Guard< Mutex > aGuard( maMutex );
305 return maRepeatDuration;
308 // XAnimationNode
309 void SAL_CALL RandomAnimationNode::setRepeatDuration( const Any& _repeatduration )
311 Guard< Mutex > aGuard( maMutex );
312 maRepeatDuration = _repeatduration;
315 // XAnimationNode
316 sal_Int16 SAL_CALL RandomAnimationNode::getFill()
318 Guard< Mutex > aGuard( maMutex );
319 return mnFill;
322 // XAnimationNode
323 void SAL_CALL RandomAnimationNode::setFill( sal_Int16 _fill )
325 Guard< Mutex > aGuard( maMutex );
326 mnFill = _fill;
329 // XAnimationNode
330 sal_Int16 SAL_CALL RandomAnimationNode::getFillDefault()
332 Guard< Mutex > aGuard( maMutex );
333 return mnFillDefault;
336 // XAnimationNode
337 void SAL_CALL RandomAnimationNode::setFillDefault( sal_Int16 _filldefault )
339 Guard< Mutex > aGuard( maMutex );
340 mnFillDefault = _filldefault;
343 // XAnimationNode
344 sal_Int16 SAL_CALL RandomAnimationNode::getRestart()
346 Guard< Mutex > aGuard( maMutex );
347 return mnRestart;
350 // XAnimationNode
351 void SAL_CALL RandomAnimationNode::setRestart( sal_Int16 _restart )
353 Guard< Mutex > aGuard( maMutex );
354 mnRestart = _restart;
357 // XAnimationNode
358 sal_Int16 SAL_CALL RandomAnimationNode::getRestartDefault()
360 Guard< Mutex > aGuard( maMutex );
361 return mnRestartDefault;
364 // XAnimationNode
365 void SAL_CALL RandomAnimationNode::setRestartDefault( sal_Int16 _restartdefault )
367 Guard< Mutex > aGuard( maMutex );
368 mnRestartDefault = _restartdefault;
371 // XAnimationNode
372 double SAL_CALL RandomAnimationNode::getAcceleration()
374 Guard< Mutex > aGuard( maMutex );
375 return mfAcceleration;
378 // XAnimationNode
379 void SAL_CALL RandomAnimationNode::setAcceleration( double _acceleration )
381 Guard< Mutex > aGuard( maMutex );
382 mfAcceleration = _acceleration;
385 // XAnimationNode
386 double SAL_CALL RandomAnimationNode::getDecelerate()
388 Guard< Mutex > aGuard( maMutex );
389 return mfDecelerate;
392 // XAnimationNode
393 void SAL_CALL RandomAnimationNode::setDecelerate( double _decelerate )
395 Guard< Mutex > aGuard( maMutex );
396 mfDecelerate = _decelerate;
399 // XAnimationNode
400 sal_Bool SAL_CALL RandomAnimationNode::getAutoReverse()
402 Guard< Mutex > aGuard( maMutex );
403 return mbAutoReverse;
406 // XAnimationNode
407 void SAL_CALL RandomAnimationNode::setAutoReverse( sal_Bool _autoreverse )
409 Guard< Mutex > aGuard( maMutex );
410 mbAutoReverse = _autoreverse;
413 Sequence< NamedValue > SAL_CALL RandomAnimationNode::getUserData()
415 Guard< Mutex > aGuard( maMutex );
416 return maUserData;
419 void SAL_CALL RandomAnimationNode::setUserData( const Sequence< NamedValue >& _userdata )
421 Guard< Mutex > aGuard( maMutex );
422 maUserData = _userdata;
425 // XChild
426 Reference< XInterface > SAL_CALL RandomAnimationNode::getParent()
428 Guard< Mutex > aGuard( maMutex );
429 return mxParent;
432 // XChild
433 void SAL_CALL RandomAnimationNode::setParent( const Reference< XInterface >& Parent )
435 Guard< Mutex > aGuard( maMutex );
436 mxParent = Parent;
439 // XCloneable
440 Reference< XCloneable > SAL_CALL RandomAnimationNode::createClone()
442 Reference< XCloneable > xNewNode( new RandomAnimationNode( *this ) );
443 return xNewNode;
446 // XElementAccess
447 Type SAL_CALL RandomAnimationNode::getElementType()
449 return cppu::UnoType<XAnimationNode>::get();
452 // XElementAccess
453 sal_Bool SAL_CALL RandomAnimationNode::hasElements()
455 return true;
458 // XEnumerationAccess
459 Reference< XEnumeration > SAL_CALL RandomAnimationNode::createEnumeration()
461 Guard< Mutex > aGuard( maMutex );
463 if( !maTarget.hasValue() && mxFirstNode.is() )
465 Any aTarget( mxFirstNode->getTarget() );
466 if( aTarget.hasValue() )
468 maTarget = aTarget;
469 mxFirstNode.clear();
473 Reference< XEnumeration > xEnum;
475 Reference< XEnumerationAccess > aEnumAccess( CustomAnimationPresets::getCustomAnimationPresets().getRandomPreset( mnPresetClass ), UNO_QUERY );
477 if( aEnumAccess.is() )
479 Reference< XEnumeration > xEnumeration( aEnumAccess->createEnumeration(), UNO_QUERY );
480 if( xEnumeration.is() )
482 while( xEnumeration->hasMoreElements() )
484 Reference< XAnimate > xAnimate( xEnumeration->nextElement(), UNO_QUERY );
485 if( xAnimate.is() )
486 xAnimate->setTarget( maTarget );
489 xEnum = aEnumAccess->createEnumeration();
491 else
493 // no presets? give empty node!
494 Reference< XParallelTimeContainer > xTimeContainer = ParallelTimeContainer::create( comphelper::getProcessComponentContext() );
495 xEnum = xTimeContainer->createEnumeration();
498 return xEnum;
501 // XTimeContainer
502 Reference< XAnimationNode > SAL_CALL RandomAnimationNode::insertBefore( const Reference< XAnimationNode >& newChild, const Reference< XAnimationNode >& )
504 return appendChild( newChild );
507 // XTimeContainer
508 Reference< XAnimationNode > SAL_CALL RandomAnimationNode::insertAfter( const Reference< XAnimationNode >& newChild, const Reference< XAnimationNode >& )
510 return appendChild( newChild );
513 // XTimeContainer
514 Reference< XAnimationNode > SAL_CALL RandomAnimationNode::replaceChild( const Reference< XAnimationNode >& newChild, const Reference< XAnimationNode >& )
516 return appendChild( newChild );
519 // XTimeContainer
520 Reference< XAnimationNode > SAL_CALL RandomAnimationNode::removeChild( const Reference< XAnimationNode >& oldChild )
522 return oldChild;
525 // XTimeContainer
526 Reference< XAnimationNode > SAL_CALL RandomAnimationNode::appendChild( const Reference< XAnimationNode >& newChild )
528 Reference< XAnimate > xAnimate( newChild, UNO_QUERY );
529 if( xAnimate.is() )
531 Any aTarget( xAnimate->getTarget() );
532 if( aTarget.hasValue() )
533 maTarget = aTarget;
536 if( !maTarget.hasValue() && !mxFirstNode.is() )
537 mxFirstNode = xAnimate;
539 return newChild;
542 // XServiceInfo
543 OUString RandomAnimationNode::getImplementationName()
545 return OUString( "sd::RandomAnimationNode" ) ;
548 // XServiceInfo
549 sal_Bool RandomAnimationNode::supportsService(const OUString& ServiceName)
551 return cppu::supportsService(this, ServiceName);
554 // XServiceInfo
555 Sequence< OUString > RandomAnimationNode::getSupportedServiceNames()
557 Sequence< OUString > aSeq( 2 );
558 aSeq[0] = "com.sun.star.animations.ParallelTimeContainer";
559 aSeq[1] = "com.sun.star.comp.sd.RandomAnimationNode";
560 return aSeq;
565 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
566 RandomAnimationNode_get_implementation(css::uno::XComponentContext*,
567 css::uno::Sequence<css::uno::Any> const &)
569 return cppu::acquire(new sd::RandomAnimationNode());
573 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */