(ScrollView) Inlined one line Getters/Setters
[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 namespace Toolkit
26 {
27 namespace Internal
28 {
29 ///////////////////////////////////////////////////////////////////////////////////////////////////
30 // ScrollBase
31 ///////////////////////////////////////////////////////////////////////////////////////////////////
32
33 ScrollBase::ScrollBase(ControlBehaviour behaviourFlags)
34 : Scrollable(behaviourFlags),
35   mParent(NULL),
36   mDelay(0.0f)
37 {
38 }
39
40 void ScrollBase::SetParent(ScrollBase* parent)
41 {
42   mParent = parent;
43 }
44
45 void ScrollBase::BindActor(Actor child)
46 {
47   FindAndUnbindActor(child);
48
49   ActorInfoPtr actorInfo(new ActorInfo(child));
50   mBoundActors.push_back(actorInfo);
51
52   // Apply all our constraints to this new child.
53   ConstraintStack::iterator i;
54
55   for(i = mConstraintStack.begin(); i != mConstraintStack.end(); i++)
56   {
57     actorInfo->ApplyConstraint(*i);
58   }
59 }
60
61 void ScrollBase::UnbindActor(Actor child)
62 {
63   // Find the child in mBoundActors, and unparent it
64   for(ActorInfoIter iter = mBoundActors.begin(); iter != mBoundActors.end(); ++iter)
65   {
66     ActorInfoPtr actorInfo = *iter;
67
68     if(actorInfo->mActor == child)
69     {
70       mBoundActors.erase(iter);
71       break;
72     }
73   }
74 }
75
76 void ScrollBase::FindAndUnbindActor(Actor child)
77 {
78   // Since we don't know if and where child may have been bound
79   // (as we cannot store such information inside the Actor), we
80   // perform a search on all associated ScrollBases
81   // This is done by recursively calling the parent of this ScrollBase
82   // until reaching the top (at which point implementation may be
83   // different as this is virtual)
84
85   if(mParent) // continuously ascend until reaches root ScrollBase.
86   {
87     mParent->FindAndUnbindActor(child);
88   }
89 }
90
91 void ScrollBase::ApplyConstraintToBoundActors(Constraint constraint)
92 {
93   mConstraintStack.push_back(constraint);
94
95   for(ActorInfoIter i = mBoundActors.begin(); i != mBoundActors.end(); ++i)
96   {
97     (*i)->ApplyConstraint(constraint);
98   }
99 }
100
101 void ScrollBase::RemoveConstraintsFromBoundActors()
102 {
103   mConstraintStack.clear();
104
105   for(ActorInfoIter i = mBoundActors.begin(); i != mBoundActors.end(); ++i)
106   {
107     (*i)->RemoveConstraints();
108   }
109 }
110
111 } // namespace Internal
112
113 } // namespace Toolkit
114
115 } // namespace Dali