Changed indicator bg color.
[platform/framework/native/uifw.git] / src / ui / controls / FUiCtrl_ContextMenuGridPresenter.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_ContextMenuGridPresenter.cpp
19  * @brief               This is the implementation file for the _ContextMenuGridPresenter class.
20  */
21
22 #include <FBaseErrorDefine.h>
23 #include <FBaseSysLog.h>
24 #include <FGrp_BitmapImpl.h>
25 #include <FGrp_CanvasImpl.h>
26 #include <FGrp_TextTextSimple.h>
27 #include "FUi_AccessibilityContainer.h"
28 #include "FUi_AccessibilityElement.h"
29 #include "FUi_CoordinateSystemUtils.h"
30 #include "FUi_Math.h"
31 #include "FUi_ResourceManager.h"
32 #include "FUiCtrl_ActionEvent.h"
33 #include "FUiCtrl_IActionEventListener.h"
34
35 #include "FUiCtrl_ContextMenuGridPresenter.h"
36
37 using namespace Tizen::Graphics;
38 using namespace Tizen::Ui;
39 using namespace Tizen::Base;
40 using namespace Tizen::Base::Runtime;
41 using namespace Tizen::Graphics::_Text;
42
43 static const int MAX_LINE_COUNT = 32;           // Only for index of array
44 static const int MAX_ITEM_COUNT = 35;
45
46 namespace Tizen { namespace Ui { namespace Controls
47 {
48
49 _ContextMenuGridPresenter::_ContextMenuGridPresenter(_ContextMenu* pContextMenu)
50         : __pContextMenu(pContextMenu)
51         , __pModel(null)
52         , __pTextObject(null)
53         , __pFont(null)
54         , __layoutSize(FloatDimension(0.0f, 0.0f))
55         , __touchOutRect(false)
56         , __selectedIndex(-1)
57         , __pressedIndex(-1)
58         , __maxWidth(0.0f)
59         , __minWidth(0.0f)
60         , __topMargin(0.0f)
61         , __bottomMargin(0.0f)
62         , __leftMargin(0.0f)
63         , __rightMargin(0.0f)
64         , __screenTopMargin(0.0f)
65         , __screenBottomMargin(0.0f)
66         , __screenLeftMargin(0.0f)
67         , __screenRightMargin(0.0f)
68         , __arrowTopMargin(0.0f)
69         , __arrowBottomMargin(0.0f)
70         , __arrowRightMargin(0.0f)
71         , __arrowLeftMargin(0.0f)
72         , __arrowWidth(0.0f)
73         , __arrowHeight(0.0f)
74         , __itemWidth(0.0f)
75         , __itemHeight(0.0f)
76         , __itemMaxWidth(0.0f)
77         , __itemTextMargin(0.0f)
78         , __itemGap(0.0f)
79         , __itemBitmapWidth(0.0f)
80         , __itemBitmapHeight(0.0f)
81         , __itemFontSize(0.0f)
82         , __dividerHeight(0.0f)
83         , __bgPressedMargin(0.0f)
84         , __anchorPopupOverlap(0.0f)
85         , __enterKeyPressed(false)
86         , __backKeyPressed(false)
87         , __focusedIndex(-1)
88 {
89
90 }
91
92 _ContextMenuGridPresenter::~_ContextMenuGridPresenter(void)
93 {
94         __pContextMenu = null;
95
96         delete __pModel;
97         __pModel = null;
98
99         if (__pTextObject)
100         {
101                 __pTextObject->RemoveAll();
102                 delete __pTextObject;
103                 __pTextObject = null;
104         }
105
106         __pFont = null;
107
108 }
109
110 result
111 _ContextMenuGridPresenter::Install(void)
112 {
113         result r = E_SUCCESS;
114
115         LoadShape();
116
117         __pModel = new (std::nothrow) _ContextMenuModel;
118         SysTryCatch(NID_UI_CTRL, __pModel != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
119
120         r = __pModel->Construct();
121         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Unable to create data instance.");
122
123         __pFont = __pContextMenu->GetFallbackFont();
124         r = GetLastResult();
125         SysTryCatch(NID_UI_CTRL, (__pFont != null), , r, "[%s] Propagating.", GetErrorMessage(r));
126
127         __pTextObject = new (std::nothrow) TextObject();
128         SysTryCatch(NID_UI_CTRL, __pTextObject, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Unable to create data instance.");
129
130         __pTextObject->Construct();
131         __pTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_CENTER | TEXT_OBJECT_ALIGNMENT_MIDDLE);
132         __pTextObject->SetWrap(TEXT_OBJECT_WRAP_TYPE_NONE);
133         __pTextObject->SetFont(__pFont, 0, __pTextObject->GetTextLength());
134
135         return r;
136
137 CATCH:
138         delete __pModel;
139         __pModel = null;
140
141         __pFont = null;
142
143         delete __pTextObject;
144         __pTextObject = null;
145
146         return r;
147 }
148
149
150 void
151 _ContextMenuGridPresenter::LoadShape(void)
152 {
153         GET_SHAPE_CONFIG(CONTEXTMENU::GRID_ITEM_WIDTH, _CONTROL_ORIENTATION_PORTRAIT, __itemWidth);
154         GET_SHAPE_CONFIG(CONTEXTMENU::GRID_ITEM_MAX_WIDTH, _CONTROL_ORIENTATION_PORTRAIT, __itemMaxWidth);
155         GET_SHAPE_CONFIG(CONTEXTMENU::GRID_ITEM_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, __itemHeight);
156         GET_SHAPE_CONFIG(CONTEXTMENU::GRID_TEXT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, __itemTextMargin);
157         GET_FIXED_VALUE_CONFIG(CONTEXTMENU::GRID_ITEM_GAP, _CONTROL_ORIENTATION_PORTRAIT, __itemGap);
158
159         GET_SHAPE_CONFIG(CONTEXTMENU::GRID_MIN_WIDTH, _CONTROL_ORIENTATION_PORTRAIT, __minWidth);
160         GET_SHAPE_CONFIG(CONTEXTMENU::GRID_TOP_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, __topMargin);
161         GET_SHAPE_CONFIG(CONTEXTMENU::GRID_BOTTOM_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, __bottomMargin);
162         GET_SHAPE_CONFIG(CONTEXTMENU::GRID_LEFT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, __leftMargin);
163         GET_SHAPE_CONFIG(CONTEXTMENU::GRID_RIGHT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, __rightMargin);
164
165         GET_SHAPE_CONFIG(CONTEXTMENU::GRID_ITEM_FONT_SIZE, _CONTROL_ORIENTATION_PORTRAIT, __itemFontSize);
166         GET_SHAPE_CONFIG(CONTEXTMENU::SCREEN_TOP_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, __screenTopMargin);
167         GET_SHAPE_CONFIG(CONTEXTMENU::SCREEN_BOTTOM_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, __screenBottomMargin);
168         GET_SHAPE_CONFIG(CONTEXTMENU::SCREEN_LEFT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, __screenLeftMargin);
169         GET_SHAPE_CONFIG(CONTEXTMENU::SCREEN_RIGHT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, __screenRightMargin);
170         GET_SHAPE_CONFIG(CONTEXTMENU::ANCHOR_TOP_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, __arrowTopMargin);
171         GET_SHAPE_CONFIG(CONTEXTMENU::ANCHOR_BOTTOM_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, __arrowBottomMargin);
172         GET_SHAPE_CONFIG(CONTEXTMENU::ANCHOR_LEFT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, __arrowLeftMargin);
173         GET_SHAPE_CONFIG(CONTEXTMENU::ANCHOR_RIGHT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, __arrowRightMargin);
174         GET_SHAPE_CONFIG(CONTEXTMENU::ANCHOR_WIDTH, _CONTROL_ORIENTATION_PORTRAIT, __arrowWidth);
175         GET_SHAPE_CONFIG(CONTEXTMENU::ANCHOR_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, __arrowHeight);
176         GET_SHAPE_CONFIG(CONTEXTMENU::GRID_ICON_WIDTH, _CONTROL_ORIENTATION_PORTRAIT, __itemBitmapWidth);
177         GET_SHAPE_CONFIG(CONTEXTMENU::GRID_ICON_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, __itemBitmapHeight);
178         GET_SHAPE_CONFIG(CONTEXTMENU::GRID_DIVIDER_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, __dividerHeight);
179         GET_SHAPE_CONFIG(CONTEXTMENU::ITEM_BG_PRESSED_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, __bgPressedMargin);
180         GET_SHAPE_CONFIG(CONTEXTMENU::ANCHOR_POPUP_OVERLAP, _CONTROL_ORIENTATION_PORTRAIT, __anchorPopupOverlap);
181 }
182
183 _ContextMenuItem*
184 _ContextMenuGridPresenter::CreateItem(const Base::String& text, int actionId, const Tizen::Graphics::Bitmap* pNormalBitmap, const Tizen::Graphics::Bitmap* pPressedBitmap, const Tizen::Graphics::Bitmap* pHighlightedBitmap)
185 {
186         _ContextMenuItem* pItem = _ContextMenuItem::CreateContextMenuItemN();
187         SysTryReturn(NID_UI_CTRL, pItem != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
188
189         ContextMenuItemDrawingType itemType = CONTEXT_MENU_ITEM_DRAWING_TYPE_NONE;
190         result r = E_SUCCESS;
191
192         if (text.GetLength() != 0)
193         {
194                 r = pItem->SetText(text);
195                 if (r != E_SUCCESS)
196                 {
197                         delete pItem;
198                         return null;
199                 }
200
201                 itemType = CONTEXT_MENU_ITEM_DRAWING_TYPE_TEXT;
202         }
203         else
204         {
205                 if (pNormalBitmap == null && pPressedBitmap == null)
206                 {
207                         delete pItem;
208                         return null;
209                 }
210
211                 if (pNormalBitmap != null)
212                 {
213                         r = pItem->SetBitmap(CONTEXT_MENU_ITEM_DRAWING_STATUS_NORMAL, pNormalBitmap);
214                         if (r != E_SUCCESS)
215                         {
216                                 delete pItem;
217                                 return null;
218                         }
219                 }
220
221                 if (pPressedBitmap != null)
222                 {
223                         r = pItem->SetBitmap(CONTEXT_MENU_ITEM_DRAWING_STATUS_PRESSED, pPressedBitmap);
224                         if (r != E_SUCCESS)
225                         {
226                                 delete pItem;
227                                 return null;
228                         }
229                 }
230
231                 itemType = CONTEXT_MENU_ITEM_DRAWING_TYPE_BITMAP;
232         }
233
234         pItem->SetType(itemType);
235         pItem->SetActionId(actionId);
236
237         // calculate item size
238         SetItemSize(pItem);
239
240         return pItem;
241 }
242
243 result
244 _ContextMenuGridPresenter::AddItem(const Base::String& text, int actionId, const Tizen::Graphics::Bitmap* normalBitmap,
245                                                                    const Tizen::Graphics::Bitmap* pPressedBitmap,
246                                                                    const Tizen::Graphics::Bitmap* pHighlightedBitmap)
247 {
248         _ContextMenuItem* pItem = CreateItem(text, actionId, normalBitmap, pPressedBitmap, pHighlightedBitmap);
249         SysTryReturn(NID_UI_CTRL, pItem != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "The memory is insufficient.");
250
251         result r = __pModel->AddItem(pItem);
252
253         if (r != E_SUCCESS)
254         {
255                 delete pItem;
256                 SysTryReturn(NID_UI_CTRL, false, r, r, "Failed to add item.");
257         }
258
259         r = AdjustItemLayout();
260         if (r != E_SUCCESS)
261         {
262                 result rt = __pModel->RemoveItem(__pModel->GetItemCount() - 1);
263                 SysTryReturn(NID_UI_CTRL, rt == E_SUCCESS, rt, rt, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
264
265                 SysTryReturn(NID_UI_CTRL, false, r, r, "Failed to add item.");
266         }
267
268         return r;
269 }
270
271 result
272 _ContextMenuGridPresenter::InsertItem(int index, const Tizen::Base::String& text, int actionId,
273                                                                           const Tizen::Graphics::Bitmap* normalBitmap, const Tizen::Graphics::Bitmap* pPressedBitmap,
274                                                                           const Tizen::Graphics::Bitmap* pHighlightedBitmap)
275 {
276         if (text.GetLength() == 0 && normalBitmap == null && pPressedBitmap == null)
277         {
278                 return E_INVALID_ARG;
279         }
280
281         _ContextMenuItem* pItem = null;
282
283         pItem = CreateItem(text, actionId, normalBitmap, pPressedBitmap, pHighlightedBitmap);
284         SysTryReturn(NID_UI_CTRL, pItem != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "The memory is insufficient.");
285
286         result r = __pModel->InsertItem(pItem, index);
287         if (r != E_SUCCESS)
288         {
289                 delete pItem;
290                 SysTryReturn(NID_UI_CTRL, false, r, r, "Failed to insert item.");
291         }
292
293         r = AdjustItemLayout();
294         if (r != E_SUCCESS)
295         {
296                 result rt = __pModel->RemoveItem(index);
297                 SysTryReturn(NID_UI_CTRL, rt == E_SUCCESS, rt, rt, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
298
299                 SysTryReturn(NID_UI_CTRL, false, r, r, "Failed to insert item.");
300         }
301
302         return E_SUCCESS;
303 }
304
305 result
306 _ContextMenuGridPresenter::SetItem(int index, const Tizen::Base::String& text, int actionId,
307                                                                    const Tizen::Graphics::Bitmap* normalBitmap, const Tizen::Graphics::Bitmap* pPressedBitmap,
308                                                                    const Tizen::Graphics::Bitmap* pHighlightedBitmap)
309 {
310         if (text.GetLength() == 0 && normalBitmap == null && pPressedBitmap == null)
311         {
312                 return E_INVALID_ARG;
313         }
314
315         _ContextMenuItem* pItem = null;
316         pItem = CreateItem(text, actionId, normalBitmap, pPressedBitmap, pHighlightedBitmap);
317         SysTryReturn(NID_UI_CTRL, pItem != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "The memory is insufficient.");
318
319         result r = __pModel->SetItem(pItem, index);
320         if (r != E_SUCCESS)
321         {
322                 delete pItem;
323                 SysTryReturn(NID_UI_CTRL, false, r, r, "Failed to set item.");
324         }
325
326         r = AdjustItemLayout();
327         if (r != E_SUCCESS)
328         {
329                 result rt = __pModel->RemoveItem(index);
330                 SysTryReturn(NID_UI_CTRL, rt == E_SUCCESS, rt, rt, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
331
332                 SysTryReturn(NID_UI_CTRL, false, r, r, "Failed to set item.");
333         }
334
335         return E_SUCCESS;
336 }
337
338 result
339 _ContextMenuGridPresenter::DeleteItem(int index)
340 {
341         int itemCount = __pContextMenu->GetItemCount();
342
343         if (itemCount <= 0 || index >= itemCount || index < 0)
344         {
345                 SysLogException(NID_UI_CTRL, E_INVALID_STATE, "Invalid argument.");
346                 return E_INVALID_STATE;
347         }
348
349         result r = __pModel->RemoveItem(index);
350         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to delete item.");
351
352         return r;
353 }
354
355 result
356 _ContextMenuGridPresenter::DeleteItemAll(void)
357 {
358         int itemCount = __pContextMenu->GetItemCount();
359
360         if (itemCount <= 0)
361         {
362                 SysLogException(NID_UI_CTRL, E_INVALID_STATE, "Invalid argument.");
363                 return E_INVALID_STATE;
364         }
365
366         result r =  __pModel->RemoveAllItem();
367         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to delete item all.");
368
369         return r;
370 }
371
372
373 int
374 _ContextMenuGridPresenter::CalculateShowItemCount(void)
375 {
376         return __pContextMenu->GetShowItemCount();
377 }
378
379 void
380 _ContextMenuGridPresenter::SetItemSize(_ContextMenuItem* pItem)
381 {
382         ContextMenuItemDrawingType itemType = pItem->GetType();
383
384         if (itemType == CONTEXT_MENU_ITEM_DRAWING_TYPE_TEXT)
385         {
386                 float textMargin = __itemTextMargin;
387                 float minWidth   = __itemWidth;
388                 float maxWidth   = __itemMaxWidth;
389
390                 String text = pItem->GetText();
391
392                 textMargin = textMargin * 2.0f;
393                 minWidth = minWidth - textMargin;
394                 maxWidth = maxWidth - textMargin;
395
396                 FloatDimension textArea(0.0f, 0.0f);
397                 FloatDimension itemSize(0.0f, 0.0f);
398
399                 __pFont->GetTextExtent(text, text.GetLength(), textArea);
400
401                 if (textArea.width < minWidth)
402                 {
403                         textArea.width = minWidth;
404                 }
405
406                 if (textArea.width > maxWidth)
407                 {
408                         textArea.width = maxWidth;
409                 }
410
411                 itemSize.width = textArea.width + textMargin;
412                 itemSize.height = __itemHeight;
413
414                 pItem->SetSize(itemSize);
415
416         }
417         else if (itemType == CONTEXT_MENU_ITEM_DRAWING_TYPE_BITMAP)
418         {
419                 FloatDimension itemSize(__itemWidth, __itemHeight);
420
421                 pItem->SetSize(itemSize);
422         }
423 }
424
425 result
426 _ContextMenuGridPresenter::CalculateWindowRect(void)
427 {
428         result r = E_SUCCESS;
429
430         r = AdjustItemLayout();
431         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
432
433         r = CalculateRect();
434         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
435
436         AdjustItemPosition();
437
438         return r;
439 }
440
441 result
442 _ContextMenuGridPresenter::ApplyColorProperty(void)
443 {
444         return E_SUCCESS;
445 }
446
447 result
448 _ContextMenuGridPresenter::CalculateRect(void)
449 {
450         Tizen::Graphics::FloatRectangle windowRect = Tizen::Graphics::FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f);   // ContextMenu window itself
451         Tizen::Graphics::FloatRectangle bodyRect   = Tizen::Graphics::FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f);   // bg surronding showing items, relative to window
452         Tizen::Graphics::FloatRectangle arrowRect  = Tizen::Graphics::FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f);   // relative to window
453         Tizen::Graphics::FloatRectangle itemRect   = Tizen::Graphics::FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f);   // relative to window
454
455         float bodyTopMargin = __topMargin;
456         float bodyBottomMargin = __bottomMargin;
457         float bodyLeftMargin = __leftMargin;
458         float bodyRightMargin = __rightMargin;
459
460         float screenTopMargin = __screenTopMargin;
461         float screenBottomMargin = __screenBottomMargin;
462         float screenLeftMargin = __screenLeftMargin;
463         float screenRightMargin = __screenRightMargin;
464
465         FloatPoint anchorPosition = __pContextMenu->GetAnchorPosition();
466
467         FloatDimension screen = _ControlManager::GetInstance()->GetScreenSizeF();
468         if (__pContextMenu->GetLayout() == _CONTROL_ORIENTATION_LANDSCAPE)
469         {
470                 screen.SetSize(screen.height, screen.width);
471         }
472
473         // calculate arrow rect
474         enum ContextMenuCoreDropPosition dropPosition = __pContextMenu->GetDropPosition();
475         if (dropPosition == CONTEXT_MENU_CORE_DROP_POSITION_UP || dropPosition == CONTEXT_MENU_CORE_DROP_POSITION_DOWN) // down, up Arrow
476         {
477                 arrowRect.width = __arrowWidth;
478                 arrowRect.height = __arrowHeight;
479         }
480         else //  left, right Arrow
481         {
482                 arrowRect.width = __arrowHeight;
483                 arrowRect.height = __arrowWidth;
484         }
485
486         // calculate body rect
487         // calculate drawable boundaries for contextmenu
488         float leftBoundary = screenLeftMargin;
489         float rightBoundary = screen.width - screenRightMargin;
490         float topBoundary = screenTopMargin;
491         float bottomBoundary = screen.height - screenBottomMargin;
492
493         if (__pModel->GetItemCount() <= 0)
494         {
495                 __layoutSize.width = __itemWidth;
496                 __layoutSize.height = __itemHeight;
497         }
498
499         bodyRect.width = __layoutSize.width + bodyLeftMargin + bodyRightMargin;
500         bodyRect.height = __layoutSize.height + bodyTopMargin + bodyBottomMargin;
501
502         // calculate the position of the arrow and body rect.
503         if (dropPosition == CONTEXT_MENU_CORE_DROP_POSITION_UP)   // down Arrow
504         {
505                 // Check touch position
506                 //  - Check left margin
507                 if (anchorPosition.x <= leftBoundary + arrowRect.width)
508                 {
509                         anchorPosition.x = leftBoundary + arrowRect.width;
510                 }
511                 //  - check right margin
512                 if (anchorPosition.x >= (rightBoundary - arrowRect.width))
513                 {
514                         anchorPosition.x = rightBoundary - arrowRect.width;
515                 }
516                 //  - check top margin
517                 if (anchorPosition.y <= topBoundary)
518                 {
519                         anchorPosition.y = topBoundary + bodyRect.height;
520                 }
521                 //  - check bottom margin
522                 if (anchorPosition.y >= bottomBoundary)
523                 {
524                         anchorPosition.y = bottomBoundary;
525                 }
526
527                 // Set body position x
528                 bodyRect.x = anchorPosition.x - (bodyRect.width / 2.0f);
529                 //  - Check left margin
530                 if (bodyRect.x <= leftBoundary)
531                 {
532                         bodyRect.x = leftBoundary;
533                 }
534                 //  - check right margin
535                 if ((bodyRect.x + bodyRect.width) >= rightBoundary)
536                 {
537                         bodyRect.x = rightBoundary - bodyRect.width;
538                 }
539                 // Set body position y
540                 bodyRect.y = anchorPosition.y - arrowRect.height - bodyRect.height;
541                 //  - check top margin
542                 if (bodyRect.y <= topBoundary)
543                 {
544                         bodyRect.y = topBoundary;
545                 }
546
547                 float correctLength = __arrowTopMargin - __anchorPopupOverlap;
548                 windowRect.x = bodyRect.x;
549                 windowRect.y = bodyRect.y + correctLength;
550                 windowRect.width = bodyRect.width;
551                 windowRect.height = bodyRect.height + arrowRect.height - correctLength;
552
553                 bodyRect.x = 0.0f;
554                 bodyRect.y = 0.0f;
555
556                 // Set arrow position
557                 arrowRect.x = anchorPosition.x - (arrowRect.width / 2.0f) - windowRect.x;
558                 arrowRect.y = bodyRect.height - correctLength;
559         }
560         else if (dropPosition == CONTEXT_MENU_CORE_DROP_POSITION_DOWN)    // up Arrow
561         {
562                 // Check touch position
563                 //  - Check left margin
564                 if (anchorPosition.x <= leftBoundary + arrowRect.width)
565                 {
566                         anchorPosition.x = leftBoundary + arrowRect.width;
567                 }
568                 //  - check right margin
569                 if (anchorPosition.x >= (rightBoundary - arrowRect.width))
570                 {
571                         anchorPosition.x = rightBoundary - arrowRect.width;
572                 }
573                 //  - check top margin
574                 if (anchorPosition.y <= topBoundary)
575                 {
576                         anchorPosition.y = topBoundary;
577                 }
578                 //  - check bottom margin
579                 if (anchorPosition.y >= bottomBoundary)
580                 {
581                         anchorPosition.y = bottomBoundary;
582                 }
583
584                 // Set body position x
585                 bodyRect.x = anchorPosition.x - (bodyRect.width / 2.0f);
586                 //  - Check left margin
587                 if (bodyRect.x <= leftBoundary)
588                 {
589                         bodyRect.x = leftBoundary;
590                 }
591                 //  - check right margin
592                 if ((bodyRect.x + bodyRect.width) >= rightBoundary)
593                 {
594                         bodyRect.x = rightBoundary - bodyRect.width;
595                 }
596                 // Set body position y
597                 bodyRect.y = anchorPosition.y + arrowRect.height;
598                 //  - Check bottom margin
599                 if ((bodyRect.y + bodyRect.height) >= bottomBoundary)
600                 {
601                         bodyRect.y = bottomBoundary - bodyRect.height;
602                 }
603
604                 float correctLength = __arrowBottomMargin - __anchorPopupOverlap;
605                 windowRect.x = bodyRect.x;
606                 windowRect.y = bodyRect.y - arrowRect.height;
607                 windowRect.width = bodyRect.width;
608                 windowRect.height = bodyRect.height + arrowRect.height - correctLength;
609
610                 bodyRect.x = 0.0f;
611                 bodyRect.y = arrowRect.height - correctLength;
612
613                 // Set arrow position
614                 arrowRect.x = anchorPosition.x - (arrowRect.width / 2.0f) - windowRect.x;
615                 arrowRect.y = 0.0f;
616         }
617         else if (dropPosition == CONTEXT_MENU_CORE_DROP_POSITION_LEFT)    // right Arrow
618         {
619                 // Check touch position
620                 //  - Check left margin
621                 if (anchorPosition.x <= leftBoundary)
622                 {
623                         anchorPosition.x = leftBoundary + bodyRect.width;
624                 }
625                 //  - check right margin
626                 if (anchorPosition.x >= rightBoundary)
627                 {
628                         anchorPosition.x = rightBoundary;
629                 }
630                 //  - Check top margin
631                 if (anchorPosition.y <= topBoundary + arrowRect.height)
632                 {
633                         anchorPosition.y = topBoundary + arrowRect.height;
634                 }
635                 //  - check bottom margin
636                 if (anchorPosition.y >= (bottomBoundary - arrowRect.height))
637                 {
638                         anchorPosition.y = bottomBoundary - arrowRect.height;
639                 }
640
641                 // Set body position x
642                 bodyRect.x = anchorPosition.x - arrowRect.width - bodyRect.width;
643                 //  - Check left margin
644                 if (bodyRect.x <= leftBoundary)
645                 {
646                         bodyRect.x = leftBoundary;
647                 }
648                 //  - check right margin
649                 if ((bodyRect.x + bodyRect.width + arrowRect.width) >= rightBoundary)
650                 {
651                         bodyRect.x = rightBoundary - bodyRect.width - arrowRect.width;
652                 }
653
654                 // Set body position y
655                 bodyRect.y = anchorPosition.y - (bodyRect.height / 2.0f);
656                 // - check top margin
657                 if (bodyRect.y <= topBoundary)
658                 {
659                         bodyRect.y = topBoundary;
660                 }
661                 // - check bottom margin
662                 if ((bodyRect.y + bodyRect.height) >= bottomBoundary)
663                 {
664                         bodyRect.y = bottomBoundary - bodyRect.height;
665                 }
666
667                 float correctLength = __arrowRightMargin - __anchorPopupOverlap;
668                 windowRect.x = bodyRect.x + correctLength;
669                 windowRect.y = bodyRect.y;
670                 windowRect.width = bodyRect.width + arrowRect.width - correctLength;
671                 windowRect.height = bodyRect.height;
672
673                 bodyRect.x = 0.0f;
674                 bodyRect.y = 0.0f;
675
676                 // Set arrow position
677                 arrowRect.x = bodyRect.width - correctLength;
678                 arrowRect.y = anchorPosition.y - (arrowRect.height / 2.0f) - windowRect.y;
679         }
680         else    // left Arrow
681         {
682                 // Check touch position
683                 //  - Check top margin
684                 if (anchorPosition.x <= leftBoundary)
685                 {
686                         anchorPosition.x = leftBoundary;
687                 }
688                 //  - check right margin
689                 if (anchorPosition.x >= rightBoundary)
690                 {
691                         anchorPosition.x = rightBoundary - bodyRect.width;
692                 }
693                 //  - Check top margin
694                 if (anchorPosition.y <= topBoundary + arrowRect.height)
695                 {
696                         anchorPosition.y = topBoundary + arrowRect.height;
697                 }
698                 //  - check bottom margin
699                 if (anchorPosition.y >= (bottomBoundary - arrowRect.height))
700                 {
701                         anchorPosition.y = bottomBoundary - arrowRect.height;
702                 }
703
704                 // Set body position x
705                 bodyRect.x = anchorPosition.x;
706                 //  - Check left margin
707                 if (bodyRect.x <= leftBoundary)
708                 {
709                         bodyRect.x = leftBoundary;
710                 }
711                 //  - check right margin
712                 if ((bodyRect.x + bodyRect.width + arrowRect.width) >= rightBoundary)
713                 {
714                         bodyRect.x = rightBoundary - bodyRect.width - arrowRect.width;
715                 }
716                 // Set body position y
717                 bodyRect.y = anchorPosition.y - (bodyRect.height / 2);
718                 // - check top margin
719                 if (bodyRect.y <= topBoundary)
720                 {
721                         bodyRect.y = topBoundary;
722                 }
723                 // - check bottom margin
724                 if ((bodyRect.y + bodyRect.height) >= bottomBoundary)
725                 {
726                         bodyRect.y = bottomBoundary - bodyRect.height;
727                 }
728
729                 float correctLength = __arrowLeftMargin - __anchorPopupOverlap;
730                 windowRect.x = bodyRect.x;
731                 windowRect.y = bodyRect.y;
732                 windowRect.width = bodyRect.width + arrowRect.width - correctLength;
733                 windowRect.height = bodyRect.height;
734
735                 bodyRect.x = arrowRect.width - correctLength;
736                 bodyRect.y = 0.0f;
737
738                 // Set arrow position
739                 arrowRect.x = 0.0f;
740                 arrowRect.y = anchorPosition.y - (arrowRect.height / 2.0f) - windowRect.y;
741         }
742
743         itemRect.x      = bodyRect.x + bodyLeftMargin;
744         itemRect.y      = bodyRect.y + bodyTopMargin;
745         itemRect.width  = __layoutSize.width;
746         itemRect.height = __layoutSize.height;
747
748         __pContextMenu->SetWindowRect(windowRect);
749         __pContextMenu->SetBodyRect(bodyRect);
750         __pContextMenu->SetArrowRect(arrowRect);
751         __pContextMenu->SetItemRect(itemRect);
752
753         __pContextMenu->SetMovable(true);
754         __pContextMenu->SetResizable(true);
755
756         __pContextMenu->SetMinimumSize(FloatDimension(0.0f, 0.0f));
757         __pContextMenu->SetMaximumSize(screen);
758         __pContextMenu->SetBounds(windowRect);
759
760         __pContextMenu->SetMovable(false);
761         __pContextMenu->SetResizable(false);
762
763         return E_SUCCESS;
764 }
765
766 bool
767 _ContextMenuGridPresenter::IsLayoutBitmapOnly(void)
768 {
769         int itemCount = __pModel->GetItemCount();
770
771         if (itemCount <= 0)
772         {
773                 return false;
774         }
775
776         _ContextMenuItem* pItem = null;
777
778         for (int i = 0; i < itemCount; i++)
779         {
780                 pItem = __pModel->GetItem(i);
781                 if (pItem == null)
782                 {
783                         return false;
784                 }
785
786                 if (pItem->GetType() == CONTEXT_MENU_ITEM_DRAWING_TYPE_TEXT)
787                 {
788                         return false;
789                 }
790         }
791
792         return true;
793 }
794
795 result
796 _ContextMenuGridPresenter::AdjustItemLayout(void)
797 {
798         int itemCount = __pModel->GetItemCount();
799         FloatDimension layoutSize(0.0f, 0.0f);
800
801         if (itemCount <= 0)
802         {
803                 __layoutSize.width = __itemWidth;
804                 __layoutSize.height = __itemHeight;
805
806                 return E_SUCCESS;
807         }
808
809         // GUI guide word: 5x2
810         bool bitmapOnly = IsLayoutBitmapOnly();
811
812         if (bitmapOnly == true)
813         {
814                 layoutSize = AdjustItemLayoutIconStyle();
815         }
816         else
817         {
818                 layoutSize = AdjustItemLayoutTabStyle();
819         }
820
821         __layoutSize = layoutSize;
822
823         return GetLastResult();
824 }
825
826 Tizen::Graphics::FloatDimension
827 _ContextMenuGridPresenter::AdjustItemLayoutIconStyle(void)
828 {
829         ClearLastResult();
830
831         int countPerLine = 0;
832         int itemCount = __pModel->GetItemCount();
833         float itemWidth = __itemWidth + __itemGap;
834         float itemHeight = __itemHeight + __itemGap;
835         FloatDimension layoutSize(0.0f, 0.0f);
836
837         if (itemCount > MAX_ITEM_COUNT)
838         {
839                 SetLastResult(E_MAX_EXCEEDED);
840                 return layoutSize;
841         }
842
843         countPerLine = GetCountPerLine(itemCount);
844
845         int lineCount = itemCount / countPerLine;
846         if (itemCount % countPerLine != 0)
847         {
848                 lineCount++;
849         }
850
851         layoutSize.width = countPerLine * __itemWidth + (countPerLine - 1) * __itemGap;
852         int showLineCount = __pContextMenu->GetShowItemMaxCount();
853         if (lineCount > showLineCount)
854         {
855                 SetLastResult(E_MAX_EXCEEDED);
856         }
857         else
858         {
859                 showLineCount = lineCount;
860         }
861         layoutSize.height = showLineCount * __itemHeight + (showLineCount - 1) *__itemGap;
862
863         _ContextMenuItem* pItem = null;
864
865         for (int line = 0; line < showLineCount; line++)
866         {
867                 float pressedTopMargin = 0.0f, pressedBottomMargin = 0.0f;
868                 if (line == 0)
869                 {
870                         pressedTopMargin = __bgPressedMargin;
871                 }
872
873                 if (line == showLineCount - 1)
874                 {
875                         pressedBottomMargin = __bgPressedMargin;
876                 }
877
878                 for (int i = 0; i < countPerLine; i++)
879                 {
880                         int index = (line * countPerLine) + i;
881                         if (index >= itemCount)
882                         {
883                                 break;
884                         }
885
886                         pItem = __pModel->GetItem(index);
887
888                         if (pItem == null)
889                         {
890                                 break;
891                         }
892
893                         FloatRectangle drawRect(0.0f, 0.0f, __itemWidth, __itemHeight);
894
895                         drawRect.x = (i * itemWidth);
896                         drawRect.y = (line * itemHeight);
897
898                         bool drawDivider = true;
899                         if (i == countPerLine - 1)
900                         {
901                                 drawDivider = false;
902                         }
903
904                         pItem->SetDrawRect(drawRect);
905                         pItem->SetLowerDivider(drawDivider);
906
907                         float pressedLeftMargin = 0.0f, pressedRightMargin = 0.0f;
908                         if (i == 0)
909                         {
910                                 pressedLeftMargin = __bgPressedMargin;
911                         }
912
913                         if (i == countPerLine  - 1)
914                         {
915                                 pressedRightMargin = __bgPressedMargin;
916                         }
917
918                         FloatRectangle pressedDrawRect = drawRect;
919                         pressedDrawRect.x      += pressedLeftMargin;
920                         pressedDrawRect.y      += pressedTopMargin;
921                         pressedDrawRect.width  -= pressedLeftMargin + pressedRightMargin;
922                         pressedDrawRect.height -= pressedTopMargin + pressedBottomMargin;
923                         pItem->SetPressedDrawRect(pressedDrawRect);
924                         __showItemCount = index;
925                 }
926         }
927
928         __showItemCount++;
929
930         return layoutSize;
931
932 }
933
934 Tizen::Graphics::FloatDimension
935 _ContextMenuGridPresenter::AdjustItemLayoutTabStyle(void)
936 {
937         ClearLastResult();
938
939         int lineItemCountList[MAX_LINE_COUNT] = {0, };
940         float lineWidthList[MAX_LINE_COUNT] = {0.0f, };
941
942         int itemCount = __pModel->GetItemCount();
943         float maxWidth = __itemWidth;
944         float itemHeight = __itemHeight + __itemGap;
945         int lineCount = 1, showLineCount = 0;
946         float lineWidth = 0.0f;
947         int lineItemCount = 0;
948         float x = 0.0f;
949         float y = 0.0f;
950         float remainWidth = 0.0f;
951         FloatDimension screen = _ControlManager::GetInstance()->GetScreenSizeF();
952         FloatPoint anchorPosition = __pContextMenu->GetAnchorPosition();
953         ContextMenuCoreDropPosition dropPosition = __pContextMenu->GetDropPosition();
954
955         if (__pContextMenu->GetLayout() == _CONTROL_ORIENTATION_LANDSCAPE)
956         {
957             GET_SHAPE_CONFIG(CONTEXTMENU::GRID_MAX_WIDTH, _CONTROL_ORIENTATION_LANDSCAPE, __maxWidth);
958                 screen.SetSize(screen.height, screen.width);
959         }
960         else
961         {
962             GET_SHAPE_CONFIG(CONTEXTMENU::GRID_MAX_WIDTH, _CONTROL_ORIENTATION_PORTRAIT, __maxWidth);
963         }
964
965         if (dropPosition == CONTEXT_MENU_CORE_DROP_POSITION_LEFT || dropPosition == CONTEXT_MENU_CORE_DROP_POSITION_RIGHT)
966         {
967                 remainWidth = anchorPosition.x * 2 < screen.width ? screen.width - anchorPosition.x : anchorPosition.x;
968                 remainWidth -= __screenLeftMargin + __leftMargin + __rightMargin + __screenRightMargin;
969                 remainWidth -= __arrowHeight;
970                 __maxWidth = __maxWidth < remainWidth ? __maxWidth : remainWidth;
971         }
972
973         _ContextMenuItem* pItem = null;
974         for (int i = 0; i < itemCount; i++)
975         {
976                 pItem = __pModel->GetItem(i);
977                 if (pItem == null)
978                 {
979                         break;
980                 }
981
982                 FloatDimension itemSize = pItem->GetSize();
983                 if (lineWidth + itemSize.width > __maxWidth)
984                 {
985                         _ContextMenuItem* pPreviousItem = __pModel->GetItem(i - 1);
986                         if (pPreviousItem != null)
987                         {
988                                 pPreviousItem->SetLowerDivider(false);
989                         }
990
991                         x = 0.0f;
992                         y = y + itemHeight;
993
994                         lineWidth = 0.0f;
995                         lineItemCount = 0;
996                         lineCount++;
997                 }
998
999                 FloatRectangle drawRect(x, y, itemSize.width, itemSize.height);
1000                 pItem->SetDrawRect(drawRect);
1001                 pItem->SetLowerDivider(true);
1002
1003                 x = x + itemSize.width + __itemGap;
1004                 lineWidth = lineWidth + itemSize.width + __itemGap;
1005
1006                 if (lineWidth > maxWidth)
1007                 {
1008                         maxWidth = lineWidth;
1009                 }
1010
1011                 lineItemCount++;
1012                 if (lineItemCount > MAX_LINE_COUNT)
1013                 {
1014                         lineItemCount = MAX_LINE_COUNT;
1015                         break;
1016                 }
1017
1018                 lineWidthList[lineCount - 1] = lineWidth;
1019                 lineItemCountList[lineCount - 1] = lineItemCount;
1020         }
1021
1022         // last item
1023         if (pItem != null)
1024         {
1025                 pItem->SetLowerDivider(false);
1026         }
1027
1028         FloatDimension layoutSize(__itemWidth, __itemHeight);
1029         layoutSize.width = maxWidth - __itemGap;
1030         showLineCount = __pContextMenu->GetShowItemMaxCount();
1031         if (lineCount > showLineCount)
1032         {
1033                 SetLastResult(E_MAX_EXCEEDED);
1034         }
1035         else
1036         {
1037                 showLineCount = lineCount;
1038         }
1039         layoutSize.height = showLineCount * __itemHeight + (showLineCount - 1) *__itemGap;
1040
1041         // divide margin
1042         int itemIndex = 0;
1043         for (int line = 0; line < showLineCount; line++)
1044         {
1045                 FloatRectangle drawRect;
1046                 float width = lineWidthList[line];
1047                 int count = lineItemCountList[line];
1048                 float blank = maxWidth - width;
1049                 float addMargin = blank / count;
1050                 if (_FloatCompareGE(blank, 100.0f) && line == showLineCount - 1)
1051                 {
1052                         addMargin = 0.0f;
1053                 }
1054
1055                 float pressedTopMargin = 0.0f, pressedBottomMargin = 0.0f;
1056                 if (line == 0)
1057                 {
1058                         pressedTopMargin = __bgPressedMargin;
1059                 }
1060
1061                 if (line == showLineCount - 1)
1062                 {
1063                         pressedBottomMargin = __bgPressedMargin;
1064                 }
1065
1066                 for (int i = 0; i < count; i++)
1067                 {
1068                         int index = itemIndex + i;
1069                         pItem = __pModel->GetItem(index);
1070                         if (pItem == null)
1071                         {
1072                                 break;
1073                         }
1074
1075                         drawRect = pItem->GetDrawRect();
1076
1077                         drawRect.width = drawRect.width + addMargin;
1078                         drawRect.x = drawRect.x + (i * addMargin);
1079
1080                         pItem->SetDrawRect(drawRect);
1081
1082                         float pressedLeftMargin = 0.0f, pressedRightMargin = 0.0f;
1083                         if (i == 0)
1084                         {
1085                                 pressedLeftMargin = __bgPressedMargin;
1086                         }
1087
1088                         if (i == count - 1)
1089                         {
1090                                 pressedRightMargin = __bgPressedMargin;
1091                         }
1092
1093                         FloatRectangle pressedDrawRect = drawRect;
1094                         pressedDrawRect.x      += pressedLeftMargin;
1095                         pressedDrawRect.y      += pressedTopMargin;
1096                         pressedDrawRect.width  -= pressedLeftMargin + pressedRightMargin;
1097                         pressedDrawRect.height -= pressedTopMargin + pressedBottomMargin;
1098                         pItem->SetPressedDrawRect(pressedDrawRect);
1099                         __showItemCount = index;
1100                 }
1101
1102                 itemIndex += count;
1103         }
1104
1105         __showItemCount++;
1106
1107         return layoutSize;
1108 }
1109
1110 void
1111 _ContextMenuGridPresenter::AdjustItemPosition(void)
1112 {
1113         int itemCount = __pModel->GetItemCount();
1114
1115         if (itemCount <= 0)
1116         {
1117                 return;
1118         }
1119
1120         int x = __pContextMenu->GetBodyRect().x + __leftMargin;
1121         int y = __pContextMenu->GetBodyRect().y + __topMargin;
1122
1123         _ContextMenuItem* pItem = null;
1124
1125         for (int i = 0; i < itemCount; i++)
1126         {
1127                 pItem = __pModel->GetItem(i);
1128
1129                 if (pItem == null)
1130                 {
1131                         break;
1132                 }
1133
1134                 FloatRectangle drawRect = pItem->GetDrawRect();
1135                 drawRect.x += x;
1136                 drawRect.y += y;
1137                 pItem->SetDrawRect(drawRect);
1138
1139                 FloatRectangle pressedDrawRect = pItem->GetPressedDrawRect();
1140                 pressedDrawRect.x += x;
1141                 pressedDrawRect.y += y;
1142                 pItem->SetPressedDrawRect(pressedDrawRect);
1143         }
1144 }
1145
1146 int
1147 _ContextMenuGridPresenter::GetCountPerLine(int count) const
1148 {
1149         static const int countOfX[MAX_ITEM_COUNT + 1] = {0,     // not used
1150                 1,      2,      3,      4,      5,      3,      4,      4,      5,      5,
1151                 4,      4,      5,      5,      5,      4,      5,      5,      5,      5,
1152                 5,      5,      5,      5,      5,      5,      5,      5,      5,      5,
1153                 5,      5,      5,      5,      5,
1154         };
1155
1156         return countOfX[count];
1157 }
1158
1159 int
1160 _ContextMenuGridPresenter::GetItemIndexFromPosition(const Tizen::Graphics::FloatPoint& point) const
1161 {
1162         int index = -1;
1163         int itemCount = __pModel->GetItemCount();
1164
1165         if (itemCount < 0)
1166         {
1167                 return -1;
1168         }
1169
1170         _ContextMenuItem* pItem = null;
1171
1172         for (int i = 0; i < itemCount; i++)
1173         {
1174                 pItem = __pModel->GetItem(i);
1175
1176                 if (pItem == null)
1177                 {
1178                         break;
1179                 }
1180
1181                 FloatRectangle drawRect = pItem->GetDrawRect();
1182
1183                 if (drawRect.Contains(point) == true)
1184                 {
1185                         index = i;
1186                         break;
1187                 }
1188         }
1189
1190         return index;
1191 }
1192
1193
1194 result
1195 _ContextMenuGridPresenter::Draw(void)
1196 {
1197         result r = E_SUCCESS;
1198
1199         Canvas* pCanvas = __pContextMenu->GetCanvasN();
1200         SysTryReturn(NID_UI_CTRL, pCanvas != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "The memory is insufficient.");
1201
1202         // Clear canvas for drawing area of the ContextMenu.
1203         pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
1204         Tizen::Graphics::FloatRectangle bounds(__pContextMenu->GetWindowRect());
1205         pCanvas->Clear(Tizen::Graphics::FloatRectangle(0.0f, 0.0f, bounds.width, bounds.height));
1206
1207         r = DrawBackground(pCanvas);
1208         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to draw background.");
1209
1210         r = DrawArrow(pCanvas);
1211         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to draw arrow.");
1212
1213         r = DrawItem(pCanvas);
1214
1215         delete pCanvas;
1216
1217         return r;
1218 }
1219
1220 result
1221 _ContextMenuGridPresenter::DrawBackground(Canvas* pCanvas)
1222 {
1223         SysTryReturn(NID_UI_CTRL, pCanvas != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
1224
1225         result r = E_SUCCESS;
1226
1227         Tizen::Graphics::FloatRectangle bodyRect = __pContextMenu->GetBodyRect();
1228
1229         const Bitmap* pBackgroundNormalBitmap = __pContextMenu->GetBackgroundNormalBitmap();
1230         const Bitmap* pBackgroundEffectBitmap = __pContextMenu->GetBackgroundEffectBitmap();
1231
1232         if (pBackgroundNormalBitmap == null && pBackgroundEffectBitmap == null)
1233         {
1234                 pCanvas->SetForegroundColor(__pContextMenu->GetColor());
1235                 pCanvas->DrawRectangle(bodyRect);
1236         }
1237         else
1238         {
1239                 if (pBackgroundNormalBitmap != null)
1240                 {
1241                         r = DrawBitmap(*pCanvas, bodyRect, *pBackgroundNormalBitmap);
1242                 }
1243
1244                 if (pBackgroundEffectBitmap != null)
1245                 {
1246                         r = DrawBitmap(*pCanvas, bodyRect, *pBackgroundEffectBitmap);
1247                 }
1248         }
1249
1250         return r;
1251 }
1252
1253 result
1254 _ContextMenuGridPresenter::DrawArrow(Canvas* pCanvas)
1255 {
1256         SysTryReturn(NID_UI_CTRL, pCanvas != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
1257
1258         result r = E_SUCCESS;
1259         Tizen::Graphics::FloatRectangle arrowRect = __pContextMenu->GetArrowRect();
1260         ContextMenuCoreDropPosition dropPosition = __pContextMenu->GetDropPosition();
1261
1262         const Bitmap* pArrowNormalBitmap = __pContextMenu->GetArrowNormalBitmap(dropPosition);
1263         const Bitmap* pEffectArrowBitmap = __pContextMenu->GetArrowEffectBitmap(dropPosition);
1264
1265         if (pArrowNormalBitmap != null)
1266         {
1267                 r = DrawBitmap(*pCanvas, arrowRect, *pArrowNormalBitmap);
1268         }
1269
1270         if (pEffectArrowBitmap != null)
1271         {
1272                 r = DrawBitmap(*pCanvas, arrowRect, *pEffectArrowBitmap);
1273         }
1274
1275         return r;
1276 }
1277
1278 result
1279 _ContextMenuGridPresenter::DrawItem(Tizen::Graphics::Canvas* pCanvas)
1280 {
1281         SysTryReturn(NID_UI_CTRL, pCanvas != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
1282
1283         result r = E_SUCCESS;
1284         TextSimple* pSimpleText = null;
1285
1286         int itemCount = __showItemCount;
1287
1288         if (itemCount <= 0)
1289         {
1290                 return E_SUCCESS;
1291         }
1292
1293         FloatRectangle bodyRect = __pContextMenu->GetBodyRect();
1294         Color pressedColor = __pContextMenu->GetItemColor(CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED);
1295
1296         float bitmapLeftMargin = __itemBitmapWidth / 2.0f;
1297         float bitmapTopMargin = __itemBitmapHeight / 2.0f;
1298         float linePositionX = bodyRect.x + __leftMargin + __rightMargin;
1299         float linePositionY = bodyRect.y + __topMargin;
1300
1301         _ContextMenuItem* pItem = null;
1302
1303         for (int i = 0; i < itemCount; i++)
1304         {
1305                 pItem = __pModel->GetItem(i);
1306
1307                 if (pItem == null)
1308                 {
1309                         continue;
1310                 }
1311
1312                 FloatRectangle rect = pItem->GetDrawRect();
1313                 // divder
1314                 bool drawDivider = pItem->HasLowerDivider();
1315                 if (drawDivider == true)
1316                 {
1317                         float x = rect.x + rect.width;
1318                         float y = rect.y + __topMargin;
1319
1320                         FloatPoint point1(x, y);
1321                         FloatPoint point2(x, y + __dividerHeight);
1322
1323
1324                         DrawLine(pCanvas, point1, point2, true);
1325                 }
1326
1327                 // horizontal line
1328 // TOCHK find out what makes SHAPE_CONFIG values * 2 / 3                if (!_FloatCompare(linePositionY, rect.y))
1329                 if (linePositionY - rect.y > 1.0f || linePositionY - rect.y < -1.0f)
1330                 {
1331                         linePositionY = rect.y;
1332
1333                         float x = linePositionX + __layoutSize.width - __leftMargin - __rightMargin;
1334                         float y = linePositionY - __itemGap;
1335
1336                         FloatPoint point1(linePositionX, y);
1337                         FloatPoint point2(x, y);
1338
1339                         DrawLine(pCanvas, point1, point2, false);
1340                 }
1341
1342                 ContextMenuItemDrawingType itemType = pItem->GetType();
1343
1344                 if (itemType == CONTEXT_MENU_ITEM_DRAWING_TYPE_TEXT)
1345                 {
1346                         FloatRectangle drawRect = rect;
1347                         drawRect.x = drawRect.x + __itemTextMargin;
1348                         drawRect.width = drawRect.width - (__itemTextMargin * 2.0f);
1349
1350                         ContextMenuCoreItemStatus itemStatus = CONTEXT_MENU_CORE_ITEM_STATUS_NORMAL;
1351
1352                         if (__selectedIndex == i)
1353                         {
1354                                 FloatRectangle pressedDrawRect = pItem->GetPressedDrawRect();
1355                                 itemStatus = CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED;
1356                                 Bitmap* bgBitmap = _BitmapImpl::GetColorReplacedBitmapN(*(pItem->GetMagentaBgBitmap()), Color::GetColor(COLOR_ID_MAGENTA), pressedColor);
1357                                 SysTryReturn(NID_UI_CTRL, bgBitmap, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1358
1359                                 DrawBitmap(*pCanvas, pressedDrawRect, *bgBitmap);
1360                                 delete bgBitmap;
1361                                 bgBitmap = null;
1362                         }
1363
1364                         String text = pItem->GetText();
1365
1366                         __pTextObject->RemoveAll();
1367                         pSimpleText = new (std::nothrow)TextSimple(const_cast <mchar*>(text.GetPointer()), text.GetLength());
1368                         SysTryReturn(NID_UI_CTRL, pSimpleText != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1369                         __pTextObject->AppendElement(*pSimpleText);
1370
1371                         __pTextObject->SetForegroundColor(__pContextMenu->GetTextColor(itemStatus), 0, __pTextObject->GetTextLength());
1372                         __pTextObject->SetBounds(drawRect);
1373                         __pTextObject->SetFont(__pFont, 0, __pTextObject->GetTextLength());
1374                         __pTextObject->Draw(*_CanvasImpl::GetInstance(*pCanvas));
1375
1376                 }
1377                 else
1378                 {
1379                         FloatRectangle drawRect = rect;
1380
1381                         drawRect.x = drawRect.x + drawRect.width / 2.0f - bitmapLeftMargin;
1382                         drawRect.y = drawRect.y + drawRect.height / 2.0f - bitmapTopMargin;
1383                         drawRect.width = __itemBitmapWidth;
1384                         drawRect.height = __itemBitmapHeight;
1385
1386                         ContextMenuItemDrawingStatus itemStatus = CONTEXT_MENU_ITEM_DRAWING_STATUS_NORMAL;
1387
1388                         if (__selectedIndex == i)
1389                         {
1390                                 FloatRectangle pressedDrawRect = pItem->GetPressedDrawRect();
1391                                 itemStatus = CONTEXT_MENU_ITEM_DRAWING_STATUS_PRESSED;
1392                                 Bitmap* bgBitmap = _BitmapImpl::GetColorReplacedBitmapN(*(pItem->GetMagentaBgBitmap()), Color::GetColor(COLOR_ID_MAGENTA), pressedColor);
1393                                 SysTryReturn(NID_UI_CTRL, bgBitmap, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1394
1395                                 DrawBitmap(*pCanvas, pressedDrawRect, *bgBitmap);
1396                                 delete bgBitmap;
1397                                 bgBitmap = null;
1398                         }
1399
1400                         const Bitmap* pBitmap = pItem->GetBitmap(itemStatus);
1401                         if (pBitmap != null)
1402                         {
1403                                 DrawBitmap(*pCanvas, drawRect, *pBitmap);
1404                         }
1405                 }
1406
1407                 if (__focusedIndex == i)
1408                 {
1409                         FloatRectangle pressedDrawRect = pItem->GetPressedDrawRect();
1410
1411                         Color contentHighlightedColor;
1412                         GET_COLOR_CONFIG(FOCUSUI::CONTENT_BG_HIGHLIGHTED, contentHighlightedColor);
1413                         Bitmap* pBitmap = null;
1414                         Bitmap* pTempBitmap = null;
1415                         result r = GET_BITMAP_CONFIG_N(FOCUSUI::FOCUS, BITMAP_PIXEL_FORMAT_ARGB8888, pTempBitmap);
1416                         SysTryReturn(NID_UI_CTRL, pTempBitmap != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1417                         if (r == E_SUCCESS)
1418                         {
1419                                 pBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pTempBitmap, Color::GetColor(COLOR_ID_MAGENTA), contentHighlightedColor);
1420                                 if (pBitmap != null)
1421                                 {
1422                                         DrawBitmap(*pCanvas, pressedDrawRect, *pBitmap);
1423                                 }
1424                         }
1425
1426                         delete pTempBitmap;
1427                         pTempBitmap = null;
1428
1429                         delete pBitmap;
1430                         pBitmap = null;
1431                 }
1432
1433         }
1434
1435         return r;
1436 }
1437
1438 result
1439 _ContextMenuGridPresenter::DrawLine(Tizen::Graphics::Canvas* pCanvas, Tizen::Graphics::FloatPoint point1, Tizen::Graphics::FloatPoint point2, bool drawVLine)
1440 {
1441         SysTryReturn(NID_UI_CTRL, pCanvas != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
1442
1443         result r = E_SUCCESS;
1444
1445         Color colorGridItemDivider01;
1446         Color colorGridItemDivider02;
1447
1448         GET_COLOR_CONFIG(CONTEXTMENU::GRID_ITEM_DIVIDER_01_NORMAL, colorGridItemDivider01);
1449         GET_COLOR_CONFIG(CONTEXTMENU::GRID_ITEM_DIVIDER_02_NORMAL, colorGridItemDivider02);
1450
1451         if (drawVLine == true)
1452         {
1453                 pCanvas->SetForegroundColor(colorGridItemDivider01);
1454                 pCanvas->DrawLine(point1, point2);
1455
1456                 point1.x++;
1457                 point2.x++;
1458
1459                 pCanvas->SetForegroundColor(colorGridItemDivider02);
1460                 pCanvas->DrawLine(point1, point2);
1461         }
1462         else
1463         {
1464                 pCanvas->SetForegroundColor(colorGridItemDivider01);
1465                 pCanvas->DrawLine(point1, point2);
1466
1467                 point1.y++;
1468                 point2.y++;
1469
1470                 pCanvas->SetForegroundColor(colorGridItemDivider02);
1471                 pCanvas->DrawLine(point1, point2);
1472         }
1473
1474         return r;
1475 }
1476
1477 _UiTouchEventDelivery
1478 _ContextMenuGridPresenter::OnPreviewTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
1479 {
1480         return _UI_TOUCH_EVENT_DELIVERY_FORCED_YES;
1481 }
1482
1483 bool
1484 _ContextMenuGridPresenter::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
1485 {
1486         FloatPoint touchPosition = touchinfo.GetCurrentPosition();
1487         FloatRectangle itemRect = __pContextMenu->GetItemRect();
1488
1489         if (itemRect.Contains(touchPosition) == false)
1490         {
1491                 __selectedIndex = -1;
1492                 __pressedIndex = -1;
1493                 __touchOutRect = true;
1494
1495                 return true;
1496         }
1497
1498         __selectedIndex = GetItemIndexFromPosition(touchPosition);
1499         __pressedIndex = __selectedIndex;
1500         __touchOutRect = false;
1501         Draw();
1502
1503         return true;
1504 }
1505
1506 _UiTouchEventDelivery
1507 _ContextMenuGridPresenter::OnPreviewTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
1508 {
1509         return _UI_TOUCH_EVENT_DELIVERY_FORCED_YES;
1510 }
1511
1512 bool
1513 _ContextMenuGridPresenter::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
1514 {
1515         FloatPoint touchPosition = touchinfo.GetCurrentPosition();
1516
1517         if (__touchOutRect == true)
1518         {
1519                 __pContextMenu->SetFocused(false);
1520                 __pContextMenu->SetVisibleState(false);
1521         }
1522
1523         int currentSelectedIndex = GetItemIndexFromPosition(touchPosition);
1524         if (__selectedIndex != -1 && (__selectedIndex == currentSelectedIndex))
1525         {
1526                 _ActionEvent* pActionEvent = __pContextMenu->GetActionEvent();
1527
1528                 if (pActionEvent == null)
1529                 {
1530                         __pContextMenu->SetFocused(false);
1531                         __pContextMenu->SetVisibleState(false);
1532                         return true;
1533                 }
1534
1535                 _ContextMenuItem* pItem = null;
1536                 pItem = __pModel->GetItem(__selectedIndex);
1537
1538                 if (pItem == null)
1539                 {
1540                         __selectedIndex = -1;
1541                         __pressedIndex = -1;
1542                         __focusedIndex = -1;
1543                         __pContextMenu->SetFocused(false);
1544                         __pContextMenu->SetVisibleState(false);
1545                         return true;
1546                 }
1547
1548                 __selectedIndex = -1;
1549                 __pressedIndex = -1;
1550                 __focusedIndex = -1;
1551
1552                 int actionId = pItem->GetActionId();
1553
1554                 IEventArg* pEventArg = _ActionEvent::CreateActionEventArgN(actionId);
1555
1556                 if (pEventArg == null)
1557                 {
1558                         __pContextMenu->SetFocused(false);
1559                         __pContextMenu->SetVisibleState(false);
1560                         return true;
1561                 }
1562
1563                 PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_TAP, __pContextMenu);
1564                 __pContextMenu->SetFocused(false);
1565                 __pContextMenu->SetVisibleState(false);
1566                 pActionEvent->Fire(*pEventArg);
1567         }
1568
1569         return true;
1570 }
1571
1572 _UiTouchEventDelivery
1573 _ContextMenuGridPresenter::OnPreviewTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
1574 {
1575         return _UI_TOUCH_EVENT_DELIVERY_FORCED_YES;
1576 }
1577
1578 bool
1579 _ContextMenuGridPresenter::OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
1580 {
1581         __selectedIndex = -1;
1582         __pressedIndex = -1;
1583
1584         return true;
1585 }
1586
1587 _UiTouchEventDelivery
1588 _ContextMenuGridPresenter::OnPreviewTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
1589 {
1590         return _UI_TOUCH_EVENT_DELIVERY_FORCED_YES;
1591 }
1592
1593 bool
1594 _ContextMenuGridPresenter::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
1595 {
1596         FloatPoint touchPosition = touchinfo.GetCurrentPosition();
1597
1598         if (__selectedIndex != -1)
1599         {
1600                 _ContextMenuItem* pItem = __pModel->GetItem(__selectedIndex);
1601
1602                 if (pItem == null)
1603                 {
1604                         __selectedIndex = -1;
1605                         __pressedIndex = -1;
1606                         return true;
1607                 }
1608
1609                 FloatRectangle drawRect = pItem->GetDrawRect();
1610                 if (drawRect.Contains(touchPosition) == false)
1611                 {
1612                         __selectedIndex = -1;
1613                         Draw();
1614                 }
1615         }
1616         else if (__pressedIndex != -1)
1617         {
1618                 _ContextMenuItem* pItem = __pModel->GetItem(__pressedIndex);
1619                 if(pItem != null)
1620                 {
1621                         FloatRectangle drawRect = pItem->GetDrawRect();
1622                         if(drawRect.Contains(touchPosition))
1623                         {
1624                                 __selectedIndex = __pressedIndex;
1625                                 Draw();
1626                         }
1627                 }
1628         }
1629
1630         return true;
1631 }
1632
1633 bool
1634 _ContextMenuGridPresenter::OnKeyPressed(const _Control& source, const _KeyInfo& keyInfo)
1635 {
1636         _KeyCode keyCode = keyInfo.GetKeyCode();
1637
1638         switch (keyCode)
1639         {
1640         case _KEY_LEFT:
1641                 // fall through
1642         case _KEY_UP:
1643         {
1644                 if (__enterKeyPressed)
1645                 {
1646                         __enterKeyPressed = false;
1647                         __selectedIndex = -1;
1648                 }
1649
1650                 if (--__focusedIndex < 0)
1651                 {
1652                         __focusedIndex = 0;
1653                 }
1654
1655                 _ContextMenuItem* pItem = __pModel->GetItem(__focusedIndex);
1656                 if (pItem == null)
1657                 {
1658                         __focusedIndex = -1;
1659                         break;
1660                 }
1661                 pItem->SetFocused(true);
1662                 Draw();
1663
1664                 break;
1665         }
1666         case _KEY_RIGHT:
1667                 // fall through
1668         case _KEY_DOWN:
1669         {
1670                 if (__enterKeyPressed)
1671                 {
1672                         __enterKeyPressed = false;
1673                         __selectedIndex = -1;
1674                 }
1675
1676                 _ContextMenuItem* pItem = __pModel->GetItem(++__focusedIndex);
1677                 if(pItem == null)
1678                 {
1679                         --__focusedIndex;
1680                         break;
1681                 }
1682                 pItem->SetFocused(true);
1683                 Draw();
1684
1685                 break;
1686         }
1687         case _KEY_ENTER:
1688         {
1689                 __enterKeyPressed = true;
1690
1691                 if (__focusedIndex == -1)
1692                 {
1693                         break;
1694                 }
1695
1696                 __selectedIndex = __focusedIndex;
1697                 _ContextMenuItem* pItem = __pModel->GetItem(__focusedIndex);
1698                 if (pItem != null)
1699                 {
1700                         pItem->SetFocused(true);
1701                         Draw();
1702                 }
1703
1704                 break;
1705         }
1706         case _KEY_BACKSPACE:
1707         {
1708                 _ContextMenuItem* pItem = __pModel->GetItem(__focusedIndex);
1709                 if (pItem != null)
1710                 {
1711                         pItem->SetFocused(false);
1712                 }
1713
1714                 __enterKeyPressed = false;
1715                 __backKeyPressed = false;
1716                 __pressedIndex = -1;
1717                 __selectedIndex = -1;
1718                 __focusedIndex = -1;
1719
1720                 __pContextMenu->SetFocused(false);
1721                 __pContextMenu->SetVisibleState(false);
1722
1723                 break;
1724         }
1725         case _KEY_ESC:
1726                 // fall through
1727         case _KEY_MENU:
1728                 // fall through
1729         case _KEY_CONTEXT_MENU:
1730                 // fall through
1731         case _KEY_BACK:
1732                 __backKeyPressed = true;
1733                 break;
1734         default:
1735                 return false;
1736         }
1737
1738         return true;
1739 }
1740
1741 bool
1742 _ContextMenuGridPresenter::OnKeyReleased(const _Control& source, const _KeyInfo& keyInfo)
1743 {
1744         _KeyCode keyCode = keyInfo.GetKeyCode();
1745
1746         switch (keyCode)
1747         {
1748         case _KEY_LEFT:
1749                 // fall through
1750         case _KEY_UP:
1751                 // fall through
1752         case _KEY_RIGHT:
1753                 // fall through
1754         case _KEY_DOWN:
1755                 // fall through
1756         case _KEY_BACKSPACE:
1757                 break;
1758         case _KEY_ENTER:
1759         {
1760                 if (!__enterKeyPressed)
1761                 {
1762                         return true;
1763                 }
1764
1765                 __enterKeyPressed = false;
1766                 __backKeyPressed =  false;
1767
1768                 _ContextMenuItem* pItem = __pModel->GetItem(__selectedIndex);
1769                 if (pItem == null)
1770                 {
1771                         __selectedIndex = -1;
1772                         __pressedIndex = -1;
1773                         __focusedIndex = -1;
1774                         __pContextMenu->SetFocused(false);
1775                         __pContextMenu->SetVisibleState(false);
1776
1777                         break;
1778                 }
1779
1780                 int actionId = pItem->GetActionId();
1781
1782                 _ActionEvent* pActionEvent = __pContextMenu->GetActionEvent();
1783                 if (pActionEvent == null)
1784                 {
1785                         break;
1786                 }
1787
1788                 IEventArg* pEventArg = _ActionEvent::CreateActionEventArgN(actionId);
1789                 if (pEventArg == null)
1790                 {
1791                         break;
1792                 }
1793
1794                 pActionEvent->Fire(*pEventArg);
1795
1796                 __selectedIndex = -1;
1797                 __pressedIndex = -1;
1798                 __focusedIndex = -1;
1799                 pItem->SetFocused(false);
1800                 __pContextMenu->SetFocused(false);
1801                 __pContextMenu->SetVisibleState(false);
1802
1803                 break;
1804         }
1805         case _KEY_ESC:
1806                 // fall through
1807         case _KEY_MENU:
1808                 // fall through
1809         case _KEY_CONTEXT_MENU:
1810                 // fall through
1811         case _KEY_BACK:
1812         {
1813                 if (!__backKeyPressed)
1814                 {
1815                         return true;
1816                 }
1817
1818                 _ContextMenuItem* pItem = __pModel->GetItem(__focusedIndex);
1819                 if (pItem != null)
1820                 {
1821                         pItem->SetFocused(false);
1822                 }
1823
1824                 __enterKeyPressed = false;
1825                 __backKeyPressed = false;
1826                 __selectedIndex = -1;
1827                 __pressedIndex = -1;
1828                 __focusedIndex = -1;
1829                 __pContextMenu->SetFocused(false);
1830                 __pContextMenu->SetVisibleState(false);
1831
1832                 break;
1833         }
1834         default:
1835                 return false;
1836         }
1837
1838         return true;
1839 }
1840
1841 bool
1842 _ContextMenuGridPresenter::IsChildControlFocusManage(void) const
1843 {
1844         return true;
1845 }
1846
1847 void
1848 _ContextMenuGridPresenter::OnDrawFocus(void)
1849 {
1850         if (__focusedIndex == -1)
1851         {
1852                 __focusedIndex = 0;
1853         }
1854         __selectedIndex = -1;
1855
1856         Draw();
1857 }
1858
1859 void
1860 _ContextMenuGridPresenter::OnFocusModeStateChanged(void)
1861 {
1862         __focusedIndex = -1;
1863         Draw();
1864 }
1865
1866 void
1867 _ContextMenuGridPresenter::OnFontChanged(Font* pFont)
1868 {
1869         __pFont = pFont;
1870 }
1871
1872 void
1873 _ContextMenuGridPresenter::OnFontInfoRequested(unsigned long& style, float& size)
1874 {
1875         style = FONT_STYLE_PLAIN;
1876         size = __itemFontSize;
1877 }
1878
1879 void
1880 _ContextMenuGridPresenter::SetAllAccessibilityElement(void)
1881 {
1882         _AccessibilityContainer* pContainer = __pContextMenu->GetAccessibilityContainer();
1883         if (pContainer != null)
1884         {
1885                 _AccessibilityElement* pElementContextMenu = new (std::nothrow) _AccessibilityElement(true);
1886                 SysTryReturnVoidResult(NID_UI_CTRL, pElementContextMenu, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
1887
1888                 pElementContextMenu->SetSupportOperatingGesture(false);
1889                 pElementContextMenu->SetTraitWithStringId("IDS_TPLATFORM_BODY_CONTEXTUAL_POP_UP_T_TTS");
1890                 pElementContextMenu->SetHint(L"double tap to close");
1891                 pElementContextMenu->SetBounds(FloatRectangle(0.0f, 0.0f, __pContextMenu->GetBoundsF().width, __pContextMenu->GetBoundsF().height));
1892                 pContainer->AddElement(*pElementContextMenu);
1893                 __pContextMenu->AddAccessibilityElement(*pElementContextMenu);
1894
1895                 int itemCount = __pModel->GetItemCount();
1896                 for (int i = 0; i < itemCount; i++)
1897                 {
1898                         _ContextMenuItem* pItem = __pModel->GetItem(i);
1899                         _AccessibilityElement* pElement = new (std::nothrow) _AccessibilityElement(true);
1900                         if (pItem != null && pElement != null)
1901                         {
1902                                 pElement->SetName(L"ContextMenuItem" + Integer::ToString(i));
1903                                 if (pItem->GetType() == CONTEXT_MENU_ITEM_DRAWING_TYPE_BITMAP)
1904                                 {
1905                                         pElement->SetLabel(L"icon");
1906                                 }
1907                                 else
1908                                 {
1909                                         pElement->SetLabel(pItem->GetText());
1910                                 }
1911
1912                                 pElement->SetTraitWithStringId("IDS_TPLATFORM_BODY_CONTEXTUAL_POP_UP_T_TTS");
1913                                 pElement->SetBounds(pItem->GetDrawRect());
1914                                 pContainer->AddElement(*pElement);
1915                                 __pContextMenu->AddAccessibilityElement(*pElement);
1916                         }
1917                         else
1918                         {
1919                                 delete pElement;
1920                         }
1921                 }
1922         }
1923
1924 }
1925
1926 _ContextMenuItemInfo
1927 _ContextMenuGridPresenter::GetItemFromPosition(const FloatPoint& position)
1928 {
1929         _ContextMenuItemInfo itemInfo;
1930         int index = GetItemIndexFromPosition(position);
1931         itemInfo.pContextMenuItem = __pModel->GetItem(index);
1932
1933         itemInfo.bListItem = false;
1934         itemInfo.pListItem = null;
1935         return itemInfo;
1936 }
1937
1938 _ContextMenuItemInfo
1939 _ContextMenuGridPresenter::FindItem(int index)
1940 {
1941         _ContextMenuItemInfo itemInfo;
1942         itemInfo.bListItem = false;
1943         itemInfo.pListItem = null;
1944         itemInfo.pContextMenuItem = __pModel->GetItem(index);
1945         return itemInfo;
1946 }
1947
1948 result
1949 _ContextMenuGridPresenter::SetTopDrawnItemIndex(int index)
1950 {
1951         return E_SUCCESS;
1952 }
1953
1954 result
1955 _ContextMenuGridPresenter::DrawBitmap(Tizen::Graphics::Canvas& canvas, const Tizen::Graphics::FloatRectangle& bounds, const Tizen::Graphics::Bitmap& bitmap)
1956 {
1957         result r = E_SUCCESS;
1958         if (_BitmapImpl::CheckNinePatchedBitmapStrictly(bitmap))
1959         {
1960                 r = canvas.DrawNinePatchedBitmap(bounds, bitmap);
1961                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Fail to draw ninepatched bitmap.")
1962         }
1963         else
1964         {
1965                 r = canvas.DrawBitmap(bounds, bitmap);
1966                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Fail to draw bitmap.")
1967         }
1968
1969         return r;
1970 }
1971
1972 }}} // Tizen::Ui: Control