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 FUiCtrl_LabelImpl.cpp
19 * @brief This is the implementation file for the _LabelImpl class.
22 #include <FAppApplication.h>
23 #include <FBaseSysLog.h>
24 #include <FBase_LocalizedNumParser.h>
25 #include <FUiAccessibilityContainer.h>
26 #include <FUiAccessibilityElement.h>
27 #include "FUi_ResourceSizeInfo.h"
28 #include "FUi_ResourceManager.h"
29 #include "FUi_UiBuilder.h"
30 #include "FUiCtrl_LabelImpl.h"
31 #include "FUiCtrl_Label.h"
32 #include "FUi_CoordinateSystemUtils.h"
35 using namespace Tizen::App;
36 using namespace Tizen::Base;
37 using namespace Tizen::Graphics;
39 namespace Tizen { namespace Ui { namespace Controls
43 _LabelImpl::LabelSizeInfo::GetDefaultMinimumSize(_ControlOrientation orientation) const
46 Dimension dimension(0, 0);
48 r = GET_DIMENSION_CONFIG(LABEL::MIN_SIZE, orientation, dimension);
49 SysTryReturn(NID_UI, r == E_SUCCESS, dimension, r, "[%s] A system error occurred.", GetErrorMessage(r));
57 _LabelImpl::LabelSizeInfo::GetDefaultMinimumSizeF(_ControlOrientation orientation) const
60 FloatDimension dimension(0.0f, 0.0f);
62 r = GET_DIMENSION_CONFIG(LABEL::MIN_SIZE, orientation, dimension);
63 SysTryReturn(NID_UI, r == E_SUCCESS, dimension, r, "[%s] A system error occurred.", GetErrorMessage(r));
71 _LabelImpl::GetInstance(Label& label)
73 return static_cast<_LabelImpl*> (label._pControlImpl);
77 _LabelImpl::GetInstance(const Label& label)
79 return static_cast<const _LabelImpl*> (label._pControlImpl);
82 _LabelImpl::_LabelImpl(Label* pPublic, _Label* pCore)
83 : _ControlImpl(pPublic, pCore)
86 SetFocusableChangable(false);
89 _LabelImpl::~_LabelImpl(void)
95 _LabelImpl::CreateLabelImplN(Label* pControl, const Rectangle& bounds)
98 r = GET_SIZE_INFO(Label).CheckInitialSizeValid(Dimension(bounds.width, bounds.height), _CONTROL_ORIENTATION_PORTRAIT);
99 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, E_INVALID_ARG, "[E_INVALID_ARG] The given size is not valid.");
101 _Label* pCore = _Label::CreateLabelN();
102 SysTryReturn(NID_UI_CTRL, pCore, null, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
104 _LabelImpl* pImpl = new (std::nothrow) _LabelImpl(pControl, pCore);
105 r = _ControlImpl::CheckConstruction(pCore, pImpl);
106 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
108 r = pImpl->InitializeBoundsProperties(GET_SIZE_INFO(Label), bounds, pCore->GetOrientation());
109 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
121 _LabelImpl::CreateLabelImplN(Label* pControl, const FloatRectangle& bounds)
123 result r = E_SUCCESS;
124 r = GET_SIZE_INFO(Label).CheckInitialSizeValidF(FloatDimension(bounds.width, bounds.height), _CONTROL_ORIENTATION_PORTRAIT);
125 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, E_INVALID_ARG, "[E_INVALID_ARG] The given size is not valid.");
127 _Label* pCore = _Label::CreateLabelN();
128 SysTryReturn(NID_UI_CTRL, pCore, null, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
130 _LabelImpl* pImpl = new (std::nothrow) _LabelImpl(pControl, pCore);
131 r = _ControlImpl::CheckConstruction(pCore, pImpl);
132 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
134 r = pImpl->InitializeBoundsPropertiesF(GET_SIZE_INFO(Label), bounds, pCore->GetOrientation());
135 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
137 pImpl->SetBackgroundColor(Color(0, 0, 0, 0)); // for transparent
149 _LabelImpl::GetColorOnError(void)
151 return Color(0XFFFFFFFF);
155 _LabelImpl::GetPublicClassName(void) const
157 return "Tizen::Ui::Controls::Label";
161 _LabelImpl::GetPublic(void) const
163 return static_cast <const Label&>(_ControlImpl::GetPublic());
167 _LabelImpl::GetPublic(void)
169 return static_cast <Label&>(_ControlImpl::GetPublic());
173 _LabelImpl::GetCore(void) const
175 return static_cast <const _Label&>(_ControlImpl::GetCore());
179 _LabelImpl::GetCore(void)
181 return static_cast <_Label&>(_ControlImpl::GetCore());
185 _LabelImpl::OnBoundsChanged(const Rectangle& oldRect, const Rectangle& newRect)
191 _LabelImpl::OnBoundsChanged(const FloatRectangle& oldRect, const FloatRectangle& newRect)
196 Tizen::Graphics::FloatDimension
197 _LabelImpl::GetContentSizeF(bool horizontalMode, bool verticalMode) const
199 return GetCore().GetContentSizeF(horizontalMode, verticalMode);
203 _LabelImpl::SetText(const String& text)
206 result r = GetCore().SetPropertyText(var);
207 SysTryLog(NID_UI_CTRL, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
213 _LabelImpl::SetTextColor(const Color& color)
215 result r = GetCore().SetTextColor(color);
216 SysTryLog(NID_UI_CTRL, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
222 _LabelImpl::SetBackgroundBitmap(const Bitmap& bitmap)
224 result r = GetCore().SetBackgroundBitmap(bitmap);
225 SetLastResultReturn(r);
229 _LabelImpl::SetTextHorizontalAlignment(HorizontalAlignment alignment)
231 result r = GetCore().SetTextHorizontalAlignment(alignment);
232 SysTryLog(NID_UI_CTRL, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
238 _LabelImpl::SetTextVerticalAlignment(VerticalAlignment alignment)
240 result r = GetCore().SetTextVerticalAlignment(alignment);
241 SysTryLog(NID_UI_CTRL, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
247 _LabelImpl::SetTextConfig(int size, LabelTextStyle style)
249 result r = GetCore().SetTextConfig(size, style);
250 SysTryLog(NID_UI_CTRL, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
256 _LabelImpl::SetTextConfig(float size, LabelTextStyle style)
258 result r = GetCore().SetTextConfig(size, style);
259 SysTryLog(NID_UI_CTRL, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
265 _LabelImpl::SetMargin(int topMargin, int leftMargin)
267 result r = GetCore().SetMargin(topMargin, leftMargin);
268 SetLastResultReturn(r);
272 _LabelImpl::SetMargin(float topMargin, float leftMargin)
274 result r = GetCore().SetMargin(topMargin, leftMargin);
275 SetLastResultReturn(r);
279 _LabelImpl::GetText(void) const
283 return GetCore().GetPropertyText().ToString();
287 _LabelImpl::GetTextHorizontalAlignment(void) const
291 return GetCore().GetTextHorizontalAlignment();
295 _LabelImpl::GetTextVerticalAlignment(void) const
299 return GetCore().GetTextVerticalAlignment();
303 _LabelImpl::GetTextColor(void) const
307 return GetCore().GetTextColor();
311 _LabelImpl::GetTextSize(void) const
315 return GetCore().GetTextSize();
319 _LabelImpl::GetTextSizeF(void) const
323 return GetCore().GetTextSizeF();
327 _LabelImpl::GetTextStyle(void) const
331 return GetCore().GetTextStyle();
335 _LabelImpl::GetTopMargin(void) const
339 return GetCore().GetTopMargin();
343 _LabelImpl::GetTopMarginF(void) const
347 return GetCore().GetTopMarginF();
351 _LabelImpl::GetLeftMargin(void) const
355 return GetCore().GetLeftMargin();
359 _LabelImpl::GetLeftMarginF(void) const
363 return GetCore().GetLeftMarginF();
367 : public _UiBuilderControlMaker
370 _LabelMaker(_UiBuilder* uibuilder)
371 : _UiBuilderControlMaker(uibuilder){};
372 virtual ~_LabelMaker(){};
373 static _UiBuilderControlMaker* GetInstance(_UiBuilder* uibuilder)
375 _LabelMaker* pLabelMaker = new (std::nothrow) _LabelMaker(uibuilder);
376 return static_cast<_UiBuilderControlMaker*>(pLabelMaker);
379 virtual Control* Make(_UiBuilderControl* pControl)
382 // bool bText = false;
383 // bool bSoftkeyCount = false;
385 _UiBuilderControlLayout* pControlProperty = null;
386 Label* pLabel = null;
389 HorizontalAlignment horizontalAlignment;
390 VerticalAlignment verticalAlignment;
391 Tizen::Base::String elementString;
394 float leftMargin = 0.0f;
395 float topMargin = 0.0f;
396 LabelTextStyle style = LABEL_TEXT_STYLE_NORMAL;
399 GetProperty(pControl, &pControlProperty);
400 if (pControlProperty == null)
405 pLabel = new (std::nothrow) Label();
406 rect = pControlProperty->GetRectF();
409 if (pControl->GetElement(L"text", elementString))
411 r = pLabel->Construct(rect, elementString);
415 r = pLabel->Construct(rect, String(L""));
425 if (pControl->GetElement(L"horizontalAlign", elementString) || pControl->GetElement(L"hAlign", elementString))
427 if (ConvertHAlignToHorizontalAlignment(elementString, horizontalAlignment))
429 pLabel->SetTextHorizontalAlignment(horizontalAlignment);
433 if (pControl->GetElement(L"verticalAlign", elementString) || pControl->GetElement(L"vAlign", elementString))
435 if (ConvertVAlignToVerticalAlignment(elementString, verticalAlignment))
437 pLabel->SetTextVerticalAlignment(verticalAlignment);
441 if (pControl->GetElement(L"backgroundColorOpacity", elementString) || pControl->GetElement(L"BGColorOpacity", elementString))
443 Base::Integer::Parse(elementString, opacity);
446 if (pControl->GetElement(L"backgroundColor", elementString) || pControl->GetElement(L"BGColor", elementString))
448 ConvertStringToColor32(elementString, opacity, color);
449 pLabel->SetBackgroundColor(color);
453 color = pLabel->GetBackgroundColor();
454 color.SetAlpha(ConvertOpacity100to255(opacity));
455 pLabel->SetBackgroundColor(color);
458 if (pControl->GetElement(L"textColor", elementString))
460 ConvertStringToColor(elementString, color);
461 pLabel->SetTextColor(color);
464 if (pControl->GetElement(L"backgroundBitmapPath", elementString) || pControl->GetElement(L"BGBitmapPath", elementString))
466 Bitmap* pBackgroundBitmap = null;
467 pBackgroundBitmap = LoadBitmapN(elementString);
469 if (pBackgroundBitmap != null)
471 pLabel->SetBackgroundBitmap(*pBackgroundBitmap);
472 delete pBackgroundBitmap;
476 if (pControl->GetElement(L"textSize", elementString))
478 size = _LocalizedNumParser::ToDouble(elementString, "C");
479 _ICoordinateSystemTransformer* pTransform = GetTransformer();
482 size = pTransform->Transform(size);
486 if (pControl->GetElement(L"textStyle", elementString))
488 if (elementString.Equals(L"LABEL_TEXT_STYLE_NORMAL", false))
490 style = LABEL_TEXT_STYLE_NORMAL;
492 else if (elementString.Equals(L"LABEL_TEXT_STYLE_BOLD", false))
494 style = LABEL_TEXT_STYLE_BOLD;
496 else if (elementString.Equals(L"LABEL_TEXT_STYLE_ITALIC", false))
498 style = LABEL_TEXT_STYLE_ITALIC;
504 pLabel->SetTextConfig(size, style);
508 pLabel->SetTextConfig(pLabel->GetTextSize(), style);
511 if (pControl->GetElement(L"LeftMargin", elementString))
513 Base::Float::Parse(elementString, leftMargin);
514 _ICoordinateSystemTransformer* pTransform = GetTransformer();
517 leftMargin = pTransform->Transform(leftMargin);
521 if (pControl->GetElement(L"TopMargin", elementString))
523 Base::Float::Parse(elementString, topMargin);
524 _ICoordinateSystemTransformer* pTransform = GetTransformer();
527 topMargin = pTransform->Transform(topMargin);
531 pLabel->SetMargin(topMargin, leftMargin);
533 //-------safety for Minimum size-------------------
534 rect = (pControl->GetAttribute(UIBUILDER_ATTRIBUTE_PORTRAIT))->GetRectF();
535 if (rect.width < 0.0f) // LABEL_MIN_WIDTH = 0
540 if (rect.height < 0.0f)
545 (pControl->GetAttribute(UIBUILDER_ATTRIBUTE_PORTRAIT))->SetRect(rect.x, rect.y, rect.width, rect.height);
547 rect = (pControl->GetAttribute(UIBUILDER_ATTRIBUTE_LANDSCAPE))->GetRectF();
548 if (rect.width < 0.0f)
553 if (rect.height < 0.0f) // LABEL_MIN_HEIGHT = 0
557 (pControl->GetAttribute(UIBUILDER_ATTRIBUTE_LANDSCAPE))->SetRect(rect.x, rect.y, rect.width, rect.height);
558 //---------end safety code------------------------
560 if (pControl->GetElement(L"accessibilityHint", elementString))
562 AccessibilityContainer* pContainer = pLabel->GetAccessibilityContainer();
565 AccessibilityElement* pElement = pContainer->GetElement(L"LabelText");
568 pElement->SetHint(elementString);
578 _LabelRegister::_LabelRegister()
580 _UiBuilderControlTableManager* pUiBuilderControlTableManager = _UiBuilderControlTableManager::GetInstance();
581 pUiBuilderControlTableManager->RegisterControl(L"Label", _LabelMaker::GetInstance);
583 _LabelRegister::~_LabelRegister()
585 _UiBuilderControlTableManager* pUiBuilderControlTableManager = _UiBuilderControlTableManager::GetInstance();
586 pUiBuilderControlTableManager->UnregisterControl(L"Label");
588 static _LabelRegister LabelRegisterToUiBuilder;
589 }}} // Tizen::Ui::Controls