Implemented scroll bar control
[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 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/control-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 ControlImpl
43 {
44
45 public:
46
47   typedef Toolkit::ScrollBar::ScrollPositionNotifiedSignalType ScrollPositionNotifiedSignalType;
48
49 public:
50
51   /**
52    * @copydoc Toolkit::ScrollBar::ScrollBar()
53    */
54   ScrollBar();
55
56   /**
57    * @copydoc Toolkit::ScrollBar::~ScrollBar()
58    */
59   virtual ~ScrollBar();
60
61   /**
62    * @copydoc Toolkit::ScrollBar::New()
63    */
64   static Toolkit::ScrollBar New();
65
66   /**
67    * @copydoc Toolkit::ScrollBar::SetScrollConnector()
68    */
69   void SetScrollConnector( Toolkit::ScrollConnector connector );
70
71   /**
72    * @copydoc Toolkit::ScrollBar::SetBackgroundImage()
73    */
74   void SetBackgroundImage( Image image, const Vector4& border );
75
76   /**
77    * @copydoc Toolkit::ScrollBar::SetIndicatorImage()
78    */
79   void SetIndicatorImage( Image image, const Vector4& border );
80
81   /**
82    * @copydoc Toolkit::ScrollBar::GetScrollIndicator()
83    */
84   Actor GetScrollIndicator();
85
86   /**
87    * @copydoc Toolkit::ScrollBar::SetPositionNotifications()
88    */
89   void SetPositionNotifications( const std::vector<float>& positions );
90
91   /**
92    * @copydoc Toolkit::ScrollBar::Show()
93    */
94   void Show();
95
96   /**
97    * @copydoc Toolkit::ScrollBar::Hide()
98    */
99  void Hide();
100
101  /**
102   * Signal emitted after the SetScrollDomain() method has been called.
103   */
104  ScrollPositionNotifiedSignalType& ScrollPositionNotifiedSignal()
105  {
106    return mScrollPositionNotifiedSignal;
107  }
108
109 private: // from ControlImpl
110
111   /**
112    * @copydoc Toolkit::Control::OnInitialize
113    */
114   virtual void OnInitialize();
115
116   /**
117    * @copydoc Toolkit::Control::OnPan
118    */
119   virtual void OnPan( PanGesture gesture );
120
121 private:
122
123   /**
124    * Apply constraints for background and indicator.
125    * These constraints are based on values from the scroll connector.
126    */
127   void ApplyConstraints();
128
129   /**
130    * Callback when the start & end position and size of the scrollable content are changed.
131    * @param[in] minPosition The minimum position.
132    * @param[in] maxPosition The maximum position.
133    * @param[in] contentSize The size of scrollable content.
134    */
135   void OnScrollDomainChanged(float minPosition, float maxPosition, float contentSize);
136
137   /**
138    * Callback when the current scroll position of the scrollable content goes above or
139    * below the values specified by SetPositionNotifications().
140    * @param[in] source the property notification that triggered this callback
141    */
142   void OnScrollPositionNotified(PropertyNotification& source);
143
144 private:
145
146   Toolkit::ScrollConnector mScrollConnector;              ///< Connects scroll bar with the scrollable container.
147   Constrainable mScrollPositionObject;                    ///< From mScrollConnector
148
149   ImageActor mBackground;                                 ///< Background image of scroll bar.
150   ImageActor mIndicator;                                  ///< Image of scroll indicator.
151   Animation mAnimation;                                   ///< Scroll indicator Show/Hide Animation.
152
153   float mScrollStart;                                     ///< Scroll Start position (start of drag)
154   Vector3 mGestureDisplacement;                           ///< Gesture Displacement.
155
156   Property::Index mPropertyIndicatorPosition;             ///< Indicatore Position ("indicator-position")
157
158   PropertyNotification mPositionNotification;             ///< Stores the property notification used for scroll position changes
159
160   ScrollPositionNotifiedSignalType mScrollPositionNotifiedSignal;
161 };
162
163 } // namespace Internal
164
165 // Helpers for public-api forwarding methods
166
167 inline Toolkit::Internal::ScrollBar& GetImpl(Toolkit::ScrollBar& scrollBar)
168 {
169   DALI_ASSERT_ALWAYS(scrollBar);
170
171   Dali::RefObject& handle = scrollBar.GetImplementation();
172
173   return static_cast<Toolkit::Internal::ScrollBar&>(handle);
174 }
175
176 inline const Toolkit::Internal::ScrollBar& GetImpl(const Toolkit::ScrollBar& scrollBar)
177 {
178   DALI_ASSERT_ALWAYS(scrollBar);
179
180   const Dali::RefObject& handle = scrollBar.GetImplementation();
181
182   return static_cast<const Toolkit::Internal::ScrollBar&>(handle);
183 }
184
185 } // namespace Toolkit
186
187 } // namespace Dali
188
189 #endif // __DALI_TOOLKIT_INTERNAL_SCROLL_BAR_H__