License conversion from Flora to Apache 2.0
[platform/core/uifw/dali-toolkit.git] / base / dali-toolkit / internal / controls / scroll-component / scroll-bar-internal-impl.h
1 #ifndef __DALI_TOOLKIT_INTERNAL_SCROLL_BAR_INTERNAL_H__
2 #define __DALI_TOOLKIT_INTERNAL_SCROLL_BAR_INTERNAL_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/internal/controls/scrollable/scrollable-impl.h>
24 #include <dali-toolkit/internal/controls/scroll-component/scroll-bar-internal.h>
25
26 namespace Dali
27 {
28
29 namespace Toolkit
30 {
31
32 namespace Internal
33 {
34
35 /**
36  * ScrollBarInternal 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 ScrollBarInternal : public ScrollComponentImpl
40 {
41
42 public:
43
44   /**
45    * ScrollBarInternal constructor.
46    * @param[in] container Reference to the container of scroll bar
47    * @param[in] vertical Whether ScrollBarInternal should be oriented vertically (true)
48    * or horizontally (false)
49    */
50   ScrollBarInternal(Toolkit::Scrollable& container, bool vertical);
51
52   /**
53    * Virtual destructor
54    */
55   virtual ~ScrollBarInternal();
56
57   /**
58    * Create an initialized ScrollBarInternal
59    * @param[in] container Reference to the container of scroll bar
60    * @param[in] vertical Whether ScrollBarInternal should be oriented vertically (true)
61    * or horizontally (false)
62    * @return A pointer to the created ScrollBarInternal.
63    */
64   static Toolkit::ScrollBarInternal New(Toolkit::Scrollable& container, bool vertical);
65
66   /**
67    * Show ScrollBarInternal
68    */
69   void Show();
70
71   /**
72    * Hide ScrollBarInternal
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::ScrollBarInternal& GetImpl(Toolkit::ScrollBarInternal& scrollBar)
148 {
149   DALI_ASSERT_ALWAYS(scrollBar);
150
151   Dali::RefObject& handle = scrollBar.GetImplementation();
152
153   return static_cast<Toolkit::Internal::ScrollBarInternal&>(handle);
154 }
155
156 inline const Toolkit::Internal::ScrollBarInternal& GetImpl(const Toolkit::ScrollBarInternal& scrollBar)
157 {
158   DALI_ASSERT_ALWAYS(scrollBar);
159
160   const Dali::RefObject& handle = scrollBar.GetImplementation();
161
162   return static_cast<const Toolkit::Internal::ScrollBarInternal&>(handle);
163 }
164
165 } // namespace Toolkit
166
167 } // namespace Dali
168
169 #endif // __DALI_TOOLKIT_INTERNAL_SCROLL_BAR_INTERNAL_H__