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