Changed indicator bg color.
[platform/framework/native/uifw.git] / src / ui / controls / FUiCtrl_OptionMenuItem.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an ”AS IS” BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file                FUiCtrl_OptionMenuItem.cpp
20  * @brief               This is the implementation file for the _OptionMenuItem class.
21  */
22
23 #include <FBaseSysLog.h>
24 #include <FGrp_BitmapImpl.h>
25 #include "FUi_AccessibilityContainer.h"
26 #include "FUi_AccessibilityElement.h"
27 #include "FUi_CoordinateSystemUtils.h"
28 #include "FUi_Math.h"
29 #include "FUi_ResourceManager.h"
30
31 #include "FUiCtrl_ScrollPanel.h"
32 #include "FUiCtrl_OptionMenuItem.h"
33
34 using namespace Tizen::Base;
35 using namespace Tizen::Graphics;
36 using namespace Tizen::Ui;
37
38 namespace {
39 static const float TOUCH_PRESS_THRESHOLD_INSENSITIVE = 0.16f;
40 }
41
42 namespace Tizen { namespace Ui { namespace Controls
43 {
44
45 _OptionMenuItem::_OptionMenuItem(void)
46         : __type(OPTION_MENU_ITEM_DRAWING_TYPE_NONE)
47         , __actionId(-1)
48         , __upperDividerLine(false)
49         , __lowerDividerLine(false)
50         , __selected(false)
51         , __highlighted(false)
52         , __parentScrollEnable(false)
53         , __leftMargin(0.0f)
54         , __rightMargin(0.0f)
55         , __dividerHeight(0.0f)
56         , __bgPressedMargin(0.0f)
57         , __textLeftMargin(0.0f)
58         , __textRightMargin(0.0f)
59         , __textTopMargin(0.0f)
60         , __textBottomMargin(0.0f)
61         , __arrowLeftMargin(0.0f)
62         , __arrowRightMargin(0.0f)
63         , __arrowMargin(0.0f)
64         , __itemHeight(0.0f)
65         , __textSize(0.0f)
66         , __text(L"")
67         , __pMagentaBgBitmap(null)
68         , __pArrowBitmap(null)
69         , __pArrowPressedBitmap(null)
70         , __size(FloatDimension(0.0f, 0.0f))
71         , __drawRect(FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f))
72         , __pBitmapLabel(null)
73         , __pTextLabel(null)
74         , __pUpperDividerLineLabel(null)
75         , __pBackgroundLabel(null)
76         , __pLowerDividerLineLabel(null)
77         , __pArrowLabel(null)
78         , __pSubItems(null)
79 {
80         _ControlOrientation orientation = GetOrientation();
81
82         __pBitmap[OPTION_MENU_ITEM_DRAWING_STATUS_NORMAL] = null;
83         __pBitmap[OPTION_MENU_ITEM_DRAWING_STATUS_PRESSED] = null;
84         __pBitmap[OPTION_MENU_ITEM_DRAWING_STATUS_HIGHLIGHTED] = null;
85
86         GET_SHAPE_CONFIG(OPTIONMENU::LIST_LEFT_MARGIN,  _CONTROL_ORIENTATION_PORTRAIT, __leftMargin);
87         GET_SHAPE_CONFIG(OPTIONMENU::LIST_RIGHT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, __rightMargin);
88         GET_SHAPE_CONFIG(OPTIONMENU::LIST_DIVIDER_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, __dividerHeight);
89         GET_SHAPE_CONFIG(OPTIONMENU::ITEM_BG_PRESSED_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, __bgPressedMargin);
90
91         GET_SHAPE_CONFIG(OPTIONMENU::TEXT_LEFT_MARGIN, orientation, __textLeftMargin);
92         GET_SHAPE_CONFIG(OPTIONMENU::TEXT_RIGHT_MARGIN, orientation, __textRightMargin);
93         GET_SHAPE_CONFIG(OPTIONMENU::TEXT_TOP_MARGIN, orientation, __textTopMargin);
94         GET_SHAPE_CONFIG(OPTIONMENU::TEXT_BOTTOM_MARGIN, orientation, __textBottomMargin);
95         GET_SHAPE_CONFIG(OPTIONMENU::LEFT_MARGIN, orientation, __arrowLeftMargin);
96         GET_SHAPE_CONFIG(OPTIONMENU::RIGHT_MARGIN, orientation, __arrowRightMargin);
97         GET_SHAPE_CONFIG(OPTIONMENU::ARROW_MARGIN, orientation, __arrowMargin);
98         GET_SHAPE_CONFIG(OPTIONMENU::ITEM_HEIGHT, orientation, __itemHeight);
99
100         GET_COLOR_CONFIG(OPTIONMENU::ITEM_BG_PRESSED, __selectedBgColor);
101         GET_COLOR_CONFIG(OPTIONMENU::LIST_ITEM_DIVIDER_01_NORMAL, __lowerDividerLineColor);     // lower divider of item n and
102         GET_COLOR_CONFIG(OPTIONMENU::LIST_ITEM_DIVIDER_02_NORMAL, __upperDividerLineColor);     // upper divider of item n+1 are bonded together.
103         GET_BITMAP_CONFIG_N(OPTIONMENU::ITEM_BG_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, __pMagentaBgBitmap);
104
105         InitializeAccessibilityElement();
106 }
107
108 _OptionMenuItem::~_OptionMenuItem(void)
109 {
110         if (__pBitmap[OPTION_MENU_ITEM_DRAWING_STATUS_NORMAL] != null)
111         {
112                 delete __pBitmap[OPTION_MENU_ITEM_DRAWING_STATUS_NORMAL];
113                 __pBitmap[OPTION_MENU_ITEM_DRAWING_STATUS_NORMAL] = null;
114         }
115
116         if (__pBitmap[OPTION_MENU_ITEM_DRAWING_STATUS_PRESSED] != null)
117         {
118                 delete __pBitmap[OPTION_MENU_ITEM_DRAWING_STATUS_PRESSED];
119                 __pBitmap[OPTION_MENU_ITEM_DRAWING_STATUS_PRESSED] = null;
120         }
121
122         if (__pBitmap[OPTION_MENU_ITEM_DRAWING_STATUS_HIGHLIGHTED] != null)
123         {
124                 delete __pBitmap[OPTION_MENU_ITEM_DRAWING_STATUS_HIGHLIGHTED];
125                 __pBitmap[OPTION_MENU_ITEM_DRAWING_STATUS_HIGHLIGHTED] = null;
126         }
127
128         if (__pUpperDividerLineLabel != null)
129         {
130                 DetachChild(*__pUpperDividerLineLabel);
131                 delete __pUpperDividerLineLabel;
132                 __pUpperDividerLineLabel = null;
133         }
134
135         if (__pBackgroundLabel != null)
136         {
137                 DetachChild(*__pBackgroundLabel);
138                 delete __pBackgroundLabel;
139                 __pBackgroundLabel = null;
140         }
141
142         if (__pBitmapLabel != null)
143         {
144                 DetachChild(*__pBitmapLabel);
145                 delete __pBitmapLabel;
146                 __pBitmapLabel = null;
147         }
148
149         if (__pTextLabel != null)
150         {
151                 DetachChild(*__pTextLabel);
152                 delete __pTextLabel;
153                 __pTextLabel = null;
154         }
155
156         delete __pMagentaBgBitmap;
157         __pMagentaBgBitmap = null;
158
159         delete __pArrowBitmap;
160         __pArrowBitmap = null;
161
162         delete __pArrowPressedBitmap;
163         __pArrowPressedBitmap = null;
164
165         if (__pLowerDividerLineLabel != null)
166         {
167                 DetachChild(*__pLowerDividerLineLabel);
168                 delete __pLowerDividerLineLabel;
169                 __pLowerDividerLineLabel = null;
170         }
171
172         if (__pArrowLabel != null)
173         {
174                 DetachChild(*__pArrowLabel);
175                 delete __pArrowLabel;
176                 __pArrowLabel = null;
177         }
178
179         if (__pSubItems != null)
180         {
181                 __pSubItems->RemoveAll(true);
182                 delete __pSubItems;
183                 __pSubItems = null;
184         }
185
186         _AccessibilityContainer* pContainer = GetAccessibilityContainer();
187         if (pContainer)
188         {
189                 pContainer->RemoveAllElement();
190         }
191 }
192
193 _OptionMenuItem*
194 _OptionMenuItem::CreateOptionMenuItemN(void)
195 {
196         ClearLastResult();
197
198         _OptionMenuItem* pItem = null;
199
200         pItem = new (std::nothrow) _OptionMenuItem();
201         if (pItem == null)
202         {
203                 SetLastResult(E_OUT_OF_MEMORY);
204                 return null;
205         }
206
207         pItem->AcquireHandle();
208
209         SetLastResult(E_SUCCESS);
210         return pItem;
211 }
212
213 result
214 _OptionMenuItem::InsertSubItemAt(_OptionMenuItem& subItem, int index)
215 {
216         if (__pSubItems == null)
217         {
218                 __pSubItems = new (std::nothrow) ArrayList;
219                 SysTryReturn(NID_UI_CTRL, (__pSubItems != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
220
221                 result r = __pSubItems->Construct();
222                 if (r != E_SUCCESS)
223                 {
224                         delete __pSubItems;
225                         __pSubItems = null;
226                         SysLogException(NID_UI_CTRL, r, "[%s] Propagating.", GetErrorMessage(r));
227                         return r;
228                 }
229         }
230
231         SysTryReturn(NID_UI_CTRL, (index >= 0 && index <= __pSubItems->GetCount()), E_INVALID_ARG, E_INVALID_ARG,
232                         "[E_INVALID_ARG]  The specified index (%d) is greater than the available items count.", index);
233
234         return __pSubItems->InsertAt(subItem, index);
235 }
236
237 result
238 _OptionMenuItem::SetSubItemAt(_OptionMenuItem& subItem, int index)
239 {
240         _OptionMenuItem* pItem = static_cast<_OptionMenuItem*>(__pSubItems->GetAt(index));
241
242         pItem->SetText(subItem.GetText());
243         pItem->SetActionId(subItem.GetActionId());
244
245         delete &subItem;
246
247         return E_SUCCESS;
248 }
249
250 result
251 _OptionMenuItem::RemoveSubItemAt(int index)
252 {
253         SysTryReturn(NID_UI_CTRL, (__pSubItems != null), E_SYSTEM, E_SYSTEM,
254                         "[E_SYSTEM] A system error has occurred. The sub items list is null.");
255         SysTryReturn(NID_UI_CTRL, (index >= 0 && index < __pSubItems->GetCount()), E_SYSTEM, E_SYSTEM,
256                         "[E_SYSTEM] A system error has occurred. The specified index (%d) is greater than the available items count.", index);
257
258         return __pSubItems->RemoveAt(index, true);
259 }
260
261 bool
262 _OptionMenuItem::HasSubItem(void) const
263 {
264         return (__pSubItems != null && __pSubItems->GetCount() > 0);
265 }
266
267 int
268 _OptionMenuItem::GetSubItemCount(void) const
269 {
270         if (__pSubItems == null)
271         {
272                         return 0;
273         }
274
275         return __pSubItems->GetCount();
276 }
277
278 _OptionMenuItem*
279 _OptionMenuItem::GetSubItem(int index)
280 {
281         SysTryReturn(NID_UI_CTRL, (__pSubItems != null), null, E_SYSTEM,
282                         "[E_SYSTEM] A system error has occurred. The sub items list is null.", index);
283         SysTryReturn(NID_UI_CTRL, (index >= 0 && index < __pSubItems->GetCount()), null, E_SYSTEM,
284                         "[E_SYSTEM] A system error has occurred. The specified index (%d) is greater than the available items count.", index);
285
286         return static_cast<_OptionMenuItem*>(__pSubItems->GetAt(index));
287 }
288
289 void
290 _OptionMenuItem::InitializeAccessibilityElement(void)
291 {
292         _AccessibilityContainer* pContainer = GetAccessibilityContainer();
293         if (pContainer)
294         {
295                 pContainer->Activate(true);
296                 _AccessibilityElement* pElement = new (std::nothrow) _AccessibilityElement(true);
297                 SysTryReturnVoidResult(NID_UI_CTRL, pElement, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
298
299                 pElement->SetTrait(L"Optionual popup");
300                 pElement->SetBounds(FloatRectangle(0.0f, 0.0f, GetBoundsF().width, GetBoundsF().height));
301                 pContainer->AddElement(*pElement);
302         }
303
304         return;
305 }
306
307 void
308 _OptionMenuItem::SetBitmapLabel(_Label* pLabel)
309 {
310         __pBitmapLabel = pLabel;
311 }
312
313 void
314 _OptionMenuItem::SetTextLabel(_Label* pLabel)
315 {
316         __pTextLabel = pLabel;
317 }
318
319 _Label*
320 _OptionMenuItem::GetBitmapLabel(void) const
321 {
322         if (__pBitmapLabel == null)
323         {
324                 return null;
325         }
326
327         return const_cast<_Label*>(__pBitmapLabel);
328 }
329
330 _Label*
331 _OptionMenuItem::GetTextLabel(void) const
332 {
333         if (__pTextLabel == null)
334         {
335                 return null;
336         }
337
338         return const_cast<_Label*>(__pTextLabel);
339 }
340
341 void
342 _OptionMenuItem::SetType(OptionMenuItemDrawingType type)
343 {
344         __type = type;
345 }
346
347 OptionMenuItemDrawingType
348 _OptionMenuItem::GetType(void) const
349 {
350         return __type;
351 }
352
353 void
354 _OptionMenuItem::SetActionId(int actionId)
355 {
356         __actionId = actionId;
357 }
358
359 int
360 _OptionMenuItem::GetActionId(void) const
361 {
362         return __actionId;
363 }
364
365 void
366 _OptionMenuItem::SetUpperDivider(bool drawDivider)
367 {
368         __upperDividerLine = drawDivider;
369 }
370
371 void
372 _OptionMenuItem::SetLowerDivider(bool drawDivider)
373 {
374         __lowerDividerLine = drawDivider;
375 }
376
377 bool
378 _OptionMenuItem::HasUpperDivider(void) const
379 {
380         return __upperDividerLine;
381 }
382
383 bool
384 _OptionMenuItem::HasLowerDivider(void) const
385 {
386         return __lowerDividerLine;
387 }
388
389 void
390 _OptionMenuItem::SetTextSize(float size)
391 {
392         __textSize = size;
393 }
394
395 result
396 _OptionMenuItem::SetText(const String& text)
397 {
398         __text = text;
399
400         return E_SUCCESS;
401 }
402
403 const String&
404 _OptionMenuItem::GetText(void) const
405 {
406         return __text;
407 }
408
409 result
410 _OptionMenuItem::SetBitmap(OptionMenuItemDrawingStatus status, const Bitmap* pBitmap)
411 {
412         if (status < OPTION_MENU_ITEM_DRAWING_STATUS_NORMAL || status > OPTION_MENU_ITEM_DRAWING_STATUS_HIGHLIGHTED)
413         {
414                 return E_INVALID_ARG;
415         }
416
417         SysTryReturn(NID_UI_CTRL, (status != OPTION_MENU_ITEM_DRAWING_STATUS_NORMAL || pBitmap != null), E_INVALID_ARG,
418                         E_INVALID_ARG, "[E_INVALID_ARG] The normal bitmap must not be null.");
419
420         Bitmap* pClonedBitmap = _BitmapImpl::CloneN(*pBitmap);
421
422         // If bitmap is in _OptionMenuItem, delete old one.
423         if (__pBitmap[status] != null)
424         {
425                 delete __pBitmap[status];
426                 __pBitmap[status] = null;
427         }
428
429         __pBitmap[status] = pClonedBitmap;
430
431         return E_SUCCESS;
432 }
433
434 const Bitmap*
435 _OptionMenuItem::GetBitmap(OptionMenuItemDrawingStatus status) const
436 {
437         if (status < OPTION_MENU_ITEM_DRAWING_STATUS_NORMAL || status > OPTION_MENU_ITEM_DRAWING_STATUS_HIGHLIGHTED)
438         {
439                 return null;
440         }
441
442         return __pBitmap[status];
443 }
444
445 void
446 _OptionMenuItem::SetSize(Tizen::Graphics::FloatDimension size)
447 {
448         __size = size;
449 }
450
451 Tizen::Graphics::FloatDimension
452 _OptionMenuItem::GetSize(void) const
453 {
454         return __size;
455 }
456
457 void
458 _OptionMenuItem::SetDrawRect(Tizen::Graphics::FloatRectangle rect)
459 {
460         __drawRect = rect;
461 }
462
463 FloatRectangle
464 _OptionMenuItem::GetDrawRect(void) const
465 {
466         return __drawRect;
467 }
468
469 void
470 _OptionMenuItem::SetPressedDrawRect(Tizen::Graphics::FloatRectangle rect)
471 {
472         __pressedDrawRect = rect;
473 }
474
475 FloatRectangle
476 _OptionMenuItem::GetPressedDrawRect(void) const
477 {
478         return __pressedDrawRect;
479 }
480
481 int
482 _OptionMenuItem::Release(void)
483 {
484         delete this;
485
486         return 0;
487 }
488
489 void
490 _OptionMenuItem::OnBoundsChanged(void)
491 {
492         _AccessibilityContainer* pContainer = GetAccessibilityContainer();
493         if (pContainer)
494         {
495                 _AccessibilityElement* pElement = pContainer->GetChildElement(0);
496                 if (pElement)
497                 {
498                         pElement->SetBounds(FloatRectangle(0.0f, 0.0f, GetBoundsF().width, GetBoundsF().height));
499                 }
500         }
501 }
502
503 void
504 _OptionMenuItem::OnDraw(void)
505 {
506         DrawItem();
507 }
508
509 void
510 _OptionMenuItem::DrawItem(void)
511 {
512         if (__upperDividerLine)
513         {
514                 DrawItemUpperDivider();
515         }
516
517         if (__lowerDividerLine)
518         {
519                 DrawItemLowerDivider();
520         }
521
522         DrawItemBackground();
523         DrawItemBitmap();
524
525         if (HasSubItem() == true)
526         {
527                 DrawArrow();
528         }
529 }
530
531 void
532 _OptionMenuItem::DrawItemBitmap(void)
533 {
534         if (__selected)
535         {
536                 __pBitmapLabel->SetBackgroundBitmap(*__pBitmap[OPTION_MENU_ITEM_DRAWING_STATUS_PRESSED]);
537         }
538         else if (__highlighted)
539         {
540                 __pBitmapLabel->SetBackgroundBitmap(*__pBitmap[OPTION_MENU_ITEM_DRAWING_STATUS_HIGHLIGHTED]);
541         }
542         else
543         {
544                 __pBitmapLabel->SetBackgroundBitmap(*__pBitmap[OPTION_MENU_ITEM_DRAWING_STATUS_NORMAL]);
545         }
546
547         FloatRectangle bounds = __pTextLabel->GetBoundsF();
548         FloatRectangle itemBounds = GetBoundsF();
549
550         float bitmapWidth = (__type == OPTION_MENU_ITEM_DRAWING_TYPE_BITMAP) ? __pBitmapLabel->GetBoundsF().width : 0.0f;
551         float textLabelX = __leftMargin + bitmapWidth;
552
553         bounds.x = textLabelX;
554         bounds.width = itemBounds.width;
555
556         bounds.width = bounds.width - __textLeftMargin - __textRightMargin - bitmapWidth;
557
558         if (HasSubItem())
559         {
560                 bounds.width = bounds.width - __arrowLeftMargin - __arrowRightMargin;
561         }
562
563         __pTextLabel->SetBounds(bounds);
564         __pBitmapLabel->Invalidate();
565         __pTextLabel->Invalidate();
566 }
567
568 void
569 _OptionMenuItem::DrawArrow(void)
570 {
571         FloatRectangle bounds = GetBoundsF();
572         FloatRectangle textRect;
573         textRect.height = bounds.height - __textTopMargin - __textBottomMargin;
574         textRect.width = bounds.width - __arrowLeftMargin - __arrowRightMargin - __textLeftMargin - __textRightMargin;
575         textRect.x = bounds.x + __arrowLeftMargin + __textLeftMargin;
576         textRect.y = bounds.y + ((bounds.height - textRect.height) / 2.0f);
577
578         textRect.width -= __arrowMargin;
579
580         Color arrowColor;
581         Bitmap *pArrowBitmap = null;
582         result r = E_SUCCESS;
583         FloatRectangle arrowbounds(0.0f, 0.0f, 0.0f, 0.0f);
584
585         if (__pArrowBitmap == null)
586         {
587                 // Load Contextual Popup Arrow Bitmap
588                 r = GET_BITMAP_CONFIG_N(OPTIONMENU::CONTEXTUAL_POPUP_ARROW, BITMAP_PIXEL_FORMAT_ARGB8888, pArrowBitmap);
589                 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
590
591                 GET_COLOR_CONFIG(OPTIONMENU::CONTEXTUAL_POPUP_ARROW_NORMAL, arrowColor);
592                 __pArrowBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pArrowBitmap, Color::GetColor(COLOR_ID_MAGENTA), arrowColor);
593                 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
594
595                 delete pArrowBitmap;
596                 pArrowBitmap = null;
597         }
598
599         if (__pArrowPressedBitmap == null)
600         {
601                 // Load Contextual Popup Arrow Pressed Bitmap
602                 r = GET_BITMAP_CONFIG_N(OPTIONMENU::CONTEXTUAL_POPUP_ARROW, BITMAP_PIXEL_FORMAT_ARGB8888, pArrowBitmap);
603                 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
604
605                 GET_COLOR_CONFIG(OPTIONMENU::CONTEXTUAL_POPUP_ARROW_PRESSED, arrowColor);
606                 __pArrowPressedBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pArrowBitmap, Color::GetColor(COLOR_ID_MAGENTA), arrowColor);
607                 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
608
609                 delete pArrowBitmap;
610                 pArrowBitmap = null;
611         }
612
613         if (__pArrowLabel == null)
614         {
615                 __pArrowLabel = _Label::CreateLabelN();
616         SysTryCatch(NID_UI_CTRL, (__pArrowLabel != null), , r, "[%s] Propagating.", GetErrorMessage(r));
617
618                 AttachChild(*__pArrowLabel);
619
620                 _AccessibilityContainer* pContainer = __pArrowLabel->GetAccessibilityContainer();
621                 if (pContainer)
622                 {
623                         pContainer->Activate(false);
624                 }
625         }
626
627         arrowbounds = FloatRectangle(bounds.x + bounds.width - __arrowMargin - __rightMargin,
628                                 (__itemHeight - __pArrowBitmap->GetHeight())/2.0f, __pArrowBitmap->GetWidth(), __pArrowBitmap->GetHeight());
629         __pArrowLabel->SetBounds(FloatRectangle(arrowbounds));
630
631         if (__selected == true)
632         {
633                 __pArrowLabel->SetBackgroundBitmap(*__pArrowPressedBitmap);
634         }
635         else
636         {
637                 __pArrowLabel->SetBackgroundBitmap(*__pArrowBitmap);
638         }
639
640         __pArrowLabel->Invalidate();
641
642         return;
643
644 CATCH:
645         delete pArrowBitmap;
646
647         delete __pArrowBitmap;
648         __pArrowBitmap = null;
649
650         delete __pArrowPressedBitmap;
651         __pArrowPressedBitmap = null;
652
653         delete __pArrowLabel;
654         __pArrowLabel = null;
655 }
656
657 void
658 _OptionMenuItem::DrawItemUpperDivider(void)
659 {
660         FloatRectangle bounds(0.0f, 0.0f, 0.0f, 0.0f);
661         Color dividerLineColor(0, 0, 0, 0);
662
663         if (__pUpperDividerLineLabel == null)
664         {
665                 __pUpperDividerLineLabel = _Label::CreateLabelN();
666                 SysTryReturnVoidResult(NID_UI_CTRL, __pUpperDividerLineLabel, E_OUT_OF_MEMORY, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
667
668                 AttachChild(*__pUpperDividerLineLabel);
669
670                 _AccessibilityContainer* pContainer = __pUpperDividerLineLabel->GetAccessibilityContainer();
671                 if (pContainer)
672                 {
673                         pContainer->Activate(false);
674                 }
675         }
676
677         bounds = GetBoundsF();
678         if (__selected == false)
679         {
680                 dividerLineColor = __upperDividerLineColor;
681         }
682
683         __pUpperDividerLineLabel->SetBounds(FloatRectangle(0.0f, 0.0f, bounds.width, __dividerHeight));
684         __pUpperDividerLineLabel->SetBackgroundColor(dividerLineColor);
685         __pUpperDividerLineLabel->Invalidate();
686 }
687
688 int
689 _OptionMenuItem::GetSubItemIndexFromActionId(int actionId) const
690 {
691         if (__pSubItems == null)
692         {
693                 return -1;
694         }
695
696         int index = 0;
697         int subItemCount = __pSubItems->GetCount();
698         const _OptionMenuItem* pItem = null;
699         for (index = 0; index < subItemCount; index++)
700         {
701                 pItem = static_cast<const _OptionMenuItem*>(__pSubItems->GetAt(index));
702                 if (pItem != null)
703                 {
704                         if (pItem->__actionId == actionId)
705                         {
706                                 return index;
707                         }
708                 }
709         }
710
711         return -1;
712 }
713
714 void
715 _OptionMenuItem::DrawItemBackground(void)
716 {
717         SetBackgroundColor(Color(0, 0, 0, 0));
718
719         if (__pBackgroundLabel == null)
720         {
721                 __pBackgroundLabel = _Label::CreateLabelN();
722                 SysTryReturnVoidResult(NID_UI_CTRL, __pBackgroundLabel, E_OUT_OF_MEMORY, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
723
724                 __pBackgroundLabel->SetTouchPressThreshold(TOUCH_PRESS_THRESHOLD_INSENSITIVE);
725                 AttachChild(*__pBackgroundLabel);
726                 MoveChildToBottom(*__pBackgroundLabel);
727
728                 _AccessibilityContainer* pContainer = __pBackgroundLabel->GetAccessibilityContainer();
729                 if (pContainer)
730                 {
731                         pContainer->Activate(false);
732                 }
733         }
734
735         Color color= Color(0, 0, 0, 0);
736         if (__selected == true)
737         {
738                 color = __selectedBgColor;
739         }
740
741         FloatRectangle bounds = GetBoundsF();
742         _ScrollPanel* pScrollPanel = static_cast<_ScrollPanel*>(GetParent());
743         FloatRectangle boundsScrollPanel = pScrollPanel->GetBoundsF();
744
745         __pBackgroundLabel->SetBounds(FloatRectangle(0, 0, bounds.width, bounds.height));
746
747         Bitmap* BgBitmap = _BitmapImpl::GetColorReplacedBitmapN(*__pMagentaBgBitmap, Color::GetColor(COLOR_ID_MAGENTA), color);
748         SysTryReturnVoidResult(NID_UI_CTRL, BgBitmap, E_OUT_OF_MEMORY, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
749
750         __pBackgroundLabel->SetBackgroundBitmap(*BgBitmap);
751         delete BgBitmap;
752         BgBitmap = null;
753
754         __pBackgroundLabel->Invalidate();
755 }
756
757 void
758 _OptionMenuItem::DrawItemLowerDivider(void)
759 {
760         FloatRectangle bounds(0.0f, 0.0f, 0.0f, 0.0f);
761         Color dividerLineColor(0, 0, 0, 0);
762
763         if (__pLowerDividerLineLabel == null)
764         {
765                 __pLowerDividerLineLabel = _Label::CreateLabelN();
766                 SysTryReturnVoidResult(NID_UI_CTRL, __pLowerDividerLineLabel, E_OUT_OF_MEMORY, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
767
768                 AttachChild(*__pLowerDividerLineLabel);
769
770                 _AccessibilityContainer* pContainer = __pLowerDividerLineLabel->GetAccessibilityContainer();
771                 if (pContainer)
772                 {
773                         pContainer->Activate(false);
774                 }
775         }
776
777         bounds = GetBoundsF();
778         if (__selected == false)
779         {
780                 dividerLineColor = __lowerDividerLineColor;
781         }
782
783         __pLowerDividerLineLabel->SetBounds(FloatRectangle(0.0f, bounds.height - __dividerHeight, bounds.width, __dividerHeight));
784         __pLowerDividerLineLabel->SetBackgroundColor(dividerLineColor);
785         __pLowerDividerLineLabel->Invalidate();
786 }
787
788 _UiTouchEventDelivery
789 _OptionMenuItem::OnPreviewTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
790 {
791         SetAndInvalidate(true);
792
793         return _UI_TOUCH_EVENT_DELIVERY_FORCED_YES;
794 }
795
796 bool
797 _OptionMenuItem::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
798 {
799         SetAndInvalidate(true);
800
801         return false;
802 }
803
804 _UiTouchEventDelivery
805 _OptionMenuItem::OnPreviewTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
806 {
807         TouchMoved(source, touchinfo);
808
809         return _UI_TOUCH_EVENT_DELIVERY_FORCED_YES;
810 }
811
812 bool
813 _OptionMenuItem::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
814 {
815         TouchMoved(source, touchinfo);
816
817         return false;
818 }
819
820 _UiTouchEventDelivery
821 _OptionMenuItem::OnPreviewTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
822 {
823         SetAndInvalidate(false);
824
825         return _UI_TOUCH_EVENT_DELIVERY_FORCED_YES;
826 }
827
828 bool
829 _OptionMenuItem::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
830 {
831         SetAndInvalidate(false);
832
833         return false;
834 }
835
836
837 void
838 _OptionMenuItem::TouchMoved(const _Control& source, const _TouchInfo& touchinfo)
839 {
840         FloatPoint touchPosition = touchinfo.GetCurrentPosition();
841
842         if (__pressed)
843         {
844                 if (__parentScrollEnable)
845                 {
846                         if (__selected)
847                         {
848                                 __selected = false;
849                                 Invalidate();
850                         }
851                 }
852                 else
853                 {
854                         int oldSelected = __selected;
855
856                         FloatRectangle bounds(0.0f, 0.0f, __size.width, __size.height);
857                         if (bounds.Contains(touchPosition))
858                         {
859                                 __selected = true;
860                         }
861                         else
862                         {
863                                 __selected = false;
864                         }
865
866                         if (oldSelected != __selected)
867                         {
868                                 Invalidate();
869                         }
870                 }
871         }
872 }
873
874 void
875 _OptionMenuItem::OnFontChanged(Tizen::Graphics::Font* pFont)
876 {
877         String fontName = _Control::GetFont();
878
879         if (__pTextLabel != null)
880         {
881                 __pTextLabel->SetFont(fontName);
882         }
883 }
884
885 void
886 _OptionMenuItem::OnFontInfoRequested(unsigned long& style, float& size)
887 {
888         style = FONT_STYLE_PLAIN;
889         size = __textSize;
890 }
891
892 void
893 _OptionMenuItem::SetParentScrollEnable(bool enable)
894 {
895         __parentScrollEnable = enable;
896 }
897
898 bool
899 _OptionMenuItem::GetParentScrollEnable(void) const
900 {
901         return __parentScrollEnable;
902 }
903
904 bool
905 _OptionMenuItem::IsSelected(void) const
906 {
907         return __selected;
908 }
909
910 bool
911 _OptionMenuItem::IsHighlighted(void) const
912 {
913         return __highlighted;
914 }
915
916 void
917 _OptionMenuItem::SetHighlighted(bool status)
918 {
919         __highlighted = status;
920 }
921
922 void
923 _OptionMenuItem::SetAndInvalidate(bool flag)
924 {
925         __selected = flag;
926         __pressed = flag;
927         Invalidate();
928 }
929
930 const Tizen::Graphics::Bitmap*
931 _OptionMenuItem::GetMagentaBgBitmap(void) const
932 {
933         return __pMagentaBgBitmap;
934 }
935
936 }}} // Tizen::Ui::Controls