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_ContextMenuImpl.cpp
19 * @brief This is the implementation file for the _ContextMenuImpl class.
22 #include <FBaseSysLog.h>
23 #include <FApp_AppInfo.h>
24 #include "FUi_ControlImplManager.h"
25 #include "FUiCtrl_ContextMenuImpl.h"
26 #include "FUiCtrl_FrameImpl.h"
27 #include "FUiCtrl_Form.h"
29 using namespace Tizen::App;
30 using namespace Tizen::Base;
31 using namespace Tizen::Graphics;
33 namespace Tizen { namespace Ui { namespace Controls
37 _ContextMenuImpl::GetInstance(ContextMenu& contextMenu)
39 return static_cast<_ContextMenuImpl*> (contextMenu._pControlImpl);
42 const _ContextMenuImpl*
43 _ContextMenuImpl::GetInstance(const ContextMenu& contextMenu)
45 return static_cast<const _ContextMenuImpl*> (contextMenu._pControlImpl);
48 _ContextMenuImpl::_ContextMenuImpl(ContextMenu* pPublic, _ContextMenu* pCore, ContextMenuStyle style)
49 : _WindowImpl(pPublic, pCore)
51 , __pContextMenu(pCore)
52 , __pPublicActionEvent(null)
57 _ContextMenuImpl::CreateContextMenuImplN(ContextMenu* pPublic, const Point& point, ContextMenuStyle style,
58 ContextMenuAnchorDirection direction)
64 enum ContextMenuCoreStyle coreStyle = CONTEXT_MENU_CORE_STYLE_LIST;
67 case CONTEXT_MENU_STYLE_LIST:
68 coreStyle = CONTEXT_MENU_CORE_STYLE_LIST;
71 case CONTEXT_MENU_STYLE_GRID:
72 coreStyle = CONTEXT_MENU_CORE_STYLE_GRID;
75 case CONTEXT_MENU_STYLE_ICON:
76 coreStyle = CONTEXT_MENU_CORE_STYLE_GRID;
80 SysLogException(NID_UI_CTRL, E_SYSTEM, "Unable to convert ContextMenu style.");
84 enum ContextMenuCoreAlign contextMenuAlign = CONTEXT_MENU_CORE_ALIGN_AUTO;
87 case CONTEXT_MENU_ANCHOR_DIRECTION_LEFTWARD:
88 contextMenuAlign = CONTEXT_MENU_CORE_ALIGN_LEFT;
91 case CONTEXT_MENU_ANCHOR_DIRECTION_RIGHTWARD:
92 contextMenuAlign = CONTEXT_MENU_CORE_ALIGN_RIGHT;
95 case CONTEXT_MENU_ANCHOR_DIRECTION_UPWARD:
96 contextMenuAlign = CONTEXT_MENU_CORE_ALIGN_UP;
99 case CONTEXT_MENU_ANCHOR_DIRECTION_DOWNWARD:
100 contextMenuAlign = CONTEXT_MENU_CORE_ALIGN_DOWN;
104 contextMenuAlign = CONTEXT_MENU_CORE_ALIGN_AUTO;
108 _ContextMenu* pCore = _ContextMenu::CreateContextMenuN(point, coreStyle, contextMenuAlign);
109 SysTryReturn(NID_UI_CTRL, pCore != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
111 _ContextMenuImpl* pImpl = new (std::nothrow) _ContextMenuImpl(pPublic, pCore, style);
112 r = CheckConstruction(pCore, pImpl);
113 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
118 _ContextMenuImpl::~_ContextMenuImpl(void)
124 _ContextMenuImpl::_Dispose(void)
126 result r = E_SUCCESS;
128 if (__pPublicActionEvent)
130 delete __pPublicActionEvent;
131 __pPublicActionEvent = null;
133 __pContextMenu = null;
139 _ContextMenuImpl::AddItem(const Base::String& text, int actionId, const Tizen::Graphics::Bitmap* pNormalBitmap,
140 const Tizen::Graphics::Bitmap* pPressedBitmap, const Tizen::Graphics::Bitmap* pHighlightedBitmap)
144 SysAssertf(__pContextMenu != null, "Not yet constructed. Construct() should be called before use.");
146 return __pContextMenu->AddItem(text, actionId, pNormalBitmap, pPressedBitmap, pHighlightedBitmap);
150 _ContextMenuImpl::InsertItem(int index, const Tizen::Base::String& text, int actionId, const Tizen::Graphics::Bitmap* pNormalBitmap,
151 const Tizen::Graphics::Bitmap* pPressedBitmap, const Tizen::Graphics::Bitmap* pHighlightedBitmap)
155 SysAssertf(__pContextMenu != null, "Not yet constructed. Construct() should be called before use.");
157 return __pContextMenu->InsertItem(index, text, actionId, pNormalBitmap, pPressedBitmap, pHighlightedBitmap);
161 _ContextMenuImpl::SetItem(int index, const Tizen::Base::String& text, int actionId, const Tizen::Graphics::Bitmap* pNormalBitmap,
162 const Tizen::Graphics::Bitmap* pPressedBitmap, const Tizen::Graphics::Bitmap* pHighlightedBitmap)
166 SysAssertf(__pContextMenu != null, "Not yet constructed. Construct() should be called before use.");
168 return __pContextMenu->SetItem(index, text, actionId, pNormalBitmap, pPressedBitmap, pHighlightedBitmap);
172 _ContextMenuImpl::RemoveItemAt(int index)
176 SysAssertf(__pContextMenu != null, "Not yet constructed. Construct() should be called before use.");
178 if (index >= GetItemCount() || index < 0)
180 SysLogException(NID_UI_CTRL, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The specified index is not valid(index = %d).", index);
182 return (_AppInfo::GetApiVersion() <= _API_VERSION_2_0 && _AppInfo::IsOspCompat())?E_SYSTEM:E_OUT_OF_RANGE;
185 return __pContextMenu->RemoveItemAt(index);
189 _ContextMenuImpl::RemoveAllItems(void)
193 SysAssertf(__pContextMenu != null, "Not yet constructed. Construct() should be called before use.");
195 return __pContextMenu->RemoveAllItems();
199 _ContextMenuImpl::OnAttachedToMainTree(void)
201 result r = E_SUCCESS;
204 if (GetOwner() == null)
206 _FrameImpl* pFrameImpl = dynamic_cast <_FrameImpl*>(_ControlImplManager::GetInstance()->GetCurrentFrame());
207 SysTryReturn(NID_UI_CTRL, pFrameImpl != null, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] This instance is not constructed.");
208 _Form* pForm = pFrameImpl->GetCore().GetCurrentForm();
209 _ContextMenu& control = GetCore();
213 control.SetOwner(pForm);
217 control.SetOwner(&pFrameImpl->GetCore());
221 r = _WindowImpl::OnAttachedToMainTree();
226 _ContextMenuImpl::SetAnchorPosition(int x, int y)
230 SysAssertf(__pContextMenu != null, "Not yet constructed. Construct() should be called before use.");
232 return __pContextMenu->SetAnchorPosition(x, y);
235 Tizen::Graphics::Point
236 _ContextMenuImpl::GetAnchorPosition(void) const
240 SysAssertf(__pContextMenu != null, "Not yet constructed. Construct() should be called before use.");
242 Tizen::Graphics::Point point;
244 point = __pContextMenu->GetAnchorPosition();
250 _ContextMenuImpl::GetItemCount(void) const
254 SysAssertf(__pContextMenu != null, "Not yet constructed. Construct() should be called before use.");
256 return __pContextMenu->GetItemCount();
260 _ContextMenuImpl::SetMaxVisibleItemsCount(int maxItemsCount)
264 SysAssertf(__pContextMenu != null, "Not yet constructed. Construct() should be called before use.");
266 return __pContextMenu->SetShowItemCount(maxItemsCount);
270 _ContextMenuImpl::GetMaxVisibleItemsCount(void) const
274 SysAssertf(__pContextMenu != null, "Not yet constructed. Construct() should be called before use.");
276 return __pContextMenu->GetShowItemCount();
280 _ContextMenuImpl::GetItemIndexFromActionId(int actionId) const
284 SysAssertf(__pContextMenu != null, "Not yet constructed. Construct() should be called before use.");
286 return __pContextMenu->GetItemIndexAt(actionId);
290 _ContextMenuImpl::GetItemActionIdAt(int index) const
294 SysAssertf(__pContextMenu != null, "Not yet constructed. Construct() should be called before use.");
296 return __pContextMenu->GetItemActionIdAt(index);
300 _ContextMenuImpl::SetColor(const Graphics::Color& color)
304 SysAssertf(__pContextMenu != null, "Not yet constructed. Construct() should be called before use.");
306 result r = E_SUCCESS;
308 r = __pContextMenu->SetColor(color);
309 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to set color.");
314 Tizen::Graphics::Color
315 _ContextMenuImpl::GetColor(void) const
319 SysAssertf(__pContextMenu != null, "Not yet constructed. Construct() should be called before use.");
321 return __pContextMenu->GetColor();
326 _ContextMenuImpl::SetItemTextColor(ContextMenuItemStatus status, const Tizen::Graphics::Color& color)
330 SysAssertf(__pContextMenu != null, "Not yet constructed. Construct() should be called before use.");
332 result r = E_SUCCESS;
336 case CONTEXT_MENU_ITEM_STATUS_NORMAL:
337 r = __pContextMenu->SetTextColor(CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL, color);
340 case CONTEXT_MENU_ITEM_STATUS_PRESSED:
341 r = __pContextMenu->SetTextColor(CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED, color);
344 case CONTEXT_MENU_ITEM_STATUS_HIGHLIGHTED:
345 r = __pContextMenu->SetTextColor(CONTEXT_MENU_CORE_ITEM_STATUS_HIGHLIGHTED, color);
349 SysLogException(NID_UI_CTRL, E_INVALID_ARG, "Invalid argument at ContextMenuItemStatus.");
358 Tizen::Graphics::Color
359 _ContextMenuImpl::GetItemTextColor(ContextMenuItemStatus status) const
363 SysAssertf(__pContextMenu != null, "Not yet constructed. Construct() should be called before use.");
365 Tizen::Graphics::Color color(0, 0, 0, 0);
369 case CONTEXT_MENU_ITEM_STATUS_NORMAL:
370 color = __pContextMenu->GetTextColor(CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL);
373 case CONTEXT_MENU_ITEM_STATUS_PRESSED:
374 color = __pContextMenu->GetTextColor(CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED);
377 case CONTEXT_MENU_ITEM_STATUS_HIGHLIGHTED:
378 color = __pContextMenu->GetTextColor(CONTEXT_MENU_CORE_ITEM_STATUS_HIGHLIGHTED);
382 SysLogException(NID_UI_CTRL, E_SYSTEM, "Invalid argument at ContextMenuItemStatus.");
390 _ContextMenuImpl::SetItemColor(ContextMenuItemStatus status, const Tizen::Graphics::Color& color)
394 SysAssertf(__pContextMenu != null, "Not yet constructed. Construct() should be called before use.");
396 result r = E_SUCCESS;
400 case CONTEXT_MENU_ITEM_STATUS_NORMAL:
401 r = __pContextMenu->SetItemColor(CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL, color);
404 case CONTEXT_MENU_ITEM_STATUS_PRESSED:
405 r = __pContextMenu->SetItemColor(CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED, color);
408 case CONTEXT_MENU_ITEM_STATUS_HIGHLIGHTED:
409 r = __pContextMenu->SetItemColor(CONTEXT_MENU_CORE_ITEM_STATUS_HIGHLIGHTED, color);
413 SysLogException(NID_UI_CTRL, E_INVALID_ARG, "Invalid argument at ContextMenuItemStatus.");
422 Tizen::Graphics::Color
423 _ContextMenuImpl::GetItemColor(ContextMenuItemStatus status) const
427 SysAssertf(__pContextMenu != null, "Not yet constructed. Construct() should be called before use.");
429 Tizen::Graphics::Color color(0, 0, 0, 0);
433 case CONTEXT_MENU_ITEM_STATUS_NORMAL:
434 color = __pContextMenu->GetItemColor(CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL);
437 case CONTEXT_MENU_ITEM_STATUS_PRESSED:
438 color = __pContextMenu->GetItemColor(CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED);
441 case CONTEXT_MENU_ITEM_STATUS_HIGHLIGHTED:
442 color = __pContextMenu->GetItemColor(CONTEXT_MENU_CORE_ITEM_STATUS_HIGHLIGHTED);
446 SysLogException(NID_UI_CTRL, E_SYSTEM, "Invalid argument at ContextMenuItemStatus.");
450 SetLastResult(E_SUCCESS);
456 _ContextMenuImpl::GetPublicStyle(void) const
462 _ContextMenuImpl::AddActionEventListener(Tizen::Ui::IActionEventListener& listener)
466 SysAssertf(__pContextMenu != null, "Not yet constructed. Construct() should be called before use.");
468 result r = E_SUCCESS;
470 if (__pPublicActionEvent == null)
472 __pPublicActionEvent = _PublicActionEvent::CreateInstanceN(GetPublic());
473 SysTryReturn(NID_UI_CTRL, __pPublicActionEvent != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
474 "[E_OUT_OF_MEMORY] The memory is insufficient.");
477 r = __pPublicActionEvent->AddListener(listener);
478 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to add an action event listener.");
480 r = __pContextMenu->AddActionEventListener(*this);
481 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to add an action event listener.");
487 _ContextMenuImpl::RemoveActionEventListener(Tizen::Ui::IActionEventListener& listener)
491 SysTryReturn(NID_UI_CTRL, __pPublicActionEvent != null, E_INVALID_STATE, E_INVALID_STATE,
492 "[E_INVALID_STATE] This instance isn't constructed.")
493 SysAssertf(__pContextMenu != null, "Not yet constructed. Construct() should be called before use.");
495 result r = E_SUCCESS;
497 r = __pPublicActionEvent->RemoveListener(listener);
498 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to remove an action event listener.");
500 r = __pContextMenu->RemoveActionEventListener(*this);
501 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to remove an action event listener.");
507 _ContextMenuImpl::OnActionPerformed(const Tizen::Ui::_Control& source, int actionId)
511 if (__pPublicActionEvent != null)
513 __pPublicActionEvent->Fire(*_PublicActionEvent::CreateActionEventArgN(actionId));
518 _ContextMenuImpl::GetPublicClassName(void) const
520 return "Tizen::Ui::Controls::ContextMenu";
524 _ContextMenuImpl::GetPublic(void) const
526 return static_cast <const ContextMenu&>(_ControlImpl::GetPublic());
530 _ContextMenuImpl::GetPublic(void)
532 return static_cast <ContextMenu&>(_ControlImpl::GetPublic());
536 _ContextMenuImpl::GetCore(void) const
538 return static_cast <const _ContextMenu&>(_ControlImpl::GetCore());
542 _ContextMenuImpl::GetCore(void)
544 return static_cast <_ContextMenu&>(_ControlImpl::GetCore());
547 }}} // Tizen::Ui: Control