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_PopupPresenter.cpp
20 * @brief This is the implementation file for the _PopupPresenter class.
24 #include <FBaseErrorDefine.h>
25 #include <FBaseSysLog.h>
26 #include <FGrp_BitmapImpl.h>
27 #include <FGrp_CanvasImpl.h>
28 #include <FGrp_FontImpl.h>
29 #include <FGrp_TextTextSimple.h>
30 #include "FUi_ControlManager.h"
31 #include "FUi_ModalLoopManager.h"
32 #include "FUi_ResourceManager.h"
33 #include "FUi_UiTouchEvent.h"
34 #include "FUiAnim_RootVisualElement.h"
35 #include "FUiCtrl_Label.h"
36 #include "FUiCtrl_PopupPresenter.h"
37 #include "FUiCtrl_Popup.h"
40 using namespace Tizen::Base;
41 using namespace Tizen::Graphics;
42 using namespace Tizen::Graphics::_Text;
43 using namespace Tizen::Ui;
44 using namespace Tizen::Ui::Animations;
47 namespace Tizen { namespace Ui { namespace Controls
51 _PopupPresenter::_PopupPresenter(void)
55 , __pBackgroundVE(null)
58 , __titleBounds(0, 0, 0, 0)
63 _PopupPresenter::~_PopupPresenter(void)
65 if (__pTextObject != null)
74 if (__pBackgroundVE != null)
76 __pBackgroundVE->Destroy();
77 __pBackgroundVE = null;
82 _PopupPresenter::UpdateEffectBounds(void)
87 int bgOutlineEffectTopMargin = 0;
88 int bgOutlineEffectBottomMargin = 0;
89 int bgOutlineEffectLeftMargin = 0;
90 int bgOutlineEffectRightMargin = 0;
93 GET_SHAPE_CONFIG(POPUP::BG_OUTLINE_EFFECT_TOP_MARGIN, __pPopup->GetOrientation(), bgOutlineEffectTopMargin);
94 GET_SHAPE_CONFIG(POPUP::BG_OUTLINE_EFFECT_BOTTOM_MARGIN, __pPopup->GetOrientation(), bgOutlineEffectBottomMargin);
95 GET_SHAPE_CONFIG(POPUP::BG_OUTLINE_EFFECT_LEFT_MARGIN, __pPopup->GetOrientation(), bgOutlineEffectLeftMargin);
96 GET_SHAPE_CONFIG(POPUP::BG_OUTLINE_EFFECT_RIGHT_MARGIN, __pPopup->GetOrientation(), bgOutlineEffectRightMargin);
98 bounds = __pPopup->GetBounds();
100 screenRect = _ControlManager::GetInstance()->GetScreenSize();
101 if (__pPopup->GetOrientation() == _CONTROL_ORIENTATION_LANDSCAPE)
103 temp = screenRect.width;
104 screenRect.width = screenRect.height;
105 screenRect.height = temp;
108 bounds.x = (screenRect.width - (bounds.width)) / 2 - bgOutlineEffectLeftMargin;
109 bounds.y = (screenRect.height - (bounds.height)) / 2 - bgOutlineEffectTopMargin;
111 __pBackgroundVE->SetBounds(FloatRectangle((float)bounds.x,
113 (float)(bounds.width + bgOutlineEffectLeftMargin + bgOutlineEffectRightMargin),
114 (float)(bounds.height + bgOutlineEffectTopMargin + bgOutlineEffectBottomMargin)));
118 _PopupPresenter::Initialize(_Popup& popup)
120 result r = E_SUCCESS;
122 Dimension screenRect;
126 int transTopMargin = 0;
127 int transBottomMargin = 0;
128 int transLeftMargin = 0;
129 int transRightMargin = 0;
131 int bgOutlineEffectTopMargin = 0;
132 int bgOutlineEffectBottomMargin = 0;
133 int bgOutlineEffectLeftMargin = 0;
134 int bgOutlineEffectRightMargin = 0;
138 GET_SHAPE_CONFIG(POPUP::BG_IMAGE_TRANSPARENT_TOP_MARGIN, __pPopup->GetOrientation(), transTopMargin);
139 GET_SHAPE_CONFIG(POPUP::BG_IMAGE_TRANSPARENT_BOTTOM_MARGIN, __pPopup->GetOrientation(), transBottomMargin);
140 GET_SHAPE_CONFIG(POPUP::BG_IMAGE_TRANSPARENT_LEFT_MARGIN, __pPopup->GetOrientation(), transLeftMargin);
141 GET_SHAPE_CONFIG(POPUP::BG_IMAGE_TRANSPARENT_RIGHT_MARGIN, __pPopup->GetOrientation(), transRightMargin);
143 GET_SHAPE_CONFIG(POPUP::BG_OUTLINE_EFFECT_TOP_MARGIN, __pPopup->GetOrientation(), bgOutlineEffectTopMargin);
144 GET_SHAPE_CONFIG(POPUP::BG_OUTLINE_EFFECT_BOTTOM_MARGIN, __pPopup->GetOrientation(), bgOutlineEffectBottomMargin);
145 GET_SHAPE_CONFIG(POPUP::BG_OUTLINE_EFFECT_LEFT_MARGIN, __pPopup->GetOrientation(), bgOutlineEffectLeftMargin);
146 GET_SHAPE_CONFIG(POPUP::BG_OUTLINE_EFFECT_RIGHT_MARGIN, __pPopup->GetOrientation(), bgOutlineEffectRightMargin);
148 // system label to cover non-client area
149 __pLabelCore = _Label::CreateLabelN();
151 SysTryReturnVoidResult(NID_UI_CTRL, __pLabelCore != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
152 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
154 __pLabelCore->SetBackgroundColor(Color(0, 0 ,0, 0));
156 r = __pPopup->AttachSystemChild(*__pLabelCore);
157 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
159 __pBackgroundVE = new (std::nothrow) _VisualElement();
160 SysTryReturnVoidResult(NID_UI_CTRL, __pBackgroundVE != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
162 r = __pBackgroundVE->Construct();
163 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
165 bounds = __pPopup->GetBounds();
167 screenRect = _ControlManager::GetInstance()->GetScreenSize();
168 if (__pPopup->GetOrientation() == _CONTROL_ORIENTATION_LANDSCAPE)
170 temp = screenRect.width;
171 screenRect.width = screenRect.height;
172 screenRect.height = temp;
175 bounds.x = (screenRect.width - (bounds.width)) / 2 - bgOutlineEffectLeftMargin;
176 bounds.y = (screenRect.height - (bounds.height)) / 2 - bgOutlineEffectTopMargin;
178 __pBackgroundVE->SetBounds(FloatRectangle((float)bounds.x,
180 (float)(bounds.width + bgOutlineEffectLeftMargin + bgOutlineEffectRightMargin),
181 (float)(bounds.height + bgOutlineEffectTopMargin + bgOutlineEffectBottomMargin)));
183 r = __pBackgroundVE->SetSurfaceOpaque(false);
184 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
186 __pBackgroundVE->SetShowState(true);
188 __pPopupVE = __pPopup->GetVisualElement();
189 SysTryCatch(NID_UI_CTRL, (__pPopupVE != null), r = E_SYSTEM, E_SYSTEM,
190 "[E_SYSTEM] A system error has occurred. Failed to get the Popup visual element.");
198 __pBackgroundVE->Destroy();
199 __pBackgroundVE = null;
205 _PopupPresenter::GetSystemLabel(void) const
211 _PopupPresenter::OnFontChanged(Font* pFont)
217 _PopupPresenter::OnFontInfoRequested(unsigned long& style, int& size)
220 GET_SHAPE_CONFIG(POPUP::TITLE_TEXT_SIZE, __pPopup->GetOrientation(), textSize);
222 style = FONT_STYLE_PLAIN;
227 _PopupPresenter::SetTitleTextObject(const String &title)
229 result r = E_SUCCESS;
230 TextSimple* pSimpleText = null;
234 int titleTopMargin = 0;
235 int titleLeftMargin = 0;
236 int titleRightMargin = 0;
237 int transTopMargin = 0;
238 int transLeftMargin = 0;
239 int transRightMargin = 0;
241 GET_SHAPE_CONFIG(POPUP::TITLE_TEXT_SIZE, __pPopup->GetOrientation(), textSize);
242 GET_SHAPE_CONFIG(POPUP::TITLE_HEIGHT, __pPopup->GetOrientation(), titleHeight);
244 GET_SHAPE_CONFIG(POPUP::TITLE_TEXT_TOP_MARGIN, __pPopup->GetOrientation(), titleTopMargin);
245 GET_SHAPE_CONFIG(POPUP::TITLE_TEXT_LEFT_MARGIN, __pPopup->GetOrientation(), titleLeftMargin);
246 GET_SHAPE_CONFIG(POPUP::TITLE_TEXT_RIGHT_MARGIN, __pPopup->GetOrientation(), titleRightMargin);
248 GET_SHAPE_CONFIG(POPUP::BG_IMAGE_TRANSPARENT_TOP_MARGIN, __pPopup->GetOrientation(), transTopMargin);
249 GET_SHAPE_CONFIG(POPUP::BG_IMAGE_TRANSPARENT_LEFT_MARGIN, __pPopup->GetOrientation(), transLeftMargin);
250 GET_SHAPE_CONFIG(POPUP::BG_IMAGE_TRANSPARENT_RIGHT_MARGIN, __pPopup->GetOrientation(), transRightMargin);
253 _pFont = __pPopup->GetFallbackFont();
254 SysTryReturn(NID_UI_CTRL, _pFont != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
256 if (__pTextObject != null)
258 delete __pTextObject;
262 __pTextObject = new (std::nothrow) TextObject();
263 SysTryReturn(NID_UI_CTRL, __pTextObject != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
265 __pTextObject->Construct();
267 pSimpleText = new (std::nothrow) TextSimple(const_cast <wchar_t*>(title.GetPointer()),
269 TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
270 SysTryCatch(NID_UI_CTRL, pSimpleText != null , r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
272 __pTextObject->AppendElement(*pSimpleText);
273 __pTextObject->SetForegroundColor(__pPopup->GetTitleTextColor(), 0, __pTextObject->GetTextLength());
274 __pTextObject->SetWrap(TEXT_OBJECT_WRAP_TYPE_NONE);
275 __pTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
276 __pTextObject->SetTextObjectEllipsisType(TEXT_OBJECT_ELLIPSIS_TYPE_TAIL);
278 __pTextObject->SetFont(_pFont, 0, __pTextObject->GetTextLength());
279 __pTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_LEFT);
281 __pTextObject->SetBounds(Rectangle(titleLeftMargin + transLeftMargin,
283 __pPopup->GetBounds().width - (titleLeftMargin + titleRightMargin + transLeftMargin + transRightMargin),
284 titleHeight - titleTopMargin));
285 __pTextObject->Compose();
287 // After TextObject::Compose(), we can get text-object's height.
288 __titleBounds.SetBounds(titleLeftMargin + transLeftMargin,
290 __pPopup->GetBounds().width - (titleLeftMargin + titleRightMargin + transLeftMargin + transRightMargin),
291 __pTextObject->GetTotalHeight());
293 __pTextObject->SetBounds(__titleBounds);
298 delete __pTextObject;
299 __pTextObject = null;
305 _PopupPresenter::OnDraw(void)
312 _PopupPresenter::GetTitleTextBounds(void) const
314 return __titleBounds;
318 _PopupPresenter::DrawSystemLabel(void)
320 result r = E_SUCCESS;
323 int transTopMargin = 0;
324 int transBottomMargin = 0;
326 GET_SHAPE_CONFIG(POPUP::TITLE_HEIGHT, __pPopup->GetOrientation(), titleHeight);
327 GET_SHAPE_CONFIG(POPUP::BG_IMAGE_TRANSPARENT_TOP_MARGIN, __pPopup->GetOrientation(), transTopMargin);
328 GET_SHAPE_CONFIG(POPUP::BG_IMAGE_TRANSPARENT_BOTTOM_MARGIN, __pPopup->GetOrientation(), transBottomMargin);
330 Rectangle systemBounds;
331 Rectangle clientBounds = __pPopup->GetPopupClientArea();
332 Rectangle bounds = __pPopup->GetBounds();
334 systemBounds.x = clientBounds.x + clientBounds.width;
336 if (__pPopup->HasTitle() == false)
340 systemBounds.y = clientBounds.y + POPUP_LABEL_GAP;
342 systemBounds.width = (bounds.width - systemBounds.x) - POPUP_LABEL_GAP / 2;
343 systemBounds.height = clientBounds.height -POPUP_LABEL_GAP * 2;
345 r = __pLabelCore->SetBounds(systemBounds);
346 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
348 __pLabelCore->SetBackgroundColor(__pPopup->GetColor());
350 __pLabelCore->Draw();
362 _PopupPresenter::Draw(void)
364 result r = E_SUCCESS;
366 int transTopMargin = 0;
367 int transBottomMargin = 0;
368 int transLeftMargin = 0;
369 int transRightMargin = 0;
371 int bgOutlineEffectTopMargin = 0;
372 int bgOutlineEffectBottomMargin = 0;
373 int bgOutlineEffectLeftMargin = 0;
374 int bgOutlineEffectRightMargin = 0;
376 GET_SHAPE_CONFIG(POPUP::BG_IMAGE_TRANSPARENT_TOP_MARGIN, __pPopup->GetOrientation(), transTopMargin);
377 GET_SHAPE_CONFIG(POPUP::BG_IMAGE_TRANSPARENT_BOTTOM_MARGIN, __pPopup->GetOrientation(), transBottomMargin);
378 GET_SHAPE_CONFIG(POPUP::BG_IMAGE_TRANSPARENT_LEFT_MARGIN, __pPopup->GetOrientation(), transLeftMargin);
379 GET_SHAPE_CONFIG(POPUP::BG_IMAGE_TRANSPARENT_RIGHT_MARGIN, __pPopup->GetOrientation(), transRightMargin);
381 GET_SHAPE_CONFIG(POPUP::BG_OUTLINE_EFFECT_TOP_MARGIN, __pPopup->GetOrientation(), bgOutlineEffectTopMargin);
382 GET_SHAPE_CONFIG(POPUP::BG_OUTLINE_EFFECT_BOTTOM_MARGIN, __pPopup->GetOrientation(), bgOutlineEffectBottomMargin);
383 GET_SHAPE_CONFIG(POPUP::BG_OUTLINE_EFFECT_LEFT_MARGIN, __pPopup->GetOrientation(), bgOutlineEffectLeftMargin);
384 GET_SHAPE_CONFIG(POPUP::BG_OUTLINE_EFFECT_RIGHT_MARGIN, __pPopup->GetOrientation(), bgOutlineEffectRightMargin);
387 Canvas* pCanvas = __pPopup->GetCanvasN();
388 SysTryReturnVoidResult(NID_UI_CTRL, pCanvas != null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
390 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
393 Canvas* pBackgroundCanvas = __pBackgroundVE->GetCanvasN();
394 SysTryCatch(NID_UI_CTRL, pBackgroundCanvas != null, , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
396 pBackgroundCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
397 pBackgroundCanvas->Clear();
400 if (__pPopup->GetBackgroundBitmap() != null)
402 Rectangle bounds(-transLeftMargin,
404 __pPopup->GetBounds().width + transLeftMargin + transRightMargin,
405 __pPopup->GetBounds().height + transTopMargin + transBottomMargin);
407 const Bitmap* pBackgroundBitmap = __pPopup->GetBackgroundBitmap();
408 if (pBackgroundBitmap->IsNinePatchedBitmap() == true)
410 pCanvas->DrawNinePatchedBitmap(bounds, *pBackgroundBitmap);
414 pCanvas->DrawBitmap(bounds, *pBackgroundBitmap);
419 if (__pPopup->HasTitle())
421 if (__pTextObject != null)
423 _pFont = __pPopup->GetFallbackFont();
425 SysTryCatch(NID_UI_CTRL, _pFont != null, , r, "[%s] Propagating.", GetErrorMessage(r));
427 __pTextObject->SetFont(_pFont, 0, __pTextObject->GetTextLength());
428 __pTextObject->SetBounds(__titleBounds);
429 __pTextObject->SetForegroundColor(__pPopup->GetTitleTextColor(), 0, __pTextObject->GetTextLength());
431 __pTextObject->Draw(*_CanvasImpl::GetInstance(*pCanvas));
437 if (__pPopup->GetOutlineBitmap() != null)
441 __pPopup->GetBounds().width + bgOutlineEffectLeftMargin + bgOutlineEffectRightMargin,
442 __pPopup->GetBounds().height + bgOutlineEffectTopMargin + bgOutlineEffectBottomMargin);
444 const Bitmap* pOutlineBitmap = __pPopup->GetOutlineBitmap();
446 if (pOutlineBitmap->IsNinePatchedBitmap() == true)
448 pBackgroundCanvas->DrawNinePatchedBitmap(bounds, *pOutlineBitmap);
452 pBackgroundCanvas->DrawBitmap(bounds, *pOutlineBitmap);
459 delete pBackgroundCanvas;
465 _PopupPresenter::OnActivated(void)
467 result r = E_SUCCESS;
469 #if !defined(MULTI_WINDOW)
470 VisualElement* pParent = __pPopupVE->GetParent();
472 _Window* pWindow = __pPopup->GetRootWindow();
473 _RootVisualElement* pParent = pWindow->GetRootVisualElement();
478 r = pParent->InsertChild(*__pBackgroundVE, __pPopupVE, false);
479 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
486 _PopupPresenter::DoModal(int& modalResult)
488 result r = E_SUCCESS;
490 r = __pPopup->Open();
491 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
497 modalResult = __pPopup->GetPopupReturnValue();
503 _PopupPresenter::ProcessEvent(void)
505 _ModalLoopManager::GetInstance()->BeginMainLoop();
507 int exitCode = _ModalLoopManager::GetInstance()->GetLastExitCode();
510 case _ModalLoopManager::MODAL_LOOP_EXIT_CODE_APP_TERMINATION:
511 case _ModalLoopManager::MODAL_LOOP_EXIT_CODE_CONTINUOUS_TERMINATION:
512 _ModalLoopManager::GetInstance()->EndMainLoop(exitCode, false);
520 _PopupPresenter::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
522 Point point = touchinfo.GetCurrentPosition();
528 _PopupPresenter::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
530 Point point = touchinfo.GetCurrentPosition();
536 }}} // Tizen::Ui::Controls