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>
21 #include <dali/integration-api/debug.h>
23 #include "dali-toolkit/internal/controls/style-change-processor.h"
24 #include "dali-toolkit/internal/controls/relayout-controller.h"
25 #include "dali-toolkit/internal/controls/relayout-helper.h"
26 #include "dali-toolkit/public-api/focus-manager/keyinput-focus-manager.h"
27 #include "dali-toolkit/public-api/focus-manager/keyboard-focus-manager.h"
28 #include <dali-toolkit/public-api/controls/control.h>
36 const Property::Index Control::PROPERTY_BACKGROUND_COLOR = Internal::Control::CONTROL_PROPERTY_START_INDEX;
37 const Property::Index Control::PROPERTY_BACKGROUND = Internal::Control::CONTROL_PROPERTY_START_INDEX + 1;
38 const Property::Index Control::PROPERTY_WIDTH_POLICY = Internal::Control::CONTROL_PROPERTY_START_INDEX + 2;
39 const Property::Index Control::PROPERTY_HEIGHT_POLICY = Internal::Control::CONTROL_PROPERTY_START_INDEX + 3;
40 const Property::Index Control::PROPERTY_MINIMUM_SIZE = Internal::Control::CONTROL_PROPERTY_START_INDEX + 4;
41 const Property::Index Control::PROPERTY_MAXIMUM_SIZE = Internal::Control::CONTROL_PROPERTY_START_INDEX + 5;
42 const Property::Index Control::PROPERTY_KEY_INPUT_FOCUS = Internal::Control::CONTROL_PROPERTY_START_INDEX + 6;
47 const Scripting::StringEnum< Control::SizePolicy > SIZE_POLICY_STRING_TABLE[] =
49 { "FIXED", Control::Fixed },
50 { "MINIMUM", Control::Minimum },
51 { "MAXIMUM", Control::Maximum },
52 { "RANGE", Control::Range },
53 { "FLEXIBLE", Control::Flexible },
55 const unsigned int SIZE_POLICY_STRING_TABLE_COUNT = sizeof( SIZE_POLICY_STRING_TABLE ) / sizeof( SIZE_POLICY_STRING_TABLE[0] );
57 #if defined(DEBUG_ENABLED)
58 Integration::Log::Filter* gLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_CONTROL");
61 const float MAX_FLOAT_VALUE( std::numeric_limits<float>::max() );
62 const float BACKGROUND_ACTOR_Z_POSITION( -0.1f );
66 return Internal::Control::New();
69 TypeRegistration CONTROL_TYPE( typeid(Control), typeid(CustomActor), Create );
71 // Property Registration after Internal::Control::Impl definition below
73 TypeAction ACTION_TYPE_1(CONTROL_TYPE, Toolkit::Control::ACTION_CONTROL_ACTIVATED, &Internal::Control::DoAction);
76 * Helper class used to set the Control's size through the Actor's API or through children added.
81 SetSizeLock( bool& lock )
97 * Structure which holds information about the background of a control
101 Actor actor; ///< Either a MeshActor or an ImageActor
102 Vector4 color; ///< The color of the actor.
109 color( Color::WHITE )
115 * Helper function to calculate a dimension given the policy of that dimension; the minimum &
116 * maximum values that dimension can be; and the allocated value for that dimension.
118 * @param[in] policy The size policy for that dimension.
119 * @param[in] minimum The minimum value that dimension can be.
120 * @param[in] maximum The maximum value that dimension can be.
121 * @param[in] allocated The value allocated for that dimension.
123 * @return The value that the dimension should be.
125 * @note This does not handle Control::Fixed policy.
127 float Calculate( Control::SizePolicy policy, float minimum, float maximum, float allocated )
129 float size( allocated );
135 // Use allocated value
139 case Control::Minimum:
141 // Size is always at least the minimum.
142 size = std::max( allocated, minimum );
146 case Control::Maximum:
148 // Size can grow but up to a maximum value.
149 size = std::min( allocated, maximum );
155 // Size is at least the minimum and can grow up to the maximum
156 size = std::max( size, minimum );
157 size = std::min( size, maximum );
161 case Control::Flexible:
163 // Size grows or shrinks with no limits.
170 DALI_ASSERT_DEBUG( false && "This function was not intended to be used by any other policy." );
179 * Creates a white coloured Mesh.
183 Vector3 white( Color::WHITE );
187 // Create vertices with a white color (actual color is set by actor color)
188 MeshData::VertexContainer vertices(4);
189 vertices[ 0 ] = MeshData::Vertex( Vector3( -0.5f, -0.5f, 0.0f ), Vector2::ZERO, white );
190 vertices[ 1 ] = MeshData::Vertex( Vector3( 0.5f, -0.5f, 0.0f ), Vector2::ZERO, white );
191 vertices[ 2 ] = MeshData::Vertex( Vector3( -0.5f, 0.5f, 0.0f ), Vector2::ZERO, white );
192 vertices[ 3 ] = MeshData::Vertex( Vector3( 0.5f, 0.5f, 0.0f ), Vector2::ZERO, white );
194 // Specify all the faces
195 MeshData::FaceIndices faces;
196 faces.reserve( 6 ); // 2 triangles in Quad
197 faces.push_back( 0 ); faces.push_back( 3 ); faces.push_back( 1 );
198 faces.push_back( 0 ); faces.push_back( 2 ); faces.push_back( 3 );
200 // Create the mesh data from the vertices and faces
201 meshData.SetMaterial( Material::New( "ControlMaterial" ) );
202 meshData.SetVertices( vertices );
203 meshData.SetFaceIndices( faces );
204 meshData.SetHasColor( true );
206 return Mesh::New( meshData );
210 * Sets all the required properties for the background actor.
212 * @param[in] actor The actor to set the properties on.
213 * @param[in] constrainingIndex The property index to constrain the parent's size on.
214 * @param[in] color The required color of the actor.
216 void SetupBackgroundActor( Actor actor, Property::Index constrainingIndex, const Vector4& color )
218 actor.SetColor( color );
219 actor.SetPositionInheritanceMode( USE_PARENT_POSITION_PLUS_LOCAL_POSITION );
220 actor.SetZ( BACKGROUND_ACTOR_Z_POSITION );
222 Constraint constraint = Constraint::New<Vector3>( constrainingIndex,
223 ParentSource( Actor::SIZE ),
224 EqualToConstraint() );
225 actor.ApplyConstraint( constraint );
228 } // unnamed namespace
233 class Control::Impl : public ConnectionTrackerInterface
236 // Construction & Destruction
237 Impl(Control& controlImpl)
238 : mControlImpl(controlImpl),
239 mInitialized( false ),
240 mPinchGestureDetector(),
241 mPanGestureDetector(),
242 mTapGestureDetector(),
243 mLongPressGestureDetector(),
244 mStartingPinchScale(),
245 mLockSetSize( false ),
246 mWidthPolicy( Toolkit::Control::Fixed ),
247 mHeightPolicy( Toolkit::Control::Fixed ),
251 mMaximumSize( MAX_FLOAT_VALUE, MAX_FLOAT_VALUE, MAX_FLOAT_VALUE ),
252 mIsKeyboardNavigationSupported(false),
253 mIsKeyboardFocusGroup(false),
261 // All gesture detectors will be destroyed so no need to disconnect.
268 // Gesture Detection Methods
270 void PinchDetected(Actor actor, PinchGesture pinch)
272 mControlImpl.OnPinch(pinch);
275 void PanDetected(Actor actor, PanGesture pan)
277 mControlImpl.OnPan(pan);
280 void TapDetected(Actor actor, TapGesture tap)
282 mControlImpl.OnTap(tap);
285 void LongPressDetected(Actor actor, LongPressGesture longPress)
287 mControlImpl.OnLongPress(longPress);
291 * @copydoc ConnectionTrackerInterface::SignalConnected
293 virtual void SignalConnected( SlotObserver* slotObserver, CallbackBase* callback )
295 mConnectionTracker.SignalConnected( slotObserver, callback );
299 * @copydoc ConnectionTrackerInterface::SignalDisconnected
301 virtual void SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback )
303 mConnectionTracker.SignalDisconnected( slotObserver, callback );
307 * @copydoc ConnectionTrackerInterface::GetConnectionCount
309 virtual std::size_t GetConnectionCount() const
311 return mConnectionTracker.GetConnectionCount();
314 // Background Methods
317 * Only creates an instance of the background if we actually use it.
318 * @return A reference to the Background structure.
320 Background& GetBackground()
324 mBackground = new Background;
332 * Called when a property of an object of this type is set.
333 * @param[in] object The object whose property is set.
334 * @param[in] index The property index.
335 * @param[in] value The new property value.
337 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
339 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
343 Control& controlImpl( control.GetImplementation() );
347 case Toolkit::Control::PROPERTY_BACKGROUND_COLOR:
349 controlImpl.SetBackgroundColor( value.Get< Vector4 >() );
353 case Toolkit::Control::PROPERTY_BACKGROUND:
355 if ( value.HasKey( "image" ) )
357 Property::Map imageMap = value.GetValue( "image" ).Get< Property::Map >();
358 Image image = Scripting::NewImage( imageMap );
362 controlImpl.SetBackground( image );
365 else if ( value.Get< Property::Map >().empty() )
367 // An empty map means the background is no longer required
368 controlImpl.ClearBackground();
373 case Toolkit::Control::PROPERTY_WIDTH_POLICY:
375 controlImpl.mImpl->mWidthPolicy = Scripting::GetEnumeration< Toolkit::Control::SizePolicy >( value.Get< std::string >(), SIZE_POLICY_STRING_TABLE, SIZE_POLICY_STRING_TABLE_COUNT );
379 case Toolkit::Control::PROPERTY_HEIGHT_POLICY:
381 controlImpl.mImpl->mHeightPolicy = Scripting::GetEnumeration< Toolkit::Control::SizePolicy >( value.Get< std::string >(), SIZE_POLICY_STRING_TABLE, SIZE_POLICY_STRING_TABLE_COUNT );
385 case Toolkit::Control::PROPERTY_MINIMUM_SIZE:
387 controlImpl.SetMinimumSize( value.Get< Vector3 >() );
391 case Toolkit::Control::PROPERTY_MAXIMUM_SIZE:
393 controlImpl.SetMaximumSize( value.Get< Vector3 >() );
397 case Toolkit::Control::PROPERTY_KEY_INPUT_FOCUS:
399 if ( value.Get< bool >() )
401 controlImpl.SetKeyInputFocus();
405 controlImpl.ClearKeyInputFocus();
414 * Called to retrieve a property of an object of this type.
415 * @param[in] object The object whose property is to be retrieved.
416 * @param[in] index The property index.
417 * @return The current value of the property.
419 static Property::Value GetProperty( BaseObject* object, Property::Index index )
421 Property::Value value;
423 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
427 Control& controlImpl( control.GetImplementation() );
431 case Toolkit::Control::PROPERTY_BACKGROUND_COLOR:
433 value = controlImpl.GetBackgroundColor();
437 case Toolkit::Control::PROPERTY_BACKGROUND:
441 Actor actor = controlImpl.GetBackgroundActor();
444 ImageActor imageActor = ImageActor::DownCast( actor );
447 Image image = imageActor.GetImage();
448 Property::Map imageMap;
449 Scripting::CreatePropertyMap( image, imageMap );
450 map.push_back( Property::StringValuePair( "image", imageMap ) );
458 case Toolkit::Control::PROPERTY_WIDTH_POLICY:
460 value = std::string( Scripting::GetEnumerationName< Toolkit::Control::SizePolicy >( controlImpl.mImpl->mWidthPolicy, SIZE_POLICY_STRING_TABLE, SIZE_POLICY_STRING_TABLE_COUNT ) );
464 case Toolkit::Control::PROPERTY_HEIGHT_POLICY:
466 value = std::string( Scripting::GetEnumerationName< Toolkit::Control::SizePolicy >( controlImpl.mImpl->mHeightPolicy, SIZE_POLICY_STRING_TABLE, SIZE_POLICY_STRING_TABLE_COUNT ) );
470 case Toolkit::Control::PROPERTY_MINIMUM_SIZE:
472 value = controlImpl.mImpl->mMinimumSize;
476 case Toolkit::Control::PROPERTY_MAXIMUM_SIZE:
478 value = controlImpl.mImpl->mMaximumSize;
482 case Toolkit::Control::PROPERTY_KEY_INPUT_FOCUS:
484 value = controlImpl.HasKeyInputFocus();
495 Control& mControlImpl;
499 ConnectionTracker mConnectionTracker; // signal connection tracker
503 PinchGestureDetector mPinchGestureDetector;
504 PanGestureDetector mPanGestureDetector;
505 TapGestureDetector mTapGestureDetector;
506 LongPressGestureDetector mLongPressGestureDetector;
508 Vector3 mStartingPinchScale; ///< The scale when a pinch gesture starts
510 // Relayout and size negotiation
512 bool mLockSetSize; ///< Used to avoid. Can't be a bitfield as a reference to this member is used in SetSizeLock helper class.
514 Toolkit::Control::SizePolicy mWidthPolicy; ///< Stores the width policy.
515 Toolkit::Control::SizePolicy mHeightPolicy; ///< Stores the height policy.
517 Vector3 mSize; ///< Stores the current control's size.
518 Vector3 mSetSize; ///< Always stores the size set through the Actor's API. Useful when reset to the initial size is needed.
519 Vector3 mMinimumSize; ///< Stores the control's minimum size.
520 Vector3 mMaximumSize; ///< Stores the control's maximum size.
522 bool mIsKeyboardNavigationSupported; ///< Stores whether keyboard navigation is supported by the control.
523 bool mIsKeyboardFocusGroup; ///< Stores whether the control is a focus group.
525 Toolkit::Control::KeyEventSignalV2 mKeyEventSignalV2;
528 Background* mBackground; ///< Only create the background if we use it
530 // Properties - these need to be members of Internal::Control::Impl as they need to functions within this class.
531 static PropertyRegistration PROPERTY_1;
532 static PropertyRegistration PROPERTY_2;
533 static PropertyRegistration PROPERTY_3;
534 static PropertyRegistration PROPERTY_4;
535 static PropertyRegistration PROPERTY_5;
536 static PropertyRegistration PROPERTY_6;
537 static PropertyRegistration PROPERTY_7;
540 PropertyRegistration Control::Impl::PROPERTY_1( CONTROL_TYPE, "background-color", Toolkit::Control::PROPERTY_BACKGROUND_COLOR, Property::VECTOR4, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
541 PropertyRegistration Control::Impl::PROPERTY_2( CONTROL_TYPE, "background", Toolkit::Control::PROPERTY_BACKGROUND, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
542 PropertyRegistration Control::Impl::PROPERTY_3( CONTROL_TYPE, "width-policy", Toolkit::Control::PROPERTY_WIDTH_POLICY, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
543 PropertyRegistration Control::Impl::PROPERTY_4( CONTROL_TYPE, "height-policy", Toolkit::Control::PROPERTY_HEIGHT_POLICY, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
544 PropertyRegistration Control::Impl::PROPERTY_5( CONTROL_TYPE, "minimum-size", Toolkit::Control::PROPERTY_MINIMUM_SIZE, Property::VECTOR3, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
545 PropertyRegistration Control::Impl::PROPERTY_6( CONTROL_TYPE, "maximum-size", Toolkit::Control::PROPERTY_MAXIMUM_SIZE, Property::VECTOR3, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
546 PropertyRegistration Control::Impl::PROPERTY_7( CONTROL_TYPE, "key-input-focus", Toolkit::Control::PROPERTY_KEY_INPUT_FOCUS, Property::BOOLEAN, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
548 Toolkit::Control Control::New()
550 // Create the implementation, temporarily owned on stack
551 IntrusivePtr<Control> controlImpl = new Control( false );
553 // Pass ownership to handle
554 Toolkit::Control handle( *controlImpl );
556 // Second-phase init of the implementation
557 // This can only be done after the CustomActor connection has been made...
558 controlImpl->Initialize();
565 if( mImpl->mInitialized )
567 // Unregister only if control has been initialized.
568 Internal::StyleChangeProcessor::Unregister( this );
573 void Control::Initialize()
575 // Register with the style change processor so we are informed when the default style changes
576 Internal::StyleChangeProcessor::Register( this );
578 // Calling deriving classes
581 mImpl->mInitialized = true;
584 void Control::EnableGestureDetection(Gesture::Type type)
586 if ( (type & Gesture::Pinch) && !mImpl->mPinchGestureDetector )
588 mImpl->mPinchGestureDetector = PinchGestureDetector::New();
589 mImpl->mPinchGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PinchDetected);
590 mImpl->mPinchGestureDetector.Attach(Self());
593 if ( (type & Gesture::Pan) && !mImpl->mPanGestureDetector )
595 mImpl->mPanGestureDetector = PanGestureDetector::New();
596 mImpl->mPanGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PanDetected);
597 mImpl->mPanGestureDetector.Attach(Self());
600 if ( (type & Gesture::Tap) && !mImpl->mTapGestureDetector )
602 mImpl->mTapGestureDetector = TapGestureDetector::New();
603 mImpl->mTapGestureDetector.DetectedSignal().Connect(mImpl, &Impl::TapDetected);
604 mImpl->mTapGestureDetector.Attach(Self());
607 if ( (type & Gesture::LongPress) && !mImpl->mLongPressGestureDetector )
609 mImpl->mLongPressGestureDetector = LongPressGestureDetector::New();
610 mImpl->mLongPressGestureDetector.DetectedSignal().Connect(mImpl, &Impl::LongPressDetected);
611 mImpl->mLongPressGestureDetector.Attach(Self());
615 void Control::DisableGestureDetection(Gesture::Type type)
617 if ( (type & Gesture::Pinch) && mImpl->mPinchGestureDetector )
619 mImpl->mPinchGestureDetector.Detach(Self());
620 mImpl->mPinchGestureDetector.Reset();
623 if ( (type & Gesture::Pan) && mImpl->mPanGestureDetector )
625 mImpl->mPanGestureDetector.Detach(Self());
626 mImpl->mPanGestureDetector.Reset();
629 if ( (type & Gesture::Tap) && mImpl->mTapGestureDetector )
631 mImpl->mTapGestureDetector.Detach(Self());
632 mImpl->mTapGestureDetector.Reset();
635 if ( (type & Gesture::LongPress) && mImpl->mLongPressGestureDetector)
637 mImpl->mLongPressGestureDetector.Detach(Self());
638 mImpl->mLongPressGestureDetector.Reset();
642 PinchGestureDetector Control::GetPinchGestureDetector() const
644 return mImpl->mPinchGestureDetector;
647 PanGestureDetector Control::GetPanGestureDetector() const
649 return mImpl->mPanGestureDetector;
652 TapGestureDetector Control::GetTapGestureDetector() const
654 return mImpl->mTapGestureDetector;
657 LongPressGestureDetector Control::GetLongPressGestureDetector() const
659 return mImpl->mLongPressGestureDetector;
662 void Control::SetBackgroundColor( const Vector4& color )
664 Background& background( mImpl->GetBackground() );
666 if ( background.actor )
668 // Just set the actor color
669 background.actor.SetColor( color );
674 MeshActor meshActor = MeshActor::New( CreateMesh() );
676 meshActor.SetAffectedByLighting( false );
677 SetupBackgroundActor( meshActor, Actor::SCALE, color );
679 // Set the background actor before adding so that we do not inform deriving classes
680 background.actor = meshActor;
681 Self().Add( meshActor );
684 background.color = color;
687 Vector4 Control::GetBackgroundColor() const
689 if ( mImpl->mBackground )
691 return mImpl->mBackground->color;
693 return Color::TRANSPARENT;
696 void Control::SetBackground( Image image )
698 Background& background( mImpl->GetBackground() );
700 if ( background.actor )
702 // Remove Current actor, unset AFTER removal so that we do not inform deriving classes
703 Self().Remove( background.actor );
704 background.actor = NULL;
707 ImageActor imageActor = ImageActor::New( image );
708 SetupBackgroundActor( imageActor, Actor::SIZE, background.color );
710 // Set the background actor before adding so that we do not inform derived classes
711 background.actor = imageActor;
712 Self().Add( imageActor );
715 void Control::ClearBackground()
717 if ( mImpl->mBackground )
719 Background& background( mImpl->GetBackground() );
720 Self().Remove( background.actor );
722 delete mImpl->mBackground;
723 mImpl->mBackground = NULL;
727 Actor Control::GetBackgroundActor() const
729 if ( mImpl->mBackground )
731 return mImpl->mBackground->actor;
737 void Control::OnPinch(PinchGesture pinch)
739 if (pinch.state == Gesture::Started)
741 mImpl->mStartingPinchScale = Self().GetCurrentScale();
744 Self().SetScale(mImpl->mStartingPinchScale * pinch.scale);
747 void Control::OnStageConnection()
751 // Notify derived classes.
752 OnControlStageConnection();
755 void Control::OnStageDisconnection()
757 // Notify derived classes
758 OnControlStageDisconnection();
761 void Control::OnChildAdd(Actor& child)
763 // If this is the background actor, then we do not want to relayout or inform deriving classes
764 if ( mImpl->mBackground && ( child == mImpl->mBackground->actor ) )
769 // Request for relayout.
772 // Notify derived classes.
773 OnControlChildAdd( child );
776 void Control::OnChildRemove(Actor& child)
778 // If this is the background actor, then we do not want to relayout or inform deriving classes
779 if ( mImpl->mBackground && ( child == mImpl->mBackground->actor ) )
784 // Request for relayout.
787 // Notify derived classes.
788 OnControlChildRemove( child );
791 void Control::OnSizeSet(const Vector3& targetSize)
793 if( ( !mImpl->mLockSetSize ) && ( targetSize != mImpl->mSetSize ) )
795 // Only updates size if set through Actor's API
796 mImpl->mSetSize = targetSize;
799 if( targetSize != mImpl->mSize )
801 // Update control size.
802 mImpl->mSize = targetSize;
804 // Notify derived classes.
805 OnControlSizeSet( targetSize );
809 void Control::OnSizeAnimation(Animation& animation, const Vector3& targetSize)
814 bool Control::OnTouchEvent(const TouchEvent& event)
816 return false; // Do not consume
819 bool Control::OnKeyEvent(const KeyEvent& event)
821 return false; // Do not consume
824 bool Control::OnMouseWheelEvent(const MouseWheelEvent& event)
826 return false; // Do not consume
829 void Control::OnKeyInputFocusGained()
834 void Control::OnKeyInputFocusLost()
839 Actor Control::GetChildByAlias(const std::string& actorAlias)
844 bool Control::OnAccessibilityPan(PanGesture gesture)
846 return false; // Accessibility pan gesture is not handled by default
849 bool Control::OnAccessibilityValueChange(bool isIncrease)
851 return false; // Accessibility value change action is not handled by default
855 void Control::SetKeyboardNavigationSupport(bool isSupported)
857 mImpl->mIsKeyboardNavigationSupported = isSupported;
860 bool Control::IsKeyboardNavigationSupported()
862 return mImpl->mIsKeyboardNavigationSupported;
865 void Control::SetAsKeyboardFocusGroup(bool isFocusGroup)
867 mImpl->mIsKeyboardFocusGroup = isFocusGroup;
869 // The following line will be removed when the deprecated API in KeyboardFocusManager is deleted
870 Toolkit::KeyboardFocusManager::Get().SetAsFocusGroup(Self(), isFocusGroup);
873 bool Control::IsKeyboardFocusGroup()
875 return Toolkit::KeyboardFocusManager::Get().IsFocusGroup(Self());
878 Actor Control::GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocusNavigationDirection direction, bool loopEnabled)
883 bool Control::DoAction(BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes)
890 void Control::DoActivatedAction(const PropertyValueContainer& attributes)
895 Toolkit::Control::KeyEventSignalV2& Control::KeyEventSignal()
897 return mImpl->mKeyEventSignalV2;
900 void Control::SetSizePolicy( Toolkit::Control::SizePolicy widthPolicy, Toolkit::Control::SizePolicy heightPolicy )
902 bool relayoutRequest( false );
904 if ( ( mImpl->mWidthPolicy != widthPolicy ) || ( mImpl->mHeightPolicy != heightPolicy ) )
906 relayoutRequest = true;
909 mImpl->mWidthPolicy = widthPolicy;
910 mImpl->mHeightPolicy = heightPolicy;
912 // Ensure RelayoutRequest is called AFTER new policies have been set.
913 if ( relayoutRequest )
919 void Control::GetSizePolicy( Toolkit::Control::SizePolicy& widthPolicy, Toolkit::Control::SizePolicy& heightPolicy ) const
921 widthPolicy = mImpl->mWidthPolicy;
922 heightPolicy = mImpl->mHeightPolicy;
925 void Control::SetMinimumSize( const Vector3& size )
927 if ( mImpl->mMinimumSize != size )
929 mImpl->mMinimumSize = size;
931 // Only relayout if our control is using the minimum or range policy.
932 if ( ( mImpl->mHeightPolicy == Toolkit::Control::Minimum ) || ( mImpl->mWidthPolicy == Toolkit::Control::Minimum ) ||
933 ( mImpl->mHeightPolicy == Toolkit::Control::Range ) || ( mImpl->mWidthPolicy == Toolkit::Control::Range ) )
940 const Vector3& Control::GetMinimumSize() const
942 return mImpl->mMinimumSize;
945 void Control::SetMaximumSize( const Vector3& size )
947 if ( mImpl->mMaximumSize != size )
949 mImpl->mMaximumSize = size;
951 // Only relayout if our control is using the maximum or range policy.
952 if ( ( mImpl->mHeightPolicy == Toolkit::Control::Maximum ) || ( mImpl->mWidthPolicy == Toolkit::Control::Maximum ) ||
953 ( mImpl->mHeightPolicy == Toolkit::Control::Range ) || ( mImpl->mWidthPolicy == Toolkit::Control::Range ) )
960 const Vector3& Control::GetMaximumSize() const
962 return mImpl->mMaximumSize;
965 Vector3 Control::GetNaturalSize()
967 // could be overridden in derived classes.
968 return mImpl->mSetSize;
971 float Control::GetHeightForWidth( float width )
973 // could be overridden in derived classes.
974 float height( 0.0f );
975 if ( mImpl->mSetSize.width > 0.0f )
977 height = mImpl->mSetSize.height * width / mImpl->mSetSize.width;
982 float Control::GetWidthForHeight( float height )
984 // could be overridden in derived classes.
986 if ( mImpl->mSetSize.height > 0.0f )
988 width = mImpl->mSetSize.width * height / mImpl->mSetSize.height;
993 const Vector3& Control::GetControlSize() const
998 const Vector3& Control::GetSizeSet() const
1000 return mImpl->mSetSize;
1003 void Control::SetKeyInputFocus()
1005 if( Self().OnStage() )
1007 Toolkit::KeyInputFocusManager::Get().SetFocus(Toolkit::Control::DownCast(Self()));
1011 bool Control::HasKeyInputFocus()
1013 bool result = false;
1014 if( Self().OnStage() )
1016 result = Toolkit::KeyInputFocusManager::Get().IsKeyboardListener(Toolkit::Control::DownCast(Self()));
1021 void Control::ClearKeyInputFocus()
1023 if( Self().OnStage() )
1025 Toolkit::KeyInputFocusManager::Get().RemoveFocus(Toolkit::Control::DownCast(Self()));
1029 void Control::RelayoutRequest()
1031 Internal::RelayoutController::Get().Request();
1034 void Control::Relayout( Vector2 size, ActorSizeContainer& container )
1036 // Avoids relayout again when OnSizeSet callback arrives.
1038 SetSizeLock lock( mImpl->mLockSetSize );
1039 Self().SetSize( size );
1042 // Only relayout controls which requested to be relaid out.
1043 OnRelaidOut( size, container );
1046 void Control::Relayout( Actor actor, Vector2 size, ActorSizeContainer& container )
1050 Toolkit::Control control( Toolkit::Control::DownCast( actor ) );
1053 control.GetImplementation().NegotiateSize( size, container );
1057 container.push_back( ActorSizePair( actor, size ) );
1062 void Control::OnRelaidOut( Vector2 size, ActorSizeContainer& container )
1064 unsigned int numChildren = Self().GetChildCount();
1066 for( unsigned int i=0; i<numChildren; ++i )
1068 container.push_back( ActorSizePair( Self().GetChildAt(i), size ) );
1072 void Control::NegotiateSize( Vector2 allocatedSize, ActorSizeContainer& container )
1076 if ( mImpl->mWidthPolicy == Toolkit::Control::Fixed )
1078 if ( mImpl->mHeightPolicy == Toolkit::Control::Fixed )
1080 // If a control says it has a fixed size, then use the size set by the application / control.
1081 Vector2 setSize( mImpl->mSetSize );
1082 if ( setSize != Vector2::ZERO )
1086 // Policy is set to Fixed, so if the application / control has not set one of the dimensions,
1087 // then we should use the natural size of the control rather than the full allocation.
1088 if ( EqualsZero( size.width ) )
1090 size.width = GetWidthForHeight( size.height );
1092 else if ( EqualsZero( size.height ) )
1094 size.height = GetHeightForWidth( size.width );
1099 // If that is not set then set the size to the control's natural size
1100 size = Vector2( GetNaturalSize() );
1105 // Width is fixed so if the application / control has set it, then use that.
1106 if ( !EqualsZero( mImpl->mSetSize.width ) )
1108 size.width = mImpl->mSetSize.width;
1112 // Otherwise, set the width to what has been allocated.
1113 size.width = allocatedSize.width;
1116 // Height is flexible so ask control what the height should be for our width.
1117 size.height = GetHeightForWidth( size.width );
1119 // Ensure height is within our policy rules
1120 size.height = Calculate( mImpl->mHeightPolicy, mImpl->mMinimumSize.height, mImpl->mMaximumSize.height, size.height );
1125 if ( mImpl->mHeightPolicy == Toolkit::Control::Fixed )
1127 // Height is fixed so if the application / control has set it, then use that.
1128 if ( !EqualsZero( mImpl->mSetSize.height ) )
1130 size.height = mImpl->mSetSize.height;
1134 // Otherwise, set the height to what has been allocated.
1135 size.height = allocatedSize.height;
1138 // Width is flexible so ask control what the width should be for our height.
1139 size.width = GetWidthForHeight( size.height );
1141 // Ensure width is within our policy rules
1142 size.width = Calculate( mImpl->mWidthPolicy, mImpl->mMinimumSize.width, mImpl->mMaximumSize.width, size.width );
1146 // Width and height are BOTH flexible.
1147 // Calculate the width and height using the policy rules.
1148 size.width = Calculate( mImpl->mWidthPolicy, mImpl->mMinimumSize.width, mImpl->mMaximumSize.width, allocatedSize.width );
1149 size.height = Calculate( mImpl->mHeightPolicy, mImpl->mMinimumSize.height, mImpl->mMaximumSize.height, allocatedSize.height );
1153 // If the width has not been set, then set to the allocated width.
1154 // Also if the width set is greater than the allocated, then set to allocated (no exceed support).
1155 if ( EqualsZero( size.width ) || ( size.width > allocatedSize.width ) )
1157 size.width = allocatedSize.width;
1160 // If the height has not been set, then set to the allocated height.
1161 // Also if the height set is greater than the allocated, then set to allocated (no exceed support).
1162 if ( EqualsZero( size.height ) || ( size.height > allocatedSize.height ) )
1164 size.height = allocatedSize.height;
1167 DALI_LOG_INFO( gLogFilter, Debug::Verbose,
1168 "%p: Natural: [%.2f, %.2f] Allocated: [%.2f, %.2f] Set: [%.2f, %.2f]\n",
1169 Self().GetObjectPtr(),
1170 GetNaturalSize().x, GetNaturalSize().y,
1171 allocatedSize.x, allocatedSize.y,
1174 Relayout( size, container );
1177 bool Control::EmitKeyEventSignal( const KeyEvent& event )
1179 // Guard against destruction during signal emission
1180 Dali::Toolkit::Control handle( GetOwner() );
1182 bool consumed = false;
1184 // signals are allocated dynamically when someone connects
1185 if ( !mImpl->mKeyEventSignalV2.Empty() )
1187 consumed = mImpl->mKeyEventSignalV2.Emit( handle, event );
1192 // Notification for derived classes
1193 consumed = OnKeyEvent(event);
1199 void Control::SignalConnected( SlotObserver* slotObserver, CallbackBase* callback )
1201 mImpl->SignalConnected( slotObserver, callback );
1204 void Control::SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback )
1206 mImpl->SignalDisconnected( slotObserver, callback );
1209 std::size_t Control::GetConnectionCount() const
1211 return mImpl->GetConnectionCount();
1214 Control::Control( bool requiresTouchEvents )
1215 : CustomActorImpl( requiresTouchEvents ),
1216 mImpl(new Impl(*this))
1220 } // namespace Internal
1222 } // namespace Toolkit