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;
70 delete _pComposedBgBitmap;
71 _pComposedBgBitmap = null;
73 delete _pOutlineBitmap;
74 _pOutlineBitmap = null;
76 delete __pButtonEffectBitmap;
77 __pButtonEffectBitmap = null;
79 delete __pTitleEffectBitmap;
80 __pTitleEffectBitmap = null;
82 delete __pComposedButtonBitmap;
83 __pComposedButtonBitmap = null;
85 delete __pComposedTitleBitmap;
86 __pComposedTitleBitmap = null;
88 _SettingInfoImpl::RemoveSettingEventListenerForInternal(*this);
92 _MessageBox::CreateMessageBoxN(void)
94 _MessageBox* pMsgbox = new (std::nothrow) _MessageBox();
95 SysTryReturn(NID_UI_CTRL, pMsgbox != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
97 result r = pMsgbox->CreateRootVisualElement(_WINDOW_TYPE_SUB);
98 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
100 // for taking touch event
101 pMsgbox->AcquireHandle();
112 _MessageBox::Initialize(const String& title, const String& text, MessageBoxStyle style, unsigned long timeout)
114 result r = E_SUCCESS;
116 float titleHeight = 0.0f;
117 Bitmap* buttonBgBitmap = null;
118 Bitmap* titleBgBitmap = null;
119 Color titleBgColor(0x00000000);
120 Color buttonBgColor(0x00000000);
121 _AccessibilityContainer* pContainer = null;
122 SetFocusNavigateEnabled(false);
125 _titleState = !(title.Equals(L"", false));
128 __msgboxStyle = style;
131 _MessageBoxPresenter* pPresenter = new (std::nothrow) _MessageBoxPresenter();
132 SysTryReturn(NID_UI_CTRL, pPresenter != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
134 SetPresenter(*pPresenter);
136 r = pPresenter->Initialize(*this);
137 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
139 SetDimmingEnabled(true);
141 GET_COLOR_CONFIG(MESSAGEBOX::BG_NORMAL, _bgColor);
142 GET_COLOR_CONFIG(MESSAGEBOX::TITLE_TEXT_NORMAL, _titleTextColor);
143 GET_COLOR_CONFIG(MESSAGEBOX::TEXT_NORMAL, __textColor);
144 GET_COLOR_CONFIG(MESSAGEBOX::TITLE_BG_NORMAL, titleBgColor);
145 GET_COLOR_CONFIG(MESSAGEBOX::BOTTOM_BG_NORMAL, buttonBgColor);
147 GET_SHAPE_CONFIG(MESSAGEBOX::TITLE_HEIGHT, GetOrientation(), titleHeight);
150 GET_BITMAP_CONFIG_N(MESSAGEBOX::BG_OUTLINE_EFFECT_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, _pOutlineBitmap);
152 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] failed to load MessageBox Outline Image.");
155 GET_BITMAP_CONFIG_N(MESSAGEBOX::BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, _pBgBitmap);
157 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] failed to load MessageBox BG Image.");
159 _pComposedBgBitmap = _BitmapImpl::GetColorReplacedBitmapN(*_pBgBitmap, Color::GetColor(COLOR_ID_MAGENTA), _bgColor);
161 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
163 if (style != MSGBOX_STYLE_NONE)
165 // MsgBox-BottomBitmap
166 GET_BITMAP_CONFIG_N(MESSAGEBOX::BG_BUTTON_AREA, BITMAP_PIXEL_FORMAT_ARGB8888, buttonBgBitmap);
168 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
170 // MsgBox-BottomEffectBitmap
171 GET_BITMAP_CONFIG_N(MESSAGEBOX::BG_BUTTON_EFFECT, BITMAP_PIXEL_FORMAT_ARGB8888, __pButtonEffectBitmap);
173 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
175 __pComposedButtonBitmap = _BitmapImpl::GetColorReplacedBitmapN(*buttonBgBitmap, Color::GetColor(COLOR_ID_MAGENTA), buttonBgColor);
177 SysTryCatch(NID_UI_CTRL, (__pComposedButtonBitmap != null), , r, "[%s] Propagating.", GetErrorMessage(r));
182 // MsgBox-TitleBitmap
183 GET_BITMAP_CONFIG_N(MESSAGEBOX::BG_TITLE_AREA, BITMAP_PIXEL_FORMAT_ARGB8888, titleBgBitmap);
185 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
187 // MsgBox-TitleEffectBitmap
188 GET_BITMAP_CONFIG_N(MESSAGEBOX::BG_TITLE_EFFECT, BITMAP_PIXEL_FORMAT_ARGB8888, __pTitleEffectBitmap);
190 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
192 __pComposedTitleBitmap = _BitmapImpl::GetColorReplacedBitmapN(*titleBgBitmap, Color::GetColor(COLOR_ID_MAGENTA), titleBgColor);
194 SysTryCatch(NID_UI_CTRL, (__pComposedTitleBitmap != null), , r, "[%s] Propagating.", GetErrorMessage(r));
197 // for clearing canvas
198 if (GetVisualElement() != null)
200 GetVisualElement()->SetSurfaceOpaque(false);
203 pContainer = GetAccessibilityContainer();
204 if(pContainer != null)
206 pContainer->Activate(true);
207 pContainer->AddListener(*this);
210 r = _SettingInfoImpl::AddSettingEventListenerForInternal(*this);
211 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
213 SetTouchPressThreshold(0.08);
215 if (buttonBgBitmap != null)
217 delete buttonBgBitmap;
218 buttonBgBitmap = null;
221 if (titleBgBitmap != null)
223 delete titleBgBitmap;
224 titleBgBitmap = null;
230 if (buttonBgBitmap != null)
232 delete buttonBgBitmap;
233 buttonBgBitmap = null;
236 if (titleBgBitmap != null)
238 delete titleBgBitmap;
239 titleBgBitmap = null;
242 delete _pComposedBgBitmap;
243 _pComposedBgBitmap = null;
245 if (__pComposedButtonBitmap != null)
247 delete __pComposedButtonBitmap;
248 __pComposedButtonBitmap = null;
251 if(__pComposedTitleBitmap != null)
253 delete __pComposedTitleBitmap;
254 __pComposedTitleBitmap = null;
261 _MessageBox::SetPresenter(const _MessageBoxPresenter& msgboxPresenter)
263 __pMsgboxPresenter = const_cast <_MessageBoxPresenter*>(&msgboxPresenter);
269 _MessageBox::GetPresenter(void)
271 return static_cast <_PopupPresenter*>(__pMsgboxPresenter);
275 _MessageBox::OnDraw()
277 __pMsgboxPresenter->Draw();
278 if(unlikely((_AccessibilityManager::IsActivated())))
280 _AccessibilityManager::GetInstance()->RequestAutoReading(_ACCESSIBILITY_AUTO_READING_MODE_FIRST_ITEM);
286 _MessageBox::OnFontChanged(Font * pFont)
288 __pMsgboxPresenter->OnFontChanged(pFont);
292 _MessageBox::OnFontInfoRequested(unsigned long& style, float& size)
294 __pMsgboxPresenter->OnFontInfoRequested(style, size);
298 _MessageBox::OnActivated(void)
300 _Popup::OnActivated();
304 _MessageBox::OnDeactivated(void)
306 _Popup::OnDeactivated();
310 _MessageBox::InitializeAccessibilityElement(void)
312 result r = E_SUCCESS;
314 _Popup::InitializeAccessibilityElement();
316 if (_pTitleTextAccessibilityElement != null)
318 _pTitleTextAccessibilityElement->SetName(L"MessageBoxTitleText");
321 __pMsgboxPresenter->InitializeAccessibilityElement();
323 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
329 _MessageBox::ShowAndWait(int& modalResult)
331 __pMsgboxPresenter->ShowAndWait(modalResult);
337 _MessageBox::GetText(void) const
343 _MessageBox::GetTimeout(void) const
349 _MessageBox::SetTextColor(const Color& color)
355 _MessageBox::GetTextColor(void) const
361 _MessageBox::GetMsgBoxStyle(void) const
363 return __msgboxStyle;
367 _MessageBox::GetTotalHeight(void) const
369 float titleHeight = 0.0f;
370 float btnHeight = 0.0f;
372 float textTopMargin = 0.0f;
373 float textTopMarginNoButton = 0.0f;
376 float btnTopMargin = 0.0f;
377 float btnBottomMargin = 0.0f;
379 float transTopMargin = 0.0f;
380 float transBottomMargin = 0.0f;
382 _ControlOrientation orientation;
383 orientation = GetOrientation();
384 GET_SHAPE_CONFIG(MESSAGEBOX::TITLE_HEIGHT, orientation, titleHeight);
385 GET_SHAPE_CONFIG(MESSAGEBOX::BUTTON_HEIGHT, orientation, btnHeight);
387 GET_SHAPE_CONFIG(MESSAGEBOX::TEXT_TOP_MRAGIN, orientation, textTopMargin);
388 GET_SHAPE_CONFIG(MESSAGEBOX::TEXT_TOP_MRAGIN_NO_BUTTON, orientation, textTopMarginNoButton);
390 GET_SHAPE_CONFIG(MESSAGEBOX::BUTTON_INTERNAL_GAP, orientation, btnGap);
391 GET_SHAPE_CONFIG(MESSAGEBOX::BUTTON_TOP_MARGIN, orientation, btnTopMargin);
392 GET_SHAPE_CONFIG(MESSAGEBOX::BUTTON_BOTTOM_MARGIN, orientation, btnBottomMargin);
394 GET_SHAPE_CONFIG(MESSAGEBOX::BG_IMAGE_TRANSPARENT_TOP_MARGIN, orientation, transTopMargin);
395 GET_SHAPE_CONFIG(MESSAGEBOX::BG_IMAGE_TRANSPARENT_BOTTOM_MARGIN, orientation, transBottomMargin);
397 if (HasTitle() == false)
402 float totalH = titleHeight
405 + __pMsgboxPresenter->GetBodyTextObjHeight();
407 switch (__msgboxStyle)
409 case MSGBOX_STYLE_NONE:
410 totalH += textTopMarginNoButton * 2.0f;
413 case MSGBOX_STYLE_OK:
415 case MSGBOX_STYLE_CANCEL:
417 case MSGBOX_STYLE_OKCANCEL:
419 case MSGBOX_STYLE_YESNO:
421 case MSGBOX_STYLE_RETRYCANCEL:
423 case MSGBOX_STYLE_YESNOCANCEL:
425 case MSGBOX_STYLE_ABORTRETRYIGNORE:
427 case MSGBOX_STYLE_CANCELTRYCONTINUE:
428 totalH += textTopMargin * 2.0f
439 _MessageBox::OnChangeLayout(_ControlOrientation orientation)
441 _Popup::OnChangeLayout(orientation);
443 result r = __pMsgboxPresenter->OnChangeLayout(orientation);
444 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
450 _MessageBox::OnBoundsChanged(void)
452 _AccessibilityContainer* pContainer = null;
454 pContainer = GetAccessibilityContainer();
456 SetClientBounds(FloatRectangle(0.0f, 0.0f, GetBoundsF().width, GetBoundsF().height));
458 if ((_pTitleTextAccessibilityElement != null) && (HasTitle() == true))
460 _pTitleTextAccessibilityElement->SetBounds(__pMsgboxPresenter->GetTitleTextBounds());
463 if (GetMsgBoxStyle() == MSGBOX_STYLE_NONE && pContainer != null)
465 _AccessibilityElement* pElementMessageBox = pContainer->GetChildElement(L"MessageBox");
467 if (pElementMessageBox != null)
469 pElementMessageBox->SetBounds(FloatRectangle(0.0f, 0.0f, GetBoundsF().width, GetBoundsF().height));
477 _MessageBox::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
484 return __pMsgboxPresenter->OnTouchPressed(source, touchinfo);
488 _MessageBox::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
495 return __pMsgboxPresenter->OnTouchReleased(source, touchinfo);
499 _MessageBox::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
506 return __pMsgboxPresenter->OnTouchMoved(source, touchinfo);
510 _MessageBox::OnSettingChanged(String& key)
512 const wchar_t* LOCALE_LANGUAGE = L"http://tizen.org/setting/locale.language";
513 if (key == LOCALE_LANGUAGE)
515 __pMsgboxPresenter->UpdateButtonString();
520 _MessageBox::OnAccessibilityFocusMovedNext(const _AccessibilityContainer& control, const _AccessibilityElement& element)
526 _MessageBox::OnAccessibilityFocusMovedPrevious(const _AccessibilityContainer& control, const _AccessibilityElement& element)
532 _MessageBox::OnAccessibilityReadElement(const _AccessibilityContainer& control, const _AccessibilityElement& element)
538 _MessageBox::OnAccessibilityReadingElement(const _AccessibilityContainer& control, const _AccessibilityElement& element)
544 _MessageBox::OnAccessibilityFocusIn(const _AccessibilityContainer& control, const _AccessibilityElement& element)
550 _MessageBox::OnAccessibilityFocusOut(const _AccessibilityContainer& control, const _AccessibilityElement& element)
556 _MessageBox::OnAccessibilityActionPerformed(const _AccessibilityContainer& control, const _AccessibilityElement& element)
558 return __pMsgboxPresenter->OnAccessibilityActionPerformed(control, element);
562 _MessageBox::OnAccessibilityValueIncreased(const _AccessibilityContainer& control, const _AccessibilityElement& element)
568 _MessageBox::OnAccessibilityValueDecreased(const _AccessibilityContainer& control, const _AccessibilityElement& element)
574 _MessageBox::OnKeyReleased(const _Control& source, const _KeyInfo& keyInfo)
576 return __pMsgboxPresenter->OnKeyReleased(source, keyInfo);
580 _MessageBox::GetButtonBackgroundBitmap(void)
582 return __pComposedButtonBitmap;
586 _MessageBox::GetButtonBackgroundEffectBitmap(void)
588 return __pButtonEffectBitmap;
592 _MessageBox::GetTitleBackgroundBitmap(void)
594 return __pComposedTitleBitmap;
598 _MessageBox::GetTitleBackgroundEffectBitmap(void)
600 return __pTitleEffectBitmap;
602 }}} // Tizen::Ui::Controls