2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.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
8 // http://floralicense.org/license/
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.
17 #include <dali-toolkit/public-api/controls/control-impl.h>
19 #include <boost/thread/tss.hpp>
22 #include <dali/integration-api/debug.h>
24 #include "dali-toolkit/internal/controls/style-change-processor.h"
25 #include "dali-toolkit/internal/controls/relayout-controller.h"
26 #include "dali-toolkit/internal/controls/relayout-helper.h"
27 #include "dali-toolkit/public-api/focus-manager/keyinput-focus-manager.h"
28 #include "dali-toolkit/public-api/focus-manager/keyboard-focus-manager.h"
29 #include <dali-toolkit/public-api/controls/control.h>
37 const Property::Index Control::PROPERTY_BACKGROUND_COLOR = ControlImpl::CONTROL_PROPERTY_START_INDEX;
38 const Property::Index Control::PROPERTY_BACKGROUND = ControlImpl::CONTROL_PROPERTY_START_INDEX + 1;
43 #if defined(DEBUG_ENABLED)
44 Integration::Log::Filter* gLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_CONTROL");
47 const float MAX_FLOAT_VALUE( std::numeric_limits<float>::max() );
48 const float BACKGROUND_ACTOR_Z_POSITION( -0.1f );
52 return ControlImpl::New();
55 TypeRegistration CONTROL_TYPE( typeid(Control), typeid(CustomActor), Create );
57 // Property Registration after ControlImpl::Impl definition below
59 TypeAction ACTION_TYPE_1(CONTROL_TYPE, Toolkit::Control::ACTION_CONTROL_ACTIVATED, &ControlImpl::DoAction);
62 * Helper class used to set the Control's size through the Actor's API or through children added.
67 SetSizeLock( bool& lock )
83 * Structure which holds information about the background of a control
87 Actor actor; ///< Either a MeshActor or an ImageActor
88 Vector4 color; ///< The color of the actor.
101 * Helper function to calculate a dimension given the policy of that dimension; the minimum &
102 * maximum values that dimension can be; and the allocated value for that dimension.
104 * @param[in] policy The size policy for that dimension.
105 * @param[in] minimum The minimum value that dimension can be.
106 * @param[in] maximum The maximum value that dimension can be.
107 * @param[in] allocated The value allocated for that dimension.
109 * @return The value that the dimension should be.
111 * @note This does not handle Control::Fixed policy.
113 float Calculate( Control::SizePolicy policy, float minimum, float maximum, float allocated )
115 float size( allocated );
121 // Use allocated value
125 case Control::Minimum:
127 // Size is always at least the minimum.
128 size = std::max( allocated, minimum );
132 case Control::Maximum:
134 // Size can grow but up to a maximum value.
135 size = std::min( allocated, maximum );
141 // Size is at least the minimum and can grow up to the maximum
142 size = std::max( size, minimum );
143 size = std::min( size, maximum );
147 case Control::Flexible:
149 // Size grows or shrinks with no limits.
156 DALI_ASSERT_DEBUG( false && "This function was not intended to be used by any other policy." );
165 * Creates a white coloured Mesh.
169 Vector3 white( Color::WHITE );
173 // Create vertices with a white color (actual color is set by actor color)
174 MeshData::VertexContainer vertices(4);
175 vertices[ 0 ] = MeshData::Vertex( Vector3( -0.5f, -0.5f, 0.0f ), Vector2::ZERO, white );
176 vertices[ 1 ] = MeshData::Vertex( Vector3( 0.5f, -0.5f, 0.0f ), Vector2::ZERO, white );
177 vertices[ 2 ] = MeshData::Vertex( Vector3( -0.5f, 0.5f, 0.0f ), Vector2::ZERO, white );
178 vertices[ 3 ] = MeshData::Vertex( Vector3( 0.5f, 0.5f, 0.0f ), Vector2::ZERO, white );
180 // Specify all the faces
181 MeshData::FaceIndices faces;
182 faces.reserve( 6 ); // 2 triangles in Quad
183 faces.push_back( 0 ); faces.push_back( 3 ); faces.push_back( 1 );
184 faces.push_back( 0 ); faces.push_back( 2 ); faces.push_back( 3 );
186 // Create the mesh data from the vertices and faces
187 meshData.SetMaterial( Material::New( "ControlMaterial" ) );
188 meshData.SetVertices( vertices );
189 meshData.SetFaceIndices( faces );
190 meshData.SetHasColor( true );
192 return Mesh::New( meshData );
196 * Sets all the required properties for the background actor.
198 * @param[in] actor The actor to set the properties on.
199 * @param[in] constrainingIndex The property index to constrain the parent's size on.
200 * @param[in] color The required color of the actor.
202 void SetupBackgroundActor( Actor actor, Property::Index constrainingIndex, const Vector4& color )
204 actor.SetColor( color );
205 actor.SetPositionInheritanceMode( USE_PARENT_POSITION_PLUS_LOCAL_POSITION );
206 actor.SetZ( BACKGROUND_ACTOR_Z_POSITION );
208 Constraint constraint = Constraint::New<Vector3>( constrainingIndex,
209 ParentSource( Actor::SIZE ),
210 EqualToConstraint() );
211 actor.ApplyConstraint( constraint );
214 } // unnamed namespace
216 class ControlImpl::Impl : public ConnectionTrackerInterface
219 // Construction & Destruction
220 Impl(ControlImpl& controlImpl)
221 : mControlImpl(controlImpl),
222 mInitialized( false ),
223 mPinchGestureDetector(),
224 mPanGestureDetector(),
225 mTapGestureDetector(),
226 mLongPressGestureDetector(),
227 mStartingPinchScale(),
228 mLockSetSize( false ),
229 mWidthPolicy( Control::Fixed ),
230 mHeightPolicy( Control::Fixed ),
234 mMaximumSize( MAX_FLOAT_VALUE, MAX_FLOAT_VALUE, MAX_FLOAT_VALUE ),
235 mIsKeyboardNavigationSupported(false),
236 mIsKeyboardFocusGroup(false),
244 // All gesture detectors will be destroyed so no need to disconnect.
251 // Gesture Detection Methods
253 void PinchDetected(Actor actor, PinchGesture pinch)
255 mControlImpl.OnPinch(pinch);
258 void PanDetected(Actor actor, PanGesture pan)
260 mControlImpl.OnPan(pan);
263 void TapDetected(Actor actor, TapGesture tap)
265 mControlImpl.OnTap(tap);
268 void LongPressDetected(Actor actor, LongPressGesture longPress)
270 mControlImpl.OnLongPress(longPress);
274 * @copydoc ConnectionTrackerInterface::SignalConnected
276 virtual void SignalConnected( SlotObserver* slotObserver, CallbackBase* callback )
278 mConnectionTracker.SignalConnected( slotObserver, callback );
282 * @copydoc ConnectionTrackerInterface::SignalDisconnected
284 virtual void SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback )
286 mConnectionTracker.SignalDisconnected( slotObserver, callback );
290 * @copydoc ConnectionTrackerInterface::GetConnectionCount
292 virtual std::size_t GetConnectionCount() const
294 return mConnectionTracker.GetConnectionCount();
297 // Background Methods
300 * Only creates an instance of the background if we actually use it.
301 * @return A reference to the Background structure.
303 Background& GetBackground()
307 mBackground = new Background;
315 * Called when a property of an object of this type is set.
316 * @param[in] object The object whose property is set.
317 * @param[in] index The property index.
318 * @param[in] value The new property value.
320 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
322 Control control = Control::DownCast( BaseHandle( object ) );
326 ControlImpl& controlImpl( control.GetImplementation() );
330 case Control::PROPERTY_BACKGROUND_COLOR:
332 controlImpl.SetBackgroundColor( value.Get< Vector4 >() );
336 case Control::PROPERTY_BACKGROUND:
338 if ( value.HasKey( "image" ) )
340 Property::Map imageMap = value.GetValue( "image" ).Get< Property::Map >();
341 Image image = Scripting::NewImage( imageMap );
345 controlImpl.SetBackground( image );
348 else if ( value.Get< Property::Map >().empty() )
350 // An empty map means the background is no longer required
351 controlImpl.ClearBackground();
360 * Called to retrieve a property of an object of this type.
361 * @param[in] object The object whose property is to be retrieved.
362 * @param[in] index The property index.
363 * @return The current value of the property.
365 static Property::Value GetProperty( BaseObject* object, Property::Index index )
367 Property::Value value;
369 Control control = Control::DownCast( BaseHandle( object ) );
373 ControlImpl& controlImpl( control.GetImplementation() );
377 case Control::PROPERTY_BACKGROUND_COLOR:
379 value = controlImpl.GetBackgroundColor();
383 case Control::PROPERTY_BACKGROUND:
387 Actor actor = controlImpl.GetBackgroundActor();
390 ImageActor imageActor = ImageActor::DownCast( actor );
393 Image image = imageActor.GetImage();
394 Property::Map imageMap;
395 Scripting::CreatePropertyMap( image, imageMap );
396 map.push_back( Property::StringValuePair( "image", imageMap ) );
412 ControlImpl& mControlImpl;
416 ConnectionTracker mConnectionTracker; // signal connection tracker
420 PinchGestureDetector mPinchGestureDetector;
421 PanGestureDetector mPanGestureDetector;
422 TapGestureDetector mTapGestureDetector;
423 LongPressGestureDetector mLongPressGestureDetector;
425 Vector3 mStartingPinchScale; ///< The scale when a pinch gesture starts
427 // Relayout and size negotiation
429 bool mLockSetSize; ///< Used to avoid. Can't be a bitfield as a reference to this member is used in SetSizeLock helper class.
431 Control::SizePolicy mWidthPolicy; ///< Stores the width policy.
432 Control::SizePolicy mHeightPolicy; ///< Stores the height policy.
434 Vector3 mSize; ///< Stores the current control's size.
435 Vector3 mSetSize; ///< Always stores the size set through the Actor's API. Useful when reset to the initial size is needed.
436 Vector3 mMinimumSize; ///< Stores the control's minimum size.
437 Vector3 mMaximumSize; ///< Stores the control's maximum size.
439 bool mIsKeyboardNavigationSupported; ///< Stores whether keyboard navigation is supported by the control.
440 bool mIsKeyboardFocusGroup; ///< Stores whether the control is a focus group.
442 Toolkit::Control::KeyEventSignalV2 mKeyEventSignalV2;
445 Background* mBackground; ///< Only create the background if we use it
447 // Properties - need to be part of this class as ControlImpl::Impl is private
448 static PropertyRegistration PROPERTY_1;
449 static PropertyRegistration PROPERTY_2;
452 PropertyRegistration ControlImpl::Impl::PROPERTY_1( CONTROL_TYPE, "background-color", Control::PROPERTY_BACKGROUND_COLOR, Property::VECTOR4, &ControlImpl::Impl::SetProperty, &ControlImpl::Impl::GetProperty );
453 PropertyRegistration ControlImpl::Impl::PROPERTY_2( CONTROL_TYPE, "background", Control::PROPERTY_BACKGROUND, Property::MAP, &ControlImpl::Impl::SetProperty, &ControlImpl::Impl::GetProperty );
455 Control ControlImpl::New()
457 // Create the implementation, temporarily owned on stack
458 IntrusivePtr<ControlImpl> controlImpl = new ControlImpl( false );
460 // Pass ownership to handle
461 Control handle( *controlImpl );
463 // Second-phase init of the implementation
464 // This can only be done after the CustomActor connection has been made...
465 controlImpl->Initialize();
470 ControlImpl::~ControlImpl()
472 if( mImpl->mInitialized )
474 // Unregister only if control has been initialized.
475 Internal::StyleChangeProcessor::Unregister( this );
480 void ControlImpl::Initialize()
482 // Register with the style change processor so we are informed when the default style changes
483 Internal::StyleChangeProcessor::Register( this );
485 // Calling deriving classes
488 mImpl->mInitialized = true;
491 void ControlImpl::EnableGestureDetection(Gesture::Type type)
493 if ( (type & Gesture::Pinch) && !mImpl->mPinchGestureDetector )
495 mImpl->mPinchGestureDetector = PinchGestureDetector::New();
496 mImpl->mPinchGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PinchDetected);
497 mImpl->mPinchGestureDetector.Attach(Self());
500 if ( (type & Gesture::Pan) && !mImpl->mPanGestureDetector )
502 mImpl->mPanGestureDetector = PanGestureDetector::New();
503 mImpl->mPanGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PanDetected);
504 mImpl->mPanGestureDetector.Attach(Self());
507 if ( (type & Gesture::Tap) && !mImpl->mTapGestureDetector )
509 mImpl->mTapGestureDetector = TapGestureDetector::New();
510 mImpl->mTapGestureDetector.DetectedSignal().Connect(mImpl, &Impl::TapDetected);
511 mImpl->mTapGestureDetector.Attach(Self());
514 if ( (type & Gesture::LongPress) && !mImpl->mLongPressGestureDetector )
516 mImpl->mLongPressGestureDetector = LongPressGestureDetector::New();
517 mImpl->mLongPressGestureDetector.DetectedSignal().Connect(mImpl, &Impl::LongPressDetected);
518 mImpl->mLongPressGestureDetector.Attach(Self());
522 void ControlImpl::DisableGestureDetection(Gesture::Type type)
524 if ( (type & Gesture::Pinch) && mImpl->mPinchGestureDetector )
526 mImpl->mPinchGestureDetector.Detach(Self());
527 mImpl->mPinchGestureDetector.Reset();
530 if ( (type & Gesture::Pan) && mImpl->mPanGestureDetector )
532 mImpl->mPanGestureDetector.Detach(Self());
533 mImpl->mPanGestureDetector.Reset();
536 if ( (type & Gesture::Tap) && mImpl->mTapGestureDetector )
538 mImpl->mTapGestureDetector.Detach(Self());
539 mImpl->mTapGestureDetector.Reset();
542 if ( (type & Gesture::LongPress) && mImpl->mLongPressGestureDetector)
544 mImpl->mLongPressGestureDetector.Detach(Self());
545 mImpl->mLongPressGestureDetector.Reset();
549 PinchGestureDetector ControlImpl::GetPinchGestureDetector() const
551 return mImpl->mPinchGestureDetector;
554 PanGestureDetector ControlImpl::GetPanGestureDetector() const
556 return mImpl->mPanGestureDetector;
559 TapGestureDetector ControlImpl::GetTapGestureDetector() const
561 return mImpl->mTapGestureDetector;
564 LongPressGestureDetector ControlImpl::GetLongPressGestureDetector() const
566 return mImpl->mLongPressGestureDetector;
569 void ControlImpl::SetBackgroundColor( const Vector4& color )
571 Background& background( mImpl->GetBackground() );
573 if ( background.actor )
575 // Just set the actor color
576 background.actor.SetColor( color );
581 MeshActor meshActor = MeshActor::New( CreateMesh() );
583 meshActor.SetAffectedByLighting( false );
584 SetupBackgroundActor( meshActor, Actor::SCALE, color );
586 // Set the background actor before adding so that we do not inform deriving classes
587 background.actor = meshActor;
588 Self().Add( meshActor );
591 background.color = color;
594 Vector4 ControlImpl::GetBackgroundColor() const
596 if ( mImpl->mBackground )
598 return mImpl->mBackground->color;
600 return Color::TRANSPARENT;
603 void ControlImpl::SetBackground( Image image )
605 Background& background( mImpl->GetBackground() );
607 if ( background.actor )
609 // Remove Current actor, unset AFTER removal so that we do not inform deriving classes
610 Self().Remove( background.actor );
611 background.actor = NULL;
614 ImageActor imageActor = ImageActor::New( image );
615 SetupBackgroundActor( imageActor, Actor::SIZE, background.color );
617 // Set the background actor before adding so that we do not inform derived classes
618 background.actor = imageActor;
619 Self().Add( imageActor );
622 void ControlImpl::ClearBackground()
624 if ( mImpl->mBackground )
626 Background& background( mImpl->GetBackground() );
627 Self().Remove( background.actor );
629 delete mImpl->mBackground;
630 mImpl->mBackground = NULL;
634 Actor ControlImpl::GetBackgroundActor() const
636 if ( mImpl->mBackground )
638 return mImpl->mBackground->actor;
644 void ControlImpl::OnPinch(PinchGesture pinch)
646 if (pinch.state == Gesture::Started)
648 mImpl->mStartingPinchScale = Self().GetCurrentScale();
651 Self().SetScale(mImpl->mStartingPinchScale * pinch.scale);
654 void ControlImpl::OnStageConnection()
658 // Notify derived classes.
659 OnControlStageConnection();
662 void ControlImpl::OnStageDisconnection()
664 // Notify derived classes
665 OnControlStageDisconnection();
668 void ControlImpl::OnChildAdd(Actor& child)
670 // If this is the background actor, then we do not want to relayout or inform deriving classes
671 if ( mImpl->mBackground && ( child == mImpl->mBackground->actor ) )
676 // Request for relayout.
679 // Notify derived classes.
680 OnControlChildAdd( child );
683 void ControlImpl::OnChildRemove(Actor& child)
685 // If this is the background actor, then we do not want to relayout or inform deriving classes
686 if ( mImpl->mBackground && ( child == mImpl->mBackground->actor ) )
691 // Request for relayout.
694 // Notify derived classes.
695 OnControlChildRemove( child );
698 void ControlImpl::OnSizeSet(const Vector3& targetSize)
700 if( ( !mImpl->mLockSetSize ) && ( targetSize != mImpl->mSetSize ) )
702 // Only updates size if set through Actor's API
703 mImpl->mSetSize = targetSize;
706 if( targetSize != mImpl->mSize )
708 // Update control size.
709 mImpl->mSize = targetSize;
711 // Notify derived classes.
712 OnControlSizeSet( targetSize );
716 void ControlImpl::OnSizeAnimation(Animation& animation, const Vector3& targetSize)
721 bool ControlImpl::OnTouchEvent(const TouchEvent& event)
723 return false; // Do not consume
726 bool ControlImpl::OnKeyEvent(const KeyEvent& event)
728 return false; // Do not consume
731 bool ControlImpl::OnMouseWheelEvent(const MouseWheelEvent& event)
733 return false; // Do not consume
736 void ControlImpl::OnKeyInputFocusGained()
741 void ControlImpl::OnKeyInputFocusLost()
746 Actor ControlImpl::GetChildByAlias(const std::string& actorAlias)
751 bool ControlImpl::OnAccessibilityPan(PanGesture gesture)
753 return false; // Accessibility pan gesture is not handled by default
756 bool ControlImpl::OnAccessibilityValueChange(bool isIncrease)
758 return false; // Accessibility value change action is not handled by default
762 void ControlImpl::SetKeyboardNavigationSupport(bool isSupported)
764 mImpl->mIsKeyboardNavigationSupported = isSupported;
767 bool ControlImpl::IsKeyboardNavigationSupported()
769 return mImpl->mIsKeyboardNavigationSupported;
772 void ControlImpl::SetAsKeyboardFocusGroup(bool isFocusGroup)
774 mImpl->mIsKeyboardFocusGroup = isFocusGroup;
776 // The following line will be removed when the deprecated API in KeyboardFocusManager is deleted
777 KeyboardFocusManager::Get().SetAsFocusGroup(Self(), isFocusGroup);
780 bool ControlImpl::IsKeyboardFocusGroup()
782 return KeyboardFocusManager::Get().IsFocusGroup(Self());
785 Actor ControlImpl::GetNextKeyboardFocusableActor(Actor currentFocusedActor, Control::KeyboardFocusNavigationDirection direction, bool loopEnabled)
790 bool ControlImpl::DoAction(BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes)
797 void ControlImpl::DoActivatedAction(const PropertyValueContainer& attributes)
802 Toolkit::Control::KeyEventSignalV2& ControlImpl::KeyEventSignal()
804 return mImpl->mKeyEventSignalV2;
807 void ControlImpl::SetSizePolicy( Control::SizePolicy widthPolicy, Control::SizePolicy heightPolicy )
809 bool relayoutRequest( false );
811 if ( ( mImpl->mWidthPolicy != widthPolicy ) || ( mImpl->mHeightPolicy != heightPolicy ) )
813 relayoutRequest = true;
816 mImpl->mWidthPolicy = widthPolicy;
817 mImpl->mHeightPolicy = heightPolicy;
819 // Ensure RelayoutRequest is called AFTER new policies have been set.
820 if ( relayoutRequest )
826 void ControlImpl::GetSizePolicy( Control::SizePolicy& widthPolicy, Control::SizePolicy& heightPolicy ) const
828 widthPolicy = mImpl->mWidthPolicy;
829 heightPolicy = mImpl->mHeightPolicy;
832 void ControlImpl::SetMinimumSize( const Vector3& size )
834 if ( mImpl->mMinimumSize != size )
836 mImpl->mMinimumSize = size;
838 // Only relayout if our control is using the minimum or range policy.
839 if ( ( mImpl->mHeightPolicy == Control::Minimum ) || ( mImpl->mWidthPolicy == Control::Minimum ) ||
840 ( mImpl->mHeightPolicy == Control::Range ) || ( mImpl->mWidthPolicy == Control::Range ) )
847 const Vector3& ControlImpl::GetMinimumSize() const
849 return mImpl->mMinimumSize;
852 void ControlImpl::SetMaximumSize( const Vector3& size )
854 if ( mImpl->mMaximumSize != size )
856 mImpl->mMaximumSize = size;
858 // Only relayout if our control is using the maximum or range policy.
859 if ( ( mImpl->mHeightPolicy == Control::Maximum ) || ( mImpl->mWidthPolicy == Control::Maximum ) ||
860 ( mImpl->mHeightPolicy == Control::Range ) || ( mImpl->mWidthPolicy == Control::Range ) )
867 const Vector3& ControlImpl::GetMaximumSize() const
869 return mImpl->mMaximumSize;
872 Vector3 ControlImpl::GetNaturalSize()
874 // could be overridden in derived classes.
875 return mImpl->mSetSize;
878 float ControlImpl::GetHeightForWidth( float width )
880 // could be overridden in derived classes.
881 float height( 0.0f );
882 if ( mImpl->mSetSize.width > 0.0f )
884 height = mImpl->mSetSize.height * width / mImpl->mSetSize.width;
889 float ControlImpl::GetWidthForHeight( float height )
891 // could be overridden in derived classes.
893 if ( mImpl->mSetSize.height > 0.0f )
895 width = mImpl->mSetSize.width * height / mImpl->mSetSize.height;
900 const Vector3& ControlImpl::GetControlSize() const
905 const Vector3& ControlImpl::GetSizeSet() const
907 return mImpl->mSetSize;
910 void ControlImpl::SetKeyInputFocus()
912 if( Self().OnStage() )
914 KeyInputFocusManager::Get().SetFocus(Control::DownCast(Self()));
918 bool ControlImpl::HasKeyInputFocus()
921 if( Self().OnStage() )
923 result = KeyInputFocusManager::Get().IsKeyboardListener(Control::DownCast(Self()));
928 void ControlImpl::ClearKeyInputFocus()
930 if( Self().OnStage() )
932 KeyInputFocusManager::Get().RemoveFocus(Control::DownCast(Self()));
936 void ControlImpl::RelayoutRequest()
938 Internal::RelayoutController::Get().Request();
941 void ControlImpl::Relayout( Vector2 size, ActorSizeContainer& container )
943 // Avoids relayout again when OnSizeSet callback arrives.
945 SetSizeLock lock( mImpl->mLockSetSize );
946 Self().SetSize( size );
949 // Only relayout controls which requested to be relaid out.
950 OnRelaidOut( size, container );
953 void ControlImpl::Relayout( Actor actor, Vector2 size, ActorSizeContainer& container )
957 Control control( Control::DownCast( actor ) );
960 control.GetImplementation().NegotiateSize( size, container );
964 container.push_back( ActorSizePair( actor, size ) );
969 void ControlImpl::OnRelaidOut( Vector2 size, ActorSizeContainer& container )
971 unsigned int numChildren = Self().GetChildCount();
973 for( unsigned int i=0; i<numChildren; ++i )
975 container.push_back( ActorSizePair( Self().GetChildAt(i), size ) );
979 void ControlImpl::NegotiateSize( Vector2 allocatedSize, ActorSizeContainer& container )
983 if ( mImpl->mWidthPolicy == Control::Fixed )
985 if ( mImpl->mHeightPolicy == Control::Fixed )
987 // If a control says it has a fixed size, then use the size set by the application / control.
988 Vector2 setSize( mImpl->mSetSize );
989 if ( setSize != Vector2::ZERO )
993 // Policy is set to Fixed, so if the application / control has not set one of the dimensions,
994 // then we should use the natural size of the control rather than the full allocation.
995 if ( EqualsZero( size.width ) )
997 size.width = GetWidthForHeight( size.height );
999 else if ( EqualsZero( size.height ) )
1001 size.height = GetHeightForWidth( size.width );
1006 // If that is not set then set the size to the control's natural size
1007 size = Vector2( GetNaturalSize() );
1012 // Width is fixed so if the application / control has set it, then use that.
1013 if ( !EqualsZero( mImpl->mSetSize.width ) )
1015 size.width = mImpl->mSetSize.width;
1019 // Otherwise, set the width to what has been allocated.
1020 size.width = allocatedSize.width;
1023 // Height is flexible so ask control what the height should be for our width.
1024 size.height = GetHeightForWidth( size.width );
1026 // Ensure height is within our policy rules
1027 size.height = Calculate( mImpl->mHeightPolicy, mImpl->mMinimumSize.height, mImpl->mMaximumSize.height, size.height );
1032 if ( mImpl->mHeightPolicy == Control::Fixed )
1034 // Height is fixed so if the application / control has set it, then use that.
1035 if ( !EqualsZero( mImpl->mSetSize.height ) )
1037 size.height = mImpl->mSetSize.height;
1041 // Otherwise, set the height to what has been allocated.
1042 size.height = allocatedSize.height;
1045 // Width is flexible so ask control what the width should be for our height.
1046 size.width = GetWidthForHeight( size.height );
1048 // Ensure width is within our policy rules
1049 size.width = Calculate( mImpl->mWidthPolicy, mImpl->mMinimumSize.width, mImpl->mMaximumSize.width, size.width );
1053 // Width and height are BOTH flexible.
1054 // Calculate the width and height using the policy rules.
1055 size.width = Calculate( mImpl->mWidthPolicy, mImpl->mMinimumSize.width, mImpl->mMaximumSize.width, allocatedSize.width );
1056 size.height = Calculate( mImpl->mHeightPolicy, mImpl->mMinimumSize.height, mImpl->mMaximumSize.height, allocatedSize.height );
1060 // If the width has not been set, then set to the allocated width.
1061 // Also if the width set is greater than the allocated, then set to allocated (no exceed support).
1062 if ( EqualsZero( size.width ) || ( size.width > allocatedSize.width ) )
1064 size.width = allocatedSize.width;
1067 // If the height has not been set, then set to the allocated height.
1068 // Also if the height set is greater than the allocated, then set to allocated (no exceed support).
1069 if ( EqualsZero( size.height ) || ( size.height > allocatedSize.height ) )
1071 size.height = allocatedSize.height;
1074 DALI_LOG_INFO( gLogFilter, Debug::Verbose,
1075 "%p: Natural: [%.2f, %.2f] Allocated: [%.2f, %.2f] Set: [%.2f, %.2f]\n",
1076 Self().GetObjectPtr(),
1077 GetNaturalSize().x, GetNaturalSize().y,
1078 allocatedSize.x, allocatedSize.y,
1081 Relayout( size, container );
1084 bool ControlImpl::EmitKeyEventSignal( const KeyEvent& event )
1086 // Guard against destruction during signal emission
1087 Dali::Toolkit::Control handle( GetOwner() );
1089 bool consumed = false;
1091 // signals are allocated dynamically when someone connects
1092 if ( !mImpl->mKeyEventSignalV2.Empty() )
1094 consumed = mImpl->mKeyEventSignalV2.Emit( handle, event );
1099 // Notification for derived classes
1100 consumed = OnKeyEvent(event);
1106 void ControlImpl::SignalConnected( SlotObserver* slotObserver, CallbackBase* callback )
1108 mImpl->SignalConnected( slotObserver, callback );
1111 void ControlImpl::SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback )
1113 mImpl->SignalDisconnected( slotObserver, callback );
1116 std::size_t ControlImpl::GetConnectionCount() const
1118 return mImpl->GetConnectionCount();
1121 ControlImpl::ControlImpl( bool requiresTouchEvents )
1122 : CustomActorImpl( requiresTouchEvents ),
1123 mImpl(new Impl(*this))
1127 } // namespace Toolkit