X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Fscroll-bar%2Fscroll-bar-impl.cpp;h=ff3dbb1f76d5076a6e444f85d898f5a1ab396da0;hp=f9473b93d6d194ae9522d2616659d76ddc7b06e5;hb=f3da11c2818c6d17706fbb2417f21b602b3190f5;hpb=818994dc0acac601b0b27c0b715259b504ef4ceb diff --git a/dali-toolkit/internal/controls/scroll-bar/scroll-bar-impl.cpp b/dali-toolkit/internal/controls/scroll-bar/scroll-bar-impl.cpp index f9473b9..ff3dbb1 100755 --- a/dali-toolkit/internal/controls/scroll-bar/scroll-bar-impl.cpp +++ b/dali-toolkit/internal/controls/scroll-bar/scroll-bar-impl.cpp @@ -1,31 +1,50 @@ -// -// Copyright (c) 2014 Samsung Electronics Co., Ltd. -// -// Licensed under the Flora License, Version 1.0 (the License); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://floralicense.org/license/ -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an AS IS BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// +/* + * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +// CLASS HEADER #include +// EXTERNAL INCLUDES +#include // for strcmp +#include +#include +#include +#include +#include +#include +#include + + +// INTERNAL INCLUDES +#include + using namespace Dali; namespace { const char* DEFAULT_INDICATOR_IMAGE_PATH = DALI_IMAGE_DIR "popup_scroll.png"; -const Vector4 DEFAULT_INDICATOR_NINE_PATCH_BORDER(0.0f, 12.0f, 14.0f, 14.0f); +const Vector4 DEFAULT_INDICATOR_NINE_PATCH_BORDER(4.0f, 9.0f, 7.0f, 11.0f); +const float MINIMUM_INDICATOR_HEIGHT(20.0f); // The minimum indicator height for the nine patch border const float DEFAULT_SLIDER_DEPTH(1.0f); -const float INDICATOR_SHOW_TIME(0.5f); -const float INDICATOR_HIDE_TIME(0.5f); +const float DEFAULT_INDICATOR_SHOW_DURATION(0.5f); +const float DEFAULT_INDICATOR_HIDE_DURATION(0.5f); +const float DEFAULT_PAN_GESTURE_PROCESS_TIME(16.7f); // 16.7 milliseconds, i.e. one frame +const float DEFAULT_INDICATOR_FIXED_HEIGHT(80.0f); /** * Indicator size constraint @@ -33,11 +52,7 @@ const float INDICATOR_HIDE_TIME(0.5f); */ struct IndicatorSizeConstraint { - /** - * @param[in] contentSize The size of scrollable content - */ - IndicatorSizeConstraint(float contentSize) - : mContentSize(contentSize) + IndicatorSizeConstraint() { } @@ -47,15 +62,17 @@ struct IndicatorSizeConstraint * @param[in] parentSizeProperty The parent size of scroll indicator. * @return The new scroll indicator size. */ - Vector3 operator()(const Vector3& current, - const PropertyInput& parentSizeProperty) + void operator()(Vector3& current, const PropertyInputContainer& inputs ) { - const Vector3& parentSize = parentSizeProperty.GetVector3(); - float height = mContentSize > parentSize.height ? parentSize.height * ( parentSize.height / mContentSize ) : parentSize.height * ( (parentSize.height - mContentSize * 0.5f) / parentSize.height); - return Vector3( parentSize.width, height, parentSize.depth ); - } + const Vector3& parentSize = inputs[0]->GetVector3(); + const float contentSize = inputs[1]->GetFloat(); - float mContentSize; ///< The size of scrollable content + float height = contentSize > parentSize.height ? + parentSize.height * ( parentSize.height / contentSize ) : + parentSize.height * ( (parentSize.height - contentSize * 0.5f) / parentSize.height); + + current.y = std::max(MINIMUM_INDICATOR_HEIGHT, height); + } }; /** @@ -68,36 +85,28 @@ struct IndicatorPositionConstraint * @param[in] minPosition The minimum limit of scroll position * @param[in] maxPosition the maximum limit of scroll position */ - IndicatorPositionConstraint(float minPosition, float maxPosition) - : mMinPosition(minPosition), - mMaxPosition(maxPosition) + IndicatorPositionConstraint() { } /** * Constraint operator - * @param[in] current The current indicator position - * @param[in] indicatorSizeProperty The size of indicator. - * @param[in] parentSizeProperty The parent size of indicator. - * @param[in] scrollPositionProperty The scroll position of the scrollable container // (from 0.0 -> 1.0 in each axis) + * @param[in,out] current The current indicator position + * @param[in] inputs Contains the size of indicator, the size of indicator's parent, and the scroll position of the scrollable container (from 0.0 -> 1.0 in each axis) * @return The new indicator position is returned. */ - Vector3 operator()(const Vector3& current, - const PropertyInput& indicatorSizeProperty, - const PropertyInput& parentSizeProperty, - const PropertyInput& scrollPositionProperty) + void operator()( Vector3& current, const PropertyInputContainer& inputs ) { - Vector3 indicatorSize = indicatorSizeProperty.GetVector3(); - Vector3 parentSize = parentSizeProperty.GetVector3(); - float scrollPosition = scrollPositionProperty.GetFloat(); - - const float domainSize = fabs(mMaxPosition - mMinPosition); - float relativePosition = (mMaxPosition - scrollPosition) / domainSize; - return Vector3(current.x, relativePosition * (parentSize.height - indicatorSize.height), DEFAULT_SLIDER_DEPTH); + const Vector3& indicatorSize = inputs[0]->GetVector3(); + const Vector3& parentSize = inputs[1]->GetVector3(); + const float scrollPosition = -inputs[2]->GetFloat(); + const float minScrollPosition = inputs[3]->GetFloat(); + const float maxScrollPosition = inputs[4]->GetFloat(); + + float relativePosition = std::max( 0.0f, std::min( 1.0f, (scrollPosition - minScrollPosition) / (maxScrollPosition - minScrollPosition) ) ); + current.y = ( parentSize.height - indicatorSize.height ) * relativePosition; + current.z = DEFAULT_SLIDER_DEPTH; } - - float mMinPosition; ///< The minimum scroll position - float mMaxPosition; ///< The maximum scroll position }; } // unnamed namespace @@ -118,16 +127,46 @@ using namespace Dali; BaseHandle Create() { - return BaseHandle(); + return Toolkit::ScrollBar::New(); } -TypeRegistration mType( typeid(Toolkit::ScrollBar), typeid(Toolkit::Control), Create ); +// Setup properties, signals and actions using the type-registry. +DALI_TYPE_REGISTRATION_BEGIN( Toolkit::ScrollBar, Toolkit::Control, Create ); + +DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "scrollDirection", STRING, SCROLL_DIRECTION ) +DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "indicatorHeightPolicy", STRING, INDICATOR_HEIGHT_POLICY ) +DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "indicatorFixedHeight", FLOAT, INDICATOR_FIXED_HEIGHT ) +DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "indicatorShowDuration", FLOAT, INDICATOR_SHOW_DURATION ) +DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "indicatorHideDuration", FLOAT, INDICATOR_HIDE_DURATION ) +DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "scrollPositionIntervals", ARRAY, SCROLL_POSITION_INTERVALS ) + +DALI_SIGNAL_REGISTRATION( Toolkit, ScrollBar, "panFinished", PAN_FINISHED_SIGNAL ) +DALI_SIGNAL_REGISTRATION( Toolkit, ScrollBar, "scrollPositionIntervalReached", SCROLL_POSITION_INTERVAL_REACHED_SIGNAL ) + +DALI_TYPE_REGISTRATION_END() + +const char* SCROLL_DIRECTION_NAME[] = {"Vertical", "Horizontal"}; +const char* INDICATOR_HEIGHT_POLICY_NAME[] = {"Variable", "Fixed"}; } -ScrollBar::ScrollBar() -: ControlImpl(true/*requires touch*/), - mScrollStart(0.0f) +ScrollBar::ScrollBar(Toolkit::ScrollBar::Direction direction) +: Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS | REQUIRES_STYLE_CHANGE_SIGNALS ) ), + mIndicatorShowAlpha(1.0f), + mDirection(direction), + mScrollableObject(WeakHandleBase()), + mPropertyScrollPosition(Property::INVALID_INDEX), + mPropertyMinScrollPosition(Property::INVALID_INDEX), + mPropertyMaxScrollPosition(Property::INVALID_INDEX), + mPropertyScrollContentSize(Property::INVALID_INDEX), + mIndicatorShowDuration(DEFAULT_INDICATOR_SHOW_DURATION), + mIndicatorHideDuration(DEFAULT_INDICATOR_HIDE_DURATION), + mScrollStart(0.0f), + mCurrentScrollPosition(0.0f), + mIndicatorHeightPolicy(Toolkit::ScrollBar::Variable), + mIndicatorFixedHeight(DEFAULT_INDICATOR_FIXED_HEIGHT), + mIsPanning(false), + mIndicatorFirstShow(true) { } @@ -137,59 +176,73 @@ ScrollBar::~ScrollBar() void ScrollBar::OnInitialize() { - Actor self = Self(); - - Image indicatorImage = Image::New( DEFAULT_INDICATOR_IMAGE_PATH ); - mIndicator = ImageActor::New( indicatorImage ); - mIndicator.SetNinePatchBorder( DEFAULT_INDICATOR_NINE_PATCH_BORDER ); - mIndicator.SetStyle( ImageActor::STYLE_NINE_PATCH ); - mIndicator.SetParentOrigin( ParentOrigin::TOP_LEFT ); - mIndicator.SetAnchorPoint( AnchorPoint::TOP_LEFT ); - self.Add(mIndicator); - - self.SetDrawMode(DrawMode::OVERLAY); - - // Enable the pan gesture which is attached to the control - EnableGestureDetection(Gesture::Type(Gesture::Pan)); + CreateDefaultIndicatorActor(); + Self().SetDrawMode(DrawMode::OVERLAY_2D); } -void ScrollBar::SetScrollConnector( Toolkit::ScrollConnector connector ) +void ScrollBar::SetScrollPropertySource( Handle handle, Property::Index propertyScrollPosition, Property::Index propertyMinScrollPosition, Property::Index propertyMaxScrollPosition, Property::Index propertyScrollContentSize ) { - if(mScrollConnector) + if( handle + && propertyScrollPosition != Property::INVALID_INDEX + && propertyMinScrollPosition != Property::INVALID_INDEX + && propertyMaxScrollPosition != Property::INVALID_INDEX + && propertyScrollContentSize != Property::INVALID_INDEX ) { - mScrollConnector.DomainChangedSignal().Disconnect(this, &ScrollBar::OnScrollDomainChanged); - } + mScrollableObject = WeakHandleBase(handle); + mPropertyScrollPosition = propertyScrollPosition; + mPropertyMinScrollPosition = propertyMinScrollPosition; + mPropertyMaxScrollPosition = propertyMaxScrollPosition; + mPropertyScrollContentSize = propertyScrollContentSize; - mScrollConnector = connector; - mScrollPositionObject = mScrollConnector.GetScrollPositionObject(); + ApplyConstraints(); + } + else + { + DALI_LOG_ERROR("Can not set empty handle of source object or invalid source property index\n"); + } +} - ApplyConstraints(); - mScrollConnector.DomainChangedSignal().Connect(this, &ScrollBar::OnScrollDomainChanged); +void ScrollBar::CreateDefaultIndicatorActor() +{ + Image indicatorImage = ResourceImage::New( DEFAULT_INDICATOR_IMAGE_PATH ); + ImageActor indicator = ImageActor::New( indicatorImage ); + indicator.SetNinePatchBorder( DEFAULT_INDICATOR_NINE_PATCH_BORDER ); + indicator.SetStyle( ImageActor::STYLE_NINE_PATCH ); + indicator.SetParentOrigin( ParentOrigin::TOP_LEFT ); + indicator.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + + SetScrollIndicator(indicator); } -void ScrollBar::SetBackgroundImage( Image image, const Vector4& border ) +void ScrollBar::SetScrollIndicator( Actor indicator ) { - if (!mBackground ) + // Don't allow empty handle + if( indicator ) { - mBackground = ImageActor::New( image ); - mBackground.SetParentOrigin( ParentOrigin::TOP_LEFT ); - mBackground.SetAnchorPoint( AnchorPoint::TOP_LEFT ); - Self().Add(mBackground); + mIndicator = indicator; + mIndicatorFirstShow = true; + Self().Add(mIndicator); + + EnableGestureDetection(Gesture::Type(Gesture::Pan)); + + PanGestureDetector detector( GetPanGestureDetector() ); + detector.DetachAll(); + detector.Attach( mIndicator ); + + unsigned int childCount = mIndicator.GetChildCount(); + for ( unsigned int index = 0; index < childCount; index++ ) + { + Actor child = mIndicator.GetChildAt( index ); + if ( child ) + { + detector.Attach( child ); + } + } } else { - mBackground.SetImage(image); + DALI_LOG_ERROR("Empty handle of scroll indicator\n"); } - - mBackground.SetNinePatchBorder( border ); - mBackground.SetStyle( ImageActor::STYLE_NINE_PATCH ); -} - -void ScrollBar::SetIndicatorImage( Image image, const Vector4& border ) -{ - mIndicator.SetImage(image); - mIndicator.SetNinePatchBorder( border ); - mIndicator.SetStyle( ImageActor::STYLE_NINE_PATCH ); } Actor ScrollBar::GetScrollIndicator() @@ -199,51 +252,77 @@ Actor ScrollBar::GetScrollIndicator() void ScrollBar::ApplyConstraints() { - mIndicator.RemoveConstraints(); + Handle scrollableHandle = mScrollableObject.GetBaseHandle(); - Constraint constraint = Constraint::New( Actor::SIZE, - ParentSource( Actor::SIZE ), - IndicatorSizeConstraint( mScrollConnector.GetContentLength() ) ); - mIndicator.ApplyConstraint( constraint ); + if( scrollableHandle ) + { + if(mIndicatorSizeConstraint) + { + mIndicatorSizeConstraint.Remove(); + } - constraint = Constraint::New( Actor::POSITION, - LocalSource( Actor::SIZE ), - ParentSource( Actor::SIZE ), - Source( mScrollPositionObject, Toolkit::ScrollConnector::SCROLL_POSITION ), - IndicatorPositionConstraint( mScrollConnector.GetMinLimit(), mScrollConnector.GetMaxLimit() ) ); - mIndicator.ApplyConstraint( constraint ); + // Set indicator height according to the indicator's height policy + if(mIndicatorHeightPolicy == Toolkit::ScrollBar::Fixed) + { + mIndicator.SetSize(Self().GetCurrentSize().width, mIndicatorFixedHeight); + } + else + { + mIndicatorSizeConstraint = Constraint::New( mIndicator, Actor::Property::SIZE, IndicatorSizeConstraint() ); + mIndicatorSizeConstraint.AddSource( ParentSource( Actor::Property::SIZE ) ); + mIndicatorSizeConstraint.AddSource( Source( scrollableHandle, mPropertyScrollContentSize ) ); + mIndicatorSizeConstraint.Apply(); + } - if( mBackground ) - { - mBackground.RemoveConstraints(); + if(mIndicatorPositionConstraint) + { + mIndicatorPositionConstraint.Remove(); + } - constraint = Constraint::New(Actor::SIZE, - ParentSource(Actor::SIZE), - EqualToConstraint()); - mBackground.ApplyConstraint(constraint); + mIndicatorPositionConstraint = Constraint::New( mIndicator, Actor::Property::POSITION, IndicatorPositionConstraint() ); + mIndicatorPositionConstraint.AddSource( LocalSource( Actor::Property::SIZE ) ); + mIndicatorPositionConstraint.AddSource( ParentSource( Actor::Property::SIZE ) ); + mIndicatorPositionConstraint.AddSource( Source( scrollableHandle, mPropertyScrollPosition ) ); + mIndicatorPositionConstraint.AddSource( Source( scrollableHandle, mPropertyMinScrollPosition ) ); + mIndicatorPositionConstraint.AddSource( Source( scrollableHandle, mPropertyMaxScrollPosition ) ); + mIndicatorPositionConstraint.Apply(); } } -void ScrollBar::SetPositionNotifications( const std::vector& positions ) +void ScrollBar::SetScrollPositionIntervals( const Dali::Vector& positions ) { - if(mScrollPositionObject) + mScrollPositionIntervals = positions; + + Handle scrollableHandle = mScrollableObject.GetBaseHandle(); + + if( scrollableHandle ) { - if(mPositionNotification) + if( mPositionNotification ) { - mScrollPositionObject.RemovePropertyNotification(mPositionNotification); + scrollableHandle.RemovePropertyNotification(mPositionNotification); } - mPositionNotification = mScrollPositionObject.AddPropertyNotification( Toolkit::ScrollConnector::SCROLL_POSITION, VariableStepCondition(positions) ); - mPositionNotification.NotifySignal().Connect( this, &ScrollBar::OnScrollPositionNotified ); + + mPositionNotification = scrollableHandle.AddPropertyNotification( mPropertyScrollPosition, VariableStepCondition(mScrollPositionIntervals) ); + mPositionNotification.NotifySignal().Connect( this, &ScrollBar::OnScrollPositionIntervalReached ); } } -void ScrollBar::OnScrollPositionNotified(PropertyNotification& source) +Dali::Vector ScrollBar::GetScrollPositionIntervals() const +{ + return mScrollPositionIntervals; +} + +void ScrollBar::OnScrollPositionIntervalReached(PropertyNotification& source) { // Emit the signal to notify the scroll position crossing - mScrollPositionNotifiedSignal.Emit(mScrollPositionObject.GetProperty( Toolkit::ScrollConnector::SCROLL_POSITION )); + Handle scrollableHandle = mScrollableObject.GetBaseHandle(); + if(scrollableHandle) + { + mScrollPositionIntervalReachedSignal.Emit(scrollableHandle.GetProperty(mPropertyScrollPosition)); + } } -void ScrollBar::Show() +void ScrollBar::ShowIndicator() { // Cancel any animation if(mAnimation) @@ -252,12 +331,26 @@ void ScrollBar::Show() mAnimation.Reset(); } - mAnimation = Animation::New( INDICATOR_SHOW_TIME ); - mAnimation.OpacityTo( Self(), 1.0f, AlphaFunctions::EaseIn ); - mAnimation.Play(); + if( mIndicatorFirstShow ) + { + // Preserve the alpha value from the stylesheet + mIndicatorShowAlpha = Self().GetCurrentColor().a; + mIndicatorFirstShow = false; + } + + if(mIndicatorShowDuration > 0.0f) + { + mAnimation = Animation::New( mIndicatorShowDuration ); + mAnimation.AnimateTo( Property( mIndicator, Actor::Property::COLOR_ALPHA ), mIndicatorShowAlpha, AlphaFunction::EASE_IN ); + mAnimation.Play(); + } + else + { + mIndicator.SetOpacity(mIndicatorShowAlpha); + } } -void ScrollBar::Hide() +void ScrollBar::HideIndicator() { // Cancel any animation if(mAnimation) @@ -266,22 +359,55 @@ void ScrollBar::Hide() mAnimation.Reset(); } - mAnimation = Animation::New( INDICATOR_HIDE_TIME ); - mAnimation.OpacityTo( Self(), 0.0f, AlphaFunctions::EaseIn ); - mAnimation.Play(); + if(mIndicatorHideDuration > 0.0f) + { + mAnimation = Animation::New( mIndicatorHideDuration ); + mAnimation.AnimateTo( Property( mIndicator, Actor::Property::COLOR_ALPHA ), 0.0f, AlphaFunction::EASE_IN ); + mAnimation.Play(); + } + else + { + mIndicator.SetOpacity(0.0f); + } +} + +bool ScrollBar::OnPanGestureProcessTick() +{ + // Update the scroll position property. + Handle scrollableHandle = mScrollableObject.GetBaseHandle(); + if( scrollableHandle ) + { + scrollableHandle.SetProperty(mPropertyScrollPosition, mCurrentScrollPosition); + } + + return true; } -void ScrollBar::OnPan( PanGesture gesture ) +void ScrollBar::OnPan( const PanGesture& gesture ) { - if(mScrollPositionObject) + Handle scrollableHandle = mScrollableObject.GetBaseHandle(); + + if(scrollableHandle) { + Dali::Toolkit::ItemView itemView = Dali::Toolkit::ItemView::DownCast(scrollableHandle); + switch(gesture.state) { case Gesture::Started: { - Show(); - mScrollStart = mScrollPositionObject.GetProperty( Toolkit::ScrollConnector::SCROLL_POSITION ); + if( !mPanProcessTimer ) + { + // Make sure the pan gesture is only being processed once per frame. + mPanProcessTimer = Timer::New( DEFAULT_PAN_GESTURE_PROCESS_TIME ); + mPanProcessTimer.TickSignal().Connect( this, &ScrollBar::OnPanGestureProcessTick ); + mPanProcessTimer.Start(); + } + + ShowIndicator(); + mScrollStart = scrollableHandle.GetProperty(mPropertyScrollPosition); mGestureDisplacement = Vector3::ZERO; + mIsPanning = true; + break; } case Gesture::Continuing: @@ -290,30 +416,285 @@ void ScrollBar::OnPan( PanGesture gesture ) mGestureDisplacement+=delta; Vector3 span = Self().GetCurrentSize() - mIndicator.GetCurrentSize(); - const float domainSize = fabs(mScrollConnector.GetMaxLimit() - mScrollConnector.GetMinLimit()); - float position = mScrollStart - mGestureDisplacement.y * domainSize / span.y; - position = std::min(mScrollConnector.GetMaxLimit(), std::max(position, mScrollConnector.GetMinLimit())); - mScrollPositionObject.SetProperty( Toolkit::ScrollConnector::SCROLL_POSITION, position ); + float minScrollPosition = scrollableHandle.GetProperty(mPropertyMinScrollPosition); + float maxScrollPosition = scrollableHandle.GetProperty(mPropertyMaxScrollPosition); + float domainSize = maxScrollPosition - minScrollPosition; + + mCurrentScrollPosition = mScrollStart - mGestureDisplacement.y * domainSize / span.y; + mCurrentScrollPosition = 0.0f - std::min(maxScrollPosition, std::max(-mCurrentScrollPosition, minScrollPosition)); + break; } default: { + mIsPanning = false; + + if( mPanProcessTimer ) + { + // Destroy the timer when pan gesture is finished. + mPanProcessTimer.Stop(); + mPanProcessTimer.TickSignal().Disconnect( this, &ScrollBar::OnPanGestureProcessTick ); + mPanProcessTimer.Reset(); + } + + if(itemView) + { + // Refresh the ItemView cache with extra items + GetImpl(itemView).DoRefresh(mCurrentScrollPosition, true); + } + + mPanFinishedSignal.Emit(); + break; } } + + if(itemView) + { + // Disable automatic refresh in ItemView during fast scrolling + GetImpl(itemView).SetRefreshEnabled(!mIsPanning); + } + } +} + +void ScrollBar::OnSizeSet( const Vector3& size ) +{ + if(mIndicatorHeightPolicy == Toolkit::ScrollBar::Fixed) + { + mIndicator.SetSize(size.width, mIndicatorFixedHeight); } } -void ScrollBar::OnScrollDomainChanged(float minPosition, float maxPosition, float contentSize) +void ScrollBar::SetScrollDirection( Toolkit::ScrollBar::Direction direction ) { - // Reapply constraints when the scroll domain is changed + mDirection = direction; +} + +Toolkit::ScrollBar::Direction ScrollBar::GetScrollDirection() const +{ + return mDirection; +} + +void ScrollBar::SetIndicatorHeightPolicy( Toolkit::ScrollBar::IndicatorHeightPolicy policy ) +{ + mIndicatorHeightPolicy = policy; ApplyConstraints(); } -Toolkit::ScrollBar ScrollBar::New() +Toolkit::ScrollBar::IndicatorHeightPolicy ScrollBar::GetIndicatorHeightPolicy() const +{ + return mIndicatorHeightPolicy; +} + +void ScrollBar::SetIndicatorFixedHeight( float height ) +{ + mIndicatorFixedHeight = height; + + if(mIndicatorHeightPolicy == Toolkit::ScrollBar::Fixed) + { + mIndicator.SetSize(Self().GetCurrentSize().width, mIndicatorFixedHeight); + } +} + +float ScrollBar::GetIndicatorFixedHeight() const +{ + return mIndicatorFixedHeight; +} + +void ScrollBar::SetIndicatorShowDuration( float durationSeconds ) +{ + mIndicatorShowDuration = durationSeconds; +} + +float ScrollBar::GetIndicatorShowDuration() const +{ + return mIndicatorShowDuration; +} + +void ScrollBar::SetIndicatorHideDuration( float durationSeconds ) +{ + mIndicatorHideDuration = durationSeconds; +} + +float ScrollBar::GetIndicatorHideDuration() const +{ + return mIndicatorHideDuration; +} + +void ScrollBar::OnScrollDirectionPropertySet( Property::Value propertyValue ) +{ + std::string directionName( propertyValue.Get() ); + if(directionName == "Vertical") + { + SetScrollDirection(Toolkit::ScrollBar::Vertical); + } + else if(directionName == "Horizontal") + { + SetScrollDirection(Toolkit::ScrollBar::Horizontal); + } + else + { + DALI_ASSERT_ALWAYS( !"ScrollBar::OnScrollDirectionPropertySet(). Invalid Property value." ); + } +} + +void ScrollBar::OnIndicatorHeightPolicyPropertySet( Property::Value propertyValue ) +{ + std::string policyName( propertyValue.Get() ); + if(policyName == "Variable") + { + SetIndicatorHeightPolicy(Toolkit::ScrollBar::Variable); + } + else if(policyName == "Fixed") + { + SetIndicatorHeightPolicy(Toolkit::ScrollBar::Fixed); + } + else + { + DALI_ASSERT_ALWAYS( !"ScrollBar::OnIndicatorHeightPolicyPropertySet(). Invalid Property value." ); + } +} + +bool ScrollBar::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor ) +{ + Dali::BaseHandle handle( object ); + + bool connected( true ); + Toolkit::ScrollBar scrollBar = Toolkit::ScrollBar::DownCast( handle ); + + if( 0 == strcmp( signalName.c_str(), PAN_FINISHED_SIGNAL ) ) + { + scrollBar.PanFinishedSignal().Connect( tracker, functor ); + } + else if( 0 == strcmp( signalName.c_str(), SCROLL_POSITION_INTERVAL_REACHED_SIGNAL ) ) + { + scrollBar.ScrollPositionIntervalReachedSignal().Connect( tracker, functor ); + } + else + { + // signalName does not match any signal + connected = false; + } + + return connected; +} + +void ScrollBar::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value ) +{ + Toolkit::ScrollBar scrollBar = Toolkit::ScrollBar::DownCast( Dali::BaseHandle( object ) ); + + if( scrollBar ) + { + ScrollBar& scrollBarImpl( GetImpl( scrollBar ) ); + switch( index ) + { + case Toolkit::ScrollBar::Property::SCROLL_DIRECTION: + { + scrollBarImpl.OnScrollDirectionPropertySet( value ); + break; + } + case Toolkit::ScrollBar::Property::INDICATOR_HEIGHT_POLICY: + { + scrollBarImpl.OnIndicatorHeightPolicyPropertySet( value ); + break; + } + case Toolkit::ScrollBar::Property::INDICATOR_FIXED_HEIGHT: + { + scrollBarImpl.SetIndicatorFixedHeight(value.Get()); + break; + } + case Toolkit::ScrollBar::Property::INDICATOR_SHOW_DURATION: + { + scrollBarImpl.SetIndicatorShowDuration(value.Get()); + break; + } + case Toolkit::ScrollBar::Property::INDICATOR_HIDE_DURATION: + { + scrollBarImpl.SetIndicatorHideDuration(value.Get()); + break; + } + case Toolkit::ScrollBar::Property::SCROLL_POSITION_INTERVALS: + { + Property::Array* array = value.GetArray(); + if( array ) + { + Dali::Vector positions; + size_t positionCount = array->Count(); + positions.Resize( positionCount ); + for( size_t i = 0; i != positionCount; ++i ) + { + array->GetElementAt( i ).Get( positions[i] ); + } + + scrollBarImpl.SetScrollPositionIntervals(positions); + } + break; + } + } + } +} + +Property::Value ScrollBar::GetProperty( BaseObject* object, Property::Index index ) +{ + Property::Value value; + + Toolkit::ScrollBar scrollBar = Toolkit::ScrollBar::DownCast( Dali::BaseHandle( object ) ); + + if( scrollBar ) + { + ScrollBar& scrollBarImpl( GetImpl( scrollBar ) ); + switch( index ) + { + case Toolkit::ScrollBar::Property::SCROLL_DIRECTION: + { + value = SCROLL_DIRECTION_NAME[ scrollBarImpl.GetScrollDirection() ]; + break; + } + case Toolkit::ScrollBar::Property::INDICATOR_HEIGHT_POLICY: + { + value = INDICATOR_HEIGHT_POLICY_NAME[ scrollBarImpl.GetIndicatorHeightPolicy() ]; + break; + } + case Toolkit::ScrollBar::Property::INDICATOR_FIXED_HEIGHT: + { + value = scrollBarImpl.GetIndicatorFixedHeight(); + break; + } + case Toolkit::ScrollBar::Property::INDICATOR_SHOW_DURATION: + { + value = scrollBarImpl.GetIndicatorShowDuration(); + break; + } + case Toolkit::ScrollBar::Property::INDICATOR_HIDE_DURATION: + { + value = scrollBarImpl.GetIndicatorHideDuration(); + break; + } + case Toolkit::ScrollBar::Property::SCROLL_POSITION_INTERVALS: + { + Property::Value value( Property::ARRAY ); + Property::Array* array = value.GetArray(); + + if( array ) + { + Dali::Vector positions = scrollBarImpl.GetScrollPositionIntervals(); + size_t positionCount( array->Count() ); + for( size_t i( 0 ); i != positionCount; ++i ) + { + array->PushBack( positions[i] ); + } + } + break; + } + } + } + return value; +} + +Toolkit::ScrollBar ScrollBar::New(Toolkit::ScrollBar::Direction direction) { // Create the implementation, temporarily owned by this handle on stack - IntrusivePtr< ScrollBar > impl = new ScrollBar(); + IntrusivePtr< ScrollBar > impl = new ScrollBar(direction); // Pass ownership to CustomActor handle Toolkit::ScrollBar handle( *impl );