Emscripten workarounds and llvm syntax fixes
[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   /**
163    * Dummy touch event handler.  We do not need to know when touch happens on our actor.  We just
164    * need to connect a function so that our attached actor is checked during our hit testing.
165    * @param[in]  actor  The hit actor (or one of its parents).
166    * @param[in]  event  The touch event.
167    * @return false always as we do not process the event.
168    */
169   bool OnTouchEvent(Dali::Actor actor, const TouchEvent& event);
170
171 private: // Default property extensions from ProxyObject
172
173   /**
174    * @copydoc Dali::Internal::ProxyObject::IsSceneObjectRemovable()
175    */
176   virtual bool IsSceneObjectRemovable() const;
177
178   /**
179    * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyCount()
180    */
181   virtual unsigned int GetDefaultPropertyCount() const;
182
183   /**
184    * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyIndices()
185    */
186   virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
187
188   /**
189    * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyName()
190    */
191   virtual const std::string& GetDefaultPropertyName(Property::Index index) const;
192
193   /**
194    * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyIndex()
195    */
196   virtual Property::Index GetDefaultPropertyIndex(const std::string& name) const;
197
198   /**
199    * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyWritable()
200    */
201   virtual bool IsDefaultPropertyWritable(Property::Index index) const;
202
203   /**
204    * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyAnimatable()
205    */
206   virtual bool IsDefaultPropertyAnimatable(Property::Index index) const;
207
208   /**
209    * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyType()
210    */
211   virtual Property::Type GetDefaultPropertyType(Property::Index index) const;
212
213   /**
214    * @copydoc Dali::Internal::ProxyObject::SetDefaultProperty()
215    */
216   virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
217
218   /**
219    * @copydoc Dali::Internal::ProxyObject::SetCustomProperty()
220    */
221   virtual void SetCustomProperty( Property::Index index, const CustomProperty& entry, const Property::Value& value );
222
223   /**
224    * @copydoc Dali::Internal::ProxyObject::GetDefaultProperty()
225    */
226   virtual Property::Value GetDefaultProperty( Property::Index index ) const;
227
228   /**
229    * @copydoc Dali::Internal::ProxyObject::InstallSceneObjectProperty()
230    */
231   virtual void InstallSceneObjectProperty( SceneGraph::PropertyBase& newProperty, const std::string& name, unsigned int index );
232
233   /**
234    * @copydoc Dali::Internal::ProxyObject::GetSceneObject()
235    */
236   virtual const SceneGraph::PropertyOwner* GetSceneObject() const;
237
238   /**
239    * @copydoc Dali::Internal::ProxyObject::GetSceneObjectAnimatableProperty()
240    */
241   virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const;
242
243   /**
244    * @copydoc Dali::Internal::ProxyObject::GetSceneObjectInputProperty()
245    */
246   virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const;
247
248 protected:
249
250   Gesture::Type                 mType;                  ///< The gesture detector will detect this type of gesture.
251   GestureDetectorActorContainer mAttachedActors;        ///< Proxy<Node>::Observer is used to provide weak-pointer behaviour
252   GestureEventProcessor&        mGestureEventProcessor; ///< A reference to the gesture event processor.
253
254 private:
255
256   SlotDelegate< GestureDetector > mSlotDelegate;
257 };
258
259 } // namespace Internal
260
261 // Helpers for public-api forwarding methods
262
263 inline Internal::GestureDetector& GetImplementation(Dali::GestureDetector& detector)
264 {
265   DALI_ASSERT_ALWAYS( detector && "GestureDetector handle is empty" );
266
267   BaseObject& handle = detector.GetBaseObject();
268
269   return static_cast<Internal::GestureDetector&>(handle);
270 }
271
272 inline const Internal::GestureDetector& GetImplementation(const Dali::GestureDetector& detector)
273 {
274   DALI_ASSERT_ALWAYS( detector && "GestureDetector handle is empty" );
275
276   const BaseObject& handle = detector.GetBaseObject();
277
278   return static_cast<const Internal::GestureDetector&>(handle);
279 }
280
281 } // namespace Dali
282
283 #endif // __DALI_INTERNAL_GESTURE_DETECTOR_H__