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();
205 Frame* pFrame = pUiApp->GetFrameAt(0);
208 __pCorrespondFrame = pFrame;
209 _ContainerImpl* pFrameWindowImpl = _ContainerImpl::GetInstance(*__pCorrespondFrame);
210 if (pFrameWindowImpl)
212 __correspondFrameControlHandle = pFrameWindowImpl->GetCore().GetHandle();
216 SysLog(NID_UI_SCENES, "WARNING! - Invalid Frame window. [_ContainerImpl::GetInstance failed]");
221 SysLog(NID_UI_SCENES, "WARNING! - Please add a Frame window before use the SceneManager. [pUiApp->GetFrameAt(0) return null]");
226 SysLog(NID_UI_SCENES, "WARNING! - Please check the application type. SceneManager is valid only Ui-Application. [UiApp::GetInstance failed]");
233 _SceneManagerImpl::RegisterFormFactory(const IFormFactory& formFactory)
235 __pFormFactory = const_cast <IFormFactory*>(&formFactory);
241 _SceneManagerImpl::RegisterPanelFactory(const IPanelFactory& panelFactory)
243 __pPanelFactory = const_cast <IPanelFactory*>(&panelFactory);
249 _SceneManagerImpl::RegisterScene(const SceneId& sceneId, const String& formId, const String& panelId)
251 result r = E_SUCCESS;
252 _SceneDescription* pSceneDescription = null;
253 bool isContains = false;
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());
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.");
263 __formIdMap.ContainsKey(formId, isContains);
264 if (panelId.IsEmpty())
266 SysTryReturnResult(NID_UI_SCENES, !isContains, E_INVALID_ARG, "Specified formId already exist. Only 'PanelScene' can share a formId for use as base form.");
271 __formIdMap.Add(formId, 1);
276 __formIdMap.GetValue(formId, refCount);
278 __formIdMap.SetValue(formId, refCount);
281 pSceneDescription = new (std::nothrow) _SceneDescription(formId, panelId);
282 SysTryReturnResult(NID_UI_SCENES, pSceneDescription != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
284 r = __sceneMap.Add(sceneId, pSceneDescription);
285 SysTryCatch(NID_UI_SCENES, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
289 delete pSceneDescription;
294 _SceneManagerImpl::RegisterScene(const String& resourceId)
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;
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();
309 const String appRootPath = Tizen::App::App::GetInstance()->GetAppRootPath();
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());
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))
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;
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.");
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());
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.");
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)
355 result regResult = RegisterScene(childNodePtr);
356 if (IsFailed(regResult))
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)
367 if (xmlStrcmp(childNodePtr->name, pElementSceneTransition) == 0)
369 result regResult = RegisterSceneTransition(childNodePtr);
370 if (IsFailed(regResult))
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)
380 } // 'Scene' and 'SceneTransition'
381 } // Children of 'Workflow'
382 } // Element 'Workflow'
383 }// Root node sibling
394 _SceneManagerImpl::UnregisterScene(const SceneId& sceneId)
396 result r = E_SUCCESS;
397 _SceneDescription* pSceneDescription = null;
399 SysTryReturnResult(NID_UI_SCENES, !sceneId.IsEmpty(), E_INVALID_ARG, "Invalid argument is used. sceneId is empty.");
401 r = __sceneMap.GetValue(sceneId, pSceneDescription);
402 SysTryReturn(NID_UI_SCENES, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
404 // Remove FormId from __formIdMap
405 if (pSceneDescription)
407 bool isContains = false;
408 __formIdMap.ContainsKey(pSceneDescription->formId, isContains);
412 __formIdMap.GetValue(pSceneDescription->formId, refCount);
416 __formIdMap.Remove(pSceneDescription->formId);
420 __formIdMap.SetValue(pSceneDescription->formId, refCount);
425 r = __sceneMap.Remove(sceneId);
426 SysTryReturn(NID_UI_SCENES, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
428 delete pSceneDescription;
433 _SceneManagerImpl::AddSceneManagerEventListener(ISceneManagerEventListener& sceneManagerEventListener)
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));
446 _SceneManagerImpl::RemoveSceneManagerEventListener(ISceneManagerEventListener& sceneManagerEventListener)
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));
457 _SceneManagerImpl::AddSceneEventListener(const SceneId& sceneId, ISceneEventListener& sceneEventListener)
459 result r = E_SUCCESS;
460 Scene* pScene = null;
461 _SceneImpl* pSceneImpl = null;
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));
474 _SceneManagerImpl::RemoveSceneEventListener(const SceneId& sceneId, ISceneEventListener& sceneEventListener)
476 result r = E_SUCCESS;
477 Scene* pScene = null;
478 _SceneImpl* pSceneImpl = null;
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));
491 _SceneManagerImpl::SetSceneAnimationProvider(const SceneId& sceneId, ISceneAnimationProvider* pSceneAnimationProvider)
493 result r = E_SUCCESS;
494 Scene* pScene = null;
495 _SceneImpl* pSceneImpl = null;
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));
508 _SceneManagerImpl::SetSceneTransitionPolicyProvider(ISceneTransitionPolicyProvider* pSceneTransitionPolicyProvider)
510 __pPolicyProvider = pSceneTransitionPolicyProvider;
516 _SceneManagerImpl::SetFormTransitionAnimationDefaultValues(SceneTransitionAnimationType animationType, long duration,
517 AnimationInterpolatorType interpolatorType)
519 static const long DURATION_MIN = 0;
520 static const long DURATION_MAX = 1000;
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;
534 _SceneManagerImpl::GoForward(const ForwardSceneTransition& sceneTransition, const Tizen::Base::Collection::IList* pArgs)
536 //## Temporary - Currently no support Non-Recursive Lock(Mutex).
537 SysTryReturnResult(NID_UI_SCENES, !__sceneTransitionProgressing, E_IN_PROGRESS, "Previous operation in progressing");
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
547 _SceneTransitionImpl forwardSceneTransition;
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));
553 sceneId = forwardSceneTransition.GetDestinationSceneId();
554 if (sceneId.GetLength() > 0)
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));
561 if (!IsAnimationCompleted())
563 r = StopAllAnimations();
564 SysTryCatch(NID_UI_SCENES, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
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));
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));
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());
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));
587 if (!IsAnimationCompleted())
589 r = StopAllAnimations();
590 SysTryCatch(NID_UI_SCENES, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
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));
601 __sceneTransitionProgressing = false; //## Temporary
602 SysTryReturnResult(NID_UI_SCENES, !IsFailed(__sceneTransitionMutex.Release()), E_SYSTEM,
603 "A system error has been occurred. Mutext release failed.");
608 _SceneManagerImpl::GoForward(const SceneTransitionId& transitionId, const Tizen::Base::Collection::IList* pArgs)
610 ForwardSceneTransition forwardTransition;
612 result r = GetSceneTransition(transitionId, forwardTransition);
613 SysTryReturnResult(NID_UI_SCENES, !IsFailed(r), E_INVALID_ARG, "Cannot get transition from Id.");
615 return GoForward(forwardTransition, pArgs);
619 _SceneManagerImpl::GoBackward(const BackwardSceneTransition& sceneTransition, const Tizen::Base::Collection::IList* pArgs)
621 //## Temporary - Currently no support Non-Recursive Lock(Mutex).
622 SysTryReturnResult(NID_UI_SCENES, !__sceneTransitionProgressing, E_IN_PROGRESS, "Previous operation in progressing");
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
631 int historyCount = 0;
632 _SceneTransitionImpl backwardSceneTransition;
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));
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));
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;
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));
661 // Stop previous animation
662 if (!IsAnimationCompleted())
664 r = StopAllAnimations();
665 SysTryCatch(NID_UI_SCENES, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
668 // 2. if destoryOption == SCENE_DESTROY_OPTION_DESTROY then destroy all scenes except matching scene.
669 if (backwardSceneTransition.GetDestroyOption() == SCENE_DESTROY_OPTION_DESTROY)
671 for (int i = historyIndex+1; i < historyCount; i++)
673 SceneId destroyTargetSceneId;
674 __sceneHistory.GetAt(i, destroyTargetSceneId);
675 // Scene instance is not always valid.
676 Scene* pScene = GetSceneFromContainer(destroyTargetSceneId);
679 // If Panel Scene then destroy sibling Panel Scene(s).
680 if (pScene->GetPanel())
682 DestroySiblingPanelScene(destroyTargetSceneId);
684 DestroyScene(destroyTargetSceneId);
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));
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));
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));
704 { // Adjacent backward transition
705 SceneId previousSceneId;
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));
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));
718 // Stop previous animation
719 if (!IsAnimationCompleted())
721 r = StopAllAnimations();
722 SysTryCatch(NID_UI_SCENES, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
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));
733 __sceneTransitionProgressing = false; //## Temporary
734 SysTryReturnResult(NID_UI_SCENES, !IsFailed(__sceneTransitionMutex.Release()), E_SYSTEM,
735 "A system error has been occurred. Mutext release failed.");
740 _SceneManagerImpl::GoBackward(const SceneTransitionId& transitionId, const Tizen::Base::Collection::IList* pArgs)
742 BackwardSceneTransition backwardTransition;
744 result r = GetSceneTransition(transitionId, backwardTransition);
745 SysTryReturnResult(NID_UI_SCENES, !IsFailed(r), E_INVALID_ARG, "Cannot get transition from Id.");
747 return GoBackward(backwardTransition, pArgs);
751 _SceneManagerImpl::GetCurrentScene(void) const
753 return __pCurrentScene;
757 _SceneManagerImpl::GetCurrentSceneId(void) const
759 return __currentSceneId;
763 _SceneManagerImpl::IsSceneAlive(const SceneId& sceneId) const
765 return (GetSceneFromContainer(sceneId)) ? true : false;
769 _SceneManagerImpl::DestroyScene(const SceneId& sceneId)
771 result r = E_SUCCESS;
772 Scene* pScene = null;
773 bool isFormScene = false;
774 bool isLastPanel = false;
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.");
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())
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());
802 RemoveSceneFromContainer(sceneId);
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());
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());
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);
827 panelFromFormResouce = pSceneImpl->IsPanelCreatedFromFormResource();
829 if (!panelFromFormResouce)
831 RemoveControlFromForm(*pScene->GetForm(), *pScene->GetPanel());
840 _SceneManagerImpl::BringCurrentSceneToTop(void)
843 Scene* pCurrentScene = GetCurrentScene();
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.");
855 _SceneManagerImpl::ClearSceneHistory(void)
857 __sceneHistory.RemoveAll();
863 _SceneManagerImpl::AddToSceneHistory(const SceneId& sceneId)
865 result r = E_SUCCESS;
866 bool isContains = false;
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));
878 _SceneManagerImpl::GetSceneHistoryN(void) const
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));
884 pSceneList->AddItems(__sceneHistory);
885 return pSceneList.release();
889 _SceneManagerImpl::GetInstance(SceneManager& pSceneManager)
891 return pSceneManager.__pSceneManagerImpl;
894 const _SceneManagerImpl*
895 _SceneManagerImpl::GetInstance(const SceneManager& pSceneManager)
897 return pSceneManager.__pSceneManagerImpl;
900 // Event handelers to asynchronous destroy the Scene.
902 _SceneManagerImpl::OnFormTransitionAnimationFinished(FrameAnimator& source, Frame& frame, Form& form1, Form& form2)
904 SetInputEventEnableState(form1, true);
905 SetInputEventEnableState(form2, true);
907 source.RemoveFrameAnimatorEventListener(*this);
908 DestroyReservedScene();
912 _SceneManagerImpl::OnFormTransitionAnimationStarted(FrameAnimator& source, Frame& frame, Form& form1, Form& form2)
918 _SceneManagerImpl::OnFormTransitionAnimationStopped(FrameAnimator& source, Frame& frame, Form& form1, Form& form2)
920 SetInputEventEnableState(form1, true);
921 SetInputEventEnableState(form2, true);
923 source.RemoveFrameAnimatorEventListener(*this);
924 DestroyReservedScene();
928 _SceneManagerImpl::OnAnimationTransactionFinished(int transactionId)
932 SetInputEventEnableState(*__pDisabledForm, true);
933 __pDisabledForm = null;
935 AnimationTransaction::SetCurrentTransactionEventListener(null);
939 _SceneManagerImpl::OnAnimationTransactionStarted(int transactionId)
945 _SceneManagerImpl::OnAnimationTransactionStopped(int transactionId)
949 SetInputEventEnableState(*__pDisabledForm, true);
950 __pDisabledForm = null;
952 AnimationTransaction::SetCurrentTransactionEventListener(null);
956 _SceneManagerImpl::OnSceneControlEventReceived(_SceneControlEventArg::SceneControlEventType eventType, const SceneId& sceneId)
958 SysSecureLog(NID_UI_SCENES, "Received type= 0x%x, sceneId=%ls", eventType, sceneId.GetPointer());
962 case _SceneControlEventArg::SCENE_CONTROL_EVENT_TYPE_DESTROY:
963 DestroyScene(sceneId);
967 SysLog(NID_UI_SCENES, "Invalid SceneControlEventType x0%x", eventType);
972 // Internal operations
974 _SceneManagerImpl::GetScene(SceneId& sceneId)
976 return GetSceneFromContainer(sceneId);
980 _SceneManagerImpl::GetLiveSceneN(void) const
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));
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));
990 while (pMapEnum->MoveNext() == E_SUCCESS)
992 Scene* pScene = null;
993 pMapEnum->GetValue(pScene);
994 pSceneList->Add(pScene);
996 return pSceneList.release();
1001 _SceneManagerImpl::GotoScene(bool forward, const SceneId& sceneId, SceneTransitionAnimationType animationType,
1002 SceneHistoryOption historyOption, SceneDestroyOption destroyOption, const IList* pArgs)
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;
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;
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);
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.
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();
1048 panelAlreadyCreated = true;
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
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]
1087 AddFormToContainer(pScene->GetFormId(), pForm);
1088 pSceneImpl->SetForm(pForm);
1089 onExceptionRemoveFormIdFromFormContainer = true;
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())
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));
1102 pSceneImpl->SetPanelCreatedFromFormResource(true); // Prevent RemoveControl - It's not creatable via Panel factory.
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]
1115 AddPanelToPanelContainer(pScene);
1116 pSceneImpl->SetPanel(pPanel);
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))
1127 doAnimation = false;
1129 if (doAnimation && (GetCurrentForm() == null))
1131 doAnimation = false;
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();
1145 // Initialize Control animator if needed.
1146 if (!formTransition && pPanel)
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();
1154 // Set default value for formTransition
1155 if (formTransition && (animationType >= SCENE_TRANSITION_ANIMATION_TYPE_LEFT) &&
1156 (pFrameAnimator->GetStatus() == ANIMATOR_STATUS_STOPPED))
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);
1165 { // Disable user input
1166 if (__pCurrentScene)
1168 r = SetInputEventEnableState(*__pCurrentScene->GetForm(), false);
1169 SysTryCatch(NID_UI_SCENES, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
1171 r = SetInputEventEnableState(*pForm, false);
1174 if (__pCurrentScene)
1176 SetInputEventEnableState(*__pCurrentScene->GetForm(), true);
1179 SysTryCatch(NID_UI_SCENES, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
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)
1192 SwitchToPanel(pScene->GetFormId(), pPanel);
1194 r = SetCurrentForm(*pForm, doAnimation); // FrameAnimator
1195 SysTryCatch(NID_UI_SCENES, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
1199 r = SetCurrentForm(*pForm);
1200 SysTryCatch(NID_UI_SCENES, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
1203 SwitchToPanel(pScene->GetFormId(), pPanel, doAnimation); // ControlAnimator
1207 else // Scene newly created
1209 if (formAlreadyCreated) // Panel scene created but base form already created - reuse base form.
1215 if (!panelAlreadyCreated) // If a new panel created then Add Panel to Form
1217 AddControlToForm(*pForm, *pPanel);
1219 SwitchToPanel(pScene->GetFormId(), pPanel);
1221 r = SetCurrentForm(*pForm, (doAnimation)); // FrameAnimator
1222 SysTryCatch(NID_UI_SCENES, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
1226 r = SetCurrentForm(*pForm);
1227 SysTryCatch(NID_UI_SCENES, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
1230 if (!panelAlreadyCreated)
1232 AddControlToForm(*pForm, *pPanel);
1234 SwitchToPanel(pScene->GetFormId(), pPanel, doAnimation); // ControlAnimator
1238 else // New Form created!
1243 AddControlToForm(*pForm, *pPanel);
1244 SwitchToPanel(pScene->GetFormId(), pPanel);
1246 AddControlToFrame(*pForm, doAnimation); // Form add to frame
1249 SetCurrentForm(*pForm);
1254 UpdateCurrentScene(pScene);
1255 if ((historyOption == SCENE_HISTORY_OPTION_ADD_HISTORY) && (!previousSceneId.IsEmpty()))
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));
1262 CallListenerOnSceneActivatedN(*pScene, previousSceneId, sceneId, const_cast<IList*>(pArgs));
1263 CallListenerOnSceneTransitionCompleted(previousSceneId, __currentSceneId);
1265 if (destroyOption == SCENE_DESTROY_OPTION_DESTROY )
1267 if (previousIsPanelScene)
1269 DestroySiblingPanelScene(previousSceneId); // Destroy sibling Panel Scene
1273 ReserveDestroyingScene(previousSceneId); // Destroy the Scene after animator finished(stopped).
1277 DestroyScene(previousSceneId); // Sync destroy for non-animation
1281 DrawForm(*pScene->GetForm());
1285 // Check all exception case for proper delete the instances: Scene, Form, Panel and item corresponding container.
1286 if (onExceptionRemovepPanel)
1288 RemovePanelFromPanelContainer(pScene);
1289 delete pPanel; // Also needed it.
1292 if (onExceptionRemoveFormIdFromFormContainer)
1294 RemoveFormFromFormContainer(pScene->GetFormId());
1296 if (onExceptionDeletepForm)
1301 if (onExceptionRemovesceneIdFromSceneContainer)
1303 RemoveSceneFromContainer(sceneId);
1305 if (onExceptionDeletepScene)
1315 _SceneManagerImpl::GetSceneFromContainer(const SceneId& sceneId) const
1317 Scene* pScene = null;
1318 __sceneContainer.GetValue(sceneId, pScene);
1323 _SceneManagerImpl::GetFormFromContainer(const String& formId)
1326 __formContainer.GetValue(formId, pForm);
1331 _SceneManagerImpl::AddSceneToContainer(const SceneId& sceneId, Scene* pScene)
1333 __sceneContainer.Add(sceneId, pScene);
1337 _SceneManagerImpl::RemoveSceneFromContainer(const SceneId& sceneId)
1339 __sceneContainer.Remove(sceneId);
1343 _SceneManagerImpl::AddFormToContainer(const String& formId, Form* pForm)
1345 __formContainer.Add(formId, pForm);
1349 _SceneManagerImpl::RemoveFormFromFormContainer(const String& formId)
1351 __formContainer.Remove(formId);
1355 _SceneManagerImpl::AddPanelToPanelContainer(Scene* pScene)
1357 __formToPanelMultiMap.Add(pScene->GetFormId(), pScene);
1361 _SceneManagerImpl::RemovePanelFromPanelContainer(Scene* pScene)
1363 __formToPanelMultiMap.Remove(pScene->GetFormId(), pScene);
1367 _SceneManagerImpl::UpdateCurrentScene(Scene* pScene)
1369 __pCurrentScene = pScene;
1370 __currentSceneId = pScene->GetSceneId();
1374 _SceneManagerImpl::AddHistory(const SceneId& sceneId)
1376 return __sceneHistory.Add(sceneId);
1380 _SceneManagerImpl::SwitchToPanel(const String& formId, Panel* pPanel, bool useAnimator)
1382 Panel* pShowPanel = null;
1383 Form* pBaseForm = null;
1386 pBaseForm = dynamic_cast<Form*>(pPanel->GetParent());
1387 if (pBaseForm == null)
1389 useAnimator = false;
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)
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)
1404 if (pCurrentScene->GetPanel()->GetShowState())
1406 pShowPanel = pCurrentScene->GetPanel();
1411 if (useAnimator && pShowPanel && pPanel)
1413 int transactionId = 0;
1414 AnimationTransaction::Begin(transactionId); // transactionId was set
1421 ControlAnimator* pControlAnimator = pShowPanel->GetControlAnimator();
1422 if (pControlAnimator)
1424 pControlAnimator->SetShowState(false);
1428 pShowPanel->SetShowState(false);
1433 pShowPanel->SetShowState(false);
1440 ControlAnimator* pControlAnimator = pPanel->GetControlAnimator();
1441 if (pControlAnimator)
1443 pControlAnimator->SetShowState(true);
1447 pPanel->SetShowState(true);
1452 pPanel->SetShowState(true);
1456 if (useAnimator && pShowPanel && pPanel)
1458 // Set event listener & start animations
1459 AnimationTransaction::SetCurrentTransactionEventListener(this);
1460 result r = AnimationTransaction::Commit();
1463 // Disable input for base Form
1466 __pDisabledForm = pBaseForm;
1467 SetInputEventEnableState(*pBaseForm, false);
1472 SysLog(NID_UI_SCENES, "Animation Commit() failed");
1478 _SceneManagerImpl::AddControlToFrame(Form& form, bool useAnimator)
1480 Frame* pFrame = GetFrame();
1485 FrameAnimator* pFrameAnimator = pFrame->GetFrameAnimator();
1488 // Add animator listener to asynchronous scene destroy for safe deletion.
1489 pFrameAnimator->AddFrameAnimatorEventListener(*this);
1490 _FrameAnimatorImpl* pFrameAnimatorImpl = _FrameAnimatorImpl::GetInstance(*pFrameAnimator);
1491 if (pFrameAnimatorImpl)
1493 pFrameAnimatorImpl->AddControl(form);
1497 SysLog(NID_UI_SCENES, "pFrameAnimator or pFrameAnimatorImpl is not valid.");
1499 pFrame->AddControl(form);
1504 _SceneManagerImpl::RemoveControlFromFrame(Form& form)
1506 Frame* pFrame = GetFrame();
1509 // Control validation check for safe operation on termination(Ui destroy before asynchronous scene destroy process).
1510 _ControlManager* pControlManager = _ControlManager::GetInstance();
1511 if (pControlManager)
1513 _Control* pControl = pControlManager->GetObject(__correspondFrameControlHandle);
1516 pFrame->RemoveControl(form);
1521 SysLog(NID_UI_SCENES, "FrameWindow already destroyed. Skip remove control to form.");
1526 SysLog(NID_UI_SCENES, "Window system already shutdown.");
1532 _SceneManagerImpl::SetCurrentForm(Form& form, bool useAnimator)
1534 result r = E_SUCCESS;
1535 Frame* pFrame = GetFrame();
1537 SysTryReturnResult(NID_UI_SCENES, pFrame != null, E_SYSTEM,
1538 "A system error has been occurred. Can not get the Frame window.");
1541 FrameAnimator* pFrameAnimator = pFrame->GetFrameAnimator();
1544 // Add animator listener to asynchronous scene destroy for safe deletion.
1545 pFrameAnimator->AddFrameAnimatorEventListener(*this);
1546 r = pFrameAnimator->SetCurrentForm(form);
1552 SysLog(NID_UI_SCENES, "Safety operation ongoing. Animation may not working, Please check the problems!");
1555 // Check the current Form, if already current one then skip the SetCurrentForm().
1556 if (GetCurrentForm() == &form)
1558 SysSecureLog(NID_UI_SCENES, "The Form already set as current form, skip the SetCurrentForm()");
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.");
1569 _SceneManagerImpl::GetCurrentForm(void)
1571 Frame* pFrame = GetFrame();
1574 return pFrame->GetCurrentForm();
1580 _SceneManagerImpl::AddControlToForm(Form& baseForm, const Panel& panel)
1582 baseForm.AddControl(panel);
1586 _SceneManagerImpl::RemoveControlFromForm(Form& baseForm, const Panel& panel)
1588 baseForm.RemoveControl(panel);
1592 _SceneManagerImpl::SetShowState(Panel& targetPanel, bool state)
1594 targetPanel.SetShowState(state);
1598 _SceneManagerImpl::DrawForm(Form& form)
1600 form.Invalidate(true);
1604 _SceneManagerImpl::CallListenerOnSceneTransitionStarted(const SceneId& currentSceneId, const SceneId& nextSceneId)
1606 std::unique_ptr<IEnumeratorT<ISceneManagerEventListener*> > pEnum(__sceneManagerEventListenerList.GetEnumeratorN());
1612 while (pEnum->MoveNext() == E_SUCCESS)
1614 ISceneManagerEventListener* pListener = null;
1615 pEnum->GetCurrent(pListener);
1618 pListener->OnSceneTransitionStarted(currentSceneId, nextSceneId);
1625 _SceneManagerImpl::CallListenerOnSceneTransitionCompleted(const SceneId& previousSceneId, const SceneId& currentSceneId)
1627 std::unique_ptr<IEnumeratorT<ISceneManagerEventListener*> > pEnum(__sceneManagerEventListenerList.GetEnumeratorN());
1633 while (pEnum->MoveNext() == E_SUCCESS)
1635 ISceneManagerEventListener* pListener = null;
1636 pEnum->GetCurrent(pListener);
1639 pListener->OnSceneTransitionCompleted(previousSceneId, currentSceneId);
1646 _SceneManagerImpl::CallListenerPrepareAnimation(Scene& scene, const SceneId& sceneId, IList* pArgs,
1647 SceneTransitionAnimationType type, bool formTransition)
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->PrepareAnimation(sceneId, pArgs, type, formTransition);
1658 _SceneManagerImpl::CallListenerOnSceneActivatedN(Scene& scene, const SceneId& previousSceneId, const SceneId& currentSceneId,
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));
1666 return pSceneImpl->OnSceneActivatedN(previousSceneId, currentSceneId, pArgs);
1670 _SceneManagerImpl::CallListenerOnSceneDeactivated(Scene& scene, const SceneId& currentSceneId, const SceneId& nextSceneId)
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));
1677 return pSceneImpl->OnSceneDeactivated(currentSceneId, nextSceneId);
1681 _SceneManagerImpl::CallStretegyGetNextScene(const SceneId& currentSceneId, const IList* pArgs)
1683 SceneId nextScene(L"");
1684 if (__pPolicyProvider)
1686 nextScene = __pPolicyProvider->GetNextScene(currentSceneId, pArgs);
1692 _SceneManagerImpl::DestroySceneAsync(const SceneId& sceneId)
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);
1702 _SceneManagerImpl::ReserveDestroyingScene(const SceneId& sceneId)
1704 if (!__destroyReservedScene.IsEmpty())
1706 SysLog(NID_UI_SCENES, "Previous reserved sceneId=%ls", __destroyReservedScene.GetPointer());
1708 __destroyReservedScene = sceneId;
1712 _SceneManagerImpl::DestroyReservedScene(void)
1714 if (!__destroyReservedScene.IsEmpty())
1716 DestroySceneAsync(__destroyReservedScene);
1717 __destroyReservedScene.Clear();
1722 _SceneManagerImpl::DestroySiblingPanelScene(const SceneId& sceneId)
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));
1729 Panel* pPanel = pScene->GetPanel();
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)
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)
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)
1755 destroyList.Add(pCurrentScene); // DestroyScene modify __formToPanelMultiMap so can't destroy here.
1759 for (int i = 0; i < destroyList.GetCount(); i++)
1761 Scene* pCurrentScene = null;
1762 destroyList.GetAt(i, pCurrentScene);
1765 DestroyScene(pCurrentScene->GetSceneId());
1772 _SceneManagerImpl::GetFrame(void)
1774 if (__pCorrespondFrame == null)
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)
1787 __correspondFrameControlHandle = pFrameWindowImpl->GetCore().GetHandle();
1790 return __pCorrespondFrame;
1794 _SceneManagerImpl::IsAnimationCompleted(void)
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();
1803 bool completed = (pFrameAnimator->GetStatus() == ANIMATOR_STATUS_STOPPED) ? true : false;
1810 _SceneManagerImpl::SetInputEventEnableState(Tizen::Ui::Control& control, bool enableState)
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();
1816 if (enableState == false)
1818 controlCore.LockInputEvent();
1822 controlCore.UnlockInputEvent();
1828 _SceneManagerImpl::GetSceneTransition(const SceneTransitionId& transitionId, SceneTransition& sceneTransition) const
1830 result r = E_SUCCESS;
1831 SysTryReturnResult(NID_UI_SCENES, !transitionId.IsEmpty(), E_INVALID_ARG,
1832 "Invalid argument is used. The transitionId is empty.");
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;
1843 _SceneManagerImpl::RegisterScene(xmlNodePtr pNode)
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;
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));
1854 xmlChar* pSceneId = xmlGetProp(pNode, reinterpret_cast<const xmlChar*>(pPropId));
1857 String strSceneId(reinterpret_cast<char*>(pSceneId));
1860 xmlChar* pFormId = xmlGetProp(pNode, reinterpret_cast<const xmlChar*>(pPropFormId));
1863 String strFormId(reinterpret_cast<char*>(pFormId));
1867 xmlChar* pPanelId = xmlGetProp(pNode, reinterpret_cast<const xmlChar*>(pPropPanelId));
1870 strPanelId = reinterpret_cast<char*>(pPanelId);
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.");
1880 pSceneDescription = new (std::nothrow) _SceneDescription(strFormId, strPanelId);
1881 SysTryReturnResult(NID_UI_SCENES, pSceneDescription != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
1883 r = __sceneMap.Add(strSceneId, pSceneDescription);
1884 SysTryCatch(NID_UI_SCENES, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
1890 delete pSceneDescription;
1895 _SceneManagerImpl::RegisterSceneTransition(xmlNodePtr pNode)
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";
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");
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 };
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));
1925 xmlChar* pTransitionId = xmlGetProp(pNode, pPropId);
1928 String strTransitionId(reinterpret_cast<char*>(pTransitionId));
1929 xmlFree(pTransitionId);
1930 if (strTransitionId.GetLength() > 0)
1932 xmlChar* pDirectionType = xmlGetProp(pNode, reinterpret_cast<const xmlChar*>(pPropDirectionType));
1935 String strDirectionType(reinterpret_cast<char*>(pDirectionType));
1936 xmlFree(pDirectionType);
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;
1948 // Get animationType and destroyOption (common property)
1949 xmlChar* pAnimationType = xmlGetProp(pNode, reinterpret_cast<const xmlChar*>(pPropAnimationType));
1952 strAnimationType = reinterpret_cast<char*>(pAnimationType);
1953 xmlFree(pAnimationType);
1954 if (strAnimationType.GetLength() > 0)
1956 for (unsigned int i = 0; i < sizeof(valueAnimation)/sizeof(valueAnimation[0]); i++)
1957 { // Consider to use map collection.
1958 if (strAnimationType == strValueAnimationType[i])
1960 animationType = valueAnimation[i];
1967 xmlChar* pDestroyOption = xmlGetProp(pNode, reinterpret_cast<const xmlChar*>(pPropDestroyOption));
1970 strDestroyOption = reinterpret_cast<char*>(pDestroyOption);
1971 xmlFree(pDestroyOption);
1974 // Compose SceneTransition
1975 if (strDirectionType == strValueDirectionAdjacentBackward) // Adjacent backward
1977 SceneDestroyOption destroyOption = SCENE_DESTROY_OPTION_DESTROY; // Default is destroy
1978 if ((strDestroyOption.GetLength() > 0) && (strDestroyOption == strValueDestroyOptionKeep))
1980 destroyOption = SCENE_DESTROY_OPTION_KEEP;
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));
1990 // Get destinationSceneId
1991 xmlChar* pDestinationSceneId = xmlGetProp(pNode, reinterpret_cast<const xmlChar*>(pPropDestinationSceneId));
1992 if (pDestinationSceneId)
1994 strDestinationSceneId = reinterpret_cast<char*>(pDestinationSceneId);
1995 xmlFree(pDestinationSceneId);
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));
2000 if (strDirectionType == strValueDirectionBackward) // Backward
2002 SceneDestroyOption destroyOption = SCENE_DESTROY_OPTION_DESTROY; // Default is destroy
2003 if ((strDestroyOption.GetLength() > 0) && (strDestroyOption == strValueDestroyOptionKeep))
2005 destroyOption = SCENE_DESTROY_OPTION_KEEP;
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));
2016 if (strDirectionType == strValueDirectionForward) // Forward
2018 SceneDestroyOption destroyOption = SCENE_DESTROY_OPTION_KEEP; // Default is keep
2019 if ((strDestroyOption.GetLength() > 0) && (strDestroyOption == strValueDestroyOptionDestroy))
2021 destroyOption = SCENE_DESTROY_OPTION_DESTROY;
2024 xmlChar* pHistoryOption = xmlGetProp(pNode, reinterpret_cast<const xmlChar*>(pPropHistoryOption));
2027 strHistoryOption = reinterpret_cast<char*>(pHistoryOption);
2028 xmlFree(pHistoryOption);
2030 SceneHistoryOption historyOption = SCENE_HISTORY_OPTION_ADD_HISTORY; // Default is add to history
2031 if ((strHistoryOption.GetLength() > 0) && (strHistoryOption == strValueHistoryOptionNoHistory))
2033 historyOption = SCENE_HISTORY_OPTION_NO_HISTORY;
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));
2045 SysLog(NID_UI_SCENES, "Unknown direction type!");
2053 delete pSceneTransition;
2058 _SceneManagerImpl::StopAllAnimations(void)
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())
2067 DestroyScene(__destroyReservedScene);
2068 __destroyReservedScene.Clear();
2073 } } } // Tizen::Ui::Scenes