Fix compile error. Non initialized variable.
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / scroll-bar / scroll-bar-impl.cpp
old mode 100755 (executable)
new mode 100644 (file)
index 5adc065..c588487
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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.
 #include <cstring> // for strcmp
 #include <dali/public-api/animation/constraint.h>
 #include <dali/public-api/animation/constraints.h>
-#include <dali/public-api/images/resource-image.h>
 #include <dali/public-api/object/type-registry.h>
 #include <dali/public-api/object/property-array.h>
 #include <dali/public-api/object/type-registry-helper.h>
 #include <dali/integration-api/debug.h>
 #include <dali/devel-api/object/property-helper-devel.h>
+#include <dali/devel-api/actors/actor-devel.h>
 
 // INTERNAL INCLUDES
+#include <dali-toolkit/devel-api/asset-manager/asset-manager.h>
 #include <dali-toolkit/internal/controls/scrollable/item-view/item-view-impl.h>
 #include <dali-toolkit/public-api/controls/image-view/image-view.h>
-#include <dali-toolkit/devel-api/controls/scroll-bar/scroll-bar-devel.h>
 
 using namespace Dali;
 
 namespace
 {
 
-const char* DEFAULT_INDICATOR_IMAGE_PATH = DALI_IMAGE_DIR "popup_scroll.9.png";
+const char* DEFAULT_INDICATOR_IMAGE_FILE_NAME = "popup_scroll.9.png";
 const float DEFAULT_SLIDER_DEPTH(1.0f);
 const float DEFAULT_INDICATOR_SHOW_DURATION(0.5f);
 const float DEFAULT_INDICATOR_HIDE_DURATION(0.5f);
@@ -166,8 +166,7 @@ DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "scrollPositionIntervals",
 DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "indicatorMinimumHeight",            FLOAT,  INDICATOR_MINIMUM_HEIGHT     )
 DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "indicatorStartPadding",             FLOAT,  INDICATOR_START_PADDING      )
 DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "indicatorEndPadding",               FLOAT,  INDICATOR_END_PADDING        )
-
-DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "indicatorTransientDuration", FLOAT,  INDICATOR_TRANSIENT_DURATION )
+DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "indicatorTransientDuration",        FLOAT,  INDICATOR_TRANSIENT_DURATION )
 
 DALI_SIGNAL_REGISTRATION(   Toolkit, ScrollBar, "panFinished",                       PAN_FINISHED_SIGNAL                     )
 DALI_SIGNAL_REGISTRATION(   Toolkit, ScrollBar, "scrollPositionIntervalReached",     SCROLL_POSITION_INTERVAL_REACHED_SIGNAL )
@@ -178,8 +177,8 @@ DALI_ACTION_REGISTRATION(   Toolkit, ScrollBar, "ShowTransientIndicator",
 
 DALI_TYPE_REGISTRATION_END()
 
-const char* SCROLL_DIRECTION_NAME[] = {"Vertical", "Horizontal"};
-const char* INDICATOR_HEIGHT_POLICY_NAME[] = {"Variable", "Fixed"};
+const char* SCROLL_DIRECTION_NAME[] = {"VERTICAL", "HORIZONTAL"};
+const char* INDICATOR_HEIGHT_POLICY_NAME[] = {"VARIABLE", "FIXED"};
 
 }
 
@@ -187,7 +186,7 @@ ScrollBar::ScrollBar(Toolkit::ScrollBar::Direction direction)
 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
   mIndicatorShowAlpha(1.0f),
   mDirection(direction),
-  mScrollableObject(WeakHandleBase()),
+  mScrollableObject(WeakHandle<Handle>()),
   mPropertyScrollPosition(Property::INVALID_INDEX),
   mPropertyMinScrollPosition(Property::INVALID_INDEX),
   mPropertyMaxScrollPosition(Property::INVALID_INDEX),
@@ -196,8 +195,9 @@ ScrollBar::ScrollBar(Toolkit::ScrollBar::Direction direction)
   mIndicatorHideDuration(DEFAULT_INDICATOR_HIDE_DURATION),
   mTransientIndicatorDuration(DEFAULT_INDICATOR_TRANSIENT_DURATION),
   mScrollStart(0.0f),
+  mGestureDisplacement( Vector2::ZERO ),
   mCurrentScrollPosition(0.0f),
-  mIndicatorHeightPolicy(Toolkit::ScrollBar::Variable),
+  mIndicatorHeightPolicy(Toolkit::ScrollBar::VARIABLE),
   mIndicatorFixedHeight(DEFAULT_INDICATOR_FIXED_HEIGHT),
   mIndicatorMinimumHeight(DEFAULT_INDICATOR_MINIMUM_HEIGHT),
   mIndicatorStartPadding(DEFAULT_INDICATOR_START_PADDING),
@@ -214,7 +214,7 @@ ScrollBar::~ScrollBar()
 void ScrollBar::OnInitialize()
 {
   CreateDefaultIndicatorActor();
-  Self().SetDrawMode(DrawMode::OVERLAY_2D);
+  Self().SetProperty( Actor::Property::DRAW_MODE,DrawMode::OVERLAY_2D);
 }
 
 void ScrollBar::SetScrollPropertySource( Handle handle, Property::Index propertyScrollPosition, Property::Index propertyMinScrollPosition, Property::Index propertyMaxScrollPosition, Property::Index propertyScrollContentSize )
@@ -225,7 +225,7 @@ void ScrollBar::SetScrollPropertySource( Handle handle, Property::Index property
       && propertyMaxScrollPosition != Property::INVALID_INDEX
       && propertyScrollContentSize != Property::INVALID_INDEX )
   {
-    mScrollableObject = WeakHandleBase(handle);
+    mScrollableObject = WeakHandle<Handle>(handle);
     mPropertyScrollPosition = propertyScrollPosition;
     mPropertyMinScrollPosition = propertyMinScrollPosition;
     mPropertyMaxScrollPosition = propertyMaxScrollPosition;
@@ -241,11 +241,12 @@ void ScrollBar::SetScrollPropertySource( Handle handle, Property::Index property
 
 void ScrollBar::CreateDefaultIndicatorActor()
 {
-  Toolkit::ImageView indicator = Toolkit::ImageView::New( DEFAULT_INDICATOR_IMAGE_PATH );
-  indicator.SetParentOrigin( ParentOrigin::TOP_LEFT );
-  indicator.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+  const std::string imageDirPath = AssetManager::GetDaliImagePath();
+  Toolkit::ImageView indicator = Toolkit::ImageView::New( imageDirPath + DEFAULT_INDICATOR_IMAGE_FILE_NAME );
+  indicator.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
+  indicator.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
   indicator.SetStyleName( "ScrollBarIndicator" );
-  indicator.SetColorMode( USE_OWN_MULTIPLY_PARENT_COLOR );
+  indicator.SetProperty( Actor::Property::COLOR_MODE, USE_OWN_MULTIPLY_PARENT_COLOR );
   SetScrollIndicator(indicator);
 }
 
@@ -293,7 +294,7 @@ Actor ScrollBar::GetScrollIndicator()
 
 void ScrollBar::ApplyConstraints()
 {
-  Handle scrollableHandle = mScrollableObject.GetBaseHandle();
+  Handle scrollableHandle = mScrollableObject.GetHandle();
 
   if( scrollableHandle )
   {
@@ -303,9 +304,9 @@ void ScrollBar::ApplyConstraints()
     }
 
     // Set indicator height according to the indicator's height policy
-    if(mIndicatorHeightPolicy == Toolkit::ScrollBar::Fixed)
+    if(mIndicatorHeightPolicy == Toolkit::ScrollBar::FIXED)
     {
-      mIndicator.SetSize(Self().GetCurrentSize().width, mIndicatorFixedHeight);
+      mIndicator.SetProperty( Actor::Property::SIZE, Vector2( Self().GetCurrentProperty< Vector3 >( Actor::Property::SIZE ).width, mIndicatorFixedHeight) );
     }
     else
     {
@@ -336,7 +337,7 @@ void ScrollBar::SetScrollPositionIntervals( const Dali::Vector<float>& positions
 {
   mScrollPositionIntervals = positions;
 
-  Handle scrollableHandle = mScrollableObject.GetBaseHandle();
+  Handle scrollableHandle = mScrollableObject.GetHandle();
 
   if( scrollableHandle )
   {
@@ -358,10 +359,10 @@ Dali::Vector<float> ScrollBar::GetScrollPositionIntervals() const
 void ScrollBar::OnScrollPositionIntervalReached(PropertyNotification& source)
 {
   // Emit the signal to notify the scroll position crossing
-  Handle scrollableHandle = mScrollableObject.GetBaseHandle();
+  Handle scrollableHandle = mScrollableObject.GetHandle();
   if(scrollableHandle)
   {
-    mScrollPositionIntervalReachedSignal.Emit(scrollableHandle.GetProperty<float>(mPropertyScrollPosition));
+    mScrollPositionIntervalReachedSignal.Emit( scrollableHandle.GetCurrentProperty< float >( mPropertyScrollPosition ) );
   }
 }
 
@@ -377,7 +378,7 @@ void ScrollBar::ShowIndicator()
   if( mIndicatorFirstShow )
   {
     // Preserve the alpha value from the stylesheet
-    mIndicatorShowAlpha = Self().GetCurrentColor().a;
+    mIndicatorShowAlpha = Self().GetCurrentProperty< Vector4 >( Actor::Property::COLOR ).a;
     mIndicatorFirstShow = false;
   }
 
@@ -389,7 +390,7 @@ void ScrollBar::ShowIndicator()
   }
   else
   {
-    mIndicator.SetOpacity(mIndicatorShowAlpha);
+    mIndicator.SetProperty( Actor::Property::OPACITY,mIndicatorShowAlpha);
   }
 }
 
@@ -410,7 +411,7 @@ void ScrollBar::HideIndicator()
   }
   else
   {
-    mIndicator.SetOpacity(0.0f);
+    mIndicator.SetProperty( Actor::Property::OPACITY,0.0f);
   }
 }
 
@@ -431,7 +432,7 @@ void ScrollBar::ShowTransientIndicator()
   }
   else
   {
-    mIndicator.SetOpacity(mIndicatorShowAlpha);
+    mIndicator.SetProperty( Actor::Property::OPACITY,mIndicatorShowAlpha);
   }
   mAnimation.AnimateTo( Property( mIndicator, Actor::Property::COLOR_ALPHA ),
                         0.0f, AlphaFunction::EASE_IN, TimePeriod((mIndicatorShowDuration + mTransientIndicatorDuration), mIndicatorHideDuration) );
@@ -441,7 +442,7 @@ void ScrollBar::ShowTransientIndicator()
 bool ScrollBar::OnPanGestureProcessTick()
 {
   // Update the scroll position property.
-  Handle scrollableHandle = mScrollableObject.GetBaseHandle();
+  Handle scrollableHandle = mScrollableObject.GetHandle();
   if( scrollableHandle )
   {
     scrollableHandle.SetProperty(mPropertyScrollPosition, mCurrentScrollPosition);
@@ -452,15 +453,15 @@ bool ScrollBar::OnPanGestureProcessTick()
 
 void ScrollBar::OnPan( const PanGesture& gesture )
 {
-  Handle scrollableHandle = mScrollableObject.GetBaseHandle();
+  Handle scrollableHandle = mScrollableObject.GetHandle();
 
   if(scrollableHandle)
   {
     Dali::Toolkit::ItemView itemView = Dali::Toolkit::ItemView::DownCast(scrollableHandle);
 
-    switch(gesture.state)
+    switch(gesture.GetState())
     {
-      case Gesture::Started:
+      case Dali::Gesture::Started:
       {
         if( !mPanProcessTimer )
         {
@@ -471,23 +472,22 @@ void ScrollBar::OnPan( const PanGesture& gesture )
         }
 
         ShowIndicator();
-        mScrollStart = scrollableHandle.GetProperty<float>(mPropertyScrollPosition);
-        mGestureDisplacement = Vector3::ZERO;
+        mScrollStart = scrollableHandle.GetCurrentProperty< float >( mPropertyScrollPosition );
+        mGestureDisplacement = Vector2::ZERO;
         mIsPanning = true;
 
         break;
       }
-      case Gesture::Continuing:
+      case Dali::Gesture::Continuing:
       {
-        mGestureDisplacement.x += gesture.displacement.x;
-        mGestureDisplacement.y += gesture.displacement.y;
+        mGestureDisplacement += gesture.GetDisplacement();
 
-        float minScrollPosition = scrollableHandle.GetProperty<float>( mPropertyMinScrollPosition );
-        float maxScrollPosition = scrollableHandle.GetProperty<float>( mPropertyMaxScrollPosition );
+        float minScrollPosition = scrollableHandle.GetCurrentProperty<float>( mPropertyMinScrollPosition );
+        float maxScrollPosition = scrollableHandle.GetCurrentProperty<float>( mPropertyMaxScrollPosition );
 
         // The domain size is the internal range
         float domainSize = maxScrollPosition - minScrollPosition;
-        float logicalSize = Self().GetCurrentSize().y - ( mIndicator.GetCurrentSize().y + mIndicatorStartPadding + mIndicatorEndPadding );
+        float logicalSize = Self().GetCurrentProperty< Vector3 >( Actor::Property::SIZE ).y - ( mIndicator.GetCurrentProperty< Vector3 >( Actor::Property::SIZE ).y + mIndicatorStartPadding + mIndicatorEndPadding );
 
         mCurrentScrollPosition = mScrollStart - ( ( mGestureDisplacement.y * domainSize ) / logicalSize );
         mCurrentScrollPosition = -std::min( maxScrollPosition, std::max( -mCurrentScrollPosition, minScrollPosition ) );
@@ -528,9 +528,9 @@ void ScrollBar::OnPan( const PanGesture& gesture )
 
 void ScrollBar::OnSizeSet( const Vector3& size )
 {
-  if(mIndicatorHeightPolicy == Toolkit::ScrollBar::Fixed)
+  if(mIndicatorHeightPolicy == Toolkit::ScrollBar::FIXED)
   {
-    mIndicator.SetSize(size.width, mIndicatorFixedHeight);
+    mIndicator.SetProperty( Actor::Property::SIZE, Vector2( size.width, mIndicatorFixedHeight ) );
   }
 
   Control::OnSizeSet( size );
@@ -564,9 +564,9 @@ void ScrollBar::SetIndicatorFixedHeight( float height )
 {
   mIndicatorFixedHeight = height;
 
-  if(mIndicatorHeightPolicy == Toolkit::ScrollBar::Fixed)
+  if(mIndicatorHeightPolicy == Toolkit::ScrollBar::FIXED)
   {
-    mIndicator.SetSize(Self().GetCurrentSize().width, mIndicatorFixedHeight);
+    mIndicator.SetProperty( Actor::Property::SIZE, Vector2( Self().GetCurrentProperty< Vector3 >( Actor::Property::SIZE ).width, mIndicatorFixedHeight) );
   }
 }
 
@@ -598,13 +598,13 @@ float ScrollBar::GetIndicatorHideDuration() const
 void ScrollBar::OnScrollDirectionPropertySet( Property::Value propertyValue )
 {
   std::string directionName( propertyValue.Get<std::string>() );
-  if(directionName == "Vertical")
+  if(directionName == "VERTICAL")
   {
-    SetScrollDirection(Toolkit::ScrollBar::Vertical);
+    SetScrollDirection(Toolkit::ScrollBar::VERTICAL);
   }
-  else if(directionName == "Horizontal")
+  else if(directionName == "HORIZONTAL")
   {
-    SetScrollDirection(Toolkit::ScrollBar::Horizontal);
+    SetScrollDirection(Toolkit::ScrollBar::HORIZONTAL);
   }
   else
   {
@@ -615,13 +615,13 @@ void ScrollBar::OnScrollDirectionPropertySet( Property::Value propertyValue )
 void ScrollBar::OnIndicatorHeightPolicyPropertySet( Property::Value propertyValue )
 {
   std::string policyName( propertyValue.Get<std::string>() );
-  if(policyName == "Variable")
+  if(policyName == "VARIABLE")
   {
-    SetIndicatorHeightPolicy(Toolkit::ScrollBar::Variable);
+    SetIndicatorHeightPolicy(Toolkit::ScrollBar::VARIABLE);
   }
-  else if(policyName == "Fixed")
+  else if(policyName == "FIXED")
   {
-    SetIndicatorHeightPolicy(Toolkit::ScrollBar::Fixed);
+    SetIndicatorHeightPolicy(Toolkit::ScrollBar::FIXED);
   }
   else
   {
@@ -722,7 +722,7 @@ void ScrollBar::SetProperty( BaseObject* object, Property::Index index, const Pr
         scrollBarImpl.ApplyConstraints();
         break;
       }
-      case Toolkit::DevelScrollBar::Property::INDICATOR_TRANSIENT_DURATION:
+      case Toolkit::ScrollBar::Property::INDICATOR_TRANSIENT_DURATION:
       {
         scrollBarImpl.mTransientIndicatorDuration = value.Get<float>();
         break;
@@ -769,17 +769,20 @@ Property::Value ScrollBar::GetProperty( BaseObject* object, Property::Index inde
       }
       case Toolkit::ScrollBar::Property::SCROLL_POSITION_INTERVALS:
       {
-        Property::Value value( Property::ARRAY );
-        Property::Array* array = value.GetArray();
+        Property::Value tempValue( Property::ARRAY );
+        Property::Array* array = tempValue.GetArray();
 
         if( array )
         {
           Dali::Vector<float> positions = scrollBarImpl.GetScrollPositionIntervals();
-          size_t positionCount( array->Count() );
+          size_t positionCount( positions.Count() );
+
           for( size_t i( 0 ); i != positionCount; ++i )
           {
             array->PushBack( positions[i] );
           }
+
+          value = tempValue;
         }
         break;
       }
@@ -798,7 +801,7 @@ Property::Value ScrollBar::GetProperty( BaseObject* object, Property::Index inde
         value = scrollBarImpl.mIndicatorEndPadding;
         break;
       }
-      case Toolkit::DevelScrollBar::Property::INDICATOR_TRANSIENT_DURATION:
+      case Toolkit::ScrollBar::Property::INDICATOR_TRANSIENT_DURATION:
       {
         value = scrollBarImpl.mTransientIndicatorDuration;
         break;