Add new API to ScrollBar to set background and indicator images.
[platform/core/uifw/dali-toolkit.git] / base / 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 Flora License, Version 1.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://floralicense.org/license/
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 // INTERNAL INCLUDES
21 #include <dali-toolkit/public-api/controls/scrollable/scroll-component-impl.h>
22 #include <dali-toolkit/public-api/controls/scrollable/scroll-connector.h>
23 #include <dali-toolkit/public-api/controls/scroll-bar/scroll-bar.h>
24
25 namespace Dali
26 {
27
28 namespace Toolkit
29 {
30
31 namespace Internal
32 {
33
34 class ScrollBar;
35
36 typedef IntrusivePtr<ScrollBar> ScrollBarPtr;
37
38 /**
39  * ScrollBar is a UI component that can be added to the scrollable controls
40  * indicating the current scroll position of the scrollable content.
41  */
42 class ScrollBar : public ScrollComponentImpl
43 {
44
45 public:
46
47   // Properties
48   enum
49   {
50     SCROLLBAR_PROPERTY_START_INDEX = ControlImpl::CONTROL_PROPERTY_END_INDEX + 1,
51     SCROLLBAR_PROPERTY_END_INDEX = SCROLLBAR_PROPERTY_START_INDEX + 1000 ///< Reserving 1000 property indices
52   };
53
54   // Signals
55   typedef Toolkit::ScrollBar::ScrollPositionNotifiedSignalType ScrollPositionNotifiedSignalType;
56
57 public:
58
59   /**
60    * @copydoc Toolkit::ScrollBar::ScrollBar()
61    */
62   ScrollBar();
63
64   /**
65    * @copydoc Toolkit::ScrollBar::~ScrollBar()
66    */
67   virtual ~ScrollBar();
68
69   /**
70    * @copydoc Toolkit::ScrollBar::New()
71    */
72   static Toolkit::ScrollBar New();
73
74   /**
75    * @copydoc Toolkit::ScrollComponentImpl::OnScrollConnectorSet()
76    */
77   void OnScrollConnectorSet( Toolkit::ScrollConnector connector );
78
79   /**
80    * @copydoc Toolkit::ScrollBar::SetBackgroundImage()
81    */
82   void SetBackgroundImage( Image image, const Vector4& border );
83
84   /**
85    * @copydoc Toolkit::ScrollBar::SetIndicatorImage()
86    */
87   void SetIndicatorImage( Image image );
88
89   /**
90    * @copydoc Toolkit::ScrollBar::SetIndicatorImage()
91    */
92   void SetIndicatorImage( Image image, const Vector4& border );
93
94   /**
95    * @copydoc Toolkit::ScrollBar::GetScrollIndicator()
96    */
97   Actor GetScrollIndicator();
98
99   /**
100    * @copydoc Toolkit::ScrollBar::SetPositionNotifications()
101    */
102   void SetPositionNotifications( const std::vector<float>& positions );
103
104   /**
105    * @copydoc Toolkit::ScrollBar::SetIndicatorHeightPolicy()
106    */
107   void SetIndicatorHeightPolicy( Toolkit::ScrollBar::IndicatorHeightPolicy policy );
108
109   /**
110    * @copydoc Toolkit::ScrollBar::GetIndicatorHeightPolicy()
111    */
112   Toolkit::ScrollBar::IndicatorHeightPolicy GetIndicatorHeightPolicy();
113
114   /**
115    * @copydoc Toolkit::ScrollBar::SetIndicatorFixedHeight()
116    */
117   void SetIndicatorFixedHeight( float height );
118
119   /**
120    * @copydoc Toolkit::ScrollBar::GetIndicatorFixedHeight()
121    */
122   float GetIndicatorFixedHeight();
123
124   /**
125    * @copydoc Toolkit::ScrollBar::Show()
126    */
127   void Show();
128
129   /**
130    * @copydoc Toolkit::ScrollBar::Hide()
131    */
132  void Hide();
133
134  /**
135   * Signal emitted after the SetScrollDomain() method has been called.
136   */
137  ScrollPositionNotifiedSignalType& ScrollPositionNotifiedSignal()
138  {
139    return mScrollPositionNotifiedSignal;
140  }
141
142  // Properties
143
144  /**
145   * Called when a property of an object of this type is set.
146   * @param[in] object The object whose property is set.
147   * @param[in] index The property index.
148   * @param[in] value The new property value.
149   */
150  static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
151
152  /**
153   * Called to retrieve a property of an object of this type.
154   * @param[in] object The object whose property is to be retrieved.
155   * @param[in] index The property index.
156   * @return The current value of the property.
157   */
158  static Property::Value GetProperty( BaseObject* object, Property::Index index );
159
160 private: // from Control
161
162   /**
163    * @copydoc Toolkit::Control::OnInitialize
164    */
165   virtual void OnInitialize();
166
167   /**
168    * @copydoc Toolkit::Control::OnPan
169    */
170   virtual void OnPan( PanGesture gesture );
171
172 private:
173
174   /**
175    * Apply constraints for background and indicator.
176    * These constraints are based on values from the scroll connector.
177    */
178   void ApplyConstraints();
179
180   /**
181    * Callback when the start & end position and size of the scrollable content are changed.
182    * @param[in] minPosition The minimum position.
183    * @param[in] maxPosition The maximum position.
184    * @param[in] contentSize The size of scrollable content.
185    */
186   void OnScrollDomainChanged(float minPosition, float maxPosition, float contentSize);
187
188   /**
189    * Callback when the current scroll position of the scrollable content goes above or
190    * below the values specified by SetPositionNotifications().
191    * @param[in] source the property notification that triggered this callback
192    */
193   void OnScrollPositionNotified(PropertyNotification& source);
194
195   /**
196    * Process the pan gesture per predefined timeout until the gesture is finished.
197    * @return True if the timer should be kept running.
198    */
199   bool OnPanGestureProcessTick();
200
201   /**
202    * Handle SetProperty for scroll indicator height policy.
203    * @param[in] propertyValue The new property value.
204    */
205   void OnIndicatorHeightPolicyPropertySet(Property::Value propertyValue);
206
207 private:
208
209   Constrainable mScrollPositionObject;                               ///< From mScrollConnector
210
211   ImageActor mBackground;                                            ///< Background image of scroll bar.
212   ImageActor mIndicator;                                             ///< Image of scroll indicator.
213   Animation mAnimation;                                              ///< Scroll indicator Show/Hide Animation.
214
215   float mScrollStart;                                               ///< Scroll Start position (start of drag)
216   Vector3 mGestureDisplacement;                                      ///< Gesture Displacement.
217
218   bool mIsPanning;                                                  ///< Whether the scroll bar is being panned.
219   float mCurrentScrollPosition;                                     ///< The current scroll position updated by the pan gesture
220
221   Toolkit::ScrollBar::IndicatorHeightPolicy mIndicatorHeightPolicy;  ///< The height policy of scroll indicator (variable or fixed)
222   float mIndicatorFixedHeight;                                      ///< The fixed height of scroll indicator
223
224   Timer mTimer;                                                      ///< The timer to process the pan gesture after the gesture is started.
225
226   Property::Index mPropertyIndicatorPosition;                        ///< Indicatore Position ("indicator-position")
227
228   PropertyNotification mPositionNotification;                        ///< Stores the property notification used for scroll position changes
229
230   ScrollPositionNotifiedSignalType mScrollPositionNotifiedSignal;
231
232   ActiveConstraint mIndicatorSizeConstraint;
233   ActiveConstraint mIndicatorPositionConstraint;
234 };
235
236 } // namespace Internal
237
238 // Helpers for public-api forwarding methods
239
240 inline Toolkit::Internal::ScrollBar& GetImpl(Toolkit::ScrollBar& scrollBar)
241 {
242   DALI_ASSERT_ALWAYS(scrollBar);
243
244   Dali::RefObject& handle = scrollBar.GetImplementation();
245
246   return static_cast<Toolkit::Internal::ScrollBar&>(handle);
247 }
248
249 inline const Toolkit::Internal::ScrollBar& GetImpl(const Toolkit::ScrollBar& scrollBar)
250 {
251   DALI_ASSERT_ALWAYS(scrollBar);
252
253   const Dali::RefObject& handle = scrollBar.GetImplementation();
254
255   return static_cast<const Toolkit::Internal::ScrollBar&>(handle);
256 }
257
258 } // namespace Toolkit
259
260 } // namespace Dali
261
262 #endif // __DALI_TOOLKIT_INTERNAL_SCROLL_BAR_H__