bump product version to 6.3.0.0.beta1
[LibreOffice.git] / oox / source / ppt / timenode.cxx
blobb3391ddd6005029ad3301a50f9e59e157507e27a
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 <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;
59 switch( nNodeType )
61 case AnimationNodeType::PAR:
62 sServiceName = "com.sun.star.animations.ParallelTimeContainer";
63 break;
64 case AnimationNodeType::SEQ:
65 sServiceName = "com.sun.star.animations.SequenceTimeContainer";
66 break;
67 case AnimationNodeType::ANIMATE:
68 sServiceName = "com.sun.star.animations.Animate";
69 break;
70 case AnimationNodeType::ITERATE:
71 sServiceName = "com.sun.star.animations.IterateContainer";
72 break;
73 case AnimationNodeType::ANIMATECOLOR:
74 sServiceName = "com.sun.star.animations.AnimateColor";
75 break;
76 case AnimationNodeType::TRANSITIONFILTER:
77 sServiceName = "com.sun.star.animations.TransitionFilter";
78 break;
79 case AnimationNodeType::ANIMATEMOTION:
80 sServiceName = "com.sun.star.animations.AnimateMotion";
81 break;
82 case AnimationNodeType::ANIMATETRANSFORM:
83 sServiceName = "com.sun.star.animations.AnimateTransform";
84 break;
85 case AnimationNodeType::COMMAND:
86 sServiceName = "com.sun.star.animations.Command";
87 break;
88 case AnimationNodeType::SET:
89 sServiceName = "com.sun.star.animations.AnimateSet";
90 break;
91 case AnimationNodeType::AUDIO:
92 sServiceName = "com.sun.star.animations.Audio";
93 break;
94 default:
95 SAL_INFO("oox.ppt","OOX: uhandled type " << nNodeType );
96 break;
98 return sServiceName;
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 )
115 bool bFirst = true;
116 Reference< XEnumerationAccess > xEA( xNode, UNO_QUERY_THROW );
117 Reference< XEnumeration > xE( xEA->createEnumeration(), UNO_SET_THROW );
118 while( xE->hasMoreElements() )
120 // click node
121 Reference< XAnimationNode > xClickNode( xE->nextElement(), UNO_QUERY );
123 Event aEvent;
124 aEvent.Trigger = EventTrigger::ON_NEXT;
125 aEvent.Repeat = 0;
126 xClickNode->setBegin( makeAny( aEvent ) );
128 if( bFirst )
130 bFirst = false;
131 Reference< XEnumerationAccess > xEA2( xClickNode, UNO_QUERY_THROW );
132 Reference< XEnumeration > xE2( xEA2->createEnumeration(), UNO_SET_THROW );
133 if( xE2->hasMoreElements() )
135 // with node
136 xE2->nextElement() >>= xEA2;
137 if( xEA2.is() )
138 xE2.set(xEA2->createEnumeration(), css::uno::UNO_QUERY);
139 else
140 xE2.clear();
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();
148 while( nLength-- )
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 ) );
159 break;
162 p++;
169 catch( Exception& )
171 SAL_INFO("oox.ppt","fixMainSequenceTiming(), exception caught!" );
175 void fixInteractiveSequenceTiming( const css::uno::Reference< css::animations::XAnimationNode >& xNode )
179 Any aBegin( xNode->getBegin() );
180 Any aEmpty;
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() )
187 // click node
188 Reference< XAnimationNode > xClickNode( xE->nextElement(), UNO_QUERY );
189 xClickNode->setBegin( aBegin );
192 catch( Exception& )
194 SAL_INFO("oox.ppt","fixInteractiveSequenceTiming(), exception caught!" );
198 void TimeNode::addNode( const XmlFilterBase& rFilter, const Reference< XAnimationNode >& rxNode, const SlidePersistPtr & pSlide )
200 try {
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 );
209 if (!xNode)
210 return;
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" );
223 try {
224 if( !msId.isEmpty() )
226 pSlide->getAnimNodesMap()[ msId ] = xNode;
229 if( mpTarget )
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 );
273 #endif
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;
288 ++pValues;
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;
301 bool bBool = false;
302 double fDouble = 0;
303 OUString sString;
304 Sequence< NamedValue > aSeq;
306 for( int i = 0; i < NP_SIZE_; i++)
308 Any & aValue( maNodeProperties[ i ] );
309 if( aValue.hasValue() )
311 switch( i )
313 case NP_TO:
314 if( xAnimate.is() )
315 xAnimate->setTo( aValue );
316 break;
317 case NP_FROM:
318 if( xAnimate.is() )
319 xAnimate->setFrom( aValue );
320 break;
321 case NP_BY:
322 if( xAnimate.is() )
323 xAnimate->setBy( aValue );
324 break;
325 case NP_TARGET:
327 if (xParent.is() && xParent->getType() == AnimationNodeType::ITERATE)
329 Reference<XIterateContainer> xParentContainer(xParent, UNO_QUERY);
330 if (xParentContainer.is())
331 xParentContainer->setTarget(aValue);
333 else
335 if (xAnimate.is())
336 xAnimate->setTarget(aValue);
337 if (xCommand.is())
338 xCommand->setTarget(aValue);
339 if (xAudio.is())
340 xAudio->setSource(aValue);
342 break;
343 case NP_SUBITEM:
344 if( xAnimate.is() )
346 if( aValue >>= nInt16 )
347 xAnimate->setSubItem( nInt16 );
348 else
350 SAL_INFO("oox.ppt","any >>= failed " << __LINE__ );
353 break;
354 case NP_ATTRIBUTENAME:
355 if( xAnimate.is() )
357 if( aValue >>= sString )
358 xAnimate->setAttributeName( sString );
359 else
361 SAL_INFO("oox.ppt","any >>= failed " << __LINE__ );
364 break;
365 case NP_CALCMODE:
366 if( xAnimate.is() )
368 if( aValue >>= nInt16 )
369 xAnimate->setCalcMode( nInt16 );
370 else
372 SAL_INFO("oox.ppt","any >>= failed " << __LINE__ );
375 break;
376 case NP_KEYTIMES:
377 if( xAnimate.is() )
379 Sequence<double> aKeyTimes;
380 if( aValue >>= aKeyTimes )
381 xAnimate->setKeyTimes(aKeyTimes);
382 else
384 SAL_INFO("oox.ppt","any >>= failed " << __LINE__ );
387 break;
388 case NP_VALUES:
389 if( xAnimate.is() )
391 Sequence<Any> aValues;
392 if( aValue >>= aValues )
393 xAnimate->setValues(aValues);
394 else
396 SAL_INFO("oox.ppt","any >>= failed " << __LINE__ );
399 break;
400 case NP_FORMULA:
401 if( xAnimate.is() )
403 if( aValue >>= sString )
404 xAnimate->setFormula(sString);
405 else
407 SAL_INFO("oox.ppt","any >>= failed " << __LINE__ );
410 break;
411 case NP_COLORINTERPOLATION:
412 if( xAnimateColor.is() )
414 if( aValue >>= nInt16 )
415 xAnimateColor->setColorInterpolation( nInt16 );
416 else
418 SAL_INFO("oox.ppt","any >>= failed " << __LINE__ );
421 break;
422 case NP_DIRECTION:
423 if( xAnimateColor.is() )
425 if( aValue >>= bBool )
426 xAnimateColor->setDirection( bBool );
427 else
429 SAL_INFO("oox.ppt","any >>= failed " << __LINE__ );
432 break;
433 case NP_PATH:
434 if( xAnimateMotion.is() )
435 xAnimateMotion->setPath( aValue );
436 break;
437 case NP_TRANSFORMTYPE:
438 if( xAnimateTransform.is() )
440 if( aValue >>= nInt16 )
441 xAnimateTransform->setTransformType( nInt16 );
442 else
444 SAL_INFO("oox.ppt","any >>= failed " << __LINE__ );
447 break;
448 case NP_USERDATA:
449 if( aValue >>= aSeq )
450 xNode->setUserData( aSeq );
451 else
453 SAL_INFO("oox.ppt","any >>= failed " << __LINE__ );
455 break;
456 case NP_ACCELERATION:
457 if( aValue >>= fDouble )
458 xNode->setAcceleration( fDouble );
459 else
461 SAL_INFO("oox.ppt","any >>= failed " << __LINE__ );
463 break;
464 case NP_DECELERATE:
465 if( aValue >>= fDouble )
466 xNode->setDecelerate( fDouble );
467 else
469 SAL_INFO("oox.ppt","any >>= failed " << __LINE__ );
471 break;
472 case NP_AUTOREVERSE:
473 if( aValue >>= bBool )
474 xNode->setAutoReverse( bBool );
475 else
477 SAL_INFO("oox.ppt","any >>= failed " << __LINE__ );
479 break;
480 case NP_DURATION:
481 xNode->setDuration( aValue );
482 break;
483 case NP_FILL:
484 if( aValue >>= nInt16 )
485 xNode->setFill( nInt16 );
486 else
488 SAL_INFO("oox.ppt","any >>= failed " << __LINE__ );
490 break;
491 case NP_REPEATCOUNT:
492 xNode->setRepeatCount( aValue );
493 break;
494 case NP_REPEATDURATION:
495 xNode->setRepeatDuration( aValue );
496 break;
497 case NP_RESTART:
498 if( aValue >>= nInt16 )
499 xNode->setRestart( nInt16 );
500 else
502 SAL_INFO("oox.ppt","any >>= failed " << __LINE__ );
504 break;
505 case NP_COMMAND:
506 if( xCommand.is() )
508 if( aValue >>= nInt16 )
509 xCommand->setCommand( nInt16 );
510 else
512 SAL_INFO("oox.ppt","any >>= failed " << __LINE__ );
515 break;
516 case NP_PARAMETER:
517 if( xCommand.is() )
518 xCommand->setParameter( aValue );
519 break;
520 case NP_ITERATETYPE:
521 if( xIterateContainer.is() )
523 if( aValue >>= nInt16 )
524 xIterateContainer->setIterateType( nInt16 );
525 else
527 SAL_INFO("oox.ppt","any >>= failed " << __LINE__ );
530 break;
531 case NP_ITERATEINTERVAL:
532 if( xIterateContainer.is() )
534 if( aValue >>= fDouble )
535 xIterateContainer->setIterateInterval( fDouble );
536 else
538 SAL_INFO("oox.ppt","any >>= failed " << __LINE__ );
541 break;
542 default:
543 SAL_INFO("oox.ppt","ERR-OOX: unknown prop index " << i );
544 break;
549 if( mnNodeType == AnimationNodeType::TRANSITIONFILTER )
552 Reference< XTransitionFilter > xFilter( xNode, UNO_QUERY );
553 maTransitionFilter.setTransitionFilterProperties( xFilter );
556 std::for_each(
557 maChildren.begin(), maChildren.end(),
558 [&rFilter, &xNode, &pSlide] (TimeNodePtr const & child) {
559 child->addNode(rFilter, xNode, pSlide);
560 } );
562 switch( mnNodeType )
564 case AnimationNodeType::SEQ:
566 sal_Int16 nEnum = 0;
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 );
578 break;
580 case AnimationNodeType::PAR:
581 // some other cut&paste... from AnimationImporter::importAnimationContainer()
582 break;
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 )
596 try {
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 );
601 return 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: */