LCOV - code coverage report
Current view: top level - libreoffice/oox/source/ppt - timenodelistcontext.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 32 419 7.6 %
Date: 2012-12-17 Functions: 13 60 21.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : #include "oox/ppt/timenodelistcontext.hxx"
      21             : 
      22             : #include "comphelper/anytostring.hxx"
      23             : #include "cppuhelper/exc_hlp.hxx"
      24             : #include <osl/diagnose.h>
      25             : #include <rtl/math.hxx>
      26             : 
      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>
      40             : 
      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"
      46             : 
      47             : #include "animvariantcontext.hxx"
      48             : #include "commonbehaviorcontext.hxx"
      49             : #include "conditioncontext.hxx"
      50             : #include "commontimenodecontext.hxx"
      51             : #include "timeanimvaluecontext.hxx"
      52             : #include "animationtypes.hxx"
      53             : 
      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;
      63             : 
      64             : using ::rtl::OUString;
      65             : 
      66             : namespace oox { namespace ppt {
      67             : 
      68             :     struct AnimColor
      69             :     {
      70           0 :         AnimColor(sal_Int16 cs, sal_Int32 o, sal_Int32 t, sal_Int32 th )
      71           0 :             : colorSpace( cs ), one( o ), two( t ), three( th )
      72             :             {
      73           0 :             }
      74             : 
      75           0 :         sal_Int32 get()
      76             :             {
      77             :                 sal_Int32 nColor;
      78             : 
      79           0 :                 switch( colorSpace )
      80             :                 {
      81             :                 case AnimationColorSpace::HSL:
      82             :                     nColor = ( ( ( one * 128 ) / 360 ) & 0xff ) << 16
      83             :                         | ( ( ( two * 128 ) / 1000 ) & 0xff ) << 8
      84           0 :                         | ( ( ( three * 128 ) / 1000 )  & 0xff );
      85           0 :                     break;
      86             :                 case AnimationColorSpace::RGB:
      87             :                     nColor = ( ( ( one * 128 ) / 1000 ) & 0xff ) << 16
      88             :                         | ( ( ( two * 128 ) / 1000 ) & 0xff ) << 8
      89           0 :                         | ( ( ( three * 128 ) / 1000 )  & 0xff );
      90           0 :                     break;
      91             :                 default:
      92           0 :                     nColor = 0;
      93           0 :                     break;
      94             :                 }
      95           0 :                 return  nColor;
      96             :             }
      97             : 
      98             :         sal_Int16 colorSpace;
      99             :         sal_Int32 one;
     100             :         sal_Int32 two;
     101             :         sal_Int32 three;
     102             :     };
     103             : 
     104             : 
     105             :     /** CT_TLMediaNodeAudio
     106             :             CT_TLMediaNodeVideo */
     107           0 :     class MediaNodeContext
     108             :         : public TimeNodeContext
     109             :     {
     110             :     public:
     111           0 :         MediaNodeContext( FragmentHandler2& rParent, sal_Int32  aElement,
     112             :                             const Reference< XFastAttributeList >& xAttribs,
     113             :                             const TimeNodePtr & pNode )
     114             :             : TimeNodeContext( rParent, aElement, xAttribs, pNode )
     115             :                 , mbIsNarration( false )
     116           0 :                 , mbFullScrn( false )
     117             :             {
     118           0 :                 AttributeList attribs( xAttribs );
     119             : 
     120           0 :                 switch( aElement )
     121             :                 {
     122             :                 case PPT_TOKEN( audio ):
     123           0 :                     mbIsNarration = attribs.getBool( XML_isNarration, false );
     124           0 :                     break;
     125             :                 case PPT_TOKEN( video ):
     126           0 :                     mbFullScrn = attribs.getBool( XML_fullScrn, false );
     127           0 :                     break;
     128             :                 default:
     129           0 :                     break;
     130           0 :                 }
     131           0 :             }
     132             : 
     133           0 :         virtual void onEndElement()
     134             :             {
     135           0 :                 sal_Int32 aElement = getCurrentElement();
     136             :                 if( aElement == PPT_TOKEN( audio ) )
     137             :                 {
     138             :                     // TODO deal with mbIsNarration
     139             :                 }
     140             :                 else if( aElement == PPT_TOKEN( video ) )
     141             :                 {
     142             :                     // TODO deal with mbFullScrn
     143             :                 }
     144           0 :             }
     145             : 
     146           0 :         virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
     147             :             {
     148           0 :                 switch ( aElementToken )
     149             :                 {
     150             :                 case PPT_TOKEN( cBhvr ):
     151           0 :                     return new CommonBehaviorContext ( *this, rAttribs.getFastAttributeList(), mpNode );
     152             :                     break;
     153             :                 default:
     154           0 :                     break;
     155             :                 }
     156             : 
     157           0 :                 return this;
     158             :             }
     159             : 
     160             :     private:
     161             :         bool mbIsNarration;
     162             :         bool mbFullScrn;
     163             :     };
     164             : 
     165             : 
     166             :     /** CT_TLSetBehavior
     167             :      */
     168             :     class SetTimeNodeContext
     169             :         : public TimeNodeContext
     170             :     {
     171             :     public:
     172           0 :         SetTimeNodeContext( FragmentHandler2& rParent, sal_Int32  aElement,
     173             :                             const Reference< XFastAttributeList >& xAttribs,
     174             :                             const TimeNodePtr & pNode )
     175           0 :             : TimeNodeContext( rParent, aElement, xAttribs, pNode )
     176             :             {
     177             : 
     178           0 :             }
     179             : 
     180           0 :         ~SetTimeNodeContext() throw ()
     181           0 :             {
     182           0 :                 if( maTo.hasValue() )
     183             :                 {
     184             :                     // TODO
     185             :                     // HACK !!! discard and refactor
     186           0 :                     OUString aString;
     187           0 :                     if( maTo >>= aString )
     188             :                     {
     189             :                         OSL_TRACE( "Magic conversion %s", OUSTRING_TO_CSTR( aString ) );
     190           0 :                         maTo = makeAny( aString == "visible" ? sal_True : sal_False );
     191           0 :                         if( !maTo.has<sal_Bool>() )
     192             :                             OSL_TRACE( "conversion failed" );
     193             :                     }
     194           0 :                     mpNode->setTo( maTo );
     195             :                 }
     196             : 
     197           0 :             }
     198             : 
     199           0 :             virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
     200             :             {
     201           0 :                 switch ( aElementToken )
     202             :                 {
     203             :                 case PPT_TOKEN( cBhvr ):
     204           0 :                     return new CommonBehaviorContext ( *this, rAttribs.getFastAttributeList(), mpNode );
     205             :                 case PPT_TOKEN( to ):
     206             :                     // CT_TLAnimVariant
     207           0 :                     return new AnimVariantContext( *this, aElementToken, maTo );
     208             :                 default:
     209           0 :                     break;
     210             :                 }
     211             : 
     212           0 :                 return this;
     213             :             }
     214             :     private:
     215             :         Any  maTo;
     216             :     };
     217             : 
     218             :     /** CT_TLCommandBehavior
     219             :      */
     220             :     class CmdTimeNodeContext
     221             :         : public TimeNodeContext
     222             :     {
     223             :     public:
     224           0 :         CmdTimeNodeContext( FragmentHandler2& rParent, sal_Int32  aElement,
     225             :                             const Reference< XFastAttributeList >& xAttribs,
     226             :                             const TimeNodePtr & pNode )
     227             :             : TimeNodeContext( rParent, aElement, xAttribs, pNode )
     228           0 :                 , maType(0)
     229             :             {
     230           0 :                 switch ( aElement )
     231             :                 {
     232             :                 case PPT_TOKEN( cmd ):
     233           0 :                     msCommand = xAttribs->getOptionalValue( XML_cmd );
     234           0 :                     maType = xAttribs->getOptionalValueToken( XML_type, 0 );
     235           0 :                     break;
     236             :                 default:
     237           0 :                     break;
     238             :                 }
     239           0 :             }
     240             : 
     241           0 :         ~CmdTimeNodeContext() throw ()
     242           0 :             {
     243           0 :             }
     244             : 
     245           0 :         virtual void onEndElement()
     246             :             {
     247           0 :                 if( isCurrentElement( PPT_TOKEN( cmd ) ) )
     248             :                 {
     249             :                     try {
     250             :                         // see sd/source/filter/ppt/pptinanimations.cxx
     251             :                         // in AnimationImporter::importCommandContainer()
     252             :                         // REFACTOR?
     253             :                         // a good chunk of this code has been copied verbatim *sigh*
     254           0 :                         sal_Int16 nCommand = EffectCommands::CUSTOM;
     255           0 :                         NamedValue aParamValue;
     256             : 
     257           0 :                         switch( maType )
     258             :                         {
     259             :                         case XML_verb:
     260           0 :                             aParamValue.Name = OUString(RTL_CONSTASCII_USTRINGPARAM("Verb"));
     261             :                             // TODO make sure msCommand has what we want
     262           0 :                             aParamValue.Value <<= msCommand.toInt32();
     263           0 :                             nCommand = EffectCommands::VERB;
     264           0 :                             break;
     265             :                         case XML_evt:
     266             :                         case XML_call:
     267           0 :                             if ( msCommand == "onstopaudio" )
     268             :                             {
     269           0 :                                 nCommand = EffectCommands::STOPAUDIO;
     270             :                             }
     271           0 :                             else if ( msCommand == "play" )
     272             :                             {
     273           0 :                                 nCommand = EffectCommands::PLAY;
     274             :                             }
     275           0 :                             else if( msCommand.compareToAscii( RTL_CONSTASCII_STRINGPARAM("playFrom") ) == 0 )
     276             :                             {
     277           0 :                                 const OUString aMediaTime( msCommand.copy( 9, msCommand.getLength() - 10 ) );
     278             :                                 rtl_math_ConversionStatus eStatus;
     279           0 :                                 double fMediaTime = ::rtl::math::stringToDouble( aMediaTime, (sal_Unicode)('.'), (sal_Unicode)(','), &eStatus, NULL );
     280           0 :                                 if( eStatus == rtl_math_ConversionStatus_Ok )
     281             :                                 {
     282           0 :                                     aParamValue.Name = CREATE_OUSTRING("MediaTime");
     283           0 :                                     aParamValue.Value <<= fMediaTime;
     284             :                                 }
     285           0 :                                 nCommand = EffectCommands::PLAY;
     286             :                             }
     287           0 :                             else if ( msCommand == "togglePause" )
     288             :                             {
     289           0 :                                 nCommand = EffectCommands::TOGGLEPAUSE;
     290             :                             }
     291           0 :                             else if ( msCommand == "stop" )
     292             :                             {
     293           0 :                                 nCommand = EffectCommands::STOP;
     294             :                             }
     295           0 :                             break;
     296             :                         }
     297           0 :                         mpNode->getNodeProperties()[ NP_COMMAND ] = makeAny((sal_Int16)nCommand);
     298           0 :                         if( nCommand == EffectCommands::CUSTOM )
     299             :                         {
     300             :                             OSL_TRACE("OOX: CmdTimeNodeContext::endFastElement(), unknown command!");
     301           0 :                             aParamValue.Name = CREATE_OUSTRING("UserDefined");
     302           0 :                             aParamValue.Value <<= msCommand;
     303             :                         }
     304           0 :                         if( aParamValue.Value.hasValue() )
     305             :                         {
     306           0 :                             Sequence< NamedValue > aParamSeq( &aParamValue, 1 );
     307           0 :                             mpNode->getNodeProperties()[ NP_PARAMETER ] = makeAny( aParamSeq );
     308           0 :                         }
     309             :                     }
     310           0 :                     catch( RuntimeException& )
     311             :                     {
     312             :                         OSL_TRACE( "OOX: Exception in CmdTimeNodeContext::endFastElement()" );
     313             :                     }
     314             :                 }
     315           0 :             }
     316             : 
     317             : 
     318           0 :         virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
     319             :             {
     320           0 :                 switch ( aElementToken )
     321             :                 {
     322             :                 case PPT_TOKEN( cBhvr ):
     323           0 :                     return new CommonBehaviorContext ( *this, rAttribs.getFastAttributeList(), mpNode );
     324             :                 default:
     325           0 :                     break;
     326             :                 }
     327             : 
     328           0 :                 return this;
     329             :             }
     330             : 
     331             :     private:
     332             :         OUString msCommand;
     333             :         sal_Int32 maType;
     334             :     };
     335             : 
     336             : 
     337             :     /** CT_TLTimeNodeSequence
     338             :      */
     339             :     class SequenceTimeNodeContext
     340             :         : public TimeNodeContext
     341             :     {
     342             :     public:
     343           0 :         SequenceTimeNodeContext( FragmentHandler2& rParent, sal_Int32  aElement,
     344             :                                  const Reference< XFastAttributeList >& xAttribs,
     345             :                                  const TimeNodePtr & pNode )
     346             :             : TimeNodeContext( rParent, aElement, xAttribs, pNode )
     347             :                 , mnNextAc(0)
     348           0 :                 , mnPrevAc(0)
     349             :             {
     350           0 :                 AttributeList attribs(xAttribs);
     351           0 :                 mbConcurrent = attribs.getBool( XML_concurrent, false );
     352             :                 // ST_TLNextActionType { none, seek }
     353           0 :                 mnNextAc = xAttribs->getOptionalValueToken( XML_nextAc, 0 );
     354             :                 // ST_TLPreviousActionType { none, skipTimed }
     355           0 :                 mnPrevAc = xAttribs->getOptionalValueToken( XML_prevAc, 0 );
     356           0 :             }
     357             : 
     358           0 :         ~SequenceTimeNodeContext() throw()
     359           0 :             {
     360           0 :             }
     361             : 
     362             : 
     363           0 :         virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
     364             :             {
     365           0 :                 switch ( aElementToken )
     366             :                 {
     367             :                 case PPT_TOKEN( cTn ):
     368           0 :                     return new CommonTimeNodeContext( *this, aElementToken, rAttribs.getFastAttributeList(), mpNode );
     369             :                 case PPT_TOKEN( nextCondLst ):
     370             :                     return new CondListContext( *this, aElementToken, rAttribs.getFastAttributeList(), mpNode,
     371           0 :                                                    mpNode->getNextCondition() );
     372             :                 case PPT_TOKEN( prevCondLst ):
     373             :                     return new CondListContext( *this, aElementToken, rAttribs.getFastAttributeList(), mpNode,
     374           0 :                                                    mpNode->getPrevCondition() );
     375             :                 default:
     376           0 :                     break;
     377             :                 }
     378             : 
     379           0 :                 return this;
     380             :             }
     381             :     private:
     382             :         bool mbConcurrent;
     383             :         sal_Int32 mnNextAc, mnPrevAc;
     384             :     };
     385             : 
     386             : 
     387             :     /** CT_TLTimeNodeParallel
     388             :      *  CT_TLTimeNodeExclusive
     389             :      */
     390          16 :     class ParallelExclTimeNodeContext
     391             :         : public TimeNodeContext
     392             :     {
     393             :     public:
     394           8 :         ParallelExclTimeNodeContext( FragmentHandler2& rParent, sal_Int32  aElement,
     395             :                                      const Reference< XFastAttributeList >& xAttribs,
     396             :                                      const TimeNodePtr & pNode )
     397           8 :             : TimeNodeContext( rParent, aElement, xAttribs, pNode )
     398             :             {
     399           8 :             }
     400             : 
     401           8 :         virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
     402             :             {
     403           8 :                 switch ( aElementToken )
     404             :                 {
     405             :                 case PPT_TOKEN( cTn ):
     406           8 :                     return new CommonTimeNodeContext( *this, aElementToken, rAttribs.getFastAttributeList(), mpNode );
     407             :                 default:
     408           0 :                     break;
     409             :                 }
     410             : 
     411           0 :                 return this;
     412             :             }
     413             : 
     414             :     protected:
     415             : 
     416             :     };
     417             : 
     418             : 
     419             :     /** CT_TLAnimateColorBehavior */
     420             :     class AnimColorContext
     421             :         : public TimeNodeContext
     422             :     {
     423             :     public:
     424           0 :         AnimColorContext( FragmentHandler2& rParent, sal_Int32  aElement,
     425             :                             const Reference< XFastAttributeList >& xAttribs,
     426             :                             const TimeNodePtr & pNode ) throw()
     427             :             : TimeNodeContext( rParent, aElement, xAttribs, pNode )
     428             :                 // ST_TLAnimateColorSpace ( XML_rgb, XML_hsl }
     429           0 :             , mnColorSpace( xAttribs->getOptionalValueToken( XML_clrSpc, 0 ) )
     430             :                 // ST_TLAnimateColorDirection { XML_cw, XML_ccw }
     431           0 :             , mnDir( xAttribs->getOptionalValueToken( XML_dir, 0 ) )
     432             :             , mbHasByColor( false )
     433           0 :             , m_byColor( AnimationColorSpace::RGB, 0, 0, 0)
     434             :             {
     435           0 :             }
     436           0 :         ~AnimColorContext() throw()
     437           0 :             {
     438           0 :             }
     439             : 
     440           0 :         virtual void onEndElement()
     441             :             {
     442             :                 //xParentNode
     443           0 :                 if( isCurrentElement( mnElement ) )
     444             :                 {
     445           0 :                     NodePropertyMap & pProps(mpNode->getNodeProperties());
     446           0 :                     pProps[ NP_DIRECTION ] = makeAny( mnDir == XML_cw );
     447           0 :                     pProps[ NP_COLORINTERPOLATION ] = makeAny( mnColorSpace == XML_hsl ? AnimationColorSpace::HSL : AnimationColorSpace::RGB );
     448           0 :                     const GraphicHelper& rGraphicHelper = getFilter().getGraphicHelper();
     449           0 :                     if( maToClr.isUsed() )
     450           0 :                         mpNode->setTo( Any( maToClr.getColor( rGraphicHelper ) ) );
     451           0 :                     if( maFromClr.isUsed() )
     452           0 :                         mpNode->setFrom( Any( maFromClr.getColor( rGraphicHelper ) ) );
     453           0 :                     if( mbHasByColor )
     454           0 :                         mpNode->setBy( Any ( m_byColor.get() ) );
     455             :                 }
     456           0 :             }
     457             : 
     458             : 
     459           0 :             virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
     460             :             {
     461           0 :                 switch ( aElementToken )
     462             :                 {
     463             :                 case PPT_TOKEN( hsl ):
     464             :                     // CT_TLByHslColorTransform
     465             :                 {
     466           0 :                     if( mbHasByColor )
     467             :                     {
     468           0 :                         m_byColor.colorSpace = AnimationColorSpace::HSL;
     469           0 :                         m_byColor.one = rAttribs.getInteger( XML_h, 0 );
     470           0 :                         m_byColor.two = rAttribs.getInteger( XML_s, 0 );
     471           0 :                         m_byColor.three = rAttribs.getInteger( XML_l, 0 );
     472             :                     }
     473           0 :                     return this;
     474             :                 }
     475             :                 case PPT_TOKEN( rgb ):
     476             :                 {
     477           0 :                     if( mbHasByColor )
     478             :                     {
     479             :                         // CT_TLByRgbColorTransform
     480           0 :                         m_byColor.colorSpace = AnimationColorSpace::RGB;
     481           0 :                         m_byColor.one = rAttribs.getInteger( XML_r, 0 );
     482           0 :                         m_byColor.two = rAttribs.getInteger( XML_g, 0 );
     483           0 :                         m_byColor.three = rAttribs.getInteger( XML_b, 0 );
     484             :                     }
     485           0 :                     return this;
     486             :                 }
     487             :                 case PPT_TOKEN( by ):
     488             :                     // CT_TLByAnimateColorTransform
     489           0 :                     mbHasByColor = true;
     490           0 :                     return this;
     491             :                 case PPT_TOKEN( cBhvr ):
     492           0 :                     return new CommonBehaviorContext ( *this, rAttribs.getFastAttributeList(), mpNode );
     493             :                 case PPT_TOKEN( to ):
     494             :                     // CT_Color
     495           0 :                     return new ColorContext( *this, maToClr );
     496             :                 case PPT_TOKEN( from ):
     497             :                     // CT_Color
     498           0 :                     return new ColorContext( *this, maFromClr );
     499             : 
     500             :                 default:
     501           0 :                     break;
     502             :                 }
     503             : 
     504           0 :                 return this;
     505             :             }
     506             : 
     507             : 
     508             :     private:
     509             :         sal_Int32 mnColorSpace;
     510             :         sal_Int32 mnDir;
     511             :         bool mbHasByColor;
     512             :         AnimColor m_byColor;
     513             :         oox::drawingml::Color maToClr;
     514             :         oox::drawingml::Color maFromClr;
     515             :     };
     516             : 
     517             : 
     518             :     /** CT_TLAnimateBehavior */
     519             :     class AnimContext
     520             :         : public TimeNodeContext
     521             :     {
     522             :     public:
     523           0 :         AnimContext( FragmentHandler2& rParent, sal_Int32  aElement,
     524             :                      const Reference< XFastAttributeList >& xAttribs,
     525             :                       const TimeNodePtr & pNode ) throw()
     526           0 :             : TimeNodeContext( rParent, aElement, xAttribs, pNode )
     527             :             {
     528           0 :                 NodePropertyMap & aProps( pNode->getNodeProperties() );
     529           0 :                 sal_Int32 nCalcMode = xAttribs->getOptionalValueToken( XML_calcmode, 0 );
     530           0 :                 if(nCalcMode)
     531             :                 {
     532           0 :                     sal_Int16 nEnum = 0;
     533           0 :                     switch(nCalcMode)
     534             :                     {
     535             :                     case XML_discrete:
     536           0 :                         nEnum = AnimationCalcMode::DISCRETE;
     537           0 :                         break;
     538             :                     case XML_lin:
     539           0 :                         nEnum = AnimationCalcMode::LINEAR;
     540           0 :                         break;
     541             :                     case XML_fmla:
     542             :                     default:
     543             :                         // TODO what value is good ?
     544           0 :                         nEnum = AnimationCalcMode::DISCRETE;
     545           0 :                         break;
     546             :                     }
     547           0 :                     aProps[ NP_CALCMODE ] = makeAny(nEnum);
     548             :                 }
     549           0 :                 OUString aStr;
     550           0 :                 aStr = xAttribs->getOptionalValue( XML_from );
     551           0 :                 if( !aStr.isEmpty() )
     552             :                 {
     553           0 :                     pNode->setFrom( makeAny( aStr ) );
     554             :                 }
     555           0 :                 aStr = xAttribs->getOptionalValue( XML_by );
     556           0 :                 if( !aStr.isEmpty() )
     557             :                 {
     558           0 :                     pNode->setBy( makeAny( aStr ) );
     559             :                 }
     560           0 :                 aStr = xAttribs->getOptionalValue( XML_to );
     561           0 :                 if( !aStr.isEmpty() )
     562             :                 {
     563           0 :                     pNode->setTo( makeAny( aStr ) );
     564             :                 }
     565           0 :                 mnValueType = xAttribs->getOptionalValueToken( XML_valueType, 0 );
     566           0 :             }
     567             : 
     568             : 
     569           0 :         ~AnimContext() throw ()
     570           0 :             {
     571           0 :                 ::std::list< TimeAnimationValue >::iterator iter, end;
     572           0 :                 int nKeyTimes = maTavList.size();
     573           0 :                 if( nKeyTimes > 0)
     574             :                 {
     575             :                     int i;
     576           0 :                     Sequence< double > aKeyTimes( nKeyTimes );
     577           0 :                     Sequence< Any > aValues( nKeyTimes );
     578             : 
     579           0 :                     NodePropertyMap & aProps( mpNode->getNodeProperties() );
     580           0 :                     end = maTavList.end();
     581           0 :                     for(iter = maTavList.begin(), i=0; iter != end; ++iter,++i)
     582             :                     {
     583             :                         // TODO what to do if it is Timing_INFINITE ?
     584           0 :                         Any aTime = GetTimeAnimateValueTime( iter->msTime );
     585           0 :                         aTime >>= aKeyTimes[i];
     586           0 :                         aValues[i] = iter->maValue;
     587             : 
     588           0 :                         OUString aTest;
     589           0 :                         iter->maValue >>= aTest;
     590           0 :                         if( !aTest.isEmpty() )
     591             :                         {
     592           0 :                             aValues[i] = iter->maValue;
     593             :                         }
     594             :                         else
     595             :                         {
     596           0 :                             aProps[ NP_FORMULA ] <<= iter->msFormula;
     597             :                         }
     598           0 :                     }
     599           0 :                     aProps[ NP_VALUES ] <<= aValues;
     600           0 :                     aProps[ NP_KEYTIMES ] <<= aKeyTimes;
     601             :                 }
     602           0 :             }
     603             : 
     604             : 
     605           0 :         virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
     606             :             {
     607           0 :                 switch ( aElementToken )
     608             :                 {
     609             :                 case PPT_TOKEN( cBhvr ):
     610           0 :                     return new CommonBehaviorContext ( *this, rAttribs.getFastAttributeList(), mpNode );
     611             :                     break;
     612             :                 case PPT_TOKEN( tavLst ):
     613           0 :                     return new TimeAnimValueListContext ( *this, rAttribs.getFastAttributeList(), maTavList );
     614             :                     break;
     615             :                 default:
     616           0 :                     break;
     617             :                 }
     618             : 
     619           0 :                 return this;
     620             :             }
     621             :     private:
     622             :         sal_Int32              mnValueType;
     623             :         TimeAnimationValueList maTavList;
     624             :     };
     625             : 
     626             : 
     627             :     /** CT_TLAnimateScaleBehavior */
     628             :     class AnimScaleContext
     629             :         : public TimeNodeContext
     630             :     {
     631             :     public:
     632           0 :         AnimScaleContext( FragmentHandler2& rParent, sal_Int32  aElement,
     633             :                             const Reference< XFastAttributeList >& xAttribs,
     634             :                             const TimeNodePtr & pNode ) throw()
     635             :             : TimeNodeContext( rParent, aElement, xAttribs, pNode )
     636           0 :                 , mbZoomContents( false )
     637             :             {
     638           0 :                 AttributeList attribs( xAttribs );
     639             :                 // TODO what to do with mbZoomContents
     640           0 :                 mbZoomContents = attribs.getBool( XML_zoomContents, false );
     641           0 :                 pNode->getNodeProperties()[ NP_TRANSFORMTYPE ]
     642           0 :                     = makeAny((sal_Int16)AnimationTransformType::SCALE);
     643           0 :             }
     644             : 
     645           0 :         ~AnimScaleContext( ) throw( )
     646           0 :             {
     647           0 :             }
     648             : 
     649           0 :         virtual void onEndElement()
     650             :             {
     651           0 :                 if( isCurrentElement( mnElement ) )
     652             :                 {
     653           0 :                     if( maTo.hasValue() )
     654             :                     {
     655           0 :                         mpNode->setTo( maTo );
     656             :                     }
     657           0 :                     if( maBy.hasValue() )
     658             :                     {
     659           0 :                         mpNode->setBy( maBy );
     660             :                     }
     661           0 :                     if( maFrom.hasValue() )
     662             :                     {
     663           0 :                         mpNode->setFrom( maFrom );
     664             :                     }
     665             :                 }
     666           0 :             }
     667             : 
     668           0 :         virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
     669             :             {
     670           0 :                 switch ( aElementToken )
     671             :                 {
     672             :                 case PPT_TOKEN( cBhvr ):
     673           0 :                     return new CommonBehaviorContext ( *this, rAttribs.getFastAttributeList(), mpNode );
     674             :                 case PPT_TOKEN( to ):
     675             :                 {
     676             :                     // CT_TLPoint
     677           0 :                     awt::Point p = GetPointPercent( rAttribs.getFastAttributeList() );
     678           0 :                     maTo <<= p.X;
     679           0 :                     maTo <<= p.Y;
     680           0 :                     return this;
     681             :                 }
     682             :                 case PPT_TOKEN( from ):
     683             :                 {
     684             :                     // CT_TLPoint
     685           0 :                     awt::Point p = GetPointPercent( rAttribs.getFastAttributeList() );
     686           0 :                     maFrom <<= p.X;
     687           0 :                     maFrom <<= p.Y;
     688           0 :                     return this;
     689             :                 }
     690             :                 case PPT_TOKEN( by ):
     691             :                 {
     692             :                     // CT_TLPoint
     693           0 :                     awt::Point p = GetPointPercent( rAttribs.getFastAttributeList() );
     694           0 :                     maBy <<= p.X;
     695           0 :                     maBy <<= p.Y;
     696           0 :                     return this;
     697             :                 }
     698             :                 default:
     699           0 :                     break;
     700             :                 }
     701             : 
     702           0 :                 return this;
     703             :             }
     704             :     private:
     705             :         Any maBy;
     706             :         Any maFrom;
     707             :         Any maTo;
     708             :         bool mbZoomContents;
     709             :     };
     710             : 
     711             : 
     712             :     /** CT_TLAnimateRotationBehavior */
     713             :     class AnimRotContext
     714             :         : public TimeNodeContext
     715             :     {
     716             :     public:
     717           0 :         AnimRotContext( FragmentHandler2& rParent, sal_Int32  aElement,
     718             :                         const Reference< XFastAttributeList >& xAttribs,
     719             :                          const TimeNodePtr & pNode ) throw()
     720           0 :             : TimeNodeContext( rParent, aElement, xAttribs, pNode )
     721             :             {
     722           0 :                 AttributeList attribs( xAttribs );
     723             : 
     724           0 :                 pNode->getNodeProperties()[ NP_TRANSFORMTYPE ]
     725           0 :                     = makeAny((sal_Int16)AnimationTransformType::ROTATE);
     726             :                 // TODO make sure the units are OK
     727           0 :                 if(attribs.hasAttribute( XML_by ) )
     728             :                 {
     729           0 :                     sal_Int32 nBy = attribs.getInteger( XML_by, 0 );
     730           0 :                     pNode->setBy( makeAny( nBy ) );
     731             :                 }
     732           0 :                 if(attribs.hasAttribute( XML_from ) )
     733             :                 {
     734           0 :                     sal_Int32 nFrom = attribs.getInteger( XML_from, 0 );
     735           0 :                     pNode->setFrom( makeAny( nFrom ) );
     736             :                 }
     737           0 :                 if(attribs.hasAttribute( XML_to ) )
     738             :                 {
     739           0 :                     sal_Int32 nTo = attribs.getInteger( XML_to, 0 );
     740           0 :                     pNode->setTo( makeAny( nTo ) );
     741           0 :                 }
     742           0 :             }
     743             : 
     744           0 :         ~AnimRotContext( ) throw( )
     745           0 :             {
     746           0 :             }
     747             : 
     748           0 :         virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
     749             :             {
     750           0 :                 switch ( aElementToken )
     751             :                 {
     752             :                 case PPT_TOKEN( cBhvr ):
     753           0 :                     return new CommonBehaviorContext ( *this, rAttribs.getFastAttributeList(), mpNode );
     754             :                 default:
     755           0 :                     break;
     756             :                 }
     757             : 
     758           0 :                 return this;
     759             :             }
     760             :     };
     761             : 
     762             : 
     763             : 
     764             :     /** CT_TLAnimateMotionBehavior */
     765             :     class AnimMotionContext
     766             :         : public TimeNodeContext
     767             :     {
     768             :     public:
     769           0 :         AnimMotionContext( FragmentHandler2& rParent, sal_Int32  aElement,
     770             :                          const Reference< XFastAttributeList >& xAttribs,
     771             :                           const TimeNodePtr & pNode ) throw()
     772           0 :             : TimeNodeContext( rParent, aElement, xAttribs, pNode )
     773             :             {
     774           0 :                 pNode->getNodeProperties()[ NP_TRANSFORMTYPE ]
     775           0 :                     = makeAny((sal_Int16)AnimationTransformType::TRANSLATE);
     776             : 
     777           0 :                 AttributeList attribs( xAttribs );
     778             :                 // ST_TLAnimateMotionBehaviorOrigin { parent, layour }
     779           0 :                 sal_Int32 nOrigin = xAttribs->getOptionalValueToken( XML_origin, 0 );
     780           0 :                 if( nOrigin != 0 )
     781             :                 {
     782           0 :                     switch(nOrigin)
     783             :                     {
     784             :                     case XML_layout:
     785             :                     case XML_parent:
     786           0 :                         break;
     787             :                     }
     788             :                     // TODO
     789             :                 }
     790             : 
     791           0 :                 OUString aStr = xAttribs->getOptionalValue( XML_path );
     792           0 :                 aStr = aStr.replace( 'E', ' ' );
     793           0 :                 aStr = aStr.trim();
     794           0 :                 pNode->getNodeProperties()[ NP_PATH ] = makeAny(aStr);
     795             : 
     796             :                 // ST_TLAnimateMotionPathEditMode{ fixed, relative }
     797           0 :                 mnPathEditMode = xAttribs->getOptionalValueToken( XML_pathEditMode, 0 );
     798           0 :                 msPtsTypes = xAttribs->getOptionalValue( XML_ptsTypes );
     799           0 :                 mnAngle = attribs.getInteger( XML_rAng, 0 );
     800             :                 // TODO make sure the units are right. Likely not.
     801           0 :             }
     802             : 
     803           0 :         ~AnimMotionContext( ) throw()
     804           0 :             {
     805           0 :             }
     806             : 
     807             : 
     808           0 :         virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
     809             :             {
     810           0 :                 switch ( aElementToken )
     811             :                 {
     812             :                 case PPT_TOKEN( cBhvr ):
     813           0 :                     return new CommonBehaviorContext ( *this, rAttribs.getFastAttributeList(), mpNode );
     814             :                 case PPT_TOKEN( to ):
     815             :                 {
     816             :                     // CT_TLPoint
     817           0 :                     awt::Point p = GetPointPercent( rAttribs.getFastAttributeList() );
     818           0 :                     Any rAny;
     819           0 :                     rAny <<= p.X;
     820           0 :                     rAny <<= p.Y;
     821           0 :                     mpNode->setTo( rAny );
     822           0 :                     return this;
     823             :                 }
     824             :                 case PPT_TOKEN( from ):
     825             :                 {
     826             :                     // CT_TLPoint
     827           0 :                     awt::Point p = GetPointPercent( rAttribs.getFastAttributeList() );
     828           0 :                     Any rAny;
     829           0 :                     rAny <<= p.X;
     830           0 :                     rAny <<= p.Y;
     831           0 :                     mpNode->setFrom( rAny );
     832           0 :                     return this;
     833             :                 }
     834             :                 case PPT_TOKEN( by ):
     835             :                 {
     836             :                     // CT_TLPoint
     837           0 :                     awt::Point p = GetPointPercent( rAttribs.getFastAttributeList() );
     838           0 :                     Any rAny;
     839           0 :                     rAny <<= p.X;
     840           0 :                     rAny <<= p.Y;
     841           0 :                     mpNode->setBy( rAny );
     842           0 :                     return this;
     843             :                 }
     844             :                 case PPT_TOKEN( rCtr ):
     845             :                 {
     846             :                     // CT_TLPoint
     847           0 :                     awt::Point p = GetPointPercent( rAttribs.getFastAttributeList() );
     848             :                     // TODO push
     849             :                     (void)p;
     850           0 :                     return this;
     851             :                 }
     852             :                 default:
     853           0 :                     break;
     854             :                 }
     855             : 
     856           0 :                 return this;
     857             :             }
     858             :     private:
     859             :         OUString msPtsTypes;
     860             :         sal_Int32 mnPathEditMode;
     861             :         sal_Int32 mnAngle;
     862             :     };
     863             : 
     864             : 
     865             :     /** CT_TLAnimateEffectBehavior */
     866             :     class AnimEffectContext
     867             :         : public TimeNodeContext
     868             :     {
     869             :     public:
     870           0 :         AnimEffectContext( FragmentHandler2& rParent, sal_Int32  aElement,
     871             :                              const Reference< XFastAttributeList >& xAttribs,
     872             :                              const TimeNodePtr & pNode ) throw()
     873           0 :             : TimeNodeContext( rParent, aElement, xAttribs, pNode )
     874             :             {
     875           0 :                 sal_Int32 nDir = xAttribs->getOptionalValueToken( XML_transition, 0 );
     876           0 :                 OUString sFilter = xAttribs->getOptionalValue( XML_filter );
     877             :                 // TODO
     878             : //              OUString sPrList = xAttribs->getOptionalValue( XML_prLst );
     879             : 
     880           0 :                 if( !sFilter.isEmpty() )
     881             :                 {
     882           0 :                     SlideTransition aFilter( sFilter );
     883           0 :                     aFilter.setMode( nDir == XML_out ? false : true );
     884           0 :                     pNode->setTransitionFilter( aFilter );
     885           0 :                 }
     886           0 :             }
     887             : 
     888             : 
     889           0 :         ~AnimEffectContext( ) throw()
     890           0 :             {
     891           0 :             }
     892             : 
     893             : 
     894           0 :         virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
     895             :             {
     896           0 :                 switch ( aElementToken )
     897             :                 {
     898             :                 case PPT_TOKEN( cBhvr ):
     899           0 :                     return new CommonBehaviorContext ( *this, rAttribs.getFastAttributeList(), mpNode );
     900             :                 case PPT_TOKEN( progress ):
     901           0 :                     return new AnimVariantContext( *this, aElementToken, maProgress );
     902             :                     // TODO handle it.
     903             :                 default:
     904           0 :                     break;
     905             :                 }
     906             : 
     907           0 :                 return this;
     908             :             }
     909             :     private:
     910             :         Any maProgress;
     911             :         OUString msFilter;
     912             :         OUString msPrList;
     913             :     };
     914             : 
     915             : 
     916             : 
     917           8 :     TimeNodeContext * TimeNodeContext::makeContext(
     918             :             FragmentHandler2& rParent, sal_Int32  aElement,
     919             :             const Reference< XFastAttributeList >& xAttribs,
     920             :             const TimeNodePtr & pNode )
     921             :     {
     922           8 :         TimeNodeContext *pCtx = NULL;
     923           8 :         switch( aElement )
     924             :         {
     925             :         case PPT_TOKEN( animClr ):
     926           0 :             pCtx = new AnimColorContext( rParent, aElement, xAttribs, pNode );
     927           0 :             break;
     928             :         case PPT_TOKEN( par ):
     929           8 :             pCtx = new ParallelExclTimeNodeContext( rParent, aElement, xAttribs, pNode );
     930           8 :             break;
     931             :         case PPT_TOKEN( seq ):
     932           0 :             pCtx = new SequenceTimeNodeContext( rParent, aElement, xAttribs, pNode );
     933           0 :             break;
     934             :         case PPT_TOKEN( excl ):
     935           0 :             pCtx = new ParallelExclTimeNodeContext( rParent, aElement, xAttribs, pNode );
     936           0 :             break;
     937             :         case PPT_TOKEN( anim ):
     938           0 :             pCtx = new AnimContext ( rParent, aElement, xAttribs, pNode );
     939           0 :             break;
     940             :         case PPT_TOKEN( animEffect ):
     941           0 :             pCtx = new AnimEffectContext( rParent, aElement, xAttribs, pNode );
     942           0 :             break;
     943             :         case PPT_TOKEN( animMotion ):
     944           0 :             pCtx = new AnimMotionContext( rParent, aElement, xAttribs, pNode );
     945           0 :             break;
     946             :         case PPT_TOKEN( animRot ):
     947           0 :             pCtx = new AnimRotContext( rParent, aElement, xAttribs, pNode );
     948           0 :             break;
     949             :         case PPT_TOKEN( animScale ):
     950           0 :             pCtx = new AnimScaleContext( rParent, aElement, xAttribs, pNode );
     951           0 :             break;
     952             :         case PPT_TOKEN( cmd ):
     953           0 :             pCtx = new CmdTimeNodeContext( rParent, aElement, xAttribs, pNode );
     954           0 :             break;
     955             :         case PPT_TOKEN( set ):
     956           0 :             pCtx = new SetTimeNodeContext( rParent, aElement, xAttribs, pNode );
     957           0 :             break;
     958             :         case PPT_TOKEN( audio ):
     959             :         case PPT_TOKEN( video ):
     960           0 :             pCtx = new MediaNodeContext( rParent, aElement, xAttribs, pNode );
     961           0 :             break;
     962             :         default:
     963           0 :             break;
     964             :         }
     965           8 :         return pCtx;
     966             :     }
     967             : 
     968             : 
     969          16 :     TimeNodeContext::TimeNodeContext( FragmentHandler2& rParent, sal_Int32 aElement,
     970             :             const Reference< XFastAttributeList >& /*xAttribs*/,
     971             :             const TimeNodePtr & pNode ) throw()
     972             :         : FragmentHandler2( rParent )
     973             :         , mnElement( aElement )
     974          16 :         , mpNode( pNode )
     975             :     {
     976          16 :     }
     977             : 
     978             : 
     979          16 :     TimeNodeContext::~TimeNodeContext( ) throw()
     980             :     {
     981             : 
     982          16 :     }
     983             : 
     984             : 
     985           8 :     TimeNodeListContext::TimeNodeListContext( FragmentHandler2& rParent, TimeNodePtrList & aList )
     986             :         throw()
     987             :         : FragmentHandler2( rParent )
     988           8 :             , maList( aList )
     989             :     {
     990           8 :     }
     991             : 
     992             : 
     993          16 :     TimeNodeListContext::~TimeNodeListContext( ) throw()
     994             :     {
     995          16 :     }
     996             : 
     997             : 
     998           8 :     ::oox::core::ContextHandlerRef TimeNodeListContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
     999             :     {
    1000             :         sal_Int16 nNodeType;
    1001             : 
    1002           8 :         switch( aElementToken )
    1003             :         {
    1004             :         case PPT_TOKEN( par ):
    1005           8 :             nNodeType = AnimationNodeType::PAR;
    1006           8 :             break;
    1007             :         case PPT_TOKEN( seq ):
    1008           0 :             nNodeType = AnimationNodeType::SEQ;
    1009           0 :             break;
    1010             :         case PPT_TOKEN( excl ):
    1011             :             // TODO pick the right type. We choose parallel for now as
    1012             :             // there does not seem to be an "Exclusive"
    1013           0 :             nNodeType = AnimationNodeType::PAR;
    1014           0 :             break;
    1015             :         case PPT_TOKEN( anim ):
    1016           0 :             nNodeType = AnimationNodeType::ANIMATE;
    1017           0 :             break;
    1018             :         case PPT_TOKEN( animClr ):
    1019           0 :             nNodeType = AnimationNodeType::ANIMATECOLOR;
    1020           0 :             break;
    1021             :         case PPT_TOKEN( animEffect ):
    1022           0 :             nNodeType = AnimationNodeType::TRANSITIONFILTER;
    1023           0 :             break;
    1024             :         case PPT_TOKEN( animMotion ):
    1025           0 :             nNodeType = AnimationNodeType::ANIMATEMOTION;
    1026           0 :             break;
    1027             :         case PPT_TOKEN( animRot ):
    1028             :         case PPT_TOKEN( animScale ):
    1029           0 :             nNodeType = AnimationNodeType::ANIMATETRANSFORM;
    1030           0 :             break;
    1031             :         case PPT_TOKEN( cmd ):
    1032           0 :             nNodeType = AnimationNodeType::COMMAND;
    1033           0 :             break;
    1034             :         case PPT_TOKEN( set ):
    1035           0 :             nNodeType = AnimationNodeType::SET;
    1036           0 :             break;
    1037             :         case PPT_TOKEN( audio ):
    1038           0 :             nNodeType = AnimationNodeType::AUDIO;
    1039           0 :             break;
    1040             :         case PPT_TOKEN( video ):
    1041           0 :             nNodeType = AnimationNodeType::AUDIO;
    1042             :             OSL_TRACE( "OOX: video requested, gave Audio instead" );
    1043           0 :             break;
    1044             : 
    1045             :         default:
    1046           0 :             nNodeType = AnimationNodeType::CUSTOM;
    1047             :             OSL_TRACE( "OOX: uhandled token %x", aElementToken );
    1048           0 :             break;
    1049             :         }
    1050             : 
    1051           8 :         TimeNodePtr pNode(new TimeNode(nNodeType));
    1052           8 :         maList.push_back( pNode );
    1053           8 :         FragmentHandler2 * pContext = TimeNodeContext::makeContext( *this, aElementToken, rAttribs.getFastAttributeList(), pNode );
    1054             : 
    1055           8 :         return pContext ? pContext : this;
    1056             :     }
    1057             : 
    1058             : 
    1059         174 : } }
    1060             : 
    1061             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10