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 :
21 : #include <xmloff/unointerfacetouniqueidentifiermapper.hxx>
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/XIterateContainer.hpp>
30 : #include <com/sun/star/animations/XAnimateMotion.hpp>
31 : #include <com/sun/star/animations/XAnimateColor.hpp>
32 : #include <com/sun/star/animations/XAnimateTransform.hpp>
33 : #include <com/sun/star/animations/XTransitionFilter.hpp>
34 : #include <com/sun/star/animations/XCommand.hpp>
35 : #include <com/sun/star/animations/XAudio.hpp>
36 : #include <com/sun/star/animations/ValuePair.hpp>
37 : #include <com/sun/star/animations/AnimationColorSpace.hpp>
38 : #include <com/sun/star/presentation/EffectPresetClass.hpp>
39 : #include <com/sun/star/animations/Timing.hpp>
40 : #include <com/sun/star/animations/Event.hpp>
41 : #include <com/sun/star/beans/XPropertySet.hpp>
42 : #include <com/sun/star/xml/sax/XAttributeList.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 <cppuhelper/implbase1.hxx>
52 :
53 : #include <sax/tools/converter.hxx>
54 :
55 : #include <list>
56 : #include <xmloff/xmltypes.hxx>
57 : #include "sdpropls.hxx"
58 : #include <xmloff/xmltoken.hxx>
59 : #include <xmloff/xmlimp.hxx>
60 : #include "xmloff/xmlnmspe.hxx"
61 : #include <xmloff/xmluconv.hxx>
62 : #include <osl/mutex.hxx>
63 : #include <xmloff/nmspmap.hxx>
64 : #include "anim.hxx"
65 :
66 : #include "animations.hxx"
67 : #include "animationimport.hxx"
68 :
69 : using ::rtl::OUString;
70 : using ::rtl::OUStringBuffer;
71 :
72 : using namespace ::std;
73 : using namespace ::cppu;
74 : using namespace ::com::sun::star::beans;
75 : using namespace ::com::sun::star::animations;
76 : using namespace ::com::sun::star::presentation;
77 : using namespace ::com::sun::star::drawing;
78 : using namespace ::xmloff::token;
79 :
80 : using ::com::sun::star::xml::sax::XAttributeList;
81 : using ::com::sun::star::uno::Any;
82 : using ::com::sun::star::uno::makeAny;
83 : using ::com::sun::star::uno::UNO_QUERY;
84 : using ::com::sun::star::uno::UNO_QUERY_THROW;
85 : using ::com::sun::star::uno::Reference;
86 : using ::com::sun::star::uno::Sequence;
87 : using ::com::sun::star::uno::RuntimeException;
88 : using ::com::sun::star::uno::Exception;
89 : using ::com::sun::star::uno::XInterface;
90 : using ::com::sun::star::uno::Type;
91 : using ::com::sun::star::beans::NamedValue;
92 : using ::com::sun::star::text::XTextRange;
93 : using ::com::sun::star::text::XTextCursor;
94 : using ::com::sun::star::text::XTextRangeCompare;
95 : using ::com::sun::star::container::XEnumerationAccess;
96 : using ::com::sun::star::container::XEnumeration;
97 : using ::com::sun::star::lang::XMultiServiceFactory;
98 : using ::com::sun::star::lang::XInitialization;
99 :
100 : namespace xmloff
101 : {
102 :
103 : ///////////////////////////////////////////////////////////////////////
104 :
105 :
106 :
107 : ///////////////////////////////////////////////////////////////////////
108 :
109 :
110 : ///////////////////////////////////////////////////////////////////////
111 :
112 : class AnimationsImportHelperImpl
113 : {
114 : private:
115 : SvXMLImport& mrImport;
116 :
117 : SvXMLTokenMap* mpAnimationNodeTokenMap;
118 : SvXMLTokenMap* mpAnimationNodeAttributeTokenMap;
119 :
120 : public:
121 : AnimationsImportHelperImpl( SvXMLImport& rImport );
122 : ~AnimationsImportHelperImpl();
123 :
124 : const SvXMLTokenMap& getAnimationNodeTokenMap();
125 : const SvXMLTokenMap& getAnimationNodeAttributeTokenMap();
126 :
127 : Any convertValue( XMLTokenEnum eAttributeName, const OUString& rValue );
128 : Sequence< Any > convertValueSequence( XMLTokenEnum eAttributeName, const OUString& rValue );
129 :
130 : Any convertTarget( const OUString& rValue );
131 : Any convertPath( const OUString& rValue );
132 : Any convertTiming( const OUString& rValue );
133 : Sequence< double > convertKeyTimes( const OUString& rValue );
134 : Sequence< TimeFilterPair > convertTimeFilter( const OUString& rValue );
135 :
136 : bool convertAnimationValue( XMLTokenEnum eAttributeName, Any& rValue );
137 : const OUString mastrHSL;
138 : };
139 :
140 0 : AnimationsImportHelperImpl::AnimationsImportHelperImpl( SvXMLImport& rImport )
141 : : mrImport( rImport ),
142 : mpAnimationNodeTokenMap( NULL ),
143 : mpAnimationNodeAttributeTokenMap( NULL ),
144 0 : mastrHSL( RTL_CONSTASCII_USTRINGPARAM( "hsl" ) )
145 : {
146 0 : }
147 :
148 0 : AnimationsImportHelperImpl::~AnimationsImportHelperImpl()
149 : {
150 0 : delete mpAnimationNodeTokenMap;
151 0 : delete mpAnimationNodeAttributeTokenMap;
152 0 : }
153 :
154 0 : const SvXMLTokenMap& AnimationsImportHelperImpl::getAnimationNodeTokenMap()
155 : {
156 0 : if( mpAnimationNodeTokenMap == NULL )
157 : {
158 : static SvXMLTokenMapEntry aAnimationNodeTokenMap[] =
159 : {
160 : { XML_NAMESPACE_ANIMATION, XML_PAR, (sal_uInt16)AnimationNodeType::PAR },
161 : { XML_NAMESPACE_ANIMATION, XML_SEQ, (sal_uInt16)AnimationNodeType::SEQ },
162 : { XML_NAMESPACE_ANIMATION, XML_ITERATE, (sal_uInt16)AnimationNodeType::ITERATE },
163 : { XML_NAMESPACE_ANIMATION, XML_ANIMATE, (sal_uInt16)AnimationNodeType::ANIMATE },
164 : { XML_NAMESPACE_ANIMATION, XML_SET, (sal_uInt16)AnimationNodeType::SET },
165 : { XML_NAMESPACE_ANIMATION, XML_ANIMATEMOTION, (sal_uInt16)AnimationNodeType::ANIMATEMOTION },
166 : { XML_NAMESPACE_ANIMATION, XML_ANIMATECOLOR, (sal_uInt16)AnimationNodeType::ANIMATECOLOR },
167 : { XML_NAMESPACE_ANIMATION, XML_ANIMATETRANSFORM, (sal_uInt16)AnimationNodeType::ANIMATETRANSFORM },
168 : { XML_NAMESPACE_ANIMATION, XML_TRANSITIONFILTER, (sal_uInt16)AnimationNodeType::TRANSITIONFILTER },
169 : { XML_NAMESPACE_ANIMATION, XML_AUDIO, (sal_uInt16)AnimationNodeType::AUDIO },
170 : { XML_NAMESPACE_ANIMATION, XML_COMMAND, (sal_uInt16)AnimationNodeType::COMMAND },
171 : XML_TOKEN_MAP_END
172 : };
173 :
174 0 : mpAnimationNodeTokenMap = new SvXMLTokenMap( aAnimationNodeTokenMap );
175 : }
176 :
177 0 : return *mpAnimationNodeTokenMap;
178 : }
179 :
180 : enum AnimationNodeAttributes
181 : {
182 : ANA_Begin,
183 : ANA_Dur,
184 : ANA_End,
185 : ANA_Fill,
186 : ANA_FillDefault,
187 : ANA_Restart,
188 : ANA_RestartDefault,
189 : ANA_Accelerate,
190 : ANA_Decelerate,
191 : ANA_AutoReverse,
192 : ANA_RepeatCount,
193 : ANA_RepeatDur,
194 : ANA_EndSync,
195 : ANA_Node_Type,
196 : ANA_Preset_ID,
197 : ANA_Preset_Sub_Type,
198 : ANA_Preset_Class,
199 : ANA_After_Effect,
200 : ANA_Target,
201 : ANA_XLink,
202 : ANA_MasterElement,
203 : ANA_SubItem,
204 : ANA_AttributeName,
205 : ANA_Values,
206 : ANA_From,
207 : ANA_By,
208 : ANA_To,
209 : ANA_KeyTimes,
210 : ANA_CalcMode,
211 : ANA_Accumulate,
212 : ANA_AdditiveMode,
213 : ANA_KeySplines,
214 : ANA_Path,
215 : ANA_ColorSpace,
216 : ANA_ColorDirection,
217 : ANA_TransformType,
218 : ANA_TransitionType,
219 : ANA_TransitionSubType,
220 : ANA_Mode,
221 : ANA_Direction,
222 : ANA_FadeColor,
223 : ANA_IterateType,
224 : ANA_IterateInterval,
225 : ANA_Formula,
226 : ANA_ANIMID,
227 : ANA_XMLID,
228 : ANA_Group_Id,
229 : ANA_Command,
230 : ANA_Volume
231 : };
232 :
233 0 : const SvXMLTokenMap& AnimationsImportHelperImpl::getAnimationNodeAttributeTokenMap()
234 : {
235 0 : if( mpAnimationNodeAttributeTokenMap == NULL )
236 : {
237 : static SvXMLTokenMapEntry aAnimationNodeAttributeTokenMap[] =
238 : {
239 : { XML_NAMESPACE_SMIL, XML_BEGIN, (sal_uInt16)ANA_Begin },
240 : { XML_NAMESPACE_SMIL, XML_DUR, (sal_uInt16)ANA_Dur },
241 : { XML_NAMESPACE_SMIL, XML_END, (sal_uInt16)ANA_End },
242 : { XML_NAMESPACE_SMIL, XML_FILL, (sal_uInt16)ANA_Fill },
243 : { XML_NAMESPACE_SMIL, XML_FILLDEFAULT, (sal_uInt16)ANA_FillDefault },
244 : { XML_NAMESPACE_SMIL, XML_RESTART, (sal_uInt16)ANA_Restart },
245 : { XML_NAMESPACE_SMIL, XML_RESTARTDEFAULT, (sal_uInt16)ANA_RestartDefault },
246 : { XML_NAMESPACE_SMIL, XML_ACCELERATE, (sal_uInt16)ANA_Accelerate },
247 : { XML_NAMESPACE_SMIL, XML_DECELERATE, (sal_uInt16)ANA_Decelerate },
248 : { XML_NAMESPACE_SMIL, XML_AUTOREVERSE, (sal_uInt16)ANA_AutoReverse },
249 : { XML_NAMESPACE_SMIL, XML_REPEATCOUNT, (sal_uInt16)ANA_RepeatCount },
250 : { XML_NAMESPACE_SMIL, XML_REPEATDUR, (sal_uInt16)ANA_RepeatDur },
251 : { XML_NAMESPACE_SMIL, XML_ENDSYNC, (sal_uInt16)ANA_EndSync },
252 : { XML_NAMESPACE_PRESENTATION, XML_NODE_TYPE, (sal_uInt16)ANA_Node_Type },
253 : { XML_NAMESPACE_PRESENTATION, XML_PRESET_ID, (sal_uInt16)ANA_Preset_ID },
254 : { XML_NAMESPACE_PRESENTATION, XML_PRESET_SUB_TYPE, (sal_uInt16)ANA_Preset_Sub_Type },
255 : { XML_NAMESPACE_PRESENTATION, XML_PRESET_CLASS, (sal_uInt16)ANA_Preset_Class },
256 : { XML_NAMESPACE_PRESENTATION, XML_AFTER_EFFECT, (sal_uInt16)ANA_After_Effect },
257 : { XML_NAMESPACE_SMIL, XML_TARGETELEMENT, (sal_uInt16)ANA_Target },
258 : { XML_NAMESPACE_XLINK, XML_HREF, (sal_uInt16)ANA_XLink },
259 : { XML_NAMESPACE_PRESENTATION, XML_MASTER_ELEMENT, (sal_uInt16)ANA_MasterElement },
260 : { XML_NAMESPACE_ANIMATION, XML_SUB_ITEM, (sal_uInt16)ANA_SubItem },
261 : { XML_NAMESPACE_SMIL, XML_ATTRIBUTENAME, (sal_uInt16)ANA_AttributeName },
262 : { XML_NAMESPACE_SMIL, XML_VALUES, (sal_uInt16)ANA_Values },
263 : { XML_NAMESPACE_SMIL, XML_FROM, (sal_uInt16)ANA_From },
264 : { XML_NAMESPACE_SMIL, XML_BY, (sal_uInt16)ANA_By },
265 : { XML_NAMESPACE_SMIL, XML_TO, (sal_uInt16)ANA_To },
266 : { XML_NAMESPACE_SMIL, XML_KEYTIMES, (sal_uInt16)ANA_KeyTimes },
267 : { XML_NAMESPACE_SMIL, XML_CALCMODE, (sal_uInt16)ANA_CalcMode },
268 : { XML_NAMESPACE_SMIL, XML_ACCUMULATE, (sal_uInt16)ANA_Accumulate },
269 : { XML_NAMESPACE_PRESENTATION, XML_ADDITIVE, (sal_uInt16)ANA_AdditiveMode },
270 : { XML_NAMESPACE_SMIL, XML_ADDITIVE, (sal_uInt16)ANA_AdditiveMode },
271 : { XML_NAMESPACE_SMIL, XML_KEYSPLINES, (sal_uInt16)ANA_KeySplines },
272 : { XML_NAMESPACE_SVG, XML_PATH, (sal_uInt16)ANA_Path },
273 : { XML_NAMESPACE_ANIMATION, XML_COLOR_INTERPOLATION, (sal_uInt16)ANA_ColorSpace },
274 : { XML_NAMESPACE_ANIMATION, XML_COLOR_INTERPOLATION_DIRECTION, (sal_uInt16)ANA_ColorDirection },
275 : { XML_NAMESPACE_SVG, XML_TYPE, (sal_uInt16)ANA_TransformType },
276 : { XML_NAMESPACE_SMIL, XML_TYPE, (sal_uInt16)ANA_TransitionType },
277 : { XML_NAMESPACE_SMIL, XML_SUBTYPE, (sal_uInt16)ANA_TransitionSubType },
278 : { XML_NAMESPACE_SMIL, XML_MODE, (sal_uInt16)ANA_Mode },
279 : { XML_NAMESPACE_SMIL, XML_DIRECTION, (sal_uInt16)ANA_Direction },
280 : { XML_NAMESPACE_SMIL, XML_FADECOLOR, (sal_uInt16)ANA_FadeColor },
281 : { XML_NAMESPACE_ANIMATION, XML_ITERATE_TYPE, (sal_uInt16)ANA_IterateType },
282 : { XML_NAMESPACE_ANIMATION, XML_ITERATE_INTERVAL, (sal_uInt16)ANA_IterateInterval },
283 : { XML_NAMESPACE_ANIMATION, XML_FORMULA, (sal_uInt16)ANA_Formula },
284 : { XML_NAMESPACE_ANIMATION, XML_ID, (sal_uInt16)ANA_ANIMID },
285 : { XML_NAMESPACE_XML, XML_ID, (sal_uInt16)ANA_XMLID },
286 : { XML_NAMESPACE_PRESENTATION, XML_GROUP_ID, (sal_uInt16)ANA_Group_Id },
287 : { XML_NAMESPACE_ANIMATION, XML_AUDIO_LEVEL, (sal_uInt16)ANA_Volume },
288 : { XML_NAMESPACE_ANIMATION, XML_COMMAND, (sal_uInt16)ANA_Command },
289 :
290 : XML_TOKEN_MAP_END
291 : };
292 :
293 0 : mpAnimationNodeAttributeTokenMap = new SvXMLTokenMap( aAnimationNodeAttributeTokenMap );
294 : }
295 :
296 0 : return *mpAnimationNodeAttributeTokenMap;
297 : }
298 :
299 0 : static bool isDouble( const OUString& rValue )
300 : {
301 0 : sal_Int32 nLength = rValue.getLength();
302 0 : const sal_Unicode * pStr = rValue.getStr();
303 0 : while( nLength )
304 : {
305 0 : if( (*pStr >= '0' && *pStr <= '9') || *pStr == '-' || *pStr == '.' || *pStr == '+' || *pStr == 'e' || *pStr == 'E' )
306 : {
307 0 : pStr++;
308 0 : nLength--;
309 : }
310 : else
311 : {
312 0 : return false;
313 : }
314 : }
315 :
316 0 : return true;
317 : }
318 :
319 0 : static bool isTime( const OUString& rValue )
320 : {
321 0 : sal_Int32 nLength = rValue.getLength();
322 : const sal_Unicode * pStr;
323 0 : for( pStr = rValue.getStr(); nLength; pStr++, nLength-- )
324 : {
325 0 : if( !( (*pStr >= '0' && *pStr <= '9') || *pStr == '-' || *pStr == '.' || *pStr == '+' || *pStr == 'e' || *pStr == 'E' ) )
326 0 : break;
327 : }
328 :
329 : // return true if this is a double (if someone forgot the 's' we silently ignore it)
330 : // or if its a double that ends with a 's' or 'S'
331 0 : return (nLength == 0) || ((*pStr == 's' || *pStr == 'S') && (nLength == 1));
332 : }
333 :
334 0 : static sal_Int32 count_codes( const OUString& rString, sal_Unicode nCode )
335 : {
336 0 : sal_Int32 nCount = 0;
337 0 : sal_Int32 fromIndex = 0;
338 :
339 0 : while(true)
340 : {
341 0 : fromIndex = rString.indexOf( nCode, fromIndex );
342 0 : if( fromIndex == -1 )
343 0 : break;
344 :
345 0 : fromIndex++;
346 0 : nCount++;
347 : }
348 :
349 0 : return nCount;
350 : }
351 :
352 0 : Any AnimationsImportHelperImpl::convertTarget( const OUString& rValue )
353 : {
354 : try
355 : {
356 0 : Reference< XInterface > xRef( mrImport.getInterfaceToIdentifierMapper().getReference( rValue ) );
357 :
358 0 : Reference< XShape > _xShape( xRef, UNO_QUERY );
359 0 : if( _xShape.is() )
360 0 : return makeAny( _xShape );
361 :
362 0 : Reference< XTextCursor > xTextCursor( xRef, UNO_QUERY );
363 0 : if( xTextCursor.is() )
364 : {
365 0 : Reference< XTextRange > xStart( xTextCursor->getStart() ), xRange;
366 0 : Reference< XShape > xShape( xTextCursor->getText(), UNO_QUERY_THROW );
367 0 : Reference< XTextRangeCompare > xTextRangeCompare( xShape, UNO_QUERY_THROW );
368 :
369 0 : Reference< XEnumerationAccess > xParaEnumAccess( xShape, UNO_QUERY_THROW );
370 0 : Reference< XEnumeration > xEnumeration( xParaEnumAccess->createEnumeration(), UNO_QUERY_THROW );
371 0 : sal_Int16 nParagraph = 0;
372 :
373 0 : while( xEnumeration->hasMoreElements() )
374 : {
375 0 : xEnumeration->nextElement() >>= xRange;
376 :
377 : // break if start of selection is prior to end of current paragraph
378 0 : if( xRange.is() && (xTextRangeCompare->compareRegionEnds( xStart, xRange ) >= 0 ) )
379 : {
380 0 : return makeAny( ParagraphTarget( xShape, nParagraph ) );
381 : }
382 :
383 0 : nParagraph++;
384 0 : }
385 0 : }
386 : }
387 0 : catch (const RuntimeException&)
388 : {
389 : OSL_FAIL( "xmloff::AnimationsImportImpl::convertTarget(), RuntimeException caught!" );
390 : }
391 :
392 0 : Any aAny;
393 0 : return aAny;
394 : }
395 :
396 0 : Any AnimationsImportHelperImpl::convertValue( XMLTokenEnum eAttributeName, const OUString& rValue )
397 : {
398 0 : sal_Int32 nCommaPos = -1, nPos;
399 0 : sal_Int32 nOpenBrakets = 0;
400 0 : for( nPos = 0; (nPos < rValue.getLength()) && (nCommaPos == -1); nPos++ )
401 : {
402 0 : switch( rValue[nPos] )
403 : {
404 : case ',':
405 0 : if( nOpenBrakets == 0 )
406 0 : nCommaPos = nPos;
407 0 : break;
408 : case '(':
409 : case '[':
410 : case '{':
411 0 : nOpenBrakets++;
412 0 : break;
413 : case ')':
414 : case ']':
415 : case '}':
416 0 : nOpenBrakets--;
417 0 : break;
418 : }
419 : }
420 :
421 0 : if( nCommaPos >= 0 )
422 : {
423 0 : ValuePair aPair;
424 0 : aPair.First = convertValue( eAttributeName, rValue.copy( 0, nCommaPos ) );
425 0 : aPair.Second = convertValue( eAttributeName, rValue.copy( nCommaPos+1, rValue.getLength() - nCommaPos - 1 ) );
426 0 : return makeAny( aPair );
427 : }
428 : else
429 : {
430 0 : Any aAny;
431 0 : sal_Int32 nType = XML_TYPE_STRING;
432 :
433 0 : if( rValue.getLength() ) switch( eAttributeName )
434 : {
435 : case XML_X:
436 : case XML_Y:
437 : case XML_WIDTH:
438 : case XML_HEIGHT:
439 : case XML_TRANSLATE:
440 : {
441 0 : return makeAny( rValue );
442 : }
443 :
444 : case XML_SCALE:
445 : case XML_SKEWY:
446 : case XML_SKEWX:
447 : case XML_OPACITY:
448 0 : case XML_ROTATE: nType = XML_TYPE_DOUBLE; break;
449 0 : case XML_TEXT_ROTATION_ANGLE:nType = XML_TYPE_TEXT_ROTATION_ANGLE; break;
450 : case XML_FILL_COLOR:
451 : case XML_STROKE_COLOR:
452 : case XML_DIM:
453 0 : case XML_COLOR: nType = XML_TYPE_COLOR; break;
454 0 : case XML_FILL: nType = XML_SD_TYPE_FILLSTYLE; break;
455 0 : case XML_STROKE: nType = XML_SD_TYPE_STROKE; break;
456 0 : case XML_FONT_WEIGHT: nType = XML_TYPE_TEXT_WEIGHT; break;
457 0 : case XML_FONT_STYLE: nType = XML_TYPE_TEXT_POSTURE; break;
458 0 : case XML_TEXT_UNDERLINE: nType = XML_TYPE_TEXT_UNDERLINE_STYLE; break;
459 0 : case XML_FONT_SIZE: nType = XML_TYPE_DOUBLE_PERCENT; break;
460 0 : case XML_VISIBILITY: nType = XML_SD_TYPE_PRESPAGE_VISIBILITY; break;
461 :
462 : default:
463 0 : if( !rValue.isEmpty() )
464 0 : aAny <<= rValue;
465 0 : return aAny;
466 : }
467 :
468 0 : const XMLPropertyHandler* pHandler = mrImport.GetShapeImport()->GetSdPropHdlFactory()->GetPropertyHandler( nType );
469 0 : if( pHandler )
470 0 : pHandler->importXML( rValue, aAny, mrImport.GetMM100UnitConverter() );
471 :
472 0 : return aAny;
473 : }
474 : }
475 :
476 0 : Sequence< Any > AnimationsImportHelperImpl::convertValueSequence( XMLTokenEnum eAttributeName, const OUString& rValue )
477 : {
478 0 : Sequence< Any > aValues;
479 :
480 : // do we have any value at all?
481 0 : if( !rValue.isEmpty() )
482 : {
483 0 : sal_Int32 nElements = count_codes( rValue, (sal_Unicode)';') + 1; // a non empty string has at least one value
484 :
485 : // prepare the sequence
486 0 : aValues.realloc( nElements );
487 :
488 : // fill the sequence
489 0 : Any* pValues = aValues.getArray();
490 : sal_Int32 nIndex;
491 0 : for( nIndex = 0; nElements && (nIndex >= 0); nElements-- )
492 : {
493 0 : *pValues++ = convertValue( eAttributeName, rValue.getToken( 0, ';', nIndex ) );
494 : }
495 : }
496 :
497 0 : return aValues;
498 : }
499 :
500 0 : Any AnimationsImportHelperImpl::convertTiming( const OUString& rValue )
501 : {
502 0 : Any aAny;
503 :
504 : // do we have any value at all?
505 0 : if( !rValue.isEmpty() )
506 : {
507 : // count the values
508 0 : sal_Int32 nElements = count_codes( rValue, (sal_Unicode)';' ) + 1; // a non empty string has at least one value
509 :
510 0 : if( nElements == 1 )
511 : {
512 0 : if( IsXMLToken( rValue, XML_MEDIA ) )
513 : {
514 0 : aAny <<= Timing_MEDIA;
515 : }
516 0 : else if( IsXMLToken( rValue, XML_INDEFINITE ) )
517 : {
518 0 : aAny <<= Timing_INDEFINITE;
519 : }
520 0 : else if( isTime( rValue ) )
521 : {
522 0 : aAny <<= rValue.toDouble();
523 : }
524 : else
525 : {
526 0 : Event aEvent;
527 0 : aEvent.Repeat = 0;
528 0 : aEvent.Trigger = 0;
529 :
530 0 : OUString aEventTrigger;
531 :
532 0 : sal_Int32 nPos = rValue.indexOf( (sal_Unicode)'+' );
533 0 : if( nPos == -1 )
534 : {
535 0 : aEventTrigger = rValue;
536 : }
537 : else
538 : {
539 0 : aEventTrigger = rValue.copy( 0, nPos );
540 :
541 : // convert offset
542 0 : aEvent.Offset <<= convertTiming( rValue.copy( nPos + 1 ) );
543 : }
544 :
545 0 : nPos = aEventTrigger.indexOf( (sal_Unicode)'.' );
546 0 : if( nPos != -1 )
547 : {
548 0 : aEvent.Source <<= mrImport.getInterfaceToIdentifierMapper().getReference( aEventTrigger.copy( 0, nPos ) );
549 0 : aEventTrigger = aEventTrigger.copy( nPos + 1 );
550 : }
551 :
552 : sal_uInt16 nEnum;
553 0 : if( SvXMLUnitConverter::convertEnum( nEnum, aEventTrigger, getAnimationsEnumMap(Animations_EnumMap_EventTrigger) ) )
554 : {
555 0 : aEvent.Trigger = (sal_Int16)nEnum;
556 : }
557 : else
558 : {
559 : OSL_FAIL("AnimationsImportHelperImpl::convertTiming(), unknown event trigger!");
560 : }
561 :
562 0 : aAny <<= aEvent;
563 : }
564 : }
565 : else
566 : {
567 : // fill the sequence
568 0 : Sequence< Any > aValues( nElements );
569 0 : Any* pValues = aValues.getArray();
570 0 : sal_Int32 nIndex = 0;
571 0 : while( (nElements--) && (nIndex >= 0) )
572 0 : *pValues++ = convertTiming( rValue.getToken( 0, ';', nIndex ) );
573 :
574 0 : aAny <<= aValues;
575 : }
576 : }
577 0 : return aAny;
578 : }
579 :
580 0 : Sequence< double > AnimationsImportHelperImpl::convertKeyTimes( const OUString& rValue )
581 : {
582 0 : sal_Int32 nElements = 0;
583 :
584 0 : if( !rValue.isEmpty() )
585 0 : nElements = count_codes( rValue, (sal_Unicode)';' ) + 1; // a non empty string has at least one value
586 :
587 0 : Sequence< double > aKeyTimes( nElements );
588 :
589 0 : if( nElements )
590 : {
591 0 : double* pValues = aKeyTimes.getArray();
592 0 : sal_Int32 nIndex = 0;
593 0 : while( (nElements--) && (nIndex >= 0) )
594 0 : *pValues++ = rValue.getToken( 0, ';', nIndex ).toDouble();
595 : }
596 :
597 0 : return aKeyTimes;
598 : }
599 :
600 0 : Sequence< TimeFilterPair > AnimationsImportHelperImpl::convertTimeFilter( const OUString& rValue )
601 : {
602 0 : sal_Int32 nElements = 0;
603 :
604 0 : if( !rValue.isEmpty() )
605 0 : nElements = count_codes( rValue, (sal_Unicode)';' ) + 1; // a non empty string has at least one value
606 :
607 0 : Sequence< TimeFilterPair > aTimeFilter( nElements );
608 :
609 0 : if( nElements )
610 : {
611 0 : TimeFilterPair* pValues = aTimeFilter.getArray();
612 0 : sal_Int32 nIndex = 0;
613 0 : while( (nElements--) && (nIndex >= 0) )
614 : {
615 0 : const OUString aToken( rValue.getToken( 0, ';', nIndex ) );
616 :
617 0 : sal_Int32 nPos = aToken.indexOf( ',' );
618 0 : if( nPos >= 0 )
619 : {
620 0 : pValues->Time = aToken.copy( 0, nPos ).toDouble();
621 0 : pValues->Progress = aToken.copy( nPos+1, aToken.getLength() - nPos - 1 ).toDouble();
622 : }
623 0 : pValues++;
624 0 : }
625 : }
626 :
627 0 : return aTimeFilter;
628 : }
629 :
630 0 : Any AnimationsImportHelperImpl::convertPath( const OUString& rValue )
631 : {
632 0 : return makeAny( rValue );
633 : }
634 :
635 : ///////////////////////////////////////////////////////////////////////
636 :
637 0 : TYPEINIT1( AnimationNodeContext, SvXMLImportContext );
638 :
639 0 : AnimationNodeContext::AnimationNodeContext(
640 : const Reference< XAnimationNode >& xParentNode,
641 : SvXMLImport& rImport, sal_uInt16 nPrfx, const rtl::OUString& rLocalName,
642 : const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList,
643 : AnimationsImportHelperImpl* pHelper /* = NULL */ )
644 : : SvXMLImportContext(rImport, nPrfx, rLocalName),
645 : mpHelper( pHelper ),
646 0 : mbRootContext( pHelper == NULL )
647 : {
648 : try
649 : {
650 0 : if( mbRootContext )
651 : {
652 0 : mpHelper = new AnimationsImportHelperImpl( rImport );
653 0 : mxNode = xParentNode;
654 : }
655 : else
656 : {
657 0 : Reference< XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory() );
658 :
659 0 : sal_Int16 nPresetClass = EffectPresetClass::CUSTOM;
660 :
661 0 : const sal_Char* pServiceName = 0;
662 :
663 0 : sal_Int16 nNodeType = (sal_Int16)mpHelper->getAnimationNodeTokenMap().Get( nPrfx, rLocalName );
664 0 : switch( nNodeType )
665 : {
666 0 : case AnimationNodeType::SEQ: pServiceName = "com.sun.star.animations.SequenceTimeContainer"; break;
667 0 : case AnimationNodeType::ITERATE: pServiceName = "com.sun.star.animations.IterateContainer"; break;
668 0 : case AnimationNodeType::ANIMATE: pServiceName = "com.sun.star.animations.Animate"; break;
669 0 : case AnimationNodeType::SET: pServiceName = "com.sun.star.animations.AnimateSet"; break;
670 0 : case AnimationNodeType::ANIMATEMOTION: pServiceName = "com.sun.star.animations.AnimateMotion"; break;
671 0 : case AnimationNodeType::ANIMATECOLOR: pServiceName = "com.sun.star.animations.AnimateColor"; break;
672 0 : case AnimationNodeType::ANIMATETRANSFORM: pServiceName = "com.sun.star.animations.AnimateTransform"; break;
673 0 : case AnimationNodeType::TRANSITIONFILTER: pServiceName = "com.sun.star.animations.TransitionFilter"; break;
674 0 : case AnimationNodeType::AUDIO: pServiceName = "com.sun.star.animations.Audio"; break;
675 0 : case AnimationNodeType::COMMAND: pServiceName = "com.sun.star.animations.Command"; break;
676 : case AnimationNodeType::PAR:
677 : {
678 0 : const sal_Int16 nCount = xAttrList.is() ? xAttrList->getLength() : 0;
679 : sal_Int16 nAttribute;
680 0 : for( nAttribute = 0; nAttribute < nCount; nAttribute++ )
681 : {
682 0 : OUString aLocalName;
683 0 : sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( xAttrList->getNameByIndex( nAttribute ), &aLocalName );
684 0 : if( (nPrefix == XML_NAMESPACE_PRESENTATION) && IsXMLToken( aLocalName, XML_PRESET_ID ) )
685 : {
686 0 : const OUString& rValue = xAttrList->getValueByIndex( nAttribute );
687 0 : if ( rValue == "ooo-entrance-random" )
688 : {
689 0 : nPresetClass = EffectPresetClass::ENTRANCE;
690 : }
691 0 : else if ( rValue == "ooo-exit-random" )
692 : {
693 0 : nPresetClass = EffectPresetClass::EXIT;
694 : }
695 :
696 0 : if( nPresetClass != EffectPresetClass::CUSTOM )
697 : {
698 0 : pServiceName = "com.sun.star.comp.sd.RandomAnimationNode";
699 : break;
700 0 : }
701 : }
702 0 : }
703 0 : if( !pServiceName )
704 0 : pServiceName = "com.sun.star.animations.ParallelTimeContainer";
705 : }
706 0 : break;
707 : default:
708 0 : pServiceName = 0;
709 : }
710 :
711 0 : if( pServiceName && xFactory.is() )
712 : {
713 0 : mxNode = Reference< XAnimationNode >( xFactory->createInstance(
714 0 : OUString::createFromAscii(pServiceName) ), UNO_QUERY_THROW );
715 :
716 0 : if( nPresetClass != EffectPresetClass::CUSTOM )
717 : {
718 0 : Reference< XInitialization > xInit( mxNode, UNO_QUERY_THROW );
719 0 : const Any aAny( makeAny( nPresetClass ) );
720 0 : Sequence< Any > aArgs( &aAny, 1 ) ;
721 0 : xInit->initialize( aArgs );
722 : }
723 :
724 0 : init_node( xAttrList );
725 :
726 0 : Reference< XTimeContainer > xParentContainer( xParentNode, UNO_QUERY_THROW );
727 0 : xParentContainer->appendChild( mxNode );
728 0 : }
729 : }
730 : }
731 0 : catch (const RuntimeException&)
732 : {
733 : OSL_FAIL( "xmloff::AnimationsImportImpl::AnimationsImportImpl(), RuntimeException caught!" );
734 : }
735 0 : }
736 :
737 0 : AnimationNodeContext::~AnimationNodeContext()
738 : {
739 0 : if( mbRootContext )
740 0 : delete mpHelper;
741 0 : }
742 :
743 0 : void AnimationNodeContext::StartElement( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& )
744 : {
745 : // code of StartElement is moved to init_node that is now called
746 : // in c'tor before appending this node to its parent.
747 : // This is needed for random nodes that need the correct target
748 : // set when child nodes are appended.
749 0 : }
750 :
751 0 : void AnimationNodeContext::init_node( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList )
752 : {
753 0 : if( mxNode.is() ) try
754 : {
755 0 : const sal_Int16 nNodeType = mxNode->getType();
756 :
757 : // query for optional interfaces that are often used later
758 0 : Reference< XAnimate > xAnimate( mxNode, UNO_QUERY );
759 0 : Reference< XCommand > xCommand( mxNode, UNO_QUERY );
760 0 : Reference< XTransitionFilter > xTransitionFilter( mxNode, UNO_QUERY );
761 0 : Reference< XIterateContainer > xIter( mxNode, UNO_QUERY );
762 :
763 0 : std::list< NamedValue > aUserData;
764 0 : XMLTokenEnum meAttributeName = XML_TOKEN_INVALID;
765 0 : OUString aFrom, aBy, aTo, aValues;
766 0 : bool bHaveXmlId( false );
767 0 : OUString sXmlId;
768 :
769 0 : const sal_Int16 nCount = xAttrList.is() ? xAttrList->getLength() : 0;
770 : sal_uInt16 nEnum;
771 : sal_Int16 nAttribute;
772 0 : for( nAttribute = 0; nAttribute < nCount; nAttribute++ )
773 : {
774 0 : const OUString& rAttrName = xAttrList->getNameByIndex( nAttribute );
775 0 : const OUString& rValue = xAttrList->getValueByIndex( nAttribute );
776 :
777 0 : OUString aLocalName;
778 0 : sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName );
779 0 : switch( mpHelper->getAnimationNodeAttributeTokenMap().Get( nPrefix, aLocalName ) )
780 : {
781 : case ANA_Begin:
782 : {
783 0 : mxNode->setBegin( mpHelper->convertTiming( rValue ) );
784 : }
785 0 : break;
786 : case ANA_Dur:
787 : {
788 0 : mxNode->setDuration( mpHelper->convertTiming( rValue ) );
789 : }
790 0 : break;
791 : case ANA_End:
792 : {
793 0 : mxNode->setEnd( mpHelper->convertTiming( rValue ) );
794 : }
795 0 : break;
796 : case ANA_Fill:
797 : {
798 0 : if( SvXMLUnitConverter::convertEnum( nEnum, rValue, getAnimationsEnumMap(Animations_EnumMap_Fill) ) )
799 0 : mxNode->setFill( (sal_Int16)nEnum );
800 : }
801 0 : break;
802 : case ANA_FillDefault:
803 : {
804 0 : if( SvXMLUnitConverter::convertEnum( nEnum, rValue, getAnimationsEnumMap(Animations_EnumMap_FillDefault) ) )
805 0 : mxNode->setFillDefault( (sal_Int16)nEnum );
806 : }
807 0 : break;
808 : case ANA_Restart:
809 : {
810 0 : if( SvXMLUnitConverter::convertEnum( nEnum, rValue, getAnimationsEnumMap(Animations_EnumMap_Restart) ) )
811 0 : mxNode->setRestart( (sal_Int16)nEnum );
812 : }
813 0 : break;
814 : case ANA_RestartDefault:
815 : {
816 0 : if( SvXMLUnitConverter::convertEnum( nEnum, rValue, getAnimationsEnumMap(Animations_EnumMap_RestartDefault) ) )
817 0 : mxNode->setRestartDefault( (sal_Int16)nEnum );
818 : }
819 0 : break;
820 : case ANA_Accelerate:
821 : {
822 0 : if( isDouble( rValue ) )
823 0 : mxNode->setAcceleration( rValue.toDouble() );
824 : }
825 0 : break;
826 : case ANA_Decelerate:
827 : {
828 0 : if( isDouble( rValue ) )
829 0 : mxNode->setDecelerate( rValue.toDouble() );
830 : }
831 0 : break;
832 : case ANA_AutoReverse:
833 : {
834 : bool bTemp;
835 0 : if (::sax::Converter::convertBool( bTemp, rValue ))
836 0 : mxNode->setAutoReverse( bTemp );
837 : }
838 0 : break;
839 : case ANA_RepeatCount:
840 : {
841 0 : mxNode->setRepeatCount( mpHelper->convertTiming( rValue ) );
842 : }
843 0 : break;
844 : case ANA_RepeatDur:
845 : {
846 0 : mxNode->setRepeatDuration( mpHelper->convertTiming( rValue ) );
847 : }
848 0 : break;
849 : case ANA_EndSync:
850 : {
851 0 : if( SvXMLUnitConverter::convertEnum( nEnum, rValue, getAnimationsEnumMap(Animations_EnumMap_Endsync) ) )
852 0 : mxNode->setEndSync( makeAny( (sal_Int16)nEnum ) );
853 : }
854 0 : break;
855 : case ANA_Node_Type:
856 : {
857 0 : if( SvXMLUnitConverter::convertEnum( nEnum, rValue, getAnimationsEnumMap(Animations_EnumMap_EffectNodeType) ) )
858 0 : aUserData.push_back( NamedValue( GetXMLToken( XML_NODE_TYPE ), makeAny( (sal_Int16)nEnum ) ) );
859 : }
860 0 : break;
861 : case ANA_Preset_ID:
862 : {
863 0 : aUserData.push_back( NamedValue( GetXMLToken( XML_PRESET_ID ), makeAny( rValue ) ) );
864 : }
865 0 : break;
866 : case ANA_Preset_Sub_Type:
867 : {
868 0 : aUserData.push_back( NamedValue( GetXMLToken( XML_PRESET_SUB_TYPE ), makeAny( rValue ) ) );
869 : }
870 0 : break;
871 : case ANA_Preset_Class:
872 : {
873 0 : if( SvXMLUnitConverter::convertEnum( nEnum, rValue, getAnimationsEnumMap(Animations_EnumMap_EffectPresetClass) ) )
874 0 : aUserData.push_back( NamedValue( GetXMLToken( XML_PRESET_CLASS ), makeAny( (sal_Int16)nEnum ) ) );
875 : }
876 0 : break;
877 : case ANA_After_Effect:
878 : {
879 : bool bTemp;
880 0 : if (::sax::Converter::convertBool( bTemp, rValue ))
881 0 : aUserData.push_back( NamedValue( GetXMLToken( XML_AFTER_EFFECT ), makeAny( bTemp ) ) );
882 : }
883 0 : break;
884 : case ANA_XLink:
885 : {
886 0 : if( nNodeType == AnimationNodeType::AUDIO )
887 : {
888 0 : Reference< XAudio > xAudio( mxNode, UNO_QUERY_THROW );
889 0 : xAudio->setSource( makeAny( GetImport().GetAbsoluteReference( rValue ) ) );
890 0 : break;
891 : }
892 :
893 : }
894 : // fall through intented!
895 : case ANA_Target:
896 : {
897 : {
898 0 : Any aTarget( mpHelper->convertTarget( rValue ) );
899 :
900 0 : if( xAnimate.is() )
901 : {
902 0 : xAnimate->setTarget( aTarget );
903 : }
904 0 : else if( xIter.is() )
905 : {
906 0 : xIter->setTarget( aTarget );
907 : }
908 0 : else if( xCommand.is() )
909 : {
910 0 : xCommand->setTarget( aTarget );
911 0 : }
912 : }
913 : }
914 0 : break;
915 :
916 : case ANA_Volume:
917 : {
918 0 : if( nNodeType == AnimationNodeType::AUDIO )
919 : {
920 0 : if( isDouble( rValue ) )
921 : {
922 0 : Reference< XAudio > xAudio( mxNode, UNO_QUERY_THROW );
923 0 : xAudio->setVolume( rValue.toDouble() );
924 : }
925 : }
926 : }
927 0 : break;
928 :
929 : case ANA_MasterElement:
930 : {
931 0 : Reference< XAnimationNode > xMaster( GetImport().getInterfaceToIdentifierMapper().getReference( rValue ), UNO_QUERY );
932 0 : aUserData.push_back( NamedValue( GetXMLToken( XML_MASTER_ELEMENT ), makeAny( xMaster ) ) );
933 : }
934 0 : break;
935 :
936 : case ANA_SubItem:
937 : {
938 0 : if( SvXMLUnitConverter::convertEnum( nEnum, rValue, getAnimationsEnumMap(Animations_EnumMap_SubItem) ) )
939 : {
940 0 : if( xAnimate.is() )
941 : {
942 0 : xAnimate->setSubItem( (sal_Int16)nEnum );
943 : }
944 0 : else if( xIter.is() )
945 : {
946 0 : xIter->setSubItem( (sal_Int16)nEnum );
947 : }
948 : }
949 : }
950 0 : break;
951 :
952 : case ANA_AttributeName:
953 : {
954 0 : if( xAnimate.is() )
955 : {
956 0 : OUString aName( rValue );
957 :
958 0 : ImplAttributeNameConversion* p = getAnimationAttributeNamesConversionList();
959 0 : while( p->mpAPIName )
960 : {
961 0 : if( IsXMLToken( aName, p->meXMLToken ) )
962 : {
963 0 : aName = OUString::createFromAscii( p->mpAPIName );
964 0 : meAttributeName = p->meXMLToken;
965 0 : break;
966 : }
967 :
968 0 : p++;
969 : }
970 :
971 0 : xAnimate->setAttributeName( aName );
972 : }
973 : }
974 0 : break;
975 :
976 : case ANA_Values:
977 : {
978 0 : aValues = rValue;
979 : }
980 0 : break;
981 :
982 : case ANA_From:
983 : {
984 0 : aFrom = rValue;
985 : }
986 0 : break;
987 :
988 : case ANA_By:
989 : {
990 0 : aBy = rValue;
991 : }
992 0 : break;
993 :
994 : case ANA_To:
995 : {
996 0 : aTo = rValue;
997 : }
998 0 : break;
999 :
1000 : case ANA_KeyTimes:
1001 : {
1002 0 : if( xAnimate.is() )
1003 0 : xAnimate->setKeyTimes( mpHelper->convertKeyTimes( rValue ) );
1004 : }
1005 0 : break;
1006 :
1007 : case ANA_Formula:
1008 : {
1009 0 : if( xAnimate.is() )
1010 0 : xAnimate->setFormula( rValue );
1011 : }
1012 0 : break;
1013 :
1014 : case ANA_ANIMID:
1015 : {
1016 0 : if (!bHaveXmlId) { sXmlId = rValue; }
1017 : }
1018 0 : break;
1019 : case ANA_XMLID:
1020 : {
1021 0 : sXmlId = rValue;
1022 0 : bHaveXmlId = true;
1023 : }
1024 0 : break;
1025 :
1026 : case ANA_CalcMode:
1027 : {
1028 0 : if( xAnimate.is() )
1029 : {
1030 0 : if( SvXMLUnitConverter::convertEnum( nEnum, rValue, getAnimationsEnumMap(Animations_EnumMap_CalcMode) ) )
1031 0 : xAnimate->setCalcMode( (sal_Int16)nEnum );
1032 : }
1033 : }
1034 0 : break;
1035 :
1036 : case ANA_Accumulate:
1037 : {
1038 0 : if( xAnimate.is() )
1039 0 : xAnimate->setAccumulate( IsXMLToken( rValue, XML_SUM ) );
1040 : }
1041 0 : break;
1042 :
1043 : case ANA_AdditiveMode:
1044 : {
1045 0 : if( xAnimate.is() )
1046 : {
1047 0 : if( SvXMLUnitConverter::convertEnum( nEnum, rValue, getAnimationsEnumMap(Animations_EnumMap_AdditiveMode) ) )
1048 0 : xAnimate->setAdditive( (sal_Int16)nEnum );
1049 : }
1050 : }
1051 0 : break;
1052 :
1053 : case ANA_KeySplines:
1054 : {
1055 0 : if( xAnimate.is() )
1056 0 : xAnimate->setTimeFilter( mpHelper->convertTimeFilter( rValue ) );
1057 : }
1058 0 : break;
1059 :
1060 : case ANA_Path:
1061 : {
1062 0 : Reference< XAnimateMotion > xAnimateMotion( mxNode, UNO_QUERY );
1063 0 : if( xAnimateMotion.is() )
1064 0 : xAnimateMotion->setPath( mpHelper->convertPath( rValue ) );
1065 : }
1066 0 : break;
1067 :
1068 : case ANA_ColorSpace:
1069 : {
1070 0 : Reference< XAnimateColor > xAnimateColor( mxNode, UNO_QUERY );
1071 0 : if( xAnimateColor.is() )
1072 0 : xAnimateColor->setColorInterpolation( IsXMLToken( rValue, XML_HSL ) ? AnimationColorSpace::HSL : AnimationColorSpace::RGB );
1073 : }
1074 0 : break;
1075 :
1076 : case ANA_ColorDirection:
1077 : {
1078 0 : Reference< XAnimateColor > xAnimateColor( mxNode, UNO_QUERY );
1079 0 : if( xAnimateColor.is() )
1080 0 : xAnimateColor->setDirection( IsXMLToken( rValue, XML_CLOCKWISE ) );
1081 : }
1082 0 : break;
1083 :
1084 : case ANA_TransformType:
1085 : {
1086 0 : Reference< XAnimateTransform > xTransform( mxNode, UNO_QUERY );
1087 0 : if( xTransform.is() )
1088 : {
1089 0 : if( SvXMLUnitConverter::convertEnum( nEnum, rValue, getAnimationsEnumMap(Animations_EnumMap_TransformType) ) )
1090 : {
1091 0 : xTransform->setTransformType( (sal_Int16)nEnum );
1092 0 : switch( nEnum )
1093 : {
1094 0 : case AnimationTransformType::SCALE: meAttributeName = XML_SCALE; break;
1095 0 : case AnimationTransformType::ROTATE: meAttributeName = XML_ROTATE; break;
1096 0 : case AnimationTransformType::SKEWX: meAttributeName = XML_SKEWX; break;
1097 0 : case AnimationTransformType::SKEWY: meAttributeName = XML_SKEWY; break;
1098 : //case AnimationTransformType::TRANSLATE:
1099 : default:
1100 0 : meAttributeName = XML_TRANSLATE; break;
1101 : }
1102 : }
1103 0 : }
1104 : }
1105 0 : break;
1106 :
1107 : case ANA_TransitionType:
1108 : {
1109 0 : if( xTransitionFilter.is() )
1110 : {
1111 0 : if( SvXMLUnitConverter::convertEnum( nEnum, rValue, getAnimationsEnumMap(Animations_EnumMap_TransitionType) ) )
1112 0 : xTransitionFilter->setTransition( (sal_Int16)nEnum );
1113 : }
1114 : }
1115 0 : break;
1116 :
1117 : case ANA_TransitionSubType:
1118 : {
1119 0 : if( xTransitionFilter.is() )
1120 : {
1121 0 : if( SvXMLUnitConverter::convertEnum( nEnum, rValue, getAnimationsEnumMap(Animations_EnumMap_TransitionSubType) ) )
1122 0 : xTransitionFilter->setSubtype( (sal_Int16)nEnum );
1123 : }
1124 : }
1125 0 : break;
1126 :
1127 : case ANA_Mode:
1128 : {
1129 0 : if( xTransitionFilter.is() )
1130 0 : xTransitionFilter->setMode( IsXMLToken( rValue, XML_IN ) );
1131 : }
1132 0 : break;
1133 :
1134 : case ANA_Direction:
1135 : {
1136 0 : if( xTransitionFilter.is() )
1137 0 : xTransitionFilter->setDirection( IsXMLToken( rValue, XML_FORWARD ) );
1138 : }
1139 0 : break;
1140 :
1141 : case ANA_FadeColor:
1142 : {
1143 0 : if( xTransitionFilter.is() )
1144 : {
1145 0 : sal_Int32 nColor(0);
1146 0 : ::sax::Converter::convertColor(nColor, rValue);
1147 0 : xTransitionFilter->setFadeColor(nColor);
1148 : }
1149 : }
1150 0 : break;
1151 :
1152 : case ANA_IterateType:
1153 : {
1154 0 : if( SvXMLUnitConverter::convertEnum( nEnum, rValue, getAnimationsEnumMap(Animations_EnumMap_IterateType) ) )
1155 : {
1156 0 : if( xIter.is() )
1157 0 : xIter->setIterateType( (sal_Int16)nEnum );
1158 : }
1159 : }
1160 0 : break;
1161 :
1162 : case ANA_IterateInterval:
1163 : {
1164 0 : if( xIter.is() )
1165 : {
1166 0 : double fInterval = 0.0;
1167 0 : if( rValue.matchAsciiL(RTL_CONSTASCII_STRINGPARAM("P")) )
1168 : {
1169 0 : ::com::sun::star::util::Duration aDuration;
1170 0 : if (::sax::Converter::convertDuration(aDuration, rValue))
1171 : {
1172 : fInterval = ((((aDuration.Hours * 60)
1173 : + aDuration.Minutes) * 60) + aDuration.Seconds)
1174 0 : + (aDuration.MilliSeconds / 1000.0);
1175 : }
1176 : }
1177 : else
1178 : {
1179 0 : fInterval = rValue.toDouble();
1180 : }
1181 :
1182 0 : xIter->setIterateInterval( fInterval );
1183 : }
1184 : }
1185 0 : break;
1186 :
1187 : case ANA_Group_Id:
1188 : {
1189 0 : aUserData.push_back( NamedValue( aLocalName, makeAny( rValue.toInt32() ) ) );
1190 : }
1191 0 : break;
1192 :
1193 : case ANA_Command:
1194 : {
1195 0 : if( xCommand.is() && nNodeType == AnimationNodeType::COMMAND )
1196 : {
1197 0 : if( SvXMLUnitConverter::convertEnum( nEnum, rValue, getAnimationsEnumMap(Animations_EnumMap_Command) ) )
1198 : {
1199 0 : xCommand->setCommand( (sal_Int16)nEnum );
1200 : }
1201 : }
1202 : }
1203 0 : break;
1204 :
1205 : default:
1206 : // push all unknown attributes within the presentation namespace as user data
1207 0 : if( nPrefix == XML_NAMESPACE_PRESENTATION )
1208 : {
1209 0 : aUserData.push_back( NamedValue( aLocalName, makeAny( rValue ) ) );
1210 : }
1211 : }
1212 0 : }
1213 :
1214 0 : if (!sXmlId.isEmpty())
1215 : {
1216 0 : Reference< XInterface > const xRef( mxNode, UNO_QUERY );
1217 0 : GetImport().getInterfaceToIdentifierMapper().registerReference(
1218 0 : sXmlId, xRef );
1219 : }
1220 :
1221 0 : sal_Int32 nUserDataCount = aUserData.size();
1222 0 : if( nUserDataCount )
1223 : {
1224 0 : Sequence< NamedValue > aUnoUserData( nUserDataCount );
1225 0 : NamedValue* pData = aUnoUserData.getArray();
1226 0 : std::list< NamedValue >::iterator aIter( aUserData.begin() );
1227 0 : const std::list< NamedValue >::iterator aEnd( aUserData.end() );
1228 0 : while( aIter != aEnd )
1229 0 : *pData++ = (*aIter++);
1230 :
1231 0 : mxNode->setUserData( aUnoUserData );
1232 : }
1233 :
1234 : // convert values
1235 0 : if( xAnimate.is() )
1236 : {
1237 0 : if( !aFrom.isEmpty() )
1238 0 : xAnimate->setFrom( mpHelper->convertValue( meAttributeName, aFrom ) );
1239 :
1240 0 : if( !aBy.isEmpty() )
1241 0 : xAnimate->setBy( mpHelper->convertValue( meAttributeName, aBy ) );
1242 :
1243 0 : if( !aTo.isEmpty() )
1244 0 : xAnimate->setTo( mpHelper->convertValue( meAttributeName, aTo ) );
1245 :
1246 0 : if( !aValues.isEmpty() )
1247 0 : xAnimate->setValues( mpHelper->convertValueSequence( meAttributeName, aValues ) );
1248 0 : }
1249 : }
1250 0 : catch (const RuntimeException&)
1251 : {
1252 : OSL_FAIL( "xmloff::AnimationNodeContext::StartElement(), RuntimeException caught!" );
1253 : }
1254 0 : }
1255 :
1256 0 : SvXMLImportContext * AnimationNodeContext::CreateChildContext( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName,
1257 : const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList )
1258 : {
1259 0 : if( mxNode.is())
1260 0 : return new AnimationNodeContext( mxNode, GetImport(), nPrefix, rLocalName, xAttrList, mpHelper );
1261 : else
1262 0 : return new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
1263 : }
1264 :
1265 : // --------------------------------------------------------------------
1266 :
1267 : class AnimationsImport: public SvXMLImport, public XAnimationNodeSupplier
1268 : {
1269 : public:
1270 : AnimationsImport( const Reference< XMultiServiceFactory > & rSMgr );
1271 : ~AnimationsImport() throw ();
1272 :
1273 : SvXMLImportContext* CreateContext(sal_uInt16 nPrefix, const OUString& rLocalName, const Reference<XAttributeList>& xAttrList);
1274 :
1275 : // XInterface
1276 : virtual Any SAL_CALL queryInterface( const Type& aType ) throw (RuntimeException);
1277 : virtual void SAL_CALL acquire() throw ();
1278 : virtual void SAL_CALL release() throw ();
1279 :
1280 : // XAnimationNodeSupplier
1281 : Reference< XAnimationNode > SAL_CALL getAnimationNode() throw (RuntimeException);
1282 :
1283 : // XServiceInfo
1284 : virtual OUString SAL_CALL getImplementationName() throw(RuntimeException);
1285 : virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw(RuntimeException);
1286 : virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() throw(RuntimeException);
1287 :
1288 : private:
1289 : Reference< XAnimationNode > mxRootNode;
1290 : };
1291 :
1292 1 : AnimationsImport::AnimationsImport( const Reference< XMultiServiceFactory > & rSMgr )
1293 1 : : SvXMLImport( rSMgr, true )
1294 : {
1295 : // add namespaces
1296 1 : GetNamespaceMap().Add(
1297 1 : GetXMLToken(XML_NP_PRESENTATION),
1298 1 : GetXMLToken(XML_N_PRESENTATION),
1299 1 : XML_NAMESPACE_PRESENTATION);
1300 :
1301 1 : GetNamespaceMap().Add(
1302 1 : GetXMLToken(XML_NP_SMIL),
1303 1 : GetXMLToken(XML_N_SMIL),
1304 1 : XML_NAMESPACE_SMIL);
1305 :
1306 1 : GetNamespaceMap().Add(
1307 1 : GetXMLToken(XML_NP_ANIMATION),
1308 1 : GetXMLToken(XML_N_ANIMATION),
1309 1 : XML_NAMESPACE_ANIMATION);
1310 :
1311 1 : mxRootNode = Reference< XAnimationNode >::query(rSMgr->createInstance(
1312 1 : OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.animations.SequenceTimeContainer"))));
1313 1 : }
1314 :
1315 2 : AnimationsImport::~AnimationsImport() throw ()
1316 : {
1317 2 : }
1318 :
1319 : // XInterface
1320 2 : Any SAL_CALL AnimationsImport::queryInterface( const Type& aType ) throw (RuntimeException)
1321 : {
1322 2 : if ( aType == ::getCppuType((Reference<XAnimationNodeSupplier> *)0) )
1323 : {
1324 0 : return makeAny( Reference<XAnimationNodeSupplier>( this ) );
1325 : }
1326 : else
1327 : {
1328 2 : return SvXMLImport::queryInterface( aType );
1329 : }
1330 : }
1331 :
1332 5 : void SAL_CALL AnimationsImport::acquire() throw ()
1333 : {
1334 5 : SvXMLImport::acquire();
1335 5 : }
1336 :
1337 5 : void SAL_CALL AnimationsImport::release() throw ()
1338 : {
1339 5 : SvXMLImport::release();
1340 5 : }
1341 :
1342 0 : SvXMLImportContext *AnimationsImport::CreateContext(sal_uInt16 nPrefix, const OUString& rLocalName, const Reference<XAttributeList>& xAttrList)
1343 : {
1344 0 : SvXMLImportContext* pContext = 0;
1345 :
1346 0 : if( (XML_NAMESPACE_ANIMATION == nPrefix) && IsXMLToken( rLocalName, XML_SEQ ) )
1347 : {
1348 0 : pContext = new AnimationNodeContext( mxRootNode, *this, nPrefix, rLocalName, xAttrList );
1349 : }
1350 : else
1351 : {
1352 0 : pContext = SvXMLImport::CreateContext(nPrefix, rLocalName, xAttrList);
1353 : }
1354 :
1355 0 : return pContext;
1356 : }
1357 :
1358 : // XAnimationNodeSupplier
1359 0 : Reference< XAnimationNode > SAL_CALL AnimationsImport::getAnimationNode() throw (RuntimeException)
1360 : {
1361 0 : return mxRootNode;
1362 : }
1363 :
1364 0 : void AnimationNodeContext::postProcessRootNode( SvXMLImport& /*rImport*/, const Reference< XAnimationNode >& xRootNode, Reference< XPropertySet >& xPageProps )
1365 : {
1366 0 : if( xRootNode.is() && xPageProps.is() ) try
1367 : {
1368 0 : Reference< XEnumerationAccess > xEnumerationAccess( xRootNode, UNO_QUERY_THROW );
1369 0 : Reference< XEnumeration > xEnumeration( xEnumerationAccess->createEnumeration(), UNO_QUERY_THROW );
1370 0 : if( xEnumeration->hasMoreElements() )
1371 : {
1372 0 : Reference< XAnimationNode > xNode( xEnumeration->nextElement(), UNO_QUERY_THROW );
1373 0 : if( xNode->getType() == AnimationNodeType::PAR )
1374 : {
1375 0 : Event aEvent;
1376 0 : if( (xNode->getBegin() >>= aEvent) && (aEvent.Trigger == EventTrigger::BEGIN_EVENT) )
1377 : {
1378 : // found transition node
1379 0 : Reference< XEnumerationAccess > xChildEnumerationAccess( xNode, UNO_QUERY_THROW );
1380 0 : Reference< XEnumeration > xChildEnumeration( xChildEnumerationAccess->createEnumeration(), UNO_QUERY_THROW );
1381 0 : while( xChildEnumeration->hasMoreElements() )
1382 : {
1383 0 : Reference< XAnimationNode > xChildNode( xChildEnumeration->nextElement(), UNO_QUERY_THROW );
1384 0 : switch( xChildNode->getType() )
1385 : {
1386 : case AnimationNodeType::TRANSITIONFILTER:
1387 : {
1388 0 : Reference< XTransitionFilter > xTransFilter( xChildNode, UNO_QUERY_THROW );
1389 :
1390 :
1391 0 : xPageProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "TransitionType" ) ), Any( xTransFilter->getTransition() ) );
1392 0 : xPageProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "TransitionSubtype" ) ), Any( xTransFilter->getSubtype() ) );
1393 0 : xPageProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "TransitionDirection" ) ), Any( xTransFilter->getDirection() ) );
1394 0 : xPageProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "TransitionFadeColor" ) ), Any( xTransFilter->getFadeColor() ) );
1395 :
1396 : double fDuration;
1397 0 : if( xTransFilter->getDuration() >>= fDuration )
1398 0 : xPageProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "TransitionDuration" ) ), Any( fDuration ) );
1399 :
1400 : }
1401 0 : break;
1402 :
1403 : case AnimationNodeType::COMMAND:
1404 : {
1405 0 : Reference< XCommand > xCommand( xChildNode, UNO_QUERY_THROW );
1406 0 : if( xCommand->getCommand() == EffectCommands::STOPAUDIO )
1407 : {
1408 0 : xPageProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "Sound" ) ), Any(sal_True) );
1409 0 : }
1410 : }
1411 0 : break;
1412 :
1413 : case AnimationNodeType::AUDIO:
1414 : {
1415 0 : Reference< XAudio > xAudio( xChildNode, UNO_QUERY_THROW );
1416 0 : OUString sSoundURL;
1417 0 : if( (xAudio->getSource() >>= sSoundURL) && !sSoundURL.isEmpty() )
1418 : {
1419 0 : xPageProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "Sound" ) ), Any(sSoundURL) );
1420 :
1421 : Timing eTiming;
1422 0 : if( (xAudio->getRepeatCount() >>= eTiming) && (eTiming == Timing_INDEFINITE) )
1423 0 : xPageProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "LoopSound" ) ), Any( sal_True ) );
1424 0 : }
1425 : }
1426 0 : break;
1427 :
1428 : }
1429 0 : }
1430 :
1431 0 : Reference< XTimeContainer > xRootContainer( xRootNode, UNO_QUERY_THROW );
1432 0 : xRootContainer->removeChild( xNode );
1433 0 : }
1434 0 : }
1435 0 : }
1436 : }
1437 0 : catch (const Exception&)
1438 : {
1439 : OSL_FAIL("xmloff::AnimationsImport::postProcessRootNode(), exception caught!");
1440 : }
1441 0 : }
1442 :
1443 : } // namespace xmloff
1444 :
1445 1 : Sequence< OUString > SAL_CALL AnimationsImport_getSupportedServiceNames() throw()
1446 : {
1447 1 : const OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.Xmloff.AnimationsImport" ) );
1448 1 : const Sequence< OUString > aSeq( &aServiceName, 1 );
1449 1 : return aSeq;
1450 : }
1451 :
1452 4 : OUString SAL_CALL AnimationsImport_getImplementationName() throw()
1453 : {
1454 4 : return OUString( RTL_CONSTASCII_USTRINGPARAM( "xmloff::AnimationsImport" ) );
1455 : }
1456 :
1457 1 : Reference< XInterface > SAL_CALL AnimationsImport_createInstance(const Reference< XMultiServiceFactory > & rSMgr) throw( Exception )
1458 : {
1459 1 : return (cppu::OWeakObject*)new xmloff::AnimationsImport( rSMgr );
1460 :
1461 : }
1462 :
1463 : namespace xmloff
1464 : {
1465 :
1466 0 : OUString SAL_CALL AnimationsImport::getImplementationName() throw(RuntimeException)
1467 : {
1468 0 : return AnimationsImport_getImplementationName();
1469 : }
1470 :
1471 0 : sal_Bool SAL_CALL AnimationsImport::supportsService( const OUString& ServiceName ) throw(RuntimeException)
1472 : {
1473 0 : return ServiceName == "com.sun.star.comp.Xmloff.AnimationsImport";
1474 : }
1475 :
1476 0 : Sequence< OUString > SAL_CALL AnimationsImport::getSupportedServiceNames() throw(RuntimeException)
1477 : {
1478 0 : return AnimationsImport_getSupportedServiceNames();
1479 : }
1480 :
1481 : } // namespace xmloff
1482 :
1483 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|