Changed indicator bg color.
[platform/framework/native/uifw.git] / src / ui / FUiVerticalBoxLayout.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                FUiVerticalBoxLayout.cpp
19  * @brief       This is the implementation file for VerticalBoxLayout class.
20  *
21  * This file contains the implementation of VerticalBoxLayout class.
22  */
23
24 #include <FUiVerticalBoxLayout.h>
25 #include <FUiControl.h>
26 #include <FApp_AppInfo.h>
27 #include "FUi_VerticalBoxLayoutImpl.h"
28 #include "FUi_CoordinateSystemUtils.h"
29
30 namespace Tizen { namespace Ui
31 {
32
33 VerticalBoxLayout::VerticalBoxLayout()
34 {
35 }
36
37 VerticalBoxLayout::~VerticalBoxLayout()
38 {
39 }
40
41 result
42 VerticalBoxLayout::Construct(VerticalDirection direction)
43 {
44         ClearLastResult();
45
46         _VerticalBoxLayoutImpl* pVerticalBoxLayoutImpl = _VerticalBoxLayoutImpl::GetInstance(*this);
47         SysAssertf(pVerticalBoxLayoutImpl == null, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
48
49         pVerticalBoxLayoutImpl = _VerticalBoxLayoutImpl::CreateVerticalBoxLayoutImplN(this, direction);
50         result r = GetLastResult();
51         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
52
53         _LayoutImpl::SetLayoutImpl(this, pVerticalBoxLayoutImpl);
54
55         return E_SUCCESS;
56 }
57
58 Tizen::Ui::LayoutType
59 VerticalBoxLayout::GetLayoutType(void) const
60 {
61         return LAYOUT_VERTICAL_BOX;
62 }
63
64 result
65 VerticalBoxLayout::GetDirection(VerticalDirection& direction) const
66 {
67         ClearLastResult();
68
69         const _VerticalBoxLayoutImpl* pVerticalBoxLayoutImpl = _VerticalBoxLayoutImpl::GetInstance(*this);
70         SysAssertf(pVerticalBoxLayoutImpl != null, "Not yet constructed. Construct() should be called before use.");
71
72         result r = pVerticalBoxLayoutImpl->GetDirection(direction);
73         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
74
75         return r;
76 }
77
78 result
79 VerticalBoxLayout::SetHorizontalAlignment(Control& childControl, LayoutHorizontalAlignment alignment)
80 {
81         ClearLastResult();
82
83         _VerticalBoxLayoutImpl* pVerticalBoxLayoutImpl = _VerticalBoxLayoutImpl::GetInstance(*this);
84         SysAssertf(pVerticalBoxLayoutImpl != null, "Not yet constructed. Construct() should be called before use.");
85
86         _ControlImpl* pControlImpl = _ControlImpl::GetInstance(childControl);
87         SysTryReturn(NID_UI, pControlImpl, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] This instance is not constructed.");
88
89         result r = pVerticalBoxLayoutImpl->SetHorizontalAlignment(*pControlImpl, alignment);
90         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
91
92         return r;
93 }
94
95 result
96 VerticalBoxLayout::SetSpacing(Control& childControl, int space)
97 {
98         ClearLastResult();
99
100         SysTryReturn(NID_UI, space >= 0, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The given parameter is invalid.");
101
102         _VerticalBoxLayoutImpl* pVerticalBoxLayoutImpl = _VerticalBoxLayoutImpl::GetInstance(*this);
103         SysAssertf(pVerticalBoxLayoutImpl != null, "Not yet constructed. Construct() should be called before use.");
104
105         _ControlImpl* pControlImpl = _ControlImpl::GetInstance(childControl);
106         SysTryReturn(NID_UI, pControlImpl, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] This instance is not constructed.");
107
108         result r = pVerticalBoxLayoutImpl->SetSpacing(*pControlImpl, _CoordinateSystemUtils::ConvertToFloat(space));
109         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
110
111         return r;
112 }
113
114 result
115 VerticalBoxLayout::SetSpacing(Control& childControl, float space)
116 {
117         ClearLastResult();
118
119         SysTryReturn(NID_UI, space >= 0, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The given parameter is invalid.");
120
121         _VerticalBoxLayoutImpl* pVerticalBoxLayoutImpl = _VerticalBoxLayoutImpl::GetInstance(*this);
122         SysAssertf(pVerticalBoxLayoutImpl != null, "Not yet constructed. Construct() should be called before use.");
123
124         _ControlImpl* pControlImpl = _ControlImpl::GetInstance(childControl);
125         SysTryReturn(NID_UI, pControlImpl, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] This instance is not constructed.");
126
127         result r = pVerticalBoxLayoutImpl->SetSpacing(*pControlImpl, space);
128         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
129
130         return r;
131 }
132
133 result
134 VerticalBoxLayout::SetHorizontalMargin(Control& childControl, int left, int right)
135 {
136         ClearLastResult();
137
138         SysTryReturn(NID_UI, (left >= 0) && (right >= 0), E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The given parameter is invalid.");
139
140         _VerticalBoxLayoutImpl* pVerticalBoxLayoutImpl = _VerticalBoxLayoutImpl::GetInstance(*this);
141         SysAssertf(pVerticalBoxLayoutImpl != null, "Not yet constructed. Construct() should be called before use.");
142
143         _ControlImpl* pControlImpl = _ControlImpl::GetInstance(childControl);
144         SysTryReturn(NID_UI, pControlImpl, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] This instance is not constructed.");
145
146         float floatLeft = _CoordinateSystemUtils::ConvertToFloat(left);
147         float floatRight = _CoordinateSystemUtils::ConvertToFloat(right);
148         result r = pVerticalBoxLayoutImpl->SetHorizontalMargin(*pControlImpl, floatLeft, floatRight);
149         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
150
151         return r;
152 }
153
154 result
155 VerticalBoxLayout::SetHorizontalMargin(Control& childControl, float left, float right)
156 {
157         ClearLastResult();
158
159         SysTryReturn(NID_UI, (left >= 0) && (right >= 0), E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The given parameter is invalid.");
160
161         _VerticalBoxLayoutImpl* pVerticalBoxLayoutImpl = _VerticalBoxLayoutImpl::GetInstance(*this);
162         SysAssertf(pVerticalBoxLayoutImpl != null, "Not yet constructed. Construct() should be called before use.");
163
164         _ControlImpl* pControlImpl = _ControlImpl::GetInstance(childControl);
165         SysTryReturn(NID_UI, pControlImpl, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] This instance is not constructed.");
166
167         result r = pVerticalBoxLayoutImpl->SetHorizontalMargin(*pControlImpl, left, right);
168         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
169
170         return r;
171 }
172
173 result
174 VerticalBoxLayout::SetWidth(Control& childControl, int width)
175 {
176         ClearLastResult();
177
178         SysTryReturn(NID_UI, width >= 0, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The given parameter is invalid.");
179
180         _VerticalBoxLayoutImpl* pVerticalBoxLayoutImpl = _VerticalBoxLayoutImpl::GetInstance(*this);
181         SysAssertf(pVerticalBoxLayoutImpl != 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 = pVerticalBoxLayoutImpl->SetWidth(*pControlImpl, _CoordinateSystemUtils::ConvertToFloat(width));
187         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
188
189         return r;
190 }
191
192 result
193 VerticalBoxLayout::SetWidth(Control& childControl, float width)
194 {
195         ClearLastResult();
196
197         SysTryReturn(NID_UI, width >= 0, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The given parameter is invalid.");
198
199         _VerticalBoxLayoutImpl* pVerticalBoxLayoutImpl = _VerticalBoxLayoutImpl::GetInstance(*this);
200         SysAssertf(pVerticalBoxLayoutImpl != null, "Not yet constructed. Construct() should be called before use.");
201
202         _ControlImpl* pControlImpl = _ControlImpl::GetInstance(childControl);
203         SysTryReturn(NID_UI, pControlImpl, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] This instance is not constructed.");
204
205         result r = pVerticalBoxLayoutImpl->SetWidth(*pControlImpl, width);
206         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
207
208         return r;
209 }
210
211 result
212 VerticalBoxLayout::SetHorizontalFitPolicy(Control& childControl, FitPolicy policy)
213 {
214         ClearLastResult();
215
216         _VerticalBoxLayoutImpl* pVerticalBoxLayoutImpl = _VerticalBoxLayoutImpl::GetInstance(*this);
217         SysAssertf(pVerticalBoxLayoutImpl != null, "Not yet constructed. Construct() should be called before use.");
218
219         _ControlImpl* pControlImpl = _ControlImpl::GetInstance(childControl);
220         SysTryReturn(NID_UI, pControlImpl, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] This instance is not constructed.");
221
222         result r = pVerticalBoxLayoutImpl->SetItemHorizontalFitPolicy(*pControlImpl, policy);
223         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
224
225         return r;
226 }
227
228 result
229 VerticalBoxLayout::SetHeight(Control& childControl, int height)
230 {
231         ClearLastResult();
232
233         SysTryReturn(NID_UI, height >= 0, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The given parameter is invalid.");
234
235         _VerticalBoxLayoutImpl* pVerticalBoxLayoutImpl = _VerticalBoxLayoutImpl::GetInstance(*this);
236         SysAssertf(pVerticalBoxLayoutImpl != null, "Not yet constructed. Construct() should be called before use.");
237
238         _ControlImpl* pControlImpl = _ControlImpl::GetInstance(childControl);
239         SysTryReturn(NID_UI, pControlImpl, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] This instance is not constructed.");
240
241         result r = pVerticalBoxLayoutImpl->SetHeight(*pControlImpl, _CoordinateSystemUtils::ConvertToFloat(height));
242         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
243
244         return r;
245 }
246
247 result
248 VerticalBoxLayout::SetHeight(Control& childControl, float height)
249 {
250         ClearLastResult();
251
252         SysTryReturn(NID_UI, height >= 0, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The given parameter is invalid.");
253
254         _VerticalBoxLayoutImpl* pVerticalBoxLayoutImpl = _VerticalBoxLayoutImpl::GetInstance(*this);
255         SysAssertf(pVerticalBoxLayoutImpl != null, "Not yet constructed. Construct() should be called before use.");
256
257         _ControlImpl* pControlImpl = _ControlImpl::GetInstance(childControl);
258         SysTryReturn(NID_UI, pControlImpl, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] This instance is not constructed.");
259
260         result r = pVerticalBoxLayoutImpl->SetHeight(*pControlImpl, height);
261         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
262
263         return r;
264 }
265
266 result
267 VerticalBoxLayout::SetVerticalFitPolicy(Control& childControl, FitPolicy policy)
268 {
269         ClearLastResult();
270
271         _VerticalBoxLayoutImpl* pVerticalBoxLayoutImpl = _VerticalBoxLayoutImpl::GetInstance(*this);
272         SysAssertf(pVerticalBoxLayoutImpl != null, "Not yet constructed. Construct() should be called before use.");
273
274         _ControlImpl* pControlImpl = _ControlImpl::GetInstance(childControl);
275         SysTryReturn(NID_UI, pControlImpl, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] This instance is not constructed.");
276
277         if (!Tizen::App::_AppInfo::IsOspCompat())
278         {
279                 if (policy == FIT_POLICY_PARENT)
280                 {
281                         return E_SUCCESS;
282                 }
283         }
284
285         result r = pVerticalBoxLayoutImpl->SetItemVerticalFitPolicy(*pControlImpl, policy);
286         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
287
288         return r;
289 }
290
291 result
292 VerticalBoxLayout::SetWeight(Control& childControl, float weight)
293 {
294         ClearLastResult();
295
296         _VerticalBoxLayoutImpl* pVerticalBoxLayoutImpl = _VerticalBoxLayoutImpl::GetInstance(*this);
297         SysAssertf(pVerticalBoxLayoutImpl != null, "Not yet constructed. Construct() should be called before use.");
298
299         _ControlImpl* pControlImpl = _ControlImpl::GetInstance(childControl);
300         SysTryReturn(NID_UI, pControlImpl, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] This instance is not constructed.");
301
302         SysTryReturn(NID_UI, weight >= 0.0f, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The given parameter is invalid.\n")
303
304         result r = pVerticalBoxLayoutImpl->SetWeight(*pControlImpl, weight);
305         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
306
307         return r;
308 }
309
310 }} // Tizen::Ui