Support weak handle for BaseHandle
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / scroll-bar / scroll-bar-impl.h
index 1da0474..f56b9a0 100755 (executable)
@@ -1,26 +1,34 @@
-#ifndef __DALI_TOOLKIT_INTERNAL_SCROLL_BAR_H__
-#define __DALI_TOOLKIT_INTERNAL_SCROLL_BAR_H__
-
-//
-// 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.
-//
+#ifndef DALI_TOOLKIT_INTERNAL_SCROLL_BAR_H
+#define DALI_TOOLKIT_INTERNAL_SCROLL_BAR_H
+
+/*
+ * 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.
+ * 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.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <dali/public-api/adaptor-framework/timer.h>
+#include <dali/public-api/animation/constraint.h>
+#include <dali/public-api/animation/animation.h>
+#include <dali/public-api/common/dali-vector.h>
+#include <dali/public-api/object/property-notification.h>
+#include <dali/public-api/object/weak-handle.h>
 
 // INTERNAL INCLUDES
 #include <dali-toolkit/public-api/controls/control-impl.h>
-#include <dali-toolkit/public-api/controls/scrollable/scroll-connector.h>
-#include <dali-toolkit/public-api/controls/scroll-bar/scroll-bar.h>
+#include <dali-toolkit/devel-api/controls/scroll-bar/scroll-bar.h>
 
 namespace Dali
 {
@@ -39,74 +47,167 @@ typedef IntrusivePtr<ScrollBar> ScrollBarPtr;
  * ScrollBar is a UI component that can be added to the scrollable controls
  * indicating the current scroll position of the scrollable content.
  */
-class ScrollBar : public ControlImpl
+class ScrollBar : public Control
 {
 
 public:
 
-  typedef Toolkit::ScrollBar::ScrollPositionNotifiedSignalType ScrollPositionNotifiedSignalType;
+  // Signals
+  typedef Toolkit::ScrollBar::PanFinishedSignalType PanFinishedSignalType;
+  typedef Toolkit::ScrollBar::ScrollPositionIntervalReachedSignalType ScrollPositionIntervalReachedSignalType;
 
 public:
 
   /**
-   * @copydoc Toolkit::ScrollBar::ScrollBar()
+   * @copydoc Toolkit::ScrollBar::New()
    */
-  ScrollBar();
+  static Toolkit::ScrollBar New(Toolkit::ScrollBar::Direction direction);
 
   /**
-   * @copydoc Toolkit::ScrollBar::~ScrollBar()
+   * @copydoc Toolkit::ScrollBar::SetScrollPropertySource()
    */
-  virtual ~ScrollBar();
+  void SetScrollPropertySource( Handle handle, Property::Index propertyScrollPosition, Property::Index propertyMinScrollPosition, Property::Index propertyMaxScrollPosition, Property::Index propertyScrollContentSize );
 
   /**
-   * @copydoc Toolkit::ScrollBar::New()
+   * @copydoc Toolkit::ScrollBar::SetScrollIndicator()
    */
-  static Toolkit::ScrollBar New();
+  void SetScrollIndicator( Actor indicator );
 
   /**
-   * @copydoc Toolkit::ScrollBar::SetScrollConnector()
+   * @copydoc Toolkit::ScrollBar::GetScrollIndicator()
    */
-  void SetScrollConnector( Toolkit::ScrollConnector connector );
+  Actor GetScrollIndicator();
 
   /**
-   * @copydoc Toolkit::ScrollBar::SetBackgroundImage()
+   * @copydoc Toolkit::ScrollBar::SetScrollPositionIntervals()
    */
-  void SetBackgroundImage( Image image, const Vector4& border );
+  void SetScrollPositionIntervals( const Dali::Vector<float>& positions );
 
   /**
-   * @copydoc Toolkit::ScrollBar::SetIndicatorImage()
+   * @copydoc Toolkit::ScrollBar::GetScrollPositionIntervals()
    */
-  void SetIndicatorImage( Image image, const Vector4& border );
+  Dali::Vector<float> GetScrollPositionIntervals() const;
 
   /**
-   * @copydoc Toolkit::ScrollBar::GetScrollIndicator()
+   * @copydoc Toolkit::ScrollBar::SetScrollDirection()
    */
-  Actor GetScrollIndicator();
+  void SetScrollDirection( Toolkit::ScrollBar::Direction direction );
+
+  /**
+   * @copydoc Toolkit::ScrollBar::GetScrollDirection()
+   */
+  Toolkit::ScrollBar::Direction GetScrollDirection() const;
+
+  /**
+   * @copydoc Toolkit::ScrollBar::SetIndicatorHeightPolicy()
+   */
+  void SetIndicatorHeightPolicy( Toolkit::ScrollBar::IndicatorHeightPolicy policy );
 
   /**
-   * @copydoc Toolkit::ScrollBar::SetPositionNotifications()
+   * @copydoc Toolkit::ScrollBar::GetIndicatorHeightPolicy()
    */
-  void SetPositionNotifications( const std::vector<float>& positions );
+  Toolkit::ScrollBar::IndicatorHeightPolicy GetIndicatorHeightPolicy() const;
 
   /**
-   * @copydoc Toolkit::ScrollBar::Show()
+   * @copydoc Toolkit::ScrollBar::SetIndicatorFixedHeight()
    */
-  void Show();
+  void SetIndicatorFixedHeight( float height );
 
   /**
-   * @copydoc Toolkit::ScrollBar::Hide()
+   * @copydoc Toolkit::ScrollBar::GetIndicatorFixedHeight()
    */
- void Hide();
+  float GetIndicatorFixedHeight() const;
+
+  /**
+   * @copydoc Toolkit::ScrollBar::SetIndicatorShowDuration()
+   */
+  void SetIndicatorShowDuration( float durationSeconds );
+
+  /**
+   * @copydoc Toolkit::ScrollBar::GetIndicatorShowDuration()
+   */
+  float GetIndicatorShowDuration() const;
+
+  /**
+   * @copydoc Toolkit::ScrollBar::SetIndicatorHideDuration()
+   */
+  void SetIndicatorHideDuration( float durationSeconds );
+
+  /**
+   * @copydoc Toolkit::ScrollBar::GetIndicatorHideDuration()
+   */
+  float GetIndicatorHideDuration() const;
+
+  /**
+   * @copydoc Toolkit::ScrollBar::ShowIndicator()
+   */
+  void ShowIndicator();
+
+  /**
+   * @copydoc Toolkit::ScrollBar::HideIndicator()
+   */
+  void HideIndicator();
+
+  /**
+   * @brief Shows indicator until the transient duration has expired
+   */
+  void ShowTransientIndicator();
+
+ /**
+  * @copydoc Toolkit::ScrollBar::PanFinishedSignal()
+  */
+ PanFinishedSignalType& PanFinishedSignal()
+ {
+   return mPanFinishedSignal;
+ }
 
  /**
-  * Signal emitted after the SetScrollDomain() method has been called.
+  * @copydoc Toolkit::ScrollBar::ScrollPositionIntervalReachedSignal()
   */
- ScrollPositionNotifiedSignalType& ScrollPositionNotifiedSignal()
+ ScrollPositionIntervalReachedSignalType& ScrollPositionIntervalReachedSignal()
  {
-   return mScrollPositionNotifiedSignal;
+   return mScrollPositionIntervalReachedSignal;
  }
 
-private: // from ControlImpl
+ /**
+  * Connects a callback function with the object's signals.
+  * @param[in] object The object providing the signal.
+  * @param[in] tracker Used to disconnect the signal.
+  * @param[in] signalName The signal to connect to.
+  * @param[in] functor A newly allocated FunctorDelegate.
+  * @return True if the signal was connected.
+  * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
+  */
+ static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
+
+ // Properties
+
+ /**
+  * Called when a property of an object of this type is set.
+  * @param[in] object The object whose property is set.
+  * @param[in] index The property index.
+  * @param[in] value The new property value.
+  */
+ static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
+
+ /**
+  * Called to retrieve a property of an object of this type.
+  * @param[in] object The object whose property is to be retrieved.
+  * @param[in] index The property index.
+  * @return The current value of the property.
+  */
+ static Property::Value GetProperty( BaseObject* object, Property::Index index );
+
+ /**
+  * Performs actions as requested using the action name.
+  * @param[in] object The object on which to perform the action.
+  * @param[in] actionName The action to perform.
+  * @param[in] attributes The attributes with which to perfrom this action.
+  * @return true if action has been accepted by this control
+  */
+ static bool DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes );
+
+private: // from Control
 
   /**
    * @copydoc Toolkit::Control::OnInitialize
@@ -116,48 +217,108 @@ private: // from ControlImpl
   /**
    * @copydoc Toolkit::Control::OnPan
    */
-  virtual void OnPan( PanGesture gesture );
+  virtual void OnPan( const PanGesture& gesture );
+
+  /**
+   * @copydoc CustomActorImpl::OnSizeSet( const Vector3& size )
+   */
+  virtual void OnSizeSet( const Vector3& size );
 
 private:
 
   /**
+   * Create the default indicator actor.
+   */
+  void CreateDefaultIndicatorActor();
+
+  /**
    * Apply constraints for background and indicator.
    * These constraints are based on values from the scroll connector.
    */
   void ApplyConstraints();
 
   /**
-   * Callback when the start & end position and size of the scrollable content are changed.
-   * @param[in] minPosition The minimum position.
-   * @param[in] maxPosition The maximum position.
-   * @param[in] contentSize The size of scrollable content.
+   * Callback when the current scroll position of the scrollable content goes above or
+   * below the values specified by SetScrollPositionIntervals().
+   * @param[in] source the property notification that triggered this callback
    */
-  void OnScrollDomainChanged(float minPosition, float maxPosition, float contentSize);
+  void OnScrollPositionIntervalReached(PropertyNotification& source);
 
   /**
-   * Callback when the current scroll position of the scrollable content goes above or
-   * below the values specified by SetPositionNotifications().
-   * @param[in] source the property notification that triggered this callback
+   * Process the pan gesture per predefined timeout until the gesture is finished.
+   * @return True if the timer should be kept running.
    */
-  void OnScrollPositionNotified(PropertyNotification& source);
+  bool OnPanGestureProcessTick();
+
+  /**
+   * Handle SetProperty for scroll direction.
+   * @param[in] propertyValue The new property value.
+   */
+  void OnScrollDirectionPropertySet(Property::Value propertyValue);
+
+  /**
+   * Handle SetProperty for scroll indicator height policy.
+   * @param[in] propertyValue The new property value.
+   */
+  void OnIndicatorHeightPolicyPropertySet(Property::Value propertyValue);
 
 private:
 
-  Toolkit::ScrollConnector mScrollConnector;              ///< Connects scroll bar with the scrollable container.
-  Constrainable mScrollPositionObject;                    ///< From mScrollConnector
+  /**
+   * Constructor.
+   * It initializes ScrollBar members.
+   */
+  ScrollBar( Toolkit::ScrollBar::Direction direction );
+
+  /**
+   * A reference counted object may only be deleted by calling Unreference()
+   */
+  virtual ~ScrollBar();
+
+private:
+
+  Actor mIndicator;                                                  ///< Image of scroll indicator.
+  float mIndicatorShowAlpha;                                         ///< The alpha value when the indicator is fully shown
+  Animation mAnimation;                                              ///< Scroll indicator Show/Hide Animation.
+
+  Toolkit::ScrollBar::Direction mDirection;                          ///< The direction of scroll bar (vertical or horizontal)
+
+  WeakHandle<Handle> mScrollableObject;                              ///< Object to be scrolled
+
+  Property::Index mPropertyScrollPosition;                           ///< Index of scroll position property owned by the object to be scrolled
+  Property::Index mPropertyMinScrollPosition;                        ///< Index of minimum scroll position property owned by the object to be scrolled
+  Property::Index mPropertyMaxScrollPosition;                        ///< Index of maximum scroll position property owned by the object to be scrolled
+  Property::Index mPropertyScrollContentSize;                        ///< Index of scroll content size property owned by the object to be scrolled
+
+  float mIndicatorShowDuration;                                      ///< The duration of scroll indicator show animation
+  float mIndicatorHideDuration;                                      ///< The duration of scroll indicator hide animation
+  float mTransientIndicatorDuration;                                 ///< The duration before hiding transient indicator
+
+  float mScrollStart;                                                ///< Scroll Start position (start of drag)
+  Vector3 mGestureDisplacement;                                      ///< Gesture Displacement.
+
+  float mCurrentScrollPosition;                                      ///< The current scroll position updated by the pan gesture
+
+  Toolkit::ScrollBar::IndicatorHeightPolicy mIndicatorHeightPolicy;  ///< The height policy of scroll indicator (variable or fixed)
+  float mIndicatorFixedHeight;                                       ///< The fixed height of scroll indicator
+  float mIndicatorMinimumHeight;                                     ///< The minimum height for a variable size indicator
+  float mIndicatorStartPadding;                                      ///< The padding at the start of the indicator
+  float mIndicatorEndPadding;                                        ///< The padding at the end of the indicator
 
-  ImageActor mBackground;                                 ///< Background image of scroll bar.
-  ImageActor mIndicator;                                  ///< Image of scroll indicator.
-  Animation mAnimation;                                   ///< Scroll indicator Show/Hide Animation.
+  Timer mContractDelayTimer;                                         ///< Timer guarantee contract delay time.
+  Timer mPanProcessTimer;                                            ///< The timer to process the pan gesture after the gesture is started.
 
-  float mScrollStart;                                     ///< Scroll Start position (start of drag)
-  Vector3 mGestureDisplacement;                           ///< Gesture Displacement.
+  Dali::Vector<float> mScrollPositionIntervals;                      ///< List of values to receive notification for when the current scroll position goes above or below them
+  PropertyNotification mPositionNotification;                        ///< Stores the property notification used for scroll position changes
 
-  Property::Index mPropertyIndicatorPosition;             ///< Indicatore Position ("indicator-position")
+  PanFinishedSignalType mPanFinishedSignal;
+  ScrollPositionIntervalReachedSignalType mScrollPositionIntervalReachedSignal;
 
-  PropertyNotification mPositionNotification;             ///< Stores the property notification used for scroll position changes
+  Constraint mIndicatorPositionConstraint;
+  Constraint mIndicatorSizeConstraint;
 
-  ScrollPositionNotifiedSignalType mScrollPositionNotifiedSignal;
+  bool mIsPanning                 : 1;                               ///< Whether the scroll bar is being panned.
+  bool mIndicatorFirstShow        : 1;                               ///< True if the indicator has never been shown
 };
 
 } // namespace Internal
@@ -186,4 +347,4 @@ inline const Toolkit::Internal::ScrollBar& GetImpl(const Toolkit::ScrollBar& scr
 
 } // namespace Dali
 
-#endif // __DALI_TOOLKIT_INTERNAL_SCROLL_BAR_H__
+#endif // DALI_TOOLKIT_INTERNAL_SCROLL_BAR_H