Updates after Handle/Constrainable merge
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / scroll-bar / scroll-bar-impl.cpp
index 1191db6..55a86e2 100755 (executable)
 #include <dali-toolkit/internal/controls/scroll-bar/scroll-bar-impl.h>
 
 // EXTERNAL INCLUDES
+#include <dali/public-api/animation/constraint.h>
 #include <dali/public-api/animation/constraints.h>
 #include <dali/public-api/object/type-registry.h>
+#include <dali/public-api/images/resource-image.h>
 
 // INTERNAL INCLUDES
 #include <dali-toolkit/internal/controls/scrollable/item-view/item-view-impl.h>
@@ -40,35 +42,15 @@ const float DEFAULT_PAN_GESTURE_PROCESS_TIME(16.7f); // 16.7 milliseconds, i.e.
 const float DEFAULT_INDICATOR_FIXED_HEIGHT(80.0f);
 
 /**
- * Indicator size constraint
  * Indicator size depends on both indicator's parent size and the scroll content size
  */
-struct IndicatorSizeConstraint
+Vector3 IndicatorSize( const Vector3& parentSize, float contentSize)
 {
-  /**
-   * @param[in] contentSize The size of scrollable content
-   */
-  IndicatorSizeConstraint(float contentSize)
-  : mContentSize(contentSize)
-  {
-  }
-
-  /**
-   * Constraint operator
-   * @param[in] current The current indicator size
-   * @param[in] parentSizeProperty The parent size of scroll indicator.
-   * @return The new scroll indicator size.
-   */
-  Vector3 operator()(const Vector3& current,
-                     const PropertyInput& parentSizeProperty)
-  {
-    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, std::max(MINIMUM_INDICATOR_HEIGHT, height), parentSize.depth );
-  }
-
-  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);
+  return Vector3( parentSize.width, std::max(MINIMUM_INDICATOR_HEIGHT, height), parentSize.depth );
+}
 
 /**
  * Indicator position constraint
@@ -140,7 +122,9 @@ BaseHandle Create()
   return Toolkit::ScrollBar::New();
 }
 
-TypeRegistration typeRegistration( typeid(Toolkit::ScrollBar), typeid(Toolkit::ScrollComponent), Create );
+TypeRegistration typeRegistration( typeid( Toolkit::ScrollBar ), typeid( Toolkit::ScrollComponent ), Create );
+
+const char* const SCROLL_POSITION_NOTIFIED_SIGNAL_NAME = "scroll-position-notified";
 
 PropertyRegistration property1( typeRegistration, "indicator-height-policy", Toolkit::ScrollBar::PROPERTY_INDICATOR_HEIGHT_POLICY, Property::STRING, &ScrollBar::SetProperty, &ScrollBar::GetProperty );
 PropertyRegistration property2( typeRegistration, "indicator-fixed-height",  Toolkit::ScrollBar::PROPERTY_INDICATOR_FIXED_HEIGHT,  Property::FLOAT,  &ScrollBar::SetProperty, &ScrollBar::GetProperty );
@@ -168,7 +152,7 @@ void ScrollBar::OnInitialize()
 {
   Actor self = Self();
 
-  Image indicatorImage = Image::New( DEFAULT_INDICATOR_IMAGE_PATH );
+  Image indicatorImage = ResourceImage::New( DEFAULT_INDICATOR_IMAGE_PATH );
   mIndicator = ImageActor::New( indicatorImage );
   mIndicator.SetNinePatchBorder( DEFAULT_INDICATOR_NINE_PATCH_BORDER );
   mIndicator.SetStyle( ImageActor::STYLE_NINE_PATCH );
@@ -228,10 +212,7 @@ void ScrollBar::ApplyConstraints()
     }
     else
     {
-      constraint = Constraint::New<Vector3>( Actor::SIZE,
-                                             ParentSource( Actor::SIZE ),
-                                             IndicatorSizeConstraint( mScrollConnector.GetContentLength() ) );
-      mIndicatorSizeConstraint = mIndicator.ApplyConstraint( constraint );
+      mIndicator.SetSize( IndicatorSize( Self().GetCurrentSize(), mScrollConnector.GetContentLength() ) );
     }
 
     if(mIndicatorPositionConstraint)
@@ -245,16 +226,6 @@ void ScrollBar::ApplyConstraints()
                                            Source( mScrollPositionObject, Toolkit::ScrollConnector::SCROLL_POSITION ),
                                            IndicatorPositionConstraint( mScrollConnector.GetMinLimit(), mScrollConnector.GetMaxLimit() ) );
     mIndicatorPositionConstraint = mIndicator.ApplyConstraint( constraint );
-
-    if( mBackground )
-    {
-      mBackground.RemoveConstraints();
-
-      constraint = Constraint::New<Vector3>(Actor::SIZE,
-                                            ParentSource(Actor::SIZE),
-                                            EqualToConstraint());
-      mBackground.ApplyConstraint(constraint);
-    }
   }
 }
 
@@ -397,6 +368,14 @@ void ScrollBar::OnPan( PanGesture gesture )
   }
 }
 
+void ScrollBar::OnControlSizeSet( const Vector3& size )
+{
+  if(mIndicatorHeightPolicy != Toolkit::ScrollBar::Fixed && mScrollConnector)
+  {
+    mIndicator.SetSize( IndicatorSize( size, mScrollConnector.GetContentLength() ) );
+  }
+}
+
 void ScrollBar::OnScrollDomainChanged(float minPosition, float maxPosition, float contentSize)
 {
   // Reapply constraints when the scroll domain is changed
@@ -462,6 +441,26 @@ void ScrollBar::OnIndicatorHeightPolicyPropertySet( Property::Value propertyValu
   }
 }
 
+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(), SCROLL_POSITION_NOTIFIED_SIGNAL_NAME ) )
+  {
+    scrollBar.ScrollPositionNotifiedSignal().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 ) );