X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Fbuttons%2Fpush-button-impl.cpp;h=0df4e3cfdc827bd05c1832d2e1fa1546d4c233ad;hp=450b03858d6637977c100234c54213351676b6df;hb=dc3613bb6248908c267a76e378b04962bce85664;hpb=57869973578f6a0b0f836d396c7232ddb8302c6b diff --git a/dali-toolkit/internal/controls/buttons/push-button-impl.cpp b/dali-toolkit/internal/controls/buttons/push-button-impl.cpp index 450b038..0df4e3c 100644 --- a/dali-toolkit/internal/controls/buttons/push-button-impl.cpp +++ b/dali-toolkit/internal/controls/buttons/push-button-impl.cpp @@ -22,7 +22,6 @@ #include #include #include -#include // INTERNAL INCLUDES #include "push-button-default-painter-impl.h" @@ -49,27 +48,13 @@ BaseHandle Create() TypeRegistration typeRegistration( typeid(Toolkit::PushButton), typeid(Toolkit::Button), Create ); -SignalConnectorType signalConnector1( typeRegistration, Toolkit::PushButton::SIGNAL_PRESSED , &PushButton::DoConnectSignal ); -SignalConnectorType signalConnector2( typeRegistration, Toolkit::PushButton::SIGNAL_RELEASED, &PushButton::DoConnectSignal ); - -TypeAction action1( typeRegistration, Toolkit::PushButton::ACTION_PUSH_BUTTON_CLICK, &PushButton::DoAction ); - } // unnamed namespace namespace { -const unsigned int INITIAL_AUTOREPEATING_DELAY( 0.15f ); -const unsigned int NEXT_AUTOREPEATING_DELAY( 0.05f ); - const float TEXT_PADDING = 12.0f; -// Helper function used to cast a ButtonPainter to PushButtonDefaultPainter -PushButtonDefaultPainterPtr GetPushButtonPainter( Dali::Toolkit::Internal::ButtonPainterPtr painter ) -{ - return static_cast( painter.Get() ); -} - /** * Find the first image actor in the actor hierarchy */ @@ -109,376 +94,6 @@ Dali::Toolkit::PushButton PushButton::New() return pushButton; } -void PushButton::SetAutoRepeating( bool autoRepeating ) -{ - mAutoRepeating = autoRepeating; - - // An autorepeating button can't be a toggle button. - if( autoRepeating ) - { - mToggleButton = false; - if( mToggled ) - { - // Emit a signal is not wanted, only change the appearance. - Toolkit::PushButton handle( GetOwner() ); - GetPushButtonPainter( mPainter )->Toggled( handle ); - mToggled = false; - } - } - - // Notifies the painter. - GetPushButtonPainter( mPainter )->SetAutoRepeating( mAutoRepeating ); -} - -bool PushButton::IsAutoRepeating() const -{ - return mAutoRepeating; -} - -void PushButton::SetInitialAutoRepeatingDelay( float initialAutoRepeatingDelay ) -{ - DALI_ASSERT_ALWAYS( initialAutoRepeatingDelay > 0.f ); - mInitialAutoRepeatingDelay = initialAutoRepeatingDelay; -} - -float PushButton::GetInitialAutoRepeatingDelay() const -{ - return mInitialAutoRepeatingDelay; -} - -void PushButton::SetNextAutoRepeatingDelay( float nextAutoRepeatingDelay ) -{ - DALI_ASSERT_ALWAYS( nextAutoRepeatingDelay > 0.f ); - mNextAutoRepeatingDelay = nextAutoRepeatingDelay; -} - -float PushButton::GetNextAutoRepeatingDelay() const -{ - return mNextAutoRepeatingDelay; -} - -void PushButton::SetToggleButton( bool toggle ) -{ - mToggleButton = toggle; - - // A toggle button can't be an autorepeating button. - if( toggle ) - { - mAutoRepeating = false; - - // Notifies the painter. - GetPushButtonPainter( mPainter )->SetAutoRepeating( mAutoRepeating ); - } -} - -bool PushButton::IsToggleButton() const -{ - return mToggleButton; -} - -void PushButton::SetToggled( bool toggle ) -{ - if( !mDisabled && mToggleButton && ( toggle != mToggled ) ) - { - mToggled = toggle; - - Toolkit::PushButton handle( GetOwner() ); - - // Notifies the painter the button has been toggled. - GetPushButtonPainter( mPainter )->Toggled( handle ); - - // Emit signal. - mStateChangedSignal.Emit( handle, mToggled ); - } -} - -bool PushButton::IsToggled() const -{ - return mToggleButton && mToggled; -} - -void PushButton::SetButtonImage( Image image ) -{ - SetButtonImage( ImageActor::New( image ) ); -} - -void PushButton::SetButtonImage( Actor image ) -{ - Toolkit::PushButton handle( GetOwner() ); - GetPushButtonPainter( mPainter )->SetButtonImage( handle, image ); -} - -Actor& PushButton::GetButtonImage() -{ - return mButtonImage; -} - -Actor PushButton::GetButtonImage() const -{ - return mButtonImage; -} - -void PushButton::SetBackgroundImage( Image image ) -{ - SetBackgroundImage( ImageActor::New( image ) ); -} - -void PushButton::SetBackgroundImage( Actor image ) -{ - Toolkit::PushButton handle( GetOwner() ); - GetPushButtonPainter( mPainter )->SetBackgroundImage( handle, image ); -} - -Actor& PushButton::GetBackgroundImage() -{ - return mBackgroundImage; -} - -Actor PushButton::GetBackgroundImage() const -{ - return mBackgroundImage; -} - -void PushButton::SetSelectedImage( Image image ) -{ - SetSelectedImage( ImageActor::New( image ) ); -} - -void PushButton::SetSelectedImage( Actor image ) -{ - Toolkit::PushButton handle( GetOwner() ); - GetPushButtonPainter( mPainter )->SetSelectedImage( handle, image ); -} - -Actor& PushButton::GetSelectedImage() -{ - return mSelectedImage; -} - -Actor PushButton::GetSelectedImage() const -{ - return mSelectedImage; -} - -void PushButton::SetDisabledBackgroundImage( Image image ) -{ - SetDisabledBackgroundImage( ImageActor::New( image ) ); -} - -void PushButton::SetDisabledBackgroundImage( Actor image ) -{ - Toolkit::PushButton handle( GetOwner() ); - GetPushButtonPainter( mPainter )->SetDisabledBackgroundImage( handle, image ); -} - -Actor& PushButton::GetDisabledBackgroundImage() -{ - return mDisabledBackgroundImage; -} - -Actor PushButton::GetDisabledBackgroundImage() const -{ - return mDisabledBackgroundImage; -} - -void PushButton::SetDisabledImage( Image image ) -{ - SetDisabledImage( ImageActor::New( image ) ); -} - -void PushButton::SetDisabledImage( Actor image ) -{ - Toolkit::PushButton handle( GetOwner() ); - GetPushButtonPainter( mPainter )->SetDisabledImage( handle, image ); -} - -Actor& PushButton::GetDisabledImage() -{ - return mDisabledImage; -} - -Actor PushButton::GetDisabledImage() const -{ - return mDisabledImage; -} - -void PushButton::SetLabel( const std::string& label ) -{ - Toolkit::TextView textView ( Toolkit::TextView::New( label ) ); - textView.SetWidthExceedPolicy( Toolkit::TextView::ShrinkToFit ); // Make sure our text always fits inside the button - SetLabel( textView ); -} - -void PushButton::SetLabel( Actor label ) -{ - Toolkit::PushButton handle( GetOwner() ); - GetPushButtonPainter( mPainter )->SetLabel( handle, label ); -} - -Actor PushButton::GetLabel() const -{ - return mLabel; -} - -Actor& PushButton::GetLabel() -{ - return mLabel; -} - -Actor& PushButton::GetFadeOutBackgroundImage() -{ - return mFadeOutBackgroundImage; -} - -Actor& PushButton::GetFadeOutButtonImage() -{ - return mFadeOutButtonImage; -} - -Toolkit::PushButton::PressedSignalType& PushButton::PressedSignal() -{ - return mPressedSignal; -} - -Toolkit::PushButton::ReleasedSignalType& PushButton::ReleasedSignal() -{ - return mReleasedSignal; -} - -bool PushButton::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor ) -{ - Dali::BaseHandle handle( object ); - - bool connected( true ); - Toolkit::PushButton button = Toolkit::PushButton::DownCast(handle); - - if( Toolkit::PushButton::SIGNAL_STATE_CHANGED == signalName ) - { - button.StateChangedSignal().Connect( tracker, functor ); - } - else if( Toolkit::PushButton::SIGNAL_PRESSED == signalName ) - { - button.PressedSignal().Connect( tracker, functor ); - } - else if( Toolkit::PushButton::SIGNAL_RELEASED == signalName ) - { - button.ReleasedSignal().Connect( tracker, functor ); - } - else - { - // signalName does not match any signal - connected = false; - } - - return connected; -} - -void PushButton::SetProperty( BaseObject* object, Property::Index propertyIndex, const Property::Value& value ) -{ - Toolkit::PushButton pushButton = Toolkit::PushButton::DownCast( Dali::BaseHandle( object ) ); - - if ( pushButton ) - { - PushButton& pushButtonImpl( GetImplementation( pushButton ) ); - - if ( propertyIndex == Toolkit::Button::PROPERTY_AUTO_REPEATING ) - { - pushButtonImpl.SetAutoRepeating( value.Get< bool >() ); - } - else if ( propertyIndex == Toolkit::Button::PROPERTY_INITIAL_AUTO_REPEATING_DELAY ) - { - pushButtonImpl.SetInitialAutoRepeatingDelay( value.Get< float >() ); - } - else if ( propertyIndex == Toolkit::Button::PROPERTY_NEXT_AUTO_REPEATING_DELAY ) - { - pushButtonImpl.SetNextAutoRepeatingDelay( value.Get< float >() ); - } - else if ( propertyIndex == Toolkit::Button::PROPERTY_TOGGLABLE ) - { - pushButtonImpl.SetToggleButton( value.Get< bool >() ); - } - else if ( propertyIndex == Toolkit::Button::PROPERTY_TOGGLED ) - { - pushButtonImpl.SetToggled( value.Get< bool >() ); - } - else if ( propertyIndex == Toolkit::Button::PROPERTY_NORMAL_STATE_ACTOR ) - { - pushButtonImpl.SetButtonImage( Scripting::NewActor( value.Get< Property::Map >() ) ); - } - else if ( propertyIndex == Toolkit::Button::PROPERTY_SELECTED_STATE_ACTOR ) - { - pushButtonImpl.SetSelectedImage( Scripting::NewActor( value.Get< Property::Map >() ) ); - } - else if ( propertyIndex == Toolkit::Button::PROPERTY_DISABLED_STATE_ACTOR ) - { - pushButtonImpl.SetDisabledImage( Scripting::NewActor( value.Get< Property::Map >() ) ); - } - else if ( propertyIndex == Toolkit::Button::PROPERTY_LABEL_ACTOR ) - { - pushButtonImpl.SetLabel( Scripting::NewActor( value.Get< Property::Map >() ) ); - } - } -} - -Property::Value PushButton::GetProperty( BaseObject* object, Property::Index propertyIndex ) -{ - Property::Value value; - - Toolkit::PushButton pushButton = Toolkit::PushButton::DownCast( Dali::BaseHandle( object ) ); - - if ( pushButton ) - { - PushButton& pushButtonImpl( GetImplementation( pushButton ) ); - - if ( propertyIndex == Toolkit::Button::PROPERTY_AUTO_REPEATING ) - { - value = pushButtonImpl.mAutoRepeating; - } - else if ( propertyIndex == Toolkit::Button::PROPERTY_INITIAL_AUTO_REPEATING_DELAY ) - { - value = pushButtonImpl.mInitialAutoRepeatingDelay; - } - else if ( propertyIndex == Toolkit::Button::PROPERTY_NEXT_AUTO_REPEATING_DELAY ) - { - value = pushButtonImpl.mNextAutoRepeatingDelay; - } - else if ( propertyIndex == Toolkit::Button::PROPERTY_TOGGLABLE ) - { - value = pushButtonImpl.mToggleButton; - } - else if ( propertyIndex == Toolkit::Button::PROPERTY_TOGGLED ) - { - value = pushButtonImpl.mToggled; - } - else if ( propertyIndex == Toolkit::Button::PROPERTY_NORMAL_STATE_ACTOR ) - { - Property::Map map; - Scripting::CreatePropertyMap( pushButtonImpl.mButtonImage, map ); - value = map; - } - else if ( propertyIndex == Toolkit::Button::PROPERTY_SELECTED_STATE_ACTOR ) - { - Property::Map map; - Scripting::CreatePropertyMap( pushButtonImpl.mSelectedImage, map ); - value = map; - } - else if ( propertyIndex == Toolkit::Button::PROPERTY_DISABLED_STATE_ACTOR ) - { - Property::Map map; - Scripting::CreatePropertyMap( pushButtonImpl.mDisabledImage, map ); - value = map; - } - else if ( propertyIndex == Toolkit::Button::PROPERTY_LABEL_ACTOR ) - { - Property::Map map; - Scripting::CreatePropertyMap( pushButtonImpl.mLabel, map ); - value = map; - } - } - - return value; -} - void PushButton::OnButtonInitialize() { // Push button requires the Leave event. @@ -486,175 +101,17 @@ void PushButton::OnButtonInitialize() root.SetLeaveRequired( true ); } -void PushButton::OnButtonDown() -{ - if( !mToggleButton ) - { - Toolkit::PushButton handle( GetOwner() ); - - // Notifies the painter the button has been pressed. - GetPushButtonPainter( mPainter )->Pressed( handle ); - - if( mAutoRepeating ) - { - SetUpTimer( mInitialAutoRepeatingDelay ); - } - - //Emit signal. - mPressedSignal.Emit( handle ); - } -} - -void PushButton::OnButtonUp() -{ - if( ButtonDown == mState ) - { - if( mToggleButton ) - { - mToggled = !mToggled; - - Toolkit::PushButton handle( GetOwner() ); - - // Notifies the painter the button has been toggled. - GetPushButtonPainter( mPainter )->Toggled( handle ); - - // Emit signal. - mStateChangedSignal.Emit( handle, mToggled ); - } - else - { - Toolkit::PushButton handle( GetOwner() ); - - // Notifies the painter the button has been clicked. - GetPushButtonPainter( mPainter )->Released( handle ); - GetPushButtonPainter( mPainter )->Clicked( handle ); - - if( mAutoRepeating ) - { - mAutoRepeatingTimer.Reset(); - } - - //Emit signal. - mReleasedSignal.Emit( handle ); - mClickedSignal.Emit( handle ); - } - } -} - -void PushButton::OnTouchPointLeave() -{ - if( ButtonDown == mState ) - { - if( !mToggleButton ) - { - Toolkit::PushButton handle( GetOwner() ); - - // Notifies the painter the button has been released. - GetPushButtonPainter( mPainter )->Released( handle ); - - if( mAutoRepeating ) - { - mAutoRepeatingTimer.Reset(); - } - - //Emit signal. - mReleasedSignal.Emit( handle ); - } - } -} - -void PushButton::OnTouchPointInterrupted() -{ - OnTouchPointLeave(); -} - -void PushButton::OnAnimationTimeSet( float animationTime ) -{ - GetPushButtonPainter( mPainter )->SetAnimationTime( animationTime ); -} - -float PushButton::OnAnimationTimeRequested() const -{ - return GetPushButtonPainter( mPainter )->GetAnimationTime(); -} - -void PushButton::OnButtonStageDisconnection() -{ - if( ButtonDown == mState ) - { - if( !mToggleButton ) - { - Toolkit::PushButton handle( GetOwner() ); - - // Notifies the painter the button has been released. - GetPushButtonPainter( mPainter )->Released( handle ); - - if( mAutoRepeating ) - { - mAutoRepeatingTimer.Reset(); - } - } - } -} - PushButton::PushButton() -: Button(), - mAutoRepeating( false ), - mInitialAutoRepeatingDelay( INITIAL_AUTOREPEATING_DELAY ), - mNextAutoRepeatingDelay( NEXT_AUTOREPEATING_DELAY ), - mToggleButton( false ), - mAutoRepeatingTimer(), - mToggled( false ), - mClickActionPerforming(false) +: Button() { - // Creates specific painter. - mPainter = PushButtonDefaultPainterPtr( new PushButtonDefaultPainter() ); + // Creates specific painter.GetBu + ButtonPainterPtr painter = PushButtonDefaultPainterPtr( new PushButtonDefaultPainter() ); + SetPainter( painter ); } PushButton::~PushButton() { - if( mAutoRepeatingTimer ) - { - mAutoRepeatingTimer.Reset(); - } - - mPainter = NULL; -} - -void PushButton::SetUpTimer( float delay ) -{ - mAutoRepeatingTimer = Dali::Timer::New( static_cast( 1000.f * delay ) ); - mAutoRepeatingTimer.TickSignal().Connect( this, &PushButton::AutoRepeatingSlot ); - mAutoRepeatingTimer.Start(); -} - -bool PushButton::AutoRepeatingSlot() -{ - bool consumed = false; - if( !mDisabled ) - { - // Restart the autorepeat timer. - SetUpTimer( mNextAutoRepeatingDelay ); - - Toolkit::PushButton handle( GetOwner() ); - - // Notifies the painter the button has been pressed. - GetPushButtonPainter( mPainter )->Pressed( handle ); - - //Emit signal. - consumed = mReleasedSignal.Emit( handle ); - consumed |= mClickedSignal.Emit( handle ); - consumed |= mPressedSignal.Emit( handle ); - } - - return consumed; -} - -void PushButton::OnActivated() -{ - // When the button is activated, it performs the click action - PropertyValueContainer attributes; - DoClickAction(attributes); + SetPainter( NULL ); } Vector3 PushButton::GetNaturalSize() @@ -667,7 +124,7 @@ Vector3 PushButton::GetNaturalSize() if( widthIsZero || heightIsZero ) { // If background and background not scale9 try get size from that - ImageActor imageActor = FindImageActor( mButtonImage ); + ImageActor imageActor = FindImageActor( GetButtonImage() ); if( imageActor && imageActor.GetStyle() != ImageActor::STYLE_NINE_PATCH ) { Vector3 imageSize = RelayoutHelper::GetNaturalSize( imageActor ); @@ -683,7 +140,7 @@ Vector3 PushButton::GetNaturalSize() } } - ImageActor backgroundImageActor = FindImageActor( mBackgroundImage ); + ImageActor backgroundImageActor = FindImageActor( GetBackgroundImage() ); if( backgroundImageActor && backgroundImageActor.GetStyle() != ImageActor::STYLE_NINE_PATCH ) { Vector3 imageSize = RelayoutHelper::GetNaturalSize( backgroundImageActor ); @@ -700,7 +157,7 @@ Vector3 PushButton::GetNaturalSize() } // If label, test against it's size - Toolkit::TextView textView = Toolkit::TextView::DownCast( mLabel ); + Toolkit::TextView textView = Toolkit::TextView::DownCast( GetLabel() ); if( textView ) { Vector3 textViewSize = textView.GetNaturalSize(); @@ -720,39 +177,6 @@ Vector3 PushButton::GetNaturalSize() return size; } -void PushButton::DoClickAction(const PropertyValueContainer& attributes) -{ - // Prevents the button signals from doing a recursive loop by sending an action - // and re-emitting the signals. - if(!mClickActionPerforming) - { - mClickActionPerforming = true; - OnButtonDown(); - mState = ButtonDown; - OnButtonUp(); - mClickActionPerforming = false; - } -} - -bool PushButton::DoAction(BaseObject* object, const std::string& actionName, const PropertyValueContainer& attributes) -{ - bool ret = false; - - Dali::BaseHandle handle(object); - - Toolkit::PushButton button = Toolkit::PushButton::DownCast(handle); - - DALI_ASSERT_ALWAYS(button); - - if(Toolkit::PushButton::ACTION_PUSH_BUTTON_CLICK == actionName) - { - GetImplementation(button).DoClickAction(attributes); - ret = true; - } - - return ret; -} - } // namespace Internal } // namespace Toolkit