LibreOffice Module sd (master) 1
randomnode.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#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>
33
38#include <randomnode.hxx>
39#include <mutex>
40
41using ::com::sun::star::uno::Reference;
42using ::com::sun::star::uno::Sequence;
43using ::com::sun::star::uno::Any;
44using ::com::sun::star::uno::UNO_QUERY;
45using ::com::sun::star::uno::XInterface;
46using ::com::sun::star::uno::WeakReference;
47using ::com::sun::star::beans::NamedValue;
48using ::com::sun::star::lang::IllegalArgumentException;
49using ::com::sun::star::container::XEnumeration;
50using ::com::sun::star::container::XEnumerationAccess;
51using ::com::sun::star::util::XCloneable;
52using ::com::sun::star::lang::XServiceInfo;
53using ::com::sun::star::lang::XInitialization;
54using ::com::sun::star::uno::Type;
55using ::com::sun::star::uno::XWeak;
56using ::com::sun::star::presentation::ParagraphTarget;
57using ::com::sun::star::drawing::XShape;
58
59using namespace ::com::sun::star::animations;
60
61namespace sd
62{
63
64typedef ::cppu::WeakImplHelper< XTimeContainer, XEnumerationAccess, XCloneable, XServiceInfo, XInitialization > RandomAnimationNodeBase;
65
66namespace {
67
68class RandomAnimationNode : public RandomAnimationNodeBase
69{
70public:
71 RandomAnimationNode( const RandomAnimationNode& rNode );
72 explicit RandomAnimationNode( sal_Int16 nPresetClass );
73 RandomAnimationNode();
74
75 void init( sal_Int16 nPresetClass );
76
77 // XInitialization
78 void SAL_CALL initialize( const Sequence< Any >& aArguments ) override;
79
80 // XChild
81 Reference< XInterface > SAL_CALL getParent( ) override;
82 void SAL_CALL setParent( const Reference< XInterface >& Parent ) override;
83
84 // XCloneable
85 virtual Reference< XCloneable > SAL_CALL createClone() override;
86
87 // XServiceInfo
88 OUString SAL_CALL getImplementationName() override;
89 Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
90 sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override;
91
92 // XAnimationNode
93 ::sal_Int16 SAL_CALL getType() override;
94 Any SAL_CALL getBegin() override;
95 void SAL_CALL setBegin( const Any& _begin ) override;
96 Any SAL_CALL getDuration() override;
97 void SAL_CALL setDuration( const Any& _duration ) override;
98 Any SAL_CALL getEnd() override;
99 void SAL_CALL setEnd( const Any& _end ) override;
100 Any SAL_CALL getEndSync() override;
101 void SAL_CALL setEndSync( const Any& _endsync ) override;
102 Any SAL_CALL getRepeatCount() override;
103 void SAL_CALL setRepeatCount( const Any& _repeatcount ) override;
104 Any SAL_CALL getRepeatDuration() override;
105 void SAL_CALL setRepeatDuration( const Any& _repeatduration ) override;
106 ::sal_Int16 SAL_CALL getFill() override;
107 void SAL_CALL setFill( ::sal_Int16 _fill ) override;
108 ::sal_Int16 SAL_CALL getFillDefault() override;
109 void SAL_CALL setFillDefault( ::sal_Int16 _filldefault ) override;
110 ::sal_Int16 SAL_CALL getRestart() override;
111 void SAL_CALL setRestart( ::sal_Int16 _restart ) override;
112 ::sal_Int16 SAL_CALL getRestartDefault() override;
113 void SAL_CALL setRestartDefault( ::sal_Int16 _restartdefault ) override;
114 double SAL_CALL getAcceleration() override;
115 void SAL_CALL setAcceleration( double _acceleration ) override;
116 double SAL_CALL getDecelerate() override;
117 void SAL_CALL setDecelerate( double _decelerate ) override;
118 sal_Bool SAL_CALL getAutoReverse() override;
119 void SAL_CALL setAutoReverse( sal_Bool _autoreverse ) override;
120 Sequence< NamedValue > SAL_CALL getUserData() override;
121 void SAL_CALL setUserData( const Sequence< NamedValue >& _userdata ) override;
122
123 // XElementAccess
124 virtual Type SAL_CALL getElementType() override;
125 virtual sal_Bool SAL_CALL hasElements() override;
126
127 // XEnumerationAccess
128 virtual Reference< XEnumeration > SAL_CALL createEnumeration() override;
129
130 // XTimeContainer
131 Reference< XAnimationNode > SAL_CALL insertBefore( const Reference< XAnimationNode >& newChild, const Reference< XAnimationNode >& refChild ) override;
132 Reference< XAnimationNode > SAL_CALL insertAfter( const Reference< XAnimationNode >& newChild, const Reference< XAnimationNode >& refChild ) override;
133 Reference< XAnimationNode > SAL_CALL replaceChild( const Reference< XAnimationNode >& newChild, const Reference< XAnimationNode >& oldChild ) override;
134 Reference< XAnimationNode > SAL_CALL removeChild( const Reference< XAnimationNode >& oldChild ) override;
135 Reference< XAnimationNode > SAL_CALL appendChild( const Reference< XAnimationNode >& newChild ) override;
136
137private:
138 // our first, last and only protection from multi-threads!
139 std::mutex maMutex;
140
141 sal_Int16 mnPresetClass;
142 WeakReference<XInterface> mxParent;
143
147 bool mbAutoReverse;
148 Sequence< NamedValue > maUserData;
149
150 Reference< XAnimate > mxFirstNode;
151};
152
153}
154
155Reference< XInterface > RandomAnimationNode_createInstance( sal_Int16 nPresetClass )
156{
157 Reference< XInterface > xInt( static_cast<XWeak*>( new RandomAnimationNode( nPresetClass ) ) );
158 return xInt;
159}
160
161RandomAnimationNode::RandomAnimationNode( const RandomAnimationNode& rNode )
163 mnPresetClass( rNode.mnPresetClass ),
164 maBegin( rNode.maBegin ),
165 maDuration( rNode.maDuration ),
166 maEnd( rNode.maEnd ),
167 maEndSync( rNode.maEndSync ),
170 maTarget( rNode.maTarget ),
171 mnFill( rNode.mnFill ),
173 mnRestart( rNode.mnRestart ),
176 mfDecelerate( rNode.mfDecelerate ),
178 maUserData( rNode.maUserData )
179{
180}
181
182RandomAnimationNode::RandomAnimationNode( sal_Int16 nPresetClass )
183{
184 init( nPresetClass );
185}
186
187RandomAnimationNode::RandomAnimationNode()
188{
189 init( 1 );
190}
191
192void RandomAnimationNode::init( sal_Int16 nPresetClass )
193{
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;
202}
203
204// XInitialization
205void SAL_CALL RandomAnimationNode::initialize( const Sequence< Any >& aArguments )
206{
207 if( aArguments.getLength() != 1 )
208 throw IllegalArgumentException();
209
210 if( aArguments[0].getValueType() == ::cppu::UnoType<sal_Int16>::get() )
211 {
212 aArguments[0] >>= mnPresetClass;
213 }
214 else if( aArguments[0].getValueType() != ::cppu::UnoType<ParagraphTarget>::get() )
215 {
216 Reference< XShape > xShape;
217 aArguments[0] >>= xShape;
218 if( !xShape.is() )
219 throw IllegalArgumentException();
220 }
221 maTarget = aArguments[0];
222}
223
224// XAnimationNode
225sal_Int16 SAL_CALL RandomAnimationNode::getType()
226{
227 return css::animations::AnimationNodeType::PAR;
228}
229
230// XAnimationNode
231Any SAL_CALL RandomAnimationNode::getBegin()
232{
233 std::unique_lock aGuard( maMutex );
234 return maBegin;
235}
236
237// XAnimationNode
238void SAL_CALL RandomAnimationNode::setBegin( const Any& _begin )
239{
240 std::unique_lock aGuard( maMutex );
241 maBegin = _begin;
242}
243
244// XAnimationNode
245Any SAL_CALL RandomAnimationNode::getDuration()
246{
247 std::unique_lock aGuard( maMutex );
248 return maDuration;
249}
250
251// XAnimationNode
252void SAL_CALL RandomAnimationNode::setDuration( const Any& _duration )
253{
254 std::unique_lock aGuard( maMutex );
255 maDuration = _duration;
256}
257
258// XAnimationNode
259Any SAL_CALL RandomAnimationNode::getEnd()
260{
261 std::unique_lock aGuard( maMutex );
262 return maEnd;
263}
264
265// XAnimationNode
266void SAL_CALL RandomAnimationNode::setEnd( const Any& _end )
267{
268 std::unique_lock aGuard( maMutex );
269 maEnd = _end;
270}
271
272// XAnimationNode
273Any SAL_CALL RandomAnimationNode::getEndSync()
274{
275 std::unique_lock aGuard( maMutex );
276 return maEndSync;
277}
278
279// XAnimationNode
280void SAL_CALL RandomAnimationNode::setEndSync( const Any& _endsync )
281{
282 std::unique_lock aGuard( maMutex );
283 maEndSync = _endsync;
284}
285
286// XAnimationNode
287Any SAL_CALL RandomAnimationNode::getRepeatCount()
288{
289 std::unique_lock aGuard( maMutex );
290 return maRepeatCount;
291}
292
293// XAnimationNode
294void SAL_CALL RandomAnimationNode::setRepeatCount( const Any& _repeatcount )
295{
296 std::unique_lock aGuard( maMutex );
297 maRepeatCount = _repeatcount;
298}
299
300// XAnimationNode
301Any SAL_CALL RandomAnimationNode::getRepeatDuration()
302{
303 std::unique_lock aGuard( maMutex );
304 return maRepeatDuration;
305}
306
307// XAnimationNode
308void SAL_CALL RandomAnimationNode::setRepeatDuration( const Any& _repeatduration )
309{
310 std::unique_lock aGuard( maMutex );
311 maRepeatDuration = _repeatduration;
312}
313
314// XAnimationNode
315sal_Int16 SAL_CALL RandomAnimationNode::getFill()
316{
317 std::unique_lock aGuard( maMutex );
318 return mnFill;
319}
320
321// XAnimationNode
322void SAL_CALL RandomAnimationNode::setFill( sal_Int16 _fill )
323{
324 std::unique_lock aGuard( maMutex );
325 mnFill = _fill;
326}
327
328// XAnimationNode
329sal_Int16 SAL_CALL RandomAnimationNode::getFillDefault()
330{
331 std::unique_lock aGuard( maMutex );
332 return mnFillDefault;
333}
334
335// XAnimationNode
336void SAL_CALL RandomAnimationNode::setFillDefault( sal_Int16 _filldefault )
337{
338 std::unique_lock aGuard( maMutex );
339 mnFillDefault = _filldefault;
340}
341
342// XAnimationNode
343sal_Int16 SAL_CALL RandomAnimationNode::getRestart()
344{
345 std::unique_lock aGuard( maMutex );
346 return mnRestart;
347}
348
349// XAnimationNode
350void SAL_CALL RandomAnimationNode::setRestart( sal_Int16 _restart )
351{
352 std::unique_lock aGuard( maMutex );
353 mnRestart = _restart;
354}
355
356// XAnimationNode
357sal_Int16 SAL_CALL RandomAnimationNode::getRestartDefault()
358{
359 std::unique_lock aGuard( maMutex );
360 return mnRestartDefault;
361}
362
363// XAnimationNode
364void SAL_CALL RandomAnimationNode::setRestartDefault( sal_Int16 _restartdefault )
365{
366 std::unique_lock aGuard( maMutex );
367 mnRestartDefault = _restartdefault;
368}
369
370// XAnimationNode
371double SAL_CALL RandomAnimationNode::getAcceleration()
372{
373 std::unique_lock aGuard( maMutex );
374 return mfAcceleration;
375}
376
377// XAnimationNode
378void SAL_CALL RandomAnimationNode::setAcceleration( double _acceleration )
379{
380 std::unique_lock aGuard( maMutex );
381 mfAcceleration = _acceleration;
382}
383
384// XAnimationNode
385double SAL_CALL RandomAnimationNode::getDecelerate()
386{
387 std::unique_lock aGuard( maMutex );
388 return mfDecelerate;
389}
390
391// XAnimationNode
392void SAL_CALL RandomAnimationNode::setDecelerate( double _decelerate )
393{
394 std::unique_lock aGuard( maMutex );
395 mfDecelerate = _decelerate;
396}
397
398// XAnimationNode
399sal_Bool SAL_CALL RandomAnimationNode::getAutoReverse()
400{
401 std::unique_lock aGuard( maMutex );
402 return mbAutoReverse;
403}
404
405// XAnimationNode
406void SAL_CALL RandomAnimationNode::setAutoReverse( sal_Bool _autoreverse )
407{
408 std::unique_lock aGuard( maMutex );
409 mbAutoReverse = _autoreverse;
410}
411
412Sequence< NamedValue > SAL_CALL RandomAnimationNode::getUserData()
413{
414 std::unique_lock aGuard( maMutex );
415 return maUserData;
416}
417
418void SAL_CALL RandomAnimationNode::setUserData( const Sequence< NamedValue >& _userdata )
419{
420 std::unique_lock aGuard( maMutex );
421 maUserData = _userdata;
422}
423
424// XChild
425Reference< XInterface > SAL_CALL RandomAnimationNode::getParent()
426{
427 std::unique_lock aGuard( maMutex );
428 return mxParent.get();
429}
430
431// XChild
432void SAL_CALL RandomAnimationNode::setParent( const Reference< XInterface >& Parent )
433{
434 std::unique_lock aGuard( maMutex );
436}
437
438// XCloneable
439Reference< XCloneable > SAL_CALL RandomAnimationNode::createClone()
440{
441 Reference< XCloneable > xNewNode( new RandomAnimationNode( *this ) );
442 return xNewNode;
443}
444
445// XElementAccess
446Type SAL_CALL RandomAnimationNode::getElementType()
447{
449}
450
451// XElementAccess
452sal_Bool SAL_CALL RandomAnimationNode::hasElements()
453{
454 return true;
455}
456
457// XEnumerationAccess
458Reference< XEnumeration > SAL_CALL RandomAnimationNode::createEnumeration()
459{
460 std::unique_lock aGuard( maMutex );
461
462 if( !maTarget.hasValue() && mxFirstNode.is() )
463 {
464 Any aTarget( mxFirstNode->getTarget() );
465 if( aTarget.hasValue() )
466 {
467 maTarget = aTarget;
468 mxFirstNode.clear();
469 }
470 }
471
472 Reference< XEnumeration > xEnum;
473
474 Reference< XEnumerationAccess > aEnumAccess( CustomAnimationPresets::getCustomAnimationPresets().getRandomPreset( mnPresetClass ), UNO_QUERY );
475
476 if( aEnumAccess.is() )
477 {
478 Reference< XEnumeration > xEnumeration = aEnumAccess->createEnumeration();
479 if( xEnumeration.is() )
480 {
481 while( xEnumeration->hasMoreElements() )
482 {
483 Reference< XAnimate > xAnimate( xEnumeration->nextElement(), UNO_QUERY );
484 if( xAnimate.is() )
485 xAnimate->setTarget( maTarget );
486 }
487 }
488 xEnum = aEnumAccess->createEnumeration();
489 }
490 else
491 {
492 // no presets? give empty node!
493 Reference< XParallelTimeContainer > xTimeContainer = ParallelTimeContainer::create( comphelper::getProcessComponentContext() );
494 xEnum = xTimeContainer->createEnumeration();
495 }
496
497 return xEnum;
498}
499
500// XTimeContainer
501Reference< XAnimationNode > SAL_CALL RandomAnimationNode::insertBefore( const Reference< XAnimationNode >& newChild, const Reference< XAnimationNode >& )
502{
503 return appendChild( newChild );
504}
505
506// XTimeContainer
507Reference< XAnimationNode > SAL_CALL RandomAnimationNode::insertAfter( const Reference< XAnimationNode >& newChild, const Reference< XAnimationNode >& )
508{
509 return appendChild( newChild );
510}
511
512// XTimeContainer
513Reference< XAnimationNode > SAL_CALL RandomAnimationNode::replaceChild( const Reference< XAnimationNode >& newChild, const Reference< XAnimationNode >& )
514{
515 return appendChild( newChild );
516}
517
518// XTimeContainer
519Reference< XAnimationNode > SAL_CALL RandomAnimationNode::removeChild( const Reference< XAnimationNode >& oldChild )
520{
521 return oldChild;
522}
523
524// XTimeContainer
525Reference< XAnimationNode > SAL_CALL RandomAnimationNode::appendChild( const Reference< XAnimationNode >& newChild )
526{
527 Reference< XAnimate > xAnimate( newChild, UNO_QUERY );
528 if( xAnimate.is() )
529 {
530 Any aTarget( xAnimate->getTarget() );
531 if( aTarget.hasValue() )
532 maTarget = aTarget;
533 }
534
535 if( !maTarget.hasValue() && !mxFirstNode.is() )
536 mxFirstNode = xAnimate;
537
538 return newChild;
539}
540
541// XServiceInfo
542OUString RandomAnimationNode::getImplementationName()
543{
544 return "sd::RandomAnimationNode" ;
545}
546
547// XServiceInfo
548sal_Bool RandomAnimationNode::supportsService(const OUString& ServiceName)
549{
550 return cppu::supportsService(this, ServiceName);
551}
552
553// XServiceInfo
554Sequence< OUString > RandomAnimationNode::getSupportedServiceNames()
555{
556 return { "com.sun.star.animations.ParallelTimeContainer", "com.sun.star.comp.sd.RandomAnimationNode" };
557}
558
559}
560
561extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
562RandomAnimationNode_get_implementation(css::uno::XComponentContext*,
563 css::uno::Sequence<css::uno::Any> const &)
564{
565 return cppu::acquire(new sd::RandomAnimationNode());
566}
567
568
569/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::mutex maMutex
const Point maEnd
sal_Int16 mnFill
Any maRepeatCount
sal_Int16 mnRestart
double mfAcceleration
sal_Int16 mnFillDefault
Any maEndSync
unotools::WeakReference< AnimationNode > mxParent
bool mbAutoReverse
Sequence< NamedValue > maUserData
sal_Int16 mnRestartDefault
Any maDuration
Any maRepeatDuration
Any maTarget
Any maBegin
double mfDecelerate
FILE * init(int, char **)
css::uno::Type const & get()
Sequence< PropertyValue > aArguments
Reference< XComponentContext > getProcessComponentContext()
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
Type
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
OUString getUserData()
::cppu::WeakImplHelper< XTimeContainer, XEnumerationAccess, XCloneable, XServiceInfo, XInitialization > RandomAnimationNodeBase
Definition: randomnode.cxx:64
Reference< XInterface > RandomAnimationNode_createInstance(sal_Int16 nPresetClass)
Definition: randomnode.cxx:155
bool getType(BSTR name, Type &type)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * RandomAnimationNode_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
Definition: randomnode.cxx:562
unsigned char sal_Bool