Updated all header files to new format
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / scrollable / scrollable-impl.h
1 #ifndef DALI_TOOLKIT_INTERNAL_SCROLLABLE_H
2 #define DALI_TOOLKIT_INTERNAL_SCROLLABLE_H
3
4 /*
5  * Copyright (c) 2021 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 // EXTERNAL INCLUDES
22 #include <dali/public-api/animation/alpha-function.h>
23
24 // INTERNAL INCLUDES
25 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
26 #include <dali-toolkit/public-api/controls/control-impl.h>
27 #include <dali-toolkit/public-api/controls/scrollable/scrollable.h>
28
29 namespace Dali
30 {
31 namespace Toolkit
32 {
33 namespace Internal
34 {
35 class Scrollable;
36 typedef IntrusivePtr<Scrollable> ScrollablePtr;
37
38 /**
39  * @copydoc Toolkit::Scrollable
40  */
41 class Scrollable : public Control
42 {
43 public:
44   /**
45    * @copydoc Dali::Toolkit::Scrollable::IsOvershootEnabled
46    */
47   bool IsOvershootEnabled() const;
48
49   /**
50    * @copydoc Dali::Toolkit::Scrollable::SetOvershootEnabled
51    */
52   void SetOvershootEnabled(bool enable);
53
54   /**
55    * Adds actor as an Overlay to Scrollable
56    * This method is called by Add-on UI components
57    * such as scroll bars, page indicators.
58    * @param[in] actor Actor to add as an overlay.
59    */
60   virtual void AddOverlay(Actor actor) = 0;
61
62   /**
63    * Removes overlay actor from Scrollable
64    * This method is called by Add-on UI components
65    * such as scroll bars, page indicators.
66    * @param[in] actor Actor overlay to remove.
67    */
68   virtual void RemoveOverlay(Actor actor) = 0;
69
70   /**
71    * Retrieves current scroll position.
72    * @returns The current scroll position.
73    */
74   virtual Vector2 GetCurrentScrollPosition() const = 0;
75
76   /**
77    * Scrolls Scrollable to position specified (contents will scroll to this position)
78    * Position 0,0 is the origin. Increasing X scrolls contents left, while
79    * increasing Y scrolls contents up.
80    * @param[in] position The position to scroll to.
81    * @param[in] duration The duration of the animation in seconds
82    */
83   virtual void ScrollTo(const Vector2& position, float duration) = 0;
84
85   /**
86    * Set the color of the overshoot effect.
87    * @parm[in] color The color of the overshoot effect
88    */
89   virtual void SetOvershootEffectColor(const Vector4& color) = 0;
90
91   /**
92    * Retrieve the color of the overshoot effect.
93    * @return The color of the overshoot effect.
94    */
95   Vector4 GetOvershootEffectColor() const;
96
97   /**
98    * @copydoc Dali::Toolkit::Scrollable::SetOvershootAnimationSpeed(float pixelsPerSecond)
99    */
100   void SetOvershootAnimationSpeed(float pixelsPerSecond);
101
102   /**
103    * @copydoc Dali::Toolkit::Scrollable::GetOvershootAnimationSpeed()
104    */
105   float GetOvershootAnimationSpeed() const;
106
107   /**
108    * @copydoc Dali::Toolkit::Scrollable::GetOvershootSize()
109    */
110   const Vector2& GetOvershootSize() const;
111
112   /**
113    * Set the size of the overshoot effect.
114    * @parm[in] size The size of the overshoot effect
115    */
116   virtual void SetOvershootSize(const Vector2& size) = 0;
117
118 protected: // From Control
119   struct AccessibleImpl : public Control::Impl::AccessibleImpl
120   {
121     using Control::Impl::AccessibleImpl::AccessibleImpl;
122
123     bool IsScrollable() override;
124   };
125
126   /**
127    * @copydoc Control::OnInitialize
128    */
129   virtual void OnInitialize() override;
130
131 private:
132   /**
133    * Temporary function to override EnableScrollOvershoot functionality for overshoot
134    * Only ScrollView needs to override this as HQ has not requested disable functionality in ItemView
135    * @param[in] enable true to enable, false to disable overshoot indicator
136    */
137   virtual void EnableScrollOvershoot(bool enable)
138   {
139   }
140
141 public: //Signals
142   /**
143    * @copydoc Dali::Toolkit::Scrollable::ScrollStartedSignal()
144    */
145   Toolkit::Scrollable::ScrollStartedSignalType& ScrollStartedSignal();
146
147   /**
148    * @copydoc Dali::Toolkit::Scrollable::ScrollUpdatedSignal()
149    */
150   Toolkit::Scrollable::ScrollUpdatedSignalType& ScrollUpdatedSignal();
151
152   /**
153    * @copydoc Dali::Toolkit::Scrollable::ScrollCompletedSignal()
154    */
155   Toolkit::Scrollable::ScrollCompletedSignalType& ScrollCompletedSignal();
156
157   /**
158    * Connects a callback function with the object's signals.
159    * @param[in] object The object providing the signal.
160    * @param[in] tracker Used to disconnect the signal.
161    * @param[in] signalName The signal to connect to.
162    * @param[in] functor A newly allocated FunctorDelegate.
163    * @return True if the signal was connected.
164    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
165    */
166   static bool DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor);
167
168   //properties
169
170   /**
171    * Called when a property of an object of this type is set.
172    * @param[in] object The object whose property is set.
173    * @param[in] index The property index.
174    * @param[in] value The new property value.
175    */
176   static void SetProperty(BaseObject* object, Property::Index index, const Property::Value& value);
177
178   /**
179    * Called to retrieve a property of an object of this type.
180    * @param[in] object The object whose property is to be retrieved.
181    * @param[in] index The property index.
182    * @return The current value of the property.
183    */
184   static Property::Value GetProperty(BaseObject* object, Property::Index index);
185
186 protected:
187   /**
188    * Removed default constructor.
189    */
190   Scrollable() = delete;
191
192   /**
193    * @brief Construct a new Scrollable.
194    *
195    * @param[in] behaviourFlags Flags to enable
196    */
197   Scrollable(ControlBehaviour behaviourFlags);
198
199   /**
200    * A reference counted object may only be deleted by calling Unreference()
201    */
202   virtual ~Scrollable();
203
204 private:
205   /**
206    * Gets position property.
207    *
208    * @return The current position
209    */
210   Vector2 GetPropertyPosition() const;
211
212 private:
213   // Undefined
214   Scrollable(const Scrollable&);
215
216   // Undefined
217   Scrollable& operator=(const Scrollable& rhs);
218
219 protected:
220   Vector4 mOvershootEffectColor;    ///<The color of the overshoot bouncing effect
221   float   mOvershootAnimationSpeed; ///<The speed of the overshoot animation (pixels per second)
222   Vector2 mOvershootSize;           ///<The size of the overshoot effect
223
224   Dali::AlphaFunction::BuiltinFunction mScrollToAlphaFunction; ///< The ScrollTo() animations use this
225
226   Toolkit::Scrollable::ScrollStartedSignalType   mScrollStartedSignal;
227   Toolkit::Scrollable::ScrollUpdatedSignalType   mScrollUpdatedSignal;
228   Toolkit::Scrollable::ScrollCompletedSignalType mScrollCompletedSignal;
229
230 private:
231   bool mOvershootEnabled : 1;
232 };
233
234 } // namespace Internal
235
236 // Helpers for public-api forwarding methods
237
238 inline Toolkit::Internal::Scrollable& GetImpl(Toolkit::Scrollable& scrollable)
239 {
240   DALI_ASSERT_ALWAYS(scrollable);
241
242   Dali::RefObject& handle = scrollable.GetImplementation();
243
244   return static_cast<Toolkit::Internal::Scrollable&>(handle);
245 }
246
247 inline const Toolkit::Internal::Scrollable& GetImpl(const Toolkit::Scrollable& scrollable)
248 {
249   DALI_ASSERT_ALWAYS(scrollable);
250
251   const Dali::RefObject& handle = scrollable.GetImplementation();
252
253   return static_cast<const Toolkit::Internal::Scrollable&>(handle);
254 }
255
256 } // namespace Toolkit
257
258 } // namespace Dali
259
260 #endif // DALI_TOOLKIT_INTERNAL_SCROLLABLE_H