Fork for IVI: mesa fixing
[profile/ivi/uifw.git] / src / ui / controls / FUiCtrl_OptionMenuPresenter.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://floralicense.org/license/
10 //
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.
16 //
17 /**
18  * @file                FUiCtrl_OptionMenuPresenter.cpp
19  * @brief               This is the implementation file for the _OptionMenuPresenter class.
20  */
21
22 #include <FBaseErrorDefine.h>
23 #include <FGrpFont.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"
41
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;
48
49 const int EFFECT_INTERVAL = 10;
50 const double EFFECT_CONSTANT = 0.075;
51
52 namespace Tizen { namespace Ui { namespace Controls
53 {
54
55 float
56 SineThirtyThreeTimingFunction::CalculateProgress(float timeProgress) const
57 {
58         const float segments[2][3] = {{0.0f, 0.050f, 0.495f}, {0.495f, 0.940f, 1.0f}};
59
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);
63
64         if (loc_9 >= loc_6)
65         {
66                 loc_9 = loc_6 - 1;
67         }
68
69         float loc_7 = (loc_5 - loc_9 * (1.0f / loc_6)) * loc_6;
70
71         float loc_8[3];
72
73         for (int i = 0; i < 3; i++)
74         {
75                 loc_8[i] = segments[loc_9][i];
76         }
77
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])));
79
80         return ret;
81 }
82
83 float
84 SineSixtyTimingFunction::CalculateProgress(float timeProgress) const
85 {
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);
90
91         if (loc_9 >= loc_6)
92         {
93                 loc_9 = loc_6 - 1;
94         }
95         float loc_7 = (loc_5 - loc_9 * (1.0 / loc_6)) * loc_6;
96         float loc_8[3];
97
98         for (int i = 0; i < 3; i++)
99         {
100                 loc_8[i] = segments[loc_9][i];
101         }
102
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])));
104
105         return ret;
106 }
107
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)
122         , __textObject()
123         , __pFont(null)
124         , __maxColumnCount(0)
125         , __rowCount(0)
126         , __columnCount(0)
127         , __width(0)
128         , __handleHeight(0)
129         , __itemHeight(0)
130         , __lineWidth(0)
131         , __leftMargin(0)
132         , __rightMargin(0)
133         , __textSize(0)
134         , __textLeftMargin(0)
135         , __textRightMargin(0)
136         , __textTopMargin(0)
137         , __textBottomMargin(0)
138         , __arrowMargin(0)
139         , __selectedIndex(-1)
140         , __isHandlerPressed(false)
141         , __isClosing(false)
142         , __isAnimationStarted(true)
143         , __pOptionMenuVE(null)
144         , __pThirtyThreeTimingFunction(null)
145         , __pSixtyTimingFunction(null)
146 {
147 }
148
149 _OptionMenuPresenter::~_OptionMenuPresenter(void)
150 {
151         __pOptionMenu = null;
152
153         delete __pOptionMenuModel;
154         __pOptionMenuModel = null;
155
156         delete __pItemBitmap;
157         __pItemBitmap = null;
158
159         delete __pItemPressedBitmap;
160         __pItemPressedBitmap = null;
161
162         delete __pItemPressedEffectBitmap;
163         __pItemPressedEffectBitmap = null;
164
165         delete __pArrowBitmap;
166         __pArrowBitmap = null;
167
168         delete __pArrowPressedBitmap;
169         __pArrowPressedBitmap = null;
170
171         delete __pHandleBitmap;
172         __pHandleBitmap = null;
173
174         delete __pHandleEffectBitmap;
175         __pHandleEffectBitmap = null;
176
177         delete __pHandlePressedBitmap;
178         __pHandlePressedBitmap = null;
179
180         delete __pHandlePressedEffectBitmap;
181         __pHandlePressedEffectBitmap = null;
182
183         delete __pHandleArrowNormalBitmap;
184         __pHandleArrowNormalBitmap = null;
185
186         delete __pHandleArrowPressedBitmap;
187         __pHandleArrowPressedBitmap = null;
188
189         if (__pOptionMenuVE != null)
190         {
191                 __pOptionMenuVE->RemoveAllAnimations();
192                 __pOptionMenuVE->SetAnimationProvider(null);
193         }
194
195         delete __pThirtyThreeTimingFunction;
196         __pThirtyThreeTimingFunction = null;
197
198         delete __pSixtyTimingFunction;
199         __pSixtyTimingFunction = null;
200 }
201
202 _OptionMenuPresenter*
203 _OptionMenuPresenter::CreateInstanceN(_OptionMenu& optionMenu)
204 {
205         result r = E_SUCCESS;
206
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.");
210
211         r = GetLastResult();
212         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
213
214         pOptionMenuPresenter->__pOptionMenuModel = _OptionMenuModel::CreateInstanceN();
215         r = GetLastResult();
216         SysTryCatch(NID_UI_CTRL, (pOptionMenuPresenter->__pOptionMenuModel != null), , r,
217                             "[%s] Propagating.", GetErrorMessage(r));
218
219         r = pOptionMenuPresenter->LoadBitmap();
220         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
221
222         r = pOptionMenuPresenter->LoadShapeResource(optionMenu.GetOrientation());
223         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
224
225         return pOptionMenuPresenter;
226
227 CATCH:
228         delete pOptionMenuPresenter;
229         return null;
230 }
231
232 result
233 _OptionMenuPresenter::InitializeVisualElement(void)
234 {
235     // matrix for scale-animation
236         _matrixOrigin.SetAsIdentity();
237         _matrixScale.SetAsIdentity();
238
239         _MatrixUtilScale(_matrixScale, 1, 0.7, 1);
240
241         __pOptionMenuVE = __pOptionMenu->GetVisualElement();
242
243         FloatPoint point(0.0f, 1.0f);
244
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.");
247
248         return E_SUCCESS;
249 }
250
251 result
252 _OptionMenuPresenter::InitializeTextObject(void)
253 {
254         result r = __textObject.Construct();
255         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
256
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.");
260
261         __textObject.AppendElement(*pSimpleText);
262
263         // Create and initialize the Font.
264         __pFont = __pOptionMenu->GetFallbackFont();
265         r = GetLastResult();
266         SysTryReturn(NID_UI_CTRL, __pFont, r , r, "[%s] Propagating.", GetErrorMessage(r));
267
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);
272
273         return E_SUCCESS;
274 }
275
276 result
277 _OptionMenuPresenter::AddItem(const String& text, int actionId)
278 {
279         result r = __pOptionMenuModel->AddItem(text, actionId);
280         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
281
282         return E_SUCCESS;
283 }
284
285 result
286 _OptionMenuPresenter::InsertItemAt(int mainIndex, const String& text, int actionId)
287 {
288         result r = __pOptionMenuModel->InsertItemAt(text, actionId, mainIndex);
289         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
290
291         return E_SUCCESS;
292 }
293
294 result
295 _OptionMenuPresenter::SetItemAt(int mainIndex, const String& text, int actionId)
296 {
297         result r = __pOptionMenuModel->SetItemAt(text, actionId, mainIndex);
298         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
299
300         return E_SUCCESS;
301 }
302
303 result
304 _OptionMenuPresenter::RemoveItemAt(int mainIndex)
305 {
306         result r = __pOptionMenuModel->RemoveItemAt(mainIndex);
307         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
308
309         return E_SUCCESS;
310 }
311
312 int
313 _OptionMenuPresenter::GetItemCount(void) const
314 {
315         return __pOptionMenuModel->GetItemCount();
316 }
317
318 int
319 _OptionMenuPresenter::GetItemIndexFromActionId(int actionId) const
320 {
321         return __pOptionMenuModel->GetItemIndexFromActionId(actionId);
322 }
323
324 int
325 _OptionMenuPresenter::GetItemActionIdAt(int mainIndex) const
326 {
327         _OptionMenuItem* pItem = __pOptionMenuModel->GetItem(mainIndex);
328         if (pItem == null)
329         {
330                 return -1;
331         }
332
333         return pItem->GetActionId();
334 }
335
336 result
337 _OptionMenuPresenter::AddSubItem(int mainIndex, const String& text, int actionId)
338 {
339         result r = __pOptionMenuModel->AddItem(text, actionId, mainIndex);
340         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
341
342         return E_SUCCESS;
343 }
344
345 result
346 _OptionMenuPresenter::InsertSubItemAt(int mainIndex, int subIndex, const String& text, int actionId)
347 {
348         result r = __pOptionMenuModel->InsertItemAt(text, actionId, mainIndex, subIndex);
349         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
350
351         return E_SUCCESS;
352 }
353
354 result
355 _OptionMenuPresenter::SetSubItemAt(int mainIndex, int subIndex, const String& text, int actionId)
356 {
357         result r = __pOptionMenuModel->SetItemAt(text, actionId, mainIndex, subIndex);
358         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
359
360         return E_SUCCESS;
361 }
362
363 result
364 _OptionMenuPresenter::RemoveSubItemAt(int mainIndex, int subIndex)
365 {
366         result r = __pOptionMenuModel->RemoveItemAt(mainIndex, subIndex);
367         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
368
369         return E_SUCCESS;
370 }
371
372 int
373 _OptionMenuPresenter::GetSubItemCount(int mainIndex) const
374 {
375         return __pOptionMenuModel->GetSubItemCount(mainIndex);
376 }
377
378 int
379 _OptionMenuPresenter::GetSubItemIndexFromActionId(int actionId) const
380 {
381         int mainIndex = -1;
382         return __pOptionMenuModel->GetSubItemIndexFromActionId(actionId, mainIndex);
383 }
384
385 int
386 _OptionMenuPresenter::GetSubItemActionIdAt(int mainIndex, int subIndex) const
387 {
388         _OptionMenuItem* pItem = __pOptionMenuModel->GetItem(mainIndex, subIndex);
389         if (pItem == null)
390         {
391                 return -1;
392         }
393
394         return pItem->GetActionId();
395 }
396
397 result
398 _OptionMenuPresenter::Draw(void)
399 {
400         CalculateBounds();
401
402         Canvas* pCanvas = __pOptionMenu->GetCanvasN();
403         result r = GetLastResult();
404         SysTryReturn(NID_UI_CTRL, (pCanvas != null), r, r, "[%s] Propagating.", GetErrorMessage(r));
405
406         DrawHandler(*pCanvas);
407
408         // Draw Items
409         for (int index = __pOptionMenuModel->GetItemCount() - 1; index >= 0; index--)
410         {
411                 DrawItem(*pCanvas, index);
412         }
413         DrawItemLine(*pCanvas);
414
415         delete pCanvas;
416
417         return E_SUCCESS;
418 }
419
420 result
421 _OptionMenuPresenter::DrawHandler(Canvas& canvas)
422 {
423         result r = E_SUCCESS;
424         _ControlOrientation orientation = __pOptionMenu->GetOrientation();
425         int arrowYPos = 0;
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));
428
429         Rectangle bounds = __pOptionMenu->GetBounds();
430         bounds.x = 0;
431         bounds.y = 0;
432
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));
435
436         canvas.SetBackgroundColor(Color(0x00000000));
437         canvas.Clear(bounds);
438
439         if (__isHandlerPressed == true)
440         {
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));
444
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));
448
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));
453         }
454         else
455         {
456                 // Draw Handle Bitmap
457                 r = DrawResourceBitmap(canvas, bounds, __pHandleBitmap);
458                 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
459
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));
463
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));
468         }
469
470         return r;
471 }
472
473 result
474 _OptionMenuPresenter::DrawItem(Canvas& canvas, int index)
475 {
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);
480
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);
483
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);
487
488         result r = DrawResourceBitmap(canvas, bounds, __pItemBitmap);
489         if (r != E_SUCCESS)
490         {
491                 return r;
492         }
493
494         Color textColor;
495         _ControlOrientation orientation = __pOptionMenu->GetOrientation();
496         if (index == __selectedIndex)
497         {
498                 Rectangle pressedBounds = bounds;
499                 int margin = 0;
500
501                 GET_FIXED_VALUE_CONFIG(OPTIONMENU::ITEM_PRESS_EDGE_MARGIN, orientation, margin);
502                 if (pressedBounds.x == 0)
503                 {
504                         // Adjust left-edge
505                         pressedBounds.x += margin;
506                         pressedBounds.width -= margin;
507                 }
508
509                 if ((pressedBounds.x + pressedBounds.width) == __width)
510                 {
511                         // Adjust right-edge
512                         pressedBounds.width -= margin;
513                 }
514
515                 GET_SHAPE_CONFIG(OPTIONMENU::ITEM_PRESS_LEFT_MARGIN, orientation, margin);
516                 pressedBounds.x += margin;
517                 pressedBounds.width -= margin;
518
519                 GET_SHAPE_CONFIG(OPTIONMENU::ITEM_PRESS_RIGHT_MARGIN, orientation, margin);
520                 pressedBounds.width -= margin;
521
522                 GET_SHAPE_CONFIG(OPTIONMENU::ITEM_PRESS_TOP_MARGIN, orientation, margin);
523                 pressedBounds.y += margin;
524                 pressedBounds.height -= margin;
525
526                 GET_SHAPE_CONFIG(OPTIONMENU::ITEM_PRESS_BOTTOM_MARGIN, orientation, margin);
527                 pressedBounds.height -= margin;
528
529                 DrawResourceBitmap(canvas, pressedBounds, __pItemPressedBitmap);
530
531                 DrawResourceBitmap(canvas, pressedBounds, __pItemPressedEffectBitmap);
532
533                 GET_COLOR_CONFIG(OPTIONMENU::ITEM_TEXT_PRESSED, textColor);
534         }
535         else
536         {
537                 GET_COLOR_CONFIG(OPTIONMENU::ITEM_TEXT_NORMAL, textColor);
538         }
539
540         __textObject.RemoveAll();
541         pSimpleText = new (std::nothrow)TextSimple((wchar_t*)(pItem->GetText().GetPointer()), pItem->GetText().GetLength());
542         if (pSimpleText != null)
543         {
544                 __textObject.AppendElement(*pSimpleText);
545         }
546         __textObject.SetForegroundColor(textColor, 0, __textObject.GetTextLength());
547         __textObject.Compose();
548
549         int lineCount = __textObject.GetTotalLineCount();
550         int textSize = __textSize;
551
552         if (lineCount > 1)
553         {
554                 textSize = textSize - 1;
555         }
556
557         (_FontImpl::GetInstance(*__pFont))->SetSize(textSize);
558
559         __textObject.SetFont(__pFont, 0, __textObject.GetTextLength());
560
561         // Draw Text
562         Rectangle textRect;
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);
567
568         if (pItem->HasSubItem() == true)
569         {
570                 textRect.width -= __arrowMargin;
571
572                 // Draw Arrow if item has subItem
573                 if (__pArrowBitmap != null)
574                 {
575                         Point arrowPosition(bounds.x + bounds.width - __arrowMargin - __rightMargin,
576                                                                 bounds.y + ((bounds.height - __pArrowBitmap->GetHeight()) / 2));
577
578                         if (index == __selectedIndex)
579                         {
580                                 canvas.DrawBitmap(arrowPosition, *__pArrowPressedBitmap);
581                         }
582                         else
583                         {
584                                 canvas.DrawBitmap(arrowPosition, *__pArrowBitmap);
585                         }
586                 }
587         }
588
589         __textObject.SetBounds(textRect);
590         __textObject.Draw(*_CanvasImpl::GetInstance(canvas));
591
592         _AccessibilityElement* pElement = __pOptionMenu->GetAccessibilityElement(index);
593         if (pElement != null)
594         {
595                 pElement->SetBounds(bounds);
596         }
597
598         return E_SUCCESS;
599 }
600
601 result
602 _OptionMenuPresenter::DrawItemLine(Canvas& canvas)
603 {
604         if (__columnCount <= 0)
605         {
606                 return E_SUCCESS;
607         }
608
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);
617
618         int rowHeight = __itemHeight + __lineWidth;
619         int x = 0;
620         int y = 0;
621         for (y = __handleHeight + (__rowCount - 1) * rowHeight - 1; y > __handleHeight; y -= rowHeight)
622         {
623                 // Horizontal Line
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));
628
629                 // Vertical Line
630                 for (int column = 1; column < __columnCount; column++)
631                 {
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));
637                 }
638         }
639
640         // Last-Row Vertical Line
641         int lastRowColumnCount = __pOptionMenuModel->GetItemCount() % __columnCount;
642         if (lastRowColumnCount == 0)
643         {
644                 lastRowColumnCount = __columnCount;
645         }
646
647         y = __handleHeight + (__rowCount - 1) * rowHeight - 1;
648         for (int column = 1; column < lastRowColumnCount; column++)
649         {
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));
655
656         }
657
658         canvas.SetForegroundColor(foreGroundColor);
659
660         return E_SUCCESS;
661 }
662
663 result
664 _OptionMenuPresenter::RefreshItem(int index)
665 {
666         if (index < 0 || index >= __pOptionMenuModel->GetItemCount())
667         {
668                 return E_OUT_OF_RANGE;
669         }
670
671         Canvas* pCanvas = __pOptionMenu->GetCanvasN();
672         if (pCanvas == null)
673         {
674                 return GetLastResult();
675         }
676
677         result r = DrawItem(*pCanvas, index);
678         delete pCanvas;
679
680         if (r == E_SUCCESS)
681         {
682                 if (__pOptionMenu->GetVisualElement() != null)
683                 {
684                         __pOptionMenu->GetVisualElement()->SetFlushNeeded();
685                 }
686         }
687
688         return r;
689 }
690
691 result
692 _OptionMenuPresenter::LoadShapeResource(_ControlOrientation orientation)
693 {
694         result r = E_SUCCESS;
695
696     r = GET_FIXED_VALUE_CONFIG(OPTIONMENU::COLUMN_MAX, orientation, __maxColumnCount);
697         if (r != E_SUCCESS)
698         {
699                 return r;
700         }
701
702         r = GET_SHAPE_CONFIG(OPTIONMENU::HANDLE_HEIGHT, orientation, __handleHeight);
703         if (r != E_SUCCESS)
704         {
705                 return r;
706         }
707
708         r = GET_SHAPE_CONFIG(OPTIONMENU::ITEM_HEIGHT, orientation, __itemHeight);
709         if (r != E_SUCCESS)
710         {
711                 return r;
712         }
713
714         r = GET_FIXED_VALUE_CONFIG(OPTIONMENU::LINE_WIDTH, orientation, __lineWidth);
715         if (r != E_SUCCESS)
716         {
717                 return r;
718         }
719
720         r = GET_SHAPE_CONFIG(OPTIONMENU::LEFT_MARGIN, orientation, __leftMargin);
721         if (r != E_SUCCESS)
722         {
723                 return r;
724         }
725
726         r = GET_SHAPE_CONFIG(OPTIONMENU::RIGHT_MARGIN, orientation, __rightMargin);
727         if (r != E_SUCCESS)
728         {
729                 return r;
730         }
731
732         r = GET_SHAPE_CONFIG(OPTIONMENU::TEXT_SIZE, orientation, __textSize);
733         if (r != E_SUCCESS)
734         {
735                 return r;
736         }
737
738         r = GET_SHAPE_CONFIG(OPTIONMENU::TEXT_LEFT_MARGIN, orientation, __textLeftMargin);
739         if (r != E_SUCCESS)
740         {
741                 return r;
742         }
743
744         r = GET_SHAPE_CONFIG(OPTIONMENU::TEXT_RIGHT_MARGIN, orientation, __textRightMargin);
745         if (r != E_SUCCESS)
746         {
747                 return r;
748         }
749
750         r = GET_SHAPE_CONFIG(OPTIONMENU::TEXT_TOP_MARGIN, orientation, __textTopMargin);
751         if (r != E_SUCCESS)
752         {
753                 return r;
754         }
755
756         r = GET_SHAPE_CONFIG(OPTIONMENU::TEXT_BOTTOM_MARGIN, orientation, __textBottomMargin);
757         if (r != E_SUCCESS)
758         {
759                 return r;
760         }
761
762         r = GET_SHAPE_CONFIG(OPTIONMENU::ARROW_MARGIN, orientation, __arrowMargin);
763         if (r != E_SUCCESS)
764         {
765                 return r;
766         }
767
768         return E_SUCCESS;
769 }
770
771 result
772 _OptionMenuPresenter::CalculateBounds(void)
773 {
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.");
777
778         Dimension screenSize = pManager->GetScreenSize();
779         Rectangle bounds(0, 0, 0, __handleHeight);
780
781         int itemCount = GetItemCount();
782         if (itemCount > 0)
783         {
784                 __rowCount = (itemCount - 1) / __maxColumnCount + 1;
785                 if (__rowCount > 0)
786                 {
787                         __columnCount = itemCount / __rowCount;
788                         if ((itemCount % __rowCount) > 0)
789                         {
790                                 __columnCount++;
791                         }
792                 }
793                 else
794                 {
795                         __rowCount = 0;
796                         __columnCount = 0;
797                 }
798
799                 bounds.height += (__itemHeight + __lineWidth) * __rowCount - __lineWidth;
800         }
801
802         if ((__pOptionMenu != null) && (__pOptionMenu->GetOrientation() == _CONTROL_ORIENTATION_PORTRAIT))
803         {
804                 bounds.width = screenSize.width;
805                 bounds.y = screenSize.height - bounds.height;
806         }
807         else
808         {
809                 bounds.width = screenSize.height;
810                 bounds.y = screenSize.width - bounds.height;
811         }
812         __width = bounds.width;
813
814         if ((__pOptionMenu != null) && (bounds.height != __pOptionMenu->GetBounds().height))
815         {
816                 __pOptionMenu->SetMovable(true);
817                 __pOptionMenu->SetResizable(true);
818
819                 result r = __pOptionMenu->SetBounds(bounds);
820                 if (r != E_SUCCESS)
821                 {
822                         return r;
823                 }
824
825                 __pOptionMenu->SetMovable(false);
826                 __pOptionMenu->SetResizable(false);
827         }
828
829
830         return E_SUCCESS;
831 }
832
833 Rectangle
834 _OptionMenuPresenter::GetItemBounds(int index) const
835 {
836         if (__columnCount <= 0)
837         {
838                 return Rectangle(0, 0, 0, 0);
839         }
840
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))
847         {
848                 // Calculate last row
849                 bounds.x = column * __width / lastRowColumnCount;
850                 column++;
851                 bounds.width = column * __width / lastRowColumnCount - bounds.x;
852
853                 if (column < lastRowColumnCount)
854                 {
855                         bounds.width -= __lineWidth;
856                 }
857         }
858         else
859         {
860                 bounds.x = column * __width / __columnCount;
861                 column++;
862                 bounds.width = column * __width / __columnCount - bounds.x;
863
864                 if (column < __columnCount)
865                 {
866                         bounds.width -= __lineWidth;
867                 }
868         }
869
870         return bounds;
871 }
872
873 int
874 _OptionMenuPresenter::GetItemIndexFromPosition(const Point& position) const
875 {
876         if ((__columnCount <= 0)
877                 || (__width <= 0)
878                 || (position.y < __handleHeight)
879                 || (position.y >= __pOptionMenu->GetBounds().height))
880         {
881                 return -1;
882         }
883
884         int itemCount = __pOptionMenuModel->GetItemCount();
885         int row = (position.y - __handleHeight) / (__itemHeight + __lineWidth);
886         if ((row == (__rowCount - 1)) && ((itemCount % __columnCount) != 0))
887         {
888                 return (row * __columnCount) + position.x * (itemCount % __columnCount) / __width;
889         }
890
891         return (row * __columnCount) + position.x * __columnCount / __width;
892 }
893
894 result
895 _OptionMenuPresenter::LoadBitmap(void)
896 {
897         result r = E_SUCCESS;
898         Color color;
899         // Load Item Bitmap
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));
902
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));
906
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));
910
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));
914
915         // Load Item Pressed
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));
918
919         // Load Arrow Bitmap
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));
922
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));
926
927
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));
934
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));
938
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));
942
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));
946
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));
950
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));
954
955
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));
959
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));
963
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));
966
967         return E_SUCCESS;
968 CATCH:
969         delete __pItemBitmap;
970         __pItemBitmap = null;
971
972         delete __pItemPressedBitmap;
973         __pItemPressedBitmap = null;
974
975         delete __pItemPressedEffectBitmap;
976         __pItemPressedEffectBitmap = null;
977
978         delete __pArrowBitmap;
979         __pArrowBitmap = null;
980
981         delete __pArrowPressedBitmap;
982         __pArrowPressedBitmap = null;
983
984         delete __pHandleBitmap;
985         __pHandleBitmap = null;
986
987         delete __pHandleEffectBitmap;
988         __pHandleEffectBitmap = null;
989
990         delete __pHandlePressedBitmap;
991         __pHandlePressedBitmap = null;
992
993         delete __pHandlePressedEffectBitmap;
994         __pHandlePressedEffectBitmap = null;
995
996         return r;
997
998 }
999
1000 result
1001 _OptionMenuPresenter::PrepareAnimation(void)
1002 {
1003         result r = E_SUCCESS;
1004
1005         __pOptionMenuVE->SetAnimationProvider(this);
1006
1007         r = __pOptionMenuVE->SetSurfaceOpaque(false);
1008         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1009
1010         __pOptionMenuVE->SetOpacity(0.0f);
1011         __pOptionMenuVE->SetShowState(true);
1012
1013         return r;
1014 }
1015
1016 result
1017 _OptionMenuPresenter::SetOptionMenuVisibility(bool visibility)
1018 {
1019         SysTryReturnResult(NID_UI_CTRL, __pOptionMenuVE != null, E_INVALID_STATE, "[E_INVALID_STATE] OptionMenu VisualElement instance is null.");
1020
1021     result r = E_SUCCESS;
1022
1023         if (visibility == true)
1024         {
1025                 __pOptionMenuVE->SetTransformMatrix(_matrixScale);
1026
1027                 __pOptionMenuVE->SetImplicitAnimationEnabled(true);
1028         r = GetLastResult();
1029         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1030
1031         __pOptionMenuVE->SetTransformMatrix(_matrixOrigin);
1032         __pOptionMenuVE->SetOpacity(1.0f);
1033
1034         __pOptionMenuVE->SetImplicitAnimationEnabled(false);
1035         r = GetLastResult();
1036         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1037         }
1038         else
1039         {
1040                 __pOptionMenuVE->SetTransformMatrix(_matrixOrigin);
1041                 __pOptionMenuVE->SetOpacity(1.0f);
1042
1043                 __pOptionMenuVE->SetImplicitAnimationEnabled(true);
1044         r = GetLastResult();
1045         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1046
1047         __pOptionMenuVE->SetTransformMatrix(_matrixScale);
1048         __pOptionMenuVE->SetOpacity(0.0f);
1049
1050         __pOptionMenuVE->SetImplicitAnimationEnabled(false);
1051         r = GetLastResult();
1052         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1053         }
1054
1055         return E_SUCCESS;
1056
1057 }
1058
1059 VisualElementAnimation*
1060 _OptionMenuPresenter::CreateAnimationForProperty(VisualElement& target, const String& property)
1061 {
1062         VisualElementAnimation* pAnimation = VisualElementAnimationProvider::CreateAnimationForProperty(target, property);
1063
1064         if (pAnimation != null)
1065         {
1066                 result r = E_SUCCESS;
1067
1068                 __isAnimationStarted = true;
1069
1070                 if (__pOptionMenuVE == (static_cast <Tizen::Ui::Animations::_VisualElement*>(&target)))
1071                 {
1072                         String opacity = L"opacity";
1073
1074                         if (opacity == property)
1075                         {
1076                                 r = pAnimation->SetDuration(333);
1077                                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
1078
1079                                 __pThirtyThreeTimingFunction = new (std::nothrow) SineThirtyThreeTimingFunction();
1080                                 SysTryCatch(NID_UI_CTRL, (__pThirtyThreeTimingFunction != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1081
1082                                 pAnimation->SetTimingFunction(__pThirtyThreeTimingFunction);
1083                         }
1084                         else
1085                         {
1086                                 r = pAnimation->SetDuration(333);
1087                                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
1088
1089                                 __pSixtyTimingFunction = new (std::nothrow) SineSixtyTimingFunction();
1090                                 SysTryCatch(NID_UI_CTRL, (__pSixtyTimingFunction != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1091
1092                                 pAnimation->SetTimingFunction(__pSixtyTimingFunction);
1093                         }
1094                 }
1095
1096                 pAnimation->SetVisualElementAnimationStatusEventListener(this);
1097         }
1098
1099         return pAnimation;
1100
1101 CATCH:
1102         delete pAnimation;
1103
1104         return null;
1105 }
1106
1107 void
1108 _OptionMenuPresenter::OnVisualElementAnimationStarted(const Tizen::Ui::Animations::VisualElementAnimation& animation, const Tizen::Base::String& keyName, Tizen::Ui::Animations::VisualElement& target)
1109 {
1110         return;
1111 }
1112
1113 void
1114 _OptionMenuPresenter::OnVisualElementAnimationRepeated(const Tizen::Ui::Animations::VisualElementAnimation& animation, const Tizen::Base::String& keyName, Tizen::Ui::Animations::VisualElement& target, long currentRepeatCount)
1115 {
1116         return;
1117 }
1118
1119 void
1120 _OptionMenuPresenter::OnVisualElementAnimationFinished(const Tizen::Ui::Animations::VisualElementAnimation& animation, const Tizen::Base::String& keyName, Tizen::Ui::Animations::VisualElement& target, bool completedNormally)
1121 {
1122     SysTryReturnVoidResult(NID_UI_CTRL, __pOptionMenuVE != null, E_INVALID_STATE, "[E_INVALID_STATE] OptionMenu VisualElement instance is null.");
1123
1124     __isAnimationStarted = false;
1125
1126     if (__pOptionMenuVE == (static_cast <Tizen::Ui::Animations::_VisualElement*>(&target)))
1127         {
1128                 if (completedNormally == true)
1129                 {
1130                         __pOptionMenuVE->RemoveAllAnimations();
1131                         __pOptionMenuVE->SetAnimationProvider(null);
1132
1133                         if (__isClosing)
1134                         {
1135                                 __isClosing = false;
1136                                 __pOptionMenu->Close();
1137                         }
1138                 }
1139         }
1140
1141         return;
1142 }
1143
1144 void
1145 _OptionMenuPresenter::Hide(void)
1146 {
1147         __isClosing = true;
1148         PrepareAnimation();
1149         SetOptionMenuVisibility(false);
1150 }
1151
1152 result
1153 _OptionMenuPresenter::SetPosition(const Point& position)
1154 {
1155         __pOptionMenu->SetMovable(true);
1156
1157         result r = __pOptionMenu->SetPosition(position);
1158
1159         __pOptionMenu->SetMovable(false);
1160
1161         return r;
1162 }
1163
1164 void
1165 _OptionMenuPresenter::OnChangeLayout(_ControlOrientation orientation)
1166 {
1167         StopAnimation();
1168         LoadShapeResource(orientation);
1169         CalculateBounds();
1170 }
1171
1172 result
1173 _OptionMenuPresenter::StopAnimation(void)
1174 {
1175         if (__isAnimationStarted)
1176         {
1177                 if (__isClosing)
1178                 {
1179                         __isClosing = false;
1180                         if (__pOptionMenu != null && __pOptionMenuVE != null)
1181                         {
1182                                 __pOptionMenuVE->RemoveAllAnimations();
1183                                 __pOptionMenuVE->SetAnimationProvider(null);
1184
1185                                 __pOptionMenu->Close();
1186                         }
1187                 }
1188         }
1189
1190         return E_SUCCESS;
1191 }
1192
1193 result
1194 _OptionMenuPresenter::OnAttachingToMainTree(const _Control* pParent)
1195 {
1196         if (__pOptionMenu->GetOwner() == null)
1197         {
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.");
1201
1202                 _Form* pForm = pFrame->GetCurrentForm();
1203                 if (pForm != null)
1204                 {
1205                         __pOptionMenu->SetOwner(pForm);
1206                 }
1207                 else
1208                 {
1209                         __pOptionMenu->SetOwner(pFrame);
1210                 }
1211         }
1212
1213         return E_SUCCESS;
1214 }
1215
1216 result
1217 _OptionMenuPresenter::OnAttachedToMainTree(void)
1218 {
1219         return E_SUCCESS;
1220 }
1221
1222 result
1223 _OptionMenuPresenter::OnDetachingFromMainTree(void)
1224 {
1225         __pOptionMenu->SetOwner(null);
1226         return E_SUCCESS;
1227 }
1228
1229 void
1230 _OptionMenuPresenter::OnVisibleStateChanged(void)
1231 {
1232         if (__pOptionMenu->IsVisible() == true)
1233         {
1234                 if (_ControlManager::GetInstance()->GetTopWindow() == __pOptionMenu)
1235                 {
1236                         __pOptionMenu->SetTouchCapture();
1237                 }
1238         }
1239         else
1240         {
1241                 _TouchManager* pManager = _TouchManager::GetInstance();
1242                 if (pManager != null && pManager->GetCapturedControl() == __pOptionMenu)
1243                 {
1244                         __pOptionMenu->ReleaseTouchCapture();
1245                 }
1246         }
1247 }
1248
1249 bool
1250 _OptionMenuPresenter::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
1251 {
1252         if (&source != __pOptionMenu)
1253         {
1254                 return false;
1255         }
1256
1257         if (__pOptionMenu->IsSubMenuShown() == true)
1258         {
1259                 __pOptionMenu->DestroySubMenu();
1260                 __pOptionMenu->SetTouchCapture();
1261                 return true;
1262         }
1263
1264         Point position = touchinfo.GetCurrentPosition();
1265         __selectedIndex = GetItemIndexFromPosition(position);
1266         if (__selectedIndex >= 0)
1267         {
1268                 RefreshItem(__selectedIndex);
1269         }
1270         else if (__selectedIndex == -1 && position.y >= 0)
1271         {
1272                 __isHandlerPressed = true;
1273                 __pOptionMenu->Draw();
1274         }
1275         else
1276         {
1277                 Hide();
1278         }
1279
1280         return true;
1281 }
1282
1283 bool
1284 _OptionMenuPresenter::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
1285 {
1286         if (&source != __pOptionMenu)
1287         {
1288                 return false;
1289         }
1290
1291         if (__isHandlerPressed == true)
1292         {
1293                 __isHandlerPressed = false;
1294                 Hide();
1295                 return true;
1296         }
1297
1298         if (__selectedIndex >= 0)
1299         {
1300                 int selectedIndex = __selectedIndex;
1301                 __selectedIndex = -1;
1302                 RefreshItem(selectedIndex);
1303
1304                 _OptionMenuItem* pItem = __pOptionMenuModel->GetItem(selectedIndex);
1305                 if (pItem != null)
1306                 {
1307                         if (pItem->HasSubItem() == true)
1308                         {
1309                                 // Show SubItem
1310                                 __pOptionMenu->ShowSubMenu(selectedIndex, *pItem);
1311                         }
1312                         else
1313                         {
1314                                 // Fire Action Event
1315                                 Hide();
1316                                 __pOptionMenu->FireActionEvent(pItem->GetActionId());
1317                         }
1318                 }
1319         }
1320
1321         return true;
1322 }
1323
1324 bool
1325 _OptionMenuPresenter::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
1326 {
1327         if (&source != __pOptionMenu)
1328         {
1329                 return false;
1330         }
1331
1332         Point position = touchinfo.GetCurrentPosition();
1333         int selectedIndex = GetItemIndexFromPosition(position);
1334         if (__isHandlerPressed == true)
1335         {
1336                 if (selectedIndex >= 0 || position.y < 0)
1337                 {
1338                         __isHandlerPressed = false;
1339                         __pOptionMenu->Draw();
1340                 }
1341                 return true;
1342         }
1343
1344         if (__selectedIndex >= 0)
1345         {
1346                 if (selectedIndex != __selectedIndex)
1347                 {
1348                         selectedIndex = __selectedIndex;
1349                         __selectedIndex = -1;
1350                         RefreshItem(selectedIndex);
1351                 }
1352         }
1353
1354         return true;
1355 }
1356
1357 bool
1358 _OptionMenuPresenter::OnTouchCanceled(const Tizen::Ui::_Control& source, const Tizen::Ui::_TouchInfo& touchinfo)
1359 {
1360         if (&source != __pOptionMenu)
1361         {
1362                 return false;
1363         }
1364
1365         __isHandlerPressed = false;
1366         __selectedIndex = -1;
1367         __pOptionMenu->Draw();
1368
1369         return true;
1370 }
1371
1372 void
1373 _OptionMenuPresenter::OnActionPerformed(const _Control& source, int actionId)
1374 {
1375         // for SubMenu Events
1376         __pOptionMenu->DestroySubMenu();
1377         Hide();
1378         __pOptionMenu->FireActionEvent(actionId);
1379 }
1380
1381 void
1382 _OptionMenuPresenter::OnFontChanged(Font* pFont)
1383 {
1384         __pFont = pFont;
1385         return;
1386 }
1387
1388 void
1389 _OptionMenuPresenter::OnFontInfoRequested(unsigned long& style, int& size)
1390 {
1391         style = FONT_STYLE_PLAIN;
1392         size = __textSize;
1393         return;
1394 }
1395
1396 Font*
1397 _OptionMenuPresenter::GetFont(void) const
1398 {
1399         return __pFont;
1400 }
1401
1402 result
1403 _OptionMenuPresenter::DrawResourceBitmap(Canvas& canvas, const Rectangle& bounds, Bitmap* pBitmap)
1404 {
1405         result r = E_SUCCESS;
1406
1407         if (pBitmap == null)
1408         {
1409                 return r;
1410         }
1411
1412         if (pBitmap->IsNinePatchedBitmap())
1413         {
1414                 r = canvas.DrawNinePatchedBitmap(bounds, *pBitmap);
1415                 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
1416         }
1417         else
1418         {
1419                 r = canvas.DrawBitmap(bounds, *pBitmap);
1420                 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
1421         }
1422
1423         return r;
1424 }
1425
1426 }}} // Tizen::Ui::Controls