Use modern construct 'using' instead of typedef.
[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) 2020 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 using GestureDetectorPtr            = IntrusivePtr<GestureDetector>;
44 using GestureDetectorContainer      = std::vector<GestureDetector*>;
45 using GestureDetectorActorContainer = std::vector<Actor*>;
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   using type = std::vector<Detector*>;
54 };
55
56 /**
57  * @copydoc Dali::GestureDetector
58  */
59 class GestureDetector : public Object, public Object::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::GetAttachedActorCount() const
80    */
81   size_t GetAttachedActorCount() const;
82
83   /**
84    * @copydoc Dali::GestureDetector::GetAttachedActor() const
85    */
86   Dali::Actor GetAttachedActor(size_t index) const;
87
88   /**
89    * Returns a const reference to the container of attached actor pointers.
90    * @return A const reference to the attached internal actors.
91    */
92   const GestureDetectorActorContainer& GetAttachedActorPointers() const
93   {
94     return mAttachedActors;
95   }
96
97   /**
98    * Retrieves the type of GestureDetector
99    * @return The GestureDetector Type
100    */
101   GestureType::Value GetType() const
102   {
103     return mType;
104   }
105
106   /**
107    * Checks if the specified actor is still attached or pending attachment.
108    * @param[in]  actor  The actor to check.
109    * @return true, if the actor is attached or pending, false otherwise.
110    */
111   bool IsAttached(Actor& actor) const;
112
113 protected: // Creation & Destruction
114
115   /**
116    * Construct a new GestureDetector.
117    * @param type the type of gesture
118    * @param pointer to the scene object, nullptr if none
119    * by default GestureDetectors don't have our own scene object
120    */
121   GestureDetector( GestureType::Value type, const SceneGraph::PropertyOwner* sceneObject = nullptr );
122
123   /**
124    * A reference counted object may only be deleted by calling Unreference()
125    */
126   virtual ~GestureDetector();
127
128 private:
129
130   // Undefined
131   GestureDetector() = delete;
132   GestureDetector(const GestureDetector&) = delete;
133   GestureDetector& operator=(const GestureDetector& rhs) = delete;
134
135   /**
136    * @copydoc Dali::Internal::Object::Observer::SceneObjectAdded()
137    */
138   virtual void SceneObjectAdded(Object& object);
139
140   /**
141    * @copydoc Dali::Internal::Object::Observer::SceneObjectAdded()
142    */
143   virtual void SceneObjectRemoved(Object& object) {}
144
145   /**
146    * @copydoc Dali::Internal::Object::Observer::ObjectDestroyed()
147    */
148   virtual void ObjectDestroyed(Object& object);
149
150   /**
151    * For use in derived classes, called after an actor is attached.
152    * @param[in]  actor  The actor that is being attached.
153    */
154   virtual void OnActorAttach(Actor& actor) = 0;
155
156   /**
157    * For use in derived classes, called after an actor is detached.
158    * @param[in] actor The actor that is being detached.
159    */
160   virtual void OnActorDetach(Actor& actor) = 0;
161
162   /**
163    * For use in derived classes, called when an attached actor is destroyed.
164    * @param[in] object The object (Actor's base class) that has been destroyed.
165    * @note Derived classes should not call any Actor specific APIs in this method as the Actor's
166    *       destructor would have already been called.
167    */
168   virtual void OnActorDestroyed(Object& object) = 0;
169
170 protected:
171
172   GestureType::Value            mType;                  ///< The gesture detector will detect this type of gesture.
173   GestureDetectorActorContainer mAttachedActors;        ///< Object::Observer is used to provide weak-pointer behaviour
174   GestureDetectorActorContainer mPendingAttachActors;   ///< Object::Observer is used to provide weak-pointer behaviour
175   GestureEventProcessor&        mGestureEventProcessor; ///< A reference to the gesture event processor.
176 };
177
178 } // namespace Internal
179
180 // Helpers for public-api forwarding methods
181
182 inline Internal::GestureDetector& GetImplementation(Dali::GestureDetector& detector)
183 {
184   DALI_ASSERT_ALWAYS( detector && "GestureDetector handle is empty" );
185
186   BaseObject& handle = detector.GetBaseObject();
187
188   return static_cast<Internal::GestureDetector&>(handle);
189 }
190
191 inline const Internal::GestureDetector& GetImplementation(const Dali::GestureDetector& detector)
192 {
193   DALI_ASSERT_ALWAYS( detector && "GestureDetector handle is empty" );
194
195   const BaseObject& handle = detector.GetBaseObject();
196
197   return static_cast<const Internal::GestureDetector&>(handle);
198 }
199
200 } // namespace Dali
201
202 #endif // DALI_INTERNAL_GESTURE_DETECTOR_H