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