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_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 "FUi_AccessibilityContainer.h"
27 #include "FUi_AccessibilityElement.h"
28 #include "FUi_ControlManager.h"
29 #include "FUi_ModalLoopManager.h"
30 #include "FUi_ResourceManager.h"
31 #include "FUi_DataBindingContext.h"
32 #include "FUiCtrl_Popup.h"
33 #include "FUiCtrl_PopupPresenter.h"
34 #include "FUiCtrl_Form.h"
35 #include "FUiCtrl_Frame.h"
38 using namespace Tizen::Graphics;
39 using namespace Tizen::Ui::Animations;
40 using namespace Tizen::Ui;
41 using namespace Tizen::Base;
44 namespace Tizen { namespace Ui { namespace Controls
50 , _ownerEnableState(false)
52 , _bgColor(Color(0xFFFFFFFF))
53 , _titleTextColor(Color(0xFFFFFFFF))
55 , _pComposedBgBitmap(null)
56 , _pOutlineBitmap(null)
57 , _pDimmingLayer(null)
58 , _pTitleTextAccessibilityElement(null)
59 , __pPopupPresenter(null)
60 , __bounds(0, 0, 0, 0)
61 , __popupResult(POPUP_RESULT_NONE)
68 _Control* pOwner = GetOwner();
71 pOwner->SetInputEnableState(_ownerEnableState);
74 ReleaseTouchCapture();
76 delete __pPopupPresenter;
77 __pPopupPresenter = null;
82 delete _pComposedBgBitmap;
83 _pComposedBgBitmap = null;
85 delete _pOutlineBitmap;
86 _pOutlineBitmap = null;
88 delete _pDimmingLayer;
89 _pDimmingLayer = null;
91 if (_pTitleTextAccessibilityElement)
93 _pTitleTextAccessibilityElement->Activate(false);
94 _pTitleTextAccessibilityElement = null;
99 _Popup::CreatePopupN(void)
101 _Popup* pPopup = new (std::nothrow) _Popup();
102 SysTryReturn(NID_UI_CTRL, pPopup != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
104 #if defined(MULTI_WINDOW)
105 result r = pPopup->CreateRootVisualElement();
106 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
109 // for taking touch event
110 pPopup->AcquireHandle();
114 #if defined(MULTI_WINDOW)
122 _Popup::Initialize(bool hasTitle, const Tizen::Graphics::Rectangle& bounds)
124 result r = E_SUCCESS;
126 _AccessibilityContainer* pContainer = null;
128 _titleState = hasTitle;
130 SetClientBounds(GetPopupClientArea());
132 _PopupPresenter* pPresenter = new (std::nothrow) _PopupPresenter();
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);
136 pPresenter->Initialize(*this);
138 _pDimmingLayer = new (std::nothrow) _DimmingLayer();
139 SysTryReturn(NID_UI_CTRL, _pDimmingLayer != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
141 r = _pDimmingLayer->Construct(*this);
142 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
144 GET_COLOR_CONFIG(POPUP::BG_NORMAL, _bgColor);
145 GET_COLOR_CONFIG(POPUP::TITLE_TEXT_NORMAL, _titleTextColor);
148 GET_BITMAP_CONFIG_N(POPUP::BG_OUTLINE_EFFECT_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, _pOutlineBitmap);
150 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
153 GET_BITMAP_CONFIG_N(POPUP::BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, _pBgBitmap);
155 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
157 _pComposedBgBitmap = _BitmapImpl::GetColorReplacedBitmapN(*_pBgBitmap, Color::GetColor(COLOR_ID_MAGENTA), _bgColor);
159 // for clearing canvas
160 r = GetVisualElement()->SetSurfaceOpaque(false);
161 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
163 //create data binding context
164 _DataBindingContext* pContext = new (std::nothrow) _DataBindingContext(*this);
165 SysTryCatch(NID_UI_CTRL, pContext != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
167 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
169 SetDataBindingContext(pContext);
171 pContainer = GetAccessibilityContainer();
172 if(pContainer != null)
174 pContainer->Activate(true);
186 _Popup::SetPresenter(const _PopupPresenter& popupPresenter)
188 __pPopupPresenter = const_cast <_PopupPresenter*>(&popupPresenter);
194 _Popup::DoModal(int& modalResult)
196 result r = E_SUCCESS;
198 __pPopupPresenter->DoModal(modalResult);
200 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
206 _Popup::EndModal(int modalResult)
208 _ModalLoopManager::GetInstance()->EndMainLoop(POPUP_RESULT_END_MODAL, false);
210 SetReturnValue(static_cast <PopupModalResult>(modalResult));
216 _Popup::SetReturnValue(PopupModalResult rtn)
222 _Popup::GetPopupReturnValue(void) const
224 return (int) __popupResult;
228 _Popup::HasTitle(void) const
234 _Popup::TranslateFromClientAreaPosition(const Point& clientPosition) const
236 Rectangle leftTop = GetClientBounds();
237 result r = GetLastResult();
238 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, Point(-1, -1), r, "[%s] Propagating.", GetErrorMessage(r));
240 return Point(clientPosition.x + leftTop.x, clientPosition.y + leftTop.y);
244 _Popup::TranslateToClientAreaPosition(const Point& position) const
246 Rectangle leftTop = GetClientBounds();
247 result r = GetLastResult();
248 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, Point(-1, -1), r, "[%s] Propagating.", GetErrorMessage(r));
250 return Point(position.x - leftTop.x, position.y - leftTop.y);
254 _Popup::GetClientAreaCanvasN(void) const
256 Canvas* pCanvas = GetCanvasN(GetClientBounds());
257 if ((pCanvas == null) || (GetLastResult() != E_SUCCESS))
259 SysLog(NID_UI_CTRL, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
268 _Popup::SetColor(const Color& color)
270 if (_pComposedBgBitmap != null)
272 delete _pComposedBgBitmap;
273 _pComposedBgBitmap = null;
276 _pComposedBgBitmap = _BitmapImpl::GetColorReplacedBitmapN(*_pBgBitmap, Color::GetColor(COLOR_ID_MAGENTA), color);
282 _Popup::GetColor() const
288 _Popup::SetTitleTextColor(const Color& color)
290 _titleTextColor = color;
294 _Popup::GetTitleTextColor() const
296 return _titleTextColor;
300 _Popup::SetTitleText(const String& title)
302 if (HasTitle() == true)
306 if (__pPopupPresenter != null)
308 result r = __pPopupPresenter->SetTitleTextObject(title);
309 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
312 if (_pTitleTextAccessibilityElement != null)
314 _pTitleTextAccessibilityElement->SetLabel(title);
326 _Popup::GetTitleText(void) const
332 _Popup::GetBackgroundBitmap(void) const
334 return _pComposedBgBitmap;
338 _Popup::GetOutlineBitmap(void) const
340 return _pOutlineBitmap;
344 _Popup::GetPopupClientArea(void) const
352 int titleLetfMargin = 0;
353 int titleRightMargin = 0;
355 int transTopMargin = 0;
356 int transBottomMargin = 0;
357 int transLeftMargin = 0;
358 int transRightMargin = 0;
361 GET_SHAPE_CONFIG(POPUP::TITLE_HEIGHT, GetOrientation(), titleHeight);
362 GET_SHAPE_CONFIG(POPUP::TITLE_TEXT_LEFT_MARGIN, GetOrientation(), titleLetfMargin);
363 GET_SHAPE_CONFIG(POPUP::TITLE_TEXT_RIGHT_MARGIN, GetOrientation(), titleRightMargin);
365 GET_SHAPE_CONFIG(POPUP::BG_IMAGE_TRANSPARENT_TOP_MARGIN, GetOrientation(), transTopMargin);
366 GET_SHAPE_CONFIG(POPUP::BG_IMAGE_TRANSPARENT_BOTTOM_MARGIN, GetOrientation(), transBottomMargin);
367 GET_SHAPE_CONFIG(POPUP::BG_IMAGE_TRANSPARENT_LEFT_MARGIN, GetOrientation(), transLeftMargin);
368 GET_SHAPE_CONFIG(POPUP::BG_IMAGE_TRANSPARENT_RIGHT_MARGIN, GetOrientation(), transRightMargin);
371 width = GetBounds().width - (titleLetfMargin + titleRightMargin);
373 if (HasTitle() == false)
379 height = GetBounds().height - y;
381 return Rectangle(x, y, width, height);
384 _AccessibilityElement*
385 _Popup::GetTitleTextAccessibilityElement(void)
387 return _pTitleTextAccessibilityElement;
393 __pPopupPresenter->OnDraw();
394 result r = GetLastResult();
395 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
401 _Popup::OnFontChanged(Font * pFont)
403 if (__pPopupPresenter != null)
405 __pPopupPresenter->OnFontChanged(pFont);
410 _Popup::OnFontInfoRequested(unsigned long& style, int& size)
412 if (__pPopupPresenter != null)
414 __pPopupPresenter->OnFontInfoRequested(style, size);
419 _Popup::OnActivated(void)
421 SysTryReturnVoidResult(NID_UI_CTRL, _pDimmingLayer != null, E_SYSTEM, "[E_SYSTEM] There is no Dimming Layer.");
423 result r = E_SUCCESS;
425 if (__pPopupPresenter != null)
427 __pPopupPresenter->OnActivated();
430 if (GetVisibleState())
432 r = _pDimmingLayer->SetDimmingEnabled(true);
433 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
439 r = _pDimmingLayer->SetDimmingEnabled(false);
440 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
443 if (GetOwner() == null)
445 _Frame* pFrame = dynamic_cast<_Frame*>(_ControlManager::GetInstance()->GetCurrentFrame());
446 SysTryReturnVoidResult(NID_UI_CTRL, pFrame != null, E_SYSTEM,"[E_SYSTEM] This instance is not constructed.");
448 _Form* pForm = pFrame->GetCurrentForm();
459 _Control* pOwner = GetOwner();
463 _ownerEnableState = pOwner->GetInputEnableState();
464 pOwner->SetInputEnableState(false);
467 _Window::OnActivated();
471 _Popup::OnDeactivated(void)
473 SysTryReturnVoidResult(NID_UI_CTRL, _pDimmingLayer != null, E_SYSTEM, "[E_SYSTEM] There is no Dimming Layer.");
475 #if !defined(MULTI_WINDOW)
476 result r = E_SUCCESS;
478 if (IsAttached() == false)
480 r = _pDimmingLayer->SetDimmingEnabled(false);
481 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
485 _Control* pOwner = GetOwner();
488 pOwner->SetInputEnableState(_ownerEnableState);
491 ReleaseTouchCapture();
493 _Window::OnDeactivated();
497 _Popup::OnVisibleStateChanged(void)
499 result r = E_SUCCESS;
501 if (GetVisibleState() == true)
503 r = _pDimmingLayer->SetDimmingEnabled(true);
504 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
508 r = _pDimmingLayer->SetDimmingEnabled(false);
509 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
512 _Window::OnVisibleStateChanged();
516 _Popup::OnAttachingToMainTree(const _Control* pParent)
518 return _Window::OnAttachingToMainTree(pParent);
522 _Popup::OnAttachedToMainTree(void)
524 SysTryReturn(NID_UI_CTRL, GetVisibleState() != false, E_INVALID_OPERATION,
525 E_INVALID_OPERATION, "[E_INVALID_OPERATION] This control is not 'displayable'");
527 InitializeAccessibilityElement();
533 _Popup::InitializeAccessibilityElement(void)
535 if (likely(!(_AccessibilityManager::IsActivated())))
540 if (_pTitleTextAccessibilityElement != null)
545 _AccessibilityContainer* pContainer = GetAccessibilityContainer();
546 if (pContainer != null)
549 GET_SHAPE_CONFIG(POPUP::TITLE_HEIGHT, GetOrientation(), titleHeight);
551 _pTitleTextAccessibilityElement = new (std::nothrow) _AccessibilityElement(true);
552 SysTryReturnVoidResult(NID_UI_CTRL, _pTitleTextAccessibilityElement != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
554 _pTitleTextAccessibilityElement->Construct(L"PopupTitleText", __pPopupPresenter->GetTitleTextBounds());
555 _pTitleTextAccessibilityElement->SetLabel(GetTitleText());
556 _pTitleTextAccessibilityElement->SetTrait(ACCESSIBILITY_TRAITS_TEXT_FIELD);
558 pContainer->AddElement(*_pTitleTextAccessibilityElement);
560 _Label* pLabelCore = __pPopupPresenter->GetSystemLabel();
561 _AccessibilityContainer* pLabelContainer = pLabelCore->GetAccessibilityContainer();
562 if (pLabelContainer != null)
564 pLabelContainer->Activate(false);
572 _Popup::OnDetachingFromMainTree(void)
574 return _Window::OnDetachingFromMainTree();
578 _Popup::OnChangeLayout(_ControlOrientation orientation)
580 SysTryReturnVoidResult(NID_UI_CTRL, _pDimmingLayer != null, E_SYSTEM, "[E_SYSTEM] There is no Dimming Layer.");
582 result r = E_SUCCESS;
584 r = _pDimmingLayer->Rearrange();
585 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
591 _Popup::OnBoundsChanged(void)
593 SetClientBounds(GetPopupClientArea());
595 if (__pPopupPresenter != null)
597 __pPopupPresenter->UpdateEffectBounds();
600 if (_pTitleTextAccessibilityElement != null)
603 GET_SHAPE_CONFIG(POPUP::TITLE_HEIGHT, GetOrientation(), titleHeight);
605 _pTitleTextAccessibilityElement->SetBounds(Rectangle(0, 0, GetPopupClientArea().width, titleHeight));
609 #if defined(MULTI_WINDOW)
611 _Popup::OnBoundsChanging(const Rectangle& bounds)
613 // Full-screen window
618 _Popup::IsLayoutChangable(void) const
620 // Full-screen window
626 _Popup::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
633 return __pPopupPresenter->OnTouchPressed(source, touchinfo);
637 _Popup::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
644 return __pPopupPresenter->OnTouchReleased(source, touchinfo);
648 }}} // Tizen::Ui::Controls