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 , __bgImageMargin(0.0f)
71 , __touchPressFlag(false)
72 , __scrollStart(false)
73 , __btnClickFlag(false)
74 , __bodyClickFlag(false)
75 , __touchOutBounds(false)
78 for (int i = 0; i < 3; i++)
84 _MessageBoxPresenter::~_MessageBoxPresenter(void)
86 for (int i = 0; i < __buttonNum; i++)
92 delete __pButtonListener;
93 __pButtonListener = null;
95 if (__pBodyTextObject != null)
97 __pBodyTextObject->RemoveAll();
98 delete __pBodyTextObject;
99 __pBodyTextObject = null;
102 if (__pLabel != null)
104 __pScrollPanel->DetachChild(*__pLabel);
109 if (__pScrollPanel != null)
111 __pMessageBox->DetachChild(*__pScrollPanel);
112 delete __pScrollPanel;
113 __pScrollPanel = null;
116 if (__pScroll != null)
118 __pMessageBox->DetachSystemChild(*__pScroll);
125 _MessageBoxPresenter::OnChangeLayout(_ControlOrientation orientation)
127 result r = E_SUCCESS;
129 float titleTextSize = 0.0f;
130 float minTitleTextSize = 0.0f;
131 float defaultWidth = 0.0f;
132 float titleHeight = 0.0f;
133 float bottomHeight = 0.0f;
134 float maxHeight = 0.0f;
136 float textTopMargin = 0.0f;
138 float titleTopMargin = 0.0f;
139 float titleLeftMargin = 0.0f;
140 float titleRightMargin = 0.0f;
142 float transTopMargin = 0.0f;
143 float transBottomMargin = 0.0f;
144 float labelHeight = 0.0f;
145 float transLeftMargin = 0.0f;
146 float transRightMargin = 0.0f;
148 GET_SHAPE_CONFIG(POPUP::TITLE_TEXT_SIZE, orientation, titleTextSize);
149 GET_SHAPE_CONFIG(POPUP::MIN_TITLE_TEXT_SIZE, orientation, minTitleTextSize);
151 GET_SHAPE_CONFIG(MESSAGEBOX::DEFAULT_WIDTH, orientation, defaultWidth);
152 GET_SHAPE_CONFIG(MESSAGEBOX::BOTTOM_HEIGHT, orientation, bottomHeight);
153 GET_SHAPE_CONFIG(MESSAGEBOX::MAX_HEIGHT, orientation, maxHeight);
155 GET_SHAPE_CONFIG(MESSAGEBOX::TEXT_TOP_MRAGIN, orientation, textTopMargin);
157 GET_SHAPE_CONFIG(MESSAGEBOX::TITLE_TEXT_TOP_MARGIN, orientation, titleTopMargin);
158 GET_SHAPE_CONFIG(MESSAGEBOX::TITLE_TEXT_LEFT_MARGIN, orientation, titleLeftMargin);
159 GET_SHAPE_CONFIG(MESSAGEBOX::TITLE_TEXT_RIGHT_MARGIN, orientation, titleRightMargin);
161 GET_SHAPE_CONFIG(MESSAGEBOX::BG_IMAGE_TRANSPARENT_TOP_MARGIN, orientation, transTopMargin);
162 GET_SHAPE_CONFIG(MESSAGEBOX::BG_IMAGE_TRANSPARENT_BOTTOM_MARGIN, orientation, transBottomMargin);
163 GET_SHAPE_CONFIG(MESSAGEBOX::BG_IMAGE_TRANSPARENT_LEFT_MARGIN, orientation, transLeftMargin);
164 GET_SHAPE_CONFIG(MESSAGEBOX::BG_IMAGE_TRANSPARENT_RIGHT_MARGIN, orientation, transRightMargin);
166 __textBounds.width = defaultWidth - GetLeftRightLabelMargin();
167 __titleBgBounds.width = defaultWidth - (transLeftMargin + transRightMargin);
168 __buttonBgBounds.width = defaultWidth - (transLeftMargin + transRightMargin);
171 if (__pMessageBox->HasTitle() == true)
173 GET_SHAPE_CONFIG(MESSAGEBOX::TITLE_HEIGHT, orientation, titleHeight);
175 _titleBounds.width = __textBounds.width;
176 _pTitleTextObject->SetBounds(_titleBounds);
178 r = CalculateTitleTextSize(titleTextSize, minTitleTextSize);
179 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
181 _titleBounds.height = titleHeight - titleTopMargin;
185 __pBodyTextObject->SetBounds(__textBounds);
187 __pBodyTextObject->Compose();
190 __pScrollPanel->SetBounds(__textBounds);
192 labelHeight = __pBodyTextObject->GetTotalHeightF();
194 if (labelHeight < __textObjHeight)
196 __pLabel->SetBounds(FloatRectangle(0.0f, (__textObjHeight - labelHeight)/2.0f, __textBounds.width, labelHeight));
200 __pLabel->SetBounds(FloatRectangle(0.0f, 0.0f, __textBounds.width, labelHeight));
203 for (int i = 0; i < __buttonNum; i++)
205 r = __pButtons[i]->SetBounds(CalculateButtonPositionAndSize(i));
206 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
213 _MessageBoxPresenter::Initialize(_MessageBox& msgbox)
215 result r = E_SUCCESS;
217 float titleTextSize = 0.0f;
218 float bodyTextSize = 0.0f;
220 float defaultWidth = 0.0f;
221 float titleHeight = 0.0f;
222 float bottomHeight = 0.0f;
223 float maxHeight = 0.0f;
225 float textTopMargin = 0.0f;
226 float textTopMarginNoButton = 0.0f;
227 float textLeftMargin = 0.0f;
229 float titleTopMargin = 0.0f;
230 float titleLeftMargin = 0.0f;
231 float titleRightMargin = 0.0f;
233 float transTopMargin = 0.0f;
234 float transBottomMargin = 0.0f;
235 float transLeftMargin = 0.0f;
236 float transRightMargin = 0.0f;
237 float labelHeight = 0.0f;
239 _ControlOrientation orientation;
241 __pMessageBox = &msgbox;
243 orientation = __pMessageBox->GetOrientation();
245 GET_SHAPE_CONFIG(MESSAGEBOX::TITLE_TEXT_SIZE, orientation, titleTextSize);
246 GET_SHAPE_CONFIG(MESSAGEBOX::TEXT_SIZE, orientation, bodyTextSize);
247 GET_SHAPE_CONFIG(MESSAGEBOX::TEXT_HEIGHT, orientation, __textObjHeight);
249 GET_SHAPE_CONFIG(MESSAGEBOX::DEFAULT_WIDTH, orientation, defaultWidth);
250 GET_SHAPE_CONFIG(MESSAGEBOX::TITLE_HEIGHT, orientation, titleHeight);
251 GET_SHAPE_CONFIG(MESSAGEBOX::BOTTOM_HEIGHT, orientation, bottomHeight);
252 GET_SHAPE_CONFIG(MESSAGEBOX::MAX_HEIGHT, orientation, maxHeight);
254 GET_SHAPE_CONFIG(MESSAGEBOX::TEXT_TOP_MRAGIN, orientation, textTopMargin);
255 GET_SHAPE_CONFIG(MESSAGEBOX::TEXT_TOP_MRAGIN_NO_BUTTON, orientation, textTopMarginNoButton);
256 GET_SHAPE_CONFIG(MESSAGEBOX::TEXT_LEFT_MARGIN, orientation, textLeftMargin);
258 GET_SHAPE_CONFIG(MESSAGEBOX::TITLE_TEXT_TOP_MARGIN, orientation, titleTopMargin);
259 GET_SHAPE_CONFIG(MESSAGEBOX::TITLE_TEXT_LEFT_MARGIN, orientation, titleLeftMargin);
260 GET_SHAPE_CONFIG(MESSAGEBOX::TITLE_TEXT_RIGHT_MARGIN, orientation, titleRightMargin);
262 GET_SHAPE_CONFIG(MESSAGEBOX::BG_IMAGE_TRANSPARENT_TOP_MARGIN, orientation, transTopMargin);
263 GET_SHAPE_CONFIG(MESSAGEBOX::BG_IMAGE_TRANSPARENT_BOTTOM_MARGIN, orientation, transBottomMargin);
264 GET_SHAPE_CONFIG(MESSAGEBOX::BG_IMAGE_TRANSPARENT_LEFT_MARGIN, orientation, transLeftMargin);
265 GET_SHAPE_CONFIG(MESSAGEBOX::BG_IMAGE_TRANSPARENT_RIGHT_MARGIN, orientation, transRightMargin);
266 GET_FIXED_VALUE_CONFIG(MESSAGEBOX::BG_IMAGE_MARGIN, orientation, __bgImageMargin);
269 __titleBgBounds= FloatRectangle(transLeftMargin, transTopMargin, _CoordinateSystemUtils::ConvertToFloat(defaultWidth) - (2 * transLeftMargin), titleHeight);
273 if (__pMessageBox->HasTitle() == true)
275 _pTitleTextObject = new (std::nothrow) TextObject();
276 SysTryReturn(NID_UI_CTRL, _pTitleTextObject != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Unable to create TitleTextObject.");
278 r = _pTitleTextObject->Construct();
279 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
281 FloatRectangle bounds = FloatRectangle(titleLeftMargin + transLeftMargin,
282 titleTopMargin + transTopMargin,
283 defaultWidth - (titleLeftMargin + titleRightMargin + transLeftMargin + transRightMargin),
284 titleHeight - titleTopMargin);
286 labelHeight = GetLabelHeight(_pTitleTextObject, const_cast <wchar_t*>(__pMessageBox->GetTitleText().GetPointer()),
287 __pMessageBox->GetTitleText().GetLength(), titleTextSize, bounds, true);
290 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
292 _titleBounds = FloatRectangle(titleLeftMargin + transLeftMargin,
293 __titleBgBounds.y + (__titleBgBounds.height - labelHeight) / 2,
294 defaultWidth - (titleLeftMargin + titleRightMargin + transLeftMargin + transRightMargin),
295 titleHeight - titleTopMargin);
303 __textBounds.SetBounds(textLeftMargin + transLeftMargin,
304 titleHeight + textTopMargin + transTopMargin,
305 defaultWidth - GetLeftRightLabelMargin(),
309 if ((__pMessageBox->HasTitle() == false) && (__pMessageBox->GetMsgBoxStyle() == MSGBOX_STYLE_NONE))
311 __textBounds.y = transTopMargin + textTopMarginNoButton;
314 __pLabel = _Label::CreateLabelN();
315 SysTryCatch(NID_UI_CTRL, __pLabel != null, , E_OUT_OF_MEMORY, "[E_SYSTEM] Failed to create the scroll.");
317 __pBodyTextObject = new (std::nothrow) TextObject();
318 SysTryCatch(NID_UI_CTRL, __pBodyTextObject != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
320 r = __pBodyTextObject->Construct();
321 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
323 labelHeight = GetLabelHeight(__pBodyTextObject, const_cast <wchar_t*>(__pMessageBox->GetText().GetPointer()),
324 __pMessageBox->GetText().GetLength(), bodyTextSize, __textBounds, false);
327 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
329 if (__pMessageBox->GetText().GetLength() > 0)
331 __textObjHeight = __pBodyTextObject->GetLineHeightAtF(0) * 3.0;
332 __textBounds.height = __textObjHeight;
335 if (labelHeight < __textObjHeight)
337 __pLabel->SetBounds(FloatRectangle(0.0f, (__textObjHeight - labelHeight)/2.0f, __textBounds.width, labelHeight));
341 __pLabel->SetBounds(FloatRectangle(0.0f, 0.0f, __textBounds.width, labelHeight));
345 __pLabel->SetText(__pMessageBox->GetText());
346 __pLabel->SetTextConfig(bodyTextSize, LABEL_TEXT_STYLE_NORMAL);
347 __pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
348 __pLabel->SetMargin(0.0f, 0.0f, 0.0f, 0.0f);
350 __pScrollPanel = _ScrollPanel::CreateScrollPanelN(__textBounds, SCROLL_PANEL_SCROLL_DIRECTION_VERTICAL, true);
352 SysTryCatch(NID_UI_CTRL, __pScrollPanel != null, , E_OUT_OF_MEMORY, "[E_SYSTEM] Failed to create the scroll.");
353 __pScrollPanel->SetBounds(__textBounds);
354 __pScrollPanel->AttachChild(*__pLabel);
355 __pScrollPanel->SetFocusable(false);
356 __pMessageBox->AttachChild(*__pScrollPanel);
358 __buttonBgBounds = FloatRectangle(transLeftMargin + __bgImageMargin, __pMessageBox->GetTotalHeight() - bottomHeight - transBottomMargin, _CoordinateSystemUtils::ConvertToFloat(defaultWidth)- (transLeftMargin + transRightMargin) - (2 * __bgImageMargin), bottomHeight - __bgImageMargin);
361 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
366 delete _pTitleTextObject;
367 _pTitleTextObject = null;
369 delete __pBodyTextObject;
370 __pBodyTextObject = null;
377 _MessageBoxPresenter::GetLabelHeight(TextObject* textObject, wchar_t* text, int length, float bodyTextSize, FloatRectangle bounds, bool isTitle)
379 TextSimple* pSimpleTextForBodyText = null;
380 result r = E_SUCCESS;
383 pSimpleTextForBodyText = new (std::nothrow) TextSimple(text, length, TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
384 SysTryCatch(NID_UI_CTRL, pSimpleTextForBodyText != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
386 textObject->AppendElement(*pSimpleTextForBodyText);
387 textObject->SetWrap(TEXT_OBJECT_WRAP_TYPE_WORD);
388 textObject->SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
389 textObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_LEFT);
390 textObject->SetBounds(bounds);
394 float minTitleTextSize = 0.0f;
396 GET_SHAPE_CONFIG(MESSAGEBOX::MIN_TITLE_TEXT_SIZE, __pMessageBox->GetOrientation(), minTitleTextSize);
398 r = CalculateTitleTextSize(bodyTextSize, minTitleTextSize);
399 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
403 r = SetFontInfo(FONT_STYLE_PLAIN, bodyTextSize);
404 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set font.", GetErrorMessage(r));
406 textObject->SetFont(_pFont, 0, textObject->GetTextLength());
408 textObject->Compose();
413 return textObject->GetTotalHeightF();
420 _MessageBoxPresenter::GetLeftRightLabelMargin(void)
422 float textLeftMargin = 0.0f;
423 float textRightMargin = 0.0f;
424 float transLeftMargin = 0.0f;
425 float transRightMargin = 0.0f;
427 _ControlOrientation orientation = __pMessageBox->GetOrientation();
429 GET_SHAPE_CONFIG(MESSAGEBOX::TEXT_LEFT_MARGIN, orientation, textLeftMargin);
430 GET_SHAPE_CONFIG(MESSAGEBOX::TEXT_RIGHT_MARGIN, orientation, textRightMargin);
431 GET_SHAPE_CONFIG(MESSAGEBOX::BG_IMAGE_TRANSPARENT_LEFT_MARGIN, orientation, transLeftMargin);
432 GET_SHAPE_CONFIG(MESSAGEBOX::BG_IMAGE_TRANSPARENT_RIGHT_MARGIN, orientation, transRightMargin);
434 return textLeftMargin + textRightMargin + transLeftMargin + transRightMargin;
438 _MessageBoxPresenter::Draw(void)
440 result r = E_SUCCESS;
442 float defaultWidth = 0.0f;
443 float textSize = 0.0f;
445 bool isCustomBitmap = false;
447 _ControlOrientation orientation;
449 orientation = __pMessageBox->GetOrientation();
451 GET_SHAPE_CONFIG(MESSAGEBOX::DEFAULT_WIDTH, orientation, defaultWidth);
452 GET_SHAPE_CONFIG(MESSAGEBOX::TEXT_SIZE, orientation, textSize);
454 Canvas* pCanvas = __pMessageBox->GetCanvasN();
455 SysTryReturnVoidResult(NID_UI_CTRL, (pCanvas != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Unable to create canvas.");
457 pCanvas->SetBackgroundColor(Color(0x00000000));
460 float totalH = __pMessageBox->GetTotalHeight();
462 FloatRectangle bgBounds(0.0f, 0.0f, _CoordinateSystemUtils::ConvertToFloat(defaultWidth), totalH);
464 const Bitmap* pBackgroundBitmap = __pMessageBox->GetBackgroundBitmap();
465 const Bitmap* pOutlineBitmap = __pMessageBox->GetOutlineBitmap();
466 const Bitmap* pButtonBitmap = __pMessageBox->GetButtonBackgroundBitmap();
467 const Bitmap* pButtonEffectBitmap = __pMessageBox->GetButtonBackgroundEffectBitmap();
468 const Bitmap* pTitleBitmap = __pMessageBox->GetTitleBackgroundBitmap();
469 const Bitmap* pTitleEffectBitmap = __pMessageBox->GetTitleBackgroundEffectBitmap();
471 isCustomBitmap = IS_CUSTOM_BITMAP(MESSAGEBOX::BG_NORMAL);
473 if (pBackgroundBitmap != null)
475 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pBackgroundBitmap))
477 pCanvas->DrawNinePatchedBitmap(bgBounds, *pBackgroundBitmap);
481 pCanvas->DrawBitmap(bgBounds, *pBackgroundBitmap);
486 if (!isCustomBitmap && pOutlineBitmap != null)
488 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pOutlineBitmap))
490 pCanvas->DrawNinePatchedBitmap(bgBounds, *pOutlineBitmap);
494 pCanvas->DrawBitmap(bgBounds, *pOutlineBitmap);
499 if(pButtonBitmap != null)
501 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pButtonBitmap))
503 pCanvas->DrawNinePatchedBitmap(__buttonBgBounds, *pButtonBitmap);
507 pCanvas->DrawBitmap(__buttonBgBounds, *pButtonBitmap);
510 //DrawEffectButtonBitmap
511 if (pButtonEffectBitmap != null)
513 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pButtonEffectBitmap))
515 pCanvas->DrawNinePatchedBitmap(__buttonBgBounds, *pButtonEffectBitmap);
519 pCanvas->DrawBitmap(__buttonBgBounds, *pButtonEffectBitmap);
524 if (_pTitleTextObject != null)
527 if(pTitleBitmap != null)
529 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pTitleBitmap))
531 pCanvas->DrawNinePatchedBitmap(__titleBgBounds, *pTitleBitmap);
535 pCanvas->DrawBitmap(__titleBgBounds, *pTitleBitmap);
538 //DrawEffectTitleBitmap
539 if (pTitleEffectBitmap != null)
541 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pTitleEffectBitmap))
543 pCanvas->DrawNinePatchedBitmap(__titleBgBounds, *pTitleEffectBitmap);
547 pCanvas->DrawBitmap(__titleBgBounds, *pTitleEffectBitmap);
550 r = SetFontInfo(FONT_STYLE_PLAIN, _titleTextSize);
551 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
553 _pTitleTextObject->SetFont(_pFont, 0, _pTitleTextObject->GetTextLength());
554 _pTitleTextObject->SetForegroundColor(__pMessageBox->GetTitleTextColor(), 0, _pTitleTextObject->GetTextLength());
555 _pTitleTextObject->SetBounds(_titleBounds);
556 _pTitleTextObject->Draw(*_CanvasImpl::GetInstance(*pCanvas));
559 __pLabel->SetTextColor(__pMessageBox->GetTextColor());
568 _MessageBoxPresenter::ShowAndWait(int& modalResult)
570 result r = E_SUCCESS;
572 r = __pMessageBox->Open();
574 __pMessageBox->SetTouchCapture(false, false);
578 __pMessageBox->ReleaseTouchCapture();
580 __pMessageBox->Close();
582 modalResult = GetReturnValue();
588 _MessageBoxPresenter::ProcessEvent(void)
590 _ControlHandle handle;
592 _TouchManager* pTouchManager = _TouchManager::GetInstance();
595 _Control* pControl = pTouchManager->GetTouchControlSource();
598 pControl->SetEventEnableState(false);
602 if (__pMessageBox->GetMsgBoxStyle() == MSGBOX_STYLE_NONE)
606 else if (__pButtonListener != null)
608 __pButtonListener->SetBeginModal(true);
611 _ModalLoopManager::GetInstance()->BeginMainLoop(__pMessageBox->GetTimeout(), MSGBOX_RESULT_CLOSE);
613 int exitCode = _ModalLoopManager::GetInstance()->GetLastExitCode();
616 case MSGBOX_BUTTON_CLICKED:
617 if (__pButtonListener != null && __pButtonListener->IsButtonClicked())
619 handle = __pButtonListener->GetClickedButtonHandle();
620 FindButtonAndResult(handle);
623 case MSGBOX_BUTTON_CLOSE:
624 SetReturnValue(MSGBOX_RESULT_CLOSE);
627 case MSGBOX_BUTTON_CANCEL:
628 SetReturnValue(MSGBOX_RESULT_CANCEL);
632 case _ModalLoopManager::MODAL_LOOP_EXIT_CODE_APP_TERMINATION:
633 case _ModalLoopManager::MODAL_LOOP_EXIT_CODE_CONTINUOUS_TERMINATION:
634 _ModalLoopManager::GetInstance()->EndMainLoop(exitCode, false);
635 __beginModal = false;
639 if (__pMessageBox->GetMsgBoxStyle() == MSGBOX_STYLE_NONE)
641 __beginModal = false;
643 else if (__pButtonListener != null)
645 __pButtonListener->SetBeginModal(false);
650 _MessageBoxPresenter::GetButtonString(void)
652 switch (__pMessageBox->GetMsgBoxStyle())
654 case MSGBOX_STYLE_NONE:
658 case MSGBOX_STYLE_OK:
660 GET_STRING_CONFIG(IDS_TPLATFORM_BUTTON_OK, __buttonText[0]);
663 case MSGBOX_STYLE_CANCEL:
665 GET_STRING_CONFIG(IDS_TPLATFORM_BUTTON_CANCEL_ABB, __buttonText[0]);
668 case MSGBOX_STYLE_OKCANCEL:
670 GET_STRING_CONFIG(IDS_TPLATFORM_BUTTON_OK, __buttonText[1]);
671 GET_STRING_CONFIG(IDS_TPLATFORM_BUTTON_CANCEL_ABB, __buttonText[0]);
674 case MSGBOX_STYLE_YESNO:
676 GET_STRING_CONFIG(IDS_TPLATFORM_BUTTON_YES, __buttonText[1]);
677 GET_STRING_CONFIG(IDS_TPLATFORM_BUTTON_NO, __buttonText[0]);
680 case MSGBOX_STYLE_YESNOCANCEL:
682 GET_STRING_CONFIG(IDS_TPLATFORM_BUTTON_YES, __buttonText[2]);
683 GET_STRING_CONFIG(IDS_TPLATFORM_BUTTON_NO, __buttonText[1]);
684 GET_STRING_CONFIG(IDS_TPLATFORM_BUTTON_CANCEL_ABB, __buttonText[0]);
687 case MSGBOX_STYLE_ABORTRETRYIGNORE:
689 GET_STRING_CONFIG(IDS_TPLATFORM_BUTTON_ABORT, __buttonText[0]);
690 GET_STRING_CONFIG(IDS_TPLATFORM_BUTTON_RETRY, __buttonText[1]);
691 GET_STRING_CONFIG(IDS_TPLATFORM_BUTTON_IGNORE, __buttonText[2]);
694 case MSGBOX_STYLE_CANCELTRYCONTINUE:
696 GET_STRING_CONFIG(IDS_TPLATFORM_BUTTON_CANCEL_ABB, __buttonText[0]);
697 GET_STRING_CONFIG(IDS_TPLATFORM_BUTTON_TRY, __buttonText[1]);
698 GET_STRING_CONFIG(IDS_TPLATFORM_BUTTON_CONTINUE_ABB, __buttonText[2]);
701 case MSGBOX_STYLE_RETRYCANCEL:
703 GET_STRING_CONFIG(IDS_TPLATFORM_BUTTON_RETRY, __buttonText[1]);
704 GET_STRING_CONFIG(IDS_TPLATFORM_BUTTON_CANCEL_ABB, __buttonText[0]);
713 _MessageBoxPresenter::UpdateButtonString(void)
717 for (int i = 0; i < __buttonNum; i++)
719 __pButtons[i]->SetText(__buttonText[i]);
724 _MessageBoxPresenter::CreateButtons(void)
726 result r = E_SUCCESS;
729 Color buttonColorNormal(0x00000000);
730 Color buttonColorPressed(0x00000000);
731 Color buttonColorDisabled(0x00000000);
732 Color buttonColorHighlighted(0x00000000);
733 Color buttonTextNormal(0x00000000);
734 Color buttonTextPressed(0x00000000);
735 Color buttonTextDisabled(0x00000000);
736 Color buttonTextHighlighted(0x00000000);
737 bool isCustomBitmap = false;
740 Bitmap* pButtonBgNormal = null;
741 Bitmap* pButtonBgPressed = null;
742 Bitmap* pButtonBgDisabled = null;
743 Bitmap* pButtonBgHighlighted = null;
745 Bitmap* pComposedButtonBgNormal = null;
746 Bitmap* pComposedButtonBgPressed = null;
747 Bitmap* pComposedButtonBgDisabled = null;
748 Bitmap* pComposedButtonBgHighlighted = null;
750 Bitmap* pButtonNormalEffect = null;
751 Bitmap* pButtonPressedEffect = null;
752 Bitmap* pButtonDisabledEffect = null;
754 GET_COLOR_CONFIG(MESSAGEBOX::BOTTOM_BUTTON_BG_NORMAL, buttonColorNormal);
755 GET_COLOR_CONFIG(MESSAGEBOX::BOTTOM_BUTTON_BG_PRESSED, buttonColorPressed);
756 GET_COLOR_CONFIG(MESSAGEBOX::BOTTOM_BUTTON_BG_DISABLED, buttonColorDisabled);
757 GET_COLOR_CONFIG(MESSAGEBOX::BOTTOM_BUTTON_BG_HIGHLIGHTED, buttonColorHighlighted);
759 GET_COLOR_CONFIG(MESSAGEBOX::BOTTOM_BUTTON_TEXT_NORMAL, buttonTextNormal);
760 GET_COLOR_CONFIG(MESSAGEBOX::BOTTOM_BUTTON_TEXT_PRESSED, buttonTextPressed);
761 GET_COLOR_CONFIG(MESSAGEBOX::BOTTOM_BUTTON_TEXT_DISABLED, buttonTextDisabled);
762 GET_COLOR_CONFIG(MESSAGEBOX::BOTTOM_BUTTON_TEXT_HIGHLIGHTED, buttonTextHighlighted);
764 GET_BITMAP_CONFIG_N(MESSAGEBOX::BOTTOM_BUTTON_BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, pButtonBgNormal);
766 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating. Failed to load Bottom button normal Image.", GetErrorMessage(r));
768 isCustomBitmap = IS_CUSTOM_BITMAP(MESSAGEBOX::BOTTOM_BUTTON_BG_NORMAL);
772 GET_BITMAP_CONFIG_N(MESSAGEBOX::BOTTOM_BUTTON_NORMAL_EFFECT, BITMAP_PIXEL_FORMAT_ARGB8888, pButtonNormalEffect);
774 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating. Failed to load Bottom button normal effect Image.", GetErrorMessage(r));
777 GET_BITMAP_CONFIG_N(MESSAGEBOX::BOTTOM_BUTTON_BG_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, pButtonBgPressed);
779 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating. Failed to load Bottom button pressed Image.", GetErrorMessage(r));
781 isCustomBitmap = IS_CUSTOM_BITMAP(MESSAGEBOX::BOTTOM_BUTTON_BG_PRESSED);
785 GET_BITMAP_CONFIG_N(MESSAGEBOX::BOTTOM_BUTTON_PRESSED_EFFECT, BITMAP_PIXEL_FORMAT_ARGB8888, pButtonPressedEffect);
787 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating. Failed to load Bottom button pressed effect Image.", GetErrorMessage(r));
790 GET_BITMAP_CONFIG_N(MESSAGEBOX::BOTTOM_BUTTON_BG_DISABLED, BITMAP_PIXEL_FORMAT_ARGB8888, pButtonBgDisabled);
792 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating. Failed to load Bottom button disabled Image.", GetErrorMessage(r));
794 isCustomBitmap = IS_CUSTOM_BITMAP(MESSAGEBOX::BOTTOM_BUTTON_BG_DISABLED);
798 GET_BITMAP_CONFIG_N(MESSAGEBOX::BOTTOM_BUTTON_DISABLED_EFFECT, BITMAP_PIXEL_FORMAT_ARGB8888, pButtonDisabledEffect);
800 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating. Failed to load Bottom button disabled effect Image.", GetErrorMessage(r));
803 GET_BITMAP_CONFIG_N(MESSAGEBOX::BOTTOM_BUTTON_BG_HIGHLIGHTED, BITMAP_PIXEL_FORMAT_ARGB8888, pButtonBgHighlighted);
805 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating. Failed to load Bottom button highlighted Image.", GetErrorMessage(r));
807 pComposedButtonBgNormal = _BitmapImpl::GetColorReplacedBitmapN(*pButtonBgNormal, Color::GetColor(COLOR_ID_MAGENTA), buttonColorNormal);
809 SysTryCatch(NID_UI_CTRL, (pComposedButtonBgNormal != null), , r, "[%s] Propagating.", GetErrorMessage(r));
811 pComposedButtonBgPressed = _BitmapImpl::GetColorReplacedBitmapN(*pButtonBgPressed, Color::GetColor(COLOR_ID_MAGENTA), buttonColorPressed);
813 SysTryCatch(NID_UI_CTRL, (pComposedButtonBgPressed != null), , r, "[%s] Propagating.", GetErrorMessage(r));
815 pComposedButtonBgDisabled = _BitmapImpl::GetColorReplacedBitmapN(*pButtonBgDisabled, Color::GetColor(COLOR_ID_MAGENTA), buttonColorDisabled);
817 SysTryCatch(NID_UI_CTRL, (pComposedButtonBgDisabled != null), , r, "[%s] Propagating.", GetErrorMessage(r));
819 pComposedButtonBgHighlighted = _BitmapImpl::GetColorReplacedBitmapN(*pButtonBgHighlighted, Color::GetColor(COLOR_ID_MAGENTA), buttonColorHighlighted);
821 SysTryCatch(NID_UI_CTRL, (pComposedButtonBgHighlighted != null), , r, "[%s] Propagating.", GetErrorMessage(r));
823 __pButtonListener = new (std::nothrow) _MessageBoxButtonListener();
824 SysTryCatch(NID_UI_CTRL, __pButtonListener != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
826 for (int i = 0; i < __buttonNum; i++)
828 _ControlImpl* pImpl = null;
829 _Button* pButtonCore = null;
831 __pButtons[i] = new (std::nothrow) Button();
832 SysTryCatch(NID_UI_CTRL, __pButtons[i] != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
834 r = __pButtons[i]->Construct(CalculateButtonPositionAndSize(i));
835 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
837 __pButtons[i]->SetText(__buttonText[i]);
838 __pButtons[i]->AddTouchEventListener(*__pButtonListener);
839 __pButtons[i]->AddKeyEventListener(*__pButtonListener);
840 __pButtons[i]->SetNormalBackgroundBitmap(*pComposedButtonBgNormal);
841 __pButtons[i]->SetPressedBackgroundBitmap(*pComposedButtonBgPressed);
842 __pButtons[i]->SetDisabledBackgroundBitmap(*pComposedButtonBgDisabled);
843 __pButtons[i]->SetHighlightedBackgroundBitmap(*pComposedButtonBgHighlighted);
844 __pButtons[i]->SetTextColor(buttonTextNormal);
845 __pButtons[i]->SetPressedTextColor(buttonTextPressed);
846 __pButtons[i]->SetDisabledTextColor(buttonTextDisabled);
847 __pButtons[i]->SetHighlightedTextColor(buttonTextHighlighted);
849 pImpl = _ControlImpl::GetInstance(*__pButtons[i]);
850 pButtonCore = dynamic_cast<_Button*>(&pImpl->GetCore());
852 if (pButtonCore != null)
854 pButtonCore->SetTouchPressThreshold(0.16);
855 __pMessageBox->AttachChild(*pButtonCore);
857 if (pButtonNormalEffect != null)
859 pButtonCore->SetBackgroundEffectBitmap(_BUTTON_STATUS_NORMAL, *pButtonNormalEffect);
862 if (pButtonPressedEffect != null)
864 pButtonCore->SetBackgroundEffectBitmap(_BUTTON_STATUS_PRESSED, *pButtonPressedEffect);
867 if(pButtonDisabledEffect != null)
869 pButtonCore->SetBackgroundEffectBitmap(_BUTTON_STATUS_DISABLED, *pButtonDisabledEffect);
875 __pButtons[i-1]->SetNextFocus(__pButtons[i]);
876 __pButtons[i]->SetPreviousFocus(__pButtons[i-1]);
881 delete pButtonBgNormal;
882 pButtonBgNormal = null;
884 delete pButtonBgPressed;
885 pButtonBgPressed = null;
887 delete pButtonBgDisabled;
888 pButtonBgDisabled = null;
890 delete pButtonBgHighlighted;
891 pButtonBgHighlighted = null;
893 delete pComposedButtonBgNormal;
894 pComposedButtonBgNormal = null;
896 delete pComposedButtonBgPressed;
897 pComposedButtonBgPressed = null;
899 delete pComposedButtonBgDisabled;
900 pComposedButtonBgDisabled = null;
902 delete pComposedButtonBgHighlighted;
903 pComposedButtonBgHighlighted = null;
905 delete pButtonNormalEffect;
906 pButtonNormalEffect = null;
908 delete pButtonPressedEffect;
909 pButtonNormalEffect = null;
911 delete pButtonDisabledEffect;
912 pButtonNormalEffect = null;
918 delete pButtonBgNormal;
919 pButtonBgNormal = null;
921 delete pButtonBgPressed;
922 pButtonBgPressed = null;
924 delete pButtonBgDisabled;
925 pButtonBgDisabled = null;
927 delete pButtonBgHighlighted;
928 pButtonBgHighlighted = null;
930 delete pComposedButtonBgNormal;
931 pComposedButtonBgNormal = null;
933 delete pComposedButtonBgPressed;
934 pComposedButtonBgPressed = null;
936 delete pComposedButtonBgDisabled;
937 pComposedButtonBgDisabled = null;
939 delete pComposedButtonBgHighlighted;
940 pComposedButtonBgHighlighted = null;
942 delete pButtonNormalEffect;
943 pButtonNormalEffect = null;
945 delete pButtonPressedEffect;
946 pButtonNormalEffect = null;
948 delete pButtonDisabledEffect;
949 pButtonNormalEffect = null;
951 delete __pButtonListener;
952 __pButtonListener = null;
954 for (int i = 0; i < __buttonNum; i++)
956 delete __pButtons[i];
957 __pButtons[i] = null;
963 _MessageBoxPresenter::CalculateButtonPositionAndSize(int buttonIndex)
970 float defaultWidth = 0.0f;
971 float btnHeight = 0.0f;
973 float btnSideMargin1 = 0.0f;
974 float btnSideMargin2 = 0.0f;
975 float btnSideMargin3 = 0.0f;
976 float btnTopMargin = 0.0f;
979 float textTopMargin = 0.0f;
981 float titleHeight = 0.0f;
982 float transTopMargin = 0.0f;
984 _ControlOrientation orientation;
985 orientation = __pMessageBox->GetOrientation();
986 GET_SHAPE_CONFIG(MESSAGEBOX::DEFAULT_WIDTH, orientation, defaultWidth);
987 GET_SHAPE_CONFIG(MESSAGEBOX::BUTTON_HEIGHT, orientation, btnHeight);
989 GET_SHAPE_CONFIG(MESSAGEBOX::BUTTON_SIDE_MARGIN_01, orientation, btnSideMargin1);
990 GET_SHAPE_CONFIG(MESSAGEBOX::BUTTON_SIDE_MARGIN_02, orientation, btnSideMargin2);
991 GET_SHAPE_CONFIG(MESSAGEBOX::BUTTON_SIDE_MARGIN_03, orientation, btnSideMargin3);
992 GET_SHAPE_CONFIG(MESSAGEBOX::BUTTON_TOP_MARGIN, orientation, btnTopMargin);
994 GET_SHAPE_CONFIG(MESSAGEBOX::BUTTON_INTERNAL_GAP, orientation, btnGap);
995 GET_SHAPE_CONFIG(MESSAGEBOX::TEXT_TOP_MRAGIN, orientation, textTopMargin);
997 GET_SHAPE_CONFIG(MESSAGEBOX::TITLE_HEIGHT, orientation, titleHeight);
998 GET_SHAPE_CONFIG(MESSAGEBOX::BG_IMAGE_TRANSPARENT_TOP_MARGIN, orientation, transTopMargin);
1000 if (__pMessageBox->HasTitle() == false)
1005 switch (__buttonNum)
1008 w = defaultWidth - (btnSideMargin1 * 2.0f);
1014 w = (defaultWidth - (btnSideMargin2 * 2.0f) - btnGap) / 2.0f;
1016 x = btnSideMargin2 + (buttonIndex * (w + btnGap));
1021 switch (buttonIndex)
1028 w = (defaultWidth - ((btnSideMargin3 + btnGap) * 2.0f)) / 3.0f;
1030 x = btnSideMargin3 + (buttonIndex * (w + btnGap));
1038 y = __buttonBgBounds.y + (__buttonBgBounds.height - h) / 2;
1039 return FloatRectangle(x, y, w, h);
1043 _MessageBoxPresenter::FindButtonAndResult(const _ControlHandle handle)
1047 for (int i = 0; i < __buttonNum; i++)
1049 _ControlImpl* pImpl = _ControlImpl::GetInstance(*__pButtons[i]);
1050 if (pImpl->GetCore().GetHandle() == handle)
1057 switch (__pMessageBox->GetMsgBoxStyle())
1059 case MSGBOX_STYLE_NONE:
1060 SetReturnValue(MSGBOX_RESULT_CLOSE);
1063 case MSGBOX_STYLE_OK:
1064 SetReturnValue(MSGBOX_RESULT_OK);
1067 case MSGBOX_STYLE_CANCEL:
1068 SetReturnValue(MSGBOX_RESULT_CANCEL);
1071 case MSGBOX_STYLE_OKCANCEL:
1075 SetReturnValue(MSGBOX_RESULT_CANCEL);
1079 SetReturnValue(MSGBOX_RESULT_OK);
1084 case MSGBOX_STYLE_YESNO:
1088 SetReturnValue(MSGBOX_RESULT_NO);
1092 SetReturnValue(MSGBOX_RESULT_YES);
1097 case MSGBOX_STYLE_YESNOCANCEL:
1101 SetReturnValue(MSGBOX_RESULT_CANCEL);
1105 SetReturnValue(MSGBOX_RESULT_NO);
1109 SetReturnValue(MSGBOX_RESULT_YES);
1114 case MSGBOX_STYLE_ABORTRETRYIGNORE:
1118 SetReturnValue(MSGBOX_RESULT_ABORT);
1122 SetReturnValue(MSGBOX_RESULT_RETRY);
1126 SetReturnValue(MSGBOX_RESULT_IGNORE);
1131 case MSGBOX_STYLE_CANCELTRYCONTINUE:
1135 SetReturnValue(MSGBOX_RESULT_CANCEL);
1139 SetReturnValue(MSGBOX_RESULT_TRY);
1143 SetReturnValue(MSGBOX_RESULT_CONTINUE);
1148 case MSGBOX_STYLE_RETRYCANCEL:
1152 SetReturnValue(MSGBOX_RESULT_CANCEL);
1156 SetReturnValue(MSGBOX_RESULT_RETRY);
1167 _MessageBoxPresenter::CalculateButtonAreaHeight(void)
1169 float btnHeight = 0.0f;
1171 GET_SHAPE_CONFIG(MESSAGEBOX::BUTTON_HEIGHT, __pMessageBox->GetOrientation(), btnHeight);
1173 switch (__pMessageBox->GetMsgBoxStyle())
1175 case MSGBOX_STYLE_NONE:
1178 case MSGBOX_STYLE_OK:
1180 case MSGBOX_STYLE_CANCEL:
1182 case MSGBOX_STYLE_OKCANCEL:
1184 case MSGBOX_STYLE_YESNO:
1186 case MSGBOX_STYLE_RETRYCANCEL:
1188 case MSGBOX_STYLE_YESNOCANCEL:
1190 case MSGBOX_STYLE_ABORTRETRYIGNORE:
1192 case MSGBOX_STYLE_CANCELTRYCONTINUE:
1200 _MessageBoxPresenter::GetBodyTextObjHeight(void) const
1202 return (__pBodyTextObject == null) ? 0.0f : __textObjHeight;
1205 _MessageBoxPresenter::GetBodyTextHeight(void) const
1207 return (__pBodyTextObject == null) ? 0.0f : __pBodyTextObject->GetTotalHeightF();
1211 _MessageBoxPresenter::GetTextBounds(void) const
1213 return __textBounds;
1217 _MessageBoxPresenter::SetReturnValue(MessageBoxModalResult rtn)
1219 __msgboxResult = rtn;
1223 _MessageBoxPresenter::GetReturnValue(void) const
1225 return (int) __msgboxResult;
1229 _MessageBoxPresenter::InitializeAccessibilityElement(void)
1231 result r = E_SUCCESS;
1233 _AccessibilityContainer* pContainer = null;
1235 pContainer = __pMessageBox->GetAccessibilityContainer();
1237 if (pContainer == null)
1242 if (__pLabel != null)
1244 _AccessibilityContainer* pLabelContainer = __pLabel->GetAccessibilityContainer();
1245 if (pLabelContainer != null)
1247 _AccessibilityElement* pLabelElement = pLabelContainer->GetChildElement(L"LabelText");
1248 if (pLabelElement != null)
1250 pLabelElement->SetName(L"MessageBoxText");
1251 pLabelElement->SetTrait(L"Popup body text");
1255 pContainer->AddChildContainer(*pLabelContainer);
1259 if (__pMessageBox->GetMsgBoxStyle() != MSGBOX_STYLE_NONE)
1261 for (int i = 0; i < __buttonNum; i++)
1263 _ControlImpl* pImpl = null;
1264 _Button* pButtonCore = null;
1266 pImpl = _ControlImpl::GetInstance(*__pButtons[i]);
1268 pButtonCore = dynamic_cast<_Button*>(&pImpl->GetCore());
1269 r = GetLastResult();
1270 SysTryReturnVoidResult(NID_UI_CTRL, pButtonCore != null, r, "[%s] Propagating.", GetErrorMessage(r));
1272 _AccessibilityContainer* pButtonContainer = pButtonCore->GetAccessibilityContainer();
1273 if (pButtonContainer != null)
1275 _AccessibilityElement* pButtonElement = pButtonContainer->GetChildElement(L"ButtonText");
1276 if (pButtonElement != null)
1278 String numberString = null;
1279 numberString = Integer::ToString(i + 1);
1281 String buttonName = L"MessageBoxButton";
1282 buttonName.Append(numberString);
1284 pButtonElement->SetName(buttonName);
1288 pContainer->AddChildContainer(*pButtonContainer);
1294 _AccessibilityElement* pElementMessageBox = new (std::nothrow) _AccessibilityElement(true);
1295 SysTryReturnVoidResult(NID_UI_CTRL, pElementMessageBox != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
1297 pElementMessageBox->SetSupportOperatingGesture(false);
1298 pElementMessageBox->SetName(L"MessageBox");
1299 pElementMessageBox->SetHint(L"double tap to close");
1300 pElementMessageBox->SetBounds(FloatRectangle(0.0f, 0.0f, __pMessageBox->GetBoundsF().width, __pMessageBox->GetBoundsF().height));
1301 pContainer->AddElement(*pElementMessageBox);
1306 _MessageBoxPresenter::GetCore(void)
1308 return static_cast <_Popup*>(__pMessageBox);
1312 _MessageBoxPresenter::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
1314 FloatPoint point = touchinfo.GetCurrentPosition();
1316 FloatRectangle rect(0.0f, 0.0f, __pMessageBox->GetBoundsF().width, __pMessageBox->GetBoundsF().height);
1318 // Touch-event's starting point is MessageBox's leftTop
1319 if (rect.Contains(point) == false)
1321 __touchOutBounds = true;
1325 __touchOutBounds = false;
1328 __touchPressFlag = true;
1330 if ((__pScroll != null) && (__textBounds.Contains(point) == true))
1332 __pScroll->SetScrollVisibility(true);
1334 __scrollStart = true;
1341 _MessageBoxPresenter::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
1343 if (__touchOutBounds == true)
1345 if (__pMessageBox->GetMsgBoxStyle() == MSGBOX_STYLE_NONE)
1347 if (__beginModal == true)
1349 SetReturnValue(MSGBOX_RESULT_CLOSE);
1350 _ModalLoopManager::GetInstance()->EndMainLoop(MSGBOX_RESULT_CLOSE, false);
1351 __beginModal = false;
1356 if (__touchPressFlag == false)
1358 __prevPositionY = -1.0f;
1360 __scrollStart = false;
1363 if (__pScroll != null)
1365 __pScroll->SetScrollVisibility(false);
1372 _MessageBoxPresenter::OnDrawFocus(void)
1374 _ControlImpl* pImpl = null;
1375 _Button* pButtonCore = null;
1377 if (__pButtons != null)
1379 pImpl = _ControlImpl::GetInstance(*__pButtons[0]);
1380 pButtonCore = dynamic_cast<_Button*>(&pImpl->GetCore());
1381 __pButtons[0]->SetFocus();
1382 __pMessageBox->SetFocusTraversalControl(pButtonCore, true);
1389 _MessageBoxPresenter::OnAccessibilityActionPerformed(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1391 if (__pMessageBox->GetMsgBoxStyle() == MSGBOX_STYLE_NONE)
1393 if (__beginModal == true)
1395 SetReturnValue(MSGBOX_RESULT_CLOSE);
1396 _ModalLoopManager::GetInstance()->EndMainLoop(MSGBOX_RESULT_CLOSE, false);
1397 __beginModal = false;
1405 _MessageBoxPresenter::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
1407 __touchOutBounds = false;
1409 if ((__pScroll != null) && (__scrollStart == true))
1411 float scrollAmountView = 0.0f;
1412 float scrollAmountData = 0.0f;
1413 float currentPosition = touchinfo.GetCurrentPosition().y;
1416 if (_FloatCompare(__prevPositionY, -1.0f))
1418 __prevPositionY = currentPosition;
1421 float distance = __prevPositionY - currentPosition;
1423 float newFirstDspY = __pBodyTextObject->GetFirstDisplayPositionYF();
1424 newFirstDspY += distance;
1426 if (newFirstDspY < 0.0f)
1428 newFirstDspY = 0.0f;
1431 if (newFirstDspY > __textBounds.height)
1433 newFirstDspY = __textBounds.height;
1436 int moveLine = __pBodyTextObject->GetLineIndexAtPositionY(newFirstDspY);
1438 __pBodyTextObject->SetFirstDisplayLineIndex(moveLine);
1439 __pBodyTextObject->SetFirstDisplayPositionY(newFirstDspY);
1442 __pScroll->GetScrollRange(&scrollAmountView, &scrollAmountData);
1443 __scrollPos += distance;
1445 if (__scrollPos < 0.0f)
1449 else if (__scrollPos > scrollAmountView)
1451 __scrollPos = scrollAmountView;
1454 __pScroll->SetScrollPosition(__scrollPos);
1456 __prevPositionY = currentPosition;
1458 __touchPressFlag = false;
1461 __pMessageBox->Show();
1469 _MessageBoxPresenter::OnKeyReleased(const _Control& source, const _KeyInfo& keyInfo)
1471 _KeyCode keyCode = keyInfo.GetKeyCode();
1473 if (keyCode == _KEY_ESC || keyCode == _KEY_BACK)
1475 MessageBoxStyle style = __pMessageBox->GetMsgBoxStyle();
1477 if ((__pButtonListener->GetBeginModal() == true) || (__beginModal == true))
1479 if (__pMessageBox->GetTimeout() != 0)
1483 case MSGBOX_STYLE_NONE:
1485 case MSGBOX_STYLE_OK:
1487 case MSGBOX_STYLE_YESNO:
1489 case MSGBOX_STYLE_ABORTRETRYIGNORE:
1490 _ModalLoopManager::GetInstance()->EndMainLoop(MSGBOX_BUTTON_CLOSE, false);
1491 __beginModal = false;
1494 case MSGBOX_STYLE_CANCEL:
1496 case MSGBOX_STYLE_OKCANCEL:
1498 case MSGBOX_STYLE_YESNOCANCEL:
1500 case MSGBOX_STYLE_CANCELTRYCONTINUE:
1502 case MSGBOX_STYLE_RETRYCANCEL:
1503 _ModalLoopManager::GetInstance()->EndMainLoop(MSGBOX_BUTTON_CANCEL, false);
1504 __beginModal = false;
1509 else if (style == MSGBOX_STYLE_CANCEL || style == MSGBOX_STYLE_OKCANCEL || style == MSGBOX_STYLE_YESNOCANCEL
1510 || style == MSGBOX_STYLE_CANCELTRYCONTINUE || style == MSGBOX_STYLE_RETRYCANCEL)
1512 _ModalLoopManager::GetInstance()->EndMainLoop(MSGBOX_BUTTON_CANCEL, false);
1513 __beginModal = false;
1521 ////////////////////////////////////////////////////////////////////////
1522 ///////////////////////////MsgBoxButtonListener/////////////////////////
1523 ////////////////////////////////////////////////////////////////////////
1525 _MessageBoxPresenter::_MessageBoxButtonListener::_MessageBoxButtonListener(void)
1527 , __buttonPressFlag(false)
1528 , __buttonReleaseState(false)
1529 , __beginModal(false)
1530 , __point(0.0f, 0.0f)
1535 _MessageBoxPresenter::_MessageBoxButtonListener::~_MessageBoxButtonListener(void)
1541 _MessageBoxPresenter::_MessageBoxButtonListener::GetClickedButtonHandle(void) const
1543 return __buttonHandle;
1547 _MessageBoxPresenter::_MessageBoxButtonListener::IsButtonClicked(void)
1549 return __buttonReleaseState;
1553 _MessageBoxPresenter::_MessageBoxButtonListener::OnTouchPressed(const Control& source, const Point& currentPosition,
1554 const TouchEventInfo& touchInfo)
1556 __buttonPressFlag = true;
1557 __buttonReleaseState = false;
1559 FloatPoint point = touchInfo.GetCurrentPositionF();
1564 _MessageBoxPresenter::_MessageBoxButtonListener::OnTouchMoved(const Control& source, const Point& currentPosition,
1565 const TouchEventInfo& touchInfo)
1567 //FloatPoint point = touchInfo.GetCurrentPositionF();
1569 __buttonPressFlag = false;
1573 _MessageBoxPresenter::_MessageBoxButtonListener::OnTouchReleased(const Control& source, const Point& currentPosition,
1574 const TouchEventInfo& touchInfo)
1576 if (__buttonPressFlag == true)
1578 __buttonHandle = _ControlImpl::GetInstance(source)->GetCore().GetHandle();
1579 SysTryReturnVoidResult(NID_UI_CTRL, __buttonHandle.IsValid() == true, E_SYSTEM, "[E_SYSTEM] Button's Handle is invalid");
1581 __buttonPressFlag = false;
1582 __buttonReleaseState = true;
1584 if (__beginModal == true)
1586 _ModalLoopManager::GetInstance()->EndMainLoop(MSGBOX_BUTTON_CLICKED, false);
1587 __beginModal = false;
1595 _MessageBoxPresenter::_MessageBoxButtonListener::OnKeyReleased(const Tizen::Ui::Control& source, Tizen::Ui::KeyCode keyCode)
1597 const _ControlImpl* pImpl = null;
1598 const _Button* pControl = null;
1600 pImpl = _ControlImpl::GetInstance(source);
1601 pControl = dynamic_cast<const _Button*>(&pImpl->GetCore());
1603 if (pControl != null)
1605 if (keyCode == KEY_ENTER)
1607 __buttonHandle = _ControlImpl::GetInstance(source)->GetCore().GetHandle();
1608 SysTryReturnVoidResult(NID_UI_CTRL, __buttonHandle.IsValid() == true, E_SYSTEM, "[E_SYSTEM] Button's Handle is invalid");
1610 __buttonPressFlag = false;
1611 __buttonReleaseState = true;
1613 if (__beginModal == true)
1615 _ModalLoopManager::GetInstance()->EndMainLoop(MSGBOX_BUTTON_CLICKED, false);
1616 __beginModal = false;
1625 _MessageBoxPresenter::_MessageBoxButtonListener::OnKeyPressed(const Tizen::Ui::Control& source, Tizen::Ui::KeyCode keyCode)
1627 const _ControlImpl* pImpl = null;
1628 const _Button* pControl = null;
1630 pImpl = _ControlImpl::GetInstance(source);
1631 pControl = dynamic_cast<const _Button*>(&pImpl->GetCore());
1633 if (pControl != null)
1635 _Button* pFocusControl = null;
1639 pFocusControl = dynamic_cast<_Button*>(pControl->GetNextFocus());
1643 pFocusControl = dynamic_cast<_Button*>(pControl->GetPreviousFocus());
1650 _Window* pTop = pControl->GetRootWindow();
1652 if (pFocusControl != null)
1654 pTop->SetFocusTraversalControl(pFocusControl, true);
1655 _Control* pParentControl = pFocusControl->GetParent();
1657 if (pParentControl != null)
1659 pParentControl->OnChildControlFocusMoved(*pFocusControl);
1662 pFocusControl->SetFocused();
1663 pFocusControl->DrawFocus();
1671 _MessageBoxPresenter::_MessageBoxButtonListener::SetBeginModal(bool beginModal)
1673 __beginModal = beginModal;
1677 _MessageBoxPresenter::_MessageBoxButtonListener::GetBeginModal(void)
1679 return __beginModal;
1682 }}} // Tizen::Ui::Controls