2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0/
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FUiCtrl_TableViewPresenter.cpp
20 * @brief This is the header file for the _TableViewPresenter class.
22 * This file contains the declarations of the _TableViewPresenter class.
25 #include <FGrpRectangle.h>
26 #include <FSysSystemTime.h>
27 #include "FUi_ResourceManager.h"
28 #include "FUi_UiTouchEvent.h"
29 #include "FUi_ResourceManager.h"
30 #include "FUiAnim_VisualElement.h"
31 #include "FUiCtrl_FastScroll.h"
32 #include "FUiCtrl_Scroll.h"
33 #include "FUiCtrl_TableView.h"
34 #include "FUiCtrl_TableViewItem.h"
35 #include "FUiCtrl_TableViewPresenter.h"
36 #include "FUiCtrl_TableViewItemProviderAdaptor.h"
37 #include "FUi_CoordinateSystemUtils.h"
38 #include "FUi_FocusManagerImpl.h"
40 #include "FUi_Window.h"
42 using namespace Tizen::Ui::Animations;
43 using namespace Tizen::Graphics;
44 using namespace Tizen::Base;
45 using namespace Tizen::Base::Runtime;
46 using namespace Tizen::Ui::Controls;
48 namespace Tizen { namespace Ui { namespace Controls
50 const float _TableViewPresenter::REORDER_SCROLL_ANIMATION_DISTANCE = 10.0f;
51 const float _TableViewPresenter::TABLEVIEW_DEFAULT_ITEM_HEIGHT_VALUE = 12.3456f;
53 _TableViewPresenter::_TableViewPresenter()
56 , __pProviderAdaptor(null)
58 , __bottomMargin(0.0f)
60 , __modelInitialized(false)
61 , __firstDrawnFlag(true)
62 , __statusChangedFlag(true)
64 , __pItemDrawingProperty(null)
65 , __pBaseVisualElement(null)
66 , __sweepOccured(false)
67 , __sweptItemPosition()
68 , __reservedScrollItemAlignment(TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_TOP)
69 , __firstTouchMoved(false)
70 , __pReorderScrollTimer(null)
72 , __itemTotalHeight(0.0f)
73 , __pCapturedItemVisualElement(null)
74 , __pFastScrollTimer(null)
75 , __isFastScrollTimerEnabled(false)
76 , __scrollHeightOnFlickStarted(0)
77 , __scrollPositionOnFlickStarted(0)
78 , __isAnimationCallbackBlocked(false)
79 , __lockLoadItemWithScroll(false)
80 , __isRestoreFocus(false)
81 , __isAnnexFocused(false)
82 , __isTableViewFocused(false)
83 , __itemTouchReleasedEventState(TABLE_VIEW_ITEM_TOUCH_RELEASED_EVENT_NORMAL)
85 , __isOrientationChanged(false)
86 , __isFocusedDuringOrientationChange(false)
87 , __isUpdatingTableView(false)
89 __sweptItemTag.itemIndex = -1;
90 __sweptItemTag.groupIndex = -1;
92 __reservedScrollItemIndex.itemIndex = -1;
93 __reservedScrollItemIndex.groupIndex = -1;
95 __expandableItemTag.groupIndex = -1;
96 __expandableItemTag.itemIndex = -1;
98 __focusItemTag.groupIndex = -1;
99 __focusItemTag.itemIndex = -1;
102 _TableViewPresenter::~_TableViewPresenter()
108 _TableViewPresenter::GetView() const
114 _TableViewPresenter::GetModel(void) const
120 _TableViewPresenter::Initialize(_TableView* pTableView)
122 _ScrollPanelPresenter::Initialize(*pTableView);
124 __pTableView = pTableView;
125 __pBaseVisualElement = __pTableView->GetVisualElement();
126 __pBaseVisualElement->SetClipChildrenEnabled(true);
127 __pBaseVisualElement->SetSurfaceOpaque(false);
129 result r = __itemHeightList.Construct();
130 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, false, E_OUT_OF_MEMORY, "[%s] Memory allocation Failed.", GetErrorMessage(E_OUT_OF_MEMORY));
132 r = __sectionAlignmentList.Construct();
133 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, false, E_OUT_OF_MEMORY,"[%s] Memory allocation Failed.", GetErrorMessage(E_OUT_OF_MEMORY));
136 __pListModel = new (std::nothrow) _ListViewModel();
137 SysTryReturn(NID_UI_CTRL, __pListModel != null, false, E_OUT_OF_MEMORY, "[%s] Memory allocation Failed.", GetErrorMessage(E_OUT_OF_MEMORY));
138 __pListModel->SetListViewModelDelegate(this);
140 __pItemDrawingProperty = new (std::nothrow) _ItemDrawingProperty();
141 SysTryReturn(NID_UI_CTRL, __pItemDrawingProperty != null, false, E_OUT_OF_MEMORY, "[%s] Memory allocation Failed.", GetErrorMessage(E_OUT_OF_MEMORY));
144 __pFastScrollTimer = new (std::nothrow) Timer();
145 SysTryCatch(NID_UI_CTRL, __pFastScrollTimer != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation Failed.", GetErrorMessage(E_OUT_OF_MEMORY));
147 r = __pFastScrollTimer->Construct(*this);
148 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
153 if (__isFastScrollTimerEnabled)
155 __pFastScrollTimer->Cancel();
158 delete __pFastScrollTimer;
159 __pFastScrollTimer = null;
165 _TableViewPresenter::Construct(_TableView* pTableView)
167 result r = E_SUCCESS;
171 init = Initialize(pTableView);
172 SysTryCatch(NID_UI_CTRL, init == true, , r = GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
182 _TableViewPresenter::Dispose(void)
184 DeleteItemHeightList();
185 DeleteSectionAlignmentList();
186 DetachContextItem(__sweptItemTag);
191 delete __pProviderAdaptor;
192 __pProviderAdaptor = null;
194 delete __pItemDrawingProperty;
195 __pItemDrawingProperty = null;
197 delete __pReorderScrollTimer;
198 __pReorderScrollTimer = null;
200 if (__isFastScrollTimerEnabled)
202 __pFastScrollTimer->Cancel();
205 delete __pFastScrollTimer;
206 __pFastScrollTimer = null;
208 if (__pCapturedItemVisualElement)
210 GetView()->GetVisualElement()->DetachChild(*__pCapturedItemVisualElement);
211 __pCapturedItemVisualElement->Destroy();
213 __pCapturedItemVisualElement = null;
217 _TableViewPresenter::SetItemProvider(const _TableViewItemProvider* pProvider)
219 result r = E_SUCCESS;
221 _TableViewItemProviderAdaptor* pProviderAdaptor = static_cast <_TableViewItemProviderAdaptor*>(__pListModel->GetItemProviderAdaptor());
222 if(pProviderAdaptor != null)
224 _TableViewItemProvider* provider = pProviderAdaptor->GetItemProvider();
225 if(provider != null && provider == pProvider)
231 if (pProviderAdaptor == null)
233 pProviderAdaptor = new (std::nothrow) _TableViewItemProviderAdaptor();
234 SysTryReturn(NID_UI_CTRL, pProviderAdaptor != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation Failed.", GetErrorMessage(E_OUT_OF_MEMORY));
236 SetTableViewItemProviderAdaptor(pProviderAdaptor);
239 _TableViewItemProvider* pNewProvider = null;
241 if (pProvider != null)
243 pNewProvider = const_cast <_TableViewItemProvider*>(pProvider);
247 __pListModel->RemoveAllItem(false);
250 pProviderAdaptor->SetItemProvider(pNewProvider);
251 pProviderAdaptor->SetListWidth(__pTableView->GetBoundsF().width - (GetLeftMargin() * 2));
252 pProviderAdaptor->SetTableViewStyle(__pTableView->GetTableViewStyle());
258 _TableViewPresenter::GetItemFromPosition(const Tizen::Graphics::FloatPoint& position, TableViewItemTag& itemPos) const
260 _TableViewItem* pItem = null;
261 TableViewItemTag lastItemPos = {-1, -1};
263 __pListModel->GetFirstLoadedItemIndex(itemPos.groupIndex, itemPos.itemIndex);
264 __pListModel->GetLastLoadedItemIndex(lastItemPos.groupIndex, lastItemPos.itemIndex);
268 pItem = static_cast <_TableViewItem*>(__pListModel->LoadItem(itemPos.groupIndex, itemPos.itemIndex));
269 SysTryCatch(NID_UI_CTRL, pItem != null, , E_OUT_OF_RANGE, "[%s] Group Index (%d) Item Index (%d) The index is out of range.", GetErrorMessage(E_OUT_OF_RANGE),itemPos.groupIndex,itemPos.itemIndex);
271 FloatRectangle itemBounds = pItem->GetBoundsF();
272 if (itemBounds.Contains(position))
277 if ((itemPos.itemIndex == lastItemPos.itemIndex) && (itemPos.groupIndex == lastItemPos.groupIndex))
282 } while (GetNextItemPosition(itemPos, itemPos));
285 itemPos.itemIndex = -1;
286 itemPos.groupIndex = -1;
288 return E_OUT_OF_RANGE;
292 _TableViewPresenter::GetTopDrawnItemIndex(int& groupIndex, int& itemIndex) const
294 result r = E_SUCCESS;
296 TableViewItemTag itemPos;
297 r = GetTopDrawnItem(itemPos);
299 groupIndex = itemPos.groupIndex;
300 itemIndex = itemPos.itemIndex;
306 _TableViewPresenter::SetTopDrawnItemIndex(int groupIndex, int itemIndex)
310 return E_INVALID_ARG;
313 if ((groupIndex < 0) || (groupIndex >= GetGroupCount()) || (itemIndex < -1) || (itemIndex >= GetItemCountAt(groupIndex)))
315 return E_OUT_OF_RANGE;
318 ScrollToItem(groupIndex, itemIndex, TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_TOP);
324 _TableViewPresenter::GetBottomDrawnItemIndex(int& groupIndex, int& itemIndex) const
326 result r = E_SUCCESS;
328 TableViewItemTag itemPos;
329 r = GetBottomDrawnItem(itemPos);
331 groupIndex = itemPos.groupIndex;
332 itemIndex = itemPos.itemIndex;
338 _TableViewPresenter::SetBottomDrawnItemIndex(int groupIndex, int itemIndex)
342 return E_INVALID_ARG;
345 if ((groupIndex < 0) || (groupIndex >= GetGroupCount()) || (itemIndex < -1) || (itemIndex >= GetItemCountAt(groupIndex)))
347 return E_OUT_OF_RANGE;
350 ScrollToItem(groupIndex, itemIndex, TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_BOTTOM);
356 _TableViewPresenter::GetGroupCount(void) const
358 return __pListModel->GetAllGroupCount();
363 _TableViewPresenter::GetItemCountAt(int groupIndex) const
365 return __pListModel->GetItemCountInGroup(groupIndex);
369 _TableViewPresenter::HasSectionHeader(int groupIndex) const
371 if (__pProviderAdaptor == null || __pTableView->GetTableViewStyle() != TABLE_VIEW_STYLE_SECTION)
376 return __pProviderAdaptor->HasSectionHeader(groupIndex);
380 _TableViewPresenter::HasSectionFooter(int groupIndex) const
382 if (__pProviderAdaptor == null || __pTableView->GetTableViewStyle() != TABLE_VIEW_STYLE_SECTION)
387 return __pProviderAdaptor->HasSectionFooter(groupIndex);
391 _TableViewPresenter::GetItemCount(void) const
393 return __pListModel->GetAllItemCount();
397 _TableViewPresenter::RefreshTableView(int groupIndex, int itemIndex, TableViewRefreshType type, bool animation)
399 _TableViewItemProviderAdaptor* pProviderAdaptor = __pProviderAdaptor;
401 SysTryReturn(NID_UI_CTRL, pProviderAdaptor != null, E_INVALID_STATE, E_INVALID_STATE,
402 "[%s] The instance is in an invalid state.", GetErrorMessage(E_INVALID_STATE));
404 if ((groupIndex < 0) || (groupIndex > GetGroupCount()) || (itemIndex < -1) || (itemIndex > GetItemCountAt(groupIndex)))
406 SysLogException(NID_UI_CTRL, E_OUT_OF_RANGE, "[%s] Group Index (%d) Item Index (%d) The index is out of range.", GetErrorMessage(E_OUT_OF_RANGE),groupIndex,itemIndex);
407 return E_OUT_OF_RANGE;
410 if (groupIndex == GetGroupCount() && itemIndex != -1 && type != TABLE_VIEW_REFRESH_TYPE_ITEM_ADD)
412 SysLogException(NID_UI_CTRL, E_OUT_OF_RANGE, "[%s] Group Index (%d) Item Index (%d) The index is out of range.", GetErrorMessage(E_OUT_OF_RANGE),groupIndex,itemIndex);
413 return E_OUT_OF_RANGE;
416 TableViewItemTag topDrawnItemPos = {-1, -1};
417 TableViewItemTag refreshItemPos = {groupIndex, itemIndex};
418 float prevScrollAreaHeight = GetScrollAreaBounds().height;
419 float prevScrollPosition = GetScrollPosition();
421 GetTopDrawnItem(topDrawnItemPos);
427 case TABLE_VIEW_REFRESH_TYPE_ITEM_ADD:
430 bool emptyState = IsEmpty();
432 int itemCount = pProviderAdaptor->GetItemCount(groupIndex);
433 if (__pListModel->InsertGroup(groupIndex, itemCount, false) != E_SUCCESS)
435 SysLogException(NID_UI_CTRL, E_SYSTEM, "[%s] A system error has been occurred. Unable to add Group item.", GetErrorMessage(E_SYSTEM));
441 GetFirstItem(topDrawnItemPos);
443 else if (groupIndex <= topDrawnItemPos.groupIndex)
445 topDrawnItemPos.groupIndex++;
450 bool emptyState = IsEmpty();
452 if (__pListModel->InsertItemToGroup(null, groupIndex, itemIndex) != E_SUCCESS)
454 SysLogException(NID_UI_CTRL, E_SYSTEM, "[%s] A system error has been occurred. Unable to add item.", GetErrorMessage(E_SYSTEM));
460 GetFirstItem(topDrawnItemPos);
464 RefreshItemHeightList(groupIndex, itemIndex, TABLE_VIEW_REFRESH_TYPE_ITEM_ADD);
465 RefreshSectionAlignmentList(groupIndex, TABLE_VIEW_REFRESH_TYPE_ITEM_ADD);
467 if (__pListModel->GetAllItemCount() == 1)
469 SetStatusChanged(true);
474 case TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE:
477 if (groupIndex == GetGroupCount())
479 SysLogException(NID_UI_CTRL, E_OUT_OF_RANGE, "[%s] Group Index (%d) Item Index (%d) The index is out of range.", GetErrorMessage(E_OUT_OF_RANGE),groupIndex,itemIndex);
480 return E_OUT_OF_RANGE;
483 RefreshItemHeightList(groupIndex, itemIndex, TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE);
484 RefreshSectionAlignmentList(groupIndex, TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE);
486 if (__pListModel->RemoveGroup(groupIndex) != E_SUCCESS)
488 SysLogException(NID_UI_CTRL, E_SYSTEM, "[%s] A system error has been occurred. Unable to remove group.", GetErrorMessage(E_SYSTEM));
492 if (groupIndex == topDrawnItemPos.groupIndex)
494 topDrawnItemPos.itemIndex = -1;
497 if (groupIndex < topDrawnItemPos.groupIndex)
499 topDrawnItemPos.groupIndex--;
502 if ((groupIndex == GetGroupCount()) && (GetGroupCount() > 0))
504 topDrawnItemPos.groupIndex--;
505 topDrawnItemPos.itemIndex = GetItemCountAt(GetGroupCount() - 1) - 1;
510 if (itemIndex == GetItemCountAt(groupIndex))
512 SysLogException(NID_UI_CTRL, E_OUT_OF_RANGE, "[%s] Group Index (%d) Item Index (%d) The index is out of range.", GetErrorMessage(E_OUT_OF_RANGE),groupIndex,itemIndex);
513 return E_OUT_OF_RANGE;
516 if (__pListModel->RemoveItemAt(groupIndex, itemIndex) != E_SUCCESS)
518 SysLogException(NID_UI_CTRL, E_SYSTEM, "[%s] A system error has been occurred. Unable to remove group.", GetErrorMessage(E_SYSTEM));
522 if ((groupIndex == topDrawnItemPos.groupIndex) && (itemIndex < topDrawnItemPos.itemIndex))
524 GetPreviousItemPosition(topDrawnItemPos, topDrawnItemPos);
527 RefreshItemHeightList(groupIndex, itemIndex, TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE);
530 if (GetModel()->IsValidItem(topDrawnItemPos.groupIndex, topDrawnItemPos.itemIndex) == false)
532 GetPreviousItemPosition(topDrawnItemPos, topDrawnItemPos);
535 if (__pListModel->GetAllItemCount() == 0)
537 SetStatusChanged(true);
542 case TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY:
544 TableViewItemTag itemTag = {groupIndex, itemIndex};
545 _TableViewItem* pTableViewItem = FindItem(itemTag);
547 if (pTableViewItem == null)
552 if (pProviderAdaptor->UpdateItem(pTableViewItem, itemTag.groupIndex, itemTag.itemIndex))
554 FloatRectangle itemBounds = pTableViewItem->GetBoundsF();
555 FloatDimension itemDim = Tizen::Graphics::CoordinateSystem::AlignToDevice(FloatDimension(itemBounds.width, itemBounds.height));
556 itemBounds.height = itemDim.height;
557 pTableViewItem->SetBounds(itemBounds);
559 CheckItemHeightAndRefreshLayout(itemTag, true);
561 if (__sweptItemTag.groupIndex != itemTag.groupIndex || __sweptItemTag.itemIndex != itemTag.itemIndex)
566 pTableViewItem->SetPublicLabelUpdate(false);
567 pTableViewItem->SetItemChanged(true);
568 pTableViewItem->Invalidate();
569 pTableViewItem->AdjustContextItemBounds();
577 SysLogException(NID_UI_CTRL, E_SYSTEM, "[%s] A system error has been occurred. Unable to refresh list.", GetErrorMessage(E_SYSTEM));
582 __lockLoadItemWithScroll = true;
584 AdjustClientAreaBounds(true);
586 __lockLoadItemWithScroll = false;
588 if ((topDrawnItemPos.groupIndex > refreshItemPos.groupIndex)
589 ||((topDrawnItemPos.groupIndex == refreshItemPos.groupIndex)&&(topDrawnItemPos.itemIndex > refreshItemPos.itemIndex)))
591 RefreshItemLayout(topDrawnItemPos, refreshItemPos, type, false);
593 float newScrollPosition = prevScrollPosition - (prevScrollAreaHeight - GetScrollAreaBounds().height);
595 __lockLoadItemWithScroll = true;
597 SetScrollPosition(newScrollPosition, false);
599 __lockLoadItemWithScroll = false;
603 RefreshItemLayout(topDrawnItemPos, refreshItemPos, type, animation);
610 _TableViewPresenter::RefreshAllItems(void)
612 result r = E_SUCCESS;
613 TableViewItemTag itemTag = {-1, -1};
614 TableViewItemTag lastLoadedItemTag = {-1, -1};
616 __pListModel->GetLastLoadedItemIndex(lastLoadedItemTag.groupIndex, lastLoadedItemTag.itemIndex);
617 __pListModel->GetFirstLoadedItemIndex(itemTag.groupIndex, itemTag.itemIndex);
621 _TableViewItem* pItem = FindItem(itemTag);
628 r = RefreshTableView(itemTag.groupIndex, itemTag.itemIndex, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY, false);
629 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
631 if ((itemTag.itemIndex == lastLoadedItemTag.itemIndex) && (itemTag.groupIndex == lastLoadedItemTag.groupIndex))
635 } while (GetNextItemPosition(itemTag, itemTag));
641 _TableViewPresenter::UpdateTableView(bool isRestoreAnnexFocusValue)
643 if ((__pTableView != null) && __pTableView->IsTableViewFocused() && __pTableView->IsFocusModeStateEnabled()
644 && __pTableView->GetRootWindow() && __pTableView->GetRootWindow()->IsActivated())
646 __isRestoreFocus = true;
649 if (!__isRestoreFocus)
651 __focusItemTag.groupIndex = -1;
652 __focusItemTag.itemIndex = -1;
653 __isTableViewFocused = false;
654 __isAnnexFocused = false;
657 if (!isRestoreAnnexFocusValue)
659 __isAnnexFocused = false;
662 if (__isUpdatingTableView)
667 __isUpdatingTableView = true;
669 _VisualElement* pVisualElement = __pTableView->GetVisualElement();
671 if (pVisualElement != null)
673 __pTableView->GetVisualElement()->RemoveAllAnimations();
677 if (__modelInitialized == false)
679 SetItemDrawingProperty();
687 __pListModel->RemoveAllItem(false, false);
693 TableViewItemTag topDrawnTag = {-1, -1};
694 float shiftingDistance = 0;
698 GetTopDrawnItem(topDrawnTag);
700 if (__pListModel->IsValidItem(topDrawnTag.groupIndex, topDrawnTag.itemIndex))
702 _TableViewItem* pItem = FindItem(topDrawnTag);
706 shiftingDistance = GetScrollPosition() - pItem->GetBoundsF().y;
710 __pListModel->RemoveAllItem(false, true);
712 PreloadItem(topDrawnTag.groupIndex, topDrawnTag.itemIndex, shiftingDistance);
714 if (__isRestoreFocus)
716 __pTableView->SetFocused(true);
717 __pTableView->DrawFocus();
718 __isRestoreFocus = false;
721 __statusChangedFlag = true;
723 if (__itemTouchReleasedEventState == TABLE_VIEW_ITEM_TOUCH_RELEASED_EVENT_FIRE)
725 __itemTouchReleasedEventState = TABLE_VIEW_ITEM_TOUCH_RELEASED_EVENT_UPDATE_TABLE_VIEW;
730 __isUpdatingTableView = false;
736 _TableViewPresenter::AdjustLayoutItems(float scrollPosition)
738 TableViewItemTag lastLoadedItemPos = {-1, -1};
739 TableViewItemTag firstLoadedItemPos = {-1, -1};
740 TableViewItemTag currentItemPos = {-1, -1};
741 _TableViewItem* pItem = null;
743 __pListModel->GetFirstLoadedItemIndex(firstLoadedItemPos.groupIndex, firstLoadedItemPos.itemIndex);
744 __pListModel->GetLastLoadedItemIndex(lastLoadedItemPos.groupIndex, lastLoadedItemPos.itemIndex);
746 pItem = FindItem(firstLoadedItemPos);
750 float positionY = pItem->GetPositionF().y;
752 currentItemPos = firstLoadedItemPos;
754 while (!_FloatCompareLE(positionY, scrollPosition) && GetPreviousItemPosition(currentItemPos, currentItemPos))
756 pItem = LoadItem(currentItemPos.groupIndex, currentItemPos.itemIndex);
763 positionY = pItem->GetPositionF().y;
767 pItem = FindItem(lastLoadedItemPos);
771 float positionY = pItem->GetPositionF().y;
772 float itemHeight = pItem->GetBoundsF().height;
773 float limitScreenArea = scrollPosition + __pTableView->GetBoundsF().height;
774 currentItemPos = lastLoadedItemPos;
776 while ((positionY + itemHeight < limitScreenArea) && GetNextItemPosition(currentItemPos, currentItemPos))
778 pItem = LoadItem(currentItemPos.groupIndex, currentItemPos.itemIndex);
785 positionY = pItem->GetPositionF().y;
786 itemHeight = pItem->GetBoundsF().height;
792 _TableViewPresenter::ResetItemLayout(TableViewItemTag& topDrawnItemTag, float shiftingDistance)
794 if (__pListModel->IsValidItem(topDrawnItemTag.groupIndex, topDrawnItemTag.itemIndex) == false)
801 _TableViewItem* pItem = LoadItem(topDrawnItemTag.groupIndex, topDrawnItemTag.itemIndex);
808 TableViewItemTag currentItem = topDrawnItemTag;
809 TableViewItemTag itemPos = topDrawnItemTag;
810 float screenAreaHeight = __pTableView->GetBoundsF().height + shiftingDistance;
811 float loadedItemTotalHeight = 0.0f;
812 FloatRectangle itemBounds = pItem->GetBoundsF();
814 itemBounds.y = CalculateItemPositionY(itemPos.groupIndex, itemPos.itemIndex);
815 pItem->SetBounds(itemBounds);
816 CheckItemHeightAndRefreshLayout(itemPos, true);
818 loadedItemTotalHeight += itemBounds.height;
820 while (loadedItemTotalHeight < screenAreaHeight && GetNextItemPosition(currentItem, itemPos))
822 pItem = LoadItem(itemPos.groupIndex, itemPos.itemIndex);
829 currentItem = itemPos;
830 loadedItemTotalHeight += pItem->GetBoundsF().height;
833 if (loadedItemTotalHeight < screenAreaHeight)
835 __pListModel->GetFirstLoadedItemIndex(itemPos.groupIndex, itemPos.itemIndex);
836 currentItem = itemPos;
838 while (loadedItemTotalHeight < screenAreaHeight && GetPreviousItemPosition(currentItem, itemPos))
840 pItem = LoadItem(itemPos.groupIndex, itemPos.itemIndex);
847 currentItem = itemPos;
848 loadedItemTotalHeight += pItem->GetBoundsF().height;
854 _TableViewPresenter::IsCachingItemsTotalHeightLessThanViewHeight(void)
856 int currentCachingsize = GetMaxItemCachingSize();
857 int loadedItemCount = 0;
858 float itemTotalHeight = 0.0f;
859 float viewHeight = __pTableView->GetBoundsF().height;
860 float lastItemHeight = 0.0f;
862 TableViewItemTag lastLoadedItemPos = {-1, -1};
863 TableViewItemTag firstLoadedItemPos = {-1, -1};
865 __pListModel->GetFirstLoadedItemIndex(firstLoadedItemPos.groupIndex, firstLoadedItemPos.itemIndex);
866 __pListModel->GetLastLoadedItemIndex(lastLoadedItemPos.groupIndex, lastLoadedItemPos.itemIndex);
870 _TableViewItem* pItem = FindItem(firstLoadedItemPos);
874 itemTotalHeight = itemTotalHeight + pItem->GetSizeF().height;
875 lastItemHeight = pItem->GetSizeF().height;
879 if ((firstLoadedItemPos.itemIndex == lastLoadedItemPos.itemIndex) && (firstLoadedItemPos.groupIndex == lastLoadedItemPos.groupIndex))
883 } while (GetNextItemPosition(firstLoadedItemPos, firstLoadedItemPos));
885 if (loadedItemCount < currentCachingsize || viewHeight < (itemTotalHeight - lastItemHeight))
894 _TableViewPresenter::GetFirstLoadedItemIndex(int& groupIndex, int& itemIndex) const
896 __pListModel->GetFirstLoadedItemIndex(groupIndex, itemIndex);
900 _TableViewPresenter::GetLastLoadedItemIndex(int& groupIndex, int& itemIndex) const
902 __pListModel->GetLastLoadedItemIndex(groupIndex, itemIndex);
906 _TableViewPresenter::RefreshItemLayout(int groupIndex, int itemIndex)
908 TableViewItemTag itemTag = {groupIndex, itemIndex};
912 RefreshItemLayout(itemTag, itemTag, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY, false);
916 _TableViewPresenter::RefreshItemLayout(TableViewItemTag& topDrawnItemTag, TableViewItemTag& refreshItemTag, TableViewRefreshType type, bool animation)
918 if (!__pListModel->IsValidItem(topDrawnItemTag.groupIndex, topDrawnItemTag.itemIndex))
923 if (refreshItemTag.itemIndex == -1)
928 _TableViewItem* pItem = null;
930 TableViewItemTag itemPos = {-1, -1};
931 TableViewItemTag currentItem = {-1, -1};
933 int loadItemCount = 0;
934 int maxLoadItemCount = GetMaxItemCachingSize();
935 FloatRectangle itemBounds(0.0f, 0.0f, 0.0f, 0.0f);
937 StopAllItemAnimation();
939 __pListModel->GetFirstLoadedItemIndex(itemPos.groupIndex, itemPos.itemIndex);
941 if (itemPos.groupIndex == -1 && itemPos.itemIndex == -1)
943 itemPos = topDrawnItemTag;
946 currentItem = itemPos;
948 float itemPositionY = CalculateItemPositionY(itemPos.groupIndex, itemPos.itemIndex);
952 pItem = LoadItem(itemPos.groupIndex, itemPos.itemIndex);
959 if (pItem->HasParent())
961 pItem->SetDrawingProperty(__pItemDrawingProperty);
962 SetItemType(pItem, itemPos);
965 itemBounds = pItem->GetBoundsF();
966 itemBounds.y = itemPositionY;
970 if (type == TABLE_VIEW_REFRESH_TYPE_ITEM_ADD)
972 if (itemPos.groupIndex == refreshItemTag.groupIndex && itemPos.itemIndex == refreshItemTag.itemIndex)
974 pItem->SetBounds(itemBounds);
975 pItem->FadeInOutItem(false, ADD_ITEM_ANIMATION_DURATION, REFRESH_ITEM_ANIMATION_DELAY);
976 pItem->ZoomInOutItem(false, ADD_ITEM_ANIMATION_DURATION, REFRESH_ITEM_ANIMATION_DELAY);
980 if (!pItem->MoveItem(FloatPoint(itemBounds.x, itemBounds.y), ADD_ITEM_ANIMATION_DURATION, 0))
982 pItem->SetBounds(itemBounds);
988 if (!pItem->MoveItem(FloatPoint(itemBounds.x, itemBounds.y), REMOVE_ITEM_MOVE_ANIMATION_DURATION, REFRESH_ITEM_ANIMATION_DELAY))
990 pItem->SetBounds(itemBounds);
996 pItem->SetBounds(itemBounds);
999 currentItem = itemPos;
1000 itemPositionY = itemBounds.y + itemBounds.height;
1004 } while (loadItemCount < maxLoadItemCount && GetNextItemPosition(currentItem, itemPos));
1006 if (loadItemCount < maxLoadItemCount)
1008 __pListModel->GetFirstLoadedItemIndex(itemPos.groupIndex, itemPos.itemIndex);
1009 currentItem = itemPos;
1011 while (loadItemCount < maxLoadItemCount && GetPreviousItemPosition(currentItem, itemPos))
1013 pItem = LoadItem(itemPos.groupIndex, itemPos.itemIndex);
1020 currentItem = itemPos;
1026 if (refreshItemTag.itemIndex == -1)
1028 ScrollToItem(topDrawnItemTag.groupIndex, topDrawnItemTag.itemIndex, TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_TOP);
1033 _TableViewPresenter::RefreshItemBounds(_TableViewItem* pItem, TableViewItemTag& itemPos)
1035 FloatRectangle itemBounds;
1042 itemBounds = pItem->GetBoundsF();
1044 itemBounds.y = CalculateItemPositionY(itemPos.groupIndex, itemPos.itemIndex);
1046 if (itemPos.itemIndex != -1)
1048 float itemMargin = GetLeftMargin();
1049 itemBounds.x = itemMargin;
1050 itemBounds.width = __pItemDrawingProperty->width - itemBounds.x - itemMargin;
1054 itemBounds.x = 0.0f;
1055 itemBounds.width = __pItemDrawingProperty->width;
1058 pItem->SetBounds(itemBounds);
1062 _TableViewPresenter::GetItemIndexFromPosition(const FloatPoint& position, int& groupIndex, int& itemIndex) const
1064 result r = E_SUCCESS;
1065 TableViewItemTag itemPos;
1067 FloatPoint targetPosition = position;
1068 float scrollPosition = GetScrollPosition();
1069 targetPosition.y += scrollPosition;
1071 r = GetItemFromPosition(targetPosition, itemPos);
1080 groupIndex = itemPos.groupIndex;
1081 itemIndex = itemPos.itemIndex;
1088 _TableViewPresenter::PreloadItem(void)
1090 if (GetModel() == null || __pProviderAdaptor == null)
1095 __modelInitialized = true;
1097 if (__pListModel->GetAllGroupCount() == 0 && (__pProviderAdaptor != null))
1100 int groupCount = __pProviderAdaptor->GetGroupCount();
1102 for (int i = 0; i < groupCount; i++)
1104 itemCount = __pProviderAdaptor->GetItemCount(i);
1105 __pListModel->AddGroup(itemCount, false);
1109 __pListModel->RestoreItemStatus();
1111 CreateItemHeightList(TABLEVIEW_DEFAULT_ITEM_HEIGHT_VALUE, TABLEVIEW_DEFAULT_ITEM_HEIGHT_VALUE);
1112 CreateSectionAlignmentList();
1114 int cachingSize = 0;
1116 if (GetItemCount() > TABLEVIEW_MAX_ITEM_COUNT)
1118 cachingSize = TABLEVIEW_MAX_ITEM_COUNT;
1120 else if (__pListModel->GetMaxCachingSize() < TABLEVIEW_MAX_ITEM_COUNT)
1122 cachingSize = __pListModel->GetMaxCachingSize();
1126 cachingSize = GetItemCount();
1129 TableViewItemTag itemPos = {-1, -1};
1130 GetFirstItem(itemPos);
1132 _TableViewItem* pItem = null;
1133 for (int i = 0; i < cachingSize; i++)
1135 pItem = LoadItem(itemPos.groupIndex, itemPos.itemIndex);
1142 if (GetNextItemPosition(itemPos, itemPos) == false)
1148 if (IsCachingItemsTotalHeightLessThanViewHeight())
1150 AdjustLayoutItems(0.0f);
1153 PresetItemHeightList();
1154 AdjustClientAreaBounds(true);
1156 TableViewScrollBarStyle scrollStyle = __pTableView->GetScrollStyle();
1158 if (scrollStyle == TABLE_VIEW_SCROLL_BAR_STYLE_FAST_SCROLL
1159 || scrollStyle == TABLE_VIEW_SCROLL_BAR_STYLE_FAST_SCROLL_FIXED)
1161 _FastScroll* pFastScroll = __pTableView->GetFastScrollBar();
1162 if (pFastScroll != null)
1164 pFastScroll->UpdateIndex();
1165 pFastScroll->SetScrollVisibility(IsScrollable());
1168 else if (scrollStyle != TABLE_VIEW_SCROLL_BAR_STYLE_NONE)
1180 _TableViewPresenter::PreloadItem(int topDrawnGroupIndex, int topDrawnItemIndex, float shiftingDistance)
1182 if (GetModel() == null || __pProviderAdaptor == null)
1187 __modelInitialized = true;
1189 if (__pListModel->GetAllGroupCount() == 0 && (__pProviderAdaptor != null))
1192 int groupCount = __pProviderAdaptor->GetGroupCount();
1194 for (int i = 0; i < groupCount; i++)
1196 itemCount = __pProviderAdaptor->GetItemCount(i);
1197 __pListModel->AddGroup(itemCount, false);
1201 float defaultGroupHeight = __pProviderAdaptor->GetDefaultGroupItemHeight();
1202 float defaultItemHeight = __pProviderAdaptor->GetDefaultItemHeight();
1204 if (_FloatCompareLE(defaultGroupHeight, 0.0f))
1206 defaultGroupHeight = TABLEVIEW_DEFAULT_ITEM_HEIGHT_VALUE;
1209 if (_FloatCompareLE(defaultItemHeight, 0.0f))
1211 defaultItemHeight = TABLEVIEW_DEFAULT_ITEM_HEIGHT_VALUE;
1214 __pListModel->RestoreItemStatus();
1216 RestoreItemHeightList(defaultGroupHeight, defaultItemHeight);
1218 DeleteSectionAlignmentList();
1219 CreateSectionAlignmentList();
1221 if (!__pListModel->IsValidItem(topDrawnGroupIndex, topDrawnItemIndex))
1223 TableViewItemTag firstItemTag = {-1, -1};
1225 GetFirstItem(firstItemTag);
1227 topDrawnGroupIndex = firstItemTag.groupIndex;
1228 topDrawnItemIndex = firstItemTag.itemIndex;
1230 shiftingDistance = 0.0f;
1233 AdjustClientAreaBounds(true);
1235 ScrollToItem(topDrawnGroupIndex, topDrawnItemIndex, TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_TOP, shiftingDistance);
1237 if (IsCachingItemsTotalHeightLessThanViewHeight())
1239 AdjustLayoutItems(GetScrollPosition());
1242 if (__pTableView->GetScrollStyle() == TABLE_VIEW_SCROLL_BAR_STYLE_FAST_SCROLL
1243 || __pTableView->GetScrollStyle() == TABLE_VIEW_SCROLL_BAR_STYLE_FAST_SCROLL_FIXED)
1245 _FastScroll* pFastScroll = __pTableView->GetFastScrollBar();
1246 if (pFastScroll != null)
1248 pFastScroll->UpdateIndex();
1249 pFastScroll->SetScrollVisibility(IsScrollable());
1257 _TableViewPresenter::IsItemChecked(int groupIndex, int itemIndex) const
1259 if ((groupIndex < 0) || (groupIndex >= GetGroupCount()) || (itemIndex < -1) || (itemIndex >= GetItemCountAt(groupIndex)))
1264 return __pListModel->IsItemChecked(groupIndex, itemIndex);
1268 _TableViewPresenter::SetItemChecked(int groupIndex, int itemIndex, bool checked)
1270 if ((groupIndex < 0) || (groupIndex >= GetGroupCount()) || (itemIndex < -1) || (itemIndex >= GetItemCountAt(groupIndex)))
1272 return E_OUT_OF_RANGE;
1275 if (__modelInitialized == false)
1277 return E_INVALID_STATE;
1280 bool enabled = __pListModel->IsItemEnabled(groupIndex, itemIndex);
1281 SysTryReturn(NID_UI_CTRL, (enabled == true), E_INVALID_OPERATION, E_INVALID_OPERATION, "[%s] The item is disabled.", GetErrorMessage(E_INVALID_OPERATION));
1283 if (__pListModel->IsItemChecked(groupIndex, itemIndex) == checked)
1288 TableViewItemTag itemTag = {groupIndex, itemIndex};
1289 _TableViewItem *pItem = FindItem(itemTag);
1291 TableViewItemTag topDrawnItemTag = {-1, -1};
1292 GetTopDrawnItem(topDrawnItemTag);
1294 TableViewItemTag bottomDrawnItemTag = {-1, -1};
1295 GetBottomDrawnItem(bottomDrawnItemTag);
1299 if (((itemTag.groupIndex == topDrawnItemTag.groupIndex && itemTag.itemIndex >= topDrawnItemTag.itemIndex)
1300 || itemTag.groupIndex > topDrawnItemTag.groupIndex) &&
1301 ((itemTag.groupIndex == bottomDrawnItemTag.groupIndex && itemTag.itemIndex <= bottomDrawnItemTag.itemIndex)
1302 || itemTag.groupIndex < bottomDrawnItemTag.groupIndex))
1304 pItem->SetCheckedAnimationEnabled(checked);
1308 result r = __pListModel->SetItemChecked(groupIndex, itemIndex, checked);
1314 _TableViewPresenter::IsItemEnabled(int groupIndex, int itemIndex) const
1316 if ((groupIndex < 0) || (groupIndex >= GetGroupCount()) || (itemIndex < -1) || (itemIndex >= GetItemCountAt(groupIndex)))
1321 return __pListModel->IsItemEnabled(groupIndex, itemIndex);
1325 _TableViewPresenter::SetItemEnabled(int groupIndex, int itemIndex, bool enabled)
1327 if ((groupIndex < 0) || (groupIndex >= GetGroupCount()) || (itemIndex < -1) || (itemIndex >= GetItemCountAt(groupIndex)))
1329 return E_OUT_OF_RANGE;
1332 if (__pListModel->IsItemEnabled(groupIndex, itemIndex) == enabled)
1337 result r = __pListModel->SetItemEnabled(groupIndex, itemIndex, enabled);
1343 _TableViewPresenter::SetStatusChanged(bool changed)
1345 __statusChangedFlag = changed;
1347 if (__statusChangedFlag == true)
1349 SetItemDrawingProperty();
1351 if ((__pItemDrawingProperty != null) && (__pItemDrawingProperty->propertyChanged == true))
1353 __pListModel->SetAllLoadedItemStateChanged(true);
1361 _TableViewPresenter::IsStatusChanged(void) const
1363 return __statusChangedFlag;
1367 _TableViewPresenter::GetTopMargin(void) const
1373 _TableViewPresenter::SetTopMargin(float topMargin)
1375 __topMargin = topMargin;
1381 _TableViewPresenter::GetBottomMargin(void) const
1383 return __bottomMargin;
1387 _TableViewPresenter::SetBottomMargin(float bottomMargin)
1389 __bottomMargin = bottomMargin;
1395 _TableViewPresenter::GetLeftMargin(void) const
1397 return __leftMargin;
1401 _TableViewPresenter::SetLeftMargin(float leftMargin)
1403 __leftMargin = leftMargin;
1409 _TableViewPresenter::RestoreFocus(bool isRestoreFocus)
1411 __isRestoreFocus = isRestoreFocus;
1415 _TableViewPresenter::SetAnnexFocused(bool isAnnexFocused)
1417 __isAnnexFocused = isAnnexFocused;
1421 _TableViewPresenter::SetTableViewFocused(bool focusStatus)
1423 if (focusStatus == false)
1425 __focusItemTag.groupIndex = -1;
1426 __focusItemTag.itemIndex = -1;
1427 __isRestoreFocus = false;
1428 __isAnnexFocused = false;
1430 __isTableViewFocused = focusStatus;
1434 _TableViewPresenter::IsTableViewFocused(void)
1436 return __isTableViewFocused;
1440 _TableViewPresenter::SetItemType(_TableViewItem* pItem, TableViewItemTag itemPosition)
1442 TableViewStyle style = __pTableView->GetTableViewStyle();
1444 if (itemPosition.itemIndex == -1)
1446 if (style == TABLE_VIEW_STYLE_SECTION)
1448 pItem->SetItemType(TABLE_VIEW_ITEM_TYPE_HEADER);
1452 pItem->SetItemType(TABLE_VIEW_ITEM_TYPE_TITLE);
1457 int itemCount = GetItemCountAt(itemPosition.groupIndex);
1458 if (style == TABLE_VIEW_STYLE_SIMPLE)
1460 if (itemCount == 1 || (itemCount > 1 && (itemPosition.itemIndex == itemCount - 1)))
1462 pItem->SetSimpleLastItemEnabled(true);
1466 pItem->SetSimpleLastItemEnabled(false);
1469 if (style == TABLE_VIEW_STYLE_SECTION)
1471 pItem->SetSectionItem(true);
1474 if (itemPosition.itemIndex == 0)
1476 if (HasSectionFooter(itemPosition.groupIndex))
1480 pItem->SetItemType(TABLE_VIEW_ITEM_TYPE_FOOTER);
1482 else if (itemCount == 2)
1484 pItem->SetItemType(TABLE_VIEW_ITEM_TYPE_ONE);
1488 pItem->SetItemType(TABLE_VIEW_ITEM_TYPE_TOP);
1495 pItem->SetItemType(TABLE_VIEW_ITEM_TYPE_ONE);
1499 pItem->SetItemType(TABLE_VIEW_ITEM_TYPE_TOP);
1505 int lastItemIndex = itemCount - 1;
1507 if (HasSectionFooter(itemPosition.groupIndex))
1509 if (itemPosition.itemIndex == lastItemIndex)
1511 pItem->SetItemType(TABLE_VIEW_ITEM_TYPE_FOOTER);
1513 else if (itemPosition.itemIndex == lastItemIndex - 1)
1515 pItem->SetItemType(TABLE_VIEW_ITEM_TYPE_BOTTOM);
1519 pItem->SetItemType(TABLE_VIEW_ITEM_TYPE_MIDDLE);
1524 if (itemPosition.itemIndex == lastItemIndex)
1526 pItem->SetItemType(TABLE_VIEW_ITEM_TYPE_BOTTOM);
1530 pItem->SetItemType(TABLE_VIEW_ITEM_TYPE_MIDDLE);
1538 _TableViewPresenter::SetItemLayout(_TableViewItem* pItem, TableViewItemTag& itemPos)
1540 _TableViewItem* pSeriesItem = null;
1541 TableViewItemTag seriesItemPos = {-1, -1};
1542 FloatRectangle seriesItemBounds;
1543 FloatRectangle itemBounds;
1544 bool validBounds = false;
1545 bool downScroll = true;
1547 if (itemPos.itemIndex == -1 && __pTableView->GetTableViewStyle() != TABLE_VIEW_STYLE_SECTION)
1550 itemBounds.width = __pItemDrawingProperty->width;
1554 float itemMargin = GetLeftMargin();
1555 itemBounds.x = itemMargin;
1556 itemBounds.width = __pItemDrawingProperty->width - itemBounds.x - itemMargin;
1559 FloatDimension itemDimension = Tizen::Graphics::CoordinateSystem::AlignToDevice(FloatDimension(pItem->GetSizeF().width, pItem->GetSizeF().height));
1560 itemBounds.height = itemDimension.height;
1562 if (itemPos.groupIndex == 0 && itemPos.itemIndex == -1)
1564 itemBounds.y = GetTopMargin();
1569 if (GetPreviousItemPosition(itemPos, seriesItemPos))
1571 if (__pListModel->IsLoadedItem(seriesItemPos.groupIndex, seriesItemPos.itemIndex))
1573 pSeriesItem = static_cast<_TableViewItem*>(__pListModel->LoadItem(seriesItemPos.groupIndex, seriesItemPos.itemIndex));
1574 if ((pSeriesItem != null) && pSeriesItem->HasParent())
1576 if (__pTableView->IsReorderModeEnabled() && (__reorderInfo.groupIndex == seriesItemPos.groupIndex && __reorderInfo.itemIndex == seriesItemPos.itemIndex))
1578 seriesItemBounds = __reorderInfo.itemBounds;
1582 seriesItemBounds = pSeriesItem->GetBoundsF();
1585 itemBounds.y = seriesItemBounds.y + seriesItemBounds.height;
1592 if ((!validBounds) && GetNextItemPosition(itemPos, seriesItemPos))
1594 if (__pListModel->IsLoadedItem(seriesItemPos.groupIndex, seriesItemPos.itemIndex))
1596 pSeriesItem = static_cast<_TableViewItem*>(__pListModel->LoadItem(seriesItemPos.groupIndex, seriesItemPos.itemIndex));
1597 if ((pSeriesItem != null) && pSeriesItem->HasParent())
1599 if (__pTableView->IsReorderModeEnabled() && (__reorderInfo.groupIndex == seriesItemPos.groupIndex && __reorderInfo.itemIndex == seriesItemPos.itemIndex))
1601 seriesItemBounds = __reorderInfo.itemBounds;
1605 seriesItemBounds = pSeriesItem->GetBoundsF();
1608 itemBounds.y = seriesItemBounds.y - itemBounds.height;
1619 pItem->SetBounds(itemBounds);
1621 CheckItemHeightAndRefreshLayout(itemPos, downScroll);
1625 itemBounds.y = CalculateItemPositionY(itemPos.groupIndex, itemPos.itemIndex);
1626 pItem->SetBounds(itemBounds);
1628 CheckItemHeightAndRefreshLayout(itemPos, true);
1631 if (__pTableView->IsReorderModeEnabled() && __reorderInfo.itemIndex != -1)
1633 TableViewItemTag reorderSelectedItemTag = {__reorderInfo.groupIndex, __reorderInfo.itemIndex};
1634 _TableViewItem* pReorderSelectedItem = FindItem(reorderSelectedItemTag);
1636 if (pReorderSelectedItem != null)
1638 pReorderSelectedItem->GetVisualElement()->SetZOrder(null, true);
1642 if (pItem->GetItemLayoutEnabled())
1644 pItem->PartialUpdateLayout();
1649 _TableViewPresenter::LoadItem(int groupIndex, int itemIndex)
1651 _TableViewItem* pItem = static_cast<_TableViewItem*>(__pListModel->LoadItem(groupIndex, itemIndex));
1653 if ((pItem != null) && !pItem->HasParent())
1655 __lockLoadItemWithScroll = true;
1657 __pTableView->AttachChild(*pItem);
1659 pItem->SetDrawingProperty(__pItemDrawingProperty);
1661 TableViewItemTag itemPosition = {groupIndex, itemIndex};
1662 SetItemType(pItem, itemPosition);
1663 SetItemLayout(pItem, itemPosition);
1664 pItem->SetReorderMode(__pTableView->IsReorderModeEnabled());
1666 __lockLoadItemWithScroll = false;
1673 _TableViewPresenter::FindItem(TableViewItemTag& itemTag)
1675 if (__pListModel->IsLoadedItem(itemTag.groupIndex, itemTag.itemIndex))
1677 return static_cast<_TableViewItem*>(__pListModel->LoadItem(itemTag.groupIndex, itemTag.itemIndex));
1683 _TableViewPresenter::UnloadItem(int groupIndex, int itemIndex)
1685 __pListModel->UnloadItem(groupIndex, itemIndex);
1689 _TableViewPresenter::UnloadItem(TableViewItemTag& itemTag)
1691 __pListModel->UnloadItem(itemTag.groupIndex, itemTag.itemIndex);
1697 _TableViewPresenter::DetachItem(TableViewItemTag& itemTag)
1699 _TableViewItem *pItem = FindItem(itemTag);
1701 if (pItem != null && pItem->HasParent())
1703 pItem->GetParent()->DetachChild(*pItem);
1708 _TableViewPresenter::DetachContextItem(TableViewItemTag& itemTag)
1710 _TableViewItem *pItem = FindItem(itemTag);
1716 _TableViewItem* contextItem = pItem->GetContextItem();
1717 if (contextItem != null && contextItem->HasParent())
1719 contextItem->GetParent()->DetachChild(*pItem);
1724 _TableViewPresenter::DetachAllItem(bool removeItem)
1726 TableViewItemTag itemPos = {-1, -1};
1727 TableViewItemTag lastItemPos = {-1, -1};
1729 __pListModel->GetFirstLoadedItemIndex(itemPos.groupIndex, itemPos.itemIndex);
1730 __pListModel->GetLastLoadedItemIndex(lastItemPos.groupIndex, lastItemPos.itemIndex);
1732 if (itemPos.groupIndex == -1 && itemPos.itemIndex == -1)
1739 DetachItem(itemPos);
1743 UnloadItem(itemPos);
1746 if (itemPos.itemIndex == lastItemPos.itemIndex && itemPos.groupIndex == lastItemPos.groupIndex)
1750 } while (GetNextItemPosition(itemPos, itemPos));
1754 _TableViewPresenter::SetItemDrawingProperty(void)
1756 if (__pItemDrawingProperty != null)
1758 __pItemDrawingProperty->propertyChanged = false;
1760 if (__pItemDrawingProperty->itemDividerEnabled != __pTableView->IsItemDividerEnabled())
1762 __pItemDrawingProperty->itemDividerEnabled = __pTableView->IsItemDividerEnabled();
1763 __pItemDrawingProperty->propertyChanged = true;
1766 if (__pItemDrawingProperty->dividerColor != __pTableView->GetItemDividerColor())
1768 __pItemDrawingProperty->dividerColor = __pTableView->GetItemDividerColor();
1769 __pItemDrawingProperty->propertyChanged = true;
1772 if (__pItemDrawingProperty->sectionStyleEnabled != (__pTableView->GetTableViewStyle() == TABLE_VIEW_STYLE_SECTION))
1774 __pItemDrawingProperty->sectionStyleEnabled = (__pTableView->GetTableViewStyle() == TABLE_VIEW_STYLE_SECTION);
1775 __pItemDrawingProperty->propertyChanged = true;
1778 if (__pItemDrawingProperty->sectionStyleBgColor != __pTableView->GetSectionColor())
1780 __pItemDrawingProperty->sectionStyleBgColor = __pTableView->GetSectionColor();
1781 __pItemDrawingProperty->propertyChanged = true;
1784 if (__pTableView->GetTableViewStyle() != TABLE_VIEW_STYLE_SIMPLE)
1786 if (__pItemDrawingProperty->groupedLookEnabled != __pTableView->IsGroupedLookEnabled())
1788 __pItemDrawingProperty->groupedLookEnabled = __pTableView->IsGroupedLookEnabled();
1789 __pItemDrawingProperty->propertyChanged = true;
1793 if (__pItemDrawingProperty->reorderMode != __pTableView->IsReorderModeEnabled())
1795 __pItemDrawingProperty->reorderMode = __pTableView->IsReorderModeEnabled();
1796 __pItemDrawingProperty->propertyChanged = true;
1799 if (!_FloatCompare(__pItemDrawingProperty->leftMargin, __leftMargin))
1801 __pItemDrawingProperty->leftMargin = __leftMargin;
1802 __pItemDrawingProperty->propertyChanged = true;
1805 if (__pTableView->GetScrollStyle() == TABLE_VIEW_SCROLL_BAR_STYLE_FAST_SCROLL_FIXED)
1807 GET_SHAPE_CONFIG(TABLEVIEW::FASTSCROLL_INDEX_WIDTH, _CONTROL_ORIENTATION_PORTRAIT,
1808 __pItemDrawingProperty->scrollMargin);
1812 __pItemDrawingProperty->scrollMargin = 0;
1815 if (!_FloatCompare(__pItemDrawingProperty->width, __pTableView->GetBoundsF().width))
1817 __pItemDrawingProperty->width = __pTableView->GetBoundsF().width;
1818 __pItemDrawingProperty->propertyChanged = true;
1824 _TableViewPresenter::OnBoundsChanged(void)
1826 float listWidth = __pTableView->GetBoundsF().width - (GetLeftMargin() * 2);
1828 if (__pProviderAdaptor != null && __modelInitialized)
1830 StopExpandCollapseAnimation();
1832 if (__pTableView->IsReorderModeEnabled() && __reorderInfo.itemIndex != -1)
1834 ResetReorderItem(__reorderInfo.groupIndex, __reorderInfo.itemIndex);
1837 if (!_FloatCompare(listWidth, __pProviderAdaptor->GetListWidth()))
1839 __pProviderAdaptor->SetListWidth(listWidth);
1841 SetItemDrawingProperty();
1843 AdjustLoadedItemWidth();
1845 __pTableView->UpdateLayout();
1848 SetClientAreaHeight(__itemTotalHeight);
1851 AdjustLayoutItems(GetScrollPosition());
1855 if (__pProviderAdaptor != null)
1857 __pProviderAdaptor->SetListWidth(listWidth);
1860 SetClientAreaHeight(__pTableView->GetBoundsF().height);
1861 _ScrollPanelPresenter::OnBoundsChanged();
1864 //FastScroll Visibility
1865 if (__isOrientationChanged)
1867 TableViewScrollBarStyle scrollStyle = __pTableView->GetScrollStyle();
1869 if (scrollStyle == TABLE_VIEW_SCROLL_BAR_STYLE_FAST_SCROLL
1870 || scrollStyle == TABLE_VIEW_SCROLL_BAR_STYLE_FAST_SCROLL_FIXED)
1872 _FastScroll* pFastScroll = __pTableView->GetFastScrollBar();
1873 if (pFastScroll != null)
1875 pFastScroll->UpdateIndex();
1876 pFastScroll->SetScrollVisibility(IsScrollable());
1880 __isOrientationChanged = false;
1885 _TableViewPresenter::Draw(void)
1887 result r = _ScrollPanelPresenter::Draw();
1888 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1890 if (__modelInitialized == false)
1892 SetItemDrawingProperty();
1894 if(PreloadItem() == false)
1896 __pTableView->SetFocusNavigateEnabled(false);
1900 if (__reservedScrollItemIndex.groupIndex != -1 && __reservedScrollItemIndex.itemIndex != -1)
1902 ScrollToItem(__reservedScrollItemIndex.groupIndex, __reservedScrollItemIndex.itemIndex, __reservedScrollItemAlignment);
1904 __reservedScrollItemIndex.groupIndex = -1;
1905 __reservedScrollItemIndex.itemIndex = -1;
1911 __firstDrawnFlag = false;
1914 if (IsEmpty() == true)
1916 __pTableView->SetFocusNavigateEnabled(false);
1917 return DrawEmptyTableView();
1921 __pTableView->SetFocusNavigateEnabled(true);
1924 if (!__isRestoreFocus && __isFocusedDuringOrientationChange)
1926 TableViewItemTag bottomDrawnItemIndex = {-1, -1};
1927 GetBottomDrawnItem(bottomDrawnItemIndex);
1929 if ((bottomDrawnItemIndex.groupIndex < __focusItemTag.groupIndex) ||
1930 (bottomDrawnItemIndex.groupIndex == __focusItemTag.groupIndex && bottomDrawnItemIndex.itemIndex <= __focusItemTag.itemIndex))
1932 ScrollToItem(__focusItemTag.groupIndex, __focusItemTag.itemIndex, TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_BOTTOM);
1935 __isFocusedDuringOrientationChange = false;
1940 _TableViewPresenter::OnChangeLayout(_ControlOrientation orientation)
1942 __isOrientationChanged = true;
1943 if (__focusItemTag.groupIndex != -1)
1945 __isFocusedDuringOrientationChange = true;
1949 _UiTouchEventDelivery
1950 _TableViewPresenter::OnPreviewTouchPressed(const _Control& source, const _TouchInfo& touchInfo)
1952 _UiTouchEventDelivery response = _ScrollPanelPresenter::OnPreviewTouchPressed(source, touchInfo);
1954 if (__focusItemTag.groupIndex != -1)
1956 _TableViewItem *pItem = FindItem(__focusItemTag);
1959 pItem->ResetItemState();
1962 __focusItemTag.groupIndex = -1;
1963 __focusItemTag.itemIndex = -1;
1965 _TableViewItem* pItem = GetTableViewItemFromControl(source);
1971 TableViewItemTag itemPos = {-1, -1};
1973 pItem->GetItemIndex(itemPos.groupIndex, itemPos.itemIndex);
1975 if (itemPos.groupIndex == -1 && itemPos.itemIndex == -1)
1980 if (IsScrollAnimationRunning() && (GetScrollPosition() == GetScrollPositionInternal()))
1982 pItem->SetTouchPressOnScroll(true);
1986 if (__pTableView->IsReorderModeEnabled())
1988 __firstTouchMoved = true;
1990 if (SelectReorderItem(itemPos.groupIndex, itemPos.itemIndex, false))
1992 __reorderInfo.touchPressedPositionY = touchInfo.GetCurrentPosition().y;
1999 _UiTouchEventDelivery
2000 _TableViewPresenter::OnPreviewTouchMoved(const _Control& source, const _TouchInfo& touchInfo)
2002 if (__pTableView->IsReorderModeEnabled())
2004 if (__reorderInfo.itemIndex != -1)
2006 if (!DragSelectedItem(touchInfo.GetCurrentPosition().y - __reorderInfo.touchPressedPositionY, true))
2008 __firstTouchMoved = false;
2010 ResetReorderItem(__reorderInfo.groupIndex, __reorderInfo.itemIndex);
2013 return _UI_TOUCH_EVENT_DELIVERY_NO;
2017 return _ScrollPanelPresenter::OnPreviewTouchMoved(source, touchInfo);
2020 _UiTouchEventDelivery
2021 _TableViewPresenter::OnPreviewTouchReleased(const _Control& source, const _TouchInfo& touchInfo)
2023 if (__pTableView->IsReorderModeEnabled() && __reorderInfo.itemIndex != -1)
2025 ResetReorderItem(__reorderInfo.groupIndex, __reorderInfo.itemIndex);
2027 if (__reorderInfo.blockedTouchReleaseState)
2029 __reorderInfo.blockedTouchReleaseState = false;
2031 return _UI_TOUCH_EVENT_DELIVERY_NO;
2035 return _ScrollPanelPresenter::OnPreviewTouchReleased(source, touchInfo);
2038 _UiTouchEventDelivery
2039 _TableViewPresenter::OnPreviewTouchCanceled(const _Control& source, const _TouchInfo& touchInfo)
2041 return _ScrollPanelPresenter::OnPreviewTouchCanceled(source, touchInfo);
2045 _TableViewPresenter::OnTouchPressed(const _Control& source, const _TouchInfo& touchInfo)
2047 __firstTouchMoved = true;
2049 _TableViewItem* pItem = GetTableViewItemFromControl(source);
2053 StopExpandCollapseAnimation();
2054 return _ScrollPanelPresenter::OnTouchPressed(source, touchInfo);
2057 TableViewItemTag itemPos = {-1, -1};
2058 pItem->GetItemIndex(itemPos.groupIndex, itemPos.itemIndex);
2060 if (!(pItem->IsContextItem()
2061 || pItem->IsItemEnabled() == false
2062 || pItem->GetItemType() == TABLE_VIEW_ITEM_TYPE_TITLE
2063 || pItem->GetItemType() == TABLE_VIEW_ITEM_TYPE_HEADER
2064 || pItem->GetItemType() == TABLE_VIEW_ITEM_TYPE_FOOTER)
2065 && ((itemPos.groupIndex != __sweptItemTag.groupIndex)
2066 || (itemPos.itemIndex != __sweptItemTag.itemIndex)))
2071 __sweepOccured = false;
2073 StopExpandCollapseAnimation();
2075 return _ScrollPanelPresenter::OnTouchPressed(source, touchInfo);
2079 _TableViewPresenter::OnTouchMoved(const _Control& source, const _TouchInfo& touchInfo)
2081 if (__pTableView->IsReorderModeEnabled())
2083 if (__reorderInfo.blockedScroll)
2088 return _ScrollPanelPresenter::OnTouchMoved(source, touchInfo);
2091 _TableViewItem* pItem = GetTableViewItemFromControl(source);
2093 || pItem->IsItemEnabled() == false
2094 || pItem->GetItemType() == TABLE_VIEW_ITEM_TYPE_TITLE
2095 || pItem->GetItemType() == TABLE_VIEW_ITEM_TYPE_HEADER
2096 || pItem->GetItemType() == TABLE_VIEW_ITEM_TYPE_FOOTER
2097 || pItem->IsAnnexOnOffSliding())
2099 return _ScrollPanelPresenter::OnTouchMoved(source, touchInfo);;
2102 if (__firstTouchMoved)
2104 FloatPoint prevTouchPosition = GetPreviousTouchPosition();
2105 FloatPoint currTouchPosition = GetCurrentTouchPosition();
2106 float moveDistanceX = currTouchPosition.x - prevTouchPosition.x;
2107 float moveDistanceY = currTouchPosition.y - prevTouchPosition.y;
2109 if ((pItem->GetContextItem() != null && abs(moveDistanceX) > abs(moveDistanceY * 2)) || pItem->IsContextItem())
2111 if (!pItem->IsContextItem() && !pItem->IsAnimationPlaying())
2113 pItem->GetItemIndex(__sweptItemTag.groupIndex, __sweptItemTag.itemIndex);
2114 __sweptItemPosition = pItem->GetPositionF();
2116 pItem->AdjustContextItemBounds();
2119 __sweepOccured = true;
2121 else if (pItem->GetContextItem() == null && __pTableView->IsSweepEnabled())
2123 __sweepOccured = true;
2131 __firstTouchMoved = false;
2135 FloatPoint prevTouchPosition = GetPreviousTouchPosition();
2136 FloatPoint currTouchPosition = GetCurrentTouchPosition();
2138 SweepItem(currTouchPosition.x - prevTouchPosition.x);
2143 return _ScrollPanelPresenter::OnTouchMoved(source, touchInfo);
2147 _TableViewPresenter::OnTouchReleased(const _Control& source, const _TouchInfo& touchInfo)
2149 _TableViewItem* pItem = GetTableViewItemFromControl(source);
2152 || pItem->GetItemType() == TABLE_VIEW_ITEM_TYPE_TITLE
2153 || pItem->GetItemType() == TABLE_VIEW_ITEM_TYPE_HEADER
2154 || pItem->GetItemType() == TABLE_VIEW_ITEM_TYPE_FOOTER)
2156 return _ScrollPanelPresenter::OnTouchReleased(source, touchInfo);
2161 if (pItem->IsContextItem())
2163 pItem = static_cast<_TableViewItem*>(__pListModel->LoadItem(__sweptItemTag.groupIndex, __sweptItemTag.itemIndex));
2165 _TableViewItem* pContextItem = pItem->GetContextItem();
2168 if (pContextItem == null && __pTableView->IsSweepEnabled())
2170 FloatPoint prevPos = _ScrollPanelPresenter::GetPreviousTouchPosition();
2172 if (prevPos.x > touchInfo.GetCurrentPosition().x)
2174 pItem->FireItemSweepEvent(TABLE_VIEW_SWEEP_DIRECTION_LEFT);
2176 else if (prevPos.x < touchInfo.GetCurrentPosition().x)
2178 pItem->FireItemSweepEvent(TABLE_VIEW_SWEEP_DIRECTION_RIGHT);
2183 else if (pContextItem != null)
2185 AdjustSweptItemPosition(true);
2189 return _ScrollPanelPresenter::OnTouchReleased(source, touchInfo);
2193 _TableViewPresenter::OnTouchCanceled(const _Control& source, const _TouchInfo& touchInfo)
2200 if (__pTableView->IsReorderModeEnabled() && __reorderInfo.itemIndex != -1)
2202 ResetReorderItem(__reorderInfo.groupIndex, __reorderInfo.itemIndex);
2206 return _ScrollPanelPresenter::OnTouchCanceled(source, touchInfo);
2210 _TableViewPresenter::OnFlickGestureDetected(_TouchFlickGestureDetector& gesture)
2212 if (__pTableView->IsReorderModeEnabled() && __reorderInfo.itemIndex != -1)
2217 _FlickDirection flickDirection = gesture.GetDirection();
2219 if (flickDirection != _FLICK_DIRECTION_RIGHT && flickDirection != _FLICK_DIRECTION_LEFT)
2221 return _ScrollPanelPresenter::OnFlickGestureDetected(gesture);
2224 _Control* gestureControl = gesture.GetControl();
2226 if (gestureControl == null)
2228 return _ScrollPanelPresenter::OnFlickGestureDetected(gesture);
2231 _TableViewItem* pItem = GetTableViewItemFromControl(*gestureControl);
2235 return _ScrollPanelPresenter::OnFlickGestureDetected(gesture);
2238 if (flickDirection == _FLICK_DIRECTION_RIGHT)
2241 if (pItem->GetContextItem() == null && __pTableView->IsSweepEnabled())
2243 pItem->FireItemSweepEvent(TABLE_VIEW_SWEEP_DIRECTION_RIGHT);
2247 if (pItem->GetContextItem() != null)
2249 AdjustSweptItemPosition();
2253 else if (flickDirection == _FLICK_DIRECTION_LEFT)
2256 if (pItem->GetContextItem() == null && __pTableView->IsSweepEnabled())
2258 pItem->FireItemSweepEvent(TABLE_VIEW_SWEEP_DIRECTION_LEFT);
2262 if (pItem->GetContextItem() != null)
2264 AdjustSweptItemPosition();
2273 _TableViewPresenter::OnFlickGestureCanceled(_TouchFlickGestureDetector& gesture)
2275 return _ScrollPanelPresenter::OnFlickGestureCanceled(gesture);
2279 _TableViewPresenter::OnPreviewFlickGestureDetected(_TouchFlickGestureDetector& gesture)
2281 if (__pTableView->IsReorderModeEnabled() && __reorderInfo.itemIndex != -1)
2286 _FlickDirection flickDirection = gesture.GetDirection();
2287 if (flickDirection != _FLICK_DIRECTION_RIGHT && flickDirection != _FLICK_DIRECTION_LEFT)
2289 return _ScrollPanelPresenter::OnFlickGestureDetected(gesture);
2296 _TableViewPresenter::OnTimerExpired(Tizen::Base::Runtime::Timer& timer)
2298 _ScrollPanelPresenter::OnTimerExpired(timer);
2300 if (&timer == __pReorderScrollTimer)
2302 float distance = 0.0f;
2304 if (__reorderInfo.isScrollDirectionUp)
2306 distance = -REORDER_SCROLL_ANIMATION_DISTANCE;
2310 distance = REORDER_SCROLL_ANIMATION_DISTANCE;
2313 DragSelectedItem(distance, false);
2315 distance = ScrollTo(distance + GetScrollPosition());
2317 StartReorderScrollTimer();
2319 else if (&timer == __pFastScrollTimer)
2321 __isFastScrollTimerEnabled = false;
2323 _FastScroll* pFastScroll = __pTableView->GetFastScrollBar();
2325 if (pFastScroll != null && !_ScrollPanelPresenter::IsScrollAnimationRunning())
2327 pFastScroll->SetScrollVisibility(false);
2333 _TableViewPresenter::StartFastScrollTimer(void)
2335 result r = E_SUCCESS;
2337 SysTryReturn(NID_UI_CTRL,
2338 __pTableView->GetScrollStyle() == TABLE_VIEW_SCROLL_BAR_STYLE_FAST_SCROLL,
2339 E_INVALID_OPERATION, E_INVALID_OPERATION, "[%s] The style of TableView scroll is not TABLE_VIEW_SCROLL_BAR_STYLE_FAST_SCROLL", GetErrorMessage(E_INVALID_OPERATION));
2340 SysTryReturn(NID_UI_CTRL, __pFastScrollTimer != null, E_INVALID_STATE, E_INVALID_STATE,"[%s] Timer is not created.", GetErrorMessage(E_INVALID_OPERATION));
2342 r = __pFastScrollTimer->Start(FAST_SCROLL_FADE_OUT_DURATION);
2343 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
2345 __isFastScrollTimerEnabled = true;
2351 _TableViewPresenter::StopFastScrollTimer(void)
2353 result r = E_SUCCESS;
2355 SysTryReturnVoidResult(NID_UI_CTRL, __pFastScrollTimer != null, E_INVALID_STATE, "[%s] Timer is invalid.", GetErrorMessage(E_INVALID_OPERATION));
2357 r = __pFastScrollTimer->Cancel();
2358 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
2360 __isFastScrollTimerEnabled = false;
2366 _TableViewPresenter::IsEmpty(void) const
2368 if (__pTableView->GetTableViewStyle() == TABLE_VIEW_STYLE_SIMPLE)
2370 if (GetItemCountAt(0) <= 0)
2377 if (GetGroupCount() <= 0 )
2387 _TableViewPresenter::DrawEmptyTableView(void)
2393 _TableViewPresenter::GetFirstItem(TableViewItemTag& firstItem) const
2397 firstItem.groupIndex = -1;
2398 firstItem.itemIndex = -1;
2402 firstItem.groupIndex = 0;
2403 firstItem.itemIndex = -1;
2410 _TableViewPresenter::GetLastItem(TableViewItemTag& lastItem) const
2414 lastItem.groupIndex = -1;
2415 lastItem.itemIndex = -1;
2419 lastItem.groupIndex = GetGroupCount() - 1;
2420 lastItem.itemIndex = GetItemCountAt(lastItem.groupIndex) - 1;
2427 _TableViewPresenter::GetTopDrawnItem(TableViewItemTag& itemPos) const
2429 _TableViewItem* pItem = null;
2430 TableViewItemTag lastItemPos = {-1, -1};
2431 float scrollPosition = 0.0f;
2433 scrollPosition = GetScrollPosition();
2435 __pListModel->GetFirstLoadedItemIndex(itemPos.groupIndex, itemPos.itemIndex);
2436 __pListModel->GetLastLoadedItemIndex(lastItemPos.groupIndex, lastItemPos.itemIndex);
2440 pItem = static_cast <_TableViewItem*>(__pListModel->LoadItem(itemPos.groupIndex, itemPos.itemIndex));
2446 FloatRectangle itemBounds = pItem->GetBoundsF();
2448 if (scrollPosition < (itemBounds.y + itemBounds.height))
2453 if ((itemPos.itemIndex == lastItemPos.itemIndex) && (itemPos.groupIndex == lastItemPos.groupIndex))
2458 } while (GetNextItemPosition(itemPos, itemPos) == true);
2461 itemPos.itemIndex = -1;
2462 itemPos.groupIndex = -1;
2464 return E_OBJ_NOT_FOUND;
2468 _TableViewPresenter::GetBottomDrawnItem(TableViewItemTag& itemPos) const
2470 _TableViewItem* pItem = null;
2471 TableViewItemTag lastItemPos = {-1, -1};
2475 itemPos.itemIndex = -1;
2476 itemPos.groupIndex = -1;
2478 return E_OBJ_NOT_FOUND;
2481 float scrollPosition = GetScrollPosition() + __pTableView->GetBoundsF().height;
2483 __pListModel->GetFirstLoadedItemIndex(itemPos.groupIndex, itemPos.itemIndex);
2484 __pListModel->GetLastLoadedItemIndex(lastItemPos.groupIndex, lastItemPos.itemIndex);
2488 static bool onProcessingByProvider = true;
2489 pItem = static_cast <_TableViewItem*>(__pListModel->LoadItem(itemPos.groupIndex, itemPos.itemIndex));
2490 onProcessingByProvider = false;
2496 FloatRectangle itemBounds = pItem->GetBoundsF();
2498 if (itemBounds.y <= scrollPosition && scrollPosition <= (itemBounds.y + itemBounds.height))
2503 if ((itemPos.itemIndex == lastItemPos.itemIndex) && (itemPos.groupIndex == lastItemPos.groupIndex))
2508 } while (GetNextItemPosition(itemPos, itemPos) == true);
2514 _TableViewPresenter::GetPreviousItemPosition(const TableViewItemTag& currentItemPos, TableViewItemTag& prevItem) const
2521 // check validation of group index
2522 if ((currentItemPos.groupIndex < 0) || (currentItemPos.groupIndex >= __pListModel->GetAllGroupCount()))
2527 // if the current item is the first item
2528 if (currentItemPos.groupIndex == 0 && currentItemPos.itemIndex == -1)
2533 if (currentItemPos.itemIndex == -1)
2535 if (__pListModel->IsGroupExpanded(currentItemPos.groupIndex - 1) == false)
2537 prevItem.groupIndex = currentItemPos.groupIndex - 1;
2538 prevItem.itemIndex = -1;
2544 if (__pListModel->IsGroupExpanded(currentItemPos.groupIndex) == false)
2546 if (currentItemPos.groupIndex == 0 && currentItemPos.itemIndex == -1)
2551 prevItem.groupIndex = currentItemPos.groupIndex - 1;
2552 prevItem.itemIndex = __pListModel->GetItemCountInGroup(prevItem.groupIndex) - 1;
2557 if (currentItemPos.itemIndex == -1) // group title item
2559 prevItem.groupIndex = currentItemPos.groupIndex - 1;
2560 prevItem.itemIndex = __pListModel->GetItemCountInGroup(prevItem.groupIndex) - 1;
2564 prevItem.groupIndex = currentItemPos.groupIndex;
2565 prevItem.itemIndex = currentItemPos.itemIndex - 1;
2572 _TableViewPresenter::GetNextItemPosition(const TableViewItemTag& currentItem, TableViewItemTag& nextItem) const
2579 int lastGroup = __pListModel->GetAllGroupCount() - 1;
2580 int lastItemInCurrentGroup = __pListModel->GetItemCountInGroup(currentItem.groupIndex) - 1;
2581 int lastItem = __pListModel->GetItemCountInGroup(lastGroup) - 1;
2583 // check validation of group index
2584 if ((currentItem.groupIndex < 0) || (currentItem.groupIndex > lastGroup))
2589 // if the current item is the last item.
2590 if ((currentItem.groupIndex == lastGroup) && (currentItem.itemIndex == lastItem))
2595 if (__pListModel->IsGroupExpanded(currentItem.groupIndex) == false)
2597 if (currentItem.groupIndex == lastGroup)
2602 nextItem.groupIndex = currentItem.groupIndex + 1;
2603 nextItem.itemIndex = -1;
2608 if (lastItemInCurrentGroup == currentItem.itemIndex)
2610 nextItem.groupIndex = currentItem.groupIndex + 1;
2611 nextItem.itemIndex = -1;
2615 nextItem.groupIndex = currentItem.groupIndex;
2616 nextItem.itemIndex = currentItem.itemIndex + 1;
2623 _TableViewPresenter::GetHeightOfAllItems(void) const
2625 int groupCount = GetGroupCount();
2626 float totalHeight = 0;
2628 for (int i = 0; i < groupCount; i++)
2630 TableViewItemTag itemTag = {i, -1};
2632 totalHeight += GetItemHeight(itemTag);
2634 if (!IsGroupExpanded(i))
2639 int itemCount = GetItemCountAt(i);
2641 for (int j = 0; j < itemCount; j++)
2643 itemTag.itemIndex = j;
2645 totalHeight += GetItemHeight(itemTag);
2653 _TableViewPresenter::SetTableViewItemProviderAdaptor(_TableViewItemProviderAdaptor* pProviderAdaptor)
2655 __pListModel->RegisterItemProviderAdaptor(pProviderAdaptor);
2657 __pProviderAdaptor = pProviderAdaptor;
2659 if (__pProviderAdaptor != null)
2661 __pProviderAdaptor->SetTableViewPresenter(this);
2665 _TableViewItemProviderAdaptor*
2666 _TableViewPresenter::GetTableViewItemProviderAdaptor(void) const
2668 return __pProviderAdaptor;
2672 _TableViewPresenter::ExpandGroup(int groupIndex, bool withAnimation)
2674 if ((groupIndex < 0) || (groupIndex >= GetGroupCount()))
2676 return E_OUT_OF_RANGE;
2679 if (__modelInitialized == false)
2681 return E_INVALID_STATE;
2684 if (IsGroupExpanded(groupIndex) == true)
2689 TableViewItemTag topTag;
2690 GetTopDrawnItem(topTag);
2692 TableViewItemTag bottomTag;
2693 GetBottomDrawnItem(bottomTag);
2695 float screenPosition = GetScrollPosition();
2697 __pListModel->SetGroupExpandState(groupIndex, true);
2701 _TableViewItem* pItem = null;
2702 TableViewItemTag itemTag = {-1, -1};
2703 float groupTotalHeight = 0.0f;
2704 int itemCount = GetItemCountAt(groupIndex);
2705 for (int i = 0; i < itemCount; i++)
2707 pItem = static_cast<_TableViewItem*>(__pListModel->GetItemFromTemporaryBuffer(groupIndex, i));
2708 groupTotalHeight += pItem->GetItemHeight();
2709 itemTag.groupIndex = groupIndex;
2710 itemTag.itemIndex = i;
2711 SetItemHeight(itemTag, pItem->GetItemHeight());
2713 AdjustClientAreaBounds(false, groupTotalHeight);
2715 if (groupIndex < topTag.groupIndex || groupIndex > bottomTag.groupIndex)
2717 _TableViewItem* pItem = FindItem(topTag);
2720 FloatRectangle itemBounds = pItem->GetBoundsF();
2721 itemBounds.y = CalculateItemPositionY(topTag.groupIndex, topTag.itemIndex);
2722 pItem->SetBounds(itemBounds);
2723 AttachNextItemsToBottom(topTag);
2724 if (groupIndex < topTag.groupIndex)
2726 ScrollTo(screenPosition + groupTotalHeight);
2730 int firstLoadedGroupIndex = -1;
2731 int firstLoadedItemIndex = -1;
2732 __pListModel->GetFirstLoadedItemIndex(firstLoadedGroupIndex, firstLoadedItemIndex);
2734 for (int j = firstLoadedGroupIndex; j <= topTag.groupIndex; j++)
2736 int itemCount = GetItemCountAt(j);
2738 for (int i = -1; i < itemCount; i++)
2740 if (i >= topTag.itemIndex && j == topTag.groupIndex)
2751 itemTag.groupIndex = groupIndex;
2752 itemTag.itemIndex = -1;
2754 __expandableItemTag.groupIndex = groupIndex;
2755 __expandableItemTag.itemIndex = -1;
2759 _TableViewItem *pItem = FindItem(itemTag);
2765 FloatRectangle itemBounds = pItem->GetBoundsF();
2766 float startPosition = itemBounds.y + itemBounds.height;
2768 float endPosition = startPosition + groupTotalHeight;
2769 if (endPosition > screenPosition + __pTableView->GetBoundsF().height)
2771 endPosition = screenPosition + __pTableView->GetBoundsF().height;
2774 _VisualElement* pVisualElement = __pTableView->GetVisualElement();
2775 String animationName(L"EXPAND_GROUP_ANIMATION");
2777 VisualElementValueAnimation* pAnimation = __pTableView->GetVisualElementValueAnimation(animationName);
2778 pAnimation->SetStartValue(Variant(startPosition));
2779 pAnimation->SetEndValue(Variant(endPosition));
2780 pAnimation->SetDuration(EXPAND_GROUP_ANIMATION_DURATION);
2781 pVisualElement->AddAnimation(animationName, *pAnimation);
2785 ExpandGroupAnimationFinished(false);
2792 _TableViewPresenter::CollapseGroup(int groupIndex, bool withAnimation)
2794 if ((groupIndex < 0) || (groupIndex >= GetGroupCount()))
2796 return E_OUT_OF_RANGE;
2799 if (__modelInitialized == false)
2801 return E_INVALID_STATE;
2804 if (IsGroupExpanded(groupIndex) == false)
2809 TableViewItemTag itemTag;
2810 GetTopDrawnItem(itemTag);
2812 TableViewItemTag bottomTag;
2813 GetBottomDrawnItem(bottomTag);
2814 float screenPosition = GetScrollPosition();
2816 __pListModel->SetGroupExpandState(groupIndex, false);
2820 if (groupIndex < itemTag.groupIndex || groupIndex > bottomTag.groupIndex)
2822 _TableViewItem* pItem = null;
2823 TableViewItemTag itemTag = {-1, -1};
2824 float groupTotalHeight = 0;
2825 int itemCount = GetItemCountAt(groupIndex);
2826 for (int i = 0; i < itemCount; i++)
2828 _TableViewItem* pItem = static_cast<_TableViewItem*>(__pListModel->GetItemFromTemporaryBuffer(groupIndex, i));
2829 groupTotalHeight += pItem->GetItemHeight();
2830 itemTag.groupIndex = groupIndex;
2831 itemTag.itemIndex = i;
2832 SetItemHeight(itemTag, pItem->GetItemHeight());
2835 TableViewItemTag firstLoadedItemTag;
2836 __pListModel->GetFirstLoadedItemIndex(firstLoadedItemTag.groupIndex, firstLoadedItemTag.itemIndex);
2838 if (firstLoadedItemTag.groupIndex == groupIndex)
2840 SetLoadedItemsVisibleInGroup(groupIndex, false);
2841 firstLoadedItemTag.groupIndex = groupIndex + 1;
2842 firstLoadedItemTag.itemIndex = -1;
2845 for (int i = 0; i < itemCount; i++)
2847 UnloadItem(groupIndex, i);
2850 __pListModel->GetFirstLoadedItemIndex(firstLoadedItemTag.groupIndex, firstLoadedItemTag.itemIndex);
2851 pItem = FindItem(firstLoadedItemTag);
2854 FloatRectangle itemBounds = pItem->GetBoundsF();
2855 itemBounds.y = CalculateItemPositionY(firstLoadedItemTag.groupIndex, firstLoadedItemTag.itemIndex);
2856 pItem->SetBounds(itemBounds);
2857 AttachNextItemsToBottom(firstLoadedItemTag);
2858 if (groupIndex < itemTag.groupIndex)
2860 ScrollTo(screenPosition - groupTotalHeight);
2864 AdjustClientAreaBounds(false, -groupTotalHeight);
2869 if (itemTag.groupIndex < groupIndex)
2871 itemTag.groupIndex = groupIndex;
2872 itemTag.itemIndex = -1;
2874 __expandableItemTag.groupIndex = itemTag.groupIndex;
2875 __expandableItemTag.itemIndex = itemTag.itemIndex;
2877 if(__firstDrawnFlag)
2879 withAnimation = false;
2884 _TableViewItem *pItem = FindItem(itemTag);
2890 FloatRectangle itemBounds = pItem->GetBoundsF();
2891 float startPosition = 0;
2892 if (itemTag.itemIndex == -1)
2894 startPosition = itemBounds.y + itemBounds.height;
2898 startPosition = GetScrollPosition();
2901 if (bottomTag.groupIndex > groupIndex)
2903 bottomTag.groupIndex = groupIndex+1;
2904 bottomTag.itemIndex = -1;
2907 pItem = FindItem(bottomTag);
2913 itemBounds = pItem->GetBoundsF();
2914 float endPosition = itemBounds.y;
2915 if (bottomTag.groupIndex != groupIndex +1)
2917 endPosition += itemBounds.height;
2920 if (endPosition > screenPosition + __pTableView->GetBoundsF().height)
2922 endPosition = screenPosition + __pTableView->GetBoundsF().height;
2925 _VisualElement* pVisualElement = __pTableView->GetVisualElement();
2926 String animationName(L"COLLAPSE_GROUP_ANIMATION");
2928 VisualElementValueAnimation* pAnimation = __pTableView->GetVisualElementValueAnimation(animationName);
2929 pAnimation->SetStartValue(Variant(endPosition));
2930 pAnimation->SetEndValue(Variant(startPosition));
2931 pAnimation->SetDuration(COLLAPSE_GROUP_ANIMATION_DURATION);
2932 pVisualElement->AddAnimation(animationName, *pAnimation);
2936 CollapseGroupAnimationFinished(false);
2943 _TableViewPresenter::IsGroupExpanded(int groupIndex) const
2945 return __pListModel->IsGroupExpanded(groupIndex);
2949 _TableViewPresenter::StopExpandCollapseAnimation(void)
2951 _VisualElement* pVisualElement = __pTableView->GetVisualElement();
2952 String animationName(L"EXPAND_GROUP_ANIMATION");
2953 VisualElementValueAnimation* pExpandGroupAnimation = dynamic_cast<VisualElementValueAnimation*>(pVisualElement->GetAnimationN(animationName));
2954 if (pExpandGroupAnimation != null)
2956 pVisualElement->RemoveAnimation(animationName);
2957 delete pExpandGroupAnimation;
2960 animationName = L"COLLAPSE_GROUP_ANIMATION";
2961 VisualElementValueAnimation* pCollapseGroupAnimation = dynamic_cast<VisualElementValueAnimation*>(pVisualElement->GetAnimationN(animationName));
2962 if (pCollapseGroupAnimation != null)
2964 pVisualElement->RemoveAnimation(animationName);
2965 delete pCollapseGroupAnimation;
2970 _TableViewPresenter::LoadAllItemsInGroup(int groupIndex, bool downward)
2972 int itemCountInGroup = __pListModel->GetItemCountInGroup(groupIndex);
2973 _TableViewItem* pItem = null;
2977 for (int i = 0; i < itemCountInGroup; i++)
2979 pItem = LoadItem(groupIndex, i);
2983 SysLogException(NID_UI_CTRL, E_SYSTEM, "[%s] A system error has been occurred. Unable to load item.", GetErrorMessage(E_SYSTEM) );
2989 for (int i = itemCountInGroup-1; i >= 0; i--)
2991 pItem = LoadItem(groupIndex, i);
2995 SysLogException(NID_UI_CTRL, E_SYSTEM, "[%s] A system error has been occurred. Unable to load item.", GetErrorMessage(E_SYSTEM) );
3000 return itemCountInGroup;
3004 _TableViewPresenter::SetLoadedItemsVisibleInGroup(int groupIndex, bool visible)
3006 int itemCountInGroup = __pListModel->GetItemCountInGroup(groupIndex);
3007 _TableViewItem* pItem = null;
3008 TableViewItemTag itemTag;
3009 itemTag.groupIndex = groupIndex;
3011 int firstLoadedGroupIndex = -1;
3012 int firstLoadedItemIndex = -1;
3013 __pListModel->GetFirstLoadedItemIndex(firstLoadedGroupIndex, firstLoadedItemIndex);
3015 if (firstLoadedGroupIndex > groupIndex)
3021 if (groupIndex == firstLoadedGroupIndex && firstLoadedItemIndex > 0)
3023 startIndex = firstLoadedItemIndex;
3026 for (int i = startIndex; i < itemCountInGroup; i++)
3028 itemTag.itemIndex = i;
3029 pItem = FindItem(itemTag);
3035 pItem->SetVisibleState(visible);
3040 _TableViewPresenter::LoadItemsToBeVisible(const TableViewItemTag& from)
3042 TableViewItemTag bottomTag = from;
3043 TableViewItemTag current;
3044 TableViewItemTag next;
3046 _TableViewItem *pItem = LoadItem(from.groupIndex, from.itemIndex);
3053 FloatRectangle itemBounds = pItem->GetBoundsF();
3054 float viewHeight = __pTableView->GetBoundsF().height;
3055 float scrollPosition = GetScrollPosition();
3056 float itemPosition = itemBounds.y + itemBounds.height - scrollPosition;
3058 while (viewHeight >= itemPosition)
3060 current.groupIndex = bottomTag.groupIndex;
3061 current.itemIndex = bottomTag.itemIndex;
3062 if (!GetNextItemPosition(current, next))
3067 pItem = LoadItem(next.groupIndex, next.itemIndex);
3068 bottomTag.groupIndex = next.groupIndex;
3069 bottomTag.itemIndex = next.itemIndex;
3070 itemPosition += pItem->GetBoundsF().height;
3077 _TableViewPresenter::AttachNextItemsToBottom(const TableViewItemTag& anchor)
3079 TableViewItemTag itemTag = anchor;
3080 TableViewItemTag current;
3081 TableViewItemTag next;
3083 _TableViewItem *pItem = FindItem(itemTag);
3089 FloatRectangle itemBounds = pItem->GetBoundsF();
3090 float itemPosition = itemBounds.y + itemBounds.height;
3092 current.groupIndex = itemTag.groupIndex;
3093 current.itemIndex = itemTag.itemIndex;
3094 while (GetNextItemPosition(current, next))
3096 pItem = FindItem(next);
3103 itemBounds = pItem->GetBoundsF();
3104 itemBounds.y = itemPosition;
3105 pItem->SetBounds(itemBounds);
3106 itemPosition += itemBounds.height;
3112 _TableViewPresenter::IsAnyItemInGroupLoaded(int groupIndex) const
3114 int startGroupIndex = 0;
3115 int endGroupIndex = 0;
3118 __pListModel->GetFirstLoadedItemIndex(startGroupIndex, index);
3119 __pListModel->GetLastLoadedItemIndex(endGroupIndex, index);
3121 return groupIndex >= startGroupIndex && groupIndex <= endGroupIndex;
3125 _TableViewPresenter::ScrollToHideNonClientArea(TableViewItemTag& bottomTag)
3127 _TableViewItem* pItem = FindItem(bottomTag);
3133 FloatRectangle itemBounds = pItem->GetBoundsF();
3134 float viewHeight = __pTableView->GetBoundsF().height;
3135 float scrollPosition = GetScrollPosition();
3136 float itemBottom = itemBounds.y + itemBounds.height - scrollPosition;
3138 if (itemBottom < viewHeight)
3140 scrollPosition -= viewHeight - itemBottom;
3141 if (scrollPosition < 0)
3146 SetScrollPosition(scrollPosition, false);
3151 _TableViewPresenter::AdjustClientAreaBounds(bool reset, float dist)
3153 float clientHeight = 0;
3157 __itemTotalHeight = GetHeightOfAllItems();
3158 clientHeight = __itemTotalHeight;
3162 __itemTotalHeight = __itemTotalHeight + dist;
3163 clientHeight = __itemTotalHeight;
3166 SetClientAreaHeight(clientHeight);
3170 _TableViewPresenter::SetClientAreaHeight(float height)
3172 FloatRectangle screenBounds = __pTableView->GetBoundsF();
3173 FloatRectangle clientBounds = screenBounds;
3175 clientBounds.height = height;
3177 if (clientBounds.height < screenBounds.height)
3179 clientBounds.height = screenBounds.height;
3182 SetScrollAreaBounds(clientBounds);
3184 _Scroll* pScroll = __pTableView->GetScrollBar();
3185 if (pScroll != null)
3187 pScroll->SetScrollRange(__pTableView->GetBoundsF().height, clientBounds.height);
3192 _TableViewPresenter::UnloadInvisibleItems(void)
3194 float scrollPosition = GetScrollPosition();
3195 TableViewItemTag itemTag;
3196 __pListModel->GetFirstLoadedItemIndex(itemTag.groupIndex, itemTag.itemIndex);
3198 _TableViewItem* pItem = null;
3199 FloatRectangle bounds;
3201 while ((pItem = FindItem(itemTag)) != null)
3203 if (itemTag.itemIndex != -1)
3205 bounds = pItem->GetBoundsF();
3206 if (bounds.y + bounds.height < scrollPosition)
3208 UnloadItem(itemTag);
3215 __pListModel->GetFirstLoadedItemIndex(itemTag.groupIndex, itemTag.itemIndex);
3218 __pListModel->GetLastLoadedItemIndex(itemTag.groupIndex, itemTag.itemIndex);
3219 scrollPosition += __pTableView->GetBoundsF().height;
3221 while ((pItem = FindItem(itemTag)) != null)
3223 if (itemTag.itemIndex != -1)
3225 bounds = pItem->GetBoundsF();
3226 if (bounds.y > scrollPosition)
3228 UnloadItem(itemTag);
3235 __pListModel->GetLastLoadedItemIndex(itemTag.groupIndex, itemTag.itemIndex);
3241 _TableViewPresenter::ScrollToInternal(float newPosition)
3243 if (!IsScrollEnabled())
3248 if (IsScrollAnimationRunning())
3250 if (__scrollPositionOnFlickStarted > newPosition)
3252 newPosition += GetScrollAreaBounds().height - __scrollHeightOnFlickStarted;
3256 float currentScrollPosition = GetScrollPosition();
3257 float currentscrollAreaHeight = GetScrollAreaBounds().height;
3258 float newScrollPosition = (newPosition < 0) ? 0 : (newPosition > currentscrollAreaHeight ? currentscrollAreaHeight : newPosition);
3259 float newScrollAreaHeight = 0;
3261 if (IsModelUpdating())
3263 currentScrollPosition = GetScrollPositionInternal();
3266 if (!__lockLoadItemWithScroll)
3268 LoadItemWithScrollPosition(currentScrollPosition, newScrollPosition);
3270 if (currentScrollPosition > newScrollPosition)
3272 newScrollAreaHeight = GetScrollAreaBounds().height;
3273 newScrollPosition += newScrollAreaHeight - currentscrollAreaHeight;
3277 //scroll effect for _ScrollPanel
3278 if (newPosition < 0.0f || newPosition > currentscrollAreaHeight - __pTableView->GetBoundsF().height)
3280 newScrollPosition = newPosition;
3283 return _ScrollPanelPresenter::ScrollToInternal(newScrollPosition);
3287 _TableViewPresenter::LoadItemWithScrollPosition(float previousScrollPosition, float currentScrollPos)
3291 TableViewItemTag lastLoadedItemPos = {-1, -1};
3292 TableViewItemTag firstLoadedItemPos = {-1, -1};
3293 __pListModel->GetLastLoadedItemIndex(lastLoadedItemPos.groupIndex, lastLoadedItemPos.itemIndex);
3294 __pListModel->GetFirstLoadedItemIndex(firstLoadedItemPos.groupIndex, firstLoadedItemPos.itemIndex);
3296 if (currentScrollPos > previousScrollPosition && lastLoadedItemPos.groupIndex != -1)
3298 _TableViewItem* pLastItem = FindItem(lastLoadedItemPos);
3299 if (pLastItem == null)
3304 while (pLastItem && (pLastItem->GetBoundsF().y <= currentScrollPos + __pTableView->GetBoundsF().height))
3306 TableViewItemTag nextItemPos = {-1, -1};
3307 if (GetNextItemPosition(lastLoadedItemPos, nextItemPos))
3309 if (nextItemPos.itemIndex == -1)
3311 LoadItem(nextItemPos.groupIndex, nextItemPos.itemIndex);
3313 if (!GetNextItemPosition(nextItemPos, nextItemPos))
3319 if (nextItemPos.groupIndex != -1)
3321 _TableViewItem* pItem = LoadItem(nextItemPos.groupIndex, nextItemPos.itemIndex);
3327 FloatRectangle scrollAreaBounds = GetScrollAreaBounds();
3328 if (pItem->GetBoundsF().y + pItem->GetBoundsF().height >= scrollAreaBounds.height)
3330 AdjustClientAreaBounds(true);
3339 lastLoadedItemPos = nextItemPos;
3340 pLastItem = static_cast<_TableViewItem*>(__pListModel->LoadItem(lastLoadedItemPos.groupIndex, lastLoadedItemPos.itemIndex));
3344 if (currentScrollPos < previousScrollPosition && firstLoadedItemPos.groupIndex != -1)
3346 _TableViewItem* pFirstItem = FindItem(firstLoadedItemPos);
3347 if (pFirstItem == null)
3352 float scrollOffsetFromBottom = GetScrollAreaBounds().height - currentScrollPos;
3356 FloatRectangle scrollAreaBounds = GetScrollAreaBounds();
3357 float itemOffsetFromBottom = scrollAreaBounds.height - (pFirstItem->GetBoundsF().y + pFirstItem->GetBoundsF().height);
3359 if (scrollOffsetFromBottom < itemOffsetFromBottom)
3364 TableViewItemTag prevItemPos = {-1, -1};
3365 if (GetPreviousItemPosition(firstLoadedItemPos, prevItemPos))
3367 if (prevItemPos.itemIndex == -1)
3369 LoadItem(prevItemPos.groupIndex, prevItemPos.itemIndex);
3371 if (!GetPreviousItemPosition(prevItemPos, prevItemPos))
3377 if (prevItemPos.groupIndex != -1)
3379 LoadItem(prevItemPos.groupIndex, prevItemPos.itemIndex);
3387 firstLoadedItemPos = prevItemPos;
3388 pFirstItem = FindItem(firstLoadedItemPos);
3394 _TableViewPresenter::ScrollToItem(int groupIndex, int itemIndex, TableViewScrollItemAlignment itemAlignment, float shiftingDistance)
3396 _VisualElement* pVisualElement = __pTableView->GetVisualElement();
3397 String animationName(L"EXPAND_GROUP_ANIMATION");
3398 VisualElementValueAnimation* pExpandGroupAnimation = dynamic_cast<VisualElementValueAnimation*>(pVisualElement->GetAnimationN(animationName));
3399 if (pExpandGroupAnimation != null)
3401 __scrollToItemTag.groupIndex = groupIndex;
3402 __scrollToItemTag.itemIndex = itemIndex;
3403 __scrollToItemTag.itemAlignment = itemAlignment;
3404 __scrollToItemTag.shiftingDistance = shiftingDistance;
3405 __scrollToItemTag.startedAnimation = true;
3406 delete pExpandGroupAnimation;
3410 animationName = L"COLLAPSE_GROUP_ANIMATION";
3411 VisualElementValueAnimation* pCollapseGroupAnimation = dynamic_cast<VisualElementValueAnimation*>(pVisualElement->GetAnimationN(animationName));
3412 if (pCollapseGroupAnimation != null)
3414 __scrollToItemTag.groupIndex = groupIndex;
3415 __scrollToItemTag.itemIndex = itemIndex;
3416 __scrollToItemTag.itemAlignment = itemAlignment;
3417 __scrollToItemTag.shiftingDistance = shiftingDistance;
3418 __scrollToItemTag.startedAnimation = true;
3419 delete pCollapseGroupAnimation;
3423 if (IsGroupExpanded(groupIndex) == false)
3428 TableViewItemTag itemPos = {groupIndex, itemIndex};
3430 StopAllItemAnimation();
3433 if (!__pListModel->IsLoadedItem(groupIndex, itemIndex))
3435 ResetItemLayout(itemPos, shiftingDistance);
3438 _TableViewItem* pItem = FindItem(itemPos);
3445 float scrollPosition = pItem->GetBoundsF().y;
3447 scrollPosition = scrollPosition + shiftingDistance;
3449 SetScrollPosition(scrollPosition, false);
3451 if (itemAlignment == TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_BOTTOM)
3453 SetScrollPosition(scrollPosition - (__pTableView->GetBoundsF().height - pItem->GetBoundsF().height), false);
3458 _TableViewPresenter::ScrollByPixel(float scrollDistance)
3461 result r = GetLastResult();
3462 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
3466 ScrollTo(scrollDistance + GetScrollPosition());
3467 r = GetLastResult();
3468 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
3470 RollbackBouncing(true);
3471 r = GetLastResult();
3472 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
3475 r = GetLastResult();
3476 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
3482 _TableViewPresenter::SetScrollEnabled(bool enable)
3484 __scrolling = enable;
3488 _TableViewPresenter::IsScrollEnabled(void) const
3494 _TableViewPresenter::GetFirstDrawnFlag(void) const
3496 return __firstDrawnFlag;
3500 _TableViewPresenter::GetMaxItemCachingSize(void) const
3502 return __pListModel->GetMaxCachingSize();
3506 _TableViewPresenter::ResetSweepItem(void)
3508 if (__sweptItemTag.groupIndex != -1 && __sweptItemTag.itemIndex != -1)
3515 _TableViewPresenter::GetSweepItemIndex(int& groupIndex, int& itemIndex) const
3517 groupIndex = __sweptItemTag.groupIndex;
3518 itemIndex = __sweptItemTag.itemIndex;
3522 _TableViewPresenter::GetPressedItemCount(void)
3524 _TableViewItem* pItem = null;
3525 TableViewItemTag itemPos = {-1, -1};
3526 TableViewItemTag lastItemPos = {-1, -1};
3529 __pListModel->GetFirstLoadedItemIndex(itemPos.groupIndex, itemPos.itemIndex);
3530 __pListModel->GetLastLoadedItemIndex(lastItemPos.groupIndex, lastItemPos.itemIndex);
3534 pItem = static_cast <_TableViewItem*>(__pListModel->LoadItem(itemPos.groupIndex, itemPos.itemIndex));
3540 if (pItem->GetDrawingStatus() == TABLE_VIEW_ITEM_DRAWING_STATUS_PRESSED)
3545 if ((itemPos.itemIndex == lastItemPos.itemIndex) && (itemPos.groupIndex == lastItemPos.groupIndex))
3549 } while (GetNextItemPosition(itemPos, itemPos) == true);
3555 _TableViewPresenter::BlockAnimationCallback(bool blocked)
3557 __isAnimationCallbackBlocked = blocked;
3561 _TableViewPresenter::CalculateItemPositionY(int groupIndex, int itemIndex)
3563 TableViewItemTag itemPos = {-1, -1};
3564 TableViewItemTag currentItemPos = {-1, -1};
3565 float positionY = 0.0f;
3567 GetFirstItem(itemPos);
3569 if (itemPos.groupIndex == -1 && itemPos.itemIndex == -1)
3574 if (__pProviderAdaptor == null)
3579 positionY = GetTopMargin();
3581 while ((itemPos.groupIndex < groupIndex) || ((itemPos.groupIndex == groupIndex) && (itemPos.itemIndex < itemIndex)))
3583 currentItemPos = itemPos;
3585 float itemHeight = GetItemHeight(itemPos);
3587 positionY += itemHeight;
3589 if (!GetNextItemPosition(currentItemPos, itemPos))
3599 _TableViewPresenter::FadeInScrollBar(void)
3601 TableViewScrollBarStyle scrollStyle = __pTableView->GetScrollStyle();
3603 if (scrollStyle == TABLE_VIEW_SCROLL_BAR_STYLE_NONE)
3605 _Scroll* pScroll = __pTableView->GetScrollBar();
3607 if (pScroll != null)
3609 pScroll->SetVisibleState(false);
3612 else if (scrollStyle == TABLE_VIEW_SCROLL_BAR_STYLE_FAST_SCROLL)
3614 _Scroll* pScroll = __pTableView->GetScrollBar();
3616 if (pScroll != null)
3618 pScroll->SetVisibleState(false);
3621 _FastScroll* pFastScroll = __pTableView->GetFastScrollBar();
3623 if (pFastScroll != null)
3625 pFastScroll->SetScrollVisibility(true);
3630 _ScrollPanelPresenter::FadeInScrollBar();
3635 _TableViewPresenter::FadeOutScrollBar(void)
3637 TableViewScrollBarStyle scrollStyle = __pTableView->GetScrollStyle();
3638 if (scrollStyle == TABLE_VIEW_SCROLL_BAR_STYLE_FAST_SCROLL)
3640 StopFastScrollTimer();
3642 if (!_ScrollPanelPresenter::IsScrollAnimationRunning())
3644 StartFastScrollTimer();
3647 else if (scrollStyle == TABLE_VIEW_SCROLL_BAR_STYLE_FIXED)
3649 _Scroll* pScroll = __pTableView->GetScrollBar();
3651 if (pScroll != null)
3653 pScroll->SetScrollingEffectVisibility(false);
3658 _ScrollPanelPresenter::FadeOutScrollBar();
3663 _TableViewPresenter::SweepItem(float x)
3665 if (!_FloatCompare(x, 0.0f))
3667 _TableViewItem* pItem = static_cast<_TableViewItem*>(__pListModel->LoadItem(__sweptItemTag.groupIndex, __sweptItemTag.itemIndex));
3671 _TableViewItem* pContextItem = pItem->GetContextItem();
3673 if (pContextItem != null)
3675 float currentPosition = __sweptItemPosition.x + x;
3676 float sweepDistance = __pTableView->GetBoundsF().width;
3677 float sweepMargin = 0.0f;
3678 float contextItemWidth = pItem->GetBoundsF().width;
3679 bool activated = pItem->IsContextItemActivated();
3680 bool needToFireEvent = false;
3682 GET_SHAPE_CONFIG(TABLEVIEW::CONTEXTITEM_RIGHT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, sweepMargin);
3684 if (currentPosition >= (sweepDistance - sweepMargin))
3686 currentPosition = (sweepDistance - sweepMargin);
3687 needToFireEvent = !activated;
3689 else if (currentPosition <= __leftMargin)
3691 currentPosition = __leftMargin;
3692 needToFireEvent = activated;
3695 __sweptItemPosition.x = currentPosition;
3697 // Set TableViewItem bounds
3698 pItem->SetPosition(__sweptItemPosition);
3700 // Set TableViewContextItem bounds
3701 if (!__pTableView->IsAncestorOf(*pContextItem))
3703 pContextItem->SetDrawingProperty(__pItemDrawingProperty);
3704 __pTableView->InsertChildToBottom(*pContextItem);
3705 __pTableView->UpdateLayout();
3708 contextItemWidth = ((contextItemWidth > (__sweptItemPosition.x - __leftMargin)) ? (__sweptItemPosition.x - __leftMargin) : contextItemWidth);
3710 pContextItem->ExposeContextItem(FloatRectangle(__leftMargin, __sweptItemPosition.y, contextItemWidth, pContextItem->GetSizeF().height), pItem->GetSize().width);
3712 if (needToFireEvent)
3714 PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_SLIDER_SWEEP, pItem);
3716 activated = !activated; // ContextItem Activation State Changed
3718 __pTableView->FireTableViewContextItemActivationEvent(__sweptItemTag.groupIndex, __sweptItemTag.itemIndex, pContextItem, activated);
3719 pItem->SetContextItemActivation(activated);
3732 _TableViewPresenter::ResetSweptItem(void)
3734 _TableViewItem* pItem = static_cast<_TableViewItem*>(__pListModel->LoadItem(__sweptItemTag.groupIndex, __sweptItemTag.itemIndex));
3738 _VisualElement* pVisualElement = __pTableView->GetVisualElement();
3740 if (pVisualElement != null)
3742 String animationName(L"SWEEP_ITEM_ANIMATION");
3743 VisualElementAnimation* pContextItemAnimation = pVisualElement->GetAnimationN(animationName);
3744 if (pContextItemAnimation != null)
3746 pVisualElement->RemoveAnimation(animationName);
3748 delete pContextItemAnimation;
3752 pItem->SetPosition(FloatPoint(__leftMargin, __sweptItemPosition.y));
3754 _TableViewItem* pContextItem = pItem->GetContextItem();
3755 if (pContextItem != null)
3757 if (__pTableView->IsAncestorOf(*pContextItem))
3759 __pTableView->DetachChild(*pContextItem);
3762 if (pItem->IsContextItemActivated())
3764 __pTableView->FireTableViewContextItemActivationEvent(__sweptItemTag.groupIndex, __sweptItemTag.itemIndex, pContextItem, false);
3765 pItem->SetContextItemActivation(false);
3770 __sweptItemTag.itemIndex = -1;
3771 __sweptItemTag.groupIndex = -1;
3773 __sweptItemPosition.SetPosition(-1.0f, -1.0f);
3774 __sweepOccured = false;
3778 _TableViewPresenter::AdjustSweptItemPosition(bool withAnimation)
3780 float itemWidth = __pTableView->GetBoundsF().width;
3781 float sweepDistance = 0.0f;
3783 if (_FloatCompare(__sweptItemPosition.x, __leftMargin))
3789 float sweepMargin = 0.0f;
3790 GET_SHAPE_CONFIG(TABLEVIEW::CONTEXTITEM_RIGHT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, sweepMargin);
3792 if (__sweptItemPosition.x > (itemWidth - sweepMargin) / 2)
3794 sweepDistance = itemWidth - __sweptItemPosition.x;
3798 sweepDistance = -__sweptItemPosition.x;
3803 SweepItem(sweepDistance);
3807 _TableViewItem* pItem = static_cast<_TableViewItem*>(__pListModel->LoadItem(__sweptItemTag.groupIndex, __sweptItemTag.itemIndex));
3811 _VisualElement* pVisualElement = __pTableView->GetVisualElement();
3813 if (pVisualElement != null)
3815 String animationName(L"SWEEP_ITEM_ANIMATION");
3816 float startValue = __sweptItemPosition.x;
3817 float endValue = 0.0f;
3819 if(sweepDistance > 0)
3821 endValue = itemWidth - sweepMargin;
3825 if(_FloatCompare(itemWidth, __sweptItemPosition.x))
3827 endValue = itemWidth - sweepMargin;
3831 endValue = __leftMargin;
3835 pVisualElement->SetImplicitAnimationEnabled(false);
3837 VisualElementValueAnimation* pAnimation = __pTableView->GetVisualElementValueAnimation(animationName);
3838 pAnimation->SetStartValue(Variant(startValue));
3839 pAnimation->SetEndValue(Variant(endValue));
3840 pAnimation->SetDuration(SWEEP_ITEM_ANIMATION_DURATION);
3841 pVisualElement->AddAnimation(animationName, *pAnimation);
3848 _TableViewPresenter::AdjustLoadedItemWidth(void)
3850 TableViewItemTag lastLoadedItemPos = {-1, -1};
3851 TableViewItemTag firstLoadedItemPos = {-1, -1};
3852 __pListModel->GetLastLoadedItemIndex(lastLoadedItemPos.groupIndex, lastLoadedItemPos.itemIndex);
3853 __pListModel->GetFirstLoadedItemIndex(firstLoadedItemPos.groupIndex, firstLoadedItemPos.itemIndex);
3857 _TableViewItem* pItem = FindItem(firstLoadedItemPos);
3864 FloatDimension itemSize = pItem->GetSizeF();
3865 itemSize.width = __pProviderAdaptor->GetListWidth();
3867 pItem->SetItemChanged(true);
3868 pItem->SetSize(itemSize);
3870 if ((firstLoadedItemPos.itemIndex == lastLoadedItemPos.itemIndex) && (firstLoadedItemPos.groupIndex == lastLoadedItemPos.groupIndex))
3874 } while (GetNextItemPosition(firstLoadedItemPos, firstLoadedItemPos));
3878 _TableViewPresenter::OpenContextItem(int groupIndex, int itemIndex)
3880 SysTryReturn(NID_UI_CTRL, groupIndex >= 0 && groupIndex < GetGroupCount(), E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[%s] Group Index (%d) is out of range.",GetErrorMessage(E_OUT_OF_RANGE),groupIndex);
3883 TableViewItemTag itemTag = {groupIndex, itemIndex};
3884 _TableViewItem* pItem = FindItem(itemTag);
3886 SysTryReturn(NID_UI_CTRL, pItem != null, E_INVALID_OPERATION, E_INVALID_OPERATION, "[%s] Item was not loaded.", GetErrorMessage(E_INVALID_OPERATION));
3887 SysTryReturn(NID_UI_CTRL, pItem->GetContextItem() != null, E_INVALID_OPERATION, E_INVALID_OPERATION, "[%s] ContextItem is not set to the item.", GetErrorMessage(E_INVALID_OPERATION));
3888 SysTryReturn(NID_UI_CTRL,__sweptItemTag.groupIndex != groupIndex || __sweptItemTag.itemIndex != itemIndex, E_INVALID_OPERATION, E_INVALID_OPERATION, "[%s] ContextItem already opened.", GetErrorMessage(E_INVALID_OPERATION));
3892 __sweptItemTag.groupIndex = groupIndex;
3893 __sweptItemTag.itemIndex = itemIndex;
3894 __sweptItemPosition = pItem->GetPositionF();
3896 pItem->AdjustContextItemBounds();
3897 __sweepOccured = true;
3899 _VisualElement* pVisualElement = __pTableView->GetVisualElement();
3901 if (pVisualElement != null)
3903 float itemWidth = __pTableView->GetBoundsF().width;
3904 float sweepMargin = 0.0f;
3905 GET_SHAPE_CONFIG(TABLEVIEW::CONTEXTITEM_RIGHT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, sweepMargin);
3907 String animationName(L"SWEEP_ITEM_ANIMATION");
3908 float startValue = __sweptItemPosition.x;
3909 float endValue = itemWidth - sweepMargin;
3911 pVisualElement->SetImplicitAnimationEnabled(false);
3913 VisualElementValueAnimation* pAnimation = __pTableView->GetVisualElementValueAnimation(animationName);
3914 pAnimation->SetStartValue(Variant(startValue));
3915 pAnimation->SetEndValue(Variant(endValue));
3916 pAnimation->SetDuration(SWEEP_ITEM_ANIMATION_DURATION);
3917 pVisualElement->AddAnimation(animationName, *pAnimation);
3924 _TableViewPresenter::CloseContextItem(int groupIndex, int itemIndex)
3926 SysTryReturn(NID_UI_CTRL, groupIndex >= 0 && groupIndex < GetGroupCount(), E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[%s] Group Index (%d) is out of range.", GetErrorMessage(E_OUT_OF_RANGE),groupIndex);
3928 TableViewItemTag itemTag = {groupIndex, itemIndex};
3929 _TableViewItem* pItem = FindItem(itemTag);
3931 SysTryReturn(NID_UI_CTRL, pItem != null, E_INVALID_OPERATION, E_INVALID_OPERATION, "[%s] Item was not loaded.", GetErrorMessage(E_INVALID_OPERATION));
3932 SysTryReturn(NID_UI_CTRL, pItem->GetContextItem() != null, E_INVALID_OPERATION, E_INVALID_OPERATION, "[%s] ContextItem is not set to the item.", GetErrorMessage(E_INVALID_OPERATION));
3933 SysTryReturn(NID_UI_CTRL, __sweptItemTag.groupIndex == groupIndex && __sweptItemTag.itemIndex == itemIndex, E_INVALID_OPERATION, E_INVALID_OPERATION, "[%s] ContextItem was not opened.", GetErrorMessage(E_INVALID_OPERATION));
3941 _TableViewPresenter::IsContextItemOpened(int groupIndex, int itemIndex) const
3943 SysTryReturn(NID_UI_CTRL, groupIndex >= 0 && groupIndex < GetGroupCount(), false, E_OUT_OF_RANGE, "[%s] Group Index (%d) is out of range. ", GetErrorMessage(E_OUT_OF_RANGE), groupIndex);
3946 if ( __sweptItemTag.groupIndex == -1 && __sweptItemTag.itemIndex == -1)
3951 if (__sweptItemTag.groupIndex == groupIndex && __sweptItemTag.itemIndex == itemIndex)
3960 _TableViewPresenter::SetSectionHeaderTextHorizontalAlignment(int sectionIndex, HorizontalAlignment alignment)
3962 SysTryReturn(NID_UI_CTRL, __pTableView->GetTableViewStyle() == TABLE_VIEW_STYLE_SECTION, E_INVALID_OPERATION, E_INVALID_OPERATION, "[%s] The style of TableView is TABLE_VIEW_STYLE_SECTION", GetErrorMessage(E_INVALID_OPERATION));
3963 SysTryReturn(NID_UI_CTRL, HasSectionHeader(sectionIndex), E_INVALID_OPERATION, E_INVALID_OPERATION, "[%s] Header is not set to the section.", GetErrorMessage(E_INVALID_OPERATION));
3964 SysTryReturn(NID_UI_CTRL, sectionIndex >= 0 && sectionIndex < GetGroupCount(), E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[%s] Section index (%d)is out of range.", GetErrorMessage(E_OUT_OF_RANGE),sectionIndex);
3966 _TableViewSectionStringAlignment newAlignment;
3968 __sectionAlignmentList.GetAt(sectionIndex, newAlignment);
3969 newAlignment.headerHorizontalAlignment = alignment;
3970 __sectionAlignmentList.SetAt(newAlignment, sectionIndex);
3972 TableViewItemTag itemTag = {sectionIndex, -1};
3973 _TableViewItem* pItem = FindItem(itemTag);
3977 pItem->SetSectionHeaderFooterAlignment(alignment);
3984 _TableViewPresenter::GetSectionHeaderTextHorizontalAlignment(int sectionIndex) const
3986 SysTryReturn(NID_UI_CTRL, __pTableView->GetTableViewStyle() == TABLE_VIEW_STYLE_SECTION, ALIGNMENT_LEFT, E_INVALID_OPERATION, "[%s] The style of TableView is TABLE_VIEW_STYLE_SECTION", GetErrorMessage(E_INVALID_OPERATION));
3987 SysTryReturn(NID_UI_CTRL, HasSectionHeader(sectionIndex), ALIGNMENT_LEFT, E_INVALID_OPERATION, "[%s] Header is not set to the section.", GetErrorMessage(E_INVALID_OPERATION));
3988 SysTryReturn(NID_UI_CTRL, sectionIndex >= 0 && sectionIndex < GetGroupCount(), ALIGNMENT_LEFT, E_OUT_OF_RANGE, "[%s] Section index (%d) is out of range.", GetErrorMessage(E_OUT_OF_RANGE),sectionIndex);
3990 _TableViewSectionStringAlignment alignment;
3991 __sectionAlignmentList.GetAt(sectionIndex, alignment);
3993 return alignment.headerHorizontalAlignment;
3997 _TableViewPresenter::SetSectionFooterTextHorizontalAlignment(int sectionIndex, HorizontalAlignment alignment)
3999 SysTryReturn(NID_UI_CTRL, __pTableView->GetTableViewStyle() == TABLE_VIEW_STYLE_SECTION, E_INVALID_OPERATION, E_INVALID_OPERATION, "[%s] The style of TableView is TABLE_VIEW_STYLE_SECTION", GetErrorMessage(E_INVALID_OPERATION));
4000 SysTryReturn(NID_UI_CTRL, HasSectionFooter(sectionIndex), E_INVALID_OPERATION, E_INVALID_OPERATION, "[%s] Footer is not set to the section.", GetErrorMessage(E_INVALID_OPERATION));
4001 SysTryReturn(NID_UI_CTRL, sectionIndex >= 0 && sectionIndex < GetGroupCount(), E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[%s] Section index (%d) is out of range.", GetErrorMessage(E_OUT_OF_RANGE),sectionIndex);
4003 _TableViewSectionStringAlignment newAlignment;
4005 __sectionAlignmentList.GetAt(sectionIndex, newAlignment);
4006 newAlignment.footerHorizontalAlignment= alignment;
4007 __sectionAlignmentList.SetAt(newAlignment, sectionIndex);
4009 TableViewItemTag itemTag = {sectionIndex, GetItemCountAt(sectionIndex) - 1};
4010 _TableViewItem* pItem = FindItem(itemTag);
4014 pItem->SetSectionHeaderFooterAlignment(alignment);
4021 _TableViewPresenter::GetSectionFooterTextHorizontalAlignment(int sectionIndex) const
4023 SysTryReturn(NID_UI_CTRL, __pTableView->GetTableViewStyle() == TABLE_VIEW_STYLE_SECTION, ALIGNMENT_RIGHT, E_INVALID_OPERATION, "[%s] The style of TableView is TABLE_VIEW_STYLE_SECTION", GetErrorMessage(E_INVALID_OPERATION));
4024 SysTryReturn(NID_UI_CTRL, HasSectionFooter(sectionIndex), ALIGNMENT_RIGHT, E_INVALID_OPERATION, "[%s] Footer is not set to the section.", GetErrorMessage(E_INVALID_OPERATION));
4025 SysTryReturn(NID_UI_CTRL, sectionIndex >= 0 && sectionIndex < GetGroupCount(), ALIGNMENT_RIGHT, E_OUT_OF_RANGE, "[%s] Section index (%d) is out of range.", GetErrorMessage(E_OUT_OF_RANGE),sectionIndex);
4027 _TableViewSectionStringAlignment alignment;
4028 __sectionAlignmentList.GetAt(sectionIndex, alignment);
4030 return alignment.footerHorizontalAlignment;
4034 _TableViewPresenter::IsValidDrawnItem(int groupIndex, int itemIndex)
4036 TableViewItemTag currentItemTag = {groupIndex, itemIndex};
4037 TableViewItemTag itemTag = {-1, -1};
4039 if (GetNextItemPosition(currentItemTag, itemTag))
4041 if (__pListModel->IsLoadedItem(itemTag.groupIndex, itemTag.itemIndex))
4047 if (GetPreviousItemPosition(currentItemTag, itemTag))
4049 if (__pListModel->IsLoadedItem(itemTag.groupIndex, itemTag.itemIndex))
4059 _TableViewPresenter::StopAllItemAnimation(void)
4061 TableViewItemTag currentItemTag = {-1, -1};
4062 TableViewItemTag lastItemTag = {-1, -1};
4064 __pListModel->GetFirstLoadedItemIndex(currentItemTag.groupIndex, currentItemTag.itemIndex);
4065 __pListModel->GetLastLoadedItemIndex(lastItemTag.groupIndex, lastItemTag.itemIndex);
4069 _TableViewItem *pItem = FindItem(currentItemTag);
4072 pItem->StopAllAnimation();
4075 if (currentItemTag.groupIndex == lastItemTag.groupIndex && currentItemTag.itemIndex == lastItemTag.itemIndex)
4080 }while (GetNextItemPosition(currentItemTag, currentItemTag));
4084 _TableViewPresenter::GetTableViewItemPosition(_TableViewItem& item, TableViewItemTag& itemTag)
4086 TableViewItemTag lastLoadedItemPos = {-1, -1};
4087 TableViewItemTag firstLoadedItemPos = {-1, -1};
4088 __pListModel->GetLastLoadedItemIndex(lastLoadedItemPos.groupIndex, lastLoadedItemPos.itemIndex);
4089 __pListModel->GetFirstLoadedItemIndex(firstLoadedItemPos.groupIndex, firstLoadedItemPos.itemIndex);
4091 _TableViewItem* pCurrentItem = null;
4094 pCurrentItem = static_cast<_TableViewItem*>(__pListModel->LoadItem(firstLoadedItemPos.groupIndex, firstLoadedItemPos.itemIndex));
4095 if (pCurrentItem == &item)
4097 itemTag.groupIndex = firstLoadedItemPos.groupIndex;
4098 itemTag.itemIndex = firstLoadedItemPos.itemIndex;
4102 if ((firstLoadedItemPos.itemIndex == lastLoadedItemPos.itemIndex) && (firstLoadedItemPos.groupIndex == lastLoadedItemPos.groupIndex))
4106 } while (GetNextItemPosition(firstLoadedItemPos, firstLoadedItemPos));
4112 _TableViewPresenter::GetItemHeight(TableViewItemTag itemTag) const
4114 float itemHeight = 0.0f;
4116 if (__pTableView->GetTableViewStyle() == TABLE_VIEW_STYLE_SECTION && itemTag.itemIndex != -1)
4118 if (HasSectionFooter(itemTag.groupIndex))
4120 if (itemTag.itemIndex == GetItemCountAt(itemTag.groupIndex) - 1)
4122 GET_SHAPE_CONFIG(TABLEVIEW::GROUPITEM_DEFAULT_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, itemHeight);
4128 if (__pProviderAdaptor == null)
4134 for (int i = 0; i < itemTag.groupIndex; i++)
4136 int itemCount = GetItemCountAt(i);
4138 startIndex = startIndex + itemCount + 1;
4141 itemTag.itemIndex++;
4142 itemTag.itemIndex = startIndex + itemTag.itemIndex;
4144 _TableViewItemHeight itemHeightListEntry;
4145 __itemHeightList.GetAt(itemTag.itemIndex, itemHeightListEntry);
4147 return itemHeightListEntry.itemHeight;
4151 _TableViewPresenter::SetItemHeight(TableViewItemTag itemTag, float height)
4154 _TableViewItemHeight oldHeightEntry;
4155 _TableViewItemHeight itemHeightListEntry;
4157 itemHeightListEntry.itemHeight = height;
4158 itemHeightListEntry.groupIndex = itemTag.groupIndex;
4159 itemHeightListEntry.itemIndex = itemTag.itemIndex;
4161 for (int i = 0; i < itemTag.groupIndex; i++)
4163 int itemCount = GetItemCountAt(i);
4165 startIndex = startIndex + itemCount + 1;
4168 itemTag.itemIndex++;
4169 itemTag.itemIndex = startIndex + itemTag.itemIndex;
4171 __itemHeightList.GetAt(itemTag.itemIndex, oldHeightEntry);
4173 itemHeightListEntry.isFooterItem = oldHeightEntry.isFooterItem;
4175 __itemHeightList.SetAt(itemHeightListEntry, itemTag.itemIndex);
4177 return oldHeightEntry.itemHeight;
4181 _TableViewPresenter::SetReorderMode(bool enabled)
4185 __reorderInfo.itemIndex = -1;
4186 __reorderInfo.groupIndex = -1;
4188 _TableViewItem* pItem = null;
4189 TableViewItemTag itemPos = {-1, -1};
4190 TableViewItemTag lastItemPos = {-1, -1};
4192 __pListModel->GetFirstLoadedItemIndex(itemPos.groupIndex, itemPos.itemIndex);
4193 __pListModel->GetLastLoadedItemIndex(lastItemPos.groupIndex, lastItemPos.itemIndex);
4197 pItem = FindItem(itemPos);
4201 if(pItem->IsReorderMode() == enabled)
4206 pItem->SetReorderMode(enabled);
4208 if (enabled && itemPos.itemIndex != -1)
4210 if (pItem->GetDrawingStatus() == TABLE_VIEW_ITEM_DRAWING_STATUS_PRESSED)
4212 if (SelectReorderItem(itemPos.groupIndex, itemPos.itemIndex, true))
4214 FloatPoint itemPosition = pItem->GetPositionF();
4215 FloatPoint touchPosition = pItem->GetLastTouchPressedPositionF();
4217 __reorderInfo.touchPressedPositionY = itemPosition.y + touchPosition.y - GetScrollPosition();
4218 __reorderInfo.blockedTouchReleaseState = true;
4224 if ((itemPos.itemIndex == lastItemPos.itemIndex) && (itemPos.groupIndex == lastItemPos.groupIndex))
4229 } while (GetNextItemPosition(itemPos, itemPos) == true);
4235 _TableViewPresenter::SelectReorderItem(int groupIndex, int itemIndex, bool directSelection)
4237 if (itemIndex == -1 || (!directSelection && GetPressedItemCount() > 0))
4242 TableViewItemTag itemPos = {groupIndex, itemIndex};
4243 _TableViewItem* pItem = FindItem(itemPos);
4250 pItem->SetDrawingStatus(TABLE_VIEW_ITEM_DRAWING_STATUS_PRESSED);
4251 pItem->SetItemChanged(true);
4252 pItem->Invalidate();
4254 __reorderInfo.blockedScroll = false;
4255 __reorderInfo.itemBounds = pItem->GetBoundsF();
4256 __reorderInfo.itemIndex = itemIndex;
4257 __reorderInfo.groupIndex = groupIndex;
4258 __reorderInfo.originGroupIndex = groupIndex;
4259 __reorderInfo.originItemIndex = itemIndex;
4260 __reorderInfo.itemBasisPositionY = __reorderInfo.itemBounds.y;
4262 Tizen::System::SystemTime::GetTicks(__reorderInfo.touchPressedTick);
4264 pItem->GetVisualElement()->SetZOrder(null, true);
4266 if (GetScrollAreaBounds().height < __pTableView->GetBoundsF().height)
4268 float itemHeight = pItem->GetBoundsF().height;
4270 __pListModel->GetLastLoadedItemIndex(itemPos.groupIndex, itemPos.itemIndex);
4272 pItem = FindItem(itemPos);
4276 FloatRectangle itemBounds = pItem->GetBoundsF();
4277 __reorderInfo.nonScrollableLimitArea = itemBounds.y + itemBounds.height - itemHeight;
4282 __reorderInfo.nonScrollableLimitArea = 0;
4289 _TableViewPresenter::ResetReorderItem(int groupIndex, int itemIndex)
4291 TableViewItemTag itemPos = {groupIndex, itemIndex};
4292 _TableViewItem* pItem = FindItem(itemPos);
4299 pItem->SetDrawingStatus(TABLE_VIEW_ITEM_DRAWING_STATUS_NORMAL);
4300 pItem->SetItemChanged(true);
4301 pItem->Invalidate();
4303 PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_LIST_REORDER, pItem);
4305 FloatPoint position = FloatPoint(__reorderInfo.itemBounds.x, __reorderInfo.itemBounds.y);
4306 pItem->SetPosition(position);
4308 if (__reorderInfo.originGroupIndex != __reorderInfo.groupIndex || __reorderInfo.originItemIndex != __reorderInfo.itemIndex)
4310 if (__pTableView->GetTableViewStyle() == TABLE_VIEW_STYLE_SIMPLE)
4312 __pTableView->FireTableViewItemReorderEvent(__reorderInfo.originItemIndex, __reorderInfo.itemIndex);
4314 else if (__pTableView->GetTableViewStyle() == TABLE_VIEW_STYLE_GROUPED)
4316 __pTableView->FireTableViewItemReorderEvent(__reorderInfo.originGroupIndex, __reorderInfo.originItemIndex, __reorderInfo.groupIndex, __reorderInfo.itemIndex);
4320 __reorderInfo.groupIndex = -1;
4321 __reorderInfo.itemIndex = -1;
4322 __reorderInfo.originGroupIndex = -1;
4323 __reorderInfo.originItemIndex = -1;
4324 __reorderInfo.nonScrollableLimitArea = 0;
4326 StopReorderScrollTimer();
4332 _TableViewPresenter::CheckReorderItemScrollAnimation(_TableViewItem *pItem)
4334 float currentScrollPosition = GetScrollPosition();
4335 float limitTopPositionY = currentScrollPosition;
4336 float limitBottomPositionY = currentScrollPosition + __pTableView->GetBoundsF().height - __reorderInfo.itemBounds.height;
4338 float itemPositionY = pItem->GetPositionF().y;
4340 if (itemPositionY < limitTopPositionY)
4342 if (__pReorderScrollTimer == null)
4344 __reorderInfo.isScrollDirectionUp = true;
4349 else if (itemPositionY > limitBottomPositionY)
4351 if (__pReorderScrollTimer == null)
4353 __reorderInfo.isScrollDirectionUp = false;
4363 _TableViewPresenter::DragSelectedItem(float distance, bool relativeCoordinate)
4365 TableViewItemTag itemPos = {__reorderInfo.groupIndex, __reorderInfo.itemIndex};
4366 _TableViewItem* pItem = FindItem(itemPos);
4373 if (__firstTouchMoved)
4375 long long currentTick = 0;
4376 Tizen::System::SystemTime::GetTicks(currentTick);
4378 if (currentTick - __reorderInfo.touchPressedTick < REORDER_TOUCH_UIACTIVATE_DURATION)
4383 __firstTouchMoved = false;
4386 FloatPoint itemPosition = pItem->GetPositionF();
4388 if (relativeCoordinate)
4390 itemPosition.y = __reorderInfo.itemBasisPositionY + distance;
4394 itemPosition.y += distance;
4396 __reorderInfo.itemBasisPositionY += distance;
4399 if (itemPosition.y < 0)
4404 float scrollAreaHeight = GetScrollAreaBounds().height;
4405 float screenHeight = __pTableView->GetBoundsF().height;
4406 float limitBottomPositionY = 0.0f;
4408 if (scrollAreaHeight < screenHeight)
4410 limitBottomPositionY = __reorderInfo.nonScrollableLimitArea;
4414 limitBottomPositionY = scrollAreaHeight - __reorderInfo.itemBounds.height;
4417 if (itemPosition.y > limitBottomPositionY)
4419 itemPosition.y = limitBottomPositionY;
4422 pItem->SetPosition(itemPosition);
4425 if (CheckReorderItemScrollAnimation(pItem))
4427 if (__pReorderScrollTimer == null)
4429 StartReorderScrollTimer();
4434 if (__pReorderScrollTimer != null)
4436 StopReorderScrollTimer();
4441 TableViewItemTag moveItemTag = {-1, -1};
4443 if (CheckReorderItemPosition(pItem, moveItemTag))
4445 if (moveItemTag.itemIndex == -1)
4447 int destGroupIndex = moveItemTag.groupIndex;
4449 if (destGroupIndex != 0 && destGroupIndex == __reorderInfo.groupIndex)
4454 if (moveItemTag.groupIndex == 0 || !__pProviderAdaptor->IsReorderable(__reorderInfo.groupIndex, destGroupIndex))
4456 __reorderInfo.blockedScroll = true;
4462 ReorderItem(moveItemTag.groupIndex, moveItemTag.itemIndex);
4469 _TableViewPresenter::CheckReorderItemPosition(_TableViewItem* pItem, TableViewItemTag& reorderItemTag)
4471 TableViewItemTag currentItemTag = {__reorderInfo.groupIndex, __reorderInfo.itemIndex};
4472 TableViewItemTag previousItemTag = {-1, -1};
4473 TableViewItemTag nextItemTag = {-1, -1};
4475 FloatRectangle itemBounds = pItem->GetBoundsF();
4477 if (GetPreviousItemPosition(currentItemTag, previousItemTag))
4479 _TableViewItem* pPreviousItem = LoadItem(previousItemTag.groupIndex, previousItemTag.itemIndex);
4481 if (pPreviousItem != null)
4483 FloatRectangle previousItemBounds = pPreviousItem->GetBoundsF();
4485 if (itemBounds.y < previousItemBounds.y + (previousItemBounds.height / 2))
4487 //return previousItemIndex;
4488 reorderItemTag.groupIndex = previousItemTag.groupIndex;
4489 reorderItemTag.itemIndex = previousItemTag.itemIndex;
4496 if (GetNextItemPosition(currentItemTag, nextItemTag))
4498 _TableViewItem* pNextItem = LoadItem(nextItemTag.groupIndex, nextItemTag.itemIndex);
4500 if (pNextItem != null)
4502 FloatRectangle nextItemBounds = pNextItem->GetBoundsF();
4504 if (itemBounds.y + itemBounds.height > nextItemBounds.y + (nextItemBounds.height / 2))
4506 //return nextItemIndex;
4507 reorderItemTag.groupIndex = nextItemTag.groupIndex;
4508 reorderItemTag.itemIndex = nextItemTag.itemIndex;
4515 reorderItemTag.groupIndex = -1;
4516 reorderItemTag.itemIndex = -1;
4522 _TableViewPresenter::ReorderItem(int destinationGroupIndex, int destinationItemIndex)
4524 TableViewItemTag itemPos = {destinationGroupIndex, destinationItemIndex};
4526 _TableViewItem* pItem = FindItem(itemPos);
4533 if (pItem->IsAnimationPlaying())
4538 FloatRectangle destinationItemBounds = pItem->GetBoundsF();
4540 FloatPoint destinationItemPosition = FloatPoint(destinationItemBounds.x, 0.0f);
4542 if ( __reorderInfo.itemIndex > destinationItemIndex && __reorderInfo.groupIndex == destinationGroupIndex)
4544 destinationItemPosition.y = __reorderInfo.itemBounds.y + __reorderInfo.itemBounds.height - destinationItemBounds.height;
4545 __reorderInfo.itemBounds.y = destinationItemBounds.y;
4547 if (destinationItemIndex == -1)
4549 destinationGroupIndex--;
4550 int itemCount = GetItemCountAt(destinationGroupIndex);
4551 destinationItemIndex = itemCount;
4556 destinationItemPosition.y = __reorderInfo.itemBounds.y;
4557 __reorderInfo.itemBounds.y = destinationItemBounds.y + destinationItemBounds.height - __reorderInfo.itemBounds.height;
4559 if (destinationItemIndex == -1)
4561 destinationItemIndex = 0;
4565 __pListModel->MoveItem(__reorderInfo.groupIndex, __reorderInfo.itemIndex, destinationGroupIndex, destinationItemIndex);
4567 if (!pItem->MoveItem(destinationItemPosition, REORDER_ITEM_MOVE_ANIMATION_DURATION, 0))
4569 pItem->SetPosition(destinationItemPosition);
4572 __reorderInfo.itemIndex = destinationItemIndex;
4573 __reorderInfo.groupIndex = destinationGroupIndex;
4579 _TableViewPresenter::StartReorderScrollTimer(void)
4581 StopReorderScrollTimer();
4583 __pReorderScrollTimer = new (std::nothrow) Tizen::Base::Runtime::Timer;
4584 SysTryReturnVoidResult(NID_UI_CTRL, __pReorderScrollTimer != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
4586 result r = __pReorderScrollTimer->Construct(*this);
4587 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
4589 r = __pReorderScrollTimer->Start(REORDER_SCROLL_ANIMATION_TIMER_DURATION);
4590 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
4595 StopReorderScrollTimer();
4599 _TableViewPresenter::StopReorderScrollTimer(void)
4601 delete __pReorderScrollTimer;
4602 __pReorderScrollTimer = null;
4607 _TableViewPresenter::UpdateLayout(void)
4613 _TableViewPresenter::CheckItemHeightAndRefreshLayout(TableViewItemTag itemTag, bool downScroll)
4615 _TableViewItem* pItem = FindItem(itemTag);
4622 if (pItem->IsAnimationPlaying())
4627 FloatRectangle itemBounds = pItem->GetBoundsF();
4629 if (_FloatCompare(GetItemHeight(itemTag), itemBounds.height))
4634 float newHeight = itemBounds.height;
4635 float originHeight = SetItemHeight(itemTag, newHeight);
4636 float dist = newHeight - originHeight;
4638 AdjustClientAreaBounds(false, dist);
4642 itemBounds.y += dist;
4643 pItem->SetBounds(itemBounds);
4646 AttachNextItemsToBottom(itemTag);
4652 _TableViewPresenter::CreateItemHeightList(float defaultGroupItemHeight, float defaultItemHeight)
4654 int groupCount = GetGroupCount();
4656 _TableViewItemHeight itemHeightEntry;
4658 result r = __itemHeightList.SetCapacity(GetItemCount());
4659 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
4661 for (int i = 0; i < groupCount; i++)
4663 int itemCount = GetItemCountAt(i);
4664 itemHeightEntry.groupIndex = i;
4665 if (__pTableView->GetTableViewStyle() == TABLE_VIEW_STYLE_SIMPLE)
4667 itemHeightEntry.itemIndex = -1;
4668 itemHeightEntry.itemHeight = 0.0f;
4669 itemHeightEntry.isFooterItem = false;
4670 __itemHeightList.Add(itemHeightEntry);
4674 itemHeightEntry.itemIndex = -1;
4675 itemHeightEntry.itemHeight = defaultGroupItemHeight;
4676 itemHeightEntry.isFooterItem = false;
4677 __itemHeightList.Add(itemHeightEntry);
4680 for (int j = 0; j < itemCount; j++)
4682 itemHeightEntry.itemIndex = j;
4683 itemHeightEntry.itemHeight = defaultItemHeight;
4684 itemHeightEntry.isFooterItem = false;
4685 if (HasSectionFooter(i) && j == (itemCount - 1))
4687 itemHeightEntry.isFooterItem = true;
4689 __itemHeightList.Add(itemHeightEntry);
4696 DeleteItemHeightList();
4702 _TableViewPresenter::RestoreItemHeightList(float defaultGroupHeight, float defaultItemHeight)
4704 _TableViewItemHeight backupItem;
4705 _TableViewItemHeight currentItem;
4706 _TableViewItemHeight itemHeightEntry;
4707 int groupCount = GetGroupCount();
4708 bool isGroupItem = true;
4713 ArrayListT<_TableViewItemHeight> backupItemHeightList;
4714 backupItemHeightList.Construct();
4716 result r = backupItemHeightList.SetCapacity(__itemHeightList.GetCapacity());
4717 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
4719 for (int index = 0; index < __itemHeightList.GetCount(); index++)
4721 __itemHeightList.GetAt(index, backupItem);
4722 backupItemHeightList.Add(backupItem);
4725 DeleteItemHeightList();
4727 r = __itemHeightList.SetCapacity(GetItemCount());
4728 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
4730 for (int backUpListIndex = 0, actualListIndex = 0; actualListIndex < GetItemCount() && groupIndex < groupCount; )
4732 backupItemHeightList.GetAt(backUpListIndex, backupItem);
4733 if (groupIndex < groupCount)
4735 itemCount = GetItemCountAt(groupIndex);
4738 isGroupItem = false;
4739 itemHeightEntry.groupIndex = groupIndex;
4741 if (__pTableView->GetTableViewStyle() == TABLE_VIEW_STYLE_SIMPLE)
4743 itemHeightEntry.itemHeight = 0.0f;
4747 itemHeightEntry.itemHeight = defaultGroupHeight;
4750 itemHeightEntry.itemIndex = -1;
4751 itemHeightEntry.isFooterItem = false;
4752 __itemHeightList.Add(itemHeightEntry);
4761 itemHeightEntry.itemIndex = itemIndex;
4762 itemHeightEntry.itemHeight = defaultItemHeight;
4763 itemHeightEntry.isFooterItem = false;
4765 if (HasSectionFooter(groupIndex) && itemIndex == (itemCount - 1))
4767 itemHeightEntry.isFooterItem = true;
4769 __itemHeightList.Add(itemHeightEntry);
4772 if (itemIndex == itemCount)
4779 if (actualListIndex < GetItemCount() && backUpListIndex < backupItemHeightList.GetCount())
4781 __itemHeightList.GetAt(actualListIndex, currentItem);
4782 if (backupItem.isFooterItem)
4788 if(backupItem.groupIndex == currentItem.groupIndex && backupItem.itemIndex == currentItem.itemIndex)
4790 currentItem.itemHeight = backupItem.itemHeight;
4791 __itemHeightList.SetAt(currentItem, actualListIndex);
4795 else if (backupItem.groupIndex > currentItem.groupIndex)
4799 else if (backupItem.groupIndex < currentItem.groupIndex)
4805 SysLog(NID_UI_CTRL, "System error has occurred. Failed to restore the height values.");
4809 backupItemHeightList.RemoveAll();
4814 backupItemHeightList.RemoveAll();
4815 DeleteItemHeightList();
4821 _TableViewPresenter::DeleteItemHeightList(void)
4823 __itemHeightList.RemoveAll();
4827 _TableViewPresenter::RefreshItemHeightList(int groupIndex, int itemIndex, TableViewRefreshType refreshType)
4829 float defaultItemHeight = __pProviderAdaptor->GetDefaultItemHeight();
4830 float defaultGroupItemHeight = __pProviderAdaptor->GetDefaultGroupItemHeight();
4832 _TableViewItemHeight itemHeightEntry;
4835 for (int i = 0; i < groupIndex; i++)
4837 int itemCount = GetItemCountAt(i);
4838 startIndex = startIndex + itemCount + 1;
4841 int targetIndex = startIndex + itemIndex + 1;
4843 if (refreshType == TABLE_VIEW_REFRESH_TYPE_ITEM_ADD)
4845 if (itemIndex == -1)
4847 result r = __itemHeightList.SetCapacity(GetItemCount());
4848 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));
4850 int itemCount = GetItemCountAt(groupIndex);
4851 for (int i = 0; i < itemCount; i++)
4853 itemHeightEntry.groupIndex = groupIndex;
4854 itemHeightEntry.itemIndex = (itemCount - 1) - i;
4855 itemHeightEntry.itemHeight = defaultItemHeight;
4856 itemHeightEntry.isFooterItem = false;
4857 if (HasSectionFooter(groupIndex) && i == (itemCount - 1))
4859 itemHeightEntry.isFooterItem = true;
4862 __itemHeightList.InsertAt(itemHeightEntry, targetIndex);
4865 itemHeightEntry.groupIndex = groupIndex;
4866 itemHeightEntry.itemIndex = itemIndex;
4867 itemHeightEntry.itemHeight = defaultGroupItemHeight;
4868 itemHeightEntry.isFooterItem = false;
4869 __itemHeightList.InsertAt(itemHeightEntry, targetIndex);
4871 int updateIndex = targetIndex + itemCount + 1;// Increment the group Index below the added item by 1
4873 int groupCount = GetGroupCount();
4875 for (int i = 0; i < groupCount; i++)
4877 int itemCount = GetItemCountAt(i);
4878 lastIndex = lastIndex + itemCount + 1;
4881 for (int index = updateIndex; index < lastIndex; index++)
4883 __itemHeightList.GetAt(index, itemHeightEntry);
4884 itemHeightEntry.groupIndex = itemHeightEntry.groupIndex + 1;
4885 __itemHeightList.SetAt(itemHeightEntry, index);
4890 itemHeightEntry.groupIndex = groupIndex;
4891 itemHeightEntry.itemIndex = itemIndex;
4892 itemHeightEntry.itemHeight = defaultItemHeight;
4893 itemHeightEntry.isFooterItem = false;
4894 __itemHeightList.InsertAt(itemHeightEntry, targetIndex);
4896 int itemCount = GetItemCountAt(groupIndex);
4897 int remainingItemCount = (itemCount - itemIndex);
4899 for (int i = (targetIndex + 1); i < (targetIndex + remainingItemCount); i++)
4901 __itemHeightList.GetAt(i, itemHeightEntry);
4902 itemHeightEntry.groupIndex = groupIndex;
4903 itemHeightEntry.itemIndex = itemHeightEntry.itemIndex + 1;
4904 __itemHeightList.SetAt(itemHeightEntry, i);
4908 else if (refreshType == TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE)
4910 if (itemIndex == -1)
4912 int itemCount = GetItemCountAt(groupIndex) + 1;
4914 for (int i = 0; i < itemCount; i++)
4916 __itemHeightList.RemoveAt(targetIndex);
4919 int updateIndex = targetIndex;// Decrement the group Index below the added item by 1
4922 for (int i = 0; i < (GetGroupCount() + 1); i++)
4924 int itemCount = GetItemCountAt(i);
4925 lastIndex = lastIndex + itemCount + 1;
4928 for (int index = updateIndex; index < lastIndex; index++)
4930 __itemHeightList.GetAt(index, itemHeightEntry);
4931 itemHeightEntry.groupIndex = itemHeightEntry.groupIndex - 1;
4932 __itemHeightList.SetAt(itemHeightEntry, index);
4937 __itemHeightList.RemoveAt(targetIndex);
4938 int itemCount = GetItemCountAt(groupIndex);
4939 int remainingItemCount = itemCount - itemIndex;
4941 for (int i = targetIndex; i < (targetIndex + remainingItemCount); i++)
4943 __itemHeightList.GetAt(i, itemHeightEntry);
4944 itemHeightEntry.groupIndex = groupIndex;
4945 itemHeightEntry.itemIndex = (itemHeightEntry.itemIndex - 1);
4946 __itemHeightList.SetAt(itemHeightEntry, i);
4955 _TableViewPresenter::CreateSectionAlignmentList(void)
4957 if (__pTableView->GetTableViewStyle() != TABLE_VIEW_STYLE_SECTION)
4962 int groupCount = GetGroupCount();
4964 result r = __sectionAlignmentList.SetCapacity(GetGroupCount());
4965 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));
4967 _TableViewSectionStringAlignment alignment;
4968 alignment.headerHorizontalAlignment = ALIGNMENT_LEFT;
4969 alignment.footerHorizontalAlignment = ALIGNMENT_RIGHT;
4971 for (int i = 0; i < groupCount; i++)
4973 __sectionAlignmentList.Add(alignment);
4980 _TableViewPresenter::DeleteSectionAlignmentList(void)
4982 __sectionAlignmentList.RemoveAll();
4986 _TableViewPresenter::RefreshSectionAlignmentList(int groupIndex, TableViewRefreshType refreshType)
4988 if (__pTableView->GetTableViewStyle() != TABLE_VIEW_STYLE_SECTION)
4993 if (refreshType == TABLE_VIEW_REFRESH_TYPE_ITEM_ADD)
4995 _TableViewSectionStringAlignment alignment;
4996 alignment.headerHorizontalAlignment = ALIGNMENT_LEFT;
4997 alignment.footerHorizontalAlignment = ALIGNMENT_RIGHT;
4999 __sectionAlignmentList.InsertAt(alignment, groupIndex);
5001 else if (refreshType == TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE)
5003 __sectionAlignmentList.RemoveAt(groupIndex);
5010 _TableViewPresenter::CaptureAndStartRemoveItemAnimation(int groupIndex, int itemIndex)
5012 TableViewItemTag itemTag = {groupIndex, itemIndex};
5013 _TableViewItem* pItem = FindItem(itemTag);
5020 FloatRectangle itemBounds = pItem->GetBoundsF();
5021 result r = E_SUCCESS;
5023 _VisualElement* pVisualElement = null;
5024 String animationName(L"REMOVE_ITEM_ANIMATION");
5025 Canvas* pCanvas = null;
5026 VisualElementValueAnimation* pAnimation = __pTableView->GetVisualElementValueAnimation(animationName);
5028 FloatDimension startValue(100.0f, itemBounds.height);
5029 FloatDimension endValue(0.0f, 0.0f);
5031 Tizen::Graphics::Bitmap* pBitmap = pItem->GetCapturedBitmapN(true);
5033 if (pBitmap == null)
5039 pVisualElement = new (std::nothrow) _VisualElement();
5040 SysTryCatch(NID_UI_CTRL, pVisualElement != null, , E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
5042 r = pVisualElement->Construct();
5043 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
5045 pVisualElement->SetImplicitAnimationEnabled(false);
5046 pVisualElement->SetSurfaceOpaque(false);
5047 pVisualElement->SetBounds(FloatRectangle(itemBounds.x, itemBounds.y, itemBounds.width, itemBounds.height));
5048 pVisualElement->SetShowState(true);
5050 pCanvas = pVisualElement->GetCanvasN();
5051 SysTryCatch(NID_UI_CTRL, pCanvas != null, , E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
5054 pCanvas->DrawBitmap(FloatRectangle(0, 0, itemBounds.width, itemBounds.height), *pBitmap);
5056 pAnimation->SetDelay(0);
5057 pAnimation->SetStartValue(Variant(startValue));
5058 pAnimation->SetEndValue(Variant(endValue));
5059 pAnimation->SetDuration(REMOVE_ITEM_MOVE_ANIMATION_DURATION);
5061 r = pVisualElement->AddAnimation(animationName, *pAnimation);
5062 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
5073 pVisualElement->Destroy();
5077 _TableViewPresenter::PresetItemHeightList(void)
5079 int groupCount = GetGroupCount();
5080 float defaultGroupItemHeight = __pProviderAdaptor->GetDefaultGroupItemHeight();
5081 float defaultItemHeight = __pProviderAdaptor->GetDefaultItemHeight();
5083 for (int i = 0; i < groupCount; i++)
5085 TableViewItemTag itemTag = {i, -1};
5086 int itemCount = GetItemCountAt(i);
5088 if (_FloatCompare(GetItemHeight(itemTag), TABLEVIEW_DEFAULT_ITEM_HEIGHT_VALUE))
5090 SetItemHeight(itemTag, defaultGroupItemHeight);
5093 for (int j = 0; j < itemCount; j++)
5095 itemTag.itemIndex = j;
5097 if (_FloatCompare(GetItemHeight(itemTag), TABLEVIEW_DEFAULT_ITEM_HEIGHT_VALUE))
5099 SetItemHeight(itemTag, defaultItemHeight);
5106 _TableViewPresenter::GetTableViewItemFromControl(const _Control& source)
5108 _Control* currentControl = const_cast<_Control*>(&source);
5109 _TableViewItem* pItem = null;
5111 while (__pTableView != currentControl)
5113 pItem = dynamic_cast<_TableViewItem*>(currentControl);
5115 if ((pItem != null) || (currentControl == null))
5120 currentControl = currentControl->GetParent();
5127 _TableViewPresenter::ShowTableViewCapturedItem(int groupIndex, int itemIndex, float height)
5129 TableViewItemTag itemTag = {groupIndex, itemIndex};
5130 _TableViewItem* pItem = FindItem(itemTag);
5132 if ((pItem == null) || _FloatCompare(height, 0.0f))
5137 result r = E_SUCCESS;
5138 Canvas* pCanvas = null;
5139 FloatRectangle itemBounds = pItem->GetBoundsF();
5141 bool visibleState = pItem->GetVisibleState();
5142 pItem->SetVisibleState(true);
5143 Bitmap* pBitmap = pItem->GetCapturedBitmapN(true);
5144 pItem->SetVisibleState(visibleState);
5146 if (pBitmap == null)
5151 if (__pCapturedItemVisualElement == null)
5153 __pCapturedItemVisualElement = new (std::nothrow) _VisualElement();
5154 SysTryCatch(NID_UI_CTRL, __pCapturedItemVisualElement != null, , E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
5156 r = __pCapturedItemVisualElement->Construct();
5157 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
5159 r = GetView()->GetVisualElement()->AttachChild(*__pCapturedItemVisualElement);
5160 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to attach child to the control VisualElement.", GetErrorMessage(r));
5162 __pCapturedItemVisualElement->SetSurfaceOpaque(false);
5163 __pCapturedItemVisualElement->SetImplicitAnimationEnabled(false);
5166 __pCapturedItemVisualElement->SetShowState(true);
5167 __pCapturedItemVisualElement->SetBounds(FloatRectangle(itemBounds.x, itemBounds.y, itemBounds.width, height));
5169 pCanvas = __pCapturedItemVisualElement->GetCanvasN();
5170 SysTryCatch(NID_UI_CTRL, pCanvas != null, , E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
5172 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
5174 pCanvas->DrawBitmap(FloatPoint(0.0f, 0.0f), *pBitmap);
5184 __pCapturedItemVisualElement->Destroy();
5188 _TableViewPresenter::SetLoadedItemsVisibleFromPosition(float position, bool visible)
5190 _TableViewItem* pItem;
5191 FloatRectangle itemBounds;
5192 TableViewItemTag current;
5193 current.groupIndex = __expandableItemTag.groupIndex;
5194 current.itemIndex = __expandableItemTag.itemIndex;
5196 int itemCountInGroup = __pListModel->GetItemCountInGroup(__expandableItemTag.groupIndex);
5198 for (int i = 0; i < itemCountInGroup; i++)
5200 current.itemIndex = i;
5204 pItem = LoadItem(current.groupIndex, current.itemIndex);
5212 pItem = FindItem(current);
5219 itemBounds = pItem->GetBoundsF();
5223 if ((position >= itemBounds.y) && (position < itemBounds.y + itemBounds.height))
5225 ShowTableViewCapturedItem(current.groupIndex, current.itemIndex, position - itemBounds.y);
5226 pItem->SetVisibleState(false);
5231 pItem->SetVisibleState(true);
5236 if (position < itemBounds.y)
5238 UnloadItem(current);
5240 else if ((position >= itemBounds.y) && (position < itemBounds.y + itemBounds.height))
5242 pItem->SetVisibleState(false);
5243 ShowTableViewCapturedItem(current.groupIndex, current.itemIndex, position - itemBounds.y);
5247 pItem->SetVisibleState(true);
5254 _TableViewPresenter::MoveLoadedItemsFromPosition(float position)
5256 FloatRectangle itemBounds;
5257 float itemPosition = position;
5259 TableViewItemTag current;
5260 TableViewItemTag next;
5262 current.groupIndex = __expandableItemTag.groupIndex;
5263 current.itemIndex = __pListModel->GetItemCountInGroup(__expandableItemTag.groupIndex) -1;
5265 float screenPosition = GetScrollPosition();
5266 FloatRectangle screenBounds = __pTableView->GetBoundsF();
5267 screenPosition += screenBounds.height;
5269 _TableViewItem* pItem = null;
5270 while (GetNextItemPosition(current, next))
5272 if (screenPosition > itemPosition)
5274 pItem = LoadItem(next.groupIndex, next.itemIndex);
5278 pItem = FindItem(next);
5286 itemBounds = pItem->GetBoundsF();
5287 itemBounds.y = itemPosition;
5288 pItem->SetBounds(itemBounds);
5289 itemPosition += itemBounds.height;
5296 _TableViewPresenter::ExpandGroupAnimationFinished(bool completedNormally)
5298 if (completedNormally == false)
5300 TableViewItemTag current;
5301 TableViewItemTag next;
5303 current.groupIndex = __expandableItemTag.groupIndex;
5304 current.itemIndex = -1;
5306 _TableViewItem* pNextItem = null;
5307 _TableViewItem* pCurrentItem = null;
5308 pCurrentItem = LoadItem(current.groupIndex, current.itemIndex);
5310 if (pCurrentItem == null)
5315 FloatRectangle itemBounds;
5316 FloatRectangle screenBounds = __pTableView->GetBoundsF();
5317 float screenPosition = GetScrollPosition() + screenBounds.height;
5318 float nextItemPositionY = pCurrentItem->GetBoundsF().y + pCurrentItem->GetBoundsF().height;
5320 while (GetNextItemPosition(current, next))
5322 if (screenPosition >= nextItemPositionY)
5324 pCurrentItem = LoadItem(current.groupIndex, current.itemIndex);
5325 if (pCurrentItem == null)
5329 pNextItem = LoadItem(next.groupIndex, next.itemIndex);
5330 if (pNextItem == null)
5334 pNextItem->SetVisibleState(true);
5335 itemBounds = pNextItem->GetBoundsF();
5336 itemBounds.y = pCurrentItem->GetBoundsF().y + pCurrentItem->GetBoundsF().height;
5337 pNextItem->SetBounds(itemBounds);
5338 nextItemPositionY = itemBounds.y + itemBounds.height;
5342 UnloadItem(next.groupIndex, next.itemIndex);
5350 int currentGroupIndex = -1;
5351 int currentItemIndex = -1;
5352 GetBottomDrawnItemIndex(currentGroupIndex, currentItemIndex);
5354 int lastLoadedGroupIndex = -1;
5355 int lastLoadedItemIndex = -1;
5356 __pListModel->GetLastLoadedItemIndex(lastLoadedGroupIndex, lastLoadedItemIndex);
5358 TableViewItemTag current;
5359 current.groupIndex = currentGroupIndex;
5360 current.itemIndex = currentItemIndex;
5362 _TableViewItem* pCurrentItem;
5363 pCurrentItem = FindItem(current);
5364 if (pCurrentItem != null)
5366 pCurrentItem->SetVisibleState(true);
5369 for (int j = currentGroupIndex; j <= lastLoadedGroupIndex; j++)
5371 int itemCount = GetItemCountAt(j);
5373 for (int i = -1; i < itemCount; i++)
5375 if (i <= currentItemIndex && j == currentGroupIndex)
5387 _TableViewPresenter::CollapseGroupAnimationFinished(bool completedNormally)
5389 _TableViewItem* pItem = null;
5390 TableViewItemTag itemTag = {-1, -1};
5391 float groupTotalHeight = 0;
5392 int itemCountInGroup = __pListModel->GetItemCountInGroup(__expandableItemTag.groupIndex);
5393 for (int i = 0; i < itemCountInGroup; i++)
5395 pItem = static_cast<_TableViewItem*>(__pListModel->GetItemFromTemporaryBuffer(__expandableItemTag.groupIndex, i));
5396 groupTotalHeight += pItem->GetItemHeight();
5397 itemTag.groupIndex = __expandableItemTag.groupIndex;
5398 itemTag.itemIndex = i;
5399 SetItemHeight(itemTag, pItem->GetItemHeight());
5402 if (completedNormally == false)
5404 TableViewItemTag current;
5405 TableViewItemTag next;
5407 current.groupIndex = __expandableItemTag.groupIndex;
5408 current.itemIndex = -1;
5410 for (int i = 0; i < itemCountInGroup; i++)
5412 UnloadItem(__expandableItemTag.groupIndex, i);
5415 _TableViewItem* pCurrentItem = LoadItem(current.groupIndex, current.itemIndex);
5416 FloatRectangle itemBounds = pCurrentItem->GetBoundsF();
5417 itemBounds.y = CalculateItemPositionY(current.groupIndex, current.itemIndex);
5418 pCurrentItem->SetBounds(itemBounds);
5420 float nextItemPositionY = pCurrentItem->GetBoundsF().y + pCurrentItem->GetBoundsF().height;
5422 FloatRectangle screenBounds = __pTableView->GetBoundsF();
5423 float screenPosition = GetScrollPosition() + screenBounds.height;
5425 while (GetNextItemPosition(current, next))
5428 if (screenPosition >= nextItemPositionY)
5430 pCurrentItem = LoadItem(current.groupIndex, current.itemIndex);
5431 if (pCurrentItem == null)
5436 pCurrentItem->SetVisibleState(true);
5437 itemBounds = pCurrentItem->GetBoundsF();
5438 itemBounds.y = nextItemPositionY;
5439 pCurrentItem->SetBounds(itemBounds);
5440 nextItemPositionY = pCurrentItem->GetBoundsF().y + pCurrentItem->GetBoundsF().height;
5444 UnloadItem(current.groupIndex, current.itemIndex);
5448 int currentGroupIndex = -1;
5449 int currentItemIndex = -1;
5450 GetTopDrawnItemIndex(currentGroupIndex, currentItemIndex);
5451 if (__expandableItemTag.groupIndex < currentGroupIndex)
5453 SetScrollPosition(GetScrollPosition() - groupTotalHeight, false);
5458 int currentGroupIndex = -1;
5459 int currentItemIndex = -1;
5460 GetTopDrawnItemIndex(currentGroupIndex, currentItemIndex);
5462 int firstLoadedGroupIndex = -1;
5463 int firstLoadedItemIndex = -1;
5464 __pListModel->GetFirstLoadedItemIndex(firstLoadedGroupIndex, firstLoadedItemIndex);
5466 for (int j = firstLoadedGroupIndex; j <= currentGroupIndex; j++)
5468 int itemCount = GetItemCountAt(j);
5470 for (int i = -1; i < itemCount; i++)
5472 if (i >= currentItemIndex && j == currentGroupIndex)
5481 for (int i = 0; i < itemCountInGroup; i++)
5483 UnloadItem(__expandableItemTag.groupIndex, i);
5486 GetTopDrawnItemIndex(currentGroupIndex, currentItemIndex);
5487 TableViewItemTag currentItemTag;
5488 currentItemTag.groupIndex = currentGroupIndex;
5489 currentItemTag.itemIndex = currentItemIndex;
5491 _TableViewItem* pItem = FindItem(currentItemTag);
5494 FloatRectangle itemBounds = pItem->GetBoundsF();
5495 itemBounds.y = CalculateItemPositionY(currentGroupIndex, currentItemIndex);
5496 pItem->SetBounds(itemBounds);
5497 AttachNextItemsToBottom(currentItemTag);
5498 if (__expandableItemTag.groupIndex < currentGroupIndex)
5500 SetScrollPosition(itemBounds.y, false);
5505 AdjustClientAreaBounds(false, -groupTotalHeight);
5509 _TableViewPresenter::OnVisualElementAnimationStarted(const Tizen::Ui::Animations::VisualElementAnimation& animation, const Tizen::Base::String& keyName, Tizen::Ui::Animations::VisualElement& target)
5511 if (keyName == L"REMOVE_ITEM_ANIMATION")
5516 if (keyName == L"SCROLL_PANEL_SCROLLING_ANIMATION")
5518 __scrollHeightOnFlickStarted = GetScrollAreaBounds().height;
5519 __scrollPositionOnFlickStarted = GetScrollPosition();
5522 _ScrollPanelPresenter::OnVisualElementAnimationStarted(animation, keyName, target);
5526 _TableViewPresenter::OnVisualElementAnimationRepeated(const Tizen::Ui::Animations::VisualElementAnimation& animation, const Tizen::Base::String& keyName, Tizen::Ui::Animations::VisualElement& target, long currentRepeatCount)
5528 if (keyName == L"REMOVE_ITEM_ANIMATION")
5532 _ScrollPanelPresenter::OnVisualElementAnimationRepeated(animation, keyName, target, currentRepeatCount);
5536 _TableViewPresenter::OnVisualElementAnimationFinished(const Tizen::Ui::Animations::VisualElementAnimation& animation, const Tizen::Base::String& keyName, Tizen::Ui::Animations::VisualElement& target, bool completedNormally)
5538 if (__isAnimationCallbackBlocked)
5543 if (keyName == L"REMOVE_ITEM_ANIMATION")
5545 _VisualElement* pVisualElement = GetView()->GetVisualElement();
5547 pVisualElement->DetachChild(target);
5552 else if (keyName == L"EXPAND_GROUP_ANIMATION")
5554 if (__pCapturedItemVisualElement)
5556 __pCapturedItemVisualElement->SetShowState(false);
5558 ExpandGroupAnimationFinished(completedNormally);
5560 if (__scrollToItemTag.startedAnimation)
5562 __scrollToItemTag.startedAnimation = false;
5563 ScrollToItem(__scrollToItemTag.groupIndex, __scrollToItemTag.itemIndex, __scrollToItemTag.itemAlignment, __scrollToItemTag.shiftingDistance);
5567 else if (keyName == L"COLLAPSE_GROUP_ANIMATION")
5569 if (__pCapturedItemVisualElement)
5571 __pCapturedItemVisualElement->SetShowState(false);
5573 CollapseGroupAnimationFinished(completedNormally);
5575 if (__scrollToItemTag.startedAnimation)
5577 __scrollToItemTag.startedAnimation = false;
5578 ScrollToItem(__scrollToItemTag.groupIndex, __scrollToItemTag.itemIndex, __scrollToItemTag.itemAlignment, __scrollToItemTag.shiftingDistance);
5583 _ScrollPanelPresenter::OnVisualElementAnimationFinished(animation, keyName, target, completedNormally);
5587 _TableViewPresenter::OnTickOccurred(const Tizen::Ui::Animations::VisualElementAnimation& animation, const Tizen::Base::String& keyName, Tizen::Ui::Animations::VisualElement& target, const Tizen::Ui::Variant& currentValue)
5589 _VisualElement* pVisualElement = __pTableView->GetVisualElement();
5591 if (&target != pVisualElement)
5596 if (keyName == L"REMOVE_ITEM_ANIMATION")
5598 Dimension value = currentValue.ToDimension();
5599 target.SetOpacity(value.width);
5601 FloatRectangle bounds = target.GetBounds();
5602 bounds.height = value.height;
5603 target.SetBounds(bounds);
5605 target.SetFlushNeeded();
5609 else if (keyName == L"EXPAND_GROUP_ANIMATION")
5611 float currentPosition = currentValue.ToFloat();
5612 SetLoadedItemsVisibleFromPosition(currentPosition, true);
5613 MoveLoadedItemsFromPosition(currentPosition);
5617 else if (keyName == L"COLLAPSE_GROUP_ANIMATION")
5619 float currentPosition = currentValue.ToFloat();
5620 SetLoadedItemsVisibleFromPosition(currentPosition, false);
5621 MoveLoadedItemsFromPosition(currentPosition);
5625 else if (keyName == L"SWEEP_ITEM_ANIMATION")
5627 float currentPosition = currentValue.ToFloat();
5628 float moveDestance = currentPosition - __sweptItemPosition.x;
5629 SweepItem(moveDestance);
5634 _ScrollPanelPresenter::OnTickOccurred(animation, keyName, target, currentValue);
5638 _TableViewPresenter::OnAccessibilityItemRefreshed(const _AccessibilityContainer& control, const _AccessibilityElement& element, _AccessibilityFocusDirection direction)
5640 TableViewItemTag itemPos = {-1, -1};
5642 if (direction == _ACCESSIBILITY_FOCUS_DIRECTION_NEXT)
5644 GetFirstItem(itemPos);
5645 if (GetAccessibilityElementFocusedState() == false && FindItem(itemPos) == null)
5647 ScrollToItem(itemPos.groupIndex, itemPos.itemIndex, TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_TOP);
5652 else if (direction == _ACCESSIBILITY_FOCUS_DIRECTION_PREVIOUS)
5654 GetLastItem(itemPos);
5656 if (IsGroupExpanded(itemPos.groupIndex) == false)
5658 itemPos.itemIndex = -1;
5661 if (GetAccessibilityElementFocusedState() == false && FindItem(itemPos) == null)
5663 ScrollToItem(itemPos.groupIndex, itemPos.itemIndex, TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_BOTTOM);
5673 _TableViewPresenter::OnOcurredOverflowItems(const int currentCashSize, const int overflowCount)
5675 return IsCachingItemsTotalHeightLessThanViewHeight();
5679 _TableViewPresenter::OnKeyPressed(const _Control& source, const _KeyInfo& keyInfo)
5681 if (!__pTableView->IsFocusModeStateEnabled())
5686 _KeyCode keyCode = keyInfo.GetKeyCode();
5687 _Control* pFocusedControl = null;
5688 _Window* pTop = source.GetRootWindow();
5691 pFocusedControl = pTop->GetCurrentFocusControl();
5694 _TableViewItem* pItem = null;
5695 TableViewItemTag itemPos = {-1, -1};
5700 if (pFocusedControl != null)
5702 pItem = dynamic_cast<_TableViewItem*>(pFocusedControl);
5705 _Control* pParentControl = pFocusedControl->GetParent();
5706 pItem = dynamic_cast<_TableViewItem*>(pParentControl);
5711 pItem->GetItemIndex(itemPos.groupIndex, itemPos.itemIndex);
5712 TableViewItemTag firstItemPos = {-1, -1};
5713 GetFirstItem(firstItemPos);
5714 if (itemPos.groupIndex == firstItemPos.groupIndex && itemPos.itemIndex == firstItemPos.itemIndex)
5716 SetTableViewFocused(false);
5720 while (GetPreviousItemPosition(itemPos, itemPos))
5722 if (__pTableView->GetTableViewStyle() == TABLE_VIEW_STYLE_SIMPLE)
5724 TableViewItemTag firstItemPos = {-1, -1};
5725 GetFirstItem(firstItemPos);
5726 if (itemPos.groupIndex == firstItemPos.groupIndex && itemPos.itemIndex == firstItemPos.itemIndex)
5728 SetTableViewFocused(false);
5733 if (IsGroupExpanded(itemPos.groupIndex) == false)
5735 itemPos.itemIndex = -1;
5738 pItem = LoadItem(itemPos.groupIndex, itemPos.itemIndex);
5741 SetTableViewFocused(false);
5745 if (!pItem->GetVisibleState() || !pItem->GetEnableState()
5746 || !pItem->IsFocusable())
5748 TableViewItemTag firstItemPos = {-1, -1};
5749 GetFirstItem(firstItemPos);
5750 if (itemPos.groupIndex == firstItemPos.groupIndex && itemPos.itemIndex == firstItemPos.itemIndex)
5752 SetTableViewFocused(false);
5759 if (pItem->GetBoundsF().y < GetScrollPosition())
5761 ScrollToItem(itemPos.groupIndex, itemPos.itemIndex, TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_TOP);
5764 if (pItem->GetEnableState() && pItem->GetVisibleState()
5765 && pItem->IsFocusable())
5767 pItem->SetFocused(true);
5768 __focusItemTag.groupIndex = itemPos.groupIndex;
5769 __focusItemTag.itemIndex = itemPos.itemIndex;
5770 __isAnnexFocused = false;
5778 SetTableViewFocused(false);
5785 if (pFocusedControl != null)
5787 pItem = dynamic_cast<_TableViewItem*>(pFocusedControl);
5790 _Control* pParentControl = pFocusedControl->GetParent();
5791 pItem = dynamic_cast<_TableViewItem*>(pParentControl);
5796 pItem->GetItemIndex(itemPos.groupIndex, itemPos.itemIndex);
5797 TableViewItemTag lastItemPos = {-1, -1};
5798 GetLastItem(lastItemPos);
5799 if (itemPos.groupIndex == lastItemPos.groupIndex && itemPos.itemIndex == lastItemPos.itemIndex)
5801 SetTableViewFocused(false);
5805 while (GetNextItemPosition(itemPos, itemPos))
5807 if (__pTableView->GetTableViewStyle() == TABLE_VIEW_STYLE_SIMPLE && itemPos.itemIndex == -1)
5809 itemPos.itemIndex = 0;
5812 pItem = LoadItem(itemPos.groupIndex, itemPos.itemIndex);
5815 SetTableViewFocused(false);
5819 if (!pItem->GetVisibleState() || !pItem->GetEnableState()
5820 || !pItem->IsFocusable())
5822 TableViewItemTag lastItemPos = {-1, -1};
5823 GetLastItem(lastItemPos);
5825 if (itemPos.groupIndex == lastItemPos.groupIndex && itemPos.itemIndex == lastItemPos.itemIndex)
5827 SetTableViewFocused(false);
5833 if (pItem->GetBoundsF().y + pItem->GetBoundsF().height > GetScrollPosition() + __pTableView->GetBoundsF().height)
5835 ScrollToItem(itemPos.groupIndex, itemPos.itemIndex, TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_BOTTOM);
5838 if (pItem->GetEnableState() && pItem->GetVisibleState()
5839 && pItem->IsFocusable())
5841 pItem->SetFocused(true);
5843 __focusItemTag.groupIndex = itemPos.groupIndex;
5844 __focusItemTag.itemIndex = itemPos.itemIndex;
5845 __isAnnexFocused = false;
5852 SetTableViewFocused(false);
5859 SetTableViewFocused(false);
5870 _TableViewPresenter::OnKeyReleased(const _Control& source, const _KeyInfo& keyInfo)
5872 if (!__pTableView->IsFocusModeStateEnabled())
5877 _KeyCode keyCode = keyInfo.GetKeyCode();
5879 if (keyCode == _KEY_UP || keyCode == _KEY_DOWN)
5888 _TableViewPresenter::OnDrawFocus(void)
5890 if (!__pTableView->IsFocusModeStateEnabled())
5895 if (__pTableView->GetRootWindow())
5897 if(!__pTableView->GetRootWindow()->IsActivated())
5903 _Control* pFocusedControl = null;
5904 _Window* pTop = __pTableView->GetRootWindow();
5907 pFocusedControl = pTop->GetCurrentFocusControl();
5910 _TableView* pTableView = null;
5911 _TableViewItem* pItem = null;
5912 TableViewItemTag itemPos = {-1, -1};
5914 if (__isFocusedDuringOrientationChange)
5916 TableViewItemTag bottomDrawnItemIndex = {-1, -1};
5917 GetBottomDrawnItem(bottomDrawnItemIndex);
5919 if ((bottomDrawnItemIndex.groupIndex < __focusItemTag.groupIndex) ||
5920 (bottomDrawnItemIndex.groupIndex == __focusItemTag.groupIndex && bottomDrawnItemIndex.itemIndex <= __focusItemTag.itemIndex))
5922 ScrollToItem(__focusItemTag.groupIndex, __focusItemTag.itemIndex, TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_BOTTOM);
5924 __isFocusedDuringOrientationChange = false;
5927 pItem = FindItem(__focusItemTag);
5929 if (__isRestoreFocus && pItem != null)
5931 if (pItem->GetEnableState() && pItem->GetVisibleState() && pItem->IsFocusable())
5933 if (__isAnnexFocused)
5935 pItem->DrawAnnexFocus();
5939 pItem->SetFocused(true);
5944 __isRestoreFocus = false;
5948 if (pFocusedControl != null)
5950 pTableView = dynamic_cast<_TableView*>(pFocusedControl);
5951 if (pTableView != null)
5953 if (_FocusManagerImpl::GetInstance()->IsForwardDirection() == true)
5955 GetFirstItem(itemPos);
5956 if (__pTableView->GetTableViewStyle() == TABLE_VIEW_STYLE_SIMPLE)
5958 itemPos.itemIndex = 0;
5961 ScrollToItem(itemPos.groupIndex, itemPos.itemIndex, TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_TOP);
5962 pItem = FindItem(itemPos);
5965 if (pItem->GetEnableState() && pItem->GetVisibleState()
5966 && pItem->IsFocusable())
5968 __focusItemTag.groupIndex = itemPos.groupIndex;
5969 __focusItemTag.itemIndex = itemPos.itemIndex;
5970 __isAnnexFocused = false;
5971 pItem->SetFocused(true);
5976 while (GetNextItemPosition(itemPos, itemPos))
5978 TableViewItemTag topDrawnItemIndex = {-1, -1};
5979 GetTopDrawnItem(topDrawnItemIndex);
5980 if (topDrawnItemIndex.groupIndex <= itemPos.groupIndex && topDrawnItemIndex.itemIndex <= itemPos.itemIndex)
5982 TableViewItemTag bottomDrawnItemIndex = {-1, -1};
5983 GetBottomDrawnItem(bottomDrawnItemIndex);
5984 if (bottomDrawnItemIndex.groupIndex >= itemPos.groupIndex && bottomDrawnItemIndex.itemIndex >= itemPos.itemIndex)
5986 pItem = FindItem(itemPos);
5990 ScrollToItem(itemPos.groupIndex, itemPos.itemIndex, TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_TOP);
5991 pItem = FindItem(itemPos);
5996 ScrollToItem(itemPos.groupIndex, itemPos.itemIndex, TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_TOP);
5997 pItem = FindItem(itemPos);
6002 if (!pItem->GetVisibleState() || !pItem->GetEnableState()
6003 || !pItem->IsFocusable())
6005 TableViewItemTag lastItemPos = {-1, -1};
6006 GetLastItem(lastItemPos);
6008 if (itemPos.groupIndex == lastItemPos.groupIndex && itemPos.itemIndex == lastItemPos.itemIndex)
6017 __focusItemTag.groupIndex = itemPos.groupIndex;
6018 __focusItemTag.itemIndex = itemPos.itemIndex;
6019 __isAnnexFocused = false;
6020 pItem->SetFocused(true);
6031 GetLastItem(itemPos);
6032 ScrollToItem(itemPos.groupIndex, itemPos.itemIndex, TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_BOTTOM);
6033 pItem = FindItem(itemPos);
6037 if (pItem->GetEnableState() && pItem->GetVisibleState()
6038 && pItem->IsFocusable())
6040 __focusItemTag.groupIndex = itemPos.groupIndex;
6041 __focusItemTag.itemIndex = itemPos.itemIndex;
6042 __isAnnexFocused = false;
6043 pItem->SetFocused(true);
6048 while (GetPreviousItemPosition(itemPos, itemPos))
6050 TableViewItemTag bottomDrawnItemIndex = {-1, -1};
6051 GetBottomDrawnItem(bottomDrawnItemIndex);
6053 if (bottomDrawnItemIndex.groupIndex >= itemPos.groupIndex && bottomDrawnItemIndex.itemIndex >= itemPos.itemIndex)
6055 TableViewItemTag topDrawnItemIndex = {-1, -1};
6056 GetTopDrawnItem(topDrawnItemIndex);
6057 if (topDrawnItemIndex.groupIndex <= itemPos.groupIndex && topDrawnItemIndex.itemIndex <= itemPos.itemIndex)
6059 pItem = FindItem(itemPos);
6063 ScrollToItem(itemPos.groupIndex, itemPos.itemIndex, TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_BOTTOM);
6064 pItem = FindItem(itemPos);
6069 ScrollToItem(itemPos.groupIndex, itemPos.itemIndex, TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_BOTTOM);
6070 pItem = FindItem(itemPos);
6075 if (!pItem->GetVisibleState() || !pItem->GetEnableState()
6076 || !pItem->IsFocusable())
6078 TableViewItemTag firstItemPos = {-1, -1};
6079 GetFirstItem(firstItemPos);
6080 if (itemPos.groupIndex == firstItemPos.groupIndex && itemPos.itemIndex == firstItemPos.itemIndex)
6089 __focusItemTag.groupIndex = itemPos.groupIndex;
6090 __focusItemTag.itemIndex = itemPos.itemIndex;
6091 __isAnnexFocused = false;
6092 pItem->SetFocused(true);
6106 _TableViewPresenter::OnFocusModeStateChanged(void)
6108 __isFocusedDuringOrientationChange = false;
6109 __focusItemTag.groupIndex = -1;
6110 __focusItemTag.itemIndex = -1;
6111 __isRestoreFocus = false;
6112 __isAnnexFocused = false;
6114 _Window* pTop = __pTableView->GetRootWindow();
6118 _Control* pFocusedControl = pTop->GetCurrentFocusControl();
6120 if (pFocusedControl != null)
6122 pFocusedControl->RemoveFocusRing();
6128 _TableViewPresenter::OnVisibleStateChanged(void)
6131 if (__pTableView->IsFocused())
6133 __pTableView->RemoveFocusRing();
6138 _TableViewPresenter::OnAncestorEnableStateChanged(const _Control& control)
6141 if (__pTableView->IsFocused())
6143 __pTableView->RemoveFocusRing();
6148 _TableViewPresenter::OnAncestorVisibleStateChanged(const _Control& control)
6151 if (__pTableView->IsFocused())
6153 __pTableView->RemoveFocusRing();
6158 _TableViewPresenter::OnFocusableStateChanged(bool focusableState)
6160 if (!focusableState)
6163 if (__pTableView->IsFocused())
6165 __pTableView->RemoveFocusRing();
6171 _TableViewPresenter::GetAccessibilityElementFocusedState(void)
6173 _TableViewItem* pItem = null;
6174 TableViewItemTag itemPos = {-1, -1};
6175 TableViewItemTag lastItemPos = {-1, -1};
6177 __pListModel->GetFirstLoadedItemIndex(itemPos.groupIndex, itemPos.itemIndex);
6178 __pListModel->GetLastLoadedItemIndex(lastItemPos.groupIndex, lastItemPos.itemIndex);
6182 pItem = static_cast <_TableViewItem*>(__pListModel->LoadItem(itemPos.groupIndex, itemPos.itemIndex));
6183 SysTryReturn(NID_UI_CTRL, pItem != null, false, E_OUT_OF_RANGE, "[%s] Group Index (%d) Item Index (%d) is out of range.", GetErrorMessage(E_OUT_OF_RANGE),itemPos.groupIndex,itemPos.itemIndex);
6185 _AccessibilityContainer* pContainer = pItem->GetAccessibilityContainer();
6186 _AccessibilityElement* pElement = null;
6188 if (pContainer != null)
6190 pElement = pContainer->GetCurrentFocusedElement();
6191 if (pElement != null)
6197 if ((itemPos.itemIndex == lastItemPos.itemIndex) && (itemPos.groupIndex == lastItemPos.groupIndex))
6202 } while (GetNextItemPosition(itemPos, itemPos) == true);
6208 _TableViewPresenter::FireItemTouchReleasedEventDuringPressing(int groupIndex, int itemIndex)
6210 TableViewItemTag fireItemPos;
6211 fireItemPos.groupIndex = groupIndex;
6212 fireItemPos.itemIndex = itemIndex;
6214 __itemTouchReleasedEventState = TABLE_VIEW_ITEM_TOUCH_RELEASED_EVENT_FIRE;
6215 _TableViewItem* pItem = FindItem(fireItemPos);
6218 pItem->FireItemTouchReleased();
6221 // for new item after UpdateTableView.
6222 pItem = FindItem(fireItemPos);
6225 if (__itemTouchReleasedEventState == TABLE_VIEW_ITEM_TOUCH_RELEASED_EVENT_UPDATE_TABLE_VIEW)
6227 __itemTouchReleasedEventState = TABLE_VIEW_ITEM_TOUCH_RELEASED_EVENT_NORMAL;
6231 pItem->SetSelectionState(true);
6232 pItem->FireItemTouchPressed();
6238 _TableViewPresenter::SetFocusDuringOrientationChange(void)
6240 if (__focusItemTag.groupIndex != -1)
6242 __isFocusedDuringOrientationChange = true;
6247 _TableViewSectionStringAlignment::operator== (const _TableViewSectionStringAlignment& rhs) const
6249 if (headerHorizontalAlignment == rhs.headerHorizontalAlignment && footerHorizontalAlignment == rhs.footerHorizontalAlignment)
6258 _TableViewSectionStringAlignment::operator!= (const _TableViewSectionStringAlignment& rhs) const
6260 if (headerHorizontalAlignment == rhs.headerHorizontalAlignment && footerHorizontalAlignment == rhs.footerHorizontalAlignment)
6269 _TableViewItemHeight::operator!= (const _TableViewItemHeight& rhs) const
6271 if (groupIndex == rhs.groupIndex && itemIndex == rhs.itemIndex && itemHeight == rhs.itemHeight && isFooterItem == rhs.isFooterItem)
6280 _TableViewItemHeight::operator== (const _TableViewItemHeight& rhs) const
6282 if (groupIndex == rhs.groupIndex && itemIndex == rhs.itemIndex && itemHeight == rhs.itemHeight && isFooterItem == rhs.isFooterItem)
6289 }}} // Tizen::Ui::Controls