-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 )
- {
- SetUpTimer( mInitialAutoRepeatingDelay );
- }
-
- //Emit signal.
- mPressedSignalV2.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.
- mToggledSignalV2.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.
- mReleasedSignalV2.Emit( handle );
- mClickedSignalV2.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.
- mReleasedSignalV2.Emit( handle );
- }
- }
-}
-
-void PushButton::OnTouchPointInterrupted()
-{
- OnTouchPointLeave();
-}
-
-void PushButton::OnAnimationTimeSet( float animationTime )
-{
- GetPushButtonPainter( mPainter )->SetAnimationTime( animationTime );
-}
-
-float PushButton::OnAnimationTimeRequested() const
-{
- return GetPushButtonPainter( mPainter )->GetAnimationTime();
-}
-
-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();
- }
-
- 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( !mDimmed )
- {
- // 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 = mReleasedSignalV2.Emit( handle );
- consumed |= mClickedSignalV2.Emit( handle );
- consumed |= mPressedSignalV2.Emit( handle );
- }
-
- return consumed;
-}
-
-void PushButton::OnActivated()
-{
- // When the button is activated, it performs the click action
- std::vector<Property::Value> attributes;
- DoClickAction(attributes);
-}
-
-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 std::vector<Property::Value>& 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;
-}
-