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"
40 using namespace Tizen::Ui::Animations;
41 using namespace Tizen::Graphics;
42 using namespace Tizen::Base;
43 using namespace Tizen::Base::Runtime;
45 namespace Tizen { namespace Ui { namespace Controls
47 _TableViewPresenter::_TableViewPresenter()
50 , __pProviderAdaptor(null)
52 , __bottomMargin(0.0f)
54 , __modelInitialized(false)
55 , __firstDrawnFlag(true)
56 , __statusChangedFlag(true)
58 , __pItemDrawingProperty(null)
59 , __pBaseVisualElement(null)
60 , __sweepOccured(false)
61 , __sweptItemPosition()
62 , __reservedScrollItemAlignment(TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_TOP)
63 , __firstTouchMoved(false)
64 , __pReorderScrollTimer(null)
66 , __itemTotalHeight(0.0f)
67 , __pCapturedItemVisualElement(null)
68 , __pFastScrollTimer(null)
69 , __isFastScrollTimerEnabled(false)
70 , __scrollHeightOnFlickStarted(0)
71 , __scrollPositionOnFlickStarted(0)
72 , __isAnimationCallbackBlocked(false)
73 , __lockLoadItemWithScroll(false)
74 , __itemTouchReleasedEventState(TABLE_VIEW_ITEM_TOUCH_RELEASED_EVENT_NORMAL)
77 __sweptItemTag.itemIndex = -1;
78 __sweptItemTag.groupIndex = -1;
80 __reservedScrollItemIndex.itemIndex = -1;
81 __reservedScrollItemIndex.groupIndex = -1;
83 __expandableItemTag.groupIndex = -1;
84 __expandableItemTag.itemIndex = -1;
87 _TableViewPresenter::~_TableViewPresenter()
93 _TableViewPresenter::GetView() const
99 _TableViewPresenter::GetModel(void) const
105 _TableViewPresenter::Initialize(_TableView* pTableView)
107 _ScrollPanelPresenter::Initialize(*pTableView);
109 __pTableView = pTableView;
110 __pBaseVisualElement = __pTableView->GetVisualElement();
111 __pBaseVisualElement->SetClipChildrenEnabled(true);
112 __pBaseVisualElement->SetSurfaceOpaque(false);
114 result r = __itemHeightList.Construct();
115 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, false, E_OUT_OF_MEMORY, ("[E_OUT_OF_MEMORY] The memory is insufficient."));
117 r = __sectionAlignmentList.Construct();
118 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, false, E_OUT_OF_MEMORY, ("[E_OUT_OF_MEMORY] The memory is insufficient."));
121 __pListModel = new (std::nothrow) _ListViewModel();
122 SysTryReturn(NID_UI_CTRL, __pListModel != null, false, E_OUT_OF_MEMORY, ("[E_OUT_OF_MEMORY] The memory is insufficient."));
123 __pListModel->SetListViewModelDelegate(this);
125 __pItemDrawingProperty = new (std::nothrow) _ItemDrawingProperty();
126 SysTryReturn(NID_UI_CTRL, __pItemDrawingProperty != null, false, E_OUT_OF_MEMORY, ("[E_OUT_OF_MEMORY] The memory is insufficient."));
129 __pFastScrollTimer = new (std::nothrow) Timer();
130 SysTryCatch(NID_UI_CTRL, __pFastScrollTimer != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
132 r = __pFastScrollTimer->Construct(*this);
133 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
138 if (__isFastScrollTimerEnabled)
140 __pFastScrollTimer->Cancel();
143 delete __pFastScrollTimer;
144 __pFastScrollTimer = null;
150 _TableViewPresenter::Construct(_TableView* pTableView)
152 result r = E_SUCCESS;
155 if (!Initialize(pTableView))
168 _TableViewPresenter::Dispose(void)
170 DeleteItemHeightList();
171 DeleteSectionAlignmentList();
172 DetachContextItem(__sweptItemTag);
177 delete __pProviderAdaptor;
178 __pProviderAdaptor = null;
180 delete __pItemDrawingProperty;
181 __pItemDrawingProperty = null;
183 delete __pReorderScrollTimer;
184 __pReorderScrollTimer = null;
186 if (__isFastScrollTimerEnabled)
188 __pFastScrollTimer->Cancel();
191 delete __pFastScrollTimer;
192 __pFastScrollTimer = null;
194 if (__pCapturedItemVisualElement)
196 GetView()->GetVisualElement()->DetachChild(*__pCapturedItemVisualElement);
197 __pCapturedItemVisualElement->Destroy();
199 __pCapturedItemVisualElement = null;
203 _TableViewPresenter::SetItemProvider(const _TableViewItemProvider* pProvider)
205 result r = E_SUCCESS;
207 _TableViewItemProviderAdaptor* pProviderAdaptor = null;
208 pProviderAdaptor = static_cast <_TableViewItemProviderAdaptor*>(__pListModel->GetItemProviderAdaptor());
210 if (pProviderAdaptor == null)
212 pProviderAdaptor = new (std::nothrow) _TableViewItemProviderAdaptor();
213 SysTryReturn(NID_UI_CTRL, pProviderAdaptor != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, ("[E_OUT_OF_MEMORY] The memory is insufficient."));
215 SetTableViewItemProviderAdaptor(pProviderAdaptor);
218 _TableViewItemProvider* pNewProvider = null;
220 if (pProvider != null)
222 pNewProvider = const_cast <_TableViewItemProvider*>(pProvider);
226 __pListModel->RemoveAllItem(false);
229 pProviderAdaptor->SetItemProvider(pNewProvider);
230 pProviderAdaptor->SetListWidth(__pTableView->GetBoundsF().width - (GetLeftMargin() * 2));
231 pProviderAdaptor->SetTableViewStyle(__pTableView->GetTableViewStyle());
237 _TableViewPresenter::GetItemFromPosition(const Tizen::Graphics::FloatPoint& position, TableViewItemTag& itemPos) const
239 _TableViewItem* pItem = null;
240 TableViewItemTag lastItemPos = {-1, -1};
242 __pListModel->GetFirstLoadedItemIndex(itemPos.groupIndex, itemPos.itemIndex);
243 __pListModel->GetLastLoadedItemIndex(lastItemPos.groupIndex, lastItemPos.itemIndex);
247 pItem = static_cast <_TableViewItem*>(__pListModel->LoadItem(itemPos.groupIndex, itemPos.itemIndex));
248 SysTryCatch(NID_UI_CTRL, pItem != null, , E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The index is out of range.");
250 FloatRectangle itemBounds = pItem->GetBoundsF();
251 if (itemBounds.Contains(position))
256 if ((itemPos.itemIndex == lastItemPos.itemIndex) && (itemPos.groupIndex == lastItemPos.groupIndex))
261 } while (GetNextItemPosition(itemPos, itemPos));
264 itemPos.itemIndex = -1;
265 itemPos.groupIndex = -1;
267 return E_OUT_OF_RANGE;
271 _TableViewPresenter::GetTopDrawnItemIndex(int& groupIndex, int& itemIndex) const
273 result r = E_SUCCESS;
275 TableViewItemTag itemPos;
276 r = GetTopDrawnItem(itemPos);
278 groupIndex = itemPos.groupIndex;
279 itemIndex = itemPos.itemIndex;
285 _TableViewPresenter::SetTopDrawnItemIndex(int groupIndex, int itemIndex)
289 return E_INVALID_ARG;
292 if ((groupIndex < 0) || (groupIndex >= GetGroupCount()) || (itemIndex < -1) || (itemIndex >= GetItemCountAt(groupIndex)))
294 return E_OUT_OF_RANGE;
297 ScrollToItem(groupIndex, itemIndex, TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_TOP);
303 _TableViewPresenter::GetBottomDrawnItemIndex(int& groupIndex, int& itemIndex) const
305 result r = E_SUCCESS;
307 TableViewItemTag itemPos;
308 r = GetBottomDrawnItem(itemPos);
310 groupIndex = itemPos.groupIndex;
311 itemIndex = itemPos.itemIndex;
317 _TableViewPresenter::SetBottomDrawnItemIndex(int groupIndex, int itemIndex)
321 return E_INVALID_ARG;
324 if ((groupIndex < 0) || (groupIndex >= GetGroupCount()) || (itemIndex < -1) || (itemIndex >= GetItemCountAt(groupIndex)))
326 return E_OUT_OF_RANGE;
329 ScrollToItem(groupIndex, itemIndex, TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_BOTTOM);
335 _TableViewPresenter::GetGroupCount(void) const
337 return __pListModel->GetAllGroupCount();
342 _TableViewPresenter::GetItemCountAt(int groupIndex) const
344 return __pListModel->GetItemCountInGroup(groupIndex);
348 _TableViewPresenter::HasSectionHeader(int groupIndex) const
350 if (__pProviderAdaptor == null || __pTableView->GetTableViewStyle() != TABLE_VIEW_STYLE_SECTION)
355 return __pProviderAdaptor->HasSectionHeader(groupIndex);
359 _TableViewPresenter::HasSectionFooter(int groupIndex) const
361 if (__pProviderAdaptor == null || __pTableView->GetTableViewStyle() != TABLE_VIEW_STYLE_SECTION)
366 return __pProviderAdaptor->HasSectionFooter(groupIndex);
370 _TableViewPresenter::GetItemCount(void) const
372 return __pListModel->GetAllItemCount();
376 _TableViewPresenter::RefreshTableView(int groupIndex, int itemIndex, TableViewRefreshType type, bool animation)
378 _TableViewItemProviderAdaptor* pProviderAdaptor = __pProviderAdaptor;
380 SysTryReturn(NID_UI_CTRL, pProviderAdaptor != null, E_INVALID_STATE, E_INVALID_STATE,
381 ("[E_INVALID_STATE] This instance isn't constructed."));
383 if ((groupIndex < 0) || (groupIndex > GetGroupCount()) || (itemIndex < -1) || (itemIndex > GetItemCountAt(groupIndex)))
385 SysLogException(NID_UI_CTRL, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The index is out of range.");
386 return E_OUT_OF_RANGE;
389 if (groupIndex == GetGroupCount() && itemIndex != -1 && type != TABLE_VIEW_REFRESH_TYPE_ITEM_ADD)
391 SysLogException(NID_UI_CTRL, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The index is out of range.");
392 return E_OUT_OF_RANGE;
395 TableViewItemTag topDrawnItemPos = {-1, -1};
396 TableViewItemTag refreshItemPos = {groupIndex, itemIndex};
397 float prevScrollAreaHeight = GetScrollAreaBounds().height;
399 GetTopDrawnItem(topDrawnItemPos);
405 case TABLE_VIEW_REFRESH_TYPE_ITEM_ADD:
408 bool emptyState = IsEmpty();
410 int itemCount = pProviderAdaptor->GetItemCount(groupIndex);
411 if (__pListModel->InsertGroup(groupIndex, itemCount, false) != E_SUCCESS)
413 SysLogException(NID_UI_CTRL, E_SYSTEM, "[E_SYSTEM] Unable to add Group item.");
419 GetFirstItem(topDrawnItemPos);
421 else if (groupIndex <= topDrawnItemPos.groupIndex)
423 topDrawnItemPos.groupIndex++;
428 bool emptyState = IsEmpty();
430 if (__pListModel->InsertItemToGroup(null, groupIndex, itemIndex) != E_SUCCESS)
432 SysLogException(NID_UI_CTRL, E_SYSTEM, "[E_SYSTEM] Unable to add item.");
438 GetFirstItem(topDrawnItemPos);
442 RefreshItemHeightList(groupIndex, itemIndex, TABLE_VIEW_REFRESH_TYPE_ITEM_ADD);
443 RefreshSectionAlignmentList(groupIndex, TABLE_VIEW_REFRESH_TYPE_ITEM_ADD);
445 if (__pListModel->GetAllItemCount() == 1)
447 SetStatusChanged(true);
452 case TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE:
455 if (groupIndex == GetGroupCount())
457 SysLogException(NID_UI_CTRL, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The index is out of range.");
458 return E_OUT_OF_RANGE;
461 RefreshItemHeightList(groupIndex, itemIndex, TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE);
462 RefreshSectionAlignmentList(groupIndex, TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE);
464 if (__pListModel->RemoveGroup(groupIndex) != E_SUCCESS)
466 SysLogException(NID_UI_CTRL, E_SYSTEM, "[E_SYSTEM] Unable to remove group.");
470 if (groupIndex < topDrawnItemPos.groupIndex)
472 topDrawnItemPos.groupIndex--;
475 if ((groupIndex == topDrawnItemPos.groupIndex) && (GetItemCountAt(groupIndex) < topDrawnItemPos.itemIndex))
477 topDrawnItemPos.itemIndex = -1;
482 if (itemIndex == GetItemCountAt(groupIndex))
484 SysLogException(NID_UI_CTRL, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The index is out of range.");
485 return E_OUT_OF_RANGE;
488 if (__pListModel->RemoveItemAt(groupIndex, itemIndex) != E_SUCCESS)
490 SysLogException(NID_UI_CTRL, E_SYSTEM, "[E_SYSTEM] Unable to remove item.");
494 if ((groupIndex == topDrawnItemPos.groupIndex) && (itemIndex < topDrawnItemPos.itemIndex))
496 GetPreviousItemPosition(topDrawnItemPos, topDrawnItemPos);
499 RefreshItemHeightList(groupIndex, itemIndex, TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE);
502 if (GetModel()->IsValidItem(topDrawnItemPos.groupIndex, topDrawnItemPos.itemIndex) == false)
504 GetPreviousItemPosition(topDrawnItemPos, topDrawnItemPos);
507 if (__pListModel->GetAllItemCount() == 0)
509 SetStatusChanged(true);
514 case TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY:
516 TableViewItemTag itemTag = {groupIndex, itemIndex};
517 _TableViewItem* pTableViewItem = FindItem(itemTag);
519 if (pTableViewItem == null)
524 if (pProviderAdaptor->UpdateItem(pTableViewItem, itemTag.groupIndex, itemTag.itemIndex))
526 CheckItemHeightAndRefreshLayout(itemTag, true);
528 if (__sweptItemTag.groupIndex != itemTag.groupIndex || __sweptItemTag.itemIndex != itemTag.itemIndex)
533 pTableViewItem->SetItemChanged(true);
534 pTableViewItem->Invalidate();
535 pTableViewItem->AdjustContextItemBounds();
543 SysLogException(NID_UI_CTRL, E_SYSTEM, "[E_SYSTEM] Unable to refresh list.");
548 AdjustClientAreaBounds(true);
550 if ((topDrawnItemPos.groupIndex > refreshItemPos.groupIndex)
551 ||((topDrawnItemPos.groupIndex == refreshItemPos.groupIndex)&&(topDrawnItemPos.itemIndex > refreshItemPos.itemIndex)))
553 RefreshItemLayout(topDrawnItemPos, refreshItemPos, type, false);
555 float newScrollPosition = GetScrollPosition() - (prevScrollAreaHeight - GetScrollAreaBounds().height);
556 SetScrollPosition(newScrollPosition, false);
560 RefreshItemLayout(topDrawnItemPos, refreshItemPos, type, animation);
567 _TableViewPresenter::RefreshAllItems(void)
569 result r = E_SUCCESS;
570 TableViewItemTag itemTag = {-1, -1};
571 TableViewItemTag lastLoadedItemTag = {-1, -1};
573 __pListModel->GetLastLoadedItemIndex(lastLoadedItemTag.groupIndex, lastLoadedItemTag.itemIndex);
574 __pListModel->GetFirstLoadedItemIndex(itemTag.groupIndex, itemTag.itemIndex);
578 _TableViewItem* pItem = FindItem(itemTag);
585 r = RefreshTableView(itemTag.groupIndex, itemTag.itemIndex, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY, false);
586 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
588 if ((itemTag.itemIndex == lastLoadedItemTag.itemIndex) && (itemTag.groupIndex == lastLoadedItemTag.groupIndex))
592 } while (GetNextItemPosition(itemTag, itemTag));
598 _TableViewPresenter::UpdateTableView(void)
600 _VisualElement* pVisualElement = __pTableView->GetVisualElement();
602 if (pVisualElement != null)
604 __pTableView->GetVisualElement()->RemoveAllAnimations();
608 if (__modelInitialized == false)
610 SetItemDrawingProperty();
612 if(PreloadItem() == false)
619 TableViewItemTag topDrawnTag = {-1, -1};
620 float shiftingDistance = 0;
624 GetTopDrawnItem(topDrawnTag);
626 if (__pListModel->IsValidItem(topDrawnTag.groupIndex, topDrawnTag.itemIndex))
628 _TableViewItem* pItem = FindItem(topDrawnTag);
632 shiftingDistance = GetScrollPosition() - pItem->GetBoundsF().y;
636 __pListModel->RemoveAllItem(false, true);
638 PreloadItem(topDrawnTag.groupIndex, topDrawnTag.itemIndex, shiftingDistance);
640 __statusChangedFlag = true;
642 if (__itemTouchReleasedEventState == TABLE_VIEW_ITEM_TOUCH_RELEASED_EVENT_FIRE)
644 __itemTouchReleasedEventState = TABLE_VIEW_ITEM_TOUCH_RELEASED_EVENT_UPDATE_TABLE_VIEW;
652 _TableViewPresenter::AdjustLayoutItems(float scrollPosition)
654 TableViewItemTag lastLoadedItemPos = {-1, -1};
655 TableViewItemTag firstLoadedItemPos = {-1, -1};
656 TableViewItemTag currentItemPos = {-1, -1};
657 _TableViewItem* pItem = null;
659 __pListModel->GetFirstLoadedItemIndex(firstLoadedItemPos.groupIndex, firstLoadedItemPos.itemIndex);
660 __pListModel->GetLastLoadedItemIndex(lastLoadedItemPos.groupIndex, lastLoadedItemPos.itemIndex);
662 pItem = FindItem(firstLoadedItemPos);
666 float positionY = pItem->GetPositionF().y;
668 currentItemPos = firstLoadedItemPos;
670 while (!_FloatCompareLE(positionY, scrollPosition) && GetPreviousItemPosition(currentItemPos, currentItemPos))
672 pItem = LoadItem(currentItemPos.groupIndex, currentItemPos.itemIndex);
679 positionY = pItem->GetPositionF().y;
683 pItem = FindItem(lastLoadedItemPos);
687 float positionY = pItem->GetPositionF().y;
688 float itemHeight = pItem->GetBoundsF().height;
689 float limitScreenArea = scrollPosition + __pTableView->GetBoundsF().height;
690 currentItemPos = lastLoadedItemPos;
692 while ((positionY + itemHeight < limitScreenArea) && GetNextItemPosition(currentItemPos, currentItemPos))
694 pItem = LoadItem(currentItemPos.groupIndex, currentItemPos.itemIndex);
701 positionY = pItem->GetPositionF().y;
702 itemHeight = pItem->GetBoundsF().height;
708 _TableViewPresenter::ResetItemLayout(TableViewItemTag& topDrawnItemTag, float shiftingDistance)
710 if (__pListModel->IsValidItem(topDrawnItemTag.groupIndex, topDrawnItemTag.itemIndex) == false)
717 _TableViewItem* pItem = LoadItem(topDrawnItemTag.groupIndex, topDrawnItemTag.itemIndex);
724 TableViewItemTag currentItem = topDrawnItemTag;
725 TableViewItemTag itemPos = topDrawnItemTag;
726 float screenAreaHeight = __pTableView->GetBoundsF().height + shiftingDistance;
727 float loadedItemTotalHeight = 0.0f;
728 FloatRectangle itemBounds = pItem->GetBoundsF();
730 itemBounds.y = CalculateItemPositionY(itemPos.groupIndex, itemPos.itemIndex);
731 pItem->SetBounds(itemBounds);
732 CheckItemHeightAndRefreshLayout(itemPos, true);
734 loadedItemTotalHeight += itemBounds.height;
736 while (loadedItemTotalHeight < screenAreaHeight && GetNextItemPosition(currentItem, itemPos))
738 pItem = LoadItem(itemPos.groupIndex, itemPos.itemIndex);
745 currentItem = itemPos;
746 loadedItemTotalHeight += pItem->GetBoundsF().height;
749 if (loadedItemTotalHeight < screenAreaHeight)
751 __pListModel->GetFirstLoadedItemIndex(itemPos.groupIndex, itemPos.itemIndex);
752 currentItem = itemPos;
754 while (loadedItemTotalHeight < screenAreaHeight && GetPreviousItemPosition(currentItem, itemPos))
756 pItem = LoadItem(itemPos.groupIndex, itemPos.itemIndex);
763 currentItem = itemPos;
764 loadedItemTotalHeight += pItem->GetBoundsF().height;
770 _TableViewPresenter::IsCachingItemsTotalHeightLessThanViewHeight(void)
772 int currentCachingsize = GetMaxItemCachingSize();
773 int loadedItemCount = 0;
774 float itemTotalHeight = 0.0f;
775 float viewHeight = __pTableView->GetBoundsF().height;
777 TableViewItemTag lastLoadedItemPos = {-1, -1};
778 TableViewItemTag firstLoadedItemPos = {-1, -1};
780 __pListModel->GetFirstLoadedItemIndex(firstLoadedItemPos.groupIndex, firstLoadedItemPos.itemIndex);
781 __pListModel->GetLastLoadedItemIndex(lastLoadedItemPos.groupIndex, lastLoadedItemPos.itemIndex);
785 _TableViewItem* pItem = FindItem(firstLoadedItemPos);
789 itemTotalHeight = itemTotalHeight + pItem->GetSizeF().height;
793 if ((firstLoadedItemPos.itemIndex == lastLoadedItemPos.itemIndex) && (firstLoadedItemPos.groupIndex == lastLoadedItemPos.groupIndex))
797 } while (GetNextItemPosition(firstLoadedItemPos, firstLoadedItemPos));
799 if (loadedItemCount < currentCachingsize || viewHeight < itemTotalHeight)
808 _TableViewPresenter::GetFirstLoadedItemIndex(int& groupIndex, int& itemIndex) const
810 __pListModel->GetFirstLoadedItemIndex(groupIndex, itemIndex);
814 _TableViewPresenter::GetLastLoadedItemIndex(int& groupIndex, int& itemIndex) const
816 __pListModel->GetLastLoadedItemIndex(groupIndex, itemIndex);
820 _TableViewPresenter::RefreshItemLayout(int groupIndex, int itemIndex)
822 TableViewItemTag itemTag = {groupIndex, itemIndex};
826 RefreshItemLayout(itemTag, itemTag, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY, false);
830 _TableViewPresenter::RefreshItemLayout(TableViewItemTag& topDrawnItemTag, TableViewItemTag& refreshItemTag, TableViewRefreshType type, bool animation)
832 if (!__pListModel->IsValidItem(topDrawnItemTag.groupIndex, topDrawnItemTag.itemIndex))
837 if (refreshItemTag.itemIndex == -1)
842 _TableViewItem* pItem = null;
844 TableViewItemTag itemPos = {-1, -1};
845 TableViewItemTag currentItem = {-1, -1};
847 int loadItemCount = 0;
848 int maxLoadItemCount = GetMaxItemCachingSize();
849 FloatRectangle itemBounds(0.0f, 0.0f, 0.0f, 0.0f);
851 StopAllItemAnimation();
853 __pListModel->GetFirstLoadedItemIndex(itemPos.groupIndex, itemPos.itemIndex);
855 if (itemPos.groupIndex == -1 && itemPos.itemIndex == -1)
857 itemPos = topDrawnItemTag;
860 currentItem = itemPos;
862 float itemPositionY = CalculateItemPositionY(itemPos.groupIndex, itemPos.itemIndex);
866 pItem = LoadItem(itemPos.groupIndex, itemPos.itemIndex);
873 if (pItem->HasParent())
875 pItem->SetDrawingProperty(__pItemDrawingProperty);
876 SetItemType(pItem, itemPos);
879 itemBounds = pItem->GetBoundsF();
880 itemBounds.y = itemPositionY;
884 if (type == TABLE_VIEW_REFRESH_TYPE_ITEM_ADD)
886 if (itemPos.groupIndex == refreshItemTag.groupIndex && itemPos.itemIndex == refreshItemTag.itemIndex)
888 pItem->SetBounds(itemBounds);
889 pItem->FadeInOutItem(false, ADD_ITEM_ANIMATION_DURATION, REFRESH_ITEM_ANIMATION_DELAY);
890 pItem->ZoomInOutItem(false, ADD_ITEM_ANIMATION_DURATION, REFRESH_ITEM_ANIMATION_DELAY);
894 if (!pItem->MoveItem(FloatPoint(itemBounds.x, itemBounds.y), ADD_ITEM_ANIMATION_DURATION, 0))
896 pItem->SetBounds(itemBounds);
902 if (!pItem->MoveItem(FloatPoint(itemBounds.x, itemBounds.y), REMOVE_ITEM_MOVE_ANIMATION_DURATION, REFRESH_ITEM_ANIMATION_DELAY))
904 pItem->SetBounds(itemBounds);
910 pItem->SetBounds(itemBounds);
913 currentItem = itemPos;
914 itemPositionY = itemBounds.y + itemBounds.height;
918 } while (loadItemCount < maxLoadItemCount && GetNextItemPosition(currentItem, itemPos));
920 if (loadItemCount < maxLoadItemCount)
922 __pListModel->GetFirstLoadedItemIndex(itemPos.groupIndex, itemPos.itemIndex);
923 currentItem = itemPos;
925 while (loadItemCount < maxLoadItemCount && GetPreviousItemPosition(currentItem, itemPos))
927 pItem = LoadItem(itemPos.groupIndex, itemPos.itemIndex);
934 currentItem = itemPos;
940 if (refreshItemTag.itemIndex == -1)
942 ScrollToItem(topDrawnItemTag.groupIndex, topDrawnItemTag.itemIndex, TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_TOP);
947 _TableViewPresenter::RefreshItemBounds(_TableViewItem* pItem, TableViewItemTag& itemPos)
949 FloatRectangle itemBounds;
956 itemBounds = pItem->GetBoundsF();
958 itemBounds.y = CalculateItemPositionY(itemPos.groupIndex, itemPos.itemIndex);
960 if (itemPos.itemIndex != -1)
962 float itemMargin = GetLeftMargin();
963 itemBounds.x = itemMargin;
964 itemBounds.width = __pItemDrawingProperty->width - itemBounds.x - itemMargin;
969 itemBounds.width = __pItemDrawingProperty->width;
972 pItem->SetBounds(itemBounds);
976 _TableViewPresenter::GetItemIndexFromPosition(const FloatPoint& position, int& groupIndex, int& itemIndex) const
978 result r = E_SUCCESS;
979 TableViewItemTag itemPos;
981 FloatPoint targetPosition = position;
982 float scrollPosition = GetScrollPosition();
983 targetPosition.y += scrollPosition;
985 r = GetItemFromPosition(targetPosition, itemPos);
994 groupIndex = itemPos.groupIndex;
995 itemIndex = itemPos.itemIndex;
1002 _TableViewPresenter::PreloadItem(void)
1004 if (GetModel() == null || __pProviderAdaptor == null)
1009 __modelInitialized = true;
1011 if (__pListModel->GetAllGroupCount() == 0 && (__pProviderAdaptor != null))
1014 int groupCount = __pProviderAdaptor->GetGroupCount();
1016 for (int i = 0; i < groupCount; i++)
1018 itemCount = __pProviderAdaptor->GetItemCount(i);
1019 __pListModel->AddGroup(itemCount, false);
1023 __pListModel->RestoreItemStatus();
1025 CreateItemHeightList(TABLEVIEW_DEFAULT_ITEM_HEIGHT_VALUE, TABLEVIEW_DEFAULT_ITEM_HEIGHT_VALUE);
1026 CreateSectionAlignmentList();
1028 int cachingSize = 0;
1030 if (GetItemCount() > TABLEVIEW_MAX_ITEM_COUNT)
1032 cachingSize = TABLEVIEW_MAX_ITEM_COUNT;
1034 else if (__pListModel->GetMaxCachingSize() < TABLEVIEW_MAX_ITEM_COUNT)
1036 cachingSize = __pListModel->GetMaxCachingSize();
1040 cachingSize = GetItemCount();
1043 TableViewItemTag itemPos = {-1, -1};
1044 GetFirstItem(itemPos);
1046 _TableViewItem* pItem = null;
1047 for (int i = 0; i < cachingSize; i++)
1049 pItem = LoadItem(itemPos.groupIndex, itemPos.itemIndex);
1056 if (GetNextItemPosition(itemPos, itemPos) == false)
1062 if (IsCachingItemsTotalHeightLessThanViewHeight())
1064 AdjustLayoutItems(0.0f);
1067 PresetItemHeightList();
1068 AdjustClientAreaBounds(true);
1070 if (__pTableView->GetScrollStyle() == TABLE_VIEW_SCROLL_BAR_STYLE_FAST_SCROLL)
1072 _FastScroll* pFastScroll = __pTableView->GetFastScrollBar();
1073 if (pFastScroll != null)
1075 pFastScroll->UpdateIndex();
1076 pFastScroll->SetScrollVisibility(IsScrollable());
1084 _TableViewPresenter::PreloadItem(int topDrawnGroupIndex, int topDrawnItemIndex, int shiftingDistance)
1086 if (GetModel() == null || __pProviderAdaptor == null)
1091 __modelInitialized = true;
1093 if (__pListModel->GetAllGroupCount() == 0 && (__pProviderAdaptor != null))
1096 int groupCount = __pProviderAdaptor->GetGroupCount();
1098 for (int i = 0; i < groupCount; i++)
1100 itemCount = __pProviderAdaptor->GetItemCount(i);
1101 __pListModel->AddGroup(itemCount, false);
1105 float defaultGroupHeight = __pProviderAdaptor->GetDefaultGroupItemHeight();
1106 float defaultItemHeight = __pProviderAdaptor->GetDefaultItemHeight();
1108 if (_FloatCompareLE(defaultGroupHeight, 0.0f))
1110 defaultGroupHeight = TABLEVIEW_DEFAULT_ITEM_HEIGHT_VALUE;
1113 if (_FloatCompareLE(defaultItemHeight, 0.0f))
1115 defaultItemHeight = TABLEVIEW_DEFAULT_ITEM_HEIGHT_VALUE;
1118 __pListModel->RestoreItemStatus();
1120 DeleteItemHeightList();
1121 CreateItemHeightList(defaultGroupHeight, defaultItemHeight);
1123 DeleteSectionAlignmentList();
1124 CreateSectionAlignmentList();
1126 if (!__pListModel->IsValidItem(topDrawnGroupIndex, topDrawnItemIndex))
1128 TableViewItemTag firstItemTag = {-1, -1};
1130 GetFirstItem(firstItemTag);
1132 topDrawnGroupIndex = firstItemTag.groupIndex;
1133 topDrawnItemIndex = firstItemTag.itemIndex;
1135 shiftingDistance = 0;
1138 ScrollToItem(topDrawnGroupIndex, topDrawnItemIndex, TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_TOP, shiftingDistance);
1140 if (IsCachingItemsTotalHeightLessThanViewHeight())
1142 AdjustLayoutItems(GetScrollPosition());
1145 AdjustClientAreaBounds(true);
1147 if (__pTableView->GetScrollStyle() == TABLE_VIEW_SCROLL_BAR_STYLE_FAST_SCROLL)
1149 _FastScroll* pFastScroll = __pTableView->GetFastScrollBar();
1150 if (pFastScroll != null)
1152 pFastScroll->UpdateIndex();
1153 pFastScroll->SetScrollVisibility(IsScrollable());
1161 _TableViewPresenter::IsItemChecked(int groupIndex, int itemIndex) const
1163 if ((groupIndex < 0) || (groupIndex >= GetGroupCount()) || (itemIndex < -1) || (itemIndex >= GetItemCountAt(groupIndex)))
1168 return __pListModel->IsItemChecked(groupIndex, itemIndex);
1172 _TableViewPresenter::SetItemChecked(int groupIndex, int itemIndex, bool checked)
1174 if ((groupIndex < 0) || (groupIndex >= GetGroupCount()) || (itemIndex < -1) || (itemIndex >= GetItemCountAt(groupIndex)))
1176 return E_OUT_OF_RANGE;
1179 if (__modelInitialized == false)
1181 return E_INVALID_STATE;
1184 TableViewItemTag itemPos = {groupIndex, itemIndex};
1186 bool enabled = __pListModel->IsItemEnabled(itemPos.groupIndex, itemPos.itemIndex);
1187 SysTryReturn(NID_UI_CTRL, (enabled == true), E_INVALID_OPERATION, E_INVALID_OPERATION,
1188 "[E_INVALID_OPERATION] The item is disabled.");
1190 if (__pListModel->IsItemChecked(itemPos.groupIndex, itemPos.itemIndex) == checked)
1195 TableViewItemTag itemTag = {groupIndex, itemIndex};
1196 _TableViewItem *pItem = FindItem(itemTag);
1199 pItem->SetCheckedAnimationEnabled(checked);
1202 result r = __pListModel->SetItemChecked(itemPos.groupIndex, itemPos.itemIndex, checked);
1208 _TableViewPresenter::IsItemEnabled(int groupIndex, int itemIndex) const
1210 if ((groupIndex < 0) || (groupIndex >= GetGroupCount()) || (itemIndex < -1) || (itemIndex >= GetItemCountAt(groupIndex)))
1215 return __pListModel->IsItemEnabled(groupIndex, itemIndex);
1219 _TableViewPresenter::SetItemEnabled(int groupIndex, int itemIndex, bool enabled)
1221 if ((groupIndex < 0) || (groupIndex >= GetGroupCount()) || (itemIndex < -1) || (itemIndex >= GetItemCountAt(groupIndex)))
1223 return E_OUT_OF_RANGE;
1226 TableViewItemTag itemPos = {groupIndex, itemIndex};
1228 if (__pListModel->IsItemEnabled(itemPos.groupIndex, itemPos.itemIndex) == enabled)
1233 result r = __pListModel->SetItemEnabled(itemPos.groupIndex, itemPos.itemIndex, enabled);
1239 _TableViewPresenter::SetStatusChanged(bool changed)
1241 __statusChangedFlag = changed;
1243 if (__statusChangedFlag == true)
1245 SetItemDrawingProperty();
1247 if ((__pItemDrawingProperty != null) && (__pItemDrawingProperty->propertyChanged == true))
1249 __pListModel->SetAllLoadedItemStateChanged(true);
1257 _TableViewPresenter::IsStatusChanged(void) const
1259 return __statusChangedFlag;
1263 _TableViewPresenter::GetTopMargin(void) const
1269 _TableViewPresenter::SetTopMargin(float topMargin)
1271 __topMargin = topMargin;
1277 _TableViewPresenter::GetBottomMargin(void) const
1279 return __bottomMargin;
1283 _TableViewPresenter::SetBottomMargin(float bottomMargin)
1285 __bottomMargin = bottomMargin;
1291 _TableViewPresenter::GetLeftMargin(void) const
1293 return __leftMargin;
1297 _TableViewPresenter::SetLeftMargin(float leftMargin)
1299 __leftMargin = leftMargin;
1305 _TableViewPresenter::SetItemType(_TableViewItem* pItem, TableViewItemTag itemPosition)
1307 TableViewStyle style = __pTableView->GetTableViewStyle();
1309 if (itemPosition.itemIndex == -1)
1311 if (style == TABLE_VIEW_STYLE_SECTION)
1313 pItem->SetItemType(TABLE_VIEW_ITEM_TYPE_HEADER);
1317 pItem->SetItemType(TABLE_VIEW_ITEM_TYPE_TITLE);
1322 int itemCount = GetItemCountAt(itemPosition.groupIndex);
1324 if (itemPosition.itemIndex == 0)
1326 if (HasSectionFooter(itemPosition.groupIndex))
1330 pItem->SetItemType(TABLE_VIEW_ITEM_TYPE_FOOTER);
1332 else if (itemCount == 2)
1334 pItem->SetItemType(TABLE_VIEW_ITEM_TYPE_ONE);
1338 pItem->SetItemType(TABLE_VIEW_ITEM_TYPE_TOP);
1345 pItem->SetItemType(TABLE_VIEW_ITEM_TYPE_ONE);
1349 pItem->SetItemType(TABLE_VIEW_ITEM_TYPE_TOP);
1355 int lastItemIndex = itemCount - 1;
1357 if (HasSectionFooter(itemPosition.groupIndex))
1359 if (itemPosition.itemIndex == lastItemIndex)
1361 pItem->SetItemType(TABLE_VIEW_ITEM_TYPE_FOOTER);
1363 else if (itemPosition.itemIndex == lastItemIndex - 1)
1365 pItem->SetItemType(TABLE_VIEW_ITEM_TYPE_BOTTOM);
1369 pItem->SetItemType(TABLE_VIEW_ITEM_TYPE_MIDDLE);
1374 if (itemPosition.itemIndex == lastItemIndex)
1376 pItem->SetItemType(TABLE_VIEW_ITEM_TYPE_BOTTOM);
1380 pItem->SetItemType(TABLE_VIEW_ITEM_TYPE_MIDDLE);
1388 _TableViewPresenter::SetItemLayout(_TableViewItem* pItem, TableViewItemTag& itemPos)
1390 _TableViewItem* pSeriesItem = null;
1391 TableViewItemTag seriesItemPos = {-1, -1};
1392 FloatRectangle seriesItemBounds;
1393 FloatRectangle itemBounds;
1394 bool validBounds = false;
1395 bool downScroll = true;
1397 if (itemPos.itemIndex == -1 && __pTableView->GetTableViewStyle() != TABLE_VIEW_STYLE_SECTION)
1400 itemBounds.width = __pItemDrawingProperty->width;
1404 float itemMargin = GetLeftMargin();
1405 itemBounds.x = itemMargin;
1406 itemBounds.width = __pItemDrawingProperty->width - itemBounds.x - itemMargin;
1409 FloatDimension itemDimension = Tizen::Graphics::CoordinateSystem::AlignToDevice(FloatDimension(pItem->GetSizeF().width, pItem->GetSizeF().height));
1410 itemBounds.height = itemDimension.height;
1412 if (itemPos.groupIndex == 0 && itemPos.itemIndex == -1)
1414 itemBounds.y = GetTopMargin();
1419 if (GetPreviousItemPosition(itemPos, seriesItemPos))
1421 if (__pListModel->IsLoadedItem(seriesItemPos.groupIndex, seriesItemPos.itemIndex))
1423 pSeriesItem = static_cast<_TableViewItem*>(__pListModel->LoadItem(seriesItemPos.groupIndex, seriesItemPos.itemIndex));
1424 if ((pSeriesItem != null) && pSeriesItem->HasParent())
1426 if (__pTableView->IsReorderModeEnabled() && (__reorderInfo.groupIndex == seriesItemPos.groupIndex && __reorderInfo.itemIndex == seriesItemPos.itemIndex))
1428 seriesItemBounds = __reorderInfo.itemBounds;
1432 seriesItemBounds = pSeriesItem->GetBoundsF();
1435 itemBounds.y = seriesItemBounds.y + seriesItemBounds.height;
1442 if ((!validBounds) && GetNextItemPosition(itemPos, seriesItemPos))
1444 if (__pListModel->IsLoadedItem(seriesItemPos.groupIndex, seriesItemPos.itemIndex))
1446 pSeriesItem = static_cast<_TableViewItem*>(__pListModel->LoadItem(seriesItemPos.groupIndex, seriesItemPos.itemIndex));
1447 if ((pSeriesItem != null) && pSeriesItem->HasParent())
1449 if (__pTableView->IsReorderModeEnabled() && (__reorderInfo.groupIndex == seriesItemPos.groupIndex && __reorderInfo.itemIndex == seriesItemPos.itemIndex))
1451 seriesItemBounds = __reorderInfo.itemBounds;
1455 seriesItemBounds = pSeriesItem->GetBoundsF();
1458 itemBounds.y = seriesItemBounds.y - itemBounds.height;
1469 pItem->SetBounds(itemBounds);
1471 CheckItemHeightAndRefreshLayout(itemPos, downScroll);
1475 itemBounds.y = CalculateItemPositionY(itemPos.groupIndex, itemPos.itemIndex);
1476 pItem->SetBounds(itemBounds);
1478 CheckItemHeightAndRefreshLayout(itemPos, true);
1481 if (__pTableView->IsReorderModeEnabled() && __reorderInfo.itemIndex != -1)
1483 TableViewItemTag reorderSelectedItemTag = {__reorderInfo.groupIndex, __reorderInfo.itemIndex};
1484 _TableViewItem* pReorderSelectedItem = FindItem(reorderSelectedItemTag);
1486 if (pReorderSelectedItem != null)
1488 pReorderSelectedItem->GetVisualElement()->SetZOrder(null, true);
1492 if (pItem->GetItemLayoutEnabled())
1494 pItem->PartialUpdateLayout();
1499 _TableViewPresenter::LoadItem(int groupIndex, int itemIndex)
1501 _TableViewItem* pItem = static_cast<_TableViewItem*>(__pListModel->LoadItem(groupIndex, itemIndex));
1503 if ((pItem != null) && !pItem->HasParent())
1505 __lockLoadItemWithScroll = true;
1507 __pTableView->AttachChild(*pItem);
1509 pItem->SetDrawingProperty(__pItemDrawingProperty);
1511 TableViewItemTag itemPosition = {groupIndex, itemIndex};
1512 SetItemType(pItem, itemPosition);
1513 SetItemLayout(pItem, itemPosition);
1514 pItem->SetReorderMode(__pTableView->IsReorderModeEnabled());
1515 pItem->AdjustChildControlMargin();
1517 __lockLoadItemWithScroll = false;
1524 _TableViewPresenter::FindItem(TableViewItemTag& itemTag)
1526 if (__pListModel->IsLoadedItem(itemTag.groupIndex, itemTag.itemIndex))
1528 return static_cast<_TableViewItem*>(__pListModel->LoadItem(itemTag.groupIndex, itemTag.itemIndex));
1534 _TableViewPresenter::UnloadItem(int groupIndex, int itemIndex)
1536 __pListModel->UnloadItem(groupIndex, itemIndex);
1540 _TableViewPresenter::UnloadItem(TableViewItemTag& itemTag)
1542 __pListModel->UnloadItem(itemTag.groupIndex, itemTag.itemIndex);
1548 _TableViewPresenter::DetachItem(TableViewItemTag& itemTag)
1550 _TableViewItem *pItem = FindItem(itemTag);
1552 if (pItem != null && pItem->HasParent())
1554 pItem->GetParent()->DetachChild(*pItem);
1559 _TableViewPresenter::DetachContextItem(TableViewItemTag& itemTag)
1561 _TableViewItem *pItem = FindItem(itemTag);
1567 _TableViewItem* contextItem = pItem->GetContextItem();
1568 if (contextItem != null && contextItem->HasParent())
1570 contextItem->GetParent()->DetachChild(*pItem);
1575 _TableViewPresenter::DetachAllItem(bool removeItem)
1577 TableViewItemTag itemPos = {-1, -1};
1578 TableViewItemTag lastItemPos = {-1, -1};
1580 __pListModel->GetFirstLoadedItemIndex(itemPos.groupIndex, itemPos.itemIndex);
1581 __pListModel->GetLastLoadedItemIndex(lastItemPos.groupIndex, lastItemPos.itemIndex);
1583 if (itemPos.groupIndex == -1 && itemPos.itemIndex == -1)
1590 DetachItem(itemPos);
1594 UnloadItem(itemPos);
1597 if (itemPos.itemIndex == lastItemPos.itemIndex && itemPos.groupIndex == lastItemPos.groupIndex)
1601 } while (GetNextItemPosition(itemPos, itemPos));
1605 _TableViewPresenter::SetItemDrawingProperty(void)
1607 if (__pItemDrawingProperty != null)
1609 __pItemDrawingProperty->propertyChanged = false;
1611 if (__pItemDrawingProperty->itemDividerEnabled != __pTableView->IsItemDividerEnabled())
1613 __pItemDrawingProperty->itemDividerEnabled = __pTableView->IsItemDividerEnabled();
1614 __pItemDrawingProperty->propertyChanged = true;
1617 if (__pItemDrawingProperty->dividerColor != __pTableView->GetItemDividerColor())
1619 __pItemDrawingProperty->dividerColor = __pTableView->GetItemDividerColor();
1620 __pItemDrawingProperty->propertyChanged = true;
1623 if (__pItemDrawingProperty->sectionStyleEnabled != (__pTableView->GetTableViewStyle() == TABLE_VIEW_STYLE_SECTION))
1625 __pItemDrawingProperty->sectionStyleEnabled = (__pTableView->GetTableViewStyle() == TABLE_VIEW_STYLE_SECTION);
1626 __pItemDrawingProperty->propertyChanged = true;
1629 if (__pItemDrawingProperty->sectionStyleBgColor != __pTableView->GetSectionColor())
1631 __pItemDrawingProperty->sectionStyleBgColor = __pTableView->GetSectionColor();
1632 __pItemDrawingProperty->propertyChanged = true;
1635 if (__pTableView->GetTableViewStyle() != TABLE_VIEW_STYLE_SIMPLE)
1637 if (__pItemDrawingProperty->groupedLookEnabled != __pTableView->IsGroupedLookEnabled())
1639 __pItemDrawingProperty->groupedLookEnabled = __pTableView->IsGroupedLookEnabled();
1640 __pItemDrawingProperty->propertyChanged = true;
1644 if (__pItemDrawingProperty->reorderMode != __pTableView->IsReorderModeEnabled())
1646 __pItemDrawingProperty->reorderMode = __pTableView->IsReorderModeEnabled();
1647 __pItemDrawingProperty->propertyChanged = true;
1650 if (!_FloatCompare(__pItemDrawingProperty->leftMargin, __leftMargin))
1652 __pItemDrawingProperty->leftMargin = __leftMargin;
1653 __pItemDrawingProperty->propertyChanged = true;
1656 __pItemDrawingProperty->scrollMargin = 0;
1658 if (!_FloatCompare(__pItemDrawingProperty->width, __pTableView->GetBoundsF().width))
1660 __pItemDrawingProperty->width = __pTableView->GetBoundsF().width;
1661 __pItemDrawingProperty->propertyChanged = true;
1667 _TableViewPresenter::OnBoundsChanged(void)
1669 float listWidth = __pTableView->GetBoundsF().width - (GetLeftMargin() * 2);
1671 if (__pProviderAdaptor != null && __modelInitialized)
1673 if (__pTableView->IsReorderModeEnabled() && __reorderInfo.itemIndex != -1)
1675 ResetReorderItem(__reorderInfo.groupIndex, __reorderInfo.itemIndex);
1678 if (!_FloatCompare(listWidth, __pProviderAdaptor->GetListWidth()))
1680 __pProviderAdaptor->SetListWidth(listWidth);
1682 SetItemDrawingProperty();
1684 AdjustLoadedItemWidth();
1686 __pTableView->UpdateLayout();
1689 SetClientAreaHeight(__itemTotalHeight);
1692 AdjustLayoutItems(GetScrollPosition());
1696 if (__pProviderAdaptor != null)
1698 __pProviderAdaptor->SetListWidth(listWidth);
1701 SetClientAreaHeight(__pTableView->GetBoundsF().height);
1702 _ScrollPanelPresenter::OnBoundsChanged();
1707 _TableViewPresenter::Draw(void)
1709 result r = _ScrollPanelPresenter::Draw();
1710 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1712 if (__modelInitialized == false)
1714 SetItemDrawingProperty();
1716 if(PreloadItem() == false)
1721 if (__reservedScrollItemIndex.groupIndex != -1 && __reservedScrollItemIndex.itemIndex != -1)
1723 ScrollToItem(__reservedScrollItemIndex.groupIndex, __reservedScrollItemIndex.itemIndex, __reservedScrollItemAlignment);
1725 __reservedScrollItemIndex.groupIndex = -1;
1726 __reservedScrollItemIndex.itemIndex = -1;
1732 __firstDrawnFlag = false;
1735 if (IsEmpty() == true)
1737 return DrawEmptyTableView();
1743 _UiTouchEventDelivery
1744 _TableViewPresenter::OnPreviewTouchPressed(const _Control& source, const _TouchInfo& touchInfo)
1746 _UiTouchEventDelivery response = _ScrollPanelPresenter::OnPreviewTouchPressed(source, touchInfo);
1748 _TableViewItem* pItem = GetTableViewItemFromControl(source);
1754 TableViewItemTag itemPos = {-1, -1};
1756 pItem->GetItemIndex(itemPos.groupIndex, itemPos.itemIndex);
1758 if (itemPos.groupIndex == -1 && itemPos.itemIndex == -1)
1763 if (__pTableView->IsReorderModeEnabled())
1765 __firstTouchMoved = true;
1767 if (SelectReorderItem(itemPos.groupIndex, itemPos.itemIndex, false))
1769 __reorderInfo.touchPressedPositionY = touchInfo.GetCurrentPosition().y;
1776 _UiTouchEventDelivery
1777 _TableViewPresenter::OnPreviewTouchMoved(const _Control& source, const _TouchInfo& touchInfo)
1779 if (__pTableView->IsReorderModeEnabled())
1781 if (__reorderInfo.itemIndex != -1)
1783 if (!DragSelectedItem(touchInfo.GetCurrentPosition().y - __reorderInfo.touchPressedPositionY, true))
1785 __firstTouchMoved = false;
1787 ResetReorderItem(__reorderInfo.groupIndex, __reorderInfo.itemIndex);
1790 return _UI_TOUCH_EVENT_DELIVERY_NO;
1794 return _ScrollPanelPresenter::OnPreviewTouchMoved(source, touchInfo);
1797 _UiTouchEventDelivery
1798 _TableViewPresenter::OnPreviewTouchReleased(const _Control& source, const _TouchInfo& touchInfo)
1800 if (__pTableView->IsReorderModeEnabled() && __reorderInfo.itemIndex != -1)
1802 ResetReorderItem(__reorderInfo.groupIndex, __reorderInfo.itemIndex);
1804 if (__reorderInfo.blockedTouchReleaseState)
1806 __reorderInfo.blockedTouchReleaseState = false;
1808 return _UI_TOUCH_EVENT_DELIVERY_NO;
1812 return _ScrollPanelPresenter::OnPreviewTouchReleased(source, touchInfo);
1815 _UiTouchEventDelivery
1816 _TableViewPresenter::OnPreviewTouchCanceled(const _Control& source, const _TouchInfo& touchInfo)
1818 return _ScrollPanelPresenter::OnPreviewTouchCanceled(source, touchInfo);
1822 _TableViewPresenter::OnTouchPressed(const _Control& source, const _TouchInfo& touchInfo)
1824 __firstTouchMoved = true;
1826 _TableViewItem* pItem = GetTableViewItemFromControl(source);
1830 return _ScrollPanelPresenter::OnTouchPressed(source, touchInfo);
1833 TableViewItemTag itemPos = {-1, -1};
1834 pItem->GetItemIndex(itemPos.groupIndex, itemPos.itemIndex);
1836 if (!(pItem->IsContextItem()
1837 || pItem->IsItemEnabled() == false
1838 || pItem->GetItemType() == TABLE_VIEW_ITEM_TYPE_TITLE
1839 || pItem->GetItemType() == TABLE_VIEW_ITEM_TYPE_HEADER
1840 || pItem->GetItemType() == TABLE_VIEW_ITEM_TYPE_FOOTER)
1841 && ((itemPos.groupIndex != __sweptItemTag.groupIndex)
1842 || (itemPos.itemIndex != __sweptItemTag.itemIndex)))
1847 __sweepOccured = false;
1849 _VisualElement* pVisualElement = __pTableView->GetVisualElement();
1850 String animationName(L"EXPAND_GROUP_ANIMATION");
1851 VisualElementValueAnimation* pExpandGroupAnimation = dynamic_cast<VisualElementValueAnimation*>(pVisualElement->GetAnimationN(animationName));
1852 if (pExpandGroupAnimation != null)
1854 pVisualElement->RemoveAnimation(animationName);
1855 delete pExpandGroupAnimation;
1858 animationName = L"COLLAPSE_GROUP_ANIMATION";
1859 VisualElementValueAnimation* pCollapseGroupAnimation = dynamic_cast<VisualElementValueAnimation*>(pVisualElement->GetAnimationN(animationName));
1860 if (pCollapseGroupAnimation != null)
1862 pVisualElement->RemoveAnimation(animationName);
1863 delete pCollapseGroupAnimation;
1866 return _ScrollPanelPresenter::OnTouchPressed(source, touchInfo);
1870 _TableViewPresenter::OnTouchMoved(const _Control& source, const _TouchInfo& touchInfo)
1872 if (__pTableView->IsReorderModeEnabled())
1874 if (__reorderInfo.blockedScroll)
1879 return _ScrollPanelPresenter::OnTouchMoved(source, touchInfo);
1882 _TableViewItem* pItem = GetTableViewItemFromControl(source);
1884 || pItem->IsItemEnabled() == false
1885 || pItem->GetItemType() == TABLE_VIEW_ITEM_TYPE_TITLE
1886 || pItem->GetItemType() == TABLE_VIEW_ITEM_TYPE_HEADER
1887 || pItem->GetItemType() == TABLE_VIEW_ITEM_TYPE_FOOTER
1888 || pItem->IsAnnexOnOffSliding())
1890 return _ScrollPanelPresenter::OnTouchMoved(source, touchInfo);;
1893 if (__firstTouchMoved)
1895 FloatPoint prevTouchPosition = GetPreviousTouchPosition();
1896 FloatPoint currTouchPosition = GetCurrentTouchPosition();
1897 float moveDistanceX = currTouchPosition.x - prevTouchPosition.x;
1898 float moveDistanceY = currTouchPosition.y - prevTouchPosition.y;
1900 if ((pItem->GetContextItem() != null && abs(moveDistanceX) > abs(moveDistanceY * 2)) || pItem->IsContextItem())
1902 if (!pItem->IsContextItem())
1904 pItem->GetItemIndex(__sweptItemTag.groupIndex, __sweptItemTag.itemIndex);
1905 __sweptItemPosition = pItem->GetPositionF();
1907 pItem->AdjustContextItemBounds();
1910 __sweepOccured = true;
1915 return _ScrollPanelPresenter::OnTouchMoved(source, touchInfo);
1919 __firstTouchMoved = false;
1923 FloatPoint prevTouchPosition = GetPreviousTouchPosition();
1924 FloatPoint currTouchPosition = GetCurrentTouchPosition();
1926 SweepItem(currTouchPosition.x - prevTouchPosition.x);
1933 _TableViewPresenter::OnTouchReleased(const _Control& source, const _TouchInfo& touchInfo)
1935 _TableViewItem* pItem = GetTableViewItemFromControl(source);
1938 || pItem->GetItemType() == TABLE_VIEW_ITEM_TYPE_TITLE
1939 || pItem->GetItemType() == TABLE_VIEW_ITEM_TYPE_HEADER
1940 || pItem->GetItemType() == TABLE_VIEW_ITEM_TYPE_FOOTER)
1942 return _ScrollPanelPresenter::OnTouchReleased(source, touchInfo);
1947 if (pItem->IsContextItem())
1949 pItem = static_cast<_TableViewItem*>(__pListModel->LoadItem(__sweptItemTag.groupIndex, __sweptItemTag.itemIndex));
1951 _TableViewItem* pContextItem = pItem->GetContextItem();
1954 if (pContextItem == null && __pTableView->IsSweepEnabled())
1956 FloatPoint prevPos = _ScrollPanelPresenter::GetPreviousTouchPosition();
1958 if (prevPos.x > touchInfo.GetCurrentPosition().x)
1960 pItem->FireItemSweepEvent(TABLE_VIEW_SWEEP_DIRECTION_LEFT);
1962 else if (prevPos.x < touchInfo.GetCurrentPosition().x)
1964 pItem->FireItemSweepEvent(TABLE_VIEW_SWEEP_DIRECTION_RIGHT);
1969 else if (pContextItem != null)
1971 AdjustSweptItemPosition(true);
1975 return _ScrollPanelPresenter::OnTouchReleased(source, touchInfo);
1979 _TableViewPresenter::OnTouchCanceled(const _Control& source, const _TouchInfo& touchInfo)
1981 if (__pTableView->IsReorderModeEnabled() && __reorderInfo.itemIndex != -1)
1983 ResetReorderItem(__reorderInfo.groupIndex, __reorderInfo.itemIndex);
1987 return _ScrollPanelPresenter::OnTouchCanceled(source, touchInfo);
1991 _TableViewPresenter::OnFlickGestureDetected(_TouchFlickGestureDetector& gesture)
1993 if (__pTableView->IsReorderModeEnabled() && __reorderInfo.itemIndex != -1)
1998 _FlickDirection flickDirection = gesture.GetDirection();
2000 if (flickDirection != _FLICK_DIRECTION_RIGHT && flickDirection != _FLICK_DIRECTION_LEFT)
2002 return _ScrollPanelPresenter::OnFlickGestureDetected(gesture);
2005 _Control* gestureControl = gesture.GetControl();
2007 if (gestureControl == null)
2009 return _ScrollPanelPresenter::OnFlickGestureDetected(gesture);
2012 _TableViewItem* pItem = GetTableViewItemFromControl(*gestureControl);
2016 return _ScrollPanelPresenter::OnFlickGestureDetected(gesture);
2019 if (flickDirection == _FLICK_DIRECTION_RIGHT)
2022 if (pItem->GetContextItem() == null && __pTableView->IsSweepEnabled())
2024 pItem->FireItemSweepEvent(TABLE_VIEW_SWEEP_DIRECTION_RIGHT);
2028 if (pItem->GetContextItem() != null)
2030 AdjustSweptItemPosition();
2034 else if (flickDirection == _FLICK_DIRECTION_LEFT)
2037 if (pItem->GetContextItem() == null && __pTableView->IsSweepEnabled())
2039 pItem->FireItemSweepEvent(TABLE_VIEW_SWEEP_DIRECTION_LEFT);
2043 if (pItem->GetContextItem() != null)
2045 AdjustSweptItemPosition();
2054 _TableViewPresenter::OnFlickGestureCanceled(_TouchFlickGestureDetector& gesture)
2056 return _ScrollPanelPresenter::OnFlickGestureCanceled(gesture);
2060 _TableViewPresenter::OnPreviewFlickGestureDetected(_TouchFlickGestureDetector& gesture)
2062 if (__pTableView->IsReorderModeEnabled() && __reorderInfo.itemIndex != -1)
2067 _FlickDirection flickDirection = gesture.GetDirection();
2068 if (flickDirection != _FLICK_DIRECTION_RIGHT && flickDirection != _FLICK_DIRECTION_LEFT)
2070 return _ScrollPanelPresenter::OnFlickGestureDetected(gesture);
2077 _TableViewPresenter::OnTimerExpired(Tizen::Base::Runtime::Timer& timer)
2079 _ScrollPanelPresenter::OnTimerExpired(timer);
2081 if (&timer == __pReorderScrollTimer)
2083 float distance = 0.0f;
2085 if (__reorderInfo.isScrollDirectionUp)
2087 distance = -REORDER_SCROLL_ANIMATION_DISTANCE;
2091 distance = REORDER_SCROLL_ANIMATION_DISTANCE;
2094 DragSelectedItem(distance, false);
2096 distance = ScrollTo(distance + GetScrollPosition());
2098 StartReorderScrollTimer();
2100 else if (&timer == __pFastScrollTimer)
2102 __isFastScrollTimerEnabled = false;
2104 _FastScroll* pFastScroll = __pTableView->GetFastScrollBar();
2106 if (pFastScroll != null && !_ScrollPanelPresenter::IsScrollAnimationRunning())
2108 pFastScroll->SetScrollVisibility(false);
2114 _TableViewPresenter::StartFastScrollTimer(void)
2116 result r = E_SUCCESS;
2118 SysTryReturn(NID_UI_CTRL, __pFastScrollTimer != null, E_INVALID_STATE, E_INVALID_STATE, "[E_INVALID_STATE] Timer is not created.");
2120 r = __pFastScrollTimer->Start(FAST_SCROLL_FADE_OUT_DURATION);
2121 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
2123 __isFastScrollTimerEnabled = true;
2129 _TableViewPresenter::StopFastScrollTimer(void)
2131 result r = E_SUCCESS;
2133 SysTryReturnVoidResult(NID_UI_CTRL, __pFastScrollTimer != null, E_INVALID_STATE, "[E_INVALID_STATE] Timer is invalid.");
2135 r = __pFastScrollTimer->Cancel();
2136 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
2138 __isFastScrollTimerEnabled = false;
2144 _TableViewPresenter::IsEmpty(void) const
2146 if (__pTableView->GetTableViewStyle() == TABLE_VIEW_STYLE_SIMPLE)
2148 if (GetItemCountAt(0) <= 0)
2155 if (GetGroupCount() <= 0 )
2165 _TableViewPresenter::DrawEmptyTableView(void)
2171 _TableViewPresenter::GetFirstItem(TableViewItemTag& firstItem) const
2175 firstItem.groupIndex = -1;
2176 firstItem.itemIndex = -1;
2180 firstItem.groupIndex = 0;
2181 firstItem.itemIndex = -1;
2188 _TableViewPresenter::GetLastItem(TableViewItemTag& lastItem) const
2192 lastItem.groupIndex = -1;
2193 lastItem.itemIndex = -1;
2197 lastItem.groupIndex = GetGroupCount() - 1;
2198 lastItem.itemIndex = GetItemCountAt(lastItem.groupIndex) - 1;
2205 _TableViewPresenter::GetTopDrawnItem(TableViewItemTag& itemPos) const
2207 _TableViewItem* pItem = null;
2208 TableViewItemTag lastItemPos = {-1, -1};
2209 float scrollPosition = 0.0f;
2211 scrollPosition = GetScrollPosition();
2213 __pListModel->GetFirstLoadedItemIndex(itemPos.groupIndex, itemPos.itemIndex);
2214 __pListModel->GetLastLoadedItemIndex(lastItemPos.groupIndex, lastItemPos.itemIndex);
2218 pItem = static_cast <_TableViewItem*>(__pListModel->LoadItem(itemPos.groupIndex, itemPos.itemIndex));
2224 FloatRectangle itemBounds = pItem->GetBoundsF();
2226 if (scrollPosition < (itemBounds.y + itemBounds.height))
2231 if ((itemPos.itemIndex == lastItemPos.itemIndex) && (itemPos.groupIndex == lastItemPos.groupIndex))
2236 } while (GetNextItemPosition(itemPos, itemPos) == true);
2239 itemPos.itemIndex = -1;
2240 itemPos.groupIndex = -1;
2242 return E_OUT_OF_RANGE;
2246 _TableViewPresenter::GetBottomDrawnItem(TableViewItemTag& itemPos) const
2248 _TableViewItem* pItem = null;
2249 TableViewItemTag lastItemPos = {-1, -1};
2253 itemPos.itemIndex = -1;
2254 itemPos.groupIndex = -1;
2256 return E_INVALID_STATE;
2259 float scrollPosition = GetScrollPosition() + __pTableView->GetBoundsF().height;
2261 __pListModel->GetFirstLoadedItemIndex(itemPos.groupIndex, itemPos.itemIndex);
2262 __pListModel->GetLastLoadedItemIndex(lastItemPos.groupIndex, lastItemPos.itemIndex);
2266 static bool onProcessingByProvider = true;
2267 pItem = static_cast <_TableViewItem*>(__pListModel->LoadItem(itemPos.groupIndex, itemPos.itemIndex));
2268 onProcessingByProvider = false;
2274 FloatRectangle itemBounds = pItem->GetBoundsF();
2276 if (itemBounds.y <= scrollPosition && scrollPosition <= (itemBounds.y + itemBounds.height))
2281 if ((itemPos.itemIndex == lastItemPos.itemIndex) && (itemPos.groupIndex == lastItemPos.groupIndex))
2286 } while (GetNextItemPosition(itemPos, itemPos) == true);
2292 _TableViewPresenter::GetPreviousItemPosition(const TableViewItemTag& currentItemPos, TableViewItemTag& prevItem) const
2299 // check validation of group index
2300 if ((currentItemPos.groupIndex < 0) || (currentItemPos.groupIndex >= __pListModel->GetAllGroupCount()))
2305 // if the current item is the first item
2306 if (currentItemPos.groupIndex == 0 && currentItemPos.itemIndex == -1)
2311 if (currentItemPos.itemIndex == -1)
2313 if (__pListModel->IsGroupExpanded(currentItemPos.groupIndex - 1) == false)
2315 prevItem.groupIndex = currentItemPos.groupIndex - 1;
2316 prevItem.itemIndex = -1;
2322 if (__pListModel->IsGroupExpanded(currentItemPos.groupIndex) == false)
2324 if (currentItemPos.groupIndex == 0 && currentItemPos.itemIndex == -1)
2329 prevItem.groupIndex = currentItemPos.groupIndex - 1;
2330 prevItem.itemIndex = __pListModel->GetItemCountInGroup(prevItem.groupIndex) - 1;
2335 if (currentItemPos.itemIndex == -1) // group title item
2337 prevItem.groupIndex = currentItemPos.groupIndex - 1;
2338 prevItem.itemIndex = __pListModel->GetItemCountInGroup(prevItem.groupIndex) - 1;
2342 prevItem.groupIndex = currentItemPos.groupIndex;
2343 prevItem.itemIndex = currentItemPos.itemIndex - 1;
2350 _TableViewPresenter::GetNextItemPosition(const TableViewItemTag& currentItem, TableViewItemTag& nextItem) const
2357 int lastGroup = __pListModel->GetAllGroupCount() - 1;
2358 int lastItemInCurrentGroup = __pListModel->GetItemCountInGroup(currentItem.groupIndex) - 1;
2359 int lastItem = __pListModel->GetItemCountInGroup(lastGroup) - 1;
2361 // check validation of group index
2362 if ((currentItem.groupIndex < 0) || (currentItem.groupIndex > lastGroup))
2367 // if the current item is the last item.
2368 if ((currentItem.groupIndex == lastGroup) && (currentItem.itemIndex == lastItem))
2373 if (__pListModel->IsGroupExpanded(currentItem.groupIndex) == false)
2375 if (currentItem.groupIndex == lastGroup)
2380 nextItem.groupIndex = currentItem.groupIndex + 1;
2381 nextItem.itemIndex = -1;
2386 if (lastItemInCurrentGroup == currentItem.itemIndex)
2388 nextItem.groupIndex = currentItem.groupIndex + 1;
2389 nextItem.itemIndex = -1;
2393 nextItem.groupIndex = currentItem.groupIndex;
2394 nextItem.itemIndex = currentItem.itemIndex + 1;
2401 _TableViewPresenter::GetHeightOfAllItems(void) const
2403 int groupCount = GetGroupCount();
2404 float totalHeight = 0;
2406 for (int i = 0; i < groupCount; i++)
2408 TableViewItemTag itemTag = {i, -1};
2410 totalHeight += GetItemHeight(itemTag);
2412 if (!IsGroupExpanded(i))
2417 int itemCount = GetItemCountAt(i);
2419 for (int j = 0; j < itemCount; j++)
2421 itemTag.itemIndex = j;
2423 totalHeight += GetItemHeight(itemTag);
2431 _TableViewPresenter::SetTableViewItemProviderAdaptor(_TableViewItemProviderAdaptor* pProviderAdaptor)
2433 __pListModel->RegisterItemProviderAdaptor(pProviderAdaptor);
2435 __pProviderAdaptor = pProviderAdaptor;
2437 if (__pProviderAdaptor != null)
2439 __pProviderAdaptor->SetTableViewPresenter(this);
2443 _TableViewItemProviderAdaptor*
2444 _TableViewPresenter::GetTableViewItemProviderAdaptor(void) const
2446 return __pProviderAdaptor;
2450 _TableViewPresenter::ExpandGroup(int groupIndex, bool withAnimation)
2452 if ((groupIndex < 0) || (groupIndex >= GetGroupCount()))
2454 return E_OUT_OF_RANGE;
2457 if (__modelInitialized == false)
2459 return E_INVALID_STATE;
2462 if (IsGroupExpanded(groupIndex) == true)
2467 TableViewItemTag topTag;
2468 GetTopDrawnItem(topTag);
2470 TableViewItemTag bottomTag;
2471 GetBottomDrawnItem(bottomTag);
2473 float screenPosition = GetScrollPosition();
2475 __pListModel->SetGroupExpandState(groupIndex, true);
2479 float groupTotalHeight = 0.0f;
2480 int itemCount = GetItemCountAt(groupIndex);
2481 _TableViewItem* pItem = null;
2482 for (int i = 0; i < itemCount; i++)
2484 pItem = static_cast<_TableViewItem*>(__pListModel->GetItemFromTemporaryBuffer(groupIndex, i));
2485 groupTotalHeight += pItem->GetItemHeight();
2488 AdjustClientAreaBounds(false, groupTotalHeight);
2490 if (groupIndex < topTag.groupIndex || groupIndex > bottomTag.groupIndex)
2492 _TableViewItem* pItem = FindItem(topTag);
2495 FloatRectangle itemBounds = pItem->GetBoundsF();
2496 itemBounds.y = CalculateItemPositionY(topTag.groupIndex, topTag.itemIndex);
2497 pItem->SetBounds(itemBounds);
2498 AttachNextItemsToBottom(topTag);
2499 if (groupIndex < topTag.groupIndex)
2501 ScrollTo(screenPosition + groupTotalHeight);
2505 int firstLoadedGroupIndex = -1;
2506 int firstLoadedItemIndex = -1;
2507 __pListModel->GetFirstLoadedItemIndex(firstLoadedGroupIndex, firstLoadedItemIndex);
2509 for (int j = firstLoadedGroupIndex; j <= topTag.groupIndex; j++)
2511 int itemCount = GetItemCountAt(j);
2513 for (int i = -1; i < itemCount; i++)
2515 if (i >= topTag.itemIndex && j == topTag.groupIndex)
2526 TableViewItemTag itemTag;
2527 itemTag.groupIndex = groupIndex;
2528 itemTag.itemIndex = -1;
2530 __expandableItemTag.groupIndex = groupIndex;
2531 __expandableItemTag.itemIndex = -1;
2535 _TableViewItem *pItem = FindItem(itemTag);
2541 FloatRectangle itemBounds = pItem->GetBoundsF();
2542 float startPosition = itemBounds.y + itemBounds.height;
2544 float endPosition = startPosition + groupTotalHeight;
2545 if (endPosition > screenPosition + __pTableView->GetBoundsF().height)
2547 endPosition = screenPosition + __pTableView->GetBoundsF().height;
2550 _VisualElement* pVisualElement = __pTableView->GetVisualElement();
2551 String animationName(L"EXPAND_GROUP_ANIMATION");
2553 VisualElementValueAnimation* pAnimation = __pTableView->GetVisualElementValueAnimation(animationName);
2554 pAnimation->SetStartValue(Variant(startPosition));
2555 pAnimation->SetEndValue(Variant(endPosition));
2556 pAnimation->SetDuration(EXPAND_GROUP_ANIMATION_DURATION);
2557 pVisualElement->AddAnimation(animationName, *pAnimation);
2561 ExpandGroupAnimationFinished(false);
2568 _TableViewPresenter::CollapseGroup(int groupIndex, bool withAnimation)
2570 if ((groupIndex < 0) || (groupIndex >= GetGroupCount()))
2572 return E_OUT_OF_RANGE;
2575 if (__modelInitialized == false)
2577 return E_INVALID_STATE;
2580 if (IsGroupExpanded(groupIndex) == false)
2585 TableViewItemTag itemTag;
2586 GetTopDrawnItem(itemTag);
2588 TableViewItemTag bottomTag;
2589 GetBottomDrawnItem(bottomTag);
2590 float screenPosition = GetScrollPosition();
2592 __pListModel->SetGroupExpandState(groupIndex, false);
2596 float groupTotalHeight = 0;
2597 int itemCount = GetItemCountAt(groupIndex);
2598 _TableViewItem* pItem = null;
2599 for (int i = 0; i < itemCount; i++)
2601 pItem = static_cast<_TableViewItem*>(__pListModel->GetItemFromTemporaryBuffer(groupIndex, i));
2602 groupTotalHeight += pItem->GetItemHeight();
2605 if (groupIndex < itemTag.groupIndex || groupIndex > bottomTag.groupIndex)
2607 TableViewItemTag firstLoadedItemTag;
2608 __pListModel->GetFirstLoadedItemIndex(firstLoadedItemTag.groupIndex, firstLoadedItemTag.itemIndex);
2610 if (firstLoadedItemTag.groupIndex == groupIndex)
2612 SetLoadedItemsVisibleInGroup(groupIndex, false);
2613 firstLoadedItemTag.groupIndex = groupIndex + 1;
2614 firstLoadedItemTag.itemIndex = -1;
2617 _TableViewItem* pItem = FindItem(firstLoadedItemTag);
2620 FloatRectangle itemBounds = pItem->GetBoundsF();
2621 itemBounds.y = CalculateItemPositionY(firstLoadedItemTag.groupIndex, firstLoadedItemTag.itemIndex);
2622 pItem->SetBounds(itemBounds);
2623 AttachNextItemsToBottom(firstLoadedItemTag);
2624 if (groupIndex < itemTag.groupIndex)
2626 ScrollTo(screenPosition - groupTotalHeight);
2630 for (int i = 0; i < itemCount; i++)
2632 UnloadItem(groupIndex, i);
2634 AdjustClientAreaBounds(false, -groupTotalHeight);
2639 if (itemTag.groupIndex < groupIndex)
2641 itemTag.groupIndex = groupIndex;
2642 itemTag.itemIndex = -1;
2644 __expandableItemTag.groupIndex = itemTag.groupIndex;
2645 __expandableItemTag.itemIndex = itemTag.itemIndex;
2647 if(__firstDrawnFlag)
2649 withAnimation = false;
2654 _TableViewItem *pItem = FindItem(itemTag);
2660 FloatRectangle itemBounds = pItem->GetBoundsF();
2661 float startPosition = 0;
2662 if (itemTag.itemIndex == -1)
2664 startPosition = itemBounds.y + itemBounds.height;
2668 startPosition = GetScrollPosition();
2671 if (bottomTag.groupIndex > groupIndex)
2673 bottomTag.groupIndex = groupIndex+1;
2674 bottomTag.itemIndex = -1;
2677 pItem = FindItem(bottomTag);
2683 itemBounds = pItem->GetBoundsF();
2684 float endPosition = itemBounds.y;
2685 if (bottomTag.groupIndex != groupIndex +1)
2687 endPosition += itemBounds.height;
2690 if (endPosition > screenPosition + __pTableView->GetBoundsF().height)
2692 endPosition = screenPosition + __pTableView->GetBoundsF().height;
2695 _VisualElement* pVisualElement = __pTableView->GetVisualElement();
2696 String animationName(L"COLLAPSE_GROUP_ANIMATION");
2698 VisualElementValueAnimation* pAnimation = __pTableView->GetVisualElementValueAnimation(animationName);
2699 pAnimation->SetStartValue(Variant(endPosition));
2700 pAnimation->SetEndValue(Variant(startPosition));
2701 pAnimation->SetDuration(COLLAPSE_GROUP_ANIMATION_DURATION);
2702 pVisualElement->AddAnimation(animationName, *pAnimation);
2706 CollapseGroupAnimationFinished(false);
2713 _TableViewPresenter::IsGroupExpanded(int groupIndex) const
2715 return __pListModel->IsGroupExpanded(groupIndex);
2719 _TableViewPresenter::LoadAllItemsInGroup(int groupIndex, bool downward)
2721 int itemCountInGroup = __pListModel->GetItemCountInGroup(groupIndex);
2722 _TableViewItem* pItem = null;
2726 for (int i = 0; i < itemCountInGroup; i++)
2728 pItem = LoadItem(groupIndex, i);
2732 SysLogException(NID_UI_CTRL, E_SYSTEM, "[E_SYSTEM] Unable to load item.");
2738 for (int i = itemCountInGroup-1; i >= 0; i--)
2740 pItem = LoadItem(groupIndex, i);
2744 SysLogException(NID_UI_CTRL, E_SYSTEM, "[E_SYSTEM] Unable to load item.");
2749 return itemCountInGroup;
2753 _TableViewPresenter::SetLoadedItemsVisibleInGroup(int groupIndex, bool visible)
2755 int itemCountInGroup = __pListModel->GetItemCountInGroup(groupIndex);
2756 _TableViewItem* pItem = null;
2757 TableViewItemTag itemTag;
2758 itemTag.groupIndex = groupIndex;
2760 int firstLoadedGroupIndex = -1;
2761 int firstLoadedItemIndex = -1;
2762 __pListModel->GetFirstLoadedItemIndex(firstLoadedGroupIndex, firstLoadedItemIndex);
2764 if (firstLoadedGroupIndex > groupIndex)
2770 if (groupIndex == firstLoadedGroupIndex && firstLoadedItemIndex > 0)
2772 startIndex = firstLoadedItemIndex;
2775 for (int i = startIndex; i < itemCountInGroup; i++)
2777 itemTag.itemIndex = i;
2778 pItem = FindItem(itemTag);
2784 pItem->SetVisibleState(visible);
2789 _TableViewPresenter::LoadItemsToBeVisible(const TableViewItemTag& from)
2791 TableViewItemTag bottomTag = from;
2792 TableViewItemTag current;
2793 TableViewItemTag next;
2795 _TableViewItem *pItem = LoadItem(from.groupIndex, from.itemIndex);
2802 FloatRectangle itemBounds = pItem->GetBoundsF();
2803 float viewHeight = __pTableView->GetBoundsF().height;
2804 float scrollPosition = GetScrollPosition();
2805 float itemPosition = itemBounds.y + itemBounds.height - scrollPosition;
2807 while (viewHeight >= itemPosition)
2809 current.groupIndex = bottomTag.groupIndex;
2810 current.itemIndex = bottomTag.itemIndex;
2811 if (!GetNextItemPosition(current, next))
2816 pItem = LoadItem(next.groupIndex, next.itemIndex);
2817 bottomTag.groupIndex = next.groupIndex;
2818 bottomTag.itemIndex = next.itemIndex;
2819 itemPosition += pItem->GetBoundsF().height;
2826 _TableViewPresenter::AttachNextItemsToBottom(const TableViewItemTag& anchor)
2828 TableViewItemTag itemTag = anchor;
2829 TableViewItemTag current;
2830 TableViewItemTag next;
2832 _TableViewItem *pItem = FindItem(itemTag);
2838 FloatRectangle itemBounds = pItem->GetBoundsF();
2839 float itemPosition = itemBounds.y + itemBounds.height;
2841 current.groupIndex = itemTag.groupIndex;
2842 current.itemIndex = itemTag.itemIndex;
2843 while (GetNextItemPosition(current, next))
2845 pItem = FindItem(next);
2852 itemBounds = pItem->GetBoundsF();
2853 itemBounds.y = itemPosition;
2854 pItem->SetBounds(itemBounds);
2855 itemPosition += itemBounds.height;
2861 _TableViewPresenter::IsAnyItemInGroupLoaded(int groupIndex) const
2863 int startGroupIndex = 0;
2864 int endGroupIndex = 0;
2867 __pListModel->GetFirstLoadedItemIndex(startGroupIndex, index);
2868 __pListModel->GetLastLoadedItemIndex(endGroupIndex, index);
2870 return groupIndex >= startGroupIndex && groupIndex <= endGroupIndex;
2874 _TableViewPresenter::ScrollToHideNonClientArea(TableViewItemTag& bottomTag)
2876 _TableViewItem* pItem = FindItem(bottomTag);
2882 FloatRectangle itemBounds = pItem->GetBoundsF();
2883 float viewHeight = __pTableView->GetBoundsF().height;
2884 float scrollPosition = GetScrollPosition();
2885 float itemBottom = itemBounds.y + itemBounds.height - scrollPosition;
2887 if (itemBottom < viewHeight)
2889 scrollPosition -= viewHeight - itemBottom;
2890 if (scrollPosition < 0)
2895 SetScrollPosition(scrollPosition, false);
2900 _TableViewPresenter::AdjustClientAreaBounds(bool reset, float dist)
2902 float clientHeight = 0;
2906 __itemTotalHeight = GetHeightOfAllItems();
2907 clientHeight = __itemTotalHeight;
2911 __itemTotalHeight = __itemTotalHeight + dist;
2912 clientHeight = __itemTotalHeight;
2915 SetClientAreaHeight(clientHeight);
2919 _TableViewPresenter::SetClientAreaHeight(float height)
2921 FloatRectangle screenBounds = __pTableView->GetBoundsF();
2922 FloatRectangle clientBounds = screenBounds;
2924 clientBounds.height = height;
2926 if (clientBounds.height < screenBounds.height)
2928 clientBounds.height = screenBounds.height;
2931 SetScrollAreaBounds(clientBounds);
2933 _Scroll* pScroll = __pTableView->GetScrollBar();
2934 if (pScroll != null)
2936 pScroll->SetScrollRange(__pTableView->GetBoundsF().height, clientBounds.height);
2941 _TableViewPresenter::UnloadInvisibleItems(void)
2943 float scrollPosition = GetScrollPosition();
2944 TableViewItemTag itemTag;
2945 __pListModel->GetFirstLoadedItemIndex(itemTag.groupIndex, itemTag.itemIndex);
2947 _TableViewItem* pItem = null;
2948 FloatRectangle bounds;
2950 while ((pItem = FindItem(itemTag)) != null)
2952 if (itemTag.itemIndex != -1)
2954 bounds = pItem->GetBoundsF();
2955 if (bounds.y + bounds.height < scrollPosition)
2957 UnloadItem(itemTag);
2964 __pListModel->GetFirstLoadedItemIndex(itemTag.groupIndex, itemTag.itemIndex);
2967 __pListModel->GetLastLoadedItemIndex(itemTag.groupIndex, itemTag.itemIndex);
2968 scrollPosition += __pTableView->GetBoundsF().height;
2970 while ((pItem = FindItem(itemTag)) != null)
2972 if (itemTag.itemIndex != -1)
2974 bounds = pItem->GetBoundsF();
2975 if (bounds.y > scrollPosition)
2977 UnloadItem(itemTag);
2984 __pListModel->GetLastLoadedItemIndex(itemTag.groupIndex, itemTag.itemIndex);
2990 _TableViewPresenter::ScrollToInternal(float newPosition)
2992 if (!IsScrollEnabled())
2997 if (IsScrollAnimationRunning())
2999 if (__scrollPositionOnFlickStarted > newPosition)
3001 newPosition += GetScrollAreaBounds().height - __scrollHeightOnFlickStarted;
3005 float currentScrollPosition = GetScrollPosition();
3006 float currentscrollAreaHeight = GetScrollAreaBounds().height;
3007 float newScrollPosition = (newPosition < 0) ? 0 : (newPosition > currentscrollAreaHeight ? currentscrollAreaHeight : newPosition);
3008 float newScrollAreaHeight = 0;
3010 if (IsModelUpdating())
3012 currentScrollPosition = GetScrollPositionInternal();
3015 if (!__lockLoadItemWithScroll)
3017 LoadItemWithScrollPosition(currentScrollPosition, newScrollPosition);
3019 if (currentScrollPosition > newScrollPosition)
3021 newScrollAreaHeight = GetScrollAreaBounds().height;
3022 newScrollPosition += newScrollAreaHeight - currentscrollAreaHeight;
3026 //scroll effect for _ScrollPanel
3027 if (newPosition < 0.0f || newPosition > currentscrollAreaHeight - __pTableView->GetBoundsF().height)
3029 newScrollPosition = newPosition;
3032 return _ScrollPanelPresenter::ScrollToInternal(newScrollPosition);
3036 _TableViewPresenter::LoadItemWithScrollPosition(float previousScrollPosition, float currentScrollPos)
3040 TableViewItemTag lastLoadedItemPos = {-1, -1};
3041 TableViewItemTag firstLoadedItemPos = {-1, -1};
3042 __pListModel->GetLastLoadedItemIndex(lastLoadedItemPos.groupIndex, lastLoadedItemPos.itemIndex);
3043 __pListModel->GetFirstLoadedItemIndex(firstLoadedItemPos.groupIndex, firstLoadedItemPos.itemIndex);
3045 if (currentScrollPos > previousScrollPosition && lastLoadedItemPos.groupIndex != -1)
3047 _TableViewItem* pLastItem = FindItem(lastLoadedItemPos);
3048 if (pLastItem == null)
3053 while (pLastItem->GetBoundsF().y <= currentScrollPos + __pTableView->GetBoundsF().height)
3055 TableViewItemTag nextItemPos = {-1, -1};
3056 if (GetNextItemPosition(lastLoadedItemPos, nextItemPos))
3058 if (nextItemPos.itemIndex == -1)
3060 LoadItem(nextItemPos.groupIndex, nextItemPos.itemIndex);
3062 if (!GetNextItemPosition(nextItemPos, nextItemPos))
3068 if (nextItemPos.groupIndex != -1)
3070 _TableViewItem* item = LoadItem(nextItemPos.groupIndex, nextItemPos.itemIndex);
3072 FloatRectangle scrollAreaBounds = GetScrollAreaBounds();
3073 if (item->GetBoundsF().y + item->GetBoundsF().height >= scrollAreaBounds.height)
3075 AdjustClientAreaBounds(true);
3084 lastLoadedItemPos = nextItemPos;
3085 pLastItem = static_cast<_TableViewItem*>(__pListModel->LoadItem(lastLoadedItemPos.groupIndex, lastLoadedItemPos.itemIndex));
3089 if (currentScrollPos < previousScrollPosition && firstLoadedItemPos.groupIndex != -1)
3091 _TableViewItem* pFirstItem = FindItem(firstLoadedItemPos);
3092 if (pFirstItem == null)
3097 float scrollOffsetFromBottom = GetScrollAreaBounds().height - currentScrollPos;
3101 FloatRectangle scrollAreaBounds = GetScrollAreaBounds();
3102 float itemOffsetFromBottom = scrollAreaBounds.height - (pFirstItem->GetBoundsF().y + pFirstItem->GetBoundsF().height);
3104 if (scrollOffsetFromBottom < itemOffsetFromBottom)
3109 TableViewItemTag prevItemPos = {-1, -1};
3110 if (GetPreviousItemPosition(firstLoadedItemPos, prevItemPos))
3112 if (prevItemPos.itemIndex == -1)
3114 LoadItem(prevItemPos.groupIndex, prevItemPos.itemIndex);
3116 if (!GetPreviousItemPosition(prevItemPos, prevItemPos))
3122 if (prevItemPos.groupIndex != -1)
3124 LoadItem(prevItemPos.groupIndex, prevItemPos.itemIndex);
3132 firstLoadedItemPos = prevItemPos;
3133 pFirstItem = FindItem(firstLoadedItemPos);
3139 _TableViewPresenter::ScrollToItem(int groupIndex, int itemIndex, TableViewScrollItemAlignment itemAlignment, float shiftingDistance)
3141 _VisualElement* pVisualElement = __pTableView->GetVisualElement();
3142 String animationName(L"EXPAND_GROUP_ANIMATION");
3143 VisualElementValueAnimation* pExpandGroupAnimation = dynamic_cast<VisualElementValueAnimation*>(pVisualElement->GetAnimationN(animationName));
3144 if (pExpandGroupAnimation != null)
3146 __scrollToItemTag.groupIndex = groupIndex;
3147 __scrollToItemTag.itemIndex = itemIndex;
3148 __scrollToItemTag.itemAlignment = itemAlignment;
3149 __scrollToItemTag.shiftingDistance = shiftingDistance;
3150 __scrollToItemTag.startedAnimation = true;
3151 delete pExpandGroupAnimation;
3155 animationName = L"COLLAPSE_GROUP_ANIMATION";
3156 VisualElementValueAnimation* pCollapseGroupAnimation = dynamic_cast<VisualElementValueAnimation*>(pVisualElement->GetAnimationN(animationName));
3157 if (pCollapseGroupAnimation != null)
3159 __scrollToItemTag.groupIndex = groupIndex;
3160 __scrollToItemTag.itemIndex = itemIndex;
3161 __scrollToItemTag.itemAlignment = itemAlignment;
3162 __scrollToItemTag.shiftingDistance = shiftingDistance;
3163 __scrollToItemTag.startedAnimation = true;
3164 delete pCollapseGroupAnimation;
3168 TableViewItemTag itemPos = {groupIndex, itemIndex};
3170 StopAllItemAnimation();
3173 if (!__pListModel->IsLoadedItem(groupIndex, itemIndex))
3175 ResetItemLayout(itemPos, shiftingDistance);
3178 _TableViewItem* pItem = FindItem(itemPos);
3185 float scrollPosition = pItem->GetBoundsF().y;
3187 scrollPosition = scrollPosition + shiftingDistance;
3189 SetScrollPosition(scrollPosition, false);
3191 if (itemAlignment == TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_BOTTOM)
3193 SetScrollPosition(scrollPosition - (__pTableView->GetBoundsF().height - pItem->GetBoundsF().height), false);
3198 _TableViewPresenter::ScrollByPixel(float scrollDistance)
3201 result r = GetLastResult();
3202 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
3206 ScrollTo(scrollDistance + GetScrollPosition());
3207 r = GetLastResult();
3208 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
3210 RollbackBouncing(true);
3211 r = GetLastResult();
3212 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
3215 r = GetLastResult();
3216 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
3222 _TableViewPresenter::SetScrollEnabled(bool enable)
3224 __scrolling = enable;
3228 _TableViewPresenter::IsScrollEnabled(void) const
3234 _TableViewPresenter::GetFirstDrawnFlag(void) const
3236 return __firstDrawnFlag;
3240 _TableViewPresenter::GetMaxItemCachingSize(void) const
3242 return __pListModel->GetMaxCachingSize();
3246 _TableViewPresenter::ResetSweepItem(void)
3248 if (__sweptItemTag.groupIndex != -1 && __sweptItemTag.itemIndex != -1)
3255 _TableViewPresenter::GetSweepItemIndex(int& groupIndex, int& itemIndex) const
3257 groupIndex = __sweptItemTag.groupIndex;
3258 itemIndex = __sweptItemTag.itemIndex;
3262 _TableViewPresenter::GetPressedItemCount(void)
3264 _TableViewItem* pItem = null;
3265 TableViewItemTag itemPos = {-1, -1};
3266 TableViewItemTag lastItemPos = {-1, -1};
3269 __pListModel->GetFirstLoadedItemIndex(itemPos.groupIndex, itemPos.itemIndex);
3270 __pListModel->GetLastLoadedItemIndex(lastItemPos.groupIndex, lastItemPos.itemIndex);
3274 pItem = static_cast <_TableViewItem*>(__pListModel->LoadItem(itemPos.groupIndex, itemPos.itemIndex));
3280 if (pItem->GetDrawingStatus() == TABLE_VIEW_ITEM_DRAWING_STATUS_PRESSED)
3285 if ((itemPos.itemIndex == lastItemPos.itemIndex) && (itemPos.groupIndex == lastItemPos.groupIndex))
3289 } while (GetNextItemPosition(itemPos, itemPos) == true);
3295 _TableViewPresenter::BlockAnimationCallback(bool blocked)
3297 __isAnimationCallbackBlocked = blocked;
3301 _TableViewPresenter::CalculateItemPositionY(int groupIndex, int itemIndex)
3303 TableViewItemTag itemPos = {-1, -1};
3304 TableViewItemTag currentItemPos = {-1, -1};
3305 float positionY = 0.0f;
3307 GetFirstItem(itemPos);
3309 if (itemPos.groupIndex == -1 && itemPos.itemIndex == -1)
3314 if (__pProviderAdaptor == null)
3319 positionY = GetTopMargin();
3321 while ((itemPos.groupIndex < groupIndex) || ((itemPos.groupIndex == groupIndex) && (itemPos.itemIndex < itemIndex)))
3323 currentItemPos = itemPos;
3325 float itemHeight = GetItemHeight(itemPos);
3327 positionY += itemHeight;
3329 if (!GetNextItemPosition(currentItemPos, itemPos))
3339 _TableViewPresenter::FadeInScrollBar(void)
3341 TableViewScrollBarStyle scrollStyle = __pTableView->GetScrollStyle();
3343 if (scrollStyle == TABLE_VIEW_SCROLL_BAR_STYLE_NONE)
3345 _Scroll* pScroll = __pTableView->GetScrollBar();
3347 if (pScroll != null)
3349 pScroll->SetVisibleState(false);
3352 else if (scrollStyle == TABLE_VIEW_SCROLL_BAR_STYLE_FAST_SCROLL)
3354 _Scroll* pScroll = __pTableView->GetScrollBar();
3356 if (pScroll != null)
3358 pScroll->SetVisibleState(false);
3361 _FastScroll* pFastScroll = __pTableView->GetFastScrollBar();
3363 if (pFastScroll != null)
3365 pFastScroll->SetScrollVisibility(true);
3370 _ScrollPanelPresenter::FadeInScrollBar();
3375 _TableViewPresenter::FadeOutScrollBar(void)
3377 TableViewScrollBarStyle scrollStyle = __pTableView->GetScrollStyle();
3378 if (scrollStyle == TABLE_VIEW_SCROLL_BAR_STYLE_FAST_SCROLL)
3380 StopFastScrollTimer();
3382 if (!_ScrollPanelPresenter::IsScrollAnimationRunning())
3384 StartFastScrollTimer();
3387 else if (scrollStyle == TABLE_VIEW_SCROLL_BAR_STYLE_FIXED)
3389 _Scroll* pScroll = __pTableView->GetScrollBar();
3391 if (pScroll != null)
3393 pScroll->SetScrollingEffectVisibility(false);
3398 _ScrollPanelPresenter::FadeOutScrollBar();
3403 _TableViewPresenter::SweepItem(float x)
3405 if (!_FloatCompare(x, 0.0f))
3407 _TableViewItem* pItem = static_cast<_TableViewItem*>(__pListModel->LoadItem(__sweptItemTag.groupIndex, __sweptItemTag.itemIndex));
3411 _TableViewItem* pContextItem = pItem->GetContextItem();
3413 if (pContextItem != null)
3415 float currentPosition = __sweptItemPosition.x + x;
3416 float sweepDistance = __pTableView->GetBoundsF().width;
3417 float sweepMargin = 0.0f;
3418 float contextItemWidth = pItem->GetBoundsF().width;
3419 bool activated = pItem->IsContextItemActivated();
3420 bool needToFireEvent = false;
3422 GET_SHAPE_CONFIG(TABLEVIEW::CONTEXTITEM_RIGHT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, sweepMargin);
3424 if (currentPosition >= (sweepDistance - sweepMargin))
3426 currentPosition = (sweepDistance - sweepMargin);
3427 needToFireEvent = !activated;
3429 else if (currentPosition <= __leftMargin)
3431 currentPosition = __leftMargin;
3432 needToFireEvent = activated;
3435 __sweptItemPosition.x = currentPosition;
3437 // Set TableViewItem bounds
3438 pItem->SetPosition(__sweptItemPosition);
3440 // Set TableViewContextItem bounds
3441 if (!__pTableView->IsAncestorOf(*pContextItem))
3443 pContextItem->SetDrawingProperty(__pItemDrawingProperty);
3444 __pTableView->InsertChildToBottom(*pContextItem);
3445 __pTableView->UpdateLayout();
3448 contextItemWidth = ((contextItemWidth > (__sweptItemPosition.x - __leftMargin)) ? (__sweptItemPosition.x - __leftMargin) : contextItemWidth);
3450 pContextItem->ExposeContextItem(FloatRectangle(__leftMargin, __sweptItemPosition.y, contextItemWidth, pContextItem->GetSizeF().height), pItem->GetSize().width);
3452 if (needToFireEvent)
3454 PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_SLIDER_SWEEP);
3456 activated = !activated; // ContextItem Activation State Changed
3458 __pTableView->FireTableViewContextItemActivationEvent(__sweptItemTag.groupIndex, __sweptItemTag.itemIndex, pContextItem, activated);
3459 pItem->SetContextItemActivation(activated);
3472 _TableViewPresenter::ResetSweptItem(void)
3474 _TableViewItem* pItem = static_cast<_TableViewItem*>(__pListModel->LoadItem(__sweptItemTag.groupIndex, __sweptItemTag.itemIndex));
3478 _VisualElement* pVisualElement = __pTableView->GetVisualElement();
3480 if (pVisualElement != null)
3482 String animationName(L"SWEEP_ITEM_ANIMATION");
3483 VisualElementAnimation* pContextItemAnimation = pVisualElement->GetAnimationN(animationName);
3484 if (pContextItemAnimation != null)
3486 pVisualElement->RemoveAnimation(animationName);
3488 delete pContextItemAnimation;
3492 pItem->SetPosition(FloatPoint(__leftMargin, __sweptItemPosition.y));
3494 _TableViewItem* pContextItem = pItem->GetContextItem();
3495 if (pContextItem != null)
3497 if (__pTableView->IsAncestorOf(*pContextItem))
3499 __pTableView->DetachChild(*pContextItem);
3502 if (pItem->IsContextItemActivated())
3504 __pTableView->FireTableViewContextItemActivationEvent(__sweptItemTag.groupIndex, __sweptItemTag.itemIndex, pContextItem, false);
3505 pItem->SetContextItemActivation(false);
3510 __sweptItemTag.itemIndex = -1;
3511 __sweptItemTag.groupIndex = -1;
3513 __sweptItemPosition.SetPosition(-1.0f, -1.0f);
3514 __sweepOccured = false;
3518 _TableViewPresenter::AdjustSweptItemPosition(bool withAnimation)
3520 float itemWidth = __pTableView->GetBoundsF().width;
3521 float sweepDistance = 0.0f;
3523 if (_FloatCompare(__sweptItemPosition.x, __leftMargin))
3529 float sweepMargin = 0.0f;
3530 GET_SHAPE_CONFIG(TABLEVIEW::CONTEXTITEM_RIGHT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, sweepMargin);
3532 if (__sweptItemPosition.x > (itemWidth - sweepMargin) / 2)
3534 sweepDistance = itemWidth - __sweptItemPosition.x;
3538 sweepDistance = -__sweptItemPosition.x;
3543 SweepItem(sweepDistance);
3547 _TableViewItem* pItem = static_cast<_TableViewItem*>(__pListModel->LoadItem(__sweptItemTag.groupIndex, __sweptItemTag.itemIndex));
3551 _VisualElement* pVisualElement = __pTableView->GetVisualElement();
3553 if (pVisualElement != null)
3555 String animationName(L"SWEEP_ITEM_ANIMATION");
3556 float startValue = __sweptItemPosition.x;
3557 float endValue = 0.0f;
3559 if(sweepDistance > 0)
3561 endValue = itemWidth - sweepMargin;
3565 if(_FloatCompare(itemWidth, __sweptItemPosition.x))
3567 endValue = itemWidth - sweepMargin;
3571 endValue = __leftMargin;
3575 pVisualElement->SetImplicitAnimationEnabled(false);
3577 VisualElementValueAnimation* pAnimation = __pTableView->GetVisualElementValueAnimation(animationName);
3578 pAnimation->SetStartValue(Variant(startValue));
3579 pAnimation->SetEndValue(Variant(endValue));
3580 pAnimation->SetDuration(SWEEP_ITEM_ANIMATION_DURATION);
3581 pVisualElement->AddAnimation(animationName, *pAnimation);
3588 _TableViewPresenter::AdjustLoadedItemWidth(void)
3590 TableViewItemTag lastLoadedItemPos = {-1, -1};
3591 TableViewItemTag firstLoadedItemPos = {-1, -1};
3592 __pListModel->GetLastLoadedItemIndex(lastLoadedItemPos.groupIndex, lastLoadedItemPos.itemIndex);
3593 __pListModel->GetFirstLoadedItemIndex(firstLoadedItemPos.groupIndex, firstLoadedItemPos.itemIndex);
3597 _TableViewItem* pItem = FindItem(firstLoadedItemPos);
3604 FloatDimension itemSize = pItem->GetSizeF();
3605 itemSize.width = __pProviderAdaptor->GetListWidth();
3607 pItem->SetItemChanged(true);
3608 pItem->SetSize(itemSize);
3610 if ((firstLoadedItemPos.itemIndex == lastLoadedItemPos.itemIndex) && (firstLoadedItemPos.groupIndex == lastLoadedItemPos.groupIndex))
3614 } while (GetNextItemPosition(firstLoadedItemPos, firstLoadedItemPos));
3618 _TableViewPresenter::OpenContextItem(int groupIndex, int itemIndex)
3620 SysTryReturn(NID_UI_CTRL, groupIndex >= 0 && groupIndex < GetGroupCount(), E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[E_INVALID_ARG] Invalid group index.");
3622 TableViewItemTag itemTag = {groupIndex, itemIndex};
3623 _TableViewItem* pItem = FindItem(itemTag);
3625 SysTryReturn(NID_UI_CTRL, pItem != null, E_INVALID_OPERATION, E_INVALID_OPERATION, "[E_INVALID_OPERATION] Item was not loaded.");
3626 SysTryReturn(NID_UI_CTRL, pItem->GetContextItem() != null, E_INVALID_OPERATION, E_INVALID_OPERATION, "[E_INVALID_OPERATION] ContextItem is not set to the item.");
3627 SysTryReturn(NID_UI_CTRL,__sweptItemTag.groupIndex != groupIndex || __sweptItemTag.itemIndex != itemIndex, E_INVALID_OPERATION, E_INVALID_OPERATION, "[E_INVALID_OPERATION] ContextItem already opened.");
3631 __sweptItemTag.groupIndex = groupIndex;
3632 __sweptItemTag.itemIndex = itemIndex;
3633 __sweptItemPosition = pItem->GetPositionF();
3635 pItem->AdjustContextItemBounds();
3636 __sweepOccured = true;
3638 _VisualElement* pVisualElement = __pTableView->GetVisualElement();
3640 if (pVisualElement != null)
3642 float itemWidth = __pTableView->GetBoundsF().width;
3643 float sweepMargin = 0.0f;
3644 GET_SHAPE_CONFIG(TABLEVIEW::CONTEXTITEM_RIGHT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, sweepMargin);
3646 String animationName(L"SWEEP_ITEM_ANIMATION");
3647 float startValue = __sweptItemPosition.x;
3648 float endValue = itemWidth - sweepMargin;
3650 pVisualElement->SetImplicitAnimationEnabled(false);
3652 VisualElementValueAnimation* pAnimation = __pTableView->GetVisualElementValueAnimation(animationName);
3653 pAnimation->SetStartValue(Variant(startValue));
3654 pAnimation->SetEndValue(Variant(endValue));
3655 pAnimation->SetDuration(SWEEP_ITEM_ANIMATION_DURATION);
3656 pVisualElement->AddAnimation(animationName, *pAnimation);
3663 _TableViewPresenter::CloseContextItem(int groupIndex, int itemIndex)
3665 SysTryReturn(NID_UI_CTRL, groupIndex >= 0 && groupIndex < GetGroupCount(), E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[E_INVALID_ARG] Invalid group index.");
3667 TableViewItemTag itemTag = {groupIndex, itemIndex};
3668 _TableViewItem* pItem = FindItem(itemTag);
3670 SysTryReturn(NID_UI_CTRL, pItem != null, E_INVALID_OPERATION, E_INVALID_OPERATION, "[E_INVALID_OPERATION] Item was not loaded.");
3671 SysTryReturn(NID_UI_CTRL, pItem->GetContextItem() != null, E_INVALID_OPERATION, E_INVALID_OPERATION, "[E_INVALID_OPERATION] ContextItem is not set to the item.");
3672 SysTryReturn(NID_UI_CTRL, __sweptItemTag.groupIndex == groupIndex && __sweptItemTag.itemIndex == itemIndex, E_INVALID_OPERATION, E_INVALID_OPERATION, "[E_INVALID_OPERATION] ContextItem was not opened.");
3680 _TableViewPresenter::IsContextItemOpened(int groupIndex, int itemIndex) const
3682 SysTryReturn(NID_UI_CTRL, groupIndex >= 0 && groupIndex < GetGroupCount(), false, E_OUT_OF_RANGE, "[E_INVALID_ARG] Invalid group index.");
3684 if ( __sweptItemTag.groupIndex == -1 && __sweptItemTag.itemIndex == -1)
3689 if (__sweptItemTag.groupIndex == groupIndex && __sweptItemTag.itemIndex == itemIndex)
3698 _TableViewPresenter::SetSectionHeaderTextHorizontalAlignment(int sectionIndex, HorizontalAlignment alignment)
3700 SysTryReturn(NID_UI_CTRL, __pTableView->GetTableViewStyle() == TABLE_VIEW_STYLE_SECTION, E_INVALID_OPERATION, E_INVALID_OPERATION, "[E_INVALID_OPERATION] The style of TableView is TABLE_VIEW_STYLE_SECTION");
3701 SysTryReturn(NID_UI_CTRL, HasSectionHeader(sectionIndex), E_INVALID_OPERATION, E_INVALID_OPERATION, "[E_INVALID_OPERATION] Header is not set to the section.");
3702 SysTryReturn(NID_UI_CTRL, sectionIndex >= 0 && sectionIndex < GetGroupCount(), E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[E_INVALID_ARG] Invalid section index.");
3704 _TableViewSectionStringAlignment newAlignment;
3706 __sectionAlignmentList.GetAt(sectionIndex, newAlignment);
3707 newAlignment.headerHorizontalAlignment = alignment;
3708 __sectionAlignmentList.SetAt(newAlignment, sectionIndex);
3710 TableViewItemTag itemTag = {sectionIndex, -1};
3711 _TableViewItem* pItem = FindItem(itemTag);
3715 pItem->SetSectionHeaderFooterAlignment(alignment);
3722 _TableViewPresenter::GetSectionHeaderTextHorizontalAlignment(int sectionIndex) const
3724 SysTryReturn(NID_UI_CTRL, __pTableView->GetTableViewStyle() == TABLE_VIEW_STYLE_SECTION, ALIGNMENT_LEFT, E_INVALID_OPERATION, "[E_INVALID_OPERATION] The style of TableView is TABLE_VIEW_STYLE_SECTION");
3725 SysTryReturn(NID_UI_CTRL, HasSectionHeader(sectionIndex), ALIGNMENT_LEFT, E_INVALID_OPERATION, "[E_INVALID_OPERATION] Header is not set to the section.");
3726 SysTryReturn(NID_UI_CTRL, sectionIndex >= 0 && sectionIndex < GetGroupCount(), ALIGNMENT_LEFT, E_OUT_OF_RANGE, "[E_INVALID_ARG] Invalid section index.");
3728 _TableViewSectionStringAlignment alignment;
3729 __sectionAlignmentList.GetAt(sectionIndex, alignment);
3731 return alignment.headerHorizontalAlignment;
3735 _TableViewPresenter::SetSectionFooterTextHorizontalAlignment(int sectionIndex, HorizontalAlignment alignment)
3737 SysTryReturn(NID_UI_CTRL, __pTableView->GetTableViewStyle() == TABLE_VIEW_STYLE_SECTION, E_INVALID_OPERATION, E_INVALID_OPERATION, "[E_INVALID_OPERATION] The style of TableView is TABLE_VIEW_STYLE_SECTION");
3738 SysTryReturn(NID_UI_CTRL, HasSectionFooter(sectionIndex), E_INVALID_OPERATION, E_INVALID_OPERATION, "[E_INVALID_OPERATION] Footer is not set to the section.");
3739 SysTryReturn(NID_UI_CTRL, sectionIndex >= 0 && sectionIndex < GetGroupCount(), E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[E_INVALID_ARG] Invalid section index.");
3741 _TableViewSectionStringAlignment newAlignment;
3743 __sectionAlignmentList.GetAt(sectionIndex, newAlignment);
3744 newAlignment.footerHorizontalAlignment= alignment;
3745 __sectionAlignmentList.SetAt(newAlignment, sectionIndex);
3747 TableViewItemTag itemTag = {sectionIndex, GetItemCountAt(sectionIndex) - 1};
3748 _TableViewItem* pItem = FindItem(itemTag);
3752 pItem->SetSectionHeaderFooterAlignment(alignment);
3759 _TableViewPresenter::GetSectionFooterTextHorizontalAlignment(int sectionIndex) const
3761 SysTryReturn(NID_UI_CTRL, __pTableView->GetTableViewStyle() == TABLE_VIEW_STYLE_SECTION, ALIGNMENT_RIGHT, E_INVALID_OPERATION, "[E_INVALID_OPERATION] The style of TableView is TABLE_VIEW_STYLE_SECTION");
3762 SysTryReturn(NID_UI_CTRL, HasSectionFooter(sectionIndex), ALIGNMENT_RIGHT, E_INVALID_OPERATION, "[E_INVALID_OPERATION] Footer is not set to the section.");
3763 SysTryReturn(NID_UI_CTRL, sectionIndex >= 0 && sectionIndex < GetGroupCount(), ALIGNMENT_RIGHT, E_OUT_OF_RANGE, "[E_INVALID_ARG] Invalid section index.");
3765 _TableViewSectionStringAlignment alignment;
3766 __sectionAlignmentList.GetAt(sectionIndex, alignment);
3768 return alignment.footerHorizontalAlignment;
3772 _TableViewPresenter::IsValidDrawnItem(int groupIndex, int itemIndex)
3774 TableViewItemTag currentItemTag = {groupIndex, itemIndex};
3775 TableViewItemTag itemTag = {-1, -1};
3777 if (GetNextItemPosition(currentItemTag, itemTag))
3779 if (__pListModel->IsLoadedItem(itemTag.groupIndex, itemTag.itemIndex))
3785 if (GetPreviousItemPosition(currentItemTag, itemTag))
3787 if (__pListModel->IsLoadedItem(itemTag.groupIndex, itemTag.itemIndex))
3797 _TableViewPresenter::StopAllItemAnimation(void)
3799 TableViewItemTag currentItemTag = {-1, -1};
3800 TableViewItemTag lastItemTag = {-1, -1};
3802 __pListModel->GetFirstLoadedItemIndex(currentItemTag.groupIndex, currentItemTag.itemIndex);
3803 __pListModel->GetLastLoadedItemIndex(lastItemTag.groupIndex, lastItemTag.itemIndex);
3807 _TableViewItem *pItem = FindItem(currentItemTag);
3810 pItem->StopAllAnimation();
3813 if (currentItemTag.groupIndex == lastItemTag.groupIndex && currentItemTag.itemIndex == lastItemTag.itemIndex)
3818 }while (GetNextItemPosition(currentItemTag, currentItemTag));
3822 _TableViewPresenter::GetTableViewItemPosition(_TableViewItem& item, TableViewItemTag& itemTag)
3824 TableViewItemTag lastLoadedItemPos = {-1, -1};
3825 TableViewItemTag firstLoadedItemPos = {-1, -1};
3826 __pListModel->GetLastLoadedItemIndex(lastLoadedItemPos.groupIndex, lastLoadedItemPos.itemIndex);
3827 __pListModel->GetFirstLoadedItemIndex(firstLoadedItemPos.groupIndex, firstLoadedItemPos.itemIndex);
3829 _TableViewItem* pCurrentItem = null;
3832 pCurrentItem = static_cast<_TableViewItem*>(__pListModel->LoadItem(firstLoadedItemPos.groupIndex, firstLoadedItemPos.itemIndex));
3833 if (pCurrentItem == &item)
3835 itemTag.groupIndex = firstLoadedItemPos.groupIndex;
3836 itemTag.itemIndex = firstLoadedItemPos.itemIndex;
3840 if ((firstLoadedItemPos.itemIndex == lastLoadedItemPos.itemIndex) && (firstLoadedItemPos.groupIndex == lastLoadedItemPos.groupIndex))
3844 } while (GetNextItemPosition(firstLoadedItemPos, firstLoadedItemPos));
3850 _TableViewPresenter::GetItemHeight(TableViewItemTag itemTag) const
3852 float itemHeight = 0.0f;
3854 if (__pTableView->GetTableViewStyle() == TABLE_VIEW_STYLE_SECTION && itemTag.itemIndex != -1)
3856 if (HasSectionFooter(itemTag.groupIndex))
3858 if (itemTag.itemIndex == GetItemCountAt(itemTag.groupIndex) - 1)
3860 GET_SHAPE_CONFIG(TABLEVIEW::GROUPITEM_DEFAULT_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, itemHeight);
3866 if (__pProviderAdaptor == null)
3872 for (int i = 0; i < itemTag.groupIndex; i++)
3874 int itemCount = GetItemCountAt(i);
3876 startIndex = startIndex + itemCount + 1;
3879 itemTag.itemIndex++;
3880 itemTag.itemIndex = startIndex + itemTag.itemIndex;
3882 __itemHeightList.GetAt(itemTag.itemIndex, itemHeight);
3888 _TableViewPresenter::SetItemHeight(TableViewItemTag itemTag, float height)
3892 for (int i = 0; i < itemTag.groupIndex; i++)
3894 int itemCount = GetItemCountAt(i);
3896 startIndex = startIndex + itemCount + 1;
3899 itemTag.itemIndex++;
3900 itemTag.itemIndex = startIndex + itemTag.itemIndex;
3902 float oldHeight = 0.0f;
3903 __itemHeightList.GetAt(itemTag.itemIndex, oldHeight);
3904 __itemHeightList.SetAt(height, itemTag.itemIndex);
3911 _TableViewPresenter::SetReorderMode(bool enabled)
3915 __reorderInfo.itemIndex = -1;
3916 __reorderInfo.groupIndex = -1;
3918 _TableViewItem* pItem = null;
3919 TableViewItemTag itemPos = {-1, -1};
3920 TableViewItemTag lastItemPos = {-1, -1};
3922 __pListModel->GetFirstLoadedItemIndex(itemPos.groupIndex, itemPos.itemIndex);
3923 __pListModel->GetLastLoadedItemIndex(lastItemPos.groupIndex, lastItemPos.itemIndex);
3927 pItem = FindItem(itemPos);
3931 pItem->SetReorderMode(enabled);
3933 if (enabled && itemPos.itemIndex != -1)
3935 if (pItem->GetDrawingStatus() == TABLE_VIEW_ITEM_DRAWING_STATUS_PRESSED)
3937 if (SelectReorderItem(itemPos.groupIndex, itemPos.itemIndex, true))
3939 FloatPoint itemPosition = pItem->GetPositionF();
3940 FloatPoint touchPosition = pItem->GetLastTouchPressedPositionF();
3942 __reorderInfo.touchPressedPositionY = itemPosition.y + touchPosition.y - GetScrollPosition();
3943 __reorderInfo.blockedTouchReleaseState = true;
3949 if ((itemPos.itemIndex == lastItemPos.itemIndex) && (itemPos.groupIndex == lastItemPos.groupIndex))
3954 } while (GetNextItemPosition(itemPos, itemPos) == true);
3960 _TableViewPresenter::SelectReorderItem(int groupIndex, int itemIndex, bool directSelection)
3962 if (itemIndex == -1 || (!directSelection && GetPressedItemCount() > 0))
3967 TableViewItemTag itemPos = {groupIndex, itemIndex};
3968 _TableViewItem* pItem = FindItem(itemPos);
3975 pItem->SetDrawingStatus(TABLE_VIEW_ITEM_DRAWING_STATUS_PRESSED);
3976 pItem->SetItemChanged(true);
3977 pItem->Invalidate();
3979 __reorderInfo.blockedScroll = false;
3980 __reorderInfo.itemBounds = pItem->GetBoundsF();
3981 __reorderInfo.itemIndex = itemIndex;
3982 __reorderInfo.groupIndex = groupIndex;
3983 __reorderInfo.originGroupIndex = groupIndex;
3984 __reorderInfo.originItemIndex = itemIndex;
3985 __reorderInfo.itemBasisPositionY = __reorderInfo.itemBounds.y;
3987 Tizen::System::SystemTime::GetTicks(__reorderInfo.touchPressedTick);
3989 pItem->GetVisualElement()->SetZOrder(null, true);
3991 if (GetScrollAreaBounds().height < __pTableView->GetBoundsF().height)
3993 float itemHeight = pItem->GetBoundsF().height;
3995 __pListModel->GetLastLoadedItemIndex(itemPos.groupIndex, itemPos.itemIndex);
3997 pItem = FindItem(itemPos);
4001 FloatRectangle itemBounds = pItem->GetBoundsF();
4002 __reorderInfo.nonScrollableLimitArea = itemBounds.y + itemBounds.height - itemHeight;
4007 __reorderInfo.nonScrollableLimitArea = 0;
4014 _TableViewPresenter::ResetReorderItem(int groupIndex, int itemIndex)
4016 TableViewItemTag itemPos = {groupIndex, itemIndex};
4017 _TableViewItem* pItem = FindItem(itemPos);
4024 pItem->SetDrawingStatus(TABLE_VIEW_ITEM_DRAWING_STATUS_NORMAL);
4025 pItem->SetItemChanged(true);
4026 pItem->Invalidate();
4028 PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_LIST_REORDER);
4030 FloatPoint position = FloatPoint(__reorderInfo.itemBounds.x, __reorderInfo.itemBounds.y);
4031 pItem->SetPosition(position);
4033 if (__reorderInfo.originGroupIndex != __reorderInfo.groupIndex || __reorderInfo.originItemIndex != __reorderInfo.itemIndex)
4035 if (__pTableView->GetTableViewStyle() == TABLE_VIEW_STYLE_SIMPLE)
4037 __pTableView->FireTableViewItemReorderEvent(__reorderInfo.originItemIndex, __reorderInfo.itemIndex);
4039 else if (__pTableView->GetTableViewStyle() == TABLE_VIEW_STYLE_GROUPED)
4041 __pTableView->FireTableViewItemReorderEvent(__reorderInfo.originGroupIndex, __reorderInfo.originItemIndex, __reorderInfo.groupIndex, __reorderInfo.itemIndex);
4045 __reorderInfo.groupIndex = -1;
4046 __reorderInfo.itemIndex = -1;
4047 __reorderInfo.originGroupIndex = -1;
4048 __reorderInfo.originItemIndex = -1;
4049 __reorderInfo.nonScrollableLimitArea = 0;
4051 StopReorderScrollTimer();
4057 _TableViewPresenter::CheckReorderItemScrollAnimation(_TableViewItem *pItem)
4059 float currentScrollPosition = GetScrollPosition();
4060 float limitTopPositionY = currentScrollPosition;
4061 float limitBottomPositionY = currentScrollPosition + __pTableView->GetBoundsF().height - __reorderInfo.itemBounds.height;
4063 float itemPositionY = pItem->GetPositionF().y;
4065 if (itemPositionY < limitTopPositionY)
4067 if (__pReorderScrollTimer == null)
4069 __reorderInfo.isScrollDirectionUp = true;
4074 else if (itemPositionY > limitBottomPositionY)
4076 if (__pReorderScrollTimer == null)
4078 __reorderInfo.isScrollDirectionUp = false;
4088 _TableViewPresenter::DragSelectedItem(float distance, bool relativeCoordinate)
4090 TableViewItemTag itemPos = {__reorderInfo.groupIndex, __reorderInfo.itemIndex};
4091 _TableViewItem* pItem = FindItem(itemPos);
4098 if (__firstTouchMoved)
4100 long long currentTick = 0;
4101 Tizen::System::SystemTime::GetTicks(currentTick);
4103 if (currentTick - __reorderInfo.touchPressedTick < REORDER_TOUCH_UIACTIVATE_DURATION)
4108 __firstTouchMoved = false;
4111 FloatPoint itemPosition = pItem->GetPositionF();
4113 if (relativeCoordinate)
4115 itemPosition.y = __reorderInfo.itemBasisPositionY + distance;
4119 itemPosition.y += distance;
4121 __reorderInfo.itemBasisPositionY += distance;
4124 if (itemPosition.y < 0)
4129 float scrollAreaHeight = GetScrollAreaBounds().height;
4130 float screenHeight = __pTableView->GetBoundsF().height;
4131 float limitBottomPositionY = 0.0f;
4133 if (scrollAreaHeight < screenHeight)
4135 limitBottomPositionY = __reorderInfo.nonScrollableLimitArea;
4139 limitBottomPositionY = scrollAreaHeight - __reorderInfo.itemBounds.height;
4142 if (itemPosition.y > limitBottomPositionY)
4144 itemPosition.y = limitBottomPositionY;
4147 pItem->SetPosition(itemPosition);
4150 if (CheckReorderItemScrollAnimation(pItem))
4152 if (__pReorderScrollTimer == null)
4154 StartReorderScrollTimer();
4159 if (__pReorderScrollTimer != null)
4161 StopReorderScrollTimer();
4166 TableViewItemTag moveItemTag = {-1, -1};
4168 if (CheckReorderItemPosition(pItem, moveItemTag))
4170 if (moveItemTag.itemIndex == -1)
4172 int destGroupIndex = moveItemTag.groupIndex;
4174 if (destGroupIndex != 0 && destGroupIndex == __reorderInfo.groupIndex)
4179 if (moveItemTag.groupIndex == 0 || !__pProviderAdaptor->IsReorderable(__reorderInfo.groupIndex, destGroupIndex))
4181 __reorderInfo.blockedScroll = true;
4187 ReorderItem(moveItemTag.groupIndex, moveItemTag.itemIndex);
4194 _TableViewPresenter::CheckReorderItemPosition(_TableViewItem* pItem, TableViewItemTag& reorderItemTag)
4196 TableViewItemTag currentItemTag = {__reorderInfo.groupIndex, __reorderInfo.itemIndex};
4197 TableViewItemTag previousItemTag = {-1, -1};
4198 TableViewItemTag nextItemTag = {-1, -1};
4200 FloatRectangle itemBounds = pItem->GetBoundsF();
4202 if (GetPreviousItemPosition(currentItemTag, previousItemTag))
4204 _TableViewItem* pPreviousItem = LoadItem(previousItemTag.groupIndex, previousItemTag.itemIndex);
4206 if (pPreviousItem != null)
4208 FloatRectangle previousItemBounds = pPreviousItem->GetBoundsF();
4210 if (itemBounds.y < previousItemBounds.y + (previousItemBounds.height / 2))
4212 //return previousItemIndex;
4213 reorderItemTag.groupIndex = previousItemTag.groupIndex;
4214 reorderItemTag.itemIndex = previousItemTag.itemIndex;
4221 if (GetNextItemPosition(currentItemTag, nextItemTag))
4223 _TableViewItem* pNextItem = LoadItem(nextItemTag.groupIndex, nextItemTag.itemIndex);
4225 if (pNextItem != null)
4227 FloatRectangle nextItemBounds = pNextItem->GetBoundsF();
4229 if (itemBounds.y + itemBounds.height > nextItemBounds.y + (nextItemBounds.height / 2))
4231 //return nextItemIndex;
4232 reorderItemTag.groupIndex = nextItemTag.groupIndex;
4233 reorderItemTag.itemIndex = nextItemTag.itemIndex;
4240 reorderItemTag.groupIndex = -1;
4241 reorderItemTag.itemIndex = -1;
4247 _TableViewPresenter::ReorderItem(int destinationGroupIndex, int destinationItemIndex)
4249 TableViewItemTag itemPos = {destinationGroupIndex, destinationItemIndex};
4251 _TableViewItem* pItem = FindItem(itemPos);
4258 if (pItem->IsAnimationPlaying())
4263 FloatRectangle destinationItemBounds = pItem->GetBoundsF();
4265 FloatPoint destinationItemPosition = FloatPoint(destinationItemBounds.x, 0.0f);
4267 if ( __reorderInfo.itemIndex > destinationItemIndex && __reorderInfo.groupIndex == destinationGroupIndex)
4269 destinationItemPosition.y = __reorderInfo.itemBounds.y + __reorderInfo.itemBounds.height - destinationItemBounds.height;
4270 __reorderInfo.itemBounds.y = destinationItemBounds.y;
4272 if (destinationItemIndex == -1)
4274 destinationGroupIndex--;
4275 int itemCount = GetItemCountAt(destinationGroupIndex);
4276 destinationItemIndex = itemCount;
4281 destinationItemPosition.y = __reorderInfo.itemBounds.y;
4282 __reorderInfo.itemBounds.y = destinationItemBounds.y + destinationItemBounds.height - __reorderInfo.itemBounds.height;
4284 if (destinationItemIndex == -1)
4286 destinationItemIndex = 0;
4290 __pListModel->MoveItem(__reorderInfo.groupIndex, __reorderInfo.itemIndex, destinationGroupIndex, destinationItemIndex);
4292 if (!pItem->MoveItem(destinationItemPosition, REORDER_ITEM_MOVE_ANIMATION_DURATION, 0))
4294 pItem->SetPosition(destinationItemPosition);
4297 __reorderInfo.itemIndex = destinationItemIndex;
4298 __reorderInfo.groupIndex = destinationGroupIndex;
4304 _TableViewPresenter::StartReorderScrollTimer(void)
4306 StopReorderScrollTimer();
4308 __pReorderScrollTimer = new (std::nothrow) Tizen::Base::Runtime::Timer;
4309 SysTryReturnVoidResult(NID_UI_CTRL, __pReorderScrollTimer != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
4311 result r = __pReorderScrollTimer->Construct(*this);
4312 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
4314 r = __pReorderScrollTimer->Start(REORDER_SCROLL_ANIMATION_TIMER_DURATION);
4315 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
4320 StopReorderScrollTimer();
4324 _TableViewPresenter::StopReorderScrollTimer(void)
4326 delete __pReorderScrollTimer;
4327 __pReorderScrollTimer = null;
4332 _TableViewPresenter::UpdateLayout(void)
4338 _TableViewPresenter::CheckItemHeightAndRefreshLayout(TableViewItemTag itemTag, bool downScroll)
4340 _TableViewItem* pItem = FindItem(itemTag);
4347 if (pItem->IsAnimationPlaying())
4352 FloatRectangle itemBounds = pItem->GetBoundsF();
4354 if (_FloatCompare(GetItemHeight(itemTag), itemBounds.height))
4359 float newHeight = itemBounds.height;
4360 float originHeight = SetItemHeight(itemTag, newHeight);
4361 float dist = newHeight - originHeight;
4363 AdjustClientAreaBounds(false, dist);
4367 itemBounds.y += dist;
4368 pItem->SetBounds(itemBounds);
4371 AttachNextItemsToBottom(itemTag);
4377 _TableViewPresenter::CreateItemHeightList(float defaultGroupItemHeight, float defaultItemHeight)
4379 int groupCount = GetGroupCount();
4381 result r = __itemHeightList.SetCapacity(GetItemCount());
4382 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
4384 for (int i = 0; i < groupCount; i++)
4386 int itemCount = GetItemCountAt(i);
4388 if (__pTableView->GetTableViewStyle() == TABLE_VIEW_STYLE_SIMPLE)
4390 __itemHeightList.Add(0.0f);
4394 __itemHeightList.Add(defaultGroupItemHeight);
4397 for (int j = 0; j < itemCount; j++)
4399 __itemHeightList.Add(defaultItemHeight);
4406 DeleteItemHeightList();
4412 _TableViewPresenter::DeleteItemHeightList(void)
4414 __itemHeightList.RemoveAll();
4418 _TableViewPresenter::RefreshItemHeightList(int groupIndex, int itemIndex, TableViewRefreshType refreshType)
4420 float defaultItemHeight = __pProviderAdaptor->GetDefaultItemHeight();
4421 float defaultGroupItemHeight = __pProviderAdaptor->GetDefaultGroupItemHeight();
4424 for (int i = 0; i < groupIndex; i++)
4426 int itemCount = GetItemCountAt(i);
4427 startIndex = startIndex + itemCount + 1;
4430 int targetIndex = startIndex + itemIndex + 1;
4432 if (refreshType == TABLE_VIEW_REFRESH_TYPE_ITEM_ADD)
4434 if (itemIndex == -1)
4436 result r = __itemHeightList.SetCapacity(GetItemCount());
4437 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));
4439 int itemCount = GetItemCountAt(groupIndex);
4440 for (int i = 0; i < itemCount; i++)
4442 __itemHeightList.InsertAt(defaultItemHeight, targetIndex);
4445 __itemHeightList.InsertAt(defaultGroupItemHeight, targetIndex);
4450 __itemHeightList.InsertAt(defaultItemHeight, targetIndex);
4453 else if (refreshType == TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE)
4455 if (itemIndex == -1)
4457 int itemCount = GetItemCountAt(groupIndex) + 1;
4459 for (int i = 0; i < itemCount; i++)
4461 __itemHeightList.RemoveAt(targetIndex);
4466 __itemHeightList.RemoveAt(targetIndex);
4474 _TableViewPresenter::CreateSectionAlignmentList(void)
4476 if (__pTableView->GetTableViewStyle() != TABLE_VIEW_STYLE_SECTION)
4481 int groupCount = GetGroupCount();
4483 result r = __sectionAlignmentList.SetCapacity(GetGroupCount());
4484 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));
4486 _TableViewSectionStringAlignment alignment;
4487 alignment.headerHorizontalAlignment = ALIGNMENT_LEFT;
4488 alignment.footerHorizontalAlignment = ALIGNMENT_RIGHT;
4490 for (int i = 0; i < groupCount; i++)
4493 __sectionAlignmentList.Add(alignment);
4500 _TableViewPresenter::DeleteSectionAlignmentList(void)
4502 __sectionAlignmentList.RemoveAll();
4506 _TableViewPresenter::RefreshSectionAlignmentList(int groupIndex, TableViewRefreshType refreshType)
4508 if (__pTableView->GetTableViewStyle() != TABLE_VIEW_STYLE_SECTION)
4513 if (refreshType == TABLE_VIEW_REFRESH_TYPE_ITEM_ADD)
4515 _TableViewSectionStringAlignment alignment;
4516 alignment.headerHorizontalAlignment = ALIGNMENT_LEFT;
4517 alignment.footerHorizontalAlignment = ALIGNMENT_RIGHT;
4519 __sectionAlignmentList.InsertAt(alignment, groupIndex);
4521 else if (refreshType == TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE)
4523 __sectionAlignmentList.RemoveAt(groupIndex);
4530 _TableViewPresenter::CaptureAndStartRemoveItemAnimation(int groupIndex, int itemIndex)
4532 TableViewItemTag itemTag = {groupIndex, itemIndex};
4533 _TableViewItem* pItem = FindItem(itemTag);
4540 FloatRectangle itemBounds = pItem->GetBoundsF();
4541 result r = E_SUCCESS;
4543 _VisualElement* pVisualElement = null;
4544 String animationName(L"REMOVE_ITEM_ANIMATION");
4545 Canvas* pCanvas = null;
4546 VisualElementValueAnimation* pAnimation = __pTableView->GetVisualElementValueAnimation(animationName);
4548 FloatDimension startValue(100.0f, itemBounds.height);
4549 FloatDimension endValue(0.0f, 0.0f);
4551 Tizen::Graphics::Bitmap* pBitmap = pItem->GetCapturedBitmapN(true);
4553 if (pBitmap == null)
4559 pVisualElement = new (std::nothrow) _VisualElement();
4560 SysTryCatch(NID_UI_CTRL, pVisualElement != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
4562 r = pVisualElement->Construct();
4563 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
4565 pVisualElement->SetImplicitAnimationEnabled(false);
4566 pVisualElement->SetSurfaceOpaque(false);
4567 pVisualElement->SetBounds(FloatRectangle(itemBounds.x, itemBounds.y, itemBounds.width, itemBounds.height));
4568 pVisualElement->SetShowState(true);
4570 pCanvas = pVisualElement->GetCanvasN();
4571 SysTryCatch(NID_UI_CTRL, pCanvas != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
4574 pCanvas->DrawBitmap(FloatRectangle(0, 0, itemBounds.width, itemBounds.height), *pBitmap);
4576 pAnimation->SetDelay(0);
4577 pAnimation->SetStartValue(Variant(startValue));
4578 pAnimation->SetEndValue(Variant(endValue));
4579 pAnimation->SetDuration(REMOVE_ITEM_MOVE_ANIMATION_DURATION);
4581 r = pVisualElement->AddAnimation(animationName, *pAnimation);
4582 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
4593 pVisualElement->Destroy();
4597 _TableViewPresenter::PresetItemHeightList(void)
4599 int groupCount = GetGroupCount();
4600 float defaultGroupItemHeight = __pProviderAdaptor->GetDefaultGroupItemHeight();
4601 float defaultItemHeight = __pProviderAdaptor->GetDefaultItemHeight();
4603 for (int i = 0; i < groupCount; i++)
4605 TableViewItemTag itemTag = {i, -1};
4606 int itemCount = GetItemCountAt(i);
4608 if (_FloatCompare(GetItemHeight(itemTag), TABLEVIEW_DEFAULT_ITEM_HEIGHT_VALUE))
4610 SetItemHeight(itemTag, defaultGroupItemHeight);
4613 for (int j = 0; j < itemCount; j++)
4615 itemTag.itemIndex = j;
4617 if (_FloatCompare(GetItemHeight(itemTag), TABLEVIEW_DEFAULT_ITEM_HEIGHT_VALUE))
4619 SetItemHeight(itemTag, defaultItemHeight);
4626 _TableViewPresenter::GetTableViewItemFromControl(const _Control& source)
4628 _Control* currentControl = const_cast<_Control*>(&source);
4629 _TableViewItem* pItem = null;
4631 while (__pTableView != currentControl)
4633 pItem = dynamic_cast<_TableViewItem*>(currentControl);
4635 if ((pItem != null) || (currentControl == null))
4640 currentControl = currentControl->GetParent();
4647 _TableViewPresenter::ShowTableViewCapturedItem(int groupIndex, int itemIndex, float height)
4649 TableViewItemTag itemTag = {groupIndex, itemIndex};
4650 _TableViewItem* pItem = FindItem(itemTag);
4652 if ((pItem == null) || _FloatCompare(height, 0.0f))
4657 result r = E_SUCCESS;
4658 Canvas* pCanvas = null;
4659 FloatRectangle itemBounds = pItem->GetBoundsF();
4661 bool visibleState = pItem->GetVisibleState();
4662 pItem->SetVisibleState(true);
4663 Bitmap* pBitmap = pItem->GetCapturedBitmapN(true);
4664 pItem->SetVisibleState(visibleState);
4666 if (pBitmap == null)
4671 if (__pCapturedItemVisualElement == null)
4673 __pCapturedItemVisualElement = new (std::nothrow) _VisualElement();
4674 SysTryCatch(NID_UI_CTRL, __pCapturedItemVisualElement != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
4676 r = __pCapturedItemVisualElement->Construct();
4677 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
4679 r = GetView()->GetVisualElement()->AttachChild(*__pCapturedItemVisualElement);
4680 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to attach child to the control VisualElement.", GetErrorMessage(r));
4682 __pCapturedItemVisualElement->SetSurfaceOpaque(false);
4683 __pCapturedItemVisualElement->SetImplicitAnimationEnabled(false);
4686 __pCapturedItemVisualElement->SetShowState(true);
4687 __pCapturedItemVisualElement->SetBounds(FloatRectangle(itemBounds.x, itemBounds.y, itemBounds.width, height));
4689 pCanvas = __pCapturedItemVisualElement->GetCanvasN();
4690 SysTryCatch(NID_UI_CTRL, pCanvas != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
4692 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
4694 pCanvas->DrawBitmap(FloatPoint(0.0f, 0.0f), *pBitmap);
4704 __pCapturedItemVisualElement->Destroy();
4708 _TableViewPresenter::SetLoadedItemsVisibleFromPosition(float position, bool visible)
4710 _TableViewItem* pItem;
4711 FloatRectangle itemBounds;
4712 TableViewItemTag current;
4713 current.groupIndex = __expandableItemTag.groupIndex;
4714 current.itemIndex = __expandableItemTag.itemIndex;
4716 int itemCountInGroup = __pListModel->GetItemCountInGroup(__expandableItemTag.groupIndex);
4718 for (int i = 0; i < itemCountInGroup; i++)
4720 current.itemIndex = i;
4724 pItem = LoadItem(current.groupIndex, current.itemIndex);
4732 pItem = FindItem(current);
4739 itemBounds = pItem->GetBoundsF();
4743 if ((position >= itemBounds.y) && (position < itemBounds.y + itemBounds.height))
4745 ShowTableViewCapturedItem(current.groupIndex, current.itemIndex, position - itemBounds.y);
4746 pItem->SetVisibleState(false);
4751 pItem->SetVisibleState(true);
4756 if (position < itemBounds.y)
4758 UnloadItem(current);
4760 else if ((position >= itemBounds.y) && (position < itemBounds.y + itemBounds.height))
4762 pItem->SetVisibleState(false);
4763 ShowTableViewCapturedItem(current.groupIndex, current.itemIndex, position - itemBounds.y);
4767 pItem->SetVisibleState(true);
4774 _TableViewPresenter::MoveLoadedItemsFromPosition(float position)
4776 FloatRectangle itemBounds;
4777 float itemPosition = position;
4779 TableViewItemTag current;
4780 TableViewItemTag next;
4782 current.groupIndex = __expandableItemTag.groupIndex;
4783 current.itemIndex = __pListModel->GetItemCountInGroup(__expandableItemTag.groupIndex) -1;
4785 float screenPosition = GetScrollPosition();
4786 FloatRectangle screenBounds = __pTableView->GetBoundsF();
4787 screenPosition += screenBounds.height;
4789 _TableViewItem* pItem = null;
4790 while (GetNextItemPosition(current, next))
4792 if (screenPosition > itemPosition)
4794 pItem = LoadItem(next.groupIndex, next.itemIndex);
4798 pItem = FindItem(next);
4806 itemBounds = pItem->GetBoundsF();
4807 itemBounds.y = itemPosition;
4808 pItem->SetBounds(itemBounds);
4809 itemPosition += itemBounds.height;
4816 _TableViewPresenter::ExpandGroupAnimationFinished(bool completedNormally)
4818 if (completedNormally == false)
4820 TableViewItemTag current;
4821 TableViewItemTag next;
4823 current.groupIndex = __expandableItemTag.groupIndex;
4824 current.itemIndex = -1;
4826 _TableViewItem* pNextItem = null;
4827 _TableViewItem* pCurrentItem = null;
4828 pCurrentItem = LoadItem(current.groupIndex, current.itemIndex);
4830 if (pCurrentItem == null)
4835 FloatRectangle itemBounds;
4836 FloatRectangle screenBounds = __pTableView->GetBoundsF();
4837 float screenPosition = GetScrollPosition() + screenBounds.height;
4838 float nextItemPositionY = pCurrentItem->GetBoundsF().y + pCurrentItem->GetBoundsF().height;
4840 while (GetNextItemPosition(current, next))
4842 if (screenPosition >= nextItemPositionY)
4844 pCurrentItem = LoadItem(current.groupIndex, current.itemIndex);
4845 if (pCurrentItem == null)
4849 pNextItem = LoadItem(next.groupIndex, next.itemIndex);
4850 if (pNextItem == null)
4854 pNextItem->SetVisibleState(true);
4855 itemBounds = pNextItem->GetBoundsF();
4856 itemBounds.y = pCurrentItem->GetBoundsF().y + pCurrentItem->GetBoundsF().height;
4857 pNextItem->SetBounds(itemBounds);
4858 nextItemPositionY = itemBounds.y + itemBounds.height;
4862 UnloadItem(next.groupIndex, next.itemIndex);
4870 int currentGroupIndex = -1;
4871 int currentItemIndex = -1;
4872 GetBottomDrawnItemIndex(currentGroupIndex, currentItemIndex);
4874 int lastLoadedGroupIndex = -1;
4875 int lastLoadedItemIndex = -1;
4876 __pListModel->GetLastLoadedItemIndex(lastLoadedGroupIndex, lastLoadedItemIndex);
4878 TableViewItemTag current;
4879 current.groupIndex = currentGroupIndex;
4880 current.itemIndex = currentItemIndex;
4882 _TableViewItem* pCurrentItem;
4883 pCurrentItem = FindItem(current);
4884 if (pCurrentItem != null)
4886 pCurrentItem->SetVisibleState(true);
4889 for (int j = currentGroupIndex; j <= lastLoadedGroupIndex; j++)
4891 int itemCount = GetItemCountAt(j);
4893 for (int i = -1; i < itemCount; i++)
4895 if (i <= currentItemIndex && j == currentGroupIndex)
4907 _TableViewPresenter::CollapseGroupAnimationFinished(bool completedNormally)
4909 int itemCountInGroup = __pListModel->GetItemCountInGroup(__expandableItemTag.groupIndex);
4911 if (completedNormally == false)
4913 TableViewItemTag current;
4914 TableViewItemTag next;
4916 current.groupIndex = __expandableItemTag.groupIndex;
4917 current.itemIndex = -1;
4919 for (int i = 0; i < itemCountInGroup; i++)
4921 UnloadItem(__expandableItemTag.groupIndex, i);
4924 _TableViewItem* pCurrentItem = FindItem(current);
4925 if (pCurrentItem == null)
4927 SysTryReturnVoidResult(NID_UI_CTRL, pCurrentItem != null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.")
4930 FloatRectangle itemBounds;
4931 float nextItemPositionY = pCurrentItem->GetBoundsF().y + pCurrentItem->GetBoundsF().height;
4933 FloatRectangle screenBounds = __pTableView->GetBoundsF();
4934 float screenPosition = GetScrollPosition() + screenBounds.height;
4936 while (GetNextItemPosition(current, next))
4939 if (screenPosition >= nextItemPositionY)
4941 pCurrentItem = LoadItem(current.groupIndex, current.itemIndex);
4942 if (pCurrentItem == null)
4947 pCurrentItem->SetVisibleState(true);
4948 itemBounds = pCurrentItem->GetBoundsF();
4949 itemBounds.y = nextItemPositionY;
4950 pCurrentItem->SetBounds(itemBounds);
4951 nextItemPositionY = pCurrentItem->GetBoundsF().y + pCurrentItem->GetBoundsF().height;
4955 UnloadItem(current.groupIndex, current.itemIndex);
4961 int currentGroupIndex = -1;
4962 int currentItemIndex = -1;
4963 GetTopDrawnItemIndex(currentGroupIndex, currentItemIndex);
4965 int firstLoadedGroupIndex = -1;
4966 int firstLoadedItemIndex = -1;
4967 __pListModel->GetFirstLoadedItemIndex(firstLoadedGroupIndex, firstLoadedItemIndex);
4969 for (int j = firstLoadedGroupIndex; j <= currentGroupIndex; j++)
4971 int itemCount = GetItemCountAt(j);
4973 for (int i = -1; i < itemCount; i++)
4975 if (i >= currentItemIndex && j == currentGroupIndex)
4984 for (int i = 0; i < itemCountInGroup; i++)
4986 UnloadItem(__expandableItemTag.groupIndex, i);
4989 GetTopDrawnItemIndex(currentGroupIndex, currentItemIndex);
4990 TableViewItemTag currentItemTag;
4991 currentItemTag.groupIndex = currentGroupIndex;
4992 currentItemTag.itemIndex = currentItemIndex;
4994 _TableViewItem* pItem = FindItem(currentItemTag);
4997 FloatRectangle itemBounds = pItem->GetBoundsF();
4998 itemBounds.y = CalculateItemPositionY(currentGroupIndex, currentItemIndex);
4999 pItem->SetBounds(itemBounds);
5000 AttachNextItemsToBottom(currentItemTag);
5001 if (__expandableItemTag.groupIndex < currentGroupIndex)
5003 SetScrollPosition(itemBounds.y, false);
5008 float groupTotalHeight = 0;
5009 _TableViewItem* pItem = null;
5010 for (int i = 0; i < itemCountInGroup; i++)
5012 pItem = static_cast<_TableViewItem*>(__pListModel->GetItemFromTemporaryBuffer(__expandableItemTag.groupIndex, i));
5013 groupTotalHeight += pItem->GetItemHeight();
5016 AdjustClientAreaBounds(false, -groupTotalHeight);
5020 _TableViewPresenter::OnVisualElementAnimationStarted(const Tizen::Ui::Animations::VisualElementAnimation& animation, const Tizen::Base::String& keyName, Tizen::Ui::Animations::VisualElement& target)
5022 if (keyName == L"REMOVE_ITEM_ANIMATION")
5027 if (keyName == L"SCROLL_PANEL_SCROLLING_ANIMATION")
5029 __scrollHeightOnFlickStarted = GetScrollAreaBounds().height;
5030 __scrollPositionOnFlickStarted = GetScrollPosition();
5033 _ScrollPanelPresenter::OnVisualElementAnimationStarted(animation, keyName, target);
5037 _TableViewPresenter::OnVisualElementAnimationRepeated(const Tizen::Ui::Animations::VisualElementAnimation& animation, const Tizen::Base::String& keyName, Tizen::Ui::Animations::VisualElement& target, long currentRepeatCount)
5039 if (keyName == L"REMOVE_ITEM_ANIMATION")
5043 _ScrollPanelPresenter::OnVisualElementAnimationRepeated(animation, keyName, target, currentRepeatCount);
5047 _TableViewPresenter::OnVisualElementAnimationFinished(const Tizen::Ui::Animations::VisualElementAnimation& animation, const Tizen::Base::String& keyName, Tizen::Ui::Animations::VisualElement& target, bool completedNormally)
5049 if (__isAnimationCallbackBlocked)
5054 if (keyName == L"REMOVE_ITEM_ANIMATION")
5056 _VisualElement* pVisualElement = GetView()->GetVisualElement();
5058 pVisualElement->DetachChild(target);
5063 else if (keyName == L"EXPAND_GROUP_ANIMATION")
5065 if (__pCapturedItemVisualElement)
5067 __pCapturedItemVisualElement->SetShowState(false);
5069 ExpandGroupAnimationFinished(completedNormally);
5071 if (__scrollToItemTag.startedAnimation)
5073 __scrollToItemTag.startedAnimation = false;
5074 ScrollToItem(__scrollToItemTag.groupIndex, __scrollToItemTag.itemIndex, __scrollToItemTag.itemAlignment, __scrollToItemTag.shiftingDistance);
5078 else if (keyName == L"COLLAPSE_GROUP_ANIMATION")
5080 if (__pCapturedItemVisualElement)
5082 __pCapturedItemVisualElement->SetShowState(false);
5084 CollapseGroupAnimationFinished(completedNormally);
5086 if (__scrollToItemTag.startedAnimation)
5088 __scrollToItemTag.startedAnimation = false;
5089 ScrollToItem(__scrollToItemTag.groupIndex, __scrollToItemTag.itemIndex, __scrollToItemTag.itemAlignment, __scrollToItemTag.shiftingDistance);
5094 _ScrollPanelPresenter::OnVisualElementAnimationFinished(animation, keyName, target, completedNormally);
5098 _TableViewPresenter::OnTickOccurred(const Tizen::Ui::Animations::VisualElementAnimation& animation, const Tizen::Base::String& keyName, Tizen::Ui::Animations::VisualElement& target, const Tizen::Ui::Variant& currentValue)
5100 _VisualElement* pVisualElement = __pTableView->GetVisualElement();
5102 if (&target != pVisualElement)
5107 if (keyName == L"REMOVE_ITEM_ANIMATION")
5109 Dimension value = currentValue.ToDimension();
5110 target.SetOpacity(value.width);
5112 FloatRectangle bounds = target.GetBounds();
5113 bounds.height = value.height;
5114 target.SetBounds(bounds);
5116 target.SetFlushNeeded();
5120 else if (keyName == L"EXPAND_GROUP_ANIMATION")
5122 float currentPosition = currentValue.ToFloat();
5123 SetLoadedItemsVisibleFromPosition(currentPosition, true);
5124 MoveLoadedItemsFromPosition(currentPosition);
5128 else if (keyName == L"COLLAPSE_GROUP_ANIMATION")
5130 float currentPosition = currentValue.ToFloat();
5131 SetLoadedItemsVisibleFromPosition(currentPosition, false);
5132 MoveLoadedItemsFromPosition(currentPosition);
5136 else if (keyName == L"SWEEP_ITEM_ANIMATION")
5138 float currentPosition = currentValue.ToFloat();
5139 float moveDestance = currentPosition - __sweptItemPosition.x;
5140 SweepItem(moveDestance);
5145 _ScrollPanelPresenter::OnTickOccurred(animation, keyName, target, currentValue);
5149 _TableViewPresenter::OnAccessibilityItemRefreshed(const _AccessibilityContainer& control, const _AccessibilityElement& element, _AccessibilityFocusDirection direction)
5151 TableViewItemTag itemPos = {-1, -1};
5153 if (direction == _ACCESSIBILITY_FOCUS_DIRECTION_NEXT)
5155 GetFirstItem(itemPos);
5156 if (GetAccessibilityElementFocusedState() == false && FindItem(itemPos) == null)
5158 ScrollToItem(itemPos.groupIndex, itemPos.itemIndex, TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_TOP);
5163 else if (direction == _ACCESSIBILITY_FOCUS_DIRECTION_PREVIOUS)
5165 GetLastItem(itemPos);
5167 if (IsGroupExpanded(itemPos.groupIndex) == false)
5169 itemPos.itemIndex = -1;
5172 if (GetAccessibilityElementFocusedState() == false && FindItem(itemPos) == null)
5174 ScrollToItem(itemPos.groupIndex, itemPos.itemIndex, TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_BOTTOM);
5184 _TableViewPresenter::OnOcurredOverflowItems(const int currentCashSize, const int overflowCount)
5186 return IsCachingItemsTotalHeightLessThanViewHeight();
5190 _TableViewPresenter::GetAccessibilityElementFocusedState(void)
5192 _TableViewItem* pItem = null;
5193 TableViewItemTag itemPos = {-1, -1};
5194 TableViewItemTag lastItemPos = {-1, -1};
5196 __pListModel->GetFirstLoadedItemIndex(itemPos.groupIndex, itemPos.itemIndex);
5197 __pListModel->GetLastLoadedItemIndex(lastItemPos.groupIndex, lastItemPos.itemIndex);
5201 pItem = static_cast <_TableViewItem*>(__pListModel->LoadItem(itemPos.groupIndex, itemPos.itemIndex));
5202 SysTryReturn(NID_UI_CTRL, pItem != null, false, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The index is out of range.");
5204 _AccessibilityContainer* pContainer = pItem->GetAccessibilityContainer();
5205 _AccessibilityElement* pElement = null;
5207 if (pContainer != null)
5209 pElement = pContainer->GetCurrentFocusedElement();
5210 if (pElement != null)
5216 if ((itemPos.itemIndex == lastItemPos.itemIndex) && (itemPos.groupIndex == lastItemPos.groupIndex))
5221 } while (GetNextItemPosition(itemPos, itemPos) == true);
5227 _TableViewPresenter::FireItemTouchReleasedEventDuringPressing(int groupIndex, int itemIndex)
5229 TableViewItemTag fireItemPos;
5230 fireItemPos.groupIndex = groupIndex;
5231 fireItemPos.itemIndex = itemIndex;
5233 __itemTouchReleasedEventState = TABLE_VIEW_ITEM_TOUCH_RELEASED_EVENT_FIRE;
5234 _TableViewItem* pItem = FindItem(fireItemPos);
5237 pItem->FireItemTouchReleased();
5240 // for new item after UpdateTableView.
5241 pItem = FindItem(fireItemPos);
5244 if (__itemTouchReleasedEventState == TABLE_VIEW_ITEM_TOUCH_RELEASED_EVENT_UPDATE_TABLE_VIEW)
5246 __itemTouchReleasedEventState = TABLE_VIEW_ITEM_TOUCH_RELEASED_EVENT_NORMAL;
5250 pItem->SetSelectionState(true);
5251 pItem->FireItemTouchPressed();
5257 _TableViewSectionStringAlignment::operator== (const _TableViewSectionStringAlignment& rhs) const
5259 if (headerHorizontalAlignment == rhs.headerHorizontalAlignment && footerHorizontalAlignment == rhs.footerHorizontalAlignment)
5268 _TableViewSectionStringAlignment::operator!= (const _TableViewSectionStringAlignment& rhs) const
5270 if (headerHorizontalAlignment == rhs.headerHorizontalAlignment && footerHorizontalAlignment == rhs.footerHorizontalAlignment)
5278 }}} // Tizen::Ui::Controls