Merge base & optional
[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  // Properties
160
161  /**
162   * Called when a property of an object of this type is set.
163   * @param[in] object The object whose property is set.
164   * @param[in] index The property index.
165   * @param[in] value The new property value.
166   */
167  static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
168
169  /**
170   * Called to retrieve a property of an object of this type.
171   * @param[in] object The object whose property is to be retrieved.
172   * @param[in] index The property index.
173   * @return The current value of the property.
174   */
175  static Property::Value GetProperty( BaseObject* object, Property::Index index );
176
177 private: // from Control
178
179   /**
180    * @copydoc Toolkit::Control::OnInitialize
181    */
182   virtual void OnInitialize();
183
184   /**
185    * @copydoc Toolkit::Control::OnPan
186    */
187   virtual void OnPan( PanGesture gesture );
188
189 private:
190
191   /**
192    * Apply constraints for background and indicator.
193    * These constraints are based on values from the scroll connector.
194    */
195   void ApplyConstraints();
196
197   /**
198    * Callback when the start & end position and size of the scrollable content are changed.
199    * @param[in] minPosition The minimum position.
200    * @param[in] maxPosition The maximum position.
201    * @param[in] contentSize The size of scrollable content.
202    */
203   void OnScrollDomainChanged(float minPosition, float maxPosition, float contentSize);
204
205   /**
206    * Callback when the current scroll position of the scrollable content goes above or
207    * below the values specified by SetPositionNotifications().
208    * @param[in] source the property notification that triggered this callback
209    */
210   void OnScrollPositionNotified(PropertyNotification& source);
211
212   /**
213    * Process the pan gesture per predefined timeout until the gesture is finished.
214    * @return True if the timer should be kept running.
215    */
216   bool OnPanGestureProcessTick();
217
218   /**
219    * Handle SetProperty for scroll indicator height policy.
220    * @param[in] propertyValue The new property value.
221    */
222   void OnIndicatorHeightPolicyPropertySet(Property::Value propertyValue);
223
224 private:
225
226   Constrainable mScrollPositionObject;                               ///< From mScrollConnector
227
228   ImageActor mBackground;                                            ///< Background image of scroll bar.
229   ImageActor mIndicator;                                             ///< Image of scroll indicator.
230   Animation mAnimation;                                              ///< Scroll indicator Show/Hide Animation.
231
232   float mIndicatorShowDuration;                                     ///< The duration of scroll indicator show animation
233   float mIndicatorHideDuration;                                     ///< The duration of scroll indicator hide animation
234
235   float mScrollStart;                                               ///< Scroll Start position (start of drag)
236   Vector3 mGestureDisplacement;                                      ///< Gesture Displacement.
237
238   bool mIsPanning;                                                  ///< Whether the scroll bar is being panned.
239   float mCurrentScrollPosition;                                     ///< The current scroll position updated by the pan gesture
240
241   Toolkit::ScrollBar::IndicatorHeightPolicy mIndicatorHeightPolicy;  ///< The height policy of scroll indicator (variable or fixed)
242   float mIndicatorFixedHeight;                                      ///< The fixed height of scroll indicator
243
244   Timer mTimer;                                                      ///< The timer to process the pan gesture after the gesture is started.
245
246   Property::Index mPropertyIndicatorPosition;                        ///< Indicatore Position ("indicator-position")
247
248   PropertyNotification mPositionNotification;                        ///< Stores the property notification used for scroll position changes
249
250   ScrollPositionNotifiedSignalType mScrollPositionNotifiedSignal;
251
252   ActiveConstraint mIndicatorSizeConstraint;
253   ActiveConstraint mIndicatorPositionConstraint;
254 };
255
256 } // namespace Internal
257
258 // Helpers for public-api forwarding methods
259
260 inline Toolkit::Internal::ScrollBar& GetImpl(Toolkit::ScrollBar& scrollBar)
261 {
262   DALI_ASSERT_ALWAYS(scrollBar);
263
264   Dali::RefObject& handle = scrollBar.GetImplementation();
265
266   return static_cast<Toolkit::Internal::ScrollBar&>(handle);
267 }
268
269 inline const Toolkit::Internal::ScrollBar& GetImpl(const Toolkit::ScrollBar& scrollBar)
270 {
271   DALI_ASSERT_ALWAYS(scrollBar);
272
273   const Dali::RefObject& handle = scrollBar.GetImplementation();
274
275   return static_cast<const Toolkit::Internal::ScrollBar&>(handle);
276 }
277
278 } // namespace Toolkit
279
280 } // namespace Dali
281
282 #endif // __DALI_TOOLKIT_INTERNAL_SCROLL_BAR_H__