e911012b23660a3c4551aac4370e3197db7773bf
[framework/osp/uifw.git] / src / ui / controls / FUiCtrl_AnimationImpl.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file                FUiCtrl_AnimationImpl.cpp
20  * @brief               This is the implementation file for the _AnimationImpl class.
21  */
22
23 #include <FUiCtrlAnimation.h>
24 #include <FBaseSysLog.h>
25 #include "FUiCtrl_AnimationImpl.h"
26 #include "FUiCtrl_Animation.h"
27
28 using namespace Tizen::Base::Collection;
29 using namespace Tizen::Base::Runtime;
30
31 namespace Tizen { namespace Ui { namespace Controls
32 {
33
34 _AnimationImpl*
35 _AnimationImpl::GetInstance(Animation& animation)
36 {
37         return static_cast<_AnimationImpl*> (animation._pControlImpl);
38 }
39
40 const _AnimationImpl*
41 _AnimationImpl::GetInstance(const Animation& animation)
42 {
43         return static_cast<const _AnimationImpl*> (animation._pControlImpl);
44 }
45
46 _AnimationImpl::_AnimationImpl(Animation* pPublic, _Animation* pCore)
47         : _ControlImpl(pPublic, pCore)
48         , __pPublicAnimationEvent(null)
49 {
50         SetFocusableChangable(false);
51 }
52
53 _AnimationImpl::~_AnimationImpl(void)
54 {
55         if (__pPublicAnimationEvent != null)
56         {
57                 delete __pPublicAnimationEvent;
58                 __pPublicAnimationEvent = null;
59         }
60 }
61
62 _AnimationImpl*
63 _AnimationImpl::CreateAnimationImplN(Animation* pControl)
64 {
65         ClearLastResult();
66
67         result r = E_SUCCESS;
68
69         _Animation* pCore = _Animation::CreateAnimationN();
70         r = GetLastResult();
71         SysTryReturn(NID_UI_CTRL, pCore != null, null, r, "[%s] Propagating.", GetErrorMessage(r));
72
73         _AnimationImpl* pImpl = new (std::nothrow) _AnimationImpl(pControl, pCore);
74
75         r = CheckConstruction(pCore, pImpl);
76         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
77
78         pImpl->__pPublicAnimationEvent = _PublicAnimationEvent::CreateInstanceN(*pControl);
79         r = GetLastResult();
80         SysTryCatch(NID_UI_CTRL, pImpl->__pPublicAnimationEvent != null, , r, "[%s] Propagating.", GetErrorMessage(r));
81
82         r = pCore->AddAnimationEventListener(*pImpl);
83         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
84
85         return pImpl;
86
87 CATCH:
88         delete pImpl;
89         pImpl = null;
90
91         return null;
92 }
93
94 result
95 _AnimationImpl::SetAnimationFrames(const IList& animationFrames)
96 {
97         ClearLastResult();
98
99         return GetCore().SetAnimationFrames(animationFrames);
100 }
101
102 void
103 _AnimationImpl::SetImageCount(int imageCount)
104 {
105         GetCore().SetImageCount(imageCount);
106
107         return;
108 }
109
110 result
111 _AnimationImpl::AddAnimationEventListener(IAnimationEventListener& listener)
112 {
113         ClearLastResult();
114
115         SysTryReturnResult(NID_UI_CTRL, __pPublicAnimationEvent, E_SYSTEM, "A system error has occurred. The _PublicAnimationEvent instance is null");
116
117         result r = __pPublicAnimationEvent->AddListener(listener);
118         SysTryReturnResult(NID_UI_CTRL, r != E_OBJ_ALREADY_EXIST, E_SYSTEM, "A system error has occurred. The IAnimationEventListener instance already exists in the event listener list.");
119
120         return r;
121 }
122
123 result
124 _AnimationImpl::RemoveAnimationEventListener(IAnimationEventListener& listener)
125 {
126         ClearLastResult();
127
128         SysTryReturnResult(NID_UI_CTRL, __pPublicAnimationEvent, E_SYSTEM, "A system error has occurred. The _PublicAnimationEvent instance is null");
129
130         result r = __pPublicAnimationEvent->RemoveListener(listener);
131         SysTryReturnResult(NID_UI_CTRL, r != E_OBJ_NOT_FOUND, E_SYSTEM, "A system error has occurred. The IAnimationEventListener instance does not exist in the event listener list.");
132
133         return r;
134 }
135
136 result
137 _AnimationImpl::SetRepeatCount(int count)
138 {
139         ClearLastResult();
140
141         Variant repeatCount(count);
142
143         return GetCore().SetPropertyRepeatCount(repeatCount);
144 }
145
146 int
147 _AnimationImpl::GetRepeatCount(void) const
148 {
149         ClearLastResult();
150
151         return GetCore().GetPropertyRepeatCount().ToInt();
152 }
153
154 int
155 _AnimationImpl::GetCurrentRepeatedCount(void) const
156 {
157         ClearLastResult();
158
159         return GetCore().GetCurrentRepeatedCount();
160 }
161
162 int
163 _AnimationImpl::GetImageCount(void) const
164 {
165         ClearLastResult();
166
167         return GetCore().GetImageCount();
168 }
169
170 result
171 _AnimationImpl::Play(void)
172 {
173         ClearLastResult();
174
175         return GetCore().Play();
176 }
177
178 result
179 _AnimationImpl::Stop(void)
180 {
181         ClearLastResult();
182
183         return GetCore().Stop();
184 }
185
186 result
187 _AnimationImpl::Pause(void)
188 {
189         ClearLastResult();
190
191         return GetCore().Pause();
192 }
193
194 AnimationStatus
195 _AnimationImpl::GetStatus(void) const
196 {
197         return GetCore().GetStatus();
198 }
199
200 void
201 _AnimationImpl::OnAnimationStopped(const _Control& source)
202 {
203         IEventArg* pEventArg = _PublicAnimationEvent::CreateAnimationEventArgN();
204         result r = GetLastResult();
205         SysTryReturnVoidResult(NID_UI_CTRL, pEventArg != null, r, "[%s] Propagating.", GetErrorMessage(r));
206
207         r = __pPublicAnimationEvent->Fire(*pEventArg);
208
209         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
210
211         SetLastResult(E_SUCCESS);
212         return;
213 }
214
215 const char*
216 _AnimationImpl::GetPublicClassName(void) const
217 {
218         return "Tizen::Ui::Controls::Animation";
219 }
220
221 const Animation&
222 _AnimationImpl::GetPublic(void) const
223 {
224         return static_cast <const Animation&>(_ControlImpl::GetPublic());
225 }
226
227 Animation&
228 _AnimationImpl::GetPublic(void)
229 {
230         return static_cast <Animation&>(_ControlImpl::GetPublic());
231 }
232
233 const _Animation&
234 _AnimationImpl::GetCore(void) const
235 {
236         return static_cast <const _Animation&>(_ControlImpl::GetCore());
237 }
238
239 _Animation&
240 _AnimationImpl::GetCore(void)
241 {
242         return static_cast <_Animation&>(_ControlImpl::GetCore());
243 }
244
245 }}} // Tizen::Ui::Controls