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;
86 GET_SHAPE_CONFIG(CONTEXTMENU::ITEM_MAX_COUNT, __layout, __showItemMaxCount);
89 _ContextMenu::~_ContextMenu(void)
91 if (__isAttachedToMainTree && GetOwner() != null)
93 GetOwner()->UnlockInputEvent();
97 __pScrollPanel->DetachAllChildren();
98 DetachChild(*__pScrollPanel);
99 delete __pScrollPanel;
100 __pScrollPanel = null;
103 delete __pContextMenuPresenter;
104 __pContextMenuPresenter = null;
106 if (__pBackgroundNormalBitmap != null)
108 delete __pBackgroundNormalBitmap;
109 __pBackgroundNormalBitmap = null;
112 if (__pBackgroundEffectBitmap != null)
114 delete __pBackgroundEffectBitmap;
115 __pBackgroundEffectBitmap = null;
120 delete __pActionEvent;
121 __pActionEvent = null;
124 for (int i = 0; i < CONTEXT_MENU_CORE_DROP_POSITION_MAX; i++)
126 delete __pArrowNormalBitmap[i];
127 __pArrowNormalBitmap[i] = null;
129 delete __pArrowEffectBitmap[i];
130 __pArrowEffectBitmap[i] = null;
133 __actionId.RemoveAll();
135 RemoveAllAccessibilityElement();
139 _ContextMenu::CreateContextMenuN(const FloatPoint& point, enum ContextMenuCoreStyle style, enum ContextMenuCoreAlign contextMenuAlign)
141 _ContextMenu* pContextMenu = new (std::nothrow) _ContextMenu(point, style, contextMenuAlign);
142 SysTryReturn(NID_UI_CTRL, pContextMenu != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
144 result r = E_SUCCESS;
146 r = pContextMenu->CreateRootVisualElement();
147 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
149 pContextMenu->SetFocusable(false);
151 r = pContextMenu->Initialize();
152 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to Initialize.", GetErrorMessage(r));
154 r = pContextMenu->Install();
155 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to Install.", GetErrorMessage(r));
157 pContextMenu->AcquireHandle();
158 pContextMenu->SetTouchPressThreshold(TOUCH_PRESS_THRESHOLD_INSENSITIVE);
160 if (pContextMenu->GetAccessibilityContainer() != null)
162 pContextMenu->GetAccessibilityContainer()->Activate(true);
163 pContextMenu->GetAccessibilityContainer()->AddListener(*pContextMenu);
166 if (style == CONTEXT_MENU_CORE_STYLE_LIST)
168 float minWidth, minHeight; // for visible scrollbar when scrollable
169 GET_SHAPE_CONFIG(CONTEXTMENU::LIST_MIN_WIDTH, _CONTROL_ORIENTATION_PORTRAIT, minWidth);
170 GET_SHAPE_CONFIG(CONTEXTMENU::LIST_ITEM_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, minHeight);
171 pContextMenu->__pScrollPanel = _ScrollPanel::CreateScrollPanelN(FloatRectangle(0.0f, 0.0f, minWidth, minHeight), SCROLL_PANEL_SCROLL_DIRECTION_VERTICAL, false, false);
172 pContextMenu->__pScrollPanel->SetTouchPressThreshold(TOUCH_PRESS_THRESHOLD_INSENSITIVE);
174 _Scroll* pScroll = pContextMenu->__pScrollPanel->GetScrollBar();
175 SysTryCatch(NID_UI_CTRL, pScroll, , E_INVALID_STATE, "[E_INVALID_STATE] _Scroll isn't constructed");
176 pScroll->SetContextMenuScrollType(true);
178 pContextMenu->AttachChild(*(pContextMenu->__pScrollPanel));
190 _ContextMenu::GetScrollPanel(void)
192 return __pScrollPanel;
196 _ContextMenu::Install(void)
198 result r = E_SUCCESS;
200 // load bitmap of a background and arrow
202 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to load bitmap.");
204 r = __actionId.Construct();
205 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to construct arraylist.");
207 if (__style == CONTEXT_MENU_CORE_STYLE_LIST)
209 if (__anchorPoint.Equals(FloatPoint(-1.0f ,-1.0f)))
\r
211 _IContextMenuPresenter* pPresenter = new (std::nothrow) _OptionMenuListPresenter(this);
\r
212 SysTryReturnResult(NID_UI_CTRL, pPresenter != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
\r
214 SetPresenter(*pPresenter);
\r
216 r = pPresenter->Install();
\r
220 _IContextMenuPresenter* pPresenter = new (std::nothrow) _ContextMenuListPresenter(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();
230 _IContextMenuPresenter* pPresenter = new (std::nothrow) _ContextMenuGridPresenter(this);
231 SysTryReturnResult(NID_UI_CTRL, pPresenter != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
233 SetPresenter(*pPresenter);
235 r = pPresenter->Install();
242 _ContextMenu::Initialize(void)
244 FloatDimension screen = _ControlManager::GetInstance()->GetScreenSizeF();
245 result r = E_SUCCESS;
247 Color backgroundColor;
248 Color backgroundSelectedColor;
250 Color itemTextSelectedColor;
252 r = SetBounds(FloatRectangle(0.0f, 0.0f, screen.width, screen.height));
253 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "SetBounds failed.");
258 GET_COLOR_CONFIG(CONTEXTMENU::BG_NORMAL, backgroundColor);
259 GET_COLOR_CONFIG(CONTEXTMENU::ITEM_BG_PRESSED, backgroundSelectedColor);
260 GET_COLOR_CONFIG(CONTEXTMENU::ITEM_TEXT_NORMAL, itemTextColor);
261 GET_COLOR_CONFIG(CONTEXTMENU::ITEM_TEXT_PRESSED, itemTextSelectedColor);
263 __backgroundColor = backgroundColor;
264 __itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL] = backgroundColor;
265 __itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED] = backgroundSelectedColor;
266 __textColor[CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL] = itemTextColor;
267 __textColor[CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED] = itemTextSelectedColor;
269 if (GetVisualElement() != null)
271 GetVisualElement()->SetSurfaceOpaque(false);
279 _ContextMenu::SetPresenter(const _IContextMenuPresenter& ContextMenuPresenter)
281 __pContextMenuPresenter = const_cast <_IContextMenuPresenter*>(&ContextMenuPresenter);
287 _ContextMenu::OnDraw()
289 __pContextMenuPresenter->Draw();
291 if(unlikely((_AccessibilityManager::IsActivated())))
293 _AccessibilityManager::GetInstance()->RequestAutoReading(_ACCESSIBILITY_AUTO_READING_MODE_FIRST_ITEM);
298 _ContextMenu::OnAttachedToMainTree(void)
300 result r = E_SUCCESS;
302 __layout = _ControlManager::GetInstance()->GetOrientation();
303 __isAttachedToMainTree = true;
304 _Control* pOwner = GetOwner();
307 _Frame* pFrame = dynamic_cast<_Frame*>(_ControlManager::GetInstance()->GetCurrentFrame());
308 SysTryReturn(NID_UI_CTRL, pFrame != null, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Current frame instance is not available.");
310 _Form* pForm = pFrame->GetCurrentForm();
311 pForm != null ? SetOwner(pForm) : SetOwner(pFrame);
313 GET_SHAPE_CONFIG(CONTEXTMENU::ITEM_MAX_COUNT, __layout, __showItemMaxCount);
317 pOwner->LockInputEvent();
320 AdjustDropPosition();
322 if (GetItemCount() <= 0)
324 __pContextMenuPresenter->CalculateShowItemCount();
327 __pContextMenuPresenter->CalculateWindowRect();
331 SetVisibleState(true);
333 if (__style == CONTEXT_MENU_CORE_STYLE_LIST)
335 SetTouchCapture(false, false);
339 SetTouchCapture(true, false);
342 SetAllAccessibilityElement();
344 _VisualElement* pVisualElement = GetVisualElement();
345 FloatRectangle pBounds = pVisualElement->GetBounds();
346 float oldBoundsX = pBounds.x;
347 float oldBoundsY = pBounds.y;
348 float distanceX = 0.0f;
349 float distanceY = 0.0f;
351 GET_SHAPE_CONFIG(CONTEXTMENU::APPEARING_ANIMATION_DISTANCE_X, __layout, distanceX);
352 GET_SHAPE_CONFIG(CONTEXTMENU::APPEARING_ANIMATION_DISTANCE_Y, __layout, distanceY);
354 switch(GetDropPosition())
356 case CONTEXT_MENU_CORE_DROP_POSITION_UP:
357 pBounds.y += distanceY;
359 case CONTEXT_MENU_CORE_DROP_POSITION_DOWN:
360 pBounds.y -= distanceY;
362 case CONTEXT_MENU_CORE_DROP_POSITION_LEFT:
363 pBounds.x += distanceX;
365 case CONTEXT_MENU_CORE_DROP_POSITION_RIGHT:
366 pBounds.x -= distanceX;
372 pVisualElement->SetBounds(pBounds);
373 pVisualElement->SetOpacity(0.0f);
375 bool enable = pVisualElement->IsImplicitAnimationEnabled();
377 pVisualElement->SetImplicitAnimationEnabled(true);
379 pBounds.x = oldBoundsX;
380 pBounds.y = oldBoundsY;
381 pVisualElement->SetBounds(pBounds);
382 pVisualElement->SetOpacity(1.0f);
384 pVisualElement->SetImplicitAnimationEnabled(enable);
390 _ContextMenu::OnDetachingFromMainTree(void)
392 result r = E_SUCCESS;
394 ReleaseTouchCapture();
396 _Control* pOwner = GetOwner();
399 pOwner->UnlockInputEvent();
402 __isAttachedToMainTree = false;
408 _ContextMenu::AddItem(const Base::String& text, int actionId, const Bitmap* pNormalBitmap, const Bitmap* pPressedBitmap,
409 const Bitmap* pHighlightedBitmap)
411 result r = E_SUCCESS;
413 r = __pContextMenuPresenter->AddItem(text, actionId, pNormalBitmap, pPressedBitmap, pHighlightedBitmap);
414 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to add a item.");
416 __actionId.Add(actionId);
418 __pContextMenuPresenter->CalculateShowItemCount();
419 __pContextMenuPresenter->CalculateWindowRect();
425 _ContextMenu::InsertItem(int index, const Base::String& text, int actionId, const Bitmap* pNormalBitmap,
426 const Bitmap* pPressedBitmap,
427 const Bitmap* pHighlightedBitmap)
429 result r = E_SUCCESS;
431 r = __pContextMenuPresenter->InsertItem(index, text, actionId, pNormalBitmap, pPressedBitmap, pHighlightedBitmap);
432 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to insert a item.");
434 __actionId.InsertAt(actionId, index);
436 __pContextMenuPresenter->CalculateShowItemCount();
437 __pContextMenuPresenter->CalculateWindowRect();
443 _ContextMenu::SetItem(int index, const Base::String& text, int actionId, const Bitmap* pNormalBitmap,
444 const Bitmap* pPressedBitmap, const Bitmap* pHighlightedBitmap)
446 result r = E_SUCCESS;
448 r = __pContextMenuPresenter->SetItem(index, text, actionId, pNormalBitmap, pPressedBitmap, pHighlightedBitmap);
449 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to set a item.");
451 __actionId.SetAt(actionId, index);
453 __pContextMenuPresenter->CalculateWindowRect();
459 _ContextMenu::RemoveItemAt(int index)
461 result r = E_SUCCESS;
463 r = __pContextMenuPresenter->DeleteItem(index);
464 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to remove a item.");
466 __actionId.RemoveAt(index);
468 __pContextMenuPresenter->CalculateShowItemCount();
469 __pContextMenuPresenter->CalculateWindowRect();
475 _ContextMenu::RemoveAllItems(void)
477 result r = E_SUCCESS;
479 r = __pContextMenuPresenter->DeleteItemAll();
480 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to remove all items.");
482 __actionId.RemoveAll();
484 __pContextMenuPresenter->CalculateShowItemCount();
485 __pContextMenuPresenter->CalculateWindowRect();
491 _ContextMenu::GetItemCount(void) const
493 return __actionId.GetCount();
497 _ContextMenu::GetItemIndexAt(int actionId) const
499 int count = __actionId.GetCount();
501 for (int i = 0; i < count; i++)
503 int index = GetItemActionIdAt(i);
505 if (actionId == index)
515 _ContextMenu::GetItemActionIdAt(int index) const
517 int count = __actionId.GetCount();
520 if (count <= 0 || index >= count)
525 __actionId.GetAt(index, actionId);
531 _ContextMenu::SetAnchorPosition(float x, float y)
536 if (__align == CONTEXT_MENU_CORE_ALIGN_AUTO)
538 AdjustDropPosition();
541 __pContextMenuPresenter->CalculateWindowRect();
546 _ContextMenu::GetAnchorPosition(void) const
548 return __anchorPoint;
552 _ContextMenu::SetWindowRect(const FloatRectangle& rect)
560 _ContextMenu::GetWindowRect(void) const
566 _ContextMenu::SetBodyRect(const FloatRectangle& rect)
574 _ContextMenu::GetBodyRect(void) const
580 _ContextMenu::SetArrowRect(const FloatRectangle& rect)
588 _ContextMenu::GetArrowRect(void) const
594 _ContextMenu::SetItemRect(const FloatRectangle& rect)
602 _ContextMenu::GetItemRect(void) const
608 _ContextMenu::SetPropertyMaxVisibleItemsCount(const Variant& count)
610 int showCount = count.ToInt();
614 SysLogException(NID_UI_CTRL, E_INVALID_ARG, "Count is invalid.");
615 return E_INVALID_ARG;
619 __showItemCount = showCount;
625 _ContextMenu::GetPropertyMaxVisibleItemsCount(void) const
627 return Tizen::Ui::Variant(__showItemCount);
631 _ContextMenu::GetShowItemCount(void) const
633 Variant count = GetProperty("maxVisibleItemsCount");
635 return count.ToInt();
639 _ContextMenu::GetShowItemMaxCount(void) const
641 return __showItemMaxCount;
645 _ContextMenu::SetShowItemCount(int count)
649 r = SetProperty("maxVisibleItemsCount", Variant(count));
650 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to set property.");
652 if (__style == CONTEXT_MENU_CORE_STYLE_LIST)
654 r = __pContextMenuPresenter->CalculateWindowRect();
655 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to calculate window.");
662 _ContextMenu::SetPropertyColor(const Variant& color)
664 __backgroundColor = color.ToColor();
666 LoadColorReplacedBitmap(__backgroundColor);
672 _ContextMenu::GetPropertyColor(void) const
674 return Tizen::Ui::Variant(__backgroundColor);
678 _ContextMenu::SetColor(const Graphics::Color& color)
680 return SetProperty("color", Variant(color));
684 _ContextMenu::GetColor(void) const
686 Variant color = GetProperty("color");
688 return color.ToColor();
692 _ContextMenu::SetPropertyNormalItemColor(const Variant& color)
694 __itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL] = color.ToColor();
696 return __pContextMenuPresenter->ApplyColorProperty();
700 _ContextMenu::GetPropertyNormalItemColor(void) const
702 return Tizen::Ui::Variant(__itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL]);
706 _ContextMenu::SetPropertyPressedItemColor(const Variant& color)
708 __itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED] = color.ToColor();
710 return __pContextMenuPresenter->ApplyColorProperty();
714 _ContextMenu::GetPropertyPressedItemColor(void) const
716 return Tizen::Ui::Variant(__itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED]);
720 _ContextMenu::SetPropertyHighlightedItemColor(const Variant & color)
722 __itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_HIGHLIGHTED] = color.ToColor();
724 return __pContextMenuPresenter->ApplyColorProperty();
728 _ContextMenu::GetPropertyHighlightedItemColor(void) const
730 return Tizen::Ui::Variant(__itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_HIGHLIGHTED]);
734 _ContextMenu::SetItemColor(enum ContextMenuCoreItemStatus status, const Graphics::Color& color)
736 result r = E_SUCCESS;
738 if (status == CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL)
740 r = SetProperty("normalItemColor", Variant(color));
742 else if (status == CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED)
744 r = SetProperty("pressedItemColor", Variant(color));
748 r = SetProperty("highlightedItemColor", Variant(color));
755 _ContextMenu::GetItemColor(enum ContextMenuCoreItemStatus status) const
759 if (status == CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL)
761 Variant color = GetProperty("normalItemColor");
762 itemColor = color.ToColor();
765 else if (status == CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED)
767 Variant color = GetProperty("pressedItemColor");
768 itemColor = color.ToColor();
773 Variant color = GetProperty("highlightedItemColor");
774 itemColor = color.ToColor();
782 _ContextMenu::SetPropertyNormalItemTextColor(const Variant& color)
784 __textColor[CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL] = color.ToColor();
786 return __pContextMenuPresenter->ApplyColorProperty();
790 _ContextMenu::GetPropertyNormalItemTextColor(void) const
792 return Tizen::Ui::Variant(__textColor[CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL]);
796 _ContextMenu::SetPropertyPressedItemTextColor(const Variant& color)
798 __textColor[CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED] = color.ToColor();
800 return __pContextMenuPresenter->ApplyColorProperty();
804 _ContextMenu::GetPropertyPressedItemTextColor(void) const
806 return Tizen::Ui::Variant(__textColor[CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED]);
810 _ContextMenu::SetPropertyHighlightedItemTextColor(const Variant & color)
812 __textColor[CONTEXT_MENU_CORE_ITEM_STATUS_HIGHLIGHTED] = color.ToColor();
814 return __pContextMenuPresenter->ApplyColorProperty();
818 _ContextMenu::GetPropertyHighlightedItemTextColor(void) const
820 return Tizen::Ui::Variant(__textColor[CONTEXT_MENU_CORE_ITEM_STATUS_HIGHLIGHTED]);
824 _ContextMenu::SetTextColor(enum ContextMenuCoreItemStatus status, const Graphics::Color& color)
826 result r = E_SUCCESS;
828 if (status == CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL)
830 r = SetProperty("normalItemTextColor", Variant(color));
832 else if (status == CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED)
834 r = SetProperty("pressedItemTextColor", Variant(color));
838 r = SetProperty("highlightedItemTextColor", Variant(color));
846 _ContextMenu::GetTextColor(enum ContextMenuCoreItemStatus status) const
850 if (status == CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL)
852 Variant color = GetProperty("normalItemTextColor");
853 textColor = color.ToColor();
856 else if (status == CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED)
858 Variant color = GetProperty("pressedItemTextColor");
859 textColor = color.ToColor();
864 Variant color = GetProperty("highlightedItemTextColor");
865 textColor = color.ToColor();
872 _ContextMenu::AddActionEventListener(const Tizen::Ui::Controls::_IActionEventListener& listener)
874 result r = E_SUCCESS;
876 if (__pActionEvent == null)
878 __pActionEvent = _ActionEvent::CreateInstanceN(*this);
879 SysTryReturn(NID_UI_CTRL, __pActionEvent != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
880 "[E_OUT_OF_MEMORY] The memory is insufficient.")
882 r = __pActionEvent->AddListener(listener);
883 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to remove an action event listener.")
889 delete __pActionEvent;
890 __pActionEvent = null;
895 _ContextMenu::RemoveActionEventListener(const Tizen::Ui::Controls::_IActionEventListener& listener)
897 SysTryReturn(NID_UI_CTRL, __pActionEvent != null, E_INVALID_STATE, E_INVALID_STATE,
898 "[E_INVALID_STATE] The action event instance isn't constructed.")
900 result r = E_SUCCESS;
902 r = __pActionEvent->RemoveListener(listener);
903 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to remove an action event listener")
908 Tizen::Ui::Controls::_ActionEvent*
909 _ContextMenu::GetActionEvent(void) const
911 return __pActionEvent;
915 _ContextMenu::LoadBitmap(void)
917 Color backgroundColor;
920 if (__pBackgroundEffectBitmap != null)
922 delete __pBackgroundEffectBitmap;
923 __pBackgroundEffectBitmap = null;
926 for (int i = 0; i < CONTEXT_MENU_CORE_DROP_POSITION_MAX; i++)
928 if (__pArrowEffectBitmap[i] != null)
930 delete __pArrowEffectBitmap[i];
931 __pArrowEffectBitmap[i] = null;
935 backgroundColor = GetColor();
939 r = GET_BITMAP_CONFIG_N(CONTEXTMENU::ANCHOR_EFFECT_UP, BITMAP_PIXEL_FORMAT_ARGB8888,
940 __pArrowEffectBitmap[CONTEXT_MENU_CORE_DROP_POSITION_UP]);
941 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
943 r = GET_BITMAP_CONFIG_N(CONTEXTMENU::ANCHOR_EFFECT_DOWN, BITMAP_PIXEL_FORMAT_ARGB8888,
944 __pArrowEffectBitmap[CONTEXT_MENU_CORE_DROP_POSITION_DOWN]);
945 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
947 r = GET_BITMAP_CONFIG_N(CONTEXTMENU::ANCHOR_EFFECT_LEFT, BITMAP_PIXEL_FORMAT_ARGB8888,
948 __pArrowEffectBitmap[CONTEXT_MENU_CORE_DROP_POSITION_LEFT]);
949 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
951 r = GET_BITMAP_CONFIG_N(CONTEXTMENU::ANCHOR_EFFECT_RIGHT, BITMAP_PIXEL_FORMAT_ARGB8888,
952 __pArrowEffectBitmap[CONTEXT_MENU_CORE_DROP_POSITION_RIGHT]);
953 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
955 r = GET_BITMAP_CONFIG_N(CONTEXTMENU::BG_OUTLINE_EFFECT_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pBackgroundEffectBitmap);
956 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
958 r = LoadColorReplacedBitmap(backgroundColor);
959 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
964 delete __pBackgroundEffectBitmap;
965 __pBackgroundEffectBitmap = null;
967 for (int i = 0; i < CONTEXT_MENU_CORE_DROP_POSITION_MAX; i++)
970 delete __pArrowEffectBitmap[i];
971 __pArrowEffectBitmap[i] = null;
978 _ContextMenu::LoadColorReplacedBitmap(const Tizen::Graphics::Color& color)
980 Bitmap* ptempNormalBitmap = null;
983 if (__pBackgroundNormalBitmap != null)
985 delete __pBackgroundNormalBitmap;
986 __pBackgroundNormalBitmap = null;
989 for (int i = 0; i < CONTEXT_MENU_CORE_DROP_POSITION_MAX; i++)
991 if (__pArrowNormalBitmap[i] != null)
993 delete __pArrowNormalBitmap[i];
994 __pArrowNormalBitmap[i] = null;
999 r = GET_BITMAP_CONFIG_N(CONTEXTMENU::ANCHOR_NORMAL_UP, BITMAP_PIXEL_FORMAT_ARGB8888, ptempNormalBitmap);
1000 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
1001 __pArrowNormalBitmap[CONTEXT_MENU_CORE_DROP_POSITION_UP] = _BitmapImpl::GetColorReplacedBitmapN(*ptempNormalBitmap,
1002 Color::GetColor(COLOR_ID_MAGENTA), color);
1003 SysTryCatch(NID_UI_CTRL, __pArrowNormalBitmap[CONTEXT_MENU_CORE_DROP_POSITION_UP] != null, , GetLastResult(),
1004 "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1005 delete ptempNormalBitmap;
1006 ptempNormalBitmap = null;
1008 r = GET_BITMAP_CONFIG_N(CONTEXTMENU::ANCHOR_NORMAL_DOWN, BITMAP_PIXEL_FORMAT_ARGB8888, ptempNormalBitmap);
1009 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
1010 __pArrowNormalBitmap[CONTEXT_MENU_CORE_DROP_POSITION_DOWN] = _BitmapImpl::GetColorReplacedBitmapN(*ptempNormalBitmap,
1011 Color::GetColor(COLOR_ID_MAGENTA), color);
1012 SysTryCatch(NID_UI_CTRL, __pArrowNormalBitmap[CONTEXT_MENU_CORE_DROP_POSITION_DOWN] != null, , GetLastResult(),
1013 "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1014 delete ptempNormalBitmap;
1015 ptempNormalBitmap = null;
1017 r = GET_BITMAP_CONFIG_N(CONTEXTMENU::ANCHOR_NORMAL_LEFT, BITMAP_PIXEL_FORMAT_ARGB8888, ptempNormalBitmap);
1018 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
1019 __pArrowNormalBitmap[CONTEXT_MENU_CORE_DROP_POSITION_LEFT] = _BitmapImpl::GetColorReplacedBitmapN(*ptempNormalBitmap,
1020 Color::GetColor(COLOR_ID_MAGENTA), color);
1021 SysTryCatch(NID_UI_CTRL, __pArrowNormalBitmap[CONTEXT_MENU_CORE_DROP_POSITION_LEFT] != null, , GetLastResult(),
1022 "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1023 delete ptempNormalBitmap;
1024 ptempNormalBitmap = null;
1026 r = GET_BITMAP_CONFIG_N(CONTEXTMENU::ANCHOR_NORMAL_RIGHT, BITMAP_PIXEL_FORMAT_ARGB8888, ptempNormalBitmap);
1027 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
1028 __pArrowNormalBitmap[CONTEXT_MENU_CORE_DROP_POSITION_RIGHT] = _BitmapImpl::GetColorReplacedBitmapN(*ptempNormalBitmap,
1029 Color::GetColor(COLOR_ID_MAGENTA), color);
1030 SysTryCatch(NID_UI_CTRL, __pArrowNormalBitmap[CONTEXT_MENU_CORE_DROP_POSITION_RIGHT] != null, , GetLastResult(),
1031 "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1032 delete ptempNormalBitmap;
1033 ptempNormalBitmap = null;
1035 r = GET_BITMAP_CONFIG_N(CONTEXTMENU::BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, ptempNormalBitmap);
1036 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
1037 __pBackgroundNormalBitmap = _BitmapImpl::GetColorReplacedBitmapN(*ptempNormalBitmap, Color::GetColor(COLOR_ID_MAGENTA), color);
1038 SysTryCatch(NID_UI_CTRL, __pBackgroundNormalBitmap != null, , GetLastResult(), "[%s] Propagating.",
1039 GetErrorMessage(GetLastResult()));
1040 delete ptempNormalBitmap;
1045 delete ptempNormalBitmap;
1047 delete __pBackgroundNormalBitmap;
1048 __pBackgroundNormalBitmap = null;
1050 for (int i = 0; i < CONTEXT_MENU_CORE_DROP_POSITION_MAX; i++)
1052 delete __pArrowNormalBitmap[i];
1053 __pArrowNormalBitmap[i] = null;
1060 _ContextMenu::GetArrowNormalBitmap(ContextMenuCoreDropPosition dropPosition) const
1062 if (dropPosition == CONTEXT_MENU_CORE_DROP_POSITION_INVALID || dropPosition == CONTEXT_MENU_CORE_DROP_POSITION_MAX)
1067 return __pArrowNormalBitmap[dropPosition];
1071 _ContextMenu::GetArrowEffectBitmap(ContextMenuCoreDropPosition dropPosition) const
1073 if (dropPosition == CONTEXT_MENU_CORE_DROP_POSITION_INVALID || dropPosition == CONTEXT_MENU_CORE_DROP_POSITION_MAX)
1078 return __pArrowEffectBitmap[dropPosition];
1082 _ContextMenu::GetBackgroundNormalBitmap(void) const
1084 return __pBackgroundNormalBitmap;
1088 _ContextMenu::GetBackgroundEffectBitmap(void) const
1090 return __pBackgroundEffectBitmap;
1093 enum ContextMenuCoreDropPosition
1094 _ContextMenu::GetDropPosition(void) const
1096 return __dropPosition;
1100 _ContextMenu::AdjustDropPosition(void)
1102 FloatDimension screen = _ControlManager::GetInstance()->GetScreenSizeF();
1104 if (__align == CONTEXT_MENU_CORE_ALIGN_UP)
1106 __dropPosition = CONTEXT_MENU_CORE_DROP_POSITION_UP;
1108 else if (__align == CONTEXT_MENU_CORE_ALIGN_DOWN)
1110 __dropPosition = CONTEXT_MENU_CORE_DROP_POSITION_DOWN;
1112 else if (__align == CONTEXT_MENU_CORE_ALIGN_LEFT)
1114 __dropPosition = CONTEXT_MENU_CORE_DROP_POSITION_LEFT;
1116 else if (__align == CONTEXT_MENU_CORE_ALIGN_RIGHT)
1118 __dropPosition = CONTEXT_MENU_CORE_DROP_POSITION_RIGHT;
1122 if (__layout == _CONTROL_ORIENTATION_LANDSCAPE)
1124 screen.SetSize(screen.height, screen.width);
1127 if (screen.height > screen.width)
1129 if ((screen.height / 2.0f) > __anchorPoint.y)
1131 __dropPosition = CONTEXT_MENU_CORE_DROP_POSITION_DOWN;
1135 __dropPosition = CONTEXT_MENU_CORE_DROP_POSITION_UP;
1140 if ((screen.width / 2.0f) > __anchorPoint.x)
1142 __dropPosition = CONTEXT_MENU_CORE_DROP_POSITION_RIGHT;
1146 __dropPosition = CONTEXT_MENU_CORE_DROP_POSITION_LEFT;
1152 _UiTouchEventDelivery
1153 _ContextMenu::OnPreviewTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
1155 return __pContextMenuPresenter->OnPreviewTouchPressed(source, touchinfo);
1159 _ContextMenu::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
1161 return __pContextMenuPresenter->OnTouchPressed(source, touchinfo);
1164 _UiTouchEventDelivery
1165 _ContextMenu::OnPreviewTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
1167 return __pContextMenuPresenter->OnPreviewTouchMoved(source, touchinfo);
1171 _ContextMenu::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
1173 return __pContextMenuPresenter->OnTouchMoved(source, touchinfo);
1176 _UiTouchEventDelivery
1177 _ContextMenu::OnPreviewTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
1179 return __pContextMenuPresenter->OnPreviewTouchReleased(source, touchinfo);
1183 _ContextMenu::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
1185 return __pContextMenuPresenter->OnTouchReleased(source, touchinfo);
1189 _ContextMenu::OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
1191 __pContextMenuPresenter->OnTouchCanceled(source, touchinfo);
1193 SetVisibleState(false);
1199 _ContextMenu::OnFontChanged(Tizen::Graphics::Font* pFont)
1201 return __pContextMenuPresenter->OnFontChanged(pFont);
1205 _ContextMenu::OnFontInfoRequested(unsigned long& style, float& size)
1207 return __pContextMenuPresenter->OnFontInfoRequested(style, size);
1211 _ContextMenu::OnVisibleStateChanged(void)
1213 _Window::OnVisibleStateChanged();
1217 _ContextMenu::OnChangeLayout(_ControlOrientation orientation)
1219 GET_SHAPE_CONFIG(CONTEXTMENU::ITEM_MAX_COUNT, orientation, __showItemMaxCount);
1221 if (__isAttachedToMainTree == true)
1223 if (__layout != orientation)
1225 SetVisibleState(false);
1229 __layout = orientation;
1233 _ContextMenu::OnOwnerChanged(_Control* pOldOwner)
1235 if (!__isAttachedToMainTree)
1240 _Control* pOwner = GetOwner();
1242 if (pOldOwner != null)
1244 pOldOwner->UnlockInputEvent();
1249 pOwner->LockInputEvent();
1253 _AccessibilityElement*
1254 _ContextMenu::GetAccessibilityElement(const int mainIndex) const
1256 _AccessibilityElement* pElement = null;
1257 result r = __accessibilityElements.GetAt(mainIndex, pElement);
1258 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed at AccessibilityElement.", GetErrorMessage(r));
1269 _ContextMenu::AddAccessibilityElement(const _AccessibilityElement& element)
1271 __accessibilityElements.Add(const_cast<_AccessibilityElement*>(&element));
1275 _ContextMenu::SetAllAccessibilityElement(void)
1277 RemoveAllAccessibilityElement();
1278 __pContextMenuPresenter->SetAllAccessibilityElement();
1282 _ContextMenu::OnAccessibilityFocusMovedNext(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1288 _ContextMenu::OnAccessibilityFocusMovedPrevious(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1294 _ContextMenu::OnAccessibilityReadElement(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1300 _ContextMenu::OnAccessibilityReadingElement(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1306 _ContextMenu::OnAccessibilityFocusIn(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1312 _ContextMenu::OnAccessibilityFocusOut(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1318 _ContextMenu::OnAccessibilityActionPerformed(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1320 SetVisibleState(false);
1326 _ContextMenu::OnAccessibilityValueIncreased(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1332 _ContextMenu::OnAccessibilityValueDecreased(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1338 _ContextMenu::RemoveAllAccessibilityElement(void)
1340 _AccessibilityContainer* pAccessibilityContainer = GetAccessibilityContainer();
1341 if (pAccessibilityContainer && pAccessibilityContainer->IsActivated())
1343 pAccessibilityContainer->RemoveAllElement();
1347 _ContextMenuItemInfo
1348 _ContextMenu::GetItemFromPosition(const FloatPoint& position) const
1350 return __pContextMenuPresenter->GetItemFromPosition(position);
1353 _ContextMenuItemInfo
1354 _ContextMenu::FindItem(int index) const
1356 return __pContextMenuPresenter->FindItem(index);
1360 _ContextMenu::SetTopDrawnItemIndex(int index)
1362 return __pContextMenuPresenter->SetTopDrawnItemIndex(index);
1366 _ContextMenu::GetLayout(void) const
1371 }}} // Tizen::Ui: Control