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.
19 * @file FUiCtrl_OptionMenuListPresenter.cpp
20 * @brief This is the implementation file for the _OptionMenuPresenter class.
23 #include <FBaseErrorDefine.h>
24 #include <FBaseSysLog.h>
25 #include <FGrp_BitmapImpl.h>
26 #include <FGrp_CanvasImpl.h>
27 #include <FGrp_TextTextSimple.h>
28 #include "FUi_AccessibilityContainer.h"
29 #include "FUi_AccessibilityElement.h"
30 #include "FUi_CoordinateSystemUtils.h"
32 #include "FUi_ResourceManager.h"
33 #include "FUiCtrl_ActionEvent.h"
34 #include "FUiCtrl_IActionEventListener.h"
36 #include "FUiCtrl_OptionMenuPresenter.h"
38 using namespace Tizen::Graphics;
39 using namespace Tizen::Ui;
40 using namespace Tizen::Base;
41 using namespace Tizen::Base::Runtime;
42 using namespace Tizen::Graphics::_Text;
45 static const float TOUCH_PRESS_THRESHOLD_INSENSITIVE = 0.16f;
46 static const int OPTION_MENU_LIST_ELEMENT_TEXT = 0;
47 static const int OPTION_MENU_LIST_ELEMENT_BITMAP = 1;
50 namespace Tizen { namespace Ui { namespace Controls
53 _OptionMenuPresenter::_OptionMenuPresenter(_OptionMenu* pOptionMenu)
54 : __pOptionMenu(pOptionMenu)
57 , __layoutSize(FloatDimension(0.0f, 0.0f))
58 , __touchOutRect(false)
60 , __scrollEnable(false)
64 , __bottomMargin(0.0f)
68 , __itemMinWidth(0.0f)
70 , __itemMaxWidth(0.0f)
72 , __itemBitmapWidth(0.0f)
73 , __itemBitmapHeight(0.0f)
74 , __itemFontSize(0.0f)
75 , __dividerHeight(0.0f)
81 _OptionMenuPresenter::~_OptionMenuPresenter(void)
93 _OptionMenuPresenter::Install(void)
99 __pModel = new (std::nothrow) _OptionMenuModel;
100 SysTryCatch(NID_UI_CTRL, __pModel != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
102 r = __pModel->Construct();
103 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
105 __pFont = __pOptionMenu->GetFallbackFont();
107 SysTryCatch(NID_UI_CTRL, (__pFont != null), , r, "[%s] Propagating.", GetErrorMessage(r));
121 _OptionMenuPresenter::LoadShape(void)
123 GET_SHAPE_CONFIG(OPTIONMENU::LIST_MIN_WIDTH, _CONTROL_ORIENTATION_PORTRAIT, __itemMinWidth);
124 GET_SHAPE_CONFIG(OPTIONMENU::LIST_MAX_WIDTH, _CONTROL_ORIENTATION_PORTRAIT, __itemMaxWidth);
125 GET_SHAPE_CONFIG(OPTIONMENU::LIST_ITEM_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, __itemHeight);
126 GET_SHAPE_CONFIG(OPTIONMENU::LIST_ITEM_GAP, _CONTROL_ORIENTATION_PORTRAIT, __itemGap);
128 GET_SHAPE_CONFIG(OPTIONMENU::LIST_TOP_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, __topMargin);
129 GET_SHAPE_CONFIG(OPTIONMENU::LIST_BOTTOM_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, __bottomMargin);
130 GET_SHAPE_CONFIG(OPTIONMENU::LIST_LEFT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, __leftMargin);
131 GET_SHAPE_CONFIG(OPTIONMENU::LIST_RIGHT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, __rightMargin);
133 GET_SHAPE_CONFIG(OPTIONMENU::LIST_ICON_WIDTH, _CONTROL_ORIENTATION_PORTRAIT, __itemBitmapWidth);
134 GET_SHAPE_CONFIG(OPTIONMENU::LIST_ICON_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, __itemBitmapHeight);
136 GET_SHAPE_CONFIG(OPTIONMENU::LIST_ITEM_FONT_SIZE, _CONTROL_ORIENTATION_PORTRAIT, __itemFontSize);
137 GET_SHAPE_CONFIG(OPTIONMENU::LIST_DIVIDER_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, __dividerHeight);
139 __itemWidth = __itemMinWidth;
143 _OptionMenuPresenter::CreateItem(const String& text, int actionId, const Bitmap* pNormalBitmap, const Bitmap* pPressedBitmap, const Bitmap* pHighlightedBitmap, bool isSubItem)
145 _OptionMenuItem* pItem = _OptionMenuItem::CreateOptionMenuItemN();
146 SysTryReturn(NID_UI_CTRL, pItem != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
148 OptionMenuItemDrawingType itemType = OPTION_MENU_ITEM_DRAWING_TYPE_TEXT;
149 _Label* pLabel = null;
150 result r = E_SUCCESS;
153 pLabel = _Label::CreateLabelN();
154 if (GetLastResult() != E_SUCCESS)
160 pLabel->SetBackgroundBitmap(*pNormalBitmap);
161 pLabel->SetBackgroundColor(Color(0, 0, 0, 0));
163 int bitmapY = (__itemHeight - __itemBitmapHeight ) / 2;
164 pLabel->SetBounds(FloatRectangle(__leftMargin, bitmapY, __itemBitmapWidth, __itemBitmapHeight));
165 pLabel->SetTouchPressThreshold(TOUCH_PRESS_THRESHOLD_INSENSITIVE);
166 pItem->AttachChild(*pLabel);
167 pItem->SetBitmapLabel(pLabel);
169 _AccessibilityContainer* pContainer = pLabel->GetAccessibilityContainer();
172 pContainer->Activate(false);
175 if (pNormalBitmap != null)
177 r = pItem->SetBitmap(OPTION_MENU_ITEM_DRAWING_STATUS_NORMAL, pNormalBitmap);
184 itemType = OPTION_MENU_ITEM_DRAWING_TYPE_BITMAP;
187 if (pPressedBitmap != null)
189 r = pItem->SetBitmap(OPTION_MENU_ITEM_DRAWING_STATUS_PRESSED, pPressedBitmap);
197 if (pHighlightedBitmap != null)
199 r = pItem->SetBitmap(OPTION_MENU_ITEM_DRAWING_STATUS_HIGHLIGHTED, pHighlightedBitmap);
207 pItem->SetType(itemType);
208 pItem->SetActionId(actionId);
210 pItem->SetTextSize(__itemFontSize);
211 r = pItem->SetText(text);
218 // calculate item size
219 float bitmapWidth = 0.0f;
221 if (itemType == OPTION_MENU_ITEM_DRAWING_TYPE_BITMAP)
223 bitmapWidth = __itemBitmapWidth;
226 FloatDimension textArea(0.0f, 0.0f);
227 FloatDimension itemSize(0.0f, 0.0f);
229 CalculateItemSize(text, itemType, textArea, itemSize);
231 float labelLeftMargin = 0.0f;
232 GET_SHAPE_CONFIG(LABEL::LEFT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, labelLeftMargin);
233 pItem->SetSize(itemSize);
236 float textLabelX = labelLeftMargin + bitmapWidth;
238 pLabel = _Label::CreateLabelN();
239 if (GetLastResult() != E_SUCCESS)
245 pLabel->SetText(text);
246 OptionMenuCoreItemStatus itemStatus = OPTION_MENU_CORE_ITEM_STATUS_NORMAL;
247 pLabel->SetTextColor(__pOptionMenu->GetTextColor(itemStatus));
248 pLabel->SetBackgroundColor(Color(0, 0, 0, 0));
250 itemSize = pItem->GetSize();
251 pLabel->SetBounds(FloatRectangle(textLabelX, (itemSize.height - textArea.height) / 2.0f, textArea.width, textArea.height));
252 pLabel->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
253 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
254 pLabel->SetTextConfig(__itemFontSize, LABEL_TEXT_STYLE_NORMAL);
256 pLabel->SetTouchPressThreshold(TOUCH_PRESS_THRESHOLD_INSENSITIVE);
257 pItem->AttachChild(*pLabel);
259 pContainer = pLabel->GetAccessibilityContainer();
263 pContainer->Activate(false);
265 pItem->SetTextLabel(pLabel);
269 __itemWidth = __itemWidth < itemSize.width ? itemSize.width : __itemWidth;
272 pItem->SetTouchPressThreshold(TOUCH_PRESS_THRESHOLD_INSENSITIVE);
277 _OptionMenuPresenter::CalculateItemSize(const String &text, OptionMenuItemDrawingType itemType, FloatDimension &textArea, FloatDimension &itemSize)
279 float labelLeftMargin = 0.0f;
280 float labelTopMargin = 0.0f;
281 __pFont->GetTextExtent(text, text.GetLength(), textArea);
283 GET_SHAPE_CONFIG(LABEL::LEFT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, labelLeftMargin);
284 GET_SHAPE_CONFIG(LABEL::TOP_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, labelTopMargin);
286 textArea.width += 2.0f * labelLeftMargin;
287 textArea.height += 2.0f * labelTopMargin;
288 itemSize.height = __itemHeight + (__dividerHeight * 2.0f);
289 itemSize.width = __leftMargin + textArea.width + __rightMargin;
291 if (itemType == OPTION_MENU_ITEM_DRAWING_TYPE_BITMAP)
293 itemSize.width = itemSize.width + __itemBitmapWidth;
296 itemSize.width = itemSize.width < __itemMinWidth ? __itemMinWidth : itemSize.width;
298 if (itemSize.width > __itemMaxWidth)
300 textArea.width -= itemSize.width - __itemMaxWidth;
301 itemSize.width = __itemMaxWidth;
306 _OptionMenuPresenter::AddItem(const String& text, int actionId, const Bitmap* normalBitmap, const Bitmap* pPressedBitmap, const Bitmap* pHighlightedBitmap)
308 _OptionMenuItem* pItem = CreateItem(text, actionId, normalBitmap, pPressedBitmap, pHighlightedBitmap);
309 SysTryReturn(NID_UI_CTRL, pItem != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "Memory allocation failed.");
311 result r = __pModel->AddItem(pItem);
316 SysTryReturn(NID_UI_CTRL, false, r, r, "Failed to add item.");
323 _OptionMenuPresenter::AddSubItem(int mainIndex, const String& text, int actionId)
325 SysTryReturn(NID_UI_CTRL, mainIndex >=0 && mainIndex < __pModel->GetItemCount(), E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid mainIndex %d.", mainIndex);
327 _OptionMenuItem* pItem = CreateItem(text, actionId, null, null, null, true);
328 SysTryReturn(NID_UI_CTRL, pItem != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "Memory allocation failed.");
330 result r = __pModel->AddItem(pItem, mainIndex);
335 SysTryReturn(NID_UI_CTRL, false, r, r, "Failed to add item.");
342 _OptionMenuPresenter::GetItemIndexFromActionId(int actionId) const
344 return __pModel->GetItemIndexFromActionId(actionId);
348 _OptionMenuPresenter::GetItemActionIdAt(int mainIndex) const
350 _OptionMenuItem* pItem = __pModel->GetItem(mainIndex);
356 return pItem->GetActionId();
360 _OptionMenuPresenter::InsertItem(int mainIndex, const String& text, int actionId, const Bitmap* normalBitmap,
361 const Bitmap* pPressedBitmap, const Bitmap* pHighlightedBitmap)
363 _OptionMenuItem* pItem = CreateItem(text, actionId, normalBitmap, pPressedBitmap, pHighlightedBitmap);
364 SysTryReturn(NID_UI_CTRL, pItem != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "Memory allocation failed.");
366 result r = __pModel->InsertItemAt(pItem, mainIndex);
370 SysTryReturn(NID_UI_CTRL, false, r, r, "Failed to add item.");
377 _OptionMenuPresenter::InsertSubItemAt(int mainIndex, int subIndex, const String& text, int actionId)
379 SysTryReturn(NID_UI_CTRL, mainIndex >=0 && mainIndex < __pModel->GetItemCount(), E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid mainIndex %d.", mainIndex);
380 SysTryReturn(NID_UI_CTRL, subIndex >=0 && subIndex <= __pModel->GetSubItemCount(mainIndex), E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid subIndex %d.", subIndex);
382 _OptionMenuItem* pItem = CreateItem(text, actionId, null, null, null, true);
383 SysTryReturn(NID_UI_CTRL, pItem != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "Memory allocation failed.");
385 result r = __pModel->InsertItemAt(pItem, mainIndex, subIndex);
386 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
392 _OptionMenuPresenter::SetSubItemAt(int mainIndex, int subIndex, const String& text, int actionId)
394 SysTryReturn(NID_UI_CTRL, mainIndex >=0 && mainIndex < __pModel->GetItemCount(), E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid mainIndex %d.", mainIndex);
395 SysTryReturn(NID_UI_CTRL, subIndex >=0 && subIndex < __pModel->GetSubItemCount(mainIndex), E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid subIndex %d.", subIndex);
397 result r = __pModel->SetItemAt(mainIndex, text, actionId, null, null, null, __itemFontSize, subIndex);
398 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
404 _OptionMenuPresenter::RemoveSubItemAt(int mainIndex, int subIndex)
406 SysTryReturn(NID_UI_CTRL, mainIndex >=0 && mainIndex < __pModel->GetItemCount(), E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid mainIndex %d.", mainIndex);
407 SysTryReturn(NID_UI_CTRL, subIndex >=0 && subIndex < __pModel->GetSubItemCount(mainIndex), E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid subIndex %d.", subIndex);
409 result r = __pModel->RemoveItem(mainIndex, subIndex);
410 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
416 _OptionMenuPresenter::GetSubItemCount(int mainIndex) const
418 SysTryReturn(NID_UI_CTRL, mainIndex >=0 && mainIndex < __pModel->GetItemCount(), -1, E_INVALID_ARG, "[E_INVALID_ARG] Invalid mainIndex %d.", mainIndex);
419 return __pModel->GetSubItemCount(mainIndex);
423 _OptionMenuPresenter::GetSubItemIndexFromActionId(int actionId) const
426 return __pModel->GetSubItemIndexFromActionId(actionId, mainIndex);
430 _OptionMenuPresenter::GetSubItemActionIdAt(int mainIndex, int subIndex) const
432 _OptionMenuItem* pItem = __pModel->GetItem(mainIndex, subIndex);
438 return pItem->GetActionId();
442 _OptionMenuPresenter::CalculateItemMaximumWidth(void)
444 FloatDimension itemSize(0.0f, 0.0f);
445 FloatDimension textArea(0.0f, 0.0f);
446 float maxItemWidth = 0.0f;
448 for (int i = 0; i < __pModel->GetItemCount() - 1; i++)
450 _OptionMenuItem* pItem = null;
452 pItem = __pModel->GetItem(i);
453 SysTryReturn(NID_UI_CTRL, pItem != null, , E_SYSTEM, "[E_SYSTEM] A system error occurred. Unable to get the item.");
455 CalculateItemSize(pItem->GetText(), pItem->GetType(), textArea, itemSize);
457 if (maxItemWidth < itemSize.width)
459 maxItemWidth = itemSize.width;
463 __itemWidth = maxItemWidth;
467 _OptionMenuPresenter::SetItem(int index, const String& text, int actionId, const Bitmap* normalBitmap, const Bitmap* pPressedBitmap, const Bitmap* pHighlightedBitmap)
469 SysTryReturn(NID_UI_CTRL, index >=0 && index < __pModel->GetItemCount(), E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid mainIndex %d.", index);
471 result r = __pModel->SetItemAt(index, text, actionId, normalBitmap, pPressedBitmap, pHighlightedBitmap, __itemFontSize);
472 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
474 _OptionMenuItem* pItem = __pModel->GetItem(index);
478 SysLog(NID_UI_CTRL, "Item is null.");
482 CalculateItemMaximumWidth();
488 _OptionMenuPresenter::DeleteItem(int index)
490 SysTryReturn(NID_UI_CTRL, (index < __pOptionMenu->GetItemCount()), E_INVALID_ARG, E_INVALID_ARG,
491 "[E_INVALID_ARG] The specified main index (%d) is invalid.", index);
493 result r = __pOptionMenu->GetScrollPanel()->DetachChild(*__pModel->GetItem(index));
494 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to detach item.");
496 r = __pModel->RemoveItem(index);
497 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to delete item.");
499 CalculateItemMaximumWidth();
505 _OptionMenuPresenter::DeleteItemAll(void)
507 SysTryReturn(NID_UI_CTRL, (__pOptionMenu->GetItemCount() > 0), E_SYSTEM, E_SYSTEM,
508 "[E_SYSTEM] A system error occurred. No items exists.");
510 __pOptionMenu->GetScrollPanel()->DetachAllChildren();
512 result r = __pModel->RemoveAllItem();
513 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to delete item all.");
519 _OptionMenuPresenter::CalculateWindowRect(void)
521 result r = CalculateRect();
522 AdjustItemPosition();
528 _OptionMenuPresenter::ApplyColorProperty(void)
534 _OptionMenuPresenter::CalculateRect(void)
536 FloatRectangle windowRect = FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f); // OptionMenu window itself
537 FloatRectangle bodyRect = FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f); // bg surronding showing items, relative to window
538 FloatRectangle itemRect = FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f); // relative to window
540 float bodyTopMargin = __topMargin;
541 float bodyBottomMargin = __bottomMargin;
542 float bodyLeftMargin = __leftMargin;
543 float bodyRightMargin = __rightMargin;
545 FloatDimension screen = _ControlManager::GetInstance()->GetScreenSizeF();
546 _ControlRotation rotation = _ControlManager::GetInstance()->GetScreenRotation();
548 if (__pOptionMenu->GetLayout() == _CONTROL_ORIENTATION_LANDSCAPE)
550 screen.SetSize(screen.height, screen.width);
555 bodyRect.width = __layoutSize.width + bodyLeftMargin + bodyRightMargin;
556 bodyRect.height = __layoutSize.height + bodyTopMargin + bodyBottomMargin;
558 if (rotation == _CONTROL_ROTATION_270 && __pOptionMenu->GetLayout() == _CONTROL_ORIENTATION_LANDSCAPE)
560 bodyRect.x = screen.width - bodyRect.width;
563 bodyRect.y = screen.height - bodyRect.height;
565 windowRect.x = bodyRect.x ;
566 windowRect.y = bodyRect.y;
567 windowRect.width = bodyRect.width ;
568 windowRect.height = bodyRect.height;
573 itemRect.x = bodyRect.x + bodyLeftMargin;
574 itemRect.y = bodyRect.y + bodyTopMargin;
575 itemRect.width = __layoutSize.width;
576 itemRect.height = __layoutSize.height;
578 __pOptionMenu->SetWindowRect(windowRect);
579 __pOptionMenu->SetBodyRect(bodyRect);
580 __pOptionMenu->SetItemRect(itemRect);
582 // _ScrollPanel API call sequence: SetBounds() -> SetScrollAreaBounds()
583 // _Scroll visual interaction if Bounds < ScrollAreaBounds
584 if (__pOptionMenu->IsVisible())
586 __pOptionMenu->GetScrollPanel()->SetBounds(FloatRectangle(bodyRect.x + bodyLeftMargin, bodyRect.y + bodyTopMargin, __layoutSize.width, __layoutSize.height));
587 int itemCount = __pModel->GetItemCount();
588 float itemHeight = __itemHeight + (__dividerHeight * 2.0f);
589 float layoutClientHeight = itemCount * itemHeight - (__dividerHeight * 2.0f);
590 __pOptionMenu->GetScrollPanel()->SetClientAreaHeight(layoutClientHeight);
593 __pOptionMenu->SetMovable(true);
594 __pOptionMenu->SetResizable(true);
596 __pOptionMenu->SetBounds(windowRect);
598 __pOptionMenu->SetMovable(false);
599 __pOptionMenu->SetResizable(false);
605 _OptionMenuPresenter::AdjustItemLayout(void)
607 FloatDimension layoutSize(0.0f, 0.0f);
609 int itemCount = __pModel->GetItemCount();
613 __layoutSize.width = __itemWidth;
614 __layoutSize.height = __itemHeight;
618 layoutSize = AdjustItemLayoutStyle();
620 FloatDimension screen = _ControlManager::GetInstance()->GetScreenSizeF();
621 if (__pOptionMenu->GetLayout() == _CONTROL_ORIENTATION_LANDSCAPE)
623 screen.SetSize(screen.height, screen.width);
626 int maxHeight = screen.height;
627 if (layoutSize.height > maxHeight)
629 layoutSize.height = maxHeight;
632 __layoutSize = layoutSize;
636 _OptionMenuPresenter::AdjustItemLayoutStyle(void)
638 int itemMaxCount = __pOptionMenu->GetMaximumVisibleItemsCount();
640 int itemCount = __pModel->GetItemCount();
641 float itemHeight = __itemHeight + (__dividerHeight * 2.0f);
643 FloatDimension layoutSize(__itemWidth, 0.0f);
645 float layoutClientHeight = itemCount * itemHeight - (__dividerHeight * 2.0f);
646 float layoutMaxHeight = itemMaxCount * itemHeight - (__dividerHeight * 2.0f);
647 if (layoutClientHeight > layoutMaxHeight)
649 __scrollEnable = true;
650 layoutSize.height = layoutMaxHeight + itemHeight / 2;
654 __scrollEnable = false;
655 layoutSize.height = layoutClientHeight;
662 _OptionMenuPresenter::AdjustItemPosition(void)
664 int itemCount = __pModel->GetItemCount();
670 float itemHeight = __itemHeight + (__dividerHeight * 2.0f);
671 float drawItemY = 0.0f;
673 float x = __pOptionMenu->GetBodyRect().x + __leftMargin;
674 float y = __pOptionMenu->GetBodyRect().y + __topMargin;
676 _OptionMenuItem* pItem = null;
678 for (int i = 0; i < itemCount; i++)
680 pItem = __pModel->GetItem(i);
687 FloatRectangle drawRect(x, drawItemY + y, __itemWidth, itemHeight);
689 pItem->SetDrawRect(drawRect);
690 pItem->SetUpperDivider(i > 0);
691 pItem->SetLowerDivider(i < itemCount - 1);
692 pItem->SetParentScrollEnable(__scrollEnable);
693 pItem->SetBounds(FloatRectangle(0.0f, drawItemY, drawRect.width, drawRect.height));
695 if (pItem->HasParent() == false)
697 __pOptionMenu->GetScrollPanel()->AttachChild(*pItem);
700 drawItemY += itemHeight;
705 _OptionMenuPresenter::GetItemIndexFromPosition(const FloatPoint& point) const
708 int itemCount = __pModel->GetItemCount();
715 _OptionMenuItem* pItem = null;
717 float scrollPosition = __pOptionMenu->GetScrollPanel()->GetScrollPosition();
718 FloatPoint position(point.x, point.y + scrollPosition);
720 for (int i = 0; i < itemCount; i++)
722 pItem = __pModel->GetItem(i);
729 FloatRectangle drawRect = pItem->GetDrawRect();
731 if (drawRect.Contains(position) == true)
742 _OptionMenuPresenter::Draw(void)
744 result r = E_SUCCESS;
746 Canvas* pCanvas = __pOptionMenu->GetCanvasN();
747 SysTryReturn(NID_UI_CTRL, pCanvas != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "Memory allocation failed.");
749 // Clear canvas for drawing area of the OptionMenu.
750 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
751 FloatRectangle bounds(__pOptionMenu->GetWindowRect());
752 pCanvas->Clear(FloatRectangle(0.0f, 0.0f, bounds.width, bounds.height));
754 r = DrawBackground(pCanvas);
757 SysLog(NID_UI_CTRL, "[%s] Failed to draw background.", GetErrorMessage(r));
765 _OptionMenuPresenter::DrawFocus(int index)
768 result r = E_SUCCESS;
771 _OptionMenuItem* pItem = __pModel->GetItem(index);
774 pItem->SetHighlighted(true);
775 pItem->Invalidate(true);
777 __focusedIndex = index;
784 _OptionMenuPresenter::ClearFocus(void)
786 _OptionMenuItem* pPreviousItem;
787 if (__focusedIndex != -1)
789 pPreviousItem = __pModel->GetItem(__focusedIndex);
790 if (pPreviousItem != null)
792 pPreviousItem->SetHighlighted(false);
793 pPreviousItem->RemoveFocusRing();
794 pPreviousItem->Invalidate(true);
800 _OptionMenuPresenter::OnEnterKeyReleased(int selectedIndex)
802 _OptionMenuItem* pItem = null;
803 pItem = __pModel->GetItem(selectedIndex);
804 __selectedIndex = -1;
809 if (pItem->HasSubItem() == true)
812 __pOptionMenu->ShowSubMenu(selectedIndex, *pItem);
817 __pOptionMenu->Close();
818 __pOptionMenu->FireActionEvent(pItem->GetActionId());
825 _OptionMenuPresenter::DrawBackground(Canvas* pCanvas)
827 SysTryReturn(NID_UI_CTRL, pCanvas != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
829 result r = E_SUCCESS;
831 FloatRectangle bodyRect = __pOptionMenu->GetBodyRect();
833 const Bitmap* pBackgroundNormalBitmap = __pOptionMenu->GetBackgroundNormalBitmap();
834 const Bitmap* pBackgroundEffectBitmap = __pOptionMenu->GetBackgroundEffectBitmap();
836 if (pBackgroundNormalBitmap == null && pBackgroundEffectBitmap == null)
838 pCanvas->SetForegroundColor(__pOptionMenu->GetColor());
839 pCanvas->DrawRectangle(bodyRect);
843 if (pBackgroundNormalBitmap != null)
845 r = DrawBitmap(*pCanvas, bodyRect, *pBackgroundNormalBitmap);
848 if (pBackgroundEffectBitmap != null)
850 r = DrawBitmap(*pCanvas, bodyRect, *pBackgroundEffectBitmap);
857 _UiTouchEventDelivery
858 _OptionMenuPresenter::OnPreviewTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
860 return _UI_TOUCH_EVENT_DELIVERY_FORCED_YES;
864 _OptionMenuPresenter::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
866 FloatPoint touchPosition = touchinfo.GetCurrentPosition();
867 FloatRectangle itemRect = __pOptionMenu->GetItemRect();
869 if (__pOptionMenu->IsSubMenuShown() == true)
871 __pOptionMenu->DestroySubMenu();
872 __pOptionMenu->SetTouchCapture(false, false);
876 if (!itemRect.Contains(touchPosition))
878 __selectedIndex = -1;
879 __touchOutRect = true;
883 __selectedIndex = GetItemIndexFromPosition(touchPosition);
884 __touchOutRect = false;
888 _UiTouchEventDelivery
889 _OptionMenuPresenter::OnPreviewTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
891 return _UI_TOUCH_EVENT_DELIVERY_FORCED_YES;
895 _OptionMenuPresenter::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
897 FloatPoint touchPosition = touchinfo.GetCurrentPosition();
901 FloatRectangle itemRect = __pOptionMenu->GetItemRect();
902 if (!itemRect.Contains(touchPosition))
904 __selectedIndex = -1;
905 __pOptionMenu->SetVisibleState(false);
911 __pOptionMenu->Invalidate(true);
913 int currentSelectedIndex = GetItemIndexFromPosition(touchPosition);
914 if (__selectedIndex != -1 && (__selectedIndex == currentSelectedIndex))
916 _OptionMenuItem* pItem = null;
917 pItem = __pModel->GetItem(__selectedIndex);
918 __selectedIndex = -1;
922 if (pItem->HasSubItem() == true)
925 __pOptionMenu->ShowSubMenu(__selectedIndex, *pItem);
931 __pOptionMenu->SetVisibleState(false);
932 PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_TAP, __pOptionMenu);
933 __pOptionMenu->FireActionEvent(pItem->GetActionId());
942 _UiTouchEventDelivery
943 _OptionMenuPresenter::OnPreviewTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
945 return _UI_TOUCH_EVENT_DELIVERY_FORCED_YES;
949 _OptionMenuPresenter::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
953 __selectedIndex = -1;
961 _OptionMenuPresenter::OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
963 __pModel->ResetAllItem();
968 _OptionMenuPresenter::ResetSelectedItem(void)
970 __pModel->ResetSelectedItem(__selectedIndex);
974 _OptionMenuPresenter::OnActionPerformed(const _Control& source, int actionId)
976 // for SubMenu Events
977 __pOptionMenu->DestroySubMenu();
978 __pOptionMenu->SetVisibleState(false);
979 __pOptionMenu->FireActionEvent(actionId);
983 _OptionMenuPresenter::OnFontChanged(Font* pFont)
986 String fontName = __pOptionMenu->GetFont();
988 int itemCount = __pModel->GetItemCount();
989 for (int i = 0; i < itemCount; i++)
991 _OptionMenuItem* pItem = __pModel->GetItem(i);
994 pItem->SetFont(fontName);
1000 _OptionMenuPresenter::OnFontInfoRequested(unsigned long& style, float& size)
1002 style = FONT_STYLE_PLAIN;
1003 size = __itemFontSize;
1007 _OptionMenuPresenter::SetAllAccessibilityElement(void)
1009 _AccessibilityContainer* pContainerOptionMenu = __pOptionMenu->GetAccessibilityContainer();
1010 if (pContainerOptionMenu != null)
1012 _AccessibilityElement* pElementOptionMenu = new (std::nothrow) _AccessibilityElement(true);
1013 SysTryReturnVoidResult(NID_UI_CTRL, pElementOptionMenu, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1015 pElementOptionMenu->SetSupportOperatingGesture(false);
1016 pElementOptionMenu->SetTrait(L"Optionual popup");
1017 pElementOptionMenu->SetHint(L"double tap to close");
1018 pElementOptionMenu->SetBounds(FloatRectangle(0.0f, 0.0f, __pOptionMenu->GetBoundsF().width, __pOptionMenu->GetBoundsF().height));
1019 pContainerOptionMenu->AddElement(*pElementOptionMenu);
1020 __pOptionMenu->AddAccessibilityElement(*pElementOptionMenu);
1022 int itemCount = __pModel->GetItemCount();
1023 for (int i = 0; i < itemCount; i++)
1025 _OptionMenuItem* pItem = __pModel->GetItem(i);
1028 _AccessibilityContainer* pContainer = pItem->GetAccessibilityContainer();
1029 if (pContainer != null)
1031 LinkedListT<_AccessibilityElement*> accessibilityElements;
1032 _AccessibilityElement* pElement = null;
1034 pContainer->GetElements(accessibilityElements);
1035 if (accessibilityElements.GetAt(0, pElement) == E_SUCCESS)
1037 pElement->SetName(L"OptionMenuItem" + Integer::ToString(i));
1038 if (pItem->GetType() == OPTION_MENU_ITEM_DRAWING_TYPE_BITMAP)
1040 pElement->SetLabel(L"icon " + pItem->GetText());
1044 pElement->SetLabel(pItem->GetText());
1047 pElement->SetBounds(FloatRectangle(0.0f, 0.0f, pItem->GetBoundsF().width, pItem->GetBoundsF().height));
1049 pContainerOptionMenu->AddChildContainer(*pContainer);
1057 _OptionMenuPresenter::GetItemFromPosition(const FloatPoint& position)
1059 _OptionMenuItemInfo itemInfo;
1060 int index = GetItemIndexFromPosition(position);
1061 itemInfo.pOptionMenuItem = __pModel->GetItem(index);
1063 itemInfo.bListItem = false;
1064 itemInfo.pListItem = null;
1069 _OptionMenuPresenter::FindItem(int index)
1071 _OptionMenuItemInfo itemInfo;
1072 itemInfo.bListItem = false;
1073 itemInfo.pListItem = null;
1074 itemInfo.pOptionMenuItem = __pModel->GetItem(index);
1079 _OptionMenuPresenter::SetTopDrawnItemIndex(int index)
1085 _OptionMenuPresenter::DrawBitmap(Canvas& canvas, const FloatRectangle& bounds, const Bitmap& bitmap)
1087 result r = E_SUCCESS;
1088 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(bitmap))
1090 r = canvas.DrawNinePatchedBitmap(bounds, bitmap);
1091 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Fail to draw ninepatched bitmap.");
1095 r = canvas.DrawBitmap(bounds, bitmap);
1096 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Fail to draw bitmap.");
1102 }}} // Tizen::Ui: Control