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