From 3fbada5f2ec43d9b0ea3e63eb54223cf7b3056f4 Mon Sep 17 00:00:00 2001 From: Adeel Kazmi Date: Tue, 18 Feb 2014 17:28:00 +0000 Subject: [PATCH] (Button/PushButton) Registering properties using the type-registry. [Issue#] N/A [Problem] N/A [Cause] N/A [Solution] Property registration via type-registry added to core which allows the addition of event-side only properties to an actor on library load time. Button dimmed property changed to this property type. Added properties to push-button with this property type. Change-Id: I95b4cd3cf02c071d74c3147ba1d48ecf835b39a9 Signed-off-by: Paul Wisbey --- .../dali-test-suite/buttons/utc-Dali-Button.cpp | 44 ++--- .../buttons/utc-Dali-PushButton.cpp | 72 +++++++ automated-tests/tet_scen | 3 + .../public-api/controls/buttons/button.h | 3 + .../public-api/controls/buttons/push-button.h | 15 +- .../public-api/controls/control-impl.h | 7 + capi/dali-toolkit/public-api/controls/control.h | 4 +- .../internal/controls/buttons/button-impl.cpp | 47 +++-- .../internal/controls/buttons/button-impl.h | 33 +++- .../internal/controls/buttons/push-button-impl.cpp | 218 ++++++++++++++++++++- .../internal/controls/buttons/push-button-impl.h | 16 +- 11 files changed, 401 insertions(+), 61 deletions(-) diff --git a/automated-tests/dali-test-suite/buttons/utc-Dali-Button.cpp b/automated-tests/dali-test-suite/buttons/utc-Dali-Button.cpp index 53a0e53..8073a41 100644 --- a/automated-tests/dali-test-suite/buttons/utc-Dali-Button.cpp +++ b/automated-tests/dali-test-suite/buttons/utc-Dali-Button.cpp @@ -65,33 +65,25 @@ extern "C" { void (*tet_cleanup)() = Cleanup; } -static void UtcDaliButtonNew(); -static void UtcDaliButtonSetProperty(); -static void UtcDaliButtonSetGetDimmed(); -static void UtcDaliButtonSize(); -static void UtcDaliButtonClicked(); -static void UtcDaliButtonConnectSignal(); -static void UtcDaliButtonSetGetAnimationTime(); - enum { POSITIVE_TC_IDX = 0x01, NEGATIVE_TC_IDX, }; -// Add test functionality for all APIs in the class (Positive and Negative) +#define MAX_NUMBER_OF_TESTS 10000 extern "C" { - struct tet_testlist tet_testlist[] = { - { UtcDaliButtonNew, POSITIVE_TC_IDX }, - { UtcDaliButtonSetProperty, POSITIVE_TC_IDX }, - { UtcDaliButtonSetGetDimmed, POSITIVE_TC_IDX }, - { UtcDaliButtonSize, POSITIVE_TC_IDX }, - { UtcDaliButtonClicked, POSITIVE_TC_IDX }, - { UtcDaliButtonConnectSignal, POSITIVE_TC_IDX }, - { UtcDaliButtonSetGetAnimationTime, POSITIVE_TC_IDX }, - { NULL, 0 } - }; + struct tet_testlist tet_testlist[MAX_NUMBER_OF_TESTS]; } +// Add test functionality for all APIs in the class (Positive and Negative) +TEST_FUNCTION( UtcDaliButtonNew, POSITIVE_TC_IDX ); +TEST_FUNCTION( UtcDaliButtonProperties, POSITIVE_TC_IDX ); +TEST_FUNCTION( UtcDaliButtonSetGetDimmed, POSITIVE_TC_IDX ); +TEST_FUNCTION( UtcDaliButtonSize, POSITIVE_TC_IDX ); +TEST_FUNCTION( UtcDaliButtonClicked, POSITIVE_TC_IDX ); +TEST_FUNCTION( UtcDaliButtonConnectSignal, POSITIVE_TC_IDX ); +TEST_FUNCTION( UtcDaliButtonSetGetAnimationTime, POSITIVE_TC_IDX ); + // Called only once before first test is run. static void Startup() { @@ -162,7 +154,7 @@ static void UtcDaliButtonNew() DALI_TEST_CHECK( downCastCheckBoxButton2 ); } -static void UtcDaliButtonSetProperty() +static void UtcDaliButtonProperties() { tet_infoline("UtcDaliButtonSetProperty: "); ToolkitTestApplication application; @@ -171,15 +163,19 @@ static void UtcDaliButtonSetProperty() PushButton pushButton = PushButton::New(); //Test various properties - checkBoxButton.SetProperty(checkBoxButton.GetPropertyIndex("dimmed"), false); + checkBoxButton.SetProperty( Button::PROPERTY_DIMMED, false ); DALI_TEST_CHECK( false == checkBoxButton.IsDimmed() ); - checkBoxButton.SetProperty(checkBoxButton.GetPropertyIndex("dimmed"), true); + DALI_TEST_CHECK( false == checkBoxButton.GetProperty< bool >( Button::PROPERTY_DIMMED ) ); + checkBoxButton.SetProperty( Button::PROPERTY_DIMMED, true ); DALI_TEST_CHECK( true == checkBoxButton.IsDimmed() ); + DALI_TEST_CHECK( true == checkBoxButton.GetProperty< bool >( Button::PROPERTY_DIMMED ) ); - pushButton.SetProperty(pushButton.GetPropertyIndex("dimmed"), false); + pushButton.SetProperty( Button::PROPERTY_DIMMED, false ); DALI_TEST_CHECK( false == pushButton.IsDimmed() ); - pushButton.SetProperty(pushButton.GetPropertyIndex("dimmed"), true); + DALI_TEST_CHECK( false == pushButton.GetProperty< bool >( Button::PROPERTY_DIMMED ) ); + pushButton.SetProperty( Button::PROPERTY_DIMMED, true ); DALI_TEST_CHECK( true == pushButton.IsDimmed() ); + DALI_TEST_CHECK( true == pushButton.GetProperty< bool >( Button::PROPERTY_DIMMED ) ); } static void UtcDaliButtonSetGetDimmed() diff --git a/automated-tests/dali-test-suite/buttons/utc-Dali-PushButton.cpp b/automated-tests/dali-test-suite/buttons/utc-Dali-PushButton.cpp index 5e13b83..a065945 100644 --- a/automated-tests/dali-test-suite/buttons/utc-Dali-PushButton.cpp +++ b/automated-tests/dali-test-suite/buttons/utc-Dali-PushButton.cpp @@ -385,6 +385,7 @@ TEST_FUNCTION( UtcDaliPushButtonReleased, POSITIVE_TC_IDX ); TEST_FUNCTION( UtcDaliPushButtonToggled, POSITIVE_TC_IDX ); TEST_FUNCTION( UtcDaliPushButtonInterruptEventWhenInsensitive, POSITIVE_TC_IDX ); TEST_FUNCTION( UtcDaliPushButtonInterruptEventWhenNonVisible, POSITIVE_TC_IDX ); +TEST_FUNCTION( UtcDaliPushButtonProperties, POSITIVE_TC_IDX ); // Called only once before first test is run. static void Startup() @@ -1261,3 +1262,74 @@ static void UtcDaliPushButtonInterruptEventWhenNonVisible() DALI_TEST_CHECK( !gOnTouchPointInterrupted ); } + +void UtcDaliPushButtonProperties() +{ + ToolkitTestApplication application; + + PushButton button = PushButton::New(); + Stage::GetCurrent().Add( button ); + + // PushButton::PROPERTY_AUTO_REPEATING + button.SetAutoRepeating( false ); + DALI_TEST_CHECK( ! button.GetProperty< bool >( PushButton::PROPERTY_AUTO_REPEATING ) ); + button.SetProperty( PushButton::PROPERTY_AUTO_REPEATING, true ); + DALI_TEST_CHECK( button.IsAutoRepeating() ) ; + DALI_TEST_CHECK( button.GetProperty< bool >( PushButton::PROPERTY_AUTO_REPEATING ) ); + + // PushButton::PROPERTY_INITIAL_AUTO_REPEATING_DELAY + button.SetInitialAutoRepeatingDelay( 10.0f ); + DALI_TEST_EQUALS( 10.0f, button.GetProperty< float >( PushButton::PROPERTY_INITIAL_AUTO_REPEATING_DELAY ), TEST_LOCATION ); + button.SetProperty( PushButton::PROPERTY_INITIAL_AUTO_REPEATING_DELAY, 25.0f ); + DALI_TEST_EQUALS( 25.0f, button.GetInitialAutoRepeatingDelay(), TEST_LOCATION ); + DALI_TEST_EQUALS( 25.0f, button.GetProperty< float >( PushButton::PROPERTY_INITIAL_AUTO_REPEATING_DELAY ), TEST_LOCATION ); + + // PushButton::PROPERTY_NEXT_AUTO_REPEATING_DELAY + button.SetNextAutoRepeatingDelay( 3.0f ); + DALI_TEST_EQUALS( 3.0f, button.GetProperty< float >( PushButton::PROPERTY_NEXT_AUTO_REPEATING_DELAY ), TEST_LOCATION ); + button.SetProperty( PushButton::PROPERTY_NEXT_AUTO_REPEATING_DELAY, 4.0f ); + DALI_TEST_EQUALS( 4.0f, button.GetNextAutoRepeatingDelay(), TEST_LOCATION ); + DALI_TEST_EQUALS( 4.0f, button.GetProperty< float >( PushButton::PROPERTY_NEXT_AUTO_REPEATING_DELAY ), TEST_LOCATION ); + + // PushButton::PROPERTY_TOGGLABLE + button.SetToggleButton( false ); + DALI_TEST_CHECK( ! button.GetProperty< bool >( PushButton::PROPERTY_TOGGLABLE ) ); + button.SetProperty( PushButton::PROPERTY_TOGGLABLE, true ); + DALI_TEST_CHECK( button.IsToggleButton() ) ; + DALI_TEST_CHECK( button.GetProperty< bool >( PushButton::PROPERTY_TOGGLABLE ) ); + + // PushButton::PROPERTY_TOGGLE + button.SetToggled( false ); + DALI_TEST_CHECK( ! button.GetProperty< bool >( PushButton::PROPERTY_TOGGLE ) ); + button.SetProperty( PushButton::PROPERTY_TOGGLE, true ); + DALI_TEST_CHECK( button.IsToggled() ) ; + DALI_TEST_CHECK( button.GetProperty< bool >( PushButton::PROPERTY_TOGGLE ) ); + + // PushButton::PROPERTY_BUTTON_IMAGE + DALI_TEST_CHECK( button.GetProperty< std::string >( PushButton::PROPERTY_BUTTON_IMAGE ).empty() ); + button.SetButtonImage( Image::New( "FunctionButtonImage") ); + DALI_TEST_EQUALS( "FunctionButtonImage", button.GetProperty< std::string >( PushButton::PROPERTY_BUTTON_IMAGE ), TEST_LOCATION ); + button.SetProperty( PushButton::PROPERTY_BUTTON_IMAGE, "PropertyButtonImage" ); + DALI_TEST_EQUALS( "PropertyButtonImage", button.GetProperty< std::string >( PushButton::PROPERTY_BUTTON_IMAGE ), TEST_LOCATION ); + + // PushButton::PROPERTY_PRESSED_IMAGE + DALI_TEST_CHECK( button.GetProperty< std::string >( PushButton::PROPERTY_PRESSED_IMAGE ).empty() ); + button.SetPressedImage( Image::New( "FunctionPressedImage") ); + DALI_TEST_EQUALS( "FunctionPressedImage", button.GetProperty< std::string >( PushButton::PROPERTY_PRESSED_IMAGE ), TEST_LOCATION ); + button.SetProperty( PushButton::PROPERTY_PRESSED_IMAGE, "PropertyPressedImage" ); + DALI_TEST_EQUALS( "PropertyPressedImage", button.GetProperty< std::string >( PushButton::PROPERTY_PRESSED_IMAGE ), TEST_LOCATION ); + + // PushButton::PROPERTY_DIMMED_IMAGE + DALI_TEST_CHECK( button.GetProperty< std::string >( PushButton::PROPERTY_DIMMED_IMAGE ).empty() ); + button.SetDimmedImage( Image::New( "FunctionDimmedImage") ); + DALI_TEST_EQUALS( "FunctionDimmedImage", button.GetProperty< std::string >( PushButton::PROPERTY_DIMMED_IMAGE ), TEST_LOCATION ); + button.SetProperty( PushButton::PROPERTY_DIMMED_IMAGE, "PropertyDimmedImage" ); + DALI_TEST_EQUALS( "PropertyDimmedImage", button.GetProperty< std::string >( PushButton::PROPERTY_DIMMED_IMAGE ), TEST_LOCATION ); + + // PushButton::PROPERTY_LABEL_TEXT + DALI_TEST_CHECK( button.GetProperty< std::string >( PushButton::PROPERTY_LABEL_TEXT ).empty() ); + button.SetLabelText( "FunctionLabel" ); + DALI_TEST_EQUALS( "FunctionLabel", button.GetProperty< std::string >( PushButton::PROPERTY_LABEL_TEXT ), TEST_LOCATION ); + button.SetProperty( PushButton::PROPERTY_LABEL_TEXT, "PropertyLabel" ); + DALI_TEST_EQUALS( "PropertyLabel", button.GetProperty< std::string >( PushButton::PROPERTY_LABEL_TEXT ), TEST_LOCATION ); +} diff --git a/automated-tests/tet_scen b/automated-tests/tet_scen index bd9f75e..3db3582 100644 --- a/automated-tests/tet_scen +++ b/automated-tests/tet_scen @@ -123,4 +123,7 @@ text-view-full :include:/dali-internal-test-suite/text-view/tslist ##### DEBUG ##### +debug + /dali-test-suite/buttons/utc-Dali-PushButton + # EOF diff --git a/capi/dali-toolkit/public-api/controls/buttons/button.h b/capi/dali-toolkit/public-api/controls/buttons/button.h index f52106e..d414714 100644 --- a/capi/dali-toolkit/public-api/controls/buttons/button.h +++ b/capi/dali-toolkit/public-api/controls/buttons/button.h @@ -57,6 +57,9 @@ public: // Signal Names static const char* const SIGNAL_CLICKED; + // Properties + static const Property::Index PROPERTY_DIMMED; ///< name "dimmed", @see SetDimmed(), type BOOLEAN + public: /** diff --git a/capi/dali-toolkit/public-api/controls/buttons/push-button.h b/capi/dali-toolkit/public-api/controls/buttons/push-button.h index eb92f14..d818b07 100644 --- a/capi/dali-toolkit/public-api/controls/buttons/push-button.h +++ b/capi/dali-toolkit/public-api/controls/buttons/push-button.h @@ -83,14 +83,25 @@ class PushButton : public Button { public: - //Signal Names + // Signal Names static const char* const SIGNAL_TOGGLED; static const char* const SIGNAL_PRESSED; static const char* const SIGNAL_RELEASED; - //Action Names + // Action Names static const char* const ACTION_PUSH_BUTTON_CLICK; + // Properties + static const Property::Index PROPERTY_AUTO_REPEATING; ///< name "auto-repeating", @see SetAutoRepeating(), type BOOLEAN + static const Property::Index PROPERTY_INITIAL_AUTO_REPEATING_DELAY; ///< name "initial-auto-repeating-delay", @see SetInitialAutoRepeatingDelay(), type FLOAT + static const Property::Index PROPERTY_NEXT_AUTO_REPEATING_DELAY; ///< name "next-auto-repeating-delay", @see SetNextAutoRepeatingDelay(), type FLOAT + static const Property::Index PROPERTY_TOGGLABLE; ///< name "togglable", @see SetToggleButton(), type BOOLEAN + static const Property::Index PROPERTY_TOGGLE; ///< name "toggle", @see SetToggled(), type BOOLEAN + static const Property::Index PROPERTY_BUTTON_IMAGE; ///< name "button-image", @see SetButtonImage(Image), type STRING + static const Property::Index PROPERTY_PRESSED_IMAGE; ///< name "pressed-image", @see SetPressedImage(Image), type STRING + static const Property::Index PROPERTY_DIMMED_IMAGE; ///< name "dimmed-image", @see SetDimmedImage(Image), type STRING + static const Property::Index PROPERTY_LABEL_TEXT; ///< name "label-text", @see SetLabelText(const std::string&), type STRING + public: /** diff --git a/capi/dali-toolkit/public-api/controls/control-impl.h b/capi/dali-toolkit/public-api/controls/control-impl.h index f4643db..d8e49dd 100644 --- a/capi/dali-toolkit/public-api/controls/control-impl.h +++ b/capi/dali-toolkit/public-api/controls/control-impl.h @@ -51,6 +51,13 @@ class ControlImpl : public CustomActorImpl, public ConnectionTrackerInterface { public: + // Properties + enum + { + CONTROL_PROPERTY_START_INDEX = PropertyRegistration::START_INDEX, + CONTROL_PROPERTY_END_INDEX = CONTROL_PROPERTY_START_INDEX + 1000 ///< Reserving 1000 property indices + }; + // Creation /** diff --git a/capi/dali-toolkit/public-api/controls/control.h b/capi/dali-toolkit/public-api/controls/control.h index 64812fa..a26cf7e 100644 --- a/capi/dali-toolkit/public-api/controls/control.h +++ b/capi/dali-toolkit/public-api/controls/control.h @@ -44,10 +44,10 @@ class Control : public CustomActor, public ConnectionTrackerInterface { public: - //Action Names + // Action Names static const char* const ACTION_CONTROL_ACTIVATED; - //Signal Names + // Signal Names static const char* const SIGNAL_KEY_EVENT; /** diff --git a/dali-toolkit/internal/controls/buttons/button-impl.cpp b/dali-toolkit/internal/controls/buttons/button-impl.cpp index bd74b57..9c1c340 100644 --- a/dali-toolkit/internal/controls/buttons/button-impl.cpp +++ b/dali-toolkit/internal/controls/buttons/button-impl.cpp @@ -29,13 +29,13 @@ namespace Dali namespace Toolkit { -namespace Internal -{ +const Property::Index Button::PROPERTY_DIMMED( Internal::Button::BUTTON_PROPERTY_START_INDEX ); namespace Internal { -using namespace Dali; +namespace +{ BaseHandle Create() { @@ -47,7 +47,9 @@ TypeRegistration typeRegistration( typeid(Toolkit::Button), typeid(Toolkit::Cont SignalConnectorType signalConnector1( typeRegistration, Toolkit::Button::SIGNAL_CLICKED, &Button::DoConnectSignal ); -} +PropertyRegistration property1( typeRegistration, "dimmed", Toolkit::Button::PROPERTY_DIMMED, Property::BOOLEAN, &Button::SetProperty, &Button::GetProperty ); + +} // unnamed namespace Button::Button() : ControlImpl( true ), @@ -196,15 +198,14 @@ void Button::OnInitialize() mPainter->Initialize( handle ); } + Actor self = Self(); + mTapDetector = TapGestureDetector::New(); - mTapDetector.Attach(Self()); + mTapDetector.Attach( self ); mTapDetector.DetectedSignal().Connect(this, &Button::OnTap); OnButtonInitialize(); - Actor self = Self(); - mPropertyDimmed = self.RegisterProperty( PROPERTY_DIMMED, false, Property::READ_WRITE ); - self.SetKeyboardFocusable( true ); } @@ -217,14 +218,6 @@ void Button::OnControlSizeSet(const Vector3& targetSize) } } -void Button::OnPropertySet( Property::Index index, Property::Value propertyValue ) -{ - if( index == mPropertyDimmed ) - { - SetDimmed(propertyValue.Get()); - } -} - void Button::OnTap(Actor actor, TapGesture tap) { // Do nothing. @@ -239,6 +232,28 @@ void Button::OnStageDisconnection() } } +void Button::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value ) +{ + Toolkit::Button button = Toolkit::Button::DownCast( Dali::BaseHandle( object ) ); + + if ( button && ( index == Toolkit::Button::PROPERTY_DIMMED ) ) + { + GetImplementation( button ).SetDimmed( value.Get() ); + } +} + +Property::Value Button::GetProperty( BaseObject* object, Property::Index propertyIndex ) +{ + Toolkit::Button button = Toolkit::Button::DownCast( Dali::BaseHandle( object ) ); + + if ( button && ( propertyIndex == Toolkit::Button::PROPERTY_DIMMED ) ) + { + return Property::Value( GetImplementation( button ).mDimmed ); + } + + return Property::Value(); +} + } // namespace Internal } // namespace Toolkit diff --git a/dali-toolkit/internal/controls/buttons/button-impl.h b/dali-toolkit/internal/controls/buttons/button-impl.h index 8365f35..d7df9f0 100644 --- a/dali-toolkit/internal/controls/buttons/button-impl.h +++ b/dali-toolkit/internal/controls/buttons/button-impl.h @@ -39,6 +39,14 @@ namespace Internal */ class Button : public ControlImpl { +public: + + // Properties + enum + { + BUTTON_PROPERTY_START_INDEX = ControlImpl::CONTROL_PROPERTY_END_INDEX + 1, + BUTTON_PROPERTY_END_INDEX = BUTTON_PROPERTY_START_INDEX + 1000 ///< Reserving 1000 property indices + }; protected: @@ -139,6 +147,24 @@ public: */ static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor ); + // Properties + + /** + * Called when a property of an object of this type is set. + * @param[in] object The object whose property is set. + * @param[in] index The property index. + * @param[in] value The new property value. + */ + static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value ); + + /** + * Called to retrieve a property of an object of this type. + * @param[in] object The object whose property is to be retrieved. + * @param[in] index The property index. + * @return The current value of the property. + */ + static Property::Value GetProperty( BaseObject* object, Property::Index propertyIndex ); + protected: // From CustomActorImpl /** @@ -158,11 +184,6 @@ private: // From ControlImpl */ virtual void OnControlSizeSet( const Vector3& targetSize ); - /** - * @copydoc Dali::CustomActorImpl::OnPropertySet() - */ - virtual void OnPropertySet( Property::Index index, Property::Value propertyValue ); - private: /** @@ -208,8 +229,6 @@ protected: // Signals Toolkit::Button::ClickedSignalV2 mClickedSignalV2; ///< Signal emitted when the button is clicked. TapGestureDetector mTapDetector; - - Property::Index mPropertyDimmed; ///< Property index for dimmed. }; } // namespace Internal diff --git a/dali-toolkit/internal/controls/buttons/push-button-impl.cpp b/dali-toolkit/internal/controls/buttons/push-button-impl.cpp index c5e078f..8b96ba5 100644 --- a/dali-toolkit/internal/controls/buttons/push-button-impl.cpp +++ b/dali-toolkit/internal/controls/buttons/push-button-impl.cpp @@ -34,14 +34,22 @@ namespace Dali namespace Toolkit { +const Property::Index PushButton::PROPERTY_AUTO_REPEATING = Internal::Button::BUTTON_PROPERTY_END_INDEX + 1; +const Property::Index PushButton::PROPERTY_INITIAL_AUTO_REPEATING_DELAY = Internal::Button::BUTTON_PROPERTY_END_INDEX + 2; +const Property::Index PushButton::PROPERTY_NEXT_AUTO_REPEATING_DELAY = Internal::Button::BUTTON_PROPERTY_END_INDEX + 3; +const Property::Index PushButton::PROPERTY_TOGGLABLE = Internal::Button::BUTTON_PROPERTY_END_INDEX + 4; +const Property::Index PushButton::PROPERTY_TOGGLE = Internal::Button::BUTTON_PROPERTY_END_INDEX + 5; +const Property::Index PushButton::PROPERTY_BUTTON_IMAGE = Internal::Button::BUTTON_PROPERTY_END_INDEX + 6; +const Property::Index PushButton::PROPERTY_PRESSED_IMAGE = Internal::Button::BUTTON_PROPERTY_END_INDEX + 8; +const Property::Index PushButton::PROPERTY_DIMMED_IMAGE = Internal::Button::BUTTON_PROPERTY_END_INDEX + 9; +const Property::Index PushButton::PROPERTY_LABEL_TEXT = Internal::Button::BUTTON_PROPERTY_END_INDEX + 11; + namespace Internal { namespace { -using namespace Dali; - BaseHandle Create() { return Toolkit::PushButton::New(); @@ -55,20 +63,56 @@ SignalConnectorType signalConnector3( typeRegistration, Toolkit::PushButton::SIG TypeAction action1( typeRegistration, Toolkit::PushButton::ACTION_PUSH_BUTTON_CLICK, &PushButton::DoAction ); -} +PropertyRegistration property1( typeRegistration, "auto-repeating", Toolkit::PushButton::PROPERTY_AUTO_REPEATING, Property::BOOLEAN, &PushButton::SetProperty, &PushButton::GetProperty ); +PropertyRegistration property2( typeRegistration, "initial-auto-repeating-delay", Toolkit::PushButton::PROPERTY_INITIAL_AUTO_REPEATING_DELAY, Property::FLOAT, &PushButton::SetProperty, &PushButton::GetProperty ); +PropertyRegistration property3( typeRegistration, "next-auto-repeating-delay", Toolkit::PushButton::PROPERTY_NEXT_AUTO_REPEATING_DELAY, Property::FLOAT, &PushButton::SetProperty, &PushButton::GetProperty ); +PropertyRegistration property4( typeRegistration, "togglable", Toolkit::PushButton::PROPERTY_TOGGLABLE, Property::BOOLEAN, &PushButton::SetProperty, &PushButton::GetProperty ); +PropertyRegistration property5( typeRegistration, "toggle", Toolkit::PushButton::PROPERTY_TOGGLE, Property::BOOLEAN, &PushButton::SetProperty, &PushButton::GetProperty ); +PropertyRegistration property6( typeRegistration, "button-image", Toolkit::PushButton::PROPERTY_BUTTON_IMAGE, Property::STRING, &PushButton::SetProperty, &PushButton::GetProperty ); +PropertyRegistration property7( typeRegistration, "pressed-image", Toolkit::PushButton::PROPERTY_PRESSED_IMAGE, Property::STRING, &PushButton::SetProperty, &PushButton::GetProperty ); +PropertyRegistration property8( typeRegistration, "dimmed-image", Toolkit::PushButton::PROPERTY_DIMMED_IMAGE, Property::STRING, &PushButton::SetProperty, &PushButton::GetProperty ); +PropertyRegistration property9( typeRegistration, "label-text", Toolkit::PushButton::PROPERTY_LABEL_TEXT, Property::STRING, &PushButton::SetProperty, &PushButton::GetProperty ); +} // 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 ) +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( painter.Get() ); +} + +/** + * Helper function to checks if the specified actor is an ImageActor and if it has an Image with a path. + * + * @param[in] actor Actor handle to check. + * @param[out] path The image path will be applied to this parameter, if available. + * If not available then this will be an empty string. + */ +void GetImageActorFilename( Actor& actor, std::string& path ) +{ + path = ""; // Just return an empty string if not using ImageActor with an image + + if ( actor ) { - return static_cast( painter.Get() ); + ImageActor imageActor = ImageActor::DownCast( actor ); + if ( imageActor ) + { + Image image = imageActor.GetImage(); + if ( image ) + { + path = image.GetFilename(); + } + } } -} // namespace +} + +} // unnamed namespace Dali::Toolkit::PushButton PushButton::New() { @@ -354,6 +398,162 @@ bool PushButton::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface return connected; } +void PushButton::SetProperty( BaseObject* object, Property::Index propertyIndex, const Property::Value& value ) +{ + Toolkit::PushButton pushButton = Toolkit::PushButton::DownCast( Dali::BaseHandle( object ) ); + + if ( pushButton ) + { + PushButton& pushButtonImpl( GetImplementation( pushButton ) ); + + switch ( propertyIndex ) + { + case Toolkit::PushButton::PROPERTY_AUTO_REPEATING: + { + pushButtonImpl.SetAutoRepeating( value.Get< bool >() ); + break; + } + + case Toolkit::PushButton::PROPERTY_INITIAL_AUTO_REPEATING_DELAY: + { + pushButtonImpl.SetInitialAutoRepeatingDelay( value.Get< float >() ); + break; + } + + case Toolkit::PushButton::PROPERTY_NEXT_AUTO_REPEATING_DELAY: + { + pushButtonImpl.SetNextAutoRepeatingDelay( value.Get< float >() ); + break; + } + + case Toolkit::PushButton::PROPERTY_TOGGLABLE: + { + pushButtonImpl.SetToggleButton( value.Get< bool >() ); + break; + } + + case Toolkit::PushButton::PROPERTY_TOGGLE: + { + pushButtonImpl.SetToggled( value.Get< bool >() ); + break; + } + + case Toolkit::PushButton::PROPERTY_BUTTON_IMAGE: + { + Image image = Image::New( value.Get() ); + pushButtonImpl.SetButtonImage( image ); + break; + } + + case Toolkit::PushButton::PROPERTY_PRESSED_IMAGE: + { + Image image = Image::New( value.Get() ); + pushButtonImpl.SetPressedImage( image ); + break; + } + + case Toolkit::PushButton::PROPERTY_DIMMED_IMAGE: + { + Image image = Image::New( value.Get() ); + pushButtonImpl.SetDimmedImage( image ); + break; + } + + case Toolkit::PushButton::PROPERTY_LABEL_TEXT: + { + pushButtonImpl.SetLabelText( value.Get< std::string >() ); + break; + } + } + } +} + +Property::Value PushButton::GetProperty( BaseObject* object, Property::Index propertyIndex ) +{ + Property::Value value; + + Toolkit::PushButton pushButton = Toolkit::PushButton::DownCast( Dali::BaseHandle( object ) ); + + if ( pushButton ) + { + PushButton& pushButtonImpl( GetImplementation( pushButton ) ); + + switch ( propertyIndex ) + { + case Toolkit::PushButton::PROPERTY_AUTO_REPEATING: + { + value = pushButtonImpl.mAutoRepeating; + break; + } + + case Toolkit::PushButton::PROPERTY_INITIAL_AUTO_REPEATING_DELAY: + { + value = pushButtonImpl.mInitialAutoRepeatingDelay; + break; + } + + case Toolkit::PushButton::PROPERTY_NEXT_AUTO_REPEATING_DELAY: + { + value = pushButtonImpl.mNextAutoRepeatingDelay; + break; + } + + case Toolkit::PushButton::PROPERTY_TOGGLABLE: + { + value = pushButtonImpl.mToggleButton; + break; + } + + case Toolkit::PushButton::PROPERTY_TOGGLE: + { + value = pushButtonImpl.mToggled; + break; + } + + case Toolkit::PushButton::PROPERTY_BUTTON_IMAGE: + { + std::string path; + GetImageActorFilename( pushButtonImpl.mButtonImage, path ); + value = path; + break; + } + + case Toolkit::PushButton::PROPERTY_PRESSED_IMAGE: + { + std::string path; + GetImageActorFilename( pushButtonImpl.mPressedImage, path ); + value = path; + break; + } + + case Toolkit::PushButton::PROPERTY_DIMMED_IMAGE: + { + std::string path; + GetImageActorFilename( pushButtonImpl.mDimmedImage, path ); + value = path; + break; + } + + case Toolkit::PushButton::PROPERTY_LABEL_TEXT: + { + value = ""; // Just return an empty string if not using a TextView + + if ( pushButtonImpl.mLabel ) + { + Toolkit::TextView textView = Toolkit::TextView::DownCast( pushButtonImpl.mLabel ); + if ( textView ) + { + value = textView.GetText(); + } + } + break; + } + } + } + + return value; +} + void PushButton::OnButtonInitialize() { // Push button requires the Leave event. diff --git a/dali-toolkit/internal/controls/buttons/push-button-impl.h b/dali-toolkit/internal/controls/buttons/push-button-impl.h index dff5fc5..b463513 100644 --- a/dali-toolkit/internal/controls/buttons/push-button-impl.h +++ b/dali-toolkit/internal/controls/buttons/push-button-impl.h @@ -236,7 +236,9 @@ public: */ Actor& GetFadeOutButtonImage(); -public: // Signals +public: + + // Signals /** * @copydoc Dali::Toolkit::PushButton::ToggledSignal() @@ -264,6 +266,18 @@ public: // Signals */ static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor ); + // Properties + + /** + * @copydoc Button::SetProperty + */ + static void SetProperty( BaseObject* object, Property::Index propertyIndex, const Property::Value& value ); + + /** + * @copydoc Button::GetProperty + */ + static Property::Value GetProperty( BaseObject* object, Property::Index propertyIndex ); + protected: // From Button /** -- 2.7.4