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_ProgressPopupImpl.cpp
20 * @brief This is the implementation file for the _ProgressPopupImpl class.
24 #include <FBaseSysLog.h>
25 #include <FUiCtrlIProgressPopupEventListener.h>
26 #include "FUi_ResourceManager.h"
27 #include "FUi_CoordinateSystemUtils.h"
28 #include "FUi_ControlImplManager.h"
30 #include "FUiCtrl_FrameImpl.h"
31 #include "FUiCtrl_Form.h"
32 #include "FUiCtrl_ProgressPopupImpl.h"
33 #include "FUiCtrl_Indicator.h"
36 using namespace Tizen::Ui::Animations;
37 using namespace Tizen::Graphics;
38 using namespace Tizen::Ui;
39 using namespace Tizen::Base;
42 namespace Tizen { namespace Ui { namespace Controls
47 _ProgressPopupImpl::GetInstance(ProgressPopup& pProgressPopup)
49 return static_cast <_ProgressPopupImpl*>(pProgressPopup._pControlImpl);
52 const _ProgressPopupImpl*
53 _ProgressPopupImpl::GetInstance(const ProgressPopup& pProgressPopup)
55 return static_cast <const _ProgressPopupImpl*>(pProgressPopup._pControlImpl);
58 _ProgressPopupImpl::_ProgressPopupImpl(ProgressPopup* pPublic, _ProgressPopup* pCore)
59 : _PopupImpl(pPublic, pCore)
60 , __pPublicProgressPopupEvent(null)
66 _ProgressPopupImpl::~_ProgressPopupImpl(void)
68 if (__pPublicProgressPopupEvent != null)
70 delete __pPublicProgressPopupEvent;
71 __pPublicProgressPopupEvent = null;
76 _ProgressPopupImpl::CreateProgressPopupImplN(ProgressPopup* pControl)
80 _ProgressPopupImpl* pImpl = null;
81 _ProgressPopup* pCore = null;
83 pCore = _ProgressPopup::CreateProgressPopupN();
85 SysTryReturn(NID_UI_CTRL, pCore, null, r, "[%s] Propagating.", GetErrorMessage(r));
87 pImpl = new (std::nothrow) _ProgressPopupImpl(pControl, pCore);
88 r = CheckConstruction(pCore, pImpl);
89 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
95 _ProgressPopupImpl::Initialize(bool cancelButton, bool transparent)
99 float animationWidth = 0.0f;
101 _ControlOrientation orientation;
103 orientation = GetCore().GetOrientation();
105 GET_SHAPE_CONFIG(POPUP::PROCESS_ANIMATION_WIDTH, orientation, animationWidth);
107 FloatRectangle animationRect;
108 animationRect = GetCenterAlignedRect(animationWidth, animationWidth);
110 r = GetCore().Initialize(cancelButton, transparent, animationRect);
111 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
115 r = SetBounds(animationRect);
116 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
120 float maxHeight = 0.0f;
121 float defaultWidth = 0.0f;
123 GET_SHAPE_CONFIG(MESSAGEBOX::MAX_HEIGHT, orientation, maxHeight);
124 GET_SHAPE_CONFIG(MESSAGEBOX::DEFAULT_WIDTH, orientation, defaultWidth);
126 float totalH = -1.0f;
127 totalH = GetCore().GetTotalHeight();
129 FloatRectangle bounds;
130 if (totalH > maxHeight)
132 bounds = GetCenterAlignedRect(defaultWidth, maxHeight);
136 bounds = GetCenterAlignedRect(defaultWidth, totalH);
139 r = SetBounds(bounds);
140 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
149 _ProgressPopupImpl::GetPublicClassName(void) const
151 return "Tizen::Ui::Controls::ProgressPopup";
155 _ProgressPopupImpl::GetPublic(void) const
157 return static_cast <const ProgressPopup&>(_ControlImpl::GetPublic());
161 _ProgressPopupImpl::GetPublic(void)
163 return static_cast <ProgressPopup&>(_ControlImpl::GetPublic());
166 const _ProgressPopup&
167 _ProgressPopupImpl::GetCore(void) const
169 return static_cast <const _ProgressPopup&>(_ControlImpl::GetCore());
173 _ProgressPopupImpl::GetCore(void)
175 return static_cast <_ProgressPopup&>(_ControlImpl::GetCore());
179 _ProgressPopupImpl::AddProgressPopupEventListener(IProgressPopupEventListener& listener)
181 result r = E_SUCCESS;
183 if (__pPublicProgressPopupEvent == null)
185 __pPublicProgressPopupEvent = _PublicProgressPopupEvent::CreateInstanceN(GetPublic());
187 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
190 r = __pPublicProgressPopupEvent->AddListener(listener);
191 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
193 return GetCore().AddProgressPopupEventListener(*this);
197 _ProgressPopupImpl::RemoveProgressPopupEventListener(IProgressPopupEventListener & listener)
199 result r = E_SUCCESS;
201 if (__pPublicProgressPopupEvent != null)
203 r = __pPublicProgressPopupEvent->RemoveListener(listener);
204 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
211 _ProgressPopupImpl::OnAttachedToMainTree(void)
213 _WindowImpl::OnAttachedToMainTree();
214 return GetCore().Open();
218 _ProgressPopupImpl::SetTitleText(const String& title)
220 result r = E_SUCCESS;
222 if (GetCore().IsTransparent())
227 r = GetCore().SetTitleText(title);
228 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, r, "[%s] Propagating.", GetErrorMessage(r));
230 float maxHeight = 0.0f;
231 float defaultWidth = 0.0f;
233 GET_SHAPE_CONFIG(MESSAGEBOX::MAX_HEIGHT, GetCore().GetOrientation(), maxHeight);
234 GET_SHAPE_CONFIG(MESSAGEBOX::DEFAULT_WIDTH, GetCore().GetOrientation(), defaultWidth);
236 float totalH = -1.0f;
237 totalH = GetCore().GetTotalHeight();
239 FloatRectangle bounds;
240 if (totalH > maxHeight)
242 bounds = GetCenterAlignedRect(defaultWidth, maxHeight);
246 bounds = GetCenterAlignedRect(defaultWidth, totalH);
251 r = SetBounds(bounds);
252 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
256 r = GetCore().UpdateBounds();
257 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
264 _ProgressPopupImpl::SetText(const String& text)
266 result r = E_SUCCESS;
269 if (GetCore().IsTransparent())
274 maxLength = GetMaxTextLength();
275 SysTryReturn(NID_UI_CTRL, text.GetLength() <= maxLength, E_MAX_EXCEEDED, E_MAX_EXCEEDED,
276 "[E_MAX_EXCEEDED] Text length is too long to create ProgressPopup.");
278 r = GetCore().SetText(text);
279 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
281 float maxHeight = 0.0f;
282 float defaultWidth = 0.0f;
284 GET_SHAPE_CONFIG(MESSAGEBOX::MAX_HEIGHT, GetCore().GetOrientation(), maxHeight);
285 GET_SHAPE_CONFIG(MESSAGEBOX::DEFAULT_WIDTH, GetCore().GetOrientation(), defaultWidth);
287 float totalH = -1.0f;
288 totalH = GetCore().GetTotalHeight();
290 FloatRectangle bounds;
292 if (totalH > maxHeight)
294 bounds = GetCenterAlignedRect(defaultWidth, maxHeight);
298 bounds = GetCenterAlignedRect(defaultWidth, totalH);
303 r = SetBounds(bounds);
304 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
308 r = GetCore().UpdateBounds();
309 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
317 _ProgressPopupImpl::GetText(void) const
319 return GetCore().GetText();
323 _ProgressPopupImpl::SetTextColor(const Color& color)
325 GetCore().SetTextColor(color);
331 _ProgressPopupImpl::GetTextColor() const
333 return GetCore().GetTextColor();
337 _ProgressPopupImpl::GetMaxTextLength(void) const
340 GET_FIXED_VALUE_CONFIG(MESSAGEBOX::TEXT_MAX_LENGTH, GetCore().GetOrientation(), maxLength);
346 _ProgressPopupImpl::GetCenterAlignedRect(float width, float height) const
351 FloatDimension screenRect = _ControlManager::GetInstance()->GetScreenSizeF();
353 if (GetCore().GetOrientation() == _CONTROL_ORIENTATION_LANDSCAPE)
355 float temp = screenRect.width;
356 screenRect.width = screenRect.height;
357 screenRect.height = temp;
360 x = (screenRect.width - width) / 2.0f;
361 y = (screenRect.height - height) / 2.0f;
363 return FloatRectangle(x, y, width, height);
367 _ProgressPopupImpl::OnProgressPopupCanceled(void)
369 if (__pPublicProgressPopupEvent != null)
371 Tizen::Base::Runtime::IEventArg* pEventArg = _PublicProgressPopupEvent::CreateProgressPopupEventArgN();
372 result r = GetLastResult();
373 SysTryReturnVoidResult(NID_UI_CTRL, pEventArg != null, r, "[%s] Propagating.", GetErrorMessage(r));
375 __pPublicProgressPopupEvent->Fire(*pEventArg);
380 _ProgressPopupImpl::OnChangeLayout(_ControlOrientation orientation)
382 result r = E_SUCCESS;
383 FloatRectangle bounds;
385 bounds = GetBoundsF();
387 if(GetCore().IsTransparent() == false)
389 GetCore().OnChangeLayout(orientation);
392 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
394 float maxHeight = 0.0f;
395 float defaultWidth = 0.0f;
397 GET_SHAPE_CONFIG(MESSAGEBOX::MAX_HEIGHT, orientation, maxHeight);
398 GET_SHAPE_CONFIG(MESSAGEBOX::DEFAULT_WIDTH, orientation, defaultWidth);
400 bounds.width = defaultWidth;
402 float totalH = -1.0f;
403 totalH = GetCore().GetTotalHeight();
405 if (totalH > maxHeight)
407 bounds.height = maxHeight;
411 bounds.height = totalH;
419 r = SetBounds(GetCenterAlignedRect(bounds.width, bounds.height));
423 r = SetBounds(bounds);
428 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
435 _ProgressPopupImpl::OnBoundsChanged(void)
438 FloatRectangle pRect = GetBoundsF();
442 rect = GetCenterAlignedRect(pRect.width, pRect.height);
444 if (!_FloatCompare(rect.x, pRect.x) || !_FloatCompare(rect.y, pRect.y))
446 _centerAlign = false;
450 _ControlImpl::OnBoundsChanged();
453 }}} // Tizen::Ui::Controls