1 #ifndef TEST_CUSTOM_ACTOR_H
2 #define TEST_CUSTOM_ACTOR_H
4 #include <dali/public-api/dali-core.h>
5 #include <dali/devel-api/object/property-helper-devel.h>
7 extern std::vector< std::string > MasterCallStack;
8 extern bool gOnRelayout;
14 struct TestCustomActor;
18 * Test custom actor handle
20 class TestCustomActor : public Dali::CustomActor
25 PROPERTY_START_INDEX = Dali::PROPERTY_REGISTRATION_START_INDEX,
26 PROPERTY_END_INDEX = PROPERTY_START_INDEX + 1000
33 TEST_PROPERTY1 = PROPERTY_START_INDEX,
39 static TestCustomActor New();
40 static TestCustomActor NewNegoSize();
41 static TestCustomActor NewVariant1( Actor childToAdd );
42 static TestCustomActor NewVariant2();
43 static TestCustomActor NewVariant3( Actor childToAdd );
44 static TestCustomActor NewVariant4();
45 static TestCustomActor NewVariant5();
46 static TestCustomActor NewVariant6();
47 static TestCustomActor NewVariant7( const char* name );
48 static TestCustomActor NewVariant8( Actor rival );
49 static TestCustomActor DownCast( Dali::BaseHandle handle );
51 virtual ~TestCustomActor();
52 Impl::TestCustomActor& GetImpl();
54 std::vector< std::string >& GetMethodsCalled();
55 void ResetCallStack();
56 void SetDaliProperty(std::string s);
57 Dali::Vector3 GetSize();
58 Dali::Vector3 GetTargetSize();
59 virtual Dali::Vector3 GetNaturalSize();
60 virtual float GetHeightForWidth( float width );
61 virtual float GetWidthForHeight( float height );
62 virtual void OnRelayout( const Dali::Vector2& size, Dali::RelayoutContainer& container );
63 virtual void OnLayoutNegotiated( float size, Dali::Dimension::Type dimension );
64 virtual void OnCalculateRelayoutSize( Dali::Dimension::Type dimension );
65 void TestRelayoutRequest();
66 float TestGetHeightForWidthBase( float width );
67 float TestGetWidthForHeightBase( float height );
68 float TestCalculateChildSizeBase( const Dali::Actor& child, Dali::Dimension::Type dimension );
69 bool TestRelayoutDependentOnChildrenBase( Dali::Dimension::Type dimension );
73 TestCustomActor( Impl::TestCustomActor& impl );
74 explicit TestCustomActor(Dali::Internal::CustomActor* internal);
78 namespace DevelTestCustomActor
84 TEST_PROPERTY1 = Test::TestCustomActor::Property::TEST_PROPERTY1,
85 TEST_PROPERTY2 = Test::TestCustomActor::Property::TEST_PROPERTY2,
86 DEVEL_TEST_PROPERTY3 = TEST_PROPERTY2+1,
87 DEVEL_TEST_PROPERTY4 = TEST_PROPERTY2+2,
88 DEVEL_TEST_PROPERTY5 = TEST_PROPERTY2+3,
89 DEVEL_TEST_PROPERTY6 = TEST_PROPERTY2+4
92 } // Namespace Property
93 } // Namespace DevelTestCustomActor
96 // TypeRegistry needs custom actor Implementations to have the same name (namespaces are ignored so we use one here)
100 struct TestCustomActor : public Dali::CustomActorImpl
107 TestCustomActor(bool nego);
108 virtual ~TestCustomActor();
109 void Initialize( const char* name = NULL );
110 virtual void OnInitialize( const char* name );
111 void ResetCallStack();
112 void AddToCallStacks( const char* method );
113 virtual void OnStageConnection( int depth );
114 virtual void OnStageDisconnection();
115 virtual void OnChildAdd(Dali::Actor& child);
116 virtual void OnChildRemove(Dali::Actor& child);
117 virtual void OnPropertySet( Dali::Property::Index index, Dali::Property::Value propertyValue );
118 virtual void OnSizeSet(const Dali::Vector3& targetSize);
119 virtual void OnSizeAnimation(Dali::Animation& animation, const Dali::Vector3& targetSize);
120 virtual bool OnTouchEvent(const Dali::TouchEvent& event);
121 virtual bool OnHoverEvent(const Dali::HoverEvent& event);
122 virtual bool OnWheelEvent(const Dali::WheelEvent& event);
123 virtual bool OnKeyEvent(const Dali::KeyEvent& event);
124 virtual void OnKeyInputFocusGained();
125 virtual void OnKeyInputFocusLost();
126 virtual Dali::Vector3 GetNaturalSize();
127 virtual float GetHeightForWidth( float width );
128 virtual float GetWidthForHeight( float height );
129 virtual void OnRelayout( const Dali::Vector2& size, Dali::RelayoutContainer& container );
130 virtual void OnSetResizePolicy( Dali::ResizePolicy::Type policy, Dali::Dimension::Type dimension );
131 virtual void OnCalculateRelayoutSize( Dali::Dimension::Type dimension );
132 virtual float CalculateChildSize( const Dali::Actor& child, Dali::Dimension::Type dimension );
133 virtual void OnLayoutNegotiated( float size, Dali::Dimension::Type dimension );
134 virtual bool RelayoutDependentOnChildren( Dali::Dimension::Type dimension = Dali::Dimension::ALL_DIMENSIONS );
135 static void SetProperty( Dali::BaseObject* object, Dali::Property::Index index, const Dali::Property::Value& value );
136 static Dali::Property::Value GetProperty( Dali::BaseObject* object, Dali::Property::Index index );
138 void SetDaliProperty(std::string s);
139 void TestRelayoutRequest();
140 float TestGetHeightForWidthBase( float width );
141 float TestGetWidthForHeightBase( float height );
142 float TestCalculateChildSizeBase( const Dali::Actor& child, Dali::Dimension::Type dimension );
143 bool TestRelayoutDependentOnChildrenBase( Dali::Dimension::Type dimension );
146 Dali::Property::Index mDaliProperty;
147 std::vector< std::string > mMethodsCalled;
148 Dali::Vector3 mSizeSet;
149 Dali::Vector3 mTargetSize;
155 Dali::Vector4 develProp3;
161 inline TestCustomActor& GetImpl( Test::TestCustomActor& handle )
163 DALI_ASSERT_ALWAYS( handle );
164 Dali::RefObject& object = handle.GetImplementation();
165 return static_cast<TestCustomActor&>( object );
168 inline const TestCustomActor& GetImpl( const Test::TestCustomActor& handle )
170 DALI_ASSERT_ALWAYS( handle );
171 const Dali::RefObject& object = handle.GetImplementation();
172 return static_cast<const TestCustomActor&>( object );
177 * Variant which adds a new child during OnStageConnection
179 struct TestCustomActorVariant1 : public TestCustomActor
184 TestCustomActorVariant1( Dali::Actor childToAdd )
185 : mChildToAdd( childToAdd )
189 // From CustomActorImpl
190 virtual void OnStageConnection( int depth )
193 TestCustomActor::OnStageConnection( depth );
196 Self().Add( mChildToAdd );
199 Dali::Actor mChildToAdd;
203 * Variant which removes children during OnStageConnection
205 struct TestCustomActorVariant2 : public TestCustomActor
210 TestCustomActorVariant2()
214 // From CustomActorImpl
215 virtual void OnStageConnection( int depth )
218 TestCustomActor::OnStageConnection( depth );
220 // Remove all the children
221 for( uint32_t i=0, num=Self().GetChildCount(); i<num; ++i )
223 Self().Remove( Self().GetChildAt(0) );
229 * Variant which adds a new child during OnStageDisconnection
231 struct TestCustomActorVariant3 : public TestCustomActor
236 TestCustomActorVariant3( Dali::Actor childToAdd )
237 : mChildToAdd( childToAdd )
241 // From CustomActorImpl
242 virtual void OnStageDisconnection()
245 TestCustomActor::OnStageDisconnection();
248 Self().Add( mChildToAdd );
251 Dali::Actor mChildToAdd;
255 * Variant which removes children during OnStageDisconnection
257 struct TestCustomActorVariant4 : public TestCustomActor
262 TestCustomActorVariant4()
266 // From CustomActorImpl
267 virtual void OnStageDisconnection()
270 TestCustomActor::OnStageDisconnection();
272 // Remove all the children
273 for( uint32_t i=0, num=Self().GetChildCount(); i<num; ++i )
275 Self().Remove( Self().GetChildAt(0) );
281 * Variant which removes its parent from Stage during OnStageConnection
283 struct TestCustomActorVariant5 : public TestCustomActor
288 TestCustomActorVariant5()
292 // From CustomActorImpl
293 virtual void OnStageConnection( int depth )
296 TestCustomActor::OnStageConnection( depth );
298 // Take parent off-stage
299 Dali::Actor parent = Self().GetParent();
302 Dali::Stage::GetCurrent().Remove( parent );
308 * Variant which adds its parent to Stage during OnStageDisconnection
310 struct TestCustomActorVariant6 : public TestCustomActor
315 TestCustomActorVariant6()
319 // From CustomActorImpl
320 virtual void OnStageDisconnection()
323 TestCustomActor::OnStageDisconnection();
325 // Put parent on-stage
326 Dali::Actor parent = Self().GetParent();
329 Dali::Stage::GetCurrent().Add( parent );
335 * Variant which reparents its children into a separate container
337 struct TestCustomActorVariant7 : public TestCustomActor
342 TestCustomActorVariant7()
346 virtual void OnInitialize( const char* name )
348 // We need to do this early, before the OnChildAdd is recorded
349 Self().SetProperty( Dali::Actor::Property::NAME, name );
351 mContainer = Dali::Actor::New();
352 mContainer.SetProperty( Dali::Actor::Property::NAME, "Container" );
353 Self().Add( mContainer );
356 // From CustomActorImpl
357 virtual void OnChildAdd(Dali::Actor& child)
360 TestCustomActor::OnChildAdd(child);
363 if ( child != mContainer )
365 mContainer.Add( child );
369 Dali::Actor mContainer;
373 * Variant which attempts to interfere with the reparenting of a child to another container
375 struct TestCustomActorVariant8 : public TestCustomActor
380 TestCustomActorVariant8( Dali::Actor rival )
381 : mRivalContainer( rival )
385 // From CustomActorImpl
386 virtual void OnChildRemove(Dali::Actor& child)
389 TestCustomActor::OnChildRemove(child);
391 mRivalContainer.Remove( child ); // attempt to block reparenting to rival (should be a NOOP)
394 Dali::Actor mRivalContainer;
397 // Need a class that doesn't override virtual methods
398 class SimpleTestCustomActor : public Dali::CustomActorImpl
405 SimpleTestCustomActor()
406 : CustomActorImpl( ActorFlags( REQUIRES_TOUCH_EVENTS | DISABLE_SIZE_NEGOTIATION ) )
413 virtual ~SimpleTestCustomActor()
417 // From CustomActorImpl
418 virtual void OnStageConnection( int depth )
421 virtual void OnStageDisconnection()
424 virtual void OnChildAdd(Dali::Actor& child)
427 virtual void OnChildRemove(Dali::Actor& child)
430 virtual void OnSizeSet(const Dali::Vector3& targetSize)
433 virtual void OnSizeAnimation(Dali::Animation& animation, const Dali::Vector3& targetSize)
436 virtual bool OnTouchEvent(const Dali::TouchEvent& event)
440 virtual bool OnHoverEvent(const Dali::HoverEvent& event)
444 virtual bool OnWheelEvent(const Dali::WheelEvent& event)
448 virtual bool OnKeyEvent(const Dali::KeyEvent& event)
452 virtual void OnKeyInputFocusGained()
455 virtual void OnKeyInputFocusLost()
459 virtual Dali::Vector3 GetNaturalSize()
461 return Dali::Vector3( 0.0f, 0.0f, 0.0f );
464 virtual float GetHeightForWidth( float width )
469 virtual float GetWidthForHeight( float height )
474 virtual void OnRelayout( const Dali::Vector2& size, Dali::RelayoutContainer& container )
478 virtual void OnSetResizePolicy( Dali::ResizePolicy::Type policy, Dali::Dimension::Type dimension )
482 virtual void OnCalculateRelayoutSize( Dali::Dimension::Type dimension )
486 virtual float CalculateChildSize( const Dali::Actor& child, Dali::Dimension::Type dimension )
491 virtual void OnLayoutNegotiated( float size, Dali::Dimension::Type dimension )
495 virtual bool RelayoutDependentOnChildren( Dali::Dimension::Type dimension = Dali::Dimension::ALL_DIMENSIONS )
504 #endif // TEST_CUSTOM_ACTOR_H