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_ContextMenuGridPresenter.cpp
19 * @brief This is the implementation file for the _ContextMenuGridPresenter class.
22 #include <FBaseErrorDefine.h>
23 #include <FBaseSysLog.h>
24 #include <FGrp_BitmapImpl.h>
25 #include <FGrp_CanvasImpl.h>
26 #include <FGrp_TextTextSimple.h>
27 #include "FUi_AccessibilityContainer.h"
28 #include "FUi_AccessibilityElement.h"
29 #include "FUi_CoordinateSystemUtils.h"
31 #include "FUi_ResourceManager.h"
32 #include "FUiCtrl_ActionEvent.h"
33 #include "FUiCtrl_IActionEventListener.h"
35 #include "FUiCtrl_ContextMenuGridPresenter.h"
37 using namespace Tizen::Graphics;
38 using namespace Tizen::Ui;
39 using namespace Tizen::Base;
40 using namespace Tizen::Base::Runtime;
41 using namespace Tizen::Graphics::_Text;
43 static const int MAX_LINE_COUNT = 32; // Only for index of array
44 static const int MAX_ITEM_COUNT = 35;
46 namespace Tizen { namespace Ui { namespace Controls
49 _ContextMenuGridPresenter::_ContextMenuGridPresenter(_ContextMenu* pContextMenu)
50 : __pContextMenu(pContextMenu)
54 , __layoutSize(FloatDimension(0.0f, 0.0f))
55 , __touchOutRect(false)
61 , __bottomMargin(0.0f)
64 , __screenTopMargin(0.0f)
65 , __screenBottomMargin(0.0f)
66 , __screenLeftMargin(0.0f)
67 , __screenRightMargin(0.0f)
68 , __arrowTopMargin(0.0f)
69 , __arrowBottomMargin(0.0f)
70 , __arrowRightMargin(0.0f)
71 , __arrowLeftMargin(0.0f)
76 , __itemMaxWidth(0.0f)
77 , __itemTextMargin(0.0f)
79 , __itemBitmapWidth(0.0f)
80 , __itemBitmapHeight(0.0f)
81 , __itemFontSize(0.0f)
82 , __dividerHeight(0.0f)
83 , __bgPressedMargin(0.0f)
84 , __anchorPopupOverlap(0.0f)
85 , __enterKeyPressed(false)
86 , __backKeyPressed(false)
92 _ContextMenuGridPresenter::~_ContextMenuGridPresenter(void)
94 __pContextMenu = null;
101 __pTextObject->RemoveAll();
102 delete __pTextObject;
103 __pTextObject = null;
111 _ContextMenuGridPresenter::Install(void)
113 result r = E_SUCCESS;
117 __pModel = new (std::nothrow) _ContextMenuModel;
118 SysTryCatch(NID_UI_CTRL, __pModel != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
120 r = __pModel->Construct();
121 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Unable to create data instance.");
123 __pFont = __pContextMenu->GetFallbackFont();
125 SysTryCatch(NID_UI_CTRL, (__pFont != null), , r, "[%s] Propagating.", GetErrorMessage(r));
127 __pTextObject = new (std::nothrow) TextObject();
128 SysTryCatch(NID_UI_CTRL, __pTextObject, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Unable to create data instance.");
130 __pTextObject->Construct();
131 __pTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_CENTER | TEXT_OBJECT_ALIGNMENT_MIDDLE);
132 __pTextObject->SetWrap(TEXT_OBJECT_WRAP_TYPE_NONE);
133 __pTextObject->SetFont(__pFont, 0, __pTextObject->GetTextLength());
143 delete __pTextObject;
144 __pTextObject = null;
151 _ContextMenuGridPresenter::LoadShape(void)
153 GET_SHAPE_CONFIG(CONTEXTMENU::GRID_ITEM_WIDTH, _CONTROL_ORIENTATION_PORTRAIT, __itemWidth);
154 GET_SHAPE_CONFIG(CONTEXTMENU::GRID_ITEM_MAX_WIDTH, _CONTROL_ORIENTATION_PORTRAIT, __itemMaxWidth);
155 GET_SHAPE_CONFIG(CONTEXTMENU::GRID_ITEM_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, __itemHeight);
156 GET_SHAPE_CONFIG(CONTEXTMENU::GRID_TEXT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, __itemTextMargin);
157 GET_FIXED_VALUE_CONFIG(CONTEXTMENU::GRID_ITEM_GAP, _CONTROL_ORIENTATION_PORTRAIT, __itemGap);
159 GET_SHAPE_CONFIG(CONTEXTMENU::GRID_MIN_WIDTH, _CONTROL_ORIENTATION_PORTRAIT, __minWidth);
160 GET_SHAPE_CONFIG(CONTEXTMENU::GRID_TOP_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, __topMargin);
161 GET_SHAPE_CONFIG(CONTEXTMENU::GRID_BOTTOM_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, __bottomMargin);
162 GET_SHAPE_CONFIG(CONTEXTMENU::GRID_LEFT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, __leftMargin);
163 GET_SHAPE_CONFIG(CONTEXTMENU::GRID_RIGHT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, __rightMargin);
165 GET_SHAPE_CONFIG(CONTEXTMENU::GRID_ITEM_FONT_SIZE, _CONTROL_ORIENTATION_PORTRAIT, __itemFontSize);
166 GET_SHAPE_CONFIG(CONTEXTMENU::SCREEN_TOP_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, __screenTopMargin);
167 GET_SHAPE_CONFIG(CONTEXTMENU::SCREEN_BOTTOM_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, __screenBottomMargin);
168 GET_SHAPE_CONFIG(CONTEXTMENU::SCREEN_LEFT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, __screenLeftMargin);
169 GET_SHAPE_CONFIG(CONTEXTMENU::SCREEN_RIGHT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, __screenRightMargin);
170 GET_SHAPE_CONFIG(CONTEXTMENU::ANCHOR_TOP_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, __arrowTopMargin);
171 GET_SHAPE_CONFIG(CONTEXTMENU::ANCHOR_BOTTOM_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, __arrowBottomMargin);
172 GET_SHAPE_CONFIG(CONTEXTMENU::ANCHOR_LEFT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, __arrowLeftMargin);
173 GET_SHAPE_CONFIG(CONTEXTMENU::ANCHOR_RIGHT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, __arrowRightMargin);
174 GET_SHAPE_CONFIG(CONTEXTMENU::ANCHOR_WIDTH, _CONTROL_ORIENTATION_PORTRAIT, __arrowWidth);
175 GET_SHAPE_CONFIG(CONTEXTMENU::ANCHOR_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, __arrowHeight);
176 GET_SHAPE_CONFIG(CONTEXTMENU::GRID_ICON_WIDTH, _CONTROL_ORIENTATION_PORTRAIT, __itemBitmapWidth);
177 GET_SHAPE_CONFIG(CONTEXTMENU::GRID_ICON_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, __itemBitmapHeight);
178 GET_SHAPE_CONFIG(CONTEXTMENU::GRID_DIVIDER_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, __dividerHeight);
179 GET_SHAPE_CONFIG(CONTEXTMENU::ITEM_BG_PRESSED_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, __bgPressedMargin);
180 GET_SHAPE_CONFIG(CONTEXTMENU::ANCHOR_POPUP_OVERLAP, _CONTROL_ORIENTATION_PORTRAIT, __anchorPopupOverlap);
184 _ContextMenuGridPresenter::CreateItem(const Base::String& text, int actionId, const Tizen::Graphics::Bitmap* pNormalBitmap, const Tizen::Graphics::Bitmap* pPressedBitmap, const Tizen::Graphics::Bitmap* pHighlightedBitmap)
186 _ContextMenuItem* pItem = _ContextMenuItem::CreateContextMenuItemN();
187 SysTryReturn(NID_UI_CTRL, pItem != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
189 ContextMenuItemDrawingType itemType = CONTEXT_MENU_ITEM_DRAWING_TYPE_NONE;
190 result r = E_SUCCESS;
192 if (text.GetLength() != 0)
194 r = pItem->SetText(text);
201 itemType = CONTEXT_MENU_ITEM_DRAWING_TYPE_TEXT;
205 if (pNormalBitmap == null && pPressedBitmap == null)
211 if (pNormalBitmap != null)
213 r = pItem->SetBitmap(CONTEXT_MENU_ITEM_DRAWING_STATUS_NORMAL, pNormalBitmap);
221 if (pPressedBitmap != null)
223 r = pItem->SetBitmap(CONTEXT_MENU_ITEM_DRAWING_STATUS_PRESSED, pPressedBitmap);
231 itemType = CONTEXT_MENU_ITEM_DRAWING_TYPE_BITMAP;
234 pItem->SetType(itemType);
235 pItem->SetActionId(actionId);
237 // calculate item size
244 _ContextMenuGridPresenter::AddItem(const Base::String& text, int actionId, const Tizen::Graphics::Bitmap* normalBitmap,
245 const Tizen::Graphics::Bitmap* pPressedBitmap,
246 const Tizen::Graphics::Bitmap* pHighlightedBitmap)
248 _ContextMenuItem* pItem = CreateItem(text, actionId, normalBitmap, pPressedBitmap, pHighlightedBitmap);
249 SysTryReturn(NID_UI_CTRL, pItem != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "The memory is insufficient.");
251 result r = __pModel->AddItem(pItem);
256 SysTryReturn(NID_UI_CTRL, false, r, r, "Failed to add item.");
259 r = AdjustItemLayout();
262 result rt = __pModel->RemoveItem(__pModel->GetItemCount() - 1);
263 SysTryReturn(NID_UI_CTRL, rt == E_SUCCESS, rt, rt, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
265 SysTryReturn(NID_UI_CTRL, false, r, r, "Failed to add item.");
272 _ContextMenuGridPresenter::InsertItem(int index, const Tizen::Base::String& text, int actionId,
273 const Tizen::Graphics::Bitmap* normalBitmap, const Tizen::Graphics::Bitmap* pPressedBitmap,
274 const Tizen::Graphics::Bitmap* pHighlightedBitmap)
276 if (text.GetLength() == 0 && normalBitmap == null && pPressedBitmap == null)
278 return E_INVALID_ARG;
281 _ContextMenuItem* pItem = null;
283 pItem = CreateItem(text, actionId, normalBitmap, pPressedBitmap, pHighlightedBitmap);
284 SysTryReturn(NID_UI_CTRL, pItem != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "The memory is insufficient.");
286 result r = __pModel->InsertItem(pItem, index);
290 SysTryReturn(NID_UI_CTRL, false, r, r, "Failed to insert item.");
293 r = AdjustItemLayout();
296 result rt = __pModel->RemoveItem(index);
297 SysTryReturn(NID_UI_CTRL, rt == E_SUCCESS, rt, rt, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
299 SysTryReturn(NID_UI_CTRL, false, r, r, "Failed to insert item.");
306 _ContextMenuGridPresenter::SetItem(int index, const Tizen::Base::String& text, int actionId,
307 const Tizen::Graphics::Bitmap* normalBitmap, const Tizen::Graphics::Bitmap* pPressedBitmap,
308 const Tizen::Graphics::Bitmap* pHighlightedBitmap)
310 if (text.GetLength() == 0 && normalBitmap == null && pPressedBitmap == null)
312 return E_INVALID_ARG;
315 _ContextMenuItem* pItem = null;
316 pItem = CreateItem(text, actionId, normalBitmap, pPressedBitmap, pHighlightedBitmap);
317 SysTryReturn(NID_UI_CTRL, pItem != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "The memory is insufficient.");
319 result r = __pModel->SetItem(pItem, index);
323 SysTryReturn(NID_UI_CTRL, false, r, r, "Failed to set item.");
326 r = AdjustItemLayout();
329 result rt = __pModel->RemoveItem(index);
330 SysTryReturn(NID_UI_CTRL, rt == E_SUCCESS, rt, rt, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
332 SysTryReturn(NID_UI_CTRL, false, r, r, "Failed to set item.");
339 _ContextMenuGridPresenter::DeleteItem(int index)
341 int itemCount = __pContextMenu->GetItemCount();
343 if (itemCount <= 0 || index >= itemCount || index < 0)
345 SysLogException(NID_UI_CTRL, E_INVALID_STATE, "Invalid argument.");
346 return E_INVALID_STATE;
349 result r = __pModel->RemoveItem(index);
350 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to delete item.");
356 _ContextMenuGridPresenter::DeleteItemAll(void)
358 int itemCount = __pContextMenu->GetItemCount();
362 SysLogException(NID_UI_CTRL, E_INVALID_STATE, "Invalid argument.");
363 return E_INVALID_STATE;
366 result r = __pModel->RemoveAllItem();
367 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to delete item all.");
374 _ContextMenuGridPresenter::CalculateShowItemCount(void)
376 return __pContextMenu->GetShowItemCount();
380 _ContextMenuGridPresenter::SetItemSize(_ContextMenuItem* pItem)
382 ContextMenuItemDrawingType itemType = pItem->GetType();
384 if (itemType == CONTEXT_MENU_ITEM_DRAWING_TYPE_TEXT)
386 float textMargin = __itemTextMargin;
387 float minWidth = __itemWidth;
388 float maxWidth = __itemMaxWidth;
390 String text = pItem->GetText();
392 textMargin = textMargin * 2.0f;
393 minWidth = minWidth - textMargin;
394 maxWidth = maxWidth - textMargin;
396 FloatDimension textArea(0.0f, 0.0f);
397 FloatDimension itemSize(0.0f, 0.0f);
399 __pFont->GetTextExtent(text, text.GetLength(), textArea);
401 if (textArea.width < minWidth)
403 textArea.width = minWidth;
406 if (textArea.width > maxWidth)
408 textArea.width = maxWidth;
411 itemSize.width = textArea.width + textMargin;
412 itemSize.height = __itemHeight;
414 pItem->SetSize(itemSize);
417 else if (itemType == CONTEXT_MENU_ITEM_DRAWING_TYPE_BITMAP)
419 FloatDimension itemSize(__itemWidth, __itemHeight);
421 pItem->SetSize(itemSize);
426 _ContextMenuGridPresenter::CalculateWindowRect(void)
428 result r = E_SUCCESS;
430 r = AdjustItemLayout();
431 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
434 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
436 AdjustItemPosition();
442 _ContextMenuGridPresenter::ApplyColorProperty(void)
448 _ContextMenuGridPresenter::CalculateRect(void)
450 Tizen::Graphics::FloatRectangle windowRect = Tizen::Graphics::FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f); // ContextMenu window itself
451 Tizen::Graphics::FloatRectangle bodyRect = Tizen::Graphics::FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f); // bg surronding showing items, relative to window
452 Tizen::Graphics::FloatRectangle arrowRect = Tizen::Graphics::FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f); // relative to window
453 Tizen::Graphics::FloatRectangle itemRect = Tizen::Graphics::FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f); // relative to window
455 float bodyTopMargin = __topMargin;
456 float bodyBottomMargin = __bottomMargin;
457 float bodyLeftMargin = __leftMargin;
458 float bodyRightMargin = __rightMargin;
460 float screenTopMargin = __screenTopMargin;
461 float screenBottomMargin = __screenBottomMargin;
462 float screenLeftMargin = __screenLeftMargin;
463 float screenRightMargin = __screenRightMargin;
465 FloatPoint anchorPosition = __pContextMenu->GetAnchorPosition();
467 FloatDimension screen = _ControlManager::GetInstance()->GetScreenSizeF();
468 if (__pContextMenu->GetLayout() == _CONTROL_ORIENTATION_LANDSCAPE)
470 screen.SetSize(screen.height, screen.width);
473 // calculate arrow rect
474 enum ContextMenuCoreDropPosition dropPosition = __pContextMenu->GetDropPosition();
475 if (dropPosition == CONTEXT_MENU_CORE_DROP_POSITION_UP || dropPosition == CONTEXT_MENU_CORE_DROP_POSITION_DOWN) // down, up Arrow
477 arrowRect.width = __arrowWidth;
478 arrowRect.height = __arrowHeight;
480 else // left, right Arrow
482 arrowRect.width = __arrowHeight;
483 arrowRect.height = __arrowWidth;
486 // calculate body rect
487 // calculate drawable boundaries for contextmenu
488 float leftBoundary = screenLeftMargin;
489 float rightBoundary = screen.width - screenRightMargin;
490 float topBoundary = screenTopMargin;
491 float bottomBoundary = screen.height - screenBottomMargin;
493 if (__pModel->GetItemCount() <= 0)
495 __layoutSize.width = __itemWidth;
496 __layoutSize.height = __itemHeight;
499 bodyRect.width = __layoutSize.width + bodyLeftMargin + bodyRightMargin;
500 bodyRect.height = __layoutSize.height + bodyTopMargin + bodyBottomMargin;
502 // calculate the position of the arrow and body rect.
503 if (dropPosition == CONTEXT_MENU_CORE_DROP_POSITION_UP) // down Arrow
505 // Check touch position
506 // - Check left margin
507 if (anchorPosition.x <= leftBoundary + arrowRect.width)
509 anchorPosition.x = leftBoundary + arrowRect.width;
511 // - check right margin
512 if (anchorPosition.x >= (rightBoundary - arrowRect.width))
514 anchorPosition.x = rightBoundary - arrowRect.width;
516 // - check top margin
517 if (anchorPosition.y <= topBoundary)
519 anchorPosition.y = topBoundary + bodyRect.height;
521 // - check bottom margin
522 if (anchorPosition.y >= bottomBoundary)
524 anchorPosition.y = bottomBoundary;
527 // Set body position x
528 bodyRect.x = anchorPosition.x - (bodyRect.width / 2.0f);
529 // - Check left margin
530 if (bodyRect.x <= leftBoundary)
532 bodyRect.x = leftBoundary;
534 // - check right margin
535 if ((bodyRect.x + bodyRect.width) >= rightBoundary)
537 bodyRect.x = rightBoundary - bodyRect.width;
539 // Set body position y
540 bodyRect.y = anchorPosition.y - arrowRect.height - bodyRect.height;
541 // - check top margin
542 if (bodyRect.y <= topBoundary)
544 bodyRect.y = topBoundary;
547 float correctLength = __arrowTopMargin - __anchorPopupOverlap;
548 windowRect.x = bodyRect.x;
549 windowRect.y = bodyRect.y + correctLength;
550 windowRect.width = bodyRect.width;
551 windowRect.height = bodyRect.height + arrowRect.height - correctLength;
556 // Set arrow position
557 arrowRect.x = anchorPosition.x - (arrowRect.width / 2.0f) - windowRect.x;
558 arrowRect.y = bodyRect.height - correctLength;
560 else if (dropPosition == CONTEXT_MENU_CORE_DROP_POSITION_DOWN) // up Arrow
562 // Check touch position
563 // - Check left margin
564 if (anchorPosition.x <= leftBoundary + arrowRect.width)
566 anchorPosition.x = leftBoundary + arrowRect.width;
568 // - check right margin
569 if (anchorPosition.x >= (rightBoundary - arrowRect.width))
571 anchorPosition.x = rightBoundary - arrowRect.width;
573 // - check top margin
574 if (anchorPosition.y <= topBoundary)
576 anchorPosition.y = topBoundary;
578 // - check bottom margin
579 if (anchorPosition.y >= bottomBoundary)
581 anchorPosition.y = bottomBoundary;
584 // Set body position x
585 bodyRect.x = anchorPosition.x - (bodyRect.width / 2.0f);
586 // - Check left margin
587 if (bodyRect.x <= leftBoundary)
589 bodyRect.x = leftBoundary;
591 // - check right margin
592 if ((bodyRect.x + bodyRect.width) >= rightBoundary)
594 bodyRect.x = rightBoundary - bodyRect.width;
596 // Set body position y
597 bodyRect.y = anchorPosition.y + arrowRect.height;
598 // - Check bottom margin
599 if ((bodyRect.y + bodyRect.height) >= bottomBoundary)
601 bodyRect.y = bottomBoundary - bodyRect.height;
604 float correctLength = __arrowBottomMargin - __anchorPopupOverlap;
605 windowRect.x = bodyRect.x;
606 windowRect.y = bodyRect.y - arrowRect.height;
607 windowRect.width = bodyRect.width;
608 windowRect.height = bodyRect.height + arrowRect.height - correctLength;
611 bodyRect.y = arrowRect.height - correctLength;
613 // Set arrow position
614 arrowRect.x = anchorPosition.x - (arrowRect.width / 2.0f) - windowRect.x;
617 else if (dropPosition == CONTEXT_MENU_CORE_DROP_POSITION_LEFT) // right Arrow
619 // Check touch position
620 // - Check left margin
621 if (anchorPosition.x <= leftBoundary)
623 anchorPosition.x = leftBoundary + bodyRect.width;
625 // - check right margin
626 if (anchorPosition.x >= rightBoundary)
628 anchorPosition.x = rightBoundary;
630 // - Check top margin
631 if (anchorPosition.y <= topBoundary + arrowRect.height)
633 anchorPosition.y = topBoundary + arrowRect.height;
635 // - check bottom margin
636 if (anchorPosition.y >= (bottomBoundary - arrowRect.height))
638 anchorPosition.y = bottomBoundary - arrowRect.height;
641 // Set body position x
642 bodyRect.x = anchorPosition.x - arrowRect.width - bodyRect.width;
643 // - Check left margin
644 if (bodyRect.x <= leftBoundary)
646 bodyRect.x = leftBoundary;
648 // - check right margin
649 if ((bodyRect.x + bodyRect.width + arrowRect.width) >= rightBoundary)
651 bodyRect.x = rightBoundary - bodyRect.width - arrowRect.width;
654 // Set body position y
655 bodyRect.y = anchorPosition.y - (bodyRect.height / 2.0f);
656 // - check top margin
657 if (bodyRect.y <= topBoundary)
659 bodyRect.y = topBoundary;
661 // - check bottom margin
662 if ((bodyRect.y + bodyRect.height) >= bottomBoundary)
664 bodyRect.y = bottomBoundary - bodyRect.height;
667 float correctLength = __arrowRightMargin - __anchorPopupOverlap;
668 windowRect.x = bodyRect.x + correctLength;
669 windowRect.y = bodyRect.y;
670 windowRect.width = bodyRect.width + arrowRect.width - correctLength;
671 windowRect.height = bodyRect.height;
676 // Set arrow position
677 arrowRect.x = bodyRect.width - correctLength;
678 arrowRect.y = anchorPosition.y - (arrowRect.height / 2.0f) - windowRect.y;
682 // Check touch position
683 // - Check top margin
684 if (anchorPosition.x <= leftBoundary)
686 anchorPosition.x = leftBoundary;
688 // - check right margin
689 if (anchorPosition.x >= rightBoundary)
691 anchorPosition.x = rightBoundary - bodyRect.width;
693 // - Check top margin
694 if (anchorPosition.y <= topBoundary + arrowRect.height)
696 anchorPosition.y = topBoundary + arrowRect.height;
698 // - check bottom margin
699 if (anchorPosition.y >= (bottomBoundary - arrowRect.height))
701 anchorPosition.y = bottomBoundary - arrowRect.height;
704 // Set body position x
705 bodyRect.x = anchorPosition.x;
706 // - Check left margin
707 if (bodyRect.x <= leftBoundary)
709 bodyRect.x = leftBoundary;
711 // - check right margin
712 if ((bodyRect.x + bodyRect.width + arrowRect.width) >= rightBoundary)
714 bodyRect.x = rightBoundary - bodyRect.width - arrowRect.width;
716 // Set body position y
717 bodyRect.y = anchorPosition.y - (bodyRect.height / 2);
718 // - check top margin
719 if (bodyRect.y <= topBoundary)
721 bodyRect.y = topBoundary;
723 // - check bottom margin
724 if ((bodyRect.y + bodyRect.height) >= bottomBoundary)
726 bodyRect.y = bottomBoundary - bodyRect.height;
729 float correctLength = __arrowLeftMargin - __anchorPopupOverlap;
730 windowRect.x = bodyRect.x;
731 windowRect.y = bodyRect.y;
732 windowRect.width = bodyRect.width + arrowRect.width - correctLength;
733 windowRect.height = bodyRect.height;
735 bodyRect.x = arrowRect.width - correctLength;
738 // Set arrow position
740 arrowRect.y = anchorPosition.y - (arrowRect.height / 2.0f) - windowRect.y;
743 itemRect.x = bodyRect.x + bodyLeftMargin;
744 itemRect.y = bodyRect.y + bodyTopMargin;
745 itemRect.width = __layoutSize.width;
746 itemRect.height = __layoutSize.height;
748 __pContextMenu->SetWindowRect(windowRect);
749 __pContextMenu->SetBodyRect(bodyRect);
750 __pContextMenu->SetArrowRect(arrowRect);
751 __pContextMenu->SetItemRect(itemRect);
753 __pContextMenu->SetMovable(true);
754 __pContextMenu->SetResizable(true);
756 __pContextMenu->SetMinimumSize(FloatDimension(0.0f, 0.0f));
757 __pContextMenu->SetMaximumSize(screen);
758 __pContextMenu->SetBounds(windowRect);
760 __pContextMenu->SetMovable(false);
761 __pContextMenu->SetResizable(false);
767 _ContextMenuGridPresenter::IsLayoutBitmapOnly(void)
769 int itemCount = __pModel->GetItemCount();
776 _ContextMenuItem* pItem = null;
778 for (int i = 0; i < itemCount; i++)
780 pItem = __pModel->GetItem(i);
786 if (pItem->GetType() == CONTEXT_MENU_ITEM_DRAWING_TYPE_TEXT)
796 _ContextMenuGridPresenter::AdjustItemLayout(void)
798 int itemCount = __pModel->GetItemCount();
799 FloatDimension layoutSize(0.0f, 0.0f);
803 __layoutSize.width = __itemWidth;
804 __layoutSize.height = __itemHeight;
809 // GUI guide word: 5x2
810 bool bitmapOnly = IsLayoutBitmapOnly();
812 if (bitmapOnly == true)
814 layoutSize = AdjustItemLayoutIconStyle();
818 layoutSize = AdjustItemLayoutTabStyle();
821 __layoutSize = layoutSize;
823 return GetLastResult();
826 Tizen::Graphics::FloatDimension
827 _ContextMenuGridPresenter::AdjustItemLayoutIconStyle(void)
831 int countPerLine = 0;
832 int itemCount = __pModel->GetItemCount();
833 float itemWidth = __itemWidth + __itemGap;
834 float itemHeight = __itemHeight + __itemGap;
835 FloatDimension layoutSize(0.0f, 0.0f);
837 if (itemCount > MAX_ITEM_COUNT)
839 SetLastResult(E_MAX_EXCEEDED);
843 countPerLine = GetCountPerLine(itemCount);
845 int lineCount = itemCount / countPerLine;
846 if (itemCount % countPerLine != 0)
851 layoutSize.width = countPerLine * __itemWidth + (countPerLine - 1) * __itemGap;
852 int showLineCount = __pContextMenu->GetShowItemMaxCount();
853 if (lineCount > showLineCount)
855 SetLastResult(E_MAX_EXCEEDED);
859 showLineCount = lineCount;
861 layoutSize.height = showLineCount * __itemHeight + (showLineCount - 1) *__itemGap;
863 _ContextMenuItem* pItem = null;
865 for (int line = 0; line < showLineCount; line++)
867 float pressedTopMargin = 0.0f, pressedBottomMargin = 0.0f;
870 pressedTopMargin = __bgPressedMargin;
873 if (line == showLineCount - 1)
875 pressedBottomMargin = __bgPressedMargin;
878 for (int i = 0; i < countPerLine; i++)
880 int index = (line * countPerLine) + i;
881 if (index >= itemCount)
886 pItem = __pModel->GetItem(index);
893 FloatRectangle drawRect(0.0f, 0.0f, __itemWidth, __itemHeight);
895 drawRect.x = (i * itemWidth);
896 drawRect.y = (line * itemHeight);
898 bool drawDivider = true;
899 if (i == countPerLine - 1)
904 pItem->SetDrawRect(drawRect);
905 pItem->SetLowerDivider(drawDivider);
907 float pressedLeftMargin = 0.0f, pressedRightMargin = 0.0f;
910 pressedLeftMargin = __bgPressedMargin;
913 if (i == countPerLine - 1)
915 pressedRightMargin = __bgPressedMargin;
918 FloatRectangle pressedDrawRect = drawRect;
919 pressedDrawRect.x += pressedLeftMargin;
920 pressedDrawRect.y += pressedTopMargin;
921 pressedDrawRect.width -= pressedLeftMargin + pressedRightMargin;
922 pressedDrawRect.height -= pressedTopMargin + pressedBottomMargin;
923 pItem->SetPressedDrawRect(pressedDrawRect);
924 __showItemCount = index;
934 Tizen::Graphics::FloatDimension
935 _ContextMenuGridPresenter::AdjustItemLayoutTabStyle(void)
939 int lineItemCountList[MAX_LINE_COUNT] = {0, };
940 float lineWidthList[MAX_LINE_COUNT] = {0.0f, };
942 int itemCount = __pModel->GetItemCount();
943 float maxWidth = __itemWidth;
944 float itemHeight = __itemHeight + __itemGap;
945 int lineCount = 1, showLineCount = 0;
946 float lineWidth = 0.0f;
947 int lineItemCount = 0;
950 float remainWidth = 0.0f;
951 FloatDimension screen = _ControlManager::GetInstance()->GetScreenSizeF();
952 FloatPoint anchorPosition = __pContextMenu->GetAnchorPosition();
953 ContextMenuCoreDropPosition dropPosition = __pContextMenu->GetDropPosition();
955 if (__pContextMenu->GetLayout() == _CONTROL_ORIENTATION_LANDSCAPE)
957 GET_SHAPE_CONFIG(CONTEXTMENU::GRID_MAX_WIDTH, _CONTROL_ORIENTATION_LANDSCAPE, __maxWidth);
958 screen.SetSize(screen.height, screen.width);
962 GET_SHAPE_CONFIG(CONTEXTMENU::GRID_MAX_WIDTH, _CONTROL_ORIENTATION_PORTRAIT, __maxWidth);
965 if (dropPosition == CONTEXT_MENU_CORE_DROP_POSITION_LEFT || dropPosition == CONTEXT_MENU_CORE_DROP_POSITION_RIGHT)
967 remainWidth = anchorPosition.x * 2 < screen.width ? screen.width - anchorPosition.x : anchorPosition.x;
968 remainWidth -= __screenLeftMargin + __leftMargin + __rightMargin + __screenRightMargin;
969 remainWidth -= __arrowHeight;
970 __maxWidth = __maxWidth < remainWidth ? __maxWidth : remainWidth;
973 _ContextMenuItem* pItem = null;
974 for (int i = 0; i < itemCount; i++)
976 pItem = __pModel->GetItem(i);
982 FloatDimension itemSize = pItem->GetSize();
983 if (lineWidth + itemSize.width > __maxWidth)
985 _ContextMenuItem* pPreviousItem = __pModel->GetItem(i - 1);
986 if (pPreviousItem != null)
988 pPreviousItem->SetLowerDivider(false);
999 FloatRectangle drawRect(x, y, itemSize.width, itemSize.height);
1000 pItem->SetDrawRect(drawRect);
1001 pItem->SetLowerDivider(true);
1003 x = x + itemSize.width + __itemGap;
1004 lineWidth = lineWidth + itemSize.width + __itemGap;
1006 if (lineWidth > maxWidth)
1008 maxWidth = lineWidth;
1012 if (lineItemCount > MAX_LINE_COUNT)
1014 lineItemCount = MAX_LINE_COUNT;
1018 lineWidthList[lineCount - 1] = lineWidth;
1019 lineItemCountList[lineCount - 1] = lineItemCount;
1025 pItem->SetLowerDivider(false);
1028 FloatDimension layoutSize(__itemWidth, __itemHeight);
1029 layoutSize.width = maxWidth - __itemGap;
1030 showLineCount = __pContextMenu->GetShowItemMaxCount();
1031 if (lineCount > showLineCount)
1033 SetLastResult(E_MAX_EXCEEDED);
1037 showLineCount = lineCount;
1039 layoutSize.height = showLineCount * __itemHeight + (showLineCount - 1) *__itemGap;
1043 for (int line = 0; line < showLineCount; line++)
1045 FloatRectangle drawRect;
1046 float width = lineWidthList[line];
1047 int count = lineItemCountList[line];
1048 float blank = maxWidth - width;
1049 float addMargin = blank / count;
1050 if (_FloatCompareGE(blank, 100.0f) && line == showLineCount - 1)
1055 float pressedTopMargin = 0.0f, pressedBottomMargin = 0.0f;
1058 pressedTopMargin = __bgPressedMargin;
1061 if (line == showLineCount - 1)
1063 pressedBottomMargin = __bgPressedMargin;
1066 for (int i = 0; i < count; i++)
1068 int index = itemIndex + i;
1069 pItem = __pModel->GetItem(index);
1075 drawRect = pItem->GetDrawRect();
1077 drawRect.width = drawRect.width + addMargin;
1078 drawRect.x = drawRect.x + (i * addMargin);
1080 pItem->SetDrawRect(drawRect);
1082 float pressedLeftMargin = 0.0f, pressedRightMargin = 0.0f;
1085 pressedLeftMargin = __bgPressedMargin;
1090 pressedRightMargin = __bgPressedMargin;
1093 FloatRectangle pressedDrawRect = drawRect;
1094 pressedDrawRect.x += pressedLeftMargin;
1095 pressedDrawRect.y += pressedTopMargin;
1096 pressedDrawRect.width -= pressedLeftMargin + pressedRightMargin;
1097 pressedDrawRect.height -= pressedTopMargin + pressedBottomMargin;
1098 pItem->SetPressedDrawRect(pressedDrawRect);
1099 __showItemCount = index;
1111 _ContextMenuGridPresenter::AdjustItemPosition(void)
1113 int itemCount = __pModel->GetItemCount();
1120 int x = __pContextMenu->GetBodyRect().x + __leftMargin;
1121 int y = __pContextMenu->GetBodyRect().y + __topMargin;
1123 _ContextMenuItem* pItem = null;
1125 for (int i = 0; i < itemCount; i++)
1127 pItem = __pModel->GetItem(i);
1134 FloatRectangle drawRect = pItem->GetDrawRect();
1137 pItem->SetDrawRect(drawRect);
1139 FloatRectangle pressedDrawRect = pItem->GetPressedDrawRect();
1140 pressedDrawRect.x += x;
1141 pressedDrawRect.y += y;
1142 pItem->SetPressedDrawRect(pressedDrawRect);
1147 _ContextMenuGridPresenter::GetCountPerLine(int count) const
1149 static const int countOfX[MAX_ITEM_COUNT + 1] = {0, // not used
1150 1, 2, 3, 4, 5, 3, 4, 4, 5, 5,
1151 4, 4, 5, 5, 5, 4, 5, 5, 5, 5,
1152 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
1156 return countOfX[count];
1160 _ContextMenuGridPresenter::GetItemIndexFromPosition(const Tizen::Graphics::FloatPoint& point) const
1163 int itemCount = __pModel->GetItemCount();
1170 _ContextMenuItem* pItem = null;
1172 for (int i = 0; i < itemCount; i++)
1174 pItem = __pModel->GetItem(i);
1181 FloatRectangle drawRect = pItem->GetDrawRect();
1183 if (drawRect.Contains(point) == true)
1195 _ContextMenuGridPresenter::Draw(void)
1197 result r = E_SUCCESS;
1199 Canvas* pCanvas = __pContextMenu->GetCanvasN();
1200 SysTryReturn(NID_UI_CTRL, pCanvas != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "The memory is insufficient.");
1202 // Clear canvas for drawing area of the ContextMenu.
1203 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
1204 Tizen::Graphics::FloatRectangle bounds(__pContextMenu->GetWindowRect());
1205 pCanvas->Clear(Tizen::Graphics::FloatRectangle(0.0f, 0.0f, bounds.width, bounds.height));
1207 r = DrawBackground(pCanvas);
1208 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to draw background.");
1210 r = DrawArrow(pCanvas);
1211 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to draw arrow.");
1213 r = DrawItem(pCanvas);
1221 _ContextMenuGridPresenter::DrawBackground(Canvas* pCanvas)
1223 SysTryReturn(NID_UI_CTRL, pCanvas != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
1225 result r = E_SUCCESS;
1227 Tizen::Graphics::FloatRectangle bodyRect = __pContextMenu->GetBodyRect();
1229 const Bitmap* pBackgroundNormalBitmap = __pContextMenu->GetBackgroundNormalBitmap();
1230 const Bitmap* pBackgroundEffectBitmap = __pContextMenu->GetBackgroundEffectBitmap();
1232 if (pBackgroundNormalBitmap == null && pBackgroundEffectBitmap == null)
1234 pCanvas->SetForegroundColor(__pContextMenu->GetColor());
1235 pCanvas->DrawRectangle(bodyRect);
1239 if (pBackgroundNormalBitmap != null)
1241 r = DrawBitmap(*pCanvas, bodyRect, *pBackgroundNormalBitmap);
1244 if (pBackgroundEffectBitmap != null)
1246 r = DrawBitmap(*pCanvas, bodyRect, *pBackgroundEffectBitmap);
1254 _ContextMenuGridPresenter::DrawArrow(Canvas* pCanvas)
1256 SysTryReturn(NID_UI_CTRL, pCanvas != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
1258 result r = E_SUCCESS;
1259 Tizen::Graphics::FloatRectangle arrowRect = __pContextMenu->GetArrowRect();
1260 ContextMenuCoreDropPosition dropPosition = __pContextMenu->GetDropPosition();
1262 const Bitmap* pArrowNormalBitmap = __pContextMenu->GetArrowNormalBitmap(dropPosition);
1263 const Bitmap* pEffectArrowBitmap = __pContextMenu->GetArrowEffectBitmap(dropPosition);
1265 if (pArrowNormalBitmap != null)
1267 r = DrawBitmap(*pCanvas, arrowRect, *pArrowNormalBitmap);
1270 if (pEffectArrowBitmap != null)
1272 r = DrawBitmap(*pCanvas, arrowRect, *pEffectArrowBitmap);
1279 _ContextMenuGridPresenter::DrawItem(Tizen::Graphics::Canvas* pCanvas)
1281 SysTryReturn(NID_UI_CTRL, pCanvas != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
1283 result r = E_SUCCESS;
1284 TextSimple* pSimpleText = null;
1286 int itemCount = __showItemCount;
1293 FloatRectangle bodyRect = __pContextMenu->GetBodyRect();
1294 Color pressedColor = __pContextMenu->GetItemColor(CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED);
1296 float bitmapLeftMargin = __itemBitmapWidth / 2.0f;
1297 float bitmapTopMargin = __itemBitmapHeight / 2.0f;
1298 float linePositionX = bodyRect.x + __leftMargin + __rightMargin;
1299 float linePositionY = bodyRect.y + __topMargin;
1301 _ContextMenuItem* pItem = null;
1303 for (int i = 0; i < itemCount; i++)
1305 pItem = __pModel->GetItem(i);
1312 FloatRectangle rect = pItem->GetDrawRect();
1314 bool drawDivider = pItem->HasLowerDivider();
1315 if (drawDivider == true)
1317 float x = rect.x + rect.width;
1318 float y = rect.y + __topMargin;
1320 FloatPoint point1(x, y);
1321 FloatPoint point2(x, y + __dividerHeight);
1324 DrawLine(pCanvas, point1, point2, true);
1328 // TOCHK find out what makes SHAPE_CONFIG values * 2 / 3 if (!_FloatCompare(linePositionY, rect.y))
1329 if (linePositionY - rect.y > 1.0f || linePositionY - rect.y < -1.0f)
1331 linePositionY = rect.y;
1333 float x = linePositionX + __layoutSize.width - __leftMargin - __rightMargin;
1334 float y = linePositionY - __itemGap;
1336 FloatPoint point1(linePositionX, y);
1337 FloatPoint point2(x, y);
1339 DrawLine(pCanvas, point1, point2, false);
1342 ContextMenuItemDrawingType itemType = pItem->GetType();
1344 if (itemType == CONTEXT_MENU_ITEM_DRAWING_TYPE_TEXT)
1346 FloatRectangle drawRect = rect;
1347 drawRect.x = drawRect.x + __itemTextMargin;
1348 drawRect.width = drawRect.width - (__itemTextMargin * 2.0f);
1350 ContextMenuCoreItemStatus itemStatus = CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL;
1352 if (__selectedIndex == i)
1354 FloatRectangle pressedDrawRect = pItem->GetPressedDrawRect();
1355 itemStatus = CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED;
1356 Bitmap* bgBitmap = _BitmapImpl::GetColorReplacedBitmapN(*(pItem->GetMagentaBgBitmap()), Color::GetColor(COLOR_ID_MAGENTA), pressedColor);
1357 SysTryReturn(NID_UI_CTRL, bgBitmap, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1359 DrawBitmap(*pCanvas, pressedDrawRect, *bgBitmap);
1364 String text = pItem->GetText();
1366 __pTextObject->RemoveAll();
1367 pSimpleText = new (std::nothrow)TextSimple(const_cast <mchar*>(text.GetPointer()), text.GetLength());
1368 SysTryReturn(NID_UI_CTRL, pSimpleText != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1369 __pTextObject->AppendElement(*pSimpleText);
1371 __pTextObject->SetForegroundColor(__pContextMenu->GetTextColor(itemStatus), 0, __pTextObject->GetTextLength());
1372 __pTextObject->SetBounds(drawRect);
1373 __pTextObject->SetFont(__pFont, 0, __pTextObject->GetTextLength());
1374 __pTextObject->Draw(*_CanvasImpl::GetInstance(*pCanvas));
1379 FloatRectangle drawRect = rect;
1381 drawRect.x = drawRect.x + drawRect.width / 2.0f - bitmapLeftMargin;
1382 drawRect.y = drawRect.y + drawRect.height / 2.0f - bitmapTopMargin;
1383 drawRect.width = __itemBitmapWidth;
1384 drawRect.height = __itemBitmapHeight;
1386 ContextMenuItemDrawingStatus itemStatus = CONTEXT_MENU_ITEM_DRAWING_STATUS_NORMAL;
1388 if (__selectedIndex == i)
1390 FloatRectangle pressedDrawRect = pItem->GetPressedDrawRect();
1391 itemStatus = CONTEXT_MENU_ITEM_DRAWING_STATUS_PRESSED;
1392 Bitmap* bgBitmap = _BitmapImpl::GetColorReplacedBitmapN(*(pItem->GetMagentaBgBitmap()), Color::GetColor(COLOR_ID_MAGENTA), pressedColor);
1393 SysTryReturn(NID_UI_CTRL, bgBitmap, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1395 DrawBitmap(*pCanvas, pressedDrawRect, *bgBitmap);
1400 const Bitmap* pBitmap = pItem->GetBitmap(itemStatus);
1401 if (pBitmap != null)
1403 DrawBitmap(*pCanvas, drawRect, *pBitmap);
1407 if (__focusedIndex == i)
1409 FloatRectangle pressedDrawRect = pItem->GetPressedDrawRect();
1411 Color contentHighlightedColor;
1412 GET_COLOR_CONFIG(FOCUSUI::CONTENT_BG_HIGHLIGHTED, contentHighlightedColor);
1413 Bitmap* pBitmap = null;
1414 Bitmap* pTempBitmap = null;
1415 result r = GET_BITMAP_CONFIG_N(FOCUSUI::FOCUS, BITMAP_PIXEL_FORMAT_ARGB8888, pTempBitmap);
1416 SysTryReturn(NID_UI_CTRL, pTempBitmap != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1419 pBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pTempBitmap, Color::GetColor(COLOR_ID_MAGENTA), contentHighlightedColor);
1420 if (pBitmap != null)
1422 DrawBitmap(*pCanvas, pressedDrawRect, *pBitmap);
1439 _ContextMenuGridPresenter::DrawLine(Tizen::Graphics::Canvas* pCanvas, Tizen::Graphics::FloatPoint point1, Tizen::Graphics::FloatPoint point2, bool drawVLine)
1441 SysTryReturn(NID_UI_CTRL, pCanvas != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
1443 result r = E_SUCCESS;
1445 Color colorGridItemDivider01;
1446 Color colorGridItemDivider02;
1448 GET_COLOR_CONFIG(CONTEXTMENU::GRID_ITEM_DIVIDER_01_NORMAL, colorGridItemDivider01);
1449 GET_COLOR_CONFIG(CONTEXTMENU::GRID_ITEM_DIVIDER_02_NORMAL, colorGridItemDivider02);
1451 if (drawVLine == true)
1453 pCanvas->SetForegroundColor(colorGridItemDivider01);
1454 pCanvas->DrawLine(point1, point2);
1459 pCanvas->SetForegroundColor(colorGridItemDivider02);
1460 pCanvas->DrawLine(point1, point2);
1464 pCanvas->SetForegroundColor(colorGridItemDivider01);
1465 pCanvas->DrawLine(point1, point2);
1470 pCanvas->SetForegroundColor(colorGridItemDivider02);
1471 pCanvas->DrawLine(point1, point2);
1477 _UiTouchEventDelivery
1478 _ContextMenuGridPresenter::OnPreviewTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
1480 return _UI_TOUCH_EVENT_DELIVERY_FORCED_YES;
1484 _ContextMenuGridPresenter::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
1486 FloatPoint touchPosition = touchinfo.GetCurrentPosition();
1487 FloatRectangle itemRect = __pContextMenu->GetItemRect();
1489 if (itemRect.Contains(touchPosition) == false)
1491 __selectedIndex = -1;
1492 __pressedIndex = -1;
1493 __touchOutRect = true;
1498 __selectedIndex = GetItemIndexFromPosition(touchPosition);
1499 __pressedIndex = __selectedIndex;
1500 __touchOutRect = false;
1506 _UiTouchEventDelivery
1507 _ContextMenuGridPresenter::OnPreviewTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
1509 return _UI_TOUCH_EVENT_DELIVERY_FORCED_YES;
1513 _ContextMenuGridPresenter::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
1515 FloatPoint touchPosition = touchinfo.GetCurrentPosition();
1517 if (__touchOutRect == true)
1519 __pContextMenu->SetFocused(false);
1520 __pContextMenu->SetVisibleState(false);
1523 int currentSelectedIndex = GetItemIndexFromPosition(touchPosition);
1524 if (__selectedIndex != -1 && (__selectedIndex == currentSelectedIndex))
1526 _ActionEvent* pActionEvent = __pContextMenu->GetActionEvent();
1528 if (pActionEvent == null)
1530 __pContextMenu->SetFocused(false);
1531 __pContextMenu->SetVisibleState(false);
1535 _ContextMenuItem* pItem = null;
1536 pItem = __pModel->GetItem(__selectedIndex);
1540 __selectedIndex = -1;
1541 __pressedIndex = -1;
1542 __focusedIndex = -1;
1543 __pContextMenu->SetFocused(false);
1544 __pContextMenu->SetVisibleState(false);
1548 __selectedIndex = -1;
1549 __pressedIndex = -1;
1550 __focusedIndex = -1;
1552 int actionId = pItem->GetActionId();
1554 IEventArg* pEventArg = _ActionEvent::CreateActionEventArgN(actionId);
1556 if (pEventArg == null)
1558 __pContextMenu->SetFocused(false);
1559 __pContextMenu->SetVisibleState(false);
1563 PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_TAP, __pContextMenu);
1564 __pContextMenu->SetFocused(false);
1565 __pContextMenu->SetVisibleState(false);
1566 pActionEvent->Fire(*pEventArg);
1572 _UiTouchEventDelivery
1573 _ContextMenuGridPresenter::OnPreviewTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
1575 return _UI_TOUCH_EVENT_DELIVERY_FORCED_YES;
1579 _ContextMenuGridPresenter::OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
1581 __selectedIndex = -1;
1582 __pressedIndex = -1;
1587 _UiTouchEventDelivery
1588 _ContextMenuGridPresenter::OnPreviewTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
1590 return _UI_TOUCH_EVENT_DELIVERY_FORCED_YES;
1594 _ContextMenuGridPresenter::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
1596 FloatPoint touchPosition = touchinfo.GetCurrentPosition();
1598 if (__selectedIndex != -1)
1600 _ContextMenuItem* pItem = __pModel->GetItem(__selectedIndex);
1604 __selectedIndex = -1;
1605 __pressedIndex = -1;
1609 FloatRectangle drawRect = pItem->GetDrawRect();
1610 if (drawRect.Contains(touchPosition) == false)
1612 __selectedIndex = -1;
1616 else if (__pressedIndex != -1)
1618 _ContextMenuItem* pItem = __pModel->GetItem(__pressedIndex);
1621 FloatRectangle drawRect = pItem->GetDrawRect();
1622 if(drawRect.Contains(touchPosition))
1624 __selectedIndex = __pressedIndex;
1634 _ContextMenuGridPresenter::OnKeyPressed(const _Control& source, const _KeyInfo& keyInfo)
1636 _KeyCode keyCode = keyInfo.GetKeyCode();
1644 if (__enterKeyPressed)
1646 __enterKeyPressed = false;
1647 __selectedIndex = -1;
1650 if (--__focusedIndex < 0)
1655 _ContextMenuItem* pItem = __pModel->GetItem(__focusedIndex);
1658 __focusedIndex = -1;
1661 pItem->SetFocused(true);
1670 if (__enterKeyPressed)
1672 __enterKeyPressed = false;
1673 __selectedIndex = -1;
1676 _ContextMenuItem* pItem = __pModel->GetItem(++__focusedIndex);
1682 pItem->SetFocused(true);
1689 __enterKeyPressed = true;
1691 if (__focusedIndex == -1)
1696 __selectedIndex = __focusedIndex;
1697 _ContextMenuItem* pItem = __pModel->GetItem(__focusedIndex);
1700 pItem->SetFocused(true);
1706 case _KEY_BACKSPACE:
1708 _ContextMenuItem* pItem = __pModel->GetItem(__focusedIndex);
1711 pItem->SetFocused(false);
1714 __enterKeyPressed = false;
1715 __backKeyPressed = false;
1716 __pressedIndex = -1;
1717 __selectedIndex = -1;
1718 __focusedIndex = -1;
1720 __pContextMenu->SetFocused(false);
1721 __pContextMenu->SetVisibleState(false);
1729 case _KEY_CONTEXT_MENU:
1732 __backKeyPressed = true;
1742 _ContextMenuGridPresenter::OnKeyReleased(const _Control& source, const _KeyInfo& keyInfo)
1744 _KeyCode keyCode = keyInfo.GetKeyCode();
1756 case _KEY_BACKSPACE:
1760 if (!__enterKeyPressed)
1765 __enterKeyPressed = false;
1766 __backKeyPressed = false;
1768 _ContextMenuItem* pItem = __pModel->GetItem(__selectedIndex);
1771 __selectedIndex = -1;
1772 __pressedIndex = -1;
1773 __focusedIndex = -1;
1774 __pContextMenu->SetFocused(false);
1775 __pContextMenu->SetVisibleState(false);
1780 int actionId = pItem->GetActionId();
1782 _ActionEvent* pActionEvent = __pContextMenu->GetActionEvent();
1783 if (pActionEvent == null)
1788 IEventArg* pEventArg = _ActionEvent::CreateActionEventArgN(actionId);
1789 if (pEventArg == null)
1794 pActionEvent->Fire(*pEventArg);
1796 __selectedIndex = -1;
1797 __pressedIndex = -1;
1798 __focusedIndex = -1;
1799 pItem->SetFocused(false);
1800 __pContextMenu->SetFocused(false);
1801 __pContextMenu->SetVisibleState(false);
1809 case _KEY_CONTEXT_MENU:
1813 if (!__backKeyPressed)
1818 _ContextMenuItem* pItem = __pModel->GetItem(__focusedIndex);
1821 pItem->SetFocused(false);
1824 __enterKeyPressed = false;
1825 __backKeyPressed = false;
1826 __selectedIndex = -1;
1827 __pressedIndex = -1;
1828 __focusedIndex = -1;
1829 __pContextMenu->SetFocused(false);
1830 __pContextMenu->SetVisibleState(false);
1842 _ContextMenuGridPresenter::IsChildControlFocusManage(void) const
1848 _ContextMenuGridPresenter::OnDrawFocus(void)
1850 if (__focusedIndex == -1)
1854 __selectedIndex = -1;
1860 _ContextMenuGridPresenter::OnFocusModeStateChanged(void)
1862 __focusedIndex = -1;
1867 _ContextMenuGridPresenter::OnFontChanged(Font* pFont)
1873 _ContextMenuGridPresenter::OnFontInfoRequested(unsigned long& style, float& size)
1875 style = FONT_STYLE_PLAIN;
1876 size = __itemFontSize;
1880 _ContextMenuGridPresenter::SetAllAccessibilityElement(void)
1882 _AccessibilityContainer* pContainer = __pContextMenu->GetAccessibilityContainer();
1883 if (pContainer != null)
1885 _AccessibilityElement* pElementContextMenu = new (std::nothrow) _AccessibilityElement(true);
1886 SysTryReturnVoidResult(NID_UI_CTRL, pElementContextMenu, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
1888 pElementContextMenu->SetSupportOperatingGesture(false);
1889 pElementContextMenu->SetTraitWithStringId("IDS_TPLATFORM_BODY_CONTEXTUAL_POP_UP_T_TTS");
1890 pElementContextMenu->SetHint(L"double tap to close");
1891 pElementContextMenu->SetBounds(FloatRectangle(0.0f, 0.0f, __pContextMenu->GetBoundsF().width, __pContextMenu->GetBoundsF().height));
1892 pContainer->AddElement(*pElementContextMenu);
1893 __pContextMenu->AddAccessibilityElement(*pElementContextMenu);
1895 int itemCount = __pModel->GetItemCount();
1896 for (int i = 0; i < itemCount; i++)
1898 _ContextMenuItem* pItem = __pModel->GetItem(i);
1899 _AccessibilityElement* pElement = new (std::nothrow) _AccessibilityElement(true);
1900 if (pItem != null && pElement != null)
1902 pElement->SetName(L"ContextMenuItem" + Integer::ToString(i));
1903 if (pItem->GetType() == CONTEXT_MENU_ITEM_DRAWING_TYPE_BITMAP)
1905 pElement->SetLabel(L"icon");
1909 pElement->SetLabel(pItem->GetText());
1912 pElement->SetTraitWithStringId("IDS_TPLATFORM_BODY_CONTEXTUAL_POP_UP_T_TTS");
1913 pElement->SetBounds(pItem->GetDrawRect());
1914 pContainer->AddElement(*pElement);
1915 __pContextMenu->AddAccessibilityElement(*pElement);
1926 _ContextMenuItemInfo
1927 _ContextMenuGridPresenter::GetItemFromPosition(const FloatPoint& position)
1929 _ContextMenuItemInfo itemInfo;
1930 int index = GetItemIndexFromPosition(position);
1931 itemInfo.pContextMenuItem = __pModel->GetItem(index);
1933 itemInfo.bListItem = false;
1934 itemInfo.pListItem = null;
1938 _ContextMenuItemInfo
1939 _ContextMenuGridPresenter::FindItem(int index)
1941 _ContextMenuItemInfo itemInfo;
1942 itemInfo.bListItem = false;
1943 itemInfo.pListItem = null;
1944 itemInfo.pContextMenuItem = __pModel->GetItem(index);
1949 _ContextMenuGridPresenter::SetTopDrawnItemIndex(int index)
1955 _ContextMenuGridPresenter::DrawBitmap(Tizen::Graphics::Canvas& canvas, const Tizen::Graphics::FloatRectangle& bounds, const Tizen::Graphics::Bitmap& bitmap)
1957 result r = E_SUCCESS;
1958 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(bitmap))
1960 r = canvas.DrawNinePatchedBitmap(bounds, bitmap);
1961 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Fail to draw ninepatched bitmap.")
1965 r = canvas.DrawBitmap(bounds, bitmap);
1966 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Fail to draw bitmap.")
1972 }}} // Tizen::Ui: Control