Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / FUiVerticalBoxLayout.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                FUiVerticalBoxLayout.cpp
19  * @brief       This is the implementation file for VerticalBoxLayout class.
20  *
21  * This file contains the implementation of VerticalBoxLayout class.
22  */
23
24 #include <FUiVerticalBoxLayout.h>
25 #include <FUiControl.h>
26 #include <FApp_AppInfo.h>
27 #include "FUi_VerticalBoxLayoutImpl.h"
28
29 namespace Tizen { namespace Ui
30 {
31
32 VerticalBoxLayout::VerticalBoxLayout()
33 {
34 }
35
36 VerticalBoxLayout::~VerticalBoxLayout()
37 {
38 }
39
40 result
41 VerticalBoxLayout::Construct(VerticalDirection direction)
42 {
43         ClearLastResult();
44
45         _VerticalBoxLayoutImpl* pVerticalBoxLayoutImpl = _VerticalBoxLayoutImpl::GetInstance(*this);
46         SysAssertf(pVerticalBoxLayoutImpl == null, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
47
48         pVerticalBoxLayoutImpl = _VerticalBoxLayoutImpl::CreateVerticalBoxLayoutImplN(this, direction);
49         result r = GetLastResult();
50         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
51
52         _LayoutImpl::SetLayoutImpl(this, pVerticalBoxLayoutImpl);
53
54         return E_SUCCESS;
55 }
56
57 Tizen::Ui::LayoutType
58 VerticalBoxLayout::GetLayoutType(void) const
59 {
60         return LAYOUT_VERTICAL_BOX;
61 }
62
63 result
64 VerticalBoxLayout::GetDirection(VerticalDirection& direction) const
65 {
66         ClearLastResult();
67
68         const _VerticalBoxLayoutImpl* pVerticalBoxLayoutImpl = _VerticalBoxLayoutImpl::GetInstance(*this);
69         SysAssertf(pVerticalBoxLayoutImpl != null, "Not yet constructed. Construct() should be called before use.");
70
71         result r = pVerticalBoxLayoutImpl->GetDirection(direction);
72         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
73
74         return r;
75 }
76
77 result
78 VerticalBoxLayout::SetHorizontalAlignment(Control& childControl, LayoutHorizontalAlignment alignment)
79 {
80         ClearLastResult();
81
82         _VerticalBoxLayoutImpl* pVerticalBoxLayoutImpl = _VerticalBoxLayoutImpl::GetInstance(*this);
83         SysAssertf(pVerticalBoxLayoutImpl != null, "Not yet constructed. Construct() should be called before use.");
84
85         _ControlImpl* pControlImpl = _ControlImpl::GetInstance(childControl);
86         SysTryReturn(NID_UI, pControlImpl, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] This instance is not constructed.");
87
88         result r = pVerticalBoxLayoutImpl->SetHorizontalAlignment(*pControlImpl, alignment);
89         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
90
91         return r;
92 }
93
94 result
95 VerticalBoxLayout::SetSpacing(Control& childControl, int space)
96 {
97         ClearLastResult();
98
99         SysTryReturn(NID_UI, space >= 0, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The given parameter is invalid.");
100
101         _VerticalBoxLayoutImpl* pVerticalBoxLayoutImpl = _VerticalBoxLayoutImpl::GetInstance(*this);
102         SysAssertf(pVerticalBoxLayoutImpl != null, "Not yet constructed. Construct() should be called before use.");
103
104         _ControlImpl* pControlImpl = _ControlImpl::GetInstance(childControl);
105         SysTryReturn(NID_UI, pControlImpl, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] This instance is not constructed.");
106
107         result r = pVerticalBoxLayoutImpl->SetSpacing(*pControlImpl, space);
108         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
109
110         return r;
111 }
112
113 result
114 VerticalBoxLayout::SetHorizontalMargin(Control& childControl, int left, int right)
115 {
116         ClearLastResult();
117
118         SysTryReturn(NID_UI, (left >= 0) && (right >= 0), E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The given parameter is invalid.");
119
120         _VerticalBoxLayoutImpl* pVerticalBoxLayoutImpl = _VerticalBoxLayoutImpl::GetInstance(*this);
121         SysAssertf(pVerticalBoxLayoutImpl != null, "Not yet constructed. Construct() should be called before use.");
122
123         _ControlImpl* pControlImpl = _ControlImpl::GetInstance(childControl);
124         SysTryReturn(NID_UI, pControlImpl, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] This instance is not constructed.");
125
126         result r = pVerticalBoxLayoutImpl->SetHorizontalMargin(*pControlImpl, left, right);
127         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
128
129         return r;
130 }
131
132 result
133 VerticalBoxLayout::SetWidth(Control& childControl, int width)
134 {
135         ClearLastResult();
136
137         SysTryReturn(NID_UI, width >= 0, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The given parameter is invalid.");
138
139         _VerticalBoxLayoutImpl* pVerticalBoxLayoutImpl = _VerticalBoxLayoutImpl::GetInstance(*this);
140         SysAssertf(pVerticalBoxLayoutImpl != null, "Not yet constructed. Construct() should be called before use.");
141
142         _ControlImpl* pControlImpl = _ControlImpl::GetInstance(childControl);
143         SysTryReturn(NID_UI, pControlImpl, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] This instance is not constructed.");
144
145         result r = pVerticalBoxLayoutImpl->SetWidth(*pControlImpl, width);
146         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
147
148         return r;
149 }
150
151 result
152 VerticalBoxLayout::SetHorizontalFitPolicy(Control& childControl, FitPolicy policy)
153 {
154         ClearLastResult();
155
156         _VerticalBoxLayoutImpl* pVerticalBoxLayoutImpl = _VerticalBoxLayoutImpl::GetInstance(*this);
157         SysAssertf(pVerticalBoxLayoutImpl != null, "Not yet constructed. Construct() should be called before use.");
158
159         _ControlImpl* pControlImpl = _ControlImpl::GetInstance(childControl);
160         SysTryReturn(NID_UI, pControlImpl, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] This instance is not constructed.");
161
162         result r = pVerticalBoxLayoutImpl->SetItemHorizontalFitPolicy(*pControlImpl, policy);
163         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
164
165         return r;
166 }
167
168 result
169 VerticalBoxLayout::SetHeight(Control& childControl, int height)
170 {
171         ClearLastResult();
172
173         SysTryReturn(NID_UI, height >= 0, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The given parameter is invalid.");
174
175         _VerticalBoxLayoutImpl* pVerticalBoxLayoutImpl = _VerticalBoxLayoutImpl::GetInstance(*this);
176         SysAssertf(pVerticalBoxLayoutImpl != null, "Not yet constructed. Construct() should be called before use.");
177
178         _ControlImpl* pControlImpl = _ControlImpl::GetInstance(childControl);
179         SysTryReturn(NID_UI, pControlImpl, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] This instance is not constructed.");
180
181         result r = pVerticalBoxLayoutImpl->SetHeight(*pControlImpl, height);
182         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
183
184         return r;
185 }
186
187 result
188 VerticalBoxLayout::SetVerticalFitPolicy(Control& childControl, FitPolicy policy)
189 {
190         ClearLastResult();
191
192         _VerticalBoxLayoutImpl* pVerticalBoxLayoutImpl = _VerticalBoxLayoutImpl::GetInstance(*this);
193         SysAssertf(pVerticalBoxLayoutImpl != null, "Not yet constructed. Construct() should be called before use.");
194
195         _ControlImpl* pControlImpl = _ControlImpl::GetInstance(childControl);
196         SysTryReturn(NID_UI, pControlImpl, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] This instance is not constructed.");
197
198         if (!Tizen::App::_AppInfo::IsOspCompat())
199         {
200                 if (policy == FIT_POLICY_PARENT)
201                 {
202                         return E_SUCCESS;
203                 }
204         }
205
206         result r = pVerticalBoxLayoutImpl->SetItemVerticalFitPolicy(*pControlImpl, policy);
207         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
208
209         return r;
210 }
211
212 result
213 VerticalBoxLayout::SetWeight(Control& childControl, float weight)
214 {
215         ClearLastResult();
216
217         _VerticalBoxLayoutImpl* pVerticalBoxLayoutImpl = _VerticalBoxLayoutImpl::GetInstance(*this);
218         SysAssertf(pVerticalBoxLayoutImpl != null, "Not yet constructed. Construct() should be called before use.");
219
220         _ControlImpl* pControlImpl = _ControlImpl::GetInstance(childControl);
221         SysTryReturn(NID_UI, pControlImpl, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] This instance is not constructed.");
222
223         SysTryReturn(NID_UI, weight >= 0.0f, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The given parameter is invalid.\n")
224
225         result r = pVerticalBoxLayoutImpl->SetWeight(*pControlImpl, weight);
226         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
227
228         return r;
229 }
230
231 }} // Tizen::Ui