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