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