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_ResourceManager.h"
28 #include "FUiAnim_VisualElement.h"
29 #include "FUiAnim_AnimationManager.h"
30 #include "FUi_AccessibilityContainer.h"
31 #include "FUi_AccessibilityElement.h"
32 #include "FUiCtrl_Form.h"
33 #include "FUiCtrl_Frame.h"
34 #include "FUiCtrl_ContextMenu.h"
35 #include "FUiCtrl_Scroll.h"
37 using namespace Tizen::Graphics;
38 using namespace Tizen::Media;
39 using namespace Tizen::Ui::Animations;
42 static const float TOUCH_PRESS_THRESHOLD_INSENSITIVE = 0.16f;
45 namespace Tizen { namespace Ui { namespace Controls
48 IMPLEMENT_PROPERTY(_ContextMenu);
50 _ContextMenu::_ContextMenu(const FloatPoint& point, enum ContextMenuCoreStyle style, enum ContextMenuCoreAlign contextMenuAlign)
51 : __pContextMenuPresenter(null)
53 , __align(contextMenuAlign)
54 , __showItemCount(MAX_CONTEXTMENU_LIST_SHOW_ITEM)
55 , __showItemMaxCount(0)
56 , __isAttachedToMainTree(false)
57 , __ownerInputEnableState(false)
58 , __anchorPoint(point)
59 , __windowRect(FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f))
60 , __bodyRect(FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f))
61 , __arrowRect(FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f))
62 , __itemRect(FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f))
63 , __pActionEvent(null)
64 , __pBackgroundNormalBitmap(null)
65 , __pBackgroundEffectBitmap(null)
66 , __dropPosition(CONTEXT_MENU_CORE_DROP_POSITION_INVALID)
67 , __layout(_CONTROL_ORIENTATION_PORTRAIT)
68 , __pScrollPanel(null)
70 __backgroundColor = Color(255, 255, 255, 255);
72 __textColor[CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL] = Color(255, 255, 255, 255);
73 __textColor[CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED] = Color(255, 255, 255, 255);
74 __textColor[CONTEXT_MENU_CORE_ITEM_STATUS_HIGHLIGHTED] = Color(255, 255, 255, 255);
76 __itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL] = Color(255, 255, 255, 255);
77 __itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED] = Color(255, 255, 255, 255);
78 __itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_HIGHLIGHTED] = Color(255, 255, 255, 255);
80 for (int i = 0; i < CONTEXT_MENU_CORE_DROP_POSITION_MAX; i++)
82 __pArrowNormalBitmap[i] = null;
83 __pArrowEffectBitmap[i] = null;
87 _ContextMenu::~_ContextMenu(void)
89 if (__isAttachedToMainTree && GetOwner() != null)
91 GetOwner()->UnlockInputEvent();
95 __pScrollPanel->DetachAllChildren();
96 DetachChild(*__pScrollPanel);
97 delete __pScrollPanel;
98 __pScrollPanel = null;
101 delete __pContextMenuPresenter;
102 __pContextMenuPresenter = null;
104 if (__pBackgroundNormalBitmap != null)
106 delete __pBackgroundNormalBitmap;
107 __pBackgroundNormalBitmap = null;
110 if (__pBackgroundEffectBitmap != null)
112 delete __pBackgroundEffectBitmap;
113 __pBackgroundEffectBitmap = null;
118 delete __pActionEvent;
119 __pActionEvent = null;
122 for (int i = 0; i < CONTEXT_MENU_CORE_DROP_POSITION_MAX; i++)
124 delete __pArrowNormalBitmap[i];
125 __pArrowNormalBitmap[i] = null;
127 delete __pArrowEffectBitmap[i];
128 __pArrowEffectBitmap[i] = null;
131 __actionId.RemoveAll();
133 RemoveAllAccessibilityElement();
137 _ContextMenu::CreateContextMenuN(const FloatPoint& point, enum ContextMenuCoreStyle style, enum ContextMenuCoreAlign contextMenuAlign)
139 _ContextMenu* pContextMenu = new (std::nothrow) _ContextMenu(point, style, contextMenuAlign);
140 SysTryReturn(NID_UI_CTRL, pContextMenu != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
142 result r = E_SUCCESS;
144 r = pContextMenu->CreateRootVisualElement();
145 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
147 pContextMenu->SetFocusable(false);
149 r = pContextMenu->Initialize();
150 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to Initialize.", GetErrorMessage(r));
152 r = pContextMenu->Install();
153 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to Install.", GetErrorMessage(r));
155 pContextMenu->AcquireHandle();
156 pContextMenu->SetTouchPressThreshold(TOUCH_PRESS_THRESHOLD_INSENSITIVE);
158 if (pContextMenu->GetAccessibilityContainer() != null)
160 pContextMenu->GetAccessibilityContainer()->Activate(true);
161 pContextMenu->GetAccessibilityContainer()->AddListener(*pContextMenu);
164 if (style == CONTEXT_MENU_CORE_STYLE_LIST)
166 float minWidth, minHeight; // for visible scrollbar when scrollable
167 GET_SHAPE_CONFIG(CONTEXTMENU::LIST_MIN_WIDTH, _CONTROL_ORIENTATION_PORTRAIT, minWidth);
168 GET_SHAPE_CONFIG(CONTEXTMENU::LIST_ITEM_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, minHeight);
169 pContextMenu->__pScrollPanel = _ScrollPanel::CreateScrollPanelN(FloatRectangle(0.0f, 0.0f, minWidth, minHeight), SCROLL_PANEL_SCROLL_DIRECTION_VERTICAL, false, false);
170 pContextMenu->__pScrollPanel->SetTouchPressThreshold(TOUCH_PRESS_THRESHOLD_INSENSITIVE);
172 _Scroll* pScroll = pContextMenu->__pScrollPanel->GetScrollBar();
173 SysTryCatch(NID_UI_CTRL, pScroll, , E_INVALID_STATE, "[E_INVALID_STATE] _Scroll isn't constructed");
174 pScroll->SetContextMenuScrollType(true);
176 pContextMenu->AttachChild(*(pContextMenu->__pScrollPanel));
188 _ContextMenu::GetScrollPanel(void)
190 return __pScrollPanel;
194 _ContextMenu::Install(void)
196 result r = E_SUCCESS;
198 // load bitmap of a background and arrow
200 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to load bitmap.");
202 r = __actionId.Construct();
203 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to construct arraylist.");
205 if (__style == CONTEXT_MENU_CORE_STYLE_LIST)
207 if (__anchorPoint.Equals(FloatPoint(-1.0f ,-1.0f)))
\r
209 _IContextMenuPresenter* pPresenter = new (std::nothrow) _OptionMenuListPresenter(this);
\r
210 SysTryReturnResult(NID_UI_CTRL, pPresenter != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
\r
212 SetPresenter(*pPresenter);
\r
214 r = pPresenter->Install();
\r
218 _IContextMenuPresenter* pPresenter = new (std::nothrow) _ContextMenuListPresenter(this);
219 SysTryReturnResult(NID_UI_CTRL, pPresenter != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
221 SetPresenter(*pPresenter);
223 r = pPresenter->Install();
228 _IContextMenuPresenter* pPresenter = new (std::nothrow) _ContextMenuGridPresenter(this);
229 SysTryReturnResult(NID_UI_CTRL, pPresenter != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
231 SetPresenter(*pPresenter);
233 r = pPresenter->Install();
240 _ContextMenu::Initialize(void)
242 FloatDimension screen = _ControlManager::GetInstance()->GetScreenSizeF();
243 result r = E_SUCCESS;
245 Color backgroundColor;
246 Color backgroundSelectedColor;
248 Color itemTextSelectedColor;
250 r = SetBounds(FloatRectangle(0.0f, 0.0f, screen.width, screen.height));
251 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "SetBounds failed.");
256 GET_COLOR_CONFIG(CONTEXTMENU::BG_NORMAL, backgroundColor);
257 GET_COLOR_CONFIG(CONTEXTMENU::ITEM_BG_PRESSED, backgroundSelectedColor);
258 GET_COLOR_CONFIG(CONTEXTMENU::ITEM_TEXT_NORMAL, itemTextColor);
259 GET_COLOR_CONFIG(CONTEXTMENU::ITEM_TEXT_PRESSED, itemTextSelectedColor);
261 __backgroundColor = backgroundColor;
262 __itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL] = backgroundColor;
263 __itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED] = backgroundSelectedColor;
264 __textColor[CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL] = itemTextColor;
265 __textColor[CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED] = itemTextSelectedColor;
267 if (GetVisualElement() != null)
269 GetVisualElement()->SetSurfaceOpaque(false);
277 _ContextMenu::SetPresenter(const _IContextMenuPresenter& ContextMenuPresenter)
279 __pContextMenuPresenter = const_cast <_IContextMenuPresenter*>(&ContextMenuPresenter);
285 _ContextMenu::OnDraw()
287 __pContextMenuPresenter->Draw();
289 if(unlikely((_AccessibilityManager::IsActivated())))
291 _AccessibilityManager::GetInstance()->RequestAutoReading(_ACCESSIBILITY_AUTO_READING_MODE_FIRST_ITEM);
296 _ContextMenu::OnAttachedToMainTree(void)
298 result r = E_SUCCESS;
300 __layout = _ControlManager::GetInstance()->GetOrientation();
301 __isAttachedToMainTree = true;
302 _Control* pOwner = GetOwner();
305 _Frame* pFrame = dynamic_cast<_Frame*>(_ControlManager::GetInstance()->GetCurrentFrame());
306 SysTryReturn(NID_UI_CTRL, pFrame != null, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Current frame instance is not available.");
308 _Form* pForm = pFrame->GetCurrentForm();
309 pForm != null ? SetOwner(pForm) : SetOwner(pFrame);
311 GET_SHAPE_CONFIG(CONTEXTMENU::ITEM_MAX_COUNT, __layout, __showItemMaxCount);
315 pOwner->LockInputEvent();
318 AdjustDropPosition();
320 if (GetItemCount() <= 0)
322 __pContextMenuPresenter->CalculateShowItemCount();
325 __pContextMenuPresenter->CalculateWindowRect();
329 SetVisibleState(true);
331 if (__style == CONTEXT_MENU_CORE_STYLE_LIST)
333 SetTouchCapture(false, false);
337 SetTouchCapture(true, false);
340 SetAllAccessibilityElement();
342 _VisualElement* pVisualElement = GetVisualElement();
343 FloatRectangle pBounds = pVisualElement->GetBounds();
344 float oldBoundsX = pBounds.x;
345 float oldBoundsY = pBounds.y;
346 float distanceX = 0.0f;
347 float distanceY = 0.0f;
349 GET_SHAPE_CONFIG(CONTEXTMENU::APPEARING_ANIMATION_DISTANCE_X, __layout, distanceX);
350 GET_SHAPE_CONFIG(CONTEXTMENU::APPEARING_ANIMATION_DISTANCE_Y, __layout, distanceY);
352 switch(GetDropPosition())
354 case CONTEXT_MENU_CORE_DROP_POSITION_UP:
355 pBounds.y += distanceY;
357 case CONTEXT_MENU_CORE_DROP_POSITION_DOWN:
358 pBounds.y -= distanceY;
360 case CONTEXT_MENU_CORE_DROP_POSITION_LEFT:
361 pBounds.x += distanceX;
363 case CONTEXT_MENU_CORE_DROP_POSITION_RIGHT:
364 pBounds.x -= distanceX;
370 pVisualElement->SetBounds(pBounds);
371 pVisualElement->SetOpacity(0.0f);
373 bool enable = pVisualElement->IsImplicitAnimationEnabled();
375 pVisualElement->SetImplicitAnimationEnabled(true);
377 pBounds.x = oldBoundsX;
378 pBounds.y = oldBoundsY;
379 pVisualElement->SetBounds(pBounds);
380 pVisualElement->SetOpacity(1.0f);
382 pVisualElement->SetImplicitAnimationEnabled(enable);
388 _ContextMenu::OnDetachingFromMainTree(void)
390 result r = E_SUCCESS;
392 ReleaseTouchCapture();
394 _Control* pOwner = GetOwner();
397 pOwner->UnlockInputEvent();
400 __isAttachedToMainTree = false;
406 _ContextMenu::AddItem(const Base::String& text, int actionId, const Bitmap* pNormalBitmap, const Bitmap* pPressedBitmap,
407 const Bitmap* pHighlightedBitmap)
409 result r = E_SUCCESS;
411 r = __pContextMenuPresenter->AddItem(text, actionId, pNormalBitmap, pPressedBitmap, pHighlightedBitmap);
412 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to add a item.");
414 __actionId.Add(actionId);
416 __pContextMenuPresenter->CalculateShowItemCount();
417 __pContextMenuPresenter->CalculateWindowRect();
423 _ContextMenu::InsertItem(int index, const Base::String& text, int actionId, const Bitmap* pNormalBitmap,
424 const Bitmap* pPressedBitmap,
425 const Bitmap* pHighlightedBitmap)
427 result r = E_SUCCESS;
429 r = __pContextMenuPresenter->InsertItem(index, text, actionId, pNormalBitmap, pPressedBitmap, pHighlightedBitmap);
430 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to insert a item.");
432 __actionId.InsertAt(actionId, index);
434 __pContextMenuPresenter->CalculateShowItemCount();
435 __pContextMenuPresenter->CalculateWindowRect();
441 _ContextMenu::SetItem(int index, const Base::String& text, int actionId, const Bitmap* pNormalBitmap,
442 const Bitmap* pPressedBitmap, const Bitmap* pHighlightedBitmap)
444 result r = E_SUCCESS;
446 r = __pContextMenuPresenter->SetItem(index, text, actionId, pNormalBitmap, pPressedBitmap, pHighlightedBitmap);
447 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to set a item.");
449 __actionId.SetAt(actionId, index);
451 __pContextMenuPresenter->CalculateWindowRect();
457 _ContextMenu::RemoveItemAt(int index)
459 result r = E_SUCCESS;
461 r = __pContextMenuPresenter->DeleteItem(index);
462 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to remove a item.");
464 __actionId.RemoveAt(index);
466 __pContextMenuPresenter->CalculateShowItemCount();
467 __pContextMenuPresenter->CalculateWindowRect();
473 _ContextMenu::RemoveAllItems(void)
475 result r = E_SUCCESS;
477 r = __pContextMenuPresenter->DeleteItemAll();
478 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to remove all items.");
480 __actionId.RemoveAll();
482 __pContextMenuPresenter->CalculateShowItemCount();
483 __pContextMenuPresenter->CalculateWindowRect();
489 _ContextMenu::GetItemCount(void) const
491 return __actionId.GetCount();
495 _ContextMenu::GetItemIndexAt(int actionId) const
497 int count = __actionId.GetCount();
499 for (int i = 0; i < count; i++)
501 int index = GetItemActionIdAt(i);
503 if (actionId == index)
513 _ContextMenu::GetItemActionIdAt(int index) const
515 int count = __actionId.GetCount();
518 if (count <= 0 || index >= count)
523 __actionId.GetAt(index, actionId);
529 _ContextMenu::SetAnchorPosition(float x, float y)
534 if (__align == CONTEXT_MENU_CORE_ALIGN_AUTO)
536 AdjustDropPosition();
539 __pContextMenuPresenter->CalculateWindowRect();
544 _ContextMenu::GetAnchorPosition(void) const
546 return __anchorPoint;
550 _ContextMenu::SetWindowRect(const FloatRectangle& rect)
558 _ContextMenu::GetWindowRect(void) const
564 _ContextMenu::SetBodyRect(const FloatRectangle& rect)
572 _ContextMenu::GetBodyRect(void) const
578 _ContextMenu::SetArrowRect(const FloatRectangle& rect)
586 _ContextMenu::GetArrowRect(void) const
592 _ContextMenu::SetItemRect(const FloatRectangle& rect)
600 _ContextMenu::GetItemRect(void) const
606 _ContextMenu::SetPropertyMaxVisibleItemsCount(const Variant& count)
608 int showCount = count.ToInt();
612 SysLogException(NID_UI_CTRL, E_INVALID_ARG, "Count is invalid.");
613 return E_INVALID_ARG;
617 __showItemCount = showCount;
623 _ContextMenu::GetPropertyMaxVisibleItemsCount(void) const
625 return Tizen::Ui::Variant(__showItemCount);
629 _ContextMenu::GetShowItemCount(void) const
631 Variant count = GetProperty("maxVisibleItemsCount");
633 return count.ToInt();
637 _ContextMenu::GetShowItemMaxCount(void) const
639 return __showItemMaxCount;
643 _ContextMenu::SetShowItemCount(int count)
647 r = SetProperty("maxVisibleItemsCount", Variant(count));
648 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to set property.");
650 if (__style == CONTEXT_MENU_CORE_STYLE_LIST)
652 r = __pContextMenuPresenter->CalculateWindowRect();
653 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to calculate window.");
660 _ContextMenu::SetPropertyColor(const Variant& color)
662 __backgroundColor = color.ToColor();
664 LoadColorReplacedBitmap(__backgroundColor);
670 _ContextMenu::GetPropertyColor(void) const
672 return Tizen::Ui::Variant(__backgroundColor);
676 _ContextMenu::SetColor(const Graphics::Color& color)
678 return SetProperty("color", Variant(color));
682 _ContextMenu::GetColor(void) const
684 Variant color = GetProperty("color");
686 return color.ToColor();
690 _ContextMenu::SetPropertyNormalItemColor(const Variant& color)
692 __itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL] = color.ToColor();
694 return __pContextMenuPresenter->ApplyColorProperty();
698 _ContextMenu::GetPropertyNormalItemColor(void) const
700 return Tizen::Ui::Variant(__itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL]);
704 _ContextMenu::SetPropertyPressedItemColor(const Variant& color)
706 __itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED] = color.ToColor();
708 return __pContextMenuPresenter->ApplyColorProperty();
712 _ContextMenu::GetPropertyPressedItemColor(void) const
714 return Tizen::Ui::Variant(__itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED]);
718 _ContextMenu::SetPropertyHighlightedItemColor(const Variant & color)
720 __itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_HIGHLIGHTED] = color.ToColor();
722 return __pContextMenuPresenter->ApplyColorProperty();
726 _ContextMenu::GetPropertyHighlightedItemColor(void) const
728 return Tizen::Ui::Variant(__itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_HIGHLIGHTED]);
732 _ContextMenu::SetItemColor(enum ContextMenuCoreItemStatus status, const Graphics::Color& color)
734 result r = E_SUCCESS;
736 if (status == CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL)
738 r = SetProperty("normalItemColor", Variant(color));
740 else if (status == CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED)
742 r = SetProperty("pressedItemColor", Variant(color));
746 r = SetProperty("highlightedItemColor", Variant(color));
753 _ContextMenu::GetItemColor(enum ContextMenuCoreItemStatus status) const
757 if (status == CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL)
759 Variant color = GetProperty("normalItemColor");
760 itemColor = color.ToColor();
763 else if (status == CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED)
765 Variant color = GetProperty("pressedItemColor");
766 itemColor = color.ToColor();
771 Variant color = GetProperty("highlightedItemColor");
772 itemColor = color.ToColor();
780 _ContextMenu::SetPropertyNormalItemTextColor(const Variant& color)
782 __textColor[CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL] = color.ToColor();
784 return __pContextMenuPresenter->ApplyColorProperty();
788 _ContextMenu::GetPropertyNormalItemTextColor(void) const
790 return Tizen::Ui::Variant(__textColor[CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL]);
794 _ContextMenu::SetPropertyPressedItemTextColor(const Variant& color)
796 __textColor[CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED] = color.ToColor();
798 return __pContextMenuPresenter->ApplyColorProperty();
802 _ContextMenu::GetPropertyPressedItemTextColor(void) const
804 return Tizen::Ui::Variant(__textColor[CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED]);
808 _ContextMenu::SetPropertyHighlightedItemTextColor(const Variant & color)
810 __textColor[CONTEXT_MENU_CORE_ITEM_STATUS_HIGHLIGHTED] = color.ToColor();
812 return __pContextMenuPresenter->ApplyColorProperty();
816 _ContextMenu::GetPropertyHighlightedItemTextColor(void) const
818 return Tizen::Ui::Variant(__textColor[CONTEXT_MENU_CORE_ITEM_STATUS_HIGHLIGHTED]);
822 _ContextMenu::SetTextColor(enum ContextMenuCoreItemStatus status, const Graphics::Color& color)
824 result r = E_SUCCESS;
826 if (status == CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL)
828 r = SetProperty("normalItemTextColor", Variant(color));
830 else if (status == CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED)
832 r = SetProperty("pressedItemTextColor", Variant(color));
836 r = SetProperty("highlightedItemTextColor", Variant(color));
844 _ContextMenu::GetTextColor(enum ContextMenuCoreItemStatus status) const
848 if (status == CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL)
850 Variant color = GetProperty("normalItemTextColor");
851 textColor = color.ToColor();
854 else if (status == CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED)
856 Variant color = GetProperty("pressedItemTextColor");
857 textColor = color.ToColor();
862 Variant color = GetProperty("highlightedItemTextColor");
863 textColor = color.ToColor();
870 _ContextMenu::AddActionEventListener(const Tizen::Ui::Controls::_IActionEventListener& listener)
872 result r = E_SUCCESS;
874 if (__pActionEvent == null)
876 __pActionEvent = _ActionEvent::CreateInstanceN(*this);
877 SysTryReturn(NID_UI_CTRL, __pActionEvent != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
878 "[E_OUT_OF_MEMORY] The memory is insufficient.")
880 r = __pActionEvent->AddListener(listener);
881 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to remove an action event listener.")
887 delete __pActionEvent;
888 __pActionEvent = null;
893 _ContextMenu::RemoveActionEventListener(const Tizen::Ui::Controls::_IActionEventListener& listener)
895 SysTryReturn(NID_UI_CTRL, __pActionEvent != null, E_INVALID_STATE, E_INVALID_STATE,
896 "[E_INVALID_STATE] The action event instance isn't constructed.")
898 result r = E_SUCCESS;
900 r = __pActionEvent->RemoveListener(listener);
901 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to remove an action event listener")
906 Tizen::Ui::Controls::_ActionEvent*
907 _ContextMenu::GetActionEvent(void) const
909 return __pActionEvent;
913 _ContextMenu::LoadBitmap(void)
915 Color backgroundColor;
918 if (__pBackgroundEffectBitmap != null)
920 delete __pBackgroundEffectBitmap;
921 __pBackgroundEffectBitmap = null;
924 for (int i = 0; i < CONTEXT_MENU_CORE_DROP_POSITION_MAX; i++)
926 if (__pArrowEffectBitmap[i] != null)
928 delete __pArrowEffectBitmap[i];
929 __pArrowEffectBitmap[i] = null;
933 backgroundColor = GetColor();
937 r = GET_BITMAP_CONFIG_N(CONTEXTMENU::ANCHOR_EFFECT_UP, BITMAP_PIXEL_FORMAT_ARGB8888,
938 __pArrowEffectBitmap[CONTEXT_MENU_CORE_DROP_POSITION_UP]);
939 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
941 r = GET_BITMAP_CONFIG_N(CONTEXTMENU::ANCHOR_EFFECT_DOWN, BITMAP_PIXEL_FORMAT_ARGB8888,
942 __pArrowEffectBitmap[CONTEXT_MENU_CORE_DROP_POSITION_DOWN]);
943 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
945 r = GET_BITMAP_CONFIG_N(CONTEXTMENU::ANCHOR_EFFECT_LEFT, BITMAP_PIXEL_FORMAT_ARGB8888,
946 __pArrowEffectBitmap[CONTEXT_MENU_CORE_DROP_POSITION_LEFT]);
947 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
949 r = GET_BITMAP_CONFIG_N(CONTEXTMENU::ANCHOR_EFFECT_RIGHT, BITMAP_PIXEL_FORMAT_ARGB8888,
950 __pArrowEffectBitmap[CONTEXT_MENU_CORE_DROP_POSITION_RIGHT]);
951 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
953 r = GET_BITMAP_CONFIG_N(CONTEXTMENU::BG_OUTLINE_EFFECT_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pBackgroundEffectBitmap);
954 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
956 r = LoadColorReplacedBitmap(backgroundColor);
957 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
962 delete __pBackgroundEffectBitmap;
963 __pBackgroundEffectBitmap = null;
965 for (int i = 0; i < CONTEXT_MENU_CORE_DROP_POSITION_MAX; i++)
968 delete __pArrowEffectBitmap[i];
969 __pArrowEffectBitmap[i] = null;
976 _ContextMenu::LoadColorReplacedBitmap(const Tizen::Graphics::Color& color)
978 Bitmap* ptempNormalBitmap = null;
981 if (__pBackgroundNormalBitmap != null)
983 delete __pBackgroundNormalBitmap;
984 __pBackgroundNormalBitmap = null;
987 for (int i = 0; i < CONTEXT_MENU_CORE_DROP_POSITION_MAX; i++)
989 if (__pArrowNormalBitmap[i] != null)
991 delete __pArrowNormalBitmap[i];
992 __pArrowNormalBitmap[i] = null;
997 r = GET_BITMAP_CONFIG_N(CONTEXTMENU::ANCHOR_NORMAL_UP, BITMAP_PIXEL_FORMAT_ARGB8888, ptempNormalBitmap);
998 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
999 __pArrowNormalBitmap[CONTEXT_MENU_CORE_DROP_POSITION_UP] = _BitmapImpl::GetColorReplacedBitmapN(*ptempNormalBitmap,
1000 Color::GetColor(COLOR_ID_MAGENTA), color);
1001 SysTryCatch(NID_UI_CTRL, __pArrowNormalBitmap[CONTEXT_MENU_CORE_DROP_POSITION_UP] != null, , GetLastResult(),
1002 "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1003 delete ptempNormalBitmap;
1004 ptempNormalBitmap = null;
1006 r = GET_BITMAP_CONFIG_N(CONTEXTMENU::ANCHOR_NORMAL_DOWN, BITMAP_PIXEL_FORMAT_ARGB8888, ptempNormalBitmap);
1007 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
1008 __pArrowNormalBitmap[CONTEXT_MENU_CORE_DROP_POSITION_DOWN] = _BitmapImpl::GetColorReplacedBitmapN(*ptempNormalBitmap,
1009 Color::GetColor(COLOR_ID_MAGENTA), color);
1010 SysTryCatch(NID_UI_CTRL, __pArrowNormalBitmap[CONTEXT_MENU_CORE_DROP_POSITION_DOWN] != null, , GetLastResult(),
1011 "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1012 delete ptempNormalBitmap;
1013 ptempNormalBitmap = null;
1015 r = GET_BITMAP_CONFIG_N(CONTEXTMENU::ANCHOR_NORMAL_LEFT, BITMAP_PIXEL_FORMAT_ARGB8888, ptempNormalBitmap);
1016 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
1017 __pArrowNormalBitmap[CONTEXT_MENU_CORE_DROP_POSITION_LEFT] = _BitmapImpl::GetColorReplacedBitmapN(*ptempNormalBitmap,
1018 Color::GetColor(COLOR_ID_MAGENTA), color);
1019 SysTryCatch(NID_UI_CTRL, __pArrowNormalBitmap[CONTEXT_MENU_CORE_DROP_POSITION_LEFT] != null, , GetLastResult(),
1020 "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1021 delete ptempNormalBitmap;
1022 ptempNormalBitmap = null;
1024 r = GET_BITMAP_CONFIG_N(CONTEXTMENU::ANCHOR_NORMAL_RIGHT, BITMAP_PIXEL_FORMAT_ARGB8888, ptempNormalBitmap);
1025 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
1026 __pArrowNormalBitmap[CONTEXT_MENU_CORE_DROP_POSITION_RIGHT] = _BitmapImpl::GetColorReplacedBitmapN(*ptempNormalBitmap,
1027 Color::GetColor(COLOR_ID_MAGENTA), color);
1028 SysTryCatch(NID_UI_CTRL, __pArrowNormalBitmap[CONTEXT_MENU_CORE_DROP_POSITION_RIGHT] != null, , GetLastResult(),
1029 "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1030 delete ptempNormalBitmap;
1031 ptempNormalBitmap = null;
1033 r = GET_BITMAP_CONFIG_N(CONTEXTMENU::BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, ptempNormalBitmap);
1034 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
1035 __pBackgroundNormalBitmap = _BitmapImpl::GetColorReplacedBitmapN(*ptempNormalBitmap, Color::GetColor(COLOR_ID_MAGENTA), color);
1036 SysTryCatch(NID_UI_CTRL, __pBackgroundNormalBitmap != null, , GetLastResult(), "[%s] Propagating.",
1037 GetErrorMessage(GetLastResult()));
1038 delete ptempNormalBitmap;
1043 delete ptempNormalBitmap;
1045 delete __pBackgroundNormalBitmap;
1046 __pBackgroundNormalBitmap = null;
1048 for (int i = 0; i < CONTEXT_MENU_CORE_DROP_POSITION_MAX; i++)
1050 delete __pArrowNormalBitmap[i];
1051 __pArrowNormalBitmap[i] = null;
1058 _ContextMenu::GetArrowNormalBitmap(ContextMenuCoreDropPosition dropPosition) const
1060 if (dropPosition == CONTEXT_MENU_CORE_DROP_POSITION_INVALID || dropPosition == CONTEXT_MENU_CORE_DROP_POSITION_MAX)
1065 return __pArrowNormalBitmap[dropPosition];
1069 _ContextMenu::GetArrowEffectBitmap(ContextMenuCoreDropPosition dropPosition) const
1071 if (dropPosition == CONTEXT_MENU_CORE_DROP_POSITION_INVALID || dropPosition == CONTEXT_MENU_CORE_DROP_POSITION_MAX)
1076 return __pArrowEffectBitmap[dropPosition];
1080 _ContextMenu::GetBackgroundNormalBitmap(void) const
1082 return __pBackgroundNormalBitmap;
1086 _ContextMenu::GetBackgroundEffectBitmap(void) const
1088 return __pBackgroundEffectBitmap;
1091 enum ContextMenuCoreDropPosition
1092 _ContextMenu::GetDropPosition(void) const
1094 return __dropPosition;
1098 _ContextMenu::AdjustDropPosition(void)
1100 FloatDimension screen = _ControlManager::GetInstance()->GetScreenSizeF();
1102 if (__align == CONTEXT_MENU_CORE_ALIGN_UP)
1104 __dropPosition = CONTEXT_MENU_CORE_DROP_POSITION_UP;
1106 else if (__align == CONTEXT_MENU_CORE_ALIGN_DOWN)
1108 __dropPosition = CONTEXT_MENU_CORE_DROP_POSITION_DOWN;
1110 else if (__align == CONTEXT_MENU_CORE_ALIGN_LEFT)
1112 __dropPosition = CONTEXT_MENU_CORE_DROP_POSITION_LEFT;
1114 else if (__align == CONTEXT_MENU_CORE_ALIGN_RIGHT)
1116 __dropPosition = CONTEXT_MENU_CORE_DROP_POSITION_RIGHT;
1120 if (__layout == _CONTROL_ORIENTATION_LANDSCAPE)
1122 screen.SetSize(screen.height, screen.width);
1125 if (screen.height > screen.width)
1127 if ((screen.height / 2.0f) > __anchorPoint.y)
1129 __dropPosition = CONTEXT_MENU_CORE_DROP_POSITION_DOWN;
1133 __dropPosition = CONTEXT_MENU_CORE_DROP_POSITION_UP;
1138 if ((screen.width / 2.0f) > __anchorPoint.x)
1140 __dropPosition = CONTEXT_MENU_CORE_DROP_POSITION_RIGHT;
1144 __dropPosition = CONTEXT_MENU_CORE_DROP_POSITION_LEFT;
1150 _UiTouchEventDelivery
1151 _ContextMenu::OnPreviewTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
1153 return __pContextMenuPresenter->OnPreviewTouchPressed(source, touchinfo);
1157 _ContextMenu::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
1159 return __pContextMenuPresenter->OnTouchPressed(source, touchinfo);
1162 _UiTouchEventDelivery
1163 _ContextMenu::OnPreviewTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
1165 return __pContextMenuPresenter->OnPreviewTouchMoved(source, touchinfo);
1169 _ContextMenu::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
1171 return __pContextMenuPresenter->OnTouchMoved(source, touchinfo);
1174 _UiTouchEventDelivery
1175 _ContextMenu::OnPreviewTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
1177 return __pContextMenuPresenter->OnPreviewTouchReleased(source, touchinfo);
1181 _ContextMenu::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
1183 return __pContextMenuPresenter->OnTouchReleased(source, touchinfo);
1187 _ContextMenu::OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
1189 __pContextMenuPresenter->OnTouchCanceled(source, touchinfo);
1191 SetVisibleState(false);
1197 _ContextMenu::OnFontChanged(Tizen::Graphics::Font* pFont)
1199 return __pContextMenuPresenter->OnFontChanged(pFont);
1203 _ContextMenu::OnFontInfoRequested(unsigned long& style, float& size)
1205 return __pContextMenuPresenter->OnFontInfoRequested(style, size);
1209 _ContextMenu::OnVisibleStateChanged(void)
1211 _Window::OnVisibleStateChanged();
1215 _ContextMenu::OnChangeLayout(_ControlOrientation orientation)
1217 GET_SHAPE_CONFIG(CONTEXTMENU::ITEM_MAX_COUNT, orientation, __showItemMaxCount);
1219 if (__isAttachedToMainTree == true)
1221 if (__layout != orientation)
1223 SetVisibleState(false);
1227 __layout = orientation;
1231 _ContextMenu::OnOwnerChanged(_Control* pOldOwner)
1233 if (!__isAttachedToMainTree)
1238 _Control* pOwner = GetOwner();
1240 if (pOldOwner != null)
1242 pOldOwner->UnlockInputEvent();
1247 pOwner->LockInputEvent();
1251 _AccessibilityElement*
1252 _ContextMenu::GetAccessibilityElement(const int mainIndex) const
1254 _AccessibilityElement* pElement = null;
1255 result r = __accessibilityElements.GetAt(mainIndex, pElement);
1256 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed at AccessibilityElement.", GetErrorMessage(r));
1267 _ContextMenu::AddAccessibilityElement(const _AccessibilityElement& element)
1269 __accessibilityElements.Add(const_cast<_AccessibilityElement*>(&element));
1273 _ContextMenu::SetAllAccessibilityElement(void)
1275 RemoveAllAccessibilityElement();
1276 __pContextMenuPresenter->SetAllAccessibilityElement();
1280 _ContextMenu::OnAccessibilityFocusMovedNext(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1286 _ContextMenu::OnAccessibilityFocusMovedPrevious(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1292 _ContextMenu::OnAccessibilityReadElement(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1298 _ContextMenu::OnAccessibilityReadingElement(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1304 _ContextMenu::OnAccessibilityFocusIn(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1310 _ContextMenu::OnAccessibilityFocusOut(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1316 _ContextMenu::OnAccessibilityActionPerformed(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1318 SetVisibleState(false);
1324 _ContextMenu::OnAccessibilityValueIncreased(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1330 _ContextMenu::OnAccessibilityValueDecreased(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1336 _ContextMenu::RemoveAllAccessibilityElement(void)
1338 _AccessibilityContainer* pAccessibilityContainer = GetAccessibilityContainer();
1339 if (pAccessibilityContainer && pAccessibilityContainer->IsActivated())
1341 pAccessibilityContainer->RemoveAllElement();
1345 _ContextMenuItemInfo
1346 _ContextMenu::GetItemFromPosition(const FloatPoint& position) const
1348 return __pContextMenuPresenter->GetItemFromPosition(position);
1351 _ContextMenuItemInfo
1352 _ContextMenu::FindItem(int index) const
1354 return __pContextMenuPresenter->FindItem(index);
1358 _ContextMenu::SetTopDrawnItemIndex(int index)
1360 return __pContextMenuPresenter->SetTopDrawnItemIndex(index);
1364 _ContextMenu::GetLayout(void) const
1369 }}} // Tizen::Ui: Control