1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #ifndef SDEXT_PRESENTER_ANIMATION_HXX
29*cdf0e10cSrcweir #define SDEXT_PRESENTER_ANIMATION_HXX
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <sal/types.h>
32*cdf0e10cSrcweir #include <boost/function.hpp>
33*cdf0e10cSrcweir #include <boost/noncopyable.hpp>
34*cdf0e10cSrcweir #include <boost/scoped_ptr.hpp>
35*cdf0e10cSrcweir #include <boost/shared_ptr.hpp>
36*cdf0e10cSrcweir #include <vector>
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir namespace sdext { namespace presenter {
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir /** Base class for animations handled by a PresenterAnimator object.
41*cdf0e10cSrcweir     A PresenterAnimation objects basically states when it wants to be
42*cdf0e10cSrcweir     started, how long it runs, and in what steps it wants to be called back
43*cdf0e10cSrcweir     while running.
44*cdf0e10cSrcweir     When a PresenterAnimation object is active/running its Run() method is
45*cdf0e10cSrcweir     called back with increasing values between 0 and 1.
46*cdf0e10cSrcweir */
47*cdf0e10cSrcweir class PresenterAnimation
48*cdf0e10cSrcweir     : private ::boost::noncopyable
49*cdf0e10cSrcweir {
50*cdf0e10cSrcweir public:
51*cdf0e10cSrcweir     /** Create a new PresenterAnimation object.
52*cdf0e10cSrcweir         @param nStartDelay
53*cdf0e10cSrcweir             The delay in ms (milliseconds) from this call until the new
54*cdf0e10cSrcweir             object is to be activated.
55*cdf0e10cSrcweir         @param nTotalDuration
56*cdf0e10cSrcweir             The duration in ms the Run() method is to be called with
57*cdf0e10cSrcweir             increasing values between 0 and 1.
58*cdf0e10cSrcweir         @param nStepDuration
59*cdf0e10cSrcweir             The duration between calls to Run().  This leads to approximately
60*cdf0e10cSrcweir             nTotalDuration/nStepDuration calls to Run().  The exact duration
61*cdf0e10cSrcweir             of each step may vary depending on system load an other influences.
62*cdf0e10cSrcweir     */
63*cdf0e10cSrcweir     PresenterAnimation (
64*cdf0e10cSrcweir         const sal_uInt64 nStartDelay,
65*cdf0e10cSrcweir         const sal_uInt64 nTotalDuration,
66*cdf0e10cSrcweir         const sal_uInt64 nStepDuration);
67*cdf0e10cSrcweir     virtual ~PresenterAnimation (void);
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir     /** Return the absolute start time in a system dependent format.
70*cdf0e10cSrcweir         At about this time the Run() method will be called with a value of 0.
71*cdf0e10cSrcweir     */
72*cdf0e10cSrcweir     sal_uInt64 GetStartTime (void);
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir     /** Return the absolute end time in a system dependent format.
75*cdf0e10cSrcweir         At about this time the Run() method will be called with a value of 1.
76*cdf0e10cSrcweir     */
77*cdf0e10cSrcweir     sal_uInt64 GetEndTime (void);
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir     /** Return the duration of each step in ms.
80*cdf0e10cSrcweir     */
81*cdf0e10cSrcweir     sal_uInt64 GetStepDuration (void);
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir     typedef ::boost::function<void(void)> Callback;
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir     /** Add a callback that is executed before Run() is called for the first
86*cdf0e10cSrcweir         time.
87*cdf0e10cSrcweir     */
88*cdf0e10cSrcweir     void AddStartCallback (const Callback& rCallback);
89*cdf0e10cSrcweir 
90*cdf0e10cSrcweir     /** Add a callback that is executed after Run() is called for the last
91*cdf0e10cSrcweir         time.
92*cdf0e10cSrcweir     */
93*cdf0e10cSrcweir     void AddEndCallback (const Callback& rCallback);
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir     /** Called with nProgress taking on values between 0 and 1.
96*cdf0e10cSrcweir         @param nProgress
97*cdf0e10cSrcweir             A value between 0 and 1.
98*cdf0e10cSrcweir         @param nCurrentTime
99*cdf0e10cSrcweir             Current time in a system dependent format.
100*cdf0e10cSrcweir     */
101*cdf0e10cSrcweir     virtual void Run (const double nProgress, const sal_uInt64 nCurrentTime) = 0;
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir     /** Called just before Run() is called for the first time to trigger the
104*cdf0e10cSrcweir         callbacks registered via the <method>AddStartCallback()</method>.
105*cdf0e10cSrcweir     */
106*cdf0e10cSrcweir     void RunStartCallbacks (void);
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir     /** Called just after Run() is called for the last time to trigger the
109*cdf0e10cSrcweir         callbacks registered via the <method>AddEndCallback()</method>.
110*cdf0e10cSrcweir     */
111*cdf0e10cSrcweir     void RunEndCallbacks (void);
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir private:
114*cdf0e10cSrcweir     const sal_uInt64 mnStartTime;
115*cdf0e10cSrcweir     const sal_uInt64 mnTotalDuration;
116*cdf0e10cSrcweir     const sal_uInt64 mnStepDuration;
117*cdf0e10cSrcweir     ::boost::scoped_ptr<std::vector<Callback> > mpStartCallbacks;
118*cdf0e10cSrcweir     ::boost::scoped_ptr<std::vector<Callback> > mpEndCallbacks;
119*cdf0e10cSrcweir };
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir sal_uInt64 GetCurrentTime (void);
122*cdf0e10cSrcweir inline sal_uInt32 GetSeconds (const sal_uInt64 nTime) { return sal_uInt32(nTime / 1000); }
123*cdf0e10cSrcweir inline sal_uInt32 GetNanoSeconds (const sal_uInt64 nTime) { return sal_uInt32((nTime % 1000) * 1000000); }
124*cdf0e10cSrcweir 
125*cdf0e10cSrcweir typedef ::boost::shared_ptr<PresenterAnimation> SharedPresenterAnimation;
126*cdf0e10cSrcweir 
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir } } // end of namespace ::sdext::presenter
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir #endif
131