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