Refactored Button and derived classes, moving state change and transition logic to...
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / buttons / push-button-impl.cpp
index 450b038..1ee6b92 100644 (file)
 #include "push-button-impl.h"
 
 // EXTERNAL INCLUDES
-#include <algorithm>
 #include <dali/public-api/actors/image-actor.h>
 #include <dali/public-api/object/type-registry.h>
-#include <dali/public-api/scripting/scripting.h>
+#include <dali/public-api/images/resource-image.h>
 
 // INTERNAL INCLUDES
-#include "push-button-default-painter-impl.h"
-
-#include <dali-toolkit/public-api/controls/text-view/text-view.h>
-#include <dali-toolkit/internal/controls/relayout-helper.h>
+#include <dali-toolkit/public-api/controls/text-controls/text-label.h>
 
 namespace Dali
 {
@@ -42,6 +38,9 @@ namespace Internal
 namespace
 {
 
+const float TEXT_PADDING = 12.0f;
+const float ANIMATION_TIME( 0.2f );
+
 BaseHandle Create()
 {
   return Toolkit::PushButton::New();
@@ -49,49 +48,31 @@ 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 );
+const char* const UNSELECTED_BUTTON_IMAGE_DIR = DALI_IMAGE_DIR "button-up.9.png";
+const char* const SELECTED_BUTTON_IMAGE_DIR = DALI_IMAGE_DIR "button-down.9.png";
+const char* const DISABLED_UNSELECTED_BUTTON_IMAGE_DIR = DALI_IMAGE_DIR "button-disabled.9.png";
+const char* const DISABLED_SELECTED_BUTTON_IMAGE_DIR = DALI_IMAGE_DIR "button-down-disabled.9.png";
 
 } // 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<PushButtonDefaultPainter*>( painter.Get() );
-}
-
 /**
- * Find the first image actor in the actor hierarchy
+ * Get size of Actor if larger than given size
+ * @param[in] root the actor to get the size of
+ * @param[out] size the greater of the given size or the size of the Actor
  */
-ImageActor FindImageActor( Actor root )
+void SizeOfActorIfLarger( Actor root, Vector3& size )
 {
-  ImageActor imageActor = ImageActor::DownCast( root );
-  if( !imageActor && root )
+  if ( root )
   {
-    for( unsigned int i = 0, numChildren = root.GetChildCount(); i < numChildren; ++i )
-    {
-      ImageActor childImageActor = FindImageActor( root.GetChildAt( i ) );
-      if( childImageActor )
-      {
-        return childImageActor;
-      }
-    }
+    // RelayoutSize retreived for Actor to use any padding set to it.
+    size.width = std::max( root.GetRelayoutSize( Dimension::WIDTH ), size.width );
+    size.height = std::max( root.GetRelayoutSize( Dimension::HEIGHT ), size.height );
   }
-
-  return imageActor;
 }
 
-
 } // unnamed namespace
 
 Dali::Toolkit::PushButton PushButton::New()
@@ -109,648 +90,258 @@ 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
+PushButton::PushButton()
+: Button(),
+  mSize()
 {
-  return mInitialAutoRepeatingDelay;
+  SetAnimationTime( ANIMATION_TIME );
 }
 
-void PushButton::SetNextAutoRepeatingDelay( float nextAutoRepeatingDelay )
+PushButton::~PushButton()
 {
-  DALI_ASSERT_ALWAYS( nextAutoRepeatingDelay > 0.f );
-  mNextAutoRepeatingDelay = nextAutoRepeatingDelay;
 }
 
-float PushButton::GetNextAutoRepeatingDelay() const
+void PushButton::OnButtonInitialize()
 {
-  return mNextAutoRepeatingDelay;
-}
+  // Push button requires the Leave event.
+  Actor self = Self();
+  self.SetLeaveRequired( true );
 
-void PushButton::SetToggleButton( bool toggle )
-{
-  mToggleButton = toggle;
+  // Set resize policy to natural size so that buttons will resize to background images
+  self.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
 
-  // A toggle button can't be an autorepeating button.
-  if( toggle )
-  {
-    mAutoRepeating = false;
+  Image buttonImage = Dali::ResourceImage::New( UNSELECTED_BUTTON_IMAGE_DIR, ResourceImage::ON_DEMAND, ResourceImage::NEVER );
+  Image selectedImage = Dali::ResourceImage::New( SELECTED_BUTTON_IMAGE_DIR, ResourceImage::ON_DEMAND, ResourceImage::NEVER );
+  Image disabledImage = Dali::ResourceImage::New( DISABLED_UNSELECTED_BUTTON_IMAGE_DIR, ResourceImage::ON_DEMAND, ResourceImage::NEVER );
+  Image disabledSelectedImage = Dali::ResourceImage::New( DISABLED_SELECTED_BUTTON_IMAGE_DIR, ResourceImage::ON_DEMAND, ResourceImage::NEVER );
 
-    // Notifies the painter.
-    GetPushButtonPainter( mPainter )->SetAutoRepeating( mAutoRepeating );
-  }
+  SetButtonImage( ImageActor::New( buttonImage ) );
+  SetSelectedImage( ImageActor::New( selectedImage ) );
+  SetDisabledImage( ImageActor::New( disabledImage ) );
+  SetDisabledSelectedImage( ImageActor::New( disabledSelectedImage ) );
 }
 
-bool PushButton::IsToggleButton() const
+void PushButton::OnLabelSet()
 {
-  return mToggleButton;
-}
+  Actor& label = GetLabel();
 
-void PushButton::SetToggled( bool toggle )
-{
-  if( !mDisabled && mToggleButton && ( toggle != mToggled ) )
+  if( label )
   {
-    mToggled = toggle;
-
-    Toolkit::PushButton handle( GetOwner() );
+    label.SetAnchorPoint( AnchorPoint::CENTER );
+    label.SetParentOrigin( ParentOrigin::CENTER );
 
-    // Notifies the painter the button has been toggled.
-    GetPushButtonPainter( mPainter )->Toggled( handle );
+    Toolkit::TextLabel textLabel = Toolkit::TextLabel::DownCast( label );
+    if( textLabel )
+    {
+      textLabel.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
+      textLabel.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
+      textLabel.SetProperty( Toolkit::TextLabel::Property::MULTI_LINE, true );
+    }
 
-    // Emit signal.
-    mStateChangedSignal.Emit( handle, mToggled );
+    ConfigureSizeNegotiation();
   }
 }
 
-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
+void PushButton::OnButtonImageSet()
 {
-  return mButtonImage;
+  ConfigureSizeNegotiation();
+  RelayoutRequest();
 }
 
-void PushButton::SetBackgroundImage( Image image )
+void PushButton::OnSelectedImageSet()
 {
-  SetBackgroundImage( ImageActor::New( image ) );
+  ConfigureSizeNegotiation();
+  RelayoutRequest();
 }
 
-void PushButton::SetBackgroundImage( Actor image )
+void PushButton::OnBackgroundImageSet()
 {
-  Toolkit::PushButton handle( GetOwner() );
-  GetPushButtonPainter( mPainter )->SetBackgroundImage( handle, image );
+  ConfigureSizeNegotiation();
+  RelayoutRequest();
 }
 
-Actor& PushButton::GetBackgroundImage()
+void PushButton::OnSelectedBackgroundImageSet()
 {
-  return mBackgroundImage;
+  ConfigureSizeNegotiation();
+  RelayoutRequest();
 }
 
-Actor PushButton::GetBackgroundImage() const
+void PushButton::OnDisabledImageSet()
 {
-  return mBackgroundImage;
+  ConfigureSizeNegotiation();
+  RelayoutRequest();
 }
 
-void PushButton::SetSelectedImage( Image image )
+void PushButton::OnDisabledSelectedImageSet()
 {
-  SetSelectedImage( ImageActor::New( image ) );
+  ConfigureSizeNegotiation();
+  RelayoutRequest();
 }
 
-void PushButton::SetSelectedImage( Actor image )
+void PushButton::OnDisabledBackgroundImageSet()
 {
-  Toolkit::PushButton handle( GetOwner() );
-  GetPushButtonPainter( mPainter )->SetSelectedImage( handle, image );
+  ConfigureSizeNegotiation();
+  RelayoutRequest();
 }
 
-Actor& PushButton::GetSelectedImage()
+void PushButton::OnSizeSet( const Vector3& targetSize )
 {
-  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;
-}
+  if( targetSize != mSize )
+  {
+    mSize = targetSize;
 
-Actor& PushButton::GetLabel()
-{
-  return mLabel;
-}
+    Actor& label = GetLabel();
 
-Actor& PushButton::GetFadeOutBackgroundImage()
-{
-  return mFadeOutBackgroundImage;
+    if( label )
+    {
+      label.SetSize( mSize );
+    }
+  }
 }
 
-Actor& PushButton::GetFadeOutButtonImage()
+void PushButton::PrepareForTranstionIn( Actor actor )
 {
-  return mFadeOutButtonImage;
+  actor.SetOpacity( 0.0f );
 }
 
-Toolkit::PushButton::PressedSignalType& PushButton::PressedSignal()
+void PushButton::PrepareForTranstionOut( Actor actor )
 {
-  return mPressedSignal;
+  actor.SetOpacity( 1.0f );
 }
 
-Toolkit::PushButton::ReleasedSignalType& PushButton::ReleasedSignal()
+void PushButton::OnTransitionIn( Actor actor )
 {
-  return mReleasedSignal;
+  FadeImageTo( actor, 1.f );
 }
 
-bool PushButton::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
+void PushButton::OnTransitionOut( Actor actor )
 {
-  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;
+  FadeImageTo( actor, 0.0f );
 }
 
-void PushButton::SetProperty( BaseObject* object, Property::Index propertyIndex, const Property::Value& value )
+void PushButton::FadeImageTo( Actor actor, float opacity )
 {
-  Toolkit::PushButton pushButton = Toolkit::PushButton::DownCast( Dali::BaseHandle( object ) );
-
-  if ( pushButton )
+  if( actor )
   {
-    PushButton& pushButtonImpl( GetImplementation( pushButton ) );
+    Dali::Animation transitionAnimation = GetTransitionAnimation();
+    DALI_ASSERT_DEBUG( transitionAnimation );
 
-    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 )
+    if( transitionAnimation )
     {
-      pushButtonImpl.SetDisabledImage( Scripting::NewActor( value.Get< Property::Map >() ) );
-    }
-    else if ( propertyIndex == Toolkit::Button::PROPERTY_LABEL_ACTOR )
-    {
-      pushButtonImpl.SetLabel( Scripting::NewActor( value.Get< Property::Map >() ) );
+      transitionAnimation.AnimateTo( Property( actor, Actor::Property::COLOR_ALPHA ), opacity );
     }
   }
 }
 
-Property::Value PushButton::GetProperty( BaseObject* object, Property::Index propertyIndex )
+Vector3 PushButton::GetNaturalSize()
 {
-  Property::Value value;
+  Vector3 size;
 
-  Toolkit::PushButton pushButton = Toolkit::PushButton::DownCast( Dali::BaseHandle( object ) );
-
-  if ( pushButton )
+  // If label, test against it's size
+  Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( GetLabel() );
+  if( label )
   {
-    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;
-    }
+    size.width  = std::max( size.width,  label.GetRelayoutSize( Dimension::WIDTH ) );
+    size.height = std::max( size.height, label.GetRelayoutSize( Dimension::HEIGHT ) );
+  }
+  else
+  {
+    // Check Image and Background image and use the largest size as the control's Natural size.
+    SizeOfActorIfLarger( GetButtonImage(), size );
+    SizeOfActorIfLarger( GetBackgroundImage(), size );
   }
 
-  return value;
+  return size;
 }
 
-void PushButton::OnButtonInitialize()
+void PushButton::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
 {
-  // Push button requires the Leave event.
-  Actor root = Self();
-  root.SetLeaveRequired( true );
+  ConfigureSizeNegotiation();
 }
 
-void PushButton::OnButtonDown()
+void PushButton::ConfigureSizeNegotiation()
 {
-  if( !mToggleButton )
-  {
-    Toolkit::PushButton handle( GetOwner() );
-
-    // Notifies the painter the button has been pressed.
-    GetPushButtonPainter( mPainter )->Pressed( handle );
+  std::vector< Actor > images;
+  images.reserve( 7 );
 
-    if( mAutoRepeating )
-    {
-      SetUpTimer( mInitialAutoRepeatingDelay );
-    }
+  images.push_back( GetButtonImage() );
+  images.push_back( GetSelectedImage() );
+  images.push_back( GetSelectedBackgroundImage() );
+  images.push_back( GetBackgroundImage() );
+  images.push_back( GetDisabledImage() );
+  images.push_back( GetDisabledSelectedImage() );
+  images.push_back( GetDisabledBackgroundImage() );
 
-    //Emit signal.
-    mPressedSignal.Emit( handle );
-  }
-}
+  Actor label = GetLabel();
 
-void PushButton::OnButtonUp()
-{
-  if( ButtonDown == mState )
+  for( unsigned int i = 0; i < Dimension::DIMENSION_COUNT; ++i )
   {
-    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 );
-    }
+    ConfigureSizeNegotiationDimension( static_cast< Dimension::Type >( 1 << i ), images, label );
   }
-}
 
-void PushButton::OnTouchPointLeave()
-{
-  if( ButtonDown == mState )
+  if( label )
   {
-    if( !mToggleButton )
-    {
-      Toolkit::PushButton handle( GetOwner() );
-
-      // Notifies the painter the button has been released.
-      GetPushButtonPainter( mPainter )->Released( handle );
-
-      if( mAutoRepeating )
-      {
-        mAutoRepeatingTimer.Reset();
-      }
+    Padding padding;
 
-      //Emit signal.
-      mReleasedSignal.Emit( handle );
+    if( label.GetResizePolicy( Dimension::WIDTH ) == ResizePolicy::USE_NATURAL_SIZE )
+    {
+      padding.left = TEXT_PADDING;
+      padding.right = TEXT_PADDING;
     }
-  }
-}
-
-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 )
+    if( label.GetResizePolicy( Dimension::HEIGHT ) == ResizePolicy::USE_NATURAL_SIZE )
     {
-      Toolkit::PushButton handle( GetOwner() );
-
-      // Notifies the painter the button has been released.
-      GetPushButtonPainter( mPainter )->Released( handle );
-
-      if( mAutoRepeating )
-      {
-        mAutoRepeatingTimer.Reset();
-      }
+      padding.top = TEXT_PADDING;
+      padding.bottom = TEXT_PADDING;
     }
-  }
-}
-
-PushButton::PushButton()
-: Button(),
-  mAutoRepeating( false ),
-  mInitialAutoRepeatingDelay( INITIAL_AUTOREPEATING_DELAY ),
-  mNextAutoRepeatingDelay( NEXT_AUTOREPEATING_DELAY ),
-  mToggleButton( false ),
-  mAutoRepeatingTimer(),
-  mToggled( false ),
-  mClickActionPerforming(false)
-{
-  // Creates specific painter.
-  mPainter = PushButtonDefaultPainterPtr( new PushButtonDefaultPainter() );
-}
 
-PushButton::~PushButton()
-{
-  if( mAutoRepeatingTimer )
-  {
-    mAutoRepeatingTimer.Reset();
+    label.SetPadding( padding );
   }
-
-  mPainter = NULL;
-}
-
-void PushButton::SetUpTimer( float delay )
-{
-  mAutoRepeatingTimer = Dali::Timer::New( static_cast<unsigned int>( 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);
 }
 
-Vector3 PushButton::GetNaturalSize()
+void PushButton::ConfigureSizeNegotiationDimension( Dimension::Type dimension, const std::vector< Actor >& images, Actor& label )
 {
-  Vector3 size = Control::GetNaturalSize();
+  ResizePolicy::Type imageResizePolicy = ResizePolicy::FILL_TO_PARENT;
+  ResizePolicy::Type labelResizePolicy = ResizePolicy::FILL_TO_PARENT;
 
-  const bool widthIsZero = EqualsZero( size.width );
-  const bool heightIsZero = EqualsZero( size.height );
-
-  if( widthIsZero || heightIsZero )
+  switch( Self().GetResizePolicy( dimension ) )
   {
-    // If background and background not scale9 try get size from that
-    ImageActor imageActor = FindImageActor( mButtonImage );
-    if( imageActor && imageActor.GetStyle() != ImageActor::STYLE_NINE_PATCH )
+    case ResizePolicy::FIT_TO_CHILDREN:
     {
-      Vector3 imageSize = RelayoutHelper::GetNaturalSize( imageActor );
-
-      if( widthIsZero )
-      {
-        size.width = imageSize.width;
-      }
-
-      if( heightIsZero )
-      {
-        size.height = imageSize.height;
-      }
+      imageResizePolicy = labelResizePolicy = ResizePolicy::USE_NATURAL_SIZE;
+      break;
     }
-
-    ImageActor backgroundImageActor = FindImageActor( mBackgroundImage );
-    if( backgroundImageActor && backgroundImageActor.GetStyle() != ImageActor::STYLE_NINE_PATCH )
+    case ResizePolicy::USE_NATURAL_SIZE:
     {
-      Vector3 imageSize = RelayoutHelper::GetNaturalSize( backgroundImageActor );
-
-      if( widthIsZero )
+      if( label )
       {
-        size.width = std::max( size.width, imageSize.width );
+        labelResizePolicy = ResizePolicy::USE_NATURAL_SIZE;
       }
-
-      if( heightIsZero )
+      else
       {
-        size.height = std::max( size.height, imageSize.height );
+        imageResizePolicy = ResizePolicy::USE_NATURAL_SIZE;
       }
+      break;
     }
-
-    // If label, test against it's size
-    Toolkit::TextView textView = Toolkit::TextView::DownCast( mLabel );
-    if( textView )
+    default:
     {
-      Vector3 textViewSize = textView.GetNaturalSize();
-
-      if( widthIsZero )
-      {
-        size.width = std::max( size.width, textViewSize.width + TEXT_PADDING * 2.0f );
-      }
-
-      if( heightIsZero )
-      {
-        size.height = std::max( size.height, textViewSize.height + TEXT_PADDING * 2.0f );
-      }
+      break;
     }
   }
 
-  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)
+  if( label )
   {
-    mClickActionPerforming = true;
-    OnButtonDown();
-    mState = ButtonDown;
-    OnButtonUp();
-    mClickActionPerforming = false;
+    label.SetResizePolicy( labelResizePolicy, dimension );
   }
-}
 
-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)
+  for( std::vector< Actor >::const_iterator it = images.begin(), itEnd = images.end(); it != itEnd; ++it )
   {
-    GetImplementation(button).DoClickAction(attributes);
-    ret = true;
+    Actor actor = *it;
+    if( actor )
+    {
+      actor.SetResizePolicy( imageResizePolicy, dimension );
+    }
   }
-
-  return ret;
 }
 
 } // namespace Internal