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