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