Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / oox / source / ppt / slidetransition.cxx
blob59c30b7bc1d63a192936867316942e3bbb355b8e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <oox/ppt/slidetransition.hxx>
22 #include <com/sun/star/beans/XPropertySet.hpp>
23 #include <com/sun/star/animations/TransitionType.hpp>
24 #include <com/sun/star/animations/TransitionSubType.hpp>
25 #include <com/sun/star/animations/XTransitionFilter.hpp>
27 #include <osl/diagnose.h>
28 #include <sal/log.hxx>
30 #include <oox/helper/helper.hxx>
31 #include <oox/helper/propertymap.hxx>
32 #include <oox/token/namespaces.hxx>
33 #include <oox/token/properties.hxx>
34 #include <oox/token/tokens.hxx>
35 #include <oox/ppt/pptfilterhelpers.hxx>
37 using namespace ::com::sun::star::uno;
38 using namespace ::com::sun::star::beans;
39 using namespace ::com::sun::star::animations;
40 using namespace ::com::sun::star::presentation;
42 namespace oox { namespace ppt {
44 SlideTransition::SlideTransition()
45 : mnTransitionType( 0 )
46 , mnTransitionSubType( 0 )
47 , mbTransitionDirectionNormal( true )
48 , mnAnimationSpeed( AnimationSpeed_FAST )
49 , mfTransitionDurationInSeconds( -1.0 )
50 , mbMode( true )
51 , mnAdvanceTime( -1 )
56 SlideTransition::SlideTransition(const OUString & sFilterName)
57 : mnTransitionType( 0 )
58 , mnTransitionSubType( 0 )
59 , mbTransitionDirectionNormal( true )
60 , mnAnimationSpeed( AnimationSpeed_FAST )
61 , mfTransitionDurationInSeconds( -1.0 )
62 , mbMode( true )
63 , mnAdvanceTime( -1 )
65 const transition *p = transition::find( sFilterName );
66 if( p )
68 mnTransitionType = p->mnType;
69 mnTransitionSubType = p->mnSubType;
70 mbTransitionDirectionNormal = p->mbDirection;
74 void SlideTransition::setSlideProperties( PropertyMap & aProps )
76 try
78 aProps.setProperty( PROP_TransitionType, mnTransitionType);
79 aProps.setProperty( PROP_TransitionSubtype, mnTransitionSubType);
80 aProps.setProperty( PROP_TransitionDirection, mbTransitionDirectionNormal);
81 aProps.setProperty( PROP_Speed, mnAnimationSpeed);
82 if( mfTransitionDurationInSeconds >= 0.0 )
83 aProps.setProperty( PROP_TransitionDuration, mfTransitionDurationInSeconds);
84 aProps.setProperty( PROP_TransitionFadeColor, sal_Int32(0));
85 if( mnAdvanceTime != -1 ) {
86 aProps.setProperty( PROP_Duration, mnAdvanceTime/1000);
87 aProps.setProperty( PROP_Change, static_cast<sal_Int32>(1));
90 catch( Exception& )
92 // should not happen
93 OSL_FAIL( "exception raised" );
97 void SlideTransition::setTransitionFilterProperties( const Reference< XTransitionFilter > & xFilter )
99 try
101 xFilter->setTransition( mnTransitionType );
102 xFilter->setSubtype( mnTransitionSubType );
103 xFilter->setDirection( mbTransitionDirectionNormal );
104 xFilter->setFadeColor( 0 );
105 xFilter->setMode( mbMode );
107 catch( Exception& )
109 // should not happen
110 OSL_FAIL( "exception raised" );
114 void SlideTransition::setOoxTransitionSpeed( sal_Int32 nToken)
116 switch( nToken )
118 /* the speed values are located in the PPT97 importer
119 * sd/source/filter/ppt/pptin.cxx:1783
120 * (void ImplSdPPTImport::ImportPageEffect)
122 case XML_fast:
123 mnAnimationSpeed = AnimationSpeed_FAST;
124 mfTransitionDurationInSeconds = 0.5;
125 break;
126 case XML_med:
127 mnAnimationSpeed = AnimationSpeed_MEDIUM;
128 mfTransitionDurationInSeconds = 0.75;
129 break;
130 case XML_slow:
131 mnAnimationSpeed = AnimationSpeed_SLOW;
132 mfTransitionDurationInSeconds = 1.0;
133 break;
134 default:
135 // should not happen. just ignore
136 break;
140 void SlideTransition::setOoxTransitionSpeed( double fDurationInSeconds )
142 // for compatibility
143 mnAnimationSpeed = ( fDurationInSeconds <= 0.5 ) ? AnimationSpeed_FAST
144 : ( fDurationInSeconds >= 1.0 ) ? AnimationSpeed_SLOW : AnimationSpeed_MEDIUM;
145 mfTransitionDurationInSeconds = fDurationInSeconds;
148 sal_Int16 SlideTransition::ooxToOdpEightDirections( ::sal_Int32 nOoxType )
150 sal_Int16 nOdpDirection;
151 nOdpDirection = ooxToOdpBorderDirections( nOoxType );
152 if( nOdpDirection == 0 )
154 nOdpDirection = ooxToOdpCornerDirections( nOoxType );
156 return nOdpDirection;
159 sal_Int16 SlideTransition::ooxToOdpBorderDirections( ::sal_Int32 nOoxType )
161 sal_Int16 nOdpDirection;
162 switch( nOoxType )
164 case XML_d:
165 nOdpDirection = TransitionSubType::FROMTOP;
166 break;
167 case XML_l:
168 nOdpDirection = TransitionSubType::FROMLEFT;
169 break;
170 case XML_r:
171 nOdpDirection = TransitionSubType::FROMRIGHT;
172 break;
173 case XML_u:
174 nOdpDirection = TransitionSubType::FROMBOTTOM;
175 break;
176 default:
177 nOdpDirection= 0;
178 break;
180 return nOdpDirection;
183 sal_Int16 SlideTransition::ooxToOdpSideDirections( ::sal_Int32 nOoxType )
185 sal_Int16 nOdpDirection;
186 switch( nOoxType )
188 case XML_d:
189 case XML_u:
190 nOdpDirection = TransitionSubType::TOPTOBOTTOM;
191 break;
192 case XML_l:
193 case XML_r:
194 nOdpDirection = TransitionSubType::LEFTTORIGHT;
195 break;
196 default:
197 nOdpDirection= 0;
198 break;
200 return nOdpDirection;
203 bool SlideTransition::ooxToOdpSideDirectionsDirectionNormal( ::sal_Int32 nOoxType )
205 bool bOdpDirection = true;
206 switch( nOoxType )
208 case XML_u:
209 case XML_l:
210 bOdpDirection = false;
211 break;
213 return bOdpDirection;
216 sal_Int16 SlideTransition::ooxToOdpCornerDirections( ::sal_Int32 nOoxType )
218 sal_Int16 nOdpDirection;
219 switch( nOoxType )
221 case XML_lu:
222 nOdpDirection = TransitionSubType::FROMBOTTOMRIGHT;
223 break;
224 case XML_ru:
225 nOdpDirection = TransitionSubType::FROMBOTTOMLEFT;
226 break;
227 case XML_ld:
228 nOdpDirection = TransitionSubType::FROMTOPRIGHT;
229 break;
230 case XML_rd:
231 nOdpDirection = TransitionSubType::FROMTOPLEFT;
232 break;
233 default:
234 nOdpDirection = 0;
235 break;
237 return nOdpDirection;
240 sal_Int16 SlideTransition::ooxToOdpDirection( ::sal_Int32 nOoxType )
242 sal_Int16 nOdpDir;
243 switch( nOoxType )
245 case XML_vert:
246 nOdpDir = TransitionSubType::VERTICAL;
247 break;
248 case XML_horz:
249 nOdpDir = TransitionSubType::HORIZONTAL;
250 break;
251 default:
252 nOdpDir = 0;
253 break;
255 return nOdpDir;
258 void SlideTransition::setOoxTransitionType( ::sal_Int32 OoxType, ::sal_Int32 param1, ::sal_Int32 param2 )
260 switch( OoxType )
262 case PPT_TOKEN( blinds ):
263 mnTransitionType = TransitionType::BLINDSWIPE;
264 mnTransitionSubType = ooxToOdpDirection( param1 );
265 break;
266 case PPT_TOKEN( checker ):
267 mnTransitionType = TransitionType::CHECKERBOARDWIPE;
268 switch ( param1 )
270 case XML_vert:
271 mnTransitionSubType = TransitionSubType::DOWN;
272 break;
273 case XML_horz:
274 mnTransitionSubType = TransitionSubType::ACROSS;
275 break;
276 default:
277 break;
279 break;
280 case PPT_TOKEN( comb ):
281 mnTransitionType = TransitionType::PUSHWIPE;
282 switch( param1 )
284 case XML_vert:
285 mnTransitionSubType = TransitionSubType::COMBVERTICAL;
286 break;
287 case XML_horz:
288 mnTransitionSubType = TransitionSubType::COMBHORIZONTAL;
289 break;
290 default:
291 break;
293 break;
294 case PPT_TOKEN( cover ):
295 mnTransitionType = TransitionType::SLIDEWIPE;
296 mnTransitionSubType = ooxToOdpEightDirections( param1 );
297 break;
298 case PPT_TOKEN( pull ): // uncover
299 mnTransitionType = TransitionType::SLIDEWIPE;
300 mnTransitionSubType = ooxToOdpEightDirections( param1 );
301 mbTransitionDirectionNormal = false;
302 break;
303 case PPT_TOKEN( cut ):
304 if( param1 )
306 mnTransitionType = TransitionType::BARWIPE;
307 mnTransitionSubType = TransitionSubType::FADEOVERCOLOR;
309 SAL_WARN("oox.ppt", "OOX: cut transition fallback." );
310 break;
311 case PPT_TOKEN( fade ):
312 mnTransitionType = TransitionType::FADE;
313 if( param1 )
315 mnTransitionSubType = TransitionSubType::FADEOVERCOLOR;
317 else
319 mnTransitionSubType = TransitionSubType::CROSSFADE;
321 break;
322 case PPT_TOKEN( push ):
323 mnTransitionType = TransitionType::PUSHWIPE;
324 mnTransitionSubType = ooxToOdpBorderDirections( param1 );
325 break;
326 case PPT_TOKEN( wipe ):
327 mnTransitionType = TransitionType::BARWIPE;
328 mnTransitionSubType = ooxToOdpSideDirections( param1 );
329 mbTransitionDirectionNormal = ooxToOdpSideDirectionsDirectionNormal( param1 );
330 break;
331 case PPT_TOKEN( split ):
332 mnTransitionType = TransitionType::BARNDOORWIPE;
333 mnTransitionSubType = ooxToOdpDirection( param1 );
334 if( param2 == XML_in )
336 // reverse
337 mbTransitionDirectionNormal = false;
339 break;
340 case PPT_TOKEN( wheel ):
341 mnTransitionType = TransitionType::PINWHEELWIPE;
342 switch( param1 )
344 case 1:
345 mnTransitionSubType = TransitionSubType::ONEBLADE;
346 break;
347 case 2:
348 mnTransitionSubType = TransitionSubType::TWOBLADEVERTICAL;
349 break;
350 case 3:
351 mnTransitionSubType = TransitionSubType::THREEBLADE;
352 break;
353 case 4:
354 mnTransitionSubType = TransitionSubType::FOURBLADE;
355 break;
356 case 8:
357 mnTransitionSubType = TransitionSubType::EIGHTBLADE;
358 break;
359 default:
360 SAL_INFO(
361 "oox.ppt",
362 "strange number of blades for the wheel-wipe " << param1);
363 if( param1 > 8 )
365 mnTransitionSubType = TransitionSubType::EIGHTBLADE;
367 else if( param1 > 4 )
369 mnTransitionSubType = TransitionSubType::FOURBLADE;
371 else if( param1 == 0)
373 mnTransitionSubType = TransitionSubType::ONEBLADE;
375 break;
377 break;
378 case PPT_TOKEN( randomBar ):
379 mnTransitionType = TransitionType::RANDOMBARWIPE;
380 mnTransitionSubType = ooxToOdpDirection( param1 );
381 break;
382 case PPT_TOKEN( circle ):
383 mnTransitionType = TransitionType::ELLIPSEWIPE;
384 mnTransitionSubType = TransitionSubType::CIRCLE;
385 break;
386 case PPT_TOKEN( diamond ):
387 mnTransitionType = TransitionType::IRISWIPE;
388 mnTransitionSubType = TransitionSubType::DIAMOND;
389 break;
390 case PPT_TOKEN( dissolve ):
391 mnTransitionType = TransitionType::DISSOLVE;
392 mnTransitionSubType = TransitionSubType::DEFAULT;
393 break;
394 case PPT_TOKEN( newsflash ):
395 mnTransitionType = TransitionType::ZOOM;
396 mnTransitionSubType = TransitionSubType::ROTATEIN;
397 break;
398 case PPT_TOKEN( plus ):
399 mnTransitionType = TransitionType::FOURBOXWIPE;
400 mnTransitionSubType = TransitionSubType::CORNERSOUT;
401 break;
402 case PPT_TOKEN( random ):
403 mnTransitionType = TransitionType::RANDOM;
404 mnTransitionSubType = TransitionSubType::DEFAULT;
405 break;
406 case PPT_TOKEN( wedge ):
407 mnTransitionType = TransitionType::FANWIPE;
408 mnTransitionSubType = TransitionSubType::CENTERTOP;
409 break;
410 case PPT_TOKEN( zoom ):
411 mnTransitionType = TransitionType::ZOOM;
412 mnTransitionSubType = TransitionSubType::DEFAULT;
413 break;
414 case P14_TOKEN(prism):
415 mnTransitionType = TransitionType::MISCSHAPEWIPE;
416 if (param1)
417 mnTransitionSubType = TransitionSubType::CORNERSIN;
418 else
419 mnTransitionSubType = TransitionSubType::CORNERSOUT;
420 break;
421 case P14_TOKEN(vortex):
422 mnTransitionType = TransitionType::MISCSHAPEWIPE;
423 mnTransitionSubType = TransitionSubType::VERTICAL;
424 break;
425 case P14_TOKEN(ripple):
426 mnTransitionType = TransitionType::MISCSHAPEWIPE;
427 mnTransitionSubType = TransitionSubType::HORIZONTAL;
428 break;
429 case P14_TOKEN(glitter):
430 mnTransitionType = TransitionType::MISCSHAPEWIPE;
431 mnTransitionSubType = TransitionSubType::DIAMOND;
432 break;
433 case P14_TOKEN(honeycomb):
434 mnTransitionType = TransitionType::MISCSHAPEWIPE;
435 mnTransitionSubType = TransitionSubType::HEART;
436 break;
437 default:
438 mnTransitionType = 0;
439 break;
443 void SlideTransition::setPresetTransition(OUString const & sPresetTransition)
445 if (sPresetTransition == "fallOver")
447 mnTransitionType = TransitionType::MISCSHAPEWIPE;
448 mnTransitionSubType = TransitionSubType::LEFTTORIGHT;
450 else
452 mnTransitionType = 0;
458 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */