Tizen 2.1 base
[apps/osp/Home.git] / inc / HmCustomPageControl.h
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://floralicense.org/license/
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 /**
18  * @file        HmCustomPageControl.h
19  * @brief       Keeps declaration of the HmCustomPageControl
20  * declares HmCustomPageControl class, it overrides default scrolling functionality of IconListView
21  */
22
23 #ifndef _HM_CUSTOM_PAGE_CONTROL_H_
24 #define _HM_CUSTOM_PAGE_CONTROL_H_
25
26 #include <FBase.h>
27 #include <FUi.h>
28
29 class HomeItemInfo;
30 class ICustomPageControlEventListener;
31 class IPageControlItemProvider;
32
33 /**
34  * @class       CustomPageControl
35  * @brief       This is the control which handles page by page scrolling of the application icons.
36  * It contains a custom IconListView and Provider for it.
37  */
38 class CustomPageControl
39         : public Tizen::Ui::Controls::Panel
40         , public Tizen::Ui::Controls::IIconListViewItemEventListener
41         , public Tizen::Base::Runtime::ITimerEventListener
42         , public Tizen::Ui::ITouchEventListener
43         , public Tizen::Ui::ITouchLongPressGestureEventListener
44 {
45 public:
46         /**
47          * The object is not fully constructed after this constructor is called.
48          * For full construction, the Construct() method must be called right after calling this constructor.
49          */
50         CustomPageControl(void);
51
52         /**
53          * Destructor, this destructor overrides ~Tizen::Ui::Controls::Panel
54          */
55         virtual ~CustomPageControl(void);
56
57         /**
58          * This function constructs the control properly
59          */
60         result Construct(const Tizen::Graphics::Rectangle& controlRect, int noOfPages, int pageWidth);
61
62         /**
63          * Adds a new page in the page control
64          */
65         result AddPage(void);
66
67         /**
68          * Returns currently selected page number
69          */
70         int GetCurrentSelectedPage(void);
71
72         /**
73          * Returns currently selected page number
74          */
75         Tizen::Base::Collection::ArrayList* GetIconLists(void);
76
77         /**
78          * returns the total no. of pages in the control
79          */
80         const int GetPageCount(void);
81
82         /**
83          * Marks a page to be deleted
84          */
85         void MarkPageToDelete(int pageNumber);
86
87         /**
88          * Scrolls to the next or previous page on crossing the bounds while moving icons in edit mode
89          */
90         void MovePage(void);
91
92         /**
93          * Sets the maximum number of icons in one page
94          */
95         void SetMaxNumberOfIcons(int iconsCount);
96
97         /**
98          * Sets the listener to intercept events on the page control.
99          */
100         void SetPageControlEventListener(ICustomPageControlEventListener* pListener);
101
102         /**
103          * Sets item provider for the Page control
104          */
105         void SetPageControlItemProvider(IPageControlItemProvider* pItemProvider);
106
107         /**
108          * Scrolls to the specified page number
109          */
110         void SetPageSelected(int pageNumber);
111
112         /**
113          * Enables/Disables edit mode
114          */
115         void ToggleEditMode(void);
116
117         // from IIconListViewItemEventListener
118         virtual void OnIconListViewItemStateChanged(Tizen::Ui::Controls::IconListView& iconListView, int index, Tizen::Ui::Controls::IconListViewItemStatus status);
119         virtual void OnIconListViewOverlayBitmapSelected(Tizen::Ui::Controls::IconListView& iconListView, int index, int overlayBitmapId);
120
121         // From ITimerEventListener
122         virtual void OnTimerExpired(Tizen::Base::Runtime::Timer& timer);
123
124         //from ITouchEventListener
125         virtual void OnTouchCanceled(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo) {}
126         virtual void OnTouchFocusIn(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo) {}
127         virtual void OnTouchFocusOut(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo) {}
128         virtual void OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo);
129         virtual void OnTouchPressed(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo);
130         virtual void OnTouchReleased(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo);
131
132         // From ITouchLongPressGestureEventListener
133         virtual void OnLongPressGestureCanceled(Tizen::Ui::TouchLongPressGestureDetector& gestureDetector) {}
134         virtual void OnLongPressGestureDetected(Tizen::Ui::TouchLongPressGestureDetector& gestureDetector);
135
136 private:
137         /**
138          * Removes a page from the Page control
139          */
140         result RemovePage(int pageNumber);
141
142         /**
143          * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
144          */
145         CustomPageControl(const CustomPageControl&);
146
147         /**
148          * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
149          */
150         CustomPageControl& operator =(const CustomPageControl&);
151
152 private:
153         bool __hasPageMoved; // keeps info if the page transition completed or not
154         bool __isDragging; // tell if an icon is being dragged
155         bool __isInEditMode; // tells if the control is in edit mode or not
156         bool __needAnimation; //indicates, if scroll animation needs to be played.
157         HomeItemInfo* __pDraggingAppInfo; // the app info of moving item
158         ICustomPageControlEventListener* __pEventListener; // the listener object to notify about the events
159         int __currentIndex; //the index in which the moving item is projected at the moment
160         int __currentPageNumber;  //Currently shown page number
161         int __iconsCount; //max number of icons per page
162         int __pageNumber; // current page number
163         int __pageToBeDeleted;  // page number to be deleted
164         int __pageWidth;  // width of one page
165         int __startIndex; // start index of the dragged icon
166         int __sweepTraveled; // the distance the touch has traveled,
167         int __totalPages; // total number of pages in this control
168         IPageControlItemProvider* __pPageItemProvider; // the provider for the PageItem
169         Tizen::Base::Collection::ArrayList* __pIconListProviders; // list of provider objects
170         Tizen::Base::Collection::ArrayList* __pIconLists;  //keeps the list of IconListViews
171         Tizen::Base::Runtime::Timer* __pPageMovementTimer;    // Time to be created for the duration for Page Movement
172         Tizen::Graphics::Bitmap* __pMovingItemBitmap; //The item bitmap of the moving item
173         Tizen::Graphics::Point __animationEndPoint; // starting position of touch from where the animation to be started
174         Tizen::Graphics::Point __animationStartPoint; // starting position control to be animated to.
175         Tizen::Graphics::Point __dragStartPosition; // starting position of touch dragging an item started
176         Tizen::Graphics::Point __iconListCurrentPos; // current position of the current page
177         Tizen::Graphics::Point __iconListRestPosition; // current position of the current page
178         Tizen::Graphics::Point __touchStartPoint; // starting position of touch from where the scrolling started
179         Tizen::Ui::Controls::IconListViewItem* __pMovementItem; //The Moving item
180         Tizen::Ui::Controls::Label* __pMovementLabel; // The label to show current position of touch location, to guide while repositioning
181         Tizen::Ui::TouchLongPressGestureDetector* __pGetureDetector; //LongTouchGesture detector
182 };
183
184 #endif // _HM_CUSTOM_PAGE_CONTROL_H_