6979c52639cfa4d8e9ed6c11b987d05c7832ce9e
[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) 2014 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/actors/image-actor.h>
24 #include <dali/public-api/animation/active-constraint.h>
25 #include <dali/public-api/animation/animation.h>
26 #include <dali/public-api/object/property-notification.h>
27
28 // INTERNAL INCLUDES
29 #include <dali-toolkit/public-api/controls/scrollable/scroll-component-impl.h>
30 #include <dali-toolkit/public-api/controls/scrollable/scroll-connector.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 ScrollComponentImpl
51 {
52
53 public:
54
55   // Properties
56   enum
57   {
58     SCROLLBAR_PROPERTY_START_INDEX = Control::CONTROL_PROPERTY_END_INDEX + 1,
59     SCROLLBAR_PROPERTY_END_INDEX = SCROLLBAR_PROPERTY_START_INDEX + 1000 ///< Reserving 1000 property indices
60   };
61
62   // Signals
63   typedef Toolkit::ScrollBar::ScrollPositionNotifiedSignalType ScrollPositionNotifiedSignalType;
64
65 public:
66
67   /**
68    * @copydoc Toolkit::ScrollBar::ScrollBar()
69    */
70   ScrollBar();
71
72   /**
73    * @copydoc Toolkit::ScrollBar::~ScrollBar()
74    */
75   virtual ~ScrollBar();
76
77   /**
78    * @copydoc Toolkit::ScrollBar::New()
79    */
80   static Toolkit::ScrollBar New();
81
82   /**
83    * @copydoc Toolkit::ScrollComponentImpl::OnScrollConnectorSet()
84    */
85   void OnScrollConnectorSet( Toolkit::ScrollConnector connector );
86
87   /**
88    * @copydoc Toolkit::ScrollBar::SetIndicatorImage()
89    */
90   void SetIndicatorImage( Image image );
91
92   /**
93    * @copydoc Toolkit::ScrollBar::GetScrollIndicator()
94    */
95   Actor GetScrollIndicator();
96
97   /**
98    * @copydoc Toolkit::ScrollBar::SetPositionNotifications()
99    */
100   void SetPositionNotifications( const std::vector<float>& positions );
101
102   /**
103    * @copydoc Toolkit::ScrollBar::SetIndicatorHeightPolicy()
104    */
105   void SetIndicatorHeightPolicy( Toolkit::ScrollBar::IndicatorHeightPolicy policy );
106
107   /**
108    * @copydoc Toolkit::ScrollBar::GetIndicatorHeightPolicy()
109    */
110   Toolkit::ScrollBar::IndicatorHeightPolicy GetIndicatorHeightPolicy();
111
112   /**
113    * @copydoc Toolkit::ScrollBar::SetIndicatorFixedHeight()
114    */
115   void SetIndicatorFixedHeight( float height );
116
117   /**
118    * @copydoc Toolkit::ScrollBar::GetIndicatorFixedHeight()
119    */
120   float GetIndicatorFixedHeight();
121
122   /**
123    * @copydoc Toolkit::ScrollBar::SetIndicatorShowDuration()
124    */
125   void SetIndicatorShowDuration( float durationSeconds );
126
127   /**
128    * @copydoc Toolkit::ScrollBar::GetIndicatorShowDuration()
129    */
130   float GetIndicatorShowDuration();
131
132   /**
133    * @copydoc Toolkit::ScrollBar::SetIndicatorHideDuration()
134    */
135   void SetIndicatorHideDuration( float durationSeconds );
136
137   /**
138    * @copydoc Toolkit::ScrollBar::GetIndicatorHideDuration()
139    */
140   float GetIndicatorHideDuration();
141
142   /**
143    * @copydoc Toolkit::ScrollBar::Show()
144    */
145   void Show();
146
147   /**
148    * @copydoc Toolkit::ScrollBar::Hide()
149    */
150  void Hide();
151
152  /**
153   * Signal emitted after the SetScrollDomain() method has been called.
154   */
155  ScrollPositionNotifiedSignalType& ScrollPositionNotifiedSignal()
156  {
157    return mScrollPositionNotifiedSignal;
158  }
159
160  /**
161   * Connects a callback function with the object's signals.
162   * @param[in] object The object providing the signal.
163   * @param[in] tracker Used to disconnect the signal.
164   * @param[in] signalName The signal to connect to.
165   * @param[in] functor A newly allocated FunctorDelegate.
166   * @return True if the signal was connected.
167   * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
168   */
169  static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
170
171  // Properties
172
173  /**
174   * Called when a property of an object of this type is set.
175   * @param[in] object The object whose property is set.
176   * @param[in] index The property index.
177   * @param[in] value The new property value.
178   */
179  static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
180
181  /**
182   * Called to retrieve a property of an object of this type.
183   * @param[in] object The object whose property is to be retrieved.
184   * @param[in] index The property index.
185   * @return The current value of the property.
186   */
187  static Property::Value GetProperty( BaseObject* object, Property::Index index );
188
189 private: // from Control
190
191   /**
192    * @copydoc Toolkit::Control::OnInitialize
193    */
194   virtual void OnInitialize();
195
196   /**
197    * @copydoc Toolkit::Control::OnPan
198    */
199   virtual void OnPan( PanGesture gesture );
200
201   /**
202    * @copydoc Toolkit::Control::OnControlSizeSet( const Vector3& size )
203    */
204   virtual void OnControlSizeSet( const Vector3& size );
205
206 private:
207
208   /**
209    * Apply constraints for background and indicator.
210    * These constraints are based on values from the scroll connector.
211    */
212   void ApplyConstraints();
213
214   /**
215    * Callback when the start & end position and size of the scrollable content are changed.
216    * @param[in] minPosition The minimum position.
217    * @param[in] maxPosition The maximum position.
218    * @param[in] contentSize The size of scrollable content.
219    */
220   void OnScrollDomainChanged(float minPosition, float maxPosition, float contentSize);
221
222   /**
223    * Callback when the current scroll position of the scrollable content goes above or
224    * below the values specified by SetPositionNotifications().
225    * @param[in] source the property notification that triggered this callback
226    */
227   void OnScrollPositionNotified(PropertyNotification& source);
228
229   /**
230    * Process the pan gesture per predefined timeout until the gesture is finished.
231    * @return True if the timer should be kept running.
232    */
233   bool OnPanGestureProcessTick();
234
235   /**
236    * Handle SetProperty for scroll indicator height policy.
237    * @param[in] propertyValue The new property value.
238    */
239   void OnIndicatorHeightPolicyPropertySet(Property::Value propertyValue);
240
241 private:
242
243   Handle mScrollPositionObject;                               ///< From mScrollConnector
244
245   ImageActor mIndicator;                                             ///< Image of scroll indicator.
246   Animation mAnimation;                                              ///< Scroll indicator Show/Hide Animation.
247
248   float mIndicatorShowDuration;                                     ///< The duration of scroll indicator show animation
249   float mIndicatorHideDuration;                                     ///< The duration of scroll indicator hide animation
250
251   float mScrollStart;                                               ///< Scroll Start position (start of drag)
252   Vector3 mGestureDisplacement;                                      ///< Gesture Displacement.
253
254   bool mIsPanning;                                                  ///< Whether the scroll bar is being panned.
255   float mCurrentScrollPosition;                                     ///< The current scroll position updated by the pan gesture
256
257   Toolkit::ScrollBar::IndicatorHeightPolicy mIndicatorHeightPolicy;  ///< The height policy of scroll indicator (variable or fixed)
258   float mIndicatorFixedHeight;                                      ///< The fixed height of scroll indicator
259
260   Timer mTimer;                                                      ///< The timer to process the pan gesture after the gesture is started.
261
262   Property::Index mPropertyIndicatorPosition;                        ///< Indicatore Position ("indicator-position")
263
264   PropertyNotification mPositionNotification;                        ///< Stores the property notification used for scroll position changes
265
266   ScrollPositionNotifiedSignalType mScrollPositionNotifiedSignal;
267
268   ActiveConstraint mIndicatorSizeConstraint;
269   ActiveConstraint mIndicatorPositionConstraint;
270 };
271
272 } // namespace Internal
273
274 // Helpers for public-api forwarding methods
275
276 inline Toolkit::Internal::ScrollBar& GetImpl(Toolkit::ScrollBar& scrollBar)
277 {
278   DALI_ASSERT_ALWAYS(scrollBar);
279
280   Dali::RefObject& handle = scrollBar.GetImplementation();
281
282   return static_cast<Toolkit::Internal::ScrollBar&>(handle);
283 }
284
285 inline const Toolkit::Internal::ScrollBar& GetImpl(const Toolkit::ScrollBar& scrollBar)
286 {
287   DALI_ASSERT_ALWAYS(scrollBar);
288
289   const Dali::RefObject& handle = scrollBar.GetImplementation();
290
291   return static_cast<const Toolkit::Internal::ScrollBar&>(handle);
292 }
293
294 } // namespace Toolkit
295
296 } // namespace Dali
297
298 #endif // __DALI_TOOLKIT_INTERNAL_SCROLL_BAR_H__