2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0/
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.
19 * @file FUiCtrl_SliderImpl.cpp
20 * @brief This is the implementation file for the _SliderImpl class.
23 #include <FApp_AppInfo.h>
24 #include <FBaseInternalTypes.h>
25 #include <FUiAccessibilityContainer.h>
26 #include <FUiAccessibilityElement.h>
27 #include "FUi_ResourceManager.h"
28 #include "FUi_ResourceSizeInfo.h"
29 #include "FUi_UiBuilder.h"
30 #include "FUiCtrl_SliderImpl.h"
31 #include "FUiCtrl_PublicAdjustmentEvent.h"
32 #include "FUiCtrl_PublicSliderEvent.h"
34 using namespace Tizen::Ui;
35 using namespace Tizen::Graphics;
36 using namespace Tizen::Base;
38 namespace Tizen { namespace Ui { namespace Controls
42 _SliderImpl::GetInstance(Slider& slider)
44 return static_cast<_SliderImpl*> (slider._pControlImpl);
48 _SliderImpl::GetInstance(const Slider& slider)
50 return static_cast<const _SliderImpl*> (slider._pControlImpl);
53 _SliderImpl::_SliderImpl(Slider* pPublic, _Slider* pCore)
54 : _ControlImpl(pPublic, pCore)
55 , __pPublicAdjustmentEvent(null)
56 , __pPublicSliderEvent(null)
60 _SliderImpl::~_SliderImpl(void)
62 if (__pPublicAdjustmentEvent != null)
64 delete __pPublicAdjustmentEvent;
65 __pPublicAdjustmentEvent = null;
68 if (__pPublicSliderEvent != null)
70 delete __pPublicSliderEvent;
71 __pPublicSliderEvent = null;
76 _SliderImpl::CreateSliderImplN(Slider* pControl, const Rectangle& rect, int sliderStyle)
82 r = FUNC_SIZE_INFO(Slider)(sliderStyle).CheckInitialSizeValid(Dimension(rect.width, rect.height), _CONTROL_ORIENTATION_PORTRAIT);
83 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
85 _Slider* pCore = _Slider::CreateSliderN();
87 SysTryReturn(NID_UI_CTRL, pCore != null, null, r, "[%s] Propagating.", GetErrorMessage(r));
89 _SliderImpl* pImpl = new (std::nothrow) _SliderImpl(pControl, pCore);
90 r = CheckConstruction(pCore, pImpl);
91 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
93 r = pImpl->InitializeBoundsProperties(FUNC_SIZE_INFO(Slider)(sliderStyle), rect, pCore->GetOrientation());
94 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
96 pImpl->__pPublicAdjustmentEvent = _PublicAdjustmentEvent::CreateInstanceN(*pControl);
97 SysTryCatch(NID_UI_CTRL, pImpl->__pPublicAdjustmentEvent != null, , E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to construct an AdjustmentEvent instance");
99 pImpl->__pPublicSliderEvent = _PublicSliderEvent::CreateInstanceN(*pControl);
100 SysTryCatch(NID_UI_CTRL, pImpl->__pPublicSliderEvent != null, , E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to construct a SliderEvent instance");
102 r = pCore->AddAdjustmentEventListener(*pImpl);
103 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
105 r = pCore->AddSliderEventListener(*pImpl);
106 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
118 _SliderImpl::CreateSliderImplFN(Slider* pControl, const FloatRectangle& rect, int sliderStyle)
122 result r = E_SUCCESS;
124 r = FUNC_SIZE_INFO(Slider)(sliderStyle).CheckInitialSizeValidF(FloatDimension(rect.width, rect.height), _CONTROL_ORIENTATION_PORTRAIT);
125 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
127 _Slider* pCore = _Slider::CreateSliderN();
129 SysTryReturn(NID_UI_CTRL, pCore != null, null, r, "[%s] Propagating.", GetErrorMessage(r));
131 _SliderImpl* pImpl = new (std::nothrow) _SliderImpl(pControl, pCore);
132 r = CheckConstruction(pCore, pImpl);
133 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
135 r = pImpl->InitializeBoundsPropertiesF(FUNC_SIZE_INFO(Slider)(sliderStyle), rect, pCore->GetOrientation());
136 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
138 pImpl->__pPublicAdjustmentEvent = _PublicAdjustmentEvent::CreateInstanceN(*pControl);
139 SysTryCatch(NID_UI_CTRL, pImpl->__pPublicAdjustmentEvent != null, , E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to construct an AdjustmentEvent instance");
141 pImpl->__pPublicSliderEvent = _PublicSliderEvent::CreateInstanceN(*pControl);
142 SysTryCatch(NID_UI_CTRL, pImpl->__pPublicSliderEvent != null, , E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to construct a SliderEvent instance");
144 r = pCore->AddAdjustmentEventListener(*pImpl);
145 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
147 r = pCore->AddSliderEventListener(*pImpl);
148 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
160 _SliderImpl::Initialize(int minValue, int maxValue, BackgroundStyle bgStyle, int sliderStyle, GroupStyle groupStyle)
164 result r = E_SUCCESS;
166 int style = _SLIDER_STYLE_NONE;
168 if (sliderStyle & SLIDER_STYLE_BUBBLE)
170 style |= _SLIDER_STYLE_OVERLAY;
173 if (bgStyle == BACKGROUND_STYLE_NONE)
175 SysTryReturn(NID_UI_CTRL, groupStyle == GROUP_STYLE_NONE, E_INVALID_OPERATION, E_INVALID_OPERATION,
176 "[E_INVALID_OPERATION] The current Slider style does not support given group style.");
178 style |= _SLIDER_STYLE_NO_BG;
180 if (sliderStyle & SLIDER_STYLE_TITLE)
182 style |= _SLIDER_STYLE_TITLE_TEXT;
185 r = SetRange(minValue, maxValue);
186 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
188 GetCore().SetStyle(style);
189 GetCore().SetGroupStyle(groupStyle);
195 _SliderImpl::SetRange(int minValue, int maxValue)
199 return GetCore().SetRange(minValue, maxValue);
203 _SliderImpl::GetRange(int& minValue, int& maxValue) const
207 return GetCore().GetRange(minValue, maxValue);
211 _SliderImpl::SetValue(int value)
215 Variant varValue(value);
217 return GetCore().SetPropertyValue(varValue);
221 _SliderImpl::GetValue(void) const
225 return GetCore().GetPropertyValue().ToInt();
229 _SliderImpl::SetIcon(IconPosition position, const Bitmap& icon)
233 return GetCore().SetIcon(position, icon);
237 _SliderImpl::SetTitleText(const String& title)
241 Variant varTitleText(title);
243 return GetCore().SetPropertyTitleText(varTitleText);
247 _SliderImpl::GetTitleText(void) const
251 return GetCore().GetPropertyTitleText().ToString();
255 _SliderImpl::SetTitleTextColor(const Color& color)
259 Variant varTitleTextColor(color);
261 return GetCore().SetPropertyTitleTextColor(varTitleTextColor);
265 _SliderImpl::GetTitleTextColor(void) const
269 return GetCore().GetPropertyTitleTextColor().ToColor();
273 _SliderImpl::AddAdjustmentEventListener(IAdjustmentEventListener& listener)
277 result r = __pPublicAdjustmentEvent->AddListener(listener);
278 SysTryReturnResult(NID_UI_CTRL, r != E_OBJ_ALREADY_EXIST, E_SYSTEM, "A system error has occurred. The IAdjustmentEventListener instance already exists in the event listener list.");
284 _SliderImpl::RemoveAdjustmentEventListener(IAdjustmentEventListener& listener)
288 result r = __pPublicAdjustmentEvent->RemoveListener(listener);
289 SysTryReturnResult(NID_UI_CTRL, r != E_OBJ_NOT_FOUND, E_SYSTEM, "A system error has occurred. The IAdjustmentEventListener instance does not exist");
295 _SliderImpl::AddSliderEventListener(const ISliderEventListener& listener)
299 result r = __pPublicSliderEvent->AddListener(listener);
300 SysTryReturnResult(NID_UI_CTRL, r != E_OBJ_ALREADY_EXIST, E_SYSTEM, "A system error has occurred. The ISliderEventListener instance already exists in the event listener list.");
306 _SliderImpl::RemoveSliderEventListener(const ISliderEventListener& listener)
310 result r = __pPublicSliderEvent->RemoveListener(listener);
311 SysTryReturnResult(NID_UI_CTRL, r != E_OBJ_NOT_FOUND, E_SYSTEM, "A system error has occurred. The ISliderEventListener does not exist in the event listener list.");
317 _SliderImpl::SetBarColor(const Color& color)
321 Variant varBarColor(color);
323 return GetCore().SetPropertyBarColor(varBarColor);
327 _SliderImpl::GetBarColor(void) const
331 return GetCore().GetPropertyBarColor().ToColor();
335 _SliderImpl::SetBarBackgroundColor(const Color& color)
339 Variant varBarBackgroundColor(color);
341 return GetCore().SetPropertyBarBackgroundColor(varBarBackgroundColor);
345 _SliderImpl::GetBarBackgroundColor(void) const
349 return GetCore().GetPropertyBarBackgroundColor().ToColor();
353 _SliderImpl::SetColor(const Color& color)
357 Variant varColor(color);
359 return GetCore().SetPropertyColor(varColor);
363 _SliderImpl::GetColor(void) const
367 return GetCore().GetPropertyColor().ToColor();
371 _SliderImpl::SetThumbBitmap(SliderThumbStatus status, const Bitmap& bitmap)
375 return GetCore().SetThumbBitmap(status, bitmap);
379 _SliderImpl::SetThumbTextColor(SliderThumbStatus status, const Color& color)
383 GetCore().SetThumbTextColor(status, color);
389 _SliderImpl::GetPublicClassName(void) const
391 return "Tizen::Ui::Controls::Slider";
395 _SliderImpl::GetPublic(void) const
397 return static_cast <const Slider&>(_ControlImpl::GetPublic());
401 _SliderImpl::GetPublic(void)
403 return static_cast <Slider&>(_ControlImpl::GetPublic());
407 _SliderImpl::GetCore(void) const
409 return static_cast <const _Slider&>(_ControlImpl::GetCore());
413 _SliderImpl::GetCore(void)
415 return static_cast <_Slider&>(_ControlImpl::GetCore());
419 _SliderImpl::OnAdjustmentValueChanged(const _Control& source, int adjustment)
423 Runtime::IEventArg* pEventArg = _PublicAdjustmentEvent::CreateAdjustmentEventArgN(adjustment);
424 result r = GetLastResult();
425 SysTryReturnVoidResult(NID_UI_CTRL, pEventArg != null, r, "[%s] Propagating.", GetErrorMessage(r));
427 __pPublicAdjustmentEvent->Fire(*pEventArg);
432 _SliderImpl::OnSliderBarMoved(_Slider& source, int value)
436 Runtime::IEventArg* pEventArg = _PublicSliderEvent::CreateSliderEventArgN(value);
437 result r = GetLastResult();
438 SysTryReturnVoidResult(NID_UI_CTRL, pEventArg != null, r, "[%s] Propagating.", GetErrorMessage(r));
440 __pPublicSliderEvent->Fire(*pEventArg);
445 : public _UiBuilderControlMaker
448 _SliderMaker(_UiBuilder* pUiBuilder)
449 : _UiBuilderControlMaker(pUiBuilder){}
450 virtual ~_SliderMaker(void){}
452 static _UiBuilderControlMaker*
453 GetInstance(_UiBuilder* pUiBuilder)
455 _SliderMaker* pSliderMaker = new (std::nothrow) _SliderMaker(pUiBuilder);
461 Make(_UiBuilderControl* pControl)
463 result r = E_SUCCESS;
464 _UiBuilderControlLayout* pControlProperty = null;
465 Slider* pSlider = null;
466 Tizen::Base::String elementString;
467 Tizen::Base::String elementString1;
472 int sliderStyle = SLIDER_STYLE_NONE;
473 bool isShowTitle = false;
474 bool isGroupStyle = false;
475 BackgroundStyle backgroundStyleEnum = BACKGROUND_STYLE_DEFAULT;
476 GroupStyle groupStyleEmum = GROUP_STYLE_NONE;
482 GetProperty(pControl, &pControlProperty);
483 if (pControlProperty == null)
488 pSlider = new (std::nothrow) Slider;
493 rect = pControlProperty->GetRectF();
495 if (pControl->GetElement(L"backgroundStyle", elementString) || pControl->GetElement(L"BackgroundStyle", elementString))
497 if (elementString.Equals(L"BACKGROUND_STYLE_NONE", false))
499 backgroundStyleEnum = BACKGROUND_STYLE_NONE;
503 if (pControl->GetElement(L"showTitleText", elementString) || pControl->GetElement(L"bShowtitleText", elementString))
505 if (elementString.Equals(L"true", false))
511 if (pControl->GetElement(L"groupStyle", elementString) || pControl->GetElement(L"GroupStyle", elementString))
515 if (elementString.Equals(L"GROUP_STYLE_NONE", false))
517 groupStyleEmum = GROUP_STYLE_NONE;
519 if (elementString.Equals(L"GROUP_STYLE_SINGLE", false))
521 groupStyleEmum = GROUP_STYLE_SINGLE;
523 if (elementString.Equals(L"GROUP_STYLE_TOP", false))
525 groupStyleEmum = GROUP_STYLE_TOP;
527 if (elementString.Equals(L"GROUP_STYLE_MIDDLE", false))
529 groupStyleEmum = GROUP_STYLE_MIDDLE;
531 if (elementString.Equals(L"GROUP_STYLE_BOTTOM", false))
533 groupStyleEmum = GROUP_STYLE_BOTTOM;
536 if (isGroupStyle == true)
538 if (pControl->GetElement(L"min", elementString) && pControl->GetElement(L"max", elementString1))
540 Base::Integer::Parse(elementString, tempMin);
541 Base::Integer::Parse(elementString1, tempMax);
543 if (tempMin > tempMax)
550 r = pSlider->Construct(rect, backgroundStyleEnum, isShowTitle, tempMin, tempMax, groupStyleEmum);
554 r = pSlider->Construct(rect, backgroundStyleEnum, isShowTitle, 0, 10, groupStyleEmum);
560 if (pControl->GetElement(L"sliderStyleBubble", elementString))
562 if (elementString.Equals(L"true", false))
564 sliderStyle |= SLIDER_STYLE_BUBBLE;
568 if (pControl->GetElement(L"sliderStyleTitle", elementString))
570 if (elementString.Equals(L"true", false))
573 sliderStyle |= SLIDER_STYLE_TITLE;
577 if (pControl->GetElement(L"min", elementString) && pControl->GetElement(L"max", elementString1))
579 Base::Integer::Parse(elementString, tempMin);
580 Base::Integer::Parse(elementString1, tempMax);
582 if (tempMin > tempMax)
589 r = pSlider->Construct(rect, sliderStyle, tempMin, tempMax);
593 r = pSlider->Construct(rect, sliderStyle, 0, 10);
605 if (pControl->GetElement(L"value", elementString))
607 Base::Integer::Parse(elementString, temp);
608 if (temp > tempMax || temp < tempMin)
610 temp = (tempMin + tempMax) >> 1;
612 pSlider->SetValue(temp);
616 pSlider->SetValue((tempMin + tempMax) >> 1);
621 if (pControl->GetElement(L"titleText", elementString))
623 pSlider->SetTitleText(elementString);
625 if (pControl->GetElement(L"colorOfTitleText", elementString))
627 ConvertStringToColor(elementString, color);
628 pSlider->SetTitleTextColor(color);
632 if (pControl->GetElement(L"normalThumbBitmap", elementString))
634 Bitmap* pBitmap = null;
635 pBitmap = LoadBitmapN(elementString);
638 pSlider->SetThumbBitmap(SLIDER_THUMB_STATUS_NORMAL, *pBitmap);
644 if (pControl->GetElement(L"pressedThumbBitmap", elementString))
646 Bitmap* pBitmap = null;
647 pBitmap = LoadBitmapN(elementString);
650 pSlider->SetThumbBitmap(SLIDER_THUMB_STATUS_PRESSED, *pBitmap);
656 if (pControl->GetElement(L"disabledThumbBitmap", elementString))
658 Bitmap* pBitmap = null;
659 pBitmap = LoadBitmapN(elementString);
662 pSlider->SetThumbBitmap(SLIDER_THUMB_STATUS_DISABLED, *pBitmap);
668 if (pControl->GetElement(L"highlightedThumbBitmap", elementString))
670 Bitmap* pBitmap = null;
671 pBitmap = LoadBitmapN(elementString);
674 pSlider->SetThumbBitmap(SLIDER_THUMB_STATUS_HIGHLIGHTED, *pBitmap);
680 if (pControl->GetElement(L"leftIconBitmapPath", elementString))
682 Bitmap* pBitmap = null;
683 pBitmap = LoadBitmapN(elementString);
686 pSlider->SetIcon(ICON_POSITION_LEFT, *pBitmap);
692 if (pControl->GetElement(L"rightIconBitmapPath", elementString))
694 Bitmap* pBitmap = null;
695 pBitmap = LoadBitmapN(elementString);
698 pSlider->SetIcon(ICON_POSITION_RIGHT, *pBitmap);
704 if (pControl->GetElement(L"normalThumbTextColor", elementString))
706 ConvertStringToColor(elementString, color);
707 pSlider->SetThumbTextColor(SLIDER_THUMB_STATUS_NORMAL, color);
710 if (pControl->GetElement(L"pressedThumbTextColor", elementString))
712 ConvertStringToColor(elementString, color);
713 pSlider->SetThumbTextColor(SLIDER_THUMB_STATUS_PRESSED, color);
716 if (pControl->GetElement(L"disabledThumbTextColor", elementString))
718 ConvertStringToColor(elementString, color);
719 pSlider->SetThumbTextColor(SLIDER_THUMB_STATUS_DISABLED, color);
722 if (pControl->GetElement(L"highlightedThumbTextColor", elementString))
724 ConvertStringToColor(elementString, color);
725 pSlider->SetThumbTextColor(SLIDER_THUMB_STATUS_HIGHLIGHTED, color);
728 if (pControl->GetElement(L"barColor", elementString))
730 ConvertStringToColor(elementString, color);
731 pSlider->SetBarColor(color);
734 if (pControl->GetElement(L"barBackgroundColor", elementString))
736 ConvertStringToColor(elementString, color);
737 pSlider->SetBarBackgroundColor(color);
740 if (pControl->GetElement(L"colorOpacity", elementString))
742 Base::Integer::Parse(elementString, opacity);
744 if (pControl->GetElement(L"color", elementString))
746 ConvertStringToColor32(elementString, opacity, color);
747 pSlider->SetColor(color);
750 if (pControl->GetElement(L"accessibilityHint", elementString))
752 AccessibilityContainer* pContainer = pSlider->GetAccessibilityContainer();
755 AccessibilityElement* pElement = pContainer->GetElement(L"SliderControl");
758 pElement->SetHint(elementString);
768 _SliderRegister::_SliderRegister(void)
770 _UiBuilderControlTableManager* pUiBuilderControlTableManager = _UiBuilderControlTableManager::GetInstance();
771 pUiBuilderControlTableManager->RegisterControl(L"Slider", _SliderMaker::GetInstance);
773 _SliderRegister::~_SliderRegister(void)
775 _UiBuilderControlTableManager* pUiBuilderControlTableManager = _UiBuilderControlTableManager::GetInstance();
776 pUiBuilderControlTableManager->UnregisterControl(L"Slider");
778 static _SliderRegister SliderRegisterToUiBuilder;
779 }}} // Tizen::Ui::Controls