xref: /trunk/main/oox/source/ppt/animationspersist.cxx (revision cf6516809c57e1bb0a940545cca99cdad54d4ce2)
1*ca5ec200SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*ca5ec200SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*ca5ec200SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*ca5ec200SAndrew Rist  * distributed with this work for additional information
6*ca5ec200SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*ca5ec200SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*ca5ec200SAndrew Rist  * "License"); you may not use this file except in compliance
9*ca5ec200SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*ca5ec200SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*ca5ec200SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*ca5ec200SAndrew Rist  * software distributed under the License is distributed on an
15*ca5ec200SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ca5ec200SAndrew Rist  * KIND, either express or implied.  See the License for the
17*ca5ec200SAndrew Rist  * specific language governing permissions and limitations
18*ca5ec200SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*ca5ec200SAndrew Rist  *************************************************************/
21*ca5ec200SAndrew Rist 
22*ca5ec200SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "oox/ppt/animationspersist.hxx"
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include <rtl/ustring.hxx>
27cdf0e10cSrcweir #include <com/sun/star/uno/Any.hxx>
28cdf0e10cSrcweir #include <com/sun/star/drawing/XShape.hpp>
29cdf0e10cSrcweir #include <com/sun/star/text/XText.hpp>
30cdf0e10cSrcweir #include <com/sun/star/presentation/ParagraphTarget.hpp>
31cdf0e10cSrcweir #include <com/sun/star/presentation/ShapeAnimationSubType.hpp>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #include "oox/drawingml/shape.hxx"
34cdf0e10cSrcweir 
35cdf0e10cSrcweir using rtl::OUString;
36cdf0e10cSrcweir using namespace ::com::sun::star::uno;
37cdf0e10cSrcweir using namespace ::com::sun::star::presentation;
38cdf0e10cSrcweir using namespace ::com::sun::star::drawing;
39cdf0e10cSrcweir using namespace ::com::sun::star::text;
40cdf0e10cSrcweir 
41cdf0e10cSrcweir namespace oox { namespace ppt {
42cdf0e10cSrcweir 
convert(::com::sun::star::uno::Any & rTarget,sal_Int16 & rSubType) const43cdf0e10cSrcweir     void ShapeTargetElement::convert( ::com::sun::star::uno::Any & rTarget, sal_Int16 & rSubType ) const
44cdf0e10cSrcweir     {
45cdf0e10cSrcweir         switch(mnType)
46cdf0e10cSrcweir         {
47cdf0e10cSrcweir         case XML_subSp:
48cdf0e10cSrcweir             rSubType = ShapeAnimationSubType::AS_WHOLE;
49cdf0e10cSrcweir             break;
50cdf0e10cSrcweir         case XML_bg:
51cdf0e10cSrcweir             rSubType = ShapeAnimationSubType::ONLY_BACKGROUND;
52cdf0e10cSrcweir             break;
53cdf0e10cSrcweir         case XML_txEl:
54cdf0e10cSrcweir         {
55cdf0e10cSrcweir             ParagraphTarget aParaTarget;
56cdf0e10cSrcweir             Reference< XShape > xShape;
57cdf0e10cSrcweir             rTarget >>= xShape;
58cdf0e10cSrcweir             aParaTarget.Shape = xShape;
59cdf0e10cSrcweir             rSubType = ShapeAnimationSubType::ONLY_TEXT;
60cdf0e10cSrcweir 
61cdf0e10cSrcweir             Reference< XText > xText( xShape, UNO_QUERY );
62cdf0e10cSrcweir             if( xText.is() )
63cdf0e10cSrcweir             {
64cdf0e10cSrcweir                 switch(mnRangeType)
65cdf0e10cSrcweir                 {
66cdf0e10cSrcweir                 case XML_charRg:
67cdf0e10cSrcweir                     // TODO calculate the corresponding paragraph for the text range....
68cdf0e10cSrcweir                     OSL_TRACE( "OOX: TODO calculate the corresponding paragraph for the text range..." );
69cdf0e10cSrcweir                     break;
70cdf0e10cSrcweir                 case XML_pRg:
71cdf0e10cSrcweir                     aParaTarget.Paragraph = static_cast< sal_Int16 >( maRange.start );
72cdf0e10cSrcweir                     // TODO what to do with more than one.
73cdf0e10cSrcweir                     OSL_TRACE( "OOX: TODO what to do with more than one" );
74cdf0e10cSrcweir                     break;
75cdf0e10cSrcweir                 }
76cdf0e10cSrcweir                 rTarget = makeAny( aParaTarget );
77cdf0e10cSrcweir             }
78cdf0e10cSrcweir             break;
79cdf0e10cSrcweir         }
80cdf0e10cSrcweir         default:
81cdf0e10cSrcweir             break;
82cdf0e10cSrcweir         }
83cdf0e10cSrcweir     }
84cdf0e10cSrcweir 
85cdf0e10cSrcweir 
convert(const SlidePersistPtr & pSlide,sal_Int16 & nSubType) const86cdf0e10cSrcweir     Any AnimTargetElement::convert(const SlidePersistPtr & pSlide, sal_Int16 & nSubType) const
87cdf0e10cSrcweir     {
88cdf0e10cSrcweir         Any aTarget;
89cdf0e10cSrcweir         // see sd/source/files/ppt/pptinanimations.cxx:3191 (in importTargetElementContainer())
90cdf0e10cSrcweir         switch(mnType)
91cdf0e10cSrcweir         {
92cdf0e10cSrcweir         case XML_inkTgt:
93cdf0e10cSrcweir             // TODO
94cdf0e10cSrcweir             OSL_TRACE( "OOX: TODO inkTgt" );
95cdf0e10cSrcweir             break;
96cdf0e10cSrcweir         case XML_sldTgt:
97cdf0e10cSrcweir             // TODO
98cdf0e10cSrcweir             OSL_TRACE( "OOX: TODO sldTgt" );
99cdf0e10cSrcweir             break;
100cdf0e10cSrcweir         case XML_sndTgt:
101cdf0e10cSrcweir             aTarget = makeAny(msValue);
102cdf0e10cSrcweir             break;
103cdf0e10cSrcweir         case XML_spTgt:
104cdf0e10cSrcweir         {
105cdf0e10cSrcweir             Any rTarget;
106cdf0e10cSrcweir             ::oox::drawingml::ShapePtr pShape = pSlide->getShape(msValue);
107cdf0e10cSrcweir             OSL_ENSURE( pShape, "failed to locate Shape");
108cdf0e10cSrcweir             if( pShape )
109cdf0e10cSrcweir             {
110cdf0e10cSrcweir                 Reference< XShape > xShape( pShape->getXShape() );
111cdf0e10cSrcweir                 OSL_ENSURE( xShape.is(), "fail to get XShape from shape" );
112cdf0e10cSrcweir                 if( xShape.is() )
113cdf0e10cSrcweir                 {
114cdf0e10cSrcweir                     rTarget <<= xShape;
115cdf0e10cSrcweir                     maShapeTarget.convert(rTarget, nSubType);
116cdf0e10cSrcweir                     aTarget = rTarget;
117cdf0e10cSrcweir                 }
118cdf0e10cSrcweir             }
119cdf0e10cSrcweir             break;
120cdf0e10cSrcweir         }
121cdf0e10cSrcweir         default:
122cdf0e10cSrcweir             break;
123cdf0e10cSrcweir         }
124cdf0e10cSrcweir         return aTarget;
125cdf0e10cSrcweir     }
126cdf0e10cSrcweir 
127cdf0e10cSrcweir 
128cdf0e10cSrcweir // BEGIN CUT&PASTE from sd/source/filter/ppt/pptinanimations.cxx
129cdf0e10cSrcweir /** this adds an any to another any.
130cdf0e10cSrcweir     if rNewValue is empty, rOldValue is returned.
131cdf0e10cSrcweir     if rOldValue is empty, rNewValue is returned.
132cdf0e10cSrcweir     if rOldValue contains a value, a sequence with rOldValue and rNewValue is returned.
133cdf0e10cSrcweir     if rOldValue contains a sequence, a new sequence with the old sequence and rNewValue is returned.
134cdf0e10cSrcweir */
addToSequence(const Any & rOldValue,const Any & rNewValue)135cdf0e10cSrcweir     static Any addToSequence( const Any& rOldValue, const Any& rNewValue )
136cdf0e10cSrcweir     {
137cdf0e10cSrcweir         if( !rNewValue.hasValue() )
138cdf0e10cSrcweir         {
139cdf0e10cSrcweir             return rOldValue;
140cdf0e10cSrcweir         }
141cdf0e10cSrcweir         else if( !rOldValue.hasValue() )
142cdf0e10cSrcweir         {
143cdf0e10cSrcweir             return rNewValue;
144cdf0e10cSrcweir         }
145cdf0e10cSrcweir         else
146cdf0e10cSrcweir         {
147cdf0e10cSrcweir             Sequence< Any > aNewSeq;
148cdf0e10cSrcweir             if( rOldValue >>= aNewSeq )
149cdf0e10cSrcweir             {
150cdf0e10cSrcweir                 sal_Int32 nSize = aNewSeq.getLength();
151cdf0e10cSrcweir                 aNewSeq.realloc(nSize+1);
152cdf0e10cSrcweir                 aNewSeq[nSize] = rNewValue;
153cdf0e10cSrcweir             }
154cdf0e10cSrcweir             else
155cdf0e10cSrcweir             {
156cdf0e10cSrcweir                 aNewSeq.realloc(2);
157cdf0e10cSrcweir                 aNewSeq[0] = rOldValue;
158cdf0e10cSrcweir                 aNewSeq[1] = rNewValue;
159cdf0e10cSrcweir             }
160cdf0e10cSrcweir             return makeAny( aNewSeq );
161cdf0e10cSrcweir         }
162cdf0e10cSrcweir     }
163cdf0e10cSrcweir // END
164cdf0e10cSrcweir 
convert(const SlidePersistPtr & pSlide) const165cdf0e10cSrcweir     Any AnimationCondition::convert(const SlidePersistPtr & pSlide) const
166cdf0e10cSrcweir     {
167cdf0e10cSrcweir         Any aAny;
168cdf0e10cSrcweir         if( mpTarget )
169cdf0e10cSrcweir         {
170cdf0e10cSrcweir             sal_Int16 nSubType;
171cdf0e10cSrcweir             aAny = mpTarget->convert( pSlide, nSubType );
172cdf0e10cSrcweir         }
173cdf0e10cSrcweir         else
174cdf0e10cSrcweir         {
175cdf0e10cSrcweir             aAny = maValue;
176cdf0e10cSrcweir         }
177cdf0e10cSrcweir         return aAny;
178cdf0e10cSrcweir     }
179cdf0e10cSrcweir 
180cdf0e10cSrcweir 
convertList(const SlidePersistPtr & pSlide,const AnimationConditionList & l)181cdf0e10cSrcweir     Any AnimationCondition::convertList(const SlidePersistPtr & pSlide, const AnimationConditionList & l)
182cdf0e10cSrcweir     {
183cdf0e10cSrcweir         Any aAny;
184cdf0e10cSrcweir         for( AnimationConditionList::const_iterator iter = l.begin();
185cdf0e10cSrcweir              iter != l.end(); iter++)
186cdf0e10cSrcweir         {
187cdf0e10cSrcweir             aAny = addToSequence( aAny, iter->convert(pSlide) );
188cdf0e10cSrcweir         }
189cdf0e10cSrcweir         return aAny;
190cdf0e10cSrcweir     }
191cdf0e10cSrcweir 
192cdf0e10cSrcweir } }
193