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