use modern construct '= default' for special functions.
[platform/core/uifw/dali-core.git] / dali / internal / event / events / tap-gesture / tap-gesture-detector-impl.cpp
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/internal/event/events/tap-gesture/tap-gesture-detector-impl.h>
20
21 // EXTERNAL INCLUDES
22 #include <cstring> // for strcmp
23
24 // INTERNAL INCLUDES
25 #include <dali/public-api/events/tap-gesture.h>
26 #include <dali/public-api/object/type-registry.h>
27 #include <dali/integration-api/debug.h>
28 #include <dali/internal/event/events/gesture-event-processor.h>
29
30 namespace Dali
31 {
32
33 namespace Internal
34 {
35
36 namespace
37 {
38
39 const unsigned int DEFAULT_TAPS_REQUIRED = 1u;
40 const unsigned int DEFAULT_TOUCHES_REQUIRED = 1u;
41
42 // Signals
43 const char* const SIGNAL_TAP_DETECTED = "tapDetected";
44
45 BaseHandle Create()
46 {
47   return Dali::TapGestureDetector::New();
48 }
49
50 TypeRegistration mType( typeid(Dali::TapGestureDetector), typeid(Dali::GestureDetector), Create );
51
52 SignalConnectorType signalConnector1( mType, SIGNAL_TAP_DETECTED, &TapGestureDetector::DoConnectSignal );
53
54 }
55
56 TapGestureDetectorPtr TapGestureDetector::New()
57 {
58   return new TapGestureDetector;
59 }
60
61 TapGestureDetectorPtr TapGestureDetector::New( unsigned int tapsRequired )
62 {
63   return new TapGestureDetector( tapsRequired );
64 }
65
66 TapGestureDetector::TapGestureDetector()
67 : GestureDetector( GestureType::TAP ),
68   mMinimumTapsRequired( DEFAULT_TAPS_REQUIRED ),
69   mMaximumTapsRequired( DEFAULT_TAPS_REQUIRED ),
70   mTouchesRequired( DEFAULT_TOUCHES_REQUIRED )
71 {
72 }
73
74 TapGestureDetector::TapGestureDetector( unsigned int tapsRequired )
75 : GestureDetector( GestureType::TAP ),
76   mMinimumTapsRequired( tapsRequired ),
77   mMaximumTapsRequired( tapsRequired ),
78   mTouchesRequired( DEFAULT_TOUCHES_REQUIRED )
79 {
80 }
81
82 TapGestureDetector::~TapGestureDetector() = default;
83
84 void TapGestureDetector::SetMinimumTapsRequired(unsigned int taps)
85 {
86   if ( mMinimumTapsRequired != taps )
87   {
88     mMinimumTapsRequired = taps;
89
90     if ( !mAttachedActors.empty() )
91     {
92       mGestureEventProcessor.GestureDetectorUpdated(this);
93     }
94   }
95 }
96
97 void TapGestureDetector::SetMaximumTapsRequired(unsigned int taps)
98 {
99   if ( mMaximumTapsRequired != taps )
100   {
101     mMaximumTapsRequired = taps;
102
103     if ( !mAttachedActors.empty() )
104     {
105       mGestureEventProcessor.GestureDetectorUpdated(this);
106     }
107   }
108 }
109
110 void TapGestureDetector::SetTouchesRequired(unsigned int touches)
111 {
112   if (mTouchesRequired != touches)
113   {
114     mTouchesRequired = touches;
115
116     if (!mAttachedActors.empty())
117     {
118       mGestureEventProcessor.GestureDetectorUpdated(this);
119     }
120   }
121 }
122
123 unsigned int TapGestureDetector::GetMinimumTapsRequired() const
124 {
125   return mMinimumTapsRequired;
126 }
127
128 unsigned int TapGestureDetector::GetMaximumTapsRequired() const
129 {
130   return mMaximumTapsRequired;
131 }
132
133 unsigned int TapGestureDetector::GetTouchesRequired() const
134 {
135   return mTouchesRequired;
136 }
137
138 void TapGestureDetector::EmitTapGestureSignal(Dali::Actor tappedActor, const Dali::TapGesture& tap)
139 {
140   // Guard against destruction during signal emission
141   Dali::TapGestureDetector handle( this );
142
143   mDetectedSignal.Emit( tappedActor, tap );
144 }
145
146 bool TapGestureDetector::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
147 {
148   bool connected( true );
149   TapGestureDetector* gesture = static_cast< TapGestureDetector* >(object); // TypeRegistry guarantees that this is the correct type.
150
151   if ( 0 == strcmp( signalName.c_str(), SIGNAL_TAP_DETECTED ) )
152   {
153     gesture->DetectedSignal().Connect( tracker, functor );
154   }
155   else
156   {
157     // signalName does not match any signal
158     connected = false;
159   }
160
161   return connected;
162 }
163
164 void TapGestureDetector::OnActorAttach(Actor& actor)
165 {
166   // Do nothing
167 }
168
169 void TapGestureDetector::OnActorDetach(Actor& actor)
170 {
171   // Do nothing
172 }
173
174 void TapGestureDetector::OnActorDestroyed(Object& object)
175 {
176   // Do nothing
177 }
178
179 } // namespace Internal
180
181 } // namespace Dali