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