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