fa9693e3372b4576d24ff4e40810588f5a989fc2
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / scrollable / scroll-view / scroll-base-impl.h
1 #ifndef __DALI_TOOLKIT_INTERNAL_SCROLL_BASE_H__
2 #define __DALI_TOOLKIT_INTERNAL_SCROLL_BASE_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 // TODO - Replace list with dali-vector.h
23 #include <list>
24
25 // INTERNAL INCLUDES
26
27 #include <dali-toolkit/public-api/controls/scrollable/scroll-view/scroll-view.h>
28 #include <dali-toolkit/internal/controls/scrollable/scrollable-impl.h>
29
30 namespace Dali
31 {
32
33 namespace Toolkit
34 {
35
36 namespace Internal
37 {
38
39 class ScrollBase;
40
41 typedef IntrusivePtr<Actor>         ActorPtr;
42 typedef std::list<Constraint>               ConstraintStack;
43
44 /**
45  * ScrollBase represents a set of properties (time, position
46  * scale etc.) that constrain a set of actors.
47  */
48 class ScrollBase : public Scrollable
49 {
50 public:
51
52   struct ActorInfo : public Dali::RefObject
53   {
54     /**
55      * ActorInfo constructor
56      * @param[in] actor The actor that this ActorInfo represents.
57      */
58     ActorInfo(Actor actor)
59     : mActor(actor)
60     {
61     }
62
63     /**
64      * ActorInfo destructor
65      * removes scrollview-related constraints only.
66      */
67     ~ActorInfo()
68     {
69       RemoveConstraints();
70     }
71
72     /**
73      * Apply a constraint to this actor
74      * The constraint will be applied to the actor,
75      * and the ActorInfo will keep track of this constraint.
76      * @param[in] constraint The constraint to apply to the actor
77      */
78     void ApplyConstraint(Constraint constraint)
79     {
80       ActiveConstraint activeConstraint = mActor.ApplyConstraint( constraint );
81       mConstraints.push_back( activeConstraint );
82     }
83
84     /**
85      * Remove constraints from this actor.
86      * All of the constraints that have been applied to the
87      * actor via this ActorInfo will be removed.
88      */
89     void RemoveConstraints()
90     {
91       std::vector<ActiveConstraint>::iterator it = mConstraints.begin();
92       std::vector<ActiveConstraint>::iterator end = mConstraints.end();
93       for(;it!=end;++it)
94       {
95         mActor.RemoveConstraint(*it);
96       }
97       mConstraints.clear();
98     }
99
100     Actor mActor;                                     ///< The Actor that this ActorInfo represents.
101     std::vector<ActiveConstraint> mConstraints;       ///< A list keeping track of constraints applied to the actor via this delegate.
102   };
103
104   typedef IntrusivePtr<ActorInfo> ActorInfoPtr;
105   typedef std::vector<ActorInfoPtr> ActorInfoContainer;
106   typedef ActorInfoContainer::iterator ActorInfoIter;
107   typedef ActorInfoContainer::const_iterator ActorInfoConstIter;
108
109 public:
110
111   /**
112    * Sets the delay in seconds.
113    * This delay affects the animation timing for all
114    * Bound Actors.
115    *
116    * @param[in] delay The delay in seconds.
117    */
118   void SetDelay(float delay)
119   {
120     mDelay = delay;
121   }
122
123   /**
124    * Gets the current delay in seconds.
125    *
126    * @return The delay in seconds.
127    */
128   float GetDelay() const
129   {
130     return mDelay;
131   }
132
133 public:
134
135   /**
136    * Sets ScrollBase Parent
137    *
138    * @param[in] parent The parent that this ScrollBase belongs to.
139    */
140   void SetParent(ScrollBase *parent);
141
142   /**
143    * Bind Actor to this scroll view/group.
144    * Once Bound, this scroll view/group will affect the actor (child)
145    *
146    * @param[in] child The actor to be bound.
147    */
148   void BindActor(Actor child);
149
150   /**
151    * Unbind Actor from this scroll view/group
152    * Once Unbound, this scroll view/group will not affect the actor
153    *
154    * @note this does not remove the child from the ScrollView container
155    *
156    * @param[in] child The actor to be unbound
157    */
158   void UnbindActor(Actor child);
159
160   /**
161    * Searches associated ScrollBases for the Actor, and attempts to Unbind
162    * systematically this Actor from the ScrollView or Groups attached.
163    *
164    * @param[in] child The actor to be unbound.
165    */
166   virtual void FindAndUnbindActor(Actor child);
167
168   /**
169    * Applies constraint to the bound actors within this ScrollView/Group only.
170    *
171    * @param[in] constraint, the constraint to apply to these bound actors and future
172    * ones.
173    */
174   void ApplyConstraintToBoundActors(Constraint constraint);
175
176   /**
177    * Removes all constraints from the bound actors within this ScrollView/Group only.
178    */
179   void RemoveConstraintsFromBoundActors();
180
181 protected:
182
183   static const std::string SCROLL_DOMAIN_OFFSET_PROPERTY_NAME;
184
185 protected:
186
187   /**
188    * Construct a new ScrollBase.
189    */
190   ScrollBase();
191
192   /**
193    * 2nd-phase initialization.
194    */
195   void RegisterProperties();
196
197 protected:
198
199   ScrollBase *mParent;                              ///< Pointer to ScrollBase parent, if exists.
200   Property::Index mPropertyTime;                    ///< Scroll Time (0 to animationDuration while animating, otherwise 0)
201   Property::Index mPropertyPrePosition;             ///< Scroll Position ("scroll-position") [function of scroll-x, scroll-y]
202   Property::Index mPropertyPosition;                ///< Scroll Position ("scroll-position") [function of scroll-pre-position]
203   Property::Index mPropertyScale;                   ///< Scroll Scale ("scroll-scale")
204   Property::Index mPropertyOvershootX;              ///< Scroll Overshoot ("scroll-overshoot-x") [function of scroll-pre-position, scroll-position]
205   Property::Index mPropertyOvershootY;              ///< Scroll Overshoot ("scroll-overshoot-y") [function of scroll-pre-position, scroll-position]
206   Property::Index mPropertyWrap;                    ///< Scroll Wrap ("scroll-wrap")
207   Property::Index mPropertyPanning;                 ///< Whether we are panning
208   Property::Index mPropertyScrolling;               ///< Whether we are scrolling
209   Property::Index mPropertyFinal;                   ///< Scroll Final Position ("scroll-final") [scroll-position + f(scroll-overshoot)]
210   Property::Index mPropertyDomainOffset;            ///< Scroll Domain Offset ("scroll-domain-offset") keeps track of scroll position as it wraps domains
211   Property::Index mPropertyPositionDelta;           ///< Scroll Position Delta ("scroll-position-delta")
212   Property::Index mPropertyScrollStartPagePosition; ///< Scroll Start Page Position ("scroll-start-page-position")
213
214 private:
215
216   float mDelay;                             ///< delay in seconds.
217   ConstraintStack mConstraintStack;         ///< The list of constraints to apply to any actors
218   ActorInfoContainer mBoundActors;          ///< The list of actors that have been bound to this ScrollBase.
219
220 };
221
222 } // namespace Internal
223
224 } // namespace Toolkit
225
226 } // namespace Dali
227
228 #endif // __DALI_TOOLKIT_INTERNAL_SCROLL_GROUP_H__