License conversion from Flora to Apache 2.0
[platform/core/uifw/dali-core.git] / dali / internal / event / events / gesture-detector-impl.h
1 #ifndef __DALI_INTERNAL_GESTURE_DETECTOR_H__
2 #define __DALI_INTERNAL_GESTURE_DETECTOR_H__
3
4 /*
5  * Copyright (c) 2014 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/common/vector-wrapper.h>
23 #include <dali/public-api/common/dali-common.h>
24 #include <dali/public-api/events/gesture.h>
25 #include <dali/public-api/signals/slot-delegate.h>
26 #include <dali/public-api/events/gesture-detector.h>
27 #include <dali/internal/event/actors/actor-impl.h>
28
29 namespace Dali
30 {
31
32 namespace Integration
33 {
34 struct GestureEvent;
35 }
36
37 namespace Internal
38 {
39
40 class GestureDetector;
41 class GestureEventProcessor;
42
43 typedef IntrusivePtr<GestureDetector> GestureDetectorPtr;
44 typedef std::vector<GestureDetector*> GestureDetectorContainer;
45 typedef std::vector<Actor*> GestureDetectorActorContainer;
46
47 /**
48  * This is a type trait that should be used by deriving gesture detectors for their container type.
49  */
50 template< typename Detector >
51 struct DerivedGestureDetectorContainer
52 {
53   typedef std::vector<Detector*> type;
54 };
55
56 /**
57  * @copydoc Dali::GestureDetector
58  */
59 class GestureDetector : public ProxyObject, public ProxyObject::Observer
60 {
61 public:
62
63   /**
64    * @copydoc Dali::GestureDetector::Attach()
65    */
66   void Attach(Actor& actor);
67
68   /**
69    * @copydoc Dali::GestureDetector::Detach()
70    */
71   void Detach(Actor& actor);
72
73   /**
74    * @copydoc Dali::GestureDetector::DetachAll()
75    */
76   void DetachAll();
77
78   /**
79    * @copydoc Dali::GestureDetector::GetAttachedActors() const
80    */
81   std::vector<Dali::Actor> GetAttachedActors() const;
82
83   /**
84    * Returns a const reference to the container of attached actor pointers.
85    * @return A const reference to the attached internal actors.
86    */
87   const GestureDetectorActorContainer& GetAttachedActorPointers() const
88   {
89     return mAttachedActors;
90   }
91
92   /**
93    * Retrieves the type of GestureDetector
94    * @return The GestureDetector Type
95    */
96   Gesture::Type GetType() const
97   {
98     return mType;
99   }
100
101   /**
102    * Checks if the specified actor is still attached.
103    * @param[in]  actor  The actor to check.
104    * @return true, if the actor is attached, false otherwise.
105    */
106   bool IsAttached(Actor& actor) const;
107
108 protected: // Creation & Destruction
109
110   /**
111    * Construct a new GestureDetector.
112    */
113   GestureDetector(Gesture::Type mType);
114
115   /**
116    * A reference counted object may only be deleted by calling Unreference()
117    */
118   virtual ~GestureDetector();
119
120 private:
121
122   // Undefined
123   GestureDetector(const GestureDetector&);
124
125   // Undefined
126   GestureDetector& operator=(const GestureDetector& rhs);
127
128   /**
129    * @copydoc Dali::Internal::ProxyObject::Observer::SceneObjectAdded()
130    */
131   virtual void SceneObjectAdded(ProxyObject& proxy) {}
132
133   /**
134    * @copydoc Dali::Internal::ProxyObject::Observer::SceneObjectAdded()
135    */
136   virtual void SceneObjectRemoved(ProxyObject& proxy) {}
137
138   /**
139    * @copydoc Dali::Internal::ProxyObject::Observer::ProxyDestroyed()
140    */
141   virtual void ProxyDestroyed(ProxyObject& proxy);
142
143   /**
144    * For use in derived classes, called after an actor is attached.
145    * @param[in]  actor  The actor that is being attached.
146    */
147   virtual void OnActorAttach(Actor& actor) = 0;
148
149   /**
150    * For use in derived classes, called after an actor is detached.
151    * @param[in] actor The actor that is being detached.
152    */
153   virtual void OnActorDetach(Actor& actor) = 0;
154
155   /**
156    * For use in derived classes, called when an attached actor is destroyed.
157    * @param[in] object The object (Actor's base class) that has been destroyed.
158    * @note Derived classes should not call any Actor specific APIs in this method as the Actor's
159    *       destructor would have already been called.
160    */
161   virtual void OnActorDestroyed(Object& object) = 0;
162
163   /**
164    * Dummy touch event handler.  We do not need to know when touch happens on our actor.  We just
165    * need to connect a function so that our attached actor is checked during our hit testing.
166    * @param[in]  actor  The hit actor (or one of its parents).
167    * @param[in]  event  The touch event.
168    * @return false always as we do not process the event.
169    */
170   bool OnTouchEvent(Dali::Actor actor, const TouchEvent& event);
171
172 private: // Default property extensions from ProxyObject
173
174   /**
175    * @copydoc Dali::Internal::ProxyObject::IsSceneObjectRemovable()
176    */
177   virtual bool IsSceneObjectRemovable() const;
178
179   /**
180    * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyCount()
181    */
182   virtual unsigned int GetDefaultPropertyCount() const;
183
184   /**
185    * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyIndices()
186    */
187   virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
188
189   /**
190    * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyName()
191    */
192   virtual const std::string& GetDefaultPropertyName(Property::Index index) const;
193
194   /**
195    * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyIndex()
196    */
197   virtual Property::Index GetDefaultPropertyIndex(const std::string& name) const;
198
199   /**
200    * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyWritable()
201    */
202   virtual bool IsDefaultPropertyWritable(Property::Index index) const;
203
204   /**
205    * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyAnimatable()
206    */
207   virtual bool IsDefaultPropertyAnimatable(Property::Index index) const;
208
209   /**
210    * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyAConstraintInput()
211    */
212   virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
213
214   /**
215    * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyType()
216    */
217   virtual Property::Type GetDefaultPropertyType(Property::Index index) const;
218
219   /**
220    * @copydoc Dali::Internal::ProxyObject::SetDefaultProperty()
221    */
222   virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
223
224   /**
225    * @copydoc Dali::Internal::ProxyObject::SetCustomProperty()
226    */
227   virtual void SetCustomProperty( Property::Index index, const CustomProperty& entry, const Property::Value& value );
228
229   /**
230    * @copydoc Dali::Internal::ProxyObject::GetDefaultProperty()
231    */
232   virtual Property::Value GetDefaultProperty( Property::Index index ) const;
233
234   /**
235    * @copydoc Dali::Internal::ProxyObject::InstallSceneObjectProperty()
236    */
237   virtual void InstallSceneObjectProperty( SceneGraph::PropertyBase& newProperty, const std::string& name, unsigned int index );
238
239   /**
240    * @copydoc Dali::Internal::ProxyObject::GetSceneObject()
241    */
242   virtual const SceneGraph::PropertyOwner* GetSceneObject() const;
243
244   /**
245    * @copydoc Dali::Internal::ProxyObject::GetSceneObjectAnimatableProperty()
246    */
247   virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const;
248
249   /**
250    * @copydoc Dali::Internal::ProxyObject::GetSceneObjectInputProperty()
251    */
252   virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const;
253
254 protected:
255
256   Gesture::Type                 mType;                  ///< The gesture detector will detect this type of gesture.
257   GestureDetectorActorContainer mAttachedActors;        ///< Proxy<Node>::Observer is used to provide weak-pointer behaviour
258   GestureEventProcessor&        mGestureEventProcessor; ///< A reference to the gesture event processor.
259
260 private:
261
262   SlotDelegate< GestureDetector > mSlotDelegate;
263 };
264
265 } // namespace Internal
266
267 // Helpers for public-api forwarding methods
268
269 inline Internal::GestureDetector& GetImplementation(Dali::GestureDetector& detector)
270 {
271   DALI_ASSERT_ALWAYS( detector && "GestureDetector handle is empty" );
272
273   BaseObject& handle = detector.GetBaseObject();
274
275   return static_cast<Internal::GestureDetector&>(handle);
276 }
277
278 inline const Internal::GestureDetector& GetImplementation(const Dali::GestureDetector& detector)
279 {
280   DALI_ASSERT_ALWAYS( detector && "GestureDetector handle is empty" );
281
282   const BaseObject& handle = detector.GetBaseObject();
283
284   return static_cast<const Internal::GestureDetector&>(handle);
285 }
286
287 } // namespace Dali
288
289 #endif // __DALI_INTERNAL_GESTURE_DETECTOR_H__