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