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.
18 * @file FUiCtrl_ContextMenu.cpp
19 * @brief This is the implementation file for the _ContextMenu class.
22 #include <FBaseErrorDefine.h>
23 #include <FBaseSysLog.h>
24 #include <FGrp_BitmapImpl.h>
25 #include <FBaseColIEnumeratorT.h>
26 #include "FUi_ControlImplManager.h"
27 #include "FUi_EcoreEvasMgr.h"
28 #include "FUi_ResourceManager.h"
29 #include "FUi_KeyEventManager.h"
30 #include "FUiAnim_VisualElement.h"
31 #include "FUiAnim_AnimationManager.h"
32 #include "FUi_AccessibilityContainer.h"
33 #include "FUi_AccessibilityElement.h"
34 #include "FUiCtrl_Form.h"
35 #include "FUiCtrl_Frame.h"
36 #include "FUiCtrl_ContextMenu.h"
37 #include "FUiCtrl_Scroll.h"
39 using namespace Tizen::Graphics;
40 using namespace Tizen::Media;
41 using namespace Tizen::Ui::Animations;
44 static const float TOUCH_PRESS_THRESHOLD_INSENSITIVE = 0.16f;
47 namespace Tizen { namespace Ui { namespace Controls
50 IMPLEMENT_PROPERTY(_ContextMenu);
52 _ContextMenu::_ContextMenu(const FloatPoint& point, enum ContextMenuCoreStyle style, enum ContextMenuCoreAlign contextMenuAlign)
53 : __pContextMenuPresenter(null)
55 , __align(contextMenuAlign)
56 , __showItemCount(MAX_CONTEXTMENU_LIST_SHOW_ITEM)
57 , __showItemMaxCount(0)
58 , __isAttachedToMainTree(false)
59 , __ownerInputEnableState(false)
60 , __anchorPoint(point)
61 , __windowRect(FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f))
62 , __bodyRect(FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f))
63 , __arrowRect(FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f))
64 , __itemRect(FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f))
65 , __pActionEvent(null)
66 , __pBackgroundNormalBitmap(null)
67 , __pBackgroundEffectBitmap(null)
68 , __dropPosition(CONTEXT_MENU_CORE_DROP_POSITION_INVALID)
69 , __layout(_CONTROL_ORIENTATION_PORTRAIT)
70 , __rotation(_CONTROL_ROTATION_0)
71 , __pScrollPanel(null)
73 __backgroundColor = Color(255, 255, 255, 255);
75 __textColor[CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL] = Color(255, 255, 255, 255);
76 __textColor[CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED] = Color(255, 255, 255, 255);
77 __textColor[CONTEXT_MENU_CORE_ITEM_STATUS_HIGHLIGHTED] = Color(255, 255, 255, 255);
79 __itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL] = Color(255, 255, 255, 255);
80 __itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED] = Color(255, 255, 255, 255);
81 __itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_HIGHLIGHTED] = Color(255, 255, 255, 255);
83 for (int i = 0; i < CONTEXT_MENU_CORE_DROP_POSITION_MAX; i++)
85 __pArrowNormalBitmap[i] = null;
86 __pArrowEffectBitmap[i] = null;
89 GET_SHAPE_CONFIG(CONTEXTMENU::ITEM_MAX_COUNT, __layout, __showItemMaxCount);
92 _ContextMenu::~_ContextMenu(void)
94 if (__isAttachedToMainTree && GetOwner() != null)
96 GetOwner()->UnlockInputEvent();
100 __pScrollPanel->DetachAllChildren();
101 DetachChild(*__pScrollPanel);
102 delete __pScrollPanel;
103 __pScrollPanel = null;
106 delete __pContextMenuPresenter;
107 __pContextMenuPresenter = null;
109 if (__pBackgroundNormalBitmap != null)
111 delete __pBackgroundNormalBitmap;
112 __pBackgroundNormalBitmap = null;
115 if (__pBackgroundEffectBitmap != null)
117 delete __pBackgroundEffectBitmap;
118 __pBackgroundEffectBitmap = null;
123 delete __pActionEvent;
124 __pActionEvent = null;
127 for (int i = 0; i < CONTEXT_MENU_CORE_DROP_POSITION_MAX; i++)
129 delete __pArrowNormalBitmap[i];
130 __pArrowNormalBitmap[i] = null;
132 delete __pArrowEffectBitmap[i];
133 __pArrowEffectBitmap[i] = null;
136 __actionId.RemoveAll();
138 RemoveAllAccessibilityElement();
142 _ContextMenu::CreateContextMenuN(const FloatPoint& point, enum ContextMenuCoreStyle style, enum ContextMenuCoreAlign contextMenuAlign)
144 _ContextMenu* pContextMenu = new (std::nothrow) _ContextMenu(point, style, contextMenuAlign);
145 SysTryReturn(NID_UI_CTRL, pContextMenu != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
147 result r = E_SUCCESS;
149 r = pContextMenu->CreateRootVisualElement();
150 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
152 pContextMenu->SetFocusable(false);
154 r = pContextMenu->Initialize();
155 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to Initialize.", GetErrorMessage(r));
157 r = pContextMenu->Install();
158 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to Install.", GetErrorMessage(r));
160 pContextMenu->AcquireHandle();
161 pContextMenu->SetTouchPressThreshold(TOUCH_PRESS_THRESHOLD_INSENSITIVE);
163 if (pContextMenu->GetAccessibilityContainer() != null)
165 pContextMenu->GetAccessibilityContainer()->Activate(true);
166 pContextMenu->GetAccessibilityContainer()->AddListener(*pContextMenu);
169 if (style == CONTEXT_MENU_CORE_STYLE_LIST)
171 float minWidth, minHeight; // for visible scrollbar when scrollable
172 GET_SHAPE_CONFIG(CONTEXTMENU::LIST_MIN_WIDTH, _CONTROL_ORIENTATION_PORTRAIT, minWidth);
173 GET_SHAPE_CONFIG(CONTEXTMENU::LIST_ITEM_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, minHeight);
174 pContextMenu->__pScrollPanel = _ScrollPanel::CreateScrollPanelN(FloatRectangle(0.0f, 0.0f, minWidth, minHeight), SCROLL_PANEL_SCROLL_DIRECTION_VERTICAL, false, false);
175 pContextMenu->__pScrollPanel->SetTouchPressThreshold(TOUCH_PRESS_THRESHOLD_INSENSITIVE);
176 pContextMenu->__pScrollPanel->SetFocusable(false);
178 _Scroll* pScroll = pContextMenu->__pScrollPanel->GetScrollBar();
179 SysTryCatch(NID_UI_CTRL, pScroll, , E_INVALID_STATE, "[E_INVALID_STATE] _Scroll isn't constructed");
180 pScroll->SetContextMenuScrollType(true);
182 pContextMenu->AttachChild(*(pContextMenu->__pScrollPanel));
194 _ContextMenu::GetScrollPanel(void)
196 return __pScrollPanel;
200 _ContextMenu::Install(void)
202 result r = E_SUCCESS;
204 // load bitmap of a background and arrow
206 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to load bitmap.");
208 r = __actionId.Construct();
209 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to construct arraylist.");
211 if (__style == CONTEXT_MENU_CORE_STYLE_LIST)
213 _IContextMenuPresenter* pPresenter = new (std::nothrow) _ContextMenuListPresenter(this);
214 SysTryReturnResult(NID_UI_CTRL, pPresenter != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
216 SetPresenter(*pPresenter);
218 r = pPresenter->Install();
222 _IContextMenuPresenter* pPresenter = new (std::nothrow) _ContextMenuGridPresenter(this);
223 SysTryReturnResult(NID_UI_CTRL, pPresenter != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
225 SetPresenter(*pPresenter);
227 r = pPresenter->Install();
234 _ContextMenu::Initialize(void)
236 FloatDimension screen = _ControlManager::GetInstance()->GetScreenSizeF();
237 result r = E_SUCCESS;
239 Color backgroundColor;
240 Color backgroundSelectedColor;
242 Color itemTextSelectedColor;
244 r = SetBounds(FloatRectangle(0.0f, 0.0f, screen.width, screen.height));
245 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "SetBounds failed.");
250 GET_COLOR_CONFIG(CONTEXTMENU::BG_NORMAL, backgroundColor);
251 GET_COLOR_CONFIG(CONTEXTMENU::ITEM_BG_PRESSED, backgroundSelectedColor);
252 GET_COLOR_CONFIG(CONTEXTMENU::ITEM_TEXT_NORMAL, itemTextColor);
253 GET_COLOR_CONFIG(CONTEXTMENU::ITEM_TEXT_PRESSED, itemTextSelectedColor);
255 __backgroundColor = backgroundColor;
256 __itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL] = backgroundColor;
257 __itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED] = backgroundSelectedColor;
258 __textColor[CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL] = itemTextColor;
259 __textColor[CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED] = itemTextSelectedColor;
261 if (GetVisualElement() != null)
263 GetVisualElement()->SetSurfaceOpaque(false);
271 _ContextMenu::SetPresenter(const _IContextMenuPresenter& ContextMenuPresenter)
273 __pContextMenuPresenter = const_cast <_IContextMenuPresenter*>(&ContextMenuPresenter);
279 _ContextMenu::OnDraw()
281 __pContextMenuPresenter->Draw();
283 if(unlikely((_AccessibilityManager::IsActivated())))
285 _AccessibilityManager::GetInstance()->RequestAutoReading(_ACCESSIBILITY_AUTO_READING_MODE_FIRST_ITEM);
290 _ContextMenu::OnAttachedToMainTree(void)
292 result r = E_SUCCESS;
294 __isAttachedToMainTree = true;
296 _Control* pOwner = GetOwner();
299 _Frame* pFrame = dynamic_cast<_Frame*>(_ControlManager::GetInstance()->GetCurrentFrame());
300 SysTryReturn(NID_UI_CTRL, pFrame != null, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Current frame instance is not available.");
302 _Form* pForm = pFrame->GetCurrentForm();
303 pForm != null ? SetOwner(pForm) : SetOwner(pFrame);
307 GET_SHAPE_CONFIG(CONTEXTMENU::ITEM_MAX_COUNT, __layout, __showItemMaxCount);
311 pOwner->LockInputEvent();
314 __layout = pOwner->GetOrientation();
316 _Window* pOwnerWindow = pOwner->GetRootWindow();
318 if (pOwnerWindow != null)
320 int ownerRotation = GetEcoreEvasMgr()->GetEcoreEvas()->GetWindowRotation(*pOwnerWindow);
321 switch (ownerRotation)
324 __rotation = _CONTROL_ROTATION_0;
328 __rotation = _CONTROL_ROTATION_90;
332 __rotation = _CONTROL_ROTATION_180;
336 __rotation = _CONTROL_ROTATION_270;
340 __rotation = _CONTROL_ROTATION_0;
345 AdjustDropPosition();
347 if (GetItemCount() <= 0)
349 __pContextMenuPresenter->CalculateShowItemCount();
352 r = __pContextMenuPresenter->CalculateWindowRect();
353 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
355 if (__pScrollPanel != null)
357 __pScrollPanel->SetScrollPosition(0.0f, false);
362 SetVisibleState(true);
364 if (__style == CONTEXT_MENU_CORE_STYLE_LIST)
366 SetTouchCapture(false, false);
370 SetTouchCapture(true, false);
373 SetAllAccessibilityElement();
375 _VisualElement* pVisualElement = GetVisualElement();
376 FloatRectangle pBounds = pVisualElement->GetBounds();
377 float oldBoundsX = pBounds.x;
378 float oldBoundsY = pBounds.y;
379 float distanceX = 0.0f;
380 float distanceY = 0.0f;
382 GET_SHAPE_CONFIG(CONTEXTMENU::APPEARING_ANIMATION_DISTANCE_X, __layout, distanceX);
383 GET_SHAPE_CONFIG(CONTEXTMENU::APPEARING_ANIMATION_DISTANCE_Y, __layout, distanceY);
385 switch(GetDropPosition())
387 case CONTEXT_MENU_CORE_DROP_POSITION_UP:
388 pBounds.y += distanceY;
390 case CONTEXT_MENU_CORE_DROP_POSITION_DOWN:
391 pBounds.y -= distanceY;
393 case CONTEXT_MENU_CORE_DROP_POSITION_LEFT:
394 pBounds.x += distanceX;
396 case CONTEXT_MENU_CORE_DROP_POSITION_RIGHT:
397 pBounds.x -= distanceX;
403 pVisualElement->SetBounds(pBounds);
404 pVisualElement->SetOpacity(0.0f);
406 bool enable = pVisualElement->IsImplicitAnimationEnabled();
408 pVisualElement->SetImplicitAnimationEnabled(true);
410 pBounds.x = oldBoundsX;
411 pBounds.y = oldBoundsY;
412 pVisualElement->SetBounds(pBounds);
413 pVisualElement->SetOpacity(1.0f);
415 pVisualElement->SetImplicitAnimationEnabled(enable);
421 _ContextMenu::OnDetachingFromMainTree(void)
423 result r = E_SUCCESS;
425 ReleaseTouchCapture();
427 _Control* pOwner = GetOwner();
430 pOwner->UnlockInputEvent();
433 __isAttachedToMainTree = false;
439 _ContextMenu::AddItem(const Base::String& text, int actionId, const Bitmap* pNormalBitmap, const Bitmap* pPressedBitmap,
440 const Bitmap* pHighlightedBitmap)
442 result r = E_SUCCESS;
444 r = __pContextMenuPresenter->AddItem(text, actionId, pNormalBitmap, pPressedBitmap, pHighlightedBitmap);
445 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to add a item.");
447 __actionId.Add(actionId);
449 __pContextMenuPresenter->CalculateShowItemCount();
450 __pContextMenuPresenter->CalculateWindowRect();
456 _ContextMenu::InsertItem(int index, const Base::String& text, int actionId, const Bitmap* pNormalBitmap,
457 const Bitmap* pPressedBitmap,
458 const Bitmap* pHighlightedBitmap)
460 result r = E_SUCCESS;
462 r = __pContextMenuPresenter->InsertItem(index, text, actionId, pNormalBitmap, pPressedBitmap, pHighlightedBitmap);
463 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to insert a item.");
465 __actionId.InsertAt(actionId, index);
467 __pContextMenuPresenter->CalculateShowItemCount();
468 __pContextMenuPresenter->CalculateWindowRect();
474 _ContextMenu::SetItem(int index, const Base::String& text, int actionId, const Bitmap* pNormalBitmap,
475 const Bitmap* pPressedBitmap, const Bitmap* pHighlightedBitmap)
477 result r = E_SUCCESS;
479 r = __pContextMenuPresenter->SetItem(index, text, actionId, pNormalBitmap, pPressedBitmap, pHighlightedBitmap);
480 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to set a item.");
482 __actionId.SetAt(actionId, index);
484 __pContextMenuPresenter->CalculateWindowRect();
490 _ContextMenu::RemoveItemAt(int index)
492 result r = E_SUCCESS;
494 r = __pContextMenuPresenter->DeleteItem(index);
495 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to remove a item.");
497 __actionId.RemoveAt(index);
499 __pContextMenuPresenter->CalculateShowItemCount();
500 __pContextMenuPresenter->CalculateWindowRect();
506 _ContextMenu::RemoveAllItems(void)
508 result r = E_SUCCESS;
510 r = __pContextMenuPresenter->DeleteItemAll();
511 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to remove all items.");
513 __actionId.RemoveAll();
515 __pContextMenuPresenter->CalculateShowItemCount();
516 __pContextMenuPresenter->CalculateWindowRect();
522 _ContextMenu::GetItemCount(void) const
524 return __actionId.GetCount();
528 _ContextMenu::GetItemIndexAt(int actionId) const
530 int count = __actionId.GetCount();
532 for (int i = 0; i < count; i++)
534 int index = GetItemActionIdAt(i);
536 if (actionId == index)
546 _ContextMenu::GetItemActionIdAt(int index) const
548 int count = __actionId.GetCount();
550 result r = E_SUCCESS;
552 if (count <= 0 || index >= count)
557 r = __actionId.GetAt(index, actionId);
558 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, actionId, r, "[%s] Propagating.", GetErrorMessage(r));
564 _ContextMenu::SetAnchorPosition(float x, float y)
569 if (__align == CONTEXT_MENU_CORE_ALIGN_AUTO)
571 AdjustDropPosition();
574 __pContextMenuPresenter->CalculateWindowRect();
579 _ContextMenu::GetAnchorPosition(void) const
581 return __anchorPoint;
585 _ContextMenu::SetWindowRect(const FloatRectangle& rect)
593 _ContextMenu::GetWindowRect(void) const
599 _ContextMenu::SetBodyRect(const FloatRectangle& rect)
607 _ContextMenu::GetBodyRect(void) const
613 _ContextMenu::SetArrowRect(const FloatRectangle& rect)
621 _ContextMenu::GetArrowRect(void) const
627 _ContextMenu::SetItemRect(const FloatRectangle& rect)
635 _ContextMenu::GetItemRect(void) const
641 _ContextMenu::SetPropertyMaxVisibleItemsCount(const Variant& count)
643 int showCount = count.ToInt();
647 SysLogException(NID_UI_CTRL, E_INVALID_ARG, "Count is invalid.");
648 return E_INVALID_ARG;
652 __showItemCount = showCount;
658 _ContextMenu::GetPropertyMaxVisibleItemsCount(void) const
660 return Tizen::Ui::Variant(__showItemCount);
664 _ContextMenu::GetShowItemCount(void) const
666 Variant count = GetProperty("maxVisibleItemsCount");
668 return count.ToInt();
672 _ContextMenu::GetShowItemMaxCount(void) const
674 return __showItemMaxCount;
678 _ContextMenu::SetShowItemCount(int count)
682 r = SetProperty("maxVisibleItemsCount", Variant(count));
683 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to set property.");
685 if (__style == CONTEXT_MENU_CORE_STYLE_LIST)
687 r = __pContextMenuPresenter->CalculateWindowRect();
688 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to calculate window.");
695 _ContextMenu::SetPropertyColor(const Variant& color)
697 __backgroundColor = color.ToColor();
699 LoadColorReplacedBitmap(__backgroundColor);
705 _ContextMenu::GetPropertyColor(void) const
707 return Tizen::Ui::Variant(__backgroundColor);
711 _ContextMenu::SetColor(const Graphics::Color& color)
713 return SetProperty("color", Variant(color));
717 _ContextMenu::GetColor(void) const
719 Variant color = GetProperty("color");
721 return color.ToColor();
725 _ContextMenu::SetPropertyNormalItemColor(const Variant& color)
727 __itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL] = color.ToColor();
729 return __pContextMenuPresenter->ApplyColorProperty();
733 _ContextMenu::GetPropertyNormalItemColor(void) const
735 return Tizen::Ui::Variant(__itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL]);
739 _ContextMenu::SetPropertyPressedItemColor(const Variant& color)
741 __itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED] = color.ToColor();
743 return __pContextMenuPresenter->ApplyColorProperty();
747 _ContextMenu::GetPropertyPressedItemColor(void) const
749 return Tizen::Ui::Variant(__itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED]);
753 _ContextMenu::SetPropertyHighlightedItemColor(const Variant & color)
755 __itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_HIGHLIGHTED] = color.ToColor();
757 return __pContextMenuPresenter->ApplyColorProperty();
761 _ContextMenu::GetPropertyHighlightedItemColor(void) const
763 return Tizen::Ui::Variant(__itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_HIGHLIGHTED]);
767 _ContextMenu::SetItemColor(enum ContextMenuCoreItemStatus status, const Graphics::Color& color)
769 result r = E_SUCCESS;
771 if (status == CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL)
773 r = SetProperty("normalItemColor", Variant(color));
775 else if (status == CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED)
777 r = SetProperty("pressedItemColor", Variant(color));
781 r = SetProperty("highlightedItemColor", Variant(color));
788 _ContextMenu::GetItemColor(enum ContextMenuCoreItemStatus status) const
792 if (status == CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL)
794 Variant color = GetProperty("normalItemColor");
795 itemColor = color.ToColor();
798 else if (status == CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED)
800 Variant color = GetProperty("pressedItemColor");
801 itemColor = color.ToColor();
806 Variant color = GetProperty("highlightedItemColor");
807 itemColor = color.ToColor();
815 _ContextMenu::SetPropertyNormalItemTextColor(const Variant& color)
817 __textColor[CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL] = color.ToColor();
819 return __pContextMenuPresenter->ApplyColorProperty();
823 _ContextMenu::GetPropertyNormalItemTextColor(void) const
825 return Tizen::Ui::Variant(__textColor[CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL]);
829 _ContextMenu::SetPropertyPressedItemTextColor(const Variant& color)
831 __textColor[CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED] = color.ToColor();
833 return __pContextMenuPresenter->ApplyColorProperty();
837 _ContextMenu::GetPropertyPressedItemTextColor(void) const
839 return Tizen::Ui::Variant(__textColor[CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED]);
843 _ContextMenu::SetPropertyHighlightedItemTextColor(const Variant & color)
845 __textColor[CONTEXT_MENU_CORE_ITEM_STATUS_HIGHLIGHTED] = color.ToColor();
847 return __pContextMenuPresenter->ApplyColorProperty();
851 _ContextMenu::GetPropertyHighlightedItemTextColor(void) const
853 return Tizen::Ui::Variant(__textColor[CONTEXT_MENU_CORE_ITEM_STATUS_HIGHLIGHTED]);
857 _ContextMenu::SetTextColor(enum ContextMenuCoreItemStatus status, const Graphics::Color& color)
859 result r = E_SUCCESS;
861 if (status == CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL)
863 r = SetProperty("normalItemTextColor", Variant(color));
865 else if (status == CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED)
867 r = SetProperty("pressedItemTextColor", Variant(color));
871 r = SetProperty("highlightedItemTextColor", Variant(color));
879 _ContextMenu::GetTextColor(enum ContextMenuCoreItemStatus status) const
883 if (status == CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL)
885 Variant color = GetProperty("normalItemTextColor");
886 textColor = color.ToColor();
889 else if (status == CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED)
891 Variant color = GetProperty("pressedItemTextColor");
892 textColor = color.ToColor();
897 Variant color = GetProperty("highlightedItemTextColor");
898 textColor = color.ToColor();
905 _ContextMenu::AddActionEventListener(const Tizen::Ui::Controls::_IActionEventListener& listener)
907 result r = E_SUCCESS;
909 if (__pActionEvent == null)
911 __pActionEvent = _ActionEvent::CreateInstanceN(*this);
912 SysTryReturn(NID_UI_CTRL, __pActionEvent != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
913 "[E_OUT_OF_MEMORY] The memory is insufficient.")
915 r = __pActionEvent->AddListener(listener);
916 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to remove an action event listener.")
922 delete __pActionEvent;
923 __pActionEvent = null;
928 _ContextMenu::RemoveActionEventListener(const Tizen::Ui::Controls::_IActionEventListener& listener)
930 SysTryReturn(NID_UI_CTRL, __pActionEvent != null, E_INVALID_STATE, E_INVALID_STATE,
931 "[E_INVALID_STATE] The action event instance isn't constructed.")
933 result r = E_SUCCESS;
935 r = __pActionEvent->RemoveListener(listener);
936 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to remove an action event listener")
941 Tizen::Ui::Controls::_ActionEvent*
942 _ContextMenu::GetActionEvent(void) const
944 return __pActionEvent;
948 _ContextMenu::LoadBitmap(void)
950 Color backgroundColor;
953 if (__pBackgroundEffectBitmap != null)
955 delete __pBackgroundEffectBitmap;
956 __pBackgroundEffectBitmap = null;
959 for (int i = 0; i < CONTEXT_MENU_CORE_DROP_POSITION_MAX; i++)
961 if (__pArrowEffectBitmap[i] != null)
963 delete __pArrowEffectBitmap[i];
964 __pArrowEffectBitmap[i] = null;
968 backgroundColor = GetColor();
972 r = GET_BITMAP_CONFIG_N(CONTEXTMENU::ANCHOR_EFFECT_UP, BITMAP_PIXEL_FORMAT_ARGB8888,
973 __pArrowEffectBitmap[CONTEXT_MENU_CORE_DROP_POSITION_UP]);
974 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
976 r = GET_BITMAP_CONFIG_N(CONTEXTMENU::ANCHOR_EFFECT_DOWN, BITMAP_PIXEL_FORMAT_ARGB8888,
977 __pArrowEffectBitmap[CONTEXT_MENU_CORE_DROP_POSITION_DOWN]);
978 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
980 r = GET_BITMAP_CONFIG_N(CONTEXTMENU::ANCHOR_EFFECT_LEFT, BITMAP_PIXEL_FORMAT_ARGB8888,
981 __pArrowEffectBitmap[CONTEXT_MENU_CORE_DROP_POSITION_LEFT]);
982 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
984 r = GET_BITMAP_CONFIG_N(CONTEXTMENU::ANCHOR_EFFECT_RIGHT, BITMAP_PIXEL_FORMAT_ARGB8888,
985 __pArrowEffectBitmap[CONTEXT_MENU_CORE_DROP_POSITION_RIGHT]);
986 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
988 r = GET_BITMAP_CONFIG_N(CONTEXTMENU::BG_OUTLINE_EFFECT_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pBackgroundEffectBitmap);
989 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
991 r = LoadColorReplacedBitmap(backgroundColor);
992 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
997 delete __pBackgroundEffectBitmap;
998 __pBackgroundEffectBitmap = null;
1000 for (int i = 0; i < CONTEXT_MENU_CORE_DROP_POSITION_MAX; i++)
1003 delete __pArrowEffectBitmap[i];
1004 __pArrowEffectBitmap[i] = null;
1011 _ContextMenu::LoadColorReplacedBitmap(const Tizen::Graphics::Color& color)
1013 Bitmap* ptempNormalBitmap = null;
1015 // Delete old bitmap
1016 if (__pBackgroundNormalBitmap != null)
1018 delete __pBackgroundNormalBitmap;
1019 __pBackgroundNormalBitmap = null;
1022 for (int i = 0; i < CONTEXT_MENU_CORE_DROP_POSITION_MAX; i++)
1024 if (__pArrowNormalBitmap[i] != null)
1026 delete __pArrowNormalBitmap[i];
1027 __pArrowNormalBitmap[i] = null;
1032 r = GET_BITMAP_CONFIG_N(CONTEXTMENU::ANCHOR_NORMAL_UP, BITMAP_PIXEL_FORMAT_ARGB8888, ptempNormalBitmap);
1033 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
1034 __pArrowNormalBitmap[CONTEXT_MENU_CORE_DROP_POSITION_UP] = _BitmapImpl::GetColorReplacedBitmapN(*ptempNormalBitmap,
1035 Color::GetColor(COLOR_ID_MAGENTA), color);
1036 SysTryCatch(NID_UI_CTRL, __pArrowNormalBitmap[CONTEXT_MENU_CORE_DROP_POSITION_UP] != null, , GetLastResult(),
1037 "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1038 delete ptempNormalBitmap;
1039 ptempNormalBitmap = null;
1041 r = GET_BITMAP_CONFIG_N(CONTEXTMENU::ANCHOR_NORMAL_DOWN, BITMAP_PIXEL_FORMAT_ARGB8888, ptempNormalBitmap);
1042 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
1043 __pArrowNormalBitmap[CONTEXT_MENU_CORE_DROP_POSITION_DOWN] = _BitmapImpl::GetColorReplacedBitmapN(*ptempNormalBitmap,
1044 Color::GetColor(COLOR_ID_MAGENTA), color);
1045 SysTryCatch(NID_UI_CTRL, __pArrowNormalBitmap[CONTEXT_MENU_CORE_DROP_POSITION_DOWN] != null, , GetLastResult(),
1046 "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1047 delete ptempNormalBitmap;
1048 ptempNormalBitmap = null;
1050 r = GET_BITMAP_CONFIG_N(CONTEXTMENU::ANCHOR_NORMAL_LEFT, BITMAP_PIXEL_FORMAT_ARGB8888, ptempNormalBitmap);
1051 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
1052 __pArrowNormalBitmap[CONTEXT_MENU_CORE_DROP_POSITION_LEFT] = _BitmapImpl::GetColorReplacedBitmapN(*ptempNormalBitmap,
1053 Color::GetColor(COLOR_ID_MAGENTA), color);
1054 SysTryCatch(NID_UI_CTRL, __pArrowNormalBitmap[CONTEXT_MENU_CORE_DROP_POSITION_LEFT] != null, , GetLastResult(),
1055 "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1056 delete ptempNormalBitmap;
1057 ptempNormalBitmap = null;
1059 r = GET_BITMAP_CONFIG_N(CONTEXTMENU::ANCHOR_NORMAL_RIGHT, BITMAP_PIXEL_FORMAT_ARGB8888, ptempNormalBitmap);
1060 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
1061 __pArrowNormalBitmap[CONTEXT_MENU_CORE_DROP_POSITION_RIGHT] = _BitmapImpl::GetColorReplacedBitmapN(*ptempNormalBitmap,
1062 Color::GetColor(COLOR_ID_MAGENTA), color);
1063 SysTryCatch(NID_UI_CTRL, __pArrowNormalBitmap[CONTEXT_MENU_CORE_DROP_POSITION_RIGHT] != null, , GetLastResult(),
1064 "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1065 delete ptempNormalBitmap;
1066 ptempNormalBitmap = null;
1068 r = GET_BITMAP_CONFIG_N(CONTEXTMENU::BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, ptempNormalBitmap);
1069 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
1070 __pBackgroundNormalBitmap = _BitmapImpl::GetColorReplacedBitmapN(*ptempNormalBitmap, Color::GetColor(COLOR_ID_MAGENTA), color);
1071 SysTryCatch(NID_UI_CTRL, __pBackgroundNormalBitmap != null, , GetLastResult(), "[%s] Propagating.",
1072 GetErrorMessage(GetLastResult()));
1073 delete ptempNormalBitmap;
1078 delete ptempNormalBitmap;
1080 delete __pBackgroundNormalBitmap;
1081 __pBackgroundNormalBitmap = null;
1083 for (int i = 0; i < CONTEXT_MENU_CORE_DROP_POSITION_MAX; i++)
1085 delete __pArrowNormalBitmap[i];
1086 __pArrowNormalBitmap[i] = null;
1093 _ContextMenu::GetArrowNormalBitmap(ContextMenuCoreDropPosition dropPosition) const
1095 if (dropPosition == CONTEXT_MENU_CORE_DROP_POSITION_INVALID || dropPosition == CONTEXT_MENU_CORE_DROP_POSITION_MAX)
1100 return __pArrowNormalBitmap[dropPosition];
1104 _ContextMenu::GetArrowEffectBitmap(ContextMenuCoreDropPosition dropPosition) const
1106 if (dropPosition == CONTEXT_MENU_CORE_DROP_POSITION_INVALID || dropPosition == CONTEXT_MENU_CORE_DROP_POSITION_MAX)
1111 return __pArrowEffectBitmap[dropPosition];
1115 _ContextMenu::GetBackgroundNormalBitmap(void) const
1117 return __pBackgroundNormalBitmap;
1121 _ContextMenu::GetBackgroundEffectBitmap(void) const
1123 return __pBackgroundEffectBitmap;
1126 enum ContextMenuCoreDropPosition
1127 _ContextMenu::GetDropPosition(void) const
1129 return __dropPosition;
1133 _ContextMenu::AdjustDropPosition(void)
1135 FloatDimension screen = _ControlManager::GetInstance()->GetScreenSizeF();
1137 if (__align == CONTEXT_MENU_CORE_ALIGN_UP)
1139 __dropPosition = CONTEXT_MENU_CORE_DROP_POSITION_UP;
1141 else if (__align == CONTEXT_MENU_CORE_ALIGN_DOWN)
1143 __dropPosition = CONTEXT_MENU_CORE_DROP_POSITION_DOWN;
1145 else if (__align == CONTEXT_MENU_CORE_ALIGN_LEFT)
1147 __dropPosition = CONTEXT_MENU_CORE_DROP_POSITION_LEFT;
1149 else if (__align == CONTEXT_MENU_CORE_ALIGN_RIGHT)
1151 __dropPosition = CONTEXT_MENU_CORE_DROP_POSITION_RIGHT;
1155 if (__layout == _CONTROL_ORIENTATION_LANDSCAPE)
1157 screen.SetSize(screen.height, screen.width);
1160 if (screen.height > screen.width)
1162 if ((screen.height / 2.0f) > __anchorPoint.y)
1164 __dropPosition = CONTEXT_MENU_CORE_DROP_POSITION_DOWN;
1168 __dropPosition = CONTEXT_MENU_CORE_DROP_POSITION_UP;
1173 if ((screen.width / 2.0f) > __anchorPoint.x)
1175 __dropPosition = CONTEXT_MENU_CORE_DROP_POSITION_RIGHT;
1179 __dropPosition = CONTEXT_MENU_CORE_DROP_POSITION_LEFT;
1185 _UiTouchEventDelivery
1186 _ContextMenu::OnPreviewTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
1188 return __pContextMenuPresenter->OnPreviewTouchPressed(source, touchinfo);
1192 _ContextMenu::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
1194 return __pContextMenuPresenter->OnTouchPressed(source, touchinfo);
1197 _UiTouchEventDelivery
1198 _ContextMenu::OnPreviewTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
1200 return __pContextMenuPresenter->OnPreviewTouchMoved(source, touchinfo);
1204 _ContextMenu::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
1206 return __pContextMenuPresenter->OnTouchMoved(source, touchinfo);
1209 _UiTouchEventDelivery
1210 _ContextMenu::OnPreviewTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
1212 return __pContextMenuPresenter->OnPreviewTouchReleased(source, touchinfo);
1216 _ContextMenu::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
1218 return __pContextMenuPresenter->OnTouchReleased(source, touchinfo);
1221 _UiTouchEventDelivery
1222 _ContextMenu::OnPreviewTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
1224 return __pContextMenuPresenter->OnPreviewTouchCanceled(source, touchinfo);
1228 _ContextMenu::OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
1230 __pContextMenuPresenter->OnTouchCanceled(source, touchinfo);
1232 SetVisibleState(false);
1238 _ContextMenu::OnFontChanged(Tizen::Graphics::Font* pFont)
1240 return __pContextMenuPresenter->OnFontChanged(pFont);
1244 _ContextMenu::OnFontInfoRequested(unsigned long& style, float& size)
1246 return __pContextMenuPresenter->OnFontInfoRequested(style, size);
1250 _ContextMenu::OnVisibleStateChanged(void)
1252 _Window::OnVisibleStateChanged();
1256 _ContextMenu::OnChangeLayout(_ControlRotation rotation)
1258 _ControlOrientation orientation;
1260 orientation = GetOwner()->GetOrientation();
1262 GET_SHAPE_CONFIG(CONTEXTMENU::ITEM_MAX_COUNT, orientation, __showItemMaxCount);
1264 if (__isAttachedToMainTree == true)
1266 if(__rotation != rotation)
1268 SetVisibleState(false);
1272 __layout = orientation;
1273 __rotation = rotation;
1276 _ContextMenu::OnOwnerChanged(_Control* pOldOwner)
1278 if (!__isAttachedToMainTree)
1283 _Control* pOwner = GetOwner();
1285 if (pOldOwner != null)
1287 pOldOwner->UnlockInputEvent();
1292 pOwner->LockInputEvent();
1297 _ContextMenu::OnTouchCaptureGained(void)
1299 if (__style == CONTEXT_MENU_CORE_STYLE_LIST)
1301 SetTouchCapture(false, false);
1305 SetTouchCapture(true, false);
1310 _ContextMenu::OnTouchCaptureLost(void)
1315 _ContextMenu::OnKeyPressed(const _Control& source, const _KeyInfo& keyInfo)
1317 return __pContextMenuPresenter->OnKeyPressed(source, keyInfo);
1321 _ContextMenu::OnKeyReleased(const _Control& source, const _KeyInfo& keyInfo)
1323 return __pContextMenuPresenter->OnKeyReleased(source, keyInfo);
1327 _ContextMenu::IsChildControlFocusManage(void) const
1329 return __pContextMenuPresenter->IsChildControlFocusManage();
1333 _ContextMenu::OnDrawFocus(void)
1335 __pContextMenuPresenter->OnDrawFocus();
1339 _ContextMenu::OnFocusModeStateChanged(void)
1341 __pContextMenuPresenter->OnFocusModeStateChanged();
1344 _AccessibilityElement*
1345 _ContextMenu::GetAccessibilityElement(const int mainIndex) const
1347 _AccessibilityElement* pElement = null;
1348 result r = __accessibilityElements.GetAt(mainIndex, pElement);
1349 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed at AccessibilityElement.", GetErrorMessage(r));
1360 _ContextMenu::AddAccessibilityElement(const _AccessibilityElement& element)
1362 __accessibilityElements.Add(const_cast<_AccessibilityElement*>(&element));
1366 _ContextMenu::SetAllAccessibilityElement(void)
1368 RemoveAllAccessibilityElement();
1369 __pContextMenuPresenter->SetAllAccessibilityElement();
1373 _ContextMenu::OnAccessibilityFocusMovedNext(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1379 _ContextMenu::OnAccessibilityFocusMovedPrevious(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1385 _ContextMenu::OnAccessibilityReadElement(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1391 _ContextMenu::OnAccessibilityReadingElement(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1397 _ContextMenu::OnAccessibilityFocusIn(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1403 _ContextMenu::OnAccessibilityFocusOut(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1409 _ContextMenu::OnAccessibilityActionPerformed(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1411 SetVisibleState(false);
1417 _ContextMenu::OnAccessibilityValueIncreased(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1423 _ContextMenu::OnAccessibilityValueDecreased(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1429 _ContextMenu::RemoveAllAccessibilityElement(void)
1431 _AccessibilityContainer* pAccessibilityContainer = GetAccessibilityContainer();
1432 if (pAccessibilityContainer && pAccessibilityContainer->IsActivated())
1434 pAccessibilityContainer->RemoveAllElement();
1438 _ContextMenuItemInfo
1439 _ContextMenu::GetItemFromPosition(const FloatPoint& position) const
1441 return __pContextMenuPresenter->GetItemFromPosition(position);
1444 _ContextMenuItemInfo
1445 _ContextMenu::FindItem(int index) const
1447 return __pContextMenuPresenter->FindItem(index);
1451 _ContextMenu::SetTopDrawnItemIndex(int index)
1453 return __pContextMenuPresenter->SetTopDrawnItemIndex(index);
1457 _ContextMenu::GetLayout(void) const
1462 }}} // Tizen::Ui: Control