-//
-// Copyright (c) 2014 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Flora License, Version 1.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://floralicense.org/license/
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an AS IS BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
// CLASS HEADER
-
#include "push-button-impl.h"
// EXTERNAL INCLUDES
-
-#include <algorithm>
+#include <dali/devel-api/scripting/scripting.h>
+#include <dali/integration-api/debug.h>
+#include <dali/public-api/object/type-registry-helper.h>
+#include <dali/public-api/object/type-registry.h>
// INTERNAL INCLUDES
+#include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
+#include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
+#include <dali-toolkit/public-api/controls/image-view/image-view.h>
+#include <dali-toolkit/public-api/controls/text-controls/text-label.h>
-#include "push-button-default-painter-impl.h"
-
-#include <dali-toolkit/public-api/controls/text-view/text-view.h>
+#if defined(DEBUG_ENABLED)
+extern Debug::Filter* gLogButtonFilter;
+#endif
namespace Dali
{
-
namespace Toolkit
{
-
namespace Internal
{
-
namespace
{
-
-using namespace Dali;
-
BaseHandle Create()
{
return Toolkit::PushButton::New();
}
-TypeRegistration typeRegistration( typeid(Toolkit::PushButton), typeid(Toolkit::Button), Create );
+// Properties
-SignalConnectorType signalConnector1( typeRegistration, Toolkit::PushButton::SIGNAL_TOGGLED , &PushButton::DoConnectSignal );
-SignalConnectorType signalConnector2( typeRegistration, Toolkit::PushButton::SIGNAL_PRESSED , &PushButton::DoConnectSignal );
-SignalConnectorType signalConnector3( 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, "labelPadding", STRING, LABEL_PADDING)
+DALI_PROPERTY_REGISTRATION(Toolkit, PushButton, "iconPadding", STRING, ICON_PADDING)
-}
+DALI_TYPE_REGISTRATION_END()
+} // unnamed namespace
namespace
{
- const unsigned int INITIAL_AUTOREPEATING_DELAY( 0.15f );
- const unsigned int NEXT_AUTOREPEATING_DELAY( 0.05f );
-
- // Helper function used to cast a ButtonPainter to PushButtonDefaultPainter
- PushButtonDefaultPainterPtr GetPushButtonPainter( Dali::Toolkit::Internal::ButtonPainterPtr painter )
- {
- return static_cast<PushButtonDefaultPainter*>( painter.Get() );
- }
-} // namespace
+} // unnamed namespace
Dali::Toolkit::PushButton PushButton::New()
{
// Create the implementation, temporarily owned on stack
- IntrusivePtr< PushButton > internalPushButton = new PushButton();
+ IntrusivePtr<PushButton> internalPushButton = new PushButton();
// Pass ownership to CustomActor
- Dali::Toolkit::PushButton pushButton( *internalPushButton );
+ Dali::Toolkit::PushButton pushButton(*internalPushButton);
// Second-phase init of the implementation
// This can only be done after the CustomActor connection has been made...
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
-{
- return mInitialAutoRepeatingDelay;
-}
-
-void PushButton::SetNextAutoRepeatingDelay( float nextAutoRepeatingDelay )
+PushButton::PushButton()
+: Button(),
+ mIconAlignment(RIGHT)
{
- DALI_ASSERT_ALWAYS( nextAutoRepeatingDelay > 0.f );
- mNextAutoRepeatingDelay = nextAutoRepeatingDelay;
}
-float PushButton::GetNextAutoRepeatingDelay() const
+PushButton::~PushButton()
{
- return mNextAutoRepeatingDelay;
}
-void PushButton::SetToggleButton( bool toggle )
+void PushButton::OnInitialize()
{
- mToggleButton = toggle;
-
- // A toggle button can't be an autorepeating button.
- if( toggle )
- {
- mAutoRepeating = false;
+ Button::OnInitialize();
- // Notifies the painter.
- GetPushButtonPainter( mPainter )->SetAutoRepeating( mAutoRepeating );
- }
-}
+ // Push button requires the Leave event.
+ Actor self = Self();
+ self.SetProperty(Actor::Property::LEAVE_REQUIRED, true);
-bool PushButton::IsToggleButton() const
-{
- return mToggleButton;
+ DevelControl::SetAccessibilityConstructor(self, [](Dali::Actor actor) {
+ return std::unique_ptr<Dali::Accessibility::Accessible>(
+ new AccessibleImpl(actor, Dali::Accessibility::Role::PUSH_BUTTON));
+ });
}
-void PushButton::SetToggled( bool toggle )
+void PushButton::SetIconAlignment(const PushButton::IconAlignment iconAlignment)
{
- if( !mDimmed && mToggleButton && ( toggle != mToggled ) )
+ mIconAlignment = iconAlignment;
+ Button::Align labelAlignment;
+ switch(iconAlignment)
{
- mToggled = toggle;
-
- Toolkit::PushButton handle( GetOwner() );
-
- // Notifies the painter the button has been toggled.
- GetPushButtonPainter( mPainter )->Toggled( handle );
-
- // Emit signal.
- mToggledSignalV2.Emit( handle, mToggled );
+ case RIGHT:
+ {
+ labelAlignment = Button::BEGIN;
+ break;
+ }
+ case TOP:
+ {
+ labelAlignment = Button::BOTTOM;
+ break;
+ }
+ case BOTTOM:
+ {
+ labelAlignment = Button::TOP;
+ break;
+ }
+ case LEFT:
+ default:
+ labelAlignment = Button::END;
+ break;
}
-}
-
-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
-{
- return mButtonImage;
-}
-
-void PushButton::SetBackgroundImage( Image image )
-{
- SetBackgroundImage( ImageActor::New( image ) );
-}
-
-void PushButton::SetBackgroundImage( Actor image )
-{
- Toolkit::PushButton handle( GetOwner() );
- GetPushButtonPainter( mPainter )->SetBackgroundImage( handle, image );
-}
-
-Actor& PushButton::GetBackgroundImage()
-{
- return mBackgroundImage;
-}
-
-Actor PushButton::GetBackgroundImage() const
-{
- return mBackgroundImage;
-}
-
-void PushButton::SetPressedImage( Image image )
-{
- SetPressedImage( ImageActor::New( image ) );
-}
-
-void PushButton::SetPressedImage( Actor image )
-{
- Toolkit::PushButton handle( GetOwner() );
- GetPushButtonPainter( mPainter )->SetPressedImage( handle, image );
-}
-
-Actor& PushButton::GetPressedImage()
-{
- return mPressedImage;
-}
-
-Actor PushButton::GetPressedImage() const
-{
- return mPressedImage;
-}
-void PushButton::SetDimmedBackgroundImage( Image image )
-{
- SetDimmedBackgroundImage( ImageActor::New( image ) );
-}
-
-void PushButton::SetDimmedBackgroundImage( Actor image )
-{
- Toolkit::PushButton handle( GetOwner() );
- GetPushButtonPainter( mPainter )->SetDimmedBackgroundImage( handle, image );
-}
-
-Actor& PushButton::GetDimmedBackgroundImage()
-{
- return mDimmedBackgroundImage;
+ Button::SetLabelAlignment(labelAlignment);
}
-Actor PushButton::GetDimmedBackgroundImage() const
+const PushButton::IconAlignment PushButton::GetIconAlignment() const
{
- return mDimmedBackgroundImage;
+ return mIconAlignment;
}
-void PushButton::SetDimmedImage( Image image )
+void PushButton::SetProperty(BaseObject* object, Property::Index propertyIndex, const Property::Value& value)
{
- SetDimmedImage( ImageActor::New( image ) );
-}
-
-void PushButton::SetDimmedImage( Actor image )
-{
- Toolkit::PushButton handle( GetOwner() );
- GetPushButtonPainter( mPainter )->SetDimmedImage( handle, image );
-}
-
-Actor& PushButton::GetDimmedImage()
-{
- return mDimmedImage;
-}
-
-Actor PushButton::GetDimmedImage() const
-{
- return mDimmedImage;
-}
-
-void PushButton::SetLabelText( const std::string& text )
-{
- Toolkit::TextView textView ( Toolkit::TextView::New( text ) );
- textView.SetWidthExceedPolicy( Toolkit::TextView::ShrinkToFit ); // Make sure our text always fits inside the button
- SetLabelText( textView );
-}
+ Toolkit::PushButton pushButton = Toolkit::PushButton::DownCast(Dali::BaseHandle(object));
-void PushButton::SetLabelText( Actor text )
-{
- Toolkit::PushButton handle( GetOwner() );
- GetPushButtonPainter( mPainter )->SetLabelText( handle, text );
-}
-
-Actor& PushButton::GetLabel()
-{
- return mLabel;
-}
-
-Actor PushButton::GetLabelText() const
-{
- return mLabel;
-}
-
-Actor& PushButton::GetFadeOutBackgroundImage()
-{
- return mFadeOutBackgroundImage;
-}
-
-Actor& PushButton::GetFadeOutButtonImage()
-{
- return mFadeOutButtonImage;
-}
-
-Toolkit::PushButton::ToggledSignalV2& PushButton::ToggledSignal()
-{
- return mToggledSignalV2;
-}
-
-Toolkit::PushButton::PressedSignalV2& PushButton::PressedSignal()
-{
- return mPressedSignalV2;
-}
-
-Toolkit::PushButton::ReleasedSignalV2& PushButton::ReleasedSignal()
-{
- return mReleasedSignalV2;
-}
-
-bool PushButton::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
-{
- Dali::BaseHandle handle( object );
-
- bool connected( true );
- Toolkit::PushButton button = Toolkit::PushButton::DownCast(handle);
-
- if( Toolkit::PushButton::SIGNAL_TOGGLED == signalName )
+ if(pushButton)
{
- button.ToggledSignal().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;
- }
+ PushButton& pushButtonImpl(GetImplementation(pushButton));
- return connected;
-}
+ // Properties remain here for Tizen 3.0 legacy requirements. Are now in Button base class
-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 )
+ switch(propertyIndex)
{
- SetUpTimer( mInitialAutoRepeatingDelay );
+ case Toolkit::PushButton::Property::LABEL_PADDING:
+ {
+ Vector4 padding(value.Get<Vector4>());
+ pushButtonImpl.Button::SetLabelPadding(Padding(padding.x, padding.y, padding.z, padding.w));
+ break;
+ }
+ case Toolkit::PushButton::Property::ICON_PADDING:
+ {
+ Vector4 padding(value.Get<Vector4>());
+ pushButtonImpl.Button::SetForegroundPadding(Padding(padding.x, padding.y, padding.z, padding.w));
+ break;
+ }
}
-
- //Emit signal.
- mPressedSignalV2.Emit( handle );
}
}
-void PushButton::OnButtonUp()
+Property::Value PushButton::GetProperty(BaseObject* object, Property::Index propertyIndex)
{
- if( ButtonDown == mState )
- {
- if( mToggleButton )
- {
- mToggled = !mToggled;
+ Property::Value value;
- Toolkit::PushButton handle( GetOwner() );
+ Toolkit::PushButton pushButton = Toolkit::PushButton::DownCast(Dali::BaseHandle(object));
- // Notifies the painter the button has been toggled.
- GetPushButtonPainter( mPainter )->Toggled( handle );
+ if(pushButton)
+ {
+ PushButton& pushButtonImpl(GetImplementation(pushButton));
- //Emit signal.
- mToggledSignalV2.Emit( handle, mToggled );
- }
- else
+ switch(propertyIndex)
{
- Toolkit::PushButton handle( GetOwner() );
-
- // Notifies the painter the button has been clicked.
- GetPushButtonPainter( mPainter )->Released( handle );
- GetPushButtonPainter( mPainter )->Clicked( handle );
-
- if( mAutoRepeating )
+ case Toolkit::PushButton::Property::LABEL_PADDING:
{
- mAutoRepeatingTimer.Reset();
+ Padding padding = pushButtonImpl.Button::GetLabelPadding();
+ value = Vector4(padding.x, padding.y, padding.top, padding.bottom);
+ break;
}
-
- //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 )
+ case Toolkit::PushButton::Property::ICON_PADDING:
{
- mAutoRepeatingTimer.Reset();
+ Padding padding = pushButtonImpl.Button::GetForegroundPadding();
+ value = Vector4(padding.x, padding.y, padding.top, padding.bottom);
+ break;
}
-
- //Emit signal.
- mReleasedSignalV2.Emit( handle );
}
}
-}
-void PushButton::OnTouchPointInterrupted()
-{
- OnTouchPointLeave();
+ return value;
}
-void PushButton::OnAnimationTimeSet( float animationTime )
+Dali::Accessibility::States PushButton::AccessibleImpl::CalculateStates()
{
- GetPushButtonPainter( mPainter )->SetAnimationTime( animationTime );
+ auto tmp = Button::AccessibleImpl::CalculateStates();
+ auto slf = Toolkit::Button::DownCast(Self());
+ tmp[Dali::Accessibility::State::PRESSED] = slf.GetProperty<bool>(Toolkit::Button::Property::SELECTED);
+ return tmp;
}
-float PushButton::OnAnimationTimeRequested() const
+void PushButton::OnStateChange(State newState)
{
- 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 )
+ // TODO: replace it with OnPropertySet hook once Button::Property::SELECTED will be consistently used
+ if(Dali::Accessibility::IsUp() && (Dali::Accessibility::Accessible::GetCurrentlyHighlightedActor() == Self())
+ && (newState == SELECTED_STATE || newState == UNSELECTED_STATE))
{
- mAutoRepeatingTimer.Reset();
- }
-
- mPainter = NULL;
-}
+ Dali::Accessibility::Accessible::Get(Self())->EmitStateChanged(
+ Dali::Accessibility::State::PRESSED, newState == SELECTED_STATE ? 1 : 0, 0);
-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;
+ if(Self().GetProperty<bool>(Toolkit::Button::Property::TOGGLABLE))
+ {
+ Dali::Accessibility::Accessible::Get(Self())->EmitStateChanged(
+ Dali::Accessibility::State::CHECKED, newState == SELECTED_STATE ? 1 : 0, 0);
+ }
}
-
- return ret;
}
} // namespace Internal