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