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