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_Progress.cpp
20 * @brief This is the implementation file for the _Progress class.
23 #include <FBaseErrorDefine.h>
24 #include <FBaseSysLog.h>
25 #include "FUiAnim_VisualElement.h"
26 #include "FUi_ResourceManager.h"
27 #include "FUi_AccessibilityContainer.h"
28 #include "FUi_AccessibilityElement.h"
29 #include "FUiCtrl_Progress.h"
30 #include "FUiCtrl_ProgressPresenter.h"
32 using namespace Tizen::Ui;
33 using namespace Tizen::Graphics;
34 using namespace Tizen::Base;
36 namespace Tizen { namespace Ui { namespace Controls
39 IMPLEMENT_PROPERTY(_Progress);
41 _Progress::_Progress(void)
42 : __pProgressPresenter(null)
43 , __pAccessibilityElement(null)
45 Tizen::Ui::Animations::_VisualElement* pBase = GetVisualElement();
49 pBase->SetSurfaceOpaque(false);
53 _Progress::~_Progress(void)
55 delete __pProgressPresenter;
56 __pProgressPresenter = null;
57 if (__pAccessibilityElement)
59 __pAccessibilityElement->Activate(false);
60 __pAccessibilityElement = null;
65 _Progress::CreateProgressN()
69 _Progress* pProgress = new (std::nothrow) _Progress;
70 SysTryReturn(NID_UI_CTRL, pProgress, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
72 _AccessibilityContainer* pContainer = pProgress->GetAccessibilityContainer();
74 pProgress->__pProgressPresenter = _ProgressPresenter::CreateInstanceN(*pProgress);
76 SysTryCatch(NID_UI_CTRL, pProgress->__pProgressPresenter != null, , r,
77 "[%s] Propagating.", GetErrorMessage(r));
79 r = GET_COLOR_CONFIG(SLIDER::BAR_NORMAL, pProgress->__barColor);
80 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to get progress colorconfig", GetErrorMessage(r));
82 r = GET_COLOR_CONFIG(SLIDER::BAR_BG_NORMAL, pProgress->__barBgColor);
83 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to get progress colorconfig", GetErrorMessage(r));
85 pProgress->AcquireHandle();
86 pProgress->SetFocusable(false);
90 pContainer->Activate(true);
91 pProgress->InitializeAccessibilityElement();
105 _Progress::InitializeAccessibilityElement(void)
107 result r = E_SUCCESS;
109 if (__pAccessibilityElement)
114 _AccessibilityContainer* pContainer = GetAccessibilityContainer();
117 __pAccessibilityElement = new _AccessibilityElement(true);
118 SysTryReturn(NID_UI_CTRL, __pAccessibilityElement, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
119 __pAccessibilityElement->SetBounds(FloatRectangle(0.0f, 0.0f, GetBounds().width, GetBounds().height));
120 __pAccessibilityElement->SetName(L"ProgressingImage");
121 __pAccessibilityElement->SetLabel(L"Progressing");
124 GET_STRING_CONFIG(IDS_TPLATFORM_BODY_PD_PERCENT_T_TTS, string);
125 string.Insert(GetPercentComplete(), 0);
126 __pAccessibilityElement->SetValue(string);
128 r = pContainer->AddElement(*__pAccessibilityElement);
129 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
136 _Progress::OnAttachedToMainTree(void)
138 if (__pAccessibilityElement)
140 __pAccessibilityElement->SetBounds(FloatRectangle(0.0f, 0.0f, GetBounds().width, GetBounds().height));
146 _Progress::OnBoundsChanged(void)
148 if (__pAccessibilityElement)
150 __pAccessibilityElement->SetBounds(FloatRectangle(0.0f, 0.0f, GetBounds().width, GetBounds().height));
157 _Progress::SetValue(int value)
159 return SetProperty("value", Variant(value));
163 _Progress::SetPropertyValue(const Variant& value)
165 result r = E_SUCCESS;
167 int tempValue = value.ToInt();
169 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
171 __pProgressPresenter->SetValue(tempValue);
173 r = InitializeAccessibilityElement();
174 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
176 if (__pAccessibilityElement)
179 GET_STRING_CONFIG(IDS_TPLATFORM_BODY_PD_PERCENT_T_TTS, string);
180 string.Insert(GetPercentComplete(), 0);
181 __pAccessibilityElement->SetValue(string);
188 _Progress::GetValue(void) const
190 Variant value = GetProperty("value");
191 result r = GetLastResult();
192 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, -1, r, "[%s] Propagating.", GetErrorMessage(r));
194 return value.ToInt();
198 _Progress::GetPropertyValue(void) const
200 return Variant(__pProgressPresenter->GetValue());
204 _Progress::SetRange(int minValue, int maxValue)
206 SysTryReturn(NID_UI_CTRL, minValue >= 0 && maxValue >= 0, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
207 "[E_OUT_OF_RANGE] Values can not be negative.");
208 SysTryReturn(NID_UI_CTRL, minValue < maxValue, E_INVALID_ARG, E_INVALID_ARG,
209 "[E_INVALID_ARG] Invalid argument(s) is used. The minimum value is greater than maximum value.");
211 result r = E_SUCCESS;
213 Variant oldMinValue = GetProperty("minValue");
214 Variant value = GetProperty("value");
216 r = SetProperty("minValue", Variant(minValue));
217 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Failed to set minimum value.", GetErrorMessage(r));
219 r = SetProperty("maxValue", Variant(maxValue));
222 SysLogException(NID_UI_CTRL, r, "[%s] Failed to set maximum value.", GetErrorMessage(r));
224 result nestedResult = SetPropertyMinValue(oldMinValue);
225 if (nestedResult != E_SUCCESS)
227 SysLog(NID_UI_CTRL, "Failed to recover original minimum value");
231 nestedResult = SetPropertyValue(value);
232 if (nestedResult != E_SUCCESS)
234 SysLog(NID_UI_CTRL, "Failed to recover original value");
238 if (__pAccessibilityElement)
241 GET_STRING_CONFIG(IDS_TPLATFORM_BODY_PD_PERCENT_T_TTS, string);
242 string.Insert(GetPercentComplete(), 0);
243 __pAccessibilityElement->SetValue(string);
250 _Progress::SetPropertyMinValue(const Variant& minValue)
252 result r = E_SUCCESS;
254 int tempMinValue = minValue.ToInt();
256 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
258 __pProgressPresenter->SetMinValue(tempMinValue);
264 _Progress::SetPropertyMaxValue(const Variant& maxValue)
266 result r = E_SUCCESS;
268 int tempMaxValue = maxValue.ToInt();
270 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
272 __pProgressPresenter->SetMaxValue(tempMaxValue);
278 _Progress::GetRange(int& minValue, int& maxValue) const
280 result r = E_SUCCESS;
282 Variant minimum = GetProperty("minValue");
284 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
286 Variant maximum = GetProperty("maxValue");
288 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
290 minValue = minimum.ToInt();
291 maxValue = maximum.ToInt();
297 _Progress::GetPropertyMinValue(void) const
299 return Variant(__pProgressPresenter->GetMinValue());
303 _Progress::GetPropertyMaxValue(void) const
305 return Variant(__pProgressPresenter->GetMaxValue());
309 _Progress::GetPercentComplete(void) const
311 return __pProgressPresenter->GetPercentComplete();
315 _Progress::SetBarColor(const Color& color)
317 return SetProperty("barColor", Variant(color));
321 _Progress::SetPropertyBarColor(const Variant& barColor)
323 result r = E_SUCCESS;
325 Color tempColor = barColor.ToColor();
327 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
329 __barColor = tempColor;
330 __barColor.SetAlpha(0xFF);
336 _Progress::GetBarColor(void) const
338 Variant barColor = GetProperty("barColor");
339 result r = GetLastResult();
340 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, Color(), r, "[%s] Propagating.", GetErrorMessage(r));
342 return barColor.ToColor();
346 _Progress::GetPropertyBarColor(void) const
348 return Variant(__barColor);
352 _Progress::SetBarBackgroundColor(const Color& color)
354 return SetProperty("barBackgroundColor", Variant(color));
358 _Progress::SetPropertyBarBackgroundColor(const Variant& barBgColor)
360 result r = E_SUCCESS;
362 Color tempColor = barBgColor.ToColor();
364 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
366 __barBgColor = tempColor;
367 __barBgColor.SetAlpha(0xFF);
373 _Progress::GetBarBackgroundColor(void) const
375 Variant barBackgroundColor = GetProperty("barBackgroundColor");
376 result r = GetLastResult();
377 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, Color(), r, "[%s] Propagating.", GetErrorMessage(r));
379 return barBackgroundColor.ToColor();
383 _Progress::GetPropertyBarBackgroundColor(void) const
385 return Variant(__barBgColor);
388 _Progress::OnDraw(void)
390 __pProgressPresenter->Draw();
394 }}} // Tizen::Ui::Controls