bump product version to 5.0.4.1
[LibreOffice.git] / xmloff / source / draw / animationimport.cxx
blob1a3f2bdd890b20fa0626ffd81dd9d11189e15433
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 <xmloff/unointerfacetouniqueidentifiermapper.hxx>
21 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
22 #include <com/sun/star/lang/XServiceInfo.hpp>
23 #include <com/sun/star/lang/XInitialization.hpp>
24 #include <com/sun/star/animations/AnimationTransformType.hpp>
25 #include <com/sun/star/animations/XAnimationNodeSupplier.hpp>
26 #include <com/sun/star/presentation/AnimationEffect.hpp>
27 #include <com/sun/star/presentation/AnimationSpeed.hpp>
28 #include <com/sun/star/animations/AnimationNodeType.hpp>
29 #include <com/sun/star/animations/SequenceTimeContainer.hpp>
30 #include <com/sun/star/animations/XIterateContainer.hpp>
31 #include <com/sun/star/animations/XAnimateMotion.hpp>
32 #include <com/sun/star/animations/XAnimateColor.hpp>
33 #include <com/sun/star/animations/XAnimateTransform.hpp>
34 #include <com/sun/star/animations/XTransitionFilter.hpp>
35 #include <com/sun/star/animations/XCommand.hpp>
36 #include <com/sun/star/animations/XAudio.hpp>
37 #include <com/sun/star/animations/ValuePair.hpp>
38 #include <com/sun/star/animations/AnimationColorSpace.hpp>
39 #include <com/sun/star/presentation/EffectPresetClass.hpp>
40 #include <com/sun/star/animations/Timing.hpp>
41 #include <com/sun/star/animations/Event.hpp>
42 #include <com/sun/star/beans/XPropertySet.hpp>
43 #include <com/sun/star/xml/sax/XAttributeList.hpp>
44 #include <com/sun/star/text/XTextCursor.hpp>
45 #include <com/sun/star/text/XTextRangeCompare.hpp>
46 #include <com/sun/star/presentation/ParagraphTarget.hpp>
47 #include <com/sun/star/container/XEnumerationAccess.hpp>
48 #include <com/sun/star/animations/EventTrigger.hpp>
49 #include <com/sun/star/presentation/EffectCommands.hpp>
50 #include <com/sun/star/util/Duration.hpp>
51 #include <comphelper/processfactory.hxx>
52 #include <cppuhelper/implbase1.hxx>
54 #include <sax/tools/converter.hxx>
56 #include <list>
57 #include <xmloff/xmltypes.hxx>
58 #include "sdpropls.hxx"
59 #include <xmloff/xmltoken.hxx>
60 #include <xmloff/xmlimp.hxx>
61 #include <xmloff/xmlnmspe.hxx>
62 #include <xmloff/xmluconv.hxx>
63 #include <osl/mutex.hxx>
64 #include <osl/diagnose.h>
65 #include <xmloff/nmspmap.hxx>
66 #include <xmloff/xmlprhdl.hxx>
67 #include "anim.hxx"
68 #include "facreg.hxx"
70 #include "animations.hxx"
71 #include "animationimport.hxx"
73 using namespace ::std;
74 using namespace ::cppu;
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::XAttributeList;
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::XMultiServiceFactory;
90 using ::com::sun::star::lang::XInitialization;
92 Sequence< OUString > SAL_CALL AnimationsImport_getSupportedServiceNames() throw()
94 const OUString aServiceName( "com.sun.star.comp.Xmloff.AnimationsImport" );
95 const Sequence< OUString > aSeq( &aServiceName, 1 );
96 return aSeq;
99 OUString SAL_CALL AnimationsImport_getImplementationName() throw()
101 return OUString( "xmloff::AnimationsImport" );
104 namespace xmloff
107 class AnimationsImportHelperImpl
109 private:
110 SvXMLImport& mrImport;
112 SvXMLTokenMap* mpAnimationNodeTokenMap;
113 SvXMLTokenMap* mpAnimationNodeAttributeTokenMap;
115 public:
116 AnimationsImportHelperImpl( SvXMLImport& rImport );
117 ~AnimationsImportHelperImpl();
119 const SvXMLTokenMap& getAnimationNodeTokenMap();
120 const SvXMLTokenMap& getAnimationNodeAttributeTokenMap();
122 Any convertValue( XMLTokenEnum eAttributeName, const OUString& rValue );
123 Sequence< Any > convertValueSequence( XMLTokenEnum eAttributeName, const OUString& rValue );
125 Any convertTarget( const OUString& rValue );
126 static Any convertPath( const OUString& rValue );
127 Any convertTiming( const OUString& rValue );
128 static Sequence< double > convertKeyTimes( const OUString& rValue );
129 static Sequence< TimeFilterPair > convertTimeFilter( const OUString& rValue );
131 const OUString mastrHSL;
134 AnimationsImportHelperImpl::AnimationsImportHelperImpl( SvXMLImport& rImport )
135 : mrImport( rImport ),
136 mpAnimationNodeTokenMap( NULL ),
137 mpAnimationNodeAttributeTokenMap( NULL ),
138 mastrHSL( "hsl" )
142 AnimationsImportHelperImpl::~AnimationsImportHelperImpl()
144 delete mpAnimationNodeTokenMap;
145 delete mpAnimationNodeAttributeTokenMap;
148 const SvXMLTokenMap& AnimationsImportHelperImpl::getAnimationNodeTokenMap()
150 if( mpAnimationNodeTokenMap == NULL )
152 static const SvXMLTokenMapEntry aAnimationNodeTokenMap[] =
154 { XML_NAMESPACE_ANIMATION, XML_PAR, (sal_uInt16)AnimationNodeType::PAR },
155 { XML_NAMESPACE_ANIMATION, XML_SEQ, (sal_uInt16)AnimationNodeType::SEQ },
156 { XML_NAMESPACE_ANIMATION, XML_ITERATE, (sal_uInt16)AnimationNodeType::ITERATE },
157 { XML_NAMESPACE_ANIMATION, XML_ANIMATE, (sal_uInt16)AnimationNodeType::ANIMATE },
158 { XML_NAMESPACE_ANIMATION, XML_SET, (sal_uInt16)AnimationNodeType::SET },
159 { XML_NAMESPACE_ANIMATION, XML_ANIMATEMOTION, (sal_uInt16)AnimationNodeType::ANIMATEMOTION },
160 { XML_NAMESPACE_ANIMATION, XML_ANIMATECOLOR, (sal_uInt16)AnimationNodeType::ANIMATECOLOR },
161 { XML_NAMESPACE_ANIMATION, XML_ANIMATETRANSFORM, (sal_uInt16)AnimationNodeType::ANIMATETRANSFORM },
162 { XML_NAMESPACE_ANIMATION, XML_TRANSITIONFILTER, (sal_uInt16)AnimationNodeType::TRANSITIONFILTER },
163 { XML_NAMESPACE_ANIMATION, XML_AUDIO, (sal_uInt16)AnimationNodeType::AUDIO },
164 { XML_NAMESPACE_ANIMATION, XML_COMMAND, (sal_uInt16)AnimationNodeType::COMMAND },
165 XML_TOKEN_MAP_END
168 mpAnimationNodeTokenMap = new SvXMLTokenMap( aAnimationNodeTokenMap );
171 return *mpAnimationNodeTokenMap;
174 enum AnimationNodeAttributes
176 ANA_Begin,
177 ANA_Dur,
178 ANA_End,
179 ANA_Fill,
180 ANA_FillDefault,
181 ANA_Restart,
182 ANA_RestartDefault,
183 ANA_Accelerate,
184 ANA_Decelerate,
185 ANA_AutoReverse,
186 ANA_RepeatCount,
187 ANA_RepeatDur,
188 ANA_EndSync,
189 ANA_Node_Type,
190 ANA_Preset_ID,
191 ANA_Preset_Sub_Type,
192 ANA_Preset_Class,
193 ANA_After_Effect,
194 ANA_Target,
195 ANA_XLink,
196 ANA_MasterElement,
197 ANA_SubItem,
198 ANA_AttributeName,
199 ANA_Values,
200 ANA_From,
201 ANA_By,
202 ANA_To,
203 ANA_KeyTimes,
204 ANA_CalcMode,
205 ANA_Accumulate,
206 ANA_AdditiveMode,
207 ANA_KeySplines,
208 ANA_Path,
209 ANA_ColorSpace,
210 ANA_ColorDirection,
211 ANA_TransformType,
212 ANA_TransitionType,
213 ANA_TransitionSubType,
214 ANA_Mode,
215 ANA_Direction,
216 ANA_FadeColor,
217 ANA_IterateType,
218 ANA_IterateInterval,
219 ANA_Formula,
220 ANA_ANIMID,
221 ANA_XMLID,
222 ANA_Group_Id,
223 ANA_Command,
224 ANA_Volume
227 const SvXMLTokenMap& AnimationsImportHelperImpl::getAnimationNodeAttributeTokenMap()
229 if( mpAnimationNodeAttributeTokenMap == NULL )
231 static const SvXMLTokenMapEntry aAnimationNodeAttributeTokenMap[] =
233 { XML_NAMESPACE_SMIL, XML_BEGIN, (sal_uInt16)ANA_Begin },
234 { XML_NAMESPACE_SMIL, XML_DUR, (sal_uInt16)ANA_Dur },
235 { XML_NAMESPACE_SMIL, XML_END, (sal_uInt16)ANA_End },
236 { XML_NAMESPACE_SMIL, XML_FILL, (sal_uInt16)ANA_Fill },
237 { XML_NAMESPACE_SMIL, XML_FILLDEFAULT, (sal_uInt16)ANA_FillDefault },
238 { XML_NAMESPACE_SMIL, XML_RESTART, (sal_uInt16)ANA_Restart },
239 { XML_NAMESPACE_SMIL, XML_RESTARTDEFAULT, (sal_uInt16)ANA_RestartDefault },
240 { XML_NAMESPACE_SMIL, XML_ACCELERATE, (sal_uInt16)ANA_Accelerate },
241 { XML_NAMESPACE_SMIL, XML_DECELERATE, (sal_uInt16)ANA_Decelerate },
242 { XML_NAMESPACE_SMIL, XML_AUTOREVERSE, (sal_uInt16)ANA_AutoReverse },
243 { XML_NAMESPACE_SMIL, XML_REPEATCOUNT, (sal_uInt16)ANA_RepeatCount },
244 { XML_NAMESPACE_SMIL, XML_REPEATDUR, (sal_uInt16)ANA_RepeatDur },
245 { XML_NAMESPACE_SMIL, XML_ENDSYNC, (sal_uInt16)ANA_EndSync },
246 { XML_NAMESPACE_PRESENTATION, XML_NODE_TYPE, (sal_uInt16)ANA_Node_Type },
247 { XML_NAMESPACE_PRESENTATION, XML_PRESET_ID, (sal_uInt16)ANA_Preset_ID },
248 { XML_NAMESPACE_PRESENTATION, XML_PRESET_SUB_TYPE, (sal_uInt16)ANA_Preset_Sub_Type },
249 { XML_NAMESPACE_PRESENTATION, XML_PRESET_CLASS, (sal_uInt16)ANA_Preset_Class },
250 { XML_NAMESPACE_PRESENTATION, XML_AFTER_EFFECT, (sal_uInt16)ANA_After_Effect },
251 { XML_NAMESPACE_SMIL, XML_TARGETELEMENT, (sal_uInt16)ANA_Target },
252 { XML_NAMESPACE_XLINK, XML_HREF, (sal_uInt16)ANA_XLink },
253 { XML_NAMESPACE_PRESENTATION, XML_MASTER_ELEMENT, (sal_uInt16)ANA_MasterElement },
254 { XML_NAMESPACE_ANIMATION, XML_SUB_ITEM, (sal_uInt16)ANA_SubItem },
255 { XML_NAMESPACE_SMIL, XML_ATTRIBUTENAME, (sal_uInt16)ANA_AttributeName },
256 { XML_NAMESPACE_SMIL, XML_VALUES, (sal_uInt16)ANA_Values },
257 { XML_NAMESPACE_SMIL, XML_FROM, (sal_uInt16)ANA_From },
258 { XML_NAMESPACE_SMIL, XML_BY, (sal_uInt16)ANA_By },
259 { XML_NAMESPACE_SMIL, XML_TO, (sal_uInt16)ANA_To },
260 { XML_NAMESPACE_SMIL, XML_KEYTIMES, (sal_uInt16)ANA_KeyTimes },
261 { XML_NAMESPACE_SMIL, XML_CALCMODE, (sal_uInt16)ANA_CalcMode },
262 { XML_NAMESPACE_SMIL, XML_ACCUMULATE, (sal_uInt16)ANA_Accumulate },
263 { XML_NAMESPACE_PRESENTATION, XML_ADDITIVE, (sal_uInt16)ANA_AdditiveMode },
264 { XML_NAMESPACE_SMIL, XML_ADDITIVE, (sal_uInt16)ANA_AdditiveMode },
265 { XML_NAMESPACE_SMIL, XML_KEYSPLINES, (sal_uInt16)ANA_KeySplines },
266 { XML_NAMESPACE_SVG, XML_PATH, (sal_uInt16)ANA_Path },
267 { XML_NAMESPACE_ANIMATION, XML_COLOR_INTERPOLATION, (sal_uInt16)ANA_ColorSpace },
268 { XML_NAMESPACE_ANIMATION, XML_COLOR_INTERPOLATION_DIRECTION, (sal_uInt16)ANA_ColorDirection },
269 { XML_NAMESPACE_SVG, XML_TYPE, (sal_uInt16)ANA_TransformType },
270 { XML_NAMESPACE_SMIL, XML_TYPE, (sal_uInt16)ANA_TransitionType },
271 { XML_NAMESPACE_SMIL, XML_SUBTYPE, (sal_uInt16)ANA_TransitionSubType },
272 { XML_NAMESPACE_SMIL, XML_MODE, (sal_uInt16)ANA_Mode },
273 { XML_NAMESPACE_SMIL, XML_DIRECTION, (sal_uInt16)ANA_Direction },
274 { XML_NAMESPACE_SMIL, XML_FADECOLOR, (sal_uInt16)ANA_FadeColor },
275 { XML_NAMESPACE_ANIMATION, XML_ITERATE_TYPE, (sal_uInt16)ANA_IterateType },
276 { XML_NAMESPACE_ANIMATION, XML_ITERATE_INTERVAL, (sal_uInt16)ANA_IterateInterval },
277 { XML_NAMESPACE_ANIMATION, XML_FORMULA, (sal_uInt16)ANA_Formula },
278 { XML_NAMESPACE_ANIMATION, XML_ID, (sal_uInt16)ANA_ANIMID },
279 { XML_NAMESPACE_XML, XML_ID, (sal_uInt16)ANA_XMLID },
280 { XML_NAMESPACE_PRESENTATION, XML_GROUP_ID, (sal_uInt16)ANA_Group_Id },
281 { XML_NAMESPACE_ANIMATION, XML_AUDIO_LEVEL, (sal_uInt16)ANA_Volume },
282 { XML_NAMESPACE_ANIMATION, XML_COMMAND, (sal_uInt16)ANA_Command },
284 XML_TOKEN_MAP_END
287 mpAnimationNodeAttributeTokenMap = new SvXMLTokenMap( aAnimationNodeAttributeTokenMap );
290 return *mpAnimationNodeAttributeTokenMap;
293 static bool isDouble( const OUString& rValue )
295 sal_Int32 nLength = rValue.getLength();
296 const sal_Unicode * pStr = rValue.getStr();
297 while( nLength )
299 if( (*pStr >= '0' && *pStr <= '9') || *pStr == '-' || *pStr == '.' || *pStr == '+' || *pStr == 'e' || *pStr == 'E' )
301 pStr++;
302 nLength--;
304 else
306 return false;
310 return true;
313 static bool isTime( const OUString& rValue )
315 sal_Int32 nLength = rValue.getLength();
316 const sal_Unicode * pStr;
317 for( pStr = rValue.getStr(); nLength; pStr++, nLength-- )
319 if( !( (*pStr >= '0' && *pStr <= '9') || *pStr == '-' || *pStr == '.' || *pStr == '+' || *pStr == 'e' || *pStr == 'E' ) )
320 break;
323 // return true if this is a double (if someone forgot the 's' we silently ignore it)
324 // or if it's a double that ends with a 's' or 'S'
325 return (nLength == 0) || ((*pStr == 's' || *pStr == 'S') && (nLength == 1));
328 static sal_Int32 count_codes( const OUString& rString, sal_Unicode nCode )
330 sal_Int32 nCount = 0;
331 sal_Int32 fromIndex = 0;
333 while(true)
335 fromIndex = rString.indexOf( nCode, fromIndex );
336 if( fromIndex == -1 )
337 break;
339 fromIndex++;
340 nCount++;
343 return nCount;
346 Any AnimationsImportHelperImpl::convertTarget( const OUString& rValue )
350 Reference< XInterface > xRef( mrImport.getInterfaceToIdentifierMapper().getReference( rValue ) );
352 Reference< XShape > _xShape( xRef, UNO_QUERY );
353 if( _xShape.is() )
354 return makeAny( _xShape );
356 Reference< XTextCursor > xTextCursor( xRef, UNO_QUERY );
357 if( xTextCursor.is() )
359 Reference< XTextRange > xStart( xTextCursor->getStart() ), xRange;
360 Reference< XShape > xShape( xTextCursor->getText(), UNO_QUERY_THROW );
361 Reference< XTextRangeCompare > xTextRangeCompare( xShape, UNO_QUERY_THROW );
363 Reference< XEnumerationAccess > xParaEnumAccess( xShape, UNO_QUERY_THROW );
364 Reference< XEnumeration > xEnumeration( xParaEnumAccess->createEnumeration(), UNO_QUERY_THROW );
365 sal_Int16 nParagraph = 0;
367 while( xEnumeration->hasMoreElements() )
369 xEnumeration->nextElement() >>= xRange;
371 // break if start of selection is prior to end of current paragraph
372 if( xRange.is() && (xTextRangeCompare->compareRegionEnds( xStart, xRange ) >= 0 ) )
374 return makeAny( ParagraphTarget( xShape, nParagraph ) );
377 nParagraph++;
381 catch (const RuntimeException&)
383 OSL_FAIL( "xmloff::AnimationsImportImpl::convertTarget(), RuntimeException caught!" );
386 Any aAny;
387 return aAny;
390 Any AnimationsImportHelperImpl::convertValue( XMLTokenEnum eAttributeName, const OUString& rValue )
392 sal_Int32 nCommaPos = -1, nPos;
393 sal_Int32 nOpenBrakets = 0;
394 for( nPos = 0; (nPos < rValue.getLength()) && (nCommaPos == -1); nPos++ )
396 switch( rValue[nPos] )
398 case ',':
399 if( nOpenBrakets == 0 )
400 nCommaPos = nPos;
401 break;
402 case '(':
403 case '[':
404 case '{':
405 nOpenBrakets++;
406 break;
407 case ')':
408 case ']':
409 case '}':
410 nOpenBrakets--;
411 break;
415 if( nCommaPos >= 0 )
417 ValuePair aPair;
418 aPair.First = convertValue( eAttributeName, rValue.copy( 0, nCommaPos ) );
419 aPair.Second = convertValue( eAttributeName, rValue.copy( nCommaPos+1, rValue.getLength() - nCommaPos - 1 ) );
420 return makeAny( aPair );
422 else
424 Any aAny;
425 sal_Int32 nType = XML_TYPE_STRING;
427 if( rValue.getLength() ) switch( eAttributeName )
429 case XML_X:
430 case XML_Y:
431 case XML_WIDTH:
432 case XML_HEIGHT:
433 case XML_TRANSLATE:
435 return makeAny( rValue );
438 case XML_SCALE:
439 case XML_SKEWY:
440 case XML_SKEWX:
441 case XML_OPACITY:
442 case XML_ROTATE: nType = XML_TYPE_DOUBLE; break;
443 case XML_TEXT_ROTATION_ANGLE:nType = XML_TYPE_TEXT_ROTATION_ANGLE; break;
444 case XML_FILL_COLOR:
445 case XML_STROKE_COLOR:
446 case XML_DIM:
447 case XML_COLOR: nType = XML_TYPE_COLOR; break;
448 case XML_FILL: nType = XML_SD_TYPE_FILLSTYLE; break;
449 case XML_STROKE: nType = XML_SD_TYPE_STROKE; break;
450 case XML_FONT_WEIGHT: nType = XML_TYPE_TEXT_WEIGHT; break;
451 case XML_FONT_STYLE: nType = XML_TYPE_TEXT_POSTURE; break;
452 case XML_TEXT_UNDERLINE: nType = XML_TYPE_TEXT_UNDERLINE_STYLE; break;
453 case XML_FONT_SIZE: nType = XML_TYPE_DOUBLE_PERCENT; break;
454 case XML_VISIBILITY: nType = XML_SD_TYPE_PRESPAGE_VISIBILITY; break;
456 default:
457 if( !rValue.isEmpty() )
458 aAny <<= rValue;
459 return aAny;
462 const XMLPropertyHandler* pHandler = mrImport.GetShapeImport()->GetSdPropHdlFactory()->GetPropertyHandler( nType );
463 if( pHandler )
464 pHandler->importXML( rValue, aAny, mrImport.GetMM100UnitConverter() );
466 return aAny;
470 Sequence< Any > AnimationsImportHelperImpl::convertValueSequence( XMLTokenEnum eAttributeName, const OUString& rValue )
472 Sequence< Any > aValues;
474 // do we have any value at all?
475 if( !rValue.isEmpty() )
477 sal_Int32 nElements = count_codes( rValue, (sal_Unicode)';') + 1; // a non empty string has at least one value
479 // prepare the sequence
480 aValues.realloc( nElements );
482 // fill the sequence
483 Any* pValues = aValues.getArray();
484 sal_Int32 nIndex;
485 for( nIndex = 0; nElements && (nIndex >= 0); nElements-- )
487 *pValues++ = convertValue( eAttributeName, rValue.getToken( 0, ';', nIndex ) );
491 return aValues;
494 Any AnimationsImportHelperImpl::convertTiming( const OUString& rValue )
496 Any aAny;
498 // do we have any value at all?
499 if( !rValue.isEmpty() )
501 // count the values
502 sal_Int32 nElements = count_codes( rValue, (sal_Unicode)';' ) + 1; // a non empty string has at least one value
504 if( nElements == 1 )
506 if( IsXMLToken( rValue, XML_MEDIA ) )
508 aAny <<= Timing_MEDIA;
510 else if( IsXMLToken( rValue, XML_INDEFINITE ) )
512 aAny <<= Timing_INDEFINITE;
514 else if( isTime( rValue ) )
516 aAny <<= rValue.toDouble();
518 else
520 Event aEvent;
521 aEvent.Repeat = 0;
522 aEvent.Trigger = 0;
524 OUString aEventTrigger;
526 sal_Int32 nPos = rValue.indexOf( (sal_Unicode)'+' );
527 if( nPos == -1 )
529 aEventTrigger = rValue;
531 else
533 aEventTrigger = rValue.copy( 0, nPos );
535 // convert offset
536 aEvent.Offset <<= convertTiming( rValue.copy( nPos + 1 ) );
539 nPos = aEventTrigger.indexOf( (sal_Unicode)'.' );
540 if( nPos != -1 )
542 aEvent.Source <<= mrImport.getInterfaceToIdentifierMapper().getReference( aEventTrigger.copy( 0, nPos ) );
543 aEventTrigger = aEventTrigger.copy( nPos + 1 );
546 sal_uInt16 nEnum;
547 if( SvXMLUnitConverter::convertEnum( nEnum, aEventTrigger, getAnimationsEnumMap(Animations_EnumMap_EventTrigger) ) )
549 aEvent.Trigger = (sal_Int16)nEnum;
551 else
553 OSL_FAIL("AnimationsImportHelperImpl::convertTiming(), unknown event trigger!");
556 aAny <<= aEvent;
559 else
561 // fill the sequence
562 Sequence< Any > aValues( nElements );
563 Any* pValues = aValues.getArray();
564 sal_Int32 nIndex = 0;
565 while( (nElements--) && (nIndex >= 0) )
566 *pValues++ = convertTiming( rValue.getToken( 0, ';', nIndex ) );
568 aAny <<= aValues;
571 return aAny;
574 Sequence< double > AnimationsImportHelperImpl::convertKeyTimes( const OUString& rValue )
576 sal_Int32 nElements = 0;
578 if( !rValue.isEmpty() )
579 nElements = count_codes( rValue, (sal_Unicode)';' ) + 1; // a non empty string has at least one value
581 Sequence< double > aKeyTimes( nElements );
583 if( nElements )
585 double* pValues = aKeyTimes.getArray();
586 sal_Int32 nIndex = 0;
587 while( (nElements--) && (nIndex >= 0) )
588 *pValues++ = rValue.getToken( 0, ';', nIndex ).toDouble();
591 return aKeyTimes;
594 Sequence< TimeFilterPair > AnimationsImportHelperImpl::convertTimeFilter( const OUString& rValue )
596 sal_Int32 nElements = 0;
598 if( !rValue.isEmpty() )
599 nElements = count_codes( rValue, (sal_Unicode)';' ) + 1; // a non empty string has at least one value
601 Sequence< TimeFilterPair > aTimeFilter( nElements );
603 if( nElements )
605 TimeFilterPair* pValues = aTimeFilter.getArray();
606 sal_Int32 nIndex = 0;
607 while( (nElements--) && (nIndex >= 0) )
609 const OUString aToken( rValue.getToken( 0, ';', nIndex ) );
611 sal_Int32 nPos = aToken.indexOf( ',' );
612 if( nPos >= 0 )
614 pValues->Time = aToken.copy( 0, nPos ).toDouble();
615 pValues->Progress = aToken.copy( nPos+1, aToken.getLength() - nPos - 1 ).toDouble();
617 pValues++;
621 return aTimeFilter;
624 Any AnimationsImportHelperImpl::convertPath( const OUString& rValue )
626 return makeAny( rValue );
629 TYPEINIT1( AnimationNodeContext, SvXMLImportContext );
631 AnimationNodeContext::AnimationNodeContext(
632 const Reference< XAnimationNode >& xParentNode,
633 SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLocalName,
634 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList,
635 AnimationsImportHelperImpl* pHelper /* = NULL */ )
636 : SvXMLImportContext(rImport, nPrfx, rLocalName),
637 mpHelper( pHelper ),
638 mbRootContext( pHelper == NULL )
642 if( mbRootContext )
644 mpHelper = new AnimationsImportHelperImpl( rImport );
645 mxNode = xParentNode;
647 else
649 sal_Int16 nPresetClass = EffectPresetClass::CUSTOM;
651 const sal_Char* pServiceName = 0;
653 sal_Int16 nNodeType = (sal_Int16)mpHelper->getAnimationNodeTokenMap().Get( nPrfx, rLocalName );
654 switch( nNodeType )
656 case AnimationNodeType::SEQ: pServiceName = "com.sun.star.animations.SequenceTimeContainer"; break;
657 case AnimationNodeType::ITERATE: pServiceName = "com.sun.star.animations.IterateContainer"; break;
658 case AnimationNodeType::ANIMATE: pServiceName = "com.sun.star.animations.Animate"; break;
659 case AnimationNodeType::SET: pServiceName = "com.sun.star.animations.AnimateSet"; break;
660 case AnimationNodeType::ANIMATEMOTION: pServiceName = "com.sun.star.animations.AnimateMotion"; break;
661 case AnimationNodeType::ANIMATECOLOR: pServiceName = "com.sun.star.animations.AnimateColor"; break;
662 case AnimationNodeType::ANIMATETRANSFORM: pServiceName = "com.sun.star.animations.AnimateTransform"; break;
663 case AnimationNodeType::TRANSITIONFILTER: pServiceName = "com.sun.star.animations.TransitionFilter"; break;
664 case AnimationNodeType::AUDIO: pServiceName = "com.sun.star.animations.Audio"; break;
665 case AnimationNodeType::COMMAND: pServiceName = "com.sun.star.animations.Command"; break;
666 case AnimationNodeType::PAR:
668 const sal_Int16 nCount = xAttrList.is() ? xAttrList->getLength() : 0;
669 sal_Int16 nAttribute;
670 for( nAttribute = 0; nAttribute < nCount; nAttribute++ )
672 OUString aLocalName;
673 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( xAttrList->getNameByIndex( nAttribute ), &aLocalName );
674 if( (nPrefix == XML_NAMESPACE_PRESENTATION) && IsXMLToken( aLocalName, XML_PRESET_ID ) )
676 const OUString& rValue = xAttrList->getValueByIndex( nAttribute );
677 if ( rValue == "ooo-entrance-random" )
679 nPresetClass = EffectPresetClass::ENTRANCE;
681 else if ( rValue == "ooo-exit-random" )
683 nPresetClass = EffectPresetClass::EXIT;
686 if( nPresetClass != EffectPresetClass::CUSTOM )
688 pServiceName = "com.sun.star.comp.sd.RandomAnimationNode";
689 break;
693 if( !pServiceName )
694 pServiceName = "com.sun.star.animations.ParallelTimeContainer";
696 break;
697 default:
698 pServiceName = 0;
701 if( pServiceName )
703 Reference< XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
705 mxNode = Reference< XAnimationNode >(
706 xContext->getServiceManager()->createInstanceWithContext(OUString::createFromAscii(pServiceName), xContext),
707 UNO_QUERY_THROW );
709 if( nPresetClass != EffectPresetClass::CUSTOM )
711 Reference< XInitialization > xInit( mxNode, UNO_QUERY_THROW );
712 const Any aAny( makeAny( nPresetClass ) );
713 Sequence< Any > aArgs( &aAny, 1 ) ;
714 xInit->initialize( aArgs );
717 init_node( xAttrList );
719 Reference< XTimeContainer > xParentContainer( xParentNode, UNO_QUERY_THROW );
720 xParentContainer->appendChild( mxNode );
724 catch (const RuntimeException&)
726 OSL_FAIL( "xmloff::AnimationsImportImpl::AnimationsImportImpl(), RuntimeException caught!" );
730 AnimationNodeContext::~AnimationNodeContext()
732 if( mbRootContext )
733 delete mpHelper;
736 void AnimationNodeContext::StartElement( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& )
738 // code of StartElement is moved to init_node that is now called
739 // in c'tor before appending this node to its parent.
740 // This is needed for random nodes that need the correct target
741 // set when child nodes are appended.
744 void AnimationNodeContext::init_node( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList )
746 if( mxNode.is() ) try
748 const sal_Int16 nNodeType = mxNode->getType();
750 // query for optional interfaces that are often used later
751 Reference< XAnimate > xAnimate( mxNode, UNO_QUERY );
752 Reference< XCommand > xCommand( mxNode, UNO_QUERY );
753 Reference< XTransitionFilter > xTransitionFilter( mxNode, UNO_QUERY );
754 Reference< XIterateContainer > xIter( mxNode, UNO_QUERY );
756 std::list< NamedValue > aUserData;
757 XMLTokenEnum meAttributeName = XML_TOKEN_INVALID;
758 OUString aFrom, aBy, aTo, aValues;
759 bool bHaveXmlId( false );
760 OUString sXmlId;
762 const sal_Int16 nCount = xAttrList.is() ? xAttrList->getLength() : 0;
763 sal_uInt16 nEnum;
764 sal_Int16 nAttribute;
765 for( nAttribute = 0; nAttribute < nCount; nAttribute++ )
767 const OUString& rAttrName = xAttrList->getNameByIndex( nAttribute );
768 const OUString& rValue = xAttrList->getValueByIndex( nAttribute );
770 OUString aLocalName;
771 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName );
772 switch( mpHelper->getAnimationNodeAttributeTokenMap().Get( nPrefix, aLocalName ) )
774 case ANA_Begin:
776 mxNode->setBegin( mpHelper->convertTiming( rValue ) );
778 break;
779 case ANA_Dur:
781 mxNode->setDuration( mpHelper->convertTiming( rValue ) );
783 break;
784 case ANA_End:
786 mxNode->setEnd( mpHelper->convertTiming( rValue ) );
788 break;
789 case ANA_Fill:
791 if( SvXMLUnitConverter::convertEnum( nEnum, rValue, getAnimationsEnumMap(Animations_EnumMap_Fill) ) )
792 mxNode->setFill( (sal_Int16)nEnum );
794 break;
795 case ANA_FillDefault:
797 if( SvXMLUnitConverter::convertEnum( nEnum, rValue, getAnimationsEnumMap(Animations_EnumMap_FillDefault) ) )
798 mxNode->setFillDefault( (sal_Int16)nEnum );
800 break;
801 case ANA_Restart:
803 if( SvXMLUnitConverter::convertEnum( nEnum, rValue, getAnimationsEnumMap(Animations_EnumMap_Restart) ) )
804 mxNode->setRestart( (sal_Int16)nEnum );
806 break;
807 case ANA_RestartDefault:
809 if( SvXMLUnitConverter::convertEnum( nEnum, rValue, getAnimationsEnumMap(Animations_EnumMap_RestartDefault) ) )
810 mxNode->setRestartDefault( (sal_Int16)nEnum );
812 break;
813 case ANA_Accelerate:
815 if( isDouble( rValue ) )
816 mxNode->setAcceleration( rValue.toDouble() );
818 break;
819 case ANA_Decelerate:
821 if( isDouble( rValue ) )
822 mxNode->setDecelerate( rValue.toDouble() );
824 break;
825 case ANA_AutoReverse:
827 bool bTemp;
828 if (::sax::Converter::convertBool( bTemp, rValue ))
829 mxNode->setAutoReverse( bTemp );
831 break;
832 case ANA_RepeatCount:
834 mxNode->setRepeatCount( mpHelper->convertTiming( rValue ) );
836 break;
837 case ANA_RepeatDur:
839 mxNode->setRepeatDuration( mpHelper->convertTiming( rValue ) );
841 break;
842 case ANA_EndSync:
844 if( SvXMLUnitConverter::convertEnum( nEnum, rValue, getAnimationsEnumMap(Animations_EnumMap_Endsync) ) )
845 mxNode->setEndSync( makeAny( (sal_Int16)nEnum ) );
847 break;
848 case ANA_Node_Type:
850 if( SvXMLUnitConverter::convertEnum( nEnum, rValue, getAnimationsEnumMap(Animations_EnumMap_EffectNodeType) ) )
851 aUserData.push_back( NamedValue( GetXMLToken( XML_NODE_TYPE ), makeAny( (sal_Int16)nEnum ) ) );
853 break;
854 case ANA_Preset_ID:
856 aUserData.push_back( NamedValue( GetXMLToken( XML_PRESET_ID ), makeAny( rValue ) ) );
858 break;
859 case ANA_Preset_Sub_Type:
861 aUserData.push_back( NamedValue( GetXMLToken( XML_PRESET_SUB_TYPE ), makeAny( rValue ) ) );
863 break;
864 case ANA_Preset_Class:
866 if( SvXMLUnitConverter::convertEnum( nEnum, rValue, getAnimationsEnumMap(Animations_EnumMap_EffectPresetClass) ) )
867 aUserData.push_back( NamedValue( GetXMLToken( XML_PRESET_CLASS ), makeAny( (sal_Int16)nEnum ) ) );
869 break;
870 case ANA_After_Effect:
872 bool bTemp;
873 if (::sax::Converter::convertBool( bTemp, rValue ))
874 aUserData.push_back( NamedValue( GetXMLToken( XML_AFTER_EFFECT ), makeAny( bTemp ) ) );
876 break;
877 case ANA_XLink:
879 if( nNodeType == AnimationNodeType::AUDIO )
881 Reference< XAudio > xAudio( mxNode, UNO_QUERY_THROW );
882 xAudio->setSource( makeAny( GetImport().GetAbsoluteReference( rValue ) ) );
883 break;
887 // fall through intended!
888 case ANA_Target:
891 Any aTarget( mpHelper->convertTarget( rValue ) );
893 if( xAnimate.is() )
895 xAnimate->setTarget( aTarget );
897 else if( xIter.is() )
899 xIter->setTarget( aTarget );
901 else if( xCommand.is() )
903 xCommand->setTarget( aTarget );
907 break;
909 case ANA_Volume:
911 if( nNodeType == AnimationNodeType::AUDIO )
913 if( isDouble( rValue ) )
915 Reference< XAudio > xAudio( mxNode, UNO_QUERY_THROW );
916 xAudio->setVolume( rValue.toDouble() );
920 break;
922 case ANA_MasterElement:
924 Reference< XAnimationNode > xMaster( GetImport().getInterfaceToIdentifierMapper().getReference( rValue ), UNO_QUERY );
925 aUserData.push_back( NamedValue( GetXMLToken( XML_MASTER_ELEMENT ), makeAny( xMaster ) ) );
927 break;
929 case ANA_SubItem:
931 if( SvXMLUnitConverter::convertEnum( nEnum, rValue, getAnimationsEnumMap(Animations_EnumMap_SubItem) ) )
933 if( xAnimate.is() )
935 xAnimate->setSubItem( (sal_Int16)nEnum );
937 else if( xIter.is() )
939 xIter->setSubItem( (sal_Int16)nEnum );
943 break;
945 case ANA_AttributeName:
947 if( xAnimate.is() )
949 OUString aName( rValue );
951 const struct ImplAttributeNameConversion* p = getAnimationAttributeNamesConversionList();
952 while( p->mpAPIName )
954 if( IsXMLToken( aName, p->meXMLToken ) )
956 aName = OUString::createFromAscii( p->mpAPIName );
957 meAttributeName = p->meXMLToken;
958 break;
961 p++;
964 xAnimate->setAttributeName( aName );
967 break;
969 case ANA_Values:
971 aValues = rValue;
973 break;
975 case ANA_From:
977 aFrom = rValue;
979 break;
981 case ANA_By:
983 aBy = rValue;
985 break;
987 case ANA_To:
989 aTo = rValue;
991 break;
993 case ANA_KeyTimes:
995 if( xAnimate.is() )
996 xAnimate->setKeyTimes( AnimationsImportHelperImpl::convertKeyTimes( rValue ) );
998 break;
1000 case ANA_Formula:
1002 if( xAnimate.is() )
1003 xAnimate->setFormula( rValue );
1005 break;
1007 case ANA_ANIMID:
1009 if (!bHaveXmlId) { sXmlId = rValue; }
1011 break;
1012 case ANA_XMLID:
1014 sXmlId = rValue;
1015 bHaveXmlId = true;
1017 break;
1019 case ANA_CalcMode:
1021 if( xAnimate.is() )
1023 if( SvXMLUnitConverter::convertEnum( nEnum, rValue, getAnimationsEnumMap(Animations_EnumMap_CalcMode) ) )
1024 xAnimate->setCalcMode( (sal_Int16)nEnum );
1027 break;
1029 case ANA_Accumulate:
1031 if( xAnimate.is() )
1032 xAnimate->setAccumulate( IsXMLToken( rValue, XML_SUM ) );
1034 break;
1036 case ANA_AdditiveMode:
1038 if( xAnimate.is() )
1040 if( SvXMLUnitConverter::convertEnum( nEnum, rValue, getAnimationsEnumMap(Animations_EnumMap_AdditiveMode) ) )
1041 xAnimate->setAdditive( (sal_Int16)nEnum );
1044 break;
1046 case ANA_KeySplines:
1048 if( xAnimate.is() )
1049 xAnimate->setTimeFilter( AnimationsImportHelperImpl::convertTimeFilter( rValue ) );
1051 break;
1053 case ANA_Path:
1055 Reference< XAnimateMotion > xAnimateMotion( mxNode, UNO_QUERY );
1056 if( xAnimateMotion.is() )
1057 xAnimateMotion->setPath( AnimationsImportHelperImpl::convertPath( rValue ) );
1059 break;
1061 case ANA_ColorSpace:
1063 Reference< XAnimateColor > xAnimateColor( mxNode, UNO_QUERY );
1064 if( xAnimateColor.is() )
1065 xAnimateColor->setColorInterpolation( IsXMLToken( rValue, XML_HSL ) ? AnimationColorSpace::HSL : AnimationColorSpace::RGB );
1067 break;
1069 case ANA_ColorDirection:
1071 Reference< XAnimateColor > xAnimateColor( mxNode, UNO_QUERY );
1072 if( xAnimateColor.is() )
1073 xAnimateColor->setDirection( IsXMLToken( rValue, XML_CLOCKWISE ) );
1075 break;
1077 case ANA_TransformType:
1079 Reference< XAnimateTransform > xTransform( mxNode, UNO_QUERY );
1080 if( xTransform.is() )
1082 if( SvXMLUnitConverter::convertEnum( nEnum, rValue, getAnimationsEnumMap(Animations_EnumMap_TransformType) ) )
1084 xTransform->setTransformType( (sal_Int16)nEnum );
1085 switch( nEnum )
1087 case AnimationTransformType::SCALE: meAttributeName = XML_SCALE; break;
1088 case AnimationTransformType::ROTATE: meAttributeName = XML_ROTATE; break;
1089 case AnimationTransformType::SKEWX: meAttributeName = XML_SKEWX; break;
1090 case AnimationTransformType::SKEWY: meAttributeName = XML_SKEWY; break;
1091 //case AnimationTransformType::TRANSLATE:
1092 default:
1093 meAttributeName = XML_TRANSLATE; break;
1098 break;
1100 case ANA_TransitionType:
1102 if( xTransitionFilter.is() )
1104 if( SvXMLUnitConverter::convertEnum( nEnum, rValue, getAnimationsEnumMap(Animations_EnumMap_TransitionType) ) )
1105 xTransitionFilter->setTransition( (sal_Int16)nEnum );
1108 break;
1110 case ANA_TransitionSubType:
1112 if( xTransitionFilter.is() )
1114 if( SvXMLUnitConverter::convertEnum( nEnum, rValue, getAnimationsEnumMap(Animations_EnumMap_TransitionSubType) ) )
1115 xTransitionFilter->setSubtype( (sal_Int16)nEnum );
1118 break;
1120 case ANA_Mode:
1122 if( xTransitionFilter.is() )
1123 xTransitionFilter->setMode( IsXMLToken( rValue, XML_IN ) );
1125 break;
1127 case ANA_Direction:
1129 if( xTransitionFilter.is() )
1130 xTransitionFilter->setDirection( IsXMLToken( rValue, XML_FORWARD ) );
1132 break;
1134 case ANA_FadeColor:
1136 if( xTransitionFilter.is() )
1138 sal_Int32 nColor(0);
1139 ::sax::Converter::convertColor(nColor, rValue);
1140 xTransitionFilter->setFadeColor(nColor);
1143 break;
1145 case ANA_IterateType:
1147 if( SvXMLUnitConverter::convertEnum( nEnum, rValue, getAnimationsEnumMap(Animations_EnumMap_IterateType) ) )
1149 if( xIter.is() )
1150 xIter->setIterateType( (sal_Int16)nEnum );
1153 break;
1155 case ANA_IterateInterval:
1157 if( xIter.is() )
1159 double fInterval = 0.0;
1160 if( rValue.match("P") )
1162 ::com::sun::star::util::Duration aDuration;
1163 if (::sax::Converter::convertDuration(aDuration, rValue))
1165 fInterval = ((((aDuration.Hours * 60)
1166 + aDuration.Minutes) * 60) + aDuration.Seconds)
1167 + (aDuration.NanoSeconds / 1000000000.0);
1170 else
1172 fInterval = rValue.toDouble();
1175 xIter->setIterateInterval( fInterval );
1178 break;
1180 case ANA_Group_Id:
1182 aUserData.push_back( NamedValue( aLocalName, makeAny( rValue.toInt32() ) ) );
1184 break;
1186 case ANA_Command:
1188 if( xCommand.is() && nNodeType == AnimationNodeType::COMMAND )
1190 if( SvXMLUnitConverter::convertEnum( nEnum, rValue, getAnimationsEnumMap(Animations_EnumMap_Command) ) )
1192 xCommand->setCommand( (sal_Int16)nEnum );
1196 break;
1198 default:
1199 // push all unknown attributes within the presentation namespace as user data
1200 if( nPrefix == XML_NAMESPACE_PRESENTATION )
1202 aUserData.push_back( NamedValue( aLocalName, makeAny( rValue ) ) );
1207 if (!sXmlId.isEmpty())
1209 Reference< XInterface > const xRef( mxNode, UNO_QUERY );
1210 GetImport().getInterfaceToIdentifierMapper().registerReference(
1211 sXmlId, xRef );
1214 sal_Int32 nUserDataCount = aUserData.size();
1215 if( nUserDataCount )
1217 Sequence< NamedValue > aUnoUserData( nUserDataCount );
1218 NamedValue* pData = aUnoUserData.getArray();
1219 std::list< NamedValue >::iterator aIter( aUserData.begin() );
1220 const std::list< NamedValue >::iterator aEnd( aUserData.end() );
1221 while( aIter != aEnd )
1222 *pData++ = (*aIter++);
1224 mxNode->setUserData( aUnoUserData );
1227 // convert values
1228 if( xAnimate.is() )
1230 if( !aFrom.isEmpty() )
1231 xAnimate->setFrom( mpHelper->convertValue( meAttributeName, aFrom ) );
1233 if( !aBy.isEmpty() )
1234 xAnimate->setBy( mpHelper->convertValue( meAttributeName, aBy ) );
1236 if( !aTo.isEmpty() )
1237 xAnimate->setTo( mpHelper->convertValue( meAttributeName, aTo ) );
1239 if( !aValues.isEmpty() )
1240 xAnimate->setValues( mpHelper->convertValueSequence( meAttributeName, aValues ) );
1243 catch (const RuntimeException&)
1245 OSL_FAIL( "xmloff::AnimationNodeContext::StartElement(), RuntimeException caught!" );
1249 SvXMLImportContext * AnimationNodeContext::CreateChildContext( sal_uInt16 nPrefix, const OUString& rLocalName,
1250 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList )
1252 if( mxNode.is())
1253 return new AnimationNodeContext( mxNode, GetImport(), nPrefix, rLocalName, xAttrList, mpHelper );
1254 else
1255 return new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
1258 class AnimationsImport: public SvXMLImport, public XAnimationNodeSupplier
1260 public:
1261 AnimationsImport( const Reference< XComponentContext > & rxContext );
1262 virtual ~AnimationsImport() throw ();
1264 SvXMLImportContext* CreateContext(sal_uInt16 nPrefix, const OUString& rLocalName, const Reference<XAttributeList>& xAttrList) SAL_OVERRIDE;
1266 // XInterface
1267 virtual Any SAL_CALL queryInterface( const Type& aType ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
1268 virtual void SAL_CALL acquire() throw () SAL_OVERRIDE;
1269 virtual void SAL_CALL release() throw () SAL_OVERRIDE;
1271 // XAnimationNodeSupplier
1272 Reference< XAnimationNode > SAL_CALL getAnimationNode() throw (RuntimeException, std::exception) SAL_OVERRIDE;
1274 private:
1275 Reference< XAnimationNode > mxRootNode;
1278 AnimationsImport::AnimationsImport( const Reference< XComponentContext > & rxContext )
1279 : SvXMLImport( rxContext, AnimationsImport_getImplementationName(), SvXMLImportFlags::META )
1280 //FIXME: the above "IMPORT_META" used to be a nonsensical "true", question
1281 // remainst whether this should be IMPORT_META (same numerical value as
1282 // true) or default IMPORT_ALL
1284 // add namespaces
1285 GetNamespaceMap().Add(
1286 GetXMLToken(XML_NP_PRESENTATION),
1287 GetXMLToken(XML_N_PRESENTATION),
1288 XML_NAMESPACE_PRESENTATION);
1290 GetNamespaceMap().Add(
1291 GetXMLToken(XML_NP_SMIL),
1292 GetXMLToken(XML_N_SMIL),
1293 XML_NAMESPACE_SMIL);
1295 GetNamespaceMap().Add(
1296 GetXMLToken(XML_NP_ANIMATION),
1297 GetXMLToken(XML_N_ANIMATION),
1298 XML_NAMESPACE_ANIMATION);
1300 mxRootNode = Reference<XAnimationNode>( SequenceTimeContainer::create(rxContext), UNO_QUERY_THROW );
1303 AnimationsImport::~AnimationsImport() throw ()
1307 // XInterface
1308 Any SAL_CALL AnimationsImport::queryInterface( const Type& aType ) throw (RuntimeException, std::exception)
1310 if ( aType == cppu::UnoType<XAnimationNodeSupplier>::get())
1312 return makeAny( Reference<XAnimationNodeSupplier>( this ) );
1314 else
1316 return SvXMLImport::queryInterface( aType );
1320 void SAL_CALL AnimationsImport::acquire() throw ()
1322 SvXMLImport::acquire();
1325 void SAL_CALL AnimationsImport::release() throw ()
1327 SvXMLImport::release();
1330 SvXMLImportContext *AnimationsImport::CreateContext(sal_uInt16 nPrefix, const OUString& rLocalName, const Reference<XAttributeList>& xAttrList)
1332 SvXMLImportContext* pContext = 0;
1334 if( (XML_NAMESPACE_ANIMATION == nPrefix) && IsXMLToken( rLocalName, XML_SEQ ) )
1336 pContext = new AnimationNodeContext( mxRootNode, *this, nPrefix, rLocalName, xAttrList );
1338 else
1340 pContext = SvXMLImport::CreateContext(nPrefix, rLocalName, xAttrList);
1343 return pContext;
1346 // XAnimationNodeSupplier
1347 Reference< XAnimationNode > SAL_CALL AnimationsImport::getAnimationNode() throw (RuntimeException, std::exception)
1349 return mxRootNode;
1352 void AnimationNodeContext::postProcessRootNode( SvXMLImport& /*rImport*/, const Reference< XAnimationNode >& xRootNode, Reference< XPropertySet >& xPageProps )
1354 if( xRootNode.is() && xPageProps.is() ) try
1356 Reference< XEnumerationAccess > xEnumerationAccess( xRootNode, UNO_QUERY_THROW );
1357 Reference< XEnumeration > xEnumeration( xEnumerationAccess->createEnumeration(), UNO_QUERY_THROW );
1358 if( xEnumeration->hasMoreElements() )
1360 Reference< XAnimationNode > xNode( xEnumeration->nextElement(), UNO_QUERY_THROW );
1361 if( xNode->getType() == AnimationNodeType::PAR )
1363 Event aEvent;
1364 if( (xNode->getBegin() >>= aEvent) && (aEvent.Trigger == EventTrigger::BEGIN_EVENT) )
1366 // found transition node
1367 Reference< XEnumerationAccess > xChildEnumerationAccess( xNode, UNO_QUERY_THROW );
1368 Reference< XEnumeration > xChildEnumeration( xChildEnumerationAccess->createEnumeration(), UNO_QUERY_THROW );
1369 while( xChildEnumeration->hasMoreElements() )
1371 Reference< XAnimationNode > xChildNode( xChildEnumeration->nextElement(), UNO_QUERY_THROW );
1372 switch( xChildNode->getType() )
1374 case AnimationNodeType::TRANSITIONFILTER:
1376 Reference< XTransitionFilter > xTransFilter( xChildNode, UNO_QUERY_THROW );
1378 xPageProps->setPropertyValue("TransitionType", Any( xTransFilter->getTransition() ) );
1379 xPageProps->setPropertyValue("TransitionSubtype", Any( xTransFilter->getSubtype() ) );
1380 xPageProps->setPropertyValue("TransitionDirection", Any( xTransFilter->getDirection() ) );
1381 xPageProps->setPropertyValue("TransitionFadeColor", Any( xTransFilter->getFadeColor() ) );
1383 double fDuration;
1384 if( xTransFilter->getDuration() >>= fDuration )
1385 xPageProps->setPropertyValue("TransitionDuration", Any( fDuration ) );
1388 break;
1390 case AnimationNodeType::COMMAND:
1392 Reference< XCommand > xCommand( xChildNode, UNO_QUERY_THROW );
1393 if( xCommand->getCommand() == EffectCommands::STOPAUDIO )
1395 xPageProps->setPropertyValue("Sound", Any(sal_True) );
1398 break;
1400 case AnimationNodeType::AUDIO:
1402 Reference< XAudio > xAudio( xChildNode, UNO_QUERY_THROW );
1403 OUString sSoundURL;
1404 if( (xAudio->getSource() >>= sSoundURL) && !sSoundURL.isEmpty() )
1406 xPageProps->setPropertyValue("Sound", Any(sSoundURL) );
1408 Timing eTiming;
1409 if( (xAudio->getRepeatCount() >>= eTiming) && (eTiming == Timing_INDEFINITE) )
1410 xPageProps->setPropertyValue("LoopSound", Any( sal_True ) );
1413 break;
1418 Reference< XTimeContainer > xRootContainer( xRootNode, UNO_QUERY_THROW );
1419 xRootContainer->removeChild( xNode );
1424 catch (const Exception&)
1426 OSL_FAIL("xmloff::AnimationsImport::postProcessRootNode(), exception caught!");
1430 } // namespace xmloff
1432 Reference< XInterface > SAL_CALL AnimationsImport_createInstance(const Reference< XMultiServiceFactory > & rSMgr) throw( Exception )
1434 return (cppu::OWeakObject*)new xmloff::AnimationsImport( comphelper::getComponentContext(rSMgr) );
1437 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */