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