Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / controls / FUiCtrlLabel.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                 FUiCtrlLabel.cpp
19 * @brief                This is the implementation file for Label class.
20 */
21
22 #include <FUiCtrlLabel.h>
23 #include <FBaseSysLog.h>
24 #include "FUiCtrl_LabelImpl.h"
25
26 #define MINIMUM_VALUE   0
27 #define MAXIMUM_VALUE   65535
28
29 using namespace Tizen::Base;
30 using namespace Tizen::Graphics;
31
32 namespace Tizen { namespace Ui { namespace Controls
33 {
34
35 Label::Label(void)
36 {
37
38 }
39
40 Label::~Label(void)
41 {
42
43 }
44
45 result
46 Label::Construct(const Rectangle& rect, const String& text)
47 {
48         SysTryReturn(NID_UI_CTRL, (rect.width >= MINIMUM_VALUE && rect.width <= MAXIMUM_VALUE), E_INVALID_ARG, E_INVALID_ARG,
49                         "[E_INVALID_ARG] The width error occurred");
50
51         SysTryReturn(NID_UI_CTRL, (rect.height >= MINIMUM_VALUE && rect.height <= MAXIMUM_VALUE), E_INVALID_ARG, E_INVALID_ARG,
52                         "[E_INVALID_ARG] The height error occurred");
53
54         result r = E_SUCCESS;
55         _LabelImpl* pLabelImpl = _LabelImpl::GetInstance(*this);
56
57         SysAssertf(pLabelImpl == null,
58                         "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
59
60         pLabelImpl = _LabelImpl::CreateLabelImplN(this, rect);
61         r = GetLastResult();
62         SysTryReturn(NID_UI_CTRL, pLabelImpl, r, r, "[%s] Propagating.", GetErrorMessage(r));
63
64         r = pLabelImpl->SetText(text);
65         SysAssert(r == E_SUCCESS); // [ToDo] Exception. Which exception can occur?
66
67         _pControlImpl = pLabelImpl;
68
69         return E_SUCCESS;
70 }
71
72 void
73 Label::SetText(const String& text)
74 {
75         _LabelImpl* pLabelImpl = _LabelImpl::GetInstance(*this);
76         SysAssertf(pLabelImpl != null,
77                         "Not yet constructed. Construct() should be called before use.");
78
79         pLabelImpl->SetText(text);
80
81         return;
82 }
83
84 String
85 Label::GetText(void) const
86 {
87         const _LabelImpl* pLabelImpl = _LabelImpl::GetInstance(*this);
88         SysAssertf(pLabelImpl != null,
89                         "Not yet constructed. Construct() should be called before use.");
90
91         return pLabelImpl->GetText();
92 }
93
94 void
95 Label::SetBackgroundBitmap(const Bitmap& bitmap)
96 {
97         _LabelImpl* pLabelImpl = _LabelImpl::GetInstance(*this);
98         SysAssertf(pLabelImpl != null,
99                         "Not yet constructed. Construct() should be called before use.");
100
101         pLabelImpl->SetBackgroundBitmap(bitmap);
102
103         return;
104 }
105
106 void
107 Label::SetTextHorizontalAlignment(HorizontalAlignment alignment)
108 {
109         _LabelImpl* pLabelImpl = _LabelImpl::GetInstance(*this);
110         SysAssertf(pLabelImpl != null,
111                         "Not yet constructed. Construct() should be called before use.");
112
113         pLabelImpl->SetTextHorizontalAlignment(alignment);
114
115         return;
116 }
117
118 void
119 Label::SetTextVerticalAlignment(VerticalAlignment alignment)
120 {
121         _LabelImpl* pLabelImpl = _LabelImpl::GetInstance(*this);
122         SysAssertf(pLabelImpl != null,
123                         "Not yet constructed. Construct() should be called before use.");
124
125         pLabelImpl->SetTextVerticalAlignment(alignment);
126
127         return;
128 }
129
130 HorizontalAlignment
131 Label::GetTextHorizontalAlignment(void) const
132 {
133         const _LabelImpl* pLabelImpl = _LabelImpl::GetInstance(*this);
134         SysAssertf(pLabelImpl != null,
135                         "Not yet constructed. Construct() should be called before use.");
136
137         return pLabelImpl->GetTextHorizontalAlignment();
138 }
139
140 VerticalAlignment
141 Label::GetTextVerticalAlignment(void) const
142 {
143         const _LabelImpl* pLabelImpl = _LabelImpl::GetInstance(*this);
144         SysAssertf(pLabelImpl != null,
145                         "Not yet constructed. Construct() should be called before use.");
146
147         return pLabelImpl->GetTextVerticalAlignment();
148 }
149
150 void
151 Label::SetBackgroundColor(const Color& color)
152 {
153         _LabelImpl* pLabelImpl = _LabelImpl::GetInstance(*this);
154         SysAssertf(pLabelImpl != null,
155                         "Not yet constructed. Construct() should be called before use.");
156
157         pLabelImpl->SetBackgroundColor(color);
158
159         return;
160 }
161
162 Color
163 Label::GetBackgroundColor(void) const
164 {
165         const _LabelImpl* pLabelImpl = _LabelImpl::GetInstance(*this);
166         SysAssertf(pLabelImpl != null,
167                         "Not yet constructed. Construct() should be called before use.");
168
169         return pLabelImpl->GetBackgroundColor();
170 }
171
172 void
173 Label::SetTextColor(const Color& color)
174 {
175         _LabelImpl* pLabelImpl = _LabelImpl::GetInstance(*this);
176         SysAssertf(pLabelImpl != null,
177                         "Not yet constructed. Construct() should be called before use.");
178
179         pLabelImpl->SetTextColor(color);
180
181         return;
182 }
183
184 Color
185 Label::GetTextColor(void) const
186 {
187         const _LabelImpl* pLabelImpl = _LabelImpl::GetInstance(*this);
188         SysAssertf(pLabelImpl != null,
189                         "Not yet constructed. Construct() should be called before use.");
190
191         return pLabelImpl->GetTextColor();
192 }
193
194 void
195 Label::SetTextConfig(int size, LabelTextStyle style)
196 {
197         _LabelImpl* pLabelImpl = _LabelImpl::GetInstance(*this);
198         SysAssertf(pLabelImpl != null,
199                         "Not yet constructed. Construct() should be called before use.");
200
201         pLabelImpl->SetTextConfig(size, style);
202
203         return;
204 }
205
206 int
207 Label::GetTextSize(void) const
208 {
209         const _LabelImpl* pLabelImpl = _LabelImpl::GetInstance(*this);
210         SysAssertf(pLabelImpl != null,
211                         "Not yet constructed. Construct() should be called before use.");
212
213         return pLabelImpl->GetTextSize();
214 }
215
216 LabelTextStyle
217 Label::GetTextStyle(void) const
218 {
219         const _LabelImpl* pLabelImpl = _LabelImpl::GetInstance(*this);
220         SysAssertf(pLabelImpl != null,
221                         "Not yet constructed. Construct() should be called before use.");
222
223         return pLabelImpl->GetTextStyle();
224 }
225
226 result
227 Label::SetMargin(int topMargin, int leftMargin)
228 {
229         _LabelImpl* pLabelImpl = _LabelImpl::GetInstance(*this);
230         SysAssertf(pLabelImpl != null,
231                         "Not yet constructed. Construct() should be called before use.");
232
233         result r = pLabelImpl->SetMargin(topMargin, leftMargin);
234         SysTryLog(NID_UI_CTRL, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
235
236         return r;
237 }
238
239 int
240 Label::GetTopMargin(void) const
241 {
242         const _LabelImpl* pLabelImpl = _LabelImpl::GetInstance(*this);
243         SysAssertf(pLabelImpl != null,
244                         "Not yet constructed. Construct() should be called before use.");
245
246         return pLabelImpl->GetTopMargin();
247 }
248
249 int
250 Label::GetLeftMargin(void) const
251 {
252         const _LabelImpl* pLabelImpl = _LabelImpl::GetInstance(*this);
253         SysAssertf(pLabelImpl != null,
254                         "Not yet constructed. Construct() should be called before use.");
255
256         return pLabelImpl->GetLeftMargin();
257 }
258
259 }}} // Tizen::Ui::Controls