Merge "fixed bug (TapGesture improvement)" into tizen_2.1
[platform/framework/native/uifw.git] / src / ui / controls / FUiCtrl_TableViewPresenter.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_TableViewPresenter.cpp
20  * @brief       This is the header file for the _TableViewPresenter class.
21  *
22  * This file contains the declarations of the _TableViewPresenter class.
23  */
24
25 #include <FGrpRectangle.h>
26 #include <FSysSystemTime.h>
27 #include "FUi_ResourceManager.h"
28 #include "FUi_UiTouchEvent.h"
29 #include "FUi_ResourceManager.h"
30 #include "FUiAnim_VisualElement.h"
31 #include "FUiCtrl_FastScroll.h"
32 #include "FUiCtrl_Scroll.h"
33 #include "FUiCtrl_TableView.h"
34 #include "FUiCtrl_TableViewItem.h"
35 #include "FUiCtrl_TableViewPresenter.h"
36 #include "FUiCtrl_TableViewItemProviderAdaptor.h"
37 #include "FUi_CoordinateSystemUtils.h"
38 #include "FUi_Math.h"
39
40 using namespace Tizen::Ui::Animations;
41 using namespace Tizen::Graphics;
42 using namespace Tizen::Base;
43 using namespace Tizen::Base::Runtime;
44
45 namespace Tizen { namespace Ui { namespace Controls
46 {
47 _TableViewPresenter::_TableViewPresenter()
48         : __pTableView(null)
49         , __pListModel(null)
50         , __pProviderAdaptor(null)
51         , __topMargin(0.0f)
52         , __bottomMargin(0.0f)
53         , __leftMargin(0.0f)
54         , __modelInitialized(false)
55         , __firstDrawnFlag(true)
56         , __statusChangedFlag(true)
57         , __scrolling(true)
58         , __pItemDrawingProperty(null)
59         , __pBaseVisualElement(null)
60         , __sweepOccured(false)
61         , __sweptItemPosition()
62         , __reservedScrollItemAlignment(TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_TOP)
63         , __firstTouchMoved(false)
64         , __pReorderScrollTimer(null)
65         , __reorderInfo()
66         , __itemTotalHeight(0.0f)
67         , __pCapturedItemVisualElement(null)
68         , __pFastScrollTimer(null)
69         , __isFastScrollTimerEnabled(false)
70         , __scrollHeightOnFlickStarted(0)
71         , __scrollPositionOnFlickStarted(0)
72         , __isAnimationCallbackBlocked(false)
73         , __lockLoadItemWithScroll(false)
74         , __itemTouchReleasedEventState(TABLE_VIEW_ITEM_TOUCH_RELEASED_EVENT_NORMAL)
75         , __scrollToItemTag()
76 {
77         __sweptItemTag.itemIndex = -1;
78         __sweptItemTag.groupIndex = -1;
79
80         __reservedScrollItemIndex.itemIndex = -1;
81         __reservedScrollItemIndex.groupIndex = -1;
82
83         __expandableItemTag.groupIndex = -1;
84         __expandableItemTag.itemIndex = -1;
85 }
86
87 _TableViewPresenter::~_TableViewPresenter()
88 {
89         Dispose();
90 }
91
92 _TableView*
93 _TableViewPresenter::GetView() const
94 {
95         return __pTableView;
96 }
97
98 _ListViewModel*
99 _TableViewPresenter::GetModel(void) const
100 {
101         return __pListModel;
102 }
103
104 bool
105 _TableViewPresenter::Initialize(_TableView* pTableView)
106 {
107         _ScrollPanelPresenter::Initialize(*pTableView);
108
109         __pTableView = pTableView;
110         __pBaseVisualElement = __pTableView->GetVisualElement();
111         __pBaseVisualElement->SetClipChildrenEnabled(true);
112         __pBaseVisualElement->SetSurfaceOpaque(false);
113
114         result r = __itemHeightList.Construct();
115         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, false, E_OUT_OF_MEMORY, ("[E_OUT_OF_MEMORY] The memory is insufficient."));
116
117         r = __sectionAlignmentList.Construct();
118         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, false, E_OUT_OF_MEMORY, ("[E_OUT_OF_MEMORY] The memory is insufficient."));
119
120         // Create Model
121         __pListModel = new (std::nothrow) _ListViewModel();
122         SysTryReturn(NID_UI_CTRL, __pListModel != null, false, E_OUT_OF_MEMORY, ("[E_OUT_OF_MEMORY] The memory is insufficient."));
123         __pListModel->SetListViewModelDelegate(this);
124
125         __pItemDrawingProperty = new (std::nothrow) _ItemDrawingProperty();
126         SysTryReturn(NID_UI_CTRL, __pItemDrawingProperty != null, false, E_OUT_OF_MEMORY, ("[E_OUT_OF_MEMORY] The memory is insufficient."));
127
128         // Timer
129         __pFastScrollTimer = new (std::nothrow) Timer();
130         SysTryCatch(NID_UI_CTRL, __pFastScrollTimer != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
131
132          r = __pFastScrollTimer->Construct(*this);
133         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
134
135         return true;
136
137 CATCH:
138         if (__isFastScrollTimerEnabled)
139         {
140                 __pFastScrollTimer->Cancel();
141         }
142
143         delete __pFastScrollTimer;
144         __pFastScrollTimer = null;
145
146         return false;
147 }
148
149 result
150 _TableViewPresenter::Construct(_TableView* pTableView)
151 {
152         result r = E_SUCCESS;
153
154         // Create Model
155         if (!Initialize(pTableView))
156         {
157                 goto CATCH;
158         }
159
160         return r;
161
162 CATCH:
163         Dispose();
164         return r;
165 }
166
167 void
168 _TableViewPresenter::Dispose(void)
169 {
170         DeleteItemHeightList();
171         DeleteSectionAlignmentList();
172         DetachContextItem(__sweptItemTag);
173
174         delete __pListModel;
175         __pListModel = null;
176
177         delete __pProviderAdaptor;
178         __pProviderAdaptor = null;
179
180         delete __pItemDrawingProperty;
181         __pItemDrawingProperty = null;
182
183         delete __pReorderScrollTimer;
184         __pReorderScrollTimer = null;
185
186         if (__isFastScrollTimerEnabled)
187         {
188                 __pFastScrollTimer->Cancel();
189         }
190
191         delete __pFastScrollTimer;
192         __pFastScrollTimer = null;
193
194         if (__pCapturedItemVisualElement)
195         {
196                 GetView()->GetVisualElement()->DetachChild(*__pCapturedItemVisualElement);
197                 __pCapturedItemVisualElement->Destroy();
198         }
199         __pCapturedItemVisualElement = null;
200 }
201
202 result
203 _TableViewPresenter::SetItemProvider(const _TableViewItemProvider* pProvider)
204 {
205         result r = E_SUCCESS;
206
207         _TableViewItemProviderAdaptor* pProviderAdaptor = null;
208         pProviderAdaptor = static_cast <_TableViewItemProviderAdaptor*>(__pListModel->GetItemProviderAdaptor());
209
210         if (pProviderAdaptor == null)
211         {
212                 pProviderAdaptor = new (std::nothrow) _TableViewItemProviderAdaptor();
213                 SysTryReturn(NID_UI_CTRL, pProviderAdaptor != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, ("[E_OUT_OF_MEMORY] The memory is insufficient."));
214
215                 SetTableViewItemProviderAdaptor(pProviderAdaptor);
216         }
217
218         _TableViewItemProvider* pNewProvider = null;
219
220         if (pProvider != null)
221         {
222                 pNewProvider = const_cast <_TableViewItemProvider*>(pProvider);
223         }
224         else
225         {
226                 __pListModel->RemoveAllItem(false);
227         }
228
229         pProviderAdaptor->SetItemProvider(pNewProvider);
230         pProviderAdaptor->SetListWidth(__pTableView->GetBoundsF().width - (GetLeftMargin() * 2));
231         pProviderAdaptor->SetTableViewStyle(__pTableView->GetTableViewStyle());
232
233         return r;
234 }
235
236 result
237 _TableViewPresenter::GetItemFromPosition(const Tizen::Graphics::FloatPoint& position, TableViewItemTag& itemPos) const
238 {
239         _TableViewItem* pItem = null;
240         TableViewItemTag lastItemPos = {-1, -1};
241
242         __pListModel->GetFirstLoadedItemIndex(itemPos.groupIndex, itemPos.itemIndex);
243         __pListModel->GetLastLoadedItemIndex(lastItemPos.groupIndex, lastItemPos.itemIndex);
244
245         do
246         {
247                 pItem = static_cast <_TableViewItem*>(__pListModel->LoadItem(itemPos.groupIndex, itemPos.itemIndex));
248                 SysTryCatch(NID_UI_CTRL, pItem != null, , E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The index is out of range.");
249
250                 FloatRectangle itemBounds = pItem->GetBoundsF();
251                 if (itemBounds.Contains(position))
252                 {
253                         return E_SUCCESS;
254                 }
255
256                 if ((itemPos.itemIndex == lastItemPos.itemIndex) && (itemPos.groupIndex == lastItemPos.groupIndex))
257                 {
258                         break;
259                 }
260
261         } while (GetNextItemPosition(itemPos, itemPos));
262
263 CATCH:
264         itemPos.itemIndex = -1;
265         itemPos.groupIndex = -1;
266
267         return E_OUT_OF_RANGE;
268 }
269
270 result
271 _TableViewPresenter::GetTopDrawnItemIndex(int& groupIndex, int& itemIndex) const
272 {
273         result r = E_SUCCESS;
274
275         TableViewItemTag itemPos;
276         r = GetTopDrawnItem(itemPos);
277
278         groupIndex = itemPos.groupIndex;
279         itemIndex = itemPos.itemIndex;
280
281         return r;
282 }
283
284 result
285 _TableViewPresenter::SetTopDrawnItemIndex(int groupIndex, int itemIndex)
286 {
287         if (IsEmpty())
288         {
289                 return E_INVALID_ARG;
290         }
291
292         if ((groupIndex < 0) || (groupIndex >= GetGroupCount()) || (itemIndex < -1) || (itemIndex >= GetItemCountAt(groupIndex)))
293         {
294                 return E_OUT_OF_RANGE;
295         }
296
297         ScrollToItem(groupIndex, itemIndex, TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_TOP);
298
299         return E_SUCCESS;
300 }
301
302 result
303 _TableViewPresenter::GetBottomDrawnItemIndex(int& groupIndex, int& itemIndex) const
304 {
305         result r = E_SUCCESS;
306
307         TableViewItemTag itemPos;
308         r = GetBottomDrawnItem(itemPos);
309
310         groupIndex = itemPos.groupIndex;
311         itemIndex = itemPos.itemIndex;
312
313         return r;
314 }
315
316 result
317 _TableViewPresenter::SetBottomDrawnItemIndex(int groupIndex, int itemIndex)
318 {
319         if (IsEmpty())
320         {
321                 return E_INVALID_ARG;
322         }
323
324         if ((groupIndex < 0) || (groupIndex >= GetGroupCount()) || (itemIndex < -1) || (itemIndex >= GetItemCountAt(groupIndex)))
325         {
326                 return E_OUT_OF_RANGE;
327         }
328
329         ScrollToItem(groupIndex, itemIndex, TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_BOTTOM);
330
331         return E_SUCCESS;
332 }
333
334 int
335 _TableViewPresenter::GetGroupCount(void) const
336 {
337         return __pListModel->GetAllGroupCount();
338 }
339
340
341 int
342 _TableViewPresenter::GetItemCountAt(int groupIndex) const
343 {
344         return __pListModel->GetItemCountInGroup(groupIndex);
345 }
346
347 bool
348 _TableViewPresenter::HasSectionHeader(int groupIndex) const
349 {
350         if (__pProviderAdaptor == null || __pTableView->GetTableViewStyle() != TABLE_VIEW_STYLE_SECTION)
351         {
352                 return false;
353         }
354
355         return __pProviderAdaptor->HasSectionHeader(groupIndex);
356 }
357
358 bool
359 _TableViewPresenter::HasSectionFooter(int groupIndex) const
360 {
361         if (__pProviderAdaptor == null || __pTableView->GetTableViewStyle() != TABLE_VIEW_STYLE_SECTION)
362         {
363                 return false;
364         }
365
366         return __pProviderAdaptor->HasSectionFooter(groupIndex);
367 }
368
369 int
370 _TableViewPresenter::GetItemCount(void) const
371 {
372         return __pListModel->GetAllItemCount();
373 }
374
375 result
376 _TableViewPresenter::RefreshTableView(int groupIndex, int itemIndex, TableViewRefreshType type, bool animation)
377 {
378         _TableViewItemProviderAdaptor* pProviderAdaptor = __pProviderAdaptor;
379
380         SysTryReturn(NID_UI_CTRL, pProviderAdaptor != null, E_INVALID_STATE, E_INVALID_STATE,
381                                 ("[E_INVALID_STATE] This instance isn't constructed."));
382
383         if ((groupIndex < 0) || (groupIndex > GetGroupCount()) || (itemIndex < -1) || (itemIndex > GetItemCountAt(groupIndex)))
384         {
385                 SysLogException(NID_UI_CTRL, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The index is out of range.");
386                 return E_OUT_OF_RANGE;
387         }
388
389         if (groupIndex == GetGroupCount() && itemIndex != -1 && type != TABLE_VIEW_REFRESH_TYPE_ITEM_ADD)
390         {
391                 SysLogException(NID_UI_CTRL, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The index is out of range.");
392                 return E_OUT_OF_RANGE;
393         }
394
395         TableViewItemTag topDrawnItemPos = {-1, -1};
396         TableViewItemTag refreshItemPos = {groupIndex, itemIndex};
397         float prevScrollAreaHeight = GetScrollAreaBounds().height;
398
399         GetTopDrawnItem(topDrawnItemPos);
400
401         ResetSweepItem();
402
403         switch (type)
404         {
405         case TABLE_VIEW_REFRESH_TYPE_ITEM_ADD:
406                 if (itemIndex == -1)
407                 {
408                         bool emptyState = IsEmpty();
409
410                         int itemCount = pProviderAdaptor->GetItemCount(groupIndex);
411                         if (__pListModel->InsertGroup(groupIndex, itemCount, false) != E_SUCCESS)
412                         {
413                                 SysLogException(NID_UI_CTRL, E_SYSTEM, "[E_SYSTEM] Unable to add Group item.");
414                                 return E_SYSTEM;
415                         }
416
417                         if (emptyState)
418                         {
419                                 GetFirstItem(topDrawnItemPos);
420                         }
421                         else if (groupIndex <= topDrawnItemPos.groupIndex)
422                         {
423                                 topDrawnItemPos.groupIndex++;
424                         }
425                 }
426                 else
427                 {
428                         bool emptyState = IsEmpty();
429
430                         if (__pListModel->InsertItemToGroup(null, groupIndex, itemIndex) != E_SUCCESS)
431                         {
432                                 SysLogException(NID_UI_CTRL, E_SYSTEM, "[E_SYSTEM] Unable to add item.");
433                                 return E_SYSTEM;
434                         }
435
436                         if (emptyState)
437                         {
438                                 GetFirstItem(topDrawnItemPos);
439                         }
440                 }
441
442                 RefreshItemHeightList(groupIndex, itemIndex, TABLE_VIEW_REFRESH_TYPE_ITEM_ADD);
443                 RefreshSectionAlignmentList(groupIndex, TABLE_VIEW_REFRESH_TYPE_ITEM_ADD);
444
445                 if (__pListModel->GetAllItemCount() == 1)
446                 {
447                         SetStatusChanged(true);
448                 }
449
450                 break;
451
452         case TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE:
453                 if (itemIndex == -1)
454                 {
455                         if (groupIndex == GetGroupCount())
456                         {
457                                 SysLogException(NID_UI_CTRL, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The index is out of range.");
458                                 return E_OUT_OF_RANGE;
459                         }
460
461                         RefreshItemHeightList(groupIndex, itemIndex, TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE);
462                         RefreshSectionAlignmentList(groupIndex, TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE);
463
464                         if (__pListModel->RemoveGroup(groupIndex) != E_SUCCESS)
465                         {
466                                 SysLogException(NID_UI_CTRL, E_SYSTEM, "[E_SYSTEM] Unable to remove group.");
467                                 return E_SYSTEM;
468                         }
469
470                         if (groupIndex < topDrawnItemPos.groupIndex)
471                         {
472                                 topDrawnItemPos.groupIndex--;
473                         }
474
475                         if ((groupIndex == topDrawnItemPos.groupIndex) && (GetItemCountAt(groupIndex) < topDrawnItemPos.itemIndex))
476                         {
477                                 topDrawnItemPos.itemIndex = -1;
478                         }
479                 }
480                 else
481                 {
482                         if (itemIndex == GetItemCountAt(groupIndex))
483                         {
484                                 SysLogException(NID_UI_CTRL, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The index is out of range.");
485                                 return E_OUT_OF_RANGE;
486                         }
487
488                         if (__pListModel->RemoveItemAt(groupIndex, itemIndex) != E_SUCCESS)
489                         {
490                                 SysLogException(NID_UI_CTRL, E_SYSTEM, "[E_SYSTEM] Unable to remove item.");
491                                 return E_SYSTEM;
492                         }
493
494                         if ((groupIndex == topDrawnItemPos.groupIndex) && (itemIndex < topDrawnItemPos.itemIndex))
495                         {
496                                 GetPreviousItemPosition(topDrawnItemPos, topDrawnItemPos);
497                         }
498
499                         RefreshItemHeightList(groupIndex, itemIndex, TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE);
500                 }
501
502                 if (GetModel()->IsValidItem(topDrawnItemPos.groupIndex, topDrawnItemPos.itemIndex) == false)
503                 {
504                         GetPreviousItemPosition(topDrawnItemPos, topDrawnItemPos);
505                 }
506
507                 if (__pListModel->GetAllItemCount() == 0)
508                 {
509                         SetStatusChanged(true);
510                 }
511
512                 break;
513
514         case TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY:
515                 {
516                         TableViewItemTag itemTag = {groupIndex, itemIndex};
517                         _TableViewItem* pTableViewItem = FindItem(itemTag);
518
519                         if (pTableViewItem == null)
520                         {
521                                 return E_SUCCESS;
522                         }
523
524                         if (pProviderAdaptor->UpdateItem(pTableViewItem, itemTag.groupIndex, itemTag.itemIndex))
525                         {
526                                 CheckItemHeightAndRefreshLayout(itemTag, true);
527
528                                 if (__sweptItemTag.groupIndex != itemTag.groupIndex || __sweptItemTag.itemIndex != itemTag.itemIndex)
529                                 {
530                                         ResetSweptItem();
531                                 }
532
533                                 pTableViewItem->SetItemChanged(true);
534                                 pTableViewItem->Invalidate();
535                                 pTableViewItem->AdjustContextItemBounds();
536
537                                 return E_SUCCESS;
538                         }
539                 }
540                 break;
541
542         default:
543                 SysLogException(NID_UI_CTRL, E_SYSTEM, "[E_SYSTEM] Unable to refresh list.");
544                 return E_SYSTEM;
545                 break;
546         }
547
548         AdjustClientAreaBounds(true);
549
550         if ((topDrawnItemPos.groupIndex > refreshItemPos.groupIndex)
551                 ||((topDrawnItemPos.groupIndex == refreshItemPos.groupIndex)&&(topDrawnItemPos.itemIndex > refreshItemPos.itemIndex)))
552         {
553                 RefreshItemLayout(topDrawnItemPos, refreshItemPos, type, false);
554
555                 float newScrollPosition = GetScrollPosition() - (prevScrollAreaHeight - GetScrollAreaBounds().height);
556                 SetScrollPosition(newScrollPosition, false);
557         }
558         else
559         {
560                 RefreshItemLayout(topDrawnItemPos, refreshItemPos, type, animation);
561         }
562
563         return E_SUCCESS;
564 }
565
566 result
567 _TableViewPresenter::RefreshAllItems(void)
568 {
569         result r = E_SUCCESS;
570         TableViewItemTag itemTag = {-1, -1};
571         TableViewItemTag lastLoadedItemTag = {-1, -1};
572
573         __pListModel->GetLastLoadedItemIndex(lastLoadedItemTag.groupIndex, lastLoadedItemTag.itemIndex);
574         __pListModel->GetFirstLoadedItemIndex(itemTag.groupIndex, itemTag.itemIndex);
575
576         do
577         {
578                 _TableViewItem* pItem = FindItem(itemTag);
579
580                 if (pItem == null)
581                 {
582                         continue;
583                 }
584
585                 r = RefreshTableView(itemTag.groupIndex, itemTag.itemIndex, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY, false);
586                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
587
588                 if ((itemTag.itemIndex == lastLoadedItemTag.itemIndex) && (itemTag.groupIndex == lastLoadedItemTag.groupIndex))
589                 {
590                         break;
591                 }
592         } while (GetNextItemPosition(itemTag, itemTag));
593
594         return r;
595 }
596
597 result
598 _TableViewPresenter::UpdateTableView(void)
599 {
600         _VisualElement* pVisualElement = __pTableView->GetVisualElement();
601
602         if (pVisualElement != null)
603         {
604                 __pTableView->GetVisualElement()->RemoveAllAnimations();
605         }
606
607
608         if (__modelInitialized == false)
609         {
610                 SetItemDrawingProperty();
611
612                 if(PreloadItem() == false)
613                 {
614                         return E_SUCCESS;
615                 }
616         }
617         else
618         {
619                 TableViewItemTag topDrawnTag = {-1, -1};
620                 float shiftingDistance = 0;
621
622                 ResetSweepItem();
623
624                 GetTopDrawnItem(topDrawnTag);
625
626                 if (__pListModel->IsValidItem(topDrawnTag.groupIndex, topDrawnTag.itemIndex))
627                 {
628                         _TableViewItem* pItem = FindItem(topDrawnTag);
629
630                         if (pItem != null)
631                         {
632                                 shiftingDistance = GetScrollPosition() - pItem->GetBoundsF().y;
633                         }
634                 }
635
636                 __pListModel->RemoveAllItem(false, true);
637
638                 PreloadItem(topDrawnTag.groupIndex, topDrawnTag.itemIndex, shiftingDistance);
639
640                 __statusChangedFlag = true;
641
642                 if (__itemTouchReleasedEventState == TABLE_VIEW_ITEM_TOUCH_RELEASED_EVENT_FIRE)
643                 {
644                         __itemTouchReleasedEventState = TABLE_VIEW_ITEM_TOUCH_RELEASED_EVENT_UPDATE_TABLE_VIEW;
645                 }
646         }
647
648         return E_SUCCESS;
649 }
650
651 void
652 _TableViewPresenter::AdjustLayoutItems(float scrollPosition)
653 {
654         TableViewItemTag lastLoadedItemPos = {-1, -1};
655         TableViewItemTag firstLoadedItemPos = {-1, -1};
656         TableViewItemTag currentItemPos = {-1, -1};
657         _TableViewItem* pItem = null;
658
659         __pListModel->GetFirstLoadedItemIndex(firstLoadedItemPos.groupIndex, firstLoadedItemPos.itemIndex);
660         __pListModel->GetLastLoadedItemIndex(lastLoadedItemPos.groupIndex, lastLoadedItemPos.itemIndex);
661
662         pItem = FindItem(firstLoadedItemPos);
663
664         if (pItem != null)
665         {
666                 float positionY = pItem->GetPositionF().y;
667
668                 currentItemPos = firstLoadedItemPos;
669
670                 while (!_FloatCompareLE(positionY, scrollPosition) && GetPreviousItemPosition(currentItemPos, currentItemPos))
671                 {
672                         pItem = LoadItem(currentItemPos.groupIndex, currentItemPos.itemIndex);
673
674                         if (pItem == null)
675                         {
676                                 break;
677                         }
678
679                         positionY = pItem->GetPositionF().y;
680                 }
681         }
682
683         pItem = FindItem(lastLoadedItemPos);
684
685         if (pItem != null)
686         {
687                 float positionY = pItem->GetPositionF().y;
688                 float itemHeight = pItem->GetBoundsF().height;
689                 float limitScreenArea = scrollPosition + __pTableView->GetBoundsF().height;
690                 currentItemPos = lastLoadedItemPos;
691
692                 while ((positionY + itemHeight < limitScreenArea) && GetNextItemPosition(currentItemPos, currentItemPos))
693                 {
694                         pItem = LoadItem(currentItemPos.groupIndex, currentItemPos.itemIndex);
695
696                         if (pItem == null)
697                         {
698                                 break;
699                         }
700
701                         positionY = pItem->GetPositionF().y;
702                         itemHeight = pItem->GetBoundsF().height;
703                 }
704         }
705 }
706
707 void
708 _TableViewPresenter::ResetItemLayout(TableViewItemTag& topDrawnItemTag, float shiftingDistance)
709 {
710         if (__pListModel->IsValidItem(topDrawnItemTag.groupIndex, topDrawnItemTag.itemIndex) == false)
711         {
712                 return;
713         }
714
715         DetachAllItem(true);
716
717         _TableViewItem* pItem = LoadItem(topDrawnItemTag.groupIndex, topDrawnItemTag.itemIndex);
718
719         if (pItem == null)
720         {
721                 return;
722         }
723
724         TableViewItemTag currentItem = topDrawnItemTag;
725         TableViewItemTag itemPos = topDrawnItemTag;
726         float screenAreaHeight = __pTableView->GetBoundsF().height + shiftingDistance;
727         float loadedItemTotalHeight = 0.0f;
728         FloatRectangle itemBounds = pItem->GetBoundsF();
729
730         itemBounds.y = CalculateItemPositionY(itemPos.groupIndex, itemPos.itemIndex);
731         pItem->SetBounds(itemBounds);
732         CheckItemHeightAndRefreshLayout(itemPos, true);
733
734         loadedItemTotalHeight += itemBounds.height;
735
736         while (loadedItemTotalHeight < screenAreaHeight && GetNextItemPosition(currentItem, itemPos))
737         {
738                 pItem = LoadItem(itemPos.groupIndex, itemPos.itemIndex);
739
740                 if (pItem == null)
741                 {
742                         break;
743                 }
744
745                 currentItem = itemPos;
746                 loadedItemTotalHeight += pItem->GetBoundsF().height;
747         }
748
749         if (loadedItemTotalHeight < screenAreaHeight)
750         {
751                 __pListModel->GetFirstLoadedItemIndex(itemPos.groupIndex, itemPos.itemIndex);
752                 currentItem = itemPos;
753
754                 while (loadedItemTotalHeight < screenAreaHeight && GetPreviousItemPosition(currentItem, itemPos))
755                 {
756                         pItem = LoadItem(itemPos.groupIndex, itemPos.itemIndex);
757
758                         if (pItem == null)
759                         {
760                                 break;
761                         }
762
763                         currentItem = itemPos;
764                         loadedItemTotalHeight += pItem->GetBoundsF().height;
765                 }
766         }
767 }
768
769 bool
770 _TableViewPresenter::IsCachingItemsTotalHeightLessThanViewHeight(void)
771 {
772         int currentCachingsize = GetMaxItemCachingSize();
773         int loadedItemCount = 0;
774         float itemTotalHeight = 0.0f;
775         float viewHeight = __pTableView->GetBoundsF().height;
776
777         TableViewItemTag lastLoadedItemPos = {-1, -1};
778         TableViewItemTag firstLoadedItemPos = {-1, -1};
779
780         __pListModel->GetFirstLoadedItemIndex(firstLoadedItemPos.groupIndex, firstLoadedItemPos.itemIndex);
781         __pListModel->GetLastLoadedItemIndex(lastLoadedItemPos.groupIndex, lastLoadedItemPos.itemIndex);
782
783         do
784         {
785                 _TableViewItem* pItem = FindItem(firstLoadedItemPos);
786
787                 if (pItem != null)
788                 {
789                         itemTotalHeight = itemTotalHeight + pItem->GetSizeF().height;
790                         loadedItemCount++;
791                 }
792
793                 if ((firstLoadedItemPos.itemIndex == lastLoadedItemPos.itemIndex) && (firstLoadedItemPos.groupIndex == lastLoadedItemPos.groupIndex))
794                 {
795                         break;
796                 }
797         } while (GetNextItemPosition(firstLoadedItemPos, firstLoadedItemPos));
798
799         if (loadedItemCount < currentCachingsize || viewHeight < itemTotalHeight)
800         {
801                 return false;
802         }
803
804         return true;
805 }
806
807 void
808 _TableViewPresenter::GetFirstLoadedItemIndex(int& groupIndex, int& itemIndex) const
809 {
810         __pListModel->GetFirstLoadedItemIndex(groupIndex, itemIndex);
811 }
812
813 void
814 _TableViewPresenter::GetLastLoadedItemIndex(int& groupIndex, int& itemIndex) const
815 {
816         __pListModel->GetLastLoadedItemIndex(groupIndex, itemIndex);
817 }
818
819 void
820 _TableViewPresenter::RefreshItemLayout(int groupIndex, int itemIndex)
821 {
822         TableViewItemTag itemTag = {groupIndex, itemIndex};
823
824         ResetSweepItem();
825
826         RefreshItemLayout(itemTag, itemTag, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY, false);
827 }
828
829 void
830 _TableViewPresenter::RefreshItemLayout(TableViewItemTag& topDrawnItemTag, TableViewItemTag& refreshItemTag, TableViewRefreshType type, bool animation)
831 {
832         if (!__pListModel->IsValidItem(topDrawnItemTag.groupIndex, topDrawnItemTag.itemIndex))
833         {
834                 return;
835         }
836
837         if (refreshItemTag.itemIndex == -1)
838         {
839                 animation = false;
840         }
841
842         _TableViewItem* pItem = null;
843
844         TableViewItemTag itemPos = {-1, -1};
845         TableViewItemTag currentItem = {-1, -1};
846
847         int loadItemCount = 0;
848         int maxLoadItemCount = GetMaxItemCachingSize();
849         FloatRectangle itemBounds(0.0f, 0.0f, 0.0f, 0.0f);
850
851         StopAllItemAnimation();
852
853         __pListModel->GetFirstLoadedItemIndex(itemPos.groupIndex, itemPos.itemIndex);
854
855         if (itemPos.groupIndex == -1 && itemPos.itemIndex == -1)
856         {
857                 itemPos = topDrawnItemTag;
858         }
859
860         currentItem = itemPos;
861
862         float itemPositionY = CalculateItemPositionY(itemPos.groupIndex, itemPos.itemIndex);
863
864         do
865         {
866                 pItem = LoadItem(itemPos.groupIndex, itemPos.itemIndex);
867
868                 if (pItem == null)
869                 {
870                         break;
871                 }
872
873                 if (pItem->HasParent())
874                 {
875                         pItem->SetDrawingProperty(__pItemDrawingProperty);
876                         SetItemType(pItem, itemPos);
877                 }
878
879                 itemBounds = pItem->GetBoundsF();
880                 itemBounds.y = itemPositionY;
881
882                 if (animation)
883                 {
884                         if (type == TABLE_VIEW_REFRESH_TYPE_ITEM_ADD)
885                         {
886                                 if (itemPos.groupIndex == refreshItemTag.groupIndex && itemPos.itemIndex == refreshItemTag.itemIndex)
887                                 {
888                                         pItem->SetBounds(itemBounds);
889                                         pItem->FadeInOutItem(false, ADD_ITEM_ANIMATION_DURATION, REFRESH_ITEM_ANIMATION_DELAY);
890                                         pItem->ZoomInOutItem(false, ADD_ITEM_ANIMATION_DURATION, REFRESH_ITEM_ANIMATION_DELAY);
891                                 }
892                                 else
893                                 {
894                                         if (!pItem->MoveItem(FloatPoint(itemBounds.x, itemBounds.y), ADD_ITEM_ANIMATION_DURATION, 0))
895                                         {
896                                                 pItem->SetBounds(itemBounds);
897                                         }
898                                 }
899                         }
900                         else
901                         {
902                                 if (!pItem->MoveItem(FloatPoint(itemBounds.x, itemBounds.y), REMOVE_ITEM_MOVE_ANIMATION_DURATION, REFRESH_ITEM_ANIMATION_DELAY))
903                                 {
904                                         pItem->SetBounds(itemBounds);
905                                 }
906                         }
907                 }
908                 else
909                 {
910                         pItem->SetBounds(itemBounds);
911                 }
912
913                 currentItem = itemPos;
914                 itemPositionY = itemBounds.y + itemBounds.height;
915
916                 loadItemCount++;
917
918         } while (loadItemCount < maxLoadItemCount && GetNextItemPosition(currentItem, itemPos));
919
920         if (loadItemCount < maxLoadItemCount)
921         {
922                 __pListModel->GetFirstLoadedItemIndex(itemPos.groupIndex, itemPos.itemIndex);
923                 currentItem = itemPos;
924
925                 while (loadItemCount < maxLoadItemCount && GetPreviousItemPosition(currentItem, itemPos))
926                 {
927                         pItem = LoadItem(itemPos.groupIndex, itemPos.itemIndex);
928
929                         if (pItem == null)
930                         {
931                                 break;
932                         }
933
934                         currentItem = itemPos;
935
936                         loadItemCount++;
937                 }
938         }
939
940         if (refreshItemTag.itemIndex == -1)
941         {
942                 ScrollToItem(topDrawnItemTag.groupIndex, topDrawnItemTag.itemIndex, TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_TOP);
943         }
944 }
945
946 void
947 _TableViewPresenter::RefreshItemBounds(_TableViewItem* pItem, TableViewItemTag& itemPos)
948 {
949         FloatRectangle itemBounds;
950
951         if (pItem == null)
952         {
953                 return;
954         }
955
956         itemBounds = pItem->GetBoundsF();
957
958         itemBounds.y = CalculateItemPositionY(itemPos.groupIndex, itemPos.itemIndex);
959
960         if (itemPos.itemIndex != -1)
961         {
962                 float itemMargin = GetLeftMargin();
963                 itemBounds.x = itemMargin;
964                 itemBounds.width = __pItemDrawingProperty->width - itemBounds.x - itemMargin;
965         }
966         else
967         {
968                 itemBounds.x = 0.0f;
969                 itemBounds.width = __pItemDrawingProperty->width;
970         }
971
972         pItem->SetBounds(itemBounds);
973 }
974
975 result
976 _TableViewPresenter::GetItemIndexFromPosition(const FloatPoint& position, int& groupIndex, int& itemIndex) const
977 {
978         result r = E_SUCCESS;
979         TableViewItemTag itemPos;
980
981         FloatPoint targetPosition = position;
982         float scrollPosition = GetScrollPosition();
983         targetPosition.y += scrollPosition;
984
985         r = GetItemFromPosition(targetPosition, itemPos);
986
987         if (r != E_SUCCESS)
988         {
989                 groupIndex = -1;
990                 itemIndex = -1;
991                 return r;
992         }
993
994         groupIndex = itemPos.groupIndex;
995         itemIndex = itemPos.itemIndex;
996
997         return r;
998 }
999
1000
1001 bool
1002 _TableViewPresenter::PreloadItem(void)
1003 {
1004         if (GetModel() == null || __pProviderAdaptor == null)
1005         {
1006                 return false;
1007         }
1008
1009         __modelInitialized = true;
1010
1011         if (__pListModel->GetAllGroupCount() == 0 && (__pProviderAdaptor != null))
1012         {
1013                 int itemCount = 0;
1014                 int groupCount = __pProviderAdaptor->GetGroupCount();
1015
1016                 for (int i = 0; i < groupCount; i++)
1017                 {
1018                         itemCount = __pProviderAdaptor->GetItemCount(i);
1019                         __pListModel->AddGroup(itemCount, false);
1020                 }
1021         }
1022
1023         __pListModel->RestoreItemStatus();
1024
1025         CreateItemHeightList(TABLEVIEW_DEFAULT_ITEM_HEIGHT_VALUE, TABLEVIEW_DEFAULT_ITEM_HEIGHT_VALUE);
1026         CreateSectionAlignmentList();
1027
1028         int cachingSize = 0;
1029
1030         if (GetItemCount() > TABLEVIEW_MAX_ITEM_COUNT)
1031         {
1032                 cachingSize = TABLEVIEW_MAX_ITEM_COUNT;
1033         }
1034         else if (__pListModel->GetMaxCachingSize() < TABLEVIEW_MAX_ITEM_COUNT)
1035         {
1036                 cachingSize = __pListModel->GetMaxCachingSize();
1037         }
1038         else
1039         {
1040                 cachingSize = GetItemCount();
1041         }
1042
1043         TableViewItemTag itemPos = {-1, -1};
1044         GetFirstItem(itemPos);
1045
1046         _TableViewItem* pItem = null;
1047         for (int i = 0; i < cachingSize; i++)
1048         {
1049                 pItem = LoadItem(itemPos.groupIndex, itemPos.itemIndex);
1050
1051                 if (pItem == null)
1052                 {
1053                         break;
1054                 }
1055
1056                 if (GetNextItemPosition(itemPos, itemPos) == false)
1057                 {
1058                         break;
1059                 }
1060         }
1061
1062         if (IsCachingItemsTotalHeightLessThanViewHeight())
1063         {
1064                 AdjustLayoutItems(0.0f);
1065         }
1066
1067         PresetItemHeightList();
1068         AdjustClientAreaBounds(true);
1069
1070         if (__pTableView->GetScrollStyle() == TABLE_VIEW_SCROLL_BAR_STYLE_FAST_SCROLL)
1071         {
1072                 _FastScroll* pFastScroll = __pTableView->GetFastScrollBar();
1073                 if (pFastScroll != null)
1074                 {
1075                         pFastScroll->UpdateIndex();
1076                         pFastScroll->SetScrollVisibility(IsScrollable());
1077                 }
1078         }
1079
1080         return true;
1081 }
1082
1083 bool
1084 _TableViewPresenter::PreloadItem(int topDrawnGroupIndex, int topDrawnItemIndex, int shiftingDistance)
1085 {
1086         if (GetModel() == null || __pProviderAdaptor == null)
1087         {
1088                 return false;
1089         }
1090
1091         __modelInitialized = true;
1092
1093         if (__pListModel->GetAllGroupCount() == 0 && (__pProviderAdaptor != null))
1094         {
1095                 int itemCount = 0;
1096                 int groupCount = __pProviderAdaptor->GetGroupCount();
1097
1098                 for (int i = 0; i < groupCount; i++)
1099                 {
1100                         itemCount = __pProviderAdaptor->GetItemCount(i);
1101                         __pListModel->AddGroup(itemCount, false);
1102                 }
1103         }
1104
1105         float defaultGroupHeight = __pProviderAdaptor->GetDefaultGroupItemHeight();
1106         float defaultItemHeight = __pProviderAdaptor->GetDefaultItemHeight();
1107
1108         if (_FloatCompareLE(defaultGroupHeight, 0.0f))
1109         {
1110                 defaultGroupHeight = TABLEVIEW_DEFAULT_ITEM_HEIGHT_VALUE;
1111         }
1112
1113         if (_FloatCompareLE(defaultItemHeight, 0.0f))
1114         {
1115                 defaultItemHeight = TABLEVIEW_DEFAULT_ITEM_HEIGHT_VALUE;
1116         }
1117
1118         __pListModel->RestoreItemStatus();
1119
1120         DeleteItemHeightList();
1121         CreateItemHeightList(defaultGroupHeight, defaultItemHeight);
1122
1123         DeleteSectionAlignmentList();
1124         CreateSectionAlignmentList();
1125
1126         if (!__pListModel->IsValidItem(topDrawnGroupIndex, topDrawnItemIndex))
1127         {
1128                 TableViewItemTag firstItemTag = {-1, -1};
1129
1130                 GetFirstItem(firstItemTag);
1131
1132                 topDrawnGroupIndex = firstItemTag.groupIndex;
1133                 topDrawnItemIndex = firstItemTag.itemIndex;
1134
1135                 shiftingDistance = 0;
1136         }
1137
1138         ScrollToItem(topDrawnGroupIndex, topDrawnItemIndex, TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_TOP, shiftingDistance);
1139
1140         if (IsCachingItemsTotalHeightLessThanViewHeight())
1141         {
1142                 AdjustLayoutItems(GetScrollPosition());
1143         }
1144
1145         AdjustClientAreaBounds(true);
1146
1147         if (__pTableView->GetScrollStyle() == TABLE_VIEW_SCROLL_BAR_STYLE_FAST_SCROLL)
1148         {
1149                 _FastScroll* pFastScroll = __pTableView->GetFastScrollBar();
1150                 if (pFastScroll != null)
1151                 {
1152                         pFastScroll->UpdateIndex();
1153                         pFastScroll->SetScrollVisibility(IsScrollable());
1154                 }
1155         }
1156
1157         return true;
1158 }
1159
1160 bool
1161 _TableViewPresenter::IsItemChecked(int groupIndex, int itemIndex) const
1162 {
1163         if ((groupIndex < 0) || (groupIndex >= GetGroupCount()) || (itemIndex < -1) || (itemIndex >= GetItemCountAt(groupIndex)))
1164         {
1165                 return false;
1166         }
1167
1168         return __pListModel->IsItemChecked(groupIndex, itemIndex);
1169 }
1170
1171 result
1172 _TableViewPresenter::SetItemChecked(int groupIndex, int itemIndex, bool checked)
1173 {
1174         if ((groupIndex < 0) || (groupIndex >= GetGroupCount()) || (itemIndex < -1) || (itemIndex >= GetItemCountAt(groupIndex)))
1175         {
1176                 return E_OUT_OF_RANGE;
1177         }
1178
1179         if (__modelInitialized == false)
1180         {
1181                 return E_INVALID_STATE;
1182         }
1183
1184         TableViewItemTag itemPos = {groupIndex, itemIndex};
1185
1186         bool enabled = __pListModel->IsItemEnabled(itemPos.groupIndex, itemPos.itemIndex);
1187         SysTryReturn(NID_UI_CTRL, (enabled == true), E_INVALID_OPERATION, E_INVALID_OPERATION,
1188                         "[E_INVALID_OPERATION] The item is disabled.");
1189
1190         if (__pListModel->IsItemChecked(itemPos.groupIndex, itemPos.itemIndex) == checked)
1191         {
1192                 return E_SUCCESS;
1193         }
1194
1195         TableViewItemTag itemTag = {groupIndex, itemIndex};
1196         _TableViewItem *pItem = FindItem(itemTag);
1197         if (pItem != null)
1198         {
1199                 pItem->SetCheckedAnimationEnabled(checked);
1200         }
1201
1202         result r = __pListModel->SetItemChecked(itemPos.groupIndex, itemPos.itemIndex, checked);
1203
1204         return r;
1205 }
1206
1207 bool
1208 _TableViewPresenter::IsItemEnabled(int groupIndex, int itemIndex) const
1209 {
1210         if ((groupIndex < 0) || (groupIndex >= GetGroupCount()) || (itemIndex < -1) || (itemIndex >= GetItemCountAt(groupIndex)))
1211         {
1212                 return false;
1213         }
1214
1215         return __pListModel->IsItemEnabled(groupIndex, itemIndex);
1216 }
1217
1218 result
1219 _TableViewPresenter::SetItemEnabled(int groupIndex, int itemIndex, bool enabled)
1220 {
1221         if ((groupIndex < 0) || (groupIndex >= GetGroupCount()) || (itemIndex < -1) || (itemIndex >= GetItemCountAt(groupIndex)))
1222         {
1223                 return E_OUT_OF_RANGE;
1224         }
1225
1226         TableViewItemTag itemPos = {groupIndex, itemIndex};
1227
1228         if (__pListModel->IsItemEnabled(itemPos.groupIndex, itemPos.itemIndex) == enabled)
1229         {
1230                 return E_SUCCESS;
1231         }
1232
1233         result r = __pListModel->SetItemEnabled(itemPos.groupIndex, itemPos.itemIndex, enabled);
1234
1235         return r;
1236 }
1237
1238 result
1239 _TableViewPresenter::SetStatusChanged(bool changed)
1240 {
1241         __statusChangedFlag = changed;
1242
1243         if (__statusChangedFlag == true)
1244         {
1245                 SetItemDrawingProperty();
1246
1247                 if ((__pItemDrawingProperty != null) && (__pItemDrawingProperty->propertyChanged == true))
1248                 {
1249                         __pListModel->SetAllLoadedItemStateChanged(true);
1250                 }
1251         }
1252
1253         return E_SUCCESS;
1254 }
1255
1256 bool
1257 _TableViewPresenter::IsStatusChanged(void) const
1258 {
1259         return __statusChangedFlag;
1260 }
1261
1262 float
1263 _TableViewPresenter::GetTopMargin(void) const
1264 {
1265         return __topMargin;
1266 }
1267
1268 result
1269 _TableViewPresenter::SetTopMargin(float topMargin)
1270 {
1271         __topMargin = topMargin;
1272
1273         return E_SUCCESS;
1274 }
1275
1276 float
1277 _TableViewPresenter::GetBottomMargin(void) const
1278 {
1279         return __bottomMargin;
1280 }
1281
1282 result
1283 _TableViewPresenter::SetBottomMargin(float bottomMargin)
1284 {
1285         __bottomMargin = bottomMargin;
1286
1287         return E_SUCCESS;
1288 }
1289
1290 float
1291 _TableViewPresenter::GetLeftMargin(void) const
1292 {
1293         return __leftMargin;
1294 }
1295
1296 result
1297 _TableViewPresenter::SetLeftMargin(float leftMargin)
1298 {
1299         __leftMargin = leftMargin;
1300
1301         return E_SUCCESS;
1302 }
1303
1304 void
1305 _TableViewPresenter::SetItemType(_TableViewItem* pItem, TableViewItemTag itemPosition)
1306 {
1307         TableViewStyle style = __pTableView->GetTableViewStyle();
1308
1309         if (itemPosition.itemIndex == -1)
1310         {
1311                 if (style == TABLE_VIEW_STYLE_SECTION)
1312                 {
1313                         pItem->SetItemType(TABLE_VIEW_ITEM_TYPE_HEADER);
1314                 }
1315                 else
1316                 {
1317                         pItem->SetItemType(TABLE_VIEW_ITEM_TYPE_TITLE);
1318                 }
1319         }
1320         else
1321         {
1322                 int itemCount = GetItemCountAt(itemPosition.groupIndex);
1323
1324                 if (itemPosition.itemIndex == 0)
1325                 {
1326                         if (HasSectionFooter(itemPosition.groupIndex))
1327                         {
1328                                 if (itemCount == 1)
1329                                 {
1330                                         pItem->SetItemType(TABLE_VIEW_ITEM_TYPE_FOOTER);
1331                                 }
1332                                 else if (itemCount == 2)
1333                                 {
1334                                         pItem->SetItemType(TABLE_VIEW_ITEM_TYPE_ONE);
1335                                 }
1336                                 else
1337                                 {
1338                                         pItem->SetItemType(TABLE_VIEW_ITEM_TYPE_TOP);
1339                                 }
1340                         }
1341                         else
1342                         {
1343                                 if (itemCount == 1)
1344                                 {
1345                                         pItem->SetItemType(TABLE_VIEW_ITEM_TYPE_ONE);
1346                                 }
1347                                 else
1348                                 {
1349                                         pItem->SetItemType(TABLE_VIEW_ITEM_TYPE_TOP);
1350                                 }
1351                         }
1352                 }
1353                 else
1354                 {
1355                         int lastItemIndex = itemCount - 1;
1356
1357                         if (HasSectionFooter(itemPosition.groupIndex))
1358                         {
1359                                 if (itemPosition.itemIndex == lastItemIndex)
1360                                 {
1361                                         pItem->SetItemType(TABLE_VIEW_ITEM_TYPE_FOOTER);
1362                                 }
1363                                 else if (itemPosition.itemIndex == lastItemIndex - 1)
1364                                 {
1365                                         pItem->SetItemType(TABLE_VIEW_ITEM_TYPE_BOTTOM);
1366                                 }
1367                                 else
1368                                 {
1369                                         pItem->SetItemType(TABLE_VIEW_ITEM_TYPE_MIDDLE);
1370                                 }
1371                         }
1372                         else
1373                         {
1374                                 if (itemPosition.itemIndex == lastItemIndex)
1375                                 {
1376                                         pItem->SetItemType(TABLE_VIEW_ITEM_TYPE_BOTTOM);
1377                                 }
1378                                 else
1379                                 {
1380                                         pItem->SetItemType(TABLE_VIEW_ITEM_TYPE_MIDDLE);
1381                                 }
1382                         }
1383                 }
1384         }
1385 }
1386
1387 void
1388 _TableViewPresenter::SetItemLayout(_TableViewItem* pItem, TableViewItemTag& itemPos)
1389 {
1390         _TableViewItem* pSeriesItem = null;
1391         TableViewItemTag seriesItemPos = {-1, -1};
1392         FloatRectangle seriesItemBounds;
1393         FloatRectangle itemBounds;
1394         bool validBounds = false;
1395         bool downScroll = true;
1396
1397         if (itemPos.itemIndex == -1 && __pTableView->GetTableViewStyle() != TABLE_VIEW_STYLE_SECTION)
1398         {
1399                 itemBounds.x = 0;
1400                 itemBounds.width = __pItemDrawingProperty->width;
1401         }
1402         else
1403         {
1404                 float itemMargin = GetLeftMargin();
1405                 itemBounds.x = itemMargin;
1406                 itemBounds.width = __pItemDrawingProperty->width - itemBounds.x - itemMargin;
1407         }
1408
1409         FloatDimension itemDimension = Tizen::Graphics::CoordinateSystem::AlignToDevice(FloatDimension(pItem->GetSizeF().width, pItem->GetSizeF().height));
1410         itemBounds.height = itemDimension.height;
1411
1412         if (itemPos.groupIndex == 0 && itemPos.itemIndex == -1)
1413         {
1414                 itemBounds.y = GetTopMargin();
1415                 validBounds = true;
1416         }
1417         else
1418         {
1419                 if (GetPreviousItemPosition(itemPos, seriesItemPos))
1420                 {
1421                         if (__pListModel->IsLoadedItem(seriesItemPos.groupIndex, seriesItemPos.itemIndex))
1422                         {
1423                                 pSeriesItem = static_cast<_TableViewItem*>(__pListModel->LoadItem(seriesItemPos.groupIndex, seriesItemPos.itemIndex));
1424                                 if ((pSeriesItem != null) && pSeriesItem->HasParent())
1425                                 {
1426                                         if (__pTableView->IsReorderModeEnabled() && (__reorderInfo.groupIndex == seriesItemPos.groupIndex && __reorderInfo.itemIndex == seriesItemPos.itemIndex))
1427                                         {
1428                                                 seriesItemBounds = __reorderInfo.itemBounds;
1429                                         }
1430                                         else
1431                                         {
1432                                                 seriesItemBounds = pSeriesItem->GetBoundsF();
1433                                         }
1434
1435                                         itemBounds.y = seriesItemBounds.y + seriesItemBounds.height;
1436
1437                                         validBounds = true;
1438                                 }
1439                         }
1440                 }
1441
1442                 if ((!validBounds) && GetNextItemPosition(itemPos, seriesItemPos))
1443                 {
1444                         if (__pListModel->IsLoadedItem(seriesItemPos.groupIndex, seriesItemPos.itemIndex))
1445                         {
1446                                 pSeriesItem = static_cast<_TableViewItem*>(__pListModel->LoadItem(seriesItemPos.groupIndex, seriesItemPos.itemIndex));
1447                                 if ((pSeriesItem != null) && pSeriesItem->HasParent())
1448                                 {
1449                                         if (__pTableView->IsReorderModeEnabled() && (__reorderInfo.groupIndex == seriesItemPos.groupIndex && __reorderInfo.itemIndex == seriesItemPos.itemIndex))
1450                                         {
1451                                                 seriesItemBounds = __reorderInfo.itemBounds;
1452                                         }
1453                                         else
1454                                         {
1455                                                 seriesItemBounds = pSeriesItem->GetBoundsF();
1456                                         }
1457
1458                                         itemBounds.y = seriesItemBounds.y - itemBounds.height;
1459
1460                                         validBounds = true;
1461                                         downScroll = false;
1462                                 }
1463                         }
1464                 }
1465         }
1466
1467         if (validBounds)
1468         {
1469                 pItem->SetBounds(itemBounds);
1470
1471                 CheckItemHeightAndRefreshLayout(itemPos, downScroll);
1472         }
1473         else
1474         {
1475                 itemBounds.y = CalculateItemPositionY(itemPos.groupIndex, itemPos.itemIndex);
1476                 pItem->SetBounds(itemBounds);
1477
1478                 CheckItemHeightAndRefreshLayout(itemPos, true);
1479         }
1480
1481         if (__pTableView->IsReorderModeEnabled() && __reorderInfo.itemIndex != -1)
1482         {
1483                 TableViewItemTag reorderSelectedItemTag = {__reorderInfo.groupIndex, __reorderInfo.itemIndex};
1484                 _TableViewItem* pReorderSelectedItem = FindItem(reorderSelectedItemTag);
1485
1486                 if (pReorderSelectedItem != null)
1487                 {
1488                         pReorderSelectedItem->GetVisualElement()->SetZOrder(null, true);
1489                 }
1490         }
1491
1492         if (pItem->GetItemLayoutEnabled())
1493         {
1494                 pItem->PartialUpdateLayout();
1495         }
1496 }
1497
1498 _TableViewItem*
1499 _TableViewPresenter::LoadItem(int groupIndex, int itemIndex)
1500 {
1501         _TableViewItem* pItem = static_cast<_TableViewItem*>(__pListModel->LoadItem(groupIndex, itemIndex));
1502
1503         if ((pItem != null) && !pItem->HasParent())
1504         {
1505                 __lockLoadItemWithScroll = true;
1506
1507                 __pTableView->AttachChild(*pItem);
1508
1509                 pItem->SetDrawingProperty(__pItemDrawingProperty);
1510
1511                 TableViewItemTag itemPosition = {groupIndex, itemIndex};
1512                 SetItemType(pItem, itemPosition);
1513                 SetItemLayout(pItem, itemPosition);
1514                 pItem->SetReorderMode(__pTableView->IsReorderModeEnabled());
1515                 pItem->AdjustChildControlMargin();
1516
1517                 __lockLoadItemWithScroll = false;
1518         }
1519
1520         return pItem;
1521 }
1522
1523 _TableViewItem*
1524 _TableViewPresenter::FindItem(TableViewItemTag& itemTag)
1525 {
1526         if (__pListModel->IsLoadedItem(itemTag.groupIndex, itemTag.itemIndex))
1527         {
1528                 return static_cast<_TableViewItem*>(__pListModel->LoadItem(itemTag.groupIndex, itemTag.itemIndex));
1529         }
1530         return null;
1531 }
1532
1533 void
1534 _TableViewPresenter::UnloadItem(int groupIndex, int itemIndex)
1535 {
1536         __pListModel->UnloadItem(groupIndex, itemIndex);
1537 }
1538
1539 void
1540 _TableViewPresenter::UnloadItem(TableViewItemTag& itemTag)
1541 {
1542         __pListModel->UnloadItem(itemTag.groupIndex, itemTag.itemIndex);
1543
1544         return;
1545 }
1546
1547 void
1548 _TableViewPresenter::DetachItem(TableViewItemTag& itemTag)
1549 {
1550         _TableViewItem *pItem = FindItem(itemTag);
1551
1552         if (pItem != null && pItem->HasParent())
1553         {
1554                 pItem->GetParent()->DetachChild(*pItem);
1555         }
1556 }
1557
1558 void
1559 _TableViewPresenter::DetachContextItem(TableViewItemTag& itemTag)
1560 {
1561         _TableViewItem *pItem = FindItem(itemTag);
1562         if (pItem == null)
1563         {
1564                 return;
1565         }
1566
1567         _TableViewItem* contextItem = pItem->GetContextItem();
1568         if (contextItem != null && contextItem->HasParent())
1569         {
1570                 contextItem->GetParent()->DetachChild(*pItem);
1571         }
1572 }
1573
1574 void
1575 _TableViewPresenter::DetachAllItem(bool removeItem)
1576 {
1577         TableViewItemTag itemPos = {-1, -1};
1578         TableViewItemTag lastItemPos = {-1, -1};
1579
1580         __pListModel->GetFirstLoadedItemIndex(itemPos.groupIndex, itemPos.itemIndex);
1581         __pListModel->GetLastLoadedItemIndex(lastItemPos.groupIndex, lastItemPos.itemIndex);
1582
1583         if (itemPos.groupIndex == -1 && itemPos.itemIndex == -1)
1584         {
1585                 return;
1586         }
1587
1588         do
1589         {
1590                 DetachItem(itemPos);
1591
1592                 if (removeItem)
1593                 {
1594                         UnloadItem(itemPos);
1595                 }
1596
1597                 if (itemPos.itemIndex == lastItemPos.itemIndex && itemPos.groupIndex == lastItemPos.groupIndex)
1598                 {
1599                         break;
1600                 }
1601         } while (GetNextItemPosition(itemPos, itemPos));
1602 }
1603
1604 void
1605 _TableViewPresenter::SetItemDrawingProperty(void)
1606 {
1607         if (__pItemDrawingProperty != null)
1608         {
1609                 __pItemDrawingProperty->propertyChanged = false;
1610
1611                 if (__pItemDrawingProperty->itemDividerEnabled != __pTableView->IsItemDividerEnabled())
1612                 {
1613                         __pItemDrawingProperty->itemDividerEnabled = __pTableView->IsItemDividerEnabled();
1614                         __pItemDrawingProperty->propertyChanged = true;
1615                 }
1616
1617                 if (__pItemDrawingProperty->dividerColor != __pTableView->GetItemDividerColor())
1618                 {
1619                         __pItemDrawingProperty->dividerColor = __pTableView->GetItemDividerColor();
1620                         __pItemDrawingProperty->propertyChanged = true;
1621                 }
1622
1623                 if (__pItemDrawingProperty->sectionStyleEnabled != (__pTableView->GetTableViewStyle() == TABLE_VIEW_STYLE_SECTION))
1624                 {
1625                         __pItemDrawingProperty->sectionStyleEnabled = (__pTableView->GetTableViewStyle() == TABLE_VIEW_STYLE_SECTION);
1626                         __pItemDrawingProperty->propertyChanged = true;
1627                 }
1628
1629                 if (__pItemDrawingProperty->sectionStyleBgColor != __pTableView->GetSectionColor())
1630                 {
1631                         __pItemDrawingProperty->sectionStyleBgColor = __pTableView->GetSectionColor();
1632                         __pItemDrawingProperty->propertyChanged = true;
1633                 }
1634
1635                 if (__pTableView->GetTableViewStyle() != TABLE_VIEW_STYLE_SIMPLE)
1636                 {
1637                         if (__pItemDrawingProperty->groupedLookEnabled != __pTableView->IsGroupedLookEnabled())
1638                         {
1639                                 __pItemDrawingProperty->groupedLookEnabled = __pTableView->IsGroupedLookEnabled();
1640                                 __pItemDrawingProperty->propertyChanged = true;
1641                         }
1642                 }
1643
1644                 if (__pItemDrawingProperty->reorderMode != __pTableView->IsReorderModeEnabled())
1645                 {
1646                         __pItemDrawingProperty->reorderMode = __pTableView->IsReorderModeEnabled();
1647                         __pItemDrawingProperty->propertyChanged = true;
1648                 }
1649
1650                 if (!_FloatCompare(__pItemDrawingProperty->leftMargin, __leftMargin))
1651                 {
1652                         __pItemDrawingProperty->leftMargin = __leftMargin;
1653                         __pItemDrawingProperty->propertyChanged = true;
1654                 }
1655
1656                 __pItemDrawingProperty->scrollMargin = 0;
1657
1658                 if (!_FloatCompare(__pItemDrawingProperty->width, __pTableView->GetBoundsF().width))
1659                 {
1660                         __pItemDrawingProperty->width = __pTableView->GetBoundsF().width;
1661                         __pItemDrawingProperty->propertyChanged = true;
1662                 }
1663         }
1664 }
1665
1666 void
1667 _TableViewPresenter::OnBoundsChanged(void)
1668 {
1669         float listWidth = __pTableView->GetBoundsF().width - (GetLeftMargin() * 2);
1670
1671         if (__pProviderAdaptor != null && __modelInitialized)
1672         {
1673                 if (__pTableView->IsReorderModeEnabled() && __reorderInfo.itemIndex != -1)
1674                 {
1675                         ResetReorderItem(__reorderInfo.groupIndex, __reorderInfo.itemIndex);
1676                 }
1677
1678                 if (!_FloatCompare(listWidth, __pProviderAdaptor->GetListWidth()))
1679                 {
1680                         __pProviderAdaptor->SetListWidth(listWidth);
1681
1682                         SetItemDrawingProperty();
1683
1684                         AdjustLoadedItemWidth();
1685
1686                         __pTableView->UpdateLayout();
1687                 }
1688
1689                 SetClientAreaHeight(__itemTotalHeight);
1690                 ResetSweepItem();
1691
1692                 AdjustLayoutItems(GetScrollPosition());
1693         }
1694         else
1695         {
1696                 if (__pProviderAdaptor != null)
1697                 {
1698                         __pProviderAdaptor->SetListWidth(listWidth);
1699                 }
1700
1701                 SetClientAreaHeight(__pTableView->GetBoundsF().height);
1702                 _ScrollPanelPresenter::OnBoundsChanged();
1703         }
1704 }
1705
1706 result
1707 _TableViewPresenter::Draw(void)
1708 {
1709         result r = _ScrollPanelPresenter::Draw();
1710         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1711
1712         if (__modelInitialized == false)
1713         {
1714                 SetItemDrawingProperty();
1715
1716                 if(PreloadItem() == false)
1717                 {
1718                         return E_SUCCESS;
1719                 }
1720
1721                 if (__reservedScrollItemIndex.groupIndex != -1 && __reservedScrollItemIndex.itemIndex != -1)
1722                 {
1723                         ScrollToItem(__reservedScrollItemIndex.groupIndex, __reservedScrollItemIndex.itemIndex, __reservedScrollItemAlignment);
1724
1725                         __reservedScrollItemIndex.groupIndex = -1;
1726                         __reservedScrollItemIndex.itemIndex = -1;
1727
1728                         return E_SUCCESS;
1729                 }
1730         }
1731
1732         __firstDrawnFlag = false;
1733
1734         // Draw empty list
1735         if (IsEmpty() == true)
1736         {
1737                 return DrawEmptyTableView();
1738         }
1739
1740         return E_SUCCESS;
1741 }
1742
1743 _UiTouchEventDelivery
1744 _TableViewPresenter::OnPreviewTouchPressed(const _Control& source, const _TouchInfo& touchInfo)
1745 {
1746         _UiTouchEventDelivery response = _ScrollPanelPresenter::OnPreviewTouchPressed(source, touchInfo);
1747
1748         _TableViewItem* pItem = GetTableViewItemFromControl(source);
1749         if (pItem == null)
1750         {
1751                 return response;
1752         }
1753
1754         TableViewItemTag itemPos = {-1, -1};
1755
1756         pItem->GetItemIndex(itemPos.groupIndex, itemPos.itemIndex);
1757
1758         if (itemPos.groupIndex == -1 && itemPos.itemIndex == -1)
1759         {
1760                 return response;
1761         }
1762
1763         if (__pTableView->IsReorderModeEnabled())
1764         {
1765                 __firstTouchMoved = true;
1766
1767                 if (SelectReorderItem(itemPos.groupIndex, itemPos.itemIndex, false))
1768                 {
1769                         __reorderInfo.touchPressedPositionY = touchInfo.GetCurrentPosition().y;
1770                 }
1771         }
1772
1773         return response;
1774 }
1775
1776 _UiTouchEventDelivery
1777 _TableViewPresenter::OnPreviewTouchMoved(const _Control& source, const _TouchInfo& touchInfo)
1778 {
1779         if (__pTableView->IsReorderModeEnabled())
1780         {
1781                 if (__reorderInfo.itemIndex != -1)
1782                 {
1783                         if (!DragSelectedItem(touchInfo.GetCurrentPosition().y - __reorderInfo.touchPressedPositionY, true))
1784                         {
1785                                 __firstTouchMoved = false;
1786
1787                                 ResetReorderItem(__reorderInfo.groupIndex, __reorderInfo.itemIndex);
1788                         }
1789
1790                         return _UI_TOUCH_EVENT_DELIVERY_NO;
1791                 }
1792         }
1793
1794         return _ScrollPanelPresenter::OnPreviewTouchMoved(source, touchInfo);
1795 }
1796
1797 _UiTouchEventDelivery
1798 _TableViewPresenter::OnPreviewTouchReleased(const _Control& source, const _TouchInfo& touchInfo)
1799 {
1800         if (__pTableView->IsReorderModeEnabled() && __reorderInfo.itemIndex != -1)
1801         {
1802                 ResetReorderItem(__reorderInfo.groupIndex, __reorderInfo.itemIndex);
1803
1804                 if (__reorderInfo.blockedTouchReleaseState)
1805                 {
1806                         __reorderInfo.blockedTouchReleaseState = false;
1807
1808                         return _UI_TOUCH_EVENT_DELIVERY_NO;
1809                 }
1810         }
1811
1812         return _ScrollPanelPresenter::OnPreviewTouchReleased(source, touchInfo);
1813 }
1814
1815 _UiTouchEventDelivery
1816 _TableViewPresenter::OnPreviewTouchCanceled(const _Control& source, const _TouchInfo& touchInfo)
1817 {
1818         return _ScrollPanelPresenter::OnPreviewTouchCanceled(source, touchInfo);
1819 }
1820
1821 bool
1822 _TableViewPresenter::OnTouchPressed(const _Control& source, const _TouchInfo& touchInfo)
1823 {
1824         __firstTouchMoved = true;
1825
1826         _TableViewItem* pItem = GetTableViewItemFromControl(source);
1827
1828         if (pItem == null)
1829         {
1830                 return _ScrollPanelPresenter::OnTouchPressed(source, touchInfo);
1831         }
1832
1833         TableViewItemTag itemPos = {-1, -1};
1834         pItem->GetItemIndex(itemPos.groupIndex, itemPos.itemIndex);
1835
1836         if (!(pItem->IsContextItem()
1837                         || pItem->IsItemEnabled() == false
1838                         || pItem->GetItemType() == TABLE_VIEW_ITEM_TYPE_TITLE
1839                         || pItem->GetItemType() == TABLE_VIEW_ITEM_TYPE_HEADER
1840                         || pItem->GetItemType() == TABLE_VIEW_ITEM_TYPE_FOOTER)
1841                         && ((itemPos.groupIndex != __sweptItemTag.groupIndex)
1842                                         || (itemPos.itemIndex != __sweptItemTag.itemIndex)))
1843         {
1844                 ResetSweptItem();
1845         }
1846
1847         __sweepOccured = false;
1848
1849         _VisualElement* pVisualElement = __pTableView->GetVisualElement();
1850         String animationName(L"EXPAND_GROUP_ANIMATION");
1851         VisualElementValueAnimation* pExpandGroupAnimation = dynamic_cast<VisualElementValueAnimation*>(pVisualElement->GetAnimationN(animationName));
1852         if (pExpandGroupAnimation != null)
1853         {
1854                 pVisualElement->RemoveAnimation(animationName);
1855                 delete pExpandGroupAnimation;
1856         }
1857
1858         animationName = L"COLLAPSE_GROUP_ANIMATION";
1859         VisualElementValueAnimation* pCollapseGroupAnimation = dynamic_cast<VisualElementValueAnimation*>(pVisualElement->GetAnimationN(animationName));
1860         if (pCollapseGroupAnimation != null)
1861         {
1862                 pVisualElement->RemoveAnimation(animationName);
1863                 delete pCollapseGroupAnimation;
1864         }
1865
1866         return _ScrollPanelPresenter::OnTouchPressed(source, touchInfo);
1867 }
1868
1869 bool
1870 _TableViewPresenter::OnTouchMoved(const _Control& source, const _TouchInfo& touchInfo)
1871 {
1872         if (__pTableView->IsReorderModeEnabled())
1873         {
1874                 if (__reorderInfo.blockedScroll)
1875                 {
1876                         return true;
1877                 }
1878
1879                 return _ScrollPanelPresenter::OnTouchMoved(source, touchInfo);
1880         }
1881
1882         _TableViewItem* pItem = GetTableViewItemFromControl(source);
1883         if (pItem == null
1884                         || pItem->IsItemEnabled() == false
1885                         || pItem->GetItemType() == TABLE_VIEW_ITEM_TYPE_TITLE
1886                         || pItem->GetItemType() == TABLE_VIEW_ITEM_TYPE_HEADER
1887                         || pItem->GetItemType() == TABLE_VIEW_ITEM_TYPE_FOOTER
1888                         || pItem->IsAnnexOnOffSliding())
1889         {
1890                 return _ScrollPanelPresenter::OnTouchMoved(source, touchInfo);;
1891         }
1892
1893         if (__firstTouchMoved)
1894         {
1895                 FloatPoint prevTouchPosition = GetPreviousTouchPosition();
1896                 FloatPoint currTouchPosition = GetCurrentTouchPosition();
1897                 float moveDistanceX = currTouchPosition.x - prevTouchPosition.x;
1898                 float moveDistanceY = currTouchPosition.y - prevTouchPosition.y;
1899
1900                 if ((pItem->GetContextItem() != null && abs(moveDistanceX) > abs(moveDistanceY * 2)) || pItem->IsContextItem())
1901                 {
1902                         if (!pItem->IsContextItem())
1903                         {
1904                                 pItem->GetItemIndex(__sweptItemTag.groupIndex, __sweptItemTag.itemIndex);
1905                                 __sweptItemPosition = pItem->GetPositionF();
1906
1907                                 pItem->AdjustContextItemBounds();
1908                         }
1909
1910                         __sweepOccured = true;
1911                 }
1912                 else
1913                 {
1914                         ResetSweptItem();
1915                         return _ScrollPanelPresenter::OnTouchMoved(source, touchInfo);
1916                 }
1917         }
1918
1919         __firstTouchMoved = false;
1920
1921         if (__sweepOccured)
1922         {
1923                 FloatPoint prevTouchPosition = GetPreviousTouchPosition();
1924                 FloatPoint currTouchPosition = GetCurrentTouchPosition();
1925
1926                 SweepItem(currTouchPosition.x - prevTouchPosition.x);
1927         }
1928
1929         return true;
1930 }
1931
1932 bool
1933 _TableViewPresenter::OnTouchReleased(const _Control& source, const _TouchInfo& touchInfo)
1934 {
1935         _TableViewItem* pItem = GetTableViewItemFromControl(source);
1936
1937         if (pItem == null
1938                         || pItem->GetItemType() == TABLE_VIEW_ITEM_TYPE_TITLE
1939                         || pItem->GetItemType() == TABLE_VIEW_ITEM_TYPE_HEADER
1940                         || pItem->GetItemType() == TABLE_VIEW_ITEM_TYPE_FOOTER)
1941         {
1942                 return _ScrollPanelPresenter::OnTouchReleased(source, touchInfo);
1943         }
1944
1945         if(__sweepOccured)
1946         {
1947                 if (pItem->IsContextItem())
1948                 {
1949                         pItem = static_cast<_TableViewItem*>(__pListModel->LoadItem(__sweptItemTag.groupIndex, __sweptItemTag.itemIndex));
1950                 }
1951                 _TableViewItem* pContextItem = pItem->GetContextItem();
1952
1953                 // Swept event fire
1954                 if (pContextItem == null && __pTableView->IsSweepEnabled())
1955                 {
1956                         FloatPoint prevPos = _ScrollPanelPresenter::GetPreviousTouchPosition();
1957
1958                         if (prevPos.x > touchInfo.GetCurrentPosition().x)
1959                         {
1960                                 pItem->FireItemSweepEvent(TABLE_VIEW_SWEEP_DIRECTION_LEFT);
1961                         }
1962                         else if (prevPos.x < touchInfo.GetCurrentPosition().x)
1963                         {
1964                                 pItem->FireItemSweepEvent(TABLE_VIEW_SWEEP_DIRECTION_RIGHT);
1965                         }
1966
1967                         ResetSweptItem();
1968                 }
1969                 else if (pContextItem != null)
1970                 {
1971                         AdjustSweptItemPosition(true);
1972                 }
1973         }
1974
1975         return _ScrollPanelPresenter::OnTouchReleased(source, touchInfo);
1976 }
1977
1978 bool
1979 _TableViewPresenter::OnTouchCanceled(const _Control& source, const _TouchInfo& touchInfo)
1980 {
1981         if (__pTableView->IsReorderModeEnabled() && __reorderInfo.itemIndex != -1)
1982         {
1983                 ResetReorderItem(__reorderInfo.groupIndex, __reorderInfo.itemIndex);
1984                 return true;
1985         }
1986
1987         return _ScrollPanelPresenter::OnTouchCanceled(source, touchInfo);
1988 }
1989
1990 bool
1991 _TableViewPresenter::OnFlickGestureDetected(_TouchFlickGestureDetector& gesture)
1992 {
1993         if (__pTableView->IsReorderModeEnabled() && __reorderInfo.itemIndex != -1)
1994         {
1995                 return true;
1996         }
1997
1998         _FlickDirection flickDirection = gesture.GetDirection();
1999
2000         if (flickDirection != _FLICK_DIRECTION_RIGHT && flickDirection != _FLICK_DIRECTION_LEFT)
2001         {
2002                 return _ScrollPanelPresenter::OnFlickGestureDetected(gesture);
2003         }
2004
2005         _Control* gestureControl = gesture.GetControl();
2006
2007         if (gestureControl == null)
2008         {
2009                 return _ScrollPanelPresenter::OnFlickGestureDetected(gesture);
2010         }
2011
2012         _TableViewItem* pItem = GetTableViewItemFromControl(*gestureControl);
2013
2014         if (pItem == null)
2015         {
2016                 return _ScrollPanelPresenter::OnFlickGestureDetected(gesture);
2017         }
2018
2019         if (flickDirection == _FLICK_DIRECTION_RIGHT)
2020         {
2021                 // event fire
2022                 if (pItem->GetContextItem() == null && __pTableView->IsSweepEnabled())
2023                 {
2024                         pItem->FireItemSweepEvent(TABLE_VIEW_SWEEP_DIRECTION_RIGHT);
2025                 }
2026                 else
2027                 {
2028                         if (pItem->GetContextItem() != null)
2029                         {
2030                                 AdjustSweptItemPosition();
2031                         }
2032                 }
2033         }
2034         else if (flickDirection == _FLICK_DIRECTION_LEFT)
2035         {
2036                 // event fire
2037                 if (pItem->GetContextItem() == null && __pTableView->IsSweepEnabled())
2038                 {
2039                         pItem->FireItemSweepEvent(TABLE_VIEW_SWEEP_DIRECTION_LEFT);
2040                 }
2041                 else
2042                 {
2043                         if (pItem->GetContextItem() != null)
2044                         {
2045                                 AdjustSweptItemPosition();
2046                         }
2047                 }
2048         }
2049
2050         return true;
2051 }
2052
2053 bool
2054 _TableViewPresenter::OnFlickGestureCanceled(_TouchFlickGestureDetector& gesture)
2055 {
2056         return _ScrollPanelPresenter::OnFlickGestureCanceled(gesture);
2057 }
2058
2059 bool
2060 _TableViewPresenter::OnPreviewFlickGestureDetected(_TouchFlickGestureDetector& gesture)
2061 {
2062         if (__pTableView->IsReorderModeEnabled() && __reorderInfo.itemIndex != -1)
2063         {
2064                 return true;
2065         }
2066
2067         _FlickDirection flickDirection = gesture.GetDirection();
2068         if (flickDirection != _FLICK_DIRECTION_RIGHT && flickDirection != _FLICK_DIRECTION_LEFT)
2069         {
2070                 return _ScrollPanelPresenter::OnFlickGestureDetected(gesture);
2071         }
2072
2073         return true;
2074 }
2075
2076 void
2077 _TableViewPresenter::OnTimerExpired(Tizen::Base::Runtime::Timer& timer)
2078 {
2079         _ScrollPanelPresenter::OnTimerExpired(timer);
2080
2081         if (&timer == __pReorderScrollTimer)
2082         {
2083                 float distance = 0.0f;
2084
2085                 if (__reorderInfo.isScrollDirectionUp)
2086                 {
2087                         distance = -REORDER_SCROLL_ANIMATION_DISTANCE;
2088                 }
2089                 else
2090                 {
2091                         distance = REORDER_SCROLL_ANIMATION_DISTANCE;
2092                 }
2093
2094                 DragSelectedItem(distance, false);
2095
2096                 distance = ScrollTo(distance + GetScrollPosition());
2097
2098                 StartReorderScrollTimer();
2099         }
2100         else if (&timer == __pFastScrollTimer)
2101         {
2102                 __isFastScrollTimerEnabled = false;
2103
2104                 _FastScroll* pFastScroll = __pTableView->GetFastScrollBar();
2105
2106                 if (pFastScroll != null && !_ScrollPanelPresenter::IsScrollAnimationRunning())
2107                 {
2108                         pFastScroll->SetScrollVisibility(false);
2109                 }
2110         }
2111 }
2112
2113 result
2114 _TableViewPresenter::StartFastScrollTimer(void)
2115 {
2116         result r = E_SUCCESS;
2117
2118         SysTryReturn(NID_UI_CTRL, __pFastScrollTimer != null, E_INVALID_STATE, E_INVALID_STATE, "[E_INVALID_STATE] Timer is not created.");
2119
2120         r = __pFastScrollTimer->Start(FAST_SCROLL_FADE_OUT_DURATION);
2121         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
2122
2123         __isFastScrollTimerEnabled = true;
2124
2125         return r;
2126 }
2127
2128 void
2129 _TableViewPresenter::StopFastScrollTimer(void)
2130 {
2131         result r = E_SUCCESS;
2132
2133         SysTryReturnVoidResult(NID_UI_CTRL, __pFastScrollTimer != null, E_INVALID_STATE, "[E_INVALID_STATE] Timer is invalid.");
2134
2135         r = __pFastScrollTimer->Cancel();
2136         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
2137
2138         __isFastScrollTimerEnabled = false;
2139
2140         return;
2141 }
2142
2143 bool
2144 _TableViewPresenter::IsEmpty(void) const
2145 {
2146         if (__pTableView->GetTableViewStyle() == TABLE_VIEW_STYLE_SIMPLE)
2147         {
2148                 if (GetItemCountAt(0) <= 0)
2149                 {
2150                         return true;
2151                 }
2152         }
2153         else
2154         {
2155                 if (GetGroupCount() <= 0 )
2156                 {
2157                         return true;
2158                 }
2159         }
2160
2161         return false;
2162 }
2163
2164 result
2165 _TableViewPresenter::DrawEmptyTableView(void)
2166 {
2167         return E_SUCCESS;
2168 }
2169
2170 bool
2171 _TableViewPresenter::GetFirstItem(TableViewItemTag& firstItem) const
2172 {
2173         if (IsEmpty())
2174         {
2175                 firstItem.groupIndex = -1;
2176                 firstItem.itemIndex = -1;
2177         }
2178         else
2179         {
2180                 firstItem.groupIndex = 0;
2181                 firstItem.itemIndex = -1;
2182         }
2183
2184         return true;
2185 }
2186
2187 bool
2188 _TableViewPresenter::GetLastItem(TableViewItemTag& lastItem) const
2189 {
2190         if (IsEmpty())
2191         {
2192                 lastItem.groupIndex = -1;
2193                 lastItem.itemIndex = -1;
2194         }
2195         else
2196         {
2197                 lastItem.groupIndex = GetGroupCount() - 1;
2198                 lastItem.itemIndex = GetItemCountAt(lastItem.groupIndex) - 1;
2199         }
2200
2201         return true;
2202 }
2203
2204 result
2205 _TableViewPresenter::GetTopDrawnItem(TableViewItemTag& itemPos) const
2206 {
2207         _TableViewItem* pItem = null;
2208         TableViewItemTag lastItemPos = {-1, -1};
2209         float scrollPosition = 0.0f;
2210
2211         scrollPosition = GetScrollPosition();
2212
2213         __pListModel->GetFirstLoadedItemIndex(itemPos.groupIndex, itemPos.itemIndex);
2214         __pListModel->GetLastLoadedItemIndex(lastItemPos.groupIndex, lastItemPos.itemIndex);
2215
2216         do
2217         {
2218                 pItem = static_cast <_TableViewItem*>(__pListModel->LoadItem(itemPos.groupIndex, itemPos.itemIndex));
2219                 if (pItem == null)
2220                 {
2221                         break;
2222                 }
2223
2224                 FloatRectangle itemBounds = pItem->GetBoundsF();
2225
2226                 if (scrollPosition < (itemBounds.y + itemBounds.height))
2227                 {
2228                         return E_SUCCESS;
2229                 }
2230
2231                 if ((itemPos.itemIndex == lastItemPos.itemIndex) && (itemPos.groupIndex == lastItemPos.groupIndex))
2232                 {
2233                         break;
2234                 }
2235
2236         } while (GetNextItemPosition(itemPos, itemPos) == true);
2237
2238
2239         itemPos.itemIndex = -1;
2240         itemPos.groupIndex = -1;
2241
2242         return E_OUT_OF_RANGE;
2243 }
2244
2245 result
2246 _TableViewPresenter::GetBottomDrawnItem(TableViewItemTag& itemPos) const
2247 {
2248         _TableViewItem* pItem = null;
2249         TableViewItemTag lastItemPos = {-1, -1};
2250
2251         if (IsEmpty())
2252         {
2253                 itemPos.itemIndex = -1;
2254                 itemPos.groupIndex = -1;
2255
2256                 return E_INVALID_STATE;
2257         }
2258
2259         float scrollPosition = GetScrollPosition() + __pTableView->GetBoundsF().height;
2260
2261         __pListModel->GetFirstLoadedItemIndex(itemPos.groupIndex, itemPos.itemIndex);
2262         __pListModel->GetLastLoadedItemIndex(lastItemPos.groupIndex, lastItemPos.itemIndex);
2263
2264         do
2265         {
2266                 static bool onProcessingByProvider = true;
2267                 pItem = static_cast <_TableViewItem*>(__pListModel->LoadItem(itemPos.groupIndex, itemPos.itemIndex));
2268                 onProcessingByProvider = false;
2269                 if (pItem == null)
2270                 {
2271                         break;
2272                 }
2273
2274                 FloatRectangle itemBounds = pItem->GetBoundsF();
2275
2276                 if (itemBounds.y <= scrollPosition && scrollPosition <= (itemBounds.y + itemBounds.height))
2277                 {
2278                         break;
2279                 }
2280
2281                 if ((itemPos.itemIndex == lastItemPos.itemIndex) && (itemPos.groupIndex == lastItemPos.groupIndex))
2282                 {
2283                         break;
2284                 }
2285
2286         } while (GetNextItemPosition(itemPos, itemPos) == true);
2287
2288         return E_SUCCESS;
2289 }
2290
2291 bool
2292 _TableViewPresenter::GetPreviousItemPosition(const TableViewItemTag& currentItemPos, TableViewItemTag& prevItem) const
2293 {
2294         if (IsEmpty())
2295         {
2296                 return false;
2297         }
2298
2299         // check validation of group index
2300         if ((currentItemPos.groupIndex < 0) || (currentItemPos.groupIndex >= __pListModel->GetAllGroupCount()))
2301         {
2302                 return false;
2303         }
2304
2305         // if the current item is the first item
2306         if (currentItemPos.groupIndex == 0 && currentItemPos.itemIndex == -1)
2307         {
2308                 return false;
2309         }
2310
2311         if (currentItemPos.itemIndex == -1)
2312         {
2313                 if (__pListModel->IsGroupExpanded(currentItemPos.groupIndex - 1) == false)
2314                 {
2315                         prevItem.groupIndex = currentItemPos.groupIndex - 1;
2316                         prevItem.itemIndex = -1;
2317
2318                         return true;
2319                 }
2320         }
2321
2322         if (__pListModel->IsGroupExpanded(currentItemPos.groupIndex) == false)
2323         {
2324                 if (currentItemPos.groupIndex == 0 && currentItemPos.itemIndex == -1)
2325                 {
2326                         return false;
2327                 }
2328
2329                 prevItem.groupIndex = currentItemPos.groupIndex - 1;
2330                 prevItem.itemIndex = __pListModel->GetItemCountInGroup(prevItem.groupIndex) - 1;
2331
2332                 return true;
2333         }
2334
2335         if (currentItemPos.itemIndex == -1) // group title item
2336         {
2337                 prevItem.groupIndex = currentItemPos.groupIndex - 1;
2338                 prevItem.itemIndex = __pListModel->GetItemCountInGroup(prevItem.groupIndex) - 1;
2339         }
2340         else
2341         {
2342                 prevItem.groupIndex = currentItemPos.groupIndex;
2343                 prevItem.itemIndex = currentItemPos.itemIndex - 1;
2344         }
2345
2346         return true;
2347 }
2348
2349 bool
2350 _TableViewPresenter::GetNextItemPosition(const TableViewItemTag& currentItem, TableViewItemTag& nextItem) const
2351 {
2352         if (IsEmpty())
2353         {
2354                 return false;
2355         }
2356
2357         int lastGroup = __pListModel->GetAllGroupCount() - 1;
2358         int lastItemInCurrentGroup = __pListModel->GetItemCountInGroup(currentItem.groupIndex) - 1;
2359         int lastItem = __pListModel->GetItemCountInGroup(lastGroup) - 1;
2360
2361         // check validation of group index
2362         if ((currentItem.groupIndex < 0) || (currentItem.groupIndex > lastGroup))
2363         {
2364                 return false;
2365         }
2366
2367         // if the current item is the last item.
2368         if ((currentItem.groupIndex == lastGroup) && (currentItem.itemIndex == lastItem))
2369         {
2370                 return false;
2371         }
2372
2373         if (__pListModel->IsGroupExpanded(currentItem.groupIndex) == false)
2374         {
2375                 if (currentItem.groupIndex == lastGroup)
2376                 {
2377                         return false;
2378                 }
2379
2380                 nextItem.groupIndex = currentItem.groupIndex + 1;
2381                 nextItem.itemIndex = -1;
2382
2383                 return true;
2384         }
2385
2386         if (lastItemInCurrentGroup == currentItem.itemIndex)
2387         {
2388                 nextItem.groupIndex = currentItem.groupIndex + 1;
2389                 nextItem.itemIndex = -1;
2390         }
2391         else
2392         {
2393                 nextItem.groupIndex = currentItem.groupIndex;
2394                 nextItem.itemIndex = currentItem.itemIndex + 1;
2395         }
2396
2397         return true;
2398 }
2399
2400 float
2401 _TableViewPresenter::GetHeightOfAllItems(void) const
2402 {
2403         int groupCount = GetGroupCount();
2404         float totalHeight = 0;
2405
2406         for (int i = 0; i < groupCount; i++)
2407         {
2408                 TableViewItemTag itemTag = {i, -1};
2409
2410                 totalHeight += GetItemHeight(itemTag);
2411
2412                 if (!IsGroupExpanded(i))
2413                 {
2414                         continue;
2415                 }
2416
2417                 int itemCount = GetItemCountAt(i);
2418
2419                 for (int j = 0; j < itemCount; j++)
2420                 {
2421                         itemTag.itemIndex = j;
2422
2423                         totalHeight += GetItemHeight(itemTag);
2424                 }
2425         }
2426
2427         return totalHeight;
2428 }
2429
2430 void
2431 _TableViewPresenter::SetTableViewItemProviderAdaptor(_TableViewItemProviderAdaptor* pProviderAdaptor)
2432 {
2433         __pListModel->RegisterItemProviderAdaptor(pProviderAdaptor);
2434
2435         __pProviderAdaptor = pProviderAdaptor;
2436
2437         if (__pProviderAdaptor != null)
2438         {
2439                 __pProviderAdaptor->SetTableViewPresenter(this);
2440         }
2441 }
2442
2443 _TableViewItemProviderAdaptor*
2444 _TableViewPresenter::GetTableViewItemProviderAdaptor(void) const
2445 {
2446         return __pProviderAdaptor;
2447 }
2448
2449 result
2450 _TableViewPresenter::ExpandGroup(int groupIndex, bool withAnimation)
2451 {
2452         if ((groupIndex < 0) || (groupIndex >= GetGroupCount()))
2453         {
2454                 return E_OUT_OF_RANGE;
2455         }
2456
2457         if (__modelInitialized == false)
2458         {
2459                 return E_INVALID_STATE;
2460         }
2461
2462         if (IsGroupExpanded(groupIndex) == true)
2463         {
2464                 return E_SUCCESS;
2465         }
2466
2467         TableViewItemTag topTag;
2468         GetTopDrawnItem(topTag);
2469
2470         TableViewItemTag bottomTag;
2471         GetBottomDrawnItem(bottomTag);
2472
2473         float screenPosition = GetScrollPosition();
2474
2475         __pListModel->SetGroupExpandState(groupIndex, true);
2476
2477         ResetSweepItem();
2478
2479         float groupTotalHeight = 0.0f;
2480         int itemCount = GetItemCountAt(groupIndex);
2481         _TableViewItem* pItem = null;
2482         for (int i = 0; i < itemCount; i++)
2483         {
2484                 pItem = static_cast<_TableViewItem*>(__pListModel->GetItemFromTemporaryBuffer(groupIndex, i));
2485                 groupTotalHeight += pItem->GetItemHeight();
2486         }
2487
2488         AdjustClientAreaBounds(false, groupTotalHeight);
2489
2490         if (groupIndex < topTag.groupIndex || groupIndex > bottomTag.groupIndex)
2491         {
2492                 _TableViewItem* pItem = FindItem(topTag);
2493                 if (pItem != null)
2494                 {
2495                         FloatRectangle itemBounds = pItem->GetBoundsF();
2496                         itemBounds.y = CalculateItemPositionY(topTag.groupIndex, topTag.itemIndex);
2497                         pItem->SetBounds(itemBounds);
2498                         AttachNextItemsToBottom(topTag);
2499                         if (groupIndex < topTag.groupIndex)
2500                         {
2501                                 ScrollTo(screenPosition + groupTotalHeight);
2502                         }
2503                 }
2504
2505                 int firstLoadedGroupIndex = -1;
2506                 int firstLoadedItemIndex = -1;
2507                 __pListModel->GetFirstLoadedItemIndex(firstLoadedGroupIndex, firstLoadedItemIndex);
2508
2509                 for (int j = firstLoadedGroupIndex; j <= topTag.groupIndex; j++)
2510                 {
2511                         int itemCount = GetItemCountAt(j);
2512
2513                         for (int i = -1; i < itemCount; i++)
2514                         {
2515                                 if (i >= topTag.itemIndex && j == topTag.groupIndex)
2516                                 {
2517                                         break;
2518                                 }
2519
2520                                 UnloadItem(j, i);
2521                         }
2522                 }
2523                 return E_SUCCESS;
2524         }
2525
2526         TableViewItemTag itemTag;
2527         itemTag.groupIndex = groupIndex;
2528         itemTag.itemIndex = -1;
2529
2530         __expandableItemTag.groupIndex = groupIndex;
2531         __expandableItemTag.itemIndex = -1;
2532
2533         if (withAnimation)
2534         {
2535                 _TableViewItem *pItem = FindItem(itemTag);
2536                 if (pItem == null)
2537                 {
2538                         return E_SUCCESS;
2539                 }
2540
2541                 FloatRectangle itemBounds = pItem->GetBoundsF();
2542                 float startPosition = itemBounds.y + itemBounds.height;
2543
2544                 float endPosition = startPosition + groupTotalHeight;
2545                 if (endPosition > screenPosition + __pTableView->GetBoundsF().height)
2546                 {
2547                         endPosition = screenPosition + __pTableView->GetBoundsF().height;
2548                 }
2549
2550                 _VisualElement* pVisualElement = __pTableView->GetVisualElement();
2551                 String animationName(L"EXPAND_GROUP_ANIMATION");
2552
2553                 VisualElementValueAnimation* pAnimation = __pTableView->GetVisualElementValueAnimation(animationName);
2554                 pAnimation->SetStartValue(Variant(startPosition));
2555                 pAnimation->SetEndValue(Variant(endPosition));
2556                 pAnimation->SetDuration(EXPAND_GROUP_ANIMATION_DURATION);
2557                 pVisualElement->AddAnimation(animationName, *pAnimation);
2558         }
2559         else
2560         {
2561                 ExpandGroupAnimationFinished(false);
2562         }
2563
2564         return E_SUCCESS;
2565 }
2566
2567 result
2568 _TableViewPresenter::CollapseGroup(int groupIndex, bool withAnimation)
2569 {
2570         if ((groupIndex < 0) || (groupIndex >= GetGroupCount()))
2571         {
2572                 return E_OUT_OF_RANGE;
2573         }
2574
2575         if (__modelInitialized == false)
2576         {
2577                 return E_INVALID_STATE;
2578         }
2579
2580         if (IsGroupExpanded(groupIndex) == false)
2581         {
2582                 return E_SUCCESS;
2583         }
2584
2585         TableViewItemTag itemTag;
2586         GetTopDrawnItem(itemTag);
2587
2588         TableViewItemTag bottomTag;
2589         GetBottomDrawnItem(bottomTag);
2590         float screenPosition = GetScrollPosition();
2591
2592         __pListModel->SetGroupExpandState(groupIndex, false);
2593
2594         ResetSweepItem();
2595
2596         float groupTotalHeight = 0;
2597         int itemCount = GetItemCountAt(groupIndex);
2598         _TableViewItem* pItem = null;
2599         for (int i = 0; i < itemCount; i++)
2600         {
2601                 pItem = static_cast<_TableViewItem*>(__pListModel->GetItemFromTemporaryBuffer(groupIndex, i));
2602                 groupTotalHeight += pItem->GetItemHeight();
2603         }
2604
2605         if (groupIndex < itemTag.groupIndex || groupIndex > bottomTag.groupIndex)
2606         {
2607                 TableViewItemTag firstLoadedItemTag;
2608                 __pListModel->GetFirstLoadedItemIndex(firstLoadedItemTag.groupIndex, firstLoadedItemTag.itemIndex);
2609
2610                 if (firstLoadedItemTag.groupIndex == groupIndex)
2611                 {
2612                         SetLoadedItemsVisibleInGroup(groupIndex, false);
2613                         firstLoadedItemTag.groupIndex = groupIndex + 1;
2614                         firstLoadedItemTag.itemIndex = -1;
2615                 }
2616
2617                 _TableViewItem* pItem = FindItem(firstLoadedItemTag);
2618                 if (pItem != null)
2619                 {
2620                         FloatRectangle itemBounds = pItem->GetBoundsF();
2621                         itemBounds.y = CalculateItemPositionY(firstLoadedItemTag.groupIndex, firstLoadedItemTag.itemIndex);
2622                         pItem->SetBounds(itemBounds);
2623                         AttachNextItemsToBottom(firstLoadedItemTag);
2624                         if (groupIndex < itemTag.groupIndex)
2625                         {
2626                                 ScrollTo(screenPosition - groupTotalHeight);
2627                         }
2628                 }
2629
2630                 for (int i = 0; i < itemCount; i++)
2631                 {
2632                         UnloadItem(groupIndex, i);
2633                 }
2634                 AdjustClientAreaBounds(false, -groupTotalHeight);
2635
2636                 return E_SUCCESS;
2637         }
2638
2639         if (itemTag.groupIndex < groupIndex)
2640         {
2641                 itemTag.groupIndex = groupIndex;
2642                 itemTag.itemIndex = -1;
2643         }
2644         __expandableItemTag.groupIndex = itemTag.groupIndex;
2645         __expandableItemTag.itemIndex = itemTag.itemIndex;
2646
2647         if(__firstDrawnFlag)
2648         {
2649                 withAnimation = false;
2650         }
2651
2652         if (withAnimation)
2653         {
2654                 _TableViewItem *pItem = FindItem(itemTag);
2655                 if (pItem == null)
2656                 {
2657                         return E_SUCCESS;
2658                 }
2659
2660                 FloatRectangle itemBounds = pItem->GetBoundsF();
2661                 float startPosition = 0;
2662                 if (itemTag.itemIndex == -1)
2663                 {
2664                         startPosition = itemBounds.y + itemBounds.height;
2665                 }
2666                 else
2667                 {
2668                         startPosition = GetScrollPosition();
2669                 }
2670
2671                 if (bottomTag.groupIndex > groupIndex)
2672                 {
2673                         bottomTag.groupIndex = groupIndex+1;
2674                         bottomTag.itemIndex = -1;
2675                 }
2676
2677                 pItem = FindItem(bottomTag);
2678                 if (pItem == null)
2679                 {
2680                         return E_SUCCESS;
2681                 }
2682
2683                 itemBounds = pItem->GetBoundsF();
2684                 float endPosition = itemBounds.y;
2685                 if (bottomTag.groupIndex != groupIndex +1)
2686                 {
2687                         endPosition += itemBounds.height;
2688                 }
2689
2690                 if (endPosition > screenPosition + __pTableView->GetBoundsF().height)
2691                 {
2692                         endPosition = screenPosition + __pTableView->GetBoundsF().height;
2693                 }
2694
2695                 _VisualElement* pVisualElement = __pTableView->GetVisualElement();
2696                 String animationName(L"COLLAPSE_GROUP_ANIMATION");
2697
2698                 VisualElementValueAnimation* pAnimation = __pTableView->GetVisualElementValueAnimation(animationName);
2699                 pAnimation->SetStartValue(Variant(endPosition));
2700                 pAnimation->SetEndValue(Variant(startPosition));
2701                 pAnimation->SetDuration(COLLAPSE_GROUP_ANIMATION_DURATION);
2702                 pVisualElement->AddAnimation(animationName, *pAnimation);
2703         }
2704         else
2705         {
2706                 CollapseGroupAnimationFinished(false);
2707         }
2708
2709         return E_SUCCESS;
2710 }
2711
2712 bool
2713 _TableViewPresenter::IsGroupExpanded(int groupIndex) const
2714 {
2715         return __pListModel->IsGroupExpanded(groupIndex);
2716 }
2717
2718 int
2719 _TableViewPresenter::LoadAllItemsInGroup(int groupIndex, bool downward)
2720 {
2721         int itemCountInGroup = __pListModel->GetItemCountInGroup(groupIndex);
2722         _TableViewItem* pItem = null;
2723
2724         if (downward)
2725         {
2726                 for (int i = 0; i < itemCountInGroup; i++)
2727                 {
2728                         pItem = LoadItem(groupIndex, i);
2729
2730                         if (pItem == null)
2731                         {
2732                                 SysLogException(NID_UI_CTRL, E_SYSTEM, "[E_SYSTEM] Unable to load item.");
2733                         }
2734                 }
2735         }
2736         else
2737         {
2738                 for (int i = itemCountInGroup-1; i >= 0; i--)
2739                 {
2740                         pItem = LoadItem(groupIndex, i);
2741
2742                         if (pItem == null)
2743                         {
2744                                 SysLogException(NID_UI_CTRL, E_SYSTEM, "[E_SYSTEM] Unable to load item.");
2745                         }
2746                 }
2747         }
2748
2749         return itemCountInGroup;
2750 }
2751
2752 void
2753 _TableViewPresenter::SetLoadedItemsVisibleInGroup(int groupIndex, bool visible)
2754 {
2755         int itemCountInGroup = __pListModel->GetItemCountInGroup(groupIndex);
2756         _TableViewItem* pItem = null;
2757         TableViewItemTag itemTag;
2758         itemTag.groupIndex = groupIndex;
2759
2760         int firstLoadedGroupIndex = -1;
2761         int firstLoadedItemIndex = -1;
2762         __pListModel->GetFirstLoadedItemIndex(firstLoadedGroupIndex, firstLoadedItemIndex);
2763
2764         if (firstLoadedGroupIndex > groupIndex)
2765         {
2766                 return;
2767         }
2768
2769         int startIndex = 0;
2770         if (groupIndex == firstLoadedGroupIndex && firstLoadedItemIndex > 0)
2771         {
2772                 startIndex = firstLoadedItemIndex;
2773         }
2774
2775         for (int i = startIndex; i < itemCountInGroup; i++)
2776         {
2777                 itemTag.itemIndex = i;
2778                 pItem = FindItem(itemTag);
2779                 if (pItem == null)
2780                 {
2781                         continue;
2782                 }
2783
2784                 pItem->SetVisibleState(visible);
2785         }
2786 }
2787
2788 TableViewItemTag
2789 _TableViewPresenter::LoadItemsToBeVisible(const TableViewItemTag& from)
2790 {
2791         TableViewItemTag bottomTag = from;
2792         TableViewItemTag current;
2793         TableViewItemTag next;
2794
2795         _TableViewItem *pItem = LoadItem(from.groupIndex, from.itemIndex);
2796
2797         if (pItem == null)
2798         {
2799                 return from;
2800         }
2801
2802         FloatRectangle itemBounds = pItem->GetBoundsF();
2803         float viewHeight = __pTableView->GetBoundsF().height;
2804         float scrollPosition = GetScrollPosition();
2805         float itemPosition = itemBounds.y + itemBounds.height - scrollPosition;
2806
2807         while (viewHeight >= itemPosition)
2808         {
2809                 current.groupIndex = bottomTag.groupIndex;
2810                 current.itemIndex = bottomTag.itemIndex;
2811                 if (!GetNextItemPosition(current, next))
2812                 {
2813                         break;
2814                 }
2815
2816                 pItem = LoadItem(next.groupIndex, next.itemIndex);
2817                 bottomTag.groupIndex = next.groupIndex;
2818                 bottomTag.itemIndex = next.itemIndex;
2819                 itemPosition += pItem->GetBoundsF().height;
2820         }
2821
2822         return bottomTag;
2823 }
2824
2825 void
2826 _TableViewPresenter::AttachNextItemsToBottom(const TableViewItemTag& anchor)
2827 {
2828         TableViewItemTag itemTag = anchor;
2829         TableViewItemTag current;
2830         TableViewItemTag next;
2831
2832         _TableViewItem *pItem = FindItem(itemTag);
2833         if (pItem == null)
2834         {
2835                 return;
2836         }
2837
2838         FloatRectangle itemBounds = pItem->GetBoundsF();
2839         float itemPosition = itemBounds.y + itemBounds.height;
2840
2841         current.groupIndex = itemTag.groupIndex;
2842         current.itemIndex = itemTag.itemIndex;
2843         while (GetNextItemPosition(current, next))
2844         {
2845                 pItem = FindItem(next);
2846                 if (pItem == null)
2847                 {
2848                         current = next;
2849                         continue;
2850                 }
2851
2852                 itemBounds = pItem->GetBoundsF();
2853                 itemBounds.y = itemPosition;
2854                 pItem->SetBounds(itemBounds);
2855                 itemPosition += itemBounds.height;
2856                 current = next;
2857         }
2858 }
2859
2860 bool
2861 _TableViewPresenter::IsAnyItemInGroupLoaded(int groupIndex) const
2862 {
2863         int startGroupIndex = 0;
2864         int endGroupIndex = 0;
2865         int index = 0;
2866
2867         __pListModel->GetFirstLoadedItemIndex(startGroupIndex, index);
2868         __pListModel->GetLastLoadedItemIndex(endGroupIndex, index);
2869
2870         return groupIndex >= startGroupIndex && groupIndex <= endGroupIndex;
2871 }
2872
2873 void
2874 _TableViewPresenter::ScrollToHideNonClientArea(TableViewItemTag& bottomTag)
2875 {
2876         _TableViewItem* pItem = FindItem(bottomTag);
2877         if (pItem == null)
2878         {
2879                 return ;
2880         }
2881
2882         FloatRectangle itemBounds = pItem->GetBoundsF();
2883         float viewHeight = __pTableView->GetBoundsF().height;
2884         float scrollPosition = GetScrollPosition();
2885         float itemBottom = itemBounds.y + itemBounds.height - scrollPosition;
2886
2887         if (itemBottom < viewHeight)
2888         {
2889                 scrollPosition -= viewHeight - itemBottom;
2890                 if (scrollPosition < 0)
2891                 {
2892                         scrollPosition = 0;
2893                 }
2894
2895                 SetScrollPosition(scrollPosition, false);
2896         }
2897 }
2898
2899 void
2900 _TableViewPresenter::AdjustClientAreaBounds(bool reset, float dist)
2901 {
2902         float clientHeight = 0;
2903
2904         if (reset)
2905         {
2906                 __itemTotalHeight = GetHeightOfAllItems();
2907                 clientHeight = __itemTotalHeight;
2908         }
2909         else
2910         {
2911                 __itemTotalHeight = __itemTotalHeight + dist;
2912                 clientHeight = __itemTotalHeight;
2913         }
2914
2915         SetClientAreaHeight(clientHeight);
2916 }
2917
2918 void
2919 _TableViewPresenter::SetClientAreaHeight(float height)
2920 {
2921         FloatRectangle screenBounds = __pTableView->GetBoundsF();
2922         FloatRectangle clientBounds = screenBounds;
2923
2924         clientBounds.height = height;
2925
2926         if (clientBounds.height < screenBounds.height)
2927         {
2928             clientBounds.height = screenBounds.height;
2929         }
2930
2931         SetScrollAreaBounds(clientBounds);
2932
2933         _Scroll* pScroll = __pTableView->GetScrollBar();
2934         if (pScroll != null)
2935         {
2936                 pScroll->SetScrollRange(__pTableView->GetBoundsF().height, clientBounds.height);
2937         }
2938 }
2939
2940 void
2941 _TableViewPresenter::UnloadInvisibleItems(void)
2942 {
2943         float scrollPosition = GetScrollPosition();
2944         TableViewItemTag itemTag;
2945         __pListModel->GetFirstLoadedItemIndex(itemTag.groupIndex, itemTag.itemIndex);
2946
2947         _TableViewItem* pItem = null;
2948         FloatRectangle bounds;
2949
2950         while ((pItem = FindItem(itemTag)) != null)
2951         {
2952                 if (itemTag.itemIndex != -1)
2953                 {
2954                         bounds = pItem->GetBoundsF();
2955                         if (bounds.y + bounds.height < scrollPosition)
2956                         {
2957                                 UnloadItem(itemTag);
2958                         }
2959                         else
2960                         {
2961                                 break;
2962                         }
2963                 }
2964                 __pListModel->GetFirstLoadedItemIndex(itemTag.groupIndex, itemTag.itemIndex);
2965         }
2966
2967         __pListModel->GetLastLoadedItemIndex(itemTag.groupIndex, itemTag.itemIndex);
2968         scrollPosition += __pTableView->GetBoundsF().height;
2969
2970         while ((pItem = FindItem(itemTag)) != null)
2971         {
2972                 if (itemTag.itemIndex != -1)
2973                 {
2974                         bounds = pItem->GetBoundsF();
2975                         if (bounds.y > scrollPosition)
2976                         {
2977                                 UnloadItem(itemTag);
2978                         }
2979                         else
2980                         {
2981                                 break;
2982                         }
2983                 }
2984                 __pListModel->GetLastLoadedItemIndex(itemTag.groupIndex, itemTag.itemIndex);
2985         }
2986
2987 }
2988
2989 float
2990 _TableViewPresenter::ScrollToInternal(float newPosition)
2991 {
2992         if (!IsScrollEnabled())
2993         {
2994                 return 0.0f;
2995         }
2996
2997         if (IsScrollAnimationRunning())
2998         {
2999                 if (__scrollPositionOnFlickStarted > newPosition)
3000                 {
3001                         newPosition += GetScrollAreaBounds().height - __scrollHeightOnFlickStarted;
3002                 }
3003         }
3004
3005         float currentScrollPosition = GetScrollPosition();
3006         float currentscrollAreaHeight = GetScrollAreaBounds().height;
3007         float newScrollPosition = (newPosition < 0) ? 0 : (newPosition > currentscrollAreaHeight ? currentscrollAreaHeight : newPosition);
3008         float newScrollAreaHeight = 0;
3009
3010         if (IsModelUpdating())
3011         {
3012                 currentScrollPosition = GetScrollPositionInternal();
3013         }
3014
3015         if (!__lockLoadItemWithScroll)
3016         {
3017                 LoadItemWithScrollPosition(currentScrollPosition, newScrollPosition);
3018
3019                 if (currentScrollPosition > newScrollPosition)
3020                 {
3021                         newScrollAreaHeight = GetScrollAreaBounds().height;
3022                         newScrollPosition += newScrollAreaHeight - currentscrollAreaHeight;
3023                 }
3024         }
3025
3026         //scroll effect for _ScrollPanel
3027         if (newPosition < 0.0f || newPosition > currentscrollAreaHeight - __pTableView->GetBoundsF().height)
3028         {
3029                 newScrollPosition = newPosition;
3030         }
3031
3032         return _ScrollPanelPresenter::ScrollToInternal(newScrollPosition);
3033 }
3034
3035 void
3036 _TableViewPresenter::LoadItemWithScrollPosition(float previousScrollPosition, float currentScrollPos)
3037 {
3038         ClearLastResult();
3039
3040         TableViewItemTag lastLoadedItemPos = {-1, -1};
3041         TableViewItemTag firstLoadedItemPos = {-1, -1};
3042         __pListModel->GetLastLoadedItemIndex(lastLoadedItemPos.groupIndex, lastLoadedItemPos.itemIndex);
3043         __pListModel->GetFirstLoadedItemIndex(firstLoadedItemPos.groupIndex, firstLoadedItemPos.itemIndex);
3044
3045         if (currentScrollPos > previousScrollPosition && lastLoadedItemPos.groupIndex != -1)
3046         {
3047                 _TableViewItem* pLastItem = FindItem(lastLoadedItemPos);
3048                 if (pLastItem == null)
3049                 {
3050                         return;
3051                 }
3052
3053                 while (pLastItem->GetBoundsF().y <= currentScrollPos + __pTableView->GetBoundsF().height)
3054                 {
3055                         TableViewItemTag nextItemPos = {-1, -1};
3056                         if (GetNextItemPosition(lastLoadedItemPos, nextItemPos))
3057                         {
3058                                 if (nextItemPos.itemIndex == -1)
3059                                 {
3060                                         LoadItem(nextItemPos.groupIndex, nextItemPos.itemIndex);
3061
3062                                         if (!GetNextItemPosition(nextItemPos, nextItemPos))
3063                                         {
3064                                                 break;
3065                                         }
3066                                 }
3067
3068                                 if (nextItemPos.groupIndex != -1)
3069                                 {
3070                                         _TableViewItem* item = LoadItem(nextItemPos.groupIndex, nextItemPos.itemIndex);
3071
3072                                         FloatRectangle scrollAreaBounds = GetScrollAreaBounds();
3073                                         if (item->GetBoundsF().y + item->GetBoundsF().height >= scrollAreaBounds.height)
3074                                         {
3075                                                 AdjustClientAreaBounds(true);
3076                                         }
3077                                 }
3078                         }
3079                         else
3080                         {
3081                                 break;
3082                         }
3083
3084                         lastLoadedItemPos = nextItemPos;
3085                         pLastItem = static_cast<_TableViewItem*>(__pListModel->LoadItem(lastLoadedItemPos.groupIndex, lastLoadedItemPos.itemIndex));
3086                 }
3087         }
3088
3089         if (currentScrollPos < previousScrollPosition && firstLoadedItemPos.groupIndex != -1)
3090         {
3091                 _TableViewItem* pFirstItem = FindItem(firstLoadedItemPos);
3092                 if (pFirstItem == null)
3093                 {
3094                         return;
3095                 }
3096
3097                 float scrollOffsetFromBottom = GetScrollAreaBounds().height - currentScrollPos;
3098
3099                 while (pFirstItem)
3100                 {
3101                         FloatRectangle scrollAreaBounds = GetScrollAreaBounds();
3102                         float itemOffsetFromBottom = scrollAreaBounds.height - (pFirstItem->GetBoundsF().y + pFirstItem->GetBoundsF().height);
3103
3104                         if (scrollOffsetFromBottom < itemOffsetFromBottom)
3105                         {
3106                                 break;
3107                         }
3108
3109                         TableViewItemTag prevItemPos = {-1, -1};
3110                         if (GetPreviousItemPosition(firstLoadedItemPos, prevItemPos))
3111                         {
3112                                 if (prevItemPos.itemIndex == -1)
3113                                 {
3114                                         LoadItem(prevItemPos.groupIndex, prevItemPos.itemIndex);
3115
3116                                         if (!GetPreviousItemPosition(prevItemPos, prevItemPos))
3117                                         {
3118                                                 break;
3119                                         }
3120                                 }
3121
3122                                 if (prevItemPos.groupIndex != -1)
3123                                 {
3124                                         LoadItem(prevItemPos.groupIndex, prevItemPos.itemIndex);
3125                                 }
3126                         }
3127                         else
3128                         {
3129                                 break;
3130                         }
3131
3132                         firstLoadedItemPos = prevItemPos;
3133                         pFirstItem = FindItem(firstLoadedItemPos);
3134                 }
3135         }
3136 }
3137
3138 void
3139 _TableViewPresenter::ScrollToItem(int groupIndex, int itemIndex, TableViewScrollItemAlignment itemAlignment, float shiftingDistance)
3140 {
3141         _VisualElement* pVisualElement = __pTableView->GetVisualElement();
3142         String animationName(L"EXPAND_GROUP_ANIMATION");
3143         VisualElementValueAnimation* pExpandGroupAnimation = dynamic_cast<VisualElementValueAnimation*>(pVisualElement->GetAnimationN(animationName));
3144         if (pExpandGroupAnimation != null)
3145         {
3146                 __scrollToItemTag.groupIndex = groupIndex;
3147                 __scrollToItemTag.itemIndex = itemIndex;
3148                 __scrollToItemTag.itemAlignment = itemAlignment;
3149                 __scrollToItemTag.shiftingDistance = shiftingDistance;
3150                 __scrollToItemTag.startedAnimation = true;
3151                 delete pExpandGroupAnimation;
3152                 return;
3153         }
3154
3155         animationName = L"COLLAPSE_GROUP_ANIMATION";
3156         VisualElementValueAnimation* pCollapseGroupAnimation = dynamic_cast<VisualElementValueAnimation*>(pVisualElement->GetAnimationN(animationName));
3157         if (pCollapseGroupAnimation != null)
3158         {
3159                 __scrollToItemTag.groupIndex = groupIndex;
3160                 __scrollToItemTag.itemIndex = itemIndex;
3161                 __scrollToItemTag.itemAlignment = itemAlignment;
3162                 __scrollToItemTag.shiftingDistance = shiftingDistance;
3163                 __scrollToItemTag.startedAnimation = true;
3164                 delete pCollapseGroupAnimation;
3165                 return;
3166         }
3167
3168         TableViewItemTag itemPos = {groupIndex, itemIndex};
3169
3170         StopAllItemAnimation();
3171         ResetSweepItem();
3172
3173         if (!__pListModel->IsLoadedItem(groupIndex, itemIndex))
3174         {
3175                 ResetItemLayout(itemPos, shiftingDistance);
3176         }
3177
3178         _TableViewItem* pItem = FindItem(itemPos);
3179
3180         if (pItem == null)
3181         {
3182                 return;
3183         }
3184
3185         float scrollPosition = pItem->GetBoundsF().y;
3186
3187         scrollPosition = scrollPosition + shiftingDistance;
3188
3189         SetScrollPosition(scrollPosition, false);
3190
3191         if (itemAlignment == TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_BOTTOM)
3192         {
3193                 SetScrollPosition(scrollPosition - (__pTableView->GetBoundsF().height - pItem->GetBoundsF().height), false);
3194         }
3195 }
3196
3197 result
3198 _TableViewPresenter::ScrollByPixel(float scrollDistance)
3199 {
3200         FadeInScrollBar();
3201         result r = GetLastResult();
3202         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
3203
3204         ResetSweepItem();
3205
3206         ScrollTo(scrollDistance + GetScrollPosition());
3207         r = GetLastResult();
3208         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
3209
3210         RollbackBouncing(true);
3211         r = GetLastResult();
3212         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
3213
3214         FadeOutScrollBar();
3215         r = GetLastResult();
3216         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
3217
3218         return r;
3219 }
3220
3221 void
3222 _TableViewPresenter::SetScrollEnabled(bool enable)
3223 {
3224         __scrolling = enable;
3225 }
3226
3227 bool
3228 _TableViewPresenter::IsScrollEnabled(void) const
3229 {
3230         return __scrolling;
3231 }
3232
3233 bool
3234 _TableViewPresenter::GetFirstDrawnFlag(void) const
3235 {
3236         return __firstDrawnFlag;
3237 }
3238
3239 int
3240 _TableViewPresenter::GetMaxItemCachingSize(void) const
3241 {
3242         return __pListModel->GetMaxCachingSize();
3243 }
3244
3245 void
3246 _TableViewPresenter::ResetSweepItem(void)
3247 {
3248         if (__sweptItemTag.groupIndex != -1 && __sweptItemTag.itemIndex != -1)
3249         {
3250                 ResetSweptItem();
3251         }
3252 }
3253
3254 void
3255 _TableViewPresenter::GetSweepItemIndex(int& groupIndex, int& itemIndex) const
3256 {
3257         groupIndex = __sweptItemTag.groupIndex;
3258         itemIndex = __sweptItemTag.itemIndex;
3259 }
3260
3261 int
3262 _TableViewPresenter::GetPressedItemCount(void)
3263 {
3264         _TableViewItem* pItem = null;
3265         TableViewItemTag itemPos = {-1, -1};
3266         TableViewItemTag lastItemPos = {-1, -1};
3267         int count = 0;
3268
3269         __pListModel->GetFirstLoadedItemIndex(itemPos.groupIndex, itemPos.itemIndex);
3270         __pListModel->GetLastLoadedItemIndex(lastItemPos.groupIndex, lastItemPos.itemIndex);
3271
3272         do
3273         {
3274                 pItem = static_cast <_TableViewItem*>(__pListModel->LoadItem(itemPos.groupIndex, itemPos.itemIndex));
3275                 if (pItem == null)
3276                 {
3277                         continue;
3278                 }
3279
3280                 if (pItem->GetDrawingStatus() == TABLE_VIEW_ITEM_DRAWING_STATUS_PRESSED)
3281                 {
3282                         count++;
3283                 }
3284
3285                 if ((itemPos.itemIndex == lastItemPos.itemIndex) && (itemPos.groupIndex == lastItemPos.groupIndex))
3286                 {
3287                         break;
3288                 }
3289         } while (GetNextItemPosition(itemPos, itemPos) == true);
3290
3291         return count;
3292 }
3293
3294 void
3295 _TableViewPresenter::BlockAnimationCallback(bool blocked)
3296 {
3297         __isAnimationCallbackBlocked = blocked;
3298 }
3299
3300 float
3301 _TableViewPresenter::CalculateItemPositionY(int groupIndex, int itemIndex)
3302 {
3303         TableViewItemTag itemPos = {-1, -1};
3304         TableViewItemTag currentItemPos = {-1, -1};
3305         float positionY = 0.0f;
3306
3307         GetFirstItem(itemPos);
3308
3309         if (itemPos.groupIndex == -1 && itemPos.itemIndex == -1)
3310         {
3311                 return 0;
3312         }
3313
3314         if (__pProviderAdaptor == null)
3315         {
3316                 return -1;
3317         }
3318
3319         positionY = GetTopMargin();
3320
3321         while ((itemPos.groupIndex < groupIndex) || ((itemPos.groupIndex == groupIndex) && (itemPos.itemIndex < itemIndex)))
3322         {
3323                 currentItemPos = itemPos;
3324
3325                 float itemHeight = GetItemHeight(itemPos);
3326
3327                 positionY += itemHeight;
3328
3329                 if (!GetNextItemPosition(currentItemPos, itemPos))
3330                 {
3331                         break;
3332                 }
3333         }
3334
3335         return positionY;
3336 }
3337
3338 void
3339 _TableViewPresenter::FadeInScrollBar(void)
3340 {
3341         TableViewScrollBarStyle scrollStyle = __pTableView->GetScrollStyle();
3342
3343         if (scrollStyle == TABLE_VIEW_SCROLL_BAR_STYLE_NONE)
3344         {
3345                 _Scroll* pScroll = __pTableView->GetScrollBar();
3346
3347                 if (pScroll != null)
3348                 {
3349                         pScroll->SetVisibleState(false);
3350                 }
3351         }
3352         else if (scrollStyle == TABLE_VIEW_SCROLL_BAR_STYLE_FAST_SCROLL)
3353         {
3354                 _Scroll* pScroll = __pTableView->GetScrollBar();
3355
3356                 if (pScroll != null)
3357                 {
3358                         pScroll->SetVisibleState(false);
3359                 }
3360
3361                 _FastScroll* pFastScroll = __pTableView->GetFastScrollBar();
3362
3363                 if (pFastScroll != null)
3364                 {
3365                         pFastScroll->SetScrollVisibility(true);
3366                 }
3367         }
3368         else
3369         {
3370                 _ScrollPanelPresenter::FadeInScrollBar();
3371         }
3372 }
3373
3374 void
3375 _TableViewPresenter::FadeOutScrollBar(void)
3376 {
3377         TableViewScrollBarStyle scrollStyle = __pTableView->GetScrollStyle();
3378         if (scrollStyle == TABLE_VIEW_SCROLL_BAR_STYLE_FAST_SCROLL)
3379         {
3380                 StopFastScrollTimer();
3381
3382                 if (!_ScrollPanelPresenter::IsScrollAnimationRunning())
3383                 {
3384                         StartFastScrollTimer();
3385                 }
3386         }
3387         else if (scrollStyle == TABLE_VIEW_SCROLL_BAR_STYLE_FIXED)
3388         {
3389                 _Scroll* pScroll = __pTableView->GetScrollBar();
3390
3391                 if (pScroll != null)
3392                 {
3393                         pScroll->SetScrollingEffectVisibility(false);
3394                 }
3395         }
3396         else
3397         {
3398                 _ScrollPanelPresenter::FadeOutScrollBar();
3399         }
3400 }
3401
3402 void
3403 _TableViewPresenter::SweepItem(float x)
3404 {
3405         if (!_FloatCompare(x,  0.0f))
3406         {
3407                 _TableViewItem* pItem = static_cast<_TableViewItem*>(__pListModel->LoadItem(__sweptItemTag.groupIndex, __sweptItemTag.itemIndex));
3408
3409                 if (pItem != null)
3410                 {
3411                         _TableViewItem* pContextItem  = pItem->GetContextItem();
3412
3413                         if (pContextItem != null)
3414                         {
3415                                 float currentPosition = __sweptItemPosition.x + x;
3416                                 float sweepDistance = __pTableView->GetBoundsF().width;
3417                                 float sweepMargin = 0.0f;
3418                                 float contextItemWidth = pItem->GetBoundsF().width;
3419                                 bool activated = pItem->IsContextItemActivated();
3420                                 bool needToFireEvent = false;
3421
3422                                 GET_SHAPE_CONFIG(TABLEVIEW::CONTEXTITEM_RIGHT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, sweepMargin);
3423
3424                                 if (currentPosition >= (sweepDistance - sweepMargin))
3425                                 {
3426                                         currentPosition = (sweepDistance - sweepMargin);
3427                                         needToFireEvent = !activated;
3428                                 }
3429                                 else if (currentPosition <= __leftMargin)
3430                                 {
3431                                         currentPosition = __leftMargin;
3432                                         needToFireEvent = activated;
3433                                 }
3434
3435                                 __sweptItemPosition.x = currentPosition;
3436
3437                                 // Set TableViewItem bounds
3438                                 pItem->SetPosition(__sweptItemPosition);
3439
3440                                 // Set TableViewContextItem bounds
3441                                 if (!__pTableView->IsAncestorOf(*pContextItem))
3442                                 {
3443                                         pContextItem->SetDrawingProperty(__pItemDrawingProperty);
3444                                         __pTableView->InsertChildToBottom(*pContextItem);
3445                                         __pTableView->UpdateLayout();
3446                                 }
3447
3448                                 contextItemWidth = ((contextItemWidth >  (__sweptItemPosition.x - __leftMargin)) ? (__sweptItemPosition.x - __leftMargin) : contextItemWidth);
3449
3450                                 pContextItem->ExposeContextItem(FloatRectangle(__leftMargin, __sweptItemPosition.y, contextItemWidth, pContextItem->GetSizeF().height), pItem->GetSize().width);
3451
3452                                 if (needToFireEvent)
3453                                 {
3454                                         PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_SLIDER_SWEEP);
3455
3456                                         activated = !activated; // ContextItem Activation State Changed
3457
3458                                         __pTableView->FireTableViewContextItemActivationEvent(__sweptItemTag.groupIndex, __sweptItemTag.itemIndex, pContextItem, activated);
3459                                         pItem->SetContextItemActivation(activated);
3460
3461                                         if (!activated)
3462                                         {
3463                                                 ResetSweepItem();
3464                                         }
3465                                 }
3466                         }
3467                 }
3468         }
3469 }
3470
3471 void
3472 _TableViewPresenter::ResetSweptItem(void)
3473 {
3474         _TableViewItem* pItem = static_cast<_TableViewItem*>(__pListModel->LoadItem(__sweptItemTag.groupIndex, __sweptItemTag.itemIndex));
3475
3476         if (pItem != null)
3477         {
3478                 _VisualElement* pVisualElement = __pTableView->GetVisualElement();
3479
3480                 if (pVisualElement != null)
3481                 {
3482                         String animationName(L"SWEEP_ITEM_ANIMATION");
3483                         VisualElementAnimation* pContextItemAnimation = pVisualElement->GetAnimationN(animationName);
3484                         if (pContextItemAnimation != null)
3485                         {
3486                                 pVisualElement->RemoveAnimation(animationName);
3487
3488                                 delete pContextItemAnimation;
3489                         }
3490                 }
3491
3492                 pItem->SetPosition(FloatPoint(__leftMargin, __sweptItemPosition.y));
3493
3494                 _TableViewItem* pContextItem = pItem->GetContextItem();
3495                 if (pContextItem != null)
3496                 {
3497                         if (__pTableView->IsAncestorOf(*pContextItem))
3498                         {
3499                                 __pTableView->DetachChild(*pContextItem);
3500                         }
3501
3502                         if (pItem->IsContextItemActivated())
3503                         {
3504                                 __pTableView->FireTableViewContextItemActivationEvent(__sweptItemTag.groupIndex, __sweptItemTag.itemIndex, pContextItem, false);
3505                                 pItem->SetContextItemActivation(false);
3506                         }
3507                 }
3508         }
3509
3510         __sweptItemTag.itemIndex = -1;
3511         __sweptItemTag.groupIndex = -1;
3512
3513         __sweptItemPosition.SetPosition(-1.0f, -1.0f);
3514         __sweepOccured = false;
3515 }
3516
3517 void
3518 _TableViewPresenter::AdjustSweptItemPosition(bool withAnimation)
3519 {
3520         float itemWidth = __pTableView->GetBoundsF().width;
3521         float sweepDistance = 0.0f;
3522
3523         if (_FloatCompare(__sweptItemPosition.x, __leftMargin))
3524         {
3525                 ResetSweptItem();
3526                 return;
3527         }
3528
3529         float sweepMargin = 0.0f;
3530         GET_SHAPE_CONFIG(TABLEVIEW::CONTEXTITEM_RIGHT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, sweepMargin);
3531
3532         if (__sweptItemPosition.x > (itemWidth - sweepMargin) / 2)
3533         {
3534                 sweepDistance = itemWidth - __sweptItemPosition.x;
3535         }
3536         else
3537         {
3538                 sweepDistance = -__sweptItemPosition.x;
3539         }
3540
3541         if (!withAnimation)
3542         {
3543                 SweepItem(sweepDistance);
3544         }
3545         else
3546         {
3547                 _TableViewItem* pItem = static_cast<_TableViewItem*>(__pListModel->LoadItem(__sweptItemTag.groupIndex, __sweptItemTag.itemIndex));
3548
3549                 if (pItem != null)
3550                 {
3551                         _VisualElement* pVisualElement = __pTableView->GetVisualElement();
3552
3553                         if (pVisualElement != null)
3554                         {
3555                                 String animationName(L"SWEEP_ITEM_ANIMATION");
3556                                 float startValue = __sweptItemPosition.x;
3557                                 float endValue = 0.0f;
3558
3559                                 if(sweepDistance > 0)
3560                                 {
3561                                         endValue = itemWidth - sweepMargin;
3562                                 }
3563                                 else
3564                                 {
3565                                         if(_FloatCompare(itemWidth, __sweptItemPosition.x))
3566                                         {
3567                                                 endValue = itemWidth - sweepMargin;
3568                                         }
3569                                         else
3570                                         {
3571                                                 endValue = __leftMargin;
3572                                         }
3573                                 }
3574
3575                                 pVisualElement->SetImplicitAnimationEnabled(false);
3576
3577                                 VisualElementValueAnimation* pAnimation = __pTableView->GetVisualElementValueAnimation(animationName);
3578                                 pAnimation->SetStartValue(Variant(startValue));
3579                                 pAnimation->SetEndValue(Variant(endValue));
3580                                 pAnimation->SetDuration(SWEEP_ITEM_ANIMATION_DURATION);
3581                                 pVisualElement->AddAnimation(animationName, *pAnimation);
3582                         }
3583                 }
3584         }
3585 }
3586
3587 void
3588 _TableViewPresenter::AdjustLoadedItemWidth(void)
3589 {
3590         TableViewItemTag lastLoadedItemPos = {-1, -1};
3591         TableViewItemTag firstLoadedItemPos = {-1, -1};
3592         __pListModel->GetLastLoadedItemIndex(lastLoadedItemPos.groupIndex, lastLoadedItemPos.itemIndex);
3593         __pListModel->GetFirstLoadedItemIndex(firstLoadedItemPos.groupIndex, firstLoadedItemPos.itemIndex);
3594
3595         do
3596         {
3597                 _TableViewItem* pItem = FindItem(firstLoadedItemPos);
3598
3599                 if (pItem == null)
3600                 {
3601                         continue;
3602                 }
3603
3604                 FloatDimension itemSize = pItem->GetSizeF();
3605                 itemSize.width = __pProviderAdaptor->GetListWidth();
3606
3607                 pItem->SetItemChanged(true);
3608                 pItem->SetSize(itemSize);
3609
3610                 if ((firstLoadedItemPos.itemIndex == lastLoadedItemPos.itemIndex) && (firstLoadedItemPos.groupIndex == lastLoadedItemPos.groupIndex))
3611                 {
3612                         break;
3613                 }
3614         } while (GetNextItemPosition(firstLoadedItemPos, firstLoadedItemPos));
3615 }
3616
3617 result
3618 _TableViewPresenter::OpenContextItem(int groupIndex, int itemIndex)
3619 {
3620         SysTryReturn(NID_UI_CTRL, groupIndex >= 0 && groupIndex < GetGroupCount(), E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[E_INVALID_ARG] Invalid group index.");
3621
3622         TableViewItemTag itemTag = {groupIndex, itemIndex};
3623         _TableViewItem* pItem = FindItem(itemTag);
3624
3625         SysTryReturn(NID_UI_CTRL, pItem != null, E_INVALID_OPERATION, E_INVALID_OPERATION, "[E_INVALID_OPERATION] Item was not loaded.");
3626         SysTryReturn(NID_UI_CTRL, pItem->GetContextItem() != null, E_INVALID_OPERATION, E_INVALID_OPERATION, "[E_INVALID_OPERATION] ContextItem is not set to the item.");
3627         SysTryReturn(NID_UI_CTRL,__sweptItemTag.groupIndex != groupIndex || __sweptItemTag.itemIndex != itemIndex, E_INVALID_OPERATION, E_INVALID_OPERATION, "[E_INVALID_OPERATION] ContextItem already opened.");
3628
3629         ResetSweepItem();
3630
3631         __sweptItemTag.groupIndex = groupIndex;
3632         __sweptItemTag.itemIndex = itemIndex;
3633         __sweptItemPosition = pItem->GetPositionF();
3634
3635         pItem->AdjustContextItemBounds();
3636         __sweepOccured = true;
3637
3638         _VisualElement* pVisualElement = __pTableView->GetVisualElement();
3639
3640         if (pVisualElement != null)
3641         {
3642                 float itemWidth = __pTableView->GetBoundsF().width;
3643                 float sweepMargin = 0.0f;
3644                 GET_SHAPE_CONFIG(TABLEVIEW::CONTEXTITEM_RIGHT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, sweepMargin);
3645
3646                 String animationName(L"SWEEP_ITEM_ANIMATION");
3647                 float startValue = __sweptItemPosition.x;
3648                 float endValue = itemWidth - sweepMargin;
3649
3650                 pVisualElement->SetImplicitAnimationEnabled(false);
3651
3652                 VisualElementValueAnimation* pAnimation = __pTableView->GetVisualElementValueAnimation(animationName);
3653                 pAnimation->SetStartValue(Variant(startValue));
3654                 pAnimation->SetEndValue(Variant(endValue));
3655                 pAnimation->SetDuration(SWEEP_ITEM_ANIMATION_DURATION);
3656                 pVisualElement->AddAnimation(animationName, *pAnimation);
3657         }
3658
3659         return E_SUCCESS;
3660 }
3661
3662 result
3663 _TableViewPresenter::CloseContextItem(int groupIndex, int itemIndex)
3664 {
3665         SysTryReturn(NID_UI_CTRL, groupIndex >= 0 && groupIndex < GetGroupCount(), E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[E_INVALID_ARG] Invalid group index.");
3666
3667         TableViewItemTag itemTag = {groupIndex, itemIndex};
3668         _TableViewItem* pItem = FindItem(itemTag);
3669
3670         SysTryReturn(NID_UI_CTRL, pItem != null, E_INVALID_OPERATION, E_INVALID_OPERATION, "[E_INVALID_OPERATION] Item was not loaded.");
3671         SysTryReturn(NID_UI_CTRL, pItem->GetContextItem() != null, E_INVALID_OPERATION, E_INVALID_OPERATION, "[E_INVALID_OPERATION] ContextItem is not set to the item.");
3672         SysTryReturn(NID_UI_CTRL, __sweptItemTag.groupIndex == groupIndex && __sweptItemTag.itemIndex == itemIndex, E_INVALID_OPERATION, E_INVALID_OPERATION, "[E_INVALID_OPERATION] ContextItem was not opened.");
3673
3674         ResetSweepItem();
3675
3676         return E_SUCCESS;
3677 }
3678
3679 bool
3680 _TableViewPresenter::IsContextItemOpened(int groupIndex, int itemIndex) const
3681 {
3682         SysTryReturn(NID_UI_CTRL, groupIndex >= 0 && groupIndex < GetGroupCount(), false, E_OUT_OF_RANGE, "[E_INVALID_ARG] Invalid group index.");
3683
3684         if ( __sweptItemTag.groupIndex == -1 && __sweptItemTag.itemIndex == -1)
3685         {
3686                 return false;
3687         }
3688
3689         if (__sweptItemTag.groupIndex == groupIndex && __sweptItemTag.itemIndex == itemIndex)
3690         {
3691                 return true;
3692         }
3693
3694         return false;
3695 }
3696
3697 result
3698 _TableViewPresenter::SetSectionHeaderTextHorizontalAlignment(int sectionIndex, HorizontalAlignment alignment)
3699 {
3700         SysTryReturn(NID_UI_CTRL, __pTableView->GetTableViewStyle() == TABLE_VIEW_STYLE_SECTION, E_INVALID_OPERATION, E_INVALID_OPERATION, "[E_INVALID_OPERATION] The style of TableView is TABLE_VIEW_STYLE_SECTION");
3701         SysTryReturn(NID_UI_CTRL, HasSectionHeader(sectionIndex), E_INVALID_OPERATION, E_INVALID_OPERATION, "[E_INVALID_OPERATION] Header is not set to the section.");
3702         SysTryReturn(NID_UI_CTRL, sectionIndex >= 0 && sectionIndex < GetGroupCount(), E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[E_INVALID_ARG] Invalid section index.");
3703
3704         _TableViewSectionStringAlignment newAlignment;
3705
3706         __sectionAlignmentList.GetAt(sectionIndex, newAlignment);
3707         newAlignment.headerHorizontalAlignment = alignment;
3708         __sectionAlignmentList.SetAt(newAlignment, sectionIndex);
3709
3710         TableViewItemTag itemTag = {sectionIndex, -1};
3711         _TableViewItem* pItem = FindItem(itemTag);
3712
3713         if (pItem != null)
3714         {
3715                 pItem->SetSectionHeaderFooterAlignment(alignment);
3716         }
3717
3718         return E_SUCCESS;
3719 }
3720
3721 HorizontalAlignment
3722 _TableViewPresenter::GetSectionHeaderTextHorizontalAlignment(int sectionIndex) const
3723 {
3724         SysTryReturn(NID_UI_CTRL, __pTableView->GetTableViewStyle() == TABLE_VIEW_STYLE_SECTION, ALIGNMENT_LEFT, E_INVALID_OPERATION, "[E_INVALID_OPERATION] The style of TableView is TABLE_VIEW_STYLE_SECTION");
3725         SysTryReturn(NID_UI_CTRL, HasSectionHeader(sectionIndex), ALIGNMENT_LEFT, E_INVALID_OPERATION, "[E_INVALID_OPERATION] Header is not set to the section.");
3726         SysTryReturn(NID_UI_CTRL, sectionIndex >= 0 && sectionIndex < GetGroupCount(), ALIGNMENT_LEFT, E_OUT_OF_RANGE, "[E_INVALID_ARG] Invalid section index.");
3727
3728         _TableViewSectionStringAlignment alignment;
3729         __sectionAlignmentList.GetAt(sectionIndex, alignment);
3730
3731         return alignment.headerHorizontalAlignment;
3732 }
3733
3734 result
3735 _TableViewPresenter::SetSectionFooterTextHorizontalAlignment(int sectionIndex, HorizontalAlignment alignment)
3736 {
3737         SysTryReturn(NID_UI_CTRL, __pTableView->GetTableViewStyle() == TABLE_VIEW_STYLE_SECTION, E_INVALID_OPERATION, E_INVALID_OPERATION, "[E_INVALID_OPERATION] The style of TableView is TABLE_VIEW_STYLE_SECTION");
3738         SysTryReturn(NID_UI_CTRL, HasSectionFooter(sectionIndex), E_INVALID_OPERATION, E_INVALID_OPERATION, "[E_INVALID_OPERATION] Footer is not set to the section.");
3739         SysTryReturn(NID_UI_CTRL, sectionIndex >= 0 && sectionIndex < GetGroupCount(), E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[E_INVALID_ARG] Invalid section index.");
3740
3741         _TableViewSectionStringAlignment newAlignment;
3742
3743         __sectionAlignmentList.GetAt(sectionIndex, newAlignment);
3744         newAlignment.footerHorizontalAlignment= alignment;
3745         __sectionAlignmentList.SetAt(newAlignment, sectionIndex);
3746
3747         TableViewItemTag itemTag = {sectionIndex, GetItemCountAt(sectionIndex) - 1};
3748         _TableViewItem* pItem = FindItem(itemTag);
3749
3750         if (pItem != null)
3751         {
3752                 pItem->SetSectionHeaderFooterAlignment(alignment);
3753         }
3754
3755         return E_SUCCESS;
3756 }
3757
3758 HorizontalAlignment
3759 _TableViewPresenter::GetSectionFooterTextHorizontalAlignment(int sectionIndex) const
3760 {
3761         SysTryReturn(NID_UI_CTRL, __pTableView->GetTableViewStyle() == TABLE_VIEW_STYLE_SECTION, ALIGNMENT_RIGHT, E_INVALID_OPERATION, "[E_INVALID_OPERATION] The style of TableView is TABLE_VIEW_STYLE_SECTION");
3762         SysTryReturn(NID_UI_CTRL, HasSectionFooter(sectionIndex), ALIGNMENT_RIGHT, E_INVALID_OPERATION, "[E_INVALID_OPERATION] Footer is not set to the section.");
3763         SysTryReturn(NID_UI_CTRL, sectionIndex >= 0 && sectionIndex < GetGroupCount(), ALIGNMENT_RIGHT, E_OUT_OF_RANGE, "[E_INVALID_ARG] Invalid section index.");
3764
3765         _TableViewSectionStringAlignment alignment;
3766         __sectionAlignmentList.GetAt(sectionIndex, alignment);
3767
3768         return alignment.footerHorizontalAlignment;
3769 }
3770
3771 bool
3772 _TableViewPresenter::IsValidDrawnItem(int groupIndex, int itemIndex)
3773 {
3774         TableViewItemTag currentItemTag = {groupIndex, itemIndex};
3775         TableViewItemTag itemTag = {-1, -1};
3776
3777         if (GetNextItemPosition(currentItemTag, itemTag))
3778         {
3779                 if (__pListModel->IsLoadedItem(itemTag.groupIndex, itemTag.itemIndex))
3780                 {
3781                         return true;
3782                 }
3783         }
3784
3785         if (GetPreviousItemPosition(currentItemTag, itemTag))
3786         {
3787                 if (__pListModel->IsLoadedItem(itemTag.groupIndex, itemTag.itemIndex))
3788                 {
3789                         return true;
3790                 }
3791         }
3792
3793         return false;
3794 }
3795
3796 void
3797 _TableViewPresenter::StopAllItemAnimation(void)
3798 {
3799         TableViewItemTag currentItemTag = {-1, -1};
3800         TableViewItemTag lastItemTag = {-1, -1};
3801
3802         __pListModel->GetFirstLoadedItemIndex(currentItemTag.groupIndex, currentItemTag.itemIndex);
3803         __pListModel->GetLastLoadedItemIndex(lastItemTag.groupIndex, lastItemTag.itemIndex);
3804
3805         do
3806         {
3807                 _TableViewItem *pItem = FindItem(currentItemTag);
3808                 if (pItem != null)
3809                 {
3810                         pItem->StopAllAnimation();
3811                 }
3812
3813                 if (currentItemTag.groupIndex == lastItemTag.groupIndex && currentItemTag.itemIndex == lastItemTag.itemIndex)
3814                 {
3815                         break;
3816                 }
3817
3818         }while (GetNextItemPosition(currentItemTag, currentItemTag));
3819 }
3820
3821 bool
3822 _TableViewPresenter::GetTableViewItemPosition(_TableViewItem& item, TableViewItemTag& itemTag)
3823 {
3824         TableViewItemTag lastLoadedItemPos = {-1, -1};
3825         TableViewItemTag firstLoadedItemPos = {-1, -1};
3826         __pListModel->GetLastLoadedItemIndex(lastLoadedItemPos.groupIndex, lastLoadedItemPos.itemIndex);
3827         __pListModel->GetFirstLoadedItemIndex(firstLoadedItemPos.groupIndex, firstLoadedItemPos.itemIndex);
3828
3829         _TableViewItem* pCurrentItem = null;
3830         do
3831         {
3832                 pCurrentItem = static_cast<_TableViewItem*>(__pListModel->LoadItem(firstLoadedItemPos.groupIndex, firstLoadedItemPos.itemIndex));
3833                 if (pCurrentItem == &item)
3834                 {
3835                         itemTag.groupIndex = firstLoadedItemPos.groupIndex;
3836                         itemTag.itemIndex = firstLoadedItemPos.itemIndex;
3837                         return true;
3838                 }
3839
3840                 if ((firstLoadedItemPos.itemIndex == lastLoadedItemPos.itemIndex) && (firstLoadedItemPos.groupIndex == lastLoadedItemPos.groupIndex))
3841                 {
3842                         break;
3843                 }
3844         } while (GetNextItemPosition(firstLoadedItemPos, firstLoadedItemPos));
3845
3846         return false;
3847 }
3848
3849 float
3850 _TableViewPresenter::GetItemHeight(TableViewItemTag itemTag) const
3851 {
3852         float itemHeight = 0.0f;
3853
3854         if (__pTableView->GetTableViewStyle() == TABLE_VIEW_STYLE_SECTION && itemTag.itemIndex != -1)
3855         {
3856                 if (HasSectionFooter(itemTag.groupIndex))
3857                 {
3858                         if (itemTag.itemIndex == GetItemCountAt(itemTag.groupIndex) - 1)
3859                         {
3860                                 GET_SHAPE_CONFIG(TABLEVIEW::GROUPITEM_DEFAULT_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, itemHeight);
3861                                 return itemHeight;
3862                         }
3863                 }
3864         }
3865
3866         if (__pProviderAdaptor == null)
3867         {
3868                 return -1;
3869         }
3870
3871         int startIndex = 0;
3872         for (int i = 0; i < itemTag.groupIndex; i++)
3873         {
3874                 int itemCount = GetItemCountAt(i);
3875
3876                 startIndex = startIndex + itemCount + 1;
3877         }
3878
3879         itemTag.itemIndex++;
3880         itemTag.itemIndex = startIndex + itemTag.itemIndex;
3881
3882         __itemHeightList.GetAt(itemTag.itemIndex, itemHeight);
3883
3884         return itemHeight;
3885 }
3886
3887 float
3888 _TableViewPresenter::SetItemHeight(TableViewItemTag itemTag, float height)
3889 {
3890         int startIndex = 0;
3891
3892         for (int i = 0; i < itemTag.groupIndex; i++)
3893         {
3894                 int itemCount = GetItemCountAt(i);
3895
3896                 startIndex = startIndex + itemCount + 1;
3897         }
3898
3899         itemTag.itemIndex++;
3900         itemTag.itemIndex = startIndex + itemTag.itemIndex;
3901
3902         float oldHeight = 0.0f;
3903         __itemHeightList.GetAt(itemTag.itemIndex, oldHeight);
3904         __itemHeightList.SetAt(height, itemTag.itemIndex);
3905
3906         return oldHeight;
3907 }
3908
3909
3910 result
3911 _TableViewPresenter::SetReorderMode(bool enabled)
3912 {
3913         ResetSweepItem();
3914
3915         __reorderInfo.itemIndex = -1;
3916         __reorderInfo.groupIndex = -1;
3917
3918         _TableViewItem* pItem = null;
3919         TableViewItemTag itemPos = {-1, -1};
3920         TableViewItemTag lastItemPos = {-1, -1};
3921
3922         __pListModel->GetFirstLoadedItemIndex(itemPos.groupIndex, itemPos.itemIndex);
3923         __pListModel->GetLastLoadedItemIndex(lastItemPos.groupIndex, lastItemPos.itemIndex);
3924
3925         do
3926         {
3927                 pItem = FindItem(itemPos);
3928
3929                 if (pItem != null)
3930                 {
3931                         pItem->SetReorderMode(enabled);
3932
3933                         if (enabled && itemPos.itemIndex != -1)
3934                         {
3935                                 if (pItem->GetDrawingStatus() == TABLE_VIEW_ITEM_DRAWING_STATUS_PRESSED)
3936                                 {
3937                                         if (SelectReorderItem(itemPos.groupIndex, itemPos.itemIndex, true))
3938                                         {
3939                                                 FloatPoint itemPosition = pItem->GetPositionF();
3940                                                 FloatPoint touchPosition = pItem->GetLastTouchPressedPositionF();
3941
3942                                                 __reorderInfo.touchPressedPositionY = itemPosition.y + touchPosition.y - GetScrollPosition();
3943                                                 __reorderInfo.blockedTouchReleaseState = true;
3944                                         }
3945                                 }
3946                         }
3947                 }
3948
3949                 if ((itemPos.itemIndex == lastItemPos.itemIndex) && (itemPos.groupIndex == lastItemPos.groupIndex))
3950                 {
3951                         break;
3952                 }
3953
3954         } while (GetNextItemPosition(itemPos, itemPos) == true);
3955
3956         return E_SUCCESS;
3957 }
3958
3959 bool
3960 _TableViewPresenter::SelectReorderItem(int groupIndex, int itemIndex, bool directSelection)
3961 {
3962         if (itemIndex == -1 || (!directSelection && GetPressedItemCount() > 0))
3963         {
3964                 return false;
3965         }
3966
3967         TableViewItemTag itemPos = {groupIndex, itemIndex};
3968         _TableViewItem* pItem = FindItem(itemPos);
3969
3970         if (pItem == null)
3971         {
3972                 return false;
3973         }
3974
3975         pItem->SetDrawingStatus(TABLE_VIEW_ITEM_DRAWING_STATUS_PRESSED);
3976         pItem->SetItemChanged(true);
3977         pItem->Invalidate();
3978
3979         __reorderInfo.blockedScroll = false;
3980         __reorderInfo.itemBounds = pItem->GetBoundsF();
3981         __reorderInfo.itemIndex = itemIndex;
3982         __reorderInfo.groupIndex = groupIndex;
3983         __reorderInfo.originGroupIndex = groupIndex;
3984         __reorderInfo.originItemIndex = itemIndex;
3985         __reorderInfo.itemBasisPositionY = __reorderInfo.itemBounds.y;
3986
3987         Tizen::System::SystemTime::GetTicks(__reorderInfo.touchPressedTick);
3988
3989         pItem->GetVisualElement()->SetZOrder(null, true);
3990
3991         if (GetScrollAreaBounds().height < __pTableView->GetBoundsF().height)
3992         {
3993                 float itemHeight = pItem->GetBoundsF().height;
3994
3995                 __pListModel->GetLastLoadedItemIndex(itemPos.groupIndex, itemPos.itemIndex);
3996
3997                 pItem = FindItem(itemPos);
3998
3999                 if (pItem != null)
4000                 {
4001                         FloatRectangle itemBounds =  pItem->GetBoundsF();
4002                         __reorderInfo.nonScrollableLimitArea = itemBounds.y + itemBounds.height - itemHeight;
4003                 }
4004         }
4005         else
4006         {
4007                 __reorderInfo.nonScrollableLimitArea = 0;
4008         }
4009
4010         return true;
4011 }
4012
4013 bool
4014 _TableViewPresenter::ResetReorderItem(int groupIndex, int itemIndex)
4015 {
4016         TableViewItemTag itemPos = {groupIndex, itemIndex};
4017         _TableViewItem* pItem = FindItem(itemPos);
4018
4019         if (pItem == null)
4020         {
4021                 return false;
4022         }
4023
4024         pItem->SetDrawingStatus(TABLE_VIEW_ITEM_DRAWING_STATUS_NORMAL);
4025         pItem->SetItemChanged(true);
4026         pItem->Invalidate();
4027
4028         PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_LIST_REORDER);
4029
4030         FloatPoint position = FloatPoint(__reorderInfo.itemBounds.x, __reorderInfo.itemBounds.y);
4031         pItem->SetPosition(position);
4032
4033         if (__reorderInfo.originGroupIndex != __reorderInfo.groupIndex || __reorderInfo.originItemIndex != __reorderInfo.itemIndex)
4034         {
4035                 if (__pTableView->GetTableViewStyle() == TABLE_VIEW_STYLE_SIMPLE)
4036                 {
4037                         __pTableView->FireTableViewItemReorderEvent(__reorderInfo.originItemIndex, __reorderInfo.itemIndex);
4038                 }
4039                 else if (__pTableView->GetTableViewStyle() == TABLE_VIEW_STYLE_GROUPED)
4040                 {
4041                         __pTableView->FireTableViewItemReorderEvent(__reorderInfo.originGroupIndex, __reorderInfo.originItemIndex, __reorderInfo.groupIndex, __reorderInfo.itemIndex);
4042                 }
4043         }
4044
4045         __reorderInfo.groupIndex = -1;
4046         __reorderInfo.itemIndex = -1;
4047         __reorderInfo.originGroupIndex = -1;
4048         __reorderInfo.originItemIndex = -1;
4049         __reorderInfo.nonScrollableLimitArea = 0;
4050
4051         StopReorderScrollTimer();
4052
4053         return true;
4054 }
4055
4056 bool
4057 _TableViewPresenter::CheckReorderItemScrollAnimation(_TableViewItem *pItem)
4058 {
4059         float currentScrollPosition = GetScrollPosition();
4060         float limitTopPositionY = currentScrollPosition;
4061         float limitBottomPositionY = currentScrollPosition + __pTableView->GetBoundsF().height - __reorderInfo.itemBounds.height;
4062
4063         float itemPositionY = pItem->GetPositionF().y;
4064
4065         if (itemPositionY < limitTopPositionY)
4066         {
4067                 if (__pReorderScrollTimer == null)
4068                 {
4069                         __reorderInfo.isScrollDirectionUp = true;
4070
4071                         return true;
4072                 }
4073         }
4074         else if (itemPositionY > limitBottomPositionY)
4075         {
4076                 if (__pReorderScrollTimer == null)
4077                 {
4078                         __reorderInfo.isScrollDirectionUp = false;
4079
4080                         return true;
4081                 }
4082         }
4083
4084         return false;
4085 }
4086
4087 bool
4088 _TableViewPresenter::DragSelectedItem(float distance, bool relativeCoordinate)
4089 {
4090         TableViewItemTag itemPos = {__reorderInfo.groupIndex, __reorderInfo.itemIndex};
4091         _TableViewItem* pItem = FindItem(itemPos);
4092
4093         if (pItem == null)
4094         {
4095                 return false;
4096         }
4097
4098         if (__firstTouchMoved)
4099         {
4100                 long long currentTick = 0;
4101                 Tizen::System::SystemTime::GetTicks(currentTick);
4102
4103                 if (currentTick - __reorderInfo.touchPressedTick < REORDER_TOUCH_UIACTIVATE_DURATION)
4104                 {
4105                         return false;
4106                 }
4107
4108                 __firstTouchMoved = false;
4109         }
4110
4111         FloatPoint itemPosition = pItem->GetPositionF();
4112
4113         if (relativeCoordinate)
4114         {
4115                 itemPosition.y = __reorderInfo.itemBasisPositionY + distance;
4116         }
4117         else
4118         {
4119                 itemPosition.y += distance;
4120
4121                 __reorderInfo.itemBasisPositionY += distance;
4122         }
4123
4124         if (itemPosition.y < 0)
4125         {
4126                 itemPosition.y = 0;
4127         }
4128
4129         float scrollAreaHeight = GetScrollAreaBounds().height;
4130         float screenHeight = __pTableView->GetBoundsF().height;
4131         float limitBottomPositionY = 0.0f;
4132
4133         if (scrollAreaHeight < screenHeight)
4134         {
4135                 limitBottomPositionY = __reorderInfo.nonScrollableLimitArea;
4136         }
4137         else
4138         {
4139                 limitBottomPositionY = scrollAreaHeight - __reorderInfo.itemBounds.height;
4140         }
4141
4142         if (itemPosition.y > limitBottomPositionY)
4143         {
4144                 itemPosition.y = limitBottomPositionY;
4145         }
4146
4147         pItem->SetPosition(itemPosition);
4148
4149         // check scroll
4150         if (CheckReorderItemScrollAnimation(pItem))
4151         {
4152                 if (__pReorderScrollTimer == null)
4153                 {
4154                         StartReorderScrollTimer();
4155                 }
4156         }
4157         else
4158         {
4159                 if (__pReorderScrollTimer != null)
4160                 {
4161                         StopReorderScrollTimer();
4162                 }
4163         }
4164
4165         // check swap
4166         TableViewItemTag moveItemTag = {-1, -1};
4167
4168         if (CheckReorderItemPosition(pItem, moveItemTag))
4169         {
4170                 if (moveItemTag.itemIndex == -1)
4171                 {
4172                         int destGroupIndex = moveItemTag.groupIndex;
4173
4174                         if (destGroupIndex != 0 && destGroupIndex == __reorderInfo.groupIndex)
4175                         {
4176                                 destGroupIndex--;
4177                         }
4178
4179                         if (moveItemTag.groupIndex == 0 || !__pProviderAdaptor->IsReorderable(__reorderInfo.groupIndex, destGroupIndex))
4180                         {
4181                                 __reorderInfo.blockedScroll = true;
4182
4183                                 return false;
4184                         }
4185                 }
4186
4187                 ReorderItem(moveItemTag.groupIndex, moveItemTag.itemIndex);
4188         }
4189
4190         return true;
4191 }
4192
4193 bool
4194 _TableViewPresenter::CheckReorderItemPosition(_TableViewItem* pItem, TableViewItemTag& reorderItemTag)
4195 {
4196         TableViewItemTag currentItemTag = {__reorderInfo.groupIndex, __reorderInfo.itemIndex};
4197         TableViewItemTag previousItemTag = {-1, -1};
4198         TableViewItemTag nextItemTag = {-1, -1};
4199
4200         FloatRectangle itemBounds = pItem->GetBoundsF();
4201
4202         if (GetPreviousItemPosition(currentItemTag, previousItemTag))
4203         {
4204                 _TableViewItem* pPreviousItem = LoadItem(previousItemTag.groupIndex, previousItemTag.itemIndex);
4205
4206                 if (pPreviousItem != null)
4207                 {
4208                         FloatRectangle previousItemBounds = pPreviousItem->GetBoundsF();
4209
4210                         if (itemBounds.y < previousItemBounds.y + (previousItemBounds.height / 2))
4211                         {
4212                                 //return previousItemIndex;
4213                                 reorderItemTag.groupIndex = previousItemTag.groupIndex;
4214                                 reorderItemTag.itemIndex = previousItemTag.itemIndex;
4215
4216                                 return true;
4217                         }
4218                 }
4219         }
4220
4221         if (GetNextItemPosition(currentItemTag, nextItemTag))
4222         {
4223                 _TableViewItem* pNextItem = LoadItem(nextItemTag.groupIndex, nextItemTag.itemIndex);
4224
4225                 if (pNextItem != null)
4226                 {
4227                         FloatRectangle nextItemBounds = pNextItem->GetBoundsF();
4228
4229                         if (itemBounds.y + itemBounds.height > nextItemBounds.y + (nextItemBounds.height / 2))
4230                         {
4231                                 //return nextItemIndex;
4232                                 reorderItemTag.groupIndex = nextItemTag.groupIndex;
4233                                 reorderItemTag.itemIndex = nextItemTag.itemIndex;
4234
4235                                 return true;
4236                         }
4237                 }
4238         }
4239
4240         reorderItemTag.groupIndex = -1;
4241         reorderItemTag.itemIndex = -1;
4242
4243         return false;
4244 }
4245
4246 bool
4247 _TableViewPresenter::ReorderItem(int destinationGroupIndex, int destinationItemIndex)
4248 {
4249         TableViewItemTag itemPos = {destinationGroupIndex, destinationItemIndex};
4250
4251         _TableViewItem* pItem = FindItem(itemPos);
4252
4253         if (pItem == null)
4254         {
4255                 return false;
4256         }
4257
4258         if (pItem->IsAnimationPlaying())
4259         {
4260                 return false;
4261         }
4262
4263         FloatRectangle destinationItemBounds = pItem->GetBoundsF();
4264
4265         FloatPoint destinationItemPosition = FloatPoint(destinationItemBounds.x, 0.0f);
4266
4267         if ( __reorderInfo.itemIndex > destinationItemIndex && __reorderInfo.groupIndex == destinationGroupIndex)
4268         {
4269                 destinationItemPosition.y = __reorderInfo.itemBounds.y + __reorderInfo.itemBounds.height - destinationItemBounds.height;
4270                 __reorderInfo.itemBounds.y = destinationItemBounds.y;
4271
4272                 if (destinationItemIndex == -1)
4273                 {
4274                         destinationGroupIndex--;
4275                         int itemCount = GetItemCountAt(destinationGroupIndex);
4276                         destinationItemIndex = itemCount;
4277                 }
4278         }
4279         else
4280         {
4281                 destinationItemPosition.y = __reorderInfo.itemBounds.y;
4282                 __reorderInfo.itemBounds.y = destinationItemBounds.y + destinationItemBounds.height - __reorderInfo.itemBounds.height;
4283
4284                 if (destinationItemIndex == -1)
4285                 {
4286                         destinationItemIndex = 0;
4287                 }
4288         }
4289
4290         __pListModel->MoveItem(__reorderInfo.groupIndex, __reorderInfo.itemIndex, destinationGroupIndex, destinationItemIndex);
4291
4292         if (!pItem->MoveItem(destinationItemPosition, REORDER_ITEM_MOVE_ANIMATION_DURATION, 0))
4293         {
4294                 pItem->SetPosition(destinationItemPosition);
4295         }
4296
4297         __reorderInfo.itemIndex = destinationItemIndex;
4298         __reorderInfo.groupIndex = destinationGroupIndex;
4299
4300         return true;
4301 }
4302
4303 void
4304 _TableViewPresenter::StartReorderScrollTimer(void)
4305 {
4306         StopReorderScrollTimer();
4307
4308         __pReorderScrollTimer = new (std::nothrow) Tizen::Base::Runtime::Timer;
4309         SysTryReturnVoidResult(NID_UI_CTRL, __pReorderScrollTimer != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
4310
4311         result r = __pReorderScrollTimer->Construct(*this);
4312         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
4313
4314         r = __pReorderScrollTimer->Start(REORDER_SCROLL_ANIMATION_TIMER_DURATION);
4315         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
4316
4317         return;
4318
4319 CATCH:
4320         StopReorderScrollTimer();
4321 }
4322
4323 void
4324 _TableViewPresenter::StopReorderScrollTimer(void)
4325 {
4326         delete __pReorderScrollTimer;
4327         __pReorderScrollTimer = null;
4328
4329 }
4330
4331 void
4332 _TableViewPresenter::UpdateLayout(void)
4333 {
4334         // nothing
4335 }
4336
4337 bool
4338 _TableViewPresenter::CheckItemHeightAndRefreshLayout(TableViewItemTag itemTag, bool downScroll)
4339 {
4340         _TableViewItem* pItem = FindItem(itemTag);
4341
4342         if (pItem == null)
4343         {
4344                 return false;
4345         }
4346
4347         if (pItem->IsAnimationPlaying())
4348         {
4349                 return false;
4350         }
4351
4352         FloatRectangle itemBounds = pItem->GetBoundsF();
4353
4354         if (_FloatCompare(GetItemHeight(itemTag), itemBounds.height))
4355         {
4356                 return false;
4357         }
4358
4359         float newHeight = itemBounds.height;
4360         float originHeight = SetItemHeight(itemTag, newHeight);
4361         float dist = newHeight - originHeight;
4362
4363         AdjustClientAreaBounds(false, dist);
4364
4365         if (!downScroll)
4366         {
4367                 itemBounds.y += dist;
4368                 pItem->SetBounds(itemBounds);
4369         }
4370
4371         AttachNextItemsToBottom(itemTag);
4372
4373         return true;
4374 }
4375
4376 bool
4377 _TableViewPresenter::CreateItemHeightList(float defaultGroupItemHeight, float defaultItemHeight)
4378 {
4379         int groupCount = GetGroupCount();
4380
4381         result r = __itemHeightList.SetCapacity(GetItemCount());
4382         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
4383
4384         for (int i = 0; i < groupCount; i++)
4385         {
4386                 int itemCount = GetItemCountAt(i);
4387
4388                 if (__pTableView->GetTableViewStyle() == TABLE_VIEW_STYLE_SIMPLE)
4389                 {
4390                         __itemHeightList.Add(0.0f);
4391                 }
4392                 else
4393                 {
4394                         __itemHeightList.Add(defaultGroupItemHeight);
4395                 }
4396
4397                 for (int j = 0; j < itemCount; j++)
4398                 {
4399                         __itemHeightList.Add(defaultItemHeight);
4400                 }
4401         }
4402
4403         return true;
4404
4405 CATCH:
4406         DeleteItemHeightList();
4407
4408         return false;
4409 }
4410
4411 void
4412 _TableViewPresenter::DeleteItemHeightList(void)
4413 {
4414         __itemHeightList.RemoveAll();
4415 }
4416
4417 bool
4418 _TableViewPresenter::RefreshItemHeightList(int groupIndex, int itemIndex, TableViewRefreshType refreshType)
4419 {
4420         float defaultItemHeight = __pProviderAdaptor->GetDefaultItemHeight();
4421         float defaultGroupItemHeight = __pProviderAdaptor->GetDefaultGroupItemHeight();
4422
4423         int startIndex = 0;
4424         for (int i = 0; i < groupIndex; i++)
4425         {
4426                 int itemCount = GetItemCountAt(i);
4427                 startIndex = startIndex + itemCount + 1;
4428         }
4429
4430         int targetIndex = startIndex + itemIndex + 1;
4431
4432         if (refreshType == TABLE_VIEW_REFRESH_TYPE_ITEM_ADD)
4433         {
4434                 if (itemIndex == -1)
4435                 {
4436                         result r = __itemHeightList.SetCapacity(GetItemCount());
4437                         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));
4438
4439                         int itemCount = GetItemCountAt(groupIndex);
4440                         for (int i = 0; i < itemCount; i++)
4441                         {
4442                                 __itemHeightList.InsertAt(defaultItemHeight, targetIndex);
4443                         }
4444
4445                         __itemHeightList.InsertAt(defaultGroupItemHeight, targetIndex);
4446
4447                 }
4448                 else
4449                 {
4450                         __itemHeightList.InsertAt(defaultItemHeight, targetIndex);
4451                 }
4452         }
4453         else if (refreshType == TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE)
4454         {
4455                 if (itemIndex == -1)
4456                 {
4457                         int itemCount = GetItemCountAt(groupIndex) + 1;
4458
4459                         for (int i = 0; i < itemCount; i++)
4460                         {
4461                                 __itemHeightList.RemoveAt(targetIndex);
4462                         }
4463                 }
4464                 else
4465                 {
4466                         __itemHeightList.RemoveAt(targetIndex);
4467                 }
4468         }
4469
4470         return true;
4471 }
4472
4473 bool
4474 _TableViewPresenter::CreateSectionAlignmentList(void)
4475 {
4476         if (__pTableView->GetTableViewStyle() != TABLE_VIEW_STYLE_SECTION)
4477         {
4478                 return false;
4479         }
4480
4481         int groupCount = GetGroupCount();
4482
4483         result r = __sectionAlignmentList.SetCapacity(GetGroupCount());
4484         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));
4485
4486         _TableViewSectionStringAlignment alignment;
4487         alignment.headerHorizontalAlignment = ALIGNMENT_LEFT;
4488         alignment.footerHorizontalAlignment = ALIGNMENT_RIGHT;
4489
4490         for (int i = 0; i < groupCount; i++)
4491         {
4492
4493                 __sectionAlignmentList.Add(alignment);
4494         }
4495
4496         return true;
4497 }
4498
4499 void
4500 _TableViewPresenter::DeleteSectionAlignmentList(void)
4501 {
4502         __sectionAlignmentList.RemoveAll();
4503 }
4504
4505 bool
4506 _TableViewPresenter::RefreshSectionAlignmentList(int groupIndex, TableViewRefreshType refreshType)
4507 {
4508         if (__pTableView->GetTableViewStyle() != TABLE_VIEW_STYLE_SECTION)
4509         {
4510                 return false;
4511         }
4512
4513         if (refreshType == TABLE_VIEW_REFRESH_TYPE_ITEM_ADD)
4514         {
4515                 _TableViewSectionStringAlignment alignment;
4516                 alignment.headerHorizontalAlignment = ALIGNMENT_LEFT;
4517                 alignment.footerHorizontalAlignment = ALIGNMENT_RIGHT;
4518
4519                 __sectionAlignmentList.InsertAt(alignment, groupIndex);
4520         }
4521         else if (refreshType == TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE)
4522         {
4523                 __sectionAlignmentList.RemoveAt(groupIndex);
4524         }
4525
4526         return true;
4527 }
4528
4529 void
4530 _TableViewPresenter::CaptureAndStartRemoveItemAnimation(int groupIndex, int itemIndex)
4531 {
4532         TableViewItemTag itemTag = {groupIndex, itemIndex};
4533         _TableViewItem* pItem = FindItem(itemTag);
4534
4535         if (pItem == null)
4536         {
4537                 return;
4538         }
4539
4540         FloatRectangle itemBounds = pItem->GetBoundsF();
4541         result r = E_SUCCESS;
4542
4543         _VisualElement* pVisualElement = null;
4544         String animationName(L"REMOVE_ITEM_ANIMATION");
4545         Canvas* pCanvas = null;
4546         VisualElementValueAnimation* pAnimation = __pTableView->GetVisualElementValueAnimation(animationName);
4547
4548         FloatDimension startValue(100.0f, itemBounds.height);
4549         FloatDimension endValue(0.0f, 0.0f);
4550
4551         Tizen::Graphics::Bitmap* pBitmap = pItem->GetCapturedBitmapN(true);
4552
4553         if (pBitmap == null)
4554         {
4555                 return;
4556         }
4557
4558         pCanvas = null;
4559         pVisualElement = new (std::nothrow) _VisualElement();
4560         SysTryCatch(NID_UI_CTRL, pVisualElement != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
4561
4562         r = pVisualElement->Construct();
4563         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
4564
4565         pVisualElement->SetImplicitAnimationEnabled(false);
4566         pVisualElement->SetSurfaceOpaque(false);
4567         pVisualElement->SetBounds(FloatRectangle(itemBounds.x, itemBounds.y, itemBounds.width, itemBounds.height));
4568         pVisualElement->SetShowState(true);
4569
4570         pCanvas = pVisualElement->GetCanvasN();
4571         SysTryCatch(NID_UI_CTRL, pCanvas != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
4572
4573         pCanvas->Clear();
4574         pCanvas->DrawBitmap(FloatRectangle(0, 0, itemBounds.width, itemBounds.height), *pBitmap);
4575
4576         pAnimation->SetDelay(0);
4577         pAnimation->SetStartValue(Variant(startValue));
4578         pAnimation->SetEndValue(Variant(endValue));
4579         pAnimation->SetDuration(REMOVE_ITEM_MOVE_ANIMATION_DURATION);
4580
4581         r = pVisualElement->AddAnimation(animationName, *pAnimation);
4582         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
4583
4584         delete pAnimation;
4585         delete pCanvas;
4586         delete pBitmap;
4587
4588         return;
4589
4590 CATCH:
4591         delete pCanvas;
4592         delete pBitmap;
4593         pVisualElement->Destroy();
4594 }
4595
4596 void
4597 _TableViewPresenter::PresetItemHeightList(void)
4598 {
4599         int groupCount = GetGroupCount();
4600         float defaultGroupItemHeight = __pProviderAdaptor->GetDefaultGroupItemHeight();
4601         float defaultItemHeight = __pProviderAdaptor->GetDefaultItemHeight();
4602
4603         for (int i = 0; i < groupCount; i++)
4604         {
4605                 TableViewItemTag itemTag = {i, -1};
4606                 int itemCount = GetItemCountAt(i);
4607
4608                 if (_FloatCompare(GetItemHeight(itemTag), TABLEVIEW_DEFAULT_ITEM_HEIGHT_VALUE))
4609                 {
4610                         SetItemHeight(itemTag, defaultGroupItemHeight);
4611                 }
4612
4613                 for (int j = 0; j < itemCount; j++)
4614                 {
4615                         itemTag.itemIndex = j;
4616
4617                         if (_FloatCompare(GetItemHeight(itemTag), TABLEVIEW_DEFAULT_ITEM_HEIGHT_VALUE))
4618                         {
4619                                 SetItemHeight(itemTag, defaultItemHeight);
4620                         }
4621                 }
4622         }
4623 }
4624
4625 _TableViewItem*
4626 _TableViewPresenter::GetTableViewItemFromControl(const _Control& source)
4627 {
4628         _Control* currentControl = const_cast<_Control*>(&source);
4629         _TableViewItem* pItem = null;
4630
4631         while (__pTableView != currentControl)
4632         {
4633                 pItem = dynamic_cast<_TableViewItem*>(currentControl);
4634
4635                 if ((pItem != null) || (currentControl == null))
4636                 {
4637                         break;
4638                 }
4639
4640                 currentControl = currentControl->GetParent();
4641         }
4642
4643         return pItem;
4644 }
4645
4646 void
4647 _TableViewPresenter::ShowTableViewCapturedItem(int groupIndex, int itemIndex, float height)
4648 {
4649         TableViewItemTag itemTag = {groupIndex, itemIndex};
4650         _TableViewItem* pItem = FindItem(itemTag);
4651
4652         if ((pItem == null) || _FloatCompare(height, 0.0f))
4653         {
4654                 return;
4655         }
4656
4657         result r = E_SUCCESS;
4658         Canvas* pCanvas = null;
4659         FloatRectangle itemBounds = pItem->GetBoundsF();
4660
4661         bool visibleState = pItem->GetVisibleState();
4662         pItem->SetVisibleState(true);
4663         Bitmap* pBitmap = pItem->GetCapturedBitmapN(true);
4664         pItem->SetVisibleState(visibleState);
4665
4666         if (pBitmap == null)
4667         {
4668                 return;
4669         }
4670
4671         if (__pCapturedItemVisualElement == null)
4672         {
4673                 __pCapturedItemVisualElement = new (std::nothrow) _VisualElement();
4674                 SysTryCatch(NID_UI_CTRL, __pCapturedItemVisualElement != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
4675
4676                 r = __pCapturedItemVisualElement->Construct();
4677                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
4678
4679                 r = GetView()->GetVisualElement()->AttachChild(*__pCapturedItemVisualElement);
4680                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to attach child to the control VisualElement.", GetErrorMessage(r));
4681
4682                 __pCapturedItemVisualElement->SetSurfaceOpaque(false);
4683                 __pCapturedItemVisualElement->SetImplicitAnimationEnabled(false);
4684         }
4685
4686         __pCapturedItemVisualElement->SetShowState(true);
4687         __pCapturedItemVisualElement->SetBounds(FloatRectangle(itemBounds.x, itemBounds.y, itemBounds.width, height));
4688
4689         pCanvas = __pCapturedItemVisualElement->GetCanvasN();
4690         SysTryCatch(NID_UI_CTRL, pCanvas != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
4691
4692         pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
4693         pCanvas->Clear();
4694         pCanvas->DrawBitmap(FloatPoint(0.0f, 0.0f), *pBitmap);
4695
4696         delete pCanvas;
4697         delete pBitmap;
4698
4699         return;
4700
4701 CATCH:
4702         delete pBitmap;
4703
4704         __pCapturedItemVisualElement->Destroy();
4705 }
4706
4707 void
4708 _TableViewPresenter::SetLoadedItemsVisibleFromPosition(float position, bool visible)
4709 {
4710         _TableViewItem* pItem;
4711         FloatRectangle itemBounds;
4712         TableViewItemTag current;
4713         current.groupIndex = __expandableItemTag.groupIndex;
4714         current.itemIndex = __expandableItemTag.itemIndex;
4715
4716         int itemCountInGroup = __pListModel->GetItemCountInGroup(__expandableItemTag.groupIndex);
4717
4718         for (int i = 0; i < itemCountInGroup; i++)
4719         {
4720                 current.itemIndex = i;
4721
4722                 if (visible)
4723                 {
4724                         pItem = LoadItem(current.groupIndex, current.itemIndex);
4725                         if (pItem == null)
4726                         {
4727                                 break;
4728                         }
4729                 }
4730                 else
4731                 {
4732                         pItem = FindItem(current);
4733                         if (pItem == null)
4734                         {
4735                                 continue;
4736                         }
4737                 }
4738
4739                 itemBounds = pItem->GetBoundsF();
4740
4741                 if (visible)
4742                 {
4743                         if ((position >= itemBounds.y) && (position < itemBounds.y + itemBounds.height))
4744                         {
4745                                 ShowTableViewCapturedItem(current.groupIndex, current.itemIndex, position - itemBounds.y);
4746                                 pItem->SetVisibleState(false);
4747                                 break;
4748                         }
4749                         else
4750                         {
4751                                 pItem->SetVisibleState(true);
4752                         }
4753                 }
4754                 else
4755                 {
4756                         if (position < itemBounds.y)
4757                         {
4758                                 UnloadItem(current);
4759                         }
4760                         else if ((position >= itemBounds.y) && (position < itemBounds.y + itemBounds.height))
4761                         {
4762                                 pItem->SetVisibleState(false);
4763                                 ShowTableViewCapturedItem(current.groupIndex, current.itemIndex, position - itemBounds.y);
4764                         }
4765                         else
4766                         {
4767                                 pItem->SetVisibleState(true);
4768                         }
4769                 }
4770         }
4771 }
4772
4773 void
4774 _TableViewPresenter::MoveLoadedItemsFromPosition(float position)
4775 {
4776         FloatRectangle itemBounds;
4777         float itemPosition = position;
4778
4779         TableViewItemTag current;
4780         TableViewItemTag next;
4781
4782         current.groupIndex = __expandableItemTag.groupIndex;
4783         current.itemIndex = __pListModel->GetItemCountInGroup(__expandableItemTag.groupIndex) -1;
4784
4785         float screenPosition = GetScrollPosition();
4786         FloatRectangle screenBounds = __pTableView->GetBoundsF();
4787         screenPosition += screenBounds.height;
4788
4789         _TableViewItem* pItem = null;
4790         while (GetNextItemPosition(current, next))
4791         {
4792                 if (screenPosition > itemPosition)
4793                 {
4794                         pItem = LoadItem(next.groupIndex, next.itemIndex);
4795                 }
4796                 else
4797                 {
4798                         pItem = FindItem(next);
4799                 }
4800
4801                 if (pItem == null)
4802                 {
4803                         break;
4804                 }
4805
4806                 itemBounds = pItem->GetBoundsF();
4807                 itemBounds.y = itemPosition;
4808                 pItem->SetBounds(itemBounds);
4809                 itemPosition += itemBounds.height;
4810
4811                 current = next;
4812         }
4813 }
4814
4815 void
4816 _TableViewPresenter::ExpandGroupAnimationFinished(bool completedNormally)
4817 {
4818         if (completedNormally == false)
4819         {
4820                 TableViewItemTag current;
4821                 TableViewItemTag next;
4822
4823                 current.groupIndex = __expandableItemTag.groupIndex;
4824                 current.itemIndex = -1;
4825
4826                 _TableViewItem* pNextItem = null;
4827                 _TableViewItem* pCurrentItem = null;
4828                 pCurrentItem = LoadItem(current.groupIndex, current.itemIndex);
4829
4830                 if (pCurrentItem == null)
4831                 {
4832                         return;
4833                 }
4834
4835                 FloatRectangle itemBounds;
4836                 FloatRectangle screenBounds = __pTableView->GetBoundsF();
4837                 float screenPosition = GetScrollPosition() + screenBounds.height;
4838                 float nextItemPositionY = pCurrentItem->GetBoundsF().y + pCurrentItem->GetBoundsF().height;
4839
4840                 while (GetNextItemPosition(current, next))
4841                 {
4842                         if (screenPosition >= nextItemPositionY)
4843                         {
4844                                 pCurrentItem = LoadItem(current.groupIndex, current.itemIndex);
4845                                 if (pCurrentItem == null)
4846                                 {
4847                                         break;
4848                                 }
4849                                 pNextItem = LoadItem(next.groupIndex, next.itemIndex);
4850                                 if (pNextItem == null)
4851                                 {
4852                                         break;
4853                                 }
4854                                 pNextItem->SetVisibleState(true);
4855                                 itemBounds = pNextItem->GetBoundsF();
4856                                 itemBounds.y = pCurrentItem->GetBoundsF().y + pCurrentItem->GetBoundsF().height;
4857                                 pNextItem->SetBounds(itemBounds);
4858                                 nextItemPositionY = itemBounds.y + itemBounds.height;
4859                         }
4860                         else
4861                         {
4862                                 UnloadItem(next.groupIndex, next.itemIndex);
4863                         }
4864
4865                         current = next;
4866                 }
4867         }
4868         else
4869         {
4870                 int currentGroupIndex = -1;
4871                 int currentItemIndex = -1;
4872                 GetBottomDrawnItemIndex(currentGroupIndex, currentItemIndex);
4873
4874                 int lastLoadedGroupIndex = -1;
4875                 int lastLoadedItemIndex = -1;
4876                 __pListModel->GetLastLoadedItemIndex(lastLoadedGroupIndex, lastLoadedItemIndex);
4877
4878                 TableViewItemTag current;
4879                 current.groupIndex = currentGroupIndex;
4880                 current.itemIndex = currentItemIndex;
4881
4882                 _TableViewItem* pCurrentItem;
4883                 pCurrentItem = FindItem(current);
4884                 if (pCurrentItem != null)
4885                 {
4886                         pCurrentItem->SetVisibleState(true);
4887                 }
4888
4889                 for (int j = currentGroupIndex; j <= lastLoadedGroupIndex; j++)
4890                 {
4891                         int itemCount = GetItemCountAt(j);
4892
4893                         for (int i = -1; i < itemCount; i++)
4894                         {
4895                                 if (i <= currentItemIndex && j == currentGroupIndex)
4896                                 {
4897                                         continue;
4898                                 }
4899
4900                                 UnloadItem(j, i);
4901                         }
4902                 }
4903         }
4904 }
4905
4906 void
4907 _TableViewPresenter::CollapseGroupAnimationFinished(bool completedNormally)
4908 {
4909         int itemCountInGroup = __pListModel->GetItemCountInGroup(__expandableItemTag.groupIndex);
4910
4911         if (completedNormally == false)
4912         {
4913                 TableViewItemTag current;
4914                 TableViewItemTag next;
4915
4916                 current.groupIndex = __expandableItemTag.groupIndex;
4917                 current.itemIndex = -1;
4918
4919                 for (int i = 0; i < itemCountInGroup; i++)
4920                 {
4921                         UnloadItem(__expandableItemTag.groupIndex, i);
4922                 }
4923
4924                 _TableViewItem* pCurrentItem = FindItem(current);
4925                 if (pCurrentItem == null)
4926                 {
4927                         SysTryReturnVoidResult(NID_UI_CTRL, pCurrentItem != null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.")
4928                 }
4929
4930                 FloatRectangle itemBounds;
4931                 float nextItemPositionY = pCurrentItem->GetBoundsF().y + pCurrentItem->GetBoundsF().height;
4932
4933                 FloatRectangle screenBounds = __pTableView->GetBoundsF();
4934                 float screenPosition = GetScrollPosition() + screenBounds.height;
4935
4936                 while (GetNextItemPosition(current, next))
4937                 {
4938                         current = next;
4939                         if (screenPosition >= nextItemPositionY)
4940                         {
4941                                 pCurrentItem = LoadItem(current.groupIndex, current.itemIndex);
4942                                 if (pCurrentItem == null)
4943                                 {
4944                                         break;
4945                                 }
4946
4947                                 pCurrentItem->SetVisibleState(true);
4948                                 itemBounds = pCurrentItem->GetBoundsF();
4949                                 itemBounds.y = nextItemPositionY;
4950                                 pCurrentItem->SetBounds(itemBounds);
4951                                 nextItemPositionY = pCurrentItem->GetBoundsF().y + pCurrentItem->GetBoundsF().height;
4952                         }
4953                         else
4954                         {
4955                                 UnloadItem(current.groupIndex, current.itemIndex);
4956                         }
4957                 }
4958         }
4959         else
4960         {
4961                 int currentGroupIndex = -1;
4962                 int currentItemIndex = -1;
4963                 GetTopDrawnItemIndex(currentGroupIndex, currentItemIndex);
4964
4965                 int firstLoadedGroupIndex = -1;
4966                 int firstLoadedItemIndex = -1;
4967                 __pListModel->GetFirstLoadedItemIndex(firstLoadedGroupIndex, firstLoadedItemIndex);
4968
4969                 for (int j = firstLoadedGroupIndex; j <= currentGroupIndex; j++)
4970                 {
4971                         int itemCount = GetItemCountAt(j);
4972
4973                         for (int i = -1; i < itemCount; i++)
4974                         {
4975                                 if (i >= currentItemIndex && j == currentGroupIndex)
4976                                 {
4977                                         break;
4978                                 }
4979
4980                                 UnloadItem(j, i);
4981                         }
4982                 }
4983
4984                 for (int i = 0; i < itemCountInGroup; i++)
4985                 {
4986                         UnloadItem(__expandableItemTag.groupIndex, i);
4987                 }
4988
4989                 GetTopDrawnItemIndex(currentGroupIndex, currentItemIndex);
4990                 TableViewItemTag currentItemTag;
4991                 currentItemTag.groupIndex = currentGroupIndex;
4992                 currentItemTag.itemIndex = currentItemIndex;
4993
4994                 _TableViewItem* pItem = FindItem(currentItemTag);
4995                 if (pItem != null)
4996                 {
4997                         FloatRectangle itemBounds = pItem->GetBoundsF();
4998                         itemBounds.y = CalculateItemPositionY(currentGroupIndex, currentItemIndex);
4999                         pItem->SetBounds(itemBounds);
5000                         AttachNextItemsToBottom(currentItemTag);
5001                         if (__expandableItemTag.groupIndex < currentGroupIndex)
5002                         {
5003                                 SetScrollPosition(itemBounds.y, false);
5004                         }
5005                 }
5006         }
5007
5008         float groupTotalHeight = 0;
5009         _TableViewItem* pItem = null;
5010         for (int i = 0; i < itemCountInGroup; i++)
5011         {
5012                 pItem = static_cast<_TableViewItem*>(__pListModel->GetItemFromTemporaryBuffer(__expandableItemTag.groupIndex, i));
5013                 groupTotalHeight += pItem->GetItemHeight();
5014         }
5015
5016         AdjustClientAreaBounds(false, -groupTotalHeight);
5017 }
5018
5019 void
5020 _TableViewPresenter::OnVisualElementAnimationStarted(const Tizen::Ui::Animations::VisualElementAnimation& animation, const Tizen::Base::String& keyName, Tizen::Ui::Animations::VisualElement& target)
5021 {
5022         if (keyName == L"REMOVE_ITEM_ANIMATION")
5023         {
5024                 return;
5025         }
5026
5027         if (keyName == L"SCROLL_PANEL_SCROLLING_ANIMATION")
5028         {
5029                 __scrollHeightOnFlickStarted = GetScrollAreaBounds().height;
5030                 __scrollPositionOnFlickStarted = GetScrollPosition();
5031         }
5032
5033         _ScrollPanelPresenter::OnVisualElementAnimationStarted(animation, keyName, target);
5034 }
5035
5036 void
5037 _TableViewPresenter::OnVisualElementAnimationRepeated(const Tizen::Ui::Animations::VisualElementAnimation& animation, const Tizen::Base::String& keyName, Tizen::Ui::Animations::VisualElement& target, long currentRepeatCount)
5038 {
5039         if (keyName == L"REMOVE_ITEM_ANIMATION")
5040         {
5041                 return;
5042         }
5043         _ScrollPanelPresenter::OnVisualElementAnimationRepeated(animation, keyName, target, currentRepeatCount);
5044 }
5045
5046 void
5047 _TableViewPresenter::OnVisualElementAnimationFinished(const Tizen::Ui::Animations::VisualElementAnimation& animation, const Tizen::Base::String& keyName, Tizen::Ui::Animations::VisualElement& target, bool completedNormally)
5048 {
5049         if (__isAnimationCallbackBlocked)
5050         {
5051                 return;
5052         }
5053
5054         if (keyName == L"REMOVE_ITEM_ANIMATION")
5055         {
5056                 _VisualElement* pVisualElement = GetView()->GetVisualElement();
5057
5058                 pVisualElement->DetachChild(target);
5059
5060                 target.Destroy();
5061                 return;
5062         }
5063         else if (keyName == L"EXPAND_GROUP_ANIMATION")
5064         {
5065                 if (__pCapturedItemVisualElement)
5066                 {
5067                         __pCapturedItemVisualElement->SetShowState(false);
5068                 }
5069                 ExpandGroupAnimationFinished(completedNormally);
5070
5071                 if (__scrollToItemTag.startedAnimation)
5072                 {
5073                         __scrollToItemTag.startedAnimation = false;
5074                         ScrollToItem(__scrollToItemTag.groupIndex, __scrollToItemTag.itemIndex, __scrollToItemTag.itemAlignment, __scrollToItemTag.shiftingDistance);
5075                 }
5076                 return;
5077         }
5078         else if (keyName == L"COLLAPSE_GROUP_ANIMATION")
5079         {
5080                 if (__pCapturedItemVisualElement)
5081                 {
5082                         __pCapturedItemVisualElement->SetShowState(false);
5083                 }
5084                 CollapseGroupAnimationFinished(completedNormally);
5085
5086                 if (__scrollToItemTag.startedAnimation)
5087                 {
5088                         __scrollToItemTag.startedAnimation = false;
5089                         ScrollToItem(__scrollToItemTag.groupIndex, __scrollToItemTag.itemIndex, __scrollToItemTag.itemAlignment, __scrollToItemTag.shiftingDistance);
5090                 }
5091                 return;
5092         }
5093
5094         _ScrollPanelPresenter::OnVisualElementAnimationFinished(animation, keyName, target, completedNormally);
5095 }
5096
5097 void
5098 _TableViewPresenter::OnTickOccurred(const Tizen::Ui::Animations::VisualElementAnimation& animation, const Tizen::Base::String& keyName, Tizen::Ui::Animations::VisualElement& target, const Tizen::Ui::Variant& currentValue)
5099 {
5100         _VisualElement* pVisualElement = __pTableView->GetVisualElement();
5101
5102         if (&target != pVisualElement)
5103         {
5104                 return;
5105         }
5106
5107         if (keyName == L"REMOVE_ITEM_ANIMATION")
5108         {
5109                 Dimension value = currentValue.ToDimension();
5110                 target.SetOpacity(value.width);
5111
5112                 FloatRectangle bounds = target.GetBounds();
5113                 bounds.height = value.height;
5114                 target.SetBounds(bounds);
5115
5116                 target.SetFlushNeeded();
5117
5118                 return;
5119         }
5120         else if (keyName == L"EXPAND_GROUP_ANIMATION")
5121         {
5122                 float currentPosition = currentValue.ToFloat();
5123                 SetLoadedItemsVisibleFromPosition(currentPosition, true);
5124                 MoveLoadedItemsFromPosition(currentPosition);
5125
5126                 return;
5127         }
5128         else if (keyName == L"COLLAPSE_GROUP_ANIMATION")
5129         {
5130                 float currentPosition = currentValue.ToFloat();
5131                 SetLoadedItemsVisibleFromPosition(currentPosition, false);
5132                 MoveLoadedItemsFromPosition(currentPosition);
5133
5134                 return;
5135         }
5136         else if (keyName == L"SWEEP_ITEM_ANIMATION")
5137         {
5138                 float currentPosition = currentValue.ToFloat();
5139                 float moveDestance = currentPosition - __sweptItemPosition.x;
5140                 SweepItem(moveDestance);
5141
5142                 return;
5143         }
5144
5145         _ScrollPanelPresenter::OnTickOccurred(animation, keyName, target, currentValue);
5146 }
5147
5148 bool
5149 _TableViewPresenter::OnAccessibilityItemRefreshed(const _AccessibilityContainer& control, const _AccessibilityElement& element, _AccessibilityFocusDirection direction)
5150 {
5151         TableViewItemTag itemPos = {-1, -1};
5152
5153         if (direction == _ACCESSIBILITY_FOCUS_DIRECTION_NEXT)
5154         {
5155                 GetFirstItem(itemPos);
5156                 if (GetAccessibilityElementFocusedState() == false && FindItem(itemPos) == null)
5157                 {
5158                         ScrollToItem(itemPos.groupIndex, itemPos.itemIndex, TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_TOP);
5159
5160                         return true;
5161                 }
5162         }
5163         else if (direction == _ACCESSIBILITY_FOCUS_DIRECTION_PREVIOUS)
5164         {
5165                 GetLastItem(itemPos);
5166
5167                 if (IsGroupExpanded(itemPos.groupIndex) == false)
5168                 {
5169                         itemPos.itemIndex = -1;
5170                 }
5171
5172                 if (GetAccessibilityElementFocusedState() == false && FindItem(itemPos) == null)
5173                 {
5174                         ScrollToItem(itemPos.groupIndex, itemPos.itemIndex, TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_BOTTOM);
5175
5176                         return true;
5177                 }
5178         }
5179
5180         return false;
5181 }
5182
5183 bool
5184 _TableViewPresenter::OnOcurredOverflowItems(const int currentCashSize, const int overflowCount)
5185 {
5186         return IsCachingItemsTotalHeightLessThanViewHeight();
5187 }
5188
5189 bool
5190 _TableViewPresenter::GetAccessibilityElementFocusedState(void)
5191 {
5192         _TableViewItem* pItem = null;
5193         TableViewItemTag itemPos = {-1, -1};
5194         TableViewItemTag lastItemPos = {-1, -1};
5195
5196         __pListModel->GetFirstLoadedItemIndex(itemPos.groupIndex, itemPos.itemIndex);
5197         __pListModel->GetLastLoadedItemIndex(lastItemPos.groupIndex, lastItemPos.itemIndex);
5198
5199         do
5200         {
5201                 pItem = static_cast <_TableViewItem*>(__pListModel->LoadItem(itemPos.groupIndex, itemPos.itemIndex));
5202                 SysTryReturn(NID_UI_CTRL, pItem != null, false, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The index is out of range.");
5203
5204                 _AccessibilityContainer* pContainer = pItem->GetAccessibilityContainer();
5205                 _AccessibilityElement* pElement = null;
5206
5207                 if (pContainer != null)
5208                 {
5209                         pElement = pContainer->GetCurrentFocusedElement();
5210                         if (pElement != null)
5211                         {
5212                                 return true;
5213                         }
5214                 }
5215
5216                 if ((itemPos.itemIndex == lastItemPos.itemIndex) && (itemPos.groupIndex == lastItemPos.groupIndex))
5217                 {
5218                         break;
5219                 }
5220
5221         } while (GetNextItemPosition(itemPos, itemPos) == true);
5222
5223         return false;
5224 }
5225
5226 void
5227 _TableViewPresenter::FireItemTouchReleasedEventDuringPressing(int groupIndex, int itemIndex)
5228 {
5229         TableViewItemTag fireItemPos;
5230         fireItemPos.groupIndex = groupIndex;
5231         fireItemPos.itemIndex = itemIndex;
5232
5233         __itemTouchReleasedEventState = TABLE_VIEW_ITEM_TOUCH_RELEASED_EVENT_FIRE;
5234         _TableViewItem* pItem = FindItem(fireItemPos);
5235         if (pItem != null)
5236         {
5237                 pItem->FireItemTouchReleased();
5238         }
5239
5240         // for new item after UpdateTableView.
5241         pItem = FindItem(fireItemPos);
5242         if (pItem != null)
5243         {
5244                 if (__itemTouchReleasedEventState == TABLE_VIEW_ITEM_TOUCH_RELEASED_EVENT_UPDATE_TABLE_VIEW)
5245                 {
5246                         __itemTouchReleasedEventState = TABLE_VIEW_ITEM_TOUCH_RELEASED_EVENT_NORMAL;
5247                 }
5248                 else
5249                 {
5250                         pItem->SetSelectionState(true);
5251                         pItem->FireItemTouchPressed();
5252                 }
5253         }
5254 }
5255
5256 bool
5257 _TableViewSectionStringAlignment::operator== (const _TableViewSectionStringAlignment& rhs) const
5258 {
5259         if (headerHorizontalAlignment == rhs.headerHorizontalAlignment && footerHorizontalAlignment == rhs.footerHorizontalAlignment)
5260         {
5261                 return true;
5262         }
5263
5264         return false;
5265 }
5266
5267 bool
5268 _TableViewSectionStringAlignment::operator!= (const _TableViewSectionStringAlignment& rhs) const
5269 {
5270         if (headerHorizontalAlignment == rhs.headerHorizontalAlignment && footerHorizontalAlignment == rhs.footerHorizontalAlignment)
5271         {
5272                 return false;
5273         }
5274
5275         return true;
5276 }
5277
5278 }}} // Tizen::Ui::Controls