2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include <dali-toolkit/public-api/controls/control-impl.h>
20 #include <boost/thread/tss.hpp>
23 #include <dali/integration-api/debug.h>
25 #include "dali-toolkit/internal/controls/style-change-processor.h"
26 #include "dali-toolkit/internal/controls/relayout-controller.h"
27 #include "dali-toolkit/internal/controls/relayout-helper.h"
28 #include "dali-toolkit/public-api/focus-manager/keyinput-focus-manager.h"
29 #include "dali-toolkit/public-api/focus-manager/keyboard-focus-manager.h"
30 #include <dali-toolkit/public-api/controls/control.h>
38 const Property::Index Control::PROPERTY_BACKGROUND_COLOR = ControlImpl::CONTROL_PROPERTY_START_INDEX;
39 const Property::Index Control::PROPERTY_BACKGROUND = ControlImpl::CONTROL_PROPERTY_START_INDEX + 1;
44 #if defined(DEBUG_ENABLED)
45 Integration::Log::Filter* gLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_CONTROL");
48 const float MAX_FLOAT_VALUE( std::numeric_limits<float>::max() );
49 const float BACKGROUND_ACTOR_Z_POSITION( -0.1f );
53 return ControlImpl::New();
56 TypeRegistration CONTROL_TYPE( typeid(Control), typeid(CustomActor), Create );
58 // Property Registration after ControlImpl::Impl definition below
60 TypeAction ACTION_TYPE_1(CONTROL_TYPE, Toolkit::Control::ACTION_CONTROL_ACTIVATED, &ControlImpl::DoAction);
63 * Helper class used to set the Control's size through the Actor's API or through children added.
68 SetSizeLock( bool& lock )
84 * Structure which holds information about the background of a control
88 Actor actor; ///< Either a MeshActor or an ImageActor
89 Vector4 color; ///< The color of the actor.
102 * Helper function to calculate a dimension given the policy of that dimension; the minimum &
103 * maximum values that dimension can be; and the allocated value for that dimension.
105 * @param[in] policy The size policy for that dimension.
106 * @param[in] minimum The minimum value that dimension can be.
107 * @param[in] maximum The maximum value that dimension can be.
108 * @param[in] allocated The value allocated for that dimension.
110 * @return The value that the dimension should be.
112 * @note This does not handle Control::Fixed policy.
114 float Calculate( Control::SizePolicy policy, float minimum, float maximum, float allocated )
116 float size( allocated );
122 // Use allocated value
126 case Control::Minimum:
128 // Size is always at least the minimum.
129 size = std::max( allocated, minimum );
133 case Control::Maximum:
135 // Size can grow but up to a maximum value.
136 size = std::min( allocated, maximum );
142 // Size is at least the minimum and can grow up to the maximum
143 size = std::max( size, minimum );
144 size = std::min( size, maximum );
148 case Control::Flexible:
150 // Size grows or shrinks with no limits.
157 DALI_ASSERT_DEBUG( false && "This function was not intended to be used by any other policy." );
166 * Creates a white coloured Mesh.
170 Vector3 white( Color::WHITE );
174 // Create vertices with a white color (actual color is set by actor color)
175 MeshData::VertexContainer vertices(4);
176 vertices[ 0 ] = MeshData::Vertex( Vector3( -0.5f, -0.5f, 0.0f ), Vector2::ZERO, white );
177 vertices[ 1 ] = MeshData::Vertex( Vector3( 0.5f, -0.5f, 0.0f ), Vector2::ZERO, white );
178 vertices[ 2 ] = MeshData::Vertex( Vector3( -0.5f, 0.5f, 0.0f ), Vector2::ZERO, white );
179 vertices[ 3 ] = MeshData::Vertex( Vector3( 0.5f, 0.5f, 0.0f ), Vector2::ZERO, white );
181 // Specify all the faces
182 MeshData::FaceIndices faces;
183 faces.reserve( 6 ); // 2 triangles in Quad
184 faces.push_back( 0 ); faces.push_back( 3 ); faces.push_back( 1 );
185 faces.push_back( 0 ); faces.push_back( 2 ); faces.push_back( 3 );
187 // Create the mesh data from the vertices and faces
188 meshData.SetMaterial( Material::New( "ControlMaterial" ) );
189 meshData.SetVertices( vertices );
190 meshData.SetFaceIndices( faces );
191 meshData.SetHasColor( true );
193 return Mesh::New( meshData );
197 * Sets all the required properties for the background actor.
199 * @param[in] actor The actor to set the properties on.
200 * @param[in] constrainingIndex The property index to constrain the parent's size on.
201 * @param[in] color The required color of the actor.
203 void SetupBackgroundActor( Actor actor, Property::Index constrainingIndex, const Vector4& color )
205 actor.SetColor( color );
206 actor.SetPositionInheritanceMode( USE_PARENT_POSITION_PLUS_LOCAL_POSITION );
207 actor.SetZ( BACKGROUND_ACTOR_Z_POSITION );
209 Constraint constraint = Constraint::New<Vector3>( constrainingIndex,
210 ParentSource( Actor::SIZE ),
211 EqualToConstraint() );
212 actor.ApplyConstraint( constraint );
215 } // unnamed namespace
217 class ControlImpl::Impl : public ConnectionTrackerInterface
220 // Construction & Destruction
221 Impl(ControlImpl& controlImpl)
222 : mControlImpl(controlImpl),
223 mInitialized( false ),
224 mPinchGestureDetector(),
225 mPanGestureDetector(),
226 mTapGestureDetector(),
227 mLongPressGestureDetector(),
228 mStartingPinchScale(),
229 mLockSetSize( false ),
230 mWidthPolicy( Control::Fixed ),
231 mHeightPolicy( Control::Fixed ),
235 mMaximumSize( MAX_FLOAT_VALUE, MAX_FLOAT_VALUE, MAX_FLOAT_VALUE ),
236 mIsKeyboardNavigationSupported(false),
237 mIsKeyboardFocusGroup(false),
245 // All gesture detectors will be destroyed so no need to disconnect.
252 // Gesture Detection Methods
254 void PinchDetected(Actor actor, PinchGesture pinch)
256 mControlImpl.OnPinch(pinch);
259 void PanDetected(Actor actor, PanGesture pan)
261 mControlImpl.OnPan(pan);
264 void TapDetected(Actor actor, TapGesture tap)
266 mControlImpl.OnTap(tap);
269 void LongPressDetected(Actor actor, LongPressGesture longPress)
271 mControlImpl.OnLongPress(longPress);
275 * @copydoc ConnectionTrackerInterface::SignalConnected
277 virtual void SignalConnected( SlotObserver* slotObserver, CallbackBase* callback )
279 mConnectionTracker.SignalConnected( slotObserver, callback );
283 * @copydoc ConnectionTrackerInterface::SignalDisconnected
285 virtual void SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback )
287 mConnectionTracker.SignalDisconnected( slotObserver, callback );
291 * @copydoc ConnectionTrackerInterface::GetConnectionCount
293 virtual std::size_t GetConnectionCount() const
295 return mConnectionTracker.GetConnectionCount();
298 // Background Methods
301 * Only creates an instance of the background if we actually use it.
302 * @return A reference to the Background structure.
304 Background& GetBackground()
308 mBackground = new Background;
316 * Called when a property of an object of this type is set.
317 * @param[in] object The object whose property is set.
318 * @param[in] index The property index.
319 * @param[in] value The new property value.
321 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
323 Control control = Control::DownCast( BaseHandle( object ) );
327 ControlImpl& controlImpl( control.GetImplementation() );
331 case Control::PROPERTY_BACKGROUND_COLOR:
333 controlImpl.SetBackgroundColor( value.Get< Vector4 >() );
337 case Control::PROPERTY_BACKGROUND:
339 if ( value.HasKey( "image" ) )
341 Property::Map imageMap = value.GetValue( "image" ).Get< Property::Map >();
342 Image image = Scripting::NewImage( imageMap );
346 controlImpl.SetBackground( image );
349 else if ( value.Get< Property::Map >().empty() )
351 // An empty map means the background is no longer required
352 controlImpl.ClearBackground();
361 * Called to retrieve a property of an object of this type.
362 * @param[in] object The object whose property is to be retrieved.
363 * @param[in] index The property index.
364 * @return The current value of the property.
366 static Property::Value GetProperty( BaseObject* object, Property::Index index )
368 Property::Value value;
370 Control control = Control::DownCast( BaseHandle( object ) );
374 ControlImpl& controlImpl( control.GetImplementation() );
378 case Control::PROPERTY_BACKGROUND_COLOR:
380 value = controlImpl.GetBackgroundColor();
384 case Control::PROPERTY_BACKGROUND:
388 Actor actor = controlImpl.GetBackgroundActor();
391 ImageActor imageActor = ImageActor::DownCast( actor );
394 Image image = imageActor.GetImage();
395 Property::Map imageMap;
396 Scripting::CreatePropertyMap( image, imageMap );
397 map.push_back( Property::StringValuePair( "image", imageMap ) );
413 ControlImpl& mControlImpl;
417 ConnectionTracker mConnectionTracker; // signal connection tracker
421 PinchGestureDetector mPinchGestureDetector;
422 PanGestureDetector mPanGestureDetector;
423 TapGestureDetector mTapGestureDetector;
424 LongPressGestureDetector mLongPressGestureDetector;
426 Vector3 mStartingPinchScale; ///< The scale when a pinch gesture starts
428 // Relayout and size negotiation
430 bool mLockSetSize; ///< Used to avoid. Can't be a bitfield as a reference to this member is used in SetSizeLock helper class.
432 Control::SizePolicy mWidthPolicy; ///< Stores the width policy.
433 Control::SizePolicy mHeightPolicy; ///< Stores the height policy.
435 Vector3 mSize; ///< Stores the current control's size.
436 Vector3 mSetSize; ///< Always stores the size set through the Actor's API. Useful when reset to the initial size is needed.
437 Vector3 mMinimumSize; ///< Stores the control's minimum size.
438 Vector3 mMaximumSize; ///< Stores the control's maximum size.
440 bool mIsKeyboardNavigationSupported; ///< Stores whether keyboard navigation is supported by the control.
441 bool mIsKeyboardFocusGroup; ///< Stores whether the control is a focus group.
443 Toolkit::Control::KeyEventSignalV2 mKeyEventSignalV2;
446 Background* mBackground; ///< Only create the background if we use it
448 // Properties - need to be part of this class as ControlImpl::Impl is private
449 static PropertyRegistration PROPERTY_1;
450 static PropertyRegistration PROPERTY_2;
453 PropertyRegistration ControlImpl::Impl::PROPERTY_1( CONTROL_TYPE, "background-color", Control::PROPERTY_BACKGROUND_COLOR, Property::VECTOR4, &ControlImpl::Impl::SetProperty, &ControlImpl::Impl::GetProperty );
454 PropertyRegistration ControlImpl::Impl::PROPERTY_2( CONTROL_TYPE, "background", Control::PROPERTY_BACKGROUND, Property::MAP, &ControlImpl::Impl::SetProperty, &ControlImpl::Impl::GetProperty );
456 Control ControlImpl::New()
458 // Create the implementation, temporarily owned on stack
459 IntrusivePtr<ControlImpl> controlImpl = new ControlImpl( false );
461 // Pass ownership to handle
462 Control handle( *controlImpl );
464 // Second-phase init of the implementation
465 // This can only be done after the CustomActor connection has been made...
466 controlImpl->Initialize();
471 ControlImpl::~ControlImpl()
473 if( mImpl->mInitialized )
475 // Unregister only if control has been initialized.
476 Internal::StyleChangeProcessor::Unregister( this );
481 void ControlImpl::Initialize()
483 // Register with the style change processor so we are informed when the default style changes
484 Internal::StyleChangeProcessor::Register( this );
486 // Calling deriving classes
489 mImpl->mInitialized = true;
492 void ControlImpl::EnableGestureDetection(Gesture::Type type)
494 if ( (type & Gesture::Pinch) && !mImpl->mPinchGestureDetector )
496 mImpl->mPinchGestureDetector = PinchGestureDetector::New();
497 mImpl->mPinchGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PinchDetected);
498 mImpl->mPinchGestureDetector.Attach(Self());
501 if ( (type & Gesture::Pan) && !mImpl->mPanGestureDetector )
503 mImpl->mPanGestureDetector = PanGestureDetector::New();
504 mImpl->mPanGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PanDetected);
505 mImpl->mPanGestureDetector.Attach(Self());
508 if ( (type & Gesture::Tap) && !mImpl->mTapGestureDetector )
510 mImpl->mTapGestureDetector = TapGestureDetector::New();
511 mImpl->mTapGestureDetector.DetectedSignal().Connect(mImpl, &Impl::TapDetected);
512 mImpl->mTapGestureDetector.Attach(Self());
515 if ( (type & Gesture::LongPress) && !mImpl->mLongPressGestureDetector )
517 mImpl->mLongPressGestureDetector = LongPressGestureDetector::New();
518 mImpl->mLongPressGestureDetector.DetectedSignal().Connect(mImpl, &Impl::LongPressDetected);
519 mImpl->mLongPressGestureDetector.Attach(Self());
523 void ControlImpl::DisableGestureDetection(Gesture::Type type)
525 if ( (type & Gesture::Pinch) && mImpl->mPinchGestureDetector )
527 mImpl->mPinchGestureDetector.Detach(Self());
528 mImpl->mPinchGestureDetector.Reset();
531 if ( (type & Gesture::Pan) && mImpl->mPanGestureDetector )
533 mImpl->mPanGestureDetector.Detach(Self());
534 mImpl->mPanGestureDetector.Reset();
537 if ( (type & Gesture::Tap) && mImpl->mTapGestureDetector )
539 mImpl->mTapGestureDetector.Detach(Self());
540 mImpl->mTapGestureDetector.Reset();
543 if ( (type & Gesture::LongPress) && mImpl->mLongPressGestureDetector)
545 mImpl->mLongPressGestureDetector.Detach(Self());
546 mImpl->mLongPressGestureDetector.Reset();
550 PinchGestureDetector ControlImpl::GetPinchGestureDetector() const
552 return mImpl->mPinchGestureDetector;
555 PanGestureDetector ControlImpl::GetPanGestureDetector() const
557 return mImpl->mPanGestureDetector;
560 TapGestureDetector ControlImpl::GetTapGestureDetector() const
562 return mImpl->mTapGestureDetector;
565 LongPressGestureDetector ControlImpl::GetLongPressGestureDetector() const
567 return mImpl->mLongPressGestureDetector;
570 void ControlImpl::SetBackgroundColor( const Vector4& color )
572 Background& background( mImpl->GetBackground() );
574 if ( background.actor )
576 // Just set the actor color
577 background.actor.SetColor( color );
582 MeshActor meshActor = MeshActor::New( CreateMesh() );
584 meshActor.SetAffectedByLighting( false );
585 SetupBackgroundActor( meshActor, Actor::SCALE, color );
587 // Set the background actor before adding so that we do not inform deriving classes
588 background.actor = meshActor;
589 Self().Add( meshActor );
592 background.color = color;
595 Vector4 ControlImpl::GetBackgroundColor() const
597 if ( mImpl->mBackground )
599 return mImpl->mBackground->color;
601 return Color::TRANSPARENT;
604 void ControlImpl::SetBackground( Image image )
606 Background& background( mImpl->GetBackground() );
608 if ( background.actor )
610 // Remove Current actor, unset AFTER removal so that we do not inform deriving classes
611 Self().Remove( background.actor );
612 background.actor = NULL;
615 ImageActor imageActor = ImageActor::New( image );
616 SetupBackgroundActor( imageActor, Actor::SIZE, background.color );
618 // Set the background actor before adding so that we do not inform derived classes
619 background.actor = imageActor;
620 Self().Add( imageActor );
623 void ControlImpl::ClearBackground()
625 if ( mImpl->mBackground )
627 Background& background( mImpl->GetBackground() );
628 Self().Remove( background.actor );
630 delete mImpl->mBackground;
631 mImpl->mBackground = NULL;
635 Actor ControlImpl::GetBackgroundActor() const
637 if ( mImpl->mBackground )
639 return mImpl->mBackground->actor;
645 void ControlImpl::OnPinch(PinchGesture pinch)
647 if (pinch.state == Gesture::Started)
649 mImpl->mStartingPinchScale = Self().GetCurrentScale();
652 Self().SetScale(mImpl->mStartingPinchScale * pinch.scale);
655 void ControlImpl::OnStageConnection()
659 // Notify derived classes.
660 OnControlStageConnection();
663 void ControlImpl::OnStageDisconnection()
665 // Notify derived classes
666 OnControlStageDisconnection();
669 void ControlImpl::OnChildAdd(Actor& child)
671 // If this is the background actor, then we do not want to relayout or inform deriving classes
672 if ( mImpl->mBackground && ( child == mImpl->mBackground->actor ) )
677 // Request for relayout.
680 // Notify derived classes.
681 OnControlChildAdd( child );
684 void ControlImpl::OnChildRemove(Actor& child)
686 // If this is the background actor, then we do not want to relayout or inform deriving classes
687 if ( mImpl->mBackground && ( child == mImpl->mBackground->actor ) )
692 // Request for relayout.
695 // Notify derived classes.
696 OnControlChildRemove( child );
699 void ControlImpl::OnSizeSet(const Vector3& targetSize)
701 if( ( !mImpl->mLockSetSize ) && ( targetSize != mImpl->mSetSize ) )
703 // Only updates size if set through Actor's API
704 mImpl->mSetSize = targetSize;
707 if( targetSize != mImpl->mSize )
709 // Update control size.
710 mImpl->mSize = targetSize;
712 // Notify derived classes.
713 OnControlSizeSet( targetSize );
717 void ControlImpl::OnSizeAnimation(Animation& animation, const Vector3& targetSize)
722 bool ControlImpl::OnTouchEvent(const TouchEvent& event)
724 return false; // Do not consume
727 bool ControlImpl::OnKeyEvent(const KeyEvent& event)
729 return false; // Do not consume
732 bool ControlImpl::OnMouseWheelEvent(const MouseWheelEvent& event)
734 return false; // Do not consume
737 void ControlImpl::OnKeyInputFocusGained()
742 void ControlImpl::OnKeyInputFocusLost()
747 Actor ControlImpl::GetChildByAlias(const std::string& actorAlias)
752 bool ControlImpl::OnAccessibilityPan(PanGesture gesture)
754 return false; // Accessibility pan gesture is not handled by default
757 bool ControlImpl::OnAccessibilityValueChange(bool isIncrease)
759 return false; // Accessibility value change action is not handled by default
763 void ControlImpl::SetKeyboardNavigationSupport(bool isSupported)
765 mImpl->mIsKeyboardNavigationSupported = isSupported;
768 bool ControlImpl::IsKeyboardNavigationSupported()
770 return mImpl->mIsKeyboardNavigationSupported;
773 void ControlImpl::SetAsKeyboardFocusGroup(bool isFocusGroup)
775 mImpl->mIsKeyboardFocusGroup = isFocusGroup;
777 // The following line will be removed when the deprecated API in KeyboardFocusManager is deleted
778 KeyboardFocusManager::Get().SetAsFocusGroup(Self(), isFocusGroup);
781 bool ControlImpl::IsKeyboardFocusGroup()
783 return KeyboardFocusManager::Get().IsFocusGroup(Self());
786 Actor ControlImpl::GetNextKeyboardFocusableActor(Actor currentFocusedActor, Control::KeyboardFocusNavigationDirection direction, bool loopEnabled)
791 bool ControlImpl::DoAction(BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes)
798 void ControlImpl::DoActivatedAction(const PropertyValueContainer& attributes)
803 Toolkit::Control::KeyEventSignalV2& ControlImpl::KeyEventSignal()
805 return mImpl->mKeyEventSignalV2;
808 void ControlImpl::SetSizePolicy( Control::SizePolicy widthPolicy, Control::SizePolicy heightPolicy )
810 bool relayoutRequest( false );
812 if ( ( mImpl->mWidthPolicy != widthPolicy ) || ( mImpl->mHeightPolicy != heightPolicy ) )
814 relayoutRequest = true;
817 mImpl->mWidthPolicy = widthPolicy;
818 mImpl->mHeightPolicy = heightPolicy;
820 // Ensure RelayoutRequest is called AFTER new policies have been set.
821 if ( relayoutRequest )
827 void ControlImpl::GetSizePolicy( Control::SizePolicy& widthPolicy, Control::SizePolicy& heightPolicy ) const
829 widthPolicy = mImpl->mWidthPolicy;
830 heightPolicy = mImpl->mHeightPolicy;
833 void ControlImpl::SetMinimumSize( const Vector3& size )
835 if ( mImpl->mMinimumSize != size )
837 mImpl->mMinimumSize = size;
839 // Only relayout if our control is using the minimum or range policy.
840 if ( ( mImpl->mHeightPolicy == Control::Minimum ) || ( mImpl->mWidthPolicy == Control::Minimum ) ||
841 ( mImpl->mHeightPolicy == Control::Range ) || ( mImpl->mWidthPolicy == Control::Range ) )
848 const Vector3& ControlImpl::GetMinimumSize() const
850 return mImpl->mMinimumSize;
853 void ControlImpl::SetMaximumSize( const Vector3& size )
855 if ( mImpl->mMaximumSize != size )
857 mImpl->mMaximumSize = size;
859 // Only relayout if our control is using the maximum or range policy.
860 if ( ( mImpl->mHeightPolicy == Control::Maximum ) || ( mImpl->mWidthPolicy == Control::Maximum ) ||
861 ( mImpl->mHeightPolicy == Control::Range ) || ( mImpl->mWidthPolicy == Control::Range ) )
868 const Vector3& ControlImpl::GetMaximumSize() const
870 return mImpl->mMaximumSize;
873 Vector3 ControlImpl::GetNaturalSize()
875 // could be overridden in derived classes.
876 return mImpl->mSetSize;
879 float ControlImpl::GetHeightForWidth( float width )
881 // could be overridden in derived classes.
882 float height( 0.0f );
883 if ( mImpl->mSetSize.width > 0.0f )
885 height = mImpl->mSetSize.height * width / mImpl->mSetSize.width;
890 float ControlImpl::GetWidthForHeight( float height )
892 // could be overridden in derived classes.
894 if ( mImpl->mSetSize.height > 0.0f )
896 width = mImpl->mSetSize.width * height / mImpl->mSetSize.height;
901 const Vector3& ControlImpl::GetControlSize() const
906 const Vector3& ControlImpl::GetSizeSet() const
908 return mImpl->mSetSize;
911 void ControlImpl::SetKeyInputFocus()
913 if( Self().OnStage() )
915 KeyInputFocusManager::Get().SetFocus(Control::DownCast(Self()));
919 bool ControlImpl::HasKeyInputFocus()
922 if( Self().OnStage() )
924 result = KeyInputFocusManager::Get().IsKeyboardListener(Control::DownCast(Self()));
929 void ControlImpl::ClearKeyInputFocus()
931 if( Self().OnStage() )
933 KeyInputFocusManager::Get().RemoveFocus(Control::DownCast(Self()));
937 void ControlImpl::RelayoutRequest()
939 Internal::RelayoutController::Get().Request();
942 void ControlImpl::Relayout( Vector2 size, ActorSizeContainer& container )
944 // Avoids relayout again when OnSizeSet callback arrives.
946 SetSizeLock lock( mImpl->mLockSetSize );
947 Self().SetSize( size );
950 // Only relayout controls which requested to be relaid out.
951 OnRelaidOut( size, container );
954 void ControlImpl::Relayout( Actor actor, Vector2 size, ActorSizeContainer& container )
958 Control control( Control::DownCast( actor ) );
961 control.GetImplementation().NegotiateSize( size, container );
965 container.push_back( ActorSizePair( actor, size ) );
970 void ControlImpl::OnRelaidOut( Vector2 size, ActorSizeContainer& container )
972 unsigned int numChildren = Self().GetChildCount();
974 for( unsigned int i=0; i<numChildren; ++i )
976 container.push_back( ActorSizePair( Self().GetChildAt(i), size ) );
980 void ControlImpl::NegotiateSize( Vector2 allocatedSize, ActorSizeContainer& container )
984 if ( mImpl->mWidthPolicy == Control::Fixed )
986 if ( mImpl->mHeightPolicy == Control::Fixed )
988 // If a control says it has a fixed size, then use the size set by the application / control.
989 Vector2 setSize( mImpl->mSetSize );
990 if ( setSize != Vector2::ZERO )
994 // Policy is set to Fixed, so if the application / control has not set one of the dimensions,
995 // then we should use the natural size of the control rather than the full allocation.
996 if ( EqualsZero( size.width ) )
998 size.width = GetWidthForHeight( size.height );
1000 else if ( EqualsZero( size.height ) )
1002 size.height = GetHeightForWidth( size.width );
1007 // If that is not set then set the size to the control's natural size
1008 size = Vector2( GetNaturalSize() );
1013 // Width is fixed so if the application / control has set it, then use that.
1014 if ( !EqualsZero( mImpl->mSetSize.width ) )
1016 size.width = mImpl->mSetSize.width;
1020 // Otherwise, set the width to what has been allocated.
1021 size.width = allocatedSize.width;
1024 // Height is flexible so ask control what the height should be for our width.
1025 size.height = GetHeightForWidth( size.width );
1027 // Ensure height is within our policy rules
1028 size.height = Calculate( mImpl->mHeightPolicy, mImpl->mMinimumSize.height, mImpl->mMaximumSize.height, size.height );
1033 if ( mImpl->mHeightPolicy == Control::Fixed )
1035 // Height is fixed so if the application / control has set it, then use that.
1036 if ( !EqualsZero( mImpl->mSetSize.height ) )
1038 size.height = mImpl->mSetSize.height;
1042 // Otherwise, set the height to what has been allocated.
1043 size.height = allocatedSize.height;
1046 // Width is flexible so ask control what the width should be for our height.
1047 size.width = GetWidthForHeight( size.height );
1049 // Ensure width is within our policy rules
1050 size.width = Calculate( mImpl->mWidthPolicy, mImpl->mMinimumSize.width, mImpl->mMaximumSize.width, size.width );
1054 // Width and height are BOTH flexible.
1055 // Calculate the width and height using the policy rules.
1056 size.width = Calculate( mImpl->mWidthPolicy, mImpl->mMinimumSize.width, mImpl->mMaximumSize.width, allocatedSize.width );
1057 size.height = Calculate( mImpl->mHeightPolicy, mImpl->mMinimumSize.height, mImpl->mMaximumSize.height, allocatedSize.height );
1061 // If the width has not been set, then set to the allocated width.
1062 // Also if the width set is greater than the allocated, then set to allocated (no exceed support).
1063 if ( EqualsZero( size.width ) || ( size.width > allocatedSize.width ) )
1065 size.width = allocatedSize.width;
1068 // If the height has not been set, then set to the allocated height.
1069 // Also if the height set is greater than the allocated, then set to allocated (no exceed support).
1070 if ( EqualsZero( size.height ) || ( size.height > allocatedSize.height ) )
1072 size.height = allocatedSize.height;
1075 DALI_LOG_INFO( gLogFilter, Debug::Verbose,
1076 "%p: Natural: [%.2f, %.2f] Allocated: [%.2f, %.2f] Set: [%.2f, %.2f]\n",
1077 Self().GetObjectPtr(),
1078 GetNaturalSize().x, GetNaturalSize().y,
1079 allocatedSize.x, allocatedSize.y,
1082 Relayout( size, container );
1085 bool ControlImpl::EmitKeyEventSignal( const KeyEvent& event )
1087 // Guard against destruction during signal emission
1088 Dali::Toolkit::Control handle( GetOwner() );
1090 bool consumed = false;
1092 // signals are allocated dynamically when someone connects
1093 if ( !mImpl->mKeyEventSignalV2.Empty() )
1095 consumed = mImpl->mKeyEventSignalV2.Emit( handle, event );
1100 // Notification for derived classes
1101 consumed = OnKeyEvent(event);
1107 void ControlImpl::SignalConnected( SlotObserver* slotObserver, CallbackBase* callback )
1109 mImpl->SignalConnected( slotObserver, callback );
1112 void ControlImpl::SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback )
1114 mImpl->SignalDisconnected( slotObserver, callback );
1117 std::size_t ControlImpl::GetConnectionCount() const
1119 return mImpl->GetConnectionCount();
1122 ControlImpl::ControlImpl( bool requiresTouchEvents )
1123 : CustomActorImpl( requiresTouchEvents ),
1124 mImpl(new Impl(*this))
1128 } // namespace Toolkit