2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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.
18 #include <dali-toolkit/internal/controls/scrollable/scrollable-impl.h>
19 #include <dali-toolkit/internal/controls/scroll-component/scroll-bar-internal-impl.h>
26 } // unnamed namespace
42 // empty handle as we cannot create Scrollable (but type registered for scroll signal)
46 TypeRegistration mType( typeid(Toolkit::Scrollable), typeid(Toolkit::Control), Create );
48 SignalConnectorType s1(mType, Toolkit::Scrollable::SIGNAL_SCROLL_STARTED, &Scrollable::DoConnectSignal);
49 SignalConnectorType s2(mType, Toolkit::Scrollable::SIGNAL_SCROLL_COMPLETED, &Scrollable::DoConnectSignal);
50 SignalConnectorType s3(mType, Toolkit::Scrollable::SIGNAL_SCROLL_UPDATED, &Scrollable::DoConnectSignal);
51 SignalConnectorType s4(mType, Toolkit::Scrollable::SIGNAL_SCROLL_CLAMPED, &Scrollable::DoConnectSignal);
55 const std::string Scrollable::SCROLLABLE_CAN_SCROLL_VERTICAL( "scrollable-can-scroll-vertical" );
56 const std::string Scrollable::SCROLLABLE_CAN_SCROLL_HORIZONTAL( "scrollable-can-scroll-horizontal" );
57 const Vector4 Scrollable::DEFAULT_OVERSHOOT_COLOUR(0.0f, 0.64f, 0.85f, 0.6f);
59 ///////////////////////////////////////////////////////////////////////////////////////////////////
61 ///////////////////////////////////////////////////////////////////////////////////////////////////
63 Scrollable::Scrollable()
64 : Control(true/*requires touch*/),
65 mPropertyRelativePosition(Property::INVALID_INDEX),
66 mPropertyPositionMin(Property::INVALID_INDEX),
67 mPropertyPositionMax(Property::INVALID_INDEX),
68 mPropertyScrollDirection(Property::INVALID_INDEX),
69 mOvershootEnabled(false)
73 Scrollable::~Scrollable()
75 // Clear scroll components, forces their destruction before Scrollable is destroyed.
79 void Scrollable::RegisterCommonProperties()
83 // Register properties.
84 mPropertyRelativePosition = self.RegisterProperty(Toolkit::Scrollable::SCROLL_RELATIVE_POSITION_PROPERTY_NAME, Vector3::ZERO);
85 mPropertyPositionMin = self.RegisterProperty(Toolkit::Scrollable::SCROLL_POSITION_MIN_PROPERTY_NAME, Vector3::ZERO);
86 mPropertyPositionMax = self.RegisterProperty(Toolkit::Scrollable::SCROLL_POSITION_MAX_PROPERTY_NAME, Vector3::ZERO);
87 mPropertyScrollDirection = self.RegisterProperty(Toolkit::Scrollable::SCROLL_DIRECTION_PROPERTY_NAME, Vector3::ZERO);
88 mPropertyCanScrollVertical = self.RegisterProperty(SCROLLABLE_CAN_SCROLL_VERTICAL, true);
89 mPropertyCanScrollHorizontal = self.RegisterProperty(SCROLLABLE_CAN_SCROLL_HORIZONTAL, true);
92 bool Scrollable::IsScrollComponentEnabled(Toolkit::Scrollable::ScrollComponentType type) const
94 if(type == Toolkit::Scrollable::OvershootIndicator)
96 return mOvershootEnabled;
98 return (mComponents.find(type) != mComponents.end());
101 void Scrollable::EnableScrollComponent(Toolkit::Scrollable::ScrollComponentType type)
103 if(type == Toolkit::Scrollable::OvershootIndicator)
105 if( !mOvershootEnabled )
107 SetOvershootEnabled(true);
108 mOvershootEnabled = true;
112 if( mComponents.find(type) == mComponents.end() )
114 // Create ScrollComponent
115 Toolkit::Scrollable scrollable = Toolkit::Scrollable::DownCast(Self());
116 Toolkit::ScrollComponent scrollComponent = NewScrollComponent(scrollable, type);
117 Toolkit::ScrollComponentImpl& component = static_cast<Toolkit::ScrollComponentImpl&>(scrollComponent.GetImplementation());
118 ScrollComponentPtr componentPtr(&component);
120 mComponents[type] = componentPtr;
124 void Scrollable::DisableScrollComponent(Toolkit::Scrollable::ScrollComponentType type)
126 if(type == Toolkit::Scrollable::OvershootIndicator)
128 if( mOvershootEnabled )
130 SetOvershootEnabled(false);
131 mOvershootEnabled = false;
135 ComponentIter pair = mComponents.find( type );
137 if( mComponents.end() != pair )
139 ScrollComponentPtr component = pair->second;
141 // Disconnect the scroll component first.
142 component->OnDisconnect();
144 // Destroy ScrollComponent.
145 mComponents.erase( type );
149 Toolkit::Scrollable::ScrollStartedSignalV2& Scrollable::ScrollStartedSignal()
151 return mScrollStartedSignalV2;
154 Toolkit::Scrollable::ScrollUpdatedSignalV2& Scrollable::ScrollUpdatedSignal()
156 return mScrollUpdatedSignalV2;
159 Toolkit::Scrollable::ScrollCompletedSignalV2& Scrollable::ScrollCompletedSignal()
161 return mScrollCompletedSignalV2;
164 Toolkit::Scrollable::ScrollClampedSignalV2& Scrollable::ScrollClampedSignal()
166 return mScrollClampedSignalV2;
169 bool Scrollable::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
171 Dali::BaseHandle handle( object );
173 bool connected( true );
174 Toolkit::Scrollable scrollable = Toolkit::Scrollable::DownCast( handle );
176 if( Toolkit::Scrollable::SIGNAL_SCROLL_STARTED == signalName )
178 scrollable.ScrollStartedSignal().Connect( tracker, functor );
180 else if( Toolkit::Scrollable::SIGNAL_SCROLL_UPDATED == signalName )
182 scrollable.ScrollUpdatedSignal().Connect( tracker, functor );
184 else if( Toolkit::Scrollable::SIGNAL_SCROLL_COMPLETED == signalName )
186 scrollable.ScrollCompletedSignal().Connect( tracker, functor );
188 else if( Toolkit::Scrollable::SIGNAL_SCROLL_CLAMPED == signalName )
190 scrollable.ScrollClampedSignal().Connect( tracker, functor );
194 // signalName does not match any signal
201 Toolkit::ScrollComponent Scrollable::NewScrollComponent(Toolkit::Scrollable& scrollable, Toolkit::Scrollable::ScrollComponentType type)
203 Toolkit::ScrollComponent instance;
207 case Toolkit::Scrollable::VerticalScrollBar:
209 instance = static_cast<Toolkit::ScrollComponent>(Toolkit::ScrollBarInternal::New(scrollable, true));
212 case Toolkit::Scrollable::HorizontalScrollBar:
214 instance = static_cast<Toolkit::ScrollComponent>(Toolkit::ScrollBarInternal::New(scrollable, false));
219 DALI_ASSERT_ALWAYS(true && "Unrecognized component type");
226 } // namespace Internal
228 } // namespace Toolkit