DALi signals refactor to remove V2 naming
[platform/core/uifw/dali-core.git] / dali / internal / event / events / long-press-gesture-detector-impl.cpp
1 /*
2  * Copyright (c) 2014 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 "long-press-gesture-detector-impl.h"
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/events/long-press-gesture.h>
23 #include <dali/public-api/object/type-registry.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::LongPressGestureDetector::New();
37 }
38
39 TypeRegistration mType( typeid(Dali::LongPressGestureDetector), typeid(Dali::GestureDetector), Create );
40
41 SignalConnectorType signalConnector1( mType, Dali::LongPressGestureDetector::SIGNAL_LONG_PRESS_DETECTED, &LongPressGestureDetector::DoConnectSignal );
42
43 }
44
45
46 namespace
47 {
48 const unsigned int DEFAULT_TOUCHES_REQUIRED = 1;
49 } // unnamed namespace
50
51 LongPressGestureDetectorPtr LongPressGestureDetector::New()
52 {
53   return new LongPressGestureDetector;
54 }
55
56 LongPressGestureDetectorPtr LongPressGestureDetector::New(unsigned int touchesRequired)
57 {
58   return new LongPressGestureDetector(touchesRequired, touchesRequired);
59 }
60
61 LongPressGestureDetectorPtr LongPressGestureDetector::New(unsigned int minTouches, unsigned int maxTouches)
62 {
63   return new LongPressGestureDetector(minTouches, maxTouches);
64 }
65
66 LongPressGestureDetector::LongPressGestureDetector()
67 : GestureDetector(Gesture::LongPress),
68   mMinimumTouchesRequired(DEFAULT_TOUCHES_REQUIRED),
69   mMaximumTouchesRequired(DEFAULT_TOUCHES_REQUIRED)
70 {
71 }
72
73 LongPressGestureDetector::LongPressGestureDetector(unsigned int minTouches, unsigned int maxTouches)
74 : GestureDetector(Gesture::LongPress),
75   mMinimumTouchesRequired(minTouches),
76   mMaximumTouchesRequired(maxTouches)
77 {
78 }
79
80 LongPressGestureDetector::~LongPressGestureDetector()
81 {
82 }
83
84 void LongPressGestureDetector::SetTouchesRequired(unsigned int touches)
85 {
86   DALI_ASSERT_ALWAYS( touches > 0 && "Can only set a positive number of required touches" );
87
88   if (mMinimumTouchesRequired != touches || mMaximumTouchesRequired != touches)
89   {
90     mMinimumTouchesRequired = mMaximumTouchesRequired = touches;
91
92     if (!mAttachedActors.empty())
93     {
94       mGestureEventProcessor.GestureDetectorUpdated(this);
95     }
96   }
97 }
98
99 void LongPressGestureDetector::SetTouchesRequired(unsigned int minTouches, unsigned int maxTouches)
100 {
101   DALI_ASSERT_ALWAYS(minTouches > 0 && "Can only set a positive number of minimum touches");
102   DALI_ASSERT_ALWAYS(maxTouches > 0 && "Can only set a positive number of minimum touches");
103   DALI_ASSERT_ALWAYS(minTouches <= maxTouches && "Number of minimum touches must be less than maximum");
104
105   if (mMinimumTouchesRequired != minTouches || mMaximumTouchesRequired != maxTouches)
106   {
107     mMinimumTouchesRequired = minTouches;
108     mMaximumTouchesRequired = maxTouches;
109
110     if (!mAttachedActors.empty())
111     {
112       mGestureEventProcessor.GestureDetectorUpdated(this);
113     }
114   }
115 }
116
117 unsigned int LongPressGestureDetector::GetMinimumTouchesRequired() const
118 {
119   return mMinimumTouchesRequired;
120 }
121
122 unsigned int LongPressGestureDetector::GetMaximumTouchesRequired() const
123 {
124   return mMaximumTouchesRequired;
125 }
126
127 void LongPressGestureDetector::EmitLongPressGestureSignal(Dali::Actor pressedActor, const LongPressGesture& longPress)
128 {
129   // Guard against destruction during signal emission
130   Dali::LongPressGestureDetector handle( this );
131
132   mDetectedSignal.Emit( pressedActor, longPress );
133 }
134
135 bool LongPressGestureDetector::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
136 {
137   bool connected( true );
138   LongPressGestureDetector* gesture = dynamic_cast<LongPressGestureDetector*>(object);
139
140   if ( Dali::LongPressGestureDetector::SIGNAL_LONG_PRESS_DETECTED == signalName )
141   {
142     gesture->DetectedSignal().Connect( tracker, functor );
143   }
144   else
145   {
146     // signalName does not match any signal
147     connected = false;
148   }
149
150   return connected;
151 }
152
153 void LongPressGestureDetector::OnActorAttach(Actor& actor)
154 {
155   // Do nothing
156 }
157
158 void LongPressGestureDetector::OnActorDetach(Actor& actor)
159 {
160   // Do nothing
161 }
162
163 void LongPressGestureDetector::OnActorDestroyed(Object& object)
164 {
165   // Do nothing
166 }
167
168 } // namespace Internal
169
170 } // namespace Dali