2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0/
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.
18 * @file FUiGridLayout.cpp
19 * @brief This is the implementation file for GridLayout class.
21 * This file contains the implementation of GridLayout class.
24 #include <FUiGridLayout.h>
25 #include <FUiControl.h>
26 #include "FUi_GridLayoutImpl.h"
27 #include "FUi_CoordinateSystemUtils.h"
29 namespace Tizen { namespace Ui
32 GridLayout::GridLayout()
36 GridLayout::~GridLayout()
41 GridLayout::Construct(int maxRow, int maxColumn)
45 SysTryReturn(NID_UI, (maxRow - 1 >= 0) && (maxColumn - 1 >= 0), E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The given parameter is invalid.");
47 _GridLayoutImpl* pGridLayoutImpl = _GridLayoutImpl::GetInstance(*this);
48 SysAssertf(pGridLayoutImpl == null, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
50 pGridLayoutImpl = _GridLayoutImpl::CreateGridLayoutImplN(this, maxRow, maxColumn);
51 result r = GetLastResult();
52 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
54 _LayoutImpl::SetLayoutImpl(this, pGridLayoutImpl);
60 GridLayout::GetLayoutType(void) const
66 GridLayout::GetRowCount() const
70 const _GridLayoutImpl* pGridLayoutImpl = _GridLayoutImpl::GetInstance(*this);
71 SysAssertf(pGridLayoutImpl != null, "Not yet constructed. Construct() should be called before use.");
73 return pGridLayoutImpl->GetRowCount();
77 GridLayout::GetColumnCount() const
81 const _GridLayoutImpl* pGridLayoutImpl = _GridLayoutImpl::GetInstance(*this);
82 SysAssertf(pGridLayoutImpl != null, "Not yet constructed. Construct() should be called before use.");
84 return pGridLayoutImpl->GetColumnCount();
88 GridLayout::SetColumnStretchable(int columnIndex, bool stretchable)
92 _GridLayoutImpl* pGridLayoutImpl = _GridLayoutImpl::GetInstance(*this);
93 SysAssertf(pGridLayoutImpl != null, "Not yet constructed. Construct() should be called before use.");
95 SysTryReturn(NID_UI, (columnIndex >= 0) && (columnIndex <= GetColumnCount() - 1), E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The given parameter is out of range.");
97 result r = pGridLayoutImpl->SetColumnStretchable(columnIndex, stretchable);
98 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
104 GridLayout::SetColumnShrinkable(int columnIndex, bool shrinkable)
108 _GridLayoutImpl* pGridLayoutImpl = _GridLayoutImpl::GetInstance(*this);
109 SysAssertf(pGridLayoutImpl != null, "Not yet constructed. Construct() should be called before use.");
111 SysTryReturn(NID_UI, (columnIndex >= 0) && (columnIndex <= GetColumnCount() - 1), E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The given parameter is out of range.");
113 result r = pGridLayoutImpl->SetColumnShrinkable(columnIndex, shrinkable);
114 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
120 GridLayout::SetColumnCollapsed(int columnIndex, bool collapsed)
124 _GridLayoutImpl* pGridLayoutImpl = _GridLayoutImpl::GetInstance(*this);
125 SysAssertf(pGridLayoutImpl != null, "Not yet constructed. Construct() should be called before use.");
127 SysTryReturn(NID_UI, (columnIndex >= 0) && (columnIndex <= GetColumnCount() - 1), E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The given parameter is out of range.");
129 result r = pGridLayoutImpl->SetColumnCollapsed(columnIndex, collapsed);
130 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
136 GridLayout::SetAllColumnsStretchable(bool stretchable)
140 _GridLayoutImpl* pGridLayoutImpl = _GridLayoutImpl::GetInstance(*this);
141 SysAssertf(pGridLayoutImpl != null, "Not yet constructed. Construct() should be called before use.");
143 result r = pGridLayoutImpl->SetAllColumnsStretchable(stretchable);
144 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
150 GridLayout::SetAllColumnsShrinkable(bool shrinkable)
154 _GridLayoutImpl* pGridLayoutImpl = _GridLayoutImpl::GetInstance(*this);
155 SysAssertf(pGridLayoutImpl != null, "Not yet constructed. Construct() should be called before use.");
157 result r = pGridLayoutImpl->SetAllColumnsShrinkable(shrinkable);
158 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
164 GridLayout::SetColumnSpacing(int columnIndex, int space)
168 _GridLayoutImpl* pGridLayoutImpl = _GridLayoutImpl::GetInstance(*this);
169 SysAssertf(pGridLayoutImpl != null, "Not yet constructed. Construct() should be called before use.");
171 SysTryReturn(NID_UI, (columnIndex >= 0) && (columnIndex <= GetColumnCount() - 1), E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The given parameter is out of range.");
172 SysTryReturn(NID_UI, space >= 0, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The given parameter is invalid.");
174 result r = pGridLayoutImpl->SetColumnSpacing(columnIndex, _CoordinateSystemUtils::ConvertToFloat(space));
175 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
181 GridLayout::SetColumnSpacing(int columnIndex, float space)
185 _GridLayoutImpl* pGridLayoutImpl = _GridLayoutImpl::GetInstance(*this);
186 SysAssertf(pGridLayoutImpl != null, "Not yet constructed. Construct() should be called before use.");
188 SysTryReturn(NID_UI, (columnIndex >= 0) && (columnIndex <= GetColumnCount() - 1), E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The given parameter is out of range.");
189 SysTryReturn(NID_UI, space >= 0, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The given parameter is invalid.");
191 result r = pGridLayoutImpl->SetColumnSpacing(columnIndex, space);
192 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
198 GridLayout::SetRowStretchable(int rowIndex, bool stretchable)
202 _GridLayoutImpl* pGridLayoutImpl = _GridLayoutImpl::GetInstance(*this);
203 SysAssertf(pGridLayoutImpl != null, "Not yet constructed. Construct() should be called before use.");
205 SysTryReturn(NID_UI, (rowIndex >= 0) && (rowIndex <= GetRowCount() - 1), E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The given parameter is out of range.");
207 result r = pGridLayoutImpl->SetRowStretchable(rowIndex, stretchable);
208 SysTryReturn(NID_UI, GetLastResult() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(r));
214 GridLayout::SetRowShrinkable(int rowIndex, bool shrinkable)
218 _GridLayoutImpl* pGridLayoutImpl = _GridLayoutImpl::GetInstance(*this);
219 SysAssertf(pGridLayoutImpl != null, "Not yet constructed. Construct() should be called before use.");
221 SysTryReturn(NID_UI, (rowIndex >= 0) && (rowIndex <= GetRowCount() - 1), E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The given parameter is out of range.");
223 result r = pGridLayoutImpl->SetRowShrinkable(rowIndex, shrinkable);
224 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
230 GridLayout::SetRowCollapsed(int rowIndex, bool collapsed)
234 _GridLayoutImpl* pGridLayoutImpl = _GridLayoutImpl::GetInstance(*this);
235 SysAssertf(pGridLayoutImpl != null, "Not yet constructed. Construct() should be called before use.");
237 SysTryReturn(NID_UI, (rowIndex >= 0) && (rowIndex <= GetRowCount() - 1), E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The given parameter is out of range.");
239 result r = pGridLayoutImpl->SetRowCollapsed(rowIndex, collapsed);
240 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
246 GridLayout::SetAllRowsStretchable(bool stretchable)
250 _GridLayoutImpl* pGridLayoutImpl = _GridLayoutImpl::GetInstance(*this);
251 SysAssertf(pGridLayoutImpl != null, "Not yet constructed. Construct() should be called before use.");
253 result r = pGridLayoutImpl->SetAllRowsStretchable(stretchable);
254 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
260 GridLayout::SetAllRowsShrinkable(bool shrinkable)
263 _GridLayoutImpl* pGridLayoutImpl = _GridLayoutImpl::GetInstance(*this);
264 SysAssertf(pGridLayoutImpl != null, "Not yet constructed. Construct() should be called before use.");
266 result r = pGridLayoutImpl->SetAllRowsShrinkable(shrinkable);
267 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
273 GridLayout::SetRowSpacing(int rowIndex, int space)
277 _GridLayoutImpl* pGridLayoutImpl = _GridLayoutImpl::GetInstance(*this);
278 SysAssertf(pGridLayoutImpl != null, "Not yet constructed. Construct() should be called before use.");
280 SysTryReturn(NID_UI, (rowIndex >= 0) && (rowIndex <= GetRowCount() - 1), E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The given parameter is out of range.");
281 SysTryReturn(NID_UI, space >= 0, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The given parameter is invalid.");
283 result r = pGridLayoutImpl->SetRowSpacing(rowIndex, _CoordinateSystemUtils::ConvertToFloat(space));
284 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
290 GridLayout::SetRowSpacing(int rowIndex, float space)
294 _GridLayoutImpl* pGridLayoutImpl = _GridLayoutImpl::GetInstance(*this);
295 SysAssertf(pGridLayoutImpl != null, "Not yet constructed. Construct() should be called before use.");
297 SysTryReturn(NID_UI, (rowIndex >= 0) && (rowIndex <= GetRowCount() - 1), E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The given parameter is out of range.");
298 SysTryReturn(NID_UI, space >= 0, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The given parameter is invalid.");
300 result r = pGridLayoutImpl->SetRowSpacing(rowIndex, space);
301 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
307 GridLayout::SetPosition(Control& childControl, int rowStartIndex, int columnStartIndex, int rowSpan, int columnSpan)
311 _ControlImpl* pControlImpl = _ControlImpl::GetInstance(childControl);
312 SysTryReturn(NID_UI, pControlImpl, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] This instance is not constructed.");
314 _GridLayoutImpl* pGridLayoutImpl = _GridLayoutImpl::GetInstance(*this);
315 SysAssertf(pGridLayoutImpl != null, "Not yet constructed. Construct() should be called before use.");
317 result r = pGridLayoutImpl->SetPosition(*pControlImpl, rowStartIndex, columnStartIndex, rowSpan, columnSpan);
318 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
324 GridLayout::SetAlignment(Control& childControl, LayoutHorizontalAlignment horAlign, LayoutVerticalAlignment vertAlign)
328 _GridLayoutImpl* pGridLayoutImpl = _GridLayoutImpl::GetInstance(*this);
329 SysAssertf(pGridLayoutImpl != null, "Not yet constructed. Construct() should be called before use.");
331 _ControlImpl* pControlImpl = _ControlImpl::GetInstance(childControl);
332 SysTryReturn(NID_UI, pControlImpl, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] This instance is not constructed.");
334 result r = pGridLayoutImpl->SetAlignment(*pControlImpl, horAlign, vertAlign);
335 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
341 GridLayout::SetMargin(Control& childControl, int left, int right, int top, int bottom)
345 SysTryReturn(NID_UI, (left >= 0) && (right >= 0) && (top >= 0) && (bottom >= 0), E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The given parameter is invalid.");
347 _GridLayoutImpl* pGridLayoutImpl = _GridLayoutImpl::GetInstance(*this);
348 SysAssertf(pGridLayoutImpl != null, "Not yet constructed. Construct() should be called before use.");
350 _ControlImpl* pControlImpl = _ControlImpl::GetInstance(childControl);
351 SysTryReturn(NID_UI, pControlImpl, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] This instance is not constructed.");
353 float floatLeft = _CoordinateSystemUtils::ConvertToFloat(left);
354 float floatRight = _CoordinateSystemUtils::ConvertToFloat(right);
355 float floatTop = _CoordinateSystemUtils::ConvertToFloat(top);
356 float floatBottom = _CoordinateSystemUtils::ConvertToFloat(bottom);
357 result r = pGridLayoutImpl->SetMargin(*pControlImpl, floatLeft, floatRight, floatTop, floatBottom);
358 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
364 GridLayout::SetMargin(Control& childControl, float left, float right, float top, float bottom)
368 SysTryReturn(NID_UI, (left >= 0) && (right >= 0) && (top >= 0) && (bottom >= 0), E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The given parameter is invalid.");
370 _GridLayoutImpl* pGridLayoutImpl = _GridLayoutImpl::GetInstance(*this);
371 SysAssertf(pGridLayoutImpl != null, "Not yet constructed. Construct() should be called before use.");
373 _ControlImpl* pControlImpl = _ControlImpl::GetInstance(childControl);
374 SysTryReturn(NID_UI, pControlImpl, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] This instance is not constructed.");
376 result r = pGridLayoutImpl->SetMargin(*pControlImpl, left, right, top, bottom);
377 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));