2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0/
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.
18 * @file FUiCtrlLabel.cpp
19 * @brief This is the implementation file for Label class.
22 #include <FUiCtrlLabel.h>
23 #include <FBaseSysLog.h>
24 #include "FUiCtrl_LabelImpl.h"
26 #define MINIMUM_VALUE 0
27 #define MAXIMUM_VALUE 65535
29 using namespace Tizen::Base;
30 using namespace Tizen::Graphics;
32 namespace Tizen { namespace Ui { namespace Controls
46 Label::Construct(const Rectangle& rect, const String& text)
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");
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");
55 _LabelImpl* pLabelImpl = _LabelImpl::GetInstance(*this);
57 SysAssertf(pLabelImpl == null,
58 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
60 pLabelImpl = _LabelImpl::CreateLabelImplN(this, rect);
62 SysTryReturn(NID_UI_CTRL, pLabelImpl, r, r, "[%s] Propagating.", GetErrorMessage(r));
64 r = pLabelImpl->SetText(text);
65 SysAssert(r == E_SUCCESS); // [ToDo] Exception. Which exception can occur?
67 _pControlImpl = pLabelImpl;
73 Label::Construct(const FloatRectangle& rect, const String& text)
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");
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");
82 _LabelImpl* pLabelImpl = _LabelImpl::GetInstance(*this);
84 SysAssertf(pLabelImpl == null,
85 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
87 pLabelImpl = _LabelImpl::CreateLabelImplN(this, rect);
89 SysTryReturn(NID_UI_CTRL, pLabelImpl, r, r, "[%s] Propagating.", GetErrorMessage(r));
91 r = pLabelImpl->SetText(text);
92 SysAssert(r == E_SUCCESS); // [ToDo] Exception. Which exception can occur?
94 _pControlImpl = pLabelImpl;
100 Label::SetText(const String& text)
102 _LabelImpl* pLabelImpl = _LabelImpl::GetInstance(*this);
103 SysAssertf(pLabelImpl != null,
104 "Not yet constructed. Construct() should be called before use.");
106 pLabelImpl->SetText(text);
112 Label::GetText(void) const
114 const _LabelImpl* pLabelImpl = _LabelImpl::GetInstance(*this);
115 SysAssertf(pLabelImpl != null,
116 "Not yet constructed. Construct() should be called before use.");
118 return pLabelImpl->GetText();
122 Label::SetBackgroundBitmap(const Bitmap& bitmap)
124 _LabelImpl* pLabelImpl = _LabelImpl::GetInstance(*this);
125 SysAssertf(pLabelImpl != null,
126 "Not yet constructed. Construct() should be called before use.");
128 pLabelImpl->SetBackgroundBitmap(bitmap);
134 Label::SetTextHorizontalAlignment(HorizontalAlignment alignment)
136 _LabelImpl* pLabelImpl = _LabelImpl::GetInstance(*this);
137 SysAssertf(pLabelImpl != null,
138 "Not yet constructed. Construct() should be called before use.");
140 pLabelImpl->SetTextHorizontalAlignment(alignment);
146 Label::SetTextVerticalAlignment(VerticalAlignment alignment)
148 _LabelImpl* pLabelImpl = _LabelImpl::GetInstance(*this);
149 SysAssertf(pLabelImpl != null,
150 "Not yet constructed. Construct() should be called before use.");
152 pLabelImpl->SetTextVerticalAlignment(alignment);
158 Label::GetTextHorizontalAlignment(void) const
160 const _LabelImpl* pLabelImpl = _LabelImpl::GetInstance(*this);
161 SysAssertf(pLabelImpl != null,
162 "Not yet constructed. Construct() should be called before use.");
164 return pLabelImpl->GetTextHorizontalAlignment();
168 Label::GetTextVerticalAlignment(void) const
170 const _LabelImpl* pLabelImpl = _LabelImpl::GetInstance(*this);
171 SysAssertf(pLabelImpl != null,
172 "Not yet constructed. Construct() should be called before use.");
174 return pLabelImpl->GetTextVerticalAlignment();
178 Label::SetBackgroundColor(const Color& color)
180 _LabelImpl* pLabelImpl = _LabelImpl::GetInstance(*this);
181 SysAssertf(pLabelImpl != null,
182 "Not yet constructed. Construct() should be called before use.");
184 pLabelImpl->SetBackgroundColor(color);
190 Label::GetBackgroundColor(void) const
192 const _LabelImpl* pLabelImpl = _LabelImpl::GetInstance(*this);
193 SysAssertf(pLabelImpl != null,
194 "Not yet constructed. Construct() should be called before use.");
196 return pLabelImpl->GetBackgroundColor();
200 Label::SetTextColor(const Color& color)
202 _LabelImpl* pLabelImpl = _LabelImpl::GetInstance(*this);
203 SysAssertf(pLabelImpl != null,
204 "Not yet constructed. Construct() should be called before use.");
206 pLabelImpl->SetTextColor(color);
212 Label::GetTextColor(void) const
214 const _LabelImpl* pLabelImpl = _LabelImpl::GetInstance(*this);
215 SysAssertf(pLabelImpl != null,
216 "Not yet constructed. Construct() should be called before use.");
218 return pLabelImpl->GetTextColor();
222 Label::SetTextConfig(int size, LabelTextStyle style)
224 _LabelImpl* pLabelImpl = _LabelImpl::GetInstance(*this);
225 SysAssertf(pLabelImpl != null,
226 "Not yet constructed. Construct() should be called before use.");
228 pLabelImpl->SetTextConfig(size, style);
234 Label::SetTextConfig(float size, LabelTextStyle style)
236 _LabelImpl* pLabelImpl = _LabelImpl::GetInstance(*this);
237 SysAssertf(pLabelImpl != null,
238 "Not yet constructed. Construct() should be called before use.");
240 pLabelImpl->SetTextConfig(size, style);
246 Label::GetTextSize(void) const
248 const _LabelImpl* pLabelImpl = _LabelImpl::GetInstance(*this);
249 SysAssertf(pLabelImpl != null,
250 "Not yet constructed. Construct() should be called before use.");
252 return pLabelImpl->GetTextSize();
256 Label::GetTextSizeF(void) const
258 const _LabelImpl* pLabelImpl = _LabelImpl::GetInstance(*this);
259 SysAssertf(pLabelImpl != null,
260 "Not yet constructed. Construct() should be called before use.");
262 return pLabelImpl->GetTextSizeF();
266 Label::GetTextStyle(void) const
268 const _LabelImpl* pLabelImpl = _LabelImpl::GetInstance(*this);
269 SysAssertf(pLabelImpl != null,
270 "Not yet constructed. Construct() should be called before use.");
272 return pLabelImpl->GetTextStyle();
276 Label::SetMargin(int topMargin, int leftMargin)
278 _LabelImpl* pLabelImpl = _LabelImpl::GetInstance(*this);
279 SysAssertf(pLabelImpl != null,
280 "Not yet constructed. Construct() should be called before use.");
282 result r = pLabelImpl->SetMargin(topMargin, leftMargin);
283 SysTryLog(NID_UI_CTRL, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
289 Label::SetMargin(float topMargin, float leftMargin)
291 _LabelImpl* pLabelImpl = _LabelImpl::GetInstance(*this);
292 SysAssertf(pLabelImpl != null,
293 "Not yet constructed. Construct() should be called before use.");
295 result r = pLabelImpl->SetMargin(topMargin, leftMargin);
296 SysTryLog(NID_UI_CTRL, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
302 Label::GetTopMargin(void) const
304 const _LabelImpl* pLabelImpl = _LabelImpl::GetInstance(*this);
305 SysAssertf(pLabelImpl != null,
306 "Not yet constructed. Construct() should be called before use.");
308 return pLabelImpl->GetTopMargin();
312 Label::GetTopMarginF(void) const
314 const _LabelImpl* pLabelImpl = _LabelImpl::GetInstance(*this);
315 SysAssertf(pLabelImpl != null,
316 "Not yet constructed. Construct() should be called before use.");
318 return pLabelImpl->GetTopMarginF();
322 Label::GetLeftMargin(void) const
324 const _LabelImpl* pLabelImpl = _LabelImpl::GetInstance(*this);
325 SysAssertf(pLabelImpl != null,
326 "Not yet constructed. Construct() should be called before use.");
328 return pLabelImpl->GetLeftMargin();
332 Label::GetLeftMarginF(void) const
334 const _LabelImpl* pLabelImpl = _LabelImpl::GetInstance(*this);
335 SysAssertf(pLabelImpl != null,
336 "Not yet constructed. Construct() should be called before use.");
338 return pLabelImpl->GetLeftMarginF();
341 }}} // Tizen::Ui::Controls