Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / controls / FUiCtrl_CustomListElements.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://floralicense.org/license/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19 * @file         FUiCtrl_CustomListElements.cpp
20 * @brief        This is the header file for the classes related to implementing elements in CustomListItem.
21 */
22
23 #include <FBaseSysLog.h>
24 #include <FGrp_BitmapImpl.h>
25 #include <FGrp_TextTextObject.h>
26 #include <FGrp_TextTextSimple.h>
27 #include "FUiCtrl_CustomListItemImpl.h"
28 #include "FUiCtrl_CustomListItemFormatImpl.h"
29 #include "FUiCtrl_PanelImpl.h"
30 #include "FUi_ResourceManager.h"
31
32 using namespace Tizen::Base;
33 using namespace Tizen::Base::Collection;
34 using namespace Tizen::Graphics;
35 using namespace Tizen::Graphics::_Text;
36
37 namespace Tizen { namespace Ui { namespace Controls
38 {
39
40 _ElementBaseModel::_ElementBaseModel(void)
41         : _elementId(-1)
42         , _itemStatus(CUSTOM_LIST_ITEM_STATUS_NORMAL)
43 {
44 }
45
46 _ElementBaseModel::~_ElementBaseModel(void)
47 {
48 }
49
50 int
51 _ElementBaseModel::GetElementId(void)
52 {
53         return _elementId;
54 }
55
56 CustomListItemStatus
57 _ElementBaseModel::GetItemStatus(void)
58 {
59         return _itemStatus;
60 }
61
62 void
63 _ElementBaseModel::HandleElementEvent(CustomListItemStatus itemStatus)
64 {
65         _itemStatus = itemStatus;
66 }
67
68 _TextElementModel::_TextElementModel(const String& text)
69         : __text(text)
70         , __textSize(0)
71         , __slidingEnabled(false)
72 {
73 }
74
75 _TextElementModel::~_TextElementModel(void)
76 {
77 }
78
79 void
80 _TextElementModel::SetTextSliding(bool enable)
81 {
82         __slidingEnabled = enable;
83 }
84
85 bool
86 _TextElementModel::GetTextSliding(void)
87 {
88         return __slidingEnabled;
89 }
90
91 void
92 _TextElementModel::GetData(String& text, Color& textColor, int& textSize) const
93 {
94         text = __text;
95         textColor = __textColor[_itemStatus];
96         textSize = __textSize;
97
98         return;
99 }
100
101 int
102 _TextElementModel::GetTextSize(void) const
103 {
104         return __textSize;
105 }
106
107 result
108 _TextElementModel::CreateElementView(_ElementViewParams& elementParams)
109 {
110         _TextElementModel* pTextElementModel = dynamic_cast<_TextElementModel*>(elementParams.pElementModel);
111         SysTryReturn(NID_UI_CTRL, (pTextElementModel != null), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get element model");
112
113         SysTryReturn(NID_UI_CTRL, (elementParams.pElementFormatData != null), E_SYSTEM, E_SYSTEM, "[E_INVALID_ARG] Invalid argument is used. pElementFormatData must not be null");
114         SysTryReturn(NID_UI_CTRL, (elementParams.pTableViewItemBase != null), E_SYSTEM, E_SYSTEM, "[E_INVALID_ARG] Invalid argument is used. pTableViewItemBase must not be null");
115         SysTryReturn(NID_UI_CTRL, (elementParams.pCustomListItemImpl != null), E_SYSTEM, E_SYSTEM, "[E_INVALID_ARG] Invalid argument is used. pCustomListItemImpl must not be null");
116
117         pTextElementModel->__textSize = elementParams.pElementFormatData->textSize;
118         pTextElementModel->__textColor[CUSTOM_LIST_ITEM_STATUS_NORMAL] = elementParams.pElementFormatData->normalTextColor;
119         pTextElementModel->__textColor[CUSTOM_LIST_ITEM_STATUS_FOCUSED] = elementParams.pElementFormatData->focusedTextColor;
120         pTextElementModel->__textColor[CUSTOM_LIST_ITEM_STATUS_SELECTED] = elementParams.pElementFormatData->highlightedTextColor;
121
122         TextObject* pText = new (std::nothrow) TextObject();
123         SysTryReturn(NID_UI_CTRL, pText, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
124
125         pText->Construct();
126
127         TextSimple* pSimpleText = new (std::nothrow) TextSimple(const_cast <wchar_t*>(pTextElementModel->__text.GetPointer()), pTextElementModel->__text.GetLength());
128         SysTryReturn(NID_UI_CTRL, pSimpleText, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
129
130         pText->AppendElement(*pSimpleText);
131
132         pText->SetAction(TEXT_OBJECT_ACTION_TYPE_NONE);
133         pText->SetAlignment(TEXT_OBJECT_ALIGNMENT_LEFT | TEXT_OBJECT_ALIGNMENT_MIDDLE);
134         pText->SetWrap(TEXT_OBJECT_WRAP_TYPE_NONE);
135         pText->Compose();
136
137         _TextElementView* pTextElementView = new (std::nothrow) _TextElementView(pText);
138         SysTryReturn(NID_UI_CTRL, (pTextElementView != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
139
140         pTextElementView->Construct(elementParams.pElementFormatData->rect);
141         pTextElementView->AddTouchEventListener(*elementParams.pCustomListItemImpl);
142         elementParams.pTableViewItemBase->AddControl(*pTextElementView);
143         pTextElementView->SetModel(pTextElementModel);
144         elementParams.pTableViewItemBase->SetIndividualSelectionEnabled(pTextElementView, true);
145
146         return E_SUCCESS;
147 }
148
149 _BitmapElementModel::_BitmapElementModel(void)
150 {
151         for (int i = 0; i <= CUSTOM_LIST_ITEM_STATUS_FOCUSED; i++)
152         {
153                 __pBitmap[i] = null;
154         }
155 }
156
157 _BitmapElementModel::~_BitmapElementModel(void)
158 {
159         for (int i = 0; i <= CUSTOM_LIST_ITEM_STATUS_FOCUSED; i++)
160         {
161                 delete __pBitmap[i];
162         }
163 }
164
165 Bitmap*
166 _BitmapElementModel::GetData(void) const
167 {
168         return __pBitmap[_itemStatus];
169 }
170
171 result
172 _BitmapElementModel::CreateElementView(_ElementViewParams& elementParams)
173 {
174         _BitmapElementModel* pBitmapElementModel = dynamic_cast<_BitmapElementModel*>(elementParams.pElementModel);
175         SysTryReturn(NID_UI_CTRL, (pBitmapElementModel != null), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get element model");
176
177         SysTryReturn(NID_UI_CTRL, (elementParams.pElementFormatData != null), E_SYSTEM, E_SYSTEM, "[E_INVALID_ARG] Invalid argument is used. pElementFormatData must not be null");
178         SysTryReturn(NID_UI_CTRL, (elementParams.pCustomListItemImpl != null), E_SYSTEM, E_SYSTEM, "[E_INVALID_ARG] Invalid argument is used. pCustomListItemImpl must not be null");
179         SysTryReturn(NID_UI_CTRL, (elementParams.pTableViewItemBase != null), E_SYSTEM, E_SYSTEM, "[E_INVALID_ARG] Invalid argument is used. pTableViewItemBase must not be null");
180
181         _BitmapElementView* pBitmapElementView = new (std::nothrow) _BitmapElementView();
182         SysTryReturn(NID_UI_CTRL, (pBitmapElementView != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
183
184         pBitmapElementView->Construct(elementParams.pElementFormatData->rect);
185         pBitmapElementView->AddTouchEventListener(*elementParams.pCustomListItemImpl);
186         elementParams.pTableViewItemBase->AddControl(*pBitmapElementView);
187         pBitmapElementView->SetModel(pBitmapElementModel);
188         elementParams.pTableViewItemBase->SetIndividualSelectionEnabled(pBitmapElementView, true);
189
190         return E_SUCCESS;
191 }
192
193 _CustomElementModel::_CustomElementModel(void)
194         : __pListElement(null)
195 {
196 }
197
198 _CustomElementModel::~_CustomElementModel(void)
199 {
200 }
201
202 ICustomListElement*
203 _CustomElementModel::GetData(void) const
204 {
205         return __pListElement;
206 }
207
208 result
209 _CustomElementModel::CreateElementView(_ElementViewParams& elementParams)
210 {
211         _CustomElementModel* pCustomElementModel = dynamic_cast<_CustomElementModel*>(elementParams.pElementModel);
212         SysTryReturn(NID_UI_CTRL, (pCustomElementModel != null), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get element model");
213
214         SysTryReturn(NID_UI_CTRL, (elementParams.pElementFormatData != null), E_SYSTEM, E_SYSTEM, "[E_INVALID_ARG] Invalid argument is used. pElementFormatData must not be null");
215         SysTryReturn(NID_UI_CTRL, (elementParams.pCustomListItemImpl != null), E_SYSTEM, E_SYSTEM, "[E_INVALID_ARG] Invalid argument is used. pCustomListItemImpl must not be null");
216         SysTryReturn(NID_UI_CTRL, (elementParams.pTableViewItemBase != null), E_SYSTEM, E_SYSTEM, "[E_INVALID_ARG] Invalid argument is used. pTableViewItemBase must not be null");
217
218         _CustomElementView* pCustomElementView = new (std::nothrow) _CustomElementView();
219         SysTryReturn(NID_UI_CTRL, (pCustomElementView != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
220
221         pCustomElementView->Construct(elementParams.pElementFormatData->rect);
222         pCustomElementView->AddTouchEventListener(*elementParams.pCustomListItemImpl);
223         elementParams.pTableViewItemBase->AddControl(*pCustomElementView);
224         pCustomElementView->SetModel(pCustomElementModel);
225         elementParams.pTableViewItemBase->SetIndividualSelectionEnabled(pCustomElementView, true);
226
227         return E_SUCCESS;
228 }
229
230 _CheckElementModel::_CheckElementModel(void)
231         : __checkBoxStatus(CHECK_BOX_UNCHECKED)
232         , __pCheckBitmaps(null)
233         , __isDividerEnabled(false)
234         , __rightDivider(false)
235         , __leftDivider(false)
236 {
237 }
238
239 _CheckElementModel::~_CheckElementModel(void)
240 {
241 }
242
243 void
244 _CheckElementModel::SetCheckBoxStatus(_CheckBoxBitmapType checkBoxStatus)
245 {
246         __checkBoxStatus = checkBoxStatus;
247 }
248
249 _CheckBoxBitmapType
250 _CheckElementModel::GetCheckBoxStatus(void)
251 {
252         return __checkBoxStatus;
253 }
254
255 const _CheckBoxBitmapType
256 _CheckElementModel::GetCheckBoxStatus(void) const
257 {
258         return __checkBoxStatus;
259 }
260
261 void
262 _CheckElementModel::GetData(Rectangle& bitmapBounds, bool& isDividerEnabled, bool& leftDivider, bool& rightDivider) const
263 {
264         bitmapBounds = __bitmapBounds;
265         isDividerEnabled = __isDividerEnabled;
266         leftDivider = __leftDivider;
267         rightDivider = __rightDivider;
268
269         return;
270 }
271
272 Bitmap*
273 _CheckElementModel::GetCheckBitmap(void) const
274 {
275         return __pCheckBitmaps[__checkBoxStatus];
276 }
277
278 result
279 _CheckElementModel::CreateElementView(_ElementViewParams& elementParams)
280 {
281         SysTryReturn(NID_UI_CTRL, (elementParams.pElementFormatData != null), E_SYSTEM, E_SYSTEM, "[E_INVALID_ARG] Invalid argument is used. pElementFormatData must not be null");
282         SysTryReturn(NID_UI_CTRL, (elementParams.pCustomListItemImpl != null), E_SYSTEM, E_SYSTEM, "[E_INVALID_ARG] Invalid argument is used. pCustomListItemImpl must not be null");
283         SysTryReturn(NID_UI_CTRL, (elementParams.pTableViewItemBase != null), E_SYSTEM, E_SYSTEM, "[E_INVALID_ARG] Invalid argument is used. pTableViewItemBase must not be null");
284
285         if (elementParams.annexStyle != TABLE_VIEW_ANNEX_STYLE_NORMAL)
286         {
287                 Rectangle checkBoxBounds(elementParams.pElementFormatData->rect);
288                 int dividerMargin = 0;
289
290                 GET_SHAPE_CONFIG(LIST::CHECK_ELEMENT_DIVIDER_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, dividerMargin);
291
292                 if (elementParams.isDividerEnabled)
293                 {
294                         checkBoxBounds.width += 2 * dividerMargin;
295                         checkBoxBounds.y = 0;
296                         checkBoxBounds.height = elementParams.pCustomListItemImpl->height;
297                 }
298
299                 _CheckElementModel* pCheckElementModel = dynamic_cast<_CheckElementModel*>(elementParams.pElementModel);
300                 SysTryReturn(NID_UI_CTRL, (pCheckElementModel != null), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get element model");
301
302                 pCheckElementModel->__pCheckBitmaps = elementParams.pCheckBitmaps;
303                 pCheckElementModel->__isDividerEnabled = elementParams.isDividerEnabled;
304
305                 pCheckElementModel->__bitmapBounds.width = elementParams.pElementFormatData->rect.width;
306                 pCheckElementModel->__bitmapBounds.height = elementParams.pElementFormatData->rect.height;
307
308                 if (elementParams.isDividerEnabled)
309                 {
310                         pCheckElementModel->__bitmapBounds.x = ((checkBoxBounds.x + dividerMargin) > elementParams.pElementFormatData->rect.x) ? (dividerMargin) : (0);
311                         pCheckElementModel->__bitmapBounds.y = elementParams.pElementFormatData->rect.y;
312
313                         _CustomListItemImpl::SetDividerRequired(*elementParams.pElementFormat, elementParams.pElementFormatData->rect, pCheckElementModel->__leftDivider, pCheckElementModel->__rightDivider);
314                 }
315                 else
316                 {
317                         pCheckElementModel->__bitmapBounds.x = 0;
318                         pCheckElementModel->__bitmapBounds.y = 0;
319                 }
320
321                 _CheckElementView* pCheckElementView = new (std::nothrow) _CheckElementView();
322                 SysTryReturn(NID_UI_CTRL, (pCheckElementView != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
323
324                 pCheckElementView->Construct(checkBoxBounds);
325                 pCheckElementView->AddTouchEventListener(*elementParams.pCustomListItemImpl);
326                 elementParams.pTableViewItemBase->AddControl(*pCheckElementView);
327                 pCheckElementView->SetModel(pCheckElementModel);
328                 elementParams.pTableViewItemBase->SetIndividualSelectionEnabled(pCheckElementView, true);
329         }
330
331         return E_SUCCESS;
332 }
333
334 _ElementBaseView::_ElementBaseView(void)
335         : __pElementBaseModel(null)
336 {
337 }
338
339 _ElementBaseView::~_ElementBaseView(void)
340 {
341 }
342
343 int
344 _ElementBaseView::GetElementId(void) const
345 {
346         SysTryReturn(NID_UI_CTRL, (__pElementBaseModel != null), -1, E_SYSTEM, "Element model not set");
347
348         return __pElementBaseModel->GetElementId();
349 }
350
351 _TextElementView::_TextElementView(TextObject* pText)
352         : __pText(pText)
353 {
354 }
355
356 _TextElementView::~_TextElementView(void)
357 {
358         __pText->RemoveAll();
359
360         delete __pText;
361         __pText = null;
362
363 }
364
365 result
366 _TextElementView::OnDraw(void)
367 {
368         result r = E_SUCCESS;
369
370         _TextElementModel* __pTextElementModel = dynamic_cast<_TextElementModel*>(__pElementBaseModel);
371         SysTryReturn(NID_UI_CTRL, (__pTextElementModel), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error occured. Failed to get _TextElementModel.");
372
373         Canvas* pCanvas = GetCanvasN();
374         r  = GetLastResult();
375         SysTryReturn(NID_UI_CTRL, (pCanvas), r, r, "[%s] Propagating.", GetErrorMessage(r));
376
377         String text;
378         Color textColor;
379         int textSize = 0;
380
381         __pTextElementModel->GetData(text, textColor, textSize);
382
383         if (IsEnabled() == false)
384         {
385                 GET_COLOR_CONFIG(LIST::LIST_ELEMENT_TEXT_DISABLED_COLOR, textColor);
386         }
387
388         pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
389         pCanvas->Clear();
390
391         if (__pText)
392         {
393                 Rectangle bounds = GetBounds();
394                 bounds.x = 0;
395                 bounds.y = 0;
396
397                 _ListBaseImpl* pListBaseImpl = _CustomListItemImpl::GetListBaseImplFromElement(*this);
398                 SysTryCatch(NID_UI_CTRL, (pListBaseImpl != null), , E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get _ListBaseImpl instance.");
399
400                 Font font;
401                 r = font.Construct(pListBaseImpl->GetCore().GetFont(), FONT_STYLE_PLAIN, textSize);
402                 if (r != E_SUCCESS)
403                 {
404                         font.Construct(FONT_STYLE_PLAIN, textSize);
405                 }
406
407                 __pText->SetFont(&font, 0, __pText->GetTextLength());
408                 __pText->SetForegroundColor(textColor, 0, __pText->GetTextLength());
409                 __pText->SetBounds(bounds);
410                 __pText->Draw(*_CanvasImpl::GetInstance(*pCanvas));
411         }
412
413         delete pCanvas;
414         return E_SUCCESS;
415
416 CATCH:
417         delete pCanvas;
418         return E_SYSTEM;
419 }
420
421 void
422 _TextElementView::SetModel(_TextElementModel* pTextElementModel)
423 {
424         __pElementBaseModel = pTextElementModel;
425 }
426
427 void
428 _TextElementView::StartTextSlide(void)
429 {
430         if (IsEnabled() == false)
431         {
432                 return;
433         }
434
435         Canvas* pCanvas = GetCanvasN();
436         SysTryReturnVoidResult(NID_UI_CTRL, (pCanvas != null), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
437
438         pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
439         pCanvas->Clear();
440
441         if (__pText->GetTextLengthAt(0) < __pText->GetTextLength())
442         {
443                 __pText->SetAction(TEXT_OBJECT_ACTION_TYPE_SLIDE_LEFT);
444                 __pText->Compose();
445                 __pText->DrawWithOffset(*_CanvasImpl::GetInstance(*pCanvas));
446         }
447         else
448         {
449                 __pText->Draw(*_CanvasImpl::GetInstance(*pCanvas));
450         }
451
452         delete pCanvas;
453 }
454
455 void
456 _TextElementView::StopTextSlide(void)
457 {
458         if (IsEnabled() == false)
459         {
460                 return;
461         }
462
463         Canvas* pCanvas = GetCanvasN();
464         SysTryReturnVoidResult(NID_UI_CTRL, (pCanvas != null), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
465
466         pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
467         pCanvas->Clear();
468
469         __pText->SetAction(TEXT_OBJECT_ACTION_TYPE_NONE);
470         __pText->SetAlignment(TEXT_OBJECT_ALIGNMENT_LEFT | TEXT_OBJECT_ALIGNMENT_MIDDLE);
471         __pText->SetWrap(TEXT_OBJECT_WRAP_TYPE_NONE);
472         __pText->Compose();
473         __pText->DrawWithOffset(*_CanvasImpl::GetInstance(*pCanvas));
474
475         delete pCanvas;
476 }
477
478 _BitmapElementView::_BitmapElementView(void)
479 {
480 }
481
482 _BitmapElementView::~_BitmapElementView(void)
483 {
484 }
485
486 result
487 _BitmapElementView::OnDraw(void)
488 {
489         result r = E_SUCCESS;
490         Canvas* pCanvas = GetCanvasN();
491
492         r  = GetLastResult();
493         SysTryReturn(NID_UI_CTRL, (pCanvas), r, r, "[%s] Propagating.", GetErrorMessage(r));
494
495         _BitmapElementModel* __pBitmapElementModel = dynamic_cast<_BitmapElementModel*>(__pElementBaseModel);
496         SysTryReturn(NID_UI_CTRL, (__pBitmapElementModel), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occured. Failed to get _BitmapElementModel.");
497
498         Bitmap *pBitmap = __pBitmapElementModel->GetData();
499
500         if (pBitmap)
501         {
502                 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
503                 pCanvas->Clear();
504
505                 if (pBitmap->IsNinePatchedBitmap())
506                 {
507                         pCanvas->DrawNinePatchedBitmap(Rectangle(0, 0, GetWidth(), GetHeight()), *pBitmap);
508                 }
509                 else
510                 {
511                         pCanvas->DrawBitmap(Rectangle(0, 0, GetWidth(), GetHeight()), *pBitmap);
512                 }
513         }
514
515         delete pCanvas;
516
517         return E_SUCCESS;
518 }
519
520 void
521 _BitmapElementView::SetModel(_BitmapElementModel* pBitmapElementModel)
522 {
523         __pElementBaseModel = static_cast<_ElementBaseModel*>(pBitmapElementModel);
524 }
525
526 _CustomElementView::_CustomElementView(void)
527 {
528 }
529
530 _CustomElementView::~_CustomElementView(void)
531 {
532 }
533
534 result
535 _CustomElementView::OnDraw(void)
536 {
537         result r = E_SUCCESS;
538         Canvas* pCanvas = GetCanvasN();
539
540         CustomListItemStatus itemStatus;
541         ICustomListElement* pListElement;
542
543         r  = GetLastResult();
544         SysTryReturn(NID_UI_CTRL, (pCanvas), r, r, "[%s] Propagating.", GetErrorMessage(r));
545
546         _CustomElementModel* __pCustomElementModel = dynamic_cast<_CustomElementModel*>(__pElementBaseModel);
547         SysTryCatch(NID_UI_CTRL, (__pCustomElementModel), , E_SYSTEM, "[E_SYSTEM] A system error has occured. Failed to get _CustomElementModel.");
548
549         itemStatus = __pCustomElementModel->GetItemStatus();
550         pListElement = __pCustomElementModel->GetData();
551
552         if (pListElement)
553         {
554                 TableViewItemBase* pParentItem = dynamic_cast<TableViewItemBase*>(GetParent());
555                 SysTryCatch(NID_UI_CTRL, pParentItem, , E_SYSTEM, "[E_SYSTEM] Failed to get parent item");
556
557                 Color bgColor = pParentItem->GetBackgroundColor(TABLE_VIEW_ITEM_DRAWING_STATUS_NORMAL);
558
559                 pCanvas->SetBackgroundColor(bgColor);
560                 pCanvas->Clear();
561                 pListElement->DrawElement(*pCanvas, Rectangle(0, 0, GetWidth(), GetHeight()), itemStatus);
562         }
563
564         delete pCanvas;
565         return E_SUCCESS;
566
567 CATCH:
568         delete pCanvas;
569         return E_SYSTEM;
570
571 }
572
573 void
574 _CustomElementView::SetModel(_CustomElementModel* pCustomElementModel)
575 {
576         __pElementBaseModel = static_cast<_ElementBaseModel*>(pCustomElementModel);
577 }
578
579 _CheckElementView::_CheckElementView(void)
580         : __pressedState(false)
581 {
582         GET_COLOR_CONFIG(LIST::LISTITEM_DIVIDER_LEFT_HALF_COLOR, __leftHalfDividerColor);
583         GET_COLOR_CONFIG(LIST::LISTITEM_DIVIDER_RIGHT_HALF_COLOR, __rightHalfDividerColor);
584 }
585
586 _CheckElementView::~_CheckElementView(void)
587 {
588 }
589
590 result
591 _CheckElementView::OnDraw(void)
592 {
593         result r = E_SUCCESS;
594         Canvas* pCanvas = GetCanvasN();
595
596         r  = GetLastResult();
597         SysTryReturn(NID_UI_CTRL, (pCanvas), r, r, "[%s] Propagating.", GetErrorMessage(r));
598
599         Rectangle bitmapBounds;
600         bool isDividerEnabled = false;
601         bool leftDivider = false;
602         bool rightDivider = false;
603         Bitmap* pCheckBitmap = null;
604
605         _CheckElementModel* __pCheckElementModel = dynamic_cast<_CheckElementModel*>(__pElementBaseModel);
606         SysTryCatch(NID_UI_CTRL, (__pCheckElementModel), , E_SYSTEM, "[E_SYSTEM] A system error has occured. Failed to get _CheckElementModel.");
607
608         __pCheckElementModel->GetData(bitmapBounds, isDividerEnabled, leftDivider, rightDivider);
609
610         if (isDividerEnabled)
611         {
612                 _ListBaseImpl* pListBaseImpl = _CustomListItemImpl::GetListBaseImplFromElement(*this);
613
614                 if (pListBaseImpl)
615                 {
616                         Color bgColor;
617
618                         if (__pressedState == true)
619                         {
620                                 GET_COLOR_CONFIG(TABLEVIEW::ITEM_BG_PRESSED, bgColor);
621                         }
622                         else
623                         {
624                                 bgColor = pListBaseImpl->GetBackgroundColor();
625                                 Color defaultColor(0, 0, 0, 0);
626                                 _ContainerImpl* pParent = null;
627
628                                 while (bgColor == defaultColor)
629                                 {
630                                         pParent = pListBaseImpl->GetParent();
631
632                                         if (pParent)
633                                         {
634                                                 bgColor = pParent->GetBackgroundColor();
635                                         }
636                                         else
637                                         {
638                                                 break;
639                                         }
640                                 }
641                         }
642
643                         pCanvas->SetBackgroundColor(bgColor);
644                 }
645         }
646         else
647         {
648                 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
649         }
650
651         pCheckBitmap = __pCheckElementModel->GetCheckBitmap();
652
653         pCanvas->Clear();
654         pCanvas->DrawBitmap(bitmapBounds, *pCheckBitmap);
655
656         if (isDividerEnabled)
657         {
658                 int lineWidth = 0;
659
660                 GET_SHAPE_CONFIG(LIST::CHECK_ELEMENT_DIVIDER_WIDTH, _CONTROL_ORIENTATION_PORTRAIT, lineWidth);
661
662                 Rectangle bounds = GetBounds();
663                 int dividerHeight = 0;
664
665                 dividerHeight = bounds.height / 2;
666                 bounds.y = bounds.y + ((bounds.height - dividerHeight) / 2);
667
668                 if (leftDivider)
669                 {
670                         pCanvas->SetLineWidth(lineWidth / 2);
671                         pCanvas->SetForegroundColor(__leftHalfDividerColor);
672                         pCanvas->DrawLine(Point(0, bounds.y), Point(0, dividerHeight + bounds.y));
673
674                         pCanvas->SetLineWidth(lineWidth / 2);
675                         pCanvas->SetForegroundColor(__rightHalfDividerColor);
676                         pCanvas->DrawLine(Point(1, bounds.y), Point(1, dividerHeight + bounds.y));
677                 }
678
679                 if (rightDivider)
680                 {
681                         pCanvas->SetLineWidth(lineWidth / 2);
682                         pCanvas->SetForegroundColor(__leftHalfDividerColor);
683                         pCanvas->DrawLine(Point(bounds.width - lineWidth, bounds.y), Point(bounds.width - lineWidth, dividerHeight + bounds.y));
684
685                         pCanvas->SetLineWidth(lineWidth / 2);
686                         pCanvas->SetForegroundColor(__rightHalfDividerColor);
687                         pCanvas->DrawLine(Point(bounds.width - lineWidth + 1, bounds.y), Point(bounds.width - lineWidth + 1, dividerHeight + bounds.y));
688                 }
689         }
690
691         delete pCanvas;
692         return E_SUCCESS;
693
694 CATCH:
695         delete pCanvas;
696         return E_SYSTEM;
697 }
698
699 void
700 _CheckElementView::SetModel(_CheckElementModel* pCheckElementModel)
701 {
702         __pElementBaseModel = static_cast<_ElementBaseModel*>(pCheckElementModel);
703 }
704
705 void
706 _CheckElementView::SetPressed(bool pressedState)
707 {
708         __pressedState = pressedState;
709 }
710
711 }}} //Tizen::Ui::Controls