xref: /trunk/main/xmloff/source/draw/animimp.cxx (revision a633b3dd)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_xmloff.hxx"
26 
27 #include <tools/debug.hxx>
28 #include "unointerfacetouniqueidentifiermapper.hxx"
29 #include <com/sun/star/lang/XServiceInfo.hpp>
30 #include <com/sun/star/presentation/AnimationEffect.hpp>
31 #include <com/sun/star/presentation/AnimationSpeed.hpp>
32 #include <com/sun/star/beans/XPropertySet.hpp>
33 #include <com/sun/star/xml/sax/XAttributeList.hpp>
34 
35 #include <list>
36 #include <tools/color.hxx>
37 #include <comphelper/extract.hxx>
38 #include <xmloff/xmltoken.hxx>
39 #include <xmloff/xmlimp.hxx>
40 #include "xmloff/xmlnmspe.hxx"
41 #include <xmloff/xmluconv.hxx>
42 /*
43 #include <xmloff/xmlement.hxx>
44 */
45 #include <xmloff/nmspmap.hxx>
46 #include "anim.hxx"
47 #include "animimp.hxx"
48 
49 using ::rtl::OUString;
50 using ::rtl::OUStringBuffer;
51 
52 using namespace ::std;
53 using namespace ::cppu;
54 using namespace ::com::sun::star;
55 using namespace ::com::sun::star::xml;
56 using namespace ::com::sun::star::xml::sax;
57 using namespace ::com::sun::star::uno;
58 using namespace ::com::sun::star::drawing;
59 using namespace ::com::sun::star::beans;
60 using namespace ::com::sun::star::lang;
61 using namespace ::com::sun::star::presentation;
62 using namespace ::xmloff::token;
63 
64 SvXMLEnumMapEntry aXML_AnimationEffect_EnumMap[] =
65 {
66 	{ XML_NONE,			EK_none },
67 	{ XML_FADE,			EK_fade },
68 	{ XML_MOVE,			EK_move },
69 	{ XML_STRIPES,		EK_stripes },
70 	{ XML_OPEN,			EK_open },
71 	{ XML_CLOSE,		EK_close },
72 	{ XML_DISSOLVE,		EK_dissolve },
73 	{ XML_WAVYLINE,		EK_wavyline },
74 	{ XML_RANDOM,		EK_random },
75 	{ XML_LINES,		EK_lines },
76 	{ XML_LASER,		EK_laser },
77 	{ XML_APPEAR,		EK_appear },
78 	{ XML_HIDE,			EK_hide },
79 	{ XML_MOVE_SHORT,	EK_move_short },
80 	{ XML_CHECKERBOARD,	EK_checkerboard },
81 	{ XML_ROTATE,		EK_rotate },
82 	{ XML_STRETCH,		EK_stretch },
83 	{ XML_TOKEN_INVALID, 0 }
84 };
85 
86 SvXMLEnumMapEntry aXML_AnimationDirection_EnumMap[] =
87 {
88 	{ XML_NONE,				ED_none },
89 	{ XML_FROM_LEFT,		ED_from_left },
90 	{ XML_FROM_TOP,			ED_from_top },
91 	{ XML_FROM_RIGHT,		ED_from_right },
92 	{ XML_FROM_BOTTOM,		ED_from_bottom },
93 	{ XML_FROM_CENTER,		ED_from_center },
94 	{ XML_FROM_UPPER_LEFT,	ED_from_upperleft },
95 	{ XML_FROM_UPPER_RIGHT,	ED_from_upperright },
96 	{ XML_FROM_LOWER_LEFT,	ED_from_lowerleft },
97 	{ XML_FROM_LOWER_RIGHT,	ED_from_lowerright },
98 	{ XML_TO_LEFT,			ED_to_left },
99 	{ XML_TO_TOP,			ED_to_top },
100 	{ XML_TO_RIGHT,			ED_to_right },
101 	{ XML_TO_BOTTOM,		ED_to_bottom },
102 	{ XML_TO_UPPER_LEFT,	ED_to_upperleft },
103 	{ XML_TO_UPPER_RIGHT,	ED_to_upperright },
104 	{ XML_TO_LOWER_RIGHT,	ED_to_lowerright },
105 	{ XML_TO_LOWER_LEFT,	ED_to_lowerleft },
106 	{ XML_PATH,				ED_path },
107 	{ XML_SPIRAL_INWARD_LEFT,	ED_spiral_inward_left },
108 	{ XML_SPIRAL_INWARD_RIGHT,	ED_spiral_inward_right },
109 	{ XML_SPIRAL_OUTWARD_LEFT,	ED_spiral_outward_left },
110 	{ XML_SPIRAL_OUTWARD_RIGHT,	ED_spiral_outward_right },
111 	{ XML_VERTICAL,			ED_vertical },
112 	{ XML_HORIZONTAL,		ED_horizontal },
113 	{ XML_TO_CENTER,		ED_to_center },
114 	{ XML_CLOCKWISE,		ED_clockwise },
115 	{ XML_COUNTER_CLOCKWISE,ED_cclockwise },
116 	{ XML_TOKEN_INVALID, 0 }
117 };
118 
119 SvXMLEnumMapEntry aXML_AnimationSpeed_EnumMap[] =
120 {
121 	{ XML_SLOW,		AnimationSpeed_SLOW },
122 	{ XML_MEDIUM,	AnimationSpeed_MEDIUM },
123 	{ XML_FAST,		AnimationSpeed_FAST },
124 	{ XML_TOKEN_INVALID, 0 }
125 };
126 
ImplSdXMLgetEffect(XMLEffect eKind,XMLEffectDirection eDirection,sal_Int16 nStartScale,sal_Bool)127 AnimationEffect ImplSdXMLgetEffect( XMLEffect eKind, XMLEffectDirection eDirection, sal_Int16 nStartScale, sal_Bool /*bIn*/ )
128 {
129 	switch( eKind )
130 	{
131 	case EK_fade:
132 		switch( eDirection )
133 		{
134 		case ED_from_left:			return AnimationEffect_FADE_FROM_LEFT;
135 		case ED_from_top:			return AnimationEffect_FADE_FROM_TOP;
136 		case ED_from_right:			return AnimationEffect_FADE_FROM_RIGHT;
137 		case ED_from_bottom:		return AnimationEffect_FADE_FROM_BOTTOM;
138 		case ED_from_center:		return AnimationEffect_FADE_FROM_CENTER;
139 		case ED_from_upperleft:		return AnimationEffect_FADE_FROM_UPPERLEFT;
140 		case ED_from_upperright:	return AnimationEffect_FADE_FROM_UPPERRIGHT;
141 		case ED_from_lowerleft:		return AnimationEffect_FADE_FROM_LOWERLEFT;
142 		case ED_from_lowerright:	return AnimationEffect_FADE_FROM_LOWERRIGHT;
143 		case ED_to_center:			return AnimationEffect_FADE_TO_CENTER;
144 		case ED_clockwise:			return AnimationEffect_CLOCKWISE;
145 		case ED_cclockwise:			return AnimationEffect_COUNTERCLOCKWISE;
146 		case ED_spiral_inward_left:	return AnimationEffect_SPIRALIN_LEFT;
147 		case ED_spiral_inward_right:return AnimationEffect_SPIRALIN_RIGHT;
148 		case ED_spiral_outward_left:return AnimationEffect_SPIRALOUT_LEFT;
149 		case ED_spiral_outward_right:return AnimationEffect_SPIRALOUT_RIGHT;
150 		default:					return AnimationEffect_FADE_FROM_LEFT;
151 		}
152 	case EK_move:
153 		if( nStartScale == 200 )
154 		{
155 			return AnimationEffect_ZOOM_OUT_SMALL;
156 		}
157 		else if( nStartScale == 50 )
158 		{
159 			return AnimationEffect_ZOOM_IN_SMALL;
160 		}
161 		else if( nStartScale < 100 )
162 		{
163 			switch( eDirection )
164 			{
165 			case ED_from_left:			return AnimationEffect_ZOOM_IN_FROM_LEFT;
166 			case ED_from_top:			return AnimationEffect_ZOOM_IN_FROM_TOP;
167 			case ED_from_right:			return AnimationEffect_ZOOM_IN_FROM_RIGHT;
168 			case ED_from_bottom:		return AnimationEffect_ZOOM_IN_FROM_BOTTOM;
169 			case ED_from_upperleft:		return AnimationEffect_ZOOM_IN_FROM_UPPERLEFT;
170 			case ED_from_upperright:	return AnimationEffect_ZOOM_IN_FROM_UPPERRIGHT;
171 			case ED_from_lowerleft:		return AnimationEffect_ZOOM_IN_FROM_LOWERLEFT;
172 			case ED_from_lowerright:	return AnimationEffect_ZOOM_IN_FROM_LOWERRIGHT;
173 			case ED_from_center:		return AnimationEffect_ZOOM_IN_FROM_CENTER;
174 			case ED_spiral_inward_left:	return AnimationEffect_ZOOM_IN_SPIRAL;
175 			case ED_to_left:			return AnimationEffect_MOVE_TO_LEFT;
176 			case ED_to_top:				return AnimationEffect_MOVE_TO_TOP;
177 			case ED_to_right:			return AnimationEffect_MOVE_TO_RIGHT;
178 			case ED_to_bottom:			return AnimationEffect_MOVE_TO_BOTTOM;
179 			case ED_to_upperleft:		return AnimationEffect_MOVE_TO_UPPERLEFT;
180 			case ED_to_upperright:		return AnimationEffect_MOVE_TO_UPPERRIGHT;
181 			case ED_to_lowerright:		return AnimationEffect_MOVE_TO_LOWERRIGHT;
182 			case ED_to_lowerleft:		return AnimationEffect_MOVE_TO_LOWERLEFT;
183 			default:					return AnimationEffect_ZOOM_IN;
184 			}
185 		}
186 		else if( nStartScale > 100 )
187 		{
188 			switch( eDirection )
189 			{
190 			case ED_from_left:			return AnimationEffect_ZOOM_OUT_FROM_LEFT;
191 			case ED_from_top:			return AnimationEffect_ZOOM_OUT_FROM_TOP;
192 			case ED_from_right:			return AnimationEffect_ZOOM_OUT_FROM_RIGHT;
193 			case ED_from_bottom:		return AnimationEffect_ZOOM_OUT_FROM_BOTTOM;
194 			case ED_from_upperleft:		return AnimationEffect_ZOOM_OUT_FROM_UPPERLEFT;
195 			case ED_from_upperright:	return AnimationEffect_ZOOM_OUT_FROM_UPPERRIGHT;
196 			case ED_from_lowerleft:		return AnimationEffect_ZOOM_OUT_FROM_LOWERLEFT;
197 			case ED_from_lowerright:	return AnimationEffect_ZOOM_OUT_FROM_LOWERRIGHT;
198 			case ED_from_center:		return AnimationEffect_ZOOM_OUT_FROM_CENTER;
199 			case ED_spiral_inward_left:	return AnimationEffect_ZOOM_OUT_SPIRAL;
200 			default:					return AnimationEffect_ZOOM_OUT;
201 			}
202 		}
203 		else
204 		{
205 			switch( eDirection )
206 			{
207 			case ED_from_left:			return AnimationEffect_MOVE_FROM_LEFT;
208 			case ED_from_top:			return AnimationEffect_MOVE_FROM_TOP;
209 			case ED_from_right:			return AnimationEffect_MOVE_FROM_RIGHT;
210 			case ED_from_bottom:		return AnimationEffect_MOVE_FROM_BOTTOM;
211 			case ED_from_upperleft:		return AnimationEffect_MOVE_FROM_UPPERLEFT;
212 			case ED_from_upperright:	return AnimationEffect_MOVE_FROM_UPPERRIGHT;
213 			case ED_from_lowerleft:		return AnimationEffect_MOVE_FROM_LOWERLEFT;
214 			case ED_from_lowerright:	return AnimationEffect_MOVE_FROM_LOWERRIGHT;
215 			case ED_path:				return AnimationEffect_PATH;
216 			case ED_to_top:				return AnimationEffect_MOVE_TO_TOP;
217 			case ED_to_right:			return AnimationEffect_MOVE_TO_RIGHT;
218 			case ED_to_bottom:			return AnimationEffect_MOVE_TO_BOTTOM;
219 			case ED_to_upperleft:		return AnimationEffect_MOVE_TO_UPPERLEFT;
220 			case ED_to_upperright:		return AnimationEffect_MOVE_TO_UPPERRIGHT;
221 			case ED_to_lowerright:		return AnimationEffect_MOVE_TO_LOWERRIGHT;
222 			case ED_to_lowerleft:		return AnimationEffect_MOVE_TO_LOWERLEFT;
223 			default:
224 				break;
225 			}
226 		}
227 		return AnimationEffect_MOVE_FROM_LEFT;
228 	case EK_stripes:
229 		if( eDirection == ED_vertical )
230 			return AnimationEffect_VERTICAL_STRIPES;
231 		else
232 			return AnimationEffect_HORIZONTAL_STRIPES;
233 	case EK_open:
234 		if( eDirection == ED_vertical )
235 			return AnimationEffect_OPEN_VERTICAL;
236 		else
237 			return AnimationEffect_OPEN_HORIZONTAL;
238 	case EK_close:
239 		if( eDirection == ED_vertical )
240 			return AnimationEffect_CLOSE_VERTICAL;
241 		else
242 			return AnimationEffect_CLOSE_HORIZONTAL;
243 	case EK_dissolve:
244 		return AnimationEffect_DISSOLVE;
245 	case EK_wavyline:
246 		switch( eDirection )
247 		{
248 		case ED_from_left:			return AnimationEffect_WAVYLINE_FROM_LEFT;
249 		case ED_from_top:			return AnimationEffect_WAVYLINE_FROM_TOP;
250 		case ED_from_right:			return AnimationEffect_WAVYLINE_FROM_RIGHT;
251 		case ED_from_bottom:		return AnimationEffect_WAVYLINE_FROM_BOTTOM;
252 		default:					return AnimationEffect_WAVYLINE_FROM_LEFT;
253 		}
254 	case EK_random:
255 		return AnimationEffect_RANDOM;
256 	case EK_lines:
257 		if( eDirection == ED_vertical )
258 			return AnimationEffect_VERTICAL_LINES;
259 		else
260 			return AnimationEffect_HORIZONTAL_LINES;
261 	case EK_laser:
262 		switch( eDirection )
263 		{
264 		case ED_from_left:			return AnimationEffect_LASER_FROM_LEFT;
265 		case ED_from_top:			return AnimationEffect_LASER_FROM_TOP;
266 		case ED_from_right:			return AnimationEffect_LASER_FROM_RIGHT;
267 		case ED_from_bottom:		return AnimationEffect_LASER_FROM_BOTTOM;
268 		case ED_from_upperleft:		return AnimationEffect_LASER_FROM_UPPERLEFT;
269 		case ED_from_upperright:	return AnimationEffect_LASER_FROM_UPPERRIGHT;
270 		case ED_from_lowerleft:		return AnimationEffect_LASER_FROM_LOWERLEFT;
271 		case ED_from_lowerright:	return AnimationEffect_LASER_FROM_LOWERRIGHT;
272 		default:					return AnimationEffect_LASER_FROM_LEFT;
273 		}
274 	case EK_appear:
275 		return AnimationEffect_APPEAR;
276 	case EK_hide:
277 		return AnimationEffect_HIDE;
278 	case EK_move_short:
279 		switch( eDirection )
280 		{
281 		case ED_from_left:			return AnimationEffect_MOVE_SHORT_FROM_LEFT;
282 		case ED_from_top:			return AnimationEffect_MOVE_SHORT_FROM_TOP;
283 		case ED_from_right:			return AnimationEffect_MOVE_SHORT_FROM_RIGHT;
284 		case ED_from_bottom:		return AnimationEffect_MOVE_SHORT_FROM_BOTTOM;
285 		case ED_from_upperleft:		return AnimationEffect_MOVE_SHORT_FROM_UPPERLEFT;
286 		case ED_from_upperright:	return AnimationEffect_MOVE_SHORT_FROM_UPPERRIGHT;
287 		case ED_from_lowerleft:		return AnimationEffect_MOVE_SHORT_FROM_LOWERLEFT;
288 		case ED_from_lowerright:	return AnimationEffect_MOVE_SHORT_FROM_LOWERRIGHT;
289 		case ED_to_left:			return AnimationEffect_MOVE_SHORT_TO_LEFT;
290 		case ED_to_upperleft:		return AnimationEffect_MOVE_SHORT_TO_UPPERLEFT;
291 		case ED_to_top:				return AnimationEffect_MOVE_SHORT_TO_TOP;
292 		case ED_to_upperright:		return AnimationEffect_MOVE_SHORT_TO_UPPERRIGHT;
293 		case ED_to_right:			return AnimationEffect_MOVE_SHORT_TO_RIGHT;
294 		case ED_to_lowerright:		return AnimationEffect_MOVE_SHORT_TO_LOWERRIGHT;
295 		case ED_to_bottom:			return AnimationEffect_MOVE_SHORT_TO_BOTTOM;
296 		case ED_to_lowerleft:		return AnimationEffect_MOVE_SHORT_TO_LOWERLEFT;
297 		default:					return AnimationEffect_MOVE_SHORT_FROM_LEFT;
298 		}
299 	case EK_checkerboard:
300 		if( eDirection == ED_vertical )
301 			return AnimationEffect_VERTICAL_CHECKERBOARD;
302 		else
303 			return AnimationEffect_HORIZONTAL_CHECKERBOARD;
304 	case EK_rotate:
305 		if( eDirection == ED_vertical )
306 			return AnimationEffect_VERTICAL_ROTATE;
307 		else
308 			return AnimationEffect_HORIZONTAL_ROTATE;
309 	case EK_stretch:
310 		switch( eDirection )
311 		{
312 		case ED_from_left:			return AnimationEffect_STRETCH_FROM_LEFT;
313 		case ED_from_top:			return AnimationEffect_STRETCH_FROM_TOP;
314 		case ED_from_right:			return AnimationEffect_STRETCH_FROM_RIGHT;
315 		case ED_from_bottom:		return AnimationEffect_STRETCH_FROM_BOTTOM;
316 		case ED_from_upperleft:		return AnimationEffect_STRETCH_FROM_UPPERLEFT;
317 		case ED_from_upperright:	return AnimationEffect_STRETCH_FROM_UPPERRIGHT;
318 		case ED_from_lowerleft:		return AnimationEffect_STRETCH_FROM_LOWERLEFT;
319 		case ED_from_lowerright:	return AnimationEffect_STRETCH_FROM_LOWERRIGHT;
320 		case ED_vertical:			return AnimationEffect_VERTICAL_STRETCH;
321 		case ED_horizontal:			return AnimationEffect_HORIZONTAL_STRETCH;
322 		default:
323 			break;
324 		}
325 		return AnimationEffect_STRETCH_FROM_LEFT;
326 	default:
327 		return AnimationEffect_NONE;
328 	}
329 }
330 
331 ///////////////////////////////////////////////////////////////////////
332 
333 class AnimImpImpl
334 {
335 public:
336 	Reference< XPropertySet > mxLastShape;
337 	OUString maLastShapeId;
338 
339 	OUString msDimColor;
340 	OUString msDimHide;
341 	OUString msDimPrev;
342 	OUString msEffect;
343 	OUString msPlayFull;
344 	OUString msPresOrder;
345 	OUString msSound;
346 	OUString msSoundOn;
347 	OUString msSpeed;
348 	OUString msTextEffect;
349 	OUString msPresShapeService;
350 	OUString msAnimPath;
351 	OUString msIsAnimation;
352 
AnimImpImpl()353 	AnimImpImpl()
354 	:	msDimColor( RTL_CONSTASCII_USTRINGPARAM( "DimColor" ) ),
355 		msDimHide( RTL_CONSTASCII_USTRINGPARAM( "DimHide" ) ),
356 		msDimPrev( RTL_CONSTASCII_USTRINGPARAM( "DimPrevious" ) ),
357 		msEffect( RTL_CONSTASCII_USTRINGPARAM( "Effect" ) ),
358 		msPlayFull( RTL_CONSTASCII_USTRINGPARAM( "PlayFull" ) ),
359 		msPresOrder( RTL_CONSTASCII_USTRINGPARAM( "PresentationOrder" ) ),
360 		msSound( RTL_CONSTASCII_USTRINGPARAM( "Sound" ) ),
361 		msSoundOn( RTL_CONSTASCII_USTRINGPARAM( "SoundOn" ) ),
362 		msSpeed( RTL_CONSTASCII_USTRINGPARAM( "Speed" ) ),
363 		msTextEffect( RTL_CONSTASCII_USTRINGPARAM( "TextEffect" ) ),
364 		msPresShapeService( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.presentation.Shape" ) ),
365 		msAnimPath( RTL_CONSTASCII_USTRINGPARAM( "AnimationPath" ) ),
366 		msIsAnimation( RTL_CONSTASCII_USTRINGPARAM( "IsAnimation" ) )
367 	{}
368 };
369 
370 ///////////////////////////////////////////////////////////////////////
371 
372 enum XMLActionKind
373 {
374 	XMLE_SHOW,
375 	XMLE_HIDE,
376 	XMLE_DIM,
377 	XMLE_PLAY
378 };
379 
380 class XMLAnimationsEffectContext : public SvXMLImportContext
381 {
382 public:
383 	AnimImpImpl*	mpImpl;
384 
385 	XMLActionKind	meKind;
386 	sal_Bool		mbTextEffect;
387 	OUString		maShapeId;
388 
389 	XMLEffect		meEffect;
390 	XMLEffectDirection	meDirection;
391 	sal_Int16		mnStartScale;
392 
393 	AnimationSpeed	meSpeed;
394 	Color			maDimColor;
395 	OUString		maSoundURL;
396 	sal_Bool		mbPlayFull;
397 	OUString		maPathShapeId;
398 
399 public:
400 	TYPEINFO();
401 
402 	XMLAnimationsEffectContext( SvXMLImport& rImport,
403 		sal_uInt16 nPrfx,
404 		const OUString& rLocalName,
405 		const Reference< XAttributeList >& xAttrList,
406 		AnimImpImpl* pImpl);
407 	virtual ~XMLAnimationsEffectContext();
408 
409 	virtual void EndElement();
410 
411 	virtual SvXMLImportContext * CreateChildContext( sal_uInt16 nPrefix, const OUString& rLocalName,
412 		const Reference< XAttributeList >& xAttrList );
413 };
414 
415 class XMLAnimationsSoundContext : public SvXMLImportContext
416 {
417 	XMLAnimationsEffectContext* mpParent;
418 
419 public:
420 	TYPEINFO();
421 
422 	XMLAnimationsSoundContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLocalName, const Reference< XAttributeList >& xAttrList, XMLAnimationsEffectContext* pParent );
423 	virtual ~XMLAnimationsSoundContext();
424 };
425 
426 TYPEINIT1( XMLAnimationsSoundContext, SvXMLImportContext );
427 
XMLAnimationsSoundContext(SvXMLImport & rImport,sal_uInt16 nPrfx,const OUString & rLocalName,const Reference<XAttributeList> & xAttrList,XMLAnimationsEffectContext * pParent)428 XMLAnimationsSoundContext::XMLAnimationsSoundContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLocalName, const Reference< XAttributeList >& xAttrList, XMLAnimationsEffectContext* pParent )
429 : SvXMLImportContext( rImport, nPrfx, rLocalName ), mpParent( pParent )
430 {
431 	if( mpParent && nPrfx == XML_NAMESPACE_PRESENTATION && IsXMLToken( rLocalName, XML_SOUND ) )
432 	{
433 		const sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
434 		for(sal_Int16 i=0; i < nAttrCount; i++)
435 		{
436 			OUString sAttrName = xAttrList->getNameByIndex( i );
437 			OUString aLocalName;
438 			sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
439 			OUString sValue = xAttrList->getValueByIndex( i );
440 
441 			switch( nPrefix )
442 			{
443 			case XML_NAMESPACE_XLINK:
444 				if( IsXMLToken( aLocalName, XML_HREF ) )
445 				{
446 					mpParent->maSoundURL = rImport.GetAbsoluteReference(sValue);
447 				}
448 				break;
449 			case XML_NAMESPACE_PRESENTATION:
450 				if( IsXMLToken( aLocalName, XML_PLAY_FULL ) )
451 				{
452 					mpParent->mbPlayFull = IsXMLToken( sValue, XML_TRUE );
453 				}
454 			}
455 		}
456 	}
457 }
458 
~XMLAnimationsSoundContext()459 XMLAnimationsSoundContext::~XMLAnimationsSoundContext()
460 {
461 }
462 
463 
464 TYPEINIT1( XMLAnimationsEffectContext, SvXMLImportContext );
465 
XMLAnimationsEffectContext(SvXMLImport & rImport,sal_uInt16 nPrfx,const OUString & rLocalName,const Reference<XAttributeList> & xAttrList,AnimImpImpl * pImpl)466 XMLAnimationsEffectContext::XMLAnimationsEffectContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLocalName, const Reference< XAttributeList >& xAttrList, AnimImpImpl* pImpl )
467 :	SvXMLImportContext(rImport, nPrfx, rLocalName),
468 	mpImpl( pImpl ),
469 	meKind( XMLE_SHOW ), mbTextEffect( sal_False ),
470 	meEffect( EK_none ), meDirection( ED_none ), mnStartScale( 100 ),
471 	meSpeed( AnimationSpeed_MEDIUM ), maDimColor(0), mbPlayFull( sal_False )
472 {
473 	if( IsXMLToken( rLocalName, XML_SHOW_SHAPE ) )
474 	{
475 		meKind = XMLE_SHOW;
476 	}
477 	else if( IsXMLToken( rLocalName, XML_SHOW_TEXT ) )
478 	{
479 		meKind = XMLE_SHOW;
480 		mbTextEffect = sal_True;
481 	}
482 	else if( IsXMLToken( rLocalName, XML_HIDE_SHAPE ) )
483 	{
484 		meKind = XMLE_HIDE;
485 	}
486 	else if( IsXMLToken( rLocalName, XML_HIDE_TEXT ) )
487 	{
488 		meKind = XMLE_HIDE;
489 		mbTextEffect = sal_True;
490 	}
491 	else if( IsXMLToken( rLocalName, XML_DIM ) )
492 	{
493 		meKind = XMLE_DIM;
494 	}
495 	else if( IsXMLToken( rLocalName, XML_PLAY ) )
496 	{
497 		meKind = XMLE_PLAY;
498 	}
499 	else
500 	{
501 		// unknown action, overread
502 		return;
503 	}
504 
505 	// read attributes
506 	const sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
507 	for(sal_Int16 i=0; i < nAttrCount; i++)
508 	{
509 		OUString sAttrName = xAttrList->getNameByIndex( i );
510 		OUString aLocalName;
511 		sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
512 		OUString sValue = xAttrList->getValueByIndex( i );
513 
514 		switch( nPrefix )
515 		{
516 		case XML_NAMESPACE_DRAW:
517 			if( IsXMLToken( aLocalName, XML_SHAPE_ID ) )
518 			{
519 				maShapeId = sValue;
520 			}
521 			else if( IsXMLToken( aLocalName, XML_COLOR ) )
522 			{
523 				SvXMLUnitConverter::convertColor(maDimColor, sValue);
524 			}
525 			break;
526 
527 		case XML_NAMESPACE_PRESENTATION:
528 			if( IsXMLToken( aLocalName, XML_EFFECT ) )
529 			{
530 				sal_uInt16 eEnum;
531 				if( SvXMLUnitConverter::convertEnum( eEnum, sValue, aXML_AnimationEffect_EnumMap ) )
532 					meEffect = (XMLEffect)eEnum;
533 			}
534 			else if( IsXMLToken(aLocalName, XML_DIRECTION ) )
535 			{
536 				sal_uInt16 eEnum;
537 				if( SvXMLUnitConverter::convertEnum( eEnum, sValue, aXML_AnimationDirection_EnumMap ) )
538 					meDirection = (XMLEffectDirection)eEnum;
539 			}
540 			else if( IsXMLToken( aLocalName, XML_START_SCALE ) )
541 			{
542 				sal_Int32 nScale;
543 				if( SvXMLUnitConverter::convertPercent( nScale, sValue ) )
544 					mnStartScale = (sal_Int16)nScale;
545 			}
546 			else if( IsXMLToken( aLocalName, XML_SPEED ) )
547 			{
548 				sal_uInt16 eEnum;
549 				if( SvXMLUnitConverter::convertEnum( eEnum, sValue, aXML_AnimationSpeed_EnumMap ) )
550 					meSpeed = (AnimationSpeed)eEnum;
551 			}
552 			else if( IsXMLToken( aLocalName, XML_PATH_ID ) )
553 			{
554 				maPathShapeId = sValue;
555 			}
556 			break;
557 		}
558 	}
559 }
560 
~XMLAnimationsEffectContext()561 XMLAnimationsEffectContext::~XMLAnimationsEffectContext()
562 {
563 }
564 
CreateChildContext(sal_uInt16 nPrefix,const OUString & rLocalName,const Reference<XAttributeList> & xAttrList)565 SvXMLImportContext * XMLAnimationsEffectContext::CreateChildContext( sal_uInt16 nPrefix, const OUString& rLocalName, const Reference< XAttributeList>& xAttrList )
566 {
567 	return new XMLAnimationsSoundContext( GetImport(), nPrefix, rLocalName, xAttrList, this );
568 }
569 
EndElement()570 void XMLAnimationsEffectContext::EndElement()
571 {
572 	// set effect on shape
573 
574 	try
575 	{
576 		UniReference< XMLShapeImportHelper > xShapeImport( GetImport().GetShapeImport() );
577 		Any aAny;
578 
579 		if( maShapeId.getLength() )
580 		{
581 			Reference< XPropertySet > xSet;
582 			if( mpImpl->maLastShapeId != maShapeId )
583 			{
584 				xSet = Reference< XPropertySet >::query( GetImport().getInterfaceToIdentifierMapper().getReference( maShapeId ) );
585 				if( xSet.is() )
586 				{
587 					// check for presentation shape service
588 					{
589 						Reference< XServiceInfo > xServiceInfo( xSet, UNO_QUERY );
590 						if( !xServiceInfo.is() || !xServiceInfo->supportsService( mpImpl->msPresShapeService ) )
591 							return;
592 					}
593 
594 					mpImpl->maLastShapeId = maShapeId;
595 					mpImpl->mxLastShape = xSet;
596 				}
597 			}
598 			else
599 			{
600 				xSet = mpImpl->mxLastShape;
601 			}
602 
603 			if( xSet.is() )
604 			{
605 				if( meKind == XMLE_DIM )
606 				{
607 					aAny <<= (sal_Bool)sal_True;
608 					xSet->setPropertyValue( mpImpl->msDimPrev, aAny );
609 
610 					aAny <<= (sal_Int32)maDimColor.GetColor();
611 					xSet->setPropertyValue( mpImpl->msDimColor, aAny );
612 				}
613 				else if( meKind == XMLE_PLAY )
614 				{
615 					aAny <<= (sal_Bool)sal_True;
616 					xSet->setPropertyValue( mpImpl->msIsAnimation, aAny );
617 
618 					// #42894# speed is not supported for the old group animation fallback, so no need to set it
619 					// aAny <<= meSpeed;
620 					// xSet->setPropertyValue( mpImpl->msSpeed, aAny );
621 				}
622 				else
623 				{
624 					if( meKind == XMLE_HIDE && !mbTextEffect && meEffect == EK_none )
625 					{
626 						aAny = bool2any( sal_True );
627 						xSet->setPropertyValue( mpImpl->msDimHide, aAny );
628 					}
629 					else
630 					{
631 						const AnimationEffect eEffect = ImplSdXMLgetEffect( meEffect, meDirection, mnStartScale, meKind == XMLE_SHOW );
632 
633 						xSet->setPropertyValue( mbTextEffect ? mpImpl->msTextEffect : mpImpl->msEffect, makeAny( eEffect ) );
634 						xSet->setPropertyValue( mpImpl->msSpeed, makeAny( meSpeed ) );
635 
636 						if( eEffect == AnimationEffect_PATH && maPathShapeId.getLength() )
637 						{
638 							Reference< XShape > xPath( GetImport().getInterfaceToIdentifierMapper().getReference( maPathShapeId ), UNO_QUERY );
639 							if( xPath.is() )
640 								xSet->setPropertyValue( mpImpl->msAnimPath, makeAny( xPath ) );
641 						}
642 					}
643 				}
644 			}
645 			if( maSoundURL.getLength() != 0 )
646 			{
647 				if( xSet.is() )
648 				{
649 					aAny <<= maSoundURL;
650 					xSet->setPropertyValue( mpImpl->msSound, aAny );
651 
652 					aAny <<= bool2any( mbPlayFull );
653 					xSet->setPropertyValue( mpImpl->msPlayFull, aAny );
654 
655 					aAny <<= bool2any( sal_True );
656 					xSet->setPropertyValue( mpImpl->msSoundOn, aAny );
657 				}
658 				else
659 				{
660 					DBG_ERROR("XMLAnimationsEffectContext::EndElement - Sound URL without a XPropertySet!");
661 				}
662 			}
663 		}
664 	}
665 	catch( Exception e )
666 	{
667 		DBG_ERROR( "exception caught while importing animation information!" );
668 	}
669 }
670 
671 ///////////////////////////////////////////////////////////////////////
672 
673 TYPEINIT1( XMLAnimationsContext, SvXMLImportContext );
674 
XMLAnimationsContext(SvXMLImport & rImport,sal_uInt16 nPrfx,const rtl::OUString & rLocalName,const com::sun::star::uno::Reference<com::sun::star::xml::sax::XAttributeList> &)675 XMLAnimationsContext::XMLAnimationsContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const rtl::OUString& rLocalName,
676 		const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& )
677 : SvXMLImportContext(rImport, nPrfx, rLocalName)
678 {
679 	mpImpl = new AnimImpImpl();
680 }
681 
~XMLAnimationsContext()682 XMLAnimationsContext::~XMLAnimationsContext()
683 {
684 	delete mpImpl;
685 }
686 
CreateChildContext(sal_uInt16 nPrefix,const::rtl::OUString & rLocalName,const com::sun::star::uno::Reference<com::sun::star::xml::sax::XAttributeList> & xAttrList)687 SvXMLImportContext * XMLAnimationsContext::CreateChildContext( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName,
688 		const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList )
689 {
690 	return new XMLAnimationsEffectContext( GetImport(), nPrefix, rLocalName, xAttrList, mpImpl );
691 }
692