merge the formfield patch from ooo-build
[ooovba.git] / xmloff / source / draw / animimp.cxx
blobe3cbe881634d92797de3981add19ff12884431f6
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: animimp.cxx,v $
10 * $Revision: 1.20 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
34 #include <tools/debug.hxx>
35 #include "unointerfacetouniqueidentifiermapper.hxx"
36 #include <com/sun/star/lang/XServiceInfo.hpp>
37 #include <com/sun/star/presentation/AnimationEffect.hpp>
38 #include <com/sun/star/presentation/AnimationSpeed.hpp>
39 #include <com/sun/star/beans/XPropertySet.hpp>
40 #include <com/sun/star/xml/sax/XAttributeList.hpp>
42 #include <list>
43 #include <tools/color.hxx>
44 #include <comphelper/extract.hxx>
45 #include <xmloff/xmltoken.hxx>
46 #include <xmloff/xmlimp.hxx>
47 #include "xmlnmspe.hxx"
48 #include <xmloff/xmluconv.hxx>
50 #include <xmloff/xmlement.hxx>
52 #include <xmloff/nmspmap.hxx>
53 #include "anim.hxx"
54 #include "animimp.hxx"
56 using ::rtl::OUString;
57 using ::rtl::OUStringBuffer;
59 using namespace ::std;
60 using namespace ::cppu;
61 using namespace ::com::sun::star;
62 using namespace ::com::sun::star::xml;
63 using namespace ::com::sun::star::xml::sax;
64 using namespace ::com::sun::star::uno;
65 using namespace ::com::sun::star::drawing;
66 using namespace ::com::sun::star::beans;
67 using namespace ::com::sun::star::lang;
68 using namespace ::com::sun::star::presentation;
69 using namespace ::xmloff::token;
71 SvXMLEnumMapEntry aXML_AnimationEffect_EnumMap[] =
73 { XML_NONE, EK_none },
74 { XML_FADE, EK_fade },
75 { XML_MOVE, EK_move },
76 { XML_STRIPES, EK_stripes },
77 { XML_OPEN, EK_open },
78 { XML_CLOSE, EK_close },
79 { XML_DISSOLVE, EK_dissolve },
80 { XML_WAVYLINE, EK_wavyline },
81 { XML_RANDOM, EK_random },
82 { XML_LINES, EK_lines },
83 { XML_LASER, EK_laser },
84 { XML_APPEAR, EK_appear },
85 { XML_HIDE, EK_hide },
86 { XML_MOVE_SHORT, EK_move_short },
87 { XML_CHECKERBOARD, EK_checkerboard },
88 { XML_ROTATE, EK_rotate },
89 { XML_STRETCH, EK_stretch },
90 { XML_TOKEN_INVALID, 0 }
93 SvXMLEnumMapEntry aXML_AnimationDirection_EnumMap[] =
95 { XML_NONE, ED_none },
96 { XML_FROM_LEFT, ED_from_left },
97 { XML_FROM_TOP, ED_from_top },
98 { XML_FROM_RIGHT, ED_from_right },
99 { XML_FROM_BOTTOM, ED_from_bottom },
100 { XML_FROM_CENTER, ED_from_center },
101 { XML_FROM_UPPER_LEFT, ED_from_upperleft },
102 { XML_FROM_UPPER_RIGHT, ED_from_upperright },
103 { XML_FROM_LOWER_LEFT, ED_from_lowerleft },
104 { XML_FROM_LOWER_RIGHT, ED_from_lowerright },
105 { XML_TO_LEFT, ED_to_left },
106 { XML_TO_TOP, ED_to_top },
107 { XML_TO_RIGHT, ED_to_right },
108 { XML_TO_BOTTOM, ED_to_bottom },
109 { XML_TO_UPPER_LEFT, ED_to_upperleft },
110 { XML_TO_UPPER_RIGHT, ED_to_upperright },
111 { XML_TO_LOWER_RIGHT, ED_to_lowerright },
112 { XML_TO_LOWER_LEFT, ED_to_lowerleft },
113 { XML_PATH, ED_path },
114 { XML_SPIRAL_INWARD_LEFT, ED_spiral_inward_left },
115 { XML_SPIRAL_INWARD_RIGHT,ED_spiral_inward_right },
116 { XML_SPIRAL_OUTWARD_LEFT, ED_spiral_outward_left },
117 { XML_SPIRAL_OUTWARD_RIGHT, ED_spiral_outward_right },
118 { XML_VERTICAL, ED_vertical },
119 { XML_HORIZONTAL, ED_horizontal },
120 { XML_TO_CENTER, ED_to_center },
121 { XML_CLOCKWISE, ED_clockwise },
122 { XML_COUNTER_CLOCKWISE,ED_cclockwise },
123 { XML_TOKEN_INVALID, 0 }
126 SvXMLEnumMapEntry aXML_AnimationSpeed_EnumMap[] =
128 { XML_SLOW, AnimationSpeed_SLOW },
129 { XML_MEDIUM, AnimationSpeed_MEDIUM },
130 { XML_FAST, AnimationSpeed_FAST },
131 { XML_TOKEN_INVALID, 0 }
134 AnimationEffect ImplSdXMLgetEffect( XMLEffect eKind, XMLEffectDirection eDirection, sal_Int16 nStartScale, sal_Bool /*bIn*/ )
136 switch( eKind )
138 case EK_fade:
139 switch( eDirection )
141 case ED_from_left: return AnimationEffect_FADE_FROM_LEFT;
142 case ED_from_top: return AnimationEffect_FADE_FROM_TOP;
143 case ED_from_right: return AnimationEffect_FADE_FROM_RIGHT;
144 case ED_from_bottom: return AnimationEffect_FADE_FROM_BOTTOM;
145 case ED_from_center: return AnimationEffect_FADE_FROM_CENTER;
146 case ED_from_upperleft: return AnimationEffect_FADE_FROM_UPPERLEFT;
147 case ED_from_upperright: return AnimationEffect_FADE_FROM_UPPERRIGHT;
148 case ED_from_lowerleft: return AnimationEffect_FADE_FROM_LOWERLEFT;
149 case ED_from_lowerright: return AnimationEffect_FADE_FROM_LOWERRIGHT;
150 case ED_to_center: return AnimationEffect_FADE_TO_CENTER;
151 case ED_clockwise: return AnimationEffect_CLOCKWISE;
152 case ED_cclockwise: return AnimationEffect_COUNTERCLOCKWISE;
153 case ED_spiral_inward_left: return AnimationEffect_SPIRALIN_LEFT;
154 case ED_spiral_inward_right:return AnimationEffect_SPIRALIN_RIGHT;
155 case ED_spiral_outward_left:return AnimationEffect_SPIRALOUT_LEFT;
156 case ED_spiral_outward_right:return AnimationEffect_SPIRALOUT_RIGHT;
157 default: return AnimationEffect_FADE_FROM_LEFT;
159 case EK_move:
160 if( nStartScale == 200 )
162 return AnimationEffect_ZOOM_OUT_SMALL;
164 else if( nStartScale == 50 )
166 return AnimationEffect_ZOOM_IN_SMALL;
168 else if( nStartScale < 100 )
170 switch( eDirection )
172 case ED_from_left: return AnimationEffect_ZOOM_IN_FROM_LEFT;
173 case ED_from_top: return AnimationEffect_ZOOM_IN_FROM_TOP;
174 case ED_from_right: return AnimationEffect_ZOOM_IN_FROM_RIGHT;
175 case ED_from_bottom: return AnimationEffect_ZOOM_IN_FROM_BOTTOM;
176 case ED_from_upperleft: return AnimationEffect_ZOOM_IN_FROM_UPPERLEFT;
177 case ED_from_upperright: return AnimationEffect_ZOOM_IN_FROM_UPPERRIGHT;
178 case ED_from_lowerleft: return AnimationEffect_ZOOM_IN_FROM_LOWERLEFT;
179 case ED_from_lowerright: return AnimationEffect_ZOOM_IN_FROM_LOWERRIGHT;
180 case ED_from_center: return AnimationEffect_ZOOM_IN_FROM_CENTER;
181 case ED_spiral_inward_left: return AnimationEffect_ZOOM_IN_SPIRAL;
182 case ED_to_left: return AnimationEffect_MOVE_TO_LEFT;
183 case ED_to_top: return AnimationEffect_MOVE_TO_TOP;
184 case ED_to_right: return AnimationEffect_MOVE_TO_RIGHT;
185 case ED_to_bottom: return AnimationEffect_MOVE_TO_BOTTOM;
186 case ED_to_upperleft: return AnimationEffect_MOVE_TO_UPPERLEFT;
187 case ED_to_upperright: return AnimationEffect_MOVE_TO_UPPERRIGHT;
188 case ED_to_lowerright: return AnimationEffect_MOVE_TO_LOWERRIGHT;
189 case ED_to_lowerleft: return AnimationEffect_MOVE_TO_LOWERLEFT;
190 default: return AnimationEffect_ZOOM_IN;
193 else if( nStartScale > 100 )
195 switch( eDirection )
197 case ED_from_left: return AnimationEffect_ZOOM_OUT_FROM_LEFT;
198 case ED_from_top: return AnimationEffect_ZOOM_OUT_FROM_TOP;
199 case ED_from_right: return AnimationEffect_ZOOM_OUT_FROM_RIGHT;
200 case ED_from_bottom: return AnimationEffect_ZOOM_OUT_FROM_BOTTOM;
201 case ED_from_upperleft: return AnimationEffect_ZOOM_OUT_FROM_UPPERLEFT;
202 case ED_from_upperright: return AnimationEffect_ZOOM_OUT_FROM_UPPERRIGHT;
203 case ED_from_lowerleft: return AnimationEffect_ZOOM_OUT_FROM_LOWERLEFT;
204 case ED_from_lowerright: return AnimationEffect_ZOOM_OUT_FROM_LOWERRIGHT;
205 case ED_from_center: return AnimationEffect_ZOOM_OUT_FROM_CENTER;
206 case ED_spiral_inward_left: return AnimationEffect_ZOOM_OUT_SPIRAL;
207 default: return AnimationEffect_ZOOM_OUT;
210 else
212 switch( eDirection )
214 case ED_from_left: return AnimationEffect_MOVE_FROM_LEFT;
215 case ED_from_top: return AnimationEffect_MOVE_FROM_TOP;
216 case ED_from_right: return AnimationEffect_MOVE_FROM_RIGHT;
217 case ED_from_bottom: return AnimationEffect_MOVE_FROM_BOTTOM;
218 case ED_from_upperleft: return AnimationEffect_MOVE_FROM_UPPERLEFT;
219 case ED_from_upperright: return AnimationEffect_MOVE_FROM_UPPERRIGHT;
220 case ED_from_lowerleft: return AnimationEffect_MOVE_FROM_LOWERLEFT;
221 case ED_from_lowerright: return AnimationEffect_MOVE_FROM_LOWERRIGHT;
222 case ED_path: return AnimationEffect_PATH;
223 case ED_to_top: return AnimationEffect_MOVE_TO_TOP;
224 case ED_to_right: return AnimationEffect_MOVE_TO_RIGHT;
225 case ED_to_bottom: return AnimationEffect_MOVE_TO_BOTTOM;
226 case ED_to_upperleft: return AnimationEffect_MOVE_TO_UPPERLEFT;
227 case ED_to_upperright: return AnimationEffect_MOVE_TO_UPPERRIGHT;
228 case ED_to_lowerright: return AnimationEffect_MOVE_TO_LOWERRIGHT;
229 case ED_to_lowerleft: return AnimationEffect_MOVE_TO_LOWERLEFT;
230 default:
231 break;
234 return AnimationEffect_MOVE_FROM_LEFT;
235 case EK_stripes:
236 if( eDirection == ED_vertical )
237 return AnimationEffect_VERTICAL_STRIPES;
238 else
239 return AnimationEffect_HORIZONTAL_STRIPES;
240 case EK_open:
241 if( eDirection == ED_vertical )
242 return AnimationEffect_OPEN_VERTICAL;
243 else
244 return AnimationEffect_OPEN_HORIZONTAL;
245 case EK_close:
246 if( eDirection == ED_vertical )
247 return AnimationEffect_CLOSE_VERTICAL;
248 else
249 return AnimationEffect_CLOSE_HORIZONTAL;
250 case EK_dissolve:
251 return AnimationEffect_DISSOLVE;
252 case EK_wavyline:
253 switch( eDirection )
255 case ED_from_left: return AnimationEffect_WAVYLINE_FROM_LEFT;
256 case ED_from_top: return AnimationEffect_WAVYLINE_FROM_TOP;
257 case ED_from_right: return AnimationEffect_WAVYLINE_FROM_RIGHT;
258 case ED_from_bottom: return AnimationEffect_WAVYLINE_FROM_BOTTOM;
259 default: return AnimationEffect_WAVYLINE_FROM_LEFT;
261 case EK_random:
262 return AnimationEffect_RANDOM;
263 case EK_lines:
264 if( eDirection == ED_vertical )
265 return AnimationEffect_VERTICAL_LINES;
266 else
267 return AnimationEffect_HORIZONTAL_LINES;
268 case EK_laser:
269 switch( eDirection )
271 case ED_from_left: return AnimationEffect_LASER_FROM_LEFT;
272 case ED_from_top: return AnimationEffect_LASER_FROM_TOP;
273 case ED_from_right: return AnimationEffect_LASER_FROM_RIGHT;
274 case ED_from_bottom: return AnimationEffect_LASER_FROM_BOTTOM;
275 case ED_from_upperleft: return AnimationEffect_LASER_FROM_UPPERLEFT;
276 case ED_from_upperright: return AnimationEffect_LASER_FROM_UPPERRIGHT;
277 case ED_from_lowerleft: return AnimationEffect_LASER_FROM_LOWERLEFT;
278 case ED_from_lowerright: return AnimationEffect_LASER_FROM_LOWERRIGHT;
279 default: return AnimationEffect_LASER_FROM_LEFT;
281 case EK_appear:
282 return AnimationEffect_APPEAR;
283 case EK_hide:
284 return AnimationEffect_HIDE;
285 case EK_move_short:
286 switch( eDirection )
288 case ED_from_left: return AnimationEffect_MOVE_SHORT_FROM_LEFT;
289 case ED_from_top: return AnimationEffect_MOVE_SHORT_FROM_TOP;
290 case ED_from_right: return AnimationEffect_MOVE_SHORT_FROM_RIGHT;
291 case ED_from_bottom: return AnimationEffect_MOVE_SHORT_FROM_BOTTOM;
292 case ED_from_upperleft: return AnimationEffect_MOVE_SHORT_FROM_UPPERLEFT;
293 case ED_from_upperright: return AnimationEffect_MOVE_SHORT_FROM_UPPERRIGHT;
294 case ED_from_lowerleft: return AnimationEffect_MOVE_SHORT_FROM_LOWERLEFT;
295 case ED_from_lowerright: return AnimationEffect_MOVE_SHORT_FROM_LOWERRIGHT;
296 case ED_to_left: return AnimationEffect_MOVE_SHORT_TO_LEFT;
297 case ED_to_upperleft: return AnimationEffect_MOVE_SHORT_TO_UPPERLEFT;
298 case ED_to_top: return AnimationEffect_MOVE_SHORT_TO_TOP;
299 case ED_to_upperright: return AnimationEffect_MOVE_SHORT_TO_UPPERRIGHT;
300 case ED_to_right: return AnimationEffect_MOVE_SHORT_TO_RIGHT;
301 case ED_to_lowerright: return AnimationEffect_MOVE_SHORT_TO_LOWERRIGHT;
302 case ED_to_bottom: return AnimationEffect_MOVE_SHORT_TO_BOTTOM;
303 case ED_to_lowerleft: return AnimationEffect_MOVE_SHORT_TO_LOWERLEFT;
304 default: return AnimationEffect_MOVE_SHORT_FROM_LEFT;
306 case EK_checkerboard:
307 if( eDirection == ED_vertical )
308 return AnimationEffect_VERTICAL_CHECKERBOARD;
309 else
310 return AnimationEffect_HORIZONTAL_CHECKERBOARD;
311 case EK_rotate:
312 if( eDirection == ED_vertical )
313 return AnimationEffect_VERTICAL_ROTATE;
314 else
315 return AnimationEffect_HORIZONTAL_ROTATE;
316 case EK_stretch:
317 switch( eDirection )
319 case ED_from_left: return AnimationEffect_STRETCH_FROM_LEFT;
320 case ED_from_top: return AnimationEffect_STRETCH_FROM_TOP;
321 case ED_from_right: return AnimationEffect_STRETCH_FROM_RIGHT;
322 case ED_from_bottom: return AnimationEffect_STRETCH_FROM_BOTTOM;
323 case ED_from_upperleft: return AnimationEffect_STRETCH_FROM_UPPERLEFT;
324 case ED_from_upperright: return AnimationEffect_STRETCH_FROM_UPPERRIGHT;
325 case ED_from_lowerleft: return AnimationEffect_STRETCH_FROM_LOWERLEFT;
326 case ED_from_lowerright: return AnimationEffect_STRETCH_FROM_LOWERRIGHT;
327 case ED_vertical: return AnimationEffect_VERTICAL_STRETCH;
328 case ED_horizontal: return AnimationEffect_HORIZONTAL_STRETCH;
329 default:
330 break;
332 return AnimationEffect_STRETCH_FROM_LEFT;
333 default:
334 return AnimationEffect_NONE;
338 ///////////////////////////////////////////////////////////////////////
340 class AnimImpImpl
342 public:
343 Reference< XPropertySet > mxLastShape;
344 OUString maLastShapeId;
346 OUString msDimColor;
347 OUString msDimHide;
348 OUString msDimPrev;
349 OUString msEffect;
350 OUString msPlayFull;
351 OUString msPresOrder;
352 OUString msSound;
353 OUString msSoundOn;
354 OUString msSpeed;
355 OUString msTextEffect;
356 OUString msPresShapeService;
357 OUString msAnimPath;
358 OUString msIsAnimation;
360 AnimImpImpl()
361 : msDimColor( RTL_CONSTASCII_USTRINGPARAM( "DimColor" ) ),
362 msDimHide( RTL_CONSTASCII_USTRINGPARAM( "DimHide" ) ),
363 msDimPrev( RTL_CONSTASCII_USTRINGPARAM( "DimPrevious" ) ),
364 msEffect( RTL_CONSTASCII_USTRINGPARAM( "Effect" ) ),
365 msPlayFull( RTL_CONSTASCII_USTRINGPARAM( "PlayFull" ) ),
366 msPresOrder( RTL_CONSTASCII_USTRINGPARAM( "PresentationOrder" ) ),
367 msSound( RTL_CONSTASCII_USTRINGPARAM( "Sound" ) ),
368 msSoundOn( RTL_CONSTASCII_USTRINGPARAM( "SoundOn" ) ),
369 msSpeed( RTL_CONSTASCII_USTRINGPARAM( "Speed" ) ),
370 msTextEffect( RTL_CONSTASCII_USTRINGPARAM( "TextEffect" ) ),
371 msPresShapeService( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.presentation.Shape" ) ),
372 msAnimPath( RTL_CONSTASCII_USTRINGPARAM( "AnimationPath" ) ),
373 msIsAnimation( RTL_CONSTASCII_USTRINGPARAM( "IsAnimation" ) )
377 ///////////////////////////////////////////////////////////////////////
379 enum XMLActionKind
381 XMLE_SHOW,
382 XMLE_HIDE,
383 XMLE_DIM,
384 XMLE_PLAY
387 class XMLAnimationsEffectContext : public SvXMLImportContext
389 public:
390 AnimImpImpl* mpImpl;
392 XMLActionKind meKind;
393 sal_Bool mbTextEffect;
394 OUString maShapeId;
396 XMLEffect meEffect;
397 XMLEffectDirection meDirection;
398 sal_Int16 mnStartScale;
400 AnimationSpeed meSpeed;
401 Color maDimColor;
402 OUString maSoundURL;
403 sal_Bool mbPlayFull;
404 OUString maPathShapeId;
406 public:
407 TYPEINFO();
409 XMLAnimationsEffectContext( SvXMLImport& rImport,
410 sal_uInt16 nPrfx,
411 const OUString& rLocalName,
412 const Reference< XAttributeList >& xAttrList,
413 AnimImpImpl* pImpl);
414 virtual ~XMLAnimationsEffectContext();
416 virtual void EndElement();
418 virtual SvXMLImportContext * CreateChildContext( USHORT nPrefix, const OUString& rLocalName,
419 const Reference< XAttributeList >& xAttrList );
422 class XMLAnimationsSoundContext : public SvXMLImportContext
424 XMLAnimationsEffectContext* mpParent;
426 public:
427 TYPEINFO();
429 XMLAnimationsSoundContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLocalName, const Reference< XAttributeList >& xAttrList, XMLAnimationsEffectContext* pParent );
430 virtual ~XMLAnimationsSoundContext();
433 TYPEINIT1( XMLAnimationsSoundContext, SvXMLImportContext );
435 XMLAnimationsSoundContext::XMLAnimationsSoundContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLocalName, const Reference< XAttributeList >& xAttrList, XMLAnimationsEffectContext* pParent )
436 : SvXMLImportContext( rImport, nPrfx, rLocalName ), mpParent( pParent )
438 if( mpParent && nPrfx == XML_NAMESPACE_PRESENTATION && IsXMLToken( rLocalName, XML_SOUND ) )
440 const sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
441 for(sal_Int16 i=0; i < nAttrCount; i++)
443 OUString sAttrName = xAttrList->getNameByIndex( i );
444 OUString aLocalName;
445 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
446 OUString sValue = xAttrList->getValueByIndex( i );
448 switch( nPrefix )
450 case XML_NAMESPACE_XLINK:
451 if( IsXMLToken( aLocalName, XML_HREF ) )
453 mpParent->maSoundURL = rImport.GetAbsoluteReference(sValue);
455 break;
456 case XML_NAMESPACE_PRESENTATION:
457 if( IsXMLToken( aLocalName, XML_PLAY_FULL ) )
459 mpParent->mbPlayFull = IsXMLToken( sValue, XML_TRUE );
466 XMLAnimationsSoundContext::~XMLAnimationsSoundContext()
471 TYPEINIT1( XMLAnimationsEffectContext, SvXMLImportContext );
473 XMLAnimationsEffectContext::XMLAnimationsEffectContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLocalName, const Reference< XAttributeList >& xAttrList, AnimImpImpl* pImpl )
474 : SvXMLImportContext(rImport, nPrfx, rLocalName),
475 mpImpl( pImpl ),
476 meKind( XMLE_SHOW ), mbTextEffect( sal_False ),
477 meEffect( EK_none ), meDirection( ED_none ), mnStartScale( 100 ),
478 meSpeed( AnimationSpeed_MEDIUM ), maDimColor(0), mbPlayFull( sal_False )
480 if( IsXMLToken( rLocalName, XML_SHOW_SHAPE ) )
482 meKind = XMLE_SHOW;
484 else if( IsXMLToken( rLocalName, XML_SHOW_TEXT ) )
486 meKind = XMLE_SHOW;
487 mbTextEffect = sal_True;
489 else if( IsXMLToken( rLocalName, XML_HIDE_SHAPE ) )
491 meKind = XMLE_HIDE;
493 else if( IsXMLToken( rLocalName, XML_HIDE_TEXT ) )
495 meKind = XMLE_HIDE;
496 mbTextEffect = sal_True;
498 else if( IsXMLToken( rLocalName, XML_DIM ) )
500 meKind = XMLE_DIM;
502 else if( IsXMLToken( rLocalName, XML_PLAY ) )
504 meKind = XMLE_PLAY;
506 else
508 // unknown action, overread
509 return;
512 // read attributes
513 const sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
514 for(sal_Int16 i=0; i < nAttrCount; i++)
516 OUString sAttrName = xAttrList->getNameByIndex( i );
517 OUString aLocalName;
518 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
519 OUString sValue = xAttrList->getValueByIndex( i );
521 switch( nPrefix )
523 case XML_NAMESPACE_DRAW:
524 if( IsXMLToken( aLocalName, XML_SHAPE_ID ) )
526 maShapeId = sValue;
528 else if( IsXMLToken( aLocalName, XML_COLOR ) )
530 SvXMLUnitConverter::convertColor(maDimColor, sValue);
532 break;
534 case XML_NAMESPACE_PRESENTATION:
535 if( IsXMLToken( aLocalName, XML_EFFECT ) )
537 USHORT eEnum;
538 if( SvXMLUnitConverter::convertEnum( eEnum, sValue, aXML_AnimationEffect_EnumMap ) )
539 meEffect = (XMLEffect)eEnum;
541 else if( IsXMLToken(aLocalName, XML_DIRECTION ) )
543 USHORT eEnum;
544 if( SvXMLUnitConverter::convertEnum( eEnum, sValue, aXML_AnimationDirection_EnumMap ) )
545 meDirection = (XMLEffectDirection)eEnum;
547 else if( IsXMLToken( aLocalName, XML_START_SCALE ) )
549 sal_Int32 nScale;
550 if( SvXMLUnitConverter::convertPercent( nScale, sValue ) )
551 mnStartScale = (sal_Int16)nScale;
553 else if( IsXMLToken( aLocalName, XML_SPEED ) )
555 USHORT eEnum;
556 if( SvXMLUnitConverter::convertEnum( eEnum, sValue, aXML_AnimationSpeed_EnumMap ) )
557 meSpeed = (AnimationSpeed)eEnum;
559 else if( IsXMLToken( aLocalName, XML_PATH_ID ) )
561 maPathShapeId = sValue;
563 break;
568 XMLAnimationsEffectContext::~XMLAnimationsEffectContext()
572 SvXMLImportContext * XMLAnimationsEffectContext::CreateChildContext( USHORT nPrefix, const OUString& rLocalName, const Reference< XAttributeList>& xAttrList )
574 return new XMLAnimationsSoundContext( GetImport(), nPrefix, rLocalName, xAttrList, this );
577 void XMLAnimationsEffectContext::EndElement()
579 // set effect on shape
583 UniReference< XMLShapeImportHelper > xShapeImport( GetImport().GetShapeImport() );
584 Any aAny;
586 if( maShapeId.getLength() )
588 Reference< XPropertySet > xSet;
589 if( mpImpl->maLastShapeId != maShapeId )
591 xSet = Reference< XPropertySet >::query( GetImport().getInterfaceToIdentifierMapper().getReference( maShapeId ) );
592 if( xSet.is() )
594 // check for presentation shape service
596 Reference< XServiceInfo > xServiceInfo( xSet, UNO_QUERY );
597 if( !xServiceInfo.is() || !xServiceInfo->supportsService( mpImpl->msPresShapeService ) )
598 return;
601 mpImpl->maLastShapeId = maShapeId;
602 mpImpl->mxLastShape = xSet;
605 else
607 xSet = mpImpl->mxLastShape;
610 if( xSet.is() )
612 if( meKind == XMLE_DIM )
614 aAny <<= (sal_Bool)sal_True;
615 xSet->setPropertyValue( mpImpl->msDimPrev, aAny );
617 aAny <<= (sal_Int32)maDimColor.GetColor();
618 xSet->setPropertyValue( mpImpl->msDimColor, aAny );
620 else if( meKind == XMLE_PLAY )
622 aAny <<= (sal_Bool)sal_True;
623 xSet->setPropertyValue( mpImpl->msIsAnimation, aAny );
625 aAny <<= meSpeed;
626 xSet->setPropertyValue( mpImpl->msSpeed, aAny );
628 else
630 if( meKind == XMLE_HIDE && !mbTextEffect && meEffect == EK_none )
632 aAny = bool2any( sal_True );
633 xSet->setPropertyValue( mpImpl->msDimHide, aAny );
635 else
637 const AnimationEffect eEffect = ImplSdXMLgetEffect( meEffect, meDirection, mnStartScale, meKind == XMLE_SHOW );
639 xSet->setPropertyValue( mbTextEffect ? mpImpl->msTextEffect : mpImpl->msEffect, makeAny( eEffect ) );
640 xSet->setPropertyValue( mpImpl->msSpeed, makeAny( meSpeed ) );
642 if( eEffect == AnimationEffect_PATH && maPathShapeId.getLength() )
644 Reference< XShape > xPath( GetImport().getInterfaceToIdentifierMapper().getReference( maPathShapeId ), UNO_QUERY );
645 if( xPath.is() )
646 xSet->setPropertyValue( mpImpl->msAnimPath, makeAny( xPath ) );
651 if( maSoundURL.getLength() != 0 )
653 if( xSet.is() )
655 aAny <<= maSoundURL;
656 xSet->setPropertyValue( mpImpl->msSound, aAny );
658 aAny <<= bool2any( mbPlayFull );
659 xSet->setPropertyValue( mpImpl->msPlayFull, aAny );
661 aAny <<= bool2any( sal_True );
662 xSet->setPropertyValue( mpImpl->msSoundOn, aAny );
664 else
666 DBG_ERROR("XMLAnimationsEffectContext::EndElement - Sound URL without a XPropertySet!");
671 catch( Exception e )
673 DBG_ERROR( "exception catched while importing animation information!" );
677 ///////////////////////////////////////////////////////////////////////
679 TYPEINIT1( XMLAnimationsContext, SvXMLImportContext );
681 XMLAnimationsContext::XMLAnimationsContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const rtl::OUString& rLocalName,
682 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& )
683 : SvXMLImportContext(rImport, nPrfx, rLocalName)
685 mpImpl = new AnimImpImpl();
688 XMLAnimationsContext::~XMLAnimationsContext()
690 delete mpImpl;
693 SvXMLImportContext * XMLAnimationsContext::CreateChildContext( USHORT nPrefix, const ::rtl::OUString& rLocalName,
694 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList )
696 return new XMLAnimationsEffectContext( GetImport(), nPrefix, rLocalName, xAttrList, mpImpl );