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_IconListPresenter.cpp
20 * @brief This is the implementation file for the _IconListPresenter class.
24 #include <FBaseSysLog.h>
25 #include <FGrpCanvas.h>
26 #include <FUiAnimVisualElementPropertyAnimation.h>
27 #include <FUiCtrlIIconListViewItemProvider.h>
28 #include <FGrp_BitmapImpl.h>
29 #include <FGrp_CanvasImpl.h>
30 #include <FGrp_TextTextSimple.h>
32 #include "FUi_AccessibilityElement.h"
33 #include "FUi_AccessibilityManager.h"
34 #include "FUi_CoordinateSystemUtils.h"
36 #include "FUi_ResourceManager.h"
37 #include "FUi_UiTouchEvent.h"
38 #include "FUiAnim_VisualElement.h"
39 #include "FUiCtrl_IconListItem.h"
40 #include "FUiCtrl_IconListItemDrawingProperty.h"
41 #include "FUiCtrl_IconListItemProviderAdaptor.h"
42 #include "FUiCtrl_IconListPresenter.h"
43 #include "FUiCtrl_IconListView.h"
44 #include "FUiCtrl_IconListViewItemEvent.h"
45 #include "FUiCtrl_ListViewModel.h"
46 #include "FUiCtrl_Scroll.h"
47 #include "FUiCtrl_UiIconListItemEvent.h"
48 #include "FUiCtrl_UiScrollEvent.h"
49 #include "FUiCtrl_UiScrollEventArg.h"
51 using namespace Tizen::Base;
52 using namespace Tizen::Base::Collection;
53 using namespace Tizen::Base::Runtime;
54 using namespace Tizen::Base::Utility;
55 using namespace Tizen::Graphics;
56 using namespace Tizen::Graphics::_Text;
57 using namespace Tizen::Ui::Animations;
60 const int SCROLL_PANEL_FIXED_FLICK_AMOUNT = 1000;
63 namespace Tizen { namespace Ui { namespace Controls
66 _IconListPresenter::_IconListPresenter(_IconListView* pIconListView, _ListViewModel* pListModel)
67 : __pListModel(pListModel)
68 , __pIconListView(pIconListView)
69 , __pItemProviderAdaptor(null)
70 , __backgroundColor(0)
71 , __currentTouchInfo()
72 , __selectedOverlayBitmapId(-1)
73 , __selectedIndex(INVALID_INDEX)
74 , __checkedIndex(INVALID_INDEX)
75 , __previousIndex(INVALID_INDEX)
76 , __previousCheckIndex(INVALID_INDEX)
77 , __highlightedIndex(INVALID_INDEX)
78 , __firstDrawnIndex(INVALID_INDEX)
79 , __lastDrawnIndex(INVALID_INDEX)
80 , __scrollDirection(ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL)
82 , __bottomMargin(0.0f)
85 , __horizontalSpacing(0.0f)
86 , __verticalSpacing(0.0f)
87 , __magneticScrollSize(0)
88 , __itemCountPerAxis(0)
89 , __itemHorizontalAlignment(ALIGNMENT_LEFT)
90 , __itemVerticalAlignment(ALIGNMENT_TOP)
91 , __scrollPosition(0.0f)
92 , __unitScrollLength(0.0f)
93 , __scrollLength(0.0f)
94 , __unitLengthOfAxis(0.0f)
95 , __startPosOfAxis(0.0f)
96 , __endPosOfAxis(0.0f)
97 , __checkedRadioIndex(INVALID_INDEX)
98 , __isItemChecked(false)
99 , __pItemDrawingProperty(null)
100 , __pTouchActionTimer(null)
101 , __pMagneticScrollTimer(null)
102 , __pAnimationTimer(null)
103 , __magneticScrollAnimation()
104 , __isTouchAnimationEnabled(true)
105 , __previousTouchAnimatinEnabled(true)
106 , __isLayoutChanged(true)
107 , __isTouchPressed(false)
109 , __requireNextDrawing(false)
110 , __alreadyDrawn(false)
111 , __enableCustomItemProviderAdaptor(false)
112 , __listStatusChanged(false)
113 , __needBaseCanvas(false)
114 , __isSelectionDelayed(false)
115 , __isCheckAnimationRunning(false)
116 , __isSelectAnimationRunning(false)
117 , __pPreviousAnimationVE(null)
118 , __pRemoveItemVE(null)
119 , __pEmptyListVE(null)
121 , __pSelectAnimationVE(null)
122 , __pCheckAnimationVE(null)
123 , __pPreviousSelectAnimationVE(null)
124 , __pPreviousCheckAnimationVE(null)
125 , __onReordering(false)
126 , __reorderFromIndex(INVALID_INDEX)
127 , __reorderToIndex(INVALID_INDEX)
128 , __lastReorderedPosition(-1.0f, -1.0f)
129 , __lastReorderedDifferences(0.0f, 0.0f)
130 , __reorderItemBounds(0.0f, 0.0f, 0.0f, 0.0f)
131 , __pReorderScrollTimer(null)
132 , __reorderScrollAnimationDistance(0.0f)
133 , __scrollPositionBeforeScrollAnimation(0.0f)
134 , __flickRunning(false)
135 , __animationItemIndex(INVALID_INDEX)
136 , __previousAnimationItemIndex(INVALID_INDEX)
137 , __addTransactionId(0)
138 , __removeTransactionId(0)
139 , __moveTransactionId(0)
140 , __firstTouchMove(true)
141 , __firstTouchMoveDirection(ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL)
145 _IconListPresenter::~_IconListPresenter(void)
151 _IconListPresenter::CreateInstanceN(_IconListView& pIconListView)
153 _IconListPresenter* pIconListPresenter = null;
154 _IconListItemDrawingProperty* pItemDrawingProperty = null;
157 _ListViewModel* pListModel = new (std::nothrow) _ListViewModel;
158 SysTryCatch(NID_UI_CTRL, (pListModel != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
160 // Create _IconListPresenter
161 pIconListPresenter = new (std::nothrow) _IconListPresenter(&pIconListView, pListModel);
162 SysTryCatch(NID_UI_CTRL, (pIconListPresenter != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
164 // Create _IconListItemDrawingProperty
165 pItemDrawingProperty = _IconListItemDrawingProperty::CreateInstanceN();
166 SysTryCatch(NID_UI_CTRL, (pItemDrawingProperty != null), , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
167 pIconListPresenter->__pItemDrawingProperty = pItemDrawingProperty;
169 // Initialize _IconListPresenter
170 pIconListPresenter->Initialize();
172 return pIconListPresenter;
176 delete pIconListPresenter;
182 _IconListPresenter::Dispose(void)
187 delete __pItemProviderAdaptor;
188 __pItemProviderAdaptor = null;
190 __pIconListView = null;
192 delete __pItemDrawingProperty;
193 __pItemDrawingProperty = null;
195 delete __pTouchActionTimer;
196 __pTouchActionTimer = null;
198 delete __pMagneticScrollTimer;
199 __pMagneticScrollTimer = null;
201 delete __pReorderScrollTimer;
202 __pReorderScrollTimer = null;
204 delete __pAnimationTimer;
205 __pAnimationTimer = null;
207 if (__pRemoveItemVE != null)
209 __pRemoveItemVE->Destroy();
210 __pRemoveItemVE = null;
213 if (__pEmptyListVE != null)
215 __pEmptyListVE->Destroy();
216 __pEmptyListVE = null;
223 _IconListPresenter::Initialize(void)
225 SetItemBorderStyle(ICON_LIST_VIEW_ITEM_BORDER_STYLE_NONE);
226 SetTextHorizontalAlignment(ALIGNMENT_CENTER);
227 SetTextVerticalAlignment(ICON_LIST_VIEW_ITEM_TEXT_VERTICAL_ALIGNMENT_INSIDE_BOTTOM);
228 SetItemBitmapAsAspectRatio(true);
229 SetCheckBoxPosition(ICON_LIST_VIEW_CHECK_BOX_POSITION_TOP_RIGHT);
231 __pVE = __pIconListView->GetVisualElement();
232 __pVE->SetClipChildrenEnabled(true);
233 __pVE->SetSurfaceOpaque(false);
239 _IconListPresenter::InitializeFont(void)
241 Font* pFont = __pIconListView->GetFallbackFont();
242 SysTryReturn(NID_UI_CTRL, (pFont != null), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
244 return __pItemDrawingProperty->SetFont(pFont);
248 _IconListPresenter::SetItemProvider(const IIconListViewItemProvider& provider)
250 _IconListItemProviderAdaptor* pAdaptor = static_cast <_IconListItemProviderAdaptor*>(__pListModel->GetItemProviderAdaptor());
252 if (pAdaptor == null)
254 RegisterItemProviderAdaptor(null);
255 pAdaptor = dynamic_cast <_IconListItemProviderAdaptor*>(__pItemProviderAdaptor);
256 SysTryReturn(NID_UI_CTRL, (pAdaptor != null), E_SYSTEM, E_SYSTEM, "[ESYSTEM] A system error has been occurred.");
261 __pListModel->RemoveAllItem();
265 pAdaptor->SetItemProvider(const_cast <IIconListViewItemProvider*>(&provider));
267 __isLayoutChanged = true;
268 __scrollPosition = 0.0f;
277 _IconListPresenter::RegisterItemProviderAdaptor(_IListItemProviderAdaptor* pItemProviderAdaptor)
280 __pListModel->RemoveAllItem();
281 __selectedIndex = INVALID_INDEX;
282 __highlightedIndex = INVALID_INDEX;
283 __isLayoutChanged = true;
284 __alreadyDrawn = false;
286 _IconListItemProviderAdaptor* pAdaptor = null;
287 bool enableCustomItemProviderAdaptor = true;
288 if (pItemProviderAdaptor == null)
290 // Create Default _IconListItemProviderAdaptor
291 pAdaptor = new (std::nothrow) _IconListItemProviderAdaptor;
292 SysTryReturn(NID_UI_CTRL, (pAdaptor != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
293 "[E_OUT_OF_MEMORY] Memory allocation failed.");
295 pAdaptor->SetVisualElement(__pIconListView->GetVisualElement());
296 enableCustomItemProviderAdaptor = false;
297 pItemProviderAdaptor = pAdaptor;
300 // Set _IconListItemProviderAdaptor
301 __pItemProviderAdaptor = null;
302 result r = __pListModel->RegisterItemProviderAdaptor(pItemProviderAdaptor);
303 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
305 if (enableCustomItemProviderAdaptor)
307 __pListModel->AddGroup(0, __pIconListView->GetStyle() == ICON_LIST_VIEW_STYLE_RADIO);
310 __pItemProviderAdaptor = pItemProviderAdaptor;
311 __enableCustomItemProviderAdaptor = enableCustomItemProviderAdaptor;
322 _IconListPresenter::SetScrollDirection(IconListViewScrollDirection scrollDirection)
324 SysTryReturn(NID_UI_CTRL,
325 (scrollDirection >= ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL && scrollDirection <= ICON_LIST_VIEW_SCROLL_DIRECTION_HORIZONTAL),
326 E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid scrollDirection is used.");
328 _ControlOrientation orientation = __pIconListView->GetOrientation();
329 float scrollBarWidth = 0.0f;
330 GET_SHAPE_CONFIG(ICONLIST::TOP_MARGIN, orientation, __topMargin);
331 GET_SHAPE_CONFIG(ICONLIST::BOTTOM_MARGIN, orientation, __bottomMargin);
332 GET_SHAPE_CONFIG(ICONLIST::LEFT_MARGIN, orientation, __leftMargin);
333 GET_SHAPE_CONFIG(ICONLIST::RIGHT_MARGIN, orientation, __rightMargin);
334 GET_SHAPE_CONFIG(ICONLIST::HORIZONTAL_SPACING, orientation, __horizontalSpacing);
335 GET_SHAPE_CONFIG(ICONLIST::VERTICAL_SPACING, orientation, __verticalSpacing);
337 __scrollDirection = scrollDirection;
338 FloatRectangle bounds = __pIconListView->GetBoundsF();
339 if (scrollDirection == ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL)
341 GET_SHAPE_CONFIG(SCROLL::VERTICAL_THUMB_MIN_WIDTH, orientation, scrollBarWidth);
342 SetItemLayoutHorizontalAlignment(ALIGNMENT_CENTER);
343 __pIconListView->SetScroll(FloatRectangle(bounds.width - scrollBarWidth, 0.0f, scrollBarWidth, bounds.height),
344 SCROLL_DIRECTION_VERTICAL);
348 GET_SHAPE_CONFIG(SCROLL::HORIZONTAL_THUMB_MIN_WIDTH, orientation, scrollBarWidth);
349 SetItemLayoutVerticalAlignment(ALIGNMENT_MIDDLE);
350 __pIconListView->SetScroll(FloatRectangle(0.0f, bounds.height - scrollBarWidth, bounds.width, scrollBarWidth),
351 SCROLL_DIRECTION_HORIZONTAL);
358 _IconListPresenter::SetMargin(MarginType type, float value)
360 SysTryReturn(NID_UI_CTRL, _FloatCompareGE(value, 0.0f), E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. The value must be non-negative value.");
364 case MARGIN_TYPE_TOP:
365 if (!_FloatCompare(__topMargin, value))
372 case MARGIN_TYPE_BOTTOM:
373 if (!_FloatCompare(__bottomMargin, value))
375 __bottomMargin = value;
380 case MARGIN_TYPE_LEFT:
381 if (!_FloatCompare(__leftMargin, value))
383 __leftMargin = value;
388 case MARGIN_TYPE_RIGHT:
389 if (!_FloatCompare(__rightMargin, value))
391 __rightMargin = value;
397 SysLogException(NID_UI_CTRL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used.");
398 return E_INVALID_ARG;
404 _IconListPresenter::GetMargin(MarginType type) const
409 case MARGIN_TYPE_TOP:
412 case MARGIN_TYPE_BOTTOM:
413 return __bottomMargin;
415 case MARGIN_TYPE_LEFT:
418 case MARGIN_TYPE_RIGHT:
419 return __rightMargin;
422 SysLogException(NID_UI_CTRL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used.");
428 _IconListPresenter::SetItemSpacing(float horizontalSpacing, float verticalSpacing)
430 SysTryReturn(NID_UI_CTRL, _FloatCompareGE(horizontalSpacing, 0.0f) && _FloatCompareGE(verticalSpacing, 0.0f), E_INVALID_ARG, E_INVALID_ARG,
431 "[E_INVALID_ARG] Invalid argument is used. The value must be non-negative value.");
433 if (!_FloatCompare(__horizontalSpacing, horizontalSpacing))
435 __horizontalSpacing = horizontalSpacing;
436 __isLayoutChanged = true;
439 if (!_FloatCompare(__verticalSpacing, verticalSpacing))
441 __verticalSpacing = verticalSpacing;
442 __isLayoutChanged = true;
445 if (__isLayoutChanged)
454 _IconListPresenter::GetItemHorizontalSpacing(void) const
457 return __horizontalSpacing;
461 _IconListPresenter::GetItemVerticalSpacing(void) const
464 return __verticalSpacing;
468 _IconListPresenter::SetUseCheckedStyle(bool checkedStyle)
470 __pItemDrawingProperty->SetItemCheckedStyle(checkedStyle);
474 _IconListPresenter::SetItemChecked(int index, bool check)
476 if (__pListModel->GetAllGroupCount() == 0)
478 SysTryReturn(NID_UI_CTRL, (__pItemProviderAdaptor != null), E_INVALID_STATE, E_INVALID_STATE,
479 "[E_INVALID_STATE] This instance isn't constructed.");
481 int itemCount = __pItemProviderAdaptor->GetItemCount();
487 SysTryReturn(NID_UI_CTRL, (index >= 0 && index < itemCount), E_OUT_OF_RANGE, E_OUT_OF_RANGE,
488 "[E_OUT_OF_RANGE] Index must be non-negative integer, and less count of whole items.");
491 result r = __pListModel->AddGroup(itemCount, __pIconListView->GetStyle() == ICON_LIST_VIEW_STYLE_RADIO);
492 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
496 SysTryReturn(NID_UI_CTRL, (index >= 0 && index < __pListModel->GetItemCountInGroup(DEFAULT_GROUP_INDEX)), E_OUT_OF_RANGE,
497 E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] Index must be non-negative integer, and less count of whole items.");
500 return __pListModel->SetItemChecked(DEFAULT_GROUP_INDEX, index, check);
504 _IconListPresenter::IsItemChecked(int index) const
507 return __pListModel->IsItemChecked(DEFAULT_GROUP_INDEX, index);
511 _IconListPresenter::GetItemIndexFromPosition(float x, float y) const
514 if (_FloatCompareLE(__unitLengthOfAxis, 0.0f) || _FloatCompareLE(__unitScrollLength, 0.0f))
527 if (__scrollDirection == ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL)
529 x -= __startPosOfAxis;
530 if (!_FloatCompareGE(x, 0.0f))
535 col = static_cast<int> (x / __unitLengthOfAxis);
536 if (col >= __itemCountPerAxis)
541 modX = x - (static_cast<int> (x / __unitLengthOfAxis) * __unitLengthOfAxis);
542 if (_FloatCompareGE(modX, GetItemSize().width))
547 y += __scrollPosition - __topMargin;
548 if (!_FloatCompareGE(y, 0.0f))
553 modY = y - (static_cast<int> (y / __unitScrollLength) * __unitScrollLength);
554 if (_FloatCompareGE(modY, GetItemSize().height))
559 row = static_cast<int> (y / __unitScrollLength);
560 index = row * __itemCountPerAxis + col;
561 if (index >= __pListModel->GetItemCountInGroup(DEFAULT_GROUP_INDEX))
568 y -= __startPosOfAxis;
569 if (!_FloatCompareGE(y, 0.0f))
574 row = static_cast<int> (y / __unitLengthOfAxis);
575 if (row >= __itemCountPerAxis)
580 modY = y - (static_cast<int> (y / __unitLengthOfAxis) * __unitLengthOfAxis);
581 if (_FloatCompareGE(modY, GetItemSize().height))
586 x += __scrollPosition - __leftMargin;
587 if (!_FloatCompareGE(x, 0.0f))
592 modX = x - (static_cast<int> (x / __unitScrollLength) * __unitScrollLength);
593 if (_FloatCompareGE(modX, GetItemSize().width))
598 col = static_cast<int> (x / __unitScrollLength);
599 index = col * __itemCountPerAxis + row;
600 if (index >= __pListModel->GetItemCountInGroup(DEFAULT_GROUP_INDEX))
610 _IconListPresenter::GetItemIndexFromPosition(const FloatPoint& position) const
612 return GetItemIndexFromPosition(position.x, position.y);
616 _IconListPresenter::SetTextHorizontalAlignment(HorizontalAlignment alignment)
618 return __pItemDrawingProperty->SetTextHorizontalAlignment(alignment);
622 _IconListPresenter::SetTextVerticalAlignment(IconListViewItemTextVerticalAlignment alignment)
624 int itemHeight = __pItemDrawingProperty->GetItemSize().height;
625 result r = __pItemDrawingProperty->SetTextVerticalAlignment(alignment);
626 if (alignment >= ICON_LIST_VIEW_ITEM_TEXT_VERTICAL_ALIGNMENT_OUTSIDE_TOP)
628 _ControlOrientation orientation = __pIconListView->GetOrientation();
629 GET_SHAPE_CONFIG(ICONLIST::OUTSIDE_TEXT_VERTICAL_SPACING, orientation, __verticalSpacing);
632 if (itemHeight != __pItemDrawingProperty->GetItemSize().height)
641 _IconListPresenter::GetTextHorizontalAlignment(void) const
644 return __pItemDrawingProperty->GetTextHorizontalAlignment();
647 IconListViewItemTextVerticalAlignment
648 _IconListPresenter::GetTextVerticalAlignment(void) const
651 return __pItemDrawingProperty->GetTextVerticalAlignment();
655 _IconListPresenter::SetItemTextColor(IconListViewItemDrawingStatus status, const Color& color)
657 SysTryReturn(NID_UI_CTRL,
658 (status >= ICON_LIST_VIEW_ITEM_DRAWING_STATUS_NORMAL && status <= ICON_LIST_VIEW_ITEM_DRAWING_STATUS_HIGHLIGHTED),
659 E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Invalid status is used.");
661 return __pItemDrawingProperty->SetTextColor(status, color);
665 _IconListPresenter::GetItemTextColor(IconListViewItemDrawingStatus status) const
667 SysTryReturn(NID_UI_CTRL,
668 (status >= ICON_LIST_VIEW_ITEM_DRAWING_STATUS_NORMAL && status <= ICON_LIST_VIEW_ITEM_DRAWING_STATUS_HIGHLIGHTED),
669 E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] status is invalid.");
671 return __pItemDrawingProperty->GetTextColor(status);
675 _IconListPresenter::SetItemTextSize(float size)
677 float itemHeight = __pItemDrawingProperty->GetItemSize().height;
678 result r = __pItemDrawingProperty->SetTextSize(size);
682 if (!_FloatCompare(itemHeight, __pItemDrawingProperty->GetItemSize().height))
691 _IconListPresenter::GetItemTextSize(void) const
693 return __pItemDrawingProperty->GetTextSize();
697 _IconListPresenter::SetCheckBoxPosition(IconListViewCheckBoxPosition position)
699 return __pItemDrawingProperty->SetCheckBoxPosition(position);
702 IconListViewCheckBoxPosition
703 _IconListPresenter::GetCheckBoxPosition(void) const
706 return __pItemDrawingProperty->GetCheckBoxPosition();
710 _IconListPresenter::SetTouchAnimationEnabled(bool enable)
712 __isTouchAnimationEnabled = enable;
713 __previousTouchAnimatinEnabled = enable;
719 _IconListPresenter::IsTouchAnimationEnabled(void) const
722 return __onReordering ? __previousTouchAnimatinEnabled : __isTouchAnimationEnabled;
726 _IconListPresenter::ScrollToItem(int index)
728 int itemCount = __pListModel->GetItemCountInGroup(DEFAULT_GROUP_INDEX);
729 SysTryReturn(NID_UI_CTRL, (index >= 0 && index < itemCount), E_OUT_OF_RANGE, E_OUT_OF_RANGE,
730 "[E_OUT_OF_RANGE] Index must be non-negative integer, and less count of whole items.");
732 SysTryReturn(NID_UI_CTRL, (__itemCountPerAxis > 0), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Unable to get ItemCount per axis.");
734 float scrollPosition = (index / __itemCountPerAxis) * __unitScrollLength;
735 if (__scrollDirection == ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL)
737 scrollPosition += __topMargin;
741 scrollPosition += __leftMargin;
744 if (SetScrollPosition(scrollPosition, false))
754 _IconListPresenter::ScrollByPixel(float pixel)
756 if (_FloatCompare(pixel, 0.0f))
761 if (SetScrollPosition(__scrollPosition + pixel, false))
763 __pIconListView->Invalidate();
770 return E_OUT_OF_RANGE;
774 _IconListPresenter::RefreshList(int index, ListRefreshType type)
776 SysTryReturn(NID_UI_CTRL, (__pItemProviderAdaptor != null), E_INVALID_STATE, E_INVALID_STATE,
777 "[E_INVALID_STATE] IconListViewItemProvider isn't added.");
779 SysTryReturn(NID_UI_CTRL, __alreadyDrawn, E_INVALID_OPERATION, E_INVALID_OPERATION,
780 "[E_INVALID_OPERATION] Unable to refresh IconListView before first drawn.");
782 int itemCount = __pListModel->GetItemCountInGroup(DEFAULT_GROUP_INDEX);
783 SysTryReturn(NID_UI_CTRL, (index >= 0 && index <= itemCount), E_OUT_OF_RANGE, E_OUT_OF_RANGE,
784 "[E_OUT_OF_RANGE] Index must be non-negative integer, and less count of whole items.");
786 SysTryReturn(NID_UI_CTRL, (index < itemCount || type == LIST_REFRESH_TYPE_ITEM_ADD), E_OUT_OF_RANGE, E_OUT_OF_RANGE,
787 "[E_OUT_OF_RANGE] Index must be non-negative integer, and less count of whole items.");
789 SysTryReturn(NID_UI_CTRL, (type >= LIST_REFRESH_TYPE_ITEM_ADD && type <= LIST_REFRESH_TYPE_ITEM_MODIFY), E_SYSTEM, E_SYSTEM,
790 "[E_SYSTEM] A system error has been occurred. Refresh type is invalid.");
792 if (__pAnimationTimer != null)
794 ResetAnimationTimer();
799 bool usingAnimation = false;
800 result r = E_SUCCESS;
803 case LIST_REFRESH_TYPE_ITEM_ADD:
805 _IconListItem* pItem = dynamic_cast <_IconListItem*>(__pItemProviderAdaptor->LoadItem(DEFAULT_GROUP_INDEX, index));
806 SysTryReturn(NID_UI_CTRL, (pItem != null), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
808 if ((__firstDrawnIndex <= index) && (__lastDrawnIndex >= index))
812 else if (__firstDrawnIndex > index)
814 MoveBackward(__firstDrawnIndex - 1);
815 usingAnimation = true;
818 if (__pListModel->GetItemCountInGroup(DEFAULT_GROUP_INDEX) == 0)
820 __listStatusChanged = true;
823 r = InsertItemAt(index, pItem);
824 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
826 if (__listStatusChanged)
828 __pIconListView->Invalidate();
831 if (((__firstDrawnIndex <= index) && (__lastDrawnIndex >= index)) || (index == (__lastDrawnIndex + 1)))
833 if (index < itemCount)
835 StartAnimationTimer(ITEM_ANIMATION_DELAY);
836 __animationItemIndex = index;
840 AddAnimation(*pItem, index);
843 usingAnimation = true;
849 case LIST_REFRESH_TYPE_ITEM_REMOVE:
851 _IconListItem* pItem = dynamic_cast <_IconListItem*>(__pListModel->LoadItem(DEFAULT_GROUP_INDEX, index));
852 SysTryReturn(NID_UI_CTRL, (pItem != null), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
854 if ((__firstDrawnIndex <= index) && (__lastDrawnIndex >= index))
856 RemoveAnimation(*pItem, index);
857 MoveForward(index + 1);
858 usingAnimation = true;
860 else if (__firstDrawnIndex > index)
862 MoveForward(__firstDrawnIndex);
863 usingAnimation = true;
866 r = RemoveItemAt(index);
867 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
869 if (__pListModel->GetItemCountInGroup(DEFAULT_GROUP_INDEX) == 0)
871 __listStatusChanged = true;
872 __pIconListView->Invalidate();
879 case LIST_REFRESH_TYPE_ITEM_MODIFY:
881 if (__pListModel->IsLoadedItem(DEFAULT_GROUP_INDEX , index) == false)
884 _IconListItem* pItem = dynamic_cast <_IconListItem*>(__pItemProviderAdaptor->LoadItem(DEFAULT_GROUP_INDEX, index));
885 SysTryReturn(NID_UI_CTRL, (pItem != null), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
887 r = SetItemAt(index, pItem);
888 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
890 RedrawItem(index, 1.0f);
907 _IconListPresenter::UpdateDrawnIndex(void)
910 int itemCount = __pListModel->GetItemCountInGroup(DEFAULT_GROUP_INDEX);
911 FloatRectangle itemRect(0.0f, 0.0f, GetItemSize().height, GetItemSize().width);
913 if (__scrollDirection == ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL)
915 float endXPos = __endPosOfAxis;
916 float endYPos = __pIconListView->GetBounds().height;
918 drawingLine = (__scrollPosition > __topMargin) ? (__scrollPosition - __topMargin + __verticalSpacing) / __unitScrollLength : 0;
919 itemRect.y = __topMargin + drawingLine * __unitScrollLength - __scrollPosition;
921 int index = drawingLine * __itemCountPerAxis;
922 __firstDrawnIndex = index;
923 while(!_FloatCompareGE(itemRect.y, endYPos))
925 itemRect.x = __startPosOfAxis;
926 while (!_FloatCompareGE(itemRect.x, endXPos) && (index < itemCount))
929 itemRect.x += __unitLengthOfAxis;
931 itemRect.y += __unitScrollLength;
933 __lastDrawnIndex = index - 1;
937 float endXPos = __pIconListView->GetBounds().width;
938 float endYPos = __endPosOfAxis;
940 drawingLine = (__scrollPosition > __leftMargin) ? (__scrollPosition - __leftMargin + __horizontalSpacing) / __unitScrollLength : 0;
941 itemRect.x = __leftMargin + drawingLine * __unitScrollLength - __scrollPosition;
943 int index = drawingLine * __itemCountPerAxis;
944 __firstDrawnIndex = index;
945 while(!_FloatCompareGE(itemRect.x, endXPos))
947 itemRect.y = __startPosOfAxis;
948 while (!_FloatCompareGE(itemRect.y, endYPos) && (index < itemCount))
951 itemRect.y += __unitLengthOfAxis;
953 itemRect.x += __unitScrollLength;
955 __lastDrawnIndex = index - 1;
960 _IconListPresenter::UpdateList(void)
962 SysTryReturn(NID_UI_CTRL, (__pItemProviderAdaptor != null), E_INVALID_STATE, E_INVALID_STATE,
963 "[E_INVALID_STATE] IconListViewItemProvider isn't added.");
965 ResetTouchActionTimer();
966 ResetAnimationTimer();
969 result r = RemoveAllItems();
970 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
972 __selectedIndex = INVALID_INDEX;
973 __highlightedIndex = INVALID_INDEX;
974 __isLayoutChanged = true;
975 __alreadyDrawn = false;
976 __listStatusChanged = true;
978 AddGroupAndRestoreItem(true);
980 __pIconListView->Draw();
981 __pIconListView->Show();
987 _IconListPresenter::SetItemBitmapBounds(const FloatRectangle& bounds)
989 result r = __pItemDrawingProperty->SetItemBitmapBounds(bounds);
993 __isLayoutChanged = true;
1000 _IconListPresenter::GetItemBitmapBounds(void) const
1002 return __pItemDrawingProperty->GetItemBitmapBounds();
1006 _IconListPresenter::GetItemBitmapSize(float& width, float& height) const
1008 FloatDimension itemSize = __pItemDrawingProperty->GetItemBitmapSize();
1009 width = itemSize.width;
1010 height = itemSize.height;
1016 _IconListPresenter::GetItemBitmapSize(void) const
1018 return __pItemDrawingProperty->GetItemBitmapSize();
1022 _IconListPresenter::SetItemSize(const FloatDimension& size)
1024 SysTryReturn(NID_UI_CTRL, (__pItemDrawingProperty != null), E_INVALID_STATE, E_INVALID_STATE,
1025 "[E_INVALID_STATE] This instance isn't constructed.");
1027 SysTryReturn(NID_UI_CTRL, !_FloatCompareLE(size.width, 0.0f) && !_FloatCompareLE(size.height, 0.0f), E_INVALID_ARG,
1028 E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. Width and Height should be larger than 0.");
1030 __isLayoutChanged = true;
1031 return __pItemDrawingProperty->SetItemSize(size);
1035 _IconListPresenter::GetItemSize(float& width, float& height) const
1037 FloatDimension itemSize = __pItemDrawingProperty->GetItemSize();
1038 width = itemSize.width;
1039 height = itemSize.height;
1045 _IconListPresenter::GetItemSize(void) const
1047 return __pItemDrawingProperty->GetItemSize();
1051 _IconListPresenter::SetMagneticScrollSize(int scrollSize)
1053 SysTryReturn(NID_UI_CTRL, (__pItemProviderAdaptor != null), E_INVALID_STATE, E_INVALID_STATE,
1054 "[E_INVALID_STATE] This instance isn't constructed.");
1056 int rowCount = static_cast<int> (Math::Ceiling(((double) __pItemProviderAdaptor->GetItemCount()) / ((double) __itemCountPerAxis)));
1057 SysTryReturn(NID_UI_CTRL, ((scrollSize >= 0) && (scrollSize <= rowCount)), E_INVALID_ARG, E_INVALID_ARG,
1058 "[E_INVALID_ARG] Invalid argument is used. ScrollSize is a non-negative integer and less than the number of rows.");
1060 __magneticScrollSize = scrollSize;
1066 _IconListPresenter::GetMagneticScrollSize(void) const
1069 return __magneticScrollSize;
1073 _IconListPresenter::SetItemCountPerAxis(int itemCountPerAxis)
1075 SysTryReturnVoidResult(NID_UI_CTRL, (itemCountPerAxis >= 0), E_INVALID_ARG,
1076 "[E_INVALID_ARG] Invalid argument is used. itemCountPerAxis is a non-negative integer.");
1079 __itemCountPerAxis = itemCountPerAxis;
1083 _IconListPresenter::GetItemCountPerAxis(void) const
1086 return __itemCountPerAxis;
1090 _IconListPresenter::SetItemLayoutHorizontalAlignment(HorizontalAlignment alignment)
1092 SysTryReturn(NID_UI_CTRL, (__scrollDirection == ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL), E_INVALID_OPERATION,
1093 E_INVALID_OPERATION, "[E_INVALID_OPERATION] This isn't vertical scroll.");
1095 SysTryReturn(NID_UI_CTRL, (alignment >= ALIGNMENT_LEFT && alignment <= ALIGNMENT_RIGHT), E_INVALID_ARG, E_INVALID_ARG,
1096 "[E_INVALID_ARG] alignment is invalid.");
1098 if (alignment != __itemHorizontalAlignment)
1100 __itemHorizontalAlignment = alignment;
1101 __isLayoutChanged = true;
1108 _IconListPresenter::SetItemLayoutVerticalAlignment(VerticalAlignment alignment)
1110 SysTryReturn(NID_UI_CTRL, (__scrollDirection == ICON_LIST_VIEW_SCROLL_DIRECTION_HORIZONTAL), E_INVALID_OPERATION,
1111 E_INVALID_OPERATION, "[E_INVALID_OPERATION] This isn't horizontal scroll.");
1113 SysTryReturn(NID_UI_CTRL, (alignment >= ALIGNMENT_TOP && alignment <= ALIGNMENT_BOTTOM), E_INVALID_ARG, E_INVALID_ARG,
1114 "[E_INVALID_ARG] alignment is invalid.");
1116 if (alignment != __itemVerticalAlignment)
1118 __itemVerticalAlignment = alignment;
1119 __isLayoutChanged = true;
1126 _IconListPresenter::GetItemLayoutHorizontalAlignment(void) const
1129 return __itemHorizontalAlignment;
1133 _IconListPresenter::GetItemLayoutVerticalAlignment(void) const
1136 return __itemVerticalAlignment;
1140 _IconListPresenter::SetItemBorderStyle(IconListViewItemBorderStyle borderStyle)
1142 return __pItemDrawingProperty->SetBorderStyle(borderStyle);
1145 IconListViewItemBorderStyle
1146 _IconListPresenter::GetItemBorderStyle(void) const
1148 return __pItemDrawingProperty->GetBorderStyle();
1151 _IconListItemDrawingProperty*
1152 _IconListPresenter::GetItemDrawingProperty(void) const
1154 return __pItemDrawingProperty;
1158 _IconListPresenter::ClearVisualElement(void)
1160 __listStatusChanged = true;
1164 _IconListPresenter::SetNonSlidableList(void)
1166 // Remove All Items & Register Adaptor
1167 __pListModel->RemoveAllItem();
1169 __firstDrawnIndex = INVALID_INDEX;
1170 __lastDrawnIndex = INVALID_INDEX;
1171 __selectedIndex = INVALID_INDEX;
1172 __highlightedIndex = INVALID_INDEX;
1173 __isLayoutChanged = true;
1174 __alreadyDrawn = true;
1176 return __pListModel->AddGroup(0, __pIconListView->GetStyle() == ICON_LIST_VIEW_STYLE_RADIO);
1180 _IconListPresenter::AddItem(_IconListItem* pItem)
1182 result r = __pListModel->AddItemToGroup(pItem, DEFAULT_GROUP_INDEX);
1183 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
1185 pItem->ClearVisualElement();
1187 // Attach _VisualElement
1188 _VisualElement* pBase = pItem->GetVisualElement();
1191 VisualElement* pParent = pBase->GetParent();
1192 if (pParent != null)
1194 pParent->DetachChild(*pBase);
1196 __pIconListView->GetVisualElement()->AttachChild(*pBase);
1197 pBase->SetShowState(false);
1198 pBase->SetClipToParent(true);
1201 __isLayoutChanged = true;
1207 _IconListPresenter::InsertItemAt(int index, _IconListItem* pItem)
1209 result r = __pListModel->InsertItemToGroup(pItem, DEFAULT_GROUP_INDEX, index);
1210 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
1212 pItem->ClearVisualElement();
1213 pItem->SetDrawingProperty(*__pItemDrawingProperty);
1215 // Attach _VisualElement
1216 _VisualElement* pBase = pItem->GetVisualElement();
1219 VisualElement* pParent = pBase->GetParent();
1220 if (pParent != null)
1222 pParent->DetachChild(*pBase);
1224 __pIconListView->GetVisualElement()->AttachChild(*pBase);
1225 pBase->SetShowState(false);
1226 pBase->SetClipToParent(true);
1229 __isLayoutChanged = true;
1235 _IconListPresenter::SetItemAt(int index, _IconListItem* pItem)
1237 SysTryReturn(NID_UI_CTRL, (pItem != null), E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. pItem is null.");
1239 result r = __pListModel->SetItem(*pItem, DEFAULT_GROUP_INDEX, index);
1240 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
1242 pItem->ClearVisualElement();
1243 pItem->SetDrawingProperty(*__pItemDrawingProperty);
1245 // Attach _VisualElement
1246 _VisualElement* pBase = pItem->GetVisualElement();
1249 VisualElement* pParent = pBase->GetParent();
1250 if (pParent != null)
1252 pParent->DetachChild(*pBase);
1254 __pIconListView->GetVisualElement()->AttachChild(*pBase);
1255 pBase->SetShowState(false);
1256 pBase->SetClipToParent(true);
1263 _IconListPresenter::RemoveItemAt(int index)
1265 __isLayoutChanged = true;
1267 return __pListModel->RemoveItemAt(DEFAULT_GROUP_INDEX, index);
1271 _IconListPresenter::RemoveAllItems(void)
1273 __isLayoutChanged = true;
1275 return __pListModel->RemoveAllItem(false, true);
1279 _IconListPresenter::SetItemBitmapAsAspectRatio(bool isAspect)
1281 __pItemDrawingProperty->SetItemBitmapAsAspectRatio(isAspect);
1285 _IconListPresenter::IsItemBitmapAsAspectRatio(void) const
1287 return __pItemDrawingProperty->IsItemBitmapAsAspectRatio();
1291 _IconListPresenter::SetReorderModeEnabled(bool enable)
1293 __isLayoutChanged = true;
1295 if (__isTouchAnimationEnabled && enable)
1297 __isTouchAnimationEnabled = false;
1301 __isTouchAnimationEnabled = __previousTouchAnimatinEnabled;
1304 __pIconListView->Invalidate();
1309 _IconListPresenter::Draw(void)
1311 result r = E_SUCCESS;
1316 __requireNextDrawing = true;
1320 // If it is first draw,
1321 if (!__alreadyDrawn)
1323 r = AddGroupAndRestoreItem(false);
1324 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
1331 Color backgroundColor = __pIconListView->GetBackgroundColor();
1332 if (__listStatusChanged)
1334 const Bitmap* pBackgroundBitmap = __pIconListView->GetBackgroundBitmap();
1335 if (pBackgroundBitmap != null)
1337 Canvas* pCanvas = __pVE->GetCanvasN();
1338 SysTryCatch(NID_UI_CTRL, (pCanvas!= null), , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1340 pCanvas->SetBackgroundColor(backgroundColor);
1342 FloatRectangle bounds(__pIconListView->GetBoundsF());
1343 bounds.SetPosition(0.0f, 0.0f);
1344 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pBackgroundBitmap))
1346 pCanvas->DrawNinePatchedBitmap(bounds, *pBackgroundBitmap);
1350 pCanvas->DrawBitmap(bounds, *pBackgroundBitmap);
1355 __needBaseCanvas = true;
1359 __pVE->SetBackgroundColor(_Colorf((float) backgroundColor.GetRed() / 255, (float) backgroundColor.GetGreen() / 255, (float) backgroundColor.GetBlue() / 255, (float) backgroundColor.GetAlpha() / 255));
1360 __needBaseCanvas = false;
1364 itemCount = __pListModel->GetItemCountInGroup(DEFAULT_GROUP_INDEX);
1367 r = DrawEmptyList();
1368 __onDrawing = false;
1369 __alreadyDrawn = true;
1370 if (__requireNextDrawing)
1372 __requireNextDrawing = false;
1378 // If layout is changed, adjust layout.
1379 if (__isLayoutChanged)
1385 if (__scrollDirection == ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL)
1388 r = DrawVerticalScrollList();
1389 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1393 // Horizontal Scroll
1394 r = DrawHorizontalScrollList();
1395 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1398 __pItemDrawingProperty->SetDrawingFlag();
1400 if (!__alreadyDrawn)
1402 __alreadyDrawn = true;
1404 // start timer for scroll fade out
1405 _Scroll* pScroll = __pIconListView->GetScroll();
1406 if (pScroll != null)
1408 float scrollViewRange = 0.0f;
1409 float scrollRange = 0.0f;
1410 pScroll->GetScrollRange(&scrollViewRange, &scrollRange);
1411 if (!_FloatCompareGE(scrollViewRange, scrollRange))
1416 InitializeAccessibilityElement();
1419 if (__listStatusChanged)
1421 if (__pEmptyListVE != null)
1423 if (__needBaseCanvas)
1425 __pEmptyListVE->Destroy();
1426 __pEmptyListVE = null;
1430 __pEmptyListVE->SetShowState(false);
1433 __listStatusChanged = false;
1437 __onDrawing = false;
1438 if (__requireNextDrawing)
1440 __requireNextDrawing = false;
1448 _IconListPresenter::AddGroupAndRestoreItem(bool restoreItem)
1450 if (__pListModel->GetAllGroupCount() == 0)
1452 int itemCount = (__pItemProviderAdaptor != null) ? __pItemProviderAdaptor->GetItemCount() : 0;
1455 result r = __pListModel->AddGroup(itemCount, __pIconListView->GetStyle() == ICON_LIST_VIEW_STYLE_RADIO);
1456 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
1458 __isLayoutChanged = true;
1463 __pListModel->RestoreItemStatus();
1470 _IconListPresenter::DrawEmptyList(void)
1472 result r = E_SUCCESS;
1474 if (!__listStatusChanged)
1479 Canvas* pCanvas = null;
1480 TextObject* pTextObject = null;
1481 FloatDimension textDimension;
1482 FloatRectangle bounds(0.0f, 0.0f, 0.0f, 0.0f);
1483 FloatRectangle viewBounds = __pIconListView->GetBoundsF();
1484 viewBounds.x = 0.0f;
1485 viewBounds.y = 0.0f;
1487 float emptyTextHeight = 0.0f;
1490 const String emptyText = __pIconListView->GetTextOfEmptyList();
1492 float bitmapXPosition = 0.0f;
1493 float bitmapHeight = 0.0f;
1494 float bitmapWidth = 0.0f;
1495 const Bitmap* pBitmap = __pIconListView->GetBitmapOfEmptyList();
1497 // set visual element or canvas for empty list
1498 if (!__needBaseCanvas && __pEmptyListVE == null)
1500 __pEmptyListVE = new (std::nothrow) _VisualElement();
1501 SysTryCatch(NID_UI, __pEmptyListVE != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1503 r = __pEmptyListVE->Construct();
1504 SysTryCatch(NID_UI, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
1506 __pEmptyListVE->SetSurfaceOpaque(false);
1507 __pEmptyListVE->SetImplicitAnimationEnabled(false);
1509 __pVE->AttachChild(*__pEmptyListVE);
1511 else if (__needBaseCanvas)
1513 pCanvas = __pVE->GetCanvasN();
1514 SysTryCatch(NID_UI, pCanvas != null, , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1517 if (!emptyText.IsEmpty())
1519 GET_SHAPE_CONFIG(ICONLIST::EMPTY_TEXT_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, emptyTextHeight);
1521 pFont = __pIconListView->GetFallbackFont();
1522 SysTryCatch(NID_UI, pFont != null, , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1524 pTextObject = new (std::nothrow) TextObject;
1525 SysTryCatch(NID_UI, pTextObject != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1527 pTextObject->Construct();
1528 TextSimple* pSimpleText = new (std::nothrow)TextSimple(const_cast <wchar_t*>(emptyText.GetPointer()), emptyText.GetLength());
1529 SysTryCatch(NID_UI, pSimpleText != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1531 pTextObject->AppendElement(*pSimpleText);
1532 pTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_CENTER | TEXT_OBJECT_ALIGNMENT_MIDDLE);
1533 pTextObject->SetForegroundColor(__pIconListView->GetTextColorOfEmptyList(), 0, pTextObject->GetTextLength());
1534 pTextObject->SetFont(pFont, 0, pTextObject->GetTextLength());
1535 pTextObject->SetWrap(TEXT_OBJECT_WRAP_TYPE_WORD);
1536 pTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
1538 pTextObject->SetBounds(FloatRectangle(0.0f, 0.0f, viewBounds.width, 1.0f));
1539 pTextObject->Compose();
1540 textDimension.height = pTextObject->GetTotalHeightF();
1541 textDimension.width = pTextObject->GetLineWidthAtF(0);
1543 for (int i = 1; i < pTextObject->GetTotalLineCount(); i++)
1545 float tempWidth = pTextObject->GetLineWidthAtF(i);
1546 textDimension.width = textDimension.width > tempWidth ? textDimension.width : tempWidth;
1549 // calculate bounds with text
1550 if (_FloatCompareGE(viewBounds.width, textDimension.width))
1552 bounds.x = (viewBounds.width - textDimension.width) / 2;
1553 bounds.width = textDimension.width;
1557 bounds.width = viewBounds.width;
1560 if (_FloatCompareGE(viewBounds.height, textDimension.height))
1562 bounds.y = (viewBounds.height - textDimension.height) / 2;
1563 bounds.height = textDimension.height;
1567 bounds.height = viewBounds.height;
1571 if (pBitmap != null)
1573 bitmapHeight = pBitmap->GetHeightF();
1574 bitmapWidth = pBitmap->GetWidthF();
1576 bounds.height += bitmapHeight + emptyTextHeight;
1578 bounds.y = (viewBounds.height - bounds.height) / 2;
1580 if (!_FloatCompareGE(bounds.y, 0.0f))
1585 if (!_FloatCompareLE(bounds.width, bitmapWidth))
1587 bitmapXPosition = (bounds.width - bitmapWidth) / 2;
1589 else if (!_FloatCompareLE(viewBounds.width, bitmapWidth))
1591 bounds.x = (viewBounds.width - bitmapWidth) / 2;
1592 bounds.width = bitmapWidth;
1597 bounds.width = bitmapWidth;
1602 if (!__needBaseCanvas)
1604 __pEmptyListVE->SetBounds(bounds);
1605 __pEmptyListVE->SetShowState(true);
1607 pCanvas = __pEmptyListVE->GetCanvasN();
1608 SysTryCatch(NID_UI, pCanvas != null, , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1610 Color backgroundColor = __pIconListView->GetBackgroundColor();
1611 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
1618 if (pBitmap != null)
1620 FloatRectangle bitmapBounds(bounds.x + bitmapXPosition, bounds.y, bitmapWidth, bitmapHeight);
1621 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pBitmap))
1623 pCanvas->DrawNinePatchedBitmap(bitmapBounds, *pBitmap);
1627 pCanvas->DrawBitmap(bitmapBounds, *pBitmap);
1631 if (!emptyText.IsEmpty())
1633 if (!_FloatCompare(bitmapHeight, 0.0f))
1635 bounds.y += emptyTextHeight + bitmapHeight;
1637 bounds.height = textDimension.height;
1638 pTextObject->SetBounds(bounds);
1639 pTextObject->Draw(*_CanvasImpl::GetInstance(*pCanvas));
1642 __listStatusChanged = false;
1644 if (__needBaseCanvas && __pEmptyListVE != null)
1646 __pEmptyListVE->Destroy();
1647 __pEmptyListVE = null;
1655 if (__pEmptyListVE != null)
1657 __pEmptyListVE->Destroy();
1658 __pEmptyListVE = null;
1667 _IconListPresenter::DrawHorizontalScrollList(void)
1669 int itemCount = __pListModel->GetItemCountInGroup(DEFAULT_GROUP_INDEX);
1670 float itemHeight = GetItemSize().height;
1671 float itemWidth = GetItemSize().width;
1672 FloatRectangle itemRect(0.0f, 0.0f, itemWidth, itemHeight);
1673 int drawingLine = __scrollPosition > __leftMargin ? _CoordinateSystemUtils::ConvertToInteger((__scrollPosition - __leftMargin + __horizontalSpacing) / __unitScrollLength) : 0;
1674 int index = drawingLine * __itemCountPerAxis;
1675 float endXPos = __pIconListView->GetBounds().width;
1676 float endYPos = __endPosOfAxis;
1677 float unitWidth = __unitScrollLength;
1678 float unitHeight = __unitLengthOfAxis;
1679 itemRect.x = __leftMargin + drawingLine * unitWidth - __scrollPosition;
1682 if (__lastDrawnIndex >= 0)
1684 float scroll = endXPos - itemRect.x;
1685 int lastIndex = index + (static_cast<int> ((scroll - 1.0f) / unitWidth) + 1) * __itemCountPerAxis - 1;
1686 if (lastIndex >= itemCount)
1688 lastIndex = itemCount - 1;
1691 if (__lastDrawnIndex < index || __firstDrawnIndex > lastIndex)
1693 HideItems(__firstDrawnIndex, __lastDrawnIndex);
1697 HideItems(__firstDrawnIndex, index - 1);
1698 HideItems(lastIndex + 1, __lastDrawnIndex);
1703 if (__firstDrawnIndex > index)
1705 int topIndex = __firstDrawnIndex - __itemCountPerAxis * (static_cast<int> (__pIconListView->GetBounds().width / __unitScrollLength) + 1);
1706 if (topIndex <= index)
1708 while (--__firstDrawnIndex > index)
1710 __pListModel->LoadItem(DEFAULT_GROUP_INDEX, __firstDrawnIndex);
1716 _IconListItem* pItem = null;
1717 __firstDrawnIndex = index;
1718 while (itemRect.x < endXPos)
1720 itemRect.y = __startPosOfAxis;
1721 while (itemRect.y < endYPos && index < itemCount)
1724 pItem = dynamic_cast <_IconListItem*>(__pListModel->LoadItem(DEFAULT_GROUP_INDEX, index));
1727 pItem->SetDrawingProperty(*__pItemDrawingProperty);
1729 if (__reorderToIndex == index && __isTouchPressed)
1731 pItem->DrawItem(itemRect, LIST_ITEM_STATE_PRESSED);
1735 pItem->DrawItem(itemRect, LIST_ITEM_STATE_NORMAL);
1738 if (pItem->GetVisualElement() != null)
1740 pItem->GetVisualElement()->SetFlushNeeded();
1744 itemRect.y += unitHeight;
1746 itemRect.x += unitWidth;
1748 __lastDrawnIndex = index - 1;
1754 _IconListPresenter::DrawVerticalScrollList(void)
1756 int itemCount = __pListModel->GetItemCountInGroup(DEFAULT_GROUP_INDEX);
1757 float itemHeight = GetItemSize().height;
1758 float itemWidth = GetItemSize().width;
1759 FloatRectangle itemRect(0.0f, 0.0f, itemWidth, itemHeight);
1760 int drawingLine = __scrollPosition > __topMargin ? _CoordinateSystemUtils::ConvertToInteger((__scrollPosition - __topMargin + __verticalSpacing) / __unitScrollLength) : 0;
1761 int index = drawingLine * __itemCountPerAxis;
1762 float endXPos = __endPosOfAxis;
1763 float endYPos = __pIconListView->GetBounds().height;
1764 float unitWidth = __unitLengthOfAxis;
1765 float unitHeight = __unitScrollLength;
1766 itemRect.y = __topMargin + drawingLine * unitHeight - __scrollPosition;
1769 if (__lastDrawnIndex >= 0)
1771 float scroll = endYPos - itemRect.y;
1772 int lastIndex = index + (static_cast<int> ((scroll - 1.0f) / unitHeight) + 1) * __itemCountPerAxis - 1;
1773 if (lastIndex >= itemCount)
1775 lastIndex = itemCount - 1;
1778 if (__lastDrawnIndex < index || __firstDrawnIndex > lastIndex)
1780 HideItems(__firstDrawnIndex, __lastDrawnIndex);
1784 HideItems(__firstDrawnIndex, index - 1);
1785 HideItems(lastIndex + 1, __lastDrawnIndex);
1790 if (__firstDrawnIndex > index)
1792 int topIndex = __firstDrawnIndex - __itemCountPerAxis * (static_cast<int> (__pIconListView->GetBounds().height / __unitScrollLength) + 1);
1793 if (topIndex <= index)
1795 while (--__firstDrawnIndex > index)
1797 __pListModel->LoadItem(DEFAULT_GROUP_INDEX, __firstDrawnIndex);
1803 _IconListItem* pItem = null;
1804 __firstDrawnIndex = index;
1805 while (itemRect.y < endYPos)
1807 itemRect.x = __startPosOfAxis;
1808 while (itemRect.x < endXPos && index < itemCount)
1811 pItem = dynamic_cast <_IconListItem*>(__pListModel->LoadItem(DEFAULT_GROUP_INDEX, index));
1814 pItem->SetDrawingProperty(*__pItemDrawingProperty);
1816 if (__reorderToIndex == index && __isTouchPressed)
1818 pItem->DrawItem(itemRect, LIST_ITEM_STATE_PRESSED);
1822 pItem->DrawItem(itemRect, LIST_ITEM_STATE_NORMAL);
1826 itemRect.x += unitWidth;
1828 itemRect.y += unitHeight;
1830 __lastDrawnIndex = index - 1;
1836 _IconListPresenter::AdjustLayout(void)
1838 FloatDimension itemSize = __pIconListView->GetItemSize();
1839 FloatRectangle bounds = __pIconListView->GetBoundsF();
1840 int itemCount = __pListModel->GetItemCountInGroup(DEFAULT_GROUP_INDEX);
1841 float oldScrollLength = __scrollLength;
1843 // Reset layout changed flag
1844 __isLayoutChanged = false;
1847 if (__scrollDirection == ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL)
1849 // Unit Axis Length(= Item Width + Horizontal Spacing)
1850 __unitLengthOfAxis = itemSize.width + __horizontalSpacing;
1853 __itemCountPerAxis = (bounds.width - __leftMargin - __rightMargin + __horizontalSpacing) / __unitLengthOfAxis;
1855 // Unit Scroll Length(= Item Height + Vertical Spacing)
1856 __unitScrollLength = itemSize.height + __verticalSpacing;
1859 if (__itemCountPerAxis > 0)
1861 __scrollLength = __topMargin + __bottomMargin - __verticalSpacing + __unitScrollLength *
1862 ((itemCount - 1) / __itemCountPerAxis + 1) - bounds.height;
1863 if (!_FloatCompareGE(__scrollLength, 0.0f))
1865 __scrollLength = 0.0f;
1870 __itemCountPerAxis = 0;
1871 __scrollLength = 0.0f;
1875 switch (__itemHorizontalAlignment)
1877 case ALIGNMENT_LEFT:
1878 __startPosOfAxis = __leftMargin;
1881 case ALIGNMENT_CENTER:
1882 __startPosOfAxis = (bounds.width + __leftMargin - __rightMargin - __itemCountPerAxis * __unitLengthOfAxis
1883 + __horizontalSpacing) / 2;
1886 case ALIGNMENT_RIGHT:
1887 __startPosOfAxis = bounds.width - __rightMargin - __itemCountPerAxis * __unitLengthOfAxis + __horizontalSpacing;
1892 __endPosOfAxis = __startPosOfAxis + __itemCountPerAxis * __unitLengthOfAxis - __horizontalSpacing;
1894 if (!_FloatCompare(__scrollLength, oldScrollLength))
1896 // Set Scroll Range & Position
1897 _Scroll* pScroll = __pIconListView->GetScroll();
1898 if (pScroll != null)
1900 pScroll->SetScrollRange(bounds.height, __scrollLength + bounds.height);
1902 if (_FloatCompareLE(__scrollLength, 0.0f))
1904 pScroll->EnableScrollingEffect(false);
1908 pScroll->EnableScrollingEffect(true);
1912 if (!_FloatCompareGE(__scrollLength, oldScrollLength) && !_FloatCompareLE(__scrollPosition, __scrollLength))
1914 if (SetScrollPosition(__scrollLength))
1919 __pIconListView->Invalidate();
1924 // CachingSize = # of items of view * ITEM_CACHE_SIZE_MULTIPLIER
1925 __pListModel->SetMaxCachingSize((static_cast<int> (bounds.height / __unitScrollLength) + 1) *
1926 __itemCountPerAxis * ITEM_CACHE_SIZE_MULTIPLIER);
1930 // Unit Axis Length(= Item Height + Vertical Spacing)
1931 __unitLengthOfAxis = itemSize.height + __verticalSpacing;
1934 __itemCountPerAxis = static_cast<int> ((bounds.height - __topMargin - __bottomMargin + __verticalSpacing) / __unitLengthOfAxis);
1936 // Unit Scroll Length(= Item Width + Horizontal Spacing)
1937 __unitScrollLength = itemSize.width + __horizontalSpacing;
1940 if (__itemCountPerAxis > 0)
1942 __scrollLength = __leftMargin + __rightMargin - __horizontalSpacing + __unitScrollLength *
1943 ((itemCount - 1) / __itemCountPerAxis + 1) - bounds.width;
1944 if (!_FloatCompareGE(__scrollLength, 0.0f))
1946 __scrollLength = 0.0f;
1951 __itemCountPerAxis = 0;
1952 __scrollLength = 0.0f;
1956 switch (__itemVerticalAlignment)
1959 __startPosOfAxis = __topMargin;
1962 case ALIGNMENT_MIDDLE:
1963 __startPosOfAxis = (bounds.height + __topMargin - __bottomMargin - __itemCountPerAxis * __unitLengthOfAxis +
1964 __verticalSpacing) / 2;
1967 case ALIGNMENT_BOTTOM:
1968 __startPosOfAxis = bounds.height - __bottomMargin - __itemCountPerAxis * __unitLengthOfAxis + __verticalSpacing;
1973 __endPosOfAxis = __startPosOfAxis + __itemCountPerAxis * __unitLengthOfAxis - __verticalSpacing;
1975 if (!_FloatCompare(__scrollLength, oldScrollLength))
1977 // Set Scroll Range & Position
1978 _Scroll* pScroll = __pIconListView->GetScroll();
1979 if (pScroll != null)
1981 pScroll->SetScrollRange(bounds.width, __scrollLength + bounds.width);
1983 if (_FloatCompareLE(__scrollLength, 0.0f))
1985 pScroll->EnableScrollingEffect(false);
1989 pScroll->EnableScrollingEffect(true);
1993 if (!_FloatCompareGE(__scrollLength, oldScrollLength) && !_FloatCompareLE(__scrollPosition, __scrollLength))
1995 if (SetScrollPosition(__scrollLength))
2000 __pIconListView->Invalidate();
2005 // CachingSize = # of items of view * ITEM_CACHE_SIZE_MULTIPLIER
2006 __pListModel->SetMaxCachingSize(static_cast<int> (bounds.width / __unitScrollLength + 1) *
2007 __itemCountPerAxis * ITEM_CACHE_SIZE_MULTIPLIER);
2012 _IconListPresenter::HideItems(int startIndex, int endIndex)
2015 if (startIndex < 0 || endIndex < 0)
2020 if (endIndex >= __pListModel->GetItemCountInGroup(DEFAULT_GROUP_INDEX))
2022 endIndex = __pListModel->GetItemCountInGroup(DEFAULT_GROUP_INDEX) - 1;
2025 for (int index = startIndex; index <= endIndex; ++index)
2027 _IconListItem* pItem = dynamic_cast <_IconListItem*>(__pListModel->LoadItem(DEFAULT_GROUP_INDEX, index));
2030 _VisualElement* pBase = pItem->GetVisualElement();
2033 pBase->SetShowState(false);
2040 _IconListPresenter::RedrawItem(int index, float ratio, bool doShow, float checkRatio)
2042 SysTryReturn(NID_UI_CTRL, (index >= 0 && index < __pListModel->GetItemCountInGroup(DEFAULT_GROUP_INDEX)), E_OUT_OF_RANGE,
2043 E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] Index must be non-negative integer, and less than count of whole items.");
2047 _IconListItem* pItem = dynamic_cast <_IconListItem*>(__pListModel->LoadItem(DEFAULT_GROUP_INDEX, index));
2048 SysTryReturn(NID_UI_CTRL, (pItem != null), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Unable to get item.");
2051 if (index < __firstDrawnIndex || index > __lastDrawnIndex)
2053 pItem->ClearVisualElement();
2057 FloatRectangle itemRect = GetItemBounds(index);
2059 pItem->SetDrawingProperty(*__pItemDrawingProperty);
2060 pItem->ClearVisualElement();
2062 if (__reorderToIndex == index && __isTouchPressed)
2064 pItem->DrawItem(itemRect, LIST_ITEM_STATE_PRESSED);
2068 pItem->DrawItem(itemRect, LIST_ITEM_STATE_NORMAL);
2071 _VisualElement* pBase = pItem->GetVisualElement();
2072 pBase->InvalidateRectangle(&itemRect);
2077 pBase->SetFlushNeeded();
2084 _IconListPresenter::FireIconListViewItemEvent(_IconListViewItemEventType eventType, int index, int arg)
2087 _IconListViewItemEventArg* pArg = new (std::nothrow) _IconListViewItemEventArg(index, eventType);
2088 SysTryReturn(NID_UI_CTRL, (pArg != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2091 case EVENT_TYPE_ITEM_SELECTED:
2092 pArg->SetStatus(static_cast<IconListViewItemStatus> (arg));
2095 case EVENT_TYPE_OVERLAY_BITMAP_SELECTED:
2096 pArg->SetOverlayBitmapId(arg);
2099 case EVENT_TYPE_ITEM_REORDERED:
2100 pArg->SetToIndex(arg);
2105 return __pIconListView->GetIconListItemEvent()->Fire(*pArg);
2109 _IconListPresenter::FireScrollEndReachedEvent(ScrollEndEvent type)
2112 _UiScrollEventArg* pEventArg = _UiScrollEventArg::GetScrollEventArgN(*__pIconListView, type);
2113 result r = GetLastResult();
2114 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
2117 r = __pIconListView->GetScrollEvent()->Fire(*pEventArg);
2125 _IconListPresenter::FireScrollPositionChangedEvent(float scrollPosition)
2128 _UiScrollEventArg* pEventArg = _UiScrollEventArg::GetScrollEventArgN(*__pIconListView, scrollPosition);
2129 result r = GetLastResult();
2130 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
2133 r = __pIconListView->GetScrollEvent()->Fire(*pEventArg);
2141 _IconListPresenter::FireScrollStoppedEvent()
2144 _UiScrollEventArg* pEventArg = _UiScrollEventArg::GetScrollEventArgN(*__pIconListView);
2145 result r = GetLastResult();
2146 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
2149 r = __pIconListView->GetScrollEvent()->Fire(*pEventArg);
2157 _IconListPresenter::FireScrollEvent()
2159 result r = E_SUCCESS;
2161 if ((__flickRunning) || (__pMagneticScrollTimer != null))
2166 if (_FloatCompare(__scrollPosition, 0.0f))
2168 if (__scrollDirection == ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL)
2170 r = FireScrollEndReachedEvent(SCROLL_END_EVENT_END_TOP);
2174 r = FireScrollEndReachedEvent(SCROLL_END_EVENT_END_LEFT);
2177 if (!__isTouchPressed)
2182 else if (_FloatCompare(__scrollPosition, __scrollLength))
2184 if (__scrollDirection == ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL)
2186 r = FireScrollEndReachedEvent(SCROLL_END_EVENT_END_BOTTOM);
2190 r = FireScrollEndReachedEvent(SCROLL_END_EVENT_END_RIGHT);
2193 if (!__isTouchPressed)
2200 r = FireScrollPositionChangedEvent(__scrollPosition);
2206 _IconListPresenter::SetScrollPosition(float position, bool enableFadeEffect)
2208 if (_FloatCompareLE(__scrollLength, 0.0f) && (!_FloatCompare(position, 0.0f)))
2213 if (_FloatCompare(__scrollPosition, position))
2218 if (!_FloatCompareLE(position, __scrollLength))
2220 __scrollPosition = __scrollLength;
2222 else if (!_FloatCompareGE(position, 0.0f))
2224 __scrollPosition = 0.0f;
2228 __scrollPosition = position;
2231 result r = E_SUCCESS;
2232 _Scroll *pScroll =__pIconListView->GetScroll();
2233 if (pScroll != null)
2235 pScroll->SetScrollingEffectVisibility(true);
2237 if (pScroll->IsEnabledFadeEffect())
2239 if (enableFadeEffect)
2241 pScroll->SetScrollVisibility(true);
2245 pScroll->EnableFadeEffect(false);
2246 pScroll->SetScrollVisibility(true);
2247 pScroll->EnableFadeEffect(true);
2251 r = pScroll->SetScrollPosition(position);
2254 return (r == E_SUCCESS);
2258 _IconListPresenter::ScrollFadeOut(bool showEffect)
2260 _Scroll* pScroll = __pIconListView->GetScroll();
2261 if (pScroll != null)
2263 if (pScroll->IsEnabledFadeEffect())
2267 pScroll->EnableFadeEffect(false);
2268 pScroll->SetScrollVisibility(true);
2269 pScroll->SetScrollingEffectVisibility(true);
2270 pScroll->EnableFadeEffect(true);
2273 pScroll->SetScrollVisibility(false);
2276 pScroll->SetScrollingEffectVisibility(false);
2281 _IconListPresenter::GetMagneticScrollPosition(void) const
2283 return GetMagneticScrollPosition(__scrollPosition);
2287 _IconListPresenter::GetMagneticScrollPosition(float scrollPosition) const
2289 if (__magneticScrollSize <= 0)
2291 return __scrollPosition;
2294 float leftScrollLength = __scrollLength - scrollPosition;
2295 if (__scrollDirection == ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL)
2297 if (!_FloatCompareGE(scrollPosition, __topMargin))
2302 scrollPosition -= __topMargin;
2306 if (!_FloatCompareGE(scrollPosition, __leftMargin))
2311 scrollPosition -= __leftMargin;
2314 float unitMagneticScrollSize = __unitScrollLength * __magneticScrollSize;
2315 float leftMagneticScrollPosition = scrollPosition - (static_cast<int> (scrollPosition / unitMagneticScrollSize) * unitMagneticScrollSize);
2316 if (!_FloatCompareLE(leftMagneticScrollPosition, leftScrollLength))
2318 scrollPosition = __scrollLength + OVERSCROLLING_MAX_DISTANCE;
2320 else if (!_FloatCompareLE(leftMagneticScrollPosition, unitMagneticScrollSize / 2))
2322 scrollPosition = scrollPosition - leftMagneticScrollPosition + unitMagneticScrollSize;
2326 scrollPosition = scrollPosition - leftMagneticScrollPosition;
2329 return scrollPosition;
2333 _IconListPresenter::GetItemBounds(int index) const
2335 // Absolute Coordinate Base
2336 FloatRectangle rect(0.0f, 0.0f, GetItemSize().width, GetItemSize().height);
2337 if (__scrollDirection == ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL)
2339 rect.x = __startPosOfAxis + __unitLengthOfAxis * (index % __itemCountPerAxis);
2340 rect.y = __topMargin + __unitScrollLength * (index / __itemCountPerAxis) - __scrollPosition;
2344 rect.x = __leftMargin + __unitScrollLength * (index / __itemCountPerAxis) - __scrollPosition;
2345 rect.y = __startPosOfAxis + __unitLengthOfAxis * (index % __itemCountPerAxis);
2352 _IconListPresenter::CalculateFlickAmount(int distance, int duration)
2354 if (_FloatCompare(distance, 0.0f))
2358 else if (distance < 0.0)
2360 return -SCROLL_PANEL_FIXED_FLICK_AMOUNT;
2364 return SCROLL_PANEL_FIXED_FLICK_AMOUNT;
2369 _IconListPresenter::InitializeAccessibilityElement(void)
2371 RemoveAllAccessibilityElements();
2373 int itemCount = __pListModel->GetItemCountInGroup(DEFAULT_GROUP_INDEX);
2379 int firstIndex = INVALID_INDEX;
2380 int endIndex = INVALID_INDEX;
2381 if (__scrollDirection == ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL)
2383 int firstLine = !_FloatCompareLE(__scrollPosition, __topMargin) ? static_cast<int> (__scrollPosition - __topMargin + __verticalSpacing) / __unitScrollLength : 0;
2385 firstIndex = firstLine * __itemCountPerAxis;
2386 endIndex = firstIndex + (static_cast<int> (__pIconListView->GetBounds().height + __verticalSpacing) / __unitScrollLength) * __itemCountPerAxis;
2390 int firstLine = !_FloatCompareLE(__scrollPosition, __leftMargin) ? static_cast<int> (__scrollPosition - __leftMargin + __horizontalSpacing) / __unitScrollLength : 0;
2392 firstIndex = firstLine * __itemCountPerAxis;
2393 endIndex = firstIndex + (static_cast<int> (__pIconListView->GetBounds().width + __horizontalSpacing) / __unitScrollLength) * __itemCountPerAxis;
2396 endIndex = itemCount > endIndex ? endIndex : (itemCount - 1);
2398 for (int i = firstIndex; i < endIndex; i++)
2400 _IconListItem* pItem = static_cast<_IconListItem*>(__pListModel->LoadItem(DEFAULT_GROUP_INDEX, i));
2403 _VisualElement* pVE = pItem->GetItemVisualElement();
2406 AddAccessibilityElement(*pItem, pVE->GetBounds());
2413 _IconListPresenter::AddAccessibilityElement(_IconListItem& item, const FloatRectangle& rect)
2415 if (likely(!(_AccessibilityManager::IsActivated())))
2420 _AccessibilityContainer* pContainer = __pIconListView->GetAccessibilityContainer();
2421 if (pContainer != null)
2423 _AccessibilityElement* pElement = new (std::nothrow) _AccessibilityElement(true);
2424 SysTryReturnVoidResult(NID_UI_CTRL, (pElement != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2425 pElement->SetLabel(item.GetText());
2426 pElement->SetTrait(ACCESSIBILITY_TRAITS_IMAGE);
2427 pElement->SetValue(item.IsChecked() ? L"selected" : L"");
2428 pElement->SetBounds(_CoordinateSystemUtils::ConvertToInteger(rect));
2429 pContainer->AddElement(*pElement);
2434 _IconListPresenter::RemoveAllAccessibilityElements(void)
2436 _AccessibilityContainer* pContainer = __pIconListView->GetAccessibilityContainer();
2437 if (pContainer != null)
2439 pContainer->RemoveAllElement();
2444 _IconListPresenter::TranslateIconListItemPosition(float& x, float& y)
2446 if (_FloatCompareLE(__unitLengthOfAxis, 0.0f) || _FloatCompareLE(__unitScrollLength, 0.0f))
2453 if (__scrollDirection == ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL)
2455 x -= __startPosOfAxis;
2456 if (!_FloatCompareGE(x, 0.0f))
2463 x = x - static_cast<int> (x / __unitLengthOfAxis) * __unitLengthOfAxis;
2465 y += __scrollPosition - __topMargin;
2466 if (!_FloatCompareGE(y, 0.0f))
2473 y = y - static_cast<int> (y / __unitScrollLength) * __unitScrollLength;
2477 y -= __startPosOfAxis;
2478 if (!_FloatCompareGE(y, 0.0f))
2485 y = y - static_cast<int> (y - __unitLengthOfAxis) * __unitLengthOfAxis;
2487 x += __scrollPosition - __leftMargin;
2488 if (!_FloatCompareGE(x, 0.0f))
2495 x = x - static_cast<int> (x / __unitScrollLength) * __unitScrollLength;
2500 _IconListPresenter::StartTouchActionTimer(void)
2502 result r = E_SUCCESS;
2504 if (__pTouchActionTimer == null)
2506 __pTouchActionTimer = new (std::nothrow) Timer;
2507 SysTryReturn(NID_UI_CTRL, (__pTouchActionTimer != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2509 r = __pTouchActionTimer->Construct(*this);
2510 SysTryCatch(NID_UI, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
2514 __pTouchActionTimer->Cancel();
2517 r = __pTouchActionTimer->Start(TOUCH_ACTION_TIMER_PERIOD);
2518 SysTryCatch(NID_UI, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
2523 ResetTouchActionTimer();
2528 _IconListPresenter::ResetTouchActionTimer(void)
2530 delete __pTouchActionTimer;
2531 __pTouchActionTimer = null;
2537 _IconListPresenter::StartMagneticScrollTimer(void)
2539 result r = E_SUCCESS;
2541 if (__pMagneticScrollTimer == null)
2543 __pMagneticScrollTimer = new (std::nothrow) Timer;
2544 SysTryReturn(NID_UI_CTRL, (__pMagneticScrollTimer != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2546 r = __pMagneticScrollTimer->Construct(*this);
2547 SysTryCatch(NID_UI, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
2551 __pMagneticScrollTimer->Cancel();
2554 r = __pMagneticScrollTimer->Start(MAGNETIC_SCROLL_TIMER_PERIOD);
2555 SysTryCatch(NID_UI, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
2560 ResetMagneticScrollTimer();
2565 _IconListPresenter::ResetMagneticScrollTimer(void)
2567 if (__pMagneticScrollTimer != null)
2569 FireScrollStoppedEvent();
2572 delete __pMagneticScrollTimer;
2573 __pMagneticScrollTimer = null;
2579 _IconListPresenter::StartReorderScrollTimer(void)
2581 result r = E_SUCCESS;
2583 if (__pReorderScrollTimer == null)
2585 __pReorderScrollTimer = new (std::nothrow) Timer;
2586 SysTryReturn(NID_UI_CTRL, (__pReorderScrollTimer != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2588 r = __pReorderScrollTimer->Construct(*this);
2589 SysTryCatch(NID_UI, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
2593 __pReorderScrollTimer->Cancel();
2596 r = __pReorderScrollTimer->Start(REORDER_SCROLL_TIMER_PERIOD);
2597 SysTryCatch(NID_UI, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
2602 ResetReorderScrollTimer();
2607 _IconListPresenter::ResetReorderScrollTimer(void)
2609 delete __pReorderScrollTimer;
2610 __pReorderScrollTimer = null;
2616 _IconListPresenter::StartAnimationTimer(int delay)
2618 result r = E_SUCCESS;
2620 if (__pAnimationTimer == null)
2622 __pAnimationTimer = new (std::nothrow) Timer;
2623 SysTryReturn(NID_UI_CTRL, (__pAnimationTimer != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2625 r = __pAnimationTimer->Construct(*this);
2626 SysTryCatch(NID_UI, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
2630 __pAnimationTimer->Cancel();
2633 r = __pAnimationTimer->Start(delay);
2634 SysTryCatch(NID_UI, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
2639 ResetAnimationTimer();
2645 _IconListPresenter::ResetAnimationTimer(void)
2647 delete __pAnimationTimer;
2648 __pAnimationTimer = null;
2653 // Tizen::Ui::_ControlImpl
2655 _IconListPresenter::OnBoundsChanged(void)
2657 __isLayoutChanged = true;
2659 if (__pIconListView->GetScroll() != null)
2661 __pIconListView->GetScroll()->OnParentBoundsChanged();
2666 _IconListPresenter::OnFontInfoRequested(unsigned long& style, float& size)
2668 style = FONT_STYLE_PLAIN;
2670 if (__pListModel->GetItemCountInGroup(DEFAULT_GROUP_INDEX) <= 0)
2672 size = __pIconListView->GetTextSizeOfEmptyList();
2676 size = __pItemDrawingProperty->GetTextSize();
2681 _IconListPresenter::OnFontChanged(Font* pFont)
2683 ClearVisualElement();
2684 __pItemDrawingProperty->SetFont(pFont);
2687 // Tizen::Ui::_IKeyEventPreviewer
2689 _IconListPresenter::OnPreviewKeyPressed(const _Control& source, const _KeyInfo& keyInfo)
2695 _IconListPresenter::OnPreviewKeyReleased(const _Control& source, const _KeyInfo& keyInfo)
2700 // Tizen::Ui::_IKeyEventListener
2702 _IconListPresenter::OnKeyPressed(const _Control& source, const _KeyInfo& keyInfo)
2708 _IconListPresenter::OnKeyReleased(const _Control& source, const _KeyInfo& keyInfo)
2713 // Tizen::Ui::_INotificationEventPreviewer
2715 _IconListPresenter::OnPreviewNotifiedN(const _Control& source, IList* pArgs)
2721 // Tizen::Ui::_INotificationEventListener
2723 _IconListPresenter::OnNotifiedN(const _Control& source, IList* pArgs)
2729 // Tizen::Ui::_ITouchEventPreviewer
2730 _UiTouchEventDelivery
2731 _IconListPresenter::OnPreviewTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
2733 if (__selectedIndex < 0)
2735 // handle the event of touch release that occurred from thumb style scrollbar
2736 _Scroll* pScroll = __pIconListView->GetScroll();
2737 if (pScroll != null && pScroll->IsEnabledHandler())
2739 // Trigger Magnetic Scroll Effect
2740 if ((__pMagneticScrollTimer == null) && (!__flickRunning) && (__magneticScrollSize > 0))
2742 float diff = GetMagneticScrollPosition() - __scrollPosition;
2745 ResetMagneticScrollTimer();
2747 // Trigger Magnetic Scroll Effect
2748 __magneticScrollAnimation.StartAnimation(diff);
2749 StartMagneticScrollTimer();
2757 if ((__pMagneticScrollTimer == null) && (!__flickRunning))
2764 return _UI_TOUCH_EVENT_DELIVERY_YES;
2767 // Tizen::Ui::_ITouchEventListener
2769 _IconListPresenter::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
2771 __currentTouchInfo = touchinfo;
2772 __isTouchPressed = true;
2774 _Scroll* pScroll = __pIconListView->GetScroll();
2775 if (pScroll != null)
2777 float scrollPosition = pScroll->GetScrollPosition();
2778 if (!_FloatCompare(scrollPosition, __scrollPosition))
2780 pScroll->SetScrollPosition(__scrollPosition);
2784 StopAllAnimations();
2787 ResetAnimationTimer();
2788 ResetTouchActionTimer();
2789 ResetMagneticScrollTimer();
2790 StartTouchActionTimer();
2796 _IconListPresenter::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
2798 __isTouchPressed = false;
2799 __firstTouchMove = true;
2800 int fireIndex = INVALID_INDEX;;
2805 PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_LIST_REORDER);
2809 if (__selectedIndex >= 0)
2811 fireIndex = __selectedIndex;
2812 __isSelectionDelayed = false;
2814 PreDrawCheckAnimation(fireIndex);
2815 FireEventAfterTouchRelease(fireIndex);
2817 if (__isTouchAnimationEnabled)
2819 StartSelectAnimation(fireIndex);
2823 DrawCheckAnimation(fireIndex);
2826 else if (__pTouchActionTimer != null)
2828 ResetTouchActionTimer();
2829 if (OnTouchActionActivated(*__pIconListView, __currentTouchInfo))
2831 fireIndex = __selectedIndex;
2832 __isSelectionDelayed = true;
2834 PreDrawCheckAnimation(fireIndex);
2835 FireEventAfterTouchRelease(fireIndex);
2837 if (__isTouchAnimationEnabled)
2839 StartSelectAnimation(fireIndex);
2843 DrawCheckAnimation(fireIndex);
2849 // Trigger Magnetic Scroll Effect
2850 if ((__pMagneticScrollTimer == null) && (!__flickRunning) && (__magneticScrollSize > 0))
2852 float diff = GetMagneticScrollPosition() - __scrollPosition;
2853 if (!_FloatCompare(diff, 0.0f))
2855 ResetMagneticScrollTimer();
2857 // Trigger Magnetic Scroll Effect
2858 __magneticScrollAnimation.StartAnimation(diff);
2859 StartMagneticScrollTimer();
2867 if ((__pMagneticScrollTimer == null) && (!__flickRunning))
2869 if (__pIconListView->GetScroll()->GetScrollVisibility())
2872 InitializeAccessibilityElement();
2880 _IconListPresenter::FireEventAfterTouchRelease(int index)
2882 if (index >= 0 && __pListModel->IsItemEnabled(DEFAULT_GROUP_INDEX, index))
2884 if (__selectedOverlayBitmapId >= 0)
2886 FireIconListViewItemEvent(EVENT_TYPE_OVERLAY_BITMAP_SELECTED, index, __selectedOverlayBitmapId);
2890 switch (__pIconListView->GetStyle())
2892 case ICON_LIST_VIEW_STYLE_NORMAL:
2894 FireIconListViewItemEvent(EVENT_TYPE_ITEM_SELECTED, index, ICON_LIST_VIEW_ITEM_SELECTED);
2898 case ICON_LIST_VIEW_STYLE_RADIO:
2900 FireIconListViewItemEvent(EVENT_TYPE_ITEM_SELECTED, index, ICON_LIST_VIEW_ITEM_CHECKED);
2901 InitializeAccessibilityElement();
2905 case ICON_LIST_VIEW_STYLE_MARK:
2907 bool isChecked = __pListModel->IsItemChecked(DEFAULT_GROUP_INDEX, index);
2908 InitializeAccessibilityElement();
2912 FireIconListViewItemEvent(EVENT_TYPE_ITEM_SELECTED, index, ICON_LIST_VIEW_ITEM_CHECKED);
2916 FireIconListViewItemEvent(EVENT_TYPE_ITEM_SELECTED, index, ICON_LIST_VIEW_ITEM_UNCHECKED);
2921 PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_TAP);
2926 _IconListPresenter::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
2928 const FloatPoint movedPosition = touchinfo.GetCurrentPosition();
2930 if (__pTouchActionTimer != null)
2932 ResetAnimationTimer();
2933 ResetTouchActionTimer();
2935 int revertIndex = __selectedIndex;
2936 __selectedIndex = INVALID_INDEX;
2937 __selectedOverlayBitmapId = -1;
2938 RedrawItem(revertIndex);
2941 if (__pIconListView == null || !__isTouchPressed)
2943 __currentTouchInfo = touchinfo;
2947 FloatPoint pressedPosition = __currentTouchInfo.GetCurrentPosition();
2951 DoReordering(movedPosition);
2955 if (__pIconListView->GetScrollInputMode() == SCROLL_INPUT_MODE_RESTRICT_TO_INITIAL_DIRECTION)
2957 float scrollDistanceX = _Abs(pressedPosition.x - movedPosition.x);
2958 float scrollDistanceY = _Abs(pressedPosition.y - movedPosition.y);
2960 bool isVerticalDirection = scrollDistanceY > scrollDistanceX;
2961 bool isHorizontalDirection = scrollDistanceX > scrollDistanceY;
2963 if (__firstTouchMove)
2965 if (isVerticalDirection)
2967 __firstTouchMoveDirection = ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL;
2969 else if (isHorizontalDirection)
2971 __firstTouchMoveDirection = ICON_LIST_VIEW_SCROLL_DIRECTION_HORIZONTAL;
2975 __firstTouchMoveDirection = __scrollDirection;
2977 __firstTouchMove = false;
2980 if (__scrollDirection != __firstTouchMoveDirection)
2982 if (__firstTouchMoveDirection == ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL && !isHorizontalDirection)
2986 else if (__firstTouchMoveDirection == ICON_LIST_VIEW_SCROLL_DIRECTION_HORIZONTAL && !isVerticalDirection)
2994 if (__firstTouchMoveDirection == ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL && isHorizontalDirection)
2998 else if (__firstTouchMoveDirection == ICON_LIST_VIEW_SCROLL_DIRECTION_HORIZONTAL && isVerticalDirection)
3005 float scrollPosition = __scrollPosition;
3007 _Scroll* pScroll = __pIconListView->GetScroll();
3008 if (pScroll != null)
3010 scrollPosition = pScroll->GetScrollPosition();
3013 if (__scrollDirection == ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL)
3015 scrollPosition += pressedPosition.y - movedPosition.y;
3019 scrollPosition += pressedPosition.x - movedPosition.x;
3022 __currentTouchInfo = touchinfo;
3024 if (SetScrollPosition(scrollPosition))
3027 __selectedIndex = INVALID_INDEX;
3028 __pIconListView->Invalidate();
3030 // Trigger ScrollEvent
3040 _IconListPresenter::OnTouchActionActivated(const _Control& source, const _TouchInfo& touchinfo)
3042 if (__pListModel == null || __pIconListView == null)
3047 if (__pIconListView->IsInReorderingMode())
3049 __lastReorderedPosition = touchinfo.GetCurrentPosition();
3050 PrepareReordering();
3051 __lastReorderedDifferences.x = touchinfo.GetCurrentPosition().x - __reorderItemBounds.x;
3052 __lastReorderedDifferences.y = touchinfo.GetCurrentPosition().y - __reorderItemBounds.y;
3056 FloatPoint touchPressedPosition = touchinfo.GetCurrentPosition();
3057 int index = GetItemIndexFromPosition(touchPressedPosition);
3058 if (index >= 0 && __pListModel->IsItemEnabled(DEFAULT_GROUP_INDEX, index))
3060 __selectedIndex = index;
3061 __selectedOverlayBitmapId = -1;
3062 _IconListItem* pItem = dynamic_cast<_IconListItem*>(__pListModel->LoadItem(DEFAULT_GROUP_INDEX, index));
3065 pItem->SetDrawingProperty(*__pItemDrawingProperty);
3067 TranslateIconListItemPosition(touchPressedPosition.x, touchPressedPosition.y);
3068 if (_FloatCompareGE(touchPressedPosition.x, 0.0f) && _FloatCompareGE(touchPressedPosition.y, 0.0f))
3070 __selectedOverlayBitmapId = pItem->GetOverlayBitmapIdFromPosition(touchPressedPosition);
3074 bool flag = __isTouchAnimationEnabled;
3075 __isTouchAnimationEnabled = false;
3081 __isTouchAnimationEnabled = true;
3093 _IconListPresenter::OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
3095 StopScrollToAnimation();
3097 ResetAnimationTimer();
3098 ResetTouchActionTimer();
3099 ResetMagneticScrollTimer();
3100 ResetReorderScrollTimer();
3102 __isTouchPressed = false;
3103 __firstTouchMove = true;
3110 _IconListPresenter::OnFlickGestureDetected(bool isFlicked, const Point& flickPosition, int flickTime)
3114 StopAllAnimations();
3116 ResetAnimationTimer();
3117 ResetTouchActionTimer();
3118 ResetMagneticScrollTimer();
3120 __flickRunning = true;
3122 float targetPosition = __scrollPosition;
3123 if (__scrollDirection == ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL && flickPosition.y != 0)
3125 targetPosition -= CalculateFlickAmount(flickPosition.y, flickTime);
3127 else if (__scrollDirection == ICON_LIST_VIEW_SCROLL_DIRECTION_HORIZONTAL && flickPosition.x != 0)
3129 targetPosition -= CalculateFlickAmount(flickPosition.x, flickTime);
3132 if (_FloatCompareLE(targetPosition, OVERSCROLLING_MAX_DISTANCE * -1))
3134 targetPosition = (OVERSCROLLING_MAX_DISTANCE * -1);
3136 else if (_FloatCompareGE(targetPosition, __scrollLength + OVERSCROLLING_MAX_DISTANCE))
3138 targetPosition = (__scrollLength + OVERSCROLLING_MAX_DISTANCE);
3140 else if (__magneticScrollSize > 0)
3142 targetPosition = GetMagneticScrollPosition(targetPosition);
3145 StartScrollToAnimation(targetPosition);
3151 _IconListPresenter::OnLongPressGestureDetected(void)
3157 _IconListPresenter::OnTimerExpired(Timer& timer)
3159 if (&timer == __pTouchActionTimer)
3161 OnTouchActionActivated(*__pIconListView, __currentTouchInfo);
3163 else if (&timer == __pMagneticScrollTimer)
3165 float scrollPosition = 0.0f;
3166 if (__magneticScrollAnimation.GetMagneticScrollAnimationFrame(scrollPosition))
3168 scrollPosition += __pIconListView->GetScroll()->GetScrollPosition();
3169 if (SetScrollPosition(scrollPosition))
3171 StartMagneticScrollTimer();
3172 __pIconListView->Invalidate();
3174 FireScrollPositionChangedEvent(__scrollPosition);
3179 ResetMagneticScrollTimer();
3181 if (!__flickRunning)
3185 FireScrollStoppedEvent();
3186 InitializeAccessibilityElement();
3190 else if (&timer == __pReorderScrollTimer)
3192 StartReorderScrollAnimation();
3194 else if (&timer == __pAnimationTimer)
3196 int index = __animationItemIndex;
3197 ResetAnimationTimer();
3199 // start add animation
3200 _IconListItem* pItem = dynamic_cast <_IconListItem*>(__pListModel->LoadItem(DEFAULT_GROUP_INDEX, index));
3201 SysTryReturnVoidResult(NID_UI_CTRL, (pItem != null), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
3203 AddAnimation(*pItem, index);
3208 _IconListPresenter::StartReorderScrollAnimation(void)
3210 float scrollPosition = __scrollPosition;
3211 scrollPosition += __reorderScrollAnimationDistance;
3213 if (SetScrollPosition(scrollPosition))
3215 __pIconListView->Invalidate();
3216 FireScrollPositionChangedEvent(__scrollPosition);
3218 if (!_FloatCompareLE(__scrollPosition, 0.0f) && !_FloatCompareGE(__scrollPosition, __scrollLength))
3220 StartReorderScrollTimer();
3226 _IconListPresenter::OnVisibleStateChanged(void)
3228 StopScrollToAnimation();
3230 ResetAnimationTimer();
3231 ResetTouchActionTimer();
3232 ResetMagneticScrollTimer();
3233 ResetReorderScrollTimer();
3237 _IconListPresenter::OnInputEnableStateChanged(void)
3239 if (__selectedIndex != INVALID_INDEX)
3241 int inputEnableIndex = __selectedIndex;
3242 __selectedIndex = INVALID_INDEX;
3243 RedrawItem(inputEnableIndex);
3247 // Tizen::Ui::_IScrollEventListener
3249 _IconListPresenter::OnScrollEndReached(_Control& source, ScrollEndEvent type)
3252 FireScrollEndReachedEvent(type);
3256 _IconListPresenter::OnScrollPositionChanged(_Control& source, float scrollPosition)
3258 StopScrollToAnimation();
3260 if (SetScrollPosition(scrollPosition))
3262 __selectedIndex = INVALID_INDEX;
3263 __pIconListView->Invalidate();
3271 _IconListPresenter::OnScrollStopped(_Control& source)
3273 FireScrollStoppedEvent();
3274 InitializeAccessibilityElement();
3278 _IconListPresenter::OnScrollJumpToTop(_Control& source)
3280 StopScrollToAnimation();
3282 if (SetScrollPosition(0.0f))
3284 __selectedIndex = INVALID_INDEX;
3285 __pIconListView->Invalidate();
3292 // Tizen::Ui::Animations::IAnimationTransactionEventListener
3294 _IconListPresenter::OnAnimationTransactionStarted(int transactionId)
3299 _IconListPresenter::OnAnimationTransactionStopped(int transactionId)
3301 if (__addTransactionId == transactionId)
3303 __animationItemIndex = INVALID_INDEX;
3304 __addTransactionId = 0;
3305 __pPreviousAnimationVE->SetOpacity(1.0f);
3306 RedrawItem(__previousAnimationItemIndex);
3308 else if (__removeTransactionId == transactionId)
3310 __removeTransactionId = 0;
3312 if (__pRemoveItemVE != null)
3314 _VisualElement* pParent = __pIconListView->GetVisualElement();
3315 if (pParent != null)
3317 pParent->DetachChild(*__pRemoveItemVE);
3319 __pRemoveItemVE->Destroy();
3320 __pRemoveItemVE = null;
3324 else if (__moveTransactionId == transactionId)
3326 __moveTransactionId = 0;
3329 ClearVisualElement();
3331 if (__pIconListView != null)
3333 __pIconListView->Invalidate();
3338 _IconListPresenter::OnAnimationTransactionFinished(int transactionId)
3340 if (__addTransactionId == transactionId)
3342 __addTransactionId = 0;
3343 RedrawItem(__animationItemIndex);
3344 __animationItemIndex = INVALID_INDEX;
3346 else if (__removeTransactionId == transactionId)
3348 __removeTransactionId = 0;
3350 if (__pRemoveItemVE != null)
3352 _VisualElement* pParent = __pIconListView->GetVisualElement();
3353 if (pParent != null)
3355 pParent->DetachChild(*__pRemoveItemVE);
3357 __pRemoveItemVE->Destroy();
3358 __pRemoveItemVE = null;
3361 else if (__moveTransactionId == transactionId)
3363 __moveTransactionId = 0;
3367 // Tizen::Ui::Animations::IVisualElementAnimationTickEventListener
3369 _IconListPresenter::OnTickOccurred(const VisualElementAnimation& animation, const String& keyName, VisualElement& target, const Variant& currentValue)
3371 if (&target != __pIconListView->GetVisualElement() && &target != __pCheckAnimationVE)
3376 if (keyName == L"ScrollAnimation")
3378 if (SetScrollPosition(currentValue.ToFloat()))
3380 __pIconListView->Invalidate();
3383 FireScrollPositionChangedEvent(__scrollPosition);
3386 if (keyName == L"CheckAnimation")
3388 Canvas* pCanvas = __pCheckAnimationVE->GetCanvasN();
3390 if (pCanvas == null)
3395 const Bitmap* pBitmap = null;
3396 pBitmap = IsItemChecked(__checkedIndex) ? __pItemDrawingProperty->GetCheckBitmap(): null;
3398 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
3401 SysLogException(NID_UI_CTRL, E_SUCCESS, "currentValue %f", currentValue.ToFloat());
3402 if (pBitmap != null)
3404 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pBitmap))
3406 pCanvas->DrawNinePatchedBitmap(FloatRectangle(0.0f, 0.0f, pBitmap->GetWidthF(), pBitmap->GetHeightF()), *pBitmap);
3410 pCanvas->DrawBitmap(FloatRectangle(0.0f, 0.0f, pBitmap->GetWidthF()*currentValue.ToFloat()/1000.0f, pBitmap->GetHeightF()*currentValue.ToFloat()/1000.0f), *pBitmap, FloatRectangle(0.0f, 0.0f, pBitmap->GetWidthF()*currentValue.ToFloat()/1000.0f, pBitmap->GetHeightF()*currentValue.ToFloat()/1000.0f));
3417 // Tizen::Ui::Animations::IVisualElementAnimationStatusEventListener
3419 _IconListPresenter::OnVisualElementAnimationStarted(const VisualElementAnimation& animation, const String& keyName, VisualElement& target)
3422 if (keyName == L"CheckAnimation")
3424 RedrawItem(__checkedIndex);
3429 _IconListPresenter::OnVisualElementAnimationRepeated(const VisualElementAnimation& animation, const String& keyName, VisualElement& target, long currentRepeatCount)
3435 _IconListPresenter::OnVisualElementAnimationFinished(const VisualElementAnimation& animation, const String& keyName, VisualElement& target, bool completedNormally)
3437 if (keyName == L"ScrollAnimation")
3439 if (&target != __pIconListView->GetVisualElement())
3444 __flickRunning = false;
3446 FireScrollPositionChangedEvent(__scrollPosition);
3447 FireScrollStoppedEvent();
3450 if (keyName == L"SelectAnimation")
3452 if (&target != __pIconListView->GetVisualElement() && &target != __pPreviousSelectAnimationVE && &target != __pSelectAnimationVE)
3457 int index = __selectedIndex;
3458 __selectedIndex = INVALID_INDEX;
3460 if (!completedNormally)
3462 if (__pIconListView->GetStyle() == ICON_LIST_VIEW_STYLE_RADIO)
3464 if (__checkedIndex != __checkedRadioIndex)
3466 RedrawItem(__checkedIndex);
3467 RedrawItem(__checkedRadioIndex);
3474 DrawCheckAnimation(index);
3476 __isSelectAnimationRunning = false;
3479 if (keyName == L"CheckAnimation")
3481 if (&target != __pIconListView->GetVisualElement() && &target != __pPreviousCheckAnimationVE && &target != __pCheckAnimationVE)
3486 int index = __checkedIndex;
3487 __checkedIndex = INVALID_INDEX;
3489 if (!completedNormally)
3493 __isCheckAnimationRunning = false;
3498 _IconListPresenter::PrepareReordering(void)
3500 int index = GetItemIndexFromPosition(__lastReorderedPosition);
3501 if (__onReordering || index == INVALID_INDEX)
3506 __onReordering = true;
3507 __reorderFromIndex = index;
3508 __reorderToIndex = index;
3510 if (__pListModel->IsValidItem(DEFAULT_GROUP_INDEX, __reorderToIndex))
3512 _IconListItem* pToItem = static_cast <_IconListItem*>(__pListModel->LoadItem(DEFAULT_GROUP_INDEX, __reorderToIndex));
3513 if (pToItem != null)
3515 _VisualElement* pItemVE = pToItem->GetItemVisualElement();
3516 if (pItemVE != null)
3518 __reorderItemBounds = pItemVE->GetBounds();
3519 pItemVE->SetImplicitAnimationEnabled(false);
3520 RedrawItem(__reorderToIndex);
3525 ClearReorderingInformation();
3530 ClearReorderingInformation();
3535 _IconListPresenter::DoReordering(const FloatPoint& movedPosition)
3537 if (__pListModel->IsValidItem(DEFAULT_GROUP_INDEX, __reorderToIndex))
3539 _IconListItem* pToItem = static_cast <_IconListItem*>(__pListModel->LoadItem(DEFAULT_GROUP_INDEX, __reorderToIndex));
3540 if (pToItem != null)
3542 _VisualElement* pItemVE = pToItem->GetItemVisualElement();
3543 if (pItemVE != null)
3545 FloatRectangle rect = pItemVE->GetBounds();
3546 pItemVE->SetShowState(true);
3547 pItemVE->SetImplicitAnimationEnabled(false);
3548 pItemVE->SetBounds(FloatRectangle(movedPosition.x - __lastReorderedDifferences.x, movedPosition.y - __lastReorderedDifferences.y, rect.width, rect.height));
3550 if (__scrollDirection == ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL)
3552 if (!_FloatCompareGE(movedPosition.y, __topMargin))
3554 __reorderScrollAnimationDistance = -REORDER_SCROLL_ANIMATION_DISTANCE;
3555 if (__pReorderScrollTimer == null && !_FloatCompareLE(__scrollPosition, 0.0f))
3557 __scrollPositionBeforeScrollAnimation = __scrollPosition;
3558 StartReorderScrollTimer();
3561 else if (!_FloatCompareLE(movedPosition.y + __lastReorderedDifferences.y, __pIconListView->GetBounds().height - __bottomMargin) &&
3562 !_FloatCompareGE(__scrollPosition, __scrollLength))
3564 __reorderScrollAnimationDistance = REORDER_SCROLL_ANIMATION_DISTANCE;
3565 if (__pReorderScrollTimer == null)
3567 __scrollPositionBeforeScrollAnimation = __scrollPosition;
3568 StartReorderScrollTimer();
3573 if (__pReorderScrollTimer == null)
3575 CheckAndReorderItem(movedPosition.x - __lastReorderedPosition.x, movedPosition.y - __lastReorderedPosition.y);
3579 ResetReorderScrollTimer();
3580 float diff = __scrollPositionBeforeScrollAnimation - __scrollPosition;
3581 int rowCount = static_cast<int> (diff / __unitScrollLength);
3582 int index = __reorderToIndex - rowCount * __itemCountPerAxis;
3583 __reorderItemBounds.y += diff;
3584 SwapReorderedItems(index, false);
3585 __lastReorderedPosition.y += rowCount * __itemCountPerAxis - __verticalSpacing;
3591 if (!_FloatCompareGE(movedPosition.x, __leftMargin) && !_FloatCompareLE(__scrollPosition, 0.0f))
3593 __reorderScrollAnimationDistance = -REORDER_SCROLL_ANIMATION_DISTANCE;
3594 if (__pReorderScrollTimer == null)
3596 __scrollPositionBeforeScrollAnimation = __scrollPosition;
3597 StartReorderScrollTimer();
3600 else if (!_FloatCompareLE(movedPosition.x + __lastReorderedDifferences.x, __pIconListView->GetBounds().width - __rightMargin) &&
3601 !_FloatCompareGE(__scrollPosition, __scrollLength))
3603 __reorderScrollAnimationDistance = REORDER_SCROLL_ANIMATION_DISTANCE;
3604 if (__pReorderScrollTimer == null)
3606 __scrollPositionBeforeScrollAnimation = __scrollPosition;
3607 StartReorderScrollTimer();
3612 if (__pReorderScrollTimer == null)
3614 CheckAndReorderItem(movedPosition.x - __lastReorderedPosition.x, movedPosition.y - __lastReorderedPosition.y);
3618 ResetReorderScrollTimer();
3619 float diff = __scrollPositionBeforeScrollAnimation - __scrollPosition;
3620 int rowCount = static_cast<int> (diff / __unitScrollLength);
3621 int index = __reorderToIndex - rowCount * __itemCountPerAxis;
3622 __reorderItemBounds.x += diff;
3623 SwapReorderedItems(index, false);
3624 __lastReorderedPosition.x += rowCount * __itemCountPerAxis - __horizontalSpacing;
3634 _IconListPresenter::CheckAndReorderItem(float movedX, float movedY)
3637 bool toDown = false;
3638 bool toLeft = false;
3639 bool toRight = false;
3641 bool singleItemChanged = true;
3643 float horizontalThreshold = (GetItemSize().width + __verticalSpacing) / 2;
3644 float verticalThreshold = (GetItemSize().height + __verticalSpacing) / 2;
3646 if (!_FloatCompareLE(_Abs(movedX), horizontalThreshold))
3648 if (!_FloatCompareLE(movedX, 0.0f))
3658 if (!_FloatCompareLE(_Abs(movedY), verticalThreshold))
3660 if (!_FloatCompareLE(movedY, 0.0f))
3670 int toIndex = INVALID_INDEX;
3672 if (__scrollDirection == ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL)
3676 if (__reorderToIndex % __itemCountPerAxis != 0)
3678 toIndex = __reorderToIndex - 1;
3679 __lastReorderedPosition.x -= __unitLengthOfAxis;
3684 if (__reorderToIndex % __itemCountPerAxis != __itemCountPerAxis - 1)
3686 toIndex = __reorderToIndex + 1;
3687 __lastReorderedPosition.x += __unitLengthOfAxis;
3692 if (__reorderToIndex >= __itemCountPerAxis)
3694 toIndex = __reorderToIndex - __itemCountPerAxis;
3695 __lastReorderedPosition.y -= __unitScrollLength;
3697 singleItemChanged = false;
3702 if (__reorderToIndex + __itemCountPerAxis < __pListModel->GetAllItemCount())
3704 toIndex = __reorderToIndex +__itemCountPerAxis;
3705 __lastReorderedPosition.y += __unitScrollLength;
3707 singleItemChanged = false;
3715 if (__reorderToIndex % __itemCountPerAxis != 0)
3717 toIndex = __reorderToIndex - 1;
3718 __lastReorderedPosition.y -= __unitLengthOfAxis;
3723 if (__reorderToIndex % __itemCountPerAxis != __itemCountPerAxis - 1)
3725 toIndex = __reorderToIndex + 1;
3726 __lastReorderedPosition.y += __unitLengthOfAxis;
3731 if (__reorderToIndex >= __itemCountPerAxis)
3733 toIndex = __reorderToIndex - __itemCountPerAxis;
3734 __lastReorderedPosition.x -= __unitScrollLength;
3736 singleItemChanged = false;
3741 if (__reorderToIndex + __itemCountPerAxis < __pListModel->GetAllItemCount())
3743 toIndex = __reorderToIndex +__itemCountPerAxis;
3744 __lastReorderedPosition.x += __unitScrollLength;
3746 singleItemChanged = false;
3751 if (toIndex != INVALID_INDEX)
3753 SwapReorderedItems(toIndex, singleItemChanged);
3758 _IconListPresenter::SwapReorderedItems(int toIndex, bool singleItemChanged)
3764 else if (toIndex >= __pListModel->GetAllItemCount())
3766 toIndex -= __itemCountPerAxis;
3769 _IconListItem* pItem = null;
3770 _IconListItem* pTempItem = null;
3771 _VisualElement* pToItemVE = null;
3772 _VisualElement* pToTempItemVE = null;
3773 FloatRectangle tempBounds;
3775 if (singleItemChanged)
3777 pItem = static_cast<_IconListItem*>(__pListModel->LoadItem(DEFAULT_GROUP_INDEX, toIndex));
3780 pToItemVE = pItem->GetItemVisualElement();
3782 if (pToItemVE != null)
3784 FloatRectangle bounds = pToItemVE->GetBounds();
3785 if (bounds.IsEmpty())
3787 bounds = GetItemBounds(toIndex);
3789 pToItemVE->SetImplicitAnimationEnabled(false);
3790 pToItemVE->SetBounds(bounds);
3793 FloatRectangle temp = __reorderItemBounds;
3794 __reorderItemBounds.SetPosition(bounds.x, bounds.y);
3795 pToItemVE->SetImplicitAnimationEnabled(true);
3796 pToItemVE->SetBounds(temp);
3797 pToItemVE->SetImplicitAnimationEnabled(false);
3802 if (__reorderToIndex > toIndex)
3804 for (int i = toIndex; i < __reorderToIndex; i++)
3806 pItem = static_cast<_IconListItem*>(__pListModel->LoadItem(DEFAULT_GROUP_INDEX, i));
3807 pTempItem = static_cast<_IconListItem*>(__pListModel->LoadItem(DEFAULT_GROUP_INDEX, i + 1));
3808 if (pItem != null && pTempItem != null)
3810 pToItemVE = pItem->GetItemVisualElement();
3811 pToTempItemVE = pTempItem->GetItemVisualElement();
3814 if (pToItemVE != null && pToTempItemVE != null)
3816 FloatRectangle temp = pToTempItemVE->GetBounds();
3819 temp = GetItemBounds(i + 1);
3821 pToTempItemVE->SetImplicitAnimationEnabled(false);
3822 pToTempItemVE->SetBounds(temp);
3827 tempBounds = pToItemVE->GetBounds();
3828 if (tempBounds.IsEmpty())
3830 tempBounds = GetItemBounds(toIndex);
3832 pToItemVE->SetImplicitAnimationEnabled(false);
3833 pToItemVE->SetBounds(tempBounds);
3836 else if (i == __reorderToIndex -1)
3838 temp = __reorderItemBounds;
3839 __reorderItemBounds.SetPosition(tempBounds.x, tempBounds.y);
3841 pToItemVE->SetImplicitAnimationEnabled(true);
3842 pToItemVE->SetBounds(temp);
3843 pToItemVE->SetImplicitAnimationEnabled(false);
3849 for (int i = toIndex; i > __reorderToIndex; i--)
3851 pItem = static_cast<_IconListItem*>(__pListModel->LoadItem(DEFAULT_GROUP_INDEX, i));
3852 pTempItem = static_cast<_IconListItem*>(__pListModel->LoadItem(DEFAULT_GROUP_INDEX, i - 1));
3853 if (pItem != null && pTempItem != null)
3855 pToItemVE = pItem->GetItemVisualElement();
3856 pToTempItemVE = pTempItem->GetItemVisualElement();
3859 if (pToItemVE != null && pToTempItemVE != null)
3861 FloatRectangle temp = pToTempItemVE->GetBounds();
3864 temp = GetItemBounds(i - 1);
3866 pToTempItemVE->SetImplicitAnimationEnabled(false);
3867 pToTempItemVE->SetBounds(temp);
3872 tempBounds = pToItemVE->GetBounds();
3873 if (tempBounds.IsEmpty())
3875 tempBounds = GetItemBounds(toIndex);
3877 pToItemVE->SetImplicitAnimationEnabled(false);
3878 pToItemVE->SetBounds(tempBounds);
3881 else if (i == __reorderToIndex + 1)
3883 temp = __reorderItemBounds;
3884 __reorderItemBounds.SetPosition(tempBounds.x, tempBounds.y);
3887 pToItemVE->SetImplicitAnimationEnabled(true);
3888 pToItemVE->SetBounds(temp);
3889 pToItemVE->SetImplicitAnimationEnabled(false);
3895 __pListModel->MoveItem(DEFAULT_GROUP_INDEX, __reorderToIndex, DEFAULT_GROUP_INDEX, toIndex);
3896 __reorderToIndex = toIndex;
3900 _IconListPresenter::FinishReordering(void)
3902 if (__pListModel->IsValidItem(DEFAULT_GROUP_INDEX, __reorderToIndex))
3904 if (__reorderFromIndex != __reorderToIndex)
3906 FireIconListViewItemEvent(EVENT_TYPE_ITEM_REORDERED , __reorderFromIndex, __reorderToIndex);
3907 for (int i = _Min(__reorderFromIndex, __reorderToIndex); i <= _Max(__reorderFromIndex, __reorderToIndex); i++)
3914 RedrawItem(__reorderToIndex);
3917 ResetReorderScrollTimer();
3918 ClearReorderingInformation();
3922 _IconListPresenter::ClearReorderingInformation(void)
3924 __onReordering = false;
3925 __reorderFromIndex = INVALID_INDEX;
3926 __reorderToIndex = INVALID_INDEX;
3927 __reorderItemBounds.SetBounds(0.0f, 0.0f, 0.0f, 0.0f);
3930 // visual interaction animation
3932 _IconListPresenter::StartScrollToAnimation(float targetPosition)
3934 __pVE->RemoveAnimation(L"ScrollAnimation");
3936 VisualElementValueAnimation* pScrollingAnimation = __pIconListView->GetScrollingAnimation();
3937 pScrollingAnimation->SetStartValue(Variant(__scrollPosition));
3938 pScrollingAnimation->SetEndValue(Variant(targetPosition));
3939 pScrollingAnimation->SetDuration(FLICK_ANIMATION_DURATION);
3940 __pVE->AddAnimation(L"ScrollAnimation", *pScrollingAnimation);
3944 _IconListPresenter::StopScrollToAnimation(void)
3946 __pVE->RemoveAnimation(L"ScrollAnimation");
3950 _IconListPresenter::StopAllAnimations(void)
3952 __pVE->RemoveAnimation(L"ScrollAnimation");
3954 if (__isTouchAnimationEnabled && __isSelectAnimationRunning)
3956 if (__pSelectAnimationVE != null)
3958 __pSelectAnimationVE->RemoveAnimation(L"SelectAnimation");
3961 if (__previousIndex > INVALID_INDEX && __pListModel->IsLoadedItem(DEFAULT_GROUP_INDEX, __previousIndex))
3963 if (__pPreviousSelectAnimationVE != null)
3965 __pPreviousSelectAnimationVE->RemoveAnimation(L"SelectAnimation");
3970 if (__pIconListView->GetStyle() != ICON_LIST_VIEW_STYLE_NORMAL && __isCheckAnimationRunning)
3972 if (__pCheckAnimationVE != null)
3974 __pCheckAnimationVE->RemoveAnimation(L"CheckAnimation");
3977 if (__previousCheckIndex> INVALID_INDEX && __pListModel->IsLoadedItem(DEFAULT_GROUP_INDEX, __previousCheckIndex))
3979 if (__pPreviousCheckAnimationVE != null)
3981 __pPreviousCheckAnimationVE->RemoveAnimation(L"CheckAnimation");
3988 _IconListPresenter::AddAnimation(_IconListItem& item, int index, int delay)
3990 _VisualElement* pVE = item.GetItemVisualElement();
3993 pVE->SetImplicitAnimationEnabled(true);
3994 FloatRectangle endRect(GetItemBounds(index));
3995 FloatRectangle startRect(endRect.x + (endRect.width * 0.15f), endRect.y + (endRect.height * 0.15f), endRect.width * 0.7f, endRect.height * 0.7f);
3997 if (IsAnimationRunning(__addTransactionId))
3999 AnimationTransaction::Stop(__addTransactionId);
4002 AnimationTransaction::Begin(__addTransactionId);
4003 AnimationTransaction::SetVisualElementAnimationTimingFunction(VisualElementAnimation::GetTimingFunctionByName("EaseInOut"));
4004 AnimationTransaction::SetVisualElementAnimationDuration(ITEM_ANIMATION_DURATION);
4005 AnimationTransaction::SetVisualElementAnimationDelay(delay);
4007 // opacity animation
4008 VisualElementPropertyAnimation* pOpacityAnimation = new (std::nothrow) VisualElementPropertyAnimation();
4009 SysTryReturnVoidResult(NID_UI_CTRL, (pOpacityAnimation != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
4011 pOpacityAnimation->SetPropertyName(L"opacity");
4012 pOpacityAnimation->SetStartValue(Variant(0.0f));
4013 pOpacityAnimation->SetEndValue(Variant(1.0f));
4015 pVE->AddAnimation(L"AddItemOpacityAnimation", *pOpacityAnimation);
4016 delete pOpacityAnimation;
4019 VisualElementPropertyAnimation* pScaleAnimation = new (std::nothrow) VisualElementPropertyAnimation();
4020 SysTryReturnVoidResult(NID_UI_CTRL, (pScaleAnimation != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
4022 pScaleAnimation->SetPropertyName(L"bounds");
4023 pScaleAnimation->SetStartValue(Variant(startRect));
4024 pScaleAnimation->SetEndValue(Variant(endRect));
4026 pVE->AddAnimation(L"AddItemScaleAnimation", *pScaleAnimation);
4027 delete pScaleAnimation;
4029 pVE->SetImplicitAnimationEnabled(false);
4031 AnimationTransaction::Commit();
4032 __previousAnimationItemIndex = index;
4033 __pPreviousAnimationVE = pVE;
4038 _IconListPresenter::RemoveAnimation(_IconListItem& item, int index)
4040 result r = E_SUCCESS;
4041 Canvas* pCanvas = null;
4042 _VisualElement* pItemVE = item.GetItemVisualElement();
4043 if (pItemVE != null)
4045 if (__pRemoveItemVE != null)
4047 __pRemoveItemVE->Destroy();
4048 __pRemoveItemVE = null;
4051 FloatRectangle startRect = pItemVE->GetBounds();
4052 FloatRectangle endRect = FloatRectangle(startRect.x + (startRect.width * 0.1f), startRect.y + (startRect.height * 0.1f), startRect.width * 0.8f, startRect.height * 0.8f);
4054 __pRemoveItemVE = new (std::nothrow) _VisualElement();
4055 SysTryReturnVoidResult(NID_UI_CTRL, __pRemoveItemVE != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
4057 r = __pRemoveItemVE->Construct();
4058 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
4060 __pRemoveItemVE->SetSurfaceOpaque(false);
4061 __pRemoveItemVE->SetShowState(true);
4062 __pRemoveItemVE->SetImplicitAnimationEnabled(false);
4064 r = __pRemoveItemVE->SetBounds(startRect);
4065 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
4067 _VisualElement* pParent = __pIconListView->GetVisualElement();
4068 pParent->AttachChild(*__pRemoveItemVE);
4070 pCanvas = __pRemoveItemVE->GetCanvasN();
4071 SysTryCatch(NID_UI_CTRL, (pCanvas != null), , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
4074 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
4075 r = pItemVE->Capture(*pCanvas, FloatRectangle(0.0f, 0.0f, startRect.width, startRect.height), false);
4076 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
4079 if (IsAnimationRunning(__removeTransactionId))
4081 AnimationTransaction::Stop(__removeTransactionId);
4084 AnimationTransaction::Begin(__removeTransactionId);
4087 VisualElementPropertyAnimation* pScaleAnimation = new (std::nothrow) VisualElementPropertyAnimation();
4088 SysTryReturnVoidResult(NID_UI_CTRL, (pScaleAnimation != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
4090 pScaleAnimation->SetTimingFunction(VisualElementAnimation::GetTimingFunctionByName("EaseInOut"));
4091 pScaleAnimation->SetPropertyName(L"bounds");
4092 pScaleAnimation->SetStartValue(Variant(startRect));
4093 pScaleAnimation->SetEndValue(Variant(endRect));
4094 pScaleAnimation->SetDuration(ITEM_ANIMATION_DURATION);
4096 String scaleAnimationName(L"RemoveItemScaleAnimation");
4097 __pRemoveItemVE->AddAnimation(scaleAnimationName, *pScaleAnimation);
4098 delete pScaleAnimation;
4100 // opacity animation
4101 VisualElementPropertyAnimation* pOpacityAnimation = new (std::nothrow) VisualElementPropertyAnimation();
4102 SysTryReturnVoidResult(NID_UI_CTRL, (pOpacityAnimation != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
4104 pOpacityAnimation->SetTimingFunction(VisualElementAnimation::GetTimingFunctionByName("EaseInOut"));
4105 pOpacityAnimation->SetPropertyName(L"opacity");
4106 pOpacityAnimation->SetStartValue(Variant(1.0f));
4107 pOpacityAnimation->SetEndValue(Variant(0.0f));
4108 pOpacityAnimation->SetDuration(ITEM_ANIMATION_DURATION);
4110 String opacityAnimationName(L"RemoveItemOpacityAnimation");
4111 __pRemoveItemVE->AddAnimation(opacityAnimationName, *pOpacityAnimation);
4112 delete pOpacityAnimation;
4114 AnimationTransaction::Commit();
4123 _IconListPresenter::MoveAnimation(_IconListItem& item, FloatRectangle& bounds, int delay)
4125 _VisualElement* pVE = item.GetItemVisualElement();
4128 pVE->SetImplicitAnimationEnabled(false);
4129 pVE->SetShowState(true);
4132 VisualElementPropertyAnimation* pMoveAnimation = new (std::nothrow) VisualElementPropertyAnimation();
4133 SysTryReturnVoidResult(NID_UI_CTRL, (pMoveAnimation != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
4135 FloatRectangle startRect = pVE->GetBounds();
4137 pMoveAnimation->SetTimingFunction(VisualElementAnimation::GetTimingFunctionByName("EaseInOut"));
4138 pMoveAnimation->SetPropertyName(L"bounds");
4139 pMoveAnimation->SetStartValue(Variant(startRect));
4140 pMoveAnimation->SetEndValue(Variant(bounds));
4141 pMoveAnimation->SetDuration(MOVE_ITEM_ANIMATION_DURATION);
4142 pMoveAnimation->SetDelay(delay);
4144 String moveAnimationName(L"MoveItemAnimation");
4145 pVE->AddAnimation(moveAnimationName, *pMoveAnimation);
4146 delete pMoveAnimation;
4151 _IconListPresenter::MoveAnimation(_IconListItem& item, FloatRectangle& startBounds, FloatRectangle& endBounds, int delay)
4153 if (!item.IsDrawn())
4155 item.SetDrawingProperty(*__pItemDrawingProperty);
4156 item.DrawItem(startBounds, LIST_ITEM_STATE_NORMAL);
4159 _VisualElement* pVE = item.GetItemVisualElement();
4162 pVE->SetImplicitAnimationEnabled(false);
4163 pVE->SetShowState(true);
4166 VisualElementPropertyAnimation* pMoveAnimation = new (std::nothrow) VisualElementPropertyAnimation();
4167 SysTryReturnVoidResult(NID_UI_CTRL, (pMoveAnimation != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
4169 FloatRectangle startRect = pVE->GetBounds();
4171 pMoveAnimation->SetTimingFunction(VisualElementAnimation::GetTimingFunctionByName("EaseInOut"));
4172 pMoveAnimation->SetPropertyName(L"bounds");
4173 pMoveAnimation->SetStartValue(Variant(startBounds));
4174 pMoveAnimation->SetEndValue(Variant(endBounds));
4175 pMoveAnimation->SetDuration(MOVE_ITEM_ANIMATION_DURATION);
4176 pMoveAnimation->SetDelay(delay);
4178 String moveAnimationName(L"MoveItemAnimation");
4179 pVE->AddAnimation(moveAnimationName, *pMoveAnimation);
4180 delete pMoveAnimation;
4185 _IconListPresenter::MoveAnimation(_IconListItem& item, FloatRectangle& bounds, int delay, bool fadeIn)
4187 _VisualElement* pVE = item.GetItemVisualElement();
4190 pVE->SetImplicitAnimationEnabled(false);
4192 // opacity animation
4193 VisualElementPropertyAnimation* pOpacityAnimation = new (std::nothrow) VisualElementPropertyAnimation();
4194 SysTryReturnVoidResult(NID_UI_CTRL, (pOpacityAnimation != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
4196 pOpacityAnimation->SetTimingFunction(VisualElementAnimation::GetTimingFunctionByName("EaseInOut"));
4197 pOpacityAnimation->SetPropertyName(L"opacity");
4201 pOpacityAnimation->SetStartValue(Variant(0.0f));
4202 pOpacityAnimation->SetEndValue(Variant(1.0f));
4206 pOpacityAnimation->SetStartValue(Variant(1.0f));
4207 pOpacityAnimation->SetEndValue(Variant(0.0f));
4210 pOpacityAnimation->SetDuration(MOVE_ITEM_ANIMATION_DURATION);
4212 String opacityAnimationName(L"MoveItemOpacityAnimation");
4213 pVE->AddAnimation(opacityAnimationName, *pOpacityAnimation);
4214 delete pOpacityAnimation;
4217 VisualElementPropertyAnimation* pMoveAnimation = new (std::nothrow) VisualElementPropertyAnimation();
4218 SysTryReturnVoidResult(NID_UI_CTRL, (pMoveAnimation != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
4220 FloatRectangle startRect = pVE->GetBounds();
4222 pMoveAnimation->SetTimingFunction(VisualElementAnimation::GetTimingFunctionByName("EaseInOut"));
4223 pMoveAnimation->SetPropertyName(L"bounds");
4224 pMoveAnimation->SetStartValue(Variant(startRect));
4225 pMoveAnimation->SetEndValue(Variant(bounds));
4226 pMoveAnimation->SetDuration(MOVE_ITEM_ANIMATION_DURATION);
4227 pMoveAnimation->SetDelay(delay);
4229 String moveAnimationName(L"MoveItemAnimation");
4230 pVE->AddAnimation(moveAnimationName, *pMoveAnimation);
4231 delete pMoveAnimation;
4236 _IconListPresenter::RemoveAllAnimation(_IconListItem& item)
4238 _VisualElement* pVE = item.GetItemVisualElement();
4241 pVE->RemoveAllAnimations();
4246 _IconListPresenter::MoveForward(int index)
4248 int itemCount = __pListModel->GetItemCountInGroup(DEFAULT_GROUP_INDEX);
4249 if (index < 0 || index >= itemCount)
4255 if (__scrollDirection == ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL)
4257 float bottomPosition = __scrollPosition + __pIconListView->GetBounds().height;
4258 bottomLine = (bottomPosition - __topMargin + __verticalSpacing) / __unitScrollLength;
4262 float bottomPosition = __scrollPosition + __pIconListView->GetBounds().width;
4263 bottomLine = (bottomPosition - __leftMargin + __horizontalSpacing) / __unitScrollLength;
4266 int startIndex = index;
4267 int endIndex = (bottomLine + 1) * __itemCountPerAxis;
4268 endIndex = endIndex >= itemCount ? itemCount - 1 : endIndex;
4269 if (startIndex > endIndex)
4275 _IconListItem* pItem = null;
4276 _VisualElement* pItemVE = null;
4278 if (IsAnimationRunning(__moveTransactionId))
4280 AnimationTransaction::Stop(__moveTransactionId);
4283 AnimationTransaction::Begin(__moveTransactionId);
4285 FloatRectangle startBounds;
4286 FloatRectangle endBounds;
4287 for (int i = startIndex; i <= endIndex; i++)
4289 startBounds = GetItemBounds(i);
4290 endBounds = GetItemBounds(i - 1);
4291 if (!endBounds.IsEmpty() && !startBounds.IsEmpty())
4293 pItem = static_cast<_IconListItem*>(__pListModel->LoadItem(DEFAULT_GROUP_INDEX, i));
4296 pItemVE = pItem->GetItemVisualElement();
4297 if (pItemVE != null)
4299 MoveAnimation(*pItem, startBounds, endBounds, ITEM_ANIMATION_DELAY);
4304 AnimationTransaction::Commit();
4308 _IconListPresenter::MoveBackward(int index)
4310 int itemCount = __pListModel->GetItemCountInGroup(DEFAULT_GROUP_INDEX);
4311 if (index < 0 || index >= itemCount)
4317 if (__scrollDirection == ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL)
4319 float bottomPosition = __scrollPosition + __pIconListView->GetBounds().height;
4320 bottomLine = (bottomPosition - __topMargin + __verticalSpacing) / __unitScrollLength;
4324 float bottomPosition = __scrollPosition + __pIconListView->GetBounds().width;
4325 bottomLine = (bottomPosition - __leftMargin + __horizontalSpacing) / __unitScrollLength;
4328 int endIndex = index;
4329 int startIndex = (bottomLine + 1) * __itemCountPerAxis;
4330 startIndex = startIndex >= itemCount ? itemCount - 1 : startIndex;
4332 if (startIndex < endIndex)
4338 _IconListItem* pItem = null;
4339 _VisualElement* pItemVE = null;
4341 if (IsAnimationRunning(__moveTransactionId))
4343 AnimationTransaction::Stop(__moveTransactionId);
4346 AnimationTransaction::Begin(__moveTransactionId);
4348 FloatRectangle startBounds;
4349 FloatRectangle endBounds;
4350 for (int i = startIndex; i >= endIndex; i--)
4352 startBounds = GetItemBounds(i);
4353 endBounds = GetItemBounds(i + 1);
4354 if (!startBounds.IsEmpty() && !endBounds.IsEmpty())
4356 pItem = static_cast<_IconListItem*>(__pListModel->LoadItem(DEFAULT_GROUP_INDEX, i));
4359 pItemVE = pItem->GetItemVisualElement();
4360 if (pItemVE != null)
4362 MoveAnimation(*pItem, startBounds, endBounds, 0);
4367 AnimationTransaction::Commit();
4371 _IconListPresenter::IsAnimationRunning(int transactionId)
4373 if (AnimationTransaction::GetStatus(transactionId) == ANIMATION_TRANSACTION_STATUS_PLAYING)
4382 _IconListPresenter::StartSelectAnimation(int index)
4384 if (index <= INVALID_INDEX)
4387 if (__previousIndex > INVALID_INDEX && __pPreviousSelectAnimationVE != null)
4389 if (__pListModel->IsLoadedItem(DEFAULT_GROUP_INDEX, __previousIndex) && __isSelectAnimationRunning)
4391 __pPreviousSelectAnimationVE->RemoveAnimation(L"SelectAnimation");
4395 _IconListItem* pItem = static_cast<_IconListItem*>(__pListModel->LoadItem(DEFAULT_GROUP_INDEX, index));
4396 __pSelectAnimationVE = pItem->GetSelectAniVisualElement();
4397 if (__pSelectAnimationVE == null)
4401 __pSelectAnimationVE->RemoveAllAnimations();
4403 FloatRectangle startFloatRect = __pSelectAnimationVE->GetBounds();
4404 FloatRectangle endFloatRect;
4405 endFloatRect = FloatRectangle(startFloatRect.x + startFloatRect.width*0.5f/2, startFloatRect.y + startFloatRect.height*0.5f/2, startFloatRect.width*0.5f, startFloatRect.height*0.5f);
4407 VisualElementPropertyAnimation* pSelectAnimation = new (std::nothrow) VisualElementPropertyAnimation();
4408 SysTryReturnVoidResult(NID_UI_CTRL, (pSelectAnimation != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
4410 pSelectAnimation->SetTimingFunction(VisualElementAnimation::GetTimingFunctionByName("EaseInOut"));
4411 pSelectAnimation->SetPropertyName(L"bounds");
4412 pSelectAnimation->SetAutoReverseEnabled(true);
4413 pSelectAnimation->SetStartValue(Variant(startFloatRect));
4414 pSelectAnimation->SetEndValue(Variant(endFloatRect));
4415 pSelectAnimation->SetDuration(TOUCH_ACTION_TIMER_PERIOD);
4416 pSelectAnimation->SetVisualElementAnimationStatusEventListener(__pIconListView);
4417 __pSelectAnimationVE->AddAnimation(L"SelectAnimation", *pSelectAnimation);
4418 delete pSelectAnimation;
4420 __isSelectAnimationRunning = true;
4421 __pPreviousSelectAnimationVE = __pSelectAnimationVE;
4422 __previousIndex = index;
4426 _IconListPresenter::StartCheckAnimation(int index)
4428 if (index <= INVALID_INDEX)
4431 _IconListItem* pItem = static_cast<_IconListItem*>(__pListModel->LoadItem(DEFAULT_GROUP_INDEX, index));
4433 if (__previousCheckIndex >= 0 && __pPreviousCheckAnimationVE !=null && __isCheckAnimationRunning)
4435 if (__pListModel->IsLoadedItem(DEFAULT_GROUP_INDEX, __previousCheckIndex))
4437 __pPreviousCheckAnimationVE->RemoveAnimation(L"CheckAnimation");
4441 const Bitmap* pBackgroundBitmap = __pListModel->IsItemEnabled(DEFAULT_GROUP_INDEX, index) ? (IsItemChecked(index) ? __pItemDrawingProperty->GetCheckedBackgroundBitmap() : __pItemDrawingProperty->GetUnCheckedBackgroundBitmap()) : __pItemDrawingProperty->GetDisabledCheckBitmap();
4443 Canvas* pCheckBgCanvas = pItem->GetCheckBGVisualElement()->GetCanvasN();
4445 if (pCheckBgCanvas == null)
4450 pCheckBgCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
4451 pCheckBgCanvas->Clear();
4453 // draw background of check box
4454 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pBackgroundBitmap))
4456 pCheckBgCanvas->DrawNinePatchedBitmap(FloatRectangle(0.0f, 0.0f, pBackgroundBitmap->GetWidthF(), pBackgroundBitmap->GetHeightF()), *pBackgroundBitmap);
4460 pCheckBgCanvas->DrawBitmap(FloatRectangle(0.0f, 0.0f, pBackgroundBitmap->GetWidthF(), pBackgroundBitmap->GetHeightF()), *pBackgroundBitmap);
4463 delete pCheckBgCanvas;
4465 __pCheckAnimationVE = pItem->GetCheckAniVisualElement();
4466 if (__pCheckAnimationVE == null)
4470 __pCheckAnimationVE->RemoveAllAnimations();
4472 VisualElementValueAnimation* pCheckAnimation = new (std::nothrow) VisualElementValueAnimation();
4473 pCheckAnimation->SetStartValue(Variant(0.0f));
4474 pCheckAnimation->SetEndValue(Variant(1000.0f));
4475 pCheckAnimation->SetDuration(150);
4476 pCheckAnimation->SetVisualElementAnimationTickEventListener(__pIconListView);
4477 pCheckAnimation->SetVisualElementAnimationStatusEventListener(__pIconListView);
4479 __pCheckAnimationVE->AddAnimation(L"CheckAnimation", *pCheckAnimation);
4480 __isCheckAnimationRunning = true;
4481 __pPreviousCheckAnimationVE = __pCheckAnimationVE;
4482 __previousCheckIndex = index;
4487 _IconListPresenter::DrawCheckAnimation(int index)
4489 result r = GetLastResult();
4490 __selectedIndex = INVALID_INDEX;
4492 switch (__pIconListView->GetStyle())
4494 case ICON_LIST_VIEW_STYLE_NORMAL:
4499 case ICON_LIST_VIEW_STYLE_RADIO:
4501 if (index != __checkedRadioIndex)
4503 if (__checkedRadioIndex >= 0 && __pListModel->IsLoadedItem(DEFAULT_GROUP_INDEX, __checkedRadioIndex))
4505 r = RedrawItem(__checkedRadioIndex);
4507 __checkedIndex = index;
4508 StartCheckAnimation(index);
4516 case ICON_LIST_VIEW_STYLE_MARK:
4518 InitializeAccessibilityElement();
4520 if (__isItemChecked)
4522 r = RedrawItem(index);
4526 __checkedIndex = index;
4527 StartCheckAnimation(index);
4533 __isItemChecked = false;
4539 _IconListPresenter::PreDrawCheckAnimation(int index)
4541 switch (__pIconListView->GetStyle())
4543 case ICON_LIST_VIEW_STYLE_NORMAL:
4548 case ICON_LIST_VIEW_STYLE_RADIO:
4550 __checkedRadioIndex = __pListModel->GetIndexOfRadioCheckedItem(0);
4551 __pListModel->SetItemChecked(DEFAULT_GROUP_INDEX, index, true);
4554 case ICON_LIST_VIEW_STYLE_MARK:
4556 __isItemChecked = __pListModel->IsItemChecked(DEFAULT_GROUP_INDEX, index);
4557 __pListModel->SetItemChecked(DEFAULT_GROUP_INDEX, index, !__isItemChecked);
4562 }}} // Tizen::Ui::Controls