b049433e071c0ed6f6b6e4b2a4b6389dcaac1a34
[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) 2019 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 struct LongPressGesture;
29
30 namespace Internal
31 {
32
33 class LongPressGestureDetector;
34
35 typedef IntrusivePtr<LongPressGestureDetector> LongPressGestureDetectorPtr;
36 typedef DerivedGestureDetectorContainer<LongPressGestureDetector>::type LongPressGestureDetectorContainer;
37
38 /**
39  * @copydoc Dali::LongPressGestureDetector
40  */
41 class LongPressGestureDetector : public GestureDetector
42 {
43 public: // Creation
44
45   /**
46    * Create a new gesture detector.
47    * @return A smart-pointer to the newly allocated detector.
48    */
49   static LongPressGestureDetectorPtr New();
50
51   /**
52    * Create a new gesture detector with the specified touches.
53    * @param[in]  touchesRequired  The number of touches required.
54    * @return A smart-pointer to the newly allocated detector.
55    */
56   static LongPressGestureDetectorPtr New(unsigned int touchesRequired);
57
58   /**
59    * Create a new gesture detector with the specified minimum and maximum touches.
60    * @param[in]  minTouches  The minimum number of touches required.
61    * @param[in]  maxTouches  The maximum number of touches required.
62    * @return A smart-pointer to the newly allocated detector.
63    */
64   static LongPressGestureDetectorPtr New(unsigned int minTouches, unsigned int maxTouches);
65
66   /**
67    * Construct a new GestureDetector.
68    */
69   LongPressGestureDetector();
70
71   /**
72    * Create a new gesture detector with the specified minimum and maximum touches.
73    * @param[in]  minTouches  The minimum number of touches required.
74    * @param[in]  maxTouches  The maximum number of touches required.
75    */
76   LongPressGestureDetector(unsigned int minTouches, unsigned int maxTouches);
77
78 public:
79
80   /**
81    * @copydoc Dali::LongPressGestureDetector::SetTouchesRequired(unsigned int)
82    */
83   void SetTouchesRequired(unsigned int touches);
84
85   /**
86    * @copydoc Dali::LongPressGestureDetector::SetTouchesRequired(unsigned int, unsigned int)
87    */
88   void SetTouchesRequired(unsigned int minTouches, unsigned int maxTouches);
89
90   /**
91    * @copydoc Dali::LongPressGestureDetector::GetMinimumTouchesRequired()
92    */
93   unsigned int GetMinimumTouchesRequired() const;
94
95   /**
96    * @copydoc Dali::LongPressGestureDetector::GetMaximumTouchesRequired()
97    */
98   unsigned int GetMaximumTouchesRequired() const;
99
100 public:
101
102   /**
103    * Called by the LongPressGestureProcessor when a tap gesture event occurs within the bounds of our
104    * attached actor.
105    * @param[in]  pressedActor  The pressed actor.
106    * @param[in]  longPress     The long press
107    */
108   void EmitLongPressGestureSignal(Dali::Actor pressedActor, const LongPressGesture& longPress);
109
110 public: // Signals
111
112   /**
113    * @copydoc Dali::LongPressGestureDetector::DetectedSignal()
114    */
115   Dali::LongPressGestureDetector::DetectedSignalType& DetectedSignal()
116   {
117     return mDetectedSignal;
118   }
119
120   /**
121    * Connects a callback function with the object's signals.
122    * @param[in] object The object providing the signal.
123    * @param[in] tracker Used to disconnect the signal.
124    * @param[in] signalName The signal to connect to.
125    * @param[in] functor A newly allocated FunctorDelegate.
126    * @return True if the signal was connected.
127    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
128    */
129   static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
130
131 protected:
132
133   /**
134    * A reference counted object may only be deleted by calling Unreference()
135    */
136   virtual ~LongPressGestureDetector();
137
138 private:
139
140   // Undefined
141   LongPressGestureDetector(const LongPressGestureDetector&);
142   LongPressGestureDetector& operator=(const LongPressGestureDetector& rhs);
143
144 private: // GestureDetector overrides
145
146   /**
147    * @copydoc Dali::Internal::GestureDetector::OnActorAttach(Actor&)
148    */
149   virtual void OnActorAttach(Actor& actor);
150
151   /**
152    * @copydoc Dali::Internal::GestureDetector::OnActorDetach(Actor&)
153    */
154   virtual void OnActorDetach(Actor& actor);
155
156   /**
157    * @copydoc Dali::Internal::GestureDetector::OnActorDestroyed(Object&)
158    */
159   virtual void OnActorDestroyed(Object& object);
160
161 private:
162
163   Dali::LongPressGestureDetector::DetectedSignalType mDetectedSignal;
164
165   unsigned int mMinimumTouchesRequired;
166   unsigned int mMaximumTouchesRequired;
167 };
168
169 } // namespace Internal
170
171 // Helpers for public-api forwarding methods
172
173 inline Internal::LongPressGestureDetector& GetImplementation(Dali::LongPressGestureDetector& detector)
174 {
175   DALI_ASSERT_ALWAYS( detector && "LongPressGestureDetector handle is empty" );
176
177   BaseObject& handle = detector.GetBaseObject();
178
179   return static_cast<Internal::LongPressGestureDetector&>(handle);
180 }
181
182 inline const Internal::LongPressGestureDetector& GetImplementation(const Dali::LongPressGestureDetector& detector)
183 {
184   DALI_ASSERT_ALWAYS( detector && "LongPressGestureDetector handle is empty" );
185
186   const BaseObject& handle = detector.GetBaseObject();
187
188   return static_cast<const Internal::LongPressGestureDetector&>(handle);
189 }
190
191 } // namespace Dali
192
193 #endif // DALI_INTERNAL_LONG_PRESS_GESTURE_DETECTOR_IMPL_H