Scrollable public API clean-up phase 1
[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) 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 // EXTERNAL INCLUDES
22 #include <dali/public-api/common/map-wrapper.h>
23
24 // INTERNAL INCLUDES
25 #include <dali-toolkit/public-api/controls/control-impl.h>
26 #include <dali-toolkit/public-api/controls/scrollable/scrollable.h>
27 #include <dali-toolkit/public-api/controls/scrollable/scroll-component-impl.h>
28
29 namespace Dali
30 {
31
32 namespace Toolkit
33 {
34
35 namespace Internal
36 {
37
38 class Scrollable;
39 typedef IntrusivePtr<Scrollable> ScrollablePtr;
40
41 /**
42  * @copydoc Toolkit::Scrollable
43  */
44 class Scrollable : public Control
45 {
46 public:
47   static const std::string SCROLLABLE_CAN_SCROLL_VERTICAL;
48   static const std::string SCROLLABLE_CAN_SCROLL_HORIZONTAL;
49
50   /**
51    * Create a new Scrollable.
52    * @return A public handle to the newly allocated Scrollable.
53    */
54 //  static Dali::Toolkit::Scrollable New();
55
56 public:
57
58   /**
59    * @copydoc Dali::Toolkit::Scrollable::IsScrollComponentEnabled(Scrollable::ScrollComponentType type)
60    */
61   bool IsScrollComponentEnabled(Toolkit::Scrollable::ScrollComponentType type) const;
62
63   /**
64    * @copydoc Dali::Toolkit::Scrollable::EnableScrollComponent(Scrollable::ScrollComponentType type)
65    */
66   void EnableScrollComponent(Toolkit::Scrollable::ScrollComponentType type);
67
68   /**
69    * @copydoc Dali::Toolkit::Scrollable::DisableScrollComponent(Scrollable::ScrollComponentType type)
70    */
71   void DisableScrollComponent(Toolkit::Scrollable::ScrollComponentType type);
72
73   /**
74    * Gets the size of the domain (minimum/maximum extents for each axis to scroll to)
75    * @return the domain size
76    */
77   virtual Vector3 GetDomainSize() const = 0;
78
79   /**
80    * Adds actor as an Overlay to Scrollable
81    * This method is called by Add-on UI components
82    * such as scroll bars, page indicators.
83    * @param[in] actor Actor to add as an overlay.
84    */
85   virtual void AddOverlay(Actor actor) = 0;
86
87   /**
88    * Removes overlay actor from Scrollable
89    * This method is called by Add-on UI components
90    * such as scroll bars, page indicators.
91    * @param[in] actor Actor overlay to remove.
92    */
93   virtual void RemoveOverlay(Actor actor) = 0;
94
95   /**
96    * Retrieves current scroll position.
97    * @returns The current scroll position.
98    */
99   virtual Vector3 GetCurrentScrollPosition() const = 0;
100
101   /**
102    * Scrolls Scrollable to position specified (contents will scroll to this position)
103    * Position 0,0 is the origin. Increasing X scrolls contents left, while
104    * increasing Y scrolls contents up.
105    * @param[in] position The position to scroll to.
106    * @param[in] duration The duration of the animation in seconds
107    */
108   virtual void ScrollTo(const Vector3 &position, float duration) = 0;
109
110   /**
111    * Set the color of the overshoot effect.
112    * @parm[in] color The color of the overshoot effect
113    */
114   virtual void SetOvershootEffectColor( const Vector4& color ) = 0;
115
116   /**
117    * Retrieve the color of the overshoot effect.
118    * @return The color of the overshoot effect.
119    */
120   Vector4 GetOvershootEffectColor() const;
121
122   /**
123    * @copydoc Dali::Toolkit::Scrollable::SetOvershootAnimationSpeed(float pixelsPerSecond)
124    */
125   void SetOvershootAnimationSpeed( float pixelsPerSecond );
126
127   /**
128    * @copydoc Dali::Toolkit::Scrollable::GetOvershootAnimationSpeed()
129    */
130   float GetOvershootAnimationSpeed() const;
131
132 private:
133
134   /**
135    * Temporary function to override EnableScrollComponent functionality for overshoot
136    * Only ScrollView needs to override this as HQ has not requested disable functionality in ItemView
137    * @param[in] enable true to enable, false to disable overshoot indicator
138    */
139   virtual void SetOvershootEnabled(bool enable) {}
140
141 public: //Signals
142
143   /**
144    * @copydoc Dali::Toolkit::Scrollable::ScrollStartedSignal()
145    */
146   Toolkit::Scrollable::ScrollStartedSignalType& ScrollStartedSignal();
147
148   /**
149    * @copydoc Dali::Toolkit::Scrollable::ScrollUpdatedSignal()
150    */
151   Toolkit::Scrollable::ScrollUpdatedSignalType& ScrollUpdatedSignal();
152
153   /**
154    * @copydoc Dali::Toolkit::Scrollable::ScrollCompletedSignal()
155    */
156   Toolkit::Scrollable::ScrollCompletedSignalType& ScrollCompletedSignal();
157
158   /**
159    * Connects a callback function with the object's signals.
160    * @param[in] object The object providing the signal.
161    * @param[in] tracker Used to disconnect the signal.
162    * @param[in] signalName The signal to connect to.
163    * @param[in] functor A newly allocated FunctorDelegate.
164    * @return True if the signal was connected.
165    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
166    */
167   static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
168
169   //properties
170
171   /**
172    * Called when a property of an object of this type is set.
173    * @param[in] object The object whose property is set.
174    * @param[in] index The property index.
175    * @param[in] value The new property value.
176    */
177   static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
178
179   /**
180    * Called to retrieve a property of an object of this type.
181    * @param[in] object The object whose property is to be retrieved.
182    * @param[in] index The property index.
183    * @return The current value of the property.
184    */
185   static Property::Value GetProperty( BaseObject* object, Property::Index index );
186
187 protected:
188
189   /**
190    * Construct a new Scrollable.
191    */
192   Scrollable();
193
194   /**
195    * A reference counted object may only be deleted by calling Unreference()
196    */
197   virtual ~Scrollable();
198
199   /**
200    * Register common properties
201    */
202   void RegisterCommonProperties();
203
204 private:
205
206   /**
207    * Gets position property.
208    *
209    * @return The current position
210    */
211   Vector3 GetPropertyPosition() const;
212
213 private:
214
215   // Undefined
216   Scrollable(const Scrollable&);
217
218   // Undefined
219   Scrollable& operator=(const Scrollable& rhs);
220
221   /**
222    * Helper to create an initialized ScrollComponent
223    * @param[in] scrollable reference to ScrollView implementation
224    * @param[in] type the type of scroll component to create.
225    * @return A pointer to the created ScrollComponent.
226    */
227   Toolkit::ScrollComponent NewScrollComponent(Toolkit::Scrollable& scrollable, Toolkit::Scrollable::ScrollComponentType type);
228
229 protected:
230
231   Vector4         mOvershootEffectColor;    ///<The color of the overshoot bouncing effect
232   float           mOvershootAnimationSpeed; ///<The speed of the overshoot animation (pixels per second)
233
234   Property::Index mPropertyRelativePosition;///< Scroll Relative Position ("scroll-relative-position") [range from 0.0f - 1.0f in each axes]
235   Property::Index mPropertyPositionMin;     ///< Scroll Domain Minimum ("position-min")
236   Property::Index mPropertyPositionMax;     ///< Scroll Domain Maximum ("position-max")
237   Property::Index mPropertyScrollDirection; ///< Scroll direction ("scroll-direction")
238   Property::Index mPropertyCanScrollVertical;    ///< Whether the current scroll domain is large enough to scroll vertically
239   Property::Index mPropertyCanScrollHorizontal;    ///< Whether the current scroll domain is large enough to scroll horizontally
240
241   std::map<Toolkit::Scrollable::ScrollComponentType, ScrollComponentPtr> mComponent;  ///< ScrollComponent (such as a scrollbar/page indicator/status)
242
243   Toolkit::Scrollable::ScrollStartedSignalType mScrollStartedSignal;
244   Toolkit::Scrollable::ScrollUpdatedSignalType mScrollUpdatedSignal;
245   Toolkit::Scrollable::ScrollCompletedSignalType mScrollCompletedSignal;
246
247 private:
248
249   typedef std::map<Toolkit::Scrollable::ScrollComponentType, ScrollComponentPtr> ComponentContainer;
250   typedef ComponentContainer::iterator ComponentIter;
251
252   ComponentContainer mComponents;  ///< ScrollComponent (such as a scrollbar/page indicator/status)
253   bool mOvershootEnabled:1;
254 };
255
256 } // namespace Internal
257
258 // Helpers for public-api forwarding methods
259
260 inline Toolkit::Internal::Scrollable& GetImpl(Toolkit::Scrollable& scrollable)
261 {
262   DALI_ASSERT_ALWAYS(scrollable);
263
264   Dali::RefObject& handle = scrollable.GetImplementation();
265
266   return static_cast<Toolkit::Internal::Scrollable&>(handle);
267 }
268
269 inline const Toolkit::Internal::Scrollable& GetImpl(const Toolkit::Scrollable& scrollable)
270 {
271   DALI_ASSERT_ALWAYS(scrollable);
272
273   const Dali::RefObject& handle = scrollable.GetImplementation();
274
275   return static_cast<const Toolkit::Internal::Scrollable&>(handle);
276 }
277
278 } // namespace Toolkit
279
280 } // namespace Dali
281
282 #endif // __DALI_TOOLKIT_INTERNAL_SCROLLABLE_H__