Changed indicator bg color.
[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
335         if ((GetStyle() & _SLIDER_STYLE_OVERLAY) && (!__pSliderPresenter->IsTouchPressed()) && (__isKeyPressed == true))
336         {
337                 _SliderOverlay* pSliderOverlay = __pSliderPresenter->GetSliderOverlay();
338                 pSliderOverlay->SetVisibleState(false);
339                 pSliderOverlay->Close();
340         }
341
342         __isKeyPressed = false;
343         Invalidate();
344
345         return true;
346 }
347
348 void
349 _Slider::OnFocusModeStateChanged()
350 {
351         __pSliderPresenter->SetFocusMode(false);
352         Invalidate();
353 }
354
355 bool
356 _Slider::IsKeyPressed() const
357 {
358         return __isKeyPressed;
359 }
360
361 bool
362 _Slider::OnKeyPressed(const _Control& source, const _KeyInfo& keyInfo)
363 {
364         if(__pSliderPresenter->GetFocusMode() == false)
365         {
366                 return false;
367         }
368
369         _KeyCode keyCode = keyInfo.GetKeyCode();
370
371         if (keyCode == _KEY_RIGHT)
372         {
373                 SetValue(GetValue() + 1);
374                 FireSliderMoveEvent(GetValue());
375
376                 if (GetStyle() & _SLIDER_STYLE_OVERLAY)
377                 {
378                         _SliderOverlay* pSliderOverlay = __pSliderPresenter->GetSliderOverlay();
379                         pSliderOverlay->SetVisibleState(true);
380                         pSliderOverlay->Open();
381                         __isKeyPressed = true;
382                 }
383
384                 Invalidate();
385                 return true;
386         }
387
388         if (keyCode == _KEY_LEFT)
389         {
390                 SetValue(GetValue() - 1);
391                 FireSliderMoveEvent(GetValue());
392
393                 if (GetStyle() & _SLIDER_STYLE_OVERLAY)
394                 {
395                         _SliderOverlay* pSliderOverlay = __pSliderPresenter->GetSliderOverlay();
396                         pSliderOverlay->SetVisibleState(true);
397                         pSliderOverlay->Open();
398                         __isKeyPressed = true;
399                 }
400
401                 Invalidate();
402                 return true;
403         }
404
405         return false;
406 }
407
408 bool
409 _Slider::OnKeyReleased(const _Control &source, const _KeyInfo &keyInfo)
410 {
411         if(__pSliderPresenter->GetFocusMode() == false)
412         {
413                 return false;
414         }
415
416         _KeyCode keyCode = keyInfo.GetKeyCode();
417
418         if (keyCode == _KEY_LEFT || keyCode == _KEY_RIGHT)
419         {
420                 if ((GetStyle() & _SLIDER_STYLE_OVERLAY) &&  (__isKeyPressed == true))
421                 {
422                         _SliderOverlay* pSliderOverlay = __pSliderPresenter->GetSliderOverlay();
423                         pSliderOverlay->SetVisibleState(false);
424                         pSliderOverlay->Close();
425                 }
426
427                 FireAdjustmentValueEvent(GetValue());
428                 __isKeyPressed = false;
429
430                 Invalidate();
431                 return true;
432         }
433
434         return false;
435 }
436
437 void
438 _Slider::OnBoundsChanged(void)
439 {
440         __pSliderPresenter->OnBoundsChanged();
441
442         if (__pAccessibilityElement)
443         {
444                 __pAccessibilityElement->SetBounds(FloatRectangle(0.0f, 0.0f, GetBounds().width, GetBounds().height));
445         }
446
447         return;
448 }
449
450 void
451 _Slider::OnChangeLayout(_ControlOrientation orientation)
452 {
453         __pSliderPresenter->OnChangeLayout(orientation);
454         return;
455 }
456
457 result
458 _Slider::SetRange(int minValue, int maxValue)
459 {
460         result r = E_SUCCESS;
461
462         SysTryReturn(NID_UI_CTRL, (minValue >= _SLIDER_MINIMUM_VALUE && maxValue >= _SLIDER_MINIMUM_VALUE),
463                                 E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The minimum value %d is out of range [-99 to 999].", minValue);
464         SysTryReturn(NID_UI_CTRL, (minValue <= _SLIDER_MAXIMUM_VALUE && maxValue <= _SLIDER_MAXIMUM_VALUE),
465                                 E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The maximum value %d is out of range [-99 to 999].", maxValue);
466         SysTryReturn(NID_UI_CTRL, (minValue < maxValue), E_INVALID_ARG, E_INVALID_ARG,
467                                 "[E_INVALID_ARG] The minimum value is greater than maximum value.");
468
469         Variant oldMinValue = GetProperty("minValue");
470         Variant value = GetProperty("value");
471
472         r = SetProperty("minValue", Variant(minValue));
473         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Failed to set minimum value.", GetErrorMessage(r));
474
475         r = SetProperty("maxValue", Variant(maxValue));
476         if (r != E_SUCCESS)
477         {
478                 SysLogException(NID_UI_CTRL, r, "[%s] Failed to set maximum value.", GetErrorMessage(r));
479
480                 result nestedResult = SetPropertyMinValue(oldMinValue);
481                 if (nestedResult != E_SUCCESS)
482                 {
483                         SysLog(NID_UI_CTRL, "Failed to recover original minimum value");
484                         return r;
485                 }
486
487                 nestedResult = SetPropertyValue(value);
488                 if (nestedResult != E_SUCCESS)
489                 {
490                         SysLog(NID_UI_CTRL, "Failed to recover original value");
491                 }
492         }
493
494         SetAccessibilityElementValue();
495
496         return r;
497 }
498
499 result
500 _Slider::SetPropertyMinValue(const Variant& minValue)
501 {
502         result r = E_SUCCESS;
503
504         int tempMinValue = minValue.ToInt();
505         r = GetLastResult();
506         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
507
508         __pSliderPresenter->SetMinValue(tempMinValue);
509
510         return r;
511 }
512
513 result
514 _Slider::SetPropertyMaxValue(const Variant& maxValue)
515 {
516         result r = E_SUCCESS;
517
518         int tempMaxValue = maxValue.ToInt();
519         r = GetLastResult();
520         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
521
522         __pSliderPresenter->SetMaxValue(tempMaxValue);
523
524         return r;
525 }
526
527 result
528 _Slider::GetRange(int& minValue, int& maxValue) const
529 {
530         result r = E_SUCCESS;
531
532         Variant minimum = GetProperty("minValue");
533         r = GetLastResult();
534         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
535
536         Variant maximum = GetProperty("maxValue");
537         r = GetLastResult();
538         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
539
540         minValue = minimum.ToInt();
541         maxValue = maximum.ToInt();
542
543         return r;
544 }
545
546 Variant
547 _Slider::GetPropertyMinValue(void) const
548 {
549         return Variant(__pSliderPresenter->GetMinValue());
550 }
551
552 Variant
553 _Slider::GetPropertyMaxValue(void) const
554 {
555         return Variant(__pSliderPresenter->GetMaxValue());
556 }
557
558 result
559 _Slider::SetValue(int value)
560 {
561         return SetProperty("value", Variant(value));
562 }
563
564 result
565 _Slider::SetPropertyValue(const Variant& value)
566 {
567         result r = E_SUCCESS;
568
569         int tempValue = value.ToInt();
570         r = GetLastResult();
571         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
572
573         __pSliderPresenter->SetValue(tempValue);
574
575         SetAccessibilityElementValue();
576
577         return r;
578 }
579
580 void
581 _Slider::SetAccessibilityElementValue()
582 {
583         if (__pAccessibilityElement)
584         {
585         String string;
586         GET_STRING_CONFIG(IDS_TPLATFORM_BODY_POSITION_P1SD_OF_P2SD_T_TTS, string);
587         char buffer[10] = {0,};
588         sprintf(buffer, "%d", GetValue());
589         string.Replace(L"%1$d", buffer);
590         memset(buffer, 0, 10);
591         sprintf(buffer, "%d", __pSliderPresenter->GetMaxValue());
592         string.Replace(L"%2$d", buffer);
593         __pAccessibilityElement->SetValue(string);
594         }
595
596         return;
597 }
598 int
599 _Slider::GetValue(void) const
600 {
601         result r = E_SUCCESS;
602
603         Variant value = GetProperty("value");
604         r = GetLastResult();
605         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, -1, r, "[%s] Propagating.", GetErrorMessage(r));
606
607         return value.ToInt();
608 }
609
610 Variant
611 _Slider::GetPropertyValue(void) const
612 {
613         return Variant(__pSliderPresenter->GetValue());
614 }
615
616 result
617 _Slider::SetIcon(IconPosition position, const Bitmap& icon)
618 {
619         result r = E_SUCCESS;
620
621         float iconWidth = 0.0f;
622         float iconHeight = 0.0f;
623         _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
624         Bitmap* pNewBitmap = null;
625
626         r = GET_SHAPE_CONFIG(SLIDER::ICON_WIDTH, orientation, iconWidth);
627         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
628
629         r = GET_SHAPE_CONFIG(SLIDER::ICON_HEIGHT, orientation, iconHeight);
630         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
631
632         if (position == ICON_POSITION_LEFT)
633         {
634                 pNewBitmap = _BitmapImpl::CloneN(icon);
635
636                 r = GetLastResult();
637                 SysTryReturn(NID_UI_CTRL, pNewBitmap != null, r, r, "[%s] Propagating.", GetErrorMessage(r));
638
639                 r = pNewBitmap->Scale(Dimension(iconWidth, iconHeight));
640                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
641
642                 delete __pLeftBitmap;
643                 __pLeftBitmap = pNewBitmap;
644
645         }
646         else //(position == ICON_POSITION_RIGHT)
647         {
648                 pNewBitmap = _BitmapImpl::CloneN(icon);
649
650                 r = GetLastResult();
651                 SysTryReturn(NID_UI_CTRL, pNewBitmap != null, r, r, "[%s] Propagating.", GetErrorMessage(r));
652
653                 r = pNewBitmap->Scale(Dimension(iconWidth, iconHeight));
654                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
655
656                 delete __pRightBitmap;
657                 __pRightBitmap = pNewBitmap;
658
659         }
660
661         __pSliderPresenter->SetNeedUpdate();
662
663         return E_SUCCESS;
664 CATCH:
665         delete pNewBitmap;
666         pNewBitmap = null;
667
668         return E_SYSTEM;
669 }
670
671 Bitmap*
672 _Slider::GetIcon(IconPosition position) const
673 {
674         if (position == ICON_POSITION_LEFT)
675         {
676                 return __pLeftBitmap;
677         }
678         else //(position == ICON_POSITION_RIGHT)
679         {
680                 return __pRightBitmap;
681         }
682 }
683
684 result
685 _Slider::SetTitleText(const String& title)
686 {
687         return SetProperty("titleText", Variant(title));
688 }
689
690 result
691 _Slider::SetPropertyTitleText(const Variant& titleText)
692 {
693         result r = E_SUCCESS;
694         String title = titleText.ToString();
695
696         if (!(GetStyle() & _SLIDER_STYLE_TITLE_TEXT))
697         {
698                 SysLogException(NID_UI_CTRL, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The current Slider style does not support title text.");
699                 return E_SYSTEM;
700         }
701
702         __titleText = title;
703         __pSliderPresenter->SetNeedUpdate();
704
705         r = InitializeAccessibilityElement();
706         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
707
708         if (__pAccessibilityElement != null)
709         {
710                 __pAccessibilityElement->SetLabel(__titleText);
711         }
712
713         return r;
714 }
715
716 String
717 _Slider::GetTitleText(void) const
718 {
719         result r = E_SUCCESS;
720
721         Variant titleText = GetProperty("titleText");
722         r = GetLastResult();
723         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, String(), r, "[%s] Propagating.", GetErrorMessage(r));
724
725         return titleText.ToString();
726 }
727
728 Variant
729 _Slider::GetPropertyTitleText(void) const
730 {
731         return Variant(__titleText);
732 }
733
734 result
735 _Slider::SetTitleTextColor(const Color& color)
736 {
737         return SetProperty("titleTextColor", Variant(color));
738 }
739
740 result
741 _Slider::SetPropertyTitleTextColor(const Variant& titleTextColor)
742 {
743         result r = E_SUCCESS;
744
745         Color tempColor = titleTextColor.ToColor();
746         r = GetLastResult();
747         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
748
749         __titleTextColor = tempColor;
750         __pSliderPresenter->SetNeedUpdate();
751
752         return r;
753 }
754
755 Color
756 _Slider::GetTitleTextColor(void) const
757 {
758         result r = E_SUCCESS;
759
760         Variant titleTexColor = GetProperty("titleTextColor");
761         r = GetLastResult();
762         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, Color(), r, "[%s] Propagating.", GetErrorMessage(r));
763
764         return titleTexColor.ToColor();
765 }
766
767 Variant
768 _Slider::GetPropertyTitleTextColor(void) const
769 {
770         return Variant(__titleTextColor);
771 }
772
773 result
774 _Slider::AddAdjustmentEventListener(const _IAdjustmentEventListener& listener)
775 {
776         return  __pAdjustmentEvent->AddListener(listener);
777 }
778
779 result
780 _Slider::RemoveAdjustmentEventListener(const _IAdjustmentEventListener& listener)
781 {
782         return __pAdjustmentEvent->RemoveListener(listener);
783 }
784
785 result
786 _Slider::AddSliderEventListener(const _ISliderEventListener& listener)
787 {
788         return __pSliderEvent->AddListener(listener);
789 }
790
791 result
792 _Slider::RemoveSliderEventListener(const _ISliderEventListener& listener)
793 {
794         return __pSliderEvent->RemoveListener(listener);
795 }
796
797 result
798 _Slider::SetBarColor(const Color& color)
799 {
800         return SetProperty("barColor", Variant(color));
801 }
802
803 result
804 _Slider::SetPropertyBarColor(const Variant& barColor)
805 {
806         result r = E_SUCCESS;
807
808         Color tempBarColor = barColor.ToColor();
809         r = GetLastResult();
810         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
811
812         __barColor = tempBarColor;
813         __barColor.SetAlpha(0xFF);
814
815         __pSliderPresenter->SetNeedUpdate();
816
817         return r;
818 }
819
820 Color
821 _Slider::GetBarColor(void) const
822 {
823         result r = E_SUCCESS;
824
825         Variant barColor = GetProperty("barColor");
826         r = GetLastResult();
827         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, Color(), r, "[%s] Propagating.", GetErrorMessage(r));
828
829         return barColor.ToColor();
830 }
831
832 Variant
833 _Slider::GetPropertyBarColor(void) const
834 {
835         return Variant(__barColor);
836 }
837
838 result
839 _Slider::SetBarBackgroundColor(const Color& color)
840 {
841         return SetProperty("barBackgroundColor", Variant(color));
842 }
843
844 result
845 _Slider::SetPropertyBarBackgroundColor(const Variant& barBackgroundColor)
846 {
847         result r = E_SUCCESS;
848
849         Color tempBarBackgroundColor = barBackgroundColor.ToColor();
850         r = GetLastResult();
851         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
852
853         __barBgColor = tempBarBackgroundColor;
854         __barBgColor.SetAlpha(0xFF);
855
856         __pSliderPresenter->SetNeedUpdate();
857
858         return r;
859 }
860
861 Color
862 _Slider::GetBarBackgroundColor(void) const
863 {
864         result r = E_SUCCESS;
865
866         Variant barBgColor = GetProperty("barBackgroundColor");
867         r = GetLastResult();
868         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, Color(), r, "[%s] Propagating.", GetErrorMessage(r));
869
870         return barBgColor.ToColor();
871 }
872
873 Variant
874 _Slider::GetPropertyBarBackgroundColor(void) const
875 {
876         return Variant(__barBgColor);
877 }
878
879 result
880 _Slider::SetColor(const Color& color)
881 {
882         return SetProperty("color", Variant(color));
883 }
884
885 result
886 _Slider::SetPropertyColor(const Variant& color)
887 {
888         if (__sliderStyle & _SLIDER_STYLE_NO_BG)
889         {
890                 SysLogException(NID_UI_CTRL, E_INVALID_OPERATION, "[E_INVALID_OPERATION] The current Slider style does not support background color.");
891                 return E_INVALID_OPERATION;
892         }
893
894         result r = E_SUCCESS;
895
896         Color tempBgColor = color.ToColor();
897         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
898
899         __bgColor = tempBgColor;
900
901         __pSliderPresenter->SetNeedUpdate();
902
903         return r;
904 }
905
906 Color
907 _Slider::GetColor(void) const
908 {
909         result r = E_SUCCESS;
910
911         Variant color = GetProperty("color");
912         r = GetLastResult();
913         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, Color(), r, "[%s] Propagating.", GetErrorMessage(r));
914
915         return color.ToColor();
916 }
917
918 Variant
919 _Slider::GetPropertyColor(void) const
920 {
921         if (__sliderStyle & _SLIDER_STYLE_NO_BG)
922         {
923                 SysLogException(NID_UI_CTRL, E_INVALID_OPERATION, "[E_INVALID_OPERATION] The current Slider style does not support background color.");
924                 return Variant(Color());
925         }
926         else
927         {
928                 return Variant(__bgColor);
929         }
930 }
931
932 Tizen::Base::Runtime::_Event*
933 _Slider::GetAdjustmentEvent(void) const
934 {
935         return __pAdjustmentEvent;
936 }
937
938 _SliderEvent*
939 _Slider::GetSliderEvent(void) const
940 {
941         return __pSliderEvent;
942 }
943
944 result
945 _Slider::SetThumbBitmap(SliderThumbStatus status, const Bitmap& bitmap)
946 {
947         return __pSliderPresenter->SetThumbBitmap(status, bitmap);
948 }
949
950 void
951 _Slider::SetThumbTextColor(SliderThumbStatus status, const Color& color)
952 {
953         __pSliderPresenter->SetThumbTextColor(status, color);
954         return;
955 }
956
957 void
958 _Slider::OnFontChanged(Font* pFont)
959 {
960         __pSliderPresenter->OnFontChanged(pFont);
961         return;
962 }
963
964 void
965 _Slider::OnFontInfoRequested(unsigned long& style, float& size)
966 {
967         __pSliderPresenter->OnFontInfoRequested(style, size);
968         return;
969 }
970
971 void
972 _Slider::OnAncestorEnableStateChanged(const _Control& control)
973 {
974         __pSliderPresenter->OnAncestorEnableStateChanged(control);
975
976         return;
977 }
978
979 bool
980 _Slider::OnAccessibilityValueIncreased(const _AccessibilityContainer& control, const _AccessibilityElement& element)
981 {
982         if (GetEnableState() == false)
983         {
984                 return true;
985         }
986         SetValue(GetValue() + 1);
987         String string;
988         GET_STRING_CONFIG(IDS_TPLATFORM_BODY_POSITION_P1SD_OF_P2SD_T_TTS, string);
989         char buffer[10] = {0,};
990         sprintf(buffer, "%d", GetValue());
991         string.Replace(L"%1$d", buffer);
992         memset(buffer, 0, 10);
993         sprintf(buffer, "%d", __pSliderPresenter->GetMaxValue());
994         string.Replace(L"%2$d", buffer);
995         _AccessibilityManager::GetInstance()->ReadContent(string);
996
997         Invalidate();
998         FireSliderMoveEvent(GetValue());
999         FireAdjustmentValueEvent(GetValue());
1000
1001         return true;
1002 }
1003
1004 bool
1005 _Slider::OnAccessibilityValueDecreased(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1006 {
1007         if (GetEnableState() == false)
1008         {
1009                 return true;
1010         }
1011         SetValue(GetValue() - 1);
1012         String string;
1013         GET_STRING_CONFIG(IDS_TPLATFORM_BODY_POSITION_P1SD_OF_P2SD_T_TTS, string);
1014         char buffer[10] = {0,};
1015         sprintf(buffer, "%d", GetValue());
1016         string.Replace(L"%1$d", buffer);
1017         memset(buffer, 0, 10);
1018         sprintf(buffer, "%d", __pSliderPresenter->GetMaxValue());
1019         string.Replace(L"%2$d", buffer);
1020         _AccessibilityManager::GetInstance()->ReadContent(string);
1021
1022         Invalidate();
1023         FireSliderMoveEvent(GetValue());
1024         FireAdjustmentValueEvent(GetValue());
1025
1026         return true;
1027 }
1028
1029 void
1030 _Slider::FireSliderMoveEvent(int value)
1031 {
1032         if (__pSliderEvent != null)
1033         {
1034                 IEventArg* pEventArg = _SliderEvent::CreateSliderEventArgN(value);
1035
1036                 if( pEventArg == null)
1037                 {
1038                         return;
1039                 }
1040
1041                 __pSliderEvent->Fire(*pEventArg);
1042         }
1043 }
1044
1045 void
1046 _Slider::FireAdjustmentValueEvent(int adjustment)
1047 {
1048         if (__pAdjustmentEvent != null)
1049         {
1050                 IEventArg* pEventArg = _AdjustmentEvent::CreateAdjustmentEventArgN(adjustment);
1051                 if( pEventArg == null)
1052                 {
1053                         return;
1054                 }
1055
1056                 __pAdjustmentEvent->Fire(*pEventArg);
1057         }
1058 }
1059 }}} // Tizen::Ui::Controls