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 "FUi_KeyEventManager.h"
29 #include "FUiAnim_VisualElement.h"
30 #include "FUiAnim_AnimationManager.h"
31 #include "FUi_AccessibilityContainer.h"
32 #include "FUi_AccessibilityElement.h"
33 #include "FUiCtrl_Form.h"
34 #include "FUiCtrl_Frame.h"
35 #include "FUiCtrl_ContextMenu.h"
36 #include "FUiCtrl_Scroll.h"
38 using namespace Tizen::Graphics;
39 using namespace Tizen::Media;
40 using namespace Tizen::Ui::Animations;
43 static const float TOUCH_PRESS_THRESHOLD_INSENSITIVE = 0.16f;
46 namespace Tizen { namespace Ui { namespace Controls
49 IMPLEMENT_PROPERTY(_ContextMenu);
51 _ContextMenu::_ContextMenu(const FloatPoint& point, enum ContextMenuCoreStyle style, enum ContextMenuCoreAlign contextMenuAlign)
52 : __pContextMenuPresenter(null)
54 , __align(contextMenuAlign)
55 , __showItemCount(MAX_CONTEXTMENU_LIST_SHOW_ITEM)
56 , __showItemMaxCount(0)
57 , __isAttachedToMainTree(false)
58 , __ownerInputEnableState(false)
59 , __anchorPoint(point)
60 , __windowRect(FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f))
61 , __bodyRect(FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f))
62 , __arrowRect(FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f))
63 , __itemRect(FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f))
64 , __pActionEvent(null)
65 , __pBackgroundNormalBitmap(null)
66 , __pBackgroundEffectBitmap(null)
67 , __dropPosition(CONTEXT_MENU_CORE_DROP_POSITION_INVALID)
68 , __layout(_CONTROL_ORIENTATION_PORTRAIT)
69 , __rotation(_CONTROL_ROTATION_0)
70 , __pScrollPanel(null)
72 __backgroundColor = Color(255, 255, 255, 255);
74 __textColor[CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL] = Color(255, 255, 255, 255);
75 __textColor[CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED] = Color(255, 255, 255, 255);
76 __textColor[CONTEXT_MENU_CORE_ITEM_STATUS_HIGHLIGHTED] = Color(255, 255, 255, 255);
78 __itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL] = Color(255, 255, 255, 255);
79 __itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED] = Color(255, 255, 255, 255);
80 __itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_HIGHLIGHTED] = Color(255, 255, 255, 255);
82 for (int i = 0; i < CONTEXT_MENU_CORE_DROP_POSITION_MAX; i++)
84 __pArrowNormalBitmap[i] = null;
85 __pArrowEffectBitmap[i] = null;
88 GET_SHAPE_CONFIG(CONTEXTMENU::ITEM_MAX_COUNT, __layout, __showItemMaxCount);
91 _ContextMenu::~_ContextMenu(void)
93 if (__isAttachedToMainTree && GetOwner() != null)
95 GetOwner()->UnlockInputEvent();
99 __pScrollPanel->DetachAllChildren();
100 DetachChild(*__pScrollPanel);
101 delete __pScrollPanel;
102 __pScrollPanel = null;
105 delete __pContextMenuPresenter;
106 __pContextMenuPresenter = null;
108 if (__pBackgroundNormalBitmap != null)
110 delete __pBackgroundNormalBitmap;
111 __pBackgroundNormalBitmap = null;
114 if (__pBackgroundEffectBitmap != null)
116 delete __pBackgroundEffectBitmap;
117 __pBackgroundEffectBitmap = null;
122 delete __pActionEvent;
123 __pActionEvent = null;
126 for (int i = 0; i < CONTEXT_MENU_CORE_DROP_POSITION_MAX; i++)
128 delete __pArrowNormalBitmap[i];
129 __pArrowNormalBitmap[i] = null;
131 delete __pArrowEffectBitmap[i];
132 __pArrowEffectBitmap[i] = null;
135 __actionId.RemoveAll();
137 RemoveAllAccessibilityElement();
141 _ContextMenu::CreateContextMenuN(const FloatPoint& point, enum ContextMenuCoreStyle style, enum ContextMenuCoreAlign contextMenuAlign)
143 _ContextMenu* pContextMenu = new (std::nothrow) _ContextMenu(point, style, contextMenuAlign);
144 SysTryReturn(NID_UI_CTRL, pContextMenu != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
146 result r = E_SUCCESS;
148 r = pContextMenu->CreateRootVisualElement();
149 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
151 pContextMenu->SetFocusable(false);
153 r = pContextMenu->Initialize();
154 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to Initialize.", GetErrorMessage(r));
156 r = pContextMenu->Install();
157 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to Install.", GetErrorMessage(r));
159 pContextMenu->AcquireHandle();
160 pContextMenu->SetTouchPressThreshold(TOUCH_PRESS_THRESHOLD_INSENSITIVE);
162 if (pContextMenu->GetAccessibilityContainer() != null)
164 pContextMenu->GetAccessibilityContainer()->Activate(true);
165 pContextMenu->GetAccessibilityContainer()->AddListener(*pContextMenu);
168 if (style == CONTEXT_MENU_CORE_STYLE_LIST)
170 float minWidth, minHeight; // for visible scrollbar when scrollable
171 GET_SHAPE_CONFIG(CONTEXTMENU::LIST_MIN_WIDTH, _CONTROL_ORIENTATION_PORTRAIT, minWidth);
172 GET_SHAPE_CONFIG(CONTEXTMENU::LIST_ITEM_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, minHeight);
173 pContextMenu->__pScrollPanel = _ScrollPanel::CreateScrollPanelN(FloatRectangle(0.0f, 0.0f, minWidth, minHeight), SCROLL_PANEL_SCROLL_DIRECTION_VERTICAL, false, false);
174 pContextMenu->__pScrollPanel->SetTouchPressThreshold(TOUCH_PRESS_THRESHOLD_INSENSITIVE);
175 pContextMenu->__pScrollPanel->SetFocusable(false);
177 _Scroll* pScroll = pContextMenu->__pScrollPanel->GetScrollBar();
178 SysTryCatch(NID_UI_CTRL, pScroll, , E_INVALID_STATE, "[E_INVALID_STATE] _Scroll isn't constructed");
179 pScroll->SetContextMenuScrollType(true);
181 pContextMenu->AttachChild(*(pContextMenu->__pScrollPanel));
193 _ContextMenu::GetScrollPanel(void)
195 return __pScrollPanel;
199 _ContextMenu::Install(void)
201 result r = E_SUCCESS;
203 // load bitmap of a background and arrow
205 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to load bitmap.");
207 r = __actionId.Construct();
208 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to construct arraylist.");
210 if (__style == CONTEXT_MENU_CORE_STYLE_LIST)
212 _IContextMenuPresenter* pPresenter = new (std::nothrow) _ContextMenuListPresenter(this);
213 SysTryReturnResult(NID_UI_CTRL, pPresenter != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
215 SetPresenter(*pPresenter);
217 r = pPresenter->Install();
221 _IContextMenuPresenter* pPresenter = new (std::nothrow) _ContextMenuGridPresenter(this);
222 SysTryReturnResult(NID_UI_CTRL, pPresenter != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
224 SetPresenter(*pPresenter);
226 r = pPresenter->Install();
233 _ContextMenu::Initialize(void)
235 FloatDimension screen = _ControlManager::GetInstance()->GetScreenSizeF();
236 result r = E_SUCCESS;
238 Color backgroundColor;
239 Color backgroundSelectedColor;
241 Color itemTextSelectedColor;
243 r = SetBounds(FloatRectangle(0.0f, 0.0f, screen.width, screen.height));
244 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "SetBounds failed.");
249 GET_COLOR_CONFIG(CONTEXTMENU::BG_NORMAL, backgroundColor);
250 GET_COLOR_CONFIG(CONTEXTMENU::ITEM_BG_PRESSED, backgroundSelectedColor);
251 GET_COLOR_CONFIG(CONTEXTMENU::ITEM_TEXT_NORMAL, itemTextColor);
252 GET_COLOR_CONFIG(CONTEXTMENU::ITEM_TEXT_PRESSED, itemTextSelectedColor);
254 __backgroundColor = backgroundColor;
255 __itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL] = backgroundColor;
256 __itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED] = backgroundSelectedColor;
257 __textColor[CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL] = itemTextColor;
258 __textColor[CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED] = itemTextSelectedColor;
260 if (GetVisualElement() != null)
262 GetVisualElement()->SetSurfaceOpaque(false);
270 _ContextMenu::SetPresenter(const _IContextMenuPresenter& ContextMenuPresenter)
272 __pContextMenuPresenter = const_cast <_IContextMenuPresenter*>(&ContextMenuPresenter);
278 _ContextMenu::OnDraw()
280 __pContextMenuPresenter->Draw();
282 if(unlikely((_AccessibilityManager::IsActivated())))
284 _AccessibilityManager::GetInstance()->RequestAutoReading(_ACCESSIBILITY_AUTO_READING_MODE_FIRST_ITEM);
289 _ContextMenu::OnAttachedToMainTree(void)
291 result r = E_SUCCESS;
293 __layout = _ControlManager::GetInstance()->GetOrientation();
294 __rotation = _ControlManager::GetInstance()->GetScreenRotation();
295 __isAttachedToMainTree = true;
296 _Control* pOwner = GetOwner();
299 _Frame* pFrame = dynamic_cast<_Frame*>(_ControlManager::GetInstance()->GetCurrentFrame());
300 SysTryReturn(NID_UI_CTRL, pFrame != null, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Current frame instance is not available.");
302 _Form* pForm = pFrame->GetCurrentForm();
303 pForm != null ? SetOwner(pForm) : SetOwner(pFrame);
305 GET_SHAPE_CONFIG(CONTEXTMENU::ITEM_MAX_COUNT, __layout, __showItemMaxCount);
309 pOwner->LockInputEvent();
312 AdjustDropPosition();
314 if (GetItemCount() <= 0)
316 __pContextMenuPresenter->CalculateShowItemCount();
319 r = __pContextMenuPresenter->CalculateWindowRect();
320 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
322 if (__pScrollPanel != null)
324 __pScrollPanel->SetScrollPosition(0.0f, false);
329 SetVisibleState(true);
331 if (__style == CONTEXT_MENU_CORE_STYLE_LIST)
333 SetTouchCapture(false, false);
337 SetTouchCapture(true, false);
340 SetAllAccessibilityElement();
342 _VisualElement* pVisualElement = GetVisualElement();
343 FloatRectangle pBounds = pVisualElement->GetBounds();
344 float oldBoundsX = pBounds.x;
345 float oldBoundsY = pBounds.y;
346 float distanceX = 0.0f;
347 float distanceY = 0.0f;
349 GET_SHAPE_CONFIG(CONTEXTMENU::APPEARING_ANIMATION_DISTANCE_X, __layout, distanceX);
350 GET_SHAPE_CONFIG(CONTEXTMENU::APPEARING_ANIMATION_DISTANCE_Y, __layout, distanceY);
352 switch(GetDropPosition())
354 case CONTEXT_MENU_CORE_DROP_POSITION_UP:
355 pBounds.y += distanceY;
357 case CONTEXT_MENU_CORE_DROP_POSITION_DOWN:
358 pBounds.y -= distanceY;
360 case CONTEXT_MENU_CORE_DROP_POSITION_LEFT:
361 pBounds.x += distanceX;
363 case CONTEXT_MENU_CORE_DROP_POSITION_RIGHT:
364 pBounds.x -= distanceX;
370 pVisualElement->SetBounds(pBounds);
371 pVisualElement->SetOpacity(0.0f);
373 bool enable = pVisualElement->IsImplicitAnimationEnabled();
375 pVisualElement->SetImplicitAnimationEnabled(true);
377 pBounds.x = oldBoundsX;
378 pBounds.y = oldBoundsY;
379 pVisualElement->SetBounds(pBounds);
380 pVisualElement->SetOpacity(1.0f);
382 pVisualElement->SetImplicitAnimationEnabled(enable);
388 _ContextMenu::OnDetachingFromMainTree(void)
390 result r = E_SUCCESS;
392 ReleaseTouchCapture();
394 _Control* pOwner = GetOwner();
397 pOwner->UnlockInputEvent();
400 __isAttachedToMainTree = false;
406 _ContextMenu::AddItem(const Base::String& text, int actionId, const Bitmap* pNormalBitmap, const Bitmap* pPressedBitmap,
407 const Bitmap* pHighlightedBitmap)
409 result r = E_SUCCESS;
411 r = __pContextMenuPresenter->AddItem(text, actionId, pNormalBitmap, pPressedBitmap, pHighlightedBitmap);
412 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to add a item.");
414 __actionId.Add(actionId);
416 __pContextMenuPresenter->CalculateShowItemCount();
417 __pContextMenuPresenter->CalculateWindowRect();
423 _ContextMenu::InsertItem(int index, const Base::String& text, int actionId, const Bitmap* pNormalBitmap,
424 const Bitmap* pPressedBitmap,
425 const Bitmap* pHighlightedBitmap)
427 result r = E_SUCCESS;
429 r = __pContextMenuPresenter->InsertItem(index, text, actionId, pNormalBitmap, pPressedBitmap, pHighlightedBitmap);
430 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to insert a item.");
432 __actionId.InsertAt(actionId, index);
434 __pContextMenuPresenter->CalculateShowItemCount();
435 __pContextMenuPresenter->CalculateWindowRect();
441 _ContextMenu::SetItem(int index, const Base::String& text, int actionId, const Bitmap* pNormalBitmap,
442 const Bitmap* pPressedBitmap, const Bitmap* pHighlightedBitmap)
444 result r = E_SUCCESS;
446 r = __pContextMenuPresenter->SetItem(index, text, actionId, pNormalBitmap, pPressedBitmap, pHighlightedBitmap);
447 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to set a item.");
449 __actionId.SetAt(actionId, index);
451 __pContextMenuPresenter->CalculateWindowRect();
457 _ContextMenu::RemoveItemAt(int index)
459 result r = E_SUCCESS;
461 r = __pContextMenuPresenter->DeleteItem(index);
462 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to remove a item.");
464 __actionId.RemoveAt(index);
466 __pContextMenuPresenter->CalculateShowItemCount();
467 __pContextMenuPresenter->CalculateWindowRect();
473 _ContextMenu::RemoveAllItems(void)
475 result r = E_SUCCESS;
477 r = __pContextMenuPresenter->DeleteItemAll();
478 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to remove all items.");
480 __actionId.RemoveAll();
482 __pContextMenuPresenter->CalculateShowItemCount();
483 __pContextMenuPresenter->CalculateWindowRect();
489 _ContextMenu::GetItemCount(void) const
491 return __actionId.GetCount();
495 _ContextMenu::GetItemIndexAt(int actionId) const
497 int count = __actionId.GetCount();
499 for (int i = 0; i < count; i++)
501 int index = GetItemActionIdAt(i);
503 if (actionId == index)
513 _ContextMenu::GetItemActionIdAt(int index) const
515 int count = __actionId.GetCount();
517 result r = E_SUCCESS;
519 if (count <= 0 || index >= count)
524 r = __actionId.GetAt(index, actionId);
525 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, actionId, r, "[%s] Propagating.", GetErrorMessage(r));
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);
1188 _UiTouchEventDelivery
1189 _ContextMenu::OnPreviewTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
1191 return __pContextMenuPresenter->OnPreviewTouchCanceled(source, touchinfo);
1195 _ContextMenu::OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
1197 __pContextMenuPresenter->OnTouchCanceled(source, touchinfo);
1199 SetVisibleState(false);
1205 _ContextMenu::OnFontChanged(Tizen::Graphics::Font* pFont)
1207 return __pContextMenuPresenter->OnFontChanged(pFont);
1211 _ContextMenu::OnFontInfoRequested(unsigned long& style, float& size)
1213 return __pContextMenuPresenter->OnFontInfoRequested(style, size);
1217 _ContextMenu::OnVisibleStateChanged(void)
1219 _Window::OnVisibleStateChanged();
1223 _ContextMenu::OnChangeLayout(_ControlRotation rotation)
1225 _ControlOrientation orientation;
1227 orientation = GetOwner()->GetOrientation();
1229 GET_SHAPE_CONFIG(CONTEXTMENU::ITEM_MAX_COUNT, orientation, __showItemMaxCount);
1231 if (__isAttachedToMainTree == true)
1233 if(__rotation != rotation)
1235 SetVisibleState(false);
1239 __layout = orientation;
1240 __rotation = rotation;
1243 _ContextMenu::OnOwnerChanged(_Control* pOldOwner)
1245 if (!__isAttachedToMainTree)
1250 _Control* pOwner = GetOwner();
1252 if (pOldOwner != null)
1254 pOldOwner->UnlockInputEvent();
1259 pOwner->LockInputEvent();
1264 _ContextMenu::OnTouchCaptureGained(void)
1266 if (__style == CONTEXT_MENU_CORE_STYLE_LIST)
1268 SetTouchCapture(false, false);
1272 SetTouchCapture(true, false);
1277 _ContextMenu::OnTouchCaptureLost(void)
1282 _ContextMenu::OnKeyPressed(const _Control& source, const _KeyInfo& keyInfo)
1284 return __pContextMenuPresenter->OnKeyPressed(source, keyInfo);
1288 _ContextMenu::OnKeyReleased(const _Control& source, const _KeyInfo& keyInfo)
1290 return __pContextMenuPresenter->OnKeyReleased(source, keyInfo);
1294 _ContextMenu::IsChildControlFocusManage(void) const
1296 return __pContextMenuPresenter->IsChildControlFocusManage();
1300 _ContextMenu::OnDrawFocus(void)
1302 __pContextMenuPresenter->OnDrawFocus();
1306 _ContextMenu::OnFocusModeStateChanged(void)
1308 __pContextMenuPresenter->OnFocusModeStateChanged();
1311 _AccessibilityElement*
1312 _ContextMenu::GetAccessibilityElement(const int mainIndex) const
1314 _AccessibilityElement* pElement = null;
1315 result r = __accessibilityElements.GetAt(mainIndex, pElement);
1316 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed at AccessibilityElement.", GetErrorMessage(r));
1327 _ContextMenu::AddAccessibilityElement(const _AccessibilityElement& element)
1329 __accessibilityElements.Add(const_cast<_AccessibilityElement*>(&element));
1333 _ContextMenu::SetAllAccessibilityElement(void)
1335 RemoveAllAccessibilityElement();
1336 __pContextMenuPresenter->SetAllAccessibilityElement();
1340 _ContextMenu::OnAccessibilityFocusMovedNext(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1346 _ContextMenu::OnAccessibilityFocusMovedPrevious(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1352 _ContextMenu::OnAccessibilityReadElement(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1358 _ContextMenu::OnAccessibilityReadingElement(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1364 _ContextMenu::OnAccessibilityFocusIn(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1370 _ContextMenu::OnAccessibilityFocusOut(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1376 _ContextMenu::OnAccessibilityActionPerformed(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1378 SetVisibleState(false);
1384 _ContextMenu::OnAccessibilityValueIncreased(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1390 _ContextMenu::OnAccessibilityValueDecreased(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1396 _ContextMenu::RemoveAllAccessibilityElement(void)
1398 _AccessibilityContainer* pAccessibilityContainer = GetAccessibilityContainer();
1399 if (pAccessibilityContainer && pAccessibilityContainer->IsActivated())
1401 pAccessibilityContainer->RemoveAllElement();
1405 _ContextMenuItemInfo
1406 _ContextMenu::GetItemFromPosition(const FloatPoint& position) const
1408 return __pContextMenuPresenter->GetItemFromPosition(position);
1411 _ContextMenuItemInfo
1412 _ContextMenu::FindItem(int index) const
1414 return __pContextMenuPresenter->FindItem(index);
1418 _ContextMenu::SetTopDrawnItemIndex(int index)
1420 return __pContextMenuPresenter->SetTopDrawnItemIndex(index);
1424 _ContextMenu::GetLayout(void) const
1429 }}} // Tizen::Ui: Control