2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
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
9 // http://floralicense.org/license/
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 "FUi_ResourceSizeInfo.h"
25 #include "FUi_ResourceManager.h"
26 #include "FUi_UiBuilder.h"
27 #include "FUiCtrl_LabelImpl.h"
28 #include "FUiCtrl_Label.h"
30 using namespace Tizen::App;
31 using namespace Tizen::Base;
32 using namespace Tizen::Graphics;
34 namespace Tizen { namespace Ui { namespace Controls
38 _LabelImpl::LabelSizeInfo::GetDefaultMinimumSize(_ControlOrientation orientation) const
41 Dimension dimension(0, 0);
43 r = GET_DIMENSION_CONFIG(LABEL::MIN_SIZE, orientation, dimension);
44 SysTryReturn(NID_UI, r == E_SUCCESS, dimension, r, "[%s] A system error occurred.", GetErrorMessage(r));
52 _LabelImpl::GetInstance(Label& label)
54 return static_cast<_LabelImpl*> (label._pControlImpl);
58 _LabelImpl::GetInstance(const Label& label)
60 return static_cast<const _LabelImpl*> (label._pControlImpl);
63 _LabelImpl::_LabelImpl(Label* pPublic, _Label* pCore)
64 : _ControlImpl(pPublic, pCore)
67 SetFocusableChangable(false);
70 _LabelImpl::~_LabelImpl(void)
76 _LabelImpl::CreateLabelImplN(Label* pControl, const Rectangle& bounds)
79 r = GET_SIZE_INFO(Label).CheckInitialSizeValid(Dimension(bounds.width, bounds.height), _CONTROL_ORIENTATION_PORTRAIT);
80 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, E_INVALID_ARG, "[E_INVALID_ARG] The given size is not valid.");
82 _Label* pCore = _Label::CreateLabelN();
83 SysTryReturn(NID_UI_CTRL, pCore, null, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
85 _LabelImpl* pImpl = new (std::nothrow) _LabelImpl(pControl, pCore);
86 r = _ControlImpl::CheckConstruction(pCore, pImpl);
87 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
89 r = pImpl->InitializeBoundsProperties(GET_SIZE_INFO(Label), bounds, pCore->GetOrientation());
90 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
92 pImpl->SetBackgroundColor(Color(0, 0, 0, 0)); // for transparent
104 _LabelImpl::GetColorOnError(void)
106 return Color(0XFFFFFFFF);
110 _LabelImpl::GetPublicClassName(void) const
112 return "Tizen::Ui::Controls::Label";
116 _LabelImpl::GetPublic(void) const
118 return static_cast <const Label&>(_ControlImpl::GetPublic());
122 _LabelImpl::GetPublic(void)
124 return static_cast <Label&>(_ControlImpl::GetPublic());
128 _LabelImpl::GetCore(void) const
130 return static_cast <const _Label&>(_ControlImpl::GetCore());
134 _LabelImpl::GetCore(void)
136 return static_cast <_Label&>(_ControlImpl::GetCore());
140 _LabelImpl::OnBoundsChanged(const Rectangle& oldRect, const Rectangle& newRect)
145 Tizen::Graphics::Dimension
146 _LabelImpl::GetContentSize(void) const
148 return GetCore().GetContentSizeInternal();
152 _LabelImpl::SetText(const String& text)
155 result r = GetCore().SetPropertyText(var);
156 SysTryLog(NID_UI_CTRL, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
162 _LabelImpl::SetTextColor(const Color& color)
164 result r = GetCore().SetTextColor(color);
165 SysTryLog(NID_UI_CTRL, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
171 _LabelImpl::SetBackgroundBitmap(const Bitmap& bitmap)
173 result r = GetCore().SetBackgroundBitmap(bitmap);
174 SetLastResultReturn(r);
178 _LabelImpl::SetTextHorizontalAlignment(HorizontalAlignment alignment)
180 result r = GetCore().SetTextHorizontalAlignment(alignment);
181 SysTryLog(NID_UI_CTRL, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
187 _LabelImpl::SetTextVerticalAlignment(VerticalAlignment alignment)
189 result r = GetCore().SetTextVerticalAlignment(alignment);
190 SysTryLog(NID_UI_CTRL, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
196 _LabelImpl::SetTextConfig(int size, LabelTextStyle style)
198 result r = GetCore().SetTextConfig(size, style);
199 SysTryLog(NID_UI_CTRL, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
205 _LabelImpl::SetMargin(int topMargin, int leftMargin)
207 result r = GetCore().SetMargin(topMargin, leftMargin);
208 SetLastResultReturn(r);
212 _LabelImpl::GetText(void) const
216 return GetCore().GetPropertyText().ToString();
220 _LabelImpl::GetTextHorizontalAlignment(void) const
224 return GetCore().GetTextHorizontalAlignment();
228 _LabelImpl::GetTextVerticalAlignment(void) const
232 return GetCore().GetTextVerticalAlignment();
236 _LabelImpl::GetTextColor(void) const
240 return GetCore().GetTextColor();
244 _LabelImpl::GetTextSize(void) const
248 return GetCore().GetTextSize();
252 _LabelImpl::GetTextStyle(void) const
256 return GetCore().GetTextStyle();
260 _LabelImpl::GetTopMargin(void) const
264 return GetCore().GetTopMargin();
268 _LabelImpl::GetLeftMargin(void) const
272 return GetCore().GetLeftMargin();
276 : public _UiBuilderControlMaker
279 _LabelMaker(_UiBuilder* uibuilder)
280 : _UiBuilderControlMaker(uibuilder){};
281 virtual ~_LabelMaker(){};
282 static _UiBuilderControlMaker* GetInstance(_UiBuilder* uibuilder)
284 _LabelMaker* pLabelMaker = new (std::nothrow) _LabelMaker(uibuilder);
285 return static_cast<_UiBuilderControlMaker*>(pLabelMaker);
288 virtual Control* Make(_UiBuilderControl* pControl)
291 // bool bText = false;
292 // bool bSoftkeyCount = false;
294 _UiBuilderControlLayout* pControlProperty = null;
295 Label* pLabel = null;
298 AppResource* pAppResource = null;
299 UiApp* pUiApp = UiApp::GetInstance();
302 pAppResource = UiApp::GetInstance()->GetAppResource();
305 HorizontalAlignment horizontalAlignment;
306 VerticalAlignment verticalAlignment;
307 Tizen::Base::String elementString;
310 LabelTextStyle style = LABEL_TEXT_STYLE_NORMAL;
313 GetProperty(pControl, &pControlProperty);
314 if (pControlProperty == null)
319 pLabel = new (std::nothrow) Label();
320 rect = pControlProperty->GetRect();
323 if (pControl->GetElement(L"text", elementString))
325 r = pLabel->Construct(rect, elementString);
329 r = pLabel->Construct(rect, String(L""));
339 if (pControl->GetElement(L"horizontalAlign", elementString) || pControl->GetElement(L"hAlign", elementString))
341 if (ConvertHAlignToHorizontalAlignment(elementString, horizontalAlignment))
343 pLabel->SetTextHorizontalAlignment(horizontalAlignment);
347 if (pControl->GetElement(L"verticalAlign", elementString) || pControl->GetElement(L"vAlign", elementString))
349 if (ConvertVAlignToVerticalAlignment(elementString, verticalAlignment))
351 pLabel->SetTextVerticalAlignment(verticalAlignment);
355 if (pControl->GetElement(L"backgroundColorOpacity", elementString) || pControl->GetElement(L"BGColorOpacity", elementString))
357 Base::Integer::Parse(elementString, opacity);
360 if (pControl->GetElement(L"backgroundColor", elementString) || pControl->GetElement(L"BGColor", elementString))
362 ConvertStringToColor32(elementString, opacity, color);
363 pLabel->SetBackgroundColor(color);
367 color = pLabel->GetBackgroundColor();
368 color.SetAlpha(ConvertOpacity100to255(opacity));
369 pLabel->SetBackgroundColor(color);
372 if (pControl->GetElement(L"textColor", elementString))
374 ConvertStringToColor(elementString, color);
375 pLabel->SetTextColor(color);
378 if (pControl->GetElement(L"backgroundBitmapPath", elementString) || pControl->GetElement(L"BGBitmapPath", elementString))
380 Bitmap* pBackgroundBitmap = null;
381 pBackgroundBitmap = pAppResource->GetBitmapN(elementString);
382 if (pBackgroundBitmap != null)
384 pLabel->SetBackgroundBitmap(*pBackgroundBitmap);
385 delete pBackgroundBitmap;
389 if (pControl->GetElement(L"textSize", elementString))
391 Base::Integer::Parse(elementString, size);
392 _ICoordinateSystemTransformer* pTransform = GetTransformer();
395 size = pTransform->Transform(size);
400 if (pControl->GetElement(L"textStyle", elementString))
402 if (elementString.Equals(L"LABEL_TEXT_STYLE_NORMAL", false))
404 style = LABEL_TEXT_STYLE_NORMAL;
406 else if (elementString.Equals(L"LABEL_TEXT_STYLE_BOLD", false))
408 style = LABEL_TEXT_STYLE_BOLD;
410 else if (elementString.Equals(L"LABEL_TEXT_STYLE_ITALIC", false))
412 style = LABEL_TEXT_STYLE_ITALIC;
418 pLabel->SetTextConfig(size, style);
422 pLabel->SetTextConfig(pLabel->GetTextSize(), style);
425 //-------safety for Minimum size-------------------
426 rect = (pControl->GetAttribute(UIBUILDER_ATTRIBUTE_PORTRAIT))->GetRect();
427 if (rect.width < 0) // LABEL_MIN_WIDTH = 0
437 (pControl->GetAttribute(UIBUILDER_ATTRIBUTE_PORTRAIT))->SetRect(rect.x, rect.y, rect.width, rect.height);
439 rect = (pControl->GetAttribute(UIBUILDER_ATTRIBUTE_LANDSCAPE))->GetRect();
445 if (rect.height < 0) // LABEL_MIN_HEIGHT = 0
449 (pControl->GetAttribute(UIBUILDER_ATTRIBUTE_LANDSCAPE))->SetRect(rect.x, rect.y, rect.width, rect.height);
450 //---------end safety code------------------------
457 _LabelRegister::_LabelRegister()
459 _UiBuilderControlTableManager* pUiBuilderControlTableManager = _UiBuilderControlTableManager::GetInstance();
460 pUiBuilderControlTableManager->RegisterControl(L"Label", _LabelMaker::GetInstance);
462 _LabelRegister::~_LabelRegister()
464 _UiBuilderControlTableManager* pUiBuilderControlTableManager = _UiBuilderControlTableManager::GetInstance();
465 pUiBuilderControlTableManager->UnregisterControl(L"Label");
467 static _LabelRegister LabelRegisterToUiBuilder;
468 }}} // Tizen::Ui::Controls