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>
37 const char* const SIGNAL_LONG_PRESS_DETECTED = "long-press-detected";
41 return Dali::LongPressGestureDetector::New();
44 TypeRegistration mType( typeid(Dali::LongPressGestureDetector), typeid(Dali::GestureDetector), Create );
46 SignalConnectorType signalConnector1( mType, SIGNAL_LONG_PRESS_DETECTED, &LongPressGestureDetector::DoConnectSignal );
53 const unsigned int DEFAULT_TOUCHES_REQUIRED = 1;
54 } // unnamed namespace
56 LongPressGestureDetectorPtr LongPressGestureDetector::New()
58 return new LongPressGestureDetector;
61 LongPressGestureDetectorPtr LongPressGestureDetector::New(unsigned int touchesRequired)
63 return new LongPressGestureDetector(touchesRequired, touchesRequired);
66 LongPressGestureDetectorPtr LongPressGestureDetector::New(unsigned int minTouches, unsigned int maxTouches)
68 return new LongPressGestureDetector(minTouches, maxTouches);
71 LongPressGestureDetector::LongPressGestureDetector()
72 : GestureDetector(Gesture::LongPress),
73 mMinimumTouchesRequired(DEFAULT_TOUCHES_REQUIRED),
74 mMaximumTouchesRequired(DEFAULT_TOUCHES_REQUIRED)
78 LongPressGestureDetector::LongPressGestureDetector(unsigned int minTouches, unsigned int maxTouches)
79 : GestureDetector(Gesture::LongPress),
80 mMinimumTouchesRequired(minTouches),
81 mMaximumTouchesRequired(maxTouches)
85 LongPressGestureDetector::~LongPressGestureDetector()
89 void LongPressGestureDetector::SetTouchesRequired(unsigned int touches)
91 DALI_ASSERT_ALWAYS( touches > 0 && "Can only set a positive number of required touches" );
93 if (mMinimumTouchesRequired != touches || mMaximumTouchesRequired != touches)
95 mMinimumTouchesRequired = mMaximumTouchesRequired = touches;
97 if (!mAttachedActors.empty())
99 mGestureEventProcessor.GestureDetectorUpdated(this);
104 void LongPressGestureDetector::SetTouchesRequired(unsigned int minTouches, unsigned int maxTouches)
106 DALI_ASSERT_ALWAYS(minTouches > 0 && "Can only set a positive number of minimum touches");
107 DALI_ASSERT_ALWAYS(maxTouches > 0 && "Can only set a positive number of minimum touches");
108 DALI_ASSERT_ALWAYS(minTouches <= maxTouches && "Number of minimum touches must be less than maximum");
110 if (mMinimumTouchesRequired != minTouches || mMaximumTouchesRequired != maxTouches)
112 mMinimumTouchesRequired = minTouches;
113 mMaximumTouchesRequired = maxTouches;
115 if (!mAttachedActors.empty())
117 mGestureEventProcessor.GestureDetectorUpdated(this);
122 unsigned int LongPressGestureDetector::GetMinimumTouchesRequired() const
124 return mMinimumTouchesRequired;
127 unsigned int LongPressGestureDetector::GetMaximumTouchesRequired() const
129 return mMaximumTouchesRequired;
132 void LongPressGestureDetector::EmitLongPressGestureSignal(Dali::Actor pressedActor, const LongPressGesture& longPress)
134 // Guard against destruction during signal emission
135 Dali::LongPressGestureDetector handle( this );
137 mDetectedSignal.Emit( pressedActor, longPress );
140 bool LongPressGestureDetector::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
142 bool connected( true );
143 LongPressGestureDetector* gesture = dynamic_cast<LongPressGestureDetector*>(object);
145 if ( 0 == strcmp( signalName.c_str(), SIGNAL_LONG_PRESS_DETECTED ) )
147 gesture->DetectedSignal().Connect( tracker, functor );
151 // signalName does not match any signal
158 void LongPressGestureDetector::OnActorAttach(Actor& actor)
163 void LongPressGestureDetector::OnActorDetach(Actor& actor)
168 void LongPressGestureDetector::OnActorDestroyed(Object& object)
173 } // namespace Internal