+void Button::SetLabel( const std::string& label )
+{
+ Toolkit::TextLabel textLabel = Toolkit::TextLabel::New( label );
+ SetLabel( textLabel );
+}
+
+void Button::SetLabel( Actor label )
+{
+ if( mLabel != label )
+ {
+ if( mLabel && mLabel.GetParent() )
+ {
+ mLabel.GetParent().Remove( mLabel );
+ }
+
+ mLabel = label;
+ mLabel.SetPosition( 0.f, 0.f );
+
+ // label should be the top of the button
+ Self().Add( mLabel );
+
+ OnLabelSet();
+
+ RelayoutRequest();
+ }
+}
+
+Actor Button::GetLabel() const
+{
+ return mLabel;
+}
+
+Actor& Button::GetLabel()
+{
+ return mLabel;
+}
+
+void Button::SetButtonImage( Actor image )
+{
+ StopTransitionAnimation();
+
+ if( mUnselectedContent && mUnselectedContent.GetParent() )
+ {
+ Self().Remove( mUnselectedContent );
+ }
+
+ mUnselectedContent = image;
+ if( mUnselectedContent )
+ {
+ mUnselectedContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+ mUnselectedContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
+ mUnselectedContent.SetPosition( 0.f, 0.f );
+ }
+ ResetImageLayers();
+ OnButtonImageSet();
+
+ RelayoutRequest();
+}
+
+Actor Button::GetButtonImage() const
+{
+ return mUnselectedContent;
+}
+
+Actor& Button::GetButtonImage()
+{
+ return mUnselectedContent;
+}
+
+void Button::SetSelectedImage( Actor image )
+{
+ StopTransitionAnimation();
+
+ if( mSelectedContent && mSelectedContent.GetParent() )
+ {
+ Self().Remove( mSelectedContent );
+ }
+
+ mSelectedContent = image;
+ if( mSelectedContent )
+ {
+ mSelectedContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+ mSelectedContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
+ mSelectedContent.SetPosition( 0.f, 0.f );
+ }
+ ResetImageLayers();
+ OnSelectedImageSet();
+
+ RelayoutRequest();
+}
+
+Actor Button::GetSelectedImage() const
+{
+ return mSelectedContent;
+}
+
+Actor& Button::GetSelectedImage()
+{
+ return mSelectedContent;
+}
+
+void Button::SetBackgroundImage( Actor image )
+{
+ StopTransitionAnimation();
+
+ if( mBackgroundContent && mBackgroundContent.GetParent() )
+ {
+ Self().Remove( mBackgroundContent );
+ }
+
+ mBackgroundContent = image;
+ if( mBackgroundContent )
+ {
+ mBackgroundContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+ mBackgroundContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
+ mBackgroundContent.SetPosition( 0.f, 0.f );
+ }
+ ResetImageLayers();
+ OnBackgroundImageSet();
+
+ RelayoutRequest();
+}
+
+Actor Button::GetBackgroundImage() const
+{
+ return mBackgroundContent;
+}
+
+Actor& Button::GetBackgroundImage()
+{
+ return mBackgroundContent;
+}
+
+void Button::SetSelectedBackgroundImage( Actor image )
+{
+ StopTransitionAnimation();
+
+ if( mSelectedBackgroundContent && mSelectedBackgroundContent.GetParent() )
+ {
+ Self().Remove( mSelectedBackgroundContent );
+ }
+
+ mSelectedBackgroundContent = image;
+ if( mSelectedBackgroundContent )
+ {
+ mSelectedBackgroundContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+ mSelectedBackgroundContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
+ mSelectedBackgroundContent.SetPosition( 0.f, 0.f );
+ }
+ ResetImageLayers();
+ OnSelectedBackgroundImageSet();
+
+ RelayoutRequest();
+}
+
+Actor Button::GetSelectedBackgroundImage() const
+{
+ return mSelectedBackgroundContent;
+}
+
+Actor& Button::GetSelectedBackgroundImage()
+{
+ return mSelectedBackgroundContent;
+}
+
+void Button::SetDisabledImage( Actor image )
+{
+ StopTransitionAnimation();
+
+ if( mDisabledContent && mDisabledContent.GetParent() )
+ {
+ Self().Remove( mDisabledContent );
+ }
+
+ mDisabledContent = image;
+ if( mDisabledContent )
+ {
+ mDisabledContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+ mDisabledContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
+ mDisabledContent.SetPosition( 0.f, 0.f );
+ }
+
+ ResetImageLayers();
+ OnDisabledImageSet();
+}
+
+Actor Button::GetDisabledImage() const
+{
+ return mDisabledContent;
+}
+
+Actor& Button::GetDisabledImage()
+{
+ return mDisabledContent;
+}
+
+void Button::SetDisabledSelectedImage( Actor image )
+{
+ StopTransitionAnimation();
+
+ if( mDisabledSelectedContent && mDisabledSelectedContent.GetParent() )
+ {
+ Self().Remove( mDisabledSelectedContent );
+ }
+
+ mDisabledSelectedContent = image;
+ if( mDisabledSelectedContent )
+ {
+ mDisabledSelectedContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+ mDisabledSelectedContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
+ mDisabledSelectedContent.SetPosition( 0.f, 0.f );
+ }
+
+ ResetImageLayers();
+ OnDisabledSelectedImageSet();
+}
+
+Actor Button::GetDisabledSelectedImage() const
+{
+ return mDisabledSelectedContent;
+}
+
+Actor& Button::GetDisabledSelectedImage()
+{
+ return mDisabledSelectedContent;
+}
+
+void Button::SetDisabledBackgroundImage( Actor image )
+{
+ StopTransitionAnimation();
+
+ if( mDisabledBackgroundContent && mDisabledBackgroundContent.GetParent() )
+ {
+ Self().Remove( mDisabledBackgroundContent );
+ }
+
+ mDisabledBackgroundContent = image;
+ if( mDisabledBackgroundContent )
+ {
+ mDisabledBackgroundContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+ mDisabledBackgroundContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
+ mDisabledBackgroundContent.SetPosition( 0.f, 0.f );
+ }
+ ResetImageLayers();
+ OnDisabledBackgroundImageSet();
+}
+
+Actor Button::GetDisabledBackgroundImage() const
+{
+ return mDisabledBackgroundContent;
+}
+
+Actor& Button::GetDisabledBackgroundImage()
+{
+ return mDisabledBackgroundContent;
+}
+
+bool Button::DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes )
+{
+ bool ret = false;
+
+ Dali::BaseHandle handle( object );
+
+ Toolkit::Button button = Toolkit::Button::DownCast( handle );
+
+ DALI_ASSERT_ALWAYS( button );
+
+ if( 0 == strcmp( actionName.c_str(), ACTION_BUTTON_CLICK ) )
+ {
+ ret = GetImplementation( button ).DoClickAction( attributes );
+ }
+
+ return ret;
+}
+
+bool Button::DoClickAction( const Property::Map& 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;
+
+ return true;
+ }
+
+ return false;
+}
+
+void Button::OnButtonStageDisconnection()
+{
+ if( ButtonDown == mState )
+ {
+ if( !mTogglableButton )
+ {
+ Released();
+
+ if( mAutoRepeating )
+ {
+ mAutoRepeatingTimer.Reset();
+ }
+ }
+ }
+}
+
+void Button::OnButtonDown()
+{
+ if( !mTogglableButton )
+ {
+ Toolkit::Button handle( GetOwner() );
+
+ Pressed();
+
+ if( mAutoRepeating )
+ {
+ SetUpTimer( mInitialAutoRepeatingDelay );
+ }
+
+ //Emit signal.
+ mPressedSignal.Emit( handle );
+ }
+}
+
+void Button::OnButtonUp()
+{
+ if( ButtonDown == mState )
+ {
+ if( mTogglableButton )
+ {
+ SetSelected( !mSelected );
+ }
+ else
+ {
+ Released();
+
+ if( mAutoRepeating )
+ {
+ mAutoRepeatingTimer.Reset();
+ }
+
+ Toolkit::Button handle( GetOwner() );
+
+ //Emit signal.
+ mReleasedSignal.Emit( handle );
+ mClickedSignal.Emit( handle );
+ }
+ }
+}
+
+void Button::OnTouchPointLeave()
+{
+ if( ButtonDown == mState )
+ {
+ if( !mTogglableButton )
+ {
+ Toolkit::Button handle( GetOwner() );
+
+ Released();