2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0/
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_Popup.cpp
20 * @brief This is the implementation file for the _Popup class.
23 #include <FBaseSysLog.h>
24 #include <FBaseErrorDefine.h>
25 #include <FGrp_BitmapImpl.h>
26 #include <FUiCtrlForm.h>
27 #include "FUi_AccessibilityContainer.h"
28 #include "FUi_AccessibilityElement.h"
29 #include "FUi_ControlManager.h"
30 #include "FUi_CoordinateSystemUtils.h"
31 #include "FUi_EcoreEvas.h"
32 #include "FUi_EcoreEvasMgr.h"
33 #include "FUi_ModalLoopManager.h"
34 #include "FUi_ResourceManager.h"
35 #include "FUi_DataBindingContext.h"
36 #include "FUiCtrl_Popup.h"
37 #include "FUiCtrl_PopupPresenter.h"
38 #include "FUiCtrl_Form.h"
39 #include "FUiCtrl_Frame.h"
40 #include "FUiCtrl_Indicator.h"
43 using namespace Tizen::Graphics;
44 using namespace Tizen::Ui::Animations;
45 using namespace Tizen::Ui;
46 using namespace Tizen::Base;
49 namespace Tizen { namespace Ui { namespace Controls
56 , _bgColor(Color(0xFFFFFFFF))
57 , _titleTextColor(Color(0xFFFFFFFF))
59 , _pComposedBgBitmap(null)
60 , _pOutlineBitmap(null)
61 , _pComposedTitleBitmap(null)
62 , _pTitleEffectBitmap(null)
63 , _pTitleTextAccessibilityElement(null)
64 , __pPopupPresenter(null)
65 , __bounds(0.0f, 0.0f, 0.0f, 0.0f)
66 , __popupResult(POPUP_RESULT_NONE)
69 __pIndicator = _Indicator::CreateIndicator();
70 SysTryReturnVoidResult(NID_UI_CTRL, GetLastResult() == E_SUCCESS, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
75 delete __pPopupPresenter;
76 __pPopupPresenter = null;
81 delete _pComposedBgBitmap;
82 _pComposedBgBitmap = null;
84 delete _pOutlineBitmap;
85 _pOutlineBitmap = null;
87 delete _pComposedTitleBitmap;
88 _pComposedTitleBitmap = null;
90 delete _pTitleEffectBitmap;
91 _pTitleEffectBitmap = null;
93 if (_pTitleTextAccessibilityElement)
95 _pTitleTextAccessibilityElement->Activate(false);
96 _pTitleTextAccessibilityElement = null;
101 __pIndicator->Destroy();
107 _Popup::CreatePopupN(void)
109 _Popup* pPopup = new (std::nothrow) _Popup();
110 SysTryReturn(NID_UI_CTRL, pPopup != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
112 result r = pPopup->CreateRootVisualElement(_WINDOW_TYPE_SUB);
113 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
115 // for taking touch event
116 pPopup->AcquireHandle();
126 _Popup::Initialize(bool hasTitle, const Tizen::Graphics::FloatRectangle& bounds)
128 result r = E_SUCCESS;
130 _AccessibilityContainer* pContainer = null;
131 _DataBindingContext* pContext = null;
132 Bitmap* titleBgBitmap = null;
133 Color titleBgColor(0x00000000);
135 _titleState = hasTitle;
137 SetClientBounds(GetPopupClientArea());
139 _PopupPresenter* pPresenter = new (std::nothrow) _PopupPresenter();
140 SysTryReturn(NID_UI_CTRL, pPresenter != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
142 SetPresenter(*pPresenter);
143 pPresenter->Initialize(*this);
145 SetDimmingEnabled(true);
147 GET_COLOR_CONFIG(POPUP::BG_NORMAL, _bgColor);
148 GET_COLOR_CONFIG(POPUP::TITLE_TEXT_NORMAL, _titleTextColor);
152 GET_COLOR_CONFIG(POPUP::TITLE_BG_NORMAL, titleBgColor);
155 GET_BITMAP_CONFIG_N(POPUP::BG_TITLE_AREA, BITMAP_PIXEL_FORMAT_ARGB8888, titleBgBitmap);
157 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
159 _pComposedTitleBitmap = _BitmapImpl::GetColorReplacedBitmapN(*titleBgBitmap, Color::GetColor(COLOR_ID_MAGENTA), titleBgColor);
161 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
163 // Popup-TitleEffectBitmap
164 GET_BITMAP_CONFIG_N(POPUP::BG_TITLE_EFFECT, BITMAP_PIXEL_FORMAT_ARGB8888, _pTitleEffectBitmap);
166 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
170 GET_BITMAP_CONFIG_N(POPUP::BG_OUTLINE_EFFECT_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, _pOutlineBitmap);
172 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
175 GET_BITMAP_CONFIG_N(POPUP::BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, _pBgBitmap);
177 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
179 _pComposedBgBitmap = _BitmapImpl::GetColorReplacedBitmapN(*_pBgBitmap, Color::GetColor(COLOR_ID_MAGENTA), _bgColor);
181 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
183 // for clearing canvas
184 r = GetVisualElement()->SetSurfaceOpaque(false);
185 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
187 GetVisualElement()->SetClipChildrenEnabled(true);
189 //create data binding context
190 pContext = new (std::nothrow) _DataBindingContext(*this);
191 SysTryCatch(NID_UI_CTRL, pContext != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
193 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
195 SetDataBindingContext(pContext);
197 pContainer = GetAccessibilityContainer();
198 if(pContainer != null)
200 pContainer->Activate(true);
203 if (titleBgBitmap != null)
205 delete titleBgBitmap;
206 titleBgBitmap = null;
214 if (titleBgBitmap != null)
216 delete titleBgBitmap;
217 titleBgBitmap = null;
220 if (_pComposedTitleBitmap != null)
222 delete _pComposedTitleBitmap;
223 _pComposedTitleBitmap = null;
226 if (_pTitleEffectBitmap != null)
228 delete _pTitleEffectBitmap;
229 _pTitleEffectBitmap = null;
232 delete _pOutlineBitmap;
233 _pOutlineBitmap = null;
238 delete _pComposedBgBitmap;
239 _pComposedBgBitmap = null;
245 _Popup::SetPresenter(const _PopupPresenter& popupPresenter)
247 __pPopupPresenter = const_cast <_PopupPresenter*>(&popupPresenter);
253 _Popup::GetPresenter(void)
255 return __pPopupPresenter;
259 _Popup::DoModal(int& modalResult)
261 SysTryReturn(NID_UI_CTRL, __pPopupPresenter != null, E_INVALID_STATE, E_INVALID_STATE, "[E_INVALID_STATE] This instance is not allocated.");
263 __pPopupPresenter->DoModal(modalResult);
265 result r = GetLastResult();
266 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
272 _Popup::EndModal(int modalResult)
274 _ModalLoopManager::GetInstance()->EndMainLoop(POPUP_RESULT_END_MODAL, false);
276 SetReturnValue(static_cast <PopupModalResult>(modalResult));
282 _Popup::SetReturnValue(PopupModalResult rtn)
288 _Popup::GetPopupReturnValue(void) const
290 return (int) __popupResult;
294 _Popup::HasTitle(void) const
300 _Popup::TranslateFromClientAreaPosition(const FloatPoint& clientPosition) const
302 FloatRectangle leftTop = GetClientBoundsF();
303 result r = GetLastResult();
304 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, FloatPoint(-1.0f, -1.0f), r, "[%s] Propagating.", GetErrorMessage(r));
306 return FloatPoint(clientPosition.x + leftTop.x, clientPosition.y + leftTop.y);
310 _Popup::TranslateToClientAreaPosition(const FloatPoint& position) const
312 FloatRectangle leftTop = GetClientBoundsF();
313 result r = GetLastResult();
314 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, FloatPoint(-1.0f, -1.0f), r, "[%s] Propagating.", GetErrorMessage(r));
316 return FloatPoint(position.x - leftTop.x, position.y - leftTop.y);
320 _Popup::GetClientAreaCanvasN(void) const
322 Canvas* pCanvas = GetCanvasN(GetClientBoundsF());
323 if ((pCanvas == null) || (GetLastResult() != E_SUCCESS))
325 SysLog(NID_UI_CTRL, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
334 _Popup::SetColor(const Color& color)
336 if (_pComposedBgBitmap != null)
338 delete _pComposedBgBitmap;
339 _pComposedBgBitmap = null;
342 _pComposedBgBitmap = _BitmapImpl::GetColorReplacedBitmapN(*_pBgBitmap, Color::GetColor(COLOR_ID_MAGENTA), color);
348 _Popup::GetColor() const
354 _Popup::SetTitleTextColor(const Color& color)
356 _titleTextColor = color;
360 _Popup::GetTitleTextColor() const
362 return _titleTextColor;
366 _Popup::SetTitleText(const String& title)
368 if (HasTitle() == true)
370 if (__pPopupPresenter != null)
374 result r = __pPopupPresenter->SetTitleTextObject(_titleText);
375 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
377 if (_pTitleTextAccessibilityElement != null)
379 _pTitleTextAccessibilityElement->SetLabel(title);
392 _Popup::GetTitleText(void) const
398 _Popup::GetBackgroundBitmap(void) const
400 return _pComposedBgBitmap;
404 _Popup::GetOutlineBitmap(void) const
406 return _pOutlineBitmap;
410 _Popup::GetTitleBackgroundBitmap(void)
412 return _pComposedTitleBitmap;
416 _Popup::GetTitleBackgroundEffectBitmap(void)
418 return _pTitleEffectBitmap;
423 _Popup::GetPopupClientArea(void) const
430 float titleHeight = 0.0f;
434 GET_SHAPE_CONFIG(POPUP::TITLE_HEIGHT, GetOrientation(), titleHeight);
438 width = GetBoundsF().width;
439 height = GetBoundsF().height - y;
441 return FloatRectangle(x, y, width, height);
444 _AccessibilityElement*
445 _Popup::GetTitleTextAccessibilityElement(void)
447 return _pTitleTextAccessibilityElement;
451 _Popup::GetIndicator(void) const
459 __pPopupPresenter->OnDraw();
460 result r = GetLastResult();
461 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
462 if(unlikely((_AccessibilityManager::IsActivated())))
464 _AccessibilityManager::GetInstance()->RequestAutoReading(_ACCESSIBILITY_AUTO_READING_MODE_FIRST_ITEM);
470 _Popup::OnFontChanged(Font * pFont)
472 if (__pPopupPresenter != null)
474 __pPopupPresenter->OnFontChanged(pFont);
479 _Popup::OnFontInfoRequested(unsigned long& style, float& size)
481 if (__pPopupPresenter != null)
483 __pPopupPresenter->OnFontInfoRequested(style, size);
488 _Popup::OnActivated(void)
490 if (__pPopupPresenter != null)
492 __pPopupPresenter->OnActivated();
495 if (GetVisibleState())
497 SetTouchCapture(false, false);
500 bool showstate = false;
501 bool opacity = false;
502 unsigned long formstyle = 0x00000000;
504 _Control* pOwner = GetOwner();
507 _Frame* pFrame = dynamic_cast<_Frame*>(_ControlManager::GetInstance()->GetCurrentFrame());
508 SysTryReturnVoidResult(NID_UI_CTRL, pFrame != null, E_SYSTEM, "[E_SYSTEM] This instance is not constructed.");
510 _Form* pForm = pFrame->GetCurrentForm();
515 showstate = pForm->IsIndicatorVisible();
516 opacity = pForm->IsIndicatorTranslucent();
517 formstyle = pForm->GetFormStyle();
526 _Form* pForm = dynamic_cast<_Form*>(pOwner);
529 showstate = pForm->IsIndicatorVisible();
530 opacity = pForm->IsIndicatorTranslucent();
531 formstyle = pForm->GetFormStyle();
534 pOwner->LockInputEvent();
539 __pIndicator->AddIndicatorObject(this, GetRootWindow());
542 float indicatorwidth = 0.0f;
543 float indicatorheight = 0.0f;
545 if (GetOrientation() == _CONTROL_ORIENTATION_PORTRAIT)
547 indicatorwidth = _ControlManager::GetInstance()->_ControlManager::GetScreenSizeF().width;
548 GET_SHAPE_CONFIG(FORM::INDICATOR_HEIGHT, GetOrientation(), indicatorheight);
552 indicatorwidth = _ControlManager::GetInstance()->_ControlManager::GetScreenSizeF().height;
553 GET_SHAPE_CONFIG(FORM::INDICATOR_MINIMIZE_HEIGHT, GetOrientation(), indicatorheight);
555 __pIndicator->SetBounds(FloatRectangle(0.0f, 0.0f, indicatorwidth, indicatorheight));
556 __pIndicator->SetIndicatorShowState(showstate);
559 __pIndicator->SetIndicatorOpacity(_INDICATOR_OPACITY_TRANSLUCENT);
563 __pIndicator->SetIndicatorOpacity(_INDICATOR_OPACITY_OPAQUE);
566 if (formstyle & FORM_STYLE_PORTRAIT_INDICATOR)
568 if (formstyle & FORM_STYLE_LANDSCAPE_INDICATOR_AUTO_HIDE)
570 __pIndicator->SetIndicatorAutoHide(false, true);
574 __pIndicator->SetIndicatorAutoHide(false, false);
577 else if (formstyle & FORM_STYLE_INDICATOR_AUTO_HIDE)
579 if (formstyle & FORM_STYLE_LANDSCAPE_INDICATOR_AUTO_HIDE)
581 __pIndicator->SetIndicatorAutoHide(true, true);
585 __pIndicator->SetIndicatorAutoHide(true, false);
590 if (formstyle & FORM_STYLE_LANDSCAPE_INDICATOR_AUTO_HIDE)
592 __pIndicator->SetIndicatorAutoHide(false, true);
596 __pIndicator->SetIndicatorAutoHide(false, false);
601 _Window::OnActivated();
605 _Popup::OnDeactivated(void)
607 _Control* pOwner = GetOwner();
610 pOwner->UnlockInputEvent();
613 ReleaseTouchCapture();
615 _Window::OnDeactivated();
619 _Popup::OnVisibleStateChanged(void)
621 _Window::OnVisibleStateChanged();
625 _Popup::OnAttachingToMainTree(const _Control* pParent)
627 return _Window::OnAttachingToMainTree(pParent);
631 _Popup::OnAttachedToMainTree(void)
633 SysTryReturn(NID_UI_CTRL, GetVisibleState() != false, E_INVALID_OPERATION,
634 E_INVALID_OPERATION, "[E_INVALID_OPERATION] This control is not 'displayable'");
636 _Control* pOwner = GetOwner();
639 GetEcoreEvasMgr()->GetEcoreEvas()->SetOwner(*this, *pOwner);
644 __pIndicator->OnAttachedToMainTree();
647 InitializeAccessibilityElement();
653 _Popup::InitializeAccessibilityElement(void)
655 _AccessibilityContainer* pContainer = GetAccessibilityContainer();
656 if (pContainer != null)
658 pContainer->RemoveAllElement();
659 _pTitleTextAccessibilityElement = null;
660 if (HasTitle() == true)
662 _pTitleTextAccessibilityElement = new (std::nothrow) _AccessibilityElement(true);
663 SysTryReturnVoidResult(NID_UI_CTRL, _pTitleTextAccessibilityElement != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
665 _PopupPresenter* pPresenter = GetPresenter();
666 SysTryReturnVoidResult(NID_UI_CTRL, pPresenter != null, E_SYSTEM, "[E_SYSTEM] This instance is not constructed.");
667 _pTitleTextAccessibilityElement->Construct(L"PopupTitleText", pPresenter->GetTitleTextBounds());
668 _pTitleTextAccessibilityElement->SetLabel(GetTitleText());
669 _pTitleTextAccessibilityElement->SetTrait(L"Popup Title");
671 pContainer->AddElement(*_pTitleTextAccessibilityElement);
679 _Popup::OnDetachingFromMainTree(void)
683 __pIndicator->DeleteIndicatorObject();
685 return _Window::OnDetachingFromMainTree();
689 _Popup::OnBoundsChanging(const FloatRectangle& bounds)
695 _Popup::OnBoundsChanged(void)
697 SetClientBounds(GetPopupClientArea());
699 if (__pPopupPresenter != null)
701 __pPopupPresenter->OnBoundsChanged();
703 if ((_pTitleTextAccessibilityElement != null) && (HasTitle() == true))
705 _pTitleTextAccessibilityElement->SetBounds(__pPopupPresenter->GetTitleTextBounds());
711 _Popup::OnDrawFocus(void)
717 _Popup::IsLayoutChangable(void) const
723 _Popup::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
730 return __pPopupPresenter->OnTouchPressed(source, touchinfo);
734 _Popup::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
741 return __pPopupPresenter->OnTouchReleased(source, touchinfo);
745 _Popup::OnOwnerChanged(_Control* pOldOwner)
747 if (IsActivated() == false)
752 _Control* pOwner = GetOwner();
754 if (pOldOwner != null)
756 pOldOwner->UnlockInputEvent();
761 pOwner->LockInputEvent();
766 _Popup::UpdateClientBounds(const FloatDimension& size, FloatRectangle& clientBounds)
768 float titleHeight = 0.0f;
772 GET_SHAPE_CONFIG(POPUP::TITLE_HEIGHT, GetOrientation(), titleHeight);
773 clientBounds.y = titleHeight;
776 clientBounds.width = size.width;
777 clientBounds.height = size.height - clientBounds.y;
781 _Popup::IsRotationSynchronized(void) const
787 _Popup::OnChangeLayout(_ControlOrientation orientation)
789 _Window::OnChangeLayout(orientation);
791 float indicatorheight = 0.0f;
793 const FloatDimension portraitSize = _ControlManager::GetInstance()->_ControlManager::GetScreenSizeF();
794 const FloatDimension landscapeSize = FloatDimension(portraitSize.height, portraitSize.width);
796 GET_SHAPE_CONFIG(FORM::INDICATOR_HEIGHT, GetOrientation(), indicatorheight);
798 _Form* pForm = dynamic_cast<_Form*>(GetOwner());
803 if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
805 __pIndicator->SetBounds(FloatRectangle(0.0f, 0.0f, portraitSize.width, indicatorheight));
806 if ((FORM_STYLE_INDICATOR & pForm->GetFormStyle()) || (FORM_STYLE_INDICATOR_AUTO_HIDE & pForm->GetFormStyle()))
808 __pIndicator->SetIndicatorShowState(true);
812 __pIndicator->SetIndicatorShowState(false);
817 if (FORM_STYLE_LANDSCAPE_INDICATOR_AUTO_HIDE & pForm->GetFormStyle())
819 __pIndicator->SetIndicatorShowState(true);
823 __pIndicator->SetIndicatorShowState(false);
826 __pIndicator->OnChangeLayout(orientation);
831 }}} // Tizen::Ui::Controls