From 4766f576c69e43148e7b9efa5d9f74f85799c826 Mon Sep 17 00:00:00 2001 From: Keuckdo Bang Date: Thu, 30 May 2013 23:46:24 +0900 Subject: [PATCH] Add event listener regarding option button. Change-Id: Iceb56978824ca1cb9f3d6bd3d851a0162d40ffe9 --- inc/FUiControls.h | 1 + inc/FUiCtrlForm.h | 12 + inc/FUiCtrlIFormControlEventListener.h | 110 +++ inc/FUiCtrlOptionMenu.h | 2 + src/ui/CMakeLists.txt | 1 + src/ui/controls/FUiCtrlForm.cpp | 10 + src/ui/controls/FUiCtrlOptionMenu.cpp | 28 + src/ui/controls/FUiCtrl_ContextMenu.cpp | 29 +- src/ui/controls/FUiCtrl_Form.cpp | 47 +- src/ui/controls/FUiCtrl_FormImpl.cpp | 47 + src/ui/controls/FUiCtrl_OptionMenuImpl.cpp | 53 +- .../controls/FUiCtrl_OptionMenuListPresenter.cpp | 941 +++++++++++++++++++++ src/ui/inc/FUiCtrl_ContextMenu.h | 1 + src/ui/inc/FUiCtrl_Form.h | 4 + src/ui/inc/FUiCtrl_FormImpl.h | 6 + src/ui/inc/FUiCtrl_IFormControlEventListener.h | 107 +++ src/ui/inc/FUiCtrl_OptionMenuImpl.h | 13 +- src/ui/inc/FUiCtrl_OptionMenuListPresenter.h | 146 ++++ 18 files changed, 1526 insertions(+), 32 deletions(-) create mode 100644 inc/FUiCtrlIFormControlEventListener.h create mode 100644 src/ui/controls/FUiCtrl_OptionMenuListPresenter.cpp create mode 100644 src/ui/inc/FUiCtrl_IFormControlEventListener.h create mode 100644 src/ui/inc/FUiCtrl_OptionMenuListPresenter.h diff --git a/inc/FUiControls.h b/inc/FUiControls.h index 6adbd6b..a8e0447 100644 --- a/inc/FUiControls.h +++ b/inc/FUiControls.h @@ -75,6 +75,7 @@ #include #include #include +#include #include #include #include diff --git a/inc/FUiCtrlForm.h b/inc/FUiCtrlForm.h index 9c5d1a9..17a39da 100644 --- a/inc/FUiCtrlForm.h +++ b/inc/FUiCtrlForm.h @@ -44,6 +44,7 @@ class Header; class Footer; class Tab; class IFormBackEventListener; +class IFormControlEventListener; /** * @enum FormStyle @@ -1044,6 +1045,17 @@ public: /** + * Sets the %Form control event listener. + * + * @since 2.1 + * + * @param[in] pFormControlEventListener The %Form control event listener to set + * @see Tizen::Ui::Controls::IFormControlEventListener. + */ + void SetFormControlEventListener(IFormControlEventListener* pFormControlEventListener); + + + /** * Gets the data binding context. * * @since 2.0 diff --git a/inc/FUiCtrlIFormControlEventListener.h b/inc/FUiCtrlIFormControlEventListener.h new file mode 100644 index 0000000..164f27b --- /dev/null +++ b/inc/FUiCtrlIFormControlEventListener.h @@ -0,0 +1,110 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0/ +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FUiCtrlIFormControlventListener.h + * @brief This is the header file for the %IFormControlventListener interface. + * + * This header file contains the declarations of the %IFormControlventListener interface. + */ +#ifndef _FUI_CTRL_IFORM_CONTROL_EVENT_LISTENER_H_ +#define _FUI_CTRL_IFORM_CONTROL_EVENT_LISTENER_H_ + +// includes +#include + +// namespace declaration +namespace Tizen { namespace Ui { namespace Controls +{ + +class Form; + +/** + * @interface IFormControlEventListener + * @brief This interface implements the listener for Form-related events. + * + * @since 2.0 + * + * The %IFormControlEventListener interface is the listener interface for receiving Form-related events. + * + * For more information on the class features, see Form. + */ +class IFormControlEventListener + : virtual public Tizen::Base::Runtime::IEventListener +{ +// Lifecycle +public: + /** + * This is the destructor for this class. + * + * @since 2.0 + */ + virtual ~IFormControlEventListener(void) {} + +// Operation +public: + /** + * Called when the current Form control needs to be closed to revert back to the previous %Form control. + * + * @since 2.1 + * + * @param[in] source The source of the event + * @remarks This event is fired when the user clicks on the software 'back' button on the Footer control, or the hardware back button on the + * device. + */ + virtual void OnFormBackButtonRequested(Tizen::Ui::Controls::Form& source) = 0; + + virtual void OnFormOptionButtonRequested(Tizen::Ui::Controls::Form& source) = 0; + +// Reserves +protected: + // + //This method is for internal use only. Using this method can cause behavioral, security-related, + //and consistency-related issues in the application. + // + // This method is reserved and may change its name at any time without + // prior notice. + // + // @since 2.0 + // + virtual void IFormControlEventListener_Reserved1(void) { } + + // + //This method is for internal use only. Using this method can cause behavioral, security-related, + //and consistency-related issues in the application. + // + // This method is reserved and may change its name at any time without + // prior notice. + // + // @since 2.0 + // + virtual void IFormControlEventListener_Reserved2(void) { } + + // + //This method is for internal use only. Using this method can cause behavioral, security-related, + //and consistency-related issues in the application. + // + // This method is reserved and may change its name at any time without + // prior notice. + // + // @since 2.0 + // + virtual void IFormControlEventListener_Reserved3(void) { } +}; // IFormControlEventListener + +}}} // Tizen::Ui::Controls + +#endif // _FUI_CTRL_IFORM_CONTROL_EVENT_LISTENER_H_ diff --git a/inc/FUiCtrlOptionMenu.h b/inc/FUiCtrlOptionMenu.h index 4fcd115..87a3a83 100644 --- a/inc/FUiCtrlOptionMenu.h +++ b/inc/FUiCtrlOptionMenu.h @@ -246,6 +246,8 @@ public: */ result AddItem(const Tizen::Base::String& text, int actionId); + result AddItem(const Tizen::Graphics::Bitmap& normalBitmap, const Tizen::Graphics::Bitmap* pPressedBitmap, const Tizen::Graphics::Bitmap* pHighlightedBitmap, int actionId); + result AddItem(const Tizen::Base::String &text, int actionId, const Tizen::Graphics::Bitmap& normalBitmap, const Tizen::Graphics::Bitmap* pPressedBitmap=null, const Tizen::Graphics::Bitmap* pHighlightedBitmap=null); /** * @if OSPDEPREC * Inserts a specific item at the given index of %OptionMenu. diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt index 4d67243..691cda9 100644 --- a/src/ui/CMakeLists.txt +++ b/src/ui/CMakeLists.txt @@ -386,6 +386,7 @@ SET (${this_target}_SOURCE_FILES controls/FUiCtrl_OptionMenu.cpp controls/FUiCtrl_OptionMenuModel.cpp controls/FUiCtrl_OptionMenuPresenter.cpp + controls/FUiCtrl_OptionMenuListPresenter.cpp controls/FUiCtrl_OptionMenuItem.cpp controls/FUiCtrl_Panel.cpp controls/FUiCtrl_PanelPresenter.cpp diff --git a/src/ui/controls/FUiCtrlForm.cpp b/src/ui/controls/FUiCtrlForm.cpp index bdcffe9..d2be91d 100644 --- a/src/ui/controls/FUiCtrlForm.cpp +++ b/src/ui/controls/FUiCtrlForm.cpp @@ -668,6 +668,16 @@ Form::SetFormBackEventListener(IFormBackEventListener* pFormBackEventListener) return pImpl->SetFormBackEventListener(pFormBackEventListener); } +void +Form::SetFormControlEventListener(IFormControlEventListener* pFormControlEventListener) +{ + _FormImpl* pImpl = _FormImpl::GetInstance(*this); + SysAssertf(pImpl != null, + "Not yet constructed. Construct() should be called before use."); + + return pImpl->SetFormControlEventListener(pFormControlEventListener); +} + DataBindingContext* Form::GetDataBindingContextN(void) const { diff --git a/src/ui/controls/FUiCtrlOptionMenu.cpp b/src/ui/controls/FUiCtrlOptionMenu.cpp index 36a5467..22ff111 100644 --- a/src/ui/controls/FUiCtrlOptionMenu.cpp +++ b/src/ui/controls/FUiCtrlOptionMenu.cpp @@ -24,6 +24,7 @@ #include #include "FUiCtrl_OptionMenuImpl.h" +#include "FUiCtrl_ContextMenuImpl.h" using namespace Tizen::Base; @@ -92,6 +93,33 @@ OptionMenu::AddItem(const String& text, int actionId) SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r)); return r; +} +result +OptionMenu::AddItem(const Tizen::Graphics::Bitmap& normalBitmap, const Tizen::Graphics::Bitmap* pPressedBitmap, const Tizen::Graphics::Bitmap* pHighlightedBitmap, int actionId) +{ + ClearLastResult(); + + _OptionMenuImpl* pOptionMenuImpl = _OptionMenuImpl::GetInstance(*this); + SysAssertf((pOptionMenuImpl != null), "Not yet constructed. Construct() should be called before use."); + + result r = pOptionMenuImpl->AddItem(normalBitmap, pPressedBitmap, pHighlightedBitmap, actionId); + SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r)); + + return r; +} + +result +OptionMenu::AddItem(const Tizen::Base::String &text, int actionId, const Tizen::Graphics::Bitmap& normalBitmap, const Tizen::Graphics::Bitmap* pPressedBitmap, const Tizen::Graphics::Bitmap* pHighlightedBitmap) +{ + ClearLastResult(); + + _OptionMenuImpl* pOptionMenuImpl = _OptionMenuImpl::GetInstance(*this); + SysAssertf((pOptionMenuImpl != null), "Not yet constructed. Construct() should be called before use."); + + result r = pOptionMenuImpl->AddItem(text, actionId, normalBitmap, pPressedBitmap, pHighlightedBitmap); + SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r)); + + return r; } result diff --git a/src/ui/controls/FUiCtrl_ContextMenu.cpp b/src/ui/controls/FUiCtrl_ContextMenu.cpp index f763947..459b26f 100644 --- a/src/ui/controls/FUiCtrl_ContextMenu.cpp +++ b/src/ui/controls/FUiCtrl_ContextMenu.cpp @@ -82,8 +82,6 @@ _ContextMenu::_ContextMenu(const FloatPoint& point, enum ContextMenuCoreStyle st __pArrowNormalBitmap[i] = null; __pArrowEffectBitmap[i] = null; } - - GET_SHAPE_CONFIG(CONTEXTMENU::ITEM_MAX_COUNT, __layout, __showItemMaxCount); } _ContextMenu::~_ContextMenu(void) @@ -206,12 +204,24 @@ _ContextMenu::Install(void) if (__style == CONTEXT_MENU_CORE_STYLE_LIST) { - _IContextMenuPresenter* pPresenter = new (std::nothrow) _ContextMenuListPresenter(this); - SysTryReturnResult(NID_UI_CTRL, pPresenter != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient."); - - SetPresenter(*pPresenter); - - r = pPresenter->Install(); + if (__anchorPoint.Equals(FloatPoint(-1.0f ,-1.0f))) + { + _IContextMenuPresenter* pPresenter = new (std::nothrow) _OptionMenuListPresenter(this); + SysTryReturnResult(NID_UI_CTRL, pPresenter != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient."); + + SetPresenter(*pPresenter); + + r = pPresenter->Install(); + } + else + { + _IContextMenuPresenter* pPresenter = new (std::nothrow) _ContextMenuListPresenter(this); + SysTryReturnResult(NID_UI_CTRL, pPresenter != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient."); + + SetPresenter(*pPresenter); + + r = pPresenter->Install(); + } } else { @@ -312,8 +322,7 @@ _ContextMenu::OnAttachedToMainTree(void) __pContextMenuPresenter->CalculateShowItemCount(); } - r = __pContextMenuPresenter->CalculateWindowRect(); - SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(GetLastResult())); + __pContextMenuPresenter->CalculateWindowRect(); r = Open(); diff --git a/src/ui/controls/FUiCtrl_Form.cpp b/src/ui/controls/FUiCtrl_Form.cpp index 9523859..52702da 100644 --- a/src/ui/controls/FUiCtrl_Form.cpp +++ b/src/ui/controls/FUiCtrl_Form.cpp @@ -64,6 +64,7 @@ namespace Tizen { namespace Ui { namespace Controls _Form::_Form(void) : __pFormPresenter(null) , __pFormBackEventListener(null) + , __pFormControlEventListener(null) , __formStyle(0) , __pActionEvent(null) , __pHeader(null) @@ -350,6 +351,19 @@ _Form::SetFormBackEventListener(_IFormBackEventListener* pFormBackEventListener) SetLastResult(E_SUCCESS); } +void +_Form::SetFormControlEventListener(_IFormControlEventListener* pFormControlEventListener) +{ + SysTryReturnVoidResult(NID_UI_CTRL, __pFooter, E_INVALID_STATE, "[E_INVALID_STATE] Footer and Header aren't constructed."); + __pFormControlEventListener = pFormControlEventListener; + if (__pFooter) + { + __pFooter->SetOptionEventListener(*this, ID_OPTION_BUTTON); + } + + SetLastResult(E_SUCCESS); +} + unsigned long _Form::GetFormStyle(void) const { @@ -2536,7 +2550,7 @@ _Form::OnKeyPressed(const _Control& source, const _KeyInfo& keyInfo) bool _Form::OnKeyReleased(const _Control& source, const _KeyInfo& keyInfo) { - if (keyInfo.GetKeyCode() == _KEY_ESC) + if (keyInfo.GetKeyCode() == _KEY_ESC || keyInfo.GetKeyCode() == _KEY_CLEAR) { _Toolbar* pToolbar = GetFooter(); if (pToolbar == null) @@ -2551,6 +2565,27 @@ _Form::OnKeyReleased(const _Control& source, const _KeyInfo& keyInfo) { _FormImpl* pDataImpl = static_cast<_FormImpl*>(pData); pDataImpl->OnFormBackRequested(*this); + pDataImpl->OnFormBackButtonRequested(*this); + } + } + + return true; + } + if (keyInfo.GetKeyCode() == _KEY_CONTEXT_MENU) + { + _Toolbar* pToolbar = GetFooter(); + if (pToolbar == null) + { + return null; + } + + if (pToolbar->IsButtonSet(OPTION_BUTTON)) + { + void* pData = GetUserData(); + if (pData) + { + _FormImpl* pDataImpl = static_cast<_FormImpl*>(pData); + pDataImpl->OnFormOptionButtonRequested(*this); } } @@ -2704,6 +2739,10 @@ _Form::OnActionPerformed(const _Control& source, int actionId) { __pFormBackEventListener->OnFormBackRequested(*this); } + if (__pFormControlEventListener) + { + __pFormControlEventListener->OnFormBackButtonRequested(*this); + } } else { @@ -2719,6 +2758,12 @@ _Form::OnActionPerformed(const _Control& source, int actionId) } } break; + case ID_OPTION_BUTTON : + if (__pFormControlEventListener) + { + __pFormControlEventListener->OnFormOptionButtonRequested(*this); + } + break; default: break; diff --git a/src/ui/controls/FUiCtrl_FormImpl.cpp b/src/ui/controls/FUiCtrl_FormImpl.cpp index db0fdb3..aa4a0e9 100644 --- a/src/ui/controls/FUiCtrl_FormImpl.cpp +++ b/src/ui/controls/FUiCtrl_FormImpl.cpp @@ -100,6 +100,7 @@ _FormImpl::_FormImpl(Form* pPublic, _Form* pCore, Layout* pPublicPortraitLayout, : _ContainerImpl(pPublic, pCore, pPublicPortraitLayout, pPublicLandscapeLayout) , __pForm(null) , __pFormBackEventListener(null) + , __pFormControlEventListener(null) , __pOriAgent(null) , __pImeOriAgent(null) , __pLeftSoftkeyActionEvent(null) @@ -845,6 +846,16 @@ _FormImpl::SetFormBackEventListener(const IFormBackEventListener* pFormBackEvent } void +_FormImpl::SetFormControlEventListener(const IFormControlEventListener* pFormControlEventListener) +{ + SysTryReturnVoidResult(NID_UI_CTRL, GetFooter() || GetHeader(), E_INVALID_STATE, "[E_INVALID_STATE] Footer isn't constructed."); + __pFormControlEventListener = const_cast (pFormControlEventListener); + GetCore().SetFormBackEventListener(this); + result r = GetLastResult(); + SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r)); +} + +void _FormImpl::AddOrientationEventListener(IOrientationEventListener& listener) { if (__pOriAgent) @@ -1614,6 +1625,42 @@ _FormImpl::OnFormBackRequested(Tizen::Ui::Controls::_Form& source) } } +void +_FormImpl::OnFormBackButtonRequested(Tizen::Ui::Controls::_Form& source) +{ + if (__pFormControlEventListener) + { + _FormImpl* pFormImpl = static_cast<_FormImpl*>(source.GetUserData()); + Form* pForm = dynamic_cast (&pFormImpl->GetPublic()); + if (pForm) + { + __pFormControlEventListener->OnFormBackButtonRequested(*pForm); + } + else + { + return; + } + } +} + +void +_FormImpl::OnFormOptionButtonRequested(Tizen::Ui::Controls::_Form& source) +{ + if (__pFormControlEventListener) + { + _FormImpl* pFormImpl = static_cast<_FormImpl*>(source.GetUserData()); + Form* pForm = dynamic_cast (&pFormImpl->GetPublic()); + if (pForm) + { + __pFormControlEventListener->OnFormOptionButtonRequested(*pForm); + } + else + { + return; + } + } +} + OrientationStatus _FormImpl::OnFormOrientationStatusRequested(void) { diff --git a/src/ui/controls/FUiCtrl_OptionMenuImpl.cpp b/src/ui/controls/FUiCtrl_OptionMenuImpl.cpp index 3157d0c..80760a7 100644 --- a/src/ui/controls/FUiCtrl_OptionMenuImpl.cpp +++ b/src/ui/controls/FUiCtrl_OptionMenuImpl.cpp @@ -30,6 +30,8 @@ using namespace Tizen::Base; using namespace Tizen::Base::Runtime; using namespace Tizen::Ui; +const int MAX_ITEM_COUNT = 7; + namespace Tizen { namespace Ui { namespace Controls { @@ -45,7 +47,7 @@ _OptionMenuImpl::GetInstance(const OptionMenu& optionMenu) return static_cast(optionMenu._pControlImpl); } -_OptionMenuImpl::_OptionMenuImpl(OptionMenu* pPublic, _OptionMenu* pCore) +_OptionMenuImpl::_OptionMenuImpl(OptionMenu* pPublic, _ContextMenu* pCore) : _WindowImpl(pPublic, pCore) , __pPublicActionEvent(null) { @@ -56,9 +58,10 @@ _OptionMenuImpl::CreateOptionMenuImplN(OptionMenu& control) { ClearLastResult(); - _OptionMenu* pCore = _OptionMenu::CreateOptionMenuN(); + _ContextMenu* pCore = _ContextMenu::CreateContextMenuN(Tizen::Graphics::FloatPoint(-1,-1),CONTEXT_MENU_CORE_STYLE_LIST, CONTEXT_MENU_CORE_ALIGN_UP); result r = GetLastResult(); SysTryReturn(NID_UI_CTRL, (pCore != null), null, r, "[%s] Propagating.", GetErrorMessage(r)); + pCore->SetShowItemCount(MAX_ITEM_COUNT); _OptionMenuImpl* pImpl = new (std::nothrow) _OptionMenuImpl(&control, pCore); r = CheckConstruction(pCore, pImpl); @@ -109,8 +112,24 @@ _OptionMenuImpl::AddItem(const String& text, int actionId) { ClearLastResult(); - return GetCore().AddItem(text, actionId); + return GetCore().AddItem(text, actionId, null, null ,null); } +result +_OptionMenuImpl::AddItem(const Tizen::Graphics::Bitmap& normalBitmap, const Tizen::Graphics::Bitmap* pPressedBitmap, const Tizen::Graphics::Bitmap* pHighlightedBitmap, int actionId) +{ + ClearLastResult(); + + return GetCore().AddItem(L" ", actionId, &normalBitmap, pPressedBitmap, pHighlightedBitmap); +} + +result +_OptionMenuImpl::AddItem(const Tizen::Base::String &text, int actionId, const Tizen::Graphics::Bitmap& normalBitmap, const Tizen::Graphics::Bitmap* pPressedBitmap, const Tizen::Graphics::Bitmap* pHighlightedBitmap) +{ + ClearLastResult(); + + return GetCore().AddItem(text, actionId, &normalBitmap, pPressedBitmap, pHighlightedBitmap); +} + result _OptionMenuImpl::InsertItemAt(int mainIndex, const String& text, int actionId) @@ -119,7 +138,7 @@ _OptionMenuImpl::InsertItemAt(int mainIndex, const String& text, int actionId) SysTryReturn(NID_UI_CTRL, (mainIndex >= 0), E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The specified main index (%d) is negative.", mainIndex); - return GetCore().InsertItemAt(mainIndex, text, actionId); + return GetCore().InsertItem(mainIndex, text, actionId, null, null, null); } result @@ -129,7 +148,7 @@ _OptionMenuImpl::SetItemAt(int mainIndex, const String& text, int actionId) SysTryReturn(NID_UI_CTRL, (mainIndex >= 0), E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The specified main index (%d) is negative.", mainIndex); - return GetCore().SetItemAt(mainIndex, text, actionId); + return GetCore().SetItem(mainIndex, text, actionId, null, null, null); } result @@ -155,7 +174,7 @@ _OptionMenuImpl::GetItemIndexFromActionId(int actionId) const { ClearLastResult(); - return GetCore().GetItemIndexFromActionId(actionId); + return 0;//GetCore().GetItemIndexFromActionId(actionId); } int @@ -175,7 +194,7 @@ _OptionMenuImpl::AddSubItem(int mainIndex, const String& text, int actionId) SysTryReturn(NID_UI_CTRL, (mainIndex >= 0), E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The specified main index (%d) is negative.", mainIndex); - return GetCore().AddSubItem(mainIndex, text, actionId); + return E_SUCCESS;//GetCore().AddSubItem(mainIndex, text, actionId); } result @@ -187,7 +206,7 @@ _OptionMenuImpl::InsertSubItemAt(int mainIndex, int subIndex, const String& text SysTryReturn(NID_UI_CTRL, (subIndex >= 0), E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The specified sub index (%d) is negative.", subIndex); - return GetCore().InsertSubItemAt(mainIndex, subIndex, text, actionId); + return E_SUCCESS;//GetCore().InsertSubItemAt(mainIndex, subIndex, text, actionId); } result @@ -199,7 +218,7 @@ _OptionMenuImpl::SetSubItemAt(int mainIndex, int subIndex, const String& text, i SysTryReturn(NID_UI_CTRL, (subIndex >= 0), E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The specified sub index (%d) is negative.", subIndex); - return GetCore().SetSubItemAt(mainIndex, subIndex, text, actionId); + return E_SUCCESS;//GetCore().SetSubItemAt(mainIndex, subIndex, text, actionId); } result @@ -211,7 +230,7 @@ _OptionMenuImpl::RemoveSubItemAt(int mainIndex, int subIndex) SysTryReturn(NID_UI_CTRL, (subIndex >= 0), E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The specified sub index (%d) is negative.", subIndex); - return GetCore().RemoveSubItemAt(mainIndex, subIndex); + return E_SUCCESS;//GetCore().RemoveSubItemAt(mainIndex, subIndex); } int @@ -221,7 +240,7 @@ _OptionMenuImpl::GetSubItemCount(int mainIndex) const SysTryReturn(NID_UI_CTRL, (mainIndex >= 0), E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The specified main index (%d) is negative.", mainIndex); - return GetCore().GetSubItemCount(mainIndex); + return 0;//GetCore().GetSubItemCount(mainIndex); } int @@ -229,7 +248,7 @@ _OptionMenuImpl::GetSubItemIndexFromActionId(int actionId) const { ClearLastResult(); - return GetCore().GetSubItemIndexFromActionId(actionId); + return 0;//GetCore().GetSubItemIndexFromActionId(actionId); } int @@ -241,7 +260,7 @@ _OptionMenuImpl::GetSubItemActionIdAt(int mainIndex, int subIndex) const SysTryReturn(NID_UI_CTRL, (subIndex >= 0), E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The specified sub index (%d) is negative.", subIndex); - return GetCore().GetSubItemActionIdAt(mainIndex, subIndex); + return 0;//GetCore().GetSubItemActionIdAt(mainIndex, subIndex); } result @@ -272,16 +291,16 @@ _OptionMenuImpl::GetPublic(void) return static_cast (_ControlImpl::GetPublic()); } -const _OptionMenu& +const _ContextMenu& _OptionMenuImpl::GetCore(void) const { - return static_cast (_ControlImpl::GetCore()); + return static_cast (_ControlImpl::GetCore()); } -_OptionMenu& +_ContextMenu& _OptionMenuImpl::GetCore(void) { - return static_cast <_OptionMenu&>(_ControlImpl::GetCore()); + return static_cast <_ContextMenu&>(_ControlImpl::GetCore()); } void diff --git a/src/ui/controls/FUiCtrl_OptionMenuListPresenter.cpp b/src/ui/controls/FUiCtrl_OptionMenuListPresenter.cpp new file mode 100644 index 0000000..855f92b --- /dev/null +++ b/src/ui/controls/FUiCtrl_OptionMenuListPresenter.cpp @@ -0,0 +1,941 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0/ +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FUiCtrl_OptionMenuListPresenter.cpp + * @brief This is the implementation file for the _OptionMenuListPresenter class. + */ + +#include +#include +#include +#include +#include +#include "FUi_AccessibilityContainer.h" +#include "FUi_AccessibilityElement.h" +#include "FUi_CoordinateSystemUtils.h" +#include "FUi_Math.h" +#include "FUi_ResourceManager.h" +#include "FUiCtrl_ActionEvent.h" +#include "FUiCtrl_IActionEventListener.h" + +#include "FUiCtrl_OptionMenuListPresenter.h" + +using namespace Tizen::Graphics; +using namespace Tizen::Ui; +using namespace Tizen::Base; +using namespace Tizen::Base::Runtime; +using namespace Tizen::Graphics::_Text; + +const int MAX_MAIN_ITEM_COUNT = 12; + +namespace { +static const float TOUCH_PRESS_THRESHOLD_INSENSITIVE = 0.16f; +static const int CONTEXT_MENU_LIST_ELEMENT_TEXT = 0; +static const int CONTEXT_MENU_LIST_ELEMENT_BITMAP = 1; +} + +namespace Tizen { namespace Ui { namespace Controls +{ + +_OptionMenuListPresenter::_OptionMenuListPresenter(_ContextMenu* pContextMenu) + : __pContextMenu(pContextMenu) + , __pModel(null) + , __pFont(null) + , __layoutSize(FloatDimension(0.0f, 0.0f)) + , __touchOutRect(false) + , __selectedIndex(-1) + , __scrollEnable(false) + , __maxWidth(0.0f) + , __minWidth(0.0f) + , __topMargin(0.0f) + , __bottomMargin(0.0f) + , __leftMargin(0.0f) + , __rightMargin(0.0f) + , __screenTopMargin(0.0f) + , __screenBottomMargin(0.0f) + , __screenLeftMargin(0.0f) + , __screenRightMargin(0.0f) + , __arrowTopMargin(0.0f) + , __arrowBottomMargin(0.0f) + , __arrowRightMargin(0.0f) + , __arrowLeftMargin(0.0f) + , __arrowWidth(0.0f) + , __arrowHeight(0.0f) + , __itemWidth(0.0f) + , __itemMinWidth(0.0f) + , __itemHeight(0.0f) + , __itemMaxWidth(0.0f) + , __itemGap(0.0f) + , __itemBitmapWidth(0.0f) + , __itemBitmapHeight(0.0f) + , __itemFontSize(0.0f) + , __dividerHeight(0.0f) + , __anchorPopupOverlap(0.0f) +{ + +} + +_OptionMenuListPresenter::~_OptionMenuListPresenter(void) +{ + __pContextMenu = null; + + delete __pModel; + __pModel = null; + + __pFont = null; + +} + +result +_OptionMenuListPresenter::Install(void) +{ + result r = E_SUCCESS; + + LoadShape(); + + __pModel = new (std::nothrow) _ContextMenuModel; + SysTryCatch(NID_UI_CTRL, __pModel != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage."); + + r = __pModel->Construct(); + SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Unable to create data instance."); + + __pFont = __pContextMenu->GetFallbackFont(); + r = GetLastResult(); + SysTryCatch(NID_UI_CTRL, (__pFont != null), , r, "[%s] Propagating.", GetErrorMessage(r)); + + return r; + +CATCH: + delete __pModel; + __pModel = null; + + __pFont = null; + + return r; +} + + +void +_OptionMenuListPresenter::LoadShape(void) +{ + GET_SHAPE_CONFIG(CONTEXTMENU::LIST_MIN_WIDTH, _CONTROL_ORIENTATION_PORTRAIT, __itemMinWidth); + GET_SHAPE_CONFIG(CONTEXTMENU::LIST_MAX_WIDTH, _CONTROL_ORIENTATION_PORTRAIT, __itemMaxWidth); + GET_SHAPE_CONFIG(CONTEXTMENU::LIST_ITEM_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, __itemHeight); + GET_SHAPE_CONFIG(CONTEXTMENU::LIST_ITEM_GAP, _CONTROL_ORIENTATION_PORTRAIT, __itemGap); + + GET_SHAPE_CONFIG(CONTEXTMENU::LIST_TOP_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, __topMargin); + GET_SHAPE_CONFIG(CONTEXTMENU::LIST_BOTTOM_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, __bottomMargin); + GET_SHAPE_CONFIG(CONTEXTMENU::LIST_LEFT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, __leftMargin); + GET_SHAPE_CONFIG(CONTEXTMENU::LIST_RIGHT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, __rightMargin); + + GET_SHAPE_CONFIG(CONTEXTMENU::SCREEN_TOP_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, __screenTopMargin); + GET_SHAPE_CONFIG(CONTEXTMENU::SCREEN_BOTTOM_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, __screenBottomMargin); + GET_SHAPE_CONFIG(CONTEXTMENU::SCREEN_LEFT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, __screenLeftMargin); + GET_SHAPE_CONFIG(CONTEXTMENU::SCREEN_RIGHT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, __screenRightMargin); + GET_SHAPE_CONFIG(CONTEXTMENU::ANCHOR_TOP_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, __arrowTopMargin); + GET_SHAPE_CONFIG(CONTEXTMENU::ANCHOR_BOTTOM_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, __arrowBottomMargin); + GET_SHAPE_CONFIG(CONTEXTMENU::ANCHOR_LEFT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, __arrowLeftMargin); + GET_SHAPE_CONFIG(CONTEXTMENU::ANCHOR_RIGHT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, __arrowRightMargin); + GET_SHAPE_CONFIG(CONTEXTMENU::ANCHOR_WIDTH, _CONTROL_ORIENTATION_PORTRAIT, __arrowWidth); + GET_SHAPE_CONFIG(CONTEXTMENU::ANCHOR_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, __arrowHeight); + GET_SHAPE_CONFIG(CONTEXTMENU::LIST_ICON_WIDTH, _CONTROL_ORIENTATION_PORTRAIT, __itemBitmapWidth); + GET_SHAPE_CONFIG(CONTEXTMENU::LIST_ICON_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, __itemBitmapHeight); + + GET_SHAPE_CONFIG(CONTEXTMENU::LIST_ITEM_FONT_SIZE, _CONTROL_ORIENTATION_PORTRAIT, __itemFontSize); + GET_SHAPE_CONFIG(CONTEXTMENU::LIST_DIVIDER_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, __dividerHeight); + GET_SHAPE_CONFIG(CONTEXTMENU::ANCHOR_POPUP_OVERLAP, _CONTROL_ORIENTATION_PORTRAIT, __anchorPopupOverlap); + + __itemWidth = __itemMinWidth; +} + +_ContextMenuItem* +_OptionMenuListPresenter::CreateItem(const Base::String& text, int actionId, const Tizen::Graphics::Bitmap* pNormalBitmap, const Tizen::Graphics::Bitmap* pPressedBitmap, const Tizen::Graphics::Bitmap* pHighlightedBitmap) +{ + _ContextMenuItem* pItem = _ContextMenuItem::CreateContextMenuItemN(); + SysTryReturn(NID_UI_CTRL, pItem != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient."); + + ContextMenuItemDrawingType itemType = CONTEXT_MENU_ITEM_DRAWING_TYPE_TEXT; + _Label* pLabel = null; + result r = E_SUCCESS; + + if (pNormalBitmap != null) + { + r = pItem->SetBitmap(CONTEXT_MENU_ITEM_DRAWING_STATUS_NORMAL, pNormalBitmap); + if (r != E_SUCCESS) + { + delete pItem; + return null; + } + + // add bitmap label + pLabel = _Label::CreateLabelN(); + pLabel->SetBackgroundBitmap(*pNormalBitmap); + pLabel->SetBackgroundColor(Color(0, 0, 0, 0)); + + int bitmapY = (__itemHeight - __itemBitmapHeight ) / 2; + pLabel->SetBounds(FloatRectangle(__leftMargin, bitmapY, __itemBitmapWidth, __itemBitmapHeight)); + pLabel->SetTouchPressThreshold(TOUCH_PRESS_THRESHOLD_INSENSITIVE); + pItem->AttachChild(*pLabel); + _AccessibilityContainer* pContainer = pLabel->GetAccessibilityContainer(); + if (pContainer) + { + pContainer->Activate(false); + } + pItem->SetBitmapLabel(pLabel); + + itemType = CONTEXT_MENU_ITEM_DRAWING_TYPE_BITMAP; + } + + if (pPressedBitmap != null) + { + r = pItem->SetBitmap(CONTEXT_MENU_ITEM_DRAWING_STATUS_PRESSED, pPressedBitmap); + if (r != E_SUCCESS) + { + delete pItem; + return null; + } + } + + pItem->SetType(itemType); + pItem->SetActionId(actionId); + + pItem->SetTextSize(__itemFontSize); + r = pItem->SetText(text); + if (r != E_SUCCESS) + { + delete pItem; + return null; + } + + // calculate item size + float bitmapWidth = (itemType == CONTEXT_MENU_ITEM_DRAWING_TYPE_BITMAP) ? __itemBitmapWidth : 0.0f; + + FloatDimension textArea(0.0f, 0.0f); + FloatDimension itemSize(0.0f, 0.0f); + + __pFont->GetTextExtent(text, text.GetLength(), textArea); + float labelLeftMargin = 0.0f, labelTopMargin = 0.0f; + GET_SHAPE_CONFIG(LABEL::LEFT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, labelLeftMargin); + GET_SHAPE_CONFIG(LABEL::TOP_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, labelTopMargin); + textArea.width += 2.0f * labelLeftMargin; + textArea.height += 2.0f * labelTopMargin; + itemSize.height = __itemHeight + (__dividerHeight * 2.0f); + itemSize.width = __leftMargin + textArea.width + __rightMargin + bitmapWidth; + + itemSize.width = itemSize.width < __itemMinWidth ? __itemMinWidth : itemSize.width; + + if (itemSize.width > __itemMaxWidth) + { + textArea.width -= itemSize.width - __itemMaxWidth; + itemSize.width = __itemMaxWidth; + } + + pItem->SetSize(itemSize); + + // add text label + float textLabelX = __leftMargin + bitmapWidth; + + pLabel = _Label::CreateLabelN(); + pLabel->SetText(text); + ContextMenuCoreItemStatus itemStatus = CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL; + pLabel->SetTextColor(__pContextMenu->GetTextColor(itemStatus)); + pLabel->SetBackgroundColor(Color(0, 0, 0, 0)); + + itemSize = pItem->GetSize(); + pLabel->SetBounds(FloatRectangle(textLabelX, (itemSize.height - textArea.height) / 2.0f, textArea.width, textArea.height)); + pLabel->SetTextVerticalAlignment(ALIGNMENT_MIDDLE); + pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT); + pLabel->SetTextConfig(__itemFontSize, LABEL_TEXT_STYLE_NORMAL); + + pLabel->SetTouchPressThreshold(TOUCH_PRESS_THRESHOLD_INSENSITIVE); + pItem->AttachChild(*pLabel); + _AccessibilityContainer* pContainer = pLabel->GetAccessibilityContainer(); + if (pContainer) + { + pContainer->Activate(false); + } + pItem->SetTextLabel(pLabel); + + __itemWidth = __itemWidth < itemSize.width ? itemSize.width : __itemWidth; + + pItem->SetTouchPressThreshold(TOUCH_PRESS_THRESHOLD_INSENSITIVE); + return pItem; +} + +result +_OptionMenuListPresenter::AddItem(const Base::String& text, int actionId, const Tizen::Graphics::Bitmap* normalBitmap, + const Tizen::Graphics::Bitmap* pPressedBitmap, + const Tizen::Graphics::Bitmap* pHighlightedBitmap) +{ + SysTryReturn(NID_UI_CTRL, (__pModel->GetItemCount() < MAX_MAIN_ITEM_COUNT), E_SYSTEM, E_SYSTEM, + "[E_SYSTEM] A system error has occurred. The maximum items count is reached."); + _ContextMenuItem* pItem = CreateItem(text, actionId, normalBitmap, pPressedBitmap, pHighlightedBitmap); + SysTryReturn(NID_UI_CTRL, pItem != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "The memory is insufficient."); + + result r = __pModel->AddItem(pItem); + + if (r != E_SUCCESS) + { + delete pItem; + SysTryReturn(NID_UI_CTRL, false, r, r, "Failed to add item."); + } + + return r; +} + +result +_OptionMenuListPresenter::InsertItem(int index, const Tizen::Base::String& text, int actionId, + const Tizen::Graphics::Bitmap* normalBitmap, const Tizen::Graphics::Bitmap* pPressedBitmap, + const Tizen::Graphics::Bitmap* pHighlightedBitmap) +{ + if (text.GetLength() == 0 && normalBitmap == null && pPressedBitmap == null) + { + return E_INVALID_ARG; + } + + _ContextMenuItem* pItem = null; + + pItem = CreateItem(text, actionId, normalBitmap, pPressedBitmap, pHighlightedBitmap); + SysTryReturn(NID_UI_CTRL, pItem != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "The memory is insufficient."); + + result r = __pModel->InsertItem(pItem, index); + if (r != E_SUCCESS) + { + delete pItem; + SysTryReturn(NID_UI_CTRL, false, r, r, "Failed to add item."); + } + + return E_SUCCESS; +} + +result +_OptionMenuListPresenter::SetItem(int index, const Tizen::Base::String& text, int actionId, + const Tizen::Graphics::Bitmap* normalBitmap, const Tizen::Graphics::Bitmap* pPressedBitmap, + const Tizen::Graphics::Bitmap* pHighlightedBitmap) +{ + if (text.GetLength() == 0 && normalBitmap == null && pPressedBitmap == null) + { + return E_INVALID_ARG; + } + + result r = __pContextMenu->GetScrollPanel()->DetachChild(*__pModel->GetItem(index)); + SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to detach item."); + + _ContextMenuItem* pItem = null; + pItem = CreateItem(text, actionId, normalBitmap, pPressedBitmap, pHighlightedBitmap); + SysTryReturn(NID_UI_CTRL, pItem != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "The memory is insufficient."); + + r = __pModel->SetItem(pItem, index); + if (r != E_SUCCESS) + { + delete pItem; + SysTryReturn(NID_UI_CTRL, false, r, r, "Failed to add item."); + } + + return E_SUCCESS; +} + +result +_OptionMenuListPresenter::DeleteItem(int index) +{ + if (__pContextMenu->GetItemCount() <= 0) + { + SysLogException(NID_UI_CTRL, E_INVALID_STATE, "Invalid argument."); + return E_INVALID_STATE; + } + + result r = __pContextMenu->GetScrollPanel()->DetachChild(*__pModel->GetItem(index)); + SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to detach item."); + + r = __pModel->RemoveItem(index); + SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to delete item."); + + return r; +} + +result +_OptionMenuListPresenter::DeleteItemAll(void) +{ + if (__pContextMenu->GetItemCount() <= 0) + { + SysLogException(NID_UI_CTRL, E_INVALID_STATE, "Invalid argument."); + return E_INVALID_STATE; + } + + __pContextMenu->GetScrollPanel()->DetachAllChildren(); + + result r = __pModel->RemoveAllItem(); + SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to delete item all."); + + return r; +} + + +int +_OptionMenuListPresenter::CalculateShowItemCount(void) +{ + int itemMaxCount = 0; + _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation(); + GET_SHAPE_CONFIG(CONTEXTMENU::ITEM_MAX_COUNT, orientation, itemMaxCount); + + int maxVisibleCount = __pContextMenu->GetShowItemCount(); + + return maxVisibleCount > itemMaxCount ? itemMaxCount : maxVisibleCount; +} + +result +_OptionMenuListPresenter::CalculateWindowRect(void) +{ + result r = CalculateRect(); + AdjustItemPosition(); + + return r; +} + +result +_OptionMenuListPresenter::ApplyColorProperty(void) +{ + return E_SUCCESS; +} + + +result +_OptionMenuListPresenter::CalculateRect(void) +{ + Tizen::Graphics::FloatRectangle windowRect = Tizen::Graphics::FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f); // ContextMenu window itself + Tizen::Graphics::FloatRectangle bodyRect = Tizen::Graphics::FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f); // bg surronding showing items, relative to window + Tizen::Graphics::FloatRectangle arrowRect = Tizen::Graphics::FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f); // relative to window + Tizen::Graphics::FloatRectangle itemRect = Tizen::Graphics::FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f); // relative to window + + float bodyTopMargin = __topMargin; + float bodyBottomMargin = __bottomMargin; + float bodyLeftMargin = __leftMargin; + float bodyRightMargin = __rightMargin; + + + FloatDimension screen = _ControlManager::GetInstance()->GetScreenSizeF(); + + if (__pContextMenu->GetLayout() == _CONTROL_ORIENTATION_LANDSCAPE) + { + screen.SetSize(screen.height, screen.width); + } + + // calculate layout size (__layoutSize) + AdjustItemLayout(); + + bodyRect.width = __layoutSize.width + bodyLeftMargin + bodyRightMargin; + bodyRect.height = __layoutSize.height + bodyTopMargin + bodyBottomMargin; + + bodyRect.x = 0; + // Set body position y + bodyRect.y = screen.height - bodyRect.height; + // - check top margin + + + float correctLength = __arrowTopMargin - __anchorPopupOverlap; + windowRect.x = bodyRect.x; + windowRect.y = bodyRect.y; + windowRect.width = bodyRect.width; + windowRect.height = bodyRect.height; + + bodyRect.x = 0.0f; + bodyRect.y = 0.0f; + + + if (_ControlManager::GetInstance()->GetOrientationStatus() == _CONTROL_ROTATION_270) + { + windowRect.x = screen.width - bodyRect.width; + } + + itemRect.x = bodyRect.x; + itemRect.y = bodyRect.y; + itemRect.width = __layoutSize.width; + itemRect.height = __layoutSize.height; + + __pContextMenu->SetWindowRect(windowRect); + __pContextMenu->SetBodyRect(bodyRect); + __pContextMenu->SetArrowRect(arrowRect); + __pContextMenu->SetItemRect(itemRect); + + // _ScrollPanel API call sequence: SetBounds() -> SetScrollAreaBounds() + // _Scroll visual interaction if Bounds < ScrollAreaBounds + if (__pContextMenu->IsVisible()) + { + __pContextMenu->GetScrollPanel()->SetBounds(FloatRectangle(bodyRect.x + bodyLeftMargin, bodyRect.y + bodyTopMargin, __layoutSize.width, __layoutSize.height)); + int itemCount = __pModel->GetItemCount(); + float itemHeight = __itemHeight + (__dividerHeight * 2.0f); + float layoutClientHeight = itemCount * itemHeight - (__dividerHeight * 2.0f); + __pContextMenu->GetScrollPanel()->SetClientAreaHeight(layoutClientHeight); + } + + __pContextMenu->SetMovable(true); + __pContextMenu->SetResizable(true); + + __pContextMenu->SetMinimumSize(FloatDimension(0.0f, 0.0f)); + __pContextMenu->SetMaximumSize(screen); + __pContextMenu->SetBounds(windowRect); + + __pContextMenu->SetMovable(false); + __pContextMenu->SetResizable(false); + + return E_SUCCESS; +} + +void +_OptionMenuListPresenter::AdjustItemLayout(void) +{ + FloatDimension layoutSize(0.0f, 0.0f); + + int itemCount = __pModel->GetItemCount(); + if (itemCount <= 0) + { + __layoutSize.width = __itemWidth; + __layoutSize.height = __itemHeight; + return; + } + + layoutSize = AdjustItemLayoutStyle(); + + FloatDimension screen = _ControlManager::GetInstance()->GetScreenSizeF(); + if (__pContextMenu->GetLayout() == _CONTROL_ORIENTATION_LANDSCAPE) + { + screen.SetSize(screen.height, screen.width); + } + + int maxHeight = screen.height;// - __screenTopMargin - __screenBottomMargin - __arrowHeight; + if (layoutSize.height > maxHeight) + { + layoutSize.height = maxHeight; + } + + __layoutSize = layoutSize; +} + + +Tizen::Graphics::FloatDimension +_OptionMenuListPresenter::AdjustItemLayoutStyle(void) +{ + int itemMaxCount = CalculateShowItemCount(); + + int itemCount = __pModel->GetItemCount(); + float itemHeight = __itemHeight + (__dividerHeight * 2.0f); + + FloatDimension layoutSize(__itemWidth, 0.0f); + + float layoutClientHeight = itemCount * itemHeight - (__dividerHeight * 2.0f); + float layoutMaxHeight = itemMaxCount * itemHeight - (__dividerHeight * 2.0f); + if (layoutClientHeight > layoutMaxHeight) + { + __scrollEnable = true; + layoutSize.height = layoutMaxHeight; + } + else + { + __scrollEnable = false; + layoutSize.height = layoutClientHeight; + } + + return layoutSize; +} + +void +_OptionMenuListPresenter::AdjustItemPosition(void) +{ + int itemCount = __pModel->GetItemCount(); + if (itemCount <= 0) + { + return; + } + + float itemHeight = __itemHeight + (__dividerHeight * 2.0f); + float drawItemY = 0.0f; + + float x = __pContextMenu->GetBodyRect().x; + float y = __pContextMenu->GetBodyRect().y ; + + _ContextMenuItem* pItem = null; + + for (int i = 0; i < itemCount; i++) + { + pItem = __pModel->GetItem(i); + + if (pItem == null) + { + break; + } + + FloatRectangle drawRect(x, drawItemY + y, __itemWidth, itemHeight); + + pItem->SetDrawRect(drawRect); + pItem->SetUpperDivider(i > 0); + pItem->SetLowerDivider(i < itemCount - 1); + pItem->SetParentScrollEnable(__scrollEnable); + pItem->SetBounds(FloatRectangle(0.0f, drawItemY, drawRect.width, drawRect.height)); + + if (pItem->HasParent() == false) + { + __pContextMenu->GetScrollPanel()->AttachChild(*pItem); + } + + drawItemY += itemHeight; + } +} + +int +_OptionMenuListPresenter::GetItemIndexFromPosition(const Tizen::Graphics::FloatPoint& point) const +{ + int index = -1; + int itemCount = __pModel->GetItemCount(); + + if (itemCount < 0) + { + return -1; + } + + _ContextMenuItem* pItem = null; + + float scrollPosition = __pContextMenu->GetScrollPanel()->GetScrollPosition(); + FloatPoint position(point.x, point.y + scrollPosition); + + for (int i = 0; i < itemCount; i++) + { + pItem = __pModel->GetItem(i); + + if (pItem == null) + { + break; + } + + FloatRectangle drawRect = pItem->GetDrawRect(); + + if (drawRect.Contains(position) == true) + { + index = i; + break; + } + } + + return index; +} + + +result +_OptionMenuListPresenter::Draw(void) +{ + result r = E_SUCCESS; + + Canvas* pCanvas = __pContextMenu->GetCanvasN(); + SysTryReturn(NID_UI_CTRL, pCanvas != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "The memory is insufficient."); + + // Clear canvas for drawing area of the ContextMenu. + pCanvas->SetBackgroundColor(Color(0, 0, 0, 0)); + Tizen::Graphics::FloatRectangle bounds(__pContextMenu->GetWindowRect()); + pCanvas->Clear(Tizen::Graphics::FloatRectangle(0.0f, 0.0f, bounds.width, bounds.height)); + + r = DrawBackground(pCanvas); + SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to draw background."); + + //r = DrawArrow(pCanvas); + //SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to draw arrow."); + + delete pCanvas; + + return r; +} + +result +_OptionMenuListPresenter::DrawBackground(Canvas* pCanvas) +{ + SysTryReturn(NID_UI_CTRL, pCanvas != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient."); + + result r = E_SUCCESS; + + Tizen::Graphics::FloatRectangle bodyRect = __pContextMenu->GetBodyRect(); + + const Bitmap* pBackgroundNormalBitmap = __pContextMenu->GetBackgroundNormalBitmap(); + const Bitmap* pBackgroundEffectBitmap = __pContextMenu->GetBackgroundEffectBitmap(); + + if (pBackgroundNormalBitmap == null && pBackgroundEffectBitmap == null) + { + pCanvas->SetForegroundColor(__pContextMenu->GetColor()); + pCanvas->DrawRectangle(bodyRect); + } + else + { + if (pBackgroundNormalBitmap != null) + { + r = DrawBitmap(*pCanvas, bodyRect, *pBackgroundNormalBitmap); + } + + if (pBackgroundEffectBitmap != null) + { + r = DrawBitmap(*pCanvas, bodyRect, *pBackgroundEffectBitmap); + } + } + + return r; +} + + +result +_OptionMenuListPresenter::DrawArrow(Canvas* pCanvas) +{ + SysTryReturn(NID_UI_CTRL, pCanvas != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient."); + + result r = E_SUCCESS; + Tizen::Graphics::FloatRectangle arrowRect = __pContextMenu->GetArrowRect(); + ContextMenuCoreDropPosition dropPosition = __pContextMenu->GetDropPosition(); + + const Bitmap* pArrowNormalBitmap = __pContextMenu->GetArrowNormalBitmap(dropPosition); + const Bitmap* pEffectArrowBitmap = __pContextMenu->GetArrowEffectBitmap(dropPosition); + + if (pArrowNormalBitmap != null) + { + r = DrawBitmap(*pCanvas, arrowRect, *pArrowNormalBitmap); + } + + if (pEffectArrowBitmap != null) + { + r = DrawBitmap(*pCanvas, arrowRect, *pEffectArrowBitmap); + } + + return r; +} + +_UiTouchEventDelivery +_OptionMenuListPresenter::OnPreviewTouchPressed(const _Control& source, const _TouchInfo& touchinfo) +{ + return _UI_TOUCH_EVENT_DELIVERY_FORCED_YES; +} + +bool +_OptionMenuListPresenter::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo) +{ + FloatPoint touchPosition = touchinfo.GetCurrentPosition(); + FloatRectangle itemRect = __pContextMenu->GetItemRect(); + + if (!itemRect.Contains(touchPosition)) + { + __selectedIndex = -1; + __touchOutRect = true; + return true; + } + + __selectedIndex = GetItemIndexFromPosition(touchPosition); + __touchOutRect = false; + return true; +} + +_UiTouchEventDelivery +_OptionMenuListPresenter::OnPreviewTouchReleased(const _Control& source, const _TouchInfo& touchinfo) +{ + return _UI_TOUCH_EVENT_DELIVERY_FORCED_YES; +} + +bool +_OptionMenuListPresenter::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo) +{ + FloatPoint touchPosition = touchinfo.GetCurrentPosition(); + + if (__touchOutRect) + { + FloatRectangle itemRect = __pContextMenu->GetItemRect(); + if (!itemRect.Contains(touchPosition)) + { + __selectedIndex = -1; + __pContextMenu->SetVisibleState(false); + + return true; + } + } + + int currentSelectedIndex = GetItemIndexFromPosition(touchPosition); + if (__selectedIndex != -1 && (__selectedIndex == currentSelectedIndex)) + { + _ContextMenuItem* pItem = null; + pItem = __pModel->GetItem(__selectedIndex); + + __selectedIndex = -1; + __pContextMenu->SetVisibleState(false); + + int actionId = pItem->GetActionId(); + + _ActionEvent* pActionEvent = __pContextMenu->GetActionEvent(); + if (pActionEvent == null) + { + return true; + } + + IEventArg* pEventArg = _ActionEvent::CreateActionEventArgN(actionId); + if (pEventArg == null) + { + return true; + } + + PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_TAP); + pActionEvent->Fire(*pEventArg); + } + + return true; +} + +_UiTouchEventDelivery +_OptionMenuListPresenter::OnPreviewTouchMoved(const _Control& source, const _TouchInfo& touchinfo) +{ + return _UI_TOUCH_EVENT_DELIVERY_FORCED_YES; +} + +bool +_OptionMenuListPresenter::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo) +{ + if (__scrollEnable) + { + __selectedIndex = -1; + } + + return true; +} + +bool +_OptionMenuListPresenter::OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo) +{ + __pModel->ResetAllItem(); + + return true; +} + +void +_OptionMenuListPresenter::OnFontChanged(Tizen::Graphics::Font* pFont) +{ + __pFont = pFont; + String fontName = __pContextMenu->GetFont(); + + int itemCount = __pModel->GetItemCount(); + for (int i = 0; i < itemCount; i++) + { + _ContextMenuItem* pItem = __pModel->GetItem(i); + if (pItem != null) + { + pItem->SetFont(fontName); + } + } +} + +void +_OptionMenuListPresenter::OnFontInfoRequested(unsigned long& style, float& size) +{ + style = FONT_STYLE_PLAIN; + size = __itemFontSize; +} + +void +_OptionMenuListPresenter::SetAllAccessibilityElement(void) +{ + _AccessibilityContainer* pContainerContextMenu = __pContextMenu->GetAccessibilityContainer(); + if (pContainerContextMenu != null) + { + _AccessibilityElement* pElementContextMenu = new (std::nothrow) _AccessibilityElement(true); + SysTryReturnVoidResult(NID_UI_CTRL, pElementContextMenu, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage."); + + pElementContextMenu->SetSupportOperatingGesture(false); + pElementContextMenu->SetTrait(L"Contextual popup"); + pElementContextMenu->SetHint(L"double tap to close"); + pElementContextMenu->SetBounds(FloatRectangle(0.0f, 0.0f, __pContextMenu->GetBoundsF().width, __pContextMenu->GetBoundsF().height)); + pContainerContextMenu->AddElement(*pElementContextMenu); + __pContextMenu->AddAccessibilityElement(*pElementContextMenu); + + int itemCount = __pModel->GetItemCount(); + for (int i = 0; i < itemCount; i++) + { + _ContextMenuItem* pItem = __pModel->GetItem(i); + if (pItem) + { + _AccessibilityContainer* pContainer = pItem->GetAccessibilityContainer(); + if (pContainer != null) + { + LinkedListT<_AccessibilityElement*> accessibilityElements; + _AccessibilityElement* pElement = null; + + pContainer->GetElements(accessibilityElements); + if (accessibilityElements.GetAt(0, pElement) == E_SUCCESS) + { + pElement->SetName(L"ContextMenuItem" + Integer::ToString(i)); + if (pItem->GetType() == CONTEXT_MENU_ITEM_DRAWING_TYPE_BITMAP) + { + pElement->SetLabel(L"icon " + pItem->GetText()); + } + else + { + pElement->SetLabel(pItem->GetText()); + } + + pElement->SetBounds(FloatRectangle(0.0f, 0.0f, pItem->GetBoundsF().width, pItem->GetBoundsF().height)); + } + pContainerContextMenu->AddChildContainer(*pContainer); + } + } + } + } +} + +_ContextMenuItemInfo +_OptionMenuListPresenter::GetItemFromPosition(const FloatPoint& position) +{ + _ContextMenuItemInfo itemInfo; + int index = GetItemIndexFromPosition(position); + itemInfo.pContextMenuItem = __pModel->GetItem(index); + + itemInfo.bListItem = false; + itemInfo.pListItem = null; + return itemInfo; +} + +_ContextMenuItemInfo +_OptionMenuListPresenter::FindItem(int index) +{ + _ContextMenuItemInfo itemInfo; + itemInfo.bListItem = false; + itemInfo.pListItem = null; + itemInfo.pContextMenuItem = __pModel->GetItem(index); + return itemInfo; +} + +result +_OptionMenuListPresenter::SetTopDrawnItemIndex(int index) +{ + return E_SUCCESS; +} + +result +_OptionMenuListPresenter::DrawBitmap(Tizen::Graphics::Canvas& canvas, const Tizen::Graphics::FloatRectangle& bounds, const Tizen::Graphics::Bitmap& bitmap) +{ + result r = E_SUCCESS; + if (_BitmapImpl::CheckNinePatchedBitmapStrictly(bitmap)) + { + r = canvas.DrawNinePatchedBitmap(bounds, bitmap); + SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Fail to draw ninepatched bitmap.") + } + else + { + r = canvas.DrawBitmap(bounds, bitmap); + SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Fail to draw bitmap.") + } + + return r; +} + +}}} // Tizen::Ui: Control diff --git a/src/ui/inc/FUiCtrl_ContextMenu.h b/src/ui/inc/FUiCtrl_ContextMenu.h index c7631c5..fd888d0 100644 --- a/src/ui/inc/FUiCtrl_ContextMenu.h +++ b/src/ui/inc/FUiCtrl_ContextMenu.h @@ -29,6 +29,7 @@ #include "FUiCtrl_IContextMenuPresenter.h" #include "FUiCtrl_ContextMenuGridPresenter.h" #include "FUiCtrl_ContextMenuListPresenter.h" +#include "FUiCtrl_OptionMenuListPresenter.h" #include "FUiCtrl_ActionEvent.h" #include "FUiCtrl_IActionEventListener.h" diff --git a/src/ui/inc/FUiCtrl_Form.h b/src/ui/inc/FUiCtrl_Form.h index 82de4b8..777f1e8 100644 --- a/src/ui/inc/FUiCtrl_Form.h +++ b/src/ui/inc/FUiCtrl_Form.h @@ -42,6 +42,7 @@ class _Indicator; class _ActionEvent; class _OverlayRegionImpl; class _IFormBackEventListener; +class _IFormControlEventListener; enum _FormStyle { @@ -97,6 +98,7 @@ public: static _Form* CreateFormN(void); void SetFormBackEventListener(_IFormBackEventListener* pFormBackEventListener); + void SetFormControlEventListener(_IFormControlEventListener* pFormControlEventListener); unsigned long GetFormStyle(void) const; _Toolbar* GetFooter(void) const; @@ -242,6 +244,7 @@ private: private: _FormPresenter* __pFormPresenter; _IFormBackEventListener* __pFormBackEventListener; + _IFormControlEventListener* __pFormControlEventListener; unsigned long __formStyle; _ActionEvent* __pActionEvent; @@ -299,6 +302,7 @@ private: //Back button action ID static const int ID_BACK_BUTTON = -10; + static const int ID_OPTION_BUTTON = -20; //For Focus UI mutable std::unique_ptr > __pFocusControlList; diff --git a/src/ui/inc/FUiCtrl_FormImpl.h b/src/ui/inc/FUiCtrl_FormImpl.h index 9e11488..a5cb326 100644 --- a/src/ui/inc/FUiCtrl_FormImpl.h +++ b/src/ui/inc/FUiCtrl_FormImpl.h @@ -21,6 +21,7 @@ #include "FUi_ContainerImpl.h" #include "FUiCtrl_Form.h" #include "FUiCtrl_IFormBackEventListener.h" +#include "FUiCtrl_IFormControlEventListener.h" namespace Tizen { namespace Ui { class DataBindingContext; @@ -39,6 +40,7 @@ class _OSP_EXPORT_ _FormImpl : public _ContainerImpl , public Tizen::Ui::Controls::_IActionEventListener , public Tizen::Ui::Controls::_IFormBackEventListener + , public Tizen::Ui::Controls::_IFormControlEventListener , virtual public Tizen::Base::Runtime::IEventListener , public _IFormOrientationStatusEventListener { @@ -65,6 +67,7 @@ public: _ControlImpl* GetFocusControl(void); void SetFormBackEventListener(const IFormBackEventListener* pFormBackEventListener); + void SetFormControlEventListener(const IFormControlEventListener* pFormControlEventListener); unsigned long GetFormStyle(void) const; _FooterImpl* GetFooter(void) const; @@ -145,6 +148,8 @@ public: virtual bool IsOpaque(void) const; virtual void OnFormBackRequested(Tizen::Ui::Controls::_Form& source); + virtual void OnFormBackButtonRequested(Tizen::Ui::Controls::_Form& source); + virtual void OnFormOptionButtonRequested(Tizen::Ui::Controls::_Form& source); virtual Tizen::Ui::OrientationStatus OnFormOrientationStatusRequested(void); @@ -175,6 +180,7 @@ private: private: _Form* __pForm; IFormBackEventListener* __pFormBackEventListener; + IFormControlEventListener* __pFormControlEventListener; Tizen::Ui::_OrientationAgent* __pOriAgent; Tizen::Ui::_ImeOrientationAgent* __pImeOriAgent; diff --git a/src/ui/inc/FUiCtrl_IFormControlEventListener.h b/src/ui/inc/FUiCtrl_IFormControlEventListener.h new file mode 100644 index 0000000..80cf1e6 --- /dev/null +++ b/src/ui/inc/FUiCtrl_IFormControlEventListener.h @@ -0,0 +1,107 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0/ +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FUiCtrl_IFormControlEventListener.h + * @brief This is the header file for the _IFormControlEventListener interface. + * + * This header file contains the declarations of the _IFormControlEventListener interface. + */ +#ifndef _FUI_CTRL_INTERNAL_IFORM_CONTROL_EVENT_LISTENER_H_ +#define _FUI_CTRL_INTERNAL_IFORM_CONTROL_EVENT_LISTENER_H_ + +// includes +#include + +// namespace declaration +namespace Tizen { namespace Ui { namespace Controls +{ + +class _Form; + +/** + * @interface _IFormControlEventListener + * @brief This interface implements the listener for Form related events. + * @since 2.0 + * + * The %_IFormControlEventListener interface is the listener interface for receiving Form-related events. + * + * For more information on the class features, see Form. + */ +class _IFormControlEventListener + : virtual public Tizen::Base::Runtime::IEventListener +{ +// Lifecycle +public: + /** + * This is the destructor for this class. + * @since 2.0 + */ + virtual ~_IFormControlEventListener(void) {} + +// Operation +public: + /** + * Called when the current %Form control needs to be closed to revert back to the previous %Form control. + * + * @since 2.0 + * @param[in] source The source of the event + * @remarks This event is fired when the user clicks on the software 'back' button on the Footer control, or the hardware back button on the + * device. + */ + virtual void OnFormBackButtonRequested(Tizen::Ui::Controls::_Form& source) = 0; + + virtual void OnFormOptionButtonRequested(Tizen::Ui::Controls::_Form& source) = 0; + +// Reserves +protected: + // + //This method is for internal use only. Using this method can cause behavioral, security-related, + //and consistency-related issues in the application. + // + // Following method is reserved and may change its name at any time without + // prior notice. + // + // @since 2.0 + // + virtual void _IFormControlEventListener_Reserved1(void) { } + + // + //This method is for internal use only. Using this method can cause behavioral, security-related, + //and consistency-related issues in the application. + // + // Following method is reserved and may change its name at any time without + // prior notice. + // + // @since 2.0 + // + virtual void _IFormControlEventListener_Reserved2(void) { } + + // + //This method is for internal use only. Using this method can cause behavioral, security-related, + //and consistency-related issues in the application. + // + // Following method is reserved and may change its name at any time without + // prior notice. + // + // @since 2.0 + // + virtual void _IFormControlEventListener_Reserved3(void) { } +}; // _IFormControlEventListener + +}}} // Tizen::Ui::Controls + +#endif // _FUI_CTRL_INTERNAL_IFORM_CONTROL_EVENT_LISTENER_H_ diff --git a/src/ui/inc/FUiCtrl_OptionMenuImpl.h b/src/ui/inc/FUiCtrl_OptionMenuImpl.h index 7044e96..25aca21 100644 --- a/src/ui/inc/FUiCtrl_OptionMenuImpl.h +++ b/src/ui/inc/FUiCtrl_OptionMenuImpl.h @@ -24,7 +24,8 @@ #define _FUI_CTRL_INTERNAL_OPTION_MENU_IMPL_H_ #include - +#include +#include #include "FUiCtrl_OptionMenu.h" #include "FUiCtrl_IActionEventListener.h" #include "FUi_WindowImpl.h" @@ -45,6 +46,10 @@ public: result RemoveActionEventListener(Tizen::Ui::IActionEventListener& listener); result AddItem(const Tizen::Base::String& text, int actionId); + + result AddItem(const Tizen::Graphics::Bitmap& normalBitmap, const Tizen::Graphics::Bitmap* pPressedBitmap, const Tizen::Graphics::Bitmap* pHighlightedBitmap, int actionId); + result AddItem(const Tizen::Base::String &text, int actionId, const Tizen::Graphics::Bitmap& normalBitmap, const Tizen::Graphics::Bitmap* pPressedBitmap=null, const Tizen::Graphics::Bitmap* pHighlightedBitmap=null); + result InsertItemAt(int mainIndex, const Tizen::Base::String& text, int actionId); @@ -78,9 +83,9 @@ public: virtual OptionMenu& GetPublic(void); - virtual const _OptionMenu& GetCore(void) const; + virtual const _ContextMenu& GetCore(void) const; - virtual _OptionMenu& GetCore(void); + virtual _ContextMenu& GetCore(void); virtual void OnActionPerformed(const Tizen::Ui::_Control& source, int actionId); @@ -95,7 +100,7 @@ public: virtual result OnAttachedToMainTree(void); private: - _OptionMenuImpl(OptionMenu* pPublic, _OptionMenu* pCore); + _OptionMenuImpl(OptionMenu* pPublic, _ContextMenu* pCore); _OptionMenuImpl(const _OptionMenuImpl&); diff --git a/src/ui/inc/FUiCtrl_OptionMenuListPresenter.h b/src/ui/inc/FUiCtrl_OptionMenuListPresenter.h new file mode 100644 index 0000000..413fefd --- /dev/null +++ b/src/ui/inc/FUiCtrl_OptionMenuListPresenter.h @@ -0,0 +1,146 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0/ +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FUiCtrl_OptionMenuListPresenter.h + * @brief This is the header file for the _OptionMenuListPresenter class. + * + * This header file contains the declarations of the %_OptionMenuListPresenter class. + */ +#ifndef _FUI_CTRL_INTERNAL_OPTIONMENU_LIST_PRESENTER_H_ +#define _FUI_CTRL_INTERNAL_OPTIONMENU_LIST_PRESENTER_H_ + +#include +#include "FUi_Control.h" +#include "FUiCtrl_ContextMenu.h" +#include "FUiCtrl_ContextMenuModel.h" +#include "FUiCtrl_IContextMenuPresenter.h" + +namespace Tizen { namespace Ui { namespace Controls +{ + +class _ContextMenu; +class _ContextMenuModel; +class _ContextMenuItem; + +/** + * @class _OptionMenuListPresenter + * @brief + * @since 2.0 + * + * + * + * + */ +class _OptionMenuListPresenter + : public _IContextMenuPresenter +{ +// Lifecycle +public: + _OptionMenuListPresenter(_ContextMenu* pContextMenu); + virtual ~_OptionMenuListPresenter(void); + +// Operation +public: + virtual result Install(void); + virtual result Draw(void); + virtual result DrawBackground(Tizen::Graphics::Canvas* pCanvas); + virtual result DrawArrow(Tizen::Graphics::Canvas* pCanvas); + virtual result AddItem(const Base::String& text, int actionId, const Tizen::Graphics::Bitmap* normalBitmap, const Tizen::Graphics::Bitmap* pPressedBitmap, const Tizen::Graphics::Bitmap* pHighlightedBitmap); + virtual result InsertItem(int index, const Tizen::Base::String& text, int actionId, const Tizen::Graphics::Bitmap* normalBitmap, const Tizen::Graphics::Bitmap* pPressedBitmap, const Tizen::Graphics::Bitmap* pHighlightedBitmap); + virtual result SetItem(int index, const Tizen::Base::String& text, int actionId, const Tizen::Graphics::Bitmap* normalBitmap, const Tizen::Graphics::Bitmap* pPressedBitmap, const Tizen::Graphics::Bitmap* pHighlightedBitmap); + virtual result DeleteItem(int index); + virtual result DeleteItemAll(void); + virtual int CalculateShowItemCount(void); + virtual result CalculateWindowRect(void); + virtual result ApplyColorProperty(void); + + virtual _UiTouchEventDelivery OnPreviewTouchPressed(const _Control& source, const _TouchInfo& touchinfo); + virtual _UiTouchEventDelivery OnPreviewTouchMoved(const _Control& source, const _TouchInfo& touchinfo); + virtual _UiTouchEventDelivery OnPreviewTouchReleased(const _Control& source, const _TouchInfo& touchinfo); + + virtual bool OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo); + virtual bool OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo); + virtual bool OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo); + virtual bool OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo); + + virtual void OnFontChanged(Tizen::Graphics::Font* pFont); + virtual void OnFontInfoRequested(unsigned long& style, float& size); + + virtual void SetAllAccessibilityElement(void); + + virtual _ContextMenuItemInfo GetItemFromPosition(const Tizen::Graphics::FloatPoint& position); + virtual _ContextMenuItemInfo FindItem(int index); + virtual result SetTopDrawnItemIndex(int index); + virtual result DrawBitmap(Tizen::Graphics::Canvas& canvas, const Tizen::Graphics::FloatRectangle& bounds, const Tizen::Graphics::Bitmap& bitmap); + +private: + void LoadShape(void); + result CalculateRect(void); + void AdjustItemLayout(void); + void AdjustItemPosition(void); + Tizen::Graphics::FloatDimension AdjustItemLayoutStyle(void); + + _ContextMenuItem* CreateItem(const Base::String& text, int actionId, const Tizen::Graphics::Bitmap* pNormalBitmap, const Tizen::Graphics::Bitmap* pPressedBitmap, const Tizen::Graphics::Bitmap* pHighlightedBitmap); + int GetItemIndexFromPosition(const Tizen::Graphics::FloatPoint& point) const; + +private: + _OptionMenuListPresenter(const _OptionMenuListPresenter& rhs); + _OptionMenuListPresenter& operator =(const _OptionMenuListPresenter& rhs); + +// Attribute +private: + _ContextMenu* __pContextMenu; + _ContextMenuModel* __pModel; + + Tizen::Graphics::Font* __pFont; + Tizen::Graphics::FloatDimension __layoutSize; + + bool __touchOutRect; + int __selectedIndex; + bool __scrollEnable; + + float __maxWidth; + float __minWidth; + float __topMargin; + float __bottomMargin; + float __leftMargin; + float __rightMargin; + float __screenTopMargin; + float __screenBottomMargin; + float __screenLeftMargin; + float __screenRightMargin; + float __arrowTopMargin; + float __arrowBottomMargin; + float __arrowRightMargin; + float __arrowLeftMargin; + float __arrowWidth; + float __arrowHeight; + float __itemWidth; + float __itemMinWidth; + float __itemHeight; + float __itemMaxWidth; + float __itemGap; + float __itemBitmapWidth; + float __itemBitmapHeight; + float __itemFontSize; + float __dividerHeight; + float __anchorPopupOverlap; +}; // _OptionMenuListPresenter + +}}} // Tizen::Ui: Control + +#endif //_FUI_CTRL_INTERNAL_OPTIONMENU_LIST_PRESENTER_H_ -- 2.7.4