6d2e6596d19abf21a23594c5f7fef95a11ca0cd5
[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 private: // Default property extensions from ProxyObject
164
165   /**
166    * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyCount()
167    */
168   virtual unsigned int GetDefaultPropertyCount() const;
169
170   /**
171    * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyIndices()
172    */
173   virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
174
175   /**
176    * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyName()
177    */
178   virtual const char* GetDefaultPropertyName(Property::Index index) const;
179
180   /**
181    * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyIndex()
182    */
183   virtual Property::Index GetDefaultPropertyIndex(const std::string& name) const;
184
185   /**
186    * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyWritable()
187    */
188   virtual bool IsDefaultPropertyWritable(Property::Index index) const;
189
190   /**
191    * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyAnimatable()
192    */
193   virtual bool IsDefaultPropertyAnimatable(Property::Index index) const;
194
195   /**
196    * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyAConstraintInput()
197    */
198   virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
199
200   /**
201    * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyType()
202    */
203   virtual Property::Type GetDefaultPropertyType(Property::Index index) const;
204
205   /**
206    * @copydoc Dali::Internal::ProxyObject::SetDefaultProperty()
207    */
208   virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
209
210   /**
211    * @copydoc Dali::Internal::ProxyObject::SetCustomProperty()
212    */
213   virtual void SetCustomProperty( Property::Index index, const CustomProperty& entry, const Property::Value& value );
214
215   /**
216    * @copydoc Dali::Internal::ProxyObject::GetDefaultProperty()
217    */
218   virtual Property::Value GetDefaultProperty( Property::Index index ) const;
219
220   /**
221    * @copydoc Dali::Internal::ProxyObject::InstallSceneObjectProperty()
222    */
223   virtual void InstallSceneObjectProperty( SceneGraph::PropertyBase& newProperty, const std::string& name, unsigned int index );
224
225   /**
226    * @copydoc Dali::Internal::ProxyObject::GetSceneObject()
227    */
228   virtual const SceneGraph::PropertyOwner* GetSceneObject() const;
229
230   /**
231    * @copydoc Dali::Internal::ProxyObject::GetSceneObjectAnimatableProperty()
232    */
233   virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const;
234
235   /**
236    * @copydoc Dali::Internal::ProxyObject::GetSceneObjectInputProperty()
237    */
238   virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const;
239
240 protected:
241
242   Gesture::Type                 mType;                  ///< The gesture detector will detect this type of gesture.
243   GestureDetectorActorContainer mAttachedActors;        ///< Proxy<Node>::Observer is used to provide weak-pointer behaviour
244   GestureEventProcessor&        mGestureEventProcessor; ///< A reference to the gesture event processor.
245 };
246
247 } // namespace Internal
248
249 // Helpers for public-api forwarding methods
250
251 inline Internal::GestureDetector& GetImplementation(Dali::GestureDetector& detector)
252 {
253   DALI_ASSERT_ALWAYS( detector && "GestureDetector handle is empty" );
254
255   BaseObject& handle = detector.GetBaseObject();
256
257   return static_cast<Internal::GestureDetector&>(handle);
258 }
259
260 inline const Internal::GestureDetector& GetImplementation(const Dali::GestureDetector& detector)
261 {
262   DALI_ASSERT_ALWAYS( detector && "GestureDetector handle is empty" );
263
264   const BaseObject& handle = detector.GetBaseObject();
265
266   return static_cast<const Internal::GestureDetector&>(handle);
267 }
268
269 } // namespace Dali
270
271 #endif // __DALI_INTERNAL_GESTURE_DETECTOR_H__