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