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