2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include "long-press-gesture-detector-impl.h"
22 #include <cstring> // for strcmp
25 #include <dali/public-api/events/long-press-gesture.h>
26 #include <dali/public-api/object/type-registry.h>
27 #include <dali/internal/event/events/gesture-event-processor.h>
40 const char* const SIGNAL_LONG_PRESS_DETECTED = "longPressDetected";
44 return Dali::LongPressGestureDetector::New();
47 TypeRegistration mType( typeid(Dali::LongPressGestureDetector), typeid(Dali::GestureDetector), Create );
49 SignalConnectorType signalConnector1( mType, SIGNAL_LONG_PRESS_DETECTED, &LongPressGestureDetector::DoConnectSignal );
56 const unsigned int DEFAULT_TOUCHES_REQUIRED = 1;
57 } // unnamed namespace
59 LongPressGestureDetectorPtr LongPressGestureDetector::New()
61 return new LongPressGestureDetector;
64 LongPressGestureDetectorPtr LongPressGestureDetector::New(unsigned int touchesRequired)
66 return new LongPressGestureDetector(touchesRequired, touchesRequired);
69 LongPressGestureDetectorPtr LongPressGestureDetector::New(unsigned int minTouches, unsigned int maxTouches)
71 return new LongPressGestureDetector(minTouches, maxTouches);
74 LongPressGestureDetector::LongPressGestureDetector()
75 : GestureDetector(Gesture::LongPress),
76 mMinimumTouchesRequired(DEFAULT_TOUCHES_REQUIRED),
77 mMaximumTouchesRequired(DEFAULT_TOUCHES_REQUIRED)
81 LongPressGestureDetector::LongPressGestureDetector(unsigned int minTouches, unsigned int maxTouches)
82 : GestureDetector(Gesture::LongPress),
83 mMinimumTouchesRequired(minTouches),
84 mMaximumTouchesRequired(maxTouches)
88 LongPressGestureDetector::~LongPressGestureDetector()
92 void LongPressGestureDetector::SetTouchesRequired(unsigned int touches)
94 DALI_ASSERT_ALWAYS( touches > 0 && "Can only set a positive number of required touches" );
96 if (mMinimumTouchesRequired != touches || mMaximumTouchesRequired != touches)
98 mMinimumTouchesRequired = mMaximumTouchesRequired = touches;
100 if (!mAttachedActors.empty())
102 mGestureEventProcessor.GestureDetectorUpdated(this);
107 void LongPressGestureDetector::SetTouchesRequired(unsigned int minTouches, unsigned int maxTouches)
109 DALI_ASSERT_ALWAYS(minTouches > 0 && "Can only set a positive number of minimum touches");
110 DALI_ASSERT_ALWAYS(maxTouches > 0 && "Can only set a positive number of minimum touches");
111 DALI_ASSERT_ALWAYS(minTouches <= maxTouches && "Number of minimum touches must be less than maximum");
113 if (mMinimumTouchesRequired != minTouches || mMaximumTouchesRequired != maxTouches)
115 mMinimumTouchesRequired = minTouches;
116 mMaximumTouchesRequired = maxTouches;
118 if (!mAttachedActors.empty())
120 mGestureEventProcessor.GestureDetectorUpdated(this);
125 unsigned int LongPressGestureDetector::GetMinimumTouchesRequired() const
127 return mMinimumTouchesRequired;
130 unsigned int LongPressGestureDetector::GetMaximumTouchesRequired() const
132 return mMaximumTouchesRequired;
135 void LongPressGestureDetector::EmitLongPressGestureSignal(Dali::Actor pressedActor, const LongPressGesture& longPress)
137 // Guard against destruction during signal emission
138 Dali::LongPressGestureDetector handle( this );
140 mDetectedSignal.Emit( pressedActor, longPress );
143 bool LongPressGestureDetector::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
145 bool connected( true );
146 LongPressGestureDetector* gesture = dynamic_cast<LongPressGestureDetector*>(object);
148 if ( 0 == strcmp( signalName.c_str(), SIGNAL_LONG_PRESS_DETECTED ) )
150 gesture->DetectedSignal().Connect( tracker, functor );
154 // signalName does not match any signal
161 void LongPressGestureDetector::OnActorAttach(Actor& actor)
166 void LongPressGestureDetector::OnActorDetach(Actor& actor)
171 void LongPressGestureDetector::OnActorDestroyed(Object& object)
176 } // namespace Internal