2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://floralicense.org/license/
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FUiCtrl_ProgressPopup.cpp
20 * @brief This is the implementation file for the _ProgressPopup class.
23 #include <FBaseSysLog.h>
24 #include <FBaseErrorDefine.h>
25 #include <FUiCtrlButton.h>
26 #include <FGrp_BitmapImpl.h>
27 #include "FUi_AccessibilityContainer.h"
28 #include "FUi_AccessibilityElement.h"
29 #include "FUi_ResourceManager.h"
30 #include "FUi_DataBindingContext.h"
31 #include "FUiCtrl_ButtonImpl.h"
32 #include "FUiCtrl_Button.h"
33 #include "FUiCtrl_Form.h"
34 #include "FUiCtrl_Frame.h"
35 #include "FUiCtrl_ProgressPopup.h"
36 #include "FUiCtrl_ProgressPopupPresenter.h"
39 using namespace Tizen::Graphics;
40 using namespace Tizen::Ui;
41 using namespace Tizen::Ui::Animations;
42 using namespace Tizen::Base;
45 namespace Tizen { namespace Ui { namespace Controls
49 _ProgressPopup::_ProgressPopup(void)
50 : __pProgressPopupPresenter(null)
51 , __pProgressPopupEvent(null)
54 , __textColor(Color(0xFFFFFFFF))
55 , __animationRect(0, 0, 0, 0)
56 , __pTextAccessibilityElement(null)
58 , __buttonState(false)
59 , __isTranslucent(false)
64 _ProgressPopup::~_ProgressPopup(void)
66 delete __pProgressPopupPresenter;
67 __pProgressPopupPresenter = null;
69 if (__pProgressPopupEvent != null)
71 delete __pProgressPopupEvent;
72 __pProgressPopupEvent = null;
78 delete _pComposedBgBitmap;
79 _pComposedBgBitmap = null;
81 delete _pOutlineBitmap;
82 _pOutlineBitmap = null;
84 delete _pDimmingLayer;
85 _pDimmingLayer = null;
90 if (__pTextAccessibilityElement)
92 __pTextAccessibilityElement->Activate(false);
93 __pTextAccessibilityElement = null;
98 _ProgressPopup::CreateProgressPopupN(void)
100 _ProgressPopup* pProgressPopup = new (std::nothrow) _ProgressPopup();
101 SysTryReturn(NID_UI_CTRL, pProgressPopup != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
103 #if defined(MULTI_WINDOW)
104 result r = pProgressPopup->CreateRootVisualElement();
105 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
108 // for taking touch event
109 pProgressPopup->AcquireHandle();
111 return pProgressPopup;
113 #if defined(MULTI_WINDOW)
115 delete pProgressPopup;
122 _ProgressPopup::Initialize(bool cancelButton, bool translucent, const Rectangle& animationRect)
124 result r = E_SUCCESS;
126 _AccessibilityContainer* pContainer = null;
128 __animationRect = animationRect;
129 __buttonState = cancelButton;
130 __isTranslucent = translucent;
132 _ProgressPopupPresenter* pPresenter = new (std::nothrow) _ProgressPopupPresenter();
133 SysTryReturn(NID_UI_CTRL, pPresenter != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
135 SetPresenter(*pPresenter);
137 r = pPresenter->Initialize(*this, cancelButton, translucent, animationRect);
138 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
140 GET_COLOR_CONFIG(POPUP::TITLE_TEXT_NORMAL, _titleTextColor);
141 GET_COLOR_CONFIG(MESSAGEBOX::TEXT_NORMAL, __textColor);
143 GET_BITMAP_CONFIG_N(POPUP::BG_OUTLINE_EFFECT_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, _pOutlineBitmap);
145 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
148 GET_COLOR_CONFIG(POPUP::BG_NORMAL, bgColor);
150 GET_BITMAP_CONFIG_N(POPUP::BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, _pBgBitmap);
152 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
154 _pComposedBgBitmap = _BitmapImpl::GetColorReplacedBitmapN(*_pBgBitmap, Color::GetColor(COLOR_ID_MAGENTA), bgColor);
156 // for clearing canvas
157 if (GetVisualElement() != null)
159 GetVisualElement()->SetSurfaceOpaque(false);
164 GetVisualElement()->SetOpacity(0.6f); // FIXME : temp
167 _pDimmingLayer = new (std::nothrow) _DimmingLayer();
168 SysTryReturn(NID_UI_CTRL, _pDimmingLayer != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
170 r = _pDimmingLayer->Construct(*this);
171 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
173 if (__buttonState && !__isTranslucent)
175 __pButton = new (std::nothrow) Button();
176 SysTryCatch(NID_UI_CTRL, __pButton != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
178 r = __pButton->Construct(pPresenter->GetButtonBounds(), L"Cancel");
179 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
181 _ControlImpl* pImpl = _ControlImpl::GetInstance(*__pButton);
182 r = AttachChild(pImpl->GetCore());
183 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
185 _Button* pButtonCore = dynamic_cast <_Button*>(&pImpl->GetCore());
186 SysTryCatch(NID_UI_CTRL, pButtonCore != null, , r, "[%s] Propagating.", GetErrorMessage(r));
188 pButtonCore->SetActionId(ID_PROGRESS_POPUP_CANCEL_BUTTON);
189 pButtonCore->AddActionEventListener(*this);
192 pContainer = GetAccessibilityContainer();
193 if(pContainer != null)
195 pContainer->Activate(true);
201 delete _pDimmingLayer;
202 _pDimmingLayer = null;
211 _ProgressPopup::SetPresenter(const _ProgressPopupPresenter& ProgressPopupPresenter)
213 __pProgressPopupPresenter = const_cast <_ProgressPopupPresenter*>(&ProgressPopupPresenter);
219 _ProgressPopup::DoModal(int& modalResult)
221 result r = E_SUCCESS;
223 r = __pProgressPopupPresenter->DoModal(modalResult);
224 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
230 _ProgressPopup::AddProgressPopupEventListener(const Tizen::Ui::Controls::_IProgressPopupEventListener& listener)
232 result r = E_SUCCESS;
234 if (__pProgressPopupEvent == null)
236 __pProgressPopupEvent = _ProgressPopupEvent::CreateInstanceN(*this);
238 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
241 r = __pProgressPopupEvent->AddListener(listener);
242 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
248 _ProgressPopup::SetTitleText(const String& title)
250 result r = E_SUCCESS;
255 if (_pTitleTextAccessibilityElement != null)
257 _pTitleTextAccessibilityElement->SetLabel(title);
260 __pProgressPopupPresenter->SetTitleTextObject();
266 _ProgressPopup::SetText(const String& text)
268 result r = E_SUCCESS;
273 if (__pTextAccessibilityElement != null)
275 __pTextAccessibilityElement->SetLabel(text);
278 __pProgressPopupPresenter->SetTextObject();
284 _ProgressPopup::UpdateBounds(void)
286 result r = E_SUCCESS;
288 // create button with new position
291 _ControlImpl* pImpl = null;
292 _Button* pButtonCore = null;
294 if (__pButton != null)
296 pImpl = _ControlImpl::GetInstance(*__pButton);
297 r = DetachChild(pImpl->GetCore());
298 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
304 __pButton = new (std::nothrow) Button();
305 SysTryReturn(NID_UI_CTRL, __pButton != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
307 r = __pButton->Construct(__pProgressPopupPresenter->GetButtonBounds(), L"Cancel");
308 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
310 pImpl = _ControlImpl::GetInstance(*__pButton);
311 r = AttachChild(pImpl->GetCore());
312 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
314 pButtonCore = dynamic_cast <_Button*>(&pImpl->GetCore());
316 SysTryCatch(NID_UI_CTRL, pButtonCore != null, , r, "[%s] Propagating.", GetErrorMessage(r));
318 pButtonCore->SetActionId(ID_PROGRESS_POPUP_CANCEL_BUTTON);
319 pButtonCore->AddActionEventListener(*this);
322 // update total height -> GetTotalHeight (called by Impl)
323 // update process-animation rect position -> GetAnimationRect (called by UpdateProcessAnimationVE)
324 // update process-animation VE
325 // r = __pProgressPopupPresenter->UpdateProcessAnimationVE();
326 // SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
338 _ProgressPopup::GetText(void) const
344 _ProgressPopup::GetTotalHeight(void) const
346 int transTopMargin = 0;
347 int transBottomMargin = 0;
349 int noTitleHeigth = 0;
350 int animationWidth = 0;
352 int textBottomGap = 0;
353 int bottomHeight = 0;
355 GET_SHAPE_CONFIG(POPUP::BG_IMAGE_TRANSPARENT_TOP_MARGIN, GetOrientation(), transTopMargin);
356 GET_SHAPE_CONFIG(POPUP::BG_IMAGE_TRANSPARENT_BOTTOM_MARGIN, GetOrientation(), transBottomMargin);
357 GET_SHAPE_CONFIG(POPUP::PROCESS_ANIMATION_NO_TITLE_TOP_MARGIN, GetOrientation(), noTitleHeigth);
358 GET_SHAPE_CONFIG(POPUP::PROCESS_ANIMATION_WIDTH, GetOrientation(), animationWidth);
359 GET_SHAPE_CONFIG(POPUP::PROCESS_TEXT_TOP_MARGIN, GetOrientation(), textTopGap);
360 GET_SHAPE_CONFIG(POPUP::PROCESS_TEXT_BOTTOM_MARGIN, GetOrientation(), textBottomGap);
361 GET_SHAPE_CONFIG(POPUP::TITLE_HEIGHT, GetOrientation(), titleHeight);
363 GET_SHAPE_CONFIG(MESSAGEBOX::BOTTOM_HEIGHT, GetOrientation(), bottomHeight);
385 int totalH = transTopMargin
392 + __pProgressPopupPresenter->GetBodyTextHeight()
399 _ProgressPopup::SetTextColor(const Color& color)
407 _ProgressPopup::GetTextColor() const
413 _ProgressPopup::GetAnimationRect(void) const
415 Rectangle animationBounds;
417 int defaultWidth = 0;
419 int animationWidth = 0;
420 int noTitleProcessTop = 0;
421 int transTopMargin = 0;
423 GET_SHAPE_CONFIG(MESSAGEBOX::DEFAULT_WIDTH, GetOrientation(), defaultWidth);
425 GET_SHAPE_CONFIG(POPUP::TITLE_HEIGHT, GetOrientation(), titleHeight);
426 GET_SHAPE_CONFIG(POPUP::PROCESS_ANIMATION_WIDTH, GetOrientation(), animationWidth);
427 GET_SHAPE_CONFIG(POPUP::PROCESS_ANIMATION_NO_TITLE_TOP_MARGIN, GetOrientation(), noTitleProcessTop);
428 GET_SHAPE_CONFIG(POPUP::BG_IMAGE_TRANSPARENT_TOP_MARGIN, GetOrientation(), transTopMargin);
432 animationBounds = Rectangle((defaultWidth - animationWidth) / 2, titleHeight + transTopMargin, animationWidth, animationWidth);
434 else if (HasText() || HasButton())
436 animationBounds = Rectangle((defaultWidth - animationWidth) / 2, noTitleProcessTop + transTopMargin, animationWidth, animationWidth);
440 animationBounds = __animationRect;
443 return animationBounds;
447 _ProgressPopup::HasText(void) const
453 _ProgressPopup::HasButton(void) const
455 return (__buttonState && !__isTranslucent);
459 _ProgressPopup::IsTranslucent(void) const
461 return __isTranslucent;
465 _ProgressPopup::FireProgressPopupEvent(void)
467 if (__pProgressPopupEvent != null)
469 Tizen::Base::Runtime::IEventArg* pEventArg = _ProgressPopupEvent::CreateProgressPopupEventArgN();
470 result r = GetLastResult();
471 SysTryReturnVoidResult(NID_UI_CTRL, pEventArg != null, r, "[%s] Propagating.", GetErrorMessage(r));
473 __pProgressPopupEvent->Fire(*pEventArg);
478 _ProgressPopup::OnDraw(void)
480 __pProgressPopupPresenter->Draw();
484 _ProgressPopup::OnFontChanged(Font * pFont)
486 __pProgressPopupPresenter->OnFontChanged(pFont);
490 _ProgressPopup::OnFontInfoRequested(unsigned long& style, int& size)
492 __pProgressPopupPresenter->OnFontInfoRequested(style, size);
496 _ProgressPopup::OnActionPerformed(const Tizen::Ui::_Control& source, int actionId)
500 case ID_PROGRESS_POPUP_CANCEL_BUTTON:
502 FireProgressPopupEvent();
503 _Popup::SetReturnValue(POPUP_RESULT_CANCEL);
513 _ProgressPopup::OnBoundsChanged(void)
515 SetClientBounds(Rectangle(0, 0, GetBounds().width, GetBounds().height));
521 _ProgressPopup::OnVisibleStateChanged(void)
523 _Popup::OnVisibleStateChanged();
527 _ProgressPopup::OnAttachedToMainTree(void)
530 SysTryReturn(NID_UI_CTRL, GetVisibleState() != false, E_INVALID_OPERATION,
531 E_INVALID_OPERATION, "[E_INVALID_OPERATION] This control is not 'displayable'");
533 InitializeAccessibilityElement();
539 _ProgressPopup::OnActivated(void)
541 __pProgressPopupPresenter->PlayProcessAnimation();
543 _Popup::OnActivated();
547 _ProgressPopup::OnDeactivated(void)
549 __pProgressPopupPresenter->StopProcessAnimation();
551 _Popup::OnDeactivated();
555 _ProgressPopup::InitializeAccessibilityElement(void)
557 if (likely(!(_AccessibilityManager::IsActivated())))
562 if ((_pTitleTextAccessibilityElement != null) && (__pTextAccessibilityElement != null))
567 _AccessibilityContainer* pContainer = GetAccessibilityContainer();
568 if (pContainer != null)
570 if (_pTitleTextAccessibilityElement == null)
572 _pTitleTextAccessibilityElement = new (std::nothrow) _AccessibilityElement(true);
573 SysTryReturnVoidResult(NID_UI_CTRL, _pTitleTextAccessibilityElement != null, E_OUT_OF_MEMORY,"[E_OUT_OF_MEMORY] Memory allocation failed.");
575 _pTitleTextAccessibilityElement->Construct(L"ProgressPopupTitleText", __pProgressPopupPresenter->GetTitleBounds());
576 _pTitleTextAccessibilityElement->SetLabel(GetTitleText());
577 _pTitleTextAccessibilityElement->SetTrait(ACCESSIBILITY_TRAITS_TEXT_FIELD);
579 pContainer->AddElement(*_pTitleTextAccessibilityElement);
582 if (__pTextAccessibilityElement == null)
584 __pTextAccessibilityElement = new (std::nothrow) _AccessibilityElement(true);
585 SysTryReturnVoidResult(NID_UI_CTRL, __pTextAccessibilityElement != null, E_OUT_OF_MEMORY,"[E_OUT_OF_MEMORY] Memory allocation failed.");
587 __pTextAccessibilityElement->Construct(L"ProgressPopupText", __pProgressPopupPresenter->GetTextBounds());
588 __pTextAccessibilityElement->SetLabel(GetText());
589 __pTextAccessibilityElement->SetTrait(ACCESSIBILITY_TRAITS_TEXT_FIELD);
591 pContainer->AddElement(*__pTextAccessibilityElement);
594 if (HasButton() == true)
596 _ControlImpl* pImpl = null;
597 _Button* pButtonCore = null;
599 pImpl = _ControlImpl::GetInstance(*__pButton);
601 pButtonCore = dynamic_cast<_Button*>(&pImpl->GetCore());
602 result r = GetLastResult();
603 SysTryReturnVoidResult(NID_UI_CTRL, pButtonCore != null, r, "[%s] Propagating.", GetErrorMessage(r));
605 _AccessibilityContainer* pButtonContainer = pButtonCore->GetAccessibilityContainer();
606 if (pButtonContainer != null)
608 _AccessibilityElement* pButtonElement = pButtonContainer->GetChildElement(L"ButtonText");
609 if (pButtonElement != null)
611 pButtonElement->SetName(L"ProgressPopupButton1");
615 pContainer->AddChildContainer(*pButtonContainer);
626 _ProgressPopup::OnChangeLayout(_ControlOrientation orientation)
628 SysTryReturnVoidResult(NID_UI_CTRL, _pDimmingLayer != null, E_SYSTEM, "[E_SYSTEM] There is no Dimming Layer.");
630 result r = E_SUCCESS;
632 r = _pDimmingLayer->Rearrange();
633 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
637 _ProgressPopup::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
644 return __pProgressPopupPresenter->OnTouchPressed(source, touchinfo);
648 _ProgressPopup::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
655 return __pProgressPopupPresenter->OnTouchMoved(source, touchinfo);
659 _ProgressPopup::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
666 return __pProgressPopupPresenter->OnTouchReleased(source, touchinfo);
670 }}} // Tizen::Ui::Controls