Fixed Jira issue N_SE-44828, N_SE-45077, N_SE-45140
[platform/framework/native/uifw.git] / src / ui / controls / FUiCtrl_Slider.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_Slider.cpp
20  * @brief       This is the implementation file for the _Slider class.
21  */
22
23 #include <stdio.h>
24 #include <FBaseSysLog.h>
25 #include <FBaseErrorDefine.h>
26 #include <FGrp_BitmapImpl.h>
27 #include "FUi_ResourceManager.h"
28 #include "FUi_AccessibilityContainer.h"
29 #include "FUi_AccessibilityElement.h"
30 #include "FUiAnim_VisualElement.h"
31 #include "FUiCtrl_Slider.h"
32 #include "FUiCtrl_SliderPresenter.h"
33 #include "FUiCtrl_IAdjustmentEventListener.h"
34 #include "FUiCtrl_ISliderEventListener.h"
35 #include "FUiCtrl_SliderOverlay.h"
36
37 using namespace Tizen::Ui;
38 using namespace Tizen::Base;
39 using namespace Tizen::Graphics;
40 using namespace Tizen::Ui::Animations;
41 using namespace Tizen::Base::Runtime;
42
43 namespace Tizen { namespace Ui { namespace Controls
44 {
45 IMPLEMENT_PROPERTY(_Slider);
46
47 _Slider::_Slider(void)
48         : __pSliderPresenter(null)
49         , __pAdjustmentEvent(null)
50         , __pSliderEvent(null)
51         , __titleText()
52         , __pLeftBitmap(null)
53         , __pRightBitmap(null)
54         , __bgColor()
55         , __barColor()
56         , __barBgColor()
57         , __titleTextColor()
58         , __sliderStyle(_SLIDER_STYLE_OVERLAY)
59         , __pBase(null)
60         , __pHandle(null)
61         , __pAccessibilityElement(null)
62         , __isKeyPressed(false)
63 {
64         __pBase = GetVisualElement();
65
66         if (__pBase != null)
67         {
68                 __pBase->SetSurfaceOpaque(false);
69                 __pBase->SetClipChildrenEnabled(false);
70         }
71
72         _AccessibilityContainer* pContainer = GetAccessibilityContainer();
73         if (pContainer)
74         {
75                 pContainer->Activate(true);
76         }
77 }
78
79 _Slider::~_Slider(void)
80 {
81         if (__pAdjustmentEvent != null)
82         {
83                 delete __pAdjustmentEvent;
84                 __pAdjustmentEvent = null;
85         }
86
87         if (__pSliderEvent != null)
88         {
89                 delete __pSliderEvent;
90                 __pSliderEvent = null;
91         }
92
93         delete __pLeftBitmap;
94         __pLeftBitmap = null;
95
96         delete __pRightBitmap;
97         __pRightBitmap = null;
98
99         delete __pSliderPresenter;
100         __pSliderPresenter = null;
101
102         if (__pAccessibilityElement)
103         {
104                 __pAccessibilityElement->Activate(false);
105                 __pAccessibilityElement = null;
106         }
107
108         if (__pBase != null && __pHandle != null)
109         {
110                 __pBase->DetachChild(*__pHandle);
111                 __pHandle->Destroy();
112         }
113
114         __pHandle = null;
115         __pBase = null;
116 }
117
118 _Slider*
119 _Slider::CreateSliderN(void)
120 {
121         result r = E_SUCCESS;
122
123         _Slider* pSlider = new (std::nothrow) _Slider;
124         SysTryReturn(NID_UI_CTRL, pSlider, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
125
126         pSlider->__pSliderPresenter = _SliderPresenter::CreateInstanceN(*pSlider);
127         r = GetLastResult();
128         SysTryCatch(NID_UI_CTRL, pSlider->__pSliderPresenter != null, , r, "[%s] Propagating.", GetErrorMessage(r));
129
130         r = pSlider->Initialize();
131         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
132
133         pSlider->AcquireHandle();
134
135         return pSlider;
136
137 CATCH:
138         delete pSlider;
139         pSlider = null;
140
141         return null;
142 }
143
144 result
145 _Slider::Initialize(void)
146 {
147         result r = E_SUCCESS;
148
149         FloatRectangle handleRect(0.0f, 0.0f, 0.0f, 0.0f);
150         _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
151
152         r = GET_COLOR_CONFIG(SLIDER::BG_DEFAULT_NORMAL, __bgColor);
153         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
154
155         r = GET_COLOR_CONFIG(SLIDER::BAR_NORMAL, __barColor);
156         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
157
158         r = GET_COLOR_CONFIG(SLIDER::BAR_BG_NORMAL, __barBgColor);
159         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
160
161         r = GET_COLOR_CONFIG(SLIDER::TITLE_TEXT_NORMAL, __titleTextColor);
162         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
163
164         r = GET_SHAPE_CONFIG(SLIDER::HANDLE_WIDTH, orientation, handleRect.width);
165         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
166
167         r = GET_SHAPE_CONFIG(SLIDER::HANDLE_HEIGHT, orientation, handleRect.height);
168         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
169
170         __pHandle = new (std::nothrow) Tizen::Ui::Animations::_VisualElement;
171         SysTryReturn(NID_UI_CTRL, __pHandle != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
172
173         r = __pHandle->Construct();
174         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
175
176         __pHandle->SetBounds(FloatRectangle(handleRect.x, handleRect.y, handleRect.width, handleRect.height));
177
178         __pHandle->SetShowState(true);
179
180         __pBase->SetClipChildrenEnabled(true);
181         __pHandle->SetClipToParent(true);
182
183
184         r = __pHandle->SetSurfaceOpaque(false);
185         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
186
187         __pHandle->SetImplicitAnimationEnabled(false);
188
189         r = __pBase->AttachChild(*__pHandle);
190         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
191
192         __pAdjustmentEvent = _AdjustmentEvent::CreateInstanceN(*this);
193         r = GetLastResult();
194         SysTryReturn(NID_UI_CTRL, __pAdjustmentEvent, r, r, "[%s] Propagating.", GetErrorMessage(r));
195
196         __pSliderEvent = _SliderEvent::CreateInstanceN(*this);
197         r = GetLastResult();
198         SysTryReturn(NID_UI_CTRL, __pSliderEvent, r, r, "[%s] Propagating.", GetErrorMessage(r));
199
200         InitializeAccessibilityElement();
201
202         return r;
203 }
204
205 result
206 _Slider::InitializeAccessibilityElement(void)
207 {
208         result r = E_SUCCESS;
209
210         if (__pAccessibilityElement)
211         {
212                 return r;
213         }
214
215         _AccessibilityContainer* pContainer = GetAccessibilityContainer();
216         if (pContainer)
217         {
218                 __pAccessibilityElement = new (std::nothrow) _AccessibilityElement(true);
219                 SysTryReturn(NID_UI_CTRL, __pAccessibilityElement, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
220                                         "[E_OUT_OF_MEMORY] Memory allocation failed.");
221                 __pAccessibilityElement->SetBounds(FloatRectangle(0.0f, 0.0f, GetBounds().width, GetBounds().height));
222                 __pAccessibilityElement->SetLabel(__titleText);
223                 __pAccessibilityElement->SetName(L"SliderControl");
224                 __pAccessibilityElement->SetTraitWithStringId("IDS_TPLATFORM_BODY_SLIDER_T_TTS");
225                 __pAccessibilityElement->SetHintWithStringId("IDS_TPLATFORM_BODY_FLICK_UP_AND_DOWN_TO_ADJUST_THE_POSITION_T_TTS");
226                 SetAccessibilityElementValue();
227                 r = pContainer->AddElement(*__pAccessibilityElement);
228                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
229                 pContainer->AddListener(*this);
230         }
231
232         return r;
233 }
234
235 void
236 _Slider::OnDraw(void)
237 {
238         __pSliderPresenter->Draw();
239         return;
240 }
241
242 result
243 _Slider::OnAttachedToMainTree(void)
244 {
245         return _Control::OnAttachedToMainTree();
246 }
247
248 void
249 _Slider::SetStyle(int style)
250 {
251         __sliderStyle = style;
252         return;
253 }
254
255 int
256 _Slider::GetStyle(void) const
257 {
258         return __sliderStyle;
259 }
260
261 Canvas*
262 _Slider::GetHandleCanvasN(void) const
263 {
264         return __pHandle->GetCanvasN();
265 }
266
267 _VisualElement*
268 _Slider::GetHandle(void) const
269 {
270         return __pHandle;
271 }
272
273 void
274 _Slider::SetGroupStyle(GroupStyle groupStyle)
275 {
276         __pSliderPresenter->SetGroupStyle(groupStyle);
277         return;
278 }
279
280 result
281 _Slider::UpdateHandle(const FloatRectangle& handleRect)
282 {
283         __pHandle->SetBounds(handleRect);
284
285         return __pHandle->SetFlushNeeded();
286 }
287
288 bool
289 _Slider::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
290 {
291         return __pSliderPresenter->OnTouchPressed(source, touchinfo);
292 }
293
294 bool
295 _Slider::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
296 {
297         return __pSliderPresenter->OnTouchReleased(source, touchinfo);
298 }
299
300 bool
301 _Slider::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
302 {
303         return __pSliderPresenter->OnTouchMoved(source, touchinfo);
304 }
305
306 bool
307 _Slider::OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
308 {
309         return __pSliderPresenter->OnTouchCanceled(source, touchinfo);
310 }
311
312 void
313 _Slider::OnDrawFocus(void)
314 {
315         __pSliderPresenter->SetFocusMode(true);
316         Invalidate();
317
318         return;
319 }
320
321 bool
322 _Slider::OnFocusGained(const _Control& source)
323 {
324         __pSliderPresenter->SetFocusMode(true);
325         Invalidate();
326
327         return true;
328 }
329
330 bool
331 _Slider::OnFocusLost(const _Control& source)
332 {
333         __pSliderPresenter->SetFocusMode(false);
334         Invalidate();
335
336         return true;
337 }
338
339 void
340 _Slider::OnFocusModeStateChanged()
341 {
342         __pSliderPresenter->SetFocusMode(false);
343         Invalidate();
344 }
345
346 bool
347 _Slider::IsKeyPressed() const
348 {
349         return __isKeyPressed;
350 }
351
352 bool
353 _Slider::OnKeyPressed(const _Control& source, const _KeyInfo& keyInfo)
354 {
355         if(__pSliderPresenter->GetFocusMode() == false)
356         {
357                 return false;
358         }
359
360         _KeyCode keyCode = keyInfo.GetKeyCode();
361
362         if (keyCode == _KEY_RIGHT)
363         {
364                 SetValue(GetValue() + 1);
365                 FireSliderMoveEvent(GetValue());
366
367                 if (GetStyle() & _SLIDER_STYLE_OVERLAY)
368                 {
369                         _SliderOverlay* pSliderOverlay = __pSliderPresenter->GetSliderOverlay();
370                         pSliderOverlay->SetVisibleState(true);
371                         pSliderOverlay->Open();
372                         __isKeyPressed = true;
373                 }
374
375                 Invalidate();
376                 return true;
377         }
378
379         if (keyCode == _KEY_LEFT)
380         {
381                 SetValue(GetValue() - 1);
382                 FireSliderMoveEvent(GetValue());
383
384                 if (GetStyle() & _SLIDER_STYLE_OVERLAY)
385                 {
386                         _SliderOverlay* pSliderOverlay = __pSliderPresenter->GetSliderOverlay();
387                         pSliderOverlay->SetVisibleState(true);
388                         pSliderOverlay->Open();
389                         __isKeyPressed = true;
390                 }
391
392                 Invalidate();
393                 return true;
394         }
395
396         return false;
397 }
398
399 bool
400 _Slider::OnKeyReleased(const _Control &source, const _KeyInfo &keyInfo)
401 {
402         if(__pSliderPresenter->GetFocusMode() == false)
403         {
404                 return false;
405         }
406
407         _KeyCode keyCode = keyInfo.GetKeyCode();
408
409         if (keyCode == _KEY_LEFT || keyCode == _KEY_RIGHT)
410         {
411                 if (GetStyle() & _SLIDER_STYLE_OVERLAY)
412                 {
413                         _SliderOverlay* pSliderOverlay = __pSliderPresenter->GetSliderOverlay();
414                         pSliderOverlay->SetVisibleState(false);
415                         pSliderOverlay->Close();
416                 }
417
418                 FireAdjustmentValueEvent(GetValue());
419                 __isKeyPressed = false;
420
421                 Invalidate();
422                 return true;
423         }
424
425         return false;
426 }
427
428 void
429 _Slider::OnBoundsChanged(void)
430 {
431         __pSliderPresenter->OnBoundsChanged();
432
433         if (__pAccessibilityElement)
434         {
435                 __pAccessibilityElement->SetBounds(FloatRectangle(0.0f, 0.0f, GetBounds().width, GetBounds().height));
436         }
437
438         return;
439 }
440
441 void
442 _Slider::OnChangeLayout(_ControlOrientation orientation)
443 {
444         __pSliderPresenter->OnChangeLayout(orientation);
445         return;
446 }
447
448 result
449 _Slider::SetRange(int minValue, int maxValue)
450 {
451         result r = E_SUCCESS;
452
453         SysTryReturn(NID_UI_CTRL, (minValue >= _SLIDER_MINIMUM_VALUE && maxValue >= _SLIDER_MINIMUM_VALUE),
454                                 E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The minimum value %d is out of range [-99 to 999].", minValue);
455         SysTryReturn(NID_UI_CTRL, (minValue <= _SLIDER_MAXIMUM_VALUE && maxValue <= _SLIDER_MAXIMUM_VALUE),
456                                 E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The maximum value %d is out of range [-99 to 999].", maxValue);
457         SysTryReturn(NID_UI_CTRL, (minValue < maxValue), E_INVALID_ARG, E_INVALID_ARG,
458                                 "[E_INVALID_ARG] The minimum value is greater than maximum value.");
459
460         Variant oldMinValue = GetProperty("minValue");
461         Variant value = GetProperty("value");
462
463         r = SetProperty("minValue", Variant(minValue));
464         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Failed to set minimum value.", GetErrorMessage(r));
465
466         r = SetProperty("maxValue", Variant(maxValue));
467         if (r != E_SUCCESS)
468         {
469                 SysLogException(NID_UI_CTRL, r, "[%s] Failed to set maximum value.", GetErrorMessage(r));
470
471                 result nestedResult = SetPropertyMinValue(oldMinValue);
472                 if (nestedResult != E_SUCCESS)
473                 {
474                         SysLog(NID_UI_CTRL, "Failed to recover original minimum value");
475                         return r;
476                 }
477
478                 nestedResult = SetPropertyValue(value);
479                 if (nestedResult != E_SUCCESS)
480                 {
481                         SysLog(NID_UI_CTRL, "Failed to recover original value");
482                 }
483         }
484
485         SetAccessibilityElementValue();
486
487         return r;
488 }
489
490 result
491 _Slider::SetPropertyMinValue(const Variant& minValue)
492 {
493         result r = E_SUCCESS;
494
495         int tempMinValue = minValue.ToInt();
496         r = GetLastResult();
497         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
498
499         __pSliderPresenter->SetMinValue(tempMinValue);
500
501         return r;
502 }
503
504 result
505 _Slider::SetPropertyMaxValue(const Variant& maxValue)
506 {
507         result r = E_SUCCESS;
508
509         int tempMaxValue = maxValue.ToInt();
510         r = GetLastResult();
511         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
512
513         __pSliderPresenter->SetMaxValue(tempMaxValue);
514
515         return r;
516 }
517
518 result
519 _Slider::GetRange(int& minValue, int& maxValue) const
520 {
521         result r = E_SUCCESS;
522
523         Variant minimum = GetProperty("minValue");
524         r = GetLastResult();
525         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
526
527         Variant maximum = GetProperty("maxValue");
528         r = GetLastResult();
529         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
530
531         minValue = minimum.ToInt();
532         maxValue = maximum.ToInt();
533
534         return r;
535 }
536
537 Variant
538 _Slider::GetPropertyMinValue(void) const
539 {
540         return Variant(__pSliderPresenter->GetMinValue());
541 }
542
543 Variant
544 _Slider::GetPropertyMaxValue(void) const
545 {
546         return Variant(__pSliderPresenter->GetMaxValue());
547 }
548
549 result
550 _Slider::SetValue(int value)
551 {
552         return SetProperty("value", Variant(value));
553 }
554
555 result
556 _Slider::SetPropertyValue(const Variant& value)
557 {
558         result r = E_SUCCESS;
559
560         int tempValue = value.ToInt();
561         r = GetLastResult();
562         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
563
564         __pSliderPresenter->SetValue(tempValue);
565
566         SetAccessibilityElementValue();
567
568         return r;
569 }
570
571 void
572 _Slider::SetAccessibilityElementValue()
573 {
574         if (__pAccessibilityElement)
575         {
576         String string;
577         GET_STRING_CONFIG(IDS_TPLATFORM_BODY_POSITION_P1SD_OF_P2SD_T_TTS, string);
578         char buffer[10] = {0,};
579         sprintf(buffer, "%d", GetValue());
580         string.Replace(L"%1$d", buffer);
581         memset(buffer, 0, 10);
582         sprintf(buffer, "%d", __pSliderPresenter->GetMaxValue());
583         string.Replace(L"%2$d", buffer);
584         __pAccessibilityElement->SetValue(string);
585         }
586
587         return;
588 }
589 int
590 _Slider::GetValue(void) const
591 {
592         result r = E_SUCCESS;
593
594         Variant value = GetProperty("value");
595         r = GetLastResult();
596         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, -1, r, "[%s] Propagating.", GetErrorMessage(r));
597
598         return value.ToInt();
599 }
600
601 Variant
602 _Slider::GetPropertyValue(void) const
603 {
604         return Variant(__pSliderPresenter->GetValue());
605 }
606
607 result
608 _Slider::SetIcon(IconPosition position, const Bitmap& icon)
609 {
610         result r = E_SUCCESS;
611
612         float iconWidth = 0.0f;
613         float iconHeight = 0.0f;
614         _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
615         Bitmap* pNewBitmap = null;
616
617         r = GET_SHAPE_CONFIG(SLIDER::ICON_WIDTH, orientation, iconWidth);
618         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
619
620         r = GET_SHAPE_CONFIG(SLIDER::ICON_HEIGHT, orientation, iconHeight);
621         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
622
623         if (position == ICON_POSITION_LEFT)
624         {
625                 pNewBitmap = _BitmapImpl::CloneN(icon);
626
627                 r = GetLastResult();
628                 SysTryReturn(NID_UI_CTRL, pNewBitmap != null, r, r, "[%s] Propagating.", GetErrorMessage(r));
629
630                 r = pNewBitmap->Scale(Dimension(iconWidth, iconHeight));
631                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
632
633                 delete __pLeftBitmap;
634                 __pLeftBitmap = pNewBitmap;
635
636         }
637         else //(position == ICON_POSITION_RIGHT)
638         {
639                 pNewBitmap = _BitmapImpl::CloneN(icon);
640
641                 r = GetLastResult();
642                 SysTryReturn(NID_UI_CTRL, pNewBitmap != null, r, r, "[%s] Propagating.", GetErrorMessage(r));
643
644                 r = pNewBitmap->Scale(Dimension(iconWidth, iconHeight));
645                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
646
647                 delete __pRightBitmap;
648                 __pRightBitmap = pNewBitmap;
649
650         }
651
652         __pSliderPresenter->SetNeedUpdate();
653
654         return E_SUCCESS;
655 CATCH:
656         delete pNewBitmap;
657         pNewBitmap = null;
658
659         return E_SYSTEM;
660 }
661
662 Bitmap*
663 _Slider::GetIcon(IconPosition position) const
664 {
665         if (position == ICON_POSITION_LEFT)
666         {
667                 return __pLeftBitmap;
668         }
669         else //(position == ICON_POSITION_RIGHT)
670         {
671                 return __pRightBitmap;
672         }
673 }
674
675 result
676 _Slider::SetTitleText(const String& title)
677 {
678         return SetProperty("titleText", Variant(title));
679 }
680
681 result
682 _Slider::SetPropertyTitleText(const Variant& titleText)
683 {
684         result r = E_SUCCESS;
685         String title = titleText.ToString();
686
687         if (!(GetStyle() & _SLIDER_STYLE_TITLE_TEXT))
688         {
689                 SysLogException(NID_UI_CTRL, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The current Slider style does not support title text.");
690                 return E_SYSTEM;
691         }
692
693         __titleText = title;
694         __pSliderPresenter->SetNeedUpdate();
695
696         r = InitializeAccessibilityElement();
697         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
698
699         if (__pAccessibilityElement != null)
700         {
701                 __pAccessibilityElement->SetLabel(__titleText);
702         }
703
704         return r;
705 }
706
707 String
708 _Slider::GetTitleText(void) const
709 {
710         result r = E_SUCCESS;
711
712         Variant titleText = GetProperty("titleText");
713         r = GetLastResult();
714         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, String(), r, "[%s] Propagating.", GetErrorMessage(r));
715
716         return titleText.ToString();
717 }
718
719 Variant
720 _Slider::GetPropertyTitleText(void) const
721 {
722         return Variant(__titleText);
723 }
724
725 result
726 _Slider::SetTitleTextColor(const Color& color)
727 {
728         return SetProperty("titleTextColor", Variant(color));
729 }
730
731 result
732 _Slider::SetPropertyTitleTextColor(const Variant& titleTextColor)
733 {
734         result r = E_SUCCESS;
735
736         Color tempColor = titleTextColor.ToColor();
737         r = GetLastResult();
738         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
739
740         __titleTextColor = tempColor;
741         __pSliderPresenter->SetNeedUpdate();
742
743         return r;
744 }
745
746 Color
747 _Slider::GetTitleTextColor(void) const
748 {
749         result r = E_SUCCESS;
750
751         Variant titleTexColor = GetProperty("titleTextColor");
752         r = GetLastResult();
753         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, Color(), r, "[%s] Propagating.", GetErrorMessage(r));
754
755         return titleTexColor.ToColor();
756 }
757
758 Variant
759 _Slider::GetPropertyTitleTextColor(void) const
760 {
761         return Variant(__titleTextColor);
762 }
763
764 result
765 _Slider::AddAdjustmentEventListener(const _IAdjustmentEventListener& listener)
766 {
767         return  __pAdjustmentEvent->AddListener(listener);
768 }
769
770 result
771 _Slider::RemoveAdjustmentEventListener(const _IAdjustmentEventListener& listener)
772 {
773         return __pAdjustmentEvent->RemoveListener(listener);
774 }
775
776 result
777 _Slider::AddSliderEventListener(const _ISliderEventListener& listener)
778 {
779         return __pSliderEvent->AddListener(listener);
780 }
781
782 result
783 _Slider::RemoveSliderEventListener(const _ISliderEventListener& listener)
784 {
785         return __pSliderEvent->RemoveListener(listener);
786 }
787
788 result
789 _Slider::SetBarColor(const Color& color)
790 {
791         return SetProperty("barColor", Variant(color));
792 }
793
794 result
795 _Slider::SetPropertyBarColor(const Variant& barColor)
796 {
797         result r = E_SUCCESS;
798
799         Color tempBarColor = barColor.ToColor();
800         r = GetLastResult();
801         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
802
803         __barColor = tempBarColor;
804         __barColor.SetAlpha(0xFF);
805
806         __pSliderPresenter->SetNeedUpdate();
807
808         return r;
809 }
810
811 Color
812 _Slider::GetBarColor(void) const
813 {
814         result r = E_SUCCESS;
815
816         Variant barColor = GetProperty("barColor");
817         r = GetLastResult();
818         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, Color(), r, "[%s] Propagating.", GetErrorMessage(r));
819
820         return barColor.ToColor();
821 }
822
823 Variant
824 _Slider::GetPropertyBarColor(void) const
825 {
826         return Variant(__barColor);
827 }
828
829 result
830 _Slider::SetBarBackgroundColor(const Color& color)
831 {
832         return SetProperty("barBackgroundColor", Variant(color));
833 }
834
835 result
836 _Slider::SetPropertyBarBackgroundColor(const Variant& barBackgroundColor)
837 {
838         result r = E_SUCCESS;
839
840         Color tempBarBackgroundColor = barBackgroundColor.ToColor();
841         r = GetLastResult();
842         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
843
844         __barBgColor = tempBarBackgroundColor;
845         __barBgColor.SetAlpha(0xFF);
846
847         __pSliderPresenter->SetNeedUpdate();
848
849         return r;
850 }
851
852 Color
853 _Slider::GetBarBackgroundColor(void) const
854 {
855         result r = E_SUCCESS;
856
857         Variant barBgColor = GetProperty("barBackgroundColor");
858         r = GetLastResult();
859         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, Color(), r, "[%s] Propagating.", GetErrorMessage(r));
860
861         return barBgColor.ToColor();
862 }
863
864 Variant
865 _Slider::GetPropertyBarBackgroundColor(void) const
866 {
867         return Variant(__barBgColor);
868 }
869
870 result
871 _Slider::SetColor(const Color& color)
872 {
873         return SetProperty("color", Variant(color));
874 }
875
876 result
877 _Slider::SetPropertyColor(const Variant& color)
878 {
879         if (__sliderStyle & _SLIDER_STYLE_NO_BG)
880         {
881                 SysLogException(NID_UI_CTRL, E_INVALID_OPERATION, "[E_INVALID_OPERATION] The current Slider style does not support background color.");
882                 return E_INVALID_OPERATION;
883         }
884
885         result r = E_SUCCESS;
886
887         Color tempBgColor = color.ToColor();
888         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
889
890         __bgColor = tempBgColor;
891
892         __pSliderPresenter->SetNeedUpdate();
893
894         return r;
895 }
896
897 Color
898 _Slider::GetColor(void) const
899 {
900         result r = E_SUCCESS;
901
902         Variant color = GetProperty("color");
903         r = GetLastResult();
904         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, Color(), r, "[%s] Propagating.", GetErrorMessage(r));
905
906         return color.ToColor();
907 }
908
909 Variant
910 _Slider::GetPropertyColor(void) const
911 {
912         if (__sliderStyle & _SLIDER_STYLE_NO_BG)
913         {
914                 SysLogException(NID_UI_CTRL, E_INVALID_OPERATION, "[E_INVALID_OPERATION] The current Slider style does not support background color.");
915                 return Variant(Color());
916         }
917         else
918         {
919                 return Variant(__bgColor);
920         }
921 }
922
923 Tizen::Base::Runtime::_Event*
924 _Slider::GetAdjustmentEvent(void) const
925 {
926         return __pAdjustmentEvent;
927 }
928
929 _SliderEvent*
930 _Slider::GetSliderEvent(void) const
931 {
932         return __pSliderEvent;
933 }
934
935 result
936 _Slider::SetThumbBitmap(SliderThumbStatus status, const Bitmap& bitmap)
937 {
938         return __pSliderPresenter->SetThumbBitmap(status, bitmap);
939 }
940
941 void
942 _Slider::SetThumbTextColor(SliderThumbStatus status, const Color& color)
943 {
944         __pSliderPresenter->SetThumbTextColor(status, color);
945         return;
946 }
947
948 void
949 _Slider::OnFontChanged(Font* pFont)
950 {
951         __pSliderPresenter->OnFontChanged(pFont);
952         return;
953 }
954
955 void
956 _Slider::OnFontInfoRequested(unsigned long& style, float& size)
957 {
958         __pSliderPresenter->OnFontInfoRequested(style, size);
959         return;
960 }
961
962 void
963 _Slider::OnAncestorEnableStateChanged(const _Control& control)
964 {
965         __pSliderPresenter->OnAncestorEnableStateChanged(control);
966
967         return;
968 }
969
970 bool
971 _Slider::OnAccessibilityValueIncreased(const _AccessibilityContainer& control, const _AccessibilityElement& element)
972 {
973         if (GetEnableState() == false)
974         {
975                 return true;
976         }
977         SetValue(GetValue() + 1);
978         String string;
979         GET_STRING_CONFIG(IDS_TPLATFORM_BODY_POSITION_P1SD_OF_P2SD_T_TTS, string);
980         char buffer[10] = {0,};
981         sprintf(buffer, "%d", GetValue());
982         string.Replace(L"%1$d", buffer);
983         memset(buffer, 0, 10);
984         sprintf(buffer, "%d", __pSliderPresenter->GetMaxValue());
985         string.Replace(L"%2$d", buffer);
986         _AccessibilityManager::GetInstance()->ReadContent(string);
987
988         Invalidate();
989         FireSliderMoveEvent(GetValue());
990         FireAdjustmentValueEvent(GetValue());
991
992         return true;
993 }
994
995 bool
996 _Slider::OnAccessibilityValueDecreased(const _AccessibilityContainer& control, const _AccessibilityElement& element)
997 {
998         if (GetEnableState() == false)
999         {
1000                 return true;
1001         }
1002         SetValue(GetValue() - 1);
1003         String string;
1004         GET_STRING_CONFIG(IDS_TPLATFORM_BODY_POSITION_P1SD_OF_P2SD_T_TTS, string);
1005         char buffer[10] = {0,};
1006         sprintf(buffer, "%d", GetValue());
1007         string.Replace(L"%1$d", buffer);
1008         memset(buffer, 0, 10);
1009         sprintf(buffer, "%d", __pSliderPresenter->GetMaxValue());
1010         string.Replace(L"%2$d", buffer);
1011         _AccessibilityManager::GetInstance()->ReadContent(string);
1012
1013         Invalidate();
1014         FireSliderMoveEvent(GetValue());
1015         FireAdjustmentValueEvent(GetValue());
1016
1017         return true;
1018 }
1019
1020 void
1021 _Slider::FireSliderMoveEvent(int value)
1022 {
1023         if (__pSliderEvent != null)
1024         {
1025                 IEventArg* pEventArg = _SliderEvent::CreateSliderEventArgN(value);
1026
1027                 if( pEventArg == null)
1028                 {
1029                         return;
1030                 }
1031
1032                 __pSliderEvent->Fire(*pEventArg);
1033         }
1034 }
1035
1036 void
1037 _Slider::FireAdjustmentValueEvent(int adjustment)
1038 {
1039         if (__pAdjustmentEvent != null)
1040         {
1041                 IEventArg* pEventArg = _AdjustmentEvent::CreateAdjustmentEventArgN(adjustment);
1042                 if( pEventArg == null)
1043                 {
1044                         return;
1045                 }
1046
1047                 __pAdjustmentEvent->Fire(*pEventArg);
1048         }
1049 }
1050 }}} // Tizen::Ui::Controls