Changed indicator bg color.
[platform/framework/native/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 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                 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 result
73 Label::Construct(const FloatRectangle& rect, const String& text)
74 {
75         SysTryReturn(NID_UI_CTRL, (rect.width >= MINIMUM_VALUE && rect.width <= MAXIMUM_VALUE), E_INVALID_ARG, E_INVALID_ARG,
76                         "[E_INVALID_ARG] The width error occurred");
77
78         SysTryReturn(NID_UI_CTRL, (rect.height >= MINIMUM_VALUE && rect.height <= MAXIMUM_VALUE), E_INVALID_ARG, E_INVALID_ARG,
79                         "[E_INVALID_ARG] The height error occurred");
80
81         result r = E_SUCCESS;
82         _LabelImpl* pLabelImpl = _LabelImpl::GetInstance(*this);
83
84         SysAssertf(pLabelImpl == null,
85                         "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
86
87         pLabelImpl = _LabelImpl::CreateLabelImplN(this, rect);
88         r = GetLastResult();
89         SysTryReturn(NID_UI_CTRL, pLabelImpl, r, r, "[%s] Propagating.", GetErrorMessage(r));
90
91         r = pLabelImpl->SetText(text);
92         SysAssert(r == E_SUCCESS); // [ToDo] Exception. Which exception can occur?
93
94         _pControlImpl = pLabelImpl;
95
96         return E_SUCCESS;
97 }
98
99 void
100 Label::SetText(const String& text)
101 {
102         _LabelImpl* pLabelImpl = _LabelImpl::GetInstance(*this);
103         SysAssertf(pLabelImpl != null,
104                         "Not yet constructed. Construct() should be called before use.");
105
106         pLabelImpl->SetText(text);
107
108         return;
109 }
110
111 String
112 Label::GetText(void) const
113 {
114         const _LabelImpl* pLabelImpl = _LabelImpl::GetInstance(*this);
115         SysAssertf(pLabelImpl != null,
116                         "Not yet constructed. Construct() should be called before use.");
117
118         return pLabelImpl->GetText();
119 }
120
121 void
122 Label::SetBackgroundBitmap(const Bitmap& bitmap)
123 {
124         _LabelImpl* pLabelImpl = _LabelImpl::GetInstance(*this);
125         SysAssertf(pLabelImpl != null,
126                         "Not yet constructed. Construct() should be called before use.");
127
128         pLabelImpl->SetBackgroundBitmap(bitmap);
129
130         return;
131 }
132
133 void
134 Label::SetTextHorizontalAlignment(HorizontalAlignment alignment)
135 {
136         _LabelImpl* pLabelImpl = _LabelImpl::GetInstance(*this);
137         SysAssertf(pLabelImpl != null,
138                         "Not yet constructed. Construct() should be called before use.");
139
140         pLabelImpl->SetTextHorizontalAlignment(alignment);
141
142         return;
143 }
144
145 void
146 Label::SetTextVerticalAlignment(VerticalAlignment alignment)
147 {
148         _LabelImpl* pLabelImpl = _LabelImpl::GetInstance(*this);
149         SysAssertf(pLabelImpl != null,
150                         "Not yet constructed. Construct() should be called before use.");
151
152         pLabelImpl->SetTextVerticalAlignment(alignment);
153
154         return;
155 }
156
157 HorizontalAlignment
158 Label::GetTextHorizontalAlignment(void) const
159 {
160         const _LabelImpl* pLabelImpl = _LabelImpl::GetInstance(*this);
161         SysAssertf(pLabelImpl != null,
162                         "Not yet constructed. Construct() should be called before use.");
163
164         return pLabelImpl->GetTextHorizontalAlignment();
165 }
166
167 VerticalAlignment
168 Label::GetTextVerticalAlignment(void) const
169 {
170         const _LabelImpl* pLabelImpl = _LabelImpl::GetInstance(*this);
171         SysAssertf(pLabelImpl != null,
172                         "Not yet constructed. Construct() should be called before use.");
173
174         return pLabelImpl->GetTextVerticalAlignment();
175 }
176
177 void
178 Label::SetBackgroundColor(const Color& color)
179 {
180         _LabelImpl* pLabelImpl = _LabelImpl::GetInstance(*this);
181         SysAssertf(pLabelImpl != null,
182                         "Not yet constructed. Construct() should be called before use.");
183
184         pLabelImpl->SetBackgroundColor(color);
185
186         return;
187 }
188
189 Color
190 Label::GetBackgroundColor(void) const
191 {
192         const _LabelImpl* pLabelImpl = _LabelImpl::GetInstance(*this);
193         SysAssertf(pLabelImpl != null,
194                         "Not yet constructed. Construct() should be called before use.");
195
196         return pLabelImpl->GetBackgroundColor();
197 }
198
199 void
200 Label::SetTextColor(const Color& color)
201 {
202         _LabelImpl* pLabelImpl = _LabelImpl::GetInstance(*this);
203         SysAssertf(pLabelImpl != null,
204                         "Not yet constructed. Construct() should be called before use.");
205
206         pLabelImpl->SetTextColor(color);
207
208         return;
209 }
210
211 Color
212 Label::GetTextColor(void) const
213 {
214         const _LabelImpl* pLabelImpl = _LabelImpl::GetInstance(*this);
215         SysAssertf(pLabelImpl != null,
216                         "Not yet constructed. Construct() should be called before use.");
217
218         return pLabelImpl->GetTextColor();
219 }
220
221 void
222 Label::SetTextConfig(int size, LabelTextStyle style)
223 {
224         _LabelImpl* pLabelImpl = _LabelImpl::GetInstance(*this);
225         SysAssertf(pLabelImpl != null,
226                         "Not yet constructed. Construct() should be called before use.");
227
228         pLabelImpl->SetTextConfig(size, style);
229
230         return;
231 }
232
233 void
234 Label::SetTextConfig(float size, LabelTextStyle style)
235 {
236         _LabelImpl* pLabelImpl = _LabelImpl::GetInstance(*this);
237         SysAssertf(pLabelImpl != null,
238                         "Not yet constructed. Construct() should be called before use.");
239
240         pLabelImpl->SetTextConfig(size, style);
241
242         return;
243 }
244
245 int
246 Label::GetTextSize(void) const
247 {
248         const _LabelImpl* pLabelImpl = _LabelImpl::GetInstance(*this);
249         SysAssertf(pLabelImpl != null,
250                         "Not yet constructed. Construct() should be called before use.");
251
252         return pLabelImpl->GetTextSize();
253 }
254
255 float
256 Label::GetTextSizeF(void) const
257 {
258         const _LabelImpl* pLabelImpl = _LabelImpl::GetInstance(*this);
259         SysAssertf(pLabelImpl != null,
260                         "Not yet constructed. Construct() should be called before use.");
261
262         return pLabelImpl->GetTextSizeF();
263 }
264
265 LabelTextStyle
266 Label::GetTextStyle(void) const
267 {
268         const _LabelImpl* pLabelImpl = _LabelImpl::GetInstance(*this);
269         SysAssertf(pLabelImpl != null,
270                         "Not yet constructed. Construct() should be called before use.");
271
272         return pLabelImpl->GetTextStyle();
273 }
274
275 result
276 Label::SetMargin(int topMargin, int leftMargin)
277 {
278         _LabelImpl* pLabelImpl = _LabelImpl::GetInstance(*this);
279         SysAssertf(pLabelImpl != null,
280                         "Not yet constructed. Construct() should be called before use.");
281
282         result r = pLabelImpl->SetMargin(topMargin, leftMargin);
283         SysTryLog(NID_UI_CTRL, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
284
285         return r;
286 }
287
288 result
289 Label::SetMargin(float topMargin, float leftMargin)
290 {
291         _LabelImpl* pLabelImpl = _LabelImpl::GetInstance(*this);
292         SysAssertf(pLabelImpl != null,
293                         "Not yet constructed. Construct() should be called before use.");
294
295         result r = pLabelImpl->SetMargin(topMargin, leftMargin);
296         SysTryLog(NID_UI_CTRL, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
297
298         return r;
299 }
300
301 int
302 Label::GetTopMargin(void) const
303 {
304         const _LabelImpl* pLabelImpl = _LabelImpl::GetInstance(*this);
305         SysAssertf(pLabelImpl != null,
306                         "Not yet constructed. Construct() should be called before use.");
307
308         return pLabelImpl->GetTopMargin();
309 }
310
311 float
312 Label::GetTopMarginF(void) const
313 {
314         const _LabelImpl* pLabelImpl = _LabelImpl::GetInstance(*this);
315         SysAssertf(pLabelImpl != null,
316                         "Not yet constructed. Construct() should be called before use.");
317
318         return pLabelImpl->GetTopMarginF();
319 }
320
321 int
322 Label::GetLeftMargin(void) const
323 {
324         const _LabelImpl* pLabelImpl = _LabelImpl::GetInstance(*this);
325         SysAssertf(pLabelImpl != null,
326                         "Not yet constructed. Construct() should be called before use.");
327
328         return pLabelImpl->GetLeftMargin();
329 }
330
331 float
332 Label::GetLeftMarginF(void) const
333 {
334         const _LabelImpl* pLabelImpl = _LabelImpl::GetInstance(*this);
335         SysAssertf(pLabelImpl != null,
336                         "Not yet constructed. Construct() should be called before use.");
337
338         return pLabelImpl->GetLeftMarginF();
339 }
340
341 }}} // Tizen::Ui::Controls