X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Fbuttons%2Fbutton-impl.cpp;h=4f7dd860e9a47afdcce141d6dd2bc32d68bb7369;hp=eef0cd8970d93e1b7fb71b53017ac67316b3b69c;hb=4c85a797e24c20bfb1670c079e5f66a9a5d6fa0e;hpb=87f440c3d0367ca5a7027eef8d01d79b8703cf05 diff --git a/dali-toolkit/internal/controls/buttons/button-impl.cpp b/dali-toolkit/internal/controls/buttons/button-impl.cpp index eef0cd8..4f7dd86 100644 --- a/dali-toolkit/internal/controls/buttons/button-impl.cpp +++ b/dali-toolkit/internal/controls/buttons/button-impl.cpp @@ -23,6 +23,8 @@ #include #include #include + +// INTERNAL INCLUDES #include namespace Dali @@ -51,20 +53,31 @@ namespace const unsigned int INITIAL_AUTOREPEATING_DELAY( 0.15f ); const unsigned int NEXT_AUTOREPEATING_DELAY( 0.05f ); +// Signals + +const char* const SIGNAL_PRESSED = "pressed"; +const char* const SIGNAL_RELEASED = "released"; +const char* const SIGNAL_CLICKED = "clicked"; +const char* const SIGNAL_STATE_CHANGED = "state-changed"; + +// Actions + +const char* const ACTION_BUTTON_CLICK = "button-click"; + BaseHandle Create() { // empty handle as we cannot create button (but type registered for clicked signal) return BaseHandle(); } -TypeRegistration typeRegistration( typeid(Toolkit::Button), typeid(Toolkit::Control), Create ); +TypeRegistration typeRegistration( typeid( Toolkit::Button ), typeid( Toolkit::Control ), Create ); -SignalConnectorType signalConnector1( typeRegistration, Toolkit::Button::SIGNAL_PRESSED , &Button::DoConnectSignal ); -SignalConnectorType signalConnector2( typeRegistration, Toolkit::Button::SIGNAL_RELEASED, &Button::DoConnectSignal ); -SignalConnectorType signalConnector3( typeRegistration, Toolkit::Button::SIGNAL_CLICKED, &Button::DoConnectSignal ); -SignalConnectorType signalConnector4( typeRegistration, Toolkit::Button::SIGNAL_STATE_CHANGED, &Button::DoConnectSignal ); +SignalConnectorType signalConnector1( typeRegistration, SIGNAL_PRESSED , &Button::DoConnectSignal ); +SignalConnectorType signalConnector2( typeRegistration, SIGNAL_RELEASED, &Button::DoConnectSignal ); +SignalConnectorType signalConnector3( typeRegistration, SIGNAL_CLICKED, &Button::DoConnectSignal ); +SignalConnectorType signalConnector4( typeRegistration, SIGNAL_STATE_CHANGED, &Button::DoConnectSignal ); -TypeAction action1( typeRegistration, Toolkit::Button::ACTION_BUTTON_CLICK, &Button::DoAction ); +TypeAction action1( typeRegistration, ACTION_BUTTON_CLICK, &Button::DoAction ); PropertyRegistration property1( typeRegistration, "disabled", Toolkit::Button::PROPERTY_DISABLED, Property::BOOLEAN, &Button::SetProperty, &Button::GetProperty ); PropertyRegistration property2( typeRegistration, "auto-repeating", Toolkit::Button::PROPERTY_AUTO_REPEATING, Property::BOOLEAN, &Button::SetProperty, &Button::GetProperty ); @@ -81,16 +94,14 @@ PropertyRegistration property10( typeRegistration, "label-actor", Button::Button() : Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS | REQUIRES_STYLE_CHANGE_SIGNALS ) ), - mTogglableButton( false ), - mSelected( false ), - mPainter( NULL ), mAutoRepeatingTimer(), mDisabled( false ), mAutoRepeating( false ), -// mTogglableButton( false ), -// mSelected( false ), + mTogglableButton( false ), + mSelected( false ), mInitialAutoRepeatingDelay( INITIAL_AUTOREPEATING_DELAY ), mNextAutoRepeatingDelay( NEXT_AUTOREPEATING_DELAY ), + mAnimationTime( 0.0f ), mClickActionPerforming( false ), mState( ButtonUp ) { @@ -106,13 +117,11 @@ Button::~Button() void Button::SetDisabled( bool disabled ) { - mDisabled = disabled; - - // Notifies the painter. - Toolkit::Button handle( GetOwner() ); - if( mPainter ) + if( disabled != mDisabled ) { - mPainter->SetDisabled( handle, mDisabled ); + mDisabled = disabled; + + OnDisabled( mDisabled ); } } @@ -129,17 +138,17 @@ void Button::SetAutoRepeating( bool autoRepeating ) if( autoRepeating ) { mTogglableButton = false; + if( mSelected ) { // Emit a signal is not wanted, only change the appearance. - Toolkit::Button handle( GetOwner() ); - mPainter->Selected( handle ); + OnSelected( false ); + mSelected = false; + + RelayoutRequest(); } } - - // Notifies the painter. - mPainter->SetAutoRepeating( mAutoRepeating ); } bool Button::IsAutoRepeating() const @@ -177,9 +186,6 @@ void Button::SetTogglableButton( bool togglable ) if( togglable ) { mAutoRepeating = false; - - // Notifies the painter. - mPainter->SetAutoRepeating( mAutoRepeating ); } } @@ -192,15 +198,17 @@ void Button::SetSelected( bool selected ) { if( !mDisabled && mTogglableButton && ( selected != mSelected ) ) { + // Notifies the derived class the button has been selected. + OnSelected( selected ); + mSelected = selected; Toolkit::Button handle( GetOwner() ); - // Notifies the painter the button has been selected. - mPainter->Selected( handle ); - // Emit signal. mStateChangedSignal.Emit( handle ); + + RelayoutRequest(); } } @@ -211,12 +219,12 @@ bool Button::IsSelected() const void Button::SetAnimationTime( float animationTime ) { - OnAnimationTimeSet( animationTime ); + mAnimationTime = animationTime; } float Button::GetAnimationTime() const { - return OnAnimationTimeRequested(); + return mAnimationTime; } void Button::SetLabel( const std::string& label ) @@ -224,15 +232,23 @@ void Button::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 ); - - RelayoutRequest(); } void Button::SetLabel( Actor label ) { - Toolkit::Button handle( GetOwner() ); + if( mLabel != label ) + { + if( mLabel && mLabel.GetParent() ) + { + mLabel.GetParent().Remove( mLabel ); + } - mPainter->SetLabel( handle, label ); + mLabel = label; + + OnLabelSet(); + + RelayoutRequest(); + } } Actor Button::GetLabel() const @@ -245,145 +261,64 @@ Actor& Button::GetLabel() return mLabel; } -void Button::SetButtonImage( Image image ) -{ - SetButtonImage( ImageActor::New( image ) ); -} - -void Button::SetButtonImage( Actor image ) -{ - Toolkit::Button handle( GetOwner() ); - mPainter->SetButtonImage( handle, image ); -} - Actor Button::GetButtonImage() const { - return mButtonImage; + return mButtonContent; } Actor& Button::GetButtonImage() { - return mButtonImage; -} - -void Button::SetSelectedImage( Image image ) -{ - SetSelectedImage( ImageActor::New( image ) ); -} - -void Button::SetSelectedImage( Actor image ) -{ - Toolkit::Button handle( GetOwner() ); - mPainter->SetSelectedImage( handle, image ); + return mButtonContent; } Actor Button::GetSelectedImage() const { - return mSelectedImage; + return mSelectedContent; } Actor& Button::GetSelectedImage() { - return mSelectedImage; -} - -void Button::SetBackgroundImage( Image image ) -{ - SetBackgroundImage( ImageActor::New( image ) ); -} - -void Button::SetBackgroundImage( Actor image ) -{ - Toolkit::Button handle( GetOwner() ); - mPainter->SetBackgroundImage( handle, image ); + return mSelectedContent; } Actor Button::GetBackgroundImage() const { - return mBackgroundImage; + return mBackgroundContent; } Actor& Button::GetBackgroundImage() { - return mBackgroundImage; -} - -void Button::SetDisabledImage( Image image ) -{ - SetDisabledImage( ImageActor::New( image ) ); -} - -void Button::SetDisabledImage( Actor image ) -{ - Toolkit::Button handle( GetOwner() ); - mPainter->SetDisabledImage( handle, image ); + return mBackgroundContent; } Actor Button::GetDisabledImage() const { - return mDisabledImage; + return mDisabledContent; } Actor& Button::GetDisabledImage() { - return mDisabledImage; -} - -void Button::SetDisabledSelectedImage( Image image ) -{ - SetDisabledSelectedImage( ImageActor::New( image ) ); -} - -void Button::SetDisabledSelectedImage( Actor image ) -{ - Toolkit::Button handle( GetOwner() ); - mPainter->SetDisabledSelectedImage( handle, image ); + return mDisabledContent; } Actor Button::GetDisabledSelectedImage() const { - return mDisabledSelectedImage; + return mDisabledSelectedContent; } Actor& Button::GetDisabledSelectedImage() { - return mDisabledSelectedImage; -} - -void Button::SetDisabledBackgroundImage( Image image ) -{ - SetDisabledBackgroundImage( ImageActor::New( image ) ); -} - -void Button::SetDisabledBackgroundImage( Actor image ) -{ - Toolkit::Button handle( GetOwner() ); - mPainter->SetDisabledBackgroundImage( handle, image ); + return mDisabledSelectedContent; } Actor Button::GetDisabledBackgroundImage() const { - return mDisabledBackgroundImage; + return mDisabledBackgroundContent; } Actor& Button::GetDisabledBackgroundImage() { - return mDisabledBackgroundImage; -} - -Actor& Button::GetFadeOutButtonImage() -{ - return mFadeOutButtonImage; -} - -Actor& Button::GetFadeOutSelectedImage() -{ - return mFadeOutSelectedImage; -} - -Actor& Button::GetFadeOutBackgroundImage() -{ - return mFadeOutBackgroundImage; + return mDisabledBackgroundContent; } bool Button::DoAction( BaseObject* object, const std::string& actionName, const PropertyValueContainer& attributes ) @@ -396,7 +331,7 @@ bool Button::DoAction( BaseObject* object, const std::string& actionName, const DALI_ASSERT_ALWAYS( button ); - if( Toolkit::Button::ACTION_BUTTON_CLICK == actionName ) + if( 0 == strcmp( actionName.c_str(), ACTION_BUTTON_CLICK ) ) { GetImplementation( button ).DoClickAction( attributes ); ret = true; @@ -419,16 +354,6 @@ void Button::DoClickAction( const PropertyValueContainer& attributes ) } } -void Button::OnAnimationTimeSet( float animationTime ) -{ - mPainter->SetAnimationTime( animationTime ); -} - -float Button::OnAnimationTimeRequested() const -{ - return mPainter->GetAnimationTime(); -} - void Button::OnButtonStageDisconnection() { if( ButtonDown == mState ) @@ -437,8 +362,8 @@ void Button::OnButtonStageDisconnection() { Toolkit::Button handle( GetOwner() ); - // Notifies the painter the button has been released. - mPainter->Released( handle ); + // Notifies the derived class the button has been released. + OnReleased(); if( mAutoRepeating ) { @@ -454,8 +379,8 @@ void Button::OnButtonDown() { Toolkit::Button handle( GetOwner() ); - // Notifies the painter the button has been pressed. - mPainter->Pressed( handle ); + // Notifies the derived class the button has been pressed. + OnPressed(); if( mAutoRepeating ) { @@ -477,17 +402,17 @@ void Button::OnButtonUp() } else { - Toolkit::Button handle( GetOwner() ); - - // Notifies the painter the button has been clicked. - mPainter->Released( handle ); - mPainter->Clicked( handle ); + // Notifies the derived class the button has been clicked. + OnReleased(); + OnClicked(); if( mAutoRepeating ) { mAutoRepeatingTimer.Reset(); } + Toolkit::Button handle( GetOwner() ); + //Emit signal. mReleasedSignal.Emit( handle ); mClickedSignal.Emit( handle ); @@ -503,8 +428,8 @@ void Button::OnTouchPointLeave() { Toolkit::Button handle( GetOwner() ); - // Notifies the painter the button has been released. - mPainter->Released( handle ); + // Notifies the derived class the button has been released. + OnReleased(); if( mAutoRepeating ) { @@ -547,21 +472,21 @@ bool Button::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tr Dali::BaseHandle handle( object ); bool connected( true ); - Toolkit::Button button = Toolkit::Button::DownCast(handle); + Toolkit::Button button = Toolkit::Button::DownCast( handle ); - if( Toolkit::Button::SIGNAL_PRESSED == signalName ) + if( 0 == strcmp( signalName.c_str(), SIGNAL_PRESSED ) ) { button.PressedSignal().Connect( tracker, functor ); } - else if( Toolkit::Button::SIGNAL_RELEASED == signalName ) + else if( 0 == strcmp( signalName.c_str(), SIGNAL_RELEASED ) ) { button.ReleasedSignal().Connect( tracker, functor ); } - else if( Dali::Toolkit::Button::SIGNAL_CLICKED == signalName ) + else if( 0 == strcmp( signalName.c_str(), SIGNAL_CLICKED ) ) { button.ClickedSignal().Connect( tracker, functor ); } - else if( Dali::Toolkit::Button::SIGNAL_STATE_CHANGED == signalName ) + else if( 0 == strcmp( signalName.c_str(), SIGNAL_STATE_CHANGED ) ) { button.StateChangedSignal().Connect( tracker, functor ); } @@ -640,13 +565,6 @@ bool Button::OnTouchEvent(const TouchEvent& event) void Button::OnInitialize() { - // Initialize the painter and notifies subclasses. - Toolkit::Button handle( GetOwner() ); - if( mPainter ) - { - mPainter->Initialize( handle ); - } - Actor self = Self(); mTapDetector = TapGestureDetector::New(); @@ -665,15 +583,6 @@ void Button::OnActivated() DoClickAction( attributes ); } -void Button::OnControlSizeSet(const Vector3& targetSize) -{ - Toolkit::Button handle( GetOwner() ); - if( mPainter ) - { - mPainter->SetSize( handle, targetSize ); - } -} - void Button::OnTap(Actor actor, const TapGesture& tap) { // Do nothing. @@ -696,8 +605,8 @@ bool Button::AutoRepeatingSlot() Toolkit::Button handle( GetOwner() ); - // Notifies the painter the button has been pressed. - mPainter->Pressed( handle ); + // Notifies the derived class the button has been pressed. + OnPressed(); //Emit signal. consumed = mReleasedSignal.Emit( handle ); @@ -714,11 +623,6 @@ void Button::OnControlStageDisconnection() mState = ButtonUp; } -void Button::SetPainter(ButtonPainterPtr painter) -{ - mPainter = painter; -} - Button::ButtonState Button::GetState() { return mState; @@ -844,7 +748,7 @@ Property::Value Button::GetProperty( BaseObject* object, Property::Index propert case Toolkit::Button::PROPERTY_NORMAL_STATE_ACTOR: { Property::Map map; - Scripting::CreatePropertyMap( GetImplementation( button ).mButtonImage, map ); + Scripting::CreatePropertyMap( GetImplementation( button ).mButtonContent, map ); value = map; break; } @@ -852,7 +756,7 @@ Property::Value Button::GetProperty( BaseObject* object, Property::Index propert case Toolkit::Button::PROPERTY_SELECTED_STATE_ACTOR: { Property::Map map; - Scripting::CreatePropertyMap( GetImplementation( button ).mSelectedImage, map ); + Scripting::CreatePropertyMap( GetImplementation( button ).mSelectedContent, map ); value = map; break; } @@ -860,7 +764,7 @@ Property::Value Button::GetProperty( BaseObject* object, Property::Index propert case Toolkit::Button::PROPERTY_DISABLED_STATE_ACTOR: { Property::Map map; - Scripting::CreatePropertyMap( GetImplementation( button ).mDisabledImage, map ); + Scripting::CreatePropertyMap( GetImplementation( button ).mDisabledContent, map ); value = map; break; }