merge the formfield patch from ooo-build
[ooovba.git] / oox / source / ppt / timenodelistcontext.cxx
blobed3ef93765ea9e2596d4ca59cf2dfa166eac667b
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: timenodelistcontext.cxx,v $
10 * $Revision: 1.4.20.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "oox/ppt/timenodelistcontext.hxx"
33 #include "comphelper/anytostring.hxx"
34 #include "cppuhelper/exc_hlp.hxx"
35 #include <osl/diagnose.h>
36 #include <rtl/math.hxx>
38 #include <com/sun/star/animations/XTimeContainer.hpp>
39 #include <com/sun/star/animations/XAnimationNode.hpp>
40 #include <com/sun/star/animations/XAnimateColor.hpp>
41 #include <com/sun/star/animations/XAnimateSet.hpp>
42 #include <com/sun/star/animations/XAnimateTransform.hpp>
43 #include <com/sun/star/animations/AnimationTransformType.hpp>
44 #include <com/sun/star/animations/AnimationCalcMode.hpp>
45 #include <com/sun/star/animations/AnimationColorSpace.hpp>
46 #include <com/sun/star/animations/AnimationNodeType.hpp>
47 #include <com/sun/star/animations/XCommand.hpp>
48 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
49 #include <com/sun/star/presentation/EffectCommands.hpp>
50 #include <com/sun/star/beans/NamedValue.hpp>
52 #include "oox/helper/attributelist.hxx"
53 #include "oox/core/namespaces.hxx"
54 #include "oox/core/xmlfilterbase.hxx"
55 #include "oox/drawingml/drawingmltypes.hxx"
56 #include "oox/drawingml/colorchoicecontext.hxx"
57 #include "oox/ppt/slidetransition.hxx"
58 #include "tokens.hxx"
60 #include "animvariantcontext.hxx"
61 #include "commonbehaviorcontext.hxx"
62 #include "conditioncontext.hxx"
63 #include "commontimenodecontext.hxx"
64 #include "timeanimvaluecontext.hxx"
65 #include "animationtypes.hxx"
67 using namespace ::oox::core;
68 using namespace ::oox::drawingml;
69 using namespace ::com::sun::star::uno;
70 using namespace ::com::sun::star::lang;
71 using namespace ::com::sun::star::animations;
72 using namespace ::com::sun::star::presentation;
73 using namespace ::com::sun::star::xml::sax;
74 using namespace ::com::sun::star::awt;
75 using ::com::sun::star::beans::NamedValue;
77 using ::rtl::OUString;
79 namespace oox { namespace ppt {
81 struct AnimColor
83 AnimColor(sal_Int16 cs, sal_Int32 o, sal_Int32 t, sal_Int32 th )
84 : colorSpace( cs ), one( o ), two( t ), three( th )
88 sal_Int32 get()
90 sal_Int32 nColor;
92 switch( colorSpace )
94 case AnimationColorSpace::HSL:
95 nColor = ( ( ( one * 128 ) / 360 ) & 0xff ) << 16
96 | ( ( ( two * 128 ) / 1000 ) & 0xff ) << 8
97 | ( ( ( three * 128 ) / 1000 ) & 0xff );
98 break;
99 case AnimationColorSpace::RGB:
100 nColor = ( ( ( one * 128 ) / 1000 ) & 0xff ) << 16
101 | ( ( ( two * 128 ) / 1000 ) & 0xff ) << 8
102 | ( ( ( three * 128 ) / 1000 ) & 0xff );
103 break;
104 default:
105 nColor = 0;
106 break;
108 return nColor;
111 sal_Int16 colorSpace;
112 sal_Int32 one;
113 sal_Int32 two;
114 sal_Int32 three;
118 /** CT_TLMediaNodeAudio
119 CT_TLMediaNodeVideo */
120 class MediaNodeContext
121 : public TimeNodeContext
123 public:
124 MediaNodeContext( ContextHandler& rParent, sal_Int32 aElement,
125 const Reference< XFastAttributeList >& xAttribs,
126 const TimeNodePtr & pNode )
127 : TimeNodeContext( rParent, aElement, xAttribs, pNode )
128 , mbIsNarration( false )
129 , mbFullScrn( false )
131 AttributeList attribs( xAttribs );
133 switch( aElement )
135 case NMSP_PPT|XML_audio:
136 mbIsNarration = attribs.getBool( XML_isNarration, false );
137 break;
138 case NMSP_PPT|XML_video:
139 mbFullScrn = attribs.getBool( XML_fullScrn, false );
140 break;
141 default:
142 break;
146 virtual void SAL_CALL endFastElement( sal_Int32 aElement )
147 throw ( SAXException, RuntimeException)
149 if( aElement == ( NMSP_PPT|XML_audio ) )
151 // TODO deal with mbIsNarration
153 else if( aElement == ( NMSP_PPT|XML_video ) )
155 // TODO deal with mbFullScrn
159 virtual Reference< XFastContextHandler > SAL_CALL createFastChildContext( ::sal_Int32 aElementToken,
160 const Reference< XFastAttributeList >& xAttribs )
161 throw ( SAXException, RuntimeException )
163 Reference< XFastContextHandler > xRet;
165 switch ( aElementToken )
167 case NMSP_PPT|XML_cBhvr:
168 xRet.set( new CommonBehaviorContext ( *this, xAttribs, mpNode ) );
169 break;
170 default:
171 break;
174 if( !xRet.is() )
175 xRet.set( this );
177 return xRet;
180 private:
181 bool mbIsNarration;
182 bool mbFullScrn;
186 /** CT_TLSetBehavior
188 class SetTimeNodeContext
189 : public TimeNodeContext
191 public:
192 SetTimeNodeContext( ContextHandler& rParent, sal_Int32 aElement,
193 const Reference< XFastAttributeList >& xAttribs,
194 const TimeNodePtr & pNode )
195 : TimeNodeContext( rParent, aElement, xAttribs, pNode )
200 ~SetTimeNodeContext() throw ()
202 if( maTo.hasValue() )
204 // TODO
205 // HACK !!! discard and refactor
206 OUString aString;
207 if( maTo >>= aString )
209 OSL_TRACE( "Magic conversion %s", OUSTRING_TO_CSTR( aString ) );
210 maTo = makeAny( aString.equalsAscii( "visible" ) ? sal_True : sal_False );
211 if( !maTo.has<sal_Bool>() )
212 OSL_TRACE( "conversion failed" );
214 mpNode->setTo( maTo );
219 virtual void SAL_CALL endFastElement( sal_Int32 /*aElement*/ )
220 throw ( SAXException, RuntimeException)
225 virtual Reference< XFastContextHandler > SAL_CALL createFastChildContext( ::sal_Int32 aElementToken,
226 const Reference< XFastAttributeList >& xAttribs )
227 throw ( SAXException, RuntimeException )
229 Reference< XFastContextHandler > xRet;
231 switch ( aElementToken )
233 case NMSP_PPT|XML_cBhvr:
234 xRet.set( new CommonBehaviorContext ( *this, xAttribs, mpNode ) );
235 break;
236 case NMSP_PPT|XML_to:
237 // CT_TLAnimVariant
238 xRet.set( new AnimVariantContext( *this, aElementToken, maTo ) );
239 break;
240 default:
241 break;
244 if( !xRet.is() )
245 xRet.set( this );
247 return xRet;
249 private:
250 Any maTo;
253 /** CT_TLCommandBehavior
255 class CmdTimeNodeContext
256 : public TimeNodeContext
258 public:
259 CmdTimeNodeContext( ContextHandler& rParent, sal_Int32 aElement,
260 const Reference< XFastAttributeList >& xAttribs,
261 const TimeNodePtr & pNode )
262 : TimeNodeContext( rParent, aElement, xAttribs, pNode )
263 , maType(0)
265 switch ( aElement )
267 case NMSP_PPT|XML_cmd:
268 msCommand = xAttribs->getOptionalValue( XML_cmd );
269 maType = xAttribs->getOptionalValueToken( XML_type, 0 );
270 break;
271 default:
272 break;
276 ~CmdTimeNodeContext() throw ()
280 virtual void SAL_CALL endFastElement( sal_Int32 aElement )
281 throw ( SAXException, RuntimeException)
283 if( aElement == ( NMSP_PPT|XML_cmd ) )
285 try {
286 // see sd/source/filter/ppt/pptinanimations.cxx
287 // in AnimationImporter::importCommandContainer()
288 // REFACTOR?
289 // a good chunk of this code has been copied verbatim *sigh*
290 sal_Int16 nCommand = EffectCommands::CUSTOM;
291 NamedValue aParamValue;
293 switch( maType )
295 case XML_verb:
296 aParamValue.Name = OUString(RTL_CONSTASCII_USTRINGPARAM("Verb"));
297 // TODO make sure msCommand has what we want
298 aParamValue.Value <<= msCommand.toInt32();
299 nCommand = EffectCommands::VERB;
300 break;
301 case XML_evt:
302 case XML_call:
303 if( msCommand.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "onstopaudio" ) ) )
305 nCommand = EffectCommands::STOPAUDIO;
307 else if( msCommand.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("play") ) )
309 nCommand = EffectCommands::PLAY;
311 else if( msCommand.compareToAscii( RTL_CONSTASCII_STRINGPARAM("playFrom") ) == 0 )
313 const OUString aMediaTime( msCommand.copy( 9, msCommand.getLength() - 10 ) );
314 rtl_math_ConversionStatus eStatus;
315 double fMediaTime = ::rtl::math::stringToDouble( aMediaTime, (sal_Unicode)('.'), (sal_Unicode)(','), &eStatus, NULL );
316 if( eStatus == rtl_math_ConversionStatus_Ok )
318 aParamValue.Name = CREATE_OUSTRING("MediaTime");
319 aParamValue.Value <<= fMediaTime;
321 nCommand = EffectCommands::PLAY;
323 else if( msCommand.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("togglePause") ) )
325 nCommand = EffectCommands::TOGGLEPAUSE;
327 else if( msCommand.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("stop") ) )
329 nCommand = EffectCommands::STOP;
331 break;
333 mpNode->getNodeProperties()[ NP_COMMAND ] = makeAny((sal_Int16)nCommand);
334 if( nCommand == EffectCommands::CUSTOM )
336 OSL_TRACE("OOX: CmdTimeNodeContext::endFastElement(), unknown command!");
337 aParamValue.Name = CREATE_OUSTRING("UserDefined");
338 aParamValue.Value <<= msCommand;
340 if( aParamValue.Value.hasValue() )
342 Sequence< NamedValue > aParamSeq( &aParamValue, 1 );
343 mpNode->getNodeProperties()[ NP_PARAMETER ] = makeAny( aParamSeq );
346 catch( RuntimeException& )
348 OSL_TRACE( "OOX: Exception in CmdTimeNodeContext::endFastElement()" );
354 virtual Reference< XFastContextHandler > SAL_CALL createFastChildContext( ::sal_Int32 aElementToken,
355 const Reference< XFastAttributeList >& xAttribs )
356 throw ( SAXException, RuntimeException )
358 Reference< XFastContextHandler > xRet;
360 switch ( aElementToken )
362 case NMSP_PPT|XML_cBhvr:
363 xRet.set( new CommonBehaviorContext ( *this, xAttribs, mpNode ) );
364 break;
365 default:
366 break;
369 if( !xRet.is() )
370 xRet.set( this );
372 return xRet;
375 private:
376 OUString msCommand;
377 sal_Int32 maType;
381 /** CT_TLTimeNodeSequence
383 class SequenceTimeNodeContext
384 : public TimeNodeContext
386 public:
387 SequenceTimeNodeContext( ContextHandler& rParent, sal_Int32 aElement,
388 const Reference< XFastAttributeList >& xAttribs,
389 const TimeNodePtr & pNode )
390 : TimeNodeContext( rParent, aElement, xAttribs, pNode )
391 , mnNextAc(0)
392 , mnPrevAc(0)
394 AttributeList attribs(xAttribs);
395 mbConcurrent = attribs.getBool( XML_concurrent, false );
396 // ST_TLNextActionType { none, seek }
397 mnNextAc = xAttribs->getOptionalValueToken( XML_nextAc, 0 );
398 // ST_TLPreviousActionType { none, skipTimed }
399 mnPrevAc = xAttribs->getOptionalValueToken( XML_prevAc, 0 );
402 ~SequenceTimeNodeContext() throw()
407 virtual Reference< XFastContextHandler > SAL_CALL createFastChildContext( ::sal_Int32 aElementToken,
408 const Reference< XFastAttributeList >& xAttribs )
409 throw ( SAXException, RuntimeException )
411 Reference< XFastContextHandler > xRet;
413 switch ( aElementToken )
415 case NMSP_PPT|XML_cTn:
416 xRet.set( new CommonTimeNodeContext( *this, aElementToken, xAttribs, mpNode ) );
417 break;
418 case NMSP_PPT|XML_nextCondLst:
419 xRet.set( new CondListContext( *this, aElementToken, xAttribs, mpNode,
420 mpNode->getNextCondition() ) );
421 break;
422 case NMSP_PPT|XML_prevCondLst:
423 xRet.set( new CondListContext( *this, aElementToken, xAttribs, mpNode,
424 mpNode->getPrevCondition() ) );
425 break;
426 default:
427 break;
430 if( !xRet.is() )
431 xRet.set( this );
433 return xRet;
435 private:
436 bool mbConcurrent;
437 sal_Int32 mnNextAc, mnPrevAc;
441 /** CT_TLTimeNodeParallel
442 * CT_TLTimeNodeExclusive
444 class ParallelExclTimeNodeContext
445 : public TimeNodeContext
447 public:
448 ParallelExclTimeNodeContext( ContextHandler& rParent, sal_Int32 aElement,
449 const Reference< XFastAttributeList >& xAttribs,
450 const TimeNodePtr & pNode )
451 : TimeNodeContext( rParent, aElement, xAttribs, pNode )
455 virtual Reference< XFastContextHandler > SAL_CALL createFastChildContext( ::sal_Int32 aElementToken,
456 const Reference< XFastAttributeList >& xAttribs )
457 throw ( SAXException, RuntimeException )
459 Reference< XFastContextHandler > xRet;
461 switch ( aElementToken )
463 case NMSP_PPT|XML_cTn:
464 xRet.set( new CommonTimeNodeContext( *this, aElementToken, xAttribs, mpNode ) );
465 break;
466 default:
467 break;
470 if( !xRet.is() )
471 xRet.set( this );
473 return xRet;
476 protected:
481 /** CT_TLAnimateColorBehavior */
482 class AnimColorContext
483 : public TimeNodeContext
485 public:
486 AnimColorContext( ContextHandler& rParent, sal_Int32 aElement,
487 const Reference< XFastAttributeList >& xAttribs,
488 const TimeNodePtr & pNode ) throw()
489 : TimeNodeContext( rParent, aElement, xAttribs, pNode )
490 // ST_TLAnimateColorSpace ( XML_rgb, XML_hsl }
491 , mnColorSpace( xAttribs->getOptionalValueToken( XML_clrSpc, 0 ) )
492 // ST_TLAnimateColorDirection { XML_cw, XML_ccw }
493 , mnDir( xAttribs->getOptionalValueToken( XML_dir, 0 ) )
494 , mbHasByColor( false )
495 , m_byColor( AnimationColorSpace::RGB, 0, 0, 0)
498 ~AnimColorContext() throw()
502 virtual void SAL_CALL endFastElement( sal_Int32 aElement ) throw ( SAXException, RuntimeException)
504 //xParentNode
505 if( aElement == mnElement )
507 NodePropertyMap & pProps(mpNode->getNodeProperties());
508 pProps[ NP_DIRECTION ] = makeAny( mnDir == XML_cw );
509 pProps[ NP_COLORINTERPOLATION ] = makeAny( mnColorSpace == XML_hsl ? AnimationColorSpace::HSL : AnimationColorSpace::RGB );
510 if( maToClr.isUsed() )
512 mpNode->setTo( Any( maToClr.getColor( getFilter() ) ) );
514 if( maFromClr.isUsed() )
516 mpNode->setFrom( Any( maFromClr.getColor( getFilter() ) ) );
518 if( mbHasByColor )
520 mpNode->setBy( Any ( m_byColor.get() ) );
527 virtual Reference< XFastContextHandler > SAL_CALL createFastChildContext( ::sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs ) throw ( SAXException, RuntimeException )
529 Reference< XFastContextHandler > xRet;
531 switch ( aElementToken )
533 case NMSP_PPT|XML_hsl:
534 // CT_TLByHslColorTransform
536 if( mbHasByColor )
538 m_byColor.colorSpace = AnimationColorSpace::HSL;
539 m_byColor.one = xAttribs->getOptionalValue( XML_h ).toInt32( );
540 m_byColor.two = xAttribs->getOptionalValue( XML_s ).toInt32( );
541 m_byColor.three = xAttribs->getOptionalValue( XML_l ).toInt32( );
543 xRet.set(this);
544 break;
546 case NMSP_PPT|XML_rgb:
548 if( mbHasByColor )
550 // CT_TLByRgbColorTransform
551 m_byColor.colorSpace = AnimationColorSpace::RGB;
552 m_byColor.one = xAttribs->getOptionalValue( XML_r ).toInt32();
553 m_byColor.two = xAttribs->getOptionalValue( XML_g ).toInt32();
554 m_byColor.three = xAttribs->getOptionalValue( XML_b ).toInt32();
556 xRet.set(this);
557 break;
559 case NMSP_PPT|XML_by:
560 // CT_TLByAnimateColorTransform
561 mbHasByColor = true;
562 xRet.set(this);
563 break;
564 case NMSP_PPT|XML_cBhvr:
565 xRet.set( new CommonBehaviorContext ( *this, xAttribs, mpNode ) );
566 break;
567 case NMSP_PPT|XML_to:
568 // CT_Color
569 xRet.set( new ColorContext( *this, maToClr ) );
570 break;
571 case NMSP_PPT|XML_from:
572 // CT_Color
573 xRet.set( new ColorContext( *this, maFromClr ) );
574 break;
576 default:
577 break;
580 if( !xRet.is() )
581 xRet.set( this );
583 return xRet;
587 private:
588 sal_Int32 mnColorSpace;
589 sal_Int32 mnDir;
590 bool mbHasByColor;
591 AnimColor m_byColor;
592 oox::drawingml::Color maToClr;
593 oox::drawingml::Color maFromClr;
597 /** CT_TLAnimateBehavior */
598 class AnimContext
599 : public TimeNodeContext
601 public:
602 AnimContext( ContextHandler& rParent, sal_Int32 aElement,
603 const Reference< XFastAttributeList >& xAttribs,
604 const TimeNodePtr & pNode ) throw()
605 : TimeNodeContext( rParent, aElement, xAttribs, pNode )
607 NodePropertyMap & aProps( pNode->getNodeProperties() );
608 sal_Int32 nCalcMode = xAttribs->getOptionalValueToken( XML_calcmode, 0 );
609 if(nCalcMode)
611 sal_Int16 nEnum = 0;
612 switch(nCalcMode)
614 case XML_discrete:
615 nEnum = AnimationCalcMode::DISCRETE;
616 break;
617 case XML_lin:
618 nEnum = AnimationCalcMode::LINEAR;
619 break;
620 case XML_fmla:
621 default:
622 // TODO what value is good ?
623 nEnum = AnimationCalcMode::DISCRETE;
624 break;
626 aProps[ NP_CALCMODE ] = makeAny(nEnum);
628 OUString aStr;
629 aStr = xAttribs->getOptionalValue( XML_from );
630 if( aStr.getLength() )
632 pNode->setFrom( makeAny( aStr ) );
634 aStr = xAttribs->getOptionalValue( XML_by );
635 if( aStr.getLength() )
637 pNode->setBy( makeAny( aStr ) );
639 aStr = xAttribs->getOptionalValue( XML_to );
640 if( aStr.getLength() )
642 pNode->setTo( makeAny( aStr ) );
644 mnValueType = xAttribs->getOptionalValueToken( XML_valueType, 0 );
648 ~AnimContext() throw ()
650 ::std::list< TimeAnimationValue >::iterator iter, end;
651 int nKeyTimes = maTavList.size();
652 if( nKeyTimes > 0)
654 int i;
655 Sequence< double > aKeyTimes( nKeyTimes );
656 Sequence< Any > aValues( nKeyTimes );
658 NodePropertyMap & aProps( mpNode->getNodeProperties() );
659 end = maTavList.end();
660 for(iter = maTavList.begin(), i=0; iter != end; iter++,i++)
662 // TODO what to do if it is Timing_INFINITE ?
663 Any aTime = GetTimeAnimateValueTime( iter->msTime );
664 aTime >>= aKeyTimes[i];
665 aValues[i] = iter->maValue;
667 OUString aTest;
668 iter->maValue >>= aTest;
669 if( aTest.getLength() != 0 )
671 aValues[i] = iter->maValue;
673 else
675 aProps[ NP_FORMULA ] <<= iter->msFormula;
678 aProps[ NP_VALUES ] <<= aValues;
679 aProps[ NP_KEYTIMES ] <<= aKeyTimes;
684 virtual Reference< XFastContextHandler > SAL_CALL createFastChildContext( ::sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs ) throw ( SAXException, RuntimeException )
686 Reference< XFastContextHandler > xRet;
688 switch ( aElementToken )
690 case NMSP_PPT|XML_cBhvr:
691 xRet.set( new CommonBehaviorContext ( *this, xAttribs, mpNode ) );
692 break;
693 case NMSP_PPT|XML_tavLst:
694 xRet.set( new TimeAnimValueListContext ( *this, xAttribs, maTavList ) );
695 break;
696 default:
697 break;
700 if( !xRet.is() )
701 xRet.set( this );
703 return xRet;
705 private:
706 sal_Int32 mnValueType;
707 TimeAnimationValueList maTavList;
711 /** CT_TLAnimateScaleBehavior */
712 class AnimScaleContext
713 : public TimeNodeContext
715 public:
716 AnimScaleContext( ContextHandler& rParent, sal_Int32 aElement,
717 const Reference< XFastAttributeList >& xAttribs,
718 const TimeNodePtr & pNode ) throw()
719 : TimeNodeContext( rParent, aElement, xAttribs, pNode )
720 , mbZoomContents( false )
722 AttributeList attribs( xAttribs );
723 // TODO what to do with mbZoomContents
724 mbZoomContents = attribs.getBool( XML_zoomContents, false );
725 pNode->getNodeProperties()[ NP_TRANSFORMTYPE ]
726 = makeAny((sal_Int16)AnimationTransformType::SCALE);
729 ~AnimScaleContext( ) throw( )
733 virtual void SAL_CALL endFastElement( sal_Int32 aElement ) throw ( SAXException, RuntimeException)
735 if( aElement == mnElement )
737 if( maTo.hasValue() )
739 mpNode->setTo( maTo );
741 if( maBy.hasValue() )
743 mpNode->setBy( maBy );
745 if( maFrom.hasValue() )
747 mpNode->setFrom( maFrom );
752 virtual Reference< XFastContextHandler > SAL_CALL createFastChildContext( ::sal_Int32 aElementToken,
753 const Reference< XFastAttributeList >& xAttribs )
754 throw ( SAXException, RuntimeException )
756 Reference< XFastContextHandler > xRet;
758 switch ( aElementToken )
760 case NMSP_PPT|XML_cBhvr:
761 xRet.set( new CommonBehaviorContext ( *this, xAttribs, mpNode ) );
762 break;
763 case NMSP_PPT|XML_to:
765 // CT_TLPoint
766 Point p = GetPointPercent( xAttribs );
767 maTo <<= p.X;
768 maTo <<= p.Y;
769 break;
771 case NMSP_PPT|XML_from:
773 // CT_TLPoint
774 Point p = GetPointPercent( xAttribs );
775 maFrom <<= p.X;
776 maFrom <<= p.Y;
777 break;
779 case NMSP_PPT|XML_by:
781 // CT_TLPoint
782 Point p = GetPointPercent( xAttribs );
783 maBy <<= p.X;
784 maBy <<= p.Y;
785 break;
787 default:
788 break;
791 if( !xRet.is() )
792 xRet.set( this );
794 return xRet;
796 private:
797 Any maBy;
798 Any maFrom;
799 Any maTo;
800 bool mbZoomContents;
804 /** CT_TLAnimateRotationBehavior */
805 class AnimRotContext
806 : public TimeNodeContext
808 public:
809 AnimRotContext( ContextHandler& rParent, sal_Int32 aElement,
810 const Reference< XFastAttributeList >& xAttribs,
811 const TimeNodePtr & pNode ) throw()
812 : TimeNodeContext( rParent, aElement, xAttribs, pNode )
814 AttributeList attribs( xAttribs );
816 pNode->getNodeProperties()[ NP_TRANSFORMTYPE ]
817 = makeAny((sal_Int16)AnimationTransformType::ROTATE);
818 // TODO make sure the units are OK
819 if(attribs.hasAttribute( XML_by ) )
821 sal_Int32 nBy = attribs.getInteger( XML_by, 0 );
822 pNode->setBy( makeAny( nBy ) );
824 if(attribs.hasAttribute( XML_from ) )
826 sal_Int32 nFrom = attribs.getInteger( XML_from, 0 );
827 pNode->setFrom( makeAny( nFrom ) );
829 if(attribs.hasAttribute( XML_to ) )
831 sal_Int32 nTo = attribs.getInteger( XML_to, 0 );
832 pNode->setTo( makeAny( nTo ) );
836 ~AnimRotContext( ) throw( )
840 virtual Reference< XFastContextHandler > SAL_CALL createFastChildContext( ::sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs ) throw ( SAXException, RuntimeException )
842 Reference< XFastContextHandler > xRet;
844 switch ( aElementToken )
846 case NMSP_PPT|XML_cBhvr:
847 xRet.set( new CommonBehaviorContext ( *this, xAttribs, mpNode ) );
848 break;
849 default:
850 break;
853 if( !xRet.is() )
854 xRet.set( this );
856 return xRet;
862 /** CT_TLAnimateMotionBehavior */
863 class AnimMotionContext
864 : public TimeNodeContext
866 public:
867 AnimMotionContext( ContextHandler& rParent, sal_Int32 aElement,
868 const Reference< XFastAttributeList >& xAttribs,
869 const TimeNodePtr & pNode ) throw()
870 : TimeNodeContext( rParent, aElement, xAttribs, pNode )
872 pNode->getNodeProperties()[ NP_TRANSFORMTYPE ]
873 = makeAny((sal_Int16)AnimationTransformType::TRANSLATE);
875 AttributeList attribs( xAttribs );
876 // ST_TLAnimateMotionBehaviorOrigin { parent, layour }
877 sal_Int32 nOrigin = xAttribs->getOptionalValueToken( XML_origin, 0 );
878 if( nOrigin != 0 )
880 switch(nOrigin)
882 case XML_layout:
883 case XML_parent:
884 break;
886 // TODO
889 OUString aStr = xAttribs->getOptionalValue( XML_path );
890 aStr = aStr.replace( 'E', ' ' );
891 aStr = aStr.trim();
892 pNode->getNodeProperties()[ NP_PATH ] = makeAny(aStr);
894 // ST_TLAnimateMotionPathEditMode{ fixed, relative }
895 mnPathEditMode = xAttribs->getOptionalValueToken( XML_pathEditMode, 0 );
896 msPtsTypes = xAttribs->getOptionalValue( XML_ptsTypes );
897 mnAngle = attribs.getInteger( XML_rAng, 0 );
898 // TODO make sure the units are right. Likely not.
901 ~AnimMotionContext( ) throw()
906 virtual Reference< XFastContextHandler > SAL_CALL createFastChildContext( ::sal_Int32 aElementToken,
907 const Reference< XFastAttributeList >& xAttribs )
908 throw ( SAXException, RuntimeException )
910 Reference< XFastContextHandler > xRet;
912 switch ( aElementToken )
914 case NMSP_PPT|XML_cBhvr:
915 xRet.set( new CommonBehaviorContext ( *this, xAttribs, mpNode ) );
916 break;
917 case NMSP_PPT|XML_to:
919 // CT_TLPoint
920 Point p = GetPointPercent( xAttribs );
921 Any rAny;
922 rAny <<= p.X;
923 rAny <<= p.Y;
924 mpNode->setTo( rAny );
925 break;
927 case NMSP_PPT|XML_from:
929 // CT_TLPoint
930 Point p = GetPointPercent( xAttribs );
931 Any rAny;
932 rAny <<= p.X;
933 rAny <<= p.Y;
934 mpNode->setFrom( rAny );
935 break;
937 case NMSP_PPT|XML_by:
939 // CT_TLPoint
940 Point p = GetPointPercent( xAttribs );
941 Any rAny;
942 rAny <<= p.X;
943 rAny <<= p.Y;
944 mpNode->setBy( rAny );
945 break;
947 case NMSP_PPT|XML_rCtr:
949 // CT_TLPoint
950 Point p = GetPointPercent( xAttribs );
951 // TODO push
952 break;
954 default:
955 break;
958 if( !xRet.is() )
959 xRet.set( this );
961 return xRet;
963 private:
964 OUString msPtsTypes;
965 sal_Int32 mnPathEditMode;
966 sal_Int32 mnAngle;
970 /** CT_TLAnimateEffectBehavior */
971 class AnimEffectContext
972 : public TimeNodeContext
974 public:
975 AnimEffectContext( ContextHandler& rParent, sal_Int32 aElement,
976 const Reference< XFastAttributeList >& xAttribs,
977 const TimeNodePtr & pNode ) throw()
978 : TimeNodeContext( rParent, aElement, xAttribs, pNode )
980 sal_Int32 nDir = xAttribs->getOptionalValueToken( XML_transition, 0 );
981 OUString sFilter = xAttribs->getOptionalValue( XML_filter );
982 // TODO
983 // OUString sPrList = xAttribs->getOptionalValue( XML_prLst );
985 if( sFilter.getLength() )
987 SlideTransition aFilter( sFilter );
988 aFilter.setMode( nDir == XML_out ? false : true );
989 pNode->setTransitionFilter( aFilter );
994 ~AnimEffectContext( ) throw()
999 virtual Reference< XFastContextHandler > SAL_CALL createFastChildContext( ::sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs ) throw ( SAXException, RuntimeException )
1001 Reference< XFastContextHandler > xRet;
1003 switch ( aElementToken )
1005 case NMSP_PPT|XML_cBhvr:
1006 xRet.set( new CommonBehaviorContext ( *this, xAttribs, mpNode ) );
1007 break;
1008 case NMSP_PPT|XML_progress:
1009 xRet.set( new AnimVariantContext( *this, aElementToken, maProgress ) );
1010 // TODO handle it.
1011 break;
1012 default:
1013 break;
1016 if( !xRet.is() )
1017 xRet.set( this );
1019 return xRet;
1021 private:
1022 Any maProgress;
1023 OUString msFilter;
1024 OUString msPrList;
1029 TimeNodeContext * TimeNodeContext::makeContext(
1030 ContextHandler& rParent, sal_Int32 aElement,
1031 const Reference< XFastAttributeList >& xAttribs,
1032 const TimeNodePtr & pNode )
1034 TimeNodeContext *pCtx = NULL;
1035 switch( aElement )
1037 case NMSP_PPT|XML_animClr:
1038 pCtx = new AnimColorContext( rParent, aElement, xAttribs, pNode );
1039 break;
1040 case NMSP_PPT|XML_par:
1041 pCtx = new ParallelExclTimeNodeContext( rParent, aElement, xAttribs, pNode );
1042 break;
1043 case NMSP_PPT|XML_seq:
1044 pCtx = new SequenceTimeNodeContext( rParent, aElement, xAttribs, pNode );
1045 break;
1046 case NMSP_PPT|XML_excl:
1047 pCtx = new ParallelExclTimeNodeContext( rParent, aElement, xAttribs, pNode );
1048 break;
1049 case NMSP_PPT|XML_anim:
1050 pCtx = new AnimContext ( rParent, aElement, xAttribs, pNode );
1051 break;
1052 case NMSP_PPT|XML_animEffect:
1053 pCtx = new AnimEffectContext( rParent, aElement, xAttribs, pNode );
1054 break;
1055 case NMSP_PPT|XML_animMotion:
1056 pCtx = new AnimMotionContext( rParent, aElement, xAttribs, pNode );
1057 break;
1058 case NMSP_PPT|XML_animRot:
1059 pCtx = new AnimRotContext( rParent, aElement, xAttribs, pNode );
1060 break;
1061 case NMSP_PPT|XML_animScale:
1062 pCtx = new AnimScaleContext( rParent, aElement, xAttribs, pNode );
1063 break;
1064 case NMSP_PPT|XML_cmd:
1065 pCtx = new CmdTimeNodeContext( rParent, aElement, xAttribs, pNode );
1066 break;
1067 case NMSP_PPT|XML_set:
1068 pCtx = new SetTimeNodeContext( rParent, aElement, xAttribs, pNode );
1069 break;
1070 case NMSP_PPT|XML_audio:
1071 case NMSP_PPT|XML_video:
1072 pCtx = new MediaNodeContext( rParent, aElement, xAttribs, pNode );
1073 break;
1074 default:
1075 break;
1077 return pCtx;
1081 TimeNodeContext::TimeNodeContext( ContextHandler& rParent, sal_Int32 aElement,
1082 const Reference< XFastAttributeList >& /*xAttribs*/,
1083 const TimeNodePtr & pNode ) throw()
1084 : ContextHandler( rParent )
1085 , mnElement( aElement )
1086 , mpNode( pNode )
1091 TimeNodeContext::~TimeNodeContext( ) throw()
1097 TimeNodeListContext::TimeNodeListContext( ContextHandler& rParent, TimeNodePtrList & aList )
1098 throw()
1099 : ContextHandler( rParent )
1100 , maList( aList )
1105 TimeNodeListContext::~TimeNodeListContext( ) throw()
1110 Reference< XFastContextHandler > SAL_CALL TimeNodeListContext::createFastChildContext( ::sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs ) throw (SAXException, RuntimeException)
1112 Reference< XFastContextHandler > xRet;
1114 sal_Int16 nNodeType;
1116 switch( aElementToken )
1118 case NMSP_PPT|XML_par:
1119 nNodeType = AnimationNodeType::PAR;
1120 break;
1121 case NMSP_PPT|XML_seq:
1122 nNodeType = AnimationNodeType::SEQ;
1123 break;
1124 case NMSP_PPT|XML_excl:
1125 // TODO pick the right type. We choose parallel for now as
1126 // there does not seem to be an "Exclusive"
1127 nNodeType = AnimationNodeType::PAR;
1128 break;
1129 case NMSP_PPT|XML_anim:
1130 nNodeType = AnimationNodeType::ANIMATE;
1131 break;
1132 case NMSP_PPT|XML_animClr:
1133 nNodeType = AnimationNodeType::ANIMATECOLOR;
1134 break;
1135 case NMSP_PPT|XML_animEffect:
1136 nNodeType = AnimationNodeType::TRANSITIONFILTER;
1137 break;
1138 case NMSP_PPT|XML_animMotion:
1139 nNodeType = AnimationNodeType::ANIMATEMOTION;
1140 break;
1141 case NMSP_PPT|XML_animRot:
1142 case NMSP_PPT|XML_animScale:
1143 nNodeType = AnimationNodeType::ANIMATETRANSFORM;
1144 break;
1145 case NMSP_PPT|XML_cmd:
1146 nNodeType = AnimationNodeType::COMMAND;
1147 break;
1148 case NMSP_PPT|XML_set:
1149 nNodeType = AnimationNodeType::SET;
1150 break;
1151 case NMSP_PPT|XML_audio:
1152 nNodeType = AnimationNodeType::AUDIO;
1153 break;
1154 case NMSP_PPT|XML_video:
1155 nNodeType = AnimationNodeType::AUDIO;
1156 OSL_TRACE( "OOX: video requested, gave Audio instead" );
1157 break;
1159 default:
1160 nNodeType = AnimationNodeType::CUSTOM;
1161 OSL_TRACE( "OOX: uhandled token %x", aElementToken );
1162 break;
1165 TimeNodePtr pNode(new TimeNode(nNodeType));
1166 maList.push_back( pNode );
1167 ContextHandler * pContext = TimeNodeContext::makeContext( *this, aElementToken, xAttribs, pNode );
1168 xRet.set( pContext ? pContext : this );
1170 return xRet;