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