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