Changed indicator bg color.
[platform/framework/native/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 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
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0/
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 #include "FUi_CoordinateSystemUtils.h"
26
27 namespace Tizen { namespace Ui
28 {
29
30 namespace
31 {
32 static const int CONVERT_ERROR_CODE = -1;
33
34 _Layout::LinearLayoutDirection
35 ConvertEnum(VerticalDirection val)
36 {
37         switch (val)
38         {
39         case VERTICAL_DIRECTION_DOWNWARD:
40                 return _Layout::LINEAR_TOP_TO_BOTTOM;
41
42         case VERTICAL_DIRECTION_UPWARD:
43                 return _Layout::LINEAR_BOTTOM_TO_TOP;
44
45         default:
46                 return _Layout::LINEAR_NONE_DIRECTION;
47         }
48 }
49
50 VerticalDirection
51 ConvertEnum(_Layout::LinearLayoutDirection val)
52 {
53         switch (val)
54         {
55         case _Layout::LINEAR_TOP_TO_BOTTOM:
56                 return VERTICAL_DIRECTION_DOWNWARD;
57
58         case _Layout::LINEAR_BOTTOM_TO_TOP:
59                 return VERTICAL_DIRECTION_UPWARD;
60
61         default:
62                 return static_cast <VerticalDirection>(CONVERT_ERROR_CODE);
63         }
64 }
65 }
66
67 // _VerticalBoxLayoutImpl implementation
68 _VerticalBoxLayoutImpl::_VerticalBoxLayoutImpl(VerticalBoxLayout* pPublicLayout, _Layout::LinearLayout* pCoreLayout)
69         : _LayoutImpl(pPublicLayout, pCoreLayout)
70 {
71 }
72
73 _VerticalBoxLayoutImpl::~_VerticalBoxLayoutImpl()
74 {
75 }
76
77 Tizen::Ui::LayoutType
78 _VerticalBoxLayoutImpl::GetLayoutType(void) const
79 {
80         return LAYOUT_VERTICAL_BOX;
81 }
82
83 result
84 _VerticalBoxLayoutImpl::Construct(VerticalDirection direction)
85 {
86         ClearLastResult();
87
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.");
91
92         result r = GetCore().Initialize(_Layout::LINEAR_VERTICAL, linearDirection);
93
94         return r;
95 }
96
97 result
98 _VerticalBoxLayoutImpl::GetDirection(VerticalDirection& direction) const
99 {
100         ClearLastResult();
101
102         _Layout::LinearLayoutDirection internalDirection;
103
104         result 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, float 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, float left, float right)
133 {
134         result r = SetMargin(control, left, right, 0.0f, 0.0f);
135
136         return r;
137 }
138
139 result
140 _VerticalBoxLayoutImpl::SetWidth(_ControlImpl& control, float 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, float 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