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_PopupImpl.cpp
20 * @brief This is the implementation file for the _PopupImpl class.
24 #include <FUiLayout.h>
25 #include <FBaseSysLog.h>
26 #include <FUiAccessibilityContainer.h>
27 #include <FUiAccessibilityElement.h>
28 #include "FUi_CoordinateSystemUtils.h"
29 #include "FUi_UiBuilder.h"
30 #include "FUi_DataBindingContextImpl.h"
31 #include "FUi_ResourceSizeInfo.h"
32 #include "FUi_ResourceManager.h"
33 #include "FUi_ControlImplManager.h"
34 #include "FUi_LayoutImpl.h"
36 #include "FUiCtrl_FrameImpl.h"
37 #include "FUiCtrl_PopupImpl.h"
38 #include "FUiCtrl_Popup.h"
39 #include "FUiCtrl_Form.h"
42 using namespace Tizen::Ui::Animations;
43 using namespace Tizen::Graphics;
44 using namespace Tizen::Ui;
47 namespace Tizen { namespace Ui { namespace Controls
52 _PopupImpl::PopupSizeInfo::GetDefaultMinimumSizeF(_ControlOrientation orientation) const
55 FloatDimension dimension(0, 0);
57 r = GET_DIMENSION_CONFIG(POPUP::MIN_SIZE, orientation, dimension);
58 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, dimension, r, "[%s] A system error occurred.", GetErrorMessage(r));
65 _PopupImpl::GetInstance(Popup& pPopup)
67 return static_cast <_PopupImpl*>(pPopup._pControlImpl);
71 _PopupImpl::GetInstance(const Popup& pPopup)
73 return static_cast <const _PopupImpl*>(pPopup._pControlImpl);
76 _PopupImpl::_PopupImpl(Popup* pPublic, _Popup* pCore, Layout* pPublicPortraitLayout, Layout* pPublicLandscapeLayout)
77 : _WindowImpl(pPublic, pCore, pPublicPortraitLayout, pPublicLandscapeLayout)
81 , __callBoundsChange(false)
82 , __prevPos(0.0f, 0.0f)
87 _PopupImpl::~_PopupImpl(void)
93 _PopupImpl::CreatePopupImplN(Popup* pControl, const Tizen::Graphics::FloatDimension& dim, Layout* pPublicPortraitLayout, Layout* pPublicLandscapeLayout)
97 r = GET_SIZE_INFO(Popup).CheckInitialSizeValidF(dim, _CONTROL_ORIENTATION_PORTRAIT);
98 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, E_INVALID_ARG, "[E_INVALID_ARG] The given size is not valid.");
100 _PopupImpl* pImpl = null;
101 _Popup* pCore = null;
103 pCore = _Popup::CreatePopupN();
104 SysTryReturn(NID_UI_CTRL, pCore, null, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
106 pImpl = new (std::nothrow) _PopupImpl(pControl, pCore, pPublicPortraitLayout, pPublicLandscapeLayout);
107 r = CheckConstruction(pCore, pImpl);
108 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
110 r = pImpl->InitializeBoundsPropertiesF(GET_SIZE_INFO(Popup), dim, pCore->GetOrientation());
111 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
118 delete pImpl; //This deletes pCore as well
124 _PopupImpl::Initialize(bool hasTitle, const Tizen::Graphics::FloatDimension& dim)
126 result r = E_SUCCESS;
130 FloatDimension minSize(0.0f, 0.0f);
132 r = GET_DIMENSION_CONFIG(POPUP::MIN_SIZE_WITH_TITLE, GetCore().GetOrientation(), minSize);
134 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] A system error occurred.", GetErrorMessage(r));
136 SysTryReturn(NID_UI_CTRL,
137 (minSize.width <= dim.width && minSize.height <= dim.height), E_INVALID_ARG,
138 E_INVALID_ARG, "[E_INVALID_ARG] The size is out of minimum size(%f, %f)",
139 minSize.width, minSize.height);
141 r = GetCore().SetMinimumSize(minSize);
143 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] SetMinimumSize is failed.", GetErrorMessage(r));
146 FloatRectangle bounds = GetCenterAlignedRect(dim.width, dim.height);
150 r = SetBounds(bounds);
151 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
153 return GetCore().Initialize(hasTitle, bounds);
157 _PopupImpl::GetPublicClassName(void) const
159 return "Tizen::Ui::Controls::Popup";
163 _PopupImpl::GetPublic(void) const
165 return static_cast <const Popup&>(_ControlImpl::GetPublic());
169 _PopupImpl::GetPublic(void)
171 return static_cast <Popup&>(_ControlImpl::GetPublic());
175 _PopupImpl::GetCore(void) const
177 return static_cast <const _Popup&>(_ControlImpl::GetCore());
181 _PopupImpl::GetCore(void)
183 return static_cast <_Popup&>(_ControlImpl::GetCore());
187 _PopupImpl::GetCenterAlignedRect(float width, float height) const
192 _ControlManager* pControlManager = _ControlManager::GetInstance();
194 FloatDimension screenRect = pControlManager->GetScreenSizeF();
196 if (GetCore().GetOrientation() == _CONTROL_ORIENTATION_LANDSCAPE)
198 float temp = screenRect.width;
199 screenRect.width = screenRect.height;
200 screenRect.height = temp;
203 x = (screenRect.width - width) / 2.0f;
204 y = (screenRect.height - height) / 2.0f;
206 return FloatRectangle(x, y, width, height);
210 _PopupImpl::GetClientAreaBounds(void) const
212 return _ControlImpl::GetClientBoundsF();
216 _PopupImpl::GetClientAreaCanvasN(void) const
218 return GetCore().GetClientAreaCanvasN();
222 _PopupImpl::TranslateFromClientAreaPosition(const FloatPoint& clientPosition) const
224 return GetCore().TranslateFromClientAreaPosition(clientPosition);
228 _PopupImpl::TranslateToClientAreaPosition(const FloatPoint& position) const
230 return GetCore().TranslateToClientAreaPosition(position);
234 _PopupImpl::DoModal(int& modalResult)
236 SysTryReturn(NID_UI_CTRL, GetVisibleState() != false, E_INVALID_STATE,
237 E_INVALID_STATE, "[E_INVALID_STATE] The Popup is not visible");
241 return GetCore().DoModal(modalResult);
245 _PopupImpl::EndModal(int modalResult)
247 SysTryReturn(NID_UI_CTRL, _isModal == true, E_INVALID_STATE, E_INVALID_STATE,
248 "[E_INVALID_STATE] The method is not supported because this popup isn't running as a modal window.");
250 return GetCore().EndModal(modalResult);
254 _PopupImpl::SetColor(const Color& color)
256 GetCore().SetColor(color);
262 _PopupImpl::GetColor(void) const
264 return GetCore().GetColor();
268 _PopupImpl::SetTitleText(const Tizen::Base::String& title)
270 return GetCore().SetTitleText(title);
274 _PopupImpl::GetTitleText(void) const
276 return GetCore().GetTitleText();
280 _PopupImpl::SetTitleTextColor(const Color& color)
282 GetCore().SetTitleTextColor(color);
288 _PopupImpl::GetTitleTextColor() const
290 return GetCore().GetTitleTextColor();
294 _PopupImpl::GetDataBindingContextN(void) const
296 return Tizen::Ui::_DataBindingContextImpl::GetDataBindingContextN(*this);
300 _PopupImpl::GetXmlBounds(Tizen::Graphics::FloatRectangle& rect)
302 Rectangle builderBounds;
303 _ControlOrientation controlOrientation = _CONTROL_ORIENTATION_PORTRAIT;
304 bool exist = GetBuilderBounds(controlOrientation, builderBounds);
310 _ControlImplManager* pControlImplManager = _ControlImplManager::GetInstance();
311 OrientationStatus orientation = pControlImplManager->GetFormOrientationStatus(this);
313 if (orientation == ORIENTATION_STATUS_LANDSCAPE
314 || orientation == ORIENTATION_STATUS_LANDSCAPE_REVERSE)
316 controlOrientation = _CONTROL_ORIENTATION_LANDSCAPE;
317 this->GetBuilderBounds(controlOrientation, builderBounds);
320 rect = _CoordinateSystemUtils::ConvertToFloat(builderBounds);
325 _PopupImpl::OnChangeLayout(_ControlOrientation orientation)
327 result r = E_SUCCESS;
328 FloatRectangle bounds;
329 if (!__callBoundsChange)
333 if(GetXmlBounds(bounds))
335 bounds = GetCenterAlignedRect(bounds.width, bounds.height);
339 bounds = GetCenterAlignedRect(GetBounds().width, GetBounds().height);
341 r = SetBounds(bounds);
342 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
346 if(GetXmlBounds(bounds))
348 r = SetBounds(bounds);
350 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
354 return GetCore().OnChangeLayout(orientation);
358 _PopupImpl::OnBoundsChanging(const FloatRectangle& bounds)
360 __prevPos = GetBoundsF().GetTopLeft();
362 return _ControlImpl::OnBoundsChanging(bounds);
366 _PopupImpl::OnBoundsChanged(void)
368 FloatRectangle rect = GetBoundsF();
371 if ((_centerAlign || (_FloatCompare(__prevPos.x, rect.x) && _FloatCompare(__prevPos.y, rect.y))) && __callBoundsChange == false)
373 rect = GetCenterAlignedRect(GetSizeF().width, GetSizeF().height);
377 __callBoundsChange = true;
383 result r = SetBounds(rect, true);
386 // Error propagation fall through
390 _ControlImpl::OnBoundsChanged();
392 _centerAlign = false;
397 : public _UiBuilderControlMaker
400 _PopupMaker(_UiBuilder* uibuilder)
401 : _UiBuilderControlMaker(uibuilder){};
402 virtual ~_PopupMaker(){};
404 static _UiBuilderControlMaker* GetInstance(_UiBuilder* uibuilder)
406 _PopupMaker* pPopupMaker = new (std::nothrow) _PopupMaker(uibuilder);
408 return static_cast<_UiBuilderControlMaker*>(pPopupMaker);
412 virtual Tizen::Ui::Control* Make(_UiBuilderControl* pControl)
414 bool hasTitle = false;
416 _UiBuilderControlLayout* pControlProperty = null;
417 Tizen::Base::String elementString;
419 Tizen::Graphics::Dimension dim;
420 Tizen::Graphics::Rectangle rect;
422 Popup* pPopup = dynamic_cast <Popup*>(GetContainer());
423 SysTryReturn(NID_UI_CTRL, pPopup != null, null, E_SYSTEM, "[E_SYSTEM] This instance is not constructed.");
425 SetUiBuilderRotateState(UIBUIDER_SCREEN_VERTICAL);
426 GetProperty(pControl, &pControlProperty);
428 if (pControlProperty == null)
433 if (pControl->GetElement("titleText", elementString))
442 //pPopup = new (std::nothrow) Popup();
443 rect = pControlProperty->GetRect();
445 dim.width = rect.width;
446 dim.height = rect.height;
448 // int sideMargin = 0;
449 // GET_SHAPE_CONFIG(POPUP::TITLE_TEXT_SIDE_MARGIN, _ControlManager::GetInstance()->GetOrientation(), sideMargin);
451 // // To consider client's area
452 // dim.width += sideMargin * 2;
454 // if (hasTitle == true)
456 // int titleHeight = 0;
457 // GET_SHAPE_CONFIG(POPUP::TITLE_HEIGHT, _ControlManager::GetInstance()->GetOrientation(), titleHeight);
459 // dim.height += titleHeight;
462 _UiBuilderLayoutType layoutType = UIBUILDER_LAYOUT_NONE;
463 __pLayoutMaker->GetLayoutType(pControlProperty, layoutType);
465 if (layoutType == UIBUILDER_LAYOUT_NONE)
467 r = pPopup->Construct(hasTitle, dim);
471 Layout* pPortraitLayout = null;
472 Layout* pLandscapeLayout = null;
473 result tempResult = E_SUCCESS;
475 tempResult = __pLayoutMaker->GetLayoutN(pControl, pPortraitLayout, pLandscapeLayout);
477 if (E_SUCCESS == tempResult)
479 r = pPopup->Construct(*pPortraitLayout, *pLandscapeLayout, hasTitle, dim);
486 _UiBuilderLayoutType layoutType = UIBUILDER_LAYOUT_NONE;
488 if (__pLayoutMaker->GetLayoutType(pControlProperty, layoutType) == false)
493 if ( layoutType == UIBUILDER_LAYOUT_GRID)
495 for (int i = 0; i < UIBUILDER_ATTRIBUTE_NUM; i++)
497 GridLayout* pGridLayout = null;
498 pControlProperty = pControl->GetAttribute(i);
500 if ( i == UIBUILDER_ATTRIBUTE_PORTRAIT)
502 pGridLayout = dynamic_cast<GridLayout*>(pPortraitLayout);
506 pGridLayout = dynamic_cast<GridLayout*>(pLandscapeLayout);
508 __pLayoutMaker->SetGridLayoutContainerProperty(pGridLayout, pControlProperty);
512 delete pPortraitLayout;
514 if (pPortraitLayout != pLandscapeLayout)
516 delete pLandscapeLayout;
518 // CONSTRUCT_WITH_LAYOUT_ARG2(pPopup, hasTitle, dim);
523 SysLog(NID_UI_CTRL, "Failed to create Popup.");
527 if (hasTitle == true)
529 pPopup->SetTitleText(elementString);
533 if (pControl->GetElement("color", elementString))
535 ConvertStringToColor(elementString, color);
536 pPopup->SetColor(color);
539 if (pControl->GetElement("titleTextColor", elementString))
541 ConvertStringToColor(elementString, color);
542 pPopup->SetTitleTextColor(color);
545 if (pControl->GetElement(L"accessibilityHint", elementString))
547 AccessibilityContainer* pContainer = pPopup->GetAccessibilityContainer();
550 AccessibilityElement* pElement = pContainer->GetElement(L"PopupTitleText");
553 pElement->SetHint(elementString);
558 //-------safety for Minimum size-------------------
559 // rect = (pControl->GetAttribute(UIBUILDER_ATTRIBUTE_PORTRAIT))->GetRect();
560 // if (rect.width < __BaseProperty(PROPERTY_POPUP_MIN_WIDTH))
562 // rect.width = __BaseProperty(PROPERTY_POPUP_MIN_WIDTH);
564 // if (rect.height < __BaseProperty(PROPERTY_POPUP_MIN_HEIGHT))
566 // rect.height = __BaseProperty(PROPERTY_POPUP_MIN_HEIGHT);
568 // (pControl->GetAttribute(UIBUILDER_ATTRIBUTE_PORTRAIT))->SetRect(rect.x,rect.y,rect.width,rect.height);
570 // rect = (pControl->GetAttribute(UIBUILDER_ATTRIBUTE_LANDSCAPE))->GetRect();
571 // if (rect.width < __BaseProperty(PROPERTY_POPUP_MIN_WIDTH))
573 // rect.width = __BaseProperty(PROPERTY_POPUP_MIN_WIDTH);
575 // if (rect.height < __BaseProperty(PROPERTY_POPUP_MIN_HEIGHT))
577 // rect.height = __BaseProperty(PROPERTY_POPUP_MIN_HEIGHT);
579 // (pControl->GetAttribute(UIBUILDER_ATTRIBUTE_LANDSCAPE))->SetRect(rect.x,rect.y,rect.width,rect.height);
580 //---------end safety code------------------------
589 _PopupRegister::_PopupRegister()
591 _UiBuilderControlTableManager* pUiBuilderControlTableManager = _UiBuilderControlTableManager::GetInstance();
592 pUiBuilderControlTableManager->RegisterControl(L"Popup", _PopupMaker::GetInstance);
595 _PopupRegister::~_PopupRegister()
597 _UiBuilderControlTableManager* pUiBuilderControlTableManager = _UiBuilderControlTableManager::GetInstance();
598 pUiBuilderControlTableManager->UnregisterControl(L"Popup");
600 static _PopupRegister PopupRegisterToUiBuilder;
602 }}} // Tizen::Ui::Controls