2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0/
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.
19 #include <unique_ptr.h>
20 #include <FAppUiApp.h>
21 #include <FAppIAppFrame.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"
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;
61 namespace Tizen { namespace Ui { namespace Scenes
64 // HashMapT assist template
66 class _StringHashCodeProvider
67 : public IHashCodeProviderT <T>
71 GetHashCode(const T& obj) const
73 String& objString = static_cast <String&>(const_cast <T&>(obj));
74 return objString.GetHashCode();
79 : public IComparerT <T>
83 Compare(const T& obj1, const T& obj2, int& cmp) const
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);
93 _SceneManagerImpl::_SceneDescription::_SceneDescription(const String& descriptionFormId, const String& descriptionPanelId)
94 : formId(descriptionFormId)
95 , panelId(descriptionPanelId)
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)
112 for (int i = 0; i < FRAME_ANIMATOR_FORM_TRANSITION_ANIMATION_MAX; i++)
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;
119 __sceneTransitionMutex.Create();
122 _SceneManagerImpl::~_SceneManagerImpl(void)
124 bool memoryError = false;
126 std::unique_ptr<IMapEnumeratorT<String, _SceneDescription*> > pMapEnum(__sceneMap.GetMapEnumeratorN());
129 while (pMapEnum->MoveNext() == E_SUCCESS)
131 _SceneDescription* pValue = null;
132 pMapEnum->GetValue(pValue);
141 std::unique_ptr<IMapEnumeratorT<String, SceneTransition*> > pTransitionMapEnum(__transitionMap.GetMapEnumeratorN());
142 if (pTransitionMapEnum)
144 while (pTransitionMapEnum->MoveNext() == E_SUCCESS)
146 SceneTransition* pValue = null;
147 pTransitionMapEnum->GetValue(pValue);
156 std::unique_ptr<IMapEnumeratorT<SceneId, Scene*> > pSceneContainerEnum(__sceneContainer.GetMapEnumeratorN());
157 if (pSceneContainerEnum)
159 while (pSceneContainerEnum->MoveNext() == E_SUCCESS)
161 Scene* pValue = null;
162 pSceneContainerEnum->GetValue(pValue);
173 SysLogException(NID_UI_SCENES, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
178 _SceneManagerImpl::Construct(void)
180 result r = E_SUCCESS;
181 static _StringHashCodeProvider <String> sceneHashCodeProvider;
182 static _StringComparer <String> strComparer;
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));
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));
202 UiApp* pUiApp = UiApp::GetInstance();
203 SysTryReturn(NID_UI_SCENES, pUiApp != null, null, E_SYSTEM,
204 "[%s] A system error has been occurred. UiApp::GetInstance failed.", GetErrorMessage(E_SYSTEM));
205 Frame* pFrame = pUiApp->GetFrameAt(0);
206 SysTryReturn(NID_UI_SCENES, pFrame != null, null, E_SYSTEM,
207 "[%s] A system error has been occurred. pUiApp->GetFrameAt(0) return null.", GetErrorMessage(E_SYSTEM));
208 __pCorrespondFrame = pFrame;
209 _ContainerImpl* pFrameWindowImpl = _ContainerImpl::GetInstance(*__pCorrespondFrame);
210 SysTryReturn(NID_UI_SCENES, pFrameWindowImpl != null, null, E_SYSTEM,
211 "[%s] A system error has been occurred. _ContainerImpl::GetInstance failed.", GetErrorMessage(E_SYSTEM));
212 __correspondFrameControlHandle = pFrameWindowImpl->GetCore().GetHandle();
218 _SceneManagerImpl::RegisterFormFactory(const IFormFactory& formFactory)
220 __pFormFactory = const_cast <IFormFactory*>(&formFactory);
226 _SceneManagerImpl::RegisterPanelFactory(const IPanelFactory& panelFactory)
228 __pPanelFactory = const_cast <IPanelFactory*>(&panelFactory);
234 _SceneManagerImpl::RegisterScene(const SceneId& sceneId, const String& formId, const String& panelId)
236 result r = E_SUCCESS;
237 _SceneDescription* pSceneDescription = null;
238 bool isContains = false;
240 SysTryReturnResult(NID_UI_SCENES, !(sceneId.IsEmpty() || formId.IsEmpty()), E_INVALID_ARG,
241 "Invalid argument is used. String length of sceneId=%d, formId=%d",
242 sceneId.GetLength(), formId.GetLength());
244 r = __sceneMap.ContainsKey(sceneId, isContains);
245 SysTryReturn(NID_UI_SCENES, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
246 SysTryReturnResult(NID_UI_SCENES, !isContains, E_OBJ_ALREADY_EXIST, "Specified sceneId already exist.");
248 __formIdMap.ContainsKey(formId, isContains);
249 if (panelId.IsEmpty())
251 SysTryReturnResult(NID_UI_SCENES, !isContains, E_INVALID_ARG, "Specified formId already exist. Only 'PanelScene' can share a formId for use as base form.");
256 __formIdMap.Add(formId, 1);
261 __formIdMap.GetValue(formId, refCount);
263 __formIdMap.SetValue(formId, refCount);
266 pSceneDescription = new (std::nothrow) _SceneDescription(formId, panelId);
267 SysTryReturnResult(NID_UI_SCENES, pSceneDescription != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
269 r = __sceneMap.Add(sceneId, pSceneDescription);
270 SysTryCatch(NID_UI_SCENES, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
274 delete pSceneDescription;
279 _SceneManagerImpl::RegisterScene(const String& resourceId)
281 static const wchar_t RESOUCE_FILE_PATH[] = L"res/";
282 static const wchar_t RESOUCE_FILE_EXT[] = L".xml";
283 static const wchar_t RESOUCE_FILE_NORMAL[] = L"screen-size-normal/";
284 static const xmlChar* pElementWorkflow = reinterpret_cast<const xmlChar*>("Workflow");
285 static const xmlChar* pElementScene = reinterpret_cast<const xmlChar*>("Scene");
286 static const xmlChar* pElementSceneTransition = reinterpret_cast<const xmlChar*>("SceneTransition");
287 result r = E_SUCCESS;
289 _ControlManager* pControlManager = _ControlManager::GetInstance();
290 SysTryReturnResult(NID_UI_SCENES, pControlManager != null, E_SYSTEM,
291 "A system error has been occurred. Unable to get the control manager.");
292 Dimension screenSize = pControlManager->GetScreenSize();
294 const String appRootPath = Tizen::App::App::GetInstance()->GetAppRootPath();
296 // Formating path for current resolution: [AppRootPath/][res/][width]x[height]/[resourceId][.xml]
297 r = filePath.Format(FILENAME_MAX, L"%ls%ls%dx%d/%ls%ls",
298 appRootPath.GetPointer(), RESOUCE_FILE_PATH, screenSize.width, screenSize.height,
299 resourceId.GetPointer(), RESOUCE_FILE_EXT);
300 SysTryReturnResult(NID_UI_SCENES, !IsFailed(r), E_SYSTEM, "A system error has been occurred. File path formatting failed.");
301 SysLog(NID_UI_SCENES, "RegisterScene: res path: %ls", filePath.GetPointer());
303 if (!File::IsFileExist(filePath))
304 { // File not exist on specific resolution then try again: [AppRootPath/][res/][screen-size-normal/][resourceId][.xml]
305 filePath.Format(FILENAME_MAX, L"%ls%ls%ls%ls%ls",
306 appRootPath.GetPointer(), RESOUCE_FILE_PATH, RESOUCE_FILE_NORMAL,
307 resourceId.GetPointer(), RESOUCE_FILE_EXT);
308 SysTryReturnResult(NID_UI_SCENES, !IsFailed(r), E_SYSTEM, "A system error has been occurred. File path formatting failed.");
309 SysLog(NID_UI_SCENES, "RegisterScene: 2nd try - res path: %ls", filePath.GetPointer());
310 if (!pControlManager->IsCoordinateSystemLogical() || !File::IsFileExist(filePath))
312 SysLogException(NID_UI_SCENES, E_FILE_NOT_FOUND, "[%s] File could not be found. File path=%ls",
313 GetErrorMessage(E_FILE_NOT_FOUND), filePath.GetPointer());
314 return E_FILE_NOT_FOUND;
318 std::unique_ptr<ByteBuffer> pfilePathBuffer(Tizen::Base::Utility::StringUtil::StringToUtf8N(filePath));
319 SysTryReturnResult(NID_UI_SCENES, pfilePathBuffer != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
321 xmlDocPtr docPtr = xmlParseFile(reinterpret_cast<const char*>(pfilePathBuffer->GetPointer()));
322 SysTryReturnResult(NID_UI_SCENES, docPtr != null, E_SYSTEM,
323 "A system error has been occurred. Can not parse xml file: %ls", filePath.GetPointer());
325 xmlNodePtr rootNodePtr = xmlDocGetRootElement(docPtr);
326 SysTryReturnResult(NID_UI_SCENES, rootNodePtr != null, E_SYSTEM,
327 "A system error has been occurred. Can not find root node");
330 for (xmlNodePtr nodePtr = rootNodePtr; nodePtr != null; nodePtr = nodePtr->next) // Visit sibling node
331 { // Get element 'Workflow'
332 if ((nodePtr->type == XML_ELEMENT_NODE) && (xmlStrcmp(nodePtr->name, pElementWorkflow) == 0))
333 { // and Get child - 'Scene's and 'SceneTransition's
334 for (xmlNodePtr childNodePtr = nodePtr->children; childNodePtr != null; childNodePtr = childNodePtr->next) // Visit sibling
335 { // Get element 'Scene's and 'SceneTransition's
336 if (childNodePtr->type == XML_ELEMENT_NODE)
337 { // Check E_OBJ_ALREADY_EXIST(continue) and E_OUT_OF_MEMORY(break) for all case.
338 if (xmlStrcmp(childNodePtr->name, pElementScene) == 0)
340 result regResult = RegisterScene(childNodePtr);
341 if (IsFailed(regResult))
343 SysTryCatch(NID_UI_SCENES, regResult != E_OUT_OF_MEMORY, r = regResult, regResult,
344 "[%s] Propagating.", GetErrorMessage(regResult));
345 if (regResult == E_OBJ_ALREADY_EXIST)
352 if (xmlStrcmp(childNodePtr->name, pElementSceneTransition) == 0)
354 result regResult = RegisterSceneTransition(childNodePtr);
355 if (IsFailed(regResult))
357 SysTryCatch(NID_UI_SCENES, regResult != E_OUT_OF_MEMORY, r = regResult, regResult,
358 "[%s] Propagating.", GetErrorMessage(regResult));
359 if (regResult == E_OBJ_ALREADY_EXIST)
365 } // 'Scene' and 'SceneTransition'
366 } // Children of 'Workflow'
367 } // Element 'Workflow'
368 }// Root node sibling
379 _SceneManagerImpl::UnregisterScene(const SceneId& sceneId)
381 result r = E_SUCCESS;
382 _SceneDescription* pSceneDescription = null;
384 SysTryReturnResult(NID_UI_SCENES, !sceneId.IsEmpty(), E_INVALID_ARG, "Invalid argument is used. sceneId is empty.");
386 r = __sceneMap.GetValue(sceneId, pSceneDescription);
387 SysTryReturn(NID_UI_SCENES, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
389 // Remove FormId from __formIdMap
390 if (pSceneDescription)
392 bool isContains = false;
393 __formIdMap.ContainsKey(pSceneDescription->formId, isContains);
397 __formIdMap.GetValue(pSceneDescription->formId, refCount);
401 __formIdMap.Remove(pSceneDescription->formId);
405 __formIdMap.SetValue(pSceneDescription->formId, refCount);
410 r = __sceneMap.Remove(sceneId);
411 SysTryReturn(NID_UI_SCENES, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
413 delete pSceneDescription;
418 _SceneManagerImpl::AddSceneManagerEventListener(ISceneManagerEventListener& sceneManagerEventListener)
420 result r = E_SUCCESS;
421 ISceneManagerEventListener* pListener = &sceneManagerEventListener;
422 bool alreadyExist = __sceneManagerEventListenerList.Contains(pListener);
423 SysTryReturnResult(NID_UI_SCENES, !alreadyExist, E_OBJ_ALREADY_EXIST, "The event listener already exist.");
424 r = __sceneManagerEventListenerList.Add(pListener);
425 SysTryReturn(NID_UI_SCENES, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
431 _SceneManagerImpl::RemoveSceneManagerEventListener(ISceneManagerEventListener& sceneManagerEventListener)
433 result r = E_SUCCESS;
434 ISceneManagerEventListener* pListener = &sceneManagerEventListener;
435 r = __sceneManagerEventListenerList.Remove(pListener);
436 SysTryReturn(NID_UI_SCENES, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
442 _SceneManagerImpl::AddSceneEventListener(const SceneId& sceneId, ISceneEventListener& sceneEventListener)
444 result r = E_SUCCESS;
445 Scene* pScene = null;
446 _SceneImpl* pSceneImpl = null;
448 pScene = GetSceneFromContainer(sceneId);
449 SysTryReturnResult(NID_UI_SCENES, pScene != null, E_INVALID_ARG, "Invalid argument is used. The sceneId is not valid.");
450 pSceneImpl = _SceneImpl::GetInstance(*pScene);
451 SysTryReturnResult(NID_UI_SCENES, pSceneImpl != null, E_INVALID_ARG, "Invalid argument is used. The sceneId is not valid.");
452 r = pSceneImpl->AddSceneEventListener(sceneEventListener);
453 SysTryReturn(NID_UI_SCENES, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
459 _SceneManagerImpl::RemoveSceneEventListener(const SceneId& sceneId, ISceneEventListener& sceneEventListener)
461 result r = E_SUCCESS;
462 Scene* pScene = null;
463 _SceneImpl* pSceneImpl = null;
465 pScene = GetSceneFromContainer(sceneId);
466 SysTryReturnResult(NID_UI_SCENES, pScene != null, E_INVALID_ARG, "Invalid argument is used. The sceneId is not valid.");
467 pSceneImpl = _SceneImpl::GetInstance(*pScene);
468 SysTryReturnResult(NID_UI_SCENES, pSceneImpl != null, E_INVALID_ARG, "Invalid argument is used. The sceneId is not valid.");
469 r = pSceneImpl->RemoveSceneEventListener(sceneEventListener);
470 SysTryReturn(NID_UI_SCENES, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
476 _SceneManagerImpl::SetSceneAnimationProvider(const SceneId& sceneId, ISceneAnimationProvider* pSceneAnimationProvider)
478 result r = E_SUCCESS;
479 Scene* pScene = null;
480 _SceneImpl* pSceneImpl = null;
482 pScene = GetSceneFromContainer(sceneId);
483 SysTryReturnResult(NID_UI_SCENES, pScene != null, E_INVALID_ARG, "Invalid argument is used. The sceneId is not valid.");
484 pSceneImpl = _SceneImpl::GetInstance(*pScene);
485 SysTryReturnResult(NID_UI_SCENES, pSceneImpl != null, E_INVALID_ARG, "Invalid argument is used. The sceneId is not valid.");
486 r = pSceneImpl->SetSceneAnimationProvider(pSceneAnimationProvider);
487 SysTryReturn(NID_UI_SCENES, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
493 _SceneManagerImpl::SetSceneTransitionPolicyProvider(ISceneTransitionPolicyProvider* pSceneTransitionPolicyProvider)
495 __pPolicyProvider = pSceneTransitionPolicyProvider;
501 _SceneManagerImpl::SetFormTransitionAnimationDefaultValues(SceneTransitionAnimationType animationType, long duration,
502 AnimationInterpolatorType interpolatorType)
504 static const long DURATION_MIN = 0;
505 static const long DURATION_MAX = 1000;
507 SysTryReturnResult(NID_UI_SCENES, (SCENE_TRANSITION_ANIMATION_TYPE_LEFT <= animationType &&
508 animationType <= SCENE_TRANSITION_ANIMATION_TYPE_DEPTH_OUT), E_INVALID_ARG,
509 "Invalid argument is used. animationType=%d", animationType);
510 SysTryReturnResult(NID_UI_SCENES, (DURATION_MIN <= duration && duration <= DURATION_MAX), E_INVALID_ARG,
511 "Invalid argument is used. duration=%d", duration);
512 __animationDescriptions[animationType - SCENE_TRANSITION_ANIMATION_TYPE_LEFT].duration = duration;
513 __animationDescriptions[animationType - SCENE_TRANSITION_ANIMATION_TYPE_LEFT].interpolatorType = interpolatorType;
519 _SceneManagerImpl::GoForward(const ForwardSceneTransition& sceneTransition, const Tizen::Base::Collection::IList* pArgs)
521 //## Temporary - Currently no support Non-Recursive Lock(Mutex).
522 SysTryReturnResult(NID_UI_SCENES, !__sceneTransitionProgressing, E_IN_PROGRESS, "Previous operation in progressing");
524 result r = __sceneTransitionMutex.TryToAcquire();
525 SysTryReturnResult(NID_UI_SCENES, r != E_OBJECT_LOCKED, E_IN_PROGRESS, "Previous operation in progressing");
526 SysTryReturnResult(NID_UI_SCENES, r != E_SYSTEM, E_SYSTEM, "A system error has been occurred.");
527 r = __sceneTransitionMutex.Acquire();
528 SysTryReturnResult(NID_UI_SCENES, !IsFailed(r), E_SYSTEM, "A system error has been occurred. Mutex acquire failed.");
529 __sceneTransitionProgressing = true; //## Temporary
532 _SceneTransitionImpl forwardSceneTransition;
534 forwardSceneTransition = *_SceneTransitionImpl::GetInstance(static_cast<const SceneTransition&>(sceneTransition));
535 SysTryCatch(NID_UI_SCENES, forwardSceneTransition.GetDirection() == SCENE_TRANSITION_DIRECTION_FORWARD, r= E_INVALID_ARG,
536 E_INVALID_ARG, "[%s] Invalid argument is used. sceneTransition's direction is not SCENE_TRANSITION_DIRECTION_FORWARD.", GetErrorMessage(E_INVALID_ARG));
538 sceneId = forwardSceneTransition.GetDestinationSceneId();
539 if (sceneId.GetLength() > 0)
541 // Prevent transit to current scene
542 SysTryCatch(NID_UI_SCENES, __currentSceneId != sceneId, r = E_INVALID_ARG, E_INVALID_ARG,
543 "[%s] Invalid argument is used. Can't forward to current Scene.", GetErrorMessage(E_INVALID_ARG));
546 if (!IsAnimationCompleted())
548 r = StopAllAnimations();
549 SysTryCatch(NID_UI_SCENES, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
552 // Go to the specified scene
553 r = GotoScene(true, sceneId, forwardSceneTransition.GetAnimationType(),
554 forwardSceneTransition.GetHistoryOption(), forwardSceneTransition.GetDestroyOption(), pArgs);
555 SysTryCatch(NID_UI_SCENES, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
558 { // Transition via PolicyProvider
559 SysTryCatch(NID_UI_SCENES, __pPolicyProvider != null, r = E_INVALID_STATE, E_INVALID_STATE,
560 "[%s] SceneManager is in an invalid state. Policy provider not registered.", GetErrorMessage(E_INVALID_STATE));
562 SceneId nextSceneId = __pPolicyProvider->GetNextScene(__currentSceneId, pArgs);
563 SysTryCatch(NID_UI_SCENES, !nextSceneId.IsEmpty(), r = E_INVALID_STATE, E_INVALID_STATE,
564 "[%s] SceneManager is in an invalid state. Policy provider does not know next scene. Current scene= %ls",
565 GetErrorMessage(E_INVALID_STATE), __currentSceneId.GetPointer());
567 // Prevent transit to current scene
568 SysTryCatch(NID_UI_SCENES, __currentSceneId != nextSceneId, r = E_INVALID_ARG, E_INVALID_ARG,
569 "[%s] Invalid argument is used. Can't forward to current Scene.", GetErrorMessage(E_INVALID_ARG));
572 if (!IsAnimationCompleted())
574 r = StopAllAnimations();
575 SysTryCatch(NID_UI_SCENES, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
578 r = GotoScene(true, nextSceneId, forwardSceneTransition.GetAnimationType(),
579 forwardSceneTransition.GetHistoryOption(), forwardSceneTransition.GetDestroyOption(), pArgs);
580 SysTryCatch(NID_UI_SCENES, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
586 __sceneTransitionProgressing = false; //## Temporary
587 SysTryReturnResult(NID_UI_SCENES, !IsFailed(__sceneTransitionMutex.Release()), E_SYSTEM,
588 "A system error has been occurred. Mutext release failed.");
593 _SceneManagerImpl::GoForward(const SceneTransitionId& transitionId, const Tizen::Base::Collection::IList* pArgs)
595 ForwardSceneTransition forwardTransition;
597 result r = GetSceneTransition(transitionId, forwardTransition);
598 SysTryReturnResult(NID_UI_SCENES, !IsFailed(r), E_INVALID_ARG, "Cannot get transition from Id.");
600 return GoForward(forwardTransition, pArgs);
604 _SceneManagerImpl::GoBackward(const BackwardSceneTransition& sceneTransition, const Tizen::Base::Collection::IList* pArgs)
606 //## Temporary - Currently no support Non-Recursive Lock(Mutex).
607 SysTryReturnResult(NID_UI_SCENES, !__sceneTransitionProgressing, E_IN_PROGRESS, "Previous operation in progressing");
609 result r = __sceneTransitionMutex.TryToAcquire();
610 SysTryReturnResult(NID_UI_SCENES, r != E_OBJECT_LOCKED, E_IN_PROGRESS, "Previous operation in progressing");
611 SysTryReturnResult(NID_UI_SCENES, r != E_SYSTEM, E_SYSTEM, "A system error has been occurred.");
612 r = __sceneTransitionMutex.Acquire();
613 SysTryReturnResult(NID_UI_SCENES, !IsFailed(r), E_SYSTEM, "A system error has been occurred. Mutex acquire failed.");
614 __sceneTransitionProgressing = true; //## Temporary
616 int historyCount = 0;
617 _SceneTransitionImpl backwardSceneTransition;
620 historyCount = __sceneHistory.GetCount();
621 SysTryCatch(NID_UI_SCENES, historyCount != 0, r = E_UNDERFLOW, E_UNDERFLOW, "[%s] The Scene history is empty.",
622 GetErrorMessage(E_UNDERFLOW));
624 backwardSceneTransition = *_SceneTransitionImpl::GetInstance(sceneTransition);
625 SysTryCatch(NID_UI_SCENES, backwardSceneTransition.GetDirection() == SCENE_TRANSITION_DIRECTION_BACKWARD,
626 r = E_INVALID_ARG, E_INVALID_ARG,
627 "[%s] Invalid argument is used. sceneTransition's direction is not SCENE_TRANSITION_DIRECTION_BACKWARD!", GetErrorMessage(E_INVALID_ARG));
628 SysTryCatch(NID_UI_SCENES, backwardSceneTransition.GetHistoryOption() == SCENE_HISTORY_OPTION_NO_HISTORY,
629 r = E_INVALID_ARG, E_INVALID_ARG,
630 "[%s] Invalid argument is used. sceneTransition's history option is not SCENE_HISTORY_OPTION_NO_HISTORY!", GetErrorMessage(E_INVALID_ARG));
632 sceneId = backwardSceneTransition.GetDestinationSceneId();
633 if (sceneId.GetLength() > 0)
634 { // Back to specific scene and clean up history between destination and last point.
635 int historyIndex = -1;
636 SceneId destinationSceneId;
638 // 1. Back tracking and pick a first matching sceneId
639 r = __sceneHistory.LastIndexOf(sceneId, historyIndex);
640 SysTryCatch(NID_UI_SCENES, !IsFailed(r), r = E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND,
641 "[%s] The given sceneId was not found in the registered scenes.", GetErrorMessage(E_OBJ_NOT_FOUND));
642 r = __sceneHistory.GetAt(historyIndex, destinationSceneId);
643 SysTryCatch(NID_UI_SCENES, !IsFailed(r), r = E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.",
644 GetErrorMessage(E_SYSTEM));
646 // 2. if destoryOption == SCENE_DESTROY_OPTION_DESTROY then destroy all scenes except matching scene.
647 if (backwardSceneTransition.GetDestroyOption() == SCENE_DESTROY_OPTION_DESTROY)
649 for (int i = historyIndex+1; i < historyCount; i++)
651 SceneId destroyTargetSceneId;
652 __sceneHistory.GetAt(i, destroyTargetSceneId);
653 // Scene instance is not always valid.
654 Scene* pScene = GetSceneFromContainer(destroyTargetSceneId);
657 // If Panel Scene then destroy sibling Panel Scene(s).
658 if (pScene->GetPanel())
660 DestroySiblingPanelScene(destroyTargetSceneId);
662 DestroyScene(destroyTargetSceneId);
667 // 3. Remove all scenes on history between latest scene to matching scene.
668 r = __sceneHistory.RemoveItems(historyIndex, historyCount-historyIndex);
669 SysTryCatch(NID_UI_SCENES, !IsFailed(r), r = E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.",
670 GetErrorMessage(E_SYSTEM));
672 // Prevent transit to current scene
673 SysTryCatch(NID_UI_SCENES, __currentSceneId != destinationSceneId, r = E_INVALID_ARG, E_INVALID_ARG,
674 "[%s] Invalid argument is used. Can't backward to current Scene.", GetErrorMessage(E_INVALID_ARG));
676 // Stop previous animation
677 if (!IsAnimationCompleted())
679 r = StopAllAnimations();
680 SysTryCatch(NID_UI_SCENES, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
684 r = GotoScene(false, destinationSceneId, backwardSceneTransition.GetAnimationType(),
685 SCENE_HISTORY_OPTION_NO_HISTORY, backwardSceneTransition.GetDestroyOption(), pArgs);
686 SysTryCatch(NID_UI_SCENES, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
689 { // Adjacent backward transition
690 SceneId previousSceneId;
692 r = __sceneHistory.GetAt(historyCount-1, previousSceneId);
693 SysTryCatch(NID_UI_SCENES, !IsFailed(r), r = E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND,
694 "[%s] The given sceneId was not found in the registered scenes.", GetErrorMessage(E_OBJ_NOT_FOUND));
695 r = __sceneHistory.RemoveAt(historyCount-1);
696 SysTryCatch(NID_UI_SCENES, !IsFailed(r), r = E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.",
697 GetErrorMessage(E_SYSTEM));
699 // Prevent transit to current scene
700 SysTryCatch(NID_UI_SCENES, __currentSceneId != previousSceneId, r = E_INVALID_ARG, E_INVALID_ARG,
701 "[%s] Invalid argument is used. Can't backward to current Scene.", GetErrorMessage(E_INVALID_ARG));
703 // Stop previous animation
704 if (!IsAnimationCompleted())
706 r = StopAllAnimations();
707 SysTryCatch(NID_UI_SCENES, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
710 r = GotoScene(false, previousSceneId, backwardSceneTransition.GetAnimationType(),
711 SCENE_HISTORY_OPTION_NO_HISTORY, backwardSceneTransition.GetDestroyOption(), pArgs);
712 SysTryCatch(NID_UI_SCENES, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
718 __sceneTransitionProgressing = false; //## Temporary
719 SysTryReturnResult(NID_UI_SCENES, !IsFailed(__sceneTransitionMutex.Release()), E_SYSTEM,
720 "A system error has been occurred. Mutext release failed.");
725 _SceneManagerImpl::GoBackward(const SceneTransitionId& transitionId, const Tizen::Base::Collection::IList* pArgs)
727 BackwardSceneTransition backwardTransition;
729 result r = GetSceneTransition(transitionId, backwardTransition);
730 SysTryReturnResult(NID_UI_SCENES, !IsFailed(r), E_INVALID_ARG, "Cannot get transition from Id.");
732 return GoBackward(backwardTransition, pArgs);
736 _SceneManagerImpl::GetCurrentScene(void) const
738 return __pCurrentScene;
742 _SceneManagerImpl::GetCurrentSceneId(void) const
744 return __currentSceneId;
748 _SceneManagerImpl::IsSceneAlive(const SceneId& sceneId) const
750 return (GetSceneFromContainer(sceneId)) ? true : false;
754 _SceneManagerImpl::DestroyScene(const SceneId& sceneId)
756 result r = E_SUCCESS;
757 Scene* pScene = null;
758 bool isFormScene = false;
759 bool isLastPanel = false;
762 SysTryReturnResult(NID_UI_SCENES, __currentSceneId != sceneId, E_INVALID_ARG,
763 "Invalid argument is used. The current Scene can not be destroy.");
764 pScene = GetSceneFromContainer(sceneId);
765 SysTryReturnResult(NID_UI_SCENES, pScene != null, E_OBJ_NOT_FOUND, "Specified sceneId does not exist.");
767 // Ok now destroy associated Ui controls
768 // Form scene: Destroy Form - that's all.
769 // Panel scene: Normal case - destroy Panel only but the current scene is the last panel then destroy Form.
770 // Correspondent internal data item should be destroy.
771 if (!pScene->GetPanel())
777 r = __formToPanelMultiMap.GetCount(pScene->GetFormId(), panelCount);
778 SysTryReturnResult(NID_UI_SCENES, !IsFailed(r), E_SYSTEM,
779 "A system error has been occurred. Form(SceneId:%ls) is not valid.", sceneId.GetPointer());
787 { // 1. Remove Form control(Associated on Scene) from Frame
788 RemoveControlFromFrame(*pScene->GetForm());
789 // 2. Remove Form from Form container
790 RemoveFormFromFormContainer(pScene->GetFormId());
794 { // 1. Remove Panel from Panel container.
795 RemovePanelFromPanelContainer(pScene);
796 // 2. Remove Form control from Frame. (Associated Panel automatically removed by Ui)
797 RemoveControlFromFrame(*pScene->GetForm());
798 // 3. Remove Form from Form container.
799 RemoveFormFromFormContainer(pScene->GetFormId());
802 { // 1. Remove Panel from Panel container.
803 RemovePanelFromPanelContainer(pScene);
804 // 2. Remove Panel control from base Form
805 bool panelFromFormResouce = false;
806 _SceneImpl* pSceneImpl = _SceneImpl::GetInstance(*pScene);
809 panelFromFormResouce = pSceneImpl->IsPanelCreatedFromFormResource();
811 if (!panelFromFormResouce)
813 RemoveControlFromForm(*pScene->GetForm(), *pScene->GetPanel());
817 // Finally remove Scene
818 RemoveSceneFromContainer(sceneId);
825 _SceneManagerImpl::BringCurrentSceneToTop(void)
828 Scene* pCurrentScene = GetCurrentScene();
830 SysTryReturnResult(NID_UI_SCENES, pCurrentScene != null, E_OPERATION_FAILED, "The current Scene is not valid.");
831 pForm = pCurrentScene->GetForm();
832 SysTryReturnResult(NID_UI_SCENES, pForm != null, E_SYSTEM, "A system error has been occurred. The Form is not valid.");
833 result r = SetCurrentForm(*pForm);
834 SysTryReturnResult(NID_UI_SCENES, !IsFailed(r), E_SYSTEM, "A system error has been occurred.");
840 _SceneManagerImpl::ClearSceneHistory(void)
842 __sceneHistory.RemoveAll();
848 _SceneManagerImpl::AddToSceneHistory(const SceneId& sceneId)
850 result r = E_SUCCESS;
851 bool isContains = false;
853 SysTryReturnResult(NID_UI_SCENES, !sceneId.IsEmpty(), E_INVALID_ARG, "Invalid argument is used. sceneId length is 0.");
854 r = __sceneMap.ContainsKey(sceneId, isContains);
855 SysTryReturnResult(NID_UI_SCENES, isContains, E_OBJ_NOT_FOUND, "The sceneId is not registered.");
856 r = AddHistory(sceneId);
857 SysTryReturn(NID_UI_SCENES, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
863 _SceneManagerImpl::GetSceneHistoryN(void) const
865 std::unique_ptr<IListT<String> > pSceneList(new (std::nothrow) ArrayListT<String>);
866 SysTryReturn(NID_UI_SCENES, pSceneList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.",
867 GetErrorMessage(E_OUT_OF_MEMORY));
869 pSceneList->AddItems(__sceneHistory);
870 return pSceneList.release();
874 _SceneManagerImpl::GetInstance(SceneManager& pSceneManager)
876 return pSceneManager.__pSceneManagerImpl;
879 const _SceneManagerImpl*
880 _SceneManagerImpl::GetInstance(const SceneManager& pSceneManager)
882 return pSceneManager.__pSceneManagerImpl;
885 // Event handelers to asynchronous destroy the Scene.
887 _SceneManagerImpl::OnFormTransitionAnimationFinished(FrameAnimator& source, Frame& frame, Form& form1, Form& form2)
889 SetInputEventEnableState(form1, true);
890 SetInputEventEnableState(form2, true);
892 source.RemoveFrameAnimatorEventListener(*this);
893 DestroyReservedScene();
897 _SceneManagerImpl::OnFormTransitionAnimationStarted(FrameAnimator& source, Frame& frame, Form& form1, Form& form2)
903 _SceneManagerImpl::OnFormTransitionAnimationStopped(FrameAnimator& source, Frame& frame, Form& form1, Form& form2)
905 SetInputEventEnableState(form1, true);
906 SetInputEventEnableState(form2, true);
908 source.RemoveFrameAnimatorEventListener(*this);
909 DestroyReservedScene();
913 _SceneManagerImpl::OnAnimationTransactionFinished(int transactionId)
917 SetInputEventEnableState(*__pDisabledForm, true);
918 __pDisabledForm = null;
920 AnimationTransaction::SetCurrentTransactionEventListener(null);
924 _SceneManagerImpl::OnAnimationTransactionStarted(int transactionId)
930 _SceneManagerImpl::OnAnimationTransactionStopped(int transactionId)
934 SetInputEventEnableState(*__pDisabledForm, true);
935 __pDisabledForm = null;
937 AnimationTransaction::SetCurrentTransactionEventListener(null);
941 _SceneManagerImpl::OnSceneControlEventReceived(_SceneControlEventArg::SceneControlEventType eventType, const SceneId& sceneId)
943 SysLog(NID_UI_SCENES, "Received type= 0x%x, sceneId=%ls", eventType, &sceneId);
947 case _SceneControlEventArg::SCENE_CONTROL_EVENT_TYPE_DESTROY:
948 DestroyScene(sceneId);
952 SysLog(NID_UI_SCENES, "Invalid SceneControlEventType x0%x", eventType);
957 // Internal operations
959 _SceneManagerImpl::GetScene(SceneId& sceneId)
961 return GetSceneFromContainer(sceneId);
965 _SceneManagerImpl::GetLiveSceneN(void) const
967 std::unique_ptr<ArrayListT<Scene*> > pSceneList(new (std::nothrow) ArrayListT<Scene*>);
968 SysTryReturn(NID_UI_SCENES, pSceneList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.",
969 GetErrorMessage(E_OUT_OF_MEMORY));
971 std::unique_ptr<IMapEnumeratorT<SceneId, Scene*> > pMapEnum(__sceneContainer.GetMapEnumeratorN());
972 SysTryReturn(NID_UI_SCENES, pMapEnum != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.",
973 GetErrorMessage(E_OUT_OF_MEMORY));
975 while (pMapEnum->MoveNext() == E_SUCCESS)
977 Scene* pScene = null;
978 pMapEnum->GetValue(pScene);
979 pSceneList->Add(pScene);
981 return pSceneList.release();
986 _SceneManagerImpl::GotoScene(bool forward, const SceneId& sceneId, SceneTransitionAnimationType animationType,
987 SceneHistoryOption historyOption, SceneDestroyOption destroyOption, const IList* pArgs)
989 // 1. Initialize for Scene transition.
990 result r = E_SUCCESS;
991 bool sceneAlreadyCreated = false;
992 bool formAlreadyCreated = false;
993 bool panelAlreadyCreated = false;
994 bool doAnimation = false;
995 bool formTransition = false;
996 Scene* pScene = null;
998 Panel* pPanel = null;
999 SceneId previousSceneId = __currentSceneId; // Save for later
1000 String previousFormId = (__pCurrentScene) ? __pCurrentScene->GetFormId() : L"";
1001 bool previousIsPanelScene = (__pCurrentScene) ? (__pCurrentScene->GetPanel()) : false;
1002 Frame* pFrame = null;
1003 FrameAnimator* pFrameAnimator = null;
1004 // Exception handling hintings
1005 bool onExceptionDeletepScene = false;
1006 bool onExceptionRemovesceneIdFromSceneContainer = false;
1007 bool onExceptionDeletepForm = false;
1008 bool onExceptionRemoveFormIdFromFormContainer = false;
1009 bool onExceptionRemovepPanel = false;
1011 // Prevent self forward
1012 SysTryCatch(NID_UI_SCENES, __currentSceneId != sceneId, r = E_INVALID_ARG, E_INVALID_ARG,
1013 "[%s] Invalid argument is used. Can't transit to current Scene.", GetErrorMessage(E_INVALID_ARG));
1014 CallListenerOnSceneTransitionStarted(__currentSceneId, sceneId); // Call listener - ISceneManagerEventListener's
1015 if (__pCurrentScene)
1016 { // Call listener - ISceneEventListener's
1017 CallListenerOnSceneDeactivated(*__pCurrentScene, __pCurrentScene->GetSceneId(), sceneId);
1020 // 2. Find the Scene on SceneContainer - Scene and correspond UI control has same life time.
1021 pScene = GetSceneFromContainer(sceneId);
1022 if (pScene) // Activate pScene: Scene already existing then Re-activate associated a Form and a Panel.
1024 sceneAlreadyCreated = true;
1025 pForm = GetFormFromContainer(pScene->GetFormId());
1026 SysTryCatch(NID_UI_SCENES, pForm == pScene->GetForm(), r = E_SYSTEM, E_SYSTEM,
1027 "[%s] A system error has been occurred. FormId mismatch with associated From instance.",
1028 GetErrorMessage(E_SYSTEM));
1029 formAlreadyCreated = true;
1030 pPanel = pScene->GetPanel();
1033 panelAlreadyCreated = true;
1037 { // 3. Scene not found- Create new Scene
1038 _SceneDescription* pSceneValue = null;
1039 __sceneMap.GetValue(sceneId, pSceneValue);
1040 SysTryCatch(NID_UI_SCENES, pSceneValue != null, r = E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND,
1041 "[%s] The given sceneId was not found in the registered scenes.", GetErrorMessage(E_OBJ_NOT_FOUND));
1042 // 4. Setup the new Scene
1043 pScene = _SceneImpl::CreateSceneN(sceneId, pSceneValue->formId, pSceneValue->panelId);
1044 SysTryCatch(NID_UI_SCENES, pScene != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
1045 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1046 onExceptionDeletepScene = true; // On the CATCH [delete pScene]
1047 _SceneImpl* pSceneImpl = _SceneImpl::GetInstance(*pScene);
1048 SysTryCatch(NID_UI_SCENES, pSceneImpl != null, r = E_SYSTEM, E_SYSTEM,
1049 "[%s] A system error has been occurred. pSceneImpl not valid", GetErrorMessage(E_SYSTEM));
1050 // 5. Register Scene
1051 AddSceneToContainer(sceneId, pScene);
1052 onExceptionRemovesceneIdFromSceneContainer = true; // On the CATCH [remove 'sceneId' from SceneContainer]
1053 // 6. Find the Form on FormContainer
1054 pForm = GetFormFromContainer(pScene->GetFormId());
1055 if (pForm) // Form existing: just call SetCurrentForm
1056 { // If the Scene is panel scene then add new panel to pForm or change showState.
1057 formAlreadyCreated = true;
1058 pSceneImpl->SetForm(pForm); // Panel Scene share same Form intance
1060 else// 7. Form not found- Create new Form
1061 { // 8. Get the new Form from the FormFactory
1062 SysTryCatch(NID_UI_SCENES, __pFormFactory != null, r = E_INVALID_STATE, E_INVALID_STATE,
1063 "[%s] SceneManager is in an invalid state. Form factory is not registered.",
1064 GetErrorMessage(E_INVALID_STATE));
1065 String formId(pScene->GetFormId());
1066 pForm = __pFormFactory->CreateFormN(formId, sceneId); // On the CATCH [delete pForm]
1067 SysTryCatch(NID_UI_SCENES, pForm != null, r = E_SYSTEM, E_SYSTEM,
1068 "[%s] A system error has been occurred. Form(Id=%ls) creation failed on form factroy.",
1069 GetErrorMessage(E_SYSTEM), formId.GetPointer());
1070 onExceptionDeletepForm = true; // On the CATCH [remove pForm from FormContainer]
1072 AddFormToContainer(pScene->GetFormId(), pForm);
1073 pSceneImpl->SetForm(pForm);
1074 onExceptionRemoveFormIdFromFormContainer = true;
1076 // 10. Create panel for Panel Scene
1077 // * One Panel instance for each Panel-Scene so no need to check duplicated panel instance for same panel Id.
1078 if (!pScene->GetPanelId().IsEmpty())
1080 String panelId(pScene->GetPanelId());
1081 // First of all, get the Panel from the based Form.
1082 // Because, base Form loaded from the resources, the child Panel also loaded and created.
1083 // So, do not create a new Panel instance but get from base Form with panelId as resource Id.
1084 pPanel = dynamic_cast<Panel*>(pForm->GetControl(panelId));
1087 pSceneImpl->SetPanelCreatedFromFormResource(true); // Prevent RemoveControl - It's not creatable via Panel factory.
1091 SysTryCatch(NID_UI_SCENES, __pPanelFactory != null, r = E_INVALID_STATE, E_INVALID_STATE,
1092 "[%s] SceneManager is in an invalid state. Panel factory is not registered.",
1093 GetErrorMessage(E_INVALID_STATE));
1094 pPanel = __pPanelFactory->CreatePanelN(panelId, sceneId); // On the CATCH [delete pPanel]
1095 SysTryCatch(NID_UI_SCENES, pPanel != null, r = E_SYSTEM, E_SYSTEM,
1096 "[%s] A system error has been occurred. Panel(Id=%ls) creation failed on PanelFactory.",
1097 GetErrorMessage(E_SYSTEM), panelId.GetPointer());
1098 onExceptionRemovepPanel = true; // On the CATCH [remove pPanel from __formToPanelMultiMap]
1100 AddPanelToPanelContainer(pScene);
1101 pSceneImpl->SetPanel(pPanel);
1105 // For animation logic should be divide Animator section and normal section for proper operations.
1106 // If (showAnimation && forwardAnimation is Not NONE) then doing animator related logic /
1107 // Setup default animation setting / Add listener to get animation stop/finishing
1108 formTransition = (previousFormId != pScene->GetFormId()) ? true : false;
1109 doAnimation = (animationType > SCENE_TRANSITION_ANIMATION_TYPE_NONE) ? true : false;
1110 if (doAnimation && (animationType != SCENE_TRANSITION_ANIMATION_TYPE_CUSTOM && !formTransition))
1112 doAnimation = false;
1114 if (doAnimation && (GetCurrentForm() == null))
1116 doAnimation = false;
1121 // Initialize Frame animator
1122 pFrame = GetFrame();
1123 SysTryCatch(NID_UI_SCENES, pFrame != null, r = E_SYSTEM, E_SYSTEM,
1124 "[%s] A system error has been occurred. Cannot get Frame.", GetErrorMessage(E_SYSTEM));
1125 pFrameAnimator = pFrame->GetFrameAnimator();
1126 SysTryCatch(NID_UI_SCENES, pFrameAnimator != null, r = E_SYSTEM, E_SYSTEM,
1127 "[%s] A system error has been occurred. Cannot get FrameAnimator.", GetErrorMessage(E_SYSTEM));
1128 pFrameAnimator->StopAllAnimations();
1130 // Initialize Control animator if needed.
1131 if (!formTransition && pPanel)
1133 ControlAnimator* pControlAnimator = pPanel->GetControlAnimator();
1134 SysTryCatch(NID_UI_SCENES, pControlAnimator != null, r = E_SYSTEM, E_SYSTEM,
1135 "[%s] A system error has been occurred. Cannot get ControlAnimator.", GetErrorMessage(E_SYSTEM));
1136 pControlAnimator->StopAllAnimations();
1139 // Set default value for formTransition
1140 if (formTransition && (animationType >= SCENE_TRANSITION_ANIMATION_TYPE_LEFT) &&
1141 (pFrameAnimator->GetStatus() == ANIMATOR_STATUS_STOPPED))
1143 pFrameAnimator->SetFormTransitionAnimation(
1144 __animationDescriptions[animationType-SCENE_TRANSITION_ANIMATION_TYPE_LEFT].animationType,
1145 __animationDescriptions[animationType-SCENE_TRANSITION_ANIMATION_TYPE_LEFT].duration,
1146 __animationDescriptions[animationType-SCENE_TRANSITION_ANIMATION_TYPE_LEFT].interpolatorType);
1150 { // Disable user input
1151 if (__pCurrentScene)
1153 r = SetInputEventEnableState(*__pCurrentScene->GetForm(), false);
1154 SysTryCatch(NID_UI_SCENES, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
1156 r = SetInputEventEnableState(*pForm, false);
1159 if (__pCurrentScene)
1161 SetInputEventEnableState(*__pCurrentScene->GetForm(), true);
1164 SysTryCatch(NID_UI_SCENES, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
1168 // Prepare animation for customization.
1169 CallListenerPrepareAnimation(*pScene, sceneId, const_cast<IList*>(pArgs), animationType, formTransition );
1170 // Setup Ui controls to show the result.
1171 if (sceneAlreadyCreated)
1177 SwitchToPanel(pScene->GetFormId(), pPanel);
1179 r = SetCurrentForm(*pForm, doAnimation); // FrameAnimator
1180 SysTryCatch(NID_UI_SCENES, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
1184 r = SetCurrentForm(*pForm);
1185 SysTryCatch(NID_UI_SCENES, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
1188 SwitchToPanel(pScene->GetFormId(), pPanel, doAnimation); // ControlAnimator
1192 else // Scene newly created
1194 if (formAlreadyCreated) // Panel scene created but base form already created - reuse base form.
1200 if (!panelAlreadyCreated) // If a new panel created then Add Panel to Form
1202 AddControlToForm(*pForm, *pPanel);
1204 SwitchToPanel(pScene->GetFormId(), pPanel);
1206 r = SetCurrentForm(*pForm, (doAnimation)); // FrameAnimator
1207 SysTryCatch(NID_UI_SCENES, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
1211 r = SetCurrentForm(*pForm);
1212 SysTryCatch(NID_UI_SCENES, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
1215 if (!panelAlreadyCreated)
1217 AddControlToForm(*pForm, *pPanel);
1219 SwitchToPanel(pScene->GetFormId(), pPanel, doAnimation); // ControlAnimator
1223 else // New Form created!
1228 AddControlToForm(*pForm, *pPanel);
1229 SwitchToPanel(pScene->GetFormId(), pPanel);
1231 AddControlToFrame(*pForm, doAnimation); // Form add to frame
1234 SetCurrentForm(*pForm);
1239 UpdateCurrentScene(pScene);
1240 if ((historyOption == SCENE_HISTORY_OPTION_ADD_HISTORY) && (!previousSceneId.IsEmpty()))
1242 r = AddHistory(previousSceneId);
1243 // Too late revert to previous scene, so just return the error code but not revert to previous state.
1244 SysTryLog(NID_UI_SCENES, !IsFailed(r), "[%s] History adding failed.", GetErrorMessage(r));
1247 CallListenerOnSceneActivatedN(*pScene, previousSceneId, sceneId, const_cast<IList*>(pArgs));
1248 CallListenerOnSceneTransitionCompleted(previousSceneId, __currentSceneId);
1250 if (destroyOption == SCENE_DESTROY_OPTION_DESTROY )
1252 if (previousIsPanelScene)
1254 DestroySiblingPanelScene(previousSceneId); // Destroy sibling Panel Scene
1258 ReserveDestroyingScene(previousSceneId); // Destroy the Scene after animator finished(stopped).
1262 DestroySceneAsync(previousSceneId);
1266 DrawForm(*pScene->GetForm());
1270 // Check all exception case for proper delete the instances: Scene, Form, Panel and item corresponding container.
1271 if (onExceptionRemovepPanel)
1273 RemovePanelFromPanelContainer(pScene);
1274 delete pPanel; // Also needed it.
1277 if (onExceptionRemoveFormIdFromFormContainer)
1279 RemoveFormFromFormContainer(pScene->GetFormId());
1281 if (onExceptionDeletepForm)
1286 if (onExceptionRemovesceneIdFromSceneContainer)
1288 RemoveSceneFromContainer(sceneId);
1290 if (onExceptionDeletepScene)
1300 _SceneManagerImpl::GetSceneFromContainer(const SceneId& sceneId) const
1302 Scene* pScene = null;
1303 __sceneContainer.GetValue(sceneId, pScene);
1308 _SceneManagerImpl::GetFormFromContainer(const String& formId)
1311 __formContainer.GetValue(formId, pForm);
1316 _SceneManagerImpl::AddSceneToContainer(const SceneId& sceneId, Scene* pScene)
1318 __sceneContainer.Add(sceneId, pScene);
1322 _SceneManagerImpl::RemoveSceneFromContainer(const SceneId& sceneId)
1324 __sceneContainer.Remove(sceneId);
1328 _SceneManagerImpl::AddFormToContainer(const String& formId, Form* pForm)
1330 __formContainer.Add(formId, pForm);
1334 _SceneManagerImpl::RemoveFormFromFormContainer(const String& formId)
1336 __formContainer.Remove(formId);
1340 _SceneManagerImpl::AddPanelToPanelContainer(Scene* pScene)
1342 __formToPanelMultiMap.Add(pScene->GetFormId(), pScene);
1346 _SceneManagerImpl::RemovePanelFromPanelContainer(Scene* pScene)
1348 __formToPanelMultiMap.Remove(pScene->GetFormId(), pScene);
1352 _SceneManagerImpl::UpdateCurrentScene(Scene* pScene)
1354 __pCurrentScene = pScene;
1355 __currentSceneId = pScene->GetSceneId();
1359 _SceneManagerImpl::AddHistory(const SceneId& sceneId)
1361 return __sceneHistory.Add(sceneId);
1365 _SceneManagerImpl::SwitchToPanel(const String& formId, Panel* pPanel, bool useAnimator)
1367 Panel* pShowPanel = null;
1368 Form* pBaseForm = null;
1371 pBaseForm = dynamic_cast<Form*>(pPanel->GetParent());
1372 if (pBaseForm == null)
1374 useAnimator = false;
1378 std::unique_ptr<IEnumeratorT<Scene*> > pSceneEnum(__formToPanelMultiMap.GetValuesN(formId));
1379 SysTryReturnVoidResult(NID_UI_SCENES, pSceneEnum != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.",
1380 GetErrorMessage(E_OUT_OF_MEMORY));
1381 while (pSceneEnum->MoveNext() == E_SUCCESS)
1383 Scene* pCurrentScene = null;
1384 pSceneEnum->GetCurrent(pCurrentScene);
1385 SysTryReturnVoidResult(NID_UI_SCENES, pCurrentScene != null, E_SYSTEM, "[%s] Memory allocation failed.",
1386 GetErrorMessage(E_OUT_OF_MEMORY));
1387 if (pCurrentScene->GetPanel() != pPanel)
1389 if (pCurrentScene->GetPanel()->GetShowState())
1391 pShowPanel = pCurrentScene->GetPanel();
1396 if (useAnimator && pShowPanel && pPanel)
1398 int transactionId = 0;
1399 AnimationTransaction::Begin(transactionId); // transactionId was set
1406 ControlAnimator* pControlAnimator = pShowPanel->GetControlAnimator();
1407 if (pControlAnimator)
1409 pControlAnimator->SetShowState(false);
1413 pShowPanel->SetShowState(false);
1418 pShowPanel->SetShowState(false);
1425 ControlAnimator* pControlAnimator = pPanel->GetControlAnimator();
1426 if (pControlAnimator)
1428 pControlAnimator->SetShowState(true);
1432 pPanel->SetShowState(true);
1437 pPanel->SetShowState(true);
1441 if (useAnimator && pShowPanel && pPanel)
1443 // Set event listener & start animations
1444 AnimationTransaction::SetCurrentTransactionEventListener(this);
1445 result r = AnimationTransaction::Commit();
1448 // Disable input for base Form
1451 __pDisabledForm = pBaseForm;
1452 SetInputEventEnableState(*pBaseForm, false);
1457 SysLog(NID_UI_SCENES, "Animation Commit() failed");
1463 _SceneManagerImpl::AddControlToFrame(Form& form, bool useAnimator)
1465 Frame* pFrame = GetFrame();
1470 FrameAnimator* pFrameAnimator = pFrame->GetFrameAnimator();
1473 // Add animator listener to asynchronous scene destroy for safe deletion.
1474 pFrameAnimator->AddFrameAnimatorEventListener(*this);
1475 _FrameAnimatorImpl* pFrameAnimatorImpl = _FrameAnimatorImpl::GetInstance(*pFrameAnimator);
1476 if (pFrameAnimatorImpl)
1478 pFrameAnimatorImpl->AddControl(form);
1482 SysLog(NID_UI_SCENES, "pFrameAnimator or pFrameAnimatorImpl is not valid.");
1484 pFrame->AddControl(form);
1489 _SceneManagerImpl::RemoveControlFromFrame(Form& form)
1491 Frame* pFrame = GetFrame();
1494 // Control validation check for safe operation on termination(Ui destroy before asynchronous scene destroy process).
1495 _ControlManager* pControlManager = _ControlManager::GetInstance();
1496 if (pControlManager)
1498 _Control* pControl = pControlManager->GetObject(__correspondFrameControlHandle);
1501 pFrame->RemoveControl(form);
1506 SysLog(NID_UI_SCENES, "FrameWindow already destroyed. Skip remove control to form.");
1511 SysLog(NID_UI_SCENES, "Window system already shutdown.");
1517 _SceneManagerImpl::SetCurrentForm(Form& form, bool useAnimator)
1519 result r = E_SUCCESS;
1520 Frame* pFrame = GetFrame();
1522 SysTryReturnResult(NID_UI_SCENES, pFrame != null, E_SYSTEM,
1523 "A system error has been occurred. Can not get the Frame window.");
1526 FrameAnimator* pFrameAnimator = pFrame->GetFrameAnimator();
1529 // Add animator listener to asynchronous scene destroy for safe deletion.
1530 pFrameAnimator->AddFrameAnimatorEventListener(*this);
1531 r = pFrameAnimator->SetCurrentForm(form);
1537 SysLog(NID_UI_SCENES, "Safety operation ongoing. Animation may not working, Please check the problems!");
1540 r = pFrame->SetCurrentForm(form);
1541 SysTryReturnResult(NID_UI_SCENES, !IsFailed(r), E_SYSTEM, "A system error has been occurred. Can not set current form.");
1546 _SceneManagerImpl::GetCurrentForm(void)
1548 Frame* pFrame = GetFrame();
1551 return pFrame->GetCurrentForm();
1557 _SceneManagerImpl::AddControlToForm(Form& baseForm, const Panel& panel)
1559 baseForm.AddControl(panel);
1563 _SceneManagerImpl::RemoveControlFromForm(Form& baseForm, const Panel& panel)
1565 baseForm.RemoveControl(panel);
1569 _SceneManagerImpl::SetShowState(Panel& targetPanel, bool state)
1571 targetPanel.SetShowState(state);
1575 _SceneManagerImpl::DrawForm(Form& form)
1577 form.Invalidate(true);
1581 _SceneManagerImpl::CallListenerOnSceneTransitionStarted(const SceneId& currentSceneId, const SceneId& nextSceneId)
1583 std::unique_ptr<IEnumeratorT<ISceneManagerEventListener*> > pEnum(__sceneManagerEventListenerList.GetEnumeratorN());
1589 while (pEnum->MoveNext() == E_SUCCESS)
1591 ISceneManagerEventListener* pListener = null;
1592 pEnum->GetCurrent(pListener);
1595 pListener->OnSceneTransitionStarted(currentSceneId, nextSceneId);
1602 _SceneManagerImpl::CallListenerOnSceneTransitionCompleted(const SceneId& previousSceneId, const SceneId& currentSceneId)
1604 std::unique_ptr<IEnumeratorT<ISceneManagerEventListener*> > pEnum(__sceneManagerEventListenerList.GetEnumeratorN());
1610 while (pEnum->MoveNext() == E_SUCCESS)
1612 ISceneManagerEventListener* pListener = null;
1613 pEnum->GetCurrent(pListener);
1616 pListener->OnSceneTransitionCompleted(previousSceneId, currentSceneId);
1623 _SceneManagerImpl::CallListenerPrepareAnimation(Scene& scene, const SceneId& sceneId, IList* pArgs,
1624 SceneTransitionAnimationType type, bool formTransition)
1626 _SceneImpl* pSceneImpl = _SceneImpl::GetInstance(scene);
1627 SysTryReturn(NID_UI_SCENES, pSceneImpl, false, E_INVALID_STATE,
1628 "[%s] SceneManager is in an invalid state. scene is not valid.",
1629 GetErrorMessage(E_INVALID_STATE));
1631 return pSceneImpl->PrepareAnimation(sceneId, pArgs, type, formTransition);
1635 _SceneManagerImpl::CallListenerOnSceneActivatedN(Scene& scene, const SceneId& previousSceneId, const SceneId& currentSceneId,
1638 _SceneImpl* pSceneImpl = _SceneImpl::GetInstance(scene);
1639 SysTryReturn(NID_UI_SCENES, pSceneImpl, false, E_INVALID_STATE,
1640 "[%s] SceneManager is in an invalid state. scene is not valid.",
1641 GetErrorMessage(E_INVALID_STATE));
1643 return pSceneImpl->OnSceneActivatedN(previousSceneId, currentSceneId, pArgs);
1647 _SceneManagerImpl::CallListenerOnSceneDeactivated(Scene& scene, const SceneId& currentSceneId, const SceneId& nextSceneId)
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));
1654 return pSceneImpl->OnSceneDeactivated(currentSceneId, nextSceneId);
1658 _SceneManagerImpl::CallStretegyGetNextScene(const SceneId& currentSceneId, const IList* pArgs)
1660 SceneId nextScene(L"");
1661 if (__pPolicyProvider)
1663 nextScene = __pPolicyProvider->GetNextScene(currentSceneId, pArgs);
1669 _SceneManagerImpl::DestroySceneAsync(const SceneId& sceneId)
1671 _SceneControlEventArg* pArg = new (std::nothrow) _SceneControlEventArg(
1672 _SceneControlEventArg::SCENE_CONTROL_EVENT_TYPE_DESTROY, sceneId);
1673 SysTryReturnVoidResult(NID_UI_SCENES, pArg != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.",
1674 GetErrorMessage(E_OUT_OF_MEMORY));
1675 __sceneControlEvent.FireAsync(*pArg);
1679 _SceneManagerImpl::ReserveDestroyingScene(const SceneId& sceneId)
1681 if (!__destroyReservedScene.IsEmpty())
1683 SysLog(NID_UI_SCENES, "Previous reserved sceneId=%ls", __destroyReservedScene.GetPointer());
1685 __destroyReservedScene = sceneId;
1689 _SceneManagerImpl::DestroyReservedScene(void)
1691 if (!__destroyReservedScene.IsEmpty())
1693 DestroySceneAsync(__destroyReservedScene);
1694 __destroyReservedScene.Clear();
1699 _SceneManagerImpl::DestroySiblingPanelScene(const SceneId& sceneId)
1701 Scene* pScene = null;
1702 pScene = GetSceneFromContainer(sceneId);
1703 SysTryReturnVoidResult(NID_UI_SCENES, pScene != null, E_OBJ_NOT_FOUND, "[%s] Specified sceneId does not exist.",
1704 GetErrorMessage(E_OBJ_NOT_FOUND));
1706 Panel* pPanel = pScene->GetPanel();
1710 result r = __formToPanelMultiMap.GetCount(pScene->GetFormId(), panelCount);
1711 SysTryReturnVoidResult(NID_UI_SCENES, !IsFailed(r), E_SYSTEM,
1712 "[%s] A system error has been occurred. Form(SceneId:%ls) not valid.",
1713 GetErrorMessage(E_SYSTEM), sceneId.GetPointer());
1714 if (panelCount <= 1)
1719 ArrayListT<Scene*> destroyList;
1720 std::unique_ptr<IEnumeratorT<Scene*> > pSceneEnum(__formToPanelMultiMap.GetValuesN(pScene->GetFormId()));
1721 SysTryReturnVoidResult(NID_UI_SCENES, pSceneEnum != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.",
1722 GetErrorMessage(E_OUT_OF_MEMORY));
1723 while (pSceneEnum->MoveNext() == E_SUCCESS)
1725 Scene* pCurrentScene = null;
1726 pSceneEnum->GetCurrent(pCurrentScene);
1727 SysTryReturnVoidResult(NID_UI_SCENES, pCurrentScene != null, E_SYSTEM,
1728 "[%s] A system error has been occurred. Current scene is not valid.",
1729 GetErrorMessage(E_SYSTEM));
1730 if (pCurrentScene->GetPanel() != pPanel)
1732 destroyList.Add(pCurrentScene); // DestroyScene modify __formToPanelMultiMap so can't destroy here.
1736 for (int i = 0; i < destroyList.GetCount(); i++)
1738 Scene* pCurrentScene = null;
1739 destroyList.GetAt(i, pCurrentScene);
1742 DestroyScene(pCurrentScene->GetSceneId());
1749 _SceneManagerImpl::GetFrame(void)
1751 if (__pCorrespondFrame == null)
1753 SysLog(NID_UI_SCENES, "WARNING! - Initialize error!. First GetInstance must call after set a FrameWindow.");
1754 UiApp* pUiApp = UiApp::GetInstance();
1755 SysTryReturn(NID_UI_SCENES, pUiApp != null, null, E_SYSTEM,
1756 "[%s] A system error has been occurred. UiApp::GetInstance failed.", GetErrorMessage(E_SYSTEM));
1757 Frame* pFrame = pUiApp->GetFrameAt(0);
1758 SysTryReturn(NID_UI_SCENES, pFrame != null, null, E_SYSTEM,
1759 "[%s] A system error has been occurred. pUiApp->GetFrameAt(0) return null.", GetErrorMessage(E_SYSTEM));
1760 __pCorrespondFrame = pFrame;
1761 _ContainerImpl* pFrameWindowImpl = _ContainerImpl::GetInstance(*__pCorrespondFrame);
1762 if (pFrameWindowImpl)
1764 __correspondFrameControlHandle = pFrameWindowImpl->GetCore().GetHandle();
1767 return __pCorrespondFrame;
1771 _SceneManagerImpl::IsAnimationCompleted(void)
1773 Frame* pFrame = GetFrame();
1774 SysTryReturn(NID_UI_SCENES, pFrame != null, true, E_SYSTEM, "[%s] A system error has been occurred. Cannot get Frame.",
1775 GetErrorMessage(E_SYSTEM));
1776 FrameAnimator* pFrameAnimator = pFrame->GetFrameAnimator();
1780 bool completed = (pFrameAnimator->GetStatus() == ANIMATOR_STATUS_STOPPED) ? true : false;
1787 _SceneManagerImpl::SetInputEventEnableState(Tizen::Ui::Control& control, bool enableState)
1789 _ControlImpl* pControlImpl = _ControlImpl::GetInstance(control);
1790 SysTryReturnResult(NID_UI_SCENES, pControlImpl != null, E_SYSTEM, "A system error has been occurred. Cannot get _ControlImpl.");
1791 _Control& controlCore = pControlImpl->GetCore();
1793 if (enableState == false)
1795 controlCore.LockInputEvent();
1799 controlCore.UnlockInputEvent();
1805 _SceneManagerImpl::GetSceneTransition(const SceneTransitionId& transitionId, SceneTransition& sceneTransition) const
1807 result r = E_SUCCESS;
1808 SysTryReturnResult(NID_UI_SCENES, !transitionId.IsEmpty(), E_INVALID_ARG,
1809 "Invalid argument is used. The transitionId is empty.");
1811 SceneTransition* pSceneTransition = null;
1812 r = __transitionMap.GetValue(transitionId, pSceneTransition);
1813 SysTryReturn(NID_UI_SCENES, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
1814 sceneTransition = *pSceneTransition;
1820 _SceneManagerImpl::RegisterScene(xmlNodePtr pNode)
1822 static const char* pPropId = "Id";
1823 static const char* pPropFormId = "Form";
1824 static const char* pPropPanelId = "Panel";
1825 result r = E_SUCCESS;
1826 _SceneDescription* pSceneDescription = null;
1828 SysTryReturn(NID_UI_SCENES, pNode != null, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. pNode is null.",
1829 GetErrorMessage(E_INVALID_ARG));
1831 xmlChar* pSceneId = xmlGetProp(pNode, reinterpret_cast<const xmlChar*>(pPropId));
1834 String strSceneId(reinterpret_cast<char*>(pSceneId));
1837 xmlChar* pFormId = xmlGetProp(pNode, reinterpret_cast<const xmlChar*>(pPropFormId));
1840 String strFormId(reinterpret_cast<char*>(pFormId));
1844 xmlChar* pPanelId = xmlGetProp(pNode, reinterpret_cast<const xmlChar*>(pPropPanelId));
1847 strPanelId = reinterpret_cast<char*>(pPanelId);
1851 // Register a Scene item
1852 bool isContains = false;
1853 r = __sceneMap.ContainsKey(strSceneId, isContains);
1854 SysTryReturn(NID_UI_SCENES, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
1855 SysTryReturnResult(NID_UI_SCENES, !isContains, E_OBJ_ALREADY_EXIST, "Specified sceneId already exist.");
1857 pSceneDescription = new (std::nothrow) _SceneDescription(strFormId, strPanelId);
1858 SysTryReturnResult(NID_UI_SCENES, pSceneDescription != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
1860 r = __sceneMap.Add(strSceneId, pSceneDescription);
1861 SysTryCatch(NID_UI_SCENES, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
1867 delete pSceneDescription;
1872 _SceneManagerImpl::RegisterSceneTransition(xmlNodePtr pNode)
1874 static const xmlChar* pPropId = reinterpret_cast<const xmlChar*>("Id");
1875 static const char* pPropDestinationSceneId = "TargetId";
1876 static const char* pPropDirectionType = "DirectionType";
1877 static const char* pPropAnimationType = "AnimationType";
1878 static const char* pPropHistoryOption = "HistoryOption";
1879 static const char* pPropDestroyOption = "DestroyOption";
1881 static const String strValueDirectionForward(L"forward");
1882 static const String strValueDirectionBackward(L"backward");
1883 static const String strValueDirectionAdjacentBackward(L"adjacentBackward");
1884 static const String strValueAnimationType[] = {L"none", L"custom", L"left", L"right", L"fade_in_out",
1885 L"zoom_in", L"zoom_out", L"depth_in", "depth_out"};
1886 static const String strValueHistoryOptionNoHistory(L"no");
1887 static const String strValueDestroyOptionKeep(L"keep");
1888 static const String strValueDestroyOptionDestroy(L"destroy");
1890 static const SceneTransitionAnimationType valueAnimation[] = {
1891 SCENE_TRANSITION_ANIMATION_TYPE_NONE, SCENE_TRANSITION_ANIMATION_TYPE_CUSTOM,
1892 SCENE_TRANSITION_ANIMATION_TYPE_LEFT, SCENE_TRANSITION_ANIMATION_TYPE_RIGHT,
1893 SCENE_TRANSITION_ANIMATION_TYPE_FADE_IN_OUT, SCENE_TRANSITION_ANIMATION_TYPE_ZOOM_IN,
1894 SCENE_TRANSITION_ANIMATION_TYPE_ZOOM_OUT, SCENE_TRANSITION_ANIMATION_TYPE_DEPTH_IN,
1895 SCENE_TRANSITION_ANIMATION_TYPE_DEPTH_OUT };
1897 SceneTransition* pSceneTransition = null;
1898 result r = E_SUCCESS;
1899 SysTryReturn(NID_UI_SCENES, pNode != null, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. pNode is null.",
1900 GetErrorMessage(E_INVALID_ARG));
1902 xmlChar* pTransitionId = xmlGetProp(pNode, pPropId);
1905 String strTransitionId(reinterpret_cast<char*>(pTransitionId));
1906 xmlFree(pTransitionId);
1907 if (strTransitionId.GetLength() > 0)
1909 xmlChar* pDirectionType = xmlGetProp(pNode, reinterpret_cast<const xmlChar*>(pPropDirectionType));
1912 String strDirectionType(reinterpret_cast<char*>(pDirectionType));
1913 xmlFree(pDirectionType);
1915 // Mandatory item: transitionId, direction
1916 // forward: destinationSceneId(mandatory), animationType, historyOption, destroyOption
1917 // backward: destinationSceneId(mandatory), animationType, destroyOption [ Don't care: historyOption ]
1918 // adjacentBackward: animationType, destroyOption [ Don't care: destinationSceneId, historyOption]
1919 String strDestinationSceneId;
1920 String strAnimationType;
1921 String strHistoryOption;
1922 String strDestroyOption;
1923 SceneTransitionAnimationType animationType = SCENE_TRANSITION_ANIMATION_TYPE_NONE;
1925 // Get animationType and destroyOption (common property)
1926 xmlChar* pAnimationType = xmlGetProp(pNode, reinterpret_cast<const xmlChar*>(pPropAnimationType));
1929 strAnimationType = reinterpret_cast<char*>(pAnimationType);
1930 xmlFree(pAnimationType);
1931 if (strAnimationType.GetLength() > 0)
1933 for (unsigned int i = 0; i < sizeof(valueAnimation)/sizeof(valueAnimation[0]); i++)
1934 { // Consider to use map collection.
1935 if (strAnimationType == strValueAnimationType[i])
1937 animationType = valueAnimation[i];
1944 xmlChar* pDestroyOption = xmlGetProp(pNode, reinterpret_cast<const xmlChar*>(pPropDestroyOption));
1947 strDestroyOption = reinterpret_cast<char*>(pDestroyOption);
1948 xmlFree(pDestroyOption);
1951 // Compose SceneTransition
1952 if (strDirectionType == strValueDirectionAdjacentBackward) // Adjacent backward
1954 SceneDestroyOption destroyOption = SCENE_DESTROY_OPTION_DESTROY; // Default is destroy
1955 if ((strDestroyOption.GetLength() > 0) && (strDestroyOption == strValueDestroyOptionKeep))
1957 destroyOption = SCENE_DESTROY_OPTION_KEEP;
1960 pSceneTransition = new (std::nothrow) BackwardSceneTransition(animationType, destroyOption);
1961 SysTryReturnResult(NID_UI_SCENES, pSceneTransition != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
1962 r = __transitionMap.Add(strTransitionId, pSceneTransition);
1963 SysTryCatch(NID_UI_SCENES, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
1967 // Get destinationSceneId
1968 xmlChar* pDestinationSceneId = xmlGetProp(pNode, reinterpret_cast<const xmlChar*>(pPropDestinationSceneId));
1969 if (pDestinationSceneId)
1971 strDestinationSceneId = reinterpret_cast<char*>(pDestinationSceneId);
1972 xmlFree(pDestinationSceneId);
1974 SysTryReturn(NID_UI_SCENES, strDestinationSceneId.GetLength() > 0, E_INVALID_ARG, E_INVALID_ARG,
1975 "[%s] Invalid argument is used. strDestinationSceneId is empty.", GetErrorMessage(E_INVALID_ARG));
1977 if (strDirectionType == strValueDirectionBackward) // Backward
1979 SceneDestroyOption destroyOption = SCENE_DESTROY_OPTION_DESTROY; // Default is destroy
1980 if ((strDestroyOption.GetLength() > 0) && (strDestroyOption == strValueDestroyOptionKeep))
1982 destroyOption = SCENE_DESTROY_OPTION_KEEP;
1986 new (std::nothrow) BackwardSceneTransition(strDestinationSceneId, animationType, destroyOption);
1987 SysTryReturnResult(NID_UI_SCENES, pSceneTransition != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
1988 r = __transitionMap.Add(strTransitionId, pSceneTransition);
1989 SysTryCatch(NID_UI_SCENES, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
1993 if (strDirectionType == strValueDirectionForward) // Forward
1995 SceneDestroyOption destroyOption = SCENE_DESTROY_OPTION_KEEP; // Default is keep
1996 if ((strDestroyOption.GetLength() > 0) && (strDestroyOption == strValueDestroyOptionDestroy))
1998 destroyOption = SCENE_DESTROY_OPTION_DESTROY;
2001 xmlChar* pHistoryOption = xmlGetProp(pNode, reinterpret_cast<const xmlChar*>(pPropHistoryOption));
2004 strHistoryOption = reinterpret_cast<char*>(pHistoryOption);
2005 xmlFree(pHistoryOption);
2007 SceneHistoryOption historyOption = SCENE_HISTORY_OPTION_ADD_HISTORY; // Default is add to history
2008 if ((strHistoryOption.GetLength() > 0) && (strHistoryOption == strValueHistoryOptionNoHistory))
2010 historyOption = SCENE_HISTORY_OPTION_NO_HISTORY;
2013 pSceneTransition = new (std::nothrow) ForwardSceneTransition(strDestinationSceneId, animationType,
2014 historyOption, destroyOption);
2015 SysTryReturnResult(NID_UI_SCENES, pSceneTransition != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
2016 r = __transitionMap.Add(strTransitionId, pSceneTransition);
2017 SysTryCatch(NID_UI_SCENES, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
2022 SysLog(NID_UI_SCENES, "Unknown direction type!");
2030 delete pSceneTransition;
2035 _SceneManagerImpl::StopAllAnimations(void)
2037 Frame* pFrame = GetFrame();
2038 SysTryReturnResult(NID_UI_SCENES, pFrame != null, E_SYSTEM, "A system error has been occurred. Cannot get Frame.");
2039 FrameAnimator* pFrameAnimator = pFrame->GetFrameAnimator();
2040 SysTryReturnResult(NID_UI_SCENES, pFrameAnimator != null, E_SYSTEM, "A system error has been occurred. Cannot get FrameAnimator.");
2041 pFrameAnimator->StopAllAnimations();
2042 if (!__destroyReservedScene.IsEmpty())
2044 DestroyScene(__destroyReservedScene);
2045 __destroyReservedScene.Clear();
2050 } } } // Tizen::Ui::Scenes