4ee9baa07516c75c04f0c0c9cffdd6763e4fb621
[framework/osp/uifw.git] / src / ui / controls / FUiCtrl_ProgressPopupPresenter.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_ProgressPopupPresenter.cpp
20  * @brief       This is the implementation file for the _ProgressPopupPresenter class.
21  */
22
23
24 #include <FBaseErrorDefine.h>
25 #include <FBaseSysLog.h>
26 #include <FGrp_BitmapImpl.h>
27 #include <FGrp_CanvasImpl.h>
28 #include <FGrp_TextTextSimple.h>
29 #include "FUi_AccessibilityContainer.h"
30 #include "FUi_AccessibilityElement.h"
31 #include "FUi_CoordinateSystemUtils.h"
32 #include "FUi_ResourceManager.h"
33 #include "FUi_UiTouchEvent.h"
34 #include "FUiCtrl_Label.h"
35 #include "FUiCtrl_ScrollPanel.h"
36 #include "FUiCtrl_ProgressPopupPresenter.h"
37 #include "FUiCtrl_ProgressPopup.h"
38
39
40 using namespace Tizen::Base;
41 using namespace Tizen::Base::Collection;
42 using namespace Tizen::Base::Runtime;
43 using namespace Tizen::Graphics;
44 using namespace Tizen::Graphics::_Text;
45 using namespace Tizen::Ui;
46 using namespace Tizen::Ui::Animations;
47
48
49 namespace Tizen { namespace Ui { namespace Controls
50 {
51
52
53 _ProgressPopupPresenter::_ProgressPopupPresenter(void)
54         : __pProgressPopup(null)
55         , __pBodyTextObject(null)
56         , __textBounds(0.0f, 0.0f, 0.0f, 0.0f)
57         , __titleBgBounds(0.0f, 0.0f, 0.0f, 0.0f)
58         , __buttonBgBounds(0.0f, 0.0f, 0.0f, 0.0f)
59         , __pLabel(null)
60         , __pScrollPanel(null)
61         , __pAnimation(null)
62         , __pAnimationFrameList(null)
63         , __textObjectHeight(0.0f)
64         , __currentIndex(0)
65         , __buttonPressState(false)
66         , __cancelButton(false)
67         , __transparent(false)
68 {
69 }
70
71 _ProgressPopupPresenter::~_ProgressPopupPresenter(void)
72 {
73         if (__pBodyTextObject != null)
74         {
75                 __pBodyTextObject->RemoveAll();
76                 delete __pBodyTextObject;
77                 __pBodyTextObject = null;
78         }
79
80         if (__pLabel != null)
81         {
82                 __pScrollPanel->DetachChild(*__pLabel);
83                 delete __pLabel;
84                 __pLabel = null;
85         }
86
87         if (__pScrollPanel != null)
88         {
89                 __pProgressPopup->DetachChild(*__pScrollPanel);
90                 delete __pScrollPanel;
91                 __pScrollPanel = null;
92         }
93
94         if (__pAnimationFrameList != null)
95         {
96                 delete __pAnimationFrameList;
97                 __pAnimationFrameList = null;
98         }
99
100         if (__pAnimation != null)
101         {
102                 delete __pAnimation;
103                 __pAnimation = null;
104         }
105
106 }
107
108 result
109 _ProgressPopupPresenter::Initialize(_ProgressPopup& ProgressPopup, bool cancelButton, bool transparent, const FloatRectangle& animationRect)
110 {
111         result r = E_SUCCESS;
112
113         __cancelButton = cancelButton;
114         __transparent = transparent;
115         __pProgressPopup = &ProgressPopup;
116
117         return r;
118 }
119
120 void
121 _ProgressPopupPresenter::SetTitleTextObject(void)
122 {
123         result r = E_SUCCESS;
124
125         TextSimple* pSimpleTextForTitleText = null;
126
127         float titleTextSize = 0.0f;
128         float minTitleTextSize = 0.0f;
129         float defaultWidth = 0.0f;
130         float titleHeight = 0.0f;
131         float titleTopMargin = 0.0f;
132         float titleLeftMargin = 0.0f;
133         float titleRightMargin = 0.0f;
134
135         float transTopMargin = 0.0f;
136         float transLeftMargin = 0.0f;
137         float transRightMargin = 0.0f;
138
139         _ControlOrientation orientation;
140
141         orientation = __pProgressPopup->GetOrientation();
142
143         GET_SHAPE_CONFIG(POPUP::TITLE_TEXT_SIZE, orientation, titleTextSize);
144         GET_SHAPE_CONFIG(POPUP::MIN_TITLE_TEXT_SIZE, orientation, minTitleTextSize);
145         GET_SHAPE_CONFIG(MESSAGEBOX::DEFAULT_WIDTH, orientation, defaultWidth);
146         GET_SHAPE_CONFIG(POPUP::TITLE_HEIGHT, orientation, titleHeight);
147         GET_SHAPE_CONFIG(POPUP::TITLE_TEXT_TOP_MARGIN, orientation, titleTopMargin);
148         GET_SHAPE_CONFIG(POPUP::TITLE_TEXT_LEFT_MARGIN, orientation, titleLeftMargin);
149         GET_SHAPE_CONFIG(POPUP::TITLE_TEXT_RIGHT_MARGIN, orientation, titleRightMargin);
150
151         GET_SHAPE_CONFIG(POPUP::BG_IMAGE_TRANSPARENT_TOP_MARGIN, orientation, transTopMargin);
152         GET_SHAPE_CONFIG(POPUP::BG_IMAGE_TRANSPARENT_LEFT_MARGIN, orientation, transLeftMargin);
153         GET_SHAPE_CONFIG(POPUP::BG_IMAGE_TRANSPARENT_RIGHT_MARGIN, orientation, transRightMargin);
154
155         if (_pTitleTextObject == null)
156         {
157                 _pTitleTextObject = new (std::nothrow) TextObject();
158                 SysTryReturnVoidResult(NID_UI_CTRL, _pTitleTextObject != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
159
160                 r = _pTitleTextObject->Construct();
161                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
162         }
163         else
164         {
165                 r = _pTitleTextObject->RemoveAll();
166                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
167         }
168
169         pSimpleTextForTitleText = new (std::nothrow) TextSimple(const_cast <wchar_t*>(__pProgressPopup->GetTitleText().GetPointer()),
170                         __pProgressPopup->GetTitleText().GetLength(),
171                         TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
172         SysTryCatch(NID_UI_CTRL, pSimpleTextForTitleText != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
173
174         _pTitleTextObject->AppendElement(*pSimpleTextForTitleText);
175         _pTitleTextObject->SetForegroundColor(__pProgressPopup->GetTitleTextColor(), 0, _pTitleTextObject->GetTextLength());
176         _pTitleTextObject->SetWrap(TEXT_OBJECT_WRAP_TYPE_NONE);
177         _pTitleTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
178         _pTitleTextObject->SetTextObjectEllipsisType(TEXT_OBJECT_ELLIPSIS_TYPE_TAIL);
179
180         _pTitleTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_LEFT);
181
182         _pTitleTextObject->SetBounds(FloatRectangle(titleLeftMargin + transLeftMargin,
183                                 titleTopMargin + transTopMargin,
184                                 defaultWidth - (titleLeftMargin + titleRightMargin + transLeftMargin + transRightMargin),
185                                 titleHeight - titleTopMargin));
186
187         r = CalculateTitleTextSize(titleTextSize, minTitleTextSize);
188         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
189
190         _titleBounds = FloatRectangle(titleLeftMargin + transLeftMargin,
191                         titleTopMargin + transTopMargin,
192                         defaultWidth - (titleLeftMargin + titleRightMargin + transLeftMargin + transRightMargin),
193                         titleHeight - titleTopMargin);
194
195         __titleBgBounds.SetBounds(transLeftMargin, transTopMargin,
196                                                         defaultWidth - (transLeftMargin + transRightMargin), titleHeight);
197
198         SetLastResult(E_SUCCESS);
199         return;
200 CATCH:
201         delete _pTitleTextObject;
202         _pTitleTextObject = null;
203
204         return;
205 }
206
207 void
208 _ProgressPopupPresenter::SetTextObject(void)
209 {
210         result r = E_SUCCESS;
211
212         TextSimple* pSimpleTextForBodyText = null;
213
214         float bodyTextSize = 0.0f;
215         float defaultWidth = 0.0f;
216         float titleHeight = 0.0f;
217         float maxHeight = 0.0f;
218         float textLeftMargin = 0.0f;
219         float textRightMargin = 0.0f;
220         float bottomHeight = 0.0f;
221         float transTopMargin = 0.0f;
222         float transLeftMargin = 0.0f;
223         float transRightMargin = 0.0f;
224         float animationWidth = 0.0f;
225         float textTopMargin = 0.0f;
226         float animationTopMargin = 0.0f;
227
228         _ControlOrientation orientation;
229
230         orientation = __pProgressPopup->GetOrientation();
231
232         GET_SHAPE_CONFIG(POPUP::PROCESS_ANIMATION_WIDTH, orientation, animationWidth);
233
234         GET_SHAPE_CONFIG(POPUP::BG_IMAGE_TRANSPARENT_TOP_MARGIN, orientation, transTopMargin);
235         GET_SHAPE_CONFIG(POPUP::BG_IMAGE_TRANSPARENT_LEFT_MARGIN, orientation, transLeftMargin);
236         GET_SHAPE_CONFIG(POPUP::BG_IMAGE_TRANSPARENT_RIGHT_MARGIN, orientation, transRightMargin);
237
238         GET_SHAPE_CONFIG(POPUP::PROCESS_TEXT_TOP_MARGIN, orientation, textTopMargin);
239         GET_SHAPE_CONFIG(POPUP::BODY_TEXT_HEIGHT, orientation, __textObjectHeight);
240         GET_SHAPE_CONFIG(MESSAGEBOX::TEXT_LEFT_MARGIN, orientation, textLeftMargin);
241         GET_SHAPE_CONFIG(MESSAGEBOX::TEXT_RIGHT_MARGIN, orientation, textRightMargin);
242         GET_SHAPE_CONFIG(MESSAGEBOX::TEXT_SIZE, orientation, bodyTextSize);
243
244         GET_SHAPE_CONFIG(MESSAGEBOX::MAX_HEIGHT, orientation, maxHeight);
245         GET_SHAPE_CONFIG(MESSAGEBOX::DEFAULT_WIDTH, orientation, defaultWidth);
246         GET_SHAPE_CONFIG(MESSAGEBOX::BOTTOM_HEIGHT, orientation, bottomHeight);
247
248         if (__pProgressPopup->HasTitle())
249         {
250                 GET_SHAPE_CONFIG(POPUP::TITLE_HEIGHT, orientation, titleHeight);
251                 GET_SHAPE_CONFIG(POPUP::PROCESS_ANIMATION_WITH_TITLE_TOP_MARGIN, orientation, animationTopMargin);
252         }
253         else
254         {
255                 GET_SHAPE_CONFIG(POPUP::PROCESS_ANIMATION_NO_TITLE_TOP_MARGIN, orientation, animationTopMargin);
256         }
257
258         if (__pBodyTextObject == null)
259         {
260                 __pBodyTextObject = new (std::nothrow) TextObject();
261                 SysTryReturnVoidResult(NID_UI_CTRL, __pBodyTextObject != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
262
263                 r = __pBodyTextObject->Construct();
264                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
265
266                 __pLabel = _Label::CreateLabelN();
267                 SysTryCatch(NID_UI_CTRL, __pLabel != null, , E_OUT_OF_MEMORY, "[E_SYSTEM] Failed to create the scroll.");
268         }
269         else
270         {
271                 r = __pBodyTextObject->RemoveAll();
272                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
273         }
274
275         pSimpleTextForBodyText = new (std::nothrow) TextSimple(const_cast <wchar_t*>(__pProgressPopup->GetText().GetPointer()),
276                                                                                                                                         __pProgressPopup->GetText().GetLength(),
277                                                                                                                                         TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
278         SysTryCatch(NID_UI_CTRL, pSimpleTextForBodyText != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
279
280         __pBodyTextObject->AppendElement(*pSimpleTextForBodyText);
281         __pBodyTextObject->SetForegroundColor(__pProgressPopup->GetTextColor(), 0, __pBodyTextObject->GetTextLength());
282         __pBodyTextObject->SetWrap(TEXT_OBJECT_WRAP_TYPE_WORD);
283
284         r = SetFontInfo(FONT_STYLE_PLAIN, bodyTextSize);
285         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set font.", GetErrorMessage(r));
286
287         __pBodyTextObject->SetFont(_pFont, 0, __pBodyTextObject->GetTextLength());
288         __pBodyTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_LEFT);
289
290         if (__pProgressPopup->HasButton())
291         {
292                 GET_SHAPE_CONFIG(MESSAGEBOX::BOTTOM_HEIGHT, orientation, bottomHeight);
293         }
294
295         // Calculate Text bounds
296         __textBounds.SetBounds(textLeftMargin + transLeftMargin,
297                                                         titleHeight + textTopMargin + transTopMargin + animationWidth + animationTopMargin,
298                                                         defaultWidth - (textLeftMargin + textRightMargin + transLeftMargin + transRightMargin),
299                                                         maxHeight - titleHeight - bottomHeight - animationWidth);
300
301         __pBodyTextObject->SetBounds(__textBounds);
302
303         if (__pProgressPopup->GetText().GetLength() > 0)
304         {
305                 __pBodyTextObject->Compose();
306                 __textObjectHeight = __pBodyTextObject->GetLineHeightAtF(0) * 3.0;
307                 __textBounds.height = __textObjectHeight;
308         }
309
310         if (__pBodyTextObject->GetTotalHeightF() < __textObjectHeight)
311         {
312                 __pLabel->SetBounds(FloatRectangle(0.0f, (__textObjectHeight - __pBodyTextObject->GetTotalHeightF())/2.0f, __textBounds.width, __pBodyTextObject->GetTotalHeightF()));
313         }
314         else
315         {
316                 __pLabel->SetBounds(FloatRectangle(0.0f, 0.0f, __textBounds.width, __pBodyTextObject->GetTotalHeightF()));
317         }
318
319         __pLabel->SetText(__pProgressPopup->GetText());
320         __pLabel->SetTextConfig(bodyTextSize, LABEL_TEXT_STYLE_NORMAL);
321         __pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
322         __pLabel->SetMargin(0.0f, 0.0f, 0.0f, 0.0f);
323
324         if (__pScrollPanel == null)
325         {
326                 __pScrollPanel = _ScrollPanel::CreateScrollPanelN(__textBounds, SCROLL_PANEL_SCROLL_DIRECTION_VERTICAL, true);
327                 SysTryCatch(NID_UI_CTRL, __pScrollPanel != null, , E_OUT_OF_MEMORY, "[E_SYSTEM] Failed to create the scroll.");
328
329                 __pScrollPanel->SetBounds(__textBounds);
330                 __pScrollPanel->AttachChild(*__pLabel);
331                 __pProgressPopup->AttachChild(*__pScrollPanel);
332         }
333         else
334         {
335                 __pScrollPanel->SetBounds(__textBounds);
336         }
337
338         SetLastResult(E_SUCCESS);
339
340         return;
341 CATCH:
342         delete __pBodyTextObject;
343         __pBodyTextObject = null;
344
345         delete __pLabel;
346         __pLabel = null;
347
348         delete __pScrollPanel;
349         __pScrollPanel = null;
350
351         return;
352 }
353
354 result
355 _ProgressPopupPresenter::PlayProcessAnimation(void)
356 {
357         if (__pAnimation != null)
358         {
359                 if (__pAnimation->GetStatus() == ANIMATION_PLAYING)
360                 {
361                         return E_SUCCESS;
362                 }
363         }
364         else
365         {
366                 SetProcessAnimation();
367         }
368
369         if (__pAnimation != null)
370         {
371                 __pAnimation->Play();
372         }
373
374         return E_SUCCESS;
375
376 }
377
378 result
379 _ProgressPopupPresenter::StopProcessAnimation(void)
380 {
381         if (__pAnimation != null)
382         {
383                 __pAnimation->Stop();
384
385                 __pProgressPopup->DetachChild(*__pAnimation);
386
387                 delete __pAnimation;
388                 __pAnimation = null;
389         }
390
391         return E_SUCCESS;
392 }
393
394 result
395 _ProgressPopupPresenter::SetProcessAnimation(void)
396 {
397         result r = E_SUCCESS;
398
399         if (__pAnimation != null)
400         {
401                 if (__pAnimation->GetStatus() == ANIMATION_PLAYING)
402                 {
403                         return r;
404                 }
405         }
406
407         if (__pAnimationFrameList)
408         {
409                 __pAnimationFrameList->RemoveAll(true);
410                 delete __pAnimationFrameList;
411                 __pAnimationFrameList = null;
412         }
413
414         r = GET_ANIMATION_CONFIG_N(POPUP::PROCESSING_ANIMATION, __pAnimationFrameList);
415         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM,"System error is occured.");
416
417         delete __pAnimation;
418         __pAnimation = null;
419
420         __pAnimation = _Animation::CreateAnimationN();
421
422         if (__pAnimation)
423         {
424                 if (__pAnimationFrameList)
425                 {
426                         __pAnimation->SetAnimationFrames(*__pAnimationFrameList);
427                         __pAnimation->SetImageCount(__pAnimationFrameList->GetCount());
428                 }
429
430                 __pAnimation->SetRepeatCount(ANIMATION_REPEAT_COUNT);
431                 __pAnimation->AddAnimationEventListener(*this);
432
433                 FloatRectangle animationBounds = __pProgressPopup->GetAnimationRect();
434
435                 if (__transparent)
436                 {
437                         __pAnimation->GetVisualElement()->SetOpacity(0.6f);
438                         __pAnimation->SetBounds(FloatRectangle(0.0f, 0.0f, animationBounds.width, animationBounds.height));
439                 }
440                 else
441                 {
442                         __pAnimation->SetBounds(FloatRectangle(animationBounds.x, animationBounds.y, animationBounds.width, animationBounds.height));
443                 }
444
445                 __pProgressPopup->AttachChild(*__pAnimation);
446         }
447
448         return r;
449 }
450
451 void
452 _ProgressPopupPresenter::OnAnimationStopped(const _Control & source)
453 {
454         if (&source == __pAnimation)
455         {
456                 __pAnimation->Play();
457         }
458 }
459
460 void
461 _ProgressPopupPresenter::Draw(void)
462 {
463         result r = E_SUCCESS;
464
465         float titleTextSize = 0.0f;
466         float bodyTextSize = 0.0f;
467         float defaultWidth = 0.0f;
468
469         bool isCustomBitmap = false;
470
471         _ControlOrientation orientation;
472
473         isCustomBitmap = IS_CUSTOM_BITMAP(POPUP::BG_NORMAL);
474
475         orientation = __pProgressPopup->GetOrientation();
476
477         Canvas* pCanvas = __pProgressPopup->GetCanvasN();
478         SysTryReturnVoidResult(NID_UI_CTRL, (pCanvas != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Unable to create canvas.");
479
480         pCanvas->SetBackgroundColor(Color(0x00000000));
481         pCanvas->Clear();
482
483         if (__transparent)
484         {
485                 return;
486         }
487
488         GET_SHAPE_CONFIG(POPUP::TITLE_TEXT_SIZE, orientation, titleTextSize);
489         GET_SHAPE_CONFIG(MESSAGEBOX::TEXT_SIZE, orientation, bodyTextSize);
490
491         GET_SHAPE_CONFIG(MESSAGEBOX::DEFAULT_WIDTH, orientation, defaultWidth);
492
493         float totalH = __pProgressPopup->GetTotalHeight();
494
495         const Bitmap* pBackgroundBitmap = __pProgressPopup->GetBackgroundBitmap();
496         const Bitmap* pOutlineBitmap = __pProgressPopup->GetOutlineBitmap();
497
498         FloatRectangle bgBounds(0.0f, 0.0f, defaultWidth, totalH);
499
500         // Draw BG
501         if (pBackgroundBitmap != null)
502         {
503                 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pBackgroundBitmap))
504                 {
505                         pCanvas->DrawNinePatchedBitmap(bgBounds, *pBackgroundBitmap);
506                 }
507                 else
508                 {
509                         pCanvas->DrawBitmap(bgBounds, *pBackgroundBitmap);
510                 }
511         }
512
513         // Draw Outline
514         if (!isCustomBitmap && pOutlineBitmap != null)
515         {
516                 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pOutlineBitmap))
517                 {
518                         pCanvas->DrawNinePatchedBitmap(bgBounds, *pOutlineBitmap);
519                 }
520                 else
521                 {
522                         pCanvas->DrawBitmap(bgBounds, *pOutlineBitmap);
523                 }
524         }
525
526         const Bitmap* pTitleBitmap = __pProgressPopup->GetTitleBackgroundBitmap();
527         const Bitmap* pTitleEffectBitmap = __pProgressPopup->GetTitleBackgroundEffectBitmap();
528
529         // Draw Title text
530         if (_pTitleTextObject != null)
531         {
532                 isCustomBitmap = IS_CUSTOM_BITMAP(MESSAGEBOX::BG_TITLE_AREA);
533                 //DrawTitleBG
534                 if(pTitleBitmap != null)
535                 {
536                         if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pTitleBitmap))
537                         {
538                                 pCanvas->DrawNinePatchedBitmap(__titleBgBounds, *pTitleBitmap);
539                         }
540                         else
541                         {
542                                 pCanvas->DrawBitmap(__titleBgBounds, *pTitleBitmap);
543                         }
544                 }
545
546                  //DrawEffectTitleBitmap
547                 if (!isCustomBitmap && pTitleEffectBitmap != null)
548                 {
549                         if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pTitleEffectBitmap))
550                         {
551                                 pCanvas->DrawNinePatchedBitmap(__titleBgBounds, *pTitleEffectBitmap);
552                         }
553                         else
554                         {
555                                 pCanvas->DrawBitmap(__titleBgBounds, *pTitleEffectBitmap);
556                         }
557                 }
558
559                 r = SetFontInfo(FONT_STYLE_PLAIN, _titleTextSize);
560                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
561
562                 _pTitleTextObject->SetFont(_pFont, 0, _pTitleTextObject->GetTextLength());
563                 _pTitleTextObject->SetBounds(_titleBounds);
564                 _pTitleTextObject->Draw(*_CanvasImpl::GetInstance(*pCanvas));
565         }
566
567         if( __cancelButton )
568         {
569                 const Bitmap* pButtonBitmap = __pProgressPopup->GetButtonBackgroundBitmap();
570                 const Bitmap* pButtonEffectBitmap = __pProgressPopup->GetButtonBackgroundEffectBitmap();
571                 isCustomBitmap = IS_CUSTOM_BITMAP(MESSAGEBOX::BG_BUTTON_AREA);
572
573                 //DrawButtonBG
574                 if(pButtonBitmap != null)
575                 {
576                         if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pButtonBitmap))
577                         {
578                                 pCanvas->DrawNinePatchedBitmap(__buttonBgBounds, *pButtonBitmap);
579                         }
580                         else
581                         {
582                                 pCanvas->DrawBitmap(__buttonBgBounds, *pButtonBitmap);
583                         }
584                 }
585
586                 //DrawEffectButtonBitmap
587                 if (!isCustomBitmap && pButtonEffectBitmap != null)
588                 {
589                         if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pButtonEffectBitmap))
590                         {
591                                 pCanvas->DrawNinePatchedBitmap(__buttonBgBounds, *pButtonEffectBitmap);
592                         }
593                         else
594                         {
595                                 pCanvas->DrawBitmap(__buttonBgBounds, *pButtonEffectBitmap);
596                         }
597                 }
598         }
599
600         if (__pLabel != null)
601         {
602                 __pLabel->SetTextColor(__pProgressPopup->GetTextColor());
603         }
604
605         //fall thtrough
606 CATCH:
607         delete pCanvas;
608
609         return;
610 }
611
612 result
613 _ProgressPopupPresenter::DoModal(int& modalResult)
614 {
615         __pProgressPopup->Open();
616
617         ProcessEvent();
618
619         __pProgressPopup->Close();
620
621         modalResult = __pProgressPopup->GetPopupReturnValue();
622
623         return E_SUCCESS;
624 }
625
626 float
627 _ProgressPopupPresenter::GetBodyTextObjHeight(void) const
628 {
629         return (__pBodyTextObject == null) ? 0.0f : __textObjectHeight;
630 }
631 float
632 _ProgressPopupPresenter::GetBodyTextHeight(void) const
633 {
634         return (__pBodyTextObject == null) ? 0.0f : __pBodyTextObject->GetTotalHeightF();
635 }
636
637 FloatRectangle
638 _ProgressPopupPresenter::GetTextBounds(void) const
639 {
640         return __textBounds;
641 }
642
643 FloatRectangle
644 _ProgressPopupPresenter::GetButtonBounds(void)
645 {
646         float width = 0;
647         float height = 0;
648         float x = 0;
649         float y = 0;
650
651         float defaultWidth = 0.0f;
652         float titleHeight = 0.0f;
653         float btnHeight = 0.0f;
654         float btnSideMargin1 = 0.0f;
655         float transTopMargin = 0.0f;
656         float transLeftMargin = 0.0f;
657         float transRightMargin = 0.0f;
658         float animationWidth = 0.0f;
659         float animationTopMargin = 0.0f;
660         float textTopMargin = 0.0f;
661         float textBottomMargin = 0.0f;
662         float buttonBgHeight = 0.0f;
663         _ControlOrientation orientation;
664
665         orientation = __pProgressPopup->GetOrientation();
666
667         GET_SHAPE_CONFIG(POPUP::BG_IMAGE_TRANSPARENT_TOP_MARGIN, orientation, transTopMargin);
668         GET_SHAPE_CONFIG(POPUP::BG_IMAGE_TRANSPARENT_LEFT_MARGIN, orientation, transLeftMargin);
669         GET_SHAPE_CONFIG(POPUP::BG_IMAGE_TRANSPARENT_RIGHT_MARGIN, orientation, transRightMargin);
670         GET_SHAPE_CONFIG(POPUP::PROCESS_ANIMATION_WIDTH, orientation, animationWidth);
671         GET_SHAPE_CONFIG(POPUP::PROCESS_TEXT_TOP_MARGIN, orientation, textTopMargin);
672         GET_SHAPE_CONFIG(POPUP::PROCESS_TEXT_BOTTOM_MARGIN, orientation, textBottomMargin);
673
674
675         GET_SHAPE_CONFIG(MESSAGEBOX::DEFAULT_WIDTH, orientation, defaultWidth);
676         GET_SHAPE_CONFIG(MESSAGEBOX::BUTTON_HEIGHT, orientation, btnHeight);
677         GET_SHAPE_CONFIG(MESSAGEBOX::BUTTON_SIDE_MARGIN_01, orientation, btnSideMargin1);
678         GET_SHAPE_CONFIG(MESSAGEBOX::BOTTOM_HEIGHT, orientation, buttonBgHeight);
679
680         if (!__pProgressPopup->HasButton())
681         {
682                 return FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f);
683         }
684
685         if (__pProgressPopup->HasTitle())
686         {
687                 GET_SHAPE_CONFIG(POPUP::TITLE_HEIGHT, orientation, titleHeight);
688                 GET_SHAPE_CONFIG(POPUP::PROCESS_ANIMATION_WITH_TITLE_TOP_MARGIN, orientation, animationTopMargin);
689         }
690         else
691         {
692                 GET_SHAPE_CONFIG(POPUP::PROCESS_ANIMATION_NO_TITLE_TOP_MARGIN, orientation, animationTopMargin);
693         }
694
695         if (!__pProgressPopup->HasText())
696         {
697                 textTopMargin = 0.0f;
698                 textBottomMargin = textBottomMargin * 1.5f;
699         }
700
701         width = defaultWidth - (btnSideMargin1 * 2.0f);
702         height = btnHeight;
703         x = btnSideMargin1;
704
705         y = transTopMargin
706                 + titleHeight
707                 + animationTopMargin
708                 + animationWidth
709                 + textTopMargin
710                 + textBottomMargin
711                 + GetBodyTextObjHeight();
712
713         __buttonBgBounds.SetBounds(transLeftMargin,  y , (defaultWidth - (transLeftMargin + transRightMargin)) , buttonBgHeight);
714
715         return FloatRectangle(x, y + ((buttonBgHeight - height) / 2), width, height);
716 }
717
718 void
719 _ProgressPopupPresenter::InitializeAccessibilityElement(void)
720 {
721         _AccessibilityContainer* pContainer = __pProgressPopup->GetAccessibilityContainer();
722
723         if (pContainer == null)
724         {
725                 return ;
726         }
727
728         if (__pLabel != null)
729         {
730                 _AccessibilityContainer* pLabelContainer = __pLabel->GetAccessibilityContainer();
731                 if (pLabelContainer != null)
732                 {
733                         _AccessibilityElement* pLabelElement = pLabelContainer->GetChildElement(L"LabelText");
734                         if (pLabelElement != null)
735                         {
736                                 pLabelElement->SetName(L"ProgressPopupText");
737                                 pLabelElement->SetTrait(L"Popup body text");
738                         }
739
740                         // Add Container
741                         pContainer->AddChildContainer(*pLabelContainer);
742                 }
743         }
744 }
745
746
747 _Popup*
748 _ProgressPopupPresenter::GetCore(void)
749 {
750         return static_cast <_Popup*>(__pProgressPopup);
751 }
752
753 bool
754 _ProgressPopupPresenter::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
755 {
756         __buttonPressState = true;
757
758         return true;
759 }
760
761 bool
762 _ProgressPopupPresenter::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
763 {
764         __buttonPressState = false;
765
766         return true;
767 }
768
769 bool
770 _ProgressPopupPresenter::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
771 {
772         Point touchPoint = _CoordinateSystemUtils::ConvertToInteger(touchinfo.GetCurrentPosition());
773
774         return true;
775 }
776
777 result
778 _ProgressPopupPresenter::OnChangeLayout(_ControlOrientation orientation)
779 {
780         FloatRectangle animationBounds = __pProgressPopup->GetAnimationRect();
781
782         if (__pAnimation != null)
783         {
784                 __pAnimation->SetBounds(FloatRectangle(animationBounds.x, animationBounds.y, animationBounds.width, animationBounds.height));
785         }
786
787         if (__pProgressPopup->HasTitle())
788         {
789                 SetTitleTextObject();
790         }
791
792         if (__pProgressPopup->HasText())
793         {
794                 SetTextObject();
795         }
796
797         return E_SUCCESS;
798 }
799
800 }}} // Tizen::Ui::Controls
801
802