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