Fork for IVI: mesa fixing
[profile/ivi/uifw.git] / src / ui / FUi_VerticalBoxLayoutImpl.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://floralicense.org/license/
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                FUi_VerticalBoxLayoutImpl.cpp
19  * @brief       This is the implementation file for _VerticalBoxLayoutImpl class.
20  *
21  * This file contains the implementation of _VerticalBoxLayoutImpl class.
22  */
23
24 #include "FUi_VerticalBoxLayoutImpl.h"
25
26 namespace Tizen { namespace Ui
27 {
28
29 namespace
30 {
31 static const int CONVERT_ERROR_CODE = -1;
32
33 _Layout::LinearLayoutDirection
34 ConvertEnum(VerticalDirection val)
35 {
36         switch (val)
37         {
38         case VERTICAL_DIRECTION_DOWNWARD:
39                 return _Layout::LINEAR_TOP_TO_BOTTOM;
40
41         case VERTICAL_DIRECTION_UPWARD:
42                 return _Layout::LINEAR_BOTTOM_TO_TOP;
43
44         default:
45                 return _Layout::LINEAR_NONE_DIRECTION;
46         }
47 }
48
49 VerticalDirection
50 ConvertEnum(_Layout::LinearLayoutDirection val)
51 {
52         switch (val)
53         {
54         case _Layout::LINEAR_TOP_TO_BOTTOM:
55                 return VERTICAL_DIRECTION_DOWNWARD;
56
57         case _Layout::LINEAR_BOTTOM_TO_TOP:
58                 return VERTICAL_DIRECTION_UPWARD;
59
60         default:
61                 return static_cast <VerticalDirection>(CONVERT_ERROR_CODE);
62         }
63 }
64 }
65
66 // _VerticalBoxLayoutImpl implementation
67 _VerticalBoxLayoutImpl::_VerticalBoxLayoutImpl(VerticalBoxLayout* pPublicLayout, _Layout::LinearLayout* pCoreLayout)
68         : _LayoutImpl(pPublicLayout, pCoreLayout)
69 {
70 }
71
72 _VerticalBoxLayoutImpl::~_VerticalBoxLayoutImpl()
73 {
74 }
75
76 Tizen::Ui::LayoutType
77 _VerticalBoxLayoutImpl::GetLayoutType(void) const
78 {
79         return LAYOUT_VERTICAL_BOX;
80 }
81
82 result
83 _VerticalBoxLayoutImpl::Construct(VerticalDirection direction)
84 {
85         ClearLastResult();
86
87         _Layout::LinearLayoutDirection linearDirection = ConvertEnum(direction);
88         SysTryReturn(NID_UI, linearDirection != _Layout::LINEAR_NONE_DIRECTION,
89                                 E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The argument is invalid data.");
90
91         result r = GetCore().Initialize(_Layout::LINEAR_VERTICAL, linearDirection);
92
93         return r;
94 }
95
96 result
97 _VerticalBoxLayoutImpl::GetDirection(VerticalDirection& direction) const
98 {
99         ClearLastResult();
100
101         _Layout::LinearLayoutDirection internalDirection;
102         result r = E_SUCCESS;
103
104         r = GetCore().GetDirection(internalDirection);
105         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
106         direction = ConvertEnum(internalDirection);
107
108         return r;
109 }
110
111 result
112 _VerticalBoxLayoutImpl::SetHorizontalAlignment(_ControlImpl& control, LayoutHorizontalAlignment horAlign)
113 {
114         result r = SetAlignment(control, horAlign, LAYOUT_VERTICAL_ALIGN_TOP);
115
116         return r;
117 }
118
119 result
120 _VerticalBoxLayoutImpl::SetSpacing(_ControlImpl& control, int space)
121 {
122         ClearLastResult();
123
124         _Layout::LayoutItem& layoutItem = control.GetLayoutContainer();
125
126         result r = GetCore().SetItemSpacing(layoutItem, space);
127
128         return r;
129 }
130
131 result
132 _VerticalBoxLayoutImpl::SetHorizontalMargin(_ControlImpl& control, int left, int right)
133 {
134         result r = SetMargin(control, left, right, 0, 0);
135
136         return r;
137 }
138
139 result
140 _VerticalBoxLayoutImpl::SetWidth(_ControlImpl& control, int width)
141 {
142         ClearLastResult();
143
144         result r = SetHorizontalFitPolicy(control, FIT_POLICY_FIXED);
145         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
146
147         _Layout::LayoutRect rect;
148         r = GetItemBaseRect(control, rect);
149         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
150
151         rect.w = width;
152         r = SetItemBaseRect(control, rect);
153         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
154
155         return r;
156 }
157
158 result
159 _VerticalBoxLayoutImpl::SetItemHorizontalFitPolicy(_ControlImpl& control, FitPolicy policy)
160 {
161         result r = SetHorizontalFitPolicy(control, policy);
162
163         return r;
164 }
165
166 result
167 _VerticalBoxLayoutImpl::SetHeight(_ControlImpl& control, int height)
168 {
169         ClearLastResult();
170
171         result r = SetVerticalFitPolicy(control, FIT_POLICY_FIXED);
172         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
173
174         _Layout::LayoutRect rect;
175         r = GetItemBaseRect(control, rect);
176         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
177
178         rect.h = height;
179         r = SetItemBaseRect(control, rect);
180         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
181
182         return r;
183 }
184
185 result
186 _VerticalBoxLayoutImpl::SetItemVerticalFitPolicy(_ControlImpl& control, FitPolicy policy)
187 {
188         result r = SetVerticalFitPolicy(control, policy);
189
190         return r;
191 }
192
193 result
194 _VerticalBoxLayoutImpl::SetWeight(_ControlImpl& control, float weight)
195 {
196         ClearLastResult();
197
198         _Layout::LayoutItem& layoutItem = control.GetLayoutContainer();
199
200         result r = GetCore().SetItemWeight(layoutItem, weight);
201
202         return r;
203 }
204
205 _VerticalBoxLayoutImpl*
206 _VerticalBoxLayoutImpl::CreateVerticalBoxLayoutImplN(VerticalBoxLayout* pPublicLayout, VerticalDirection direction)
207 {
208         ClearLastResult();
209
210         _Layout::LinearLayout* pCoreLayout = null;
211         _VerticalBoxLayoutImpl* pImplLayout = null;
212         result r = E_SUCCESS;
213
214         pCoreLayout = _Layout::LinearLayout::CreateLinearLayoutN();
215         r = GetLastResult();
216         SysTryReturn(NID_UI, pCoreLayout != null, null, r, "[%s] Propagating.", GetErrorMessage(r));
217
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));
221
222         r = pImplLayout->Construct(direction);
223         if (r != E_SUCCESS)
224         {
225                 delete pImplLayout;
226                 SysTryReturn(NID_UI, false, null, E_INVALID_ARG, "[E_INVALID_ARG] The Direction is invalid.");
227         }
228
229         return pImplLayout;
230 }
231
232 const char*
233 _VerticalBoxLayoutImpl::GetPublicClassName(void) const
234 {
235         return "Tizen::Ui::VerticalBoxLayout";
236 }
237
238 const VerticalBoxLayout&
239 _VerticalBoxLayoutImpl::GetPublic(void) const
240 {
241         return static_cast <const VerticalBoxLayout&>(_LayoutImpl::GetPublic());
242 }
243
244 VerticalBoxLayout&
245 _VerticalBoxLayoutImpl::GetPublic(void)
246 {
247         return static_cast <VerticalBoxLayout&>(_LayoutImpl::GetPublic());
248 }
249
250 const _Layout::LinearLayout&
251 _VerticalBoxLayoutImpl::GetCore(void) const
252 {
253         return static_cast <const _Layout::LinearLayout&>(_LayoutImpl::GetCore());
254 }
255
256 _Layout::LinearLayout&
257 _VerticalBoxLayoutImpl::GetCore(void)
258 {
259         return static_cast <_Layout::LinearLayout&>(_LayoutImpl::GetCore());
260 }
261
262 const _VerticalBoxLayoutImpl*
263 _VerticalBoxLayoutImpl::GetInstance(const VerticalBoxLayout& layout)
264 {
265         return static_cast<const _VerticalBoxLayoutImpl*>(_LayoutImpl::GetInstance(layout));
266 }
267
268 _VerticalBoxLayoutImpl*
269 _VerticalBoxLayoutImpl::GetInstance(VerticalBoxLayout& layout)
270 {
271         return static_cast<_VerticalBoxLayoutImpl*>(_LayoutImpl::GetInstance(layout));
272 }
273
274 }} // Tizen::Ui