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_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_ControlImplManager.h"
28 #include "FUiCtrl_FrameImpl.h"
29 #include "FUiCtrl_Form.h"
30 #include "FUiCtrl_ProgressPopupImpl.h"
33 using namespace Tizen::Ui::Animations;
34 using namespace Tizen::Graphics;
35 using namespace Tizen::Ui;
36 using namespace Tizen::Base;
39 namespace Tizen { namespace Ui { namespace Controls
44 _ProgressPopupImpl::GetInstance(ProgressPopup& pProgressPopup)
46 return static_cast <_ProgressPopupImpl*>(pProgressPopup._pControlImpl);
49 const _ProgressPopupImpl*
50 _ProgressPopupImpl::GetInstance(const ProgressPopup& pProgressPopup)
52 return static_cast <const _ProgressPopupImpl*>(pProgressPopup._pControlImpl);
55 _ProgressPopupImpl::_ProgressPopupImpl(ProgressPopup* pPublic, _ProgressPopup* pCore)
56 : _PopupImpl(pPublic, pCore)
57 , __pPublicProgressPopupEvent(null)
62 _ProgressPopupImpl::~_ProgressPopupImpl(void)
64 if (__pPublicProgressPopupEvent != null)
66 delete __pPublicProgressPopupEvent;
67 __pPublicProgressPopupEvent = null;
72 _ProgressPopupImpl::CreateProgressPopupImplN(ProgressPopup* pControl)
76 _ProgressPopupImpl* pImpl = null;
77 _ProgressPopup* pCore = null;
79 pCore = _ProgressPopup::CreateProgressPopupN();
81 SysTryReturn(NID_UI_CTRL, pCore, null, r, "[%s] Propagating.", GetErrorMessage(r));
83 pImpl = new (std::nothrow) _ProgressPopupImpl(pControl, pCore);
84 r = CheckConstruction(pCore, pImpl);
85 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
91 _ProgressPopupImpl::Initialize(bool cancelButton, bool translucent)
95 int animationWidth = 0;
96 GET_SHAPE_CONFIG(POPUP::PROCESS_ANIMATION_WIDTH, GetCore().GetOrientation(), animationWidth);
98 Rectangle animationRect;
99 animationRect = GetCenterAlignedRect(animationWidth, animationWidth);
101 r = GetCore().Initialize(cancelButton, translucent, animationRect);
102 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
104 if (!cancelButton || translucent)
106 r = SetBounds(animationRect);
107 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
112 int defaultWidth = 0;
114 GET_SHAPE_CONFIG(MESSAGEBOX::MAX_HEIGHT, GetCore().GetOrientation(), maxHeight);
115 GET_SHAPE_CONFIG(MESSAGEBOX::DEFAULT_WIDTH, GetCore().GetOrientation(), defaultWidth);
118 totalH = GetCore().GetTotalHeight();
121 if (totalH > maxHeight)
123 bounds = GetCenterAlignedRect(defaultWidth, maxHeight);
127 bounds = GetCenterAlignedRect(defaultWidth, totalH);
130 r = SetBounds(bounds);
131 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
141 _ProgressPopupImpl::GetPublicClassName(void) const
143 return "Tizen::Ui::Controls::ProgressPopup";
147 _ProgressPopupImpl::GetPublic(void) const
149 return static_cast <const ProgressPopup&>(_ControlImpl::GetPublic());
153 _ProgressPopupImpl::GetPublic(void)
155 return static_cast <ProgressPopup&>(_ControlImpl::GetPublic());
158 const _ProgressPopup&
159 _ProgressPopupImpl::GetCore(void) const
161 return static_cast <const _ProgressPopup&>(_ControlImpl::GetCore());
165 _ProgressPopupImpl::GetCore(void)
167 return static_cast <_ProgressPopup&>(_ControlImpl::GetCore());
171 _ProgressPopupImpl::AddProgressPopupEventListener(IProgressPopupEventListener& listener)
173 result r = E_SUCCESS;
175 if (__pPublicProgressPopupEvent == null)
177 __pPublicProgressPopupEvent = _PublicProgressPopupEvent::CreateInstanceN(GetPublic());
179 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
182 r = __pPublicProgressPopupEvent->AddListener(listener);
183 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
185 return GetCore().AddProgressPopupEventListener(*this);
189 _ProgressPopupImpl::RemoveProgressPopupEventListener(IProgressPopupEventListener & listener)
191 result r = E_SUCCESS;
193 if (__pPublicProgressPopupEvent != null)
195 r = __pPublicProgressPopupEvent->RemoveListener(listener);
196 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
203 _ProgressPopupImpl::OnAttachedToMainTree(void)
205 if (GetOwner() == null)
207 _FrameImpl* pFrameImpl = static_cast <_FrameImpl*>(_ControlImplManager::GetInstance()->GetCurrentFrame());
208 SysTryReturn(NID_UI_CTRL, pFrameImpl != null, E_SYSTEM,
209 E_SYSTEM, "[E_SYSTEM] This instance is not constructed.");
211 _Form* pForm = pFrameImpl->GetCore().GetCurrentForm();
213 _Window* pWindow = static_cast <_Window*>(&GetCore());
214 SysTryReturn(NID_UI_CTRL, pWindow != null, E_SYSTEM,
215 E_SYSTEM, "[E_SYSTEM] This instance is not constructed.");
219 pWindow->SetOwner(pForm);
223 pWindow->SetOwner(&pFrameImpl->GetCore());
227 _WindowImpl::OnAttachedToMainTree();
228 return GetCore().Open();
232 _ProgressPopupImpl::SetTitleText(const String& title)
234 result r = E_SUCCESS;
236 r = GetCore().SetTitleText(title);
237 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
240 int defaultWidth = 0;
242 GET_SHAPE_CONFIG(MESSAGEBOX::MAX_HEIGHT, GetCore().GetOrientation(), maxHeight);
243 GET_SHAPE_CONFIG(MESSAGEBOX::DEFAULT_WIDTH, GetCore().GetOrientation(), defaultWidth);
246 totalH = GetCore().GetTotalHeight();
249 if (totalH > maxHeight)
251 bounds = GetCenterAlignedRect(defaultWidth, maxHeight);
255 bounds = GetCenterAlignedRect(defaultWidth, totalH);
261 r = SetBounds(bounds);
262 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
267 r = GetCore().UpdateBounds();
268 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
275 _ProgressPopupImpl::SetText(const String& text)
277 result r = E_SUCCESS;
280 maxLength = GetMaxTextLength();
281 SysTryReturn(NID_UI_CTRL, text.GetLength() <= maxLength, E_MAX_EXCEEDED, E_MAX_EXCEEDED,
282 "[E_MAX_EXCEEDED] Text length is too long to create ProgressPopup.");
284 r = GetCore().SetText(text);
285 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
288 int defaultWidth = 0;
290 GET_SHAPE_CONFIG(MESSAGEBOX::MAX_HEIGHT, GetCore().GetOrientation(), maxHeight);
291 GET_SHAPE_CONFIG(MESSAGEBOX::DEFAULT_WIDTH, GetCore().GetOrientation(), defaultWidth);
294 totalH = GetCore().GetTotalHeight();
297 if (totalH > maxHeight)
299 bounds = GetCenterAlignedRect(defaultWidth, maxHeight);
303 bounds = GetCenterAlignedRect(defaultWidth, totalH);
309 r = SetBounds(bounds);
310 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
315 r = GetCore().UpdateBounds();
316 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
324 _ProgressPopupImpl::GetText(void) const
326 return GetCore().GetText();
330 _ProgressPopupImpl::SetTextColor(const Color& color)
332 GetCore().SetTextColor(color);
338 _ProgressPopupImpl::GetTextColor() const
340 return GetCore().GetTextColor();
344 _ProgressPopupImpl::GetMaxTextLength(void) const
347 GET_FIXED_VALUE_CONFIG(MESSAGEBOX::TEXT_MAX_LENGTH, GetCore().GetOrientation(), maxLength);
353 _ProgressPopupImpl::GetCenterAlignedRect(int width, int height) const
358 Dimension screenRect = _ControlManager::GetInstance()->GetScreenSize();
360 if (GetCore().GetOrientation() == _CONTROL_ORIENTATION_LANDSCAPE)
362 int temp = screenRect.width;
363 screenRect.width = screenRect.height;
364 screenRect.height = temp;
367 x = (screenRect.width - width) / 2;
368 y = (screenRect.height - height) / 2;
370 return Rectangle(x, y, width, height);
374 _ProgressPopupImpl::OnProgressPopupCanceled(void)
376 if (__pPublicProgressPopupEvent != null)
378 Tizen::Base::Runtime::IEventArg* pEventArg = _PublicProgressPopupEvent::CreateProgressPopupEventArgN();
379 result r = GetLastResult();
380 SysTryReturnVoidResult(NID_UI_CTRL, pEventArg != null, r, "[%s] Propagating.", GetErrorMessage(r));
382 __pPublicProgressPopupEvent->Fire(*pEventArg);
387 _ProgressPopupImpl::OnChangeLayout(_ControlOrientation orientation)
389 result r = E_SUCCESS;
390 Dimension portraitSize;
391 Dimension landscapeSize;
393 if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
395 portraitSize = Dimension(GetBounds().width, GetBounds().height);
396 landscapeSize = Dimension(portraitSize.height, portraitSize.width);
400 portraitSize = Dimension(GetBounds().height, GetBounds().width);
401 landscapeSize = Dimension(portraitSize.height, portraitSize.width);
404 if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
409 r = SetBounds(GetCenterAlignedRect(portraitSize.width, portraitSize.height));
410 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
420 r = SetBounds(GetCenterAlignedRect(landscapeSize.width, landscapeSize.height));
421 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
427 return GetCore().OnChangeLayout(orientation);
431 }}} // Tizen::Ui::Controls