Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / animations / FUiAnimParallelAnimationGroup.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 /**
19  * @file        FUiAnimParallelAnimationGroup.cpp
20  * @brief       This file contains implementation of ParallelAnimationGroup class
21  *
22  * This file contains implementation of ParallelAnimationGroup class.
23  */
24
25 #include <FBaseSysLog.h>
26 #include <FBaseColArrayListT.h>
27
28 #include <FUiAnimParallelAnimationGroup.h>
29 #include <FUiAnimDimensionAnimation.h>
30 #include <FUiAnimFloatAnimation.h>
31 #include <FUiAnimRectangleAnimation.h>
32 #include <FUiAnimIntegerAnimation.h>
33 #include <FUiAnimPointAnimation.h>
34 #include <FUiAnimRotateAnimation.h>
35
36 #include "FUiAnim_AnimationGroupImpl.h"
37
38
39 using namespace Tizen::Base;
40 using namespace Tizen::Base::Collection;
41
42
43 namespace Tizen { namespace Ui { namespace Animations
44 {
45
46 ParallelAnimationGroup::ParallelAnimationGroup(void)
47         : AnimationGroup()
48         , _pParallelAnimationGroupImpl(null)
49 {
50 }
51
52 ParallelAnimationGroup::~ParallelAnimationGroup(void)
53 {
54 }
55
56 ParallelAnimationGroup::ParallelAnimationGroup(const ParallelAnimationGroup& animationGroup)
57         : AnimationGroup(animationGroup)
58         , _pParallelAnimationGroupImpl(null)
59 {
60         result r = GetLastResult();
61         SysTryReturnVoidResult(NID_UI_ANIM, (_pAnimationGroupImpl), r, "[%s] Propagating.", GetErrorMessage(r));
62
63         int animationCount = animationGroup._pAnimationGroupImpl->animationList.GetCount();
64
65         _AnimationGroupImpl::AnimationStore animStore;
66
67         for (int index = 0; index < animationCount; index++)
68         {
69                 animationGroup._pAnimationGroupImpl->animationList.GetAt(index, animStore);
70
71                 r = AddAnimation(animStore.animTarget, *(animStore.pAnimationBase));
72                 if (r != E_SUCCESS)
73                 {
74                         SysLogException(NID_UI_ANIM, r, "[%s] Propagating.", GetErrorMessage(r));
75
76                         delete _pAnimationGroupImpl;
77                         _pAnimationGroupImpl = null;
78
79                         return;
80                 }
81         }
82 }
83
84 ParallelAnimationGroup&
85 ParallelAnimationGroup::operator =(const ParallelAnimationGroup& rhs)
86 {
87         ClearLastResult();
88
89         if ((&rhs) != this)
90         {
91                 result r = E_SUCCESS;
92
93                 // Deleting the contents
94                 if (_pAnimationGroupImpl->animationList.GetCount() > 0)
95                 {
96                         int index = _pAnimationGroupImpl->animationList.GetCount();
97
98                         while (index > 0)
99                         {
100                                 _AnimationGroupImpl::AnimationStore animStore;
101
102                                 _pAnimationGroupImpl->animationList.GetAt(index - 1, animStore);
103
104                                 if (animStore.pAnimationBase)
105                                 {
106                                         delete animStore.pAnimationBase;
107                                         animStore.pAnimationBase = null;
108                                 }
109
110                                 index--;
111                         }
112
113                         _pAnimationGroupImpl->animationList.RemoveAll();
114                 }
115
116                 // Copying the contents
117                 int animationCount = rhs._pAnimationGroupImpl->animationList.GetCount();
118
119                 for (int index = 0; index < animationCount; index++)
120                 {
121                         _AnimationGroupImpl::AnimationStore animStore;
122
123                         rhs._pAnimationGroupImpl->animationList.GetAt(index, animStore);
124
125                         _AnimationGroupImpl::AnimationStore animStoreNew;
126                         animStoreNew.animTarget = animStore.animTarget;
127
128                         animStoreNew.pAnimationBase = _pAnimationGroupImpl->CloneAnimation(animStore.animTarget, *(animStore.pAnimationBase), r);
129                         SysTryReturn(NID_UI_ANIM, (animStoreNew.pAnimationBase), *this, r, "[%s] Failed to clone animation.", GetErrorMessage(r));
130
131                         r = _pAnimationGroupImpl->animationList.Add(animStoreNew);
132                         SysTryReturn(NID_UI_ANIM, (r == E_SUCCESS), *this, r, "[%s] Propagating.", GetErrorMessage(r));
133                 }
134         }
135
136         return *this;
137 }
138
139 bool
140 ParallelAnimationGroup::operator ==(const ParallelAnimationGroup& rhs) const
141 {
142         if (_pAnimationGroupImpl->animationList.GetCount() != rhs._pAnimationGroupImpl->animationList.GetCount())
143         {
144                 return false;
145         }
146
147         int animationCount = rhs._pAnimationGroupImpl->animationList.GetCount();
148
149         for (int index = 0; index < animationCount; index++)
150         {
151                 _AnimationGroupImpl::AnimationStore animStore;
152
153                 _pAnimationGroupImpl->animationList.GetAt(index, animStore);
154
155                 if (!(rhs._pAnimationGroupImpl->animationList.Contains(animStore)))
156                 {
157                         return false;
158                 }
159         }
160
161         return true;
162 }
163
164 bool
165 ParallelAnimationGroup::operator !=(const ParallelAnimationGroup& rhs) const
166 {
167         return !(*this == rhs);
168 }
169
170 bool
171 ParallelAnimationGroup::Equals(const Object& obj) const
172 {
173         const ParallelAnimationGroup* pParallelGrp = dynamic_cast< const ParallelAnimationGroup* >(&obj);
174         if (pParallelGrp == null)
175         {
176                 return false;
177         }
178
179         return (*this == *pParallelGrp);
180 }
181
182 int
183 ParallelAnimationGroup::GetHashCode(void) const
184 {
185         return GetAnimationCount();
186 }
187
188 void
189 ParallelAnimationGroup::RemoveAllAnimations(void)
190 {
191         int index = _pAnimationGroupImpl->animationList.GetCount() - 1;
192
193         while (index >= 0)
194         {
195                 _AnimationGroupImpl::AnimationStore animStore;
196
197                 _pAnimationGroupImpl->animationList.GetAt(index, animStore);
198
199                 delete animStore.pAnimationBase;
200                 animStore.pAnimationBase = null;
201
202                 index--;
203         }
204
205         _pAnimationGroupImpl->animationList.RemoveAll();
206 }
207
208 int
209 ParallelAnimationGroup::GetAnimationCount(void) const
210 {
211         return _pAnimationGroupImpl->animationList.GetCount();
212 }
213
214 result
215 ParallelAnimationGroup::AddAnimation(AnimationTargetType animTarget, const AnimationBase& animation)
216 {
217         SysTryReturnResult(NID_UI_ANIM, (animTarget >= ANIMATION_TARGET_NONE && animTarget <= ANIMATION_TARGET_MAX), E_INVALID_ARG, "Invalid argument(s) is used. animTarget is invalid.");
218
219         _AnimationGroupImpl::AnimationStore animStoreNew;
220
221         animStoreNew.animTarget = animTarget;
222
223         result r = E_SUCCESS;
224
225         animStoreNew.pAnimationBase = _pAnimationGroupImpl->CloneAnimation(animTarget, const_cast< AnimationBase& >(animation), r);
226         SysTryReturnResult(NID_UI_ANIM, (animStoreNew.pAnimationBase), r, "Failed to clone animation ");
227
228         int animationCount = _pAnimationGroupImpl->animationList.GetCount();
229         int index = 0;
230
231         _AnimationGroupImpl::AnimationStore animStore;
232
233         for (index = 0; index < animationCount; index++)
234         {
235                 _pAnimationGroupImpl->animationList.GetAt(index, animStore);
236
237                 if (animStore.animTarget == animTarget)
238                 {
239                         break;
240                 }
241         }
242
243         r = _pAnimationGroupImpl->animationList.Add(animStoreNew);
244         if (r != E_SUCCESS)
245         {
246                 SysLogException(NID_UI_ANIM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to add animation.");
247
248                 delete animStoreNew.pAnimationBase;
249                 animStoreNew.pAnimationBase = null;
250
251                 return E_SYSTEM;
252         }
253
254         if (index < animationCount)
255         {
256                 _pAnimationGroupImpl->animationList.RemoveAt(index);
257
258                 delete animStore.pAnimationBase;
259                 animStore.pAnimationBase = null;
260         }
261
262         return E_SUCCESS;
263 }
264
265 result
266 ParallelAnimationGroup::RemoveAnimation(AnimationTargetType animTarget)
267 {
268         SysTryReturnResult(NID_UI_ANIM, (animTarget >= ANIMATION_TARGET_NONE && animTarget <= ANIMATION_TARGET_MAX), E_INVALID_ARG, "Invalid argument(s) is used. animTarget is invalid.");
269
270         int animationCount = _pAnimationGroupImpl->animationList.GetCount();
271         _AnimationGroupImpl::AnimationStore animStore;
272
273         for (int index = 0; index < animationCount; index++)
274         {
275                 _pAnimationGroupImpl->animationList.GetAt(index, animStore);
276
277                 if (animStore.animTarget == animTarget)
278                 {
279                         _pAnimationGroupImpl->animationList.RemoveAt(index);
280
281                         delete animStore.pAnimationBase;
282                         animStore.pAnimationBase = null;
283
284                         return E_SUCCESS;
285                 }
286         }
287
288         return E_OBJ_NOT_FOUND;
289 }
290
291 AnimationBase*
292 ParallelAnimationGroup::GetAnimationN(AnimationTargetType animTarget) const
293 {
294         result r = E_SUCCESS;
295
296         int animationCount = _pAnimationGroupImpl->animationList.GetCount();
297         _AnimationGroupImpl::AnimationStore animStore;
298
299         for (int index = 0; index < animationCount; index++)
300         {
301                 _pAnimationGroupImpl->animationList.GetAt(index, animStore);
302
303                 if (animStore.animTarget == animTarget)
304                 {
305                         SysTryReturn(NID_UI_ANIM, (animStore.pAnimationBase), null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Animation is invalid.");
306
307                         AnimationBase *pAnimationBase = _pAnimationGroupImpl->CloneAnimation(animTarget, *(animStore.pAnimationBase), r);
308                         SysTryReturn(NID_UI_ANIM, (pAnimationBase), null, r, "[%s] Failed to clone animation.", GetErrorMessage(r));
309
310                         return pAnimationBase;
311                 }
312         }
313
314         return null;
315 }
316
317 bool
318 ParallelAnimationGroup::IsAnimationAdded(AnimationTargetType animTarget)
319 {
320         int animationCount = _pAnimationGroupImpl->animationList.GetCount();
321         _AnimationGroupImpl::AnimationStore animStore;
322
323         for (int index = 0; index < animationCount; index++)
324         {
325                 _pAnimationGroupImpl->animationList.GetAt(index, animStore);
326
327                 if (animStore.animTarget == animTarget)
328                 {
329                         return true;
330                 }
331         }
332
333         return false;
334 }
335
336 AnimationGroupType
337 ParallelAnimationGroup::GetType(void) const
338 {
339         return ANIMATION_GROUP_TYPE_PARALLEL;
340 }
341
342 }}}   // Tizen::Ui::Animations