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 <boost/bind.hpp>
24 #include <com/sun/star/beans/XPropertySet.hpp>
25 #include <com/sun/star/beans/NamedValue.hpp>
26 #include <com/sun/star/container/XEnumerationAccess.hpp>
27 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
28 #include <com/sun/star/frame/XModel.hpp>
29 #include <com/sun/star/animations/XAnimateColor.hpp>
30 #include <com/sun/star/animations/XAnimateMotion.hpp>
31 #include <com/sun/star/animations/XAnimateTransform.hpp>
32 #include <com/sun/star/animations/XCommand.hpp>
33 #include <com/sun/star/animations/XIterateContainer.hpp>
34 #include <com/sun/star/animations/XAnimationNodeSupplier.hpp>
35 #include <com/sun/star/animations/XTimeContainer.hpp>
36 #include <com/sun/star/animations/AnimationNodeType.hpp>
37 #include <com/sun/star/animations/Event.hpp>
38 #include <com/sun/star/animations/EventTrigger.hpp>
39 #include <com/sun/star/presentation/EffectNodeType.hpp>
41 #include "oox/helper/helper.hxx"
42 #include "oox/core/xmlfilterbase.hxx"
43 #include "sal/log.hxx"
45 using namespace ::oox::core
;
46 using namespace ::com::sun::star::beans
;
47 using namespace ::com::sun::star::container
;
48 using namespace ::com::sun::star::uno
;
49 using namespace ::com::sun::star::lang
;
50 using namespace ::com::sun::star::animations
;
51 using namespace ::com::sun::star::frame
;
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::ANIMATECOLOR
:
71 sServiceName
= "com.sun.star.animations.AnimateColor";
73 case AnimationNodeType::TRANSITIONFILTER
:
74 sServiceName
= "com.sun.star.animations.TransitionFilter";
76 case AnimationNodeType::ANIMATEMOTION
:
77 sServiceName
= "com.sun.star.animations.AnimateMotion";
79 case AnimationNodeType::ANIMATETRANSFORM
:
80 sServiceName
= "com.sun.star.animations.AnimateTransform";
82 case AnimationNodeType::COMMAND
:
83 sServiceName
= "com.sun.star.animations.Command";
85 case AnimationNodeType::SET
:
86 sServiceName
= "com.sun.star.animations.AnimateSet";
88 case AnimationNodeType::AUDIO
:
89 sServiceName
= "com.sun.star.animations.Audio";
92 SAL_INFO("oox.ppt","OOX: uhandled type " << nNodeType
);
100 TimeNode::TimeNode( sal_Int16 nNodeType
)
101 : mnNodeType( nNodeType
)
102 , mbHasEndSyncValue( false )
107 TimeNode::~TimeNode()
111 // BEGIN CUT&PASTE from sd/source/filter/ppt/pptinanimations.hxx
112 // --------------------------------------------------------------------
113 static void fixMainSequenceTiming( const ::com::sun::star::uno::Reference
< ::com::sun::star::animations::XAnimationNode
>& xNode
)
118 Reference
< XEnumerationAccess
> xEA( xNode
, UNO_QUERY_THROW
);
119 Reference
< XEnumeration
> xE( xEA
->createEnumeration(), UNO_QUERY_THROW
);
120 while( xE
->hasMoreElements() )
123 Reference
< XAnimationNode
> xClickNode( xE
->nextElement(), UNO_QUERY
);
126 aEvent
.Trigger
= EventTrigger::ON_NEXT
;
128 xClickNode
->setBegin( makeAny( aEvent
) );
133 Reference
< XEnumerationAccess
> xEA2( xClickNode
, UNO_QUERY_THROW
);
134 Reference
< XEnumeration
> xE2( xEA2
->createEnumeration(), UNO_QUERY_THROW
);
135 if( xE2
->hasMoreElements() )
138 xE2
->nextElement() >>= xEA2
;
140 xE2
.query( xEA2
->createEnumeration() );
144 if( xE2
.is() && xE2
->hasMoreElements() )
146 Reference
< XAnimationNode
> xEffectNode( xE2
->nextElement(), UNO_QUERY_THROW
);
147 const Sequence
< NamedValue
> aUserData( xEffectNode
->getUserData() );
148 const NamedValue
* p
= aUserData
.getConstArray();
149 sal_Int32 nLength
= aUserData
.getLength();
152 if ( p
->Name
== "node-type" )
154 sal_Int16 nNodeType
= 0;
155 p
->Value
>>= nNodeType
;
156 if( nNodeType
!= ::com::sun::star::presentation::EffectNodeType::ON_CLICK
)
158 // first effect does not start on click, so correct
159 // first click nodes begin to 0s
160 xClickNode
->setBegin( makeAny( (double)0.0 ) );
171 catch( Exception
& e
)
174 SAL_INFO("oox.ppt","fixMainSequenceTiming(), exception caught!" );
178 // --------------------------------------------------------------------
180 static void fixInteractiveSequenceTiming( const ::com::sun::star::uno::Reference
< ::com::sun::star::animations::XAnimationNode
>& xNode
)
184 Any
aBegin( xNode
->getBegin() );
186 xNode
->setBegin( aEmpty
);
188 Reference
< XEnumerationAccess
> xEA( xNode
, UNO_QUERY_THROW
);
189 Reference
< XEnumeration
> xE( xEA
->createEnumeration(), UNO_QUERY_THROW
);
190 while( xE
->hasMoreElements() )
193 Reference
< XAnimationNode
> xClickNode( xE
->nextElement(), UNO_QUERY
);
194 xClickNode
->setBegin( aBegin
);
197 catch( Exception
& e
)
200 SAL_INFO("oox.ppt","fixInteractiveSequenceTiming(), exception caught!" );
206 void TimeNode::addNode( const XmlFilterBase
& rFilter
, const Reference
< XAnimationNode
>& rxNode
, const SlidePersistPtr
& pSlide
)
209 OUString sServiceName
= getServiceName( mnNodeType
);
210 Reference
< XAnimationNode
> xNode
= createAndInsert( rFilter
, sServiceName
, rxNode
);
211 setNode( rFilter
, xNode
, pSlide
);
213 catch( const Exception
& e
)
215 SAL_INFO("oox.ppt","OOX: exception raised in TimeNode::addNode() - " <<
216 OUStringToOString( e
.Message
, RTL_TEXTENCODING_ASCII_US
).getStr() );
220 void TimeNode::setNode( const XmlFilterBase
& rFilter
, const Reference
< XAnimationNode
>& xNode
, const SlidePersistPtr
& pSlide
)
222 SAL_WARN_IF( !xNode
.is(), "oox.ppt", "null node passed" );
225 if( !msId
.isEmpty() )
227 pSlide
->getAnimNodesMap()[ msId
] = xNode
;
232 sal_Int16
nSubType(0);
233 maNodeProperties
[ NP_TARGET
] = mpTarget
->convert( pSlide
, nSubType
);
234 if( mpTarget
->mnType
== XML_spTgt
)
236 maNodeProperties
[ NP_SUBITEM
] <<= nSubType
;
240 if( !maStCondList
.empty() )
242 Any aAny
= AnimationCondition::convertList( pSlide
, maStCondList
);
243 if( aAny
.hasValue() )
245 xNode
->setBegin( aAny
);
249 if( !maEndCondList
.empty() )
251 Any aAny
= AnimationCondition::convertList( pSlide
, maEndCondList
);
252 if( aAny
.hasValue() )
254 xNode
->setEnd( aAny
);
257 #if 0 // FIXME even the binary filter has this disabled.
258 if( !maNextCondList
.empty() )
260 Any aAny
= AnimationCondition::convertList( pSlide
, maNextCondList
);
261 if( aAny
.hasValue() )
263 xNode
->setNext( aAny
);
266 if( !maPrevCondList
.empty() )
268 Any aAny
= AnimationCondition::convertList( pSlide
, maPrevCondList
);
269 if( aAny
.hasValue() )
271 xNode
->setPrev( aAny
);
275 if( mbHasEndSyncValue
)
277 Any aValue
= maEndSyncValue
.convert( pSlide
);
278 xNode
->setEndSync(aValue
);
281 if( !maUserData
.empty() )
283 Sequence
< NamedValue
> aUserDataSeq( static_cast< sal_Int32
>( maUserData
.size() ) );
284 NamedValue
* pValues
= aUserDataSeq
.getArray();
285 for( UserDataMap::const_iterator aIt
= maUserData
.begin(), aEnd
= maUserData
.end(); aIt
!= aEnd
; ++aIt
, ++pValues
)
287 pValues
->Name
= aIt
->first
;
288 pValues
->Value
= aIt
->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
< XIterateContainer
> xIterateContainer( xNode
, UNO_QUERY
);
299 sal_Int16 nInt16
= 0;
300 sal_Bool bBool
= sal_False
;
303 Sequence
< NamedValue
> aSeq
;
305 for( int i
= 0; i
< _NP_SIZE
; i
++)
307 Any
& aValue( maNodeProperties
[ i
] );
308 if( aValue
.hasValue() )
314 xAnimate
->setTo( aValue
);
318 xAnimate
->setFrom( aValue
);
322 xAnimate
->setBy( aValue
);
326 xAnimate
->setTarget( aValue
);
331 if( aValue
>>= nInt16
)
332 xAnimate
->setSubItem( nInt16
);
335 SAL_INFO("oox.ppt","any >>= failed " << __LINE__
);
339 case NP_ATTRIBUTENAME
:
342 if( aValue
>>= sString
)
343 xAnimate
->setAttributeName( sString
);
346 SAL_INFO("oox.ppt","any >>= failed " << __LINE__
);
353 if( aValue
>>= nInt16
)
354 xAnimate
->setCalcMode( nInt16
);
357 SAL_INFO("oox.ppt","any >>= failed " << __LINE__
);
364 Sequence
<double> aKeyTimes
;
365 if( aValue
>>= aKeyTimes
)
366 xAnimate
->setKeyTimes(aKeyTimes
);
369 SAL_INFO("oox.ppt","any >>= failed " << __LINE__
);
376 Sequence
<Any
> aValues
;
377 if( aValue
>>= aValues
)
378 xAnimate
->setValues(aValues
);
381 SAL_INFO("oox.ppt","any >>= failed " << __LINE__
);
388 if( aValue
>>= sString
)
389 xAnimate
->setFormula(sString
);
392 SAL_INFO("oox.ppt","any >>= failed " << __LINE__
);
396 case NP_COLORINTERPOLATION
:
397 if( xAnimateColor
.is() )
399 if( aValue
>>= nInt16
)
400 xAnimateColor
->setColorInterpolation( nInt16
);
403 SAL_INFO("oox.ppt","any >>= failed " << __LINE__
);
408 if( xAnimateColor
.is() )
410 if( aValue
>>= bBool
)
411 xAnimateColor
->setDirection( bBool
);
414 SAL_INFO("oox.ppt","any >>= failed " << __LINE__
);
419 if( xAnimateMotion
.is() )
420 xAnimateMotion
->setPath( aValue
);
422 case NP_TRANSFORMTYPE
:
423 if( xAnimateTransform
.is() )
425 if( aValue
>>= nInt16
)
426 xAnimateTransform
->setTransformType( nInt16
);
429 SAL_INFO("oox.ppt","any >>= failed " << __LINE__
);
434 if( aValue
>>= aSeq
)
435 xNode
->setUserData( aSeq
);
438 SAL_INFO("oox.ppt","any >>= failed " << __LINE__
);
441 case NP_ACCELERATION
:
442 if( aValue
>>= fDouble
)
443 xNode
->setAcceleration( fDouble
);
446 SAL_INFO("oox.ppt","any >>= failed " << __LINE__
);
450 if( aValue
>>= fDouble
)
451 xNode
->setDecelerate( fDouble
);
454 SAL_INFO("oox.ppt","any >>= failed " << __LINE__
);
458 if( aValue
>>= bBool
)
459 xNode
->setAutoReverse( bBool
);
462 SAL_INFO("oox.ppt","any >>= failed " << __LINE__
);
466 xNode
->setDuration( aValue
);
469 if( aValue
>>= nInt16
)
470 xNode
->setFill( nInt16
);
473 SAL_INFO("oox.ppt","any >>= failed " << __LINE__
);
477 xNode
->setRepeatCount( aValue
);
479 case NP_REPEATDURATION
:
480 xNode
->setRepeatDuration( aValue
);
483 if( aValue
>>= nInt16
)
484 xNode
->setRestart( nInt16
);
487 SAL_INFO("oox.ppt","any >>= failed " << __LINE__
);
493 if( aValue
>>= nInt16
)
494 xCommand
->setCommand( nInt16
);
497 SAL_INFO("oox.ppt","any >>= failed " << __LINE__
);
503 xCommand
->setParameter( aValue
);
506 if( xIterateContainer
.is() )
508 if( aValue
>>= nInt16
)
509 xIterateContainer
->setIterateType( nInt16
);
512 SAL_INFO("oox.ppt","any >>= failed " << __LINE__
);
516 case NP_ITERATEINTERVAL
:
517 if( xIterateContainer
.is() )
519 if( aValue
>>= fDouble
)
520 xIterateContainer
->setIterateInterval( fDouble
);
523 SAL_INFO("oox.ppt","any >>= failed " << __LINE__
);
528 SAL_INFO("oox.ppt","ERR-OOX: unknown prop index " << i
);
534 if( mnNodeType
== AnimationNodeType::TRANSITIONFILTER
)
537 Reference
< XTransitionFilter
> xFilter( xNode
, UNO_QUERY
);
538 maTransitionFilter
.setTransitionFilterProperties( xFilter
);
541 std::for_each( maChildren
.begin(), maChildren
.end(),
542 boost::bind(&TimeNode::addNode
, _1
, boost::cref(rFilter
), boost::ref(xNode
),
543 boost::ref(pSlide
) ) );
547 case AnimationNodeType::SEQ
:
550 if( maUserData
[ "node-type" ] >>= nEnum
)
552 if( nEnum
== EffectNodeType::MAIN_SEQUENCE
)
554 fixMainSequenceTiming( xNode
);
556 else if( nEnum
== EffectNodeType::INTERACTIVE_SEQUENCE
)
558 fixInteractiveSequenceTiming( xNode
);
563 case AnimationNodeType::PAR
:
564 // some other cut&paste... from AnimationImporter::importAnimationContainer()
568 catch( const Exception
& e
)
570 SAL_INFO("oox.ppt","OOX: exception raised in TimeNode::setNode() - " << e
.Message
);
575 Reference
< XAnimationNode
> TimeNode::createAndInsert(
576 const XmlFilterBase
& rFilter
,
577 const OUString
& rServiceName
,
578 const Reference
< XAnimationNode
>& rxNode
)
581 Reference
< XAnimationNode
> xNode( Reference
<css::lang::XMultiServiceFactory
>(rFilter
.getComponentContext()->getServiceManager(), UNO_QUERY_THROW
)->createInstance( rServiceName
), UNO_QUERY_THROW
);;
582 Reference
< XTimeContainer
> xParentContainer( rxNode
, UNO_QUERY_THROW
);
584 xParentContainer
->appendChild( xNode
);
587 catch( const Exception
& e
)
589 SAL_INFO("oox.ppt","OOX: exception raised in TimeNode::createAndInsert() trying to create a service " << OUStringToOString( rServiceName
, RTL_TEXTENCODING_ASCII_US
).getStr() << " = " << OUStringToOString( e
.Message
, RTL_TEXTENCODING_ASCII_US
).getStr() );
592 return Reference
< XAnimationNode
>();
596 void TimeNode::setId( sal_Int32 nId
)
598 msId
= OUString::number(nId
);
601 void TimeNode::setTo( const Any
& aTo
)
603 maNodeProperties
[ NP_TO
] = aTo
;
607 void TimeNode::setFrom( const Any
& aFrom
)
609 maNodeProperties
[ NP_FROM
] = aFrom
;
612 void TimeNode::setBy( const Any
& aBy
)
614 maNodeProperties
[ NP_BY
] = aBy
;
620 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */