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"
39 #include "FUi_Window.h"
41 using namespace Tizen::Ui::Animations;
42 using namespace Tizen::Graphics;
43 using namespace Tizen::Base;
44 using namespace Tizen::Base::Runtime;
45 using namespace Tizen::Ui::Controls;
47 namespace Tizen { namespace Ui { namespace Controls
49 const float _TableViewPresenter::REORDER_SCROLL_ANIMATION_DISTANCE = 10.0f;
50 const float _TableViewPresenter::TABLEVIEW_DEFAULT_ITEM_HEIGHT_VALUE = 12.3456f;
52 _TableViewPresenter::_TableViewPresenter()
55 , __pProviderAdaptor(null)
57 , __bottomMargin(0.0f)
59 , __modelInitialized(false)
60 , __firstDrawnFlag(true)
61 , __statusChangedFlag(true)
63 , __pItemDrawingProperty(null)
64 , __pBaseVisualElement(null)
65 , __sweepOccured(false)
66 , __sweptItemPosition()
67 , __reservedScrollItemAlignment(TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_TOP)
68 , __firstTouchMoved(false)
69 , __pReorderScrollTimer(null)
71 , __itemTotalHeight(0.0f)
72 , __pCapturedItemVisualElement(null)
73 , __pFastScrollTimer(null)
74 , __isFastScrollTimerEnabled(false)
75 , __scrollHeightOnFlickStarted(0)
76 , __scrollPositionOnFlickStarted(0)
77 , __isAnimationCallbackBlocked(false)
78 , __lockLoadItemWithScroll(false)
79 , __itemTouchReleasedEventState(TABLE_VIEW_ITEM_TOUCH_RELEASED_EVENT_NORMAL)
82 __sweptItemTag.itemIndex = -1;
83 __sweptItemTag.groupIndex = -1;
85 __reservedScrollItemIndex.itemIndex = -1;
86 __reservedScrollItemIndex.groupIndex = -1;
88 __expandableItemTag.groupIndex = -1;
89 __expandableItemTag.itemIndex = -1;
92 _TableViewPresenter::~_TableViewPresenter()
98 _TableViewPresenter::GetView() const
104 _TableViewPresenter::GetModel(void) const
110 _TableViewPresenter::Initialize(_TableView* pTableView)
112 _ScrollPanelPresenter::Initialize(*pTableView);
114 __pTableView = pTableView;
115 __pBaseVisualElement = __pTableView->GetVisualElement();
116 __pBaseVisualElement->SetClipChildrenEnabled(true);
117 __pBaseVisualElement->SetSurfaceOpaque(false);
119 result r = __itemHeightList.Construct();
120 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, false, E_OUT_OF_MEMORY, ("[E_OUT_OF_MEMORY] The memory is insufficient."));
122 r = __sectionAlignmentList.Construct();
123 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, false, E_OUT_OF_MEMORY, ("[E_OUT_OF_MEMORY] The memory is insufficient."));
126 __pListModel = new (std::nothrow) _ListViewModel();
127 SysTryReturn(NID_UI_CTRL, __pListModel != null, false, E_OUT_OF_MEMORY, ("[E_OUT_OF_MEMORY] The memory is insufficient."));
128 __pListModel->SetListViewModelDelegate(this);
130 __pItemDrawingProperty = new (std::nothrow) _ItemDrawingProperty();
131 SysTryReturn(NID_UI_CTRL, __pItemDrawingProperty != null, false, E_OUT_OF_MEMORY, ("[E_OUT_OF_MEMORY] The memory is insufficient."));
134 __pFastScrollTimer = new (std::nothrow) Timer();
135 SysTryCatch(NID_UI_CTRL, __pFastScrollTimer != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
137 r = __pFastScrollTimer->Construct(*this);
138 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
143 if (__isFastScrollTimerEnabled)
145 __pFastScrollTimer->Cancel();
148 delete __pFastScrollTimer;
149 __pFastScrollTimer = null;
155 _TableViewPresenter::Construct(_TableView* pTableView)
157 result r = E_SUCCESS;
161 init = Initialize(pTableView);
162 SysTryCatch(NID_UI_CTRL, init == true, , r = GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
172 _TableViewPresenter::Dispose(void)
174 DeleteItemHeightList();
175 DeleteSectionAlignmentList();
176 DetachContextItem(__sweptItemTag);
181 delete __pProviderAdaptor;
182 __pProviderAdaptor = null;
184 delete __pItemDrawingProperty;
185 __pItemDrawingProperty = null;
187 delete __pReorderScrollTimer;
188 __pReorderScrollTimer = null;
190 if (__isFastScrollTimerEnabled)
192 __pFastScrollTimer->Cancel();
195 delete __pFastScrollTimer;
196 __pFastScrollTimer = null;
198 if (__pCapturedItemVisualElement)
200 GetView()->GetVisualElement()->DetachChild(*__pCapturedItemVisualElement);
201 __pCapturedItemVisualElement->Destroy();
203 __pCapturedItemVisualElement = null;
207 _TableViewPresenter::SetItemProvider(const _TableViewItemProvider* pProvider)
209 result r = E_SUCCESS;
211 _TableViewItemProviderAdaptor* pProviderAdaptor = static_cast <_TableViewItemProviderAdaptor*>(__pListModel->GetItemProviderAdaptor());
212 if(pProviderAdaptor != null)
214 _TableViewItemProvider* provider = pProviderAdaptor->GetItemProvider();
215 if(provider != null && provider == pProvider)
221 if (pProviderAdaptor == null)
223 pProviderAdaptor = new (std::nothrow) _TableViewItemProviderAdaptor();
224 SysTryReturn(NID_UI_CTRL, pProviderAdaptor != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, ("[E_OUT_OF_MEMORY] The memory is insufficient."));
226 SetTableViewItemProviderAdaptor(pProviderAdaptor);
229 _TableViewItemProvider* pNewProvider = null;
231 if (pProvider != null)
233 pNewProvider = const_cast <_TableViewItemProvider*>(pProvider);
237 __pListModel->RemoveAllItem(false);
240 pProviderAdaptor->SetItemProvider(pNewProvider);
241 pProviderAdaptor->SetListWidth(__pTableView->GetBoundsF().width - (GetLeftMargin() * 2));
242 pProviderAdaptor->SetTableViewStyle(__pTableView->GetTableViewStyle());
248 _TableViewPresenter::GetItemFromPosition(const Tizen::Graphics::FloatPoint& position, TableViewItemTag& itemPos) const
250 _TableViewItem* pItem = null;
251 TableViewItemTag lastItemPos = {-1, -1};
253 __pListModel->GetFirstLoadedItemIndex(itemPos.groupIndex, itemPos.itemIndex);
254 __pListModel->GetLastLoadedItemIndex(lastItemPos.groupIndex, lastItemPos.itemIndex);
258 pItem = static_cast <_TableViewItem*>(__pListModel->LoadItem(itemPos.groupIndex, itemPos.itemIndex));
259 SysTryCatch(NID_UI_CTRL, pItem != null, , E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The index is out of range.");
261 FloatRectangle itemBounds = pItem->GetBoundsF();
262 if (itemBounds.Contains(position))
267 if ((itemPos.itemIndex == lastItemPos.itemIndex) && (itemPos.groupIndex == lastItemPos.groupIndex))
272 } while (GetNextItemPosition(itemPos, itemPos));
275 itemPos.itemIndex = -1;
276 itemPos.groupIndex = -1;
278 return E_OUT_OF_RANGE;
282 _TableViewPresenter::GetTopDrawnItemIndex(int& groupIndex, int& itemIndex) const
284 result r = E_SUCCESS;
286 TableViewItemTag itemPos;
287 r = GetTopDrawnItem(itemPos);
289 groupIndex = itemPos.groupIndex;
290 itemIndex = itemPos.itemIndex;
296 _TableViewPresenter::SetTopDrawnItemIndex(int groupIndex, int itemIndex)
300 return E_INVALID_ARG;
303 if ((groupIndex < 0) || (groupIndex >= GetGroupCount()) || (itemIndex < -1) || (itemIndex >= GetItemCountAt(groupIndex)))
305 return E_OUT_OF_RANGE;
308 ScrollToItem(groupIndex, itemIndex, TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_TOP);
314 _TableViewPresenter::GetBottomDrawnItemIndex(int& groupIndex, int& itemIndex) const
316 result r = E_SUCCESS;
318 TableViewItemTag itemPos;
319 r = GetBottomDrawnItem(itemPos);
321 groupIndex = itemPos.groupIndex;
322 itemIndex = itemPos.itemIndex;
328 _TableViewPresenter::SetBottomDrawnItemIndex(int groupIndex, int itemIndex)
332 return E_INVALID_ARG;
335 if ((groupIndex < 0) || (groupIndex >= GetGroupCount()) || (itemIndex < -1) || (itemIndex >= GetItemCountAt(groupIndex)))
337 return E_OUT_OF_RANGE;
340 ScrollToItem(groupIndex, itemIndex, TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_BOTTOM);
346 _TableViewPresenter::GetGroupCount(void) const
348 return __pListModel->GetAllGroupCount();
353 _TableViewPresenter::GetItemCountAt(int groupIndex) const
355 return __pListModel->GetItemCountInGroup(groupIndex);
359 _TableViewPresenter::HasSectionHeader(int groupIndex) const
361 if (__pProviderAdaptor == null || __pTableView->GetTableViewStyle() != TABLE_VIEW_STYLE_SECTION)
366 return __pProviderAdaptor->HasSectionHeader(groupIndex);
370 _TableViewPresenter::HasSectionFooter(int groupIndex) const
372 if (__pProviderAdaptor == null || __pTableView->GetTableViewStyle() != TABLE_VIEW_STYLE_SECTION)
377 return __pProviderAdaptor->HasSectionFooter(groupIndex);
381 _TableViewPresenter::GetItemCount(void) const
383 return __pListModel->GetAllItemCount();
387 _TableViewPresenter::RefreshTableView(int groupIndex, int itemIndex, TableViewRefreshType type, bool animation)
389 _TableViewItemProviderAdaptor* pProviderAdaptor = __pProviderAdaptor;
391 SysTryReturn(NID_UI_CTRL, pProviderAdaptor != null, E_INVALID_STATE, E_INVALID_STATE,
392 ("[E_INVALID_STATE] This instance isn't constructed."));
394 if ((groupIndex < 0) || (groupIndex > GetGroupCount()) || (itemIndex < -1) || (itemIndex > GetItemCountAt(groupIndex)))
396 SysLogException(NID_UI_CTRL, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The index is out of range.");
397 return E_OUT_OF_RANGE;
400 if (groupIndex == GetGroupCount() && itemIndex != -1 && type != TABLE_VIEW_REFRESH_TYPE_ITEM_ADD)
402 SysLogException(NID_UI_CTRL, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The index is out of range.");
403 return E_OUT_OF_RANGE;
406 TableViewItemTag topDrawnItemPos = {-1, -1};
407 TableViewItemTag refreshItemPos = {groupIndex, itemIndex};
408 float prevScrollAreaHeight = GetScrollAreaBounds().height;
409 float prevScrollPosition = GetScrollPosition();
411 GetTopDrawnItem(topDrawnItemPos);
417 case TABLE_VIEW_REFRESH_TYPE_ITEM_ADD:
420 bool emptyState = IsEmpty();
422 int itemCount = pProviderAdaptor->GetItemCount(groupIndex);
423 if (__pListModel->InsertGroup(groupIndex, itemCount, false) != E_SUCCESS)
425 SysLogException(NID_UI_CTRL, E_SYSTEM, "[E_SYSTEM] Unable to add Group item.");
431 GetFirstItem(topDrawnItemPos);
433 else if (groupIndex <= topDrawnItemPos.groupIndex)
435 topDrawnItemPos.groupIndex++;
440 bool emptyState = IsEmpty();
442 if (__pListModel->InsertItemToGroup(null, groupIndex, itemIndex) != E_SUCCESS)
444 SysLogException(NID_UI_CTRL, E_SYSTEM, "[E_SYSTEM] Unable to add item.");
450 GetFirstItem(topDrawnItemPos);
454 RefreshItemHeightList(groupIndex, itemIndex, TABLE_VIEW_REFRESH_TYPE_ITEM_ADD);
455 RefreshSectionAlignmentList(groupIndex, TABLE_VIEW_REFRESH_TYPE_ITEM_ADD);
457 if (__pListModel->GetAllItemCount() == 1)
459 SetStatusChanged(true);
464 case TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE:
467 if (groupIndex == GetGroupCount())
469 SysLogException(NID_UI_CTRL, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The index is out of range.");
470 return E_OUT_OF_RANGE;
473 RefreshItemHeightList(groupIndex, itemIndex, TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE);
474 RefreshSectionAlignmentList(groupIndex, TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE);
476 if (__pListModel->RemoveGroup(groupIndex) != E_SUCCESS)
478 SysLogException(NID_UI_CTRL, E_SYSTEM, "[E_SYSTEM] Unable to remove group.");
482 if (groupIndex < topDrawnItemPos.groupIndex)
484 topDrawnItemPos.groupIndex--;
487 if ((groupIndex == topDrawnItemPos.groupIndex) && (GetItemCountAt(groupIndex) < topDrawnItemPos.itemIndex))
489 topDrawnItemPos.itemIndex = -1;
494 if (itemIndex == GetItemCountAt(groupIndex))
496 SysLogException(NID_UI_CTRL, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The index is out of range.");
497 return E_OUT_OF_RANGE;
500 if (__pListModel->RemoveItemAt(groupIndex, itemIndex) != E_SUCCESS)
502 SysLogException(NID_UI_CTRL, E_SYSTEM, "[E_SYSTEM] Unable to remove item.");
506 if ((groupIndex == topDrawnItemPos.groupIndex) && (itemIndex < topDrawnItemPos.itemIndex))
508 GetPreviousItemPosition(topDrawnItemPos, topDrawnItemPos);
511 RefreshItemHeightList(groupIndex, itemIndex, TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE);
514 if (GetModel()->IsValidItem(topDrawnItemPos.groupIndex, topDrawnItemPos.itemIndex) == false)
516 GetPreviousItemPosition(topDrawnItemPos, topDrawnItemPos);
519 if (__pListModel->GetAllItemCount() == 0)
521 SetStatusChanged(true);
526 case TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY:
528 TableViewItemTag itemTag = {groupIndex, itemIndex};
529 _TableViewItem* pTableViewItem = FindItem(itemTag);
531 if (pTableViewItem == null)
536 if (pProviderAdaptor->UpdateItem(pTableViewItem, itemTag.groupIndex, itemTag.itemIndex))
538 FloatRectangle itemBounds = pTableViewItem->GetBoundsF();
539 FloatDimension itemDim = Tizen::Graphics::CoordinateSystem::AlignToDevice(FloatDimension(itemBounds.width, itemBounds.height));
540 itemBounds.height = itemDim.height;
541 pTableViewItem->SetBounds(itemBounds);
543 CheckItemHeightAndRefreshLayout(itemTag, true);
545 if (__sweptItemTag.groupIndex != itemTag.groupIndex || __sweptItemTag.itemIndex != itemTag.itemIndex)
550 pTableViewItem->SetItemChanged(true);
551 pTableViewItem->Invalidate();
552 pTableViewItem->AdjustContextItemBounds();
560 SysLogException(NID_UI_CTRL, E_SYSTEM, "[E_SYSTEM] Unable to refresh list.");
565 __lockLoadItemWithScroll = true;
567 AdjustClientAreaBounds(true);
569 __lockLoadItemWithScroll = false;
571 if ((topDrawnItemPos.groupIndex > refreshItemPos.groupIndex)
572 ||((topDrawnItemPos.groupIndex == refreshItemPos.groupIndex)&&(topDrawnItemPos.itemIndex > refreshItemPos.itemIndex)))
574 RefreshItemLayout(topDrawnItemPos, refreshItemPos, type, false);
576 float newScrollPosition = prevScrollPosition - (prevScrollAreaHeight - GetScrollAreaBounds().height);
578 __lockLoadItemWithScroll = true;
580 SetScrollPosition(newScrollPosition, false);
582 __lockLoadItemWithScroll = false;
586 RefreshItemLayout(topDrawnItemPos, refreshItemPos, type, animation);
593 _TableViewPresenter::RefreshAllItems(void)
595 result r = E_SUCCESS;
596 TableViewItemTag itemTag = {-1, -1};
597 TableViewItemTag lastLoadedItemTag = {-1, -1};
599 __pListModel->GetLastLoadedItemIndex(lastLoadedItemTag.groupIndex, lastLoadedItemTag.itemIndex);
600 __pListModel->GetFirstLoadedItemIndex(itemTag.groupIndex, itemTag.itemIndex);
604 _TableViewItem* pItem = FindItem(itemTag);
611 r = RefreshTableView(itemTag.groupIndex, itemTag.itemIndex, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY, false);
612 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
614 if ((itemTag.itemIndex == lastLoadedItemTag.itemIndex) && (itemTag.groupIndex == lastLoadedItemTag.groupIndex))
618 } while (GetNextItemPosition(itemTag, itemTag));
624 _TableViewPresenter::UpdateTableView(void)
626 _VisualElement* pVisualElement = __pTableView->GetVisualElement();
628 if (pVisualElement != null)
630 __pTableView->GetVisualElement()->RemoveAllAnimations();
634 if (__modelInitialized == false)
636 SetItemDrawingProperty();
638 if(PreloadItem() == false)
647 __pListModel->RemoveAllItem(false, false);
653 TableViewItemTag topDrawnTag = {-1, -1};
654 float shiftingDistance = 0;
658 GetTopDrawnItem(topDrawnTag);
660 if (__pListModel->IsValidItem(topDrawnTag.groupIndex, topDrawnTag.itemIndex))
662 _TableViewItem* pItem = FindItem(topDrawnTag);
666 shiftingDistance = GetScrollPosition() - pItem->GetBoundsF().y;
670 __pListModel->RemoveAllItem(false, true);
672 PreloadItem(topDrawnTag.groupIndex, topDrawnTag.itemIndex, shiftingDistance);
674 __statusChangedFlag = true;
676 if (__itemTouchReleasedEventState == TABLE_VIEW_ITEM_TOUCH_RELEASED_EVENT_FIRE)
678 __itemTouchReleasedEventState = TABLE_VIEW_ITEM_TOUCH_RELEASED_EVENT_UPDATE_TABLE_VIEW;
687 _TableViewPresenter::AdjustLayoutItems(float scrollPosition)
689 TableViewItemTag lastLoadedItemPos = {-1, -1};
690 TableViewItemTag firstLoadedItemPos = {-1, -1};
691 TableViewItemTag currentItemPos = {-1, -1};
692 _TableViewItem* pItem = null;
694 __pListModel->GetFirstLoadedItemIndex(firstLoadedItemPos.groupIndex, firstLoadedItemPos.itemIndex);
695 __pListModel->GetLastLoadedItemIndex(lastLoadedItemPos.groupIndex, lastLoadedItemPos.itemIndex);
697 pItem = FindItem(firstLoadedItemPos);
701 float positionY = pItem->GetPositionF().y;
703 currentItemPos = firstLoadedItemPos;
705 while (!_FloatCompareLE(positionY, scrollPosition) && GetPreviousItemPosition(currentItemPos, currentItemPos))
707 pItem = LoadItem(currentItemPos.groupIndex, currentItemPos.itemIndex);
714 positionY = pItem->GetPositionF().y;
718 pItem = FindItem(lastLoadedItemPos);
722 float positionY = pItem->GetPositionF().y;
723 float itemHeight = pItem->GetBoundsF().height;
724 float limitScreenArea = scrollPosition + __pTableView->GetBoundsF().height;
725 currentItemPos = lastLoadedItemPos;
727 while ((positionY + itemHeight < limitScreenArea) && GetNextItemPosition(currentItemPos, currentItemPos))
729 pItem = LoadItem(currentItemPos.groupIndex, currentItemPos.itemIndex);
736 positionY = pItem->GetPositionF().y;
737 itemHeight = pItem->GetBoundsF().height;
743 _TableViewPresenter::ResetItemLayout(TableViewItemTag& topDrawnItemTag, float shiftingDistance)
745 if (__pListModel->IsValidItem(topDrawnItemTag.groupIndex, topDrawnItemTag.itemIndex) == false)
752 _TableViewItem* pItem = LoadItem(topDrawnItemTag.groupIndex, topDrawnItemTag.itemIndex);
759 TableViewItemTag currentItem = topDrawnItemTag;
760 TableViewItemTag itemPos = topDrawnItemTag;
761 float screenAreaHeight = __pTableView->GetBoundsF().height + shiftingDistance;
762 float loadedItemTotalHeight = 0.0f;
763 FloatRectangle itemBounds = pItem->GetBoundsF();
765 itemBounds.y = CalculateItemPositionY(itemPos.groupIndex, itemPos.itemIndex);
766 pItem->SetBounds(itemBounds);
767 CheckItemHeightAndRefreshLayout(itemPos, true);
769 loadedItemTotalHeight += itemBounds.height;
771 while (loadedItemTotalHeight < screenAreaHeight && GetNextItemPosition(currentItem, itemPos))
773 pItem = LoadItem(itemPos.groupIndex, itemPos.itemIndex);
780 currentItem = itemPos;
781 loadedItemTotalHeight += pItem->GetBoundsF().height;
784 if (loadedItemTotalHeight < screenAreaHeight)
786 __pListModel->GetFirstLoadedItemIndex(itemPos.groupIndex, itemPos.itemIndex);
787 currentItem = itemPos;
789 while (loadedItemTotalHeight < screenAreaHeight && GetPreviousItemPosition(currentItem, itemPos))
791 pItem = LoadItem(itemPos.groupIndex, itemPos.itemIndex);
798 currentItem = itemPos;
799 loadedItemTotalHeight += pItem->GetBoundsF().height;
805 _TableViewPresenter::IsCachingItemsTotalHeightLessThanViewHeight(void)
807 int currentCachingsize = GetMaxItemCachingSize();
808 int loadedItemCount = 0;
809 float itemTotalHeight = 0.0f;
810 float viewHeight = __pTableView->GetBoundsF().height;
811 float lastItemHeight = 0.0f;
813 TableViewItemTag lastLoadedItemPos = {-1, -1};
814 TableViewItemTag firstLoadedItemPos = {-1, -1};
816 __pListModel->GetFirstLoadedItemIndex(firstLoadedItemPos.groupIndex, firstLoadedItemPos.itemIndex);
817 __pListModel->GetLastLoadedItemIndex(lastLoadedItemPos.groupIndex, lastLoadedItemPos.itemIndex);
821 _TableViewItem* pItem = FindItem(firstLoadedItemPos);
825 itemTotalHeight = itemTotalHeight + pItem->GetSizeF().height;
826 lastItemHeight = pItem->GetSizeF().height;
830 if ((firstLoadedItemPos.itemIndex == lastLoadedItemPos.itemIndex) && (firstLoadedItemPos.groupIndex == lastLoadedItemPos.groupIndex))
834 } while (GetNextItemPosition(firstLoadedItemPos, firstLoadedItemPos));
836 if (loadedItemCount < currentCachingsize || viewHeight < (itemTotalHeight - lastItemHeight))
845 _TableViewPresenter::GetFirstLoadedItemIndex(int& groupIndex, int& itemIndex) const
847 __pListModel->GetFirstLoadedItemIndex(groupIndex, itemIndex);
851 _TableViewPresenter::GetLastLoadedItemIndex(int& groupIndex, int& itemIndex) const
853 __pListModel->GetLastLoadedItemIndex(groupIndex, itemIndex);
857 _TableViewPresenter::RefreshItemLayout(int groupIndex, int itemIndex)
859 TableViewItemTag itemTag = {groupIndex, itemIndex};
863 RefreshItemLayout(itemTag, itemTag, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY, false);
867 _TableViewPresenter::RefreshItemLayout(TableViewItemTag& topDrawnItemTag, TableViewItemTag& refreshItemTag, TableViewRefreshType type, bool animation)
869 if (!__pListModel->IsValidItem(topDrawnItemTag.groupIndex, topDrawnItemTag.itemIndex))
874 if (refreshItemTag.itemIndex == -1)
879 _TableViewItem* pItem = null;
881 TableViewItemTag itemPos = {-1, -1};
882 TableViewItemTag currentItem = {-1, -1};
884 int loadItemCount = 0;
885 int maxLoadItemCount = GetMaxItemCachingSize();
886 FloatRectangle itemBounds(0.0f, 0.0f, 0.0f, 0.0f);
888 StopAllItemAnimation();
890 __pListModel->GetFirstLoadedItemIndex(itemPos.groupIndex, itemPos.itemIndex);
892 if (itemPos.groupIndex == -1 && itemPos.itemIndex == -1)
894 itemPos = topDrawnItemTag;
897 currentItem = itemPos;
899 float itemPositionY = CalculateItemPositionY(itemPos.groupIndex, itemPos.itemIndex);
903 pItem = LoadItem(itemPos.groupIndex, itemPos.itemIndex);
910 if (pItem->HasParent())
912 pItem->SetDrawingProperty(__pItemDrawingProperty);
913 SetItemType(pItem, itemPos);
916 itemBounds = pItem->GetBoundsF();
917 itemBounds.y = itemPositionY;
921 if (type == TABLE_VIEW_REFRESH_TYPE_ITEM_ADD)
923 if (itemPos.groupIndex == refreshItemTag.groupIndex && itemPos.itemIndex == refreshItemTag.itemIndex)
925 pItem->SetBounds(itemBounds);
926 pItem->FadeInOutItem(false, ADD_ITEM_ANIMATION_DURATION, REFRESH_ITEM_ANIMATION_DELAY);
927 pItem->ZoomInOutItem(false, ADD_ITEM_ANIMATION_DURATION, REFRESH_ITEM_ANIMATION_DELAY);
931 if (!pItem->MoveItem(FloatPoint(itemBounds.x, itemBounds.y), ADD_ITEM_ANIMATION_DURATION, 0))
933 pItem->SetBounds(itemBounds);
939 if (!pItem->MoveItem(FloatPoint(itemBounds.x, itemBounds.y), REMOVE_ITEM_MOVE_ANIMATION_DURATION, REFRESH_ITEM_ANIMATION_DELAY))
941 pItem->SetBounds(itemBounds);
947 pItem->SetBounds(itemBounds);
950 currentItem = itemPos;
951 itemPositionY = itemBounds.y + itemBounds.height;
955 } while (loadItemCount < maxLoadItemCount && GetNextItemPosition(currentItem, itemPos));
957 if (loadItemCount < maxLoadItemCount)
959 __pListModel->GetFirstLoadedItemIndex(itemPos.groupIndex, itemPos.itemIndex);
960 currentItem = itemPos;
962 while (loadItemCount < maxLoadItemCount && GetPreviousItemPosition(currentItem, itemPos))
964 pItem = LoadItem(itemPos.groupIndex, itemPos.itemIndex);
971 currentItem = itemPos;
977 if (refreshItemTag.itemIndex == -1)
979 ScrollToItem(topDrawnItemTag.groupIndex, topDrawnItemTag.itemIndex, TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_TOP);
984 _TableViewPresenter::RefreshItemBounds(_TableViewItem* pItem, TableViewItemTag& itemPos)
986 FloatRectangle itemBounds;
993 itemBounds = pItem->GetBoundsF();
995 itemBounds.y = CalculateItemPositionY(itemPos.groupIndex, itemPos.itemIndex);
997 if (itemPos.itemIndex != -1)
999 float itemMargin = GetLeftMargin();
1000 itemBounds.x = itemMargin;
1001 itemBounds.width = __pItemDrawingProperty->width - itemBounds.x - itemMargin;
1005 itemBounds.x = 0.0f;
1006 itemBounds.width = __pItemDrawingProperty->width;
1009 pItem->SetBounds(itemBounds);
1013 _TableViewPresenter::GetItemIndexFromPosition(const FloatPoint& position, int& groupIndex, int& itemIndex) const
1015 result r = E_SUCCESS;
1016 TableViewItemTag itemPos;
1018 FloatPoint targetPosition = position;
1019 float scrollPosition = GetScrollPosition();
1020 targetPosition.y += scrollPosition;
1022 r = GetItemFromPosition(targetPosition, itemPos);
1031 groupIndex = itemPos.groupIndex;
1032 itemIndex = itemPos.itemIndex;
1039 _TableViewPresenter::PreloadItem(void)
1041 if (GetModel() == null || __pProviderAdaptor == null)
1046 __modelInitialized = true;
1048 if (__pListModel->GetAllGroupCount() == 0 && (__pProviderAdaptor != null))
1051 int groupCount = __pProviderAdaptor->GetGroupCount();
1053 for (int i = 0; i < groupCount; i++)
1055 itemCount = __pProviderAdaptor->GetItemCount(i);
1056 __pListModel->AddGroup(itemCount, false);
1060 __pListModel->RestoreItemStatus();
1062 CreateItemHeightList(TABLEVIEW_DEFAULT_ITEM_HEIGHT_VALUE, TABLEVIEW_DEFAULT_ITEM_HEIGHT_VALUE);
1063 CreateSectionAlignmentList();
1065 int cachingSize = 0;
1067 if (GetItemCount() > TABLEVIEW_MAX_ITEM_COUNT)
1069 cachingSize = TABLEVIEW_MAX_ITEM_COUNT;
1071 else if (__pListModel->GetMaxCachingSize() < TABLEVIEW_MAX_ITEM_COUNT)
1073 cachingSize = __pListModel->GetMaxCachingSize();
1077 cachingSize = GetItemCount();
1080 TableViewItemTag itemPos = {-1, -1};
1081 GetFirstItem(itemPos);
1083 _TableViewItem* pItem = null;
1084 for (int i = 0; i < cachingSize; i++)
1086 pItem = LoadItem(itemPos.groupIndex, itemPos.itemIndex);
1093 if (GetNextItemPosition(itemPos, itemPos) == false)
1099 if (IsCachingItemsTotalHeightLessThanViewHeight())
1101 AdjustLayoutItems(0.0f);
1104 PresetItemHeightList();
1105 AdjustClientAreaBounds(true);
1107 TableViewScrollBarStyle scrollStyle = __pTableView->GetScrollStyle();
1109 if (scrollStyle == TABLE_VIEW_SCROLL_BAR_STYLE_FAST_SCROLL
1110 || scrollStyle == TABLE_VIEW_SCROLL_BAR_STYLE_FAST_SCROLL_FIXED)
1112 _FastScroll* pFastScroll = __pTableView->GetFastScrollBar();
1113 if (pFastScroll != null)
1115 pFastScroll->UpdateIndex();
1116 pFastScroll->SetScrollVisibility(IsScrollable());
1119 else if (scrollStyle != TABLE_VIEW_SCROLL_BAR_STYLE_NONE)
1131 _TableViewPresenter::PreloadItem(int topDrawnGroupIndex, int topDrawnItemIndex, float shiftingDistance)
1133 if (GetModel() == null || __pProviderAdaptor == null)
1138 __modelInitialized = true;
1140 if (__pListModel->GetAllGroupCount() == 0 && (__pProviderAdaptor != null))
1143 int groupCount = __pProviderAdaptor->GetGroupCount();
1145 for (int i = 0; i < groupCount; i++)
1147 itemCount = __pProviderAdaptor->GetItemCount(i);
1148 __pListModel->AddGroup(itemCount, false);
1152 float defaultGroupHeight = __pProviderAdaptor->GetDefaultGroupItemHeight();
1153 float defaultItemHeight = __pProviderAdaptor->GetDefaultItemHeight();
1155 if (_FloatCompareLE(defaultGroupHeight, 0.0f))
1157 defaultGroupHeight = TABLEVIEW_DEFAULT_ITEM_HEIGHT_VALUE;
1160 if (_FloatCompareLE(defaultItemHeight, 0.0f))
1162 defaultItemHeight = TABLEVIEW_DEFAULT_ITEM_HEIGHT_VALUE;
1165 __pListModel->RestoreItemStatus();
1167 DeleteItemHeightList();
1168 CreateItemHeightList(defaultGroupHeight, defaultItemHeight);
1170 DeleteSectionAlignmentList();
1171 CreateSectionAlignmentList();
1173 if (!__pListModel->IsValidItem(topDrawnGroupIndex, topDrawnItemIndex))
1175 TableViewItemTag firstItemTag = {-1, -1};
1177 GetFirstItem(firstItemTag);
1179 topDrawnGroupIndex = firstItemTag.groupIndex;
1180 topDrawnItemIndex = firstItemTag.itemIndex;
1182 shiftingDistance = 0.0f;
1185 AdjustClientAreaBounds(true);
1187 ScrollToItem(topDrawnGroupIndex, topDrawnItemIndex, TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_TOP, shiftingDistance);
1189 if (IsCachingItemsTotalHeightLessThanViewHeight())
1191 AdjustLayoutItems(GetScrollPosition());
1194 if (__pTableView->GetScrollStyle() == TABLE_VIEW_SCROLL_BAR_STYLE_FAST_SCROLL
1195 || __pTableView->GetScrollStyle() == TABLE_VIEW_SCROLL_BAR_STYLE_FAST_SCROLL_FIXED)
1197 _FastScroll* pFastScroll = __pTableView->GetFastScrollBar();
1198 if (pFastScroll != null)
1200 pFastScroll->UpdateIndex();
1201 pFastScroll->SetScrollVisibility(IsScrollable());
1209 _TableViewPresenter::IsItemChecked(int groupIndex, int itemIndex) const
1211 if ((groupIndex < 0) || (groupIndex >= GetGroupCount()) || (itemIndex < -1) || (itemIndex >= GetItemCountAt(groupIndex)))
1216 return __pListModel->IsItemChecked(groupIndex, itemIndex);
1220 _TableViewPresenter::SetItemChecked(int groupIndex, int itemIndex, bool checked)
1222 if ((groupIndex < 0) || (groupIndex >= GetGroupCount()) || (itemIndex < -1) || (itemIndex >= GetItemCountAt(groupIndex)))
1224 return E_OUT_OF_RANGE;
1227 if (__modelInitialized == false)
1229 return E_INVALID_STATE;
1232 bool enabled = __pListModel->IsItemEnabled(groupIndex, itemIndex);
1233 SysTryReturn(NID_UI_CTRL, (enabled == true), E_INVALID_OPERATION, E_INVALID_OPERATION,
1234 "[E_INVALID_OPERATION] The item is disabled.");
1236 if (__pListModel->IsItemChecked(groupIndex, itemIndex) == checked)
1241 TableViewItemTag itemTag = {groupIndex, itemIndex};
1242 _TableViewItem *pItem = FindItem(itemTag);
1245 pItem->SetCheckedAnimationEnabled(checked);
1248 result r = __pListModel->SetItemChecked(groupIndex, itemIndex, checked);
1254 _TableViewPresenter::IsItemEnabled(int groupIndex, int itemIndex) const
1256 if ((groupIndex < 0) || (groupIndex >= GetGroupCount()) || (itemIndex < -1) || (itemIndex >= GetItemCountAt(groupIndex)))
1261 return __pListModel->IsItemEnabled(groupIndex, itemIndex);
1265 _TableViewPresenter::SetItemEnabled(int groupIndex, int itemIndex, bool enabled)
1267 if ((groupIndex < 0) || (groupIndex >= GetGroupCount()) || (itemIndex < -1) || (itemIndex >= GetItemCountAt(groupIndex)))
1269 return E_OUT_OF_RANGE;
1272 if (__pListModel->IsItemEnabled(groupIndex, itemIndex) == enabled)
1277 result r = __pListModel->SetItemEnabled(groupIndex, itemIndex, enabled);
1283 _TableViewPresenter::SetStatusChanged(bool changed)
1285 __statusChangedFlag = changed;
1287 if (__statusChangedFlag == true)
1289 SetItemDrawingProperty();
1291 if ((__pItemDrawingProperty != null) && (__pItemDrawingProperty->propertyChanged == true))
1293 __pListModel->SetAllLoadedItemStateChanged(true);
1301 _TableViewPresenter::IsStatusChanged(void) const
1303 return __statusChangedFlag;
1307 _TableViewPresenter::GetTopMargin(void) const
1313 _TableViewPresenter::SetTopMargin(float topMargin)
1315 __topMargin = topMargin;
1321 _TableViewPresenter::GetBottomMargin(void) const
1323 return __bottomMargin;
1327 _TableViewPresenter::SetBottomMargin(float bottomMargin)
1329 __bottomMargin = bottomMargin;
1335 _TableViewPresenter::GetLeftMargin(void) const
1337 return __leftMargin;
1341 _TableViewPresenter::SetLeftMargin(float leftMargin)
1343 __leftMargin = leftMargin;
1349 _TableViewPresenter::SetItemType(_TableViewItem* pItem, TableViewItemTag itemPosition)
1351 TableViewStyle style = __pTableView->GetTableViewStyle();
1353 if (itemPosition.itemIndex == -1)
1355 if (style == TABLE_VIEW_STYLE_SECTION)
1357 pItem->SetItemType(TABLE_VIEW_ITEM_TYPE_HEADER);
1361 pItem->SetItemType(TABLE_VIEW_ITEM_TYPE_TITLE);
1366 int itemCount = GetItemCountAt(itemPosition.groupIndex);
1367 if (style == TABLE_VIEW_STYLE_SIMPLE)
1369 if (itemCount == 1 || (itemCount > 1 && (itemPosition.itemIndex == itemCount - 1)))
1371 pItem->SetSimpleLastItemEnabled(true);
1375 pItem->SetSimpleLastItemEnabled(false);
1379 if (itemPosition.itemIndex == 0)
1381 if (HasSectionFooter(itemPosition.groupIndex))
1385 pItem->SetItemType(TABLE_VIEW_ITEM_TYPE_FOOTER);
1387 else if (itemCount == 2)
1389 pItem->SetItemType(TABLE_VIEW_ITEM_TYPE_ONE);
1393 pItem->SetItemType(TABLE_VIEW_ITEM_TYPE_TOP);
1400 pItem->SetItemType(TABLE_VIEW_ITEM_TYPE_ONE);
1404 pItem->SetItemType(TABLE_VIEW_ITEM_TYPE_TOP);
1410 int lastItemIndex = itemCount - 1;
1412 if (HasSectionFooter(itemPosition.groupIndex))
1414 if (itemPosition.itemIndex == lastItemIndex)
1416 pItem->SetItemType(TABLE_VIEW_ITEM_TYPE_FOOTER);
1418 else if (itemPosition.itemIndex == lastItemIndex - 1)
1420 pItem->SetItemType(TABLE_VIEW_ITEM_TYPE_BOTTOM);
1424 pItem->SetItemType(TABLE_VIEW_ITEM_TYPE_MIDDLE);
1429 if (itemPosition.itemIndex == lastItemIndex)
1431 pItem->SetItemType(TABLE_VIEW_ITEM_TYPE_BOTTOM);
1435 pItem->SetItemType(TABLE_VIEW_ITEM_TYPE_MIDDLE);
1443 _TableViewPresenter::SetItemLayout(_TableViewItem* pItem, TableViewItemTag& itemPos)
1445 _TableViewItem* pSeriesItem = null;
1446 TableViewItemTag seriesItemPos = {-1, -1};
1447 FloatRectangle seriesItemBounds;
1448 FloatRectangle itemBounds;
1449 bool validBounds = false;
1450 bool downScroll = true;
1452 if (itemPos.itemIndex == -1 && __pTableView->GetTableViewStyle() != TABLE_VIEW_STYLE_SECTION)
1455 itemBounds.width = __pItemDrawingProperty->width;
1459 float itemMargin = GetLeftMargin();
1460 itemBounds.x = itemMargin;
1461 itemBounds.width = __pItemDrawingProperty->width - itemBounds.x - itemMargin;
1464 FloatDimension itemDimension = Tizen::Graphics::CoordinateSystem::AlignToDevice(FloatDimension(pItem->GetSizeF().width, pItem->GetSizeF().height));
1465 itemBounds.height = itemDimension.height;
1467 if (itemPos.groupIndex == 0 && itemPos.itemIndex == -1)
1469 itemBounds.y = GetTopMargin();
1474 if (GetPreviousItemPosition(itemPos, seriesItemPos))
1476 if (__pListModel->IsLoadedItem(seriesItemPos.groupIndex, seriesItemPos.itemIndex))
1478 pSeriesItem = static_cast<_TableViewItem*>(__pListModel->LoadItem(seriesItemPos.groupIndex, seriesItemPos.itemIndex));
1479 if ((pSeriesItem != null) && pSeriesItem->HasParent())
1481 if (__pTableView->IsReorderModeEnabled() && (__reorderInfo.groupIndex == seriesItemPos.groupIndex && __reorderInfo.itemIndex == seriesItemPos.itemIndex))
1483 seriesItemBounds = __reorderInfo.itemBounds;
1487 seriesItemBounds = pSeriesItem->GetBoundsF();
1490 itemBounds.y = seriesItemBounds.y + seriesItemBounds.height;
1497 if ((!validBounds) && GetNextItemPosition(itemPos, seriesItemPos))
1499 if (__pListModel->IsLoadedItem(seriesItemPos.groupIndex, seriesItemPos.itemIndex))
1501 pSeriesItem = static_cast<_TableViewItem*>(__pListModel->LoadItem(seriesItemPos.groupIndex, seriesItemPos.itemIndex));
1502 if ((pSeriesItem != null) && pSeriesItem->HasParent())
1504 if (__pTableView->IsReorderModeEnabled() && (__reorderInfo.groupIndex == seriesItemPos.groupIndex && __reorderInfo.itemIndex == seriesItemPos.itemIndex))
1506 seriesItemBounds = __reorderInfo.itemBounds;
1510 seriesItemBounds = pSeriesItem->GetBoundsF();
1513 itemBounds.y = seriesItemBounds.y - itemBounds.height;
1524 pItem->SetBounds(itemBounds);
1526 CheckItemHeightAndRefreshLayout(itemPos, downScroll);
1530 itemBounds.y = CalculateItemPositionY(itemPos.groupIndex, itemPos.itemIndex);
1531 pItem->SetBounds(itemBounds);
1533 CheckItemHeightAndRefreshLayout(itemPos, true);
1536 if (__pTableView->IsReorderModeEnabled() && __reorderInfo.itemIndex != -1)
1538 TableViewItemTag reorderSelectedItemTag = {__reorderInfo.groupIndex, __reorderInfo.itemIndex};
1539 _TableViewItem* pReorderSelectedItem = FindItem(reorderSelectedItemTag);
1541 if (pReorderSelectedItem != null)
1543 pReorderSelectedItem->GetVisualElement()->SetZOrder(null, true);
1547 if (pItem->GetItemLayoutEnabled())
1549 pItem->PartialUpdateLayout();
1554 _TableViewPresenter::LoadItem(int groupIndex, int itemIndex)
1556 _TableViewItem* pItem = static_cast<_TableViewItem*>(__pListModel->LoadItem(groupIndex, itemIndex));
1558 if ((pItem != null) && !pItem->HasParent())
1560 __lockLoadItemWithScroll = true;
1562 __pTableView->AttachChild(*pItem);
1564 pItem->SetDrawingProperty(__pItemDrawingProperty);
1566 TableViewItemTag itemPosition = {groupIndex, itemIndex};
1567 SetItemType(pItem, itemPosition);
1568 SetItemLayout(pItem, itemPosition);
1569 pItem->SetReorderMode(__pTableView->IsReorderModeEnabled());
1571 __lockLoadItemWithScroll = false;
1578 _TableViewPresenter::FindItem(TableViewItemTag& itemTag)
1580 if (__pListModel->IsLoadedItem(itemTag.groupIndex, itemTag.itemIndex))
1582 return static_cast<_TableViewItem*>(__pListModel->LoadItem(itemTag.groupIndex, itemTag.itemIndex));
1588 _TableViewPresenter::UnloadItem(int groupIndex, int itemIndex)
1590 __pListModel->UnloadItem(groupIndex, itemIndex);
1594 _TableViewPresenter::UnloadItem(TableViewItemTag& itemTag)
1596 __pListModel->UnloadItem(itemTag.groupIndex, itemTag.itemIndex);
1602 _TableViewPresenter::DetachItem(TableViewItemTag& itemTag)
1604 _TableViewItem *pItem = FindItem(itemTag);
1606 if (pItem != null && pItem->HasParent())
1608 pItem->GetParent()->DetachChild(*pItem);
1613 _TableViewPresenter::DetachContextItem(TableViewItemTag& itemTag)
1615 _TableViewItem *pItem = FindItem(itemTag);
1621 _TableViewItem* contextItem = pItem->GetContextItem();
1622 if (contextItem != null && contextItem->HasParent())
1624 contextItem->GetParent()->DetachChild(*pItem);
1629 _TableViewPresenter::DetachAllItem(bool removeItem)
1631 TableViewItemTag itemPos = {-1, -1};
1632 TableViewItemTag lastItemPos = {-1, -1};
1634 __pListModel->GetFirstLoadedItemIndex(itemPos.groupIndex, itemPos.itemIndex);
1635 __pListModel->GetLastLoadedItemIndex(lastItemPos.groupIndex, lastItemPos.itemIndex);
1637 if (itemPos.groupIndex == -1 && itemPos.itemIndex == -1)
1644 DetachItem(itemPos);
1648 UnloadItem(itemPos);
1651 if (itemPos.itemIndex == lastItemPos.itemIndex && itemPos.groupIndex == lastItemPos.groupIndex)
1655 } while (GetNextItemPosition(itemPos, itemPos));
1659 _TableViewPresenter::SetItemDrawingProperty(void)
1661 if (__pItemDrawingProperty != null)
1663 __pItemDrawingProperty->propertyChanged = false;
1665 if (__pItemDrawingProperty->itemDividerEnabled != __pTableView->IsItemDividerEnabled())
1667 __pItemDrawingProperty->itemDividerEnabled = __pTableView->IsItemDividerEnabled();
1668 __pItemDrawingProperty->propertyChanged = true;
1671 if (__pItemDrawingProperty->dividerColor != __pTableView->GetItemDividerColor())
1673 __pItemDrawingProperty->dividerColor = __pTableView->GetItemDividerColor();
1674 __pItemDrawingProperty->propertyChanged = true;
1677 if (__pItemDrawingProperty->sectionStyleEnabled != (__pTableView->GetTableViewStyle() == TABLE_VIEW_STYLE_SECTION))
1679 __pItemDrawingProperty->sectionStyleEnabled = (__pTableView->GetTableViewStyle() == TABLE_VIEW_STYLE_SECTION);
1680 __pItemDrawingProperty->propertyChanged = true;
1683 if (__pItemDrawingProperty->sectionStyleBgColor != __pTableView->GetSectionColor())
1685 __pItemDrawingProperty->sectionStyleBgColor = __pTableView->GetSectionColor();
1686 __pItemDrawingProperty->propertyChanged = true;
1689 if (__pTableView->GetTableViewStyle() != TABLE_VIEW_STYLE_SIMPLE)
1691 if (__pItemDrawingProperty->groupedLookEnabled != __pTableView->IsGroupedLookEnabled())
1693 __pItemDrawingProperty->groupedLookEnabled = __pTableView->IsGroupedLookEnabled();
1694 __pItemDrawingProperty->propertyChanged = true;
1698 if (__pItemDrawingProperty->reorderMode != __pTableView->IsReorderModeEnabled())
1700 __pItemDrawingProperty->reorderMode = __pTableView->IsReorderModeEnabled();
1701 __pItemDrawingProperty->propertyChanged = true;
1704 if (!_FloatCompare(__pItemDrawingProperty->leftMargin, __leftMargin))
1706 __pItemDrawingProperty->leftMargin = __leftMargin;
1707 __pItemDrawingProperty->propertyChanged = true;
1710 if (__pTableView->GetScrollStyle() == TABLE_VIEW_SCROLL_BAR_STYLE_FAST_SCROLL_FIXED)
1712 GET_SHAPE_CONFIG(TABLEVIEW::FASTSCROLL_INDEX_WIDTH, _CONTROL_ORIENTATION_PORTRAIT,
1713 __pItemDrawingProperty->scrollMargin);
1717 __pItemDrawingProperty->scrollMargin = 0;
1720 if (!_FloatCompare(__pItemDrawingProperty->width, __pTableView->GetBoundsF().width))
1722 __pItemDrawingProperty->width = __pTableView->GetBoundsF().width;
1723 __pItemDrawingProperty->propertyChanged = true;
1729 _TableViewPresenter::OnBoundsChanged(void)
1731 float listWidth = __pTableView->GetBoundsF().width - (GetLeftMargin() * 2);
1733 if (__pProviderAdaptor != null && __modelInitialized)
1735 StopExpandCollapseAnimation();
1737 if (__pTableView->IsReorderModeEnabled() && __reorderInfo.itemIndex != -1)
1739 ResetReorderItem(__reorderInfo.groupIndex, __reorderInfo.itemIndex);
1742 if (!_FloatCompare(listWidth, __pProviderAdaptor->GetListWidth()))
1744 __pProviderAdaptor->SetListWidth(listWidth);
1746 SetItemDrawingProperty();
1748 AdjustLoadedItemWidth();
1750 __pTableView->UpdateLayout();
1753 SetClientAreaHeight(__itemTotalHeight);
1756 AdjustLayoutItems(GetScrollPosition());
1760 if (__pProviderAdaptor != null)
1762 __pProviderAdaptor->SetListWidth(listWidth);
1765 SetClientAreaHeight(__pTableView->GetBoundsF().height);
1766 _ScrollPanelPresenter::OnBoundsChanged();
1771 _TableViewPresenter::Draw(void)
1773 result r = _ScrollPanelPresenter::Draw();
1774 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1776 if (__modelInitialized == false)
1778 SetItemDrawingProperty();
1780 if(PreloadItem() == false)
1782 __pTableView->SetFocusNavigateEnabled(false);
1786 if (__reservedScrollItemIndex.groupIndex != -1 && __reservedScrollItemIndex.itemIndex != -1)
1788 ScrollToItem(__reservedScrollItemIndex.groupIndex, __reservedScrollItemIndex.itemIndex, __reservedScrollItemAlignment);
1790 __reservedScrollItemIndex.groupIndex = -1;
1791 __reservedScrollItemIndex.itemIndex = -1;
1797 __firstDrawnFlag = false;
1800 if (IsEmpty() == true)
1802 __pTableView->SetFocusNavigateEnabled(false);
1803 return DrawEmptyTableView();
1807 __pTableView->SetFocusNavigateEnabled(true);
1813 _UiTouchEventDelivery
1814 _TableViewPresenter::OnPreviewTouchPressed(const _Control& source, const _TouchInfo& touchInfo)
1816 _UiTouchEventDelivery response = _ScrollPanelPresenter::OnPreviewTouchPressed(source, touchInfo);
1818 _TableViewItem* pItem = GetTableViewItemFromControl(source);
1824 TableViewItemTag itemPos = {-1, -1};
1826 pItem->GetItemIndex(itemPos.groupIndex, itemPos.itemIndex);
1828 if (itemPos.groupIndex == -1 && itemPos.itemIndex == -1)
1833 if (IsScrollAnimationRunning())
1835 pItem->SetTouchPressOnScroll(true);
1839 if (__pTableView->IsReorderModeEnabled())
1841 __firstTouchMoved = true;
1843 if (SelectReorderItem(itemPos.groupIndex, itemPos.itemIndex, false))
1845 __reorderInfo.touchPressedPositionY = touchInfo.GetCurrentPosition().y;
1852 _UiTouchEventDelivery
1853 _TableViewPresenter::OnPreviewTouchMoved(const _Control& source, const _TouchInfo& touchInfo)
1855 if (__pTableView->IsReorderModeEnabled())
1857 if (__reorderInfo.itemIndex != -1)
1859 if (!DragSelectedItem(touchInfo.GetCurrentPosition().y - __reorderInfo.touchPressedPositionY, true))
1861 __firstTouchMoved = false;
1863 ResetReorderItem(__reorderInfo.groupIndex, __reorderInfo.itemIndex);
1866 return _UI_TOUCH_EVENT_DELIVERY_NO;
1870 return _ScrollPanelPresenter::OnPreviewTouchMoved(source, touchInfo);
1873 _UiTouchEventDelivery
1874 _TableViewPresenter::OnPreviewTouchReleased(const _Control& source, const _TouchInfo& touchInfo)
1876 if (__pTableView->IsReorderModeEnabled() && __reorderInfo.itemIndex != -1)
1878 ResetReorderItem(__reorderInfo.groupIndex, __reorderInfo.itemIndex);
1880 if (__reorderInfo.blockedTouchReleaseState)
1882 __reorderInfo.blockedTouchReleaseState = false;
1884 return _UI_TOUCH_EVENT_DELIVERY_NO;
1888 return _ScrollPanelPresenter::OnPreviewTouchReleased(source, touchInfo);
1891 _UiTouchEventDelivery
1892 _TableViewPresenter::OnPreviewTouchCanceled(const _Control& source, const _TouchInfo& touchInfo)
1894 return _ScrollPanelPresenter::OnPreviewTouchCanceled(source, touchInfo);
1898 _TableViewPresenter::OnTouchPressed(const _Control& source, const _TouchInfo& touchInfo)
1900 __firstTouchMoved = true;
1902 _TableViewItem* pItem = GetTableViewItemFromControl(source);
1906 StopExpandCollapseAnimation();
1907 return _ScrollPanelPresenter::OnTouchPressed(source, touchInfo);
1910 TableViewItemTag itemPos = {-1, -1};
1911 pItem->GetItemIndex(itemPos.groupIndex, itemPos.itemIndex);
1913 if (!(pItem->IsContextItem()
1914 || pItem->IsItemEnabled() == false
1915 || pItem->GetItemType() == TABLE_VIEW_ITEM_TYPE_TITLE
1916 || pItem->GetItemType() == TABLE_VIEW_ITEM_TYPE_HEADER
1917 || pItem->GetItemType() == TABLE_VIEW_ITEM_TYPE_FOOTER)
1918 && ((itemPos.groupIndex != __sweptItemTag.groupIndex)
1919 || (itemPos.itemIndex != __sweptItemTag.itemIndex)))
1924 __sweepOccured = false;
1926 StopExpandCollapseAnimation();
1928 return _ScrollPanelPresenter::OnTouchPressed(source, touchInfo);
1932 _TableViewPresenter::OnTouchMoved(const _Control& source, const _TouchInfo& touchInfo)
1934 if (__pTableView->IsReorderModeEnabled())
1936 if (__reorderInfo.blockedScroll)
1941 return _ScrollPanelPresenter::OnTouchMoved(source, touchInfo);
1944 _TableViewItem* pItem = GetTableViewItemFromControl(source);
1946 || pItem->IsItemEnabled() == false
1947 || pItem->GetItemType() == TABLE_VIEW_ITEM_TYPE_TITLE
1948 || pItem->GetItemType() == TABLE_VIEW_ITEM_TYPE_HEADER
1949 || pItem->GetItemType() == TABLE_VIEW_ITEM_TYPE_FOOTER
1950 || pItem->IsAnnexOnOffSliding())
1952 return _ScrollPanelPresenter::OnTouchMoved(source, touchInfo);;
1955 if (__firstTouchMoved)
1957 FloatPoint prevTouchPosition = GetPreviousTouchPosition();
1958 FloatPoint currTouchPosition = GetCurrentTouchPosition();
1959 float moveDistanceX = currTouchPosition.x - prevTouchPosition.x;
1960 float moveDistanceY = currTouchPosition.y - prevTouchPosition.y;
1962 if ((pItem->GetContextItem() != null && abs(moveDistanceX) > abs(moveDistanceY * 2)) || pItem->IsContextItem())
1964 if (!pItem->IsContextItem() && !pItem->IsAnimationPlaying())
1966 pItem->GetItemIndex(__sweptItemTag.groupIndex, __sweptItemTag.itemIndex);
1967 __sweptItemPosition = pItem->GetPositionF();
1969 pItem->AdjustContextItemBounds();
1972 __sweepOccured = true;
1974 else if (pItem->GetContextItem() == null && __pTableView->IsSweepEnabled())
1976 __sweepOccured = true;
1984 __firstTouchMoved = false;
1988 FloatPoint prevTouchPosition = GetPreviousTouchPosition();
1989 FloatPoint currTouchPosition = GetCurrentTouchPosition();
1991 SweepItem(currTouchPosition.x - prevTouchPosition.x);
1996 return _ScrollPanelPresenter::OnTouchMoved(source, touchInfo);
2000 _TableViewPresenter::OnTouchReleased(const _Control& source, const _TouchInfo& touchInfo)
2002 _TableViewItem* pItem = GetTableViewItemFromControl(source);
2005 || pItem->GetItemType() == TABLE_VIEW_ITEM_TYPE_TITLE
2006 || pItem->GetItemType() == TABLE_VIEW_ITEM_TYPE_HEADER
2007 || pItem->GetItemType() == TABLE_VIEW_ITEM_TYPE_FOOTER)
2009 return _ScrollPanelPresenter::OnTouchReleased(source, touchInfo);
2014 if (pItem->IsContextItem())
2016 pItem = static_cast<_TableViewItem*>(__pListModel->LoadItem(__sweptItemTag.groupIndex, __sweptItemTag.itemIndex));
2018 _TableViewItem* pContextItem = pItem->GetContextItem();
2021 if (pContextItem == null && __pTableView->IsSweepEnabled())
2023 FloatPoint prevPos = _ScrollPanelPresenter::GetPreviousTouchPosition();
2025 if (prevPos.x > touchInfo.GetCurrentPosition().x)
2027 pItem->FireItemSweepEvent(TABLE_VIEW_SWEEP_DIRECTION_LEFT);
2029 else if (prevPos.x < touchInfo.GetCurrentPosition().x)
2031 pItem->FireItemSweepEvent(TABLE_VIEW_SWEEP_DIRECTION_RIGHT);
2036 else if (pContextItem != null)
2038 AdjustSweptItemPosition(true);
2042 return _ScrollPanelPresenter::OnTouchReleased(source, touchInfo);
2046 _TableViewPresenter::OnTouchCanceled(const _Control& source, const _TouchInfo& touchInfo)
2053 if (__pTableView->IsReorderModeEnabled() && __reorderInfo.itemIndex != -1)
2055 ResetReorderItem(__reorderInfo.groupIndex, __reorderInfo.itemIndex);
2059 return _ScrollPanelPresenter::OnTouchCanceled(source, touchInfo);
2063 _TableViewPresenter::OnFlickGestureDetected(_TouchFlickGestureDetector& gesture)
2065 if (__pTableView->IsReorderModeEnabled() && __reorderInfo.itemIndex != -1)
2070 _FlickDirection flickDirection = gesture.GetDirection();
2072 if (flickDirection != _FLICK_DIRECTION_RIGHT && flickDirection != _FLICK_DIRECTION_LEFT)
2074 return _ScrollPanelPresenter::OnFlickGestureDetected(gesture);
2077 _Control* gestureControl = gesture.GetControl();
2079 if (gestureControl == null)
2081 return _ScrollPanelPresenter::OnFlickGestureDetected(gesture);
2084 _TableViewItem* pItem = GetTableViewItemFromControl(*gestureControl);
2088 return _ScrollPanelPresenter::OnFlickGestureDetected(gesture);
2091 if (flickDirection == _FLICK_DIRECTION_RIGHT)
2094 if (pItem->GetContextItem() == null && __pTableView->IsSweepEnabled())
2096 pItem->FireItemSweepEvent(TABLE_VIEW_SWEEP_DIRECTION_RIGHT);
2100 if (pItem->GetContextItem() != null)
2102 AdjustSweptItemPosition();
2106 else if (flickDirection == _FLICK_DIRECTION_LEFT)
2109 if (pItem->GetContextItem() == null && __pTableView->IsSweepEnabled())
2111 pItem->FireItemSweepEvent(TABLE_VIEW_SWEEP_DIRECTION_LEFT);
2115 if (pItem->GetContextItem() != null)
2117 AdjustSweptItemPosition();
2126 _TableViewPresenter::OnFlickGestureCanceled(_TouchFlickGestureDetector& gesture)
2128 return _ScrollPanelPresenter::OnFlickGestureCanceled(gesture);
2132 _TableViewPresenter::OnPreviewFlickGestureDetected(_TouchFlickGestureDetector& gesture)
2134 if (__pTableView->IsReorderModeEnabled() && __reorderInfo.itemIndex != -1)
2139 _FlickDirection flickDirection = gesture.GetDirection();
2140 if (flickDirection != _FLICK_DIRECTION_RIGHT && flickDirection != _FLICK_DIRECTION_LEFT)
2142 return _ScrollPanelPresenter::OnFlickGestureDetected(gesture);
2149 _TableViewPresenter::OnTimerExpired(Tizen::Base::Runtime::Timer& timer)
2151 _ScrollPanelPresenter::OnTimerExpired(timer);
2153 if (&timer == __pReorderScrollTimer)
2155 float distance = 0.0f;
2157 if (__reorderInfo.isScrollDirectionUp)
2159 distance = -REORDER_SCROLL_ANIMATION_DISTANCE;
2163 distance = REORDER_SCROLL_ANIMATION_DISTANCE;
2166 DragSelectedItem(distance, false);
2168 distance = ScrollTo(distance + GetScrollPosition());
2170 StartReorderScrollTimer();
2172 else if (&timer == __pFastScrollTimer)
2174 __isFastScrollTimerEnabled = false;
2176 _FastScroll* pFastScroll = __pTableView->GetFastScrollBar();
2178 if (pFastScroll != null && !_ScrollPanelPresenter::IsScrollAnimationRunning())
2180 pFastScroll->SetScrollVisibility(false);
2186 _TableViewPresenter::StartFastScrollTimer(void)
2188 result r = E_SUCCESS;
2190 SysTryReturn(NID_UI_CTRL,
2191 __pTableView->GetScrollStyle() == TABLE_VIEW_SCROLL_BAR_STYLE_FAST_SCROLL,
2192 E_INVALID_OPERATION, E_INVALID_OPERATION, "[E_INVALID_OPERATION] The style of TableView scroll is not TABLE_VIEW_SCROLL_BAR_STYLE_FAST_SCROLL");
2193 SysTryReturn(NID_UI_CTRL, __pFastScrollTimer != null, E_INVALID_STATE, E_INVALID_STATE, "[E_INVALID_STATE] Timer is not created.");
2195 r = __pFastScrollTimer->Start(FAST_SCROLL_FADE_OUT_DURATION);
2196 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
2198 __isFastScrollTimerEnabled = true;
2204 _TableViewPresenter::StopFastScrollTimer(void)
2206 result r = E_SUCCESS;
2208 SysTryReturnVoidResult(NID_UI_CTRL, __pFastScrollTimer != null, E_INVALID_STATE, "[E_INVALID_STATE] Timer is invalid.");
2210 r = __pFastScrollTimer->Cancel();
2211 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
2213 __isFastScrollTimerEnabled = false;
2219 _TableViewPresenter::IsEmpty(void) const
2221 if (__pTableView->GetTableViewStyle() == TABLE_VIEW_STYLE_SIMPLE)
2223 if (GetItemCountAt(0) <= 0)
2230 if (GetGroupCount() <= 0 )
2240 _TableViewPresenter::DrawEmptyTableView(void)
2246 _TableViewPresenter::GetFirstItem(TableViewItemTag& firstItem) const
2250 firstItem.groupIndex = -1;
2251 firstItem.itemIndex = -1;
2255 firstItem.groupIndex = 0;
2256 firstItem.itemIndex = -1;
2263 _TableViewPresenter::GetLastItem(TableViewItemTag& lastItem) const
2267 lastItem.groupIndex = -1;
2268 lastItem.itemIndex = -1;
2272 lastItem.groupIndex = GetGroupCount() - 1;
2273 lastItem.itemIndex = GetItemCountAt(lastItem.groupIndex) - 1;
2280 _TableViewPresenter::GetTopDrawnItem(TableViewItemTag& itemPos) const
2282 _TableViewItem* pItem = null;
2283 TableViewItemTag lastItemPos = {-1, -1};
2284 float scrollPosition = 0.0f;
2286 scrollPosition = GetScrollPosition();
2288 __pListModel->GetFirstLoadedItemIndex(itemPos.groupIndex, itemPos.itemIndex);
2289 __pListModel->GetLastLoadedItemIndex(lastItemPos.groupIndex, lastItemPos.itemIndex);
2293 pItem = static_cast <_TableViewItem*>(__pListModel->LoadItem(itemPos.groupIndex, itemPos.itemIndex));
2299 FloatRectangle itemBounds = pItem->GetBoundsF();
2301 if (scrollPosition < (itemBounds.y + itemBounds.height))
2306 if ((itemPos.itemIndex == lastItemPos.itemIndex) && (itemPos.groupIndex == lastItemPos.groupIndex))
2311 } while (GetNextItemPosition(itemPos, itemPos) == true);
2314 itemPos.itemIndex = -1;
2315 itemPos.groupIndex = -1;
2317 return E_OUT_OF_RANGE;
2321 _TableViewPresenter::GetBottomDrawnItem(TableViewItemTag& itemPos) const
2323 _TableViewItem* pItem = null;
2324 TableViewItemTag lastItemPos = {-1, -1};
2328 itemPos.itemIndex = -1;
2329 itemPos.groupIndex = -1;
2331 return E_INVALID_STATE;
2334 float scrollPosition = GetScrollPosition() + __pTableView->GetBoundsF().height;
2336 __pListModel->GetFirstLoadedItemIndex(itemPos.groupIndex, itemPos.itemIndex);
2337 __pListModel->GetLastLoadedItemIndex(lastItemPos.groupIndex, lastItemPos.itemIndex);
2341 static bool onProcessingByProvider = true;
2342 pItem = static_cast <_TableViewItem*>(__pListModel->LoadItem(itemPos.groupIndex, itemPos.itemIndex));
2343 onProcessingByProvider = false;
2349 FloatRectangle itemBounds = pItem->GetBoundsF();
2351 if (itemBounds.y <= scrollPosition && scrollPosition <= (itemBounds.y + itemBounds.height))
2356 if ((itemPos.itemIndex == lastItemPos.itemIndex) && (itemPos.groupIndex == lastItemPos.groupIndex))
2361 } while (GetNextItemPosition(itemPos, itemPos) == true);
2367 _TableViewPresenter::GetPreviousItemPosition(const TableViewItemTag& currentItemPos, TableViewItemTag& prevItem) const
2374 // check validation of group index
2375 if ((currentItemPos.groupIndex < 0) || (currentItemPos.groupIndex >= __pListModel->GetAllGroupCount()))
2380 // if the current item is the first item
2381 if (currentItemPos.groupIndex == 0 && currentItemPos.itemIndex == -1)
2386 if (currentItemPos.itemIndex == -1)
2388 if (__pListModel->IsGroupExpanded(currentItemPos.groupIndex - 1) == false)
2390 prevItem.groupIndex = currentItemPos.groupIndex - 1;
2391 prevItem.itemIndex = -1;
2397 if (__pListModel->IsGroupExpanded(currentItemPos.groupIndex) == false)
2399 if (currentItemPos.groupIndex == 0 && currentItemPos.itemIndex == -1)
2404 prevItem.groupIndex = currentItemPos.groupIndex - 1;
2405 prevItem.itemIndex = __pListModel->GetItemCountInGroup(prevItem.groupIndex) - 1;
2410 if (currentItemPos.itemIndex == -1) // group title item
2412 prevItem.groupIndex = currentItemPos.groupIndex - 1;
2413 prevItem.itemIndex = __pListModel->GetItemCountInGroup(prevItem.groupIndex) - 1;
2417 prevItem.groupIndex = currentItemPos.groupIndex;
2418 prevItem.itemIndex = currentItemPos.itemIndex - 1;
2425 _TableViewPresenter::GetNextItemPosition(const TableViewItemTag& currentItem, TableViewItemTag& nextItem) const
2432 int lastGroup = __pListModel->GetAllGroupCount() - 1;
2433 int lastItemInCurrentGroup = __pListModel->GetItemCountInGroup(currentItem.groupIndex) - 1;
2434 int lastItem = __pListModel->GetItemCountInGroup(lastGroup) - 1;
2436 // check validation of group index
2437 if ((currentItem.groupIndex < 0) || (currentItem.groupIndex > lastGroup))
2442 // if the current item is the last item.
2443 if ((currentItem.groupIndex == lastGroup) && (currentItem.itemIndex == lastItem))
2448 if (__pListModel->IsGroupExpanded(currentItem.groupIndex) == false)
2450 if (currentItem.groupIndex == lastGroup)
2455 nextItem.groupIndex = currentItem.groupIndex + 1;
2456 nextItem.itemIndex = -1;
2461 if (lastItemInCurrentGroup == currentItem.itemIndex)
2463 nextItem.groupIndex = currentItem.groupIndex + 1;
2464 nextItem.itemIndex = -1;
2468 nextItem.groupIndex = currentItem.groupIndex;
2469 nextItem.itemIndex = currentItem.itemIndex + 1;
2476 _TableViewPresenter::GetHeightOfAllItems(void) const
2478 int groupCount = GetGroupCount();
2479 float totalHeight = 0;
2481 for (int i = 0; i < groupCount; i++)
2483 TableViewItemTag itemTag = {i, -1};
2485 totalHeight += GetItemHeight(itemTag);
2487 if (!IsGroupExpanded(i))
2492 int itemCount = GetItemCountAt(i);
2494 for (int j = 0; j < itemCount; j++)
2496 itemTag.itemIndex = j;
2498 totalHeight += GetItemHeight(itemTag);
2506 _TableViewPresenter::SetTableViewItemProviderAdaptor(_TableViewItemProviderAdaptor* pProviderAdaptor)
2508 __pListModel->RegisterItemProviderAdaptor(pProviderAdaptor);
2510 __pProviderAdaptor = pProviderAdaptor;
2512 if (__pProviderAdaptor != null)
2514 __pProviderAdaptor->SetTableViewPresenter(this);
2518 _TableViewItemProviderAdaptor*
2519 _TableViewPresenter::GetTableViewItemProviderAdaptor(void) const
2521 return __pProviderAdaptor;
2525 _TableViewPresenter::ExpandGroup(int groupIndex, bool withAnimation)
2527 if ((groupIndex < 0) || (groupIndex >= GetGroupCount()))
2529 return E_OUT_OF_RANGE;
2532 if (__modelInitialized == false)
2534 return E_INVALID_STATE;
2537 if (IsGroupExpanded(groupIndex) == true)
2542 TableViewItemTag topTag;
2543 GetTopDrawnItem(topTag);
2545 TableViewItemTag bottomTag;
2546 GetBottomDrawnItem(bottomTag);
2548 float screenPosition = GetScrollPosition();
2550 __pListModel->SetGroupExpandState(groupIndex, true);
2554 _TableViewItem* pItem = null;
2555 TableViewItemTag itemTag = {-1, -1};
2556 float groupTotalHeight = 0.0f;
2557 int itemCount = GetItemCountAt(groupIndex);
2558 for (int i = 0; i < itemCount; i++)
2560 pItem = static_cast<_TableViewItem*>(__pListModel->GetItemFromTemporaryBuffer(groupIndex, i));
2561 groupTotalHeight += pItem->GetItemHeight();
2562 itemTag.groupIndex = groupIndex;
2563 itemTag.itemIndex = i;
2564 SetItemHeight(itemTag, pItem->GetItemHeight());
2566 AdjustClientAreaBounds(false, groupTotalHeight);
2568 if (groupIndex < topTag.groupIndex || groupIndex > bottomTag.groupIndex)
2570 _TableViewItem* pItem = FindItem(topTag);
2573 FloatRectangle itemBounds = pItem->GetBoundsF();
2574 itemBounds.y = CalculateItemPositionY(topTag.groupIndex, topTag.itemIndex);
2575 pItem->SetBounds(itemBounds);
2576 AttachNextItemsToBottom(topTag);
2577 if (groupIndex < topTag.groupIndex)
2579 ScrollTo(screenPosition + groupTotalHeight);
2583 int firstLoadedGroupIndex = -1;
2584 int firstLoadedItemIndex = -1;
2585 __pListModel->GetFirstLoadedItemIndex(firstLoadedGroupIndex, firstLoadedItemIndex);
2587 for (int j = firstLoadedGroupIndex; j <= topTag.groupIndex; j++)
2589 int itemCount = GetItemCountAt(j);
2591 for (int i = -1; i < itemCount; i++)
2593 if (i >= topTag.itemIndex && j == topTag.groupIndex)
2604 itemTag.groupIndex = groupIndex;
2605 itemTag.itemIndex = -1;
2607 __expandableItemTag.groupIndex = groupIndex;
2608 __expandableItemTag.itemIndex = -1;
2612 _TableViewItem *pItem = FindItem(itemTag);
2618 FloatRectangle itemBounds = pItem->GetBoundsF();
2619 float startPosition = itemBounds.y + itemBounds.height;
2621 float endPosition = startPosition + groupTotalHeight;
2622 if (endPosition > screenPosition + __pTableView->GetBoundsF().height)
2624 endPosition = screenPosition + __pTableView->GetBoundsF().height;
2627 _VisualElement* pVisualElement = __pTableView->GetVisualElement();
2628 String animationName(L"EXPAND_GROUP_ANIMATION");
2630 VisualElementValueAnimation* pAnimation = __pTableView->GetVisualElementValueAnimation(animationName);
2631 pAnimation->SetStartValue(Variant(startPosition));
2632 pAnimation->SetEndValue(Variant(endPosition));
2633 pAnimation->SetDuration(EXPAND_GROUP_ANIMATION_DURATION);
2634 pVisualElement->AddAnimation(animationName, *pAnimation);
2638 ExpandGroupAnimationFinished(false);
2645 _TableViewPresenter::CollapseGroup(int groupIndex, bool withAnimation)
2647 if ((groupIndex < 0) || (groupIndex >= GetGroupCount()))
2649 return E_OUT_OF_RANGE;
2652 if (__modelInitialized == false)
2654 return E_INVALID_STATE;
2657 if (IsGroupExpanded(groupIndex) == false)
2662 TableViewItemTag itemTag;
2663 GetTopDrawnItem(itemTag);
2665 TableViewItemTag bottomTag;
2666 GetBottomDrawnItem(bottomTag);
2667 float screenPosition = GetScrollPosition();
2669 __pListModel->SetGroupExpandState(groupIndex, false);
2673 if (groupIndex < itemTag.groupIndex || groupIndex > bottomTag.groupIndex)
2675 _TableViewItem* pItem = null;
2676 TableViewItemTag itemTag = {-1, -1};
2677 float groupTotalHeight = 0;
2678 int itemCount = GetItemCountAt(groupIndex);
2679 for (int i = 0; i < itemCount; i++)
2681 _TableViewItem* pItem = static_cast<_TableViewItem*>(__pListModel->GetItemFromTemporaryBuffer(groupIndex, i));
2682 groupTotalHeight += pItem->GetItemHeight();
2683 itemTag.groupIndex = groupIndex;
2684 itemTag.itemIndex = i;
2685 SetItemHeight(itemTag, pItem->GetItemHeight());
2688 TableViewItemTag firstLoadedItemTag;
2689 __pListModel->GetFirstLoadedItemIndex(firstLoadedItemTag.groupIndex, firstLoadedItemTag.itemIndex);
2691 if (firstLoadedItemTag.groupIndex == groupIndex)
2693 SetLoadedItemsVisibleInGroup(groupIndex, false);
2694 firstLoadedItemTag.groupIndex = groupIndex + 1;
2695 firstLoadedItemTag.itemIndex = -1;
2698 for (int i = 0; i < itemCount; i++)
2700 UnloadItem(groupIndex, i);
2703 __pListModel->GetFirstLoadedItemIndex(firstLoadedItemTag.groupIndex, firstLoadedItemTag.itemIndex);
2704 pItem = FindItem(firstLoadedItemTag);
2707 FloatRectangle itemBounds = pItem->GetBoundsF();
2708 itemBounds.y = CalculateItemPositionY(firstLoadedItemTag.groupIndex, firstLoadedItemTag.itemIndex);
2709 pItem->SetBounds(itemBounds);
2710 AttachNextItemsToBottom(firstLoadedItemTag);
2711 if (groupIndex < itemTag.groupIndex)
2713 ScrollTo(screenPosition - groupTotalHeight);
2717 AdjustClientAreaBounds(false, -groupTotalHeight);
2722 if (itemTag.groupIndex < groupIndex)
2724 itemTag.groupIndex = groupIndex;
2725 itemTag.itemIndex = -1;
2727 __expandableItemTag.groupIndex = itemTag.groupIndex;
2728 __expandableItemTag.itemIndex = itemTag.itemIndex;
2730 if(__firstDrawnFlag)
2732 withAnimation = false;
2737 _TableViewItem *pItem = FindItem(itemTag);
2743 FloatRectangle itemBounds = pItem->GetBoundsF();
2744 float startPosition = 0;
2745 if (itemTag.itemIndex == -1)
2747 startPosition = itemBounds.y + itemBounds.height;
2751 startPosition = GetScrollPosition();
2754 if (bottomTag.groupIndex > groupIndex)
2756 bottomTag.groupIndex = groupIndex+1;
2757 bottomTag.itemIndex = -1;
2760 pItem = FindItem(bottomTag);
2766 itemBounds = pItem->GetBoundsF();
2767 float endPosition = itemBounds.y;
2768 if (bottomTag.groupIndex != groupIndex +1)
2770 endPosition += itemBounds.height;
2773 if (endPosition > screenPosition + __pTableView->GetBoundsF().height)
2775 endPosition = screenPosition + __pTableView->GetBoundsF().height;
2778 _VisualElement* pVisualElement = __pTableView->GetVisualElement();
2779 String animationName(L"COLLAPSE_GROUP_ANIMATION");
2781 VisualElementValueAnimation* pAnimation = __pTableView->GetVisualElementValueAnimation(animationName);
2782 pAnimation->SetStartValue(Variant(endPosition));
2783 pAnimation->SetEndValue(Variant(startPosition));
2784 pAnimation->SetDuration(COLLAPSE_GROUP_ANIMATION_DURATION);
2785 pVisualElement->AddAnimation(animationName, *pAnimation);
2789 CollapseGroupAnimationFinished(false);
2796 _TableViewPresenter::IsGroupExpanded(int groupIndex) const
2798 return __pListModel->IsGroupExpanded(groupIndex);
2802 _TableViewPresenter::StopExpandCollapseAnimation(void)
2804 _VisualElement* pVisualElement = __pTableView->GetVisualElement();
2805 String animationName(L"EXPAND_GROUP_ANIMATION");
2806 VisualElementValueAnimation* pExpandGroupAnimation = dynamic_cast<VisualElementValueAnimation*>(pVisualElement->GetAnimationN(animationName));
2807 if (pExpandGroupAnimation != null)
2809 pVisualElement->RemoveAnimation(animationName);
2810 delete pExpandGroupAnimation;
2813 animationName = L"COLLAPSE_GROUP_ANIMATION";
2814 VisualElementValueAnimation* pCollapseGroupAnimation = dynamic_cast<VisualElementValueAnimation*>(pVisualElement->GetAnimationN(animationName));
2815 if (pCollapseGroupAnimation != null)
2817 pVisualElement->RemoveAnimation(animationName);
2818 delete pCollapseGroupAnimation;
2823 _TableViewPresenter::LoadAllItemsInGroup(int groupIndex, bool downward)
2825 int itemCountInGroup = __pListModel->GetItemCountInGroup(groupIndex);
2826 _TableViewItem* pItem = null;
2830 for (int i = 0; i < itemCountInGroup; i++)
2832 pItem = LoadItem(groupIndex, i);
2836 SysLogException(NID_UI_CTRL, E_SYSTEM, "[E_SYSTEM] Unable to load item.");
2842 for (int i = itemCountInGroup-1; i >= 0; i--)
2844 pItem = LoadItem(groupIndex, i);
2848 SysLogException(NID_UI_CTRL, E_SYSTEM, "[E_SYSTEM] Unable to load item.");
2853 return itemCountInGroup;
2857 _TableViewPresenter::SetLoadedItemsVisibleInGroup(int groupIndex, bool visible)
2859 int itemCountInGroup = __pListModel->GetItemCountInGroup(groupIndex);
2860 _TableViewItem* pItem = null;
2861 TableViewItemTag itemTag;
2862 itemTag.groupIndex = groupIndex;
2864 int firstLoadedGroupIndex = -1;
2865 int firstLoadedItemIndex = -1;
2866 __pListModel->GetFirstLoadedItemIndex(firstLoadedGroupIndex, firstLoadedItemIndex);
2868 if (firstLoadedGroupIndex > groupIndex)
2874 if (groupIndex == firstLoadedGroupIndex && firstLoadedItemIndex > 0)
2876 startIndex = firstLoadedItemIndex;
2879 for (int i = startIndex; i < itemCountInGroup; i++)
2881 itemTag.itemIndex = i;
2882 pItem = FindItem(itemTag);
2888 pItem->SetVisibleState(visible);
2893 _TableViewPresenter::LoadItemsToBeVisible(const TableViewItemTag& from)
2895 TableViewItemTag bottomTag = from;
2896 TableViewItemTag current;
2897 TableViewItemTag next;
2899 _TableViewItem *pItem = LoadItem(from.groupIndex, from.itemIndex);
2906 FloatRectangle itemBounds = pItem->GetBoundsF();
2907 float viewHeight = __pTableView->GetBoundsF().height;
2908 float scrollPosition = GetScrollPosition();
2909 float itemPosition = itemBounds.y + itemBounds.height - scrollPosition;
2911 while (viewHeight >= itemPosition)
2913 current.groupIndex = bottomTag.groupIndex;
2914 current.itemIndex = bottomTag.itemIndex;
2915 if (!GetNextItemPosition(current, next))
2920 pItem = LoadItem(next.groupIndex, next.itemIndex);
2921 bottomTag.groupIndex = next.groupIndex;
2922 bottomTag.itemIndex = next.itemIndex;
2923 itemPosition += pItem->GetBoundsF().height;
2930 _TableViewPresenter::AttachNextItemsToBottom(const TableViewItemTag& anchor)
2932 TableViewItemTag itemTag = anchor;
2933 TableViewItemTag current;
2934 TableViewItemTag next;
2936 _TableViewItem *pItem = FindItem(itemTag);
2942 FloatRectangle itemBounds = pItem->GetBoundsF();
2943 float itemPosition = itemBounds.y + itemBounds.height;
2945 current.groupIndex = itemTag.groupIndex;
2946 current.itemIndex = itemTag.itemIndex;
2947 while (GetNextItemPosition(current, next))
2949 pItem = FindItem(next);
2956 itemBounds = pItem->GetBoundsF();
2957 itemBounds.y = itemPosition;
2958 pItem->SetBounds(itemBounds);
2959 itemPosition += itemBounds.height;
2965 _TableViewPresenter::IsAnyItemInGroupLoaded(int groupIndex) const
2967 int startGroupIndex = 0;
2968 int endGroupIndex = 0;
2971 __pListModel->GetFirstLoadedItemIndex(startGroupIndex, index);
2972 __pListModel->GetLastLoadedItemIndex(endGroupIndex, index);
2974 return groupIndex >= startGroupIndex && groupIndex <= endGroupIndex;
2978 _TableViewPresenter::ScrollToHideNonClientArea(TableViewItemTag& bottomTag)
2980 _TableViewItem* pItem = FindItem(bottomTag);
2986 FloatRectangle itemBounds = pItem->GetBoundsF();
2987 float viewHeight = __pTableView->GetBoundsF().height;
2988 float scrollPosition = GetScrollPosition();
2989 float itemBottom = itemBounds.y + itemBounds.height - scrollPosition;
2991 if (itemBottom < viewHeight)
2993 scrollPosition -= viewHeight - itemBottom;
2994 if (scrollPosition < 0)
2999 SetScrollPosition(scrollPosition, false);
3004 _TableViewPresenter::AdjustClientAreaBounds(bool reset, float dist)
3006 float clientHeight = 0;
3010 __itemTotalHeight = GetHeightOfAllItems();
3011 clientHeight = __itemTotalHeight;
3015 __itemTotalHeight = __itemTotalHeight + dist;
3016 clientHeight = __itemTotalHeight;
3019 SetClientAreaHeight(clientHeight);
3023 _TableViewPresenter::SetClientAreaHeight(float height)
3025 FloatRectangle screenBounds = __pTableView->GetBoundsF();
3026 FloatRectangle clientBounds = screenBounds;
3028 clientBounds.height = height;
3030 if (clientBounds.height < screenBounds.height)
3032 clientBounds.height = screenBounds.height;
3035 SetScrollAreaBounds(clientBounds);
3037 _Scroll* pScroll = __pTableView->GetScrollBar();
3038 if (pScroll != null)
3040 pScroll->SetScrollRange(__pTableView->GetBoundsF().height, clientBounds.height);
3045 _TableViewPresenter::UnloadInvisibleItems(void)
3047 float scrollPosition = GetScrollPosition();
3048 TableViewItemTag itemTag;
3049 __pListModel->GetFirstLoadedItemIndex(itemTag.groupIndex, itemTag.itemIndex);
3051 _TableViewItem* pItem = null;
3052 FloatRectangle bounds;
3054 while ((pItem = FindItem(itemTag)) != null)
3056 if (itemTag.itemIndex != -1)
3058 bounds = pItem->GetBoundsF();
3059 if (bounds.y + bounds.height < scrollPosition)
3061 UnloadItem(itemTag);
3068 __pListModel->GetFirstLoadedItemIndex(itemTag.groupIndex, itemTag.itemIndex);
3071 __pListModel->GetLastLoadedItemIndex(itemTag.groupIndex, itemTag.itemIndex);
3072 scrollPosition += __pTableView->GetBoundsF().height;
3074 while ((pItem = FindItem(itemTag)) != null)
3076 if (itemTag.itemIndex != -1)
3078 bounds = pItem->GetBoundsF();
3079 if (bounds.y > scrollPosition)
3081 UnloadItem(itemTag);
3088 __pListModel->GetLastLoadedItemIndex(itemTag.groupIndex, itemTag.itemIndex);
3094 _TableViewPresenter::ScrollToInternal(float newPosition)
3096 if (!IsScrollEnabled())
3101 if (IsScrollAnimationRunning())
3103 if (__scrollPositionOnFlickStarted > newPosition)
3105 newPosition += GetScrollAreaBounds().height - __scrollHeightOnFlickStarted;
3109 float currentScrollPosition = GetScrollPosition();
3110 float currentscrollAreaHeight = GetScrollAreaBounds().height;
3111 float newScrollPosition = (newPosition < 0) ? 0 : (newPosition > currentscrollAreaHeight ? currentscrollAreaHeight : newPosition);
3112 float newScrollAreaHeight = 0;
3114 if (IsModelUpdating())
3116 currentScrollPosition = GetScrollPositionInternal();
3119 if (!__lockLoadItemWithScroll)
3121 LoadItemWithScrollPosition(currentScrollPosition, newScrollPosition);
3123 if (currentScrollPosition > newScrollPosition)
3125 newScrollAreaHeight = GetScrollAreaBounds().height;
3126 newScrollPosition += newScrollAreaHeight - currentscrollAreaHeight;
3130 //scroll effect for _ScrollPanel
3131 if (newPosition < 0.0f || newPosition > currentscrollAreaHeight - __pTableView->GetBoundsF().height)
3133 newScrollPosition = newPosition;
3136 return _ScrollPanelPresenter::ScrollToInternal(newScrollPosition);
3140 _TableViewPresenter::LoadItemWithScrollPosition(float previousScrollPosition, float currentScrollPos)
3144 TableViewItemTag lastLoadedItemPos = {-1, -1};
3145 TableViewItemTag firstLoadedItemPos = {-1, -1};
3146 __pListModel->GetLastLoadedItemIndex(lastLoadedItemPos.groupIndex, lastLoadedItemPos.itemIndex);
3147 __pListModel->GetFirstLoadedItemIndex(firstLoadedItemPos.groupIndex, firstLoadedItemPos.itemIndex);
3149 if (currentScrollPos > previousScrollPosition && lastLoadedItemPos.groupIndex != -1)
3151 _TableViewItem* pLastItem = FindItem(lastLoadedItemPos);
3152 if (pLastItem == null)
3157 while (pLastItem->GetBoundsF().y <= currentScrollPos + __pTableView->GetBoundsF().height)
3159 TableViewItemTag nextItemPos = {-1, -1};
3160 if (GetNextItemPosition(lastLoadedItemPos, nextItemPos))
3162 if (nextItemPos.itemIndex == -1)
3164 LoadItem(nextItemPos.groupIndex, nextItemPos.itemIndex);
3166 if (!GetNextItemPosition(nextItemPos, nextItemPos))
3172 if (nextItemPos.groupIndex != -1)
3174 _TableViewItem* item = LoadItem(nextItemPos.groupIndex, nextItemPos.itemIndex);
3176 FloatRectangle scrollAreaBounds = GetScrollAreaBounds();
3177 if (item->GetBoundsF().y + item->GetBoundsF().height >= scrollAreaBounds.height)
3179 AdjustClientAreaBounds(true);
3188 lastLoadedItemPos = nextItemPos;
3189 pLastItem = static_cast<_TableViewItem*>(__pListModel->LoadItem(lastLoadedItemPos.groupIndex, lastLoadedItemPos.itemIndex));
3193 if (currentScrollPos < previousScrollPosition && firstLoadedItemPos.groupIndex != -1)
3195 _TableViewItem* pFirstItem = FindItem(firstLoadedItemPos);
3196 if (pFirstItem == null)
3201 float scrollOffsetFromBottom = GetScrollAreaBounds().height - currentScrollPos;
3205 FloatRectangle scrollAreaBounds = GetScrollAreaBounds();
3206 float itemOffsetFromBottom = scrollAreaBounds.height - (pFirstItem->GetBoundsF().y + pFirstItem->GetBoundsF().height);
3208 if (scrollOffsetFromBottom < itemOffsetFromBottom)
3213 TableViewItemTag prevItemPos = {-1, -1};
3214 if (GetPreviousItemPosition(firstLoadedItemPos, prevItemPos))
3216 if (prevItemPos.itemIndex == -1)
3218 LoadItem(prevItemPos.groupIndex, prevItemPos.itemIndex);
3220 if (!GetPreviousItemPosition(prevItemPos, prevItemPos))
3226 if (prevItemPos.groupIndex != -1)
3228 LoadItem(prevItemPos.groupIndex, prevItemPos.itemIndex);
3236 firstLoadedItemPos = prevItemPos;
3237 pFirstItem = FindItem(firstLoadedItemPos);
3243 _TableViewPresenter::ScrollToItem(int groupIndex, int itemIndex, TableViewScrollItemAlignment itemAlignment, float shiftingDistance)
3245 _VisualElement* pVisualElement = __pTableView->GetVisualElement();
3246 String animationName(L"EXPAND_GROUP_ANIMATION");
3247 VisualElementValueAnimation* pExpandGroupAnimation = dynamic_cast<VisualElementValueAnimation*>(pVisualElement->GetAnimationN(animationName));
3248 if (pExpandGroupAnimation != null)
3250 __scrollToItemTag.groupIndex = groupIndex;
3251 __scrollToItemTag.itemIndex = itemIndex;
3252 __scrollToItemTag.itemAlignment = itemAlignment;
3253 __scrollToItemTag.shiftingDistance = shiftingDistance;
3254 __scrollToItemTag.startedAnimation = true;
3255 delete pExpandGroupAnimation;
3259 animationName = L"COLLAPSE_GROUP_ANIMATION";
3260 VisualElementValueAnimation* pCollapseGroupAnimation = dynamic_cast<VisualElementValueAnimation*>(pVisualElement->GetAnimationN(animationName));
3261 if (pCollapseGroupAnimation != null)
3263 __scrollToItemTag.groupIndex = groupIndex;
3264 __scrollToItemTag.itemIndex = itemIndex;
3265 __scrollToItemTag.itemAlignment = itemAlignment;
3266 __scrollToItemTag.shiftingDistance = shiftingDistance;
3267 __scrollToItemTag.startedAnimation = true;
3268 delete pCollapseGroupAnimation;
3272 if (IsGroupExpanded(groupIndex) == false)
3277 TableViewItemTag itemPos = {groupIndex, itemIndex};
3279 StopAllItemAnimation();
3282 if (!__pListModel->IsLoadedItem(groupIndex, itemIndex))
3284 ResetItemLayout(itemPos, shiftingDistance);
3287 _TableViewItem* pItem = FindItem(itemPos);
3294 float scrollPosition = pItem->GetBoundsF().y;
3296 scrollPosition = scrollPosition + shiftingDistance;
3298 SetScrollPosition(scrollPosition, false);
3300 if (itemAlignment == TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_BOTTOM)
3302 SetScrollPosition(scrollPosition - (__pTableView->GetBoundsF().height - pItem->GetBoundsF().height), false);
3307 _TableViewPresenter::ScrollByPixel(float scrollDistance)
3310 result r = GetLastResult();
3311 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
3315 ScrollTo(scrollDistance + GetScrollPosition());
3316 r = GetLastResult();
3317 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
3319 RollbackBouncing(true);
3320 r = GetLastResult();
3321 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
3324 r = GetLastResult();
3325 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
3331 _TableViewPresenter::SetScrollEnabled(bool enable)
3333 __scrolling = enable;
3337 _TableViewPresenter::IsScrollEnabled(void) const
3343 _TableViewPresenter::GetFirstDrawnFlag(void) const
3345 return __firstDrawnFlag;
3349 _TableViewPresenter::GetMaxItemCachingSize(void) const
3351 return __pListModel->GetMaxCachingSize();
3355 _TableViewPresenter::ResetSweepItem(void)
3357 if (__sweptItemTag.groupIndex != -1 && __sweptItemTag.itemIndex != -1)
3364 _TableViewPresenter::GetSweepItemIndex(int& groupIndex, int& itemIndex) const
3366 groupIndex = __sweptItemTag.groupIndex;
3367 itemIndex = __sweptItemTag.itemIndex;
3371 _TableViewPresenter::GetPressedItemCount(void)
3373 _TableViewItem* pItem = null;
3374 TableViewItemTag itemPos = {-1, -1};
3375 TableViewItemTag lastItemPos = {-1, -1};
3378 __pListModel->GetFirstLoadedItemIndex(itemPos.groupIndex, itemPos.itemIndex);
3379 __pListModel->GetLastLoadedItemIndex(lastItemPos.groupIndex, lastItemPos.itemIndex);
3383 pItem = static_cast <_TableViewItem*>(__pListModel->LoadItem(itemPos.groupIndex, itemPos.itemIndex));
3389 if (pItem->GetDrawingStatus() == TABLE_VIEW_ITEM_DRAWING_STATUS_PRESSED)
3394 if ((itemPos.itemIndex == lastItemPos.itemIndex) && (itemPos.groupIndex == lastItemPos.groupIndex))
3398 } while (GetNextItemPosition(itemPos, itemPos) == true);
3404 _TableViewPresenter::BlockAnimationCallback(bool blocked)
3406 __isAnimationCallbackBlocked = blocked;
3410 _TableViewPresenter::CalculateItemPositionY(int groupIndex, int itemIndex)
3412 TableViewItemTag itemPos = {-1, -1};
3413 TableViewItemTag currentItemPos = {-1, -1};
3414 float positionY = 0.0f;
3416 GetFirstItem(itemPos);
3418 if (itemPos.groupIndex == -1 && itemPos.itemIndex == -1)
3423 if (__pProviderAdaptor == null)
3428 positionY = GetTopMargin();
3430 while ((itemPos.groupIndex < groupIndex) || ((itemPos.groupIndex == groupIndex) && (itemPos.itemIndex < itemIndex)))
3432 currentItemPos = itemPos;
3434 float itemHeight = GetItemHeight(itemPos);
3436 positionY += itemHeight;
3438 if (!GetNextItemPosition(currentItemPos, itemPos))
3448 _TableViewPresenter::FadeInScrollBar(void)
3450 TableViewScrollBarStyle scrollStyle = __pTableView->GetScrollStyle();
3452 if (scrollStyle == TABLE_VIEW_SCROLL_BAR_STYLE_NONE)
3454 _Scroll* pScroll = __pTableView->GetScrollBar();
3456 if (pScroll != null)
3458 pScroll->SetVisibleState(false);
3461 else if (scrollStyle == TABLE_VIEW_SCROLL_BAR_STYLE_FAST_SCROLL)
3463 _Scroll* pScroll = __pTableView->GetScrollBar();
3465 if (pScroll != null)
3467 pScroll->SetVisibleState(false);
3470 _FastScroll* pFastScroll = __pTableView->GetFastScrollBar();
3472 if (pFastScroll != null)
3474 pFastScroll->SetScrollVisibility(true);
3479 _ScrollPanelPresenter::FadeInScrollBar();
3484 _TableViewPresenter::FadeOutScrollBar(void)
3486 TableViewScrollBarStyle scrollStyle = __pTableView->GetScrollStyle();
3487 if (scrollStyle == TABLE_VIEW_SCROLL_BAR_STYLE_FAST_SCROLL)
3489 StopFastScrollTimer();
3491 if (!_ScrollPanelPresenter::IsScrollAnimationRunning())
3493 StartFastScrollTimer();
3496 else if (scrollStyle == TABLE_VIEW_SCROLL_BAR_STYLE_FIXED)
3498 _Scroll* pScroll = __pTableView->GetScrollBar();
3500 if (pScroll != null)
3502 pScroll->SetScrollingEffectVisibility(false);
3507 _ScrollPanelPresenter::FadeOutScrollBar();
3512 _TableViewPresenter::SweepItem(float x)
3514 if (!_FloatCompare(x, 0.0f))
3516 _TableViewItem* pItem = static_cast<_TableViewItem*>(__pListModel->LoadItem(__sweptItemTag.groupIndex, __sweptItemTag.itemIndex));
3520 _TableViewItem* pContextItem = pItem->GetContextItem();
3522 if (pContextItem != null)
3524 float currentPosition = __sweptItemPosition.x + x;
3525 float sweepDistance = __pTableView->GetBoundsF().width;
3526 float sweepMargin = 0.0f;
3527 float contextItemWidth = pItem->GetBoundsF().width;
3528 bool activated = pItem->IsContextItemActivated();
3529 bool needToFireEvent = false;
3531 GET_SHAPE_CONFIG(TABLEVIEW::CONTEXTITEM_RIGHT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, sweepMargin);
3533 if (currentPosition >= (sweepDistance - sweepMargin))
3535 currentPosition = (sweepDistance - sweepMargin);
3536 needToFireEvent = !activated;
3538 else if (currentPosition <= __leftMargin)
3540 currentPosition = __leftMargin;
3541 needToFireEvent = activated;
3544 __sweptItemPosition.x = currentPosition;
3546 // Set TableViewItem bounds
3547 pItem->SetPosition(__sweptItemPosition);
3549 // Set TableViewContextItem bounds
3550 if (!__pTableView->IsAncestorOf(*pContextItem))
3552 pContextItem->SetDrawingProperty(__pItemDrawingProperty);
3553 __pTableView->InsertChildToBottom(*pContextItem);
3554 __pTableView->UpdateLayout();
3557 contextItemWidth = ((contextItemWidth > (__sweptItemPosition.x - __leftMargin)) ? (__sweptItemPosition.x - __leftMargin) : contextItemWidth);
3559 pContextItem->ExposeContextItem(FloatRectangle(__leftMargin, __sweptItemPosition.y, contextItemWidth, pContextItem->GetSizeF().height), pItem->GetSize().width);
3561 if (needToFireEvent)
3563 PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_SLIDER_SWEEP, pItem);
3565 activated = !activated; // ContextItem Activation State Changed
3567 __pTableView->FireTableViewContextItemActivationEvent(__sweptItemTag.groupIndex, __sweptItemTag.itemIndex, pContextItem, activated);
3568 pItem->SetContextItemActivation(activated);
3581 _TableViewPresenter::ResetSweptItem(void)
3583 _TableViewItem* pItem = static_cast<_TableViewItem*>(__pListModel->LoadItem(__sweptItemTag.groupIndex, __sweptItemTag.itemIndex));
3587 _VisualElement* pVisualElement = __pTableView->GetVisualElement();
3589 if (pVisualElement != null)
3591 String animationName(L"SWEEP_ITEM_ANIMATION");
3592 VisualElementAnimation* pContextItemAnimation = pVisualElement->GetAnimationN(animationName);
3593 if (pContextItemAnimation != null)
3595 pVisualElement->RemoveAnimation(animationName);
3597 delete pContextItemAnimation;
3601 pItem->SetPosition(FloatPoint(__leftMargin, __sweptItemPosition.y));
3603 _TableViewItem* pContextItem = pItem->GetContextItem();
3604 if (pContextItem != null)
3606 if (__pTableView->IsAncestorOf(*pContextItem))
3608 __pTableView->DetachChild(*pContextItem);
3611 if (pItem->IsContextItemActivated())
3613 __pTableView->FireTableViewContextItemActivationEvent(__sweptItemTag.groupIndex, __sweptItemTag.itemIndex, pContextItem, false);
3614 pItem->SetContextItemActivation(false);
3619 __sweptItemTag.itemIndex = -1;
3620 __sweptItemTag.groupIndex = -1;
3622 __sweptItemPosition.SetPosition(-1.0f, -1.0f);
3623 __sweepOccured = false;
3627 _TableViewPresenter::AdjustSweptItemPosition(bool withAnimation)
3629 float itemWidth = __pTableView->GetBoundsF().width;
3630 float sweepDistance = 0.0f;
3632 if (_FloatCompare(__sweptItemPosition.x, __leftMargin))
3638 float sweepMargin = 0.0f;
3639 GET_SHAPE_CONFIG(TABLEVIEW::CONTEXTITEM_RIGHT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, sweepMargin);
3641 if (__sweptItemPosition.x > (itemWidth - sweepMargin) / 2)
3643 sweepDistance = itemWidth - __sweptItemPosition.x;
3647 sweepDistance = -__sweptItemPosition.x;
3652 SweepItem(sweepDistance);
3656 _TableViewItem* pItem = static_cast<_TableViewItem*>(__pListModel->LoadItem(__sweptItemTag.groupIndex, __sweptItemTag.itemIndex));
3660 _VisualElement* pVisualElement = __pTableView->GetVisualElement();
3662 if (pVisualElement != null)
3664 String animationName(L"SWEEP_ITEM_ANIMATION");
3665 float startValue = __sweptItemPosition.x;
3666 float endValue = 0.0f;
3668 if(sweepDistance > 0)
3670 endValue = itemWidth - sweepMargin;
3674 if(_FloatCompare(itemWidth, __sweptItemPosition.x))
3676 endValue = itemWidth - sweepMargin;
3680 endValue = __leftMargin;
3684 pVisualElement->SetImplicitAnimationEnabled(false);
3686 VisualElementValueAnimation* pAnimation = __pTableView->GetVisualElementValueAnimation(animationName);
3687 pAnimation->SetStartValue(Variant(startValue));
3688 pAnimation->SetEndValue(Variant(endValue));
3689 pAnimation->SetDuration(SWEEP_ITEM_ANIMATION_DURATION);
3690 pVisualElement->AddAnimation(animationName, *pAnimation);
3697 _TableViewPresenter::AdjustLoadedItemWidth(void)
3699 TableViewItemTag lastLoadedItemPos = {-1, -1};
3700 TableViewItemTag firstLoadedItemPos = {-1, -1};
3701 __pListModel->GetLastLoadedItemIndex(lastLoadedItemPos.groupIndex, lastLoadedItemPos.itemIndex);
3702 __pListModel->GetFirstLoadedItemIndex(firstLoadedItemPos.groupIndex, firstLoadedItemPos.itemIndex);
3706 _TableViewItem* pItem = FindItem(firstLoadedItemPos);
3713 FloatDimension itemSize = pItem->GetSizeF();
3714 itemSize.width = __pProviderAdaptor->GetListWidth();
3716 pItem->SetItemChanged(true);
3717 pItem->SetSize(itemSize);
3719 if ((firstLoadedItemPos.itemIndex == lastLoadedItemPos.itemIndex) && (firstLoadedItemPos.groupIndex == lastLoadedItemPos.groupIndex))
3723 } while (GetNextItemPosition(firstLoadedItemPos, firstLoadedItemPos));
3727 _TableViewPresenter::OpenContextItem(int groupIndex, int itemIndex)
3729 SysTryReturn(NID_UI_CTRL, groupIndex >= 0 && groupIndex < GetGroupCount(), E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[E_INVALID_ARG] Invalid group index.");
3731 TableViewItemTag itemTag = {groupIndex, itemIndex};
3732 _TableViewItem* pItem = FindItem(itemTag);
3734 SysTryReturn(NID_UI_CTRL, pItem != null, E_INVALID_OPERATION, E_INVALID_OPERATION, "[E_INVALID_OPERATION] Item was not loaded.");
3735 SysTryReturn(NID_UI_CTRL, pItem->GetContextItem() != null, E_INVALID_OPERATION, E_INVALID_OPERATION, "[E_INVALID_OPERATION] ContextItem is not set to the item.");
3736 SysTryReturn(NID_UI_CTRL,__sweptItemTag.groupIndex != groupIndex || __sweptItemTag.itemIndex != itemIndex, E_INVALID_OPERATION, E_INVALID_OPERATION, "[E_INVALID_OPERATION] ContextItem already opened.");
3740 __sweptItemTag.groupIndex = groupIndex;
3741 __sweptItemTag.itemIndex = itemIndex;
3742 __sweptItemPosition = pItem->GetPositionF();
3744 pItem->AdjustContextItemBounds();
3745 __sweepOccured = true;
3747 _VisualElement* pVisualElement = __pTableView->GetVisualElement();
3749 if (pVisualElement != null)
3751 float itemWidth = __pTableView->GetBoundsF().width;
3752 float sweepMargin = 0.0f;
3753 GET_SHAPE_CONFIG(TABLEVIEW::CONTEXTITEM_RIGHT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, sweepMargin);
3755 String animationName(L"SWEEP_ITEM_ANIMATION");
3756 float startValue = __sweptItemPosition.x;
3757 float endValue = itemWidth - sweepMargin;
3759 pVisualElement->SetImplicitAnimationEnabled(false);
3761 VisualElementValueAnimation* pAnimation = __pTableView->GetVisualElementValueAnimation(animationName);
3762 pAnimation->SetStartValue(Variant(startValue));
3763 pAnimation->SetEndValue(Variant(endValue));
3764 pAnimation->SetDuration(SWEEP_ITEM_ANIMATION_DURATION);
3765 pVisualElement->AddAnimation(animationName, *pAnimation);
3772 _TableViewPresenter::CloseContextItem(int groupIndex, int itemIndex)
3774 SysTryReturn(NID_UI_CTRL, groupIndex >= 0 && groupIndex < GetGroupCount(), E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[E_INVALID_ARG] Invalid group index.");
3776 TableViewItemTag itemTag = {groupIndex, itemIndex};
3777 _TableViewItem* pItem = FindItem(itemTag);
3779 SysTryReturn(NID_UI_CTRL, pItem != null, E_INVALID_OPERATION, E_INVALID_OPERATION, "[E_INVALID_OPERATION] Item was not loaded.");
3780 SysTryReturn(NID_UI_CTRL, pItem->GetContextItem() != null, E_INVALID_OPERATION, E_INVALID_OPERATION, "[E_INVALID_OPERATION] ContextItem is not set to the item.");
3781 SysTryReturn(NID_UI_CTRL, __sweptItemTag.groupIndex == groupIndex && __sweptItemTag.itemIndex == itemIndex, E_INVALID_OPERATION, E_INVALID_OPERATION, "[E_INVALID_OPERATION] ContextItem was not opened.");
3789 _TableViewPresenter::IsContextItemOpened(int groupIndex, int itemIndex) const
3791 SysTryReturn(NID_UI_CTRL, groupIndex >= 0 && groupIndex < GetGroupCount(), false, E_OUT_OF_RANGE, "[E_INVALID_ARG] Invalid group index.");
3793 if ( __sweptItemTag.groupIndex == -1 && __sweptItemTag.itemIndex == -1)
3798 if (__sweptItemTag.groupIndex == groupIndex && __sweptItemTag.itemIndex == itemIndex)
3807 _TableViewPresenter::SetSectionHeaderTextHorizontalAlignment(int sectionIndex, HorizontalAlignment alignment)
3809 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");
3810 SysTryReturn(NID_UI_CTRL, HasSectionHeader(sectionIndex), E_INVALID_OPERATION, E_INVALID_OPERATION, "[E_INVALID_OPERATION] Header is not set to the section.");
3811 SysTryReturn(NID_UI_CTRL, sectionIndex >= 0 && sectionIndex < GetGroupCount(), E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[E_INVALID_ARG] Invalid section index.");
3813 _TableViewSectionStringAlignment newAlignment;
3815 __sectionAlignmentList.GetAt(sectionIndex, newAlignment);
3816 newAlignment.headerHorizontalAlignment = alignment;
3817 __sectionAlignmentList.SetAt(newAlignment, sectionIndex);
3819 TableViewItemTag itemTag = {sectionIndex, -1};
3820 _TableViewItem* pItem = FindItem(itemTag);
3824 pItem->SetSectionHeaderFooterAlignment(alignment);
3831 _TableViewPresenter::GetSectionHeaderTextHorizontalAlignment(int sectionIndex) const
3833 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");
3834 SysTryReturn(NID_UI_CTRL, HasSectionHeader(sectionIndex), ALIGNMENT_LEFT, E_INVALID_OPERATION, "[E_INVALID_OPERATION] Header is not set to the section.");
3835 SysTryReturn(NID_UI_CTRL, sectionIndex >= 0 && sectionIndex < GetGroupCount(), ALIGNMENT_LEFT, E_OUT_OF_RANGE, "[E_INVALID_ARG] Invalid section index.");
3837 _TableViewSectionStringAlignment alignment;
3838 __sectionAlignmentList.GetAt(sectionIndex, alignment);
3840 return alignment.headerHorizontalAlignment;
3844 _TableViewPresenter::SetSectionFooterTextHorizontalAlignment(int sectionIndex, HorizontalAlignment alignment)
3846 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");
3847 SysTryReturn(NID_UI_CTRL, HasSectionFooter(sectionIndex), E_INVALID_OPERATION, E_INVALID_OPERATION, "[E_INVALID_OPERATION] Footer is not set to the section.");
3848 SysTryReturn(NID_UI_CTRL, sectionIndex >= 0 && sectionIndex < GetGroupCount(), E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[E_INVALID_ARG] Invalid section index.");
3850 _TableViewSectionStringAlignment newAlignment;
3852 __sectionAlignmentList.GetAt(sectionIndex, newAlignment);
3853 newAlignment.footerHorizontalAlignment= alignment;
3854 __sectionAlignmentList.SetAt(newAlignment, sectionIndex);
3856 TableViewItemTag itemTag = {sectionIndex, GetItemCountAt(sectionIndex) - 1};
3857 _TableViewItem* pItem = FindItem(itemTag);
3861 pItem->SetSectionHeaderFooterAlignment(alignment);
3868 _TableViewPresenter::GetSectionFooterTextHorizontalAlignment(int sectionIndex) const
3870 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");
3871 SysTryReturn(NID_UI_CTRL, HasSectionFooter(sectionIndex), ALIGNMENT_RIGHT, E_INVALID_OPERATION, "[E_INVALID_OPERATION] Footer is not set to the section.");
3872 SysTryReturn(NID_UI_CTRL, sectionIndex >= 0 && sectionIndex < GetGroupCount(), ALIGNMENT_RIGHT, E_OUT_OF_RANGE, "[E_INVALID_ARG] Invalid section index.");
3874 _TableViewSectionStringAlignment alignment;
3875 __sectionAlignmentList.GetAt(sectionIndex, alignment);
3877 return alignment.footerHorizontalAlignment;
3881 _TableViewPresenter::IsValidDrawnItem(int groupIndex, int itemIndex)
3883 TableViewItemTag currentItemTag = {groupIndex, itemIndex};
3884 TableViewItemTag itemTag = {-1, -1};
3886 if (GetNextItemPosition(currentItemTag, itemTag))
3888 if (__pListModel->IsLoadedItem(itemTag.groupIndex, itemTag.itemIndex))
3894 if (GetPreviousItemPosition(currentItemTag, itemTag))
3896 if (__pListModel->IsLoadedItem(itemTag.groupIndex, itemTag.itemIndex))
3906 _TableViewPresenter::StopAllItemAnimation(void)
3908 TableViewItemTag currentItemTag = {-1, -1};
3909 TableViewItemTag lastItemTag = {-1, -1};
3911 __pListModel->GetFirstLoadedItemIndex(currentItemTag.groupIndex, currentItemTag.itemIndex);
3912 __pListModel->GetLastLoadedItemIndex(lastItemTag.groupIndex, lastItemTag.itemIndex);
3916 _TableViewItem *pItem = FindItem(currentItemTag);
3919 pItem->StopAllAnimation();
3922 if (currentItemTag.groupIndex == lastItemTag.groupIndex && currentItemTag.itemIndex == lastItemTag.itemIndex)
3927 }while (GetNextItemPosition(currentItemTag, currentItemTag));
3931 _TableViewPresenter::GetTableViewItemPosition(_TableViewItem& item, TableViewItemTag& itemTag)
3933 TableViewItemTag lastLoadedItemPos = {-1, -1};
3934 TableViewItemTag firstLoadedItemPos = {-1, -1};
3935 __pListModel->GetLastLoadedItemIndex(lastLoadedItemPos.groupIndex, lastLoadedItemPos.itemIndex);
3936 __pListModel->GetFirstLoadedItemIndex(firstLoadedItemPos.groupIndex, firstLoadedItemPos.itemIndex);
3938 _TableViewItem* pCurrentItem = null;
3941 pCurrentItem = static_cast<_TableViewItem*>(__pListModel->LoadItem(firstLoadedItemPos.groupIndex, firstLoadedItemPos.itemIndex));
3942 if (pCurrentItem == &item)
3944 itemTag.groupIndex = firstLoadedItemPos.groupIndex;
3945 itemTag.itemIndex = firstLoadedItemPos.itemIndex;
3949 if ((firstLoadedItemPos.itemIndex == lastLoadedItemPos.itemIndex) && (firstLoadedItemPos.groupIndex == lastLoadedItemPos.groupIndex))
3953 } while (GetNextItemPosition(firstLoadedItemPos, firstLoadedItemPos));
3959 _TableViewPresenter::GetItemHeight(TableViewItemTag itemTag) const
3961 float itemHeight = 0.0f;
3963 if (__pTableView->GetTableViewStyle() == TABLE_VIEW_STYLE_SECTION && itemTag.itemIndex != -1)
3965 if (HasSectionFooter(itemTag.groupIndex))
3967 if (itemTag.itemIndex == GetItemCountAt(itemTag.groupIndex) - 1)
3969 GET_SHAPE_CONFIG(TABLEVIEW::GROUPITEM_DEFAULT_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, itemHeight);
3975 if (__pProviderAdaptor == null)
3981 for (int i = 0; i < itemTag.groupIndex; i++)
3983 int itemCount = GetItemCountAt(i);
3985 startIndex = startIndex + itemCount + 1;
3988 itemTag.itemIndex++;
3989 itemTag.itemIndex = startIndex + itemTag.itemIndex;
3991 __itemHeightList.GetAt(itemTag.itemIndex, itemHeight);
3997 _TableViewPresenter::SetItemHeight(TableViewItemTag itemTag, float height)
4001 for (int i = 0; i < itemTag.groupIndex; i++)
4003 int itemCount = GetItemCountAt(i);
4005 startIndex = startIndex + itemCount + 1;
4008 itemTag.itemIndex++;
4009 itemTag.itemIndex = startIndex + itemTag.itemIndex;
4011 float oldHeight = 0.0f;
4012 __itemHeightList.GetAt(itemTag.itemIndex, oldHeight);
4013 __itemHeightList.SetAt(height, itemTag.itemIndex);
4020 _TableViewPresenter::SetReorderMode(bool enabled)
4024 __reorderInfo.itemIndex = -1;
4025 __reorderInfo.groupIndex = -1;
4027 _TableViewItem* pItem = null;
4028 TableViewItemTag itemPos = {-1, -1};
4029 TableViewItemTag lastItemPos = {-1, -1};
4031 __pListModel->GetFirstLoadedItemIndex(itemPos.groupIndex, itemPos.itemIndex);
4032 __pListModel->GetLastLoadedItemIndex(lastItemPos.groupIndex, lastItemPos.itemIndex);
4036 pItem = FindItem(itemPos);
4040 if(pItem->IsReorderMode() == enabled)
4045 pItem->SetReorderMode(enabled);
4047 if (enabled && itemPos.itemIndex != -1)
4049 if (pItem->GetDrawingStatus() == TABLE_VIEW_ITEM_DRAWING_STATUS_PRESSED)
4051 if (SelectReorderItem(itemPos.groupIndex, itemPos.itemIndex, true))
4053 FloatPoint itemPosition = pItem->GetPositionF();
4054 FloatPoint touchPosition = pItem->GetLastTouchPressedPositionF();
4056 __reorderInfo.touchPressedPositionY = itemPosition.y + touchPosition.y - GetScrollPosition();
4057 __reorderInfo.blockedTouchReleaseState = true;
4063 if ((itemPos.itemIndex == lastItemPos.itemIndex) && (itemPos.groupIndex == lastItemPos.groupIndex))
4068 } while (GetNextItemPosition(itemPos, itemPos) == true);
4074 _TableViewPresenter::SelectReorderItem(int groupIndex, int itemIndex, bool directSelection)
4076 if (itemIndex == -1 || (!directSelection && GetPressedItemCount() > 0))
4081 TableViewItemTag itemPos = {groupIndex, itemIndex};
4082 _TableViewItem* pItem = FindItem(itemPos);
4089 pItem->SetDrawingStatus(TABLE_VIEW_ITEM_DRAWING_STATUS_PRESSED);
4090 pItem->SetItemChanged(true);
4091 pItem->Invalidate();
4093 __reorderInfo.blockedScroll = false;
4094 __reorderInfo.itemBounds = pItem->GetBoundsF();
4095 __reorderInfo.itemIndex = itemIndex;
4096 __reorderInfo.groupIndex = groupIndex;
4097 __reorderInfo.originGroupIndex = groupIndex;
4098 __reorderInfo.originItemIndex = itemIndex;
4099 __reorderInfo.itemBasisPositionY = __reorderInfo.itemBounds.y;
4101 Tizen::System::SystemTime::GetTicks(__reorderInfo.touchPressedTick);
4103 pItem->GetVisualElement()->SetZOrder(null, true);
4105 if (GetScrollAreaBounds().height < __pTableView->GetBoundsF().height)
4107 float itemHeight = pItem->GetBoundsF().height;
4109 __pListModel->GetLastLoadedItemIndex(itemPos.groupIndex, itemPos.itemIndex);
4111 pItem = FindItem(itemPos);
4115 FloatRectangle itemBounds = pItem->GetBoundsF();
4116 __reorderInfo.nonScrollableLimitArea = itemBounds.y + itemBounds.height - itemHeight;
4121 __reorderInfo.nonScrollableLimitArea = 0;
4128 _TableViewPresenter::ResetReorderItem(int groupIndex, int itemIndex)
4130 TableViewItemTag itemPos = {groupIndex, itemIndex};
4131 _TableViewItem* pItem = FindItem(itemPos);
4138 pItem->SetDrawingStatus(TABLE_VIEW_ITEM_DRAWING_STATUS_NORMAL);
4139 pItem->SetItemChanged(true);
4140 pItem->Invalidate();
4142 PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_LIST_REORDER, pItem);
4144 FloatPoint position = FloatPoint(__reorderInfo.itemBounds.x, __reorderInfo.itemBounds.y);
4145 pItem->SetPosition(position);
4147 if (__reorderInfo.originGroupIndex != __reorderInfo.groupIndex || __reorderInfo.originItemIndex != __reorderInfo.itemIndex)
4149 if (__pTableView->GetTableViewStyle() == TABLE_VIEW_STYLE_SIMPLE)
4151 __pTableView->FireTableViewItemReorderEvent(__reorderInfo.originItemIndex, __reorderInfo.itemIndex);
4153 else if (__pTableView->GetTableViewStyle() == TABLE_VIEW_STYLE_GROUPED)
4155 __pTableView->FireTableViewItemReorderEvent(__reorderInfo.originGroupIndex, __reorderInfo.originItemIndex, __reorderInfo.groupIndex, __reorderInfo.itemIndex);
4159 __reorderInfo.groupIndex = -1;
4160 __reorderInfo.itemIndex = -1;
4161 __reorderInfo.originGroupIndex = -1;
4162 __reorderInfo.originItemIndex = -1;
4163 __reorderInfo.nonScrollableLimitArea = 0;
4165 StopReorderScrollTimer();
4171 _TableViewPresenter::CheckReorderItemScrollAnimation(_TableViewItem *pItem)
4173 float currentScrollPosition = GetScrollPosition();
4174 float limitTopPositionY = currentScrollPosition;
4175 float limitBottomPositionY = currentScrollPosition + __pTableView->GetBoundsF().height - __reorderInfo.itemBounds.height;
4177 float itemPositionY = pItem->GetPositionF().y;
4179 if (itemPositionY < limitTopPositionY)
4181 if (__pReorderScrollTimer == null)
4183 __reorderInfo.isScrollDirectionUp = true;
4188 else if (itemPositionY > limitBottomPositionY)
4190 if (__pReorderScrollTimer == null)
4192 __reorderInfo.isScrollDirectionUp = false;
4202 _TableViewPresenter::DragSelectedItem(float distance, bool relativeCoordinate)
4204 TableViewItemTag itemPos = {__reorderInfo.groupIndex, __reorderInfo.itemIndex};
4205 _TableViewItem* pItem = FindItem(itemPos);
4212 if (__firstTouchMoved)
4214 long long currentTick = 0;
4215 Tizen::System::SystemTime::GetTicks(currentTick);
4217 if (currentTick - __reorderInfo.touchPressedTick < REORDER_TOUCH_UIACTIVATE_DURATION)
4222 __firstTouchMoved = false;
4225 FloatPoint itemPosition = pItem->GetPositionF();
4227 if (relativeCoordinate)
4229 itemPosition.y = __reorderInfo.itemBasisPositionY + distance;
4233 itemPosition.y += distance;
4235 __reorderInfo.itemBasisPositionY += distance;
4238 if (itemPosition.y < 0)
4243 float scrollAreaHeight = GetScrollAreaBounds().height;
4244 float screenHeight = __pTableView->GetBoundsF().height;
4245 float limitBottomPositionY = 0.0f;
4247 if (scrollAreaHeight < screenHeight)
4249 limitBottomPositionY = __reorderInfo.nonScrollableLimitArea;
4253 limitBottomPositionY = scrollAreaHeight - __reorderInfo.itemBounds.height;
4256 if (itemPosition.y > limitBottomPositionY)
4258 itemPosition.y = limitBottomPositionY;
4261 pItem->SetPosition(itemPosition);
4264 if (CheckReorderItemScrollAnimation(pItem))
4266 if (__pReorderScrollTimer == null)
4268 StartReorderScrollTimer();
4273 if (__pReorderScrollTimer != null)
4275 StopReorderScrollTimer();
4280 TableViewItemTag moveItemTag = {-1, -1};
4282 if (CheckReorderItemPosition(pItem, moveItemTag))
4284 if (moveItemTag.itemIndex == -1)
4286 int destGroupIndex = moveItemTag.groupIndex;
4288 if (destGroupIndex != 0 && destGroupIndex == __reorderInfo.groupIndex)
4293 if (moveItemTag.groupIndex == 0 || !__pProviderAdaptor->IsReorderable(__reorderInfo.groupIndex, destGroupIndex))
4295 __reorderInfo.blockedScroll = true;
4301 ReorderItem(moveItemTag.groupIndex, moveItemTag.itemIndex);
4308 _TableViewPresenter::CheckReorderItemPosition(_TableViewItem* pItem, TableViewItemTag& reorderItemTag)
4310 TableViewItemTag currentItemTag = {__reorderInfo.groupIndex, __reorderInfo.itemIndex};
4311 TableViewItemTag previousItemTag = {-1, -1};
4312 TableViewItemTag nextItemTag = {-1, -1};
4314 FloatRectangle itemBounds = pItem->GetBoundsF();
4316 if (GetPreviousItemPosition(currentItemTag, previousItemTag))
4318 _TableViewItem* pPreviousItem = LoadItem(previousItemTag.groupIndex, previousItemTag.itemIndex);
4320 if (pPreviousItem != null)
4322 FloatRectangle previousItemBounds = pPreviousItem->GetBoundsF();
4324 if (itemBounds.y < previousItemBounds.y + (previousItemBounds.height / 2))
4326 //return previousItemIndex;
4327 reorderItemTag.groupIndex = previousItemTag.groupIndex;
4328 reorderItemTag.itemIndex = previousItemTag.itemIndex;
4335 if (GetNextItemPosition(currentItemTag, nextItemTag))
4337 _TableViewItem* pNextItem = LoadItem(nextItemTag.groupIndex, nextItemTag.itemIndex);
4339 if (pNextItem != null)
4341 FloatRectangle nextItemBounds = pNextItem->GetBoundsF();
4343 if (itemBounds.y + itemBounds.height > nextItemBounds.y + (nextItemBounds.height / 2))
4345 //return nextItemIndex;
4346 reorderItemTag.groupIndex = nextItemTag.groupIndex;
4347 reorderItemTag.itemIndex = nextItemTag.itemIndex;
4354 reorderItemTag.groupIndex = -1;
4355 reorderItemTag.itemIndex = -1;
4361 _TableViewPresenter::ReorderItem(int destinationGroupIndex, int destinationItemIndex)
4363 TableViewItemTag itemPos = {destinationGroupIndex, destinationItemIndex};
4365 _TableViewItem* pItem = FindItem(itemPos);
4372 if (pItem->IsAnimationPlaying())
4377 FloatRectangle destinationItemBounds = pItem->GetBoundsF();
4379 FloatPoint destinationItemPosition = FloatPoint(destinationItemBounds.x, 0.0f);
4381 if ( __reorderInfo.itemIndex > destinationItemIndex && __reorderInfo.groupIndex == destinationGroupIndex)
4383 destinationItemPosition.y = __reorderInfo.itemBounds.y + __reorderInfo.itemBounds.height - destinationItemBounds.height;
4384 __reorderInfo.itemBounds.y = destinationItemBounds.y;
4386 if (destinationItemIndex == -1)
4388 destinationGroupIndex--;
4389 int itemCount = GetItemCountAt(destinationGroupIndex);
4390 destinationItemIndex = itemCount;
4395 destinationItemPosition.y = __reorderInfo.itemBounds.y;
4396 __reorderInfo.itemBounds.y = destinationItemBounds.y + destinationItemBounds.height - __reorderInfo.itemBounds.height;
4398 if (destinationItemIndex == -1)
4400 destinationItemIndex = 0;
4404 __pListModel->MoveItem(__reorderInfo.groupIndex, __reorderInfo.itemIndex, destinationGroupIndex, destinationItemIndex);
4406 if (!pItem->MoveItem(destinationItemPosition, REORDER_ITEM_MOVE_ANIMATION_DURATION, 0))
4408 pItem->SetPosition(destinationItemPosition);
4411 __reorderInfo.itemIndex = destinationItemIndex;
4412 __reorderInfo.groupIndex = destinationGroupIndex;
4418 _TableViewPresenter::StartReorderScrollTimer(void)
4420 StopReorderScrollTimer();
4422 __pReorderScrollTimer = new (std::nothrow) Tizen::Base::Runtime::Timer;
4423 SysTryReturnVoidResult(NID_UI_CTRL, __pReorderScrollTimer != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
4425 result r = __pReorderScrollTimer->Construct(*this);
4426 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
4428 r = __pReorderScrollTimer->Start(REORDER_SCROLL_ANIMATION_TIMER_DURATION);
4429 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
4434 StopReorderScrollTimer();
4438 _TableViewPresenter::StopReorderScrollTimer(void)
4440 delete __pReorderScrollTimer;
4441 __pReorderScrollTimer = null;
4446 _TableViewPresenter::UpdateLayout(void)
4452 _TableViewPresenter::CheckItemHeightAndRefreshLayout(TableViewItemTag itemTag, bool downScroll)
4454 _TableViewItem* pItem = FindItem(itemTag);
4461 if (pItem->IsAnimationPlaying())
4466 FloatRectangle itemBounds = pItem->GetBoundsF();
4468 if (_FloatCompare(GetItemHeight(itemTag), itemBounds.height))
4473 float newHeight = itemBounds.height;
4474 float originHeight = SetItemHeight(itemTag, newHeight);
4475 float dist = newHeight - originHeight;
4477 AdjustClientAreaBounds(false, dist);
4481 itemBounds.y += dist;
4482 pItem->SetBounds(itemBounds);
4485 AttachNextItemsToBottom(itemTag);
4491 _TableViewPresenter::CreateItemHeightList(float defaultGroupItemHeight, float defaultItemHeight)
4493 int groupCount = GetGroupCount();
4495 result r = __itemHeightList.SetCapacity(GetItemCount());
4496 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
4498 for (int i = 0; i < groupCount; i++)
4500 int itemCount = GetItemCountAt(i);
4502 if (__pTableView->GetTableViewStyle() == TABLE_VIEW_STYLE_SIMPLE)
4504 __itemHeightList.Add(0.0f);
4508 __itemHeightList.Add(defaultGroupItemHeight);
4511 for (int j = 0; j < itemCount; j++)
4513 __itemHeightList.Add(defaultItemHeight);
4520 DeleteItemHeightList();
4526 _TableViewPresenter::DeleteItemHeightList(void)
4528 __itemHeightList.RemoveAll();
4532 _TableViewPresenter::RefreshItemHeightList(int groupIndex, int itemIndex, TableViewRefreshType refreshType)
4534 float defaultItemHeight = __pProviderAdaptor->GetDefaultItemHeight();
4535 float defaultGroupItemHeight = __pProviderAdaptor->GetDefaultGroupItemHeight();
4538 for (int i = 0; i < groupIndex; i++)
4540 int itemCount = GetItemCountAt(i);
4541 startIndex = startIndex + itemCount + 1;
4544 int targetIndex = startIndex + itemIndex + 1;
4546 if (refreshType == TABLE_VIEW_REFRESH_TYPE_ITEM_ADD)
4548 if (itemIndex == -1)
4550 result r = __itemHeightList.SetCapacity(GetItemCount());
4551 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));
4553 int itemCount = GetItemCountAt(groupIndex);
4554 for (int i = 0; i < itemCount; i++)
4556 __itemHeightList.InsertAt(defaultItemHeight, targetIndex);
4559 __itemHeightList.InsertAt(defaultGroupItemHeight, targetIndex);
4564 __itemHeightList.InsertAt(defaultItemHeight, targetIndex);
4567 else if (refreshType == TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE)
4569 if (itemIndex == -1)
4571 int itemCount = GetItemCountAt(groupIndex) + 1;
4573 for (int i = 0; i < itemCount; i++)
4575 __itemHeightList.RemoveAt(targetIndex);
4580 __itemHeightList.RemoveAt(targetIndex);
4588 _TableViewPresenter::CreateSectionAlignmentList(void)
4590 if (__pTableView->GetTableViewStyle() != TABLE_VIEW_STYLE_SECTION)
4595 int groupCount = GetGroupCount();
4597 result r = __sectionAlignmentList.SetCapacity(GetGroupCount());
4598 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));
4600 _TableViewSectionStringAlignment alignment;
4601 alignment.headerHorizontalAlignment = ALIGNMENT_LEFT;
4602 alignment.footerHorizontalAlignment = ALIGNMENT_RIGHT;
4604 for (int i = 0; i < groupCount; i++)
4607 __sectionAlignmentList.Add(alignment);
4614 _TableViewPresenter::DeleteSectionAlignmentList(void)
4616 __sectionAlignmentList.RemoveAll();
4620 _TableViewPresenter::RefreshSectionAlignmentList(int groupIndex, TableViewRefreshType refreshType)
4622 if (__pTableView->GetTableViewStyle() != TABLE_VIEW_STYLE_SECTION)
4627 if (refreshType == TABLE_VIEW_REFRESH_TYPE_ITEM_ADD)
4629 _TableViewSectionStringAlignment alignment;
4630 alignment.headerHorizontalAlignment = ALIGNMENT_LEFT;
4631 alignment.footerHorizontalAlignment = ALIGNMENT_RIGHT;
4633 __sectionAlignmentList.InsertAt(alignment, groupIndex);
4635 else if (refreshType == TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE)
4637 __sectionAlignmentList.RemoveAt(groupIndex);
4644 _TableViewPresenter::CaptureAndStartRemoveItemAnimation(int groupIndex, int itemIndex)
4646 TableViewItemTag itemTag = {groupIndex, itemIndex};
4647 _TableViewItem* pItem = FindItem(itemTag);
4654 FloatRectangle itemBounds = pItem->GetBoundsF();
4655 result r = E_SUCCESS;
4657 _VisualElement* pVisualElement = null;
4658 String animationName(L"REMOVE_ITEM_ANIMATION");
4659 Canvas* pCanvas = null;
4660 VisualElementValueAnimation* pAnimation = __pTableView->GetVisualElementValueAnimation(animationName);
4662 FloatDimension startValue(100.0f, itemBounds.height);
4663 FloatDimension endValue(0.0f, 0.0f);
4665 Tizen::Graphics::Bitmap* pBitmap = pItem->GetCapturedBitmapN(true);
4667 if (pBitmap == null)
4673 pVisualElement = new (std::nothrow) _VisualElement();
4674 SysTryCatch(NID_UI_CTRL, pVisualElement != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
4676 r = pVisualElement->Construct();
4677 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
4679 pVisualElement->SetImplicitAnimationEnabled(false);
4680 pVisualElement->SetSurfaceOpaque(false);
4681 pVisualElement->SetBounds(FloatRectangle(itemBounds.x, itemBounds.y, itemBounds.width, itemBounds.height));
4682 pVisualElement->SetShowState(true);
4684 pCanvas = pVisualElement->GetCanvasN();
4685 SysTryCatch(NID_UI_CTRL, pCanvas != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
4688 pCanvas->DrawBitmap(FloatRectangle(0, 0, itemBounds.width, itemBounds.height), *pBitmap);
4690 pAnimation->SetDelay(0);
4691 pAnimation->SetStartValue(Variant(startValue));
4692 pAnimation->SetEndValue(Variant(endValue));
4693 pAnimation->SetDuration(REMOVE_ITEM_MOVE_ANIMATION_DURATION);
4695 r = pVisualElement->AddAnimation(animationName, *pAnimation);
4696 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
4707 pVisualElement->Destroy();
4711 _TableViewPresenter::PresetItemHeightList(void)
4713 int groupCount = GetGroupCount();
4714 float defaultGroupItemHeight = __pProviderAdaptor->GetDefaultGroupItemHeight();
4715 float defaultItemHeight = __pProviderAdaptor->GetDefaultItemHeight();
4717 for (int i = 0; i < groupCount; i++)
4719 TableViewItemTag itemTag = {i, -1};
4720 int itemCount = GetItemCountAt(i);
4722 if (_FloatCompare(GetItemHeight(itemTag), TABLEVIEW_DEFAULT_ITEM_HEIGHT_VALUE))
4724 SetItemHeight(itemTag, defaultGroupItemHeight);
4727 for (int j = 0; j < itemCount; j++)
4729 itemTag.itemIndex = j;
4731 if (_FloatCompare(GetItemHeight(itemTag), TABLEVIEW_DEFAULT_ITEM_HEIGHT_VALUE))
4733 SetItemHeight(itemTag, defaultItemHeight);
4740 _TableViewPresenter::GetTableViewItemFromControl(const _Control& source)
4742 _Control* currentControl = const_cast<_Control*>(&source);
4743 _TableViewItem* pItem = null;
4745 while (__pTableView != currentControl)
4747 pItem = dynamic_cast<_TableViewItem*>(currentControl);
4749 if ((pItem != null) || (currentControl == null))
4754 currentControl = currentControl->GetParent();
4761 _TableViewPresenter::ShowTableViewCapturedItem(int groupIndex, int itemIndex, float height)
4763 TableViewItemTag itemTag = {groupIndex, itemIndex};
4764 _TableViewItem* pItem = FindItem(itemTag);
4766 if ((pItem == null) || _FloatCompare(height, 0.0f))
4771 result r = E_SUCCESS;
4772 Canvas* pCanvas = null;
4773 FloatRectangle itemBounds = pItem->GetBoundsF();
4775 bool visibleState = pItem->GetVisibleState();
4776 pItem->SetVisibleState(true);
4777 Bitmap* pBitmap = pItem->GetCapturedBitmapN(true);
4778 pItem->SetVisibleState(visibleState);
4780 if (pBitmap == null)
4785 if (__pCapturedItemVisualElement == null)
4787 __pCapturedItemVisualElement = new (std::nothrow) _VisualElement();
4788 SysTryCatch(NID_UI_CTRL, __pCapturedItemVisualElement != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
4790 r = __pCapturedItemVisualElement->Construct();
4791 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
4793 r = GetView()->GetVisualElement()->AttachChild(*__pCapturedItemVisualElement);
4794 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to attach child to the control VisualElement.", GetErrorMessage(r));
4796 __pCapturedItemVisualElement->SetSurfaceOpaque(false);
4797 __pCapturedItemVisualElement->SetImplicitAnimationEnabled(false);
4800 __pCapturedItemVisualElement->SetShowState(true);
4801 __pCapturedItemVisualElement->SetBounds(FloatRectangle(itemBounds.x, itemBounds.y, itemBounds.width, height));
4803 pCanvas = __pCapturedItemVisualElement->GetCanvasN();
4804 SysTryCatch(NID_UI_CTRL, pCanvas != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
4806 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
4808 pCanvas->DrawBitmap(FloatPoint(0.0f, 0.0f), *pBitmap);
4818 __pCapturedItemVisualElement->Destroy();
4822 _TableViewPresenter::SetLoadedItemsVisibleFromPosition(float position, bool visible)
4824 _TableViewItem* pItem;
4825 FloatRectangle itemBounds;
4826 TableViewItemTag current;
4827 current.groupIndex = __expandableItemTag.groupIndex;
4828 current.itemIndex = __expandableItemTag.itemIndex;
4830 int itemCountInGroup = __pListModel->GetItemCountInGroup(__expandableItemTag.groupIndex);
4832 for (int i = 0; i < itemCountInGroup; i++)
4834 current.itemIndex = i;
4838 pItem = LoadItem(current.groupIndex, current.itemIndex);
4846 pItem = FindItem(current);
4853 itemBounds = pItem->GetBoundsF();
4857 if ((position >= itemBounds.y) && (position < itemBounds.y + itemBounds.height))
4859 ShowTableViewCapturedItem(current.groupIndex, current.itemIndex, position - itemBounds.y);
4860 pItem->SetVisibleState(false);
4865 pItem->SetVisibleState(true);
4870 if (position < itemBounds.y)
4872 UnloadItem(current);
4874 else if ((position >= itemBounds.y) && (position < itemBounds.y + itemBounds.height))
4876 pItem->SetVisibleState(false);
4877 ShowTableViewCapturedItem(current.groupIndex, current.itemIndex, position - itemBounds.y);
4881 pItem->SetVisibleState(true);
4888 _TableViewPresenter::MoveLoadedItemsFromPosition(float position)
4890 FloatRectangle itemBounds;
4891 float itemPosition = position;
4893 TableViewItemTag current;
4894 TableViewItemTag next;
4896 current.groupIndex = __expandableItemTag.groupIndex;
4897 current.itemIndex = __pListModel->GetItemCountInGroup(__expandableItemTag.groupIndex) -1;
4899 float screenPosition = GetScrollPosition();
4900 FloatRectangle screenBounds = __pTableView->GetBoundsF();
4901 screenPosition += screenBounds.height;
4903 _TableViewItem* pItem = null;
4904 while (GetNextItemPosition(current, next))
4906 if (screenPosition > itemPosition)
4908 pItem = LoadItem(next.groupIndex, next.itemIndex);
4912 pItem = FindItem(next);
4920 itemBounds = pItem->GetBoundsF();
4921 itemBounds.y = itemPosition;
4922 pItem->SetBounds(itemBounds);
4923 itemPosition += itemBounds.height;
4930 _TableViewPresenter::ExpandGroupAnimationFinished(bool completedNormally)
4932 if (completedNormally == false)
4934 TableViewItemTag current;
4935 TableViewItemTag next;
4937 current.groupIndex = __expandableItemTag.groupIndex;
4938 current.itemIndex = -1;
4940 _TableViewItem* pNextItem = null;
4941 _TableViewItem* pCurrentItem = null;
4942 pCurrentItem = LoadItem(current.groupIndex, current.itemIndex);
4944 if (pCurrentItem == null)
4949 FloatRectangle itemBounds;
4950 FloatRectangle screenBounds = __pTableView->GetBoundsF();
4951 float screenPosition = GetScrollPosition() + screenBounds.height;
4952 float nextItemPositionY = pCurrentItem->GetBoundsF().y + pCurrentItem->GetBoundsF().height;
4954 while (GetNextItemPosition(current, next))
4956 if (screenPosition >= nextItemPositionY)
4958 pCurrentItem = LoadItem(current.groupIndex, current.itemIndex);
4959 if (pCurrentItem == null)
4963 pNextItem = LoadItem(next.groupIndex, next.itemIndex);
4964 if (pNextItem == null)
4968 pNextItem->SetVisibleState(true);
4969 itemBounds = pNextItem->GetBoundsF();
4970 itemBounds.y = pCurrentItem->GetBoundsF().y + pCurrentItem->GetBoundsF().height;
4971 pNextItem->SetBounds(itemBounds);
4972 nextItemPositionY = itemBounds.y + itemBounds.height;
4976 UnloadItem(next.groupIndex, next.itemIndex);
4984 int currentGroupIndex = -1;
4985 int currentItemIndex = -1;
4986 GetBottomDrawnItemIndex(currentGroupIndex, currentItemIndex);
4988 int lastLoadedGroupIndex = -1;
4989 int lastLoadedItemIndex = -1;
4990 __pListModel->GetLastLoadedItemIndex(lastLoadedGroupIndex, lastLoadedItemIndex);
4992 TableViewItemTag current;
4993 current.groupIndex = currentGroupIndex;
4994 current.itemIndex = currentItemIndex;
4996 _TableViewItem* pCurrentItem;
4997 pCurrentItem = FindItem(current);
4998 if (pCurrentItem != null)
5000 pCurrentItem->SetVisibleState(true);
5003 for (int j = currentGroupIndex; j <= lastLoadedGroupIndex; j++)
5005 int itemCount = GetItemCountAt(j);
5007 for (int i = -1; i < itemCount; i++)
5009 if (i <= currentItemIndex && j == currentGroupIndex)
5021 _TableViewPresenter::CollapseGroupAnimationFinished(bool completedNormally)
5023 _TableViewItem* pItem = null;
5024 TableViewItemTag itemTag = {-1, -1};
5025 float groupTotalHeight = 0;
5026 int itemCountInGroup = __pListModel->GetItemCountInGroup(__expandableItemTag.groupIndex);
5027 for (int i = 0; i < itemCountInGroup; i++)
5029 pItem = static_cast<_TableViewItem*>(__pListModel->GetItemFromTemporaryBuffer(__expandableItemTag.groupIndex, i));
5030 groupTotalHeight += pItem->GetItemHeight();
5031 itemTag.groupIndex = __expandableItemTag.groupIndex;
5032 itemTag.itemIndex = i;
5033 SetItemHeight(itemTag, pItem->GetItemHeight());
5036 if (completedNormally == false)
5038 TableViewItemTag current;
5039 TableViewItemTag next;
5041 current.groupIndex = __expandableItemTag.groupIndex;
5042 current.itemIndex = -1;
5044 for (int i = 0; i < itemCountInGroup; i++)
5046 UnloadItem(__expandableItemTag.groupIndex, i);
5049 _TableViewItem* pCurrentItem = LoadItem(current.groupIndex, current.itemIndex);
5050 FloatRectangle itemBounds = pCurrentItem->GetBoundsF();
5051 itemBounds.y = CalculateItemPositionY(current.groupIndex, current.itemIndex);
5052 pCurrentItem->SetBounds(itemBounds);
5054 float nextItemPositionY = pCurrentItem->GetBoundsF().y + pCurrentItem->GetBoundsF().height;
5056 FloatRectangle screenBounds = __pTableView->GetBoundsF();
5057 float screenPosition = GetScrollPosition() + screenBounds.height;
5059 while (GetNextItemPosition(current, next))
5062 if (screenPosition >= nextItemPositionY)
5064 pCurrentItem = LoadItem(current.groupIndex, current.itemIndex);
5065 if (pCurrentItem == null)
5070 pCurrentItem->SetVisibleState(true);
5071 itemBounds = pCurrentItem->GetBoundsF();
5072 itemBounds.y = nextItemPositionY;
5073 pCurrentItem->SetBounds(itemBounds);
5074 nextItemPositionY = pCurrentItem->GetBoundsF().y + pCurrentItem->GetBoundsF().height;
5078 UnloadItem(current.groupIndex, current.itemIndex);
5082 int currentGroupIndex = -1;
5083 int currentItemIndex = -1;
5084 GetTopDrawnItemIndex(currentGroupIndex, currentItemIndex);
5085 if (__expandableItemTag.groupIndex < currentGroupIndex)
5087 SetScrollPosition(GetScrollPosition() - groupTotalHeight, false);
5092 int currentGroupIndex = -1;
5093 int currentItemIndex = -1;
5094 GetTopDrawnItemIndex(currentGroupIndex, currentItemIndex);
5096 int firstLoadedGroupIndex = -1;
5097 int firstLoadedItemIndex = -1;
5098 __pListModel->GetFirstLoadedItemIndex(firstLoadedGroupIndex, firstLoadedItemIndex);
5100 for (int j = firstLoadedGroupIndex; j <= currentGroupIndex; j++)
5102 int itemCount = GetItemCountAt(j);
5104 for (int i = -1; i < itemCount; i++)
5106 if (i >= currentItemIndex && j == currentGroupIndex)
5115 for (int i = 0; i < itemCountInGroup; i++)
5117 UnloadItem(__expandableItemTag.groupIndex, i);
5120 GetTopDrawnItemIndex(currentGroupIndex, currentItemIndex);
5121 TableViewItemTag currentItemTag;
5122 currentItemTag.groupIndex = currentGroupIndex;
5123 currentItemTag.itemIndex = currentItemIndex;
5125 _TableViewItem* pItem = FindItem(currentItemTag);
5128 FloatRectangle itemBounds = pItem->GetBoundsF();
5129 itemBounds.y = CalculateItemPositionY(currentGroupIndex, currentItemIndex);
5130 pItem->SetBounds(itemBounds);
5131 AttachNextItemsToBottom(currentItemTag);
5132 if (__expandableItemTag.groupIndex < currentGroupIndex)
5134 SetScrollPosition(itemBounds.y, false);
5139 AdjustClientAreaBounds(false, -groupTotalHeight);
5143 _TableViewPresenter::OnVisualElementAnimationStarted(const Tizen::Ui::Animations::VisualElementAnimation& animation, const Tizen::Base::String& keyName, Tizen::Ui::Animations::VisualElement& target)
5145 if (keyName == L"REMOVE_ITEM_ANIMATION")
5150 if (keyName == L"SCROLL_PANEL_SCROLLING_ANIMATION")
5152 __scrollHeightOnFlickStarted = GetScrollAreaBounds().height;
5153 __scrollPositionOnFlickStarted = GetScrollPosition();
5156 _ScrollPanelPresenter::OnVisualElementAnimationStarted(animation, keyName, target);
5160 _TableViewPresenter::OnVisualElementAnimationRepeated(const Tizen::Ui::Animations::VisualElementAnimation& animation, const Tizen::Base::String& keyName, Tizen::Ui::Animations::VisualElement& target, long currentRepeatCount)
5162 if (keyName == L"REMOVE_ITEM_ANIMATION")
5166 _ScrollPanelPresenter::OnVisualElementAnimationRepeated(animation, keyName, target, currentRepeatCount);
5170 _TableViewPresenter::OnVisualElementAnimationFinished(const Tizen::Ui::Animations::VisualElementAnimation& animation, const Tizen::Base::String& keyName, Tizen::Ui::Animations::VisualElement& target, bool completedNormally)
5172 if (__isAnimationCallbackBlocked)
5177 if (keyName == L"REMOVE_ITEM_ANIMATION")
5179 _VisualElement* pVisualElement = GetView()->GetVisualElement();
5181 pVisualElement->DetachChild(target);
5186 else if (keyName == L"EXPAND_GROUP_ANIMATION")
5188 if (__pCapturedItemVisualElement)
5190 __pCapturedItemVisualElement->SetShowState(false);
5192 ExpandGroupAnimationFinished(completedNormally);
5194 if (__scrollToItemTag.startedAnimation)
5196 __scrollToItemTag.startedAnimation = false;
5197 ScrollToItem(__scrollToItemTag.groupIndex, __scrollToItemTag.itemIndex, __scrollToItemTag.itemAlignment, __scrollToItemTag.shiftingDistance);
5201 else if (keyName == L"COLLAPSE_GROUP_ANIMATION")
5203 if (__pCapturedItemVisualElement)
5205 __pCapturedItemVisualElement->SetShowState(false);
5207 CollapseGroupAnimationFinished(completedNormally);
5209 if (__scrollToItemTag.startedAnimation)
5211 __scrollToItemTag.startedAnimation = false;
5212 ScrollToItem(__scrollToItemTag.groupIndex, __scrollToItemTag.itemIndex, __scrollToItemTag.itemAlignment, __scrollToItemTag.shiftingDistance);
5217 _ScrollPanelPresenter::OnVisualElementAnimationFinished(animation, keyName, target, completedNormally);
5221 _TableViewPresenter::OnTickOccurred(const Tizen::Ui::Animations::VisualElementAnimation& animation, const Tizen::Base::String& keyName, Tizen::Ui::Animations::VisualElement& target, const Tizen::Ui::Variant& currentValue)
5223 _VisualElement* pVisualElement = __pTableView->GetVisualElement();
5225 if (&target != pVisualElement)
5230 if (keyName == L"REMOVE_ITEM_ANIMATION")
5232 Dimension value = currentValue.ToDimension();
5233 target.SetOpacity(value.width);
5235 FloatRectangle bounds = target.GetBounds();
5236 bounds.height = value.height;
5237 target.SetBounds(bounds);
5239 target.SetFlushNeeded();
5243 else if (keyName == L"EXPAND_GROUP_ANIMATION")
5245 float currentPosition = currentValue.ToFloat();
5246 SetLoadedItemsVisibleFromPosition(currentPosition, true);
5247 MoveLoadedItemsFromPosition(currentPosition);
5251 else if (keyName == L"COLLAPSE_GROUP_ANIMATION")
5253 float currentPosition = currentValue.ToFloat();
5254 SetLoadedItemsVisibleFromPosition(currentPosition, false);
5255 MoveLoadedItemsFromPosition(currentPosition);
5259 else if (keyName == L"SWEEP_ITEM_ANIMATION")
5261 float currentPosition = currentValue.ToFloat();
5262 float moveDestance = currentPosition - __sweptItemPosition.x;
5263 SweepItem(moveDestance);
5268 _ScrollPanelPresenter::OnTickOccurred(animation, keyName, target, currentValue);
5272 _TableViewPresenter::OnAccessibilityItemRefreshed(const _AccessibilityContainer& control, const _AccessibilityElement& element, _AccessibilityFocusDirection direction)
5274 TableViewItemTag itemPos = {-1, -1};
5276 if (direction == _ACCESSIBILITY_FOCUS_DIRECTION_NEXT)
5278 GetFirstItem(itemPos);
5279 if (GetAccessibilityElementFocusedState() == false && FindItem(itemPos) == null)
5281 ScrollToItem(itemPos.groupIndex, itemPos.itemIndex, TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_TOP);
5286 else if (direction == _ACCESSIBILITY_FOCUS_DIRECTION_PREVIOUS)
5288 GetLastItem(itemPos);
5290 if (IsGroupExpanded(itemPos.groupIndex) == false)
5292 itemPos.itemIndex = -1;
5295 if (GetAccessibilityElementFocusedState() == false && FindItem(itemPos) == null)
5297 ScrollToItem(itemPos.groupIndex, itemPos.itemIndex, TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_BOTTOM);
5307 _TableViewPresenter::OnOcurredOverflowItems(const int currentCashSize, const int overflowCount)
5309 return IsCachingItemsTotalHeightLessThanViewHeight();
5313 _TableViewPresenter::OnKeyPressed(const _Control& source, const _KeyInfo& keyInfo)
5315 if (!__pTableView->IsFocusModeStateEnabled())
5320 _KeyCode keyCode = keyInfo.GetKeyCode();
5321 _Control* pFocusedControl = null;
5322 _Window* pTop = source.GetRootWindow();
5325 pFocusedControl = pTop->GetCurrentFocusControl();
5328 _TableViewItem* pItem = null;
5329 TableViewItemTag itemPos = {-1, -1};
5334 if (pFocusedControl != null)
5336 pItem = dynamic_cast<_TableViewItem*>(pFocusedControl);
5339 _Control* pParentControl = pFocusedControl->GetParent();
5340 pItem = dynamic_cast<_TableViewItem*>(pParentControl);
5345 pItem->GetItemIndex(itemPos.groupIndex, itemPos.itemIndex);
5346 TableViewItemTag firstItemPos = {-1, -1};
5347 GetFirstItem(firstItemPos);
5348 if (itemPos.groupIndex == firstItemPos.groupIndex && itemPos.itemIndex == firstItemPos.itemIndex)
5353 while (GetPreviousItemPosition(itemPos, itemPos))
5355 if (__pTableView->GetTableViewStyle() == TABLE_VIEW_STYLE_SIMPLE)
5357 TableViewItemTag firstItemPos = {-1, -1};
5358 GetFirstItem(firstItemPos);
5359 if (itemPos.groupIndex == firstItemPos.groupIndex && itemPos.itemIndex == firstItemPos.itemIndex)
5365 if (IsGroupExpanded(itemPos.groupIndex) == false)
5367 itemPos.itemIndex = -1;
5370 pItem = static_cast <_TableViewItem*>(__pListModel->LoadItem(itemPos.groupIndex, itemPos.itemIndex));
5371 if (pItem->GetBoundsF().y < GetScrollPosition())
5373 ScrollToItem(itemPos.groupIndex, itemPos.itemIndex, TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_BOTTOM);
5376 if (pItem->GetEnableState())
5378 pItem->SetFocused(true);
5392 if (pFocusedControl != null)
5394 pItem = dynamic_cast<_TableViewItem*>(pFocusedControl);
5397 _Control* pParentControl = pFocusedControl->GetParent();
5398 pItem = dynamic_cast<_TableViewItem*>(pParentControl);
5403 pItem->GetItemIndex(itemPos.groupIndex, itemPos.itemIndex);
5404 TableViewItemTag lastItemPos = {-1, -1};
5405 GetLastItem(lastItemPos);
5406 if (itemPos.groupIndex == lastItemPos.groupIndex && itemPos.itemIndex == lastItemPos.itemIndex)
5411 while (GetNextItemPosition(itemPos, itemPos))
5413 if (__pTableView->GetTableViewStyle() == TABLE_VIEW_STYLE_SIMPLE && itemPos.itemIndex == -1)
5415 itemPos.itemIndex = 0;
5418 pItem = static_cast <_TableViewItem*>(__pListModel->LoadItem(itemPos.groupIndex, itemPos.itemIndex));
5419 if (pItem->GetBoundsF().y + pItem->GetBoundsF().height > GetScrollPosition() + __pTableView->GetBoundsF().height)
5421 ScrollToItem(itemPos.groupIndex, itemPos.itemIndex, TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_TOP);
5424 if (pItem->GetEnableState())
5426 pItem->SetFocused(true);
5447 _TableViewPresenter::OnKeyReleased(const _Control& source, const _KeyInfo& keyInfo)
5449 if (!__pTableView->IsFocusModeStateEnabled())
5454 _KeyCode keyCode = keyInfo.GetKeyCode();
5456 if (keyCode == _KEY_UP || keyCode == _KEY_DOWN)
5465 _TableViewPresenter::OnDrawFocus(void)
5467 if (!__pTableView->IsFocusModeStateEnabled())
5472 _Control* pFocusedControl = null;
5473 _Window* pTop = __pTableView->GetRootWindow();
5476 pFocusedControl = pTop->GetCurrentFocusControl();
5479 _TableView* pTableView = null;
5480 _TableViewItem* pItem = null;
5481 TableViewItemTag itemPos = {-1, -1};
5483 if (pFocusedControl != null)
5485 pTableView = dynamic_cast<_TableView*>(pFocusedControl);
5486 if (pTableView != null)
5488 GetFirstItem(itemPos);
5489 if (__pTableView->GetTableViewStyle() == TABLE_VIEW_STYLE_SIMPLE)
5491 itemPos.itemIndex = 0;
5494 ScrollToItem(itemPos.groupIndex, itemPos.itemIndex, TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_TOP);
5495 pItem = FindItem(itemPos);
5498 if (pItem->GetEnableState())
5500 pItem->SetFocused(true);
5505 while (GetNextItemPosition(itemPos, itemPos))
5507 TableViewItemTag topDrawnItemIndex = {-1, -1};
5508 GetTopDrawnItem(topDrawnItemIndex);
5509 if (topDrawnItemIndex.groupIndex <= itemPos.groupIndex && topDrawnItemIndex.itemIndex <= itemPos.itemIndex)
5511 TableViewItemTag bottomDrawnItemIndex = {-1, -1};
5512 GetBottomDrawnItem(bottomDrawnItemIndex);
5513 if (bottomDrawnItemIndex.groupIndex >= itemPos.groupIndex && bottomDrawnItemIndex.itemIndex >= itemPos.itemIndex)
5515 pItem = FindItem(itemPos);
5519 ScrollToItem(itemPos.groupIndex, itemPos.itemIndex, TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_TOP);
5520 pItem = FindItem(itemPos);
5525 ScrollToItem(itemPos.groupIndex, itemPos.itemIndex, TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_TOP);
5526 pItem = FindItem(itemPos);
5531 if (pItem->GetEnableState())
5533 pItem->SetFocused(true);
5546 _TableViewPresenter::OnFocusModeStateChanged(void)
5548 _Window* pTop = __pTableView->GetRootWindow();
5552 _Control* pFocusedControl = pTop->GetCurrentFocusControl();
5554 if (pFocusedControl != null)
5556 pFocusedControl->RemoveFocusRing();
5562 _TableViewPresenter::GetAccessibilityElementFocusedState(void)
5564 _TableViewItem* pItem = null;
5565 TableViewItemTag itemPos = {-1, -1};
5566 TableViewItemTag lastItemPos = {-1, -1};
5568 __pListModel->GetFirstLoadedItemIndex(itemPos.groupIndex, itemPos.itemIndex);
5569 __pListModel->GetLastLoadedItemIndex(lastItemPos.groupIndex, lastItemPos.itemIndex);
5573 pItem = static_cast <_TableViewItem*>(__pListModel->LoadItem(itemPos.groupIndex, itemPos.itemIndex));
5574 SysTryReturn(NID_UI_CTRL, pItem != null, false, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The index is out of range.");
5576 _AccessibilityContainer* pContainer = pItem->GetAccessibilityContainer();
5577 _AccessibilityElement* pElement = null;
5579 if (pContainer != null)
5581 pElement = pContainer->GetCurrentFocusedElement();
5582 if (pElement != null)
5588 if ((itemPos.itemIndex == lastItemPos.itemIndex) && (itemPos.groupIndex == lastItemPos.groupIndex))
5593 } while (GetNextItemPosition(itemPos, itemPos) == true);
5599 _TableViewPresenter::FireItemTouchReleasedEventDuringPressing(int groupIndex, int itemIndex)
5601 TableViewItemTag fireItemPos;
5602 fireItemPos.groupIndex = groupIndex;
5603 fireItemPos.itemIndex = itemIndex;
5605 __itemTouchReleasedEventState = TABLE_VIEW_ITEM_TOUCH_RELEASED_EVENT_FIRE;
5606 _TableViewItem* pItem = FindItem(fireItemPos);
5609 pItem->FireItemTouchReleased();
5612 // for new item after UpdateTableView.
5613 pItem = FindItem(fireItemPos);
5616 if (__itemTouchReleasedEventState == TABLE_VIEW_ITEM_TOUCH_RELEASED_EVENT_UPDATE_TABLE_VIEW)
5618 __itemTouchReleasedEventState = TABLE_VIEW_ITEM_TOUCH_RELEASED_EVENT_NORMAL;
5622 pItem->SetSelectionState(true);
5623 pItem->FireItemTouchPressed();
5629 _TableViewSectionStringAlignment::operator== (const _TableViewSectionStringAlignment& rhs) const
5631 if (headerHorizontalAlignment == rhs.headerHorizontalAlignment && footerHorizontalAlignment == rhs.footerHorizontalAlignment)
5640 _TableViewSectionStringAlignment::operator!= (const _TableViewSectionStringAlignment& rhs) const
5642 if (headerHorizontalAlignment == rhs.headerHorizontalAlignment && footerHorizontalAlignment == rhs.footerHorizontalAlignment)
5650 }}} // Tizen::Ui::Controls