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;
40 namespace Tizen { namespace Ui { namespace Controls
43 IMPLEMENT_PROPERTY(_ContextMenu);
45 _ContextMenu::_ContextMenu(const Point& point, enum ContextMenuCoreStyle style, enum ContextMenuCoreAlign contextMenuAlign)
46 : __pContextMenuPresenter(null)
48 , __align(contextMenuAlign)
49 , __showItemCount(MAX_CONTEXTMENU_LIST_SHOW_ITEM)
50 , __showItemMaxCount(0)
51 , __isAttachedToMainTree(false)
52 , __ownerInputEnableState(false)
53 , __anchorPoint(point)
54 , __bodyRect(Rectangle(0, 0, 0, 0))
55 , __arrowRect(Rectangle(0, 0, 0, 0))
56 , __windowRect(Rectangle(0, 0, 0, 0))
57 , __pActionEvent(null)
58 , __pBackgroundNormalBitmap(null)
59 , __pBackgroundEffectBitmap(null)
60 , __dropPosition(CONTEXT_MENU_CORE_DROP_POSITION_INVALID)
61 , __layout(_CONTROL_ORIENTATION_PORTRAIT)
62 , __pScrollPanel(null)
64 __backgroundColor = Color(255, 255, 255, 255);
66 __textColor[CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL] = Color(255, 255, 255, 255);
67 __textColor[CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED] = Color(255, 255, 255, 255);
68 __textColor[CONTEXT_MENU_CORE_ITEM_STATUS_HIGHLIGHTED] = Color(255, 255, 255, 255);
70 __itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL] = Color(255, 255, 255, 255);
71 __itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED] = Color(255, 255, 255, 255);
72 __itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_HIGHLIGHTED] = Color(255, 255, 255, 255);
74 for (int i = 0; i < CONTEXT_MENU_CORE_DROP_POSITION_MAX; i++)
76 __pArrowNormalBitmap[i] = null;
77 __pArrowEffectBitmap[i] = null;
81 _ContextMenu::~_ContextMenu(void)
83 _Control* pOwner = GetOwner();
84 if (__isAttachedToMainTree == true && pOwner != null)
86 pOwner->SetInputEnableState(__ownerInputEnableState);
90 __pScrollPanel->DetachAllChildren();
91 DetachChild(*__pScrollPanel);
92 delete __pScrollPanel;
93 __pScrollPanel = null;
96 delete __pContextMenuPresenter;
97 __pContextMenuPresenter = null;
99 if (__pBackgroundNormalBitmap != null)
101 delete __pBackgroundNormalBitmap;
102 __pBackgroundNormalBitmap = null;
105 if (__pBackgroundEffectBitmap != null)
107 delete __pBackgroundEffectBitmap;
108 __pBackgroundEffectBitmap = null;
113 delete __pActionEvent;
114 __pActionEvent = null;
117 for (int i = 0; i < CONTEXT_MENU_CORE_DROP_POSITION_MAX; i++)
119 delete __pArrowNormalBitmap[i];
120 __pArrowNormalBitmap[i] = null;
122 delete __pArrowEffectBitmap[i];
123 __pArrowEffectBitmap[i] = null;
126 __actionId.RemoveAll();
128 RemoveAllAccessibilityElement();
133 _ContextMenu::IsActivatedOnOpen(void) const
139 _ContextMenu::CreateContextMenuN(const Point& 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 #if defined(MULTI_WINDOW)
147 r = pContextMenu->CreateRootVisualElement();
148 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
150 pContextMenu->SetActivationEnabled(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();
161 if (pContextMenu->GetAccessibilityContainer() != null)
163 pContextMenu->GetAccessibilityContainer()->Activate(true);
166 if (style == CONTEXT_MENU_CORE_STYLE_LIST)
168 int 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(Rectangle(0, 0, minWidth, minHeight), SCROLL_PANEL_SCROLL_DIRECTION_VERTICAL, false, false);
172 pContextMenu->AttachChild(*(pContextMenu->__pScrollPanel));
184 _ContextMenu::GetScrollPanel(void)
186 return __pScrollPanel;
190 _ContextMenu::Install(void)
192 result r = E_SUCCESS;
194 // load bitmap of a background and arrow
196 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to load bitmap.");
198 r = __actionId.Construct();
199 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to construct arraylist.");
201 if (__style == CONTEXT_MENU_CORE_STYLE_LIST)
203 _IContextMenuPresenter* pPresenter = new (std::nothrow) _ContextMenuListPresenter(this);
204 SysTryReturnResult(NID_UI_CTRL, pPresenter != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
206 SetPresenter(*pPresenter);
208 r = pPresenter->Install();
212 _IContextMenuPresenter* pPresenter = new (std::nothrow) _ContextMenuGridPresenter(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();
224 _ContextMenu::Initialize(void)
226 Dimension screen = _ControlManager::GetInstance()->GetScreenSize();
227 result r = E_SUCCESS;
229 Color backgroundColor;
230 Color backgroundSelectedColor;
232 Color itemTextSelectedColor;
234 r = SetBounds(Rectangle(0, 0, screen.width, screen.height));
235 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "SetBounds failed.");
237 SetMovable(false); // To do Modify
238 SetResizable(false); // To do Modify
240 GET_COLOR_CONFIG(CONTEXTMENU::BG_NORMAL, backgroundColor);
241 GET_COLOR_CONFIG(CONTEXTMENU::ITEM_BG_PRESSED, backgroundSelectedColor);
242 GET_COLOR_CONFIG(CONTEXTMENU::ITEM_TEXT_NORMAL, itemTextColor);
243 GET_COLOR_CONFIG(CONTEXTMENU::ITEM_TEXT_PRESSED, itemTextSelectedColor);
245 __backgroundColor = backgroundColor;
246 __itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL] = backgroundColor;
247 __itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED] = backgroundSelectedColor;
248 __textColor[CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL] = itemTextColor;
249 __textColor[CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED] = itemTextSelectedColor;
251 if (GetVisualElement() != null)
253 GetVisualElement()->SetSurfaceOpaque(false);
261 _ContextMenu::SetPresenter(const _IContextMenuPresenter& ContextMenuPresenter)
263 __pContextMenuPresenter = const_cast <_IContextMenuPresenter*>(&ContextMenuPresenter);
269 _ContextMenu::OnDraw()
271 __pContextMenuPresenter->Draw();
275 _ContextMenu::OnAttachedToMainTree(void)
277 result r = E_SUCCESS;
279 if (GetOwner() == null)
281 _Frame* pFrame = dynamic_cast<_Frame*>(_ControlManager::GetInstance()->GetCurrentFrame());
282 SysTryReturn(NID_UI_CTRL, pFrame != null, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Current frame instance is not available.");
284 _Form* pForm = pFrame->GetCurrentForm();
295 _Control* pOwner = GetOwner();
296 if (pOwner != null && __isAttachedToMainTree == false)
298 __ownerInputEnableState = pOwner->GetInputEnableState();
299 pOwner->SetInputEnableState(false);
302 __layout = _ControlManager::GetInstance()->GetOrientation();
303 AdjustDropPosition();
304 GET_SHAPE_CONFIG(CONTEXTMENU::ITEM_MAX_COUNT, __layout, __showItemMaxCount);
306 if (GetItemCount() <= 0)
308 __pContextMenuPresenter->CalculateShowItemCount();
311 __pContextMenuPresenter->CalculateWindowRect();
315 SetVisibleState(true);
317 if (__style == CONTEXT_MENU_CORE_STYLE_LIST)
323 SetTouchCapture(true);
326 SetAllAccessibilityElement();
328 __isAttachedToMainTree = true;
334 _ContextMenu::OnDetachingFromMainTree(void)
336 result r = E_SUCCESS;
338 ReleaseTouchCapture();
340 _Control* pOwner = GetOwner();
343 pOwner->SetInputEnableState(__ownerInputEnableState);
346 __isAttachedToMainTree = false;
352 _ContextMenu::AddItem(const Base::String& text, int actionId, const Bitmap* pNormalBitmap, const Bitmap* pPressedBitmap,
353 const Bitmap* pHighlightedBitmap)
355 result r = E_SUCCESS;
357 r = __pContextMenuPresenter->AddItem(text, actionId, pNormalBitmap, pPressedBitmap, pHighlightedBitmap);
358 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to add a item.");
360 __actionId.Add(actionId);
362 __pContextMenuPresenter->CalculateShowItemCount();
363 __pContextMenuPresenter->CalculateWindowRect();
369 _ContextMenu::InsertItem(int index, const Base::String& text, int actionId, const Bitmap* pNormalBitmap,
370 const Bitmap* pPressedBitmap,
371 const Bitmap* pHighlightedBitmap)
373 result r = E_SUCCESS;
375 r = __pContextMenuPresenter->InsertItem(index, text, actionId, pNormalBitmap, pPressedBitmap, pHighlightedBitmap);
376 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to insert a item.");
378 __actionId.InsertAt(actionId, index);
380 __pContextMenuPresenter->CalculateShowItemCount();
381 __pContextMenuPresenter->CalculateWindowRect();
387 _ContextMenu::SetItem(int index, const Base::String& text, int actionId, const Bitmap* pNormalBitmap,
388 const Bitmap* pPressedBitmap, const Bitmap* pHighlightedBitmap)
390 result r = E_SUCCESS;
392 r = __pContextMenuPresenter->SetItem(index, text, actionId, pNormalBitmap, pPressedBitmap, pHighlightedBitmap);
393 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to set a item.");
395 __actionId.SetAt(actionId, index);
397 __pContextMenuPresenter->CalculateWindowRect();
403 _ContextMenu::RemoveItemAt(int index)
405 result r = E_SUCCESS;
407 r = __pContextMenuPresenter->DeleteItem(index);
408 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to remove a item.");
410 __actionId.RemoveAt(index);
412 __pContextMenuPresenter->CalculateShowItemCount();
413 __pContextMenuPresenter->CalculateWindowRect();
419 _ContextMenu::RemoveAllItems(void)
421 result r = E_SUCCESS;
423 r = __pContextMenuPresenter->DeleteItemAll();
424 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to remove all items.");
426 __actionId.RemoveAll();
428 __pContextMenuPresenter->CalculateShowItemCount();
429 __pContextMenuPresenter->CalculateWindowRect();
435 _ContextMenu::GetItemCount(void) const
437 return __actionId.GetCount();
441 _ContextMenu::GetItemIndexAt(int actionId) const
443 int count = __actionId.GetCount();
445 for (int i = 0; i < count; i++)
447 int index = GetItemActionIdAt(i);
449 if (actionId == index)
459 _ContextMenu::GetItemActionIdAt(int index) const
461 int count = __actionId.GetCount();
464 if (count <= 0 || index >= count)
469 __actionId.GetAt(index, actionId);
475 _ContextMenu::SetAnchorPosition(int x, int y)
480 if (__align == CONTEXT_MENU_CORE_ALIGN_AUTO)
482 AdjustDropPosition();
485 __pContextMenuPresenter->CalculateWindowRect();
490 _ContextMenu::GetAnchorPosition(void) const
492 return __anchorPoint;
496 _ContextMenu::SetBodyRect(const Rectangle& rect)
504 _ContextMenu::GetBodyRect(void) const
510 _ContextMenu::SetArrowRect(const Rectangle& rect)
518 _ContextMenu::GetArrowRect(void) const
524 _ContextMenu::SetWindowRect(const Rectangle& rect)
532 _ContextMenu::GetWindowRect(void) const
538 _ContextMenu::SetPropertyMaxVisibleItemsCount(const Variant& count)
540 int showCount = count.ToInt();
544 SysLogException(NID_UI_CTRL, E_INVALID_ARG, "Count is invalid.");
545 return E_INVALID_ARG;
549 __showItemCount = showCount;
555 _ContextMenu::GetPropertyMaxVisibleItemsCount(void) const
557 return Tizen::Ui::Variant(__showItemCount);
561 _ContextMenu::GetShowItemCount(void) const
563 Variant count = GetProperty("maxVisibleItemsCount");
565 return count.ToInt();
569 _ContextMenu::GetShowItemMaxCount(void) const
571 return __showItemMaxCount;
575 _ContextMenu::SetShowItemCount(int count)
579 r = SetProperty("maxVisibleItemsCount", Variant(count));
580 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to set property.");
582 if (__style == CONTEXT_MENU_CORE_STYLE_LIST)
584 r = __pContextMenuPresenter->CalculateWindowRect();
585 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to calculate window.");
592 _ContextMenu::SetPropertyColor(const Variant& color)
594 __backgroundColor = color.ToColor();
596 LoadColorReplacedBitmap(__backgroundColor);
602 _ContextMenu::GetPropertyColor(void) const
604 return Tizen::Ui::Variant(__backgroundColor);
608 _ContextMenu::SetColor(const Graphics::Color& color)
610 return SetProperty("color", Variant(color));
614 _ContextMenu::GetColor(void) const
616 Variant color = GetProperty("color");
618 return color.ToColor();
622 _ContextMenu::SetPropertyNormalItemColor(const Variant& color)
624 __itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL] = color.ToColor();
626 return __pContextMenuPresenter->ApplyColorProperty();
630 _ContextMenu::GetPropertyNormalItemColor(void) const
632 return Tizen::Ui::Variant(__itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL]);
636 _ContextMenu::SetPropertyPressedItemColor(const Variant& color)
638 __itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED] = color.ToColor();
640 return __pContextMenuPresenter->ApplyColorProperty();
644 _ContextMenu::GetPropertyPressedItemColor(void) const
646 return Tizen::Ui::Variant(__itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED]);
650 _ContextMenu::SetPropertyHighlightedItemColor(const Variant & color)
652 __itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_HIGHLIGHTED] = color.ToColor();
654 return __pContextMenuPresenter->ApplyColorProperty();
658 _ContextMenu::GetPropertyHighlightedItemColor(void) const
660 return Tizen::Ui::Variant(__itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_HIGHLIGHTED]);
664 _ContextMenu::SetItemColor(enum ContextMenuCoreItemStatus status, const Graphics::Color& color)
666 result r = E_SUCCESS;
668 if (status == CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL)
670 r = SetProperty("normalItemColor", Variant(color));
672 else if (status == CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED)
674 r = SetProperty("pressedItemColor", Variant(color));
678 r = SetProperty("highlightedItemColor", Variant(color));
685 _ContextMenu::GetItemColor(enum ContextMenuCoreItemStatus status) const
689 if (status == CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL)
691 Variant color = GetProperty("normalItemColor");
692 itemColor = color.ToColor();
695 else if (status == CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED)
697 Variant color = GetProperty("pressedItemColor");
698 itemColor = color.ToColor();
703 Variant color = GetProperty("highlightedItemColor");
704 itemColor = color.ToColor();
712 _ContextMenu::SetPropertyNormalItemTextColor(const Variant& color)
714 __textColor[CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL] = color.ToColor();
716 return __pContextMenuPresenter->ApplyColorProperty();
720 _ContextMenu::GetPropertyNormalItemTextColor(void) const
722 return Tizen::Ui::Variant(__textColor[CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL]);
726 _ContextMenu::SetPropertyPressedItemTextColor(const Variant& color)
728 __textColor[CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED] = color.ToColor();
730 return __pContextMenuPresenter->ApplyColorProperty();
734 _ContextMenu::GetPropertyPressedItemTextColor(void) const
736 return Tizen::Ui::Variant(__textColor[CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED]);
740 _ContextMenu::SetPropertyHighlightedItemTextColor(const Variant & color)
742 __textColor[CONTEXT_MENU_CORE_ITEM_STATUS_HIGHLIGHTED] = color.ToColor();
744 return __pContextMenuPresenter->ApplyColorProperty();
748 _ContextMenu::GetPropertyHighlightedItemTextColor(void) const
750 return Tizen::Ui::Variant(__textColor[CONTEXT_MENU_CORE_ITEM_STATUS_HIGHLIGHTED]);
754 _ContextMenu::SetTextColor(enum ContextMenuCoreItemStatus status, const Graphics::Color& color)
756 result r = E_SUCCESS;
758 if (status == CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL)
760 r = SetProperty("normalItemTextColor", Variant(color));
762 else if (status == CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED)
764 r = SetProperty("pressedItemTextColor", Variant(color));
768 r = SetProperty("highlightedItemTextColor", Variant(color));
776 _ContextMenu::GetTextColor(enum ContextMenuCoreItemStatus status) const
780 if (status == CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL)
782 Variant color = GetProperty("normalItemTextColor");
783 textColor = color.ToColor();
786 else if (status == CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED)
788 Variant color = GetProperty("pressedItemTextColor");
789 textColor = color.ToColor();
794 Variant color = GetProperty("highlightedItemTextColor");
795 textColor = color.ToColor();
802 _ContextMenu::AddActionEventListener(const Tizen::Ui::Controls::_IActionEventListener& listener)
804 result r = E_SUCCESS;
806 if (__pActionEvent == null)
808 __pActionEvent = _ActionEvent::CreateInstanceN(*this);
809 SysTryReturn(NID_UI_CTRL, __pActionEvent != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
810 "[E_OUT_OF_MEMORY] The memory is insufficient.")
812 r = __pActionEvent->AddListener(listener);
813 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to remove an action event listener.")
819 delete __pActionEvent;
820 __pActionEvent = null;
825 _ContextMenu::RemoveActionEventListener(const Tizen::Ui::Controls::_IActionEventListener& listener)
827 SysTryReturn(NID_UI_CTRL, __pActionEvent != null, E_INVALID_STATE, E_INVALID_STATE,
828 "[E_INVALID_STATE] The action event instance isn't constructed.")
830 result r = E_SUCCESS;
832 r = __pActionEvent->RemoveListener(listener);
833 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to remove an action event listener")
838 Tizen::Ui::Controls::_ActionEvent*
839 _ContextMenu::GetActionEvent(void) const
841 return __pActionEvent;
845 _ContextMenu::LoadBitmap(void)
847 Color backgroundColor;
850 if (__pBackgroundEffectBitmap != null)
852 delete __pBackgroundEffectBitmap;
853 __pBackgroundEffectBitmap = null;
856 for (int i = 0; i < CONTEXT_MENU_CORE_DROP_POSITION_MAX; i++)
858 if (__pArrowEffectBitmap[i] != null)
860 delete __pArrowEffectBitmap[i];
861 __pArrowEffectBitmap[i] = null;
865 backgroundColor = GetColor();
869 r = GET_BITMAP_CONFIG_N(CONTEXTMENU::ANCHOR_EFFECT_UP, BITMAP_PIXEL_FORMAT_ARGB8888,
870 __pArrowEffectBitmap[CONTEXT_MENU_CORE_DROP_POSITION_UP]);
871 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
873 r = GET_BITMAP_CONFIG_N(CONTEXTMENU::ANCHOR_EFFECT_DOWN, BITMAP_PIXEL_FORMAT_ARGB8888,
874 __pArrowEffectBitmap[CONTEXT_MENU_CORE_DROP_POSITION_DOWN]);
875 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
877 r = GET_BITMAP_CONFIG_N(CONTEXTMENU::ANCHOR_EFFECT_LEFT, BITMAP_PIXEL_FORMAT_ARGB8888,
878 __pArrowEffectBitmap[CONTEXT_MENU_CORE_DROP_POSITION_LEFT]);
879 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
881 r = GET_BITMAP_CONFIG_N(CONTEXTMENU::ANCHOR_EFFECT_RIGHT, BITMAP_PIXEL_FORMAT_ARGB8888,
882 __pArrowEffectBitmap[CONTEXT_MENU_CORE_DROP_POSITION_RIGHT]);
883 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
885 r = GET_BITMAP_CONFIG_N(CONTEXTMENU::BG_OUTLINE_EFFECT_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pBackgroundEffectBitmap);
886 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
888 r = LoadColorReplacedBitmap(backgroundColor);
889 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
894 delete __pBackgroundEffectBitmap;
895 __pBackgroundEffectBitmap = null;
897 for (int i = 0; i < CONTEXT_MENU_CORE_DROP_POSITION_MAX; i++)
900 delete __pArrowEffectBitmap[i];
901 __pArrowEffectBitmap[i] = null;
908 _ContextMenu::LoadColorReplacedBitmap(const Tizen::Graphics::Color& color)
910 Bitmap* ptempNormalBitmap = null;
913 if (__pBackgroundNormalBitmap != null)
915 delete __pBackgroundNormalBitmap;
916 __pBackgroundNormalBitmap = null;
919 for (int i = 0; i < CONTEXT_MENU_CORE_DROP_POSITION_MAX; i++)
921 if (__pArrowNormalBitmap[i] != null)
923 delete __pArrowNormalBitmap[i];
924 __pArrowNormalBitmap[i] = null;
929 r = GET_BITMAP_CONFIG_N(CONTEXTMENU::ANCHOR_NORMAL_UP, BITMAP_PIXEL_FORMAT_ARGB8888, ptempNormalBitmap);
930 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
931 __pArrowNormalBitmap[CONTEXT_MENU_CORE_DROP_POSITION_UP] = _BitmapImpl::GetColorReplacedBitmapN(*ptempNormalBitmap,
932 Color::GetColor(COLOR_ID_MAGENTA), color);
933 SysTryCatch(NID_UI_CTRL, __pArrowNormalBitmap[CONTEXT_MENU_CORE_DROP_POSITION_UP] != null, , GetLastResult(),
934 "[%s] Propagating.", GetErrorMessage(GetLastResult()));
935 delete ptempNormalBitmap;
936 ptempNormalBitmap = null;
938 r = GET_BITMAP_CONFIG_N(CONTEXTMENU::ANCHOR_NORMAL_DOWN, BITMAP_PIXEL_FORMAT_ARGB8888, ptempNormalBitmap);
939 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
940 __pArrowNormalBitmap[CONTEXT_MENU_CORE_DROP_POSITION_DOWN] = _BitmapImpl::GetColorReplacedBitmapN(*ptempNormalBitmap,
941 Color::GetColor(COLOR_ID_MAGENTA), color);
942 SysTryCatch(NID_UI_CTRL, __pArrowNormalBitmap[CONTEXT_MENU_CORE_DROP_POSITION_DOWN] != null, , GetLastResult(),
943 "[%s] Propagating.", GetErrorMessage(GetLastResult()));
944 delete ptempNormalBitmap;
945 ptempNormalBitmap = null;
947 r = GET_BITMAP_CONFIG_N(CONTEXTMENU::ANCHOR_NORMAL_LEFT, BITMAP_PIXEL_FORMAT_ARGB8888, ptempNormalBitmap);
948 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
949 __pArrowNormalBitmap[CONTEXT_MENU_CORE_DROP_POSITION_LEFT] = _BitmapImpl::GetColorReplacedBitmapN(*ptempNormalBitmap,
950 Color::GetColor(COLOR_ID_MAGENTA), color);
951 SysTryCatch(NID_UI_CTRL, __pArrowNormalBitmap[CONTEXT_MENU_CORE_DROP_POSITION_LEFT] != null, , GetLastResult(),
952 "[%s] Propagating.", GetErrorMessage(GetLastResult()));
953 delete ptempNormalBitmap;
954 ptempNormalBitmap = null;
956 r = GET_BITMAP_CONFIG_N(CONTEXTMENU::ANCHOR_NORMAL_RIGHT, BITMAP_PIXEL_FORMAT_ARGB8888, ptempNormalBitmap);
957 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
958 __pArrowNormalBitmap[CONTEXT_MENU_CORE_DROP_POSITION_RIGHT] = _BitmapImpl::GetColorReplacedBitmapN(*ptempNormalBitmap,
959 Color::GetColor(COLOR_ID_MAGENTA), color);
960 SysTryCatch(NID_UI_CTRL, __pArrowNormalBitmap[CONTEXT_MENU_CORE_DROP_POSITION_RIGHT] != null, , GetLastResult(),
961 "[%s] Propagating.", GetErrorMessage(GetLastResult()));
962 delete ptempNormalBitmap;
963 ptempNormalBitmap = null;
965 r = GET_BITMAP_CONFIG_N(CONTEXTMENU::BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, ptempNormalBitmap);
966 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
967 __pBackgroundNormalBitmap = _BitmapImpl::GetColorReplacedBitmapN(*ptempNormalBitmap, Color::GetColor(COLOR_ID_MAGENTA), color);
968 SysTryCatch(NID_UI_CTRL, __pBackgroundNormalBitmap != null, , GetLastResult(), "[%s] Propagating.",
969 GetErrorMessage(GetLastResult()));
970 delete ptempNormalBitmap;
975 delete ptempNormalBitmap;
977 delete __pBackgroundNormalBitmap;
978 __pBackgroundNormalBitmap = null;
980 for (int i = 0; i < CONTEXT_MENU_CORE_DROP_POSITION_MAX; i++)
982 delete __pArrowNormalBitmap[i];
983 __pArrowNormalBitmap[i] = null;
990 _ContextMenu::GetArrowNormalBitmap(ContextMenuCoreDropPosition dropPosition) const
992 if (dropPosition == CONTEXT_MENU_CORE_DROP_POSITION_INVALID || dropPosition == CONTEXT_MENU_CORE_DROP_POSITION_MAX)
997 return __pArrowNormalBitmap[dropPosition];
1001 _ContextMenu::GetArrowEffectBitmap(ContextMenuCoreDropPosition dropPosition) const
1003 if (dropPosition == CONTEXT_MENU_CORE_DROP_POSITION_INVALID || dropPosition == CONTEXT_MENU_CORE_DROP_POSITION_MAX)
1008 return __pArrowEffectBitmap[dropPosition];
1012 _ContextMenu::GetBackgroundNormalBitmap(void) const
1014 return __pBackgroundNormalBitmap;
1018 _ContextMenu::GetBackgroundEffectBitmap(void) const
1020 return __pBackgroundEffectBitmap;
1023 enum ContextMenuCoreDropPosition
1024 _ContextMenu::GetDropPosition(void) const
1026 return __dropPosition;
1030 _ContextMenu::AdjustDropPosition(void)
1032 Dimension screen = _ControlManager::GetInstance()->GetScreenSize();
1034 if (__align == CONTEXT_MENU_CORE_ALIGN_UP)
1036 __dropPosition = CONTEXT_MENU_CORE_DROP_POSITION_UP;
1038 else if (__align == CONTEXT_MENU_CORE_ALIGN_DOWN)
1040 __dropPosition = CONTEXT_MENU_CORE_DROP_POSITION_DOWN;
1042 else if (__align == CONTEXT_MENU_CORE_ALIGN_LEFT)
1044 __dropPosition = CONTEXT_MENU_CORE_DROP_POSITION_LEFT;
1046 else if (__align == CONTEXT_MENU_CORE_ALIGN_RIGHT)
1048 __dropPosition = CONTEXT_MENU_CORE_DROP_POSITION_RIGHT;
1052 if (__layout == _CONTROL_ORIENTATION_LANDSCAPE)
1054 screen.SetSize(screen.height, screen.width);
1057 if (screen.height > screen.width)
1059 if ((screen.height / 2) > __anchorPoint.y)
1061 __dropPosition = CONTEXT_MENU_CORE_DROP_POSITION_DOWN;
1065 __dropPosition = CONTEXT_MENU_CORE_DROP_POSITION_UP;
1070 if ((screen.width / 2) > __anchorPoint.x)
1072 __dropPosition = CONTEXT_MENU_CORE_DROP_POSITION_RIGHT;
1076 __dropPosition = CONTEXT_MENU_CORE_DROP_POSITION_LEFT;
1082 _UiTouchEventDelivery
1083 _ContextMenu::OnPreviewTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
1085 return __pContextMenuPresenter->OnPreviewTouchPressed(source, touchinfo);
1089 _ContextMenu::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
1091 return __pContextMenuPresenter->OnTouchPressed(source, touchinfo);
1094 _UiTouchEventDelivery
1095 _ContextMenu::OnPreviewTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
1097 return __pContextMenuPresenter->OnPreviewTouchMoved(source, touchinfo);
1101 _ContextMenu::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
1103 return __pContextMenuPresenter->OnTouchMoved(source, touchinfo);
1106 _UiTouchEventDelivery
1107 _ContextMenu::OnPreviewTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
1109 return __pContextMenuPresenter->OnPreviewTouchReleased(source, touchinfo);
1113 _ContextMenu::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
1115 return __pContextMenuPresenter->OnTouchReleased(source, touchinfo);
1119 _ContextMenu::OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
1121 __pContextMenuPresenter->OnTouchCanceled(source, touchinfo);
1123 SetVisibleState(false);
1129 _ContextMenu::OnFontChanged(Tizen::Graphics::Font* pFont)
1131 return __pContextMenuPresenter->OnFontChanged(pFont);
1135 _ContextMenu::OnFontInfoRequested(unsigned long& style, int& size)
1137 return __pContextMenuPresenter->OnFontInfoRequested(style, size);
1141 _ContextMenu::OnVisibleStateChanged(void)
1143 #if defined(MULTI_WINDOW)
1144 _Window::OnVisibleStateChanged();
1149 _ContextMenu::OnChangeLayout(_ControlOrientation orientation)
1151 GET_SHAPE_CONFIG(CONTEXTMENU::ITEM_MAX_COUNT, orientation, __showItemMaxCount);
1153 if (__isAttachedToMainTree == true)
1155 if (__layout != orientation)
1157 SetVisibleState(false);
1161 __layout = orientation;
1164 _AccessibilityElement*
1165 _ContextMenu::GetAccessibilityElement(const int mainIndex) const
1167 _AccessibilityElement* pElement = null;
1168 result r = __accessibilityElements.GetAt(mainIndex, pElement);
1169 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed at AccessibilityElement.", GetErrorMessage(r));
1180 _ContextMenu::AddAccessibilityElement(const _AccessibilityElement& element)
1182 __accessibilityElements.Add(const_cast<_AccessibilityElement*>(&element));
1186 _ContextMenu::SetAllAccessibilityElement(void)
1188 RemoveAllAccessibilityElement();
1189 __pContextMenuPresenter->SetAllAccessibilityElement();
1193 _ContextMenu::RemoveAllAccessibilityElement(void)
1195 while (__accessibilityElements.GetCount() > 0)
1197 _AccessibilityElement* pElement = null;
1198 if (__accessibilityElements.GetAt(0, pElement) == E_SUCCESS)
1200 __accessibilityElements.RemoveAt(0);
1201 pElement->GetParent()->RemoveElement(*pElement);
1206 _ContextMenuItemInfo
1207 _ContextMenu::GetItemFromPosition(const Point& position) const
1209 return __pContextMenuPresenter->GetItemFromPosition(position);
1212 _ContextMenuItemInfo
1213 _ContextMenu::FindItem(int index) const
1215 return __pContextMenuPresenter->FindItem(index);
1219 _ContextMenu::SetTopDrawnItemIndex(int index)
1221 return __pContextMenuPresenter->SetTopDrawnItemIndex(index);
1225 _ContextMenu::GetLayout(void) const
1230 }}} // Tizen::Ui: Control