Move Stage to Devel API
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / dali-test-suite-utils / test-custom-actor.cpp
1 #include "test-custom-actor.h"
2
3 using namespace Dali;
4
5 std::vector< std::string > MasterCallStack;
6 bool gOnRelayout = false;
7
8 namespace Test
9 {
10 namespace Impl
11 {
12 struct TestCustomActor;
13 }
14
15
16 TestCustomActor TestCustomActor::New()
17 {
18   Impl::TestCustomActor* impl = new Impl::TestCustomActor;
19   TestCustomActor custom( *impl ); // takes ownership
20
21   impl->Initialize();
22
23   return custom;
24 }
25
26 TestCustomActor TestCustomActor::NewNegoSize()
27 {
28   Impl::TestCustomActor* impl = new Impl::TestCustomActor( true );
29   TestCustomActor custom( *impl ); // takes ownership
30   custom.SetProperty( Dali::Actor::Property::NAME, "SizeNegotiationActor" );
31
32   impl->Initialize();
33
34   return custom;
35 }
36
37 TestCustomActor TestCustomActor::NewVariant1( Actor childToAdd )
38 {
39   Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant1( childToAdd );
40   TestCustomActor custom( *impl ); // takes ownership
41
42   impl->Initialize();
43
44   return custom;
45 }
46
47 TestCustomActor TestCustomActor::NewVariant2()
48 {
49   Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant2();
50   TestCustomActor custom( *impl ); // takes ownership
51
52   impl->Initialize();
53
54   return custom;
55 }
56
57 TestCustomActor TestCustomActor::NewVariant3( Actor childToAdd )
58 {
59   Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant3( childToAdd );
60   TestCustomActor custom( *impl ); // takes ownership
61
62   impl->Initialize();
63
64   return custom;
65 }
66
67 TestCustomActor TestCustomActor::NewVariant4()
68 {
69   Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant4();
70   TestCustomActor custom( *impl ); // takes ownership
71
72   impl->Initialize();
73
74   return custom;
75 }
76
77 TestCustomActor TestCustomActor::NewVariant5(Integration::Scene scene)
78 {
79   Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant5(scene);
80   TestCustomActor custom( *impl ); // takes ownership
81
82   impl->Initialize();
83
84   return custom;
85 }
86
87 TestCustomActor TestCustomActor::NewVariant6(Integration::Scene scene)
88 {
89   Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant6(scene);
90   TestCustomActor custom( *impl ); // takes ownership
91
92   impl->Initialize();
93
94   return custom;
95 }
96
97 TestCustomActor TestCustomActor::NewVariant7( const char* name )
98 {
99   Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant7();
100   TestCustomActor custom( *impl ); // takes ownership
101
102   impl->Initialize( name );
103
104   return custom;
105 }
106
107 TestCustomActor TestCustomActor::NewVariant8( Actor rival )
108 {
109   Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant8( rival );
110   TestCustomActor custom( *impl ); // takes ownership
111
112   impl->Initialize();
113
114   return custom;
115 }
116
117 TestCustomActor::~TestCustomActor()
118 {
119 }
120
121 Impl::TestCustomActor& TestCustomActor::GetImpl()
122 {
123   return static_cast<Impl::TestCustomActor&>(GetImplementation());
124 }
125
126 std::vector< std::string >& TestCustomActor::GetMethodsCalled()
127 {
128   return GetImpl().mMethodsCalled;
129 }
130
131 void TestCustomActor::ResetCallStack()
132 {
133   GetImpl().ResetCallStack();
134 }
135
136 void TestCustomActor::SetDaliProperty(std::string s)
137 {
138   GetImpl().SetDaliProperty(s);
139 }
140
141 Vector3 TestCustomActor::GetSize()
142 {
143   return GetImpl().mSizeSet;
144 }
145
146 Vector3 TestCustomActor::GetTargetSize()
147 {
148   return GetImpl().mTargetSize;
149 }
150
151 Vector3 TestCustomActor::GetNaturalSize()
152 {
153   return Vector3( 0.0f, 0.0f, 0.0f );
154 }
155
156 float TestCustomActor::GetHeightForWidth( float width )
157 {
158   return 0.0f;
159 }
160
161 float TestCustomActor::GetWidthForHeight( float height )
162 {
163   return 0.0f;
164 }
165
166 void TestCustomActor::OnRelayout( const Vector2& size, RelayoutContainer& container )
167 {
168 }
169
170 void TestCustomActor::OnLayoutNegotiated( float size, Dimension::Type dimension )
171 {
172 }
173
174 void TestCustomActor::OnCalculateRelayoutSize( Dimension::Type dimension )
175 {
176 }
177
178 void TestCustomActor::TestRelayoutRequest()
179 {
180   GetImpl().TestRelayoutRequest();
181 }
182
183 float TestCustomActor::TestGetHeightForWidthBase( float width )
184 {
185   return GetImpl().TestGetHeightForWidthBase( width );
186 }
187
188 float TestCustomActor::TestGetWidthForHeightBase( float height )
189 {
190   return GetImpl().TestGetWidthForHeightBase( height );
191 }
192
193 float TestCustomActor::TestCalculateChildSizeBase( const Dali::Actor& child, Dimension::Type dimension )
194 {
195   return GetImpl().TestCalculateChildSizeBase( child, dimension );
196 }
197
198 bool TestCustomActor::TestRelayoutDependentOnChildrenBase( Dimension::Type dimension )
199 {
200   return GetImpl().TestRelayoutDependentOnChildrenBase( dimension );
201 }
202
203 uint32_t TestCustomActor::GetDepth()
204 {
205   return GetImpl().mDepth;
206 }
207
208 TestCustomActor::TestCustomActor()
209 {
210 }
211
212 TestCustomActor::TestCustomActor( Impl::TestCustomActor& impl )
213 : CustomActor( impl )
214 {
215 }
216
217 TestCustomActor::TestCustomActor( Dali::Internal::CustomActor* internal )
218 : CustomActor( internal )
219 {
220 }
221
222 TestCustomActor TestCustomActor::DownCast( BaseHandle handle )
223 {
224   TestCustomActor actor;
225   CustomActor custom = Dali::CustomActor::DownCast(handle);
226   if(custom)
227   {
228     CustomActorImpl& customImpl = custom.GetImplementation();
229
230     Test::Impl::TestCustomActor* impl = dynamic_cast<Test::Impl::TestCustomActor*>(&customImpl);
231     if( impl )
232     {
233       actor = TestCustomActor(customImpl.GetOwner());
234     }
235   }
236   return actor;
237 }
238
239 namespace Impl
240 {
241
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 ),
247   mNego( false ),
248   mDepth(0u),
249   develProp6( 10.0f )
250 {
251 }
252
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 ),
258   mNego( nego ),
259   develProp6( 10.0f )
260 {
261 }
262 /**
263  * Destructor
264  */
265 TestCustomActor::~TestCustomActor()
266 {
267 }
268
269 void TestCustomActor::Initialize( const char* name )
270 {
271   mDaliProperty = Self().RegisterProperty( "Dali", std::string("no"), Property::READ_WRITE);
272
273   OnInitialize( name );
274 }
275
276 void TestCustomActor::OnInitialize( const char* name ) {}
277
278 /**
279  * Resets the call stack
280  */
281 void TestCustomActor::ResetCallStack()
282 {
283   mSizeSet = Vector3();
284   mTargetSize = Vector3();
285   mMethodsCalled.clear();
286 }
287
288 void TestCustomActor::AddToCallStacks( const char* method )
289 {
290   mMethodsCalled.push_back( method );
291
292   // Combine Actor name with method string
293   std::string nameAndMethod( Self().GetProperty< std::string >( Dali::Actor::Property::NAME ) );
294   if ( 0 == nameAndMethod.size() )
295   {
296     nameAndMethod = "Unknown: ";
297   }
298   else
299   {
300     nameAndMethod += ": ";
301   }
302   nameAndMethod += method;
303
304   MasterCallStack.push_back( nameAndMethod );
305 }
306
307 // From CustomActorImpl
308 void TestCustomActor::OnStageConnection( int depth )
309 {
310   AddToCallStacks("OnStageConnection");
311   mDepth = depth;
312 }
313 void TestCustomActor::OnStageDisconnection()
314 {
315   AddToCallStacks("OnStageDisconnection");
316 }
317 void TestCustomActor::OnChildAdd(Actor& child)
318 {
319   AddToCallStacks("OnChildAdd");
320 }
321 void TestCustomActor::OnChildRemove(Actor& child)
322 {
323   AddToCallStacks("OnChildRemove");
324 }
325 void TestCustomActor::OnPropertySet( Property::Index index, Property::Value propertyValue )
326 {
327   AddToCallStacks("OnPropertySet");
328 }
329 void TestCustomActor::OnSizeSet(const Vector3& targetSize)
330 {
331   mSizeSet = targetSize;
332   AddToCallStacks("OnSizeSet");
333 }
334 void TestCustomActor::OnSizeAnimation(Animation& animation, const Vector3& targetSize)
335 {
336   mTargetSize = targetSize;
337   AddToCallStacks("OnSizeAnimation");
338 }
339 bool TestCustomActor::OnTouchEvent(const TouchEvent& event)
340 {
341   AddToCallStacks("OnTouchEvent");
342   return true;
343 }
344 bool TestCustomActor::OnHoverEvent(const HoverEvent& event)
345 {
346   AddToCallStacks("OnHoverEvent");
347   return true;
348 }
349 bool TestCustomActor::OnWheelEvent(const WheelEvent& event)
350 {
351   AddToCallStacks("OnWheelEvent");
352   return true;
353 }
354 bool TestCustomActor::OnKeyEvent(const KeyEvent& event)
355 {
356   AddToCallStacks("OnKeyEvent");
357   return true;
358 }
359 void TestCustomActor::OnKeyInputFocusGained()
360 {
361   AddToCallStacks("OnKeyInputFocusGained");
362 }
363 void TestCustomActor::OnKeyInputFocusLost()
364 {
365   AddToCallStacks("OnKeyInputFocusLost");
366 }
367 Vector3 TestCustomActor::GetNaturalSize()
368 {
369   return Vector3( 0.0f, 0.0f, 0.0f );
370 }
371
372 float TestCustomActor::GetHeightForWidth( float width )
373 {
374   return 0.0f;
375 }
376
377 float TestCustomActor::GetWidthForHeight( float height )
378 {
379   return 0.0f;
380 }
381
382 void TestCustomActor::OnRelayout( const Vector2& size, RelayoutContainer& container )
383 {
384   gOnRelayout = true;
385 }
386
387 void TestCustomActor::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
388 {
389 }
390
391 void TestCustomActor::OnCalculateRelayoutSize( Dimension::Type dimension )
392 {
393 }
394
395 float TestCustomActor::CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension )
396 {
397   return 0.0f;
398 }
399
400 void TestCustomActor::OnLayoutNegotiated( float size, Dimension::Type dimension )
401 {
402 }
403
404 bool TestCustomActor::RelayoutDependentOnChildren( Dimension::Type dimension )
405 {
406   return false;
407 }
408
409 void TestCustomActor::SetDaliProperty(std::string s)
410 {
411   Self().SetProperty(mDaliProperty, s);
412 }
413 void TestCustomActor::TestRelayoutRequest()
414 {
415   RelayoutRequest();
416 }
417
418 float TestCustomActor::TestGetHeightForWidthBase( float width )
419 {
420   return GetHeightForWidthBase( width );
421 }
422
423 float TestCustomActor::TestGetWidthForHeightBase( float height )
424 {
425   return GetWidthForHeightBase( height );
426 }
427
428 float TestCustomActor::TestCalculateChildSizeBase( const Dali::Actor& child, Dimension::Type dimension )
429 {
430   return CalculateChildSizeBase( child, dimension );
431 }
432
433 bool TestCustomActor::TestRelayoutDependentOnChildrenBase( Dimension::Type dimension )
434 {
435   return RelayoutDependentOnChildrenBase( dimension );
436 }
437
438 void TestCustomActor::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
439 {
440   Test::TestCustomActor actor = Test::TestCustomActor::DownCast( Dali::BaseHandle( object ) );
441
442   if ( actor )
443   {
444     TestCustomActor& actorImpl = GetImpl(actor);
445     switch(index)
446     {
447       case Test::TestCustomActor::Property::TEST_PROPERTY1:
448       {
449         actorImpl.prop1 = value.Get<float>();
450         break;
451       }
452       case Test::TestCustomActor::Property::TEST_PROPERTY2:
453       {
454         actorImpl.prop2 = value.Get<Vector4>();
455         break;
456       }
457       case Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY3:
458       {
459         actorImpl.develProp3 = value.Get<Vector4>();
460         break;
461       }
462       case Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY4:
463       {
464         actorImpl.develProp4 = value.Get<int>();
465         break;
466       }
467       case Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY5:
468       {
469         actorImpl.develProp5 = value.Get<float>();
470         break;
471       }
472     }
473   }
474 }
475
476 Property::Value TestCustomActor::GetProperty( BaseObject* object, Property::Index index )
477 {
478   Test::TestCustomActor actor = Test::TestCustomActor::DownCast( Dali::BaseHandle( object ) );
479
480   if ( actor )
481   {
482     TestCustomActor& actorImpl = GetImpl(actor);
483     switch(index)
484     {
485       case Test::TestCustomActor::Property::TEST_PROPERTY1:
486       {
487         return Property::Value(actorImpl.prop1);
488       }
489       case Test::TestCustomActor::Property::TEST_PROPERTY2:
490       {
491         return Property::Value(actorImpl.prop2);
492       }
493       case Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY3:
494       {
495         return Property::Value(actorImpl.develProp3);
496       }
497       case Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY4:
498       {
499         return Property::Value(actorImpl.develProp4);
500       }
501       case Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY5:
502       {
503         return Property::Value(actorImpl.develProp5);
504       }
505       case Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY6:
506       {
507         return Property::Value(actorImpl.develProp6);
508       }
509     }
510   }
511   return Property::Value();
512 }
513
514
515 BaseHandle CreateActor()
516 {
517   return Test::TestCustomActor::New();
518 }
519
520 DALI_TYPE_REGISTRATION_BEGIN( Test::TestCustomActor, Dali::CustomActor, CreateActor );
521
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)
528
529 DALI_TYPE_REGISTRATION_END()
530
531 } // Impl
532 } // Test namespace