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 <com/sun/star/presentation/EffectNodeType.hpp>
21 : #include <com/sun/star/presentation/ShapeAnimationSubType.hpp>
22 : #include <com/sun/star/presentation/TextAnimationType.hpp>
23 : #include <com/sun/star/presentation/ParagraphTarget.hpp>
24 : #include <svx/unoshape.hxx>
25 : #include <svx/svdotext.hxx>
26 : #include <svx/svdopath.hxx>
27 : #include "drawdoc.hxx"
28 : #include "sdpage.hxx"
29 : #include <CustomAnimationPreset.hxx>
30 : #include <TransitionPreset.hxx>
31 : #include <EffectMigration.hxx>
32 : #include <anminfo.hxx>
33 :
34 : using namespace ::sd;
35 : using namespace ::com::sun::star::uno;
36 : using namespace ::com::sun::star::animations;
37 : using namespace ::com::sun::star::presentation;
38 :
39 : using ::com::sun::star::drawing::XShape;
40 :
41 : struct deprecated_FadeEffect_conversion_table_entry
42 : {
43 : FadeEffect meFadeEffect;
44 : const sal_Char* mpPresetId;
45 : }
46 : deprecated_FadeEffect_conversion_table[] =
47 : {
48 : // OOo 1.x transitions
49 : { FadeEffect_FADE_FROM_LEFT, "wipe-right" },
50 : { FadeEffect_FADE_FROM_TOP, "wipe-down" },
51 : { FadeEffect_FADE_FROM_RIGHT, "wipe-left" },
52 : { FadeEffect_FADE_FROM_BOTTOM, "wipe-up" },
53 :
54 : { FadeEffect_CLOCKWISE, "wheel-clockwise-1-spoke" },
55 :
56 : { FadeEffect_UNCOVER_TO_LEFT, "uncover-left" },
57 : { FadeEffect_UNCOVER_TO_UPPERLEFT, "uncover-left-up" },
58 : { FadeEffect_UNCOVER_TO_TOP, "uncover-up" },
59 : { FadeEffect_UNCOVER_TO_UPPERRIGHT, "uncover-right-up" },
60 : { FadeEffect_UNCOVER_TO_RIGHT, "uncover-right" },
61 : { FadeEffect_UNCOVER_TO_LOWERRIGHT, "uncover-right-down" },
62 : { FadeEffect_UNCOVER_TO_BOTTOM, "uncover-down" },
63 : { FadeEffect_UNCOVER_TO_LOWERLEFT, "uncover-left-down" },
64 :
65 : { FadeEffect_VERTICAL_LINES, "random-bars-vertical" },
66 : { FadeEffect_HORIZONTAL_LINES, "random-bars-horizontal" },
67 :
68 : { FadeEffect_VERTICAL_CHECKERBOARD, "checkerboard-down" },
69 : { FadeEffect_HORIZONTAL_CHECKERBOARD, "checkerboard-across" },
70 :
71 : { FadeEffect_FADE_TO_CENTER, "box-in" },
72 : { FadeEffect_FADE_FROM_CENTER, "box-out" },
73 :
74 : { FadeEffect_VERTICAL_STRIPES, "venetian-blinds-vertical" },
75 : { FadeEffect_HORIZONTAL_STRIPES, "venetian-blinds-horizontal" },
76 :
77 : { FadeEffect_MOVE_FROM_LEFT, "cover-right" },
78 : { FadeEffect_MOVE_FROM_TOP, "cover-down" },
79 : { FadeEffect_MOVE_FROM_RIGHT, "cover-left" },
80 : { FadeEffect_MOVE_FROM_BOTTOM, "cover-up" },
81 : { FadeEffect_MOVE_FROM_UPPERLEFT, "cover-right-down" },
82 : { FadeEffect_MOVE_FROM_UPPERRIGHT, "cover-left-down" },
83 : { FadeEffect_MOVE_FROM_LOWERRIGHT, "cover-left-up" },
84 : { FadeEffect_MOVE_FROM_LOWERLEFT, "cover-right-up" },
85 :
86 : { FadeEffect_DISSOLVE, "dissolve" },
87 :
88 : { FadeEffect_RANDOM, "random-transition" },
89 :
90 : { FadeEffect_ROLL_FROM_LEFT, "push-right" },
91 : { FadeEffect_ROLL_FROM_TOP, "push-down" },
92 : { FadeEffect_ROLL_FROM_RIGHT, "push-left" },
93 : { FadeEffect_ROLL_FROM_BOTTOM, "push-up" },
94 :
95 : { FadeEffect_CLOSE_VERTICAL, "split-horizontal-in" },
96 : { FadeEffect_CLOSE_HORIZONTAL, "split-vertical-in" },
97 : { FadeEffect_OPEN_VERTICAL, "split-horizontal-out" },
98 : { FadeEffect_OPEN_HORIZONTAL, "split-vertical-out" },
99 :
100 : { FadeEffect_FADE_FROM_UPPERLEFT, "diagonal-squares-right-down" },
101 : { FadeEffect_FADE_FROM_UPPERRIGHT, "diagonal-squares-left-down" },
102 : { FadeEffect_FADE_FROM_LOWERLEFT, "diagonal-squares-right-up" },
103 : { FadeEffect_FADE_FROM_LOWERRIGHT, "diagonal-squares-left-up" },
104 :
105 : // OOo 1.x transitions not in OOo 2.x
106 : { FadeEffect_CLOCKWISE, "clock-wipe-twelve" },
107 : { FadeEffect_COUNTERCLOCKWISE, "reverse-clock-wipe-twelve" },
108 : { FadeEffect_SPIRALIN_LEFT, "spiral-wipe-top-left-clockwise" },
109 : { FadeEffect_SPIRALIN_RIGHT, "spiral-wipe-top-right-counter-clockwise" },
110 : { FadeEffect_SPIRALOUT_LEFT, "spiral-wipe-out-to-bottom-right-clockwise" },
111 : { FadeEffect_SPIRALOUT_RIGHT, "spiral-wipe-out-to-bottom-left-counter-clockwise" },
112 : { FadeEffect_WAVYLINE_FROM_LEFT, "snake-wipe-top-left-vertical" },
113 : { FadeEffect_WAVYLINE_FROM_TOP, "snake-wipe-top-left-horizontal" },
114 : { FadeEffect_WAVYLINE_FROM_RIGHT, "snake-wipe-bottom-right-vertical" },
115 : { FadeEffect_WAVYLINE_FROM_BOTTOM, "snake-wipe-bottom-right-horizontal" },
116 : { FadeEffect_STRETCH_FROM_LEFT, "wipe-right" }, // todo
117 : { FadeEffect_STRETCH_FROM_TOP, "wipe-down" }, // todo
118 : { FadeEffect_STRETCH_FROM_RIGHT, "wipe-left" }, // todo
119 : { FadeEffect_STRETCH_FROM_BOTTOM, "wipe-up" }, // todo
120 :
121 : // OOo 1.x not available transitions
122 :
123 : { FadeEffect_CLOCKWISE, "wheel-clockwise-2-spokes" },
124 : { FadeEffect_CLOCKWISE, "wheel-clockwise-3-spokes" },
125 : { FadeEffect_CLOCKWISE, "wheel-clockwise-4-spokes" },
126 : { FadeEffect_CLOCKWISE, "wheel-clockwise-8-spokes" },
127 :
128 : { FadeEffect_FADE_FROM_CENTER, "shape-circle" },
129 : { FadeEffect_FADE_FROM_CENTER, "shape-diamond" },
130 : { FadeEffect_FADE_FROM_CENTER, "shape-plus" },
131 :
132 : { FadeEffect_CLOCKWISE, "wedge" },
133 :
134 : { FadeEffect_DISSOLVE, "fade-through-black" },
135 :
136 : { FadeEffect_CLOCKWISE, "zoom-rotate-in" },
137 :
138 : { FadeEffect_HORIZONTAL_LINES, "comb-horizontal" },
139 : { FadeEffect_VERTICAL_LINES, "comb-vertical" },
140 :
141 : { FadeEffect_DISSOLVE, "fade-smoothly" },
142 :
143 : { FadeEffect_NONE, 0 }
144 : };
145 :
146 : /* todo
147 : cut cut (same as NONE?)
148 : cut-through-black cut toBlack
149 : wedge wedge
150 : */
151 :
152 1 : void EffectMigration::SetFadeEffect( SdPage* pPage, ::com::sun::star::presentation::FadeEffect eNewEffect)
153 : {
154 1 : deprecated_FadeEffect_conversion_table_entry* pEntry = deprecated_FadeEffect_conversion_table;
155 72 : while( (pEntry->meFadeEffect != FadeEffect_NONE) && (pEntry->meFadeEffect != eNewEffect) )
156 70 : pEntry++;
157 :
158 1 : if( pEntry->mpPresetId )
159 : {
160 0 : const OUString aPresetId( OUString::createFromAscii( pEntry->mpPresetId ) );
161 :
162 0 : const TransitionPresetList& rPresetList = TransitionPreset::getTransitionPresetList();
163 :
164 0 : TransitionPresetList::const_iterator aIt( rPresetList.begin());
165 0 : const TransitionPresetList::const_iterator aEndIt( rPresetList.end());
166 0 : for( ; aIt != aEndIt; ++aIt )
167 : {
168 0 : if( (*aIt)->getPresetId() == aPresetId)
169 : {
170 0 : pPage->setTransitionType( (*aIt)->getTransition() );
171 0 : pPage->setTransitionSubtype( (*aIt)->getSubtype() );
172 0 : pPage->setTransitionDirection( (*aIt)->getDirection() );
173 0 : pPage->setTransitionFadeColor( (*aIt)->getFadeColor() );
174 0 : break;
175 : }
176 0 : }
177 : }
178 : else
179 : {
180 1 : pPage->setTransitionType( 0 );
181 1 : pPage->setTransitionSubtype( 0 );
182 1 : pPage->setTransitionDirection( 0 );
183 1 : pPage->setTransitionFadeColor( 0 );
184 : }
185 1 : }
186 :
187 2 : FadeEffect EffectMigration::GetFadeEffect( const SdPage* pPage )
188 : {
189 2 : const TransitionPresetList & rPresetList = TransitionPreset::getTransitionPresetList();
190 2 : TransitionPresetList::const_iterator aIt( rPresetList.begin());
191 2 : const TransitionPresetList::const_iterator aEndIt( rPresetList.end());
192 164 : for( ; aIt != aEndIt; ++aIt )
193 : {
194 324 : if( ( (*aIt)->getTransition() == pPage->getTransitionType() ) &&
195 0 : ( (*aIt)->getSubtype() == pPage->getTransitionSubtype() ) &&
196 162 : ( (*aIt)->getDirection() == pPage->getTransitionDirection() ) &&
197 0 : ( (*aIt)->getFadeColor() == pPage->getTransitionFadeColor() ) )
198 : {
199 0 : const OUString& aPresetId = (*aIt)->getPresetId();
200 :
201 0 : deprecated_FadeEffect_conversion_table_entry* pEntry = deprecated_FadeEffect_conversion_table;
202 0 : while( (pEntry->meFadeEffect != FadeEffect_NONE) && (!aPresetId.equalsAscii( pEntry->mpPresetId ) ) )
203 0 : pEntry++;
204 :
205 0 : return pEntry->meFadeEffect;
206 : }
207 : }
208 2 : return FadeEffect_NONE;
209 : }
210 :
211 : struct deprecated_AnimationEffect_conversion_table_entry
212 : {
213 : AnimationEffect meEffect;
214 : const sal_Char* mpPresetId;
215 : const sal_Char* mpPresetSubType;
216 : }
217 : deprecated_AnimationEffect_conversion_table[] =
218 : {
219 : // OOo 1.x entrance effects
220 : { AnimationEffect_APPEAR, "ooo-entrance-appear",0 },
221 :
222 : { AnimationEffect_FADE_TO_CENTER, "ooo-entrance-box","in" },
223 : { AnimationEffect_FADE_FROM_CENTER, "ooo-entrance-box","out" },
224 :
225 : { AnimationEffect_VERTICAL_CHECKERBOARD, "ooo-entrance-checkerboard","downward" },
226 : { AnimationEffect_HORIZONTAL_CHECKERBOARD, "ooo-entrance-checkerboard","across" },
227 :
228 : { AnimationEffect_FADE_FROM_UPPERLEFT, "ooo-entrance-diagonal-squares","right-to-bottom" },
229 : { AnimationEffect_FADE_FROM_UPPERRIGHT, "ooo-entrance-diagonal-squares","left-to-bottom" },
230 : { AnimationEffect_FADE_FROM_LOWERLEFT, "ooo-entrance-diagonal-squares","right-to-top" },
231 : { AnimationEffect_FADE_FROM_LOWERRIGHT, "ooo-entrance-diagonal-squares","left-to-top" },
232 :
233 : { AnimationEffect_DISSOLVE, "ooo-entrance-dissolve-in",0 },
234 :
235 : { AnimationEffect_MOVE_FROM_LEFT, "ooo-entrance-fly-in","from-left" },
236 : { AnimationEffect_MOVE_FROM_TOP, "ooo-entrance-fly-in","from-top" },
237 : { AnimationEffect_MOVE_FROM_RIGHT, "ooo-entrance-fly-in","from-right" },
238 : { AnimationEffect_MOVE_FROM_BOTTOM, "ooo-entrance-fly-in","from-bottom" },
239 : { AnimationEffect_MOVE_FROM_UPPERLEFT, "ooo-entrance-fly-in","from-top-left" },
240 : { AnimationEffect_MOVE_FROM_UPPERRIGHT, "ooo-entrance-fly-in","from-top-right" },
241 : { AnimationEffect_MOVE_FROM_LOWERRIGHT, "ooo-entrance-fly-in","from-bottom-right" },
242 : { AnimationEffect_MOVE_FROM_LOWERLEFT, "ooo-entrance-fly-in","from-bottom-left" },
243 :
244 : { AnimationEffect_MOVE_FROM_BOTTOM, "ooo-entrance-fly-in-slow", "from-bottom" },
245 : { AnimationEffect_MOVE_FROM_LEFT, "ooo-entrance-fly-in-slow", "from-left" },
246 : { AnimationEffect_MOVE_FROM_RIGHT, "ooo-entrance-fly-in-slow", "from-right" },
247 : { AnimationEffect_MOVE_FROM_TOP, "ooo-entrance-fly-in-slow", "from-top" },
248 :
249 : { AnimationEffect_MOVE_SHORT_FROM_LEFT, "ooo-entrance-peek-in","from-left" },
250 : { AnimationEffect_MOVE_SHORT_FROM_TOP, "ooo-entrance-peek-in","from-top" },
251 : { AnimationEffect_MOVE_SHORT_FROM_RIGHT, "ooo-entrance-peek-in","from-right" },
252 : { AnimationEffect_MOVE_SHORT_FROM_BOTTOM, "ooo-entrance-peek-in","from-bottom" },
253 :
254 : { AnimationEffect_VERTICAL_LINES, "ooo-entrance-random-bars","horizontal" },
255 : { AnimationEffect_HORIZONTAL_LINES, "ooo-entrance-random-bars","vertical" },
256 :
257 : { AnimationEffect_RANDOM, "ooo-entrance-random",0 },
258 :
259 : { AnimationEffect_CLOSE_VERTICAL, "ooo-entrance-split","horizontal-in" },
260 : { AnimationEffect_CLOSE_HORIZONTAL, "ooo-entrance-split","vertical-in" },
261 : { AnimationEffect_OPEN_VERTICAL, "ooo-entrance-split","horizontal-out" },
262 : { AnimationEffect_OPEN_HORIZONTAL, "ooo-entrance-split","vertical-out" },
263 :
264 : { AnimationEffect_VERTICAL_STRIPES, "ooo-entrance-venetian-blinds","horizontal" },
265 : { AnimationEffect_HORIZONTAL_STRIPES, "ooo-entrance-venetian-blinds","vertical" },
266 :
267 : { AnimationEffect_FADE_FROM_LEFT, "ooo-entrance-wipe","from-left" },
268 : { AnimationEffect_FADE_FROM_TOP, "ooo-entrance-wipe","from-bottom" },
269 : { AnimationEffect_FADE_FROM_RIGHT, "ooo-entrance-wipe","from-right" },
270 : { AnimationEffect_FADE_FROM_BOTTOM, "ooo-entrance-wipe","from-top" },
271 :
272 : { AnimationEffect_HORIZONTAL_ROTATE, "ooo-entrance-swivel","vertical" },
273 : { AnimationEffect_VERTICAL_ROTATE, "ooo-entrance-swivel","horizontal" },
274 :
275 : { AnimationEffect_STRETCH_FROM_LEFT, "ooo-entrance-stretchy","from-left" },
276 : { AnimationEffect_STRETCH_FROM_UPPERLEFT, "ooo-entrance-stretchy","from-top-left" },
277 : { AnimationEffect_STRETCH_FROM_TOP, "ooo-entrance-stretchy","from-top" },
278 : { AnimationEffect_STRETCH_FROM_UPPERRIGHT, "ooo-entrance-stretchy","from-top-right" },
279 : { AnimationEffect_STRETCH_FROM_RIGHT, "ooo-entrance-stretchy","from-right" },
280 : { AnimationEffect_STRETCH_FROM_LOWERRIGHT, "ooo-entrance-stretchy","from-bottom-right" },
281 : { AnimationEffect_STRETCH_FROM_BOTTOM, "ooo-entrance-stretchy","from-bottom" },
282 : { AnimationEffect_STRETCH_FROM_LOWERLEFT, "ooo-entrance-stretchy","from-bottom-left" },
283 :
284 : { AnimationEffect_HORIZONTAL_STRETCH, "ooo-entrance-expand", 0 },
285 :
286 : { AnimationEffect_CLOCKWISE, "ooo-entrance-wheel","1" },
287 : { AnimationEffect_COUNTERCLOCKWISE, "ooo-entrance-clock-wipe","counter-clockwise" },
288 :
289 : { AnimationEffect_SPIRALIN_LEFT, "ooo-entrance-spiral-wipe", "from-top-left-clockwise" },
290 : { AnimationEffect_SPIRALIN_RIGHT, "ooo-entrance-spiral-wipe", "from-top-right-counter-clockwise" },
291 : { AnimationEffect_SPIRALOUT_LEFT, "ooo-entrance-spiral-wipe", "from-center-clockwise" },
292 : { AnimationEffect_SPIRALOUT_RIGHT, "ooo-entrance-spiral-wipe", "from-center-counter-clockwise" },
293 :
294 : { AnimationEffect_WAVYLINE_FROM_LEFT, "ooo-entrance-snake-wipe","from-top-left-vertical" },
295 : { AnimationEffect_WAVYLINE_FROM_TOP, "ooo-entrance-snake-wipe","from-top-left-horizontal" },
296 : { AnimationEffect_WAVYLINE_FROM_RIGHT, "ooo-entrance-snake-wipe","from-bottom-right-vertical" },
297 : { AnimationEffect_WAVYLINE_FROM_BOTTOM, "ooo-entrance-snake-wipe","from-bottom-right-horizontal" },
298 :
299 : // ooo 1.x exit effects
300 : { AnimationEffect_HIDE, "ooo-exit-disappear",0 },
301 : { AnimationEffect_MOVE_TO_LEFT, "ooo-exit-fly-out", "from-right" },
302 : { AnimationEffect_MOVE_TO_TOP, "ooo-exit-fly-out", "from-bottom" },
303 : { AnimationEffect_MOVE_TO_RIGHT, "ooo-exit-fly-out", "from-left" },
304 : { AnimationEffect_MOVE_TO_BOTTOM, "ooo-exit-fly-out", "from-top" },
305 : { AnimationEffect_MOVE_TO_UPPERLEFT, "ooo-exit-fly-out", "from-top-right" },
306 : { AnimationEffect_MOVE_TO_UPPERRIGHT, "ooo-exit-fly-out", "from-top-left" },
307 : { AnimationEffect_MOVE_TO_LOWERRIGHT, "ooo-exit-fly-out", "from-bottom-left" },
308 : { AnimationEffect_MOVE_TO_LOWERLEFT, "ooo-exit-fly-out", "from-bottom-right" },
309 : { AnimationEffect_MOVE_SHORT_TO_LEFT, "ooo-exit-peek-out", "from-right" },
310 : { AnimationEffect_MOVE_SHORT_TO_UPPERLEFT, "ooo-exit-peek-out", "from-right" },
311 : { AnimationEffect_MOVE_SHORT_TO_TOP, "ooo-exit-peek-out", "from-bottom" },
312 : { AnimationEffect_MOVE_SHORT_TO_UPPERRIGHT, "ooo-exit-peek-out", "from-bottom" },
313 : { AnimationEffect_MOVE_SHORT_TO_RIGHT, "ooo-exit-peek-out", "from-left" },
314 : { AnimationEffect_MOVE_SHORT_TO_LOWERRIGHT, "ooo-exit-peek-out","from-left" },
315 : { AnimationEffect_MOVE_SHORT_TO_BOTTOM, "ooo-exit-peek-out", "from-top" },
316 : { AnimationEffect_MOVE_SHORT_TO_LOWERLEFT, "ooo-exit-peek-out", "from-top" },
317 :
318 : // no matching in OOo 2.x
319 : { AnimationEffect_MOVE_SHORT_FROM_UPPERLEFT, "ooo-entrance-peek-in","from-left" },
320 : { AnimationEffect_MOVE_SHORT_FROM_UPPERRIGHT, "ooo-entrance-peek-in","from-top" },
321 : { AnimationEffect_MOVE_SHORT_FROM_LOWERRIGHT, "ooo-entrance-peek-in","from-right" },
322 : { AnimationEffect_MOVE_SHORT_FROM_LOWERLEFT, "ooo-entrance-peek-in","from-bottom" },
323 : { AnimationEffect_LASER_FROM_LEFT, "ooo-entrance-fly-in","from-left" },
324 : { AnimationEffect_LASER_FROM_TOP, "ooo-entrance-fly-in","from-top" },
325 : { AnimationEffect_LASER_FROM_RIGHT, "ooo-entrance-fly-in","from-right" },
326 : { AnimationEffect_LASER_FROM_BOTTOM, "ooo-entrance-fly-in","from-bottom" },
327 : { AnimationEffect_LASER_FROM_UPPERLEFT, "ooo-entrance-fly-in","from-top-left" },
328 : { AnimationEffect_LASER_FROM_UPPERRIGHT, "ooo-entrance-fly-in","from-top-right" },
329 : { AnimationEffect_LASER_FROM_LOWERLEFT, "ooo-entrance-fly-in","from-bottom-left" },
330 : { AnimationEffect_LASER_FROM_LOWERRIGHT, "ooo-entrance-fly-in","from-bottom-right" },
331 :
332 : // no matching in OOo 1.x
333 :
334 : { AnimationEffect_FADE_TO_CENTER, "ooo-entrance-circle", "in" },
335 : { AnimationEffect_FADE_FROM_CENTER, "ooo-entrance-circle", "out" },
336 : { AnimationEffect_FADE_TO_CENTER, "ooo-entrance-diamond", "in" },
337 : { AnimationEffect_FADE_FROM_CENTER, "ooo-entrance-diamond", "out" },
338 : { AnimationEffect_FADE_TO_CENTER, "ooo-entrance-plus", "in" },
339 : { AnimationEffect_FADE_FROM_CENTER, "ooo-entrance-plus", "out" },
340 : { AnimationEffect_CLOCKWISE, "ooo-entrance-wedge", 0 },
341 : { AnimationEffect_CLOCKWISE, "ooo-entrance-wheel", "2" },
342 : { AnimationEffect_CLOCKWISE, "ooo-entrance-wheel", "3" },
343 : { AnimationEffect_CLOCKWISE, "ooo-entrance-wheel", "4" },
344 : { AnimationEffect_CLOCKWISE, "ooo-entrance-wheel", "8" },
345 :
346 : { AnimationEffect_MOVE_FROM_RIGHT, "ooo-entrance-boomerang", 0 },
347 : { AnimationEffect_MOVE_FROM_UPPERRIGHT, "ooo-entrance-bounce", 0 },
348 : { AnimationEffect_MOVE_FROM_BOTTOM, "ooo-entrance-curve-up", 0 },
349 : { AnimationEffect_MOVE_FROM_TOP, "ooo-entrance-float", 0 },
350 : { AnimationEffect_MOVE_FROM_LEFT, "ooo-entrance-glide", 0 },
351 : { AnimationEffect_MOVE_FROM_BOTTOM, "ooo-entrance-magnify", 0 },
352 : { AnimationEffect_HORIZONTAL_ROTATE, "ooo-entrance-pinwheel", 0 },
353 : { AnimationEffect_MOVE_FROM_LEFT, "ooo-entrance-breaks", 0 },
354 : { AnimationEffect_MOVE_FROM_LEFT, "ooo-entrance-sling", 0 },
355 : { AnimationEffect_MOVE_FROM_LEFT, "ooo-entrance-spiral-in", 0 },
356 : { AnimationEffect_MOVE_FROM_LEFT, "ooo-entrance-thread", 0 },
357 : { AnimationEffect_MOVE_FROM_BOTTOM, "ooo-entrance-ascend", 0 },
358 : { AnimationEffect_MOVE_FROM_BOTTOM, "ooo-entrance-center-revolve", 0 },
359 : { AnimationEffect_APPEAR, "ooo-entrance-compress", 0 },
360 : { AnimationEffect_MOVE_SHORT_FROM_TOP, "ooo-entrance-descend", 0 },
361 : { AnimationEffect_MOVE_SHORT_FROM_LEFT, "ooo-entrance-ease-in", 0 },
362 : { AnimationEffect_MOVE_FROM_BOTTOM, "ooo-entrance-rise-up", 0 },
363 : { AnimationEffect_HORIZONTAL_ROTATE, "ooo-entrance-spin-in", 0 },
364 : { AnimationEffect_STRETCH_FROM_LEFT, "ooo-entrance-stretchy", "across" },
365 : { AnimationEffect_STRETCH_FROM_TOP, "ooo-entrance-stretchy", "downward" },
366 :
367 : { AnimationEffect_FADE_FROM_CENTER, "ooo-entrance-zoom","in" },
368 : { AnimationEffect_FADE_FROM_CENTER, "ooo-entrance-zoom","in-slightly" },
369 : { AnimationEffect_FADE_FROM_CENTER, "ooo-entrance-zoom","in-from-screen-center" },
370 : { AnimationEffect_FADE_TO_CENTER, "ooo-entrance-zoom","out" },
371 : { AnimationEffect_FADE_TO_CENTER, "ooo-entrance-zoom","out-slightly" },
372 : { AnimationEffect_FADE_TO_CENTER, "ooo-entrance-zoom","out-from-screen-center" },
373 :
374 : { AnimationEffect_DISSOLVE, "ooo-entrance-fade-in", 0 },
375 : { AnimationEffect_DISSOLVE, "ooo-entrance-fade-in-and-zoom", 0 },
376 : { AnimationEffect_DISSOLVE, "ooo-entrance-fade-in-and-swivel", 0 },
377 :
378 : // still open (no matching effect: AnimationEffect_ZOOM_IN_FROM_*,
379 : // AnimationEffect_ZOOM_OUT_FROM_*, AnimationEffect_PATH
380 :
381 : { AnimationEffect_NONE, 0, 0 }
382 : };
383 :
384 2 : EffectSequence::iterator ImplFindEffect( MainSequencePtr& pMainSequence, const Reference< XShape >& rShape, sal_Int16 nSubItem )
385 : {
386 2 : EffectSequence::iterator aIter;
387 :
388 2 : for( aIter = pMainSequence->getBegin(); aIter != pMainSequence->getEnd(); ++aIter )
389 : {
390 0 : CustomAnimationEffectPtr pEffect( (*aIter) );
391 0 : if( (pEffect->getTargetShape() == rShape) && (pEffect->getTargetSubItem() == nSubItem) )
392 0 : break;
393 0 : }
394 :
395 2 : return aIter;
396 : }
397 :
398 0 : static bool implIsInsideGroup( SdrObject* pObj )
399 : {
400 0 : return pObj && pObj->GetObjList() && pObj->GetObjList()->GetUpList();
401 : }
402 :
403 0 : void EffectMigration::SetAnimationEffect( SvxShape* pShape, AnimationEffect eEffect )
404 : {
405 : DBG_ASSERT( pShape && pShape->GetSdrObject() && pShape->GetSdrObject()->GetPage(),
406 : "sd::EffectMigration::SetAnimationEffect(), invalid argument!" );
407 0 : if( !pShape || !pShape->GetSdrObject() || !pShape->GetSdrObject()->GetPage() )
408 0 : return;
409 :
410 0 : SdrObject* pObj = pShape->GetSdrObject();
411 0 : if( implIsInsideGroup( pObj ) )
412 0 : return;
413 :
414 0 : OUString aPresetId;
415 0 : OUString aPresetSubType;
416 :
417 0 : if( !ConvertAnimationEffect( eEffect, aPresetId, aPresetSubType ) )
418 : {
419 : OSL_FAIL( "sd::EffectMigration::SetAnimationEffect(), no mapping for given AnimationEffect value" );
420 0 : return;
421 : }
422 :
423 0 : const CustomAnimationPresets& rPresets = CustomAnimationPresets::getCustomAnimationPresets();
424 :
425 0 : CustomAnimationPresetPtr pPreset( rPresets.getEffectDescriptor( aPresetId ) );
426 0 : sd::MainSequencePtr pMainSequence = static_cast<SdPage*>(pObj->GetPage())->getMainSequence();
427 :
428 0 : if( pPreset.get() && pMainSequence.get() )
429 : {
430 0 : const Reference< XShape > xShape( pShape );
431 :
432 0 : EffectSequence::iterator aIterOnlyBackground( ImplFindEffect( pMainSequence, xShape, ShapeAnimationSubType::ONLY_BACKGROUND ) );
433 0 : EffectSequence::iterator aIterAsWhole( ImplFindEffect( pMainSequence, xShape, ShapeAnimationSubType::AS_WHOLE ) );
434 0 : const EffectSequence::iterator aEnd( pMainSequence->getEnd() );
435 :
436 0 : bool bEffectCreated = false;
437 :
438 0 : if( (aIterOnlyBackground == aEnd) && (aIterAsWhole == aEnd) )
439 : {
440 : // check if there is already an text effect for this shape
441 0 : EffectSequence::iterator aIterOnlyText( ImplFindEffect( pMainSequence, xShape, ShapeAnimationSubType::ONLY_TEXT ) );
442 0 : if( aIterOnlyText != aEnd )
443 : {
444 : // check if this is an animation text group
445 0 : sal_Int32 nGroupId = (*aIterOnlyText)->getGroupId();
446 0 : if( nGroupId >= 0 )
447 : {
448 0 : CustomAnimationTextGroupPtr pGroup = pMainSequence->findGroup( nGroupId );
449 0 : if( pGroup.get() )
450 : {
451 : // add an effect to animate the shape
452 0 : pMainSequence->setAnimateForm( pGroup, true );
453 :
454 : // find this effect
455 0 : EffectSequence::iterator aIter( ImplFindEffect( pMainSequence, xShape, ShapeAnimationSubType::ONLY_BACKGROUND ) );
456 :
457 0 : if( aIter != aEnd )
458 : {
459 0 : if( ((*aIter)->getPresetId() != aPresetId) ||
460 0 : ((*aIter)->getPresetSubType() != aPresetSubType) )
461 : {
462 0 : (*aIter)->replaceNode( pPreset->create( aPresetSubType ) );
463 0 : pMainSequence->rebuild();
464 0 : bEffectCreated = true;
465 : }
466 : }
467 0 : }
468 : }
469 : }
470 :
471 0 : if( !bEffectCreated )
472 : {
473 : // if there is not yet an effect that target this shape, we generate one
474 : // we insert the shape effect before it
475 0 : Reference< XAnimationNode > xNode( pPreset->create( aPresetSubType ) );
476 : DBG_ASSERT( xNode.is(), "EffectMigration::SetAnimationEffect(), could not create preset!" );
477 0 : if( xNode.is() )
478 : {
479 0 : CustomAnimationEffectPtr pEffect( new CustomAnimationEffect( xNode ) );
480 0 : pEffect->setTarget( makeAny( xShape ) );
481 0 : SdPage* pPage = dynamic_cast< SdPage* >( pObj->GetPage() );
482 0 : const bool bManual = (pPage == 0) || (pPage->GetPresChange() == PRESCHANGE_MANUAL);
483 0 : if( !bManual )
484 0 : pEffect->setNodeType( EffectNodeType::AFTER_PREVIOUS );
485 :
486 0 : pMainSequence->append( pEffect );
487 :
488 0 : if( ( pObj->GetObjInventor() == SdrInventor ) && ( pObj->GetObjIdentifier() == OBJ_OUTLINETEXT ) )
489 : {
490 : // special case for outline text, effects are always mapped to text group effect
491 0 : pMainSequence->
492 0 : createTextGroup( pEffect, 10, bManual ? -1 : 0.0, sal_False, sal_False );
493 0 : }
494 0 : }
495 : }
496 : }
497 : else
498 : {
499 : // if there is already an effect targeting this shape
500 : // just replace it
501 0 : CustomAnimationEffectPtr pEffect;
502 0 : if( aIterAsWhole != aEnd )
503 : {
504 0 : pEffect = (*aIterAsWhole);
505 : }
506 : else
507 : {
508 0 : pEffect = (*aIterOnlyBackground);
509 : }
510 :
511 0 : if( pEffect.get() )
512 : {
513 0 : if( (pEffect->getPresetId() != aPresetId) ||
514 0 : (pEffect->getPresetSubType() != aPresetSubType) )
515 : {
516 0 : pMainSequence->replace( pEffect, pPreset, aPresetSubType );
517 : }
518 0 : }
519 0 : }
520 0 : }
521 : }
522 :
523 : // --------------------------------------------------------------------
524 :
525 6 : AnimationEffect EffectMigration::GetAnimationEffect( SvxShape* pShape )
526 : {
527 6 : OUString aPresetId;
528 12 : OUString aPresetSubType;
529 :
530 6 : SdrObject* pObj = pShape->GetSdrObject();
531 12 : sd::MainSequencePtr pMainSequence = static_cast<SdPage*>(pObj->GetPage())->getMainSequence();
532 :
533 6 : if( pMainSequence.get() )
534 : {
535 6 : const Reference< XShape > xShape( pShape );
536 :
537 6 : EffectSequence::iterator aIter;
538 :
539 6 : for( aIter = pMainSequence->getBegin(); aIter != pMainSequence->getEnd(); ++aIter )
540 : {
541 0 : CustomAnimationEffectPtr pEffect( (*aIter) );
542 0 : if( pEffect->getTargetShape() == xShape )
543 : {
544 0 : if( (pEffect->getTargetSubItem() == ShapeAnimationSubType::ONLY_BACKGROUND) ||
545 0 : (pEffect->getTargetSubItem() == ShapeAnimationSubType::AS_WHOLE))
546 : {
547 0 : if( pEffect->getDuration() != 0.1 ) // ignore appear effects created from old text effect import
548 : {
549 0 : aPresetId = (*aIter)->getPresetId();
550 0 : aPresetSubType = (*aIter)->getPresetSubType();
551 0 : break;
552 : }
553 : }
554 : }
555 6 : }
556 : }
557 :
558 : // now find old effect
559 6 : AnimationEffect eEffect = AnimationEffect_NONE;
560 :
561 6 : if( !ConvertPreset( aPresetId, &aPresetSubType, eEffect ) )
562 0 : ConvertPreset( aPresetId, 0, eEffect );
563 :
564 12 : return eEffect;
565 : }
566 :
567 :
568 : // --------------------------------------------------------------------
569 :
570 0 : void EffectMigration::SetTextAnimationEffect( SvxShape* pShape, AnimationEffect eEffect )
571 : {
572 : DBG_ASSERT( pShape && pShape->GetSdrObject() && pShape->GetSdrObject()->GetPage(),
573 : "sd::EffectMigration::SetAnimationEffect(), invalid argument!" );
574 0 : if( !pShape || !pShape->GetSdrObject() || !pShape->GetSdrObject()->GetPage() )
575 0 : return;
576 :
577 0 : SdrObject* pObj = pShape->GetSdrObject();
578 0 : if( implIsInsideGroup( pObj ) )
579 0 : return;
580 :
581 : // first map the deprecated AnimationEffect to a preset and subtype
582 0 : OUString aPresetId;
583 0 : OUString aPresetSubType;
584 :
585 0 : if( !ConvertAnimationEffect( eEffect, aPresetId, aPresetSubType ) )
586 : {
587 : OSL_FAIL( "sd::EffectMigration::SetAnimationEffect(), no mapping for given AnimationEffect value" );
588 0 : return;
589 : }
590 :
591 0 : SdrTextObj* pTextObj = dynamic_cast< SdrTextObj* >( pObj );
592 :
593 : // ignore old text effects on shape without text
594 0 : if( (pTextObj == 0) || (!pTextObj->HasText()) )
595 0 : return;
596 :
597 0 : const CustomAnimationPresets& rPresets = CustomAnimationPresets::getCustomAnimationPresets();
598 :
599 : // create an effect from this preset
600 0 : CustomAnimationPresetPtr pPreset( rPresets.getEffectDescriptor( aPresetId ) );
601 :
602 0 : sd::MainSequencePtr pMainSequence = static_cast<SdPage*>(pObj->GetPage())->getMainSequence();
603 :
604 0 : if( pPreset.get() && pMainSequence.get() )
605 : {
606 0 : const Reference< XShape > xShape( pShape );
607 :
608 0 : EffectSequence::iterator aIterOnlyText( ImplFindEffect( pMainSequence, xShape, ShapeAnimationSubType::ONLY_TEXT ) );
609 0 : const EffectSequence::iterator aEnd( pMainSequence->getEnd() );
610 :
611 0 : CustomAnimationTextGroupPtr pGroup;
612 :
613 : // is there already an animation text group for this shape?
614 0 : if( aIterOnlyText != aEnd )
615 : {
616 0 : const sal_Int32 nGroupId = (*aIterOnlyText)->getGroupId();
617 0 : if( nGroupId >= 0 )
618 0 : pGroup = pMainSequence->findGroup( nGroupId );
619 : }
620 :
621 : // if there is not yet a group, create it
622 0 : if( pGroup.get() == 0 )
623 : {
624 0 : CustomAnimationEffectPtr pShapeEffect;
625 :
626 0 : EffectSequence::iterator aIterOnlyBackground( ImplFindEffect( pMainSequence, xShape, ShapeAnimationSubType::ONLY_BACKGROUND ) );
627 0 : if( aIterOnlyBackground != aEnd )
628 : {
629 0 : pShapeEffect = (*aIterOnlyBackground);
630 : }
631 : else
632 : {
633 0 : EffectSequence::iterator aIterAsWhole( ImplFindEffect( pMainSequence, xShape, ShapeAnimationSubType::AS_WHOLE ) );
634 0 : if( aIterAsWhole != aEnd )
635 : {
636 0 : pShapeEffect = (*aIterAsWhole);
637 : }
638 : else
639 : {
640 0 : OUString aEmpty;
641 0 : CustomAnimationPresetPtr pShapePreset( rPresets.getEffectDescriptor( "ooo-entrance-appear" ) );
642 :
643 0 : Reference< XAnimationNode > xNode( pPreset->create( aEmpty ) );
644 : DBG_ASSERT( xNode.is(), "EffectMigration::SetTextAnimationEffect(), could not create preset!" );
645 0 : if( xNode.is() )
646 : {
647 0 : pShapeEffect.reset( new CustomAnimationEffect( xNode ) );
648 0 : pShapeEffect->setTarget( makeAny( xShape ) );
649 0 : pShapeEffect->setDuration( 0.1 );
650 0 : pMainSequence->append( pShapeEffect );
651 :
652 0 : SdPage* pPage = dynamic_cast< SdPage* >( pObj->GetPage() );
653 0 : if( pPage && pPage->GetPresChange() != PRESCHANGE_MANUAL )
654 0 : pShapeEffect->setNodeType( EffectNodeType::AFTER_PREVIOUS );
655 0 : }
656 : }
657 : }
658 :
659 0 : if( pShapeEffect.get() )
660 : {
661 0 : SdPage* pPage = dynamic_cast< SdPage* >( pObj->GetPage() );
662 0 : const bool bManual = (pPage == 0) || (pPage->GetPresChange() == PRESCHANGE_MANUAL);
663 :
664 : // now create effects for each paragraph
665 0 : pGroup =
666 0 : pMainSequence->
667 0 : createTextGroup( pShapeEffect, 10, bManual ? -1 : 0.0, sal_True, sal_False );
668 0 : }
669 : }
670 :
671 0 : if( pGroup.get() != 0 )
672 : {
673 0 : const bool bLaserEffect = (eEffect >= AnimationEffect_LASER_FROM_LEFT) && (eEffect <= AnimationEffect_LASER_FROM_LOWERRIGHT);
674 :
675 : // now we have a group, so check if all effects are same as we like to have them
676 0 : const EffectSequence& rEffects = pGroup->getEffects();
677 :
678 0 : EffectSequence::const_iterator aIter;
679 0 : for( aIter = rEffects.begin(); aIter != rEffects.end(); ++aIter )
680 : {
681 : // only work on paragraph targets
682 0 : if( (*aIter)->getTarget().getValueType() == ::getCppuType((const ParagraphTarget*)0) )
683 : {
684 0 : if( ((*aIter)->getPresetId() != aPresetId) ||
685 0 : ((*aIter)->getPresetSubType() != aPresetSubType) )
686 : {
687 0 : (*aIter)->replaceNode( pPreset->create( aPresetSubType ) );
688 : }
689 :
690 0 : if( bLaserEffect )
691 : {
692 0 : (*aIter)->setIterateType( TextAnimationType::BY_LETTER );
693 0 : (*aIter)->setIterateInterval( 0.5 );// TODO:
694 : // Determine
695 : // interval
696 : // according
697 : // to
698 : // total
699 : // effect
700 : // duration
701 : }
702 : }
703 : }
704 : }
705 0 : pMainSequence->rebuild();
706 0 : }
707 : }
708 :
709 : // --------------------------------------------------------------------
710 :
711 2 : AnimationEffect EffectMigration::GetTextAnimationEffect( SvxShape* pShape )
712 : {
713 2 : OUString aPresetId;
714 4 : OUString aPresetSubType;
715 :
716 2 : SdrObject* pObj = pShape->GetSdrObject();
717 2 : if( pObj )
718 : {
719 2 : sd::MainSequencePtr pMainSequence = static_cast<SdPage*>(pObj->GetPage())->getMainSequence();
720 :
721 2 : if( pMainSequence.get() )
722 : {
723 2 : const Reference< XShape > xShape( pShape );
724 2 : EffectSequence::iterator aIter( ImplFindEffect( pMainSequence, xShape, ShapeAnimationSubType::ONLY_TEXT ) );
725 2 : if( aIter != pMainSequence->getEnd() )
726 : {
727 0 : aPresetId = (*aIter)->getPresetId();
728 0 : aPresetSubType = (*aIter)->getPresetSubType();
729 2 : }
730 2 : }
731 : }
732 :
733 : // now find old effect
734 2 : AnimationEffect eEffect = AnimationEffect_NONE;
735 :
736 2 : if( !ConvertPreset( aPresetId, &aPresetSubType, eEffect ) )
737 0 : ConvertPreset( aPresetId, 0, eEffect );
738 :
739 4 : return eEffect;
740 : }
741 :
742 : // --------------------------------------------------------------------
743 :
744 8 : bool EffectMigration::ConvertPreset( const OUString& rPresetId, const OUString* pPresetSubType, AnimationEffect& rEffect )
745 : {
746 8 : rEffect = AnimationEffect_NONE;
747 8 : if( !rPresetId.isEmpty() )
748 : {
749 : // first try a match for preset id and subtype
750 0 : deprecated_AnimationEffect_conversion_table_entry* p = deprecated_AnimationEffect_conversion_table;
751 0 : while( p->mpPresetId )
752 : {
753 0 : if( rPresetId.equalsAscii( p->mpPresetId ) &&
754 0 : (( p->mpPresetSubType == 0 ) ||
755 0 : ( pPresetSubType == 0) ||
756 0 : ( pPresetSubType->equalsAscii( p->mpPresetSubType )) ) )
757 : {
758 0 : rEffect = p->meEffect;
759 0 : return true;
760 : }
761 0 : p++;
762 : }
763 0 : return false;
764 : }
765 : else
766 : {
767 : // empty preset id means AnimationEffect_NONE
768 8 : return true;
769 : }
770 : }
771 :
772 : // --------------------------------------------------------------------
773 :
774 0 : bool EffectMigration::ConvertAnimationEffect( const AnimationEffect& rEffect, OUString& rPresetId, OUString& rPresetSubType )
775 : {
776 0 : deprecated_AnimationEffect_conversion_table_entry* p = deprecated_AnimationEffect_conversion_table;
777 0 : while( p->mpPresetId )
778 : {
779 0 : if( p->meEffect == rEffect )
780 : {
781 0 : rPresetId = OUString::createFromAscii( p->mpPresetId );
782 0 : rPresetSubType = OUString::createFromAscii( p->mpPresetSubType );
783 0 : return true;
784 : }
785 0 : p++;
786 : }
787 :
788 0 : return false;
789 : }
790 :
791 : // --------------------------------------------------------------------
792 :
793 0 : double EffectMigration::ConvertAnimationSpeed( AnimationSpeed eSpeed )
794 : {
795 : double fDuration;
796 0 : switch( eSpeed )
797 : {
798 0 : case AnimationSpeed_SLOW: fDuration = 2.0; break;
799 0 : case AnimationSpeed_FAST: fDuration = 0.5; break;
800 : default:
801 0 : fDuration = 1.0; break;
802 : }
803 0 : return fDuration;
804 : }
805 : // --------------------------------------------------------------------
806 :
807 0 : void EffectMigration::SetAnimationSpeed( SvxShape* pShape, AnimationSpeed eSpeed )
808 : {
809 : DBG_ASSERT( pShape && pShape->GetSdrObject() && pShape->GetSdrObject()->GetPage(),
810 : "sd::EffectMigration::SetAnimationEffect(), invalid argument!" );
811 0 : if( !pShape || !pShape->GetSdrObject() || !pShape->GetSdrObject()->GetPage() )
812 0 : return;
813 :
814 0 : SdrObject* pObj = pShape->GetSdrObject();
815 0 : if( implIsInsideGroup( pObj ) )
816 0 : return;
817 :
818 0 : double fDuration = ConvertAnimationSpeed( eSpeed );
819 :
820 0 : sd::MainSequencePtr pMainSequence = static_cast<SdPage*>(pObj->GetPage())->getMainSequence();
821 :
822 0 : const Reference< XShape > xShape( pShape );
823 :
824 0 : EffectSequence::iterator aIter;
825 0 : bool bNeedRebuild = false;
826 :
827 0 : for( aIter = pMainSequence->getBegin(); aIter != pMainSequence->getEnd(); ++aIter )
828 : {
829 0 : CustomAnimationEffectPtr pEffect( (*aIter) );
830 0 : if( pEffect->getTargetShape() == xShape )
831 : {
832 0 : if( pEffect->getDuration() != 0.1 )
833 0 : pEffect->setDuration( fDuration );
834 0 : bNeedRebuild = true;
835 : }
836 0 : }
837 :
838 0 : if( bNeedRebuild )
839 0 : pMainSequence->rebuild();
840 : }
841 :
842 : // --------------------------------------------------------------------
843 :
844 2 : AnimationSpeed EffectMigration::GetAnimationSpeed( SvxShape* pShape )
845 : {
846 2 : SdrObject* pObj = pShape->GetSdrObject();
847 2 : sd::MainSequencePtr pMainSequence = static_cast<SdPage*>(pObj->GetPage())->getMainSequence();
848 :
849 4 : const Reference< XShape > xShape( pShape );
850 :
851 2 : EffectSequence::iterator aIter;
852 :
853 2 : double fDuration = 1.0;
854 :
855 2 : for( aIter = pMainSequence->getBegin(); aIter != pMainSequence->getEnd(); ++aIter )
856 : {
857 0 : CustomAnimationEffectPtr pEffect( (*aIter) );
858 0 : if( pEffect->getTargetShape() == xShape )
859 : {
860 0 : if( pEffect->getDuration() != 0.1 )
861 : {
862 0 : fDuration = pEffect->getDuration();
863 0 : break;
864 : }
865 : }
866 0 : }
867 :
868 4 : return ConvertDuration( fDuration );
869 : }
870 :
871 : // --------------------------------------------------------------------
872 :
873 2 : AnimationSpeed EffectMigration::ConvertDuration( double fDuration )
874 : {
875 : AnimationSpeed eSpeed;
876 :
877 2 : if( fDuration < 1.0 )
878 0 : eSpeed = AnimationSpeed_FAST;
879 2 : else if( fDuration > 1.5 )
880 0 : eSpeed = AnimationSpeed_SLOW;
881 : else
882 2 : eSpeed = AnimationSpeed_MEDIUM;
883 :
884 2 : return eSpeed;
885 : }
886 :
887 : // --------------------------------------------------------------------
888 :
889 0 : void EffectMigration::SetDimColor( SvxShape* pShape, sal_Int32 nColor )
890 : {
891 : DBG_ASSERT( pShape && pShape->GetSdrObject() && pShape->GetSdrObject()->GetPage(),
892 : "sd::EffectMigration::SetAnimationEffect(), invalid argument!" );
893 0 : if( !pShape || !pShape->GetSdrObject() || !pShape->GetSdrObject()->GetPage() )
894 0 : return;
895 :
896 0 : SdrObject* pObj = pShape->GetSdrObject();
897 0 : if( implIsInsideGroup( pObj ) )
898 0 : return;
899 :
900 0 : sd::MainSequencePtr pMainSequence = static_cast<SdPage*>(pObj->GetPage())->getMainSequence();
901 :
902 0 : const Reference< XShape > xShape( pShape );
903 :
904 0 : EffectSequence::iterator aIter;
905 0 : bool bNeedRebuild = false;
906 :
907 0 : for( aIter = pMainSequence->getBegin(); aIter != pMainSequence->getEnd(); ++aIter )
908 : {
909 0 : CustomAnimationEffectPtr pEffect( (*aIter) );
910 0 : if( pEffect->getTargetShape() == xShape )
911 : {
912 0 : pEffect->setHasAfterEffect( true );
913 0 : pEffect->setDimColor( makeAny( nColor ) );
914 0 : pEffect->setAfterEffectOnNext( true );
915 0 : bNeedRebuild = true;
916 : }
917 0 : }
918 :
919 0 : if( bNeedRebuild )
920 0 : pMainSequence->rebuild();
921 : }
922 :
923 : // --------------------------------------------------------------------
924 :
925 0 : sal_Int32 EffectMigration::GetDimColor( SvxShape* pShape )
926 : {
927 0 : sal_Int32 nColor = 0;
928 0 : if( pShape )
929 : {
930 0 : SdrObject* pObj = pShape->GetSdrObject();
931 0 : if( pObj && pObj->GetPage() )
932 : {
933 0 : sd::MainSequencePtr pMainSequence = static_cast<SdPage*>(pObj->GetPage())->getMainSequence();
934 :
935 0 : const Reference< XShape > xShape( pShape );
936 0 : EffectSequence::iterator aIter;
937 :
938 0 : for( aIter = pMainSequence->getBegin(); aIter != pMainSequence->getEnd(); ++aIter )
939 : {
940 0 : CustomAnimationEffectPtr pEffect( (*aIter) );
941 0 : if( (pEffect->getTargetShape() == xShape) &&
942 0 : pEffect->getDimColor().hasValue() &&
943 0 : pEffect->hasAfterEffect())
944 : {
945 0 : pEffect->getDimColor() >>= nColor;
946 0 : break;
947 : }
948 0 : }
949 : }
950 : }
951 :
952 0 : return nColor;
953 : }
954 :
955 : // --------------------------------------------------------------------
956 :
957 :
958 0 : void EffectMigration::SetDimHide( SvxShape* pShape, sal_Bool bDimHide )
959 : {
960 : DBG_ASSERT( pShape && pShape->GetSdrObject() && pShape->GetSdrObject()->GetPage(),
961 : "sd::EffectMigration::SetAnimationEffect(), invalid argument!" );
962 0 : if( !pShape || !pShape->GetSdrObject() || !pShape->GetSdrObject()->GetPage() )
963 0 : return;
964 :
965 0 : SdrObject* pObj = pShape->GetSdrObject();
966 0 : if( implIsInsideGroup( pObj ) )
967 0 : return;
968 :
969 0 : sd::MainSequencePtr pMainSequence = static_cast<SdPage*>(pObj->GetPage())->getMainSequence();
970 :
971 0 : const Reference< XShape > xShape( pShape );
972 :
973 0 : EffectSequence::iterator aIter;
974 0 : bool bNeedRebuild = false;
975 :
976 0 : for( aIter = pMainSequence->getBegin(); aIter != pMainSequence->getEnd(); ++aIter )
977 : {
978 0 : CustomAnimationEffectPtr pEffect( (*aIter) );
979 0 : if( pEffect->getTargetShape() == xShape )
980 : {
981 0 : pEffect->setHasAfterEffect( bDimHide ? true : false );
982 0 : if( bDimHide ) {
983 0 : Any aEmpty;
984 0 : pEffect->setDimColor( aEmpty );
985 : }
986 0 : pEffect->setAfterEffectOnNext( false );
987 0 : bNeedRebuild = true;
988 : }
989 0 : }
990 :
991 0 : if( bNeedRebuild )
992 0 : pMainSequence->rebuild();
993 : }
994 :
995 : // --------------------------------------------------------------------
996 :
997 2 : sal_Bool EffectMigration::GetDimHide( SvxShape* pShape )
998 : {
999 2 : sal_Bool bRet = sal_False;
1000 2 : if( pShape )
1001 : {
1002 2 : SdrObject* pObj = pShape->GetSdrObject();
1003 2 : if( pObj && pObj->GetPage() )
1004 : {
1005 2 : sd::MainSequencePtr pMainSequence = static_cast<SdPage*>(pObj->GetPage())->getMainSequence();
1006 :
1007 4 : const Reference< XShape > xShape( pShape );
1008 :
1009 2 : EffectSequence::iterator aIter;
1010 2 : for( aIter = pMainSequence->getBegin(); aIter != pMainSequence->getEnd(); ++aIter )
1011 : {
1012 0 : CustomAnimationEffectPtr pEffect( (*aIter) );
1013 0 : if( pEffect->getTargetShape() == xShape )
1014 : {
1015 0 : bRet = pEffect->hasAfterEffect() &&
1016 0 : !pEffect->getDimColor().hasValue() &&
1017 0 : (!pEffect->IsAfterEffectOnNext());
1018 0 : break;
1019 : }
1020 2 : }
1021 : }
1022 : }
1023 :
1024 2 : return bRet;
1025 : }
1026 :
1027 : // --------------------------------------------------------------------
1028 :
1029 0 : void EffectMigration::SetDimPrevious( SvxShape* pShape, sal_Bool bDimPrevious )
1030 : {
1031 : DBG_ASSERT( pShape && pShape->GetSdrObject() && pShape->GetSdrObject()->GetPage(),
1032 : "sd::EffectMigration::SetAnimationEffect(), invalid argument!" );
1033 0 : if( !pShape || !pShape->GetSdrObject() || !pShape->GetSdrObject()->GetPage() )
1034 0 : return;
1035 :
1036 0 : SdrObject* pObj = pShape->GetSdrObject();
1037 0 : if( implIsInsideGroup( pObj ) )
1038 0 : return;
1039 :
1040 0 : Any aColor;
1041 :
1042 0 : if( bDimPrevious )
1043 0 : aColor <<= (sal_Int32)COL_LIGHTGRAY;
1044 :
1045 0 : sd::MainSequencePtr pMainSequence = static_cast<SdPage*>(pObj->GetPage())->getMainSequence();
1046 :
1047 0 : const Reference< XShape > xShape( pShape );
1048 :
1049 0 : EffectSequence::iterator aIter;
1050 0 : bool bNeedRebuild = false;
1051 :
1052 0 : for( aIter = pMainSequence->getBegin(); aIter != pMainSequence->getEnd(); ++aIter )
1053 : {
1054 0 : CustomAnimationEffectPtr pEffect( (*aIter) );
1055 0 : if( pEffect->getTargetShape() == xShape )
1056 : {
1057 0 : pEffect->setHasAfterEffect( bDimPrevious );
1058 0 : if( !bDimPrevious || !pEffect->getDimColor().hasValue() )
1059 0 : pEffect->setDimColor( aColor );
1060 0 : pEffect->setAfterEffectOnNext( true );
1061 0 : bNeedRebuild = true;
1062 : }
1063 0 : }
1064 :
1065 0 : if( bNeedRebuild )
1066 0 : pMainSequence->rebuild();
1067 : }
1068 :
1069 : // --------------------------------------------------------------------
1070 :
1071 2 : sal_Bool EffectMigration::GetDimPrevious( SvxShape* pShape )
1072 : {
1073 2 : sal_Bool bRet = sal_False;
1074 2 : if( pShape )
1075 : {
1076 2 : SdrObject* pObj = pShape->GetSdrObject();
1077 2 : if( pObj && pObj->GetPage() )
1078 : {
1079 2 : sd::MainSequencePtr pMainSequence = static_cast<SdPage*>(pObj->GetPage())->getMainSequence();
1080 :
1081 4 : const Reference< XShape > xShape( pShape );
1082 :
1083 2 : EffectSequence::iterator aIter;
1084 2 : for( aIter = pMainSequence->getBegin(); aIter != pMainSequence->getEnd(); ++aIter )
1085 : {
1086 0 : CustomAnimationEffectPtr pEffect( (*aIter) );
1087 0 : if( pEffect->getTargetShape() == xShape )
1088 : {
1089 0 : bRet = pEffect->hasAfterEffect() &&
1090 0 : pEffect->getDimColor().hasValue() &&
1091 0 : pEffect->IsAfterEffectOnNext();
1092 0 : break;
1093 : }
1094 2 : }
1095 : }
1096 : }
1097 :
1098 2 : return bRet;
1099 : }
1100 :
1101 : // --------------------------------------------------------------------
1102 :
1103 0 : void EffectMigration::SetPresentationOrder( SvxShape* pShape, sal_Int32 nNewPos )
1104 : {
1105 0 : if( !pShape || !pShape->GetSdrObject() || !pShape->GetSdrObject()->GetPage() )
1106 0 : return;
1107 :
1108 0 : SdrObject* pObj = pShape->GetSdrObject();
1109 0 : sd::MainSequencePtr pMainSequence = static_cast<SdPage*>(pObj->GetPage())->getMainSequence();
1110 :
1111 0 : EffectSequence& rSequence = pMainSequence->getSequence();
1112 : sal_Int32 nPos;
1113 0 : sal_Int32 nCurrentPos = -1;
1114 0 : std::vector< std::vector< EffectSequence::iterator > > aEffectVector(1);
1115 :
1116 0 : if( !rSequence.empty() )
1117 : {
1118 0 : Reference< XShape > xThis( pShape );
1119 0 : Reference< XShape > xCurrent;
1120 :
1121 0 : EffectSequence::iterator aIter( rSequence.begin() );
1122 0 : EffectSequence::iterator aEnd( rSequence.end() );
1123 0 : for( nPos = 0; aIter != aEnd; ++aIter )
1124 : {
1125 0 : CustomAnimationEffectPtr pEffect = (*aIter);
1126 :
1127 0 : if( !xCurrent.is() )
1128 : {
1129 0 : xCurrent = pEffect->getTargetShape();
1130 : }
1131 0 : else if( pEffect->getTargetShape() != xCurrent )
1132 : {
1133 0 : nPos++;
1134 0 : xCurrent = pEffect->getTargetShape();
1135 0 : aEffectVector.resize( nPos+1 );
1136 : }
1137 :
1138 : // is this the first effect for xThis shape?
1139 0 : if(( nCurrentPos == -1 ) && ( xCurrent == xThis ) )
1140 : {
1141 0 : nCurrentPos = nPos;
1142 : }
1143 :
1144 0 : aEffectVector[nPos].push_back( aIter );
1145 0 : }
1146 : }
1147 :
1148 : // check if there is at least one effect for xThis
1149 0 : if( nCurrentPos == -1 )
1150 : {
1151 : OSL_FAIL("sd::EffectMigration::SetPresentationOrder() failed cause this shape has no effect" );
1152 0 : return;
1153 : }
1154 :
1155 : // check trivial case
1156 0 : if( nCurrentPos != nNewPos )
1157 : {
1158 0 : std::vector< CustomAnimationEffectPtr > aEffects;
1159 :
1160 0 : std::vector< EffectSequence::iterator >::iterator aIter( aEffectVector[nCurrentPos].begin() );
1161 0 : std::vector< EffectSequence::iterator >::iterator aEnd( aEffectVector[nCurrentPos].end() );
1162 0 : while( aIter != aEnd )
1163 : {
1164 0 : aEffects.push_back( (*(*aIter)) );
1165 0 : rSequence.erase( (*aIter++) );
1166 : }
1167 :
1168 0 : if( nNewPos > nCurrentPos )
1169 0 : nNewPos++;
1170 :
1171 0 : std::vector< CustomAnimationEffectPtr >::iterator aTempIter( aEffects.begin() );
1172 0 : std::vector< CustomAnimationEffectPtr >::iterator aTempEnd( aEffects.end() );
1173 :
1174 0 : if( nNewPos == (sal_Int32)aEffectVector.size() )
1175 : {
1176 0 : while( aTempIter != aTempEnd )
1177 : {
1178 0 : rSequence.push_back( (*aTempIter++) );
1179 : }
1180 : }
1181 : else
1182 : {
1183 0 : EffectSequence::iterator aPos( aEffectVector[nNewPos][0] );
1184 0 : while( aTempIter != aTempEnd )
1185 : {
1186 0 : rSequence.insert( aPos, (*aTempIter++) );
1187 : }
1188 0 : }
1189 0 : }
1190 : }
1191 :
1192 : // --------------------------------------------------------------------
1193 :
1194 : /** Returns the position of the given SdrObject in the Presentation order.
1195 : * This function returns -1 if the SdrObject is not in the Presentation order
1196 : * or if its the path-object.
1197 : */
1198 2 : sal_Int32 EffectMigration::GetPresentationOrder( SvxShape* pShape )
1199 : {
1200 2 : sal_Int32 nPos = -1, nFound = -1;
1201 :
1202 2 : SdrObject* pObj = pShape->GetSdrObject();
1203 2 : sd::MainSequencePtr pMainSequence = static_cast<SdPage*>(pObj->GetPage())->getMainSequence();
1204 :
1205 2 : EffectSequence& rSequence = pMainSequence->getSequence();
1206 :
1207 4 : Reference< XShape > xThis( pShape );
1208 4 : Reference< XShape > xCurrent;
1209 :
1210 2 : EffectSequence::iterator aIter( rSequence.begin() );
1211 2 : EffectSequence::iterator aEnd( rSequence.end() );
1212 0 : for( ; aIter != aEnd; ++aIter )
1213 : {
1214 0 : CustomAnimationEffectPtr pEffect = (*aIter);
1215 :
1216 0 : if( !xCurrent.is() || pEffect->getTargetShape() != xCurrent )
1217 : {
1218 0 : nPos++;
1219 0 : xCurrent = pEffect->getTargetShape();
1220 :
1221 : // is this the first effect for xThis shape?
1222 0 : if( xCurrent == xThis )
1223 : {
1224 0 : nFound = nPos;
1225 0 : break;
1226 : }
1227 : }
1228 0 : }
1229 :
1230 4 : return nFound;
1231 : }
1232 :
1233 : // --------------------------------------------------------------------
1234 :
1235 0 : void EffectMigration::UpdateSoundEffect( SvxShape* pShape, SdAnimationInfo* pInfo )
1236 : {
1237 0 : if( pInfo )
1238 : {
1239 0 : SdrObject* pObj = pShape->GetSdrObject();
1240 0 : sd::MainSequencePtr pMainSequence = static_cast<SdPage*>(pObj->GetPage())->getMainSequence();
1241 :
1242 0 : const Reference< XShape > xShape( pShape );
1243 :
1244 0 : EffectSequence::iterator aIter;
1245 0 : bool bNeedRebuild = false;
1246 :
1247 0 : OUString aSoundFile;
1248 0 : if( pInfo->mbSoundOn )
1249 0 : aSoundFile = pInfo->maSoundFile;
1250 :
1251 0 : for( aIter = pMainSequence->getBegin(); aIter != pMainSequence->getEnd(); ++aIter )
1252 : {
1253 0 : CustomAnimationEffectPtr pEffect( (*aIter) );
1254 0 : if( pEffect->getTargetShape() == xShape )
1255 : {
1256 0 : if( !aSoundFile.isEmpty() )
1257 : {
1258 0 : pEffect->createAudio( makeAny( aSoundFile ) );
1259 : }
1260 : else
1261 : {
1262 0 : pEffect->removeAudio();
1263 : }
1264 0 : bNeedRebuild = true;
1265 : }
1266 0 : }
1267 :
1268 0 : if( bNeedRebuild )
1269 0 : pMainSequence->rebuild();
1270 : }
1271 0 : }
1272 :
1273 : // --------------------------------------------------------------------
1274 :
1275 2 : OUString EffectMigration::GetSoundFile( SvxShape* pShape )
1276 : {
1277 2 : OUString aSoundFile;
1278 :
1279 2 : if( pShape )
1280 : {
1281 2 : SdrObject* pObj = pShape->GetSdrObject();
1282 2 : if( pObj && pObj->GetPage() )
1283 : {
1284 2 : sd::MainSequencePtr pMainSequence = static_cast<SdPage*>(pObj->GetPage())->getMainSequence();
1285 :
1286 4 : const Reference< XShape > xShape( pShape );
1287 :
1288 2 : EffectSequence::iterator aIter;
1289 :
1290 6 : for( aIter = pMainSequence->getBegin();
1291 6 : (aSoundFile.isEmpty()) && (aIter != pMainSequence->getEnd());
1292 : ++aIter )
1293 : {
1294 0 : CustomAnimationEffectPtr pEffect( (*aIter) );
1295 0 : if( pEffect->getTargetShape() == xShape )
1296 : {
1297 0 : if( pEffect->getAudio().is() )
1298 0 : pEffect->getAudio()->getSource() >>= aSoundFile;
1299 : }
1300 2 : }
1301 : }
1302 : }
1303 2 : return aSoundFile;
1304 : }
1305 :
1306 : // --------------------------------------------------------------------
1307 :
1308 2 : sal_Bool EffectMigration::GetSoundOn( SvxShape* pShape )
1309 : {
1310 2 : return !GetSoundFile( pShape ).isEmpty();
1311 : }
1312 :
1313 : // --------------------------------------------------------------------
1314 :
1315 0 : void EffectMigration::SetAnimationPath( SvxShape* pShape, SdrPathObj* pPathObj )
1316 : {
1317 0 : if( pShape && pPathObj )
1318 : {
1319 0 : SdrObject* pObj = pShape->GetSdrObject();
1320 :
1321 0 : if( pObj )
1322 : {
1323 0 : const Reference< XShape > xShape( pShape );
1324 0 : SdPage* pPage = dynamic_cast< SdPage* >(pPathObj->GetPage());
1325 0 : if( pPage )
1326 : {
1327 0 : boost::shared_ptr< sd::MainSequence > pMainSequence( pPage->getMainSequence() );
1328 0 : if( pMainSequence.get() )
1329 0 : CustomAnimationEffectPtr pCreated( pMainSequence->append( *pPathObj, makeAny( xShape ), -1.0 ) );
1330 0 : }
1331 : }
1332 : }
1333 33 : }
1334 :
1335 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|