Fix bug on OnSceneDeactivated call arguments.
[framework/osp/uifw.git] / src / ui / scenes / FUiScenes_SceneManagerImpl.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 #include <new>
19 #include <unique_ptr.h>
20 #include <FAppUiApp.h>
21 #include <FAppIAppFrame.h>
22 #include <FIo.h>
23 #include <FUiControl.h>
24 #include <FUiCtrlFrame.h>
25 #include <FUiCtrlForm.h>
26 #include <FUiCtrlPanel.h>
27 #include <FUiAnimFrameAnimator.h>
28 #include <FUiAnimControlAnimator.h>
29 #include <FUiAnimAnimationTransaction.h>
30 #include <FUiScenesSceneManager.h>
31 #include <FUiScenesScene.h>
32 #include <FUiScenesISceneEventListener.h>
33 #include <FUiScenesISceneManagerEventListener.h>
34 #include <FUiScenesISceneTransitionPolicyProvider.h>
35 #include <FUiScenesIFormFactory.h>
36 #include <FUiScenesIPanelFactory.h>
37 #include <FUiScenesForwardSceneTransition.h>
38 #include <FUiScenesBackwardSceneTransition.h>
39 #include <FBaseSysLog.h>
40 #include "FUiScenes_SceneImpl.h"
41 #include "FUiScenes_SceneManagerImpl.h"
42 #include "FUiScenes_SceneTransitionImpl.h"
43 #include "FUiAnim_FrameAnimatorImpl.h"
44 #include "FUi_Control.h"
45 #include "FUi_ControlManager.h"
46 #include "FUi_ContainerImpl.h"
47 #include "FUiCtrl_FrameImpl.h"
48
49
50 using namespace Tizen::Base;
51 using namespace Tizen::Base::Runtime;
52 using namespace Tizen::Base::Collection;
53 using namespace Tizen::App;
54 using namespace Tizen::Io;
55 using namespace Tizen::Ui;
56 using namespace Tizen::Ui::Controls;
57 using namespace Tizen::Ui::Animations;
58 using namespace Tizen::Graphics;
59
60
61 namespace Tizen { namespace Ui { namespace Scenes
62 {
63
64 // HashMapT assist template
65 template<class T>
66 class _StringHashCodeProvider
67         : public IHashCodeProviderT <T>
68 {
69 public:
70         virtual int
71         GetHashCode(const T& obj) const
72         {
73                 String& objString = static_cast <String&>(const_cast <T&>(obj));
74                 return objString.GetHashCode();
75         }
76 };
77 template<class T>
78 class _StringComparer
79         : public IComparerT <T>
80 {
81 public:
82         virtual result
83         Compare(const T& obj1, const T& obj2, int& cmp) const
84         {
85                 String& objString1 = static_cast <String&>(const_cast <T&>(obj1));
86                 String& objString2 = static_cast <String&>(const_cast <T&>(obj2));
87                 cmp = objString1.CompareTo(objString2);
88                 return E_SUCCESS;
89         }
90 };
91
92
93 _SceneManagerImpl::_SceneDescription::_SceneDescription(const String& descriptionFormId, const String& descriptionPanelId)
94         : formId(descriptionFormId)
95         , panelId(descriptionPanelId)
96 {
97
98 }
99
100 _SceneManagerImpl::_SceneManagerImpl(void)
101         : __currentSceneId(L"")
102         , __pCurrentScene(null)
103         , __pFormFactory(null)
104         , __pPanelFactory(null)
105         , __pPolicyProvider(null)
106         , __destroyReservedScene(L"")
107         , __pCorrespondFrame(null)
108         , __correspondFrameControlHandle()
109         , __sceneTransitionProgressing(false)
110         , __pDisabledForm(null)
111 {
112         for (int i = 0; i < FRAME_ANIMATOR_FORM_TRANSITION_ANIMATION_MAX; i++)
113         {
114                 static const long ANIMATION_DURATION = 250L;
115                 __animationDescriptions[i].animationType = FrameAnimatorFormTransitionAnimation(i);
116                 __animationDescriptions[i].duration = ANIMATION_DURATION;
117                 __animationDescriptions[i].interpolatorType = ANIMATION_INTERPOLATOR_LINEAR;
118         }
119         __sceneTransitionMutex.Create();
120 }
121
122 _SceneManagerImpl::~_SceneManagerImpl(void)
123 {
124         bool memoryError = false;
125
126         std::unique_ptr<IMapEnumeratorT<String, _SceneDescription*> > pMapEnum(__sceneMap.GetMapEnumeratorN());
127         if (pMapEnum)
128         {
129                 while (pMapEnum->MoveNext() == E_SUCCESS)
130                 {
131                         _SceneDescription* pValue = null;
132                         pMapEnum->GetValue(pValue);
133                         delete pValue;
134                 }
135         }
136         else
137         {
138                 memoryError = true;
139         }
140
141         std::unique_ptr<IMapEnumeratorT<String, SceneTransition*> > pTransitionMapEnum(__transitionMap.GetMapEnumeratorN());
142         if (pTransitionMapEnum)
143         {
144                 while (pTransitionMapEnum->MoveNext() == E_SUCCESS)
145                 {
146                         SceneTransition* pValue = null;
147                         pTransitionMapEnum->GetValue(pValue);
148                         delete pValue;
149                 }
150         }
151         else
152         {
153                 memoryError = true;
154         }
155
156         std::unique_ptr<IMapEnumeratorT<SceneId, Scene*> > pSceneContainerEnum(__sceneContainer.GetMapEnumeratorN());
157         if (pSceneContainerEnum)
158         {
159                 while (pSceneContainerEnum->MoveNext() == E_SUCCESS)
160                 {
161                         Scene* pValue = null;
162                         pSceneContainerEnum->GetValue(pValue);
163                         delete pValue;
164                 }
165         }
166         else
167         {
168                 memoryError = true;
169         }
170
171         if (memoryError)
172         {
173                 SysLogException(NID_UI_SCENES, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
174         }
175 }
176
177 result
178 _SceneManagerImpl::Construct(void)
179 {
180         result r = E_SUCCESS;
181         static _StringHashCodeProvider <String> sceneHashCodeProvider;
182         static _StringComparer <String> strComparer;
183
184         r = __sceneContainer.Construct(0, 0, sceneHashCodeProvider, strComparer);
185         SysTryReturn(NID_UI_SCENES, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
186         r = __formContainer.Construct(0, 0, sceneHashCodeProvider, strComparer);
187         SysTryReturn(NID_UI_SCENES, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
188         r = __formToPanelMultiMap.Construct(0, 0, sceneHashCodeProvider, strComparer);
189         SysTryReturn(NID_UI_SCENES, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
190         r = __sceneMap.Construct(0, 0, sceneHashCodeProvider, strComparer);
191         SysTryReturn(NID_UI_SCENES, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
192         r = __transitionMap.Construct(0, 0, sceneHashCodeProvider, strComparer);
193         SysTryReturn(NID_UI_SCENES, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
194         r = __formIdMap.Construct(0, 0, sceneHashCodeProvider, strComparer);
195         SysTryReturn(NID_UI_SCENES, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
196
197         r = __sceneControlEvent.Construct();
198         SysTryReturn(NID_UI_SCENES, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
199         r = __sceneControlEvent.AddListener(dynamic_cast<_ISceneControlEventListener&>(*this));
200         SysTryReturn(NID_UI_SCENES, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
201
202         UiApp* pUiApp = UiApp::GetInstance();
203         SysTryReturn(NID_UI_SCENES, pUiApp != null, null, E_SYSTEM,
204                                  "[%s] A system error has been occurred. UiApp::GetInstance failed.", GetErrorMessage(E_SYSTEM));
205         Frame* pFrame = pUiApp->GetFrameAt(0);
206         SysTryReturn(NID_UI_SCENES, pFrame != null, null, E_SYSTEM,
207                                  "[%s] A system error has been occurred. pUiApp->GetFrameAt(0) return null.", GetErrorMessage(E_SYSTEM));
208         __pCorrespondFrame = pFrame;
209         _ContainerImpl* pFrameWindowImpl = _ContainerImpl::GetInstance(*__pCorrespondFrame);
210         SysTryReturn(NID_UI_SCENES, pFrameWindowImpl != null, null, E_SYSTEM,
211                                  "[%s] A system error has been occurred. _ContainerImpl::GetInstance failed.", GetErrorMessage(E_SYSTEM));
212         __correspondFrameControlHandle = pFrameWindowImpl->GetCore().GetHandle();
213
214         return E_SUCCESS;
215 }
216
217 result
218 _SceneManagerImpl::RegisterFormFactory(const IFormFactory& formFactory)
219 {
220         __pFormFactory = const_cast <IFormFactory*>(&formFactory);
221
222         return E_SUCCESS;
223 }
224
225 result
226 _SceneManagerImpl::RegisterPanelFactory(const IPanelFactory& panelFactory)
227 {
228         __pPanelFactory = const_cast <IPanelFactory*>(&panelFactory);
229
230         return E_SUCCESS;
231 }
232
233 result
234 _SceneManagerImpl::RegisterScene(const SceneId& sceneId, const String& formId, const String& panelId)
235 {
236         result r = E_SUCCESS;
237         _SceneDescription* pSceneDescription = null;
238         bool isContains = false;
239
240         SysTryReturnResult(NID_UI_SCENES, !(sceneId.IsEmpty() || formId.IsEmpty()), E_INVALID_ARG,
241                                            "Invalid argument is used. String length of sceneId=%d, formId=%d",
242                                            sceneId.GetLength(), formId.GetLength());
243
244         r = __sceneMap.ContainsKey(sceneId, isContains);
245         SysTryReturn(NID_UI_SCENES, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
246         SysTryReturnResult(NID_UI_SCENES, !isContains, E_OBJ_ALREADY_EXIST, "Specified sceneId already exist.");
247
248         __formIdMap.ContainsKey(formId, isContains);
249         if (panelId.IsEmpty())
250         {
251                 SysTryReturnResult(NID_UI_SCENES, !isContains, E_INVALID_ARG, "Specified formId already exist. Only 'PanelScene' can share a formId for use as base form.");
252         }
253
254         if (!isContains)
255         {
256                 __formIdMap.Add(formId, 1);
257         }
258         else
259         {
260                 int refCount = 0;
261                 __formIdMap.GetValue(formId, refCount);
262                 ++refCount;
263                 __formIdMap.SetValue(formId, refCount);
264         }
265
266         pSceneDescription = new (std::nothrow) _SceneDescription(formId, panelId);
267         SysTryReturnResult(NID_UI_SCENES, pSceneDescription != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
268
269         r = __sceneMap.Add(sceneId, pSceneDescription);
270         SysTryCatch(NID_UI_SCENES, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
271         return r;
272
273 CATCH:
274         delete pSceneDescription;
275         return r;
276 }
277
278 result
279 _SceneManagerImpl::RegisterScene(const String& resourceId)
280 {
281         static const wchar_t RESOUCE_FILE_PATH[] = L"res/";
282         static const wchar_t RESOUCE_FILE_EXT[] = L".xml";
283         static const wchar_t RESOUCE_FILE_NORMAL[] = L"screen-size-normal/";
284         static const xmlChar* pElementWorkflow = reinterpret_cast<const xmlChar*>("Workflow");
285         static const xmlChar* pElementScene = reinterpret_cast<const xmlChar*>("Scene");
286         static const xmlChar* pElementSceneTransition = reinterpret_cast<const xmlChar*>("SceneTransition");
287         result r = E_SUCCESS;
288
289         _ControlManager* pControlManager = _ControlManager::GetInstance();
290         SysTryReturnResult(NID_UI_SCENES, pControlManager != null, E_SYSTEM,
291                                            "A system error has been occurred. Unable to get the control manager.");
292         Dimension screenSize = pControlManager->GetScreenSize();
293
294         const String appRootPath = Tizen::App::App::GetInstance()->GetAppRootPath();
295         String filePath;
296         // Formating path for current resolution: [AppRootPath/][res/][width]x[height]/[resourceId][.xml]
297         r = filePath.Format(FILENAME_MAX, L"%ls%ls%dx%d/%ls%ls",
298                                                 appRootPath.GetPointer(), RESOUCE_FILE_PATH, screenSize.width, screenSize.height,
299                                                 resourceId.GetPointer(), RESOUCE_FILE_EXT);
300         SysTryReturnResult(NID_UI_SCENES, !IsFailed(r), E_SYSTEM, "A system error has been occurred. File path formatting failed.");
301         SysLog(NID_UI_SCENES, "RegisterScene: res path: %ls", filePath.GetPointer());
302
303         if (!File::IsFileExist(filePath))
304         {       // File not exist on specific resolution then try again: [AppRootPath/][res/][screen-size-normal/][resourceId][.xml]
305                 filePath.Format(FILENAME_MAX, L"%ls%ls%ls%ls%ls",
306                                                 appRootPath.GetPointer(), RESOUCE_FILE_PATH, RESOUCE_FILE_NORMAL,
307                                                 resourceId.GetPointer(), RESOUCE_FILE_EXT);
308                 SysTryReturnResult(NID_UI_SCENES, !IsFailed(r), E_SYSTEM, "A system error has been occurred. File path formatting failed.");
309                 SysLog(NID_UI_SCENES, "RegisterScene: 2nd try - res path: %ls", filePath.GetPointer());
310                 if (!pControlManager->IsCoordinateSystemLogical() || !File::IsFileExist(filePath))
311                 {
312                         SysLogException(NID_UI_SCENES, E_FILE_NOT_FOUND, "[%s] File could not be found. File path=%ls",
313                                                         GetErrorMessage(E_FILE_NOT_FOUND), filePath.GetPointer());
314                         return E_FILE_NOT_FOUND;
315                 }
316         }
317
318         std::unique_ptr<ByteBuffer> pfilePathBuffer(Tizen::Base::Utility::StringUtil::StringToUtf8N(filePath));
319         SysTryReturnResult(NID_UI_SCENES, pfilePathBuffer != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
320
321         xmlDocPtr docPtr = xmlParseFile(reinterpret_cast<const char*>(pfilePathBuffer->GetPointer()));
322         SysTryReturnResult(NID_UI_SCENES, docPtr != null, E_SYSTEM,
323                                            "A system error has been occurred. Can not parse xml file: %ls", filePath.GetPointer());
324
325         xmlNodePtr rootNodePtr = xmlDocGetRootElement(docPtr);
326         SysTryReturnResult(NID_UI_SCENES, rootNodePtr != null, E_SYSTEM,
327                                            "A system error has been occurred. Can not find root node");
328
329         // Visit xml nodes
330         for (xmlNodePtr nodePtr = rootNodePtr; nodePtr != null; nodePtr = nodePtr->next)        // Visit sibling node
331         {       // Get element 'Workflow'
332                 if ((nodePtr->type == XML_ELEMENT_NODE) && (xmlStrcmp(nodePtr->name, pElementWorkflow) == 0))
333                 {       // and Get child - 'Scene's and 'SceneTransition's
334                         for (xmlNodePtr childNodePtr = nodePtr->children; childNodePtr != null; childNodePtr = childNodePtr->next) // Visit sibling
335                         {       // Get element 'Scene's and 'SceneTransition's
336                                 if (childNodePtr->type == XML_ELEMENT_NODE)
337                                 {       // Check E_OBJ_ALREADY_EXIST(continue) and E_OUT_OF_MEMORY(break) for all case.
338                                         if (xmlStrcmp(childNodePtr->name, pElementScene) == 0)
339                                         {
340                                                 result regResult = RegisterScene(childNodePtr);
341                                                 if (IsFailed(regResult))
342                                                 {
343                                                         SysTryCatch(NID_UI_SCENES, regResult != E_OUT_OF_MEMORY, r = regResult, regResult,
344                                                                                 "[%s] Propagating.", GetErrorMessage(regResult));
345                                                         if (regResult == E_OBJ_ALREADY_EXIST)
346                                                         {
347                                                                 r = regResult;
348                                                         }
349                                                 }
350                                         }
351                                         else
352                                         if (xmlStrcmp(childNodePtr->name, pElementSceneTransition) == 0)
353                                         {
354                                                 result regResult = RegisterSceneTransition(childNodePtr);
355                                                 if (IsFailed(regResult))
356                                                 {
357                                                         SysTryCatch(NID_UI_SCENES, regResult != E_OUT_OF_MEMORY, r = regResult, regResult,
358                                                                                 "[%s] Propagating.", GetErrorMessage(regResult));
359                                                         if (regResult == E_OBJ_ALREADY_EXIST)
360                                                         {
361                                                                 r = regResult;
362                                                         }
363                                                 }
364                                         }
365                                 } // 'Scene' and 'SceneTransition'
366                         } // Children of 'Workflow'
367                 } // Element 'Workflow'
368         }// Root node sibling
369
370         xmlFreeDoc(docPtr);
371         return r;
372
373 CATCH:
374         xmlFreeDoc(docPtr);
375         return r;
376 }
377
378 result
379 _SceneManagerImpl::UnregisterScene(const SceneId& sceneId)
380 {
381         result r = E_SUCCESS;
382         _SceneDescription* pSceneDescription = null;
383
384         SysTryReturnResult(NID_UI_SCENES, !sceneId.IsEmpty(), E_INVALID_ARG, "Invalid argument is used. sceneId is empty.");
385
386         r = __sceneMap.GetValue(sceneId, pSceneDescription);
387         SysTryReturn(NID_UI_SCENES, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
388
389         // Remove FormId from __formIdMap
390         if (pSceneDescription)
391         {
392                 bool isContains = false;
393                 __formIdMap.ContainsKey(pSceneDescription->formId, isContains);
394                 if (isContains)
395                 {
396                         int refCount = 0;
397                         __formIdMap.GetValue(pSceneDescription->formId, refCount);
398                         --refCount;
399                         if (refCount <= 0)
400                         {
401                                 __formIdMap.Remove(pSceneDescription->formId);
402                         }
403                         else
404                         {
405                                 __formIdMap.SetValue(pSceneDescription->formId, refCount);
406                         }
407                 }
408         }
409
410         r = __sceneMap.Remove(sceneId);
411         SysTryReturn(NID_UI_SCENES, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
412
413         delete pSceneDescription;
414         return r;
415 }
416
417 result
418 _SceneManagerImpl::AddSceneManagerEventListener(ISceneManagerEventListener& sceneManagerEventListener)
419 {
420         result r = E_SUCCESS;
421         ISceneManagerEventListener* pListener = &sceneManagerEventListener;
422         bool alreadyExist = __sceneManagerEventListenerList.Contains(pListener);
423         SysTryReturnResult(NID_UI_SCENES, !alreadyExist, E_OBJ_ALREADY_EXIST, "The event listener already exist.");
424         r = __sceneManagerEventListenerList.Add(pListener);
425         SysTryReturn(NID_UI_SCENES, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
426
427         return E_SUCCESS;
428 }
429
430 result
431 _SceneManagerImpl::RemoveSceneManagerEventListener(ISceneManagerEventListener& sceneManagerEventListener)
432 {
433         result r = E_SUCCESS;
434         ISceneManagerEventListener* pListener = &sceneManagerEventListener;
435         r = __sceneManagerEventListenerList.Remove(pListener);
436         SysTryReturn(NID_UI_SCENES, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
437
438         return E_SUCCESS;
439 }
440
441 result
442 _SceneManagerImpl::AddSceneEventListener(const SceneId& sceneId, ISceneEventListener& sceneEventListener)
443 {
444         result r = E_SUCCESS;
445         Scene* pScene = null;
446         _SceneImpl* pSceneImpl = null;
447
448         pScene = GetSceneFromContainer(sceneId);
449         SysTryReturnResult(NID_UI_SCENES, pScene != null, E_INVALID_ARG, "Invalid argument is used. The sceneId is not valid.");
450         pSceneImpl = _SceneImpl::GetInstance(*pScene);
451         SysTryReturnResult(NID_UI_SCENES, pSceneImpl != null, E_INVALID_ARG, "Invalid argument is used. The sceneId is not valid.");
452         r = pSceneImpl->AddSceneEventListener(sceneEventListener);
453         SysTryReturn(NID_UI_SCENES, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
454
455         return E_SUCCESS;
456 }
457
458 result
459 _SceneManagerImpl::RemoveSceneEventListener(const SceneId& sceneId, ISceneEventListener& sceneEventListener)
460 {
461         result r = E_SUCCESS;
462         Scene* pScene = null;
463         _SceneImpl* pSceneImpl = null;
464
465         pScene = GetSceneFromContainer(sceneId);
466         SysTryReturnResult(NID_UI_SCENES, pScene != null, E_INVALID_ARG, "Invalid argument is used. The sceneId is not valid.");
467         pSceneImpl = _SceneImpl::GetInstance(*pScene);
468         SysTryReturnResult(NID_UI_SCENES, pSceneImpl != null, E_INVALID_ARG, "Invalid argument is used. The sceneId is not valid.");
469         r = pSceneImpl->RemoveSceneEventListener(sceneEventListener);
470         SysTryReturn(NID_UI_SCENES, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
471
472         return E_SUCCESS;
473 }
474
475 result
476 _SceneManagerImpl::SetSceneAnimationProvider(const SceneId& sceneId, ISceneAnimationProvider* pSceneAnimationProvider)
477 {
478         result r = E_SUCCESS;
479         Scene* pScene = null;
480         _SceneImpl* pSceneImpl = null;
481
482         pScene = GetSceneFromContainer(sceneId);
483         SysTryReturnResult(NID_UI_SCENES, pScene != null, E_INVALID_ARG, "Invalid argument is used. The sceneId is not valid.");
484         pSceneImpl = _SceneImpl::GetInstance(*pScene);
485         SysTryReturnResult(NID_UI_SCENES, pSceneImpl != null, E_INVALID_ARG, "Invalid argument is used. The sceneId is not valid.");
486         r = pSceneImpl->SetSceneAnimationProvider(pSceneAnimationProvider);
487         SysTryReturn(NID_UI_SCENES, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
488
489         return E_SUCCESS;
490 }
491
492 result
493 _SceneManagerImpl::SetSceneTransitionPolicyProvider(ISceneTransitionPolicyProvider* pSceneTransitionPolicyProvider)
494 {
495         __pPolicyProvider = pSceneTransitionPolicyProvider;
496
497         return E_SUCCESS;
498 }
499
500 result
501 _SceneManagerImpl::SetFormTransitionAnimationDefaultValues(SceneTransitionAnimationType animationType, long duration,
502                                                                                                                    AnimationInterpolatorType interpolatorType)
503 {
504         static const long DURATION_MIN = 0;
505         static const long DURATION_MAX = 1000;
506
507         SysTryReturnResult(NID_UI_SCENES, (SCENE_TRANSITION_ANIMATION_TYPE_LEFT <= animationType &&
508                                            animationType <= SCENE_TRANSITION_ANIMATION_TYPE_DEPTH_OUT), E_INVALID_ARG,
509                                            "Invalid argument is used. animationType=%d", animationType);
510         SysTryReturnResult(NID_UI_SCENES, (DURATION_MIN <= duration && duration <= DURATION_MAX), E_INVALID_ARG,
511                                            "Invalid argument is used. duration=%d", duration);
512         __animationDescriptions[animationType - SCENE_TRANSITION_ANIMATION_TYPE_LEFT].duration = duration;
513         __animationDescriptions[animationType - SCENE_TRANSITION_ANIMATION_TYPE_LEFT].interpolatorType = interpolatorType;
514
515         return E_SUCCESS;
516 }
517
518 result
519 _SceneManagerImpl::GoForward(const ForwardSceneTransition& sceneTransition, const Tizen::Base::Collection::IList* pArgs)
520 {
521         //## Temporary - Currently no support Non-Recursive Lock(Mutex).
522         SysTryReturnResult(NID_UI_SCENES, !__sceneTransitionProgressing, E_IN_PROGRESS, "Previous operation in progressing");
523
524         result r = __sceneTransitionMutex.TryToAcquire();
525         SysTryReturnResult(NID_UI_SCENES, r != E_OBJECT_LOCKED, E_IN_PROGRESS, "Previous operation in progressing");
526         SysTryReturnResult(NID_UI_SCENES, r != E_SYSTEM, E_SYSTEM, "A system error has been occurred.");
527         r = __sceneTransitionMutex.Acquire();
528         SysTryReturnResult(NID_UI_SCENES, !IsFailed(r), E_SYSTEM, "A system error has been occurred. Mutex acquire failed.");
529         __sceneTransitionProgressing = true;    //## Temporary
530
531         SceneId sceneId;
532         _SceneTransitionImpl forwardSceneTransition;
533
534         forwardSceneTransition = *_SceneTransitionImpl::GetInstance(static_cast<const SceneTransition&>(sceneTransition));
535         SysTryCatch(NID_UI_SCENES, forwardSceneTransition.GetDirection() == SCENE_TRANSITION_DIRECTION_FORWARD, r= E_INVALID_ARG,
536                                 E_INVALID_ARG, "[%s] Invalid argument is used. sceneTransition's direction is not SCENE_TRANSITION_DIRECTION_FORWARD.", GetErrorMessage(E_INVALID_ARG));
537
538         sceneId = forwardSceneTransition.GetDestinationSceneId();
539         if (sceneId.GetLength() > 0)
540         {
541                 // Prevent transit to current scene
542                 SysTryCatch(NID_UI_SCENES, __currentSceneId != sceneId, r = E_INVALID_ARG, E_INVALID_ARG,
543                                         "[%s] Invalid argument is used. Can't forward to current Scene.", GetErrorMessage(E_INVALID_ARG));
544
545                 // Stop animation
546                 if (!IsAnimationCompleted())
547                 {
548                         r = StopAllAnimations();
549                         SysTryCatch(NID_UI_SCENES, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
550                 }
551
552                 // Go to the specified scene
553                 r = GotoScene(true, sceneId, forwardSceneTransition.GetAnimationType(),
554                                           forwardSceneTransition.GetHistoryOption(), forwardSceneTransition.GetDestroyOption(), pArgs);
555                 SysTryCatch(NID_UI_SCENES, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
556         }
557         else
558         {       // Transition via PolicyProvider
559                 SysTryCatch(NID_UI_SCENES, __pPolicyProvider != null, r = E_INVALID_STATE, E_INVALID_STATE,
560                                         "[%s] SceneManager is in an invalid state. Policy provider not registered.", GetErrorMessage(E_INVALID_STATE));
561
562                 SceneId nextSceneId = __pPolicyProvider->GetNextScene(__currentSceneId, pArgs);
563                 SysTryCatch(NID_UI_SCENES, !nextSceneId.IsEmpty(), r = E_INVALID_STATE, E_INVALID_STATE,
564                                         "[%s] SceneManager is in an invalid state. Policy provider does not know next scene. Current scene= %ls",
565                                         GetErrorMessage(E_INVALID_STATE), __currentSceneId.GetPointer());
566
567                 // Prevent transit to current scene
568                 SysTryCatch(NID_UI_SCENES, __currentSceneId != nextSceneId, r = E_INVALID_ARG, E_INVALID_ARG,
569                                         "[%s] Invalid argument is used. Can't forward to current Scene.", GetErrorMessage(E_INVALID_ARG));
570
571                 // Stop animation
572                 if (!IsAnimationCompleted())
573                 {
574                         r = StopAllAnimations();
575                         SysTryCatch(NID_UI_SCENES, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
576                 }
577
578                 r = GotoScene(true, nextSceneId, forwardSceneTransition.GetAnimationType(),
579                                           forwardSceneTransition.GetHistoryOption(), forwardSceneTransition.GetDestroyOption(), pArgs);
580                 SysTryCatch(NID_UI_SCENES, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
581         }
582
583         r = E_SUCCESS;
584
585 CATCH:
586         __sceneTransitionProgressing = false;   //## Temporary
587         SysTryReturnResult(NID_UI_SCENES, !IsFailed(__sceneTransitionMutex.Release()), E_SYSTEM,
588                                            "A system error has been occurred. Mutext release failed.");
589         return r;
590 }
591
592 result
593 _SceneManagerImpl::GoForward(const SceneTransitionId& transitionId, const Tizen::Base::Collection::IList* pArgs)
594 {
595         ForwardSceneTransition forwardTransition;
596
597         result r = GetSceneTransition(transitionId, forwardTransition);
598         SysTryReturnResult(NID_UI_SCENES, !IsFailed(r), E_INVALID_ARG, "Cannot get transition from Id.");
599
600         return GoForward(forwardTransition, pArgs);
601 }
602
603 result
604 _SceneManagerImpl::GoBackward(const BackwardSceneTransition& sceneTransition, const Tizen::Base::Collection::IList* pArgs)
605 {
606         //## Temporary - Currently no support Non-Recursive Lock(Mutex).
607         SysTryReturnResult(NID_UI_SCENES, !__sceneTransitionProgressing, E_IN_PROGRESS, "Previous operation in progressing");
608
609         result r = __sceneTransitionMutex.TryToAcquire();
610         SysTryReturnResult(NID_UI_SCENES, r != E_OBJECT_LOCKED, E_IN_PROGRESS, "Previous operation in progressing");
611         SysTryReturnResult(NID_UI_SCENES, r != E_SYSTEM, E_SYSTEM, "A system error has been occurred.");
612         r = __sceneTransitionMutex.Acquire();
613         SysTryReturnResult(NID_UI_SCENES, !IsFailed(r), E_SYSTEM, "A system error has been occurred. Mutex acquire failed.");
614         __sceneTransitionProgressing = true;    //## Temporary
615
616         int historyCount = 0;
617         _SceneTransitionImpl backwardSceneTransition;
618         SceneId sceneId;
619
620         historyCount = __sceneHistory.GetCount();
621         SysTryCatch(NID_UI_SCENES, historyCount != 0, r = E_UNDERFLOW, E_UNDERFLOW, "[%s] The Scene history is empty.",
622                                 GetErrorMessage(E_UNDERFLOW));
623
624         backwardSceneTransition = *_SceneTransitionImpl::GetInstance(sceneTransition);
625         SysTryCatch(NID_UI_SCENES, backwardSceneTransition.GetDirection() == SCENE_TRANSITION_DIRECTION_BACKWARD,
626                                 r = E_INVALID_ARG, E_INVALID_ARG,
627                                 "[%s] Invalid argument is used. sceneTransition's direction is not SCENE_TRANSITION_DIRECTION_BACKWARD!", GetErrorMessage(E_INVALID_ARG));
628         SysTryCatch(NID_UI_SCENES, backwardSceneTransition.GetHistoryOption() == SCENE_HISTORY_OPTION_NO_HISTORY,
629                                 r = E_INVALID_ARG, E_INVALID_ARG,
630                                 "[%s] Invalid argument is used. sceneTransition's history option is not SCENE_HISTORY_OPTION_NO_HISTORY!", GetErrorMessage(E_INVALID_ARG));
631
632         sceneId = backwardSceneTransition.GetDestinationSceneId();
633         if (sceneId.GetLength() > 0)
634         {       // Back to specific scene and clean up history between destination and last point.
635                 int historyIndex = -1;
636                 SceneId destinationSceneId;
637
638                 // 1. Back tracking and pick a first matching sceneId
639                 r = __sceneHistory.LastIndexOf(sceneId, historyIndex);
640                 SysTryCatch(NID_UI_SCENES, !IsFailed(r), r = E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND,
641                                         "[%s] The given sceneId was not found in the registered scenes.", GetErrorMessage(E_OBJ_NOT_FOUND));
642                 r = __sceneHistory.GetAt(historyIndex, destinationSceneId);
643                 SysTryCatch(NID_UI_SCENES, !IsFailed(r), r = E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.",
644                                         GetErrorMessage(E_SYSTEM));
645
646                 // 2. if destoryOption == SCENE_DESTROY_OPTION_DESTROY then destroy all scenes except matching scene.
647                 if (backwardSceneTransition.GetDestroyOption() == SCENE_DESTROY_OPTION_DESTROY)
648                 {
649                         for (int i = historyIndex+1; i < historyCount; i++)
650                         {
651                                 SceneId destroyTargetSceneId;
652                                 __sceneHistory.GetAt(i, destroyTargetSceneId);
653                                 // Scene instance is not always valid.
654                                 Scene* pScene = GetSceneFromContainer(destroyTargetSceneId);
655                                 if (pScene)
656                                 {
657                                         // If Panel Scene then destroy sibling Panel Scene(s).
658                                         if (pScene->GetPanel())
659                                         {
660                                                 DestroySiblingPanelScene(destroyTargetSceneId);
661                                         }
662                                         DestroyScene(destroyTargetSceneId);
663                                 }
664                         }
665                 }
666
667                 // 3. Remove all scenes on history between latest scene to matching scene.
668                 r = __sceneHistory.RemoveItems(historyIndex, historyCount-historyIndex);
669                 SysTryCatch(NID_UI_SCENES, !IsFailed(r), r = E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.",
670                                         GetErrorMessage(E_SYSTEM));
671
672                 // Prevent transit to current scene
673                 SysTryCatch(NID_UI_SCENES, __currentSceneId != destinationSceneId, r = E_INVALID_ARG, E_INVALID_ARG,
674                                         "[%s] Invalid argument is used. Can't backward to current Scene.", GetErrorMessage(E_INVALID_ARG));
675
676                 // Stop previous animation
677                 if (!IsAnimationCompleted())
678                 {
679                         r = StopAllAnimations();
680                         SysTryCatch(NID_UI_SCENES, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
681                 }
682
683                 // Transition
684                 r = GotoScene(false, destinationSceneId, backwardSceneTransition.GetAnimationType(),
685                                           SCENE_HISTORY_OPTION_NO_HISTORY, backwardSceneTransition.GetDestroyOption(), pArgs);
686                 SysTryCatch(NID_UI_SCENES, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
687         }
688         else
689         {       // Adjacent backward transition
690                 SceneId previousSceneId;
691
692                 r = __sceneHistory.GetAt(historyCount-1, previousSceneId);
693                 SysTryCatch(NID_UI_SCENES, !IsFailed(r), r = E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND,
694                                         "[%s] The given sceneId was not found in the registered scenes.", GetErrorMessage(E_OBJ_NOT_FOUND));
695                 r = __sceneHistory.RemoveAt(historyCount-1);
696                 SysTryCatch(NID_UI_SCENES, !IsFailed(r), r = E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.",
697                                         GetErrorMessage(E_SYSTEM));
698
699                 // Prevent transit to current scene
700                 SysTryCatch(NID_UI_SCENES, __currentSceneId != previousSceneId, r = E_INVALID_ARG, E_INVALID_ARG,
701                                         "[%s] Invalid argument is used. Can't backward to current Scene.", GetErrorMessage(E_INVALID_ARG));
702
703                 // Stop previous animation
704                 if (!IsAnimationCompleted())
705                 {
706                         r = StopAllAnimations();
707                         SysTryCatch(NID_UI_SCENES, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
708                 }
709
710                 r = GotoScene(false, previousSceneId, backwardSceneTransition.GetAnimationType(),
711                                           SCENE_HISTORY_OPTION_NO_HISTORY, backwardSceneTransition.GetDestroyOption(), pArgs);
712                 SysTryCatch(NID_UI_SCENES, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
713         }
714
715         r = E_SUCCESS;
716
717 CATCH:
718         __sceneTransitionProgressing = false;   //## Temporary
719         SysTryReturnResult(NID_UI_SCENES, !IsFailed(__sceneTransitionMutex.Release()), E_SYSTEM,
720                                            "A system error has been occurred. Mutext release failed.");
721         return r;
722 }
723
724 result
725 _SceneManagerImpl::GoBackward(const SceneTransitionId& transitionId, const Tizen::Base::Collection::IList* pArgs)
726 {
727         BackwardSceneTransition backwardTransition;
728
729         result r = GetSceneTransition(transitionId, backwardTransition);
730         SysTryReturnResult(NID_UI_SCENES, !IsFailed(r), E_INVALID_ARG, "Cannot get transition from Id.");
731
732         return GoBackward(backwardTransition, pArgs);
733 }
734
735 Scene*
736 _SceneManagerImpl::GetCurrentScene(void) const
737 {
738         return __pCurrentScene;
739 }
740
741 SceneId
742 _SceneManagerImpl::GetCurrentSceneId(void) const
743 {
744         return __currentSceneId;
745 }
746
747 bool
748 _SceneManagerImpl::IsSceneAlive(const SceneId& sceneId) const
749 {
750         return  (GetSceneFromContainer(sceneId)) ? true : false;
751 }
752
753 result
754 _SceneManagerImpl::DestroyScene(const SceneId& sceneId)
755 {
756         result r = E_SUCCESS;
757         Scene* pScene = null;
758         bool isFormScene = false;
759         bool isLastPanel = false;
760         int panelCount = 0;
761
762         SysTryReturnResult(NID_UI_SCENES, __currentSceneId != sceneId, E_INVALID_ARG,
763                                            "Invalid argument is used. The current Scene can not be destroy.");
764         pScene = GetSceneFromContainer(sceneId);
765         SysTryReturnResult(NID_UI_SCENES, pScene != null, E_OBJ_NOT_FOUND, "Specified sceneId does not exist.");
766
767         // Ok now destroy associated Ui controls
768         // Form scene: Destroy Form - that's all.
769         // Panel scene: Normal case - destroy Panel only but the current scene is the last panel then destroy Form.
770         // Correspondent internal data item should be destroy.
771         if (!pScene->GetPanel())
772         {
773                 isFormScene = true;
774         }
775         else
776         {
777                 r = __formToPanelMultiMap.GetCount(pScene->GetFormId(), panelCount);
778                 SysTryReturnResult(NID_UI_SCENES, !IsFailed(r), E_SYSTEM,
779                                                    "A system error has been occurred. Form(SceneId:%ls) is not valid.", sceneId.GetPointer());
780                 if (panelCount <= 1)
781                 {
782                         isLastPanel = true;
783                 }
784         }
785
786         if (isFormScene)
787         {       // 1. Remove Form control(Associated on Scene) from Frame
788                 RemoveControlFromFrame(*pScene->GetForm());
789                 // 2. Remove Form from Form container
790                 RemoveFormFromFormContainer(pScene->GetFormId());
791         }
792         else
793         if (isLastPanel)
794         {       // 1. Remove Panel from Panel container.
795                 RemovePanelFromPanelContainer(pScene);
796                 // 2. Remove Form control from Frame. (Associated Panel automatically removed by Ui)
797                 RemoveControlFromFrame(*pScene->GetForm());
798                 // 3. Remove Form from Form container.
799                 RemoveFormFromFormContainer(pScene->GetFormId());
800         }
801         else
802         {       // 1. Remove Panel from Panel container.
803                 RemovePanelFromPanelContainer(pScene);
804                 // 2. Remove Panel control from base Form
805                 bool panelFromFormResouce = false;
806                 _SceneImpl* pSceneImpl = _SceneImpl::GetInstance(*pScene);
807                 if (pSceneImpl)
808                 {
809                         panelFromFormResouce = pSceneImpl->IsPanelCreatedFromFormResource();
810                 }
811                 if (!panelFromFormResouce)
812                 {
813                         RemoveControlFromForm(*pScene->GetForm(), *pScene->GetPanel());
814                 }
815         }
816
817         // Finally remove Scene
818         RemoveSceneFromContainer(sceneId);
819         delete pScene;
820
821         return E_SUCCESS;
822 }
823
824 result
825 _SceneManagerImpl::BringCurrentSceneToTop(void)
826 {
827         Form* pForm = null;
828         Scene* pCurrentScene = GetCurrentScene();
829
830         SysTryReturnResult(NID_UI_SCENES, pCurrentScene != null, E_OPERATION_FAILED, "The current Scene is not valid.");
831         pForm = pCurrentScene->GetForm();
832         SysTryReturnResult(NID_UI_SCENES, pForm != null, E_SYSTEM, "A system error has been occurred. The Form is not valid.");
833         result r = SetCurrentForm(*pForm);
834         SysTryReturnResult(NID_UI_SCENES, !IsFailed(r), E_SYSTEM, "A system error has been occurred.");
835
836         return E_SUCCESS;
837 }
838
839 result
840 _SceneManagerImpl::ClearSceneHistory(void)
841 {
842         __sceneHistory.RemoveAll();
843
844         return E_SUCCESS;
845 }
846
847 result
848 _SceneManagerImpl::AddToSceneHistory(const SceneId& sceneId)
849 {
850         result r = E_SUCCESS;
851         bool isContains = false;
852
853         SysTryReturnResult(NID_UI_SCENES, !sceneId.IsEmpty(), E_INVALID_ARG, "Invalid argument is used. sceneId length is 0.");
854         r = __sceneMap.ContainsKey(sceneId, isContains);
855         SysTryReturnResult(NID_UI_SCENES, isContains, E_OBJ_NOT_FOUND, "The sceneId is not registered.");
856         r = AddHistory(sceneId);
857         SysTryReturn(NID_UI_SCENES, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
858
859         return E_SUCCESS;
860 }
861
862 IListT<SceneId>*
863 _SceneManagerImpl::GetSceneHistoryN(void) const
864 {
865         std::unique_ptr<IListT<String> > pSceneList(new (std::nothrow) ArrayListT<String>);
866         SysTryReturn(NID_UI_SCENES, pSceneList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.",
867                                  GetErrorMessage(E_OUT_OF_MEMORY));
868
869         pSceneList->AddItems(__sceneHistory);
870         return pSceneList.release();
871 }
872
873 _SceneManagerImpl*
874 _SceneManagerImpl::GetInstance(SceneManager& pSceneManager)
875 {
876         return pSceneManager.__pSceneManagerImpl;
877 }
878
879 const _SceneManagerImpl*
880 _SceneManagerImpl::GetInstance(const SceneManager& pSceneManager)
881 {
882         return pSceneManager.__pSceneManagerImpl;
883 }
884
885 // Event handelers to asynchronous destroy the Scene.
886 void
887 _SceneManagerImpl::OnFormTransitionAnimationFinished(FrameAnimator& source, Frame& frame, Form& form1, Form& form2)
888 {
889         SetInputEventEnableState(form1, true);
890         SetInputEventEnableState(form2, true);
891
892         source.RemoveFrameAnimatorEventListener(*this);
893         DestroyReservedScene();
894 }
895
896 void
897 _SceneManagerImpl::OnFormTransitionAnimationStarted(FrameAnimator& source, Frame& frame, Form& form1, Form& form2)
898 {
899         // Nothing to do.
900 }
901
902 void
903 _SceneManagerImpl::OnFormTransitionAnimationStopped(FrameAnimator& source, Frame& frame, Form& form1, Form& form2)
904 {
905         SetInputEventEnableState(form1, true);
906         SetInputEventEnableState(form2, true);
907
908         source.RemoveFrameAnimatorEventListener(*this);
909         DestroyReservedScene();
910 }
911
912 void
913 _SceneManagerImpl::OnAnimationTransactionFinished(int transactionId)
914 {
915         if (__pDisabledForm)
916         {
917                 SetInputEventEnableState(*__pDisabledForm, true);
918                 __pDisabledForm = null;
919         }
920         AnimationTransaction::SetCurrentTransactionEventListener(null);
921 }
922
923 void
924 _SceneManagerImpl::OnAnimationTransactionStarted(int transactionId)
925 {
926         // Nothing to do.
927 }
928
929 void
930 _SceneManagerImpl::OnAnimationTransactionStopped(int transactionId)
931 {
932         if (__pDisabledForm)
933         {
934                 SetInputEventEnableState(*__pDisabledForm, true);
935                 __pDisabledForm = null;
936         }
937         AnimationTransaction::SetCurrentTransactionEventListener(null);
938 }
939
940 void
941 _SceneManagerImpl::OnSceneControlEventReceived(_SceneControlEventArg::SceneControlEventType eventType, const SceneId& sceneId)
942 {
943         SysLog(NID_UI_SCENES, "Received type= 0x%x, sceneId=%ls", eventType, &sceneId);
944
945         switch (eventType)
946         {
947         case _SceneControlEventArg::SCENE_CONTROL_EVENT_TYPE_DESTROY:
948                 DestroyScene(sceneId);
949                 break;
950
951         default:
952                 SysLog(NID_UI_SCENES, "Invalid SceneControlEventType x0%x", eventType);
953                 break;
954         }
955 }
956
957 // Internal operations
958 Scene*
959 _SceneManagerImpl::GetScene(SceneId& sceneId)
960 {
961         return GetSceneFromContainer(sceneId);
962 }
963
964 IListT<Scene*>*
965 _SceneManagerImpl::GetLiveSceneN(void) const
966 {
967         std::unique_ptr<ArrayListT<Scene*> > pSceneList(new (std::nothrow) ArrayListT<Scene*>);
968         SysTryReturn(NID_UI_SCENES, pSceneList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.",
969                                  GetErrorMessage(E_OUT_OF_MEMORY));
970
971         std::unique_ptr<IMapEnumeratorT<SceneId, Scene*> > pMapEnum(__sceneContainer.GetMapEnumeratorN());
972         SysTryReturn(NID_UI_SCENES, pMapEnum != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.",
973                                  GetErrorMessage(E_OUT_OF_MEMORY));
974
975         while (pMapEnum->MoveNext() == E_SUCCESS)
976         {
977                 Scene* pScene = null;
978                 pMapEnum->GetValue(pScene);
979                 pSceneList->Add(pScene);
980         }
981         return pSceneList.release();
982 }
983
984 // Private method
985 result
986 _SceneManagerImpl::GotoScene(bool forward, const SceneId& sceneId, SceneTransitionAnimationType animationType,
987                                                          SceneHistoryOption historyOption, SceneDestroyOption destroyOption, const IList* pArgs)
988 {
989         // 1. Initialize for Scene transition.
990         result r = E_SUCCESS;
991         bool sceneAlreadyCreated = false;
992         bool formAlreadyCreated = false;
993         bool panelAlreadyCreated = false;
994         bool doAnimation = false;
995         bool formTransition = false;
996         Scene* pScene = null;
997         Form* pForm = null;
998         Panel* pPanel = null;
999         SceneId previousSceneId = __currentSceneId;             // Save for later
1000         String previousFormId = (__pCurrentScene) ? __pCurrentScene->GetFormId() : L"";
1001         bool previousIsPanelScene = (__pCurrentScene) ? (__pCurrentScene->GetPanel()) : false;
1002         Frame* pFrame = null;
1003         FrameAnimator* pFrameAnimator = null;
1004         // Exception handling hintings
1005         bool onExceptionDeletepScene = false;
1006         bool onExceptionRemovesceneIdFromSceneContainer = false;
1007         bool onExceptionDeletepForm = false;
1008         bool onExceptionRemoveFormIdFromFormContainer = false;
1009         bool onExceptionRemovepPanel = false;
1010
1011         // Prevent self forward
1012         SysTryCatch(NID_UI_SCENES, __currentSceneId != sceneId, r = E_INVALID_ARG, E_INVALID_ARG,
1013                                 "[%s] Invalid argument is used. Can't transit to current Scene.", GetErrorMessage(E_INVALID_ARG));
1014         CallListenerOnSceneTransitionStarted(__currentSceneId, sceneId);        // Call listener - ISceneManagerEventListener's
1015         if (__pCurrentScene)
1016         {       // Call listener - ISceneEventListener's
1017                 CallListenerOnSceneDeactivated(*__pCurrentScene, __pCurrentScene->GetSceneId(), sceneId);
1018         }
1019
1020         // 2. Find the Scene on SceneContainer - Scene and correspond UI control has same life time.
1021         pScene = GetSceneFromContainer(sceneId);
1022         if (pScene) // Activate pScene: Scene already existing then Re-activate associated a Form and a Panel.
1023         {
1024                 sceneAlreadyCreated = true;
1025                 pForm = GetFormFromContainer(pScene->GetFormId());
1026                 SysTryCatch(NID_UI_SCENES, pForm == pScene->GetForm(), r = E_SYSTEM, E_SYSTEM,
1027                                         "[%s] A system error has been occurred. FormId mismatch with associated From instance.",
1028                                         GetErrorMessage(E_SYSTEM));
1029                 formAlreadyCreated = true;
1030                 pPanel = pScene->GetPanel();
1031                 if (pPanel)
1032                 {
1033                         panelAlreadyCreated = true;
1034                 }
1035         }
1036         else
1037         {       // 3. Scene not found- Create new Scene
1038                 _SceneDescription* pSceneValue = null;
1039                 __sceneMap.GetValue(sceneId, pSceneValue);
1040                 SysTryCatch(NID_UI_SCENES, pSceneValue != null, r = E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND,
1041                                         "[%s] The given sceneId was not found in the registered scenes.", GetErrorMessage(E_OBJ_NOT_FOUND));
1042                 // 4. Setup the new Scene
1043                 pScene = _SceneImpl::CreateSceneN(sceneId, pSceneValue->formId, pSceneValue->panelId);
1044                 SysTryCatch(NID_UI_SCENES, pScene != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
1045                                         "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1046                 onExceptionDeletepScene = true;                                                         // On the CATCH [delete pScene]
1047                 _SceneImpl* pSceneImpl = _SceneImpl::GetInstance(*pScene);
1048                 SysTryCatch(NID_UI_SCENES, pSceneImpl != null, r = E_SYSTEM, E_SYSTEM,
1049                                         "[%s] A system error has been occurred. pSceneImpl not valid", GetErrorMessage(E_SYSTEM));
1050                 // 5. Register Scene
1051                 AddSceneToContainer(sceneId, pScene);
1052                 onExceptionRemovesceneIdFromSceneContainer = true;                      // On the CATCH [remove 'sceneId' from SceneContainer]
1053                 // 6. Find the Form on FormContainer
1054                 pForm = GetFormFromContainer(pScene->GetFormId());
1055                 if (pForm) // Form existing: just call SetCurrentForm
1056                 {   // If the Scene is panel scene then add new panel to pForm or change showState.
1057                         formAlreadyCreated = true;
1058                         pSceneImpl->SetForm(pForm);             // Panel Scene share same Form intance
1059                 }
1060                 else// 7. Form not found- Create new Form
1061                 {       // 8. Get the new Form from the FormFactory
1062                         SysTryCatch(NID_UI_SCENES, __pFormFactory != null, r = E_INVALID_STATE, E_INVALID_STATE,
1063                                                 "[%s] SceneManager is in an invalid state. Form factory is not registered.",
1064                                                 GetErrorMessage(E_INVALID_STATE));
1065                         String  formId(pScene->GetFormId());
1066                         pForm = __pFormFactory->CreateFormN(formId, sceneId);   // On the CATCH [delete pForm]
1067                         SysTryCatch(NID_UI_SCENES, pForm != null, r = E_SYSTEM, E_SYSTEM,
1068                                                 "[%s] A system error has been occurred. Form(Id=%ls) creation failed on form factroy.",
1069                                                 GetErrorMessage(E_SYSTEM), formId.GetPointer());
1070                         onExceptionDeletepForm = true;                                                  // On the CATCH [remove pForm from FormContainer]
1071                         // 9. Register Form
1072                         AddFormToContainer(pScene->GetFormId(), pForm);
1073                         pSceneImpl->SetForm(pForm);
1074                         onExceptionRemoveFormIdFromFormContainer = true;
1075                 }
1076                 // 10. Create panel for Panel Scene
1077                 // * One Panel instance for each Panel-Scene so no need to check duplicated panel instance for same panel Id.
1078                 if (!pScene->GetPanelId().IsEmpty())
1079                 {
1080                         String panelId(pScene->GetPanelId());
1081                         // First of all, get the Panel from the based Form.
1082                         // Because, base Form loaded from the resources, the child Panel also loaded and created.
1083                         // So, do not create a new Panel instance but get from base Form with panelId as resource Id.
1084                         pPanel = dynamic_cast<Panel*>(pForm->GetControl(panelId));
1085                         if (pPanel)
1086                         {
1087                                 pSceneImpl->SetPanelCreatedFromFormResource(true);      // Prevent RemoveControl - It's not creatable via Panel factory.
1088                         }
1089                         else
1090                         {
1091                                 SysTryCatch(NID_UI_SCENES, __pPanelFactory != null, r = E_INVALID_STATE, E_INVALID_STATE,
1092                                                         "[%s] SceneManager is in an invalid state. Panel factory is not registered.",
1093                                                         GetErrorMessage(E_INVALID_STATE));
1094                                 pPanel = __pPanelFactory->CreatePanelN(panelId, sceneId); // On the CATCH [delete pPanel]
1095                                 SysTryCatch(NID_UI_SCENES, pPanel != null, r = E_SYSTEM, E_SYSTEM,
1096                                                         "[%s] A system error has been occurred. Panel(Id=%ls) creation failed on PanelFactory.",
1097                                                         GetErrorMessage(E_SYSTEM), panelId.GetPointer());
1098                                 onExceptionRemovepPanel = true;                                         // On the CATCH [remove pPanel from __formToPanelMultiMap]
1099                         }
1100                         AddPanelToPanelContainer(pScene);
1101                         pSceneImpl->SetPanel(pPanel);
1102                 }
1103         }
1104
1105         // For animation logic should be divide Animator section and normal section for proper operations.
1106         // If (showAnimation && forwardAnimation is Not NONE) then doing animator related logic /
1107         // Setup default animation setting / Add listener to get animation stop/finishing
1108         formTransition = (previousFormId != pScene->GetFormId()) ? true : false;
1109         doAnimation = (animationType > SCENE_TRANSITION_ANIMATION_TYPE_NONE) ? true : false;
1110         if (doAnimation && (animationType != SCENE_TRANSITION_ANIMATION_TYPE_CUSTOM && !formTransition))
1111         {
1112                 doAnimation = false;
1113         }
1114         if (doAnimation && (GetCurrentForm() == null))
1115         {
1116                 doAnimation = false;
1117         }
1118
1119         if (doAnimation)
1120         {
1121                 // Initialize Frame animator
1122                 pFrame = GetFrame();
1123                 SysTryCatch(NID_UI_SCENES, pFrame != null, r = E_SYSTEM, E_SYSTEM,
1124                                         "[%s] A system error has been occurred. Cannot get Frame.", GetErrorMessage(E_SYSTEM));
1125                 pFrameAnimator = pFrame->GetFrameAnimator();
1126                 SysTryCatch(NID_UI_SCENES, pFrameAnimator != null, r = E_SYSTEM, E_SYSTEM,
1127                                         "[%s] A system error has been occurred. Cannot get FrameAnimator.", GetErrorMessage(E_SYSTEM));
1128                 pFrameAnimator->StopAllAnimations();
1129
1130                 // Initialize Control animator if needed.
1131                 if (!formTransition && pPanel)
1132                 {
1133                         ControlAnimator* pControlAnimator = pPanel->GetControlAnimator();
1134                         SysTryCatch(NID_UI_SCENES, pControlAnimator != null, r = E_SYSTEM, E_SYSTEM,
1135                                                 "[%s] A system error has been occurred. Cannot get ControlAnimator.", GetErrorMessage(E_SYSTEM));
1136                         pControlAnimator->StopAllAnimations();
1137                 }
1138
1139                 // Set default value for formTransition
1140                 if (formTransition && (animationType >= SCENE_TRANSITION_ANIMATION_TYPE_LEFT) &&
1141                         (pFrameAnimator->GetStatus() == ANIMATOR_STATUS_STOPPED))
1142                 {
1143                         pFrameAnimator->SetFormTransitionAnimation(
1144                                         __animationDescriptions[animationType-SCENE_TRANSITION_ANIMATION_TYPE_LEFT].animationType,
1145                                         __animationDescriptions[animationType-SCENE_TRANSITION_ANIMATION_TYPE_LEFT].duration,
1146                                         __animationDescriptions[animationType-SCENE_TRANSITION_ANIMATION_TYPE_LEFT].interpolatorType);
1147                 }
1148
1149                 if (formTransition)
1150                 {       // Disable user input
1151                         if (__pCurrentScene)
1152                         {
1153                                 r = SetInputEventEnableState(*__pCurrentScene->GetForm(), false);
1154                                 SysTryCatch(NID_UI_SCENES, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
1155                         }
1156                         r = SetInputEventEnableState(*pForm, false);
1157                         if (IsFailed(r))
1158                         {
1159                                 if (__pCurrentScene)
1160                                 {
1161                                         SetInputEventEnableState(*__pCurrentScene->GetForm(), true);
1162                                 }
1163                         }
1164                         SysTryCatch(NID_UI_SCENES, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
1165                 }
1166         }
1167
1168         // Prepare animation for customization.
1169         CallListenerPrepareAnimation(*pScene, sceneId, const_cast<IList*>(pArgs), animationType, formTransition );
1170         // Setup Ui controls to show the result.
1171         if (sceneAlreadyCreated)
1172         {
1173                 if (formTransition)
1174                 {
1175                         if (pPanel)
1176                         {
1177                                 SwitchToPanel(pScene->GetFormId(), pPanel);
1178                         }
1179                         r = SetCurrentForm(*pForm, doAnimation); // FrameAnimator
1180                         SysTryCatch(NID_UI_SCENES, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
1181                 }
1182                 else
1183                 {
1184                         r = SetCurrentForm(*pForm);
1185                         SysTryCatch(NID_UI_SCENES, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
1186                         if (pPanel)
1187                         {
1188                                 SwitchToPanel(pScene->GetFormId(), pPanel, doAnimation); // ControlAnimator
1189                         }
1190                 }
1191         }
1192         else // Scene newly created
1193         {
1194                 if (formAlreadyCreated) // Panel scene created but base form already created - reuse base form.
1195                 {
1196                         if (formTransition)
1197                         {
1198                                 if (pPanel)
1199                                 {
1200                                         if (!panelAlreadyCreated)       // If a new panel created then Add Panel to Form
1201                                         {
1202                                                 AddControlToForm(*pForm, *pPanel);
1203                                         }
1204                                         SwitchToPanel(pScene->GetFormId(), pPanel);
1205                                 }
1206                                 r = SetCurrentForm(*pForm, (doAnimation));      // FrameAnimator
1207                                 SysTryCatch(NID_UI_SCENES, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
1208                         }
1209                         else
1210                         {
1211                                 r = SetCurrentForm(*pForm);
1212                                 SysTryCatch(NID_UI_SCENES, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
1213                                 if (pPanel)
1214                                 {
1215                                         if (!panelAlreadyCreated)
1216                                         {
1217                                                 AddControlToForm(*pForm, *pPanel);
1218                                         }
1219                                         SwitchToPanel(pScene->GetFormId(), pPanel, doAnimation); // ControlAnimator
1220                                 }
1221                         }
1222                 }
1223                 else    // New Form created!
1224                 {
1225                         if (pPanel)
1226                         {
1227                                 // New panel
1228                                 AddControlToForm(*pForm, *pPanel);
1229                                 SwitchToPanel(pScene->GetFormId(), pPanel);
1230                         }
1231                         AddControlToFrame(*pForm, doAnimation);         // Form add to frame
1232                         if (!doAnimation)
1233                         {
1234                                 SetCurrentForm(*pForm);
1235                         }
1236                 }
1237         }
1238
1239         UpdateCurrentScene(pScene);
1240         if ((historyOption == SCENE_HISTORY_OPTION_ADD_HISTORY) && (!previousSceneId.IsEmpty()))
1241         {
1242                 r = AddHistory(previousSceneId);
1243                 // Too late revert to previous scene, so just return the error code but not revert to previous state.
1244                 SysTryLog(NID_UI_SCENES, !IsFailed(r), "[%s] History adding failed.", GetErrorMessage(r));
1245         }
1246
1247         CallListenerOnSceneActivatedN(*pScene, previousSceneId, sceneId, const_cast<IList*>(pArgs));
1248         CallListenerOnSceneTransitionCompleted(previousSceneId, __currentSceneId);
1249
1250         if (destroyOption == SCENE_DESTROY_OPTION_DESTROY )
1251         {
1252                 if (previousIsPanelScene)
1253                 {
1254                         DestroySiblingPanelScene(previousSceneId);      // Destroy sibling Panel Scene
1255                 }
1256                 if (doAnimation)
1257                 {
1258                         ReserveDestroyingScene(previousSceneId);                // Destroy the Scene after animator finished(stopped).
1259                 }
1260                 else
1261                 {
1262                         DestroySceneAsync(previousSceneId);
1263                 }
1264         }
1265
1266         DrawForm(*pScene->GetForm());
1267         return r;
1268
1269 CATCH:
1270         // Check all exception case for proper delete the instances: Scene, Form, Panel and item corresponding container.
1271         if (onExceptionRemovepPanel)
1272         {
1273                 RemovePanelFromPanelContainer(pScene);
1274                 delete pPanel;  // Also needed it.
1275                 pPanel = null;
1276         }
1277         if (onExceptionRemoveFormIdFromFormContainer)
1278         {
1279                 RemoveFormFromFormContainer(pScene->GetFormId());
1280         }
1281         if (onExceptionDeletepForm)
1282         {
1283                 delete pForm;
1284                 pForm = null;
1285         }
1286         if (onExceptionRemovesceneIdFromSceneContainer)
1287         {
1288                 RemoveSceneFromContainer(sceneId);
1289         }
1290         if (onExceptionDeletepScene)
1291         {
1292                 delete pScene;
1293                 pScene = null;
1294         }
1295
1296         return r;
1297 }
1298
1299 Scene*
1300 _SceneManagerImpl::GetSceneFromContainer(const SceneId& sceneId) const
1301 {
1302         Scene* pScene = null;
1303         __sceneContainer.GetValue(sceneId, pScene);
1304         return pScene;
1305 }
1306
1307 Form*
1308 _SceneManagerImpl::GetFormFromContainer(const String& formId)
1309 {
1310         Form* pForm = null;
1311         __formContainer.GetValue(formId, pForm);
1312         return pForm;
1313 }
1314
1315 void
1316 _SceneManagerImpl::AddSceneToContainer(const SceneId& sceneId, Scene* pScene)
1317 {
1318         __sceneContainer.Add(sceneId, pScene);
1319 }
1320
1321 void
1322 _SceneManagerImpl::RemoveSceneFromContainer(const SceneId& sceneId)
1323 {
1324         __sceneContainer.Remove(sceneId);
1325 }
1326
1327 void
1328 _SceneManagerImpl::AddFormToContainer(const String& formId, Form* pForm)
1329 {
1330         __formContainer.Add(formId, pForm);
1331 }
1332
1333 void
1334 _SceneManagerImpl::RemoveFormFromFormContainer(const String& formId)
1335 {
1336         __formContainer.Remove(formId);
1337 }
1338
1339 void
1340 _SceneManagerImpl::AddPanelToPanelContainer(Scene* pScene)
1341 {
1342         __formToPanelMultiMap.Add(pScene->GetFormId(), pScene);
1343 }
1344
1345 void
1346 _SceneManagerImpl::RemovePanelFromPanelContainer(Scene* pScene)
1347 {
1348         __formToPanelMultiMap.Remove(pScene->GetFormId(), pScene);
1349 }
1350
1351 void
1352 _SceneManagerImpl::UpdateCurrentScene(Scene* pScene)
1353 {
1354         __pCurrentScene = pScene;
1355         __currentSceneId = pScene->GetSceneId();
1356 }
1357
1358 result
1359 _SceneManagerImpl::AddHistory(const SceneId& sceneId)
1360 {
1361         return __sceneHistory.Add(sceneId);
1362 }
1363
1364 void
1365 _SceneManagerImpl::SwitchToPanel(const String& formId, Panel* pPanel, bool useAnimator)
1366 {
1367         Panel* pShowPanel = null;
1368         Form* pBaseForm = null;
1369         if (useAnimator)
1370         {
1371                 pBaseForm = dynamic_cast<Form*>(pPanel->GetParent());
1372                 if (pBaseForm == null)
1373                 {
1374                         useAnimator = false;
1375                 }
1376         }
1377
1378         std::unique_ptr<IEnumeratorT<Scene*> > pSceneEnum(__formToPanelMultiMap.GetValuesN(formId));
1379         SysTryReturnVoidResult(NID_UI_SCENES, pSceneEnum != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.",
1380                                                    GetErrorMessage(E_OUT_OF_MEMORY));
1381         while (pSceneEnum->MoveNext() == E_SUCCESS)
1382         {
1383                 Scene* pCurrentScene = null;
1384                 pSceneEnum->GetCurrent(pCurrentScene);
1385                 SysTryReturnVoidResult(NID_UI_SCENES, pCurrentScene != null, E_SYSTEM, "[%s] Memory allocation failed.",
1386                                                            GetErrorMessage(E_OUT_OF_MEMORY));
1387                 if (pCurrentScene->GetPanel() != pPanel)
1388                 {
1389                         if (pCurrentScene->GetPanel()->GetShowState())
1390                         {
1391                                 pShowPanel = pCurrentScene->GetPanel();
1392                         }
1393                 }
1394         }
1395
1396         if (useAnimator && pShowPanel && pPanel)
1397         {
1398                 int transactionId = 0;
1399                 AnimationTransaction::Begin(transactionId);     // transactionId was set
1400         }
1401
1402         if (pShowPanel)
1403         {
1404                 if (useAnimator)
1405                 {
1406                         ControlAnimator* pControlAnimator = pShowPanel->GetControlAnimator();
1407                         if (pControlAnimator)
1408                         {
1409                                 pControlAnimator->SetShowState(false);
1410                         }
1411                         else
1412                         {
1413                                 pShowPanel->SetShowState(false);
1414                         }
1415                 }
1416                 else
1417                 {
1418                         pShowPanel->SetShowState(false);
1419                 }
1420         }
1421         if (pPanel)
1422         {
1423                 if (useAnimator)
1424                 {
1425                         ControlAnimator* pControlAnimator = pPanel->GetControlAnimator();
1426                         if (pControlAnimator)
1427                         {
1428                                 pControlAnimator->SetShowState(true);
1429                         }
1430                         else
1431                         {
1432                                 pPanel->SetShowState(true);
1433                         }
1434                 }
1435                 else
1436                 {
1437                         pPanel->SetShowState(true);
1438                 }
1439         }
1440
1441         if (useAnimator && pShowPanel && pPanel)
1442         {
1443                 // Set event listener & start animations
1444                 AnimationTransaction::SetCurrentTransactionEventListener(this);
1445                 result r = AnimationTransaction::Commit();
1446                 if (!IsFailed(r))
1447                 {
1448                         // Disable input for base Form
1449                         if (pBaseForm)
1450                         {
1451                                 __pDisabledForm = pBaseForm;
1452                                 SetInputEventEnableState(*pBaseForm, false);
1453                         }
1454                 }
1455                 else
1456                 {
1457                         SysLog(NID_UI_SCENES, "Animation Commit() failed");
1458                 }
1459         }
1460 }
1461
1462 void
1463 _SceneManagerImpl::AddControlToFrame(Form& form, bool useAnimator)
1464 {
1465         Frame* pFrame = GetFrame();
1466         if (pFrame)
1467         {
1468                 if (useAnimator)
1469                 {
1470                         FrameAnimator* pFrameAnimator = pFrame->GetFrameAnimator();
1471                         if (pFrameAnimator)
1472                         {
1473                                 // Add animator listener to asynchronous scene destroy for safe deletion.
1474                                 pFrameAnimator->AddFrameAnimatorEventListener(*this);
1475                                 _FrameAnimatorImpl* pFrameAnimatorImpl = _FrameAnimatorImpl::GetInstance(*pFrameAnimator);
1476                                 if (pFrameAnimatorImpl)
1477                                 {
1478                                         pFrameAnimatorImpl->AddControl(form);
1479                                         return;
1480                                 }
1481                         }
1482                         SysLog(NID_UI_SCENES, "pFrameAnimator or pFrameAnimatorImpl is not valid.");
1483                 }
1484                 pFrame->AddControl(form);
1485         }
1486 }
1487
1488 void
1489 _SceneManagerImpl::RemoveControlFromFrame(Form& form)
1490 {
1491         Frame* pFrame = GetFrame();
1492         if (pFrame)
1493         {
1494                 // Control validation check for safe operation on termination(Ui destroy before asynchronous scene destroy process).
1495                 _ControlManager* pControlManager = _ControlManager::GetInstance();
1496                 if (pControlManager)
1497                 {
1498                         _Control* pControl = pControlManager->GetObject(__correspondFrameControlHandle);
1499                         if (pControl)
1500                         {
1501                                 pFrame->RemoveControl(form);
1502                                 return;
1503                         }
1504                         else
1505                         {
1506                                 SysLog(NID_UI_SCENES, "FrameWindow already destroyed. Skip remove control to form.");
1507                         }
1508                 }
1509                 else
1510                 {
1511                         SysLog(NID_UI_SCENES, "Window system already shutdown.");
1512                 }
1513         }
1514 }
1515
1516 result
1517 _SceneManagerImpl::SetCurrentForm(Form& form, bool useAnimator)
1518 {
1519         result r = E_SUCCESS;
1520         Frame* pFrame = GetFrame();
1521
1522         SysTryReturnResult(NID_UI_SCENES, pFrame != null, E_SYSTEM,
1523                                            "A system error has been occurred. Can not get the Frame window.");
1524         if (useAnimator)
1525         {
1526                 FrameAnimator* pFrameAnimator = pFrame->GetFrameAnimator();
1527                 if (pFrameAnimator)
1528                 {
1529                         // Add animator listener to asynchronous scene destroy for safe deletion.
1530                         pFrameAnimator->AddFrameAnimatorEventListener(*this);
1531                         r = pFrameAnimator->SetCurrentForm(form);
1532                         if (r != E_SYSTEM)
1533                         {
1534                                 return E_SUCCESS;
1535                         }
1536                 }
1537                 SysLog(NID_UI_SCENES, "Safety operation ongoing. Animation may not working, Please check the problems!");
1538         }
1539
1540         r = pFrame->SetCurrentForm(form);
1541         SysTryReturnResult(NID_UI_SCENES, !IsFailed(r), E_SYSTEM, "A system error has been occurred. Can not set current form.");
1542         return E_SUCCESS;
1543 }
1544
1545 Form*
1546 _SceneManagerImpl::GetCurrentForm(void)
1547 {
1548         Frame* pFrame = GetFrame();
1549         if (pFrame)
1550         {
1551                 return pFrame->GetCurrentForm();
1552         }
1553         return null;
1554 }
1555
1556 void
1557 _SceneManagerImpl::AddControlToForm(Form& baseForm, const Panel& panel)
1558 {
1559         baseForm.AddControl(panel);
1560 }
1561
1562 void
1563 _SceneManagerImpl::RemoveControlFromForm(Form& baseForm, const Panel& panel)
1564 {
1565         baseForm.RemoveControl(panel);
1566 }
1567
1568 void
1569 _SceneManagerImpl::SetShowState(Panel& targetPanel, bool state)
1570 {
1571         targetPanel.SetShowState(state);
1572 }
1573
1574 void
1575 _SceneManagerImpl::DrawForm(Form& form)
1576 {
1577         form.Invalidate(true);
1578 }
1579
1580 bool
1581 _SceneManagerImpl::CallListenerOnSceneTransitionStarted(const SceneId& currentSceneId, const SceneId& nextSceneId)
1582 {
1583         std::unique_ptr<IEnumeratorT<ISceneManagerEventListener*> > pEnum(__sceneManagerEventListenerList.GetEnumeratorN());
1584         if (!pEnum)
1585         {
1586                 return false;
1587         }
1588
1589         while (pEnum->MoveNext() == E_SUCCESS)
1590         {
1591                 ISceneManagerEventListener*     pListener = null;
1592                 pEnum->GetCurrent(pListener);
1593                 if (pListener)
1594                 {
1595                         pListener->OnSceneTransitionStarted(currentSceneId, nextSceneId);
1596                 }
1597         }
1598         return true;
1599 }
1600
1601 bool
1602 _SceneManagerImpl::CallListenerOnSceneTransitionCompleted(const SceneId& previousSceneId, const SceneId& currentSceneId)
1603 {
1604         std::unique_ptr<IEnumeratorT<ISceneManagerEventListener*> > pEnum(__sceneManagerEventListenerList.GetEnumeratorN());
1605         if (!pEnum)
1606         {
1607                 return false;
1608         }
1609
1610         while (pEnum->MoveNext() == E_SUCCESS)
1611         {
1612                 ISceneManagerEventListener*     pListener = null;
1613                 pEnum->GetCurrent(pListener);
1614                 if (pListener)
1615                 {
1616                         pListener->OnSceneTransitionCompleted(previousSceneId, currentSceneId);
1617                 }
1618         }
1619         return true;
1620 }
1621
1622 bool
1623 _SceneManagerImpl::CallListenerPrepareAnimation(Scene& scene, const SceneId& sceneId, IList* pArgs,
1624                                                                                                 SceneTransitionAnimationType type, bool formTransition)
1625 {
1626         _SceneImpl* pSceneImpl = _SceneImpl::GetInstance(scene);
1627         SysTryReturn(NID_UI_SCENES, pSceneImpl, false, E_INVALID_STATE,
1628                                  "[%s] SceneManager is in an invalid state. scene is not valid.",
1629                                  GetErrorMessage(E_INVALID_STATE));
1630
1631         return pSceneImpl->PrepareAnimation(sceneId, pArgs, type, formTransition);
1632 }
1633
1634 bool
1635 _SceneManagerImpl::CallListenerOnSceneActivatedN(Scene& scene, const SceneId& previousSceneId, const SceneId& currentSceneId,
1636                                                                                                  IList* pArgs)
1637 {
1638         _SceneImpl* pSceneImpl = _SceneImpl::GetInstance(scene);
1639         SysTryReturn(NID_UI_SCENES, pSceneImpl, false, E_INVALID_STATE,
1640                                  "[%s] SceneManager is in an invalid state. scene is not valid.",
1641                                  GetErrorMessage(E_INVALID_STATE));
1642
1643         return pSceneImpl->OnSceneActivatedN(previousSceneId, currentSceneId, pArgs);
1644 }
1645
1646 bool
1647 _SceneManagerImpl::CallListenerOnSceneDeactivated(Scene& scene, const SceneId& currentSceneId, const SceneId& nextSceneId)
1648 {
1649         _SceneImpl* pSceneImpl = _SceneImpl::GetInstance(scene);
1650         SysTryReturn(NID_UI_SCENES, pSceneImpl, false, E_INVALID_STATE,
1651                                  "[%s] SceneManager is in an invalid state. scene is not valid.",
1652                                  GetErrorMessage(E_INVALID_STATE));
1653
1654         return pSceneImpl->OnSceneDeactivated(currentSceneId, nextSceneId);
1655 }
1656
1657 SceneId
1658 _SceneManagerImpl::CallStretegyGetNextScene(const SceneId& currentSceneId, const IList* pArgs)
1659 {
1660         SceneId nextScene(L"");
1661         if (__pPolicyProvider)
1662         {
1663                 nextScene = __pPolicyProvider->GetNextScene(currentSceneId, pArgs);
1664         }
1665         return nextScene;
1666 }
1667
1668 void
1669 _SceneManagerImpl::DestroySceneAsync(const SceneId& sceneId)
1670 {
1671         _SceneControlEventArg* pArg = new (std::nothrow) _SceneControlEventArg(
1672                                                                                                                 _SceneControlEventArg::SCENE_CONTROL_EVENT_TYPE_DESTROY, sceneId);
1673         SysTryReturnVoidResult(NID_UI_SCENES, pArg != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.",
1674                                                    GetErrorMessage(E_OUT_OF_MEMORY));
1675         __sceneControlEvent.FireAsync(*pArg);
1676 }
1677
1678 void
1679 _SceneManagerImpl::ReserveDestroyingScene(const SceneId& sceneId)
1680 {
1681         if (!__destroyReservedScene.IsEmpty())
1682         {
1683                 SysLog(NID_UI_SCENES, "Previous reserved sceneId=%ls", __destroyReservedScene.GetPointer());
1684         }
1685         __destroyReservedScene = sceneId;
1686 }
1687
1688 void
1689 _SceneManagerImpl::DestroyReservedScene(void)
1690 {
1691         if (!__destroyReservedScene.IsEmpty())
1692         {
1693                 DestroySceneAsync(__destroyReservedScene);
1694                 __destroyReservedScene.Clear();
1695         }
1696 }
1697
1698 void
1699 _SceneManagerImpl::DestroySiblingPanelScene(const SceneId& sceneId)
1700 {
1701         Scene* pScene = null;
1702         pScene = GetSceneFromContainer(sceneId);
1703         SysTryReturnVoidResult(NID_UI_SCENES, pScene != null, E_OBJ_NOT_FOUND, "[%s] Specified sceneId does not exist.",
1704                                                    GetErrorMessage(E_OBJ_NOT_FOUND));
1705
1706         Panel* pPanel = pScene->GetPanel();
1707         if (pPanel)
1708         {
1709                 int panelCount = 0;
1710                 result r = __formToPanelMultiMap.GetCount(pScene->GetFormId(), panelCount);
1711                 SysTryReturnVoidResult(NID_UI_SCENES, !IsFailed(r), E_SYSTEM,
1712                                                            "[%s] A system error has been occurred. Form(SceneId:%ls) not valid.",
1713                                                            GetErrorMessage(E_SYSTEM), sceneId.GetPointer());
1714                 if (panelCount <= 1)
1715                 {
1716                         return;
1717                 }
1718
1719                 ArrayListT<Scene*> destroyList;
1720                 std::unique_ptr<IEnumeratorT<Scene*> > pSceneEnum(__formToPanelMultiMap.GetValuesN(pScene->GetFormId()));
1721                 SysTryReturnVoidResult(NID_UI_SCENES, pSceneEnum != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.",
1722                                                            GetErrorMessage(E_OUT_OF_MEMORY));
1723                 while (pSceneEnum->MoveNext() == E_SUCCESS)
1724                 {
1725                         Scene* pCurrentScene = null;
1726                         pSceneEnum->GetCurrent(pCurrentScene);
1727                         SysTryReturnVoidResult(NID_UI_SCENES, pCurrentScene != null, E_SYSTEM,
1728                                                                    "[%s] A system error has been occurred. Current scene is not valid.",
1729                                                                    GetErrorMessage(E_SYSTEM));
1730                         if (pCurrentScene->GetPanel() != pPanel)
1731                         {
1732                                 destroyList.Add(pCurrentScene);                 // DestroyScene modify __formToPanelMultiMap so can't destroy here.
1733                         }
1734                 }
1735
1736                 for (int i = 0; i < destroyList.GetCount(); i++)
1737                 {
1738                         Scene* pCurrentScene = null;
1739                         destroyList.GetAt(i, pCurrentScene);
1740                         if (pCurrentScene)
1741                         {
1742                                 DestroyScene(pCurrentScene->GetSceneId());
1743                         }
1744                 }
1745         }
1746 }
1747
1748 Frame*
1749 _SceneManagerImpl::GetFrame(void)
1750 {
1751         if (__pCorrespondFrame == null)
1752         {
1753                 SysLog(NID_UI_SCENES, "WARNING! - Initialize error!. First GetInstance must call after set a FrameWindow.");
1754                 UiApp* pUiApp = UiApp::GetInstance();
1755                 SysTryReturn(NID_UI_SCENES, pUiApp != null, null, E_SYSTEM,
1756                                          "[%s] A system error has been occurred. UiApp::GetInstance failed.", GetErrorMessage(E_SYSTEM));
1757                 Frame* pFrame = pUiApp->GetFrameAt(0);
1758                 SysTryReturn(NID_UI_SCENES, pFrame != null, null, E_SYSTEM,
1759                                          "[%s] A system error has been occurred. pUiApp->GetFrameAt(0) return null.", GetErrorMessage(E_SYSTEM));
1760                 __pCorrespondFrame = pFrame;
1761                 _ContainerImpl* pFrameWindowImpl = _ContainerImpl::GetInstance(*__pCorrespondFrame);
1762                 if (pFrameWindowImpl)
1763                 {
1764                         __correspondFrameControlHandle = pFrameWindowImpl->GetCore().GetHandle();
1765                 }
1766         }
1767         return __pCorrespondFrame;
1768 }
1769
1770 bool
1771 _SceneManagerImpl::IsAnimationCompleted(void)
1772 {
1773         Frame* pFrame = GetFrame();
1774         SysTryReturn(NID_UI_SCENES, pFrame != null, true, E_SYSTEM, "[%s] A system error has been occurred. Cannot get Frame.",
1775                                  GetErrorMessage(E_SYSTEM));
1776         FrameAnimator* pFrameAnimator = pFrame->GetFrameAnimator();
1777
1778         if (pFrameAnimator)
1779         {
1780                 bool completed = (pFrameAnimator->GetStatus() == ANIMATOR_STATUS_STOPPED) ? true : false;
1781                 return completed;
1782         }
1783         return true;
1784 }
1785
1786 result
1787 _SceneManagerImpl::SetInputEventEnableState(Tizen::Ui::Control& control, bool enableState)
1788 {
1789         _ControlImpl* pControlImpl = _ControlImpl::GetInstance(control);
1790         SysTryReturnResult(NID_UI_SCENES, pControlImpl != null, E_SYSTEM, "A system error has been occurred. Cannot get _ControlImpl.");
1791         _Control& controlCore = pControlImpl->GetCore();
1792
1793         if (enableState == false)
1794         {
1795                 controlCore.LockInputEvent();
1796         }
1797         else
1798         {
1799                 controlCore.UnlockInputEvent();
1800         }
1801         return E_SUCCESS;
1802 }
1803
1804 result
1805 _SceneManagerImpl::GetSceneTransition(const SceneTransitionId& transitionId, SceneTransition& sceneTransition) const
1806 {
1807         result r = E_SUCCESS;
1808         SysTryReturnResult(NID_UI_SCENES, !transitionId.IsEmpty(), E_INVALID_ARG,
1809                                            "Invalid argument is used. The transitionId is empty.");
1810
1811         SceneTransition* pSceneTransition = null;
1812         r = __transitionMap.GetValue(transitionId, pSceneTransition);
1813         SysTryReturn(NID_UI_SCENES, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
1814         sceneTransition = *pSceneTransition;
1815
1816         return r;
1817 }
1818
1819 result
1820 _SceneManagerImpl::RegisterScene(xmlNodePtr pNode)
1821 {
1822         static const char* pPropId = "Id";
1823         static const char* pPropFormId = "Form";
1824         static const char* pPropPanelId = "Panel";
1825         result r = E_SUCCESS;
1826         _SceneDescription* pSceneDescription = null;
1827
1828         SysTryReturn(NID_UI_SCENES, pNode != null, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. pNode is null.",
1829                                  GetErrorMessage(E_INVALID_ARG));
1830
1831         xmlChar* pSceneId = xmlGetProp(pNode, reinterpret_cast<const xmlChar*>(pPropId));
1832         if (pSceneId)
1833         {
1834                 String strSceneId(reinterpret_cast<char*>(pSceneId));
1835                 xmlFree(pSceneId);
1836
1837                 xmlChar* pFormId = xmlGetProp(pNode, reinterpret_cast<const xmlChar*>(pPropFormId));
1838                 if (pFormId)
1839                 {
1840                         String strFormId(reinterpret_cast<char*>(pFormId));
1841                         xmlFree(pFormId);
1842
1843                         String strPanelId;
1844                         xmlChar* pPanelId = xmlGetProp(pNode, reinterpret_cast<const xmlChar*>(pPropPanelId));
1845                         if (pPanelId)
1846                         {
1847                                 strPanelId = reinterpret_cast<char*>(pPanelId);
1848                                 xmlFree(pPanelId);
1849                         }
1850
1851                         // Register a Scene item
1852                         bool isContains = false;
1853                         r = __sceneMap.ContainsKey(strSceneId, isContains);
1854                         SysTryReturn(NID_UI_SCENES, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
1855                         SysTryReturnResult(NID_UI_SCENES, !isContains, E_OBJ_ALREADY_EXIST, "Specified sceneId already exist.");
1856
1857                         pSceneDescription = new (std::nothrow) _SceneDescription(strFormId, strPanelId);
1858                         SysTryReturnResult(NID_UI_SCENES, pSceneDescription != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
1859
1860                         r = __sceneMap.Add(strSceneId, pSceneDescription);
1861                         SysTryCatch(NID_UI_SCENES, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
1862                 }
1863         }
1864         return r;
1865
1866 CATCH:
1867         delete pSceneDescription;
1868         return r;
1869 }
1870
1871 result
1872 _SceneManagerImpl::RegisterSceneTransition(xmlNodePtr pNode)
1873 {
1874         static const xmlChar* pPropId = reinterpret_cast<const xmlChar*>("Id");
1875         static const char* pPropDestinationSceneId = "TargetId";
1876         static const char* pPropDirectionType = "DirectionType";
1877         static const char* pPropAnimationType = "AnimationType";
1878         static const char* pPropHistoryOption = "HistoryOption";
1879         static const char* pPropDestroyOption = "DestroyOption";
1880
1881         static const String strValueDirectionForward(L"forward");
1882         static const String strValueDirectionBackward(L"backward");
1883         static const String strValueDirectionAdjacentBackward(L"adjacentBackward");
1884         static const String strValueAnimationType[] = {L"none", L"custom", L"left", L"right", L"fade_in_out",
1885                                                                                                    L"zoom_in", L"zoom_out", L"depth_in", "depth_out"};
1886         static const String strValueHistoryOptionNoHistory(L"no");
1887         static const String strValueDestroyOptionKeep(L"keep");
1888         static const String strValueDestroyOptionDestroy(L"destroy");
1889
1890         static const SceneTransitionAnimationType valueAnimation[] = {
1891                 SCENE_TRANSITION_ANIMATION_TYPE_NONE, SCENE_TRANSITION_ANIMATION_TYPE_CUSTOM,
1892                 SCENE_TRANSITION_ANIMATION_TYPE_LEFT, SCENE_TRANSITION_ANIMATION_TYPE_RIGHT,
1893                 SCENE_TRANSITION_ANIMATION_TYPE_FADE_IN_OUT, SCENE_TRANSITION_ANIMATION_TYPE_ZOOM_IN,
1894                 SCENE_TRANSITION_ANIMATION_TYPE_ZOOM_OUT, SCENE_TRANSITION_ANIMATION_TYPE_DEPTH_IN,
1895                 SCENE_TRANSITION_ANIMATION_TYPE_DEPTH_OUT };
1896
1897         SceneTransition* pSceneTransition = null;
1898         result r = E_SUCCESS;
1899         SysTryReturn(NID_UI_SCENES, pNode != null, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. pNode is null.",
1900                                  GetErrorMessage(E_INVALID_ARG));
1901
1902         xmlChar* pTransitionId = xmlGetProp(pNode, pPropId);
1903         if (pTransitionId)
1904         {
1905                 String strTransitionId(reinterpret_cast<char*>(pTransitionId));
1906                 xmlFree(pTransitionId);
1907                 if (strTransitionId.GetLength() > 0)
1908                 {
1909                         xmlChar* pDirectionType = xmlGetProp(pNode, reinterpret_cast<const xmlChar*>(pPropDirectionType));
1910                         if (pDirectionType)
1911                         {
1912                                 String strDirectionType(reinterpret_cast<char*>(pDirectionType));
1913                                 xmlFree(pDirectionType);
1914
1915                                 // Mandatory item: transitionId, direction
1916                                 // forward: destinationSceneId(mandatory), animationType, historyOption, destroyOption
1917                                 // backward: destinationSceneId(mandatory), animationType, destroyOption [ Don't care: historyOption ]
1918                                 // adjacentBackward: animationType, destroyOption [ Don't care: destinationSceneId, historyOption]
1919                                 String strDestinationSceneId;
1920                                 String strAnimationType;
1921                                 String strHistoryOption;
1922                                 String strDestroyOption;
1923                                 SceneTransitionAnimationType animationType = SCENE_TRANSITION_ANIMATION_TYPE_NONE;
1924
1925                                 // Get animationType and destroyOption (common property)
1926                                 xmlChar* pAnimationType = xmlGetProp(pNode, reinterpret_cast<const xmlChar*>(pPropAnimationType));
1927                                 if (pAnimationType)
1928                                 {
1929                                         strAnimationType = reinterpret_cast<char*>(pAnimationType);
1930                                         xmlFree(pAnimationType);
1931                                         if (strAnimationType.GetLength() > 0)
1932                                         {
1933                                                 for (unsigned int i = 0; i < sizeof(valueAnimation)/sizeof(valueAnimation[0]); i++)
1934                                                 {       // Consider to use map collection.
1935                                                         if (strAnimationType == strValueAnimationType[i])
1936                                                         {
1937                                                                 animationType = valueAnimation[i];
1938                                                                 break;
1939                                                         }
1940                                                 }
1941                                         }
1942                                 }
1943
1944                                 xmlChar* pDestroyOption = xmlGetProp(pNode, reinterpret_cast<const xmlChar*>(pPropDestroyOption));
1945                                 if (pDestroyOption)
1946                                 {
1947                                         strDestroyOption = reinterpret_cast<char*>(pDestroyOption);
1948                                         xmlFree(pDestroyOption);
1949                                 }
1950
1951                                 // Compose SceneTransition
1952                                 if (strDirectionType == strValueDirectionAdjacentBackward)      // Adjacent backward
1953                                 {
1954                                         SceneDestroyOption destroyOption = SCENE_DESTROY_OPTION_DESTROY;        // Default is destroy
1955                                         if ((strDestroyOption.GetLength() > 0) && (strDestroyOption == strValueDestroyOptionKeep))
1956                                         {
1957                                                 destroyOption = SCENE_DESTROY_OPTION_KEEP;
1958                                         }
1959
1960                                         pSceneTransition = new (std::nothrow) BackwardSceneTransition(animationType, destroyOption);
1961                                         SysTryReturnResult(NID_UI_SCENES, pSceneTransition != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
1962                                         r = __transitionMap.Add(strTransitionId, pSceneTransition);
1963                                         SysTryCatch(NID_UI_SCENES, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
1964                                         return r;
1965                                 }
1966
1967                                 // Get destinationSceneId
1968                                 xmlChar* pDestinationSceneId = xmlGetProp(pNode, reinterpret_cast<const xmlChar*>(pPropDestinationSceneId));
1969                                 if (pDestinationSceneId)
1970                                 {
1971                                         strDestinationSceneId = reinterpret_cast<char*>(pDestinationSceneId);
1972                                         xmlFree(pDestinationSceneId);
1973                                 }
1974                                 SysTryReturn(NID_UI_SCENES, strDestinationSceneId.GetLength() > 0, E_INVALID_ARG, E_INVALID_ARG,
1975                                                          "[%s] Invalid argument is used. strDestinationSceneId is empty.", GetErrorMessage(E_INVALID_ARG));
1976
1977                                 if (strDirectionType == strValueDirectionBackward)              // Backward
1978                                 {
1979                                         SceneDestroyOption destroyOption = SCENE_DESTROY_OPTION_DESTROY;        // Default is destroy
1980                                         if ((strDestroyOption.GetLength() > 0) && (strDestroyOption == strValueDestroyOptionKeep))
1981                                         {
1982                                                 destroyOption = SCENE_DESTROY_OPTION_KEEP;
1983                                         }
1984
1985                                         pSceneTransition =
1986                                                         new (std::nothrow) BackwardSceneTransition(strDestinationSceneId, animationType, destroyOption);
1987                                         SysTryReturnResult(NID_UI_SCENES, pSceneTransition != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
1988                                         r = __transitionMap.Add(strTransitionId, pSceneTransition);
1989                                         SysTryCatch(NID_UI_SCENES, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
1990                                         return r;
1991                                 }
1992
1993                                 if (strDirectionType == strValueDirectionForward)               // Forward
1994                                 {
1995                                         SceneDestroyOption destroyOption = SCENE_DESTROY_OPTION_KEEP;           // Default is keep
1996                                         if ((strDestroyOption.GetLength() > 0) && (strDestroyOption == strValueDestroyOptionDestroy))
1997                                         {
1998                                                 destroyOption = SCENE_DESTROY_OPTION_DESTROY;
1999                                         }
2000
2001                                         xmlChar* pHistoryOption = xmlGetProp(pNode, reinterpret_cast<const xmlChar*>(pPropHistoryOption));
2002                                         if (pHistoryOption)
2003                                         {
2004                                                 strHistoryOption = reinterpret_cast<char*>(pHistoryOption);
2005                                                 xmlFree(pHistoryOption);
2006                                         }
2007                                         SceneHistoryOption historyOption = SCENE_HISTORY_OPTION_ADD_HISTORY;    // Default is add to history
2008                                         if ((strHistoryOption.GetLength() > 0) && (strHistoryOption == strValueHistoryOptionNoHistory))
2009                                         {
2010                                                 historyOption = SCENE_HISTORY_OPTION_NO_HISTORY;
2011                                         }
2012
2013                                         pSceneTransition = new (std::nothrow) ForwardSceneTransition(strDestinationSceneId, animationType,
2014                                                                                                                                                                  historyOption, destroyOption);
2015                                         SysTryReturnResult(NID_UI_SCENES, pSceneTransition != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
2016                                         r = __transitionMap.Add(strTransitionId, pSceneTransition);
2017                                         SysTryCatch(NID_UI_SCENES, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
2018                                         return r;
2019                                 }
2020                                 else
2021                                 {
2022                                         SysLog(NID_UI_SCENES, "Unknown direction type!");
2023                                 }
2024                         }
2025                 }
2026         }
2027         return r;
2028
2029 CATCH:
2030         delete pSceneTransition;
2031         return r;
2032 }
2033
2034 result
2035 _SceneManagerImpl::StopAllAnimations(void)
2036 {
2037         Frame* pFrame = GetFrame();
2038         SysTryReturnResult(NID_UI_SCENES, pFrame != null, E_SYSTEM, "A system error has been occurred. Cannot get Frame.");
2039         FrameAnimator* pFrameAnimator = pFrame->GetFrameAnimator();
2040         SysTryReturnResult(NID_UI_SCENES, pFrameAnimator != null, E_SYSTEM, "A system error has been occurred. Cannot get FrameAnimator.");
2041         pFrameAnimator->StopAllAnimations();
2042         if (!__destroyReservedScene.IsEmpty())
2043         {
2044                 DestroyScene(__destroyReservedScene);
2045                 __destroyReservedScene.Clear();
2046         }
2047         return E_SUCCESS;
2048 }
2049
2050 } } } // Tizen::Ui::Scenes