Tizen 2.1 base
[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 Flora License, Version 1.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://floralicense.org/license/
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  * @file                FUiCtrl_AnimationImpl.cpp
19  * @brief               This is the implementation file for the _AnimationImpl class.
20  */
21
22 #include <FUiCtrlAnimation.h>
23 #include <FBaseSysLog.h>
24 #include "FUiCtrl_AnimationImpl.h"
25 #include "FUiCtrl_Animation.h"
26
27 using namespace Tizen::Base::Collection;
28 using namespace Tizen::Base::Runtime;
29
30 namespace Tizen { namespace Ui { namespace Controls
31 {
32
33 _AnimationImpl*
34 _AnimationImpl::GetInstance(Animation& animation)
35 {
36         return static_cast<_AnimationImpl*> (animation._pControlImpl);
37 }
38
39 const _AnimationImpl*
40 _AnimationImpl::GetInstance(const Animation& animation)
41 {
42         return static_cast<const _AnimationImpl*> (animation._pControlImpl);
43 }
44
45 _AnimationImpl::_AnimationImpl(Animation* pPublic, _Animation* pCore)
46         : _ControlImpl(pPublic, pCore)
47         , __pPublicAnimationEvent(null)
48 {
49         SetFocusableChangable(false);
50 }
51
52 _AnimationImpl::~_AnimationImpl(void)
53 {
54         if (__pPublicAnimationEvent != null)
55         {
56                 delete __pPublicAnimationEvent;
57                 __pPublicAnimationEvent = null;
58         }
59 }
60
61 _AnimationImpl*
62 _AnimationImpl::CreateAnimationImplN(Animation* pControl)
63 {
64         ClearLastResult();
65
66         result r = E_SUCCESS;
67
68         _Animation* pCore = _Animation::CreateAnimationN();
69         r = GetLastResult();
70         SysTryReturn(NID_UI_CTRL, pCore != null, null, r, "[%s] Propagating.", GetErrorMessage(r));
71
72         _AnimationImpl* pImpl = new (std::nothrow) _AnimationImpl(pControl, pCore);
73
74         r = CheckConstruction(pCore, pImpl);
75         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
76
77         pImpl->__pPublicAnimationEvent = _PublicAnimationEvent::CreateInstanceN(*pControl);
78         r = GetLastResult();
79         SysTryCatch(NID_UI_CTRL, pImpl->__pPublicAnimationEvent != null, , r, "[%s] Propagating.", GetErrorMessage(r));
80
81         r = pCore->AddAnimationEventListener(*pImpl);
82         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
83
84         return pImpl;
85
86 CATCH:
87         delete pImpl;
88         pImpl = null;
89
90         return null;
91 }
92
93 result
94 _AnimationImpl::SetAnimationFrames(const IList& animationFrames)
95 {
96         ClearLastResult();
97
98         return GetCore().SetAnimationFrames(animationFrames);
99 }
100
101 void
102 _AnimationImpl::SetImageCount(int imageCount)
103 {
104         GetCore().SetImageCount(imageCount);
105
106         return;
107 }
108
109 result
110 _AnimationImpl::AddAnimationEventListener(IAnimationEventListener& listener)
111 {
112         ClearLastResult();
113
114         SysTryReturnResult(NID_UI_CTRL, __pPublicAnimationEvent, E_SYSTEM, "A system error has occurred. The _PublicAnimationEvent instance is null");
115
116         result r = __pPublicAnimationEvent->AddListener(listener);
117         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.");
118
119         return r;
120 }
121
122 result
123 _AnimationImpl::RemoveAnimationEventListener(IAnimationEventListener& listener)
124 {
125         ClearLastResult();
126
127         SysTryReturnResult(NID_UI_CTRL, __pPublicAnimationEvent, E_SYSTEM, "A system error has occurred. The _PublicAnimationEvent instance is null");
128
129         result r = __pPublicAnimationEvent->RemoveListener(listener);
130         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.");
131
132         return r;
133 }
134
135 result
136 _AnimationImpl::SetRepeatCount(int count)
137 {
138         ClearLastResult();
139
140         Variant repeatCount(count);
141
142         return GetCore().SetPropertyRepeatCount(repeatCount);
143 }
144
145 int
146 _AnimationImpl::GetRepeatCount(void) const
147 {
148         ClearLastResult();
149
150         return GetCore().GetPropertyRepeatCount().ToInt();
151 }
152
153 int
154 _AnimationImpl::GetCurrentRepeatedCount(void) const
155 {
156         ClearLastResult();
157
158         return GetCore().GetCurrentRepeatedCount();
159 }
160
161 int
162 _AnimationImpl::GetImageCount(void) const
163 {
164         ClearLastResult();
165
166         return GetCore().GetImageCount();
167 }
168
169 result
170 _AnimationImpl::Play(void)
171 {
172         ClearLastResult();
173
174         return GetCore().Play();
175 }
176
177 result
178 _AnimationImpl::Stop(void)
179 {
180         ClearLastResult();
181
182         return GetCore().Stop();
183 }
184
185 result
186 _AnimationImpl::Pause(void)
187 {
188         ClearLastResult();
189
190         return GetCore().Pause();
191 }
192
193 AnimationStatus
194 _AnimationImpl::GetStatus(void) const
195 {
196         return GetCore().GetStatus();
197 }
198
199 void
200 _AnimationImpl::OnAnimationStopped(const _Control& source)
201 {
202         IEventArg* pEventArg = _PublicAnimationEvent::CreateAnimationEventArgN();
203         result r = GetLastResult();
204         SysTryReturnVoidResult(NID_UI_CTRL, pEventArg != null, r, "[%s] Propagating.", GetErrorMessage(r));
205
206         r = __pPublicAnimationEvent->Fire(*pEventArg);
207
208         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
209
210         SetLastResult(E_SUCCESS);
211         return;
212 }
213
214 const char*
215 _AnimationImpl::GetPublicClassName(void) const
216 {
217         return "Tizen::Ui::Controls::Animation";
218 }
219
220 const Animation&
221 _AnimationImpl::GetPublic(void) const
222 {
223         return static_cast <const Animation&>(_ControlImpl::GetPublic());
224 }
225
226 Animation&
227 _AnimationImpl::GetPublic(void)
228 {
229         return static_cast <Animation&>(_ControlImpl::GetPublic());
230 }
231
232 const _Animation&
233 _AnimationImpl::GetCore(void) const
234 {
235         return static_cast <const _Animation&>(_ControlImpl::GetCore());
236 }
237
238 _Animation&
239 _AnimationImpl::GetCore(void)
240 {
241         return static_cast <_Animation&>(_ControlImpl::GetCore());
242 }
243
244 }}} // Tizen::Ui::Controls