2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0/
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 <FUiAnimVisualElementPropertyAnimation.h>
27 #include <FUiCtrlIconListViewItem.h>
28 #include <FGrpCoordinateSystem.h>
29 #include <FGrp_BitmapImpl.h>
30 #include <FGrp_CanvasImpl.h>
31 #include <FGrp_TextTextObject.h>
32 #include <FGrp_TextTextSimple.h>
34 #include "FUi_CoordinateSystemUtils.h"
36 #include "FUiAnim_VisualElement.h"
37 #include "FUiCtrl_IconListItem.h"
38 #include "FUiCtrl_IconListItemDrawingProperty.h"
39 #include "FUiCtrl_IconListUtils.h"
41 using namespace Tizen::Base;
42 using namespace Tizen::Graphics;
43 using namespace Tizen::Graphics::_Text;
44 using namespace Tizen::Ui::Animations;
46 namespace Tizen { namespace Ui { namespace Controls
49 _IconListItem::_IconListItem(_VisualElement* pBase)
60 , __foreDrawnState(LIST_ITEM_STATE_NORMAL)
62 , __isAlradyDestory(false)
64 , __pAccessibilityElement(null)
66 __pBitmap[ICON_LIST_VIEW_ITEM_DRAWING_STATUS_NORMAL] = null;
67 __pBitmap[ICON_LIST_VIEW_ITEM_DRAWING_STATUS_PRESSED] = null;
68 __pBitmap[ICON_LIST_VIEW_ITEM_DRAWING_STATUS_HIGHLIGHTED] = null;
71 _IconListItem::~_IconListItem(void)
73 delete __pBitmap[ICON_LIST_VIEW_ITEM_DRAWING_STATUS_NORMAL];
74 __pBitmap[ICON_LIST_VIEW_ITEM_DRAWING_STATUS_NORMAL] = null;
76 delete __pBitmap[ICON_LIST_VIEW_ITEM_DRAWING_STATUS_PRESSED];
77 __pBitmap[ICON_LIST_VIEW_ITEM_DRAWING_STATUS_PRESSED] = null;
79 delete __pBitmap[ICON_LIST_VIEW_ITEM_DRAWING_STATUS_HIGHLIGHTED];
80 __pBitmap[ICON_LIST_VIEW_ITEM_DRAWING_STATUS_HIGHLIGHTED] = null;
89 __pBase->RemoveAllAnimations();
91 for (int i = 0, n = __overlayBitmaps.size() ; i < n ; i++)
93 _OverlayBitmap* pOverlayBitmap = __overlayBitmaps.at(i);
94 delete pOverlayBitmap->pBitmap;
95 pOverlayBitmap->pBitmap = null;
97 if (pOverlayBitmap->pVE != null)
99 __pBase->DetachChild(*(pOverlayBitmap->pVE));
100 pOverlayBitmap->pVE->Destroy();
101 pOverlayBitmap->pVE = null;
103 delete pOverlayBitmap;
106 if (__pTextVE != null)
108 __pBase->DetachChild(*__pTextVE);
109 __pTextVE->Destroy();
113 if (__pCheckVE != null)
115 __pBase->DetachChild(*__pCheckVE);
116 __pCheckVE->Destroy();
120 if (__pCheckBgVE != null)
122 __pBase->DetachChild(*__pCheckBgVE);
123 __pCheckBgVE->Destroy();
127 if (__pTouchAniVE!= null)
129 __pBase->DetachChild(*__pTouchAniVE);
130 __pTouchAniVE->Destroy();
131 __pTouchAniVE = null;
134 if (__pFocusVE!= null)
136 __pBase->DetachChild(*__pFocusVE);
137 __pFocusVE->Destroy();
141 VisualElement* pParent = __pBase->GetParent();
144 pParent->DetachChild(*__pBase);
150 __isAlradyDestory = true;
151 __overlayBitmaps.clear();
153 if (__pAccessibilityElement != null)
155 if (__pAccessibilityElement->GetParent() != null)
157 __pAccessibilityElement->GetParent()->RemoveElement(*__pAccessibilityElement);
159 __pAccessibilityElement = null;
164 _IconListItem::CreateIconListItemN(IconListViewItem* pIconListViewItem)
166 result r = E_SUCCESS;
167 _IconListItem* pItem = null;
168 _VisualElement* pBase = new (std::nothrow) _VisualElement;
169 SysTryReturn(NID_UI_CTRL, (pBase != null), null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
171 r = pBase->Construct();
172 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
176 pBase->SetSurfaceOpaque(false);
177 pBase->SetImplicitAnimationEnabled(false);
179 pItem = new (std::nothrow) _IconListItem(pBase);
180 SysTryCatch(NID_UI_CTRL, pItem != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
182 pItem->SetAppInfo(pIconListViewItem);
192 _IconListItem::DrawItem(FloatRectangle& rect, ListItemState isFocused, int itemIndex)
194 SysAssertf(__pProperty != null, "Not yet initialized. SetDrawingProperty() should be called before use.");
198 if (!__pBase->GetShowState())
200 __pBase->SetShowState(true);
203 __pBase->SetBounds(rect);
205 // Support Accessibility
206 if (__pProperty->IsAccessibilityEnabled())
208 SetItemAccessibilityElement(rect, itemIndex);
211 if (!__pProperty->IsChanged() && __isDrawn && __foreDrawnState == isFocused)
216 Canvas* pCanvas = __pBase->GetCanvasN(FloatRectangle(0.0f, 0.0f, rect.width, rect.height));
222 // Draw Background Color
223 IconListViewItemDrawingStatus status = _IconListUtils::EnumConverter::ConvertListItemStateToIconListViewItemDrawingStatus(isFocused);
224 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
227 float margin = __pProperty->GetSelectBackgroundMargin();
228 pCanvas->FillRectangle(__pProperty->GetBackgroundColor(status), FloatRectangle(margin, margin, rect.width - margin, rect.height - margin));
231 Bitmap* pBitmap = (__pBitmap[isFocused] != null) ? __pBitmap[isFocused] : __pBitmap[ICON_LIST_VIEW_ITEM_DRAWING_STATUS_NORMAL];
234 DrawBitmap(*pCanvas, *pBitmap);
238 DrawText(__pProperty->GetTextColor(status));
241 if (__pProperty->IsItemCheckedStyle())
246 // Draw Overlay Bitmap
247 if (__overlayBitmaps.size() > 0)
249 DrawOverlayBitmaps();
252 DrawBorder(*pCanvas, (status == ICON_LIST_VIEW_ITEM_DRAWING_STATUS_HIGHLIGHTED));
254 __pBase->SetFlushNeeded();
256 __foreDrawnState = isFocused;
263 _IconListItem::DrawItemTouchAnimation(FloatRectangle& rect, float ratio)
265 SysAssertf(__pProperty != null, "Not yet initialized. SetDrawingProperty() should be called before use.");
267 __pBase->SetBounds(rect);
269 if (!__pBase->GetShowState())
271 __pBase->SetShowState(true);
274 Canvas* pCanvas = __pBase->GetCanvasN(FloatRectangle(0.0f, 0.0f, rect.width, rect.height));
277 result r = GetLastResult();
278 SysLogException(NID_UI_CTRL, r, "[%s] Propagating.", GetErrorMessage(r));
282 pCanvas->SetBackgroundColor(__pProperty->GetBackgroundColor(ICON_LIST_VIEW_ITEM_DRAWING_STATUS_NORMAL));
286 Bitmap* pBitmap = __pBitmap[ICON_LIST_VIEW_ITEM_DRAWING_STATUS_NORMAL];
289 DrawBitmap(*pCanvas, *pBitmap, ratio);
293 DrawText(__pProperty->GetTextColor(ICON_LIST_VIEW_ITEM_DRAWING_STATUS_NORMAL));
296 if (__pProperty->IsItemCheckedStyle())
301 if (__overlayBitmaps.size() > 0)
303 DrawOverlayBitmaps();
313 _IconListItem::DrawItemCheckAnimation(FloatRectangle& rect, float ratio)
315 SysAssertf(__pProperty != null, "Not yet initialized. SetDrawingProperty() should be called before use.");
317 __pBase->SetBounds(rect);
319 if (!__pBase->GetShowState())
321 __pBase->SetShowState(true);
324 Canvas* pCanvas = __pBase->GetCanvasN(FloatRectangle(0.0f, 0.0f, rect.width, rect.height));
327 result r = GetLastResult();
328 SysLogException(NID_UI_CTRL, r, "[%s] Propagating.", GetErrorMessage(r));
332 pCanvas->SetBackgroundColor(__pProperty->GetBackgroundColor(ICON_LIST_VIEW_ITEM_DRAWING_STATUS_NORMAL));
336 Bitmap* pBitmap = __pBitmap[ICON_LIST_VIEW_ITEM_DRAWING_STATUS_NORMAL];
339 DrawBitmap(*pCanvas, *pBitmap);
343 DrawText(__pProperty->GetTextColor(ICON_LIST_VIEW_ITEM_DRAWING_STATUS_NORMAL));
346 if (__pProperty->IsItemCheckedStyle())
348 DrawCheck(*pCanvas, ratio);
351 if (__overlayBitmaps.size() > 0)
353 DrawOverlayBitmaps();
363 _IconListItem::DrawBitmap(Canvas& canvas, Bitmap& bitmap, float ratio)
365 FloatRectangle rect = __pProperty->GetItemBitmapBounds();
366 float borderWidth = __pProperty->GetDropShadowBorderWidth();
367 if (__pProperty->GetBorderStyle() == ICON_LIST_VIEW_ITEM_BORDER_STYLE_SHADOW || __pProperty->GetBorderStyle() == ICON_LIST_VIEW_ITEM_BORDER_STYLE_OUTLINE)
369 rect.x += CoordinateSystem::ConvertToLogicalX(1.0f);
370 rect.y += CoordinateSystem::ConvertToLogicalY(1.0f);
371 rect.width -= CoordinateSystem::ConvertToLogicalX(borderWidth);
372 rect.height -= CoordinateSystem::ConvertToLogicalY(borderWidth);
375 float width = rect.width;
376 float height = rect.height;
378 // Adjust Bitmap Ratio
379 if (__pProperty->IsItemBitmapAsAspectRatio())
381 width = bitmap.GetWidthF() * rect.height / bitmap.GetHeightF();
382 height = bitmap.GetHeightF() * rect.width / bitmap.GetWidthF();
383 if (!_FloatCompareLE(width, rect.width))
388 if (!_FloatCompareLE(height, rect.height))
390 height = rect.height;
394 // Resize & Set Alpha by Ratio(ratio < 1.0f)
395 if (!_FloatCompareGE(ratio, REFERENCE_FACTOR))
397 width = width * ratio;
398 height = height * ratio;
399 bitmap.SetAlphaConstant(OPAQUE_ALPHA * ratio);
403 rect.x += (rect.width - width) / 2.0f;
404 rect.y += (rect.height - height) / 2.0f;
405 rect.SetSize(width, height);
407 if (__pTouchAniVE == null)
409 __pTouchAniVE = new (std::nothrow) _VisualElement();
410 SysTryReturn(NID_UI_CTRL, __pTouchAniVE != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
412 result r = __pTouchAniVE->Construct();
413 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
415 __pTouchAniVE->SetRedrawOnResizeEnabled(false);
416 __pTouchAniVE->SetImplicitAnimationEnabled(false);
417 __pBase->AttachChild(*__pTouchAniVE);
419 __pTouchAniVE->SetBounds(FloatRectangle(rect.x, rect.y, width, height));
420 __pTouchAniVE->SetShowState(true);
422 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(bitmap))
424 Canvas* pCanvas = __pTouchAniVE->GetCanvasN();
425 SysTryReturn(NID_UI_CTRL, pCanvas != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
426 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
428 pCanvas->DrawNinePatchedBitmap(FloatRectangle(0.0f, 0.0f, bitmap.GetWidthF(), bitmap.GetHeightF()), bitmap);
433 String imagePath = _BitmapImpl::GetInstance(bitmap)->GetFileName();
435 if (!imagePath.IsEmpty())
437 __pTouchAniVE->SetImageSource(imagePath);
441 __pTouchAniVE->SetImageSource(L"");
442 Canvas* pCanvas = __pTouchAniVE->GetCanvasN();
443 SysTryReturn(NID_UI_CTRL, pCanvas != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
444 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
446 pCanvas->DrawBitmap(FloatRectangle(0.0f, 0.0f, width, height), bitmap);
451 if (!_FloatCompareGE(ratio, REFERENCE_FACTOR))
453 bitmap.SetAlphaConstant(OPAQUE_ALPHA);
460 _IconListItem::DrawText(const Color& color)
462 if (__text.IsEmpty())
467 if (__pTextObject == null)
469 __pTextObject = new (std::nothrow) TextObject;
470 wchar_t* pStr = const_cast <wchar_t*>(__text.GetPointer());
471 __pTextObject->Construct();
472 TextSimple* pSimpleText = new (std::nothrow)TextSimple(pStr, __text.GetLength(), TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
473 __pTextObject->AppendElement(*pSimpleText);
475 __pTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
479 switch (__pProperty->GetTextHorizontalAlignment())
482 __pTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_LEFT);
485 case ALIGNMENT_CENTER:
486 __pTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_CENTER);
489 case ALIGNMENT_RIGHT:
490 __pTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_RIGHT);
494 __pTextObject->SetForegroundColor(color, 0, __pTextObject->GetTextLength());
496 Font* pFont = __pProperty->GetFont();
497 SysTryReturn(NID_UI_CTRL, pFont != null, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
499 float textVerticalMargin = __pProperty->GetTextVerticalMargin();
500 float width = __pProperty->GetTextAreaWidth();
502 __pTextObject->SetFont(pFont, 0, __pTextObject->GetTextLength());
503 __pTextObject->SetWrap(TEXT_OBJECT_WRAP_TYPE_WORD);
504 __pTextObject->SetBounds(FloatRectangle(0.0f, 0.0f, width, 1.0f));
505 __pTextObject->Compose();
507 float height = __pTextObject->GetTotalHeightF();
508 float leading = _FontImpl::GetInstance((*pFont))->GetLeadingF();
509 float textYPos = __pProperty->GetTextYPosition();
510 if (_FloatCompareGE(height, leading * 2))
512 textYPos = __pProperty->GetTwoLineTextYPosition();
513 height = (leading + textVerticalMargin) * 2;
517 height += (textVerticalMargin * 2);
520 if (__pProperty->GetTextVerticalAlignment() == ICON_LIST_VIEW_ITEM_TEXT_VERTICAL_ALIGNMENT_INSIDE_BOTTOM)
522 FloatDimension itemSize = __pProperty->GetItemSize();
523 textYPos = itemSize.height - height - 1;
526 result r = GetLastResult();
527 FloatRectangle bounds(0.0f, 0.0f, width, height);
528 Canvas* pCanvas = null;
530 if (__pTextVE == null)
532 __pTextVE = new (std::nothrow) _VisualElement();
533 SysTryReturn(NID_UI_CTRL, __pTextVE != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
535 result r = __pTextVE->Construct();
536 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
538 __pTextVE->SetRedrawOnResizeEnabled(false);
539 __pTextVE->SetImplicitAnimationEnabled(false);
541 __pBase->AttachChild(*__pTextVE);
544 __pTextVE->SetBounds(FloatRectangle(__pProperty->GetTextXPosition(), textYPos, width, height));
545 __pTextVE->SetShowState(true);
547 pCanvas = __pTextVE->GetCanvasN();
548 SysTryReturn(NID_UI_CTRL, pCanvas != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
550 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
552 pCanvas->FillRectangle(__pProperty->GetTextBackgroundColor(), bounds);
554 __pTextObject->SetBounds(bounds);
555 __pTextObject->Draw(*_CanvasImpl::GetInstance(*pCanvas));
561 __pTextVE->Destroy();
568 _IconListItem::DrawCheck(Canvas& canvas, float ratio)
570 const Bitmap* pBackgroundBitmap = null;
571 const Bitmap* pBitmap = null;
572 pBitmap = IsChecked() ? __pProperty->GetCheckBitmap() : null;
573 pBackgroundBitmap = IsItemEnabled() ? (IsChecked() ? __pProperty->GetCheckedBackgroundBitmap() : __pProperty->GetUnCheckedBackgroundBitmap()) : __pProperty->GetDisabledCheckBitmap();
575 if (pBackgroundBitmap == null)
580 float width = pBackgroundBitmap->GetWidthF();
581 float height = pBackgroundBitmap->GetHeightF();
582 float checkMargin = __pProperty->GetCheckMargin();
584 FloatRectangle bitmapBounds = __pProperty->GetItemBitmapBounds();
585 FloatPoint checkPosition(0.0f, 0.0f);
586 switch (__pProperty->GetCheckBoxPosition())
588 case ICON_LIST_VIEW_CHECK_BOX_POSITION_TOP_LEFT:
589 checkPosition.x += checkMargin;
590 checkPosition.y += checkMargin;
593 case ICON_LIST_VIEW_CHECK_BOX_POSITION_TOP_RIGHT:
594 checkPosition.x += bitmapBounds.width - checkMargin - width;
595 checkPosition.y += checkMargin;
598 case ICON_LIST_VIEW_CHECK_BOX_POSITION_BOTTOM_LEFT:
599 checkPosition.x += checkMargin;
600 checkPosition.y += bitmapBounds.height - checkMargin - height;
603 case ICON_LIST_VIEW_CHECK_BOX_POSITION_BOTTOM_RIGHT:
604 checkPosition.x += bitmapBounds.width - checkMargin - width;
605 checkPosition.y += bitmapBounds.height - checkMargin - height;
609 if (__pCheckBgVE == null)
611 __pCheckBgVE = new (std::nothrow) _VisualElement();
612 SysTryReturn(NID_UI_CTRL, __pCheckBgVE != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
614 result r = __pCheckBgVE->Construct();
615 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
617 __pCheckBgVE->SetRedrawOnResizeEnabled(false);
618 __pCheckBgVE->SetImplicitAnimationEnabled(false);
619 __pBase->AttachChild(*__pCheckBgVE);
620 __pCheckBgVE->SetBounds(FloatRectangle(checkPosition.x, checkPosition.y, width, height));
621 __pCheckBgVE->SetShowState(true);
624 Canvas* pCheckBgCanvas = __pCheckBgVE->GetCanvasN();
625 SysTryReturn(NID_UI_CTRL, pCheckBgCanvas != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
627 pCheckBgCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
628 pCheckBgCanvas->Clear();
630 // draw background of check box
631 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pBackgroundBitmap))
633 pCheckBgCanvas->DrawNinePatchedBitmap(FloatRectangle(0.0f, 0.0f, width, height), *pBackgroundBitmap);
637 pCheckBgCanvas->DrawBitmap(FloatRectangle(0.0f, 0.0f, width, height), *pBackgroundBitmap);
641 if (__pCheckVE == null)
643 __pCheckVE = new (std::nothrow) _VisualElement();
644 SysTryReturn(NID_UI_CTRL, __pCheckVE != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
646 result r = __pCheckVE->Construct();
647 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
649 __pCheckVE->SetRedrawOnResizeEnabled(false);
650 __pCheckVE->SetImplicitAnimationEnabled(false);
651 __pBase->AttachChild(*__pCheckVE);
653 __pCheckVE->SetBounds(FloatRectangle(checkPosition.x, checkPosition.y, width, height));
654 __pCheckVE->SetShowState(true);
657 Canvas* pCanvas = __pCheckVE->GetCanvasN();
658 SysTryReturn(NID_UI_CTRL, pCanvas != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
660 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
665 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pBitmap))
667 pCanvas->DrawNinePatchedBitmap(FloatRectangle(0.0f, 0.0f, pBitmap->GetWidthF(), pBitmap->GetHeightF()), *pBitmap);
671 pCanvas->DrawBitmap(FloatRectangle(0.0f, 0.0f, pBitmap->GetWidthF() * ratio, pBitmap->GetHeightF()), *pBitmap, FloatRectangle(0.0f, 0.0f, pBitmap->GetWidthF() * ratio, pBitmap->GetHeightF()));
675 delete pCheckBgCanvas;
682 _IconListItem::DrawOverlayBitmaps(void)
684 result r = E_SUCCESS;
685 FloatRectangle bitmapBounds = __pProperty->GetItemBitmapBounds();
686 Canvas* pCanvas = null;
687 for (int i = 0, n = __overlayBitmaps.size(); i < n; i++)
689 _OverlayBitmap* pOverlayBitmap = __overlayBitmaps.at(i);
690 float overlayMargin = __pProperty->GetOverlayMargin();
691 if (pOverlayBitmap->pBitmap != null)
693 FloatRectangle overlayBitmapBounds = GetOverlayBitmapBounds(pOverlayBitmap, bitmapBounds, overlayMargin);
695 _VisualElement* pVE = null;
696 if (pOverlayBitmap->pVE == null)
698 pVE = new (std::nothrow) _VisualElement();
699 SysTryReturn(NID_UI_CTRL, pVE != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
701 r = pVE->Construct();
702 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
704 pVE->SetRedrawOnResizeEnabled(false);
705 pVE->SetImplicitAnimationEnabled(false);
707 __pBase->AttachChild(*pVE);
708 pOverlayBitmap->pVE = pVE;
712 pVE = pOverlayBitmap->pVE;
715 pVE->SetBounds(overlayBitmapBounds);
716 pVE->SetShowState(true);
718 pCanvas = pVE->GetCanvasN();
719 SysTryReturn(NID_UI_CTRL, pCanvas != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
721 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
724 overlayBitmapBounds.SetPosition(0.0f, 0.0f);
725 Bitmap* pBitmap = pOverlayBitmap->pBitmap;
726 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pBitmap))
728 pCanvas->DrawNinePatchedBitmap(overlayBitmapBounds, *pBitmap);
732 pCanvas->DrawBitmap(overlayBitmapBounds, *pBitmap);
741 _IconListItem::DrawBorder(Tizen::Graphics::Canvas& canvas, bool isFocused)
743 if (__pFocusVE == null)
745 __pFocusVE = new (std::nothrow) _VisualElement();
746 SysTryReturn(NID_UI_CTRL, __pFocusVE != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
748 result r = __pFocusVE->Construct();
749 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
751 __pFocusVE->SetRedrawOnResizeEnabled(false);
752 __pFocusVE->SetImplicitAnimationEnabled(false);
753 __pBase->AttachChild(*__pFocusVE);
755 FloatRectangle focusUiBounds = __pProperty->GetItemBitmapBounds();
756 __pFocusVE->SetBounds(FloatRectangle(focusUiBounds.x, focusUiBounds.y, focusUiBounds.width, focusUiBounds.height));
761 Canvas* pCanvas = __pFocusVE->GetCanvasN();
762 SysTryReturn(NID_UI_CTRL, pCanvas != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
764 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
767 const Bitmap* pShadowBitmap = __pProperty->GetFocusBitmap();
769 if (pShadowBitmap != null)
771 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pShadowBitmap))
773 pCanvas->DrawNinePatchedBitmap(__pProperty->GetDropShadowBitmapBounds(), *pShadowBitmap);
777 pCanvas->DrawBitmap(__pProperty->GetDropShadowBitmapBounds(), *pShadowBitmap);
779 __pFocusVE->SetShowState(true);
785 switch (__pProperty->GetBorderStyle())
787 case ICON_LIST_VIEW_ITEM_BORDER_STYLE_NONE:
790 case ICON_LIST_VIEW_ITEM_BORDER_STYLE_OUTLINE:
793 canvas.SetForegroundColor(__pProperty->GetBorderColor(isFocused));
794 canvas.SetLineWidth(1.0f);
795 FloatDimension dim = __pProperty->GetItemSize();
796 canvas.DrawRectangle(FloatRectangle(0.0f, 0.0f, dim.width, dim.height));
800 case ICON_LIST_VIEW_ITEM_BORDER_STYLE_SHADOW:
802 // Draw Drop-Shadow Effect
803 if (__pProperty->GetDropShadowBitmap() != null)
805 const Bitmap* pShadowBitmap = __pProperty->GetDropShadowBitmap();
806 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pShadowBitmap))
808 canvas.DrawNinePatchedBitmap(__pProperty->GetDropShadowBitmapBounds(), *pShadowBitmap);
812 canvas.DrawBitmap(__pProperty->GetDropShadowBitmapBounds(), *pShadowBitmap);
818 __pFocusVE->SetShowState(false);
824 _IconListItem::SetText(const String* pText)
828 __text = String(L"");
839 _IconListItem::GetText(void) const
845 _IconListItem::SetBitmap(IconListViewItemDrawingStatus status, const Bitmap* pBitmap)
847 if (ICON_LIST_VIEW_ITEM_DRAWING_STATUS_NORMAL > status || ICON_LIST_VIEW_ITEM_DRAWING_STATUS_HIGHLIGHTED < status)
849 SysLogException(NID_UI_CTRL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used.");
850 return E_INVALID_ARG;
853 SysTryReturn(NID_UI_CTRL, (status != ICON_LIST_VIEW_ITEM_DRAWING_STATUS_NORMAL || pBitmap != null), E_INVALID_ARG,
854 E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. The normal bitmap must not be null.");
856 result r = E_SUCCESS;
857 Bitmap* pCopiedBitmap = null;
860 pCopiedBitmap = _BitmapImpl::CloneN(*pBitmap);
866 delete __pBitmap[status];
867 __pBitmap[status] = pCopiedBitmap;
871 delete pCopiedBitmap;
880 _IconListItem::GetBitmap(IconListViewItemDrawingStatus status) const
882 SysTryReturn(NID_UI_CTRL,
883 (status > ICON_LIST_VIEW_ITEM_DRAWING_STATUS_NORMAL && status < ICON_LIST_VIEW_ITEM_DRAWING_STATUS_HIGHLIGHTED),
884 null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used.");
886 SetLastResult(E_SUCCESS);
887 return __pBitmap[status];
891 _IconListItem::GetVisualElement(void) const
897 _IconListItem::ClearVisualElement(void)
903 _IconListItem::SetDrawingProperty(_IconListItemDrawingProperty& property)
905 __pProperty = &property;
911 _IconListItem::SetChecked(bool checked)
913 if (IsChecked() == checked)
918 _ListItemCommon::SetChecked(checked);
923 _IconListItem::SetItemIndex(int groupIndex, int itemIndex)
925 __itemIndex = itemIndex;
929 _IconListItem::GetItemIndex(int& groupIndex, int& itemIndex) const
931 groupIndex = DEFAULT_GROUP_INDEX;
932 itemIndex = __itemIndex;
936 _IconListItem::SetOverlayBitmap(int overlayBitmapId, const Bitmap* pOverlayBitmap, HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment)
938 result r = E_SUCCESS;
940 SysTryReturn(NID_UI_CTRL, horizontalAlignment >= ALIGNMENT_LEFT && horizontalAlignment <= ALIGNMENT_RIGHT, E_INVALID_ARG,
941 E_INVALID_ARG, "[E_INVALID_ARG] The horizontal alignment is inappropriate.");
942 SysTryReturn(NID_UI_CTRL, verticalAlignment >= ALIGNMENT_TOP && verticalAlignment <= ALIGNMENT_BOTTOM, E_INVALID_ARG,
943 E_INVALID_ARG, "[E_INVALID_ARG] The vertical alignment is inappropriate.");
946 Bitmap* pCopiedBitmap = null;
947 for (int i = 0, n = __overlayBitmaps.size() ; i < n; i++)
949 _OverlayBitmap* pCurrentOverlayBitmap = __overlayBitmaps.at(i);
950 if (pCurrentOverlayBitmap->horizontalAlignment == horizontalAlignment && pCurrentOverlayBitmap->verticalAlignment == verticalAlignment)
953 if (pOverlayBitmap == null)
955 // delete overlay bitmap
956 delete pCurrentOverlayBitmap->pBitmap;
957 pCurrentOverlayBitmap->pBitmap = null;
959 if (pCurrentOverlayBitmap->pVE != null)
961 pCurrentOverlayBitmap->pVE->Destroy();
962 pCurrentOverlayBitmap->pVE = null;
964 __overlayBitmaps.erase(__overlayBitmaps.begin() + i);
965 delete pCurrentOverlayBitmap;
969 // replace overlay bitmap
970 pCopiedBitmap = null;
971 pCopiedBitmap = _BitmapImpl::CloneN(*pOverlayBitmap);
976 delete pCurrentOverlayBitmap->pBitmap;
977 pCurrentOverlayBitmap->pBitmap = pCopiedBitmap;
978 pCurrentOverlayBitmap->id = overlayBitmapId;
987 if (pOverlayBitmap != null)
989 // add overlay bitmap
990 pCopiedBitmap = null;
991 pCopiedBitmap = _BitmapImpl::CloneN(*pOverlayBitmap);
993 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
995 _OverlayBitmap* pNewOverlayBitmap = new (std::nothrow) _OverlayBitmap();
996 pNewOverlayBitmap->id = overlayBitmapId;
997 pNewOverlayBitmap->pBitmap = pCopiedBitmap;
998 pNewOverlayBitmap->horizontalAlignment = horizontalAlignment;
999 pNewOverlayBitmap->verticalAlignment = verticalAlignment;
1000 pNewOverlayBitmap->pVE = null;
1002 __overlayBitmaps.push_back(pNewOverlayBitmap);
1011 _IconListItem::GetOverlayBitmapIdFromPosition(FloatPoint& position) const
1013 if (__overlayBitmaps.size() <= 0)
1018 FloatRectangle bitmapBounds = __pProperty->GetItemBitmapBounds();
1019 for (int i = __overlayBitmaps.size() - 1; i >= 0; i--)
1021 _OverlayBitmap* pOverlayBitmap = __overlayBitmaps.at(i);
1022 if (pOverlayBitmap != null)
1024 float overlayMargin = __pProperty->GetOverlayMargin();
1025 if (pOverlayBitmap->pBitmap != null)
1027 FloatRectangle rect = GetOverlayBitmapBounds(pOverlayBitmap, bitmapBounds, overlayMargin);
1028 if (rect.Contains(position))
1030 return pOverlayBitmap->id;
1039 _IconListItem::GetItemVisualElement(void) const
1044 _AccessibilityElement*
1045 _IconListItem::SetItemAccessibilityElement(FloatRectangle& rect, int itemIndex, const _AccessibilityElement& pElement, bool swapElement)
1047 if (__pAccessibilityElement == null)
1049 __pAccessibilityElement = new (std::nothrow) _AccessibilityElement(true);
1050 SysTryReturn(NID_UI_CTRL, __pAccessibilityElement != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1052 __pAccessibilityElement->SetTraitWithStringId("IDS_TPLATFORM_BODY_IMAGE");
1059 __pAccessibilityElement = const_cast<_AccessibilityElement*>(&pElement);
1062 __pAccessibilityElement->Activate(true);
1065 __pAccessibilityElement->SetValueWithStringId("IDS_TPLATFORM_BODY_SELECTED_T_TTS");
1067 __pAccessibilityElement->SetName(L"IconListViewItem" + Integer::ToString(itemIndex + 1));
1068 __pAccessibilityElement->SetLabel(GetText());
1070 if (__pAccessibilityElement->GetBounds() != rect)
1072 __pAccessibilityElement->SetBounds(rect);
1076 return __pAccessibilityElement;
1079 _AccessibilityElement*
1080 _IconListItem::GetItemAccessibilityElement(void)
1082 return __pAccessibilityElement;
1086 _IconListItem::GetOverlayBitmapBounds(_OverlayBitmap* pOverlayBitmap, const FloatRectangle& parentRect, float overlayMargin) const
1088 float x = parentRect.x;
1089 float y = parentRect.y;
1090 float width = pOverlayBitmap->pBitmap->GetWidthF();
1091 float height = pOverlayBitmap->pBitmap->GetHeightF();
1093 switch (pOverlayBitmap->horizontalAlignment)
1095 case ALIGNMENT_LEFT:
1098 case ALIGNMENT_CENTER:
1099 x += (parentRect.width - width) / 2;
1101 case ALIGNMENT_RIGHT:
1102 x += (parentRect.width - width - overlayMargin);
1106 switch (pOverlayBitmap->verticalAlignment)
1111 case ALIGNMENT_MIDDLE:
1112 y += (parentRect.height - height) / 2;
1114 case ALIGNMENT_BOTTOM:
1115 y += (parentRect.height - height - overlayMargin);
1119 return FloatRectangle(x, y, width, height);
1123 _IconListItem::IsDrawn(void) const
1128 Tizen::Ui::Animations::_VisualElement*
1129 _IconListItem::GetSelectAniVisualElement(void) const
1131 return __pTouchAniVE;
1134 Tizen::Ui::Animations::_VisualElement*
1135 _IconListItem::GetCheckAniVisualElement(void) const
1140 Tizen::Ui::Animations::_VisualElement*
1141 _IconListItem::GetCheckBGVisualElement(void) const
1143 return __pCheckBgVE;
1145 }}} // Tizen::Ui::Controls