Merge "DALi Version 1.0.31" into tizen
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / public-api / controls / control-impl.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali-toolkit/public-api/controls/control-impl.h>
20
21 // EXTERNAL INCLUDES
22 #include <stack>
23 #include <dali/public-api/actors/image-actor.h>
24 #include <dali/public-api/actors/mesh-actor.h>
25 #include <dali/public-api/animation/active-constraint.h>
26 #include <dali/public-api/animation/constraint.h>
27 #include <dali/public-api/animation/constraints.h>
28 #include <dali/public-api/geometry/mesh.h>
29 #include <dali/public-api/object/type-registry.h>
30 #include <dali/public-api/scripting/scripting.h>
31 #include <dali/integration-api/debug.h>
32
33 // INTERNAL INCLUDES
34 #include <dali-toolkit/internal/controls/relayout-controller.h>
35 #include <dali-toolkit/internal/controls/relayout-helper.h>
36 #include <dali-toolkit/public-api/focus-manager/keyinput-focus-manager.h>
37 #include <dali-toolkit/public-api/focus-manager/keyboard-focus-manager.h>
38 #include <dali-toolkit/public-api/controls/control.h>
39 #include <dali-toolkit/public-api/styling/style-manager.h>
40 #include <dali-toolkit/internal/styling/style-manager-impl.h>
41
42 namespace Dali
43 {
44
45 namespace Toolkit
46 {
47
48 const Property::Index Control::PROPERTY_BACKGROUND_COLOR      = Internal::Control::CONTROL_PROPERTY_START_INDEX;
49 const Property::Index Control::PROPERTY_BACKGROUND            = Internal::Control::CONTROL_PROPERTY_START_INDEX + 1;
50 const Property::Index Control::PROPERTY_WIDTH_POLICY          = Internal::Control::CONTROL_PROPERTY_START_INDEX + 2;
51 const Property::Index Control::PROPERTY_HEIGHT_POLICY         = Internal::Control::CONTROL_PROPERTY_START_INDEX + 3;
52 const Property::Index Control::PROPERTY_MINIMUM_SIZE          = Internal::Control::CONTROL_PROPERTY_START_INDEX + 4;
53 const Property::Index Control::PROPERTY_MAXIMUM_SIZE          = Internal::Control::CONTROL_PROPERTY_START_INDEX + 5;
54 const Property::Index Control::PROPERTY_KEY_INPUT_FOCUS       = Internal::Control::CONTROL_PROPERTY_START_INDEX + 6;
55
56 namespace
57 {
58
59 // Signals
60
61 const char* const SIGNAL_KEY_EVENT =    "key-event";
62 const char* const SIGNAL_TAPPED =       "tapped";
63 const char* const SIGNAL_PANNED =       "panned";
64 const char* const SIGNAL_PINCHED =      "pinched";
65 const char* const SIGNAL_LONG_PRESSED = "long-pressed";
66
67 // Actions
68
69 const char* const ACTION_CONTROL_ACTIVATED = "control-activated";
70
71 const Scripting::StringEnum< Control::SizePolicy > SIZE_POLICY_STRING_TABLE[] =
72 {
73   { "FIXED",      Control::Fixed      },
74   { "MINIMUM",    Control::Minimum    },
75   { "MAXIMUM",    Control::Maximum    },
76   { "RANGE",      Control::Range      },
77   { "FLEXIBLE",   Control::Flexible   },
78 };
79 const unsigned int SIZE_POLICY_STRING_TABLE_COUNT = sizeof( SIZE_POLICY_STRING_TABLE ) / sizeof( SIZE_POLICY_STRING_TABLE[0] );
80
81 #if defined(DEBUG_ENABLED)
82 Integration::Log::Filter* gLogFilter  = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_CONTROL");
83 #endif
84
85 const float MAX_FLOAT_VALUE( std::numeric_limits<float>::max() );
86 const Vector3 MAX_SIZE( MAX_FLOAT_VALUE, MAX_FLOAT_VALUE, MAX_FLOAT_VALUE );
87 const float BACKGROUND_ACTOR_Z_POSITION( -0.1f );
88
89 BaseHandle Create()
90 {
91   return Internal::Control::New();
92 }
93
94 TypeRegistration CONTROL_TYPE( typeid(Control), typeid(CustomActor), Create );
95
96 // Property Registration after Internal::Control::Impl definition below
97
98 TypeAction ACTION_TYPE_1( CONTROL_TYPE, ACTION_CONTROL_ACTIVATED, &Internal::Control::DoAction );
99
100 SignalConnectorType SIGNAL_CONNECTOR_1( CONTROL_TYPE, SIGNAL_KEY_EVENT,     &Internal::Control::DoConnectSignal );
101 SignalConnectorType SIGNAL_CONNECTOR_2( CONTROL_TYPE, SIGNAL_TAPPED,        &Internal::Control::DoConnectSignal );
102 SignalConnectorType SIGNAL_CONNECTOR_3( CONTROL_TYPE, SIGNAL_PANNED,        &Internal::Control::DoConnectSignal );
103 SignalConnectorType SIGNAL_CONNECTOR_4( CONTROL_TYPE, SIGNAL_PINCHED,       &Internal::Control::DoConnectSignal );
104 SignalConnectorType SIGNAL_CONNECTOR_5( CONTROL_TYPE, SIGNAL_LONG_PRESSED,  &Internal::Control::DoConnectSignal );
105
106 /**
107  * Structure which holds information about the background of a control
108  */
109 struct Background
110 {
111   Actor actor;   ///< Either a MeshActor or an ImageActor
112   Vector4 color; ///< The color of the actor.
113
114   /**
115    * Constructor
116    */
117   Background()
118   : actor(),
119     color( Color::WHITE )
120   {
121   }
122 };
123
124 /**
125  * Helper function to calculate a dimension given the policy of that dimension; the minimum &
126  * maximum values that dimension can be; and the allocated value for that dimension.
127  *
128  * @param[in]  policy     The size policy for that dimension.
129  * @param[in]  minimum    The minimum value that dimension can be.
130  * @param[in]  maximum    The maximum value that dimension can be.
131  * @param[in]  allocated  The value allocated for that dimension.
132  *
133  * @return The value that the dimension should be.
134  *
135  * @note This does not handle Control::Fixed policy.
136  */
137 float Calculate( Control::SizePolicy policy, float minimum, float maximum, float allocated )
138 {
139   float size( allocated );
140
141   switch( policy )
142   {
143     case Control::Fixed:
144     {
145       // Use allocated value
146       break;
147     }
148
149     case Control::Minimum:
150     {
151       // Size is always at least the minimum.
152       size = std::max( allocated, minimum );
153       break;
154     }
155
156     case Control::Maximum:
157     {
158       // Size can grow but up to a maximum value.
159       size = std::min( allocated, maximum );
160       break;
161     }
162
163     case Control::Range:
164     {
165       // Size is at least the minimum and can grow up to the maximum
166       size = std::max( size, minimum );
167       size = std::min( size, maximum );
168      break;
169     }
170
171     case Control::Flexible:
172     {
173       // Size grows or shrinks with no limits.
174       size = allocated;
175       break;
176     }
177
178     default:
179     {
180       DALI_ASSERT_DEBUG( false && "This function was not intended to be used by any other policy." );
181       break;
182     }
183   }
184
185   return size;
186 }
187
188 /**
189  * Creates a white coloured Mesh.
190  */
191 Mesh CreateMesh()
192 {
193   Vector3 white( Color::WHITE );
194
195   MeshData meshData;
196
197   // Create vertices with a white color (actual color is set by actor color)
198   MeshData::VertexContainer vertices(4);
199   vertices[ 0 ] = MeshData::Vertex( Vector3( -0.5f, -0.5f, 0.0f ), Vector2::ZERO, white );
200   vertices[ 1 ] = MeshData::Vertex( Vector3(  0.5f, -0.5f, 0.0f ), Vector2::ZERO, white );
201   vertices[ 2 ] = MeshData::Vertex( Vector3( -0.5f,  0.5f, 0.0f ), Vector2::ZERO, white );
202   vertices[ 3 ] = MeshData::Vertex( Vector3(  0.5f,  0.5f, 0.0f ), Vector2::ZERO, white );
203
204   // Specify all the faces
205   MeshData::FaceIndices faces;
206   faces.reserve( 6 ); // 2 triangles in Quad
207   faces.push_back( 0 ); faces.push_back( 3 ); faces.push_back( 1 );
208   faces.push_back( 0 ); faces.push_back( 2 ); faces.push_back( 3 );
209
210   // Create the mesh data from the vertices and faces
211   meshData.SetMaterial( Material::New( "ControlMaterial" ) );
212   meshData.SetVertices( vertices );
213   meshData.SetFaceIndices( faces );
214   meshData.SetHasColor( true );
215
216   return Mesh::New( meshData );
217 }
218
219 /**
220  * Sets all the required properties for the background actor.
221  *
222  * @param[in]  actor              The actor to set the properties on.
223  * @param[in]  constrainingIndex  The property index to constrain the parent's size on.
224  * @param[in]  color              The required color of the actor.
225  */
226 void SetupBackgroundActor( Actor actor, Property::Index constrainingIndex, const Vector4& color )
227 {
228   actor.SetColor( color );
229   actor.SetPositionInheritanceMode( USE_PARENT_POSITION_PLUS_LOCAL_POSITION );
230   actor.SetColorMode( USE_OWN_MULTIPLY_PARENT_COLOR );
231   actor.SetZ( BACKGROUND_ACTOR_Z_POSITION );
232
233   Constraint constraint = Constraint::New<Vector3>( constrainingIndex,
234                                                     ParentSource( Actor::SIZE ),
235                                                     EqualToConstraint() );
236   actor.ApplyConstraint( constraint );
237 }
238
239 } // unnamed namespace
240
241 namespace Internal
242 {
243
244 class Control::Impl : public ConnectionTracker
245 {
246 public:
247
248   /**
249    * Size indices for mMinMaxSize array
250    */
251   enum
252   {
253     MIN_SIZE_INDEX = 0,
254     MAX_SIZE_INDEX = 1
255   };
256
257 public:
258   // Construction & Destruction
259   Impl(Control& controlImpl)
260   : mControlImpl( controlImpl ),
261     mBackground( NULL ),
262     mStartingPinchScale( NULL ),
263     mKeyEventSignal(),
264     mPinchGestureDetector(),
265     mPanGestureDetector(),
266     mTapGestureDetector(),
267     mLongPressGestureDetector(),
268     mCurrentSize(),
269     mNaturalSize(),
270     mWidthPolicy( Toolkit::Control::Fixed ),
271     mHeightPolicy( Toolkit::Control::Fixed ),
272     mFlags( Control::CONTROL_BEHAVIOUR_NONE ),
273     mInsideRelayout( false ),
274     mIsKeyboardNavigationSupported( false ),
275     mIsKeyboardFocusGroup( false ),
276     mInitialized( false )
277   {
278   }
279
280   ~Impl()
281   {
282     // All gesture detectors will be destroyed so no need to disconnect.
283     delete mBackground;
284     delete mStartingPinchScale;
285   }
286
287   // Gesture Detection Methods
288
289   void PinchDetected(Actor actor, const PinchGesture& pinch)
290   {
291     mControlImpl.OnPinch(pinch);
292   }
293
294   void PanDetected(Actor actor, const PanGesture& pan)
295   {
296     mControlImpl.OnPan(pan);
297   }
298
299   void TapDetected(Actor actor, const TapGesture& tap)
300   {
301     mControlImpl.OnTap(tap);
302   }
303
304   void LongPressDetected(Actor actor, const LongPressGesture& longPress)
305   {
306     mControlImpl.OnLongPress(longPress);
307   }
308
309   // Background Methods
310
311   /**
312    * Only creates an instance of the background if we actually use it.
313    * @return A reference to the Background structure.
314    */
315   Background& GetBackground()
316   {
317     if ( !mBackground )
318     {
319       mBackground = new Background;
320     }
321     return *mBackground;
322   }
323
324   // Properties
325
326   /**
327    * Called when a property of an object of this type is set.
328    * @param[in] object The object whose property is set.
329    * @param[in] index The property index.
330    * @param[in] value The new property value.
331    */
332   static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
333   {
334     Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
335
336     if ( control )
337     {
338       Control& controlImpl( control.GetImplementation() );
339
340       switch ( index )
341       {
342         case Toolkit::Control::PROPERTY_BACKGROUND_COLOR:
343         {
344           controlImpl.SetBackgroundColor( value.Get< Vector4 >() );
345           break;
346         }
347
348         case Toolkit::Control::PROPERTY_BACKGROUND:
349         {
350           if ( value.HasKey( "image" ) )
351           {
352             Property::Map imageMap = value.GetValue( "image" ).Get< Property::Map >();
353             Image image = Scripting::NewImage( imageMap );
354
355             if ( image )
356             {
357               controlImpl.SetBackground( image );
358             }
359           }
360           else if ( value.Get< Property::Map >().Empty() )
361           {
362             // An empty map means the background is no longer required
363             controlImpl.ClearBackground();
364           }
365           break;
366         }
367
368         case Toolkit::Control::PROPERTY_WIDTH_POLICY:
369         {
370           controlImpl.mImpl->mWidthPolicy = Scripting::GetEnumeration< Toolkit::Control::SizePolicy >( value.Get< std::string >().c_str(), SIZE_POLICY_STRING_TABLE, SIZE_POLICY_STRING_TABLE_COUNT );
371           break;
372         }
373
374         case Toolkit::Control::PROPERTY_HEIGHT_POLICY:
375         {
376           controlImpl.mImpl->mHeightPolicy = Scripting::GetEnumeration< Toolkit::Control::SizePolicy >( value.Get< std::string >().c_str(), SIZE_POLICY_STRING_TABLE, SIZE_POLICY_STRING_TABLE_COUNT );
377           break;
378         }
379
380         case Toolkit::Control::PROPERTY_MINIMUM_SIZE:
381         {
382           controlImpl.SetMinimumSize( value.Get< Vector3 >() );
383           break;
384         }
385
386         case Toolkit::Control::PROPERTY_MAXIMUM_SIZE:
387         {
388           controlImpl.SetMaximumSize( value.Get< Vector3 >() );
389           break;
390         }
391
392         case Toolkit::Control::PROPERTY_KEY_INPUT_FOCUS:
393         {
394           if ( value.Get< bool >() )
395           {
396             controlImpl.SetKeyInputFocus();
397           }
398           else
399           {
400             controlImpl.ClearKeyInputFocus();
401           }
402           break;
403         }
404       }
405     }
406   }
407
408   /**
409    * Called to retrieve a property of an object of this type.
410    * @param[in] object The object whose property is to be retrieved.
411    * @param[in] index The property index.
412    * @return The current value of the property.
413    */
414   static Property::Value GetProperty( BaseObject* object, Property::Index index )
415   {
416     Property::Value value;
417
418     Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
419
420     if ( control )
421     {
422       Control& controlImpl( control.GetImplementation() );
423
424       switch ( index )
425       {
426         case Toolkit::Control::PROPERTY_BACKGROUND_COLOR:
427         {
428           value = controlImpl.GetBackgroundColor();
429           break;
430         }
431
432         case Toolkit::Control::PROPERTY_BACKGROUND:
433         {
434           Property::Map map;
435
436           Actor actor = controlImpl.GetBackgroundActor();
437           if ( actor )
438           {
439             ImageActor imageActor = ImageActor::DownCast( actor );
440             if ( imageActor )
441             {
442               Image image = imageActor.GetImage();
443               Property::Map imageMap;
444               Scripting::CreatePropertyMap( image, imageMap );
445               map[ "image" ] = imageMap;
446             }
447           }
448
449           value = map;
450           break;
451         }
452
453         case Toolkit::Control::PROPERTY_WIDTH_POLICY:
454         {
455           value = std::string( Scripting::GetEnumerationName< Toolkit::Control::SizePolicy >( controlImpl.mImpl->mWidthPolicy, SIZE_POLICY_STRING_TABLE, SIZE_POLICY_STRING_TABLE_COUNT ) );
456           break;
457         }
458
459         case Toolkit::Control::PROPERTY_HEIGHT_POLICY:
460         {
461           value = std::string( Scripting::GetEnumerationName< Toolkit::Control::SizePolicy >( controlImpl.mImpl->mHeightPolicy, SIZE_POLICY_STRING_TABLE, SIZE_POLICY_STRING_TABLE_COUNT ) );
462           break;
463         }
464
465         case Toolkit::Control::PROPERTY_MINIMUM_SIZE:
466         {
467           value = controlImpl.mImpl->GetMinimumSize();
468           break;
469         }
470
471         case Toolkit::Control::PROPERTY_MAXIMUM_SIZE:
472         {
473           value = controlImpl.mImpl->GetMaximumSize();
474           break;
475         }
476
477         case Toolkit::Control::PROPERTY_KEY_INPUT_FOCUS:
478         {
479           value = controlImpl.HasKeyInputFocus();
480           break;
481         }
482       }
483     }
484
485     return value;
486   }
487
488   /**
489    * Helper to get minimum size
490    * @return minimum size
491    */
492   inline const Vector3& GetMinimumSize()
493   {
494     if( mMinMaxSize.Count() > MIN_SIZE_INDEX )
495     {
496       return mMinMaxSize[ MIN_SIZE_INDEX ];
497     }
498     else
499     {
500       // its not been allocated so its ZERO
501       return Vector3::ZERO;
502     }
503   }
504   /**
505    * Helper to Set minimum size
506    * @param size to set
507    */
508   inline void SetMinimumSize( const Vector3& size )
509   {
510     if( mMinMaxSize.Count() > MIN_SIZE_INDEX )
511     {
512       mMinMaxSize[ MIN_SIZE_INDEX ] = size;
513     }
514     else
515     {
516       // its not been allocated so push the new value there
517       mMinMaxSize.PushBack( size );
518     }
519   }
520
521   /**
522    * Helper to get maximum size
523    * @return maximum size
524    */
525   inline const Vector3& GetMaximumSize()
526   {
527     if( mMinMaxSize.Count() > MAX_SIZE_INDEX )
528     {
529       return mMinMaxSize[ MAX_SIZE_INDEX ];
530     }
531     else
532     {
533       // its not been allocated so its MAX_SIZE
534       return MAX_SIZE;
535     }
536   }
537
538   /**
539    * Helper to Set minimum size
540    * @param size to set
541    */
542   inline void SetMaximumSize( const Vector3& size )
543   {
544     if( mMinMaxSize.Count() > MAX_SIZE_INDEX )
545     {
546       mMinMaxSize[ MAX_SIZE_INDEX ] = size;
547     }
548     else if( mMinMaxSize.Count() > MIN_SIZE_INDEX )
549     {
550       // max has not been allocated, but min has
551       mMinMaxSize.PushBack( size );
552     }
553     else
554     {
555       // min and max both unallocated so allocate both
556       mMinMaxSize.Resize( 2u ); // this will reserve and default construct two Vector3s
557       mMinMaxSize[ MAX_SIZE_INDEX ] = size;
558     }
559   }
560
561   // Data
562
563   Control& mControlImpl;
564   Background* mBackground;           ///< Only create the background if we use it
565   Vector3* mStartingPinchScale;      ///< The scale when a pinch gesture starts, TODO: consider removing this
566   Toolkit::Control::KeyEventSignalType mKeyEventSignal;
567
568   // Gesture Detection
569   PinchGestureDetector mPinchGestureDetector;
570   PanGestureDetector mPanGestureDetector;
571   TapGestureDetector mTapGestureDetector;
572   LongPressGestureDetector mLongPressGestureDetector;
573   // @todo change all these to Vector2 when we have a chance to sanitize the public API as well
574   Vector3 mCurrentSize; ///< Stores the current control's size, this is the negotiated size
575   Vector3 mNaturalSize; ///< Stores the size set through the Actor's API. This is size the actor wants to be. Useful when reset to the initial size is needed.
576   Dali::Vector< Vector3 > mMinMaxSize; ///< Stores the minimum and maximum size if they are set
577
578   Toolkit::Control::SizePolicy mWidthPolicy :3;  ///< Stores the width policy. 3 bits covers 8 values
579   Toolkit::Control::SizePolicy mHeightPolicy :3; ///< Stores the height policy. 3 bits covers 8 values
580   ControlBehaviour mFlags :6;             ///< Flags passed in from constructor. Need to increase this size when new enums are added
581   bool mInsideRelayout:1;                 ///< Detect when were in Relayout
582   bool mIsKeyboardNavigationSupported:1;  ///< Stores whether keyboard navigation is supported by the control.
583   bool mIsKeyboardFocusGroup:1;           ///< Stores whether the control is a focus group.
584   bool mInitialized:1;
585
586   // Properties - these need to be members of Internal::Control::Impl as they need to functions within this class.
587   static PropertyRegistration PROPERTY_1;
588   static PropertyRegistration PROPERTY_2;
589   static PropertyRegistration PROPERTY_3;
590   static PropertyRegistration PROPERTY_4;
591   static PropertyRegistration PROPERTY_5;
592   static PropertyRegistration PROPERTY_6;
593   static PropertyRegistration PROPERTY_7;
594 };
595
596 PropertyRegistration Control::Impl::PROPERTY_1( CONTROL_TYPE, "background-color", Toolkit::Control::PROPERTY_BACKGROUND_COLOR, Property::VECTOR4, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
597 PropertyRegistration Control::Impl::PROPERTY_2( CONTROL_TYPE, "background",       Toolkit::Control::PROPERTY_BACKGROUND,       Property::MAP,     &Control::Impl::SetProperty, &Control::Impl::GetProperty );
598 PropertyRegistration Control::Impl::PROPERTY_3( CONTROL_TYPE, "width-policy",     Toolkit::Control::PROPERTY_WIDTH_POLICY,     Property::STRING,  &Control::Impl::SetProperty, &Control::Impl::GetProperty );
599 PropertyRegistration Control::Impl::PROPERTY_4( CONTROL_TYPE, "height-policy",    Toolkit::Control::PROPERTY_HEIGHT_POLICY,    Property::STRING,  &Control::Impl::SetProperty, &Control::Impl::GetProperty );
600 PropertyRegistration Control::Impl::PROPERTY_5( CONTROL_TYPE, "minimum-size",     Toolkit::Control::PROPERTY_MINIMUM_SIZE,     Property::VECTOR3, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
601 PropertyRegistration Control::Impl::PROPERTY_6( CONTROL_TYPE, "maximum-size",     Toolkit::Control::PROPERTY_MAXIMUM_SIZE,     Property::VECTOR3, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
602 PropertyRegistration Control::Impl::PROPERTY_7( CONTROL_TYPE, "key-input-focus",  Toolkit::Control::PROPERTY_KEY_INPUT_FOCUS,  Property::BOOLEAN, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
603
604 Toolkit::Control Control::New()
605 {
606   // Create the implementation, temporarily owned on stack
607   IntrusivePtr<Control> controlImpl = new Control( CONTROL_BEHAVIOUR_NONE );
608
609   // Pass ownership to handle
610   Toolkit::Control handle( *controlImpl );
611
612   // Second-phase init of the implementation
613   // This can only be done after the CustomActor connection has been made...
614   controlImpl->Initialize();
615
616   return handle;
617 }
618
619 Control::~Control()
620 {
621   delete mImpl;
622 }
623
624 void Control::SetSizePolicy( Toolkit::Control::SizePolicy widthPolicy, Toolkit::Control::SizePolicy heightPolicy )
625 {
626   bool relayoutRequest( false );
627
628   if ( ( mImpl->mWidthPolicy != widthPolicy ) || ( mImpl->mHeightPolicy != heightPolicy ) )
629   {
630     relayoutRequest = true;
631   }
632
633   mImpl->mWidthPolicy = widthPolicy;
634   mImpl->mHeightPolicy = heightPolicy;
635
636   // Ensure RelayoutRequest is called AFTER new policies have been set.
637   if ( relayoutRequest )
638   {
639     RelayoutRequest();
640   }
641 }
642
643 void Control::GetSizePolicy( Toolkit::Control::SizePolicy& widthPolicy, Toolkit::Control::SizePolicy& heightPolicy ) const
644 {
645   widthPolicy = mImpl->mWidthPolicy;
646   heightPolicy = mImpl->mHeightPolicy;
647 }
648
649 void Control::SetMinimumSize( const Vector3& size )
650 {
651   const Vector3& minSize = mImpl->GetMinimumSize();
652   if ( fabsf( minSize.width - size.width ) > Math::MACHINE_EPSILON_1000 ||
653        fabsf( minSize.height - size.height ) > Math::MACHINE_EPSILON_1000 )
654   {
655     mImpl->SetMinimumSize( size );
656
657     // Only relayout if our control is using the minimum or range policy.
658     if ( ( mImpl->mHeightPolicy == Toolkit::Control::Minimum ) || ( mImpl->mWidthPolicy  == Toolkit::Control::Minimum ) ||
659          ( mImpl->mHeightPolicy == Toolkit::Control::Range   ) || ( mImpl->mWidthPolicy  == Toolkit::Control::Range   ) )
660     {
661       RelayoutRequest();
662     }
663   }
664 }
665
666 const Vector3& Control::GetMinimumSize() const
667 {
668   return mImpl->GetMinimumSize();
669 }
670
671 void Control::SetMaximumSize( const Vector3& size )
672 {
673   const Vector3& maxSize = mImpl->GetMaximumSize();
674   if ( fabsf( maxSize.width - size.width ) > Math::MACHINE_EPSILON_1000 ||
675        fabsf( maxSize.height - size.height ) > Math::MACHINE_EPSILON_1000 )
676   {
677     mImpl->SetMaximumSize( size );
678
679     // Only relayout if our control is using the maximum or range policy.
680     if ( ( mImpl->mHeightPolicy == Toolkit::Control::Maximum ) || ( mImpl->mWidthPolicy  == Toolkit::Control::Maximum ) ||
681          ( mImpl->mHeightPolicy == Toolkit::Control::Range   ) || ( mImpl->mWidthPolicy  == Toolkit::Control::Range   ) )
682     {
683       RelayoutRequest();
684     }
685   }
686 }
687
688 const Vector3& Control::GetMaximumSize() const
689 {
690   return mImpl->GetMaximumSize();
691 }
692
693 Vector3 Control::GetNaturalSize()
694 {
695   // could be overridden in derived classes.
696   return mImpl->mNaturalSize;
697 }
698
699 float Control::GetHeightForWidth( float width )
700 {
701   // could be overridden in derived classes.
702   float height( 0.0f );
703   if ( mImpl->mNaturalSize.width > 0.0f )
704   {
705     height = mImpl->mNaturalSize.height * width / mImpl->mNaturalSize.width;
706   }
707   return height;
708 }
709
710 float Control::GetWidthForHeight( float height )
711 {
712   // could be overridden in derived classes.
713   float width( 0.0f );
714   if ( mImpl->mNaturalSize.height > 0.0f )
715   {
716     width = mImpl->mNaturalSize.width * height / mImpl->mNaturalSize.height;
717   }
718   return width;
719 }
720
721 const Vector3& Control::GetControlSize() const
722 {
723   return mImpl->mCurrentSize;
724 }
725
726 const Vector3& Control::GetSizeSet() const
727 {
728   return mImpl->mNaturalSize;
729 }
730
731 void Control::SetKeyInputFocus()
732 {
733   if( Self().OnStage() )
734   {
735     Toolkit::KeyInputFocusManager::Get().SetFocus(Toolkit::Control::DownCast(Self()));
736   }
737 }
738
739 bool Control::HasKeyInputFocus()
740 {
741   bool result = false;
742   if( Self().OnStage() )
743   {
744     result = Toolkit::KeyInputFocusManager::Get().IsKeyboardListener(Toolkit::Control::DownCast(Self()));
745   }
746   return result;
747 }
748
749 void Control::ClearKeyInputFocus()
750 {
751   if( Self().OnStage() )
752   {
753     Toolkit::KeyInputFocusManager::Get().RemoveFocus(Toolkit::Control::DownCast(Self()));
754   }
755 }
756
757 PinchGestureDetector Control::GetPinchGestureDetector() const
758 {
759   return mImpl->mPinchGestureDetector;
760 }
761
762 PanGestureDetector Control::GetPanGestureDetector() const
763 {
764   return mImpl->mPanGestureDetector;
765 }
766
767 TapGestureDetector Control::GetTapGestureDetector() const
768 {
769   return mImpl->mTapGestureDetector;
770 }
771
772 LongPressGestureDetector Control::GetLongPressGestureDetector() const
773 {
774   return mImpl->mLongPressGestureDetector;
775 }
776
777 void Control::SetBackgroundColor( const Vector4& color )
778 {
779   Background& background( mImpl->GetBackground() );
780
781   if ( background.actor )
782   {
783     // Just set the actor color
784     background.actor.SetColor( color );
785   }
786   else
787   {
788     // Create Mesh Actor
789     MeshActor meshActor = MeshActor::New( CreateMesh() );
790
791     meshActor.SetAffectedByLighting( false );
792     SetupBackgroundActor( meshActor, Actor::SCALE, color );
793
794     // Set the background actor before adding so that we do not inform deriving classes
795     background.actor = meshActor;
796     Self().Add( meshActor );
797   }
798
799   background.color = color;
800 }
801
802 Vector4 Control::GetBackgroundColor() const
803 {
804   if ( mImpl->mBackground )
805   {
806     return mImpl->mBackground->color;
807   }
808   return Color::TRANSPARENT;
809 }
810
811 void Control::SetBackground( Image image )
812 {
813   Background& background( mImpl->GetBackground() );
814
815   if ( background.actor )
816   {
817     // Remove Current actor, unset AFTER removal so that we do not inform deriving classes
818     Self().Remove( background.actor );
819     background.actor.Reset();
820   }
821
822   ImageActor imageActor = ImageActor::New( image );
823   SetupBackgroundActor( imageActor, Actor::SIZE, background.color );
824
825   // Set the background actor before adding so that we do not inform derived classes
826   background.actor = imageActor;
827   Self().Add( imageActor );
828 }
829
830 void Control::ClearBackground()
831 {
832   if ( mImpl->mBackground )
833   {
834     Background& background( mImpl->GetBackground() );
835     Self().Remove( background.actor );
836
837     delete mImpl->mBackground;
838     mImpl->mBackground = NULL;
839   }
840 }
841
842 Actor Control::GetBackgroundActor() const
843 {
844   if ( mImpl->mBackground )
845   {
846     return mImpl->mBackground->actor;
847   }
848
849   return Actor();
850 }
851
852 void Control::SetKeyboardNavigationSupport(bool isSupported)
853 {
854   mImpl->mIsKeyboardNavigationSupported = isSupported;
855 }
856
857 bool Control::IsKeyboardNavigationSupported()
858 {
859   return mImpl->mIsKeyboardNavigationSupported;
860 }
861
862 void Control::Activate()
863 {
864   // Inform deriving classes
865   OnActivated();
866 }
867
868 bool Control::OnAccessibilityPan(PanGesture gesture)
869 {
870   return false; // Accessibility pan gesture is not handled by default
871 }
872
873 bool Control::OnAccessibilityTouch(const TouchEvent& touchEvent)
874 {
875   return false; // Accessibility touch event is not handled by default
876 }
877
878 bool Control::OnAccessibilityValueChange(bool isIncrease)
879 {
880   return false; // Accessibility value change action is not handled by default
881 }
882
883 void Control::NegotiateSize( const Vector2& allocatedSize, ActorSizeContainer& container )
884 {
885   Vector2 size;
886
887   if ( mImpl->mWidthPolicy == Toolkit::Control::Fixed )
888   {
889     if ( mImpl->mHeightPolicy == Toolkit::Control::Fixed )
890     {
891       // If a control says it has a fixed size, then use the size set by the application / control.
892       Vector2 setSize( mImpl->mNaturalSize );
893       if ( setSize != Vector2::ZERO )
894       {
895         size = setSize;
896
897         // Policy is set to Fixed, so if the application / control has not set one of the dimensions,
898         // then we should use the natural size of the control rather than the full allocation.
899         if ( EqualsZero( size.width ) )
900         {
901           size.width = GetWidthForHeight( size.height );
902         }
903         else if ( EqualsZero( size.height ) )
904         {
905           size.height = GetHeightForWidth( size.width );
906         }
907       }
908       else
909       {
910         // If that is not set then set the size to the control's natural size
911         size = Vector2( GetNaturalSize() );
912       }
913     }
914     else
915     {
916       // Width is fixed so if the application / control has set it, then use that.
917       if ( !EqualsZero( mImpl->mNaturalSize.width ) )
918       {
919         size.width = mImpl->mNaturalSize.width;
920       }
921       else
922       {
923         // Otherwise, set the width to what has been allocated.
924         size.width = allocatedSize.width;
925       }
926
927       // Height is flexible so ask control what the height should be for our width.
928       size.height = GetHeightForWidth( size.width );
929
930       // Ensure height is within our policy rules
931       size.height = Calculate( mImpl->mHeightPolicy, GetMinimumSize().height, GetMaximumSize().height, size.height );
932     }
933   }
934   else
935   {
936     if ( mImpl->mHeightPolicy == Toolkit::Control::Fixed )
937     {
938       // Height is fixed so if the application / control has set it, then use that.
939       if ( !EqualsZero( mImpl->mNaturalSize.height ) )
940       {
941         size.height = mImpl->mNaturalSize.height;
942       }
943       else
944       {
945         // Otherwise, set the height to what has been allocated.
946         size.height = allocatedSize.height;
947       }
948
949       // Width is flexible so ask control what the width should be for our height.
950       size.width = GetWidthForHeight( size.height );
951
952       // Ensure width is within our policy rules
953       size.width = Calculate( mImpl->mWidthPolicy, mImpl->GetMinimumSize().width, mImpl->GetMaximumSize().width, size.width );
954     }
955     else
956     {
957       // Width and height are BOTH flexible.
958       // Calculate the width and height using the policy rules.
959       size.width = Calculate( mImpl->mWidthPolicy, mImpl->GetMinimumSize().width, mImpl->GetMaximumSize().width, allocatedSize.width );
960       size.height = Calculate( mImpl->mHeightPolicy, mImpl->GetMinimumSize().height, mImpl->GetMaximumSize().height, allocatedSize.height );
961     }
962   }
963
964   // If the width has not been set, then set to the allocated width.
965   // Also if the width set is greater than the allocated, then set to allocated (no exceed support).
966   if ( EqualsZero( size.width ) || ( size.width > allocatedSize.width ) )
967   {
968     size.width = allocatedSize.width;
969   }
970
971   // If the height has not been set, then set to the allocated height.
972   // Also if the height set is greater than the allocated, then set to allocated (no exceed support).
973   if ( EqualsZero( size.height ) || ( size.height > allocatedSize.height ) )
974   {
975     size.height = allocatedSize.height;
976   }
977
978   DALI_LOG_INFO( gLogFilter, Debug::Verbose,
979                  "%p: Natural: [%.2f, %.2f] Allocated: [%.2f, %.2f] Set: [%.2f, %.2f]\n",
980                  Self().GetObjectPtr(),
981                  GetNaturalSize().x, GetNaturalSize().y,
982                  allocatedSize.x, allocatedSize.y,
983                  size.x, size.y );
984
985   // Avoids relayout again when OnSizeSet callback arrives as a function of us or deriving class calling SetSize()
986   mImpl->mInsideRelayout = true;
987   Self().SetSize( size );
988   // Only relayout controls which requested to be relaid out.
989   OnRelayout( size, container );
990   mImpl->mInsideRelayout = false;
991 }
992
993 void Control::SetAsKeyboardFocusGroup(bool isFocusGroup)
994 {
995   mImpl->mIsKeyboardFocusGroup = isFocusGroup;
996
997   // The following line will be removed when the deprecated API in KeyboardFocusManager is deleted
998   Toolkit::KeyboardFocusManager::Get().SetAsFocusGroup(Self(), isFocusGroup);
999 }
1000
1001 bool Control::IsKeyboardFocusGroup()
1002 {
1003   return Toolkit::KeyboardFocusManager::Get().IsFocusGroup(Self());
1004 }
1005
1006 Actor Control::GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocusNavigationDirection direction, bool loopEnabled)
1007 {
1008   return Actor();
1009 }
1010
1011 void Control::OnKeyboardFocusChangeCommitted(Actor commitedFocusableActor)
1012 {
1013 }
1014
1015 bool Control::DoAction(BaseObject* object, const std::string& actionName, const PropertyValueContainer& attributes)
1016 {
1017   bool ret = false;
1018
1019   if( object && ( 0 == strcmp( actionName.c_str(), ACTION_CONTROL_ACTIVATED ) ) )
1020   {
1021     Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
1022     if( control )
1023     {
1024       // if cast succeeds there is an implementation so no need to check
1025       control.GetImplementation().OnActivated();
1026     }
1027   }
1028
1029   return ret;
1030 }
1031
1032 bool Control::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
1033 {
1034   Dali::BaseHandle handle( object );
1035
1036   bool connected( false );
1037   Toolkit::Control control = Toolkit::Control::DownCast( handle );
1038   if ( control )
1039   {
1040     Control& controlImpl( control.GetImplementation() );
1041     connected = true;
1042
1043     if ( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_EVENT ) )
1044     {
1045       controlImpl.KeyEventSignal().Connect( tracker, functor );
1046     }
1047     else if( 0 == strcmp( signalName.c_str(), SIGNAL_TAPPED ) )
1048     {
1049       controlImpl.EnableGestureDetection( Gesture::Tap );
1050       controlImpl.GetTapGestureDetector().DetectedSignal().Connect( tracker, functor );
1051     }
1052     else if( 0 == strcmp( signalName.c_str(), SIGNAL_PANNED ) )
1053     {
1054       controlImpl.EnableGestureDetection( Gesture::Pan );
1055       controlImpl.GetPanGestureDetector().DetectedSignal().Connect( tracker, functor );
1056     }
1057     else if( 0 == strcmp( signalName.c_str(), SIGNAL_PINCHED ) )
1058     {
1059       controlImpl.EnableGestureDetection( Gesture::Pinch );
1060       controlImpl.GetPinchGestureDetector().DetectedSignal().Connect( tracker, functor );
1061     }
1062     else if( 0 == strcmp( signalName.c_str(), SIGNAL_LONG_PRESSED ) )
1063     {
1064       controlImpl.EnableGestureDetection( Gesture::LongPress );
1065       controlImpl.GetLongPressGestureDetector().DetectedSignal().Connect( tracker, functor );
1066     }
1067     else
1068     {
1069       // signalName does not match any signal
1070       connected = false;
1071     }
1072   }
1073   return connected;
1074 }
1075
1076 Toolkit::Control::KeyEventSignalType& Control::KeyEventSignal()
1077 {
1078   return mImpl->mKeyEventSignal;
1079 }
1080
1081 bool Control::EmitKeyEventSignal( const KeyEvent& event )
1082 {
1083   // Guard against destruction during signal emission
1084   Dali::Toolkit::Control handle( GetOwner() );
1085
1086   bool consumed = false;
1087
1088   // signals are allocated dynamically when someone connects
1089   if ( !mImpl->mKeyEventSignal.Empty() )
1090   {
1091     consumed = mImpl->mKeyEventSignal.Emit( handle, event );
1092   }
1093
1094   if (!consumed)
1095   {
1096     // Notification for derived classes
1097     consumed = OnKeyEvent(event);
1098   }
1099
1100   return consumed;
1101 }
1102
1103 Control::Control( ControlBehaviour behaviourFlags )
1104 : CustomActorImpl( behaviourFlags & REQUIRES_TOUCH_EVENTS ),
1105   mImpl(new Impl(*this))
1106 {
1107   mImpl->mFlags = behaviourFlags;
1108 }
1109
1110 void Control::Initialize()
1111 {
1112
1113   // Calling deriving classes
1114   OnInitialize();
1115
1116   if( mImpl->mFlags & REQUIRES_STYLE_CHANGE_SIGNALS )
1117   {
1118     Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
1119
1120     // Register for style changes
1121     styleManager.StyleChangeSignal().Connect( this, &Control::DoStyleChange );
1122
1123     // SetTheme
1124     GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
1125   }
1126
1127   SetRequiresHoverEvents(mImpl->mFlags & REQUIRES_HOVER_EVENTS);
1128   SetRequiresMouseWheelEvents(mImpl->mFlags & REQUIRES_MOUSE_WHEEL_EVENTS);
1129
1130   mImpl->mInitialized = true;
1131 }
1132
1133 void Control::EnableGestureDetection(Gesture::Type type)
1134 {
1135   if ( (type & Gesture::Pinch) && !mImpl->mPinchGestureDetector )
1136   {
1137     mImpl->mPinchGestureDetector = PinchGestureDetector::New();
1138     mImpl->mPinchGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PinchDetected);
1139     mImpl->mPinchGestureDetector.Attach(Self());
1140   }
1141
1142   if ( (type & Gesture::Pan) && !mImpl->mPanGestureDetector )
1143   {
1144     mImpl->mPanGestureDetector = PanGestureDetector::New();
1145     mImpl->mPanGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PanDetected);
1146     mImpl->mPanGestureDetector.Attach(Self());
1147   }
1148
1149   if ( (type & Gesture::Tap) && !mImpl->mTapGestureDetector )
1150   {
1151     mImpl->mTapGestureDetector = TapGestureDetector::New();
1152     mImpl->mTapGestureDetector.DetectedSignal().Connect(mImpl, &Impl::TapDetected);
1153     mImpl->mTapGestureDetector.Attach(Self());
1154   }
1155
1156   if ( (type & Gesture::LongPress) && !mImpl->mLongPressGestureDetector )
1157   {
1158     mImpl->mLongPressGestureDetector = LongPressGestureDetector::New();
1159     mImpl->mLongPressGestureDetector.DetectedSignal().Connect(mImpl, &Impl::LongPressDetected);
1160     mImpl->mLongPressGestureDetector.Attach(Self());
1161   }
1162 }
1163
1164 void Control::DisableGestureDetection(Gesture::Type type)
1165 {
1166   if ( (type & Gesture::Pinch) && mImpl->mPinchGestureDetector )
1167   {
1168     mImpl->mPinchGestureDetector.Detach(Self());
1169     mImpl->mPinchGestureDetector.Reset();
1170   }
1171
1172   if ( (type & Gesture::Pan) && mImpl->mPanGestureDetector )
1173   {
1174     mImpl->mPanGestureDetector.Detach(Self());
1175     mImpl->mPanGestureDetector.Reset();
1176   }
1177
1178   if ( (type & Gesture::Tap) && mImpl->mTapGestureDetector )
1179   {
1180     mImpl->mTapGestureDetector.Detach(Self());
1181     mImpl->mTapGestureDetector.Reset();
1182   }
1183
1184   if ( (type & Gesture::LongPress) && mImpl->mLongPressGestureDetector)
1185   {
1186     mImpl->mLongPressGestureDetector.Detach(Self());
1187     mImpl->mLongPressGestureDetector.Reset();
1188   }
1189 }
1190
1191 void Control::RelayoutRequest()
1192 {
1193   // unfortunate double negative but thats to guarantee new controls get size negotiation
1194   // by default and have to "opt-out" if they dont want it
1195   if( !(mImpl->mFlags & NO_SIZE_NEGOTIATION) )
1196   {
1197     Internal::RelayoutController::Request();
1198   }
1199 }
1200
1201 void Control::Relayout( Actor actor, const Vector2& size, ActorSizeContainer& container )
1202 {
1203   if ( actor )
1204   {
1205     Toolkit::Control control( Toolkit::Control::DownCast( actor ) );
1206     if( control )
1207     {
1208       control.GetImplementation().NegotiateSize( size, container );
1209     }
1210     else
1211     {
1212       container.push_back( ActorSizePair( actor, size ) );
1213     }
1214   }
1215 }
1216
1217 void Control::OnInitialize()
1218 {
1219 }
1220
1221 void Control::OnActivated()
1222 {
1223 }
1224
1225 void Control::OnThemeChange( Toolkit::StyleManager styleManager )
1226 {
1227   GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
1228 }
1229
1230 void Control::OnFontChange( bool defaultFontChange, bool defaultFontSizeChange )
1231 {
1232 }
1233
1234 void Control::OnPinch(const PinchGesture& pinch)
1235 {
1236   if( !( mImpl->mStartingPinchScale ) )
1237   {
1238     // lazy allocate
1239     mImpl->mStartingPinchScale = new Vector3;
1240   }
1241
1242   if( pinch.state == Gesture::Started )
1243   {
1244     *( mImpl->mStartingPinchScale ) = Self().GetCurrentScale();
1245   }
1246
1247   Self().SetScale( *( mImpl->mStartingPinchScale ) * pinch.scale );
1248 }
1249
1250 void Control::OnPan( const PanGesture& pan )
1251 {
1252 }
1253
1254 void Control::OnTap(const TapGesture& tap)
1255 {
1256 }
1257
1258 void Control::OnLongPress( const LongPressGesture& longPress )
1259 {
1260 }
1261
1262 void Control::OnControlStageConnection()
1263 {
1264 }
1265
1266 void Control::OnControlStageDisconnection()
1267 {
1268 }
1269
1270 void Control::OnControlChildAdd( Actor& child )
1271 {
1272 }
1273
1274 void Control::OnControlChildRemove( Actor& child )
1275 {
1276 }
1277
1278 void Control::OnControlSizeSet( const Vector3& size )
1279 {
1280 }
1281
1282 void Control::OnRelayout( const Vector2& size, ActorSizeContainer& container )
1283 {
1284   unsigned int numChildren = Self().GetChildCount();
1285
1286   for( unsigned int i=0; i<numChildren; ++i )
1287   {
1288     container.push_back( ActorSizePair( Self().GetChildAt(i), size ) );
1289   }
1290 }
1291
1292 void Control::OnKeyInputFocusGained()
1293 {
1294   // Do Nothing
1295 }
1296
1297 void Control::OnKeyInputFocusLost()
1298 {
1299   // Do Nothing
1300 }
1301
1302 void Control::OnSizeAnimation(Animation& animation, const Vector3& targetSize)
1303 {
1304   // @todo consider animating negotiated child sizes to target size
1305 }
1306
1307 bool Control::OnTouchEvent(const TouchEvent& event)
1308 {
1309   return false; // Do not consume
1310 }
1311
1312 bool Control::OnHoverEvent(const HoverEvent& event)
1313 {
1314   return false; // Do not consume
1315 }
1316
1317 bool Control::OnKeyEvent(const KeyEvent& event)
1318 {
1319   return false; // Do not consume
1320 }
1321
1322 bool Control::OnMouseWheelEvent(const MouseWheelEvent& event)
1323 {
1324   return false; // Do not consume
1325 }
1326
1327 Actor Control::GetChildByAlias(const std::string& actorAlias)
1328 {
1329   return Actor();
1330 }
1331
1332 void Control::OnStageConnection()
1333 {
1334   RelayoutRequest();
1335
1336   // Notify derived classes.
1337   OnControlStageConnection();
1338 }
1339
1340 void Control::OnStageDisconnection()
1341 {
1342   // Notify derived classes
1343   OnControlStageDisconnection();
1344 }
1345
1346 void Control::OnChildAdd(Actor& child)
1347 {
1348   // If this is the background actor, then we do not want to relayout or inform deriving classes
1349   if ( mImpl->mBackground && ( child == mImpl->mBackground->actor ) )
1350   {
1351     return;
1352   }
1353
1354   // Request for relayout as we may need to position the new child and old ones
1355   RelayoutRequest();
1356
1357   // Notify derived classes.
1358   OnControlChildAdd( child );
1359 }
1360
1361 void Control::OnChildRemove(Actor& child)
1362 {
1363   // If this is the background actor, then we do not want to relayout or inform deriving classes
1364   if ( mImpl->mBackground && ( child == mImpl->mBackground->actor ) )
1365   {
1366     return;
1367   }
1368
1369   // Request for relayout as we may need to re-position the old child
1370   RelayoutRequest();
1371
1372   // Notify derived classes.
1373   OnControlChildRemove( child );
1374 }
1375
1376 void Control::OnSizeSet(const Vector3& targetSize)
1377 {
1378   if( ( !mImpl->mInsideRelayout ) && ( targetSize != mImpl->mNaturalSize ) )
1379   {
1380     // Only updates size if set through Actor's API
1381     mImpl->mNaturalSize = targetSize;
1382   }
1383
1384   if( targetSize != mImpl->mCurrentSize )
1385   {
1386     // Update control size.
1387     mImpl->mCurrentSize = targetSize;
1388
1389     // Notify derived classes.
1390     OnControlSizeSet( targetSize );
1391   }
1392 }
1393
1394 void Control::SignalConnected( SlotObserver* slotObserver, CallbackBase* callback )
1395 {
1396   mImpl->SignalConnected( slotObserver, callback );
1397 }
1398
1399 void Control::SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback )
1400 {
1401   mImpl->SignalDisconnected( slotObserver, callback );
1402 }
1403
1404 void Control::DoStyleChange( Toolkit::StyleManager styleManager, StyleChange change )
1405 {
1406   if( change.themeChange )
1407   {
1408     OnThemeChange( styleManager );
1409   }
1410   else if( change.defaultFontChange || change.defaultFontSizeChange )
1411   {
1412     OnFontChange( change.defaultFontChange, change.defaultFontSizeChange );
1413   }
1414 }
1415
1416 } // namespace Internal
1417
1418 } // namespace Toolkit
1419
1420 } // namespace Dali