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_MessageBoxPresenter.cpp
20 * @brief This is the implementation file for the _MessageBoxPresenter class.
23 #include <FUiCtrlMessageBox.h>
24 #include <FBaseSysLog.h>
25 #include <FBaseErrorDefine.h>
26 #include <FGrp_CanvasImpl.h>
27 #include <FGrp_TextTextSimple.h>
28 #include "FUi_AccessibilityContainer.h"
29 #include "FUi_AccessibilityElement.h"
30 #include "FUi_ModalLoopManager.h"
31 #include "FUi_ResourceManager.h"
32 #include "FUi_TouchManager.h"
33 #include "FUiCtrl_ButtonImpl.h"
34 #include "FUiCtrl_Button.h"
35 #include "FUiCtrl_Scroll.h"
36 #include "FUiCtrl_MessageBox.h"
37 #include "FUiCtrl_MessageBoxPresenter.h"
40 using namespace Tizen::Base;
41 using namespace Tizen::Base::Runtime;
42 using namespace Tizen::Graphics;
43 using namespace Tizen::Graphics::_Text;
44 using namespace Tizen::Ui;
45 using namespace Tizen::Ui::Animations;
48 namespace Tizen { namespace Ui { namespace Controls
52 _MessageBoxPresenter::_MessageBoxPresenter(void)
54 , __pButtonListener(null)
55 , __msgboxResult(MSGBOX_RESULT_CLOSE)
56 , __pTextAccessibilityElement(null)
57 , __pTitleTextObject(null)
58 , __pBodyTextObject(null)
59 , __titleBounds(0, 0, 0, 0)
60 , __textBounds(0, 0, 0, 0)
68 , __touchPressFlag(false)
69 , __scrollStart(false)
70 , __btnClickFlag(false)
71 , __bodyClickFlag(false)
72 , __touchOutBounds(false)
74 for (int i = 0; i < 3; i++)
80 _MessageBoxPresenter::~_MessageBoxPresenter(void)
82 for (int i = 0; i < __buttonNum; i++)
88 delete __pButtonListener;
89 __pButtonListener = null;
91 if (__pTitleTextObject != null)
93 __pTitleTextObject->RemoveAll();
94 delete __pTitleTextObject;
95 __pTitleTextObject = null;
98 if (__pBodyTextObject != null)
100 __pBodyTextObject->RemoveAll();
101 delete __pBodyTextObject;
102 __pBodyTextObject = null;
105 if (__pScroll != null)
107 __pMessageBox->DetachSystemChild(*__pScroll);
112 if (__pTextAccessibilityElement)
114 __pTextAccessibilityElement->Activate(false);
115 __pTextAccessibilityElement = null;
120 _MessageBoxPresenter::Initialize(_MessageBox& msgbox)
122 result r = E_SUCCESS;
123 String titleText = L"";
124 String bodyText = L"";
125 TextSimple* pSimpleTextForBodyText = null;
127 int titleTextSize = 0;
128 int bodyTextSize = 0;
130 int defaultWidth = 0;
132 int bottomHeight = 0;
135 int btnBottomMargin = 0;
136 int textTopMargin = 0;
137 int textLeftMargin = 0;
138 int textRightMargin = 0;
140 int titleTopMargin = 0;
141 int titleLeftMargin = 0;
142 int titleRightMargin = 0;
144 int transTopMargin = 0;
145 int transBottomMargin = 0;
146 int transLeftMargin = 0;
147 int transRightMargin = 0;
149 int totalHeightExceptTextObj = 0;
152 __pMessageBox = &msgbox;
154 GET_SHAPE_CONFIG(MESSAGEBOX::TITLE_TEXT_SIZE, __pMessageBox->GetOrientation(), titleTextSize);
155 GET_SHAPE_CONFIG(MESSAGEBOX::TEXT_SIZE, __pMessageBox->GetOrientation(), bodyTextSize);
157 GET_SHAPE_CONFIG(MESSAGEBOX::DEFAULT_WIDTH, __pMessageBox->GetOrientation(), defaultWidth);
158 GET_SHAPE_CONFIG(MESSAGEBOX::TITLE_HEIGHT, __pMessageBox->GetOrientation(), titleHeight);
159 GET_SHAPE_CONFIG(MESSAGEBOX::BOTTOM_HEIGHT, __pMessageBox->GetOrientation(), bottomHeight);
160 GET_SHAPE_CONFIG(MESSAGEBOX::MAX_HEIGHT, __pMessageBox->GetOrientation(), maxHeight);
162 GET_SHAPE_CONFIG(MESSAGEBOX::BUTTON_BOTTOM_MARGIN, __pMessageBox->GetOrientation(), btnBottomMargin);
163 GET_SHAPE_CONFIG(MESSAGEBOX::TEXT_TOP_MRAGIN, __pMessageBox->GetOrientation(), textTopMargin);
164 GET_SHAPE_CONFIG(MESSAGEBOX::TEXT_LEFT_MARGIN, __pMessageBox->GetOrientation(), textLeftMargin);
165 GET_SHAPE_CONFIG(MESSAGEBOX::TEXT_RIGHT_MARGIN, __pMessageBox->GetOrientation(), textRightMargin);
167 GET_SHAPE_CONFIG(MESSAGEBOX::TITLE_TEXT_TOP_MARGIN, __pMessageBox->GetOrientation(), titleTopMargin);
168 GET_SHAPE_CONFIG(MESSAGEBOX::TITLE_TEXT_LEFT_MARGIN, __pMessageBox->GetOrientation(), titleLeftMargin);
169 GET_SHAPE_CONFIG(MESSAGEBOX::TITLE_TEXT_RIGHT_MARGIN, __pMessageBox->GetOrientation(), titleRightMargin);
171 GET_SHAPE_CONFIG(MESSAGEBOX::BG_IMAGE_TRANSPARENT_TOP_MARGIN, __pMessageBox->GetOrientation(), transTopMargin);
172 GET_SHAPE_CONFIG(MESSAGEBOX::BG_IMAGE_TRANSPARENT_BOTTOM_MARGIN, __pMessageBox->GetOrientation(), transBottomMargin);
173 GET_SHAPE_CONFIG(MESSAGEBOX::BG_IMAGE_TRANSPARENT_LEFT_MARGIN, __pMessageBox->GetOrientation(), transLeftMargin);
174 GET_SHAPE_CONFIG(MESSAGEBOX::BG_IMAGE_TRANSPARENT_RIGHT_MARGIN, __pMessageBox->GetOrientation(), transRightMargin);
177 if (__pMessageBox->HasTitle() == true)
179 r = SetFontInfo(FONT_STYLE_PLAIN, titleTextSize);
180 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Failed to set font.", GetErrorMessage(r));
182 __pTitleTextObject = new (std::nothrow) TextObject();
183 SysTryReturn(NID_UI_CTRL, __pTitleTextObject != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Unable to create TitleTextObject.");
185 __pTitleTextObject->Construct();
186 TextSimple* pSimpleTextForTitleText = new (std::nothrow) TextSimple(const_cast <wchar_t*>(__pMessageBox->GetTitleText().GetPointer()),
187 __pMessageBox->GetTitleText().GetLength(),
188 TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
189 SysTryCatch(NID_UI_CTRL, pSimpleTextForTitleText != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
191 __pTitleTextObject->AppendElement(*pSimpleTextForTitleText);
192 __pTitleTextObject->SetForegroundColor(__pMessageBox->GetTitleTextColor(), 0, __pTitleTextObject->GetTextLength());
193 __pTitleTextObject->SetWrap(TEXT_OBJECT_WRAP_TYPE_NONE);
194 __pTitleTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
195 __pTitleTextObject->SetTextObjectEllipsisType(TEXT_OBJECT_ELLIPSIS_TYPE_TAIL);
197 __pTitleTextObject->SetFont(_pFont, 0, __pTitleTextObject->GetTextLength());
198 __pTitleTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_LEFT);
199 __pTitleTextObject->SetBounds(Rectangle(titleLeftMargin + transLeftMargin,
200 titleTopMargin + transTopMargin,
201 defaultWidth - (titleLeftMargin + titleRightMargin + transLeftMargin + transRightMargin),
202 titleHeight - titleTopMargin));
203 __pTitleTextObject->Compose();
205 __titleBounds = Rectangle(titleLeftMargin + transLeftMargin,
206 titleTopMargin + transTopMargin,
207 defaultWidth - (titleLeftMargin + titleRightMargin + transLeftMargin + transRightMargin),
208 __pTitleTextObject->GetTotalHeight());
217 r = SetFontInfo(FONT_STYLE_PLAIN, bodyTextSize);
218 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set font.", GetErrorMessage(r));
220 __pBodyTextObject = new (std::nothrow) TextObject();
221 SysTryCatch(NID_UI_CTRL, __pBodyTextObject != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
223 __pBodyTextObject->Construct();
225 pSimpleTextForBodyText = new (std::nothrow) TextSimple(const_cast <wchar_t*>(__pMessageBox->GetText().GetPointer()),
226 __pMessageBox->GetText().GetLength(),
227 TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
228 SysTryCatch(NID_UI_CTRL, pSimpleTextForBodyText != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
230 __pBodyTextObject->AppendElement(*pSimpleTextForBodyText);
231 __pBodyTextObject->SetForegroundColor(__pMessageBox->GetTextColor(), 0, __pBodyTextObject->GetTextLength());
232 __pBodyTextObject->SetWrap(TEXT_OBJECT_WRAP_TYPE_WORD);
233 __pBodyTextObject->SetFont(_pFont, 0, __pBodyTextObject->GetTextLength());
234 __pBodyTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_LEFT);
235 __pBodyTextObject->SetBounds(Rectangle(textLeftMargin + transLeftMargin,
236 titleHeight + textTopMargin + transTopMargin,
237 defaultWidth - (textLeftMargin + textRightMargin + transLeftMargin + transRightMargin),
238 maxHeight - titleHeight));
239 __pBodyTextObject->Compose();
241 __textObjHeight = __pBodyTextObject->GetTotalHeight();
244 totalHeightExceptTextObj = titleHeight + (textTopMargin * 2) + bottomHeight + (transTopMargin + transBottomMargin);
245 tempHeight = maxHeight - (totalHeightExceptTextObj + __textObjHeight);
247 __textObjHeight = (tempHeight > 0) ? __textObjHeight : __textObjHeight + tempHeight;
249 __textBounds.SetBounds(textLeftMargin+ transLeftMargin,
250 titleHeight + textTopMargin + transTopMargin,
251 defaultWidth - (textLeftMargin + textRightMargin + transLeftMargin + transRightMargin),
254 __pBodyTextObject->SetBounds(__textBounds);
257 if (__pBodyTextObject->GetTotalHeight() > __textObjHeight)
259 int maxH = __pBodyTextObject->GetTotalHeight();
261 __pScroll = _Scroll::CreateScrollN(*__pMessageBox,
262 SCROLL_DIRECTION_VERTICAL,
271 SysTryCatch(NID_UI_CTRL, __pScroll != null, , E_OUT_OF_MEMORY, "[E_SYSTEM] Failed to create the scroll.");
273 __pMessageBox->AttachSystemChild(*__pScroll);
277 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
282 delete __pTitleTextObject;
283 __pTitleTextObject = null;
285 delete __pBodyTextObject;
286 __pBodyTextObject = null;
288 delete pSimpleTextForBodyText;
295 _MessageBoxPresenter::OnFontChanged(Font* pFont)
301 _MessageBoxPresenter::OnFontInfoRequested(unsigned long& style, int& size)
308 _MessageBoxPresenter::SetFontInfo(unsigned long style, int size)
313 _pFont = __pMessageBox->GetFallbackFont();
314 SysTryReturnResult(NID_UI_CTRL, _pFont != null, GetLastResult(), "Failed to get a font.");
320 _MessageBoxPresenter::Draw(void)
322 result r = E_SUCCESS;
324 int defaultWidth = 0;
326 int titleTextSize = 0;
327 int titleTopMargin = 0;
330 int btnTopMargin = 0;
331 int btnBottomMargin = 0;
334 int textTopMarginNoButton = 0;
335 int textTopMargin = 0;
337 int transTopMargin = 0;
338 int transBottomMargin = 0;
339 int transLeftMargin = 0;
340 int transRightMargin = 0;
342 GET_SHAPE_CONFIG(MESSAGEBOX::DEFAULT_WIDTH, __pMessageBox->GetOrientation(), defaultWidth);
343 GET_SHAPE_CONFIG(MESSAGEBOX::TITLE_HEIGHT, __pMessageBox->GetOrientation(), titleHeight);
344 GET_SHAPE_CONFIG(MESSAGEBOX::TITLE_TEXT_SIZE, __pMessageBox->GetOrientation(), titleTextSize);
345 GET_SHAPE_CONFIG(MESSAGEBOX::TITLE_TEXT_TOP_MARGIN, __pMessageBox->GetOrientation(), titleTopMargin);
347 GET_SHAPE_CONFIG(MESSAGEBOX::TEXT_SIZE, __pMessageBox->GetOrientation(), textSize);
348 GET_SHAPE_CONFIG(MESSAGEBOX::TEXT_TOP_MRAGIN, __pMessageBox->GetOrientation(), textTopMargin);
349 GET_SHAPE_CONFIG(MESSAGEBOX::TEXT_TOP_MRAGIN_NO_BUTTON, __pMessageBox->GetOrientation(), textTopMarginNoButton);
351 GET_SHAPE_CONFIG(MESSAGEBOX::BUTTON_HEIGHT, __pMessageBox->GetOrientation(), btnHeight);
352 GET_SHAPE_CONFIG(MESSAGEBOX::BUTTON_TOP_MARGIN, __pMessageBox->GetOrientation(), btnTopMargin);
353 GET_SHAPE_CONFIG(MESSAGEBOX::BUTTON_BOTTOM_MARGIN, __pMessageBox->GetOrientation(), btnBottomMargin);
355 GET_SHAPE_CONFIG(MESSAGEBOX::BG_IMAGE_TRANSPARENT_TOP_MARGIN, __pMessageBox->GetOrientation(), transTopMargin);
356 GET_SHAPE_CONFIG(MESSAGEBOX::BG_IMAGE_TRANSPARENT_BOTTOM_MARGIN, __pMessageBox->GetOrientation(), transBottomMargin);
357 GET_SHAPE_CONFIG(MESSAGEBOX::BG_IMAGE_TRANSPARENT_LEFT_MARGIN, __pMessageBox->GetOrientation(), transLeftMargin);
358 GET_SHAPE_CONFIG(MESSAGEBOX::BG_IMAGE_TRANSPARENT_RIGHT_MARGIN, __pMessageBox->GetOrientation(), transRightMargin);
360 Canvas* pCanvas = __pMessageBox->GetCanvasN();
361 SysTryReturnVoidResult(NID_UI_CTRL, (pCanvas != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Unable to create canvas.");
363 pCanvas->SetBackgroundColor(Color(0x00000000));
366 bool hasBgBitmap = (__pMessageBox->GetBackgroundBitmap() != null);
368 int totalH = __pMessageBox->GetTotalHeight();
371 if (hasBgBitmap == true)
373 Rectangle bounds(0, 0, defaultWidth, totalH);
375 const Bitmap* pBackgroundBitmap = __pMessageBox->GetBackgroundBitmap();
376 if (pBackgroundBitmap->IsNinePatchedBitmap() == true)
378 pCanvas->DrawNinePatchedBitmap(bounds, *pBackgroundBitmap);
382 pCanvas->DrawBitmap(bounds, *pBackgroundBitmap);
387 if (__pTitleTextObject != null)
389 r = SetFontInfo(FONT_STYLE_PLAIN, titleTextSize);
390 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
392 __pTitleTextObject->SetFont(_pFont, 0, __pTitleTextObject->GetTextLength());
393 __pTitleTextObject->SetBounds(__titleBounds);
394 __pTitleTextObject->SetForegroundColor(__pMessageBox->GetTitleTextColor(), 0, __pTitleTextObject->GetTextLength());
396 __pTitleTextObject->Draw(*_CanvasImpl::GetInstance(*pCanvas));
400 if (__pBodyTextObject != null)
402 r = SetFontInfo(FONT_STYLE_PLAIN, textSize);
403 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
405 __pBodyTextObject->SetFont(_pFont, 0, __pBodyTextObject->GetTextLength());
406 __pBodyTextObject->SetForegroundColor(__pMessageBox->GetTextColor(), 0, __pBodyTextObject->GetTextLength());
408 __pBodyTextObject->SetBounds(__textBounds);
409 if ((__pMessageBox->HasTitle() == false) && (__pMessageBox->GetMsgBoxStyle() == MSGBOX_STYLE_NONE))
411 __textBounds.y = transTopMargin + textTopMarginNoButton;
412 __pBodyTextObject->SetBounds(__textBounds);
415 __pBodyTextObject->Draw(*_CanvasImpl::GetInstance(*pCanvas));
426 _MessageBoxPresenter::ShowAndWait(int& modalResult)
428 result r = E_SUCCESS;
430 for (int i = 0; i < __buttonNum; i++)
432 _ControlImpl* pImpl = _ControlImpl::GetInstance(*__pButtons[i]);
433 __pMessageBox->AttachChild(pImpl->GetCore());
436 r = __pMessageBox->Open();
438 if (__pMessageBox->GetMsgBoxStyle() == MSGBOX_STYLE_NONE)
440 __pMessageBox->SetTouchCapture(true);
444 __pMessageBox->SetTouchCapture();
449 __pMessageBox->ReleaseTouchCapture();
451 __pMessageBox->Close();
454 modalResult = GetReturnValue();
460 _MessageBoxPresenter::ProcessEvent(void)
462 _ControlHandle handle;
464 _TouchManager* pTouchManager = _TouchManager::GetInstance();
467 _Control* pControl = pTouchManager->GetTouchControlSource();
470 pControl->SetEventReceivable(false);
474 _ModalLoopManager::GetInstance()->BeginMainLoop(__pMessageBox->GetTimeout(), MSGBOX_RESULT_CLOSE);
476 int exitCode = _ModalLoopManager::GetInstance()->GetLastExitCode();
479 case MSGBOX_BUTTON_CLICKED:
480 if (__pButtonListener->IsButtonClicked())
482 handle = __pButtonListener->GetClickedButtonHandle();
483 FindButtonAndResult(handle);
487 case _ModalLoopManager::MODAL_LOOP_EXIT_CODE_APP_TERMINATION:
488 case _ModalLoopManager::MODAL_LOOP_EXIT_CODE_CONTINUOUS_TERMINATION:
489 _ModalLoopManager::GetInstance()->EndMainLoop(exitCode, false);
495 _MessageBoxPresenter::CreateButtons(void)
497 String buttonText[3];
499 switch (__pMessageBox->GetMsgBoxStyle())
501 case MSGBOX_STYLE_NONE:
505 case MSGBOX_STYLE_OK:
507 GET_STRING_CONFIG(IDS_COM_SK_OK, buttonText[0]);
510 case MSGBOX_STYLE_CANCEL:
512 GET_STRING_CONFIG(IDS_COM_SK_CANCEL, buttonText[0]);
515 case MSGBOX_STYLE_OKCANCEL:
517 GET_STRING_CONFIG(IDS_COM_SK_OK, buttonText[0]);
518 GET_STRING_CONFIG(IDS_COM_SK_CANCEL, buttonText[1]);
521 case MSGBOX_STYLE_YESNO:
523 GET_STRING_CONFIG(IDS_COM_SK_YES, buttonText[0]);
524 GET_STRING_CONFIG(IDS_COM_SK_NO, buttonText[1]);
527 case MSGBOX_STYLE_YESNOCANCEL:
529 GET_STRING_CONFIG(IDS_COM_SK_YES, buttonText[0]);
530 GET_STRING_CONFIG(IDS_COM_SK_NO, buttonText[1]);
531 GET_STRING_CONFIG(IDS_COM_SK_CANCEL, buttonText[2]);
534 case MSGBOX_STYLE_ABORTRETRYIGNORE:
536 GET_STRING_CONFIG(IDS_COM_SK_ABORT, buttonText[0]);
537 GET_STRING_CONFIG(IDS_COM_SK_RETRY, buttonText[1]);
538 GET_STRING_CONFIG(IDS_COM_SK_IGNORE, buttonText[2]);
541 case MSGBOX_STYLE_CANCELTRYCONTINUE:
543 GET_STRING_CONFIG(IDS_COM_SK_CANCEL, buttonText[0]);
544 GET_STRING_CONFIG(IDS_COM_SK_TRY, buttonText[1]);
545 GET_STRING_CONFIG(IDS_COM_BODY_CONTINUE, buttonText[2]);
548 case MSGBOX_STYLE_RETRYCANCEL:
550 GET_STRING_CONFIG(IDS_COM_SK_RETRY, buttonText[0]);
551 GET_STRING_CONFIG(IDS_COM_SK_CANCEL, buttonText[1]);
558 __pButtonListener = new (std::nothrow) _MessageBoxButtonListener();
559 SysTryReturn(NID_UI_CTRL, __pButtonListener != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
561 result r = E_SUCCESS;
563 for (int i = 0; i < __buttonNum; i++)
565 _ControlImpl* pImpl = null;
566 _Button* pButtonCore = null;
568 __pButtons[i] = new (std::nothrow) Button();
569 SysTryCatch(NID_UI_CTRL, __pButtons[i] != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
571 r = __pButtons[i]->Construct(CalculateButtonPositionAndSize(i));
572 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
574 __pButtons[i]->SetText(buttonText[i]);
575 __pButtons[i]->AddTouchEventListener(*__pButtonListener);
577 pImpl = _ControlImpl::GetInstance(*__pButtons[i]);
578 pButtonCore = dynamic_cast<_Button*>(&pImpl->GetCore());
580 if (pButtonCore != null)
582 pButtonCore->SetTouchMoveAllowance(TOUCH_MOVE_ALLOWANCE_INSENSITIVE);
589 delete __pButtonListener;
590 __pButtonListener = null;
592 for (int i = 0; i < __buttonNum; i++)
594 delete __pButtons[i];
595 __pButtons[i] = null;
602 _MessageBoxPresenter::CalculateButtonPositionAndSize(int buttonIndex)
609 int defaultWidth = 0;
612 int btnSideMargin1 = 0;
613 int btnSideMargin2 = 0;
614 int btnSideMargin3 = 0;
615 int btnTopMargin = 0;
618 int textTopMargin = 0;
621 int transTopMargin = 0;
623 GET_SHAPE_CONFIG(MESSAGEBOX::DEFAULT_WIDTH, __pMessageBox->GetOrientation(), defaultWidth);
624 GET_SHAPE_CONFIG(MESSAGEBOX::BUTTON_HEIGHT, __pMessageBox->GetOrientation(), btnHeight);
626 GET_SHAPE_CONFIG(MESSAGEBOX::BUTTON_SIDE_MARGIN_01, __pMessageBox->GetOrientation(), btnSideMargin1);
627 GET_SHAPE_CONFIG(MESSAGEBOX::BUTTON_SIDE_MARGIN_02, __pMessageBox->GetOrientation(), btnSideMargin2);
628 GET_SHAPE_CONFIG(MESSAGEBOX::BUTTON_SIDE_MARGIN_03, __pMessageBox->GetOrientation(), btnSideMargin3);
629 GET_SHAPE_CONFIG(MESSAGEBOX::BUTTON_TOP_MARGIN, __pMessageBox->GetOrientation(), btnTopMargin);
631 GET_SHAPE_CONFIG(MESSAGEBOX::BUTTON_INTERNAL_GAP, __pMessageBox->GetOrientation(), btnGap);
632 GET_SHAPE_CONFIG(MESSAGEBOX::TEXT_TOP_MRAGIN, __pMessageBox->GetOrientation(), textTopMargin);
634 GET_SHAPE_CONFIG(MESSAGEBOX::TITLE_HEIGHT, __pMessageBox->GetOrientation(), titleHeight);
635 GET_SHAPE_CONFIG(MESSAGEBOX::BG_IMAGE_TRANSPARENT_TOP_MARGIN, __pMessageBox->GetOrientation(), transTopMargin);
637 if (__pMessageBox->HasTitle() == false)
645 w = defaultWidth - (btnSideMargin1 * 2);
648 y = transTopMargin + titleHeight + (textTopMargin * 2) + __textObjHeight + btnTopMargin;
652 w = (defaultWidth - (btnSideMargin2 * 2) - btnGap) / 2;
654 x = btnSideMargin2 + (buttonIndex * (w + btnGap));
655 y = transTopMargin + titleHeight + (textTopMargin * 2) + __textObjHeight + btnTopMargin;
667 w = (defaultWidth - ((btnSideMargin3 + btnGap) * 2)) / 3;
669 x = btnSideMargin3 + (buttonIndex * (w + btnGap));
670 y = transTopMargin + titleHeight + (textTopMargin * 2) + __textObjHeight + btnTopMargin;
679 return Rectangle(x, y, w, h);
683 _MessageBoxPresenter::FindButtonAndResult(const _ControlHandle handle)
687 for (int i = 0; i < __buttonNum; i++)
689 _ControlImpl* pImpl = _ControlImpl::GetInstance(*__pButtons[i]);
690 if (pImpl->GetCore().GetHandle() == handle)
697 switch (__pMessageBox->GetMsgBoxStyle())
699 case MSGBOX_STYLE_NONE:
700 SetReturnValue(MSGBOX_RESULT_CLOSE);
703 case MSGBOX_STYLE_OK:
704 SetReturnValue(MSGBOX_RESULT_OK);
707 case MSGBOX_STYLE_CANCEL:
708 SetReturnValue(MSGBOX_RESULT_CANCEL);
711 case MSGBOX_STYLE_OKCANCEL:
715 SetReturnValue(MSGBOX_RESULT_OK);
719 SetReturnValue(MSGBOX_RESULT_CANCEL);
724 case MSGBOX_STYLE_YESNO:
728 SetReturnValue(MSGBOX_RESULT_YES);
732 SetReturnValue(MSGBOX_RESULT_NO);
737 case MSGBOX_STYLE_YESNOCANCEL:
741 SetReturnValue(MSGBOX_RESULT_YES);
745 SetReturnValue(MSGBOX_RESULT_NO);
749 SetReturnValue(MSGBOX_RESULT_CANCEL);
754 case MSGBOX_STYLE_ABORTRETRYIGNORE:
758 SetReturnValue(MSGBOX_RESULT_ABORT);
762 SetReturnValue(MSGBOX_RESULT_RETRY);
766 SetReturnValue(MSGBOX_RESULT_IGNORE);
771 case MSGBOX_STYLE_CANCELTRYCONTINUE:
775 SetReturnValue(MSGBOX_RESULT_CANCEL);
779 SetReturnValue(MSGBOX_RESULT_TRY);
783 SetReturnValue(MSGBOX_RESULT_CONTINUE);
788 case MSGBOX_STYLE_RETRYCANCEL:
792 SetReturnValue(MSGBOX_RESULT_RETRY);
796 SetReturnValue(MSGBOX_RESULT_CANCEL);
807 _MessageBoxPresenter::CalculateButtonAreaHeight(void)
811 GET_SHAPE_CONFIG(MESSAGEBOX::BUTTON_HEIGHT, __pMessageBox->GetOrientation(), btnHeight);
813 switch (__pMessageBox->GetMsgBoxStyle())
815 case MSGBOX_STYLE_NONE:
818 case MSGBOX_STYLE_OK:
820 case MSGBOX_STYLE_CANCEL:
822 case MSGBOX_STYLE_OKCANCEL:
824 case MSGBOX_STYLE_YESNO:
826 case MSGBOX_STYLE_RETRYCANCEL:
828 case MSGBOX_STYLE_YESNOCANCEL:
830 case MSGBOX_STYLE_ABORTRETRYIGNORE:
832 case MSGBOX_STYLE_CANCELTRYCONTINUE:
840 _MessageBoxPresenter::GetBodyTextHeight(void) const
842 return (__pBodyTextObject == null) ? 0 : __pBodyTextObject->GetTotalHeight();
846 _MessageBoxPresenter::GetTitleBounds(void) const
848 return __titleBounds;
852 _MessageBoxPresenter::GetTextBounds(void) const
858 _MessageBoxPresenter::SetReturnValue(MessageBoxModalResult rtn)
860 __msgboxResult = rtn;
864 _MessageBoxPresenter::GetReturnValue(void) const
866 return (int) __msgboxResult;
870 _MessageBoxPresenter::OnAttachedToMainTree(void)
872 result r = E_SUCCESS;
873 _AccessibilityElement* pTitleTextAccessibility = null;
875 if (likely(!(_AccessibilityManager::IsActivated())))
880 pTitleTextAccessibility = __pMessageBox->GetTitleTextAccessibilityElement();
881 if ((pTitleTextAccessibility != null) && (__pTextAccessibilityElement != null))
886 _AccessibilityContainer* pContainer = __pMessageBox->GetAccessibilityContainer();
887 if (pContainer != null)
890 GET_SHAPE_CONFIG(MESSAGEBOX::TITLE_HEIGHT, __pMessageBox->GetOrientation(), titleHeight);
892 if (pTitleTextAccessibility == null)
894 pTitleTextAccessibility = new (std::nothrow) _AccessibilityElement(true);
895 SysTryReturn(NID_UI_CTRL, pTitleTextAccessibility != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,"[E_OUT_OF_MEMORY] Memory allocation failed.");
897 pTitleTextAccessibility->Construct(L"MessageBoxTitleText", __titleBounds);
898 pTitleTextAccessibility->SetLabel(__pMessageBox->GetTitleText());
899 pTitleTextAccessibility->SetTrait(ACCESSIBILITY_TRAITS_TEXT_FIELD);
901 pContainer->AddElement(*pTitleTextAccessibility);
904 if (__pTextAccessibilityElement == null)
906 __pTextAccessibilityElement = new (std::nothrow) _AccessibilityElement(true);
907 SysTryReturn(NID_UI_CTRL, __pTextAccessibilityElement != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,"[E_OUT_OF_MEMORY] Memory allocation failed.");
909 __pTextAccessibilityElement->Construct(L"MessageBoxText", __textBounds);
910 __pTextAccessibilityElement->SetLabel(__pMessageBox->GetText());
911 __pTextAccessibilityElement->SetTrait(ACCESSIBILITY_TRAITS_TEXT_FIELD);
913 pContainer->AddElement(*__pTextAccessibilityElement);
916 if (__pMessageBox->GetMsgBoxStyle() != MSGBOX_STYLE_NONE)
918 for (int i = 0; i < __buttonNum; i++)
920 _ControlImpl* pImpl = null;
921 _Button* pButtonCore = null;
923 pImpl = _ControlImpl::GetInstance(*__pButtons[i]);
925 pButtonCore = dynamic_cast<_Button*>(&pImpl->GetCore());
927 SysTryReturn(NID_UI_CTRL, pButtonCore != null, r, r, "[%s] Propagating.", GetErrorMessage(r));
929 _AccessibilityContainer* pButtonContainer = pButtonCore->GetAccessibilityContainer();
930 if (pButtonContainer != null)
932 _AccessibilityElement* pButtonElement = pButtonContainer->GetChildElement(L"ButtonText");
933 if (pButtonElement != null)
935 String numberString = null;
936 numberString = Integer::ToString(i + 1);
938 String buttonName = L"MessageBoxButton";
939 buttonName.Append(numberString);
941 pButtonElement->SetName(buttonName);
945 pContainer->AddChildContainer(*pButtonContainer);
956 _MessageBoxPresenter::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
958 Point point = touchinfo.GetCurrentPosition();
960 Rectangle rect(0, 0, __pMessageBox->GetBounds().width, __pMessageBox->GetBounds().height);
962 // Touch-event's starting point is MessageBox's leftTop
963 if (rect.Contains(touchinfo.GetCurrentPosition()) == false)
965 __touchOutBounds = true;
969 __touchOutBounds = false;
972 __touchPressFlag = true;
974 if ((__pScroll != null) && (__textBounds.Contains(touchinfo.GetCurrentPosition()) == true))
976 __pScroll->SetScrollVisibility(true);
978 __scrollStart = true;
985 _MessageBoxPresenter::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
987 if (__touchOutBounds == true)
989 if (__pMessageBox->GetMsgBoxStyle() == MSGBOX_STYLE_NONE)
991 SetReturnValue(MSGBOX_RESULT_CLOSE);
992 _ModalLoopManager::GetInstance()->EndMainLoop(MSGBOX_RESULT_CLOSE, false);
996 if (__touchPressFlag == false)
998 __prevPositionY = -1;
1000 __scrollStart = false;
1003 if (__pScroll != null)
1005 __pScroll->SetScrollVisibility(false);
1012 _MessageBoxPresenter::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
1014 __touchOutBounds = false;
1016 if ((__pScroll != null) && (__scrollStart == true))
1018 int scrollAmountView = -1;
1019 int scrollAmountData = -1;
1020 int currentPosition = touchinfo.GetCurrentPosition().y;
1023 if (__prevPositionY == -1)
1025 __prevPositionY = touchinfo.GetCurrentPosition().y;
1028 int distance = __prevPositionY - currentPosition;
1030 int newFirstDspY = __pBodyTextObject->GetFirstDisplayPositionY();
1031 newFirstDspY += distance;
1033 if (newFirstDspY < 0)
1038 if (newFirstDspY > __textBounds.height)
1040 newFirstDspY = __textBounds.height;
1043 int moveLine = __pBodyTextObject->GetLineIndexAtPositionY(newFirstDspY);
1045 __pBodyTextObject->SetFirstDisplayLineIndex(moveLine);
1046 __pBodyTextObject->SetFirstDisplayPositionY(newFirstDspY);
1049 __pScroll->GetScrollRange(&scrollAmountView, &scrollAmountData);
1050 __scrollPos += distance;
1052 if (__scrollPos < 0)
1056 else if (__scrollPos > scrollAmountView)
1058 __scrollPos = scrollAmountView;
1061 __pScroll->SetScrollPosition(__scrollPos);
1063 __prevPositionY = currentPosition;
1065 __touchPressFlag = false;
1068 __pMessageBox->Show();
1076 ////////////////////////////////////////////////////////////////////////
1077 ///////////////////////////MsgBoxButtonListener/////////////////////////
1078 ////////////////////////////////////////////////////////////////////////
1080 _MessageBoxPresenter::_MessageBoxButtonListener::_MessageBoxButtonListener(void)
1082 , __buttonPressFlag(false)
1083 , __buttonReleaseState(false)
1089 _MessageBoxPresenter::_MessageBoxButtonListener::~_MessageBoxButtonListener(void)
1095 _MessageBoxPresenter::_MessageBoxButtonListener::GetClickedButtonHandle(void) const
1097 return __buttonHandle;
1101 _MessageBoxPresenter::_MessageBoxButtonListener::IsButtonClicked(void)
1103 return __buttonReleaseState;
1107 _MessageBoxPresenter::_MessageBoxButtonListener::OnTouchPressed(const Control& source, const Point& currentPosition,
1108 const TouchEventInfo& touchInfo)
1110 __buttonPressFlag = true;
1111 __buttonReleaseState = false;
1113 Point point = touchInfo.GetCurrentPosition();
1118 _MessageBoxPresenter::_MessageBoxButtonListener::OnTouchMoved(const Control& source, const Point& currentPosition,
1119 const TouchEventInfo& touchInfo)
1121 Point point = touchInfo.GetCurrentPosition();
1123 __buttonPressFlag = false;
1127 _MessageBoxPresenter::_MessageBoxButtonListener::OnTouchReleased(const Control& source, const Point& currentPosition,
1128 const TouchEventInfo& touchInfo)
1130 if (__buttonPressFlag == true)
1132 __buttonHandle = _ControlImpl::GetInstance(source)->GetCore().GetHandle();
1133 SysTryReturnVoidResult(NID_UI_CTRL, __buttonHandle.IsValid() == true, E_SYSTEM, "[E_SYSTEM] Button's Handle is invalid");
1135 __buttonPressFlag = false;
1136 __buttonReleaseState = true;
1138 _ModalLoopManager::GetInstance()->EndMainLoop(MSGBOX_BUTTON_CLICKED, false);
1145 }}} // Tizen::Ui::Controls