X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Fbuttons%2Fcheck-box-button-impl.cpp;h=103992f1a7995640cc269c7123ddb66c0127b638;hb=8ca4aa19ff1c7282e1a724d4660bf34e5a4b77fa;hp=c15c15e08e9be4134254df6ac0f12f9eb00f0738;hpb=2ddfbb9e23a7c3fc30e604236c41e0ef6d2ed6a2;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/dali-toolkit/internal/controls/buttons/check-box-button-impl.cpp b/dali-toolkit/internal/controls/buttons/check-box-button-impl.cpp index c15c15e..103992f 100644 --- a/dali-toolkit/internal/controls/buttons/check-box-button-impl.cpp +++ b/dali-toolkit/internal/controls/buttons/check-box-button-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,12 +19,18 @@ #include "check-box-button-impl.h" // EXTERNAL INCLUDES -#include -#include +#include #include -// INTERNAL INCLUDES -#include "check-box-button-default-painter-impl.h" +//INTERNAL INCLUDES +#include +#include +#include +#include + +#if defined(DEBUG_ENABLED) + extern Debug::Filter* gLogButtonFilter; +#endif namespace Dali { @@ -45,18 +51,9 @@ BaseHandle Create() TypeRegistration mType( typeid(Toolkit::CheckBoxButton), typeid(Toolkit::Button), Create ); -TypeAction a1(mType, Toolkit::CheckBoxButton::ACTION_CHECK_BOX_BUTTON_CLICK, &CheckBoxButton::DoAction); -} -namespace -{ - // Helper function used to cast a ButtonPainterPtr to CheckBoxButtonDefaultPainterPtr - CheckBoxButtonDefaultPainterPtr GetCheckBoxButtonPainter( ButtonPainterPtr painter ) - { - return static_cast( painter.Get() ); - } -} // namespace +} Dali::Toolkit::CheckBoxButton CheckBoxButton::New() { @@ -73,195 +70,46 @@ Dali::Toolkit::CheckBoxButton CheckBoxButton::New() return checkBoxButton; } -void CheckBoxButton::SetChecked( bool checked ) -{ - if( !mDisabled && ( checked != mChecked ) ) - { - // Stores the state. - mChecked = checked; - - Toolkit::CheckBoxButton handle( GetOwner() ); - - // Notifies the painter the checkbox has been checked. - GetCheckBoxButtonPainter( mPainter )->Checked( handle ); - - // Raise state changed signal - mStateChangedSignal.Emit( handle, mChecked ); - } -} - -bool CheckBoxButton::IsChecked() const -{ - return mChecked; -} - -void CheckBoxButton::SetBackgroundImage( Image image ) -{ - SetBackgroundImage( ImageActor::New( image ) ); -} - -void CheckBoxButton::SetBackgroundImage( Actor image ) -{ - Toolkit::CheckBoxButton handle( GetOwner() ); - GetCheckBoxButtonPainter( mPainter )->SetBackgroundImage( handle, image ); -} - -Actor& CheckBoxButton::GetBackgroundImage() -{ - return mBackgroundImage; -} - -Actor CheckBoxButton::GetBackgroundImage() const -{ - return mBackgroundImage; -} - -void CheckBoxButton::SetCheckedImage( Image image ) -{ - SetCheckedImage( ImageActor::New( image ) ); -} - -void CheckBoxButton::SetCheckedImage( Actor image ) -{ - Toolkit::CheckBoxButton handle( GetOwner() ); - GetCheckBoxButtonPainter( mPainter )->SetCheckedImage( handle, image ); -} - -Actor& CheckBoxButton::GetCheckedImage() -{ - return mCheckedImage; -} - -Actor CheckBoxButton::GetCheckedImage() const -{ - return mCheckedImage; -} - -void CheckBoxButton::SetDisabledBackgroundImage( Image image ) -{ - SetDisabledBackgroundImage( ImageActor::New( image ) ); -} - -void CheckBoxButton::SetDisabledBackgroundImage( Actor image ) -{ - Toolkit::CheckBoxButton handle( GetOwner() ); - GetCheckBoxButtonPainter( mPainter )->SetDisabledBackgroundImage( handle, image ); -} - -Actor& CheckBoxButton::GetDisabledBackgroundImage() -{ - return mDisabledBackgroundImage; -} - -Actor CheckBoxButton::GetDisabledBackgroundImage() const -{ - return mDisabledBackgroundImage; -} - -void CheckBoxButton::SetDisabledCheckedImage( Image image ) -{ - SetDisabledCheckedImage( ImageActor::New( image ) ); -} - -void CheckBoxButton::SetDisabledCheckedImage( Actor image ) -{ - Toolkit::CheckBoxButton handle( GetOwner() ); - GetCheckBoxButtonPainter( mPainter )->SetDisabledCheckedImage( handle, image ); -} - -Actor& CheckBoxButton::GetDisabledCheckedImage() -{ - return mDisabledCheckedImage; -} - -Actor CheckBoxButton::GetDisabledCheckedImage() const -{ - return mDisabledCheckedImage; -} - -Actor& CheckBoxButton::GetFadeOutBackgroundImage() -{ - return mFadeOutBackgroundImage; -} - -Actor& CheckBoxButton::GetFadeOutCheckedImage() -{ - return mFadeOutCheckedImage; -} - -void CheckBoxButton::OnButtonInitialize() +CheckBoxButton::CheckBoxButton() +: Button() { + SetTogglableButton( true ); } -void CheckBoxButton::OnButtonUp() +CheckBoxButton::~CheckBoxButton() { - if( ButtonDown == mState ) - { - // Stores the state, notifies the painter and emits a signal. - SetChecked( !mChecked ); - } } -void CheckBoxButton::OnAnimationTimeSet( float animationTime ) +void CheckBoxButton::OnInitialize() { - GetCheckBoxButtonPainter( mPainter )->SetAnimationTime( animationTime ); -} + Button::OnInitialize(); -float CheckBoxButton::OnAnimationTimeRequested() const -{ - return GetCheckBoxButtonPainter( mPainter )->GetAnimationTime(); + DevelControl::SetAccessibilityConstructor( Self(), []( Dali::Actor actor ) { + return std::unique_ptr< Dali::Accessibility::Accessible >( + new AccessibleImpl( actor, Dali::Accessibility::Role::CHECK_BOX ) ); + } ); } -void CheckBoxButton::OnActivated() +Dali::Accessibility::States CheckBoxButton::AccessibleImpl::CalculateStates() { - // When the button is activated, it performs the click action - PropertyValueContainer attributes; - DoClickAction(attributes); + auto tmp = Button::AccessibleImpl::CalculateStates(); + auto slf = Toolkit::Button::DownCast( self ); + if( slf.GetProperty( Toolkit::Button::Property::SELECTED ) ) + tmp[Dali::Accessibility::State::CHECKED] = true; + return tmp; } -void CheckBoxButton::DoClickAction(const PropertyValueContainer& attributes) +void CheckBoxButton::OnStateChange( State newState ) { - // Prevents the button signals from doing a recursive loop by sending an action - // and re-emitting the signals. - if(!mClickActionPerforming) + // TODO: replace it with OnPropertySet hook once Button::Property::SELECTED will be consistently used + if (Dali::Accessibility::IsUp() && (newState == SELECTED_STATE || newState == UNSELECTED_STATE)) { - mClickActionPerforming = true; - SetChecked( !mChecked ); - mClickActionPerforming = false; + Dali::Accessibility::Accessible::Get(Self())->EmitStateChanged( + Dali::Accessibility::State::CHECKED, newState == SELECTED_STATE ? 1 : 0, 0 + ); } } -bool CheckBoxButton::DoAction(BaseObject* object, const std::string& actionName, const PropertyValueContainer& attributes) -{ - bool ret = false; - - Dali::BaseHandle handle(object); - - Toolkit::CheckBoxButton button = Toolkit::CheckBoxButton::DownCast(handle); - - if(Toolkit::CheckBoxButton::ACTION_CHECK_BOX_BUTTON_CLICK == actionName) - { - GetImplementation(button).DoClickAction(attributes); - ret = true; - } - - return ret; -} - -CheckBoxButton::CheckBoxButton() -: Button(), - mChecked( false ), - mClickActionPerforming(false) -{ - // Creates specific painter. - mPainter = new CheckBoxButtonDefaultPainter(); -} - -CheckBoxButton::~CheckBoxButton() -{ - mPainter = NULL; -} - } // namespace Internal } // namespace Toolkit