merge the formfield patch from ooo-build
[ooovba.git] / oox / source / ppt / slidetransition.cxx
blob1265a764a7297df52d748ef1206c0fc461be9f8d
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: slidetransition.cxx,v $
10 * $Revision: 1.4 $
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 ************************************************************************/
31 #include "oox/ppt/slidetransition.hxx"
33 #include <com/sun/star/uno/Any.hxx>
34 #include <com/sun/star/beans/XPropertySet.hpp>
35 #include <com/sun/star/presentation/AnimationSpeed.hpp>
36 #include <com/sun/star/animations/TransitionType.hpp>
37 #include <com/sun/star/animations/TransitionSubType.hpp>
39 #include "oox/helper/helper.hxx"
40 #include "oox/helper/propertymap.hxx"
41 #include "oox/core/namespaces.hxx"
42 #include "pptfilterhelpers.hxx"
43 #include "properties.hxx"
44 #include "tokens.hxx"
46 using rtl::OUString;
47 using namespace ::com::sun::star::uno;
48 using namespace ::com::sun::star::beans;
49 using namespace ::com::sun::star::animations;
50 using namespace ::com::sun::star::presentation;
52 namespace oox { namespace ppt {
55 SlideTransition::SlideTransition()
56 : mnTransitionType( 0 )
57 , mnTransitionSubType( 0 )
58 , mbTransitionDirectionNormal( true )
59 , mnAnimationSpeed( AnimationSpeed_FAST )
60 , mnFadeColor( 0 )
61 , mbMode( true )
62 , mnAdvanceTime( -1 )
68 SlideTransition::SlideTransition(const OUString & sFilterName)
69 : mnTransitionType( 0 )
70 , mnTransitionSubType( 0 )
71 , mbTransitionDirectionNormal( true )
72 , mnAnimationSpeed( AnimationSpeed_FAST )
73 , mnFadeColor( 0 )
74 , mbMode( true )
75 , mnAdvanceTime( -1 )
77 const transition *p = transition::find( sFilterName );
78 if( p )
80 mnTransitionType = p->mnType;
81 mnTransitionSubType = p->mnSubType;
82 mbTransitionDirectionNormal = p->mbDirection;
87 void SlideTransition::setSlideProperties( PropertyMap & aProps )
89 try
91 aProps[ PROP_TransitionType ] <<= mnTransitionType;
92 aProps[ PROP_TransitionSubtype ] <<= mnTransitionSubType;
93 aProps[ PROP_TransitionDirection ] <<= mbTransitionDirectionNormal;
94 aProps[ PROP_Speed ] <<= mnAnimationSpeed;
95 aProps[ PROP_TransitionFadeColor ] <<= mnFadeColor;
96 if( mnAdvanceTime != -1 ) {
97 aProps[ PROP_Duration ] <<= mnAdvanceTime/1000;
98 aProps[ PROP_Change ] <<= static_cast<sal_Int32>(1);
101 catch( Exception& )
103 // should not happen
104 OSL_ENSURE( false, "exception raised" );
108 void SlideTransition::setTransitionFilterProperties( const Reference< XTransitionFilter > & xFilter )
112 xFilter->setTransition( mnTransitionType );
113 xFilter->setSubtype( mnTransitionSubType );
114 xFilter->setDirection( mbTransitionDirectionNormal );
115 xFilter->setFadeColor( mnFadeColor );
116 xFilter->setMode( mbMode );
118 catch( Exception& )
120 // should not happen
121 OSL_ENSURE( false, "exception raised" );
126 void SlideTransition::setOoxTransitionSpeed( sal_Int32 nToken)
128 switch( nToken )
130 /* In case you want to use time values in second,
131 * the speed values are located in the PPT97 importer
132 * sd/source/filter/ppt/ppt97animations.cxx:664
133 * (void Ppt97Animation::UpdateCacheData() const)
135 case XML_fast:
136 mnAnimationSpeed = AnimationSpeed_FAST;
137 break;
138 case XML_med:
139 mnAnimationSpeed = AnimationSpeed_MEDIUM;
140 break;
141 case XML_slow:
142 mnAnimationSpeed = AnimationSpeed_SLOW;
143 break;
144 default:
145 // should not happen. just ignore
146 break;
150 sal_Int16 SlideTransition::ooxToOdpEightDirections( ::sal_Int32 nOoxType )
152 sal_Int16 nOdpDirection;
153 nOdpDirection = ooxToOdpBorderDirections( nOoxType );
154 if( nOdpDirection == 0 )
156 nOdpDirection = ooxToOdpCornerDirections( nOoxType );
158 return nOdpDirection;
162 sal_Int16 SlideTransition::ooxToOdpBorderDirections( ::sal_Int32 nOoxType )
164 sal_Int16 nOdpDirection;
165 switch( nOoxType )
167 case XML_d:
168 nOdpDirection = TransitionSubType::FROMTOP;
169 break;
170 case XML_l:
171 nOdpDirection = TransitionSubType::FROMLEFT;
172 break;
173 case XML_r:
174 nOdpDirection = TransitionSubType::FROMRIGHT;
175 break;
176 case XML_u:
177 nOdpDirection = TransitionSubType::FROMBOTTOM;
178 break;
179 default:
180 nOdpDirection= 0;
181 break;
183 return nOdpDirection;
186 sal_Int16 SlideTransition::ooxToOdpSideDirections( ::sal_Int32 nOoxType )
188 sal_Int16 nOdpDirection;
189 switch( nOoxType )
191 case XML_d:
192 case XML_u:
193 nOdpDirection = TransitionSubType::TOPTOBOTTOM;
194 break;
195 case XML_l:
196 case XML_r:
197 nOdpDirection = TransitionSubType::LEFTTORIGHT;
198 break;
199 default:
200 nOdpDirection= 0;
201 break;
203 return nOdpDirection;
206 sal_Bool SlideTransition::ooxToOdpSideDirectionsDirectionNormal( ::sal_Int32 nOoxType )
208 sal_Bool nOdpDirection = true;
209 switch( nOoxType )
211 case XML_u:
212 case XML_l:
213 nOdpDirection = false;
214 break;
216 return nOdpDirection;
219 sal_Int16 SlideTransition::ooxToOdpCornerDirections( ::sal_Int32 nOoxType )
221 sal_Int16 nOdpDirection;
222 switch( nOoxType )
224 case XML_lu:
225 nOdpDirection = TransitionSubType::FROMBOTTOMRIGHT;
226 break;
227 case XML_ru:
228 nOdpDirection = TransitionSubType::FROMBOTTOMLEFT;
229 break;
230 case XML_ld:
231 nOdpDirection = TransitionSubType::FROMTOPRIGHT;
232 break;
233 case XML_rd:
234 nOdpDirection = TransitionSubType::FROMTOPLEFT;
235 break;
236 default:
237 nOdpDirection = 0;
238 break;
240 return nOdpDirection;
244 sal_Int16 SlideTransition::ooxToOdpDirection( ::sal_Int32 nOoxType )
246 sal_Int16 nOdpDir;
247 switch( nOoxType )
249 case XML_vert:
250 nOdpDir = TransitionSubType::VERTICAL;
251 break;
252 case XML_horz:
253 nOdpDir = TransitionSubType::HORIZONTAL;
254 break;
255 default:
256 nOdpDir = 0;
257 break;
259 return nOdpDir;
262 void SlideTransition::setOoxTransitionType( ::sal_Int32 OoxType, ::sal_Int32 param1, ::sal_Int32 param2 )
264 switch( OoxType )
266 case NMSP_PPT|XML_blinds:
267 mnTransitionType = TransitionType::BLINDSWIPE;
268 mnTransitionSubType = ooxToOdpDirection( param1 );
269 break;
270 case NMSP_PPT|XML_checker:
271 mnTransitionType = TransitionType::CHECKERBOARDWIPE;
272 switch ( param1 )
274 case XML_vert:
275 mnTransitionSubType = TransitionSubType::DOWN;
276 break;
277 case XML_horz:
278 mnTransitionSubType = TransitionSubType::ACROSS;
279 break;
280 default:
281 break;
283 break;
284 case NMSP_PPT|XML_comb:
285 mnTransitionType = TransitionType::PUSHWIPE;
286 switch( param1 )
288 case XML_vert:
289 mnTransitionSubType = TransitionSubType::COMBVERTICAL;
290 break;
291 case XML_horz:
292 mnTransitionSubType = TransitionSubType::COMBHORIZONTAL;
293 break;
294 default:
295 break;
297 break;
298 case NMSP_PPT|XML_cover:
299 mnTransitionType = TransitionType::SLIDEWIPE;
300 mnTransitionSubType = ooxToOdpEightDirections( param1 );
301 break;
302 case NMSP_PPT|XML_pull: // uncover
303 mnTransitionType = TransitionType::SLIDEWIPE;
304 mnTransitionSubType = ooxToOdpEightDirections( param1 );
305 mbTransitionDirectionNormal = false;
306 break;
307 case NMSP_PPT|XML_cut:
308 // The binfilter seems to ignore this transition.
309 // Fade to black instead if thrBlk is true.
310 if( param1 )
312 mnTransitionType = TransitionType::FADE;
313 mnTransitionSubType = TransitionSubType::FADEOVERCOLOR;
315 OSL_TRACE( "OOX: cut transition fallback." );
316 break;
317 case NMSP_PPT|XML_fade:
318 mnTransitionType = TransitionType::FADE;
319 if( param1 )
321 mnTransitionSubType = TransitionSubType::FADEOVERCOLOR;
323 else
325 mnTransitionSubType = TransitionSubType::CROSSFADE;
327 break;
328 case NMSP_PPT|XML_push:
329 mnTransitionType = TransitionType::PUSHWIPE;
330 mnTransitionSubType = ooxToOdpBorderDirections( param1 );
331 break;
332 case NMSP_PPT|XML_wipe:
333 mnTransitionType = TransitionType::BARWIPE;
334 mnTransitionSubType = ooxToOdpSideDirections( param1 );
335 mbTransitionDirectionNormal = ooxToOdpSideDirectionsDirectionNormal( param1 );
336 break;
337 case NMSP_PPT|XML_split:
338 mnTransitionType = TransitionType::BARNDOORWIPE;
339 mnTransitionSubType = ooxToOdpDirection( param1 );
340 if( param2 == XML_in )
342 // reverse
343 mbTransitionDirectionNormal = false;
345 break;
346 case NMSP_PPT|XML_wheel:
347 mnTransitionType = TransitionType::PINWHEELWIPE;
348 switch( param1 )
350 case 1:
351 mnTransitionSubType = TransitionSubType::ONEBLADE;
352 break;
353 case 2:
354 mnTransitionSubType = TransitionSubType::TWOBLADEVERTICAL;
355 break;
356 case 3:
357 mnTransitionSubType = TransitionSubType::THREEBLADE;
358 break;
359 case 4:
360 mnTransitionSubType = TransitionSubType::FOURBLADE;
361 break;
362 case 8:
363 mnTransitionSubType = TransitionSubType::EIGHTBLADE;
364 break;
365 default:
366 OSL_TRACE( "OOX: strange number of blades for thw wheel-wipe %d", param1 );
367 if( param1 > 8 )
369 mnTransitionSubType = TransitionSubType::EIGHTBLADE;
371 else if( param1 > 4 )
373 mnTransitionSubType = TransitionSubType::FOURBLADE;
375 else if( param1 == 0)
377 mnTransitionSubType = TransitionSubType::ONEBLADE;
379 break;
381 break;
382 case NMSP_PPT|XML_randomBar:
383 mnTransitionType = TransitionType::RANDOMBARWIPE;
384 mnTransitionSubType = ooxToOdpDirection( param1 );
385 break;
386 case NMSP_PPT|XML_circle:
387 mnTransitionType = TransitionType::ELLIPSEWIPE;
388 mnTransitionSubType = TransitionSubType::CIRCLE;
389 break;
390 case NMSP_PPT|XML_diamond:
391 mnTransitionType = TransitionType::IRISWIPE;
392 mnTransitionSubType = TransitionSubType::DIAMOND;
393 break;
394 case NMSP_PPT|XML_dissolve:
395 mnTransitionType = TransitionType::DISSOLVE;
396 mnTransitionSubType = TransitionSubType::DEFAULT;
397 break;
398 case NMSP_PPT|XML_newsflash:
399 // this is what the PPT binary filter does.... not sure I agree.
400 mnTransitionType = TransitionType::FOURBOXWIPE;
401 mnTransitionSubType = TransitionSubType::CORNERSOUT;
402 break;
403 case NMSP_PPT|XML_plus:
404 mnTransitionType = TransitionType::FOURBOXWIPE;
405 mnTransitionSubType = TransitionSubType::CORNERSOUT;
406 break;
407 case NMSP_PPT|XML_random:
408 mnTransitionType = TransitionType::RANDOM;
409 mnTransitionSubType = TransitionSubType::DEFAULT;
410 break;
411 case NMSP_PPT|XML_wedge:
412 mnTransitionType = TransitionType::FANWIPE;
413 mnTransitionSubType = TransitionSubType::CENTERTOP;
414 break;
415 case NMSP_PPT|XML_zoom:
416 mnTransitionType = TransitionType::ZOOM;
417 mnTransitionSubType = TransitionSubType::DEFAULT;
418 break;
419 default:
420 mnTransitionType = 0;
421 break;