2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0/
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FUiCtrl_TableViewPresenter.cpp
20 * @brief This is the header file for the _TableViewPresenter class.
22 * This file contains the declarations of the _TableViewPresenter class.
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"
40 #include "FUi_Window.h"
41 #include "FUiCtrl_Edit.h"
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;
49 namespace Tizen { namespace Ui { namespace Controls
51 const float _TableViewPresenter::REORDER_SCROLL_ANIMATION_DISTANCE = 10.0f;
52 const float _TableViewPresenter::TABLEVIEW_DEFAULT_ITEM_HEIGHT_VALUE = 12.3456f;
54 _TableViewPresenter::_TableViewPresenter()
57 , __pProviderAdaptor(null)
59 , __bottomMargin(0.0f)
61 , __modelInitialized(false)
62 , __firstDrawnFlag(true)
63 , __statusChangedFlag(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)
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)
86 , __isOrientationChanged(false)
87 , __isFocusedDuringOrientationChange(false)
88 , __isUpdatingTableView(false)
90 __sweptItemTag.itemIndex = -1;
91 __sweptItemTag.groupIndex = -1;
93 __reservedScrollItemIndex.itemIndex = -1;
94 __reservedScrollItemIndex.groupIndex = -1;
96 __expandableItemTag.groupIndex = -1;
97 __expandableItemTag.itemIndex = -1;
99 __focusItemTag.groupIndex = -1;
100 __focusItemTag.itemIndex = -1;
102 __focusItemTagOnTraversal.groupIndex = -1;
103 __focusItemTagOnTraversal.itemIndex = -1;
106 _TableViewPresenter::~_TableViewPresenter()
112 _TableViewPresenter::GetView() const
118 _TableViewPresenter::GetModel(void) const
124 _TableViewPresenter::Initialize(_TableView* pTableView)
126 _ScrollPanelPresenter::Initialize(*pTableView);
128 __pTableView = pTableView;
129 __pBaseVisualElement = __pTableView->GetVisualElement();
130 __pBaseVisualElement->SetClipChildrenEnabled(true);
131 __pBaseVisualElement->SetSurfaceOpaque(false);
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));
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));
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);
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));
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));
151 r = __pFastScrollTimer->Construct(*this);
152 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
157 if (__isFastScrollTimerEnabled)
159 __pFastScrollTimer->Cancel();
162 delete __pFastScrollTimer;
163 __pFastScrollTimer = null;
169 _TableViewPresenter::Construct(_TableView* pTableView)
171 result r = E_SUCCESS;
175 init = Initialize(pTableView);
176 SysTryCatch(NID_UI_CTRL, init == true, , r = GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
186 _TableViewPresenter::Dispose(void)
188 DeleteItemHeightList();
189 DeleteSectionAlignmentList();
190 DetachContextItem(__sweptItemTag);
195 delete __pProviderAdaptor;
196 __pProviderAdaptor = null;
198 delete __pItemDrawingProperty;
199 __pItemDrawingProperty = null;
201 delete __pReorderScrollTimer;
202 __pReorderScrollTimer = null;
204 if (__isFastScrollTimerEnabled)
206 __pFastScrollTimer->Cancel();
209 delete __pFastScrollTimer;
210 __pFastScrollTimer = null;
212 if (__pCapturedItemVisualElement)
214 GetView()->GetVisualElement()->DetachChild(*__pCapturedItemVisualElement);
215 __pCapturedItemVisualElement->Destroy();
217 __pCapturedItemVisualElement = null;
221 _TableViewPresenter::SetItemProvider(const _TableViewItemProvider* pProvider)
223 result r = E_SUCCESS;
225 _TableViewItemProviderAdaptor* pProviderAdaptor = static_cast <_TableViewItemProviderAdaptor*>(__pListModel->GetItemProviderAdaptor());
226 if(pProviderAdaptor != null)
228 _TableViewItemProvider* provider = pProviderAdaptor->GetItemProvider();
229 if(provider != null && provider == pProvider)
235 if (pProviderAdaptor == null)
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));
240 SetTableViewItemProviderAdaptor(pProviderAdaptor);
243 _TableViewItemProvider* pNewProvider = null;
245 if (pProvider != null)
247 pNewProvider = const_cast <_TableViewItemProvider*>(pProvider);
251 __pListModel->RemoveAllItem(false);
254 pProviderAdaptor->SetItemProvider(pNewProvider);
255 pProviderAdaptor->SetListWidth(__pTableView->GetBoundsF().width - (GetLeftMargin() * 2));
256 pProviderAdaptor->SetTableViewStyle(__pTableView->GetTableViewStyle());
262 _TableViewPresenter::GetItemFromPosition(const Tizen::Graphics::FloatPoint& position, TableViewItemTag& itemPos) const
264 _TableViewItem* pItem = null;
265 TableViewItemTag lastItemPos = {-1, -1};
267 __pListModel->GetFirstLoadedItemIndex(itemPos.groupIndex, itemPos.itemIndex);
268 __pListModel->GetLastLoadedItemIndex(lastItemPos.groupIndex, lastItemPos.itemIndex);
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);
275 FloatRectangle itemBounds = pItem->GetBoundsF();
276 if (itemBounds.Contains(position))
281 if ((itemPos.itemIndex == lastItemPos.itemIndex) && (itemPos.groupIndex == lastItemPos.groupIndex))
286 } while (GetNextItemPosition(itemPos, itemPos));
289 itemPos.itemIndex = -1;
290 itemPos.groupIndex = -1;
292 return E_OUT_OF_RANGE;
296 _TableViewPresenter::GetTopDrawnItemIndex(int& groupIndex, int& itemIndex) const
298 result r = E_SUCCESS;
300 TableViewItemTag itemPos;
301 r = GetTopDrawnItem(itemPos);
303 groupIndex = itemPos.groupIndex;
304 itemIndex = itemPos.itemIndex;
310 _TableViewPresenter::SetTopDrawnItemIndex(int groupIndex, int itemIndex)
314 return E_INVALID_ARG;
317 if ((groupIndex < 0) || (groupIndex >= GetGroupCount()) || (itemIndex < -1) || (itemIndex >= GetItemCountAt(groupIndex)))
319 return E_OUT_OF_RANGE;
322 ScrollToItem(groupIndex, itemIndex, TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_TOP);
328 _TableViewPresenter::GetBottomDrawnItemIndex(int& groupIndex, int& itemIndex) const
330 result r = E_SUCCESS;
332 TableViewItemTag itemPos;
333 r = GetBottomDrawnItem(itemPos);
335 groupIndex = itemPos.groupIndex;
336 itemIndex = itemPos.itemIndex;
342 _TableViewPresenter::SetBottomDrawnItemIndex(int groupIndex, int itemIndex)
346 return E_INVALID_ARG;
349 if ((groupIndex < 0) || (groupIndex >= GetGroupCount()) || (itemIndex < -1) || (itemIndex >= GetItemCountAt(groupIndex)))
351 return E_OUT_OF_RANGE;
354 ScrollToItem(groupIndex, itemIndex, TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_BOTTOM);
360 _TableViewPresenter::GetGroupCount(void) const
362 return __pListModel->GetAllGroupCount();
367 _TableViewPresenter::GetItemCountAt(int groupIndex) const
369 return __pListModel->GetItemCountInGroup(groupIndex);
373 _TableViewPresenter::HasSectionHeader(int groupIndex) const
375 if (__pProviderAdaptor == null || __pTableView->GetTableViewStyle() != TABLE_VIEW_STYLE_SECTION)
380 return __pProviderAdaptor->HasSectionHeader(groupIndex);
384 _TableViewPresenter::HasSectionFooter(int groupIndex) const
386 if (__pProviderAdaptor == null || __pTableView->GetTableViewStyle() != TABLE_VIEW_STYLE_SECTION)
391 return __pProviderAdaptor->HasSectionFooter(groupIndex);
395 _TableViewPresenter::GetItemCount(void) const
397 return __pListModel->GetAllItemCount();
401 _TableViewPresenter::RefreshTableView(int groupIndex, int itemIndex, TableViewRefreshType type, bool animation)
403 _TableViewItemProviderAdaptor* pProviderAdaptor = __pProviderAdaptor;
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));
408 if ((groupIndex < 0) || (groupIndex > GetGroupCount()) || (itemIndex < -1) || (itemIndex > GetItemCountAt(groupIndex)))
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;
414 if (groupIndex == GetGroupCount() && itemIndex != -1 && type != TABLE_VIEW_REFRESH_TYPE_ITEM_ADD)
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;
420 TableViewItemTag topDrawnItemPos = {-1, -1};
421 TableViewItemTag refreshItemPos = {groupIndex, itemIndex};
422 float prevScrollAreaHeight = GetScrollAreaBounds().height;
423 float prevScrollPosition = GetScrollPosition();
425 GetTopDrawnItem(topDrawnItemPos);
431 case TABLE_VIEW_REFRESH_TYPE_ITEM_ADD:
434 bool emptyState = IsEmpty();
436 int itemCount = pProviderAdaptor->GetItemCount(groupIndex);
437 if (__pListModel->InsertGroup(groupIndex, itemCount, false) != E_SUCCESS)
439 SysLogException(NID_UI_CTRL, E_SYSTEM, "[%s] A system error has been occurred. Unable to add Group item.", GetErrorMessage(E_SYSTEM));
445 GetFirstItem(topDrawnItemPos);
447 else if (groupIndex <= topDrawnItemPos.groupIndex)
449 topDrawnItemPos.groupIndex++;
454 bool emptyState = IsEmpty();
456 if (__pListModel->InsertItemToGroup(null, groupIndex, itemIndex) != E_SUCCESS)
458 SysLogException(NID_UI_CTRL, E_SYSTEM, "[%s] A system error has been occurred. Unable to add item.", GetErrorMessage(E_SYSTEM));
464 GetFirstItem(topDrawnItemPos);
468 RefreshItemHeightList(groupIndex, itemIndex, TABLE_VIEW_REFRESH_TYPE_ITEM_ADD);
469 RefreshSectionAlignmentList(groupIndex, TABLE_VIEW_REFRESH_TYPE_ITEM_ADD);
471 if (__pListModel->GetAllItemCount() == 1)
473 SetStatusChanged(true);
476 if (!__pTableView->IsFocusNavigateEnabled() && (!IsEmpty()))
478 __pTableView->SetFocusNavigateEnabled(true);
483 case TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE:
486 if (groupIndex == GetGroupCount())
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;
492 RefreshItemHeightList(groupIndex, itemIndex, TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE);
493 RefreshSectionAlignmentList(groupIndex, TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE);
495 if (__pListModel->RemoveGroup(groupIndex) != E_SUCCESS)
497 SysLogException(NID_UI_CTRL, E_SYSTEM, "[%s] A system error has been occurred. Unable to remove group.", GetErrorMessage(E_SYSTEM));
501 if (groupIndex == topDrawnItemPos.groupIndex)
503 topDrawnItemPos.itemIndex = -1;
506 if (groupIndex < topDrawnItemPos.groupIndex)
508 topDrawnItemPos.groupIndex--;
511 if ((groupIndex == GetGroupCount()) && (GetGroupCount() > 0))
513 topDrawnItemPos.groupIndex--;
514 topDrawnItemPos.itemIndex = GetItemCountAt(GetGroupCount() - 1) - 1;
519 if (itemIndex == GetItemCountAt(groupIndex))
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;
525 if (__pListModel->RemoveItemAt(groupIndex, itemIndex) != E_SUCCESS)
527 SysLogException(NID_UI_CTRL, E_SYSTEM, "[%s] A system error has been occurred. Unable to remove group.", GetErrorMessage(E_SYSTEM));
531 if ((groupIndex == topDrawnItemPos.groupIndex) && (itemIndex < topDrawnItemPos.itemIndex))
533 GetPreviousItemPosition(topDrawnItemPos, topDrawnItemPos);
536 RefreshItemHeightList(groupIndex, itemIndex, TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE);
539 if (GetModel()->IsValidItem(topDrawnItemPos.groupIndex, topDrawnItemPos.itemIndex) == false)
541 GetPreviousItemPosition(topDrawnItemPos, topDrawnItemPos);
544 if (__pListModel->GetAllItemCount() == 0)
546 SetStatusChanged(true);
549 if (__pTableView->IsFocusNavigateEnabled() && IsEmpty())
551 __pTableView->SetFocusNavigateEnabled(false);
556 case TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY:
558 TableViewItemTag itemTag = {groupIndex, itemIndex};
559 _TableViewItem* pTableViewItem = FindItem(itemTag);
561 if (pTableViewItem == null)
566 if (pProviderAdaptor->UpdateItem(pTableViewItem, itemTag.groupIndex, itemTag.itemIndex))
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);
573 CheckItemHeightAndRefreshLayout(itemTag, true);
575 if (__sweptItemTag.groupIndex != itemTag.groupIndex || __sweptItemTag.itemIndex != itemTag.itemIndex)
580 pTableViewItem->SetPublicLabelUpdate(false);
581 pTableViewItem->SetItemChanged(true);
582 pTableViewItem->Invalidate();
583 pTableViewItem->AdjustContextItemBounds();
591 SysLogException(NID_UI_CTRL, E_SYSTEM, "[%s] A system error has been occurred. Unable to refresh list.", GetErrorMessage(E_SYSTEM));
596 __lockLoadItemWithScroll = true;
598 AdjustClientAreaBounds(true);
600 __lockLoadItemWithScroll = false;
602 if ((topDrawnItemPos.groupIndex > refreshItemPos.groupIndex)
603 ||((topDrawnItemPos.groupIndex == refreshItemPos.groupIndex)&&(topDrawnItemPos.itemIndex > refreshItemPos.itemIndex)))
605 RefreshItemLayout(topDrawnItemPos, refreshItemPos, type, false);
607 float newScrollPosition = prevScrollPosition - (prevScrollAreaHeight - GetScrollAreaBounds().height);
609 __lockLoadItemWithScroll = true;
611 SetScrollPosition(newScrollPosition, false);
613 __lockLoadItemWithScroll = false;
617 RefreshItemLayout(topDrawnItemPos, refreshItemPos, type, animation);
620 RestoreEditCopyPasteManager();
626 _TableViewPresenter::RefreshAllItems(void)
628 result r = E_SUCCESS;
629 TableViewItemTag itemTag = {-1, -1};
630 TableViewItemTag lastLoadedItemTag = {-1, -1};
632 __pListModel->GetLastLoadedItemIndex(lastLoadedItemTag.groupIndex, lastLoadedItemTag.itemIndex);
633 __pListModel->GetFirstLoadedItemIndex(itemTag.groupIndex, itemTag.itemIndex);
637 _TableViewItem* pItem = FindItem(itemTag);
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));
647 if ((itemTag.itemIndex == lastLoadedItemTag.itemIndex) && (itemTag.groupIndex == lastLoadedItemTag.groupIndex))
651 } while (GetNextItemPosition(itemTag, itemTag));
657 _TableViewPresenter::UpdateTableView(bool isRestoreAnnexFocusValue)
659 if (__focusItemTag.groupIndex != -1 && __pTableView->IsTableViewFocused() && __pTableView->IsFocusModeStateEnabled()
660 && __pTableView->GetRootWindow() && __pTableView->GetRootWindow()->IsActivated())
662 __isRestoreFocus = true;
665 if (!__isRestoreFocus)
667 __focusItemTag.groupIndex = -1;
668 __focusItemTag.itemIndex = -1;
669 __isTableViewFocused = false;
670 __isAnnexFocused = false;
673 if (!isRestoreAnnexFocusValue)
675 __isAnnexFocused = false;
678 if (__isUpdatingTableView)
683 __isUpdatingTableView = true;
685 _VisualElement* pVisualElement = __pTableView->GetVisualElement();
687 if (pVisualElement != null)
689 pVisualElement->RemoveAllAnimations();
693 if (__modelInitialized == false)
695 SetItemDrawingProperty();
703 __pListModel->RemoveAllItem(false, false);
709 TableViewItemTag topDrawnTag = {-1, -1};
710 float shiftingDistance = 0;
714 GetTopDrawnItem(topDrawnTag);
716 if (__pListModel->IsValidItem(topDrawnTag.groupIndex, topDrawnTag.itemIndex))
718 _TableViewItem* pItem = FindItem(topDrawnTag);
722 shiftingDistance = GetScrollPosition() - pItem->GetBoundsF().y;
726 __pListModel->RemoveAllItem(false, true);
728 PreloadItem(topDrawnTag.groupIndex, topDrawnTag.itemIndex, shiftingDistance);
730 if (__isRestoreFocus)
732 __pTableView->SetFocused(true);
733 __pTableView->DrawFocus();
734 __isRestoreFocus = false;
737 __statusChangedFlag = true;
739 if (__itemTouchReleasedEventState == TABLE_VIEW_ITEM_TOUCH_RELEASED_EVENT_FIRE)
741 __itemTouchReleasedEventState = TABLE_VIEW_ITEM_TOUCH_RELEASED_EVENT_UPDATE_TABLE_VIEW;
746 if (IsEmpty() == true)
748 __pTableView->SetFocusNavigateEnabled(false);
752 __pTableView->SetFocusNavigateEnabled(true);
755 __isUpdatingTableView = false;
761 _TableViewPresenter::AdjustLayoutItems(float scrollPosition)
763 TableViewItemTag lastLoadedItemPos = {-1, -1};
764 TableViewItemTag firstLoadedItemPos = {-1, -1};
765 TableViewItemTag currentItemPos = {-1, -1};
766 _TableViewItem* pItem = null;
768 __pListModel->GetFirstLoadedItemIndex(firstLoadedItemPos.groupIndex, firstLoadedItemPos.itemIndex);
769 __pListModel->GetLastLoadedItemIndex(lastLoadedItemPos.groupIndex, lastLoadedItemPos.itemIndex);
771 pItem = FindItem(firstLoadedItemPos);
775 float positionY = pItem->GetPositionF().y;
777 currentItemPos = firstLoadedItemPos;
779 while (!_FloatCompareLE(positionY, scrollPosition) && GetPreviousItemPosition(currentItemPos, currentItemPos))
781 pItem = LoadItem(currentItemPos.groupIndex, currentItemPos.itemIndex);
788 positionY = pItem->GetPositionF().y;
792 pItem = FindItem(lastLoadedItemPos);
796 float positionY = pItem->GetPositionF().y;
797 float itemHeight = pItem->GetBoundsF().height;
798 float limitScreenArea = scrollPosition + __pTableView->GetBoundsF().height;
799 currentItemPos = lastLoadedItemPos;
801 while ((positionY + itemHeight < limitScreenArea) && GetNextItemPosition(currentItemPos, currentItemPos))
803 pItem = LoadItem(currentItemPos.groupIndex, currentItemPos.itemIndex);
810 positionY = pItem->GetPositionF().y;
811 itemHeight = pItem->GetBoundsF().height;
817 _TableViewPresenter::ResetItemLayout(TableViewItemTag& topDrawnItemTag, float shiftingDistance)
819 if (__pListModel->IsValidItem(topDrawnItemTag.groupIndex, topDrawnItemTag.itemIndex) == false)
826 _TableViewItem* pItem = LoadItem(topDrawnItemTag.groupIndex, topDrawnItemTag.itemIndex);
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();
839 itemBounds.y = CalculateItemPositionY(itemPos.groupIndex, itemPos.itemIndex);
840 pItem->SetBounds(itemBounds);
841 CheckItemHeightAndRefreshLayout(itemPos, true);
843 loadedItemTotalHeight += itemBounds.height;
845 while (loadedItemTotalHeight < screenAreaHeight && GetNextItemPosition(currentItem, itemPos))
847 pItem = LoadItem(itemPos.groupIndex, itemPos.itemIndex);
854 currentItem = itemPos;
855 loadedItemTotalHeight += pItem->GetBoundsF().height;
858 if (loadedItemTotalHeight < screenAreaHeight)
860 __pListModel->GetFirstLoadedItemIndex(itemPos.groupIndex, itemPos.itemIndex);
861 currentItem = itemPos;
863 while (loadedItemTotalHeight < screenAreaHeight && GetPreviousItemPosition(currentItem, itemPos))
865 pItem = LoadItem(itemPos.groupIndex, itemPos.itemIndex);
872 currentItem = itemPos;
873 loadedItemTotalHeight += pItem->GetBoundsF().height;
879 _TableViewPresenter::IsCachingItemsTotalHeightLessThanViewHeight(void)
881 int currentCachingsize = GetMaxItemCachingSize();
882 int loadedItemCount = 0;
883 float itemTotalHeight = 0.0f;
884 float viewHeight = __pTableView->GetBoundsF().height;
885 float lastItemHeight = 0.0f;
887 TableViewItemTag lastLoadedItemPos = {-1, -1};
888 TableViewItemTag firstLoadedItemPos = {-1, -1};
890 __pListModel->GetFirstLoadedItemIndex(firstLoadedItemPos.groupIndex, firstLoadedItemPos.itemIndex);
891 __pListModel->GetLastLoadedItemIndex(lastLoadedItemPos.groupIndex, lastLoadedItemPos.itemIndex);
895 _TableViewItem* pItem = FindItem(firstLoadedItemPos);
899 itemTotalHeight = itemTotalHeight + pItem->GetSizeF().height;
900 lastItemHeight = pItem->GetSizeF().height;
904 if ((firstLoadedItemPos.itemIndex == lastLoadedItemPos.itemIndex) && (firstLoadedItemPos.groupIndex == lastLoadedItemPos.groupIndex))
908 } while (GetNextItemPosition(firstLoadedItemPos, firstLoadedItemPos));
910 if (loadedItemCount < currentCachingsize || viewHeight < (itemTotalHeight - lastItemHeight))
919 _TableViewPresenter::GetFirstLoadedItemIndex(int& groupIndex, int& itemIndex) const
921 __pListModel->GetFirstLoadedItemIndex(groupIndex, itemIndex);
925 _TableViewPresenter::GetLastLoadedItemIndex(int& groupIndex, int& itemIndex) const
927 __pListModel->GetLastLoadedItemIndex(groupIndex, itemIndex);
931 _TableViewPresenter::RefreshItemLayout(int groupIndex, int itemIndex)
933 TableViewItemTag itemTag = {groupIndex, itemIndex};
937 RefreshItemLayout(itemTag, itemTag, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY, false);
941 _TableViewPresenter::RefreshItemLayout(TableViewItemTag& topDrawnItemTag, TableViewItemTag& refreshItemTag, TableViewRefreshType type, bool animation)
943 if (!__pListModel->IsValidItem(topDrawnItemTag.groupIndex, topDrawnItemTag.itemIndex))
948 if (refreshItemTag.itemIndex == -1)
953 _TableViewItem* pItem = null;
955 TableViewItemTag itemPos = {-1, -1};
956 TableViewItemTag currentItem = {-1, -1};
958 int loadItemCount = 0;
959 int maxLoadItemCount = GetMaxItemCachingSize();
960 FloatRectangle itemBounds(0.0f, 0.0f, 0.0f, 0.0f);
962 StopAllItemAnimation();
964 __pListModel->GetFirstLoadedItemIndex(itemPos.groupIndex, itemPos.itemIndex);
966 if (itemPos.groupIndex == -1 && itemPos.itemIndex == -1)
968 itemPos = topDrawnItemTag;
971 currentItem = itemPos;
973 float itemPositionY = CalculateItemPositionY(itemPos.groupIndex, itemPos.itemIndex);
977 pItem = LoadItem(itemPos.groupIndex, itemPos.itemIndex);
984 if (pItem->HasParent())
986 pItem->SetDrawingProperty(__pItemDrawingProperty);
987 SetItemType(pItem, itemPos);
990 itemBounds = pItem->GetBoundsF();
991 itemBounds.y = itemPositionY;
995 if (type == TABLE_VIEW_REFRESH_TYPE_ITEM_ADD)
997 if (itemPos.groupIndex == refreshItemTag.groupIndex && itemPos.itemIndex == refreshItemTag.itemIndex)
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);
1005 if (!pItem->MoveItem(FloatPoint(itemBounds.x, itemBounds.y), ADD_ITEM_ANIMATION_DURATION, 0))
1007 pItem->SetBounds(itemBounds);
1013 if (!pItem->MoveItem(FloatPoint(itemBounds.x, itemBounds.y), REMOVE_ITEM_MOVE_ANIMATION_DURATION, REFRESH_ITEM_ANIMATION_DELAY))
1015 pItem->SetBounds(itemBounds);
1021 pItem->SetBounds(itemBounds);
1024 currentItem = itemPos;
1025 itemPositionY = itemBounds.y + itemBounds.height;
1029 } while (loadItemCount < maxLoadItemCount && GetNextItemPosition(currentItem, itemPos));
1031 if (loadItemCount < maxLoadItemCount)
1033 __pListModel->GetFirstLoadedItemIndex(itemPos.groupIndex, itemPos.itemIndex);
1034 currentItem = itemPos;
1036 while (loadItemCount < maxLoadItemCount && GetPreviousItemPosition(currentItem, itemPos))
1038 pItem = LoadItem(itemPos.groupIndex, itemPos.itemIndex);
1045 currentItem = itemPos;
1051 if (refreshItemTag.itemIndex == -1)
1053 ScrollToItem(topDrawnItemTag.groupIndex, topDrawnItemTag.itemIndex, TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_TOP);
1058 _TableViewPresenter::RefreshItemBounds(_TableViewItem* pItem, TableViewItemTag& itemPos)
1060 FloatRectangle itemBounds;
1067 itemBounds = pItem->GetBoundsF();
1069 itemBounds.y = CalculateItemPositionY(itemPos.groupIndex, itemPos.itemIndex);
1071 if (itemPos.itemIndex != -1)
1073 float itemMargin = GetLeftMargin();
1074 itemBounds.x = itemMargin;
1075 itemBounds.width = __pItemDrawingProperty->width - itemBounds.x - itemMargin;
1079 itemBounds.x = 0.0f;
1080 itemBounds.width = __pItemDrawingProperty->width;
1083 pItem->SetBounds(itemBounds);
1087 _TableViewPresenter::GetItemIndexFromPosition(const FloatPoint& position, int& groupIndex, int& itemIndex) const
1089 result r = E_SUCCESS;
1090 TableViewItemTag itemPos;
1092 FloatPoint targetPosition = position;
1093 float scrollPosition = GetScrollPosition();
1094 targetPosition.y += scrollPosition;
1096 r = GetItemFromPosition(targetPosition, itemPos);
1105 groupIndex = itemPos.groupIndex;
1106 itemIndex = itemPos.itemIndex;
1113 _TableViewPresenter::PreloadItem(void)
1115 if (GetModel() == null || __pProviderAdaptor == null)
1120 __modelInitialized = true;
1122 if (__pListModel->GetAllGroupCount() == 0 && (__pProviderAdaptor != null))
1125 int groupCount = __pProviderAdaptor->GetGroupCount();
1127 for (int i = 0; i < groupCount; i++)
1129 itemCount = __pProviderAdaptor->GetItemCount(i);
1130 __pListModel->AddGroup(itemCount, false);
1134 __pListModel->RestoreItemStatus();
1136 CreateItemHeightList(TABLEVIEW_DEFAULT_ITEM_HEIGHT_VALUE, TABLEVIEW_DEFAULT_ITEM_HEIGHT_VALUE);
1137 CreateSectionAlignmentList();
1139 int cachingSize = 0;
1141 if (GetItemCount() > TABLEVIEW_MAX_ITEM_COUNT)
1143 cachingSize = TABLEVIEW_MAX_ITEM_COUNT;
1145 else if (__pListModel->GetMaxCachingSize() < TABLEVIEW_MAX_ITEM_COUNT)
1147 cachingSize = __pListModel->GetMaxCachingSize();
1151 cachingSize = GetItemCount();
1154 TableViewItemTag itemPos = {-1, -1};
1155 GetFirstItem(itemPos);
1157 _TableViewItem* pItem = null;
1158 for (int i = 0; i < cachingSize; i++)
1160 pItem = LoadItem(itemPos.groupIndex, itemPos.itemIndex);
1167 if (GetNextItemPosition(itemPos, itemPos) == false)
1173 if (IsCachingItemsTotalHeightLessThanViewHeight())
1175 AdjustLayoutItems(0.0f);
1178 PresetItemHeightList();
1179 AdjustClientAreaBounds(true);
1181 TableViewScrollBarStyle scrollStyle = __pTableView->GetScrollStyle();
1183 if (scrollStyle == TABLE_VIEW_SCROLL_BAR_STYLE_FAST_SCROLL
1184 || scrollStyle == TABLE_VIEW_SCROLL_BAR_STYLE_FAST_SCROLL_FIXED)
1186 _FastScroll* pFastScroll = __pTableView->GetFastScrollBar();
1187 if (pFastScroll != null)
1189 pFastScroll->UpdateIndex();
1190 pFastScroll->SetScrollVisibility(IsScrollable());
1193 else if (scrollStyle != TABLE_VIEW_SCROLL_BAR_STYLE_NONE)
1205 _TableViewPresenter::PreloadItem(int topDrawnGroupIndex, int topDrawnItemIndex, float shiftingDistance)
1207 if (GetModel() == null || __pProviderAdaptor == null)
1212 __modelInitialized = true;
1214 if (__pListModel->GetAllGroupCount() == 0 && (__pProviderAdaptor != null))
1217 int groupCount = __pProviderAdaptor->GetGroupCount();
1219 for (int i = 0; i < groupCount; i++)
1221 itemCount = __pProviderAdaptor->GetItemCount(i);
1222 __pListModel->AddGroup(itemCount, false);
1226 float defaultGroupHeight = __pProviderAdaptor->GetDefaultGroupItemHeight();
1227 float defaultItemHeight = __pProviderAdaptor->GetDefaultItemHeight();
1229 if (_FloatCompareLE(defaultGroupHeight, 0.0f))
1231 defaultGroupHeight = TABLEVIEW_DEFAULT_ITEM_HEIGHT_VALUE;
1234 if (_FloatCompareLE(defaultItemHeight, 0.0f))
1236 defaultItemHeight = TABLEVIEW_DEFAULT_ITEM_HEIGHT_VALUE;
1239 __pListModel->RestoreItemStatus();
1241 RestoreItemHeightList(defaultGroupHeight, defaultItemHeight);
1243 DeleteSectionAlignmentList();
1244 CreateSectionAlignmentList();
1246 if (!__pListModel->IsValidItem(topDrawnGroupIndex, topDrawnItemIndex))
1248 TableViewItemTag firstItemTag = {-1, -1};
1250 GetFirstItem(firstItemTag);
1252 topDrawnGroupIndex = firstItemTag.groupIndex;
1253 topDrawnItemIndex = firstItemTag.itemIndex;
1255 shiftingDistance = 0.0f;
1258 AdjustClientAreaBounds(true);
1260 ScrollToItem(topDrawnGroupIndex, topDrawnItemIndex, TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_TOP, shiftingDistance);
1262 if (IsCachingItemsTotalHeightLessThanViewHeight())
1264 AdjustLayoutItems(GetScrollPosition());
1267 if (__pTableView->GetScrollStyle() == TABLE_VIEW_SCROLL_BAR_STYLE_FAST_SCROLL
1268 || __pTableView->GetScrollStyle() == TABLE_VIEW_SCROLL_BAR_STYLE_FAST_SCROLL_FIXED)
1270 _FastScroll* pFastScroll = __pTableView->GetFastScrollBar();
1271 if (pFastScroll != null)
1273 pFastScroll->UpdateIndex();
1274 pFastScroll->SetScrollVisibility(IsScrollable());
1282 _TableViewPresenter::IsItemChecked(int groupIndex, int itemIndex) const
1284 if ((groupIndex < 0) || (groupIndex >= GetGroupCount()) || (itemIndex < -1) || (itemIndex >= GetItemCountAt(groupIndex)))
1289 return __pListModel->IsItemChecked(groupIndex, itemIndex);
1293 _TableViewPresenter::SetItemChecked(int groupIndex, int itemIndex, bool checked)
1295 if ((groupIndex < 0) || (groupIndex >= GetGroupCount()) || (itemIndex < -1) || (itemIndex >= GetItemCountAt(groupIndex)))
1297 return E_OUT_OF_RANGE;
1300 if (__modelInitialized == false)
1302 return E_INVALID_STATE;
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));
1308 if (__pListModel->IsItemChecked(groupIndex, itemIndex) == checked)
1313 TableViewItemTag itemTag = {groupIndex, itemIndex};
1314 _TableViewItem* pItem = FindItem(itemTag);
1316 TableViewItemTag topDrawnItemTag = {-1, -1};
1317 GetTopDrawnItem(topDrawnItemTag);
1319 TableViewItemTag bottomDrawnItemTag = {-1, -1};
1320 GetBottomDrawnItem(bottomDrawnItemTag);
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))
1329 pItem->SetCheckedAnimationEnabled(checked);
1333 result r = __pListModel->SetItemChecked(groupIndex, itemIndex, checked);
1339 _TableViewPresenter::IsItemEnabled(int groupIndex, int itemIndex) const
1341 if ((groupIndex < 0) || (groupIndex >= GetGroupCount()) || (itemIndex < -1) || (itemIndex >= GetItemCountAt(groupIndex)))
1346 return __pListModel->IsItemEnabled(groupIndex, itemIndex);
1350 _TableViewPresenter::SetItemEnabled(int groupIndex, int itemIndex, bool enabled)
1352 if ((groupIndex < 0) || (groupIndex >= GetGroupCount()) || (itemIndex < -1) || (itemIndex >= GetItemCountAt(groupIndex)))
1354 return E_OUT_OF_RANGE;
1357 if (__pListModel->IsItemEnabled(groupIndex, itemIndex) == enabled)
1362 result r = __pListModel->SetItemEnabled(groupIndex, itemIndex, enabled);
1368 _TableViewPresenter::SetStatusChanged(bool changed)
1370 __statusChangedFlag = changed;
1372 if (__statusChangedFlag == true)
1374 SetItemDrawingProperty();
1376 if ((__pItemDrawingProperty != null) && (__pItemDrawingProperty->propertyChanged == true))
1378 __pListModel->SetAllLoadedItemStateChanged(true);
1386 _TableViewPresenter::IsStatusChanged(void) const
1388 return __statusChangedFlag;
1392 _TableViewPresenter::GetTopMargin(void) const
1398 _TableViewPresenter::SetTopMargin(float topMargin)
1400 __topMargin = topMargin;
1406 _TableViewPresenter::GetBottomMargin(void) const
1408 return __bottomMargin;
1412 _TableViewPresenter::SetBottomMargin(float bottomMargin)
1414 __bottomMargin = bottomMargin;
1420 _TableViewPresenter::GetLeftMargin(void) const
1422 return __leftMargin;
1426 _TableViewPresenter::SetLeftMargin(float leftMargin)
1428 __leftMargin = leftMargin;
1434 _TableViewPresenter::SetAnnexFocused(bool isAnnexFocused)
1436 __isAnnexFocused = isAnnexFocused;
1440 _TableViewPresenter::IsAnnexFocused(void)
1442 return __isAnnexFocused;
1446 _TableViewPresenter::SetTableViewFocused(bool focusStatus)
1448 if (focusStatus == false)
1450 __focusItemTag.groupIndex = -1;
1451 __focusItemTag.itemIndex = -1;
1452 __isRestoreFocus = false;
1453 __isAnnexFocused = false;
1455 __isTableViewFocused = focusStatus;
1459 _TableViewPresenter::IsTableViewFocused(void)
1461 return __isTableViewFocused;
1465 _TableViewPresenter::GetFocusedItemIndex(int& groupIndex, int& itemIndex) const
1467 result r = E_SUCCESS;
1469 groupIndex = __focusItemTag.groupIndex;
1470 itemIndex = __focusItemTag.itemIndex;
1476 _TableViewPresenter::SetItemType(_TableViewItem* pItem, TableViewItemTag itemPosition)
1478 TableViewStyle style = __pTableView->GetTableViewStyle();
1480 if (itemPosition.itemIndex == -1)
1482 if (style == TABLE_VIEW_STYLE_SECTION)
1484 pItem->SetItemType(TABLE_VIEW_ITEM_TYPE_HEADER);
1488 pItem->SetItemType(TABLE_VIEW_ITEM_TYPE_TITLE);
1493 int itemCount = GetItemCountAt(itemPosition.groupIndex);
1494 if (style == TABLE_VIEW_STYLE_SIMPLE)
1496 if (itemCount == 1 || (itemCount > 1 && (itemPosition.itemIndex == itemCount - 1)))
1498 pItem->SetSimpleLastItemEnabled(true);
1502 pItem->SetSimpleLastItemEnabled(false);
1505 if (style == TABLE_VIEW_STYLE_SECTION)
1507 pItem->SetSectionItem(true);
1510 if (itemPosition.itemIndex == 0)
1512 if (HasSectionFooter(itemPosition.groupIndex))
1516 pItem->SetItemType(TABLE_VIEW_ITEM_TYPE_FOOTER);
1518 else if (itemCount == 2)
1520 pItem->SetItemType(TABLE_VIEW_ITEM_TYPE_ONE);
1524 pItem->SetItemType(TABLE_VIEW_ITEM_TYPE_TOP);
1531 pItem->SetItemType(TABLE_VIEW_ITEM_TYPE_ONE);
1535 pItem->SetItemType(TABLE_VIEW_ITEM_TYPE_TOP);
1541 int lastItemIndex = itemCount - 1;
1543 if (HasSectionFooter(itemPosition.groupIndex))
1545 if (itemPosition.itemIndex == lastItemIndex)
1547 pItem->SetItemType(TABLE_VIEW_ITEM_TYPE_FOOTER);
1549 else if (itemPosition.itemIndex == lastItemIndex - 1)
1551 pItem->SetItemType(TABLE_VIEW_ITEM_TYPE_BOTTOM);
1555 pItem->SetItemType(TABLE_VIEW_ITEM_TYPE_MIDDLE);
1560 if (itemPosition.itemIndex == lastItemIndex)
1562 pItem->SetItemType(TABLE_VIEW_ITEM_TYPE_BOTTOM);
1566 pItem->SetItemType(TABLE_VIEW_ITEM_TYPE_MIDDLE);
1574 _TableViewPresenter::SetItemLayout(_TableViewItem* pItem, TableViewItemTag& itemPos)
1576 _TableViewItem* pSeriesItem = null;
1577 TableViewItemTag seriesItemPos = {-1, -1};
1578 FloatRectangle seriesItemBounds;
1579 FloatRectangle itemBounds;
1580 bool validBounds = false;
1581 bool downScroll = true;
1583 if (itemPos.itemIndex == -1 && __pTableView->GetTableViewStyle() != TABLE_VIEW_STYLE_SECTION)
1586 itemBounds.width = __pItemDrawingProperty->width;
1590 float itemMargin = GetLeftMargin();
1591 itemBounds.x = itemMargin;
1592 itemBounds.width = __pItemDrawingProperty->width - itemBounds.x - itemMargin;
1595 FloatDimension itemDimension = Tizen::Graphics::CoordinateSystem::AlignToDevice(FloatDimension(pItem->GetSizeF().width, pItem->GetSizeF().height));
1596 itemBounds.height = itemDimension.height;
1598 if (itemPos.groupIndex == 0 && itemPos.itemIndex == -1)
1600 itemBounds.y = GetTopMargin();
1605 if (GetPreviousItemPosition(itemPos, seriesItemPos))
1607 if (__pListModel->IsLoadedItem(seriesItemPos.groupIndex, seriesItemPos.itemIndex))
1609 pSeriesItem = static_cast<_TableViewItem*>(__pListModel->LoadItem(seriesItemPos.groupIndex, seriesItemPos.itemIndex));
1610 if ((pSeriesItem != null) && pSeriesItem->HasParent())
1612 if (__pTableView->IsReorderModeEnabled() && (__reorderInfo.groupIndex == seriesItemPos.groupIndex && __reorderInfo.itemIndex == seriesItemPos.itemIndex))
1614 seriesItemBounds = __reorderInfo.itemBounds;
1618 seriesItemBounds = pSeriesItem->GetBoundsF();
1621 itemBounds.y = seriesItemBounds.y + seriesItemBounds.height;
1628 if ((!validBounds) && GetNextItemPosition(itemPos, seriesItemPos))
1630 if (__pListModel->IsLoadedItem(seriesItemPos.groupIndex, seriesItemPos.itemIndex))
1632 pSeriesItem = static_cast<_TableViewItem*>(__pListModel->LoadItem(seriesItemPos.groupIndex, seriesItemPos.itemIndex));
1633 if ((pSeriesItem != null) && pSeriesItem->HasParent())
1635 if (__pTableView->IsReorderModeEnabled() && (__reorderInfo.groupIndex == seriesItemPos.groupIndex && __reorderInfo.itemIndex == seriesItemPos.itemIndex))
1637 seriesItemBounds = __reorderInfo.itemBounds;
1641 seriesItemBounds = pSeriesItem->GetBoundsF();
1644 itemBounds.y = seriesItemBounds.y - itemBounds.height;
1655 pItem->SetBounds(itemBounds);
1657 CheckItemHeightAndRefreshLayout(itemPos, downScroll);
1661 itemBounds.y = CalculateItemPositionY(itemPos.groupIndex, itemPos.itemIndex);
1662 pItem->SetBounds(itemBounds);
1664 CheckItemHeightAndRefreshLayout(itemPos, true);
1667 if (__pTableView->IsReorderModeEnabled() && __reorderInfo.itemIndex != -1)
1669 TableViewItemTag reorderSelectedItemTag = {__reorderInfo.groupIndex, __reorderInfo.itemIndex};
1670 _TableViewItem* pReorderSelectedItem = FindItem(reorderSelectedItemTag);
1672 if (pReorderSelectedItem != null)
1674 pReorderSelectedItem->GetVisualElement()->SetZOrder(null, true);
1678 if (pItem->GetItemLayoutEnabled())
1680 pItem->PartialUpdateLayout();
1685 _TableViewPresenter::LoadItem(int groupIndex, int itemIndex)
1687 _TableViewItem* pItem = static_cast<_TableViewItem*>(__pListModel->LoadItem(groupIndex, itemIndex));
1689 if ((pItem != null) && !pItem->HasParent())
1691 __lockLoadItemWithScroll = true;
1693 __pTableView->AttachChild(*pItem);
1695 pItem->SetDrawingProperty(__pItemDrawingProperty);
1697 TableViewItemTag itemPosition = {groupIndex, itemIndex};
1698 SetItemType(pItem, itemPosition);
1699 SetItemLayout(pItem, itemPosition);
1700 pItem->SetReorderMode(__pTableView->IsReorderModeEnabled());
1702 __lockLoadItemWithScroll = false;
1709 _TableViewPresenter::FindItem(TableViewItemTag& itemTag)
1711 if (__pListModel->IsLoadedItem(itemTag.groupIndex, itemTag.itemIndex))
1713 return static_cast<_TableViewItem*>(__pListModel->LoadItem(itemTag.groupIndex, itemTag.itemIndex));
1719 _TableViewPresenter::UnloadItem(int groupIndex, int itemIndex)
1721 __pListModel->UnloadItem(groupIndex, itemIndex);
1725 _TableViewPresenter::UnloadItem(TableViewItemTag& itemTag)
1727 __pListModel->UnloadItem(itemTag.groupIndex, itemTag.itemIndex);
1733 _TableViewPresenter::DetachItem(TableViewItemTag& itemTag)
1735 _TableViewItem* pItem = FindItem(itemTag);
1737 if (pItem != null && pItem->HasParent())
1739 pItem->GetParent()->DetachChild(*pItem);
1744 _TableViewPresenter::DetachContextItem(TableViewItemTag& itemTag)
1746 _TableViewItem* pItem = FindItem(itemTag);
1752 _TableViewItem* contextItem = pItem->GetContextItem();
1753 if (contextItem != null && contextItem->HasParent())
1755 contextItem->GetParent()->DetachChild(*pItem);
1760 _TableViewPresenter::DetachAllItem(bool removeItem)
1762 TableViewItemTag itemPos = {-1, -1};
1763 TableViewItemTag lastItemPos = {-1, -1};
1765 __pListModel->GetFirstLoadedItemIndex(itemPos.groupIndex, itemPos.itemIndex);
1766 __pListModel->GetLastLoadedItemIndex(lastItemPos.groupIndex, lastItemPos.itemIndex);
1768 if (itemPos.groupIndex == -1 && itemPos.itemIndex == -1)
1775 DetachItem(itemPos);
1779 UnloadItem(itemPos);
1782 if (itemPos.itemIndex == lastItemPos.itemIndex && itemPos.groupIndex == lastItemPos.groupIndex)
1786 } while (GetNextItemPosition(itemPos, itemPos));
1790 _TableViewPresenter::SetItemDrawingProperty(void)
1792 if (__pItemDrawingProperty != null)
1794 __pItemDrawingProperty->propertyChanged = false;
1796 if (__pItemDrawingProperty->itemDividerEnabled != __pTableView->IsItemDividerEnabled())
1798 __pItemDrawingProperty->itemDividerEnabled = __pTableView->IsItemDividerEnabled();
1799 __pItemDrawingProperty->propertyChanged = true;
1802 if (__pItemDrawingProperty->dividerColor != __pTableView->GetItemDividerColor())
1804 __pItemDrawingProperty->dividerColor = __pTableView->GetItemDividerColor();
1805 __pItemDrawingProperty->propertyChanged = true;
1808 if (__pItemDrawingProperty->sectionStyleEnabled != (__pTableView->GetTableViewStyle() == TABLE_VIEW_STYLE_SECTION))
1810 __pItemDrawingProperty->sectionStyleEnabled = (__pTableView->GetTableViewStyle() == TABLE_VIEW_STYLE_SECTION);
1811 __pItemDrawingProperty->propertyChanged = true;
1814 if (__pItemDrawingProperty->sectionStyleBgColor != __pTableView->GetSectionColor())
1816 __pItemDrawingProperty->sectionStyleBgColor = __pTableView->GetSectionColor();
1817 __pItemDrawingProperty->propertyChanged = true;
1820 if (__pTableView->GetTableViewStyle() != TABLE_VIEW_STYLE_SIMPLE)
1822 if (__pItemDrawingProperty->groupedLookEnabled != __pTableView->IsGroupedLookEnabled())
1824 __pItemDrawingProperty->groupedLookEnabled = __pTableView->IsGroupedLookEnabled();
1825 __pItemDrawingProperty->propertyChanged = true;
1829 if (__pItemDrawingProperty->reorderMode != __pTableView->IsReorderModeEnabled())
1831 __pItemDrawingProperty->reorderMode = __pTableView->IsReorderModeEnabled();
1832 __pItemDrawingProperty->propertyChanged = true;
1835 if (!_FloatCompare(__pItemDrawingProperty->leftMargin, __leftMargin))
1837 __pItemDrawingProperty->leftMargin = __leftMargin;
1838 __pItemDrawingProperty->propertyChanged = true;
1841 if (__pTableView->GetScrollStyle() == TABLE_VIEW_SCROLL_BAR_STYLE_FAST_SCROLL_FIXED)
1843 GET_SHAPE_CONFIG(TABLEVIEW::FASTSCROLL_INDEX_WIDTH, _CONTROL_ORIENTATION_PORTRAIT,
1844 __pItemDrawingProperty->scrollMargin);
1848 __pItemDrawingProperty->scrollMargin = 0;
1851 if (!_FloatCompare(__pItemDrawingProperty->width, __pTableView->GetBoundsF().width))
1853 __pItemDrawingProperty->width = __pTableView->GetBoundsF().width;
1854 __pItemDrawingProperty->propertyChanged = true;
1860 _TableViewPresenter::OnBoundsChanged(void)
1862 float listWidth = __pTableView->GetBoundsF().width - (GetLeftMargin() * 2);
1864 if (__pProviderAdaptor != null && __modelInitialized)
1866 StopExpandCollapseAnimation();
1868 if (__pTableView->IsReorderModeEnabled() && __reorderInfo.itemIndex != -1)
1870 ResetReorderItem(__reorderInfo.groupIndex, __reorderInfo.itemIndex);
1873 if (!_FloatCompare(listWidth, __pProviderAdaptor->GetListWidth()))
1875 __pProviderAdaptor->SetListWidth(listWidth);
1877 SetItemDrawingProperty();
1879 AdjustLoadedItemWidth();
1881 __pTableView->UpdateLayout();
1884 SetClientAreaHeight(__itemTotalHeight);
1887 AdjustLayoutItems(GetScrollPosition());
1891 if (__pProviderAdaptor != null)
1893 __pProviderAdaptor->SetListWidth(listWidth);
1896 SetClientAreaHeight(__pTableView->GetBoundsF().height);
1897 _ScrollPanelPresenter::OnBoundsChanged();
1900 //FastScroll Visibility
1901 if (__isOrientationChanged)
1903 TableViewScrollBarStyle scrollStyle = __pTableView->GetScrollStyle();
1905 if (scrollStyle == TABLE_VIEW_SCROLL_BAR_STYLE_FAST_SCROLL
1906 || scrollStyle == TABLE_VIEW_SCROLL_BAR_STYLE_FAST_SCROLL_FIXED)
1908 _FastScroll* pFastScroll = __pTableView->GetFastScrollBar();
1909 if (pFastScroll != null)
1911 pFastScroll->UpdateIndex();
1912 pFastScroll->SetScrollVisibility(IsScrollable());
1916 __isOrientationChanged = false;
1921 _TableViewPresenter::Draw(void)
1923 result r = _ScrollPanelPresenter::Draw();
1924 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1926 if (__modelInitialized == false)
1928 SetItemDrawingProperty();
1930 if(PreloadItem() == false)
1932 __pTableView->SetFocusNavigateEnabled(false);
1936 if (__reservedScrollItemIndex.groupIndex != -1 && __reservedScrollItemIndex.itemIndex != -1)
1938 ScrollToItem(__reservedScrollItemIndex.groupIndex, __reservedScrollItemIndex.itemIndex, __reservedScrollItemAlignment);
1940 __reservedScrollItemIndex.groupIndex = -1;
1941 __reservedScrollItemIndex.itemIndex = -1;
1947 __firstDrawnFlag = false;
1950 if (IsEmpty() == true)
1952 __pTableView->SetFocusNavigateEnabled(false);
1953 return DrawEmptyTableView();
1957 __pTableView->SetFocusNavigateEnabled(true);
1960 if (!__isRestoreFocus && __isFocusedDuringOrientationChange)
1962 TableViewItemTag bottomDrawnItemIndex = {-1, -1};
1963 GetBottomDrawnItem(bottomDrawnItemIndex);
1965 if ((bottomDrawnItemIndex.groupIndex < __focusItemTag.groupIndex) ||
1966 (bottomDrawnItemIndex.groupIndex == __focusItemTag.groupIndex && bottomDrawnItemIndex.itemIndex <= __focusItemTag.itemIndex))
1968 ScrollToItem(__focusItemTag.groupIndex, __focusItemTag.itemIndex, TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_BOTTOM);
1971 __isFocusedDuringOrientationChange = false;
1976 _TableViewPresenter::OnChangeLayout(_ControlOrientation orientation)
1978 __isOrientationChanged = true;
1979 if (__focusItemTag.groupIndex != -1)
1981 __isFocusedDuringOrientationChange = true;
1985 _UiTouchEventDelivery
1986 _TableViewPresenter::OnPreviewTouchPressed(const _Control& source, const _TouchInfo& touchInfo)
1988 _UiTouchEventDelivery response = _ScrollPanelPresenter::OnPreviewTouchPressed(source, touchInfo);
1990 if (__focusItemTag.groupIndex != -1)
1992 _TableViewItem* pItem = FindItem(__focusItemTag);
1995 pItem->ResetItemState();
1998 __focusItemTag.groupIndex = -1;
1999 __focusItemTag.itemIndex = -1;
2001 _TableViewItem* pItem = GetTableViewItemFromControl(source);
2007 TableViewItemTag itemPos = {-1, -1};
2009 pItem->GetItemIndex(itemPos.groupIndex, itemPos.itemIndex);
2011 if (itemPos.groupIndex == -1 && itemPos.itemIndex == -1)
2016 if (IsScrollAnimationRunning() && (GetScrollPosition() == GetScrollPositionInternal()))
2018 pItem->SetTouchPressOnScroll(true);
2022 if (__pTableView->IsReorderModeEnabled())
2024 __firstTouchMoved = true;
2026 if (SelectReorderItem(itemPos.groupIndex, itemPos.itemIndex, false))
2028 __reorderInfo.touchPressedPositionY = touchInfo.GetCurrentPosition().y;
2035 _UiTouchEventDelivery
2036 _TableViewPresenter::OnPreviewTouchMoved(const _Control& source, const _TouchInfo& touchInfo)
2038 if (__pTableView->IsReorderModeEnabled())
2040 if (__reorderInfo.itemIndex != -1)
2042 if (!DragSelectedItem(touchInfo.GetCurrentPosition().y - __reorderInfo.touchPressedPositionY, true))
2044 __firstTouchMoved = false;
2046 ResetReorderItem(__reorderInfo.groupIndex, __reorderInfo.itemIndex);
2049 return _UI_TOUCH_EVENT_DELIVERY_NO;
2053 return _ScrollPanelPresenter::OnPreviewTouchMoved(source, touchInfo);
2056 _UiTouchEventDelivery
2057 _TableViewPresenter::OnPreviewTouchReleased(const _Control& source, const _TouchInfo& touchInfo)
2059 if (__pTableView->IsReorderModeEnabled() && __reorderInfo.itemIndex != -1)
2061 ResetReorderItem(__reorderInfo.groupIndex, __reorderInfo.itemIndex);
2063 if (__reorderInfo.blockedTouchReleaseState)
2065 __reorderInfo.blockedTouchReleaseState = false;
2067 return _UI_TOUCH_EVENT_DELIVERY_NO;
2071 return _ScrollPanelPresenter::OnPreviewTouchReleased(source, touchInfo);
2074 _UiTouchEventDelivery
2075 _TableViewPresenter::OnPreviewTouchCanceled(const _Control& source, const _TouchInfo& touchInfo)
2077 return _ScrollPanelPresenter::OnPreviewTouchCanceled(source, touchInfo);
2081 _TableViewPresenter::OnTouchPressed(const _Control& source, const _TouchInfo& touchInfo)
2083 __firstTouchMoved = true;
2085 _TableViewItem* pItem = GetTableViewItemFromControl(source);
2089 StopExpandCollapseAnimation();
2090 return _ScrollPanelPresenter::OnTouchPressed(source, touchInfo);
2093 TableViewItemTag itemPos = {-1, -1};
2094 pItem->GetItemIndex(itemPos.groupIndex, itemPos.itemIndex);
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)))
2107 __sweepOccured = false;
2109 StopExpandCollapseAnimation();
2111 return _ScrollPanelPresenter::OnTouchPressed(source, touchInfo);
2115 _TableViewPresenter::OnTouchMoved(const _Control& source, const _TouchInfo& touchInfo)
2117 if (__pTableView->IsReorderModeEnabled())
2119 if (__reorderInfo.blockedScroll)
2124 return _ScrollPanelPresenter::OnTouchMoved(source, touchInfo);
2127 _TableViewItem* pItem = GetTableViewItemFromControl(source);
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())
2135 return _ScrollPanelPresenter::OnTouchMoved(source, touchInfo);;
2138 if (__firstTouchMoved)
2140 FloatPoint prevTouchPosition = GetPreviousTouchPosition();
2141 FloatPoint currTouchPosition = GetCurrentTouchPosition();
2142 float moveDistanceX = currTouchPosition.x - prevTouchPosition.x;
2143 float moveDistanceY = currTouchPosition.y - prevTouchPosition.y;
2145 if ((pItem->GetContextItem() != null && abs(moveDistanceX) > abs(moveDistanceY * 2)) || pItem->IsContextItem())
2147 if (!pItem->IsContextItem() && !pItem->IsAnimationPlaying())
2149 pItem->GetItemIndex(__sweptItemTag.groupIndex, __sweptItemTag.itemIndex);
2150 __sweptItemPosition = pItem->GetPositionF();
2152 pItem->AdjustContextItemBounds();
2155 __sweepOccured = true;
2157 else if (pItem->GetContextItem() == null && __pTableView->IsSweepEnabled())
2159 __sweepOccured = true;
2167 __firstTouchMoved = false;
2171 FloatPoint prevTouchPosition = GetPreviousTouchPosition();
2172 FloatPoint currTouchPosition = GetCurrentTouchPosition();
2174 SweepItem(currTouchPosition.x - prevTouchPosition.x);
2179 return _ScrollPanelPresenter::OnTouchMoved(source, touchInfo);
2183 _TableViewPresenter::OnTouchReleased(const _Control& source, const _TouchInfo& touchInfo)
2185 _TableViewItem* pItem = GetTableViewItemFromControl(source);
2188 || pItem->GetItemType() == TABLE_VIEW_ITEM_TYPE_TITLE
2189 || pItem->GetItemType() == TABLE_VIEW_ITEM_TYPE_HEADER
2190 || pItem->GetItemType() == TABLE_VIEW_ITEM_TYPE_FOOTER)
2192 return _ScrollPanelPresenter::OnTouchReleased(source, touchInfo);
2197 if (pItem->IsContextItem())
2199 pItem = static_cast<_TableViewItem*>(__pListModel->LoadItem(__sweptItemTag.groupIndex, __sweptItemTag.itemIndex));
2201 _TableViewItem* pContextItem = pItem->GetContextItem();
2204 if (pContextItem == null && __pTableView->IsSweepEnabled())
2206 FloatPoint prevPos = _ScrollPanelPresenter::GetPreviousTouchPosition();
2208 if (prevPos.x > touchInfo.GetCurrentPosition().x)
2210 pItem->FireItemSweepEvent(TABLE_VIEW_SWEEP_DIRECTION_LEFT);
2212 else if (prevPos.x < touchInfo.GetCurrentPosition().x)
2214 pItem->FireItemSweepEvent(TABLE_VIEW_SWEEP_DIRECTION_RIGHT);
2219 else if (pContextItem != null)
2221 AdjustSweptItemPosition(true);
2225 return _ScrollPanelPresenter::OnTouchReleased(source, touchInfo);
2229 _TableViewPresenter::OnTouchCanceled(const _Control& source, const _TouchInfo& touchInfo)
2236 if (__pTableView->IsReorderModeEnabled() && __reorderInfo.itemIndex != -1)
2238 ResetReorderItem(__reorderInfo.groupIndex, __reorderInfo.itemIndex);
2242 return _ScrollPanelPresenter::OnTouchCanceled(source, touchInfo);
2246 _TableViewPresenter::OnFlickGestureDetected(_TouchFlickGestureDetector& gesture)
2248 if (__pTableView->IsReorderModeEnabled() && __reorderInfo.itemIndex != -1)
2253 _FlickDirection flickDirection = gesture.GetDirection();
2255 if (flickDirection != _FLICK_DIRECTION_RIGHT && flickDirection != _FLICK_DIRECTION_LEFT)
2257 return _ScrollPanelPresenter::OnFlickGestureDetected(gesture);
2260 _Control* gestureControl = gesture.GetControl();
2262 if (gestureControl == null)
2264 return _ScrollPanelPresenter::OnFlickGestureDetected(gesture);
2267 _TableViewItem* pItem = GetTableViewItemFromControl(*gestureControl);
2271 return _ScrollPanelPresenter::OnFlickGestureDetected(gesture);
2274 if (flickDirection == _FLICK_DIRECTION_RIGHT)
2277 if (pItem->GetContextItem() == null && __pTableView->IsSweepEnabled())
2279 pItem->FireItemSweepEvent(TABLE_VIEW_SWEEP_DIRECTION_RIGHT);
2283 if (pItem->GetContextItem() != null)
2285 AdjustSweptItemPosition();
2289 else if (flickDirection == _FLICK_DIRECTION_LEFT)
2292 if (pItem->GetContextItem() == null && __pTableView->IsSweepEnabled())
2294 pItem->FireItemSweepEvent(TABLE_VIEW_SWEEP_DIRECTION_LEFT);
2298 if (pItem->GetContextItem() != null)
2300 AdjustSweptItemPosition();
2309 _TableViewPresenter::OnFlickGestureCanceled(_TouchFlickGestureDetector& gesture)
2311 return _ScrollPanelPresenter::OnFlickGestureCanceled(gesture);
2315 _TableViewPresenter::OnPreviewFlickGestureDetected(_TouchFlickGestureDetector& gesture)
2317 if (__pTableView->IsReorderModeEnabled() && __reorderInfo.itemIndex != -1)
2322 _FlickDirection flickDirection = gesture.GetDirection();
2323 if (flickDirection != _FLICK_DIRECTION_RIGHT && flickDirection != _FLICK_DIRECTION_LEFT)
2325 return _ScrollPanelPresenter::OnFlickGestureDetected(gesture);
2332 _TableViewPresenter::OnTimerExpired(Tizen::Base::Runtime::Timer& timer)
2334 _ScrollPanelPresenter::OnTimerExpired(timer);
2336 if (&timer == __pReorderScrollTimer)
2338 float distance = 0.0f;
2340 if (__reorderInfo.isScrollDirectionUp)
2342 distance = -REORDER_SCROLL_ANIMATION_DISTANCE;
2346 distance = REORDER_SCROLL_ANIMATION_DISTANCE;
2349 DragSelectedItem(distance, false);
2351 distance = ScrollTo(distance + GetScrollPosition());
2353 StartReorderScrollTimer();
2355 else if (&timer == __pFastScrollTimer)
2357 __isFastScrollTimerEnabled = false;
2359 _FastScroll* pFastScroll = __pTableView->GetFastScrollBar();
2361 if (pFastScroll != null && !_ScrollPanelPresenter::IsScrollAnimationRunning())
2363 pFastScroll->SetScrollVisibility(false);
2369 _TableViewPresenter::StartFastScrollTimer(void)
2371 result r = E_SUCCESS;
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));
2378 r = __pFastScrollTimer->Start(FAST_SCROLL_FADE_OUT_DURATION);
2379 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
2381 __isFastScrollTimerEnabled = true;
2387 _TableViewPresenter::StopFastScrollTimer(void)
2389 result r = E_SUCCESS;
2391 SysTryReturnVoidResult(NID_UI_CTRL, __pFastScrollTimer != null, E_INVALID_STATE, "[%s] Timer is invalid.", GetErrorMessage(E_INVALID_OPERATION));
2393 r = __pFastScrollTimer->Cancel();
2394 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
2396 __isFastScrollTimerEnabled = false;
2402 _TableViewPresenter::IsEmpty(void) const
2404 if (__pTableView->GetTableViewStyle() == TABLE_VIEW_STYLE_SIMPLE)
2406 if (GetItemCountAt(0) <= 0)
2413 if (GetGroupCount() <= 0)
2423 _TableViewPresenter::DrawEmptyTableView(void)
2429 _TableViewPresenter::GetFirstItem(TableViewItemTag& firstItem) const
2433 firstItem.groupIndex = -1;
2434 firstItem.itemIndex = -1;
2438 firstItem.groupIndex = 0;
2439 firstItem.itemIndex = -1;
2446 _TableViewPresenter::GetLastItem(TableViewItemTag& lastItem) const
2450 lastItem.groupIndex = -1;
2451 lastItem.itemIndex = -1;
2455 lastItem.groupIndex = GetGroupCount() - 1;
2456 lastItem.itemIndex = GetItemCountAt(lastItem.groupIndex) - 1;
2463 _TableViewPresenter::GetTopDrawnItem(TableViewItemTag& itemPos) const
2465 _TableViewItem* pItem = null;
2466 TableViewItemTag lastItemPos = {-1, -1};
2467 float scrollPosition = 0.0f;
2469 scrollPosition = GetScrollPosition();
2471 __pListModel->GetFirstLoadedItemIndex(itemPos.groupIndex, itemPos.itemIndex);
2472 __pListModel->GetLastLoadedItemIndex(lastItemPos.groupIndex, lastItemPos.itemIndex);
2476 pItem = static_cast <_TableViewItem*>(__pListModel->LoadItem(itemPos.groupIndex, itemPos.itemIndex));
2482 FloatRectangle itemBounds = pItem->GetBoundsF();
2484 if (scrollPosition < (itemBounds.y + itemBounds.height))
2489 if ((itemPos.itemIndex == lastItemPos.itemIndex) && (itemPos.groupIndex == lastItemPos.groupIndex))
2494 } while (GetNextItemPosition(itemPos, itemPos) == true);
2497 itemPos.itemIndex = -1;
2498 itemPos.groupIndex = -1;
2500 return E_OBJ_NOT_FOUND;
2504 _TableViewPresenter::GetBottomDrawnItem(TableViewItemTag& itemPos) const
2506 _TableViewItem* pItem = null;
2507 TableViewItemTag lastItemPos = {-1, -1};
2511 itemPos.itemIndex = -1;
2512 itemPos.groupIndex = -1;
2514 return E_OBJ_NOT_FOUND;
2517 float scrollPosition = GetScrollPosition() + __pTableView->GetBoundsF().height;
2519 __pListModel->GetFirstLoadedItemIndex(itemPos.groupIndex, itemPos.itemIndex);
2520 __pListModel->GetLastLoadedItemIndex(lastItemPos.groupIndex, lastItemPos.itemIndex);
2524 static bool onProcessingByProvider = true;
2525 pItem = static_cast <_TableViewItem*>(__pListModel->LoadItem(itemPos.groupIndex, itemPos.itemIndex));
2526 onProcessingByProvider = false;
2532 FloatRectangle itemBounds = pItem->GetBoundsF();
2534 if (itemBounds.y <= scrollPosition && scrollPosition <= (itemBounds.y + itemBounds.height))
2539 if ((itemPos.itemIndex == lastItemPos.itemIndex) && (itemPos.groupIndex == lastItemPos.groupIndex))
2544 } while (GetNextItemPosition(itemPos, itemPos) == true);
2550 _TableViewPresenter::GetPreviousItemPosition(const TableViewItemTag& currentItemPos, TableViewItemTag& prevItem) const
2557 // check validation of group index
2558 if ((currentItemPos.groupIndex < 0) || (currentItemPos.groupIndex >= __pListModel->GetAllGroupCount()))
2563 // if the current item is the first item
2564 if (currentItemPos.groupIndex == 0 && currentItemPos.itemIndex == -1)
2569 if (currentItemPos.itemIndex == -1)
2571 if (__pListModel->IsGroupExpanded(currentItemPos.groupIndex - 1) == false)
2573 prevItem.groupIndex = currentItemPos.groupIndex - 1;
2574 prevItem.itemIndex = -1;
2580 prevItem.groupIndex = currentItemPos.groupIndex - 1;
2581 prevItem.itemIndex = __pListModel->GetItemCountInGroup(prevItem.groupIndex) - 1;
2587 if (__pListModel->IsGroupExpanded(currentItemPos.groupIndex) == false)
2589 if (currentItemPos.itemIndex >= 0)
2591 prevItem.groupIndex = currentItemPos.groupIndex;
2592 prevItem.itemIndex = -1;
2598 if (currentItemPos.itemIndex == -1) // group title item
2600 prevItem.groupIndex = currentItemPos.groupIndex - 1;
2601 prevItem.itemIndex = __pListModel->GetItemCountInGroup(prevItem.groupIndex) - 1;
2605 prevItem.groupIndex = currentItemPos.groupIndex;
2606 prevItem.itemIndex = currentItemPos.itemIndex - 1;
2613 _TableViewPresenter::GetNextItemPosition(const TableViewItemTag& currentItem, TableViewItemTag& nextItem) const
2620 int lastGroup = __pListModel->GetAllGroupCount() - 1;
2621 int lastItemInCurrentGroup = __pListModel->GetItemCountInGroup(currentItem.groupIndex) - 1;
2622 int lastItem = __pListModel->GetItemCountInGroup(lastGroup) - 1;
2624 // check validation of group index
2625 if ((currentItem.groupIndex < 0) || (currentItem.groupIndex > lastGroup))
2630 // if the current item is the last item.
2631 if ((currentItem.groupIndex == lastGroup) && (currentItem.itemIndex == lastItem))
2636 if (__pListModel->IsGroupExpanded(currentItem.groupIndex) == false)
2638 if (currentItem.groupIndex == lastGroup)
2643 nextItem.groupIndex = currentItem.groupIndex + 1;
2644 nextItem.itemIndex = -1;
2649 if (lastItemInCurrentGroup == currentItem.itemIndex)
2651 nextItem.groupIndex = currentItem.groupIndex + 1;
2652 nextItem.itemIndex = -1;
2656 nextItem.groupIndex = currentItem.groupIndex;
2657 nextItem.itemIndex = currentItem.itemIndex + 1;
2664 _TableViewPresenter::GetHeightOfAllItems(void) const
2666 int groupCount = GetGroupCount();
2667 float totalHeight = 0;
2669 for (int i = 0; i < groupCount; i++)
2671 TableViewItemTag itemTag = {i, -1};
2673 totalHeight += GetItemHeight(itemTag);
2675 if (!IsGroupExpanded(i))
2680 int itemCount = GetItemCountAt(i);
2682 for (int j = 0; j < itemCount; j++)
2684 itemTag.itemIndex = j;
2686 totalHeight += GetItemHeight(itemTag);
2694 _TableViewPresenter::SetTableViewItemProviderAdaptor(_TableViewItemProviderAdaptor* pProviderAdaptor)
2696 __pListModel->RegisterItemProviderAdaptor(pProviderAdaptor);
2698 __pProviderAdaptor = pProviderAdaptor;
2700 if (__pProviderAdaptor != null)
2702 __pProviderAdaptor->SetTableViewPresenter(this);
2706 _TableViewItemProviderAdaptor*
2707 _TableViewPresenter::GetTableViewItemProviderAdaptor(void) const
2709 return __pProviderAdaptor;
2713 _TableViewPresenter::ExpandGroup(int groupIndex, bool withAnimation)
2715 if ((groupIndex < 0) || (groupIndex >= GetGroupCount()))
2717 return E_OUT_OF_RANGE;
2720 if (__modelInitialized == false)
2722 return E_INVALID_STATE;
2725 if (IsGroupExpanded(groupIndex) == true)
2730 TableViewItemTag topTag;
2731 GetTopDrawnItem(topTag);
2733 TableViewItemTag bottomTag;
2734 GetBottomDrawnItem(bottomTag);
2736 float screenPosition = GetScrollPosition();
2738 __pListModel->SetGroupExpandState(groupIndex, true);
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++)
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());
2754 AdjustClientAreaBounds(false, groupTotalHeight);
2756 if (groupIndex < topTag.groupIndex || groupIndex > bottomTag.groupIndex)
2758 _TableViewItem* pItem = FindItem(topTag);
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)
2767 ScrollTo(screenPosition + groupTotalHeight);
2771 int firstLoadedGroupIndex = -1;
2772 int firstLoadedItemIndex = -1;
2773 __pListModel->GetFirstLoadedItemIndex(firstLoadedGroupIndex, firstLoadedItemIndex);
2775 for (int j = firstLoadedGroupIndex; j <= topTag.groupIndex; j++)
2777 int itemCount = GetItemCountAt(j);
2779 for (int i = -1; i < itemCount; i++)
2781 if (i >= topTag.itemIndex && j == topTag.groupIndex)
2792 itemTag.groupIndex = groupIndex;
2793 itemTag.itemIndex = -1;
2795 __expandableItemTag.groupIndex = groupIndex;
2796 __expandableItemTag.itemIndex = -1;
2800 _TableViewItem* pItem = FindItem(itemTag);
2806 FloatRectangle itemBounds = pItem->GetBoundsF();
2807 float startPosition = itemBounds.y + itemBounds.height;
2809 float endPosition = startPosition + groupTotalHeight;
2810 if (endPosition > screenPosition + __pTableView->GetBoundsF().height)
2812 endPosition = screenPosition + __pTableView->GetBoundsF().height;
2815 _VisualElement* pVisualElement = __pTableView->GetVisualElement();
2816 String animationName(L"EXPAND_GROUP_ANIMATION");
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);
2826 ExpandGroupAnimationFinished(false);
2833 _TableViewPresenter::CollapseGroup(int groupIndex, bool withAnimation)
2835 if ((groupIndex < 0) || (groupIndex >= GetGroupCount()))
2837 return E_OUT_OF_RANGE;
2840 if (__modelInitialized == false)
2842 return E_INVALID_STATE;
2845 if (IsGroupExpanded(groupIndex) == false)
2850 TableViewItemTag itemTag;
2851 GetTopDrawnItem(itemTag);
2853 TableViewItemTag bottomTag;
2854 GetBottomDrawnItem(bottomTag);
2855 float screenPosition = GetScrollPosition();
2857 __pListModel->SetGroupExpandState(groupIndex, false);
2861 if (groupIndex < itemTag.groupIndex || groupIndex > bottomTag.groupIndex)
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++)
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());
2876 TableViewItemTag firstLoadedItemTag;
2877 __pListModel->GetFirstLoadedItemIndex(firstLoadedItemTag.groupIndex, firstLoadedItemTag.itemIndex);
2879 if (firstLoadedItemTag.groupIndex == groupIndex)
2881 SetLoadedItemsVisibleInGroup(groupIndex, false);
2882 firstLoadedItemTag.groupIndex = groupIndex + 1;
2883 firstLoadedItemTag.itemIndex = -1;
2886 for (int i = 0; i < itemCount; i++)
2888 UnloadItem(groupIndex, i);
2891 __pListModel->GetFirstLoadedItemIndex(firstLoadedItemTag.groupIndex, firstLoadedItemTag.itemIndex);
2892 pItem = FindItem(firstLoadedItemTag);
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)
2901 ScrollTo(screenPosition - groupTotalHeight);
2905 AdjustClientAreaBounds(false, -groupTotalHeight);
2910 if (itemTag.groupIndex < groupIndex)
2912 itemTag.groupIndex = groupIndex;
2913 itemTag.itemIndex = -1;
2915 __expandableItemTag.groupIndex = itemTag.groupIndex;
2916 __expandableItemTag.itemIndex = itemTag.itemIndex;
2918 if(__firstDrawnFlag)
2920 withAnimation = false;
2925 _TableViewItem* pItem = FindItem(itemTag);
2931 FloatRectangle itemBounds = pItem->GetBoundsF();
2932 float startPosition = 0;
2933 if (itemTag.itemIndex == -1)
2935 startPosition = itemBounds.y + itemBounds.height;
2939 startPosition = GetScrollPosition();
2942 if (bottomTag.groupIndex > groupIndex)
2944 bottomTag.groupIndex = groupIndex+1;
2945 bottomTag.itemIndex = -1;
2948 pItem = FindItem(bottomTag);
2954 itemBounds = pItem->GetBoundsF();
2955 float endPosition = itemBounds.y;
2956 if (bottomTag.groupIndex != groupIndex +1)
2958 endPosition += itemBounds.height;
2961 if (endPosition > screenPosition + __pTableView->GetBoundsF().height)
2963 endPosition = screenPosition + __pTableView->GetBoundsF().height;
2966 _VisualElement* pVisualElement = __pTableView->GetVisualElement();
2967 String animationName(L"COLLAPSE_GROUP_ANIMATION");
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);
2977 CollapseGroupAnimationFinished(false);
2984 _TableViewPresenter::IsGroupExpanded(int groupIndex) const
2986 return __pListModel->IsGroupExpanded(groupIndex);
2990 _TableViewPresenter::StopExpandCollapseAnimation(void)
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)
2997 pVisualElement->RemoveAnimation(animationName);
2998 delete pExpandGroupAnimation;
3001 animationName = L"COLLAPSE_GROUP_ANIMATION";
3002 VisualElementValueAnimation* pCollapseGroupAnimation = dynamic_cast<VisualElementValueAnimation*>(pVisualElement->GetAnimationN(animationName));
3003 if (pCollapseGroupAnimation != null)
3005 pVisualElement->RemoveAnimation(animationName);
3006 delete pCollapseGroupAnimation;
3011 _TableViewPresenter::LoadAllItemsInGroup(int groupIndex, bool downward)
3013 int itemCountInGroup = __pListModel->GetItemCountInGroup(groupIndex);
3014 _TableViewItem* pItem = null;
3018 for (int i = 0; i < itemCountInGroup; i++)
3020 pItem = LoadItem(groupIndex, i);
3024 SysLogException(NID_UI_CTRL, E_SYSTEM, "[%s] A system error has been occurred. Unable to load item.", GetErrorMessage(E_SYSTEM));
3030 for (int i = itemCountInGroup-1; i >= 0; i--)
3032 pItem = LoadItem(groupIndex, i);
3036 SysLogException(NID_UI_CTRL, E_SYSTEM, "[%s] A system error has been occurred. Unable to load item.", GetErrorMessage(E_SYSTEM));
3041 return itemCountInGroup;
3045 _TableViewPresenter::SetLoadedItemsVisibleInGroup(int groupIndex, bool visible)
3047 int itemCountInGroup = __pListModel->GetItemCountInGroup(groupIndex);
3048 _TableViewItem* pItem = null;
3049 TableViewItemTag itemTag;
3050 itemTag.groupIndex = groupIndex;
3052 int firstLoadedGroupIndex = -1;
3053 int firstLoadedItemIndex = -1;
3054 __pListModel->GetFirstLoadedItemIndex(firstLoadedGroupIndex, firstLoadedItemIndex);
3056 if (firstLoadedGroupIndex > groupIndex)
3062 if (groupIndex == firstLoadedGroupIndex && firstLoadedItemIndex > 0)
3064 startIndex = firstLoadedItemIndex;
3067 for (int i = startIndex; i < itemCountInGroup; i++)
3069 itemTag.itemIndex = i;
3070 pItem = FindItem(itemTag);
3076 pItem->SetVisibleState(visible);
3081 _TableViewPresenter::LoadItemsToBeVisible(const TableViewItemTag& from)
3083 TableViewItemTag bottomTag = from;
3084 TableViewItemTag current;
3085 TableViewItemTag next;
3087 _TableViewItem* pItem = LoadItem(from.groupIndex, from.itemIndex);
3094 FloatRectangle itemBounds = pItem->GetBoundsF();
3095 float viewHeight = __pTableView->GetBoundsF().height;
3096 float scrollPosition = GetScrollPosition();
3097 float itemPosition = itemBounds.y + itemBounds.height - scrollPosition;
3099 while (viewHeight >= itemPosition)
3101 current.groupIndex = bottomTag.groupIndex;
3102 current.itemIndex = bottomTag.itemIndex;
3103 if (!GetNextItemPosition(current, next))
3108 pItem = LoadItem(next.groupIndex, next.itemIndex);
3109 bottomTag.groupIndex = next.groupIndex;
3110 bottomTag.itemIndex = next.itemIndex;
3111 itemPosition += pItem->GetBoundsF().height;
3118 _TableViewPresenter::AttachNextItemsToBottom(const TableViewItemTag& anchor)
3120 TableViewItemTag itemTag = anchor;
3121 TableViewItemTag current;
3122 TableViewItemTag next;
3124 _TableViewItem* pItem = FindItem(itemTag);
3130 FloatRectangle itemBounds = pItem->GetBoundsF();
3131 float itemPosition = itemBounds.y + itemBounds.height;
3133 current.groupIndex = itemTag.groupIndex;
3134 current.itemIndex = itemTag.itemIndex;
3135 while (GetNextItemPosition(current, next))
3137 pItem = FindItem(next);
3144 itemBounds = pItem->GetBoundsF();
3145 itemBounds.y = itemPosition;
3146 pItem->SetBounds(itemBounds);
3147 itemPosition += itemBounds.height;
3153 _TableViewPresenter::IsAnyItemInGroupLoaded(int groupIndex) const
3155 int startGroupIndex = 0;
3156 int endGroupIndex = 0;
3159 __pListModel->GetFirstLoadedItemIndex(startGroupIndex, index);
3160 __pListModel->GetLastLoadedItemIndex(endGroupIndex, index);
3162 return groupIndex >= startGroupIndex && groupIndex <= endGroupIndex;
3166 _TableViewPresenter::ScrollToHideNonClientArea(TableViewItemTag& bottomTag)
3168 _TableViewItem* pItem = FindItem(bottomTag);
3174 FloatRectangle itemBounds = pItem->GetBoundsF();
3175 float viewHeight = __pTableView->GetBoundsF().height;
3176 float scrollPosition = GetScrollPosition();
3177 float itemBottom = itemBounds.y + itemBounds.height - scrollPosition;
3179 if (itemBottom < viewHeight)
3181 scrollPosition -= viewHeight - itemBottom;
3182 if (scrollPosition < 0)
3187 SetScrollPosition(scrollPosition, false);
3192 _TableViewPresenter::AdjustClientAreaBounds(bool reset, float dist)
3194 float clientHeight = 0;
3198 __itemTotalHeight = GetHeightOfAllItems();
3199 clientHeight = __itemTotalHeight;
3203 __itemTotalHeight = __itemTotalHeight + dist;
3204 clientHeight = __itemTotalHeight;
3207 SetClientAreaHeight(clientHeight);
3211 _TableViewPresenter::SetClientAreaHeight(float height)
3213 FloatRectangle screenBounds = __pTableView->GetBoundsF();
3214 FloatRectangle clientBounds = screenBounds;
3216 clientBounds.height = height;
3218 if (clientBounds.height < screenBounds.height)
3220 clientBounds.height = screenBounds.height;
3223 SetScrollAreaBounds(clientBounds);
3225 _Scroll* pScroll = __pTableView->GetScrollBar();
3226 if (pScroll != null)
3228 pScroll->SetScrollRange(__pTableView->GetBoundsF().height, clientBounds.height);
3233 _TableViewPresenter::UnloadInvisibleItems(void)
3235 float scrollPosition = GetScrollPosition();
3236 TableViewItemTag itemTag;
3237 __pListModel->GetFirstLoadedItemIndex(itemTag.groupIndex, itemTag.itemIndex);
3239 _TableViewItem* pItem = null;
3240 FloatRectangle bounds;
3242 while ((pItem = FindItem(itemTag)) != null)
3244 if (itemTag.itemIndex != -1)
3246 bounds = pItem->GetBoundsF();
3247 if (bounds.y + bounds.height < scrollPosition)
3249 UnloadItem(itemTag);
3256 __pListModel->GetFirstLoadedItemIndex(itemTag.groupIndex, itemTag.itemIndex);
3259 __pListModel->GetLastLoadedItemIndex(itemTag.groupIndex, itemTag.itemIndex);
3260 scrollPosition += __pTableView->GetBoundsF().height;
3262 while ((pItem = FindItem(itemTag)) != null)
3264 if (itemTag.itemIndex != -1)
3266 bounds = pItem->GetBoundsF();
3267 if (bounds.y > scrollPosition)
3269 UnloadItem(itemTag);
3276 __pListModel->GetLastLoadedItemIndex(itemTag.groupIndex, itemTag.itemIndex);
3282 _TableViewPresenter::ScrollToInternal(float newPosition)
3284 if (!IsScrollEnabled())
3289 if (IsScrollAnimationRunning())
3291 if (__scrollPositionOnFlickStarted > newPosition)
3293 newPosition += GetScrollAreaBounds().height - __scrollHeightOnFlickStarted;
3297 float currentScrollPosition = GetScrollPosition();
3298 float currentscrollAreaHeight = GetScrollAreaBounds().height;
3299 float newScrollPosition = (newPosition < 0) ? 0 : (newPosition > currentscrollAreaHeight ? currentscrollAreaHeight : newPosition);
3300 float newScrollAreaHeight = 0;
3302 if (IsModelUpdating())
3304 currentScrollPosition = GetScrollPositionInternal();
3307 if (!__lockLoadItemWithScroll)
3309 LoadItemWithScrollPosition(currentScrollPosition, newScrollPosition);
3311 if (currentScrollPosition > newScrollPosition)
3313 newScrollAreaHeight = GetScrollAreaBounds().height;
3314 newScrollPosition += newScrollAreaHeight - currentscrollAreaHeight;
3318 //scroll effect for _ScrollPanel
3319 if (newPosition < 0.0f || newPosition > currentscrollAreaHeight - __pTableView->GetBoundsF().height)
3321 newScrollPosition = newPosition;
3324 return _ScrollPanelPresenter::ScrollToInternal(newScrollPosition);
3328 _TableViewPresenter::LoadItemWithScrollPosition(float previousScrollPosition, float currentScrollPos)
3332 TableViewItemTag lastLoadedItemPos = {-1, -1};
3333 TableViewItemTag firstLoadedItemPos = {-1, -1};
3334 __pListModel->GetLastLoadedItemIndex(lastLoadedItemPos.groupIndex, lastLoadedItemPos.itemIndex);
3335 __pListModel->GetFirstLoadedItemIndex(firstLoadedItemPos.groupIndex, firstLoadedItemPos.itemIndex);
3337 if (currentScrollPos > previousScrollPosition && lastLoadedItemPos.groupIndex != -1)
3339 _TableViewItem* pLastItem = FindItem(lastLoadedItemPos);
3340 if (pLastItem == null)
3345 while (pLastItem && (pLastItem->GetBoundsF().y <= currentScrollPos + __pTableView->GetBoundsF().height))
3347 TableViewItemTag nextItemPos = {-1, -1};
3348 if (GetNextItemPosition(lastLoadedItemPos, nextItemPos))
3350 if (nextItemPos.itemIndex == -1)
3352 LoadItem(nextItemPos.groupIndex, nextItemPos.itemIndex);
3354 if (!GetNextItemPosition(nextItemPos, nextItemPos))
3360 if (nextItemPos.groupIndex != -1)
3362 _TableViewItem* pItem = LoadItem(nextItemPos.groupIndex, nextItemPos.itemIndex);
3368 FloatRectangle scrollAreaBounds = GetScrollAreaBounds();
3369 if (pItem->GetBoundsF().y + pItem->GetBoundsF().height >= scrollAreaBounds.height)
3371 AdjustClientAreaBounds(true);
3380 lastLoadedItemPos = nextItemPos;
3381 pLastItem = static_cast<_TableViewItem*>(__pListModel->LoadItem(lastLoadedItemPos.groupIndex, lastLoadedItemPos.itemIndex));
3385 if (currentScrollPos < previousScrollPosition && firstLoadedItemPos.groupIndex != -1)
3387 _TableViewItem* pFirstItem = FindItem(firstLoadedItemPos);
3388 if (pFirstItem == null)
3393 float scrollOffsetFromBottom = GetScrollAreaBounds().height - currentScrollPos;
3397 FloatRectangle scrollAreaBounds = GetScrollAreaBounds();
3398 float itemOffsetFromBottom = scrollAreaBounds.height - (pFirstItem->GetBoundsF().y + pFirstItem->GetBoundsF().height);
3400 if (scrollOffsetFromBottom < itemOffsetFromBottom)
3405 TableViewItemTag prevItemPos = {-1, -1};
3406 if (GetPreviousItemPosition(firstLoadedItemPos, prevItemPos))
3408 if (prevItemPos.itemIndex == -1)
3410 LoadItem(prevItemPos.groupIndex, prevItemPos.itemIndex);
3412 if (!GetPreviousItemPosition(prevItemPos, prevItemPos))
3418 if (prevItemPos.groupIndex != -1)
3420 LoadItem(prevItemPos.groupIndex, prevItemPos.itemIndex);
3428 firstLoadedItemPos = prevItemPos;
3429 pFirstItem = FindItem(firstLoadedItemPos);
3435 _TableViewPresenter::ScrollToItem(int groupIndex, int itemIndex, TableViewScrollItemAlignment itemAlignment, float shiftingDistance)
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)
3442 __scrollToItemTag.groupIndex = groupIndex;
3443 __scrollToItemTag.itemIndex = itemIndex;
3444 __scrollToItemTag.itemAlignment = itemAlignment;
3445 __scrollToItemTag.shiftingDistance = shiftingDistance;
3446 __scrollToItemTag.startedAnimation = true;
3447 delete pExpandGroupAnimation;
3451 animationName = L"COLLAPSE_GROUP_ANIMATION";
3452 VisualElementValueAnimation* pCollapseGroupAnimation = dynamic_cast<VisualElementValueAnimation*>(pVisualElement->GetAnimationN(animationName));
3453 if (pCollapseGroupAnimation != null)
3455 __scrollToItemTag.groupIndex = groupIndex;
3456 __scrollToItemTag.itemIndex = itemIndex;
3457 __scrollToItemTag.itemAlignment = itemAlignment;
3458 __scrollToItemTag.shiftingDistance = shiftingDistance;
3459 __scrollToItemTag.startedAnimation = true;
3460 delete pCollapseGroupAnimation;
3464 if (IsGroupExpanded(groupIndex) == false)
3469 TableViewItemTag itemPos = {groupIndex, itemIndex};
3471 StopAllItemAnimation();
3474 if (!__pListModel->IsLoadedItem(groupIndex, itemIndex))
3476 ResetItemLayout(itemPos, shiftingDistance);
3479 _TableViewItem* pItem = FindItem(itemPos);
3486 float scrollPosition = pItem->GetBoundsF().y;
3488 scrollPosition = scrollPosition + shiftingDistance;
3490 SetScrollPosition(scrollPosition, false);
3492 if (itemAlignment == TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_BOTTOM)
3494 SetScrollPosition(scrollPosition - (__pTableView->GetBoundsF().height - pItem->GetBoundsF().height), false);
3499 _TableViewPresenter::ScrollByPixel(float scrollDistance)
3502 result r = GetLastResult();
3503 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
3507 ScrollTo(scrollDistance + GetScrollPosition());
3508 r = GetLastResult();
3509 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
3511 RollbackBouncing(true);
3512 r = GetLastResult();
3513 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
3516 r = GetLastResult();
3517 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
3523 _TableViewPresenter::SetScrollEnabled(bool enable)
3525 __scrolling = enable;
3529 _TableViewPresenter::IsScrollEnabled(void) const
3535 _TableViewPresenter::GetFirstDrawnFlag(void) const
3537 return __firstDrawnFlag;
3541 _TableViewPresenter::GetMaxItemCachingSize(void) const
3543 return __pListModel->GetMaxCachingSize();
3547 _TableViewPresenter::ResetSweepItem(void)
3549 if (__sweptItemTag.groupIndex != -1 && __sweptItemTag.itemIndex != -1)
3556 _TableViewPresenter::GetSweepItemIndex(int& groupIndex, int& itemIndex) const
3558 groupIndex = __sweptItemTag.groupIndex;
3559 itemIndex = __sweptItemTag.itemIndex;
3563 _TableViewPresenter::GetPressedItemCount(void)
3565 _TableViewItem* pItem = null;
3566 TableViewItemTag itemPos = {-1, -1};
3567 TableViewItemTag lastItemPos = {-1, -1};
3570 __pListModel->GetFirstLoadedItemIndex(itemPos.groupIndex, itemPos.itemIndex);
3571 __pListModel->GetLastLoadedItemIndex(lastItemPos.groupIndex, lastItemPos.itemIndex);
3575 pItem = static_cast <_TableViewItem*>(__pListModel->LoadItem(itemPos.groupIndex, itemPos.itemIndex));
3581 if (pItem->GetDrawingStatus() == TABLE_VIEW_ITEM_DRAWING_STATUS_PRESSED)
3586 if ((itemPos.itemIndex == lastItemPos.itemIndex) && (itemPos.groupIndex == lastItemPos.groupIndex))
3590 } while (GetNextItemPosition(itemPos, itemPos) == true);
3596 _TableViewPresenter::BlockAnimationCallback(bool blocked)
3598 __isAnimationCallbackBlocked = blocked;
3602 _TableViewPresenter::CalculateItemPositionY(int groupIndex, int itemIndex)
3604 TableViewItemTag itemPos = {-1, -1};
3605 TableViewItemTag currentItemPos = {-1, -1};
3606 float positionY = 0.0f;
3608 GetFirstItem(itemPos);
3610 if (itemPos.groupIndex == -1 && itemPos.itemIndex == -1)
3615 if (__pProviderAdaptor == null)
3620 positionY = GetTopMargin();
3622 while ((itemPos.groupIndex < groupIndex) || ((itemPos.groupIndex == groupIndex) && (itemPos.itemIndex < itemIndex)))
3624 currentItemPos = itemPos;
3626 float itemHeight = GetItemHeight(itemPos);
3628 positionY += itemHeight;
3630 if (!GetNextItemPosition(currentItemPos, itemPos))
3640 _TableViewPresenter::FadeInScrollBar(void)
3642 TableViewScrollBarStyle scrollStyle = __pTableView->GetScrollStyle();
3644 if (scrollStyle == TABLE_VIEW_SCROLL_BAR_STYLE_NONE)
3646 _Scroll* pScroll = __pTableView->GetScrollBar();
3648 if (pScroll != null)
3650 pScroll->SetVisibleState(false);
3653 else if (scrollStyle == TABLE_VIEW_SCROLL_BAR_STYLE_FAST_SCROLL)
3655 _Scroll* pScroll = __pTableView->GetScrollBar();
3657 if (pScroll != null)
3659 pScroll->SetVisibleState(false);
3662 _FastScroll* pFastScroll = __pTableView->GetFastScrollBar();
3664 if (pFastScroll != null)
3666 pFastScroll->SetScrollVisibility(true);
3671 _ScrollPanelPresenter::FadeInScrollBar();
3676 _TableViewPresenter::FadeOutScrollBar(void)
3678 TableViewScrollBarStyle scrollStyle = __pTableView->GetScrollStyle();
3679 if (scrollStyle == TABLE_VIEW_SCROLL_BAR_STYLE_FAST_SCROLL)
3681 StopFastScrollTimer();
3683 if (!_ScrollPanelPresenter::IsScrollAnimationRunning())
3685 StartFastScrollTimer();
3688 else if (scrollStyle == TABLE_VIEW_SCROLL_BAR_STYLE_FIXED)
3690 _Scroll* pScroll = __pTableView->GetScrollBar();
3692 if (pScroll != null)
3694 pScroll->SetScrollingEffectVisibility(false);
3699 _ScrollPanelPresenter::FadeOutScrollBar();
3704 _TableViewPresenter::SweepItem(float x)
3706 if (!_FloatCompare(x, 0.0f))
3708 _TableViewItem* pItem = static_cast<_TableViewItem*>(__pListModel->LoadItem(__sweptItemTag.groupIndex, __sweptItemTag.itemIndex));
3712 _TableViewItem* pContextItem = pItem->GetContextItem();
3714 if (pContextItem != null)
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;
3723 GET_SHAPE_CONFIG(TABLEVIEW::CONTEXTITEM_RIGHT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, sweepMargin);
3725 if (currentPosition >= (sweepDistance - sweepMargin))
3727 currentPosition = (sweepDistance - sweepMargin);
3728 needToFireEvent = !activated;
3730 else if (currentPosition <= __leftMargin)
3732 currentPosition = __leftMargin;
3733 needToFireEvent = activated;
3736 __sweptItemPosition.x = currentPosition;
3738 // Set TableViewItem bounds
3739 pItem->SetPosition(__sweptItemPosition);
3741 // Set TableViewContextItem bounds
3742 if (!__pTableView->IsAncestorOf(*pContextItem))
3744 pContextItem->SetDrawingProperty(__pItemDrawingProperty);
3745 __pTableView->InsertChildToBottom(*pContextItem);
3746 __pTableView->UpdateLayout();
3749 contextItemWidth = ((contextItemWidth > (__sweptItemPosition.x - __leftMargin)) ? (__sweptItemPosition.x - __leftMargin) : contextItemWidth);
3751 pContextItem->ExposeContextItem(FloatRectangle(__leftMargin, __sweptItemPosition.y, contextItemWidth, pContextItem->GetSizeF().height), pItem->GetSize().width);
3753 if (needToFireEvent)
3755 PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_SLIDER_SWEEP, pItem);
3757 activated = !activated; // ContextItem Activation State Changed
3759 __pTableView->FireTableViewContextItemActivationEvent(__sweptItemTag.groupIndex, __sweptItemTag.itemIndex, pContextItem, activated);
3760 pItem->SetContextItemActivation(activated);
3773 _TableViewPresenter::ResetSweptItem(void)
3775 _TableViewItem* pItem = static_cast<_TableViewItem*>(__pListModel->LoadItem(__sweptItemTag.groupIndex, __sweptItemTag.itemIndex));
3779 _VisualElement* pVisualElement = __pTableView->GetVisualElement();
3781 if (pVisualElement != null)
3783 String animationName(L"SWEEP_ITEM_ANIMATION");
3784 VisualElementAnimation* pContextItemAnimation = pVisualElement->GetAnimationN(animationName);
3785 if (pContextItemAnimation != null)
3787 pVisualElement->RemoveAnimation(animationName);
3789 delete pContextItemAnimation;
3793 pItem->SetPosition(FloatPoint(__leftMargin, __sweptItemPosition.y));
3795 _TableViewItem* pContextItem = pItem->GetContextItem();
3796 if (pContextItem != null)
3798 if (__pTableView->IsAncestorOf(*pContextItem))
3800 __pTableView->DetachChild(*pContextItem);
3803 if (pItem->IsContextItemActivated())
3805 __pTableView->FireTableViewContextItemActivationEvent(__sweptItemTag.groupIndex, __sweptItemTag.itemIndex, pContextItem, false);
3806 pItem->SetContextItemActivation(false);
3811 __sweptItemTag.itemIndex = -1;
3812 __sweptItemTag.groupIndex = -1;
3814 __sweptItemPosition.SetPosition(-1.0f, -1.0f);
3815 __sweepOccured = false;
3819 _TableViewPresenter::AdjustSweptItemPosition(bool withAnimation)
3821 float itemWidth = __pTableView->GetBoundsF().width;
3822 float sweepDistance = 0.0f;
3824 if (_FloatCompare(__sweptItemPosition.x, __leftMargin))
3830 float sweepMargin = 0.0f;
3831 GET_SHAPE_CONFIG(TABLEVIEW::CONTEXTITEM_RIGHT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, sweepMargin);
3833 if (__sweptItemPosition.x > (itemWidth - sweepMargin) / 2)
3835 sweepDistance = itemWidth - __sweptItemPosition.x;
3839 sweepDistance = -__sweptItemPosition.x;
3844 SweepItem(sweepDistance);
3848 _TableViewItem* pItem = static_cast<_TableViewItem*>(__pListModel->LoadItem(__sweptItemTag.groupIndex, __sweptItemTag.itemIndex));
3852 _VisualElement* pVisualElement = __pTableView->GetVisualElement();
3854 if (pVisualElement != null)
3856 String animationName(L"SWEEP_ITEM_ANIMATION");
3857 float startValue = __sweptItemPosition.x;
3858 float endValue = 0.0f;
3860 if(sweepDistance > 0)
3862 endValue = itemWidth - sweepMargin;
3866 if(_FloatCompare(itemWidth, __sweptItemPosition.x))
3868 endValue = itemWidth - sweepMargin;
3872 endValue = __leftMargin;
3876 pVisualElement->SetImplicitAnimationEnabled(false);
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);
3889 _TableViewPresenter::AdjustLoadedItemWidth(void)
3891 TableViewItemTag lastLoadedItemPos = {-1, -1};
3892 TableViewItemTag firstLoadedItemPos = {-1, -1};
3893 __pListModel->GetLastLoadedItemIndex(lastLoadedItemPos.groupIndex, lastLoadedItemPos.itemIndex);
3894 __pListModel->GetFirstLoadedItemIndex(firstLoadedItemPos.groupIndex, firstLoadedItemPos.itemIndex);
3898 _TableViewItem* pItem = FindItem(firstLoadedItemPos);
3905 FloatDimension itemSize = pItem->GetSizeF();
3906 itemSize.width = __pProviderAdaptor->GetListWidth();
3908 pItem->SetItemChanged(true);
3909 pItem->SetSize(itemSize);
3911 if ((firstLoadedItemPos.itemIndex == lastLoadedItemPos.itemIndex) && (firstLoadedItemPos.groupIndex == lastLoadedItemPos.groupIndex))
3915 } while (GetNextItemPosition(firstLoadedItemPos, firstLoadedItemPos));
3919 _TableViewPresenter::OpenContextItem(int groupIndex, int itemIndex)
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);
3924 TableViewItemTag itemTag = {groupIndex, itemIndex};
3925 _TableViewItem* pItem = FindItem(itemTag);
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));
3933 __sweptItemTag.groupIndex = groupIndex;
3934 __sweptItemTag.itemIndex = itemIndex;
3935 __sweptItemPosition = pItem->GetPositionF();
3937 pItem->AdjustContextItemBounds();
3938 __sweepOccured = true;
3940 _VisualElement* pVisualElement = __pTableView->GetVisualElement();
3942 if (pVisualElement != null)
3944 float itemWidth = __pTableView->GetBoundsF().width;
3945 float sweepMargin = 0.0f;
3946 GET_SHAPE_CONFIG(TABLEVIEW::CONTEXTITEM_RIGHT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, sweepMargin);
3948 String animationName(L"SWEEP_ITEM_ANIMATION");
3949 float startValue = __sweptItemPosition.x;
3950 float endValue = itemWidth - sweepMargin;
3952 pVisualElement->SetImplicitAnimationEnabled(false);
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);
3965 _TableViewPresenter::CloseContextItem(int groupIndex, int itemIndex)
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);
3969 TableViewItemTag itemTag = {groupIndex, itemIndex};
3970 _TableViewItem* pItem = FindItem(itemTag);
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));
3982 _TableViewPresenter::IsContextItemOpened(int groupIndex, int itemIndex) const
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);
3987 if (__sweptItemTag.groupIndex == -1 && __sweptItemTag.itemIndex == -1)
3992 if (__sweptItemTag.groupIndex == groupIndex && __sweptItemTag.itemIndex == itemIndex)
4001 _TableViewPresenter::SetSectionHeaderTextHorizontalAlignment(int sectionIndex, HorizontalAlignment alignment)
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);
4007 _TableViewSectionStringAlignment newAlignment;
4009 __sectionAlignmentList.GetAt(sectionIndex, newAlignment);
4010 newAlignment.headerHorizontalAlignment = alignment;
4011 __sectionAlignmentList.SetAt(newAlignment, sectionIndex);
4013 TableViewItemTag itemTag = {sectionIndex, -1};
4014 _TableViewItem* pItem = FindItem(itemTag);
4018 pItem->SetSectionHeaderFooterAlignment(alignment);
4025 _TableViewPresenter::GetSectionHeaderTextHorizontalAlignment(int sectionIndex) const
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);
4031 _TableViewSectionStringAlignment alignment;
4032 __sectionAlignmentList.GetAt(sectionIndex, alignment);
4034 return alignment.headerHorizontalAlignment;
4038 _TableViewPresenter::SetSectionFooterTextHorizontalAlignment(int sectionIndex, HorizontalAlignment alignment)
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);
4044 _TableViewSectionStringAlignment newAlignment;
4046 __sectionAlignmentList.GetAt(sectionIndex, newAlignment);
4047 newAlignment.footerHorizontalAlignment= alignment;
4048 __sectionAlignmentList.SetAt(newAlignment, sectionIndex);
4050 TableViewItemTag itemTag = {sectionIndex, GetItemCountAt(sectionIndex) - 1};
4051 _TableViewItem* pItem = FindItem(itemTag);
4055 pItem->SetSectionHeaderFooterAlignment(alignment);
4062 _TableViewPresenter::GetSectionFooterTextHorizontalAlignment(int sectionIndex) const
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);
4068 _TableViewSectionStringAlignment alignment;
4069 __sectionAlignmentList.GetAt(sectionIndex, alignment);
4071 return alignment.footerHorizontalAlignment;
4075 _TableViewPresenter::IsValidDrawnItem(int groupIndex, int itemIndex)
4077 TableViewItemTag currentItemTag = {groupIndex, itemIndex};
4078 TableViewItemTag itemTag = {-1, -1};
4080 if (GetNextItemPosition(currentItemTag, itemTag))
4082 if (__pListModel->IsLoadedItem(itemTag.groupIndex, itemTag.itemIndex))
4088 if (GetPreviousItemPosition(currentItemTag, itemTag))
4090 if (__pListModel->IsLoadedItem(itemTag.groupIndex, itemTag.itemIndex))
4100 _TableViewPresenter::StopAllItemAnimation(void)
4102 TableViewItemTag currentItemTag = {-1, -1};
4103 TableViewItemTag lastItemTag = {-1, -1};
4105 __pListModel->GetFirstLoadedItemIndex(currentItemTag.groupIndex, currentItemTag.itemIndex);
4106 __pListModel->GetLastLoadedItemIndex(lastItemTag.groupIndex, lastItemTag.itemIndex);
4110 _TableViewItem* pItem = FindItem(currentItemTag);
4113 pItem->StopAllAnimation();
4116 if (currentItemTag.groupIndex == lastItemTag.groupIndex && currentItemTag.itemIndex == lastItemTag.itemIndex)
4121 }while (GetNextItemPosition(currentItemTag, currentItemTag));
4125 _TableViewPresenter::GetTableViewItemPosition(_TableViewItem& item, TableViewItemTag& itemTag)
4127 TableViewItemTag lastLoadedItemPos = {-1, -1};
4128 TableViewItemTag firstLoadedItemPos = {-1, -1};
4129 __pListModel->GetLastLoadedItemIndex(lastLoadedItemPos.groupIndex, lastLoadedItemPos.itemIndex);
4130 __pListModel->GetFirstLoadedItemIndex(firstLoadedItemPos.groupIndex, firstLoadedItemPos.itemIndex);
4132 _TableViewItem* pCurrentItem = null;
4135 pCurrentItem = static_cast<_TableViewItem*>(__pListModel->LoadItem(firstLoadedItemPos.groupIndex, firstLoadedItemPos.itemIndex));
4136 if (pCurrentItem == &item)
4138 itemTag.groupIndex = firstLoadedItemPos.groupIndex;
4139 itemTag.itemIndex = firstLoadedItemPos.itemIndex;
4143 if ((firstLoadedItemPos.itemIndex == lastLoadedItemPos.itemIndex) && (firstLoadedItemPos.groupIndex == lastLoadedItemPos.groupIndex))
4147 } while (GetNextItemPosition(firstLoadedItemPos, firstLoadedItemPos));
4153 _TableViewPresenter::GetItemHeight(TableViewItemTag itemTag) const
4155 float itemHeight = 0.0f;
4157 if (__pTableView->GetTableViewStyle() == TABLE_VIEW_STYLE_SECTION && itemTag.itemIndex != -1)
4159 if (HasSectionFooter(itemTag.groupIndex))
4161 if (itemTag.itemIndex == GetItemCountAt(itemTag.groupIndex) - 1)
4163 GET_SHAPE_CONFIG(TABLEVIEW::GROUPITEM_DEFAULT_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, itemHeight);
4169 if (__pProviderAdaptor == null)
4175 for (int i = 0; i < itemTag.groupIndex; i++)
4177 int itemCount = GetItemCountAt(i);
4179 startIndex = startIndex + itemCount + 1;
4182 itemTag.itemIndex++;
4183 itemTag.itemIndex = startIndex + itemTag.itemIndex;
4185 _TableViewItemHeight itemHeightListEntry;
4186 __itemHeightList.GetAt(itemTag.itemIndex, itemHeightListEntry);
4188 return itemHeightListEntry.itemHeight;
4192 _TableViewPresenter::SetItemHeight(TableViewItemTag itemTag, float height)
4195 _TableViewItemHeight oldHeightEntry;
4196 _TableViewItemHeight itemHeightListEntry;
4198 itemHeightListEntry.itemHeight = height;
4199 itemHeightListEntry.groupIndex = itemTag.groupIndex;
4200 itemHeightListEntry.itemIndex = itemTag.itemIndex;
4202 for (int i = 0; i < itemTag.groupIndex; i++)
4204 int itemCount = GetItemCountAt(i);
4206 startIndex = startIndex + itemCount + 1;
4209 itemTag.itemIndex++;
4210 itemTag.itemIndex = startIndex + itemTag.itemIndex;
4212 __itemHeightList.GetAt(itemTag.itemIndex, oldHeightEntry);
4214 itemHeightListEntry.isFooterItem = oldHeightEntry.isFooterItem;
4216 __itemHeightList.SetAt(itemHeightListEntry, itemTag.itemIndex);
4218 return oldHeightEntry.itemHeight;
4222 _TableViewPresenter::SetReorderMode(bool enabled)
4226 __reorderInfo.itemIndex = -1;
4227 __reorderInfo.groupIndex = -1;
4229 _TableViewItem* pItem = null;
4230 TableViewItemTag itemPos = {-1, -1};
4231 TableViewItemTag lastItemPos = {-1, -1};
4233 __pListModel->GetFirstLoadedItemIndex(itemPos.groupIndex, itemPos.itemIndex);
4234 __pListModel->GetLastLoadedItemIndex(lastItemPos.groupIndex, lastItemPos.itemIndex);
4238 pItem = FindItem(itemPos);
4242 if(pItem->IsReorderMode() == enabled)
4247 pItem->SetReorderMode(enabled);
4249 if (enabled && itemPos.itemIndex != -1)
4251 if (pItem->GetDrawingStatus() == TABLE_VIEW_ITEM_DRAWING_STATUS_PRESSED)
4253 if (SelectReorderItem(itemPos.groupIndex, itemPos.itemIndex, true))
4255 FloatPoint itemPosition = pItem->GetPositionF();
4256 FloatPoint touchPosition = pItem->GetLastTouchPressedPositionF();
4258 __reorderInfo.touchPressedPositionY = itemPosition.y + touchPosition.y - GetScrollPosition();
4259 __reorderInfo.blockedTouchReleaseState = true;
4265 if ((itemPos.itemIndex == lastItemPos.itemIndex) && (itemPos.groupIndex == lastItemPos.groupIndex))
4270 } while (GetNextItemPosition(itemPos, itemPos) == true);
4276 _TableViewPresenter::SelectReorderItem(int groupIndex, int itemIndex, bool directSelection)
4278 if (itemIndex == -1 || (!directSelection && GetPressedItemCount() > 0))
4283 TableViewItemTag itemPos = {groupIndex, itemIndex};
4284 _TableViewItem* pItem = FindItem(itemPos);
4291 pItem->SetDrawingStatus(TABLE_VIEW_ITEM_DRAWING_STATUS_PRESSED);
4292 pItem->SetItemChanged(true);
4293 pItem->Invalidate();
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;
4303 Tizen::System::SystemTime::GetTicks(__reorderInfo.touchPressedTick);
4305 pItem->GetVisualElement()->SetZOrder(null, true);
4307 if (GetScrollAreaBounds().height < __pTableView->GetBoundsF().height)
4309 float itemHeight = pItem->GetBoundsF().height;
4311 __pListModel->GetLastLoadedItemIndex(itemPos.groupIndex, itemPos.itemIndex);
4313 pItem = FindItem(itemPos);
4317 FloatRectangle itemBounds = pItem->GetBoundsF();
4318 __reorderInfo.nonScrollableLimitArea = itemBounds.y + itemBounds.height - itemHeight;
4323 __reorderInfo.nonScrollableLimitArea = 0;
4330 _TableViewPresenter::ResetReorderItem(int groupIndex, int itemIndex)
4332 TableViewItemTag itemPos = {groupIndex, itemIndex};
4333 _TableViewItem* pItem = FindItem(itemPos);
4340 pItem->SetDrawingStatus(TABLE_VIEW_ITEM_DRAWING_STATUS_NORMAL);
4341 pItem->SetItemChanged(true);
4342 pItem->Invalidate();
4344 PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_LIST_REORDER, pItem);
4346 FloatPoint position = FloatPoint(__reorderInfo.itemBounds.x, __reorderInfo.itemBounds.y);
4347 pItem->SetPosition(position);
4349 if (__reorderInfo.originGroupIndex != __reorderInfo.groupIndex || __reorderInfo.originItemIndex != __reorderInfo.itemIndex)
4351 if (__pTableView->GetTableViewStyle() == TABLE_VIEW_STYLE_SIMPLE)
4353 __pTableView->FireTableViewItemReorderEvent(__reorderInfo.originItemIndex, __reorderInfo.itemIndex);
4355 else if (__pTableView->GetTableViewStyle() == TABLE_VIEW_STYLE_GROUPED)
4357 __pTableView->FireTableViewItemReorderEvent(__reorderInfo.originGroupIndex, __reorderInfo.originItemIndex, __reorderInfo.groupIndex, __reorderInfo.itemIndex);
4361 __reorderInfo.groupIndex = -1;
4362 __reorderInfo.itemIndex = -1;
4363 __reorderInfo.originGroupIndex = -1;
4364 __reorderInfo.originItemIndex = -1;
4365 __reorderInfo.nonScrollableLimitArea = 0;
4367 StopReorderScrollTimer();
4373 _TableViewPresenter::CheckReorderItemScrollAnimation(_TableViewItem *pItem)
4375 float currentScrollPosition = GetScrollPosition();
4376 float limitTopPositionY = currentScrollPosition;
4377 float limitBottomPositionY = currentScrollPosition + __pTableView->GetBoundsF().height - __reorderInfo.itemBounds.height;
4379 float itemPositionY = pItem->GetPositionF().y;
4381 if (itemPositionY < limitTopPositionY)
4383 if (__pReorderScrollTimer == null)
4385 __reorderInfo.isScrollDirectionUp = true;
4390 else if (itemPositionY > limitBottomPositionY)
4392 if (__pReorderScrollTimer == null)
4394 __reorderInfo.isScrollDirectionUp = false;
4404 _TableViewPresenter::DragSelectedItem(float distance, bool relativeCoordinate)
4406 TableViewItemTag itemPos = {__reorderInfo.groupIndex, __reorderInfo.itemIndex};
4407 _TableViewItem* pItem = FindItem(itemPos);
4414 if (__firstTouchMoved)
4416 long long currentTick = 0;
4417 Tizen::System::SystemTime::GetTicks(currentTick);
4419 if (currentTick - __reorderInfo.touchPressedTick < REORDER_TOUCH_UIACTIVATE_DURATION)
4424 __firstTouchMoved = false;
4427 FloatPoint itemPosition = pItem->GetPositionF();
4429 if (relativeCoordinate)
4431 itemPosition.y = __reorderInfo.itemBasisPositionY + distance;
4435 itemPosition.y += distance;
4437 __reorderInfo.itemBasisPositionY += distance;
4440 if (itemPosition.y < 0)
4442 __reorderInfo.itemBasisPositionY += (0 - itemPosition.y);
4446 float scrollAreaHeight = GetScrollAreaBounds().height;
4447 float screenHeight = __pTableView->GetBoundsF().height;
4448 float limitBottomPositionY = 0.0f;
4450 if (scrollAreaHeight < screenHeight)
4452 limitBottomPositionY = __reorderInfo.nonScrollableLimitArea;
4456 limitBottomPositionY = scrollAreaHeight - __reorderInfo.itemBounds.height;
4459 if (itemPosition.y > limitBottomPositionY)
4461 __reorderInfo.itemBasisPositionY -= (itemPosition.y - limitBottomPositionY);
4462 itemPosition.y = limitBottomPositionY;
4465 pItem->SetPosition(itemPosition);
4468 if (CheckReorderItemScrollAnimation(pItem))
4470 if (__pReorderScrollTimer == null)
4472 StartReorderScrollTimer();
4477 if (__pReorderScrollTimer != null)
4479 StopReorderScrollTimer();
4484 TableViewItemTag moveItemTag = {-1, -1};
4486 if (CheckReorderItemPosition(pItem, moveItemTag))
4488 if (moveItemTag.itemIndex == -1)
4490 int destGroupIndex = moveItemTag.groupIndex;
4492 if (destGroupIndex != 0 && destGroupIndex == __reorderInfo.groupIndex)
4497 if (moveItemTag.groupIndex == 0 || !__pProviderAdaptor->IsReorderable(__reorderInfo.groupIndex, destGroupIndex))
4499 __reorderInfo.blockedScroll = true;
4505 ReorderItem(moveItemTag.groupIndex, moveItemTag.itemIndex);
4512 _TableViewPresenter::CheckReorderItemPosition(_TableViewItem* pItem, TableViewItemTag& reorderItemTag)
4514 TableViewItemTag currentItemTag = {__reorderInfo.groupIndex, __reorderInfo.itemIndex};
4515 TableViewItemTag previousItemTag = {-1, -1};
4516 TableViewItemTag nextItemTag = {-1, -1};
4518 FloatRectangle itemBounds = pItem->GetBoundsF();
4520 if (GetPreviousItemPosition(currentItemTag, previousItemTag))
4522 _TableViewItem* pPreviousItem = LoadItem(previousItemTag.groupIndex, previousItemTag.itemIndex);
4524 if (pPreviousItem != null)
4526 FloatRectangle previousItemBounds = pPreviousItem->GetBoundsF();
4528 if (itemBounds.y < previousItemBounds.y + (previousItemBounds.height / 2))
4530 //return previousItemIndex;
4531 reorderItemTag.groupIndex = previousItemTag.groupIndex;
4532 reorderItemTag.itemIndex = previousItemTag.itemIndex;
4539 if (GetNextItemPosition(currentItemTag, nextItemTag))
4541 _TableViewItem* pNextItem = LoadItem(nextItemTag.groupIndex, nextItemTag.itemIndex);
4543 if (pNextItem != null)
4545 FloatRectangle nextItemBounds = pNextItem->GetBoundsF();
4547 if (itemBounds.y + itemBounds.height > nextItemBounds.y + (nextItemBounds.height / 2))
4549 //return nextItemIndex;
4550 reorderItemTag.groupIndex = nextItemTag.groupIndex;
4551 reorderItemTag.itemIndex = nextItemTag.itemIndex;
4558 reorderItemTag.groupIndex = -1;
4559 reorderItemTag.itemIndex = -1;
4565 _TableViewPresenter::ReorderItem(int destinationGroupIndex, int destinationItemIndex)
4567 TableViewItemTag itemPos = {destinationGroupIndex, destinationItemIndex};
4569 _TableViewItem* pItem = FindItem(itemPos);
4576 if (pItem->IsAnimationPlaying())
4581 FloatRectangle destinationItemBounds = pItem->GetBoundsF();
4583 FloatPoint destinationItemPosition = FloatPoint(destinationItemBounds.x, 0.0f);
4585 if (__reorderInfo.itemIndex > destinationItemIndex && __reorderInfo.groupIndex == destinationGroupIndex)
4587 destinationItemPosition.y = __reorderInfo.itemBounds.y + __reorderInfo.itemBounds.height - destinationItemBounds.height;
4588 __reorderInfo.itemBounds.y = destinationItemBounds.y;
4590 if (destinationItemIndex == -1)
4592 destinationGroupIndex--;
4593 int itemCount = GetItemCountAt(destinationGroupIndex);
4594 destinationItemIndex = itemCount;
4599 destinationItemPosition.y = __reorderInfo.itemBounds.y;
4600 __reorderInfo.itemBounds.y = destinationItemBounds.y + destinationItemBounds.height - __reorderInfo.itemBounds.height;
4602 if (destinationItemIndex == -1)
4604 destinationItemIndex = 0;
4608 __pListModel->MoveItem(__reorderInfo.groupIndex, __reorderInfo.itemIndex, destinationGroupIndex, destinationItemIndex);
4610 if (!pItem->MoveItem(destinationItemPosition, REORDER_ITEM_MOVE_ANIMATION_DURATION, 0))
4612 pItem->SetPosition(destinationItemPosition);
4615 __reorderInfo.itemIndex = destinationItemIndex;
4616 __reorderInfo.groupIndex = destinationGroupIndex;
4622 _TableViewPresenter::StartReorderScrollTimer(void)
4624 StopReorderScrollTimer();
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));
4629 result r = __pReorderScrollTimer->Construct(*this);
4630 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
4632 r = __pReorderScrollTimer->Start(REORDER_SCROLL_ANIMATION_TIMER_DURATION);
4633 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
4638 StopReorderScrollTimer();
4642 _TableViewPresenter::StopReorderScrollTimer(void)
4644 delete __pReorderScrollTimer;
4645 __pReorderScrollTimer = null;
4650 _TableViewPresenter::UpdateLayout(void)
4656 _TableViewPresenter::CheckItemHeightAndRefreshLayout(TableViewItemTag itemTag, bool downScroll)
4658 _TableViewItem* pItem = FindItem(itemTag);
4665 if (pItem->IsAnimationPlaying())
4670 FloatRectangle itemBounds = pItem->GetBoundsF();
4672 if (_FloatCompare(GetItemHeight(itemTag), itemBounds.height))
4677 float newHeight = itemBounds.height;
4678 float originHeight = SetItemHeight(itemTag, newHeight);
4679 float dist = newHeight - originHeight;
4681 AdjustClientAreaBounds(false, dist);
4685 itemBounds.y += dist;
4686 pItem->SetBounds(itemBounds);
4689 AttachNextItemsToBottom(itemTag);
4695 _TableViewPresenter::CreateItemHeightList(float defaultGroupItemHeight, float defaultItemHeight)
4697 int groupCount = GetGroupCount();
4699 _TableViewItemHeight itemHeightEntry;
4701 result r = __itemHeightList.SetCapacity(GetItemCount());
4702 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
4704 for (int i = 0; i < groupCount; i++)
4706 int itemCount = GetItemCountAt(i);
4707 itemHeightEntry.groupIndex = i;
4708 if (__pTableView->GetTableViewStyle() == TABLE_VIEW_STYLE_SIMPLE)
4710 itemHeightEntry.itemIndex = -1;
4711 itemHeightEntry.itemHeight = 0.0f;
4712 itemHeightEntry.isFooterItem = false;
4713 __itemHeightList.Add(itemHeightEntry);
4717 itemHeightEntry.itemIndex = -1;
4718 itemHeightEntry.itemHeight = defaultGroupItemHeight;
4719 itemHeightEntry.isFooterItem = false;
4720 __itemHeightList.Add(itemHeightEntry);
4723 for (int j = 0; j < itemCount; j++)
4725 itemHeightEntry.itemIndex = j;
4726 itemHeightEntry.itemHeight = defaultItemHeight;
4727 itemHeightEntry.isFooterItem = false;
4728 if (HasSectionFooter(i) && j == (itemCount - 1))
4730 itemHeightEntry.isFooterItem = true;
4732 __itemHeightList.Add(itemHeightEntry);
4739 DeleteItemHeightList();
4745 _TableViewPresenter::RestoreItemHeightList(float defaultGroupHeight, float defaultItemHeight)
4747 _TableViewItemHeight backupItem;
4748 _TableViewItemHeight currentItem;
4749 _TableViewItemHeight itemHeightEntry;
4750 int groupCount = GetGroupCount();
4751 bool isGroupItem = true;
4756 ArrayListT<_TableViewItemHeight> backupItemHeightList;
4757 backupItemHeightList.Construct();
4759 result r = backupItemHeightList.SetCapacity(__itemHeightList.GetCapacity());
4760 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
4762 for (int index = 0; index < __itemHeightList.GetCount(); index++)
4764 __itemHeightList.GetAt(index, backupItem);
4765 backupItemHeightList.Add(backupItem);
4768 DeleteItemHeightList();
4770 r = __itemHeightList.SetCapacity(GetItemCount());
4771 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
4773 for (int backUpListIndex = 0, actualListIndex = 0; actualListIndex < GetItemCount() && groupIndex < groupCount;)
4775 backupItemHeightList.GetAt(backUpListIndex, backupItem);
4776 if (groupIndex < groupCount)
4778 itemCount = GetItemCountAt(groupIndex);
4781 isGroupItem = false;
4782 itemHeightEntry.groupIndex = groupIndex;
4784 if (__pTableView->GetTableViewStyle() == TABLE_VIEW_STYLE_SIMPLE)
4786 itemHeightEntry.itemHeight = 0.0f;
4790 itemHeightEntry.itemHeight = defaultGroupHeight;
4793 itemHeightEntry.itemIndex = -1;
4794 itemHeightEntry.isFooterItem = false;
4795 __itemHeightList.Add(itemHeightEntry);
4804 itemHeightEntry.itemIndex = itemIndex;
4805 itemHeightEntry.itemHeight = defaultItemHeight;
4806 itemHeightEntry.isFooterItem = false;
4808 if (HasSectionFooter(groupIndex) && itemIndex == (itemCount - 1))
4810 itemHeightEntry.isFooterItem = true;
4812 __itemHeightList.Add(itemHeightEntry);
4815 if (itemIndex == itemCount)
4822 if (actualListIndex < GetItemCount() && backUpListIndex < backupItemHeightList.GetCount())
4824 __itemHeightList.GetAt(actualListIndex, currentItem);
4825 if (backupItem.isFooterItem)
4831 if(backupItem.groupIndex == currentItem.groupIndex && backupItem.itemIndex == currentItem.itemIndex)
4833 currentItem.itemHeight = backupItem.itemHeight;
4834 __itemHeightList.SetAt(currentItem, actualListIndex);
4838 else if (backupItem.groupIndex > currentItem.groupIndex)
4842 else if (backupItem.groupIndex < currentItem.groupIndex)
4848 SysLog(NID_UI_CTRL, "System error has occurred. Failed to restore the height values.");
4852 backupItemHeightList.RemoveAll();
4857 backupItemHeightList.RemoveAll();
4858 DeleteItemHeightList();
4864 _TableViewPresenter::DeleteItemHeightList(void)
4866 __itemHeightList.RemoveAll();
4870 _TableViewPresenter::RefreshItemHeightList(int groupIndex, int itemIndex, TableViewRefreshType refreshType)
4872 float defaultItemHeight = __pProviderAdaptor->GetDefaultItemHeight();
4873 float defaultGroupItemHeight = __pProviderAdaptor->GetDefaultGroupItemHeight();
4875 _TableViewItemHeight itemHeightEntry;
4878 for (int i = 0; i < groupIndex; i++)
4880 int itemCount = GetItemCountAt(i);
4881 startIndex = startIndex + itemCount + 1;
4884 int targetIndex = startIndex + itemIndex + 1;
4886 if (refreshType == TABLE_VIEW_REFRESH_TYPE_ITEM_ADD)
4888 if (itemIndex == -1)
4890 result r = __itemHeightList.SetCapacity(GetItemCount());
4891 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));
4893 int itemCount = GetItemCountAt(groupIndex);
4894 for (int i = 0; i < itemCount; i++)
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))
4902 itemHeightEntry.isFooterItem = true;
4905 __itemHeightList.InsertAt(itemHeightEntry, targetIndex);
4908 itemHeightEntry.groupIndex = groupIndex;
4909 itemHeightEntry.itemIndex = itemIndex;
4910 itemHeightEntry.itemHeight = defaultGroupItemHeight;
4911 itemHeightEntry.isFooterItem = false;
4912 __itemHeightList.InsertAt(itemHeightEntry, targetIndex);
4914 int updateIndex = targetIndex + itemCount + 1;// Increment the group Index below the added item by 1
4916 int groupCount = GetGroupCount();
4918 for (int i = 0; i < groupCount; i++)
4920 int itemCount = GetItemCountAt(i);
4921 lastIndex = lastIndex + itemCount + 1;
4924 for (int index = updateIndex; index < lastIndex; index++)
4926 __itemHeightList.GetAt(index, itemHeightEntry);
4927 itemHeightEntry.groupIndex = itemHeightEntry.groupIndex + 1;
4928 __itemHeightList.SetAt(itemHeightEntry, index);
4933 itemHeightEntry.groupIndex = groupIndex;
4934 itemHeightEntry.itemIndex = itemIndex;
4935 itemHeightEntry.itemHeight = defaultItemHeight;
4936 itemHeightEntry.isFooterItem = false;
4937 __itemHeightList.InsertAt(itemHeightEntry, targetIndex);
4939 int itemCount = GetItemCountAt(groupIndex);
4940 int remainingItemCount = (itemCount - itemIndex);
4942 for (int i = (targetIndex + 1); i < (targetIndex + remainingItemCount); i++)
4944 __itemHeightList.GetAt(i, itemHeightEntry);
4945 itemHeightEntry.groupIndex = groupIndex;
4946 itemHeightEntry.itemIndex = itemHeightEntry.itemIndex + 1;
4947 __itemHeightList.SetAt(itemHeightEntry, i);
4951 else if (refreshType == TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE)
4953 if (itemIndex == -1)
4955 int itemCount = GetItemCountAt(groupIndex) + 1;
4957 for (int i = 0; i < itemCount; i++)
4959 __itemHeightList.RemoveAt(targetIndex);
4962 int updateIndex = targetIndex;// Decrement the group Index below the added item by 1
4965 for (int i = 0; i < (GetGroupCount() + 1); i++)
4967 int itemCount = GetItemCountAt(i);
4968 lastIndex = lastIndex + itemCount + 1;
4971 for (int index = updateIndex; index < lastIndex; index++)
4973 __itemHeightList.GetAt(index, itemHeightEntry);
4974 itemHeightEntry.groupIndex = itemHeightEntry.groupIndex - 1;
4975 __itemHeightList.SetAt(itemHeightEntry, index);
4980 __itemHeightList.RemoveAt(targetIndex);
4981 int itemCount = GetItemCountAt(groupIndex);
4982 int remainingItemCount = itemCount - itemIndex;
4984 for (int i = targetIndex; i < (targetIndex + remainingItemCount); i++)
4986 __itemHeightList.GetAt(i, itemHeightEntry);
4987 itemHeightEntry.groupIndex = groupIndex;
4988 itemHeightEntry.itemIndex = (itemHeightEntry.itemIndex - 1);
4989 __itemHeightList.SetAt(itemHeightEntry, i);
4998 _TableViewPresenter::CreateSectionAlignmentList(void)
5000 if (__pTableView->GetTableViewStyle() != TABLE_VIEW_STYLE_SECTION)
5005 int groupCount = GetGroupCount();
5007 result r = __sectionAlignmentList.SetCapacity(GetGroupCount());
5008 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));
5010 _TableViewSectionStringAlignment alignment;
5011 alignment.headerHorizontalAlignment = ALIGNMENT_LEFT;
5012 alignment.footerHorizontalAlignment = ALIGNMENT_RIGHT;
5014 for (int i = 0; i < groupCount; i++)
5016 __sectionAlignmentList.Add(alignment);
5023 _TableViewPresenter::DeleteSectionAlignmentList(void)
5025 __sectionAlignmentList.RemoveAll();
5029 _TableViewPresenter::RefreshSectionAlignmentList(int groupIndex, TableViewRefreshType refreshType)
5031 if (__pTableView->GetTableViewStyle() != TABLE_VIEW_STYLE_SECTION)
5036 if (refreshType == TABLE_VIEW_REFRESH_TYPE_ITEM_ADD)
5038 _TableViewSectionStringAlignment alignment;
5039 alignment.headerHorizontalAlignment = ALIGNMENT_LEFT;
5040 alignment.footerHorizontalAlignment = ALIGNMENT_RIGHT;
5042 __sectionAlignmentList.InsertAt(alignment, groupIndex);
5044 else if (refreshType == TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE)
5046 __sectionAlignmentList.RemoveAt(groupIndex);
5053 _TableViewPresenter::CaptureAndStartRemoveItemAnimation(int groupIndex, int itemIndex)
5055 TableViewItemTag itemTag = {groupIndex, itemIndex};
5056 _TableViewItem* pItem = FindItem(itemTag);
5063 FloatRectangle itemBounds = pItem->GetBoundsF();
5064 result r = E_SUCCESS;
5066 _VisualElement* pVisualElement = null;
5067 String animationName(L"REMOVE_ITEM_ANIMATION");
5068 Canvas* pCanvas = null;
5069 VisualElementValueAnimation* pAnimation = __pTableView->GetVisualElementValueAnimation(animationName);
5071 FloatDimension startValue(100.0f, itemBounds.height);
5072 FloatDimension endValue(0.0f, 0.0f);
5074 Tizen::Graphics::Bitmap* pBitmap = pItem->GetCapturedBitmapN(true);
5076 if (pBitmap == 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));
5085 r = pVisualElement->Construct();
5086 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
5088 pVisualElement->SetImplicitAnimationEnabled(false);
5089 pVisualElement->SetSurfaceOpaque(false);
5090 pVisualElement->SetBounds(FloatRectangle(itemBounds.x, itemBounds.y, itemBounds.width, itemBounds.height));
5091 pVisualElement->SetShowState(true);
5093 pCanvas = pVisualElement->GetCanvasN();
5094 SysTryCatch(NID_UI_CTRL, pCanvas != null, , E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
5097 pCanvas->DrawBitmap(FloatRectangle(0, 0, itemBounds.width, itemBounds.height), *pBitmap);
5099 pAnimation->SetDelay(0);
5100 pAnimation->SetStartValue(Variant(startValue));
5101 pAnimation->SetEndValue(Variant(endValue));
5102 pAnimation->SetDuration(REMOVE_ITEM_MOVE_ANIMATION_DURATION);
5104 r = pVisualElement->AddAnimation(animationName, *pAnimation);
5105 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
5116 pVisualElement->Destroy();
5120 _TableViewPresenter::PresetItemHeightList(void)
5122 int groupCount = GetGroupCount();
5123 float defaultGroupItemHeight = __pProviderAdaptor->GetDefaultGroupItemHeight();
5124 float defaultItemHeight = __pProviderAdaptor->GetDefaultItemHeight();
5126 for (int i = 0; i < groupCount; i++)
5128 TableViewItemTag itemTag = {i, -1};
5129 int itemCount = GetItemCountAt(i);
5131 if (_FloatCompare(GetItemHeight(itemTag), TABLEVIEW_DEFAULT_ITEM_HEIGHT_VALUE))
5133 SetItemHeight(itemTag, defaultGroupItemHeight);
5136 for (int j = 0; j < itemCount; j++)
5138 itemTag.itemIndex = j;
5140 if (_FloatCompare(GetItemHeight(itemTag), TABLEVIEW_DEFAULT_ITEM_HEIGHT_VALUE))
5142 SetItemHeight(itemTag, defaultItemHeight);
5149 _TableViewPresenter::GetTableViewItemFromControl(const _Control& source)
5151 _Control* currentControl = const_cast<_Control*>(&source);
5152 _TableViewItem* pItem = null;
5154 while (__pTableView != currentControl)
5156 pItem = dynamic_cast<_TableViewItem*>(currentControl);
5158 if ((pItem != null) || (currentControl == null))
5163 currentControl = currentControl->GetParent();
5170 _TableViewPresenter::ShowTableViewCapturedItem(int groupIndex, int itemIndex, float height)
5172 TableViewItemTag itemTag = {groupIndex, itemIndex};
5173 _TableViewItem* pItem = FindItem(itemTag);
5175 if ((pItem == null) || _FloatCompare(height, 0.0f))
5180 result r = E_SUCCESS;
5181 Canvas* pCanvas = null;
5182 FloatRectangle itemBounds = pItem->GetBoundsF();
5184 bool visibleState = pItem->GetVisibleState();
5185 pItem->SetVisibleState(true);
5186 Bitmap* pBitmap = pItem->GetCapturedBitmapN(true);
5187 pItem->SetVisibleState(visibleState);
5189 if (pBitmap == null)
5194 if (__pCapturedItemVisualElement == null)
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));
5199 r = __pCapturedItemVisualElement->Construct();
5200 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
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));
5205 __pCapturedItemVisualElement->SetSurfaceOpaque(false);
5206 __pCapturedItemVisualElement->SetImplicitAnimationEnabled(false);
5209 __pCapturedItemVisualElement->SetShowState(true);
5210 __pCapturedItemVisualElement->SetBounds(FloatRectangle(itemBounds.x, itemBounds.y, itemBounds.width, height));
5212 pCanvas = __pCapturedItemVisualElement->GetCanvasN();
5213 SysTryCatch(NID_UI_CTRL, pCanvas != null, , E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
5215 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
5217 pCanvas->DrawBitmap(FloatPoint(0.0f, 0.0f), *pBitmap);
5227 __pCapturedItemVisualElement->Destroy();
5231 _TableViewPresenter::SetLoadedItemsVisibleFromPosition(float position, bool visible)
5233 _TableViewItem* pItem;
5234 FloatRectangle itemBounds;
5235 TableViewItemTag current;
5236 current.groupIndex = __expandableItemTag.groupIndex;
5237 current.itemIndex = __expandableItemTag.itemIndex;
5239 int itemCountInGroup = __pListModel->GetItemCountInGroup(__expandableItemTag.groupIndex);
5241 for (int i = 0; i < itemCountInGroup; i++)
5243 current.itemIndex = i;
5247 pItem = LoadItem(current.groupIndex, current.itemIndex);
5255 pItem = FindItem(current);
5262 itemBounds = pItem->GetBoundsF();
5266 if ((position >= itemBounds.y) && (position < itemBounds.y + itemBounds.height))
5268 ShowTableViewCapturedItem(current.groupIndex, current.itemIndex, position - itemBounds.y);
5269 pItem->SetVisibleState(false);
5274 pItem->SetVisibleState(true);
5279 if (position < itemBounds.y)
5281 UnloadItem(current);
5283 else if ((position >= itemBounds.y) && (position < itemBounds.y + itemBounds.height))
5285 pItem->SetVisibleState(false);
5286 ShowTableViewCapturedItem(current.groupIndex, current.itemIndex, position - itemBounds.y);
5290 pItem->SetVisibleState(true);
5297 _TableViewPresenter::MoveLoadedItemsFromPosition(float position)
5299 FloatRectangle itemBounds;
5300 float itemPosition = position;
5302 TableViewItemTag current;
5303 TableViewItemTag next;
5305 current.groupIndex = __expandableItemTag.groupIndex;
5306 current.itemIndex = __pListModel->GetItemCountInGroup(__expandableItemTag.groupIndex) -1;
5308 float screenPosition = GetScrollPosition();
5309 FloatRectangle screenBounds = __pTableView->GetBoundsF();
5310 screenPosition += screenBounds.height;
5312 _TableViewItem* pItem = null;
5313 while (GetNextItemPosition(current, next))
5315 if (screenPosition > itemPosition)
5317 pItem = LoadItem(next.groupIndex, next.itemIndex);
5321 pItem = FindItem(next);
5329 itemBounds = pItem->GetBoundsF();
5330 itemBounds.y = itemPosition;
5331 pItem->SetBounds(itemBounds);
5332 itemPosition += itemBounds.height;
5339 _TableViewPresenter::ExpandGroupAnimationFinished(bool completedNormally)
5341 if (completedNormally == false)
5343 TableViewItemTag current;
5344 TableViewItemTag next;
5346 current.groupIndex = __expandableItemTag.groupIndex;
5347 current.itemIndex = -1;
5349 _TableViewItem* pNextItem = null;
5350 _TableViewItem* pCurrentItem = null;
5351 pCurrentItem = LoadItem(current.groupIndex, current.itemIndex);
5353 if (pCurrentItem == null)
5358 FloatRectangle itemBounds;
5359 FloatRectangle screenBounds = __pTableView->GetBoundsF();
5360 float screenPosition = GetScrollPosition() + screenBounds.height;
5361 float nextItemPositionY = pCurrentItem->GetBoundsF().y + pCurrentItem->GetBoundsF().height;
5363 while (GetNextItemPosition(current, next))
5365 if (screenPosition >= nextItemPositionY)
5367 pCurrentItem = LoadItem(current.groupIndex, current.itemIndex);
5368 if (pCurrentItem == null)
5372 pNextItem = LoadItem(next.groupIndex, next.itemIndex);
5373 if (pNextItem == null)
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;
5385 UnloadItem(next.groupIndex, next.itemIndex);
5393 int currentGroupIndex = -1;
5394 int currentItemIndex = -1;
5395 GetBottomDrawnItemIndex(currentGroupIndex, currentItemIndex);
5397 int lastLoadedGroupIndex = -1;
5398 int lastLoadedItemIndex = -1;
5399 __pListModel->GetLastLoadedItemIndex(lastLoadedGroupIndex, lastLoadedItemIndex);
5401 TableViewItemTag current;
5402 current.groupIndex = currentGroupIndex;
5403 current.itemIndex = currentItemIndex;
5405 _TableViewItem* pCurrentItem;
5406 pCurrentItem = FindItem(current);
5407 if (pCurrentItem != null)
5409 pCurrentItem->SetVisibleState(true);
5412 for (int j = currentGroupIndex; j <= lastLoadedGroupIndex; j++)
5414 int itemCount = GetItemCountAt(j);
5416 for (int i = -1; i < itemCount; i++)
5418 if (i <= currentItemIndex && j == currentGroupIndex)
5430 _TableViewPresenter::CollapseGroupAnimationFinished(bool completedNormally)
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++)
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());
5445 if (completedNormally == false)
5447 TableViewItemTag current;
5448 TableViewItemTag next;
5450 current.groupIndex = __expandableItemTag.groupIndex;
5451 current.itemIndex = -1;
5453 for (int i = 0; i < itemCountInGroup; i++)
5455 UnloadItem(__expandableItemTag.groupIndex, i);
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);
5463 float nextItemPositionY = pCurrentItem->GetBoundsF().y + pCurrentItem->GetBoundsF().height;
5465 FloatRectangle screenBounds = __pTableView->GetBoundsF();
5466 float screenPosition = GetScrollPosition() + screenBounds.height;
5468 while (GetNextItemPosition(current, next))
5471 if (screenPosition >= nextItemPositionY)
5473 pCurrentItem = LoadItem(current.groupIndex, current.itemIndex);
5474 if (pCurrentItem == null)
5479 pCurrentItem->SetVisibleState(true);
5480 itemBounds = pCurrentItem->GetBoundsF();
5481 itemBounds.y = nextItemPositionY;
5482 pCurrentItem->SetBounds(itemBounds);
5483 nextItemPositionY = pCurrentItem->GetBoundsF().y + pCurrentItem->GetBoundsF().height;
5487 UnloadItem(current.groupIndex, current.itemIndex);
5491 int currentGroupIndex = -1;
5492 int currentItemIndex = -1;
5493 GetTopDrawnItemIndex(currentGroupIndex, currentItemIndex);
5494 if (__expandableItemTag.groupIndex < currentGroupIndex)
5496 SetScrollPosition(GetScrollPosition() - groupTotalHeight, false);
5501 int currentGroupIndex = -1;
5502 int currentItemIndex = -1;
5503 GetTopDrawnItemIndex(currentGroupIndex, currentItemIndex);
5505 int firstLoadedGroupIndex = -1;
5506 int firstLoadedItemIndex = -1;
5507 __pListModel->GetFirstLoadedItemIndex(firstLoadedGroupIndex, firstLoadedItemIndex);
5509 for (int j = firstLoadedGroupIndex; j <= currentGroupIndex; j++)
5511 int itemCount = GetItemCountAt(j);
5513 for (int i = -1; i < itemCount; i++)
5515 if (i >= currentItemIndex && j == currentGroupIndex)
5524 for (int i = 0; i < itemCountInGroup; i++)
5526 UnloadItem(__expandableItemTag.groupIndex, i);
5529 GetTopDrawnItemIndex(currentGroupIndex, currentItemIndex);
5530 TableViewItemTag currentItemTag;
5531 currentItemTag.groupIndex = currentGroupIndex;
5532 currentItemTag.itemIndex = currentItemIndex;
5534 _TableViewItem* pItem = FindItem(currentItemTag);
5537 FloatRectangle itemBounds = pItem->GetBoundsF();
5538 itemBounds.y = CalculateItemPositionY(currentGroupIndex, currentItemIndex);
5539 pItem->SetBounds(itemBounds);
5540 AttachNextItemsToBottom(currentItemTag);
5541 if (__expandableItemTag.groupIndex < currentGroupIndex)
5543 SetScrollPosition(itemBounds.y, false);
5548 AdjustClientAreaBounds(false, -groupTotalHeight);
5552 _TableViewPresenter::RestoreEditCopyPasteManager(void)
5554 _ControlManager* pControlManager = _ControlManager::GetInstance();
5555 SysTryReturnVoidResult(NID_UI_CTRL, pControlManager != null, E_SYSTEM, "Failed to get Control Manager.");
5557 _Control* pFocusControl = pControlManager->GetFocusControl();
5558 SysTryReturnVoidResult(NID_UI_CTRL, pFocusControl != null, E_SYSTEM, "Failed to get Focussed Control.");
5560 _Edit* pEdit = dynamic_cast<_Edit*>(pFocusControl);
5566 _Control* pControl = pEdit;
5569 pControl = pControl->GetParent();
5570 _TableViewItem* pItem = dynamic_cast<_TableViewItem*>(pControl);
5573 pEdit->Invalidate();
5580 _TableViewPresenter::OnVisualElementAnimationStarted(const Tizen::Ui::Animations::VisualElementAnimation& animation, const Tizen::Base::String& keyName, Tizen::Ui::Animations::VisualElement& target)
5582 if (keyName == L"REMOVE_ITEM_ANIMATION")
5587 if (keyName == L"SCROLL_PANEL_SCROLLING_ANIMATION")
5589 __scrollHeightOnFlickStarted = GetScrollAreaBounds().height;
5590 __scrollPositionOnFlickStarted = GetScrollPosition();
5593 _ScrollPanelPresenter::OnVisualElementAnimationStarted(animation, keyName, target);
5597 _TableViewPresenter::OnVisualElementAnimationRepeated(const Tizen::Ui::Animations::VisualElementAnimation& animation, const Tizen::Base::String& keyName, Tizen::Ui::Animations::VisualElement& target, long currentRepeatCount)
5599 if (keyName == L"REMOVE_ITEM_ANIMATION")
5603 _ScrollPanelPresenter::OnVisualElementAnimationRepeated(animation, keyName, target, currentRepeatCount);
5607 _TableViewPresenter::OnVisualElementAnimationFinished(const Tizen::Ui::Animations::VisualElementAnimation& animation, const Tizen::Base::String& keyName, Tizen::Ui::Animations::VisualElement& target, bool completedNormally)
5609 if (__isAnimationCallbackBlocked)
5614 if (keyName == L"REMOVE_ITEM_ANIMATION")
5616 _VisualElement* pVisualElement = GetView()->GetVisualElement();
5618 pVisualElement->DetachChild(target);
5623 else if (keyName == L"EXPAND_GROUP_ANIMATION")
5625 if (__pCapturedItemVisualElement)
5627 __pCapturedItemVisualElement->SetShowState(false);
5629 ExpandGroupAnimationFinished(completedNormally);
5631 if (__scrollToItemTag.startedAnimation)
5633 __scrollToItemTag.startedAnimation = false;
5634 ScrollToItem(__scrollToItemTag.groupIndex, __scrollToItemTag.itemIndex, __scrollToItemTag.itemAlignment, __scrollToItemTag.shiftingDistance);
5636 RestoreEditCopyPasteManager();
5639 else if (keyName == L"COLLAPSE_GROUP_ANIMATION")
5641 if (__pCapturedItemVisualElement)
5643 __pCapturedItemVisualElement->SetShowState(false);
5645 CollapseGroupAnimationFinished(completedNormally);
5647 if (__scrollToItemTag.startedAnimation)
5649 __scrollToItemTag.startedAnimation = false;
5650 ScrollToItem(__scrollToItemTag.groupIndex, __scrollToItemTag.itemIndex, __scrollToItemTag.itemAlignment, __scrollToItemTag.shiftingDistance);
5652 RestoreEditCopyPasteManager();
5656 _ScrollPanelPresenter::OnVisualElementAnimationFinished(animation, keyName, target, completedNormally);
5660 _TableViewPresenter::OnTickOccurred(const Tizen::Ui::Animations::VisualElementAnimation& animation, const Tizen::Base::String& keyName, Tizen::Ui::Animations::VisualElement& target, const Tizen::Ui::Variant& currentValue)
5662 _VisualElement* pVisualElement = __pTableView->GetVisualElement();
5664 if (&target != pVisualElement)
5669 if (keyName == L"REMOVE_ITEM_ANIMATION")
5671 Dimension value = currentValue.ToDimension();
5672 target.SetOpacity(value.width);
5674 FloatRectangle bounds = target.GetBounds();
5675 bounds.height = value.height;
5676 target.SetBounds(bounds);
5678 target.SetFlushNeeded();
5682 else if (keyName == L"EXPAND_GROUP_ANIMATION")
5684 float currentPosition = currentValue.ToFloat();
5685 SetLoadedItemsVisibleFromPosition(currentPosition, true);
5686 MoveLoadedItemsFromPosition(currentPosition);
5688 RestoreEditCopyPasteManager();
5691 else if (keyName == L"COLLAPSE_GROUP_ANIMATION")
5693 float currentPosition = currentValue.ToFloat();
5694 SetLoadedItemsVisibleFromPosition(currentPosition, false);
5695 MoveLoadedItemsFromPosition(currentPosition);
5697 RestoreEditCopyPasteManager();
5700 else if (keyName == L"SWEEP_ITEM_ANIMATION")
5702 float currentPosition = currentValue.ToFloat();
5703 float moveDestance = currentPosition - __sweptItemPosition.x;
5704 SweepItem(moveDestance);
5709 _ScrollPanelPresenter::OnTickOccurred(animation, keyName, target, currentValue);
5713 _TableViewPresenter::OnAccessibilityItemRefreshed(const _AccessibilityContainer& control, const _AccessibilityElement& element, _AccessibilityFocusDirection direction)
5715 TableViewItemTag itemPos = {-1, -1};
5717 if (direction == _ACCESSIBILITY_FOCUS_DIRECTION_NEXT)
5719 GetFirstItem(itemPos);
5720 if (GetAccessibilityElementFocusedState() == false && FindItem(itemPos) == null)
5722 ScrollToItem(itemPos.groupIndex, itemPos.itemIndex, TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_TOP);
5727 else if (direction == _ACCESSIBILITY_FOCUS_DIRECTION_PREVIOUS)
5729 GetLastItem(itemPos);
5731 if (IsGroupExpanded(itemPos.groupIndex) == false)
5733 itemPos.itemIndex = -1;
5736 if (GetAccessibilityElementFocusedState() == false && FindItem(itemPos) == null)
5738 ScrollToItem(itemPos.groupIndex, itemPos.itemIndex, TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_BOTTOM);
5748 _TableViewPresenter::OnOcurredOverflowItems(const int currentCashSize, const int overflowCount)
5750 return IsCachingItemsTotalHeightLessThanViewHeight();
5754 _TableViewPresenter::OnKeyPressed(const _Control& source, const _KeyInfo& keyInfo)
5756 if (!__pTableView->IsFocusModeStateEnabled())
5761 _KeyCode keyCode = keyInfo.GetKeyCode();
5762 _Control* pFocusedControl = null;
5763 _Window* pTop = source.GetRootWindow();
5766 pFocusedControl = pTop->GetCurrentFocusControl();
5769 _TableViewItem* pItem = null;
5770 TableViewItemTag itemPos = {-1, -1};
5775 StopExpandCollapseAnimation();
5776 if (pFocusedControl != null)
5778 pItem = dynamic_cast<_TableViewItem*>(pFocusedControl);
5781 _Control* pParentControl = pFocusedControl->GetParent();
5782 pItem = dynamic_cast<_TableViewItem*>(pParentControl);
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)
5792 SetTableViewFocused(false);
5796 while (GetPreviousItemPosition(itemPos, itemPos))
5798 if (__pTableView->GetTableViewStyle() == TABLE_VIEW_STYLE_SIMPLE)
5800 TableViewItemTag firstItemPos = {-1, -1};
5801 GetFirstItem(firstItemPos);
5802 if (itemPos.groupIndex == firstItemPos.groupIndex && itemPos.itemIndex == firstItemPos.itemIndex)
5804 SetTableViewFocused(false);
5809 if (IsGroupExpanded(itemPos.groupIndex) == false)
5811 itemPos.itemIndex = -1;
5814 pItem = LoadItem(itemPos.groupIndex, itemPos.itemIndex);
5817 SetTableViewFocused(false);
5821 if (!pItem->GetVisibleState() || !pItem->GetEnableState()
5822 || !pItem->IsFocusable())
5824 TableViewItemTag firstItemPos = {-1, -1};
5825 GetFirstItem(firstItemPos);
5826 if (itemPos.groupIndex == firstItemPos.groupIndex && itemPos.itemIndex == firstItemPos.itemIndex)
5828 SetTableViewFocused(false);
5835 if (pItem->GetBoundsF().y < GetScrollPosition())
5837 ScrollToItem(itemPos.groupIndex, itemPos.itemIndex, TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_TOP);
5839 else if (pItem->GetBoundsF().y + pItem->GetBoundsF().height > GetScrollPosition() + __pTableView->GetBoundsF().height)
5841 ScrollToItem(itemPos.groupIndex, itemPos.itemIndex, TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_BOTTOM);
5844 if (pItem->GetEnableState() && pItem->GetVisibleState()
5845 && pItem->IsFocusable())
5847 SetItemFocus(pItem, itemPos);
5854 SetTableViewFocused(false);
5861 StopExpandCollapseAnimation();
5862 if (pFocusedControl != null)
5864 pItem = dynamic_cast<_TableViewItem*>(pFocusedControl);
5867 _Control* pParentControl = pFocusedControl->GetParent();
5868 pItem = dynamic_cast<_TableViewItem*>(pParentControl);
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))
5878 SetTableViewFocused(false);
5882 while (GetNextItemPosition(itemPos, itemPos))
5884 if (__pTableView->GetTableViewStyle() == TABLE_VIEW_STYLE_SIMPLE && itemPos.itemIndex == -1)
5886 itemPos.itemIndex = 0;
5889 pItem = LoadItem(itemPos.groupIndex, itemPos.itemIndex);
5892 SetTableViewFocused(false);
5896 if (!pItem->GetVisibleState() || !pItem->GetEnableState()
5897 || !pItem->IsFocusable())
5899 TableViewItemTag lastItemPos = {-1, -1};
5900 GetLastItem(lastItemPos);
5902 if (itemPos.groupIndex == lastItemPos.groupIndex && (itemPos.itemIndex == lastItemPos.itemIndex
5903 || __pListModel->IsGroupExpanded(itemPos.groupIndex) == false))
5905 SetTableViewFocused(false);
5911 if (pItem->GetBoundsF().y + pItem->GetBoundsF().height > GetScrollPosition() + __pTableView->GetBoundsF().height)
5913 ScrollToItem(itemPos.groupIndex, itemPos.itemIndex, TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_BOTTOM);
5916 if (pItem->GetEnableState() && pItem->GetVisibleState()
5917 && pItem->IsFocusable())
5919 SetItemFocus(pItem, itemPos);
5926 SetTableViewFocused(false);
5933 SetTableViewFocused(false);
5944 _TableViewPresenter::OnKeyReleased(const _Control& source, const _KeyInfo& keyInfo)
5946 if (!__pTableView->IsFocusModeStateEnabled())
5951 _KeyCode keyCode = keyInfo.GetKeyCode();
5953 if (keyCode == _KEY_UP || keyCode == _KEY_DOWN)
5962 _TableViewPresenter::SetFocusItemOnPressedState(int groupIndex, int itemIndex)
5964 __focusItemTagOnTraversal.groupIndex = groupIndex;
5965 __focusItemTagOnTraversal.itemIndex = itemIndex;
5969 _TableViewPresenter::SetItemFocus(_TableViewItem* pItem, TableViewItemTag itemPos)
5971 pItem->SetFocused(true);
5972 __focusItemTag.groupIndex = itemPos.groupIndex;
5973 __focusItemTag.itemIndex = itemPos.itemIndex;
5974 __isAnnexFocused = false;
5979 _TableViewPresenter::OnDrawFocus(void)
5981 if (!__pTableView->IsFocusModeStateEnabled())
5986 if (__pTableView->GetRootWindow())
5988 if(!__pTableView->GetRootWindow()->IsActivated())
5994 _Control* pFocusedControl = null;
5995 _Window* pTop = __pTableView->GetRootWindow();
5998 pFocusedControl = pTop->GetCurrentFocusControl();
6001 _TableView* pTableView = null;
6002 _TableViewItem* pItem = null;
6003 TableViewItemTag itemPos = {-1, -1};
6005 if (__focusItemTagOnTraversal.groupIndex != -1)
6007 __focusItemTag.groupIndex = __focusItemTagOnTraversal.groupIndex;
6008 __focusItemTag.itemIndex = __focusItemTagOnTraversal.itemIndex;
6009 __isRestoreFocus = true;
6010 __isAnnexFocused = false;
6013 //Check for focus on orientation change
6014 if (__isFocusedDuringOrientationChange || __focusItemTagOnTraversal.groupIndex != -1)
6016 TableViewItemTag bottomDrawnItemIndex = {-1, -1};
6017 TableViewItemTag topDrawnItemIndex = {-1, -1};
6018 GetBottomDrawnItem(bottomDrawnItemIndex);
6019 GetTopDrawnItem(topDrawnItemIndex);
6021 if ((bottomDrawnItemIndex.groupIndex < __focusItemTag.groupIndex) ||
6022 (bottomDrawnItemIndex.groupIndex == __focusItemTag.groupIndex && bottomDrawnItemIndex.itemIndex <= __focusItemTag.itemIndex))
6024 ScrollToItem(__focusItemTag.groupIndex, __focusItemTag.itemIndex, TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_BOTTOM);
6028 if ((topDrawnItemIndex.groupIndex > __focusItemTag.groupIndex) ||
6029 (topDrawnItemIndex.groupIndex == __focusItemTag.groupIndex && topDrawnItemIndex.itemIndex >= __focusItemTag.itemIndex))
6031 ScrollToItem(__focusItemTag.groupIndex, __focusItemTag.itemIndex, TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_TOP);
6035 __isFocusedDuringOrientationChange = false;
6038 __focusItemTagOnTraversal.groupIndex = -1;
6039 __focusItemTagOnTraversal.itemIndex = -1;
6041 pItem = FindItem(__focusItemTag);
6043 if (__isRestoreFocus && pItem != null)
6045 if (pItem->GetEnableState() && pItem->GetVisibleState() && pItem->IsFocusable())
6047 if (__isAnnexFocused)
6049 pItem->DrawAnnexFocus();
6053 pItem->SetFocused(true);
6058 __isRestoreFocus = false;
6062 SysTryReturnVoidResult(NID_UI_CTRL, pFocusedControl != null, E_SYSTEM, "Failed to get Focussed control.");
6064 pTableView = dynamic_cast<_TableView*>(pFocusedControl);
6065 SysTryReturnVoidResult(NID_UI_CTRL, pTableView != null, E_SYSTEM, "Failed to get Focussed control.");
6067 if (_FocusManagerImpl::GetInstance()->IsForwardDirection() == true)
6069 GetFirstItem(itemPos);
6070 if (__pTableView->GetTableViewStyle() == TABLE_VIEW_STYLE_SIMPLE)
6072 itemPos.itemIndex = 0;
6075 ScrollToItem(itemPos.groupIndex, itemPos.itemIndex, TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_TOP);
6076 pItem = FindItem(itemPos);
6078 if (pItem != null && pItem->GetEnableState() && pItem->GetVisibleState() && pItem->IsFocusable())
6080 SetItemFocus(pItem, itemPos);
6084 while (GetNextItemPosition(itemPos, itemPos))
6086 TableViewItemTag topDrawnItemIndex = {-1, -1};
6087 GetTopDrawnItem(topDrawnItemIndex);
6088 if (topDrawnItemIndex.groupIndex <= itemPos.groupIndex && topDrawnItemIndex.itemIndex <= itemPos.itemIndex)
6090 TableViewItemTag bottomDrawnItemIndex = {-1, -1};
6091 GetBottomDrawnItem(bottomDrawnItemIndex);
6092 if (bottomDrawnItemIndex.groupIndex >= itemPos.groupIndex && bottomDrawnItemIndex.itemIndex >= itemPos.itemIndex)
6094 pItem = FindItem(itemPos);
6098 ScrollToItem(itemPos.groupIndex, itemPos.itemIndex, TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_TOP);
6099 pItem = FindItem(itemPos);
6104 ScrollToItem(itemPos.groupIndex, itemPos.itemIndex, TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_TOP);
6105 pItem = FindItem(itemPos);
6110 if (!pItem->GetVisibleState() || !pItem->GetEnableState()
6111 || !pItem->IsFocusable())
6113 TableViewItemTag lastItemPos = {-1, -1};
6114 GetLastItem(lastItemPos);
6116 if (itemPos.groupIndex == lastItemPos.groupIndex && itemPos.itemIndex == lastItemPos.itemIndex)
6125 SetItemFocus(pItem, itemPos);
6133 GetLastItem(itemPos);
6134 ScrollToItem(itemPos.groupIndex, itemPos.itemIndex, TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_BOTTOM);
6135 pItem = FindItem(itemPos);
6137 if (pItem != null && pItem->GetEnableState() && pItem->GetVisibleState() && pItem->IsFocusable())
6139 SetItemFocus(pItem, itemPos);
6143 while (GetPreviousItemPosition(itemPos, itemPos))
6145 TableViewItemTag bottomDrawnItemIndex = {-1, -1};
6146 GetBottomDrawnItem(bottomDrawnItemIndex);
6148 if (bottomDrawnItemIndex.groupIndex >= itemPos.groupIndex && bottomDrawnItemIndex.itemIndex >= itemPos.itemIndex)
6150 TableViewItemTag topDrawnItemIndex = {-1, -1};
6151 GetTopDrawnItem(topDrawnItemIndex);
6152 if (topDrawnItemIndex.groupIndex <= itemPos.groupIndex && topDrawnItemIndex.itemIndex <= itemPos.itemIndex)
6154 pItem = FindItem(itemPos);
6158 ScrollToItem(itemPos.groupIndex, itemPos.itemIndex, TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_BOTTOM);
6159 pItem = FindItem(itemPos);
6164 ScrollToItem(itemPos.groupIndex, itemPos.itemIndex, TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_BOTTOM);
6165 pItem = FindItem(itemPos);
6170 if (!pItem->GetVisibleState() || !pItem->GetEnableState()
6171 || !pItem->IsFocusable())
6173 TableViewItemTag firstItemPos = {-1, -1};
6174 GetFirstItem(firstItemPos);
6175 if (itemPos.groupIndex == firstItemPos.groupIndex && itemPos.itemIndex == firstItemPos.itemIndex)
6184 SetItemFocus(pItem, itemPos);
6193 _TableViewPresenter::OnTraversalControlFocusGained(void)
6195 if (__focusItemTagOnTraversal.groupIndex != -1)
6204 _TableViewPresenter::OnTraversalControlFocusLost(void)
6210 _TableViewPresenter::OnFocusModeStateChanged(void)
6212 __isFocusedDuringOrientationChange = false;
6213 __focusItemTag.groupIndex = -1;
6214 __focusItemTag.itemIndex = -1;
6215 __isRestoreFocus = false;
6216 __isAnnexFocused = false;
6218 _Window* pTop = __pTableView->GetRootWindow();
6222 _Control* pFocusedControl = pTop->GetCurrentFocusControl();
6224 if (pFocusedControl != null)
6226 pFocusedControl->RemoveFocusRing();
6232 _TableViewPresenter::OnVisibleStateChanged(void)
6235 if (__pTableView->IsFocused())
6237 __pTableView->RemoveFocusRing();
6242 _TableViewPresenter::OnAncestorEnableStateChanged(const _Control& control)
6245 if (__pTableView->IsFocused())
6247 __pTableView->RemoveFocusRing();
6252 _TableViewPresenter::OnAncestorVisibleStateChanged(const _Control& control)
6255 if (__pTableView->IsFocused())
6257 __pTableView->RemoveFocusRing();
6262 _TableViewPresenter::OnFocusableStateChanged(bool focusableState)
6264 if (!focusableState)
6267 if (__pTableView->IsFocused())
6269 __pTableView->RemoveFocusRing();
6275 _TableViewPresenter::GetAccessibilityElementFocusedState(void)
6277 _TableViewItem* pItem = null;
6278 TableViewItemTag itemPos = {-1, -1};
6279 TableViewItemTag lastItemPos = {-1, -1};
6281 __pListModel->GetFirstLoadedItemIndex(itemPos.groupIndex, itemPos.itemIndex);
6282 __pListModel->GetLastLoadedItemIndex(lastItemPos.groupIndex, lastItemPos.itemIndex);
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);
6289 _AccessibilityContainer* pContainer = pItem->GetAccessibilityContainer();
6290 _AccessibilityElement* pElement = null;
6292 if (pContainer != null)
6294 pElement = pContainer->GetCurrentFocusedElement();
6295 if (pElement != null)
6301 if ((itemPos.itemIndex == lastItemPos.itemIndex) && (itemPos.groupIndex == lastItemPos.groupIndex))
6306 } while (GetNextItemPosition(itemPos, itemPos) == true);
6312 _TableViewPresenter::FireItemTouchReleasedEventDuringPressing(int groupIndex, int itemIndex)
6314 TableViewItemTag fireItemPos;
6315 fireItemPos.groupIndex = groupIndex;
6316 fireItemPos.itemIndex = itemIndex;
6318 __itemTouchReleasedEventState = TABLE_VIEW_ITEM_TOUCH_RELEASED_EVENT_FIRE;
6319 _TableViewItem* pItem = FindItem(fireItemPos);
6322 pItem->FireItemTouchReleased();
6325 // for new item after UpdateTableView.
6326 pItem = FindItem(fireItemPos);
6329 if (__itemTouchReleasedEventState == TABLE_VIEW_ITEM_TOUCH_RELEASED_EVENT_UPDATE_TABLE_VIEW)
6331 __itemTouchReleasedEventState = TABLE_VIEW_ITEM_TOUCH_RELEASED_EVENT_NORMAL;
6335 pItem->SetSelectionState(true);
6336 pItem->FireItemTouchPressed();
6342 _TableViewPresenter::SetFocusDuringOrientationChange(void)
6344 if (__focusItemTag.groupIndex != -1)
6346 __isFocusedDuringOrientationChange = true;
6351 _TableViewSectionStringAlignment::operator== (const _TableViewSectionStringAlignment& rhs) const
6353 if (headerHorizontalAlignment == rhs.headerHorizontalAlignment && footerHorizontalAlignment == rhs.footerHorizontalAlignment)
6362 _TableViewSectionStringAlignment::operator!= (const _TableViewSectionStringAlignment& rhs) const
6364 if (headerHorizontalAlignment == rhs.headerHorizontalAlignment && footerHorizontalAlignment == rhs.footerHorizontalAlignment)
6373 _TableViewItemHeight::operator!= (const _TableViewItemHeight& rhs) const
6375 if (groupIndex == rhs.groupIndex && itemIndex == rhs.itemIndex && itemHeight == rhs.itemHeight && isFooterItem == rhs.isFooterItem)
6384 _TableViewItemHeight::operator== (const _TableViewItemHeight& rhs) const
6386 if (groupIndex == rhs.groupIndex && itemIndex == rhs.itemIndex && itemHeight == rhs.itemHeight && isFooterItem == rhs.isFooterItem)
6393 }}} // Tizen::Ui::Controls