Changed indicator bg color.
[platform/framework/native/uifw.git] / src / ui / FUiRelativeLayout.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 /**
18  * @file                FUiRelativeLayout.cpp
19  * @brief       This is the implementation file for RelativeLayout class.
20  *
21  * This file contains the implementation of RelativeLayout class.
22  */
23
24 #include <FUiRelativeLayout.h>
25 #include <FUiControl.h>
26 #include "FUi_RelativeLayoutImpl.h"
27 #include "FUi_CoordinateSystemUtils.h"
28
29 namespace Tizen { namespace Ui
30 {
31
32 RelativeLayout::RelativeLayout()
33 {
34 }
35
36 RelativeLayout::~RelativeLayout()
37 {
38 }
39
40 result
41 RelativeLayout::Construct(void)
42 {
43         ClearLastResult();
44
45         _RelativeLayoutImpl* pRelativeLayoutImpl = _RelativeLayoutImpl::GetInstance(*this);
46         SysAssertf(pRelativeLayoutImpl == null, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
47
48         pRelativeLayoutImpl = _RelativeLayoutImpl::CreateRelativeLayoutImplN(this);
49         result r = GetLastResult();
50         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
51
52         _LayoutImpl::SetLayoutImpl(this, pRelativeLayoutImpl);
53
54         return E_SUCCESS;
55 }
56
57 Tizen::Ui::LayoutType
58 RelativeLayout::GetLayoutType(void) const
59 {
60         return LAYOUT_RELATIVE;
61 }
62
63 result
64 RelativeLayout::SetRelation(Control& childControl, const Control& targetControl, RectangleEdgeRelation edgeRelation)
65 {
66         ClearLastResult();
67
68         _RelativeLayoutImpl* pRelativeLayoutImpl = _RelativeLayoutImpl::GetInstance(*this);
69         SysAssertf(pRelativeLayoutImpl != null, "Not yet constructed. Construct() should be called before use.");
70
71         _ControlImpl* pControlImpl = _ControlImpl::GetInstance(childControl);
72         SysTryReturn(NID_UI, pControlImpl, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] This instance is not constructed.");
73
74         _ControlImpl* pTargetControlImpl = const_cast<_ControlImpl*>(_ControlImpl::GetInstance(targetControl));
75         SysTryReturn(NID_UI, pTargetControlImpl, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] This instance is not constructed.");
76
77         result r = pRelativeLayoutImpl->SetRelation(*pControlImpl, *pTargetControlImpl, edgeRelation);
78         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
79
80         return r;
81 }
82
83 result
84 RelativeLayout::SetRelation(Control& childControl, Control* pTargetControl, RectangleEdgeRelation edgeRelation)
85 {
86         ClearLastResult();
87
88         _RelativeLayoutImpl* pRelativeLayoutImpl = _RelativeLayoutImpl::GetInstance(*this);
89         SysAssertf(pRelativeLayoutImpl != null, "Not yet constructed. Construct() should be called before use.");
90
91         _ControlImpl* pControlImpl = _ControlImpl::GetInstance(childControl);
92         SysTryReturn(NID_UI, pControlImpl, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] This instance is not constructed.");
93
94         _ControlImpl* pTargetControlImpl = _ControlImpl::GetInstance(*pTargetControl);
95         SysTryReturn(NID_UI, pTargetControlImpl, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] This instance is not constructed.");
96
97         result r = pRelativeLayoutImpl->SetRelation(*pControlImpl, *pTargetControlImpl, edgeRelation);
98         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
99
100         return r;
101 }
102
103 result
104 RelativeLayout::ResetRelation(Control& childControl, RectangleEdgeType edgeType)
105 {
106         ClearLastResult();
107
108         _RelativeLayoutImpl* pRelativeLayoutImpl = _RelativeLayoutImpl::GetInstance(*this);
109         SysAssertf(pRelativeLayoutImpl != null, "Not yet constructed. Construct() should be called before use.");
110
111         _ControlImpl* pControlImpl = _ControlImpl::GetInstance(childControl);
112         SysTryReturn(NID_UI, pControlImpl, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] This instance is not constructed.");
113
114         result r = pRelativeLayoutImpl->ResetRelation(*pControlImpl, edgeType);
115         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
116
117         return r;
118 }
119
120 result
121 RelativeLayout::SetCenterAligned(Control& childControl, CenterAlignmentType alignment)
122 {
123         ClearLastResult();
124
125         _RelativeLayoutImpl* pRelativeLayoutImpl = _RelativeLayoutImpl::GetInstance(*this);
126         SysAssertf(pRelativeLayoutImpl != null, "Not yet constructed. Construct() should be called before use.");
127
128         _ControlImpl* pControlImpl = _ControlImpl::GetInstance(childControl);
129         SysTryReturn(NID_UI, pControlImpl, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] This instance is not constructed.");
130
131         result r = pRelativeLayoutImpl->SetCenterAligned(*pControlImpl, alignment);
132         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
133
134         return r;
135 }
136
137 result
138 RelativeLayout::ResetCenterAligned(Control& childControl, CenterAlignmentType alignment)
139 {
140         ClearLastResult();
141
142         _RelativeLayoutImpl* pRelativeLayoutImpl = _RelativeLayoutImpl::GetInstance(*this);
143         SysAssertf(pRelativeLayoutImpl != null, "Not yet constructed. Construct() should be called before use.");
144
145         _ControlImpl* pControlImpl = _ControlImpl::GetInstance(childControl);
146         SysTryReturn(NID_UI, pControlImpl, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] This instance is not constructed.");
147
148         result r = pRelativeLayoutImpl->ResetCenterAligned(*pControlImpl, alignment);
149         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
150
151         return r;
152 }
153
154 result
155 RelativeLayout::SetMargin(Control& childControl, int left, int right, int top, int bottom)
156 {
157         ClearLastResult();
158
159         _RelativeLayoutImpl* pRelativeLayoutImpl = _RelativeLayoutImpl::GetInstance(*this);
160         SysAssertf(pRelativeLayoutImpl != null, "Not yet constructed. Construct() should be called before use.");
161
162         _ControlImpl* pControlImpl = _ControlImpl::GetInstance(childControl);
163         SysTryReturn(NID_UI, pControlImpl, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] This instance is not constructed.");
164
165         float floatLeft = _CoordinateSystemUtils::ConvertToFloat(left);
166         float floatRight = _CoordinateSystemUtils::ConvertToFloat(right);
167         float floatTop = _CoordinateSystemUtils::ConvertToFloat(top);
168         float floatBottom = _CoordinateSystemUtils::ConvertToFloat(bottom);
169         result r = pRelativeLayoutImpl->SetItemMargin(*pControlImpl, floatLeft, floatRight, floatTop, floatBottom);
170         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
171
172         return r;
173 }
174
175 result
176 RelativeLayout::SetMargin(Control& childControl, float left, float right, float top, float bottom)
177 {
178         ClearLastResult();
179
180         _RelativeLayoutImpl* pRelativeLayoutImpl = _RelativeLayoutImpl::GetInstance(*this);
181         SysAssertf(pRelativeLayoutImpl != null, "Not yet constructed. Construct() should be called before use.");
182
183         _ControlImpl* pControlImpl = _ControlImpl::GetInstance(childControl);
184         SysTryReturn(NID_UI, pControlImpl, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] This instance is not constructed.");
185
186         result r = pRelativeLayoutImpl->SetItemMargin(*pControlImpl, left, right, top, bottom);
187         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
188
189         return r;
190 }
191
192 result
193 RelativeLayout::SetWidth(Control& childControl, int width)
194 {
195         ClearLastResult();
196
197         _RelativeLayoutImpl* pRelativeLayoutImpl = _RelativeLayoutImpl::GetInstance(*this);
198         SysAssertf(pRelativeLayoutImpl != null, "Not yet constructed. Construct() should be called before use.");
199
200         _ControlImpl* pControlImpl = _ControlImpl::GetInstance(childControl);
201         SysTryReturn(NID_UI, pControlImpl, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] This instance is not constructed.");
202
203         result r = pRelativeLayoutImpl->SetWidth(*pControlImpl, _CoordinateSystemUtils::ConvertToFloat(width));
204         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
205
206         return r;
207 }
208
209 result
210 RelativeLayout::SetWidth(Control& childControl, float width)
211 {
212         ClearLastResult();
213
214         _RelativeLayoutImpl* pRelativeLayoutImpl = _RelativeLayoutImpl::GetInstance(*this);
215         SysAssertf(pRelativeLayoutImpl != null, "Not yet constructed. Construct() should be called before use.");
216
217         _ControlImpl* pControlImpl = _ControlImpl::GetInstance(childControl);
218         SysTryReturn(NID_UI, pControlImpl, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] This instance is not constructed.");
219
220         result r = pRelativeLayoutImpl->SetWidth(*pControlImpl, width);
221         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
222
223         return r;
224 }
225
226 result
227 RelativeLayout::SetHeight(Control& childControl, int height)
228 {
229         ClearLastResult();
230
231         _RelativeLayoutImpl* pRelativeLayoutImpl = _RelativeLayoutImpl::GetInstance(*this);
232         SysAssertf(pRelativeLayoutImpl != null, "Not yet constructed. Construct() should be called before use.");
233
234         _ControlImpl* pControlImpl = _ControlImpl::GetInstance(childControl);
235         SysTryReturn(NID_UI, pControlImpl, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] This instance is not constructed.");
236
237         result r = pRelativeLayoutImpl->SetHeight(*pControlImpl, _CoordinateSystemUtils::ConvertToFloat(height));
238         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
239
240         return r;
241 }
242
243 result
244 RelativeLayout::SetHeight(Control& childControl, float height)
245 {
246         ClearLastResult();
247
248         _RelativeLayoutImpl* pRelativeLayoutImpl = _RelativeLayoutImpl::GetInstance(*this);
249         SysAssertf(pRelativeLayoutImpl != null, "Not yet constructed. Construct() should be called before use.");
250
251         _ControlImpl* pControlImpl = _ControlImpl::GetInstance(childControl);
252         SysTryReturn(NID_UI, pControlImpl, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] This instance is not constructed.");
253
254         result r = pRelativeLayoutImpl->SetHeight(*pControlImpl, height);
255         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
256
257         return r;
258 }
259
260 result
261 RelativeLayout::SetHorizontalFitPolicy(Control& childControl, FitPolicy policy)
262 {
263         ClearLastResult();
264
265         _RelativeLayoutImpl* pRelativeLayoutImpl = _RelativeLayoutImpl::GetInstance(*this);
266         SysAssertf(pRelativeLayoutImpl != null, "Not yet constructed. Construct() should be called before use.");
267
268         _ControlImpl* pControlImpl = _ControlImpl::GetInstance(childControl);
269         SysTryReturn(NID_UI, pControlImpl, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] This instance is not constructed.");
270
271         result r = pRelativeLayoutImpl->SetItemHorizontalFitPolicy(*pControlImpl, policy);
272         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
273
274         return r;
275 }
276
277 result
278 RelativeLayout::SetVerticalFitPolicy(Control& childControl, FitPolicy policy)
279 {
280         ClearLastResult();
281
282         _RelativeLayoutImpl* pRelativeLayoutImpl = _RelativeLayoutImpl::GetInstance(*this);
283         SysAssertf(pRelativeLayoutImpl != null, "Not yet constructed. Construct() should be called before use.");
284
285         _ControlImpl* pControlImpl = _ControlImpl::GetInstance(childControl);
286         SysTryReturn(NID_UI, pControlImpl, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] This instance is not constructed.");
287
288         result r = pRelativeLayoutImpl->SetItemVerticalFitPolicy(*pControlImpl, policy);
289         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
290
291         return r;
292 }
293
294 }} // Tizen::Ui