Fix a log error
[platform/framework/native/uifw.git] / src / ui / controls / FUiCtrl_OptionMenu.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0/
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 /**
19  * @file                FUiCtrl_OptionMenu.cpp
20  * @brief               This is the implementation file for the _OptionMenu class.
21  */
22
23 #include <FBaseErrorDefine.h>
24 #include <FBaseSysLog.h>
25 #include <FBaseColIEnumeratorT.h>
26
27 #include <FGrp_BitmapImpl.h>
28 #include "FUi_ControlImplManager.h"
29 #include "FUi_EcoreEvasMgr.h"
30 #include "FUi_ResourceManager.h"
31 #include "FUi_TouchManager.h"
32 #include "FUiAnim_VisualElement.h"
33 #include "FUiAnim_AnimationManager.h"
34 #include "FUi_AccessibilityContainer.h"
35 #include "FUi_AccessibilityElement.h"
36 #include "FUiCtrl_ActionEvent.h"
37 #include "FUiCtrl_Form.h"
38 #include "FUiCtrl_Frame.h"
39 #include "FUiCtrl_OptionMenu.h"
40 #include "FUiCtrl_Scroll.h"
41 #include "FUiCtrl_ContextMenu.h"
42 #include "FUiCtrl_OptionMenuItem.h"
43
44 using namespace Tizen::Graphics;
45 using namespace Tizen::Base;
46 using namespace Tizen::Media;
47 using namespace Tizen::Ui;
48 using namespace Tizen::Ui::Animations;
49 using namespace Runtime;
50
51 namespace {
52 static const float TOUCH_PRESS_THRESHOLD_INSENSITIVE = 0.16f;
53 }
54
55 namespace Tizen { namespace Ui { namespace Controls
56 {
57
58 IMPLEMENT_PROPERTY(_OptionMenu);
59
60 _OptionMenu::_OptionMenu(void)
61         : __pOptionMenuPresenter(null)
62         , __showItemCount(0)
63         , __isAttachedToMainTree(false)
64         , __isMaxVisibleCountSet(false)
65         , __isFocused(false)
66         , __currentFocusedIndex(-1)
67         , __selectedActionID(-1)
68         , __pBoundsTimingFunction(null)
69         , __pOpacityTimingFunction(null)
70         , __isAnimating(false)
71         , __windowRect(FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f))
72         , __bodyRect(FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f))
73         , __itemRect(FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f))
74         , __pActionEvent(null)
75         , __pBackgroundNormalBitmap(null)
76         , __pBackgroundEffectBitmap(null)
77         , __layout(_CONTROL_ORIENTATION_PORTRAIT)
78         , __rotation(_CONTROL_ROTATION_0)
79         , __pScrollPanel(null)
80         , __pSubMenu(null)
81         , __pCurrentFrame(null)
82         , __subMenuIndex(-1)
83 {
84         __backgroundColor = Color(255, 255, 255, 255);
85
86         __textColor[OPTION_MENU_CORE_ITEM_STATUS_NORMAL] = Color(255, 255, 255, 255);
87         __textColor[OPTION_MENU_CORE_ITEM_STATUS_PRESSED] = Color(255, 255, 255, 255);
88         __textColor[OPTION_MENU_CORE_ITEM_STATUS_HIGHLIGHTED] = Color(255, 255, 255, 255);
89
90         __itemColor[OPTION_MENU_CORE_ITEM_STATUS_NORMAL] = Color(255, 255, 255, 255);
91         __itemColor[OPTION_MENU_CORE_ITEM_STATUS_PRESSED] = Color(255, 255, 255, 255);
92         __itemColor[OPTION_MENU_CORE_ITEM_STATUS_HIGHLIGHTED] = Color(255, 255, 255, 255);
93 }
94
95 _OptionMenu::~_OptionMenu(void)
96 {
97         if (__isAttachedToMainTree && GetOwner() != null)
98         {
99                 GetOwner()->UnlockInputEvent();
100         }
101
102         if (__isAnimating && GetVisualElement())
103         {
104                 GetVisualElement()->RemoveAllAnimations();
105         }
106
107         __pCurrentFrame = null;
108
109         if (__pScrollPanel != null)
110         {
111                 __pScrollPanel->DetachAllChildren();
112                 DetachChild(*__pScrollPanel);
113                 delete __pScrollPanel;
114                 __pScrollPanel = null;
115         }
116
117         if (__pSubMenu != null)
118         {
119                 __pSubMenu->Close();
120                 delete __pSubMenu;
121                 __pSubMenu = null;
122         }
123
124         delete __pOptionMenuPresenter;
125         __pOptionMenuPresenter = null;
126
127         delete __pBackgroundNormalBitmap;
128         __pBackgroundNormalBitmap = null;
129
130         delete __pBackgroundEffectBitmap;
131         __pBackgroundEffectBitmap = null;
132
133         delete __pActionEvent;
134         __pActionEvent = null;
135
136         delete __pBoundsTimingFunction;
137         __pBoundsTimingFunction = null;
138
139         delete __pOpacityTimingFunction;
140         __pOpacityTimingFunction= null;
141
142         __actionId.RemoveAll();
143
144         RemoveAllAccessibilityElement();
145 }
146
147 _OptionMenu*
148 _OptionMenu::CreateOptionMenuN(void)
149 {
150         result r = E_SUCCESS;
151         float minWidth = 0.0f;
152         float minHeight = 0.0f;
153         _OptionMenu* pOptionMenu = null;
154         _ScrollPanel* pScrollPanel = null;
155         _Scroll* pScroll = null;
156
157         GET_SHAPE_CONFIG(OPTIONMENU::LIST_MIN_WIDTH,   _CONTROL_ORIENTATION_PORTRAIT, minWidth);
158         GET_SHAPE_CONFIG(OPTIONMENU::LIST_ITEM_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, minHeight);
159
160         pOptionMenu = new (std::nothrow) _OptionMenu();
161         SysTryReturn(NID_UI_CTRL, pOptionMenu != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
162
163         r = pOptionMenu->CreateRootVisualElement();
164         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
165
166         pOptionMenu->SetFocusable(true);
167
168         r = pOptionMenu->Initialize();
169         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to Initialize.", GetErrorMessage(r));
170
171         r = pOptionMenu->Install();
172         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to Install.", GetErrorMessage(r));
173
174         pOptionMenu->AcquireHandle();
175         pOptionMenu->SetTouchPressThreshold(TOUCH_PRESS_THRESHOLD_INSENSITIVE);
176
177         pOptionMenu->SetMovable(false);
178         pOptionMenu->SetResizable(false);
179
180         if (pOptionMenu->GetAccessibilityContainer() != null)
181         {
182                 pOptionMenu->GetAccessibilityContainer()->Activate(true);
183                 pOptionMenu->GetAccessibilityContainer()->AddListener(*pOptionMenu);
184         }
185
186         pScrollPanel = _ScrollPanel::CreateScrollPanelN(FloatRectangle(0.0f, 0.0f, minWidth, minHeight), SCROLL_PANEL_SCROLL_DIRECTION_VERTICAL, false, false);
187         pScrollPanel->SetTouchPressThreshold(TOUCH_PRESS_THRESHOLD_INSENSITIVE);
188
189         pScroll = pScrollPanel->GetScrollBar();
190         SysTryCatch(NID_UI_CTRL, pScroll, , E_INVALID_STATE, "[%s] _Scroll is not constructed", GetErrorMessage(E_INVALID_STATE));
191         pScroll->SetContextMenuScrollType(true);
192
193         pOptionMenu->AttachChild(*(pScrollPanel));
194
195         pOptionMenu->__pScrollPanel = pScrollPanel;
196
197         return pOptionMenu;
198
199 CATCH:
200         delete pOptionMenu;
201         delete pScrollPanel;
202
203         return null;
204 }
205
206 _ScrollPanel*
207 _OptionMenu::GetScrollPanel(void)
208 {
209         return __pScrollPanel;
210 }
211
212 bool
213 _OptionMenu::OnFocusGained(const _Control &source)
214 {
215         __currentFocusedIndex = 0;
216         __isFocused = false;
217
218         return true;
219 }
220
221 bool
222 _OptionMenu::OnFocusLost(const _Control &source)
223 {
224         __pOptionMenuPresenter->ClearFocus();
225         __isFocused = false;
226
227         return true;
228 }
229
230 void
231 _OptionMenu::OnDrawFocus(void)
232 {
233         if (!__isFocused)
234         {
235                 GetScrollPanel()->ScrollToTop();
236                 __isFocused = true;
237                 __currentFocusedIndex = 0;
238                 __pOptionMenuPresenter->DrawFocus(__currentFocusedIndex);
239         }
240
241         return;
242 }
243
244 void
245 _OptionMenu::OnFocusModeStateChanged(void)
246 {
247         __isFocused = false;
248         __pOptionMenuPresenter->ClearFocus();
249         return;
250 }
251
252 bool
253 _OptionMenu::OnKeyPressed(const _Control &source, const _KeyInfo &keyInfo)
254 {
255         _KeyCode keyCode = keyInfo.GetKeyCode();
256
257         if (!__isFocused)
258         {
259                 if (keyCode == _KEY_TAB || keyCode == _KEY_UP || keyCode == _KEY_DOWN)
260                 {
261                         __isFocused = true;
262                         __currentFocusedIndex = 0;
263                         __pOptionMenuPresenter->DrawFocus(__currentFocusedIndex);
264                 }
265                 return true;
266         }
267
268         int height = 0;
269         int dividerHeight = 0;
270         int count = GetMaximumVisibleItemsCount();
271         int totalItemCount = GetItemCount();
272
273         GET_SHAPE_CONFIG(OPTIONMENU::ITEM_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, height);
274         GET_SHAPE_CONFIG(OPTIONMENU::LIST_DIVIDER_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, dividerHeight);
275
276         switch (keyCode)
277         {
278         case _KEY_DOWN:
279                 if (__currentFocusedIndex < totalItemCount - 1)
280                 {
281                         if (__currentFocusedIndex < count - 1)
282                         {
283                                 __currentFocusedIndex++;
284                         }
285                         else
286                         {
287                                 int pos = GetScrollPanel()->GetScrollPosition();
288                                 GetScrollPanel()->SetScrollPosition(pos + height + 2 * dividerHeight);
289                                 __currentFocusedIndex++;
290                         }
291                 }
292                 else
293                 {
294                         __currentFocusedIndex = totalItemCount - 1;
295                 }
296                 break;
297
298         case _KEY_UP:
299                 if (__currentFocusedIndex > 0)
300                 {
301                         if (__currentFocusedIndex < count - 1)
302                         {
303                                 __currentFocusedIndex--;
304                         }
305                         else
306                         {
307                                 int pos = GetScrollPanel()->GetScrollPosition();
308                                 GetScrollPanel()->SetScrollPosition(pos - height - 2 * dividerHeight);
309                                 __currentFocusedIndex--;
310                         }
311                 }
312                 else
313                 {
314                         __currentFocusedIndex = 0;
315                 }
316                 break;
317
318         default:
319                 return true;
320         }
321
322         __pOptionMenuPresenter->DrawFocus(__currentFocusedIndex);
323
324         return true;
325 }
326
327 bool
328 _OptionMenu::OnKeyReleased(const _Control& source, const _KeyInfo& keyInfo)
329 {
330         _KeyCode keyCode = keyInfo.GetKeyCode();
331
332         if (keyCode ==  _KEY_ENTER && __isFocused)
333         {
334                 __pOptionMenuPresenter->OnEnterKeyReleased(__currentFocusedIndex);
335                 return true;
336         }
337
338         if (keyCode == _KEY_ESC || keyCode == _KEY_BACK)
339         {
340                 __isFocused = false;
341                 __pOptionMenuPresenter->ClearFocus();
342
343                 CloseAnimation(-1);
344                 return true;
345         }
346
347         if (keyCode == _KEY_CONTEXT_MENU || keyCode == _KEY_MENU)
348         {
349                 if (__isAttachedToMainTree)
350                 {
351                         CloseAnimation(-1);
352                 }
353                 else
354                 {
355
356                 }
357
358                 return true;
359         }
360
361         return false;
362 }
363
364 void
365 _OptionMenu::OnVisualElementAnimationFinished(const Tizen::Ui::Animations::VisualElementAnimation& animation, const Tizen::Base::String& keyName, Tizen::Ui::Animations::VisualElement& target, bool completedNormally)
366 {
367         if (keyName == L"ClosingOpacityAnimation" || keyName == L"OpeningOpacityAnimation")
368         {
369                 __isAnimating = false;
370         }
371
372         if (keyName == L"ClosingOpacityAnimation")
373         {
374                 SetVisibleState(false);
375
376                 if (__selectedActionID != -1)
377                 {
378                         FireActionEvent(__selectedActionID);
379                         __selectedActionID = -1;
380                 }
381         }
382 }
383
384 result
385 _OptionMenu::Install(void)
386 {
387         result r = E_SUCCESS;
388
389         // load bitmap of a background and arrow
390         r = LoadBitmap();
391         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to load bitmap.");
392
393         r = __actionId.Construct();
394         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to construct arraylist.");
395
396         _OptionMenuPresenter* pPresenter = new (std::nothrow) _OptionMenuPresenter(this);
397         SysTryReturnResult(NID_UI_CTRL, pPresenter != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
398
399         SetPresenter(*pPresenter);
400
401         r = pPresenter->Install();
402
403         return r;
404 }
405
406 result
407 _OptionMenu::Initialize(void)
408 {
409         result r = E_SUCCESS;
410         FloatDimension screen(0.0f, 0.0f);
411         Color backgroundColor(0, 0, 0, 0);
412         Color backgroundSelectedColor(0, 0, 0, 0);
413         Color itemTextColor(0, 0, 0, 0);
414         Color itemTextSelectedColor(0, 0, 0, 0);
415
416         screen = _ControlManager::GetInstance()->GetScreenSizeF();
417
418         r = SetBounds(FloatRectangle(0.0f, 0.0f, screen.width, screen.height));
419         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to set option menu bounds.");
420
421         SetMovable(false);
422         SetResizable(false);
423
424         GET_COLOR_CONFIG(OPTIONMENU::ITEM_BG_NORMAL, backgroundColor);
425         GET_COLOR_CONFIG(OPTIONMENU::ITEM_BG_PRESSED, backgroundSelectedColor);
426         GET_COLOR_CONFIG(OPTIONMENU::ITEM_TEXT_NORMAL, itemTextColor);
427         GET_COLOR_CONFIG(OPTIONMENU::ITEM_TEXT_PRESSED, itemTextSelectedColor);
428
429         __backgroundColor = backgroundColor;
430         __itemColor[OPTION_MENU_CORE_ITEM_STATUS_NORMAL] = backgroundColor;
431         __itemColor[OPTION_MENU_CORE_ITEM_STATUS_PRESSED] = backgroundSelectedColor;
432         __textColor[OPTION_MENU_CORE_ITEM_STATUS_NORMAL] = itemTextColor;
433         __textColor[OPTION_MENU_CORE_ITEM_STATUS_PRESSED] = itemTextSelectedColor;
434
435         if (GetVisualElement() != null)
436         {
437                 GetVisualElement()->SetSurfaceOpaque(false);
438         }
439
440         return r;
441 }
442
443 result
444 _OptionMenu::SetPresenter(const _OptionMenuPresenter& OptionMenuPresenter)
445 {
446         __pOptionMenuPresenter = const_cast <_OptionMenuPresenter*>(&OptionMenuPresenter);
447
448         return E_SUCCESS;
449 }
450
451 void
452 _OptionMenu::OnDraw(void)
453 {
454         __pOptionMenuPresenter->Draw();
455
456         if(unlikely((_AccessibilityManager::IsActivated())))
457         {
458                 _AccessibilityManager::GetInstance()->RequestAutoReading(_ACCESSIBILITY_AUTO_READING_MODE_FIRST_ITEM);
459         }
460
461         return;
462 }
463
464 result
465 _OptionMenu::OnAttachedToMainTree(void)
466 {
467         result r = E_SUCCESS;
468
469         __isAttachedToMainTree = true;
470
471         _Control* pOwner = GetOwner();
472         if (pOwner == null)
473         {
474                 __pCurrentFrame = dynamic_cast<_Frame*>(_ControlManager::GetInstance()->GetCurrentFrame());
475                 SysTryReturnResult(NID_UI_CTRL, __pCurrentFrame != null, E_SYSTEM, "Current frame instance is not available.");
476
477                 _Form* pForm = __pCurrentFrame->GetCurrentForm();
478                 pForm != null ? SetOwner(pForm) : SetOwner(__pCurrentFrame);
479
480                 pOwner = GetOwner();
481         }
482         else
483         {
484                 pOwner->LockInputEvent();
485         }
486
487         if (__pCurrentFrame != null)
488         {
489                 __pCurrentFrame->AddFrameEventListener(*this);
490         }
491
492         __layout = pOwner->GetOrientation();
493
494         _Window* pOwnerWindow = pOwner->GetRootWindow();
495
496         if (pOwnerWindow != null)
497         {
498                 int ownerRotation = GetEcoreEvasMgr()->GetEcoreEvas()->GetWindowRotation(*pOwnerWindow);
499                 switch (ownerRotation)
500                 {
501                 case 0:
502                         __rotation = _CONTROL_ROTATION_0;
503                         break;
504
505                 case 90:
506                         __rotation = _CONTROL_ROTATION_90;
507                         break;
508
509                 case 180:
510                         __rotation = _CONTROL_ROTATION_180;
511                         break;
512
513                 case 270:
514                         __rotation = _CONTROL_ROTATION_270;
515                         break;
516
517                 default:
518                         __rotation = _CONTROL_ROTATION_0;
519                         break;
520                 }
521         }
522
523         __pOptionMenuPresenter->CalculateItemMaximumWidth();
524
525         r = __pOptionMenuPresenter->CalculateWindowRect();
526         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
527
528         GetEcoreEvasMgr()->GetEcoreEvas()->SetWindowBounds(*this, GetBoundsF());
529
530         SetAllAccessibilityElement();
531
532         OpenAnimation();
533
534         return _Window::OnAttachedToMainTree();
535 }
536
537 result
538 _OptionMenu::OnDetachingFromMainTree(void)
539 {
540         ReleaseTouchCapture();
541
542         if (__pCurrentFrame != null)
543         {
544                 __pCurrentFrame->RemoveFrameEventListener(*this);
545         }
546
547         _Control* pOwner = GetOwner();
548         if (pOwner != null)
549         {
550                 pOwner->UnlockInputEvent();
551         }
552
553         __isAttachedToMainTree = false;
554
555         __pScrollPanel->ScrollToTop();
556
557         return _Window::OnDetachingFromMainTree();
558 }
559
560 void
561 _OptionMenu::OnFrameDeactivated(const _Frame& source)
562 {
563         DestroySubMenu();
564         SetVisibleState(false);
565         return;
566 }
567
568 void
569 _OptionMenu::OnFrameActivated(const _Frame& source)
570 {
571         return;
572 }
573
574 void
575 _OptionMenu::OnFrameMinimized(const _Frame& source)
576 {
577         return;
578 }
579 void
580 _OptionMenu::OnFrameRestored(const _Frame& source)
581 {
582         return;
583 }
584
585 void
586 _OptionMenu::OnActivated(void)
587 {
588         _TouchManager* pTouchManager = _TouchManager::GetInstance();
589
590         if (pTouchManager != null)
591         {
592                 pTouchManager->SetTouchCanceled(null);
593         }
594         SetTouchCapture(false, false);
595
596         return _Window::OnActivated();
597 }
598
599 void
600 _OptionMenu::OnDeactivated(void)
601 {
602         __pOptionMenuPresenter->ResetSelectedItem();
603         return _Window::OnDeactivated();
604 }
605
606 result
607 _OptionMenu::AddItem(const String& text, int actionId, const Bitmap* pNormalBitmap, const Bitmap* pPressedBitmap, const Bitmap* pHighlightedBitmap)
608 {
609         result r = E_SUCCESS;
610
611         SysTryReturnResult(NID_UI_CTRL, (GetItemIndexFromActionId(actionId) == -1), E_SYSTEM, "A system error has occurred."
612                         " The option menu already has an item with the same action id (%d)", actionId);
613
614         r = __pOptionMenuPresenter->AddItem(text, actionId, pNormalBitmap, pPressedBitmap, pHighlightedBitmap);
615         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to add a item.");
616
617         __actionId.Add(actionId);
618
619         if (__isAttachedToMainTree)
620         {
621                 __pOptionMenuPresenter->CalculateWindowRect();
622         }
623
624         return r;
625 }
626
627 result
628 _OptionMenu::InsertItemAt(int mainIndex, const String& text, int actionId, const Bitmap* pNormalBitmap, const Bitmap* pPressedBitmap, const Bitmap* pHighlightedBitmap)
629 {
630         result r = E_SUCCESS;
631
632         SysTryReturnResult(NID_UI_CTRL, (GetItemIndexFromActionId(actionId) == -1), E_SYSTEM, "A system error has occurred."
633                         " The option menu already has an item with the same action id (%d)", actionId);
634
635         r = __pOptionMenuPresenter->InsertItem(mainIndex, text, actionId, pNormalBitmap, pPressedBitmap, pHighlightedBitmap);
636         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to add a item.");
637
638         __actionId.InsertAt(actionId, mainIndex);
639
640         if (__isAttachedToMainTree)
641         {
642                 __pOptionMenuPresenter->CalculateWindowRect();
643         }
644
645         return r;
646 }
647
648 int
649 _OptionMenu::GetItemIndexFromActionId(int actionId) const
650 {
651         return __pOptionMenuPresenter->GetItemIndexFromActionId(actionId);
652 }
653
654 result
655 _OptionMenu::SetItemAt(int mainIndex, const String& text, int actionId, const Bitmap* pNormalBitmap, const Bitmap* pPressedBitmap, const Bitmap* pHighlightedBitmap)
656 {
657         result r = E_SUCCESS;
658
659         r = __pOptionMenuPresenter->SetItem(mainIndex, text, actionId, pNormalBitmap, pPressedBitmap, pHighlightedBitmap);
660         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to set a item.");
661
662         __actionId.SetAt(actionId, mainIndex);
663
664         if (__isAttachedToMainTree)
665         {
666                 __pOptionMenuPresenter->CalculateWindowRect();
667         }
668
669         return r;
670 }
671
672 result
673 _OptionMenu::AddSubItem(int mainIndex, const String& text, int actionId)
674 {
675         result r = __pOptionMenuPresenter->AddSubItem(mainIndex, text, actionId);
676         SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), r, "Propagating.");
677
678         if (__pSubMenu != null && mainIndex == __subMenuIndex)
679         {
680                 __pSubMenu->AddItem(text, actionId, null, null, null);
681         }
682
683         return E_SUCCESS;
684 }
685
686 result
687 _OptionMenu::InsertSubItemAt(int mainIndex, int subIndex, const String& text, int actionId)
688 {
689         result r = __pOptionMenuPresenter->InsertSubItemAt(mainIndex, subIndex, text, actionId);
690         SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), r, "Propagating.");
691
692         if (__pSubMenu != null && mainIndex == __subMenuIndex)
693         {
694                 __pSubMenu->InsertItem(subIndex, text, actionId, null, null, null);
695         }
696
697         return E_SUCCESS;
698 }
699
700 result
701 _OptionMenu::SetSubItemAt(int mainIndex, int subIndex, const String& text, int actionId)
702 {
703         result r = __pOptionMenuPresenter->SetSubItemAt(mainIndex, subIndex, text, actionId);
704         SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), r, "Propagating.");
705
706         if (__pSubMenu != null && mainIndex == __subMenuIndex)
707         {
708                 __pSubMenu->SetItem(subIndex, text, actionId, null, null, null);
709         }
710
711         return E_SUCCESS;
712 }
713
714 result
715 _OptionMenu::RemoveSubItemAt(int mainIndex, int subIndex)
716 {
717         result r = __pOptionMenuPresenter->RemoveSubItemAt(mainIndex, subIndex);
718         SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), r, "Propagating.");
719
720         if (__pSubMenu != null && mainIndex == __subMenuIndex)
721         {
722                 __pSubMenu->RemoveItemAt(subIndex);
723         }
724
725         return E_SUCCESS;
726 }
727
728 int
729 _OptionMenu::GetSubItemCount(int mainIndex) const
730 {
731         return __pOptionMenuPresenter->GetSubItemCount(mainIndex);
732 }
733
734 int
735 _OptionMenu::GetSubItemIndexFromActionId(int actionId) const
736 {
737         return __pOptionMenuPresenter->GetSubItemIndexFromActionId(actionId);
738 }
739
740 int
741 _OptionMenu::GetSubItemActionIdAt(int mainIndex, int subIndex) const
742 {
743         return __pOptionMenuPresenter->GetSubItemActionIdAt(mainIndex, subIndex);
744 }
745
746
747 result
748 _OptionMenu::ShowSubMenu(int mainIndex, _OptionMenuItem& item)
749 {
750         if (__pSubMenu != null)
751         {
752                 DestroySubMenu();
753         }
754
755         float textSize = 0.0f;
756         float itemHeight = 0.0f;
757
758         GET_SHAPE_CONFIG(OPTIONMENU::TEXT_SIZE, GetOrientation(), textSize);
759         GET_SHAPE_CONFIG(OPTIONMENU::LIST_ITEM_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, itemHeight);
760
761         FloatRectangle itemBounds = item.GetBoundsF();
762         itemBounds.height = itemHeight;
763         float scrollPosition = __pScrollPanel->GetScrollPosition();
764         FloatPoint anchorPosition(0.0f, 0.0f);
765         ContextMenuCoreAlign alignment = CONTEXT_MENU_CORE_ALIGN_RIGHT;
766
767         if (__rotation == _CONTROL_ROTATION_270 && __layout == _CONTROL_ORIENTATION_LANDSCAPE)
768         {
769                 alignment = CONTEXT_MENU_CORE_ALIGN_LEFT;
770         }
771         else
772         {
773                 alignment = CONTEXT_MENU_CORE_ALIGN_RIGHT;
774         }
775
776         anchorPosition = FloatPoint(GetBoundsF().x + itemBounds.x + itemBounds.width / 2.0f, GetBoundsF().y + itemBounds.y + itemBounds.height / 2.0f - scrollPosition);
777
778         __pSubMenu = _ContextMenu::CreateContextMenuN(anchorPosition, CONTEXT_MENU_CORE_STYLE_LIST, alignment);
779
780         if (__pSubMenu == null)
781         {
782                 return GetLastResult();
783         }
784
785         __pSubMenu->SetFocusable(true);
786
787         if (__pSubMenu->GetOwner() == null)
788         {
789                 _Frame* pFrame = dynamic_cast<_Frame*>(_ControlManager::GetInstance()->GetCurrentFrame());
790                 SysTryReturnResult(NID_UI_CTRL, pFrame != null, E_SYSTEM, "This instance is not constructed.");
791
792                 _Form* pForm = pFrame->GetCurrentForm();
793                 if (pForm != null)
794                 {
795                         __pSubMenu->SetOwner(pForm);
796                 }
797                 else
798                 {
799                         __pSubMenu->SetOwner(pFrame);
800                 }
801         }
802
803         __pSubMenu->Initialize();
804         __pSubMenu->AddActionEventListener(*this);
805
806         _OptionMenuItem* pSubItem = null;
807         int subItemCount = item.GetSubItemCount();
808         for (int subIndex = 0; subIndex < subItemCount; subIndex++)
809         {
810                 pSubItem = item.GetSubItem(subIndex);
811                 if (pSubItem != null)
812                 {
813                         __pSubMenu->AddItem(pSubItem->GetText(), pSubItem->GetActionId(), null, null, null);
814                 }
815         }
816
817         __pSubMenu->Open();
818         __subMenuIndex = mainIndex;
819
820         return E_SUCCESS;
821 }
822
823 bool
824 _OptionMenu::IsSubMenuShown(void) const
825 {
826         return (__pSubMenu != null) && __pSubMenu->IsAttached();
827 }
828
829 result
830 _OptionMenu::DestroySubMenu(void)
831 {
832         SysTryReturnResult(NID_UI_CTRL, __pSubMenu != null, E_SYSTEM, "A system error has occured. __pSubMenu is null.");
833
834         __pSubMenu->Close();
835         delete __pSubMenu;
836         __pSubMenu = null;
837
838         __subMenuIndex = -1;
839
840         return E_SUCCESS;
841 }
842
843 result
844 _OptionMenu::InsertItem(int index, const String& text, int actionId, const Bitmap* pNormalBitmap, const Bitmap* pPressedBitmap, const Bitmap* pHighlightedBitmap)
845 {
846         result r = E_SUCCESS;
847
848         r = __pOptionMenuPresenter->InsertItem(index, text, actionId, pNormalBitmap, pPressedBitmap, pHighlightedBitmap);
849         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to insert a item.");
850
851         __actionId.InsertAt(actionId, index);
852
853         if (__isAttachedToMainTree)
854         {
855                 __pOptionMenuPresenter->CalculateWindowRect();
856         }
857
858         return r;
859 }
860
861 result
862 _OptionMenu::SetItem(int index, const String& text, int actionId, const Bitmap* pNormalBitmap, const Bitmap* pPressedBitmap, const Bitmap* pHighlightedBitmap)
863 {
864         result r = E_SUCCESS;
865
866         r = __pOptionMenuPresenter->SetItem(index, text, actionId, pNormalBitmap, pPressedBitmap, pHighlightedBitmap);
867         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to set a item.");
868
869         __actionId.SetAt(actionId, index);
870
871         if (__isAttachedToMainTree)
872         {
873                 __pOptionMenuPresenter->CalculateWindowRect();
874         }
875
876         return r;
877 }
878
879 result
880 _OptionMenu::RemoveItemAt(int index)
881 {
882         result r = E_SUCCESS;
883
884         r = __pOptionMenuPresenter->DeleteItem(index);
885         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to remove a item.");
886
887         __actionId.RemoveAt(index);
888
889         if (__isAttachedToMainTree)
890         {
891                 __pOptionMenuPresenter->CalculateWindowRect();
892         }
893
894         return r;
895 }
896
897 void
898 _OptionMenu::RemoveAllItems(void)
899 {
900         result r = E_SUCCESS;
901
902         r = __pOptionMenuPresenter->DeleteItemAll();
903         SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Failed to remove all items.", GetErrorMessage(r));
904
905         __actionId.RemoveAll();
906
907         if (__isAttachedToMainTree)
908         {
909                 __pOptionMenuPresenter->CalculateWindowRect();
910         }
911
912         SetLastResult(r);
913         return;
914 }
915
916 int
917 _OptionMenu::GetItemCount(void) const
918 {
919         return __actionId.GetCount();
920 }
921
922 int
923 _OptionMenu::GetItemIndexAt(int actionId) const
924 {
925         int count = __actionId.GetCount();
926
927         for (int i = 0; i < count; i++)
928         {
929                 int index = GetItemActionIdAt(i);
930
931                 if (actionId == index)
932                 {
933                         return i;
934                 }
935         }
936
937         return -1;
938 }
939
940 int
941 _OptionMenu::GetItemActionIdAt(int index) const
942 {
943         int count = __actionId.GetCount();
944         int actionId = -1;
945
946         if (count <= 0 || index >= count)
947         {
948                 return -1;
949         }
950
951         __actionId.GetAt(index, actionId);
952
953         return actionId;
954 }
955
956 result
957 _OptionMenu::SetWindowRect(const FloatRectangle& rect)
958 {
959         __windowRect = rect;
960
961         return E_SUCCESS;
962 }
963
964 FloatRectangle
965 _OptionMenu::GetWindowRect(void) const
966 {
967         return __windowRect;
968 }
969
970 result
971 _OptionMenu::SetBodyRect(const FloatRectangle& rect)
972 {
973         __bodyRect = rect;
974
975         return E_SUCCESS;
976 }
977
978 FloatRectangle
979 _OptionMenu::GetBodyRect(void) const
980 {
981         return __bodyRect;
982 }
983
984 result
985 _OptionMenu::SetItemRect(const FloatRectangle& rect)
986 {
987         __itemRect = rect;
988
989         return E_SUCCESS;
990 }
991
992 FloatRectangle
993 _OptionMenu::GetItemRect(void) const
994 {
995         return __itemRect;
996 }
997
998 result
999 _OptionMenu::SetPropertyMaxVisibleItemsCount(const Variant& count)
1000 {
1001         int showCount = count.ToInt();
1002
1003         SysTryReturnResult(NID_UI_CTRL, showCount > 0, E_INVALID_ARG, "Invalid argument is used. Count is invalid.");
1004
1005         __showItemCount = showCount;
1006
1007         return E_SUCCESS;
1008 }
1009
1010 Variant
1011 _OptionMenu::GetPropertyMaxVisibleItemsCount(void) const
1012 {
1013         return Variant(__showItemCount);
1014 }
1015
1016 int
1017 _OptionMenu::GetMaximumVisibleItemsCount(void) const
1018 {
1019         Variant count = GetProperty("maxVisibleItemsCount");
1020
1021         return count.ToInt();
1022 }
1023
1024 result
1025 _OptionMenu::SetShowItemCount(int count)
1026 {
1027         result r;
1028
1029         r = SetProperty("maxVisibleItemsCount", Variant(count));
1030         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to set property.");
1031
1032         if (__isAttachedToMainTree)
1033         {
1034                 __pOptionMenuPresenter->CalculateWindowRect();
1035                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to calculate window.");
1036         }
1037
1038         return E_SUCCESS;
1039 }
1040
1041 result
1042 _OptionMenu::SetPropertyColor(const Variant& color)
1043 {
1044         __backgroundColor = color.ToColor();
1045
1046         result r = LoadColorReplacedBitmap(__backgroundColor);
1047         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "A system error has occurred. Failed to load the color replacement bitmap.");
1048
1049         return E_SUCCESS;
1050 }
1051
1052 Variant
1053 _OptionMenu::GetPropertyColor(void) const
1054 {
1055         return Variant(__backgroundColor);
1056 }
1057
1058 result
1059 _OptionMenu::SetColor(const Graphics::Color& color)
1060 {
1061         return SetProperty("color", Variant(color));
1062 }
1063
1064 Color
1065 _OptionMenu::GetColor(void) const
1066 {
1067         Variant color = GetProperty("color");
1068
1069         return color.ToColor();
1070 }
1071
1072 result
1073 _OptionMenu::SetMaxVisibleItemsCount(int maxItemsCount)
1074 {
1075         result r = SetPropertyMaxVisibleItemsCount(maxItemsCount);
1076         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1077
1078         __isMaxVisibleCountSet = true;
1079
1080         if (__isAttachedToMainTree)
1081         {
1082                 __pOptionMenuPresenter->CalculateWindowRect();
1083         }
1084
1085         return E_SUCCESS;
1086 }
1087
1088 result
1089 _OptionMenu::SetPropertyNormalItemColor(const Variant& color)
1090 {
1091         __itemColor[OPTION_MENU_CORE_ITEM_STATUS_NORMAL] = color.ToColor();
1092
1093         return __pOptionMenuPresenter->ApplyColorProperty();
1094 }
1095
1096 Variant
1097 _OptionMenu::GetPropertyNormalItemColor(void) const
1098 {
1099         return Variant(__itemColor[OPTION_MENU_CORE_ITEM_STATUS_NORMAL]);
1100 }
1101
1102 result
1103 _OptionMenu::SetPropertyPressedItemColor(const Variant& color)
1104 {
1105         __itemColor[OPTION_MENU_CORE_ITEM_STATUS_PRESSED] = color.ToColor();
1106
1107         return __pOptionMenuPresenter->ApplyColorProperty();
1108 }
1109
1110 Variant
1111 _OptionMenu::GetPropertyPressedItemColor(void) const
1112 {
1113         return Variant(__itemColor[OPTION_MENU_CORE_ITEM_STATUS_PRESSED]);
1114 }
1115
1116 result
1117 _OptionMenu::SetPropertyHighlightedItemColor(const Variant & color)
1118 {
1119         __itemColor[OPTION_MENU_CORE_ITEM_STATUS_HIGHLIGHTED] = color.ToColor();
1120
1121         return __pOptionMenuPresenter->ApplyColorProperty();
1122 }
1123
1124 Variant
1125 _OptionMenu::GetPropertyHighlightedItemColor(void) const
1126 {
1127         return Variant(__itemColor[OPTION_MENU_CORE_ITEM_STATUS_HIGHLIGHTED]);
1128 }
1129
1130 result
1131 _OptionMenu::SetItemColor(enum OptionMenuCoreItemStatus status, const Graphics::Color& color)
1132 {
1133         result r = E_SUCCESS;
1134
1135         if (status == OPTION_MENU_CORE_ITEM_STATUS_NORMAL)
1136         {
1137                 r = SetProperty("normalItemColor", Variant(color));
1138         }
1139         else if (status == OPTION_MENU_CORE_ITEM_STATUS_PRESSED)
1140         {
1141                 r = SetProperty("pressedItemColor", Variant(color));
1142         }
1143         else
1144         {
1145                 r = SetProperty("highlightedItemColor", Variant(color));
1146         }
1147
1148         return r;
1149 }
1150
1151 Color
1152 _OptionMenu::GetItemColor(enum OptionMenuCoreItemStatus status) const
1153 {
1154         Color itemColor;
1155
1156         if (status == OPTION_MENU_CORE_ITEM_STATUS_NORMAL)
1157         {
1158                 Variant color = GetProperty("normalItemColor");
1159                 itemColor = color.ToColor();
1160
1161         }
1162         else if (status == OPTION_MENU_CORE_ITEM_STATUS_PRESSED)
1163         {
1164                 Variant color = GetProperty("pressedItemColor");
1165                 itemColor = color.ToColor();
1166
1167         }
1168         else
1169         {
1170                 Variant color = GetProperty("highlightedItemColor");
1171                 itemColor = color.ToColor();
1172         }
1173
1174         return itemColor;
1175 }
1176
1177 result
1178 _OptionMenu::SetPropertyNormalItemTextColor(const Variant& color)
1179 {
1180         __textColor[OPTION_MENU_CORE_ITEM_STATUS_NORMAL] = color.ToColor();
1181
1182         return __pOptionMenuPresenter->ApplyColorProperty();
1183 }
1184
1185 Variant
1186 _OptionMenu::GetPropertyNormalItemTextColor(void) const
1187 {
1188         return Variant(__textColor[OPTION_MENU_CORE_ITEM_STATUS_NORMAL]);
1189 }
1190
1191 result
1192 _OptionMenu::SetPropertyPressedItemTextColor(const Variant& color)
1193 {
1194         __textColor[OPTION_MENU_CORE_ITEM_STATUS_PRESSED] = color.ToColor();
1195
1196         return __pOptionMenuPresenter->ApplyColorProperty();
1197 }
1198
1199 Variant
1200 _OptionMenu::GetPropertyPressedItemTextColor(void) const
1201 {
1202         return Variant(__textColor[OPTION_MENU_CORE_ITEM_STATUS_PRESSED]);
1203 }
1204
1205 result
1206 _OptionMenu::SetPropertyHighlightedItemTextColor(const Variant & color)
1207 {
1208         __textColor[OPTION_MENU_CORE_ITEM_STATUS_HIGHLIGHTED] = color.ToColor();
1209
1210         return __pOptionMenuPresenter->ApplyColorProperty();
1211 }
1212
1213 Variant
1214 _OptionMenu::GetPropertyHighlightedItemTextColor(void) const
1215 {
1216         return Variant(__textColor[OPTION_MENU_CORE_ITEM_STATUS_HIGHLIGHTED]);
1217 }
1218
1219 result
1220 _OptionMenu::SetTextColor(enum OptionMenuCoreItemStatus status, const Graphics::Color& color)
1221 {
1222         result r = E_SUCCESS;
1223
1224         if (status == OPTION_MENU_CORE_ITEM_STATUS_NORMAL)
1225         {
1226                 r = SetProperty("normalItemTextColor", Variant(color));
1227         }
1228         else if (status == OPTION_MENU_CORE_ITEM_STATUS_PRESSED)
1229         {
1230                 r = SetProperty("pressedItemTextColor", Variant(color));
1231         }
1232         else
1233         {
1234                 r = SetProperty("highlightedItemTextColor", Variant(color));
1235         }
1236
1237         return r;
1238 }
1239
1240 Color
1241 _OptionMenu::GetTextColor(enum OptionMenuCoreItemStatus status) const
1242 {
1243         Color textColor;
1244
1245         if (status == OPTION_MENU_CORE_ITEM_STATUS_NORMAL)
1246         {
1247                 Variant color = GetProperty("normalItemTextColor");
1248                 textColor = color.ToColor();
1249
1250         }
1251         else if (status == OPTION_MENU_CORE_ITEM_STATUS_PRESSED)
1252         {
1253                 Variant color = GetProperty("pressedItemTextColor");
1254                 textColor = color.ToColor();
1255
1256         }
1257         else
1258         {
1259                 Variant color = GetProperty("highlightedItemTextColor");
1260                 textColor = color.ToColor();
1261         }
1262
1263         return textColor;
1264 }
1265
1266 result
1267 _OptionMenu::AddActionEventListener(const _IActionEventListener& listener)
1268 {
1269         result r = E_SUCCESS;
1270
1271         if (__pActionEvent == null)
1272         {
1273                 __pActionEvent = _ActionEvent::CreateInstanceN(*this);
1274                 SysTryReturnResult(NID_UI_CTRL, __pActionEvent != null, GetLastResult(), "Propagating.");
1275
1276                 r = __pActionEvent->AddListener(listener);
1277                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to remove action event listener.");
1278         }
1279
1280         return r;
1281
1282 CATCH:
1283         delete __pActionEvent;
1284         __pActionEvent = null;
1285         return r;
1286 }
1287
1288 result
1289 _OptionMenu::RemoveActionEventListener(const _IActionEventListener& listener)
1290 {
1291         SysTryReturnResult(NID_UI_CTRL, __pActionEvent != null, E_INVALID_STATE,
1292                         "The action event instance isn't constructed.");
1293
1294         result r = E_SUCCESS;
1295
1296         r = __pActionEvent->RemoveListener(listener);
1297         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to remove action event listener");
1298
1299         return r;
1300 }
1301
1302 result
1303 _OptionMenu::FireActionEvent(int actionId)
1304 {
1305         IEventArg* pArg = _ActionEvent::CreateActionEventArgN(actionId);
1306         result r = GetLastResult();
1307         SysTryReturnResult(NID_UI_CTRL, (pArg != null), r, "Propagating.");
1308
1309         r = __pActionEvent->Fire(*pArg);
1310
1311         return r;
1312 }
1313
1314 _ActionEvent*
1315 _OptionMenu::GetActionEvent(void) const
1316 {
1317         return __pActionEvent;
1318 }
1319
1320 result
1321 _OptionMenu::LoadBitmap(void)
1322 {
1323         result r = E_SUCCESS;
1324         Color backgroundColor;
1325
1326         r = GET_BITMAP_CONFIG_N(OPTIONMENU::BG_EFFECT, BITMAP_PIXEL_FORMAT_ARGB8888, __pBackgroundEffectBitmap);
1327         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
1328
1329         backgroundColor = GetColor();
1330
1331         r = LoadColorReplacedBitmap(backgroundColor);
1332         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
1333
1334         return r;
1335
1336 CATCH:
1337         delete __pBackgroundEffectBitmap;
1338         __pBackgroundEffectBitmap = null;
1339
1340         return r;
1341 }
1342
1343 result
1344 _OptionMenu::LoadColorReplacedBitmap(const Color& color)
1345 {
1346         result r = E_SUCCESS;
1347
1348         // Delete old bitmap
1349         if (__pBackgroundNormalBitmap != null)
1350         {
1351                 delete __pBackgroundNormalBitmap;
1352                 __pBackgroundNormalBitmap = null;
1353         }
1354
1355         r = GET_REPLACED_BITMAP_CONFIG_N(OPTIONMENU::BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, color, __pBackgroundNormalBitmap);
1356         r = GetLastResult();
1357         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to load bitmap.");
1358
1359         return r;
1360 }
1361
1362 const Bitmap*
1363 _OptionMenu::GetBackgroundNormalBitmap(void) const
1364 {
1365         return __pBackgroundNormalBitmap;
1366 }
1367
1368 const Bitmap*
1369 _OptionMenu::GetBackgroundEffectBitmap(void) const
1370 {
1371         return __pBackgroundEffectBitmap;
1372 }
1373
1374 _UiTouchEventDelivery
1375 _OptionMenu::OnPreviewTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
1376 {
1377         return __pOptionMenuPresenter->OnPreviewTouchPressed(source, touchinfo);
1378 }
1379
1380 void
1381 _OptionMenu::OpenAnimation()
1382 {
1383         VisualElementPropertyAnimation* pBoundsAnimation;
1384         VisualElementPropertyAnimation* pOpacityAnimation;
1385
1386         _VisualElement* pVisualElement = GetVisualElement();
1387         SysTryReturnVoidResult(NID_UI_CTRL, pVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get visual element.");
1388
1389         FloatRectangle pEndBounds = pVisualElement->GetBounds();
1390         FloatRectangle pStartBounds(0.0f, 0.0f, 0.0f, 0.0f);
1391         pStartBounds = pEndBounds;
1392
1393         float animationDistance = 0.0f;
1394
1395         GET_SHAPE_CONFIG(OPTIONMENU::ANIMATION_DISTANCE_Y, _CONTROL_ORIENTATION_PORTRAIT, animationDistance);
1396
1397         pStartBounds.y += animationDistance;
1398
1399         pBoundsAnimation = new (std::nothrow) VisualElementPropertyAnimation();
1400         SysTryReturnVoidResult(NID_UI_CTRL, pBoundsAnimation != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1401
1402         pOpacityAnimation = new (std::nothrow) VisualElementPropertyAnimation();
1403         SysTryCatch(NID_UI_CTRL, pOpacityAnimation != null, , E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1404
1405         if (__pBoundsTimingFunction != null)
1406         {
1407                 delete __pBoundsTimingFunction;
1408                 __pBoundsTimingFunction = null;
1409         }
1410
1411         __pBoundsTimingFunction = new (std::nothrow) SineThirtyThreeTimingFunction();
1412         SysTryCatch(NID_UI_CTRL, __pBoundsTimingFunction != null, , E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1413
1414         pBoundsAnimation->SetPropertyName(L"bounds");
1415         pBoundsAnimation->SetStartValue(Variant(pStartBounds));
1416         pBoundsAnimation->SetEndValue(Variant(pEndBounds));
1417         pBoundsAnimation->SetTimingFunction(__pBoundsTimingFunction);
1418         pBoundsAnimation->SetDuration(ANIMATION_DURATION);
1419
1420         pBoundsAnimation->SetVisualElementAnimationStatusEventListener(this);
1421
1422         if (__pOpacityTimingFunction != null)
1423         {
1424                 delete __pOpacityTimingFunction;
1425                 __pOpacityTimingFunction = null;
1426         }
1427
1428         __pOpacityTimingFunction = new (std::nothrow) SineSixtyTimingFunction();
1429         SysTryCatch(NID_UI_CTRL, __pOpacityTimingFunction != null, , E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1430
1431         pOpacityAnimation->SetPropertyName(L"opacity");
1432         pOpacityAnimation->SetStartValue(Variant(0.0f));
1433         pOpacityAnimation->SetEndValue(Variant(1.0f));
1434         pBoundsAnimation->SetTimingFunction(__pOpacityTimingFunction);
1435         pOpacityAnimation->SetDuration(ANIMATION_DURATION);
1436
1437         pOpacityAnimation->SetVisualElementAnimationStatusEventListener(this);
1438
1439         pVisualElement->AddAnimation(L"OpeningBoundsAnimation", *pBoundsAnimation);
1440         pVisualElement->AddAnimation(L"OpeningOpacityAnimation", *pOpacityAnimation);
1441
1442         __isAnimating = true;
1443
1444         delete pBoundsAnimation;
1445
1446         delete pOpacityAnimation;
1447
1448         return;
1449
1450 CATCH:
1451         delete pBoundsAnimation;
1452         delete pOpacityAnimation;
1453
1454         delete __pBoundsTimingFunction;
1455         __pBoundsTimingFunction = null;
1456
1457         delete __pOpacityTimingFunction;
1458         __pOpacityTimingFunction = null;
1459
1460         return;
1461 }
1462
1463 void
1464 _OptionMenu::CloseAnimation(int actionId)
1465 {
1466         __selectedActionID = actionId;
1467
1468         VisualElementPropertyAnimation* pBoundsAnimation ;
1469         VisualElementPropertyAnimation* pOpacityAnimation;
1470
1471         _VisualElement* pVisualElement = GetVisualElement();
1472         SysTryReturnVoidResult(NID_UI_CTRL, pVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get visual element.");
1473
1474         FloatRectangle pStartBounds = pVisualElement->GetBounds();
1475         FloatRectangle pEndBounds(0.0f, 0.0f, 0.0f, 0.0f);
1476         pEndBounds = pStartBounds;
1477
1478         float animationDistance = 0.0f;
1479
1480         GET_SHAPE_CONFIG(OPTIONMENU::ANIMATION_DISTANCE_Y, _CONTROL_ORIENTATION_PORTRAIT, animationDistance);
1481
1482         pEndBounds.y += animationDistance;
1483
1484         pBoundsAnimation = new (std::nothrow) VisualElementPropertyAnimation();
1485         SysTryReturnVoidResult(NID_UI_CTRL, pBoundsAnimation != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1486
1487         pOpacityAnimation = new (std::nothrow) VisualElementPropertyAnimation();
1488         SysTryCatch(NID_UI_CTRL, pOpacityAnimation != null, , E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1489
1490         if (__pBoundsTimingFunction != null)
1491         {
1492                 delete __pBoundsTimingFunction;
1493                 __pBoundsTimingFunction = null;
1494         }
1495
1496         __pBoundsTimingFunction = new (std::nothrow) SineThirtyThreeTimingFunction();
1497         SysTryCatch(NID_UI_CTRL, __pBoundsTimingFunction != null, , E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1498
1499         pBoundsAnimation->SetPropertyName(L"bounds");
1500         pBoundsAnimation->SetStartValue(Variant(pStartBounds));
1501         pBoundsAnimation->SetEndValue(Variant(pEndBounds));
1502         pBoundsAnimation->SetTimingFunction(__pBoundsTimingFunction);
1503         pBoundsAnimation->SetEndValueApplied(false);
1504         pBoundsAnimation->SetDuration(ANIMATION_DURATION);
1505
1506         pBoundsAnimation->SetVisualElementAnimationStatusEventListener(this);
1507
1508         if (__pOpacityTimingFunction != null)
1509         {
1510                 delete __pOpacityTimingFunction;
1511                 __pOpacityTimingFunction = null;
1512         }
1513
1514         __pOpacityTimingFunction = new (std::nothrow) SineSixtyTimingFunction();
1515         SysTryCatch(NID_UI_CTRL, __pOpacityTimingFunction != null, , E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1516
1517         pOpacityAnimation->SetPropertyName(L"opacity");
1518         pOpacityAnimation->SetStartValue(Variant(1.0f));
1519         pOpacityAnimation->SetEndValue(Variant(0.0f));
1520         pBoundsAnimation->SetEndValueApplied(false);
1521         pBoundsAnimation->SetTimingFunction(__pOpacityTimingFunction);
1522         pOpacityAnimation->SetDuration(ANIMATION_DURATION);
1523
1524         pOpacityAnimation->SetVisualElementAnimationStatusEventListener(this);
1525
1526         pVisualElement->AddAnimation(L"ClosingBoundsAnimation", *pBoundsAnimation);
1527         pVisualElement->AddAnimation(L"ClosingOpacityAnimation", *pOpacityAnimation);
1528
1529         __isAnimating = true;
1530
1531         delete pBoundsAnimation;
1532         delete pOpacityAnimation;
1533
1534         return;
1535
1536 CATCH:
1537         delete pBoundsAnimation;
1538
1539         delete pOpacityAnimation;
1540
1541         delete __pBoundsTimingFunction;
1542         __pBoundsTimingFunction = null;
1543
1544         delete __pOpacityTimingFunction;
1545         __pOpacityTimingFunction = null;
1546
1547         return;
1548 }
1549
1550 bool
1551 _OptionMenu::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
1552 {
1553         return __pOptionMenuPresenter->OnTouchPressed(source, touchinfo);
1554 }
1555
1556 _UiTouchEventDelivery
1557 _OptionMenu::OnPreviewTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
1558 {
1559         return __pOptionMenuPresenter->OnPreviewTouchMoved(source, touchinfo);
1560 }
1561
1562 bool
1563 _OptionMenu::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
1564 {
1565         return __pOptionMenuPresenter->OnTouchMoved(source, touchinfo);
1566 }
1567
1568 _UiTouchEventDelivery
1569 _OptionMenu::OnPreviewTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
1570 {
1571         return __pOptionMenuPresenter->OnPreviewTouchReleased(source, touchinfo);
1572 }
1573
1574 bool
1575 _OptionMenu::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
1576 {
1577         return __pOptionMenuPresenter->OnTouchReleased(source, touchinfo);
1578 }
1579
1580 bool
1581 _OptionMenu::OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
1582 {
1583         __pOptionMenuPresenter->OnTouchCanceled(source, touchinfo);
1584
1585         SetVisibleState(false);
1586
1587         return true;
1588 }
1589
1590 void
1591 _OptionMenu::OnActionPerformed(const _Control& source, int actionId)
1592 {
1593         __pOptionMenuPresenter->OnActionPerformed(source, actionId);
1594 }
1595
1596 void
1597 _OptionMenu::OnFontChanged(Font* pFont)
1598 {
1599         return __pOptionMenuPresenter->OnFontChanged(pFont);
1600 }
1601
1602 void
1603 _OptionMenu::OnFontInfoRequested(unsigned long& style, float& size)
1604 {
1605         return __pOptionMenuPresenter->OnFontInfoRequested(style, size);
1606 }
1607
1608 void
1609 _OptionMenu::OnChangeLayout(_ControlRotation rotation)
1610 {
1611         __layout = GetOwner()->GetOrientation();
1612
1613         if (!__isMaxVisibleCountSet)
1614         {
1615                 GET_SHAPE_CONFIG(OPTIONMENU::MAX_VISIBLE_ITEM_COUNT, __layout, __showItemCount);
1616         }
1617
1618         if (__isAttachedToMainTree)
1619         {
1620                 if(__rotation != rotation)
1621                 {
1622                         SetVisibleState(false);
1623                 }
1624         }
1625
1626         __rotation =  rotation;
1627
1628         __pOptionMenuPresenter->ResetSelectedItem();
1629 }
1630
1631 void
1632 _OptionMenu::OnOwnerChanged(_Control* pOldOwner)
1633 {
1634         if (!__isAttachedToMainTree)
1635         {
1636                 return;
1637         }
1638
1639         _Control* pOwner = GetOwner();
1640
1641         if (pOldOwner != null)
1642         {
1643                 pOldOwner->UnlockInputEvent();
1644         }
1645
1646         if (pOwner != null)
1647         {
1648                 pOwner->LockInputEvent();
1649         }
1650 }
1651
1652 _AccessibilityElement*
1653 _OptionMenu::GetAccessibilityElement(const int mainIndex) const
1654 {
1655         _AccessibilityElement* pElement = null;
1656         result r = __accessibilityElements.GetAt(mainIndex, pElement);
1657         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed at AccessibilityElement.", GetErrorMessage(r));
1658
1659         return pElement;
1660
1661 CATCH:
1662         delete pElement;
1663
1664         return null;
1665 }
1666
1667 void
1668 _OptionMenu::AddAccessibilityElement(const _AccessibilityElement& element)
1669 {
1670         __accessibilityElements.Add(const_cast<_AccessibilityElement*>(&element));
1671 }
1672
1673 void
1674 _OptionMenu::SetAllAccessibilityElement(void)
1675 {
1676         RemoveAllAccessibilityElement();
1677         __pOptionMenuPresenter->SetAllAccessibilityElement();
1678 }
1679
1680 bool
1681 _OptionMenu::OnAccessibilityFocusMovedNext(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1682 {
1683         return false;
1684 }
1685
1686 bool
1687 _OptionMenu::OnAccessibilityFocusMovedPrevious(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1688 {
1689         return false;
1690 }
1691
1692 bool
1693 _OptionMenu::OnAccessibilityReadElement(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1694 {
1695         return false;
1696 }
1697
1698 bool
1699 _OptionMenu::OnAccessibilityReadingElement(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1700 {
1701         return false;
1702 }
1703
1704 bool
1705 _OptionMenu::OnAccessibilityFocusIn(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1706 {
1707         return false;
1708 }
1709
1710 bool
1711 _OptionMenu::OnAccessibilityFocusOut(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1712 {
1713         return false;
1714 }
1715
1716 bool
1717 _OptionMenu::OnAccessibilityActionPerformed(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1718 {
1719         CloseAnimation(-1);
1720
1721         return true;
1722 }
1723
1724 bool
1725 _OptionMenu::OnAccessibilityValueIncreased(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1726 {
1727         return false;
1728 }
1729
1730 bool
1731 _OptionMenu::OnAccessibilityValueDecreased(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1732 {
1733         return false;
1734 }
1735
1736 void
1737 _OptionMenu::RemoveAllAccessibilityElement(void)
1738 {
1739         _AccessibilityContainer* pAccessibilityContainer = GetAccessibilityContainer();
1740         if (pAccessibilityContainer != null && pAccessibilityContainer->IsActivated())
1741         {
1742                 pAccessibilityContainer->RemoveAllElement();
1743         }
1744
1745         return;
1746 }
1747
1748 _OptionMenuItemInfo
1749 _OptionMenu::GetItemFromPosition(const FloatPoint& position) const
1750 {
1751         return __pOptionMenuPresenter->GetItemFromPosition(position);
1752 }
1753
1754 _OptionMenuItemInfo
1755 _OptionMenu::FindItem(int index) const
1756 {
1757         return __pOptionMenuPresenter->FindItem(index);
1758 }
1759
1760 result
1761 _OptionMenu::SetTopDrawnItemIndex(int index)
1762 {
1763         return __pOptionMenuPresenter->SetTopDrawnItemIndex(index);
1764 }
1765
1766 _ControlOrientation
1767 _OptionMenu::GetLayout(void) const
1768 {
1769         return __layout;
1770 }
1771
1772 _ControlRotation
1773 _OptionMenu::GetRotation(void) const
1774 {
1775         return __rotation;
1776 }
1777
1778 }}} // Tizen::Ui: Control