From ed08da8ea1a4a1efe1b01dd885d45153bc5f87c8 Mon Sep 17 00:00:00 2001 From: Keuckdo Bang Date: Thu, 31 Oct 2013 15:15:11 +0900 Subject: [PATCH] Add EventList for activating and deactivating. Change-Id: I92c1cce89cb53e15c09e2ca99b119e50e55de72d --- src/ui/FUi_Control.cpp | 7 ++ src/ui/FUi_ControlImpl.cpp | 6 ++ src/ui/controls/FUiCtrl_Frame.cpp | 114 ++++++++++++++++++--- src/ui/inc/FUiCtrl_Frame.h | 15 ++- .../FUiCtrl_IFormActivationChangeEventListener.h | 6 +- src/ui/inc/FUi_Control.h | 2 + src/ui/inc/FUi_ControlImpl.h | 1 + 7 files changed, 130 insertions(+), 21 deletions(-) diff --git a/src/ui/FUi_Control.cpp b/src/ui/FUi_Control.cpp index e3f8f52..30f6c33 100644 --- a/src/ui/FUi_Control.cpp +++ b/src/ui/FUi_Control.cpp @@ -881,6 +881,11 @@ _Control::OnChildAttached(const _Control& child) } void +_Control::OnChildAttaching(const _Control& child) +{ +} + +void _Control::OnChildDetaching(const _Control& child) { } @@ -1720,6 +1725,8 @@ _Control::StartAttaching(_Control& child, _ControlArea area) r = child.GetControlDelegate().OnAttaching(this); SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r)); + GetControlDelegate().OnChildAttaching(child); + if (IsAttachedToMainTree()) { r = CallOnAttachingToMainTree(child); diff --git a/src/ui/FUi_ControlImpl.cpp b/src/ui/FUi_ControlImpl.cpp index 0e56b4d..0864761 100644 --- a/src/ui/FUi_ControlImpl.cpp +++ b/src/ui/FUi_ControlImpl.cpp @@ -2782,6 +2782,12 @@ _ControlImpl::OnChildAttached(const _Control& child) } void +_ControlImpl::OnChildAttaching(const _Control& child) +{ + GetCore().OnChildAttaching(child); +} + +void _ControlImpl::OnChildDetaching(const _Control& child) { GetCore().OnChildDetaching(child); diff --git a/src/ui/controls/FUiCtrl_Frame.cpp b/src/ui/controls/FUiCtrl_Frame.cpp index e5ab51a..0cc230d 100644 --- a/src/ui/controls/FUiCtrl_Frame.cpp +++ b/src/ui/controls/FUiCtrl_Frame.cpp @@ -71,7 +71,7 @@ _Frame::_Frame(void) , __rotation(false) , __changingBoundsEnabled(true) , __skipSetBounds(false) - , __pFormActivationChangeEventListener(null) + , __pFormActivationChangeEventListeners(null) { _FramePresenter* pPresenter = new (std::nothrow) _FramePresenter(*this); SysTryReturnVoidResult(NID_UI_CTRL, pPresenter, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient."); @@ -80,12 +80,19 @@ _Frame::_Frame(void) __floatingBounds.width = screen.width; __floatingBounds.height = screen.height; - __pFrameEvent = _FrameEvent::CreateInstanceN(*this); - SysTryCatch(NID_UI_CTRL, __pFrameEvent, , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); + LinkedListT <_IFormActivationChangeEventListener*>* pFormActivationChangeEventListeners = null; + + _FrameEvent* pFrameEvent = _FrameEvent::CreateInstanceN(*this); + SysTryCatch(NID_UI_CTRL, pFrameEvent, , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); + + pFormActivationChangeEventListeners = new (std::nothrow) LinkedListT <_IFormActivationChangeEventListener*>; + SysTryCatch(NID_UI_CTRL, pFormActivationChangeEventListeners, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage."); SetPresenter(*pPresenter); SetClipChildrenEnabled(false); + __pFrameEvent = pFrameEvent; + __pFormActivationChangeEventListeners = pFormActivationChangeEventListeners; ClearLastResult(); return; @@ -93,6 +100,9 @@ _Frame::_Frame(void) CATCH: delete pPresenter; pPresenter = null; + + delete pFrameEvent; + pFrameEvent = null; } _Frame::~_Frame(void) @@ -106,6 +116,9 @@ _Frame::~_Frame(void) delete __pFramePresenter; __pFramePresenter = null; + delete __pFormActivationChangeEventListeners; + __pFormActivationChangeEventListeners = null; + ClearLastResult(); } @@ -380,6 +393,8 @@ _Frame::SetCurrentForm(const _Form* pForm) { if (pCurrentForm != pForm) { + FireFormActivationChangeEvent(pCurrentForm, _FORM_STATUS_DEACTIVATING); + // Change order r = MoveChildToTop(*pForm); SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r)); @@ -390,13 +405,11 @@ _Frame::SetCurrentForm(const _Form* pForm) pCurrentForm->OnFormDeactivated(); - if (__pFormActivationChangeEventListener) - { - __pFormActivationChangeEventListener->OnFormDeactivated(*pCurrentForm); - } + FireFormActivationChangeEvent(pCurrentForm, _FORM_STATUS_DEACTIVATED); } } + FireFormActivationChangeEvent(pCurrentForm, _FORM_STATUS_ACTIVATING); pNewForm->SetVisibleState(true); pNewForm->OnFormActivated(); _Control* pFocus = pNewForm->GetFocusControl(); @@ -415,10 +428,7 @@ _Frame::SetCurrentForm(const _Form* pForm) } pNewForm->SetUpdateLayoutState(true); - if (__pFormActivationChangeEventListener) - { - __pFormActivationChangeEventListener->OnFormActivated(*pNewForm); - } + FireFormActivationChangeEvent(pNewForm, _FORM_STATUS_ACTIVATED); SetLastResult(E_SUCCESS); @@ -481,12 +491,67 @@ _Frame::RemoveFrameEventListener(const _IFrameEventListener& listener) SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r)); } -void -_Frame::SetFormActivationChangeEventListener(const _IFormActivationChangeEventListener* plistener) +result +_Frame::AddFormActivationChangeEventListener(_IFormActivationChangeEventListener& listener) { - __pFormActivationChangeEventListener = const_cast<_IFormActivationChangeEventListener*>(plistener); + ClearLastResult(); + SysTryReturn(NID_UI, + __pFormActivationChangeEventListeners->Add(&listener) == E_SUCCESS, E_SYSTEM, + E_SYSTEM, "[E_SYSTEM] System error occurred."); + + return E_SUCCESS; } +result +_Frame::RemoveFormActivationChangeEventListener(_IFormActivationChangeEventListener& listener) +{ + ClearLastResult(); + SysTryReturn(NID_UI, __pFormActivationChangeEventListeners->Remove(&listener) == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] System error occurred."); + + return E_SUCCESS; +} + +result +_Frame::FireFormActivationChangeEvent(_Form* pForm, _FormStatus status) +{ + if (__pFormActivationChangeEventListeners) + { + if (__pFormActivationChangeEventListeners->GetCount() > 0 ) + { + IEnumeratorT<_IFormActivationChangeEventListener*>* pEnumerator = __pFormActivationChangeEventListeners->GetEnumeratorN(); + if (pEnumerator) + { + while (pEnumerator->MoveNext() == E_SUCCESS) + { + _IFormActivationChangeEventListener* pFormActivationChangeEventListener = null; + pEnumerator->GetCurrent(pFormActivationChangeEventListener); + if (pFormActivationChangeEventListener) + { + switch (status) + { + case _FORM_STATUS_ACTIVATING : + pFormActivationChangeEventListener->OnFormActivating(*pForm); + break; + case _FORM_STATUS_DEACTIVATING : + pFormActivationChangeEventListener->OnFormDeactivating(*pForm); + break; + case _FORM_STATUS_ACTIVATED : + pFormActivationChangeEventListener->OnFormActivated(*pForm); + break; + case _FORM_STATUS_DEACTIVATED : + pFormActivationChangeEventListener->OnFormDeactivated(*pForm); + break; + default: + break; + } + } + } + delete pEnumerator; + } + } + } + return E_SUCCESS; +} void _Frame::SetFloatingBounds(const FloatRectangle& rect) @@ -781,23 +846,38 @@ _Frame::OnChildAttached(const _Control& child) if (controlCount > 1) { - _Control* pOldCurrentForm = GetChild(controlCount - 2); + _Form* pOldCurrentForm = dynamic_cast<_Form*>(GetChild(controlCount - 2)); SysTryReturnVoidResult(NID_UI_CTRL, pOldCurrentForm != null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); pOldCurrentForm->SetVisibleState(false); + FireFormActivationChangeEvent(pOldCurrentForm, _FORM_STATUS_DEACTIVATED); } } } void +_Frame::OnChildAttaching(const _Control& child) +{ + _Form* pCurrentForm = GetCurrentForm(); + + if (pCurrentForm != null && pCurrentForm != &child) + { + FireFormActivationChangeEvent(pCurrentForm, _FORM_STATUS_DEACTIVATING); + } + _Form* pChild = dynamic_cast<_Form*>(&const_cast<_Control&>(child)); + FireFormActivationChangeEvent(pChild, _FORM_STATUS_ACTIVATING); +} + +void _Frame::OnChildDetached(const _Control& child) { int controlCount = GetChildCount(); if (controlCount > 0) { - _Control* pCurrentForm = GetChild(controlCount - 1); + _Form* pCurrentForm = dynamic_cast<_Form*>(GetChild(controlCount - 1)); SysTryReturnVoidResult(NID_UI_CTRL, pCurrentForm, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); pCurrentForm->SetVisibleState(true); + FireFormActivationChangeEvent(pCurrentForm, _FORM_STATUS_ACTIVATED); } else { @@ -1032,7 +1112,7 @@ _Frame::OnBackgroundColorChanged(Color& backgroundColor) void _Frame::ResetFocusList(void) { - Tizen::Ui::Controls::_Form* pCurrentForm = GetCurrentForm(); + _Form* pCurrentForm = GetCurrentForm(); if (pCurrentForm) { pCurrentForm->ResetFocusList(); diff --git a/src/ui/inc/FUiCtrl_Frame.h b/src/ui/inc/FUiCtrl_Frame.h index a344ffd..ba41822 100644 --- a/src/ui/inc/FUiCtrl_Frame.h +++ b/src/ui/inc/FUiCtrl_Frame.h @@ -34,6 +34,14 @@ class _IFrameEventListener; class _IFormActivationChangeEventListener; class _Form; +enum _FormStatus +{ + _FORM_STATUS_ACTIVATING = 0, + _FORM_STATUS_DEACTIVATING, + _FORM_STATUS_ACTIVATED, + _FORM_STATUS_DEACTIVATED, +}; + /** * @class _Frame * @brief @@ -55,6 +63,7 @@ public: virtual void OnDraw(void); virtual void OnActivated(void); virtual void OnDeactivated(void); + virtual void OnChildAttaching(const Tizen::Ui::_Control& child); virtual void OnChildAttached(const Tizen::Ui::_Control& child); virtual void OnChildDetached(const Tizen::Ui::_Control& child); virtual bool OnNotifiedN(const Tizen::Ui::_Control& source, Tizen::Base::Collection::IList* pArgs); @@ -77,7 +86,8 @@ public: // Event listeners void AddFrameEventListener(const Tizen::Ui::Controls::_IFrameEventListener& listener); void RemoveFrameEventListener(const Tizen::Ui::Controls::_IFrameEventListener& listener); - void SetFormActivationChangeEventListener(const Tizen::Ui::Controls::_IFormActivationChangeEventListener* plistener); + result AddFormActivationChangeEventListener(_IFormActivationChangeEventListener& listener); + result RemoveFormActivationChangeEventListener(_IFormActivationChangeEventListener& listener); // Floating void SetFloatingBounds(const Tizen::Graphics::Rectangle& rect); @@ -111,6 +121,7 @@ private: _Frame& operator =(const _Frame&); virtual bool IsChildAttachable(_Control& child) const; + result FireFormActivationChangeEvent(_Form* pForm, _FormStatus status); // Attribute private: @@ -126,7 +137,7 @@ private: bool __rotation; bool __changingBoundsEnabled; bool __skipSetBounds; - _IFormActivationChangeEventListener* __pFormActivationChangeEventListener; + Tizen::Base::Collection::LinkedListT * __pFormActivationChangeEventListeners; }; // _Frame }}} // Tizen::Ui::Controls diff --git a/src/ui/inc/FUiCtrl_IFormActivationChangeEventListener.h b/src/ui/inc/FUiCtrl_IFormActivationChangeEventListener.h index 3c73d2c..ede0498 100644 --- a/src/ui/inc/FUiCtrl_IFormActivationChangeEventListener.h +++ b/src/ui/inc/FUiCtrl_IFormActivationChangeEventListener.h @@ -38,11 +38,11 @@ class _FormImpl; * @brief This interface implements the listener for the form activation chage event. * @since 2.0 * - * The listener interface for receiving form activation chage event. + * The listener interface for receiving form activation change event. * */ class _IFormActivationChangeEventListener - : public Tizen::Base::Runtime::IEventListener + : virtual public Tizen::Base::Runtime::IEventListener { public: /** @@ -55,6 +55,8 @@ public: virtual void OnFormActivated(const Tizen::Ui::Controls::_Form& source) = 0; virtual void OnFormDeactivated(const Tizen::Ui::Controls::_Form& source) = 0; + virtual void OnFormActivating(const Tizen::Ui::Controls::_Form& source) = 0; + virtual void OnFormDeactivating(const Tizen::Ui::Controls::_Form& source) = 0; }; // _IFormActivationChangeEventListener diff --git a/src/ui/inc/FUi_Control.h b/src/ui/inc/FUi_Control.h index 2ea1c29..b6f1a72 100644 --- a/src/ui/inc/FUi_Control.h +++ b/src/ui/inc/FUi_Control.h @@ -99,6 +99,7 @@ public: virtual void OnEvaluateSize(Tizen::Graphics::Dimension& evaluatedSize) = 0; virtual bool OnEvaluateSize(Tizen::Graphics::FloatDimension& evaluatedSize) = 0; virtual void OnParentBoundsChanged(const _Control& parent) = 0; + virtual void OnChildAttaching(const _Control& child) = 0; virtual void OnChildAttached(const _Control& child) = 0; virtual void OnChildDetaching(const _Control& child) = 0; virtual void OnChildDetached(const _Control& child) = 0; @@ -262,6 +263,7 @@ public: virtual void OnEvaluateSize(Tizen::Graphics::Dimension& evaluatedSize); virtual bool OnEvaluateSize(Tizen::Graphics::FloatDimension& evaluatedSize); virtual void OnParentBoundsChanged(const _Control& parent); + virtual void OnChildAttaching(const _Control& child); virtual void OnChildAttached(const _Control& child); virtual void OnChildDetaching(const _Control& child); virtual void OnChildDetached(const _Control& child); diff --git a/src/ui/inc/FUi_ControlImpl.h b/src/ui/inc/FUi_ControlImpl.h index be32949..ad5764d 100644 --- a/src/ui/inc/FUi_ControlImpl.h +++ b/src/ui/inc/FUi_ControlImpl.h @@ -148,6 +148,7 @@ public: virtual void OnEvaluateSize(Tizen::Graphics::Dimension& evaluatedSize); virtual bool OnEvaluateSize(Tizen::Graphics::FloatDimension& evaluatedSize); virtual void OnParentBoundsChanged(const _Control& parent); + virtual void OnChildAttaching(const _Control& child); virtual void OnChildAttached(const _Control& child); virtual void OnChildDetaching(const _Control& child); virtual void OnChildDetached(const _Control& child); -- 2.7.4