-#include "dali-test-suite-utils/dali-test-suite-utils.h"
-
-using namespace Dali;
-
-
-void custom_actor_test_startup(void)
-{
- test_return_value = TET_UNDEF;
-}
-
-void custom_actor_test_cleanup(void)
-{
- test_return_value = TET_PASS;
-}
-
-namespace
-{
-
-std::vector< std::string > MasterCallStack;
-bool gOnRelayout = false;
-
-} // anon namespace
-
-// TypeRegistry needs custom actor Implementations to have the same name (namespaces are ignored so we use one here)
-namespace Impl
-{
-
-struct TestCustomActor : public CustomActorImpl
-{
- /**
- * Constructor
- */
- TestCustomActor()
- : CustomActorImpl( ActorFlags( REQUIRES_TOUCH_EVENTS | REQUIRES_WHEEL_EVENTS | REQUIRES_HOVER_EVENTS | DISABLE_SIZE_NEGOTIATION ) ),
- mDaliProperty( Property::INVALID_INDEX ),
- mSizeSet( Vector3::ZERO ),
- mTargetSize( Vector3::ZERO ),
- mNego( false )
- {
- }
-
- TestCustomActor(bool nego)
- : CustomActorImpl( ActorFlags( REQUIRES_TOUCH_EVENTS | REQUIRES_WHEEL_EVENTS | REQUIRES_HOVER_EVENTS ) ),
- mDaliProperty( Property::INVALID_INDEX ),
- mSizeSet( Vector3::ZERO ),
- mTargetSize( Vector3::ZERO ),
- mNego( nego )
- {
- }
- /**
- * Destructor
- */
- virtual ~TestCustomActor()
- {
- }
-
- void Initialize( const char* name = NULL )
- {
- mDaliProperty = Self().RegisterProperty( "Dali", std::string("no"), Property::READ_WRITE);
-
- OnInitialize( name );
- }
-
- virtual void OnInitialize( const char* name ) {}
-
- /**
- * Resets the call stack
- */
- void ResetCallStack()
- {
- mSizeSet = Vector3();
- mTargetSize = Vector3();
- mMethodsCalled.clear();
- }
-
- void AddToCallStacks( const char* method )
- {
- mMethodsCalled.push_back( method );
-
- // Combine Actor name with method string
- std::string nameAndMethod( Self().GetName() );
- if ( 0 == nameAndMethod.size() )
- {
- nameAndMethod = "Unknown: ";
- }
- else
- {
- nameAndMethod += ": ";
- }
- nameAndMethod += method;
-
- MasterCallStack.push_back( nameAndMethod );
- }
-
- // From CustomActorImpl
- virtual void OnStageConnection()
- {
- AddToCallStacks("OnStageConnection");
- }
- virtual void OnStageDisconnection()
- {
- AddToCallStacks("OnStageDisconnection");
- }
- virtual void OnChildAdd(Actor& child)
- {
- AddToCallStacks("OnChildAdd");
- }
- virtual void OnChildRemove(Actor& child)
- {
- AddToCallStacks("OnChildRemove");
- }
- virtual void OnPropertySet( Property::Index index, Property::Value propertyValue )
- {
- AddToCallStacks("OnPropertySet");
- }
- virtual void OnSizeSet(const Vector3& targetSize)
- {
- mSizeSet = targetSize;
- AddToCallStacks("OnSizeSet");
- }
- virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize)
- {
- mTargetSize = targetSize;
- AddToCallStacks("OnSizeAnimation");
- }
- virtual bool OnTouchEvent(const TouchEvent& event)
- {
- AddToCallStacks("OnTouchEvent");
- return true;
- }
- virtual bool OnHoverEvent(const HoverEvent& event)
- {
- AddToCallStacks("OnHoverEvent");
- return true;
- }
- virtual bool OnWheelEvent(const WheelEvent& event)
- {
- AddToCallStacks("OnWheelEvent");
- return true;
- }
- virtual bool OnKeyEvent(const KeyEvent& event)
- {
- AddToCallStacks("OnKeyEvent");
- return true;
- }
- virtual void OnKeyInputFocusGained()
- {
- AddToCallStacks("OnKeyInputFocusGained");
- }
- virtual void OnKeyInputFocusLost()
- {
- AddToCallStacks("OnKeyInputFocusLost");
- }
- virtual Vector3 GetNaturalSize()
- {
- return Vector3( 0.0f, 0.0f, 0.0f );
- }
-
- virtual float GetHeightForWidth( float width )
- {
- return 0.0f;
- }
-
- virtual float GetWidthForHeight( float height )
- {
- return 0.0f;
- }
-
- virtual void OnRelayout( const Vector2& size, RelayoutContainer& container )
- {
- gOnRelayout = true;
- }
-
- virtual void OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
- {
- }
-
- virtual void OnCalculateRelayoutSize( Dimension::Type dimension )
- {
- }
-
- virtual float CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension )
- {
- return 0.0f;
- }
-
- virtual void OnLayoutNegotiated( float size, Dimension::Type dimension )
- {
- }
-
- virtual bool RelayoutDependentOnChildren( Dimension::Type dimension = Dimension::ALL_DIMENSIONS )
- {
- return false;
- }
-
- void SetDaliProperty(std::string s)
- {
- Self().SetProperty(mDaliProperty, s);
- }
- void TestRelayoutRequest()
- {
- RelayoutRequest();
- }
-
- float TestGetHeightForWidthBase( float width )
- {
- return GetHeightForWidthBase( width );
- }
-
- float TestGetWidthForHeightBase( float height )
- {
- return GetWidthForHeightBase( height );
- }
-
- float TestCalculateChildSizeBase( const Dali::Actor& child, Dimension::Type dimension )
- {
- return CalculateChildSizeBase( child, dimension );
- }
-
- bool TestRelayoutDependentOnChildrenBase( Dimension::Type dimension )
- {
- return RelayoutDependentOnChildrenBase( dimension );
- }
-
- Property::Index mDaliProperty;
- std::vector< std::string > mMethodsCalled;
- Vector3 mSizeSet;
- Vector3 mTargetSize;
- bool mNego;
-};
-
-/**
- * Variant which adds a new child during OnStageConnection
- */
-struct TestCustomActorVariant1 : public TestCustomActor
-{
- /**
- * Constructor
- */
- TestCustomActorVariant1( Actor childToAdd )
- : mChildToAdd( childToAdd )
- {
- }
-
- // From CustomActorImpl
- virtual void OnStageConnection()
- {
- // Chain up first
- TestCustomActor::OnStageConnection();
-
- // Add the child
- Self().Add( mChildToAdd );
- }
-
- Actor mChildToAdd;
-};
-
-/**
- * Variant which removes children during OnStageConnection
- */
-struct TestCustomActorVariant2 : public TestCustomActor
-{
- /**
- * Constructor
- */
- TestCustomActorVariant2()
- {
- }
-
- // From CustomActorImpl
- virtual void OnStageConnection()
- {
- // Chain up first
- TestCustomActor::OnStageConnection();
-
- // Remove all the children
- for( unsigned int i=0, num=Self().GetChildCount(); i<num; ++i )
- {
- Self().Remove( Self().GetChildAt(0) );
- }
- }
-};
-
-/**
- * Variant which adds a new child during OnStageDisconnection
- */
-struct TestCustomActorVariant3 : public TestCustomActor
-{
- /**
- * Constructor
- */
- TestCustomActorVariant3( Actor childToAdd )
- : mChildToAdd( childToAdd )
- {
- }
-
- // From CustomActorImpl
- virtual void OnStageDisconnection()
- {
- // Chain up first
- TestCustomActor::OnStageDisconnection();
-
- // Add the child
- Self().Add( mChildToAdd );
- }
-
- Actor mChildToAdd;
-};
-
-/**
- * Variant which removes children during OnStageDisconnection
- */
-struct TestCustomActorVariant4 : public TestCustomActor
-{
- /**
- * Constructor
- */
- TestCustomActorVariant4()
- {
- }
-
- // From CustomActorImpl
- virtual void OnStageDisconnection()
- {
- // Chain up first
- TestCustomActor::OnStageDisconnection();
-
- // Remove all the children
- for( unsigned int i=0, num=Self().GetChildCount(); i<num; ++i )
- {
- Self().Remove( Self().GetChildAt(0) );
- }
- }
-};
-
-/**
- * Variant which removes its parent from Stage during OnStageConnection
- */
-struct TestCustomActorVariant5 : public TestCustomActor
-{
- /**
- * Constructor
- */
- TestCustomActorVariant5()
- {
- }
-
- // From CustomActorImpl
- virtual void OnStageConnection()
- {
- // Chain up first
- TestCustomActor::OnStageConnection();
-
- // Take parent off-stage
- Actor parent = Self().GetParent();
- if ( parent )
- {
- Stage::GetCurrent().Remove( parent );
- }
- }
-};
-
-/**
- * Variant which adds its parent to Stage during OnStageDisconnection
- */
-struct TestCustomActorVariant6 : public TestCustomActor
-{
- /**
- * Constructor
- */
- TestCustomActorVariant6()
- {
- }
-
- // From CustomActorImpl
- virtual void OnStageDisconnection()
- {
- // Chain up first
- TestCustomActor::OnStageDisconnection();
-
- // Put parent on-stage
- Actor parent = Self().GetParent();
- if ( parent )
- {
- Stage::GetCurrent().Add( parent );
- }
- }
-};
-
-/**
- * Variant which reparents its children into a separate container
- */
-struct TestCustomActorVariant7 : public TestCustomActor
-{
- /**
- * Constructor
- */
- TestCustomActorVariant7()
- {
- }
-
- virtual void OnInitialize( const char* name )
- {
- // We need to do this early, before the OnChildAdd is recorded
- Self().SetName( name );
-
- mContainer = Actor::New();
- mContainer.SetName( "Container" );
- Self().Add( mContainer );
- }
-
- // From CustomActorImpl
- virtual void OnChildAdd(Actor& child)
- {
- // Chain up first
- TestCustomActor::OnChildAdd(child);
-
- // Reparent child
- if ( child != mContainer )
- {
- mContainer.Add( child );
- }
- }
-
- Actor mContainer;
-};
-
-/**
- * Variant which attempts to interfere with the reparenting of a child to another container
- */
-struct TestCustomActorVariant8 : public TestCustomActor
-{
- /**
- * Constructor
- */
- TestCustomActorVariant8( Actor rival )
- : mRivalContainer( rival )
- {
- }
-
- // From CustomActorImpl
- virtual void OnChildRemove(Actor& child)
- {
- // Chain up first
- TestCustomActor::OnChildRemove(child);
-
- mRivalContainer.Remove( child ); // attempt to block reparenting to rival (should be a NOOP)
- }
-
- Actor mRivalContainer;
-};
-
-// Need a class that doesn't override virtual methods
-class SimpleTestCustomActor : public CustomActorImpl
-{
-public:
-
- /**
- * Constructor
- */
- SimpleTestCustomActor()
- : CustomActorImpl( ActorFlags( REQUIRES_TOUCH_EVENTS | DISABLE_SIZE_NEGOTIATION ) )
- {
- }
-
- /**
- * Destructor
- */
- virtual ~SimpleTestCustomActor()
- {
- }
-
- // From CustomActorImpl
- virtual void OnStageConnection()
- {
- }
- virtual void OnStageDisconnection()
- {
- }
- virtual void OnChildAdd(Actor& child)
- {
- }
- virtual void OnChildRemove(Actor& child)
- {
- }
- virtual void OnSizeSet(const Vector3& targetSize)
- {
- }
- virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize)
- {
- }
- virtual bool OnTouchEvent(const TouchEvent& event)
- {
- return true;
- }
- virtual bool OnHoverEvent(const HoverEvent& event)
- {
- return true;
- }
- virtual bool OnWheelEvent(const WheelEvent& event)
- {
- return true;
- }
- virtual bool OnKeyEvent(const KeyEvent& event)
- {
- return true;
- }
- virtual void OnKeyInputFocusGained()
- {
- }
- virtual void OnKeyInputFocusLost()
- {
- }
-
- virtual Vector3 GetNaturalSize()
- {
- return Vector3( 0.0f, 0.0f, 0.0f );
- }
-
- virtual float GetHeightForWidth( float width )
- {
- return 0.0f;
- }
-
- virtual float GetWidthForHeight( float height )
- {
- return 0.0f;
- }
-
- virtual void OnRelayout( const Vector2& size, RelayoutContainer& container )
- {
- }
-
- virtual void OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
- {
- }
-
- virtual void OnCalculateRelayoutSize( Dimension::Type dimension )
- {
- }
-
- virtual float CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension )
- {
- return 0.0f;
- }
-
- virtual void OnLayoutNegotiated( float size, Dimension::Type dimension )
- {
- }
-
- virtual bool RelayoutDependentOnChildren( Dimension::Type dimension = Dimension::ALL_DIMENSIONS )
- {
- return false;
- }
-};
-
-} ; // namespace Impl
-
-
-namespace
-{
-
-/**
- * Test custom actor handle
- */
-class TestCustomActor : public CustomActor
-{
-public:
-
- static TestCustomActor New()
- {
- Impl::TestCustomActor* impl = new Impl::TestCustomActor;
- TestCustomActor custom( *impl ); // takes ownership
-
- impl->Initialize();
-
- return custom;
- }
-
- static TestCustomActor NewNegoSize()
- {
- Impl::TestCustomActor* impl = new Impl::TestCustomActor( true );
- TestCustomActor custom( *impl ); // takes ownership
- custom.SetName( "SizeNegotiationActor" );
-
- impl->Initialize();
-
- return custom;
- }
-
- static TestCustomActor NewVariant1( Actor childToAdd )
- {
- Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant1( childToAdd );
- TestCustomActor custom( *impl ); // takes ownership
-
- impl->Initialize();
-
- return custom;
- }
-
- static TestCustomActor NewVariant2()
- {
- Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant2();
- TestCustomActor custom( *impl ); // takes ownership
-
- impl->Initialize();
-
- return custom;
- }
-
- static TestCustomActor NewVariant3( Actor childToAdd )
- {
- Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant3( childToAdd );
- TestCustomActor custom( *impl ); // takes ownership
-
- impl->Initialize();
-
- return custom;
- }
-
- static TestCustomActor NewVariant4()
- {
- Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant4();
- TestCustomActor custom( *impl ); // takes ownership
-
- impl->Initialize();
-
- return custom;
- }
-
- static TestCustomActor NewVariant5()
- {
- Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant5();
- TestCustomActor custom( *impl ); // takes ownership
-
- impl->Initialize();
-
- return custom;
- }
-
- static TestCustomActor NewVariant6()
- {
- Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant6();
- TestCustomActor custom( *impl ); // takes ownership
-
- impl->Initialize();
-
- return custom;
- }
-
- static TestCustomActor NewVariant7( const char* name )
- {
- Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant7();
- TestCustomActor custom( *impl ); // takes ownership
-
- impl->Initialize( name );
-
- return custom;
- }
-
- static TestCustomActor NewVariant8( Actor rival )
- {
- Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant8( rival );
- TestCustomActor custom( *impl ); // takes ownership
-
- impl->Initialize();
-
- return custom;
- }
-
- virtual ~TestCustomActor()
- {
- }
-
- Impl::TestCustomActor& GetImpl()
- {
- return static_cast<Impl::TestCustomActor&>(GetImplementation());
- }
-
- std::vector< std::string >& GetMethodsCalled()
- {
- return GetImpl().mMethodsCalled;
- }
-
- void ResetCallStack()
- {
- GetImpl().ResetCallStack();
- }
-
- void SetDaliProperty(std::string s)
- {
- GetImpl().SetDaliProperty(s);
- }
-
- Vector3 GetSize()
- {
- return GetImpl().mSizeSet;
- }
-
- Vector3 GetTargetSize()
- {
- return GetImpl().mTargetSize;
- }
-
- virtual Vector3 GetNaturalSize()
- {
- return Vector3( 0.0f, 0.0f, 0.0f );
- }
-
- virtual float GetHeightForWidth( float width )
- {
- return 0.0f;
- }
-
- virtual float GetWidthForHeight( float height )
- {
- return 0.0f;
- }
-
- virtual void OnRelayout( const Vector2& size, RelayoutContainer& container )
- {
- }
-
- virtual void OnLayoutNegotiated( float size, Dimension::Type dimension )
- {
- }
-
- virtual void OnCalculateRelayoutSize( Dimension::Type dimension )
- {
- }
-
- void TestRelayoutRequest()
- {
- GetImpl().TestRelayoutRequest();
- }
-
- float TestGetHeightForWidthBase( float width )
- {
- return GetImpl().TestGetHeightForWidthBase( width );
- }
-
- float TestGetWidthForHeightBase( float height )
- {
- return GetImpl().TestGetWidthForHeightBase( height );
- }
-
- float TestCalculateChildSizeBase( const Dali::Actor& child, Dimension::Type dimension )
- {
- return GetImpl().TestCalculateChildSizeBase( child, dimension );
- }
-
- bool TestRelayoutDependentOnChildrenBase( Dimension::Type dimension )
- {
- return GetImpl().TestRelayoutDependentOnChildrenBase( dimension );
- }
-
-private:
-
- TestCustomActor( Impl::TestCustomActor& impl ) : CustomActor( impl )
- {
- }
-};
-