Revert "License conversion from Flora to Apache 2.0"
[platform/core/uifw/dali-core.git] / dali / internal / event / events / tap-gesture-detector-impl.cpp
1 //
2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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 // CLASS HEADER
18 #include <dali/internal/event/events/tap-gesture-detector-impl.h>
19
20 // INTERNAL INCLUDES
21 #include <dali/public-api/events/tap-gesture.h>
22 #include <dali/public-api/object/type-registry.h>
23 #include <dali/integration-api/debug.h>
24 #include <dali/internal/event/events/gesture-event-processor.h>
25
26 namespace Dali
27 {
28
29 namespace Internal
30 {
31
32 namespace
33 {
34 BaseHandle Create()
35 {
36   return Dali::TapGestureDetector::New();
37 }
38
39 TypeRegistration mType( typeid(Dali::TapGestureDetector), typeid(Dali::GestureDetector), Create );
40
41 SignalConnectorType signalConnector1( mType, Dali::TapGestureDetector::SIGNAL_TAP_DETECTED, &TapGestureDetector::DoConnectSignal );
42
43 }
44
45 TapGestureDetectorPtr TapGestureDetector::New()
46 {
47   return new TapGestureDetector;
48 }
49
50 TapGestureDetectorPtr TapGestureDetector::New(unsigned int tapsRequired, unsigned int touchesRequired)
51 {
52   return new TapGestureDetector(tapsRequired, touchesRequired);
53 }
54
55 TapGestureDetector::TapGestureDetector()
56 : GestureDetector(Gesture::Tap),
57   mTapsRequired(1),
58   mTouchesRequired(1)
59 {
60 }
61
62 TapGestureDetector::TapGestureDetector(unsigned int tapsRequired, unsigned int touchesRequired)
63 : GestureDetector(Gesture::Tap),
64   mTapsRequired(tapsRequired),
65   mTouchesRequired(touchesRequired)
66 {
67 }
68
69 TapGestureDetector::~TapGestureDetector()
70 {
71 }
72
73 void TapGestureDetector::SetTapsRequired(unsigned int taps)
74 {
75   DALI_ASSERT_ALWAYS(taps > 0 && "Can only set a positive number of taps" );
76
77   if (mTapsRequired != taps)
78   {
79     mTapsRequired = taps;
80
81     if (!mAttachedActors.empty())
82     {
83       mGestureEventProcessor.GestureDetectorUpdated(this);
84     }
85   }
86 }
87
88 void TapGestureDetector::SetTouchesRequired(unsigned int touches)
89 {
90   DALI_ASSERT_ALWAYS(touches > 0 && "Can only set a positive number of touches" );
91
92   if (mTouchesRequired != touches)
93   {
94     mTouchesRequired = touches;
95
96     if (!mAttachedActors.empty())
97     {
98       mGestureEventProcessor.GestureDetectorUpdated(this);
99     }
100   }
101 }
102
103 unsigned int TapGestureDetector::GetTapsRequired() const
104 {
105   return mTapsRequired;
106 }
107
108 unsigned int TapGestureDetector::GetTouchesRequired() const
109 {
110   return mTouchesRequired;
111 }
112
113 void TapGestureDetector::EmitTapGestureSignal(Dali::Actor tappedActor, const TapGesture& tap)
114 {
115   // Guard against destruction during signal emission
116   Dali::TapGestureDetector handle( this );
117
118   mDetectedSignalV2.Emit( tappedActor, tap );
119 }
120
121 bool TapGestureDetector::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
122 {
123   bool connected( true );
124   TapGestureDetector* gesture = dynamic_cast<TapGestureDetector*>(object);
125
126   if ( Dali::TapGestureDetector::SIGNAL_TAP_DETECTED  == signalName )
127   {
128     gesture->DetectedSignal().Connect( tracker, functor );
129   }
130   else
131   {
132     // signalName does not match any signal
133     connected = false;
134   }
135
136   return connected;
137 }
138
139 void TapGestureDetector::OnActorAttach(Actor& actor)
140 {
141   // Do nothing
142 }
143
144 void TapGestureDetector::OnActorDetach(Actor& actor)
145 {
146   // Do nothing
147 }
148
149 void TapGestureDetector::OnActorDestroyed(Object& object)
150 {
151   // Do nothing
152 }
153
154 } // namespace Internal
155
156 } // namespace Dali