2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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.h
20 * @brief This is the implementation file for _TableViewPresenter class.
22 * This file contains the implementation of _TableViewPresenter class.
26 #ifndef _FUI_CTRL_INTERNAL_TABLE_VIEW_PRESENTER_H_
27 #define _FUI_CTRL_INTERNAL_TABLE_VIEW_PRESENTER_H_
29 #include <FUiCtrlTableView.h>
30 #include <FBaseColArrayListT.h>
31 #include "FUiCtrl_TableViewItem.h"
32 #include "FUiCtrl_ScrollPanelPresenter.h"
34 namespace Tizen { namespace Ui { namespace Animations
39 namespace Tizen { namespace Ui { namespace Controls
44 TABLE_VIEW_ITEM_ALIGNMENT_TOP = 0,
45 TABLE_VIEW_ITEM_ALIGNMENT_BOTTOM
48 struct _TableViewReorderInfo
54 int touchPressedPositionY;
55 int itemBasisPositionY;
56 int isScrollDirectionUp;
57 int nonScrollableLimitArea;
58 bool blockedTouchReleaseState;
59 long long touchPressedTick;
60 Tizen::Graphics::Rectangle itemBounds;
62 _TableViewReorderInfo(void)
65 , originGroupIndex(-1)
67 , touchPressedPositionY(0)
68 , itemBasisPositionY(0)
69 , isScrollDirectionUp(false)
70 , nonScrollableLimitArea(0)
71 , blockedTouchReleaseState(false)
81 class _TableViewItemProviderAdaptor;
83 class _TableViewPresenter
84 : public _ScrollPanelPresenter
85 , public Tizen::Ui::Animations::IVisualElementAnimationTickEventListener
86 , public Tizen::Ui::Animations::IVisualElementAnimationStatusEventListener
87 , virtual public Tizen::Base::Runtime::IEventListener
90 _TableViewPresenter();
91 virtual ~_TableViewPresenter(void);
93 virtual result Construct(_TableView* pTableView);
95 bool Initialize(_TableView* pTableView);
97 _TableView* GetView(void) const;
99 _ListViewModel* GetModel(void) const;
102 result SetItemProvider(const _TableViewItemProvider* pProvider);
104 virtual void PreloadItem(void);
106 void SetTableViewItemProviderAdaptor(_TableViewItemProviderAdaptor* pProviderAdaptor);
108 _TableViewItemProviderAdaptor* GetTableViewItemProviderAdaptor(void) const;
110 // event handler for window event
111 virtual void OnBoundsChanged(void);
112 virtual result Draw(void);
114 // Touch Event Previewer
115 virtual _UiTouchEventDelivery OnPreviewTouchPressed(const _Control& source, const _TouchInfo& touchInfo);
116 virtual _UiTouchEventDelivery OnPreviewTouchMoved(const _Control& source, const _TouchInfo& touchInfo);
117 virtual _UiTouchEventDelivery OnPreviewTouchReleased(const _Control& source, const _TouchInfo& touchInfo);
118 virtual _UiTouchEventDelivery OnPreviewTouchCanceled(const _Control& source, const _TouchInfo& touchInfo);
120 // Touch Event Listener
121 virtual bool OnTouchPressed(const _Control& source, const _TouchInfo& touchInfo);
122 virtual bool OnTouchMoved(const _Control& source, const _TouchInfo& touchInfo);
123 virtual bool OnTouchReleased(const _Control& source, const _TouchInfo& touchInfo);
124 virtual bool OnTouchCanceled(const _Control& source, const _TouchInfo& touchInfo);
126 // gestureListener Callback API
127 virtual bool OnFlickGestureDetected(_TouchFlickGestureDetector& gesture);
128 virtual bool OnFlickGestureCanceled(_TouchFlickGestureDetector& gesture);
129 virtual bool OnPreviewFlickGestureDetected(_TouchFlickGestureDetector& gesture);
131 virtual void OnVisualElementAnimationStarted(const Tizen::Ui::Animations::VisualElementAnimation& animation, const Tizen::Base::String& keyName, Tizen::Ui::Animations::VisualElement& target);
132 virtual void OnVisualElementAnimationRepeated(const Tizen::Ui::Animations::VisualElementAnimation& animation, const Tizen::Base::String& keyName, Tizen::Ui::Animations::VisualElement& target, long currentRepeatCount);
133 virtual void OnVisualElementAnimationFinished(const Tizen::Ui::Animations::VisualElementAnimation& animation, const Tizen::Base::String& keyName, Tizen::Ui::Animations::VisualElement& target, bool completedNormally);
134 virtual void OnTickOccurred(const Tizen::Ui::Animations::VisualElementAnimation& animation, const Tizen::Base::String& keyName, Tizen::Ui::Animations::VisualElement& target, const Tizen::Ui::Variant& currentValue);
137 virtual void OnTimerExpired(Tizen::Base::Runtime::Timer& timer);
141 result RefreshTableView(int groupIndex, int itemIndex, TableViewRefreshType type, bool animation);
142 result UpdateTableView(void);
144 result GetItemIndexFromPosition(const Tizen::Graphics::Point& position, int& groupIndex, int& itemIndex) const;
145 result GetItemFromPosition(const Tizen::Graphics::Point& position, TableViewItemTag& itemPos) const;
147 result GetTopDrawnItem(TableViewItemTag& itemPos) const;
148 result SetTopDrawnItem(TableViewItemTag& itemPos);
150 result GetBottomDrawnItem(TableViewItemTag& itemPos) const;
152 result GetTopDrawnItemIndex(int& groupIndex, int& itemIndex) const;
153 result SetTopDrawnItemIndex(int groupIndex, int itemIndex);
155 result GetBottomDrawnItemIndex(int& groupIndex, int& itemIndex) const;
156 result SetBottomDrawnItemIndex(int groupIndex, int itemIndex);
158 int GetGroupCount(void) const;
159 int GetItemCountAt(int groupIndex) const;
160 bool HasSectionFooter(int groupIndex) const;
162 int GetTopMargin(void) const;
163 result SetTopMargin(int topMargin);
165 int GetBottomMargin(void) const;
166 result SetBottomMargin(int bottomMargin);
168 int GetLeftMargin(void) const;
169 result SetLeftMargin(int leftMargin);
171 bool IsItemChecked(int groupIndex, int itemIndex) const;
172 result SetItemChecked(int groupIndex, int itemIndex, bool checked);
174 bool IsItemEnabled(int groupIndex, int itemIndex) const;
175 result SetItemEnabled(int groupIndex, int itemIndex, bool enabled);
177 _TableViewItem* FindItem(TableViewItemTag& itemTag);
178 void UnloadItem(int groupIndex, int itemIndex);
179 _TableViewItem* LoadItem(int groupIndex, int itemIndex);
180 void RefreshItemLayout(int groupIndex, int itemIndex);
181 void GetFirstLoadedItemIndex(int& groupIndex, int& itemIndex) const;
182 void GetLastLoadedItemIndex(int& groupIndex, int& itemIndex) const;
184 result SetStatusChanged(bool changed);
185 bool IsStatusChanged(void) const;
187 result ExpandGroup(int groupIndex, bool withAnimation);
188 result CollapseGroup(int groupIndex, bool withAnimation);
189 bool IsGroupExpanded(int groupIndex) const;
191 result SetReorderMode(bool enabled);
193 bool CheckItemHeightAndRefreshLayout(TableViewItemTag itemTag, bool downScroll);
195 result ScrollByPixel(int scrollDistance);
196 void SetScrollEnabled(bool enable);
197 bool IsScrollEnabled(void) const;
199 bool GetFirstDrawnFlag(void) const;
200 int GetMaxItemCachingSize(void) const;
201 void ResetSweepItem(void);
202 int GetPressedItemCount(void);
205 virtual int ScrollToInternal(int targetPosition);
207 virtual void FadeInScrollBar(void);
208 virtual void FadeOutScrollBar(void);
211 virtual void UpdateLayout(void);
214 _TableViewPresenter(const _TableViewPresenter& rhs);
215 _TableViewPresenter& operator =(const _TableViewPresenter& rhs);
217 _TableView* __pTableView;
218 _ListViewModel* __pListModel;
219 _TableViewItemProviderAdaptor* __pProviderAdaptor;
221 bool GetFirstItem(TableViewItemTag& firstItem) const;
222 bool GetPreviousItemPosition(const TableViewItemTag& currentItem, TableViewItemTag& prevItem) const;
223 bool GetNextItemPosition(const TableViewItemTag& currentItem, TableViewItemTag& nextItem) const;
224 int GetItemCount(void) const;
225 int GetHeightOfAllItems(void) const;
227 void SetItemLayout(_TableViewItem* pItem, TableViewItemTag& itemPos);
228 int CalculateItemPositionY(int groupIndex, int itemIndex);
229 void AdjustLayoutItems(int scrollPosition);
230 void ResetItemLayout(TableViewItemTag& topDrawnItemTag);
231 void RefreshItemLayout(TableViewItemTag& topDrawnItemTag, TableViewItemTag& refreshItemTag, TableViewRefreshType type, bool animation);
232 void RefreshItemBounds(_TableViewItem* pItem, TableViewItemTag& itemPos);
233 void ScrollToItem(int groupIndex, int itemIndex, TableViewScrollItemAlignment itemAlignment, int shiftingDistance = 0);
235 _TableViewItem* GetTableViewItemFromControl(const _Control& source);
237 void UnloadItem(TableViewItemTag& itemTag);
238 void DetachItem(TableViewItemTag& itemTag);
239 void DetachContextItem(TableViewItemTag& itemTag);
240 void DetachAllItem(bool removeItem);
241 void SetItemDrawingProperty(void);
242 void SetItemType(_TableViewItem* pItem, TableViewItemTag itemPosition);
244 result StartFastScrollTimer(void);
245 void StopFastScrollTimer(void);
247 bool IsEmpty(void) const;
248 result DrawEmptyTableView(void);
250 void LoadItemWithScrollPosition(int previousScrollPosition, int currentScrollPos);
252 bool GetTableViewItemPosition(_TableViewItem& item, TableViewItemTag& itemTag); // item must exist between from tag and end tag
254 int LoadAllItemsInGroup(int groupIndex, bool downward);
255 void SetLoadedItemsVisibleInGroup(int groupIndex, bool visible);
256 TableViewItemTag LoadItemsToBeVisible(const TableViewItemTag& from);
257 void AttachNextItemsToBottom(const TableViewItemTag& anchor);
258 bool IsAnyItemInGroupLoaded(int groupIndex) const;
259 bool IsAnyItemInLoadedIndex(int groupIndex, int itemIndex);
260 void ScrollToHideNonClientArea(TableViewItemTag& bottomTag);
261 void AdjustClientAreaBounds(bool reset, int dist = 0);
262 void SetClientAreaHeight(int height);
263 void UnloadInvisibleItems(void);
266 bool SelectReorderItem(int groupIndex, int itemIndex);
267 bool ResetReorderItem(int groupIndex, int itemIndex);
268 bool DragSelectedItem(int distance, bool relativeCoordinate);
269 bool CheckReorderItemScrollAnimation(_TableViewItem *pItem);
270 bool CheckReorderItemPosition(_TableViewItem* pItem, TableViewItemTag& reorderItemTag);
271 void AdjustReorderItemLimitPositionY(int& positionY);
272 bool ReorderItem(int destinationGroupIndex, int destinationItemIndex);
273 void StartReorderScrollTimer(void);
274 void StopReorderScrollTimer(void);
277 int GetItemHeight(TableViewItemTag itemTag) const;
278 int SetItemHeight(TableViewItemTag itemTag, int height);
279 bool CreateItemHeightList(void);
280 void DeleteItemHeightList(void);
281 bool RefreshItemHeightList(int groupIndex, int itemIndex, TableViewRefreshType refreshType);
283 void CaptureAndStartRemoveItemAnimation(int groupIndex, int itemIndex);
285 void SetLoadedItemsVisibleFromPosition(int position, bool visible);
286 void MoveLoadedItemsFromPosition(int position);
288 void SweepItem(int x);
289 void ResetSweptItem(void);
290 void AdjustSweptItemPosition(bool withAnimation = false);
291 void AdjustLoadedItemWidth(void);
293 bool IsValidDrawnItem(int groupIndex, int itemIndex);
300 bool __modelInitialized;
301 bool __firstDrawnFlag;
302 bool __statusChangedFlag;
308 _ItemDrawingProperty* __pItemDrawingProperty;
310 Tizen::Ui::Animations::_VisualElement* __pBaseVisualElement;
313 Tizen::Graphics::Point __sweptItemPosition;
314 TableViewItemTag __sweptItemTag;
316 TableViewItemTag __reservedScrollItemIndex;
317 TableViewScrollItemAlignment __reservedScrollItemAlignment;
319 bool __firstTouchMoved;
321 Tizen::Base::Runtime::Timer* __pReorderScrollTimer;
323 _TableViewReorderInfo __reorderInfo;
325 Tizen::Base::Collection::ArrayListT<int> __itemHeightList;
326 int __itemTotalHeight;
328 TableViewItemTag __expandableItemTag;
330 Tizen::Base::Runtime::Timer* __pFastScrollTimer;
331 bool __isFastScrollTimerEnabled;
333 static const int TABLEVIEW_MAX_ITEM_COUNT = 30;
334 static const int REORDER_SCROLL_ANIMATION_TIMER_DURATION = 10;
335 static const int REORDER_SCROLL_ANIMATION_DISTANCE = 10;
336 static const int REORDER_TOUCH_UIACTIVATE_DURATION = 100;
337 static const int FAST_SCROLL_FADE_OUT_DURATION = 500;
340 static const int REORDER_ITEM_MOVE_ANIMATION_DURATION = 113;
341 static const int ADD_ITEM_ANIMATION_DURATION = 333;
342 static const int REMOVE_ITEM_MOVE_ANIMATION_DURATION = 267;
343 static const int REFRESH_ITEM_ANIMATION_DELAY = 100;
344 static const int EXPAND_GROUP_ANIMATION_DURATION = 335;
345 static const int COLLAPSE_GROUP_ANIMATION_DURATION = 329;
346 static const int SWEEP_ITEM_ANIMATION_DURATION = 300;
349 }}} // Tizen::Ui::Controls
351 #endif // _FUI_CTRL_INTERNAL_TABLE_VIEW_PRESENTER_H_