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.
19 * @file FUiCtrl_MessageBox.cpp
20 * @brief This is the implementation file for the _MessageBox class.
23 #include <FBaseSysLog.h>
24 #include <FBaseErrorDefine.h>
25 #include <FGrp_BitmapImpl.h>
26 #include <FSys_SettingInfoImpl.h>
27 #include "FUi_AccessibilityContainer.h"
28 #include "FUi_AccessibilityElement.h"
29 #include "FUi_CoordinateSystemUtils.h"
30 #include "FUi_EcoreEvas.h"
31 #include "FUi_EcoreEvasMgr.h"
32 #include "FUi_ResourceManager.h"
33 #include "FUiCtrl_Form.h"
34 #include "FUiCtrl_Frame.h"
35 #include "FUiCtrl_MessageBox.h"
36 #include "FUiCtrl_MessageBoxPresenter.h"
39 using namespace Tizen::Base;
40 using namespace Tizen::Graphics;
41 using namespace Tizen::System;
44 namespace Tizen { namespace Ui { namespace Controls
48 _MessageBox::_MessageBox(void)
49 : __pMsgboxPresenter(null)
50 , __msgboxStyle(MSGBOX_STYLE_NONE)
51 , __textColor(Color(0xFFFFFFFF))
52 , __pButtonEffectBitmap(null)
53 , __pTitleEffectBitmap(null)
54 , __pComposedButtonBitmap(null)
55 , __pComposedTitleBitmap(null)
62 _MessageBox::~_MessageBox(void)
64 delete __pMsgboxPresenter;
65 __pMsgboxPresenter = null;
67 delete _pComposedBgBitmap;
68 _pComposedBgBitmap = null;
70 delete _pOutlineBitmap;
71 _pOutlineBitmap = null;
73 delete __pButtonEffectBitmap;
74 __pButtonEffectBitmap = null;
76 delete __pTitleEffectBitmap;
77 __pTitleEffectBitmap = null;
79 delete __pComposedButtonBitmap;
80 __pComposedButtonBitmap = null;
82 delete __pComposedTitleBitmap;
83 __pComposedTitleBitmap = null;
85 _SettingInfoImpl::RemoveSettingEventListenerForInternal(*this);
89 _MessageBox::CreateMessageBoxN(void)
91 _MessageBox* pMsgbox = new (std::nothrow) _MessageBox();
92 SysTryReturn(NID_UI_CTRL, pMsgbox != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
94 result r = pMsgbox->CreateRootVisualElement(_WINDOW_TYPE_SUB);
95 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
97 // for taking touch event
98 pMsgbox->AcquireHandle();
109 _MessageBox::Initialize(const String& title, const String& text, MessageBoxStyle style, unsigned long timeout)
111 result r = E_SUCCESS;
113 float titleHeight = 0.0f;
114 Color titleBgColor(0x00000000);
115 Color buttonBgColor(0x00000000);
116 _AccessibilityContainer* pContainer = null;
117 SetFocusNavigateEnabled(false);
120 _titleState = !(title.Equals(L"", false));
123 __msgboxStyle = style;
126 _MessageBoxPresenter* pPresenter = new (std::nothrow) _MessageBoxPresenter();
127 SysTryReturn(NID_UI_CTRL, pPresenter != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
129 SetPresenter(*pPresenter);
131 r = pPresenter->Initialize(*this);
132 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
134 SetDimmingEnabled(true);
136 GET_COLOR_CONFIG(MESSAGEBOX::BG_NORMAL, _bgColor);
137 GET_COLOR_CONFIG(MESSAGEBOX::TITLE_TEXT_NORMAL, _titleTextColor);
138 GET_COLOR_CONFIG(MESSAGEBOX::TEXT_NORMAL, __textColor);
139 GET_COLOR_CONFIG(MESSAGEBOX::TITLE_BG_NORMAL, titleBgColor);
140 GET_COLOR_CONFIG(MESSAGEBOX::BOTTOM_BG_NORMAL, buttonBgColor);
142 GET_SHAPE_CONFIG(MESSAGEBOX::TITLE_HEIGHT, GetOrientation(), titleHeight);
145 r = GET_BITMAP_CONFIG_N(MESSAGEBOX::BG_OUTLINE_EFFECT_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, _pOutlineBitmap);
146 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] failed to load MessageBox Outline Image.");
149 r = GET_REPLACED_BITMAP_CONFIG_N(MESSAGEBOX::BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, _bgColor, _pComposedBgBitmap);
150 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] failed to load MessageBox BG Image.");
152 if (style != MSGBOX_STYLE_NONE)
154 // MsgBox-BottomBitmap
155 r = GET_REPLACED_BITMAP_CONFIG_N(MESSAGEBOX::BG_BUTTON_AREA, BITMAP_PIXEL_FORMAT_ARGB8888, buttonBgColor, __pComposedButtonBitmap);
156 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
158 // MsgBox-BottomEffectBitmap
159 r = GET_BITMAP_CONFIG_N(MESSAGEBOX::BG_BUTTON_EFFECT, BITMAP_PIXEL_FORMAT_ARGB8888, __pButtonEffectBitmap);
160 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
166 // MsgBox-TitleBitmap
167 r = GET_REPLACED_BITMAP_CONFIG_N(MESSAGEBOX::BG_TITLE_AREA, BITMAP_PIXEL_FORMAT_ARGB8888, titleBgColor, __pComposedTitleBitmap);
168 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
170 // MsgBox-TitleEffectBitmap
171 r = GET_BITMAP_CONFIG_N(MESSAGEBOX::BG_TITLE_EFFECT, BITMAP_PIXEL_FORMAT_ARGB8888, __pTitleEffectBitmap);
172 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
176 // for clearing canvas
177 if (GetVisualElement() != null)
179 GetVisualElement()->SetSurfaceOpaque(false);
182 pContainer = GetAccessibilityContainer();
183 if(pContainer != null)
185 pContainer->Activate(true);
186 pContainer->AddListener(*this);
189 r = _SettingInfoImpl::AddSettingEventListenerForInternal(*this);
190 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
192 SetTouchPressThreshold(0.08);
198 delete _pOutlineBitmap;
199 _pOutlineBitmap = null;
201 delete _pComposedBgBitmap;
202 _pComposedBgBitmap = null;
204 delete __pComposedButtonBitmap;
205 __pComposedButtonBitmap = null;
207 delete __pButtonEffectBitmap;
208 __pButtonEffectBitmap = null;
210 delete __pComposedTitleBitmap;
211 __pComposedTitleBitmap = null;
213 delete __pTitleEffectBitmap;
214 __pTitleEffectBitmap = null;
220 _MessageBox::SetPresenter(const _MessageBoxPresenter& msgboxPresenter)
222 __pMsgboxPresenter = const_cast <_MessageBoxPresenter*>(&msgboxPresenter);
228 _MessageBox::GetPresenter(void)
230 return static_cast <_PopupPresenter*>(__pMsgboxPresenter);
234 _MessageBox::OnDraw()
236 __pMsgboxPresenter->Draw();
237 if(unlikely((_AccessibilityManager::IsActivated())))
239 _AccessibilityManager::GetInstance()->RequestAutoReading(_ACCESSIBILITY_AUTO_READING_MODE_FIRST_ITEM);
245 _MessageBox::OnFontChanged(Font* pFont)
247 __pMsgboxPresenter->OnFontChanged(pFont);
251 _MessageBox::OnFontInfoRequested(unsigned long& style, float& size)
253 __pMsgboxPresenter->OnFontInfoRequested(style, size);
257 _MessageBox::OnActivated(void)
259 _Popup::OnActivated();
263 _MessageBox::OnDeactivated(void)
265 _Popup::OnDeactivated();
269 _MessageBox::InitializeAccessibilityElement(void)
271 result r = E_SUCCESS;
273 _Popup::InitializeAccessibilityElement();
275 if (_pTitleTextAccessibilityElement != null)
277 _pTitleTextAccessibilityElement->SetName(L"MessageBoxTitleText");
280 __pMsgboxPresenter->InitializeAccessibilityElement();
282 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
288 _MessageBox::ShowAndWait(int& modalResult)
290 __pMsgboxPresenter->ShowAndWait(modalResult);
296 _MessageBox::GetText(void) const
302 _MessageBox::GetTimeout(void) const
308 _MessageBox::SetTextColor(const Color& color)
314 _MessageBox::GetTextColor(void) const
320 _MessageBox::GetMsgBoxStyle(void) const
322 return __msgboxStyle;
326 _MessageBox::GetTotalHeight(void) const
328 float titleHeight = 0.0f;
329 float bottomHeight = 0.0f;
331 float textTopMargin = 0.0f;
332 float textTopMarginNoButton = 0.0f;
334 float transTopMargin = 0.0f;
335 float transBottomMargin = 0.0f;
337 _ControlOrientation orientation;
338 orientation = GetOrientation();
339 GET_SHAPE_CONFIG(MESSAGEBOX::TITLE_HEIGHT, orientation, titleHeight);
340 GET_SHAPE_CONFIG(MESSAGEBOX::BOTTOM_HEIGHT, orientation, bottomHeight);
342 GET_SHAPE_CONFIG(MESSAGEBOX::TEXT_TOP_MRAGIN, orientation, textTopMargin);
343 GET_SHAPE_CONFIG(MESSAGEBOX::TEXT_TOP_MRAGIN_NO_BUTTON, orientation, textTopMarginNoButton);
345 GET_SHAPE_CONFIG(MESSAGEBOX::BG_IMAGE_TRANSPARENT_TOP_MARGIN, orientation, transTopMargin);
346 GET_SHAPE_CONFIG(MESSAGEBOX::BG_IMAGE_TRANSPARENT_BOTTOM_MARGIN, orientation, transBottomMargin);
348 if (HasTitle() == false)
353 float totalH = titleHeight
356 + __pMsgboxPresenter->GetBodyTextObjHeight();
358 switch (__msgboxStyle)
360 case MSGBOX_STYLE_NONE:
361 totalH += textTopMarginNoButton * 2.0f;
364 case MSGBOX_STYLE_OK:
366 case MSGBOX_STYLE_CANCEL:
368 case MSGBOX_STYLE_OKCANCEL:
370 case MSGBOX_STYLE_YESNO:
372 case MSGBOX_STYLE_RETRYCANCEL:
374 case MSGBOX_STYLE_YESNOCANCEL:
376 case MSGBOX_STYLE_ABORTRETRYIGNORE:
378 case MSGBOX_STYLE_CANCELTRYCONTINUE:
379 totalH += textTopMargin * 2.0f
388 _MessageBox::OnChangeLayout(_ControlOrientation orientation)
390 _Popup::OnChangeLayout(orientation);
392 result r = __pMsgboxPresenter->OnChangeLayout(orientation);
393 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
399 _MessageBox::OnBoundsChanged(void)
401 _AccessibilityContainer* pContainer = null;
403 pContainer = GetAccessibilityContainer();
405 SetClientBounds(FloatRectangle(0.0f, 0.0f, GetBoundsF().width, GetBoundsF().height));
407 if ((_pTitleTextAccessibilityElement != null) && (HasTitle() == true))
409 _pTitleTextAccessibilityElement->SetBounds(__pMsgboxPresenter->GetTitleTextBounds());
412 if (GetMsgBoxStyle() == MSGBOX_STYLE_NONE && pContainer != null)
414 _AccessibilityElement* pElementMessageBox = pContainer->GetChildElement(L"MessageBox");
416 if (pElementMessageBox != null)
418 pElementMessageBox->SetBounds(FloatRectangle(0.0f, 0.0f, GetBoundsF().width, GetBoundsF().height));
426 _MessageBox::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
433 return __pMsgboxPresenter->OnTouchPressed(source, touchinfo);
437 _MessageBox::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
444 return __pMsgboxPresenter->OnTouchReleased(source, touchinfo);
448 _MessageBox::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
455 return __pMsgboxPresenter->OnTouchMoved(source, touchinfo);
459 _MessageBox::OnSettingChanged(String& key)
461 const wchar_t* LOCALE_LANGUAGE = L"http://tizen.org/setting/locale.language";
462 if (key == LOCALE_LANGUAGE)
464 __pMsgboxPresenter->UpdateButtonString();
469 _MessageBox::OnAccessibilityFocusMovedNext(const _AccessibilityContainer& control, const _AccessibilityElement& element)
475 _MessageBox::OnAccessibilityFocusMovedPrevious(const _AccessibilityContainer& control, const _AccessibilityElement& element)
481 _MessageBox::OnAccessibilityReadElement(const _AccessibilityContainer& control, const _AccessibilityElement& element)
487 _MessageBox::OnAccessibilityReadingElement(const _AccessibilityContainer& control, const _AccessibilityElement& element)
493 _MessageBox::OnAccessibilityFocusIn(const _AccessibilityContainer& control, const _AccessibilityElement& element)
499 _MessageBox::OnAccessibilityFocusOut(const _AccessibilityContainer& control, const _AccessibilityElement& element)
505 _MessageBox::OnAccessibilityActionPerformed(const _AccessibilityContainer& control, const _AccessibilityElement& element)
507 return __pMsgboxPresenter->OnAccessibilityActionPerformed(control, element);
511 _MessageBox::OnAccessibilityValueIncreased(const _AccessibilityContainer& control, const _AccessibilityElement& element)
517 _MessageBox::OnAccessibilityValueDecreased(const _AccessibilityContainer& control, const _AccessibilityElement& element)
523 _MessageBox::OnKeyReleased(const _Control& source, const _KeyInfo& keyInfo)
525 return __pMsgboxPresenter->OnKeyReleased(source, keyInfo);
529 _MessageBox::GetButtonBackgroundBitmap(void)
531 return __pComposedButtonBitmap;
535 _MessageBox::GetButtonBackgroundEffectBitmap(void)
537 return __pButtonEffectBitmap;
541 _MessageBox::GetTitleBackgroundBitmap(void)
543 return __pComposedTitleBitmap;
547 _MessageBox::GetTitleBackgroundEffectBitmap(void)
549 return __pTitleEffectBitmap;
551 }}} // Tizen::Ui::Controls