bump product version to 6.4.0.3
[LibreOffice.git] / sd / source / ui / unoidl / randomnode.cxx
blob64fcfd6b32b523e59671c1dfd03b6fca42fd7715
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 <randomnode.hxx>
40 using ::osl::Mutex;
41 using ::osl::Guard;
43 using ::com::sun::star::uno::Reference;
44 using ::com::sun::star::uno::RuntimeException;
45 using ::com::sun::star::uno::Exception;
46 using ::com::sun::star::uno::Sequence;
47 using ::com::sun::star::uno::Any;
48 using ::com::sun::star::uno::UNO_QUERY;
49 using ::com::sun::star::uno::XInterface;
50 using ::com::sun::star::beans::NamedValue;
51 using ::com::sun::star::lang::IllegalArgumentException;
52 using ::com::sun::star::container::NoSuchElementException;
53 using ::com::sun::star::lang::WrappedTargetException;
54 using ::com::sun::star::container::XEnumeration;
55 using ::com::sun::star::container::XEnumerationAccess;
56 using ::com::sun::star::util::XCloneable;
57 using ::com::sun::star::lang::XServiceInfo;
58 using ::com::sun::star::lang::XInitialization;
59 using ::com::sun::star::uno::Type;
60 using ::com::sun::star::uno::XWeak;
61 using ::com::sun::star::presentation::ParagraphTarget;
62 using ::com::sun::star::drawing::XShape;
64 using namespace ::com::sun::star::animations;
65 namespace sd
68 typedef ::cppu::WeakImplHelper< XTimeContainer, XEnumerationAccess, XCloneable, XServiceInfo, XInitialization > RandomAnimationNodeBase;
69 class RandomAnimationNode : public RandomAnimationNodeBase
71 public:
72 RandomAnimationNode( const RandomAnimationNode& rNode );
73 explicit RandomAnimationNode( sal_Int16 nPresetClass );
74 RandomAnimationNode();
76 void init( sal_Int16 nPresetClass );
78 // XInitialization
79 void SAL_CALL initialize( const Sequence< Any >& aArguments ) override;
81 // XChild
82 Reference< XInterface > SAL_CALL getParent( ) override;
83 void SAL_CALL setParent( const Reference< XInterface >& Parent ) override;
85 // XCloneable
86 virtual Reference< XCloneable > SAL_CALL createClone() override;
88 // XServiceInfo
89 OUString SAL_CALL getImplementationName() override;
90 Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
91 sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override;
93 // XAnimationNode
94 ::sal_Int16 SAL_CALL getType() override;
95 Any SAL_CALL getBegin() override;
96 void SAL_CALL setBegin( const Any& _begin ) override;
97 Any SAL_CALL getDuration() override;
98 void SAL_CALL setDuration( const Any& _duration ) override;
99 Any SAL_CALL getEnd() override;
100 void SAL_CALL setEnd( const Any& _end ) override;
101 Any SAL_CALL getEndSync() override;
102 void SAL_CALL setEndSync( const Any& _endsync ) override;
103 Any SAL_CALL getRepeatCount() override;
104 void SAL_CALL setRepeatCount( const Any& _repeatcount ) override;
105 Any SAL_CALL getRepeatDuration() override;
106 void SAL_CALL setRepeatDuration( const Any& _repeatduration ) override;
107 ::sal_Int16 SAL_CALL getFill() override;
108 void SAL_CALL setFill( ::sal_Int16 _fill ) override;
109 ::sal_Int16 SAL_CALL getFillDefault() override;
110 void SAL_CALL setFillDefault( ::sal_Int16 _filldefault ) override;
111 ::sal_Int16 SAL_CALL getRestart() override;
112 void SAL_CALL setRestart( ::sal_Int16 _restart ) override;
113 ::sal_Int16 SAL_CALL getRestartDefault() override;
114 void SAL_CALL setRestartDefault( ::sal_Int16 _restartdefault ) override;
115 double SAL_CALL getAcceleration() override;
116 void SAL_CALL setAcceleration( double _acceleration ) override;
117 double SAL_CALL getDecelerate() override;
118 void SAL_CALL setDecelerate( double _decelerate ) override;
119 sal_Bool SAL_CALL getAutoReverse() override;
120 void SAL_CALL setAutoReverse( sal_Bool _autoreverse ) override;
121 Sequence< NamedValue > SAL_CALL getUserData() override;
122 void SAL_CALL setUserData( const Sequence< NamedValue >& _userdata ) override;
124 // XElementAccess
125 virtual Type SAL_CALL getElementType() override;
126 virtual sal_Bool SAL_CALL hasElements() override;
128 // XEnumerationAccess
129 virtual Reference< XEnumeration > SAL_CALL createEnumeration() override;
131 // XTimeContainer
132 Reference< XAnimationNode > SAL_CALL insertBefore( const Reference< XAnimationNode >& newChild, const Reference< XAnimationNode >& refChild ) override;
133 Reference< XAnimationNode > SAL_CALL insertAfter( const Reference< XAnimationNode >& newChild, const Reference< XAnimationNode >& refChild ) override;
134 Reference< XAnimationNode > SAL_CALL replaceChild( const Reference< XAnimationNode >& newChild, const Reference< XAnimationNode >& oldChild ) override;
135 Reference< XAnimationNode > SAL_CALL removeChild( const Reference< XAnimationNode >& oldChild ) override;
136 Reference< XAnimationNode > SAL_CALL appendChild( const Reference< XAnimationNode >& newChild ) override;
138 private:
139 // our first, last and only protection from multi-threads!
140 Mutex maMutex;
142 sal_Int16 mnPresetClass;
143 Reference< XInterface > mxParent;
145 Any maBegin, maDuration, maEnd, maEndSync, maRepeatCount, maRepeatDuration, maTarget;
146 sal_Int16 mnFill, mnFillDefault, mnRestart, mnRestartDefault;
147 double mfAcceleration, mfDecelerate;
148 bool mbAutoReverse;
149 Sequence< NamedValue > maUserData;
151 Reference< XAnimate > mxFirstNode;
154 Reference< XInterface > RandomAnimationNode_createInstance( sal_Int16 nPresetClass )
156 Reference< XInterface > xInt( static_cast<XWeak*>( new RandomAnimationNode( nPresetClass ) ) );
157 return xInt;
160 RandomAnimationNode::RandomAnimationNode( const RandomAnimationNode& rNode )
161 : RandomAnimationNodeBase(rNode),
162 mnPresetClass( rNode.mnPresetClass ),
163 maBegin( rNode.maBegin ),
164 maDuration( rNode.maDuration ),
165 maEnd( rNode.maEnd ),
166 maEndSync( rNode.maEndSync ),
167 maRepeatCount( rNode.maRepeatCount ),
168 maRepeatDuration( rNode.maRepeatDuration ),
169 maTarget( rNode.maTarget ),
170 mnFill( rNode.mnFill ),
171 mnFillDefault( rNode.mnFillDefault ),
172 mnRestart( rNode.mnRestart ),
173 mnRestartDefault( rNode.mnRestartDefault ),
174 mfAcceleration( rNode.mfAcceleration ),
175 mfDecelerate( rNode.mfDecelerate ),
176 mbAutoReverse( rNode.mbAutoReverse ),
177 maUserData( rNode.maUserData )
181 RandomAnimationNode::RandomAnimationNode( sal_Int16 nPresetClass )
183 init( nPresetClass );
186 RandomAnimationNode::RandomAnimationNode()
188 init( 1 );
191 void RandomAnimationNode::init( sal_Int16 nPresetClass )
193 mnPresetClass = nPresetClass;
194 mnFill = AnimationFill::DEFAULT;
195 mnFillDefault = AnimationFill::INHERIT;
196 mnRestart = AnimationRestart::DEFAULT;
197 mnRestartDefault = AnimationRestart::INHERIT;
198 mfAcceleration = 0.0;
199 mfDecelerate = 0.0;
200 mbAutoReverse = false;
203 // XInitialization
204 void SAL_CALL RandomAnimationNode::initialize( const Sequence< Any >& aArguments )
206 if( aArguments.getLength() != 1 )
207 throw IllegalArgumentException();
209 if( aArguments[0].getValueType() == ::cppu::UnoType<sal_Int16>::get() )
211 aArguments[0] >>= mnPresetClass;
213 else if( aArguments[0].getValueType() != ::cppu::UnoType<ParagraphTarget>::get() )
215 Reference< XShape > xShape;
216 aArguments[0] >>= xShape;
217 if( !xShape.is() )
218 throw IllegalArgumentException();
220 maTarget = aArguments[0];
223 // XAnimationNode
224 sal_Int16 SAL_CALL RandomAnimationNode::getType()
226 Guard< Mutex > aGuard( maMutex );
227 return css::animations::AnimationNodeType::PAR;
230 // XAnimationNode
231 Any SAL_CALL RandomAnimationNode::getBegin()
233 Guard< Mutex > aGuard( maMutex );
234 return maBegin;
237 // XAnimationNode
238 void SAL_CALL RandomAnimationNode::setBegin( const Any& _begin )
240 Guard< Mutex > aGuard( maMutex );
241 maBegin = _begin;
244 // XAnimationNode
245 Any SAL_CALL RandomAnimationNode::getDuration()
247 Guard< Mutex > aGuard( maMutex );
248 return maDuration;
251 // XAnimationNode
252 void SAL_CALL RandomAnimationNode::setDuration( const Any& _duration )
254 Guard< Mutex > aGuard( maMutex );
255 maDuration = _duration;
258 // XAnimationNode
259 Any SAL_CALL RandomAnimationNode::getEnd()
261 Guard< Mutex > aGuard( maMutex );
262 return maEnd;
265 // XAnimationNode
266 void SAL_CALL RandomAnimationNode::setEnd( const Any& _end )
268 Guard< Mutex > aGuard( maMutex );
269 maEnd = _end;
272 // XAnimationNode
273 Any SAL_CALL RandomAnimationNode::getEndSync()
275 Guard< Mutex > aGuard( maMutex );
276 return maEndSync;
279 // XAnimationNode
280 void SAL_CALL RandomAnimationNode::setEndSync( const Any& _endsync )
282 Guard< Mutex > aGuard( maMutex );
283 maEndSync = _endsync;
286 // XAnimationNode
287 Any SAL_CALL RandomAnimationNode::getRepeatCount()
289 Guard< Mutex > aGuard( maMutex );
290 return maRepeatCount;
293 // XAnimationNode
294 void SAL_CALL RandomAnimationNode::setRepeatCount( const Any& _repeatcount )
296 Guard< Mutex > aGuard( maMutex );
297 maRepeatCount = _repeatcount;
300 // XAnimationNode
301 Any SAL_CALL RandomAnimationNode::getRepeatDuration()
303 Guard< Mutex > aGuard( maMutex );
304 return maRepeatDuration;
307 // XAnimationNode
308 void SAL_CALL RandomAnimationNode::setRepeatDuration( const Any& _repeatduration )
310 Guard< Mutex > aGuard( maMutex );
311 maRepeatDuration = _repeatduration;
314 // XAnimationNode
315 sal_Int16 SAL_CALL RandomAnimationNode::getFill()
317 Guard< Mutex > aGuard( maMutex );
318 return mnFill;
321 // XAnimationNode
322 void SAL_CALL RandomAnimationNode::setFill( sal_Int16 _fill )
324 Guard< Mutex > aGuard( maMutex );
325 mnFill = _fill;
328 // XAnimationNode
329 sal_Int16 SAL_CALL RandomAnimationNode::getFillDefault()
331 Guard< Mutex > aGuard( maMutex );
332 return mnFillDefault;
335 // XAnimationNode
336 void SAL_CALL RandomAnimationNode::setFillDefault( sal_Int16 _filldefault )
338 Guard< Mutex > aGuard( maMutex );
339 mnFillDefault = _filldefault;
342 // XAnimationNode
343 sal_Int16 SAL_CALL RandomAnimationNode::getRestart()
345 Guard< Mutex > aGuard( maMutex );
346 return mnRestart;
349 // XAnimationNode
350 void SAL_CALL RandomAnimationNode::setRestart( sal_Int16 _restart )
352 Guard< Mutex > aGuard( maMutex );
353 mnRestart = _restart;
356 // XAnimationNode
357 sal_Int16 SAL_CALL RandomAnimationNode::getRestartDefault()
359 Guard< Mutex > aGuard( maMutex );
360 return mnRestartDefault;
363 // XAnimationNode
364 void SAL_CALL RandomAnimationNode::setRestartDefault( sal_Int16 _restartdefault )
366 Guard< Mutex > aGuard( maMutex );
367 mnRestartDefault = _restartdefault;
370 // XAnimationNode
371 double SAL_CALL RandomAnimationNode::getAcceleration()
373 Guard< Mutex > aGuard( maMutex );
374 return mfAcceleration;
377 // XAnimationNode
378 void SAL_CALL RandomAnimationNode::setAcceleration( double _acceleration )
380 Guard< Mutex > aGuard( maMutex );
381 mfAcceleration = _acceleration;
384 // XAnimationNode
385 double SAL_CALL RandomAnimationNode::getDecelerate()
387 Guard< Mutex > aGuard( maMutex );
388 return mfDecelerate;
391 // XAnimationNode
392 void SAL_CALL RandomAnimationNode::setDecelerate( double _decelerate )
394 Guard< Mutex > aGuard( maMutex );
395 mfDecelerate = _decelerate;
398 // XAnimationNode
399 sal_Bool SAL_CALL RandomAnimationNode::getAutoReverse()
401 Guard< Mutex > aGuard( maMutex );
402 return mbAutoReverse;
405 // XAnimationNode
406 void SAL_CALL RandomAnimationNode::setAutoReverse( sal_Bool _autoreverse )
408 Guard< Mutex > aGuard( maMutex );
409 mbAutoReverse = _autoreverse;
412 Sequence< NamedValue > SAL_CALL RandomAnimationNode::getUserData()
414 Guard< Mutex > aGuard( maMutex );
415 return maUserData;
418 void SAL_CALL RandomAnimationNode::setUserData( const Sequence< NamedValue >& _userdata )
420 Guard< Mutex > aGuard( maMutex );
421 maUserData = _userdata;
424 // XChild
425 Reference< XInterface > SAL_CALL RandomAnimationNode::getParent()
427 Guard< Mutex > aGuard( maMutex );
428 return mxParent;
431 // XChild
432 void SAL_CALL RandomAnimationNode::setParent( const Reference< XInterface >& Parent )
434 Guard< Mutex > aGuard( maMutex );
435 mxParent = Parent;
438 // XCloneable
439 Reference< XCloneable > SAL_CALL RandomAnimationNode::createClone()
441 Reference< XCloneable > xNewNode( new RandomAnimationNode( *this ) );
442 return xNewNode;
445 // XElementAccess
446 Type SAL_CALL RandomAnimationNode::getElementType()
448 return cppu::UnoType<XAnimationNode>::get();
451 // XElementAccess
452 sal_Bool SAL_CALL RandomAnimationNode::hasElements()
454 return true;
457 // XEnumerationAccess
458 Reference< XEnumeration > SAL_CALL RandomAnimationNode::createEnumeration()
460 Guard< Mutex > aGuard( maMutex );
462 if( !maTarget.hasValue() && mxFirstNode.is() )
464 Any aTarget( mxFirstNode->getTarget() );
465 if( aTarget.hasValue() )
467 maTarget = aTarget;
468 mxFirstNode.clear();
472 Reference< XEnumeration > xEnum;
474 Reference< XEnumerationAccess > aEnumAccess( CustomAnimationPresets::getCustomAnimationPresets().getRandomPreset( mnPresetClass ), UNO_QUERY );
476 if( aEnumAccess.is() )
478 Reference< XEnumeration > xEnumeration = aEnumAccess->createEnumeration();
479 if( xEnumeration.is() )
481 while( xEnumeration->hasMoreElements() )
483 Reference< XAnimate > xAnimate( xEnumeration->nextElement(), UNO_QUERY );
484 if( xAnimate.is() )
485 xAnimate->setTarget( maTarget );
488 xEnum = aEnumAccess->createEnumeration();
490 else
492 // no presets? give empty node!
493 Reference< XParallelTimeContainer > xTimeContainer = ParallelTimeContainer::create( comphelper::getProcessComponentContext() );
494 xEnum = xTimeContainer->createEnumeration();
497 return xEnum;
500 // XTimeContainer
501 Reference< XAnimationNode > SAL_CALL RandomAnimationNode::insertBefore( const Reference< XAnimationNode >& newChild, const Reference< XAnimationNode >& )
503 return appendChild( newChild );
506 // XTimeContainer
507 Reference< XAnimationNode > SAL_CALL RandomAnimationNode::insertAfter( const Reference< XAnimationNode >& newChild, const Reference< XAnimationNode >& )
509 return appendChild( newChild );
512 // XTimeContainer
513 Reference< XAnimationNode > SAL_CALL RandomAnimationNode::replaceChild( const Reference< XAnimationNode >& newChild, const Reference< XAnimationNode >& )
515 return appendChild( newChild );
518 // XTimeContainer
519 Reference< XAnimationNode > SAL_CALL RandomAnimationNode::removeChild( const Reference< XAnimationNode >& oldChild )
521 return oldChild;
524 // XTimeContainer
525 Reference< XAnimationNode > SAL_CALL RandomAnimationNode::appendChild( const Reference< XAnimationNode >& newChild )
527 Reference< XAnimate > xAnimate( newChild, UNO_QUERY );
528 if( xAnimate.is() )
530 Any aTarget( xAnimate->getTarget() );
531 if( aTarget.hasValue() )
532 maTarget = aTarget;
535 if( !maTarget.hasValue() && !mxFirstNode.is() )
536 mxFirstNode = xAnimate;
538 return newChild;
541 // XServiceInfo
542 OUString RandomAnimationNode::getImplementationName()
544 return "sd::RandomAnimationNode" ;
547 // XServiceInfo
548 sal_Bool RandomAnimationNode::supportsService(const OUString& ServiceName)
550 return cppu::supportsService(this, ServiceName);
553 // XServiceInfo
554 Sequence< OUString > RandomAnimationNode::getSupportedServiceNames()
556 return { "com.sun.star.animations.ParallelTimeContainer", "com.sun.star.comp.sd.RandomAnimationNode" };
561 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
562 RandomAnimationNode_get_implementation(css::uno::XComponentContext*,
563 css::uno::Sequence<css::uno::Any> const &)
565 return cppu::acquire(new sd::RandomAnimationNode());
569 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */