2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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"
26 namespace Tizen { namespace Ui
29 // _GridLayoutImpl implementation
30 _GridLayoutImpl::_GridLayoutImpl(GridLayout* pPublicLayout, _Layout::TableLayout* pCoreLayout)
31 : _LayoutImpl(pPublicLayout, pCoreLayout)
37 _GridLayoutImpl::~_GridLayoutImpl()
42 _GridLayoutImpl::GetLayoutType(void) const
48 _GridLayoutImpl::CreateGridLayoutImplN(GridLayout* pPublicLayout, int maxRow, int maxColumn)
52 _Layout::TableLayout* pCoreLayout = null;
53 _GridLayoutImpl* pImplLayout = null;
56 pCoreLayout = _Layout::TableLayout::CreateTableLayoutN();
58 SysTryReturn(NID_UI, pCoreLayout != null, null, r, "[%s] Propagating.", GetErrorMessage(r));
60 pImplLayout = new (std::nothrow) _GridLayoutImpl(pPublicLayout, pCoreLayout);
61 r = CheckConstruction(pCoreLayout, pImplLayout);
62 SysTryReturn(NID_UI, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
64 r = pImplLayout->Construct(maxRow, maxColumn);
68 SysTryReturn(NID_UI, false, null, r, "[%s] Propagating.", GetErrorMessage(r));
75 _GridLayoutImpl::GetPublicClassName(void) const
77 return "Tizen::Ui::GridLayout";
81 _GridLayoutImpl::GetPublic(void) const
83 return static_cast <const GridLayout&>(_LayoutImpl::GetPublic());
87 _GridLayoutImpl::GetPublic(void)
89 return static_cast <GridLayout&>(_LayoutImpl::GetPublic());
92 const _Layout::TableLayout&
93 _GridLayoutImpl::GetCore(void) const
95 return static_cast <const _Layout::TableLayout&>(_LayoutImpl::GetCore());
99 _GridLayoutImpl::GetCore(void)
101 return static_cast <_Layout::TableLayout&>(_LayoutImpl::GetCore());
104 const _GridLayoutImpl*
105 _GridLayoutImpl::GetInstance(const GridLayout& layout)
107 return static_cast<const _GridLayoutImpl*>(_LayoutImpl::GetInstance(layout));
111 _GridLayoutImpl::GetInstance(GridLayout& layout)
113 return static_cast<_GridLayoutImpl*>(_LayoutImpl::GetInstance(layout));
117 _GridLayoutImpl::Construct(int maxRow, int maxColumn)
121 result r = GetCore().CreateTable(maxRow, maxColumn);
122 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
125 __maxColumn = maxColumn;
131 _GridLayoutImpl::SetColumnStretchable(int columnIndex, bool stretchable)
135 return GetCore().SetColumnStretchable(columnIndex, stretchable);
139 _GridLayoutImpl::SetColumnShrinkable(int columnIndex, bool shrinkable)
143 return GetCore().SetColumnShrinkable(columnIndex, shrinkable);
147 _GridLayoutImpl::SetColumnCollapsed(int columnIndex, bool collapsed)
151 return GetCore().SetColumnCollapsed(columnIndex, collapsed);
155 _GridLayoutImpl::SetAllColumnsStretchable(bool stretchable)
159 result r = E_SUCCESS;
160 bool* pOldStretchable = new (std::nothrow) bool[__maxColumn];
161 SysTryReturn(NID_UI, pOldStretchable != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
162 memset(pOldStretchable, 0, sizeof(bool) * __maxColumn);
165 for (col = 0; col < __maxColumn; col++)
167 pOldStretchable[col] = GetCore().GetColumnStretchable(col);
171 SysLogException(NID_UI, E_INVALID_ARG, "[E_INVALID_ARG] max column is invalid value.");
175 r = GetCore().SetColumnStretchable(col, stretchable);
178 SysLogException(NID_UI, E_INVALID_ARG, "[E_INVALID_ARG] max column is invalid value.");
183 delete[] pOldStretchable;
188 for (int colIndex = 0; colIndex < col; colIndex++)
190 GetCore().SetColumnStretchable(colIndex, pOldStretchable[colIndex]);
193 delete[] pOldStretchable;
199 _GridLayoutImpl::SetAllColumnsShrinkable(bool shrinkable)
203 result r = E_SUCCESS;
204 bool* pOldShrinkable = new (std::nothrow) bool[__maxColumn];
205 SysTryReturn(NID_UI, pOldShrinkable != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
206 memset(pOldShrinkable, 0, sizeof(bool) * __maxColumn);
209 for (col = 0; col < __maxColumn; col++)
211 pOldShrinkable[col] = GetCore().GetColumnShrinkable(col);
215 SysLogException(NID_UI, E_INVALID_ARG, "[E_INVALID_ARG] max column is invalid value.");
219 r = GetCore().SetColumnShrinkable(col, shrinkable);
222 SysLogException(NID_UI, E_INVALID_ARG, "[E_INVALID_ARG] max column is invalid value.");
227 delete[] pOldShrinkable;
232 for (int colIndex = 0; colIndex < col; colIndex++)
234 GetCore().SetColumnShrinkable(colIndex, pOldShrinkable[colIndex]);
237 delete[] pOldShrinkable;
243 _GridLayoutImpl::SetColumnSpacing(int columnIndex, int space)
247 return GetCore().SetColumnSpacing(columnIndex, space);
251 _GridLayoutImpl::SetRowStretchable(int rowIndex, bool stretchable)
255 return GetCore().SetRowStretchable(rowIndex, stretchable);
259 _GridLayoutImpl::SetRowShrinkable(int rowIndex, bool shrinkable)
263 return GetCore().SetRowShrinkable(rowIndex, shrinkable);
267 _GridLayoutImpl::SetRowCollapsed(int rowIndex, bool collapsed)
271 return GetCore().SetRowCollapsed(rowIndex, collapsed);
275 _GridLayoutImpl::SetAllRowsStretchable(bool stretchable)
279 result r = E_SUCCESS;
280 bool* pOldStretchable = new (std::nothrow) bool[__maxRow];
281 SysTryReturn(NID_UI, pOldStretchable != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
282 memset(pOldStretchable, 0, sizeof(bool) * __maxRow);
286 for (row = 0; row < __maxRow; row++)
288 pOldStretchable[row] = GetCore().GetRowStretchable(row);
292 SysLogException(NID_UI, E_INVALID_ARG, "[E_INVALID_ARG] max row is invalid value.");
296 r = GetCore().SetRowStretchable(row, stretchable);
299 SysLogException(NID_UI, E_INVALID_ARG, "[E_INVALID_ARG] max row is invalid value.");
304 delete[] pOldStretchable;
309 for (int rowIndex = 0; rowIndex < row; rowIndex++)
311 GetCore().SetRowStretchable(rowIndex, pOldStretchable[rowIndex]);
314 delete[] pOldStretchable;
320 _GridLayoutImpl::SetAllRowsShrinkable(bool shrinkable)
324 result r = E_SUCCESS;
325 bool* pOldShrinkable = new (std::nothrow) bool[__maxRow];
326 SysTryReturn(NID_UI, pOldShrinkable != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
327 memset(pOldShrinkable, 0, sizeof(bool) * __maxRow);
330 for (row = 0; row < __maxRow; row++)
332 pOldShrinkable[row] = GetCore().GetRowShrinkable(row);
336 SysLogException(NID_UI, E_INVALID_ARG, "[E_INVALID_ARG] max row is invalid value.");
340 r = GetCore().SetRowShrinkable(row, shrinkable);
343 SysLogException(NID_UI, E_INVALID_ARG, "[E_INVALID_ARG] max row is invalid value.");
348 delete[] pOldShrinkable;
353 for (int rowIndex = 0; rowIndex < row; rowIndex++)
355 GetCore().SetRowShrinkable(rowIndex, pOldShrinkable[rowIndex]);
357 delete[] pOldShrinkable;
363 _GridLayoutImpl::SetRowSpacing(int rowIndex, int space)
367 return GetCore().SetRowSpacing(rowIndex, space);
371 _GridLayoutImpl::SetPosition(_ControlImpl& control, int row, int column, int rowSpan, int columnSpan)
375 _Layout::LayoutItem& layoutItem = control.GetLayoutContainer();
377 result r = E_SUCCESS;
381 SysTryReturn(NID_UI, GetCore().ItemExists(layoutItem), E_INVALID_ARG, E_INVALID_ARG,
382 "[E_INVALID_ARG] The control is not belong to layout");
384 SysTryReturn(NID_UI, row >= 0, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
385 "[E_OUT_OF_RANGE] Negative input argument : row(%d)", row);
386 SysTryReturn(NID_UI, row < __maxRow, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
387 "[E_OUT_OF_RANGE] Input Argument row over the max row : row(%d), maxRow(%d)", row, __maxRow);
388 SysTryReturn(NID_UI, column >= 0, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
389 "[E_OUT_OF_RANGE] Negative input argument : column(%d)", column);
390 SysTryReturn(NID_UI, column < __maxColumn, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
391 "[E_OUT_OF_RANGE] Input Argument column over the max column : column(%d), maxColumn(%d)", column, __maxColumn);
393 SysTryReturn(NID_UI, rowSpan >= 0, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The row span is negative value.");
394 SysTryReturn(NID_UI, columnSpan >= 0, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The column span is negative value.");
396 SysTryReturn(NID_UI, (row + rowSpan - 1) < __maxRow, E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] Out of range.");
397 SysTryReturn(NID_UI, (column + columnSpan - 1) < __maxColumn, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
398 "[E_OUT_OF_RANGE] Out of range.");
400 r = GetCore().GetMergeSize(row, column, rowSize, colSize);
401 SysTryReturn(NID_UI, (r == E_SUCCESS), r, r,
402 "The specified span tries to include a cell which is already included in another span.");
404 _Layout::LayoutItem* prevItem = GetCore().GetItem(row, column);
407 if (prevItem != &layoutItem)
409 r = GetCore().SwapItemPosition(layoutItem, *prevItem);
414 r = GetCore().SetItemPosition(layoutItem, row, column);
416 GetCore().SetFillCell(row, column, false, false);
423 if (rowSpan != rowSize || columnSpan != colSize)
425 for (int y = 0; y < rowSpan; y++)
427 for (int x = 0; x < columnSpan; x++)
429 r = GetCore().Unmerge(row + y, column + x);
437 r = GetCore().Merge(row, column, row + rowSpan - 1, column + columnSpan - 1);
438 GetCore().SetFillCell(row, column, true, true);
445 _GridLayoutImpl::GetRowCount() const
451 _GridLayoutImpl::GetColumnCount() const