Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / inc / FUi_TouchGestureDetector.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  * @file        FUi_TouchGestureDetector.h
19  * @brief       This is the header file for the %_TouchGestureDetector class.
20  *
21  * This header file contains the declarations of the %_TouchGestureDetector class.
22  */
23 #ifndef _FUI_INTERNAL_TOUCH_GESTURE_DETECTOR_H_
24 #define _FUI_INTERNAL_TOUCH_GESTURE_DETECTOR_H_
25
26 #include <math.h>
27 #include <FBaseColIList.h>
28 #include <FBaseObject.h>
29 #include <FBaseSysLog.h>
30 #include "FUi_Types.h"
31 #include "FUi_UiTouchEvent.h"
32 #include "FUi_ITouchEventListener.h"
33 #include "FUi_ITouchGestureEventListener.h"
34 #include "FUi_ITouchGestureDelegate.h"
35 #include "FUi_ITouchGestureStateChangedListener.h"
36
37 namespace Tizen { namespace Ui
38 {
39 class _Control;
40
41 template <class T>
42 T Distance(T x1, T y1, T x2, T y2)
43 {
44         return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
45 }
46
47 enum _TouchGestureDetectorState
48 {
49         _TOUCH_GESTURE_DETECTOR_STATE_READY,
50         _TOUCH_GESTURE_DETECTOR_STATE_STARTED,
51         _TOUCH_GESTURE_DETECTOR_STATE_CHANGED,
52         _TOUCH_GESTURE_DETECTOR_STATE_FINISHED,
53         _TOUCH_GESTURE_DETECTOR_STATE_FAILED,
54         _TOUCH_GESTURE_DETECTOR_STATE_CANCELED,
55         _TOUCH_GESTURE_DETECTOR_STATE_SUCCESS_AND_WAIT,
56         _TOUCH_GESTURE_DETECTOR_STATE_SUCCESS = _TOUCH_GESTURE_DETECTOR_STATE_FINISHED
57 };
58
59 enum _TouchGestureDetectorType
60 {
61         _TOUCH_GESTURE_DETECTOR_TYPE_CUSTOM,
62         _TOUCH_GESTURE_DETECTOR_TYPE_TAP,
63         _TOUCH_GESTURE_DETECTOR_TYPE_LONG_PRESS,
64         _TOUCH_GESTURE_DETECTOR_TYPE_PINCH,
65         _TOUCH_GESTURE_DETECTOR_TYPE_FLICK,
66         _TOUCH_GESTURE_DETECTOR_TYPE_ROTATION,
67         _TOUCH_GESTURE_DETECTOR_TYPE_PANNING
68 };
69
70 enum _TouchGestureDetectorEventType
71 {
72         _TOUCH_GESTURE_DETECTOR_EVENT_TYPE_DISCRETE,
73         _TOUCH_GESTURE_DETECTOR_EVENT_TYPE_CONTINUOUS
74 };
75
76 class _OSP_EXPORT_ _TouchGestureDetector
77         : public Tizen::Base::Object
78         , virtual public _ITouchGestureStateChangedListener
79         , virtual public _ITouchGestureDelegate
80 {
81 public:
82         _TouchGestureDetector(void);
83         virtual ~_TouchGestureDetector(void);
84
85         void SetDetectorState(_TouchGestureDetectorState state);
86         _TouchGestureDetectorState GetDetectorState(void) const;
87
88         void SetDelayTouchEventEnabled(bool enable);
89         bool IsDelayTouchEventEnabled(void) const;
90
91         void SetCancelTouchEventOnSuccessEnabled(bool enable);
92         bool IsCancelTouchEventOnSuccessEnabled(void) const;
93
94         result AddGestureListener(const Tizen::Ui::_ITouchGestureEventListener& listener);
95         result RemoveGestureListener(const Tizen::Ui::_ITouchGestureEventListener& listener);
96         Tizen::Base::Collection::IListT <Tizen::Ui::_ITouchGestureEventListener*>* GetGestureListenerList(void) const;
97
98         result StartOnFailureOf(const _TouchGestureDetector& gesture);
99
100         void SetDetectorType(_TouchGestureDetectorType type);
101         _TouchGestureDetectorType GetDetectorType(void) const;
102
103         result SetControl(const Tizen::Ui::_Control& control);
104         _Control* GetControl(void) const;
105
106         void SetUserData(void* pUserData);
107         void* GetUserData(void) const;
108
109         void SetDelegate(const _ITouchGestureDelegate& delegator);
110         _ITouchGestureDelegate* GetDelegate(void) const;
111
112         bool IsSentDelayedEvent(void) const;
113         void SetSentDelayedEvent(bool sent);
114         bool IsSendingDelayedEvent(void) const;
115
116         void AddTouchInfo(const _TouchInfo& touchInfo);
117         void ClearTouchInfo(void);
118
119         void SetGestureStart(bool start);
120         bool IsGestureStarted(void) const;
121
122         virtual bool OnTouchPressed(const Tizen::Ui::_Control& source, const Tizen::Ui::_TouchInfo& touchinfo);
123         virtual bool OnTouchMoved(const Tizen::Ui:: _Control& source, const Tizen::Ui::_TouchInfo& touchinfo);
124         virtual bool OnTouchReleased(const Tizen::Ui::_Control& source, const Tizen::Ui::_TouchInfo& touchinfo);
125         virtual bool OnTouchCanceled(const Tizen::Ui::_Control& source, const Tizen::Ui::_TouchInfo& touchinfo);
126
127         virtual void OnGestureDetectorStateChanged(const _TouchGestureDetector& gestureDetector);
128
129         void ProcessPublicListener(_TouchGestureDetector& gesture);
130         void ProcessCoreListener(_TouchGestureDetector& gesture);
131
132         Tizen::Base::String GetDescription(void);
133
134 private:
135         Tizen::Base::Collection::IListT <_TouchGestureDetector*>* GetWantToFailList(void) const;
136         Tizen::Base::Collection::IListT <_TouchGestureDetector*>* GetCurrentWantToFailList(void) const;
137         bool ExistWaitingList(void) const;
138         void NotifyStateChanged(void);
139         Tizen::Base::Collection::IListT<_TouchInfo*>* GetTouchInfoList(void);
140         bool IsPossibleToAddFailList(const _TouchGestureDetector& gesture);
141         void SetToDefaultState(void);
142         _TouchGestureDetectorEventType GetGestureDetectorEventType(void);
143          void SendDelayedTouchEvent(_Control* pControl);
144          void ProcessGestureCondition(void);
145
146         _TouchGestureDetector(const _TouchGestureDetector&);
147         _TouchGestureDetector& operator =(const _TouchGestureDetector&);
148
149 private:
150         bool __isTouchEventDelayed;
151         bool __isTouchCanceledOnSuccess;
152         bool __isDetectionStarted;
153         _TouchGestureDetectorState __currentState;
154         _TouchGestureDetectorType __type;
155         _ControlHandle __gestureContol;
156         void* __pUserData;
157         _ITouchGestureDelegate* __pDelegator;
158         Tizen::Base::Collection::IListT <_TouchGestureDetector*>* __pWantToFailList;
159         Tizen::Base::Collection::IListT <_TouchGestureDetector*>* __pCurrentWantToFailList;
160         Tizen::Base::Collection::IListT <Tizen::Ui::_ITouchGestureEventListener*>* __pEventListenerList;
161 }; // _TouchGestureDetector
162
163 } } //Tizen::Ui
164
165 #endif //_FUI_INTERNAL_TOUCH_GESTURE_DETECTOR_H_