Remove some public Setter/Getter APIs from Dali::Actor
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / dali-test-suite-utils / test-custom-actor.h
1 #ifndef TEST_CUSTOM_ACTOR_H
2 #define TEST_CUSTOM_ACTOR_H
3
4 #include <dali/public-api/dali-core.h>
5 #include <dali/devel-api/object/property-helper-devel.h>
6
7 extern std::vector< std::string > MasterCallStack;
8 extern bool gOnRelayout;
9
10 namespace Test
11 {
12 namespace Impl
13 {
14 struct TestCustomActor;
15 }
16
17 /**
18  * Test custom actor handle
19  */
20 class TestCustomActor : public Dali::CustomActor
21 {
22 public:
23   enum PropertyRange
24   {
25     PROPERTY_START_INDEX = Dali::PROPERTY_REGISTRATION_START_INDEX,
26     PROPERTY_END_INDEX =   PROPERTY_START_INDEX + 1000
27   };
28
29   struct Property
30   {
31     enum Type
32     {
33       TEST_PROPERTY1 = PROPERTY_START_INDEX,
34       TEST_PROPERTY2
35     };
36   };
37
38   TestCustomActor();
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 );
50
51   virtual ~TestCustomActor();
52   Impl::TestCustomActor& GetImpl();
53
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 );
70   uint32_t GetDepth();
71
72 private:
73   TestCustomActor( Impl::TestCustomActor& impl );
74   explicit TestCustomActor(Dali::Internal::CustomActor* internal);
75 };
76
77
78 namespace DevelTestCustomActor
79 {
80 namespace Property
81 {
82 enum Type
83 {
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
90 };
91
92 } // Namespace Property
93 } // Namespace DevelTestCustomActor
94
95
96 // TypeRegistry needs custom actor Implementations to have the same name (namespaces are ignored so we use one here)
97 namespace Impl
98 {
99
100 struct TestCustomActor : public Dali::CustomActorImpl
101 {
102 public:
103   /**
104    * Constructor
105    */
106   TestCustomActor();
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 );
137
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 );
144
145 public:
146   Dali::Property::Index mDaliProperty;
147   std::vector< std::string > mMethodsCalled;
148   Dali::Vector3         mSizeSet;
149   Dali::Vector3         mTargetSize;
150   bool                  mNego;
151   uint32_t          mDepth;
152
153   float         prop1;
154   Dali::Vector4 prop2;
155   Dali::Vector4 develProp3;
156   int           develProp4;
157   float         develProp5;
158   float         develProp6;
159 };
160
161 inline TestCustomActor& GetImpl( Test::TestCustomActor& handle )
162 {
163   DALI_ASSERT_ALWAYS( handle );
164   Dali::RefObject& object = handle.GetImplementation();
165   return static_cast<TestCustomActor&>( object );
166 }
167
168 inline const TestCustomActor& GetImpl( const Test::TestCustomActor& handle )
169 {
170   DALI_ASSERT_ALWAYS( handle );
171   const Dali::RefObject& object = handle.GetImplementation();
172   return static_cast<const TestCustomActor&>( object );
173 }
174
175
176 /**
177  * Variant which adds a new child during OnStageConnection
178  */
179 struct TestCustomActorVariant1 : public TestCustomActor
180 {
181   /**
182    * Constructor
183    */
184   TestCustomActorVariant1( Dali::Actor childToAdd )
185   : mChildToAdd( childToAdd )
186   {
187   }
188
189   // From CustomActorImpl
190   virtual void OnStageConnection( int depth )
191   {
192     // Chain up first
193     TestCustomActor::OnStageConnection( depth );
194
195     // Add the child
196     Self().Add( mChildToAdd );
197   }
198
199   Dali::Actor mChildToAdd;
200 };
201
202 /**
203  * Variant which removes children during OnStageConnection
204  */
205 struct TestCustomActorVariant2 : public TestCustomActor
206 {
207   /**
208    * Constructor
209    */
210   TestCustomActorVariant2()
211   {
212   }
213
214   // From CustomActorImpl
215   virtual void OnStageConnection( int depth )
216   {
217     // Chain up first
218     TestCustomActor::OnStageConnection( depth );
219
220     // Remove all the children
221     for( uint32_t i=0, num=Self().GetChildCount(); i<num; ++i )
222     {
223       Self().Remove( Self().GetChildAt(0) );
224     }
225   }
226 };
227
228 /**
229  * Variant which adds a new child during OnStageDisconnection
230  */
231 struct TestCustomActorVariant3 : public TestCustomActor
232 {
233   /**
234    * Constructor
235    */
236   TestCustomActorVariant3( Dali::Actor childToAdd )
237   : mChildToAdd( childToAdd )
238   {
239   }
240
241   // From CustomActorImpl
242   virtual void OnStageDisconnection()
243   {
244     // Chain up first
245     TestCustomActor::OnStageDisconnection();
246
247     // Add the child
248     Self().Add( mChildToAdd );
249   }
250
251   Dali::Actor mChildToAdd;
252 };
253
254 /**
255  * Variant which removes children during OnStageDisconnection
256  */
257 struct TestCustomActorVariant4 : public TestCustomActor
258 {
259   /**
260    * Constructor
261    */
262   TestCustomActorVariant4()
263   {
264   }
265
266   // From CustomActorImpl
267   virtual void OnStageDisconnection()
268   {
269     // Chain up first
270     TestCustomActor::OnStageDisconnection();
271
272     // Remove all the children
273     for( uint32_t i=0, num=Self().GetChildCount(); i<num; ++i )
274     {
275       Self().Remove( Self().GetChildAt(0) );
276     }
277   }
278 };
279
280 /**
281  * Variant which removes its parent from Stage during OnStageConnection
282  */
283 struct TestCustomActorVariant5 : public TestCustomActor
284 {
285   /**
286    * Constructor
287    */
288   TestCustomActorVariant5()
289   {
290   }
291
292   // From CustomActorImpl
293   virtual void OnStageConnection( int depth )
294   {
295     // Chain up first
296     TestCustomActor::OnStageConnection( depth );
297
298     // Take parent off-stage
299     Dali::Actor parent = Self().GetParent();
300     if ( parent )
301     {
302       Dali::Stage::GetCurrent().Remove( parent );
303     }
304   }
305 };
306
307 /**
308  * Variant which adds its parent to Stage during OnStageDisconnection
309  */
310 struct TestCustomActorVariant6 : public TestCustomActor
311 {
312   /**
313    * Constructor
314    */
315   TestCustomActorVariant6()
316   {
317   }
318
319   // From CustomActorImpl
320   virtual void OnStageDisconnection()
321   {
322     // Chain up first
323     TestCustomActor::OnStageDisconnection();
324
325     // Put parent on-stage
326     Dali::Actor parent = Self().GetParent();
327     if ( parent )
328     {
329       Dali::Stage::GetCurrent().Add( parent );
330     }
331   }
332 };
333
334 /**
335  * Variant which reparents its children into a separate container
336  */
337 struct TestCustomActorVariant7 : public TestCustomActor
338 {
339   /**
340    * Constructor
341    */
342   TestCustomActorVariant7()
343   {
344   }
345
346   virtual void OnInitialize( const char* name )
347   {
348     // We need to do this early, before the OnChildAdd is recorded
349     Self().SetProperty( Dali::Actor::Property::NAME, name );
350
351     mContainer = Dali::Actor::New();
352     mContainer.SetProperty( Dali::Actor::Property::NAME, "Container" );
353     Self().Add( mContainer );
354   }
355
356   // From CustomActorImpl
357   virtual void OnChildAdd(Dali::Actor& child)
358   {
359     // Chain up first
360     TestCustomActor::OnChildAdd(child);
361
362     // Reparent child
363     if ( child != mContainer )
364     {
365       mContainer.Add( child );
366     }
367   }
368
369   Dali::Actor mContainer;
370 };
371
372 /**
373  * Variant which attempts to interfere with the reparenting of a child to another container
374  */
375 struct TestCustomActorVariant8 : public TestCustomActor
376 {
377   /**
378    * Constructor
379    */
380   TestCustomActorVariant8( Dali::Actor rival )
381   : mRivalContainer( rival )
382   {
383   }
384
385   // From CustomActorImpl
386   virtual void OnChildRemove(Dali::Actor& child)
387   {
388     // Chain up first
389     TestCustomActor::OnChildRemove(child);
390
391     mRivalContainer.Remove( child ); // attempt to block reparenting to rival (should be a NOOP)
392   }
393
394   Dali::Actor mRivalContainer;
395 };
396
397 // Need a class that doesn't override virtual methods
398 class SimpleTestCustomActor : public Dali::CustomActorImpl
399 {
400 public:
401
402   /**
403    * Constructor
404    */
405   SimpleTestCustomActor()
406   : CustomActorImpl( ActorFlags( REQUIRES_TOUCH_EVENTS | DISABLE_SIZE_NEGOTIATION ) )
407   {
408   }
409
410   /**
411    * Destructor
412    */
413   virtual ~SimpleTestCustomActor()
414   {
415   }
416
417   // From CustomActorImpl
418   virtual void OnStageConnection( int depth )
419   {
420   }
421   virtual void OnStageDisconnection()
422   {
423   }
424   virtual void OnChildAdd(Dali::Actor& child)
425   {
426   }
427   virtual void OnChildRemove(Dali::Actor& child)
428   {
429   }
430   virtual void OnSizeSet(const Dali::Vector3& targetSize)
431   {
432   }
433   virtual void OnSizeAnimation(Dali::Animation& animation, const Dali::Vector3& targetSize)
434   {
435   }
436   virtual bool OnTouchEvent(const Dali::TouchEvent& event)
437   {
438     return true;
439   }
440   virtual bool OnHoverEvent(const Dali::HoverEvent& event)
441   {
442     return true;
443   }
444   virtual bool OnWheelEvent(const Dali::WheelEvent& event)
445   {
446     return true;
447   }
448   virtual bool OnKeyEvent(const Dali::KeyEvent& event)
449   {
450     return true;
451   }
452   virtual void OnKeyInputFocusGained()
453   {
454   }
455   virtual void OnKeyInputFocusLost()
456   {
457   }
458
459   virtual Dali::Vector3 GetNaturalSize()
460   {
461     return Dali::Vector3( 0.0f, 0.0f, 0.0f );
462   }
463
464   virtual float GetHeightForWidth( float width )
465   {
466     return 0.0f;
467   }
468
469   virtual float GetWidthForHeight( float height )
470   {
471     return 0.0f;
472   }
473
474   virtual void OnRelayout( const Dali::Vector2& size, Dali::RelayoutContainer& container )
475   {
476   }
477
478   virtual void OnSetResizePolicy( Dali::ResizePolicy::Type policy, Dali::Dimension::Type dimension )
479   {
480   }
481
482   virtual void OnCalculateRelayoutSize( Dali::Dimension::Type dimension )
483   {
484   }
485
486   virtual float CalculateChildSize( const Dali::Actor& child, Dali::Dimension::Type dimension )
487   {
488     return 0.0f;
489   }
490
491   virtual void OnLayoutNegotiated( float size, Dali::Dimension::Type dimension )
492   {
493   }
494
495   virtual bool RelayoutDependentOnChildren( Dali::Dimension::Type dimension = Dali::Dimension::ALL_DIMENSIONS )
496   {
497     return false;
498   }
499 };
500
501 } //namespace Impl
502 } //namespace Test
503
504 #endif // TEST_CUSTOM_ACTOR_H