GPU-Calc: remove Alloc_Host_Ptr for clmem of NAN vector
[LibreOffice.git] / oox / source / ppt / timenodelistcontext.cxx
blobca7f1cde248b9e03cec6c05c9d873ece9bc629f3
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/timenodelistcontext.hxx"
22 #include "comphelper/anytostring.hxx"
23 #include "cppuhelper/exc_hlp.hxx"
24 #include <osl/diagnose.h>
25 #include <rtl/math.hxx>
27 #include <com/sun/star/animations/XTimeContainer.hpp>
28 #include <com/sun/star/animations/XAnimationNode.hpp>
29 #include <com/sun/star/animations/XAnimateColor.hpp>
30 #include <com/sun/star/animations/XAnimateSet.hpp>
31 #include <com/sun/star/animations/XAnimateTransform.hpp>
32 #include <com/sun/star/animations/AnimationTransformType.hpp>
33 #include <com/sun/star/animations/AnimationCalcMode.hpp>
34 #include <com/sun/star/animations/AnimationColorSpace.hpp>
35 #include <com/sun/star/animations/AnimationNodeType.hpp>
36 #include <com/sun/star/animations/XCommand.hpp>
37 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
38 #include <com/sun/star/presentation/EffectCommands.hpp>
39 #include <com/sun/star/beans/NamedValue.hpp>
41 #include "oox/helper/attributelist.hxx"
42 #include "oox/core/xmlfilterbase.hxx"
43 #include "oox/drawingml/drawingmltypes.hxx"
44 #include "oox/drawingml/colorchoicecontext.hxx"
45 #include "oox/ppt/slidetransition.hxx"
47 #include "animvariantcontext.hxx"
48 #include "commonbehaviorcontext.hxx"
49 #include "conditioncontext.hxx"
50 #include "commontimenodecontext.hxx"
51 #include "timeanimvaluecontext.hxx"
52 #include "animationtypes.hxx"
54 using namespace ::oox::core;
55 using namespace ::oox::drawingml;
56 using namespace ::com::sun::star;
57 using namespace ::com::sun::star::uno;
58 using namespace ::com::sun::star::lang;
59 using namespace ::com::sun::star::animations;
60 using namespace ::com::sun::star::presentation;
61 using namespace ::com::sun::star::xml::sax;
62 using ::com::sun::star::beans::NamedValue;
64 namespace oox { namespace ppt {
66 struct AnimColor
68 AnimColor(sal_Int16 cs, sal_Int32 o, sal_Int32 t, sal_Int32 th )
69 : colorSpace( cs ), one( o ), two( t ), three( th )
73 sal_Int32 get()
75 sal_Int32 nColor;
77 switch( colorSpace )
79 case AnimationColorSpace::HSL:
80 nColor = ( ( ( one * 128 ) / 360 ) & 0xff ) << 16
81 | ( ( ( two * 128 ) / 1000 ) & 0xff ) << 8
82 | ( ( ( three * 128 ) / 1000 ) & 0xff );
83 break;
84 case AnimationColorSpace::RGB:
85 nColor = ( ( ( one * 128 ) / 1000 ) & 0xff ) << 16
86 | ( ( ( two * 128 ) / 1000 ) & 0xff ) << 8
87 | ( ( ( three * 128 ) / 1000 ) & 0xff );
88 break;
89 default:
90 nColor = 0;
91 break;
93 return nColor;
96 sal_Int16 colorSpace;
97 sal_Int32 one;
98 sal_Int32 two;
99 sal_Int32 three;
103 /** CT_TLMediaNodeAudio
104 CT_TLMediaNodeVideo */
105 class MediaNodeContext
106 : public TimeNodeContext
108 public:
109 MediaNodeContext( FragmentHandler2& rParent, sal_Int32 aElement,
110 const Reference< XFastAttributeList >& xAttribs,
111 const TimeNodePtr & pNode )
112 : TimeNodeContext( rParent, aElement, xAttribs, pNode )
113 , mbIsNarration( false )
114 , mbFullScrn( false )
116 AttributeList attribs( xAttribs );
118 switch( aElement )
120 case PPT_TOKEN( audio ):
121 mbIsNarration = attribs.getBool( XML_isNarration, false );
122 break;
123 case PPT_TOKEN( video ):
124 mbFullScrn = attribs.getBool( XML_fullScrn, false );
125 break;
126 default:
127 break;
131 virtual void onEndElement()
133 sal_Int32 aElement = getCurrentElement();
134 if( aElement == PPT_TOKEN( audio ) )
136 // TODO deal with mbIsNarration
138 else if( aElement == PPT_TOKEN( video ) )
140 // TODO deal with mbFullScrn
144 virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
146 switch ( aElementToken )
148 case PPT_TOKEN( cBhvr ):
149 return new CommonBehaviorContext ( *this, rAttribs.getFastAttributeList(), mpNode );
150 default:
151 break;
154 return this;
157 private:
158 bool mbIsNarration;
159 bool mbFullScrn;
163 /** CT_TLSetBehavior
165 class SetTimeNodeContext
166 : public TimeNodeContext
168 public:
169 SetTimeNodeContext( FragmentHandler2& rParent, sal_Int32 aElement,
170 const Reference< XFastAttributeList >& xAttribs,
171 const TimeNodePtr & pNode )
172 : TimeNodeContext( rParent, aElement, xAttribs, pNode )
177 ~SetTimeNodeContext() throw ()
179 if( maTo.hasValue() )
181 // TODO
182 // HACK !!! discard and refactor
183 OUString aString;
184 if( maTo >>= aString )
186 OSL_TRACE( "Magic conversion %s", OUSTRING_TO_CSTR( aString ) );
187 maTo = makeAny( aString == "visible" ? sal_True : sal_False );
188 if( !maTo.has<sal_Bool>() )
189 OSL_TRACE( "conversion failed" );
191 mpNode->setTo( maTo );
196 virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
198 switch ( aElementToken )
200 case PPT_TOKEN( cBhvr ):
201 return new CommonBehaviorContext ( *this, rAttribs.getFastAttributeList(), mpNode );
202 case PPT_TOKEN( to ):
203 // CT_TLAnimVariant
204 return new AnimVariantContext( *this, aElementToken, maTo );
205 default:
206 break;
209 return this;
211 private:
212 Any maTo;
215 /** CT_TLCommandBehavior
217 class CmdTimeNodeContext
218 : public TimeNodeContext
220 public:
221 CmdTimeNodeContext( FragmentHandler2& rParent, sal_Int32 aElement,
222 const Reference< XFastAttributeList >& xAttribs,
223 const TimeNodePtr & pNode )
224 : TimeNodeContext( rParent, aElement, xAttribs, pNode )
225 , maType(0)
227 switch ( aElement )
229 case PPT_TOKEN( cmd ):
230 msCommand = xAttribs->getOptionalValue( XML_cmd );
231 maType = xAttribs->getOptionalValueToken( XML_type, 0 );
232 break;
233 default:
234 break;
238 ~CmdTimeNodeContext() throw ()
242 virtual void onEndElement()
244 if( isCurrentElement( PPT_TOKEN( cmd ) ) )
246 try {
247 // see sd/source/filter/ppt/pptinanimations.cxx
248 // in AnimationImporter::importCommandContainer()
249 // REFACTOR?
250 // a good chunk of this code has been copied verbatim *sigh*
251 sal_Int16 nCommand = EffectCommands::CUSTOM;
252 NamedValue aParamValue;
254 switch( maType )
256 case XML_verb:
257 aParamValue.Name = "Verb";
258 // TODO make sure msCommand has what we want
259 aParamValue.Value <<= msCommand.toInt32();
260 nCommand = EffectCommands::VERB;
261 break;
262 case XML_evt:
263 case XML_call:
264 if ( msCommand == "onstopaudio" )
266 nCommand = EffectCommands::STOPAUDIO;
268 else if ( msCommand == "play" )
270 nCommand = EffectCommands::PLAY;
272 else if( msCommand.equalsAscii( "playFrom" ) )
274 const OUString aMediaTime( msCommand.copy( 9, msCommand.getLength() - 10 ) );
275 rtl_math_ConversionStatus eStatus;
276 double fMediaTime = ::rtl::math::stringToDouble( aMediaTime, (sal_Unicode)('.'), (sal_Unicode)(','), &eStatus, NULL );
277 if( eStatus == rtl_math_ConversionStatus_Ok )
279 aParamValue.Name = "MediaTime";
280 aParamValue.Value <<= fMediaTime;
282 nCommand = EffectCommands::PLAY;
284 else if ( msCommand == "togglePause" )
286 nCommand = EffectCommands::TOGGLEPAUSE;
288 else if ( msCommand == "stop" )
290 nCommand = EffectCommands::STOP;
292 break;
294 mpNode->getNodeProperties()[ NP_COMMAND ] = makeAny((sal_Int16)nCommand);
295 if( nCommand == EffectCommands::CUSTOM )
297 OSL_TRACE("OOX: CmdTimeNodeContext::endFastElement(), unknown command!");
298 aParamValue.Name = "UserDefined";
299 aParamValue.Value <<= msCommand;
301 if( aParamValue.Value.hasValue() )
303 Sequence< NamedValue > aParamSeq( &aParamValue, 1 );
304 mpNode->getNodeProperties()[ NP_PARAMETER ] = makeAny( aParamSeq );
307 catch( RuntimeException& )
309 OSL_TRACE( "OOX: Exception in CmdTimeNodeContext::endFastElement()" );
315 virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
317 switch ( aElementToken )
319 case PPT_TOKEN( cBhvr ):
320 return new CommonBehaviorContext ( *this, rAttribs.getFastAttributeList(), mpNode );
321 default:
322 break;
325 return this;
328 private:
329 OUString msCommand;
330 sal_Int32 maType;
334 /** CT_TLTimeNodeSequence
336 class SequenceTimeNodeContext
337 : public TimeNodeContext
339 public:
340 SequenceTimeNodeContext( FragmentHandler2& rParent, sal_Int32 aElement,
341 const Reference< XFastAttributeList >& xAttribs,
342 const TimeNodePtr & pNode )
343 : TimeNodeContext( rParent, aElement, xAttribs, pNode )
344 , mnNextAc(0)
345 , mnPrevAc(0)
347 AttributeList attribs(xAttribs);
348 mbConcurrent = attribs.getBool( XML_concurrent, false );
349 mnNextAc = xAttribs->getOptionalValueToken( XML_nextAc, 0 );
350 mnPrevAc = xAttribs->getOptionalValueToken( XML_prevAc, 0 );
353 ~SequenceTimeNodeContext() throw()
358 virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
360 switch ( aElementToken )
362 case PPT_TOKEN( cTn ):
363 return new CommonTimeNodeContext( *this, aElementToken, rAttribs.getFastAttributeList(), mpNode );
364 case PPT_TOKEN( nextCondLst ):
365 return new CondListContext( *this, aElementToken, rAttribs.getFastAttributeList(), mpNode,
366 mpNode->getNextCondition() );
367 case PPT_TOKEN( prevCondLst ):
368 return new CondListContext( *this, aElementToken, rAttribs.getFastAttributeList(), mpNode,
369 mpNode->getPrevCondition() );
370 default:
371 break;
374 return this;
376 private:
377 bool mbConcurrent;
378 sal_Int32 mnNextAc, mnPrevAc;
382 /** CT_TLTimeNodeParallel
383 * CT_TLTimeNodeExclusive
385 class ParallelExclTimeNodeContext
386 : public TimeNodeContext
388 public:
389 ParallelExclTimeNodeContext( FragmentHandler2& rParent, sal_Int32 aElement,
390 const Reference< XFastAttributeList >& xAttribs,
391 const TimeNodePtr & pNode )
392 : TimeNodeContext( rParent, aElement, xAttribs, pNode )
396 virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
398 switch ( aElementToken )
400 case PPT_TOKEN( cTn ):
401 return new CommonTimeNodeContext( *this, aElementToken, rAttribs.getFastAttributeList(), mpNode );
402 default:
403 break;
406 return this;
409 protected:
414 /** CT_TLAnimateColorBehavior */
415 class AnimColorContext
416 : public TimeNodeContext
418 public:
419 AnimColorContext( FragmentHandler2& rParent, sal_Int32 aElement,
420 const Reference< XFastAttributeList >& xAttribs,
421 const TimeNodePtr & pNode ) throw()
422 : TimeNodeContext( rParent, aElement, xAttribs, pNode )
423 , mnColorSpace( xAttribs->getOptionalValueToken( XML_clrSpc, 0 ) )
424 , mnDir( xAttribs->getOptionalValueToken( XML_dir, 0 ) )
425 , mbHasByColor( false )
426 , m_byColor( AnimationColorSpace::RGB, 0, 0, 0)
429 ~AnimColorContext() throw()
433 virtual void onEndElement()
435 //xParentNode
436 if( isCurrentElement( mnElement ) )
438 NodePropertyMap & pProps(mpNode->getNodeProperties());
439 pProps[ NP_DIRECTION ] = makeAny( mnDir == XML_cw );
440 pProps[ NP_COLORINTERPOLATION ] = makeAny( mnColorSpace == XML_hsl ? AnimationColorSpace::HSL : AnimationColorSpace::RGB );
441 const GraphicHelper& rGraphicHelper = getFilter().getGraphicHelper();
442 if( maToClr.isUsed() )
443 mpNode->setTo( Any( maToClr.getColor( rGraphicHelper ) ) );
444 if( maFromClr.isUsed() )
445 mpNode->setFrom( Any( maFromClr.getColor( rGraphicHelper ) ) );
446 if( mbHasByColor )
447 mpNode->setBy( Any ( m_byColor.get() ) );
452 virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
454 switch ( aElementToken )
456 case PPT_TOKEN( hsl ):
457 // CT_TLByHslColorTransform
459 if( mbHasByColor )
461 m_byColor.colorSpace = AnimationColorSpace::HSL;
462 m_byColor.one = rAttribs.getInteger( XML_h, 0 );
463 m_byColor.two = rAttribs.getInteger( XML_s, 0 );
464 m_byColor.three = rAttribs.getInteger( XML_l, 0 );
466 return this;
468 case PPT_TOKEN( rgb ):
470 if( mbHasByColor )
472 // CT_TLByRgbColorTransform
473 m_byColor.colorSpace = AnimationColorSpace::RGB;
474 m_byColor.one = rAttribs.getInteger( XML_r, 0 );
475 m_byColor.two = rAttribs.getInteger( XML_g, 0 );
476 m_byColor.three = rAttribs.getInteger( XML_b, 0 );
478 return this;
480 case PPT_TOKEN( by ):
481 // CT_TLByAnimateColorTransform
482 mbHasByColor = true;
483 return this;
484 case PPT_TOKEN( cBhvr ):
485 return new CommonBehaviorContext ( *this, rAttribs.getFastAttributeList(), mpNode );
486 case PPT_TOKEN( to ):
487 // CT_Color
488 return new ColorContext( *this, maToClr );
489 case PPT_TOKEN( from ):
490 // CT_Color
491 return new ColorContext( *this, maFromClr );
493 default:
494 break;
497 return this;
501 private:
502 sal_Int32 mnColorSpace;
503 sal_Int32 mnDir;
504 bool mbHasByColor;
505 AnimColor m_byColor;
506 oox::drawingml::Color maToClr;
507 oox::drawingml::Color maFromClr;
511 /** CT_TLAnimateBehavior */
512 class AnimContext
513 : public TimeNodeContext
515 public:
516 AnimContext( FragmentHandler2& rParent, sal_Int32 aElement,
517 const Reference< XFastAttributeList >& xAttribs,
518 const TimeNodePtr & pNode ) throw()
519 : TimeNodeContext( rParent, aElement, xAttribs, pNode )
521 NodePropertyMap & aProps( pNode->getNodeProperties() );
522 sal_Int32 nCalcMode = xAttribs->getOptionalValueToken( XML_calcmode, 0 );
523 if(nCalcMode)
525 sal_Int16 nEnum = 0;
526 switch(nCalcMode)
528 case XML_discrete:
529 nEnum = AnimationCalcMode::DISCRETE;
530 break;
531 case XML_lin:
532 nEnum = AnimationCalcMode::LINEAR;
533 break;
534 case XML_fmla:
535 default:
536 // TODO what value is good ?
537 nEnum = AnimationCalcMode::DISCRETE;
538 break;
540 aProps[ NP_CALCMODE ] = makeAny(nEnum);
542 OUString aStr;
543 aStr = xAttribs->getOptionalValue( XML_from );
544 if( !aStr.isEmpty() )
546 pNode->setFrom( makeAny( aStr ) );
548 aStr = xAttribs->getOptionalValue( XML_by );
549 if( !aStr.isEmpty() )
551 pNode->setBy( makeAny( aStr ) );
553 aStr = xAttribs->getOptionalValue( XML_to );
554 if( !aStr.isEmpty() )
556 pNode->setTo( makeAny( aStr ) );
558 mnValueType = xAttribs->getOptionalValueToken( XML_valueType, 0 );
562 ~AnimContext() throw ()
564 ::std::list< TimeAnimationValue >::iterator iter, end;
565 int nKeyTimes = maTavList.size();
566 if( nKeyTimes > 0)
568 int i;
569 Sequence< double > aKeyTimes( nKeyTimes );
570 Sequence< Any > aValues( nKeyTimes );
572 NodePropertyMap & aProps( mpNode->getNodeProperties() );
573 end = maTavList.end();
574 for(iter = maTavList.begin(), i=0; iter != end; ++iter,++i)
576 // TODO what to do if it is Timing_INFINITE ?
577 Any aTime = GetTimeAnimateValueTime( iter->msTime );
578 aTime >>= aKeyTimes[i];
579 aValues[i] = iter->maValue;
581 OUString aTest;
582 iter->maValue >>= aTest;
583 if( !aTest.isEmpty() )
585 aValues[i] = iter->maValue;
587 else
589 aProps[ NP_FORMULA ] <<= iter->msFormula;
592 aProps[ NP_VALUES ] <<= aValues;
593 aProps[ NP_KEYTIMES ] <<= aKeyTimes;
598 virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
600 switch ( aElementToken )
602 case PPT_TOKEN( cBhvr ):
603 return new CommonBehaviorContext ( *this, rAttribs.getFastAttributeList(), mpNode );
604 case PPT_TOKEN( tavLst ):
605 return new TimeAnimValueListContext ( *this, rAttribs.getFastAttributeList(), maTavList );
606 default:
607 break;
610 return this;
612 private:
613 sal_Int32 mnValueType;
614 TimeAnimationValueList maTavList;
618 /** CT_TLAnimateScaleBehavior */
619 class AnimScaleContext
620 : public TimeNodeContext
622 public:
623 AnimScaleContext( FragmentHandler2& rParent, sal_Int32 aElement,
624 const Reference< XFastAttributeList >& xAttribs,
625 const TimeNodePtr & pNode ) throw()
626 : TimeNodeContext( rParent, aElement, xAttribs, pNode )
627 , mbZoomContents( false )
629 AttributeList attribs( xAttribs );
630 // TODO what to do with mbZoomContents
631 mbZoomContents = attribs.getBool( XML_zoomContents, false );
632 pNode->getNodeProperties()[ NP_TRANSFORMTYPE ]
633 = makeAny((sal_Int16)AnimationTransformType::SCALE);
636 ~AnimScaleContext( ) throw( )
640 virtual void onEndElement()
642 if( isCurrentElement( mnElement ) )
644 if( maTo.hasValue() )
646 mpNode->setTo( maTo );
648 if( maBy.hasValue() )
650 mpNode->setBy( maBy );
652 if( maFrom.hasValue() )
654 mpNode->setFrom( maFrom );
659 virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
661 switch ( aElementToken )
663 case PPT_TOKEN( cBhvr ):
664 return new CommonBehaviorContext ( *this, rAttribs.getFastAttributeList(), mpNode );
665 case PPT_TOKEN( to ):
667 // CT_TLPoint
668 awt::Point p = GetPointPercent( rAttribs.getFastAttributeList() );
669 maTo <<= p.X;
670 maTo <<= p.Y;
671 return this;
673 case PPT_TOKEN( from ):
675 // CT_TLPoint
676 awt::Point p = GetPointPercent( rAttribs.getFastAttributeList() );
677 maFrom <<= p.X;
678 maFrom <<= p.Y;
679 return this;
681 case PPT_TOKEN( by ):
683 // CT_TLPoint
684 awt::Point p = GetPointPercent( rAttribs.getFastAttributeList() );
685 maBy <<= p.X;
686 maBy <<= p.Y;
687 return this;
689 default:
690 break;
693 return this;
695 private:
696 Any maBy;
697 Any maFrom;
698 Any maTo;
699 bool mbZoomContents;
703 /** CT_TLAnimateRotationBehavior */
704 class AnimRotContext
705 : public TimeNodeContext
707 public:
708 AnimRotContext( FragmentHandler2& rParent, sal_Int32 aElement,
709 const Reference< XFastAttributeList >& xAttribs,
710 const TimeNodePtr & pNode ) throw()
711 : TimeNodeContext( rParent, aElement, xAttribs, pNode )
713 AttributeList attribs( xAttribs );
715 pNode->getNodeProperties()[ NP_TRANSFORMTYPE ]
716 = makeAny((sal_Int16)AnimationTransformType::ROTATE);
717 // TODO make sure the units are OK
718 if(attribs.hasAttribute( XML_by ) )
720 sal_Int32 nBy = attribs.getInteger( XML_by, 0 );
721 pNode->setBy( makeAny( nBy ) );
723 if(attribs.hasAttribute( XML_from ) )
725 sal_Int32 nFrom = attribs.getInteger( XML_from, 0 );
726 pNode->setFrom( makeAny( nFrom ) );
728 if(attribs.hasAttribute( XML_to ) )
730 sal_Int32 nTo = attribs.getInteger( XML_to, 0 );
731 pNode->setTo( makeAny( nTo ) );
735 ~AnimRotContext( ) throw( )
739 virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
741 switch ( aElementToken )
743 case PPT_TOKEN( cBhvr ):
744 return new CommonBehaviorContext ( *this, rAttribs.getFastAttributeList(), mpNode );
745 default:
746 break;
749 return this;
755 /** CT_TLAnimateMotionBehavior */
756 class AnimMotionContext
757 : public TimeNodeContext
759 public:
760 AnimMotionContext( FragmentHandler2& rParent, sal_Int32 aElement,
761 const Reference< XFastAttributeList >& xAttribs,
762 const TimeNodePtr & pNode ) throw()
763 : TimeNodeContext( rParent, aElement, xAttribs, pNode )
765 pNode->getNodeProperties()[ NP_TRANSFORMTYPE ]
766 = makeAny((sal_Int16)AnimationTransformType::TRANSLATE);
768 AttributeList attribs( xAttribs );
769 sal_Int32 nOrigin = xAttribs->getOptionalValueToken( XML_origin, 0 );
770 if( nOrigin != 0 )
772 switch(nOrigin)
774 case XML_layout:
775 case XML_parent:
776 break;
778 // TODO
781 OUString aStr = xAttribs->getOptionalValue( XML_path );
782 aStr = aStr.replace( 'E', ' ' );
783 aStr = aStr.trim();
784 pNode->getNodeProperties()[ NP_PATH ] = makeAny(aStr);
785 mnPathEditMode = xAttribs->getOptionalValueToken( XML_pathEditMode, 0 );
786 msPtsTypes = xAttribs->getOptionalValue( XML_ptsTypes );
787 mnAngle = attribs.getInteger( XML_rAng, 0 );
788 // TODO make sure the units are right. Likely not.
791 ~AnimMotionContext( ) throw()
796 virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
798 switch ( aElementToken )
800 case PPT_TOKEN( cBhvr ):
801 return new CommonBehaviorContext ( *this, rAttribs.getFastAttributeList(), mpNode );
802 case PPT_TOKEN( to ):
804 // CT_TLPoint
805 awt::Point p = GetPointPercent( rAttribs.getFastAttributeList() );
806 Any rAny;
807 rAny <<= p.X;
808 rAny <<= p.Y;
809 mpNode->setTo( rAny );
810 return this;
812 case PPT_TOKEN( from ):
814 // CT_TLPoint
815 awt::Point p = GetPointPercent( rAttribs.getFastAttributeList() );
816 Any rAny;
817 rAny <<= p.X;
818 rAny <<= p.Y;
819 mpNode->setFrom( rAny );
820 return this;
822 case PPT_TOKEN( by ):
824 // CT_TLPoint
825 awt::Point p = GetPointPercent( rAttribs.getFastAttributeList() );
826 Any rAny;
827 rAny <<= p.X;
828 rAny <<= p.Y;
829 mpNode->setBy( rAny );
830 return this;
832 case PPT_TOKEN( rCtr ):
834 // CT_TLPoint
835 awt::Point p = GetPointPercent( rAttribs.getFastAttributeList() );
836 // TODO push
837 (void)p;
838 return this;
840 default:
841 break;
844 return this;
846 private:
847 OUString msPtsTypes;
848 sal_Int32 mnPathEditMode;
849 sal_Int32 mnAngle;
853 /** CT_TLAnimateEffectBehavior */
854 class AnimEffectContext
855 : public TimeNodeContext
857 public:
858 AnimEffectContext( FragmentHandler2& rParent, sal_Int32 aElement,
859 const Reference< XFastAttributeList >& xAttribs,
860 const TimeNodePtr & pNode ) throw()
861 : TimeNodeContext( rParent, aElement, xAttribs, pNode )
863 sal_Int32 nDir = xAttribs->getOptionalValueToken( XML_transition, 0 );
864 OUString sFilter = xAttribs->getOptionalValue( XML_filter );
865 // TODO
866 // OUString sPrList = xAttribs->getOptionalValue( XML_prLst );
868 if( !sFilter.isEmpty() )
870 SlideTransition aFilter( sFilter );
871 aFilter.setMode( nDir == XML_out ? false : true );
872 pNode->setTransitionFilter( aFilter );
877 ~AnimEffectContext( ) throw()
882 virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
884 switch ( aElementToken )
886 case PPT_TOKEN( cBhvr ):
887 return new CommonBehaviorContext ( *this, rAttribs.getFastAttributeList(), mpNode );
888 case PPT_TOKEN( progress ):
889 return new AnimVariantContext( *this, aElementToken, maProgress );
890 // TODO handle it.
891 default:
892 break;
895 return this;
897 private:
898 Any maProgress;
899 OUString msFilter;
900 OUString msPrList;
905 TimeNodeContext * TimeNodeContext::makeContext(
906 FragmentHandler2& rParent, sal_Int32 aElement,
907 const Reference< XFastAttributeList >& xAttribs,
908 const TimeNodePtr & pNode )
910 TimeNodeContext *pCtx = NULL;
911 switch( aElement )
913 case PPT_TOKEN( animClr ):
914 pCtx = new AnimColorContext( rParent, aElement, xAttribs, pNode );
915 break;
916 case PPT_TOKEN( par ):
917 pCtx = new ParallelExclTimeNodeContext( rParent, aElement, xAttribs, pNode );
918 break;
919 case PPT_TOKEN( seq ):
920 pCtx = new SequenceTimeNodeContext( rParent, aElement, xAttribs, pNode );
921 break;
922 case PPT_TOKEN( excl ):
923 pCtx = new ParallelExclTimeNodeContext( rParent, aElement, xAttribs, pNode );
924 break;
925 case PPT_TOKEN( anim ):
926 pCtx = new AnimContext ( rParent, aElement, xAttribs, pNode );
927 break;
928 case PPT_TOKEN( animEffect ):
929 pCtx = new AnimEffectContext( rParent, aElement, xAttribs, pNode );
930 break;
931 case PPT_TOKEN( animMotion ):
932 pCtx = new AnimMotionContext( rParent, aElement, xAttribs, pNode );
933 break;
934 case PPT_TOKEN( animRot ):
935 pCtx = new AnimRotContext( rParent, aElement, xAttribs, pNode );
936 break;
937 case PPT_TOKEN( animScale ):
938 pCtx = new AnimScaleContext( rParent, aElement, xAttribs, pNode );
939 break;
940 case PPT_TOKEN( cmd ):
941 pCtx = new CmdTimeNodeContext( rParent, aElement, xAttribs, pNode );
942 break;
943 case PPT_TOKEN( set ):
944 pCtx = new SetTimeNodeContext( rParent, aElement, xAttribs, pNode );
945 break;
946 case PPT_TOKEN( audio ):
947 case PPT_TOKEN( video ):
948 pCtx = new MediaNodeContext( rParent, aElement, xAttribs, pNode );
949 break;
950 default:
951 break;
953 return pCtx;
957 TimeNodeContext::TimeNodeContext( FragmentHandler2& rParent, sal_Int32 aElement,
958 const Reference< XFastAttributeList >& /*xAttribs*/,
959 const TimeNodePtr & pNode ) throw()
960 : FragmentHandler2( rParent )
961 , mnElement( aElement )
962 , mpNode( pNode )
967 TimeNodeContext::~TimeNodeContext( ) throw()
973 TimeNodeListContext::TimeNodeListContext( FragmentHandler2& rParent, TimeNodePtrList & aList )
974 throw()
975 : FragmentHandler2( rParent )
976 , maList( aList )
981 TimeNodeListContext::~TimeNodeListContext( ) throw()
986 ::oox::core::ContextHandlerRef TimeNodeListContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
988 sal_Int16 nNodeType;
990 switch( aElementToken )
992 case PPT_TOKEN( par ):
993 nNodeType = AnimationNodeType::PAR;
994 break;
995 case PPT_TOKEN( seq ):
996 nNodeType = AnimationNodeType::SEQ;
997 break;
998 case PPT_TOKEN( excl ):
999 // TODO pick the right type. We choose parallel for now as
1000 // there does not seem to be an "Exclusive"
1001 nNodeType = AnimationNodeType::PAR;
1002 break;
1003 case PPT_TOKEN( anim ):
1004 nNodeType = AnimationNodeType::ANIMATE;
1005 break;
1006 case PPT_TOKEN( animClr ):
1007 nNodeType = AnimationNodeType::ANIMATECOLOR;
1008 break;
1009 case PPT_TOKEN( animEffect ):
1010 nNodeType = AnimationNodeType::TRANSITIONFILTER;
1011 break;
1012 case PPT_TOKEN( animMotion ):
1013 nNodeType = AnimationNodeType::ANIMATEMOTION;
1014 break;
1015 case PPT_TOKEN( animRot ):
1016 case PPT_TOKEN( animScale ):
1017 nNodeType = AnimationNodeType::ANIMATETRANSFORM;
1018 break;
1019 case PPT_TOKEN( cmd ):
1020 nNodeType = AnimationNodeType::COMMAND;
1021 break;
1022 case PPT_TOKEN( set ):
1023 nNodeType = AnimationNodeType::SET;
1024 break;
1025 case PPT_TOKEN( audio ):
1026 nNodeType = AnimationNodeType::AUDIO;
1027 break;
1028 case PPT_TOKEN( video ):
1029 nNodeType = AnimationNodeType::AUDIO;
1030 OSL_TRACE( "OOX: video requested, gave Audio instead" );
1031 break;
1033 default:
1034 nNodeType = AnimationNodeType::CUSTOM;
1035 OSL_TRACE( "OOX: uhandled token %x", aElementToken );
1036 break;
1039 TimeNodePtr pNode(new TimeNode(nNodeType));
1040 maList.push_back( pNode );
1041 FragmentHandler2 * pContext = TimeNodeContext::makeContext( *this, aElementToken, rAttribs.getFastAttributeList(), pNode );
1043 return pContext ? pContext : this;
1049 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */