Preserve the ScrollBar alpha value from the stylesheet
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / scroll-bar / scroll-bar-impl.cpp
index 350ace5..f92f721 100755 (executable)
@@ -152,8 +152,9 @@ const char* INDICATOR_HEIGHT_POLICY_NAME[] = {"Variable", "Fixed"};
 
 ScrollBar::ScrollBar(Toolkit::ScrollBar::Direction direction)
 : Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS | REQUIRES_STYLE_CHANGE_SIGNALS ) ),
+  mIndicatorShowAlpha(1.0f),
   mDirection(direction),
-  mScrollableObject(Handle()),
+  mScrollableObject(WeakHandleBase()),
   mPropertyScrollPosition(Property::INVALID_INDEX),
   mPropertyMinScrollPosition(Property::INVALID_INDEX),
   mPropertyMaxScrollPosition(Property::INVALID_INDEX),
@@ -161,10 +162,11 @@ ScrollBar::ScrollBar(Toolkit::ScrollBar::Direction direction)
   mIndicatorShowDuration(DEFAULT_INDICATOR_SHOW_DURATION),
   mIndicatorHideDuration(DEFAULT_INDICATOR_HIDE_DURATION),
   mScrollStart(0.0f),
-  mIsPanning(false),
   mCurrentScrollPosition(0.0f),
   mIndicatorHeightPolicy(Toolkit::ScrollBar::Variable),
-  mIndicatorFixedHeight(DEFAULT_INDICATOR_FIXED_HEIGHT)
+  mIndicatorFixedHeight(DEFAULT_INDICATOR_FIXED_HEIGHT),
+  mIsPanning(false),
+  mIndicatorFirstShow(true)
 {
 }
 
@@ -186,7 +188,7 @@ void ScrollBar::SetScrollPropertySource( Handle handle, Property::Index property
       && propertyMaxScrollPosition != Property::INVALID_INDEX
       && propertyScrollContentSize != Property::INVALID_INDEX )
   {
-    mScrollableObject = handle;
+    mScrollableObject = WeakHandleBase(handle);
     mPropertyScrollPosition = propertyScrollPosition;
     mPropertyMinScrollPosition = propertyMinScrollPosition;
     mPropertyMaxScrollPosition = propertyMaxScrollPosition;
@@ -218,6 +220,7 @@ void ScrollBar::SetScrollIndicator( Actor indicator )
   if( indicator )
   {
     mIndicator = indicator;
+    mIndicatorFirstShow = true;
     Self().Add(mIndicator);
 
     EnableGestureDetection(Gesture::Type(Gesture::Pan));
@@ -249,7 +252,9 @@ Actor ScrollBar::GetScrollIndicator()
 
 void ScrollBar::ApplyConstraints()
 {
-  if( mScrollableObject )
+  Handle scrollableHandle = mScrollableObject.GetBaseHandle();
+
+  if( scrollableHandle )
   {
     if(mIndicatorSizeConstraint)
     {
@@ -265,7 +270,7 @@ void ScrollBar::ApplyConstraints()
     {
       mIndicatorSizeConstraint = Constraint::New<Vector3>( mIndicator, Actor::Property::SIZE, IndicatorSizeConstraint() );
       mIndicatorSizeConstraint.AddSource( ParentSource( Actor::Property::SIZE ) );
-      mIndicatorSizeConstraint.AddSource( Source( mScrollableObject, mPropertyScrollContentSize ) );
+      mIndicatorSizeConstraint.AddSource( Source( scrollableHandle, mPropertyScrollContentSize ) );
       mIndicatorSizeConstraint.Apply();
     }
 
@@ -277,9 +282,9 @@ void ScrollBar::ApplyConstraints()
     mIndicatorPositionConstraint = Constraint::New<Vector3>( mIndicator, Actor::Property::POSITION, IndicatorPositionConstraint() );
     mIndicatorPositionConstraint.AddSource( LocalSource( Actor::Property::SIZE ) );
     mIndicatorPositionConstraint.AddSource( ParentSource( Actor::Property::SIZE ) );
-    mIndicatorPositionConstraint.AddSource( Source( mScrollableObject, mPropertyScrollPosition ) );
-    mIndicatorPositionConstraint.AddSource( Source( mScrollableObject, mPropertyMinScrollPosition ) );
-    mIndicatorPositionConstraint.AddSource( Source( mScrollableObject, mPropertyMaxScrollPosition ) );
+    mIndicatorPositionConstraint.AddSource( Source( scrollableHandle, mPropertyScrollPosition ) );
+    mIndicatorPositionConstraint.AddSource( Source( scrollableHandle, mPropertyMinScrollPosition ) );
+    mIndicatorPositionConstraint.AddSource( Source( scrollableHandle, mPropertyMaxScrollPosition ) );
     mIndicatorPositionConstraint.Apply();
   }
 }
@@ -288,14 +293,16 @@ void ScrollBar::SetScrollPositionIntervals( const Dali::Vector<float>& positions
 {
   mScrollPositionIntervals = positions;
 
-  if( mScrollableObject )
+  Handle scrollableHandle = mScrollableObject.GetBaseHandle();
+
+  if( scrollableHandle )
   {
     if( mPositionNotification )
     {
-      mScrollableObject.RemovePropertyNotification(mPositionNotification);
+      scrollableHandle.RemovePropertyNotification(mPositionNotification);
     }
 
-    mPositionNotification = mScrollableObject.AddPropertyNotification( mPropertyScrollPosition, VariableStepCondition(mScrollPositionIntervals) );
+    mPositionNotification = scrollableHandle.AddPropertyNotification( mPropertyScrollPosition, VariableStepCondition(mScrollPositionIntervals) );
     mPositionNotification.NotifySignal().Connect( this, &ScrollBar::OnScrollPositionIntervalReached );
   }
 }
@@ -308,9 +315,10 @@ Dali::Vector<float> ScrollBar::GetScrollPositionIntervals() const
 void ScrollBar::OnScrollPositionIntervalReached(PropertyNotification& source)
 {
   // Emit the signal to notify the scroll position crossing
-  if(mScrollableObject)
+  Handle scrollableHandle = mScrollableObject.GetBaseHandle();
+  if(scrollableHandle)
   {
-    mScrollPositionIntervalReachedSignal.Emit(mScrollableObject.GetProperty<float>(mPropertyScrollPosition));
+    mScrollPositionIntervalReachedSignal.Emit(scrollableHandle.GetProperty<float>(mPropertyScrollPosition));
   }
 }
 
@@ -323,15 +331,22 @@ void ScrollBar::ShowIndicator()
     mAnimation.Reset();
   }
 
+  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 ), 1.0f, AlphaFunction::EASE_IN );
+    mAnimation.AnimateTo( Property( mIndicator, Actor::Property::COLOR_ALPHA ), mIndicatorShowAlpha, AlphaFunction::EASE_IN );
     mAnimation.Play();
   }
   else
   {
-    mIndicator.SetOpacity(1.0f);
+    mIndicator.SetOpacity(mIndicatorShowAlpha);
   }
 }
 
@@ -359,9 +374,10 @@ void ScrollBar::HideIndicator()
 bool ScrollBar::OnPanGestureProcessTick()
 {
   // Update the scroll position property.
-  if( mScrollableObject )
+  Handle scrollableHandle = mScrollableObject.GetBaseHandle();
+  if( scrollableHandle )
   {
-    mScrollableObject.SetProperty(mPropertyScrollPosition, mCurrentScrollPosition);
+    scrollableHandle.SetProperty(mPropertyScrollPosition, mCurrentScrollPosition);
   }
 
   return true;
@@ -369,9 +385,11 @@ bool ScrollBar::OnPanGestureProcessTick()
 
 void ScrollBar::OnPan( const PanGesture& gesture )
 {
-  if(mScrollableObject)
+  Handle scrollableHandle = mScrollableObject.GetBaseHandle();
+
+  if(scrollableHandle)
   {
-    Dali::Toolkit::ItemView itemView = Dali::Toolkit::ItemView::DownCast(mScrollableObject);
+    Dali::Toolkit::ItemView itemView = Dali::Toolkit::ItemView::DownCast(scrollableHandle);
 
     switch(gesture.state)
     {
@@ -386,7 +404,7 @@ void ScrollBar::OnPan( const PanGesture& gesture )
         }
 
         ShowIndicator();
-        mScrollStart = mScrollableObject.GetProperty<float>(mPropertyScrollPosition);
+        mScrollStart = scrollableHandle.GetProperty<float>(mPropertyScrollPosition);
         mGestureDisplacement = Vector3::ZERO;
         mIsPanning = true;
 
@@ -398,8 +416,8 @@ void ScrollBar::OnPan( const PanGesture& gesture )
         mGestureDisplacement+=delta;
 
         Vector3 span = Self().GetCurrentSize() - mIndicator.GetCurrentSize();
-        float minScrollPosition = mScrollableObject.GetProperty<float>(mPropertyMinScrollPosition);
-        float maxScrollPosition = mScrollableObject.GetProperty<float>(mPropertyMaxScrollPosition);
+        float minScrollPosition = scrollableHandle.GetProperty<float>(mPropertyMinScrollPosition);
+        float maxScrollPosition = scrollableHandle.GetProperty<float>(mPropertyMaxScrollPosition);
         float domainSize = maxScrollPosition - minScrollPosition;
 
         mCurrentScrollPosition = mScrollStart - mGestureDisplacement.y * domainSize / span.y;
@@ -434,7 +452,7 @@ void ScrollBar::OnPan( const PanGesture& gesture )
     if(itemView)
     {
       // Disable automatic refresh in ItemView during fast scrolling
-      GetImpl(itemView).SetRefreshEnabled(true);//!mIsPanning);
+      GetImpl(itemView).SetRefreshEnabled(!mIsPanning);
     }
   }
 }
@@ -656,11 +674,15 @@ Property::Value ScrollBar::GetProperty( BaseObject* object, Property::Index inde
       {
         Property::Value value( Property::ARRAY );
         Property::Array* array = value.GetArray();
-        Dali::Vector<float> positions = scrollBarImpl.GetScrollPositionIntervals();
-        size_t positionCount( array->Count() );
-        for( size_t i( 0 ); i != positionCount; ++i )
+
+        if( array )
         {
-          array->PushBack( positions[i] );
+          Dali::Vector<float> positions = scrollBarImpl.GetScrollPositionIntervals();
+          size_t positionCount( array->Count() );
+          for( size_t i( 0 ); i != positionCount; ++i )
+          {
+            array->PushBack( positions[i] );
+          }
         }
         break;
       }