Adding Devel Property Registration macro
[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.SetName( "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()
78 {
79   Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant5();
80   TestCustomActor custom( *impl ); // takes ownership
81
82   impl->Initialize();
83
84   return custom;
85 }
86
87 TestCustomActor TestCustomActor::NewVariant6()
88 {
89   Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant6();
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 unsigned int 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 {
250 }
251
252 TestCustomActor::TestCustomActor(bool nego)
253 : CustomActorImpl( ActorFlags( REQUIRES_TOUCH_EVENTS | REQUIRES_WHEEL_EVENTS | REQUIRES_HOVER_EVENTS ) ),
254   mDaliProperty( Property::INVALID_INDEX ),
255   mSizeSet( Vector3::ZERO ),
256   mTargetSize( Vector3::ZERO ),
257   mNego( nego )
258 {
259 }
260 /**
261  * Destructor
262  */
263 TestCustomActor::~TestCustomActor()
264 {
265 }
266
267 void TestCustomActor::Initialize( const char* name )
268 {
269   mDaliProperty = Self().RegisterProperty( "Dali", std::string("no"), Property::READ_WRITE);
270
271   OnInitialize( name );
272 }
273
274 void TestCustomActor::OnInitialize( const char* name ) {}
275
276 /**
277  * Resets the call stack
278  */
279 void TestCustomActor::ResetCallStack()
280 {
281   mSizeSet = Vector3();
282   mTargetSize = Vector3();
283   mMethodsCalled.clear();
284 }
285
286 void TestCustomActor::AddToCallStacks( const char* method )
287 {
288   mMethodsCalled.push_back( method );
289
290   // Combine Actor name with method string
291   std::string nameAndMethod( Self().GetName() );
292   if ( 0 == nameAndMethod.size() )
293   {
294     nameAndMethod = "Unknown: ";
295   }
296   else
297   {
298     nameAndMethod += ": ";
299   }
300   nameAndMethod += method;
301
302   MasterCallStack.push_back( nameAndMethod );
303 }
304
305 // From CustomActorImpl
306 void TestCustomActor::OnStageConnection( int depth )
307 {
308   AddToCallStacks("OnStageConnection");
309   mDepth = depth;
310 }
311 void TestCustomActor::OnStageDisconnection()
312 {
313   AddToCallStacks("OnStageDisconnection");
314 }
315 void TestCustomActor::OnChildAdd(Actor& child)
316 {
317   AddToCallStacks("OnChildAdd");
318 }
319 void TestCustomActor::OnChildRemove(Actor& child)
320 {
321   AddToCallStacks("OnChildRemove");
322 }
323 void TestCustomActor::OnPropertySet( Property::Index index, Property::Value propertyValue )
324 {
325   AddToCallStacks("OnPropertySet");
326 }
327 void TestCustomActor::OnSizeSet(const Vector3& targetSize)
328 {
329   mSizeSet = targetSize;
330   AddToCallStacks("OnSizeSet");
331 }
332 void TestCustomActor::OnSizeAnimation(Animation& animation, const Vector3& targetSize)
333 {
334   mTargetSize = targetSize;
335   AddToCallStacks("OnSizeAnimation");
336 }
337 bool TestCustomActor::OnTouchEvent(const TouchEvent& event)
338 {
339   AddToCallStacks("OnTouchEvent");
340   return true;
341 }
342 bool TestCustomActor::OnHoverEvent(const HoverEvent& event)
343 {
344   AddToCallStacks("OnHoverEvent");
345   return true;
346 }
347 bool TestCustomActor::OnWheelEvent(const WheelEvent& event)
348 {
349   AddToCallStacks("OnWheelEvent");
350   return true;
351 }
352 bool TestCustomActor::OnKeyEvent(const KeyEvent& event)
353 {
354   AddToCallStacks("OnKeyEvent");
355   return true;
356 }
357 void TestCustomActor::OnKeyInputFocusGained()
358 {
359   AddToCallStacks("OnKeyInputFocusGained");
360 }
361 void TestCustomActor::OnKeyInputFocusLost()
362 {
363   AddToCallStacks("OnKeyInputFocusLost");
364 }
365 Vector3 TestCustomActor::GetNaturalSize()
366 {
367   return Vector3( 0.0f, 0.0f, 0.0f );
368 }
369
370 float TestCustomActor::GetHeightForWidth( float width )
371 {
372   return 0.0f;
373 }
374
375 float TestCustomActor::GetWidthForHeight( float height )
376 {
377   return 0.0f;
378 }
379
380 void TestCustomActor::OnRelayout( const Vector2& size, RelayoutContainer& container )
381 {
382   gOnRelayout = true;
383 }
384
385 void TestCustomActor::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
386 {
387 }
388
389 void TestCustomActor::OnCalculateRelayoutSize( Dimension::Type dimension )
390 {
391 }
392
393 float TestCustomActor::CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension )
394 {
395   return 0.0f;
396 }
397
398 void TestCustomActor::OnLayoutNegotiated( float size, Dimension::Type dimension )
399 {
400 }
401
402 bool TestCustomActor::RelayoutDependentOnChildren( Dimension::Type dimension )
403 {
404   return false;
405 }
406
407 void TestCustomActor::SetDaliProperty(std::string s)
408 {
409   Self().SetProperty(mDaliProperty, s);
410 }
411 void TestCustomActor::TestRelayoutRequest()
412 {
413   RelayoutRequest();
414 }
415
416 float TestCustomActor::TestGetHeightForWidthBase( float width )
417 {
418   return GetHeightForWidthBase( width );
419 }
420
421 float TestCustomActor::TestGetWidthForHeightBase( float height )
422 {
423   return GetWidthForHeightBase( height );
424 }
425
426 float TestCustomActor::TestCalculateChildSizeBase( const Dali::Actor& child, Dimension::Type dimension )
427 {
428   return CalculateChildSizeBase( child, dimension );
429 }
430
431 bool TestCustomActor::TestRelayoutDependentOnChildrenBase( Dimension::Type dimension )
432 {
433   return RelayoutDependentOnChildrenBase( dimension );
434 }
435
436 void TestCustomActor::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
437 {
438   Test::TestCustomActor actor = Test::TestCustomActor::DownCast( Dali::BaseHandle( object ) );
439
440   if ( actor )
441   {
442     TestCustomActor& actorImpl = GetImpl(actor);
443     switch(index)
444     {
445       case Test::TestCustomActor::Property::TEST_PROPERTY1:
446       {
447         actorImpl.prop1 = value.Get<float>();
448         break;
449       }
450       case Test::TestCustomActor::Property::TEST_PROPERTY2:
451       {
452         actorImpl.prop2 = value.Get<Vector4>();
453         break;
454       }
455       case Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY3:
456       {
457         actorImpl.develProp3 = value.Get<Vector4>();
458         break;
459       }
460       case Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY4:
461       {
462         actorImpl.develProp4 = value.Get<int>();
463         break;
464       }
465       case Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY5:
466       {
467         actorImpl.develProp5 = value.Get<float>();
468         break;
469       }
470     }
471   }
472 }
473
474 Property::Value TestCustomActor::GetProperty( BaseObject* object, Property::Index index )
475 {
476   Test::TestCustomActor actor = Test::TestCustomActor::DownCast( Dali::BaseHandle( object ) );
477
478   if ( actor )
479   {
480     TestCustomActor& actorImpl = GetImpl(actor);
481     switch(index)
482     {
483       case Test::TestCustomActor::Property::TEST_PROPERTY1:
484       {
485         return Property::Value(actorImpl.prop1);
486       }
487       case Test::TestCustomActor::Property::TEST_PROPERTY2:
488       {
489         return Property::Value(actorImpl.prop2);
490       }
491       case Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY3:
492       {
493         return Property::Value(actorImpl.develProp3);
494       }
495       case Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY4:
496       {
497         return Property::Value(actorImpl.develProp4);
498       }
499       case Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY5:
500       {
501         return Property::Value(actorImpl.develProp5);
502       }
503     }
504   }
505   return Property::Value();
506 }
507
508
509 BaseHandle CreateActor()
510 {
511   return Test::TestCustomActor::New();
512 }
513
514 DALI_TYPE_REGISTRATION_BEGIN( Test::TestCustomActor, Dali::CustomActor, CreateActor );
515
516 DALI_PROPERTY_REGISTRATION( Test, TestCustomActor, "testProperty1", FLOAT, TEST_PROPERTY1)
517 DALI_PROPERTY_REGISTRATION( Test, TestCustomActor, "testProperty2", VECTOR4, TEST_PROPERTY2)
518 DALI_DEVEL_PROPERTY_REGISTRATION( Test, TestCustomActor, "develTestProperty3", VECTOR4, DEVEL_TEST_PROPERTY3)
519 DALI_DEVEL_PROPERTY_REGISTRATION( Test, TestCustomActor, "develTestProperty4", INTEGER, DEVEL_TEST_PROPERTY4)
520 DALI_DEVEL_PROPERTY_REGISTRATION( Test, TestCustomActor, "develTestProperty5", FLOAT, DEVEL_TEST_PROPERTY5)
521
522 DALI_TYPE_REGISTRATION_END()
523
524 } // Impl
525 } // Test namespace