xref: /trunk/main/oox/source/ppt/animationspersist.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #include "oox/ppt/animationspersist.hxx"
29*cdf0e10cSrcweir 
30*cdf0e10cSrcweir #include <rtl/ustring.hxx>
31*cdf0e10cSrcweir #include <com/sun/star/uno/Any.hxx>
32*cdf0e10cSrcweir #include <com/sun/star/drawing/XShape.hpp>
33*cdf0e10cSrcweir #include <com/sun/star/text/XText.hpp>
34*cdf0e10cSrcweir #include <com/sun/star/presentation/ParagraphTarget.hpp>
35*cdf0e10cSrcweir #include <com/sun/star/presentation/ShapeAnimationSubType.hpp>
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir #include "oox/drawingml/shape.hxx"
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir using rtl::OUString;
40*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
41*cdf0e10cSrcweir using namespace ::com::sun::star::presentation;
42*cdf0e10cSrcweir using namespace ::com::sun::star::drawing;
43*cdf0e10cSrcweir using namespace ::com::sun::star::text;
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir namespace oox { namespace ppt {
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir     void ShapeTargetElement::convert( ::com::sun::star::uno::Any & rTarget, sal_Int16 & rSubType ) const
48*cdf0e10cSrcweir     {
49*cdf0e10cSrcweir         switch(mnType)
50*cdf0e10cSrcweir         {
51*cdf0e10cSrcweir         case XML_subSp:
52*cdf0e10cSrcweir             rSubType = ShapeAnimationSubType::AS_WHOLE;
53*cdf0e10cSrcweir             break;
54*cdf0e10cSrcweir         case XML_bg:
55*cdf0e10cSrcweir             rSubType = ShapeAnimationSubType::ONLY_BACKGROUND;
56*cdf0e10cSrcweir             break;
57*cdf0e10cSrcweir         case XML_txEl:
58*cdf0e10cSrcweir         {
59*cdf0e10cSrcweir             ParagraphTarget aParaTarget;
60*cdf0e10cSrcweir             Reference< XShape > xShape;
61*cdf0e10cSrcweir             rTarget >>= xShape;
62*cdf0e10cSrcweir             aParaTarget.Shape = xShape;
63*cdf0e10cSrcweir             rSubType = ShapeAnimationSubType::ONLY_TEXT;
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir             Reference< XText > xText( xShape, UNO_QUERY );
66*cdf0e10cSrcweir             if( xText.is() )
67*cdf0e10cSrcweir             {
68*cdf0e10cSrcweir                 switch(mnRangeType)
69*cdf0e10cSrcweir                 {
70*cdf0e10cSrcweir                 case XML_charRg:
71*cdf0e10cSrcweir                     // TODO calculate the corresponding paragraph for the text range....
72*cdf0e10cSrcweir                     OSL_TRACE( "OOX: TODO calculate the corresponding paragraph for the text range..." );
73*cdf0e10cSrcweir                     break;
74*cdf0e10cSrcweir                 case XML_pRg:
75*cdf0e10cSrcweir                     aParaTarget.Paragraph = static_cast< sal_Int16 >( maRange.start );
76*cdf0e10cSrcweir                     // TODO what to do with more than one.
77*cdf0e10cSrcweir                     OSL_TRACE( "OOX: TODO what to do with more than one" );
78*cdf0e10cSrcweir                     break;
79*cdf0e10cSrcweir                 }
80*cdf0e10cSrcweir                 rTarget = makeAny( aParaTarget );
81*cdf0e10cSrcweir             }
82*cdf0e10cSrcweir             break;
83*cdf0e10cSrcweir         }
84*cdf0e10cSrcweir         default:
85*cdf0e10cSrcweir             break;
86*cdf0e10cSrcweir         }
87*cdf0e10cSrcweir     }
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir 
90*cdf0e10cSrcweir     Any AnimTargetElement::convert(const SlidePersistPtr & pSlide, sal_Int16 & nSubType) const
91*cdf0e10cSrcweir     {
92*cdf0e10cSrcweir         Any aTarget;
93*cdf0e10cSrcweir         // see sd/source/files/ppt/pptinanimations.cxx:3191 (in importTargetElementContainer())
94*cdf0e10cSrcweir         switch(mnType)
95*cdf0e10cSrcweir         {
96*cdf0e10cSrcweir         case XML_inkTgt:
97*cdf0e10cSrcweir             // TODO
98*cdf0e10cSrcweir             OSL_TRACE( "OOX: TODO inkTgt" );
99*cdf0e10cSrcweir             break;
100*cdf0e10cSrcweir         case XML_sldTgt:
101*cdf0e10cSrcweir             // TODO
102*cdf0e10cSrcweir             OSL_TRACE( "OOX: TODO sldTgt" );
103*cdf0e10cSrcweir             break;
104*cdf0e10cSrcweir         case XML_sndTgt:
105*cdf0e10cSrcweir             aTarget = makeAny(msValue);
106*cdf0e10cSrcweir             break;
107*cdf0e10cSrcweir         case XML_spTgt:
108*cdf0e10cSrcweir         {
109*cdf0e10cSrcweir             Any rTarget;
110*cdf0e10cSrcweir             ::oox::drawingml::ShapePtr pShape = pSlide->getShape(msValue);
111*cdf0e10cSrcweir             OSL_ENSURE( pShape, "failed to locate Shape");
112*cdf0e10cSrcweir             if( pShape )
113*cdf0e10cSrcweir             {
114*cdf0e10cSrcweir                 Reference< XShape > xShape( pShape->getXShape() );
115*cdf0e10cSrcweir                 OSL_ENSURE( xShape.is(), "fail to get XShape from shape" );
116*cdf0e10cSrcweir                 if( xShape.is() )
117*cdf0e10cSrcweir                 {
118*cdf0e10cSrcweir                     rTarget <<= xShape;
119*cdf0e10cSrcweir                     maShapeTarget.convert(rTarget, nSubType);
120*cdf0e10cSrcweir                     aTarget = rTarget;
121*cdf0e10cSrcweir                 }
122*cdf0e10cSrcweir             }
123*cdf0e10cSrcweir             break;
124*cdf0e10cSrcweir         }
125*cdf0e10cSrcweir         default:
126*cdf0e10cSrcweir             break;
127*cdf0e10cSrcweir         }
128*cdf0e10cSrcweir         return aTarget;
129*cdf0e10cSrcweir     }
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir // BEGIN CUT&PASTE from sd/source/filter/ppt/pptinanimations.cxx
133*cdf0e10cSrcweir /** this adds an any to another any.
134*cdf0e10cSrcweir     if rNewValue is empty, rOldValue is returned.
135*cdf0e10cSrcweir     if rOldValue is empty, rNewValue is returned.
136*cdf0e10cSrcweir     if rOldValue contains a value, a sequence with rOldValue and rNewValue is returned.
137*cdf0e10cSrcweir     if rOldValue contains a sequence, a new sequence with the old sequence and rNewValue is returned.
138*cdf0e10cSrcweir */
139*cdf0e10cSrcweir     static Any addToSequence( const Any& rOldValue, const Any& rNewValue )
140*cdf0e10cSrcweir     {
141*cdf0e10cSrcweir         if( !rNewValue.hasValue() )
142*cdf0e10cSrcweir         {
143*cdf0e10cSrcweir             return rOldValue;
144*cdf0e10cSrcweir         }
145*cdf0e10cSrcweir         else if( !rOldValue.hasValue() )
146*cdf0e10cSrcweir         {
147*cdf0e10cSrcweir             return rNewValue;
148*cdf0e10cSrcweir         }
149*cdf0e10cSrcweir         else
150*cdf0e10cSrcweir         {
151*cdf0e10cSrcweir             Sequence< Any > aNewSeq;
152*cdf0e10cSrcweir             if( rOldValue >>= aNewSeq )
153*cdf0e10cSrcweir             {
154*cdf0e10cSrcweir                 sal_Int32 nSize = aNewSeq.getLength();
155*cdf0e10cSrcweir                 aNewSeq.realloc(nSize+1);
156*cdf0e10cSrcweir                 aNewSeq[nSize] = rNewValue;
157*cdf0e10cSrcweir             }
158*cdf0e10cSrcweir             else
159*cdf0e10cSrcweir             {
160*cdf0e10cSrcweir                 aNewSeq.realloc(2);
161*cdf0e10cSrcweir                 aNewSeq[0] = rOldValue;
162*cdf0e10cSrcweir                 aNewSeq[1] = rNewValue;
163*cdf0e10cSrcweir             }
164*cdf0e10cSrcweir             return makeAny( aNewSeq );
165*cdf0e10cSrcweir         }
166*cdf0e10cSrcweir     }
167*cdf0e10cSrcweir // END
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir     Any AnimationCondition::convert(const SlidePersistPtr & pSlide) const
170*cdf0e10cSrcweir     {
171*cdf0e10cSrcweir         Any aAny;
172*cdf0e10cSrcweir         if( mpTarget )
173*cdf0e10cSrcweir         {
174*cdf0e10cSrcweir             sal_Int16 nSubType;
175*cdf0e10cSrcweir             aAny = mpTarget->convert( pSlide, nSubType );
176*cdf0e10cSrcweir         }
177*cdf0e10cSrcweir         else
178*cdf0e10cSrcweir         {
179*cdf0e10cSrcweir             aAny = maValue;
180*cdf0e10cSrcweir         }
181*cdf0e10cSrcweir         return aAny;
182*cdf0e10cSrcweir     }
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir     Any AnimationCondition::convertList(const SlidePersistPtr & pSlide, const AnimationConditionList & l)
186*cdf0e10cSrcweir     {
187*cdf0e10cSrcweir         Any aAny;
188*cdf0e10cSrcweir         for( AnimationConditionList::const_iterator iter = l.begin();
189*cdf0e10cSrcweir              iter != l.end(); iter++)
190*cdf0e10cSrcweir         {
191*cdf0e10cSrcweir             aAny = addToSequence( aAny, iter->convert(pSlide) );
192*cdf0e10cSrcweir         }
193*cdf0e10cSrcweir         return aAny;
194*cdf0e10cSrcweir     }
195*cdf0e10cSrcweir 
196*cdf0e10cSrcweir } }
197*cdf0e10cSrcweir 
198*cdf0e10cSrcweir 
199