1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef INCLUDED_SLIDESHOW_ACTIVITIESFACTORY_HXX
29 #define INCLUDED_SLIDESHOW_ACTIVITIESFACTORY_HXX
30 
31 #include <com/sun/star/animations/XAnimate.hpp>
32 #include <com/sun/star/animations/XAnimateColor.hpp>
33 
34 #include "animationactivity.hxx"
35 #include "activitiesqueue.hxx"
36 #include "event.hxx"
37 #include "eventqueue.hxx"
38 #include "shape.hxx"
39 #include "numberanimation.hxx"
40 #include "enumanimation.hxx"
41 #include "coloranimation.hxx"
42 #include "hslcoloranimation.hxx"
43 #include "stringanimation.hxx"
44 #include "boolanimation.hxx"
45 #include "pairanimation.hxx"
46 
47 #include <boost/optional.hpp>
48 #include <boost/utility.hpp>
49 
50 /* Definition of ActivitiesFactory class */
51 
52 namespace slideshow {
53 namespace internal {
54 
55 class ActivitiesFactory : private ::boost::noncopyable
56 {
57 public:
58     /// Collection of common factory parameters
59     struct CommonParameters
60     {
61         CommonParameters(
62             const EventSharedPtr&                 rEndEvent,
63             EventQueue&                           rEventQueue,
64             ActivitiesQueue&                      rActivitiesQueue,
65             double                                nMinDuration,
66             sal_uInt32                            nMinNumberOfFrames,
67             bool                                  bAutoReverse,
68             ::boost::optional<double> const&      aRepeats,
69             double                                nAcceleration,
70             double                                nDeceleration,
71             const ShapeSharedPtr&                 rShape,
72             const ::basegfx::B2DVector&           rSlideBounds )
73             : mpEndEvent( rEndEvent ),
74               mrEventQueue( rEventQueue ),
75               mrActivitiesQueue( rActivitiesQueue ),
76               mnMinDuration( nMinDuration ),
77               mnMinNumberOfFrames( nMinNumberOfFrames ),
78               maRepeats( aRepeats ),
79               mnAcceleration( nAcceleration ),
80               mnDeceleration( nDeceleration ),
81               mpShape( rShape ),
82               maSlideBounds( rSlideBounds ),
83               mbAutoReverse( bAutoReverse ) {}
84 
85         /// End event to fire when animation is over
86         EventSharedPtr                                  mpEndEvent;
87 
88         /// Event queue to insert the end event into.
89         EventQueue&                                     mrEventQueue;
90         /// Event queue to insert the end event into.
91         ActivitiesQueue&                                mrActivitiesQueue;
92 
93         /** Simple duration of the activity
94 
95             Specifies the minimal simple duration of the
96             activity (minimal, because mnMinNumberOfFrames
97             might prolongue the activity). According to SMIL,
98             this might also be indefinite, which for our
99             framework does not make much sense, though
100             (wouldn't have a clue, then, how to scale the
101             animation over time).
102         */
103         double                                          mnMinDuration;
104 
105         /** Minimal number of frames for this activity.
106 
107             This specifies the minimal number of frames this
108             activity will display per simple duration. If less
109             than this number are displayed until mnMinDuration
110             is over, the activity will be prolongued until
111             mnMinNumberOfFrames are rendered.
112         */
113         sal_uInt32                                      mnMinNumberOfFrames;
114 
115         /** Number of repeats for the simple duration
116 
117             This specified the number of repeats. The
118             mnMinDuration times maRepeats yields the total
119             duration of this activity. If this value is
120             unspecified, the activity will repeat
121             indefinitely.
122         */
123         ::boost::optional<double> const                 maRepeats;
124 
125         /// Fraction of simple time to accelerate animation
126         double                                          mnAcceleration;
127 
128         /// Fraction of simple time to decelerate animation
129         double                                          mnDeceleration;
130 
131         /// Shape, to get bounds from
132         ShapeSharedPtr                                  mpShape;
133 
134         /// LayerManager, to get page size from
135         ::basegfx::B2DVector                            maSlideBounds;
136 
137         /// When true, activity is played reversed after mnDuration.
138         bool                                            mbAutoReverse;
139     };
140 
141     /** Create an activity from an XAnimate node.
142 
143         This method creates an animated activity from the
144         given XAnimate node, extracting all necessary
145         animation parameters from that. Note that due to the
146         animator parameter, the animation values must be
147         convertible to a double value.
148 
149         @param rParms
150         Factory parameter structure
151 
152         @param rAnimator
153         Animator sub-object
154 
155         @param xNode
156         The SMIL animation node to animate
157     */
158     static AnimationActivitySharedPtr createAnimateActivity(
159         const CommonParameters&                        rParms,
160         const NumberAnimationSharedPtr&                rAnimator,
161         const ::com::sun::star::uno::Reference<
162         ::com::sun::star::animations::XAnimate >&   xNode );
163 
164     /** Create an activity from an XAnimate node.
165 
166         This method creates an animated activity from the
167         given XAnimate node, extracting all necessary
168         animation parameters from that. Note that due to the
169         animator parameter, the animation values must be
170         convertible to a double value.
171 
172         @param rParms
173         Factory parameter structure
174 
175         @param rAnimator
176         Animator sub-object
177 
178         @param xNode
179         The SMIL animation node to animate
180     */
181     static AnimationActivitySharedPtr createAnimateActivity(
182         const CommonParameters&                        rParms,
183         const EnumAnimationSharedPtr&                  rAnimator,
184         const ::com::sun::star::uno::Reference<
185         ::com::sun::star::animations::XAnimate >&      xNode );
186 
187     /** Create an activity from an XAnimate node.
188 
189         This method creates an animated activity from the
190         given XAnimate node, extracting all necessary
191         animation parameters from that. Note that due to the
192         animator parameter, the animation values must be
193         convertible to a color value.
194 
195         @param rParms
196         Factory parameter structure
197 
198         @param rAnimator
199         Animator sub-object
200 
201         @param xNode
202         The SMIL animation node to animate
203     */
204     static AnimationActivitySharedPtr createAnimateActivity(
205         const CommonParameters&                        rParms,
206         const ColorAnimationSharedPtr&                 rAnimator,
207         const ::com::sun::star::uno::Reference<
208         ::com::sun::star::animations::XAnimate >&      xNode );
209 
210     /** Create an activity from an XAnimate node.
211 
212         This method creates an animated activity from the
213         given XAnimate node, extracting all necessary
214         animation parameters from that. Note that due to the
215         animator parameter, the animation values must be
216         convertible to a color value.
217 
218         @param rParms
219         Factory parameter structure
220 
221         @param rAnimator
222         Animator sub-object
223 
224         @param xNode
225         The SMIL animation node to animate
226     */
227     static AnimationActivitySharedPtr createAnimateActivity(
228         const CommonParameters&                            rParms,
229         const HSLColorAnimationSharedPtr&                  rAnimator,
230         const ::com::sun::star::uno::Reference<
231         ::com::sun::star::animations::XAnimateColor >&     xNode );
232 
233     /** Create an activity from an XAnimate node.
234 
235         This method creates an animated activity from the
236         given XAnimate node, extracting all necessary
237         animation parameters from that. Note that due to the
238         animator parameter, the animation values must be
239         convertible to a pair of double values.
240 
241         @param rParms
242         Factory parameter structure
243 
244         @param rAnimator
245         Animator sub-object
246 
247         @param xNode
248         The SMIL animation node to animate
249     */
250     static AnimationActivitySharedPtr createAnimateActivity(
251         const CommonParameters&                        rParms,
252         const PairAnimationSharedPtr&                  rAnimator,
253         const ::com::sun::star::uno::Reference<
254         ::com::sun::star::animations::XAnimate >&   xNode );
255 
256     /** Create an activity from an XAnimate node.
257 
258         This method creates an animated activity from the
259         given XAnimate node, extracting all necessary
260         animation parameters from that. Note that due to the
261         animator parameter, the animation values must be
262         convertible to a string.
263 
264         @param rParms
265         Factory parameter structure
266 
267         @param rAnimator
268         Animator sub-object
269 
270         @param xNode
271         The SMIL animation node to animate
272     */
273     static AnimationActivitySharedPtr createAnimateActivity(
274         const CommonParameters&                        rParms,
275         const StringAnimationSharedPtr&                rAnimator,
276         const ::com::sun::star::uno::Reference<
277         ::com::sun::star::animations::XAnimate >&      xNode );
278 
279     /** Create an activity from an XAnimate node.
280 
281         This method creates an animated activity from the
282         given XAnimate node, extracting all necessary
283         animation parameters from that. Note that due to the
284         animator parameter, the animation values must be
285         convertible to a bool value.
286 
287         @param rParms
288         Factory parameter structure
289 
290         @param rAnimator
291         Animator sub-object
292 
293         @param xNode
294         The SMIL animation node to animate
295     */
296     static AnimationActivitySharedPtr createAnimateActivity(
297         const CommonParameters&                        rParms,
298         const BoolAnimationSharedPtr&                  rAnimator,
299         const ::com::sun::star::uno::Reference<
300         ::com::sun::star::animations::XAnimate >&      xNode );
301 
302     /** Create a simple activity for the given animator
303 
304         This method is suited to create activities for custom
305         animations, which need a simple double value and lasts
306         a given timespan. This activity always generates values
307         from the [0,1] range.
308 
309         @param rParms
310         Factory parameter structure
311 
312         @param rAnimator
313         Animator sub-object
314 
315         @param bDirectionForward
316         If true, the activity goes 'forward', i.e. from 0 to
317         1. With false, the direction is reversed.
318     */
319     static AnimationActivitySharedPtr createSimpleActivity(
320         const CommonParameters&         rParms,
321         const NumberAnimationSharedPtr& rAnimator,
322         bool                            bDirectionForward );
323 
324 private:
325     // default: constructor/destructor disabed
326     ActivitiesFactory();
327     ~ActivitiesFactory();
328 };
329 
330 } // namespace internal
331 } // namespace presentation
332 
333 #endif /* INCLUDED_SLIDESHOW_ACTIVITIESFACTORY_HXX */
334 
335