f1acd752db3f6bf85c444669c7805bb04d91b02e
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / scroll-component / 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/internal/controls/scroll-component/scroll-component-impl.h>
22 #include <dali-toolkit/internal/controls/scrollable/scrollable-impl.h>
23 #include <dali-toolkit/public-api/controls/scroll-component/scroll-bar.h>
24 #include <dali-toolkit/public-api/controls/control-impl.h>
25
26 namespace Dali
27 {
28
29 namespace Toolkit
30 {
31
32 namespace Internal
33 {
34
35 /**
36  * ScrollBar is a UI component that can be added to the sides of the ScrollView
37  * indicating the current scroll position within the domain.
38  */
39 class ScrollBar : public ScrollComponent
40 {
41
42 public:
43
44   /**
45    * ScrollBar constructor.
46    * @param[in] container Reference to the container of scroll bar
47    * @param[in] vertical Whether ScrollBar should be oriented vertically (true)
48    * or horizontally (false)
49    */
50   ScrollBar(Toolkit::Scrollable& container, bool vertical);
51
52   /**
53    * Virtual destructor
54    */
55   virtual ~ScrollBar();
56
57   /**
58    * Create an initialized ScrollBar
59    * @param[in] container Reference to the container of scroll bar
60    * @param[in] vertical Whether ScrollBar should be oriented vertically (true)
61    * or horizontally (false)
62    * @return A pointer to the created ScrollBar.
63    */
64   static Toolkit::ScrollBar New(Toolkit::Scrollable& container, bool vertical);
65
66   /**
67    * Show ScrollBar
68    */
69   void Show();
70
71   /**
72    * Hide ScrollBar
73    */
74   void Hide();
75
76 private:
77
78   /**
79    * @copydoc Toolkit::Control::OnInitialize()
80    */
81   virtual void OnInitialize();
82
83   /**
84    * @copydoc Toolkit::ScrollComponent::OnDisconnect()
85    */
86   virtual void OnDisconnect();
87
88   /**
89    * Called when scrollbar is dragged.
90    * @param[in] actor Actor under touch
91    * @param[in] gesture The pan gesture data.
92    */
93   void OnPanGesture(Actor actor, PanGesture gesture);
94
95   /**
96    * Called when scrolling starts (scroll bars should extend out)
97    * @param[in] position current scroll position.
98    */
99   void OnStarted(const Vector3& position);
100
101   /**
102    * Called when scrolling ends (scroll bars should contract)
103    * @param[in] position current scroll position.
104    */
105   void OnCompleted(const Vector3& position);
106
107   /**
108    * Called when timer is finished. This time guarantee contract animation time.
109    * @return Timer is used or not.
110    */
111   bool OnContractDelayExpired(void);
112
113   /**
114    * Create timer. This timer used for wating contract.
115    */
116   void CreateTimer();
117
118   /**
119    * Destruct timer.
120    */
121   void DestructTimer();
122
123   /**
124    * Wait ContractTime
125    */
126   void WaitingContractDelay();
127
128 private:
129   Scrollable& mContainer;                                 ///< Container of scroll bar
130   ImageActor mSlider;                                     ///< Scroll Slider.
131   ImageActor mSliderWrap;                                 ///< Scroll Slider (wrapped view).
132   Actor mHitArea;                                         ///< Hit Area for dragging scroll slider.
133   PanGestureDetector mPanGesture;                         ///< Pan Gesture detector for dragging scrollbar.
134   Animation mAnimation;                                   ///< Scroll Contract/Expand Animation.
135   bool mVertical;                                         ///< Scroll Axis (Vertical or Horizontal)
136   Vector3 mAxisMask;                                      ///< Scroll Axis mask (Vector3::YAXIS for vert. or Vector3::XAXIS for horiz.)
137   Vector3 mScrollStart;                                   ///< Scroll Start position (start of drag)
138   Vector3 mGestureDisplacement;                           ///< Gesture Displacement.
139   bool mDragMode;                                         ///< Flag indicating whether currently dragging or not.
140   Timer mTimer;                                           ///< Timer guarantee contract delay time.
141 };
142
143 } // namespace Internal
144
145 // Helpers for public-api forwarding methods
146
147 inline Toolkit::Internal::ScrollBar& GetImpl(Toolkit::ScrollBar& scrollBar)
148 {
149   DALI_ASSERT_ALWAYS(scrollBar);
150
151   Dali::RefObject& handle = scrollBar.GetImplementation();
152
153   return static_cast<Toolkit::Internal::ScrollBar&>(handle);
154 }
155
156 inline const Toolkit::Internal::ScrollBar& GetImpl(const Toolkit::ScrollBar& scrollBar)
157 {
158   DALI_ASSERT_ALWAYS(scrollBar);
159
160   const Dali::RefObject& handle = scrollBar.GetImplementation();
161
162   return static_cast<const Toolkit::Internal::ScrollBar&>(handle);
163 }
164
165 } // namespace Toolkit
166
167 } // namespace Dali
168
169 #endif // __DALI_TOOLKIT_INTERNAL_SCROLL_BAR_H__