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