1*c142477cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*c142477cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*c142477cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*c142477cSAndrew Rist  * distributed with this work for additional information
6*c142477cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*c142477cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*c142477cSAndrew Rist  * "License"); you may not use this file except in compliance
9*c142477cSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*c142477cSAndrew Rist  *
11*c142477cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*c142477cSAndrew Rist  *
13*c142477cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*c142477cSAndrew Rist  * software distributed under the License is distributed on an
15*c142477cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*c142477cSAndrew Rist  * KIND, either express or implied.  See the License for the
17*c142477cSAndrew Rist  * specific language governing permissions and limitations
18*c142477cSAndrew Rist  * under the License.
19*c142477cSAndrew Rist  *
20*c142477cSAndrew Rist  *************************************************************/
21*c142477cSAndrew Rist 
22*c142477cSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sdext.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "PresenterAnimation.hxx"
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <osl/time.h>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir namespace sdext { namespace presenter {
32cdf0e10cSrcweir 
33cdf0e10cSrcweir sal_uInt64 GetCurrentTime (void)
34cdf0e10cSrcweir {
35cdf0e10cSrcweir     TimeValue aTimeValue;
36cdf0e10cSrcweir     if (osl_getSystemTime(&aTimeValue))
37cdf0e10cSrcweir         return sal_uInt64(aTimeValue.Seconds * 1000.0 + aTimeValue.Nanosec / 1000000.0);
38cdf0e10cSrcweir     else
39cdf0e10cSrcweir         return 0;
40cdf0e10cSrcweir }
41cdf0e10cSrcweir 
42cdf0e10cSrcweir 
43cdf0e10cSrcweir 
44cdf0e10cSrcweir 
45cdf0e10cSrcweir PresenterAnimation::PresenterAnimation (
46cdf0e10cSrcweir     const sal_uInt64 nStartDelay,
47cdf0e10cSrcweir     const sal_uInt64 nTotalDuration,
48cdf0e10cSrcweir     const sal_uInt64 nStepDuration)
49cdf0e10cSrcweir     : mnStartTime(GetCurrentTime()+nStartDelay),
50cdf0e10cSrcweir       mnTotalDuration(nTotalDuration),
51cdf0e10cSrcweir       mnStepDuration(nStepDuration),
52cdf0e10cSrcweir       mpStartCallbacks(),
53cdf0e10cSrcweir       mpEndCallbacks()
54cdf0e10cSrcweir {
55cdf0e10cSrcweir }
56cdf0e10cSrcweir 
57cdf0e10cSrcweir 
58cdf0e10cSrcweir 
59cdf0e10cSrcweir 
60cdf0e10cSrcweir PresenterAnimation::~PresenterAnimation (void)
61cdf0e10cSrcweir {
62cdf0e10cSrcweir }
63cdf0e10cSrcweir 
64cdf0e10cSrcweir 
65cdf0e10cSrcweir 
66cdf0e10cSrcweir 
67cdf0e10cSrcweir sal_uInt64 PresenterAnimation::GetStartTime (void)
68cdf0e10cSrcweir {
69cdf0e10cSrcweir     return mnStartTime;
70cdf0e10cSrcweir }
71cdf0e10cSrcweir 
72cdf0e10cSrcweir 
73cdf0e10cSrcweir 
74cdf0e10cSrcweir 
75cdf0e10cSrcweir sal_uInt64 PresenterAnimation::GetEndTime (void)
76cdf0e10cSrcweir {
77cdf0e10cSrcweir     return mnStartTime + mnTotalDuration;
78cdf0e10cSrcweir }
79cdf0e10cSrcweir 
80cdf0e10cSrcweir 
81cdf0e10cSrcweir 
82cdf0e10cSrcweir 
83cdf0e10cSrcweir sal_uInt64 PresenterAnimation::GetStepDuration (void)
84cdf0e10cSrcweir {
85cdf0e10cSrcweir     return mnStepDuration;
86cdf0e10cSrcweir }
87cdf0e10cSrcweir 
88cdf0e10cSrcweir 
89cdf0e10cSrcweir 
90cdf0e10cSrcweir 
91cdf0e10cSrcweir void PresenterAnimation::AddStartCallback (const Callback& rCallback)
92cdf0e10cSrcweir {
93cdf0e10cSrcweir     if (mpStartCallbacks.get() == NULL)
94cdf0e10cSrcweir         mpStartCallbacks.reset(new ::std::vector<Callback>());
95cdf0e10cSrcweir     mpStartCallbacks->push_back(rCallback);
96cdf0e10cSrcweir }
97cdf0e10cSrcweir 
98cdf0e10cSrcweir 
99cdf0e10cSrcweir 
100cdf0e10cSrcweir 
101cdf0e10cSrcweir void PresenterAnimation::AddEndCallback (const Callback& rCallback)
102cdf0e10cSrcweir {
103cdf0e10cSrcweir     if (mpEndCallbacks.get() == NULL)
104cdf0e10cSrcweir         mpEndCallbacks.reset(new ::std::vector<Callback>());
105cdf0e10cSrcweir     mpEndCallbacks->push_back(rCallback);
106cdf0e10cSrcweir }
107cdf0e10cSrcweir 
108cdf0e10cSrcweir 
109cdf0e10cSrcweir 
110cdf0e10cSrcweir void PresenterAnimation::RunStartCallbacks (void)
111cdf0e10cSrcweir {
112cdf0e10cSrcweir     if (mpStartCallbacks.get() != NULL)
113cdf0e10cSrcweir     {
114cdf0e10cSrcweir         ::std::vector<Callback>::const_iterator iCallback;
115cdf0e10cSrcweir         for (iCallback=mpStartCallbacks->begin(); iCallback!=mpStartCallbacks->end(); ++iCallback)
116cdf0e10cSrcweir             (*iCallback)();
117cdf0e10cSrcweir     }
118cdf0e10cSrcweir }
119cdf0e10cSrcweir 
120cdf0e10cSrcweir 
121cdf0e10cSrcweir 
122cdf0e10cSrcweir 
123cdf0e10cSrcweir void PresenterAnimation::RunEndCallbacks (void)
124cdf0e10cSrcweir {
125cdf0e10cSrcweir     if (mpEndCallbacks.get() != NULL)
126cdf0e10cSrcweir     {
127cdf0e10cSrcweir         ::std::vector<Callback>::const_iterator iCallback;
128cdf0e10cSrcweir         for (iCallback=mpEndCallbacks->begin(); iCallback!=mpEndCallbacks->end(); ++iCallback)
129cdf0e10cSrcweir             (*iCallback)();
130cdf0e10cSrcweir     }
131cdf0e10cSrcweir }
132cdf0e10cSrcweir 
133cdf0e10cSrcweir 
134cdf0e10cSrcweir 
135cdf0e10cSrcweir 
136cdf0e10cSrcweir } } // end of namespace ::sdext::presenter
137