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_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"
40 #include "FUiCtrl_Indicator.h"
43 using namespace Tizen::Ui::Animations;
44 using namespace Tizen::Graphics;
45 using namespace Tizen::Ui;
48 namespace Tizen { namespace Ui { namespace Controls
53 _PopupImpl::PopupSizeInfo::GetDefaultMinimumSizeF(_ControlOrientation orientation) const
56 FloatDimension dimension(0, 0);
58 r = GET_DIMENSION_CONFIG(POPUP::MIN_SIZE, orientation, dimension);
59 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, dimension, r, "[%s] A system error occurred.", GetErrorMessage(r));
66 _PopupImpl::GetInstance(Popup& pPopup)
68 return static_cast <_PopupImpl*>(pPopup._pControlImpl);
72 _PopupImpl::GetInstance(const Popup& pPopup)
74 return static_cast <const _PopupImpl*>(pPopup._pControlImpl);
77 _PopupImpl::_PopupImpl(Popup* pPublic, _Popup* pCore, Layout* pPublicPortraitLayout, Layout* pPublicLandscapeLayout)
78 : _WindowImpl(pPublic, pCore, pPublicPortraitLayout, pPublicLandscapeLayout)
82 , __callBoundsChange(false)
83 , __prevPos(0.0f, 0.0f)
84 , __boundsChangedInternally(false)
85 , __boundsChangedExternally(false)
90 _PopupImpl::~_PopupImpl(void)
96 _PopupImpl::CreatePopupImplN(Popup* pControl, const Tizen::Graphics::FloatDimension& dim, Layout* pPublicPortraitLayout, Layout* pPublicLandscapeLayout)
100 r = GET_SIZE_INFO(Popup).CheckInitialSizeValidF(dim, _CONTROL_ORIENTATION_PORTRAIT);
101 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, E_INVALID_ARG, "[E_INVALID_ARG] The given size is not valid.");
103 _PopupImpl* pImpl = null;
104 _Popup* pCore = null;
106 pCore = _Popup::CreatePopupN();
107 SysTryReturn(NID_UI_CTRL, pCore, null, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
109 pImpl = new (std::nothrow) _PopupImpl(pControl, pCore, pPublicPortraitLayout, pPublicLandscapeLayout);
110 r = CheckConstruction(pCore, pImpl);
111 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
113 r = pImpl->InitializeBoundsPropertiesF(GET_SIZE_INFO(Popup), dim, pCore->GetOrientation());
114 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
121 delete pImpl; //This deletes pCore as well
127 _PopupImpl::Initialize(bool hasTitle, const Tizen::Graphics::FloatDimension& dim)
129 result r = E_SUCCESS;
131 FloatRectangle bounds = GetCenterAlignedRect(dim.width, dim.height);
134 __boundsChangedInternally = true;
135 r = SetBounds(bounds);
136 __boundsChangedInternally = false;
137 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
138 return GetCore().Initialize(hasTitle, bounds);
142 _PopupImpl::GetPublicClassName(void) const
144 return "Tizen::Ui::Controls::Popup";
148 _PopupImpl::GetPublic(void) const
150 return static_cast <const Popup&>(_ControlImpl::GetPublic());
154 _PopupImpl::GetPublic(void)
156 return static_cast <Popup&>(_ControlImpl::GetPublic());
160 _PopupImpl::GetCore(void) const
162 return static_cast <const _Popup&>(_ControlImpl::GetCore());
166 _PopupImpl::GetCore(void)
168 return static_cast <_Popup&>(_ControlImpl::GetCore());
172 _PopupImpl::GetCenterAlignedRect(float width, float height) const
177 _ControlManager* pControlManager = _ControlManager::GetInstance();
179 FloatDimension screenRect = pControlManager->GetScreenSizeF();
181 if (GetCore().GetOrientation() == _CONTROL_ORIENTATION_LANDSCAPE)
183 float temp = screenRect.width;
184 screenRect.width = screenRect.height;
185 screenRect.height = temp;
188 x = (screenRect.width - width) / 2.0f;
189 y = (screenRect.height - height) / 2.0f;
191 return FloatRectangle(x, y, width, height);
195 _PopupImpl::GetClientAreaBounds(void) const
197 return CoordinateSystem::AlignToDevice(_ControlImpl::GetClientBoundsF());
201 _PopupImpl::GetClientAreaCanvasN(void) const
203 return GetCore().GetClientAreaCanvasN();
207 _PopupImpl::TranslateFromClientAreaPosition(const FloatPoint& clientPosition) const
209 return GetCore().TranslateFromClientAreaPosition(clientPosition);
213 _PopupImpl::TranslateToClientAreaPosition(const FloatPoint& position) const
215 return GetCore().TranslateToClientAreaPosition(position);
219 _PopupImpl::DoModal(int& modalResult)
221 SysTryReturn(NID_UI_CTRL, GetVisibleState() != false, E_INVALID_STATE,
222 E_INVALID_STATE, "[E_INVALID_STATE] The Popup is not visible");
226 return GetCore().DoModal(modalResult);
230 _PopupImpl::EndModal(int modalResult)
232 SysTryReturn(NID_UI_CTRL, _isModal == true, E_INVALID_STATE, E_INVALID_STATE,
233 "[E_INVALID_STATE] The method is not supported because this popup isn't running as a modal window.");
235 return GetCore().EndModal(modalResult);
239 _PopupImpl::SetColor(const Color& color)
241 GetCore().SetColor(color);
247 _PopupImpl::GetColor(void) const
249 return GetCore().GetColor();
253 _PopupImpl::SetTitleText(const Tizen::Base::String& title)
255 result r = GetCore().SetTitleText(title);
256 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, r, "[%s] Propagating.", GetErrorMessage(r));
262 _PopupImpl::GetTitleText(void) const
264 return GetCore().GetTitleText();
268 _PopupImpl::SetTitleTextColor(const Color& color)
270 GetCore().SetTitleTextColor(color);
276 _PopupImpl::GetTitleTextColor() const
278 return GetCore().GetTitleTextColor();
282 _PopupImpl::GetDataBindingContextN(void) const
284 return Tizen::Ui::_DataBindingContextImpl::GetDataBindingContextN(*this);
288 _PopupImpl::GetXmlBounds(Tizen::Graphics::FloatRectangle& rect)
290 Rectangle builderBounds;
291 _ControlOrientation controlOrientation = _CONTROL_ORIENTATION_PORTRAIT;
292 bool exist = GetBuilderBounds(controlOrientation, builderBounds);
298 controlOrientation = GetCore().GetOrientation();
300 if (controlOrientation == _CONTROL_ORIENTATION_LANDSCAPE)
302 exist = GetBuilderBounds(controlOrientation, builderBounds);
304 rect = _CoordinateSystemUtils::ConvertToFloat(builderBounds);
309 _PopupImpl::OnChangeLayout(_ControlOrientation orientation)
311 result r = E_SUCCESS;
312 FloatRectangle bounds;
313 if (!__callBoundsChange)
317 if (__boundsChangedExternally)
319 bounds = GetCenterAlignedRect(GetBounds().width, GetBounds().height);
320 __boundsChangedInternally = true;
321 r = SetBounds(bounds);
322 __boundsChangedInternally = false;
327 if(GetXmlBounds(bounds))
329 bounds = GetCenterAlignedRect(bounds.width, bounds.height);
333 bounds = GetCenterAlignedRect(GetBounds().width, GetBounds().height);
335 __boundsChangedInternally = true;
336 r = SetBounds(bounds);
337 __boundsChangedInternally = false;
340 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
344 if (!__boundsChangedExternally)
346 if(GetXmlBounds(bounds))
348 __boundsChangedInternally = true;
349 r = SetBounds(bounds);
350 __boundsChangedInternally = false;
354 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
360 pLayout = GetPublicLayoutN();
364 Tizen::Ui::_SharedPtr<Tizen::Ui::_LayoutImpl> pLayoutImpl = _LayoutImpl::GetLayoutImpl(pLayout);
366 if (!pLayoutImpl.IsNull())
368 r = GetCore().SetCurrentLayout(pLayoutImpl->GetCore());
369 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] Failed to set up the current layout");
373 return GetCore().OnChangeLayout(orientation);
377 _PopupImpl::OnBoundsChanging(const FloatRectangle& bounds)
379 __prevPos = GetBoundsF().GetTopLeft();
381 return _ControlImpl::OnBoundsChanging(bounds);
385 _PopupImpl::OnBoundsChanged(void)
387 if (!__boundsChangedInternally && __init)
389 __boundsChangedExternally = true;
392 FloatRectangle rect = GetBoundsF();
395 if ((_centerAlign || (_FloatCompare(__prevPos.x, rect.x) && _FloatCompare(__prevPos.y, rect.y))) && __callBoundsChange == false)
397 rect = GetCenterAlignedRect(GetSizeF().width, GetSizeF().height);
401 __callBoundsChange = true;
406 __boundsChangedInternally = true;
407 result r = SetBounds(rect, true);
408 __boundsChangedInternally = false;
411 // Error propagation fall through
415 _ControlImpl::OnBoundsChanged();
417 _centerAlign = false;
422 : public _UiBuilderControlMaker
425 _PopupMaker(_UiBuilder* uibuilder)
426 : _UiBuilderControlMaker(uibuilder){};
427 virtual ~_PopupMaker(){};
429 static _UiBuilderControlMaker* GetInstance(_UiBuilder* uibuilder)
431 _PopupMaker* pPopupMaker = new (std::nothrow) _PopupMaker(uibuilder);
433 return static_cast<_UiBuilderControlMaker*>(pPopupMaker);
437 virtual Tizen::Ui::Control* Make(_UiBuilderControl* pControl)
439 bool hasTitle = false;
441 _UiBuilderControlLayout* pControlProperty = null;
442 Tizen::Base::String elementString;
444 Tizen::Graphics::FloatDimension dim;
445 Tizen::Graphics::FloatRectangle rect;
447 Popup* pPopup = dynamic_cast <Popup*>(GetContainer());
448 SysTryReturn(NID_UI_CTRL, pPopup != null, null, E_SYSTEM, "[E_SYSTEM] This instance is not constructed.");
450 SetUiBuilderRotateState(UIBUIDER_SCREEN_VERTICAL);
451 GetProperty(pControl, &pControlProperty);
453 if (pControlProperty == null)
458 if (pControl->GetElement("titleText", elementString))
467 //pPopup = new (std::nothrow) Popup();
468 rect = pControlProperty->GetRectF();
470 dim.width = rect.width;
471 dim.height = rect.height;
473 _UiBuilderLayoutType layoutType = UIBUILDER_LAYOUT_NONE;
474 __pLayoutMaker->GetLayoutType(pControlProperty, layoutType);
476 if (layoutType == UIBUILDER_LAYOUT_NONE)
478 r = pPopup->Construct(hasTitle, dim);
482 Layout* pPortraitLayout = null;
483 Layout* pLandscapeLayout = null;
484 result tempResult = E_SUCCESS;
486 tempResult = __pLayoutMaker->GetLayoutN(pControl, pPortraitLayout, pLandscapeLayout);
488 if (E_SUCCESS == tempResult)
490 r = pPopup->Construct(*pPortraitLayout, *pLandscapeLayout, hasTitle, dim);
497 _UiBuilderLayoutType layoutType = UIBUILDER_LAYOUT_NONE;
499 if (__pLayoutMaker->GetLayoutType(pControlProperty, layoutType) == false)
504 if ( layoutType == UIBUILDER_LAYOUT_GRID)
506 for (int i = 0; i < UIBUILDER_ATTRIBUTE_NUM; i++)
508 GridLayout* pGridLayout = null;
509 pControlProperty = pControl->GetAttribute(i);
511 if ( i == UIBUILDER_ATTRIBUTE_PORTRAIT)
513 pGridLayout = dynamic_cast<GridLayout*>(pPortraitLayout);
517 pGridLayout = dynamic_cast<GridLayout*>(pLandscapeLayout);
519 __pLayoutMaker->SetGridLayoutContainerProperty(pGridLayout, pControlProperty);
523 delete pPortraitLayout;
525 if (pPortraitLayout != pLandscapeLayout)
527 delete pLandscapeLayout;
529 // CONSTRUCT_WITH_LAYOUT_ARG2(pPopup, hasTitle, dim);
534 SysLog(NID_UI_CTRL, "Failed to create Popup.");
538 if (hasTitle == true)
540 pPopup->SetTitleText(elementString);
544 if (pControl->GetElement("color", elementString))
546 ConvertStringToColor(elementString, color);
547 pPopup->SetColor(color);
550 if (pControl->GetElement("titleTextColor", elementString))
552 ConvertStringToColor(elementString, color);
553 pPopup->SetTitleTextColor(color);
556 if (pControl->GetElement(L"accessibilityHint", elementString))
558 AccessibilityContainer* pContainer = pPopup->GetAccessibilityContainer();
561 AccessibilityElement* pElement = pContainer->GetElement(L"PopupTitleText");
564 pElement->SetHint(elementString);
576 _PopupRegister::_PopupRegister()
578 _UiBuilderControlTableManager* pUiBuilderControlTableManager = _UiBuilderControlTableManager::GetInstance();
579 pUiBuilderControlTableManager->RegisterControl(L"Popup", _PopupMaker::GetInstance);
582 _PopupRegister::~_PopupRegister()
584 _UiBuilderControlTableManager* pUiBuilderControlTableManager = _UiBuilderControlTableManager::GetInstance();
585 pUiBuilderControlTableManager->UnregisterControl(L"Popup");
587 static _PopupRegister PopupRegisterToUiBuilder;
589 }}} // Tizen::Ui::Controls