2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
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
9 // http://floralicense.org/license/
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.
19 * @file FUiCtrl_IconListItem.cpp
20 * @brief This is the implementation file for the _IconListItem class.
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>
32 #include "FUiAnim_VisualElement.h"
33 #include "FUiCtrl_IconListItem.h"
34 #include "FUiCtrl_IconListItemDrawingProperty.h"
35 #include "FUiCtrl_IconListUtils.h"
37 using namespace Tizen::Base;
38 using namespace Tizen::Graphics;
39 using namespace Tizen::Graphics::_Text;
40 using namespace Tizen::Ui::Animations;
42 namespace Tizen { namespace Ui { namespace Controls
45 _IconListItem::_IconListItem(_VisualElement* pBase)
53 , __foreDrawnState(LIST_ITEM_STATE_NORMAL)
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;
62 _IconListItem::~_IconListItem(void)
64 delete __pBitmap[ICON_LIST_VIEW_ITEM_DRAWING_STATUS_NORMAL];
65 __pBitmap[ICON_LIST_VIEW_ITEM_DRAWING_STATUS_NORMAL] = null;
67 delete __pBitmap[ICON_LIST_VIEW_ITEM_DRAWING_STATUS_PRESSED];
68 __pBitmap[ICON_LIST_VIEW_ITEM_DRAWING_STATUS_PRESSED] = null;
70 delete __pBitmap[ICON_LIST_VIEW_ITEM_DRAWING_STATUS_HIGHLIGHTED];
71 __pBitmap[ICON_LIST_VIEW_ITEM_DRAWING_STATUS_HIGHLIGHTED] = null;
78 for (int i = 0, n = __overlayBitmaps.size() ; i < n ; i++)
80 _OverlayBitmap* pOverlayBitmap = __overlayBitmaps.at(i);
81 delete pOverlayBitmap->pBitmap;
82 pOverlayBitmap->pBitmap = null;
84 if (pOverlayBitmap->pVE != null)
88 __pBase->DetachChild(*(pOverlayBitmap->pVE));
91 pOverlayBitmap->pVE->Destroy();
92 pOverlayBitmap->pVE = null;
95 delete pOverlayBitmap;
98 if (__pTextVE != null)
102 __pBase->DetachChild(*__pTextVE);
105 __pTextVE->Destroy();
109 if (__pCheckVE != null)
113 __pBase->DetachChild(*__pCheckVE);
116 __pCheckVE->Destroy();
122 VisualElement* pParent = __pBase->GetParent();
125 pParent->DetachChild(*__pBase);
131 __overlayBitmaps.clear();
135 _IconListItem::CreateIconListItemN(IconListViewItem* pIconListViewItem)
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.");
142 r = pBase->Construct();
143 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
147 pBase->SetSurfaceOpaque(false);
148 pBase->SetImplicitAnimationEnabled(false);
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.");
153 pItem->SetAppInfo(pIconListViewItem);
163 _IconListItem::DrawItem(Rectangle& rcItem, ListItemState isFocused, bool itemDivider)
165 SysAssertf(__pProperty != null, "Not yet initialized. SetDrawingProperty() should be called before use.");
169 if (!__pBase->GetShowState())
171 __pBase->SetShowState(true);
174 __pBase->SetBounds(FloatRectangle(rcItem.x, rcItem.y, rcItem.width, rcItem.height));
176 if (!__pProperty->IsChanged() && __isDrawn && __foreDrawnState == isFocused)
181 Canvas* pCanvas = __pBase->GetCanvasN(Rectangle(0, 0, rcItem.width, rcItem.height));
187 // Draw Background Color
188 IconListViewItemDrawingStatus status = _IconListUtils::EnumConverter::ConvertListItemStateToIconListViewItemDrawingStatus(isFocused);
189 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
191 int margin = __pProperty->GetSelectBackgroundMargin();
192 pCanvas->FillRectangle(__pProperty->GetBackgroundColor(status), Rectangle(margin, margin, rcItem.width - margin, rcItem.height - margin));
195 Bitmap* pBitmap = (__pBitmap[isFocused] != null) ? __pBitmap[isFocused] : __pBitmap[ICON_LIST_VIEW_ITEM_DRAWING_STATUS_NORMAL];
198 DrawBitmap(*pCanvas, *pBitmap, (status == ICON_LIST_VIEW_ITEM_DRAWING_STATUS_HIGHLIGHTED));
202 DrawText(__pProperty->GetTextColor(status));
205 if (__pProperty->IsItemCheckedStyle())
210 // Draw Overlay Bitmap
211 if (__overlayBitmaps.size() > 0)
213 DrawOverlayBitmaps();
216 __pBase->SetFlushNeeded();
218 __foreDrawnState = isFocused;
225 _IconListItem::DrawItemTouchAnimation(Rectangle& rcItem, float ratio)
227 SysAssertf(__pProperty != null, "Not yet initialized. SetDrawingProperty() should be called before use.");
229 __pBase->SetBounds(FloatRectangle(rcItem.x, rcItem.y, rcItem.width, rcItem.height));
231 if (!__pBase->GetShowState())
233 __pBase->SetShowState(true);
236 Canvas* pCanvas = __pBase->GetCanvasN(Rectangle(0, 0, rcItem.width, rcItem.height));
239 result r = GetLastResult();
240 SysLogException(NID_UI_CTRL, r, "[%s] Propagating.", GetErrorMessage(r));
244 pCanvas->SetBackgroundColor(__pProperty->GetBackgroundColor(ICON_LIST_VIEW_ITEM_DRAWING_STATUS_NORMAL));
248 Bitmap* pBitmap = __pBitmap[ICON_LIST_VIEW_ITEM_DRAWING_STATUS_NORMAL];
251 DrawBitmap(*pCanvas, *pBitmap, false, ratio);
255 DrawText(__pProperty->GetTextColor(ICON_LIST_VIEW_ITEM_DRAWING_STATUS_NORMAL));
258 if (__pProperty->IsItemCheckedStyle())
263 if (__overlayBitmaps.size() > 0)
265 DrawOverlayBitmaps();
275 _IconListItem::DrawItemCheckAnimation(Tizen::Graphics::Rectangle& rcItem, float ratio)
277 SysAssertf(__pProperty != null, "Not yet initialized. SetDrawingProperty() should be called before use.");
279 __pBase->SetBounds(FloatRectangle(rcItem.x, rcItem.y, rcItem.width, rcItem.height));
281 if (!__pBase->GetShowState())
283 __pBase->SetShowState(true);
286 Canvas* pCanvas = __pBase->GetCanvasN(Rectangle(0, 0, rcItem.width, rcItem.height));
289 result r = GetLastResult();
290 SysLogException(NID_UI_CTRL, r, "[%s] Propagating.", GetErrorMessage(r));
294 pCanvas->SetBackgroundColor(__pProperty->GetBackgroundColor(ICON_LIST_VIEW_ITEM_DRAWING_STATUS_NORMAL));
298 Bitmap* pBitmap = __pBitmap[ICON_LIST_VIEW_ITEM_DRAWING_STATUS_NORMAL];
301 DrawBitmap(*pCanvas, *pBitmap);
305 DrawText(__pProperty->GetTextColor(ICON_LIST_VIEW_ITEM_DRAWING_STATUS_NORMAL));
308 if (__pProperty->IsItemCheckedStyle())
310 DrawCheck(*pCanvas, ratio);
313 if (__overlayBitmaps.size() > 0)
315 DrawOverlayBitmaps();
325 _IconListItem::DrawBitmap(Canvas& canvas, Bitmap& bitmap, bool isFocused, float ratio)
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)
332 rect.x += borderWidth;
333 rect.y += borderWidth;
334 rect.width -= dropShadowSize;
335 rect.height -= dropShadowSize;
338 int width = rect.width;
339 int height = rect.height;
341 // Adjust Bitmap Ratio
342 if (__pProperty->IsItemBitmapAsAspectRatio())
344 width = bitmap.GetWidth() * rect.height / bitmap.GetHeight();
345 height = bitmap.GetHeight() * rect.width / bitmap.GetWidth();
346 if (width > rect.width)
351 if (height > rect.height)
353 height = rect.height;
357 // Resize & Set Alpha by Ratio(ratio < 1.0f)
358 if (ratio < REFERENCE_FACTOR)
360 width = width * ratio;
361 height = height * ratio;
362 bitmap.SetAlphaConstant(OPAQUE_ALPHA * ratio);
366 rect.x += (rect.width - width) >> 1;
367 rect.y += (rect.height - height) >> 1;
368 rect.SetSize(width, height);
370 switch (__pProperty->GetBorderStyle())
372 case ICON_LIST_VIEW_ITEM_BORDER_STYLE_NONE:
375 if (bitmap.IsNinePatchedBitmap())
377 canvas.DrawNinePatchedBitmap(rect, bitmap);
381 canvas.DrawBitmap(rect, bitmap);
386 case ICON_LIST_VIEW_ITEM_BORDER_STYLE_OUTLINE:
389 if (bitmap.IsNinePatchedBitmap())
391 canvas.DrawNinePatchedBitmap(rect, bitmap);
395 canvas.DrawBitmap(rect, bitmap);
398 if (ratio >= REFERENCE_FACTOR)
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);
410 case ICON_LIST_VIEW_ITEM_BORDER_STYLE_SHADOW:
414 // Draw Drop-Shadow Effect
415 if (__pProperty->GetFocusDropShadowBitmap() != null && ratio >= REFERENCE_FACTOR)
417 const Bitmap* pShadowBitmap = __pProperty->GetFocusDropShadowBitmap();
418 if (pShadowBitmap->IsNinePatchedBitmap())
420 canvas.DrawNinePatchedBitmap(__pProperty->GetDropShadowBitmapBounds(), *pShadowBitmap);
424 canvas.DrawBitmap(__pProperty->GetDropShadowBitmapBounds(), *pShadowBitmap);
430 // Draw Drop-Shadow Effect
431 if (__pProperty->GetDropShadowBitmap() != null && ratio >= REFERENCE_FACTOR)
433 const Bitmap* pShadowBitmap = __pProperty->GetDropShadowBitmap();
434 if (pShadowBitmap->IsNinePatchedBitmap())
436 canvas.DrawNinePatchedBitmap(__pProperty->GetDropShadowBitmapBounds(), *pShadowBitmap);
440 canvas.DrawBitmap(__pProperty->GetDropShadowBitmapBounds(), *pShadowBitmap);
446 if (bitmap.IsNinePatchedBitmap())
448 canvas.DrawNinePatchedBitmap(rect, bitmap);
452 canvas.DrawBitmap(rect, bitmap);
458 if (ratio < REFERENCE_FACTOR)
460 bitmap.SetAlphaConstant(OPAQUE_ALPHA);
467 _IconListItem::DrawText(const Color& color)
469 if (__text.IsEmpty())
474 if (__pTextObject == null)
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);
482 __pTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
486 switch (__pProperty->GetTextHorizontalAlignment())
489 __pTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_LEFT);
492 case ALIGNMENT_CENTER:
493 __pTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_CENTER);
496 case ALIGNMENT_RIGHT:
497 __pTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_RIGHT);
501 __pTextObject->SetForegroundColor(color, 0, __pTextObject->GetTextLength());
503 Font* pFont = __pProperty->GetFont();
504 SysTryReturn(NID_UI_CTRL, pFont != null, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
506 int textVerticalMargin = __pProperty->GetTextVerticalMargin();
507 int width = __pProperty->GetTextAreaWidth();
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();
514 int height = __pTextObject->GetTotalHeight();
515 int leading = _FontImpl::GetInstance((*pFont))->GetLeading();
516 int textYPos = __pProperty->GetTextYPosition();
517 if (height >= leading * 2)
519 textYPos = __pProperty->GetTwoLineTextYPosition();
520 height = (leading + textVerticalMargin) * 2;
524 height += (textVerticalMargin * 2);
527 if (__pProperty->GetTextVerticalAlignment() == ICON_LIST_VIEW_ITEM_TEXT_VERTICAL_ALIGNMENT_INSIDE_BOTTOM)
529 Dimension itemSize = __pProperty->GetItemSize();
530 textYPos = itemSize.height - height;
533 if (__pTextVE == null)
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.");
538 result r = __pTextVE->Construct();
539 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
541 __pTextVE->SetRedrawOnResizeEnabled(false);
542 __pTextVE->SetImplicitAnimationEnabled(false);
544 __pBase->AttachChild(*__pTextVE);
547 __pTextVE->SetBounds(FloatRectangle(__pProperty->GetTextXPosition(), textYPos, width, height));
548 __pTextVE->SetShowState(true);
550 Canvas* pCanvas = __pTextVE->GetCanvasN();
551 SysTryReturn(NID_UI_CTRL, pCanvas != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
553 Rectangle bounds(0, 0, width, height);
554 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
556 pCanvas->FillRectangle(__pProperty->GetTextBackgroundColor(), bounds);
558 __pTextObject->SetBounds(bounds);
559 __pTextObject->Draw(*_CanvasImpl::GetInstance(*pCanvas));
566 _IconListItem::DrawCheck(Canvas& canvas, float ratio)
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();
573 if (pBackgroundBitmap == null)
578 int width = pBackgroundBitmap->GetWidth();
579 int height = pBackgroundBitmap->GetHeight();
580 int checkMargin = __pProperty->GetCheckMargin();
582 Rectangle bitmapBounds = __pProperty->GetItemBitmapBounds();
583 Point checkPosition(bitmapBounds.x, bitmapBounds.y);
584 switch (__pProperty->GetCheckBoxPosition())
586 case ICON_LIST_VIEW_CHECK_BOX_POSITION_TOP_LEFT:
587 checkPosition.x += checkMargin;
588 checkPosition.y += checkMargin;
591 case ICON_LIST_VIEW_CHECK_BOX_POSITION_TOP_RIGHT:
592 checkPosition.x += bitmapBounds.width - checkMargin - width;
593 checkPosition.y += checkMargin;
596 case ICON_LIST_VIEW_CHECK_BOX_POSITION_BOTTOM_LEFT:
597 checkPosition.x += checkMargin;
598 checkPosition.y += bitmapBounds.height - checkMargin - height;
601 case ICON_LIST_VIEW_CHECK_BOX_POSITION_BOTTOM_RIGHT:
602 checkPosition.x += bitmapBounds.width - checkMargin - width;
603 checkPosition.y += bitmapBounds.height - checkMargin - height;
607 // draw background of check box
608 if (pBackgroundBitmap->IsNinePatchedBitmap())
610 canvas.DrawNinePatchedBitmap(Rectangle(checkPosition.x, checkPosition.y, width, height), *pBackgroundBitmap);
614 canvas.DrawBitmap(checkPosition, *pBackgroundBitmap);
618 if (__pCheckVE == null)
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.");
623 result r = __pCheckVE->Construct();
624 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
626 __pCheckVE->SetRedrawOnResizeEnabled(false);
627 __pCheckVE->SetImplicitAnimationEnabled(false);
628 __pBase->AttachChild(*__pCheckVE);
631 FloatRectangle checkRect(checkPosition.x, checkPosition.y, width, height);
632 __pCheckVE->SetBounds(checkRect);
633 __pCheckVE->SetShowState(true);
635 Canvas* pCanvas = __pCheckVE->GetCanvasN();
636 SysTryReturn(NID_UI_CTRL, pCanvas != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
638 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
643 if (pBitmap->IsNinePatchedBitmap())
645 pCanvas->DrawNinePatchedBitmap(Rectangle(0, 0, pBitmap->GetWidth(), pBitmap->GetHeight()), *pBitmap);
649 Rectangle animationRect(0, 0, pBitmap->GetWidth() * ratio, pBitmap->GetHeight());
650 pCanvas->DrawBitmap(animationRect, *pBitmap, animationRect);
659 _IconListItem::DrawOverlayBitmaps(void)
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++)
666 _OverlayBitmap* pOverlayBitmap = __overlayBitmaps.at(i);
667 int overlayMargin = __pProperty->GetOverlayMargin();
668 if (pOverlayBitmap->pBitmap != null)
670 Rectangle rect = GetOverlayBitmapBounds(pOverlayBitmap, bitmapBounds, overlayMargin);
672 _VisualElement* pVE = null;
673 if (pOverlayBitmap->pVE == null)
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.");
678 r = pVE->Construct();
679 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
681 pVE->SetRedrawOnResizeEnabled(false);
682 pVE->SetImplicitAnimationEnabled(false);
684 __pBase->AttachChild(*pVE);
685 pOverlayBitmap->pVE = pVE;
689 pVE = pOverlayBitmap->pVE;
692 pVE->SetBounds(FloatRectangle(rect.x, rect.y, rect.width, rect.height));
693 pVE->SetShowState(true);
695 pCanvas = pVE->GetCanvasN();
696 SysTryReturn(NID_UI_CTRL, pCanvas != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
698 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
701 Bitmap* pBitmap = pOverlayBitmap->pBitmap;
702 if(pBitmap->IsNinePatchedBitmap())
704 pCanvas->DrawNinePatchedBitmap(Rectangle(0, 0, rect.width, rect.height), *pBitmap);
708 pCanvas->DrawBitmap(Rectangle(0, 0, rect.width, rect.height), *pBitmap);
717 _IconListItem::SetText(const String* pText)
721 __text = String(L"");
732 _IconListItem::GetText(void) const
738 _IconListItem::SetBitmap(IconListViewItemDrawingStatus status, const Bitmap* pBitmap)
740 if (ICON_LIST_VIEW_ITEM_DRAWING_STATUS_NORMAL > status
741 || ICON_LIST_VIEW_ITEM_DRAWING_STATUS_HIGHLIGHTED < status)
743 SysLogException(NID_UI_CTRL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used.");
744 return E_INVALID_ARG;
747 SysTryReturn(NID_UI_CTRL, (status != ICON_LIST_VIEW_ITEM_DRAWING_STATUS_NORMAL || pBitmap != null), E_INVALID_ARG,
749 "[E_INVALID_ARG] Invalid argument is used. The normal bitmap must not be null.");
751 result r = E_SUCCESS;
752 Bitmap* pCopiedBitmap = null;
755 pCopiedBitmap = _BitmapImpl::CloneN(*pBitmap);
761 delete __pBitmap[status];
762 __pBitmap[status] = pCopiedBitmap;
771 _IconListItem::GetBitmap(IconListViewItemDrawingStatus status) const
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.");
777 SetLastResult(E_SUCCESS);
778 return __pBitmap[status];
781 Tizen::Ui::Animations::_VisualElement*
782 _IconListItem::GetVisualElement(void) const
788 _IconListItem::ClearVisualElement(void)
794 _IconListItem::SetDrawingProperty(_IconListItemDrawingProperty& property)
796 __pProperty = &property;
802 _IconListItem::SetChecked(bool checked)
804 if (IsChecked() == checked)
809 _ListItemCommon::SetChecked(checked);
814 _IconListItem::SetItemIndex(int groupIndex, int itemIndex)
816 __itemIndex = itemIndex;
820 _IconListItem::GetItemIndex(int& groupIndex, int& itemIndex) const
822 groupIndex = DEFAULT_GROUP_INDEX;
823 itemIndex = __itemIndex;
827 _IconListItem::SetOverlayBitmap(int overlayBitmapId, const Tizen::Graphics::Bitmap* pOverlayBitmap, HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment)
829 result r = E_SUCCESS;
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.");
837 Bitmap* pCopiedBitmap = null;
838 for (int i = 0, n = __overlayBitmaps.size() ; i < n; i++)
840 _OverlayBitmap* pCurrentOverlayBitmap = __overlayBitmaps.at(i);
841 if (pCurrentOverlayBitmap->horizontalAlignment == horizontalAlignment && pCurrentOverlayBitmap->verticalAlignment == verticalAlignment)
844 if (pOverlayBitmap == null)
846 // delete overlay bitmap
847 delete pCurrentOverlayBitmap->pBitmap;
848 pCurrentOverlayBitmap->pBitmap = null;
850 if (pCurrentOverlayBitmap->pVE != null)
852 pCurrentOverlayBitmap->pVE->Destroy();
853 pCurrentOverlayBitmap->pVE = null;
855 __overlayBitmaps.erase(__overlayBitmaps.begin() + i);
856 delete pCurrentOverlayBitmap;
860 // replace overlay bitmap
861 pCopiedBitmap = null;
862 pCopiedBitmap = _BitmapImpl::CloneN(*pOverlayBitmap);
867 delete pCurrentOverlayBitmap->pBitmap;
868 pCurrentOverlayBitmap->pBitmap = pCopiedBitmap;
869 pCurrentOverlayBitmap->id = overlayBitmapId;
878 if (pOverlayBitmap != null)
880 // add overlay bitmap
881 pCopiedBitmap = null;
882 pCopiedBitmap = _BitmapImpl::CloneN(*pOverlayBitmap);
884 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
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;
893 __overlayBitmaps.push_back(pNewOverlayBitmap);
902 _IconListItem::GetOverlayBitmapIdFromPosition(Point& position) const
904 if (__overlayBitmaps.size() <= 0)
909 Rectangle bitmapBounds = __pProperty->GetItemBitmapBounds();
910 for (int i = __overlayBitmaps.size() - 1; i >= 0; i--)
912 _OverlayBitmap* pOverlayBitmap = __overlayBitmaps.at(i);
913 if (pOverlayBitmap != null)
915 int overlayMargin = __pProperty->GetOverlayMargin();
916 if (pOverlayBitmap->pBitmap != null)
918 Rectangle rect = GetOverlayBitmapBounds(pOverlayBitmap, bitmapBounds, overlayMargin);
919 if (rect.Contains(position))
921 return pOverlayBitmap->id;
931 _IconListItem::GetItemVisualElement(void) const
937 _IconListItem::GetOverlayBitmapBounds(_OverlayBitmap* pOverlayBitmap, const Rectangle& parentRect, int margin) const
939 int x = parentRect.x;
940 int y = parentRect.y;
941 int width = pOverlayBitmap->pBitmap->GetWidth();
942 int height = pOverlayBitmap->pBitmap->GetHeight();
944 switch (pOverlayBitmap->horizontalAlignment)
949 case ALIGNMENT_CENTER:
950 x += (parentRect.width - width) / 2;
952 case ALIGNMENT_RIGHT:
953 x += (parentRect.width - width - margin);
957 switch (pOverlayBitmap->verticalAlignment)
962 case ALIGNMENT_MIDDLE:
963 y += (parentRect.height - height) / 2;
965 case ALIGNMENT_BOTTOM:
966 y += (parentRect.height - height - margin);
970 return Rectangle(x, y, width, height);
973 }}} // Tizen::Ui::Controls