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 SDEXT_PRESENTER_ANIMATION_HXX
29 #define SDEXT_PRESENTER_ANIMATION_HXX
30 
31 #include <sal/types.h>
32 #include <boost/function.hpp>
33 #include <boost/noncopyable.hpp>
34 #include <boost/scoped_ptr.hpp>
35 #include <boost/shared_ptr.hpp>
36 #include <vector>
37 
38 namespace sdext { namespace presenter {
39 
40 /** Base class for animations handled by a PresenterAnimator object.
41     A PresenterAnimation objects basically states when it wants to be
42     started, how long it runs, and in what steps it wants to be called back
43     while running.
44     When a PresenterAnimation object is active/running its Run() method is
45     called back with increasing values between 0 and 1.
46 */
47 class PresenterAnimation
48     : private ::boost::noncopyable
49 {
50 public:
51     /** Create a new PresenterAnimation object.
52         @param nStartDelay
53             The delay in ms (milliseconds) from this call until the new
54             object is to be activated.
55         @param nTotalDuration
56             The duration in ms the Run() method is to be called with
57             increasing values between 0 and 1.
58         @param nStepDuration
59             The duration between calls to Run().  This leads to approximately
60             nTotalDuration/nStepDuration calls to Run().  The exact duration
61             of each step may vary depending on system load an other influences.
62     */
63     PresenterAnimation (
64         const sal_uInt64 nStartDelay,
65         const sal_uInt64 nTotalDuration,
66         const sal_uInt64 nStepDuration);
67     virtual ~PresenterAnimation (void);
68 
69     /** Return the absolute start time in a system dependent format.
70         At about this time the Run() method will be called with a value of 0.
71     */
72     sal_uInt64 GetStartTime (void);
73 
74     /** Return the absolute end time in a system dependent format.
75         At about this time the Run() method will be called with a value of 1.
76     */
77     sal_uInt64 GetEndTime (void);
78 
79     /** Return the duration of each step in ms.
80     */
81     sal_uInt64 GetStepDuration (void);
82 
83     typedef ::boost::function<void(void)> Callback;
84 
85     /** Add a callback that is executed before Run() is called for the first
86         time.
87     */
88     void AddStartCallback (const Callback& rCallback);
89 
90     /** Add a callback that is executed after Run() is called for the last
91         time.
92     */
93     void AddEndCallback (const Callback& rCallback);
94 
95     /** Called with nProgress taking on values between 0 and 1.
96         @param nProgress
97             A value between 0 and 1.
98         @param nCurrentTime
99             Current time in a system dependent format.
100     */
101     virtual void Run (const double nProgress, const sal_uInt64 nCurrentTime) = 0;
102 
103     /** Called just before Run() is called for the first time to trigger the
104         callbacks registered via the <method>AddStartCallback()</method>.
105     */
106     void RunStartCallbacks (void);
107 
108     /** Called just after Run() is called for the last time to trigger the
109         callbacks registered via the <method>AddEndCallback()</method>.
110     */
111     void RunEndCallbacks (void);
112 
113 private:
114     const sal_uInt64 mnStartTime;
115     const sal_uInt64 mnTotalDuration;
116     const sal_uInt64 mnStepDuration;
117     ::boost::scoped_ptr<std::vector<Callback> > mpStartCallbacks;
118     ::boost::scoped_ptr<std::vector<Callback> > mpEndCallbacks;
119 };
120 
121 sal_uInt64 GetCurrentTime (void);
122 inline sal_uInt32 GetSeconds (const sal_uInt64 nTime) { return sal_uInt32(nTime / 1000); }
123 inline sal_uInt32 GetNanoSeconds (const sal_uInt64 nTime) { return sal_uInt32((nTime % 1000) * 1000000); }
124 
125 typedef ::boost::shared_ptr<PresenterAnimation> SharedPresenterAnimation;
126 
127 
128 } } // end of namespace ::sdext::presenter
129 
130 #endif
131