Updated all header files to new format
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / scroll-bar / scroll-bar-impl.h
1 #ifndef DALI_TOOLKIT_INTERNAL_SCROLL_BAR_H
2 #define DALI_TOOLKIT_INTERNAL_SCROLL_BAR_H
3
4 /*
5  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/adaptor-framework/timer.h>
23 #include <dali/public-api/animation/animation.h>
24 #include <dali/public-api/animation/constraint.h>
25 #include <dali/public-api/common/dali-vector.h>
26 #include <dali/public-api/object/property-notification.h>
27 #include <dali/public-api/object/weak-handle.h>
28
29 // INTERNAL INCLUDES
30 #include <dali-toolkit/devel-api/controls/scroll-bar/scroll-bar.h>
31 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
32 #include <dali-toolkit/public-api/controls/control-impl.h>
33
34 namespace Dali
35 {
36 namespace Toolkit
37 {
38 namespace Internal
39 {
40 class ScrollBar;
41
42 typedef IntrusivePtr<ScrollBar> ScrollBarPtr;
43
44 /**
45  * ScrollBar is a UI component that can be added to the scrollable controls
46  * indicating the current scroll position of the scrollable content.
47  */
48 class ScrollBar : public Control
49 {
50 public:
51   // Signals
52   typedef Toolkit::ScrollBar::PanFinishedSignalType                   PanFinishedSignalType;
53   typedef Toolkit::ScrollBar::ScrollPositionIntervalReachedSignalType ScrollPositionIntervalReachedSignalType;
54
55 public:
56   /**
57    * @copydoc Toolkit::ScrollBar::New()
58    */
59   static Toolkit::ScrollBar New(Toolkit::ScrollBar::Direction direction);
60
61   /**
62    * @copydoc Toolkit::ScrollBar::SetScrollPropertySource()
63    */
64   void SetScrollPropertySource(Handle handle, Property::Index propertyScrollPosition, Property::Index propertyMinScrollPosition, Property::Index propertyMaxScrollPosition, Property::Index propertyScrollContentSize);
65
66   /**
67    * @copydoc Toolkit::ScrollBar::SetScrollIndicator()
68    */
69   void SetScrollIndicator(Actor indicator);
70
71   /**
72    * @copydoc Toolkit::ScrollBar::GetScrollIndicator()
73    */
74   Actor GetScrollIndicator();
75
76   /**
77    * @copydoc Toolkit::ScrollBar::SetScrollPositionIntervals()
78    */
79   void SetScrollPositionIntervals(const Dali::Vector<float>& positions);
80
81   /**
82    * @copydoc Toolkit::ScrollBar::GetScrollPositionIntervals()
83    */
84   Dali::Vector<float> GetScrollPositionIntervals() const;
85
86   /**
87    * @copydoc Toolkit::ScrollBar::SetScrollDirection()
88    */
89   void SetScrollDirection(Toolkit::ScrollBar::Direction direction);
90
91   /**
92    * @copydoc Toolkit::ScrollBar::GetScrollDirection()
93    */
94   Toolkit::ScrollBar::Direction GetScrollDirection() const;
95
96   /**
97    * @copydoc Toolkit::ScrollBar::SetIndicatorHeightPolicy()
98    */
99   void SetIndicatorHeightPolicy(Toolkit::ScrollBar::IndicatorHeightPolicy policy);
100
101   /**
102    * @copydoc Toolkit::ScrollBar::GetIndicatorHeightPolicy()
103    */
104   Toolkit::ScrollBar::IndicatorHeightPolicy GetIndicatorHeightPolicy() const;
105
106   /**
107    * @copydoc Toolkit::ScrollBar::SetIndicatorFixedHeight()
108    */
109   void SetIndicatorFixedHeight(float height);
110
111   /**
112    * @copydoc Toolkit::ScrollBar::GetIndicatorFixedHeight()
113    */
114   float GetIndicatorFixedHeight() const;
115
116   /**
117    * @copydoc Toolkit::ScrollBar::SetIndicatorShowDuration()
118    */
119   void SetIndicatorShowDuration(float durationSeconds);
120
121   /**
122    * @copydoc Toolkit::ScrollBar::GetIndicatorShowDuration()
123    */
124   float GetIndicatorShowDuration() const;
125
126   /**
127    * @copydoc Toolkit::ScrollBar::SetIndicatorHideDuration()
128    */
129   void SetIndicatorHideDuration(float durationSeconds);
130
131   /**
132    * @copydoc Toolkit::ScrollBar::GetIndicatorHideDuration()
133    */
134   float GetIndicatorHideDuration() const;
135
136   /**
137    * @copydoc Toolkit::ScrollBar::ShowIndicator()
138    */
139   void ShowIndicator();
140
141   /**
142    * @copydoc Toolkit::ScrollBar::HideIndicator()
143    */
144   void HideIndicator();
145
146   /**
147    * @brief Shows indicator until the transient duration has expired
148    */
149   void ShowTransientIndicator();
150
151   /**
152   * @copydoc Toolkit::ScrollBar::PanFinishedSignal()
153   */
154   PanFinishedSignalType& PanFinishedSignal()
155   {
156     return mPanFinishedSignal;
157   }
158
159   /**
160   * @copydoc Toolkit::ScrollBar::ScrollPositionIntervalReachedSignal()
161   */
162   ScrollPositionIntervalReachedSignalType& ScrollPositionIntervalReachedSignal()
163   {
164     return mScrollPositionIntervalReachedSignal;
165   }
166
167   /**
168   * Connects a callback function with the object's signals.
169   * @param[in] object The object providing the signal.
170   * @param[in] tracker Used to disconnect the signal.
171   * @param[in] signalName The signal to connect to.
172   * @param[in] functor A newly allocated FunctorDelegate.
173   * @return True if the signal was connected.
174   * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
175   */
176   static bool DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor);
177
178   // Properties
179
180   /**
181   * Called when a property of an object of this type is set.
182   * @param[in] object The object whose property is set.
183   * @param[in] index The property index.
184   * @param[in] value The new property value.
185   */
186   static void SetProperty(BaseObject* object, Property::Index index, const Property::Value& value);
187
188   /**
189   * Called to retrieve a property of an object of this type.
190   * @param[in] object The object whose property is to be retrieved.
191   * @param[in] index The property index.
192   * @return The current value of the property.
193   */
194   static Property::Value GetProperty(BaseObject* object, Property::Index index);
195
196   /**
197   * Performs actions as requested using the action name.
198   * @param[in] object The object on which to perform the action.
199   * @param[in] actionName The action to perform.
200   * @param[in] attributes The attributes with which to perfrom this action.
201   * @return true if action has been accepted by this control
202   */
203   static bool DoAction(BaseObject* object, const std::string& actionName, const Property::Map& attributes);
204
205 private: // from Control
206   /**
207    * @copydoc Toolkit::Control::OnInitialize
208    */
209   void OnInitialize() override;
210
211   /**
212    * @copydoc Toolkit::Control::OnPan
213    */
214   void OnPan(const PanGesture& gesture) override;
215
216   /**
217    * @copydoc CustomActorImpl::OnSizeSet( const Vector3& size )
218    */
219   void OnSizeSet(const Vector3& size) override;
220
221 private:
222   /**
223    * Create the default indicator actor.
224    */
225   void CreateDefaultIndicatorActor();
226
227   /**
228    * Apply constraints for background and indicator.
229    * These constraints are based on values from the scroll connector.
230    */
231   void ApplyConstraints();
232
233   /**
234    * Callback when the current scroll position of the scrollable content goes above or
235    * below the values specified by SetScrollPositionIntervals().
236    * @param[in] source the property notification that triggered this callback
237    */
238   void OnScrollPositionIntervalReached(PropertyNotification& source);
239
240   /**
241    * Process the pan gesture per predefined timeout until the gesture is finished.
242    * @return True if the timer should be kept running.
243    */
244   bool OnPanGestureProcessTick();
245
246   /**
247    * Handle SetProperty for scroll direction.
248    * @param[in] propertyValue The new property value.
249    */
250   void OnScrollDirectionPropertySet(Property::Value propertyValue);
251
252   /**
253    * Handle SetProperty for scroll indicator height policy.
254    * @param[in] propertyValue The new property value.
255    */
256   void OnIndicatorHeightPolicyPropertySet(Property::Value propertyValue);
257
258 private:
259   /**
260    * Constructor.
261    * It initializes ScrollBar members.
262    */
263   ScrollBar(Toolkit::ScrollBar::Direction direction);
264
265   /**
266    * A reference counted object may only be deleted by calling Unreference()
267    */
268   virtual ~ScrollBar();
269
270 private:
271   Actor     mIndicator;          ///< Image of scroll indicator.
272   float     mIndicatorShowAlpha; ///< The alpha value when the indicator is fully shown
273   Animation mAnimation;          ///< Scroll indicator Show/Hide Animation.
274
275   Toolkit::ScrollBar::Direction mDirection; ///< The direction of scroll bar (vertical or horizontal)
276
277   WeakHandle<Handle> mScrollableObject; ///< Object to be scrolled
278
279   Property::Index mPropertyScrollPosition    = 0; ///< Index of scroll position property owned by the object to be scrolled
280   Property::Index mPropertyMinScrollPosition = 0; ///< Index of minimum scroll position property owned by the object to be scrolled
281   Property::Index mPropertyMaxScrollPosition = 1; ///< Index of maximum scroll position property owned by the object to be scrolled
282   Property::Index mPropertyScrollContentSize;     ///< Index of scroll content size property owned by the object to be scrolled
283
284   float mIndicatorShowDuration;      ///< The duration of scroll indicator show animation
285   float mIndicatorHideDuration;      ///< The duration of scroll indicator hide animation
286   float mTransientIndicatorDuration; ///< The duration before hiding transient indicator
287
288   float   mScrollStart;         ///< Scroll Start position (start of drag)
289   Vector2 mGestureDisplacement; ///< Gesture Displacement.
290
291   float mCurrentScrollPosition; ///< The current scroll position updated by the pan gesture
292
293   Toolkit::ScrollBar::IndicatorHeightPolicy mIndicatorHeightPolicy;  ///< The height policy of scroll indicator (variable or fixed)
294   float                                     mIndicatorFixedHeight;   ///< The fixed height of scroll indicator
295   float                                     mIndicatorMinimumHeight; ///< The minimum height for a variable size indicator
296   float                                     mIndicatorStartPadding;  ///< The padding at the start of the indicator
297   float                                     mIndicatorEndPadding;    ///< The padding at the end of the indicator
298
299   Timer mContractDelayTimer; ///< Timer guarantee contract delay time.
300   Timer mPanProcessTimer;    ///< The timer to process the pan gesture after the gesture is started.
301
302   Dali::Vector<float>  mScrollPositionIntervals; ///< List of values to receive notification for when the current scroll position goes above or below them
303   PropertyNotification mPositionNotification;    ///< Stores the property notification used for scroll position changes
304
305   PanFinishedSignalType                   mPanFinishedSignal;
306   ScrollPositionIntervalReachedSignalType mScrollPositionIntervalReachedSignal;
307
308   Constraint mIndicatorPositionConstraint;
309   Constraint mIndicatorSizeConstraint;
310
311   bool mIsPanning : 1;          ///< Whether the scroll bar is being panned.
312   bool mIndicatorFirstShow : 1; ///< True if the indicator has never been shown
313
314 protected:
315   struct AccessibleImpl : public Control::Impl::AccessibleImpl,
316                           public virtual Dali::Accessibility::Value
317   {
318     using Control::Impl::AccessibleImpl::AccessibleImpl;
319     double GetMinimum() override;
320     double GetCurrent() override;
321     double GetMaximum() override;
322     bool   SetCurrent(double) override;
323     double GetMinimumIncrement() override;
324   };
325 };
326
327 } // namespace Internal
328
329 // Helpers for public-api forwarding methods
330
331 inline Toolkit::Internal::ScrollBar& GetImpl(Toolkit::ScrollBar& scrollBar)
332 {
333   DALI_ASSERT_ALWAYS(scrollBar);
334
335   Dali::RefObject& handle = scrollBar.GetImplementation();
336
337   return static_cast<Toolkit::Internal::ScrollBar&>(handle);
338 }
339
340 inline const Toolkit::Internal::ScrollBar& GetImpl(const Toolkit::ScrollBar& scrollBar)
341 {
342   DALI_ASSERT_ALWAYS(scrollBar);
343
344   const Dali::RefObject& handle = scrollBar.GetImplementation();
345
346   return static_cast<const Toolkit::Internal::ScrollBar&>(handle);
347 }
348
349 } // namespace Toolkit
350
351 } // namespace Dali
352
353 #endif // DALI_TOOLKIT_INTERNAL_SCROLL_BAR_H