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_OptionMenuPresenter.cpp
19 * @brief This is the implementation file for the _OptionMenuPresenter class.
22 #include <FBaseErrorDefine.h>
24 #include <FBaseSysLog.h>
25 #include <FGrp_BitmapImpl.h>
26 #include <FGrp_TextCommon.h>
27 #include <FGrp_TextTextSimple.h>
28 #include "FUiAnim_MatrixUtil.h"
29 #include "FUiCtrl_OptionMenuPresenter.h"
30 #include "FUiCtrl_OptionMenu.h"
31 #include "FUiCtrl_OptionMenuModel.h"
32 #include "FUiCtrl_OptionMenuItem.h"
33 #include "FUiCtrl_Frame.h"
34 #include "FUiCtrl_Form.h"
35 #include "FGrp_FontImpl.h"
36 #include "FUi_AccessibilityElement.h"
37 #include "FUi_ControlManager.h"
38 #include "FUi_TouchManager.h"
39 #include "FUi_UiTouchEvent.h"
40 #include "FUi_ResourceManager.h"
42 using namespace Tizen::Base;
43 using namespace Tizen::Base::Runtime;
44 using namespace Tizen::Graphics;
45 using namespace Tizen::Graphics::_Text;
46 using namespace Tizen::Ui;
47 using namespace Tizen::Ui::Animations;
49 const int EFFECT_INTERVAL = 10;
50 const double EFFECT_CONSTANT = 0.075;
52 namespace Tizen { namespace Ui { namespace Controls
56 SineThirtyThreeTimingFunction::CalculateProgress(float timeProgress) const
58 const float segments[2][3] = {{0.0f, 0.050f, 0.495f}, {0.495f, 0.940f, 1.0f}};
60 float loc_5 = timeProgress;
61 int loc_6 = 2; //Length of the segments array
62 int loc_9 = (int)floor(loc_6 * loc_5);
69 float loc_7 = (loc_5 - loc_9 * (1.0f / loc_6)) * loc_6;
73 for (int i = 0; i < 3; i++)
75 loc_8[i] = segments[loc_9][i];
78 float ret = 0 + 1 * (loc_8[0] + loc_7 * (2 * (1 - loc_7) * (loc_8[1] - loc_8[0]) + loc_7 * (loc_8[2] - loc_8[0])));
84 SineSixtyTimingFunction::CalculateProgress(float timeProgress) const
86 const float segments[3][3] = {{0.0f, 0.01f, 0.37f}, {0.37f, 0.72f, 0.888f}, {0.888f, 0.9999f, 1.0f}};
87 float loc_5 = timeProgress;
88 int loc_6 = 3; //Length of the segments array
89 int loc_9 = (int)floor(loc_6 * loc_5);
95 float loc_7 = (loc_5 - loc_9 * (1.0 / loc_6)) * loc_6;
98 for (int i = 0; i < 3; i++)
100 loc_8[i] = segments[loc_9][i];
103 float ret = 0 + 1 * (loc_8[0] + loc_7 * (2 * (1 - loc_7) * (loc_8[1] - loc_8[0]) + loc_7 * (loc_8[2] - loc_8[0])));
108 _OptionMenuPresenter::_OptionMenuPresenter(_OptionMenu* optionMenu)
109 : __pOptionMenu(optionMenu)
110 , __pOptionMenuModel(null)
111 , __pItemBitmap(null)
112 , __pItemPressedBitmap(null)
113 , __pItemPressedEffectBitmap(null)
114 , __pArrowBitmap(null)
115 , __pArrowPressedBitmap(null)
116 , __pHandleBitmap(null)
117 , __pHandleEffectBitmap(null)
118 , __pHandlePressedBitmap(null)
119 , __pHandlePressedEffectBitmap(null)
120 , __pHandleArrowNormalBitmap(null)
121 , __pHandleArrowPressedBitmap(null)
124 , __maxColumnCount(0)
134 , __textLeftMargin(0)
135 , __textRightMargin(0)
137 , __textBottomMargin(0)
139 , __selectedIndex(-1)
140 , __isHandlerPressed(false)
142 , __isAnimationStarted(true)
143 , __pOptionMenuVE(null)
144 , __pThirtyThreeTimingFunction(null)
145 , __pSixtyTimingFunction(null)
149 _OptionMenuPresenter::~_OptionMenuPresenter(void)
151 __pOptionMenu = null;
153 delete __pOptionMenuModel;
154 __pOptionMenuModel = null;
156 delete __pItemBitmap;
157 __pItemBitmap = null;
159 delete __pItemPressedBitmap;
160 __pItemPressedBitmap = null;
162 delete __pItemPressedEffectBitmap;
163 __pItemPressedEffectBitmap = null;
165 delete __pArrowBitmap;
166 __pArrowBitmap = null;
168 delete __pArrowPressedBitmap;
169 __pArrowPressedBitmap = null;
171 delete __pHandleBitmap;
172 __pHandleBitmap = null;
174 delete __pHandleEffectBitmap;
175 __pHandleEffectBitmap = null;
177 delete __pHandlePressedBitmap;
178 __pHandlePressedBitmap = null;
180 delete __pHandlePressedEffectBitmap;
181 __pHandlePressedEffectBitmap = null;
183 delete __pHandleArrowNormalBitmap;
184 __pHandleArrowNormalBitmap = null;
186 delete __pHandleArrowPressedBitmap;
187 __pHandleArrowPressedBitmap = null;
189 if (__pOptionMenuVE != null)
191 __pOptionMenuVE->RemoveAllAnimations();
192 __pOptionMenuVE->SetAnimationProvider(null);
195 delete __pThirtyThreeTimingFunction;
196 __pThirtyThreeTimingFunction = null;
198 delete __pSixtyTimingFunction;
199 __pSixtyTimingFunction = null;
202 _OptionMenuPresenter*
203 _OptionMenuPresenter::CreateInstanceN(_OptionMenu& optionMenu)
205 result r = E_SUCCESS;
207 _OptionMenuPresenter* pOptionMenuPresenter = new (std::nothrow) _OptionMenuPresenter(&optionMenu);
208 SysTryReturn(NID_UI_CTRL, (pOptionMenuPresenter != null), null, E_OUT_OF_MEMORY,
209 "[E_OUT_OF_MEMORY] Memory allocation failed.");
212 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
214 pOptionMenuPresenter->__pOptionMenuModel = _OptionMenuModel::CreateInstanceN();
216 SysTryCatch(NID_UI_CTRL, (pOptionMenuPresenter->__pOptionMenuModel != null), , r,
217 "[%s] Propagating.", GetErrorMessage(r));
219 r = pOptionMenuPresenter->LoadBitmap();
220 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
222 r = pOptionMenuPresenter->LoadShapeResource(optionMenu.GetOrientation());
223 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
225 return pOptionMenuPresenter;
228 delete pOptionMenuPresenter;
233 _OptionMenuPresenter::InitializeVisualElement(void)
235 // matrix for scale-animation
236 _matrixOrigin.SetAsIdentity();
237 _matrixScale.SetAsIdentity();
239 _MatrixUtilScale(_matrixScale, 1, 0.7, 1);
241 __pOptionMenuVE = __pOptionMenu->GetVisualElement();
243 FloatPoint point(0.0f, 1.0f);
245 __pOptionMenuVE->SetAnchor(point);
246 SysTryReturn(NID_UI_CTRL, __pOptionMenuVE != null, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get VisualElement.");
252 _OptionMenuPresenter::InitializeTextObject(void)
254 result r = __textObject.Construct();
255 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
257 TextSimple* pSimpleText = new (std::nothrow)TextSimple(null, 0, TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
258 SysTryReturn(NID_UI_CTRL, (pSimpleText != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
259 "[E_OUT_OF_MEMORY] Memory allocation failed.");
261 __textObject.AppendElement(*pSimpleText);
263 // Create and initialize the Font.
264 __pFont = __pOptionMenu->GetFallbackFont();
266 SysTryReturn(NID_UI_CTRL, __pFont, r , r, "[%s] Propagating.", GetErrorMessage(r));
268 __textObject.SetAlignment(TEXT_OBJECT_ALIGNMENT_CENTER | TEXT_OBJECT_ALIGNMENT_MIDDLE);
269 __textObject.SetWrap(TEXT_OBJECT_WRAP_TYPE_CHARACTER);
270 __textObject.SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
271 __textObject.SetTextObjectEllipsisType(TEXT_OBJECT_ELLIPSIS_TYPE_TAIL);
277 _OptionMenuPresenter::AddItem(const String& text, int actionId)
279 result r = __pOptionMenuModel->AddItem(text, actionId);
280 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
286 _OptionMenuPresenter::InsertItemAt(int mainIndex, const String& text, int actionId)
288 result r = __pOptionMenuModel->InsertItemAt(text, actionId, mainIndex);
289 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
295 _OptionMenuPresenter::SetItemAt(int mainIndex, const String& text, int actionId)
297 result r = __pOptionMenuModel->SetItemAt(text, actionId, mainIndex);
298 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
304 _OptionMenuPresenter::RemoveItemAt(int mainIndex)
306 result r = __pOptionMenuModel->RemoveItemAt(mainIndex);
307 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
313 _OptionMenuPresenter::GetItemCount(void) const
315 return __pOptionMenuModel->GetItemCount();
319 _OptionMenuPresenter::GetItemIndexFromActionId(int actionId) const
321 return __pOptionMenuModel->GetItemIndexFromActionId(actionId);
325 _OptionMenuPresenter::GetItemActionIdAt(int mainIndex) const
327 _OptionMenuItem* pItem = __pOptionMenuModel->GetItem(mainIndex);
333 return pItem->GetActionId();
337 _OptionMenuPresenter::AddSubItem(int mainIndex, const String& text, int actionId)
339 result r = __pOptionMenuModel->AddItem(text, actionId, mainIndex);
340 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
346 _OptionMenuPresenter::InsertSubItemAt(int mainIndex, int subIndex, const String& text, int actionId)
348 result r = __pOptionMenuModel->InsertItemAt(text, actionId, mainIndex, subIndex);
349 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
355 _OptionMenuPresenter::SetSubItemAt(int mainIndex, int subIndex, const String& text, int actionId)
357 result r = __pOptionMenuModel->SetItemAt(text, actionId, mainIndex, subIndex);
358 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
364 _OptionMenuPresenter::RemoveSubItemAt(int mainIndex, int subIndex)
366 result r = __pOptionMenuModel->RemoveItemAt(mainIndex, subIndex);
367 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
373 _OptionMenuPresenter::GetSubItemCount(int mainIndex) const
375 return __pOptionMenuModel->GetSubItemCount(mainIndex);
379 _OptionMenuPresenter::GetSubItemIndexFromActionId(int actionId) const
382 return __pOptionMenuModel->GetSubItemIndexFromActionId(actionId, mainIndex);
386 _OptionMenuPresenter::GetSubItemActionIdAt(int mainIndex, int subIndex) const
388 _OptionMenuItem* pItem = __pOptionMenuModel->GetItem(mainIndex, subIndex);
394 return pItem->GetActionId();
398 _OptionMenuPresenter::Draw(void)
402 Canvas* pCanvas = __pOptionMenu->GetCanvasN();
403 result r = GetLastResult();
404 SysTryReturn(NID_UI_CTRL, (pCanvas != null), r, r, "[%s] Propagating.", GetErrorMessage(r));
406 DrawHandler(*pCanvas);
409 for (int index = __pOptionMenuModel->GetItemCount() - 1; index >= 0; index--)
411 DrawItem(*pCanvas, index);
413 DrawItemLine(*pCanvas);
421 _OptionMenuPresenter::DrawHandler(Canvas& canvas)
423 result r = E_SUCCESS;
424 _ControlOrientation orientation = __pOptionMenu->GetOrientation();
426 r = GET_SHAPE_CONFIG(OPTIONMENU::HANDLE_ARROW_Y_POSITION, orientation, arrowYPos);
427 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
429 Rectangle bounds = __pOptionMenu->GetBounds();
433 r = GET_SHAPE_CONFIG(OPTIONMENU::HANDLE_HEIGHT, orientation, bounds.height);
434 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
436 canvas.SetBackgroundColor(Color(0x00000000));
437 canvas.Clear(bounds);
439 if (__isHandlerPressed == true)
441 // Draw Handle Pressed Bitmap
442 r = DrawResourceBitmap(canvas, bounds, __pHandlePressedBitmap);
443 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
445 // Draw Handle Pressed Effect Bitmap
446 r = DrawResourceBitmap(canvas, bounds, __pHandlePressedEffectBitmap);
447 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
449 // Draw Arrow for Handle
450 r = canvas.DrawBitmap(Point((bounds.width - __pHandleArrowPressedBitmap->GetWidth()) >> 1, arrowYPos),
451 *__pHandleArrowPressedBitmap);
452 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
456 // Draw Handle Bitmap
457 r = DrawResourceBitmap(canvas, bounds, __pHandleBitmap);
458 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
460 // Draw Handle Effect Bitmap
461 r = DrawResourceBitmap(canvas, bounds, __pHandleEffectBitmap);
462 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
464 // Draw Arrow for Handle
465 r = canvas.DrawBitmap(Point((bounds.width - __pHandleArrowNormalBitmap->GetWidth()) >> 1, arrowYPos),
466 *__pHandleArrowNormalBitmap);
467 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
474 _OptionMenuPresenter::DrawItem(Canvas& canvas, int index)
476 Rectangle bounds = GetItemBounds(index);
477 TextSimple* pSimpleText = null;
478 _OptionMenuItem* pItem = __pOptionMenuModel->GetItem(index);
479 SysTryReturn(NID_UI_CTRL, (pItem != null), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The item in specified index (%d) is null.", index);
481 SysTryReturn (NID_UI_CTRL, (index != __selectedIndex || __pItemPressedBitmap != null), E_SYSTEM, E_SYSTEM,
482 "[E_SYSTEM] A system error has occurred. Failed to draw an item with index (%d).", index);
484 // Draw Background of Item
485 SysTryReturn(NID_UI_CTRL, (__pItemBitmap != null), E_SYSTEM, E_SYSTEM,
486 "[E_SYSTEM] A system error has occurred. Failed to draw an item with index (%d).", index);
488 result r = DrawResourceBitmap(canvas, bounds, __pItemBitmap);
495 _ControlOrientation orientation = __pOptionMenu->GetOrientation();
496 if (index == __selectedIndex)
498 Rectangle pressedBounds = bounds;
501 GET_FIXED_VALUE_CONFIG(OPTIONMENU::ITEM_PRESS_EDGE_MARGIN, orientation, margin);
502 if (pressedBounds.x == 0)
505 pressedBounds.x += margin;
506 pressedBounds.width -= margin;
509 if ((pressedBounds.x + pressedBounds.width) == __width)
512 pressedBounds.width -= margin;
515 GET_SHAPE_CONFIG(OPTIONMENU::ITEM_PRESS_LEFT_MARGIN, orientation, margin);
516 pressedBounds.x += margin;
517 pressedBounds.width -= margin;
519 GET_SHAPE_CONFIG(OPTIONMENU::ITEM_PRESS_RIGHT_MARGIN, orientation, margin);
520 pressedBounds.width -= margin;
522 GET_SHAPE_CONFIG(OPTIONMENU::ITEM_PRESS_TOP_MARGIN, orientation, margin);
523 pressedBounds.y += margin;
524 pressedBounds.height -= margin;
526 GET_SHAPE_CONFIG(OPTIONMENU::ITEM_PRESS_BOTTOM_MARGIN, orientation, margin);
527 pressedBounds.height -= margin;
529 DrawResourceBitmap(canvas, pressedBounds, __pItemPressedBitmap);
531 DrawResourceBitmap(canvas, pressedBounds, __pItemPressedEffectBitmap);
533 GET_COLOR_CONFIG(OPTIONMENU::ITEM_TEXT_PRESSED, textColor);
537 GET_COLOR_CONFIG(OPTIONMENU::ITEM_TEXT_NORMAL, textColor);
540 __textObject.RemoveAll();
541 pSimpleText = new (std::nothrow)TextSimple((wchar_t*)(pItem->GetText().GetPointer()), pItem->GetText().GetLength());
542 if (pSimpleText != null)
544 __textObject.AppendElement(*pSimpleText);
546 __textObject.SetForegroundColor(textColor, 0, __textObject.GetTextLength());
547 __textObject.Compose();
549 int lineCount = __textObject.GetTotalLineCount();
550 int textSize = __textSize;
554 textSize = textSize - 1;
557 (_FontImpl::GetInstance(*__pFont))->SetSize(textSize);
559 __textObject.SetFont(__pFont, 0, __textObject.GetTextLength());
563 textRect.height = bounds.height - __textTopMargin - __textBottomMargin;
564 textRect.width = bounds.width - __leftMargin - __rightMargin - __textLeftMargin - __textRightMargin;
565 textRect.x = bounds.x + __leftMargin + __textLeftMargin;
566 textRect.y = bounds.y + ((bounds.height - textRect.height) / 2);
568 if (pItem->HasSubItem() == true)
570 textRect.width -= __arrowMargin;
572 // Draw Arrow if item has subItem
573 if (__pArrowBitmap != null)
575 Point arrowPosition(bounds.x + bounds.width - __arrowMargin - __rightMargin,
576 bounds.y + ((bounds.height - __pArrowBitmap->GetHeight()) / 2));
578 if (index == __selectedIndex)
580 canvas.DrawBitmap(arrowPosition, *__pArrowPressedBitmap);
584 canvas.DrawBitmap(arrowPosition, *__pArrowBitmap);
589 __textObject.SetBounds(textRect);
590 __textObject.Draw(*_CanvasImpl::GetInstance(canvas));
592 _AccessibilityElement* pElement = __pOptionMenu->GetAccessibilityElement(index);
593 if (pElement != null)
595 pElement->SetBounds(bounds);
602 _OptionMenuPresenter::DrawItemLine(Canvas& canvas)
604 if (__columnCount <= 0)
609 Color lineColor(0xFF8995AE);
610 int lineWidth = __lineWidth - 1;
611 Color lineColorEF(0xFFFFFFFF);
612 Color foreGroundColor = canvas.GetForegroundColor();
613 GET_COLOR_CONFIG(OPTIONMENU::LINE, lineColor);
614 canvas.SetForegroundColor(lineColor);
615 canvas.SetLineStyle(LINE_STYLE_SOLID);
616 canvas.SetLineWidth(lineWidth);
618 int rowHeight = __itemHeight + __lineWidth;
621 for (y = __handleHeight + (__rowCount - 1) * rowHeight - 1; y > __handleHeight; y -= rowHeight)
624 canvas.SetForegroundColor(lineColor);
625 canvas.DrawLine(Point(0, y), Point(__width, y));
626 canvas.SetForegroundColor(lineColorEF);
627 canvas.DrawLine(Point(0, y-1), Point(__width, y-1));
630 for (int column = 1; column < __columnCount; column++)
632 x = (__width - 1) * column / __columnCount;
633 canvas.SetForegroundColor(lineColor);
634 canvas.DrawLine(Point(x, y - __itemHeight), Point(x, y));
635 canvas.SetForegroundColor(lineColorEF);
636 canvas.DrawLine(Point(x-1, y - __itemHeight), Point(x-1, y));
640 // Last-Row Vertical Line
641 int lastRowColumnCount = __pOptionMenuModel->GetItemCount() % __columnCount;
642 if (lastRowColumnCount == 0)
644 lastRowColumnCount = __columnCount;
647 y = __handleHeight + (__rowCount - 1) * rowHeight - 1;
648 for (int column = 1; column < lastRowColumnCount; column++)
650 x = (__width - 1) * column / __columnCount;
651 canvas.SetForegroundColor(lineColor);
652 canvas.DrawLine(Point(x, y), Point(x, y + __itemHeight));
653 canvas.SetForegroundColor(lineColorEF);
654 canvas.DrawLine(Point(x-1, y), Point(x-1, y + __itemHeight));
658 canvas.SetForegroundColor(foreGroundColor);
664 _OptionMenuPresenter::RefreshItem(int index)
666 if (index < 0 || index >= __pOptionMenuModel->GetItemCount())
668 return E_OUT_OF_RANGE;
671 Canvas* pCanvas = __pOptionMenu->GetCanvasN();
674 return GetLastResult();
677 result r = DrawItem(*pCanvas, index);
682 if (__pOptionMenu->GetVisualElement() != null)
684 __pOptionMenu->GetVisualElement()->SetFlushNeeded();
692 _OptionMenuPresenter::LoadShapeResource(_ControlOrientation orientation)
694 result r = E_SUCCESS;
696 r = GET_FIXED_VALUE_CONFIG(OPTIONMENU::COLUMN_MAX, orientation, __maxColumnCount);
702 r = GET_SHAPE_CONFIG(OPTIONMENU::HANDLE_HEIGHT, orientation, __handleHeight);
708 r = GET_SHAPE_CONFIG(OPTIONMENU::ITEM_HEIGHT, orientation, __itemHeight);
714 r = GET_FIXED_VALUE_CONFIG(OPTIONMENU::LINE_WIDTH, orientation, __lineWidth);
720 r = GET_SHAPE_CONFIG(OPTIONMENU::LEFT_MARGIN, orientation, __leftMargin);
726 r = GET_SHAPE_CONFIG(OPTIONMENU::RIGHT_MARGIN, orientation, __rightMargin);
732 r = GET_SHAPE_CONFIG(OPTIONMENU::TEXT_SIZE, orientation, __textSize);
738 r = GET_SHAPE_CONFIG(OPTIONMENU::TEXT_LEFT_MARGIN, orientation, __textLeftMargin);
744 r = GET_SHAPE_CONFIG(OPTIONMENU::TEXT_RIGHT_MARGIN, orientation, __textRightMargin);
750 r = GET_SHAPE_CONFIG(OPTIONMENU::TEXT_TOP_MARGIN, orientation, __textTopMargin);
756 r = GET_SHAPE_CONFIG(OPTIONMENU::TEXT_BOTTOM_MARGIN, orientation, __textBottomMargin);
762 r = GET_SHAPE_CONFIG(OPTIONMENU::ARROW_MARGIN, orientation, __arrowMargin);
772 _OptionMenuPresenter::CalculateBounds(void)
774 _ControlManager *pManager = _ControlManager::GetInstance();
775 SysTryReturn(NID_UI_CTRL, (pManager != null), E_SYSTEM, E_SYSTEM,
776 "[E_SYSTEM] A system error has occurred. The _ControlManager instance is null.");
778 Dimension screenSize = pManager->GetScreenSize();
779 Rectangle bounds(0, 0, 0, __handleHeight);
781 int itemCount = GetItemCount();
784 __rowCount = (itemCount - 1) / __maxColumnCount + 1;
787 __columnCount = itemCount / __rowCount;
788 if ((itemCount % __rowCount) > 0)
799 bounds.height += (__itemHeight + __lineWidth) * __rowCount - __lineWidth;
802 if ((__pOptionMenu != null) && (__pOptionMenu->GetOrientation() == _CONTROL_ORIENTATION_PORTRAIT))
804 bounds.width = screenSize.width;
805 bounds.y = screenSize.height - bounds.height;
809 bounds.width = screenSize.height;
810 bounds.y = screenSize.width - bounds.height;
812 __width = bounds.width;
814 if ((__pOptionMenu != null) && (bounds.height != __pOptionMenu->GetBounds().height))
816 __pOptionMenu->SetMovable(true);
817 __pOptionMenu->SetResizable(true);
819 result r = __pOptionMenu->SetBounds(bounds);
825 __pOptionMenu->SetMovable(false);
826 __pOptionMenu->SetResizable(false);
834 _OptionMenuPresenter::GetItemBounds(int index) const
836 if (__columnCount <= 0)
838 return Rectangle(0, 0, 0, 0);
841 int itemCount = __pOptionMenuModel->GetItemCount();
842 int lastRowColumnCount = itemCount % __columnCount;
843 int row = index / __columnCount;
844 int column = index % __columnCount;
845 Rectangle bounds(0, __handleHeight + row * (__itemHeight + __lineWidth), 0, __itemHeight);
846 if ((row == (__rowCount - 1)) && (lastRowColumnCount != 0))
848 // Calculate last row
849 bounds.x = column * __width / lastRowColumnCount;
851 bounds.width = column * __width / lastRowColumnCount - bounds.x;
853 if (column < lastRowColumnCount)
855 bounds.width -= __lineWidth;
860 bounds.x = column * __width / __columnCount;
862 bounds.width = column * __width / __columnCount - bounds.x;
864 if (column < __columnCount)
866 bounds.width -= __lineWidth;
874 _OptionMenuPresenter::GetItemIndexFromPosition(const Point& position) const
876 if ((__columnCount <= 0)
878 || (position.y < __handleHeight)
879 || (position.y >= __pOptionMenu->GetBounds().height))
884 int itemCount = __pOptionMenuModel->GetItemCount();
885 int row = (position.y - __handleHeight) / (__itemHeight + __lineWidth);
886 if ((row == (__rowCount - 1)) && ((itemCount % __columnCount) != 0))
888 return (row * __columnCount) + position.x * (itemCount % __columnCount) / __width;
891 return (row * __columnCount) + position.x * __columnCount / __width;
895 _OptionMenuPresenter::LoadBitmap(void)
897 result r = E_SUCCESS;
900 r = GET_BITMAP_CONFIG_N(OPTIONMENU::ITEM_BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pItemBitmap);
901 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
903 GET_COLOR_CONFIG(OPTIONMENU::ITEM_BG_NORMAL, color);
904 __pItemBitmap = _BitmapImpl::GetColorReplacedBitmapN(*__pItemBitmap, Color::GetColor(COLOR_ID_MAGENTA), color);
905 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
907 // Load Item Pressed Bitmap
908 r = GET_BITMAP_CONFIG_N(OPTIONMENU::ITEM_BG_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, __pItemPressedBitmap);
909 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
911 GET_COLOR_CONFIG(OPTIONMENU::ITEM_BG_PRESSED, color);
912 __pItemPressedBitmap = _BitmapImpl::GetColorReplacedBitmapN(*__pItemPressedBitmap, Color::GetColor(COLOR_ID_MAGENTA), color);
913 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
916 r = GET_BITMAP_CONFIG_N(OPTIONMENU::ITEM_BG_EFFECT_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, __pItemPressedEffectBitmap);
917 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
920 r = GET_BITMAP_CONFIG_N(OPTIONMENU::CONTEXTUAL_POPUP_ARROW, BITMAP_PIXEL_FORMAT_ARGB8888, __pArrowBitmap);
921 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
923 GET_COLOR_CONFIG(OPTIONMENU::ARROW_NORMAL, color);
924 __pArrowBitmap = _BitmapImpl::GetColorReplacedBitmapN(*__pArrowBitmap, Color::GetColor(COLOR_ID_MAGENTA), color);
925 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
928 // Load Arrow Pressed Bitmap
929 r = GET_BITMAP_CONFIG_N(OPTIONMENU::CONTEXTUAL_POPUP_ARROW, BITMAP_PIXEL_FORMAT_ARGB8888, __pArrowPressedBitmap);
930 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
931 GET_COLOR_CONFIG(OPTIONMENU::ARROW_PRESSED, color);
932 __pArrowPressedBitmap = _BitmapImpl::GetColorReplacedBitmapN(*__pArrowPressedBitmap, Color::GetColor(COLOR_ID_MAGENTA), color);
933 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
935 // Load Handle Bitmap
936 r = GET_BITMAP_CONFIG_N(OPTIONMENU::HANDLE_BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pHandleBitmap);
937 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
939 GET_COLOR_CONFIG(OPTIONMENU::HANDLE_NORMAL, color);
940 __pHandleBitmap = _BitmapImpl::GetColorReplacedBitmapN(*__pHandleBitmap, Color::GetColor(COLOR_ID_MAGENTA), color);
941 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
943 // Load Handle Effect Bitmap
944 r = GET_BITMAP_CONFIG_N(OPTIONMENU::HANDLE_BG_EFFECT_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pHandleEffectBitmap);
945 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
947 // Load Handle Pressed Bitmap
948 r = GET_BITMAP_CONFIG_N(OPTIONMENU::HANDLE_BG_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, __pHandlePressedBitmap);
949 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
951 GET_COLOR_CONFIG(OPTIONMENU::HANDLE_PRESSED, color);
952 __pHandlePressedBitmap = _BitmapImpl::GetColorReplacedBitmapN(*__pHandlePressedBitmap, Color::GetColor(COLOR_ID_MAGENTA), color);
953 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
956 // Load Handle Pressed Effect Bitmap
957 r = GET_BITMAP_CONFIG_N(OPTIONMENU::HANDLE_BG_EFFECT_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, __pHandlePressedEffectBitmap);
958 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
960 // Load Handle Arrow Bitmap
961 r = GET_BITMAP_CONFIG_N(OPTIONMENU::HANDLE_ARROW_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pHandleArrowNormalBitmap);
962 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
964 r = GET_BITMAP_CONFIG_N(OPTIONMENU::HANDLE_ARROW_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, __pHandleArrowPressedBitmap);
965 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
969 delete __pItemBitmap;
970 __pItemBitmap = null;
972 delete __pItemPressedBitmap;
973 __pItemPressedBitmap = null;
975 delete __pItemPressedEffectBitmap;
976 __pItemPressedEffectBitmap = null;
978 delete __pArrowBitmap;
979 __pArrowBitmap = null;
981 delete __pArrowPressedBitmap;
982 __pArrowPressedBitmap = null;
984 delete __pHandleBitmap;
985 __pHandleBitmap = null;
987 delete __pHandleEffectBitmap;
988 __pHandleEffectBitmap = null;
990 delete __pHandlePressedBitmap;
991 __pHandlePressedBitmap = null;
993 delete __pHandlePressedEffectBitmap;
994 __pHandlePressedEffectBitmap = null;
1001 _OptionMenuPresenter::PrepareAnimation(void)
1003 result r = E_SUCCESS;
1005 __pOptionMenuVE->SetAnimationProvider(this);
1007 r = __pOptionMenuVE->SetSurfaceOpaque(false);
1008 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1010 __pOptionMenuVE->SetOpacity(0.0f);
1011 __pOptionMenuVE->SetShowState(true);
1017 _OptionMenuPresenter::SetOptionMenuVisibility(bool visibility)
1019 SysTryReturnResult(NID_UI_CTRL, __pOptionMenuVE != null, E_INVALID_STATE, "[E_INVALID_STATE] OptionMenu VisualElement instance is null.");
1021 result r = E_SUCCESS;
1023 if (visibility == true)
1025 __pOptionMenuVE->SetTransformMatrix(_matrixScale);
1027 __pOptionMenuVE->SetImplicitAnimationEnabled(true);
1028 r = GetLastResult();
1029 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1031 __pOptionMenuVE->SetTransformMatrix(_matrixOrigin);
1032 __pOptionMenuVE->SetOpacity(1.0f);
1034 __pOptionMenuVE->SetImplicitAnimationEnabled(false);
1035 r = GetLastResult();
1036 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1040 __pOptionMenuVE->SetTransformMatrix(_matrixOrigin);
1041 __pOptionMenuVE->SetOpacity(1.0f);
1043 __pOptionMenuVE->SetImplicitAnimationEnabled(true);
1044 r = GetLastResult();
1045 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1047 __pOptionMenuVE->SetTransformMatrix(_matrixScale);
1048 __pOptionMenuVE->SetOpacity(0.0f);
1050 __pOptionMenuVE->SetImplicitAnimationEnabled(false);
1051 r = GetLastResult();
1052 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1059 VisualElementAnimation*
1060 _OptionMenuPresenter::CreateAnimationForProperty(VisualElement& target, const String& property)
1062 VisualElementAnimation* pAnimation = VisualElementAnimationProvider::CreateAnimationForProperty(target, property);
1064 if (pAnimation != null)
1066 result r = E_SUCCESS;
1068 __isAnimationStarted = true;
1070 if (__pOptionMenuVE == (static_cast <Tizen::Ui::Animations::_VisualElement*>(&target)))
1072 String opacity = L"opacity";
1074 if (opacity == property)
1076 r = pAnimation->SetDuration(333);
1077 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
1079 __pThirtyThreeTimingFunction = new (std::nothrow) SineThirtyThreeTimingFunction();
1080 SysTryCatch(NID_UI_CTRL, (__pThirtyThreeTimingFunction != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1082 pAnimation->SetTimingFunction(__pThirtyThreeTimingFunction);
1086 r = pAnimation->SetDuration(333);
1087 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
1089 __pSixtyTimingFunction = new (std::nothrow) SineSixtyTimingFunction();
1090 SysTryCatch(NID_UI_CTRL, (__pSixtyTimingFunction != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1092 pAnimation->SetTimingFunction(__pSixtyTimingFunction);
1096 pAnimation->SetVisualElementAnimationStatusEventListener(this);
1108 _OptionMenuPresenter::OnVisualElementAnimationStarted(const Tizen::Ui::Animations::VisualElementAnimation& animation, const Tizen::Base::String& keyName, Tizen::Ui::Animations::VisualElement& target)
1114 _OptionMenuPresenter::OnVisualElementAnimationRepeated(const Tizen::Ui::Animations::VisualElementAnimation& animation, const Tizen::Base::String& keyName, Tizen::Ui::Animations::VisualElement& target, long currentRepeatCount)
1120 _OptionMenuPresenter::OnVisualElementAnimationFinished(const Tizen::Ui::Animations::VisualElementAnimation& animation, const Tizen::Base::String& keyName, Tizen::Ui::Animations::VisualElement& target, bool completedNormally)
1122 SysTryReturnVoidResult(NID_UI_CTRL, __pOptionMenuVE != null, E_INVALID_STATE, "[E_INVALID_STATE] OptionMenu VisualElement instance is null.");
1124 __isAnimationStarted = false;
1126 if (__pOptionMenuVE == (static_cast <Tizen::Ui::Animations::_VisualElement*>(&target)))
1128 if (completedNormally == true)
1130 __pOptionMenuVE->RemoveAllAnimations();
1131 __pOptionMenuVE->SetAnimationProvider(null);
1135 __isClosing = false;
1136 __pOptionMenu->Close();
1145 _OptionMenuPresenter::Hide(void)
1149 SetOptionMenuVisibility(false);
1153 _OptionMenuPresenter::SetPosition(const Point& position)
1155 __pOptionMenu->SetMovable(true);
1157 result r = __pOptionMenu->SetPosition(position);
1159 __pOptionMenu->SetMovable(false);
1165 _OptionMenuPresenter::OnChangeLayout(_ControlOrientation orientation)
1168 LoadShapeResource(orientation);
1173 _OptionMenuPresenter::StopAnimation(void)
1175 if (__isAnimationStarted)
1179 __isClosing = false;
1180 if (__pOptionMenu != null && __pOptionMenuVE != null)
1182 __pOptionMenuVE->RemoveAllAnimations();
1183 __pOptionMenuVE->SetAnimationProvider(null);
1185 __pOptionMenu->Close();
1194 _OptionMenuPresenter::OnAttachingToMainTree(const _Control* pParent)
1196 if (__pOptionMenu->GetOwner() == null)
1198 _Frame* pFrame = dynamic_cast<_Frame*>(_ControlManager::GetInstance()->GetCurrentFrame());
1199 SysTryReturn(NID_UI_CTRL, pFrame != null, E_SYSTEM,
1200 E_SYSTEM, "[E_SYSTEM] This instance is not constructed.");
1202 _Form* pForm = pFrame->GetCurrentForm();
1205 __pOptionMenu->SetOwner(pForm);
1209 __pOptionMenu->SetOwner(pFrame);
1217 _OptionMenuPresenter::OnAttachedToMainTree(void)
1223 _OptionMenuPresenter::OnDetachingFromMainTree(void)
1225 __pOptionMenu->SetOwner(null);
1230 _OptionMenuPresenter::OnVisibleStateChanged(void)
1232 if (__pOptionMenu->IsVisible() == true)
1234 if (_ControlManager::GetInstance()->GetTopWindow() == __pOptionMenu)
1236 __pOptionMenu->SetTouchCapture();
1241 _TouchManager* pManager = _TouchManager::GetInstance();
1242 if (pManager != null && pManager->GetCapturedControl() == __pOptionMenu)
1244 __pOptionMenu->ReleaseTouchCapture();
1250 _OptionMenuPresenter::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
1252 if (&source != __pOptionMenu)
1257 if (__pOptionMenu->IsSubMenuShown() == true)
1259 __pOptionMenu->DestroySubMenu();
1260 __pOptionMenu->SetTouchCapture();
1264 Point position = touchinfo.GetCurrentPosition();
1265 __selectedIndex = GetItemIndexFromPosition(position);
1266 if (__selectedIndex >= 0)
1268 RefreshItem(__selectedIndex);
1270 else if (__selectedIndex == -1 && position.y >= 0)
1272 __isHandlerPressed = true;
1273 __pOptionMenu->Draw();
1284 _OptionMenuPresenter::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
1286 if (&source != __pOptionMenu)
1291 if (__isHandlerPressed == true)
1293 __isHandlerPressed = false;
1298 if (__selectedIndex >= 0)
1300 int selectedIndex = __selectedIndex;
1301 __selectedIndex = -1;
1302 RefreshItem(selectedIndex);
1304 _OptionMenuItem* pItem = __pOptionMenuModel->GetItem(selectedIndex);
1307 if (pItem->HasSubItem() == true)
1310 __pOptionMenu->ShowSubMenu(selectedIndex, *pItem);
1314 // Fire Action Event
1316 __pOptionMenu->FireActionEvent(pItem->GetActionId());
1325 _OptionMenuPresenter::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
1327 if (&source != __pOptionMenu)
1332 Point position = touchinfo.GetCurrentPosition();
1333 int selectedIndex = GetItemIndexFromPosition(position);
1334 if (__isHandlerPressed == true)
1336 if (selectedIndex >= 0 || position.y < 0)
1338 __isHandlerPressed = false;
1339 __pOptionMenu->Draw();
1344 if (__selectedIndex >= 0)
1346 if (selectedIndex != __selectedIndex)
1348 selectedIndex = __selectedIndex;
1349 __selectedIndex = -1;
1350 RefreshItem(selectedIndex);
1358 _OptionMenuPresenter::OnTouchCanceled(const Tizen::Ui::_Control& source, const Tizen::Ui::_TouchInfo& touchinfo)
1360 if (&source != __pOptionMenu)
1365 __isHandlerPressed = false;
1366 __selectedIndex = -1;
1367 __pOptionMenu->Draw();
1373 _OptionMenuPresenter::OnActionPerformed(const _Control& source, int actionId)
1375 // for SubMenu Events
1376 __pOptionMenu->DestroySubMenu();
1378 __pOptionMenu->FireActionEvent(actionId);
1382 _OptionMenuPresenter::OnFontChanged(Font* pFont)
1389 _OptionMenuPresenter::OnFontInfoRequested(unsigned long& style, int& size)
1391 style = FONT_STYLE_PLAIN;
1397 _OptionMenuPresenter::GetFont(void) const
1403 _OptionMenuPresenter::DrawResourceBitmap(Canvas& canvas, const Rectangle& bounds, Bitmap* pBitmap)
1405 result r = E_SUCCESS;
1407 if (pBitmap == null)
1412 if (pBitmap->IsNinePatchedBitmap())
1414 r = canvas.DrawNinePatchedBitmap(bounds, *pBitmap);
1415 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
1419 r = canvas.DrawBitmap(bounds, *pBitmap);
1420 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
1426 }}} // Tizen::Ui::Controls