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-toolkit/internal/controls/scrollable/scrollable-impl.h>
20 #include <dali-toolkit/internal/controls/scroll-component/scroll-bar-internal-impl.h>
27 } // unnamed namespace
43 // empty handle as we cannot create Scrollable (but type registered for scroll signal)
47 TypeRegistration mType( typeid(Toolkit::Scrollable), typeid(Toolkit::Control), Create );
49 SignalConnectorType s1(mType, Toolkit::Scrollable::SIGNAL_SCROLL_STARTED, &Scrollable::DoConnectSignal);
50 SignalConnectorType s2(mType, Toolkit::Scrollable::SIGNAL_SCROLL_COMPLETED, &Scrollable::DoConnectSignal);
51 SignalConnectorType s3(mType, Toolkit::Scrollable::SIGNAL_SCROLL_UPDATED, &Scrollable::DoConnectSignal);
52 SignalConnectorType s4(mType, Toolkit::Scrollable::SIGNAL_SCROLL_CLAMPED, &Scrollable::DoConnectSignal);
56 const std::string Scrollable::SCROLLABLE_CAN_SCROLL_VERTICAL( "scrollable-can-scroll-vertical" );
57 const std::string Scrollable::SCROLLABLE_CAN_SCROLL_HORIZONTAL( "scrollable-can-scroll-horizontal" );
58 const Vector4 Scrollable::DEFAULT_OVERSHOOT_COLOUR(0.0f, 0.64f, 0.85f, 0.6f);
60 ///////////////////////////////////////////////////////////////////////////////////////////////////
62 ///////////////////////////////////////////////////////////////////////////////////////////////////
64 Scrollable::Scrollable()
65 : Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS | REQUIRES_STYLE_CHANGE_SIGNALS ) ),
66 mPropertyRelativePosition(Property::INVALID_INDEX),
67 mPropertyPositionMin(Property::INVALID_INDEX),
68 mPropertyPositionMax(Property::INVALID_INDEX),
69 mPropertyScrollDirection(Property::INVALID_INDEX),
70 mPropertyCanScrollVertical(Property::INVALID_INDEX),
71 mPropertyCanScrollHorizontal(Property::INVALID_INDEX),
72 mOvershootEnabled(false)
76 Scrollable::~Scrollable()
78 // Clear scroll components, forces their destruction before Scrollable is destroyed.
82 void Scrollable::RegisterCommonProperties()
86 // Register properties.
87 mPropertyRelativePosition = self.RegisterProperty(Toolkit::Scrollable::SCROLL_RELATIVE_POSITION_PROPERTY_NAME, Vector3::ZERO);
88 mPropertyPositionMin = self.RegisterProperty(Toolkit::Scrollable::SCROLL_POSITION_MIN_PROPERTY_NAME, Vector3::ZERO);
89 mPropertyPositionMax = self.RegisterProperty(Toolkit::Scrollable::SCROLL_POSITION_MAX_PROPERTY_NAME, Vector3::ZERO);
90 mPropertyScrollDirection = self.RegisterProperty(Toolkit::Scrollable::SCROLL_DIRECTION_PROPERTY_NAME, Vector3::ZERO);
91 mPropertyCanScrollVertical = self.RegisterProperty(SCROLLABLE_CAN_SCROLL_VERTICAL, true);
92 mPropertyCanScrollHorizontal = self.RegisterProperty(SCROLLABLE_CAN_SCROLL_HORIZONTAL, true);
95 bool Scrollable::IsScrollComponentEnabled(Toolkit::Scrollable::ScrollComponentType type) const
97 if(type == Toolkit::Scrollable::OvershootIndicator)
99 return mOvershootEnabled;
101 return (mComponents.find(type) != mComponents.end());
104 void Scrollable::EnableScrollComponent(Toolkit::Scrollable::ScrollComponentType type)
106 if(type == Toolkit::Scrollable::OvershootIndicator)
108 if( !mOvershootEnabled )
110 SetOvershootEnabled(true);
111 mOvershootEnabled = true;
115 if( mComponents.find(type) == mComponents.end() )
117 // Create ScrollComponent
118 Toolkit::Scrollable scrollable = Toolkit::Scrollable::DownCast(Self());
119 Toolkit::ScrollComponent scrollComponent = NewScrollComponent(scrollable, type);
120 Toolkit::ScrollComponentImpl& component = static_cast<Toolkit::ScrollComponentImpl&>(scrollComponent.GetImplementation());
121 ScrollComponentPtr componentPtr(&component);
123 mComponents[type] = componentPtr;
127 void Scrollable::DisableScrollComponent(Toolkit::Scrollable::ScrollComponentType type)
129 if(type == Toolkit::Scrollable::OvershootIndicator)
131 if( mOvershootEnabled )
133 SetOvershootEnabled(false);
134 mOvershootEnabled = false;
138 ComponentIter pair = mComponents.find( type );
140 if( mComponents.end() != pair )
142 ScrollComponentPtr component = pair->second;
144 // Disconnect the scroll component first.
145 component->OnDisconnect();
147 // Destroy ScrollComponent.
148 mComponents.erase( type );
152 Toolkit::Scrollable::ScrollStartedSignalV2& Scrollable::ScrollStartedSignal()
154 return mScrollStartedSignalV2;
157 Toolkit::Scrollable::ScrollUpdatedSignalV2& Scrollable::ScrollUpdatedSignal()
159 return mScrollUpdatedSignalV2;
162 Toolkit::Scrollable::ScrollCompletedSignalV2& Scrollable::ScrollCompletedSignal()
164 return mScrollCompletedSignalV2;
167 Toolkit::Scrollable::ScrollClampedSignalV2& Scrollable::ScrollClampedSignal()
169 return mScrollClampedSignalV2;
172 bool Scrollable::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
174 Dali::BaseHandle handle( object );
176 bool connected( true );
177 Toolkit::Scrollable scrollable = Toolkit::Scrollable::DownCast( handle );
179 if( Toolkit::Scrollable::SIGNAL_SCROLL_STARTED == signalName )
181 scrollable.ScrollStartedSignal().Connect( tracker, functor );
183 else if( Toolkit::Scrollable::SIGNAL_SCROLL_UPDATED == signalName )
185 scrollable.ScrollUpdatedSignal().Connect( tracker, functor );
187 else if( Toolkit::Scrollable::SIGNAL_SCROLL_COMPLETED == signalName )
189 scrollable.ScrollCompletedSignal().Connect( tracker, functor );
191 else if( Toolkit::Scrollable::SIGNAL_SCROLL_CLAMPED == signalName )
193 scrollable.ScrollClampedSignal().Connect( tracker, functor );
197 // signalName does not match any signal
204 Toolkit::ScrollComponent Scrollable::NewScrollComponent(Toolkit::Scrollable& scrollable, Toolkit::Scrollable::ScrollComponentType type)
206 Toolkit::ScrollComponent instance;
210 case Toolkit::Scrollable::VerticalScrollBar:
212 instance = static_cast<Toolkit::ScrollComponent>(Toolkit::ScrollBarInternal::New(scrollable, true));
215 case Toolkit::Scrollable::HorizontalScrollBar:
217 instance = static_cast<Toolkit::ScrollComponent>(Toolkit::ScrollBarInternal::New(scrollable, false));
222 DALI_ASSERT_ALWAYS(true && "Unrecognized component type");
229 } // namespace Internal
231 } // namespace Toolkit