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