Bump version to 24.04.3.4
[LibreOffice.git] / xmloff / source / draw / animationimport.cxx
blob519c3288cdce5a8fd3c2aa980c8bbcdf5e0e637b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <memory>
21 #include <xmloff/unointerfacetouniqueidentifiermapper.hxx>
22 #include <com/sun/star/lang/XInitialization.hpp>
23 #include <com/sun/star/animations/AnimationTransformType.hpp>
24 #include <com/sun/star/animations/XAnimationNodeSupplier.hpp>
25 #include <com/sun/star/animations/AnimationNodeType.hpp>
26 #include <com/sun/star/animations/SequenceTimeContainer.hpp>
27 #include <com/sun/star/animations/XIterateContainer.hpp>
28 #include <com/sun/star/animations/XAnimateMotion.hpp>
29 #include <com/sun/star/animations/XAnimatePhysics.hpp>
30 #include <com/sun/star/animations/XAnimateColor.hpp>
31 #include <com/sun/star/animations/XAnimateTransform.hpp>
32 #include <com/sun/star/animations/XTransitionFilter.hpp>
33 #include <com/sun/star/animations/XCommand.hpp>
34 #include <com/sun/star/animations/XAudio.hpp>
35 #include <com/sun/star/animations/ValuePair.hpp>
36 #include <com/sun/star/animations/AnimationColorSpace.hpp>
37 #include <com/sun/star/presentation/EffectPresetClass.hpp>
38 #include <com/sun/star/animations/Timing.hpp>
39 #include <com/sun/star/animations/Event.hpp>
40 #include <com/sun/star/beans/XPropertySet.hpp>
41 #include <com/sun/star/io/WrongFormatException.hpp>
42 #include <com/sun/star/xml/sax/XFastAttributeList.hpp>
43 #include <com/sun/star/text/XTextCursor.hpp>
44 #include <com/sun/star/text/XTextRangeCompare.hpp>
45 #include <com/sun/star/presentation/ParagraphTarget.hpp>
46 #include <com/sun/star/container/XEnumerationAccess.hpp>
47 #include <com/sun/star/animations/EventTrigger.hpp>
48 #include <com/sun/star/presentation/EffectCommands.hpp>
49 #include <com/sun/star/util/Duration.hpp>
50 #include <comphelper/processfactory.hxx>
51 #include <comphelper/string.hxx>
53 #include <rtl/math.h>
54 #include <sal/log.hxx>
55 #include <comphelper/diagnose_ex.hxx>
56 #include <o3tl/string_view.hxx>
57 #include <sax/tools/converter.hxx>
59 #include <vector>
61 #include <xmloff/xmltypes.hxx>
62 #include "sdpropls.hxx"
63 #include <xmloff/xmltoken.hxx>
64 #include <xmloff/xmlimp.hxx>
65 #include <xmloff/xmlnamespace.hxx>
66 #include <xmloff/xmluconv.hxx>
67 #include <xmloff/xmlprhdl.hxx>
68 #include <xmlsdtypes.hxx>
70 #include <animations.hxx>
71 #include <animationimport.hxx>
73 using namespace ::cppu;
74 using namespace ::com::sun::star;
75 using namespace ::com::sun::star::beans;
76 using namespace ::com::sun::star::animations;
77 using namespace ::com::sun::star::presentation;
78 using namespace ::com::sun::star::drawing;
79 using namespace ::com::sun::star::uno;
80 using namespace ::xmloff::token;
82 using ::com::sun::star::xml::sax::XFastAttributeList;
83 using ::com::sun::star::beans::NamedValue;
84 using ::com::sun::star::text::XTextRange;
85 using ::com::sun::star::text::XTextCursor;
86 using ::com::sun::star::text::XTextRangeCompare;
87 using ::com::sun::star::container::XEnumerationAccess;
88 using ::com::sun::star::container::XEnumeration;
89 using ::com::sun::star::lang::XInitialization;
91 static OUString
92 lcl_GetMediaReference(SvXMLImport const& rImport, OUString const& rURL)
94 if (rImport.IsPackageURL(rURL))
95 return "vnd.sun.star.Package:" + rURL;
97 return rImport.GetAbsoluteReference(rURL);
100 namespace xmloff
103 class AnimationsImportHelperImpl
105 private:
106 SvXMLImport& mrImport;
108 public:
109 explicit AnimationsImportHelperImpl( SvXMLImport& rImport );
111 Any convertValue( XMLTokenEnum eAttributeName, const OUString& rValue );
112 Sequence< Any > convertValueSequence( XMLTokenEnum eAttributeName, std::u16string_view rValue );
114 Any convertTarget( const OUString& rValue );
115 static Any convertPath( const OUString& rValue );
116 Any convertTiming( const OUString& rValue );
117 static Sequence< double > convertKeyTimes( std::string_view rValue );
118 static Sequence< TimeFilterPair > convertTimeFilter( std::string_view rValue );
121 AnimationsImportHelperImpl::AnimationsImportHelperImpl( SvXMLImport& rImport )
122 : mrImport( rImport )
126 static bool isDouble( std::string_view rValue )
128 sal_Int32 nLength = rValue.size();
129 const char * pStr = rValue.data();
130 while( nLength )
132 if( (*pStr >= '0' && *pStr <= '9') || *pStr == '-' || *pStr == '.' || *pStr == '+' || *pStr == 'e' || *pStr == 'E' )
134 pStr++;
135 nLength--;
137 else
139 return false;
143 return true;
146 static bool isTime( const OUString& rValue )
148 sal_Int32 nLength = rValue.getLength();
149 const sal_Unicode * pStr;
150 for( pStr = rValue.getStr(); nLength; pStr++, nLength-- )
152 if( !( (*pStr >= '0' && *pStr <= '9') || *pStr == '-' || *pStr == '.' || *pStr == '+' || *pStr == 'e' || *pStr == 'E' ) )
153 break;
156 // return true if this is a double (if someone forgot the 's' we silently ignore it)
157 // or if it's a double that ends with a 's' or 'S'
158 return (nLength == 0) || ((*pStr == 's' || *pStr == 'S') && (nLength == 1));
161 Any AnimationsImportHelperImpl::convertTarget( const OUString& rValue )
165 Reference< XInterface > xRef( mrImport.getInterfaceToIdentifierMapper().getReference( rValue ) );
167 Reference< XShape > _xShape( xRef, UNO_QUERY );
168 if( _xShape.is() )
169 return Any( _xShape );
171 Reference< XTextCursor > xTextCursor( xRef, UNO_QUERY );
172 if( xTextCursor.is() )
174 Reference< XTextRange > xStart( xTextCursor->getStart() ), xRange;
175 Reference< XShape > xShape( xTextCursor->getText(), UNO_QUERY_THROW );
176 Reference< XTextRangeCompare > xTextRangeCompare( xShape, UNO_QUERY_THROW );
178 Reference< XEnumerationAccess > xParaEnumAccess( xShape, UNO_QUERY_THROW );
179 Reference< XEnumeration > xEnumeration( xParaEnumAccess->createEnumeration(), UNO_SET_THROW );
180 sal_Int16 nParagraph = 0;
182 while( xEnumeration->hasMoreElements() )
184 xEnumeration->nextElement() >>= xRange;
186 // break if start of selection is prior to end of current paragraph
187 if( xRange.is() && (xTextRangeCompare->compareRegionEnds( xStart, xRange ) >= 0 ) )
189 return Any( ParagraphTarget( xShape, nParagraph ) );
192 nParagraph++;
196 catch (const RuntimeException&)
198 TOOLS_WARN_EXCEPTION("xmloff.draw", "");
201 Any aAny;
202 return aAny;
205 Any AnimationsImportHelperImpl::convertValue( XMLTokenEnum eAttributeName, const OUString& rValue )
207 sal_Int32 nCommaPos = -1, nPos;
208 sal_Int32 nOpenBrackets = 0;
209 for( nPos = 0; (nPos < rValue.getLength()) && (nCommaPos == -1); nPos++ )
211 switch( rValue[nPos] )
213 case ',':
214 if( nOpenBrackets == 0 )
215 nCommaPos = nPos;
216 break;
217 case '(':
218 case '[':
219 case '{':
220 nOpenBrackets++;
221 break;
222 case ')':
223 case ']':
224 case '}':
225 nOpenBrackets--;
226 break;
230 if( nCommaPos >= 0 )
232 ValuePair aPair;
233 aPair.First = convertValue( eAttributeName, rValue.copy( 0, nCommaPos ) );
234 aPair.Second = convertValue( eAttributeName, rValue.copy( nCommaPos+1 ) );
235 return Any( aPair );
237 else
239 Any aAny;
240 sal_Int32 nType = XML_TYPE_STRING;
242 if( rValue.getLength() ) switch( eAttributeName )
244 case XML_X:
245 case XML_Y:
246 case XML_WIDTH:
247 case XML_HEIGHT:
248 case XML_TRANSLATE:
250 return Any( rValue );
253 case XML_SCALE:
254 case XML_SKEWY:
255 case XML_SKEWX:
256 case XML_OPACITY:
257 case XML_ROTATE: nType = XML_TYPE_DOUBLE; break;
258 case XML_TEXT_ROTATION_ANGLE:nType = XML_TYPE_TEXT_ROTATION_ANGLE; break;
259 case XML_FILL_COLOR:
260 case XML_STROKE_COLOR:
261 case XML_DIM:
262 case XML_COLOR: nType = XML_TYPE_COLOR; break;
263 case XML_FILL: nType = XML_SD_TYPE_FILLSTYLE; break;
264 case XML_STROKE: nType = XML_SD_TYPE_STROKE; break;
265 case XML_FONT_WEIGHT: nType = XML_TYPE_TEXT_WEIGHT; break;
266 case XML_FONT_STYLE: nType = XML_TYPE_TEXT_POSTURE; break;
267 case XML_TEXT_UNDERLINE: nType = XML_TYPE_TEXT_UNDERLINE_STYLE; break;
268 case XML_FONT_SIZE: nType = XML_TYPE_DOUBLE_PERCENT; break;
269 case XML_VISIBILITY: nType = XML_SD_TYPE_PRESPAGE_VISIBILITY; break;
271 default:
272 if( !rValue.isEmpty() )
273 aAny <<= rValue;
274 return aAny;
277 const XMLPropertyHandler* pHandler = mrImport.GetShapeImport()->GetSdPropHdlFactory()->GetPropertyHandler( nType );
278 if( pHandler )
279 pHandler->importXML( rValue, aAny, mrImport.GetMM100UnitConverter() );
281 return aAny;
285 Sequence< Any > AnimationsImportHelperImpl::convertValueSequence( XMLTokenEnum eAttributeName, std::u16string_view rValue )
287 Sequence< Any > aValues;
289 const sal_Int32 nElements { comphelper::string::getTokenCount(rValue, ';') };
290 if ( nElements>0 )
292 // prepare the sequence
293 aValues.realloc( nElements );
295 // fill the sequence
296 Any* pValues = aValues.getArray();
297 for (sal_Int32 nIndex = 0; nIndex >= 0; )
298 *pValues++ = convertValue( eAttributeName, OUString(o3tl::getToken(rValue, 0, ';', nIndex )) );
301 return aValues;
304 Any AnimationsImportHelperImpl::convertTiming( const OUString& rValue )
306 Any aAny;
308 const sal_Int32 nElements { comphelper::string::getTokenCount(rValue, ';') };
309 if ( nElements>0 )
311 if( nElements == 1 )
313 if( IsXMLToken( rValue, XML_MEDIA ) )
315 aAny <<= Timing_MEDIA;
317 else if( IsXMLToken( rValue, XML_INDEFINITE ) )
319 aAny <<= Timing_INDEFINITE;
321 else if( isTime( rValue ) )
323 aAny <<= rValue.toDouble();
325 else
327 Event aEvent;
328 aEvent.Repeat = 0;
329 aEvent.Trigger = 0;
331 OUString aEventTrigger;
333 sal_Int32 nPos = rValue.indexOf( '+' );
334 if( nPos == -1 )
336 aEventTrigger = rValue;
338 else
340 aEventTrigger = rValue.copy( 0, nPos );
342 // convert offset
343 aEvent.Offset = convertTiming( rValue.copy( nPos + 1 ) );
346 nPos = aEventTrigger.indexOf( '.' );
347 if( nPos != -1 )
349 aEvent.Source <<= mrImport.getInterfaceToIdentifierMapper().getReference( aEventTrigger.copy( 0, nPos ) );
350 aEventTrigger = aEventTrigger.copy( nPos + 1 );
353 sal_Int16 nEnum;
354 if( SvXMLUnitConverter::convertEnum( nEnum, aEventTrigger, aAnimations_EnumMap_EventTrigger ) )
356 aEvent.Trigger = nEnum;
358 else
360 OSL_FAIL("AnimationsImportHelperImpl::convertTiming(), unknown event trigger!");
363 aAny <<= aEvent;
366 else
368 // fill the sequence
369 Sequence< Any > aValues( nElements );
370 Any* pValues = aValues.getArray();
371 for (sal_Int32 nIndex = 0; nIndex >= 0; )
372 *pValues++ = convertTiming( rValue.getToken( 0, ';', nIndex ) );
374 aAny <<= aValues;
377 return aAny;
380 Sequence< double > AnimationsImportHelperImpl::convertKeyTimes( std::string_view rValue )
382 const sal_Int32 nElements { comphelper::string::getTokenCount(rValue, ';') };
384 Sequence< double > aKeyTimes( nElements );
386 if( nElements )
388 double* pValues = aKeyTimes.getArray();
389 for (sal_Int32 nIndex = 0; nIndex >= 0; )
390 *pValues++ = o3tl::toDouble(o3tl::getToken(rValue, 0, ';', nIndex ));
393 return aKeyTimes;
396 Sequence< TimeFilterPair > AnimationsImportHelperImpl::convertTimeFilter( std::string_view rValue )
398 const sal_Int32 nElements { comphelper::string::getTokenCount(rValue, ';') };
400 Sequence< TimeFilterPair > aTimeFilter( nElements );
402 if( nElements )
404 TimeFilterPair* pValues = aTimeFilter.getArray();
405 for (sal_Int32 nIndex = 0; nIndex >= 0; )
407 const std::string_view aToken( o3tl::getToken(rValue, 0, ';', nIndex ) );
409 size_t nPos = aToken.find( ',' );
410 if( nPos != std::string_view::npos )
412 pValues->Time = rtl_math_stringToDouble(
413 aToken.data(), aToken.data() + nPos, '.', 0, nullptr, nullptr);
414 pValues->Progress = rtl_math_stringToDouble(
415 aToken.data() + nPos + 1, aToken.data() + aToken.size(), '.', 0,
416 nullptr, nullptr);
418 pValues++;
422 return aTimeFilter;
425 Any AnimationsImportHelperImpl::convertPath( const OUString& rValue )
427 return Any( rValue );
431 AnimationNodeContext::AnimationNodeContext(
432 const Reference< XAnimationNode >& xParentNode,
433 SvXMLImport& rImport, sal_Int32 nElement,
434 const css::uno::Reference< css::xml::sax::XFastAttributeList>& xAttrList,
435 const std::shared_ptr<AnimationsImportHelperImpl>& pHelper )
436 : SvXMLImportContext(rImport),
437 mpHelper( pHelper )
439 bool bRootContext = !pHelper;
442 if( bRootContext )
444 mpHelper = std::make_shared<AnimationsImportHelperImpl>( rImport );
445 mxNode = xParentNode;
447 else
449 sal_Int16 nPresetClass = EffectPresetClass::CUSTOM;
451 const char* pServiceName = nullptr;
453 // we see namespace ANIMATION and ANIMATION_OOO and PRESENTATION_OASIS and PRESENTATION_SO52 and PRESENTATION_OOO
454 switch( nElement & TOKEN_MASK )
456 case XML_SEQ:
457 pServiceName = "com.sun.star.animations.SequenceTimeContainer"; break;
458 case XML_ITERATE:
459 pServiceName = "com.sun.star.animations.IterateContainer"; break;
460 case XML_ANIMATE:
461 pServiceName = "com.sun.star.animations.Animate"; break;
462 case XML_SET:
463 pServiceName = "com.sun.star.animations.AnimateSet"; break;
464 case XML_ANIMATEMOTION:
465 pServiceName = "com.sun.star.animations.AnimateMotion"; break;
466 case XML_ANIMATEPHYSICS:
467 pServiceName = "com.sun.star.animations.AnimatePhysics"; break;
468 case XML_ANIMATECOLOR:
469 pServiceName = "com.sun.star.animations.AnimateColor"; break;
470 case XML_ANIMATETRANSFORM:
471 pServiceName = "com.sun.star.animations.AnimateTransform"; break;
472 case XML_TRANSITIONFILTER:
473 pServiceName = "com.sun.star.animations.TransitionFilter"; break;
474 case XML_AUDIO:
475 pServiceName = "com.sun.star.animations.Audio"; break;
476 case XML_COMMAND:
477 pServiceName = "com.sun.star.animations.Command"; break;
478 case XML_PAR:
480 for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
482 if( (aIter.getToken() & TOKEN_MASK) == XML_PRESET_ID)
484 const OUString& rValue = aIter.toString();
485 if ( rValue == "ooo-entrance-random" )
487 nPresetClass = EffectPresetClass::ENTRANCE;
489 else if ( rValue == "ooo-exit-random" )
491 nPresetClass = EffectPresetClass::EXIT;
494 if( nPresetClass != EffectPresetClass::CUSTOM )
496 pServiceName = "com.sun.star.comp.sd.RandomAnimationNode";
497 break;
501 if( !pServiceName )
502 pServiceName = "com.sun.star.animations.ParallelTimeContainer";
504 break;
505 default:
506 SAL_WARN("xmloff", "unexpected token '" + SvXMLImport::getNameFromToken(nElement)
507 << "' 0x" << std::hex << nElement);
508 break;
511 if( pServiceName )
513 Reference< XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
515 mxNode.set(
516 xContext->getServiceManager()->createInstanceWithContext(OUString::createFromAscii(pServiceName), xContext),
517 UNO_QUERY_THROW );
519 if( nPresetClass != EffectPresetClass::CUSTOM )
521 Reference< XInitialization > xInit( mxNode, UNO_QUERY_THROW );
522 const Any aAny( nPresetClass );
523 Sequence< Any > aArgs( &aAny, 1 ) ;
524 xInit->initialize( aArgs );
527 init_node( xAttrList );
529 Reference< XTimeContainer > xParentContainer( xParentNode, UNO_QUERY_THROW );
530 xParentContainer->appendChild( mxNode );
534 catch (const RuntimeException&)
536 TOOLS_WARN_EXCEPTION("xmloff.draw", "");
540 void AnimationNodeContext::init_node( const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
542 if( !mxNode.is() )
543 return;
547 const sal_Int16 nNodeType = mxNode->getType();
549 // query for optional interfaces that are often used later
550 Reference< XAnimate > xAnimate( mxNode, UNO_QUERY );
551 Reference< XCommand > xCommand( mxNode, UNO_QUERY );
552 Reference< XTransitionFilter > xTransitionFilter( mxNode, UNO_QUERY );
553 Reference< XIterateContainer > xIter( mxNode, UNO_QUERY );
555 std::vector< NamedValue > aUserData;
556 XMLTokenEnum meAttributeName = XML_TOKEN_INVALID;
557 OUString aFrom, aBy, aTo, aValues;
558 bool bHaveXmlId( false );
559 OUString sXmlId;
561 sal_Int16 nEnum;
562 for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
564 auto nToken = aIter.getToken();
565 switch( nToken )
567 case XML_ELEMENT(SMIL, XML_BEGIN):
568 case XML_ELEMENT(SMIL_COMPAT, XML_BEGIN):
569 case XML_ELEMENT(SMIL_SO52, XML_BEGIN):
571 mxNode->setBegin( mpHelper->convertTiming( aIter.toString() ) );
573 break;
574 case XML_ELEMENT(SMIL, XML_DUR):
575 case XML_ELEMENT(SMIL_COMPAT, XML_DUR):
576 case XML_ELEMENT(SMIL_SO52, XML_DUR):
578 mxNode->setDuration( mpHelper->convertTiming( aIter.toString() ) );
580 break;
581 case XML_ELEMENT(SMIL, XML_END):
582 case XML_ELEMENT(SMIL_COMPAT, XML_END):
583 case XML_ELEMENT(SMIL_SO52, XML_END):
585 mxNode->setEnd( mpHelper->convertTiming( aIter.toString() ) );
587 break;
588 case XML_ELEMENT(SMIL, XML_FILL):
589 case XML_ELEMENT(SMIL_COMPAT, XML_FILL):
590 case XML_ELEMENT(SMIL_SO52, XML_FILL):
592 if( SvXMLUnitConverter::convertEnum( nEnum, aIter.toView(), aAnimations_EnumMap_Fill ) )
593 mxNode->setFill( nEnum );
595 break;
596 case XML_ELEMENT(SMIL, XML_FILLDEFAULT):
597 case XML_ELEMENT(SMIL_COMPAT, XML_FILLDEFAULT):
598 case XML_ELEMENT(SMIL_SO52, XML_FILLDEFAULT):
600 if( SvXMLUnitConverter::convertEnum( nEnum, aIter.toView(), aAnimations_EnumMap_FillDefault ) )
601 mxNode->setFillDefault( nEnum );
603 break;
604 case XML_ELEMENT(SMIL, XML_RESTART):
605 case XML_ELEMENT(SMIL_COMPAT, XML_RESTART):
606 case XML_ELEMENT(SMIL_SO52, XML_RESTART):
608 if( SvXMLUnitConverter::convertEnum( nEnum, aIter.toView(), aAnimations_EnumMap_Restart ) )
609 mxNode->setRestart( nEnum );
611 break;
612 case XML_ELEMENT(SMIL, XML_RESTARTDEFAULT):
613 case XML_ELEMENT(SMIL_COMPAT, XML_RESTARTDEFAULT):
614 case XML_ELEMENT(SMIL_SO52, XML_RESTARTDEFAULT):
616 if( SvXMLUnitConverter::convertEnum( nEnum, aIter.toView(), aAnimations_EnumMap_RestartDefault ) )
617 mxNode->setRestartDefault( nEnum );
619 break;
620 case XML_ELEMENT(SMIL, XML_ACCELERATE):
621 case XML_ELEMENT(SMIL_COMPAT, XML_ACCELERATE):
622 case XML_ELEMENT(SMIL_SO52, XML_ACCELERATE):
624 if( isDouble( aIter.toView() ) )
625 mxNode->setAcceleration( aIter.toDouble() );
627 break;
628 case XML_ELEMENT(SMIL, XML_DECELERATE):
629 case XML_ELEMENT(SMIL_COMPAT, XML_DECELERATE):
630 case XML_ELEMENT(SMIL_SO52, XML_DECELERATE):
632 if( isDouble( aIter.toView() ) )
633 mxNode->setDecelerate( aIter.toDouble() );
635 break;
636 case XML_ELEMENT(SMIL, XML_AUTOREVERSE):
637 case XML_ELEMENT(SMIL_COMPAT, XML_AUTOREVERSE):
638 case XML_ELEMENT(SMIL_SO52, XML_AUTOREVERSE):
640 bool bTemp;
641 if (::sax::Converter::convertBool( bTemp, aIter.toView() ))
642 mxNode->setAutoReverse( bTemp );
644 break;
645 case XML_ELEMENT(SMIL, XML_REPEATCOUNT):
646 case XML_ELEMENT(SMIL_COMPAT, XML_REPEATCOUNT):
647 case XML_ELEMENT(SMIL_SO52, XML_REPEATCOUNT):
649 mxNode->setRepeatCount( mpHelper->convertTiming( aIter.toString() ) );
651 break;
652 case XML_ELEMENT(SMIL, XML_REPEATDUR):
653 case XML_ELEMENT(SMIL_COMPAT, XML_REPEATDUR):
654 case XML_ELEMENT(SMIL_SO52, XML_REPEATDUR):
656 mxNode->setRepeatDuration( mpHelper->convertTiming( aIter.toString() ) );
658 break;
659 case XML_ELEMENT(SMIL, XML_ENDSYNC):
660 case XML_ELEMENT(SMIL_COMPAT, XML_ENDSYNC):
661 case XML_ELEMENT(SMIL_SO52, XML_ENDSYNC):
663 if( SvXMLUnitConverter::convertEnum( nEnum, aIter.toView(), aAnimations_EnumMap_Endsync ) )
664 mxNode->setEndSync( Any( nEnum ) );
666 break;
667 case XML_ELEMENT(PRESENTATION, XML_NODE_TYPE):
668 case XML_ELEMENT(PRESENTATION_SO52, XML_NODE_TYPE):
669 case XML_ELEMENT(PRESENTATION_OOO, XML_NODE_TYPE):
670 case XML_ELEMENT(PRESENTATION_OASIS, XML_NODE_TYPE):
672 if( SvXMLUnitConverter::convertEnum( nEnum, aIter.toView(), aAnimations_EnumMap_EffectNodeType ) )
673 aUserData.emplace_back( GetXMLToken( XML_NODE_TYPE ), Any( nEnum ) );
675 break;
676 case XML_ELEMENT(PRESENTATION, XML_PRESET_ID):
677 case XML_ELEMENT(PRESENTATION_SO52, XML_PRESET_ID):
678 case XML_ELEMENT(PRESENTATION_OOO, XML_PRESET_ID):
679 case XML_ELEMENT(PRESENTATION_OASIS, XML_PRESET_ID):
681 aUserData.emplace_back( GetXMLToken( XML_PRESET_ID ), Any( aIter.toString() ) );
683 break;
684 case XML_ELEMENT(PRESENTATION, XML_PRESET_SUB_TYPE):
685 case XML_ELEMENT(PRESENTATION_SO52, XML_PRESET_SUB_TYPE):
686 case XML_ELEMENT(PRESENTATION_OOO, XML_PRESET_SUB_TYPE):
687 case XML_ELEMENT(PRESENTATION_OASIS, XML_PRESET_SUB_TYPE):
689 aUserData.emplace_back( GetXMLToken( XML_PRESET_SUB_TYPE ), Any( aIter.toString() ) );
691 break;
692 case XML_ELEMENT(PRESENTATION, XML_PRESET_CLASS):
693 case XML_ELEMENT(PRESENTATION_SO52, XML_PRESET_CLASS):
694 case XML_ELEMENT(PRESENTATION_OOO, XML_PRESET_CLASS):
695 case XML_ELEMENT(PRESENTATION_OASIS, XML_PRESET_CLASS):
697 if( SvXMLUnitConverter::convertEnum( nEnum, aIter.toView(), aAnimations_EnumMap_EffectPresetClass ) )
698 aUserData.emplace_back( GetXMLToken( XML_PRESET_CLASS ), Any( nEnum ) );
700 break;
701 case XML_ELEMENT(PRESENTATION, XML_AFTER_EFFECT):
702 case XML_ELEMENT(PRESENTATION_SO52, XML_AFTER_EFFECT):
703 case XML_ELEMENT(PRESENTATION_OOO, XML_AFTER_EFFECT):
705 bool bTemp;
706 if (::sax::Converter::convertBool( bTemp, aIter.toView() ))
707 aUserData.emplace_back( GetXMLToken( XML_AFTER_EFFECT ), Any( bTemp ) );
709 break;
710 case XML_ELEMENT(XLINK, XML_HREF):
712 if( nNodeType == AnimationNodeType::AUDIO )
714 Reference< XAudio > xAudio( mxNode, UNO_QUERY_THROW );
715 xAudio->setSource( Any(lcl_GetMediaReference(GetImport(), aIter.toString())) );
716 break;
718 [[fallthrough]];
720 case XML_ELEMENT(SMIL, XML_TARGETELEMENT):
721 case XML_ELEMENT(SMIL_COMPAT, XML_TARGETELEMENT):
722 case XML_ELEMENT(SMIL_SO52, XML_TARGETELEMENT):
724 Any aTarget( mpHelper->convertTarget( aIter.toString() ) );
726 if( xAnimate.is() )
728 xAnimate->setTarget( aTarget );
730 else if( xIter.is() )
732 xIter->setTarget( aTarget );
734 else if( xCommand.is() )
736 xCommand->setTarget( aTarget );
739 break;
741 case XML_ELEMENT(ANIMATION, XML_AUDIO_LEVEL):
742 case XML_ELEMENT(ANIMATION_OOO, XML_AUDIO_LEVEL):
744 if( nNodeType == AnimationNodeType::AUDIO )
746 if( isDouble( aIter.toView() ) )
748 Reference< XAudio > xAudio( mxNode, UNO_QUERY_THROW );
749 xAudio->setVolume( aIter.toDouble() );
753 break;
755 case XML_ELEMENT(PRESENTATION, XML_MASTER_ELEMENT):
756 case XML_ELEMENT(PRESENTATION_SO52, XML_MASTER_ELEMENT):
757 case XML_ELEMENT(PRESENTATION_OOO, XML_MASTER_ELEMENT):
759 Reference< XAnimationNode > xMaster( GetImport().getInterfaceToIdentifierMapper().getReference( aIter.toString() ), UNO_QUERY );
760 aUserData.emplace_back( GetXMLToken( XML_MASTER_ELEMENT ), Any( xMaster ) );
762 break;
764 case XML_ELEMENT(ANIMATION, XML_SUB_ITEM):
765 case XML_ELEMENT(ANIMATION_OOO, XML_SUB_ITEM):
767 if( SvXMLUnitConverter::convertEnum( nEnum, aIter.toView(), aAnimations_EnumMap_SubItem ) )
769 if( xAnimate.is() )
771 xAnimate->setSubItem( nEnum );
773 else if( xIter.is() )
775 xIter->setSubItem( nEnum );
779 break;
781 case XML_ELEMENT(SMIL, XML_ATTRIBUTENAME):
782 case XML_ELEMENT(SMIL_COMPAT, XML_ATTRIBUTENAME):
783 case XML_ELEMENT(SMIL_SO52, XML_ATTRIBUTENAME):
785 if( xAnimate.is() )
787 OUString aName( aIter.toString() );
789 const struct ImplAttributeNameConversion* p = getAnimationAttributeNamesConversionList();
790 while( p->mpAPIName )
792 if( IsXMLToken( aIter, p->meXMLToken ) )
794 aName = OUString::createFromAscii( p->mpAPIName );
795 meAttributeName = p->meXMLToken;
796 break;
799 p++;
802 xAnimate->setAttributeName( aName );
805 break;
807 case XML_ELEMENT(SMIL, XML_VALUES):
808 case XML_ELEMENT(SMIL_COMPAT, XML_VALUES):
809 case XML_ELEMENT(SMIL_SO52, XML_VALUES):
811 aValues = aIter.toString();
813 break;
815 case XML_ELEMENT(SMIL, XML_FROM):
816 case XML_ELEMENT(SMIL_COMPAT, XML_FROM):
817 case XML_ELEMENT(SMIL_SO52, XML_FROM):
819 aFrom = aIter.toString();
821 break;
823 case XML_ELEMENT(SMIL, XML_BY):
824 case XML_ELEMENT(SMIL_COMPAT, XML_BY):
825 case XML_ELEMENT(SMIL_SO52, XML_BY):
827 aBy = aIter.toString();
829 break;
831 case XML_ELEMENT(SMIL, XML_TO):
832 case XML_ELEMENT(SMIL_COMPAT, XML_TO):
833 case XML_ELEMENT(SMIL_SO52, XML_TO):
835 aTo = aIter.toString();
837 break;
839 case XML_ELEMENT(SMIL, XML_KEYTIMES):
840 case XML_ELEMENT(SMIL_COMPAT, XML_KEYTIMES):
841 case XML_ELEMENT(SMIL_SO52, XML_KEYTIMES):
843 if( xAnimate.is() )
844 xAnimate->setKeyTimes( AnimationsImportHelperImpl::convertKeyTimes( aIter.toView() ) );
846 break;
848 case XML_ELEMENT(ANIMATION, XML_FORMULA):
849 case XML_ELEMENT(ANIMATION_OOO, XML_FORMULA):
851 if( xAnimate.is() )
852 xAnimate->setFormula( aIter.toString() );
854 break;
856 case XML_ELEMENT(ANIMATION, XML_ID):
857 case XML_ELEMENT(ANIMATION_OOO, XML_ID):
859 if (!bHaveXmlId) { sXmlId = aIter.toString(); }
861 break;
862 case XML_ELEMENT(XML, XML_ID):
864 sXmlId = aIter.toString();
865 bHaveXmlId = true;
867 break;
869 case XML_ELEMENT(SMIL, XML_CALCMODE):
870 case XML_ELEMENT(SMIL_COMPAT, XML_CALCMODE):
871 case XML_ELEMENT(SMIL_SO52, XML_CALCMODE):
873 if( xAnimate.is() )
875 if( SvXMLUnitConverter::convertEnum( nEnum, aIter.toView(), aAnimations_EnumMap_CalcMode ) )
876 xAnimate->setCalcMode( nEnum );
879 break;
881 case XML_ELEMENT(SMIL, XML_ACCUMULATE):
882 case XML_ELEMENT(SMIL_COMPAT, XML_ACCUMULATE):
883 case XML_ELEMENT(SMIL_SO52, XML_ACCUMULATE):
885 if( xAnimate.is() )
886 xAnimate->setAccumulate( IsXMLToken( aIter, XML_SUM ) );
888 break;
890 case XML_ELEMENT(PRESENTATION, XML_ADDITIVE):
891 case XML_ELEMENT(PRESENTATION_SO52, XML_ADDITIVE):
892 case XML_ELEMENT(PRESENTATION_OOO, XML_ADDITIVE):
893 case XML_ELEMENT(SMIL, XML_ADDITIVE):
894 case XML_ELEMENT(SMIL_COMPAT, XML_ADDITIVE):
895 case XML_ELEMENT(SMIL_SO52, XML_ADDITIVE):
897 if( xAnimate.is() )
899 if( SvXMLUnitConverter::convertEnum( nEnum, aIter.toView(), aAnimations_EnumMap_AdditiveMode ) )
900 xAnimate->setAdditive( nEnum );
903 break;
905 case XML_ELEMENT(SMIL, XML_KEYSPLINES):
906 case XML_ELEMENT(SMIL_COMPAT, XML_KEYSPLINES):
907 case XML_ELEMENT(SMIL_SO52, XML_KEYSPLINES):
909 if( xAnimate.is() )
910 xAnimate->setTimeFilter( AnimationsImportHelperImpl::convertTimeFilter( aIter.toView() ) );
912 break;
914 case XML_ELEMENT(SVG, XML_PATH):
915 case XML_ELEMENT(SVG_COMPAT, XML_PATH):
917 Reference< XAnimateMotion > xAnimateMotion( mxNode, UNO_QUERY );
918 if( xAnimateMotion.is() )
919 xAnimateMotion->setPath( AnimationsImportHelperImpl::convertPath( aIter.toString() ) );
921 break;
923 case XML_ELEMENT(ANIMATION, XML_PHYSICS_ANIMATION_START_VELOCITY_X):
924 case XML_ELEMENT(ANIMATION_OOO, XML_PHYSICS_ANIMATION_START_VELOCITY_X):
925 case XML_ELEMENT(LO_EXT, XML_PHYSICS_ANIMATION_START_VELOCITY_X):
927 Reference< XAnimatePhysics > xAnimatePhysics( mxNode, UNO_QUERY );
928 if( xAnimatePhysics.is() )
929 xAnimatePhysics->setStartVelocityX( Any(aIter.toDouble()) );
931 break;
933 case XML_ELEMENT(ANIMATION, XML_PHYSICS_ANIMATION_START_VELOCITY_Y):
934 case XML_ELEMENT(ANIMATION_OOO, XML_PHYSICS_ANIMATION_START_VELOCITY_Y):
935 case XML_ELEMENT(LO_EXT, XML_PHYSICS_ANIMATION_START_VELOCITY_Y):
937 Reference< XAnimatePhysics > xAnimatePhysics( mxNode, UNO_QUERY );
938 if( xAnimatePhysics.is() )
939 xAnimatePhysics->setStartVelocityY( Any(aIter.toDouble()) );
941 break;
943 case XML_ELEMENT(ANIMATION, XML_PHYSICS_ANIMATION_DENSITY):
944 case XML_ELEMENT(ANIMATION_OOO, XML_PHYSICS_ANIMATION_DENSITY):
945 case XML_ELEMENT(LO_EXT, XML_PHYSICS_ANIMATION_DENSITY):
947 Reference< XAnimatePhysics > xAnimatePhysics( mxNode, UNO_QUERY );
948 if( xAnimatePhysics.is() )
949 xAnimatePhysics->setDensity( Any(aIter.toDouble()) );
951 break;
953 case XML_ELEMENT(ANIMATION, XML_PHYSICS_ANIMATION_BOUNCINESS):
954 case XML_ELEMENT(ANIMATION_OOO, XML_PHYSICS_ANIMATION_BOUNCINESS):
955 case XML_ELEMENT(LO_EXT, XML_PHYSICS_ANIMATION_BOUNCINESS):
957 Reference< XAnimatePhysics > xAnimatePhysics( mxNode, UNO_QUERY );
958 if( xAnimatePhysics.is() )
959 xAnimatePhysics->setBounciness( Any(aIter.toDouble()) );
961 break;
963 case XML_ELEMENT(ANIMATION, XML_COLOR_INTERPOLATION):
964 case XML_ELEMENT(ANIMATION_OOO, XML_COLOR_INTERPOLATION):
966 Reference< XAnimateColor > xAnimateColor( mxNode, UNO_QUERY );
967 if( xAnimateColor.is() )
968 xAnimateColor->setColorInterpolation( IsXMLToken( aIter, XML_HSL ) ? AnimationColorSpace::HSL : AnimationColorSpace::RGB );
970 break;
972 case XML_ELEMENT(ANIMATION, XML_COLOR_INTERPOLATION_DIRECTION):
973 case XML_ELEMENT(ANIMATION_OOO, XML_COLOR_INTERPOLATION_DIRECTION):
975 Reference< XAnimateColor > xAnimateColor( mxNode, UNO_QUERY );
976 if( xAnimateColor.is() )
977 xAnimateColor->setDirection( IsXMLToken( aIter, XML_CLOCKWISE ) );
979 break;
981 case XML_ELEMENT(SVG, XML_TYPE):
982 case XML_ELEMENT(SVG_COMPAT, XML_TYPE):
984 Reference< XAnimateTransform > xTransform( mxNode, UNO_QUERY );
985 if( xTransform.is() )
987 if( SvXMLUnitConverter::convertEnum( nEnum, aIter.toView(), aAnimations_EnumMap_TransformType ) )
989 xTransform->setTransformType( nEnum );
990 switch( nEnum )
992 case AnimationTransformType::SCALE: meAttributeName = XML_SCALE; break;
993 case AnimationTransformType::ROTATE: meAttributeName = XML_ROTATE; break;
994 case AnimationTransformType::SKEWX: meAttributeName = XML_SKEWX; break;
995 case AnimationTransformType::SKEWY: meAttributeName = XML_SKEWY; break;
996 //case AnimationTransformType::TRANSLATE:
997 default:
998 meAttributeName = XML_TRANSLATE; break;
1003 break;
1005 case XML_ELEMENT(SMIL, XML_TYPE):
1006 case XML_ELEMENT(SMIL_COMPAT, XML_TYPE):
1007 case XML_ELEMENT(SMIL_SO52, XML_TYPE):
1009 if( xTransitionFilter.is() )
1011 if( SvXMLUnitConverter::convertEnum( nEnum, aIter.toView(), aAnimations_EnumMap_TransitionType ) )
1012 xTransitionFilter->setTransition( nEnum );
1015 break;
1017 case XML_ELEMENT(SMIL, XML_SUBTYPE):
1018 case XML_ELEMENT(SMIL_COMPAT, XML_SUBTYPE):
1019 case XML_ELEMENT(SMIL_SO52, XML_SUBTYPE):
1021 if( xTransitionFilter.is() )
1023 if( SvXMLUnitConverter::convertEnum( nEnum, aIter.toView(), aAnimations_EnumMap_TransitionSubType ) )
1024 xTransitionFilter->setSubtype( nEnum );
1027 break;
1029 case XML_ELEMENT(SMIL, XML_MODE):
1030 case XML_ELEMENT(SMIL_COMPAT, XML_MODE):
1031 case XML_ELEMENT(SMIL_SO52, XML_MODE):
1033 if( xTransitionFilter.is() )
1034 xTransitionFilter->setMode( IsXMLToken( aIter, XML_IN ) );
1036 break;
1038 case XML_ELEMENT(SMIL, XML_DIRECTION):
1039 case XML_ELEMENT(SMIL_COMPAT, XML_DIRECTION):
1040 case XML_ELEMENT(SMIL_SO52, XML_DIRECTION):
1042 if( xTransitionFilter.is() )
1043 xTransitionFilter->setDirection( IsXMLToken( aIter, XML_FORWARD ) );
1045 break;
1047 case XML_ELEMENT(SMIL, XML_FADECOLOR):
1048 case XML_ELEMENT(SMIL_COMPAT, XML_FADECOLOR):
1049 case XML_ELEMENT(SMIL_SO52, XML_FADECOLOR):
1051 if( xTransitionFilter.is() )
1053 sal_Int32 nColor(0);
1054 ::sax::Converter::convertColor(nColor, aIter.toView());
1055 xTransitionFilter->setFadeColor(nColor);
1058 break;
1060 case XML_ELEMENT(ANIMATION, XML_ITERATE_TYPE):
1061 case XML_ELEMENT(ANIMATION_OOO, XML_ITERATE_TYPE):
1063 if( SvXMLUnitConverter::convertEnum( nEnum, aIter.toView(), aAnimations_EnumMap_IterateType ) )
1065 if( xIter.is() )
1066 xIter->setIterateType( nEnum );
1069 break;
1071 case XML_ELEMENT(ANIMATION, XML_ITERATE_INTERVAL):
1072 case XML_ELEMENT(ANIMATION_OOO, XML_ITERATE_INTERVAL):
1074 if( xIter.is() )
1076 OUString rValue = aIter.toString();
1077 double fInterval = 0.0;
1078 if( rValue.match("P") )
1080 css::util::Duration aDuration;
1081 if (::sax::Converter::convertDuration(aDuration, rValue))
1083 fInterval = ((((aDuration.Hours * 60)
1084 + aDuration.Minutes) * 60) + aDuration.Seconds)
1085 + (aDuration.NanoSeconds / 1000000000.0);
1088 else
1090 fInterval = aIter.toDouble();
1093 xIter->setIterateInterval( fInterval );
1096 break;
1098 case XML_ELEMENT(PRESENTATION, XML_GROUP_ID):
1099 case XML_ELEMENT(PRESENTATION_SO52, XML_GROUP_ID):
1100 case XML_ELEMENT(PRESENTATION_OOO, XML_GROUP_ID):
1102 aUserData.emplace_back( "group-id", Any( aIter.toInt32() ) );
1104 break;
1106 case XML_ELEMENT(ANIMATION, XML_COMMAND):
1107 case XML_ELEMENT(ANIMATION_OOO, XML_COMMAND):
1109 if( xCommand.is() && nNodeType == AnimationNodeType::COMMAND )
1111 if( SvXMLUnitConverter::convertEnum( nEnum, aIter.toView(), aAnimations_EnumMap_Command ) )
1113 xCommand->setCommand( nEnum );
1117 break;
1119 default:
1121 // push all unknown attributes within the presentation namespace as user data
1122 if (IsTokenInNamespace(nToken, XML_NAMESPACE_PRESENTATION)
1123 || IsTokenInNamespace(nToken, XML_NAMESPACE_PRESENTATION_SO52)
1124 || IsTokenInNamespace(nToken, XML_NAMESPACE_PRESENTATION_OASIS)
1125 || IsTokenInNamespace(nToken, XML_NAMESPACE_PRESENTATION_OOO))
1127 aUserData.emplace_back( SvXMLImport::getNameFromToken(aIter.getToken()), Any( aIter.toString() ) );
1129 else
1130 XMLOFF_WARN_UNKNOWN("xmloff", aIter);
1135 if (!sXmlId.isEmpty())
1137 Reference< XInterface > const xRef( mxNode, UNO_QUERY );
1138 GetImport().getInterfaceToIdentifierMapper().registerReference(
1139 sXmlId, xRef );
1142 sal_Int32 nUserDataCount = aUserData.size();
1143 if( nUserDataCount )
1145 Sequence< NamedValue > aUnoUserData( nUserDataCount );
1146 NamedValue* pData = aUnoUserData.getArray();
1147 for (auto const& item : aUserData)
1148 *pData++ = item;
1150 mxNode->setUserData( aUnoUserData );
1153 // convert values
1154 if( xAnimate.is() )
1156 if( !aFrom.isEmpty() )
1157 xAnimate->setFrom( mpHelper->convertValue( meAttributeName, aFrom ) );
1159 if( !aBy.isEmpty() )
1160 xAnimate->setBy( mpHelper->convertValue( meAttributeName, aBy ) );
1162 if( !aTo.isEmpty() )
1163 xAnimate->setTo( mpHelper->convertValue( meAttributeName, aTo ) );
1165 if( !aValues.isEmpty() )
1166 xAnimate->setValues( mpHelper->convertValueSequence( meAttributeName, aValues ) );
1168 if (xAnimate->getValues().getLength() != xAnimate->getKeyTimes().getLength())
1169 throw css::io::WrongFormatException();
1172 catch (const css::io::WrongFormatException&)
1174 throw;
1176 catch (const RuntimeException&)
1178 TOOLS_WARN_EXCEPTION("xmloff.draw", "");
1182 css::uno::Reference< css::xml::sax::XFastContextHandler > AnimationNodeContext::createFastChildContext(sal_Int32 nElement,
1183 const css::uno::Reference<css::xml::sax::XFastAttributeList>& xAttrList)
1185 if( mxNode.is())
1186 return new AnimationNodeContext( mxNode, GetImport(), nElement, xAttrList, mpHelper );
1187 return nullptr;
1190 namespace {
1192 class AnimationsImport: public SvXMLImport, public XAnimationNodeSupplier
1194 public:
1195 explicit AnimationsImport( const Reference< XComponentContext > & rxContext );
1197 SvXMLImportContext* CreateFastContext(sal_Int32 nElement,
1198 const Reference<XFastAttributeList>& xAttrList) override;
1200 // XInterface
1201 virtual Any SAL_CALL queryInterface( const Type& aType ) override;
1202 virtual void SAL_CALL acquire() noexcept override;
1203 virtual void SAL_CALL release() noexcept override;
1205 // XAnimationNodeSupplier
1206 Reference< XAnimationNode > SAL_CALL getAnimationNode() override;
1208 private:
1209 Reference< XAnimationNode > mxRootNode;
1214 AnimationsImport::AnimationsImport( const Reference< XComponentContext > & rxContext )
1215 : SvXMLImport( rxContext, "xmloff::AnimationsImport", SvXMLImportFlags::META )
1216 //FIXME: the above "IMPORT_META" used to be a nonsensical "true", question
1217 // remains whether this should be IMPORT_META (same numerical value as
1218 // true) or default IMPORT_ALL
1220 mxRootNode.set( SequenceTimeContainer::create(rxContext), UNO_QUERY_THROW );
1223 // XInterface
1224 Any SAL_CALL AnimationsImport::queryInterface( const Type& aType )
1226 if ( aType == cppu::UnoType<XAnimationNodeSupplier>::get())
1228 return Any( Reference<XAnimationNodeSupplier>( this ) );
1230 else
1232 return SvXMLImport::queryInterface( aType );
1236 void SAL_CALL AnimationsImport::acquire() noexcept
1238 SvXMLImport::acquire();
1241 void SAL_CALL AnimationsImport::release() noexcept
1243 SvXMLImport::release();
1246 SvXMLImportContext *AnimationsImport::CreateFastContext(
1247 sal_Int32 nElement,
1248 const Reference<XFastAttributeList>& xAttrList)
1250 SvXMLImportContext* pContext = nullptr;
1252 if( nElement == XML_ELEMENT(ANIMATION, XML_SEQ) || nElement == XML_ELEMENT(ANIMATION_OOO, XML_SEQ) )
1254 pContext = new AnimationNodeContext( mxRootNode, *this, nElement, xAttrList );
1257 return pContext;
1260 // XAnimationNodeSupplier
1261 Reference< XAnimationNode > SAL_CALL AnimationsImport::getAnimationNode()
1263 return mxRootNode;
1266 void AnimationNodeContext::postProcessRootNode( const Reference< XAnimationNode >& xRootNode, Reference< XPropertySet > const & xPageProps )
1268 if( !(xRootNode.is() && xPageProps.is()) )
1269 return;
1273 Reference< XEnumerationAccess > xEnumerationAccess( xRootNode, UNO_QUERY_THROW );
1274 Reference< XEnumeration > xEnumeration( xEnumerationAccess->createEnumeration(), UNO_SET_THROW );
1275 if( xEnumeration->hasMoreElements() )
1277 Reference< XAnimationNode > xNode( xEnumeration->nextElement(), UNO_QUERY_THROW );
1278 if( xNode->getType() == AnimationNodeType::PAR )
1280 Event aEvent;
1281 if( (xNode->getBegin() >>= aEvent) && (aEvent.Trigger == EventTrigger::BEGIN_EVENT) )
1283 // found transition node
1284 Reference< XEnumerationAccess > xChildEnumerationAccess( xNode, UNO_QUERY_THROW );
1285 Reference< XEnumeration > xChildEnumeration( xChildEnumerationAccess->createEnumeration(), UNO_SET_THROW );
1286 while( xChildEnumeration->hasMoreElements() )
1288 Reference< XAnimationNode > xChildNode( xChildEnumeration->nextElement(), UNO_QUERY_THROW );
1289 switch( xChildNode->getType() )
1291 case AnimationNodeType::TRANSITIONFILTER:
1293 Reference< XTransitionFilter > xTransFilter( xChildNode, UNO_QUERY_THROW );
1295 xPageProps->setPropertyValue("TransitionType", Any( xTransFilter->getTransition() ) );
1296 xPageProps->setPropertyValue("TransitionSubtype", Any( xTransFilter->getSubtype() ) );
1297 xPageProps->setPropertyValue("TransitionDirection", Any( xTransFilter->getDirection() ) );
1298 xPageProps->setPropertyValue("TransitionFadeColor", Any( xTransFilter->getFadeColor() ) );
1300 double fDuration;
1301 if( xTransFilter->getDuration() >>= fDuration )
1302 xPageProps->setPropertyValue("TransitionDuration", Any( fDuration ) );
1305 break;
1307 case AnimationNodeType::COMMAND:
1309 Reference< XCommand > xCommand( xChildNode, UNO_QUERY_THROW );
1310 if( xCommand->getCommand() == EffectCommands::STOPAUDIO )
1312 xPageProps->setPropertyValue("Sound", Any(true) );
1315 break;
1317 case AnimationNodeType::AUDIO:
1319 Reference< XAudio > xAudio( xChildNode, UNO_QUERY_THROW );
1320 OUString sSoundURL;
1321 if( (xAudio->getSource() >>= sSoundURL) && !sSoundURL.isEmpty() )
1323 xPageProps->setPropertyValue("Sound", Any(sSoundURL) );
1325 Timing eTiming;
1326 if( (xAudio->getRepeatCount() >>= eTiming) && (eTiming == Timing_INDEFINITE) )
1327 xPageProps->setPropertyValue("LoopSound", Any( true ) );
1330 break;
1335 Reference< XTimeContainer > xRootContainer( xRootNode, UNO_QUERY_THROW );
1336 xRootContainer->removeChild( xNode );
1341 catch (const Exception&)
1343 TOOLS_WARN_EXCEPTION("xmloff.draw", "");
1347 } // namespace xmloff
1349 extern "C" SAL_DLLPUBLIC_EXPORT uno::XInterface*
1350 com_sun_star_comp_Xmloff_AnimationsImport(uno::XComponentContext* pCtx,
1351 uno::Sequence<uno::Any> const& /*rSeq*/)
1353 return cppu::acquire(new xmloff::AnimationsImport(pCtx));
1356 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */