2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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.
18 * @file FUiCtrl_SliderImpl.cpp
19 * @brief This is the implementation file for the _SliderImpl class.
22 #include <FApp_AppInfo.h>
23 #include <FBaseInternalTypes.h>
24 #include "FUi_ResourceManager.h"
25 #include "FUi_ResourceSizeInfo.h"
26 #include "FUi_UiBuilder.h"
27 #include "FUiCtrl_SliderImpl.h"
28 #include "FUiCtrl_PublicAdjustmentEvent.h"
29 #include "FUiCtrl_PublicSliderEvent.h"
31 using namespace Tizen::Ui;
32 using namespace Tizen::Graphics;
33 using namespace Tizen::Base;
35 namespace Tizen { namespace Ui { namespace Controls
39 _SliderImpl::GetInstance(Slider& slider)
41 return static_cast<_SliderImpl*> (slider._pControlImpl);
45 _SliderImpl::GetInstance(const Slider& slider)
47 return static_cast<const _SliderImpl*> (slider._pControlImpl);
50 _SliderImpl::_SliderImpl(Slider* pPublic, _Slider* pCore)
51 : _ControlImpl(pPublic, pCore)
52 , __pPublicAdjustmentEvent(null)
53 , __pPublicSliderEvent(null)
57 _SliderImpl::~_SliderImpl(void)
59 if (__pPublicAdjustmentEvent != null)
61 delete __pPublicAdjustmentEvent;
62 __pPublicAdjustmentEvent = null;
65 if (__pPublicSliderEvent != null)
67 delete __pPublicSliderEvent;
68 __pPublicSliderEvent = null;
73 _SliderImpl::CreateSliderImplN(Slider* pControl, const Rectangle& rect, int sliderStyle)
79 r = FUNC_SIZE_INFO(Slider)(sliderStyle).CheckInitialSizeValid(Dimension(rect.width, rect.height), _CONTROL_ORIENTATION_PORTRAIT);
80 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
82 _Slider* pCore = _Slider::CreateSliderN();
84 SysTryReturn(NID_UI_CTRL, pCore != null, null, r, "[%s] Propagating.", GetErrorMessage(r));
86 _SliderImpl* pImpl = new (std::nothrow) _SliderImpl(pControl, pCore);
87 r = CheckConstruction(pCore, pImpl);
88 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
90 r = pImpl->InitializeBoundsProperties(FUNC_SIZE_INFO(Slider)(sliderStyle), rect, pCore->GetOrientation());
91 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
93 pImpl->__pPublicAdjustmentEvent = _PublicAdjustmentEvent::CreateInstanceN(*pControl);
94 SysTryCatch(NID_UI_CTRL, pImpl->__pPublicAdjustmentEvent != null, , E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to construct an AdjustmentEvent instance");
96 pImpl->__pPublicSliderEvent = _PublicSliderEvent::CreateInstanceN(*pControl);
97 SysTryCatch(NID_UI_CTRL, pImpl->__pPublicSliderEvent != null, , E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to construct a SliderEvent instance");
99 r = pCore->AddAdjustmentEventListener(*pImpl);
100 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
102 r = pCore->AddSliderEventListener(*pImpl);
103 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
115 _SliderImpl::Initialize(int minValue, int maxValue, BackgroundStyle bgStyle, int sliderStyle, GroupStyle groupStyle)
119 result r = E_SUCCESS;
121 int style = _SLIDER_STYLE_NONE;
123 if (sliderStyle & SLIDER_STYLE_BUBBLE)
125 style |= _SLIDER_STYLE_OVERLAY;
128 if (bgStyle == BACKGROUND_STYLE_NONE)
130 SysTryReturn(NID_UI_CTRL, groupStyle == GROUP_STYLE_NONE, E_INVALID_OPERATION, E_INVALID_OPERATION,
131 "[E_INVALID_OPERATION] The current Slider style does not support given group style.");
133 style |= _SLIDER_STYLE_NO_BG;
135 if (sliderStyle & SLIDER_STYLE_TITLE)
137 style |= _SLIDER_STYLE_TITLE_TEXT;
140 r = SetRange(minValue, maxValue);
141 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
143 GetCore().SetStyle(style);
144 GetCore().SetGroupStyle(groupStyle);
150 _SliderImpl::SetRange(int minValue, int maxValue)
154 return GetCore().SetRange(minValue, maxValue);
158 _SliderImpl::GetRange(int& minValue, int& maxValue) const
162 return GetCore().GetRange(minValue, maxValue);
166 _SliderImpl::SetValue(int value)
170 Variant varValue(value);
172 return GetCore().SetPropertyValue(varValue);
176 _SliderImpl::GetValue(void) const
180 return GetCore().GetPropertyValue().ToInt();
184 _SliderImpl::SetIcon(IconPosition position, const Bitmap& icon)
188 return GetCore().SetIcon(position, icon);
192 _SliderImpl::SetTitleText(const String& title)
196 Variant varTitleText(title);
198 return GetCore().SetPropertyTitleText(varTitleText);
202 _SliderImpl::GetTitleText(void) const
206 return GetCore().GetPropertyTitleText().ToString();
210 _SliderImpl::SetTitleTextColor(const Color& color)
214 Variant varTitleTextColor(color);
216 return GetCore().SetPropertyTitleTextColor(varTitleTextColor);
220 _SliderImpl::GetTitleTextColor(void) const
224 return GetCore().GetPropertyTitleTextColor().ToColor();
228 _SliderImpl::AddAdjustmentEventListener(IAdjustmentEventListener& listener)
232 result r = __pPublicAdjustmentEvent->AddListener(listener);
233 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.");
239 _SliderImpl::RemoveAdjustmentEventListener(IAdjustmentEventListener& listener)
243 result r = __pPublicAdjustmentEvent->RemoveListener(listener);
244 SysTryReturnResult(NID_UI_CTRL, r != E_OBJ_NOT_FOUND, E_SYSTEM, "A system error has occurred. The IAdjustmentEventListener instance does not exist");
250 _SliderImpl::AddSliderEventListener(const ISliderEventListener& listener)
254 result r = __pPublicSliderEvent->AddListener(listener);
255 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.");
261 _SliderImpl::RemoveSliderEventListener(const ISliderEventListener& listener)
265 result r = __pPublicSliderEvent->RemoveListener(listener);
266 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.");
272 _SliderImpl::SetBarColor(const Color& color)
276 Variant varBarColor(color);
278 return GetCore().SetPropertyBarColor(varBarColor);
282 _SliderImpl::GetBarColor(void) const
286 return GetCore().GetPropertyBarColor().ToColor();
290 _SliderImpl::SetColor(const Color& color)
294 Variant varColor(color);
296 return GetCore().SetPropertyColor(varColor);
300 _SliderImpl::GetColor(void) const
304 return GetCore().GetPropertyColor().ToColor();
308 _SliderImpl::SetThumbBitmap(SliderThumbStatus status, const Bitmap& bitmap)
312 return GetCore().SetThumbBitmap(status, bitmap);
316 _SliderImpl::SetThumbTextColor(SliderThumbStatus status, const Color& color)
320 GetCore().SetThumbTextColor(status, color);
326 _SliderImpl::GetPublicClassName(void) const
328 return "Tizen::Ui::Controls::Slider";
332 _SliderImpl::GetPublic(void) const
334 return static_cast <const Slider&>(_ControlImpl::GetPublic());
338 _SliderImpl::GetPublic(void)
340 return static_cast <Slider&>(_ControlImpl::GetPublic());
344 _SliderImpl::GetCore(void) const
346 return static_cast <const _Slider&>(_ControlImpl::GetCore());
350 _SliderImpl::GetCore(void)
352 return static_cast <_Slider&>(_ControlImpl::GetCore());
356 _SliderImpl::OnAdjustmentValueChanged(const _Control& source, int adjustment)
360 Runtime::IEventArg* pEventArg = _PublicAdjustmentEvent::CreateAdjustmentEventArgN(adjustment);
361 result r = GetLastResult();
362 SysTryReturnVoidResult(NID_UI_CTRL, pEventArg != null, r, "[%s] Propagating.", GetErrorMessage(r));
364 __pPublicAdjustmentEvent->Fire(*pEventArg);
369 _SliderImpl::OnSliderBarMoved(_Slider& source, int value)
373 Runtime::IEventArg* pEventArg = _PublicSliderEvent::CreateSliderEventArgN(value);
374 result r = GetLastResult();
375 SysTryReturnVoidResult(NID_UI_CTRL, pEventArg != null, r, "[%s] Propagating.", GetErrorMessage(r));
377 __pPublicSliderEvent->Fire(*pEventArg);
382 : public _UiBuilderControlMaker
385 _SliderMaker(_UiBuilder* pUiBuilder)
386 : _UiBuilderControlMaker(pUiBuilder){}
387 virtual ~_SliderMaker(void){}
389 static _UiBuilderControlMaker*
390 GetInstance(_UiBuilder* pUiBuilder)
392 _SliderMaker* pSliderMaker = new (std::nothrow) _SliderMaker(pUiBuilder);
398 Make(_UiBuilderControl* pControl)
400 result r = E_SUCCESS;
401 _UiBuilderControlLayout* pControlProperty = null;
402 Slider* pSlider = null;
403 Tizen::Base::String elementString;
404 Tizen::Base::String elementString1;
409 int sliderStyle = SLIDER_STYLE_NONE;
410 bool isShowTitle = false;
411 bool isGroupStyle = false;
412 BackgroundStyle backgroundStyleEnum = BACKGROUND_STYLE_DEFAULT;
413 GroupStyle groupStyleEmum = GROUP_STYLE_NONE;
419 GetProperty(pControl, &pControlProperty);
420 if (pControlProperty == null)
425 pSlider = new (std::nothrow) Slider;
430 rect = pControlProperty->GetRect();
432 if (pControl->GetElement(L"backgroundStyle", elementString) || pControl->GetElement(L"BackgroundStyle", elementString))
434 if (elementString.Equals(L"BACKGROUND_STYLE_NONE", false))
436 backgroundStyleEnum = BACKGROUND_STYLE_NONE;
440 if (pControl->GetElement(L"showTitleText", elementString) || pControl->GetElement(L"bShowtitleText", elementString))
442 if (elementString.Equals(L"true", false))
448 if (pControl->GetElement(L"groupStyle", elementString) || pControl->GetElement(L"GroupStyle", elementString))
452 if (elementString.Equals(L"GROUP_STYLE_NONE", false))
454 groupStyleEmum = GROUP_STYLE_NONE;
456 if (elementString.Equals(L"GROUP_STYLE_SINGLE", false))
458 groupStyleEmum = GROUP_STYLE_SINGLE;
460 if (elementString.Equals(L"GROUP_STYLE_TOP", false))
462 groupStyleEmum = GROUP_STYLE_TOP;
464 if (elementString.Equals(L"GROUP_STYLE_MIDDLE", false))
466 groupStyleEmum = GROUP_STYLE_MIDDLE;
468 if (elementString.Equals(L"GROUP_STYLE_BOTTOM", false))
470 groupStyleEmum = GROUP_STYLE_BOTTOM;
473 if (isGroupStyle == true)
475 if (pControl->GetElement(L"min", elementString) && pControl->GetElement(L"max", elementString1))
477 Base::Integer::Parse(elementString, tempMin);
478 Base::Integer::Parse(elementString1, tempMax);
480 if (tempMin > tempMax)
487 r = pSlider->Construct(rect, backgroundStyleEnum, isShowTitle, tempMin, tempMax, groupStyleEmum);
491 r = pSlider->Construct(rect, backgroundStyleEnum, isShowTitle, 0, 10, groupStyleEmum);
497 if (pControl->GetElement(L"sliderStyleBubble", elementString))
499 if (elementString.Equals(L"true", false))
501 sliderStyle |= SLIDER_STYLE_BUBBLE;
505 if (pControl->GetElement(L"sliderStyleTitle", elementString))
507 if (elementString.Equals(L"true", false))
510 sliderStyle |= SLIDER_STYLE_TITLE;
514 if (pControl->GetElement(L"min", elementString) && pControl->GetElement(L"max", elementString1))
516 Base::Integer::Parse(elementString, tempMin);
517 Base::Integer::Parse(elementString1, tempMax);
519 if (tempMin > tempMax)
526 r = pSlider->Construct(rect, sliderStyle, tempMin, tempMax);
530 r = pSlider->Construct(rect, sliderStyle, 0, 10);
542 if (pControl->GetElement(L"value", elementString))
544 Base::Integer::Parse(elementString, temp);
545 if (temp > tempMax || temp < tempMin)
547 temp = (tempMin + tempMax) >> 1;
549 pSlider->SetValue(temp);
553 pSlider->SetValue((tempMin + tempMax) >> 1);
558 if (pControl->GetElement(L"titleText", elementString))
560 pSlider->SetTitleText(elementString);
562 if (pControl->GetElement(L"colorOfTitleText", elementString))
564 ConvertStringToColor(elementString, color);
565 pSlider->SetTitleTextColor(color);
569 if (pControl->GetElement(L"normalThumbBitmap", elementString))
571 Bitmap* pBitmap = null;
572 pBitmap = LoadBitmapN(elementString);
575 pSlider->SetThumbBitmap(SLIDER_THUMB_STATUS_NORMAL, *pBitmap);
581 if (pControl->GetElement(L"pressedThumbBitmap", elementString))
583 Bitmap* pBitmap = null;
584 pBitmap = LoadBitmapN(elementString);
587 pSlider->SetThumbBitmap(SLIDER_THUMB_STATUS_PRESSED, *pBitmap);
593 if (pControl->GetElement(L"disabledThumbBitmap", elementString))
595 Bitmap* pBitmap = null;
596 pBitmap = LoadBitmapN(elementString);
599 pSlider->SetThumbBitmap(SLIDER_THUMB_STATUS_DISABLED, *pBitmap);
605 if (pControl->GetElement(L"highlightedThumbBitmap", elementString))
607 Bitmap* pBitmap = null;
608 pBitmap = LoadBitmapN(elementString);
611 pSlider->SetThumbBitmap(SLIDER_THUMB_STATUS_HIGHLIGHTED, *pBitmap);
617 if (pControl->GetElement(L"leftIconBitmapPath", elementString))
619 Bitmap* pBitmap = null;
620 pBitmap = LoadBitmapN(elementString);
623 pSlider->SetIcon(ICON_POSITION_LEFT, *pBitmap);
629 if (pControl->GetElement(L"rightIconBitmapPath", elementString))
631 Bitmap* pBitmap = null;
632 pBitmap = LoadBitmapN(elementString);
635 pSlider->SetIcon(ICON_POSITION_RIGHT, *pBitmap);
641 if (pControl->GetElement(L"normalThumbTextColor", elementString))
643 ConvertStringToColor(elementString, color);
644 pSlider->SetThumbTextColor(SLIDER_THUMB_STATUS_NORMAL, color);
647 if (pControl->GetElement(L"pressedThumbTextColor", elementString))
649 ConvertStringToColor(elementString, color);
650 pSlider->SetThumbTextColor(SLIDER_THUMB_STATUS_PRESSED, color);
653 if (pControl->GetElement(L"disabledThumbTextColor", elementString))
655 ConvertStringToColor(elementString, color);
656 pSlider->SetThumbTextColor(SLIDER_THUMB_STATUS_DISABLED, color);
659 if (pControl->GetElement(L"highlightedThumbTextColor", elementString))
661 ConvertStringToColor(elementString, color);
662 pSlider->SetThumbTextColor(SLIDER_THUMB_STATUS_HIGHLIGHTED, color);
665 if (pControl->GetElement(L"barColor", elementString))
667 ConvertStringToColor(elementString, color);
668 pSlider->SetBarColor(color);
670 if (pControl->GetElement(L"colorOpacity", elementString))
672 Base::Integer::Parse(elementString, opacity);
674 if (pControl->GetElement(L"color", elementString))
676 ConvertStringToColor32(elementString, opacity, color);
677 pSlider->SetColor(color);
685 _SliderRegister::_SliderRegister(void)
687 _UiBuilderControlTableManager* pUiBuilderControlTableManager = _UiBuilderControlTableManager::GetInstance();
688 pUiBuilderControlTableManager->RegisterControl(L"Slider", _SliderMaker::GetInstance);
690 _SliderRegister::~_SliderRegister(void)
692 _UiBuilderControlTableManager* pUiBuilderControlTableManager = _UiBuilderControlTableManager::GetInstance();
693 pUiBuilderControlTableManager->UnregisterControl(L"Slider");
695 static _SliderRegister SliderRegisterToUiBuilder;
696 }}} // Tizen::Ui::Controls