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