Remove Deprecated APIs
[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 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 // INTERNAL INCLUDES
22 #include <dali-toolkit/public-api/controls/scrollable/scroll-component-impl.h>
23 #include <dali-toolkit/public-api/controls/scrollable/scroll-connector.h>
24 #include <dali-toolkit/public-api/controls/scroll-bar/scroll-bar.h>
25
26 namespace Dali
27 {
28
29 namespace Toolkit
30 {
31
32 namespace Internal
33 {
34
35 class ScrollBar;
36
37 typedef IntrusivePtr<ScrollBar> ScrollBarPtr;
38
39 /**
40  * ScrollBar is a UI component that can be added to the scrollable controls
41  * indicating the current scroll position of the scrollable content.
42  */
43 class ScrollBar : public ScrollComponentImpl
44 {
45
46 public:
47
48   // Properties
49   enum
50   {
51     SCROLLBAR_PROPERTY_START_INDEX = Control::CONTROL_PROPERTY_END_INDEX + 1,
52     SCROLLBAR_PROPERTY_END_INDEX = SCROLLBAR_PROPERTY_START_INDEX + 1000 ///< Reserving 1000 property indices
53   };
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::Show()
117    */
118   void Show();
119
120   /**
121    * @copydoc Toolkit::ScrollBar::Hide()
122    */
123  void Hide();
124
125  /**
126   * Signal emitted after the SetScrollDomain() method has been called.
127   */
128  ScrollPositionNotifiedSignalType& ScrollPositionNotifiedSignal()
129  {
130    return mScrollPositionNotifiedSignal;
131  }
132
133  // Properties
134
135  /**
136   * Called when a property of an object of this type is set.
137   * @param[in] object The object whose property is set.
138   * @param[in] index The property index.
139   * @param[in] value The new property value.
140   */
141  static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
142
143  /**
144   * Called to retrieve a property of an object of this type.
145   * @param[in] object The object whose property is to be retrieved.
146   * @param[in] index The property index.
147   * @return The current value of the property.
148   */
149  static Property::Value GetProperty( BaseObject* object, Property::Index index );
150
151 private: // from Control
152
153   /**
154    * @copydoc Toolkit::Control::OnInitialize
155    */
156   virtual void OnInitialize();
157
158   /**
159    * @copydoc Toolkit::Control::OnPan
160    */
161   virtual void OnPan( PanGesture gesture );
162
163 private:
164
165   /**
166    * Apply constraints for background and indicator.
167    * These constraints are based on values from the scroll connector.
168    */
169   void ApplyConstraints();
170
171   /**
172    * Callback when the start & end position and size of the scrollable content are changed.
173    * @param[in] minPosition The minimum position.
174    * @param[in] maxPosition The maximum position.
175    * @param[in] contentSize The size of scrollable content.
176    */
177   void OnScrollDomainChanged(float minPosition, float maxPosition, float contentSize);
178
179   /**
180    * Callback when the current scroll position of the scrollable content goes above or
181    * below the values specified by SetPositionNotifications().
182    * @param[in] source the property notification that triggered this callback
183    */
184   void OnScrollPositionNotified(PropertyNotification& source);
185
186   /**
187    * Process the pan gesture per predefined timeout until the gesture is finished.
188    * @return True if the timer should be kept running.
189    */
190   bool OnPanGestureProcessTick();
191
192   /**
193    * Handle SetProperty for scroll indicator height policy.
194    * @param[in] propertyValue The new property value.
195    */
196   void OnIndicatorHeightPolicyPropertySet(Property::Value propertyValue);
197
198 private:
199
200   Constrainable mScrollPositionObject;                               ///< From mScrollConnector
201
202   ImageActor mBackground;                                            ///< Background image of scroll bar.
203   ImageActor mIndicator;                                             ///< Image of scroll indicator.
204   Animation mAnimation;                                              ///< Scroll indicator Show/Hide Animation.
205
206   float mScrollStart;                                               ///< Scroll Start position (start of drag)
207   Vector3 mGestureDisplacement;                                      ///< Gesture Displacement.
208
209   bool mIsPanning;                                                  ///< Whether the scroll bar is being panned.
210   float mCurrentScrollPosition;                                     ///< The current scroll position updated by the pan gesture
211
212   Toolkit::ScrollBar::IndicatorHeightPolicy mIndicatorHeightPolicy;  ///< The height policy of scroll indicator (variable or fixed)
213   float mIndicatorFixedHeight;                                      ///< The fixed height of scroll indicator
214
215   Timer mTimer;                                                      ///< The timer to process the pan gesture after the gesture is started.
216
217   Property::Index mPropertyIndicatorPosition;                        ///< Indicatore Position ("indicator-position")
218
219   PropertyNotification mPositionNotification;                        ///< Stores the property notification used for scroll position changes
220
221   ScrollPositionNotifiedSignalType mScrollPositionNotifiedSignal;
222
223   ActiveConstraint mIndicatorSizeConstraint;
224   ActiveConstraint mIndicatorPositionConstraint;
225 };
226
227 } // namespace Internal
228
229 // Helpers for public-api forwarding methods
230
231 inline Toolkit::Internal::ScrollBar& GetImpl(Toolkit::ScrollBar& scrollBar)
232 {
233   DALI_ASSERT_ALWAYS(scrollBar);
234
235   Dali::RefObject& handle = scrollBar.GetImplementation();
236
237   return static_cast<Toolkit::Internal::ScrollBar&>(handle);
238 }
239
240 inline const Toolkit::Internal::ScrollBar& GetImpl(const Toolkit::ScrollBar& scrollBar)
241 {
242   DALI_ASSERT_ALWAYS(scrollBar);
243
244   const Dali::RefObject& handle = scrollBar.GetImplementation();
245
246   return static_cast<const Toolkit::Internal::ScrollBar&>(handle);
247 }
248
249 } // namespace Toolkit
250
251 } // namespace Dali
252
253 #endif // __DALI_TOOLKIT_INTERNAL_SCROLL_BAR_H__