Tizen 2.1 base
[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 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 /**
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 == true)
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 Rectangle& rect, unsigned long sliderStyle, int minValue, int maxValue)
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         pSliderImpl = _SliderImpl::CreateSliderImplN(this, rect, sliderStyle);
84         r = GetLastResult();
85         SysTryReturn(NID_UI_CTRL, pSliderImpl != null, r, r, "[%s] Propagating.", GetErrorMessage(r));
86
87         r = pSliderImpl->Initialize(minValue, maxValue, BACKGROUND_STYLE_DEFAULT, sliderStyle, GROUP_STYLE_NONE);
88         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
89
90         _pControlImpl = pSliderImpl;
91
92         return r;
93
94 CATCH:
95         delete pSliderImpl;
96         pSliderImpl = null;
97
98         return r;
99 }
100
101 result
102 Slider::SetRange(int minValue, int maxValue)
103 {
104         _SliderImpl* pSliderImpl = _SliderImpl::GetInstance(*this);
105         SysAssertf(pSliderImpl != null, "Not yet constructed. Construct() should be called before use.");
106
107         result r = pSliderImpl->SetRange(minValue, maxValue);
108         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
109
110         return r;
111 }
112
113 void
114 Slider::GetRange(int& minValue, int& maxValue) const
115 {
116         const _SliderImpl* pSliderImpl = _SliderImpl::GetInstance(*this);
117         SysAssertf(pSliderImpl != null, "Not yet constructed. Construct() should be called before use.");
118
119         result r = pSliderImpl->GetRange(minValue, maxValue);
120         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
121
122         return;
123 }
124
125 void
126 Slider::SetValue(int value)
127 {
128         _SliderImpl* pSliderImpl = _SliderImpl::GetInstance(*this);
129         SysAssertf(pSliderImpl != null, "Not yet constructed. Construct() should be called before use.");
130
131         result r = pSliderImpl->SetValue(value);
132         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
133
134         return;
135 }
136
137 int
138 Slider::GetValue(void) const
139 {
140         const _SliderImpl* pSliderImpl = _SliderImpl::GetInstance(*this);
141         SysAssertf(pSliderImpl != null, "Not yet constructed. Construct() should be called before use.");
142
143         int value = pSliderImpl->GetValue();
144         result r = GetLastResult();
145         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, -1, r, "[%s] Propagating.", GetErrorMessage(r));
146
147         return value;
148 }
149
150 void
151 Slider::SetIcon(IconPosition position, const Bitmap& icon)
152 {
153         _SliderImpl* pSliderImpl = _SliderImpl::GetInstance(*this);
154         SysAssertf(pSliderImpl != null, "Not yet constructed. Construct() should be called before use.");
155
156         result r = pSliderImpl->SetIcon(position, icon);
157         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
158
159         return;
160 }
161
162 void
163 Slider::AddAdjustmentEventListener(IAdjustmentEventListener& listener)
164 {
165         _SliderImpl* pSliderImpl = _SliderImpl::GetInstance(*this);
166         SysAssertf(pSliderImpl != null, "Not yet constructed. Construct() should be called before use.");
167
168         result r = pSliderImpl->AddAdjustmentEventListener(listener);
169         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
170
171         return;
172 }
173
174 void
175 Slider::RemoveAdjustmentEventListener(IAdjustmentEventListener& listener)
176 {
177         _SliderImpl* pSliderImpl = _SliderImpl::GetInstance(*this);
178         SysAssertf(pSliderImpl != null, "Not yet constructed. Construct() should be called before use.");
179
180         result r = pSliderImpl->RemoveAdjustmentEventListener(listener);
181         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
182
183         return;
184 }
185
186 result
187 Slider::SetTitleText(const String& title)
188 {
189         _SliderImpl* pSliderImpl = _SliderImpl::GetInstance(*this);
190         SysAssertf(pSliderImpl != null, "Not yet constructed. Construct() should be called before use.");
191
192         result r = pSliderImpl->SetTitleText(title);
193         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
194
195         return r;
196 }
197
198 String
199 Slider::GetTitleText(void) const
200 {
201         const _SliderImpl* pSliderImpl = _SliderImpl::GetInstance(*this);
202         SysAssertf(pSliderImpl != null, "Not yet constructed. Construct() should be called before use.");
203
204         String string = pSliderImpl->GetTitleText();
205         result r = GetLastResult();
206         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, String(), r, "[%s] Propagating.", GetErrorMessage(r));
207
208         return string;
209 }
210
211 void
212 Slider::SetTitleTextColor(const Color& color)
213 {
214         _SliderImpl* pSliderImpl = _SliderImpl::GetInstance(*this);
215         SysAssertf(pSliderImpl != null, "Not yet constructed. Construct() should be called before use.");
216
217         result r = pSliderImpl->SetTitleTextColor(color);
218         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
219
220         return;
221 }
222
223 Color
224 Slider::GetTitleTextColor(void) const
225 {
226         const _SliderImpl* pSliderImpl = _SliderImpl::GetInstance(*this);
227         SysAssertf(pSliderImpl != null, "Not yet constructed. Construct() should be called before use.");
228
229         Color color = pSliderImpl->GetTitleTextColor();
230         result r = GetLastResult();
231         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, Color(), r, "[%s] Propagating.", GetErrorMessage(r));
232
233         return color;
234 }
235
236 void
237 Slider::AddSliderEventListener(ISliderEventListener& listener)
238 {
239         _SliderImpl* pSliderImpl = _SliderImpl::GetInstance(*this);
240         SysAssertf(pSliderImpl != null, "Not yet constructed. Construct() should be called before use.");
241
242         result r = pSliderImpl->AddSliderEventListener(listener);
243         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
244
245         return;
246 }
247
248 void
249 Slider::RemoveSliderEventListener(ISliderEventListener& listener)
250 {
251         _SliderImpl* pSliderImpl = _SliderImpl::GetInstance(*this);
252         SysAssertf(pSliderImpl != null, "Not yet constructed. Construct() should be called before use.");
253
254         result r = pSliderImpl->RemoveSliderEventListener(listener);
255         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
256
257         return;
258 }
259
260 result
261 Slider::SetBarColor(const Color& color)
262 {
263         _SliderImpl* pSliderImpl = _SliderImpl::GetInstance(*this);
264         SysAssertf(pSliderImpl != null, "Not yet constructed. Construct() should be called before use.");
265
266         result r = pSliderImpl->SetBarColor(color);
267         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
268
269         return r;
270 }
271
272 Color
273 Slider::GetBarColor(void) const
274 {
275         const _SliderImpl* pSliderImpl = _SliderImpl::GetInstance(*this);
276         SysAssertf(pSliderImpl != null, "Not yet constructed. Construct() should be called before use.");
277
278         Color color = pSliderImpl->GetBarColor();
279         result r = GetLastResult();
280         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, Color(), r, "[%s] Propagating.", GetErrorMessage(r));
281
282         return color;
283 }
284
285 result
286 Slider::SetColor(const Color& color)
287 {
288         _SliderImpl* pSliderImpl = _SliderImpl::GetInstance(*this);
289         SysAssertf(pSliderImpl != null, "Not yet constructed. Construct() should be called before use.");
290
291         result r = pSliderImpl->SetColor(color);
292         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
293
294         return r;
295 }
296
297 Color
298 Slider::GetColor(void) const
299 {
300         const _SliderImpl* pSliderImpl = _SliderImpl::GetInstance(*this);
301         SysAssertf(pSliderImpl != null, "Not yet constructed. Construct() should be called before use.");
302
303         Color color = pSliderImpl->GetColor();
304         result r = GetLastResult();
305         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, Color(), r, "[%s] Propagating.", GetErrorMessage(r));
306
307         return color;
308 }
309
310 result
311 Slider::SetThumbBitmap(SliderThumbStatus status, const Bitmap& bitmap)
312 {
313         _SliderImpl* pSliderImpl = _SliderImpl::GetInstance(*this);
314         SysAssertf(pSliderImpl != null, "Not yet constructed. Construct() should be called before use.");
315
316         result r = pSliderImpl->SetThumbBitmap(status, bitmap);
317         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
318
319         return r;
320 }
321
322 void
323 Slider::SetThumbTextColor(SliderThumbStatus status, const Color& color)
324 {
325         _SliderImpl* pSliderImpl = _SliderImpl::GetInstance(*this);
326         SysAssertf(pSliderImpl != null, "Not yet constructed. Construct() should be called before use.");
327
328         pSliderImpl->SetThumbTextColor(status, color);
329
330         return;
331 }
332
333 }}} // Tizen::Ui::Controls