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 <dali/internal/event/events/gesture-detector-impl.h>
25 #include <dali/integration-api/debug.h>
26 #include <dali/internal/event/events/gesture-event-processor.h>
27 #include <dali/internal/event/common/thread-local-storage.h>
28 #include <dali/internal/event/common/stage-impl.h>
38 const std::string INVALID_PROPERTY; // Empty string for invalid calls
41 GestureDetector::GestureDetector(Gesture::Type type)
43 mGestureEventProcessor(ThreadLocalStorage::Get().GetGestureEventProcessor()),
48 GestureDetector::~GestureDetector()
50 if ( !mAttachedActors.empty() )
52 for ( GestureDetectorActorContainer::iterator iter = mAttachedActors.begin(), endIter = mAttachedActors.end(); iter != endIter; ++iter )
54 (*iter)->RemoveObserver( *this );
55 (*iter)->TouchedSignal().Disconnect( mSlotDelegate, &GestureDetector::OnTouchEvent );
58 mAttachedActors.clear();
60 // Guard to allow handle destruction after Core has been destroyed
61 if ( Stage::IsInstalled() )
63 mGestureEventProcessor.RemoveGestureDetector( this );
68 void GestureDetector::Attach(Actor& actor)
70 if ( !IsAttached(actor) )
72 // Register with EventProcessor if first actor being added
73 if ( mAttachedActors.empty() )
75 mGestureEventProcessor.AddGestureDetector(this);
78 mAttachedActors.push_back(&actor);
80 // We need to observe the actor's destruction
81 actor.AddObserver(*this);
83 // Dummy connection to touch event
84 actor.TouchedSignal().Connect( mSlotDelegate, &GestureDetector::OnTouchEvent );
86 // Notification for derived classes
91 void GestureDetector::Detach(Actor& actor)
93 if ( !mAttachedActors.empty() )
95 GestureDetectorActorContainer::iterator match = find(mAttachedActors.begin(), mAttachedActors.end(), &actor);
97 if ( match != mAttachedActors.end() )
99 // We no longer need to observe the actor's destruction
100 actor.RemoveObserver(*this);
102 mAttachedActors.erase(match);
104 // Disconnect connection to touch event
105 actor.TouchedSignal().Disconnect( mSlotDelegate, &PanGestureDetector::OnTouchEvent );
107 // Notification for derived classes
108 OnActorDetach(actor);
110 // Unregister from gesture event processor if we do not have any actors
111 if ( mAttachedActors.empty() )
113 mGestureEventProcessor.RemoveGestureDetector(this);
119 void GestureDetector::DetachAll()
121 if ( !mAttachedActors.empty() )
123 GestureDetectorActorContainer attachedActors(mAttachedActors);
125 // Clear mAttachedActors before we call OnActorDetach in case derived classes call a method which manipulates mAttachedActors.
126 mAttachedActors.clear();
128 for ( GestureDetectorActorContainer::iterator iter = attachedActors.begin(), endIter = attachedActors.end(); iter != endIter; ++iter )
132 // We no longer need to observe the actor's destruction
133 actor->RemoveObserver(*this);
135 // Notification for derived classes
136 OnActorDetach(*actor);
139 // Unregister from gesture event processor
140 mGestureEventProcessor.RemoveGestureDetector(this);
144 std::vector<Dali::Actor> GestureDetector::GetAttachedActors() const
146 // Will only be used by Public API.
147 // Unlikely that it will be called that often so copying should be OK.
149 std::vector<Dali::Actor> actors;
151 for ( GestureDetectorActorContainer::const_iterator iter = mAttachedActors.begin(), endIter = mAttachedActors.end(); iter != endIter; ++iter )
153 actors.push_back(Dali::Actor(*iter));
159 bool GestureDetector::IsAttached(Actor& actor) const
161 return find(mAttachedActors.begin(), mAttachedActors.end(), &actor) != mAttachedActors.end();
164 void GestureDetector::ProxyDestroyed(ProxyObject& proxy)
166 if ( !mAttachedActors.empty() )
168 GestureDetectorActorContainer::iterator match = find(mAttachedActors.begin(), mAttachedActors.end(), &proxy);
170 if ( match != mAttachedActors.end() )
172 mAttachedActors.erase(match);
174 // Notification for derived classes
175 OnActorDestroyed(proxy);
177 // Unregister from gesture event processor if we do not have any actors
178 if ( mAttachedActors.empty() )
180 mGestureEventProcessor.RemoveGestureDetector(this);
186 bool GestureDetector::OnTouchEvent(Dali::Actor actor, const TouchEvent& event)
191 bool GestureDetector::IsSceneObjectRemovable() const
196 unsigned int GestureDetector::GetDefaultPropertyCount() const
201 void GestureDetector::GetDefaultPropertyIndices( Property::IndexContainer& ) const
205 const std::string& GestureDetector::GetDefaultPropertyName( Property::Index index ) const
207 return INVALID_PROPERTY;
210 Property::Index GestureDetector::GetDefaultPropertyIndex(const std::string& name) const
215 bool GestureDetector::IsDefaultPropertyWritable(Property::Index index) const
220 bool GestureDetector::IsDefaultPropertyAnimatable(Property::Index index) const
225 bool GestureDetector::IsDefaultPropertyAConstraintInput( Property::Index index ) const
230 Property::Type GestureDetector::GetDefaultPropertyType(Property::Index index) const
232 return Property::NONE;
235 void GestureDetector::SetDefaultProperty( Property::Index index, const Property::Value& property )
237 // None of our properties should be settable from Public API
240 void GestureDetector::SetCustomProperty( Property::Index index, const CustomProperty& entry, const Property::Value& value )
242 // None of our properties should be settable from Public API
245 Property::Value GestureDetector::GetDefaultProperty(Property::Index index) const
247 return Property::Value();
250 void GestureDetector::InstallSceneObjectProperty( SceneGraph::PropertyBase& newProperty, const std::string& name, unsigned int index )
252 // We do not want the user to install custom properties
255 const SceneGraph::PropertyOwner* GestureDetector::GetSceneObject() const
260 const SceneGraph::PropertyBase* GestureDetector::GetSceneObjectAnimatableProperty( Property::Index index ) const
265 const PropertyInputImpl* GestureDetector::GetSceneObjectInputProperty( Property::Index index ) const
270 } // namespace Internal