Merge remote-tracking branch 'origin/tizen' into devel/new_mesh
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / scrollable / scroll-view / scroll-base-impl.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali-toolkit/internal/controls/scrollable/scroll-view/scroll-base-impl.h>
20
21 using namespace Dali;
22
23 namespace Dali
24 {
25
26 namespace Toolkit
27 {
28
29 namespace Internal
30 {
31
32 ///////////////////////////////////////////////////////////////////////////////////////////////////
33 // ScrollBase
34 ///////////////////////////////////////////////////////////////////////////////////////////////////
35
36 ScrollBase::ScrollBase()
37 : Scrollable(),
38   mParent(NULL),
39   mDelay(0.0f)
40 {
41 }
42
43 ScrollBase::ScrollBase( ControlBehaviour behaviourFlags )
44 : Scrollable( behaviourFlags ),
45   mParent(NULL),
46   mDelay(0.0f)
47 {
48 }
49
50 void ScrollBase::SetParent(ScrollBase *parent)
51 {
52   mParent = parent;
53 }
54
55 void ScrollBase::BindActor(Actor child)
56 {
57   FindAndUnbindActor(child);
58
59   ActorInfoPtr actorInfo(new ActorInfo(child));
60   mBoundActors.push_back(actorInfo);
61
62   // Apply all our constraints to this new child.
63   ConstraintStack::iterator i;
64
65   for(i = mConstraintStack.begin();i!=mConstraintStack.end();i++)
66   {
67     actorInfo->ApplyConstraint(*i);
68   }
69 }
70
71 void ScrollBase::UnbindActor(Actor child)
72 {
73   // Find the child in mBoundActors, and unparent it
74   for (ActorInfoIter iter = mBoundActors.begin(); iter != mBoundActors.end(); ++iter)
75   {
76     ActorInfoPtr actorInfo = *iter;
77
78     if( actorInfo->mActor == child )
79     {
80       mBoundActors.erase(iter);
81       break;
82     }
83   }
84 }
85
86 void ScrollBase::FindAndUnbindActor(Actor child)
87 {
88   // Since we don't know if and where child may have been bound
89   // (as we cannot store such information inside the Actor), we
90   // perform a search on all associated ScrollBases
91   // This is done by recursively calling the parent of this ScrollBase
92   // until reaching the top (at which point implementation may be
93   // different as this is virtual)
94
95   if(mParent) // continuously ascend until reaches root ScrollBase.
96   {
97     mParent->FindAndUnbindActor(child);
98   }
99 }
100
101 void ScrollBase::ApplyConstraintToBoundActors(Constraint constraint)
102 {
103   mConstraintStack.push_back(constraint);
104
105   for(ActorInfoIter i = mBoundActors.begin();i != mBoundActors.end(); ++i)
106   {
107     (*i)->ApplyConstraint(constraint);
108   }
109 }
110
111 void ScrollBase::RemoveConstraintsFromBoundActors()
112 {
113   mConstraintStack.clear();
114
115   for(ActorInfoIter i = mBoundActors.begin();i != mBoundActors.end(); ++i)
116   {
117     (*i)->RemoveConstraints();
118   }
119 }
120
121 } // namespace Internal
122
123 } // namespace Toolkit
124
125 } // namespace Dali