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