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_Button.cpp
19 * @brief This is the implementation file for the _Button class.
22 #include <FBaseErrorDefine.h>
23 #include <FBaseSysLog.h>
24 #include <FGrp_BitmapImpl.h>
25 #include "FUi_AccessibilityContainer.h"
26 #include "FUi_AccessibilityElement.h"
27 #include "FUi_AccessibilityManager.h"
28 #include "FUi_CoordinateSystemUtils.h"
29 #include "FUi_ResourceManager.h"
30 #include "FUi_UiTouchEvent.h"
31 #include "FUiCtrl_Button.h"
32 #include "FUiCtrl_ButtonPresenter.h"
35 using namespace Tizen::Base;
36 using namespace Tizen::Base::Runtime;
37 using namespace Tizen::Graphics;
38 using namespace Tizen::Graphics::_Text;
40 namespace Tizen { namespace Ui { namespace Controls
43 IMPLEMENT_PROPERTY(_Button);
46 : __pButtonPresenter(null)
47 , __pActionEvent(null)
50 , __horizontalAlignment(ALIGNMENT_CENTER)
51 , __verticalAlignment(ALIGNMENT_MIDDLE)
52 , __buttonStatus(_BUTTON_STATUS_NORMAL)
53 , __buttonStyle(_BUTTON_STYLE_NORMAL)
55 , __multilineFontSize(0.0f)
57 , __isSettingMultilineFontSize(false)
58 , __previousTouchArea(false)
59 , __userDefinedText(false)
60 , __tabTextSlide(false)
64 , __bottomMargin(0.0f)
65 , __leftTouchMargin(0.0f)
66 , __topTouchMargin(0.0f)
67 , __rightTouchMargin(0.0f)
68 , __bottomTouchMargin(0.0f)
69 , __userDefinedTextArea(0.0f, 0.0f, 0.0f, 0.0f)
70 , __pTextElement(null)
74 _AccessibilityContainer* pContainer = null;
76 GET_SHAPE_CONFIG(BUTTON::DEFAULT_FONT_SIZE, _CONTROL_ORIENTATION_PORTRAIT, __textSize);
77 GET_SHAPE_CONFIG(BUTTON::MULTILINE_FONT_SIZE, _CONTROL_ORIENTATION_PORTRAIT, __multilineFontSize);
79 _ButtonPresenter* pPresenter = new (std::nothrow) _ButtonPresenter();
80 SysTryReturnVoidResult(NID_UI_CTRL, pPresenter, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
82 r = SetPresenter(*pPresenter);
83 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error occurred.");
85 r = pPresenter->Construct(*this);
86 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error occurred.");
88 r = pPresenter->Install();
89 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error occurred.");
91 for (int i = 0; i < NUMBER_OF_BUTTON_STATUS; i++)
94 __pEffectBitmap[i] = null;
95 __pToolbarItemBackgroundBitmap[i] = null;
96 __pBackgroundBitmap[i] = null;
97 __pBackgroundEffectBitmap[i] = null;
98 __isUserBackgroundBitmap[i] = false;
99 __isUserBackgroundEffectBitmap[i] = false;
102 __pUnderlineBitmap = null;
103 __pTabTextDimLeftBitmap = null;
104 __pTabTextDimRightBitmap = null;
105 __pSubTitleEffectBitmap = null;
107 GET_COLOR_CONFIG(BUTTON::BG_NORMAL, __color[_BUTTON_STATUS_NORMAL]);
108 GET_COLOR_CONFIG(BUTTON::BG_DISABLED, __color[_BUTTON_STATUS_DISABLED]);
109 GET_COLOR_CONFIG(BUTTON::BG_PRESSED, __color[_BUTTON_STATUS_PRESSED]);
110 GET_COLOR_CONFIG(BUTTON::BG_HIGHLIGHTED, __color[_BUTTON_STATUS_HIGHLIGHTED]);
111 GET_COLOR_CONFIG(BUTTON::BG_PRESSED, __color[_BUTTON_STATUS_SELECTED]);
113 GET_COLOR_CONFIG(BUTTON::TEXT_NORMAL, __textColor[_BUTTON_STATUS_NORMAL]);
114 GET_COLOR_CONFIG(BUTTON::TEXT_DISABLED, __textColor[_BUTTON_STATUS_DISABLED]);
115 GET_COLOR_CONFIG(BUTTON::TEXT_PRESSED, __textColor[_BUTTON_STATUS_PRESSED]);
116 GET_COLOR_CONFIG(BUTTON::TEXT_HIGHLIGHTED, __textColor[_BUTTON_STATUS_HIGHLIGHTED]);
117 GET_COLOR_CONFIG(BUTTON::TEXT_PRESSED, __textColor[_BUTTON_STATUS_SELECTED]);
119 GET_SHAPE_CONFIG(BUTTON::LEFT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, __leftMargin);
120 GET_SHAPE_CONFIG(BUTTON::TOP_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, __topMargin);
121 GET_SHAPE_CONFIG(BUTTON::RIGHT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, __rightMargin);
122 GET_SHAPE_CONFIG(BUTTON::BOTTOM_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, __bottomMargin);
124 AddPropertyChangeEventListener(*this);
126 pContainer = GetAccessibilityContainer();
130 pContainer->Activate(true);
131 InitializeAccessibilityElement();
143 _Button::CreateButtonN(void)
145 _Button* pButton = new (std::nothrow) _Button();
146 SysTryReturn(NID_UI_CTRL, pButton, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
147 SysTryCatch(NID_UI_CTRL, GetLastResult() == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error occurred.");
149 pButton->AcquireHandle();
151 pButton->SetTouchPressThreshold(SENSITIVE);
160 _Button::~_Button(void)
162 if (__pButtonPresenter)
164 delete __pButtonPresenter;
165 __pButtonPresenter = null;
170 delete __pActionEvent;
171 __pActionEvent = null;
174 for (int i = 0; i < NUMBER_OF_BUTTON_STATUS; i++)
182 if (__pEffectBitmap[i])
184 delete __pEffectBitmap[i];
185 __pEffectBitmap[i] = null;
188 if (__pToolbarItemBackgroundBitmap[i])
190 delete __pToolbarItemBackgroundBitmap[i];
191 __pToolbarItemBackgroundBitmap[i] = null;
194 if (__pBackgroundBitmap[i])
196 delete __pBackgroundBitmap[i];
197 __pBackgroundBitmap[i] = null;
200 if (__pBackgroundEffectBitmap[i])
202 delete __pBackgroundEffectBitmap[i];
203 __pBackgroundEffectBitmap[i] = null;
207 if (__pUnderlineBitmap)
209 delete __pUnderlineBitmap;
210 __pUnderlineBitmap = null;
213 if (__pTabTextDimLeftBitmap)
215 delete __pTabTextDimLeftBitmap;
216 __pTabTextDimLeftBitmap = null;
219 if (__pTabTextDimRightBitmap)
221 delete __pTabTextDimRightBitmap;
222 __pTabTextDimRightBitmap = null;
225 if (__pSubTitleEffectBitmap)
227 delete __pSubTitleEffectBitmap;
228 __pSubTitleEffectBitmap = null;
233 __pTextElement->Activate(false);
234 __pTextElement = null;
241 _Button::SetPresenter(const _ButtonPresenter& buttonPresenter)
243 __pButtonPresenter = const_cast<_ButtonPresenter*>(&buttonPresenter);
249 _Button::OnDraw(void)
251 __pButtonPresenter->Draw();
257 _Button::OnAttachedToMainTree(void)
261 __pTextElement->SetBounds(FloatRectangle(0.0f, 0.0f, GetBoundsF().width, GetBoundsF().height));
267 _Button::InitializeAccessibilityElement(void)
274 _AccessibilityContainer* pContainer = GetAccessibilityContainer();
278 __pTextElement = new (std::nothrow) _AccessibilityElement(true);
279 SysTryReturnVoidResult(NID_UI_CTRL, __pTextElement, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
281 __pTextElement->SetBounds(FloatRectangle(0.0f, 0.0f, GetBoundsF().width, GetBoundsF().height));
282 __pTextElement->SetLabel(GetText());
283 __pTextElement->SetTraitWithStringId("IDS_TPLATFORM_BODY_BUTTON_T_TTS");
284 __pTextElement->SetName(L"ButtonText");
286 pContainer->AddElement(*__pTextElement);
293 _Button::OnPropertyChanging(_PropertyBase& source, const String& name, const Variant& oldValue, const Variant& newValue)
299 _Button::OnPropertyChanged(_PropertyBase& source, const String& name, const Variant& oldValue, const Variant& newValue)
305 _Button::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
307 return __pButtonPresenter->OnTouchPressed(source, touchinfo);
311 _Button::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
313 return __pButtonPresenter->OnTouchReleased(source, touchinfo);
317 _Button::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
319 return __pButtonPresenter->OnTouchMoved(source, touchinfo);
323 _Button::OnTouchCanceled(const _Control & source, const _TouchInfo & touchinfo)
325 return __pButtonPresenter->OnTouchCanceled(source, touchinfo);
329 _Button::OnTouchMoveHandled(const _Control& control)
331 __pButtonPresenter->OnTouchMoveHandled(control);
337 _Button::OnKeyPressed(const _Control& source, const _KeyInfo& keyInfo)
339 return __pButtonPresenter->OnKeyPressed(source, keyInfo);
343 _Button::OnKeyReleased(const _Control& source, const _KeyInfo& keyInfo)
345 return __pButtonPresenter->OnKeyReleased(source, keyInfo);
349 _Button::OnBoundsChanged(void)
353 __pTextElement->SetBounds(FloatRectangle(0.0f, 0.0f, GetBoundsF().width, GetBoundsF().height));
360 _Button::OnFontChanged(Font* pFont)
362 __pButtonPresenter->OnFontChanged(pFont);
364 _Control::OnFontChanged(pFont);
370 _Button::OnFontInfoRequested(unsigned long& style, int& size)
372 __pButtonPresenter->OnFontInfoRequested(style, size);
378 _Button::OnFontInfoRequested(unsigned long& style, float& size)
380 __pButtonPresenter->OnFontInfoRequested(style, size);
386 _Button::OnAncestorEnableStateChanged(const _Control& control)
388 __pButtonPresenter->OnAncestorEnableStateChanged(control);
394 _Button::OnDrawFocus(void)
396 __pButtonPresenter->OnDrawFocus();
402 _Button::OnChildControlFocusMoved(const _Control& control)
404 __pButtonPresenter->OnChildControlFocusMoved(control);
410 _Button::IsChildControlFocusManage(void) const
412 __pButtonPresenter->IsChildControlFocusManage();
418 _Button::OnFocusableStateChanged(bool focusalbeState)
420 __pButtonPresenter->OnFocusableStateChanged(focusalbeState);
426 _Button::OnFocusModeStateChanged(void)
428 __pButtonPresenter->OnFocusModeStateChanged();
434 _Button::OnFocusGained(const _Control& source)
436 __pButtonPresenter->OnFocusGained(source);
442 _Button::OnFocusLost(const _Control& source)
444 __pButtonPresenter->OnFocusLost(source);
450 _Button::OnCanvasRequestedN(const FloatRectangle& bounds)
452 return __pButtonPresenter->OnCanvasRequestedN(bounds);
456 _Button::SetText(const String& text)
458 return SetProperty(L"text", Variant(text));
462 _Button::SetPropertyText(const Variant& text)
464 __text = text.ToString();
468 __pTextElement->SetLabel(__text);
471 result r = __pButtonPresenter->InitTextObject();
472 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
478 _Button::GetText(void) const
480 Variant text = GetProperty(L"text");
482 return text.ToString();
486 _Button::GetPropertyText(void) const
488 return Variant(__text);
492 _Button::SetColor(_ButtonStatus status, const Color& color)
494 result r = E_SUCCESS;
498 case _BUTTON_STATUS_NORMAL:
499 r = SetProperty(L"normalColor", Variant(color));
501 case _BUTTON_STATUS_DISABLED:
502 r = SetProperty(L"disabledColor", Variant(color));
504 case _BUTTON_STATUS_PRESSED:
505 r = SetProperty(L"pressedColor", Variant(color));
507 case _BUTTON_STATUS_HIGHLIGHTED:
508 r = SetProperty(L"highlightedColor", Variant(color));
511 r = SetProperty(L"selectedColor", Variant(color));
518 _Button::SetPropertyNormalColor(const Variant& color)
520 __color[_BUTTON_STATUS_NORMAL] = color.ToColor();
526 _Button::SetPropertyDisabledColor(const Variant& color)
528 __color[_BUTTON_STATUS_DISABLED] = color.ToColor();
534 _Button::SetPropertyPressedColor(const Variant& color)
536 __color[_BUTTON_STATUS_PRESSED] = color.ToColor();
542 _Button::SetPropertyHighlightedColor(const Variant& color)
544 __color[_BUTTON_STATUS_HIGHLIGHTED] = color.ToColor();
550 _Button::SetPropertySelectedColor(const Variant& color)
552 __color[_BUTTON_STATUS_SELECTED] = color.ToColor();
558 _Button::GetColor(_ButtonStatus status) const
564 case _BUTTON_STATUS_NORMAL:
565 color = GetProperty(L"normalColor");
567 case _BUTTON_STATUS_DISABLED:
568 color = GetProperty(L"disabledColor");
570 case _BUTTON_STATUS_PRESSED:
571 color = GetProperty(L"pressedColor");
573 case _BUTTON_STATUS_HIGHLIGHTED:
574 color = GetProperty(L"highlightedColor");
577 color = GetProperty(L"selectedColor");
580 return color.ToColor();
584 _Button::GetPropertyNormalColor(void) const
586 return Variant(__color[_BUTTON_STATUS_NORMAL]);
590 _Button::GetPropertyDisabledColor(void) const
592 return Variant(__color[_BUTTON_STATUS_DISABLED]);
596 _Button::GetPropertyPressedColor(void) const
598 return Variant(__color[_BUTTON_STATUS_PRESSED]);
602 _Button::GetPropertyHighlightedColor(void) const
604 return Variant(__color[_BUTTON_STATUS_HIGHLIGHTED]);
608 _Button::GetPropertySelectedColor(void) const
610 return Variant(__color[_BUTTON_STATUS_SELECTED]);
614 _Button::AddActionEventListener(const _IActionEventListener& listener)
616 if (__pActionEvent == null)
618 __pActionEvent = _ActionEvent::CreateInstanceN(*this);
619 SysTryReturn(NID_UI_CTRL, __pActionEvent, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
622 result r = __pActionEvent->AddListener(listener);
623 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
629 _Button::RemoveActionEventListener(const _IActionEventListener& listener)
631 result r = E_OBJ_NOT_FOUND;
635 r = __pActionEvent->RemoveListener(listener);
638 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
644 _Button::SetActionId(int actionId)
646 return SetProperty(L"actionId", Variant(actionId));
650 _Button::SetPropertyActionId(const Variant& actionId)
652 __actionId = actionId.ToInt();
658 _Button::GetActionId(void) const
660 Variant actionId = GetProperty(L"actionId");
662 return actionId.ToInt();
666 _Button::GetPropertyActionId(void) const
668 return Variant(__actionId);
672 _Button::SetTextHorizontalAlignment(HorizontalAlignment alignment)
674 __horizontalAlignment = alignment;
680 _Button::GetTextHorizontalAlignment(void) const
682 return __horizontalAlignment;
686 _Button::SetTextVerticalAlignment(VerticalAlignment alignment)
688 __verticalAlignment = alignment;
694 _Button::GetTextVerticalAlignment(void) const
696 return __verticalAlignment;
700 _Button::SetTextColor(_ButtonStatus status, const Color& color)
702 result r = E_SUCCESS;
706 case _BUTTON_STATUS_NORMAL:
707 r = SetProperty(L"normalTextColor", Variant(color));
709 case _BUTTON_STATUS_DISABLED:
710 r = SetProperty(L"disabledTextColor", Variant(color));
712 case _BUTTON_STATUS_PRESSED:
713 r = SetProperty(L"pressedTextColor", Variant(color));
715 case _BUTTON_STATUS_HIGHLIGHTED:
716 r = SetProperty(L"highlightedTextColor", Variant(color));
719 r = SetProperty(L"selectedTextColor", Variant(color));
726 _Button::SetPropertyNormalTextColor(const Variant& color)
728 __textColor[_BUTTON_STATUS_NORMAL] = color.ToColor();
734 _Button::SetPropertyDisabledTextColor(const Variant& color)
736 __textColor[_BUTTON_STATUS_DISABLED] = color.ToColor();
742 _Button::SetPropertyPressedTextColor(const Variant& color)
744 __textColor[_BUTTON_STATUS_PRESSED] = color.ToColor();
750 _Button::SetPropertyHighlightedTextColor(const Variant& color)
752 __textColor[_BUTTON_STATUS_HIGHLIGHTED] = color.ToColor();
758 _Button::SetPropertySelectedTextColor(const Variant& color)
760 __textColor[_BUTTON_STATUS_SELECTED] = color.ToColor();
766 _Button::GetTextColor(_ButtonStatus status) const
772 case _BUTTON_STATUS_NORMAL:
773 color = GetProperty(L"normalTextColor");
775 case _BUTTON_STATUS_DISABLED:
776 color = GetProperty(L"disabledTextColor");
778 case _BUTTON_STATUS_PRESSED:
779 color = GetProperty(L"pressedTextColor");
781 case _BUTTON_STATUS_HIGHLIGHTED:
782 color = GetProperty(L"highlightedTextColor");
785 color = GetProperty(L"selectedTextColor");
788 return color.ToColor();
792 _Button::GetPropertyNormalTextColor(void) const
794 return Variant(__textColor[_BUTTON_STATUS_NORMAL]);
798 _Button::GetPropertyDisabledTextColor(void) const
800 return Variant(__textColor[_BUTTON_STATUS_DISABLED]);
804 _Button::GetPropertyPressedTextColor(void) const
806 return Variant(__textColor[_BUTTON_STATUS_PRESSED]);
810 _Button::GetPropertyHighlightedTextColor(void) const
812 return Variant(__textColor[_BUTTON_STATUS_HIGHLIGHTED]);
816 _Button::GetPropertySelectedTextColor(void) const
818 return Variant(__textColor[_BUTTON_STATUS_SELECTED]);
822 _Button::SetBitmap(_ButtonStatus status, const Point& position, const Bitmap& bitmap)
824 FloatPoint floatPosition = _CoordinateSystemUtils::ConvertToFloat(position);
826 return SetBitmap(status, floatPosition, bitmap);
830 _Button::SetBitmap(_ButtonStatus status, const FloatPoint& position, const Bitmap& bitmap)
834 Bitmap* pClonedBitmap = _BitmapImpl::CloneN(bitmap);
838 __bitmapPosition[status] = position;
840 if (__pBitmap[status] != null)
842 delete __pBitmap[status];
845 __pBitmap[status] = pClonedBitmap;
854 _Button::GetBitmap(_ButtonStatus status) const
856 return __pBitmap[status];
860 _Button::GetBitmapPosition(_ButtonStatus status) const
862 return _CoordinateSystemUtils::ConvertToInteger(GetBitmapPositionF(status));
866 _Button::GetBitmapPositionF(_ButtonStatus status) const
868 return FloatPoint(__bitmapPosition[status].x + __leftTouchMargin, __bitmapPosition[status].y + __topTouchMargin);
872 _Button::SetEffectBitmap(_ButtonStatus status, const Point& position, const Bitmap& bitmap)
874 FloatPoint floatPosition = _CoordinateSystemUtils::ConvertToFloat(position);
876 return SetEffectBitmap(status, floatPosition, bitmap);
880 _Button::SetEffectBitmap(_ButtonStatus status, const FloatPoint& position, const Bitmap& bitmap)
884 Bitmap* pClonedBitmap = _BitmapImpl::CloneN(bitmap);
888 __effectBitmapPosition[status] = position;
890 if (__pEffectBitmap[status] != null)
892 delete __pEffectBitmap[status];
895 __pEffectBitmap[status] = pClonedBitmap;
904 _Button::GetEffectBitmap(_ButtonStatus status) const
906 return __pEffectBitmap[status];
910 _Button::GetEffectBitmapPosition(_ButtonStatus status) const
912 return _CoordinateSystemUtils::ConvertToInteger(GetEffectBitmapPositionF(status));
916 _Button::GetEffectBitmapPositionF(_ButtonStatus status) const
918 return FloatPoint(__effectBitmapPosition[status].x + __leftTouchMargin, __effectBitmapPosition[status].y + __topTouchMargin);
922 _Button::SetToolbarItemBackgroundBitmap(_ButtonStatus status, const Bitmap& bitmap)
926 Bitmap* pClonedBitmap = _BitmapImpl::CloneN(bitmap);
930 if (__pToolbarItemBackgroundBitmap[status] != null)
932 delete __pToolbarItemBackgroundBitmap[status];
935 __pToolbarItemBackgroundBitmap[status] = pClonedBitmap;
944 _Button::GetToolbarItemBackgroundBitmap(_ButtonStatus status) const
946 return __pToolbarItemBackgroundBitmap[status];
950 _Button::SetUnderlineBitmap(const Bitmap& bitmap)
954 Bitmap* pClonedBitmap = _BitmapImpl::CloneN(bitmap);
958 if (__pUnderlineBitmap != null)
960 delete __pUnderlineBitmap;
963 __pUnderlineBitmap = pClonedBitmap;
972 _Button::ShowUnderlineBitmap(bool show)
974 return __pButtonPresenter->ShowUnderlineBitmap(show);
978 _Button::GetUnderlineBitmap(void) const
980 return __pUnderlineBitmap;
984 _Button::SetTabTextDimLeftBitmap(const Bitmap& bitmap)
988 Bitmap* pClonedBitmap = _BitmapImpl::CloneN(bitmap);
992 if (__pTabTextDimLeftBitmap != null)
994 delete __pTabTextDimLeftBitmap;
997 __pTabTextDimLeftBitmap = pClonedBitmap;
1006 _Button::GetTabTextDimLeftBitmap(void) const
1008 return __pTabTextDimLeftBitmap;
1012 _Button::SetTabTextDimRightBitmap(const Bitmap& bitmap)
1014 result r = E_SYSTEM;
1016 Bitmap* pClonedBitmap = _BitmapImpl::CloneN(bitmap);
1020 if (__pTabTextDimRightBitmap != null)
1022 delete __pTabTextDimRightBitmap;
1025 __pTabTextDimRightBitmap = pClonedBitmap;
1034 _Button::GetTabTextDimRightBitmap(void) const
1036 return __pTabTextDimRightBitmap;
1040 _Button::SetSubTitleEffectBitmap(const Bitmap& bitmap)
1042 result r = E_SYSTEM;
1044 Bitmap* pClonedBitmap = _BitmapImpl::CloneN(bitmap);
1048 if (__pSubTitleEffectBitmap != null)
1050 delete __pSubTitleEffectBitmap;
1053 __pSubTitleEffectBitmap = pClonedBitmap;
1062 _Button::GetSubTitleEffectBitmap(void) const
1064 return __pSubTitleEffectBitmap;
1068 _Button::SetBackgroundBitmap(_ButtonStatus status, const Bitmap& bitmap)
1070 result r = E_SYSTEM;
1072 Bitmap* pClonedBitmap = _BitmapImpl::CloneN(bitmap);
1076 if (__pBackgroundBitmap[status] != null)
1078 delete __pBackgroundBitmap[status];
1081 __pBackgroundBitmap[status] = pClonedBitmap;
1082 __isUserBackgroundBitmap[status] = true;
1091 _Button::GetBackgroundBitmap(_ButtonStatus status) const
1093 result r = E_SYSTEM;
1095 _Button* pButton = const_cast<_Button*>(this);
1097 if (!pButton->__pBackgroundBitmap[status])
1101 case _BUTTON_STATUS_NORMAL:
1102 r = GET_BITMAP_CONFIG_N(BUTTON::BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, pButton->__pBackgroundBitmap[_BUTTON_STATUS_NORMAL]);
1104 case _BUTTON_STATUS_DISABLED:
1105 r = GET_BITMAP_CONFIG_N(BUTTON::BG_DISABLED, BITMAP_PIXEL_FORMAT_ARGB8888, pButton->__pBackgroundBitmap[_BUTTON_STATUS_DISABLED]);
1107 case _BUTTON_STATUS_PRESSED:
1108 r = GET_BITMAP_CONFIG_N(BUTTON::BG_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, pButton->__pBackgroundBitmap[_BUTTON_STATUS_PRESSED]);
1110 case _BUTTON_STATUS_HIGHLIGHTED:
1111 r = GET_BITMAP_CONFIG_N(BUTTON::BG_HIGHLIGHTED, BITMAP_PIXEL_FORMAT_ARGB8888, pButton->__pBackgroundBitmap[_BUTTON_STATUS_HIGHLIGHTED]);
1114 r = GET_BITMAP_CONFIG_N(BUTTON::BG_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, pButton->__pBackgroundBitmap[_BUTTON_STATUS_SELECTED]);
1117 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
1120 return pButton->__pBackgroundBitmap[status];
1124 _Button::SetBackgroundEffectBitmap(_ButtonStatus status, const Bitmap& bitmap)
1126 result r = E_SYSTEM;
1128 Bitmap* pClonedBitmap = _BitmapImpl::CloneN(bitmap);
1132 if (__pBackgroundEffectBitmap[status] != null)
1134 delete __pBackgroundEffectBitmap[status];
1137 __pBackgroundEffectBitmap[status] = pClonedBitmap;
1138 __isUserBackgroundEffectBitmap[status] = true;
1147 _Button::GetBackgroundEffectBitmap(_ButtonStatus status) const
1149 result r = E_SYSTEM;
1150 bool themeBackgroundBitmap = false;
1152 _Button* pButton = const_cast<_Button*>(this);
1154 if (!pButton->__pBackgroundEffectBitmap[status])
1158 case _BUTTON_STATUS_NORMAL:
1159 themeBackgroundBitmap = IS_CUSTOM_BITMAP(BUTTON::BG_NORMAL);
1160 if (!themeBackgroundBitmap)
1162 r = GET_BITMAP_CONFIG_N(BUTTON::BG_EFFECT_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, pButton->__pBackgroundEffectBitmap[_BUTTON_STATUS_NORMAL]);
1165 case _BUTTON_STATUS_DISABLED:
1166 themeBackgroundBitmap = IS_CUSTOM_BITMAP(BUTTON::BG_DISABLED);
1167 if (!themeBackgroundBitmap)
1169 r = GET_BITMAP_CONFIG_N(BUTTON::BG_EFFECT_DISABLED, BITMAP_PIXEL_FORMAT_ARGB8888, pButton->__pBackgroundEffectBitmap[_BUTTON_STATUS_DISABLED]);
1172 case _BUTTON_STATUS_PRESSED:
1173 themeBackgroundBitmap = IS_CUSTOM_BITMAP(BUTTON::BG_PRESSED);
1174 if (!themeBackgroundBitmap)
1176 r = GET_BITMAP_CONFIG_N(BUTTON::BG_EFFECT_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, pButton->__pBackgroundEffectBitmap[_BUTTON_STATUS_PRESSED]);
1179 case _BUTTON_STATUS_HIGHLIGHTED:
1180 themeBackgroundBitmap = IS_CUSTOM_BITMAP(BUTTON::BG_HIGHLIGHTED);
1181 if (!themeBackgroundBitmap)
1183 r = GET_BITMAP_CONFIG_N(BUTTON::BG_EFFECT_HIGHLIGHTED, BITMAP_PIXEL_FORMAT_ARGB8888, pButton->__pBackgroundEffectBitmap[_BUTTON_STATUS_HIGHLIGHTED]);
1187 themeBackgroundBitmap = IS_CUSTOM_BITMAP(BUTTON::BG_PRESSED);
1188 if (!themeBackgroundBitmap)
1190 r = GET_BITMAP_CONFIG_N(BUTTON::BG_EFFECT_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, pButton->__pBackgroundEffectBitmap[_BUTTON_STATUS_SELECTED]);
1194 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
1197 return pButton->__pBackgroundEffectBitmap[status];
1201 _Button::SetTextSize(int size, unsigned long fontStyle)
1203 float floatSize = _CoordinateSystemUtils::ConvertToFloat(size);
1205 __pButtonPresenter->SetTextSize(floatSize, fontStyle);
1207 return SetProperty(L"textSize", Variant(floatSize));
1211 _Button::SetTextSize(float size, unsigned long fontStyle)
1213 __pButtonPresenter->SetTextSize(size, fontStyle);
1215 return SetProperty(L"textSize", Variant(size));
1219 _Button::SetPropertyTextSize(const Variant& textSize)
1221 result r = E_SUCCESS;
1223 if (textSize.ToFloat() > 0.0f)
1225 __textSize = textSize.ToFloat();
1226 __multilineFontSize = textSize.ToFloat();
1231 SysLogException(NID_UI_CTRL, r, "[E_INVALID_ARG] Text size is no greater than 0.");
1238 _Button::GetTextSize(void) const
1240 return _CoordinateSystemUtils::ConvertToInteger(GetTextSizeF());
1244 _Button::GetTextSizeF(void) const
1246 Variant size = GetProperty(L"textSize");
1248 return size.ToFloat();
1252 _Button::GetPropertyTextSize(void) const
1254 return Variant(__textSize);
1258 _Button::SetButtonStyle(_ButtonStyle buttonStyle)
1260 __buttonStyle = buttonStyle;
1266 _Button::GetButtonStyle(void) const
1268 return __buttonStyle;
1272 _Button::SetButtonStatus(_ButtonStatus buttonStatus, bool fire)
1274 result r = E_SUCCESS;
1276 __buttonStatus = buttonStatus;
1278 if (_BUTTON_STATUS_DISABLED == __buttonStatus)
1280 SetEnableState(false);
1284 SetEnableState(true);
1287 if ((_BUTTON_STATUS_SELECTED == __buttonStatus || _BUTTON_STATUS_HIGHLIGHTED == __buttonStatus) && fire)
1289 r = FireActionEvent();
1290 SysTryLog(NID_UI_CTRL, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
1297 _Button::GetButtonStatus(void) const
1299 return __buttonStatus;
1303 _Button::SetTextMaxLine(int textMaxLine)
1305 __textMaxLine = textMaxLine;
1311 _Button::GetTextMaxLine(void) const
1313 return __textMaxLine;
1317 _Button::UnloadBackgroundBitmap(_ButtonStatus status)
1319 if (__pBackgroundBitmap[status] != null)
1321 delete __pBackgroundBitmap[status];
1322 __pBackgroundBitmap[status] = null;
1328 _Button::UnloadBackgroundEffectBitmap(_ButtonStatus status)
1330 if (__pBackgroundEffectBitmap[status] != null)
1332 delete __pBackgroundEffectBitmap[status];
1333 __pBackgroundEffectBitmap[status] = null;
1339 _Button::IsUserBackgroundBitmap(_ButtonStatus status) const
1341 return __isUserBackgroundBitmap[status];
1345 _Button::IsUserBackgroundEffectBitmap(_ButtonStatus status) const
1347 return __isUserBackgroundEffectBitmap[status];
1351 _Button::IsTouchAreaChanged(bool currentButtonArea)
1353 if (__previousTouchArea != currentButtonArea)
1355 __previousTouchArea = currentButtonArea;
1366 _Button::FireActionEvent(void)
1368 result r = E_SUCCESS;
1372 IEventArg* pEventArg = _ActionEvent::CreateActionEventArgN(__actionId);
1373 SysTryReturn(NID_UI_CTRL, pEventArg, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
1375 __pActionEvent->Fire(*pEventArg);
1382 _Button::SetUserDefinedTextArea(const Rectangle& bounds)
1384 FloatRectangle floatBounds = _CoordinateSystemUtils::ConvertToFloat(bounds);
1386 return SetUserDefinedTextArea(floatBounds);
1390 _Button::SetUserDefinedTextArea(const FloatRectangle& bounds)
1392 __userDefinedText = true;
1394 __userDefinedTextArea = bounds;
1400 _Button::GetUserDefinedTextArea(void) const
1402 return _CoordinateSystemUtils::ConvertToInteger(GetUserDefinedTextAreaF());
1406 _Button::GetUserDefinedTextAreaF(void) const
1408 return __userDefinedTextArea;
1412 _Button::UserDefinedText(void) const
1414 return __userDefinedText;
1418 _Button::SetTabTextSlide(bool tabTextSlide)
1420 __tabTextSlide = tabTextSlide;
1426 _Button::IsTabTextSlide(void) const
1428 return __tabTextSlide;
1432 _Button::SetMargin(int leftMargin, int topMargin, int rightMargin, int bottomMargin)
1434 float floatLeftMargin = _CoordinateSystemUtils::ConvertToFloat(leftMargin);
1435 float floatTopMargin = _CoordinateSystemUtils::ConvertToFloat(topMargin);
1436 float floatRightMargin = _CoordinateSystemUtils::ConvertToFloat(rightMargin);
1437 float floatBottomMargin = _CoordinateSystemUtils::ConvertToFloat(bottomMargin);
1439 return SetMargin(floatLeftMargin, floatTopMargin, floatRightMargin, floatBottomMargin);
1443 _Button::SetMargin(float leftMargin, float topMargin, float rightMargin, float bottomMargin)
1445 __leftMargin = leftMargin;
1446 __topMargin = topMargin;
1447 __rightMargin = rightMargin;
1448 __bottomMargin = bottomMargin;
1454 _Button::GetLeftMargin(void) const
1456 return _CoordinateSystemUtils::ConvertToInteger(GetLeftMarginF());
1460 _Button::GetLeftMarginF(void) const
1462 return __leftMargin;
1466 _Button::GetTopMargin(void) const
1468 return _CoordinateSystemUtils::ConvertToInteger(GetTopMarginF());
1472 _Button::GetTopMarginF(void) const
1477 _Button::GetRightMargin(void) const
1479 return _CoordinateSystemUtils::ConvertToInteger(GetRightMarginF());
1483 _Button::GetRightMarginF(void) const
1485 return __rightMargin;
1489 _Button::GetBottomMargin(void) const
1491 return _CoordinateSystemUtils::ConvertToInteger(GetBottomMarginF());
1495 _Button::GetBottomMarginF(void) const
1497 return __bottomMargin;
1501 _Button::GetContentSizeF(bool horizontalMode, bool verticalMode) const
1503 return GetContentSizeInternalF(horizontalMode, verticalMode);
1507 _Button::GetContentSizeInternalF(bool horizontalMode, bool verticalMode) const
1509 for (int i = 0; i < NUMBER_OF_BUTTON_STATUS; i++)
1511 if (__text.IsEmpty() && __pBitmap[i] == null && __isUserBackgroundBitmap[i] == false)
1513 return FloatDimension(GetBoundsF().width, GetBoundsF().height);
1517 FloatDimension textSize(0.0f, 0.0f);
1518 FloatDimension dimension(0.0f, 0.0f);
1519 FloatRectangle contentRect(0.0f, 0.0f, 0.0f, 0.0f);
1521 TextObject* pTextObject = __pButtonPresenter->GetTextObject();
1523 FloatRectangle previousRect = pTextObject->GetBoundsF();
1525 dimension.width = GetBoundsF().width - __leftMargin * 2;
1526 dimension.height = GetBoundsF().height - __topMargin * 2;
1528 _ControlOrientation orientation = GetOrientation();
1529 if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
1531 contentRect.width = _ControlManager::GetInstance()->GetScreenSizeF().width;
1532 contentRect.height = _ControlManager::GetInstance()->GetScreenSizeF().height;
1536 contentRect.width = _ControlManager::GetInstance()->GetScreenSizeF().height;
1537 contentRect.height = _ControlManager::GetInstance()->GetScreenSizeF().width;
1540 if (horizontalMode == true)
1542 FloatRectangle bounds(0.0f, 0.0f, contentRect.width - GetBoundsF().x - __leftMargin, dimension.height);
1543 pTextObject->SetBounds(bounds);
1544 pTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_NONE);
1545 pTextObject->Compose();
1547 textSize = pTextObject->GetTextExtentF();
1549 dimension.width = (textSize.width < bounds.width) ? textSize.width : bounds.width;
1552 if (verticalMode == true)
1554 FloatRectangle bounds(0.0f, 0.0f, dimension.width, dimension.height);
1555 pTextObject->SetBounds(bounds);
1556 pTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_NONE);
1557 pTextObject->Compose();
1559 textSize = pTextObject->GetTextExtentF();
1561 dimension.height = textSize.height;
1564 pTextObject->SetBounds(previousRect);
1566 dimension.width += __leftMargin * 4 - __leftTouchMargin - __rightTouchMargin;
1567 dimension.height += __topMargin * 4 - __topTouchMargin - __bottomTouchMargin;
1569 for (int i = 0; i < NUMBER_OF_BUTTON_STATUS; i++)
1571 if (__pBitmap[i] != null || __isUserBackgroundBitmap[i] == true)
1573 dimension.width = GetBoundsF().width;
1574 dimension.height = GetBoundsF().height;
1582 _Button::GetTextExtentSize(void) const
1584 return _CoordinateSystemUtils::ConvertToInteger(GetTextExtentSizeF());
1588 _Button::GetTextExtentSizeF(void) const
1590 float textExtentSize = 0.0f;
1592 TextObject* pTextObject = __pButtonPresenter->GetTextObject();
1593 Font* pFont = __pButtonPresenter->GetFont();
1595 TextObjectActionType previousActionType = pTextObject->GetAction();
1596 TextObjectWrapType previousWrapType = pTextObject->GetWrap();
1597 FloatRectangle previousRect = pTextObject->GetBoundsF();
1599 pTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_NONE);
1600 pTextObject->SetWrap(TEXT_OBJECT_WRAP_TYPE_WORD);
1601 pTextObject->SetFont(pFont, 0, pTextObject->GetTextLength());
1602 pTextObject->Compose();
1604 textExtentSize = pTextObject->GetTextExtentF(0, pTextObject->GetTextLength()).width;
1606 pTextObject->SetBounds(previousRect);
1607 pTextObject->SetAction(previousActionType);
1608 pTextObject->SetWrap(previousWrapType);
1609 pTextObject->Compose();
1611 return textExtentSize;
1615 _Button::SetTouchMargin(int leftTouchMargin, int topTouchMargin, int rightTouchMargin, int bottomTouchMargin)
1617 float floatLeftTouchMargin = _CoordinateSystemUtils::ConvertToFloat(leftTouchMargin);
1618 float floatTopTouchMargin = _CoordinateSystemUtils::ConvertToFloat(topTouchMargin);
1619 float floatRightTouchMargin = _CoordinateSystemUtils::ConvertToFloat(rightTouchMargin);
1620 float floatBottomTouchMargin = _CoordinateSystemUtils::ConvertToFloat(bottomTouchMargin);
1622 return SetTouchMargin(floatLeftTouchMargin, floatTopTouchMargin, floatRightTouchMargin, floatBottomTouchMargin);
1626 _Button::SetTouchMargin(float leftTouchMargin, float topTouchMargin, float rightTouchMargin, float bottomTouchMargin)
1628 __leftTouchMargin = leftTouchMargin;
1629 __topTouchMargin = topTouchMargin;
1630 __rightTouchMargin = rightTouchMargin;
1631 __bottomTouchMargin = bottomTouchMargin;
1637 _Button::GetLeftTouchMargin(void) const
1639 return _CoordinateSystemUtils::ConvertToInteger(GetLeftTouchMarginF());
1643 _Button::GetLeftTouchMarginF(void) const
1645 return __leftTouchMargin;
1649 _Button::GetTopTouchMargin(void) const
1651 return _CoordinateSystemUtils::ConvertToInteger(GetTopTouchMarginF());
1655 _Button::GetTopTouchMarginF(void) const
1657 return __topTouchMargin;
1661 _Button::GetRightTouchMargin(void) const
1663 return _CoordinateSystemUtils::ConvertToInteger(GetRightTouchMarginF());
1667 _Button::GetRightTouchMarginF(void) const
1669 return __rightTouchMargin;
1673 _Button::GetBottomTouchMargin(void) const
1675 return _CoordinateSystemUtils::ConvertToInteger(GetBottomTouchMarginF());
1679 _Button::GetBottomTouchMarginF(void) const
1681 return __bottomTouchMargin;
1685 _Button::SetMultilineTextSize(const Variant& textSize)
1687 result r = E_SUCCESS;
1689 if (textSize.ToFloat() > 0.0f)
1691 __multilineFontSize = textSize.ToFloat();
1692 __isSettingMultilineFontSize = true;
1697 SysLogException(NID_UI_CTRL, r, "[E_INVALID_ARG] Text size is no greater than 0.");
1704 _Button::GetMultilineTextSizeF(void) const
1706 return __multilineFontSize;
1710 _Button::IsMultilineFontSizeSet(void) const
1712 return __isSettingMultilineFontSize;
1714 }}} // Tizen::Ui::Controls