xref: /aoo41x/main/oox/source/ppt/slidetransition.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #include "oox/ppt/slidetransition.hxx"
29 
30 #include <com/sun/star/uno/Any.hxx>
31 #include <com/sun/star/beans/XPropertySet.hpp>
32 #include <com/sun/star/presentation/AnimationSpeed.hpp>
33 #include <com/sun/star/animations/TransitionType.hpp>
34 #include <com/sun/star/animations/TransitionSubType.hpp>
35 
36 #include "oox/helper/helper.hxx"
37 #include "oox/helper/propertymap.hxx"
38 #include "oox/token/namespaces.hxx"
39 #include "oox/token/tokens.hxx"
40 #include "pptfilterhelpers.hxx"
41 
42 using rtl::OUString;
43 using namespace ::com::sun::star::uno;
44 using namespace ::com::sun::star::beans;
45 using namespace ::com::sun::star::animations;
46 using namespace ::com::sun::star::presentation;
47 
48 namespace oox { namespace ppt {
49 
50 
51 	SlideTransition::SlideTransition()
52 		: mnTransitionType( 0 )
53 		, mnTransitionSubType( 0 )
54 		, mbTransitionDirectionNormal( true )
55 		, mnAnimationSpeed( AnimationSpeed_FAST )
56 		, mnFadeColor( 0 )
57 		, mbMode( true )
58 	{
59 
60 	}
61 
62 
63 	SlideTransition::SlideTransition(const OUString & sFilterName)
64 		: mnTransitionType( 0 )
65 		, mnTransitionSubType( 0 )
66 		, mbTransitionDirectionNormal( true )
67 		, mnAnimationSpeed( AnimationSpeed_FAST )
68 		, mnFadeColor( 0 )
69 		, mbMode( true )
70 	{
71 		const transition *p = transition::find( sFilterName );
72 		if( p )
73 		{
74 			mnTransitionType = p->mnType;
75 			mnTransitionSubType = p->mnSubType;
76 			mbTransitionDirectionNormal = p->mbDirection;
77 		}
78 	}
79 
80 
81     void SlideTransition::setSlideProperties( PropertyMap & aProps )
82 	{
83 		try
84 		{
85             aProps[ PROP_TransitionType ] <<= mnTransitionType;
86             aProps[ PROP_TransitionSubtype ] <<= mnTransitionSubType;
87             aProps[ PROP_TransitionDirection ] <<= mbTransitionDirectionNormal;
88             aProps[ PROP_Speed ] <<= mnAnimationSpeed;
89             aProps[ PROP_TransitionFadeColor ] <<= mnFadeColor;
90 		}
91 		catch( Exception& )
92 		{
93 			// should not happen
94 			OSL_ENSURE( false, "exception raised" );
95 		}
96 	}
97 
98 	void SlideTransition::setTransitionFilterProperties( const Reference< XTransitionFilter > & xFilter )
99 	{
100 		try
101 		{
102 			xFilter->setTransition( mnTransitionType );
103 			xFilter->setSubtype( mnTransitionSubType );
104 			xFilter->setDirection( mbTransitionDirectionNormal );
105 			xFilter->setFadeColor( mnFadeColor );
106 			xFilter->setMode( mbMode );
107 		}
108 		catch( Exception& )
109 		{
110 			// should not happen
111 			OSL_ENSURE( false, "exception raised" );
112 		}
113 	}
114 
115 
116 	void SlideTransition::setOoxTransitionSpeed( sal_Int32 nToken)
117 	{
118 		switch( nToken  )
119 		{
120 			/* In case you want to use time values in second,
121 			 * the speed values are located in the PPT97 importer
122 			 * sd/source/filter/ppt/ppt97animations.cxx:664
123 			 * (void Ppt97Animation::UpdateCacheData() const)
124 			 */
125 		case XML_fast:
126 			mnAnimationSpeed = AnimationSpeed_FAST;
127 			break;
128 		case XML_med:
129 			mnAnimationSpeed = AnimationSpeed_MEDIUM;
130 			break;
131 		case XML_slow:
132 			mnAnimationSpeed = AnimationSpeed_SLOW;
133 			break;
134 		default:
135 			// should not happen. just ignore
136 			break;
137 		}
138 	}
139 
140 
141 
142 	sal_Int16 SlideTransition::ooxToOdpEightDirections( ::sal_Int32 nOoxType )
143 	{
144     sal_Int16 nOdpDirection;
145 		nOdpDirection = ooxToOdpBorderDirections( nOoxType );
146 		if( nOdpDirection == 0 )
147 		{
148 			nOdpDirection = ooxToOdpCornerDirections( nOoxType );
149 		}
150 		return nOdpDirection;
151 	}
152 
153 
154 	sal_Int16 SlideTransition::ooxToOdpBorderDirections( ::sal_Int32 nOoxType )
155 	{
156     sal_Int16 nOdpDirection;
157 		switch( nOoxType )
158 		{
159 		case XML_d:
160 			nOdpDirection = TransitionSubType::FROMTOP;
161 			break;
162 		case XML_l:
163 			nOdpDirection = TransitionSubType::FROMLEFT;
164 			break;
165 		case XML_r:
166 			nOdpDirection = TransitionSubType::FROMRIGHT;
167 			break;
168 		case XML_u:
169 			nOdpDirection = TransitionSubType::FROMBOTTOM;
170 			break;
171 		default:
172 			nOdpDirection= 0;
173 			break;
174 		}
175 		return nOdpDirection;
176 	}
177 
178 	sal_Int16 SlideTransition::ooxToOdpSideDirections( ::sal_Int32 nOoxType )
179 	{
180     sal_Int16 nOdpDirection;
181 		switch( nOoxType )
182 		{
183 		case XML_d:
184 		case XML_u:
185 			nOdpDirection = TransitionSubType::TOPTOBOTTOM;
186 			break;
187 		case XML_l:
188 		case XML_r:
189 			nOdpDirection = TransitionSubType::LEFTTORIGHT;
190 			break;
191 		default:
192 			nOdpDirection= 0;
193 			break;
194 		}
195 		return nOdpDirection;
196 	}
197 
198 	sal_Bool SlideTransition::ooxToOdpSideDirectionsDirectionNormal( ::sal_Int32 nOoxType )
199 	{
200     sal_Bool nOdpDirection = true;
201 		switch( nOoxType )
202 		{
203 		case XML_u:
204 		case XML_l:
205 			nOdpDirection = false;
206 			break;
207 		}
208 		return nOdpDirection;
209 	}
210 
211 	sal_Int16 SlideTransition::ooxToOdpCornerDirections( ::sal_Int32 nOoxType )
212 	{
213     sal_Int16 nOdpDirection;
214 		switch( nOoxType )
215 		{
216 		case XML_lu:
217 			nOdpDirection = TransitionSubType::FROMBOTTOMRIGHT;
218 			break;
219 		case XML_ru:
220 			nOdpDirection = TransitionSubType::FROMBOTTOMLEFT;
221 			break;
222 		case XML_ld:
223 			nOdpDirection = TransitionSubType::FROMTOPRIGHT;
224 			break;
225 		case XML_rd:
226 			nOdpDirection = TransitionSubType::FROMTOPLEFT;
227 			break;
228 		default:
229 			nOdpDirection = 0;
230 			break;
231 		}
232 		return nOdpDirection;
233 	}
234 
235 
236 	sal_Int16 SlideTransition::ooxToOdpDirection( ::sal_Int32 nOoxType )
237 	{
238     sal_Int16 nOdpDir;
239 		switch( nOoxType )
240 		{
241 		case XML_vert:
242 			nOdpDir = TransitionSubType::VERTICAL;
243 			break;
244 		case XML_horz:
245 			nOdpDir = TransitionSubType::HORIZONTAL;
246 			break;
247 		default:
248 			nOdpDir = 0;
249 			break;
250 		}
251 		return nOdpDir;
252 	}
253 
254 	void SlideTransition::setOoxTransitionType( ::sal_Int32 OoxType, ::sal_Int32 param1, ::sal_Int32 param2 )
255 	{
256 		switch( OoxType )
257 		{
258 		case PPT_TOKEN( blinds ):
259 			mnTransitionType = TransitionType::BLINDSWIPE;
260 			mnTransitionSubType = ooxToOdpDirection( param1 );
261 			break;
262 		case PPT_TOKEN( checker ):
263 			mnTransitionType = TransitionType::CHECKERBOARDWIPE;
264 			switch ( param1 )
265 			{
266 			case XML_vert:
267 				mnTransitionSubType = TransitionSubType::DOWN;
268 				break;
269 			case XML_horz:
270 				mnTransitionSubType = TransitionSubType::ACROSS;
271 				break;
272 			default:
273 				break;
274 			}
275 			break;
276 		case PPT_TOKEN( comb ):
277 			mnTransitionType = TransitionType::PUSHWIPE;
278 			switch( param1 )
279 			{
280 			case XML_vert:
281 				mnTransitionSubType = TransitionSubType::COMBVERTICAL;
282 				break;
283 			case XML_horz:
284 				mnTransitionSubType = TransitionSubType::COMBHORIZONTAL;
285 				break;
286 			default:
287 				break;
288 			}
289 			break;
290 		case PPT_TOKEN( cover ):
291 			mnTransitionType = TransitionType::SLIDEWIPE;
292 			mnTransitionSubType = ooxToOdpEightDirections( param1 );
293 			break;
294 		case PPT_TOKEN( pull ): // uncover
295 			mnTransitionType = TransitionType::SLIDEWIPE;
296 			mnTransitionSubType = ooxToOdpEightDirections( param1 );
297 			mbTransitionDirectionNormal = false;
298 			break;
299 		case PPT_TOKEN( cut ):
300 			// The binfilter seems to ignore this transition.
301 			// Fade to black instead if thrBlk is true.
302 			if( param1 )
303 			{
304 				mnTransitionType = TransitionType::FADE;
305 				mnTransitionSubType = TransitionSubType::FADEOVERCOLOR;
306 			}
307 			OSL_TRACE( "OOX: cut transition fallback." );
308 			break;
309 		case PPT_TOKEN( fade ):
310 			mnTransitionType = TransitionType::FADE;
311 			if( param1 )
312 			{
313 				mnTransitionSubType = TransitionSubType::FADEOVERCOLOR;
314 			}
315 			else
316 			{
317 				mnTransitionSubType = TransitionSubType::CROSSFADE;
318 			}
319 			break;
320 		case PPT_TOKEN( push ):
321 			mnTransitionType = TransitionType::PUSHWIPE;
322 			mnTransitionSubType = ooxToOdpBorderDirections( param1 );
323 			break;
324 		case PPT_TOKEN( wipe ):
325 			mnTransitionType = TransitionType::BARWIPE;
326 			mnTransitionSubType = ooxToOdpSideDirections( param1 );
327 			mbTransitionDirectionNormal = ooxToOdpSideDirectionsDirectionNormal( param1 );
328 			break;
329 		case PPT_TOKEN( split ):
330 			mnTransitionType = TransitionType::BARNDOORWIPE;
331 			mnTransitionSubType = ooxToOdpDirection( param1 );
332 			if( param2 == XML_in )
333 			{
334 				// reverse
335 				mbTransitionDirectionNormal = false;
336 			}
337 			break;
338 		case PPT_TOKEN( wheel ):
339 			mnTransitionType = TransitionType::PINWHEELWIPE;
340 			switch( param1 )
341 			{
342 			case 1:
343 				mnTransitionSubType = TransitionSubType::ONEBLADE;
344 				break;
345 			case 2:
346 				mnTransitionSubType = TransitionSubType::TWOBLADEVERTICAL;
347 				break;
348 			case 3:
349 				mnTransitionSubType = TransitionSubType::THREEBLADE;
350 				break;
351 			case 4:
352 				mnTransitionSubType = TransitionSubType::FOURBLADE;
353 				break;
354 			case 8:
355 				mnTransitionSubType = TransitionSubType::EIGHTBLADE;
356 				break;
357 			default:
358 				OSL_TRACE( "OOX: strange number of blades for thw wheel-wipe %d", param1 );
359 				if( param1 > 8 )
360 				{
361 					mnTransitionSubType = TransitionSubType::EIGHTBLADE;
362 				}
363 				else if( param1 > 4 )
364 				{
365 					mnTransitionSubType = TransitionSubType::FOURBLADE;
366 				}
367 				else if( param1 == 0)
368 				{
369 					mnTransitionSubType = TransitionSubType::ONEBLADE;
370 				}
371 				break;
372 			}
373 			break;
374 		case PPT_TOKEN( randomBar ):
375 			mnTransitionType = TransitionType::RANDOMBARWIPE;
376 			mnTransitionSubType = ooxToOdpDirection( param1 );
377 			break;
378 		case PPT_TOKEN( circle ):
379 			mnTransitionType = TransitionType::ELLIPSEWIPE;
380 			mnTransitionSubType = TransitionSubType::CIRCLE;
381 			break;
382 		case PPT_TOKEN( diamond ):
383 			mnTransitionType = TransitionType::IRISWIPE;
384 			mnTransitionSubType = TransitionSubType::DIAMOND;
385 			break;
386 		case PPT_TOKEN( dissolve ):
387 			mnTransitionType = TransitionType::DISSOLVE;
388 			mnTransitionSubType = TransitionSubType::DEFAULT;
389 			break;
390 		case PPT_TOKEN( newsflash ):
391 			// this is what the PPT binary filter does.... not sure I agree.
392 			mnTransitionType = TransitionType::FOURBOXWIPE;
393 			mnTransitionSubType = TransitionSubType::CORNERSOUT;
394 			break;
395 		case PPT_TOKEN( plus ):
396 			mnTransitionType = TransitionType::FOURBOXWIPE;
397 			mnTransitionSubType = TransitionSubType::CORNERSOUT;
398 			break;
399 		case PPT_TOKEN( random ):
400 			mnTransitionType = TransitionType::RANDOM;
401 			mnTransitionSubType = TransitionSubType::DEFAULT;
402 			break;
403 		case PPT_TOKEN( wedge ):
404 			mnTransitionType = TransitionType::FANWIPE;
405 			mnTransitionSubType = TransitionSubType::CENTERTOP;
406 			break;
407 		case PPT_TOKEN( zoom ):
408 			mnTransitionType = TransitionType::ZOOM;
409 			mnTransitionSubType = TransitionSubType::DEFAULT;
410 			break;
411 		default:
412 			mnTransitionType = 0;
413 			break;
414 		}
415 	}
416 
417 
418 } }
419