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 <oox/ppt/timenode.hxx>
22 #include <com/sun/star/beans/XPropertySet.hpp>
23 #include <com/sun/star/beans/NamedValue.hpp>
24 #include <com/sun/star/container/XEnumerationAccess.hpp>
25 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
26 #include <com/sun/star/animations/XAnimateColor.hpp>
27 #include <com/sun/star/animations/XAnimateMotion.hpp>
28 #include <com/sun/star/animations/XAnimateTransform.hpp>
29 #include <com/sun/star/animations/XCommand.hpp>
30 #include <com/sun/star/animations/XAudio.hpp>
31 #include <com/sun/star/animations/XIterateContainer.hpp>
32 #include <com/sun/star/animations/XTimeContainer.hpp>
33 #include <com/sun/star/animations/XTransitionFilter.hpp>
34 #include <com/sun/star/animations/AnimationNodeType.hpp>
35 #include <com/sun/star/animations/Event.hpp>
36 #include <com/sun/star/animations/EventTrigger.hpp>
37 #include <com/sun/star/presentation/EffectNodeType.hpp>
38 #include <com/sun/star/uno/XComponentContext.hpp>
40 #include <oox/helper/helper.hxx>
41 #include <oox/core/xmlfilterbase.hxx>
42 #include <oox/ppt/pptfilterhelpers.hxx>
43 #include <oox/token/tokens.hxx>
44 #include <sal/log.hxx>
46 using namespace ::oox::core
;
47 using namespace ::com::sun::star::beans
;
48 using namespace ::com::sun::star::container
;
49 using namespace ::com::sun::star::uno
;
50 using namespace ::com::sun::star::lang
;
51 using namespace ::com::sun::star::animations
;
52 using namespace ::com::sun::star::presentation
;
54 namespace oox
{ namespace ppt
{
56 OUString
TimeNode::getServiceName( sal_Int16 nNodeType
)
58 OUString sServiceName
;
61 case AnimationNodeType::PAR
:
62 sServiceName
= "com.sun.star.animations.ParallelTimeContainer";
64 case AnimationNodeType::SEQ
:
65 sServiceName
= "com.sun.star.animations.SequenceTimeContainer";
67 case AnimationNodeType::ANIMATE
:
68 sServiceName
= "com.sun.star.animations.Animate";
70 case AnimationNodeType::ITERATE
:
71 sServiceName
= "com.sun.star.animations.IterateContainer";
73 case AnimationNodeType::ANIMATECOLOR
:
74 sServiceName
= "com.sun.star.animations.AnimateColor";
76 case AnimationNodeType::TRANSITIONFILTER
:
77 sServiceName
= "com.sun.star.animations.TransitionFilter";
79 case AnimationNodeType::ANIMATEMOTION
:
80 sServiceName
= "com.sun.star.animations.AnimateMotion";
82 case AnimationNodeType::ANIMATETRANSFORM
:
83 sServiceName
= "com.sun.star.animations.AnimateTransform";
85 case AnimationNodeType::COMMAND
:
86 sServiceName
= "com.sun.star.animations.Command";
88 case AnimationNodeType::SET
:
89 sServiceName
= "com.sun.star.animations.AnimateSet";
91 case AnimationNodeType::AUDIO
:
92 sServiceName
= "com.sun.star.animations.Audio";
95 SAL_INFO("oox.ppt","OOX: uhandled type " << nNodeType
);
101 TimeNode::TimeNode( sal_Int16 nNodeType
)
102 : mnNodeType( nNodeType
)
103 , mbHasEndSyncValue( false )
107 TimeNode::~TimeNode()
111 void fixMainSequenceTiming( const css::uno::Reference
< css::animations::XAnimationNode
>& xNode
)
116 Reference
< XEnumerationAccess
> xEA( xNode
, UNO_QUERY_THROW
);
117 Reference
< XEnumeration
> xE( xEA
->createEnumeration(), UNO_SET_THROW
);
118 while( xE
->hasMoreElements() )
121 Reference
< XAnimationNode
> xClickNode( xE
->nextElement(), UNO_QUERY
);
124 aEvent
.Trigger
= EventTrigger::ON_NEXT
;
126 xClickNode
->setBegin( makeAny( aEvent
) );
131 Reference
< XEnumerationAccess
> xEA2( xClickNode
, UNO_QUERY_THROW
);
132 Reference
< XEnumeration
> xE2( xEA2
->createEnumeration(), UNO_SET_THROW
);
133 if( xE2
->hasMoreElements() )
136 xE2
->nextElement() >>= xEA2
;
138 xE2
.set(xEA2
->createEnumeration(), css::uno::UNO_QUERY
);
142 if( xE2
.is() && xE2
->hasMoreElements() )
144 Reference
< XAnimationNode
> xEffectNode( xE2
->nextElement(), UNO_QUERY_THROW
);
145 const Sequence
< NamedValue
> aUserData( xEffectNode
->getUserData() );
146 const NamedValue
* p
= aUserData
.getConstArray();
147 sal_Int32 nLength
= aUserData
.getLength();
150 if ( p
->Name
== "node-type" )
152 sal_Int16 nNodeType
= 0;
153 p
->Value
>>= nNodeType
;
154 if( nNodeType
!= css::presentation::EffectNodeType::ON_CLICK
)
156 // first effect does not start on click, so correct
157 // first click nodes begin to 0s
158 xClickNode
->setBegin( makeAny( 0.0 ) );
171 SAL_INFO("oox.ppt","fixMainSequenceTiming(), exception caught!" );
175 void fixInteractiveSequenceTiming( const css::uno::Reference
< css::animations::XAnimationNode
>& xNode
)
179 Any
aBegin( xNode
->getBegin() );
181 xNode
->setBegin( aEmpty
);
183 Reference
< XEnumerationAccess
> xEA( xNode
, UNO_QUERY_THROW
);
184 Reference
< XEnumeration
> xE( xEA
->createEnumeration(), UNO_SET_THROW
);
185 while( xE
->hasMoreElements() )
188 Reference
< XAnimationNode
> xClickNode( xE
->nextElement(), UNO_QUERY
);
189 xClickNode
->setBegin( aBegin
);
194 SAL_INFO("oox.ppt","fixInteractiveSequenceTiming(), exception caught!" );
198 void TimeNode::addNode( const XmlFilterBase
& rFilter
, const Reference
< XAnimationNode
>& rxNode
, const SlidePersistPtr
& pSlide
)
201 sal_Int16 nNodeType
= mnNodeType
;
203 if (mnNodeType
== AnimationNodeType::PAR
&& maNodeProperties
[NP_ITERATETYPE
].hasValue())
204 nNodeType
= AnimationNodeType::ITERATE
;
206 OUString sServiceName
= getServiceName(nNodeType
);
208 Reference
< XAnimationNode
> xNode
= createAndInsert( rFilter
, sServiceName
, rxNode
);
211 setNode(rFilter
, xNode
, pSlide
, rxNode
);
213 catch( const Exception
& e
)
215 SAL_INFO("oox.ppt","OOX: exception raised in TimeNode::addNode() - " << e
);
219 void TimeNode::setNode(const XmlFilterBase
& rFilter
, const Reference
< XAnimationNode
>& xNode
, const SlidePersistPtr
& pSlide
, const Reference
<XAnimationNode
>& xParent
)
221 SAL_WARN_IF( !xNode
.is(), "oox.ppt", "null node passed" );
224 if( !msId
.isEmpty() )
226 pSlide
->getAnimNodesMap()[ msId
] = xNode
;
231 sal_Int16
nSubType(0);
232 maNodeProperties
[ NP_TARGET
] = mpTarget
->convert( pSlide
, nSubType
);
233 if( mpTarget
->mnType
== XML_spTgt
)
235 maNodeProperties
[ NP_SUBITEM
] <<= nSubType
;
239 if( !maStCondList
.empty() )
241 Any aAny
= AnimationCondition::convertList( pSlide
, maStCondList
);
242 if( aAny
.hasValue() )
244 xNode
->setBegin( aAny
);
248 if( !maEndCondList
.empty() )
250 Any aAny
= AnimationCondition::convertList( pSlide
, maEndCondList
);
251 if( aAny
.hasValue() )
253 xNode
->setEnd( aAny
);
256 #if 0 // FIXME even the binary filter has this disabled.
257 if( !maNextCondList
.empty() )
259 Any aAny
= AnimationCondition::convertList( pSlide
, maNextCondList
);
260 if( aAny
.hasValue() )
262 xNode
->setNext( aAny
);
265 if( !maPrevCondList
.empty() )
267 Any aAny
= AnimationCondition::convertList( pSlide
, maPrevCondList
);
268 if( aAny
.hasValue() )
270 xNode
->setPrev( aAny
);
274 if( mbHasEndSyncValue
)
276 Any aValue
= maEndSyncValue
.convert( pSlide
);
277 xNode
->setEndSync(aValue
);
280 if( !maUserData
.empty() )
282 Sequence
< NamedValue
> aUserDataSeq( static_cast< sal_Int32
>( maUserData
.size() ) );
283 NamedValue
* pValues
= aUserDataSeq
.getArray();
284 for (auto const& elem
: maUserData
)
286 pValues
->Name
= elem
.first
;
287 pValues
->Value
= elem
.second
;
290 maNodeProperties
[ NP_USERDATA
] <<= aUserDataSeq
;
293 Reference
< XAnimate
> xAnimate( xNode
, UNO_QUERY
);
294 Reference
< XAnimateColor
> xAnimateColor( xNode
, UNO_QUERY
);
295 Reference
< XAnimateMotion
> xAnimateMotion( xNode
, UNO_QUERY
);
296 Reference
< XAnimateTransform
> xAnimateTransform( xNode
, UNO_QUERY
);
297 Reference
< XCommand
> xCommand( xNode
, UNO_QUERY
);
298 Reference
< XAudio
> xAudio( xNode
, UNO_QUERY
);
299 Reference
< XIterateContainer
> xIterateContainer( xNode
, UNO_QUERY
);
300 sal_Int16 nInt16
= 0;
304 Sequence
< NamedValue
> aSeq
;
306 for( int i
= 0; i
< NP_SIZE_
; i
++)
308 Any
& aValue( maNodeProperties
[ i
] );
309 if( aValue
.hasValue() )
315 xAnimate
->setTo( aValue
);
319 xAnimate
->setFrom( aValue
);
323 xAnimate
->setBy( aValue
);
327 if (xParent
.is() && xParent
->getType() == AnimationNodeType::ITERATE
)
329 Reference
<XIterateContainer
> xParentContainer(xParent
, UNO_QUERY
);
330 if (xParentContainer
.is())
331 xParentContainer
->setTarget(aValue
);
336 xAnimate
->setTarget(aValue
);
338 xCommand
->setTarget(aValue
);
340 xAudio
->setSource(aValue
);
346 if( aValue
>>= nInt16
)
347 xAnimate
->setSubItem( nInt16
);
350 SAL_INFO("oox.ppt","any >>= failed " << __LINE__
);
354 case NP_ATTRIBUTENAME
:
357 if( aValue
>>= sString
)
358 xAnimate
->setAttributeName( sString
);
361 SAL_INFO("oox.ppt","any >>= failed " << __LINE__
);
368 if( aValue
>>= nInt16
)
369 xAnimate
->setCalcMode( nInt16
);
372 SAL_INFO("oox.ppt","any >>= failed " << __LINE__
);
379 Sequence
<double> aKeyTimes
;
380 if( aValue
>>= aKeyTimes
)
381 xAnimate
->setKeyTimes(aKeyTimes
);
384 SAL_INFO("oox.ppt","any >>= failed " << __LINE__
);
391 Sequence
<Any
> aValues
;
392 if( aValue
>>= aValues
)
393 xAnimate
->setValues(aValues
);
396 SAL_INFO("oox.ppt","any >>= failed " << __LINE__
);
403 if( aValue
>>= sString
)
404 xAnimate
->setFormula(sString
);
407 SAL_INFO("oox.ppt","any >>= failed " << __LINE__
);
411 case NP_COLORINTERPOLATION
:
412 if( xAnimateColor
.is() )
414 if( aValue
>>= nInt16
)
415 xAnimateColor
->setColorInterpolation( nInt16
);
418 SAL_INFO("oox.ppt","any >>= failed " << __LINE__
);
423 if( xAnimateColor
.is() )
425 if( aValue
>>= bBool
)
426 xAnimateColor
->setDirection( bBool
);
429 SAL_INFO("oox.ppt","any >>= failed " << __LINE__
);
434 if( xAnimateMotion
.is() )
435 xAnimateMotion
->setPath( aValue
);
437 case NP_TRANSFORMTYPE
:
438 if( xAnimateTransform
.is() )
440 if( aValue
>>= nInt16
)
441 xAnimateTransform
->setTransformType( nInt16
);
444 SAL_INFO("oox.ppt","any >>= failed " << __LINE__
);
449 if( aValue
>>= aSeq
)
450 xNode
->setUserData( aSeq
);
453 SAL_INFO("oox.ppt","any >>= failed " << __LINE__
);
456 case NP_ACCELERATION
:
457 if( aValue
>>= fDouble
)
458 xNode
->setAcceleration( fDouble
);
461 SAL_INFO("oox.ppt","any >>= failed " << __LINE__
);
465 if( aValue
>>= fDouble
)
466 xNode
->setDecelerate( fDouble
);
469 SAL_INFO("oox.ppt","any >>= failed " << __LINE__
);
473 if( aValue
>>= bBool
)
474 xNode
->setAutoReverse( bBool
);
477 SAL_INFO("oox.ppt","any >>= failed " << __LINE__
);
481 xNode
->setDuration( aValue
);
484 if( aValue
>>= nInt16
)
485 xNode
->setFill( nInt16
);
488 SAL_INFO("oox.ppt","any >>= failed " << __LINE__
);
492 xNode
->setRepeatCount( aValue
);
494 case NP_REPEATDURATION
:
495 xNode
->setRepeatDuration( aValue
);
498 if( aValue
>>= nInt16
)
499 xNode
->setRestart( nInt16
);
502 SAL_INFO("oox.ppt","any >>= failed " << __LINE__
);
508 if( aValue
>>= nInt16
)
509 xCommand
->setCommand( nInt16
);
512 SAL_INFO("oox.ppt","any >>= failed " << __LINE__
);
518 xCommand
->setParameter( aValue
);
521 if( xIterateContainer
.is() )
523 if( aValue
>>= nInt16
)
524 xIterateContainer
->setIterateType( nInt16
);
527 SAL_INFO("oox.ppt","any >>= failed " << __LINE__
);
531 case NP_ITERATEINTERVAL
:
532 if( xIterateContainer
.is() )
534 if( aValue
>>= fDouble
)
535 xIterateContainer
->setIterateInterval( fDouble
);
538 SAL_INFO("oox.ppt","any >>= failed " << __LINE__
);
543 SAL_INFO("oox.ppt","ERR-OOX: unknown prop index " << i
);
549 if( mnNodeType
== AnimationNodeType::TRANSITIONFILTER
)
552 Reference
< XTransitionFilter
> xFilter( xNode
, UNO_QUERY
);
553 maTransitionFilter
.setTransitionFilterProperties( xFilter
);
557 maChildren
.begin(), maChildren
.end(),
558 [&rFilter
, &xNode
, &pSlide
] (TimeNodePtr
const & child
) {
559 child
->addNode(rFilter
, xNode
, pSlide
);
564 case AnimationNodeType::SEQ
:
567 if( maUserData
[ "node-type" ] >>= nEnum
)
569 if( nEnum
== EffectNodeType::MAIN_SEQUENCE
)
571 fixMainSequenceTiming( xNode
);
573 else if( nEnum
== EffectNodeType::INTERACTIVE_SEQUENCE
)
575 fixInteractiveSequenceTiming( xNode
);
580 case AnimationNodeType::PAR
:
581 // some other cut&paste... from AnimationImporter::importAnimationContainer()
585 catch( const Exception
& e
)
587 SAL_INFO("oox.ppt","OOX: exception raised in TimeNode::setNode() - " << e
);
591 Reference
< XAnimationNode
> TimeNode::createAndInsert(
592 const XmlFilterBase
& rFilter
,
593 const OUString
& rServiceName
,
594 const Reference
< XAnimationNode
>& rxNode
)
597 Reference
< XAnimationNode
> xNode( Reference
<css::lang::XMultiServiceFactory
>(rFilter
.getComponentContext()->getServiceManager(), UNO_QUERY_THROW
)->createInstance( rServiceName
), UNO_QUERY_THROW
);
598 Reference
< XTimeContainer
> xParentContainer( rxNode
, UNO_QUERY_THROW
);
600 xParentContainer
->appendChild( xNode
);
603 catch( const Exception
& e
)
605 SAL_INFO("oox.ppt", "OOX: exception raised in TimeNode::createAndInsert() trying to create a service " << rServiceName
<< " = " << e
);
608 return Reference
< XAnimationNode
>();
611 void TimeNode::setId( sal_Int32 nId
)
613 msId
= OUString::number(nId
);
616 void TimeNode::setTo( const Any
& aTo
)
618 maNodeProperties
[ NP_TO
] = aTo
;
621 void TimeNode::setFrom( const Any
& aFrom
)
623 maNodeProperties
[ NP_FROM
] = aFrom
;
626 void TimeNode::setBy( const Any
& aBy
)
628 maNodeProperties
[ NP_BY
] = aBy
;
633 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */