Merge branch 'master' into tizen
[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 Flora License, Version 1.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://floralicense.org/license/
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 // INTERNAL INCLUDES
21 #include <dali/dali.h>
22
23 #include <dali-toolkit/public-api/controls/control-impl.h>
24 #include <dali-toolkit/public-api/controls/scrollable/scrollable.h>
25 #include <dali-toolkit/public-api/controls/scrollable/scroll-component-impl.h>
26
27 namespace Dali
28 {
29
30 namespace Toolkit
31 {
32
33 namespace Internal
34 {
35
36 class Scrollable;
37 typedef IntrusivePtr<Scrollable> ScrollablePtr;
38
39 /**
40  * @copydoc Toolkit::Scrollable
41  */
42 class Scrollable : public Control
43 {
44 public:
45   static const std::string SCROLLABLE_CAN_SCROLL_VERTICAL;
46   static const std::string SCROLLABLE_CAN_SCROLL_HORIZONTAL;
47   static const Vector4     DEFAULT_OVERSHOOT_COLOUR;
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 private:
110
111   /**
112    * Temporary function to override EnableScrollComponent functionality for overshoot
113    * Only ScrollView needs to override this as HQ has not requested disable functionality in ItemView
114    * @param[in] enable true to enable, false to disable overshoot indicator
115    */
116   virtual void SetOvershootEnabled(bool enable) {}
117
118 public: //Signals
119
120   /**
121    * @copydoc Dali::Toolkit::Scrollable::ScrollStartedSignal()
122    */
123   Toolkit::Scrollable::ScrollStartedSignalV2& ScrollStartedSignal();
124
125   /**
126    * @copydoc Dali::Toolkit::Scrollable::ScrollUpdatedSignal()
127    */
128   Toolkit::Scrollable::ScrollUpdatedSignalV2& ScrollUpdatedSignal();
129
130   /**
131    * @copydoc Dali::Toolkit::Scrollable::ScrollCompletedSignal()
132    */
133   Toolkit::Scrollable::ScrollCompletedSignalV2& ScrollCompletedSignal();
134
135   /**
136    * @copydoc Dali::Toolkit::Scrollable::ScrollClampedSignal()
137    */
138   Toolkit::Scrollable::ScrollClampedSignalV2& ScrollClampedSignal();
139
140   /**
141    * Connects a callback function with the object's signals.
142    * @param[in] object The object providing the signal.
143    * @param[in] tracker Used to disconnect the signal.
144    * @param[in] signalName The signal to connect to.
145    * @param[in] functor A newly allocated FunctorDelegate.
146    * @return True if the signal was connected.
147    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
148    */
149   static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
150
151 protected:
152
153   /**
154    * Construct a new Scrollable.
155    */
156   Scrollable();
157
158   /**
159    * A reference counted object may only be deleted by calling Unreference()
160    */
161   virtual ~Scrollable();
162
163   /**
164    * Register common properties
165    */
166   void RegisterCommonProperties();
167
168 private:
169
170   /**
171    * Gets position property.
172    *
173    * @return The current position
174    */
175   Vector3 GetPropertyPosition() const;
176
177 private:
178
179   // Undefined
180   Scrollable(const Scrollable&);
181
182   // Undefined
183   Scrollable& operator=(const Scrollable& rhs);
184
185   /**
186    * Helper to create an initialized ScrollComponent
187    * @param[in] scrollable reference to ScrollView implementation
188    * @param[in] type the type of scroll component to create.
189    * @return A pointer to the created ScrollComponent.
190    */
191   Toolkit::ScrollComponent NewScrollComponent(Toolkit::Scrollable& scrollable, Toolkit::Scrollable::ScrollComponentType type);
192
193 protected:
194
195   Property::Index mPropertyRelativePosition;///< Scroll Relative Position ("scroll-relative-position") [range from 0.0f - 1.0f in each axes]
196   Property::Index mPropertyPositionMin;     ///< Scroll Domain Minimum ("position-min")
197   Property::Index mPropertyPositionMax;     ///< Scroll Domain Maximum ("position-max")
198   Property::Index mPropertyScrollDirection; ///< Scroll direction ("scroll-direction")
199   Property::Index mPropertyCanScrollVertical;    ///< Whether the current scroll domain is large enough to scroll vertically
200   Property::Index mPropertyCanScrollHorizontal;    ///< Whether the current scroll domain is large enough to scroll horizontally
201
202   std::map<Toolkit::Scrollable::ScrollComponentType, ScrollComponentPtr> mComponent;  ///< ScrollComponent (such as a scrollbar/page indicator/status)
203
204   Toolkit::Scrollable::ScrollStartedSignalV2 mScrollStartedSignalV2;
205   Toolkit::Scrollable::ScrollUpdatedSignalV2 mScrollUpdatedSignalV2;
206   Toolkit::Scrollable::ScrollCompletedSignalV2 mScrollCompletedSignalV2;
207   Toolkit::Scrollable::ScrollClampedSignalV2 mScrollClampedSignalV2;
208
209 private:
210
211   typedef std::map<Toolkit::Scrollable::ScrollComponentType, ScrollComponentPtr> ComponentContainer;
212   typedef ComponentContainer::iterator ComponentIter;
213
214   ComponentContainer mComponents;  ///< ScrollComponent (such as a scrollbar/page indicator/status)
215   bool mOvershootEnabled;
216 };
217
218 } // namespace Internal
219
220 // Helpers for public-api forwarding methods
221
222 inline Toolkit::Internal::Scrollable& GetImpl(Toolkit::Scrollable& scrollable)
223 {
224   DALI_ASSERT_ALWAYS(scrollable);
225
226   Dali::RefObject& handle = scrollable.GetImplementation();
227
228   return static_cast<Toolkit::Internal::Scrollable&>(handle);
229 }
230
231 inline const Toolkit::Internal::Scrollable& GetImpl(const Toolkit::Scrollable& scrollable)
232 {
233   DALI_ASSERT_ALWAYS(scrollable);
234
235   const Dali::RefObject& handle = scrollable.GetImplementation();
236
237   return static_cast<const Toolkit::Internal::Scrollable&>(handle);
238 }
239
240 } // namespace Toolkit
241
242 } // namespace Dali
243
244 #endif // __DALI_TOOLKIT_INTERNAL_SCROLLABLE_H__