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" );
58 ///////////////////////////////////////////////////////////////////////////////////////////////////
60 ///////////////////////////////////////////////////////////////////////////////////////////////////
62 Scrollable::Scrollable()
63 : ControlImpl(true/*requires touch*/),
64 mPropertyRelativePosition(Property::INVALID_INDEX),
65 mPropertyPositionMin(Property::INVALID_INDEX),
66 mPropertyPositionMax(Property::INVALID_INDEX),
67 mPropertyScrollDirection(Property::INVALID_INDEX),
68 mOvershootEnabled(false)
72 Scrollable::~Scrollable()
74 // Clear scroll components, forces their destruction before Scrollable is destroyed.
78 void Scrollable::RegisterCommonProperties()
82 // Register properties.
83 mPropertyRelativePosition = self.RegisterProperty(Toolkit::Scrollable::SCROLL_RELATIVE_POSITION_PROPERTY_NAME, Vector3::ZERO);
84 mPropertyPositionMin = self.RegisterProperty(Toolkit::Scrollable::SCROLL_POSITION_MIN_PROPERTY_NAME, Vector3::ZERO);
85 mPropertyPositionMax = self.RegisterProperty(Toolkit::Scrollable::SCROLL_POSITION_MAX_PROPERTY_NAME, Vector3::ZERO);
86 mPropertyScrollDirection = self.RegisterProperty(Toolkit::Scrollable::SCROLL_DIRECTION_PROPERTY_NAME, Vector3::ZERO);
87 mPropertyCanScrollVertical = self.RegisterProperty(SCROLLABLE_CAN_SCROLL_VERTICAL, true);
88 mPropertyCanScrollHorizontal = self.RegisterProperty(SCROLLABLE_CAN_SCROLL_HORIZONTAL, true);
91 bool Scrollable::IsScrollComponentEnabled(Toolkit::Scrollable::ScrollComponentType type) const
93 if(type == Toolkit::Scrollable::OvershootIndicator)
95 return mOvershootEnabled;
97 return (mComponents.find(type) != mComponents.end());
100 void Scrollable::EnableScrollComponent(Toolkit::Scrollable::ScrollComponentType type)
102 if(type == Toolkit::Scrollable::OvershootIndicator)
104 if( !mOvershootEnabled )
106 SetOvershootEnabled(true);
107 mOvershootEnabled = true;
111 if( mComponents.find(type) == mComponents.end() )
113 // Create ScrollComponent
114 Toolkit::Scrollable scrollable = Toolkit::Scrollable::DownCast(Self());
115 Toolkit::ScrollComponent scrollComponent = NewScrollComponent(scrollable, type);
116 Toolkit::ScrollComponentImpl& component = static_cast<Toolkit::ScrollComponentImpl&>(scrollComponent.GetImplementation());
117 ScrollComponentPtr componentPtr(&component);
119 mComponents[type] = componentPtr;
123 void Scrollable::DisableScrollComponent(Toolkit::Scrollable::ScrollComponentType type)
125 if(type == Toolkit::Scrollable::OvershootIndicator)
127 if( mOvershootEnabled )
129 SetOvershootEnabled(false);
130 mOvershootEnabled = false;
134 ComponentIter pair = mComponents.find( type );
136 if( mComponents.end() != pair )
138 ScrollComponentPtr component = pair->second;
140 // Disconnect the scroll component first.
141 component->OnDisconnect();
143 // Destroy ScrollComponent.
144 mComponents.erase( type );
148 Toolkit::Scrollable::ScrollStartedSignalV2& Scrollable::ScrollStartedSignal()
150 return mScrollStartedSignalV2;
153 Toolkit::Scrollable::ScrollUpdatedSignalV2& Scrollable::ScrollUpdatedSignal()
155 return mScrollUpdatedSignalV2;
158 Toolkit::Scrollable::ScrollCompletedSignalV2& Scrollable::ScrollCompletedSignal()
160 return mScrollCompletedSignalV2;
163 Toolkit::Scrollable::ScrollClampedSignalV2& Scrollable::ScrollClampedSignal()
165 return mScrollClampedSignalV2;
168 bool Scrollable::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
170 Dali::BaseHandle handle( object );
172 bool connected( true );
173 Toolkit::Scrollable scrollable = Toolkit::Scrollable::DownCast( handle );
175 if( Toolkit::Scrollable::SIGNAL_SCROLL_STARTED == signalName )
177 scrollable.ScrollStartedSignal().Connect( tracker, functor );
179 else if( Toolkit::Scrollable::SIGNAL_SCROLL_UPDATED == signalName )
181 scrollable.ScrollUpdatedSignal().Connect( tracker, functor );
183 else if( Toolkit::Scrollable::SIGNAL_SCROLL_COMPLETED == signalName )
185 scrollable.ScrollCompletedSignal().Connect( tracker, functor );
187 else if( Toolkit::Scrollable::SIGNAL_SCROLL_CLAMPED == signalName )
189 scrollable.ScrollClampedSignal().Connect( tracker, functor );
193 // signalName does not match any signal
200 Toolkit::ScrollComponent Scrollable::NewScrollComponent(Toolkit::Scrollable& scrollable, Toolkit::Scrollable::ScrollComponentType type)
202 Toolkit::ScrollComponent instance;
206 case Toolkit::Scrollable::VerticalScrollBar:
208 instance = static_cast<Toolkit::ScrollComponent>(Toolkit::ScrollBarInternal::New(scrollable, true));
211 case Toolkit::Scrollable::HorizontalScrollBar:
213 instance = static_cast<Toolkit::ScrollComponent>(Toolkit::ScrollBarInternal::New(scrollable, false));
218 DALI_ASSERT_ALWAYS(true && "Unrecognized component type");
225 } // namespace Internal
227 } // namespace Toolkit