Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / controls / FUiCtrl_ProgressPopupImpl.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://floralicense.org/license/
10 //
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.
16 //
17
18 /**
19  * @file                FUiCtrl_ProgressPopupImpl.cpp
20  * @brief       This is the implementation file for the _ProgressPopupImpl class.
21  */
22
23
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"
31
32
33 using namespace Tizen::Ui::Animations;
34 using namespace Tizen::Graphics;
35 using namespace Tizen::Ui;
36 using namespace Tizen::Base;
37
38
39 namespace Tizen { namespace Ui { namespace Controls
40 {
41
42
43 _ProgressPopupImpl*
44 _ProgressPopupImpl::GetInstance(ProgressPopup& pProgressPopup)
45 {
46         return static_cast <_ProgressPopupImpl*>(pProgressPopup._pControlImpl);
47 }
48
49 const _ProgressPopupImpl*
50 _ProgressPopupImpl::GetInstance(const ProgressPopup& pProgressPopup)
51 {
52         return static_cast <const _ProgressPopupImpl*>(pProgressPopup._pControlImpl);
53 }
54
55 _ProgressPopupImpl::_ProgressPopupImpl(ProgressPopup* pPublic, _ProgressPopup* pCore)
56         : _PopupImpl(pPublic, pCore)
57         , __pPublicProgressPopupEvent(null)
58 {
59         //empty statement
60 }
61
62 _ProgressPopupImpl::~_ProgressPopupImpl(void)
63 {
64         if (__pPublicProgressPopupEvent != null)
65         {
66                 delete __pPublicProgressPopupEvent;
67                 __pPublicProgressPopupEvent = null;
68         }
69 }
70
71 _ProgressPopupImpl*
72 _ProgressPopupImpl::CreateProgressPopupImplN(ProgressPopup* pControl)
73 {
74         result r = E_SUCCESS;
75
76         _ProgressPopupImpl* pImpl = null;
77         _ProgressPopup* pCore = null;
78
79         pCore = _ProgressPopup::CreateProgressPopupN();
80         r = GetLastResult();
81         SysTryReturn(NID_UI_CTRL, pCore, null, r, "[%s] Propagating.", GetErrorMessage(r));
82
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));
86
87         return pImpl;
88 }
89
90 result
91 _ProgressPopupImpl::Initialize(bool cancelButton, bool translucent)
92 {
93         result r = E_SUCCESS;
94
95         int animationWidth = 0;
96         GET_SHAPE_CONFIG(POPUP::PROCESS_ANIMATION_WIDTH, GetCore().GetOrientation(), animationWidth);
97
98         Rectangle animationRect;
99         animationRect = GetCenterAlignedRect(animationWidth, animationWidth);
100
101         r = GetCore().Initialize(cancelButton, translucent, animationRect);
102         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
103
104         if (!cancelButton || translucent)
105         {
106                 r = SetBounds(animationRect);
107                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
108         }
109         else
110         {
111                 int maxHeight = 0;
112                 int defaultWidth = 0;
113
114                 GET_SHAPE_CONFIG(MESSAGEBOX::MAX_HEIGHT, GetCore().GetOrientation(), maxHeight);
115                 GET_SHAPE_CONFIG(MESSAGEBOX::DEFAULT_WIDTH, GetCore().GetOrientation(), defaultWidth);
116
117                 int totalH = -1;
118                 totalH = GetCore().GetTotalHeight();
119
120                 Rectangle bounds;
121                 if (totalH > maxHeight)
122                 {
123                         bounds = GetCenterAlignedRect(defaultWidth, maxHeight);
124                 }
125                 else
126                 {
127                         bounds = GetCenterAlignedRect(defaultWidth, totalH);
128                 }
129
130                 r = SetBounds(bounds);
131                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
132         }
133
134         SetMovable(false);
135         SetResizable(false);
136
137         return r;
138 }
139
140 const char*
141 _ProgressPopupImpl::GetPublicClassName(void) const
142 {
143         return "Tizen::Ui::Controls::ProgressPopup";
144 }
145
146 const ProgressPopup&
147 _ProgressPopupImpl::GetPublic(void) const
148 {
149         return static_cast <const ProgressPopup&>(_ControlImpl::GetPublic());
150 }
151
152 ProgressPopup&
153 _ProgressPopupImpl::GetPublic(void)
154 {
155         return static_cast <ProgressPopup&>(_ControlImpl::GetPublic());
156 }
157
158 const _ProgressPopup&
159 _ProgressPopupImpl::GetCore(void) const
160 {
161         return static_cast <const _ProgressPopup&>(_ControlImpl::GetCore());
162 }
163
164 _ProgressPopup&
165 _ProgressPopupImpl::GetCore(void)
166 {
167         return static_cast <_ProgressPopup&>(_ControlImpl::GetCore());
168 }
169
170 result
171 _ProgressPopupImpl::AddProgressPopupEventListener(IProgressPopupEventListener& listener)
172 {
173         result r = E_SUCCESS;
174
175         if (__pPublicProgressPopupEvent == null)
176         {
177                 __pPublicProgressPopupEvent = _PublicProgressPopupEvent::CreateInstanceN(GetPublic());
178                 r = GetLastResult();
179                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
180         }
181
182         r = __pPublicProgressPopupEvent->AddListener(listener);
183         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
184
185         return GetCore().AddProgressPopupEventListener(*this);
186 }
187
188 result
189 _ProgressPopupImpl::RemoveProgressPopupEventListener(IProgressPopupEventListener & listener)
190 {
191         result r = E_SUCCESS;
192
193         if (__pPublicProgressPopupEvent != null)
194         {
195                 r = __pPublicProgressPopupEvent->RemoveListener(listener);
196                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
197         }
198
199         return r;
200 }
201
202 result
203 _ProgressPopupImpl::OnAttachedToMainTree(void)
204 {
205         if (GetOwner() == null)
206         {
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.");
210
211                 _Form* pForm = pFrameImpl->GetCore().GetCurrentForm();
212
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.");
216
217                 if (pForm != null)
218                 {
219                         pWindow->SetOwner(pForm);
220                 }
221                 else
222                 {
223                         pWindow->SetOwner(&pFrameImpl->GetCore());
224                 }
225         }
226
227         _WindowImpl::OnAttachedToMainTree();
228         return GetCore().Open();
229 }
230
231 result
232 _ProgressPopupImpl::SetTitleText(const String& title)
233 {
234         result r = E_SUCCESS;
235
236         r = GetCore().SetTitleText(title);
237         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
238
239         int maxHeight = 0;
240         int defaultWidth = 0;
241
242         GET_SHAPE_CONFIG(MESSAGEBOX::MAX_HEIGHT, GetCore().GetOrientation(), maxHeight);
243         GET_SHAPE_CONFIG(MESSAGEBOX::DEFAULT_WIDTH, GetCore().GetOrientation(), defaultWidth);
244
245         int totalH = -1;
246         totalH = GetCore().GetTotalHeight();
247
248         Rectangle bounds;
249         if (totalH > maxHeight)
250         {
251                 bounds = GetCenterAlignedRect(defaultWidth, maxHeight);
252         }
253         else
254         {
255                 bounds = GetCenterAlignedRect(defaultWidth, totalH);
256         }
257
258         SetMovable(true);
259         SetResizable(true);
260
261         r = SetBounds(bounds);
262         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
263
264         SetMovable(false);
265         SetResizable(false);
266
267         r = GetCore().UpdateBounds();
268         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
269
270         return r;
271
272 }
273
274 result
275 _ProgressPopupImpl::SetText(const String& text)
276 {
277         result r = E_SUCCESS;
278         int maxLength = 0;
279
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.");
283
284         r = GetCore().SetText(text);
285         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
286
287         int maxHeight = 0;
288         int defaultWidth = 0;
289
290         GET_SHAPE_CONFIG(MESSAGEBOX::MAX_HEIGHT, GetCore().GetOrientation(), maxHeight);
291         GET_SHAPE_CONFIG(MESSAGEBOX::DEFAULT_WIDTH, GetCore().GetOrientation(), defaultWidth);
292
293         int totalH = -1;
294         totalH = GetCore().GetTotalHeight();
295
296         Rectangle bounds;
297         if (totalH > maxHeight)
298         {
299                 bounds = GetCenterAlignedRect(defaultWidth, maxHeight);
300         }
301         else
302         {
303                 bounds = GetCenterAlignedRect(defaultWidth, totalH);
304         }
305
306         SetMovable(true);
307         SetResizable(true);
308
309         r = SetBounds(bounds);
310         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
311
312         SetMovable(false);
313         SetResizable(false);
314
315         r = GetCore().UpdateBounds();
316         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
317
318
319         return r;
320
321 }
322
323 String
324 _ProgressPopupImpl::GetText(void) const
325 {
326         return GetCore().GetText();
327 }
328
329 result
330 _ProgressPopupImpl::SetTextColor(const Color& color)
331 {
332         GetCore().SetTextColor(color);
333
334         return E_SUCCESS;
335 }
336
337 Color
338 _ProgressPopupImpl::GetTextColor() const
339 {
340         return GetCore().GetTextColor();
341 }
342
343 int
344 _ProgressPopupImpl::GetMaxTextLength(void) const
345 {
346         int maxLength = 0;
347         GET_FIXED_VALUE_CONFIG(MESSAGEBOX::TEXT_MAX_LENGTH, GetCore().GetOrientation(), maxLength);
348
349         return maxLength;
350 }
351
352 Rectangle
353 _ProgressPopupImpl::GetCenterAlignedRect(int width, int height) const
354 {
355         int x = 0;
356         int y = 0;
357
358         Dimension screenRect = _ControlManager::GetInstance()->GetScreenSize();
359
360         if (GetCore().GetOrientation() == _CONTROL_ORIENTATION_LANDSCAPE)
361         {
362                 int temp = screenRect.width;
363                 screenRect.width = screenRect.height;
364                 screenRect.height = temp;
365         }
366
367         x = (screenRect.width - width) / 2;
368         y = (screenRect.height - height) / 2;
369
370         return Rectangle(x, y, width, height);
371 }
372
373 void
374 _ProgressPopupImpl::OnProgressPopupCanceled(void)
375 {
376         if (__pPublicProgressPopupEvent != null)
377         {
378                 Tizen::Base::Runtime::IEventArg* pEventArg = _PublicProgressPopupEvent::CreateProgressPopupEventArgN();
379                 result r = GetLastResult();
380                 SysTryReturnVoidResult(NID_UI_CTRL, pEventArg != null, r, "[%s] Propagating.", GetErrorMessage(r));
381
382                 __pPublicProgressPopupEvent->Fire(*pEventArg);
383         }
384 }
385
386 void
387 _ProgressPopupImpl::OnChangeLayout(_ControlOrientation orientation)
388 {
389         result r = E_SUCCESS;
390         Dimension portraitSize;
391         Dimension landscapeSize;
392
393         if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
394         {
395                 portraitSize = Dimension(GetBounds().width, GetBounds().height);
396                 landscapeSize = Dimension(portraitSize.height, portraitSize.width);
397         }
398         else
399         {
400                 portraitSize = Dimension(GetBounds().height, GetBounds().width);
401                 landscapeSize = Dimension(portraitSize.height, portraitSize.width);
402         }
403
404         if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
405         {
406                 SetResizable(true);
407                 SetMovable(true);
408
409                 r = SetBounds(GetCenterAlignedRect(portraitSize.width, portraitSize.height));
410                 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
411
412                 SetMovable(false);
413                 SetResizable(false);
414         }
415         else
416         {
417                 SetResizable(true);
418                 SetMovable(true);
419
420                 r = SetBounds(GetCenterAlignedRect(landscapeSize.width, landscapeSize.height));
421                 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
422
423                 SetMovable(false);
424                 SetResizable(false);
425         }
426
427         return GetCore().OnChangeLayout(orientation);
428 }
429
430
431 }}} // Tizen::Ui::Controls