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.
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 "FUi_AccessibilityContainer.h"
27 #include "FUi_AccessibilityElement.h"
28 #include "FUi_ResourceManager.h"
29 #include "FUiCtrl_Form.h"
30 #include "FUiCtrl_Frame.h"
31 #include "FUiCtrl_MessageBox.h"
32 #include "FUiCtrl_MessageBoxPresenter.h"
35 using namespace Tizen::Base;
36 using namespace Tizen::Graphics;
39 namespace Tizen { namespace Ui { namespace Controls
43 _MessageBox::_MessageBox(void)
44 : __pMsgboxPresenter(null)
45 , __msgboxStyle(MSGBOX_STYLE_NONE)
46 , __textColor(Color(0xFFFFFFFF))
53 _MessageBox::~_MessageBox(void)
55 delete __pMsgboxPresenter;
56 __pMsgboxPresenter = null;
61 delete _pComposedBgBitmap;
62 _pComposedBgBitmap = null;
64 delete _pOutlineBitmap;
65 _pOutlineBitmap = null;
67 delete _pDimmingLayer;
68 _pDimmingLayer = null;
73 _MessageBox::CreateMessageBoxN(void)
75 _MessageBox* pMsgbox = new (std::nothrow) _MessageBox();
76 SysTryReturn(NID_UI, pMsgbox != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
78 #if defined(MULTI_WINDOW)
79 result r = pMsgbox->CreateRootVisualElement();
80 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
83 // for taking touch event
84 pMsgbox->AcquireHandle();
88 #if defined(MULTI_WINDOW)
97 _MessageBox::Initialize(const String& title, const String& text, MessageBoxStyle style, unsigned long timeout)
104 _titleState = !(title.Equals(L"", false));
107 __msgboxStyle = style;
110 _MessageBoxPresenter* pPresenter = new (std::nothrow) _MessageBoxPresenter();
111 SysTryReturn(NID_UI_CTRL, pPresenter != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
113 SetPresenter(*pPresenter);
115 r = pPresenter->Initialize(*this);
116 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
119 _pDimmingLayer = new (std::nothrow) _DimmingLayer();
120 SysTryReturn(NID_UI_CTRL, _pDimmingLayer != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
122 r = _pDimmingLayer->Construct(*this);
123 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
125 GET_COLOR_CONFIG(MESSAGEBOX::BG_NORMAL, _bgColor);
126 GET_COLOR_CONFIG(MESSAGEBOX::TITLE_TEXT_NORMAL, _titleTextColor);
127 GET_COLOR_CONFIG(MESSAGEBOX::TEXT_NORMAL, __textColor);
129 GET_SHAPE_CONFIG(MESSAGEBOX::TITLE_HEIGHT, GetOrientation(), titleHeight);
132 GET_BITMAP_CONFIG_N(MESSAGEBOX::BG_OUTLINE_EFFECT_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, _pOutlineBitmap);
134 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] failed to load MessageBox Outline Image.");
137 GET_BITMAP_CONFIG_N(MESSAGEBOX::BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, _pBgBitmap);
139 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] failed to load MessageBox BG Image.");
141 _pComposedBgBitmap = _BitmapImpl::GetColorReplacedBitmapN(*_pBgBitmap, Color::GetColor(COLOR_ID_MAGENTA), _bgColor);
143 // for clearing canvas
144 if (GetVisualElement() != null)
146 GetVisualElement()->SetSurfaceOpaque(false);
149 _AccessibilityContainer* pContainer = null;
151 pContainer = GetAccessibilityContainer();
152 if(pContainer != null)
154 pContainer->Activate(true);
157 SetTouchMoveAllowance(TOUCH_MOVE_ALLOWANCE_NORMAL);
163 _MessageBox::SetPresenter(const _MessageBoxPresenter& msgboxPresenter)
165 __pMsgboxPresenter = const_cast <_MessageBoxPresenter*>(&msgboxPresenter);
171 _MessageBox::OnDraw()
173 __pMsgboxPresenter->Draw();
179 _MessageBox::OnFontChanged(Font * pFont)
181 __pMsgboxPresenter->OnFontChanged(pFont);
185 _MessageBox::OnFontInfoRequested(unsigned long& style, int& size)
187 __pMsgboxPresenter->OnFontInfoRequested(style, size);
191 _MessageBox::OnActivated(void)
193 _Popup::OnActivated();
197 _MessageBox::OnDeactivated(void)
199 _Popup::OnDeactivated();
203 _MessageBox::OnAttachedToMainTree(void)
205 result r = E_SUCCESS;
207 SysTryReturn(NID_UI_CTRL, GetVisibleState() != false, E_INVALID_OPERATION,
208 E_INVALID_OPERATION, "[E_INVALID_OPERATION] This control is not 'displayable'");
210 r = __pMsgboxPresenter->OnAttachedToMainTree();
211 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
217 _MessageBox::ShowAndWait(int& modalResult)
219 __pMsgboxPresenter->ShowAndWait(modalResult);
225 _MessageBox::GetText(void) const
231 _MessageBox::GetTimeout(void) const
237 _MessageBox::SetTextColor(const Color& color)
243 _MessageBox::GetTextColor(void) const
249 _MessageBox::GetMsgBoxStyle(void) const
251 return __msgboxStyle;
255 _MessageBox::GetTotalHeight(void) const
260 int textTopMargin = 0;
261 int textTopMarginNoButton = 0;
264 int btnTopMargin = 0;
265 int btnBottomMargin = 0;
267 int transTopMargin = 0;
268 int transBottomMargin = 0;
270 GET_SHAPE_CONFIG(MESSAGEBOX::TITLE_HEIGHT, GetOrientation(), titleHeight);
271 GET_SHAPE_CONFIG(MESSAGEBOX::BUTTON_HEIGHT, GetOrientation(), btnHeight);
273 GET_SHAPE_CONFIG(MESSAGEBOX::TEXT_TOP_MRAGIN, GetOrientation(), textTopMargin);
274 GET_SHAPE_CONFIG(MESSAGEBOX::TEXT_TOP_MRAGIN_NO_BUTTON, GetOrientation(), textTopMarginNoButton);
276 GET_SHAPE_CONFIG(MESSAGEBOX::BUTTON_INTERNAL_GAP, GetOrientation(), btnGap);
277 GET_SHAPE_CONFIG(MESSAGEBOX::BUTTON_TOP_MARGIN, GetOrientation(), btnTopMargin);
278 GET_SHAPE_CONFIG(MESSAGEBOX::BUTTON_BOTTOM_MARGIN, GetOrientation(), btnBottomMargin);
280 GET_SHAPE_CONFIG(MESSAGEBOX::BG_IMAGE_TRANSPARENT_TOP_MARGIN, GetOrientation(), transTopMargin);
281 GET_SHAPE_CONFIG(MESSAGEBOX::BG_IMAGE_TRANSPARENT_BOTTOM_MARGIN, GetOrientation(), transBottomMargin);
283 if (HasTitle() == false)
288 int totalH = titleHeight
289 + __pMsgboxPresenter->GetBodyTextHeight()
293 switch (__msgboxStyle)
295 case MSGBOX_STYLE_NONE:
296 totalH += textTopMarginNoButton * 2;
299 case MSGBOX_STYLE_OK:
301 case MSGBOX_STYLE_CANCEL:
303 case MSGBOX_STYLE_OKCANCEL:
305 case MSGBOX_STYLE_YESNO:
307 case MSGBOX_STYLE_RETRYCANCEL:
309 case MSGBOX_STYLE_YESNOCANCEL:
311 case MSGBOX_STYLE_ABORTRETRYIGNORE:
313 case MSGBOX_STYLE_CANCELTRYCONTINUE:
314 totalH += textTopMargin * 2
325 _MessageBox::OnChangeLayout(_ControlOrientation orientation)
327 SysTryReturnVoidResult(NID_UI_CTRL, _pDimmingLayer != null, E_SYSTEM, "[E_SYSTEM] There is no Dimming Layer.");
329 result r = E_SUCCESS;
331 r = _pDimmingLayer->Rearrange();
332 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
338 _MessageBox::OnBoundsChanged(void)
340 SetClientBounds(Rectangle(0, 0, GetBounds().width, GetBounds().height));
346 _MessageBox::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
353 return __pMsgboxPresenter->OnTouchPressed(source, touchinfo);
357 _MessageBox::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
364 return __pMsgboxPresenter->OnTouchReleased(source, touchinfo);
368 _MessageBox::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
375 return __pMsgboxPresenter->OnTouchMoved(source, touchinfo);
379 }}} // Tizen::Ui::Controls