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 <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>
36 return Dali::LongPressGestureDetector::New();
39 TypeRegistration mType( typeid(Dali::LongPressGestureDetector), typeid(Dali::GestureDetector), Create );
41 SignalConnectorType signalConnector1( mType, Dali::LongPressGestureDetector::SIGNAL_LONG_PRESS_DETECTED, &LongPressGestureDetector::DoConnectSignal );
48 const unsigned int DEFAULT_TOUCHES_REQUIRED = 1;
49 } // unnamed namespace
51 LongPressGestureDetectorPtr LongPressGestureDetector::New()
53 return new LongPressGestureDetector;
56 LongPressGestureDetectorPtr LongPressGestureDetector::New(unsigned int touchesRequired)
58 return new LongPressGestureDetector(touchesRequired, touchesRequired);
61 LongPressGestureDetectorPtr LongPressGestureDetector::New(unsigned int minTouches, unsigned int maxTouches)
63 return new LongPressGestureDetector(minTouches, maxTouches);
66 LongPressGestureDetector::LongPressGestureDetector()
67 : GestureDetector(Gesture::LongPress),
68 mMinimumTouchesRequired(DEFAULT_TOUCHES_REQUIRED),
69 mMaximumTouchesRequired(DEFAULT_TOUCHES_REQUIRED)
73 LongPressGestureDetector::LongPressGestureDetector(unsigned int minTouches, unsigned int maxTouches)
74 : GestureDetector(Gesture::LongPress),
75 mMinimumTouchesRequired(minTouches),
76 mMaximumTouchesRequired(maxTouches)
80 LongPressGestureDetector::~LongPressGestureDetector()
84 void LongPressGestureDetector::SetTouchesRequired(unsigned int touches)
86 DALI_ASSERT_ALWAYS( touches > 0 && "Can only set a positive number of required touches" );
88 if (mMinimumTouchesRequired != touches || mMaximumTouchesRequired != touches)
90 mMinimumTouchesRequired = mMaximumTouchesRequired = touches;
92 if (!mAttachedActors.empty())
94 mGestureEventProcessor.GestureDetectorUpdated(this);
99 void LongPressGestureDetector::SetTouchesRequired(unsigned int minTouches, unsigned int maxTouches)
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");
105 if (mMinimumTouchesRequired != minTouches || mMaximumTouchesRequired != maxTouches)
107 mMinimumTouchesRequired = minTouches;
108 mMaximumTouchesRequired = maxTouches;
110 if (!mAttachedActors.empty())
112 mGestureEventProcessor.GestureDetectorUpdated(this);
117 unsigned int LongPressGestureDetector::GetMinimumTouchesRequired() const
119 return mMinimumTouchesRequired;
122 unsigned int LongPressGestureDetector::GetMaximumTouchesRequired() const
124 return mMaximumTouchesRequired;
127 void LongPressGestureDetector::EmitLongPressGestureSignal(Dali::Actor pressedActor, const LongPressGesture& longPress)
129 // Guard against destruction during signal emission
130 Dali::LongPressGestureDetector handle( this );
132 mDetectedSignal.Emit( pressedActor, longPress );
135 bool LongPressGestureDetector::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
137 bool connected( true );
138 LongPressGestureDetector* gesture = dynamic_cast<LongPressGestureDetector*>(object);
140 if ( Dali::LongPressGestureDetector::SIGNAL_LONG_PRESS_DETECTED == signalName )
142 gesture->DetectedSignal().Connect( tracker, functor );
146 // signalName does not match any signal
153 void LongPressGestureDetector::OnActorAttach(Actor& actor)
158 void LongPressGestureDetector::OnActorDetach(Actor& actor)
163 void LongPressGestureDetector::OnActorDestroyed(Object& object)
168 } // namespace Internal