1 #include "test-custom-actor.h"
5 std::vector< std::string > MasterCallStack;
6 bool gOnRelayout = false;
12 struct TestCustomActor;
16 TestCustomActor TestCustomActor::New()
18 Impl::TestCustomActor* impl = new Impl::TestCustomActor;
19 TestCustomActor custom( *impl ); // takes ownership
26 TestCustomActor TestCustomActor::NewNegoSize()
28 Impl::TestCustomActor* impl = new Impl::TestCustomActor( true );
29 TestCustomActor custom( *impl ); // takes ownership
30 custom.SetName( "SizeNegotiationActor" );
37 TestCustomActor TestCustomActor::NewVariant1( Actor childToAdd )
39 Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant1( childToAdd );
40 TestCustomActor custom( *impl ); // takes ownership
47 TestCustomActor TestCustomActor::NewVariant2()
49 Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant2();
50 TestCustomActor custom( *impl ); // takes ownership
57 TestCustomActor TestCustomActor::NewVariant3( Actor childToAdd )
59 Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant3( childToAdd );
60 TestCustomActor custom( *impl ); // takes ownership
67 TestCustomActor TestCustomActor::NewVariant4()
69 Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant4();
70 TestCustomActor custom( *impl ); // takes ownership
77 TestCustomActor TestCustomActor::NewVariant5()
79 Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant5();
80 TestCustomActor custom( *impl ); // takes ownership
87 TestCustomActor TestCustomActor::NewVariant6()
89 Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant6();
90 TestCustomActor custom( *impl ); // takes ownership
97 TestCustomActor TestCustomActor::NewVariant7( const char* name )
99 Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant7();
100 TestCustomActor custom( *impl ); // takes ownership
102 impl->Initialize( name );
107 TestCustomActor TestCustomActor::NewVariant8( Actor rival )
109 Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant8( rival );
110 TestCustomActor custom( *impl ); // takes ownership
117 TestCustomActor::~TestCustomActor()
121 Impl::TestCustomActor& TestCustomActor::GetImpl()
123 return static_cast<Impl::TestCustomActor&>(GetImplementation());
126 std::vector< std::string >& TestCustomActor::GetMethodsCalled()
128 return GetImpl().mMethodsCalled;
131 void TestCustomActor::ResetCallStack()
133 GetImpl().ResetCallStack();
136 void TestCustomActor::SetDaliProperty(std::string s)
138 GetImpl().SetDaliProperty(s);
141 Vector3 TestCustomActor::GetSize()
143 return GetImpl().mSizeSet;
146 Vector3 TestCustomActor::GetTargetSize()
148 return GetImpl().mTargetSize;
151 Vector3 TestCustomActor::GetNaturalSize()
153 return Vector3( 0.0f, 0.0f, 0.0f );
156 float TestCustomActor::GetHeightForWidth( float width )
161 float TestCustomActor::GetWidthForHeight( float height )
166 void TestCustomActor::OnRelayout( const Vector2& size, RelayoutContainer& container )
170 void TestCustomActor::OnLayoutNegotiated( float size, Dimension::Type dimension )
174 void TestCustomActor::OnCalculateRelayoutSize( Dimension::Type dimension )
178 void TestCustomActor::TestRelayoutRequest()
180 GetImpl().TestRelayoutRequest();
183 float TestCustomActor::TestGetHeightForWidthBase( float width )
185 return GetImpl().TestGetHeightForWidthBase( width );
188 float TestCustomActor::TestGetWidthForHeightBase( float height )
190 return GetImpl().TestGetWidthForHeightBase( height );
193 float TestCustomActor::TestCalculateChildSizeBase( const Dali::Actor& child, Dimension::Type dimension )
195 return GetImpl().TestCalculateChildSizeBase( child, dimension );
198 bool TestCustomActor::TestRelayoutDependentOnChildrenBase( Dimension::Type dimension )
200 return GetImpl().TestRelayoutDependentOnChildrenBase( dimension );
203 uint32_t TestCustomActor::GetDepth()
205 return GetImpl().mDepth;
208 TestCustomActor::TestCustomActor()
212 TestCustomActor::TestCustomActor( Impl::TestCustomActor& impl )
213 : CustomActor( impl )
217 TestCustomActor::TestCustomActor( Dali::Internal::CustomActor* internal )
218 : CustomActor( internal )
222 TestCustomActor TestCustomActor::DownCast( BaseHandle handle )
224 TestCustomActor actor;
225 CustomActor custom = Dali::CustomActor::DownCast(handle);
228 CustomActorImpl& customImpl = custom.GetImplementation();
230 Test::Impl::TestCustomActor* impl = dynamic_cast<Test::Impl::TestCustomActor*>(&customImpl);
233 actor = TestCustomActor(customImpl.GetOwner());
242 TestCustomActor::TestCustomActor()
243 : CustomActorImpl( ActorFlags( REQUIRES_TOUCH_EVENTS | REQUIRES_WHEEL_EVENTS | REQUIRES_HOVER_EVENTS | DISABLE_SIZE_NEGOTIATION ) ),
244 mDaliProperty( Property::INVALID_INDEX ),
245 mSizeSet( Vector3::ZERO ),
246 mTargetSize( Vector3::ZERO ),
253 TestCustomActor::TestCustomActor(bool nego)
254 : CustomActorImpl( ActorFlags( REQUIRES_TOUCH_EVENTS | REQUIRES_WHEEL_EVENTS | REQUIRES_HOVER_EVENTS ) ),
255 mDaliProperty( Property::INVALID_INDEX ),
256 mSizeSet( Vector3::ZERO ),
257 mTargetSize( Vector3::ZERO ),
265 TestCustomActor::~TestCustomActor()
269 void TestCustomActor::Initialize( const char* name )
271 mDaliProperty = Self().RegisterProperty( "Dali", std::string("no"), Property::READ_WRITE);
273 OnInitialize( name );
276 void TestCustomActor::OnInitialize( const char* name ) {}
279 * Resets the call stack
281 void TestCustomActor::ResetCallStack()
283 mSizeSet = Vector3();
284 mTargetSize = Vector3();
285 mMethodsCalled.clear();
288 void TestCustomActor::AddToCallStacks( const char* method )
290 mMethodsCalled.push_back( method );
292 // Combine Actor name with method string
293 std::string nameAndMethod( Self().GetName() );
294 if ( 0 == nameAndMethod.size() )
296 nameAndMethod = "Unknown: ";
300 nameAndMethod += ": ";
302 nameAndMethod += method;
304 MasterCallStack.push_back( nameAndMethod );
307 // From CustomActorImpl
308 void TestCustomActor::OnStageConnection( int depth )
310 AddToCallStacks("OnStageConnection");
313 void TestCustomActor::OnStageDisconnection()
315 AddToCallStacks("OnStageDisconnection");
317 void TestCustomActor::OnChildAdd(Actor& child)
319 AddToCallStacks("OnChildAdd");
321 void TestCustomActor::OnChildRemove(Actor& child)
323 AddToCallStacks("OnChildRemove");
325 void TestCustomActor::OnPropertySet( Property::Index index, Property::Value propertyValue )
327 AddToCallStacks("OnPropertySet");
329 void TestCustomActor::OnSizeSet(const Vector3& targetSize)
331 mSizeSet = targetSize;
332 AddToCallStacks("OnSizeSet");
334 void TestCustomActor::OnSizeAnimation(Animation& animation, const Vector3& targetSize)
336 mTargetSize = targetSize;
337 AddToCallStacks("OnSizeAnimation");
339 bool TestCustomActor::OnTouchEvent(const TouchEvent& event)
341 AddToCallStacks("OnTouchEvent");
344 bool TestCustomActor::OnHoverEvent(const HoverEvent& event)
346 AddToCallStacks("OnHoverEvent");
349 bool TestCustomActor::OnWheelEvent(const WheelEvent& event)
351 AddToCallStacks("OnWheelEvent");
354 bool TestCustomActor::OnKeyEvent(const KeyEvent& event)
356 AddToCallStacks("OnKeyEvent");
359 void TestCustomActor::OnKeyInputFocusGained()
361 AddToCallStacks("OnKeyInputFocusGained");
363 void TestCustomActor::OnKeyInputFocusLost()
365 AddToCallStacks("OnKeyInputFocusLost");
367 Vector3 TestCustomActor::GetNaturalSize()
369 return Vector3( 0.0f, 0.0f, 0.0f );
372 float TestCustomActor::GetHeightForWidth( float width )
377 float TestCustomActor::GetWidthForHeight( float height )
382 void TestCustomActor::OnRelayout( const Vector2& size, RelayoutContainer& container )
387 void TestCustomActor::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
391 void TestCustomActor::OnCalculateRelayoutSize( Dimension::Type dimension )
395 float TestCustomActor::CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension )
400 void TestCustomActor::OnLayoutNegotiated( float size, Dimension::Type dimension )
404 bool TestCustomActor::RelayoutDependentOnChildren( Dimension::Type dimension )
409 void TestCustomActor::SetDaliProperty(std::string s)
411 Self().SetProperty(mDaliProperty, s);
413 void TestCustomActor::TestRelayoutRequest()
418 float TestCustomActor::TestGetHeightForWidthBase( float width )
420 return GetHeightForWidthBase( width );
423 float TestCustomActor::TestGetWidthForHeightBase( float height )
425 return GetWidthForHeightBase( height );
428 float TestCustomActor::TestCalculateChildSizeBase( const Dali::Actor& child, Dimension::Type dimension )
430 return CalculateChildSizeBase( child, dimension );
433 bool TestCustomActor::TestRelayoutDependentOnChildrenBase( Dimension::Type dimension )
435 return RelayoutDependentOnChildrenBase( dimension );
438 void TestCustomActor::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
440 Test::TestCustomActor actor = Test::TestCustomActor::DownCast( Dali::BaseHandle( object ) );
444 TestCustomActor& actorImpl = GetImpl(actor);
447 case Test::TestCustomActor::Property::TEST_PROPERTY1:
449 actorImpl.prop1 = value.Get<float>();
452 case Test::TestCustomActor::Property::TEST_PROPERTY2:
454 actorImpl.prop2 = value.Get<Vector4>();
457 case Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY3:
459 actorImpl.develProp3 = value.Get<Vector4>();
462 case Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY4:
464 actorImpl.develProp4 = value.Get<int>();
467 case Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY5:
469 actorImpl.develProp5 = value.Get<float>();
476 Property::Value TestCustomActor::GetProperty( BaseObject* object, Property::Index index )
478 Test::TestCustomActor actor = Test::TestCustomActor::DownCast( Dali::BaseHandle( object ) );
482 TestCustomActor& actorImpl = GetImpl(actor);
485 case Test::TestCustomActor::Property::TEST_PROPERTY1:
487 return Property::Value(actorImpl.prop1);
489 case Test::TestCustomActor::Property::TEST_PROPERTY2:
491 return Property::Value(actorImpl.prop2);
493 case Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY3:
495 return Property::Value(actorImpl.develProp3);
497 case Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY4:
499 return Property::Value(actorImpl.develProp4);
501 case Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY5:
503 return Property::Value(actorImpl.develProp5);
505 case Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY6:
507 return Property::Value(actorImpl.develProp6);
511 return Property::Value();
515 BaseHandle CreateActor()
517 return Test::TestCustomActor::New();
520 DALI_TYPE_REGISTRATION_BEGIN( Test::TestCustomActor, Dali::CustomActor, CreateActor );
522 DALI_PROPERTY_REGISTRATION( Test, TestCustomActor, "testProperty1", FLOAT, TEST_PROPERTY1)
523 DALI_PROPERTY_REGISTRATION( Test, TestCustomActor, "testProperty2", VECTOR4, TEST_PROPERTY2)
524 DALI_DEVEL_PROPERTY_REGISTRATION( Test, TestCustomActor, "develTestProperty3", VECTOR4, DEVEL_TEST_PROPERTY3)
525 DALI_DEVEL_PROPERTY_REGISTRATION( Test, TestCustomActor, "develTestProperty4", INTEGER, DEVEL_TEST_PROPERTY4)
526 DALI_DEVEL_PROPERTY_REGISTRATION( Test, TestCustomActor, "develTestProperty5", FLOAT, DEVEL_TEST_PROPERTY5)
527 DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY( Test, TestCustomActor, "develTestProperty6", FLOAT, DEVEL_TEST_PROPERTY6)
529 DALI_TYPE_REGISTRATION_END()