Changed all property & signal names to lowerCamelCase
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / buttons / push-button-impl.cpp
index 525cb3f..4331c87 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/devel-api/object/type-registry-helper.h>
+#include <dali/public-api/images/resource-image.h>
+#include <dali/devel-api/scripting/scripting.h>
 
 // INTERNAL INCLUDES
-#include "push-button-default-painter-impl.h"
-
-#include <dali-toolkit/internal/controls/relayout-helper.h>
+#include <dali-toolkit/public-api/controls/text-controls/text-label.h>
 
 namespace Dali
 {
@@ -41,56 +40,62 @@ namespace Internal
 namespace
 {
 
+const float   ANIMATION_TIME( 0.2f );
+const Padding DEFAULT_LABEL_PADDING( 12.0f, 12.0f, 12.0f, 12.0f );
+const Padding DEFAULT_ICON_PADDING( 12.0f, 12.0f, 12.0f, 12.0f );
+
 BaseHandle Create()
 {
   return Toolkit::PushButton::New();
 }
 
-TypeRegistration typeRegistration( typeid(Toolkit::PushButton), typeid(Toolkit::Button), Create );
+// Properties
 
-SignalConnectorType signalConnector1( typeRegistration, Toolkit::PushButton::SIGNAL_PRESSED , &PushButton::DoConnectSignal );
-SignalConnectorType signalConnector2( typeRegistration, Toolkit::PushButton::SIGNAL_RELEASED, &PushButton::DoConnectSignal );
+DALI_TYPE_REGISTRATION_BEGIN( Toolkit::PushButton, Toolkit::Button, Create )
 
-TypeAction action1( typeRegistration, Toolkit::PushButton::ACTION_PUSH_BUTTON_CLICK, &PushButton::DoAction );
+DALI_PROPERTY_REGISTRATION( Toolkit, PushButton, "unselectedIcon",  STRING, UNSELECTED_ICON )
+DALI_PROPERTY_REGISTRATION( Toolkit, PushButton, "selectedIcon",  STRING, SELECTED_ICON )
+DALI_PROPERTY_REGISTRATION( Toolkit, PushButton, "iconAlignment",  STRING, ICON_ALIGNMENT )
+DALI_PROPERTY_REGISTRATION( Toolkit, PushButton, "labelPadding",  STRING, LABEL_PADDING )
+DALI_PROPERTY_REGISTRATION( Toolkit, PushButton, "iconPadding",  STRING, ICON_PADDING )
 
-} // unnamed namespace
+DALI_TYPE_REGISTRATION_END()
 
-namespace
-{
-
-const unsigned int INITIAL_AUTOREPEATING_DELAY( 0.15f );
-const unsigned int NEXT_AUTOREPEATING_DELAY( 0.05f );
+/*
+ * Table to define Text-to-enum conversions for IconAlignment.
+ */
+const Dali::Scripting::StringEnum IconAlignmentTable[] = {
+  { "LEFT",   Toolkit::Internal::PushButton::LEFT },
+  { "RIGHT",  Toolkit::Internal::PushButton::RIGHT },
+  { "TOP",    Toolkit::Internal::PushButton::TOP },
+  { "BOTTOM", Toolkit::Internal::PushButton::BOTTOM },
+}; const unsigned int IconAlignmentTableCount = sizeof( IconAlignmentTable ) / sizeof( IconAlignmentTable[0] );
+
+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";
 
-const float TEXT_PADDING = 12.0f;
+} // unnamed namespace
 
-// Helper function used to cast a ButtonPainter to PushButtonDefaultPainter
-PushButtonDefaultPainterPtr GetPushButtonPainter( Dali::Toolkit::Internal::ButtonPainterPtr painter )
+namespace
 {
-  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()
@@ -108,631 +113,491 @@ Dali::Toolkit::PushButton PushButton::New()
   return pushButton;
 }
 
-void PushButton::SetAutoRepeating( bool autoRepeating )
+PushButton::PushButton()
+: Button(),
+  mLabelPadding( DEFAULT_LABEL_PADDING ),
+  mIconPadding( DEFAULT_ICON_PADDING ),
+  mIconAlignment( RIGHT ),
+  mSize()
 {
-  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 );
+  SetAnimationTime( ANIMATION_TIME );
 }
 
-bool PushButton::IsAutoRepeating() const
+PushButton::~PushButton()
 {
-  return mAutoRepeating;
 }
 
-void PushButton::SetInitialAutoRepeatingDelay( float initialAutoRepeatingDelay )
+void PushButton::OnButtonInitialize()
 {
-  DALI_ASSERT_ALWAYS( initialAutoRepeatingDelay > 0.f );
-  mInitialAutoRepeatingDelay = initialAutoRepeatingDelay;
-}
+  // Push button requires the Leave event.
+  Actor self = Self();
+  self.SetLeaveRequired( true );
 
-float PushButton::GetInitialAutoRepeatingDelay() const
-{
-  return mInitialAutoRepeatingDelay;
-}
+  // Set resize policy to natural size so that buttons will resize to background images
+  self.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
 
-void PushButton::SetNextAutoRepeatingDelay( float nextAutoRepeatingDelay )
-{
-  DALI_ASSERT_ALWAYS( nextAutoRepeatingDelay > 0.f );
-  mNextAutoRepeatingDelay = nextAutoRepeatingDelay;
+  SetUnselectedImage( UNSELECTED_BUTTON_IMAGE_DIR );
+  SetSelectedImage( SELECTED_BUTTON_IMAGE_DIR );
+  SetDisabledImage( DISABLED_UNSELECTED_BUTTON_IMAGE_DIR );
+  SetDisabledSelectedImage( DISABLED_SELECTED_BUTTON_IMAGE_DIR );
 }
 
-float PushButton::GetNextAutoRepeatingDelay() const
+void PushButton::SetIcon( DecorationState state, const std::string iconFilename )
 {
-  return mNextAutoRepeatingDelay;
+  mIconName[ state ] = iconFilename;
+  SetDecoration( state, ImageActor::New( Dali::ResourceImage::New( iconFilename ) ) );
+  ConfigureSizeNegotiation();
 }
 
-void PushButton::SetToggleButton( bool toggle )
+std::string& PushButton::GetIcon( DecorationState state )
 {
-  mToggleButton = toggle;
-
-  // A toggle button can't be an autorepeating button.
-  if( toggle )
-  {
-    mAutoRepeating = false;
-
-    // Notifies the painter.
-    GetPushButtonPainter( mPainter )->SetAutoRepeating( mAutoRepeating );
-  }
+  return mIconName[ state ];
 }
 
-bool PushButton::IsToggleButton() const
+void PushButton::SetIconAlignment( const PushButton::IconAlignment iconAlignment )
 {
-  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 );
-  }
+  mIconAlignment = iconAlignment;
+  ConfigureSizeNegotiation();
 }
 
-bool PushButton::IsToggled() const
+const PushButton::IconAlignment PushButton::GetIconAlignment() const
 {
-  return mToggleButton && mToggled;
+  return mIconAlignment;
 }
 
-void PushButton::SetButtonImage( Image image )
+void PushButton::SetLabelPadding( const Vector4& padding )
 {
-  SetButtonImage( ImageActor::New( image ) );
+  mLabelPadding = Padding( padding.x, padding.y, padding.z, padding.w );
+  ConfigureSizeNegotiation();
 }
 
-void PushButton::SetButtonImage( Actor image )
+Vector4 PushButton::GetLabelPadding()
 {
-  Toolkit::PushButton handle( GetOwner() );
-  GetPushButtonPainter( mPainter )->SetButtonImage( handle, image );
+  return Vector4( mLabelPadding.left, mLabelPadding.right, mLabelPadding.top, mLabelPadding.bottom );
 }
 
-Actor& PushButton::GetButtonImage()
+void PushButton::SetIconPadding( const Vector4& padding )
 {
-  return mButtonImage;
+  mIconPadding = Padding( padding.x, padding.y, padding.z, padding.w );
+  ConfigureSizeNegotiation();
 }
 
-Actor PushButton::GetButtonImage() const
+Vector4 PushButton::GetIconPadding()
 {
-  return mButtonImage;
+  return Vector4( mIconPadding.left, mIconPadding.right, mIconPadding.top, mIconPadding.bottom );
 }
 
-void PushButton::SetBackgroundImage( Image image )
+void PushButton::SetProperty( BaseObject* object, Property::Index propertyIndex, const Property::Value& value )
 {
-  SetBackgroundImage( ImageActor::New( image ) );
-}
+  Toolkit::PushButton pushButton = Toolkit::PushButton::DownCast( Dali::BaseHandle( object ) );
 
-void PushButton::SetBackgroundImage( Actor image )
-{
-  Toolkit::PushButton handle( GetOwner() );
-  GetPushButtonPainter( mPainter )->SetBackgroundImage( handle, image );
-}
+  if ( pushButton )
+  {
+    PushButton& pushButtonImpl( GetImplementation( pushButton ) );
 
-Actor& PushButton::GetBackgroundImage()
-{
-  return mBackgroundImage;
+    switch ( propertyIndex )
+    {
+      case Toolkit::PushButton::Property::UNSELECTED_ICON:
+      {
+        pushButtonImpl.SetIcon( UNSELECTED_DECORATION, value.Get< std::string >() );
+        break;
+      }
+      case Toolkit::PushButton::Property::SELECTED_ICON:
+      {
+        pushButtonImpl.SetIcon( SELECTED_DECORATION, value.Get< std::string >() );
+        break;
+      }
+      case Toolkit::PushButton::Property::ICON_ALIGNMENT:
+      {
+        IconAlignment iconAlignment;
+        if( Scripting::GetEnumeration< IconAlignment >( value.Get< std::string >().c_str(), IconAlignmentTable, IconAlignmentTableCount, iconAlignment ) )
+        {
+          pushButtonImpl.SetIconAlignment( iconAlignment );
+        }
+        break;
+      }
+      case Toolkit::PushButton::Property::LABEL_PADDING:
+      {
+        pushButtonImpl.SetLabelPadding( value.Get< Vector4 >() );
+        break;
+      }
+      case Toolkit::PushButton::Property::ICON_PADDING:
+      {
+        pushButtonImpl.SetIconPadding( value.Get< Vector4 >() );
+        break;
+      }
+    }
+  }
 }
 
-Actor PushButton::GetBackgroundImage() const
+Property::Value PushButton::GetProperty( BaseObject* object, Property::Index propertyIndex )
 {
-  return mBackgroundImage;
-}
+  Property::Value value;
 
-void PushButton::SetSelectedImage( Image image )
-{
-  SetSelectedImage( ImageActor::New( image ) );
-}
+  Toolkit::PushButton pushButton = Toolkit::PushButton::DownCast( Dali::BaseHandle( object ) );
 
-void PushButton::SetSelectedImage( Actor image )
-{
-  Toolkit::PushButton handle( GetOwner() );
-  GetPushButtonPainter( mPainter )->SetSelectedImage( handle, image );
-}
+  if ( pushButton )
+  {
+    PushButton& pushButtonImpl( GetImplementation( pushButton ) );
 
-Actor& PushButton::GetSelectedImage()
-{
-  return mSelectedImage;
-}
+    switch ( propertyIndex )
+    {
+      case Toolkit::PushButton::Property::UNSELECTED_ICON:
+      {
+        value = pushButtonImpl.GetIcon( UNSELECTED_DECORATION );
+        break;
+      }
+      case Toolkit::PushButton::Property::SELECTED_ICON:
+      {
+        value = pushButtonImpl.GetIcon( UNSELECTED_DECORATION );
+        break;
+      }
+      case Toolkit::PushButton::Property::ICON_ALIGNMENT:
+      {
+        value = Scripting::GetLinearEnumerationName< IconAlignment >( pushButtonImpl.GetIconAlignment(), IconAlignmentTable, IconAlignmentTableCount );
+        break;
+      }
+      case Toolkit::PushButton::Property::LABEL_PADDING:
+      {
+        value = pushButtonImpl.GetLabelPadding();
+        break;
+      }
+      case Toolkit::PushButton::Property::ICON_PADDING:
+      {
+        value = pushButtonImpl.GetIconPadding();
+        break;
+      }
+    }
+  }
 
-Actor PushButton::GetSelectedImage() const
-{
-  return mSelectedImage;
+  return value;
 }
 
-void PushButton::SetDisabledBackgroundImage( Image image )
+void PushButton::OnLabelSet( bool noPadding )
 {
-  SetDisabledBackgroundImage( ImageActor::New( image ) );
-}
+  Actor& label = GetLabelActor();
 
-void PushButton::SetDisabledBackgroundImage( Actor image )
-{
-  Toolkit::PushButton handle( GetOwner() );
-  GetPushButtonPainter( mPainter )->SetDisabledBackgroundImage( handle, image );
-}
+  if( label )
+  {
+    if( noPadding )
+    {
+      mLabelPadding = Padding( 0.0f, 0.0f, 0.0f, 0.0f );
+    }
 
-Actor& PushButton::GetDisabledBackgroundImage()
-{
-  return mDisabledBackgroundImage;
+    Toolkit::TextLabel textLabel = Toolkit::TextLabel::DownCast( label );
+    if( textLabel )
+    {
+      textLabel.SetProperty( Toolkit::TextLabel::Property::MULTI_LINE, false );
+    }
+  }
+  ConfigureSizeNegotiation();
 }
 
-Actor PushButton::GetDisabledBackgroundImage() const
+void PushButton::OnButtonImageSet()
 {
-  return mDisabledBackgroundImage;
+  ConfigureSizeNegotiation();
 }
 
-void PushButton::SetDisabledImage( Image image )
+void PushButton::OnSelectedImageSet()
 {
-  SetDisabledImage( ImageActor::New( image ) );
+  ConfigureSizeNegotiation();
 }
 
-void PushButton::SetDisabledImage( Actor image )
+void PushButton::OnBackgroundImageSet()
 {
-  Toolkit::PushButton handle( GetOwner() );
-  GetPushButtonPainter( mPainter )->SetDisabledImage( handle, image );
+  ConfigureSizeNegotiation();
 }
 
-Actor& PushButton::GetDisabledImage()
+void PushButton::OnSelectedBackgroundImageSet()
 {
-  return mDisabledImage;
+  ConfigureSizeNegotiation();
 }
 
-Actor PushButton::GetDisabledImage() const
+void PushButton::OnDisabledImageSet()
 {
-  return mDisabledImage;
+  ConfigureSizeNegotiation();
 }
 
-void PushButton::SetLabel( const std::string& label )
+void PushButton::OnDisabledSelectedImageSet()
 {
-  // TODO
+  ConfigureSizeNegotiation();
 }
 
-void PushButton::SetLabel( Actor label )
+void PushButton::OnDisabledBackgroundImageSet()
 {
-  Toolkit::PushButton handle( GetOwner() );
-  GetPushButtonPainter( mPainter )->SetLabel( handle, label );
+  ConfigureSizeNegotiation();
 }
 
-Actor PushButton::GetLabel() const
+void PushButton::OnSizeSet( const Vector3& targetSize )
 {
-  return mLabel;
-}
+  if( targetSize != mSize )
+  {
+    mSize = targetSize;
 
-Actor& PushButton::GetLabel()
-{
-  return mLabel;
-}
+    Actor& label = GetLabelActor();
 
-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 label, test against it's size
+  Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( GetLabelActor() );
 
-  if ( pushButton )
+  Actor icon = GetDecoration( UNSELECTED_DECORATION );
+  if( label || icon )
   {
-    PushButton& pushButtonImpl( GetImplementation( pushButton ) );
+    Vector3 labelSize( Vector3::ZERO );
+    Vector3 iconSize( Vector3::ZERO );
 
-    if ( propertyIndex == Toolkit::Button::PROPERTY_AUTO_REPEATING )
+    if( label )
     {
-      value = pushButtonImpl.mAutoRepeating;
+      Vector3 labelNaturalSize = label.GetNaturalSize();
+      labelSize.width = labelNaturalSize.width + mLabelPadding.left + mLabelPadding.right;
+      labelSize.height = labelNaturalSize.height + mLabelPadding.top + mLabelPadding.bottom;
     }
-    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.
-  Actor root = Self();
-  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 )
+    if( icon )
     {
-      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 );
+      Vector3 iconNaturalSize = icon.GetNaturalSize();
+      iconSize.width = iconNaturalSize.width + mIconPadding.left + mIconPadding.right;
+      iconSize.height = iconNaturalSize.height + mIconPadding.top + mIconPadding.bottom;
 
-      // Emit signal.
-      mStateChangedSignal.Emit( handle, mToggled );
+      switch( mIconAlignment )
+      {
+        case LEFT:
+        case RIGHT:
+        {
+          size.width = labelSize.width + iconSize.width;
+          size.height = std::max( labelSize.height, iconSize.height );
+          break;
+        }
+        case TOP:
+        case BOTTOM:
+        {
+          size.width = std::max( labelSize.width, iconSize.width );
+          size.height = labelSize.height + iconSize.height;
+          break;
+        }
+      }
     }
     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 );
+      // No icon, so size is the same as label size.
+      // (If there is no label this is zero).
+      size = labelSize;
     }
   }
-}
-
-void PushButton::OnTouchPointLeave()
-{
-  if( ButtonDown == mState )
+  else
   {
-    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 );
-    }
+    // Check Image and Background image and use the largest size as the control's Natural size.
+    SizeOfActorIfLarger( GetUnselectedImage(), size );
+    SizeOfActorIfLarger( GetBackgroundImage(), size );
   }
-}
 
-void PushButton::OnTouchPointInterrupted()
-{
-  OnTouchPointLeave();
+  return size;
 }
 
-void PushButton::OnAnimationTimeSet( float animationTime )
+void PushButton::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
 {
-  GetPushButtonPainter( mPainter )->SetAnimationTime( animationTime );
+  ConfigureSizeNegotiation();
 }
 
-float PushButton::OnAnimationTimeRequested() const
+void PushButton::ConfigureSizeNegotiation()
 {
-  return GetPushButtonPainter( mPainter )->GetAnimationTime();
-}
+  std::vector< Actor > images;
+  images.reserve( 7 );
 
-void PushButton::OnButtonStageDisconnection()
-{
-  if( ButtonDown == mState )
-  {
-    if( !mToggleButton )
-    {
-      Toolkit::PushButton handle( GetOwner() );
+  images.push_back( GetUnselectedImage() );
+  images.push_back( GetSelectedImage() );
+  images.push_back( GetSelectedBackgroundImage() );
+  images.push_back( GetBackgroundImage() );
+  images.push_back( GetDisabledImage() );
+  images.push_back( GetDisabledSelectedImage() );
+  images.push_back( GetDisabledBackgroundImage() );
 
-      // Notifies the painter the button has been released.
-      GetPushButtonPainter( mPainter )->Released( handle );
+  Actor label = GetLabelActor();
 
-      if( mAutoRepeating )
-      {
-        mAutoRepeatingTimer.Reset();
-      }
-    }
+  for( unsigned int i = 0; i < Dimension::DIMENSION_COUNT; ++i )
+  {
+    ConfigureSizeNegotiationDimension( static_cast< Dimension::Type >( 1 << i ), images, label );
   }
-}
 
-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() );
-}
+  // Add any vertical padding directly to the actors.
+  Actor icon = GetDecoration( UNSELECTED_DECORATION );
+  Actor selectedIcon = GetDecoration( SELECTED_DECORATION );
+  bool iconExists = icon || selectedIcon;
 
-PushButton::~PushButton()
-{
-  if( mAutoRepeatingTimer )
+  if( label )
   {
-    mAutoRepeatingTimer.Reset();
+    label.SetPadding( mLabelPadding );
   }
-
-  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 )
+  if( icon )
   {
-    // 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()
-{
-  Vector3 size = Control::GetNaturalSize();
+    icon.SetPadding( mIconPadding );
+  }
+  if( selectedIcon )
+  {
+    selectedIcon.SetPadding( mIconPadding );
+  }
 
-  const bool widthIsZero = EqualsZero( size.width );
-  const bool heightIsZero = EqualsZero( size.height );
+  // Calculate and apply horizontal alignments and offsets
+  // to text and icon (depending on existence).
+  Vector3 iconPosition( Vector3::ZERO );
+  Vector3 labelPosition( Vector3::ZERO );
+  Vector3 iconAnchoring( AnchorPoint::CENTER );
+  Vector3 labelAnchoring( AnchorPoint::CENTER );
+  std::string horizontalLabelAlignment = "CENTER";
+  std::string verticalLabelAlignment = "CENTER";
 
-  if( widthIsZero || heightIsZero )
+  if( iconExists && label )
   {
-    // If background and background not scale9 try get size from that
-    ImageActor imageActor = FindImageActor( mButtonImage );
-    if( imageActor && imageActor.GetStyle() != ImageActor::STYLE_NINE_PATCH )
+    // There is an icon and a label to lay out.
+    switch( mIconAlignment )
     {
-      Vector3 imageSize = RelayoutHelper::GetNaturalSize( imageActor );
-
-      if( widthIsZero )
+      case LEFT:
       {
-        size.width = imageSize.width;
+        iconPosition.x = mIconPadding.left;
+        labelPosition.x = -mLabelPadding.right;
+        iconAnchoring = AnchorPoint::CENTER_LEFT;
+        labelAnchoring = AnchorPoint::CENTER_RIGHT;
+        horizontalLabelAlignment = "END";
+        break;
       }
-
-      if( heightIsZero )
+      case RIGHT:
       {
-        size.height = imageSize.height;
+        iconPosition.x = -mIconPadding.right;
+        labelPosition.x = mLabelPadding.left;
+        iconAnchoring = AnchorPoint::CENTER_RIGHT;
+        labelAnchoring = AnchorPoint::CENTER_LEFT;
+        horizontalLabelAlignment = "BEGIN";
+        break;
       }
-    }
-
-    ImageActor backgroundImageActor = FindImageActor( mBackgroundImage );
-    if( backgroundImageActor && backgroundImageActor.GetStyle() != ImageActor::STYLE_NINE_PATCH )
-    {
-      Vector3 imageSize = RelayoutHelper::GetNaturalSize( backgroundImageActor );
-
-      if( widthIsZero )
+      case TOP:
       {
-        size.width = std::max( size.width, imageSize.width );
+        iconPosition.y = mIconPadding.top;
+        labelPosition.y = -mLabelPadding.bottom;
+        iconAnchoring = AnchorPoint::TOP_CENTER;
+        labelAnchoring = AnchorPoint::BOTTOM_CENTER;
+        verticalLabelAlignment = "BOTTOM";
+        break;
       }
-
-      if( heightIsZero )
+      case BOTTOM:
       {
-        size.height = std::max( size.height, imageSize.height );
+        iconPosition.y = -mIconPadding.bottom;
+        labelPosition.y = mLabelPadding.top;
+        iconAnchoring = AnchorPoint::BOTTOM_CENTER;
+        labelAnchoring = AnchorPoint::TOP_CENTER;
+        verticalLabelAlignment = "TOP";
+        break;
       }
     }
   }
 
-  return size;
-}
+  // Note: If there is only an icon, or only a label, the default values are now correct.
+  // Setup the icon(s) with the precalculated values.
+  if( icon )
+  {
+    icon.SetPosition( iconPosition );
+    icon.SetParentOrigin( iconAnchoring );
+    icon.SetAnchorPoint( iconAnchoring );
+  }
+  if( selectedIcon )
+  {
+    selectedIcon.SetPosition( iconPosition );
+    selectedIcon.SetParentOrigin( iconAnchoring );
+    selectedIcon.SetAnchorPoint( iconAnchoring );
+  }
 
-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)
+  // Setup the label.
+  if( label )
   {
-    mClickActionPerforming = true;
-    OnButtonDown();
-    mState = ButtonDown;
-    OnButtonUp();
-    mClickActionPerforming = false;
+    label.SetPosition( labelPosition );
+    label.SetParentOrigin( labelAnchoring );
+    label.SetAnchorPoint( labelAnchoring );
+    label.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, horizontalLabelAlignment );
+    label.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, verticalLabelAlignment );
   }
+
+  RelayoutRequest();
 }
 
-bool PushButton::DoAction(BaseObject* object, const std::string& actionName, const PropertyValueContainer& attributes)
-{
-  bool ret = false;
 
-  Dali::BaseHandle handle(object);
+void PushButton::ConfigureSizeNegotiationDimension( Dimension::Type dimension, const std::vector< Actor >& images, Actor& label )
+{
+  ResizePolicy::Type imageResizePolicy = ResizePolicy::FILL_TO_PARENT;
+  ResizePolicy::Type labelResizePolicy = ResizePolicy::FILL_TO_PARENT;
 
-  Toolkit::PushButton button = Toolkit::PushButton::DownCast(handle);
+  ResizePolicy::Type resizePolicy = Self().GetResizePolicy( dimension );
 
-  DALI_ASSERT_ALWAYS(button);
+  if( resizePolicy == ResizePolicy::FIT_TO_CHILDREN || resizePolicy == ResizePolicy::USE_NATURAL_SIZE )
+  {
+    if( label )
+    {
+      labelResizePolicy = ResizePolicy::USE_NATURAL_SIZE;
+    }
+    else
+    {
+      imageResizePolicy = ResizePolicy::USE_NATURAL_SIZE;
+    }
+  }
 
-  if(Toolkit::PushButton::ACTION_PUSH_BUTTON_CLICK == actionName)
+  if( label )
   {
-    GetImplementation(button).DoClickAction(attributes);
-    ret = true;
+    label.SetResizePolicy( labelResizePolicy, dimension );
   }
 
-  return ret;
+  for( std::vector< Actor >::const_iterator it = images.begin(), itEnd = images.end(); it != itEnd; ++it )
+  {
+    Actor actor = *it;
+    if( actor )
+    {
+      actor.SetResizePolicy( imageResizePolicy, dimension );
+    }
+  }
 }
 
+
 } // namespace Internal
 
 } // namespace Toolkit