3a57574eca795c6f0bcfd5d86206a0569ddd5820
[platform/core/uifw/dali-core.git] / dali / internal / event / events / long-press-gesture / long-press-gesture-detector-impl.h
1 #ifndef DALI_INTERNAL_LONG_PRESS_GESTURE_DETECTOR_IMPL_H
2 #define DALI_INTERNAL_LONG_PRESS_GESTURE_DETECTOR_IMPL_H
3
4 /*
5  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/events/long-press-gesture-detector.h>
23 #include <dali/internal/event/events/gesture-detector-impl.h>
24
25 namespace Dali
26 {
27
28 namespace Internal
29 {
30
31 class LongPressGestureDetector;
32
33 typedef IntrusivePtr<LongPressGestureDetector> LongPressGestureDetectorPtr;
34 typedef DerivedGestureDetectorContainer<LongPressGestureDetector>::type LongPressGestureDetectorContainer;
35
36 /**
37  * @copydoc Dali::LongPressGestureDetector
38  */
39 class LongPressGestureDetector : public GestureDetector
40 {
41 public: // Creation
42
43   /**
44    * Create a new gesture detector.
45    * @return A smart-pointer to the newly allocated detector.
46    */
47   static LongPressGestureDetectorPtr New();
48
49   /**
50    * Create a new gesture detector with the specified touches.
51    * @param[in]  touchesRequired  The number of touches required.
52    * @return A smart-pointer to the newly allocated detector.
53    */
54   static LongPressGestureDetectorPtr New(unsigned int touchesRequired);
55
56   /**
57    * Create a new gesture detector with the specified minimum and maximum touches.
58    * @param[in]  minTouches  The minimum number of touches required.
59    * @param[in]  maxTouches  The maximum number of touches required.
60    * @return A smart-pointer to the newly allocated detector.
61    */
62   static LongPressGestureDetectorPtr New(unsigned int minTouches, unsigned int maxTouches);
63
64   /**
65    * Construct a new GestureDetector.
66    */
67   LongPressGestureDetector();
68
69   /**
70    * Create a new gesture detector with the specified minimum and maximum touches.
71    * @param[in]  minTouches  The minimum number of touches required.
72    * @param[in]  maxTouches  The maximum number of touches required.
73    */
74   LongPressGestureDetector(unsigned int minTouches, unsigned int maxTouches);
75
76 public:
77
78   /**
79    * @copydoc Dali::LongPressGestureDetector::SetTouchesRequired(unsigned int)
80    */
81   void SetTouchesRequired(unsigned int touches);
82
83   /**
84    * @copydoc Dali::LongPressGestureDetector::SetTouchesRequired(unsigned int, unsigned int)
85    */
86   void SetTouchesRequired(unsigned int minTouches, unsigned int maxTouches);
87
88   /**
89    * @copydoc Dali::LongPressGestureDetector::GetMinimumTouchesRequired()
90    */
91   unsigned int GetMinimumTouchesRequired() const;
92
93   /**
94    * @copydoc Dali::LongPressGestureDetector::GetMaximumTouchesRequired()
95    */
96   unsigned int GetMaximumTouchesRequired() const;
97
98   /**
99    * @return The minimum holding time required to be recognized as a long press gesture in milliseconds
100    */
101   uint32_t GetMinimumHoldingTime() const;
102
103 public:
104
105   /**
106    * Called by the LongPressGestureProcessor when a tap gesture event occurs within the bounds of our
107    * attached actor.
108    * @param[in]  pressedActor  The pressed actor.
109    * @param[in]  longPress     The long press
110    */
111   void EmitLongPressGestureSignal(Dali::Actor pressedActor, const Dali::LongPressGesture& longPress);
112
113 public: // Signals
114
115   /**
116    * @copydoc Dali::LongPressGestureDetector::DetectedSignal()
117    */
118   Dali::LongPressGestureDetector::DetectedSignalType& DetectedSignal()
119   {
120     return mDetectedSignal;
121   }
122
123   /**
124    * Connects a callback function with the object's signals.
125    * @param[in] object The object providing the signal.
126    * @param[in] tracker Used to disconnect the signal.
127    * @param[in] signalName The signal to connect to.
128    * @param[in] functor A newly allocated FunctorDelegate.
129    * @return True if the signal was connected.
130    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
131    */
132   static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
133
134 protected:
135
136   /**
137    * A reference counted object may only be deleted by calling Unreference()
138    */
139   virtual ~LongPressGestureDetector();
140
141 private:
142
143   // Undefined
144   LongPressGestureDetector(const LongPressGestureDetector&);
145   LongPressGestureDetector& operator=(const LongPressGestureDetector& rhs);
146
147 private: // GestureDetector overrides
148
149   /**
150    * @copydoc Dali::Internal::GestureDetector::OnActorAttach(Actor&)
151    */
152   virtual void OnActorAttach(Actor& actor);
153
154   /**
155    * @copydoc Dali::Internal::GestureDetector::OnActorDetach(Actor&)
156    */
157   virtual void OnActorDetach(Actor& actor);
158
159   /**
160    * @copydoc Dali::Internal::GestureDetector::OnActorDestroyed(Object&)
161    */
162   virtual void OnActorDestroyed(Object& object);
163
164 private:
165
166   Dali::LongPressGestureDetector::DetectedSignalType mDetectedSignal;
167
168   unsigned int mMinimumTouchesRequired;
169   unsigned int mMaximumTouchesRequired;
170 };
171
172 } // namespace Internal
173
174 // Helpers for public-api forwarding methods
175
176 inline Internal::LongPressGestureDetector& GetImplementation(Dali::LongPressGestureDetector& detector)
177 {
178   DALI_ASSERT_ALWAYS( detector && "LongPressGestureDetector handle is empty" );
179
180   BaseObject& handle = detector.GetBaseObject();
181
182   return static_cast<Internal::LongPressGestureDetector&>(handle);
183 }
184
185 inline const Internal::LongPressGestureDetector& GetImplementation(const Dali::LongPressGestureDetector& detector)
186 {
187   DALI_ASSERT_ALWAYS( detector && "LongPressGestureDetector handle is empty" );
188
189   const BaseObject& handle = detector.GetBaseObject();
190
191   return static_cast<const Internal::LongPressGestureDetector&>(handle);
192 }
193
194 } // namespace Dali
195
196 #endif // DALI_INTERNAL_LONG_PRESS_GESTURE_DETECTOR_IMPL_H