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 #include "oox/ppt/animationspersist.hxx"
25 
26 #include <rtl/ustring.hxx>
27 #include <com/sun/star/uno/Any.hxx>
28 #include <com/sun/star/drawing/XShape.hpp>
29 #include <com/sun/star/text/XText.hpp>
30 #include <com/sun/star/presentation/ParagraphTarget.hpp>
31 #include <com/sun/star/presentation/ShapeAnimationSubType.hpp>
32 
33 #include "oox/drawingml/shape.hxx"
34 
35 using rtl::OUString;
36 using namespace ::com::sun::star::uno;
37 using namespace ::com::sun::star::presentation;
38 using namespace ::com::sun::star::drawing;
39 using namespace ::com::sun::star::text;
40 
41 namespace oox { namespace ppt {
42 
convert(::com::sun::star::uno::Any & rTarget,sal_Int16 & rSubType) const43 	void ShapeTargetElement::convert( ::com::sun::star::uno::Any & rTarget, sal_Int16 & rSubType ) const
44 	{
45 		switch(mnType)
46 		{
47 		case XML_subSp:
48 			rSubType = ShapeAnimationSubType::AS_WHOLE;
49 			break;
50 		case XML_bg:
51 			rSubType = ShapeAnimationSubType::ONLY_BACKGROUND;
52 			break;
53 		case XML_txEl:
54 		{
55 			ParagraphTarget aParaTarget;
56 			Reference< XShape > xShape;
57 			rTarget >>= xShape;
58 			aParaTarget.Shape = xShape;
59 			rSubType = ShapeAnimationSubType::ONLY_TEXT;
60 
61 			Reference< XText > xText( xShape, UNO_QUERY );
62 			if( xText.is() )
63 			{
64 				switch(mnRangeType)
65 				{
66 				case XML_charRg:
67 					// TODO calculate the corresponding paragraph for the text range....
68 					OSL_TRACE( "OOX: TODO calculate the corresponding paragraph for the text range..." );
69 					break;
70 				case XML_pRg:
71 					aParaTarget.Paragraph = static_cast< sal_Int16 >( maRange.start );
72 					// TODO what to do with more than one.
73 					OSL_TRACE( "OOX: TODO what to do with more than one" );
74 					break;
75 				}
76 				rTarget = makeAny( aParaTarget );
77 			}
78 			break;
79 		}
80 		default:
81 			break;
82 		}
83 	}
84 
85 
convert(const SlidePersistPtr & pSlide,sal_Int16 & nSubType) const86 	Any AnimTargetElement::convert(const SlidePersistPtr & pSlide, sal_Int16 & nSubType) const
87 	{
88 		Any aTarget;
89 		// see sd/source/files/ppt/pptinanimations.cxx:3191 (in importTargetElementContainer())
90 		switch(mnType)
91 		{
92 		case XML_inkTgt:
93 			// TODO
94 			OSL_TRACE( "OOX: TODO inkTgt" );
95 			break;
96 		case XML_sldTgt:
97 			// TODO
98 			OSL_TRACE( "OOX: TODO sldTgt" );
99 			break;
100 		case XML_sndTgt:
101 			aTarget = makeAny(msValue);
102 			break;
103 		case XML_spTgt:
104 		{
105 			Any rTarget;
106 			::oox::drawingml::ShapePtr pShape = pSlide->getShape(msValue);
107 			OSL_ENSURE( pShape, "failed to locate Shape");
108 			if( pShape )
109 			{
110 				Reference< XShape > xShape( pShape->getXShape() );
111 				OSL_ENSURE( xShape.is(), "fail to get XShape from shape" );
112 				if( xShape.is() )
113 				{
114 					rTarget <<= xShape;
115 					maShapeTarget.convert(rTarget, nSubType);
116 					aTarget = rTarget;
117 				}
118 			}
119 			break;
120 		}
121 		default:
122 			break;
123 		}
124 		return aTarget;
125 	}
126 
127 
128 // BEGIN CUT&PASTE from sd/source/filter/ppt/pptinanimations.cxx
129 /** this adds an any to another any.
130 	if rNewValue is empty, rOldValue is returned.
131 	if rOldValue is empty, rNewValue is returned.
132 	if rOldValue contains a value, a sequence with rOldValue and rNewValue is returned.
133 	if rOldValue contains a sequence, a new sequence with the old sequence and rNewValue is returned.
134 */
addToSequence(const Any & rOldValue,const Any & rNewValue)135 	static Any addToSequence( const Any& rOldValue, const Any& rNewValue )
136 	{
137 		if( !rNewValue.hasValue() )
138 		{
139 			return rOldValue;
140 		}
141 		else if( !rOldValue.hasValue() )
142 		{
143 			return rNewValue;
144 		}
145 		else
146 		{
147 			Sequence< Any > aNewSeq;
148 			if( rOldValue >>= aNewSeq )
149 			{
150 				sal_Int32 nSize = aNewSeq.getLength();
151 				aNewSeq.realloc(nSize+1);
152 				aNewSeq[nSize] = rNewValue;
153 			}
154 			else
155 			{
156 				aNewSeq.realloc(2);
157 				aNewSeq[0] = rOldValue;
158 				aNewSeq[1] = rNewValue;
159 			}
160 			return makeAny( aNewSeq );
161 		}
162 	}
163 // END
164 
convert(const SlidePersistPtr & pSlide) const165 	Any AnimationCondition::convert(const SlidePersistPtr & pSlide) const
166 	{
167 		Any aAny;
168 		if( mpTarget )
169 		{
170 			sal_Int16 nSubType;
171 			aAny = mpTarget->convert( pSlide, nSubType );
172 		}
173 		else
174 		{
175 			aAny = maValue;
176 		}
177 		return aAny;
178 	}
179 
180 
convertList(const SlidePersistPtr & pSlide,const AnimationConditionList & l)181 	Any AnimationCondition::convertList(const SlidePersistPtr & pSlide, const AnimationConditionList & l)
182 	{
183 		Any aAny;
184 		for( AnimationConditionList::const_iterator iter = l.begin();
185 			 iter != l.end(); iter++)
186 		{
187 			aAny = addToSequence( aAny, iter->convert(pSlide) );
188 		}
189 		return aAny;
190 	}
191 
192 } }
193 
194 
195