Tizen 2.1 base
[framework/osp/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 Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://floralicense.org/license/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 /**
18  * @file                FUiCtrl_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_ResourceManager.h"
28 #include "FUiAnim_VisualElement.h"
29 #include "FUiAnim_AnimationManager.h"
30 #include "FUi_AccessibilityContainer.h"
31 #include "FUi_AccessibilityElement.h"
32 #include "FUiCtrl_Form.h"
33 #include "FUiCtrl_Frame.h"
34 #include "FUiCtrl_ContextMenu.h"
35
36 using namespace Tizen::Graphics;
37 using namespace Tizen::Media;
38 using namespace Tizen::Ui::Animations;
39
40 namespace Tizen { namespace Ui { namespace Controls
41 {
42
43 IMPLEMENT_PROPERTY(_ContextMenu);
44
45 _ContextMenu::_ContextMenu(const Point& point, enum ContextMenuCoreStyle style, enum ContextMenuCoreAlign contextMenuAlign)
46         : __pContextMenuPresenter(null)
47         , __style(style)
48         , __align(contextMenuAlign)
49         , __showItemCount(MAX_CONTEXTMENU_LIST_SHOW_ITEM)
50         , __showItemMaxCount(0)
51         , __isAttachedToMainTree(false)
52         , __ownerInputEnableState(false)
53         , __anchorPoint(point)
54         , __bodyRect(Rectangle(0, 0, 0, 0))
55         , __arrowRect(Rectangle(0, 0, 0, 0))
56         , __windowRect(Rectangle(0, 0, 0, 0))
57         , __pActionEvent(null)
58         , __pBackgroundNormalBitmap(null)
59         , __pBackgroundEffectBitmap(null)
60         , __dropPosition(CONTEXT_MENU_CORE_DROP_POSITION_INVALID)
61         , __layout(_CONTROL_ORIENTATION_PORTRAIT)
62         , __pScrollPanel(null)
63 {
64         __backgroundColor = Color(255, 255, 255, 255);
65
66         __textColor[CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL] = Color(255, 255, 255, 255);
67         __textColor[CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED] = Color(255, 255, 255, 255);
68         __textColor[CONTEXT_MENU_CORE_ITEM_STATUS_HIGHLIGHTED] = Color(255, 255, 255, 255);
69
70         __itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL] = Color(255, 255, 255, 255);
71         __itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED] = Color(255, 255, 255, 255);
72         __itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_HIGHLIGHTED] = Color(255, 255, 255, 255);
73
74         for (int i = 0; i < CONTEXT_MENU_CORE_DROP_POSITION_MAX; i++)
75         {
76                 __pArrowNormalBitmap[i] = null;
77                 __pArrowEffectBitmap[i] = null;
78         }
79 }
80
81 _ContextMenu::~_ContextMenu(void)
82 {
83         _Control* pOwner = GetOwner();
84         if (__isAttachedToMainTree == true && pOwner != null)
85         {
86                 pOwner->SetInputEnableState(__ownerInputEnableState);
87         }
88
89         if (__pScrollPanel) {
90                 __pScrollPanel->DetachAllChildren();
91                 DetachChild(*__pScrollPanel);
92                 delete __pScrollPanel;
93                 __pScrollPanel = null;
94         }
95
96         delete __pContextMenuPresenter;
97         __pContextMenuPresenter = null;
98
99         if (__pBackgroundNormalBitmap != null)
100         {
101                 delete __pBackgroundNormalBitmap;
102                 __pBackgroundNormalBitmap = null;
103         }
104
105         if (__pBackgroundEffectBitmap != null)
106         {
107                 delete __pBackgroundEffectBitmap;
108                 __pBackgroundEffectBitmap = null;
109         }
110
111         if (__pActionEvent)
112         {
113                 delete __pActionEvent;
114                 __pActionEvent = null;
115         }
116
117         for (int i = 0; i < CONTEXT_MENU_CORE_DROP_POSITION_MAX; i++)
118         {
119                 delete __pArrowNormalBitmap[i];
120                 __pArrowNormalBitmap[i] = null;
121
122                 delete __pArrowEffectBitmap[i];
123                 __pArrowEffectBitmap[i] = null;
124         }
125
126         __actionId.RemoveAll();
127
128         RemoveAllAccessibilityElement();
129 }
130
131
132 bool
133 _ContextMenu::IsActivatedOnOpen(void) const
134 {
135         return false;
136 }
137
138 _ContextMenu*
139 _ContextMenu::CreateContextMenuN(const Point& point, enum ContextMenuCoreStyle style, enum ContextMenuCoreAlign contextMenuAlign)
140 {
141         _ContextMenu* pContextMenu = new (std::nothrow) _ContextMenu(point, style, contextMenuAlign);
142         SysTryReturn(NID_UI_CTRL, pContextMenu != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
143
144         result r = E_SUCCESS;
145
146 #if defined(MULTI_WINDOW)
147         r = pContextMenu->CreateRootVisualElement();
148         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
149
150         pContextMenu->SetActivationEnabled(false);
151 #endif
152
153         r = pContextMenu->Initialize();
154         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to Initialize.", GetErrorMessage(r));
155
156         r = pContextMenu->Install();
157         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to Install.", GetErrorMessage(r));
158
159         pContextMenu->AcquireHandle();
160
161         if (pContextMenu->GetAccessibilityContainer() != null)
162         {
163                 pContextMenu->GetAccessibilityContainer()->Activate(true);
164         }
165
166         if (style == CONTEXT_MENU_CORE_STYLE_LIST)
167         {
168                 int minWidth, minHeight;        // for visible scrollbar when scrollable
169                 GET_SHAPE_CONFIG(CONTEXTMENU::LIST_MIN_WIDTH, _CONTROL_ORIENTATION_PORTRAIT, minWidth);
170                 GET_SHAPE_CONFIG(CONTEXTMENU::LIST_ITEM_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, minHeight);
171                 pContextMenu->__pScrollPanel = _ScrollPanel::CreateScrollPanelN(Rectangle(0, 0, minWidth, minHeight), SCROLL_PANEL_SCROLL_DIRECTION_VERTICAL, false, false);
172                 pContextMenu->AttachChild(*(pContextMenu->__pScrollPanel));
173         }
174
175         return pContextMenu;
176
177 CATCH:
178         delete pContextMenu;
179
180         return null;
181 }
182
183 _ScrollPanel*
184 _ContextMenu::GetScrollPanel(void)
185 {
186         return __pScrollPanel;
187 }
188
189 result
190 _ContextMenu::Install(void)
191 {
192         result r = E_SUCCESS;
193
194         // load bitmap of a background and arrow
195         r = LoadBitmap();
196         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to load bitmap.");
197
198         r = __actionId.Construct();
199         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to construct arraylist.");
200
201         if (__style == CONTEXT_MENU_CORE_STYLE_LIST)
202         {
203                 _IContextMenuPresenter* pPresenter = new (std::nothrow) _ContextMenuListPresenter(this);
204                 SysTryReturnResult(NID_UI_CTRL, pPresenter != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
205
206                 SetPresenter(*pPresenter);
207
208                 r = pPresenter->Install();
209         }
210         else
211         {
212                 _IContextMenuPresenter* pPresenter = new (std::nothrow) _ContextMenuGridPresenter(this);
213                 SysTryReturnResult(NID_UI_CTRL, pPresenter != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
214
215                 SetPresenter(*pPresenter);
216
217                 r = pPresenter->Install();
218         }
219
220         return r;
221 }
222
223 result
224 _ContextMenu::Initialize(void)
225 {
226         Dimension screen = _ControlManager::GetInstance()->GetScreenSize();
227         result r = E_SUCCESS;
228
229         Color backgroundColor;
230         Color backgroundSelectedColor;
231         Color itemTextColor;
232         Color itemTextSelectedColor;
233
234         r = SetBounds(Rectangle(0, 0, screen.width, screen.height));
235         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "SetBounds failed.");
236
237         SetMovable(false);   // To do Modify
238         SetResizable(false); // To do Modify
239
240         GET_COLOR_CONFIG(CONTEXTMENU::BG_NORMAL, backgroundColor);
241         GET_COLOR_CONFIG(CONTEXTMENU::ITEM_BG_PRESSED, backgroundSelectedColor);
242         GET_COLOR_CONFIG(CONTEXTMENU::ITEM_TEXT_NORMAL, itemTextColor);
243         GET_COLOR_CONFIG(CONTEXTMENU::ITEM_TEXT_PRESSED, itemTextSelectedColor);
244
245         __backgroundColor = backgroundColor;
246         __itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL] = backgroundColor;
247         __itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED] = backgroundSelectedColor;
248         __textColor[CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL] = itemTextColor;
249         __textColor[CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED] = itemTextSelectedColor;
250
251         if (GetVisualElement() != null)
252         {
253                 GetVisualElement()->SetSurfaceOpaque(false);
254         }
255
256         return r;
257
258 }
259
260 result
261 _ContextMenu::SetPresenter(const _IContextMenuPresenter& ContextMenuPresenter)
262 {
263         __pContextMenuPresenter = const_cast <_IContextMenuPresenter*>(&ContextMenuPresenter);
264
265         return E_SUCCESS;
266 }
267
268 void
269 _ContextMenu::OnDraw()
270 {
271         __pContextMenuPresenter->Draw();
272 }
273
274 result
275 _ContextMenu::OnAttachedToMainTree(void)
276 {
277         result r = E_SUCCESS;
278
279         if (GetOwner() == null)
280         {
281                 _Frame* pFrame = dynamic_cast<_Frame*>(_ControlManager::GetInstance()->GetCurrentFrame());
282                 SysTryReturn(NID_UI_CTRL, pFrame != null, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Current frame instance is not available.");
283
284                 _Form* pForm = pFrame->GetCurrentForm();
285                 if (pForm != null)
286                 {
287                         SetOwner(pForm);
288                 }
289                 else
290                 {
291                         SetOwner(pFrame);
292                 }
293         }
294
295         _Control* pOwner = GetOwner();
296         if (pOwner != null && __isAttachedToMainTree == false)
297         {
298                 __ownerInputEnableState = pOwner->GetInputEnableState();
299                 pOwner->SetInputEnableState(false);
300         }
301
302         __layout = _ControlManager::GetInstance()->GetOrientation();
303         AdjustDropPosition();
304         GET_SHAPE_CONFIG(CONTEXTMENU::ITEM_MAX_COUNT, __layout, __showItemMaxCount);
305
306         if (GetItemCount() <= 0)
307         {
308                 __pContextMenuPresenter->CalculateShowItemCount();
309         }
310
311         __pContextMenuPresenter->CalculateWindowRect();
312
313         r = Open();
314
315         SetVisibleState(true);
316
317         if (__style == CONTEXT_MENU_CORE_STYLE_LIST)
318         {
319                 SetTouchCapture();
320         }
321         else
322         {
323                 SetTouchCapture(true);
324         }
325
326         SetAllAccessibilityElement();
327
328         __isAttachedToMainTree = true;
329
330         return r;
331 }
332
333 result
334 _ContextMenu::OnDetachingFromMainTree(void)
335 {
336         result r = E_SUCCESS;
337
338         ReleaseTouchCapture();
339
340         _Control* pOwner = GetOwner();
341         if (pOwner != null)
342         {
343                 pOwner->SetInputEnableState(__ownerInputEnableState);
344         }
345
346         __isAttachedToMainTree = false;
347
348         return r;
349 }
350
351 result
352 _ContextMenu::AddItem(const Base::String& text, int actionId, const Bitmap* pNormalBitmap, const Bitmap* pPressedBitmap,
353                                           const Bitmap* pHighlightedBitmap)
354 {
355         result r = E_SUCCESS;
356
357         r = __pContextMenuPresenter->AddItem(text, actionId, pNormalBitmap, pPressedBitmap, pHighlightedBitmap);
358         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to add a item.");
359
360         __actionId.Add(actionId);
361
362         __pContextMenuPresenter->CalculateShowItemCount();
363         __pContextMenuPresenter->CalculateWindowRect();
364
365         return r;
366 }
367
368 result
369 _ContextMenu::InsertItem(int index, const Base::String& text, int actionId, const Bitmap* pNormalBitmap,
370                                                  const Bitmap* pPressedBitmap,
371                                                  const Bitmap* pHighlightedBitmap)
372 {
373         result r = E_SUCCESS;
374
375         r = __pContextMenuPresenter->InsertItem(index, text, actionId, pNormalBitmap, pPressedBitmap, pHighlightedBitmap);
376         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to insert a item.");
377
378         __actionId.InsertAt(actionId, index);
379
380         __pContextMenuPresenter->CalculateShowItemCount();
381         __pContextMenuPresenter->CalculateWindowRect();
382
383         return r;
384 }
385
386 result
387 _ContextMenu::SetItem(int index, const Base::String& text, int actionId, const Bitmap* pNormalBitmap,
388                                           const Bitmap* pPressedBitmap, const Bitmap* pHighlightedBitmap)
389 {
390         result r = E_SUCCESS;
391
392         r = __pContextMenuPresenter->SetItem(index, text, actionId, pNormalBitmap, pPressedBitmap, pHighlightedBitmap);
393         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to set a item.");
394
395         __actionId.SetAt(actionId, index);
396
397         __pContextMenuPresenter->CalculateWindowRect();
398
399         return r;
400 }
401
402 result
403 _ContextMenu::RemoveItemAt(int index)
404 {
405         result r = E_SUCCESS;
406
407         r = __pContextMenuPresenter->DeleteItem(index);
408         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to remove a item.");
409
410         __actionId.RemoveAt(index);
411
412         __pContextMenuPresenter->CalculateShowItemCount();
413         __pContextMenuPresenter->CalculateWindowRect();
414
415         return r;
416 }
417
418 result
419 _ContextMenu::RemoveAllItems(void)
420 {
421         result r = E_SUCCESS;
422
423         r = __pContextMenuPresenter->DeleteItemAll();
424         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to remove all items.");
425
426         __actionId.RemoveAll();
427
428         __pContextMenuPresenter->CalculateShowItemCount();
429         __pContextMenuPresenter->CalculateWindowRect();
430
431         return r;
432 }
433
434 int
435 _ContextMenu::GetItemCount(void) const
436 {
437         return __actionId.GetCount();
438 }
439
440 int
441 _ContextMenu::GetItemIndexAt(int actionId) const
442 {
443         int count = __actionId.GetCount();
444
445         for (int i = 0; i < count; i++)
446         {
447                 int index = GetItemActionIdAt(i);
448
449                 if (actionId == index)
450                 {
451                         return i;
452                 }
453         }
454
455         return -1;
456 }
457
458 int
459 _ContextMenu::GetItemActionIdAt(int index) const
460 {
461         int count = __actionId.GetCount();
462         int actionId = -1;
463
464         if (count <= 0 || index >= count)
465         {
466                 return -1;
467         }
468
469         __actionId.GetAt(index, actionId);
470
471         return actionId;
472 }
473
474 result
475 _ContextMenu::SetAnchorPosition(int x, int y)
476 {
477         __anchorPoint.x = x;
478         __anchorPoint.y = y;
479
480         if (__align == CONTEXT_MENU_CORE_ALIGN_AUTO)
481         {
482                 AdjustDropPosition();
483         }
484
485         __pContextMenuPresenter->CalculateWindowRect();
486         return E_SUCCESS;
487 }
488
489 Point
490 _ContextMenu::GetAnchorPosition(void) const
491 {
492         return __anchorPoint;
493 }
494
495 result
496 _ContextMenu::SetBodyRect(const Rectangle& rect)
497 {
498         __bodyRect = rect;
499
500         return E_SUCCESS;
501 }
502
503 Rectangle
504 _ContextMenu::GetBodyRect(void) const
505 {
506         return __bodyRect;
507 }
508
509 result
510 _ContextMenu::SetArrowRect(const Rectangle& rect)
511 {
512         __arrowRect = rect;
513
514         return E_SUCCESS;
515 }
516
517 Rectangle
518 _ContextMenu::GetArrowRect(void) const
519 {
520         return __arrowRect;
521 }
522
523 result
524 _ContextMenu::SetWindowRect(const Rectangle& rect)
525 {
526         __windowRect = rect;
527
528         return E_SUCCESS;
529 }
530
531 Rectangle
532 _ContextMenu::GetWindowRect(void) const
533 {
534         return __windowRect;
535 }
536
537 result
538 _ContextMenu::SetPropertyMaxVisibleItemsCount(const Variant& count)
539 {
540         int showCount = count.ToInt();
541
542         if (showCount < 1)
543         {
544                 SysLogException(NID_UI_CTRL, E_INVALID_ARG, "Count is invalid.");
545                 return E_INVALID_ARG;
546         }
547
548
549         __showItemCount = showCount;
550
551         return E_SUCCESS;
552 }
553
554 Variant
555 _ContextMenu::GetPropertyMaxVisibleItemsCount(void) const
556 {
557         return Tizen::Ui::Variant(__showItemCount);
558 }
559
560 int
561 _ContextMenu::GetShowItemCount(void) const
562 {
563         Variant count = GetProperty("maxVisibleItemsCount");
564
565         return count.ToInt();
566 }
567
568 int
569 _ContextMenu::GetShowItemMaxCount(void) const
570 {
571         return __showItemMaxCount;
572 }
573
574 result
575 _ContextMenu::SetShowItemCount(int count)
576 {
577         result r;
578
579         r = SetProperty("maxVisibleItemsCount", Variant(count));
580         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to set property.");
581
582         if (__style == CONTEXT_MENU_CORE_STYLE_LIST)
583         {
584                 r = __pContextMenuPresenter->CalculateWindowRect();
585                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to calculate window.");
586         }
587
588         return E_SUCCESS;
589 }
590
591 result
592 _ContextMenu::SetPropertyColor(const Variant& color)
593 {
594         __backgroundColor = color.ToColor();
595
596         LoadColorReplacedBitmap(__backgroundColor);
597
598         return E_SUCCESS;
599 }
600
601 Variant
602 _ContextMenu::GetPropertyColor(void) const
603 {
604         return Tizen::Ui::Variant(__backgroundColor);
605 }
606
607 result
608 _ContextMenu::SetColor(const Graphics::Color& color)
609 {
610         return SetProperty("color", Variant(color));
611 }
612
613 Color
614 _ContextMenu::GetColor(void) const
615 {
616         Variant color = GetProperty("color");
617
618         return color.ToColor();
619 }
620
621 result
622 _ContextMenu::SetPropertyNormalItemColor(const Variant& color)
623 {
624         __itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL] = color.ToColor();
625
626         return __pContextMenuPresenter->ApplyColorProperty();
627 }
628
629 Variant
630 _ContextMenu::GetPropertyNormalItemColor(void) const
631 {
632         return Tizen::Ui::Variant(__itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL]);
633 }
634
635 result
636 _ContextMenu::SetPropertyPressedItemColor(const Variant& color)
637 {
638         __itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED] = color.ToColor();
639
640         return __pContextMenuPresenter->ApplyColorProperty();
641 }
642
643 Variant
644 _ContextMenu::GetPropertyPressedItemColor(void) const
645 {
646         return Tizen::Ui::Variant(__itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED]);
647 }
648
649 result
650 _ContextMenu::SetPropertyHighlightedItemColor(const Variant & color)
651 {
652         __itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_HIGHLIGHTED] = color.ToColor();
653
654         return __pContextMenuPresenter->ApplyColorProperty();
655 }
656
657 Variant
658 _ContextMenu::GetPropertyHighlightedItemColor(void) const
659 {
660         return Tizen::Ui::Variant(__itemColor[CONTEXT_MENU_CORE_ITEM_STATUS_HIGHLIGHTED]);
661 }
662
663 result
664 _ContextMenu::SetItemColor(enum ContextMenuCoreItemStatus status, const Graphics::Color& color)
665 {
666         result r = E_SUCCESS;
667
668         if (status == CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL)
669         {
670                 r = SetProperty("normalItemColor", Variant(color));
671         }
672         else if (status == CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED)
673         {
674                 r = SetProperty("pressedItemColor", Variant(color));
675         }
676         else
677         {
678                 r = SetProperty("highlightedItemColor", Variant(color));
679         }
680
681         return r;
682 }
683
684 Color
685 _ContextMenu::GetItemColor(enum ContextMenuCoreItemStatus status) const
686 {
687         Color itemColor;
688
689         if (status == CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL)
690         {
691                 Variant color = GetProperty("normalItemColor");
692                 itemColor = color.ToColor();
693
694         }
695         else if (status == CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED)
696         {
697                 Variant color = GetProperty("pressedItemColor");
698                 itemColor = color.ToColor();
699
700         }
701         else
702         {
703                 Variant color = GetProperty("highlightedItemColor");
704                 itemColor = color.ToColor();
705         }
706
707         return itemColor;
708
709 }
710
711 result
712 _ContextMenu::SetPropertyNormalItemTextColor(const Variant& color)
713 {
714         __textColor[CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL] = color.ToColor();
715
716         return __pContextMenuPresenter->ApplyColorProperty();
717 }
718
719 Variant
720 _ContextMenu::GetPropertyNormalItemTextColor(void) const
721 {
722         return Tizen::Ui::Variant(__textColor[CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL]);
723 }
724
725 result
726 _ContextMenu::SetPropertyPressedItemTextColor(const Variant& color)
727 {
728         __textColor[CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED] = color.ToColor();
729
730         return __pContextMenuPresenter->ApplyColorProperty();
731 }
732
733 Variant
734 _ContextMenu::GetPropertyPressedItemTextColor(void) const
735 {
736         return Tizen::Ui::Variant(__textColor[CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED]);
737 }
738
739 result
740 _ContextMenu::SetPropertyHighlightedItemTextColor(const Variant & color)
741 {
742         __textColor[CONTEXT_MENU_CORE_ITEM_STATUS_HIGHLIGHTED] = color.ToColor();
743
744         return __pContextMenuPresenter->ApplyColorProperty();
745 }
746
747 Variant
748 _ContextMenu::GetPropertyHighlightedItemTextColor(void) const
749 {
750         return Tizen::Ui::Variant(__textColor[CONTEXT_MENU_CORE_ITEM_STATUS_HIGHLIGHTED]);
751 }
752
753 result
754 _ContextMenu::SetTextColor(enum ContextMenuCoreItemStatus status, const Graphics::Color& color)
755 {
756         result r = E_SUCCESS;
757
758         if (status == CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL)
759         {
760                 r = SetProperty("normalItemTextColor", Variant(color));
761         }
762         else if (status == CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED)
763         {
764                 r = SetProperty("pressedItemTextColor", Variant(color));
765         }
766         else
767         {
768                 r = SetProperty("highlightedItemTextColor", Variant(color));
769         }
770
771         return r;
772
773 }
774
775 Color
776 _ContextMenu::GetTextColor(enum ContextMenuCoreItemStatus status) const
777 {
778         Color textColor;
779
780         if (status == CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL)
781         {
782                 Variant color = GetProperty("normalItemTextColor");
783                 textColor = color.ToColor();
784
785         }
786         else if (status == CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED)
787         {
788                 Variant color = GetProperty("pressedItemTextColor");
789                 textColor = color.ToColor();
790
791         }
792         else
793         {
794                 Variant color = GetProperty("highlightedItemTextColor");
795                 textColor = color.ToColor();
796         }
797
798         return textColor;
799 }
800
801 result
802 _ContextMenu::AddActionEventListener(const Tizen::Ui::Controls::_IActionEventListener& listener)
803 {
804         result r = E_SUCCESS;
805
806         if (__pActionEvent == null)
807         {
808                 __pActionEvent = _ActionEvent::CreateInstanceN(*this);
809                 SysTryReturn(NID_UI_CTRL, __pActionEvent != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
810                                         "[E_OUT_OF_MEMORY] The memory is insufficient.")
811
812                 r = __pActionEvent->AddListener(listener);
813                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to remove an action event listener.")
814         }
815
816         return r;
817
818 CATCH:
819         delete __pActionEvent;
820         __pActionEvent = null;
821         return r;
822 }
823
824 result
825 _ContextMenu::RemoveActionEventListener(const Tizen::Ui::Controls::_IActionEventListener& listener)
826 {
827         SysTryReturn(NID_UI_CTRL, __pActionEvent != null, E_INVALID_STATE, E_INVALID_STATE,
828                         "[E_INVALID_STATE] The action event instance isn't constructed.")
829
830         result r = E_SUCCESS;
831
832         r = __pActionEvent->RemoveListener(listener);
833         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to remove an action event listener")
834
835         return r;
836 }
837
838 Tizen::Ui::Controls::_ActionEvent*
839 _ContextMenu::GetActionEvent(void) const
840 {
841         return __pActionEvent;
842 }
843
844 result
845 _ContextMenu::LoadBitmap(void)
846 {
847         Color backgroundColor;
848
849         // Delete old bitmap
850         if (__pBackgroundEffectBitmap != null)
851         {
852                 delete __pBackgroundEffectBitmap;
853                 __pBackgroundEffectBitmap = null;
854         }
855
856         for (int i = 0; i < CONTEXT_MENU_CORE_DROP_POSITION_MAX; i++)
857         {
858                 if (__pArrowEffectBitmap[i] != null)
859                 {
860                         delete __pArrowEffectBitmap[i];
861                         __pArrowEffectBitmap[i] = null;
862                 }
863         }
864
865         backgroundColor = GetColor();
866
867
868         result r;
869         r = GET_BITMAP_CONFIG_N(CONTEXTMENU::ANCHOR_EFFECT_UP, BITMAP_PIXEL_FORMAT_ARGB8888,
870                         __pArrowEffectBitmap[CONTEXT_MENU_CORE_DROP_POSITION_UP]);
871         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
872
873         r = GET_BITMAP_CONFIG_N(CONTEXTMENU::ANCHOR_EFFECT_DOWN, BITMAP_PIXEL_FORMAT_ARGB8888,
874                         __pArrowEffectBitmap[CONTEXT_MENU_CORE_DROP_POSITION_DOWN]);
875         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
876
877         r = GET_BITMAP_CONFIG_N(CONTEXTMENU::ANCHOR_EFFECT_LEFT, BITMAP_PIXEL_FORMAT_ARGB8888,
878                         __pArrowEffectBitmap[CONTEXT_MENU_CORE_DROP_POSITION_LEFT]);
879         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
880
881         r = GET_BITMAP_CONFIG_N(CONTEXTMENU::ANCHOR_EFFECT_RIGHT, BITMAP_PIXEL_FORMAT_ARGB8888,
882                         __pArrowEffectBitmap[CONTEXT_MENU_CORE_DROP_POSITION_RIGHT]);
883         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
884
885         r = GET_BITMAP_CONFIG_N(CONTEXTMENU::BG_OUTLINE_EFFECT_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pBackgroundEffectBitmap);
886         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
887
888         r = LoadColorReplacedBitmap(backgroundColor);
889         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
890
891         return r;
892
893 CATCH:
894         delete __pBackgroundEffectBitmap;
895         __pBackgroundEffectBitmap = null;
896
897         for (int i = 0; i < CONTEXT_MENU_CORE_DROP_POSITION_MAX; i++)
898         {
899
900                 delete __pArrowEffectBitmap[i];
901                 __pArrowEffectBitmap[i] = null;
902         }
903
904         return r;
905 }
906
907 result
908 _ContextMenu::LoadColorReplacedBitmap(const Tizen::Graphics::Color& color)
909 {
910         Bitmap* ptempNormalBitmap = null;
911
912         // Delete old bitmap
913         if (__pBackgroundNormalBitmap != null)
914         {
915                 delete __pBackgroundNormalBitmap;
916                 __pBackgroundNormalBitmap = null;
917         }
918
919         for (int i = 0; i < CONTEXT_MENU_CORE_DROP_POSITION_MAX; i++)
920         {
921                 if (__pArrowNormalBitmap[i] != null)
922                 {
923                         delete __pArrowNormalBitmap[i];
924                         __pArrowNormalBitmap[i] = null;
925                 }
926         }
927
928         result r;
929         r = GET_BITMAP_CONFIG_N(CONTEXTMENU::ANCHOR_NORMAL_UP, BITMAP_PIXEL_FORMAT_ARGB8888, ptempNormalBitmap);
930         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
931         __pArrowNormalBitmap[CONTEXT_MENU_CORE_DROP_POSITION_UP] = _BitmapImpl::GetColorReplacedBitmapN(*ptempNormalBitmap,
932                         Color::GetColor(COLOR_ID_MAGENTA), color);
933         SysTryCatch(NID_UI_CTRL, __pArrowNormalBitmap[CONTEXT_MENU_CORE_DROP_POSITION_UP] != null, , GetLastResult(),
934                         "[%s] Propagating.", GetErrorMessage(GetLastResult()));
935         delete ptempNormalBitmap;
936         ptempNormalBitmap = null;
937
938         r = GET_BITMAP_CONFIG_N(CONTEXTMENU::ANCHOR_NORMAL_DOWN, BITMAP_PIXEL_FORMAT_ARGB8888, ptempNormalBitmap);
939         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
940         __pArrowNormalBitmap[CONTEXT_MENU_CORE_DROP_POSITION_DOWN] = _BitmapImpl::GetColorReplacedBitmapN(*ptempNormalBitmap,
941                         Color::GetColor(COLOR_ID_MAGENTA), color);
942         SysTryCatch(NID_UI_CTRL, __pArrowNormalBitmap[CONTEXT_MENU_CORE_DROP_POSITION_DOWN] != null, , GetLastResult(),
943                         "[%s] Propagating.", GetErrorMessage(GetLastResult()));
944         delete ptempNormalBitmap;
945         ptempNormalBitmap = null;
946
947         r = GET_BITMAP_CONFIG_N(CONTEXTMENU::ANCHOR_NORMAL_LEFT, BITMAP_PIXEL_FORMAT_ARGB8888, ptempNormalBitmap);
948         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
949         __pArrowNormalBitmap[CONTEXT_MENU_CORE_DROP_POSITION_LEFT] = _BitmapImpl::GetColorReplacedBitmapN(*ptempNormalBitmap,
950                         Color::GetColor(COLOR_ID_MAGENTA), color);
951         SysTryCatch(NID_UI_CTRL, __pArrowNormalBitmap[CONTEXT_MENU_CORE_DROP_POSITION_LEFT] != null, , GetLastResult(),
952                         "[%s] Propagating.", GetErrorMessage(GetLastResult()));
953         delete ptempNormalBitmap;
954         ptempNormalBitmap = null;
955
956         r = GET_BITMAP_CONFIG_N(CONTEXTMENU::ANCHOR_NORMAL_RIGHT, BITMAP_PIXEL_FORMAT_ARGB8888, ptempNormalBitmap);
957         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
958         __pArrowNormalBitmap[CONTEXT_MENU_CORE_DROP_POSITION_RIGHT] = _BitmapImpl::GetColorReplacedBitmapN(*ptempNormalBitmap,
959                         Color::GetColor(COLOR_ID_MAGENTA), color);
960         SysTryCatch(NID_UI_CTRL, __pArrowNormalBitmap[CONTEXT_MENU_CORE_DROP_POSITION_RIGHT] != null, , GetLastResult(),
961                         "[%s] Propagating.", GetErrorMessage(GetLastResult()));
962         delete ptempNormalBitmap;
963         ptempNormalBitmap = null;
964
965         r = GET_BITMAP_CONFIG_N(CONTEXTMENU::BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, ptempNormalBitmap);
966         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
967         __pBackgroundNormalBitmap = _BitmapImpl::GetColorReplacedBitmapN(*ptempNormalBitmap, Color::GetColor(COLOR_ID_MAGENTA), color);
968         SysTryCatch(NID_UI_CTRL, __pBackgroundNormalBitmap != null, , GetLastResult(), "[%s] Propagating.",
969                         GetErrorMessage(GetLastResult()));
970         delete ptempNormalBitmap;
971
972         return r;
973
974 CATCH:
975         delete ptempNormalBitmap;
976
977         delete __pBackgroundNormalBitmap;
978         __pBackgroundNormalBitmap = null;
979
980         for (int i = 0; i < CONTEXT_MENU_CORE_DROP_POSITION_MAX; i++)
981         {
982                 delete __pArrowNormalBitmap[i];
983                 __pArrowNormalBitmap[i] = null;
984         }
985
986         return r;
987 }
988
989 const Bitmap*
990 _ContextMenu::GetArrowNormalBitmap(ContextMenuCoreDropPosition dropPosition) const
991 {
992         if (dropPosition == CONTEXT_MENU_CORE_DROP_POSITION_INVALID || dropPosition == CONTEXT_MENU_CORE_DROP_POSITION_MAX)
993         {
994                 return null;
995         }
996
997         return __pArrowNormalBitmap[dropPosition];
998 }
999
1000 const Bitmap*
1001 _ContextMenu::GetArrowEffectBitmap(ContextMenuCoreDropPosition dropPosition) const
1002 {
1003         if (dropPosition == CONTEXT_MENU_CORE_DROP_POSITION_INVALID || dropPosition == CONTEXT_MENU_CORE_DROP_POSITION_MAX)
1004         {
1005                 return null;
1006         }
1007
1008         return __pArrowEffectBitmap[dropPosition];
1009 }
1010
1011 const Bitmap*
1012 _ContextMenu::GetBackgroundNormalBitmap(void) const
1013 {
1014         return __pBackgroundNormalBitmap;
1015 }
1016
1017 const Bitmap*
1018 _ContextMenu::GetBackgroundEffectBitmap(void) const
1019 {
1020         return __pBackgroundEffectBitmap;
1021 }
1022
1023 enum ContextMenuCoreDropPosition
1024 _ContextMenu::GetDropPosition(void) const
1025 {
1026         return __dropPosition;
1027 }
1028
1029 void
1030 _ContextMenu::AdjustDropPosition(void)
1031 {
1032         Dimension screen = _ControlManager::GetInstance()->GetScreenSize();
1033
1034         if (__align == CONTEXT_MENU_CORE_ALIGN_UP)
1035         {
1036                 __dropPosition = CONTEXT_MENU_CORE_DROP_POSITION_UP;
1037         }
1038         else if (__align == CONTEXT_MENU_CORE_ALIGN_DOWN)
1039         {
1040                 __dropPosition = CONTEXT_MENU_CORE_DROP_POSITION_DOWN;
1041         }
1042         else if (__align == CONTEXT_MENU_CORE_ALIGN_LEFT)
1043         {
1044                 __dropPosition = CONTEXT_MENU_CORE_DROP_POSITION_LEFT;
1045         }
1046         else if (__align == CONTEXT_MENU_CORE_ALIGN_RIGHT)
1047         {
1048                 __dropPosition = CONTEXT_MENU_CORE_DROP_POSITION_RIGHT;
1049         }
1050         else
1051         {
1052                 if (__layout == _CONTROL_ORIENTATION_LANDSCAPE)
1053                 {
1054                         screen.SetSize(screen.height, screen.width);
1055                 }
1056
1057                 if (screen.height > screen.width)
1058                 {
1059                         if ((screen.height / 2) > __anchorPoint.y)
1060                         {
1061                                 __dropPosition = CONTEXT_MENU_CORE_DROP_POSITION_DOWN;
1062                         }
1063                         else
1064                         {
1065                                 __dropPosition = CONTEXT_MENU_CORE_DROP_POSITION_UP;
1066                         }
1067                 }
1068                 else
1069                 {
1070                         if ((screen.width / 2) > __anchorPoint.x)
1071                         {
1072                                 __dropPosition = CONTEXT_MENU_CORE_DROP_POSITION_RIGHT;
1073                         }
1074                         else
1075                         {
1076                                 __dropPosition = CONTEXT_MENU_CORE_DROP_POSITION_LEFT;
1077                         }
1078                 }
1079         }
1080 }
1081
1082 _UiTouchEventDelivery
1083 _ContextMenu::OnPreviewTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
1084 {
1085         return __pContextMenuPresenter->OnPreviewTouchPressed(source, touchinfo);
1086 }
1087
1088 bool
1089 _ContextMenu::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
1090 {
1091         return __pContextMenuPresenter->OnTouchPressed(source, touchinfo);
1092 }
1093
1094 _UiTouchEventDelivery
1095 _ContextMenu::OnPreviewTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
1096 {
1097         return __pContextMenuPresenter->OnPreviewTouchMoved(source, touchinfo);
1098 }
1099
1100 bool
1101 _ContextMenu::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
1102 {
1103         return __pContextMenuPresenter->OnTouchMoved(source, touchinfo);
1104 }
1105
1106 _UiTouchEventDelivery
1107 _ContextMenu::OnPreviewTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
1108 {
1109         return __pContextMenuPresenter->OnPreviewTouchReleased(source, touchinfo);
1110 }
1111
1112 bool
1113 _ContextMenu::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
1114 {
1115         return __pContextMenuPresenter->OnTouchReleased(source, touchinfo);
1116 }
1117
1118 bool
1119 _ContextMenu::OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
1120 {
1121         __pContextMenuPresenter->OnTouchCanceled(source, touchinfo);
1122
1123         SetVisibleState(false);
1124
1125         return true;
1126 }
1127
1128 void
1129 _ContextMenu::OnFontChanged(Tizen::Graphics::Font* pFont)
1130 {
1131         return __pContextMenuPresenter->OnFontChanged(pFont);
1132 }
1133
1134 void
1135 _ContextMenu::OnFontInfoRequested(unsigned long& style, int& size)
1136 {
1137         return __pContextMenuPresenter->OnFontInfoRequested(style, size);
1138 }
1139
1140 void
1141 _ContextMenu::OnVisibleStateChanged(void)
1142 {
1143 #if defined(MULTI_WINDOW)
1144         _Window::OnVisibleStateChanged();
1145 #endif
1146 }
1147
1148 void
1149 _ContextMenu::OnChangeLayout(_ControlOrientation orientation)
1150 {
1151         GET_SHAPE_CONFIG(CONTEXTMENU::ITEM_MAX_COUNT, orientation, __showItemMaxCount);
1152
1153         if (__isAttachedToMainTree == true)
1154         {
1155                 if (__layout != orientation)
1156                 {
1157                         SetVisibleState(false);
1158                 }
1159         }
1160
1161         __layout = orientation;
1162 }
1163
1164 _AccessibilityElement*
1165 _ContextMenu::GetAccessibilityElement(const int mainIndex) const
1166 {
1167         _AccessibilityElement* pElement = null;
1168         result r = __accessibilityElements.GetAt(mainIndex, pElement);
1169         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed at AccessibilityElement.", GetErrorMessage(r));
1170
1171         return pElement;
1172
1173 CATCH:
1174         delete pElement;
1175
1176         return null;
1177 }
1178
1179 void
1180 _ContextMenu::AddAccessibilityElement(const _AccessibilityElement& element)
1181 {
1182         __accessibilityElements.Add(const_cast<_AccessibilityElement*>(&element));
1183 }
1184
1185 void
1186 _ContextMenu::SetAllAccessibilityElement(void)
1187 {
1188         RemoveAllAccessibilityElement();
1189         __pContextMenuPresenter->SetAllAccessibilityElement();
1190 }
1191
1192 void
1193 _ContextMenu::RemoveAllAccessibilityElement(void)
1194 {
1195         while (__accessibilityElements.GetCount() > 0)
1196         {
1197                 _AccessibilityElement* pElement = null;
1198                 if (__accessibilityElements.GetAt(0, pElement) == E_SUCCESS)
1199                 {
1200                         __accessibilityElements.RemoveAt(0);
1201                         pElement->GetParent()->RemoveElement(*pElement);
1202                 }
1203         }
1204 }
1205
1206 _ContextMenuItemInfo
1207 _ContextMenu::GetItemFromPosition(const Point& position) const
1208 {
1209         return __pContextMenuPresenter->GetItemFromPosition(position);
1210 }
1211
1212 _ContextMenuItemInfo
1213 _ContextMenu::FindItem(int index) const
1214 {
1215         return __pContextMenuPresenter->FindItem(index);
1216 }
1217
1218 result
1219 _ContextMenu::SetTopDrawnItemIndex(int index)
1220 {
1221         return __pContextMenuPresenter->SetTopDrawnItemIndex(index);
1222 }
1223
1224 _ControlOrientation
1225 _ContextMenu::GetLayout(void) const
1226 {
1227         return __layout;
1228 }
1229
1230 }}} // Tizen::Ui: Control