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