Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / inc / FUiCtrl_FastScrollPresenter.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_FastScrollPresenter.h
20  * @brief               This is the header file for the _FastScrollPresenter class.
21  *
22  * This header file contains the declarations of the %_FastScrollPresenter class.
23  */
24
25 #ifndef _FUICTRL_INTERNAL_FASTSCROLL_PRESENTER_H_
26 #define _FUICTRL_INTERNAL_FASTSCROLL_PRESENTER_H_
27
28 #include "FBaseString.h"
29 #include "FGrpFloatMatrix4.h"
30
31 #include "FGrpBitmap.h"
32 #include "FGrpRectangle.h"
33 #include "FGrpColor.h"
34 #include "FGrpDimension.h"
35 #include "FGrp_TextTextObject.h"
36
37 #include "FUi_Control.h"
38 #include "FUiCtrl_IFastScrollListener.h"
39 #include "FUiCtrl_UiFastScrollEvent.h"
40
41 #include "FUiAnim_VisualElement.h"
42 #include "FUiAnimVisualElementAnimation.h"
43 #include "FUiAnimVisualElementAnimationProvider.h"
44 #include "FUiAnimIVisualElementAnimationStatusEventListener.h"
45 #include "FUiAnimVisualElementContentProvider.h"
46 #include "FUiAnimIVisualElementContentProvider.h"
47
48 #include "FUiCtrl_FastScroll.h"
49 #include "FUiCtrl_FastScrollIndex.h"
50 #include "FUiCtrl_FastScrollModel.h"
51
52
53 namespace Tizen { namespace Ui { namespace Controls
54 {
55
56 class _FastScrollViewConfig
57 {
58 public:
59         virtual ~_FastScrollViewConfig(void);
60         static _FastScrollViewConfig* CreateFastScrollViewConfigN(Tizen::Ui::_ControlOrientation orientation);
61
62         result ReloadConfig(Tizen::Ui::_ControlOrientation orientation);
63         void ReleaseResources(void);
64
65 private:
66         _FastScrollViewConfig(const _FastScrollViewConfig& rhs);
67         _FastScrollViewConfig& operator =(const _FastScrollViewConfig& rhs);
68
69         _FastScrollViewConfig(void);
70         result Construct(Tizen::Ui::_ControlOrientation orientation);
71
72 private:
73         friend class _FastScrollIndexView;
74         friend class _FastScrollPopupView;
75         friend class _FastScrollPresenter;
76
77         Tizen::Graphics::Color __indexBgColor;
78         Tizen::Graphics::Color __indexHighlightColor;
79         Tizen::Graphics::Color __indexLeftLineColor;
80         Tizen::Graphics::Color __indexTextColor;
81         Tizen::Graphics::Color __indexSeparatorColor;
82         Tizen::Graphics::Color __selectedIndexBgColor;
83         Tizen::Graphics::Color __selectedIndexTextColor;
84         Tizen::Graphics::Color __selectedIndexOutlineColor;
85         Tizen::Graphics::Color __popupBgColor;
86         Tizen::Graphics::Color __popupTextColor;
87
88         Tizen::Graphics::Dimension __indexSizeMin;
89         Tizen::Graphics::Dimension __popupSize;
90
91         int __indexMarginRight;
92         int __indexMarginTop;
93         int __indexGap;
94
95         int __indexLeftLineThickness;
96         int __indexTextSize;
97         int __indexSeparatorThickness;
98         int __selectedIndexMarginRight;
99         int __selectedIndexHeight;
100         int __popupWidthIncrement;
101         int __popupTextSize;
102         int __popupShadowRight;
103         int __popupShadowBottom;
104
105         Tizen::Graphics::Bitmap* __pIndexBgBitmap;
106         Tizen::Graphics::Bitmap* __pSelectedIndexBgBitmap;
107         Tizen::Graphics::Bitmap* __pSelectedIndexOutlineBitmap;
108         Tizen::Graphics::Bitmap* __pPopupBgBitmap;
109         Tizen::Graphics::Bitmap* __pPopupBgEffectBitmap;
110
111         Tizen::Graphics::Font* __pFont;
112 };
113
114
115 class _FastScrollIndexView
116         : public Tizen::Base::Object
117         , public Tizen::Ui::Animations::VisualElementAnimationProvider
118         , public Tizen::Ui::Animations::VisualElementContentProvider
119         , public Tizen::Ui::Animations::IVisualElementAnimationStatusEventListener
120         , virtual public Tizen::Ui::Animations::IVisualElementAnimationProvider
121         , virtual public _IUiEventListener
122 {
123 public:
124         virtual ~_FastScrollIndexView(void);
125
126         static _FastScrollIndexView* CreateFastScrollIndexViewN(Tizen::Ui::Animations::_VisualElement& parentVe, _FastScrollViewConfig& viewConfig);
127
128         result FadeOutAndDestroy(void);
129
130         result SetBaseIndex(_FastScrollIndex* pIndex);
131         _FastScrollIndex* GetBaseIndex(void) const;
132
133         result SetIndexBounds(const Tizen::Graphics::Rectangle& indexBounds);
134         Tizen::Graphics::Rectangle GetIndexBounds(void) const;
135         result SetSelectedBgBounds(const Tizen::Graphics::Rectangle& indexBounds);
136         Tizen::Graphics::Rectangle GetSelectedBgBounds(void) const;
137         result SetSelectedIndexBounds(const Tizen::Graphics::Rectangle& indexBounds);
138         Tizen::Graphics::Rectangle GetSelectedIndexBounds(void) const;
139
140         _FastScrollIndex* GetIndexAtPoint(const Tizen::Graphics::Point& point) const;
141         _FastScrollIndex* GetOmissionIndexAtPoint(_FastScrollIndex* pIndex, const Tizen::Graphics::Point& point) const;
142         int GetIndexHeight(void) const;
143         result SelectIndex(int indexOrder);
144         result SelectIndex(_FastScrollIndex* pIndex, bool animation);
145         int GetSelectedIndexOrder(void) const;
146         _FastScrollIndex* GetSelectedIndex(void) const;
147         void SetSelectedIndexInOmittedIndex(_FastScrollIndex* pIndex);
148         _FastScrollIndex* GetSelectedIndexInOmittedIndex(void) const;
149         _FastScrollIndex* GetFormerIndex(void) const;
150
151         bool IsOnAnimation(void) const;
152         void RemoveAllAnimations(void);
153
154         result SetIndexVisibility(bool visibility);
155         bool GetIndexVisibility(void) const;
156         result SetSelectedIndexVisibility(bool visibility, bool bAnimation);
157         bool GetSelectedIndexVisibility(void) const;
158         result AddAccessibilityElement(const Tizen::Ui::_AccessibilityContainer& control);
159
160         result UpdateIndex(bool bNeedUpdateBaseIndex);
161         Tizen::Graphics::Rectangle CalculateSelectedBg(void);
162
163         void OnDraw(void);
164         void DrawBaseIndex(void);
165         void DrawSelectedBg(void);
166         void DrawSelectedIndex(void);
167         result DrawBitmap(Tizen::Graphics::Canvas& canvas, const Tizen::Graphics::Rectangle& bounds, const Tizen::Graphics::Bitmap& bitmap);
168         result DrawBitmap(Tizen::Graphics::Canvas& canvas, const Tizen::Graphics::Rectangle& srcRect, const Tizen::Graphics::Bitmap& bitmap, const Tizen::Graphics::Rectangle& dstRect);
169
170         virtual Tizen::Ui::Animations::VisualElementAnimation* CreateAnimationForProperty(Tizen::Ui::Animations::VisualElement& target, const Tizen::Base::String& property);
171         virtual void OnVisualElementAnimationStarted(const Tizen::Ui::Animations::VisualElementAnimation& animation, const Tizen::Base::String& keyName, Tizen::Ui::Animations::VisualElement& target);
172         virtual void OnVisualElementAnimationRepeated(const Tizen::Ui::Animations::VisualElementAnimation& animation, const Tizen::Base::String& keyName, Tizen::Ui::Animations::VisualElement& target, long currentRepeatCount);
173         virtual void OnVisualElementAnimationFinished(const Tizen::Ui::Animations::VisualElementAnimation& animation, const Tizen::Base::String& keyName, Tizen::Ui::Animations::VisualElement& target, bool completedNormally);
174
175 private:
176         _FastScrollIndexView(const _FastScrollIndexView& rhs);
177         _FastScrollIndexView& operator =(const _FastScrollIndexView& rhs);
178
179         _FastScrollIndexView(Tizen::Ui::Animations::_VisualElement& parentVe, _FastScrollViewConfig& viewConfig);
180         result Construct(void);
181
182 private:
183         Tizen::Ui::Animations::_VisualElement& __parentVe;
184         _FastScrollViewConfig& __viewConfig;
185
186         _FastScrollIndex* __pBaseIndex;
187         _FastScrollIndex* __pSelectedIndex;
188         _FastScrollIndex* __pSelectedIndexInOmittedIndex;
189         _FastScrollIndex* __pFormerIndex;
190         Tizen::Ui::Animations::_VisualElement* __pBaseIndexVe;
191         Tizen::Ui::Animations::_VisualElement* __pSelectedBgVe;
192         Tizen::Ui::Animations::_VisualElement* __pSelectedIndexVe;
193
194         bool __needUpdateBaseIndex;
195         bool __needUpdateSelectedIndex;
196         bool __needDestroySelf;
197 };
198
199 class _FastScrollPopupView
200         : public Tizen::Ui::Animations::VisualElementAnimationProvider
201         , public Tizen::Ui::Animations::VisualElementContentProvider
202         , public Tizen::Ui::Animations::IVisualElementAnimationStatusEventListener
203         , virtual public Tizen::Ui::Animations::IVisualElementAnimationProvider
204         , virtual public _IUiEventListener
205 {
206 public:
207         virtual ~_FastScrollPopupView(void);
208
209         static _FastScrollPopupView* CreateFastScrollPopupViewN(Tizen::Ui::Animations::_VisualElement& parentVe, _FastScrollViewConfig& viewConfig);
210
211         result FadeOutAndDestroy(void);
212
213         result SelectIndex(int indexLevel, _FastScrollIndex* pIndex, _FastScrollIndex* pFormerIndex);
214         result AddPopupIndexVe(int indexLevel);
215         result RemovePopupIndexVe(int indexLevel);
216
217         result SetPopupBounds(const Tizen::Graphics::Rectangle& indexBounds);
218         Tizen::Graphics::Rectangle GetPopupBounds(void) const;
219         result SetPopupIndexBounds(int indexLevel, const _FastScrollIndex* pBaseIndex);
220         Tizen::Graphics::Rectangle GetPopupIndexBounds(int indexLevel) const;
221         Tizen::Ui::Animations::_VisualElement* GetIndexVe(int indexLevel) const;
222         int GetIndexVeCount(void) const;
223
224         bool IsOnAnimation(void) const;
225         void RemoveAllAnimations(void);
226
227         result SetPopupVisibility(bool visibility);
228         bool GetPopupVisibility(void) const;
229         void SetPopupVeUpdateNeeded(bool needUpdate);
230
231         result UpdateIndex(void);
232
233         void DrawPopupVe(void);
234         void DrawPopupIndexVe(int indexLevel, const _FastScrollIndex* pBaseIndex, const _FastScrollIndex* pSelectedIndex);
235
236         void OnDraw(int indexLevel, const _FastScrollIndex* pBaseIndex, const _FastScrollIndex* pSelectedIndex);
237         result DrawBitmap(Tizen::Graphics::Canvas& canvas, const Tizen::Graphics::Rectangle& bounds, const Tizen::Graphics::Bitmap& bitmap);
238         result DrawBitmap(Tizen::Graphics::Canvas& canvas, const Tizen::Graphics::Rectangle& srcRect, const Tizen::Graphics::Bitmap& bitmap, const Tizen::Graphics::Rectangle& dstRect);
239
240         virtual Tizen::Ui::Animations::VisualElementAnimation* CreateAnimationForProperty(Tizen::Ui::Animations::VisualElement& target, const Tizen::Base::String& property);
241         virtual void OnVisualElementAnimationStarted(const Tizen::Ui::Animations::VisualElementAnimation& animation, const Tizen::Base::String& keyName, Tizen::Ui::Animations::VisualElement& target);
242         virtual void OnVisualElementAnimationRepeated(const Tizen::Ui::Animations::VisualElementAnimation& animation, const Tizen::Base::String& keyName, Tizen::Ui::Animations::VisualElement& target, long currentRepeatCount);
243         virtual void OnVisualElementAnimationFinished(const Tizen::Ui::Animations::VisualElementAnimation& animation, const Tizen::Base::String& keyName, Tizen::Ui::Animations::VisualElement& target, bool completedNormally);
244
245 private:
246         _FastScrollPopupView(const _FastScrollPopupView& rhs);
247         _FastScrollPopupView& operator =(const _FastScrollPopupView& rhs);
248
249         _FastScrollPopupView(Tizen::Ui::Animations::_VisualElement& parentVe, _FastScrollViewConfig& viewConfig);
250         result Construct(void);
251
252 private:
253         Tizen::Ui::Animations::_VisualElement& __parentVe;
254         _FastScrollViewConfig& __viewConfig;
255
256         Tizen::Ui::Animations::_VisualElement* __pPopupVe;
257         Tizen::Base::Collection::ArrayList __indexViews;
258
259         Tizen::Graphics::FloatMatrix4 __matrixOrigin;
260         Tizen::Graphics::FloatMatrix4 __matrixFadeInStart;
261         Tizen::Graphics::FloatMatrix4 __matrixFadeOutEnd;
262
263         bool __needUpdatePopupVe;
264         bool __needUpdatePopupIndexVe;
265         bool __needDestroySelf;
266 };
267
268
269 class _FastScroll;
270
271 class _FastScrollPresenter
272         : public Tizen::Ui::Animations::VisualElementAnimationProvider
273         , public Tizen::Ui::Animations::VisualElementContentProvider
274         , public Tizen::Ui::Animations::IVisualElementAnimationStatusEventListener
275         , public _IFastScrollIndexObserver
276         , virtual public Tizen::Ui::Animations::IVisualElementAnimationProvider
277         , virtual public _IUiEventListener
278 {
279 public:
280         virtual ~_FastScrollPresenter(void);
281
282         static _FastScrollPresenter* CreateFastScrollPresenterN(Tizen::Ui::_Control& parentCtrl,
283                                                                 _FastScroll& fastScroll,
284                                                                 bool visibility = false);
285
286         result SetRootIndex(_FastScrollIndex* pIndex);
287         _FastScrollIndex* GetRootIndex(void) const;
288         result UpdateIndex(void);
289
290         void EnableFadeEffect(bool enable);
291         bool IsEnabledFadeEffect(void) const;
292         bool IsOnFadeEffect(void) const;
293         bool IsScrollVisible(void) const;
294         result SetScrollVisibility(bool visibility);
295         bool GetScrollVisibility(void) const;
296         void CancelFadeEffect(void);
297
298         void AddFastScrollEventListener(const Tizen::Ui::Controls::_IUiFastScrollListener& listener);
299         void RemoveFastScrollEventListener(const Tizen::Ui::Controls::_IUiFastScrollListener& listener);
300         result AddAccessibilityElement(const Tizen::Ui::_AccessibilityContainer& control, bool onAccessibility);
301
302         void OnParentBoundsChanged(void);
303
304         void OnDraw(void);
305         bool OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo);
306         bool OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo);
307         bool OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo);
308         bool OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo);
309         void OnFontChanged(Tizen::Graphics::Font* pFont);
310         void OnFontInfoRequested(unsigned long& style, int& size);
311         result SetFontInfo(unsigned long style, int size);
312         Tizen::Ui::Animations::HitTestResult HitTest(const Tizen::Graphics::FloatPoint& point);
313
314         virtual Tizen::Ui::Animations::VisualElementAnimation* CreateAnimationForProperty(Tizen::Ui::Animations::VisualElement& target, const Tizen::Base::String& property);
315         virtual void OnVisualElementAnimationStarted(const Tizen::Ui::Animations::VisualElementAnimation& animation, const Tizen::Base::String& keyName, Tizen::Ui::Animations::VisualElement& target);
316         virtual void OnVisualElementAnimationRepeated(const Tizen::Ui::Animations::VisualElementAnimation& animation, const Tizen::Base::String& keyName, Tizen::Ui::Animations::VisualElement& target, long currentRepeatCount);
317         virtual void OnVisualElementAnimationFinished(const Tizen::Ui::Animations::VisualElementAnimation& animation, const Tizen::Base::String& keyName, Tizen::Ui::Animations::VisualElement& target, bool completedNormally);
318
319         virtual void OnIndexDataUpdated(_FastScrollIndex& updatedIndex);
320         virtual void OnIndexDeleted(_FastScrollIndex& deletedIndex);
321         virtual void OnChildIndexAttached(_FastScrollIndex& parentIndex, int attachedOrder, _FastScrollIndex& attachedIndex);
322         virtual void OnChildIndexDetached(_FastScrollIndex& parentIndex, int detachedOrder, _FastScrollIndex& detachedIndex);
323
324 private:
325         _FastScrollPresenter(const _FastScrollPresenter& rhs);
326         _FastScrollPresenter& operator =(const _FastScrollPresenter& rhs);
327
328         _FastScrollPresenter(Tizen::Ui::_Control& parentCtrl, _FastScroll& fastScroll, bool visibility);
329         result Construct(void);
330
331         Tizen::Graphics::Rectangle CalculateFastScrollBounds(int indexCount);
332         Tizen::Graphics::Rectangle CalculateIndexBounds(int indexLevel, _FastScrollIndex& pIndex);
333         Tizen::Graphics::Rectangle CalculatePopupBounds(void);
334         void RelayoutFastScrollChildren(void);
335
336         _FastScrollIndex* SelectOnIndexViews(const Tizen::Graphics::Point& point, bool animation);
337         result DeselectIndexViews(void);
338
339         result SetPopupIndex(_FastScrollIndex& popupIndex, const Tizen::Graphics::Point& point);
340         result ClearPopupIndex(void);
341
342         result FireFastScrollEvent(_FastScrollIndex& selectedIndex);
343
344         bool OnTouchPressedAndMoved(const Tizen::Graphics::Point& point, bool animation);
345         bool OnTouchReleasedAndCanceled(void);
346
347         result AddIndexView(_FastScrollIndex& baseIndex);
348         result AddIndexView(int indexLevel, _FastScrollIndex& baseIndex);
349         result RemoveIndexView(int indexLevel, bool fadeout);
350         result RemoveAllIndexViews(bool fadeout);
351
352         _FastScrollIndexView* GetIndexView(int indexLevel) const;
353         int GetIndexViewCount(void) const;
354
355 private:
356         Tizen::Ui::_Control& __parentCtrl;
357         _FastScroll& __fastScroll;
358         Tizen::Ui::Animations::_VisualElement* __pCtrlVe;
359
360         _FastScrollViewConfig* __pViewConfig;
361
362         _UiFastScrollEvent* __pFastScrollEvent;
363         _FastScrollModel* __pFastScrollModel;
364         unsigned long __fontStyle;
365         int __fontSize;
366
367         _FastScrollPopupView* __pPopupView;
368         Tizen::Base::Collection::ArrayList __indexViews;
369
370         int __focusedIndexLevel;
371         _FastScrollIndex* __pSelectedIndex;
372
373         bool __enableFadeEffect;
374         int __indexCountMax;
375         bool __fadeIn;
376         bool __fadeOut;
377         bool __scrollVisibility;
378         int __fadeEffectDuration_ms;
379
380 };
381
382 } } }   // Tizen::Ui::Controls
383
384 #endif //_FUICTRL_INTERNAL_FASTSCROLL_PRESENTER_H_