Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / animations / FUiAnimControlAnimator.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        FUiAnimControlAnimator.cpp
20  * @brief       This file contains implementation of ControlAnimator class
21  *
22  * This file contains implementation of ControlAnimator class.
23  */
24
25 #include <FBaseSysLog.h>
26
27 #include <FUiCustomControlBase.h>
28
29 #include <FUiAnimControlAnimator.h>
30 #include <FUiAnimAnimationBase.h>
31 #include <FUiAnimDimensionAnimation.h>
32 #include <FUiAnimPointAnimation.h>
33 #include <FUiAnimRectangleAnimation.h>
34 #include <FUiAnimIntegerAnimation.h>
35 #include <FUiAnimFloatAnimation.h>
36 #include <FUiAnimRotateAnimation.h>
37
38 #include "FUiAnim_ControlAnimatorImpl.h"
39
40
41 using namespace Tizen::Base;
42 using namespace Tizen::Base::Collection;
43 using namespace Tizen::Graphics;
44 using namespace Tizen::Ui;
45
46
47 namespace Tizen { namespace Ui { namespace Animations
48 {
49
50 ///INIT_SYSCLASSTYPE(ControlAnimator);
51
52 ControlAnimator::ControlAnimator(void)
53         : _pControlAnimatorImpl(null)
54 {
55
56 }
57
58 ControlAnimator::~ControlAnimator(void)
59 {
60         delete _pControlAnimatorImpl;
61         _pControlAnimatorImpl = null;
62 }
63
64 result
65 ControlAnimator::Construct(const Control& source)
66 {
67         SysAssertf((_pControlAnimatorImpl == null), "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class.");
68
69         result r = E_SUCCESS;
70
71         _pControlAnimatorImpl = new (std::nothrow) _ControlAnimatorImpl(this);
72         SysTryReturnResult(NID_UI_ANIM, (_pControlAnimatorImpl), E_OUT_OF_MEMORY, "Memory allocation failed.");
73
74         r = _pControlAnimatorImpl->Construct(source);
75         SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to construct _ControlAnimatorImpl instance.");
76
77         return r;
78
79 CATCH:
80         delete _pControlAnimatorImpl;
81         _pControlAnimatorImpl = null;
82
83         return r;
84
85 }
86
87 result
88 ControlAnimator::StartUserAnimation(AnimationTargetType animTarget, const AnimationBase& animationBase)
89 {
90         SysTryReturnResult(NID_UI_ANIM, (animTarget > ANIMATION_TARGET_NONE && animTarget < ANIMATION_TARGET_MAX), E_INVALID_ARG,
91                                          "Invalid argument(s) is used. AnimationTargetType argument is invalid.");
92
93         SysTryReturnResult(NID_UI_ANIM, !(_pControlAnimatorImpl->IsAnimationTargetAnimating(animTarget)), E_INVALID_OPERATION,
94                            "Same AnimationTargetType is being animated.");
95
96         result r = E_SUCCESS;
97         int activeAnimationCount = _pControlAnimatorImpl->GetActiveAnimationListCount();
98
99         AnimationBase* pAnimBase = const_cast< AnimationBase* >(&animationBase);
100         SysTryReturnResult(NID_UI_ANIM, (pAnimBase != null), E_INVALID_ARG, "Invalid argument(s) is used. AnimationBase argument is invalid.");
101
102         Rectangle rect(0, 0, 0, 0);
103
104         SysTryReturnResult(NID_UI_ANIM, (_pControlAnimatorImpl->IsAnimatable(animTarget, rect, pAnimBase)), E_INVALID_ARG,
105                                          "Invalid argument(s) is used. AnimationBase argument is invalid.");
106
107         if (_pControlAnimatorImpl->IsAnimationSupported() == false)
108         {
109                 r = _pControlAnimatorImpl->SetControlProperty(animTarget, *pAnimBase);
110                 SysTryReturnResult(NID_UI_ANIM, (r == E_SUCCESS), E_SYSTEM, "A system error has been occurred. Failed to set control property.");
111
112                 return E_SUCCESS;
113         }
114
115         AnimationBase* pAnimationBase = null;
116         pAnimationBase = _pControlAnimatorImpl->CloneAnimation(animTarget, *pAnimBase);
117         SysTryReturnResult(NID_UI_ANIM, (pAnimationBase), E_SYSTEM, "A system error has been occurred. Failed to clone animation.");
118
119         if (animTarget == ANIMATION_TARGET_POSITION || animTarget == ANIMATION_TARGET_SIZE)
120         {
121                 _pControlAnimatorImpl->SetLogicalBounds(_pControlAnimatorImpl->GetControl().GetBounds());
122         }
123         else if (animTarget == ANIMATION_TARGET_ALPHA)
124         {
125                 _pControlAnimatorImpl->SetShowState(_pControlAnimatorImpl->GetControl().GetShowState());
126         }
127
128         if (animTarget == ANIMATION_TARGET_POSITION || animTarget == ANIMATION_TARGET_SIZE)
129         {
130                 _pControlAnimatorImpl->SetControlLogicalBounds(animTarget, *pAnimationBase);
131
132                 bool disable = false;
133                 bool propagation = false;
134
135                 result r = _pControlAnimatorImpl->DisableImplicitAnimation(disable);
136                 SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to disable implicit animation.");
137
138                 r = _pControlAnimatorImpl->DisableVisualElementPropagation(propagation);
139                 SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to disable visual element propagation.");
140
141                 r = _pControlAnimatorImpl->GetControl().SetBounds(_pControlAnimatorImpl->GetLogicalBounds());
142
143                 if (propagation)
144                 {
145                         _pControlAnimatorImpl->DisableVisualElementPropagation(propagation);
146                 }
147                 if (disable)
148                 {
149                         _pControlAnimatorImpl->DisableImplicitAnimation(disable);
150                 }
151
152                 SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to set bounds.");
153
154         }
155         else if (animTarget == ANIMATION_TARGET_ALPHA)
156         {
157                 _pControlAnimatorImpl->SetControlShowState(animTarget, *pAnimationBase);
158
159                 bool disable = false;
160                 bool propagation = false;
161
162                 result r = _pControlAnimatorImpl->DisableImplicitAnimation(disable);
163                 SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to enable/disable implicit animation.");
164
165                 r = _pControlAnimatorImpl->DisableVisualElementPropagation(propagation);
166                 SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to enable/disable visual element propagation.");
167
168                 r = _pControlAnimatorImpl->GetControl().SetShowState((_pControlAnimatorImpl->GetShowState()));
169                 if (propagation)
170                 {
171                         _pControlAnimatorImpl->DisableVisualElementPropagation(propagation);
172                 }
173                 if (disable)
174                 {
175                         _pControlAnimatorImpl->DisableImplicitAnimation(disable);
176                 }
177                 SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to set show state.");
178         }
179
180         //Create and play the Animation
181         r = _pControlAnimatorImpl->SetAnimation(animTarget, *pAnimationBase);
182         SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
183
184         _pControlAnimatorImpl->SetAnimationTargetAnimating(animTarget, true);
185
186         return r;
187
188 CATCH:
189         if (_pControlAnimatorImpl->DestroyAnimation(activeAnimationCount) != E_SUCCESS)
190         {
191                 SysLogException(NID_UI_ANIM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to destroy animation.");
192                 return E_SYSTEM;
193         }
194         return r;
195 }
196
197 result
198 ControlAnimator::StartUserAnimation(const AnimationGroup& animGroup)
199 {
200         result r = E_SUCCESS;
201         bool isAnimating = false;
202
203         ParallelAnimationGroup* pParallelAnimGrp = null;
204         SequentialAnimationGroup* pSequentialAnimGrp = null;
205
206         pParallelAnimGrp = dynamic_cast< ParallelAnimationGroup* >(const_cast< AnimationGroup* >(&animGroup));
207         pSequentialAnimGrp = dynamic_cast< SequentialAnimationGroup* >(const_cast< AnimationGroup* >(&animGroup));
208         SysTryReturnResult(NID_UI_ANIM, ((pParallelAnimGrp) || (pSequentialAnimGrp)), E_INVALID_ARG, "Invalid argument(s) is used. AnimationGroup argument is invalid.");
209
210         if (pParallelAnimGrp)
211         {
212                 SysTryReturnResult(NID_UI_ANIM, (pParallelAnimGrp->GetAnimationCount() > 0), E_INVALID_ARG, "Invalid argument(s) is used. No animation found in AnimationGroup.");
213
214                 for (int animType = (static_cast< int >(ANIMATION_TARGET_NONE) + 1); animType < (static_cast< int >(ANIMATION_TARGET_MAX)); animType++)
215                 {
216                         AnimationTargetType animTarget = static_cast< AnimationTargetType >(animType);
217                         AnimationBase* pAnimationBase = null;
218                         pAnimationBase = pParallelAnimGrp->GetAnimationN(animTarget);
219                         if (pAnimationBase != null)
220                         {
221                                 isAnimating = _pControlAnimatorImpl->IsAnimationTargetAnimating(animTarget);
222
223                                 Rectangle rect(0, 0, 0, 0);
224
225                                 bool animatable = _pControlAnimatorImpl->IsAnimatable(animTarget, rect, pAnimationBase);
226
227                                 delete pAnimationBase;
228
229                                 SysTryReturnResult(NID_UI_ANIM, (animatable), E_INVALID_ARG, "Invalid argument(s) is used. AnimationGroup argument is invalid.");
230                                 //The below check was removed for 2.0
231                                 SysTryReturnResult(NID_UI_ANIM, !(isAnimating), E_INVALID_OPERATION, "Same AnimationTargetType is being animated.");
232                         }
233                 }
234
235                 r = _pControlAnimatorImpl->SetGroupAnimation(pParallelAnimGrp);
236         }
237         else    //if (pSequentialAnimGrp)
238         {
239                 SysTryReturnResult(NID_UI_ANIM, (pSequentialAnimGrp->GetAnimationCount() > 0), E_INVALID_ARG, "Invalid argument(s) is used. No animation found in AnimationGroup.");
240
241                 for (int index = 0; index < pSequentialAnimGrp->GetAnimationCount(); index++)
242                 {
243                         AnimationTargetType animTarget = ANIMATION_TARGET_MAX;
244                         AnimationBase* pAnimationBase = null;
245                         pAnimationBase = pSequentialAnimGrp->GetAnimationAtN(index);
246                         animTarget = pSequentialAnimGrp->GetAnimationTargetTypeAt(index);
247
248                         if (pAnimationBase != null)
249                         {
250                                 isAnimating = _pControlAnimatorImpl->IsAnimationTargetAnimating(animTarget);
251
252                                 Rectangle rect(0, 0, 0, 0);
253
254                                 bool animatable = _pControlAnimatorImpl->IsAnimatable(animTarget, rect, pAnimationBase);
255
256                                 delete pAnimationBase;
257
258                                 SysTryReturnResult(NID_UI_ANIM, (animatable), E_INVALID_ARG, "Invalid argument(s) is used. AnimationGroup argument is invalid.");
259                                 //The below check should be removed for 2.0
260                                 SysTryReturnResult(NID_UI_ANIM, !(isAnimating), E_INVALID_OPERATION, "Same AnimationTargetType is being animated.");
261                         }
262                         else
263                         {
264                                 SysLogException(NID_UI_ANIM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. An animation in sequential group is null.");
265                                 return E_SYSTEM;
266                         }
267                 }
268
269                 r = _pControlAnimatorImpl->SetGroupAnimation(pSequentialAnimGrp);
270         }
271
272         return r;
273 }
274
275 result
276 ControlAnimator::StopAllAnimations(void)
277 {
278         SysTryReturnResult(NID_UI_ANIM, (_pControlAnimatorImpl->GetActiveAnimationListCount() > 0), E_SUCCESS, "No Active Animation.");
279
280         return _pControlAnimatorImpl->StopAllAnimations();
281 }
282
283 result
284 ControlAnimator::StopAnimation(ControlAnimatorTriggerType animTrigger)
285 {
286         SysTryReturnResult(NID_UI_ANIM, (_pControlAnimatorImpl), E_SYSTEM, "A system error has been occurred. Control animator is not constructed properly.");
287         SysTryReturnResult(NID_UI_ANIM, (animTrigger >= ANIMATION_TRIGGER_USER && animTrigger <= ANIMATION_TRIGGER_SHOW_STATE_CHANGE),
288                                                 E_INVALID_ARG, "Invalid argument(s) is used. ControlAnimatorTriggerType argument is invalid.");
289
290         return _pControlAnimatorImpl->StopAnimation(animTrigger);
291 }
292
293 AnimatorStatus
294 ControlAnimator::GetStatus(void) const
295 {
296         if (_pControlAnimatorImpl->IsAnimationSupported())
297         {
298                 _pControlAnimatorImpl->SetAnimatorStatus(ANIMATOR_STATUS_STOPPED);
299
300                 for (int animType = ((int) ANIMATION_TARGET_NONE + 1); animType < ((int) ANIMATION_TARGET_MAX); animType++)
301                 {
302                         if (_pControlAnimatorImpl->IsAnimationTargetAnimating(animType) == true)
303                         {
304                                 _pControlAnimatorImpl->SetAnimatorStatus(ANIMATOR_STATUS_PLAYING);
305                                 break;
306                         }
307                 }
308                 return _pControlAnimatorImpl->GetAnimatorStatus();
309         }
310         else
311         {
312                 SysLogException(NID_UI_ANIM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Animation support is unavailable.");
313                 return ANIMATOR_STATUS_STOPPED;
314         }
315 }
316
317 AnimatorStatus
318 ControlAnimator::GetStatus(AnimationTargetType animTarget) const
319 {
320         SysTryReturn(NID_UI_ANIM, (animTarget > ANIMATION_TARGET_NONE && animTarget < ANIMATION_TARGET_MAX), ANIMATOR_STATUS_STOPPED, E_INVALID_ARG,
321                            "Invalid argument(s) is used. AnimationTargetType argument is invalid.");
322
323         if (_pControlAnimatorImpl->IsAnimationSupported())
324         {
325                 if (_pControlAnimatorImpl->IsAnimationTargetAnimating(animTarget) == true)
326                 {
327                         return ANIMATOR_STATUS_PLAYING;
328                 }
329
330                 return ANIMATOR_STATUS_STOPPED;
331         }
332         else
333         {
334                 SysLogException(NID_UI_ANIM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Animation support is unavailable.");
335                 return ANIMATOR_STATUS_STOPPED;
336         }
337 }
338
339 result
340 ControlAnimator::AddControlAnimatorEventListener(IControlAnimatorEventListener& listener)
341 {
342         SysTryReturnResult(NID_UI_ANIM, _pControlAnimatorImpl->IsAnimationSupported(), E_UNSUPPORTED_OPERATION, "Animation is unsupported.");
343
344         return _pControlAnimatorImpl->AddControlAnimatorEventListener(listener);
345 }
346
347 result
348 ControlAnimator::RemoveControlAnimatorEventListener(IControlAnimatorEventListener& listener)
349 {
350         SysTryReturnResult(NID_UI_ANIM, (_pControlAnimatorImpl->IsAnimationSupported()), E_UNSUPPORTED_OPERATION, "Animation is unsupported.");
351
352         return _pControlAnimatorImpl->RemoveControlAnimatorEventListener(listener);
353 }
354
355 result
356 ControlAnimator::AddControlAnimatorDetailedEventListener(IControlAnimatorDetailedEventListener& listener)
357 {
358         SysTryReturnResult(NID_UI_ANIM, (_pControlAnimatorImpl->IsAnimationSupported()), E_UNSUPPORTED_OPERATION, "Animation is unsupported.");
359
360         return _pControlAnimatorImpl->AddControlAnimatorDetailedEventListener(listener);
361 }
362
363 result
364 ControlAnimator::RemoveControlAnimatorDetailedEventListener(IControlAnimatorDetailedEventListener& listener)
365 {
366         SysTryReturnResult(NID_UI_ANIM, (_pControlAnimatorImpl->IsAnimationSupported()), E_UNSUPPORTED_OPERATION, "Animation is unsupported.");
367
368         return _pControlAnimatorImpl->RemoveControlAnimatorDetailedEventListener(listener);
369 }
370
371 result
372 ControlAnimator::SetAnimation(ControlAnimatorTriggerType animTrigger, const AnimationGroup* pAnimationGroup)
373 {
374         SysTryReturnResult(NID_UI_ANIM, ((animTrigger >= ANIMATION_TRIGGER_POSITION_CHANGE) && (animTrigger <= ANIMATION_TRIGGER_SHOW_STATE_CHANGE)),
375                                                 E_INVALID_ARG, "Invalid argument(s) is used. ControlAnimatorTriggerType argument is invalid.");
376
377         if (pAnimationGroup == null)
378         {
379                 SysTryReturnResult(NID_UI_ANIM, (_pControlAnimatorImpl->GetStoredPropertyAnimationGroupType(animTrigger - 1) !=
380                                                   PROPERTY_ANIMATION_GROUP_TYPE_NONE), E_SUCCESS, "No custom implicit animation is set yet.");
381                 SysTryReturnResult(NID_UI_ANIM, (_pControlAnimatorImpl->GetPropertyGroupList(animTrigger - 1)), E_SUCCESS,
382                                                  "No custom implicit animation is set yet against this ControlAnimatorTriggerType.");
383
384                 _pControlAnimatorImpl->GetPropertyGroupList(animTrigger - 1)->RemoveAllAnimations();
385
386                 delete _pControlAnimatorImpl->GetPropertyGroupList(animTrigger - 1);
387                 _pControlAnimatorImpl->SetPropertyGroupList(animTrigger - 1, null);
388                 _pControlAnimatorImpl->SetStoredPropertyAnimationGroupType(animTrigger - 1, PROPERTY_ANIMATION_GROUP_TYPE_NONE);
389
390                 return E_SUCCESS;
391         }
392
393         SequentialAnimationGroup* pSequentialAnimGrp = null;
394         ParallelAnimationGroup* pParallelAnimGrp = null;
395         AnimationTargetType associatedAnimTarget = ANIMATION_TARGET_NONE;
396
397         pSequentialAnimGrp = dynamic_cast< SequentialAnimationGroup* >(const_cast< AnimationGroup* >(pAnimationGroup));
398         pParallelAnimGrp = dynamic_cast< ParallelAnimationGroup* >(const_cast< AnimationGroup* >(pAnimationGroup));
399         SysTryReturnResult(NID_UI_ANIM, ((pSequentialAnimGrp) || (pParallelAnimGrp)), E_INVALID_ARG, "Invalid argument(s) is used. AnimationGroup argument is invalid.");
400         SysTryReturnResult(NID_UI_ANIM, (pAnimationGroup->GetAnimationCount() > 0), E_INVALID_ARG, "Invalid argument(s) is used. No animations added to AnimationGroup.");
401
402         if (animTrigger == ANIMATION_TRIGGER_POSITION_CHANGE)
403         {
404                 associatedAnimTarget = ANIMATION_TARGET_POSITION;
405         }
406         else if (animTrigger == ANIMATION_TRIGGER_SIZE_CHANGE)
407         {
408                 associatedAnimTarget = ANIMATION_TARGET_SIZE;
409         }
410         else if (animTrigger == ANIMATION_TRIGGER_SHOW_STATE_CHANGE)
411         {
412                 associatedAnimTarget = ANIMATION_TARGET_ALPHA;
413         }
414
415         if (pSequentialAnimGrp)
416         {
417                 int targetCount = 0;
418                 for (int index = 0; index < pSequentialAnimGrp->GetAnimationCount(); index++)
419                 {
420                         AnimationTargetType animTarget = ANIMATION_TARGET_NONE;
421                         animTarget = pSequentialAnimGrp->GetAnimationTargetTypeAt(index);
422                         SysTryReturnResult(NID_UI_ANIM, ((animTarget > ANIMATION_TARGET_NONE) && (animTarget < ANIMATION_TARGET_MAX)), E_INVALID_ARG,
423                                                          "Invalid argument(s) is used. AnimationTargetType argument is invalid.");
424
425                         if (associatedAnimTarget == animTarget)
426                         {
427                                 targetCount++;
428                         }
429                 }
430                 SysTryReturnResult(NID_UI_ANIM, (targetCount >= 1), E_INVALID_ARG,
431                                                  "Invalid argument(s) is used. AnimationGroup should have at-least one animation of equivalent AnimationTargetType.");
432
433                 //Check for IsAnimatable() of all AnimationBase objects
434                 for (int index = 0; index < pSequentialAnimGrp->GetAnimationCount(); index++)
435                 {
436                         AnimationTargetType animTarget = ANIMATION_TARGET_NONE;
437                         AnimationBase* pAnimationBase = null;
438                         pAnimationBase = pSequentialAnimGrp->GetAnimationAtN(index);
439                         animTarget = pSequentialAnimGrp->GetAnimationTargetTypeAt(index);
440
441                         bool animatable = false;
442                         if (pAnimationBase)
443                         {
444                                 if (associatedAnimTarget != animTarget)
445                                 {
446                                         Rectangle rect(0, 0, 0, 0);
447
448                                         animatable = _pControlAnimatorImpl->IsAnimatable(animTarget, rect, pAnimationBase);
449                                 }
450
451                                 delete pAnimationBase;
452
453                                 if ((associatedAnimTarget != animTarget) && (!animatable))
454                                 {
455                                         SysLogException(NID_UI_ANIM, E_UNSUPPORTED_OPERATION, "[E_UNSUPPORTED_OPERATION] Control is not animable. Animations cannot be set to control.");
456                                         return E_UNSUPPORTED_OPERATION;
457                                 }
458                         }
459                         else
460                         {
461                                 SysLogException(NID_UI_ANIM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. An animation in sequential group animation is null.");
462                                 return E_SYSTEM;
463                         }
464                 }
465
466                 SequentialAnimationGroup* pSequentialAnimationGroup = null;
467                 pSequentialAnimationGroup = new (std::nothrow) SequentialAnimationGroup(*pSequentialAnimGrp);
468                 SysTryReturnResult(NID_UI_ANIM, (pSequentialAnimationGroup), E_OUT_OF_MEMORY, "Memory allocation failed.");
469
470                 if (pSequentialAnimationGroup->GetAnimationCount() != pSequentialAnimGrp->GetAnimationCount())
471                 {
472                         if (pSequentialAnimationGroup->GetAnimationCount() > 0)
473                         {
474                                 pSequentialAnimationGroup->RemoveAllAnimations();
475                         }
476
477                         delete pSequentialAnimationGroup;
478
479                         SysLogException(NID_UI_ANIM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to clone sequential group animation.");
480                         return E_SYSTEM;
481                 }
482
483                 if (_pControlAnimatorImpl->GetPropertyGroupList(animTrigger - 1))
484                 {
485                         _pControlAnimatorImpl->GetPropertyGroupList(animTrigger - 1)->RemoveAllAnimations();
486                         delete _pControlAnimatorImpl->GetPropertyGroupList(animTrigger - 1);
487                         _pControlAnimatorImpl->SetPropertyGroupList(animTrigger - 1, null);
488                         _pControlAnimatorImpl->SetStoredPropertyAnimationGroupType(animTrigger - 1, PROPERTY_ANIMATION_GROUP_TYPE_NONE);
489                 }
490                 _pControlAnimatorImpl->SetPropertyGroupList(animTrigger - 1, pSequentialAnimationGroup);
491                 _pControlAnimatorImpl->SetStoredPropertyAnimationGroupType(animTrigger - 1, PROPERTY_ANIMATION_GROUP_TYPE_SEQUENTIAL);
492
493                 return E_SUCCESS;
494         }
495         else    //if (pParallelAnimGrp)
496         {
497                 bool isPresent = false;
498
499                 if (animTrigger == ANIMATION_TRIGGER_POSITION_CHANGE)
500                 {
501                         isPresent = pParallelAnimGrp->IsAnimationAdded(ANIMATION_TARGET_POSITION);
502                 }
503                 else if (animTrigger == ANIMATION_TRIGGER_SIZE_CHANGE)
504                 {
505                         isPresent = pParallelAnimGrp->IsAnimationAdded(ANIMATION_TARGET_SIZE);
506                 }
507                 else if (animTrigger == ANIMATION_TRIGGER_SHOW_STATE_CHANGE)
508                 {
509                         isPresent = pParallelAnimGrp->IsAnimationAdded(ANIMATION_TARGET_ALPHA);
510                 }
511
512                 SysTryReturnResult(NID_UI_ANIM, (isPresent), E_INVALID_ARG,
513                                                  "Invalid argument(s) is used. AnimationGroup should have one animation of equivalent AnimationTargetType.");
514
515                 //Check for IsAnimatable() of all AnimationBase objects
516                 for (int animType = ((int) ANIMATION_TARGET_NONE + 1); animType < ((int) ANIMATION_TARGET_MAX); animType++)
517                 {
518                         AnimationTargetType animTarget = static_cast< AnimationTargetType >(animType);
519                         if (pParallelAnimGrp->IsAnimationAdded(animTarget) == false)
520                         {
521                                 continue;
522                         }
523                         AnimationBase* pAnimationBase = null;
524                         bool animatable = false;
525
526                         pAnimationBase = pParallelAnimGrp->GetAnimationN(animTarget);
527                         if (pAnimationBase)
528                         {
529                                 if (associatedAnimTarget != animTarget)
530                                 {
531                                         Rectangle rect(0, 0, 0, 0);
532
533                                         animatable = _pControlAnimatorImpl->IsAnimatable(animTarget, rect, pAnimationBase);
534                                 }
535
536                                 delete pAnimationBase;
537
538                                 SysTryReturnResult(NID_UI_ANIM, !((associatedAnimTarget != animTarget) && (!animatable)), E_UNSUPPORTED_OPERATION,
539                                                                  "Animations cannot be set to control.");
540
541                         }
542                         else
543                         {
544                                 SysLogException(NID_UI_ANIM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. An animation in parallel group animation is null.");
545                                 return E_SYSTEM;
546                         }
547                 }
548
549                 ParallelAnimationGroup* pParallelAnimationGroup = null;
550                 pParallelAnimationGroup = new (std::nothrow) ParallelAnimationGroup(*pParallelAnimGrp);
551                 SysTryReturnResult(NID_UI_ANIM, (pParallelAnimationGroup), E_OUT_OF_MEMORY, "Memory allocation failed.");
552
553                 if (pParallelAnimationGroup->GetAnimationCount() != pParallelAnimGrp->GetAnimationCount())
554                 {
555                         if (pParallelAnimationGroup->GetAnimationCount() > 0)
556                         {
557                                 pParallelAnimationGroup->RemoveAllAnimations();
558                         }
559
560                         delete pParallelAnimationGroup;
561
562                         SysLogException(NID_UI_ANIM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to clone ParallelAnimationGroup instance.");
563                         return E_SYSTEM;
564                 }
565
566                 if (_pControlAnimatorImpl->GetPropertyGroupList(animTrigger - 1))
567                 {
568                         _pControlAnimatorImpl->GetPropertyGroupList(animTrigger - 1)->RemoveAllAnimations();
569                         delete _pControlAnimatorImpl->GetPropertyGroupList(animTrigger - 1);
570                         _pControlAnimatorImpl->SetPropertyGroupList(animTrigger - 1, null);
571                         _pControlAnimatorImpl->SetStoredPropertyAnimationGroupType(animTrigger - 1, PROPERTY_ANIMATION_GROUP_TYPE_NONE);
572                 }
573                 _pControlAnimatorImpl->SetPropertyGroupList(animTrigger - 1, pParallelAnimationGroup);
574                 _pControlAnimatorImpl->SetStoredPropertyAnimationGroupType(animTrigger - 1, PROPERTY_ANIMATION_GROUP_TYPE_PARALLEL);
575
576                 return E_SUCCESS;
577         }
578 }
579
580 AnimationGroup*
581 ControlAnimator::GetAnimationN(ControlAnimatorTriggerType animTrigger) const
582 {
583         SysTryReturn(NID_UI_ANIM, ((animTrigger >= ANIMATION_TRIGGER_POSITION_CHANGE) && (animTrigger <= ANIMATION_TRIGGER_SHOW_STATE_CHANGE)),
584                                 null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument(s) is used. animTrigger is invalid.");
585         SysTryReturn(NID_UI_ANIM, (_pControlAnimatorImpl->GetStoredPropertyAnimationGroupType(animTrigger - 1) != PROPERTY_ANIMATION_GROUP_TYPE_NONE),
586                                 null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. No implicit animations set to control.");
587
588         if (_pControlAnimatorImpl->GetStoredPropertyAnimationGroupType(animTrigger - 1) == PROPERTY_ANIMATION_GROUP_TYPE_PARALLEL)
589         {
590                 ParallelAnimationGroup* pTempParallelAnimGroup = dynamic_cast< ParallelAnimationGroup* >(_pControlAnimatorImpl->GetPropertyGroupList(animTrigger - 1));
591                 SysTryReturn(NID_UI_ANIM, (pTempParallelAnimGroup), null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to get ParallelAnimationGroup instance.");
592
593                 ParallelAnimationGroup* pParallelAnimationGroup = new (std::nothrow) ParallelAnimationGroup(*pTempParallelAnimGroup);
594                 SysTryReturn(NID_UI_ANIM, (pParallelAnimationGroup), null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
595                 SysTryReturn(NID_UI_ANIM, (pParallelAnimationGroup->GetAnimationCount() > 0), null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.  Failed to create ParallelAnimationGroup.");
596
597                 return pParallelAnimationGroup;
598         }
599         else if (_pControlAnimatorImpl->GetStoredPropertyAnimationGroupType(animTrigger - 1) == PROPERTY_ANIMATION_GROUP_TYPE_SEQUENTIAL)
600         {
601                 SequentialAnimationGroup* pTempSequentialAnimGroup = dynamic_cast< SequentialAnimationGroup* >(_pControlAnimatorImpl->GetPropertyGroupList(animTrigger - 1));
602                 SysTryReturn(NID_UI_ANIM, (pTempSequentialAnimGroup), null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to clone SequentialAnimationGroup.");
603
604                 SequentialAnimationGroup* pSequentialAnimationGroup = new (std::nothrow) SequentialAnimationGroup(*pTempSequentialAnimGroup);
605                 SysTryReturn(NID_UI_ANIM, (pSequentialAnimationGroup), null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
606                 SysTryReturn(NID_UI_ANIM, (pSequentialAnimationGroup->GetAnimationCount() > 0), null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to create SequentialAnimationGroup instance.");
607
608                 return pSequentialAnimationGroup;
609         }
610         else
611         {
612                 SysLogException(NID_UI_ANIM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Invalid property animation group type provided.");
613                 return null;
614         }
615 }
616
617 result
618 ControlAnimator::SetPosition(int x, int y)
619 {
620         SysTryReturnResult(NID_UI_ANIM, (_pControlAnimatorImpl->IsAnimationTargetAnimating(ANIMATION_TARGET_POSITION) == false), E_INVALID_OPERATION, "Same AnimationTargetType is already being animated.");
621
622         result r = E_SUCCESS;
623
624         Control& controlRef = _pControlAnimatorImpl->GetControl();
625         Rectangle controlBounds = controlRef.GetBounds();
626         Point newPosition = Point(x, y);
627         Point currentPosition = controlRef.GetPosition();
628
629         SysTryReturnResult(NID_UI_ANIM, (controlRef.IsMovable()), E_UNSUPPORTED_OPERATION, "Bounds cannot be modified.");
630
631         //CustomControl s Condition check
632         CustomControlBase* pControlBase = dynamic_cast< CustomControlBase* >(&controlRef);
633
634         if (pControlBase)
635         {
636                 _ControlImpl* pControlImpl = _ControlImpl::GetInstance(_pControlAnimatorImpl->GetControl());
637                 pControlImpl->OnBoundsChanging(Rectangle(x, y, controlRef.GetWidth(), controlRef.GetHeight()));
638         }
639
640         int activeAnimationCount = _pControlAnimatorImpl->GetActiveAnimationListCount();
641         AnimationBase* pAnimationBase = null;
642
643         if (_pControlAnimatorImpl->GetStoredPropertyAnimationGroupType(ANIMATION_TRIGGER_POSITION_CHANGE - 1) == PROPERTY_ANIMATION_GROUP_TYPE_NONE)
644         {
645                 if (currentPosition == newPosition)
646                 {
647                         return E_SUCCESS;
648                 }
649
650                 PointAnimation* pPointAnim = new (std::nothrow) PointAnimation(currentPosition, newPosition, 400, ANIMATION_INTERPOLATOR_LINEAR);
651                 SysTryReturnResult(NID_UI_ANIM, (pPointAnim), E_OUT_OF_MEMORY, "Memory allocation failed.");
652
653                 pAnimationBase = pPointAnim;
654
655                 Rectangle rect(x, y, 0, 0);
656
657                 if (!(_pControlAnimatorImpl->IsAnimatable(ANIMATION_TARGET_POSITION, rect, pAnimationBase, ANIMATION_TRIGGER_POSITION_CHANGE)))
658                 {
659                         delete pAnimationBase;
660
661                         SysLogException(NID_UI_ANIM, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument(s) is used. Animation type or position is invalid.");
662                         return E_INVALID_ARG;
663                 }
664                 if (_pControlAnimatorImpl->IsAnimationSupported() == false)
665                 {
666                         r = _pControlAnimatorImpl->SetControlProperty(ANIMATION_TARGET_POSITION, *pAnimationBase);
667                         if (r != E_SUCCESS)
668                         {
669                                 SysLogException(NID_UI_ANIM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to set control property.");
670                                 r = E_SYSTEM;
671                         }
672
673                         delete pAnimationBase;
674
675                         return r;
676                 }
677                 else
678                 {
679                         _pControlAnimatorImpl->SetLogicalBounds(controlRef.GetBounds());
680                         _pControlAnimatorImpl->SetControlLogicalBounds(ANIMATION_TARGET_POSITION, *pAnimationBase);
681
682                         bool disable = false;
683                         bool propagation = false;
684
685                         result r = _pControlAnimatorImpl->DisableImplicitAnimation(disable);
686                         SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to disable/enable implicit animation.");
687
688                         r = _pControlAnimatorImpl->DisableVisualElementPropagation(propagation);
689                         SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to disable/enable visual element propagation.");
690
691                         r = controlRef.SetBounds(_pControlAnimatorImpl->GetLogicalBounds());
692
693                         if (propagation)
694                         {
695                                 _pControlAnimatorImpl->DisableVisualElementPropagation(propagation);
696                         }
697                         if (disable)
698                         {
699                                 _pControlAnimatorImpl->DisableImplicitAnimation(disable);
700                         }
701
702                         SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to set bounds.");
703                         r = _pControlAnimatorImpl->SetAnimation(ANIMATION_TARGET_POSITION, *pAnimationBase, ANIMATION_TRIGGER_POSITION_CHANGE);
704                         SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
705                 }
706
707         }
708         else
709         {
710                 Rectangle logicalBounds(x, y, controlBounds.width, controlBounds.height);
711
712                 _pControlAnimatorImpl->SetLogicalBounds(logicalBounds);
713
714                 //Need to call control bounds inside StartCustomImplicitAnimation
715                 r = _pControlAnimatorImpl->StartCustomImplicitAnimation(ANIMATION_TRIGGER_POSITION_CHANGE, x, y, controlBounds.width,
716                                                                                                                                 controlBounds.height,
717                                                                                                                                 false);
718                 SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to set logical bounds.");
719         }
720
721         //When Control's property is set with End Bounds in Custom Implicit animation params, it should return from here without animation
722         if (_pControlAnimatorImpl->IsAnimationSupported() == false)
723         {
724                 return E_SUCCESS;
725         }
726
727         _pControlAnimatorImpl->SetAnimationTargetStatus(ANIMATION_TRIGGER_POSITION_CHANGE);
728
729         return r;
730
731 CATCH:
732         if (pAnimationBase)
733         {
734                 if (_pControlAnimatorImpl->DestroyAnimation(*pAnimationBase, ANIMATION_TARGET_POSITION) == E_SUCCESS)
735                 {
736                         pAnimationBase = null;
737                 }
738                 else
739                 {
740                         SysLogException(NID_UI_ANIM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to destroy animation.");
741                         r = E_SYSTEM;
742                 }
743         }
744
745         SysTryReturnResult(NID_UI_ANIM, (_pControlAnimatorImpl->DestroyAnimation(activeAnimationCount) == E_SUCCESS),
746                                            E_SYSTEM, "A system error has been occurred. Failed to destroy animation.");
747
748         return r;
749 }
750
751 result
752 ControlAnimator::SetPosition(const Point& Position)
753 {
754         return SetPosition(Position.x, Position.y);
755 }
756
757 result
758 ControlAnimator::SetSize(int width, int height)
759 {
760         SysTryReturnResult(NID_UI_ANIM, (_pControlAnimatorImpl->IsAnimationTargetAnimating(ANIMATION_TARGET_SIZE) == false), E_INVALID_OPERATION, "Same AnimationTargetType is being animated.");
761         SysTryReturnResult(NID_UI_ANIM, ((width > 0) && (height > 0)), E_INVALID_ARG, "Invalid argument(s) is used. width = %d, height = %d", width, height);
762
763         result r = E_SUCCESS;
764         Control& controlRef = _pControlAnimatorImpl->GetControl();
765         Rectangle controlBounds = controlRef.GetBounds();
766         Dimension newSize = Dimension(width, height);
767         Dimension currentSize = controlRef.GetSize();
768
769         SysTryReturnResult(NID_UI_ANIM, (controlRef.IsResizable()), E_UNSUPPORTED_OPERATION, "Bounds cannot be modified.");
770
771         //CustomControl Bounds Condition check
772         CustomControlBase* pControlBase = dynamic_cast< CustomControlBase* >(&controlRef);
773         if (pControlBase)
774         {
775                 Dimension dim(width, height);
776                 _ControlImpl* pControlImpl = _ControlImpl::GetInstance(_pControlAnimatorImpl->GetControl());
777                 pControlImpl->OnEvaluateSize(dim);
778         }
779         else
780         {
781                 SysTryReturnResult(NID_UI_ANIM, !((width < controlRef.GetMinimumSize().width) ||
782                                                         (height < controlRef.GetMinimumSize().height) ||
783                                                         (width > controlRef.GetMaximumSize().width) ||
784                                                         (height > controlRef.GetMaximumSize().height)), E_UNSUPPORTED_OPERATION, "Bounds cannot be modified.");
785         }
786
787         int activeAnimationCount = _pControlAnimatorImpl->GetActiveAnimationListCount();
788         AnimationBase* pAnimationBase = null;
789
790         if (_pControlAnimatorImpl->GetStoredPropertyAnimationGroupType(ANIMATION_TRIGGER_SIZE_CHANGE - 1) == PROPERTY_ANIMATION_GROUP_TYPE_NONE)
791         {
792                 if (currentSize == newSize)
793                 {
794                         return E_SUCCESS;
795                 }
796
797                 DimensionAnimation* pDimensionAnim = new (std::nothrow) DimensionAnimation(currentSize, newSize, 400, ANIMATION_INTERPOLATOR_LINEAR);
798                 SysTryReturnResult(NID_UI_ANIM, (pDimensionAnim), E_OUT_OF_MEMORY, "Memory allocation failed.");
799
800                 pAnimationBase = pDimensionAnim;
801
802                 Rectangle rect(0, 0, width, height);
803
804                 if (!(_pControlAnimatorImpl->IsAnimatable(ANIMATION_TARGET_SIZE, rect, pAnimationBase, ANIMATION_TRIGGER_SIZE_CHANGE)))
805                 {
806                         delete pAnimationBase;
807
808                         SysLogException(NID_UI_ANIM, E_INVALID_ARG, "Invalid argument(s) is used. Animation type or size is invalid.");
809                         return E_INVALID_ARG;
810                 }
811
812                 if (_pControlAnimatorImpl->IsAnimationSupported() == false)
813                 {
814                         r = _pControlAnimatorImpl->SetControlProperty(ANIMATION_TARGET_SIZE, *pAnimationBase);
815
816                         if (E_SUCCESS != r)
817                         {
818                                 SysLogException(NID_UI_ANIM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Control property is not set.");
819                                 r = E_SYSTEM;
820                         }
821
822                         delete pAnimationBase;
823
824                         return r;
825                 }
826                 else
827                 {
828                         _pControlAnimatorImpl->SetLogicalBounds(controlRef.GetBounds());
829                         _pControlAnimatorImpl->SetControlLogicalBounds(ANIMATION_TARGET_SIZE, *pAnimationBase);
830
831                         bool disable = false;
832                         bool propagation = false;
833
834                         result r = _pControlAnimatorImpl->DisableImplicitAnimation(disable);
835                         SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to disable/enable implicit animation.");
836
837                         r = _pControlAnimatorImpl->DisableVisualElementPropagation(propagation);
838                         SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to disable/enable visual element propagation.");
839
840                         r = controlRef.SetBounds(_pControlAnimatorImpl->GetLogicalBounds());
841
842                         if (propagation)
843                         {
844                                 _pControlAnimatorImpl->DisableVisualElementPropagation(propagation);
845                         }
846                         if (disable)
847                         {
848                                 _pControlAnimatorImpl->DisableImplicitAnimation(disable);
849                         }
850
851                         SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to set bounds.");
852
853                         //Play the animation
854                         r = _pControlAnimatorImpl->SetAnimation(ANIMATION_TARGET_SIZE, *pAnimationBase, ANIMATION_TRIGGER_SIZE_CHANGE);
855                         SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
856                 }
857         }
858         else
859         {
860                 Rectangle logicalBounds(controlBounds.x, controlBounds.y, width, height);
861                 _pControlAnimatorImpl->SetLogicalBounds(logicalBounds);
862                 //Call control set bounds inside StartCustomImplicitAnimation
863                 //start custom Implicit animation
864                 r = _pControlAnimatorImpl->StartCustomImplicitAnimation(ANIMATION_TRIGGER_SIZE_CHANGE, controlBounds.x, controlBounds.y, width, height, false);
865                 SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to start custom implicit animation.");
866         }
867         //When Control's property is set with End Bounds in Custom Implicit animation params, it should return from here without animation
868         if (_pControlAnimatorImpl->IsAnimationSupported() == false)
869         {
870                 return E_SUCCESS;
871         }
872
873         _pControlAnimatorImpl->SetAnimationTargetStatus(ANIMATION_TRIGGER_SIZE_CHANGE);
874
875         return r;
876
877 CATCH:
878         if (pAnimationBase)
879         {
880                 if (_pControlAnimatorImpl->DestroyAnimation(*pAnimationBase, ANIMATION_TARGET_SIZE) != E_SUCCESS)
881                 {
882                         pAnimationBase = null;
883                 }
884                 else
885                 {
886                         SysLogException(NID_UI_ANIM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to destroy animation.");
887                         r = E_SYSTEM;
888                 }
889         }
890
891         SysTryReturnResult(NID_UI_ANIM, (_pControlAnimatorImpl->DestroyAnimation(activeAnimationCount) == E_SUCCESS),
892                                            E_SYSTEM, "A system error has been occurred. Failed to destroy animation.");
893
894         return r;
895 }
896
897 result
898 ControlAnimator::SetSize(const Dimension& size)
899 {
900         return SetSize(size.width, size.height);
901 }
902
903 result
904 ControlAnimator::SetBounds(int x, int y, int width, int height)
905 {
906         SysTryReturnResult(NID_UI_ANIM, (_pControlAnimatorImpl->IsAnimationTargetAnimating(ANIMATION_TARGET_POSITION) == false), E_INVALID_OPERATION, "Same AnimationTargetType being animated.");
907         SysTryReturnResult(NID_UI_ANIM, (_pControlAnimatorImpl->IsAnimationTargetAnimating(ANIMATION_TARGET_SIZE) == false), E_INVALID_OPERATION, "Same AnimationTargetType being animated.");
908         SysTryReturnResult(NID_UI_ANIM, (width >= 0 && height >= 0), E_INVALID_ARG, "Invalid argument(s) is used. width = %d, height = %d", width, height);
909
910         result r = E_SUCCESS;
911         Control& controlRef = _pControlAnimatorImpl->GetControl();
912         Rectangle newBounds = Rectangle(x, y, width, height);
913         Rectangle currentBounds = controlRef.GetBounds();
914
915         SysTryReturnResult(NID_UI_ANIM, !((controlRef.IsMovable() == false) || (controlRef.IsResizable() == false)), E_UNSUPPORTED_OPERATION, "Bounds cannot be modified.");
916
917         if (controlRef.IsResizable() == true)
918         {
919                 //CustomControl Bounds Condition check
920                 CustomControlBase* pControlBase = dynamic_cast< CustomControlBase* >(&controlRef);
921
922                 if (pControlBase)
923                 {
924                         Rectangle rect(x, y, width, height);
925                         _ControlImpl* pControlImpl = _ControlImpl::GetInstance(_pControlAnimatorImpl->GetControl());
926                         pControlImpl->OnBoundsChanging(rect);
927                 }
928                 else
929                 {
930                         SysTryReturnResult(NID_UI_ANIM, !((width < controlRef.GetMinimumSize().width) ||
931                                                                 (height < controlRef.GetMinimumSize().height) ||
932                                                                 (width > controlRef.GetMaximumSize().width) ||
933                                                                 (height > controlRef.GetMaximumSize().height)), E_UNSUPPORTED_OPERATION, "Bounds cannot be modified.");
934                 }
935         }
936
937         Point newPosition = Point(x, y);
938         Point currentPosition = controlRef.GetPosition();
939         Dimension newSize = Dimension(width, height);
940         Dimension currentSize = controlRef.GetSize();
941         int activeAnimationCount = _pControlAnimatorImpl->GetActiveAnimationListCount();
942         AnimationBase* pPointAnimationBase = null;
943         AnimationBase* pDimensionAnimationBase = null;
944         Rectangle logicalBounds(x, y, width, height);
945         _pControlAnimatorImpl->SetLogicalBounds(logicalBounds);
946
947         if ((_pControlAnimatorImpl->GetStoredPropertyAnimationGroupType(ANIMATION_TRIGGER_POSITION_CHANGE - 1) == PROPERTY_ANIMATION_GROUP_TYPE_NONE) &&
948                 (_pControlAnimatorImpl->GetStoredPropertyAnimationGroupType(ANIMATION_TRIGGER_SIZE_CHANGE - 1) == PROPERTY_ANIMATION_GROUP_TYPE_NONE))
949         {
950                 if (currentBounds == newBounds)
951                 {
952                         return E_SUCCESS;
953                 }
954         }
955
956         //Position Animation
957         if (_pControlAnimatorImpl->GetStoredPropertyAnimationGroupType(ANIMATION_TRIGGER_POSITION_CHANGE - 1) == PROPERTY_ANIMATION_GROUP_TYPE_NONE)
958         {
959                 pPointAnimationBase = new (std::nothrow) PointAnimation(currentPosition, newPosition, 400, ANIMATION_INTERPOLATOR_LINEAR);
960                 SysTryReturnResult(NID_UI_ANIM, (pPointAnimationBase), E_OUT_OF_MEMORY, "Memory allocation failed.");
961
962                 if (_pControlAnimatorImpl->IsAnimationSupported() == false)
963                 {
964                         r = _pControlAnimatorImpl->SetControlProperty(ANIMATION_TARGET_POSITION, *pPointAnimationBase);
965
966                         delete pPointAnimationBase;
967                         pPointAnimationBase = null;
968
969                         //Do not return if success, set size Bounds and then return.
970                         SysTryReturnResult(NID_UI_ANIM, (r == E_SUCCESS), r, "Control property is not set.");
971                 }
972                 else
973                 {
974                         //Create and set the animation to the layer
975                         _pControlAnimatorImpl->SetControlLogicalBounds(ANIMATION_TARGET_POSITION, *pPointAnimationBase);
976
977                         bool disable = false;
978                         bool propagation = false;
979
980                         result r = _pControlAnimatorImpl->DisableImplicitAnimation(disable);
981                         SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to disable/enable implicit animation.");
982
983                         r = _pControlAnimatorImpl->DisableVisualElementPropagation(propagation);
984                         SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to disable/enable visual element propagation.");
985
986                         r = controlRef.SetBounds(_pControlAnimatorImpl->GetLogicalBounds());
987
988                         if (propagation)
989                         {
990                                 _pControlAnimatorImpl->DisableVisualElementPropagation(propagation);
991                         }
992                         if (disable)
993                         {
994                                 _pControlAnimatorImpl->DisableImplicitAnimation(disable);
995                         }
996
997                         SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to set bounds.");
998
999                         r = _pControlAnimatorImpl->SetAnimation(ANIMATION_TARGET_POSITION, *pPointAnimationBase, ANIMATION_TRIGGER_POSITION_CHANGE);
1000                         SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
1001                 }
1002         }
1003         else
1004         {
1005                 //call control Setbounds API inside StartCustomImplicitAnimation
1006                 r = _pControlAnimatorImpl->StartCustomImplicitAnimation(ANIMATION_TRIGGER_POSITION_CHANGE, x, y, width, height, false);
1007                 SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to start custom implicit animation.");
1008         }
1009
1010         //Size Animation
1011         if (_pControlAnimatorImpl->GetStoredPropertyAnimationGroupType(ANIMATION_TRIGGER_SIZE_CHANGE - 1) == PROPERTY_ANIMATION_GROUP_TYPE_NONE)
1012         {
1013                 DimensionAnimation* pDimensionAnim = new (std::nothrow) DimensionAnimation(currentSize, newSize, 400, ANIMATION_INTERPOLATOR_LINEAR);
1014                 SysTryReturnResult(NID_UI_ANIM, (pDimensionAnim), E_OUT_OF_MEMORY, "Memory allocation failed.");
1015                 pDimensionAnimationBase = pDimensionAnim;
1016
1017                 if (_pControlAnimatorImpl->IsAnimationSupported() == false)
1018                 {
1019                         r = _pControlAnimatorImpl->SetControlProperty(ANIMATION_TARGET_SIZE, *pDimensionAnimationBase);
1020                         if (E_SUCCESS != r)
1021                         {
1022                                 SysLogException(NID_UI_ANIM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Control property is not set.");
1023                                 r = E_SYSTEM;
1024                         }
1025
1026                         delete pDimensionAnimationBase;
1027
1028                         return r;
1029                 }
1030                 else
1031                 {
1032                         _pControlAnimatorImpl->SetControlLogicalBounds(ANIMATION_TARGET_SIZE, *pDimensionAnimationBase);
1033
1034                         bool disable = false;
1035                         bool propagation = false;
1036
1037                         result r = _pControlAnimatorImpl->DisableImplicitAnimation(disable);
1038                         SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to disable/enable implicit animation.");
1039
1040                         r = _pControlAnimatorImpl->DisableVisualElementPropagation(propagation);
1041                         SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to disable/enable visual element propagation.");
1042
1043                         r = controlRef.SetBounds(_pControlAnimatorImpl->GetLogicalBounds());
1044
1045                         if (propagation)
1046                         {
1047                                 _pControlAnimatorImpl->DisableVisualElementPropagation(propagation);
1048                         }
1049                         if (disable)
1050                         {
1051                                 _pControlAnimatorImpl->DisableImplicitAnimation(disable);
1052                         }
1053
1054                         SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to set bounds.");
1055
1056                         r = _pControlAnimatorImpl->SetAnimation(ANIMATION_TARGET_SIZE, *pDimensionAnimationBase, ANIMATION_TRIGGER_SIZE_CHANGE);
1057                         SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
1058                 }
1059         }
1060         else
1061         {
1062                 //call control setbounds inside StartCustomImplicitAnimation
1063                 r = _pControlAnimatorImpl->StartCustomImplicitAnimation(ANIMATION_TRIGGER_SIZE_CHANGE, x, y, width, height, false);
1064                 SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to start custom implicit animation.");
1065         }
1066
1067         //When Control's property is set with End Bounds in Custom Implicit animation params, it should return from here without animation
1068         if (_pControlAnimatorImpl->IsAnimationSupported() == false)
1069         {
1070                 return E_SUCCESS;
1071         }
1072
1073         _pControlAnimatorImpl->SetAnimationTargetStatus(ANIMATION_TRIGGER_POSITION_CHANGE);
1074         _pControlAnimatorImpl->SetAnimationTargetStatus(ANIMATION_TRIGGER_SIZE_CHANGE);
1075
1076         return r;
1077
1078 CATCH:
1079         if (pPointAnimationBase)
1080         {
1081                 if (_pControlAnimatorImpl->DestroyAnimation(*pPointAnimationBase, ANIMATION_TARGET_POSITION) != E_SUCCESS)
1082                 {
1083                         pPointAnimationBase = null;
1084                 }
1085                 else
1086                 {
1087                         SysLogException(NID_UI_ANIM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to destroy animation.");
1088                         r = E_SYSTEM;
1089                 }
1090         }
1091         if (pDimensionAnimationBase)
1092         {
1093                 if (_pControlAnimatorImpl->DestroyAnimation(*pDimensionAnimationBase, ANIMATION_TARGET_SIZE) != E_SUCCESS)
1094                 {
1095                         pDimensionAnimationBase = null;
1096                 }
1097                 else
1098                 {
1099                         SysLogException(NID_UI_ANIM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to destroy animation.");
1100                         r = E_SYSTEM;
1101                 }
1102         }
1103
1104         SysTryReturnResult(NID_UI_ANIM, (_pControlAnimatorImpl->DestroyAnimation(activeAnimationCount) == E_SUCCESS),
1105                                            E_SYSTEM, "A system error has been occurred. Failed to destroy animation.");
1106
1107         return r;
1108 }
1109
1110 result
1111 ControlAnimator::SetBounds(const Rectangle& rect)
1112 {
1113         return SetBounds(rect.x, rect.y, rect.width, rect.height);
1114 }
1115
1116 result
1117 ControlAnimator::SetShowState(bool show)
1118 {
1119         SysTryReturnResult(NID_UI_ANIM, (_pControlAnimatorImpl->IsAnimationTargetAnimating(ANIMATION_TARGET_ALPHA) == false), E_INVALID_OPERATION, "Same AnimationTargetType being animated.");
1120
1121         result r = E_SUCCESS;
1122         Control& controlRef = _pControlAnimatorImpl->GetControl();
1123         int activeAnimationCount = _pControlAnimatorImpl->GetActiveAnimationListCount();
1124         bool currentShowState = controlRef.GetShowState();
1125         bool newShowState = show;
1126         FloatAnimation* pFloatAnim = null;
1127         AnimationBase* pAnimationBase = null;
1128
1129         if (_pControlAnimatorImpl->GetStoredPropertyAnimationGroupType(ANIMATION_TRIGGER_SHOW_STATE_CHANGE - 1) == PROPERTY_ANIMATION_GROUP_TYPE_NONE)
1130         {
1131                 SysTryReturnResult(NID_UI_ANIM, (currentShowState != newShowState), E_SUCCESS, "Current show state of control is same as new show state.");
1132
1133                 pFloatAnim = new (std::nothrow) FloatAnimation(((newShowState) ? (0.0f) : (1.0f)), ((newShowState) ? (1.0f) : (0.0f)), 400, ANIMATION_INTERPOLATOR_LINEAR);
1134                 SysTryReturnResult(NID_UI_ANIM, (pFloatAnim), E_OUT_OF_MEMORY, "Memory allocation failed.");
1135                 pAnimationBase = pFloatAnim;
1136
1137                 Rectangle rect(0, 0, 0, 0);
1138
1139                 if (!(_pControlAnimatorImpl->IsAnimatable(ANIMATION_TARGET_ALPHA, rect, pAnimationBase, ANIMATION_TRIGGER_SHOW_STATE_CHANGE)))
1140                 {
1141                         delete pAnimationBase;
1142
1143                         SysLogException(NID_UI_ANIM, E_INVALID_ARG, "Invalid argument(s) is used. Custom implicit animation parameters are wrong.");
1144                         return E_INVALID_ARG;
1145                 }
1146                 if (_pControlAnimatorImpl->IsAnimationSupported() == false)
1147                 {
1148                         r = _pControlAnimatorImpl->SetControlProperty(ANIMATION_TARGET_ALPHA, *pAnimationBase);
1149                         if (E_SUCCESS != r)
1150                         {
1151                                 SysLogException(NID_UI_ANIM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Control property is not set.");
1152                                 r = E_SYSTEM;
1153                         }
1154
1155                         delete pAnimationBase;
1156
1157                         return r;
1158                 }
1159                 else
1160                 {
1161                         _pControlAnimatorImpl->SetControlShowState(ANIMATION_TARGET_ALPHA, *pAnimationBase);
1162
1163
1164                         bool disable = false;
1165                         bool propagation = false;
1166
1167                         result r = _pControlAnimatorImpl->DisableImplicitAnimation(disable);
1168                         SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to disable/enable implicit animation.");
1169
1170                         r = _pControlAnimatorImpl->DisableVisualElementPropagation(propagation);
1171                         SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to disable/enable visual element propagation.");
1172
1173                         r = _pControlAnimatorImpl->GetControl().SetShowState((_pControlAnimatorImpl->GetShowState()));
1174
1175                         if (propagation)
1176                         {
1177                                 _pControlAnimatorImpl->DisableVisualElementPropagation(propagation);
1178                         }
1179                         if (disable)
1180                         {
1181                                 _pControlAnimatorImpl->DisableImplicitAnimation(disable);
1182                         }
1183
1184                         SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to set show state.");
1185
1186                         r = _pControlAnimatorImpl->SetAnimation(ANIMATION_TARGET_ALPHA, *pAnimationBase, ANIMATION_TRIGGER_SHOW_STATE_CHANGE);
1187                         SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
1188                 }
1189         }
1190         else
1191         {
1192                 _pControlAnimatorImpl->SetShowState(newShowState);
1193                 //Call control set show state inside StartCustomImplicitAnimation
1194                 r = _pControlAnimatorImpl->StartCustomImplicitAnimation(ANIMATION_TRIGGER_SHOW_STATE_CHANGE, 0, 0, 0, 0, newShowState);
1195                 SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to start custom implicit animation.");
1196         }
1197         //When Control's property is set with End ShowState in Custom Implicit animation params, it should return from here without animation
1198         if (_pControlAnimatorImpl->IsAnimationSupported() == false)
1199         {
1200                 return E_SUCCESS;
1201         }
1202
1203         _pControlAnimatorImpl->SetAnimationTargetStatus(ANIMATION_TRIGGER_SHOW_STATE_CHANGE);
1204
1205         return r;
1206
1207 CATCH:
1208         if (pAnimationBase)
1209         {
1210                 if (_pControlAnimatorImpl->DestroyAnimation(*pAnimationBase, ANIMATION_TARGET_ALPHA) != E_SUCCESS)
1211                 {
1212                         pAnimationBase = null;
1213                 }
1214                 else
1215                 {
1216                         SysLogException(NID_UI_ANIM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to deallocate memory.");
1217                         r = E_SYSTEM;
1218                 }
1219         }
1220
1221         if (_pControlAnimatorImpl->DestroyAnimation(activeAnimationCount) != E_SUCCESS)
1222         {
1223                 SysLogException(NID_UI_ANIM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to deallocate memory.");
1224                 r = E_SYSTEM;
1225         }
1226         SysTryReturnResult(NID_UI_ANIM, (_pControlAnimatorImpl->DestroyAnimation(activeAnimationCount) == E_SUCCESS),
1227                                            E_SYSTEM, "A system error has been occurred. Failed to destroy animation.");
1228         return r;
1229 }
1230
1231 bool
1232 ControlAnimator::IsAnimationSupported(AnimationTargetType animTarget) const
1233 {
1234         switch (animTarget)
1235         {
1236         case ANIMATION_TARGET_POSITION:
1237                 return _pControlAnimatorImpl->GetControl().IsMovable();
1238
1239         case ANIMATION_TARGET_SIZE:
1240                 return _pControlAnimatorImpl->GetControl().IsResizable();
1241
1242         case ANIMATION_TARGET_ALPHA:
1243                 return true;
1244
1245         case ANIMATION_TARGET_ROTATION:
1246                 return true;
1247
1248         default:
1249                 return false;
1250         }
1251 }
1252
1253
1254 }}}             // Tizen::Ui::Animations
1255