Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / inc / FUiCtrl_ScrollPresenter.h
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://floralicense.org/license/
10 //
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.
16 //
17
18 /**
19  * @file                FUiCtrl_ScrollPresenter.h
20  * @brief               This is the header file for the _ScrollPresenter class.
21  *
22  * This header file contains the declarations of the %_ScrollPresenter class.
23  */
24
25 #ifndef _FUICTRL_INTERNAL_FASTSCROLL_PRESENTER_H_
26 #define _FUICTRL_INTERNAL_FASTSCROLL_PRESENTER_H_
27
28 #include "FBaseString.h"
29
30 #include "FGrpBitmap.h"
31 #include "FGrpRectangle.h"
32 #include "FGrpColor.h"
33 #include "FGrpDimension.h"
34
35 #include "FUi_Control.h"
36 #include "FUi_UiTouchEvent.h"
37
38 #include "FUiAnim_VisualElement.h"
39 #include "FUiAnimVisualElementAnimation.h"
40 #include "FUiAnimVisualElementAnimationProvider.h"
41 #include "FUiAnimIVisualElementAnimationStatusEventListener.h"
42
43 #include "FUiCtrl_Scroll.h"
44
45 namespace Tizen { namespace Ui { namespace Controls
46 {
47
48 class _UiScrollEvent;
49 class _IScrollEventListener;
50
51
52 class _ScrollPresenter
53         : public Tizen::Ui::Animations::VisualElementAnimationProvider
54         , public Tizen::Ui::Animations::IVisualElementAnimationStatusEventListener
55         , virtual public Tizen::Ui::Animations::IVisualElementAnimationProvider
56         , virtual public _IUiEventListener
57 {
58 public:
59         virtual ~_ScrollPresenter(void);
60         static _ScrollPresenter* CreateScrollPresenterN(Tizen::Ui::_Control& parentCtrl,
61                                                                                                                                 _Scroll& scrollCtrl,
62                                                                                                                                 _ScrollDirection scrollDirection,
63                                                                                                                                 bool enableFadeEffect,
64                                                                                                                                 bool enableJumpToTop,
65                                                                                                                                 bool enableHandler,
66                                                                                                                                 bool visibility,
67                                                                                                                                 int viewRange,
68                                                                                                                                 int scrollRange,
69                                                                                                                                 int scrollPosition);
70
71         result SetScrollDirection(_ScrollDirection scrollDirection);
72         _ScrollDirection GetScrollDirection(void) const;
73         result SetScrollRange(int viewRange, int scrollRange);
74         void GetScrollRange(int* pViewRange, int* pScrollRange) const;
75         result SetScrollPosition(int scrollPosition);
76         int GetScrollPosition(void) const;
77
78         void EnableFadeEffect(bool enable);
79         bool IsEnabledFadeEffect(void) const;
80         bool IsOnFadeEffect(void) const;
81         void EnableScrollingEffect(bool enable);
82         bool IsEnabledScrollingEffect(void) const;
83         void EnableOverScrollingEffect(bool enable);
84         bool IsEnabledOverScrollingEffect(void) const;
85         void SetParentUsingViewport(bool useViewPort);
86         bool IsParentUsingViewport(void) const;
87
88         result SetScrollVisibility(bool visibility);
89         bool GetScrollVisibility(void) const;
90         void CancelFadeEffect(void);
91
92         result EnableJumpToTop(bool enable);
93         bool IsEnabledJumpToTop(void) const;
94
95         result EnableHandler(bool enable);
96         bool IsEnabledHandler(void) const;
97
98         result SetScrollingEffectVisibility(bool visibility);
99
100         void AddScrollEventListener(const Tizen::Ui::Controls::_IScrollEventListener& listener);
101         void RemoveScrollEventListener(const Tizen::Ui::Controls::_IScrollEventListener& listener);
102
103         void OnParentBoundsChanged(void);
104
105         void OnDraw(void);
106         bool OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo);
107         bool OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo);
108         bool OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo);
109         Tizen::Ui::Animations::HitTestResult HitTest(const Tizen::Graphics::FloatPoint& point);
110
111
112         virtual Tizen::Ui::Animations::VisualElementAnimation* CreateAnimationForProperty(Tizen::Ui::Animations::VisualElement& target, const Tizen::Base::String& property);
113         virtual void OnVisualElementAnimationStarted(const Tizen::Ui::Animations::VisualElementAnimation& animation, const Tizen::Base::String& keyName, Tizen::Ui::Animations::VisualElement& target);
114         virtual void OnVisualElementAnimationRepeated(const Tizen::Ui::Animations::VisualElementAnimation& animation, const Tizen::Base::String& keyName, Tizen::Ui::Animations::VisualElement& target, long currentRepeatCount);
115         virtual void OnVisualElementAnimationFinished(const Tizen::Ui::Animations::VisualElementAnimation& animation, const Tizen::Base::String& keyName, Tizen::Ui::Animations::VisualElement& target, bool completedNormally);
116
117 private:
118         _ScrollPresenter(const _ScrollPresenter& rhs);
119         _ScrollPresenter& operator =(const _ScrollPresenter& rhs);
120
121         _ScrollPresenter(void);
122         result Construct(Tizen::Ui::_Control& parentCtrl,
123                                                         _Scroll& scrollCtrl,
124                                                         _ScrollDirection scrollDirection,
125                                                         bool enableFadeEffect,
126                                                         bool enableJumpToTop,
127                                                         bool enableHandler,
128                                                         bool visibility,
129                                                         int viewRange,
130                                                         int scrollRange,
131                                                         int scrollPosition);
132
133         result LoadResources(_ScrollDirection scrollDirection, _ControlOrientation orientation);
134         result LoadColorConfig(void);
135         result LoadBitmapResources(_ScrollDirection scrollDirection);
136         result LoadShapeConfig(_ScrollDirection scrollDirection, _ControlOrientation orientation);
137         void ReleaseBitmapResources(void);
138
139         Tizen::Graphics::Rectangle CalculateScrollCtrlBounds(_ScrollDirection scrollDirection);
140         Tizen::Graphics::Rectangle CalculateThumbBounds(_ScrollDirection scrollDirection);
141         Tizen::Graphics::Point CalculateThumbPosition(_ScrollDirection scrollDirection);
142         Tizen::Graphics::Dimension CalculateThumbSize(_ScrollDirection scrollDirection);
143         Tizen::Graphics::Rectangle CalculateHandlerBounds(_ScrollDirection scrollDirection);
144         Tizen::Graphics::Point CalculateHandlerPosition(_ScrollDirection scrollDirection);
145         Tizen::Graphics::Dimension CalculateHandlerSize(_ScrollDirection scrollDirection);
146         Tizen::Graphics::Rectangle CalculateJumpToTopBounds(_ScrollDirection scrollDirection);
147         Tizen::Graphics::Rectangle CalculateScrollingEffectFrontBounds(_ScrollDirection scrollDirection);
148         Tizen::Graphics::Rectangle CalculateScrollingEffectReerBounds(_ScrollDirection scrollDirection);
149
150         result AttachScrollChild(Tizen::Ui::Animations::_VisualElement** ppScrollVe, const Tizen::Graphics::Rectangle& bounds, bool visibility);
151         void DetachScrollChild(Tizen::Ui::Animations::_VisualElement** ppScrollVe, bool destroy);
152         Tizen::Graphics::Rectangle GetScrollChildBounds(Tizen::Ui::Animations::_VisualElement& scrollVe) const;
153         result SetScrollChildBounds(Tizen::Ui::Animations::_VisualElement& scrollVe, const Tizen::Graphics::Rectangle& bounds);
154         result RelayoutScrollChildren(_ScrollDirection scrollDirection);
155         result SetParentBouncing(float rate);
156
157         void SetScrollingEffectOpacity(float opacity);
158         void SetScrollingEffectOpacity(Tizen::Ui::Animations::_VisualElement& Ve, bool isActive, float ratio);
159         bool IsScrollVisible(void) const;
160
161         void DrawThumb(void);
162         void DrawJumpToTop(void);
163         void DrawHandler(void);
164         void DrawScrollingEffect(void);
165         result DrawBitmap(Tizen::Graphics::Canvas& canvas, const Tizen::Graphics::Rectangle& bounds, const Tizen::Graphics::Bitmap& bitmap);
166
167         bool OnTouchPressedJumpToTop(const _Control& source, const _TouchInfo& touchinfo);
168         bool OnTouchReleasedJumpToTop(const _Control& source, const _TouchInfo& touchinfo);
169         bool OnTouchMovedJumpToTop(const _Control& source, const _TouchInfo& touchinfo);
170         bool OnTouchPressedHandler(const _Control& source, const _TouchInfo& touchinfo);
171         bool OnTouchReleasedHandler(const _Control& source, const _TouchInfo& touchinfo);
172         bool OnTouchMovedHandler(const _Control& source, const _TouchInfo& touchinfo);
173
174         void SetParentCtrl(Tizen::Ui::_Control& parentCtrl);
175         Tizen::Ui::_Control& GetParentCtrl(void) const;
176
177         void SetControl(_Scroll& scrollCtrl);
178         _Scroll& GetControl(void) const;
179
180 private:
181         Tizen::Ui::_Control* __pParentCtrl;
182         _Scroll* __pScrollCtrl;
183
184         // attributes
185         _ScrollDirection __scrollDirection;
186         bool __enableFadeEffect;
187         bool __enableJumpToTop;
188         bool __enableHandler;
189         bool __enableScrollingEffect;
190         bool __enableOverScrollingEffect;
191         bool __parentUsingViewport;
192         int __positionMin;
193         int __positionMax;
194         int __viewRange;
195         int __scrollRange;
196         int __scrollPositionCurr;
197
198         // additional information
199         int __scrollPositionPrev;
200         bool __fadeIn;
201         bool __fadeOut;
202         bool __scrollVisibility;
203         bool __scrollingEffectVisibility;
204         float __parentBouncingRate;
205         int __fadeEffectDuration_ms;
206         bool __needUpdateThumb;
207         bool __needUpdateJumpTopTop;
208         bool __needUpdateHandler;
209         bool __needUpdateScrollingEffect;
210         bool __handlerTouched;
211         int __handlerTouchedPosition;
212         bool __jumpToTopPressed;
213
214         _UiScrollEvent* __pScrollEvent;
215
216         Tizen::Ui::Animations::_VisualElement* __pCtrlVe;
217         Tizen::Ui::Animations::_VisualElement* __pThumbVe;
218         Tizen::Ui::Animations::_VisualElement* __pJumpToTopVe;
219         Tizen::Ui::Animations::_VisualElement* __pHandlerVe;
220         Tizen::Ui::Animations::_VisualElement* __pFrontScrollingEffectVe;
221         Tizen::Ui::Animations::_VisualElement* __pReerScrollingEffectVe;
222
223         Tizen::Graphics::Color __thumbColor;
224         Tizen::Graphics::Color __jumpToTopBgColor;
225         Tizen::Graphics::Color __jumpToTopColor;
226         Tizen::Graphics::Color __jumpToTopColorPressed;
227         Tizen::Graphics::Color __buttonColor;
228         Tizen::Graphics::Color __buttonColorPressed;
229
230         Tizen::Graphics::Bitmap* __pThumbBitmap;
231         Tizen::Graphics::Bitmap* __pThumbEffectBitmap;
232         Tizen::Graphics::Bitmap* __pJumpToTopBitmap;
233         Tizen::Graphics::Bitmap* __pJumpToTopEfBitmap;
234         Tizen::Graphics::Bitmap* __pJumpToTopLeftBitmap;
235         Tizen::Graphics::Bitmap* __pJumpToTopLeftEfBitmap;
236         Tizen::Graphics::Bitmap* __pButtonBitmap;
237         Tizen::Graphics::Bitmap* __pButtonEfBitmap;
238         Tizen::Graphics::Bitmap* __pButtonPressBitmap;
239         Tizen::Graphics::Bitmap* __pHandlerBgBitmap;
240         Tizen::Graphics::Bitmap* __pHandlerBgEffectBitmap;
241         Tizen::Graphics::Bitmap* __pHandlerBitmap;
242         Tizen::Graphics::Bitmap* __pFrontScrollingEffectBitmap;
243         Tizen::Graphics::Bitmap* __pReerScrollingEffectBitmap;
244
245         Tizen::Graphics::Dimension __thumbSizeMin;
246         int __thumbMargin;
247         Tizen::Graphics::Dimension __jumpToTopSize;
248         int __jumpToTopMarginRight;
249         int __jumpToTopMarginTop;
250         Tizen::Graphics::Dimension __handlerSizeMin;
251         int __handlerMarginLeft;
252         int __handlerMarginRight;
253         int __handlerMarginTop;
254         int __handlerMarginBottom;
255         int __scrollingEffectWidthLeft;
256         int __scrollingEffectWidthRight;
257         int __scrollingEffectHeightTop;
258         int __scrollingEffectHeightBottom;
259         Tizen::Base::Collection::HashMap __beforeBouncingMatrixHash;
260
261 };
262
263 }}} // Tizen::Ui::Controls
264
265 #endif //_FUICTRL_INTERNAL_FASTSCROLL_PRESENTER_H_