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