Changed indicator bg color.
[platform/framework/native/uifw.git] / src / ui / controls / FUiCtrl_ProgressImpl.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_ProgressImpl.cpp
20  * @brief               This is the implementation file for the _ProgressImpl class.
21  */
22
23 #include <FUiCtrlProgress.h>
24 #include <FBaseSysLog.h>
25 #include <FUiAccessibilityContainer.h>
26 #include <FUiAccessibilityElement.h>
27 #include "FUi_UiBuilder.h"
28 #include "FUi_ResourceManager.h"
29 #include "FUi_ResourceSizeInfo.h"
30 #include "FUiCtrl_ProgressImpl.h"
31 #include "FUiCtrl_Progress.h"
32
33 using namespace Tizen::Ui;
34 using namespace Tizen::Graphics;
35
36 const int _DEFAULT_MINIMUM = 0;
37 const int _DEFAULT_MAXIMUM = 100;
38
39 namespace Tizen { namespace Ui { namespace Controls
40 {
41
42 _ProgressImpl*
43 _ProgressImpl::GetInstance(Progress& progress)
44 {
45         return static_cast<_ProgressImpl*> (progress._pControlImpl);
46 }
47
48 const _ProgressImpl*
49 _ProgressImpl::GetInstance(const Progress& progress)
50 {
51         return static_cast<const _ProgressImpl*> (progress._pControlImpl);
52 }
53
54 _ProgressImpl::_ProgressImpl(Progress* pPublic, _Progress* pCore)
55         : _ControlImpl(pPublic, pCore)
56 {
57         SetFocusableChangable(false);
58 }
59
60 _ProgressImpl::~_ProgressImpl(void)
61 {
62 }
63
64 _ProgressImpl*
65 _ProgressImpl::CreateProgressImplN(Progress* pControl, const Rectangle& bounds)
66 {
67         ClearLastResult();
68
69         result r = E_SUCCESS;
70
71         r = GET_SIZE_INFO(Progress).CheckInitialSizeValid(Dimension(bounds.width, bounds.height), _CONTROL_ORIENTATION_PORTRAIT);
72         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
73
74         _Progress* pCore = _Progress::CreateProgressN();
75         r = GetLastResult();
76         SysTryReturn(NID_UI_CTRL, pCore != null, null, r, "[%s] Propagating.", GetErrorMessage(r));
77
78         _ProgressImpl* pImpl = new (std::nothrow) _ProgressImpl(pControl, pCore);
79         r = CheckConstruction(pCore, pImpl);
80         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
81
82         r = pImpl->InitializeBoundsProperties(GET_SIZE_INFO(Progress), bounds, pCore->GetOrientation());
83         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
84
85         return pImpl;
86
87 CATCH:
88         delete pImpl;  //This deletes pCore as well
89         pImpl = null;
90
91         return null;
92 }
93
94 _ProgressImpl*
95 _ProgressImpl::CreateProgressImplFN(Progress* pControl, const FloatRectangle& bounds)
96 {
97         ClearLastResult();
98
99         result r = E_SUCCESS;
100
101         r = GET_SIZE_INFO(Progress).CheckInitialSizeValidF(FloatDimension(bounds.width, bounds.height), _CONTROL_ORIENTATION_PORTRAIT);
102         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
103
104         _Progress* pCore = _Progress::CreateProgressN();
105         r = GetLastResult();
106         SysTryReturn(NID_UI_CTRL, pCore != null, null, r, "[%s] Propagating.", GetErrorMessage(r));
107
108         _ProgressImpl* pImpl = new (std::nothrow) _ProgressImpl(pControl, pCore);
109         r = CheckConstruction(pCore, pImpl);
110         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
111
112         r = pImpl->InitializeBoundsPropertiesF(GET_SIZE_INFO(Progress), bounds, pCore->GetOrientation());
113         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
114
115         return pImpl;
116
117 CATCH:
118         delete pImpl;  //This deletes pCore as well
119         pImpl = null;
120
121         return null;
122 }
123
124 result
125 _ProgressImpl::SetValue(int value)
126 {
127         ClearLastResult();
128
129         Variant newValue(value);
130
131         return GetCore().SetPropertyValue(newValue);
132 }
133
134 result
135 _ProgressImpl::SetRange(int minValue, int maxValue)
136 {
137         ClearLastResult();
138
139         return GetCore().SetRange(minValue, maxValue);
140 }
141
142 int
143 _ProgressImpl::GetValue(void) const
144 {
145         ClearLastResult();
146
147         return GetCore().GetPropertyValue().ToInt();
148 }
149
150 result
151 _ProgressImpl::GetRange(int& minValue, int& maxValue) const
152 {
153         ClearLastResult();
154
155         return GetCore().GetRange(minValue, maxValue);
156 }
157
158 int
159 _ProgressImpl::GetPercentComplete(void) const
160 {
161         ClearLastResult();
162
163         return GetCore().GetPercentComplete();
164 }
165
166 result
167 _ProgressImpl::SetBarColor(const Color& color)
168 {
169         ClearLastResult();
170
171         Variant barColor(color);
172
173         return GetCore().SetPropertyBarColor(barColor);
174 }
175
176 Color
177 _ProgressImpl::GetBarColor() const
178 {
179         ClearLastResult();
180
181         return GetCore().GetPropertyBarColor().ToColor();
182 }
183
184 result
185 _ProgressImpl::SetBarBackgroundColor(const Color& color)
186 {
187         ClearLastResult();
188
189         Variant barBackgroundColor(color);
190
191         return GetCore().SetPropertyBarBackgroundColor(barBackgroundColor);
192 }
193
194 Color
195 _ProgressImpl::GetBarBackgroundColor() const
196 {
197         ClearLastResult();
198
199         return GetCore().GetPropertyBarBackgroundColor().ToColor();
200 }
201 const char*
202 _ProgressImpl::GetPublicClassName(void) const
203 {
204         return "Tizen::Ui::Controls::Progress";
205 }
206
207 const Progress&
208 _ProgressImpl::GetPublic(void) const
209 {
210         return static_cast <const Progress&>(_ControlImpl::GetPublic());
211 }
212
213 Progress&
214 _ProgressImpl::GetPublic(void)
215 {
216         return static_cast <Progress&>(_ControlImpl::GetPublic());
217 }
218
219 const _Progress&
220 _ProgressImpl::GetCore(void) const
221 {
222         return static_cast <const _Progress&>(_ControlImpl::GetCore());
223 }
224
225 _Progress&
226 _ProgressImpl::GetCore(void)
227 {
228         return static_cast <_Progress&>(_ControlImpl::GetCore());
229 }
230
231
232 class _ProgressMaker
233         : public _UiBuilderControlMaker
234 {
235
236 public:
237         _ProgressMaker(_UiBuilder* pUiBuilder)
238                 : _UiBuilderControlMaker(pUiBuilder){}
239         virtual ~_ProgressMaker(void){}
240
241         static _UiBuilderControlMaker*
242         GetInstance(_UiBuilder* pUiBuilder)
243         {
244                 _ProgressMaker* pProgressMaker = new (std::nothrow) _ProgressMaker(pUiBuilder);
245                 return pProgressMaker;
246         }
247
248 protected:
249         virtual Control*
250         Make(_UiBuilderControl* pControl)
251         {
252                 result r = E_SUCCESS;
253                 _UiBuilderControlLayout* pControlProperty = null;
254                 Progress* pProgress = null;
255                 Tizen::Base::String elementString;
256                 Tizen::Base::String elementString1;
257                 Color color;
258                 int tempMin = 0;
259                 int tempMax = 0;
260                 int temp = 0;
261
262                 FloatRectangle rect;
263
264                 GetProperty(pControl, &pControlProperty);
265                 if (pControlProperty == null)
266                 {
267                         return null;
268                 }
269
270                 pProgress = new (std::nothrow) Progress;
271                 if (pProgress == null)
272                 {
273                         return null;
274                 }
275                 rect = pControlProperty->GetRectF();
276
277                 if (pControl->GetElement(L"min", elementString) && pControl->GetElement(L"max", elementString1))
278                 {
279                         Base::Integer::Parse(elementString, tempMin);
280                         Base::Integer::Parse(elementString1, tempMax);
281                         if (tempMin > tempMax)
282                         {
283                                 temp = tempMin;
284                                 tempMin = tempMax;
285                                 tempMax = tempMin;
286                         }
287                 }
288                 else
289                 {
290                         tempMin = _DEFAULT_MINIMUM;
291                         tempMax = _DEFAULT_MAXIMUM;
292                 }
293
294                 r = pProgress->Construct(rect, tempMin, tempMax);
295                 if (r != E_SUCCESS)
296                 {
297                         delete pProgress;
298                         pProgress = null;
299
300                         return null;
301                 }
302
303                 if (pControl->GetElement(L"value", elementString))
304                 {
305                         int tempValue = 0;
306                         Base::Integer::Parse(elementString, tempValue);
307                         pProgress->SetValue(tempValue);
308                 }
309
310                 if (pControl->GetElement(L"barColor", elementString))
311                 {
312                         ConvertStringToColor(elementString, color);
313                         pProgress->SetBarColor(color);
314                 }
315
316                 if (pControl->GetElement(L"barBackgroundColor", elementString))
317                 {
318                         ConvertStringToColor(elementString, color);
319                         pProgress->SetBarBackgroundColor(color);
320                 }
321
322                 if (pControl->GetElement(L"accessibilityHint", elementString))
323                 {
324                         AccessibilityContainer* pContainer = pProgress->GetAccessibilityContainer();
325                         if (pContainer)
326                         {
327                                 AccessibilityElement* pElement = pContainer->GetElement(L"ProgressingImage");
328                                 if (pElement)
329                                 {
330                                         pElement->SetHint(elementString);
331                                 }
332                         }
333                 }
334
335                 return pProgress;
336         }
337
338 }; // _ProgressMaker
339
340 _ProgressRegister::_ProgressRegister(void)
341 {
342         _UiBuilderControlTableManager* pUiBuilderControlTableManager = _UiBuilderControlTableManager::GetInstance();
343         pUiBuilderControlTableManager->RegisterControl(L"Progress", _ProgressMaker::GetInstance);
344 }
345
346 _ProgressRegister::~_ProgressRegister(void)
347 {
348         _UiBuilderControlTableManager* pUiBuilderControlTableManager = _UiBuilderControlTableManager::GetInstance();
349         pUiBuilderControlTableManager->UnregisterControl(L"Progress");
350 }
351 static _ProgressRegister ProgressRegisterToUiBuilder;
352 }}} // Tizen::Ui::Controls