add patch
[framework/osp/uifw.git] / src / ui / controls / FUiCtrlSlider.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                        FUiCtrlSlider.cpp
20  * @brief               This is the implementation file for Slider class.
21  */
22
23 #include <FBaseSysLog.h>
24 #include <FUiCtrlSlider.h>
25 #include "FUiCtrl_SliderImpl.h"
26
27 using namespace Tizen::Graphics;
28 using namespace Tizen::Base;
29 using namespace Tizen::Ui;
30
31 namespace Tizen { namespace Ui { namespace Controls
32 {
33
34 Slider::Slider(void)
35 {
36 }
37
38 Slider::~Slider(void)
39 {
40 }
41
42 result
43 Slider::Construct(const Rectangle& rect, BackgroundStyle backgroundStyle, bool showTitle, int minValue, int maxValue, GroupStyle groupStyle)
44 {
45         result r = E_SUCCESS;
46
47         _SliderImpl* pSliderImpl = _SliderImpl::GetInstance(*this);
48         SysAssertf((pSliderImpl == null), "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class.");
49
50         int sliderStyle = 0;
51         if (showTitle)
52         {
53                 sliderStyle |= SLIDER_STYLE_TITLE;
54         }
55         sliderStyle |= SLIDER_STYLE_BUBBLE;
56
57         pSliderImpl = _SliderImpl::CreateSliderImplN(this, rect, sliderStyle);
58         r = GetLastResult();
59         SysTryReturn(NID_UI_CTRL, pSliderImpl != null, r, r, "[%s] Propagating.", GetErrorMessage(r));
60
61         r = pSliderImpl->Initialize(minValue, maxValue, backgroundStyle, sliderStyle, groupStyle);
62         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
63
64         _pControlImpl = pSliderImpl;
65
66         return r;
67
68 CATCH:
69         delete pSliderImpl;
70         pSliderImpl = null;
71
72         return r;
73 }
74
75 result
76 Slider::Construct(const FloatRectangle& rect, BackgroundStyle backgroundStyle, bool showTitle, int minValue, int maxValue, GroupStyle groupStyle)
77 {
78         result r = E_SUCCESS;
79
80         _SliderImpl* pSliderImpl = _SliderImpl::GetInstance(*this);
81         SysAssertf((pSliderImpl == null), "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class.");
82
83         int sliderStyle = 0;
84         if (showTitle)
85         {
86                 sliderStyle |= SLIDER_STYLE_TITLE;
87         }
88         sliderStyle |= SLIDER_STYLE_BUBBLE;
89
90         pSliderImpl = _SliderImpl::CreateSliderImplFN(this, rect, sliderStyle);
91         r = GetLastResult();
92         SysTryReturn(NID_UI_CTRL, pSliderImpl != null, r, r, "[%s] Propagating.", GetErrorMessage(r));
93
94         r = pSliderImpl->Initialize(minValue, maxValue, backgroundStyle, sliderStyle, groupStyle);
95         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
96
97         _pControlImpl = pSliderImpl;
98
99         return r;
100
101 CATCH:
102         delete pSliderImpl;
103         pSliderImpl = null;
104
105         return r;
106 }
107
108 result
109 Slider::Construct(const Rectangle& rect, unsigned long sliderStyle, int minValue, int maxValue)
110 {
111         result r = E_SUCCESS;
112
113         _SliderImpl* pSliderImpl = _SliderImpl::GetInstance(*this);
114         SysAssertf((pSliderImpl == null), "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class.");
115
116         pSliderImpl = _SliderImpl::CreateSliderImplN(this, rect, sliderStyle);
117         r = GetLastResult();
118         SysTryReturn(NID_UI_CTRL, pSliderImpl != null, r, r, "[%s] Propagating.", GetErrorMessage(r));
119
120         r = pSliderImpl->Initialize(minValue, maxValue, BACKGROUND_STYLE_DEFAULT, sliderStyle, GROUP_STYLE_NONE);
121         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
122
123         _pControlImpl = pSliderImpl;
124
125         return r;
126
127 CATCH:
128         delete pSliderImpl;
129         pSliderImpl = null;
130
131         return r;
132 }
133
134 result
135 Slider::Construct(const FloatRectangle& rect, unsigned long sliderStyle, int minValue, int maxValue)
136 {
137         result r = E_SUCCESS;
138
139         _SliderImpl* pSliderImpl = _SliderImpl::GetInstance(*this);
140         SysAssertf((pSliderImpl == null), "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class.");
141
142         pSliderImpl = _SliderImpl::CreateSliderImplFN(this, rect, sliderStyle);
143         r = GetLastResult();
144         SysTryReturn(NID_UI_CTRL, pSliderImpl != null, r, r, "[%s] Propagating.", GetErrorMessage(r));
145
146         r = pSliderImpl->Initialize(minValue, maxValue, BACKGROUND_STYLE_DEFAULT, sliderStyle, GROUP_STYLE_NONE);
147         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
148
149         _pControlImpl = pSliderImpl;
150
151         return r;
152
153 CATCH:
154         delete pSliderImpl;
155         pSliderImpl = null;
156
157         return r;
158 }
159
160 result
161 Slider::SetRange(int minValue, int maxValue)
162 {
163         _SliderImpl* pSliderImpl = _SliderImpl::GetInstance(*this);
164         SysAssertf(pSliderImpl != null, "Not yet constructed. Construct() should be called before use.");
165
166         result r = pSliderImpl->SetRange(minValue, maxValue);
167         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
168
169         return r;
170 }
171
172 void
173 Slider::GetRange(int& minValue, int& maxValue) const
174 {
175         const _SliderImpl* pSliderImpl = _SliderImpl::GetInstance(*this);
176         SysAssertf(pSliderImpl != null, "Not yet constructed. Construct() should be called before use.");
177
178         result r = pSliderImpl->GetRange(minValue, maxValue);
179         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
180
181         return;
182 }
183
184 void
185 Slider::SetValue(int value)
186 {
187         _SliderImpl* pSliderImpl = _SliderImpl::GetInstance(*this);
188         SysAssertf(pSliderImpl != null, "Not yet constructed. Construct() should be called before use.");
189
190         result r = pSliderImpl->SetValue(value);
191         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
192
193         return;
194 }
195
196 int
197 Slider::GetValue(void) const
198 {
199         const _SliderImpl* pSliderImpl = _SliderImpl::GetInstance(*this);
200         SysAssertf(pSliderImpl != null, "Not yet constructed. Construct() should be called before use.");
201
202         int value = pSliderImpl->GetValue();
203         result r = GetLastResult();
204         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, -1, r, "[%s] Propagating.", GetErrorMessage(r));
205
206         return value;
207 }
208
209 void
210 Slider::SetIcon(IconPosition position, const Bitmap& icon)
211 {
212         _SliderImpl* pSliderImpl = _SliderImpl::GetInstance(*this);
213         SysAssertf(pSliderImpl != null, "Not yet constructed. Construct() should be called before use.");
214
215         result r = pSliderImpl->SetIcon(position, icon);
216         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
217
218         return;
219 }
220
221 void
222 Slider::AddAdjustmentEventListener(IAdjustmentEventListener& listener)
223 {
224         _SliderImpl* pSliderImpl = _SliderImpl::GetInstance(*this);
225         SysAssertf(pSliderImpl != null, "Not yet constructed. Construct() should be called before use.");
226
227         result r = pSliderImpl->AddAdjustmentEventListener(listener);
228         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
229
230         return;
231 }
232
233 void
234 Slider::RemoveAdjustmentEventListener(IAdjustmentEventListener& listener)
235 {
236         _SliderImpl* pSliderImpl = _SliderImpl::GetInstance(*this);
237         SysAssertf(pSliderImpl != null, "Not yet constructed. Construct() should be called before use.");
238
239         result r = pSliderImpl->RemoveAdjustmentEventListener(listener);
240         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
241
242         return;
243 }
244
245 result
246 Slider::SetTitleText(const String& title)
247 {
248         _SliderImpl* pSliderImpl = _SliderImpl::GetInstance(*this);
249         SysAssertf(pSliderImpl != null, "Not yet constructed. Construct() should be called before use.");
250
251         result r = pSliderImpl->SetTitleText(title);
252         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
253
254         return r;
255 }
256
257 String
258 Slider::GetTitleText(void) const
259 {
260         const _SliderImpl* pSliderImpl = _SliderImpl::GetInstance(*this);
261         SysAssertf(pSliderImpl != null, "Not yet constructed. Construct() should be called before use.");
262
263         String string = pSliderImpl->GetTitleText();
264         result r = GetLastResult();
265         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, String(), r, "[%s] Propagating.", GetErrorMessage(r));
266
267         return string;
268 }
269
270 void
271 Slider::SetTitleTextColor(const Color& color)
272 {
273         _SliderImpl* pSliderImpl = _SliderImpl::GetInstance(*this);
274         SysAssertf(pSliderImpl != null, "Not yet constructed. Construct() should be called before use.");
275
276         result r = pSliderImpl->SetTitleTextColor(color);
277         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
278
279         return;
280 }
281
282 Color
283 Slider::GetTitleTextColor(void) const
284 {
285         const _SliderImpl* pSliderImpl = _SliderImpl::GetInstance(*this);
286         SysAssertf(pSliderImpl != null, "Not yet constructed. Construct() should be called before use.");
287
288         Color color = pSliderImpl->GetTitleTextColor();
289         result r = GetLastResult();
290         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, Color(), r, "[%s] Propagating.", GetErrorMessage(r));
291
292         return color;
293 }
294
295 void
296 Slider::AddSliderEventListener(ISliderEventListener& listener)
297 {
298         _SliderImpl* pSliderImpl = _SliderImpl::GetInstance(*this);
299         SysAssertf(pSliderImpl != null, "Not yet constructed. Construct() should be called before use.");
300
301         result r = pSliderImpl->AddSliderEventListener(listener);
302         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
303
304         return;
305 }
306
307 void
308 Slider::RemoveSliderEventListener(ISliderEventListener& listener)
309 {
310         _SliderImpl* pSliderImpl = _SliderImpl::GetInstance(*this);
311         SysAssertf(pSliderImpl != null, "Not yet constructed. Construct() should be called before use.");
312
313         result r = pSliderImpl->RemoveSliderEventListener(listener);
314         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
315
316         return;
317 }
318
319 result
320 Slider::SetBarColor(const Color& color)
321 {
322         _SliderImpl* pSliderImpl = _SliderImpl::GetInstance(*this);
323         SysAssertf(pSliderImpl != null, "Not yet constructed. Construct() should be called before use.");
324
325         result r = pSliderImpl->SetBarColor(color);
326         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
327
328         return r;
329 }
330
331 Color
332 Slider::GetBarColor(void) const
333 {
334         const _SliderImpl* pSliderImpl = _SliderImpl::GetInstance(*this);
335         SysAssertf(pSliderImpl != null, "Not yet constructed. Construct() should be called before use.");
336
337         Color color = pSliderImpl->GetBarColor();
338         result r = GetLastResult();
339         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, Color(), r, "[%s] Propagating.", GetErrorMessage(r));
340
341         return color;
342 }
343
344 void
345 Slider::SetBarBackgroundColor(const Color& color)
346 {
347         _SliderImpl* pSliderImpl = _SliderImpl::GetInstance(*this);
348         SysAssertf(pSliderImpl != null, "Not yet constructed. Construct() should be called before use.");
349
350         result r = pSliderImpl->SetBarBackgroundColor(color);
351         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
352
353         return;
354 }
355
356 Color
357 Slider::GetBarBackgroundColor(void) const
358 {
359         const _SliderImpl* pSliderImpl = _SliderImpl::GetInstance(*this);
360         SysAssertf(pSliderImpl != null, "Not yet constructed. Construct() should be called before use.");
361
362         Color color = pSliderImpl->GetBarBackgroundColor();
363         result r = GetLastResult();
364         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, Color(), r, "[%s] Propagating.", GetErrorMessage(r));
365
366         return color;
367 }
368
369 result
370 Slider::SetColor(const Color& color)
371 {
372         _SliderImpl* pSliderImpl = _SliderImpl::GetInstance(*this);
373         SysAssertf(pSliderImpl != null, "Not yet constructed. Construct() should be called before use.");
374
375         result r = pSliderImpl->SetColor(color);
376         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
377
378         return r;
379 }
380
381 Color
382 Slider::GetColor(void) const
383 {
384         const _SliderImpl* pSliderImpl = _SliderImpl::GetInstance(*this);
385         SysAssertf(pSliderImpl != null, "Not yet constructed. Construct() should be called before use.");
386
387         Color color = pSliderImpl->GetColor();
388         result r = GetLastResult();
389         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, Color(), r, "[%s] Propagating.", GetErrorMessage(r));
390
391         return color;
392 }
393
394 result
395 Slider::SetThumbBitmap(SliderThumbStatus status, const Bitmap& bitmap)
396 {
397         _SliderImpl* pSliderImpl = _SliderImpl::GetInstance(*this);
398         SysAssertf(pSliderImpl != null, "Not yet constructed. Construct() should be called before use.");
399
400         result r = pSliderImpl->SetThumbBitmap(status, bitmap);
401         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
402
403         return r;
404 }
405
406 void
407 Slider::SetThumbTextColor(SliderThumbStatus status, const Color& color)
408 {
409         _SliderImpl* pSliderImpl = _SliderImpl::GetInstance(*this);
410         SysAssertf(pSliderImpl != null, "Not yet constructed. Construct() should be called before use.");
411
412         pSliderImpl->SetThumbTextColor(status, color);
413
414         return;
415 }
416
417 }}} // Tizen::Ui::Controls