GPU-Calc: remove Alloc_Host_Ptr for clmem of NAN vector
[LibreOffice.git] / oox / source / ppt / timenode.cxx
blobea483c1137f34393b41c8bcbc8763d75097c6e9d
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 <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;
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::ANIMATECOLOR:
71 sServiceName = "com.sun.star.animations.AnimateColor";
72 break;
73 case AnimationNodeType::TRANSITIONFILTER:
74 sServiceName = "com.sun.star.animations.TransitionFilter";
75 break;
76 case AnimationNodeType::ANIMATEMOTION:
77 sServiceName = "com.sun.star.animations.AnimateMotion";
78 break;
79 case AnimationNodeType::ANIMATETRANSFORM:
80 sServiceName = "com.sun.star.animations.AnimateTransform";
81 break;
82 case AnimationNodeType::COMMAND:
83 sServiceName = "com.sun.star.animations.Command";
84 break;
85 case AnimationNodeType::SET:
86 sServiceName = "com.sun.star.animations.AnimateSet";
87 break;
88 case AnimationNodeType::AUDIO:
89 sServiceName = "com.sun.star.animations.Audio";
90 break;
91 default:
92 SAL_INFO("oox.ppt","OOX: uhandled type " << nNodeType );
93 break;
95 return sServiceName;
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 )
117 bool bFirst = true;
118 Reference< XEnumerationAccess > xEA( xNode, UNO_QUERY_THROW );
119 Reference< XEnumeration > xE( xEA->createEnumeration(), UNO_QUERY_THROW );
120 while( xE->hasMoreElements() )
122 // click node
123 Reference< XAnimationNode > xClickNode( xE->nextElement(), UNO_QUERY );
125 Event aEvent;
126 aEvent.Trigger = EventTrigger::ON_NEXT;
127 aEvent.Repeat = 0;
128 xClickNode->setBegin( makeAny( aEvent ) );
130 if( bFirst )
132 bFirst = false;
133 Reference< XEnumerationAccess > xEA2( xClickNode, UNO_QUERY_THROW );
134 Reference< XEnumeration > xE2( xEA2->createEnumeration(), UNO_QUERY_THROW );
135 if( xE2->hasMoreElements() )
137 // with node
138 xE2->nextElement() >>= xEA2;
139 if( xEA2.is() )
140 xE2.query( xEA2->createEnumeration() );
141 else
142 xE2.clear();
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();
150 while( nLength-- )
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 ) );
161 break;
164 p++;
171 catch( Exception& e )
173 (void)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() );
185 Any aEmpty;
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() )
192 // click node
193 Reference< XAnimationNode > xClickNode( xE->nextElement(), UNO_QUERY );
194 xClickNode->setBegin( aBegin );
197 catch( Exception& e )
199 (void)e;
200 SAL_INFO("oox.ppt","fixInteractiveSequenceTiming(), exception caught!" );
204 // END CUT&PASTE
206 void TimeNode::addNode( const XmlFilterBase& rFilter, const Reference< XAnimationNode >& rxNode, const SlidePersistPtr & pSlide )
208 try {
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" );
224 try {
225 if( !msId.isEmpty() )
227 pSlide->getAnimNodesMap()[ msId ] = xNode;
230 if( mpTarget )
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 );
274 #endif
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;
301 double fDouble = 0;
302 OUString sString;
303 Sequence< NamedValue > aSeq;
305 for( int i = 0; i < _NP_SIZE; i++)
307 Any & aValue( maNodeProperties[ i ] );
308 if( aValue.hasValue() )
310 switch( i )
312 case NP_TO:
313 if( xAnimate.is() )
314 xAnimate->setTo( aValue );
315 break;
316 case NP_FROM:
317 if( xAnimate.is() )
318 xAnimate->setFrom( aValue );
319 break;
320 case NP_BY:
321 if( xAnimate.is() )
322 xAnimate->setBy( aValue );
323 break;
324 case NP_TARGET:
325 if( xAnimate.is() )
326 xAnimate->setTarget( aValue );
327 break;
328 case NP_SUBITEM:
329 if( xAnimate.is() )
331 if( aValue >>= nInt16 )
332 xAnimate->setSubItem( nInt16 );
333 else
335 SAL_INFO("oox.ppt","any >>= failed " << __LINE__ );
338 break;
339 case NP_ATTRIBUTENAME:
340 if( xAnimate.is() )
342 if( aValue >>= sString )
343 xAnimate->setAttributeName( sString );
344 else
346 SAL_INFO("oox.ppt","any >>= failed " << __LINE__ );
349 break;
350 case NP_CALCMODE:
351 if( xAnimate.is() )
353 if( aValue >>= nInt16 )
354 xAnimate->setCalcMode( nInt16 );
355 else
357 SAL_INFO("oox.ppt","any >>= failed " << __LINE__ );
360 break;
361 case NP_KEYTIMES:
362 if( xAnimate.is() )
364 Sequence<double> aKeyTimes;
365 if( aValue >>= aKeyTimes )
366 xAnimate->setKeyTimes(aKeyTimes);
367 else
369 SAL_INFO("oox.ppt","any >>= failed " << __LINE__ );
372 break;
373 case NP_VALUES:
374 if( xAnimate.is() )
376 Sequence<Any> aValues;
377 if( aValue >>= aValues )
378 xAnimate->setValues(aValues);
379 else
381 SAL_INFO("oox.ppt","any >>= failed " << __LINE__ );
384 break;
385 case NP_FORMULA:
386 if( xAnimate.is() )
388 if( aValue >>= sString )
389 xAnimate->setFormula(sString);
390 else
392 SAL_INFO("oox.ppt","any >>= failed " << __LINE__ );
395 break;
396 case NP_COLORINTERPOLATION:
397 if( xAnimateColor.is() )
399 if( aValue >>= nInt16 )
400 xAnimateColor->setColorInterpolation( nInt16 );
401 else
403 SAL_INFO("oox.ppt","any >>= failed " << __LINE__ );
406 break;
407 case NP_DIRECTION:
408 if( xAnimateColor.is() )
410 if( aValue >>= bBool )
411 xAnimateColor->setDirection( bBool );
412 else
414 SAL_INFO("oox.ppt","any >>= failed " << __LINE__ );
417 break;
418 case NP_PATH:
419 if( xAnimateMotion.is() )
420 xAnimateMotion->setPath( aValue );
421 break;
422 case NP_TRANSFORMTYPE:
423 if( xAnimateTransform.is() )
425 if( aValue >>= nInt16 )
426 xAnimateTransform->setTransformType( nInt16 );
427 else
429 SAL_INFO("oox.ppt","any >>= failed " << __LINE__ );
432 break;
433 case NP_USERDATA:
434 if( aValue >>= aSeq )
435 xNode->setUserData( aSeq );
436 else
438 SAL_INFO("oox.ppt","any >>= failed " << __LINE__ );
440 break;
441 case NP_ACCELERATION:
442 if( aValue >>= fDouble )
443 xNode->setAcceleration( fDouble );
444 else
446 SAL_INFO("oox.ppt","any >>= failed " << __LINE__ );
448 break;
449 case NP_DECELERATE:
450 if( aValue >>= fDouble )
451 xNode->setDecelerate( fDouble );
452 else
454 SAL_INFO("oox.ppt","any >>= failed " << __LINE__ );
456 break;
457 case NP_AUTOREVERSE:
458 if( aValue >>= bBool )
459 xNode->setAutoReverse( bBool );
460 else
462 SAL_INFO("oox.ppt","any >>= failed " << __LINE__ );
464 break;
465 case NP_DURATION:
466 xNode->setDuration( aValue );
467 break;
468 case NP_FILL:
469 if( aValue >>= nInt16 )
470 xNode->setFill( nInt16 );
471 else
473 SAL_INFO("oox.ppt","any >>= failed " << __LINE__ );
475 break;
476 case NP_REPEATCOUNT:
477 xNode->setRepeatCount( aValue );
478 break;
479 case NP_REPEATDURATION:
480 xNode->setRepeatDuration( aValue );
481 break;
482 case NP_RESTART:
483 if( aValue >>= nInt16 )
484 xNode->setRestart( nInt16 );
485 else
487 SAL_INFO("oox.ppt","any >>= failed " << __LINE__ );
489 break;
490 case NP_COMMAND:
491 if( xCommand.is() )
493 if( aValue >>= nInt16 )
494 xCommand->setCommand( nInt16 );
495 else
497 SAL_INFO("oox.ppt","any >>= failed " << __LINE__ );
500 break;
501 case NP_PARAMETER:
502 if( xCommand.is() )
503 xCommand->setParameter( aValue );
504 break;
505 case NP_ITERATETYPE:
506 if( xIterateContainer.is() )
508 if( aValue >>= nInt16 )
509 xIterateContainer->setIterateType( nInt16 );
510 else
512 SAL_INFO("oox.ppt","any >>= failed " << __LINE__ );
515 break;
516 case NP_ITERATEINTERVAL:
517 if( xIterateContainer.is() )
519 if( aValue >>= fDouble )
520 xIterateContainer->setIterateInterval( fDouble );
521 else
523 SAL_INFO("oox.ppt","any >>= failed " << __LINE__ );
526 break;
527 default:
528 SAL_INFO("oox.ppt","ERR-OOX: unknown prop index " << i );
529 break;
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) ) );
545 switch( mnNodeType )
547 case AnimationNodeType::SEQ:
549 sal_Int16 nEnum = 0;
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 );
561 break;
563 case AnimationNodeType::PAR:
564 // some other cut&paste... from AnimationImporter::importAnimationContainer()
565 break;
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 )
580 try {
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 );
585 return 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: */