Focus Ui Message Box
[platform/framework/native/uifw.git] / src / ui / controls / FUiCtrl_MessageBoxPresenter.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0/
10 //
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.
16 //
17
18 /**
19  * @file                FUiCtrl_MessageBoxPresenter.cpp
20  * @brief       This is the implementation file for the _MessageBoxPresenter class.
21  */
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"
30 #include "FUi_Math.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"
42
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;
49
50
51 namespace Tizen { namespace Ui { namespace Controls
52 {
53
54
55 _MessageBoxPresenter::_MessageBoxPresenter(void)
56         : __pMessageBox(null)
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)
63         , __pLabel(null)
64         , __pScroll(null)
65         , __pScrollPanel(null)
66         , __scrollPos(0.0f)
67         , __buttonNum(0)
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)
76         , __beginModal(false)
77 {
78         for (int i = 0; i < 3; i++)
79         {
80                 __pButtons[i] = null;
81         }
82 }
83
84 _MessageBoxPresenter::~_MessageBoxPresenter(void)
85 {
86         for (int i = 0; i < __buttonNum; i++)
87         {
88                 delete __pButtons[i];
89                 __pButtons[i] = null;
90         }
91
92         delete __pButtonListener;
93         __pButtonListener = null;
94
95         if (__pBodyTextObject != null)
96         {
97                 __pBodyTextObject->RemoveAll();
98                 delete __pBodyTextObject;
99                 __pBodyTextObject = null;
100         }
101
102         if (__pLabel != null)
103         {
104                 __pScrollPanel->DetachChild(*__pLabel);
105                 delete __pLabel;
106                 __pLabel = null;
107         }
108
109         if (__pScrollPanel != null)
110         {
111                 __pMessageBox->DetachChild(*__pScrollPanel);
112                 delete __pScrollPanel;
113                 __pScrollPanel = null;
114         }
115
116         if (__pScroll != null)
117         {
118                 __pMessageBox->DetachSystemChild(*__pScroll);
119                 delete __pScroll;
120                 __pScroll = null;
121         }
122 }
123
124 result
125 _MessageBoxPresenter::OnChangeLayout(_ControlOrientation orientation)
126 {
127         result r = E_SUCCESS;
128
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;
135
136         float textTopMargin = 0.0f;
137
138         float titleTopMargin = 0.0f;
139         float titleLeftMargin = 0.0f;
140         float titleRightMargin = 0.0f;
141
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;
147
148         GET_SHAPE_CONFIG(POPUP::TITLE_TEXT_SIZE, orientation, titleTextSize);
149         GET_SHAPE_CONFIG(POPUP::MIN_TITLE_TEXT_SIZE, orientation, minTitleTextSize);
150
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);
154
155         GET_SHAPE_CONFIG(MESSAGEBOX::TEXT_TOP_MRAGIN, orientation, textTopMargin);
156
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);
160
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);
165
166         __textBounds.width = defaultWidth - GetLeftRightLabelMargin();
167         __titleBgBounds.width = defaultWidth - (transLeftMargin + transRightMargin);
168         __buttonBgBounds.width = defaultWidth - (transLeftMargin + transRightMargin);
169
170         // TitleText
171         if (__pMessageBox->HasTitle() == true)
172         {
173                 GET_SHAPE_CONFIG(MESSAGEBOX::TITLE_HEIGHT, orientation, titleHeight);
174
175                 _titleBounds.width = __textBounds.width;
176                 _pTitleTextObject->SetBounds(_titleBounds);
177
178                 r = CalculateTitleTextSize(titleTextSize, minTitleTextSize);
179                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
180
181                 _titleBounds.height = titleHeight - titleTopMargin;
182         }
183
184         // Text
185         __pBodyTextObject->SetBounds(__textBounds);
186
187         __pBodyTextObject->Compose();
188
189         // Text bounds
190         __pScrollPanel->SetBounds(__textBounds);
191
192         labelHeight = __pBodyTextObject->GetTotalHeightF();
193
194         if (labelHeight < __textObjHeight)
195         {
196                 __pLabel->SetBounds(FloatRectangle(0.0f, (__textObjHeight - labelHeight)/2.0f, __textBounds.width, labelHeight));
197         }
198         else
199         {
200                 __pLabel->SetBounds(FloatRectangle(0.0f, 0.0f, __textBounds.width, labelHeight));
201         }
202
203         for (int i = 0; i < __buttonNum; i++)
204         {
205                 r = __pButtons[i]->SetBounds(CalculateButtonPositionAndSize(i));
206                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
207         }
208
209         return r;
210 }
211
212 result
213 _MessageBoxPresenter::Initialize(_MessageBox& msgbox)
214 {
215         result r = E_SUCCESS;
216
217         float titleTextSize = 0.0f;
218         float bodyTextSize = 0.0f;
219
220         float defaultWidth = 0.0f;
221         float titleHeight = 0.0f;
222         float bottomHeight = 0.0f;
223         float maxHeight = 0.0f;
224
225         float textTopMargin = 0.0f;
226         float textTopMarginNoButton = 0.0f;
227         float textLeftMargin = 0.0f;
228
229         float titleTopMargin = 0.0f;
230         float titleLeftMargin = 0.0f;
231         float titleRightMargin = 0.0f;
232
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;
238
239         _ControlOrientation orientation;
240
241         __pMessageBox = &msgbox;
242
243         orientation = __pMessageBox->GetOrientation();
244
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);
248
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);
253
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);
257
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);
261
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);
267
268
269         __titleBgBounds= FloatRectangle(transLeftMargin, transTopMargin, _CoordinateSystemUtils::ConvertToFloat(defaultWidth) - (2 * transLeftMargin), titleHeight);
270
271
272         // TitleText
273         if (__pMessageBox->HasTitle() == true)
274         {
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.");
277
278                 r = _pTitleTextObject->Construct();
279                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
280
281                 FloatRectangle bounds = FloatRectangle(titleLeftMargin + transLeftMargin,
282                                                                                         titleTopMargin + transTopMargin,
283                                                                                         defaultWidth - (titleLeftMargin + titleRightMargin + transLeftMargin + transRightMargin),
284                                                                                         titleHeight - titleTopMargin);
285
286                 labelHeight = GetLabelHeight(_pTitleTextObject, const_cast <wchar_t*>(__pMessageBox->GetTitleText().GetPointer()),
287                                                                         __pMessageBox->GetTitleText().GetLength(), titleTextSize, bounds, true);
288
289                 r = GetLastResult();
290                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
291
292                 _titleBounds = FloatRectangle(titleLeftMargin + transLeftMargin,
293                                                                         __titleBgBounds.y + (__titleBgBounds.height - labelHeight) / 2,
294                                                                         defaultWidth - (titleLeftMargin + titleRightMargin + transLeftMargin + transRightMargin),
295                                                                         titleHeight - titleTopMargin);
296         }
297         else
298         {
299                 titleHeight = 0;
300         }
301
302         // Text bounds
303         __textBounds.SetBounds(textLeftMargin + transLeftMargin,
304                                                         titleHeight + textTopMargin + transTopMargin,
305                                                         defaultWidth - GetLeftRightLabelMargin(),
306                                                         __textObjHeight);
307
308
309         if ((__pMessageBox->HasTitle() == false) && (__pMessageBox->GetMsgBoxStyle() == MSGBOX_STYLE_NONE))
310         {
311                 __textBounds.y = transTopMargin + textTopMarginNoButton;
312         }
313
314         __pLabel = _Label::CreateLabelN();
315         SysTryCatch(NID_UI_CTRL, __pLabel != null, , E_OUT_OF_MEMORY, "[E_SYSTEM] Failed to create the scroll.");
316
317         __pBodyTextObject = new (std::nothrow) TextObject();
318         SysTryCatch(NID_UI_CTRL, __pBodyTextObject != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
319
320         r = __pBodyTextObject->Construct();
321         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
322
323         labelHeight = GetLabelHeight(__pBodyTextObject, const_cast <wchar_t*>(__pMessageBox->GetText().GetPointer()),
324                                                                 __pMessageBox->GetText().GetLength(), bodyTextSize, __textBounds, false);
325
326         r = GetLastResult();
327         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
328
329         if (__pMessageBox->GetText().GetLength() > 0)
330         {
331                 __textObjHeight = __pBodyTextObject->GetLineHeightAtF(0) * 3.0;
332                 __textBounds.height = __textObjHeight;
333         }
334
335         if (labelHeight < __textObjHeight)
336         {
337                 __pLabel->SetBounds(FloatRectangle(0.0f, (__textObjHeight - labelHeight)/2.0f, __textBounds.width, labelHeight));
338         }
339         else
340         {
341                 __pLabel->SetBounds(FloatRectangle(0.0f, 0.0f, __textBounds.width, labelHeight));
342         }
343
344
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);
349
350         __pScrollPanel = _ScrollPanel::CreateScrollPanelN(__textBounds, SCROLL_PANEL_SCROLL_DIRECTION_VERTICAL, true);
351
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);
357
358         __buttonBgBounds = FloatRectangle(transLeftMargin + __bgImageMargin, __pMessageBox->GetTotalHeight() - bottomHeight - transBottomMargin, _CoordinateSystemUtils::ConvertToFloat(defaultWidth)- (transLeftMargin + transRightMargin) - (2 * __bgImageMargin), bottomHeight - __bgImageMargin);
359
360         r = CreateButtons();
361         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
362
363         return r;
364
365 CATCH:
366         delete _pTitleTextObject;
367         _pTitleTextObject = null;
368
369         delete __pBodyTextObject;
370         __pBodyTextObject = null;
371
372         SetLastResult(r);
373         return r;
374 }
375
376 float
377 _MessageBoxPresenter::GetLabelHeight(TextObject* textObject, wchar_t* text, int length, float bodyTextSize, FloatRectangle bounds, bool isTitle)
378 {
379         TextSimple* pSimpleTextForBodyText = null;
380         result r = E_SUCCESS;
381
382         // Text
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.");
385
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);
391
392         if (isTitle == true)
393         {
394                 float minTitleTextSize = 0.0f;
395
396                 GET_SHAPE_CONFIG(MESSAGEBOX::MIN_TITLE_TEXT_SIZE, __pMessageBox->GetOrientation(), minTitleTextSize);
397
398                 r = CalculateTitleTextSize(bodyTextSize, minTitleTextSize);
399                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
400         }
401         else
402         {
403                 r = SetFontInfo(FONT_STYLE_PLAIN, bodyTextSize);
404                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set font.", GetErrorMessage(r));
405
406                 textObject->SetFont(_pFont, 0, textObject->GetTextLength());
407
408                 textObject->Compose();
409         }
410
411         SetLastResult(r);
412
413         return textObject->GetTotalHeightF();
414
415 CATCH:
416         return 0.0f;
417 }
418
419 float
420 _MessageBoxPresenter::GetLeftRightLabelMargin(void)
421 {
422         float textLeftMargin = 0.0f;
423         float textRightMargin = 0.0f;
424         float transLeftMargin = 0.0f;
425         float transRightMargin = 0.0f;
426
427         _ControlOrientation orientation = __pMessageBox->GetOrientation();
428
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);
433
434         return textLeftMargin + textRightMargin + transLeftMargin + transRightMargin;
435 }
436
437 void
438 _MessageBoxPresenter::Draw(void)
439 {
440         result r = E_SUCCESS;
441
442         float defaultWidth = 0.0f;
443         float textSize = 0.0f;
444
445         bool isCustomBitmap = false;
446
447         _ControlOrientation orientation;
448
449         orientation = __pMessageBox->GetOrientation();
450
451         GET_SHAPE_CONFIG(MESSAGEBOX::DEFAULT_WIDTH, orientation, defaultWidth);
452         GET_SHAPE_CONFIG(MESSAGEBOX::TEXT_SIZE, orientation, textSize);
453
454         Canvas* pCanvas = __pMessageBox->GetCanvasN();
455         SysTryReturnVoidResult(NID_UI_CTRL, (pCanvas != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Unable to create canvas.");
456
457         pCanvas->SetBackgroundColor(Color(0x00000000));
458         pCanvas->Clear();
459
460         float totalH = __pMessageBox->GetTotalHeight();
461
462         FloatRectangle bgBounds(0.0f, 0.0f, _CoordinateSystemUtils::ConvertToFloat(defaultWidth), totalH);
463
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();
470
471         isCustomBitmap = IS_CUSTOM_BITMAP(MESSAGEBOX::BG_NORMAL);
472         // Draw BG
473         if (pBackgroundBitmap != null)
474         {
475                 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pBackgroundBitmap))
476                 {
477                         pCanvas->DrawNinePatchedBitmap(bgBounds, *pBackgroundBitmap);
478                 }
479                 else
480                 {
481                         pCanvas->DrawBitmap(bgBounds, *pBackgroundBitmap);
482                 }
483         }
484
485         // Draw Outline
486         if (!isCustomBitmap && pOutlineBitmap != null)
487         {
488                 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pOutlineBitmap))
489                 {
490                         pCanvas->DrawNinePatchedBitmap(bgBounds, *pOutlineBitmap);
491                 }
492                 else
493                 {
494                         pCanvas->DrawBitmap(bgBounds, *pOutlineBitmap);
495                 }
496         }
497
498         //DrawButtonBG
499         if(pButtonBitmap != null)
500         {
501                 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pButtonBitmap))
502                 {
503                         pCanvas->DrawNinePatchedBitmap(__buttonBgBounds, *pButtonBitmap);
504                 }
505                 else
506                 {
507                         pCanvas->DrawBitmap(__buttonBgBounds, *pButtonBitmap);
508                 }
509         }
510         //DrawEffectButtonBitmap
511         if (pButtonEffectBitmap != null)
512         {
513                 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pButtonEffectBitmap))
514                 {
515                         pCanvas->DrawNinePatchedBitmap(__buttonBgBounds, *pButtonEffectBitmap);
516                 }
517                 else
518                 {
519                         pCanvas->DrawBitmap(__buttonBgBounds, *pButtonEffectBitmap);
520                 }
521         }
522
523         // Draw Title
524         if (_pTitleTextObject != null)
525         {
526                 //DrawTitleBG
527                 if(pTitleBitmap != null)
528                 {
529                         if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pTitleBitmap))
530                         {
531                                 pCanvas->DrawNinePatchedBitmap(__titleBgBounds, *pTitleBitmap);
532                         }
533                         else
534                         {
535                                 pCanvas->DrawBitmap(__titleBgBounds, *pTitleBitmap);
536                         }
537                 }
538                 //DrawEffectTitleBitmap
539                 if (pTitleEffectBitmap != null)
540                 {
541                         if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pTitleEffectBitmap))
542                         {
543                                 pCanvas->DrawNinePatchedBitmap(__titleBgBounds, *pTitleEffectBitmap);
544                         }
545                         else
546                         {
547                                 pCanvas->DrawBitmap(__titleBgBounds, *pTitleEffectBitmap);
548                         }
549                 }
550                 r = SetFontInfo(FONT_STYLE_PLAIN, _titleTextSize);
551                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
552
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));
557         }
558
559         __pLabel->SetTextColor(__pMessageBox->GetTextColor());
560         //fall thtrough
561 CATCH:
562         delete pCanvas;
563
564         return;
565 }
566
567 result
568 _MessageBoxPresenter::ShowAndWait(int& modalResult)
569 {
570         result r = E_SUCCESS;
571
572         r = __pMessageBox->Open();
573
574         __pMessageBox->SetTouchCapture(false, false);
575
576         ProcessEvent();
577
578         __pMessageBox->ReleaseTouchCapture();
579
580         __pMessageBox->Close();
581
582         modalResult = GetReturnValue();
583
584         return r;
585 }
586
587 void
588 _MessageBoxPresenter::ProcessEvent(void)
589 {
590         _ControlHandle handle;
591
592         _TouchManager* pTouchManager = _TouchManager::GetInstance();
593         if (pTouchManager)
594         {
595                 _Control* pControl = pTouchManager->GetTouchControlSource();
596                 if (pControl)
597                 {
598                         pControl->SetEventEnableState(false);
599                 }
600         }
601
602         if (__pMessageBox->GetMsgBoxStyle() == MSGBOX_STYLE_NONE)
603         {
604                 __beginModal = true;
605         }
606         else if (__pButtonListener != null)
607         {
608                 __pButtonListener->SetBeginModal(true);
609         }
610
611         _ModalLoopManager::GetInstance()->BeginMainLoop(__pMessageBox->GetTimeout(), MSGBOX_RESULT_CLOSE);
612
613         int exitCode = _ModalLoopManager::GetInstance()->GetLastExitCode();
614         switch (exitCode)
615         {
616         case MSGBOX_BUTTON_CLICKED:
617                 if (__pButtonListener != null && __pButtonListener->IsButtonClicked())
618                 {
619                         handle = __pButtonListener->GetClickedButtonHandle();
620                         FindButtonAndResult(handle);
621                         break;
622                 }
623         case MSGBOX_BUTTON_CLOSE:
624                 SetReturnValue(MSGBOX_RESULT_CLOSE);
625                 break;
626
627         case MSGBOX_BUTTON_CANCEL:
628                 SetReturnValue(MSGBOX_RESULT_CANCEL);
629                 break;
630
631                 // fall through
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;
636                 break;
637         }
638
639         if (__pMessageBox->GetMsgBoxStyle() == MSGBOX_STYLE_NONE)
640         {
641                 __beginModal = false;
642         }
643         else if (__pButtonListener != null)
644         {
645                 __pButtonListener->SetBeginModal(false);
646         }
647  }
648
649 void
650 _MessageBoxPresenter::GetButtonString(void)
651 {
652         switch (__pMessageBox->GetMsgBoxStyle())
653         {
654         case MSGBOX_STYLE_NONE:
655                 __buttonNum = 0;
656                 break;
657
658         case MSGBOX_STYLE_OK:
659                 __buttonNum = 1;
660                 GET_STRING_CONFIG(IDS_TPLATFORM_BUTTON_OK, __buttonText[0]);
661                 break;
662
663         case MSGBOX_STYLE_CANCEL:
664                 __buttonNum = 1;
665                 GET_STRING_CONFIG(IDS_TPLATFORM_BUTTON_CANCEL_ABB, __buttonText[0]);
666                 break;
667
668         case MSGBOX_STYLE_OKCANCEL:
669                 __buttonNum = 2;
670                 GET_STRING_CONFIG(IDS_TPLATFORM_BUTTON_OK, __buttonText[1]);
671                 GET_STRING_CONFIG(IDS_TPLATFORM_BUTTON_CANCEL_ABB, __buttonText[0]);
672                 break;
673
674         case MSGBOX_STYLE_YESNO:
675                 __buttonNum = 2;
676                 GET_STRING_CONFIG(IDS_TPLATFORM_BUTTON_YES, __buttonText[1]);
677                 GET_STRING_CONFIG(IDS_TPLATFORM_BUTTON_NO, __buttonText[0]);
678                 break;
679
680         case MSGBOX_STYLE_YESNOCANCEL:
681                 __buttonNum = 3;
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]);
685                 break;
686
687         case MSGBOX_STYLE_ABORTRETRYIGNORE:
688                 __buttonNum = 3;
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]);
692                 break;
693
694         case MSGBOX_STYLE_CANCELTRYCONTINUE:
695                 __buttonNum = 3;
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]);
699                 break;
700
701         case MSGBOX_STYLE_RETRYCANCEL:
702                 __buttonNum = 2;
703                 GET_STRING_CONFIG(IDS_TPLATFORM_BUTTON_RETRY, __buttonText[1]);
704                 GET_STRING_CONFIG(IDS_TPLATFORM_BUTTON_CANCEL_ABB, __buttonText[0]);
705                 break;
706
707         default:
708                 break;
709         }
710 }
711
712 void
713 _MessageBoxPresenter::UpdateButtonString(void)
714 {
715         GetButtonString();
716
717         for (int i = 0; i < __buttonNum; i++)
718         {
719                 __pButtons[i]->SetText(__buttonText[i]);
720         }
721 }
722
723 result
724 _MessageBoxPresenter::CreateButtons(void)
725 {
726         result r = E_SUCCESS;
727         GetButtonString();
728         //Button Colors
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;
738
739
740         Bitmap* pButtonBgNormal = null;
741         Bitmap* pButtonBgPressed = null;
742         Bitmap* pButtonBgDisabled = null;
743         Bitmap* pButtonBgHighlighted = null;
744
745         Bitmap* pComposedButtonBgNormal = null;
746         Bitmap* pComposedButtonBgPressed = null;
747         Bitmap* pComposedButtonBgDisabled = null;
748         Bitmap* pComposedButtonBgHighlighted = null;
749
750         Bitmap* pButtonNormalEffect = null;
751         Bitmap* pButtonPressedEffect = null;
752         Bitmap* pButtonDisabledEffect = null;
753
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);
758
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);
763
764         GET_BITMAP_CONFIG_N(MESSAGEBOX::BOTTOM_BUTTON_BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, pButtonBgNormal);
765         r = GetLastResult();
766         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating. Failed to load Bottom button normal Image.", GetErrorMessage(r));
767
768         isCustomBitmap = IS_CUSTOM_BITMAP(MESSAGEBOX::BOTTOM_BUTTON_BG_NORMAL);
769
770         if (!isCustomBitmap)
771         {
772                 GET_BITMAP_CONFIG_N(MESSAGEBOX::BOTTOM_BUTTON_NORMAL_EFFECT, BITMAP_PIXEL_FORMAT_ARGB8888, pButtonNormalEffect);
773                 r = GetLastResult();
774                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating. Failed to load Bottom button normal effect Image.", GetErrorMessage(r));
775         }
776
777         GET_BITMAP_CONFIG_N(MESSAGEBOX::BOTTOM_BUTTON_BG_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, pButtonBgPressed);
778         r = GetLastResult();
779         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating. Failed to load Bottom button pressed Image.", GetErrorMessage(r));
780
781         isCustomBitmap = IS_CUSTOM_BITMAP(MESSAGEBOX::BOTTOM_BUTTON_BG_PRESSED);
782
783         if (!isCustomBitmap)
784         {
785                 GET_BITMAP_CONFIG_N(MESSAGEBOX::BOTTOM_BUTTON_PRESSED_EFFECT, BITMAP_PIXEL_FORMAT_ARGB8888, pButtonPressedEffect);
786                 r = GetLastResult();
787                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating. Failed to load Bottom button pressed effect Image.", GetErrorMessage(r));
788         }
789
790         GET_BITMAP_CONFIG_N(MESSAGEBOX::BOTTOM_BUTTON_BG_DISABLED, BITMAP_PIXEL_FORMAT_ARGB8888, pButtonBgDisabled);
791         r = GetLastResult();
792         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating. Failed to load Bottom button disabled Image.", GetErrorMessage(r));
793
794         isCustomBitmap = IS_CUSTOM_BITMAP(MESSAGEBOX::BOTTOM_BUTTON_BG_DISABLED);
795
796         if (!isCustomBitmap)
797         {
798                 GET_BITMAP_CONFIG_N(MESSAGEBOX::BOTTOM_BUTTON_DISABLED_EFFECT, BITMAP_PIXEL_FORMAT_ARGB8888, pButtonDisabledEffect);
799                 r = GetLastResult();
800                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating. Failed to load Bottom button disabled effect Image.", GetErrorMessage(r));
801         }
802
803         GET_BITMAP_CONFIG_N(MESSAGEBOX::BOTTOM_BUTTON_BG_HIGHLIGHTED, BITMAP_PIXEL_FORMAT_ARGB8888, pButtonBgHighlighted);
804         r = GetLastResult();
805         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating. Failed to load Bottom button highlighted Image.", GetErrorMessage(r));
806
807         pComposedButtonBgNormal = _BitmapImpl::GetColorReplacedBitmapN(*pButtonBgNormal, Color::GetColor(COLOR_ID_MAGENTA), buttonColorNormal);
808         r = GetLastResult();
809         SysTryCatch(NID_UI_CTRL, (pComposedButtonBgNormal != null), , r, "[%s] Propagating.", GetErrorMessage(r));
810
811         pComposedButtonBgPressed = _BitmapImpl::GetColorReplacedBitmapN(*pButtonBgPressed, Color::GetColor(COLOR_ID_MAGENTA), buttonColorPressed);
812         r = GetLastResult();
813         SysTryCatch(NID_UI_CTRL, (pComposedButtonBgPressed != null), , r, "[%s] Propagating.", GetErrorMessage(r));
814
815         pComposedButtonBgDisabled = _BitmapImpl::GetColorReplacedBitmapN(*pButtonBgDisabled, Color::GetColor(COLOR_ID_MAGENTA), buttonColorDisabled);
816         r = GetLastResult();
817         SysTryCatch(NID_UI_CTRL, (pComposedButtonBgDisabled != null), , r, "[%s] Propagating.", GetErrorMessage(r));
818
819         pComposedButtonBgHighlighted = _BitmapImpl::GetColorReplacedBitmapN(*pButtonBgHighlighted, Color::GetColor(COLOR_ID_MAGENTA), buttonColorHighlighted);
820         r = GetLastResult();
821         SysTryCatch(NID_UI_CTRL, (pComposedButtonBgHighlighted != null), , r, "[%s] Propagating.", GetErrorMessage(r));
822
823         __pButtonListener = new (std::nothrow) _MessageBoxButtonListener();
824         SysTryCatch(NID_UI_CTRL, __pButtonListener != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
825
826         for (int i = 0; i < __buttonNum; i++)
827         {
828                 _ControlImpl* pImpl = null;
829                 _Button* pButtonCore = null;
830
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.");
833
834                 r = __pButtons[i]->Construct(CalculateButtonPositionAndSize(i));
835                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
836
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);
848
849                 pImpl = _ControlImpl::GetInstance(*__pButtons[i]);
850                 pButtonCore = dynamic_cast<_Button*>(&pImpl->GetCore());
851
852                 if (pButtonCore != null)
853                 {
854                         pButtonCore->SetTouchPressThreshold(0.16);
855                         __pMessageBox->AttachChild(*pButtonCore);
856
857                         if (pButtonNormalEffect != null)
858                         {
859                           pButtonCore->SetBackgroundEffectBitmap(_BUTTON_STATUS_NORMAL, *pButtonNormalEffect);
860                         }
861
862                         if (pButtonPressedEffect != null)
863                         {
864                                 pButtonCore->SetBackgroundEffectBitmap(_BUTTON_STATUS_PRESSED, *pButtonPressedEffect);
865                         }
866
867                         if(pButtonDisabledEffect != null)
868                         {
869                                 pButtonCore->SetBackgroundEffectBitmap(_BUTTON_STATUS_DISABLED, *pButtonDisabledEffect);
870                         }
871                 }
872
873                 if (i != 0)
874                 {
875                         __pButtons[i-1]->SetNextFocus(__pButtons[i]);
876                         __pButtons[i]->SetPreviousFocus(__pButtons[i-1]);
877                 }
878
879         }
880
881         delete pButtonBgNormal;
882         pButtonBgNormal = null;
883
884         delete pButtonBgPressed;
885         pButtonBgPressed = null;
886
887         delete pButtonBgDisabled;
888         pButtonBgDisabled = null;
889
890         delete pButtonBgHighlighted;
891         pButtonBgHighlighted = null;
892
893         delete pComposedButtonBgNormal;
894         pComposedButtonBgNormal = null;
895
896         delete pComposedButtonBgPressed;
897         pComposedButtonBgPressed = null;
898
899         delete pComposedButtonBgDisabled;
900         pComposedButtonBgDisabled = null;
901
902         delete pComposedButtonBgHighlighted;
903         pComposedButtonBgHighlighted = null;
904
905         delete pButtonNormalEffect;
906         pButtonNormalEffect = null;
907
908         delete pButtonPressedEffect;
909         pButtonNormalEffect = null;
910
911         delete pButtonDisabledEffect;
912         pButtonNormalEffect = null;
913
914         return r;
915
916 CATCH:
917
918         delete pButtonBgNormal;
919         pButtonBgNormal = null;
920
921         delete pButtonBgPressed;
922         pButtonBgPressed = null;
923
924         delete pButtonBgDisabled;
925         pButtonBgDisabled = null;
926
927         delete pButtonBgHighlighted;
928         pButtonBgHighlighted = null;
929
930         delete pComposedButtonBgNormal;
931         pComposedButtonBgNormal = null;
932
933         delete pComposedButtonBgPressed;
934         pComposedButtonBgPressed = null;
935
936         delete pComposedButtonBgDisabled;
937         pComposedButtonBgDisabled = null;
938
939         delete pComposedButtonBgHighlighted;
940         pComposedButtonBgHighlighted = null;
941
942         delete pButtonNormalEffect;
943         pButtonNormalEffect = null;
944
945         delete pButtonPressedEffect;
946         pButtonNormalEffect = null;
947
948         delete pButtonDisabledEffect;
949         pButtonNormalEffect = null;
950
951         delete __pButtonListener;
952         __pButtonListener = null;
953
954         for (int i = 0; i < __buttonNum; i++)
955         {
956                 delete __pButtons[i];
957                 __pButtons[i] = null;
958         }
959         return r;
960 }
961
962 FloatRectangle
963 _MessageBoxPresenter::CalculateButtonPositionAndSize(int buttonIndex)
964 {
965         float x = 0.0f;
966         float y = 0.0f;
967         float w = 0.0f;
968         float h = 0.0f;
969
970         float defaultWidth = 0.0f;
971         float btnHeight = 0.0f;
972
973         float btnSideMargin1 = 0.0f;
974         float btnSideMargin2 = 0.0f;
975         float btnSideMargin3 = 0.0f;
976         float btnTopMargin = 0.0f;
977
978         float btnGap = 0.0f;
979         float textTopMargin = 0.0f;
980
981         float titleHeight = 0.0f;
982         float transTopMargin = 0.0f;
983
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);
988
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);
993
994         GET_SHAPE_CONFIG(MESSAGEBOX::BUTTON_INTERNAL_GAP, orientation, btnGap);
995         GET_SHAPE_CONFIG(MESSAGEBOX::TEXT_TOP_MRAGIN, orientation, textTopMargin);
996
997         GET_SHAPE_CONFIG(MESSAGEBOX::TITLE_HEIGHT, orientation, titleHeight);
998         GET_SHAPE_CONFIG(MESSAGEBOX::BG_IMAGE_TRANSPARENT_TOP_MARGIN, orientation, transTopMargin);
999
1000         if (__pMessageBox->HasTitle() == false)
1001         {
1002                 titleHeight = 0.0f;
1003         }
1004
1005         switch (__buttonNum)
1006         {
1007         case 1:
1008                 w = defaultWidth - (btnSideMargin1 * 2.0f);
1009                 h = btnHeight;
1010                 x = btnSideMargin1;
1011                 break;
1012
1013         case 2:
1014                 w = (defaultWidth - (btnSideMargin2 * 2.0f) - btnGap) / 2.0f;
1015                 h = btnHeight;
1016                 x = btnSideMargin2 + (buttonIndex * (w + btnGap));
1017                 break;
1018
1019         case 3:
1020         {
1021                 switch (buttonIndex)
1022                 {
1023                 case 0:
1024                         // fall through
1025                 case 1:
1026                         // fall through
1027                 case 2:
1028                         w = (defaultWidth - ((btnSideMargin3 + btnGap) * 2.0f)) / 3.0f;
1029                         h = btnHeight;
1030                         x = btnSideMargin3 + (buttonIndex * (w + btnGap));
1031                         break;
1032                 }
1033                 break;
1034         }
1035         default:
1036                 break;
1037         }
1038         y = __buttonBgBounds.y + (__buttonBgBounds.height - h) / 2;
1039         return FloatRectangle(x, y, w, h);
1040 }
1041
1042 void
1043 _MessageBoxPresenter::FindButtonAndResult(const _ControlHandle handle)
1044 {
1045         int btnPos = -1;
1046
1047         for (int i = 0; i < __buttonNum; i++)
1048         {
1049                 _ControlImpl* pImpl = _ControlImpl::GetInstance(*__pButtons[i]);
1050                 if (pImpl->GetCore().GetHandle() == handle)
1051                 {
1052                         btnPos = i;
1053                         break;
1054                 }
1055         }
1056
1057         switch (__pMessageBox->GetMsgBoxStyle())
1058         {
1059         case MSGBOX_STYLE_NONE:
1060                 SetReturnValue(MSGBOX_RESULT_CLOSE);
1061                 break;
1062
1063         case MSGBOX_STYLE_OK:
1064                 SetReturnValue(MSGBOX_RESULT_OK);
1065                 break;
1066
1067         case MSGBOX_STYLE_CANCEL:
1068                 SetReturnValue(MSGBOX_RESULT_CANCEL);
1069                 break;
1070
1071         case MSGBOX_STYLE_OKCANCEL:
1072                 switch (btnPos)
1073                 {
1074                 case 0:
1075                         SetReturnValue(MSGBOX_RESULT_CANCEL);
1076                         break;
1077
1078                 case 1:
1079                         SetReturnValue(MSGBOX_RESULT_OK);
1080                         break;
1081                 }
1082                 break;
1083
1084         case MSGBOX_STYLE_YESNO:
1085                 switch (btnPos)
1086                 {
1087                 case 0:
1088                         SetReturnValue(MSGBOX_RESULT_NO);
1089                         break;
1090
1091                 case 1:
1092                         SetReturnValue(MSGBOX_RESULT_YES);
1093                         break;
1094                 }
1095                 break;
1096
1097         case MSGBOX_STYLE_YESNOCANCEL:
1098                 switch (btnPos)
1099                 {
1100                 case 0:
1101                         SetReturnValue(MSGBOX_RESULT_CANCEL);
1102                         break;
1103
1104                 case 1:
1105                         SetReturnValue(MSGBOX_RESULT_NO);
1106                         break;
1107
1108                 case 2:
1109                         SetReturnValue(MSGBOX_RESULT_YES);
1110                         break;
1111                 }
1112                 break;
1113
1114         case MSGBOX_STYLE_ABORTRETRYIGNORE:
1115                 switch (btnPos)
1116                 {
1117                 case 0:
1118                         SetReturnValue(MSGBOX_RESULT_ABORT);
1119                         break;
1120
1121                 case 1:
1122                         SetReturnValue(MSGBOX_RESULT_RETRY);
1123                         break;
1124
1125                 case 2:
1126                         SetReturnValue(MSGBOX_RESULT_IGNORE);
1127                         break;
1128                 }
1129                 break;
1130
1131         case MSGBOX_STYLE_CANCELTRYCONTINUE:
1132                 switch (btnPos)
1133                 {
1134                 case 0:
1135                         SetReturnValue(MSGBOX_RESULT_CANCEL);
1136                         break;
1137
1138                 case 1:
1139                         SetReturnValue(MSGBOX_RESULT_TRY);
1140                         break;
1141
1142                 case 2:
1143                         SetReturnValue(MSGBOX_RESULT_CONTINUE);
1144                         break;
1145                 }
1146                 break;
1147
1148         case MSGBOX_STYLE_RETRYCANCEL:
1149                 switch (btnPos)
1150                 {
1151                 case 0:
1152                         SetReturnValue(MSGBOX_RESULT_CANCEL);
1153                         break;
1154
1155                 case 1:
1156                         SetReturnValue(MSGBOX_RESULT_RETRY);
1157                         break;
1158                 }
1159                 break;
1160
1161         default:
1162                 break;
1163         }
1164 }
1165
1166 float
1167 _MessageBoxPresenter::CalculateButtonAreaHeight(void)
1168 {
1169         float btnHeight = 0.0f;
1170
1171         GET_SHAPE_CONFIG(MESSAGEBOX::BUTTON_HEIGHT, __pMessageBox->GetOrientation(), btnHeight);
1172
1173         switch (__pMessageBox->GetMsgBoxStyle())
1174         {
1175         case MSGBOX_STYLE_NONE:
1176                 return 0;
1177
1178         case MSGBOX_STYLE_OK:
1179                                         // fall through
1180         case MSGBOX_STYLE_CANCEL:
1181                                         // fall through
1182         case MSGBOX_STYLE_OKCANCEL:
1183                                         // fall through
1184         case MSGBOX_STYLE_YESNO:
1185                                         // fall through
1186         case MSGBOX_STYLE_RETRYCANCEL:
1187                                         // fall through
1188         case MSGBOX_STYLE_YESNOCANCEL:
1189                                         // fall through
1190         case MSGBOX_STYLE_ABORTRETRYIGNORE:
1191                                         // fall through
1192         case MSGBOX_STYLE_CANCELTRYCONTINUE:
1193                 return btnHeight;
1194         }
1195
1196         return -1.0f;
1197 }
1198
1199 float
1200 _MessageBoxPresenter::GetBodyTextObjHeight(void) const
1201 {
1202         return (__pBodyTextObject == null) ? 0.0f : __textObjHeight;
1203 }
1204 float
1205 _MessageBoxPresenter::GetBodyTextHeight(void) const
1206 {
1207         return (__pBodyTextObject == null) ? 0.0f : __pBodyTextObject->GetTotalHeightF();
1208 }
1209
1210 FloatRectangle
1211 _MessageBoxPresenter::GetTextBounds(void) const
1212 {
1213         return __textBounds;
1214 }
1215
1216 void
1217 _MessageBoxPresenter::SetReturnValue(MessageBoxModalResult rtn)
1218 {
1219         __msgboxResult = rtn;
1220 }
1221
1222 int
1223 _MessageBoxPresenter::GetReturnValue(void) const
1224 {
1225         return (int) __msgboxResult;
1226 }
1227
1228 void
1229 _MessageBoxPresenter::InitializeAccessibilityElement(void)
1230 {
1231         result r = E_SUCCESS;
1232
1233         _AccessibilityContainer* pContainer = null;
1234
1235         pContainer = __pMessageBox->GetAccessibilityContainer();
1236
1237         if (pContainer == null)
1238         {
1239                 return ;
1240         }
1241
1242         if (__pLabel != null)
1243         {
1244                 _AccessibilityContainer* pLabelContainer = __pLabel->GetAccessibilityContainer();
1245                 if (pLabelContainer != null)
1246                 {
1247                         _AccessibilityElement* pLabelElement = pLabelContainer->GetChildElement(L"LabelText");
1248                         if (pLabelElement != null)
1249                         {
1250                                 pLabelElement->SetName(L"MessageBoxText");
1251                                 pLabelElement->SetTrait(L"Popup body text");
1252                         }
1253
1254                         // Add Container
1255                         pContainer->AddChildContainer(*pLabelContainer);
1256                 }
1257         }
1258
1259         if (__pMessageBox->GetMsgBoxStyle() != MSGBOX_STYLE_NONE)
1260         {
1261                 for (int i = 0; i < __buttonNum; i++)
1262                 {
1263                         _ControlImpl* pImpl = null;
1264                         _Button* pButtonCore = null;
1265
1266                         pImpl = _ControlImpl::GetInstance(*__pButtons[i]);
1267
1268                         pButtonCore = dynamic_cast<_Button*>(&pImpl->GetCore());
1269                         r = GetLastResult();
1270                         SysTryReturnVoidResult(NID_UI_CTRL, pButtonCore != null, r, "[%s] Propagating.", GetErrorMessage(r));
1271
1272                         _AccessibilityContainer* pButtonContainer = pButtonCore->GetAccessibilityContainer();
1273                         if (pButtonContainer != null)
1274                         {
1275                                 _AccessibilityElement* pButtonElement = pButtonContainer->GetChildElement(L"ButtonText");
1276                                 if (pButtonElement != null)
1277                                 {
1278                                         String numberString = null;
1279                                         numberString = Integer::ToString(i + 1);
1280
1281                                         String buttonName = L"MessageBoxButton";
1282                                         buttonName.Append(numberString);
1283
1284                                         pButtonElement->SetName(buttonName);
1285                                 }
1286
1287                                 // Add Container
1288                                 pContainer->AddChildContainer(*pButtonContainer);
1289                         }
1290                 }
1291         }
1292         else
1293         {
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.");
1296
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);
1302         }
1303 }
1304
1305 _Popup*
1306 _MessageBoxPresenter::GetCore(void)
1307 {
1308         return static_cast <_Popup*>(__pMessageBox);
1309 }
1310
1311 bool
1312 _MessageBoxPresenter::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
1313 {
1314         FloatPoint point = touchinfo.GetCurrentPosition();
1315
1316         FloatRectangle rect(0.0f, 0.0f, __pMessageBox->GetBoundsF().width, __pMessageBox->GetBoundsF().height);
1317
1318         // Touch-event's starting point is MessageBox's leftTop
1319         if (rect.Contains(point) == false)
1320         {
1321                 __touchOutBounds = true;
1322         }
1323         else
1324         {
1325                 __touchOutBounds = false;
1326         }
1327
1328         __touchPressFlag = true;
1329
1330         if ((__pScroll != null) && (__textBounds.Contains(point) == true))
1331         {
1332                 __pScroll->SetScrollVisibility(true);
1333
1334                 __scrollStart = true;
1335         }
1336
1337         return true;
1338 }
1339
1340 bool
1341 _MessageBoxPresenter::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
1342 {
1343         if (__touchOutBounds == true)
1344         {
1345                 if (__pMessageBox->GetMsgBoxStyle() == MSGBOX_STYLE_NONE)
1346                 {
1347                         if (__beginModal == true)
1348                         {
1349                                 SetReturnValue(MSGBOX_RESULT_CLOSE);
1350                                 _ModalLoopManager::GetInstance()->EndMainLoop(MSGBOX_RESULT_CLOSE, false);
1351                                 __beginModal = false;
1352                         }
1353                 }
1354         }
1355
1356         if (__touchPressFlag == false)
1357         {
1358                 __prevPositionY = -1.0f;
1359
1360                 __scrollStart = false;
1361         }
1362
1363         if (__pScroll != null)
1364         {
1365                 __pScroll->SetScrollVisibility(false);
1366         }
1367
1368         return true;
1369 }
1370
1371 void
1372 _MessageBoxPresenter::OnDrawFocus(void)
1373 {
1374         _ControlImpl* pImpl = null;
1375         _Button* pButtonCore = null;
1376
1377         if (__pButtons != null)
1378         {
1379                 pImpl = _ControlImpl::GetInstance(*__pButtons[0]);
1380                 pButtonCore = dynamic_cast<_Button*>(&pImpl->GetCore());
1381                 __pButtons[0]->SetFocus();
1382                 __pMessageBox->SetFocusTraversalControl(pButtonCore, true);
1383         }
1384
1385         return;
1386 }
1387
1388 bool
1389 _MessageBoxPresenter::OnAccessibilityActionPerformed(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1390 {
1391         if (__pMessageBox->GetMsgBoxStyle() == MSGBOX_STYLE_NONE)
1392         {
1393                 if (__beginModal == true)
1394                 {
1395                         SetReturnValue(MSGBOX_RESULT_CLOSE);
1396                         _ModalLoopManager::GetInstance()->EndMainLoop(MSGBOX_RESULT_CLOSE, false);
1397                         __beginModal = false;
1398                 }
1399         }
1400
1401         return true;
1402 }
1403
1404 bool
1405 _MessageBoxPresenter::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
1406 {
1407         __touchOutBounds = false;
1408
1409         if ((__pScroll != null) && (__scrollStart == true))
1410         {
1411                 float scrollAmountView = 0.0f;
1412                 float scrollAmountData = 0.0f;
1413                 float currentPosition = touchinfo.GetCurrentPosition().y;
1414
1415                 // TextObject
1416                 if (_FloatCompare(__prevPositionY, -1.0f))
1417                 {
1418                         __prevPositionY = currentPosition;
1419                 }
1420
1421                 float distance = __prevPositionY - currentPosition;
1422
1423                 float newFirstDspY = __pBodyTextObject->GetFirstDisplayPositionYF();
1424                 newFirstDspY += distance;
1425
1426                 if (newFirstDspY < 0.0f)
1427                 {
1428                         newFirstDspY = 0.0f;
1429                 }
1430
1431                 if (newFirstDspY > __textBounds.height)
1432                 {
1433                         newFirstDspY = __textBounds.height;
1434                 }
1435
1436                 int moveLine = __pBodyTextObject->GetLineIndexAtPositionY(newFirstDspY);
1437
1438                 __pBodyTextObject->SetFirstDisplayLineIndex(moveLine);
1439                 __pBodyTextObject->SetFirstDisplayPositionY(newFirstDspY);
1440
1441                 // _Scroll
1442                 __pScroll->GetScrollRange(&scrollAmountView, &scrollAmountData);
1443                 __scrollPos += distance;
1444
1445                 if (__scrollPos < 0.0f)
1446                 {
1447                         __scrollPos = 0.0f;
1448                 }
1449                 else if (__scrollPos > scrollAmountView)
1450                 {
1451                         __scrollPos = scrollAmountView;
1452                 }
1453
1454                 __pScroll->SetScrollPosition(__scrollPos);
1455
1456                 __prevPositionY = currentPosition;
1457
1458                 __touchPressFlag = false;
1459
1460                 Draw();
1461                 __pMessageBox->Show();
1462         }
1463
1464         return true;
1465
1466 }
1467
1468 bool
1469 _MessageBoxPresenter::OnKeyReleased(const _Control& source, const _KeyInfo& keyInfo)
1470 {
1471         _KeyCode keyCode = keyInfo.GetKeyCode();
1472
1473         if (keyCode == _KEY_ESC || keyCode == _KEY_BACK)
1474         {
1475                 MessageBoxStyle style = __pMessageBox->GetMsgBoxStyle();
1476
1477                 if ((__pButtonListener->GetBeginModal() == true) || (__beginModal == true))
1478                 {
1479                         if (__pMessageBox->GetTimeout() != 0)
1480                         {
1481                                 switch (style)
1482                                 {
1483                                 case MSGBOX_STYLE_NONE:
1484                                         // fall through
1485                                 case MSGBOX_STYLE_OK:
1486                                         // fall through
1487                                 case MSGBOX_STYLE_YESNO:
1488                                         // fall through
1489                                 case MSGBOX_STYLE_ABORTRETRYIGNORE:
1490                                         _ModalLoopManager::GetInstance()->EndMainLoop(MSGBOX_BUTTON_CLOSE, false);
1491                                         __beginModal = false;
1492
1493                                         break;
1494                                 case MSGBOX_STYLE_CANCEL:
1495                                         // fall through
1496                                 case MSGBOX_STYLE_OKCANCEL:
1497                                         // fall through
1498                                 case MSGBOX_STYLE_YESNOCANCEL:
1499                                         // fall through
1500                                 case MSGBOX_STYLE_CANCELTRYCONTINUE:
1501                                         // fall through
1502                                 case MSGBOX_STYLE_RETRYCANCEL:
1503                                         _ModalLoopManager::GetInstance()->EndMainLoop(MSGBOX_BUTTON_CANCEL, false);
1504                                         __beginModal = false;
1505                                         break;
1506                                 }
1507
1508                         }
1509                         else if (style == MSGBOX_STYLE_CANCEL || style == MSGBOX_STYLE_OKCANCEL || style == MSGBOX_STYLE_YESNOCANCEL
1510                                         || style == MSGBOX_STYLE_CANCELTRYCONTINUE || style == MSGBOX_STYLE_RETRYCANCEL)
1511                         {
1512                                 _ModalLoopManager::GetInstance()->EndMainLoop(MSGBOX_BUTTON_CANCEL, false);
1513                                 __beginModal = false;
1514                         }
1515                 }
1516                 return true;
1517         }
1518         return false;
1519 }
1520
1521 ////////////////////////////////////////////////////////////////////////
1522 ///////////////////////////MsgBoxButtonListener/////////////////////////
1523 ////////////////////////////////////////////////////////////////////////
1524
1525 _MessageBoxPresenter::_MessageBoxButtonListener::_MessageBoxButtonListener(void)
1526         : __buttonHandle()
1527         , __buttonPressFlag(false)
1528         , __buttonReleaseState(false)
1529         , __beginModal(false)
1530         , __point(0.0f, 0.0f)
1531 {
1532         // empty statement
1533 }
1534
1535 _MessageBoxPresenter::_MessageBoxButtonListener::~_MessageBoxButtonListener(void)
1536 {
1537         // empty statement
1538 }
1539
1540 _ControlHandle
1541 _MessageBoxPresenter::_MessageBoxButtonListener::GetClickedButtonHandle(void) const
1542 {
1543         return __buttonHandle;
1544 }
1545
1546 bool
1547 _MessageBoxPresenter::_MessageBoxButtonListener::IsButtonClicked(void)
1548 {
1549         return __buttonReleaseState;
1550 }
1551
1552 void
1553 _MessageBoxPresenter::_MessageBoxButtonListener::OnTouchPressed(const Control& source, const Point& currentPosition,
1554                                                                                                                                                 const TouchEventInfo& touchInfo)
1555 {
1556         __buttonPressFlag = true;
1557         __buttonReleaseState = false;
1558
1559         FloatPoint point = touchInfo.GetCurrentPositionF();
1560         __point = point;
1561 }
1562
1563 void
1564 _MessageBoxPresenter::_MessageBoxButtonListener::OnTouchMoved(const Control& source, const Point& currentPosition,
1565                                                                                                                                                 const TouchEventInfo& touchInfo)
1566 {
1567         //FloatPoint point = touchInfo.GetCurrentPositionF();
1568
1569         __buttonPressFlag = false;
1570 }
1571
1572 void
1573 _MessageBoxPresenter::_MessageBoxButtonListener::OnTouchReleased(const Control& source, const Point& currentPosition,
1574                                                                                                                                                 const TouchEventInfo& touchInfo)
1575 {
1576         if (__buttonPressFlag == true)
1577         {
1578                 __buttonHandle = _ControlImpl::GetInstance(source)->GetCore().GetHandle();
1579                 SysTryReturnVoidResult(NID_UI_CTRL, __buttonHandle.IsValid() == true, E_SYSTEM, "[E_SYSTEM] Button's Handle is invalid");
1580
1581                 __buttonPressFlag = false;
1582                 __buttonReleaseState = true;
1583
1584                 if (__beginModal == true)
1585                 {
1586                         _ModalLoopManager::GetInstance()->EndMainLoop(MSGBOX_BUTTON_CLICKED, false);
1587                         __beginModal = false;
1588                 }
1589
1590                 return;
1591         }
1592 }
1593
1594 void
1595 _MessageBoxPresenter::_MessageBoxButtonListener::OnKeyReleased(const Tizen::Ui::Control& source, Tizen::Ui::KeyCode keyCode)
1596 {
1597         const _ControlImpl* pImpl = null;
1598         const _Button* pControl = null;
1599
1600         pImpl = _ControlImpl::GetInstance(source);
1601         pControl = dynamic_cast<const _Button*>(&pImpl->GetCore());
1602
1603         if (pControl != null)
1604         {
1605                 if (keyCode == KEY_ENTER)
1606                 {
1607                         __buttonHandle = _ControlImpl::GetInstance(source)->GetCore().GetHandle();
1608                         SysTryReturnVoidResult(NID_UI_CTRL, __buttonHandle.IsValid() == true, E_SYSTEM, "[E_SYSTEM] Button's Handle is invalid");
1609
1610                         __buttonPressFlag = false;
1611                         __buttonReleaseState = true;
1612
1613                         if (__beginModal == true)
1614                         {
1615                                 _ModalLoopManager::GetInstance()->EndMainLoop(MSGBOX_BUTTON_CLICKED, false);
1616                                 __beginModal = false;
1617                         }
1618                 }
1619         }
1620
1621         return;
1622 }
1623
1624 void
1625 _MessageBoxPresenter::_MessageBoxButtonListener::OnKeyPressed(const Tizen::Ui::Control& source, Tizen::Ui::KeyCode keyCode)
1626 {
1627         const _ControlImpl* pImpl = null;
1628         const _Button* pControl = null;
1629
1630         pImpl = _ControlImpl::GetInstance(source);
1631         pControl = dynamic_cast<const _Button*>(&pImpl->GetCore());
1632
1633         if (pControl != null)
1634         {
1635                 _Button* pFocusControl = null;
1636                 switch (keyCode)
1637                 {
1638                 case KEY_RIGHT:
1639                         pFocusControl =  dynamic_cast<_Button*>(pControl->GetNextFocus());
1640                         break;
1641
1642                 case KEY_LEFT:
1643                         pFocusControl =  dynamic_cast<_Button*>(pControl->GetPreviousFocus());
1644                         break;
1645
1646                 default :
1647                         break;
1648                 }
1649
1650                 _Window* pTop = pControl->GetRootWindow();
1651
1652                 if (pFocusControl != null)
1653                 {
1654                         pTop->SetFocusTraversalControl(pFocusControl, true);
1655                         _Control* pParentControl =  pFocusControl->GetParent();
1656
1657                         if (pParentControl != null)
1658                         {
1659                                 pParentControl->OnChildControlFocusMoved(*pFocusControl);
1660                         }
1661
1662                         pFocusControl->SetFocused();
1663                         pFocusControl->DrawFocus();
1664                 }
1665         }
1666
1667         return ;
1668 }
1669
1670 void
1671 _MessageBoxPresenter::_MessageBoxButtonListener::SetBeginModal(bool beginModal)
1672 {
1673         __beginModal = beginModal;
1674 }
1675
1676 bool
1677 _MessageBoxPresenter::_MessageBoxButtonListener::GetBeginModal(void)
1678 {
1679         return __beginModal;
1680 }
1681
1682 }}}  // Tizen::Ui::Controls
1683