Merge "fixed bug (TapGesture improvement)" into tizen_2.1
[platform/framework/native/uifw.git] / src / ui / controls / FUiCtrl_IconListPresenter.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an ”AS IS” BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file                FUiCtrl_IconListPresenter.cpp
20  * @brief               This is the implementation file for the _IconListPresenter class.
21  */
22
23 //Includes
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>
31
32 #include "FUi_AccessibilityElement.h"
33 #include "FUi_AccessibilityManager.h"
34 #include "FUi_CoordinateSystemUtils.h"
35 #include "FUi_Math.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"
50
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;
58
59 namespace {
60 const int SCROLL_PANEL_FIXED_FLICK_AMOUNT = 1000;
61 }
62
63 namespace Tizen { namespace Ui { namespace Controls
64 {
65
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)
81         , __topMargin(0.0f)
82         , __bottomMargin(0.0f)
83         , __leftMargin(0.0f)
84         , __rightMargin(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)
108         , __onDrawing(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)
120         , __pVE(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)
142 {
143 }
144
145 _IconListPresenter::~_IconListPresenter(void)
146 {
147         Dispose();
148 }
149
150 _IconListPresenter*
151 _IconListPresenter::CreateInstanceN(_IconListView& pIconListView)
152 {
153         _IconListPresenter* pIconListPresenter = null;
154         _IconListItemDrawingProperty* pItemDrawingProperty = null;
155
156         // Create _ListModel
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.");
159
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.");
163
164         // Create _IconListItemDrawingProperty
165         pItemDrawingProperty = _IconListItemDrawingProperty::CreateInstanceN();
166         SysTryCatch(NID_UI_CTRL, (pItemDrawingProperty != null), , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
167         pIconListPresenter->__pItemDrawingProperty = pItemDrawingProperty;
168
169         // Initialize _IconListPresenter
170         pIconListPresenter->Initialize();
171
172         return pIconListPresenter;
173
174 CATCH:
175         delete pListModel;
176         delete pIconListPresenter;
177
178         return null;
179 }
180
181 result
182 _IconListPresenter::Dispose(void)
183 {
184         delete __pListModel;
185         __pListModel = null;
186
187         delete __pItemProviderAdaptor;
188         __pItemProviderAdaptor = null;
189
190         __pIconListView = null;
191
192         delete __pItemDrawingProperty;
193         __pItemDrawingProperty = null;
194
195         delete __pTouchActionTimer;
196         __pTouchActionTimer = null;
197
198         delete __pMagneticScrollTimer;
199         __pMagneticScrollTimer = null;
200
201         delete __pReorderScrollTimer;
202         __pReorderScrollTimer = null;
203
204         delete __pAnimationTimer;
205         __pAnimationTimer = null;
206
207         if (__pRemoveItemVE != null)
208         {
209                 __pRemoveItemVE->Destroy();
210                 __pRemoveItemVE = null;
211         }
212
213         if (__pEmptyListVE != null)
214         {
215                 __pEmptyListVE->Destroy();
216                 __pEmptyListVE = null;
217         }
218
219         return E_SUCCESS;
220 }
221
222 result
223 _IconListPresenter::Initialize(void)
224 {
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);
230
231         __pVE = __pIconListView->GetVisualElement();
232         __pVE->SetClipChildrenEnabled(true);
233         __pVE->SetSurfaceOpaque(false);
234
235         return E_SUCCESS;
236 }
237
238 result
239 _IconListPresenter::InitializeFont(void)
240 {
241         Font* pFont = __pIconListView->GetFallbackFont();
242         SysTryReturn(NID_UI_CTRL, (pFont != null), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
243
244         return __pItemDrawingProperty->SetFont(pFont);
245 }
246
247 result
248 _IconListPresenter::SetItemProvider(const IIconListViewItemProvider& provider)
249 {
250         _IconListItemProviderAdaptor* pAdaptor = static_cast <_IconListItemProviderAdaptor*>(__pListModel->GetItemProviderAdaptor());
251
252         if (pAdaptor == null)
253         {
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.");
257         }
258         else
259         {
260                 // Remove All Items
261                 __pListModel->RemoveAllItem();
262         }
263
264         // Set Item Provider
265         pAdaptor->SetItemProvider(const_cast <IIconListViewItemProvider*>(&provider));
266
267         __isLayoutChanged = true;
268         __scrollPosition = 0.0f;
269
270         AdjustLayout();
271         InitializeFont();
272
273         return E_SUCCESS;
274 }
275
276 result
277 _IconListPresenter::RegisterItemProviderAdaptor(_IListItemProviderAdaptor* pItemProviderAdaptor)
278 {
279         // Remove All Items
280         __pListModel->RemoveAllItem();
281         __selectedIndex = INVALID_INDEX;
282         __highlightedIndex = INVALID_INDEX;
283         __isLayoutChanged = true;
284         __alreadyDrawn = false;
285
286         _IconListItemProviderAdaptor* pAdaptor = null;
287         bool enableCustomItemProviderAdaptor = true;
288         if (pItemProviderAdaptor == null)
289         {
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.");
294
295                 pAdaptor->SetVisualElement(__pIconListView->GetVisualElement());
296                 enableCustomItemProviderAdaptor = false;
297                 pItemProviderAdaptor = pAdaptor;
298         }
299
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));
304
305         if (enableCustomItemProviderAdaptor)
306         {
307                 __pListModel->AddGroup(0, __pIconListView->GetStyle() == ICON_LIST_VIEW_STYLE_RADIO);
308         }
309
310         __pItemProviderAdaptor = pItemProviderAdaptor;
311         __enableCustomItemProviderAdaptor = enableCustomItemProviderAdaptor;
312
313         return E_SUCCESS;
314
315 CATCH:
316         delete pAdaptor;
317
318         return r;
319 }
320
321 result
322 _IconListPresenter::SetScrollDirection(IconListViewScrollDirection scrollDirection)
323 {
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.");
327
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);
336
337         __scrollDirection = scrollDirection;
338         FloatRectangle bounds = __pIconListView->GetBoundsF();
339         if (scrollDirection == ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL)
340         {
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);
345         }
346         else
347         {
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);
352         }
353
354         return E_SUCCESS;
355 }
356
357 result
358 _IconListPresenter::SetMargin(MarginType type, float value)
359 {
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.");
361
362         switch (type)
363         {
364         case MARGIN_TYPE_TOP:
365                 if (!_FloatCompare(__topMargin, value))
366                 {
367                         __topMargin = value;
368                         AdjustLayout();
369                 }
370                 break;
371
372         case MARGIN_TYPE_BOTTOM:
373                 if (!_FloatCompare(__bottomMargin, value))
374                 {
375                         __bottomMargin = value;
376                         AdjustLayout();
377                 }
378                 break;
379
380         case MARGIN_TYPE_LEFT:
381                 if (!_FloatCompare(__leftMargin, value))
382                 {
383                         __leftMargin = value;
384                         AdjustLayout();
385                 }
386                 break;
387
388         case MARGIN_TYPE_RIGHT:
389                 if (!_FloatCompare(__rightMargin, value))
390                 {
391                         __rightMargin = value;
392                         AdjustLayout();
393                 }
394                 break;
395
396         default:
397                 SysLogException(NID_UI_CTRL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used.");
398                 return E_INVALID_ARG;
399         }
400         return E_SUCCESS;
401 }
402
403 float
404 _IconListPresenter::GetMargin(MarginType type) const
405 {
406         ClearLastResult();
407         switch (type)
408         {
409         case MARGIN_TYPE_TOP:
410                 return __topMargin;
411
412         case MARGIN_TYPE_BOTTOM:
413                 return __bottomMargin;
414
415         case MARGIN_TYPE_LEFT:
416                 return __leftMargin;
417
418         case MARGIN_TYPE_RIGHT:
419                 return __rightMargin;
420
421         default:
422                 SysLogException(NID_UI_CTRL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used.");
423                 return -1.0f;
424         }
425 }
426
427 result
428 _IconListPresenter::SetItemSpacing(float horizontalSpacing, float verticalSpacing)
429 {
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.");
432
433         if (!_FloatCompare(__horizontalSpacing, horizontalSpacing))
434         {
435                 __horizontalSpacing = horizontalSpacing;
436                 __isLayoutChanged = true;
437         }
438
439         if (!_FloatCompare(__verticalSpacing, verticalSpacing))
440         {
441                 __verticalSpacing = verticalSpacing;
442                 __isLayoutChanged = true;
443         }
444
445         if (__isLayoutChanged)
446         {
447                 AdjustLayout();
448         }
449
450         return E_SUCCESS;
451 }
452
453 float
454 _IconListPresenter::GetItemHorizontalSpacing(void) const
455 {
456         ClearLastResult();
457         return __horizontalSpacing;
458 }
459
460 float
461 _IconListPresenter::GetItemVerticalSpacing(void) const
462 {
463         ClearLastResult();
464         return __verticalSpacing;
465 }
466
467 void
468 _IconListPresenter::SetUseCheckedStyle(bool checkedStyle)
469 {
470         __pItemDrawingProperty->SetItemCheckedStyle(checkedStyle);
471 }
472
473 result
474 _IconListPresenter::SetItemChecked(int index, bool check)
475 {
476         if (__pListModel->GetAllGroupCount() == 0)
477         {
478                 SysTryReturn(NID_UI_CTRL, (__pItemProviderAdaptor != null), E_INVALID_STATE, E_INVALID_STATE,
479                                 "[E_INVALID_STATE] This instance isn't constructed.");
480
481                 int itemCount = __pItemProviderAdaptor->GetItemCount();
482                 if (itemCount < 0)
483                 {
484                         itemCount = 0;
485                 }
486
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.");
489
490                 // Add Group
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));
493         }
494         else
495         {
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.");
498         }
499
500         return __pListModel->SetItemChecked(DEFAULT_GROUP_INDEX, index, check);
501 }
502
503 bool
504 _IconListPresenter::IsItemChecked(int index) const
505 {
506         ClearLastResult();
507         return __pListModel->IsItemChecked(DEFAULT_GROUP_INDEX, index);
508 }
509
510 int
511 _IconListPresenter::GetItemIndexFromPosition(float x, float y) const
512 {
513         ClearLastResult();
514         if (_FloatCompareLE(__unitLengthOfAxis, 0.0f) || _FloatCompareLE(__unitScrollLength, 0.0f))
515         {
516                 return -1;
517         }
518
519         ClearLastResult();
520
521         int row = 0;
522         int col = 0;
523         int modX = 0;
524         int modY = 0;
525         int index = -1;
526
527         if (__scrollDirection == ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL)
528         {
529                 x -= __startPosOfAxis;
530                 if (!_FloatCompareGE(x, 0.0f))
531                 {
532                         return -1;
533                 }
534
535                 col = static_cast<int> (x / __unitLengthOfAxis);
536                 if (col >= __itemCountPerAxis)
537                 {
538                         return -1;
539                 }
540
541                 modX = x - (static_cast<int> (x / __unitLengthOfAxis) * __unitLengthOfAxis);
542                 if (_FloatCompareGE(modX, GetItemSize().width))
543                 {
544                         return -1;
545                 }
546
547                 y += __scrollPosition - __topMargin;
548                 if (!_FloatCompareGE(y, 0.0f))
549                 {
550                         return -1;
551                 }
552
553                 modY = y - (static_cast<int> (y / __unitScrollLength) * __unitScrollLength);
554                 if (_FloatCompareGE(modY, GetItemSize().height))
555                 {
556                         return -1;
557                 }
558
559                 row = static_cast<int> (y / __unitScrollLength);
560                 index = row * __itemCountPerAxis + col;
561                 if (index >= __pListModel->GetItemCountInGroup(DEFAULT_GROUP_INDEX))
562                 {
563                         return -1;
564                 }
565         }
566         else
567         {
568                 y -= __startPosOfAxis;
569                 if (!_FloatCompareGE(y, 0.0f))
570                 {
571                         return -1;
572                 }
573
574                 row = static_cast<int> (y / __unitLengthOfAxis);
575                 if (row >= __itemCountPerAxis)
576                 {
577                         return -1;
578                 }
579
580                 modY = y - (static_cast<int> (y / __unitLengthOfAxis) * __unitLengthOfAxis);
581                 if (_FloatCompareGE(modY, GetItemSize().height))
582                 {
583                         return -1;
584                 }
585
586                 x += __scrollPosition - __leftMargin;
587                 if (!_FloatCompareGE(x, 0.0f))
588                 {
589                         return -1;
590                 }
591
592                 modX = x - (static_cast<int> (x / __unitScrollLength) * __unitScrollLength);
593                 if (_FloatCompareGE(modX, GetItemSize().width))
594                 {
595                         return -1;
596                 }
597
598                 col = static_cast<int> (x / __unitScrollLength);
599                 index = col * __itemCountPerAxis + row;
600                 if (index >= __pListModel->GetItemCountInGroup(DEFAULT_GROUP_INDEX))
601                 {
602                         return -1;
603                 }
604         }
605
606         return index;
607 }
608
609 int
610 _IconListPresenter::GetItemIndexFromPosition(const FloatPoint& position) const
611 {
612         return GetItemIndexFromPosition(position.x, position.y);
613 }
614
615 result
616 _IconListPresenter::SetTextHorizontalAlignment(HorizontalAlignment alignment)
617 {
618         return __pItemDrawingProperty->SetTextHorizontalAlignment(alignment);
619 }
620
621 result
622 _IconListPresenter::SetTextVerticalAlignment(IconListViewItemTextVerticalAlignment alignment)
623 {
624         int itemHeight = __pItemDrawingProperty->GetItemSize().height;
625         result r = __pItemDrawingProperty->SetTextVerticalAlignment(alignment);
626         if (alignment >= ICON_LIST_VIEW_ITEM_TEXT_VERTICAL_ALIGNMENT_OUTSIDE_TOP)
627         {
628                 _ControlOrientation orientation = __pIconListView->GetOrientation();
629                 GET_SHAPE_CONFIG(ICONLIST::OUTSIDE_TEXT_VERTICAL_SPACING, orientation, __verticalSpacing);
630         }
631
632         if (itemHeight != __pItemDrawingProperty->GetItemSize().height)
633         {
634                 AdjustLayout();
635         }
636
637         return r;
638 }
639
640 HorizontalAlignment
641 _IconListPresenter::GetTextHorizontalAlignment(void) const
642 {
643         ClearLastResult();
644         return __pItemDrawingProperty->GetTextHorizontalAlignment();
645 }
646
647 IconListViewItemTextVerticalAlignment
648 _IconListPresenter::GetTextVerticalAlignment(void) const
649 {
650         ClearLastResult();
651         return __pItemDrawingProperty->GetTextVerticalAlignment();
652 }
653
654 result
655 _IconListPresenter::SetItemTextColor(IconListViewItemDrawingStatus status, const Color& color)
656 {
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.");
660
661         return __pItemDrawingProperty->SetTextColor(status, color);
662 }
663
664 const Color
665 _IconListPresenter::GetItemTextColor(IconListViewItemDrawingStatus status) const
666 {
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.");
670
671         return __pItemDrawingProperty->GetTextColor(status);
672 }
673
674 result
675 _IconListPresenter::SetItemTextSize(float size)
676 {
677         float itemHeight = __pItemDrawingProperty->GetItemSize().height;
678         result r = __pItemDrawingProperty->SetTextSize(size);
679
680         InitializeFont();
681
682         if (!_FloatCompare(itemHeight, __pItemDrawingProperty->GetItemSize().height))
683         {
684                 AdjustLayout();
685         }
686
687         return r;
688 }
689
690 float
691 _IconListPresenter::GetItemTextSize(void) const
692 {
693         return __pItemDrawingProperty->GetTextSize();
694 }
695
696 result
697 _IconListPresenter::SetCheckBoxPosition(IconListViewCheckBoxPosition position)
698 {
699         return __pItemDrawingProperty->SetCheckBoxPosition(position);
700 }
701
702 IconListViewCheckBoxPosition
703 _IconListPresenter::GetCheckBoxPosition(void) const
704 {
705         ClearLastResult();
706         return __pItemDrawingProperty->GetCheckBoxPosition();
707 }
708
709 result
710 _IconListPresenter::SetTouchAnimationEnabled(bool enable)
711 {
712         __isTouchAnimationEnabled = enable;
713         __previousTouchAnimatinEnabled = enable;
714
715         return E_SUCCESS;
716 }
717
718 bool
719 _IconListPresenter::IsTouchAnimationEnabled(void) const
720 {
721         ClearLastResult();
722         return __onReordering ? __previousTouchAnimatinEnabled : __isTouchAnimationEnabled;
723 }
724
725 result
726 _IconListPresenter::ScrollToItem(int index)
727 {
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.");
731
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.");
733
734         float scrollPosition = (index / __itemCountPerAxis) * __unitScrollLength;
735         if (__scrollDirection == ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL)
736         {
737                 scrollPosition += __topMargin;
738         }
739         else
740         {
741                 scrollPosition += __leftMargin;
742         }
743
744         if (SetScrollPosition(scrollPosition, false))
745         {
746                 ScrollFadeOut(true);
747                 FireScrollEvent();
748         }
749
750         return E_SUCCESS;
751 }
752
753 result
754 _IconListPresenter::ScrollByPixel(float pixel)
755 {
756         if (_FloatCompare(pixel, 0.0f))
757         {
758                 return E_SUCCESS;
759         }
760
761         if (SetScrollPosition(__scrollPosition + pixel, false))
762         {
763                 __pIconListView->Invalidate();
764                 ScrollFadeOut(true);
765                 FireScrollEvent();
766
767                 return E_SUCCESS;
768         }
769
770         return E_OUT_OF_RANGE;
771 }
772
773 result
774 _IconListPresenter::RefreshList(int index, ListRefreshType type)
775 {
776         SysTryReturn(NID_UI_CTRL, (__pItemProviderAdaptor != null), E_INVALID_STATE, E_INVALID_STATE,
777                                 "[E_INVALID_STATE] IconListViewItemProvider isn't added.");
778
779         SysTryReturn(NID_UI_CTRL, __alreadyDrawn, E_INVALID_OPERATION, E_INVALID_OPERATION,
780                                 "[E_INVALID_OPERATION] Unable to refresh IconListView before first drawn.");
781
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.");
785
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.");
788
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.");
791
792         if (__pAnimationTimer != null)
793         {
794                 ResetAnimationTimer();
795                 StopAllAnimations();
796                 Draw();
797         }
798
799         bool usingAnimation = false;
800         result r = E_SUCCESS;
801         switch (type)
802         {
803         case LIST_REFRESH_TYPE_ITEM_ADD:
804         {
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()));
807
808                 if ((__firstDrawnIndex <= index) && (__lastDrawnIndex >= index))
809                 {
810                         MoveBackward(index);
811                 }
812                 else if (__firstDrawnIndex > index)
813                 {
814                         MoveBackward(__firstDrawnIndex - 1);
815                         usingAnimation = true;
816                 }
817
818                 if (__pListModel->GetItemCountInGroup(DEFAULT_GROUP_INDEX) == 0)
819                 {
820                         __listStatusChanged = true;
821                 }
822
823                 r = InsertItemAt(index, pItem);
824                 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
825
826                 if (__listStatusChanged)
827                 {
828                         __pIconListView->Invalidate();
829                 }
830
831                 if (((__firstDrawnIndex <= index) && (__lastDrawnIndex >= index)) || (index == (__lastDrawnIndex + 1)))
832                 {
833                         if (index < itemCount)
834                         {
835                                 StartAnimationTimer(ITEM_ANIMATION_DELAY);
836                                 __animationItemIndex = index;
837                         }
838                         else
839                         {
840                                 AddAnimation(*pItem, index);
841                         }
842
843                         usingAnimation = true;
844                 }
845
846                 break;
847         }
848
849         case LIST_REFRESH_TYPE_ITEM_REMOVE:
850         {
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()));
853
854                 if ((__firstDrawnIndex <= index) && (__lastDrawnIndex >= index))
855                 {
856                         RemoveAnimation(*pItem, index);
857                         MoveForward(index + 1);
858                         usingAnimation = true;
859                 }
860                 else if (__firstDrawnIndex > index)
861                 {
862                         MoveForward(__firstDrawnIndex);
863                         usingAnimation = true;
864                 }
865
866                 r = RemoveItemAt(index);
867                 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
868
869                 if (__pListModel->GetItemCountInGroup(DEFAULT_GROUP_INDEX) == 0)
870                 {
871                         __listStatusChanged = true;
872                         __pIconListView->Invalidate();
873                         return r;
874                 }
875
876                 break;
877         }
878
879         case LIST_REFRESH_TYPE_ITEM_MODIFY:
880         {
881                 if (__pListModel->IsLoadedItem(DEFAULT_GROUP_INDEX , index) == false)
882                         return r;
883
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()));
886
887                 r = SetItemAt(index, pItem);
888                 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
889
890                 RedrawItem(index, 1.0f);
891                 return r;
892         }
893         }
894
895         if (usingAnimation)
896         {
897                 AdjustLayout();
898                 InitializeFont();
899
900                 UpdateDrawnIndex();
901         }
902
903         return r;
904 }
905
906 void
907 _IconListPresenter::UpdateDrawnIndex(void)
908 {
909         int drawingLine = 0;
910         int itemCount = __pListModel->GetItemCountInGroup(DEFAULT_GROUP_INDEX);
911         FloatRectangle itemRect(0.0f, 0.0f, GetItemSize().height, GetItemSize().width);
912
913         if (__scrollDirection == ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL)
914         {
915                 float endXPos = __endPosOfAxis;
916                 float endYPos = __pIconListView->GetBounds().height;
917
918                 drawingLine = (__scrollPosition > __topMargin) ? (__scrollPosition - __topMargin + __verticalSpacing) / __unitScrollLength : 0;
919                 itemRect.y = __topMargin + drawingLine * __unitScrollLength - __scrollPosition;
920
921                 int index = drawingLine * __itemCountPerAxis;
922                 __firstDrawnIndex = index;
923                 while(!_FloatCompareGE(itemRect.y, endYPos))
924                 {
925                         itemRect.x = __startPosOfAxis;
926                         while (!_FloatCompareGE(itemRect.x, endXPos) && (index < itemCount))
927                         {
928                                 ++index;
929                                 itemRect.x += __unitLengthOfAxis;
930                         }
931                         itemRect.y += __unitScrollLength;
932                 }
933                 __lastDrawnIndex = index - 1;
934         }
935         else
936         {
937                 float endXPos = __pIconListView->GetBounds().width;
938                 float endYPos = __endPosOfAxis;
939
940                 drawingLine = (__scrollPosition > __leftMargin) ? (__scrollPosition - __leftMargin + __horizontalSpacing) / __unitScrollLength : 0;
941                 itemRect.x = __leftMargin + drawingLine * __unitScrollLength - __scrollPosition;
942
943                 int index = drawingLine * __itemCountPerAxis;
944                 __firstDrawnIndex = index;
945                 while(!_FloatCompareGE(itemRect.x, endXPos))
946                 {
947                         itemRect.y = __startPosOfAxis;
948                         while (!_FloatCompareGE(itemRect.y, endYPos) && (index < itemCount))
949                         {
950                                 ++index;
951                                 itemRect.y += __unitLengthOfAxis;
952                         }
953                         itemRect.x += __unitScrollLength;
954                 }
955                 __lastDrawnIndex = index - 1;
956         }
957 }
958
959 result
960 _IconListPresenter::UpdateList(void)
961 {
962         SysTryReturn(NID_UI_CTRL, (__pItemProviderAdaptor != null), E_INVALID_STATE, E_INVALID_STATE,
963                         "[E_INVALID_STATE] IconListViewItemProvider isn't added.");
964
965         ResetTouchActionTimer();
966         ResetAnimationTimer();
967         StopAllAnimations();
968
969         result r = RemoveAllItems();
970         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
971
972         __selectedIndex = INVALID_INDEX;
973         __highlightedIndex = INVALID_INDEX;
974         __isLayoutChanged = true;
975         __alreadyDrawn = false;
976         __listStatusChanged = true;
977
978         AddGroupAndRestoreItem(true);
979
980         __pIconListView->Draw();
981         __pIconListView->Show();
982
983         return E_SUCCESS;
984 }
985
986 result
987 _IconListPresenter::SetItemBitmapBounds(const FloatRectangle& bounds)
988 {
989         result r = __pItemDrawingProperty->SetItemBitmapBounds(bounds);
990
991         if (r == E_SUCCESS)
992         {
993                 __isLayoutChanged = true;
994         }
995
996         return r;
997 }
998
999 FloatRectangle
1000 _IconListPresenter::GetItemBitmapBounds(void) const
1001 {
1002         return __pItemDrawingProperty->GetItemBitmapBounds();
1003 }
1004
1005 result
1006 _IconListPresenter::GetItemBitmapSize(float& width, float& height) const
1007 {
1008         FloatDimension itemSize = __pItemDrawingProperty->GetItemBitmapSize();
1009         width = itemSize.width;
1010         height = itemSize.height;
1011
1012         return E_SUCCESS;
1013 }
1014
1015 FloatDimension
1016 _IconListPresenter::GetItemBitmapSize(void) const
1017 {
1018         return __pItemDrawingProperty->GetItemBitmapSize();
1019 }
1020
1021 result
1022 _IconListPresenter::SetItemSize(const FloatDimension& size)
1023 {
1024         SysTryReturn(NID_UI_CTRL, (__pItemDrawingProperty != null), E_INVALID_STATE, E_INVALID_STATE,
1025                         "[E_INVALID_STATE] This instance isn't constructed.");
1026
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.");
1029
1030         __isLayoutChanged = true;
1031         return __pItemDrawingProperty->SetItemSize(size);
1032 }
1033
1034 result
1035 _IconListPresenter::GetItemSize(float& width, float& height) const
1036 {
1037         FloatDimension itemSize = __pItemDrawingProperty->GetItemSize();
1038         width = itemSize.width;
1039         height = itemSize.height;
1040
1041         return E_SUCCESS;
1042 }
1043
1044 FloatDimension
1045 _IconListPresenter::GetItemSize(void) const
1046 {
1047         return __pItemDrawingProperty->GetItemSize();
1048 }
1049
1050 result
1051 _IconListPresenter::SetMagneticScrollSize(int scrollSize)
1052 {
1053         SysTryReturn(NID_UI_CTRL, (__pItemProviderAdaptor != null), E_INVALID_STATE, E_INVALID_STATE,
1054                         "[E_INVALID_STATE] This instance isn't constructed.");
1055
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.");
1059
1060         __magneticScrollSize = scrollSize;
1061
1062         return E_SUCCESS;
1063 }
1064
1065 int
1066 _IconListPresenter::GetMagneticScrollSize(void) const
1067 {
1068         ClearLastResult();
1069         return __magneticScrollSize;
1070 }
1071
1072 void
1073 _IconListPresenter::SetItemCountPerAxis(int itemCountPerAxis)
1074 {
1075         SysTryReturnVoidResult(NID_UI_CTRL, (itemCountPerAxis >= 0), E_INVALID_ARG,
1076                         "[E_INVALID_ARG] Invalid argument is used. itemCountPerAxis is a non-negative integer.");
1077
1078         ClearLastResult();
1079         __itemCountPerAxis = itemCountPerAxis;
1080 }
1081
1082 int
1083 _IconListPresenter::GetItemCountPerAxis(void) const
1084 {
1085         ClearLastResult();
1086         return __itemCountPerAxis;
1087 }
1088
1089 result
1090 _IconListPresenter::SetItemLayoutHorizontalAlignment(HorizontalAlignment alignment)
1091 {
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.");
1094
1095         SysTryReturn(NID_UI_CTRL, (alignment >= ALIGNMENT_LEFT && alignment <= ALIGNMENT_RIGHT), E_INVALID_ARG, E_INVALID_ARG,
1096                         "[E_INVALID_ARG] alignment is invalid.");
1097
1098         if (alignment != __itemHorizontalAlignment)
1099         {
1100                 __itemHorizontalAlignment = alignment;
1101                 __isLayoutChanged = true;
1102         }
1103
1104         return E_SUCCESS;
1105 }
1106
1107 result
1108 _IconListPresenter::SetItemLayoutVerticalAlignment(VerticalAlignment alignment)
1109 {
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.");
1112
1113         SysTryReturn(NID_UI_CTRL, (alignment >= ALIGNMENT_TOP && alignment <= ALIGNMENT_BOTTOM), E_INVALID_ARG, E_INVALID_ARG,
1114                         "[E_INVALID_ARG] alignment is invalid.");
1115
1116         if (alignment != __itemVerticalAlignment)
1117         {
1118                 __itemVerticalAlignment = alignment;
1119                 __isLayoutChanged = true;
1120         }
1121
1122         return E_SUCCESS;
1123 }
1124
1125 HorizontalAlignment
1126 _IconListPresenter::GetItemLayoutHorizontalAlignment(void) const
1127 {
1128         ClearLastResult();
1129         return __itemHorizontalAlignment;
1130 }
1131
1132 VerticalAlignment
1133 _IconListPresenter::GetItemLayoutVerticalAlignment(void) const
1134 {
1135         ClearLastResult();
1136         return __itemVerticalAlignment;
1137 }
1138
1139 result
1140 _IconListPresenter::SetItemBorderStyle(IconListViewItemBorderStyle borderStyle)
1141 {
1142         return __pItemDrawingProperty->SetBorderStyle(borderStyle);
1143 }
1144
1145 IconListViewItemBorderStyle
1146 _IconListPresenter::GetItemBorderStyle(void) const
1147 {
1148         return __pItemDrawingProperty->GetBorderStyle();
1149 }
1150
1151 _IconListItemDrawingProperty*
1152 _IconListPresenter::GetItemDrawingProperty(void) const
1153 {
1154         return __pItemDrawingProperty;
1155 }
1156
1157 void
1158 _IconListPresenter::ClearVisualElement(void)
1159 {
1160         __listStatusChanged = true;
1161 }
1162
1163 result
1164 _IconListPresenter::SetNonSlidableList(void)
1165 {
1166         // Remove All Items & Register Adaptor
1167         __pListModel->RemoveAllItem();
1168
1169         __firstDrawnIndex = INVALID_INDEX;
1170         __lastDrawnIndex = INVALID_INDEX;
1171         __selectedIndex = INVALID_INDEX;
1172         __highlightedIndex = INVALID_INDEX;
1173         __isLayoutChanged = true;
1174         __alreadyDrawn = true;
1175
1176         return __pListModel->AddGroup(0, __pIconListView->GetStyle() == ICON_LIST_VIEW_STYLE_RADIO);
1177 }
1178
1179 result
1180 _IconListPresenter::AddItem(_IconListItem* pItem)
1181 {
1182         result r = __pListModel->AddItemToGroup(pItem, DEFAULT_GROUP_INDEX);
1183         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
1184
1185         pItem->ClearVisualElement();
1186
1187         // Attach _VisualElement
1188         _VisualElement* pBase = pItem->GetVisualElement();
1189         if (pBase != null)
1190         {
1191                 VisualElement* pParent = pBase->GetParent();
1192                 if (pParent != null)
1193                 {
1194                         pParent->DetachChild(*pBase);
1195                 }
1196                 __pIconListView->GetVisualElement()->AttachChild(*pBase);
1197                 pBase->SetShowState(false);
1198                 pBase->SetClipToParent(true);
1199         }
1200
1201         __isLayoutChanged = true;
1202
1203         return E_SUCCESS;
1204 }
1205
1206 result
1207 _IconListPresenter::InsertItemAt(int index, _IconListItem* pItem)
1208 {
1209         result r = __pListModel->InsertItemToGroup(pItem, DEFAULT_GROUP_INDEX, index);
1210         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
1211
1212         pItem->ClearVisualElement();
1213         pItem->SetDrawingProperty(*__pItemDrawingProperty);
1214
1215         // Attach _VisualElement
1216         _VisualElement* pBase = pItem->GetVisualElement();
1217         if (pBase != null)
1218         {
1219                 VisualElement* pParent = pBase->GetParent();
1220                 if (pParent != null)
1221                 {
1222                         pParent->DetachChild(*pBase);
1223                 }
1224                 __pIconListView->GetVisualElement()->AttachChild(*pBase);
1225                 pBase->SetShowState(false);
1226                 pBase->SetClipToParent(true);
1227         }
1228
1229         __isLayoutChanged = true;
1230
1231         return E_SUCCESS;
1232 }
1233
1234 result
1235 _IconListPresenter::SetItemAt(int index, _IconListItem* pItem)
1236 {
1237         SysTryReturn(NID_UI_CTRL, (pItem != null), E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. pItem is null.");
1238
1239         result r = __pListModel->SetItem(*pItem, DEFAULT_GROUP_INDEX, index);
1240         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
1241
1242         pItem->ClearVisualElement();
1243         pItem->SetDrawingProperty(*__pItemDrawingProperty);
1244
1245         // Attach _VisualElement
1246         _VisualElement* pBase = pItem->GetVisualElement();
1247         if (pBase != null)
1248         {
1249                 VisualElement* pParent = pBase->GetParent();
1250                 if (pParent != null)
1251                 {
1252                         pParent->DetachChild(*pBase);
1253                 }
1254                 __pIconListView->GetVisualElement()->AttachChild(*pBase);
1255                 pBase->SetShowState(false);
1256                 pBase->SetClipToParent(true);
1257         }
1258
1259         return E_SUCCESS;
1260 }
1261
1262 result
1263 _IconListPresenter::RemoveItemAt(int index)
1264 {
1265         __isLayoutChanged = true;
1266
1267         return __pListModel->RemoveItemAt(DEFAULT_GROUP_INDEX, index);
1268 }
1269
1270 result
1271 _IconListPresenter::RemoveAllItems(void)
1272 {
1273         __isLayoutChanged = true;
1274
1275         return __pListModel->RemoveAllItem(false, true);
1276 }
1277
1278 void
1279 _IconListPresenter::SetItemBitmapAsAspectRatio(bool isAspect)
1280 {
1281         __pItemDrawingProperty->SetItemBitmapAsAspectRatio(isAspect);
1282 }
1283
1284 bool
1285 _IconListPresenter::IsItemBitmapAsAspectRatio(void) const
1286 {
1287         return __pItemDrawingProperty->IsItemBitmapAsAspectRatio();
1288 }
1289
1290 result
1291 _IconListPresenter::SetReorderModeEnabled(bool enable)
1292 {
1293         __isLayoutChanged = true;
1294
1295         if (__isTouchAnimationEnabled && enable)
1296         {
1297                 __isTouchAnimationEnabled = false;
1298         }
1299         else if (!enable)
1300         {
1301                 __isTouchAnimationEnabled = __previousTouchAnimatinEnabled;
1302         }
1303
1304         __pIconListView->Invalidate();
1305         return E_SUCCESS;
1306 }
1307
1308 result
1309 _IconListPresenter::Draw(void)
1310 {
1311         result r = E_SUCCESS;
1312         int itemCount = 0;
1313
1314         if (__onDrawing)
1315         {
1316                 __requireNextDrawing = true;
1317                 return E_SUCCESS;
1318         }
1319
1320         // If it is first draw,
1321         if (!__alreadyDrawn)
1322         {
1323                 r = AddGroupAndRestoreItem(false);
1324                 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
1325         }
1326
1327         // Set Drawing Flag
1328         __onDrawing = true;
1329
1330         // Draw Background
1331         Color backgroundColor = __pIconListView->GetBackgroundColor();
1332         if (__listStatusChanged)
1333         {
1334                 const Bitmap* pBackgroundBitmap = __pIconListView->GetBackgroundBitmap();
1335                 if (pBackgroundBitmap != null)
1336                 {
1337                         Canvas* pCanvas = __pVE->GetCanvasN();
1338                         SysTryCatch(NID_UI_CTRL, (pCanvas!= null), , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1339
1340                         pCanvas->SetBackgroundColor(backgroundColor);
1341                         pCanvas->Clear();
1342                         FloatRectangle bounds(__pIconListView->GetBoundsF());
1343                         bounds.SetPosition(0.0f, 0.0f);
1344                         if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pBackgroundBitmap))
1345                         {
1346                                 pCanvas->DrawNinePatchedBitmap(bounds, *pBackgroundBitmap);
1347                         }
1348                         else
1349                         {
1350                                 pCanvas->DrawBitmap(bounds, *pBackgroundBitmap);
1351                         }
1352
1353                         delete pCanvas;
1354
1355                         __needBaseCanvas = true;
1356                 }
1357                 else
1358                 {
1359                         __pVE->SetBackgroundColor(_Colorf((float) backgroundColor.GetRed() / 255, (float) backgroundColor.GetGreen() / 255, (float) backgroundColor.GetBlue() / 255, (float) backgroundColor.GetAlpha() / 255));
1360                         __needBaseCanvas = false;
1361                 }
1362         }
1363
1364         itemCount = __pListModel->GetItemCountInGroup(DEFAULT_GROUP_INDEX);
1365         if (itemCount <= 0)
1366         {
1367                 r = DrawEmptyList();
1368                 __onDrawing = false;
1369                 __alreadyDrawn = true;
1370                 if (__requireNextDrawing)
1371                 {
1372                         __requireNextDrawing = false;
1373                         return Draw();
1374                 }
1375                 return r;
1376         }
1377
1378         // If layout is changed, adjust layout.
1379         if (__isLayoutChanged)
1380         {
1381                 AdjustLayout();
1382         }
1383
1384         // Draw Items
1385         if (__scrollDirection == ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL)
1386         {
1387                 // Vertical Scroll
1388                 r = DrawVerticalScrollList();
1389                 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1390         }
1391         else
1392         {
1393                 // Horizontal Scroll
1394                 r = DrawHorizontalScrollList();
1395                 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1396         }
1397
1398         __pItemDrawingProperty->SetDrawingFlag();
1399
1400         if (!__alreadyDrawn)
1401         {
1402                 __alreadyDrawn = true;
1403
1404                 // start timer for scroll fade out
1405                 _Scroll* pScroll = __pIconListView->GetScroll();
1406                 if (pScroll != null)
1407                 {
1408                         float scrollViewRange = 0.0f;
1409                         float scrollRange = 0.0f;
1410                         pScroll->GetScrollRange(&scrollViewRange, &scrollRange);
1411                         if (!_FloatCompareGE(scrollViewRange, scrollRange))
1412                         {
1413                                 ScrollFadeOut();
1414                         }
1415                 }
1416                 InitializeAccessibilityElement();
1417         }
1418
1419         if (__listStatusChanged)
1420         {
1421                 if (__pEmptyListVE != null)
1422                 {
1423                         if (__needBaseCanvas)
1424                         {
1425                                 __pEmptyListVE->Destroy();
1426                                 __pEmptyListVE = null;
1427                         }
1428                         else
1429                         {
1430                                 __pEmptyListVE->SetShowState(false);
1431                         }
1432                 }
1433                 __listStatusChanged = false;
1434         }
1435
1436 CATCH:
1437         __onDrawing = false;
1438         if (__requireNextDrawing)
1439         {
1440                 __requireNextDrawing = false;
1441                 return Draw();
1442         }
1443
1444         return r;
1445 }
1446
1447 result
1448 _IconListPresenter::AddGroupAndRestoreItem(bool restoreItem)
1449 {
1450         if (__pListModel->GetAllGroupCount() == 0)
1451         {
1452                 int itemCount = (__pItemProviderAdaptor != null) ? __pItemProviderAdaptor->GetItemCount() : 0;
1453
1454                 // Add Group
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));
1457         }
1458         __isLayoutChanged = true;
1459         InitializeFont();
1460
1461         if (restoreItem)
1462         {
1463                 __pListModel->RestoreItemStatus();
1464         }
1465
1466         return E_SUCCESS;
1467 }
1468
1469 result
1470 _IconListPresenter::DrawEmptyList(void)
1471 {
1472         result r = E_SUCCESS;
1473
1474         if (!__listStatusChanged)
1475         {
1476                 return r;
1477         }
1478
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;
1486
1487         float emptyTextHeight = 0.0f;
1488
1489         Font* pFont = null;
1490         const String emptyText = __pIconListView->GetTextOfEmptyList();
1491
1492         float bitmapXPosition = 0.0f;
1493         float bitmapHeight = 0.0f;
1494         float bitmapWidth = 0.0f;
1495         const Bitmap* pBitmap = __pIconListView->GetBitmapOfEmptyList();
1496
1497         // set visual element or canvas for empty list
1498         if (!__needBaseCanvas && __pEmptyListVE == null)
1499         {
1500                 __pEmptyListVE = new (std::nothrow) _VisualElement();
1501                 SysTryCatch(NID_UI, __pEmptyListVE != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1502
1503                 r = __pEmptyListVE->Construct();
1504                 SysTryCatch(NID_UI, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
1505
1506                 __pEmptyListVE->SetSurfaceOpaque(false);
1507                 __pEmptyListVE->SetImplicitAnimationEnabled(false);
1508
1509                 __pVE->AttachChild(*__pEmptyListVE);
1510         }
1511         else if (__needBaseCanvas)
1512         {
1513                 pCanvas = __pVE->GetCanvasN();
1514                 SysTryCatch(NID_UI, pCanvas != null, , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1515         }
1516
1517         if (!emptyText.IsEmpty())
1518         {
1519                 GET_SHAPE_CONFIG(ICONLIST::EMPTY_TEXT_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, emptyTextHeight);
1520
1521                 pFont = __pIconListView->GetFallbackFont();
1522                 SysTryCatch(NID_UI, pFont != null, , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1523
1524                 pTextObject = new (std::nothrow) TextObject;
1525                 SysTryCatch(NID_UI, pTextObject != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1526
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.");
1530
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);
1537
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);
1542
1543                 for (int i = 1; i < pTextObject->GetTotalLineCount(); i++)
1544                 {
1545                         float tempWidth = pTextObject->GetLineWidthAtF(i);
1546                         textDimension.width = textDimension.width > tempWidth ? textDimension.width : tempWidth;
1547                 }
1548
1549                 // calculate bounds with text
1550                 if (_FloatCompareGE(viewBounds.width, textDimension.width))
1551                 {
1552                         bounds.x = (viewBounds.width - textDimension.width) / 2;
1553                         bounds.width = textDimension.width;
1554                 }
1555                 else
1556                 {
1557                         bounds.width = viewBounds.width;
1558                 }
1559
1560                 if (_FloatCompareGE(viewBounds.height, textDimension.height))
1561                 {
1562                         bounds.y = (viewBounds.height - textDimension.height) / 2;
1563                         bounds.height = textDimension.height;
1564                 }
1565                 else
1566                 {
1567                         bounds.height = viewBounds.height;
1568                 }
1569         }
1570
1571         if (pBitmap != null)
1572         {
1573                 bitmapHeight = pBitmap->GetHeightF();
1574                 bitmapWidth = pBitmap->GetWidthF();
1575
1576                 bounds.height += bitmapHeight + emptyTextHeight;
1577
1578                 bounds.y = (viewBounds.height - bounds.height) / 2;
1579
1580                 if (!_FloatCompareGE(bounds.y, 0.0f))
1581                 {
1582                         bounds.y = 0.0f;
1583                 }
1584
1585                 if (!_FloatCompareLE(bounds.width, bitmapWidth))
1586                 {
1587                         bitmapXPosition = (bounds.width - bitmapWidth) / 2;
1588                 }
1589                 else if (!_FloatCompareLE(viewBounds.width, bitmapWidth))
1590                 {
1591                         bounds.x = (viewBounds.width - bitmapWidth) / 2;
1592                         bounds.width = bitmapWidth;
1593                 }
1594                 else
1595                 {
1596                         bounds.x = 0.0f;
1597                         bounds.width = bitmapWidth;
1598                 }
1599         }
1600
1601         // draw empty list
1602         if (!__needBaseCanvas)
1603         {
1604                 __pEmptyListVE->SetBounds(bounds);
1605                 __pEmptyListVE->SetShowState(true);
1606
1607                 pCanvas = __pEmptyListVE->GetCanvasN();
1608                 SysTryCatch(NID_UI, pCanvas != null, , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1609
1610                 Color backgroundColor = __pIconListView->GetBackgroundColor();
1611                 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
1612                 pCanvas->Clear();
1613
1614                 bounds.x = 0.0f;
1615                 bounds.y = 0.0f;
1616         }
1617
1618         if (pBitmap != null)
1619         {
1620                 FloatRectangle bitmapBounds(bounds.x + bitmapXPosition, bounds.y, bitmapWidth, bitmapHeight);
1621                 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pBitmap))
1622                 {
1623                         pCanvas->DrawNinePatchedBitmap(bitmapBounds, *pBitmap);
1624                 }
1625                 else
1626                 {
1627                         pCanvas->DrawBitmap(bitmapBounds, *pBitmap);
1628                 }
1629         }
1630
1631         if (!emptyText.IsEmpty())
1632         {
1633                 if (!_FloatCompare(bitmapHeight, 0.0f))
1634                 {
1635                         bounds.y += emptyTextHeight + bitmapHeight;
1636                 }
1637                 bounds.height = textDimension.height;
1638                 pTextObject->SetBounds(bounds);
1639                 pTextObject->Draw(*_CanvasImpl::GetInstance(*pCanvas));
1640         }
1641
1642         __listStatusChanged = false;
1643
1644         if (__needBaseCanvas && __pEmptyListVE != null)
1645         {
1646                 __pEmptyListVE->Destroy();
1647                 __pEmptyListVE = null;
1648         }
1649
1650         delete pCanvas;
1651         delete pTextObject;
1652         return r;
1653
1654 CATCH:
1655         if (__pEmptyListVE != null)
1656         {
1657                 __pEmptyListVE->Destroy();
1658                 __pEmptyListVE = null;
1659         }
1660
1661         delete pCanvas;
1662         delete pTextObject;
1663         return r;
1664 }
1665
1666 result
1667 _IconListPresenter::DrawHorizontalScrollList(void)
1668 {
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;
1680
1681         // Hide Items
1682         if (__lastDrawnIndex >= 0)
1683         {
1684                 float scroll = endXPos - itemRect.x;
1685                 int lastIndex = index + (static_cast<int> ((scroll - 1.0f) / unitWidth) + 1) * __itemCountPerAxis - 1;
1686                 if (lastIndex >= itemCount)
1687                 {
1688                         lastIndex = itemCount - 1;
1689                 }
1690
1691                 if (__lastDrawnIndex < index || __firstDrawnIndex > lastIndex)
1692                 {
1693                         HideItems(__firstDrawnIndex, __lastDrawnIndex);
1694                 }
1695                 else
1696                 {
1697                         HideItems(__firstDrawnIndex, index - 1);
1698                         HideItems(lastIndex + 1, __lastDrawnIndex);
1699                 }
1700         }
1701
1702         // Preload Items
1703         if (__firstDrawnIndex > index)
1704         {
1705                 int topIndex = __firstDrawnIndex - __itemCountPerAxis * (static_cast<int> (__pIconListView->GetBounds().width / __unitScrollLength) + 1);
1706                 if (topIndex <= index)
1707                 {
1708                         while (--__firstDrawnIndex > index)
1709                         {
1710                                 __pListModel->LoadItem(DEFAULT_GROUP_INDEX, __firstDrawnIndex);
1711                         }
1712                 }
1713         }
1714
1715         // Draw Items
1716         _IconListItem* pItem = null;
1717         __firstDrawnIndex = index;
1718         while (itemRect.x < endXPos)
1719         {
1720                 itemRect.y = __startPosOfAxis;
1721                 while (itemRect.y < endYPos && index < itemCount)
1722                 {
1723                         // Draw Item
1724                         pItem = dynamic_cast <_IconListItem*>(__pListModel->LoadItem(DEFAULT_GROUP_INDEX, index));
1725                         if (pItem != null)
1726                         {
1727                                 pItem->SetDrawingProperty(*__pItemDrawingProperty);
1728
1729                                 if (__reorderToIndex == index && __isTouchPressed)
1730                                 {
1731                                         pItem->DrawItem(itemRect, LIST_ITEM_STATE_PRESSED);
1732                                 }
1733                                 else
1734                                 {
1735                                         pItem->DrawItem(itemRect, LIST_ITEM_STATE_NORMAL);
1736                                 }
1737
1738                                 if (pItem->GetVisualElement() != null)
1739                                 {
1740                                         pItem->GetVisualElement()->SetFlushNeeded();
1741                                 }
1742                         }
1743                         ++index;
1744                         itemRect.y += unitHeight;
1745                 }
1746                 itemRect.x += unitWidth;
1747         }
1748         __lastDrawnIndex = index - 1;
1749
1750         return E_SUCCESS;
1751 }
1752
1753 result
1754 _IconListPresenter::DrawVerticalScrollList(void)
1755 {
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;
1767
1768         // Hide Items
1769         if (__lastDrawnIndex >= 0)
1770         {
1771                 float scroll = endYPos - itemRect.y;
1772                 int lastIndex = index + (static_cast<int> ((scroll - 1.0f) / unitHeight) + 1) * __itemCountPerAxis - 1;
1773                 if (lastIndex >= itemCount)
1774                 {
1775                         lastIndex = itemCount - 1;
1776                 }
1777
1778                 if (__lastDrawnIndex < index || __firstDrawnIndex > lastIndex)
1779                 {
1780                         HideItems(__firstDrawnIndex, __lastDrawnIndex);
1781                 }
1782                 else
1783                 {
1784                         HideItems(__firstDrawnIndex, index - 1);
1785                         HideItems(lastIndex + 1, __lastDrawnIndex);
1786                 }
1787         }
1788
1789         // Preload Items
1790         if (__firstDrawnIndex > index)
1791         {
1792                 int topIndex = __firstDrawnIndex - __itemCountPerAxis * (static_cast<int> (__pIconListView->GetBounds().height / __unitScrollLength) + 1);
1793                 if (topIndex <= index)
1794                 {
1795                         while (--__firstDrawnIndex > index)
1796                         {
1797                                 __pListModel->LoadItem(DEFAULT_GROUP_INDEX, __firstDrawnIndex);
1798                         }
1799                 }
1800         }
1801
1802         // Draw Items
1803         _IconListItem* pItem = null;
1804         __firstDrawnIndex = index;
1805         while (itemRect.y < endYPos)
1806         {
1807                 itemRect.x = __startPosOfAxis;
1808                 while (itemRect.x < endXPos && index < itemCount)
1809                 {
1810                         // Draw Item
1811                         pItem = dynamic_cast <_IconListItem*>(__pListModel->LoadItem(DEFAULT_GROUP_INDEX, index));
1812                         if (pItem != null)
1813                         {
1814                                 pItem->SetDrawingProperty(*__pItemDrawingProperty);
1815
1816                                 if (__reorderToIndex == index && __isTouchPressed)
1817                                 {
1818                                         pItem->DrawItem(itemRect, LIST_ITEM_STATE_PRESSED);
1819                                 }
1820                                 else
1821                                 {
1822                                         pItem->DrawItem(itemRect, LIST_ITEM_STATE_NORMAL);
1823                                 }
1824                         }
1825                         ++index;
1826                         itemRect.x += unitWidth;
1827                 }
1828                 itemRect.y += unitHeight;
1829         }
1830         __lastDrawnIndex = index - 1;
1831
1832         return E_SUCCESS;
1833 }
1834
1835 void
1836 _IconListPresenter::AdjustLayout(void)
1837 {
1838         FloatDimension itemSize = __pIconListView->GetItemSize();
1839         FloatRectangle bounds = __pIconListView->GetBoundsF();
1840         int itemCount = __pListModel->GetItemCountInGroup(DEFAULT_GROUP_INDEX);
1841         float oldScrollLength = __scrollLength;
1842
1843         // Reset layout changed flag
1844         __isLayoutChanged = false;
1845
1846         // Calculate
1847         if (__scrollDirection == ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL)
1848         {
1849                 // Unit Axis Length(= Item Width + Horizontal Spacing)
1850                 __unitLengthOfAxis = itemSize.width + __horizontalSpacing;
1851
1852                 // ItemCountPerAxis
1853                 __itemCountPerAxis = (bounds.width - __leftMargin - __rightMargin + __horizontalSpacing) / __unitLengthOfAxis;
1854
1855                 // Unit Scroll Length(= Item Height + Vertical Spacing)
1856                 __unitScrollLength = itemSize.height + __verticalSpacing;
1857
1858                 // ScrollLength
1859                 if (__itemCountPerAxis > 0)
1860                 {
1861                         __scrollLength = __topMargin + __bottomMargin - __verticalSpacing + __unitScrollLength *
1862                                         ((itemCount - 1) / __itemCountPerAxis + 1) - bounds.height;
1863                         if (!_FloatCompareGE(__scrollLength, 0.0f))
1864                         {
1865                                 __scrollLength = 0.0f;
1866                         }
1867                 }
1868                 else
1869                 {
1870                         __itemCountPerAxis = 0;
1871                         __scrollLength = 0.0f;
1872                 }
1873
1874                 // startPosOfAxis
1875                 switch (__itemHorizontalAlignment)
1876                 {
1877                 case ALIGNMENT_LEFT:
1878                         __startPosOfAxis = __leftMargin;
1879                         break;
1880
1881                 case ALIGNMENT_CENTER:
1882                         __startPosOfAxis = (bounds.width + __leftMargin - __rightMargin - __itemCountPerAxis * __unitLengthOfAxis
1883                                         + __horizontalSpacing) / 2;
1884                         break;
1885
1886                 case ALIGNMENT_RIGHT:
1887                         __startPosOfAxis = bounds.width - __rightMargin - __itemCountPerAxis * __unitLengthOfAxis + __horizontalSpacing;
1888                         break;
1889                 }
1890
1891                 // endPosOfAxis
1892                 __endPosOfAxis = __startPosOfAxis + __itemCountPerAxis * __unitLengthOfAxis - __horizontalSpacing;
1893
1894                 if (!_FloatCompare(__scrollLength, oldScrollLength))
1895                 {
1896                         // Set Scroll Range & Position
1897                         _Scroll* pScroll = __pIconListView->GetScroll();
1898                         if (pScroll != null)
1899                         {
1900                                 pScroll->SetScrollRange(bounds.height, __scrollLength + bounds.height);
1901
1902                                 if (_FloatCompareLE(__scrollLength, 0.0f))
1903                                 {
1904                                         pScroll->EnableScrollingEffect(false);
1905                                 }
1906                                 else
1907                                 {
1908                                         pScroll->EnableScrollingEffect(true);
1909                                 }
1910                         }
1911
1912                         if (!_FloatCompareGE(__scrollLength, oldScrollLength) && !_FloatCompareLE(__scrollPosition, __scrollLength))
1913                         {
1914                                 if (SetScrollPosition(__scrollLength))
1915                                 {
1916                                         ScrollFadeOut();
1917                                         FireScrollEvent();
1918
1919                                         __pIconListView->Invalidate();
1920                                 }
1921                         }
1922                 }
1923
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);
1927         }
1928         else
1929         {
1930                 // Unit Axis Length(= Item Height + Vertical Spacing)
1931                 __unitLengthOfAxis = itemSize.height + __verticalSpacing;
1932
1933                 // ItemCountPerAxis
1934                 __itemCountPerAxis = static_cast<int> ((bounds.height - __topMargin - __bottomMargin + __verticalSpacing) / __unitLengthOfAxis);
1935
1936                 // Unit Scroll Length(= Item Width + Horizontal Spacing)
1937                 __unitScrollLength = itemSize.width + __horizontalSpacing;
1938
1939                 // ScrollLength
1940                 if (__itemCountPerAxis > 0)
1941                 {
1942                         __scrollLength = __leftMargin + __rightMargin - __horizontalSpacing + __unitScrollLength *
1943                                         ((itemCount - 1) / __itemCountPerAxis + 1) - bounds.width;
1944                         if (!_FloatCompareGE(__scrollLength, 0.0f))
1945                         {
1946                                 __scrollLength = 0.0f;
1947                         }
1948                 }
1949                 else
1950                 {
1951                         __itemCountPerAxis = 0;
1952                         __scrollLength = 0.0f;
1953                 }
1954
1955                 // startPosOfAxis
1956                 switch (__itemVerticalAlignment)
1957                 {
1958                 case ALIGNMENT_TOP:
1959                         __startPosOfAxis = __topMargin;
1960                         break;
1961
1962                 case ALIGNMENT_MIDDLE:
1963                         __startPosOfAxis = (bounds.height + __topMargin - __bottomMargin - __itemCountPerAxis * __unitLengthOfAxis +
1964                                         __verticalSpacing) / 2;
1965                         break;
1966
1967                 case ALIGNMENT_BOTTOM:
1968                         __startPosOfAxis = bounds.height - __bottomMargin - __itemCountPerAxis * __unitLengthOfAxis + __verticalSpacing;
1969                         break;
1970                 }
1971
1972                 // endPosOfAxis
1973                 __endPosOfAxis = __startPosOfAxis + __itemCountPerAxis * __unitLengthOfAxis - __verticalSpacing;
1974
1975                 if (!_FloatCompare(__scrollLength, oldScrollLength))
1976                 {
1977                         // Set Scroll Range & Position
1978                         _Scroll* pScroll = __pIconListView->GetScroll();
1979                         if (pScroll != null)
1980                         {
1981                                 pScroll->SetScrollRange(bounds.width, __scrollLength + bounds.width);
1982
1983                                 if (_FloatCompareLE(__scrollLength, 0.0f))
1984                                 {
1985                                         pScroll->EnableScrollingEffect(false);
1986                                 }
1987                                 else
1988                                 {
1989                                         pScroll->EnableScrollingEffect(true);
1990                                 }
1991                         }
1992
1993                         if (!_FloatCompareGE(__scrollLength, oldScrollLength) && !_FloatCompareLE(__scrollPosition, __scrollLength))
1994                         {
1995                                 if (SetScrollPosition(__scrollLength))
1996                                 {
1997                                         ScrollFadeOut();
1998                                         FireScrollEvent();
1999
2000                                         __pIconListView->Invalidate();
2001                                 }
2002                         }
2003                 }
2004
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);
2008         }
2009 }
2010
2011 void
2012 _IconListPresenter::HideItems(int startIndex, int endIndex)
2013 {
2014         // Valid Check
2015         if (startIndex < 0 || endIndex < 0)
2016         {
2017                 return;
2018         }
2019
2020         if (endIndex >= __pListModel->GetItemCountInGroup(DEFAULT_GROUP_INDEX))
2021         {
2022                 endIndex = __pListModel->GetItemCountInGroup(DEFAULT_GROUP_INDEX) - 1;
2023         }
2024
2025         for (int index = startIndex; index <= endIndex; ++index)
2026         {
2027                 _IconListItem* pItem = dynamic_cast <_IconListItem*>(__pListModel->LoadItem(DEFAULT_GROUP_INDEX, index));
2028                 if (pItem != null)
2029                 {
2030                         _VisualElement* pBase = pItem->GetVisualElement();
2031                         if (pBase != null)
2032                         {
2033                                 pBase->SetShowState(false);
2034                         }
2035                 }
2036         }
2037 }
2038
2039 result
2040 _IconListPresenter::RedrawItem(int index, float ratio, bool doShow, float checkRatio)
2041 {
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.");
2044
2045         // Pre-Load Check
2046
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.");
2049
2050         // Pre-draw check
2051         if (index < __firstDrawnIndex || index > __lastDrawnIndex)
2052         {
2053                 pItem->ClearVisualElement();
2054                 return E_SUCCESS;
2055         }
2056
2057         FloatRectangle itemRect = GetItemBounds(index);
2058
2059         pItem->SetDrawingProperty(*__pItemDrawingProperty);
2060         pItem->ClearVisualElement();
2061
2062         if (__reorderToIndex == index && __isTouchPressed)
2063         {
2064                 pItem->DrawItem(itemRect, LIST_ITEM_STATE_PRESSED);
2065         }
2066         else
2067         {
2068                 pItem->DrawItem(itemRect, LIST_ITEM_STATE_NORMAL);
2069         }
2070
2071         _VisualElement* pBase = pItem->GetVisualElement();
2072         pBase->InvalidateRectangle(&itemRect);
2073         pBase->Draw();
2074
2075         if (doShow)
2076         {
2077                 pBase->SetFlushNeeded();
2078         }
2079
2080         return E_SUCCESS;
2081 }
2082
2083 result
2084 _IconListPresenter::FireIconListViewItemEvent(_IconListViewItemEventType eventType, int index, int arg)
2085 {
2086         // Create EventArg
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.");
2089         switch (eventType)
2090         {
2091         case EVENT_TYPE_ITEM_SELECTED:
2092                 pArg->SetStatus(static_cast<IconListViewItemStatus> (arg));
2093                 break;
2094
2095         case EVENT_TYPE_OVERLAY_BITMAP_SELECTED:
2096                 pArg->SetOverlayBitmapId(arg);
2097                 break;
2098
2099         case EVENT_TYPE_ITEM_REORDERED:
2100                 pArg->SetToIndex(arg);
2101                 break;
2102         }
2103
2104         // Fire Event
2105         return __pIconListView->GetIconListItemEvent()->Fire(*pArg);
2106 }
2107
2108 result
2109 _IconListPresenter::FireScrollEndReachedEvent(ScrollEndEvent type)
2110 {
2111         // Create EventArg
2112         _UiScrollEventArg* pEventArg = _UiScrollEventArg::GetScrollEventArgN(*__pIconListView, type);
2113         result r = GetLastResult();
2114         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
2115
2116         // Fire Event
2117         r = __pIconListView->GetScrollEvent()->Fire(*pEventArg);
2118         return r;
2119 CATCH:
2120         delete pEventArg;
2121         return r;
2122 }
2123
2124 result
2125 _IconListPresenter::FireScrollPositionChangedEvent(float scrollPosition)
2126 {
2127         // Create EventArg
2128         _UiScrollEventArg* pEventArg = _UiScrollEventArg::GetScrollEventArgN(*__pIconListView, scrollPosition);
2129         result r = GetLastResult();
2130         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
2131
2132         // Fire Event
2133         r = __pIconListView->GetScrollEvent()->Fire(*pEventArg);
2134         return r;
2135 CATCH:
2136         delete pEventArg;
2137         return r;
2138 }
2139
2140 result
2141 _IconListPresenter::FireScrollStoppedEvent()
2142 {
2143         // Create EventArg
2144         _UiScrollEventArg* pEventArg = _UiScrollEventArg::GetScrollEventArgN(*__pIconListView);
2145         result r = GetLastResult();
2146         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
2147
2148         // Fire Event
2149         r = __pIconListView->GetScrollEvent()->Fire(*pEventArg);
2150         return r;
2151 CATCH:
2152         delete pEventArg;
2153         return r;
2154 }
2155
2156 result
2157 _IconListPresenter::FireScrollEvent()
2158 {
2159         result r = E_SUCCESS;
2160
2161         if ((__flickRunning) || (__pMagneticScrollTimer != null))
2162         {
2163                 return r;
2164         }
2165
2166         if (_FloatCompare(__scrollPosition, 0.0f))
2167         {
2168                 if (__scrollDirection == ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL)
2169                 {
2170                         r = FireScrollEndReachedEvent(SCROLL_END_EVENT_END_TOP);
2171                 }
2172                 else
2173                 {
2174                         r = FireScrollEndReachedEvent(SCROLL_END_EVENT_END_LEFT);
2175                 }
2176
2177                 if (!__isTouchPressed)
2178                 {
2179                         ScrollFadeOut();
2180                 }
2181         }
2182         else if (_FloatCompare(__scrollPosition, __scrollLength))
2183         {
2184                 if (__scrollDirection == ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL)
2185                 {
2186                         r = FireScrollEndReachedEvent(SCROLL_END_EVENT_END_BOTTOM);
2187                 }
2188                 else
2189                 {
2190                         r = FireScrollEndReachedEvent(SCROLL_END_EVENT_END_RIGHT);
2191                 }
2192
2193                 if (!__isTouchPressed)
2194                 {
2195                         ScrollFadeOut();
2196                 }
2197         }
2198         else
2199         {
2200                 r = FireScrollPositionChangedEvent(__scrollPosition);
2201         }
2202         return r;
2203 }
2204
2205 bool
2206 _IconListPresenter::SetScrollPosition(float position, bool enableFadeEffect)
2207 {
2208         if (_FloatCompareLE(__scrollLength, 0.0f) && (!_FloatCompare(position, 0.0f)))
2209         {
2210                 return false;
2211         }
2212
2213         if (_FloatCompare(__scrollPosition, position))
2214         {
2215                 return false;
2216         }
2217
2218         if (!_FloatCompareLE(position, __scrollLength))
2219         {
2220                 __scrollPosition = __scrollLength;
2221         }
2222         else if (!_FloatCompareGE(position, 0.0f))
2223         {
2224                 __scrollPosition = 0.0f;
2225         }
2226         else
2227         {
2228                 __scrollPosition = position;
2229         }
2230
2231         result r = E_SUCCESS;
2232         _Scroll *pScroll =__pIconListView->GetScroll();
2233         if (pScroll != null)
2234         {
2235                 pScroll->SetScrollingEffectVisibility(true);
2236
2237                 if (pScroll->IsEnabledFadeEffect())
2238                 {
2239                         if (enableFadeEffect)
2240                         {
2241                                 pScroll->SetScrollVisibility(true);
2242                         }
2243                         else
2244                         {
2245                                 pScroll->EnableFadeEffect(false);
2246                                 pScroll->SetScrollVisibility(true);
2247                                 pScroll->EnableFadeEffect(true);
2248                         }
2249                 }
2250
2251                 r = pScroll->SetScrollPosition(position);
2252         }
2253
2254         return (r == E_SUCCESS);
2255 }
2256
2257 void
2258 _IconListPresenter::ScrollFadeOut(bool showEffect)
2259 {
2260         _Scroll* pScroll = __pIconListView->GetScroll();
2261         if (pScroll != null)
2262         {
2263                 if (pScroll->IsEnabledFadeEffect())
2264                 {
2265                         if (showEffect)
2266                         {
2267                                 pScroll->EnableFadeEffect(false);
2268                                 pScroll->SetScrollVisibility(true);
2269                                 pScroll->SetScrollingEffectVisibility(true);
2270                                 pScroll->EnableFadeEffect(true);
2271                         }
2272
2273                         pScroll->SetScrollVisibility(false);
2274                 }
2275
2276                 pScroll->SetScrollingEffectVisibility(false);
2277         }
2278 }
2279
2280 float
2281 _IconListPresenter::GetMagneticScrollPosition(void) const
2282 {
2283         return GetMagneticScrollPosition(__scrollPosition);
2284 }
2285
2286 float
2287 _IconListPresenter::GetMagneticScrollPosition(float scrollPosition) const
2288 {
2289         if (__magneticScrollSize <= 0)
2290         {
2291                 return __scrollPosition;
2292         }
2293
2294         float leftScrollLength = __scrollLength - scrollPosition;
2295         if (__scrollDirection == ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL)
2296         {
2297                 if (!_FloatCompareGE(scrollPosition, __topMargin))
2298                 {
2299                         return 0;
2300                 }
2301
2302                 scrollPosition -= __topMargin;
2303         }
2304         else
2305         {
2306                 if (!_FloatCompareGE(scrollPosition, __leftMargin))
2307                 {
2308                         return 0;
2309                 }
2310
2311                 scrollPosition -= __leftMargin;
2312         }
2313
2314         float unitMagneticScrollSize = __unitScrollLength * __magneticScrollSize;
2315         float leftMagneticScrollPosition = scrollPosition - (static_cast<int> (scrollPosition / unitMagneticScrollSize) * unitMagneticScrollSize);
2316         if (!_FloatCompareLE(leftMagneticScrollPosition, leftScrollLength))
2317         {
2318                 scrollPosition = __scrollLength + OVERSCROLLING_MAX_DISTANCE;
2319         }
2320         else if (!_FloatCompareLE(leftMagneticScrollPosition, unitMagneticScrollSize / 2))
2321         {
2322                 scrollPosition = scrollPosition - leftMagneticScrollPosition + unitMagneticScrollSize;
2323         }
2324         else
2325         {
2326                 scrollPosition = scrollPosition - leftMagneticScrollPosition;
2327         }
2328
2329         return scrollPosition;
2330 }
2331
2332 FloatRectangle
2333 _IconListPresenter::GetItemBounds(int index) const
2334 {
2335         // Absolute Coordinate Base
2336         FloatRectangle rect(0.0f, 0.0f, GetItemSize().width, GetItemSize().height);
2337         if (__scrollDirection == ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL)
2338         {
2339                 rect.x = __startPosOfAxis + __unitLengthOfAxis * (index % __itemCountPerAxis);
2340                 rect.y = __topMargin + __unitScrollLength * (index / __itemCountPerAxis) - __scrollPosition;
2341         }
2342         else
2343         {
2344                 rect.x = __leftMargin + __unitScrollLength * (index / __itemCountPerAxis) - __scrollPosition;
2345                 rect.y = __startPosOfAxis + __unitLengthOfAxis * (index % __itemCountPerAxis);
2346         }
2347
2348         return rect;
2349 }
2350
2351 int
2352 _IconListPresenter::CalculateFlickAmount(int distance, int duration)
2353 {
2354         if (_FloatCompare(distance, 0.0f))
2355         {
2356                 return 0.0f;
2357         }
2358         else if (distance < 0.0)
2359         {
2360                 return -SCROLL_PANEL_FIXED_FLICK_AMOUNT;
2361         }
2362         else
2363         {
2364                 return SCROLL_PANEL_FIXED_FLICK_AMOUNT;
2365         }
2366 }
2367
2368 void
2369 _IconListPresenter::InitializeAccessibilityElement(void)
2370 {
2371         RemoveAllAccessibilityElements();
2372
2373         int itemCount = __pListModel->GetItemCountInGroup(DEFAULT_GROUP_INDEX);
2374         if (itemCount < 0)
2375         {
2376                 return;
2377         }
2378
2379         int firstIndex = INVALID_INDEX;
2380         int endIndex = INVALID_INDEX;
2381         if (__scrollDirection == ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL)
2382         {
2383                 int firstLine = !_FloatCompareLE(__scrollPosition, __topMargin) ? static_cast<int> (__scrollPosition - __topMargin + __verticalSpacing) / __unitScrollLength : 0;
2384
2385                 firstIndex = firstLine * __itemCountPerAxis;
2386                 endIndex = firstIndex + (static_cast<int> (__pIconListView->GetBounds().height + __verticalSpacing) / __unitScrollLength) * __itemCountPerAxis;
2387         }
2388         else
2389         {
2390                 int firstLine = !_FloatCompareLE(__scrollPosition, __leftMargin) ? static_cast<int> (__scrollPosition - __leftMargin + __horizontalSpacing) / __unitScrollLength : 0;
2391
2392                 firstIndex = firstLine * __itemCountPerAxis;
2393                 endIndex = firstIndex + (static_cast<int> (__pIconListView->GetBounds().width + __horizontalSpacing) / __unitScrollLength) * __itemCountPerAxis;
2394         }
2395
2396         endIndex = itemCount > endIndex ? endIndex : (itemCount - 1);
2397
2398         for (int i = firstIndex; i < endIndex; i++)
2399         {
2400                 _IconListItem* pItem = static_cast<_IconListItem*>(__pListModel->LoadItem(DEFAULT_GROUP_INDEX, i));
2401                 if (pItem != null)
2402                 {
2403                         _VisualElement* pVE = pItem->GetItemVisualElement();
2404                         if (pVE != null)
2405                         {
2406                                 AddAccessibilityElement(*pItem, pVE->GetBounds());
2407                         }
2408                 }
2409         }
2410 }
2411
2412 void
2413 _IconListPresenter::AddAccessibilityElement(_IconListItem& item, const FloatRectangle& rect)
2414 {
2415         if (likely(!(_AccessibilityManager::IsActivated())))
2416         {
2417                 return;
2418         }
2419
2420         _AccessibilityContainer* pContainer = __pIconListView->GetAccessibilityContainer();
2421         if (pContainer != null)
2422         {
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);
2430         }
2431 }
2432
2433 void
2434 _IconListPresenter::RemoveAllAccessibilityElements(void)
2435 {
2436         _AccessibilityContainer* pContainer = __pIconListView->GetAccessibilityContainer();
2437         if (pContainer != null)
2438         {
2439                 pContainer->RemoveAllElement();
2440         }
2441 }
2442
2443 void
2444 _IconListPresenter::TranslateIconListItemPosition(float& x, float& y)
2445 {
2446         if (_FloatCompareLE(__unitLengthOfAxis, 0.0f) || _FloatCompareLE(__unitScrollLength, 0.0f))
2447         {
2448                 x = -1.0f;
2449                 y = -1.0f;
2450                 return;
2451         }
2452
2453         if (__scrollDirection == ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL)
2454         {
2455                 x -= __startPosOfAxis;
2456                 if (!_FloatCompareGE(x, 0.0f))
2457                 {
2458                         x = -1.0f;
2459                         y = -1.0f;
2460                         return;
2461                 }
2462
2463                 x = x - static_cast<int> (x / __unitLengthOfAxis) * __unitLengthOfAxis;
2464
2465                 y += __scrollPosition - __topMargin;
2466                 if (!_FloatCompareGE(y, 0.0f))
2467                 {
2468                         x = -1.0f;
2469                         y = -1.0f;
2470                         return;
2471                 }
2472
2473                 y = y - static_cast<int> (y / __unitScrollLength) * __unitScrollLength;
2474         }
2475         else
2476         {
2477                 y -= __startPosOfAxis;
2478                 if (!_FloatCompareGE(y, 0.0f))
2479                 {
2480                         x = -1.0f;
2481                         y = -1.0f;
2482                         return;
2483                 }
2484
2485                 y = y - static_cast<int> (y - __unitLengthOfAxis) * __unitLengthOfAxis;
2486
2487                 x += __scrollPosition - __leftMargin;
2488                 if (!_FloatCompareGE(x, 0.0f))
2489                 {
2490                         x = -1.0f;
2491                         y = -1.0f;
2492                         return;
2493                 }
2494
2495                 x = x - static_cast<int> (x / __unitScrollLength) * __unitScrollLength;
2496         }
2497 }
2498
2499 result
2500 _IconListPresenter::StartTouchActionTimer(void)
2501 {
2502         result r = E_SUCCESS;
2503
2504         if (__pTouchActionTimer == null)
2505         {
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.");
2508
2509                 r = __pTouchActionTimer->Construct(*this);
2510                 SysTryCatch(NID_UI, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
2511         }
2512         else
2513         {
2514                 __pTouchActionTimer->Cancel();
2515         }
2516
2517         r = __pTouchActionTimer->Start(TOUCH_ACTION_TIMER_PERIOD);
2518         SysTryCatch(NID_UI, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
2519
2520         return r;
2521
2522 CATCH:
2523         ResetTouchActionTimer();
2524         return r;
2525 }
2526
2527 result
2528 _IconListPresenter::ResetTouchActionTimer(void)
2529 {
2530         delete __pTouchActionTimer;
2531         __pTouchActionTimer = null;
2532
2533         return E_SUCCESS;
2534 }
2535
2536 result
2537 _IconListPresenter::StartMagneticScrollTimer(void)
2538 {
2539         result r = E_SUCCESS;
2540
2541         if (__pMagneticScrollTimer == null)
2542         {
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.");
2545
2546                 r = __pMagneticScrollTimer->Construct(*this);
2547                 SysTryCatch(NID_UI, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
2548         }
2549         else
2550         {
2551                 __pMagneticScrollTimer->Cancel();
2552         }
2553
2554         r = __pMagneticScrollTimer->Start(MAGNETIC_SCROLL_TIMER_PERIOD);
2555         SysTryCatch(NID_UI, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
2556
2557         return r;
2558
2559 CATCH:
2560         ResetMagneticScrollTimer();
2561         return r;
2562 }
2563
2564 result
2565 _IconListPresenter::ResetMagneticScrollTimer(void)
2566 {
2567         if (__pMagneticScrollTimer != null)
2568         {
2569                 FireScrollStoppedEvent();
2570         }
2571
2572         delete __pMagneticScrollTimer;
2573         __pMagneticScrollTimer = null;
2574
2575         return E_SUCCESS;
2576 }
2577
2578 result
2579 _IconListPresenter::StartReorderScrollTimer(void)
2580 {
2581         result r = E_SUCCESS;
2582
2583         if (__pReorderScrollTimer == null)
2584         {
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.");
2587
2588                 r = __pReorderScrollTimer->Construct(*this);
2589                 SysTryCatch(NID_UI, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
2590         }
2591         else
2592         {
2593                 __pReorderScrollTimer->Cancel();
2594         }
2595
2596         r = __pReorderScrollTimer->Start(REORDER_SCROLL_TIMER_PERIOD);
2597         SysTryCatch(NID_UI, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
2598
2599         return r;
2600
2601 CATCH:
2602         ResetReorderScrollTimer();
2603         return r;
2604 }
2605
2606 result
2607 _IconListPresenter::ResetReorderScrollTimer(void)
2608 {
2609         delete __pReorderScrollTimer;
2610         __pReorderScrollTimer = null;
2611
2612         return E_SUCCESS;
2613 }
2614
2615 result
2616 _IconListPresenter::StartAnimationTimer(int delay)
2617 {
2618         result r = E_SUCCESS;
2619
2620         if (__pAnimationTimer == null)
2621         {
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.");
2624
2625                 r = __pAnimationTimer->Construct(*this);
2626                 SysTryCatch(NID_UI, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
2627         }
2628         else
2629         {
2630                 __pAnimationTimer->Cancel();
2631         }
2632
2633         r = __pAnimationTimer->Start(delay);
2634         SysTryCatch(NID_UI, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
2635
2636         return r;
2637
2638 CATCH:
2639         ResetAnimationTimer();
2640         return r;
2641
2642 }
2643
2644 result
2645 _IconListPresenter::ResetAnimationTimer(void)
2646 {
2647         delete __pAnimationTimer;
2648         __pAnimationTimer = null;
2649
2650         return E_SUCCESS;
2651 }
2652
2653 // Tizen::Ui::_ControlImpl
2654 void
2655 _IconListPresenter::OnBoundsChanged(void)
2656 {
2657         __isLayoutChanged = true;
2658
2659         if (__pIconListView->GetScroll() != null)
2660         {
2661                 __pIconListView->GetScroll()->OnParentBoundsChanged();
2662         }
2663 }
2664
2665 void
2666 _IconListPresenter::OnFontInfoRequested(unsigned long& style, float& size)
2667 {
2668         style = FONT_STYLE_PLAIN;
2669
2670         if (__pListModel->GetItemCountInGroup(DEFAULT_GROUP_INDEX) <= 0)
2671         {
2672                 size = __pIconListView->GetTextSizeOfEmptyList();
2673         }
2674         else
2675         {
2676                 size = __pItemDrawingProperty->GetTextSize();
2677         }
2678 }
2679
2680 void
2681 _IconListPresenter::OnFontChanged(Font* pFont)
2682 {
2683         ClearVisualElement();
2684         __pItemDrawingProperty->SetFont(pFont);
2685 }
2686
2687 // Tizen::Ui::_IKeyEventPreviewer
2688 bool
2689 _IconListPresenter::OnPreviewKeyPressed(const _Control& source, const _KeyInfo& keyInfo)
2690 {
2691         return true;
2692 }
2693
2694 bool
2695 _IconListPresenter::OnPreviewKeyReleased(const _Control& source, const _KeyInfo& keyInfo)
2696 {
2697         return true;
2698 }
2699
2700 // Tizen::Ui::_IKeyEventListener
2701 bool
2702 _IconListPresenter::OnKeyPressed(const _Control& source, const _KeyInfo& keyInfo)
2703 {
2704         return true;
2705 }
2706
2707 bool
2708 _IconListPresenter::OnKeyReleased(const _Control& source, const _KeyInfo& keyInfo)
2709 {
2710         return true;
2711 }
2712
2713 // Tizen::Ui::_INotificationEventPreviewer
2714 bool
2715 _IconListPresenter::OnPreviewNotifiedN(const _Control& source, IList* pArgs)
2716 {
2717         delete pArgs;
2718         return true;
2719 }
2720
2721 // Tizen::Ui::_INotificationEventListener
2722 bool
2723 _IconListPresenter::OnNotifiedN(const _Control& source, IList* pArgs)
2724 {
2725         delete pArgs;
2726         return true;
2727 }
2728
2729 // Tizen::Ui::_ITouchEventPreviewer
2730 _UiTouchEventDelivery
2731 _IconListPresenter::OnPreviewTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
2732 {
2733         if (__selectedIndex < 0)
2734         {
2735                 // handle the event of touch release that occurred from thumb style scrollbar
2736                 _Scroll* pScroll = __pIconListView->GetScroll();
2737                 if (pScroll != null && pScroll->IsEnabledHandler())
2738                 {
2739                         // Trigger Magnetic Scroll Effect
2740                         if ((__pMagneticScrollTimer == null) && (!__flickRunning) && (__magneticScrollSize > 0))
2741                         {
2742                                 float diff = GetMagneticScrollPosition() - __scrollPosition;
2743                                 if (diff != 0)
2744                                 {
2745                                         ResetMagneticScrollTimer();
2746
2747                                         // Trigger Magnetic Scroll Effect
2748                                         __magneticScrollAnimation.StartAnimation(diff);
2749                                         StartMagneticScrollTimer();
2750                                 }
2751                                 else
2752                                 {
2753                                         ScrollFadeOut();
2754                                 }
2755                         }
2756
2757                         if ((__pMagneticScrollTimer == null) && (!__flickRunning))
2758                         {
2759                                 ScrollFadeOut();
2760                         }
2761                 }
2762         }
2763
2764         return _UI_TOUCH_EVENT_DELIVERY_YES;
2765 }
2766
2767 // Tizen::Ui::_ITouchEventListener
2768 bool
2769 _IconListPresenter::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
2770 {
2771         __currentTouchInfo = touchinfo;
2772         __isTouchPressed = true;
2773
2774         _Scroll* pScroll = __pIconListView->GetScroll();
2775         if (pScroll != null)
2776         {
2777                 float scrollPosition = pScroll->GetScrollPosition();
2778                 if (!_FloatCompare(scrollPosition, __scrollPosition))
2779                 {
2780                         pScroll->SetScrollPosition(__scrollPosition);
2781                 }
2782         }
2783
2784         StopAllAnimations();
2785
2786         // Reset Timer
2787         ResetAnimationTimer();
2788         ResetTouchActionTimer();
2789         ResetMagneticScrollTimer();
2790         StartTouchActionTimer();
2791
2792         return true;
2793 }
2794
2795 bool
2796 _IconListPresenter::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
2797 {
2798         __isTouchPressed = false;
2799         __firstTouchMove = true;
2800         int fireIndex = INVALID_INDEX;;
2801
2802         if (__onReordering)
2803         {
2804                 FinishReordering();
2805                 PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_LIST_REORDER);
2806         }
2807         else
2808         {
2809                 if (__selectedIndex >= 0)
2810                 {
2811                         fireIndex = __selectedIndex;
2812                         __isSelectionDelayed = false;
2813
2814                         PreDrawCheckAnimation(fireIndex);
2815                         FireEventAfterTouchRelease(fireIndex);
2816
2817                         if (__isTouchAnimationEnabled)
2818                         {
2819                                 StartSelectAnimation(fireIndex);
2820                         }
2821                         else
2822                         {
2823                                 DrawCheckAnimation(fireIndex);
2824                         }
2825                 }
2826                 else if (__pTouchActionTimer != null)
2827                 {
2828                         ResetTouchActionTimer();
2829                         if (OnTouchActionActivated(*__pIconListView, __currentTouchInfo))
2830                         {
2831                                 fireIndex = __selectedIndex;
2832                                 __isSelectionDelayed = true;
2833
2834                                 PreDrawCheckAnimation(fireIndex);
2835                                 FireEventAfterTouchRelease(fireIndex);
2836
2837                                 if (__isTouchAnimationEnabled)
2838                                 {
2839                                         StartSelectAnimation(fireIndex);
2840                                 }
2841                                 else
2842                                 {
2843                                         DrawCheckAnimation(fireIndex);
2844                                 }
2845                         }
2846                 }
2847         }
2848
2849         // Trigger Magnetic Scroll Effect
2850         if ((__pMagneticScrollTimer == null) && (!__flickRunning) && (__magneticScrollSize > 0))
2851         {
2852                 float diff = GetMagneticScrollPosition() - __scrollPosition;
2853                 if (!_FloatCompare(diff, 0.0f))
2854                 {
2855                         ResetMagneticScrollTimer();
2856
2857                         // Trigger Magnetic Scroll Effect
2858                         __magneticScrollAnimation.StartAnimation(diff);
2859                         StartMagneticScrollTimer();
2860                 }
2861                 else
2862                 {
2863                         ScrollFadeOut();
2864                 }
2865         }
2866
2867         if ((__pMagneticScrollTimer == null) && (!__flickRunning))
2868         {
2869                 if (__pIconListView->GetScroll()->GetScrollVisibility())
2870                 {
2871                         ScrollFadeOut();
2872                         InitializeAccessibilityElement();
2873                 }
2874         }
2875
2876         return true;
2877 }
2878
2879 void
2880 _IconListPresenter::FireEventAfterTouchRelease(int index)
2881 {
2882         if (index >= 0 && __pListModel->IsItemEnabled(DEFAULT_GROUP_INDEX, index))
2883         {
2884                 if (__selectedOverlayBitmapId >= 0)
2885                 {
2886                         FireIconListViewItemEvent(EVENT_TYPE_OVERLAY_BITMAP_SELECTED, index, __selectedOverlayBitmapId);
2887                         return;
2888                 }
2889
2890                 switch (__pIconListView->GetStyle())
2891                 {
2892                 case ICON_LIST_VIEW_STYLE_NORMAL:
2893                 {
2894                         FireIconListViewItemEvent(EVENT_TYPE_ITEM_SELECTED, index, ICON_LIST_VIEW_ITEM_SELECTED);
2895                         break;
2896                 }
2897
2898                 case ICON_LIST_VIEW_STYLE_RADIO:
2899                 {
2900                         FireIconListViewItemEvent(EVENT_TYPE_ITEM_SELECTED, index, ICON_LIST_VIEW_ITEM_CHECKED);
2901                         InitializeAccessibilityElement();
2902                         break;
2903                 }
2904
2905                 case ICON_LIST_VIEW_STYLE_MARK:
2906                 {
2907                         bool isChecked = __pListModel->IsItemChecked(DEFAULT_GROUP_INDEX, index);
2908                         InitializeAccessibilityElement();
2909
2910                         if (isChecked)
2911                         {
2912                                 FireIconListViewItemEvent(EVENT_TYPE_ITEM_SELECTED, index, ICON_LIST_VIEW_ITEM_CHECKED);
2913                         }
2914                         else
2915                         {
2916                                 FireIconListViewItemEvent(EVENT_TYPE_ITEM_SELECTED, index, ICON_LIST_VIEW_ITEM_UNCHECKED);
2917                         }
2918                         break;
2919                 }
2920                 }
2921                 PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_TAP);
2922         }
2923 }
2924
2925 bool
2926 _IconListPresenter::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
2927 {
2928         const FloatPoint movedPosition = touchinfo.GetCurrentPosition();
2929
2930         if (__pTouchActionTimer != null)
2931         {
2932                 ResetAnimationTimer();
2933                 ResetTouchActionTimer();
2934
2935                 int revertIndex = __selectedIndex;
2936                 __selectedIndex = INVALID_INDEX;
2937                 __selectedOverlayBitmapId = -1;
2938                 RedrawItem(revertIndex);
2939         }
2940
2941         if (__pIconListView == null || !__isTouchPressed)
2942         {
2943                 __currentTouchInfo = touchinfo;
2944                 return true;
2945         }
2946
2947         FloatPoint pressedPosition = __currentTouchInfo.GetCurrentPosition();
2948
2949         if (__onReordering)
2950         {
2951                 DoReordering(movedPosition);
2952                 return true;
2953         }
2954
2955         if (__pIconListView->GetScrollInputMode() == SCROLL_INPUT_MODE_RESTRICT_TO_INITIAL_DIRECTION)
2956         {
2957                 float scrollDistanceX = _Abs(pressedPosition.x - movedPosition.x);
2958                 float scrollDistanceY = _Abs(pressedPosition.y - movedPosition.y);
2959
2960                 bool isVerticalDirection = scrollDistanceY > scrollDistanceX;
2961                 bool isHorizontalDirection = scrollDistanceX > scrollDistanceY;
2962
2963                 if (__firstTouchMove)
2964                         {
2965                                 if (isVerticalDirection)
2966                                 {
2967                                         __firstTouchMoveDirection = ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL;
2968                                 }
2969                                 else if (isHorizontalDirection)
2970                                 {
2971                                         __firstTouchMoveDirection = ICON_LIST_VIEW_SCROLL_DIRECTION_HORIZONTAL;
2972                                 }
2973                                 else
2974                                 {
2975                                         __firstTouchMoveDirection = __scrollDirection;
2976                                 }
2977                                 __firstTouchMove = false;
2978                         }
2979
2980                 if (__scrollDirection != __firstTouchMoveDirection)
2981                 {
2982                         if (__firstTouchMoveDirection == ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL && !isHorizontalDirection)
2983                         {
2984                                 return false;
2985                         }
2986                         else if (__firstTouchMoveDirection == ICON_LIST_VIEW_SCROLL_DIRECTION_HORIZONTAL && !isVerticalDirection)
2987                         {
2988                                 return false;
2989                         }
2990                         return true;
2991                 }
2992                 else
2993                 {
2994                         if (__firstTouchMoveDirection == ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL && isHorizontalDirection)
2995                         {
2996                                 return true;
2997                         }
2998                         else if (__firstTouchMoveDirection == ICON_LIST_VIEW_SCROLL_DIRECTION_HORIZONTAL && isVerticalDirection)
2999                         {
3000                                 return true;
3001                         }
3002                 }
3003         }
3004
3005         float scrollPosition = __scrollPosition;
3006
3007         _Scroll* pScroll = __pIconListView->GetScroll();
3008         if (pScroll != null)
3009         {
3010                 scrollPosition = pScroll->GetScrollPosition();
3011         }
3012
3013         if (__scrollDirection == ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL)
3014         {
3015                 scrollPosition += pressedPosition.y - movedPosition.y;
3016         }
3017         else
3018         {
3019                 scrollPosition += pressedPosition.x - movedPosition.x;
3020         }
3021
3022         __currentTouchInfo = touchinfo;
3023
3024         if (SetScrollPosition(scrollPosition))
3025         {
3026                 // Draw
3027                 __selectedIndex = INVALID_INDEX;
3028                 __pIconListView->Invalidate();
3029
3030                 // Trigger ScrollEvent
3031                 FireScrollEvent();
3032
3033                 return true;
3034         }
3035
3036         return false;
3037 }
3038
3039 bool
3040 _IconListPresenter::OnTouchActionActivated(const _Control& source, const _TouchInfo& touchinfo)
3041 {
3042         if (__pListModel == null || __pIconListView == null)
3043         {
3044                 return false;
3045         }
3046
3047         if (__pIconListView->IsInReorderingMode())
3048         {
3049                 __lastReorderedPosition = touchinfo.GetCurrentPosition();
3050                 PrepareReordering();
3051                 __lastReorderedDifferences.x = touchinfo.GetCurrentPosition().x - __reorderItemBounds.x;
3052                 __lastReorderedDifferences.y = touchinfo.GetCurrentPosition().y - __reorderItemBounds.y;
3053         }
3054         else
3055         {
3056                 FloatPoint touchPressedPosition = touchinfo.GetCurrentPosition();
3057                 int index = GetItemIndexFromPosition(touchPressedPosition);
3058                 if (index >= 0 && __pListModel->IsItemEnabled(DEFAULT_GROUP_INDEX, index))
3059                 {
3060                         __selectedIndex = index;
3061                         __selectedOverlayBitmapId = -1;
3062                         _IconListItem* pItem = dynamic_cast<_IconListItem*>(__pListModel->LoadItem(DEFAULT_GROUP_INDEX, index));
3063                         if (pItem != null)
3064                         {
3065                                 pItem->SetDrawingProperty(*__pItemDrawingProperty);
3066
3067                                 TranslateIconListItemPosition(touchPressedPosition.x, touchPressedPosition.y);
3068                                 if (_FloatCompareGE(touchPressedPosition.x, 0.0f) && _FloatCompareGE(touchPressedPosition.y, 0.0f))
3069                                 {
3070                                         __selectedOverlayBitmapId = pItem->GetOverlayBitmapIdFromPosition(touchPressedPosition);
3071                                 }
3072                         }
3073
3074                         bool flag = __isTouchAnimationEnabled;
3075                         __isTouchAnimationEnabled = false;
3076
3077                         RedrawItem(index);
3078
3079                         if (flag)
3080                         {
3081                                 __isTouchAnimationEnabled = true;
3082                         }
3083                 }
3084                 else
3085                 {
3086                         return false;
3087                 }
3088         }
3089         return true;
3090 }
3091
3092 bool
3093 _IconListPresenter::OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
3094 {
3095         StopScrollToAnimation();
3096
3097         ResetAnimationTimer();
3098         ResetTouchActionTimer();
3099         ResetMagneticScrollTimer();
3100         ResetReorderScrollTimer();
3101
3102         __isTouchPressed = false;
3103         __firstTouchMove = true;
3104         ScrollFadeOut();
3105
3106         return true;
3107 }
3108
3109 bool
3110 _IconListPresenter::OnFlickGestureDetected(bool isFlicked, const Point& flickPosition, int flickTime)
3111 {
3112         if (isFlicked)
3113         {
3114                 StopAllAnimations();
3115
3116                 ResetAnimationTimer();
3117                 ResetTouchActionTimer();
3118                 ResetMagneticScrollTimer();
3119
3120                 __flickRunning = true;
3121
3122                 float targetPosition = __scrollPosition;
3123                 if (__scrollDirection == ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL && flickPosition.y != 0)
3124                 {
3125                         targetPosition -= CalculateFlickAmount(flickPosition.y, flickTime);
3126                 }
3127                 else if (__scrollDirection == ICON_LIST_VIEW_SCROLL_DIRECTION_HORIZONTAL && flickPosition.x != 0)
3128                 {
3129                         targetPosition -= CalculateFlickAmount(flickPosition.x, flickTime);
3130                 }
3131
3132                 if (_FloatCompareLE(targetPosition, OVERSCROLLING_MAX_DISTANCE * -1))
3133                 {
3134                         targetPosition = (OVERSCROLLING_MAX_DISTANCE * -1);
3135                 }
3136                 else if (_FloatCompareGE(targetPosition, __scrollLength + OVERSCROLLING_MAX_DISTANCE))
3137                 {
3138                         targetPosition = (__scrollLength + OVERSCROLLING_MAX_DISTANCE);
3139                 }
3140                 else if (__magneticScrollSize > 0)
3141                 {
3142                         targetPosition = GetMagneticScrollPosition(targetPosition);
3143                 }
3144
3145                 StartScrollToAnimation(targetPosition);
3146         }
3147         return true;
3148 }
3149
3150 bool
3151 _IconListPresenter::OnLongPressGestureDetected(void)
3152 {
3153         return true;
3154 }
3155
3156 void
3157 _IconListPresenter::OnTimerExpired(Timer& timer)
3158 {
3159         if (&timer == __pTouchActionTimer)
3160         {
3161                 OnTouchActionActivated(*__pIconListView, __currentTouchInfo);
3162         }
3163         else if (&timer == __pMagneticScrollTimer)
3164         {
3165                 float scrollPosition = 0.0f;
3166                 if (__magneticScrollAnimation.GetMagneticScrollAnimationFrame(scrollPosition))
3167                 {
3168                         scrollPosition += __pIconListView->GetScroll()->GetScrollPosition();
3169                         if (SetScrollPosition(scrollPosition))
3170                         {
3171                                 StartMagneticScrollTimer();
3172                                 __pIconListView->Invalidate();
3173
3174                                 FireScrollPositionChangedEvent(__scrollPosition);
3175                         }
3176                 }
3177                 else
3178                 {
3179                         ResetMagneticScrollTimer();
3180
3181                         if (!__flickRunning)
3182                         {
3183                                 ScrollFadeOut();
3184                                 FireScrollEvent();
3185                                 FireScrollStoppedEvent();
3186                                 InitializeAccessibilityElement();
3187                         }
3188                 }
3189         }
3190         else if (&timer == __pReorderScrollTimer)
3191         {
3192                 StartReorderScrollAnimation();
3193         }
3194         else if (&timer == __pAnimationTimer)
3195         {
3196                 int index = __animationItemIndex;
3197                 ResetAnimationTimer();
3198
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()));
3202
3203                 AddAnimation(*pItem, index);
3204         }
3205 }
3206
3207 void
3208 _IconListPresenter::StartReorderScrollAnimation(void)
3209 {
3210         float scrollPosition = __scrollPosition;
3211         scrollPosition += __reorderScrollAnimationDistance;
3212
3213         if (SetScrollPosition(scrollPosition))
3214         {
3215                 __pIconListView->Invalidate();
3216                 FireScrollPositionChangedEvent(__scrollPosition);
3217
3218                 if (!_FloatCompareLE(__scrollPosition, 0.0f) && !_FloatCompareGE(__scrollPosition, __scrollLength))
3219                 {
3220                         StartReorderScrollTimer();
3221                 }
3222         }
3223 }
3224
3225 void
3226 _IconListPresenter::OnVisibleStateChanged(void)
3227 {
3228         StopScrollToAnimation();
3229
3230         ResetAnimationTimer();
3231         ResetTouchActionTimer();
3232         ResetMagneticScrollTimer();
3233         ResetReorderScrollTimer();
3234 }
3235
3236 void
3237 _IconListPresenter::OnInputEnableStateChanged(void)
3238 {
3239         if (__selectedIndex != INVALID_INDEX)
3240         {
3241                 int inputEnableIndex = __selectedIndex;
3242                 __selectedIndex = INVALID_INDEX;
3243                 RedrawItem(inputEnableIndex);
3244         }
3245 }
3246
3247 // Tizen::Ui::_IScrollEventListener
3248 void
3249 _IconListPresenter::OnScrollEndReached(_Control& source, ScrollEndEvent type)
3250 {
3251         ScrollFadeOut();
3252         FireScrollEndReachedEvent(type);
3253 }
3254
3255 void
3256 _IconListPresenter::OnScrollPositionChanged(_Control& source, float scrollPosition)
3257 {
3258         StopScrollToAnimation();
3259
3260         if (SetScrollPosition(scrollPosition))
3261         {
3262                 __selectedIndex = INVALID_INDEX;
3263                 __pIconListView->Invalidate();
3264
3265                 ScrollFadeOut();
3266                 FireScrollEvent();
3267         }
3268 }
3269
3270 void
3271 _IconListPresenter::OnScrollStopped(_Control& source)
3272 {
3273         FireScrollStoppedEvent();
3274         InitializeAccessibilityElement();
3275 }
3276
3277 void
3278 _IconListPresenter::OnScrollJumpToTop(_Control& source)
3279 {
3280         StopScrollToAnimation();
3281
3282         if (SetScrollPosition(0.0f))
3283         {
3284                 __selectedIndex = INVALID_INDEX;
3285                 __pIconListView->Invalidate();
3286
3287                 ScrollFadeOut();
3288                 FireScrollEvent();
3289         }
3290 }
3291
3292 // Tizen::Ui::Animations::IAnimationTransactionEventListener
3293 void
3294 _IconListPresenter::OnAnimationTransactionStarted(int transactionId)
3295 {
3296 }
3297
3298 void
3299 _IconListPresenter::OnAnimationTransactionStopped(int transactionId)
3300 {
3301         if (__addTransactionId == transactionId)
3302         {
3303                 __animationItemIndex = INVALID_INDEX;
3304                 __addTransactionId = 0;
3305                 __pPreviousAnimationVE->SetOpacity(1.0f);
3306                 RedrawItem(__previousAnimationItemIndex);
3307         }
3308         else if (__removeTransactionId == transactionId)
3309         {
3310                 __removeTransactionId = 0;
3311
3312                 if (__pRemoveItemVE != null)
3313                 {
3314                         _VisualElement* pParent = __pIconListView->GetVisualElement();
3315                         if (pParent != null)
3316                         {
3317                                 pParent->DetachChild(*__pRemoveItemVE);
3318                         }
3319                         __pRemoveItemVE->Destroy();
3320                         __pRemoveItemVE = null;
3321                 }
3322
3323         }
3324         else if (__moveTransactionId == transactionId)
3325         {
3326                 __moveTransactionId = 0;
3327         }
3328
3329         ClearVisualElement();
3330
3331         if (__pIconListView != null)
3332         {
3333                 __pIconListView->Invalidate();
3334         }
3335 }
3336
3337 void
3338 _IconListPresenter::OnAnimationTransactionFinished(int transactionId)
3339 {
3340         if (__addTransactionId == transactionId)
3341         {
3342                 __addTransactionId = 0;
3343                 RedrawItem(__animationItemIndex);
3344                 __animationItemIndex = INVALID_INDEX;
3345         }
3346         else if (__removeTransactionId == transactionId)
3347         {
3348                 __removeTransactionId = 0;
3349
3350                 if (__pRemoveItemVE != null)
3351                 {
3352                         _VisualElement* pParent = __pIconListView->GetVisualElement();
3353                         if (pParent != null)
3354                         {
3355                                 pParent->DetachChild(*__pRemoveItemVE);
3356                         }
3357                         __pRemoveItemVE->Destroy();
3358                         __pRemoveItemVE = null;
3359                 }
3360         }
3361         else if (__moveTransactionId == transactionId)
3362         {
3363                 __moveTransactionId = 0;
3364         }
3365 }
3366
3367 // Tizen::Ui::Animations::IVisualElementAnimationTickEventListener
3368 void
3369 _IconListPresenter::OnTickOccurred(const VisualElementAnimation& animation, const String& keyName, VisualElement& target, const Variant& currentValue)
3370 {
3371         if (&target != __pIconListView->GetVisualElement() && &target != __pCheckAnimationVE)
3372         {
3373                 return;
3374         }
3375
3376         if (keyName == L"ScrollAnimation")
3377         {
3378                 if (SetScrollPosition(currentValue.ToFloat()))
3379                 {
3380                         __pIconListView->Invalidate();
3381                         FireScrollEvent();
3382                 }
3383                 FireScrollPositionChangedEvent(__scrollPosition);
3384         }
3385
3386         if (keyName == L"CheckAnimation")
3387         {
3388                 Canvas* pCanvas = __pCheckAnimationVE->GetCanvasN();
3389
3390                 if (pCanvas == null)
3391                 {
3392                         return;
3393                 }
3394
3395                 const Bitmap* pBitmap = null;
3396                 pBitmap = IsItemChecked(__checkedIndex) ? __pItemDrawingProperty->GetCheckBitmap(): null;
3397
3398                 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
3399                 pCanvas->Clear();
3400
3401                 SysLogException(NID_UI_CTRL, E_SUCCESS, "currentValue %f", currentValue.ToFloat());
3402                 if (pBitmap != null)
3403                 {
3404                         if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pBitmap))
3405                         {
3406                                 pCanvas->DrawNinePatchedBitmap(FloatRectangle(0.0f, 0.0f, pBitmap->GetWidthF(), pBitmap->GetHeightF()), *pBitmap);
3407                         }
3408                         else
3409                         {
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));
3411                         }
3412                 }
3413                 delete pCanvas;
3414         }
3415 }
3416
3417 // Tizen::Ui::Animations::IVisualElementAnimationStatusEventListener
3418 void
3419 _IconListPresenter::OnVisualElementAnimationStarted(const VisualElementAnimation& animation, const String& keyName, VisualElement& target)
3420 {
3421         // nothing
3422         if (keyName == L"CheckAnimation")
3423         {
3424                 RedrawItem(__checkedIndex);
3425         }
3426 }
3427
3428 void
3429 _IconListPresenter::OnVisualElementAnimationRepeated(const VisualElementAnimation& animation, const String& keyName, VisualElement& target, long currentRepeatCount)
3430 {
3431         // nothing
3432 }
3433
3434 void
3435 _IconListPresenter::OnVisualElementAnimationFinished(const VisualElementAnimation& animation, const String& keyName, VisualElement& target, bool completedNormally)
3436 {
3437         if (keyName == L"ScrollAnimation")
3438         {
3439                 if (&target != __pIconListView->GetVisualElement())
3440                 {
3441                         return;
3442                 }
3443
3444                 __flickRunning = false;
3445                 ScrollFadeOut();
3446                 FireScrollPositionChangedEvent(__scrollPosition);
3447                 FireScrollStoppedEvent();
3448         }
3449
3450         if (keyName == L"SelectAnimation")
3451         {
3452                 if (&target != __pIconListView->GetVisualElement() && &target != __pPreviousSelectAnimationVE && &target != __pSelectAnimationVE)
3453                 {
3454                         return;
3455                 }
3456
3457                 int index = __selectedIndex;
3458                 __selectedIndex = INVALID_INDEX;
3459
3460                 if (!completedNormally)
3461                 {
3462                         if (__pIconListView->GetStyle() == ICON_LIST_VIEW_STYLE_RADIO)
3463                         {
3464                                 if (__checkedIndex != __checkedRadioIndex)
3465                                 {
3466                                         RedrawItem(__checkedIndex);
3467                                         RedrawItem(__checkedRadioIndex);
3468                                 }
3469                         }
3470                         RedrawItem(index);
3471                 }
3472                 else
3473                 {
3474                         DrawCheckAnimation(index);
3475                 }
3476                 __isSelectAnimationRunning = false;
3477         }
3478
3479         if (keyName == L"CheckAnimation")
3480         {
3481                 if (&target != __pIconListView->GetVisualElement() && &target != __pPreviousCheckAnimationVE && &target != __pCheckAnimationVE)
3482                 {
3483                         return;
3484                 }
3485
3486                 int index = __checkedIndex;
3487                 __checkedIndex = INVALID_INDEX;
3488
3489                 if (!completedNormally)
3490                 {
3491                         RedrawItem(index);
3492                 }
3493                 __isCheckAnimationRunning = false;
3494         }
3495 }
3496
3497 void
3498 _IconListPresenter::PrepareReordering(void)
3499 {
3500         int index = GetItemIndexFromPosition(__lastReorderedPosition);
3501         if (__onReordering || index == INVALID_INDEX)
3502         {
3503                 return;
3504         }
3505
3506         __onReordering = true;
3507         __reorderFromIndex = index;
3508         __reorderToIndex = index;
3509
3510         if (__pListModel->IsValidItem(DEFAULT_GROUP_INDEX, __reorderToIndex))
3511         {
3512                 _IconListItem* pToItem = static_cast <_IconListItem*>(__pListModel->LoadItem(DEFAULT_GROUP_INDEX, __reorderToIndex));
3513                 if (pToItem != null)
3514                 {
3515                         _VisualElement* pItemVE = pToItem->GetItemVisualElement();
3516                         if (pItemVE != null)
3517                         {
3518                                 __reorderItemBounds = pItemVE->GetBounds();
3519                                 pItemVE->SetImplicitAnimationEnabled(false);
3520                                 RedrawItem(__reorderToIndex);
3521                         }
3522                 }
3523                 else
3524                 {
3525                         ClearReorderingInformation();
3526                 }
3527         }
3528         else
3529         {
3530                 ClearReorderingInformation();
3531         }
3532 }
3533
3534 void
3535 _IconListPresenter::DoReordering(const FloatPoint& movedPosition)
3536 {
3537         if (__pListModel->IsValidItem(DEFAULT_GROUP_INDEX, __reorderToIndex))
3538         {
3539                 _IconListItem* pToItem = static_cast <_IconListItem*>(__pListModel->LoadItem(DEFAULT_GROUP_INDEX, __reorderToIndex));
3540                 if (pToItem != null)
3541                 {
3542                         _VisualElement* pItemVE = pToItem->GetItemVisualElement();
3543                         if (pItemVE != null)
3544                         {
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));
3549
3550                                 if (__scrollDirection == ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL)
3551                                 {
3552                                         if (!_FloatCompareGE(movedPosition.y, __topMargin))
3553                                         {
3554                                                 __reorderScrollAnimationDistance = -REORDER_SCROLL_ANIMATION_DISTANCE;
3555                                                 if (__pReorderScrollTimer == null && !_FloatCompareLE(__scrollPosition, 0.0f))
3556                                                 {
3557                                                         __scrollPositionBeforeScrollAnimation = __scrollPosition;
3558                                                         StartReorderScrollTimer();
3559                                                 }
3560                                         }
3561                                         else if (!_FloatCompareLE(movedPosition.y + __lastReorderedDifferences.y, __pIconListView->GetBounds().height - __bottomMargin) &&
3562                                                         !_FloatCompareGE(__scrollPosition, __scrollLength))
3563                                         {
3564                                                 __reorderScrollAnimationDistance = REORDER_SCROLL_ANIMATION_DISTANCE;
3565                                                 if (__pReorderScrollTimer == null)
3566                                                 {
3567                                                         __scrollPositionBeforeScrollAnimation = __scrollPosition;
3568                                                         StartReorderScrollTimer();
3569                                                 }
3570                                         }
3571                                         else
3572                                         {
3573                                                 if (__pReorderScrollTimer == null)
3574                                                 {
3575                                                         CheckAndReorderItem(movedPosition.x - __lastReorderedPosition.x, movedPosition.y - __lastReorderedPosition.y);
3576                                                 }
3577                                                 else
3578                                                 {
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;
3586                                                 }
3587                                         }
3588                                 }
3589                                 else
3590                                 {
3591                                         if (!_FloatCompareGE(movedPosition.x, __leftMargin) && !_FloatCompareLE(__scrollPosition, 0.0f))
3592                                         {
3593                                                 __reorderScrollAnimationDistance = -REORDER_SCROLL_ANIMATION_DISTANCE;
3594                                                 if (__pReorderScrollTimer == null)
3595                                                 {
3596                                                         __scrollPositionBeforeScrollAnimation = __scrollPosition;
3597                                                         StartReorderScrollTimer();
3598                                                 }
3599                                         }
3600                                         else if (!_FloatCompareLE(movedPosition.x + __lastReorderedDifferences.x, __pIconListView->GetBounds().width - __rightMargin) &&
3601                                                         !_FloatCompareGE(__scrollPosition, __scrollLength))
3602                                         {
3603                                                 __reorderScrollAnimationDistance = REORDER_SCROLL_ANIMATION_DISTANCE;
3604                                                 if (__pReorderScrollTimer == null)
3605                                                 {
3606                                                         __scrollPositionBeforeScrollAnimation = __scrollPosition;
3607                                                         StartReorderScrollTimer();
3608                                                 }
3609                                         }
3610                                         else
3611                                         {
3612                                                 if (__pReorderScrollTimer == null)
3613                                                 {
3614                                                         CheckAndReorderItem(movedPosition.x - __lastReorderedPosition.x, movedPosition.y - __lastReorderedPosition.y);
3615                                                 }
3616                                                 else
3617                                                 {
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;
3625                                                 }
3626                                         }
3627                                 }
3628                         }
3629                 }
3630         }
3631 }
3632
3633 void
3634 _IconListPresenter::CheckAndReorderItem(float movedX, float movedY)
3635 {
3636         bool toUp = false;
3637         bool toDown = false;
3638         bool toLeft = false;
3639         bool toRight = false;
3640
3641         bool singleItemChanged = true;
3642
3643         float horizontalThreshold = (GetItemSize().width + __verticalSpacing) / 2;
3644         float verticalThreshold = (GetItemSize().height  + __verticalSpacing) / 2;
3645
3646         if (!_FloatCompareLE(_Abs(movedX), horizontalThreshold))
3647         {
3648                 if (!_FloatCompareLE(movedX, 0.0f))
3649                 {
3650                         toRight = true;
3651                 }
3652                 else
3653                 {
3654                         toLeft = true;
3655                 }
3656         }
3657
3658         if (!_FloatCompareLE(_Abs(movedY), verticalThreshold))
3659         {
3660                 if (!_FloatCompareLE(movedY, 0.0f))
3661                 {
3662                         toDown = true;
3663                 }
3664                 else
3665                 {
3666                         toUp = true;
3667                 }
3668         }
3669
3670         int toIndex = INVALID_INDEX;
3671
3672         if (__scrollDirection == ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL)
3673         {
3674                 if (toLeft)
3675                 {
3676                         if (__reorderToIndex % __itemCountPerAxis != 0)
3677                         {
3678                                 toIndex = __reorderToIndex - 1;
3679                                 __lastReorderedPosition.x -= __unitLengthOfAxis;
3680                         }
3681                 }
3682                 else if (toRight)
3683                 {
3684                         if (__reorderToIndex % __itemCountPerAxis != __itemCountPerAxis - 1)
3685                         {
3686                                 toIndex = __reorderToIndex + 1;
3687                                 __lastReorderedPosition.x += __unitLengthOfAxis;
3688                         }
3689                 }
3690                 else if (toUp)
3691                 {
3692                         if (__reorderToIndex >= __itemCountPerAxis)
3693                         {
3694                                 toIndex = __reorderToIndex - __itemCountPerAxis;
3695                                 __lastReorderedPosition.y -= __unitScrollLength;
3696
3697                                 singleItemChanged = false;
3698                         }
3699                 }
3700                 else if (toDown)
3701                 {
3702                         if (__reorderToIndex + __itemCountPerAxis < __pListModel->GetAllItemCount())
3703                         {
3704                                 toIndex = __reorderToIndex +__itemCountPerAxis;
3705                                 __lastReorderedPosition.y += __unitScrollLength;
3706
3707                                 singleItemChanged = false;
3708                         }
3709                 }
3710         }
3711         else
3712         {
3713                 if (toUp)
3714                 {
3715                         if (__reorderToIndex % __itemCountPerAxis != 0)
3716                         {
3717                                 toIndex = __reorderToIndex - 1;
3718                                 __lastReorderedPosition.y -= __unitLengthOfAxis;
3719                         }
3720                 }
3721                 else if (toDown)
3722                 {
3723                         if (__reorderToIndex % __itemCountPerAxis != __itemCountPerAxis - 1)
3724                         {
3725                                 toIndex = __reorderToIndex + 1;
3726                                 __lastReorderedPosition.y += __unitLengthOfAxis;
3727                         }
3728                 }
3729                 else if (toLeft)
3730                 {
3731                         if (__reorderToIndex >= __itemCountPerAxis)
3732                         {
3733                                 toIndex = __reorderToIndex - __itemCountPerAxis;
3734                                 __lastReorderedPosition.x -= __unitScrollLength;
3735
3736                                 singleItemChanged = false;
3737                         }
3738                 }
3739                 else if (toRight)
3740                 {
3741                         if (__reorderToIndex + __itemCountPerAxis < __pListModel->GetAllItemCount())
3742                         {
3743                                 toIndex = __reorderToIndex +__itemCountPerAxis;
3744                                 __lastReorderedPosition.x += __unitScrollLength;
3745
3746                                 singleItemChanged = false;
3747                         }
3748                 }
3749         }
3750
3751         if (toIndex != INVALID_INDEX)
3752         {
3753                 SwapReorderedItems(toIndex, singleItemChanged);
3754         }
3755 }
3756
3757 void
3758 _IconListPresenter::SwapReorderedItems(int toIndex, bool singleItemChanged)
3759 {
3760         if (toIndex < 0)
3761         {
3762                 return;
3763         }
3764         else if (toIndex >= __pListModel->GetAllItemCount())
3765         {
3766                 toIndex -= __itemCountPerAxis;
3767         }
3768
3769         _IconListItem* pItem = null;
3770         _IconListItem* pTempItem = null;
3771         _VisualElement* pToItemVE = null;
3772         _VisualElement* pToTempItemVE = null;
3773         FloatRectangle tempBounds;
3774
3775         if (singleItemChanged)
3776         {
3777                 pItem = static_cast<_IconListItem*>(__pListModel->LoadItem(DEFAULT_GROUP_INDEX, toIndex));
3778                 if (pItem != null)
3779                 {
3780                         pToItemVE = pItem->GetItemVisualElement();
3781                 }
3782                 if (pToItemVE != null)
3783                 {
3784                         FloatRectangle bounds = pToItemVE->GetBounds();
3785                         if (bounds.IsEmpty())
3786                         {
3787                                 bounds = GetItemBounds(toIndex);
3788
3789                                 pToItemVE->SetImplicitAnimationEnabled(false);
3790                                 pToItemVE->SetBounds(bounds);
3791                         }
3792
3793                         FloatRectangle temp = __reorderItemBounds;
3794                         __reorderItemBounds.SetPosition(bounds.x, bounds.y);
3795                         pToItemVE->SetImplicitAnimationEnabled(true);
3796                         pToItemVE->SetBounds(temp);
3797                         pToItemVE->SetImplicitAnimationEnabled(false);
3798                 }
3799         }
3800         else
3801         {
3802                 if (__reorderToIndex > toIndex)
3803                 {
3804                         for (int i = toIndex; i < __reorderToIndex; i++)
3805                         {
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)
3809                                 {
3810                                         pToItemVE = pItem->GetItemVisualElement();
3811                                         pToTempItemVE = pTempItem->GetItemVisualElement();
3812                                 }
3813
3814                                 if (pToItemVE != null && pToTempItemVE != null)
3815                                 {
3816                                         FloatRectangle temp = pToTempItemVE->GetBounds();
3817                                         if (temp.IsEmpty())
3818                                         {
3819                                                 temp = GetItemBounds(i + 1);
3820
3821                                                 pToTempItemVE->SetImplicitAnimationEnabled(false);
3822                                                 pToTempItemVE->SetBounds(temp);
3823                                         }
3824
3825                                         if (i == toIndex)
3826                                         {
3827                                                 tempBounds = pToItemVE->GetBounds();
3828                                                 if (tempBounds.IsEmpty())
3829                                                 {
3830                                                         tempBounds = GetItemBounds(toIndex);
3831
3832                                                         pToItemVE->SetImplicitAnimationEnabled(false);
3833                                                         pToItemVE->SetBounds(tempBounds);
3834                                                 }
3835                                         }
3836                                         else if (i == __reorderToIndex -1)
3837                                         {
3838                                                 temp = __reorderItemBounds;
3839                                                 __reorderItemBounds.SetPosition(tempBounds.x, tempBounds.y);
3840                                         }
3841                                         pToItemVE->SetImplicitAnimationEnabled(true);
3842                                         pToItemVE->SetBounds(temp);
3843                                         pToItemVE->SetImplicitAnimationEnabled(false);
3844                                 }
3845                         }
3846                 }
3847                 else
3848                 {
3849                         for (int i = toIndex; i > __reorderToIndex; i--)
3850                         {
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)
3854                                 {
3855                                         pToItemVE = pItem->GetItemVisualElement();
3856                                         pToTempItemVE = pTempItem->GetItemVisualElement();
3857                                 }
3858
3859                                 if (pToItemVE != null && pToTempItemVE != null)
3860                                 {
3861                                         FloatRectangle temp = pToTempItemVE->GetBounds();
3862                                         if (temp.IsEmpty())
3863                                         {
3864                                                 temp = GetItemBounds(i - 1);
3865
3866                                                 pToTempItemVE->SetImplicitAnimationEnabled(false);
3867                                                 pToTempItemVE->SetBounds(temp);
3868                                         }
3869
3870                                         if (i == toIndex)
3871                                         {
3872                                                 tempBounds = pToItemVE->GetBounds();
3873                                                 if (tempBounds.IsEmpty())
3874                                                 {
3875                                                         tempBounds = GetItemBounds(toIndex);
3876
3877                                                         pToItemVE->SetImplicitAnimationEnabled(false);
3878                                                         pToItemVE->SetBounds(tempBounds);
3879                                                 }
3880                                         }
3881                                         else if (i == __reorderToIndex + 1)
3882                                         {
3883                                                 temp = __reorderItemBounds;
3884                                                 __reorderItemBounds.SetPosition(tempBounds.x, tempBounds.y);
3885                                         }
3886
3887                                         pToItemVE->SetImplicitAnimationEnabled(true);
3888                                         pToItemVE->SetBounds(temp);
3889                                         pToItemVE->SetImplicitAnimationEnabled(false);
3890                                 }
3891                         }
3892                 }
3893         }
3894
3895         __pListModel->MoveItem(DEFAULT_GROUP_INDEX, __reorderToIndex, DEFAULT_GROUP_INDEX, toIndex);
3896         __reorderToIndex = toIndex;
3897 }
3898
3899 void
3900 _IconListPresenter::FinishReordering(void)
3901 {
3902         if (__pListModel->IsValidItem(DEFAULT_GROUP_INDEX, __reorderToIndex))
3903         {
3904                 if (__reorderFromIndex != __reorderToIndex)
3905                 {
3906                         FireIconListViewItemEvent(EVENT_TYPE_ITEM_REORDERED , __reorderFromIndex, __reorderToIndex);
3907                         for (int i = _Min(__reorderFromIndex, __reorderToIndex); i <= _Max(__reorderFromIndex, __reorderToIndex); i++)
3908                         {
3909                                 RedrawItem(i);
3910                         }
3911                 }
3912                 else
3913                 {
3914                         RedrawItem(__reorderToIndex);
3915                 }
3916         }
3917         ResetReorderScrollTimer();
3918         ClearReorderingInformation();
3919 }
3920
3921 void
3922 _IconListPresenter::ClearReorderingInformation(void)
3923 {
3924         __onReordering = false;
3925         __reorderFromIndex = INVALID_INDEX;
3926         __reorderToIndex = INVALID_INDEX;
3927         __reorderItemBounds.SetBounds(0.0f, 0.0f, 0.0f, 0.0f);
3928 }
3929
3930 // visual interaction animation
3931 void
3932 _IconListPresenter::StartScrollToAnimation(float targetPosition)
3933 {
3934         __pVE->RemoveAnimation(L"ScrollAnimation");
3935
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);
3941 }
3942
3943 void
3944 _IconListPresenter::StopScrollToAnimation(void)
3945 {
3946         __pVE->RemoveAnimation(L"ScrollAnimation");
3947 }
3948
3949 void
3950 _IconListPresenter::StopAllAnimations(void)
3951 {
3952         __pVE->RemoveAnimation(L"ScrollAnimation");
3953
3954         if (__isTouchAnimationEnabled && __isSelectAnimationRunning)
3955         {
3956                 if (__pSelectAnimationVE != null)
3957                 {
3958                         __pSelectAnimationVE->RemoveAnimation(L"SelectAnimation");
3959                 }
3960
3961                 if (__previousIndex > INVALID_INDEX && __pListModel->IsLoadedItem(DEFAULT_GROUP_INDEX, __previousIndex))
3962                 {
3963                         if (__pPreviousSelectAnimationVE != null)
3964                         {
3965                                 __pPreviousSelectAnimationVE->RemoveAnimation(L"SelectAnimation");
3966                         }
3967                 }
3968         }
3969
3970         if (__pIconListView->GetStyle() != ICON_LIST_VIEW_STYLE_NORMAL && __isCheckAnimationRunning)
3971         {
3972                 if (__pCheckAnimationVE != null)
3973                 {
3974                         __pCheckAnimationVE->RemoveAnimation(L"CheckAnimation");
3975                 }
3976
3977                 if (__previousCheckIndex> INVALID_INDEX && __pListModel->IsLoadedItem(DEFAULT_GROUP_INDEX, __previousCheckIndex))
3978                 {
3979                         if (__pPreviousCheckAnimationVE != null)
3980                         {
3981                                 __pPreviousCheckAnimationVE->RemoveAnimation(L"CheckAnimation");
3982                         }
3983                 }
3984         }
3985 }
3986
3987 void
3988 _IconListPresenter::AddAnimation(_IconListItem& item, int index, int delay)
3989 {
3990         _VisualElement* pVE = item.GetItemVisualElement();
3991         if (pVE != null)
3992         {
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);
3996
3997                 if (IsAnimationRunning(__addTransactionId))
3998                 {
3999                         AnimationTransaction::Stop(__addTransactionId);
4000                 }
4001
4002                 AnimationTransaction::Begin(__addTransactionId);
4003                 AnimationTransaction::SetVisualElementAnimationTimingFunction(VisualElementAnimation::GetTimingFunctionByName("EaseInOut"));
4004                 AnimationTransaction::SetVisualElementAnimationDuration(ITEM_ANIMATION_DURATION);
4005                 AnimationTransaction::SetVisualElementAnimationDelay(delay);
4006
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.");
4010
4011                 pOpacityAnimation->SetPropertyName(L"opacity");
4012                 pOpacityAnimation->SetStartValue(Variant(0.0f));
4013                 pOpacityAnimation->SetEndValue(Variant(1.0f));
4014
4015                 pVE->AddAnimation(L"AddItemOpacityAnimation", *pOpacityAnimation);
4016                 delete pOpacityAnimation;
4017
4018                 // scale animation
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.");
4021
4022                 pScaleAnimation->SetPropertyName(L"bounds");
4023                 pScaleAnimation->SetStartValue(Variant(startRect));
4024                 pScaleAnimation->SetEndValue(Variant(endRect));
4025
4026                 pVE->AddAnimation(L"AddItemScaleAnimation", *pScaleAnimation);
4027                 delete pScaleAnimation;
4028
4029                 pVE->SetImplicitAnimationEnabled(false);
4030
4031                 AnimationTransaction::Commit();
4032                 __previousAnimationItemIndex = index;
4033                 __pPreviousAnimationVE = pVE;
4034         }
4035 }
4036
4037 void
4038 _IconListPresenter::RemoveAnimation(_IconListItem& item, int index)
4039 {
4040         result r = E_SUCCESS;
4041         Canvas* pCanvas = null;
4042         _VisualElement* pItemVE = item.GetItemVisualElement();
4043         if (pItemVE != null)
4044         {
4045                 if (__pRemoveItemVE != null)
4046                 {
4047                         __pRemoveItemVE->Destroy();
4048                         __pRemoveItemVE = null;
4049                 }
4050
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);
4053
4054                 __pRemoveItemVE = new (std::nothrow) _VisualElement();
4055                 SysTryReturnVoidResult(NID_UI_CTRL, __pRemoveItemVE != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
4056
4057                 r = __pRemoveItemVE->Construct();
4058                 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
4059
4060                 __pRemoveItemVE->SetSurfaceOpaque(false);
4061                 __pRemoveItemVE->SetShowState(true);
4062                 __pRemoveItemVE->SetImplicitAnimationEnabled(false);
4063
4064                 r = __pRemoveItemVE->SetBounds(startRect);
4065                 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
4066
4067                 _VisualElement* pParent = __pIconListView->GetVisualElement();
4068                 pParent->AttachChild(*__pRemoveItemVE);
4069
4070                 pCanvas = __pRemoveItemVE->GetCanvasN();
4071                 SysTryCatch(NID_UI_CTRL, (pCanvas != null), , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
4072
4073                 pCanvas->Clear();
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));
4077                 delete pCanvas;
4078
4079                 if (IsAnimationRunning(__removeTransactionId))
4080                 {
4081                         AnimationTransaction::Stop(__removeTransactionId);
4082                 }
4083
4084                 AnimationTransaction::Begin(__removeTransactionId);
4085
4086                 // scale animation
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.");
4089
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);
4095
4096                 String scaleAnimationName(L"RemoveItemScaleAnimation");
4097                 __pRemoveItemVE->AddAnimation(scaleAnimationName, *pScaleAnimation);
4098                 delete pScaleAnimation;
4099
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.");
4103
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);
4109
4110                 String opacityAnimationName(L"RemoveItemOpacityAnimation");
4111                 __pRemoveItemVE->AddAnimation(opacityAnimationName, *pOpacityAnimation);
4112                 delete pOpacityAnimation;
4113
4114                 AnimationTransaction::Commit();
4115         }
4116
4117         return;
4118 CATCH:
4119         delete pCanvas;
4120 }
4121
4122 void
4123 _IconListPresenter::MoveAnimation(_IconListItem& item, FloatRectangle& bounds, int delay)
4124 {
4125         _VisualElement* pVE = item.GetItemVisualElement();
4126         if (pVE != null)
4127         {
4128                 pVE->SetImplicitAnimationEnabled(false);
4129                 pVE->SetShowState(true);
4130
4131                 // move animation
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.");
4134
4135                 FloatRectangle startRect = pVE->GetBounds();
4136
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);
4143
4144                 String moveAnimationName(L"MoveItemAnimation");
4145                 pVE->AddAnimation(moveAnimationName, *pMoveAnimation);
4146                 delete pMoveAnimation;
4147         }
4148 }
4149
4150 void
4151 _IconListPresenter::MoveAnimation(_IconListItem& item, FloatRectangle& startBounds, FloatRectangle& endBounds, int delay)
4152 {
4153         if (!item.IsDrawn())
4154         {
4155                 item.SetDrawingProperty(*__pItemDrawingProperty);
4156                 item.DrawItem(startBounds, LIST_ITEM_STATE_NORMAL);
4157         }
4158
4159         _VisualElement* pVE = item.GetItemVisualElement();
4160         if (pVE != null)
4161         {
4162                 pVE->SetImplicitAnimationEnabled(false);
4163                 pVE->SetShowState(true);
4164
4165                 // move animation
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.");
4168
4169                 FloatRectangle startRect = pVE->GetBounds();
4170
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);
4177
4178                 String moveAnimationName(L"MoveItemAnimation");
4179                 pVE->AddAnimation(moveAnimationName, *pMoveAnimation);
4180                 delete pMoveAnimation;
4181         }
4182 }
4183
4184 void
4185 _IconListPresenter::MoveAnimation(_IconListItem& item, FloatRectangle& bounds, int delay, bool fadeIn)
4186 {
4187         _VisualElement* pVE = item.GetItemVisualElement();
4188         if (pVE != null)
4189         {
4190                 pVE->SetImplicitAnimationEnabled(false);
4191
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.");
4195
4196                 pOpacityAnimation->SetTimingFunction(VisualElementAnimation::GetTimingFunctionByName("EaseInOut"));
4197                 pOpacityAnimation->SetPropertyName(L"opacity");
4198
4199                 if (fadeIn)
4200                 {
4201                         pOpacityAnimation->SetStartValue(Variant(0.0f));
4202                         pOpacityAnimation->SetEndValue(Variant(1.0f));
4203                 }
4204                 else
4205                 {
4206                         pOpacityAnimation->SetStartValue(Variant(1.0f));
4207                         pOpacityAnimation->SetEndValue(Variant(0.0f));
4208                 }
4209
4210                 pOpacityAnimation->SetDuration(MOVE_ITEM_ANIMATION_DURATION);
4211
4212                 String opacityAnimationName(L"MoveItemOpacityAnimation");
4213                 pVE->AddAnimation(opacityAnimationName, *pOpacityAnimation);
4214                 delete pOpacityAnimation;
4215
4216                 // move animation
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.");
4219
4220                 FloatRectangle startRect = pVE->GetBounds();
4221
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);
4228
4229                 String moveAnimationName(L"MoveItemAnimation");
4230                 pVE->AddAnimation(moveAnimationName, *pMoveAnimation);
4231                 delete pMoveAnimation;
4232         }
4233 }
4234
4235 void
4236 _IconListPresenter::RemoveAllAnimation(_IconListItem& item)
4237 {
4238         _VisualElement* pVE = item.GetItemVisualElement();
4239         if (pVE != null)
4240         {
4241                 pVE->RemoveAllAnimations();
4242         }
4243 }
4244
4245 void
4246 _IconListPresenter::MoveForward(int index)
4247 {
4248         int itemCount = __pListModel->GetItemCountInGroup(DEFAULT_GROUP_INDEX);
4249         if (index < 0 || index >= itemCount)
4250         {
4251                  return;
4252         }
4253
4254         int bottomLine = 0;
4255         if (__scrollDirection == ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL)
4256         {
4257                 float bottomPosition = __scrollPosition + __pIconListView->GetBounds().height;
4258                 bottomLine = (bottomPosition - __topMargin + __verticalSpacing) / __unitScrollLength;
4259         }
4260         else
4261         {
4262                 float bottomPosition = __scrollPosition + __pIconListView->GetBounds().width;
4263                 bottomLine = (bottomPosition - __leftMargin + __horizontalSpacing) / __unitScrollLength;
4264         }
4265
4266         int startIndex = index;
4267         int endIndex = (bottomLine + 1) * __itemCountPerAxis;
4268         endIndex = endIndex >= itemCount ? itemCount - 1 : endIndex;
4269         if (startIndex > endIndex)
4270         {
4271                 return;
4272         }
4273
4274         // move forward
4275         _IconListItem* pItem = null;
4276         _VisualElement* pItemVE = null;
4277
4278         if (IsAnimationRunning(__moveTransactionId))
4279         {
4280                 AnimationTransaction::Stop(__moveTransactionId);
4281         }
4282
4283         AnimationTransaction::Begin(__moveTransactionId);
4284
4285         FloatRectangle startBounds;
4286         FloatRectangle endBounds;
4287         for (int i = startIndex; i <= endIndex; i++)
4288         {
4289                 startBounds = GetItemBounds(i);
4290                 endBounds = GetItemBounds(i - 1);
4291                 if (!endBounds.IsEmpty() && !startBounds.IsEmpty())
4292                 {
4293                         pItem = static_cast<_IconListItem*>(__pListModel->LoadItem(DEFAULT_GROUP_INDEX, i));
4294                         if (pItem != null)
4295                         {
4296                                 pItemVE = pItem->GetItemVisualElement();
4297                                 if (pItemVE != null)
4298                                 {
4299                                         MoveAnimation(*pItem, startBounds, endBounds, ITEM_ANIMATION_DELAY);
4300                                 }
4301                         }
4302                 }
4303         }
4304         AnimationTransaction::Commit();
4305 }
4306
4307 void
4308 _IconListPresenter::MoveBackward(int index)
4309 {
4310         int itemCount = __pListModel->GetItemCountInGroup(DEFAULT_GROUP_INDEX);
4311         if (index < 0 || index >= itemCount)
4312         {
4313                  return;
4314         }
4315
4316         int bottomLine = 0;
4317         if (__scrollDirection == ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL)
4318         {
4319                 float bottomPosition = __scrollPosition + __pIconListView->GetBounds().height;
4320                 bottomLine = (bottomPosition - __topMargin + __verticalSpacing) / __unitScrollLength;
4321         }
4322         else
4323         {
4324                 float bottomPosition = __scrollPosition + __pIconListView->GetBounds().width;
4325                 bottomLine = (bottomPosition - __leftMargin + __horizontalSpacing) / __unitScrollLength;
4326         }
4327
4328         int endIndex = index;
4329         int startIndex = (bottomLine + 1) * __itemCountPerAxis;
4330         startIndex = startIndex >= itemCount ? itemCount - 1 : startIndex;
4331
4332         if (startIndex < endIndex)
4333         {
4334                 return;
4335         }
4336
4337         // move backward
4338         _IconListItem* pItem = null;
4339         _VisualElement* pItemVE = null;
4340
4341         if (IsAnimationRunning(__moveTransactionId))
4342         {
4343                 AnimationTransaction::Stop(__moveTransactionId);
4344         }
4345
4346         AnimationTransaction::Begin(__moveTransactionId);
4347
4348         FloatRectangle startBounds;
4349         FloatRectangle endBounds;
4350         for (int i = startIndex; i >= endIndex; i--)
4351         {
4352                 startBounds = GetItemBounds(i);
4353                 endBounds = GetItemBounds(i + 1);
4354                 if (!startBounds.IsEmpty() && !endBounds.IsEmpty())
4355                 {
4356                         pItem = static_cast<_IconListItem*>(__pListModel->LoadItem(DEFAULT_GROUP_INDEX, i));
4357                         if (pItem != null)
4358                         {
4359                                 pItemVE = pItem->GetItemVisualElement();
4360                                 if (pItemVE != null)
4361                                 {
4362                                         MoveAnimation(*pItem, startBounds, endBounds, 0);
4363                                 }
4364                         }
4365                 }
4366         }
4367         AnimationTransaction::Commit();
4368 }
4369
4370 bool
4371 _IconListPresenter::IsAnimationRunning(int transactionId)
4372 {
4373         if (AnimationTransaction::GetStatus(transactionId) == ANIMATION_TRANSACTION_STATUS_PLAYING)
4374         {
4375                 return true;
4376         }
4377
4378         return false;
4379 }
4380
4381 void
4382 _IconListPresenter::StartSelectAnimation(int index)
4383 {
4384         if (index <= INVALID_INDEX)
4385                 return;
4386
4387         if (__previousIndex > INVALID_INDEX && __pPreviousSelectAnimationVE != null)
4388         {
4389                 if (__pListModel->IsLoadedItem(DEFAULT_GROUP_INDEX, __previousIndex) && __isSelectAnimationRunning)
4390                 {
4391                         __pPreviousSelectAnimationVE->RemoveAnimation(L"SelectAnimation");
4392                 }
4393         }
4394
4395         _IconListItem* pItem = static_cast<_IconListItem*>(__pListModel->LoadItem(DEFAULT_GROUP_INDEX, index));
4396         __pSelectAnimationVE = pItem->GetSelectAniVisualElement();
4397         if (__pSelectAnimationVE == null)
4398         {
4399                 return;
4400         }
4401         __pSelectAnimationVE->RemoveAllAnimations();
4402
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);
4406
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.");
4409
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;
4419
4420         __isSelectAnimationRunning = true;
4421         __pPreviousSelectAnimationVE = __pSelectAnimationVE;
4422         __previousIndex = index;
4423 }
4424
4425 void
4426 _IconListPresenter::StartCheckAnimation(int index)
4427 {
4428         if (index <= INVALID_INDEX)
4429                 return;
4430
4431         _IconListItem* pItem = static_cast<_IconListItem*>(__pListModel->LoadItem(DEFAULT_GROUP_INDEX, index));
4432
4433         if (__previousCheckIndex >= 0 && __pPreviousCheckAnimationVE !=null && __isCheckAnimationRunning)
4434         {
4435                 if (__pListModel->IsLoadedItem(DEFAULT_GROUP_INDEX, __previousCheckIndex))
4436                 {
4437                         __pPreviousCheckAnimationVE->RemoveAnimation(L"CheckAnimation");
4438                 }
4439         }
4440
4441         const Bitmap* pBackgroundBitmap = __pListModel->IsItemEnabled(DEFAULT_GROUP_INDEX, index) ? (IsItemChecked(index) ? __pItemDrawingProperty->GetCheckedBackgroundBitmap() : __pItemDrawingProperty->GetUnCheckedBackgroundBitmap()) : __pItemDrawingProperty->GetDisabledCheckBitmap();
4442
4443         Canvas* pCheckBgCanvas = pItem->GetCheckBGVisualElement()->GetCanvasN();
4444
4445         if (pCheckBgCanvas == null)
4446         {
4447                 return;
4448         }
4449
4450         pCheckBgCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
4451         pCheckBgCanvas->Clear();
4452
4453         // draw background of check box
4454         if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pBackgroundBitmap))
4455         {
4456                 pCheckBgCanvas->DrawNinePatchedBitmap(FloatRectangle(0.0f, 0.0f, pBackgroundBitmap->GetWidthF(), pBackgroundBitmap->GetHeightF()), *pBackgroundBitmap);
4457         }
4458         else
4459         {
4460                 pCheckBgCanvas->DrawBitmap(FloatRectangle(0.0f, 0.0f, pBackgroundBitmap->GetWidthF(), pBackgroundBitmap->GetHeightF()), *pBackgroundBitmap);
4461         }
4462
4463         delete pCheckBgCanvas;
4464
4465         __pCheckAnimationVE = pItem->GetCheckAniVisualElement();
4466         if (__pCheckAnimationVE == null)
4467         {
4468                 return;
4469         }
4470         __pCheckAnimationVE->RemoveAllAnimations();
4471
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);
4478
4479         __pCheckAnimationVE->AddAnimation(L"CheckAnimation", *pCheckAnimation);
4480         __isCheckAnimationRunning = true;
4481         __pPreviousCheckAnimationVE = __pCheckAnimationVE;
4482         __previousCheckIndex = index;
4483
4484 }
4485
4486 result
4487 _IconListPresenter::DrawCheckAnimation(int index)
4488 {
4489         result r = GetLastResult();
4490         __selectedIndex = INVALID_INDEX;
4491
4492         switch (__pIconListView->GetStyle())
4493         {
4494                 case ICON_LIST_VIEW_STYLE_NORMAL:
4495                 {
4496                         RedrawItem(index);
4497                         break;
4498                 }
4499                 case ICON_LIST_VIEW_STYLE_RADIO:
4500                 {
4501                         if (index != __checkedRadioIndex)
4502                         {
4503                                 if (__checkedRadioIndex >= 0 && __pListModel->IsLoadedItem(DEFAULT_GROUP_INDEX, __checkedRadioIndex))
4504                                 {
4505                                         r = RedrawItem(__checkedRadioIndex);
4506                                 }
4507                                 __checkedIndex = index;
4508                                 StartCheckAnimation(index);
4509                         }
4510                         else
4511                         {
4512                                 RedrawItem(index);
4513                         }
4514                         break;
4515                 }
4516                 case ICON_LIST_VIEW_STYLE_MARK:
4517                 {
4518                         InitializeAccessibilityElement();
4519
4520                         if (__isItemChecked)
4521                         {
4522                                 r = RedrawItem(index);
4523                         }
4524                         else
4525                         {
4526                                 __checkedIndex = index;
4527                                 StartCheckAnimation(index);
4528                         }
4529                         break;
4530                 }
4531         }
4532
4533         __isItemChecked = false;
4534
4535         return r;
4536 }
4537
4538 void
4539 _IconListPresenter::PreDrawCheckAnimation(int index)
4540 {
4541         switch (__pIconListView->GetStyle())
4542         {
4543                 case ICON_LIST_VIEW_STYLE_NORMAL:
4544                 {
4545                         break;
4546                 }
4547
4548                 case ICON_LIST_VIEW_STYLE_RADIO:
4549                 {
4550                         __checkedRadioIndex = __pListModel->GetIndexOfRadioCheckedItem(0);
4551                         __pListModel->SetItemChecked(DEFAULT_GROUP_INDEX, index, true);
4552                         break;
4553                 }
4554                 case ICON_LIST_VIEW_STYLE_MARK:
4555                 {
4556                         __isItemChecked = __pListModel->IsItemChecked(DEFAULT_GROUP_INDEX, index);
4557                         __pListModel->SetItemChecked(DEFAULT_GROUP_INDEX, index, !__isItemChecked);
4558                         break;
4559                 }
4560         }
4561 }
4562 }}} // Tizen::Ui::Controls