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_VerticalBoxLayoutImpl.cpp
19 * @brief This is the implementation file for _VerticalBoxLayoutImpl class.
21 * This file contains the implementation of _VerticalBoxLayoutImpl class.
24 #include "FUi_VerticalBoxLayoutImpl.h"
25 #include "FUi_CoordinateSystemUtils.h"
27 namespace Tizen { namespace Ui
32 static const int CONVERT_ERROR_CODE = -1;
34 _Layout::LinearLayoutDirection
35 ConvertEnum(VerticalDirection val)
39 case VERTICAL_DIRECTION_DOWNWARD:
40 return _Layout::LINEAR_TOP_TO_BOTTOM;
42 case VERTICAL_DIRECTION_UPWARD:
43 return _Layout::LINEAR_BOTTOM_TO_TOP;
46 return _Layout::LINEAR_NONE_DIRECTION;
51 ConvertEnum(_Layout::LinearLayoutDirection val)
55 case _Layout::LINEAR_TOP_TO_BOTTOM:
56 return VERTICAL_DIRECTION_DOWNWARD;
58 case _Layout::LINEAR_BOTTOM_TO_TOP:
59 return VERTICAL_DIRECTION_UPWARD;
62 return static_cast <VerticalDirection>(CONVERT_ERROR_CODE);
67 // _VerticalBoxLayoutImpl implementation
68 _VerticalBoxLayoutImpl::_VerticalBoxLayoutImpl(VerticalBoxLayout* pPublicLayout, _Layout::LinearLayout* pCoreLayout)
69 : _LayoutImpl(pPublicLayout, pCoreLayout)
73 _VerticalBoxLayoutImpl::~_VerticalBoxLayoutImpl()
78 _VerticalBoxLayoutImpl::GetLayoutType(void) const
80 return LAYOUT_VERTICAL_BOX;
84 _VerticalBoxLayoutImpl::Construct(VerticalDirection direction)
88 _Layout::LinearLayoutDirection linearDirection = ConvertEnum(direction);
89 SysTryReturn(NID_UI, linearDirection != _Layout::LINEAR_NONE_DIRECTION,
90 E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The argument is invalid data.");
92 result r = GetCore().Initialize(_Layout::LINEAR_VERTICAL, linearDirection);
98 _VerticalBoxLayoutImpl::GetDirection(VerticalDirection& direction) const
102 _Layout::LinearLayoutDirection internalDirection;
104 result r = GetCore().GetDirection(internalDirection);
105 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
106 direction = ConvertEnum(internalDirection);
112 _VerticalBoxLayoutImpl::SetHorizontalAlignment(_ControlImpl& control, LayoutHorizontalAlignment horAlign)
114 result r = SetAlignment(control, horAlign, LAYOUT_VERTICAL_ALIGN_TOP);
120 _VerticalBoxLayoutImpl::SetSpacing(_ControlImpl& control, float space)
124 _Layout::LayoutItem& layoutItem = control.GetLayoutContainer();
126 result r = GetCore().SetItemSpacing(layoutItem, space);
132 _VerticalBoxLayoutImpl::SetHorizontalMargin(_ControlImpl& control, float left, float right)
134 result r = SetMargin(control, left, right, 0.0f, 0.0f);
140 _VerticalBoxLayoutImpl::SetWidth(_ControlImpl& control, float width)
144 result r = SetHorizontalFitPolicy(control, FIT_POLICY_FIXED);
145 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
147 _Layout::LayoutRect rect;
148 r = GetItemBaseRect(control, rect);
149 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
152 r = SetItemBaseRect(control, rect);
153 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
159 _VerticalBoxLayoutImpl::SetItemHorizontalFitPolicy(_ControlImpl& control, FitPolicy policy)
161 result r = SetHorizontalFitPolicy(control, policy);
167 _VerticalBoxLayoutImpl::SetHeight(_ControlImpl& control, float height)
171 result r = SetVerticalFitPolicy(control, FIT_POLICY_FIXED);
172 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
174 _Layout::LayoutRect rect;
175 r = GetItemBaseRect(control, rect);
176 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
179 r = SetItemBaseRect(control, rect);
180 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
186 _VerticalBoxLayoutImpl::SetItemVerticalFitPolicy(_ControlImpl& control, FitPolicy policy)
188 result r = SetVerticalFitPolicy(control, policy);
194 _VerticalBoxLayoutImpl::SetWeight(_ControlImpl& control, float weight)
198 _Layout::LayoutItem& layoutItem = control.GetLayoutContainer();
200 result r = GetCore().SetItemWeight(layoutItem, weight);
205 _VerticalBoxLayoutImpl*
206 _VerticalBoxLayoutImpl::CreateVerticalBoxLayoutImplN(VerticalBoxLayout* pPublicLayout, VerticalDirection direction)
210 _Layout::LinearLayout* pCoreLayout = null;
211 _VerticalBoxLayoutImpl* pImplLayout = null;
212 result r = E_SUCCESS;
214 pCoreLayout = _Layout::LinearLayout::CreateLinearLayoutN();
216 SysTryReturn(NID_UI, pCoreLayout != null, null, r, "[%s] Propagating.", GetErrorMessage(r));
218 pImplLayout = new (std::nothrow) _VerticalBoxLayoutImpl(pPublicLayout, pCoreLayout);
219 r = CheckConstruction(pCoreLayout, pImplLayout);
220 SysTryReturn(NID_UI, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
222 r = pImplLayout->Construct(direction);
226 SysTryReturn(NID_UI, false, null, E_INVALID_ARG, "[E_INVALID_ARG] The Direction is invalid.");
233 _VerticalBoxLayoutImpl::GetPublicClassName(void) const
235 return "Tizen::Ui::VerticalBoxLayout";
238 const VerticalBoxLayout&
239 _VerticalBoxLayoutImpl::GetPublic(void) const
241 return static_cast <const VerticalBoxLayout&>(_LayoutImpl::GetPublic());
245 _VerticalBoxLayoutImpl::GetPublic(void)
247 return static_cast <VerticalBoxLayout&>(_LayoutImpl::GetPublic());
250 const _Layout::LinearLayout&
251 _VerticalBoxLayoutImpl::GetCore(void) const
253 return static_cast <const _Layout::LinearLayout&>(_LayoutImpl::GetCore());
256 _Layout::LinearLayout&
257 _VerticalBoxLayoutImpl::GetCore(void)
259 return static_cast <_Layout::LinearLayout&>(_LayoutImpl::GetCore());
262 const _VerticalBoxLayoutImpl*
263 _VerticalBoxLayoutImpl::GetInstance(const VerticalBoxLayout& layout)
265 return static_cast <const _VerticalBoxLayoutImpl*>(_LayoutImpl::GetInstance(layout));
268 _VerticalBoxLayoutImpl*
269 _VerticalBoxLayoutImpl::GetInstance(VerticalBoxLayout& layout)
271 return static_cast <_VerticalBoxLayoutImpl*>(_LayoutImpl::GetInstance(layout));