1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
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
;
68 typedef ::cppu::WeakImplHelper
< XTimeContainer
, XEnumerationAccess
, XCloneable
, XServiceInfo
, XInitialization
> RandomAnimationNodeBase
;
69 class RandomAnimationNode
: public RandomAnimationNodeBase
72 RandomAnimationNode( const RandomAnimationNode
& rNode
);
73 explicit RandomAnimationNode( sal_Int16 nPresetClass
);
74 RandomAnimationNode();
76 void init( sal_Int16 nPresetClass
);
79 void SAL_CALL
initialize( const Sequence
< Any
>& aArguments
) override
;
82 Reference
< XInterface
> SAL_CALL
getParent( ) override
;
83 void SAL_CALL
setParent( const Reference
< XInterface
>& Parent
) override
;
86 virtual Reference
< XCloneable
> SAL_CALL
createClone() override
;
89 OUString SAL_CALL
getImplementationName() override
;
90 Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
91 sal_Bool SAL_CALL
supportsService(const OUString
& ServiceName
) override
;
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
;
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
;
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
;
139 // our first, last and only protection from multi-threads!
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
;
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
) ) );
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()
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;
200 mbAutoReverse
= false;
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
;
218 throw IllegalArgumentException();
220 maTarget
= aArguments
[0];
224 sal_Int16 SAL_CALL
RandomAnimationNode::getType()
226 Guard
< Mutex
> aGuard( maMutex
);
227 return css::animations::AnimationNodeType::PAR
;
231 Any SAL_CALL
RandomAnimationNode::getBegin()
233 Guard
< Mutex
> aGuard( maMutex
);
238 void SAL_CALL
RandomAnimationNode::setBegin( const Any
& _begin
)
240 Guard
< Mutex
> aGuard( maMutex
);
245 Any SAL_CALL
RandomAnimationNode::getDuration()
247 Guard
< Mutex
> aGuard( maMutex
);
252 void SAL_CALL
RandomAnimationNode::setDuration( const Any
& _duration
)
254 Guard
< Mutex
> aGuard( maMutex
);
255 maDuration
= _duration
;
259 Any SAL_CALL
RandomAnimationNode::getEnd()
261 Guard
< Mutex
> aGuard( maMutex
);
266 void SAL_CALL
RandomAnimationNode::setEnd( const Any
& _end
)
268 Guard
< Mutex
> aGuard( maMutex
);
273 Any SAL_CALL
RandomAnimationNode::getEndSync()
275 Guard
< Mutex
> aGuard( maMutex
);
280 void SAL_CALL
RandomAnimationNode::setEndSync( const Any
& _endsync
)
282 Guard
< Mutex
> aGuard( maMutex
);
283 maEndSync
= _endsync
;
287 Any SAL_CALL
RandomAnimationNode::getRepeatCount()
289 Guard
< Mutex
> aGuard( maMutex
);
290 return maRepeatCount
;
294 void SAL_CALL
RandomAnimationNode::setRepeatCount( const Any
& _repeatcount
)
296 Guard
< Mutex
> aGuard( maMutex
);
297 maRepeatCount
= _repeatcount
;
301 Any SAL_CALL
RandomAnimationNode::getRepeatDuration()
303 Guard
< Mutex
> aGuard( maMutex
);
304 return maRepeatDuration
;
308 void SAL_CALL
RandomAnimationNode::setRepeatDuration( const Any
& _repeatduration
)
310 Guard
< Mutex
> aGuard( maMutex
);
311 maRepeatDuration
= _repeatduration
;
315 sal_Int16 SAL_CALL
RandomAnimationNode::getFill()
317 Guard
< Mutex
> aGuard( maMutex
);
322 void SAL_CALL
RandomAnimationNode::setFill( sal_Int16 _fill
)
324 Guard
< Mutex
> aGuard( maMutex
);
329 sal_Int16 SAL_CALL
RandomAnimationNode::getFillDefault()
331 Guard
< Mutex
> aGuard( maMutex
);
332 return mnFillDefault
;
336 void SAL_CALL
RandomAnimationNode::setFillDefault( sal_Int16 _filldefault
)
338 Guard
< Mutex
> aGuard( maMutex
);
339 mnFillDefault
= _filldefault
;
343 sal_Int16 SAL_CALL
RandomAnimationNode::getRestart()
345 Guard
< Mutex
> aGuard( maMutex
);
350 void SAL_CALL
RandomAnimationNode::setRestart( sal_Int16 _restart
)
352 Guard
< Mutex
> aGuard( maMutex
);
353 mnRestart
= _restart
;
357 sal_Int16 SAL_CALL
RandomAnimationNode::getRestartDefault()
359 Guard
< Mutex
> aGuard( maMutex
);
360 return mnRestartDefault
;
364 void SAL_CALL
RandomAnimationNode::setRestartDefault( sal_Int16 _restartdefault
)
366 Guard
< Mutex
> aGuard( maMutex
);
367 mnRestartDefault
= _restartdefault
;
371 double SAL_CALL
RandomAnimationNode::getAcceleration()
373 Guard
< Mutex
> aGuard( maMutex
);
374 return mfAcceleration
;
378 void SAL_CALL
RandomAnimationNode::setAcceleration( double _acceleration
)
380 Guard
< Mutex
> aGuard( maMutex
);
381 mfAcceleration
= _acceleration
;
385 double SAL_CALL
RandomAnimationNode::getDecelerate()
387 Guard
< Mutex
> aGuard( maMutex
);
392 void SAL_CALL
RandomAnimationNode::setDecelerate( double _decelerate
)
394 Guard
< Mutex
> aGuard( maMutex
);
395 mfDecelerate
= _decelerate
;
399 sal_Bool SAL_CALL
RandomAnimationNode::getAutoReverse()
401 Guard
< Mutex
> aGuard( maMutex
);
402 return mbAutoReverse
;
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
);
418 void SAL_CALL
RandomAnimationNode::setUserData( const Sequence
< NamedValue
>& _userdata
)
420 Guard
< Mutex
> aGuard( maMutex
);
421 maUserData
= _userdata
;
425 Reference
< XInterface
> SAL_CALL
RandomAnimationNode::getParent()
427 Guard
< Mutex
> aGuard( maMutex
);
432 void SAL_CALL
RandomAnimationNode::setParent( const Reference
< XInterface
>& Parent
)
434 Guard
< Mutex
> aGuard( maMutex
);
439 Reference
< XCloneable
> SAL_CALL
RandomAnimationNode::createClone()
441 Reference
< XCloneable
> xNewNode( new RandomAnimationNode( *this ) );
446 Type SAL_CALL
RandomAnimationNode::getElementType()
448 return cppu::UnoType
<XAnimationNode
>::get();
452 sal_Bool SAL_CALL
RandomAnimationNode::hasElements()
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() )
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
);
485 xAnimate
->setTarget( maTarget
);
488 xEnum
= aEnumAccess
->createEnumeration();
492 // no presets? give empty node!
493 Reference
< XParallelTimeContainer
> xTimeContainer
= ParallelTimeContainer::create( comphelper::getProcessComponentContext() );
494 xEnum
= xTimeContainer
->createEnumeration();
501 Reference
< XAnimationNode
> SAL_CALL
RandomAnimationNode::insertBefore( const Reference
< XAnimationNode
>& newChild
, const Reference
< XAnimationNode
>& )
503 return appendChild( newChild
);
507 Reference
< XAnimationNode
> SAL_CALL
RandomAnimationNode::insertAfter( const Reference
< XAnimationNode
>& newChild
, const Reference
< XAnimationNode
>& )
509 return appendChild( newChild
);
513 Reference
< XAnimationNode
> SAL_CALL
RandomAnimationNode::replaceChild( const Reference
< XAnimationNode
>& newChild
, const Reference
< XAnimationNode
>& )
515 return appendChild( newChild
);
519 Reference
< XAnimationNode
> SAL_CALL
RandomAnimationNode::removeChild( const Reference
< XAnimationNode
>& oldChild
)
525 Reference
< XAnimationNode
> SAL_CALL
RandomAnimationNode::appendChild( const Reference
< XAnimationNode
>& newChild
)
527 Reference
< XAnimate
> xAnimate( newChild
, UNO_QUERY
);
530 Any
aTarget( xAnimate
->getTarget() );
531 if( aTarget
.hasValue() )
535 if( !maTarget
.hasValue() && !mxFirstNode
.is() )
536 mxFirstNode
= xAnimate
;
542 OUString
RandomAnimationNode::getImplementationName()
544 return "sd::RandomAnimationNode" ;
548 sal_Bool
RandomAnimationNode::supportsService(const OUString
& ServiceName
)
550 return cppu::supportsService(this, ServiceName
);
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: */