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 FUi_GridLayoutImpl.cpp
19 * @brief This is the implementation file for _GridLayoutImpl class.
21 * This file contains the implementation of _GridLayoutImpl class.
24 #include "FUi_GridLayoutImpl.h"
25 #include "FUi_CoordinateSystemUtils.h"
27 namespace Tizen { namespace Ui
30 // _GridLayoutImpl implementation
31 _GridLayoutImpl::_GridLayoutImpl(GridLayout* pPublicLayout, _Layout::TableLayout* pCoreLayout)
32 : _LayoutImpl(pPublicLayout, pCoreLayout)
38 _GridLayoutImpl::~_GridLayoutImpl()
43 _GridLayoutImpl::GetLayoutType(void) const
49 _GridLayoutImpl::CreateGridLayoutImplN(GridLayout* pPublicLayout, int maxRow, int maxColumn)
53 _Layout::TableLayout* pCoreLayout = null;
54 _GridLayoutImpl* pImplLayout = null;
57 pCoreLayout = _Layout::TableLayout::CreateTableLayoutN();
59 SysTryReturn(NID_UI, pCoreLayout != null, null, r, "[%s] Propagating.", GetErrorMessage(r));
61 pImplLayout = new (std::nothrow) _GridLayoutImpl(pPublicLayout, pCoreLayout);
62 r = CheckConstruction(pCoreLayout, pImplLayout);
63 SysTryReturn(NID_UI, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
65 r = pImplLayout->Construct(maxRow, maxColumn);
69 SysTryReturn(NID_UI, false, null, r, "[%s] Propagating.", GetErrorMessage(r));
76 _GridLayoutImpl::GetPublicClassName(void) const
78 return "Tizen::Ui::GridLayout";
82 _GridLayoutImpl::GetPublic(void) const
84 return static_cast <const GridLayout&>(_LayoutImpl::GetPublic());
88 _GridLayoutImpl::GetPublic(void)
90 return static_cast <GridLayout&>(_LayoutImpl::GetPublic());
93 const _Layout::TableLayout&
94 _GridLayoutImpl::GetCore(void) const
96 return static_cast <const _Layout::TableLayout&>(_LayoutImpl::GetCore());
100 _GridLayoutImpl::GetCore(void)
102 return static_cast <_Layout::TableLayout&>(_LayoutImpl::GetCore());
105 const _GridLayoutImpl*
106 _GridLayoutImpl::GetInstance(const GridLayout& layout)
108 return static_cast <const _GridLayoutImpl*>(_LayoutImpl::GetInstance(layout));
112 _GridLayoutImpl::GetInstance(GridLayout& layout)
114 return static_cast <_GridLayoutImpl*>(_LayoutImpl::GetInstance(layout));
118 _GridLayoutImpl::Construct(int maxRow, int maxColumn)
122 result r = GetCore().CreateTable(maxRow, maxColumn);
123 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
126 __maxColumn = maxColumn;
132 _GridLayoutImpl::SetColumnStretchable(int columnIndex, bool stretchable)
136 return GetCore().SetColumnStretchable(columnIndex, stretchable);
140 _GridLayoutImpl::SetColumnShrinkable(int columnIndex, bool shrinkable)
144 return GetCore().SetColumnShrinkable(columnIndex, shrinkable);
148 _GridLayoutImpl::SetColumnCollapsed(int columnIndex, bool collapsed)
152 return GetCore().SetColumnCollapsed(columnIndex, collapsed);
156 _GridLayoutImpl::SetAllColumnsStretchable(bool stretchable)
160 result r = E_SUCCESS;
161 bool* pOldStretchable = new (std::nothrow) bool[__maxColumn];
162 SysTryReturn(NID_UI, pOldStretchable != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
163 memset(pOldStretchable, 0, sizeof(bool) * __maxColumn);
166 for (col = 0; col < __maxColumn; col++)
168 pOldStretchable[col] = GetCore().GetColumnStretchable(col);
172 SysLogException(NID_UI, E_INVALID_ARG, "[E_INVALID_ARG] max column is invalid value.");
176 r = GetCore().SetColumnStretchable(col, stretchable);
179 SysLogException(NID_UI, E_INVALID_ARG, "[E_INVALID_ARG] max column is invalid value.");
184 delete[] pOldStretchable;
189 for (int colIndex = 0; colIndex < col; colIndex++)
191 GetCore().SetColumnStretchable(colIndex, pOldStretchable[colIndex]);
194 delete[] pOldStretchable;
200 _GridLayoutImpl::SetAllColumnsShrinkable(bool shrinkable)
204 result r = E_SUCCESS;
205 bool* pOldShrinkable = new (std::nothrow) bool[__maxColumn];
206 SysTryReturn(NID_UI, pOldShrinkable != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
207 memset(pOldShrinkable, 0, sizeof(bool) * __maxColumn);
210 for (col = 0; col < __maxColumn; col++)
212 pOldShrinkable[col] = GetCore().GetColumnShrinkable(col);
216 SysLogException(NID_UI, E_INVALID_ARG, "[E_INVALID_ARG] max column is invalid value.");
220 r = GetCore().SetColumnShrinkable(col, shrinkable);
223 SysLogException(NID_UI, E_INVALID_ARG, "[E_INVALID_ARG] max column is invalid value.");
228 delete[] pOldShrinkable;
233 for (int colIndex = 0; colIndex < col; colIndex++)
235 GetCore().SetColumnShrinkable(colIndex, pOldShrinkable[colIndex]);
238 delete[] pOldShrinkable;
244 _GridLayoutImpl::SetColumnSpacing(int columnIndex, float space)
248 return GetCore().SetColumnSpacing(columnIndex, space);
252 _GridLayoutImpl::SetRowStretchable(int rowIndex, bool stretchable)
256 return GetCore().SetRowStretchable(rowIndex, stretchable);
260 _GridLayoutImpl::SetRowShrinkable(int rowIndex, bool shrinkable)
264 return GetCore().SetRowShrinkable(rowIndex, shrinkable);
268 _GridLayoutImpl::SetRowCollapsed(int rowIndex, bool collapsed)
272 return GetCore().SetRowCollapsed(rowIndex, collapsed);
276 _GridLayoutImpl::SetAllRowsStretchable(bool stretchable)
280 result r = E_SUCCESS;
281 bool* pOldStretchable = new (std::nothrow) bool[__maxRow];
282 SysTryReturn(NID_UI, pOldStretchable != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
283 memset(pOldStretchable, 0, sizeof(bool) * __maxRow);
287 for (row = 0; row < __maxRow; row++)
289 pOldStretchable[row] = GetCore().GetRowStretchable(row);
293 SysLogException(NID_UI, E_INVALID_ARG, "[E_INVALID_ARG] max row is invalid value.");
297 r = GetCore().SetRowStretchable(row, stretchable);
300 SysLogException(NID_UI, E_INVALID_ARG, "[E_INVALID_ARG] max row is invalid value.");
305 delete[] pOldStretchable;
310 for (int rowIndex = 0; rowIndex < row; rowIndex++)
312 GetCore().SetRowStretchable(rowIndex, pOldStretchable[rowIndex]);
315 delete[] pOldStretchable;
321 _GridLayoutImpl::SetAllRowsShrinkable(bool shrinkable)
325 result r = E_SUCCESS;
326 bool* pOldShrinkable = new (std::nothrow) bool[__maxRow];
327 SysTryReturn(NID_UI, pOldShrinkable != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
328 memset(pOldShrinkable, 0, sizeof(bool) * __maxRow);
331 for (row = 0; row < __maxRow; row++)
333 pOldShrinkable[row] = GetCore().GetRowShrinkable(row);
337 SysLogException(NID_UI, E_INVALID_ARG, "[E_INVALID_ARG] max row is invalid value.");
341 r = GetCore().SetRowShrinkable(row, shrinkable);
344 SysLogException(NID_UI, E_INVALID_ARG, "[E_INVALID_ARG] max row is invalid value.");
349 delete[] pOldShrinkable;
354 for (int rowIndex = 0; rowIndex < row; rowIndex++)
356 GetCore().SetRowShrinkable(rowIndex, pOldShrinkable[rowIndex]);
358 delete[] pOldShrinkable;
364 _GridLayoutImpl::SetRowSpacing(int rowIndex, float space)
368 return GetCore().SetRowSpacing(rowIndex, space);
372 _GridLayoutImpl::SetPosition(_ControlImpl& control, int row, int column, int rowSpan, int columnSpan)
376 _Layout::LayoutItem& layoutItem = control.GetLayoutContainer();
378 result r = E_SUCCESS;
382 SysTryReturn(NID_UI, GetCore().ItemExists(layoutItem), E_INVALID_ARG, E_INVALID_ARG,
383 "[E_INVALID_ARG] The control is not belong to layout");
385 SysTryReturn(NID_UI, row >= 0, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
386 "[E_OUT_OF_RANGE] Negative input argument : row(%d)", row);
387 SysTryReturn(NID_UI, row < __maxRow, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
388 "[E_OUT_OF_RANGE] Input Argument row over the max row : row(%d), maxRow(%d)", row, __maxRow);
389 SysTryReturn(NID_UI, column >= 0, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
390 "[E_OUT_OF_RANGE] Negative input argument : column(%d)", column);
391 SysTryReturn(NID_UI, column < __maxColumn, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
392 "[E_OUT_OF_RANGE] Input Argument column over the max column : column(%d), maxColumn(%d)", column, __maxColumn);
394 SysTryReturn(NID_UI, rowSpan >= 0, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The row span is negative value.");
395 SysTryReturn(NID_UI, columnSpan >= 0, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The column span is negative value.");
397 SysTryReturn(NID_UI, (row + rowSpan - 1) < __maxRow, E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] Out of range.");
398 SysTryReturn(NID_UI, (column + columnSpan - 1) < __maxColumn, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
399 "[E_OUT_OF_RANGE] Out of range.");
401 r = GetCore().GetMergeSize(row, column, rowSize, colSize);
402 SysTryReturn(NID_UI, (r == E_SUCCESS), r, r,
403 "The specified span tries to include a cell which is already included in another span.");
405 _Layout::LayoutItem* prevItem = GetCore().GetItem(row, column);
408 if (prevItem != &layoutItem)
410 r = GetCore().SwapItemPosition(layoutItem, *prevItem);
415 r = GetCore().SetItemPosition(layoutItem, row, column);
417 GetCore().SetFillCell(row, column, false, false);
424 if (rowSpan != rowSize || columnSpan != colSize)
426 for (int y = 0; y < rowSpan; y++)
428 for (int x = 0; x < columnSpan; x++)
430 r = GetCore().Unmerge(row + y, column + x);
438 r = GetCore().Merge(row, column, row + rowSpan - 1, column + columnSpan - 1);
439 GetCore().SetFillCell(row, column, true, true);
446 _GridLayoutImpl::GetRowCount() const
452 _GridLayoutImpl::GetColumnCount() const