Changed indicator bg color.
[platform/framework/native/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 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
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0/
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_CoordinateSystemUtils.h"
28 #include "FUi_ControlImplManager.h"
29 #include "FUi_Math.h"
30 #include "FUiCtrl_FrameImpl.h"
31 #include "FUiCtrl_Form.h"
32 #include "FUiCtrl_ProgressPopupImpl.h"
33 #include "FUiCtrl_Indicator.h"
34
35
36 using namespace Tizen::Ui::Animations;
37 using namespace Tizen::Graphics;
38 using namespace Tizen::Ui;
39 using namespace Tizen::Base;
40
41
42 namespace Tizen { namespace Ui { namespace Controls
43 {
44
45
46 _ProgressPopupImpl*
47 _ProgressPopupImpl::GetInstance(ProgressPopup& pProgressPopup)
48 {
49         return static_cast <_ProgressPopupImpl*>(pProgressPopup._pControlImpl);
50 }
51
52 const _ProgressPopupImpl*
53 _ProgressPopupImpl::GetInstance(const ProgressPopup& pProgressPopup)
54 {
55         return static_cast <const _ProgressPopupImpl*>(pProgressPopup._pControlImpl);
56 }
57
58 _ProgressPopupImpl::_ProgressPopupImpl(ProgressPopup* pPublic, _ProgressPopup* pCore)
59         : _PopupImpl(pPublic, pCore)
60         , __pPublicProgressPopupEvent(null)
61 {
62         _centerAlign = true;
63         //empty statement
64 }
65
66 _ProgressPopupImpl::~_ProgressPopupImpl(void)
67 {
68         if (__pPublicProgressPopupEvent != null)
69         {
70                 delete __pPublicProgressPopupEvent;
71                 __pPublicProgressPopupEvent = null;
72         }
73 }
74
75 _ProgressPopupImpl*
76 _ProgressPopupImpl::CreateProgressPopupImplN(ProgressPopup* pControl)
77 {
78         result r = E_SUCCESS;
79
80         _ProgressPopupImpl* pImpl = null;
81         _ProgressPopup* pCore = null;
82
83         pCore = _ProgressPopup::CreateProgressPopupN();
84         r = GetLastResult();
85         SysTryReturn(NID_UI_CTRL, pCore, null, r, "[%s] Propagating.", GetErrorMessage(r));
86
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));
90
91         return pImpl;
92 }
93
94 result
95 _ProgressPopupImpl::Initialize(bool cancelButton, bool transparent)
96 {
97         result r = E_SUCCESS;
98
99         float animationWidth = 0.0f;
100
101         _ControlOrientation orientation;
102
103         orientation = GetCore().GetOrientation();
104
105         GET_SHAPE_CONFIG(POPUP::PROCESS_ANIMATION_WIDTH, orientation, animationWidth);
106
107         FloatRectangle animationRect;
108         animationRect = GetCenterAlignedRect(animationWidth, animationWidth);
109
110         r = GetCore().Initialize(cancelButton, transparent, animationRect);
111         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
112
113         if (transparent)
114         {
115                 r = SetBounds(animationRect);
116                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
117         }
118         else
119         {
120                 float maxHeight = 0.0f;
121                 float defaultWidth = 0.0f;
122
123                 GET_SHAPE_CONFIG(MESSAGEBOX::MAX_HEIGHT, orientation, maxHeight);
124                 GET_SHAPE_CONFIG(MESSAGEBOX::DEFAULT_WIDTH, orientation, defaultWidth);
125
126                 float totalH = -1.0f;
127                 totalH = GetCore().GetTotalHeight();
128
129                 FloatRectangle bounds;
130                 if (totalH > maxHeight)
131                 {
132                         bounds = GetCenterAlignedRect(defaultWidth, maxHeight);
133                 }
134                 else
135                 {
136                         bounds = GetCenterAlignedRect(defaultWidth, totalH);
137                 }
138
139                 r = SetBounds(bounds);
140                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
141         }
142
143         SetResizable(false);
144
145         return r;
146 }
147
148 const char*
149 _ProgressPopupImpl::GetPublicClassName(void) const
150 {
151         return "Tizen::Ui::Controls::ProgressPopup";
152 }
153
154 const ProgressPopup&
155 _ProgressPopupImpl::GetPublic(void) const
156 {
157         return static_cast <const ProgressPopup&>(_ControlImpl::GetPublic());
158 }
159
160 ProgressPopup&
161 _ProgressPopupImpl::GetPublic(void)
162 {
163         return static_cast <ProgressPopup&>(_ControlImpl::GetPublic());
164 }
165
166 const _ProgressPopup&
167 _ProgressPopupImpl::GetCore(void) const
168 {
169         return static_cast <const _ProgressPopup&>(_ControlImpl::GetCore());
170 }
171
172 _ProgressPopup&
173 _ProgressPopupImpl::GetCore(void)
174 {
175         return static_cast <_ProgressPopup&>(_ControlImpl::GetCore());
176 }
177
178 result
179 _ProgressPopupImpl::AddProgressPopupEventListener(IProgressPopupEventListener& listener)
180 {
181         result r = E_SUCCESS;
182
183         if (__pPublicProgressPopupEvent == null)
184         {
185                 __pPublicProgressPopupEvent = _PublicProgressPopupEvent::CreateInstanceN(GetPublic());
186                 r = GetLastResult();
187                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
188         }
189
190         r = __pPublicProgressPopupEvent->AddListener(listener);
191         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
192
193         return GetCore().AddProgressPopupEventListener(*this);
194 }
195
196 result
197 _ProgressPopupImpl::RemoveProgressPopupEventListener(IProgressPopupEventListener & listener)
198 {
199         result r = E_SUCCESS;
200
201         if (__pPublicProgressPopupEvent != null)
202         {
203                 r = __pPublicProgressPopupEvent->RemoveListener(listener);
204                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
205         }
206
207         return r;
208 }
209
210 result
211 _ProgressPopupImpl::OnAttachedToMainTree(void)
212 {
213         _WindowImpl::OnAttachedToMainTree();
214         return GetCore().Open();
215 }
216
217 result
218 _ProgressPopupImpl::SetTitleText(const String& title)
219 {
220         result r = E_SUCCESS;
221
222         if (GetCore().IsTransparent())
223         {
224                 return r;
225         }
226
227         r = GetCore().SetTitleText(title);
228         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, r, "[%s] Propagating.", GetErrorMessage(r));
229
230         float maxHeight = 0.0f;
231         float defaultWidth = 0.0f;
232
233         GET_SHAPE_CONFIG(MESSAGEBOX::MAX_HEIGHT, GetCore().GetOrientation(), maxHeight);
234         GET_SHAPE_CONFIG(MESSAGEBOX::DEFAULT_WIDTH, GetCore().GetOrientation(), defaultWidth);
235
236         float totalH = -1.0f;
237         totalH = GetCore().GetTotalHeight();
238
239         FloatRectangle bounds;
240         if (totalH > maxHeight)
241         {
242                 bounds = GetCenterAlignedRect(defaultWidth, maxHeight);
243         }
244         else
245         {
246                 bounds = GetCenterAlignedRect(defaultWidth, totalH);
247         }
248
249         SetResizable(true);
250
251         r = SetBounds(bounds);
252         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
253
254         SetResizable(false);
255
256         r = GetCore().UpdateBounds();
257         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
258
259         return r;
260
261 }
262
263 result
264 _ProgressPopupImpl::SetText(const String& text)
265 {
266         result r = E_SUCCESS;
267         int maxLength = 0;
268
269         if (GetCore().IsTransparent())
270         {
271                 return r;
272         }
273
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.");
277
278         r = GetCore().SetText(text);
279         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
280
281         float maxHeight = 0.0f;
282         float defaultWidth = 0.0f;
283
284         GET_SHAPE_CONFIG(MESSAGEBOX::MAX_HEIGHT, GetCore().GetOrientation(), maxHeight);
285         GET_SHAPE_CONFIG(MESSAGEBOX::DEFAULT_WIDTH, GetCore().GetOrientation(), defaultWidth);
286
287         float totalH = -1.0f;
288         totalH = GetCore().GetTotalHeight();
289
290         FloatRectangle bounds;
291
292         if (totalH > maxHeight)
293         {
294                 bounds = GetCenterAlignedRect(defaultWidth, maxHeight);
295         }
296         else
297         {
298                 bounds = GetCenterAlignedRect(defaultWidth, totalH);
299         }
300
301         SetResizable(true);
302
303         r = SetBounds(bounds);
304         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
305
306         SetResizable(false);
307
308         r = GetCore().UpdateBounds();
309         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
310
311
312         return r;
313
314 }
315
316 String
317 _ProgressPopupImpl::GetText(void) const
318 {
319         return GetCore().GetText();
320 }
321
322 result
323 _ProgressPopupImpl::SetTextColor(const Color& color)
324 {
325         GetCore().SetTextColor(color);
326
327         return E_SUCCESS;
328 }
329
330 Color
331 _ProgressPopupImpl::GetTextColor() const
332 {
333         return GetCore().GetTextColor();
334 }
335
336 int
337 _ProgressPopupImpl::GetMaxTextLength(void) const
338 {
339         int maxLength = 0;
340         GET_FIXED_VALUE_CONFIG(MESSAGEBOX::TEXT_MAX_LENGTH, GetCore().GetOrientation(), maxLength);
341
342         return maxLength;
343 }
344
345 FloatRectangle
346 _ProgressPopupImpl::GetCenterAlignedRect(float width, float height) const
347 {
348         float x = 0.0f;
349         float y = 0.0f;
350
351         FloatDimension screenRect = _ControlManager::GetInstance()->GetScreenSizeF();
352
353         if (GetCore().GetOrientation() == _CONTROL_ORIENTATION_LANDSCAPE)
354         {
355                 float temp = screenRect.width;
356                 screenRect.width = screenRect.height;
357                 screenRect.height = temp;
358         }
359
360         x = (screenRect.width - width) / 2.0f;
361         y = (screenRect.height - height) / 2.0f;
362
363         return FloatRectangle(x, y, width, height);
364 }
365
366 void
367 _ProgressPopupImpl::OnProgressPopupCanceled(void)
368 {
369         if (__pPublicProgressPopupEvent != null)
370         {
371                 Tizen::Base::Runtime::IEventArg* pEventArg = _PublicProgressPopupEvent::CreateProgressPopupEventArgN();
372                 result r = GetLastResult();
373                 SysTryReturnVoidResult(NID_UI_CTRL, pEventArg != null, r, "[%s] Propagating.", GetErrorMessage(r));
374
375                 __pPublicProgressPopupEvent->Fire(*pEventArg);
376         }
377 }
378
379 void
380 _ProgressPopupImpl::OnChangeLayout(_ControlOrientation orientation)
381 {
382         result r = E_SUCCESS;
383         FloatRectangle bounds;
384
385         bounds = GetBoundsF();
386
387         if(GetCore().IsTransparent() == false)
388         {
389                 GetCore().OnChangeLayout(orientation);
390
391                 r = GetLastResult();
392                 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
393
394                 float maxHeight = 0.0f;
395                 float defaultWidth = 0.0f;
396
397                 GET_SHAPE_CONFIG(MESSAGEBOX::MAX_HEIGHT, orientation, maxHeight);
398                 GET_SHAPE_CONFIG(MESSAGEBOX::DEFAULT_WIDTH, orientation, defaultWidth);
399
400                 bounds.width = defaultWidth;
401
402                 float totalH = -1.0f;
403                 totalH = GetCore().GetTotalHeight();
404
405                 if (totalH > maxHeight)
406                 {
407                         bounds.height = maxHeight;
408                 }
409                 else
410                 {
411                         bounds.height = totalH;
412                 }
413         }
414
415         SetResizable(true);
416
417         if(_centerAlign)
418         {
419                 r = SetBounds(GetCenterAlignedRect(bounds.width, bounds.height));
420         }
421         else
422         {
423                 r = SetBounds(bounds);
424         }
425
426         SetResizable(false);
427
428         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
429
430
431         return ;
432 }
433
434 void
435 _ProgressPopupImpl::OnBoundsChanged(void)
436 {
437         FloatRectangle rect;
438         FloatRectangle pRect = GetBoundsF();
439
440         if(_centerAlign)
441         {
442                 rect = GetCenterAlignedRect(pRect.width, pRect.height);
443
444                 if (!_FloatCompare(rect.x, pRect.x) || !_FloatCompare(rect.y, pRect.y))
445                 {
446                         _centerAlign = false;
447                 }
448         }
449
450         _ControlImpl::OnBoundsChanged();
451 }
452
453 }}} // Tizen::Ui::Controls