2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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"
36 using namespace Tizen::Graphics;
37 using namespace Tizen::Media;
38 using namespace Tizen::Ui::Animations;
41 static const float TOUCH_PRESS_THRESHOLD_INSENSITIVE = 0.16f;
44 namespace Tizen { namespace Ui { namespace Controls
47 IMPLEMENT_PROPERTY(_ContextMenu);
49 _ContextMenu::_ContextMenu(const FloatPoint& point, enum ContextMenuCoreStyle style, enum ContextMenuCoreAlign contextMenuAlign)
50 : __pContextMenuPresenter(null)
52 , __align(contextMenuAlign)
53 , __showItemCount(MAX_CONTEXTMENU_LIST_SHOW_ITEM)
54 , __showItemMaxCount(0)
55 , __isAttachedToMainTree(false)
56 , __ownerInputEnableState(false)
57 , __anchorPoint(point)
58 , __bodyRect(FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f))
59 , __arrowRect(FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f))
60 , __windowRect(FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f))
61 , __pActionEvent(null)
62 , __pBackgroundNormalBitmap(null)
63 , __pBackgroundEffectBitmap(null)
64 , __dropPosition(CONTEXT_MENU_CORE_DROP_POSITION_INVALID)
65 , __layout(_CONTROL_ORIENTATION_PORTRAIT)
66 , __pScrollPanel(null)
68 __backgroundColor = Color(255, 255, 255, 255);
70 __textColor[CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL] = Color(255, 255, 255, 255);
71 __textColor[CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED] = Color(255, 255, 255, 255);
72 __textColor[CONTEXT_MENU_CORE_ITEM_STATUS_HIGHLIGHTED] = Color(255, 255, 255, 255);
74 __itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL] = Color(255, 255, 255, 255);
75 __itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED] = Color(255, 255, 255, 255);
76 __itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_HIGHLIGHTED] = Color(255, 255, 255, 255);
78 for (int i = 0; i < CONTEXT_MENU_CORE_DROP_POSITION_MAX; i++)
80 __pArrowNormalBitmap[i] = null;
81 __pArrowEffectBitmap[i] = null;
85 _ContextMenu::~_ContextMenu(void)
87 _Control* pOwner = GetOwner();
88 if (__isAttachedToMainTree == true && pOwner != null)
90 pOwner->UnlockInputEvent();
94 __pScrollPanel->DetachAllChildren();
95 DetachChild(*__pScrollPanel);
96 delete __pScrollPanel;
97 __pScrollPanel = null;
100 delete __pContextMenuPresenter;
101 __pContextMenuPresenter = null;
103 if (__pBackgroundNormalBitmap != null)
105 delete __pBackgroundNormalBitmap;
106 __pBackgroundNormalBitmap = null;
109 if (__pBackgroundEffectBitmap != null)
111 delete __pBackgroundEffectBitmap;
112 __pBackgroundEffectBitmap = null;
117 delete __pActionEvent;
118 __pActionEvent = null;
121 for (int i = 0; i < CONTEXT_MENU_CORE_DROP_POSITION_MAX; i++)
123 delete __pArrowNormalBitmap[i];
124 __pArrowNormalBitmap[i] = null;
126 delete __pArrowEffectBitmap[i];
127 __pArrowEffectBitmap[i] = null;
130 __actionId.RemoveAll();
132 RemoveAllAccessibilityElement();
137 _ContextMenu::IsActivatedOnOpen(void) const
143 _ContextMenu::CreateContextMenuN(const FloatPoint& point, enum ContextMenuCoreStyle style, enum ContextMenuCoreAlign contextMenuAlign)
145 _ContextMenu* pContextMenu = new (std::nothrow) _ContextMenu(point, style, contextMenuAlign);
146 SysTryReturn(NID_UI_CTRL, pContextMenu != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
148 result r = E_SUCCESS;
150 r = pContextMenu->CreateRootVisualElement();
151 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
153 pContextMenu->SetActivationEnabled(false);
155 r = pContextMenu->Initialize();
156 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to Initialize.", GetErrorMessage(r));
158 r = pContextMenu->Install();
159 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to Install.", GetErrorMessage(r));
161 pContextMenu->AcquireHandle();
162 pContextMenu->SetTouchPressThreshold(TOUCH_PRESS_THRESHOLD_INSENSITIVE);
164 if (pContextMenu->GetAccessibilityContainer() != null)
166 pContextMenu->GetAccessibilityContainer()->Activate(true);
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->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 _IContextMenuPresenter* pPresenter = new (std::nothrow) _ContextMenuListPresenter(this);
208 SysTryReturnResult(NID_UI_CTRL, pPresenter != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
210 SetPresenter(*pPresenter);
212 r = pPresenter->Install();
216 _IContextMenuPresenter* pPresenter = new (std::nothrow) _ContextMenuGridPresenter(this);
217 SysTryReturnResult(NID_UI_CTRL, pPresenter != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
219 SetPresenter(*pPresenter);
221 r = pPresenter->Install();
228 _ContextMenu::Initialize(void)
230 FloatDimension screen = _ControlManager::GetInstance()->GetScreenSizeF();
231 result r = E_SUCCESS;
233 Color backgroundColor;
234 Color backgroundSelectedColor;
236 Color itemTextSelectedColor;
238 r = SetBounds(FloatRectangle(0.0f, 0.0f, screen.width, screen.height));
239 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "SetBounds failed.");
244 GET_COLOR_CONFIG(CONTEXTMENU::BG_NORMAL, backgroundColor);
245 GET_COLOR_CONFIG(CONTEXTMENU::ITEM_BG_PRESSED, backgroundSelectedColor);
246 GET_COLOR_CONFIG(CONTEXTMENU::ITEM_TEXT_NORMAL, itemTextColor);
247 GET_COLOR_CONFIG(CONTEXTMENU::ITEM_TEXT_PRESSED, itemTextSelectedColor);
249 __backgroundColor = backgroundColor;
250 __itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL] = backgroundColor;
251 __itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED] = backgroundSelectedColor;
252 __textColor[CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL] = itemTextColor;
253 __textColor[CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED] = itemTextSelectedColor;
255 if (GetVisualElement() != null)
257 GetVisualElement()->SetSurfaceOpaque(false);
265 _ContextMenu::SetPresenter(const _IContextMenuPresenter& ContextMenuPresenter)
267 __pContextMenuPresenter = const_cast <_IContextMenuPresenter*>(&ContextMenuPresenter);
273 _ContextMenu::OnDraw()
275 __pContextMenuPresenter->Draw();
276 if(unlikely((_AccessibilityManager::IsActivated())))
278 _AccessibilityManager::GetInstance()->RequestAutoReading(_ACCESSIBILITY_AUTO_READING_MODE_FIRST_ITEM);
283 _ContextMenu::OnAttachedToMainTree(void)
285 result r = E_SUCCESS;
287 #if defined(WINDOW_BASE_ROTATE)
288 __layout = _ControlManager::GetInstance()->GetOrientation();
291 _Control* pOwner = GetOwner();
294 _Frame* pFrame = dynamic_cast<_Frame*>(_ControlManager::GetInstance()->GetCurrentFrame());
295 SysTryReturn(NID_UI_CTRL, pFrame != null, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Current frame instance is not available.");
297 _Form* pForm = pFrame->GetCurrentForm();
298 pForm != null ? SetOwner(pForm) : SetOwner(pFrame);
300 #if !defined(WINDOW_BASE_ROTATE)
301 __layout = _ControlManager::GetInstance()->GetOrientation();
303 GET_SHAPE_CONFIG(CONTEXTMENU::ITEM_MAX_COUNT, __layout, __showItemMaxCount);
305 else if (pOwner != null && __isAttachedToMainTree == false)
307 pOwner->LockInputEvent();
310 AdjustDropPosition();
312 if (GetItemCount() <= 0)
314 __pContextMenuPresenter->CalculateShowItemCount();
317 __pContextMenuPresenter->CalculateWindowRect();
321 SetVisibleState(true);
323 if (__style == CONTEXT_MENU_CORE_STYLE_LIST)
325 SetTouchCapture(false, false);
329 SetTouchCapture(true, false);
332 SetAllAccessibilityElement();
334 __isAttachedToMainTree = true;
336 _VisualElement* pVisualElement = GetVisualElement();
338 FloatRectangle pBounds = pVisualElement->GetBounds();
340 float oldBoundsX = pBounds.x;
341 float oldBoundsY = pBounds.y;
342 float distanceX = 0.0f;
343 float distanceY = 0.0f;
345 GET_SHAPE_CONFIG(CONTEXTMENU::APPEARING_ANIMATION_DISTANCE_X, __layout, distanceX);
346 GET_SHAPE_CONFIG(CONTEXTMENU::APPEARING_ANIMATION_DISTANCE_Y, __layout, distanceY);
348 switch(GetDropPosition())
350 case CONTEXT_MENU_CORE_DROP_POSITION_UP:
351 pBounds.y += distanceY;
353 case CONTEXT_MENU_CORE_DROP_POSITION_DOWN:
354 pBounds.y -= distanceY;
356 case CONTEXT_MENU_CORE_DROP_POSITION_LEFT:
357 pBounds.x += distanceX;
359 case CONTEXT_MENU_CORE_DROP_POSITION_RIGHT:
360 pBounds.x -= distanceX;
366 pVisualElement->SetBounds(pBounds);
367 pVisualElement->SetOpacity(0.0f);
369 bool enable = pVisualElement->IsImplicitAnimationEnabled();
371 pVisualElement->SetImplicitAnimationEnabled(true);
373 pBounds.x = oldBoundsX;
374 pBounds.y = oldBoundsY;
375 pVisualElement->SetBounds(pBounds);
376 pVisualElement->SetOpacity(1.0f);
378 pVisualElement->SetImplicitAnimationEnabled(enable);
384 _ContextMenu::OnDetachingFromMainTree(void)
386 result r = E_SUCCESS;
388 ReleaseTouchCapture();
390 _Control* pOwner = GetOwner();
393 pOwner->UnlockInputEvent();
396 __isAttachedToMainTree = false;
402 _ContextMenu::AddItem(const Base::String& text, int actionId, const Bitmap* pNormalBitmap, const Bitmap* pPressedBitmap,
403 const Bitmap* pHighlightedBitmap)
405 result r = E_SUCCESS;
407 r = __pContextMenuPresenter->AddItem(text, actionId, pNormalBitmap, pPressedBitmap, pHighlightedBitmap);
408 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to add a item.");
410 __actionId.Add(actionId);
412 __pContextMenuPresenter->CalculateShowItemCount();
413 __pContextMenuPresenter->CalculateWindowRect();
419 _ContextMenu::InsertItem(int index, const Base::String& text, int actionId, const Bitmap* pNormalBitmap,
420 const Bitmap* pPressedBitmap,
421 const Bitmap* pHighlightedBitmap)
423 result r = E_SUCCESS;
425 r = __pContextMenuPresenter->InsertItem(index, text, actionId, pNormalBitmap, pPressedBitmap, pHighlightedBitmap);
426 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to insert a item.");
428 __actionId.InsertAt(actionId, index);
430 __pContextMenuPresenter->CalculateShowItemCount();
431 __pContextMenuPresenter->CalculateWindowRect();
437 _ContextMenu::SetItem(int index, const Base::String& text, int actionId, const Bitmap* pNormalBitmap,
438 const Bitmap* pPressedBitmap, const Bitmap* pHighlightedBitmap)
440 result r = E_SUCCESS;
442 r = __pContextMenuPresenter->SetItem(index, text, actionId, pNormalBitmap, pPressedBitmap, pHighlightedBitmap);
443 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to set a item.");
445 __actionId.SetAt(actionId, index);
447 __pContextMenuPresenter->CalculateWindowRect();
453 _ContextMenu::RemoveItemAt(int index)
455 result r = E_SUCCESS;
457 r = __pContextMenuPresenter->DeleteItem(index);
458 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to remove a item.");
460 __actionId.RemoveAt(index);
462 __pContextMenuPresenter->CalculateShowItemCount();
463 __pContextMenuPresenter->CalculateWindowRect();
469 _ContextMenu::RemoveAllItems(void)
471 result r = E_SUCCESS;
473 r = __pContextMenuPresenter->DeleteItemAll();
474 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to remove all items.");
476 __actionId.RemoveAll();
478 __pContextMenuPresenter->CalculateShowItemCount();
479 __pContextMenuPresenter->CalculateWindowRect();
485 _ContextMenu::GetItemCount(void) const
487 return __actionId.GetCount();
491 _ContextMenu::GetItemIndexAt(int actionId) const
493 int count = __actionId.GetCount();
495 for (int i = 0; i < count; i++)
497 int index = GetItemActionIdAt(i);
499 if (actionId == index)
509 _ContextMenu::GetItemActionIdAt(int index) const
511 int count = __actionId.GetCount();
514 if (count <= 0 || index >= count)
519 __actionId.GetAt(index, actionId);
525 _ContextMenu::SetAnchorPosition(float x, float y)
530 if (__align == CONTEXT_MENU_CORE_ALIGN_AUTO)
532 AdjustDropPosition();
535 __pContextMenuPresenter->CalculateWindowRect();
540 _ContextMenu::GetAnchorPosition(void) const
542 return __anchorPoint;
546 _ContextMenu::SetBodyRect(const FloatRectangle& rect)
554 _ContextMenu::GetBodyRect(void) const
560 _ContextMenu::SetArrowRect(const FloatRectangle& rect)
568 _ContextMenu::GetArrowRect(void) const
574 _ContextMenu::SetWindowRect(const FloatRectangle& rect)
582 _ContextMenu::GetWindowRect(void) const
588 _ContextMenu::SetPropertyMaxVisibleItemsCount(const Variant& count)
590 int showCount = count.ToInt();
594 SysLogException(NID_UI_CTRL, E_INVALID_ARG, "Count is invalid.");
595 return E_INVALID_ARG;
599 __showItemCount = showCount;
605 _ContextMenu::GetPropertyMaxVisibleItemsCount(void) const
607 return Tizen::Ui::Variant(__showItemCount);
611 _ContextMenu::GetShowItemCount(void) const
613 Variant count = GetProperty("maxVisibleItemsCount");
615 return count.ToInt();
619 _ContextMenu::GetShowItemMaxCount(void) const
621 return __showItemMaxCount;
625 _ContextMenu::SetShowItemCount(int count)
629 r = SetProperty("maxVisibleItemsCount", Variant(count));
630 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to set property.");
632 if (__style == CONTEXT_MENU_CORE_STYLE_LIST)
634 r = __pContextMenuPresenter->CalculateWindowRect();
635 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to calculate window.");
642 _ContextMenu::SetPropertyColor(const Variant& color)
644 __backgroundColor = color.ToColor();
646 LoadColorReplacedBitmap(__backgroundColor);
652 _ContextMenu::GetPropertyColor(void) const
654 return Tizen::Ui::Variant(__backgroundColor);
658 _ContextMenu::SetColor(const Graphics::Color& color)
660 return SetProperty("color", Variant(color));
664 _ContextMenu::GetColor(void) const
666 Variant color = GetProperty("color");
668 return color.ToColor();
672 _ContextMenu::SetPropertyNormalItemColor(const Variant& color)
674 __itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL] = color.ToColor();
676 return __pContextMenuPresenter->ApplyColorProperty();
680 _ContextMenu::GetPropertyNormalItemColor(void) const
682 return Tizen::Ui::Variant(__itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL]);
686 _ContextMenu::SetPropertyPressedItemColor(const Variant& color)
688 __itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED] = color.ToColor();
690 return __pContextMenuPresenter->ApplyColorProperty();
694 _ContextMenu::GetPropertyPressedItemColor(void) const
696 return Tizen::Ui::Variant(__itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED]);
700 _ContextMenu::SetPropertyHighlightedItemColor(const Variant & color)
702 __itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_HIGHLIGHTED] = color.ToColor();
704 return __pContextMenuPresenter->ApplyColorProperty();
708 _ContextMenu::GetPropertyHighlightedItemColor(void) const
710 return Tizen::Ui::Variant(__itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_HIGHLIGHTED]);
714 _ContextMenu::SetItemColor(enum ContextMenuCoreItemStatus status, const Graphics::Color& color)
716 result r = E_SUCCESS;
718 if (status == CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL)
720 r = SetProperty("normalItemColor", Variant(color));
722 else if (status == CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED)
724 r = SetProperty("pressedItemColor", Variant(color));
728 r = SetProperty("highlightedItemColor", Variant(color));
735 _ContextMenu::GetItemColor(enum ContextMenuCoreItemStatus status) const
739 if (status == CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL)
741 Variant color = GetProperty("normalItemColor");
742 itemColor = color.ToColor();
745 else if (status == CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED)
747 Variant color = GetProperty("pressedItemColor");
748 itemColor = color.ToColor();
753 Variant color = GetProperty("highlightedItemColor");
754 itemColor = color.ToColor();
762 _ContextMenu::SetPropertyNormalItemTextColor(const Variant& color)
764 __textColor[CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL] = color.ToColor();
766 return __pContextMenuPresenter->ApplyColorProperty();
770 _ContextMenu::GetPropertyNormalItemTextColor(void) const
772 return Tizen::Ui::Variant(__textColor[CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL]);
776 _ContextMenu::SetPropertyPressedItemTextColor(const Variant& color)
778 __textColor[CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED] = color.ToColor();
780 return __pContextMenuPresenter->ApplyColorProperty();
784 _ContextMenu::GetPropertyPressedItemTextColor(void) const
786 return Tizen::Ui::Variant(__textColor[CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED]);
790 _ContextMenu::SetPropertyHighlightedItemTextColor(const Variant & color)
792 __textColor[CONTEXT_MENU_CORE_ITEM_STATUS_HIGHLIGHTED] = color.ToColor();
794 return __pContextMenuPresenter->ApplyColorProperty();
798 _ContextMenu::GetPropertyHighlightedItemTextColor(void) const
800 return Tizen::Ui::Variant(__textColor[CONTEXT_MENU_CORE_ITEM_STATUS_HIGHLIGHTED]);
804 _ContextMenu::SetTextColor(enum ContextMenuCoreItemStatus status, const Graphics::Color& color)
806 result r = E_SUCCESS;
808 if (status == CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL)
810 r = SetProperty("normalItemTextColor", Variant(color));
812 else if (status == CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED)
814 r = SetProperty("pressedItemTextColor", Variant(color));
818 r = SetProperty("highlightedItemTextColor", Variant(color));
826 _ContextMenu::GetTextColor(enum ContextMenuCoreItemStatus status) const
830 if (status == CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL)
832 Variant color = GetProperty("normalItemTextColor");
833 textColor = color.ToColor();
836 else if (status == CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED)
838 Variant color = GetProperty("pressedItemTextColor");
839 textColor = color.ToColor();
844 Variant color = GetProperty("highlightedItemTextColor");
845 textColor = color.ToColor();
852 _ContextMenu::AddActionEventListener(const Tizen::Ui::Controls::_IActionEventListener& listener)
854 result r = E_SUCCESS;
856 if (__pActionEvent == null)
858 __pActionEvent = _ActionEvent::CreateInstanceN(*this);
859 SysTryReturn(NID_UI_CTRL, __pActionEvent != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
860 "[E_OUT_OF_MEMORY] The memory is insufficient.")
862 r = __pActionEvent->AddListener(listener);
863 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to remove an action event listener.")
869 delete __pActionEvent;
870 __pActionEvent = null;
875 _ContextMenu::RemoveActionEventListener(const Tizen::Ui::Controls::_IActionEventListener& listener)
877 SysTryReturn(NID_UI_CTRL, __pActionEvent != null, E_INVALID_STATE, E_INVALID_STATE,
878 "[E_INVALID_STATE] The action event instance isn't constructed.")
880 result r = E_SUCCESS;
882 r = __pActionEvent->RemoveListener(listener);
883 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to remove an action event listener")
888 Tizen::Ui::Controls::_ActionEvent*
889 _ContextMenu::GetActionEvent(void) const
891 return __pActionEvent;
895 _ContextMenu::LoadBitmap(void)
897 Color backgroundColor;
900 if (__pBackgroundEffectBitmap != null)
902 delete __pBackgroundEffectBitmap;
903 __pBackgroundEffectBitmap = null;
906 for (int i = 0; i < CONTEXT_MENU_CORE_DROP_POSITION_MAX; i++)
908 if (__pArrowEffectBitmap[i] != null)
910 delete __pArrowEffectBitmap[i];
911 __pArrowEffectBitmap[i] = null;
915 backgroundColor = GetColor();
919 r = GET_BITMAP_CONFIG_N(CONTEXTMENU::ANCHOR_EFFECT_UP, BITMAP_PIXEL_FORMAT_ARGB8888,
920 __pArrowEffectBitmap[CONTEXT_MENU_CORE_DROP_POSITION_UP]);
921 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
923 r = GET_BITMAP_CONFIG_N(CONTEXTMENU::ANCHOR_EFFECT_DOWN, BITMAP_PIXEL_FORMAT_ARGB8888,
924 __pArrowEffectBitmap[CONTEXT_MENU_CORE_DROP_POSITION_DOWN]);
925 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
927 r = GET_BITMAP_CONFIG_N(CONTEXTMENU::ANCHOR_EFFECT_LEFT, BITMAP_PIXEL_FORMAT_ARGB8888,
928 __pArrowEffectBitmap[CONTEXT_MENU_CORE_DROP_POSITION_LEFT]);
929 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
931 r = GET_BITMAP_CONFIG_N(CONTEXTMENU::ANCHOR_EFFECT_RIGHT, BITMAP_PIXEL_FORMAT_ARGB8888,
932 __pArrowEffectBitmap[CONTEXT_MENU_CORE_DROP_POSITION_RIGHT]);
933 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
935 r = GET_BITMAP_CONFIG_N(CONTEXTMENU::BG_OUTLINE_EFFECT_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pBackgroundEffectBitmap);
936 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
938 r = LoadColorReplacedBitmap(backgroundColor);
939 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
944 delete __pBackgroundEffectBitmap;
945 __pBackgroundEffectBitmap = null;
947 for (int i = 0; i < CONTEXT_MENU_CORE_DROP_POSITION_MAX; i++)
950 delete __pArrowEffectBitmap[i];
951 __pArrowEffectBitmap[i] = null;
958 _ContextMenu::LoadColorReplacedBitmap(const Tizen::Graphics::Color& color)
960 Bitmap* ptempNormalBitmap = null;
963 if (__pBackgroundNormalBitmap != null)
965 delete __pBackgroundNormalBitmap;
966 __pBackgroundNormalBitmap = null;
969 for (int i = 0; i < CONTEXT_MENU_CORE_DROP_POSITION_MAX; i++)
971 if (__pArrowNormalBitmap[i] != null)
973 delete __pArrowNormalBitmap[i];
974 __pArrowNormalBitmap[i] = null;
979 r = GET_BITMAP_CONFIG_N(CONTEXTMENU::ANCHOR_NORMAL_UP, BITMAP_PIXEL_FORMAT_ARGB8888, ptempNormalBitmap);
980 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
981 __pArrowNormalBitmap[CONTEXT_MENU_CORE_DROP_POSITION_UP] = _BitmapImpl::GetColorReplacedBitmapN(*ptempNormalBitmap,
982 Color::GetColor(COLOR_ID_MAGENTA), color);
983 SysTryCatch(NID_UI_CTRL, __pArrowNormalBitmap[CONTEXT_MENU_CORE_DROP_POSITION_UP] != null, , GetLastResult(),
984 "[%s] Propagating.", GetErrorMessage(GetLastResult()));
985 delete ptempNormalBitmap;
986 ptempNormalBitmap = null;
988 r = GET_BITMAP_CONFIG_N(CONTEXTMENU::ANCHOR_NORMAL_DOWN, BITMAP_PIXEL_FORMAT_ARGB8888, ptempNormalBitmap);
989 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
990 __pArrowNormalBitmap[CONTEXT_MENU_CORE_DROP_POSITION_DOWN] = _BitmapImpl::GetColorReplacedBitmapN(*ptempNormalBitmap,
991 Color::GetColor(COLOR_ID_MAGENTA), color);
992 SysTryCatch(NID_UI_CTRL, __pArrowNormalBitmap[CONTEXT_MENU_CORE_DROP_POSITION_DOWN] != null, , GetLastResult(),
993 "[%s] Propagating.", GetErrorMessage(GetLastResult()));
994 delete ptempNormalBitmap;
995 ptempNormalBitmap = null;
997 r = GET_BITMAP_CONFIG_N(CONTEXTMENU::ANCHOR_NORMAL_LEFT, 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_LEFT] = _BitmapImpl::GetColorReplacedBitmapN(*ptempNormalBitmap,
1000 Color::GetColor(COLOR_ID_MAGENTA), color);
1001 SysTryCatch(NID_UI_CTRL, __pArrowNormalBitmap[CONTEXT_MENU_CORE_DROP_POSITION_LEFT] != null, , GetLastResult(),
1002 "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1003 delete ptempNormalBitmap;
1004 ptempNormalBitmap = null;
1006 r = GET_BITMAP_CONFIG_N(CONTEXTMENU::ANCHOR_NORMAL_RIGHT, 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_RIGHT] = _BitmapImpl::GetColorReplacedBitmapN(*ptempNormalBitmap,
1009 Color::GetColor(COLOR_ID_MAGENTA), color);
1010 SysTryCatch(NID_UI_CTRL, __pArrowNormalBitmap[CONTEXT_MENU_CORE_DROP_POSITION_RIGHT] != null, , GetLastResult(),
1011 "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1012 delete ptempNormalBitmap;
1013 ptempNormalBitmap = null;
1015 r = GET_BITMAP_CONFIG_N(CONTEXTMENU::BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, ptempNormalBitmap);
1016 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
1017 __pBackgroundNormalBitmap = _BitmapImpl::GetColorReplacedBitmapN(*ptempNormalBitmap, Color::GetColor(COLOR_ID_MAGENTA), color);
1018 SysTryCatch(NID_UI_CTRL, __pBackgroundNormalBitmap != null, , GetLastResult(), "[%s] Propagating.",
1019 GetErrorMessage(GetLastResult()));
1020 delete ptempNormalBitmap;
1025 delete ptempNormalBitmap;
1027 delete __pBackgroundNormalBitmap;
1028 __pBackgroundNormalBitmap = null;
1030 for (int i = 0; i < CONTEXT_MENU_CORE_DROP_POSITION_MAX; i++)
1032 delete __pArrowNormalBitmap[i];
1033 __pArrowNormalBitmap[i] = null;
1040 _ContextMenu::GetArrowNormalBitmap(ContextMenuCoreDropPosition dropPosition) const
1042 if (dropPosition == CONTEXT_MENU_CORE_DROP_POSITION_INVALID || dropPosition == CONTEXT_MENU_CORE_DROP_POSITION_MAX)
1047 return __pArrowNormalBitmap[dropPosition];
1051 _ContextMenu::GetArrowEffectBitmap(ContextMenuCoreDropPosition dropPosition) const
1053 if (dropPosition == CONTEXT_MENU_CORE_DROP_POSITION_INVALID || dropPosition == CONTEXT_MENU_CORE_DROP_POSITION_MAX)
1058 return __pArrowEffectBitmap[dropPosition];
1062 _ContextMenu::GetBackgroundNormalBitmap(void) const
1064 return __pBackgroundNormalBitmap;
1068 _ContextMenu::GetBackgroundEffectBitmap(void) const
1070 return __pBackgroundEffectBitmap;
1073 enum ContextMenuCoreDropPosition
1074 _ContextMenu::GetDropPosition(void) const
1076 return __dropPosition;
1080 _ContextMenu::AdjustDropPosition(void)
1082 FloatDimension screen = _ControlManager::GetInstance()->GetScreenSizeF();
1084 if (__align == CONTEXT_MENU_CORE_ALIGN_UP)
1086 __dropPosition = CONTEXT_MENU_CORE_DROP_POSITION_UP;
1088 else if (__align == CONTEXT_MENU_CORE_ALIGN_DOWN)
1090 __dropPosition = CONTEXT_MENU_CORE_DROP_POSITION_DOWN;
1092 else if (__align == CONTEXT_MENU_CORE_ALIGN_LEFT)
1094 __dropPosition = CONTEXT_MENU_CORE_DROP_POSITION_LEFT;
1096 else if (__align == CONTEXT_MENU_CORE_ALIGN_RIGHT)
1098 __dropPosition = CONTEXT_MENU_CORE_DROP_POSITION_RIGHT;
1102 if (__layout == _CONTROL_ORIENTATION_LANDSCAPE)
1104 screen.SetSize(screen.height, screen.width);
1107 if (screen.height > screen.width)
1109 if ((screen.height / 2.0f) > __anchorPoint.y)
1111 __dropPosition = CONTEXT_MENU_CORE_DROP_POSITION_DOWN;
1115 __dropPosition = CONTEXT_MENU_CORE_DROP_POSITION_UP;
1120 if ((screen.width / 2.0f) > __anchorPoint.x)
1122 __dropPosition = CONTEXT_MENU_CORE_DROP_POSITION_RIGHT;
1126 __dropPosition = CONTEXT_MENU_CORE_DROP_POSITION_LEFT;
1132 _UiTouchEventDelivery
1133 _ContextMenu::OnPreviewTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
1135 return __pContextMenuPresenter->OnPreviewTouchPressed(source, touchinfo);
1139 _ContextMenu::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
1141 return __pContextMenuPresenter->OnTouchPressed(source, touchinfo);
1144 _UiTouchEventDelivery
1145 _ContextMenu::OnPreviewTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
1147 return __pContextMenuPresenter->OnPreviewTouchMoved(source, touchinfo);
1151 _ContextMenu::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
1153 return __pContextMenuPresenter->OnTouchMoved(source, touchinfo);
1156 _UiTouchEventDelivery
1157 _ContextMenu::OnPreviewTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
1159 return __pContextMenuPresenter->OnPreviewTouchReleased(source, touchinfo);
1163 _ContextMenu::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
1165 return __pContextMenuPresenter->OnTouchReleased(source, touchinfo);
1169 _ContextMenu::OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
1171 __pContextMenuPresenter->OnTouchCanceled(source, touchinfo);
1173 SetVisibleState(false);
1179 _ContextMenu::OnFontChanged(Tizen::Graphics::Font* pFont)
1181 return __pContextMenuPresenter->OnFontChanged(pFont);
1185 _ContextMenu::OnFontInfoRequested(unsigned long& style, float& size)
1187 return __pContextMenuPresenter->OnFontInfoRequested(style, size);
1191 _ContextMenu::OnVisibleStateChanged(void)
1193 _Window::OnVisibleStateChanged();
1197 _ContextMenu::OnChangeLayout(_ControlOrientation orientation)
1199 GET_SHAPE_CONFIG(CONTEXTMENU::ITEM_MAX_COUNT, orientation, __showItemMaxCount);
1201 if (__isAttachedToMainTree == true)
1203 if (__layout != orientation)
1205 SetVisibleState(false);
1209 __layout = orientation;
1213 _ContextMenu::OnOwnerChanged(_Control* pOldOwner)
1215 _Control* pOwner = GetOwner();
1217 if (pOldOwner != null)
1219 pOldOwner->UnlockInputEvent();
1224 pOwner->LockInputEvent();
1228 _AccessibilityElement*
1229 _ContextMenu::GetAccessibilityElement(const int mainIndex) const
1231 _AccessibilityElement* pElement = null;
1232 result r = __accessibilityElements.GetAt(mainIndex, pElement);
1233 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed at AccessibilityElement.", GetErrorMessage(r));
1244 _ContextMenu::AddAccessibilityElement(const _AccessibilityElement& element)
1246 __accessibilityElements.Add(const_cast<_AccessibilityElement*>(&element));
1250 _ContextMenu::SetAllAccessibilityElement(void)
1252 RemoveAllAccessibilityElement();
1253 __pContextMenuPresenter->SetAllAccessibilityElement();
1257 _ContextMenu::RemoveAllAccessibilityElement(void)
1259 while (__accessibilityElements.GetCount() > 0)
1261 _AccessibilityElement* pElement = null;
1262 if (__accessibilityElements.GetAt(0, pElement) == E_SUCCESS)
1264 __accessibilityElements.RemoveAt(0);
1265 pElement->GetParent()->RemoveElement(*pElement);
1270 _ContextMenuItemInfo
1271 _ContextMenu::GetItemFromPosition(const FloatPoint& position) const
1273 return __pContextMenuPresenter->GetItemFromPosition(position);
1276 _ContextMenuItemInfo
1277 _ContextMenu::FindItem(int index) const
1279 return __pContextMenuPresenter->FindItem(index);
1283 _ContextMenu::SetTopDrawnItemIndex(int index)
1285 return __pContextMenuPresenter->SetTopDrawnItemIndex(index);
1289 _ContextMenu::GetLayout(void) const
1294 }}} // Tizen::Ui: Control