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/public-api/object/type-registry.h>
22 #include <dali-toolkit/internal/controls/scrollable/scrollable-impl.h>
23 #include <dali-toolkit/internal/controls/scroll-component/scroll-bar-internal-impl.h>
30 } // unnamed namespace
38 const Property::Index Scrollable::PROPERTY_OVERSHOOT_EFFECT_COLOR( Toolkit::Internal::Control::CONTROL_PROPERTY_END_INDEX + 1 );
39 const Property::Index Scrollable::PROPERTY_OVERSHOOT_ANIMATION_SPEED( Toolkit::Internal::Control::CONTROL_PROPERTY_END_INDEX + 2 );
46 const Vector4 DEFAULT_OVERSHOOT_COLOUR(0.0f, 0.64f, 0.85f, 0.25f);
47 const float DEFAULT_OVERSHOOT_ANIMATION_SPEED(120.0f); // 120 pixels per second
51 const char* const SIGNAL_SCROLL_STARTED = "scroll-started";
52 const char* const SIGNAL_SCROLL_COMPLETED = "scroll-completed";
53 const char* const SIGNAL_SCROLL_UPDATED = "scroll-updated";
57 // empty handle as we cannot create Scrollable (but type registered for scroll signal)
61 TypeRegistration mType( typeid( Toolkit::Scrollable ), typeid( Toolkit::Control ), Create );
63 SignalConnectorType s1( mType, SIGNAL_SCROLL_STARTED, &Scrollable::DoConnectSignal );
64 SignalConnectorType s2( mType, SIGNAL_SCROLL_COMPLETED, &Scrollable::DoConnectSignal );
65 SignalConnectorType s3( mType, SIGNAL_SCROLL_UPDATED, &Scrollable::DoConnectSignal );
67 PropertyRegistration property1( mType,
68 "overshoot-effect-color",
69 Toolkit::Scrollable::PROPERTY_OVERSHOOT_EFFECT_COLOR,
71 &Scrollable::SetProperty,
72 &Scrollable::GetProperty );
74 PropertyRegistration property2( mType,
75 "overshoot-animation-speed",
76 Toolkit::Scrollable::PROPERTY_OVERSHOOT_ANIMATION_SPEED,
78 &Scrollable::SetProperty,
79 &Scrollable::GetProperty );
83 const std::string Scrollable::SCROLLABLE_CAN_SCROLL_VERTICAL( "scrollable-can-scroll-vertical" );
84 const std::string Scrollable::SCROLLABLE_CAN_SCROLL_HORIZONTAL( "scrollable-can-scroll-horizontal" );
86 ///////////////////////////////////////////////////////////////////////////////////////////////////
88 ///////////////////////////////////////////////////////////////////////////////////////////////////
90 // Scrollable controls are not layout containers so they dont need size negotiation..
91 // we dont want size negotiation while scrolling if we can avoid it
92 Scrollable::Scrollable()
93 : Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS | REQUIRES_STYLE_CHANGE_SIGNALS | NO_SIZE_NEGOTIATION ) ),
94 mOvershootEffectColor( DEFAULT_OVERSHOOT_COLOUR ),
95 mOvershootAnimationSpeed ( DEFAULT_OVERSHOOT_ANIMATION_SPEED ),
96 mPropertyRelativePosition(Property::INVALID_INDEX),
97 mPropertyPositionMin(Property::INVALID_INDEX),
98 mPropertyPositionMax(Property::INVALID_INDEX),
99 mPropertyScrollDirection(Property::INVALID_INDEX),
100 mPropertyCanScrollVertical(Property::INVALID_INDEX),
101 mPropertyCanScrollHorizontal(Property::INVALID_INDEX),
102 mOvershootEnabled(false)
106 Scrollable::~Scrollable()
108 // Clear scroll components, forces their destruction before Scrollable is destroyed.
112 void Scrollable::RegisterCommonProperties()
116 // Register properties.
117 mPropertyRelativePosition = self.RegisterProperty(Toolkit::Scrollable::SCROLL_RELATIVE_POSITION_PROPERTY_NAME, Vector3::ZERO);
118 mPropertyPositionMin = self.RegisterProperty(Toolkit::Scrollable::SCROLL_POSITION_MIN_PROPERTY_NAME, Vector3::ZERO);
119 mPropertyPositionMax = self.RegisterProperty(Toolkit::Scrollable::SCROLL_POSITION_MAX_PROPERTY_NAME, Vector3::ZERO);
120 mPropertyScrollDirection = self.RegisterProperty(Toolkit::Scrollable::SCROLL_DIRECTION_PROPERTY_NAME, Vector3::ZERO);
121 mPropertyCanScrollVertical = self.RegisterProperty(SCROLLABLE_CAN_SCROLL_VERTICAL, true);
122 mPropertyCanScrollHorizontal = self.RegisterProperty(SCROLLABLE_CAN_SCROLL_HORIZONTAL, true);
125 bool Scrollable::IsScrollComponentEnabled(Toolkit::Scrollable::ScrollComponentType type) const
127 if(type == Toolkit::Scrollable::OvershootIndicator)
129 return mOvershootEnabled;
131 return (mComponents.find(type) != mComponents.end());
134 void Scrollable::EnableScrollComponent(Toolkit::Scrollable::ScrollComponentType type)
136 if(type == Toolkit::Scrollable::OvershootIndicator)
138 if( !mOvershootEnabled )
140 SetOvershootEnabled(true);
141 mOvershootEnabled = true;
145 if( mComponents.find(type) == mComponents.end() )
147 // Create ScrollComponent
148 Toolkit::Scrollable scrollable = Toolkit::Scrollable::DownCast(Self());
149 Toolkit::ScrollComponent scrollComponent = NewScrollComponent(scrollable, type);
150 Toolkit::ScrollComponentImpl& component = static_cast<Toolkit::ScrollComponentImpl&>(scrollComponent.GetImplementation());
151 ScrollComponentPtr componentPtr(&component);
153 mComponents[type] = componentPtr;
157 void Scrollable::DisableScrollComponent(Toolkit::Scrollable::ScrollComponentType type)
159 if(type == Toolkit::Scrollable::OvershootIndicator)
161 if( mOvershootEnabled )
163 SetOvershootEnabled(false);
164 mOvershootEnabled = false;
168 ComponentIter pair = mComponents.find( type );
170 if( mComponents.end() != pair )
172 ScrollComponentPtr component = pair->second;
174 // Disconnect the scroll component first.
175 component->OnDisconnect();
177 // Destroy ScrollComponent.
178 mComponents.erase( type );
182 Vector4 Scrollable::GetOvershootEffectColor() const
184 return mOvershootEffectColor;
187 void Scrollable::SetOvershootAnimationSpeed( float pixelsPerSecond )
189 mOvershootAnimationSpeed = pixelsPerSecond;
192 float Scrollable::GetOvershootAnimationSpeed() const
194 return mOvershootAnimationSpeed;
197 Toolkit::Scrollable::ScrollStartedSignalType& Scrollable::ScrollStartedSignal()
199 return mScrollStartedSignal;
202 Toolkit::Scrollable::ScrollUpdatedSignalType& Scrollable::ScrollUpdatedSignal()
204 return mScrollUpdatedSignal;
207 Toolkit::Scrollable::ScrollCompletedSignalType& Scrollable::ScrollCompletedSignal()
209 return mScrollCompletedSignal;
212 bool Scrollable::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
214 Dali::BaseHandle handle( object );
216 bool connected( true );
217 Toolkit::Scrollable scrollable = Toolkit::Scrollable::DownCast( handle );
219 if( 0 == strcmp( signalName.c_str(), SIGNAL_SCROLL_STARTED ) )
221 scrollable.ScrollStartedSignal().Connect( tracker, functor );
223 else if( 0 == strcmp( signalName.c_str(), SIGNAL_SCROLL_UPDATED ) )
225 scrollable.ScrollUpdatedSignal().Connect( tracker, functor );
227 else if( 0 == strcmp( signalName.c_str(), SIGNAL_SCROLL_COMPLETED ) )
229 scrollable.ScrollCompletedSignal().Connect( tracker, functor );
233 // signalName does not match any signal
240 void Scrollable::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
242 Toolkit::Scrollable scrollable = Toolkit::Scrollable::DownCast( Dali::BaseHandle( object ) );
246 Scrollable& scrollableImpl( GetImpl( scrollable ) );
249 case Toolkit::Scrollable::PROPERTY_OVERSHOOT_EFFECT_COLOR:
251 scrollableImpl.SetOvershootEffectColor( value.Get<Vector4>() );
254 case Toolkit::Scrollable::PROPERTY_OVERSHOOT_ANIMATION_SPEED:
256 scrollableImpl.SetOvershootAnimationSpeed( value.Get<float>() );
263 Property::Value Scrollable::GetProperty( BaseObject* object, Property::Index index )
265 Property::Value value;
267 Toolkit::Scrollable scrollable = Toolkit::Scrollable::DownCast( Dali::BaseHandle( object ) );
271 Scrollable& scrollableImpl( GetImpl( scrollable ) );
274 case Toolkit::Scrollable::PROPERTY_OVERSHOOT_EFFECT_COLOR:
276 value = scrollableImpl.GetOvershootEffectColor();
279 case Toolkit::Scrollable::PROPERTY_OVERSHOOT_ANIMATION_SPEED:
281 value = scrollableImpl.GetOvershootAnimationSpeed();
290 Toolkit::ScrollComponent Scrollable::NewScrollComponent(Toolkit::Scrollable& scrollable, Toolkit::Scrollable::ScrollComponentType type)
292 Toolkit::ScrollComponent instance;
296 case Toolkit::Scrollable::VerticalScrollBar:
298 instance = static_cast<Toolkit::ScrollComponent>(Toolkit::ScrollBarInternal::New(scrollable, true));
301 case Toolkit::Scrollable::HorizontalScrollBar:
303 instance = static_cast<Toolkit::ScrollComponent>(Toolkit::ScrollBarInternal::New(scrollable, false));
306 case Toolkit::Scrollable::OvershootIndicator:
308 DALI_ASSERT_ALWAYS(!"Unrecognized component type");
316 } // namespace Internal
318 } // namespace Toolkit