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_MessageBoxPresenter.cpp
20 * @brief This is the implementation file for the _MessageBoxPresenter class.
22 #include <FUiCtrlMessageBox.h>
23 #include <FBaseSysLog.h>
24 #include <FBaseErrorDefine.h>
25 #include <FGrp_BitmapImpl.h>
26 #include <FGrp_CanvasImpl.h>
27 #include <FGrp_TextTextSimple.h>
28 #include "FUi_AccessibilityContainer.h"
29 #include "FUi_AccessibilityElement.h"
31 #include "FUi_ModalLoopManager.h"
32 #include "FUi_ResourceManager.h"
33 #include "FUi_TouchManager.h"
34 #include "FUi_CoordinateSystemUtils.h"
35 #include "FUiCtrl_ButtonImpl.h"
36 #include "FUiCtrl_Button.h"
37 #include "FUiCtrl_Label.h"
38 #include "FUiCtrl_Scroll.h"
39 #include "FUiCtrl_ScrollPanel.h"
40 #include "FUiCtrl_MessageBox.h"
41 #include "FUiCtrl_MessageBoxPresenter.h"
43 using namespace Tizen::Base;
44 using namespace Tizen::Base::Runtime;
45 using namespace Tizen::Graphics;
46 using namespace Tizen::Graphics::_Text;
47 using namespace Tizen::Ui;
48 using namespace Tizen::Ui::Animations;
51 namespace Tizen { namespace Ui { namespace Controls
55 _MessageBoxPresenter::_MessageBoxPresenter(void)
57 , __pButtonListener(null)
58 , __msgboxResult(MSGBOX_RESULT_CLOSE)
59 , __pBodyTextObject(null)
60 , __textBounds(0.0f, 0.0f, 0.0f, 0.0f)
61 , __titleBgBounds(0.0f, 0.0f, 0.0f, 0.0f)
62 , __buttonBgBounds(0.0f, 0.0f, 0.0f, 0.0f)
65 , __pScrollPanel(null)
68 , __prevPositionY(-1.0f)
69 , __textObjHeight(0.0f)
70 , __touchPressFlag(false)
71 , __scrollStart(false)
72 , __btnClickFlag(false)
73 , __bodyClickFlag(false)
74 , __touchOutBounds(false)
77 for (int i = 0; i < 3; i++)
83 _MessageBoxPresenter::~_MessageBoxPresenter(void)
85 for (int i = 0; i < __buttonNum; i++)
91 delete __pButtonListener;
92 __pButtonListener = null;
94 if (__pBodyTextObject != null)
96 __pBodyTextObject->RemoveAll();
97 delete __pBodyTextObject;
98 __pBodyTextObject = null;
101 if (__pLabel != null)
103 __pScrollPanel->DetachChild(*__pLabel);
108 if (__pScrollPanel != null)
110 __pMessageBox->DetachChild(*__pScrollPanel);
111 delete __pScrollPanel;
112 __pScrollPanel = null;
115 if (__pScroll != null)
117 __pMessageBox->DetachSystemChild(*__pScroll);
124 _MessageBoxPresenter::OnChangeLayout(_ControlOrientation orientation)
126 result r = E_SUCCESS;
128 float titleTextSize = 0.0f;
129 float minTitleTextSize = 0.0f;
130 float defaultWidth = 0.0f;
131 float titleHeight = 0.0f;
132 float bottomHeight = 0.0f;
133 float maxHeight = 0.0f;
135 float textTopMargin = 0.0f;
137 float titleTopMargin = 0.0f;
138 float titleLeftMargin = 0.0f;
139 float titleRightMargin = 0.0f;
141 float transTopMargin = 0.0f;
142 float transBottomMargin = 0.0f;
143 float labelHeight = 0.0f;
144 float transLeftMargin = 0.0f;
145 float transRightMargin = 0.0f;
147 GET_SHAPE_CONFIG(POPUP::TITLE_TEXT_SIZE, orientation, titleTextSize);
148 GET_SHAPE_CONFIG(POPUP::MIN_TITLE_TEXT_SIZE, orientation, minTitleTextSize);
150 GET_SHAPE_CONFIG(MESSAGEBOX::DEFAULT_WIDTH, orientation, defaultWidth);
151 GET_SHAPE_CONFIG(MESSAGEBOX::BOTTOM_HEIGHT, orientation, bottomHeight);
152 GET_SHAPE_CONFIG(MESSAGEBOX::MAX_HEIGHT, orientation, maxHeight);
154 GET_SHAPE_CONFIG(MESSAGEBOX::TEXT_TOP_MRAGIN, orientation, textTopMargin);
156 GET_SHAPE_CONFIG(MESSAGEBOX::TITLE_TEXT_TOP_MARGIN, orientation, titleTopMargin);
157 GET_SHAPE_CONFIG(MESSAGEBOX::TITLE_TEXT_LEFT_MARGIN, orientation, titleLeftMargin);
158 GET_SHAPE_CONFIG(MESSAGEBOX::TITLE_TEXT_RIGHT_MARGIN, orientation, titleRightMargin);
160 GET_SHAPE_CONFIG(MESSAGEBOX::BG_IMAGE_TRANSPARENT_TOP_MARGIN, orientation, transTopMargin);
161 GET_SHAPE_CONFIG(MESSAGEBOX::BG_IMAGE_TRANSPARENT_BOTTOM_MARGIN, orientation, transBottomMargin);
162 GET_SHAPE_CONFIG(MESSAGEBOX::BG_IMAGE_TRANSPARENT_LEFT_MARGIN, orientation, transLeftMargin);
163 GET_SHAPE_CONFIG(MESSAGEBOX::BG_IMAGE_TRANSPARENT_RIGHT_MARGIN, orientation, transRightMargin);
165 __textBounds.width = defaultWidth - GetLeftRightLabelMargin();
166 __titleBgBounds.width = defaultWidth - (transLeftMargin + transRightMargin);
167 __buttonBgBounds.width = defaultWidth - (transLeftMargin + transRightMargin);
170 if (__pMessageBox->HasTitle() == true)
172 GET_SHAPE_CONFIG(MESSAGEBOX::TITLE_HEIGHT, orientation, titleHeight);
174 _titleBounds.width = __textBounds.width;
175 _pTitleTextObject->SetBounds(_titleBounds);
177 r = CalculateTitleTextSize(titleTextSize, minTitleTextSize);
178 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
180 _titleBounds.height = titleHeight - titleTopMargin;
184 __pBodyTextObject->SetBounds(__textBounds);
186 __pBodyTextObject->Compose();
189 __pScrollPanel->SetBounds(__textBounds);
191 labelHeight = __pBodyTextObject->GetTotalHeightF();
193 if (labelHeight < __textObjHeight)
195 __pLabel->SetBounds(FloatRectangle(0.0f, (__textObjHeight - labelHeight)/2.0f, __textBounds.width, labelHeight));
199 __pLabel->SetBounds(FloatRectangle(0.0f, 0.0f, __textBounds.width, labelHeight));
202 for (int i = 0; i < __buttonNum; i++)
204 r = __pButtons[i]->SetBounds(CalculateButtonPositionAndSize(i));
205 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
212 _MessageBoxPresenter::Initialize(_MessageBox& msgbox)
214 result r = E_SUCCESS;
216 float titleTextSize = 0.0f;
217 float bodyTextSize = 0.0f;
219 float defaultWidth = 0.0f;
220 float titleHeight = 0.0f;
221 float bottomHeight = 0.0f;
222 float maxHeight = 0.0f;
224 float textTopMargin = 0.0f;
225 float textTopMarginNoButton = 0.0f;
226 float textLeftMargin = 0.0f;
228 float titleTopMargin = 0.0f;
229 float titleLeftMargin = 0.0f;
230 float titleRightMargin = 0.0f;
232 float transTopMargin = 0.0f;
233 float transBottomMargin = 0.0f;
234 float transLeftMargin = 0.0f;
235 float transRightMargin = 0.0f;
236 float labelHeight = 0.0f;
238 _ControlOrientation orientation;
240 __pMessageBox = &msgbox;
242 orientation = __pMessageBox->GetOrientation();
244 GET_SHAPE_CONFIG(MESSAGEBOX::TITLE_TEXT_SIZE, orientation, titleTextSize);
245 GET_SHAPE_CONFIG(MESSAGEBOX::TEXT_SIZE, orientation, bodyTextSize);
246 GET_SHAPE_CONFIG(MESSAGEBOX::TEXT_HEIGHT, orientation, __textObjHeight);
248 GET_SHAPE_CONFIG(MESSAGEBOX::DEFAULT_WIDTH, orientation, defaultWidth);
249 GET_SHAPE_CONFIG(MESSAGEBOX::TITLE_HEIGHT, orientation, titleHeight);
250 GET_SHAPE_CONFIG(MESSAGEBOX::BOTTOM_HEIGHT, orientation, bottomHeight);
251 GET_SHAPE_CONFIG(MESSAGEBOX::MAX_HEIGHT, orientation, maxHeight);
253 GET_SHAPE_CONFIG(MESSAGEBOX::TEXT_TOP_MRAGIN, orientation, textTopMargin);
254 GET_SHAPE_CONFIG(MESSAGEBOX::TEXT_TOP_MRAGIN_NO_BUTTON, orientation, textTopMarginNoButton);
255 GET_SHAPE_CONFIG(MESSAGEBOX::TEXT_LEFT_MARGIN, orientation, textLeftMargin);
257 GET_SHAPE_CONFIG(MESSAGEBOX::TITLE_TEXT_TOP_MARGIN, orientation, titleTopMargin);
258 GET_SHAPE_CONFIG(MESSAGEBOX::TITLE_TEXT_LEFT_MARGIN, orientation, titleLeftMargin);
259 GET_SHAPE_CONFIG(MESSAGEBOX::TITLE_TEXT_RIGHT_MARGIN, orientation, titleRightMargin);
261 GET_SHAPE_CONFIG(MESSAGEBOX::BG_IMAGE_TRANSPARENT_TOP_MARGIN, orientation, transTopMargin);
262 GET_SHAPE_CONFIG(MESSAGEBOX::BG_IMAGE_TRANSPARENT_BOTTOM_MARGIN, orientation, transBottomMargin);
263 GET_SHAPE_CONFIG(MESSAGEBOX::BG_IMAGE_TRANSPARENT_LEFT_MARGIN, orientation, transLeftMargin);
264 GET_SHAPE_CONFIG(MESSAGEBOX::BG_IMAGE_TRANSPARENT_RIGHT_MARGIN, orientation, transRightMargin);
266 __titleBgBounds= FloatRectangle(transLeftMargin, transTopMargin, _CoordinateSystemUtils::ConvertToFloat(defaultWidth) - (2 * transLeftMargin), titleHeight);
270 if (__pMessageBox->HasTitle() == true)
272 _pTitleTextObject = new (std::nothrow) TextObject();
273 SysTryReturn(NID_UI_CTRL, _pTitleTextObject != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Unable to create TitleTextObject.");
275 r = _pTitleTextObject->Construct();
276 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
278 FloatRectangle bounds = FloatRectangle(titleLeftMargin + transLeftMargin,
279 titleTopMargin + transTopMargin,
280 defaultWidth - (titleLeftMargin + titleRightMargin + transLeftMargin + transRightMargin),
281 titleHeight - titleTopMargin);
283 labelHeight = GetLabelHeight(_pTitleTextObject, const_cast <wchar_t*>(__pMessageBox->GetTitleText().GetPointer()),
284 __pMessageBox->GetTitleText().GetLength(), titleTextSize, bounds, true);
287 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
289 _titleBounds = FloatRectangle(titleLeftMargin + transLeftMargin,
290 __titleBgBounds.y + (__titleBgBounds.height - labelHeight) / 2,
291 defaultWidth - (titleLeftMargin + titleRightMargin + transLeftMargin + transRightMargin),
292 titleHeight - titleTopMargin);
300 __textBounds.SetBounds(textLeftMargin + transLeftMargin,
301 titleHeight + textTopMargin + transTopMargin,
302 defaultWidth - GetLeftRightLabelMargin(),
306 if ((__pMessageBox->HasTitle() == false) && (__pMessageBox->GetMsgBoxStyle() == MSGBOX_STYLE_NONE))
308 __textBounds.y = transTopMargin + textTopMarginNoButton;
311 __pLabel = _Label::CreateLabelN();
312 SysTryCatch(NID_UI_CTRL, __pLabel != null, , E_OUT_OF_MEMORY, "[E_SYSTEM] Failed to create the scroll.");
314 __pBodyTextObject = new (std::nothrow) TextObject();
315 SysTryCatch(NID_UI_CTRL, __pBodyTextObject != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
317 r = __pBodyTextObject->Construct();
318 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
320 labelHeight = GetLabelHeight(__pBodyTextObject, const_cast <wchar_t*>(__pMessageBox->GetText().GetPointer()),
321 __pMessageBox->GetText().GetLength(), bodyTextSize, __textBounds, false);
324 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
326 if (__pMessageBox->GetText().GetLength() > 0)
328 __textObjHeight = __pBodyTextObject->GetLineHeightAtF(0) * 3.0;
329 __textBounds.height = __textObjHeight;
332 if (labelHeight < __textObjHeight)
334 __pLabel->SetBounds(FloatRectangle(0.0f, (__textObjHeight - labelHeight)/2.0f, __textBounds.width, labelHeight));
338 __pLabel->SetBounds(FloatRectangle(0.0f, 0.0f, __textBounds.width, labelHeight));
342 __pLabel->SetText(__pMessageBox->GetText());
343 __pLabel->SetTextConfig(bodyTextSize, LABEL_TEXT_STYLE_NORMAL);
344 __pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
345 __pLabel->SetMargin(0.0f, 0.0f, 0.0f, 0.0f);
347 __pScrollPanel = _ScrollPanel::CreateScrollPanelN(__textBounds, SCROLL_PANEL_SCROLL_DIRECTION_VERTICAL, true);
349 SysTryCatch(NID_UI_CTRL, __pScrollPanel != null, , E_OUT_OF_MEMORY, "[E_SYSTEM] Failed to create the scroll.");
350 __pScrollPanel->SetBounds(__textBounds);
351 __pScrollPanel->AttachChild(*__pLabel);
352 __pScrollPanel->SetFocusable(false);
353 __pMessageBox->AttachChild(*__pScrollPanel);
355 __buttonBgBounds = FloatRectangle(transLeftMargin, __pMessageBox->GetTotalHeight() - bottomHeight - transBottomMargin, _CoordinateSystemUtils::ConvertToFloat(defaultWidth)- (transLeftMargin + transRightMargin), bottomHeight);
358 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
363 delete _pTitleTextObject;
364 _pTitleTextObject = null;
366 delete __pBodyTextObject;
367 __pBodyTextObject = null;
374 _MessageBoxPresenter::GetLabelHeight(TextObject* textObject, wchar_t* text, int length, float bodyTextSize, FloatRectangle bounds, bool isTitle)
376 TextSimple* pSimpleTextForBodyText = null;
377 result r = E_SUCCESS;
380 pSimpleTextForBodyText = new (std::nothrow) TextSimple(text, length, TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
381 SysTryCatch(NID_UI_CTRL, pSimpleTextForBodyText != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
383 textObject->AppendElement(*pSimpleTextForBodyText);
384 textObject->SetWrap(TEXT_OBJECT_WRAP_TYPE_WORD);
385 textObject->SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
386 textObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_LEFT);
387 textObject->SetBounds(bounds);
391 float minTitleTextSize = 0.0f;
393 GET_SHAPE_CONFIG(MESSAGEBOX::MIN_TITLE_TEXT_SIZE, __pMessageBox->GetOrientation(), minTitleTextSize);
395 r = CalculateTitleTextSize(bodyTextSize, minTitleTextSize);
396 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
400 r = SetFontInfo(FONT_STYLE_PLAIN, bodyTextSize);
401 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set font.", GetErrorMessage(r));
403 textObject->SetFont(_pFont, 0, textObject->GetTextLength());
405 textObject->Compose();
410 return textObject->GetTotalHeightF();
417 _MessageBoxPresenter::GetLeftRightLabelMargin(void)
419 float textLeftMargin = 0.0f;
420 float textRightMargin = 0.0f;
421 float transLeftMargin = 0.0f;
422 float transRightMargin = 0.0f;
424 _ControlOrientation orientation = __pMessageBox->GetOrientation();
426 GET_SHAPE_CONFIG(MESSAGEBOX::TEXT_LEFT_MARGIN, orientation, textLeftMargin);
427 GET_SHAPE_CONFIG(MESSAGEBOX::TEXT_RIGHT_MARGIN, orientation, textRightMargin);
428 GET_SHAPE_CONFIG(MESSAGEBOX::BG_IMAGE_TRANSPARENT_LEFT_MARGIN, orientation, transLeftMargin);
429 GET_SHAPE_CONFIG(MESSAGEBOX::BG_IMAGE_TRANSPARENT_RIGHT_MARGIN, orientation, transRightMargin);
431 return textLeftMargin + textRightMargin + transLeftMargin + transRightMargin;
435 _MessageBoxPresenter::Draw(void)
437 result r = E_SUCCESS;
439 float defaultWidth = 0.0f;
440 float textSize = 0.0f;
442 bool isCustomBitmap = false;
444 _ControlOrientation orientation;
446 orientation = __pMessageBox->GetOrientation();
448 GET_SHAPE_CONFIG(MESSAGEBOX::DEFAULT_WIDTH, orientation, defaultWidth);
449 GET_SHAPE_CONFIG(MESSAGEBOX::TEXT_SIZE, orientation, textSize);
451 Canvas* pCanvas = __pMessageBox->GetCanvasN();
452 SysTryReturnVoidResult(NID_UI_CTRL, (pCanvas != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Unable to create canvas.");
454 pCanvas->SetBackgroundColor(Color(0x00000000));
457 float totalH = __pMessageBox->GetTotalHeight();
459 FloatRectangle bgBounds(0.0f, 0.0f, _CoordinateSystemUtils::ConvertToFloat(defaultWidth), totalH);
461 const Bitmap* pBackgroundBitmap = __pMessageBox->GetBackgroundBitmap();
462 const Bitmap* pOutlineBitmap = __pMessageBox->GetOutlineBitmap();
463 const Bitmap* pButtonBitmap = __pMessageBox->GetButtonBackgroundBitmap();
464 const Bitmap* pButtonEffectBitmap = __pMessageBox->GetButtonBackgroundEffectBitmap();
465 const Bitmap* pTitleBitmap = __pMessageBox->GetTitleBackgroundBitmap();
466 const Bitmap* pTitleEffectBitmap = __pMessageBox->GetTitleBackgroundEffectBitmap();
468 isCustomBitmap = IS_CUSTOM_BITMAP(MESSAGEBOX::BG_NORMAL);
470 if (pBackgroundBitmap != null)
472 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pBackgroundBitmap))
474 pCanvas->DrawNinePatchedBitmap(bgBounds, *pBackgroundBitmap);
478 pCanvas->DrawBitmap(bgBounds, *pBackgroundBitmap);
483 if (!isCustomBitmap && pOutlineBitmap != null)
485 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pOutlineBitmap))
487 pCanvas->DrawNinePatchedBitmap(bgBounds, *pOutlineBitmap);
491 pCanvas->DrawBitmap(bgBounds, *pOutlineBitmap);
496 if(pButtonBitmap != null)
498 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pButtonBitmap))
500 pCanvas->DrawNinePatchedBitmap(__buttonBgBounds, *pButtonBitmap);
504 pCanvas->DrawBitmap(__buttonBgBounds, *pButtonBitmap);
507 //DrawEffectButtonBitmap
508 if (pButtonEffectBitmap != null)
510 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pButtonEffectBitmap))
512 pCanvas->DrawNinePatchedBitmap(__buttonBgBounds, *pButtonEffectBitmap);
516 pCanvas->DrawBitmap(__buttonBgBounds, *pButtonEffectBitmap);
521 if (_pTitleTextObject != null)
524 if(pTitleBitmap != null)
526 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pTitleBitmap))
528 pCanvas->DrawNinePatchedBitmap(__titleBgBounds, *pTitleBitmap);
532 pCanvas->DrawBitmap(__titleBgBounds, *pTitleBitmap);
535 //DrawEffectTitleBitmap
536 if (pTitleEffectBitmap != null)
538 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pTitleEffectBitmap))
540 pCanvas->DrawNinePatchedBitmap(__titleBgBounds, *pTitleEffectBitmap);
544 pCanvas->DrawBitmap(__titleBgBounds, *pTitleEffectBitmap);
547 r = SetFontInfo(FONT_STYLE_PLAIN, _titleTextSize);
548 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
550 _pTitleTextObject->SetFont(_pFont, 0, _pTitleTextObject->GetTextLength());
551 _pTitleTextObject->SetForegroundColor(__pMessageBox->GetTitleTextColor(), 0, _pTitleTextObject->GetTextLength());
552 _pTitleTextObject->SetBounds(_titleBounds);
553 _pTitleTextObject->Draw(*_CanvasImpl::GetInstance(*pCanvas));
556 __pLabel->SetTextColor(__pMessageBox->GetTextColor());
565 _MessageBoxPresenter::ShowAndWait(int& modalResult)
567 result r = E_SUCCESS;
569 r = __pMessageBox->Open();
571 __pMessageBox->SetTouchCapture(false, false);
575 __pMessageBox->ReleaseTouchCapture();
577 __pMessageBox->Close();
579 modalResult = GetReturnValue();
585 _MessageBoxPresenter::ProcessEvent(void)
587 _ControlHandle handle;
589 _TouchManager* pTouchManager = _TouchManager::GetInstance();
592 _Control* pControl = pTouchManager->GetTouchControlSource();
595 pControl->SetEventEnableState(false);
599 if (__pMessageBox->GetMsgBoxStyle() == MSGBOX_STYLE_NONE)
603 else if (__pButtonListener != null)
605 __pButtonListener->SetBeginModal(true);
608 _ModalLoopManager::GetInstance()->BeginMainLoop(__pMessageBox->GetTimeout(), MSGBOX_RESULT_CLOSE);
610 int exitCode = _ModalLoopManager::GetInstance()->GetLastExitCode();
613 case MSGBOX_BUTTON_CLICKED:
614 if (__pButtonListener != null && __pButtonListener->IsButtonClicked())
616 handle = __pButtonListener->GetClickedButtonHandle();
617 FindButtonAndResult(handle);
620 case MSGBOX_BUTTON_CLOSE:
621 SetReturnValue(MSGBOX_RESULT_CLOSE);
624 case MSGBOX_BUTTON_CANCEL:
625 SetReturnValue(MSGBOX_RESULT_CANCEL);
629 case _ModalLoopManager::MODAL_LOOP_EXIT_CODE_APP_TERMINATION:
630 case _ModalLoopManager::MODAL_LOOP_EXIT_CODE_CONTINUOUS_TERMINATION:
631 _ModalLoopManager::GetInstance()->EndMainLoop(exitCode, false);
632 __beginModal = false;
636 if (__pMessageBox->GetMsgBoxStyle() == MSGBOX_STYLE_NONE)
638 __beginModal = false;
640 else if (__pButtonListener != null)
642 __pButtonListener->SetBeginModal(false);
647 _MessageBoxPresenter::GetButtonString(void)
649 switch (__pMessageBox->GetMsgBoxStyle())
651 case MSGBOX_STYLE_NONE:
655 case MSGBOX_STYLE_OK:
657 GET_STRING_CONFIG(IDS_TPLATFORM_BUTTON_OK, __buttonText[0]);
660 case MSGBOX_STYLE_CANCEL:
662 GET_STRING_CONFIG(IDS_TPLATFORM_BUTTON_CANCEL_ABB, __buttonText[0]);
665 case MSGBOX_STYLE_OKCANCEL:
667 GET_STRING_CONFIG(IDS_TPLATFORM_BUTTON_OK, __buttonText[1]);
668 GET_STRING_CONFIG(IDS_TPLATFORM_BUTTON_CANCEL_ABB, __buttonText[0]);
671 case MSGBOX_STYLE_YESNO:
673 GET_STRING_CONFIG(IDS_TPLATFORM_BUTTON_YES, __buttonText[1]);
674 GET_STRING_CONFIG(IDS_TPLATFORM_BUTTON_NO, __buttonText[0]);
677 case MSGBOX_STYLE_YESNOCANCEL:
679 GET_STRING_CONFIG(IDS_TPLATFORM_BUTTON_YES, __buttonText[2]);
680 GET_STRING_CONFIG(IDS_TPLATFORM_BUTTON_NO, __buttonText[1]);
681 GET_STRING_CONFIG(IDS_TPLATFORM_BUTTON_CANCEL_ABB, __buttonText[0]);
684 case MSGBOX_STYLE_ABORTRETRYIGNORE:
686 GET_STRING_CONFIG(IDS_TPLATFORM_BUTTON_ABORT, __buttonText[0]);
687 GET_STRING_CONFIG(IDS_TPLATFORM_BUTTON_RETRY, __buttonText[1]);
688 GET_STRING_CONFIG(IDS_TPLATFORM_BUTTON_IGNORE, __buttonText[2]);
691 case MSGBOX_STYLE_CANCELTRYCONTINUE:
693 GET_STRING_CONFIG(IDS_TPLATFORM_BUTTON_CANCEL_ABB, __buttonText[0]);
694 GET_STRING_CONFIG(IDS_TPLATFORM_BUTTON_TRY, __buttonText[1]);
695 GET_STRING_CONFIG(IDS_TPLATFORM_BUTTON_CONTINUE_ABB, __buttonText[2]);
698 case MSGBOX_STYLE_RETRYCANCEL:
700 GET_STRING_CONFIG(IDS_TPLATFORM_BUTTON_RETRY, __buttonText[1]);
701 GET_STRING_CONFIG(IDS_TPLATFORM_BUTTON_CANCEL_ABB, __buttonText[0]);
710 _MessageBoxPresenter::UpdateButtonString(void)
714 for (int i = 0; i < __buttonNum; i++)
716 __pButtons[i]->SetText(__buttonText[i]);
721 _MessageBoxPresenter::CreateButtons(void)
723 result r = E_SUCCESS;
726 Color buttonColorNormal(0x00000000);
727 Color buttonColorPressed(0x00000000);
728 Color buttonColorDisabled(0x00000000);
729 Color buttonColorHighlighted(0x00000000);
730 Color buttonTextNormal(0x00000000);
731 Color buttonTextPressed(0x00000000);
732 Color buttonTextDisabled(0x00000000);
733 Color buttonTextHighlighted(0x00000000);
734 bool isCustomBitmap = false;
737 Bitmap* pButtonBgNormal = null;
738 Bitmap* pButtonBgPressed = null;
739 Bitmap* pButtonBgDisabled = null;
740 Bitmap* pButtonBgHighlighted = null;
742 Bitmap* pComposedButtonBgNormal = null;
743 Bitmap* pComposedButtonBgPressed = null;
744 Bitmap* pComposedButtonBgDisabled = null;
745 Bitmap* pComposedButtonBgHighlighted = null;
747 Bitmap* pButtonNormalEffect = null;
748 Bitmap* pButtonPressedEffect = null;
749 Bitmap* pButtonDisabledEffect = null;
751 GET_COLOR_CONFIG(MESSAGEBOX::BOTTOM_BUTTON_BG_NORMAL, buttonColorNormal);
752 GET_COLOR_CONFIG(MESSAGEBOX::BOTTOM_BUTTON_BG_PRESSED, buttonColorPressed);
753 GET_COLOR_CONFIG(MESSAGEBOX::BOTTOM_BUTTON_BG_DISABLED, buttonColorDisabled);
754 GET_COLOR_CONFIG(MESSAGEBOX::BOTTOM_BUTTON_BG_HIGHLIGHTED, buttonColorHighlighted);
756 GET_COLOR_CONFIG(MESSAGEBOX::BOTTOM_BUTTON_TEXT_NORMAL, buttonTextNormal);
757 GET_COLOR_CONFIG(MESSAGEBOX::BOTTOM_BUTTON_TEXT_PRESSED, buttonTextPressed);
758 GET_COLOR_CONFIG(MESSAGEBOX::BOTTOM_BUTTON_TEXT_DISABLED, buttonTextDisabled);
759 GET_COLOR_CONFIG(MESSAGEBOX::BOTTOM_BUTTON_TEXT_HIGHLIGHTED, buttonTextHighlighted);
761 GET_BITMAP_CONFIG_N(MESSAGEBOX::BOTTOM_BUTTON_BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, pButtonBgNormal);
763 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating. Failed to load Bottom button normal Image.", GetErrorMessage(r));
765 isCustomBitmap = IS_CUSTOM_BITMAP(MESSAGEBOX::BOTTOM_BUTTON_BG_NORMAL);
769 GET_BITMAP_CONFIG_N(MESSAGEBOX::BOTTOM_BUTTON_NORMAL_EFFECT, BITMAP_PIXEL_FORMAT_ARGB8888, pButtonNormalEffect);
771 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating. Failed to load Bottom button normal effect Image.", GetErrorMessage(r));
774 GET_BITMAP_CONFIG_N(MESSAGEBOX::BOTTOM_BUTTON_BG_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, pButtonBgPressed);
776 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating. Failed to load Bottom button pressed Image.", GetErrorMessage(r));
778 isCustomBitmap = IS_CUSTOM_BITMAP(MESSAGEBOX::BOTTOM_BUTTON_BG_PRESSED);
782 GET_BITMAP_CONFIG_N(MESSAGEBOX::BOTTOM_BUTTON_PRESSED_EFFECT, BITMAP_PIXEL_FORMAT_ARGB8888, pButtonPressedEffect);
784 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating. Failed to load Bottom button pressed effect Image.", GetErrorMessage(r));
787 GET_BITMAP_CONFIG_N(MESSAGEBOX::BOTTOM_BUTTON_BG_DISABLED, BITMAP_PIXEL_FORMAT_ARGB8888, pButtonBgDisabled);
789 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating. Failed to load Bottom button disabled Image.", GetErrorMessage(r));
791 isCustomBitmap = IS_CUSTOM_BITMAP(MESSAGEBOX::BOTTOM_BUTTON_BG_DISABLED);
795 GET_BITMAP_CONFIG_N(MESSAGEBOX::BOTTOM_BUTTON_DISABLED_EFFECT, BITMAP_PIXEL_FORMAT_ARGB8888, pButtonDisabledEffect);
797 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating. Failed to load Bottom button disabled effect Image.", GetErrorMessage(r));
800 GET_BITMAP_CONFIG_N(MESSAGEBOX::BOTTOM_BUTTON_BG_HIGHLIGHTED, BITMAP_PIXEL_FORMAT_ARGB8888, pButtonBgHighlighted);
802 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating. Failed to load Bottom button highlighted Image.", GetErrorMessage(r));
804 pComposedButtonBgNormal = _BitmapImpl::GetColorReplacedBitmapN(*pButtonBgNormal, Color::GetColor(COLOR_ID_MAGENTA), buttonColorNormal);
806 SysTryCatch(NID_UI_CTRL, (pComposedButtonBgNormal != null), , r, "[%s] Propagating.", GetErrorMessage(r));
808 pComposedButtonBgPressed = _BitmapImpl::GetColorReplacedBitmapN(*pButtonBgPressed, Color::GetColor(COLOR_ID_MAGENTA), buttonColorPressed);
810 SysTryCatch(NID_UI_CTRL, (pComposedButtonBgPressed != null), , r, "[%s] Propagating.", GetErrorMessage(r));
812 pComposedButtonBgDisabled = _BitmapImpl::GetColorReplacedBitmapN(*pButtonBgDisabled, Color::GetColor(COLOR_ID_MAGENTA), buttonColorDisabled);
814 SysTryCatch(NID_UI_CTRL, (pComposedButtonBgDisabled != null), , r, "[%s] Propagating.", GetErrorMessage(r));
816 pComposedButtonBgHighlighted = _BitmapImpl::GetColorReplacedBitmapN(*pButtonBgHighlighted, Color::GetColor(COLOR_ID_MAGENTA), buttonColorHighlighted);
818 SysTryCatch(NID_UI_CTRL, (pComposedButtonBgHighlighted != null), , r, "[%s] Propagating.", GetErrorMessage(r));
820 __pButtonListener = new (std::nothrow) _MessageBoxButtonListener();
821 SysTryCatch(NID_UI_CTRL, __pButtonListener != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
823 for (int i = 0; i < __buttonNum; i++)
825 _ControlImpl* pImpl = null;
826 _Button* pButtonCore = null;
828 __pButtons[i] = new (std::nothrow) Button();
829 SysTryCatch(NID_UI_CTRL, __pButtons[i] != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
831 r = __pButtons[i]->Construct(CalculateButtonPositionAndSize(i));
832 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
834 __pButtons[i]->SetText(__buttonText[i]);
835 __pButtons[i]->AddTouchEventListener(*__pButtonListener);
836 __pButtons[i]->AddKeyEventListener(*__pButtonListener);
837 __pButtons[i]->SetNormalBackgroundBitmap(*pComposedButtonBgNormal);
838 __pButtons[i]->SetPressedBackgroundBitmap(*pComposedButtonBgPressed);
839 __pButtons[i]->SetDisabledBackgroundBitmap(*pComposedButtonBgDisabled);
840 __pButtons[i]->SetHighlightedBackgroundBitmap(*pComposedButtonBgHighlighted);
841 __pButtons[i]->SetTextColor(buttonTextNormal);
842 __pButtons[i]->SetPressedTextColor(buttonTextPressed);
843 __pButtons[i]->SetDisabledTextColor(buttonTextDisabled);
844 __pButtons[i]->SetHighlightedTextColor(buttonTextHighlighted);
846 pImpl = _ControlImpl::GetInstance(*__pButtons[i]);
847 pButtonCore = dynamic_cast<_Button*>(&pImpl->GetCore());
849 if (pButtonCore != null)
851 pButtonCore->SetTouchPressThreshold(0.16);
852 __pMessageBox->AttachChild(*pButtonCore);
854 if (pButtonNormalEffect != null)
856 pButtonCore->SetBackgroundEffectBitmap(_BUTTON_STATUS_NORMAL, *pButtonNormalEffect);
859 if (pButtonPressedEffect != null)
861 pButtonCore->SetBackgroundEffectBitmap(_BUTTON_STATUS_PRESSED, *pButtonPressedEffect);
864 if(pButtonDisabledEffect != null)
866 pButtonCore->SetBackgroundEffectBitmap(_BUTTON_STATUS_DISABLED, *pButtonDisabledEffect);
872 __pButtons[i-1]->SetNextFocus(__pButtons[i]);
873 __pButtons[i]->SetPreviousFocus(__pButtons[i-1]);
878 delete pButtonBgNormal;
879 pButtonBgNormal = null;
881 delete pButtonBgPressed;
882 pButtonBgPressed = null;
884 delete pButtonBgDisabled;
885 pButtonBgDisabled = null;
887 delete pButtonBgHighlighted;
888 pButtonBgHighlighted = null;
890 delete pComposedButtonBgNormal;
891 pComposedButtonBgNormal = null;
893 delete pComposedButtonBgPressed;
894 pComposedButtonBgPressed = null;
896 delete pComposedButtonBgDisabled;
897 pComposedButtonBgDisabled = null;
899 delete pComposedButtonBgHighlighted;
900 pComposedButtonBgHighlighted = null;
902 delete pButtonNormalEffect;
903 pButtonNormalEffect = null;
905 delete pButtonPressedEffect;
906 pButtonNormalEffect = null;
908 delete pButtonDisabledEffect;
909 pButtonNormalEffect = null;
915 delete pButtonBgNormal;
916 pButtonBgNormal = null;
918 delete pButtonBgPressed;
919 pButtonBgPressed = null;
921 delete pButtonBgDisabled;
922 pButtonBgDisabled = null;
924 delete pButtonBgHighlighted;
925 pButtonBgHighlighted = null;
927 delete pComposedButtonBgNormal;
928 pComposedButtonBgNormal = null;
930 delete pComposedButtonBgPressed;
931 pComposedButtonBgPressed = null;
933 delete pComposedButtonBgDisabled;
934 pComposedButtonBgDisabled = null;
936 delete pComposedButtonBgHighlighted;
937 pComposedButtonBgHighlighted = null;
939 delete pButtonNormalEffect;
940 pButtonNormalEffect = null;
942 delete pButtonPressedEffect;
943 pButtonNormalEffect = null;
945 delete pButtonDisabledEffect;
946 pButtonNormalEffect = null;
948 delete __pButtonListener;
949 __pButtonListener = null;
951 for (int i = 0; i < __buttonNum; i++)
953 delete __pButtons[i];
954 __pButtons[i] = null;
960 _MessageBoxPresenter::CalculateButtonPositionAndSize(int buttonIndex)
967 float defaultWidth = 0.0f;
968 float btnHeight = 0.0f;
970 float btnSideMargin1 = 0.0f;
971 float btnSideMargin2 = 0.0f;
972 float btnSideMargin3 = 0.0f;
973 float btnTopMargin = 0.0f;
976 float textTopMargin = 0.0f;
978 float titleHeight = 0.0f;
979 float transTopMargin = 0.0f;
981 _ControlOrientation orientation;
982 orientation = __pMessageBox->GetOrientation();
983 GET_SHAPE_CONFIG(MESSAGEBOX::DEFAULT_WIDTH, orientation, defaultWidth);
984 GET_SHAPE_CONFIG(MESSAGEBOX::BUTTON_HEIGHT, orientation, btnHeight);
986 GET_SHAPE_CONFIG(MESSAGEBOX::BUTTON_SIDE_MARGIN_01, orientation, btnSideMargin1);
987 GET_SHAPE_CONFIG(MESSAGEBOX::BUTTON_SIDE_MARGIN_02, orientation, btnSideMargin2);
988 GET_SHAPE_CONFIG(MESSAGEBOX::BUTTON_SIDE_MARGIN_03, orientation, btnSideMargin3);
989 GET_SHAPE_CONFIG(MESSAGEBOX::BUTTON_TOP_MARGIN, orientation, btnTopMargin);
991 GET_SHAPE_CONFIG(MESSAGEBOX::BUTTON_INTERNAL_GAP, orientation, btnGap);
992 GET_SHAPE_CONFIG(MESSAGEBOX::TEXT_TOP_MRAGIN, orientation, textTopMargin);
994 GET_SHAPE_CONFIG(MESSAGEBOX::TITLE_HEIGHT, orientation, titleHeight);
995 GET_SHAPE_CONFIG(MESSAGEBOX::BG_IMAGE_TRANSPARENT_TOP_MARGIN, orientation, transTopMargin);
997 if (__pMessageBox->HasTitle() == false)
1002 switch (__buttonNum)
1005 w = defaultWidth - (btnSideMargin1 * 2.0f);
1011 w = (defaultWidth - (btnSideMargin2 * 2.0f) - btnGap) / 2.0f;
1013 x = btnSideMargin2 + (buttonIndex * (w + btnGap));
1018 switch (buttonIndex)
1025 w = (defaultWidth - ((btnSideMargin3 + btnGap) * 2.0f)) / 3.0f;
1027 x = btnSideMargin3 + (buttonIndex * (w + btnGap));
1035 y = __buttonBgBounds.y + (__buttonBgBounds.height - h) / 2;
1036 return FloatRectangle(x, y, w, h);
1040 _MessageBoxPresenter::FindButtonAndResult(const _ControlHandle handle)
1044 for (int i = 0; i < __buttonNum; i++)
1046 _ControlImpl* pImpl = _ControlImpl::GetInstance(*__pButtons[i]);
1047 if (pImpl->GetCore().GetHandle() == handle)
1054 switch (__pMessageBox->GetMsgBoxStyle())
1056 case MSGBOX_STYLE_NONE:
1057 SetReturnValue(MSGBOX_RESULT_CLOSE);
1060 case MSGBOX_STYLE_OK:
1061 SetReturnValue(MSGBOX_RESULT_OK);
1064 case MSGBOX_STYLE_CANCEL:
1065 SetReturnValue(MSGBOX_RESULT_CANCEL);
1068 case MSGBOX_STYLE_OKCANCEL:
1072 SetReturnValue(MSGBOX_RESULT_CANCEL);
1076 SetReturnValue(MSGBOX_RESULT_OK);
1081 case MSGBOX_STYLE_YESNO:
1085 SetReturnValue(MSGBOX_RESULT_NO);
1089 SetReturnValue(MSGBOX_RESULT_YES);
1094 case MSGBOX_STYLE_YESNOCANCEL:
1098 SetReturnValue(MSGBOX_RESULT_CANCEL);
1102 SetReturnValue(MSGBOX_RESULT_NO);
1106 SetReturnValue(MSGBOX_RESULT_YES);
1111 case MSGBOX_STYLE_ABORTRETRYIGNORE:
1115 SetReturnValue(MSGBOX_RESULT_ABORT);
1119 SetReturnValue(MSGBOX_RESULT_RETRY);
1123 SetReturnValue(MSGBOX_RESULT_IGNORE);
1128 case MSGBOX_STYLE_CANCELTRYCONTINUE:
1132 SetReturnValue(MSGBOX_RESULT_CANCEL);
1136 SetReturnValue(MSGBOX_RESULT_TRY);
1140 SetReturnValue(MSGBOX_RESULT_CONTINUE);
1145 case MSGBOX_STYLE_RETRYCANCEL:
1149 SetReturnValue(MSGBOX_RESULT_CANCEL);
1153 SetReturnValue(MSGBOX_RESULT_RETRY);
1164 _MessageBoxPresenter::CalculateButtonAreaHeight(void)
1166 float btnHeight = 0.0f;
1168 GET_SHAPE_CONFIG(MESSAGEBOX::BUTTON_HEIGHT, __pMessageBox->GetOrientation(), btnHeight);
1170 switch (__pMessageBox->GetMsgBoxStyle())
1172 case MSGBOX_STYLE_NONE:
1175 case MSGBOX_STYLE_OK:
1177 case MSGBOX_STYLE_CANCEL:
1179 case MSGBOX_STYLE_OKCANCEL:
1181 case MSGBOX_STYLE_YESNO:
1183 case MSGBOX_STYLE_RETRYCANCEL:
1185 case MSGBOX_STYLE_YESNOCANCEL:
1187 case MSGBOX_STYLE_ABORTRETRYIGNORE:
1189 case MSGBOX_STYLE_CANCELTRYCONTINUE:
1197 _MessageBoxPresenter::GetBodyTextObjHeight(void) const
1199 return (__pBodyTextObject == null) ? 0.0f : __textObjHeight;
1202 _MessageBoxPresenter::GetBodyTextHeight(void) const
1204 return (__pBodyTextObject == null) ? 0.0f : __pBodyTextObject->GetTotalHeightF();
1208 _MessageBoxPresenter::GetTextBounds(void) const
1210 return __textBounds;
1214 _MessageBoxPresenter::SetReturnValue(MessageBoxModalResult rtn)
1216 __msgboxResult = rtn;
1220 _MessageBoxPresenter::GetReturnValue(void) const
1222 return (int) __msgboxResult;
1226 _MessageBoxPresenter::InitializeAccessibilityElement(void)
1228 result r = E_SUCCESS;
1230 _AccessibilityContainer* pContainer = null;
1232 pContainer = __pMessageBox->GetAccessibilityContainer();
1234 if (pContainer == null)
1239 if (__pLabel != null)
1241 _AccessibilityContainer* pLabelContainer = __pLabel->GetAccessibilityContainer();
1242 if (pLabelContainer != null)
1244 _AccessibilityElement* pLabelElement = pLabelContainer->GetChildElement(L"LabelText");
1245 if (pLabelElement != null)
1247 pLabelElement->SetName(L"MessageBoxText");
1248 pLabelElement->SetTrait(L"Popup body text");
1252 pContainer->AddChildContainer(*pLabelContainer);
1256 if (__pMessageBox->GetMsgBoxStyle() != MSGBOX_STYLE_NONE)
1258 for (int i = 0; i < __buttonNum; i++)
1260 _ControlImpl* pImpl = null;
1261 _Button* pButtonCore = null;
1263 pImpl = _ControlImpl::GetInstance(*__pButtons[i]);
1265 pButtonCore = dynamic_cast<_Button*>(&pImpl->GetCore());
1266 r = GetLastResult();
1267 SysTryReturnVoidResult(NID_UI_CTRL, pButtonCore != null, r, "[%s] Propagating.", GetErrorMessage(r));
1269 _AccessibilityContainer* pButtonContainer = pButtonCore->GetAccessibilityContainer();
1270 if (pButtonContainer != null)
1272 _AccessibilityElement* pButtonElement = pButtonContainer->GetChildElement(L"ButtonText");
1273 if (pButtonElement != null)
1275 String numberString = null;
1276 numberString = Integer::ToString(i + 1);
1278 String buttonName = L"MessageBoxButton";
1279 buttonName.Append(numberString);
1281 pButtonElement->SetName(buttonName);
1285 pContainer->AddChildContainer(*pButtonContainer);
1291 _AccessibilityElement* pElementMessageBox = new (std::nothrow) _AccessibilityElement(true);
1292 SysTryReturnVoidResult(NID_UI_CTRL, pElementMessageBox != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
1294 pElementMessageBox->SetSupportOperatingGesture(false);
1295 pElementMessageBox->SetName(L"MessageBox");
1296 pElementMessageBox->SetHint(L"double tap to close");
1297 pElementMessageBox->SetBounds(FloatRectangle(0.0f, 0.0f, __pMessageBox->GetBoundsF().width, __pMessageBox->GetBoundsF().height));
1298 pContainer->AddElement(*pElementMessageBox);
1303 _MessageBoxPresenter::GetCore(void)
1305 return static_cast <_Popup*>(__pMessageBox);
1309 _MessageBoxPresenter::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
1311 FloatPoint point = touchinfo.GetCurrentPosition();
1313 FloatRectangle rect(0.0f, 0.0f, __pMessageBox->GetBoundsF().width, __pMessageBox->GetBoundsF().height);
1315 // Touch-event's starting point is MessageBox's leftTop
1316 if (rect.Contains(point) == false)
1318 __touchOutBounds = true;
1322 __touchOutBounds = false;
1325 __touchPressFlag = true;
1327 if ((__pScroll != null) && (__textBounds.Contains(point) == true))
1329 __pScroll->SetScrollVisibility(true);
1331 __scrollStart = true;
1338 _MessageBoxPresenter::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
1340 if (__touchOutBounds == true)
1342 if (__pMessageBox->GetMsgBoxStyle() == MSGBOX_STYLE_NONE)
1344 if (__beginModal == true)
1346 SetReturnValue(MSGBOX_RESULT_CLOSE);
1347 _ModalLoopManager::GetInstance()->EndMainLoop(MSGBOX_RESULT_CLOSE, false);
1348 __beginModal = false;
1353 if (__touchPressFlag == false)
1355 __prevPositionY = -1.0f;
1357 __scrollStart = false;
1360 if (__pScroll != null)
1362 __pScroll->SetScrollVisibility(false);
1369 _MessageBoxPresenter::OnDrawFocus(void)
1371 _ControlImpl* pImpl = null;
1372 _Button* pButtonCore = null;
1374 if (__pButtons[0] != null)
1376 pImpl = _ControlImpl::GetInstance(*__pButtons[0]);
1377 pButtonCore = dynamic_cast<_Button*>(&pImpl->GetCore());
1378 __pButtons[0]->SetFocus();
1379 __pMessageBox->SetFocusTraversalControl(pButtonCore, true);
1386 _MessageBoxPresenter::OnAccessibilityActionPerformed(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1388 if (__pMessageBox->GetMsgBoxStyle() == MSGBOX_STYLE_NONE)
1390 if (__beginModal == true)
1392 SetReturnValue(MSGBOX_RESULT_CLOSE);
1393 _ModalLoopManager::GetInstance()->EndMainLoop(MSGBOX_RESULT_CLOSE, false);
1394 __beginModal = false;
1402 _MessageBoxPresenter::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
1404 __touchOutBounds = false;
1406 if ((__pScroll != null) && (__scrollStart == true))
1408 float scrollAmountView = 0.0f;
1409 float scrollAmountData = 0.0f;
1410 float currentPosition = touchinfo.GetCurrentPosition().y;
1413 if (_FloatCompare(__prevPositionY, -1.0f))
1415 __prevPositionY = currentPosition;
1418 float distance = __prevPositionY - currentPosition;
1420 float newFirstDspY = __pBodyTextObject->GetFirstDisplayPositionYF();
1421 newFirstDspY += distance;
1423 if (newFirstDspY < 0.0f)
1425 newFirstDspY = 0.0f;
1428 if (newFirstDspY > __textBounds.height)
1430 newFirstDspY = __textBounds.height;
1433 int moveLine = __pBodyTextObject->GetLineIndexAtPositionY(newFirstDspY);
1435 __pBodyTextObject->SetFirstDisplayLineIndex(moveLine);
1436 __pBodyTextObject->SetFirstDisplayPositionY(newFirstDspY);
1439 __pScroll->GetScrollRange(&scrollAmountView, &scrollAmountData);
1440 __scrollPos += distance;
1442 if (__scrollPos < 0.0f)
1446 else if (__scrollPos > scrollAmountView)
1448 __scrollPos = scrollAmountView;
1451 __pScroll->SetScrollPosition(__scrollPos);
1453 __prevPositionY = currentPosition;
1455 __touchPressFlag = false;
1458 __pMessageBox->Show();
1466 _MessageBoxPresenter::OnKeyReleased(const _Control& source, const _KeyInfo& keyInfo)
1468 _KeyCode keyCode = keyInfo.GetKeyCode();
1470 if (keyCode == _KEY_ESC || keyCode == _KEY_BACK)
1472 MessageBoxStyle style = __pMessageBox->GetMsgBoxStyle();
1474 if ((__pButtonListener->GetBeginModal() == true) || (__beginModal == true))
1476 if (__pMessageBox->GetTimeout() != 0)
1480 case MSGBOX_STYLE_NONE:
1482 case MSGBOX_STYLE_OK:
1484 case MSGBOX_STYLE_YESNO:
1486 case MSGBOX_STYLE_ABORTRETRYIGNORE:
1487 _ModalLoopManager::GetInstance()->EndMainLoop(MSGBOX_BUTTON_CLOSE, false);
1488 __beginModal = false;
1491 case MSGBOX_STYLE_CANCEL:
1493 case MSGBOX_STYLE_OKCANCEL:
1495 case MSGBOX_STYLE_YESNOCANCEL:
1497 case MSGBOX_STYLE_CANCELTRYCONTINUE:
1499 case MSGBOX_STYLE_RETRYCANCEL:
1500 _ModalLoopManager::GetInstance()->EndMainLoop(MSGBOX_BUTTON_CANCEL, false);
1501 __beginModal = false;
1506 else if (style == MSGBOX_STYLE_CANCEL || style == MSGBOX_STYLE_OKCANCEL || style == MSGBOX_STYLE_YESNOCANCEL
1507 || style == MSGBOX_STYLE_CANCELTRYCONTINUE || style == MSGBOX_STYLE_RETRYCANCEL)
1509 _ModalLoopManager::GetInstance()->EndMainLoop(MSGBOX_BUTTON_CANCEL, false);
1510 __beginModal = false;
1518 ////////////////////////////////////////////////////////////////////////
1519 ///////////////////////////MsgBoxButtonListener/////////////////////////
1520 ////////////////////////////////////////////////////////////////////////
1522 _MessageBoxPresenter::_MessageBoxButtonListener::_MessageBoxButtonListener(void)
1524 , __buttonPressFlag(false)
1525 , __buttonReleaseState(false)
1526 , __beginModal(false)
1527 , __point(0.0f, 0.0f)
1532 _MessageBoxPresenter::_MessageBoxButtonListener::~_MessageBoxButtonListener(void)
1538 _MessageBoxPresenter::_MessageBoxButtonListener::GetClickedButtonHandle(void) const
1540 return __buttonHandle;
1544 _MessageBoxPresenter::_MessageBoxButtonListener::IsButtonClicked(void)
1546 return __buttonReleaseState;
1550 _MessageBoxPresenter::_MessageBoxButtonListener::OnTouchPressed(const Control& source, const Point& currentPosition,
1551 const TouchEventInfo& touchInfo)
1553 __buttonPressFlag = true;
1554 __buttonReleaseState = false;
1556 FloatPoint point = touchInfo.GetCurrentPositionF();
1561 _MessageBoxPresenter::_MessageBoxButtonListener::OnTouchMoved(const Control& source, const Point& currentPosition,
1562 const TouchEventInfo& touchInfo)
1564 //FloatPoint point = touchInfo.GetCurrentPositionF();
1566 __buttonPressFlag = false;
1570 _MessageBoxPresenter::_MessageBoxButtonListener::OnTouchReleased(const Control& source, const Point& currentPosition,
1571 const TouchEventInfo& touchInfo)
1573 if (__buttonPressFlag == true)
1575 __buttonHandle = _ControlImpl::GetInstance(source)->GetCore().GetHandle();
1576 SysTryReturnVoidResult(NID_UI_CTRL, __buttonHandle.IsValid() == true, E_SYSTEM, "[E_SYSTEM] Button's Handle is invalid");
1578 __buttonPressFlag = false;
1579 __buttonReleaseState = true;
1581 if (__beginModal == true)
1583 _ModalLoopManager::GetInstance()->EndMainLoop(MSGBOX_BUTTON_CLICKED, false);
1584 __beginModal = false;
1592 _MessageBoxPresenter::_MessageBoxButtonListener::OnKeyReleased(const Tizen::Ui::Control& source, Tizen::Ui::KeyCode keyCode)
1594 const _ControlImpl* pImpl = null;
1595 const _Button* pControl = null;
1597 pImpl = _ControlImpl::GetInstance(source);
1598 pControl = dynamic_cast<const _Button*>(&pImpl->GetCore());
1600 if (pControl != null)
1602 if (keyCode == KEY_ENTER)
1604 __buttonHandle = _ControlImpl::GetInstance(source)->GetCore().GetHandle();
1605 SysTryReturnVoidResult(NID_UI_CTRL, __buttonHandle.IsValid() == true, E_SYSTEM, "[E_SYSTEM] Button's Handle is invalid");
1607 __buttonPressFlag = false;
1608 __buttonReleaseState = true;
1610 if (__beginModal == true)
1612 _ModalLoopManager::GetInstance()->EndMainLoop(MSGBOX_BUTTON_CLICKED, false);
1613 __beginModal = false;
1622 _MessageBoxPresenter::_MessageBoxButtonListener::OnKeyPressed(const Tizen::Ui::Control& source, Tizen::Ui::KeyCode keyCode)
1624 const _ControlImpl* pImpl = null;
1625 const _Button* pControl = null;
1627 pImpl = _ControlImpl::GetInstance(source);
1628 pControl = dynamic_cast<const _Button*>(&pImpl->GetCore());
1630 if (pControl != null)
1632 _Button* pFocusControl = null;
1636 pFocusControl = dynamic_cast<_Button*>(pControl->GetNextFocus());
1640 pFocusControl = dynamic_cast<_Button*>(pControl->GetPreviousFocus());
1647 _Window* pTop = pControl->GetRootWindow();
1649 if (pFocusControl != null)
1651 pTop->SetFocusTraversalControl(pFocusControl, true);
1652 _Control* pParentControl = pFocusControl->GetParent();
1654 if (pParentControl != null)
1656 pParentControl->OnChildControlFocusMoved(*pFocusControl);
1659 pFocusControl->SetFocused();
1660 pFocusControl->DrawFocus();
1668 _MessageBoxPresenter::_MessageBoxButtonListener::SetBeginModal(bool beginModal)
1670 __beginModal = beginModal;
1674 _MessageBoxPresenter::_MessageBoxButtonListener::GetBeginModal(void)
1676 return __beginModal;
1679 }}} // Tizen::Ui::Controls