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