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>
20 #include <dali/public-api/object/type-registry-helper.h>
23 #include <dali-toolkit/internal/controls/scrollable/scrollable-impl.h>
24 #include <dali-toolkit/internal/controls/scroll-component/scroll-bar-internal-impl.h>
42 // empty handle as we cannot create Scrollable (but type registered for scroll signal)
46 // Setup properties, signals and actions using the type-registry.
47 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::Scrollable, Toolkit::Control, Create );
49 DALI_PROPERTY_REGISTRATION( Scrollable, "overshoot-effect-color", VECTOR4, OVERSHOOT_EFFECT_COLOR )
50 DALI_PROPERTY_REGISTRATION( Scrollable, "overshoot-animation-speed", FLOAT, OVERSHOOT_ANIMATION_SPEED )
52 DALI_SIGNAL_REGISTRATION( Scrollable, "scroll-started", SIGNAL_SCROLL_STARTED )
53 DALI_SIGNAL_REGISTRATION( Scrollable, "scroll-completed", SIGNAL_SCROLL_COMPLETED )
54 DALI_SIGNAL_REGISTRATION( Scrollable, "scroll-updated", SIGNAL_SCROLL_UPDATED )
56 DALI_TYPE_REGISTRATION_END()
58 const Vector4 DEFAULT_OVERSHOOT_COLOUR(0.0f, 0.64f, 0.85f, 0.25f);
59 const float DEFAULT_OVERSHOOT_ANIMATION_SPEED(120.0f); // 120 pixels per second
63 const char* const Scrollable::SCROLLABLE_CAN_SCROLL_VERTICAL = "scrollable-can-scroll-vertical";
64 const char* const Scrollable::SCROLLABLE_CAN_SCROLL_HORIZONTAL = "scrollable-can-scroll-horizontal";
66 ///////////////////////////////////////////////////////////////////////////////////////////////////
68 ///////////////////////////////////////////////////////////////////////////////////////////////////
70 // Scrollable controls are not layout containers so they dont need size negotiation..
71 // we dont want size negotiation while scrolling if we can avoid it
72 Scrollable::Scrollable()
73 : Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS | REQUIRES_STYLE_CHANGE_SIGNALS | NO_SIZE_NEGOTIATION ) ),
74 mOvershootEffectColor( DEFAULT_OVERSHOOT_COLOUR ),
75 mOvershootAnimationSpeed ( DEFAULT_OVERSHOOT_ANIMATION_SPEED ),
76 mPropertyRelativePosition(Property::INVALID_INDEX),
77 mPropertyPositionMin(Property::INVALID_INDEX),
78 mPropertyPositionMax(Property::INVALID_INDEX),
79 mPropertyScrollDirection(Property::INVALID_INDEX),
80 mPropertyCanScrollVertical(Property::INVALID_INDEX),
81 mPropertyCanScrollHorizontal(Property::INVALID_INDEX),
82 mOvershootEnabled(false)
86 Scrollable::~Scrollable()
88 // Clear scroll components, forces their destruction before Scrollable is destroyed.
92 void Scrollable::RegisterCommonProperties()
96 // Register properties.
97 mPropertyRelativePosition = self.RegisterProperty(Toolkit::Scrollable::SCROLL_RELATIVE_POSITION_PROPERTY_NAME, Vector3::ZERO);
98 mPropertyPositionMin = self.RegisterProperty(Toolkit::Scrollable::SCROLL_POSITION_MIN_PROPERTY_NAME, Vector3::ZERO);
99 mPropertyPositionMax = self.RegisterProperty(Toolkit::Scrollable::SCROLL_POSITION_MAX_PROPERTY_NAME, Vector3::ZERO);
100 mPropertyScrollDirection = self.RegisterProperty(Toolkit::Scrollable::SCROLL_DIRECTION_PROPERTY_NAME, Vector3::ZERO);
101 mPropertyCanScrollVertical = self.RegisterProperty(SCROLLABLE_CAN_SCROLL_VERTICAL, true);
102 mPropertyCanScrollHorizontal = self.RegisterProperty(SCROLLABLE_CAN_SCROLL_HORIZONTAL, true);
105 bool Scrollable::IsScrollComponentEnabled(Toolkit::Scrollable::ScrollComponentType type) const
107 if(type == Toolkit::Scrollable::OvershootIndicator)
109 return mOvershootEnabled;
111 return (mComponents.find(type) != mComponents.end());
114 void Scrollable::EnableScrollComponent(Toolkit::Scrollable::ScrollComponentType type)
116 if(type == Toolkit::Scrollable::OvershootIndicator)
118 if( !mOvershootEnabled )
120 SetOvershootEnabled(true);
121 mOvershootEnabled = true;
125 if( mComponents.find(type) == mComponents.end() )
127 // Create ScrollComponent
128 Toolkit::Scrollable scrollable = Toolkit::Scrollable::DownCast(Self());
129 Toolkit::ScrollComponent scrollComponent = NewScrollComponent(scrollable, type);
130 Toolkit::ScrollComponentImpl& component = static_cast<Toolkit::ScrollComponentImpl&>(scrollComponent.GetImplementation());
131 ScrollComponentPtr componentPtr(&component);
133 mComponents[type] = componentPtr;
137 void Scrollable::DisableScrollComponent(Toolkit::Scrollable::ScrollComponentType type)
139 if(type == Toolkit::Scrollable::OvershootIndicator)
141 if( mOvershootEnabled )
143 SetOvershootEnabled(false);
144 mOvershootEnabled = false;
148 ComponentIter pair = mComponents.find( type );
150 if( mComponents.end() != pair )
152 ScrollComponentPtr component = pair->second;
154 // Disconnect the scroll component first.
155 component->OnDisconnect();
157 // Destroy ScrollComponent.
158 mComponents.erase( type );
162 Vector4 Scrollable::GetOvershootEffectColor() const
164 return mOvershootEffectColor;
167 void Scrollable::SetOvershootAnimationSpeed( float pixelsPerSecond )
169 mOvershootAnimationSpeed = pixelsPerSecond;
172 float Scrollable::GetOvershootAnimationSpeed() const
174 return mOvershootAnimationSpeed;
177 Toolkit::Scrollable::ScrollStartedSignalType& Scrollable::ScrollStartedSignal()
179 return mScrollStartedSignal;
182 Toolkit::Scrollable::ScrollUpdatedSignalType& Scrollable::ScrollUpdatedSignal()
184 return mScrollUpdatedSignal;
187 Toolkit::Scrollable::ScrollCompletedSignalType& Scrollable::ScrollCompletedSignal()
189 return mScrollCompletedSignal;
192 bool Scrollable::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
194 Dali::BaseHandle handle( object );
196 bool connected( true );
197 Toolkit::Scrollable scrollable = Toolkit::Scrollable::DownCast( handle );
199 if( 0 == strcmp( signalName.c_str(), SIGNAL_SCROLL_STARTED ) )
201 scrollable.ScrollStartedSignal().Connect( tracker, functor );
203 else if( 0 == strcmp( signalName.c_str(), SIGNAL_SCROLL_UPDATED ) )
205 scrollable.ScrollUpdatedSignal().Connect( tracker, functor );
207 else if( 0 == strcmp( signalName.c_str(), SIGNAL_SCROLL_COMPLETED ) )
209 scrollable.ScrollCompletedSignal().Connect( tracker, functor );
213 // signalName does not match any signal
220 void Scrollable::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
222 Toolkit::Scrollable scrollable = Toolkit::Scrollable::DownCast( Dali::BaseHandle( object ) );
226 Scrollable& scrollableImpl( GetImpl( scrollable ) );
229 case Toolkit::Scrollable::Property::OVERSHOOT_EFFECT_COLOR:
231 scrollableImpl.SetOvershootEffectColor( value.Get<Vector4>() );
234 case Toolkit::Scrollable::Property::OVERSHOOT_ANIMATION_SPEED:
236 scrollableImpl.SetOvershootAnimationSpeed( value.Get<float>() );
243 Property::Value Scrollable::GetProperty( BaseObject* object, Property::Index index )
245 Property::Value value;
247 Toolkit::Scrollable scrollable = Toolkit::Scrollable::DownCast( Dali::BaseHandle( object ) );
251 Scrollable& scrollableImpl( GetImpl( scrollable ) );
254 case Toolkit::Scrollable::Property::OVERSHOOT_EFFECT_COLOR:
256 value = scrollableImpl.GetOvershootEffectColor();
259 case Toolkit::Scrollable::Property::OVERSHOOT_ANIMATION_SPEED:
261 value = scrollableImpl.GetOvershootAnimationSpeed();
270 Toolkit::ScrollComponent Scrollable::NewScrollComponent(Toolkit::Scrollable& scrollable, Toolkit::Scrollable::ScrollComponentType type)
272 Toolkit::ScrollComponent instance;
276 case Toolkit::Scrollable::VerticalScrollBar:
278 instance = static_cast<Toolkit::ScrollComponent>(Toolkit::ScrollBarInternal::New(scrollable, true));
281 case Toolkit::Scrollable::HorizontalScrollBar:
283 instance = static_cast<Toolkit::ScrollComponent>(Toolkit::ScrollBarInternal::New(scrollable, false));
286 case Toolkit::Scrollable::OvershootIndicator:
288 DALI_ASSERT_ALWAYS(!"Unrecognized component type");
296 } // namespace Internal
298 } // namespace Toolkit