Update ooo320-m1
[ooovba.git] / oox / source / ppt / animationspersist.cxx
blob77f1d79e8922ca320370f7bc550455abcce2003e
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: animationspersist.cxx,v $
10 * $Revision: 1.3 $
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 ************************************************************************/
33 #include "oox/ppt/animationspersist.hxx"
35 #include <rtl/ustring.hxx>
36 #include <com/sun/star/uno/Any.hxx>
37 #include <com/sun/star/drawing/XShape.hpp>
38 #include <com/sun/star/text/XText.hpp>
39 #include <com/sun/star/presentation/ParagraphTarget.hpp>
40 #include <com/sun/star/presentation/ShapeAnimationSubType.hpp>
42 #include "oox/drawingml/shape.hxx"
44 #include "tokens.hxx"
46 using rtl::OUString;
47 using namespace ::com::sun::star::uno;
48 using namespace ::com::sun::star::presentation;
49 using namespace ::com::sun::star::drawing;
50 using namespace ::com::sun::star::text;
52 namespace oox { namespace ppt {
54 void ShapeTargetElement::convert( ::com::sun::star::uno::Any & rTarget, sal_Int16 & rSubType ) const
56 switch(mnType)
58 case XML_subSp:
59 rSubType = ShapeAnimationSubType::AS_WHOLE;
60 break;
61 case XML_bg:
62 rSubType = ShapeAnimationSubType::ONLY_BACKGROUND;
63 break;
64 case XML_txEl:
66 ParagraphTarget aParaTarget;
67 Reference< XShape > xShape;
68 rTarget >>= xShape;
69 aParaTarget.Shape = xShape;
70 rSubType = ShapeAnimationSubType::ONLY_TEXT;
72 Reference< XText > xText( xShape, UNO_QUERY );
73 if( xText.is() )
75 switch(mnRangeType)
77 case XML_charRg:
78 // TODO calculate the corresponding paragraph for the text range....
79 OSL_TRACE( "OOX: TODO calculate the corresponding paragraph for the text range..." );
80 break;
81 case XML_pRg:
82 aParaTarget.Paragraph = static_cast< sal_Int16 >( maRange.start );
83 // TODO what to do with more than one.
84 OSL_TRACE( "OOX: TODO what to do with more than one" );
85 break;
87 rTarget = makeAny( aParaTarget );
89 break;
91 default:
92 break;
97 Any AnimTargetElement::convert(const SlidePersistPtr & pSlide, sal_Int16 & nSubType) const
99 Any aTarget;
100 // see sd/source/files/ppt/pptinanimations.cxx:3191 (in importTargetElementContainer())
101 switch(mnType)
103 case XML_inkTgt:
104 // TODO
105 OSL_TRACE( "OOX: TODO inkTgt" );
106 break;
107 case XML_sldTgt:
108 // TODO
109 OSL_TRACE( "OOX: TODO sldTgt" );
110 break;
111 case XML_sndTgt:
112 aTarget = makeAny(msValue);
113 break;
114 case XML_spTgt:
116 Any rTarget;
117 ::oox::drawingml::ShapePtr pShape = pSlide->getShape(msValue);
118 OSL_ENSURE( pShape, "failed to locate Shape");
119 if( pShape )
121 Reference< XShape > xShape( pShape->getXShape() );
122 OSL_ENSURE( xShape.is(), "fail to get XShape from shape" );
123 if( xShape.is() )
125 rTarget <<= xShape;
126 maShapeTarget.convert(rTarget, nSubType);
127 aTarget = rTarget;
130 break;
132 default:
133 break;
135 return aTarget;
139 // BEGIN CUT&PASTE from sd/source/filter/ppt/pptinanimations.cxx
140 /** this adds an any to another any.
141 if rNewValue is empty, rOldValue is returned.
142 if rOldValue is empty, rNewValue is returned.
143 if rOldValue contains a value, a sequence with rOldValue and rNewValue is returned.
144 if rOldValue contains a sequence, a new sequence with the old sequence and rNewValue is returned.
146 static Any addToSequence( const Any& rOldValue, const Any& rNewValue )
148 if( !rNewValue.hasValue() )
150 return rOldValue;
152 else if( !rOldValue.hasValue() )
154 return rNewValue;
156 else
158 Sequence< Any > aNewSeq;
159 if( rOldValue >>= aNewSeq )
161 sal_Int32 nSize = aNewSeq.getLength();
162 aNewSeq.realloc(nSize+1);
163 aNewSeq[nSize] = rNewValue;
165 else
167 aNewSeq.realloc(2);
168 aNewSeq[0] = rOldValue;
169 aNewSeq[1] = rNewValue;
171 return makeAny( aNewSeq );
174 // END
176 Any AnimationCondition::convert(const SlidePersistPtr & pSlide) const
178 Any aAny;
179 if( mpTarget )
181 sal_Int16 nSubType;
182 aAny = mpTarget->convert( pSlide, nSubType );
184 else
186 aAny = maValue;
188 return aAny;
192 Any AnimationCondition::convertList(const SlidePersistPtr & pSlide, const AnimationConditionList & l)
194 Any aAny;
195 for( AnimationConditionList::const_iterator iter = l.begin();
196 iter != l.end(); iter++)
198 aAny = addToSequence( aAny, iter->convert(pSlide) );
200 return aAny;