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 if (__pProperty->GetFocusBitmap() != null)
769 const Bitmap* pShadowBitmap = __pProperty->GetFocusBitmap();
770 Color focusUiColor = __pProperty->GetBorderColor(isFocused);
772 pShadowBitmap = Tizen::Graphics::_BitmapImpl::GetColorReplacedBitmapN(*pShadowBitmap, Color::GetColor(COLOR_ID_MAGENTA), focusUiColor);
773 SysTryReturn(NID_UI_CTRL, pShadowBitmap != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
775 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pShadowBitmap))
777 pCanvas->DrawNinePatchedBitmap(__pProperty->GetDropShadowBitmapBounds(), *pShadowBitmap);
781 pCanvas->DrawBitmap(__pProperty->GetDropShadowBitmapBounds(), *pShadowBitmap);
783 __pFocusVE->SetShowState(true);
784 delete pShadowBitmap;
790 switch (__pProperty->GetBorderStyle())
792 case ICON_LIST_VIEW_ITEM_BORDER_STYLE_NONE:
795 case ICON_LIST_VIEW_ITEM_BORDER_STYLE_OUTLINE:
798 canvas.SetForegroundColor(__pProperty->GetBorderColor(isFocused));
799 canvas.SetLineWidth(1.0f);
800 FloatDimension dim = __pProperty->GetItemSize();
801 canvas.DrawRectangle(FloatRectangle(0.0f, 0.0f, dim.width, dim.height));
805 case ICON_LIST_VIEW_ITEM_BORDER_STYLE_SHADOW:
807 // Draw Drop-Shadow Effect
808 if (__pProperty->GetDropShadowBitmap() != null)
810 const Bitmap* pShadowBitmap = __pProperty->GetDropShadowBitmap();
811 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pShadowBitmap))
813 canvas.DrawNinePatchedBitmap(__pProperty->GetDropShadowBitmapBounds(), *pShadowBitmap);
817 canvas.DrawBitmap(__pProperty->GetDropShadowBitmapBounds(), *pShadowBitmap);
823 __pFocusVE->SetShowState(false);
829 _IconListItem::SetText(const String* pText)
833 __text = String(L"");
844 _IconListItem::GetText(void) const
850 _IconListItem::SetBitmap(IconListViewItemDrawingStatus status, const Bitmap* pBitmap)
852 if (ICON_LIST_VIEW_ITEM_DRAWING_STATUS_NORMAL > status || ICON_LIST_VIEW_ITEM_DRAWING_STATUS_HIGHLIGHTED < status)
854 SysLogException(NID_UI_CTRL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used.");
855 return E_INVALID_ARG;
858 SysTryReturn(NID_UI_CTRL, (status != ICON_LIST_VIEW_ITEM_DRAWING_STATUS_NORMAL || pBitmap != null), E_INVALID_ARG,
859 E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. The normal bitmap must not be null.");
861 result r = E_SUCCESS;
862 Bitmap* pCopiedBitmap = null;
865 pCopiedBitmap = _BitmapImpl::CloneN(*pBitmap);
871 delete __pBitmap[status];
872 __pBitmap[status] = pCopiedBitmap;
881 _IconListItem::GetBitmap(IconListViewItemDrawingStatus status) const
883 SysTryReturn(NID_UI_CTRL,
884 (status > ICON_LIST_VIEW_ITEM_DRAWING_STATUS_NORMAL && status < ICON_LIST_VIEW_ITEM_DRAWING_STATUS_HIGHLIGHTED),
885 null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used.");
887 SetLastResult(E_SUCCESS);
888 return __pBitmap[status];
892 _IconListItem::GetVisualElement(void) const
898 _IconListItem::ClearVisualElement(void)
904 _IconListItem::SetDrawingProperty(_IconListItemDrawingProperty& property)
906 __pProperty = &property;
912 _IconListItem::SetChecked(bool checked)
914 if (IsChecked() == checked)
919 _ListItemCommon::SetChecked(checked);
924 _IconListItem::SetItemIndex(int groupIndex, int itemIndex)
926 __itemIndex = itemIndex;
930 _IconListItem::GetItemIndex(int& groupIndex, int& itemIndex) const
932 groupIndex = DEFAULT_GROUP_INDEX;
933 itemIndex = __itemIndex;
937 _IconListItem::SetOverlayBitmap(int overlayBitmapId, const Bitmap* pOverlayBitmap, HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment)
939 result r = E_SUCCESS;
941 SysTryReturn(NID_UI_CTRL, horizontalAlignment >= ALIGNMENT_LEFT && horizontalAlignment <= ALIGNMENT_RIGHT, E_INVALID_ARG,
942 E_INVALID_ARG, "[E_INVALID_ARG] The horizontal alignment is inappropriate.");
943 SysTryReturn(NID_UI_CTRL, verticalAlignment >= ALIGNMENT_TOP && verticalAlignment <= ALIGNMENT_BOTTOM, E_INVALID_ARG,
944 E_INVALID_ARG, "[E_INVALID_ARG] The vertical alignment is inappropriate.");
947 Bitmap* pCopiedBitmap = null;
948 for (int i = 0, n = __overlayBitmaps.size() ; i < n; i++)
950 _OverlayBitmap* pCurrentOverlayBitmap = __overlayBitmaps.at(i);
951 if (pCurrentOverlayBitmap->horizontalAlignment == horizontalAlignment && pCurrentOverlayBitmap->verticalAlignment == verticalAlignment)
954 if (pOverlayBitmap == null)
956 // delete overlay bitmap
957 delete pCurrentOverlayBitmap->pBitmap;
958 pCurrentOverlayBitmap->pBitmap = null;
960 if (pCurrentOverlayBitmap->pVE != null)
962 pCurrentOverlayBitmap->pVE->Destroy();
963 pCurrentOverlayBitmap->pVE = null;
965 __overlayBitmaps.erase(__overlayBitmaps.begin() + i);
966 delete pCurrentOverlayBitmap;
970 // replace overlay bitmap
971 pCopiedBitmap = null;
972 pCopiedBitmap = _BitmapImpl::CloneN(*pOverlayBitmap);
977 delete pCurrentOverlayBitmap->pBitmap;
978 pCurrentOverlayBitmap->pBitmap = pCopiedBitmap;
979 pCurrentOverlayBitmap->id = overlayBitmapId;
988 if (pOverlayBitmap != null)
990 // add overlay bitmap
991 pCopiedBitmap = null;
992 pCopiedBitmap = _BitmapImpl::CloneN(*pOverlayBitmap);
994 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
996 _OverlayBitmap* pNewOverlayBitmap = new (std::nothrow) _OverlayBitmap();
997 pNewOverlayBitmap->id = overlayBitmapId;
998 pNewOverlayBitmap->pBitmap = pCopiedBitmap;
999 pNewOverlayBitmap->horizontalAlignment = horizontalAlignment;
1000 pNewOverlayBitmap->verticalAlignment = verticalAlignment;
1001 pNewOverlayBitmap->pVE = null;
1003 __overlayBitmaps.push_back(pNewOverlayBitmap);
1012 _IconListItem::GetOverlayBitmapIdFromPosition(FloatPoint& position) const
1014 if (__overlayBitmaps.size() <= 0)
1019 FloatRectangle bitmapBounds = __pProperty->GetItemBitmapBounds();
1020 for (int i = __overlayBitmaps.size() - 1; i >= 0; i--)
1022 _OverlayBitmap* pOverlayBitmap = __overlayBitmaps.at(i);
1023 if (pOverlayBitmap != null)
1025 float overlayMargin = __pProperty->GetOverlayMargin();
1026 if (pOverlayBitmap->pBitmap != null)
1028 FloatRectangle rect = GetOverlayBitmapBounds(pOverlayBitmap, bitmapBounds, overlayMargin);
1029 if (rect.Contains(position))
1031 return pOverlayBitmap->id;
1040 _IconListItem::GetItemVisualElement(void) const
1045 _AccessibilityElement*
1046 _IconListItem::SetItemAccessibilityElement(FloatRectangle& rect, int itemIndex, const _AccessibilityElement& pElement, bool swapElement)
1048 if (__pAccessibilityElement == null)
1050 __pAccessibilityElement = new (std::nothrow) _AccessibilityElement(true);
1051 SysTryReturn(NID_UI_CTRL, __pAccessibilityElement != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1053 __pAccessibilityElement->SetTraitWithStringId("IDS_TPLATFORM_BODY_IMAGE");
1060 __pAccessibilityElement = const_cast<_AccessibilityElement*>(&pElement);
1063 __pAccessibilityElement->Activate(true);
1066 __pAccessibilityElement->SetValueWithStringId("IDS_TPLATFORM_BODY_SELECTED_T_TTS");
1068 __pAccessibilityElement->SetName(L"IconListViewItem" + Integer::ToString(itemIndex + 1));
1069 __pAccessibilityElement->SetLabel(GetText());
1071 if (__pAccessibilityElement->GetBounds() != rect)
1073 __pAccessibilityElement->SetBounds(rect);
1077 return __pAccessibilityElement;
1080 _AccessibilityElement*
1081 _IconListItem::GetItemAccessibilityElement(void)
1083 return __pAccessibilityElement;
1087 _IconListItem::GetOverlayBitmapBounds(_OverlayBitmap* pOverlayBitmap, const FloatRectangle& parentRect, float overlayMargin) const
1089 float x = parentRect.x;
1090 float y = parentRect.y;
1091 float width = pOverlayBitmap->pBitmap->GetWidthF();
1092 float height = pOverlayBitmap->pBitmap->GetHeightF();
1094 switch (pOverlayBitmap->horizontalAlignment)
1096 case ALIGNMENT_LEFT:
1099 case ALIGNMENT_CENTER:
1100 x += (parentRect.width - width) / 2;
1102 case ALIGNMENT_RIGHT:
1103 x += (parentRect.width - width - overlayMargin);
1107 switch (pOverlayBitmap->verticalAlignment)
1112 case ALIGNMENT_MIDDLE:
1113 y += (parentRect.height - height) / 2;
1115 case ALIGNMENT_BOTTOM:
1116 y += (parentRect.height - height - overlayMargin);
1120 return FloatRectangle(x, y, width, height);
1124 _IconListItem::IsDrawn(void) const
1129 Tizen::Ui::Animations::_VisualElement*
1130 _IconListItem::GetSelectAniVisualElement(void) const
1132 return __pTouchAniVE;
1135 Tizen::Ui::Animations::_VisualElement*
1136 _IconListItem::GetCheckAniVisualElement(void) const
1141 Tizen::Ui::Animations::_VisualElement*
1142 _IconListItem::GetCheckBGVisualElement(void) const
1144 return __pCheckBgVE;
1146 }}} // Tizen::Ui::Controls