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_LabelPresenter.cpp
19 * @brief This is the implementation file for the _LabelPresenter class.
22 #include <FBaseErrorDefine.h>
23 #include <FGrpCanvas.h>
24 #include <FBaseSysLog.h>
25 #include <FGrp_CanvasImpl.h>
26 #include <FGrp_FontImpl.h>
27 #include <FGrp_BitmapImpl.h>
28 #include <FGrp_TextTextSimple.h>
29 #include <FAppApplication.h>
30 #include "FUi_ResourceManager.h"
31 #include "FUiAnim_VisualElement.h"
32 #include "FUiCtrl_LabelPresenter.h"
33 #include "FUiCtrl_LabelModel.h"
34 #include "FUiCtrl_Label.h"
36 using namespace Tizen::Base;
37 using namespace Tizen::Graphics;
38 using namespace Tizen::Ui::Animations;
39 using namespace Tizen::Graphics::_Text;
40 using namespace Tizen::App;
42 namespace Tizen { namespace Ui { namespace Controls
45 _LabelPresenter::_LabelPresenter(void)
48 , __previousEnabledState(false)
52 , __textStyle(LABEL_TEXT_STYLE_NORMAL)
59 _LabelPresenter::~_LabelPresenter(void)
75 _LabelPresenter::Construct(const _Label& label)
79 __pLabel = const_cast <_Label*>(&label);
81 __fontStyle = FONT_STYLE_PLAIN;
82 __fontSize = __pLabel->GetTextSize();
83 __pFont = __pLabel->GetFallbackFont();
85 SysTryReturn(NID_UI_CTRL, __pFont, r, r, "[%s] Propagating.", GetErrorMessage(r));
87 __pTextObject = new (std::nothrow) TextObject();
88 SysTryCatch(NID_UI_CTRL, __pTextObject != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
100 _LabelPresenter::Install(void)
102 result r = E_SUCCESS;
104 __pBase = __pLabel->GetVisualElement();
106 _LabelModel* pModel = new (std::nothrow) _LabelModel();
107 SysTryReturn(NID_UI_CTRL, pModel, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
109 r = SetModel(*pModel);
110 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
112 r = pModel->Construct();
113 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
123 _LabelPresenter::SetModel(const _LabelModel& labelModel)
125 __pLabelModel = const_cast <_LabelModel*>(&labelModel);
131 _LabelPresenter::InitTextObject(void)
133 TextSimple* pSimpleText = null;
135 pSimpleText = new (std::nothrow) TextSimple(const_cast<wchar_t*>(__pLabel->GetText().GetPointer()), __pLabel->GetText().GetLength(), TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
136 SysTryReturn(NID_UI_CTRL, pSimpleText, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
138 __pTextObject->Construct();
139 __pTextObject->AppendElement(*pSimpleText);
140 __pTextObject->SetWrap(TEXT_OBJECT_WRAP_TYPE_WORD);
141 __pTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
142 __pTextObject->SetFont(__pFont, 0, __pTextObject->GetTextLength());
143 __pTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_CENTER | TEXT_OBJECT_ALIGNMENT_MIDDLE);
144 __pTextObject->SetBounds(Rectangle(__pLabel->GetLeftMargin(), __pLabel->GetTopMargin(),
145 __pLabel->GetBounds().width - __pLabel->GetLeftMargin() * 2, __pLabel->GetBounds().height - __pLabel->GetTopMargin() * 2));
146 __pTextObject->Compose();
152 _LabelPresenter::OnFontChanged(Font* pFont)
160 _LabelPresenter::SetTextConfig(int size, LabelTextStyle style)
162 result r = E_SUCCESS;
164 unsigned long fontStyle = FONT_STYLE_PLAIN;
165 bool isStrikeOut = __pFont->IsStrikeOut();
166 bool isUnderLine = __pFont->IsUnderlined();
170 if (__textStyle == LABEL_TEXT_STYLE_ITALIC)
172 fontStyle |= FONT_STYLE_ITALIC;
175 if (__textStyle == LABEL_TEXT_STYLE_BOLD)
177 fontStyle |= FONT_STYLE_BOLD;
180 __fontStyle = fontStyle;
183 __pFont = __pLabel->GetFallbackFont();
185 SysTryReturn(NID_UI_CTRL, __pFont, r, r, "[%s] Propagating.", GetErrorMessage(r));
187 __pFont->SetStrikeOut(isStrikeOut);
188 __pFont->SetUnderline(isUnderLine);
194 _LabelPresenter::GetTextStyle(void) const
200 _LabelPresenter::SetFontInfo(unsigned long style, int size)
209 _LabelPresenter::OnFontInfoRequested(unsigned long& style, int& size)
218 _LabelPresenter::GetTextObject(void) const
220 return __pTextObject;
224 _LabelPresenter::Draw(void)
233 _LabelPresenter::DrawBackground(void)
235 Bitmap* pBitmap = __pLabel->GetBackgroundBitmap();
236 Bitmap* pEffectBitmap = __pLabel->GetBackgroundEffectBitmap();
238 Rectangle bounds(0, 0, __pLabel->GetBounds().width, __pLabel->GetBounds().height);
240 Color bgColor = __pLabel->GetBackgroundColor();
242 Canvas* pCanvas = null;
246 pCanvas = __pLabel->GetCanvasN();
249 SysLog(NID_UI_CTRL, "Cannot get a canvas.");
254 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
257 if (pBitmap->IsNinePatchedBitmap())
259 pCanvas->DrawNinePatchedBitmap(bounds, *pBitmap);
263 pCanvas->DrawBitmap(Rectangle(0, 0, bounds.width, bounds.height), *pBitmap);
266 if (pEffectBitmap != null)
268 if (pEffectBitmap->IsNinePatchedBitmap())
270 pCanvas->DrawNinePatchedBitmap(bounds, *pEffectBitmap);
274 pCanvas->DrawBitmap(Rectangle(0, 0, bounds.width, bounds.height), *pEffectBitmap);
280 if (__pLabel->GetText().IsEmpty() && __pLabel->IsCalledGetCanvasN() == false)
282 __pBase->SetBackgroundColor(_Colorf((float)bgColor.GetRed() / 255, (float)bgColor.GetGreen() / 255, (float)bgColor.GetBlue() / 255, (float)bgColor.GetAlpha() / 255));
286 pCanvas = __pLabel->GetCanvasN();
289 SysLog(NID_UI_CTRL, "Cannot get a canvas.");
294 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
296 pCanvas->FillRectangle(__pLabel->GetBackgroundColor(), bounds);
309 _LabelPresenter::DrawText(void)
311 if (__pLabel->GetText().IsEmpty())
313 SysLog(NID_UI_CTRL, "Text is empty.");
318 TextSimple* pSimpleText = null;
319 TextObjectAlignment horizontalAlign = TEXT_OBJECT_ALIGNMENT_CENTER;
320 TextObjectAlignment verticalAlign = TEXT_OBJECT_ALIGNMENT_MIDDLE;
322 int topMargin = __pLabel->GetTopMargin();
323 int leftMargin = __pLabel->GetLeftMargin();
324 Rectangle rect(leftMargin, topMargin, __pLabel->GetBounds().width - leftMargin * 2, __pLabel->GetBounds().height - topMargin * 2 );
325 if (rect.width <= 0 || rect.height <= 0)
327 SysLog(NID_UI_CTRL, "text display rectangle is wrong.");
332 Canvas* pCanvas = __pLabel->GetCanvasN();
335 SysLog(NID_UI_CTRL, "Cannot get a canvas.");
340 __pTextObject->RemoveAll();
341 pSimpleText = new (std::nothrow) TextSimple(const_cast<wchar_t*>(__pLabel->GetText().GetPointer()), __pLabel->GetText().GetLength(), TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
342 __pTextObject->AppendElement(*pSimpleText);
344 __pTextObject->SetForegroundColor(__pLabel->GetTextColor(), 0, __pTextObject->GetTextLength());
345 __pTextObject->SetBounds(rect);
346 __pTextObject->Compose();
348 switch (__pLabel->GetTextHorizontalAlignment())
351 horizontalAlign = TEXT_OBJECT_ALIGNMENT_LEFT;
353 case ALIGNMENT_CENTER:
354 horizontalAlign = TEXT_OBJECT_ALIGNMENT_CENTER;
357 horizontalAlign = TEXT_OBJECT_ALIGNMENT_RIGHT;
360 switch (__pLabel->GetTextVerticalAlignment())
363 verticalAlign = TEXT_OBJECT_ALIGNMENT_TOP;
365 case ALIGNMENT_MIDDLE:
366 verticalAlign = TEXT_OBJECT_ALIGNMENT_MIDDLE;
369 verticalAlign = TEXT_OBJECT_ALIGNMENT_BOTTOM;
372 __pTextObject->SetAlignment(horizontalAlign | verticalAlign);
373 __pTextObject->SetFont(__pFont, 0, __pTextObject->GetTextLength());
374 __pTextObject->SetBounds(rect);
375 __pTextObject->Draw(*_CanvasImpl::GetInstance(*pCanvas));
383 _LabelPresenter::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
389 _LabelPresenter::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
395 _LabelPresenter::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
401 _LabelPresenter::OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
407 _LabelPresenter::OnTouchMoveHandled(const _Control& control)
413 _LabelPresenter::IsEnabledStateChanged(void)
415 bool __currentEnabledState = __pLabel->GetEnableState();
417 if (__currentEnabledState != __previousEnabledState)
419 __previousEnabledState = __currentEnabledState;
428 }}} // Tizen::Ui::Controls