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 , __rotation(_CONTROL_ROTATION_0)
69 , __pScrollPanel(null)
71 __backgroundColor = Color(255, 255, 255, 255);
73 __textColor[CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL] = Color(255, 255, 255, 255);
74 __textColor[CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED] = Color(255, 255, 255, 255);
75 __textColor[CONTEXT_MENU_CORE_ITEM_STATUS_HIGHLIGHTED] = Color(255, 255, 255, 255);
77 __itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL] = Color(255, 255, 255, 255);
78 __itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED] = Color(255, 255, 255, 255);
79 __itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_HIGHLIGHTED] = Color(255, 255, 255, 255);
81 for (int i = 0; i < CONTEXT_MENU_CORE_DROP_POSITION_MAX; i++)
83 __pArrowNormalBitmap[i] = null;
84 __pArrowEffectBitmap[i] = null;
87 GET_SHAPE_CONFIG(CONTEXTMENU::ITEM_MAX_COUNT, __layout, __showItemMaxCount);
90 _ContextMenu::~_ContextMenu(void)
92 if (__isAttachedToMainTree && GetOwner() != null)
94 GetOwner()->UnlockInputEvent();
98 __pScrollPanel->DetachAllChildren();
99 DetachChild(*__pScrollPanel);
100 delete __pScrollPanel;
101 __pScrollPanel = null;
104 delete __pContextMenuPresenter;
105 __pContextMenuPresenter = null;
107 if (__pBackgroundNormalBitmap != null)
109 delete __pBackgroundNormalBitmap;
110 __pBackgroundNormalBitmap = null;
113 if (__pBackgroundEffectBitmap != null)
115 delete __pBackgroundEffectBitmap;
116 __pBackgroundEffectBitmap = null;
121 delete __pActionEvent;
122 __pActionEvent = null;
125 for (int i = 0; i < CONTEXT_MENU_CORE_DROP_POSITION_MAX; i++)
127 delete __pArrowNormalBitmap[i];
128 __pArrowNormalBitmap[i] = null;
130 delete __pArrowEffectBitmap[i];
131 __pArrowEffectBitmap[i] = null;
134 __actionId.RemoveAll();
136 RemoveAllAccessibilityElement();
140 _ContextMenu::CreateContextMenuN(const FloatPoint& point, enum ContextMenuCoreStyle style, enum ContextMenuCoreAlign contextMenuAlign)
142 _ContextMenu* pContextMenu = new (std::nothrow) _ContextMenu(point, style, contextMenuAlign);
143 SysTryReturn(NID_UI_CTRL, pContextMenu != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
145 result r = E_SUCCESS;
147 r = pContextMenu->CreateRootVisualElement();
148 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
150 pContextMenu->SetFocusable(false);
152 r = pContextMenu->Initialize();
153 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to Initialize.", GetErrorMessage(r));
155 r = pContextMenu->Install();
156 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to Install.", GetErrorMessage(r));
158 pContextMenu->AcquireHandle();
159 pContextMenu->SetTouchPressThreshold(TOUCH_PRESS_THRESHOLD_INSENSITIVE);
161 if (pContextMenu->GetAccessibilityContainer() != null)
163 pContextMenu->GetAccessibilityContainer()->Activate(true);
164 pContextMenu->GetAccessibilityContainer()->AddListener(*pContextMenu);
167 if (style == CONTEXT_MENU_CORE_STYLE_LIST)
169 float minWidth, minHeight; // for visible scrollbar when scrollable
170 GET_SHAPE_CONFIG(CONTEXTMENU::LIST_MIN_WIDTH, _CONTROL_ORIENTATION_PORTRAIT, minWidth);
171 GET_SHAPE_CONFIG(CONTEXTMENU::LIST_ITEM_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, minHeight);
172 pContextMenu->__pScrollPanel = _ScrollPanel::CreateScrollPanelN(FloatRectangle(0.0f, 0.0f, minWidth, minHeight), SCROLL_PANEL_SCROLL_DIRECTION_VERTICAL, false, false);
173 pContextMenu->__pScrollPanel->SetTouchPressThreshold(TOUCH_PRESS_THRESHOLD_INSENSITIVE);
174 pContextMenu->__pScrollPanel->SetFocusable(false);
176 _Scroll* pScroll = pContextMenu->__pScrollPanel->GetScrollBar();
177 SysTryCatch(NID_UI_CTRL, pScroll, , E_INVALID_STATE, "[E_INVALID_STATE] _Scroll isn't constructed");
178 pScroll->SetContextMenuScrollType(true);
180 pContextMenu->AttachChild(*(pContextMenu->__pScrollPanel));
192 _ContextMenu::GetScrollPanel(void)
194 return __pScrollPanel;
198 _ContextMenu::Install(void)
200 result r = E_SUCCESS;
202 // load bitmap of a background and arrow
204 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to load bitmap.");
206 r = __actionId.Construct();
207 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to construct arraylist.");
209 if (__style == CONTEXT_MENU_CORE_STYLE_LIST)
211 _IContextMenuPresenter* pPresenter = new (std::nothrow) _ContextMenuListPresenter(this);
212 SysTryReturnResult(NID_UI_CTRL, pPresenter != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
214 SetPresenter(*pPresenter);
216 r = pPresenter->Install();
220 _IContextMenuPresenter* pPresenter = new (std::nothrow) _ContextMenuGridPresenter(this);
221 SysTryReturnResult(NID_UI_CTRL, pPresenter != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
223 SetPresenter(*pPresenter);
225 r = pPresenter->Install();
232 _ContextMenu::Initialize(void)
234 FloatDimension screen = _ControlManager::GetInstance()->GetScreenSizeF();
235 result r = E_SUCCESS;
237 Color backgroundColor;
238 Color backgroundSelectedColor;
240 Color itemTextSelectedColor;
242 r = SetBounds(FloatRectangle(0.0f, 0.0f, screen.width, screen.height));
243 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "SetBounds failed.");
248 GET_COLOR_CONFIG(CONTEXTMENU::BG_NORMAL, backgroundColor);
249 GET_COLOR_CONFIG(CONTEXTMENU::ITEM_BG_PRESSED, backgroundSelectedColor);
250 GET_COLOR_CONFIG(CONTEXTMENU::ITEM_TEXT_NORMAL, itemTextColor);
251 GET_COLOR_CONFIG(CONTEXTMENU::ITEM_TEXT_PRESSED, itemTextSelectedColor);
253 __backgroundColor = backgroundColor;
254 __itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL] = backgroundColor;
255 __itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED] = backgroundSelectedColor;
256 __textColor[CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL] = itemTextColor;
257 __textColor[CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED] = itemTextSelectedColor;
259 if (GetVisualElement() != null)
261 GetVisualElement()->SetSurfaceOpaque(false);
269 _ContextMenu::SetPresenter(const _IContextMenuPresenter& ContextMenuPresenter)
271 __pContextMenuPresenter = const_cast <_IContextMenuPresenter*>(&ContextMenuPresenter);
277 _ContextMenu::OnDraw()
279 __pContextMenuPresenter->Draw();
281 if(unlikely((_AccessibilityManager::IsActivated())))
283 _AccessibilityManager::GetInstance()->RequestAutoReading(_ACCESSIBILITY_AUTO_READING_MODE_FIRST_ITEM);
288 _ContextMenu::OnAttachedToMainTree(void)
290 result r = E_SUCCESS;
292 __layout = _ControlManager::GetInstance()->GetOrientation();
293 __rotation = _ControlManager::GetInstance()->GetScreenRotation();
294 __isAttachedToMainTree = true;
295 _Control* pOwner = GetOwner();
298 _Frame* pFrame = dynamic_cast<_Frame*>(_ControlManager::GetInstance()->GetCurrentFrame());
299 SysTryReturn(NID_UI_CTRL, pFrame != null, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Current frame instance is not available.");
301 _Form* pForm = pFrame->GetCurrentForm();
302 pForm != null ? SetOwner(pForm) : SetOwner(pFrame);
304 GET_SHAPE_CONFIG(CONTEXTMENU::ITEM_MAX_COUNT, __layout, __showItemMaxCount);
308 pOwner->LockInputEvent();
311 AdjustDropPosition();
313 if (GetItemCount() <= 0)
315 __pContextMenuPresenter->CalculateShowItemCount();
318 r = __pContextMenuPresenter->CalculateWindowRect();
319 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
323 SetVisibleState(true);
325 if (__style == CONTEXT_MENU_CORE_STYLE_LIST)
327 SetTouchCapture(false, false);
331 SetTouchCapture(true, false);
334 SetAllAccessibilityElement();
336 _VisualElement* pVisualElement = GetVisualElement();
337 FloatRectangle pBounds = pVisualElement->GetBounds();
338 float oldBoundsX = pBounds.x;
339 float oldBoundsY = pBounds.y;
340 float distanceX = 0.0f;
341 float distanceY = 0.0f;
343 GET_SHAPE_CONFIG(CONTEXTMENU::APPEARING_ANIMATION_DISTANCE_X, __layout, distanceX);
344 GET_SHAPE_CONFIG(CONTEXTMENU::APPEARING_ANIMATION_DISTANCE_Y, __layout, distanceY);
346 switch(GetDropPosition())
348 case CONTEXT_MENU_CORE_DROP_POSITION_UP:
349 pBounds.y += distanceY;
351 case CONTEXT_MENU_CORE_DROP_POSITION_DOWN:
352 pBounds.y -= distanceY;
354 case CONTEXT_MENU_CORE_DROP_POSITION_LEFT:
355 pBounds.x += distanceX;
357 case CONTEXT_MENU_CORE_DROP_POSITION_RIGHT:
358 pBounds.x -= distanceX;
364 pVisualElement->SetBounds(pBounds);
365 pVisualElement->SetOpacity(0.0f);
367 bool enable = pVisualElement->IsImplicitAnimationEnabled();
369 pVisualElement->SetImplicitAnimationEnabled(true);
371 pBounds.x = oldBoundsX;
372 pBounds.y = oldBoundsY;
373 pVisualElement->SetBounds(pBounds);
374 pVisualElement->SetOpacity(1.0f);
376 pVisualElement->SetImplicitAnimationEnabled(enable);
382 _ContextMenu::OnDetachingFromMainTree(void)
384 result r = E_SUCCESS;
386 ReleaseTouchCapture();
388 _Control* pOwner = GetOwner();
391 pOwner->UnlockInputEvent();
394 __isAttachedToMainTree = false;
400 _ContextMenu::AddItem(const Base::String& text, int actionId, const Bitmap* pNormalBitmap, const Bitmap* pPressedBitmap,
401 const Bitmap* pHighlightedBitmap)
403 result r = E_SUCCESS;
405 r = __pContextMenuPresenter->AddItem(text, actionId, pNormalBitmap, pPressedBitmap, pHighlightedBitmap);
406 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to add a item.");
408 __actionId.Add(actionId);
410 __pContextMenuPresenter->CalculateShowItemCount();
411 __pContextMenuPresenter->CalculateWindowRect();
417 _ContextMenu::InsertItem(int index, const Base::String& text, int actionId, const Bitmap* pNormalBitmap,
418 const Bitmap* pPressedBitmap,
419 const Bitmap* pHighlightedBitmap)
421 result r = E_SUCCESS;
423 r = __pContextMenuPresenter->InsertItem(index, text, actionId, pNormalBitmap, pPressedBitmap, pHighlightedBitmap);
424 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to insert a item.");
426 __actionId.InsertAt(actionId, index);
428 __pContextMenuPresenter->CalculateShowItemCount();
429 __pContextMenuPresenter->CalculateWindowRect();
435 _ContextMenu::SetItem(int index, const Base::String& text, int actionId, const Bitmap* pNormalBitmap,
436 const Bitmap* pPressedBitmap, const Bitmap* pHighlightedBitmap)
438 result r = E_SUCCESS;
440 r = __pContextMenuPresenter->SetItem(index, text, actionId, pNormalBitmap, pPressedBitmap, pHighlightedBitmap);
441 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to set a item.");
443 __actionId.SetAt(actionId, index);
445 __pContextMenuPresenter->CalculateWindowRect();
451 _ContextMenu::RemoveItemAt(int index)
453 result r = E_SUCCESS;
455 r = __pContextMenuPresenter->DeleteItem(index);
456 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to remove a item.");
458 __actionId.RemoveAt(index);
460 __pContextMenuPresenter->CalculateShowItemCount();
461 __pContextMenuPresenter->CalculateWindowRect();
467 _ContextMenu::RemoveAllItems(void)
469 result r = E_SUCCESS;
471 r = __pContextMenuPresenter->DeleteItemAll();
472 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to remove all items.");
474 __actionId.RemoveAll();
476 __pContextMenuPresenter->CalculateShowItemCount();
477 __pContextMenuPresenter->CalculateWindowRect();
483 _ContextMenu::GetItemCount(void) const
485 return __actionId.GetCount();
489 _ContextMenu::GetItemIndexAt(int actionId) const
491 int count = __actionId.GetCount();
493 for (int i = 0; i < count; i++)
495 int index = GetItemActionIdAt(i);
497 if (actionId == index)
507 _ContextMenu::GetItemActionIdAt(int index) const
509 int count = __actionId.GetCount();
512 if (count <= 0 || index >= count)
517 __actionId.GetAt(index, actionId);
523 _ContextMenu::SetAnchorPosition(float x, float y)
528 if (__align == CONTEXT_MENU_CORE_ALIGN_AUTO)
530 AdjustDropPosition();
533 __pContextMenuPresenter->CalculateWindowRect();
538 _ContextMenu::GetAnchorPosition(void) const
540 return __anchorPoint;
544 _ContextMenu::SetWindowRect(const FloatRectangle& rect)
552 _ContextMenu::GetWindowRect(void) const
558 _ContextMenu::SetBodyRect(const FloatRectangle& rect)
566 _ContextMenu::GetBodyRect(void) const
572 _ContextMenu::SetArrowRect(const FloatRectangle& rect)
580 _ContextMenu::GetArrowRect(void) const
586 _ContextMenu::SetItemRect(const FloatRectangle& rect)
594 _ContextMenu::GetItemRect(void) const
600 _ContextMenu::SetPropertyMaxVisibleItemsCount(const Variant& count)
602 int showCount = count.ToInt();
606 SysLogException(NID_UI_CTRL, E_INVALID_ARG, "Count is invalid.");
607 return E_INVALID_ARG;
611 __showItemCount = showCount;
617 _ContextMenu::GetPropertyMaxVisibleItemsCount(void) const
619 return Tizen::Ui::Variant(__showItemCount);
623 _ContextMenu::GetShowItemCount(void) const
625 Variant count = GetProperty("maxVisibleItemsCount");
627 return count.ToInt();
631 _ContextMenu::GetShowItemMaxCount(void) const
633 return __showItemMaxCount;
637 _ContextMenu::SetShowItemCount(int count)
641 r = SetProperty("maxVisibleItemsCount", Variant(count));
642 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to set property.");
644 if (__style == CONTEXT_MENU_CORE_STYLE_LIST)
646 r = __pContextMenuPresenter->CalculateWindowRect();
647 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to calculate window.");
654 _ContextMenu::SetPropertyColor(const Variant& color)
656 __backgroundColor = color.ToColor();
658 LoadColorReplacedBitmap(__backgroundColor);
664 _ContextMenu::GetPropertyColor(void) const
666 return Tizen::Ui::Variant(__backgroundColor);
670 _ContextMenu::SetColor(const Graphics::Color& color)
672 return SetProperty("color", Variant(color));
676 _ContextMenu::GetColor(void) const
678 Variant color = GetProperty("color");
680 return color.ToColor();
684 _ContextMenu::SetPropertyNormalItemColor(const Variant& color)
686 __itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL] = color.ToColor();
688 return __pContextMenuPresenter->ApplyColorProperty();
692 _ContextMenu::GetPropertyNormalItemColor(void) const
694 return Tizen::Ui::Variant(__itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL]);
698 _ContextMenu::SetPropertyPressedItemColor(const Variant& color)
700 __itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED] = color.ToColor();
702 return __pContextMenuPresenter->ApplyColorProperty();
706 _ContextMenu::GetPropertyPressedItemColor(void) const
708 return Tizen::Ui::Variant(__itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED]);
712 _ContextMenu::SetPropertyHighlightedItemColor(const Variant & color)
714 __itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_HIGHLIGHTED] = color.ToColor();
716 return __pContextMenuPresenter->ApplyColorProperty();
720 _ContextMenu::GetPropertyHighlightedItemColor(void) const
722 return Tizen::Ui::Variant(__itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_HIGHLIGHTED]);
726 _ContextMenu::SetItemColor(enum ContextMenuCoreItemStatus status, const Graphics::Color& color)
728 result r = E_SUCCESS;
730 if (status == CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL)
732 r = SetProperty("normalItemColor", Variant(color));
734 else if (status == CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED)
736 r = SetProperty("pressedItemColor", Variant(color));
740 r = SetProperty("highlightedItemColor", Variant(color));
747 _ContextMenu::GetItemColor(enum ContextMenuCoreItemStatus status) const
751 if (status == CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL)
753 Variant color = GetProperty("normalItemColor");
754 itemColor = color.ToColor();
757 else if (status == CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED)
759 Variant color = GetProperty("pressedItemColor");
760 itemColor = color.ToColor();
765 Variant color = GetProperty("highlightedItemColor");
766 itemColor = color.ToColor();
774 _ContextMenu::SetPropertyNormalItemTextColor(const Variant& color)
776 __textColor[CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL] = color.ToColor();
778 return __pContextMenuPresenter->ApplyColorProperty();
782 _ContextMenu::GetPropertyNormalItemTextColor(void) const
784 return Tizen::Ui::Variant(__textColor[CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL]);
788 _ContextMenu::SetPropertyPressedItemTextColor(const Variant& color)
790 __textColor[CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED] = color.ToColor();
792 return __pContextMenuPresenter->ApplyColorProperty();
796 _ContextMenu::GetPropertyPressedItemTextColor(void) const
798 return Tizen::Ui::Variant(__textColor[CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED]);
802 _ContextMenu::SetPropertyHighlightedItemTextColor(const Variant & color)
804 __textColor[CONTEXT_MENU_CORE_ITEM_STATUS_HIGHLIGHTED] = color.ToColor();
806 return __pContextMenuPresenter->ApplyColorProperty();
810 _ContextMenu::GetPropertyHighlightedItemTextColor(void) const
812 return Tizen::Ui::Variant(__textColor[CONTEXT_MENU_CORE_ITEM_STATUS_HIGHLIGHTED]);
816 _ContextMenu::SetTextColor(enum ContextMenuCoreItemStatus status, const Graphics::Color& color)
818 result r = E_SUCCESS;
820 if (status == CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL)
822 r = SetProperty("normalItemTextColor", Variant(color));
824 else if (status == CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED)
826 r = SetProperty("pressedItemTextColor", Variant(color));
830 r = SetProperty("highlightedItemTextColor", Variant(color));
838 _ContextMenu::GetTextColor(enum ContextMenuCoreItemStatus status) const
842 if (status == CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL)
844 Variant color = GetProperty("normalItemTextColor");
845 textColor = color.ToColor();
848 else if (status == CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED)
850 Variant color = GetProperty("pressedItemTextColor");
851 textColor = color.ToColor();
856 Variant color = GetProperty("highlightedItemTextColor");
857 textColor = color.ToColor();
864 _ContextMenu::AddActionEventListener(const Tizen::Ui::Controls::_IActionEventListener& listener)
866 result r = E_SUCCESS;
868 if (__pActionEvent == null)
870 __pActionEvent = _ActionEvent::CreateInstanceN(*this);
871 SysTryReturn(NID_UI_CTRL, __pActionEvent != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
872 "[E_OUT_OF_MEMORY] The memory is insufficient.")
874 r = __pActionEvent->AddListener(listener);
875 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to remove an action event listener.")
881 delete __pActionEvent;
882 __pActionEvent = null;
887 _ContextMenu::RemoveActionEventListener(const Tizen::Ui::Controls::_IActionEventListener& listener)
889 SysTryReturn(NID_UI_CTRL, __pActionEvent != null, E_INVALID_STATE, E_INVALID_STATE,
890 "[E_INVALID_STATE] The action event instance isn't constructed.")
892 result r = E_SUCCESS;
894 r = __pActionEvent->RemoveListener(listener);
895 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to remove an action event listener")
900 Tizen::Ui::Controls::_ActionEvent*
901 _ContextMenu::GetActionEvent(void) const
903 return __pActionEvent;
907 _ContextMenu::LoadBitmap(void)
909 Color backgroundColor;
912 if (__pBackgroundEffectBitmap != null)
914 delete __pBackgroundEffectBitmap;
915 __pBackgroundEffectBitmap = null;
918 for (int i = 0; i < CONTEXT_MENU_CORE_DROP_POSITION_MAX; i++)
920 if (__pArrowEffectBitmap[i] != null)
922 delete __pArrowEffectBitmap[i];
923 __pArrowEffectBitmap[i] = null;
927 backgroundColor = GetColor();
931 r = GET_BITMAP_CONFIG_N(CONTEXTMENU::ANCHOR_EFFECT_UP, BITMAP_PIXEL_FORMAT_ARGB8888,
932 __pArrowEffectBitmap[CONTEXT_MENU_CORE_DROP_POSITION_UP]);
933 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
935 r = GET_BITMAP_CONFIG_N(CONTEXTMENU::ANCHOR_EFFECT_DOWN, BITMAP_PIXEL_FORMAT_ARGB8888,
936 __pArrowEffectBitmap[CONTEXT_MENU_CORE_DROP_POSITION_DOWN]);
937 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
939 r = GET_BITMAP_CONFIG_N(CONTEXTMENU::ANCHOR_EFFECT_LEFT, BITMAP_PIXEL_FORMAT_ARGB8888,
940 __pArrowEffectBitmap[CONTEXT_MENU_CORE_DROP_POSITION_LEFT]);
941 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
943 r = GET_BITMAP_CONFIG_N(CONTEXTMENU::ANCHOR_EFFECT_RIGHT, BITMAP_PIXEL_FORMAT_ARGB8888,
944 __pArrowEffectBitmap[CONTEXT_MENU_CORE_DROP_POSITION_RIGHT]);
945 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
947 r = GET_BITMAP_CONFIG_N(CONTEXTMENU::BG_OUTLINE_EFFECT_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pBackgroundEffectBitmap);
948 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
950 r = LoadColorReplacedBitmap(backgroundColor);
951 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
956 delete __pBackgroundEffectBitmap;
957 __pBackgroundEffectBitmap = null;
959 for (int i = 0; i < CONTEXT_MENU_CORE_DROP_POSITION_MAX; i++)
962 delete __pArrowEffectBitmap[i];
963 __pArrowEffectBitmap[i] = null;
970 _ContextMenu::LoadColorReplacedBitmap(const Tizen::Graphics::Color& color)
972 Bitmap* ptempNormalBitmap = null;
975 if (__pBackgroundNormalBitmap != null)
977 delete __pBackgroundNormalBitmap;
978 __pBackgroundNormalBitmap = null;
981 for (int i = 0; i < CONTEXT_MENU_CORE_DROP_POSITION_MAX; i++)
983 if (__pArrowNormalBitmap[i] != null)
985 delete __pArrowNormalBitmap[i];
986 __pArrowNormalBitmap[i] = null;
991 r = GET_BITMAP_CONFIG_N(CONTEXTMENU::ANCHOR_NORMAL_UP, BITMAP_PIXEL_FORMAT_ARGB8888, ptempNormalBitmap);
992 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
993 __pArrowNormalBitmap[CONTEXT_MENU_CORE_DROP_POSITION_UP] = _BitmapImpl::GetColorReplacedBitmapN(*ptempNormalBitmap,
994 Color::GetColor(COLOR_ID_MAGENTA), color);
995 SysTryCatch(NID_UI_CTRL, __pArrowNormalBitmap[CONTEXT_MENU_CORE_DROP_POSITION_UP] != null, , GetLastResult(),
996 "[%s] Propagating.", GetErrorMessage(GetLastResult()));
997 delete ptempNormalBitmap;
998 ptempNormalBitmap = null;
1000 r = GET_BITMAP_CONFIG_N(CONTEXTMENU::ANCHOR_NORMAL_DOWN, BITMAP_PIXEL_FORMAT_ARGB8888, ptempNormalBitmap);
1001 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
1002 __pArrowNormalBitmap[CONTEXT_MENU_CORE_DROP_POSITION_DOWN] = _BitmapImpl::GetColorReplacedBitmapN(*ptempNormalBitmap,
1003 Color::GetColor(COLOR_ID_MAGENTA), color);
1004 SysTryCatch(NID_UI_CTRL, __pArrowNormalBitmap[CONTEXT_MENU_CORE_DROP_POSITION_DOWN] != null, , GetLastResult(),
1005 "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1006 delete ptempNormalBitmap;
1007 ptempNormalBitmap = null;
1009 r = GET_BITMAP_CONFIG_N(CONTEXTMENU::ANCHOR_NORMAL_LEFT, BITMAP_PIXEL_FORMAT_ARGB8888, ptempNormalBitmap);
1010 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
1011 __pArrowNormalBitmap[CONTEXT_MENU_CORE_DROP_POSITION_LEFT] = _BitmapImpl::GetColorReplacedBitmapN(*ptempNormalBitmap,
1012 Color::GetColor(COLOR_ID_MAGENTA), color);
1013 SysTryCatch(NID_UI_CTRL, __pArrowNormalBitmap[CONTEXT_MENU_CORE_DROP_POSITION_LEFT] != null, , GetLastResult(),
1014 "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1015 delete ptempNormalBitmap;
1016 ptempNormalBitmap = null;
1018 r = GET_BITMAP_CONFIG_N(CONTEXTMENU::ANCHOR_NORMAL_RIGHT, BITMAP_PIXEL_FORMAT_ARGB8888, ptempNormalBitmap);
1019 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
1020 __pArrowNormalBitmap[CONTEXT_MENU_CORE_DROP_POSITION_RIGHT] = _BitmapImpl::GetColorReplacedBitmapN(*ptempNormalBitmap,
1021 Color::GetColor(COLOR_ID_MAGENTA), color);
1022 SysTryCatch(NID_UI_CTRL, __pArrowNormalBitmap[CONTEXT_MENU_CORE_DROP_POSITION_RIGHT] != null, , GetLastResult(),
1023 "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1024 delete ptempNormalBitmap;
1025 ptempNormalBitmap = null;
1027 r = GET_BITMAP_CONFIG_N(CONTEXTMENU::BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, ptempNormalBitmap);
1028 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
1029 __pBackgroundNormalBitmap = _BitmapImpl::GetColorReplacedBitmapN(*ptempNormalBitmap, Color::GetColor(COLOR_ID_MAGENTA), color);
1030 SysTryCatch(NID_UI_CTRL, __pBackgroundNormalBitmap != null, , GetLastResult(), "[%s] Propagating.",
1031 GetErrorMessage(GetLastResult()));
1032 delete ptempNormalBitmap;
1037 delete ptempNormalBitmap;
1039 delete __pBackgroundNormalBitmap;
1040 __pBackgroundNormalBitmap = null;
1042 for (int i = 0; i < CONTEXT_MENU_CORE_DROP_POSITION_MAX; i++)
1044 delete __pArrowNormalBitmap[i];
1045 __pArrowNormalBitmap[i] = null;
1052 _ContextMenu::GetArrowNormalBitmap(ContextMenuCoreDropPosition dropPosition) const
1054 if (dropPosition == CONTEXT_MENU_CORE_DROP_POSITION_INVALID || dropPosition == CONTEXT_MENU_CORE_DROP_POSITION_MAX)
1059 return __pArrowNormalBitmap[dropPosition];
1063 _ContextMenu::GetArrowEffectBitmap(ContextMenuCoreDropPosition dropPosition) const
1065 if (dropPosition == CONTEXT_MENU_CORE_DROP_POSITION_INVALID || dropPosition == CONTEXT_MENU_CORE_DROP_POSITION_MAX)
1070 return __pArrowEffectBitmap[dropPosition];
1074 _ContextMenu::GetBackgroundNormalBitmap(void) const
1076 return __pBackgroundNormalBitmap;
1080 _ContextMenu::GetBackgroundEffectBitmap(void) const
1082 return __pBackgroundEffectBitmap;
1085 enum ContextMenuCoreDropPosition
1086 _ContextMenu::GetDropPosition(void) const
1088 return __dropPosition;
1092 _ContextMenu::AdjustDropPosition(void)
1094 FloatDimension screen = _ControlManager::GetInstance()->GetScreenSizeF();
1096 if (__align == CONTEXT_MENU_CORE_ALIGN_UP)
1098 __dropPosition = CONTEXT_MENU_CORE_DROP_POSITION_UP;
1100 else if (__align == CONTEXT_MENU_CORE_ALIGN_DOWN)
1102 __dropPosition = CONTEXT_MENU_CORE_DROP_POSITION_DOWN;
1104 else if (__align == CONTEXT_MENU_CORE_ALIGN_LEFT)
1106 __dropPosition = CONTEXT_MENU_CORE_DROP_POSITION_LEFT;
1108 else if (__align == CONTEXT_MENU_CORE_ALIGN_RIGHT)
1110 __dropPosition = CONTEXT_MENU_CORE_DROP_POSITION_RIGHT;
1114 if (__layout == _CONTROL_ORIENTATION_LANDSCAPE)
1116 screen.SetSize(screen.height, screen.width);
1119 if (screen.height > screen.width)
1121 if ((screen.height / 2.0f) > __anchorPoint.y)
1123 __dropPosition = CONTEXT_MENU_CORE_DROP_POSITION_DOWN;
1127 __dropPosition = CONTEXT_MENU_CORE_DROP_POSITION_UP;
1132 if ((screen.width / 2.0f) > __anchorPoint.x)
1134 __dropPosition = CONTEXT_MENU_CORE_DROP_POSITION_RIGHT;
1138 __dropPosition = CONTEXT_MENU_CORE_DROP_POSITION_LEFT;
1144 _UiTouchEventDelivery
1145 _ContextMenu::OnPreviewTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
1147 return __pContextMenuPresenter->OnPreviewTouchPressed(source, touchinfo);
1151 _ContextMenu::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
1153 return __pContextMenuPresenter->OnTouchPressed(source, touchinfo);
1156 _UiTouchEventDelivery
1157 _ContextMenu::OnPreviewTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
1159 return __pContextMenuPresenter->OnPreviewTouchMoved(source, touchinfo);
1163 _ContextMenu::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
1165 return __pContextMenuPresenter->OnTouchMoved(source, touchinfo);
1168 _UiTouchEventDelivery
1169 _ContextMenu::OnPreviewTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
1171 return __pContextMenuPresenter->OnPreviewTouchReleased(source, touchinfo);
1175 _ContextMenu::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
1177 return __pContextMenuPresenter->OnTouchReleased(source, touchinfo);
1180 _UiTouchEventDelivery
1181 _ContextMenu::OnPreviewTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
1183 return __pContextMenuPresenter->OnPreviewTouchCanceled(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(_ControlRotation rotation)
1217 _ControlOrientation orientation;
1219 orientation = GetOwner()->GetOrientation();
1221 GET_SHAPE_CONFIG(CONTEXTMENU::ITEM_MAX_COUNT, orientation, __showItemMaxCount);
1223 if (__isAttachedToMainTree == true)
1225 if(__rotation != rotation)
1227 SetVisibleState(false);
1231 __layout = orientation;
1232 __rotation = rotation;
1235 _ContextMenu::OnOwnerChanged(_Control* pOldOwner)
1237 if (!__isAttachedToMainTree)
1242 _Control* pOwner = GetOwner();
1244 if (pOldOwner != null)
1246 pOldOwner->UnlockInputEvent();
1251 pOwner->LockInputEvent();
1256 _ContextMenu::OnKeyPressed(const _Control& source, const _KeyInfo& keyInfo)
1258 return __pContextMenuPresenter->OnKeyPressed(source, keyInfo);
1262 _ContextMenu::OnKeyReleased(const _Control& source, const _KeyInfo& keyInfo)
1264 return __pContextMenuPresenter->OnKeyReleased(source, keyInfo);
1268 _ContextMenu::IsChildControlFocusManage(void) const
1270 return __pContextMenuPresenter->IsChildControlFocusManage();
1274 _ContextMenu::OnDrawFocus(void)
1276 __pContextMenuPresenter->OnDrawFocus();
1280 _ContextMenu::OnFocusModeStateChanged(void)
1282 __pContextMenuPresenter->OnFocusModeStateChanged();
1285 _AccessibilityElement*
1286 _ContextMenu::GetAccessibilityElement(const int mainIndex) const
1288 _AccessibilityElement* pElement = null;
1289 result r = __accessibilityElements.GetAt(mainIndex, pElement);
1290 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed at AccessibilityElement.", GetErrorMessage(r));
1301 _ContextMenu::AddAccessibilityElement(const _AccessibilityElement& element)
1303 __accessibilityElements.Add(const_cast<_AccessibilityElement*>(&element));
1307 _ContextMenu::SetAllAccessibilityElement(void)
1309 RemoveAllAccessibilityElement();
1310 __pContextMenuPresenter->SetAllAccessibilityElement();
1314 _ContextMenu::OnAccessibilityFocusMovedNext(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1320 _ContextMenu::OnAccessibilityFocusMovedPrevious(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1326 _ContextMenu::OnAccessibilityReadElement(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1332 _ContextMenu::OnAccessibilityReadingElement(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1338 _ContextMenu::OnAccessibilityFocusIn(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1344 _ContextMenu::OnAccessibilityFocusOut(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1350 _ContextMenu::OnAccessibilityActionPerformed(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1352 SetVisibleState(false);
1358 _ContextMenu::OnAccessibilityValueIncreased(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1364 _ContextMenu::OnAccessibilityValueDecreased(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1370 _ContextMenu::RemoveAllAccessibilityElement(void)
1372 _AccessibilityContainer* pAccessibilityContainer = GetAccessibilityContainer();
1373 if (pAccessibilityContainer && pAccessibilityContainer->IsActivated())
1375 pAccessibilityContainer->RemoveAllElement();
1379 _ContextMenuItemInfo
1380 _ContextMenu::GetItemFromPosition(const FloatPoint& position) const
1382 return __pContextMenuPresenter->GetItemFromPosition(position);
1385 _ContextMenuItemInfo
1386 _ContextMenu::FindItem(int index) const
1388 return __pContextMenuPresenter->FindItem(index);
1392 _ContextMenu::SetTopDrawnItemIndex(int index)
1394 return __pContextMenuPresenter->SetTopDrawnItemIndex(index);
1398 _ContextMenu::GetLayout(void) const
1403 }}} // Tizen::Ui: Control