Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / controls / FUiCtrl_IconListItem.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_IconListItem.cpp
20  * @brief               This is the implementation file for the _IconListItem class.
21  */
22
23 //Includes
24 #include <FBaseSysLog.h>
25 #include <FGrpCanvas.h>
26 #include <FUiCtrlIconListViewItem.h>
27 #include <FGrp_BitmapImpl.h>
28 #include <FGrp_CanvasImpl.h>
29 #include <FGrp_TextTextObject.h>
30 #include <FGrp_TextTextSimple.h>
31
32 #include "FUiAnim_VisualElement.h"
33 #include "FUiCtrl_IconListItem.h"
34 #include "FUiCtrl_IconListItemDrawingProperty.h"
35 #include "FUiCtrl_IconListUtils.h"
36
37 using namespace Tizen::Base;
38 using namespace Tizen::Graphics;
39 using namespace Tizen::Graphics::_Text;
40 using namespace Tizen::Ui::Animations;
41
42 namespace Tizen { namespace Ui { namespace Controls
43 {
44
45 _IconListItem::_IconListItem(_VisualElement* pBase)
46         : _ListItemCommon()
47         , __itemIndex(0)
48         , __text(L"")
49         , __pBase(pBase)
50         , __pTextVE(null)
51         , __pCheckVE(null)
52         , __pProperty(null)
53         , __foreDrawnState(LIST_ITEM_STATE_NORMAL)
54         , __isDrawn(false)
55         , __pTextObject(null)
56 {
57         __pBitmap[ICON_LIST_VIEW_ITEM_DRAWING_STATUS_NORMAL] = null;
58         __pBitmap[ICON_LIST_VIEW_ITEM_DRAWING_STATUS_PRESSED] = null;
59         __pBitmap[ICON_LIST_VIEW_ITEM_DRAWING_STATUS_HIGHLIGHTED] = null;
60 }
61
62 _IconListItem::~_IconListItem(void)
63 {
64         delete __pBitmap[ICON_LIST_VIEW_ITEM_DRAWING_STATUS_NORMAL];
65         __pBitmap[ICON_LIST_VIEW_ITEM_DRAWING_STATUS_NORMAL] = null;
66
67         delete __pBitmap[ICON_LIST_VIEW_ITEM_DRAWING_STATUS_PRESSED];
68         __pBitmap[ICON_LIST_VIEW_ITEM_DRAWING_STATUS_PRESSED] = null;
69
70         delete __pBitmap[ICON_LIST_VIEW_ITEM_DRAWING_STATUS_HIGHLIGHTED];
71         __pBitmap[ICON_LIST_VIEW_ITEM_DRAWING_STATUS_HIGHLIGHTED] = null;
72
73         __pProperty = null;
74
75         delete __pTextObject;
76         __pTextObject = null;
77
78         for (int i = 0, n = __overlayBitmaps.size() ; i < n ; i++)
79         {
80                 _OverlayBitmap* pOverlayBitmap = __overlayBitmaps.at(i);
81                 delete pOverlayBitmap->pBitmap;
82                 pOverlayBitmap->pBitmap = null;
83
84                 if (pOverlayBitmap->pVE != null)
85                 {
86                         if (__pBase != null)
87                         {
88                                 __pBase->DetachChild(*(pOverlayBitmap->pVE));
89                         }
90
91                         pOverlayBitmap->pVE->Destroy();
92                         pOverlayBitmap->pVE = null;
93                 }
94
95                 delete pOverlayBitmap;
96         }
97
98         if (__pTextVE != null)
99         {
100                 if (__pBase != null)
101                 {
102                         __pBase->DetachChild(*__pTextVE);
103                 }
104
105                 __pTextVE->Destroy();
106                 __pTextVE = null;
107         }
108
109         if (__pCheckVE != null)
110         {
111                 if (__pBase != null)
112                 {
113                         __pBase->DetachChild(*__pCheckVE);
114                 }
115
116                 __pCheckVE->Destroy();
117                 __pCheckVE = null;
118         }
119
120         if (__pBase != null)
121         {
122                 VisualElement* pParent = __pBase->GetParent();
123                 if (pParent != null)
124                 {
125                         pParent->DetachChild(*__pBase);
126                 }
127                 __pBase->Destroy();
128                 __pBase = null;
129         }
130
131         __overlayBitmaps.clear();
132 }
133
134 _IconListItem*
135 _IconListItem::CreateIconListItemN(IconListViewItem* pIconListViewItem)
136 {
137         result r = E_SUCCESS;
138         _IconListItem* pItem = null;
139         _VisualElement* pBase = new (std::nothrow) _VisualElement;
140         SysTryReturn(NID_UI_CTRL, (pBase != null), null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
141
142         r = pBase->Construct();
143         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
144
145         ClearLastResult();
146
147         pBase->SetSurfaceOpaque(false);
148         pBase->SetImplicitAnimationEnabled(false);
149
150         pItem = new (std::nothrow) _IconListItem(pBase);
151         SysTryCatch(NID_UI_CTRL, pItem != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
152
153         pItem->SetAppInfo(pIconListViewItem);
154
155         return pItem;
156 CATCH:
157         pBase->Destroy();
158
159         return null;
160 }
161
162 bool
163 _IconListItem::DrawItem(Rectangle& rcItem, ListItemState isFocused, bool itemDivider)
164 {
165         SysAssertf(__pProperty != null, "Not yet initialized. SetDrawingProperty() should be called before use.");
166
167         ClearLastResult();
168
169         if (!__pBase->GetShowState())
170         {
171                 __pBase->SetShowState(true);
172         }
173
174         __pBase->SetBounds(FloatRectangle(rcItem.x, rcItem.y, rcItem.width, rcItem.height));
175
176         if (!__pProperty->IsChanged() && __isDrawn && __foreDrawnState == isFocused)
177         {
178                 return true;
179         }
180
181         Canvas* pCanvas = __pBase->GetCanvasN(Rectangle(0, 0, rcItem.width, rcItem.height));
182         if (pCanvas == null)
183         {
184                 return false;
185         }
186
187         // Draw Background Color
188         IconListViewItemDrawingStatus status = _IconListUtils::EnumConverter::ConvertListItemStateToIconListViewItemDrawingStatus(isFocused);
189         pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
190         pCanvas->Clear();
191         int margin = __pProperty->GetSelectBackgroundMargin();
192         pCanvas->FillRectangle(__pProperty->GetBackgroundColor(status), Rectangle(margin, margin, rcItem.width - margin, rcItem.height - margin));
193
194         // Draw Bitmap
195         Bitmap* pBitmap = (__pBitmap[isFocused] != null) ? __pBitmap[isFocused] : __pBitmap[ICON_LIST_VIEW_ITEM_DRAWING_STATUS_NORMAL];
196         if (pBitmap != null)
197         {
198                 DrawBitmap(*pCanvas, *pBitmap, (status == ICON_LIST_VIEW_ITEM_DRAWING_STATUS_HIGHLIGHTED));
199         }
200
201         // Draw Text
202         DrawText(__pProperty->GetTextColor(status));
203
204         // Draw Check
205         if (__pProperty->IsItemCheckedStyle())
206         {
207                 DrawCheck(*pCanvas);
208         }
209
210         // Draw Overlay Bitmap
211         if (__overlayBitmaps.size() > 0)
212         {
213                 DrawOverlayBitmaps();
214         }
215
216         __pBase->SetFlushNeeded();
217         __isDrawn = true;
218         __foreDrawnState = isFocused;
219         delete pCanvas;
220
221         return true;
222 }
223
224 result
225 _IconListItem::DrawItemTouchAnimation(Rectangle& rcItem, float ratio)
226 {
227         SysAssertf(__pProperty != null, "Not yet initialized. SetDrawingProperty() should be called before use.");
228
229         __pBase->SetBounds(FloatRectangle(rcItem.x, rcItem.y, rcItem.width, rcItem.height));
230
231         if (!__pBase->GetShowState())
232         {
233                 __pBase->SetShowState(true);
234         }
235
236         Canvas* pCanvas = __pBase->GetCanvasN(Rectangle(0, 0, rcItem.width, rcItem.height));
237         if (pCanvas == null)
238         {
239                 result r = GetLastResult();
240                 SysLogException(NID_UI_CTRL, r, "[%s] Propagating.", GetErrorMessage(r));
241                 return r;
242         }
243
244         pCanvas->SetBackgroundColor(__pProperty->GetBackgroundColor(ICON_LIST_VIEW_ITEM_DRAWING_STATUS_NORMAL));
245         pCanvas->Clear();
246
247         // Draw Bitmap
248         Bitmap* pBitmap = __pBitmap[ICON_LIST_VIEW_ITEM_DRAWING_STATUS_NORMAL];
249         if (pBitmap != null)
250         {
251                 DrawBitmap(*pCanvas, *pBitmap, false, ratio);
252         }
253
254         // Draw Text
255         DrawText(__pProperty->GetTextColor(ICON_LIST_VIEW_ITEM_DRAWING_STATUS_NORMAL));
256
257         // Draw Check
258         if (__pProperty->IsItemCheckedStyle())
259         {
260                 DrawCheck(*pCanvas);
261         }
262
263         if (__overlayBitmaps.size() > 0)
264         {
265                 DrawOverlayBitmaps();
266         }
267
268         __isDrawn = false;
269         delete pCanvas;
270
271         return E_SUCCESS;
272 }
273
274 result
275 _IconListItem::DrawItemCheckAnimation(Tizen::Graphics::Rectangle& rcItem, float ratio)
276 {
277         SysAssertf(__pProperty != null, "Not yet initialized. SetDrawingProperty() should be called before use.");
278
279         __pBase->SetBounds(FloatRectangle(rcItem.x, rcItem.y, rcItem.width, rcItem.height));
280
281         if (!__pBase->GetShowState())
282         {
283                 __pBase->SetShowState(true);
284         }
285
286         Canvas* pCanvas = __pBase->GetCanvasN(Rectangle(0, 0, rcItem.width, rcItem.height));
287         if (pCanvas == null)
288         {
289                 result r = GetLastResult();
290                 SysLogException(NID_UI_CTRL, r, "[%s] Propagating.", GetErrorMessage(r));
291                 return r;
292         }
293
294         pCanvas->SetBackgroundColor(__pProperty->GetBackgroundColor(ICON_LIST_VIEW_ITEM_DRAWING_STATUS_NORMAL));
295         pCanvas->Clear();
296
297         // Draw Bitmap
298         Bitmap* pBitmap = __pBitmap[ICON_LIST_VIEW_ITEM_DRAWING_STATUS_NORMAL];
299         if (pBitmap != null)
300         {
301                 DrawBitmap(*pCanvas, *pBitmap);
302         }
303
304         // Draw Text
305         DrawText(__pProperty->GetTextColor(ICON_LIST_VIEW_ITEM_DRAWING_STATUS_NORMAL));
306
307         // Draw Check
308         if (__pProperty->IsItemCheckedStyle())
309         {
310                 DrawCheck(*pCanvas, ratio);
311         }
312
313         if (__overlayBitmaps.size() > 0)
314         {
315                 DrawOverlayBitmaps();
316         }
317
318         __isDrawn = false;
319         delete pCanvas;
320
321         return E_SUCCESS;
322 }
323
324 result
325 _IconListItem::DrawBitmap(Canvas& canvas, Bitmap& bitmap, bool isFocused, float ratio)
326 {
327         Rectangle rect = __pProperty->GetItemBitmapBounds();
328         int borderWidth = __pProperty->GetDropShadowBorderWidth();
329         int dropShadowSize = __pProperty->GetDropShadowMargin() + (borderWidth << 1);
330         if (__pProperty->GetBorderStyle() == ICON_LIST_VIEW_ITEM_BORDER_STYLE_SHADOW)
331         {
332                 rect.x += borderWidth;
333                 rect.y += borderWidth;
334                 rect.width -= dropShadowSize;
335                 rect.height -= dropShadowSize;
336         }
337
338         int width = rect.width;
339         int height = rect.height;
340
341         // Adjust Bitmap Ratio
342         if (__pProperty->IsItemBitmapAsAspectRatio())
343         {
344                 width = bitmap.GetWidth() * rect.height / bitmap.GetHeight();
345                 height = bitmap.GetHeight() * rect.width / bitmap.GetWidth();
346                 if (width > rect.width)
347                 {
348                         width = rect.width;
349                 }
350
351                 if (height > rect.height)
352                 {
353                         height = rect.height;
354                 }
355         }
356
357         // Resize & Set Alpha by Ratio(ratio < 1.0f)
358         if (ratio < REFERENCE_FACTOR)
359         {
360                 width = width * ratio;
361                 height = height * ratio;
362                 bitmap.SetAlphaConstant(OPAQUE_ALPHA * ratio);
363         }
364
365         // Set Bitmap Rect
366         rect.x += (rect.width - width) >> 1;
367         rect.y += (rect.height - height) >> 1;
368         rect.SetSize(width, height);
369
370         switch (__pProperty->GetBorderStyle())
371         {
372         case ICON_LIST_VIEW_ITEM_BORDER_STYLE_NONE:
373         {
374                 // Draw Bitmap
375                 if (bitmap.IsNinePatchedBitmap())
376                 {
377                         canvas.DrawNinePatchedBitmap(rect, bitmap);
378                 }
379                 else
380                 {
381                         canvas.DrawBitmap(rect, bitmap);
382                 }
383                 break;
384         }
385
386         case ICON_LIST_VIEW_ITEM_BORDER_STYLE_OUTLINE:
387         {
388                 // Draw Bitmap
389                 if (bitmap.IsNinePatchedBitmap())
390                 {
391                         canvas.DrawNinePatchedBitmap(rect, bitmap);
392                 }
393                 else
394                 {
395                         canvas.DrawBitmap(rect, bitmap);
396                 }
397
398                 if (ratio >= REFERENCE_FACTOR)
399                 {
400                         // Draw Outline
401                         canvas.SetForegroundColor(__pProperty->GetBorderColor(isFocused));
402                         canvas.SetLineWidth(1);
403                         Dimension dim = __pProperty->GetItemSize();
404                         Rectangle rect(0, 0, dim.width, dim.height);
405                         canvas.DrawRectangle(rect);
406                 }
407                 break;
408         }
409
410         case ICON_LIST_VIEW_ITEM_BORDER_STYLE_SHADOW:
411         {
412                 if (isFocused)
413                 {
414                         // Draw Drop-Shadow Effect
415                         if (__pProperty->GetFocusDropShadowBitmap() != null && ratio >= REFERENCE_FACTOR)
416                         {
417                                 const Bitmap* pShadowBitmap = __pProperty->GetFocusDropShadowBitmap();
418                                 if (pShadowBitmap->IsNinePatchedBitmap())
419                                 {
420                                         canvas.DrawNinePatchedBitmap(__pProperty->GetDropShadowBitmapBounds(), *pShadowBitmap);
421                                 }
422                                 else
423                                 {
424                                         canvas.DrawBitmap(__pProperty->GetDropShadowBitmapBounds(), *pShadowBitmap);
425                                 }
426                         }
427                 }
428                 else
429                 {
430                         // Draw Drop-Shadow Effect
431                         if (__pProperty->GetDropShadowBitmap() != null && ratio >= REFERENCE_FACTOR)
432                         {
433                                 const Bitmap* pShadowBitmap = __pProperty->GetDropShadowBitmap();
434                                 if (pShadowBitmap->IsNinePatchedBitmap())
435                                 {
436                                         canvas.DrawNinePatchedBitmap(__pProperty->GetDropShadowBitmapBounds(), *pShadowBitmap);
437                                 }
438                                 else
439                                 {
440                                         canvas.DrawBitmap(__pProperty->GetDropShadowBitmapBounds(), *pShadowBitmap);
441                                 }
442                         }
443                 }
444
445                 // Draw Bitmap
446                 if (bitmap.IsNinePatchedBitmap())
447                 {
448                         canvas.DrawNinePatchedBitmap(rect, bitmap);
449                 }
450                 else
451                 {
452                         canvas.DrawBitmap(rect, bitmap);
453                 }
454                 break;
455         }
456         }
457
458         if (ratio < REFERENCE_FACTOR)
459         {
460                 bitmap.SetAlphaConstant(OPAQUE_ALPHA);
461         }
462
463         return E_SUCCESS;
464 }
465
466 result
467 _IconListItem::DrawText(const Color& color)
468 {
469         if (__text.IsEmpty())
470         {
471                 return E_SUCCESS;
472         }
473
474         if (__pTextObject == null)
475         {
476                 __pTextObject = new (std::nothrow) TextObject;
477                 wchar_t* pStr = const_cast <wchar_t*>(__text.GetPointer());
478                 __pTextObject->Construct();
479                 TextSimple* pSimpleText = new (std::nothrow)TextSimple(pStr, __text.GetLength(), TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
480                 __pTextObject->AppendElement(*pSimpleText);
481
482                 __pTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
483         }
484
485
486         switch (__pProperty->GetTextHorizontalAlignment())
487         {
488         case ALIGNMENT_LEFT:
489                 __pTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_LEFT);
490                 break;
491
492         case ALIGNMENT_CENTER:
493                 __pTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_CENTER);
494                 break;
495
496         case ALIGNMENT_RIGHT:
497                 __pTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_RIGHT);
498                 break;
499         }
500
501         __pTextObject->SetForegroundColor(color, 0, __pTextObject->GetTextLength());
502
503         Font* pFont = __pProperty->GetFont();
504         SysTryReturn(NID_UI_CTRL, pFont != null, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
505
506         int textVerticalMargin = __pProperty->GetTextVerticalMargin();
507         int width = __pProperty->GetTextAreaWidth();
508
509         __pTextObject->SetFont(pFont, 0, __pTextObject->GetTextLength());
510         __pTextObject->SetWrap(TEXT_OBJECT_WRAP_TYPE_WORD);
511         __pTextObject->SetBounds(Rectangle(0, 0, width, 1));
512         __pTextObject->Compose();
513
514         int height = __pTextObject->GetTotalHeight();
515         int leading = _FontImpl::GetInstance((*pFont))->GetLeading();
516         int textYPos = __pProperty->GetTextYPosition();
517         if (height >= leading * 2)
518         {
519                 textYPos = __pProperty->GetTwoLineTextYPosition();
520                 height = (leading + textVerticalMargin) * 2;
521         }
522         else
523         {
524                 height += (textVerticalMargin * 2);
525         }
526
527         if (__pProperty->GetTextVerticalAlignment() == ICON_LIST_VIEW_ITEM_TEXT_VERTICAL_ALIGNMENT_INSIDE_BOTTOM)
528         {
529                 Dimension itemSize = __pProperty->GetItemSize();
530                 textYPos = itemSize.height - height;
531         }
532
533         if (__pTextVE == null)
534         {
535                 __pTextVE = new (std::nothrow) _VisualElement();
536                 SysTryReturn(NID_UI_CTRL, __pTextVE != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
537
538                 result r = __pTextVE->Construct();
539                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
540
541                 __pTextVE->SetRedrawOnResizeEnabled(false);
542                 __pTextVE->SetImplicitAnimationEnabled(false);
543
544                 __pBase->AttachChild(*__pTextVE);
545         }
546
547         __pTextVE->SetBounds(FloatRectangle(__pProperty->GetTextXPosition(), textYPos, width, height));
548         __pTextVE->SetShowState(true);
549
550         Canvas* pCanvas = __pTextVE->GetCanvasN();
551         SysTryReturn(NID_UI_CTRL, pCanvas != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
552
553         Rectangle bounds(0, 0, width, height);
554         pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
555         pCanvas->Clear();
556         pCanvas->FillRectangle(__pProperty->GetTextBackgroundColor(), bounds);
557
558         __pTextObject->SetBounds(bounds);
559         __pTextObject->Draw(*_CanvasImpl::GetInstance(*pCanvas));
560         delete pCanvas;
561
562         return E_SUCCESS;
563 }
564
565 result
566 _IconListItem::DrawCheck(Canvas& canvas, float ratio)
567 {
568         const Bitmap* pBackgroundBitmap = null;
569         const Bitmap* pBitmap = null;
570         pBitmap = IsChecked() ? __pProperty->GetCheckBitmap() : null;
571         pBackgroundBitmap = IsItemEnabled() ? (IsChecked() ? __pProperty->GetCheckedBackgroundBitmap() : __pProperty->GetUnCheckedBackgroundBitmap()) : __pProperty->GetDisabledCheckBitmap();
572
573         if (pBackgroundBitmap == null)
574         {
575                 return E_SYSTEM;
576         }
577
578         int width = pBackgroundBitmap->GetWidth();
579         int height = pBackgroundBitmap->GetHeight();
580         int checkMargin = __pProperty->GetCheckMargin();
581
582         Rectangle bitmapBounds = __pProperty->GetItemBitmapBounds();
583         Point checkPosition(bitmapBounds.x, bitmapBounds.y);
584         switch (__pProperty->GetCheckBoxPosition())
585         {
586         case ICON_LIST_VIEW_CHECK_BOX_POSITION_TOP_LEFT:
587                 checkPosition.x += checkMargin;
588                 checkPosition.y += checkMargin;
589                 break;
590
591         case ICON_LIST_VIEW_CHECK_BOX_POSITION_TOP_RIGHT:
592                 checkPosition.x += bitmapBounds.width - checkMargin - width;
593                 checkPosition.y += checkMargin;
594                 break;
595
596         case ICON_LIST_VIEW_CHECK_BOX_POSITION_BOTTOM_LEFT:
597                 checkPosition.x += checkMargin;
598                 checkPosition.y += bitmapBounds.height - checkMargin - height;
599                 break;
600
601         case ICON_LIST_VIEW_CHECK_BOX_POSITION_BOTTOM_RIGHT:
602                 checkPosition.x += bitmapBounds.width - checkMargin - width;
603                 checkPosition.y += bitmapBounds.height - checkMargin - height;
604                 break;
605         }
606
607         // draw background of check box
608         if (pBackgroundBitmap->IsNinePatchedBitmap())
609         {
610                 canvas.DrawNinePatchedBitmap(Rectangle(checkPosition.x, checkPosition.y, width, height), *pBackgroundBitmap);
611         }
612         else
613         {
614                 canvas.DrawBitmap(checkPosition, *pBackgroundBitmap);
615         }
616
617         // draw check image
618         if (__pCheckVE == null)
619         {
620                 __pCheckVE = new (std::nothrow) _VisualElement();
621                 SysTryReturn(NID_UI_CTRL, __pCheckVE != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
622
623                 result r = __pCheckVE->Construct();
624                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
625
626                 __pCheckVE->SetRedrawOnResizeEnabled(false);
627                 __pCheckVE->SetImplicitAnimationEnabled(false);
628                 __pBase->AttachChild(*__pCheckVE);
629         }
630
631         FloatRectangle checkRect(checkPosition.x, checkPosition.y, width, height);
632         __pCheckVE->SetBounds(checkRect);
633         __pCheckVE->SetShowState(true);
634
635         Canvas* pCanvas = __pCheckVE->GetCanvasN();
636         SysTryReturn(NID_UI_CTRL, pCanvas != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
637
638         pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
639         pCanvas->Clear();
640
641         if (pBitmap != null)
642         {
643                 if (pBitmap->IsNinePatchedBitmap())
644                 {
645                         pCanvas->DrawNinePatchedBitmap(Rectangle(0, 0, pBitmap->GetWidth(), pBitmap->GetHeight()), *pBitmap);
646                 }
647                 else
648                 {
649                         Rectangle animationRect(0, 0, pBitmap->GetWidth() * ratio, pBitmap->GetHeight());
650                         pCanvas->DrawBitmap(animationRect, *pBitmap, animationRect);
651                 }
652         }
653         delete pCanvas;
654
655         return E_SUCCESS;
656 }
657
658 result
659 _IconListItem::DrawOverlayBitmaps(void)
660 {
661         result r = E_SUCCESS;
662         Rectangle bitmapBounds = __pProperty->GetItemBitmapBounds();
663         Canvas* pCanvas = null;
664         for (int i = 0, n = __overlayBitmaps.size(); i < n; i++)
665         {
666                 _OverlayBitmap* pOverlayBitmap = __overlayBitmaps.at(i);
667                 int overlayMargin = __pProperty->GetOverlayMargin();
668                 if (pOverlayBitmap->pBitmap != null)
669                 {
670                         Rectangle rect = GetOverlayBitmapBounds(pOverlayBitmap, bitmapBounds, overlayMargin);
671
672                         _VisualElement* pVE = null;
673                         if (pOverlayBitmap->pVE == null)
674                         {
675                                 pVE = new (std::nothrow) _VisualElement();
676                                 SysTryReturn(NID_UI_CTRL, pVE != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
677
678                                 r = pVE->Construct();
679                                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
680
681                                 pVE->SetRedrawOnResizeEnabled(false);
682                                 pVE->SetImplicitAnimationEnabled(false);
683
684                                 __pBase->AttachChild(*pVE);
685                                 pOverlayBitmap->pVE = pVE;
686                         }
687                         else
688                         {
689                                 pVE = pOverlayBitmap->pVE;
690                         }
691
692                         pVE->SetBounds(FloatRectangle(rect.x, rect.y, rect.width, rect.height));
693                         pVE->SetShowState(true);
694
695                         pCanvas = pVE->GetCanvasN();
696                         SysTryReturn(NID_UI_CTRL, pCanvas != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
697
698                         pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
699                         pCanvas->Clear();
700
701                         Bitmap* pBitmap = pOverlayBitmap->pBitmap;
702                         if(pBitmap->IsNinePatchedBitmap())
703                         {
704                                 pCanvas->DrawNinePatchedBitmap(Rectangle(0, 0, rect.width, rect.height), *pBitmap);
705                         }
706                         else
707                         {
708                                 pCanvas->DrawBitmap(Rectangle(0, 0, rect.width, rect.height), *pBitmap);
709                         }
710                         delete pCanvas;
711                 }
712         }
713         return r;
714 }
715
716 result
717 _IconListItem::SetText(const String* pText)
718 {
719         if (pText == null)
720         {
721                 __text = String(L"");
722                 return E_SUCCESS;
723         }
724
725         __text = *pText;
726         __isDrawn = false;
727
728         return E_SUCCESS;
729 }
730
731 const String&
732 _IconListItem::GetText(void) const
733 {
734         return __text;
735 }
736
737 result
738 _IconListItem::SetBitmap(IconListViewItemDrawingStatus status, const Bitmap* pBitmap)
739 {
740         if (ICON_LIST_VIEW_ITEM_DRAWING_STATUS_NORMAL > status
741                 || ICON_LIST_VIEW_ITEM_DRAWING_STATUS_HIGHLIGHTED < status)
742         {
743                 SysLogException(NID_UI_CTRL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used.");
744                 return E_INVALID_ARG;
745         }
746
747         SysTryReturn(NID_UI_CTRL, (status != ICON_LIST_VIEW_ITEM_DRAWING_STATUS_NORMAL || pBitmap != null), E_INVALID_ARG,
748                                 E_INVALID_ARG,
749                                 "[E_INVALID_ARG] Invalid argument is used. The normal bitmap must not be null.");
750
751         result r = E_SUCCESS;
752         Bitmap* pCopiedBitmap = null;
753         if (pBitmap != null)
754         {
755                 pCopiedBitmap = _BitmapImpl::CloneN(*pBitmap);
756                 r = GetLastResult();
757         }
758
759         if (r == E_SUCCESS)
760         {
761                 delete __pBitmap[status];
762                 __pBitmap[status] = pCopiedBitmap;
763         }
764
765         __isDrawn = false;
766
767         return r;
768 }
769
770 const Bitmap*
771 _IconListItem::GetBitmap(IconListViewItemDrawingStatus status) const
772 {
773         SysTryReturn(NID_UI_CTRL,
774                         (status > ICON_LIST_VIEW_ITEM_DRAWING_STATUS_NORMAL && status < ICON_LIST_VIEW_ITEM_DRAWING_STATUS_HIGHLIGHTED),
775                         null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used.");
776
777         SetLastResult(E_SUCCESS);
778         return __pBitmap[status];
779 }
780
781 Tizen::Ui::Animations::_VisualElement*
782 _IconListItem::GetVisualElement(void) const
783 {
784         return __pBase;
785 }
786
787 void
788 _IconListItem::ClearVisualElement(void)
789 {
790         __isDrawn = false;
791 }
792
793 result
794 _IconListItem::SetDrawingProperty(_IconListItemDrawingProperty& property)
795 {
796         __pProperty = &property;
797
798         return E_SUCCESS;
799 }
800
801 void
802 _IconListItem::SetChecked(bool checked)
803 {
804         if (IsChecked() == checked)
805         {
806                 return;
807         }
808
809         _ListItemCommon::SetChecked(checked);
810         __isDrawn = false;
811 }
812
813 void
814 _IconListItem::SetItemIndex(int groupIndex, int itemIndex)
815 {
816         __itemIndex = itemIndex;
817 }
818
819 void
820 _IconListItem::GetItemIndex(int& groupIndex, int& itemIndex) const
821 {
822         groupIndex = DEFAULT_GROUP_INDEX;
823         itemIndex = __itemIndex;
824 }
825
826 result
827 _IconListItem::SetOverlayBitmap(int overlayBitmapId, const Tizen::Graphics::Bitmap* pOverlayBitmap, HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment)
828 {
829         result r = E_SUCCESS;
830
831         SysTryReturn(NID_UI_CTRL, horizontalAlignment >= ALIGNMENT_LEFT && horizontalAlignment <= ALIGNMENT_RIGHT, E_INVALID_ARG,
832                         E_INVALID_ARG, "[E_INVALID_ARG] The horizontal alignment is inappropriate.");
833         SysTryReturn(NID_UI_CTRL, verticalAlignment >= ALIGNMENT_TOP && verticalAlignment <= ALIGNMENT_BOTTOM, E_INVALID_ARG,
834                                 E_INVALID_ARG, "[E_INVALID_ARG] The vertical alignment is inappropriate.");
835
836         bool found = false;
837         Bitmap* pCopiedBitmap = null;
838         for (int i = 0, n = __overlayBitmaps.size() ; i < n; i++)
839         {
840                 _OverlayBitmap* pCurrentOverlayBitmap = __overlayBitmaps.at(i);
841                 if (pCurrentOverlayBitmap->horizontalAlignment == horizontalAlignment && pCurrentOverlayBitmap->verticalAlignment == verticalAlignment)
842                 {
843                         found = true;
844                         if (pOverlayBitmap == null)
845                         {
846                                 // delete overlay bitmap
847                                 delete pCurrentOverlayBitmap->pBitmap;
848                                 pCurrentOverlayBitmap->pBitmap = null;
849
850                                 if (pCurrentOverlayBitmap->pVE != null)
851                                 {
852                                         pCurrentOverlayBitmap->pVE->Destroy();
853                                         pCurrentOverlayBitmap->pVE = null;
854                                 }
855                                 __overlayBitmaps.erase(__overlayBitmaps.begin() + i);
856                                 delete pCurrentOverlayBitmap;
857                         }
858                         else
859                         {
860                                 // replace overlay bitmap
861                                 pCopiedBitmap = null;
862                                 pCopiedBitmap = _BitmapImpl::CloneN(*pOverlayBitmap);
863                                 r = GetLastResult();
864
865                                 if (r == E_SUCCESS)
866                                 {
867                                         delete pCurrentOverlayBitmap->pBitmap;
868                                         pCurrentOverlayBitmap->pBitmap = pCopiedBitmap;
869                                         pCurrentOverlayBitmap->id = overlayBitmapId;
870                                 }
871                         }
872                         break;
873                 }
874         }
875
876         if (!found)
877         {
878                 if (pOverlayBitmap != null)
879                 {
880                         // add overlay bitmap
881                         pCopiedBitmap = null;
882                         pCopiedBitmap = _BitmapImpl::CloneN(*pOverlayBitmap);
883                         r = GetLastResult();
884                         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
885
886                         _OverlayBitmap* pNewOverlayBitmap = new (std::nothrow) _OverlayBitmap();
887                         pNewOverlayBitmap->id = overlayBitmapId;
888                         pNewOverlayBitmap->pBitmap = pCopiedBitmap;
889                         pNewOverlayBitmap->horizontalAlignment = horizontalAlignment;
890                         pNewOverlayBitmap->verticalAlignment = verticalAlignment;
891                         pNewOverlayBitmap->pVE = null;
892
893                         __overlayBitmaps.push_back(pNewOverlayBitmap);
894                 }
895         }
896
897         SetLastResult(r);
898         return r;
899 }
900
901 int
902 _IconListItem::GetOverlayBitmapIdFromPosition(Point& position) const
903 {
904         if (__overlayBitmaps.size() <= 0)
905         {
906                 return -1;
907         }
908
909         Rectangle bitmapBounds = __pProperty->GetItemBitmapBounds();
910         for (int i = __overlayBitmaps.size() - 1; i >= 0; i--)
911         {
912                 _OverlayBitmap* pOverlayBitmap = __overlayBitmaps.at(i);
913                 if (pOverlayBitmap != null)
914                 {
915                         int overlayMargin = __pProperty->GetOverlayMargin();
916                         if (pOverlayBitmap->pBitmap != null)
917                         {
918                                 Rectangle rect = GetOverlayBitmapBounds(pOverlayBitmap, bitmapBounds, overlayMargin);
919                                 if (rect.Contains(position))
920                                 {
921                                         return pOverlayBitmap->id;
922                                 }
923                         }
924                 }
925         }
926
927         return -1;
928 }
929
930 _VisualElement*
931 _IconListItem::GetItemVisualElement(void) const
932 {
933         return __pBase;
934 }
935
936 Rectangle
937 _IconListItem::GetOverlayBitmapBounds(_OverlayBitmap* pOverlayBitmap, const Rectangle& parentRect, int margin) const
938 {
939         int x = parentRect.x;
940         int y = parentRect.y;
941         int width = pOverlayBitmap->pBitmap->GetWidth();
942         int height = pOverlayBitmap->pBitmap->GetHeight();
943
944         switch (pOverlayBitmap->horizontalAlignment)
945         {
946         case ALIGNMENT_LEFT:
947                 x += margin;
948                 break;
949         case ALIGNMENT_CENTER:
950                 x += (parentRect.width - width) / 2;
951                 break;
952         case ALIGNMENT_RIGHT:
953                 x += (parentRect.width - width - margin);
954                 break;
955         }
956
957         switch (pOverlayBitmap->verticalAlignment)
958         {
959         case ALIGNMENT_TOP:
960                 y += margin;
961                 break;
962         case ALIGNMENT_MIDDLE:
963                 y += (parentRect.height - height) / 2;
964                 break;
965         case ALIGNMENT_BOTTOM:
966                 y += (parentRect.height - height - margin);
967                 break;
968         }
969
970         return Rectangle(x, y, width, height);
971 }
972
973 }}} // Tizen::Ui::Controls