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 = Internal::Control::CONTROL_PROPERTY_START_INDEX;
38 const Property::Index Control::PROPERTY_BACKGROUND = Internal::Control::CONTROL_PROPERTY_START_INDEX + 1;
39 const Property::Index Control::PROPERTY_WIDTH_POLICY = Internal::Control::CONTROL_PROPERTY_START_INDEX + 2;
40 const Property::Index Control::PROPERTY_HEIGHT_POLICY = Internal::Control::CONTROL_PROPERTY_START_INDEX + 3;
41 const Property::Index Control::PROPERTY_MINIMUM_SIZE = Internal::Control::CONTROL_PROPERTY_START_INDEX + 4;
42 const Property::Index Control::PROPERTY_MAXIMUM_SIZE = Internal::Control::CONTROL_PROPERTY_START_INDEX + 5;
43 const Property::Index Control::PROPERTY_KEY_INPUT_FOCUS = Internal::Control::CONTROL_PROPERTY_START_INDEX + 6;
48 const Scripting::StringEnum< Control::SizePolicy > SIZE_POLICY_STRING_TABLE[] =
50 { "FIXED", Control::Fixed },
51 { "MINIMUM", Control::Minimum },
52 { "MAXIMUM", Control::Maximum },
53 { "RANGE", Control::Range },
54 { "FLEXIBLE", Control::Flexible },
56 const unsigned int SIZE_POLICY_STRING_TABLE_COUNT = sizeof( SIZE_POLICY_STRING_TABLE ) / sizeof( SIZE_POLICY_STRING_TABLE[0] );
58 #if defined(DEBUG_ENABLED)
59 Integration::Log::Filter* gLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_CONTROL");
62 const float MAX_FLOAT_VALUE( std::numeric_limits<float>::max() );
63 const float BACKGROUND_ACTOR_Z_POSITION( -0.1f );
67 return Internal::Control::New();
70 TypeRegistration CONTROL_TYPE( typeid(Control), typeid(CustomActor), Create );
72 // Property Registration after Internal::Control::Impl definition below
74 TypeAction ACTION_TYPE_1(CONTROL_TYPE, Toolkit::Control::ACTION_CONTROL_ACTIVATED, &Internal::Control::DoAction);
77 * Helper class used to set the Control's size through the Actor's API or through children added.
82 SetSizeLock( bool& lock )
98 * Structure which holds information about the background of a control
102 Actor actor; ///< Either a MeshActor or an ImageActor
103 Vector4 color; ///< The color of the actor.
110 color( Color::WHITE )
116 * Helper function to calculate a dimension given the policy of that dimension; the minimum &
117 * maximum values that dimension can be; and the allocated value for that dimension.
119 * @param[in] policy The size policy for that dimension.
120 * @param[in] minimum The minimum value that dimension can be.
121 * @param[in] maximum The maximum value that dimension can be.
122 * @param[in] allocated The value allocated for that dimension.
124 * @return The value that the dimension should be.
126 * @note This does not handle Control::Fixed policy.
128 float Calculate( Control::SizePolicy policy, float minimum, float maximum, float allocated )
130 float size( allocated );
136 // Use allocated value
140 case Control::Minimum:
142 // Size is always at least the minimum.
143 size = std::max( allocated, minimum );
147 case Control::Maximum:
149 // Size can grow but up to a maximum value.
150 size = std::min( allocated, maximum );
156 // Size is at least the minimum and can grow up to the maximum
157 size = std::max( size, minimum );
158 size = std::min( size, maximum );
162 case Control::Flexible:
164 // Size grows or shrinks with no limits.
171 DALI_ASSERT_DEBUG( false && "This function was not intended to be used by any other policy." );
180 * Creates a white coloured Mesh.
184 Vector3 white( Color::WHITE );
188 // Create vertices with a white color (actual color is set by actor color)
189 MeshData::VertexContainer vertices(4);
190 vertices[ 0 ] = MeshData::Vertex( Vector3( -0.5f, -0.5f, 0.0f ), Vector2::ZERO, white );
191 vertices[ 1 ] = MeshData::Vertex( Vector3( 0.5f, -0.5f, 0.0f ), Vector2::ZERO, white );
192 vertices[ 2 ] = MeshData::Vertex( Vector3( -0.5f, 0.5f, 0.0f ), Vector2::ZERO, white );
193 vertices[ 3 ] = MeshData::Vertex( Vector3( 0.5f, 0.5f, 0.0f ), Vector2::ZERO, white );
195 // Specify all the faces
196 MeshData::FaceIndices faces;
197 faces.reserve( 6 ); // 2 triangles in Quad
198 faces.push_back( 0 ); faces.push_back( 3 ); faces.push_back( 1 );
199 faces.push_back( 0 ); faces.push_back( 2 ); faces.push_back( 3 );
201 // Create the mesh data from the vertices and faces
202 meshData.SetMaterial( Material::New( "ControlMaterial" ) );
203 meshData.SetVertices( vertices );
204 meshData.SetFaceIndices( faces );
205 meshData.SetHasColor( true );
207 return Mesh::New( meshData );
211 * Sets all the required properties for the background actor.
213 * @param[in] actor The actor to set the properties on.
214 * @param[in] constrainingIndex The property index to constrain the parent's size on.
215 * @param[in] color The required color of the actor.
217 void SetupBackgroundActor( Actor actor, Property::Index constrainingIndex, const Vector4& color )
219 actor.SetColor( color );
220 actor.SetPositionInheritanceMode( USE_PARENT_POSITION_PLUS_LOCAL_POSITION );
221 actor.SetZ( BACKGROUND_ACTOR_Z_POSITION );
223 Constraint constraint = Constraint::New<Vector3>( constrainingIndex,
224 ParentSource( Actor::SIZE ),
225 EqualToConstraint() );
226 actor.ApplyConstraint( constraint );
229 } // unnamed namespace
234 class Control::Impl : public ConnectionTrackerInterface
237 // Construction & Destruction
238 Impl(Control& controlImpl)
239 : mControlImpl(controlImpl),
240 mInitialized( false ),
241 mPinchGestureDetector(),
242 mPanGestureDetector(),
243 mTapGestureDetector(),
244 mLongPressGestureDetector(),
245 mStartingPinchScale(),
246 mLockSetSize( false ),
247 mWidthPolicy( Toolkit::Control::Fixed ),
248 mHeightPolicy( Toolkit::Control::Fixed ),
252 mMaximumSize( MAX_FLOAT_VALUE, MAX_FLOAT_VALUE, MAX_FLOAT_VALUE ),
253 mIsKeyboardNavigationSupported(false),
254 mIsKeyboardFocusGroup(false),
262 // All gesture detectors will be destroyed so no need to disconnect.
269 // Gesture Detection Methods
271 void PinchDetected(Actor actor, PinchGesture pinch)
273 mControlImpl.OnPinch(pinch);
276 void PanDetected(Actor actor, PanGesture pan)
278 mControlImpl.OnPan(pan);
281 void TapDetected(Actor actor, TapGesture tap)
283 mControlImpl.OnTap(tap);
286 void LongPressDetected(Actor actor, LongPressGesture longPress)
288 mControlImpl.OnLongPress(longPress);
292 * @copydoc ConnectionTrackerInterface::SignalConnected
294 virtual void SignalConnected( SlotObserver* slotObserver, CallbackBase* callback )
296 mConnectionTracker.SignalConnected( slotObserver, callback );
300 * @copydoc ConnectionTrackerInterface::SignalDisconnected
302 virtual void SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback )
304 mConnectionTracker.SignalDisconnected( slotObserver, callback );
308 * @copydoc ConnectionTrackerInterface::GetConnectionCount
310 virtual std::size_t GetConnectionCount() const
312 return mConnectionTracker.GetConnectionCount();
315 // Background Methods
318 * Only creates an instance of the background if we actually use it.
319 * @return A reference to the Background structure.
321 Background& GetBackground()
325 mBackground = new Background;
333 * Called when a property of an object of this type is set.
334 * @param[in] object The object whose property is set.
335 * @param[in] index The property index.
336 * @param[in] value The new property value.
338 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
340 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
344 Control& controlImpl( control.GetImplementation() );
348 case Toolkit::Control::PROPERTY_BACKGROUND_COLOR:
350 controlImpl.SetBackgroundColor( value.Get< Vector4 >() );
354 case Toolkit::Control::PROPERTY_BACKGROUND:
356 if ( value.HasKey( "image" ) )
358 Property::Map imageMap = value.GetValue( "image" ).Get< Property::Map >();
359 Image image = Scripting::NewImage( imageMap );
363 controlImpl.SetBackground( image );
366 else if ( value.Get< Property::Map >().empty() )
368 // An empty map means the background is no longer required
369 controlImpl.ClearBackground();
374 case Toolkit::Control::PROPERTY_WIDTH_POLICY:
376 controlImpl.mImpl->mWidthPolicy = Scripting::GetEnumeration< Toolkit::Control::SizePolicy >( value.Get< std::string >(), SIZE_POLICY_STRING_TABLE, SIZE_POLICY_STRING_TABLE_COUNT );
380 case Toolkit::Control::PROPERTY_HEIGHT_POLICY:
382 controlImpl.mImpl->mHeightPolicy = Scripting::GetEnumeration< Toolkit::Control::SizePolicy >( value.Get< std::string >(), SIZE_POLICY_STRING_TABLE, SIZE_POLICY_STRING_TABLE_COUNT );
386 case Toolkit::Control::PROPERTY_MINIMUM_SIZE:
388 controlImpl.SetMinimumSize( value.Get< Vector3 >() );
392 case Toolkit::Control::PROPERTY_MAXIMUM_SIZE:
394 controlImpl.SetMaximumSize( value.Get< Vector3 >() );
398 case Toolkit::Control::PROPERTY_KEY_INPUT_FOCUS:
400 if ( value.Get< bool >() )
402 controlImpl.SetKeyInputFocus();
406 controlImpl.ClearKeyInputFocus();
415 * Called to retrieve a property of an object of this type.
416 * @param[in] object The object whose property is to be retrieved.
417 * @param[in] index The property index.
418 * @return The current value of the property.
420 static Property::Value GetProperty( BaseObject* object, Property::Index index )
422 Property::Value value;
424 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
428 Control& controlImpl( control.GetImplementation() );
432 case Toolkit::Control::PROPERTY_BACKGROUND_COLOR:
434 value = controlImpl.GetBackgroundColor();
438 case Toolkit::Control::PROPERTY_BACKGROUND:
442 Actor actor = controlImpl.GetBackgroundActor();
445 ImageActor imageActor = ImageActor::DownCast( actor );
448 Image image = imageActor.GetImage();
449 Property::Map imageMap;
450 Scripting::CreatePropertyMap( image, imageMap );
451 map.push_back( Property::StringValuePair( "image", imageMap ) );
459 case Toolkit::Control::PROPERTY_WIDTH_POLICY:
461 value = std::string( Scripting::GetEnumerationName< Toolkit::Control::SizePolicy >( controlImpl.mImpl->mWidthPolicy, SIZE_POLICY_STRING_TABLE, SIZE_POLICY_STRING_TABLE_COUNT ) );
465 case Toolkit::Control::PROPERTY_HEIGHT_POLICY:
467 value = std::string( Scripting::GetEnumerationName< Toolkit::Control::SizePolicy >( controlImpl.mImpl->mHeightPolicy, SIZE_POLICY_STRING_TABLE, SIZE_POLICY_STRING_TABLE_COUNT ) );
471 case Toolkit::Control::PROPERTY_MINIMUM_SIZE:
473 value = controlImpl.mImpl->mMinimumSize;
477 case Toolkit::Control::PROPERTY_MAXIMUM_SIZE:
479 value = controlImpl.mImpl->mMaximumSize;
483 case Toolkit::Control::PROPERTY_KEY_INPUT_FOCUS:
485 value = controlImpl.HasKeyInputFocus();
496 Control& mControlImpl;
500 ConnectionTracker mConnectionTracker; // signal connection tracker
504 PinchGestureDetector mPinchGestureDetector;
505 PanGestureDetector mPanGestureDetector;
506 TapGestureDetector mTapGestureDetector;
507 LongPressGestureDetector mLongPressGestureDetector;
509 Vector3 mStartingPinchScale; ///< The scale when a pinch gesture starts
511 // Relayout and size negotiation
513 bool mLockSetSize; ///< Used to avoid. Can't be a bitfield as a reference to this member is used in SetSizeLock helper class.
515 Toolkit::Control::SizePolicy mWidthPolicy; ///< Stores the width policy.
516 Toolkit::Control::SizePolicy mHeightPolicy; ///< Stores the height policy.
518 Vector3 mSize; ///< Stores the current control's size.
519 Vector3 mSetSize; ///< Always stores the size set through the Actor's API. Useful when reset to the initial size is needed.
520 Vector3 mMinimumSize; ///< Stores the control's minimum size.
521 Vector3 mMaximumSize; ///< Stores the control's maximum size.
523 bool mIsKeyboardNavigationSupported; ///< Stores whether keyboard navigation is supported by the control.
524 bool mIsKeyboardFocusGroup; ///< Stores whether the control is a focus group.
526 Toolkit::Control::KeyEventSignalV2 mKeyEventSignalV2;
529 Background* mBackground; ///< Only create the background if we use it
531 // Properties - these need to be members of Internal::Control::Impl as they need to functions within this class.
532 static PropertyRegistration PROPERTY_1;
533 static PropertyRegistration PROPERTY_2;
534 static PropertyRegistration PROPERTY_3;
535 static PropertyRegistration PROPERTY_4;
536 static PropertyRegistration PROPERTY_5;
537 static PropertyRegistration PROPERTY_6;
538 static PropertyRegistration PROPERTY_7;
541 PropertyRegistration Control::Impl::PROPERTY_1( CONTROL_TYPE, "background-color", Toolkit::Control::PROPERTY_BACKGROUND_COLOR, Property::VECTOR4, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
542 PropertyRegistration Control::Impl::PROPERTY_2( CONTROL_TYPE, "background", Toolkit::Control::PROPERTY_BACKGROUND, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
543 PropertyRegistration Control::Impl::PROPERTY_3( CONTROL_TYPE, "width-policy", Toolkit::Control::PROPERTY_WIDTH_POLICY, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
544 PropertyRegistration Control::Impl::PROPERTY_4( CONTROL_TYPE, "height-policy", Toolkit::Control::PROPERTY_HEIGHT_POLICY, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
545 PropertyRegistration Control::Impl::PROPERTY_5( CONTROL_TYPE, "minimum-size", Toolkit::Control::PROPERTY_MINIMUM_SIZE, Property::VECTOR3, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
546 PropertyRegistration Control::Impl::PROPERTY_6( CONTROL_TYPE, "maximum-size", Toolkit::Control::PROPERTY_MAXIMUM_SIZE, Property::VECTOR3, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
547 PropertyRegistration Control::Impl::PROPERTY_7( CONTROL_TYPE, "key-input-focus", Toolkit::Control::PROPERTY_KEY_INPUT_FOCUS, Property::BOOLEAN, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
549 Toolkit::Control Control::New()
551 // Create the implementation, temporarily owned on stack
552 IntrusivePtr<Control> controlImpl = new Control( false );
554 // Pass ownership to handle
555 Toolkit::Control handle( *controlImpl );
557 // Second-phase init of the implementation
558 // This can only be done after the CustomActor connection has been made...
559 controlImpl->Initialize();
566 if( mImpl->mInitialized )
568 // Unregister only if control has been initialized.
569 Internal::StyleChangeProcessor::Unregister( this );
574 void Control::Initialize()
576 // Register with the style change processor so we are informed when the default style changes
577 Internal::StyleChangeProcessor::Register( this );
579 // Calling deriving classes
582 mImpl->mInitialized = true;
585 void Control::EnableGestureDetection(Gesture::Type type)
587 if ( (type & Gesture::Pinch) && !mImpl->mPinchGestureDetector )
589 mImpl->mPinchGestureDetector = PinchGestureDetector::New();
590 mImpl->mPinchGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PinchDetected);
591 mImpl->mPinchGestureDetector.Attach(Self());
594 if ( (type & Gesture::Pan) && !mImpl->mPanGestureDetector )
596 mImpl->mPanGestureDetector = PanGestureDetector::New();
597 mImpl->mPanGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PanDetected);
598 mImpl->mPanGestureDetector.Attach(Self());
601 if ( (type & Gesture::Tap) && !mImpl->mTapGestureDetector )
603 mImpl->mTapGestureDetector = TapGestureDetector::New();
604 mImpl->mTapGestureDetector.DetectedSignal().Connect(mImpl, &Impl::TapDetected);
605 mImpl->mTapGestureDetector.Attach(Self());
608 if ( (type & Gesture::LongPress) && !mImpl->mLongPressGestureDetector )
610 mImpl->mLongPressGestureDetector = LongPressGestureDetector::New();
611 mImpl->mLongPressGestureDetector.DetectedSignal().Connect(mImpl, &Impl::LongPressDetected);
612 mImpl->mLongPressGestureDetector.Attach(Self());
616 void Control::DisableGestureDetection(Gesture::Type type)
618 if ( (type & Gesture::Pinch) && mImpl->mPinchGestureDetector )
620 mImpl->mPinchGestureDetector.Detach(Self());
621 mImpl->mPinchGestureDetector.Reset();
624 if ( (type & Gesture::Pan) && mImpl->mPanGestureDetector )
626 mImpl->mPanGestureDetector.Detach(Self());
627 mImpl->mPanGestureDetector.Reset();
630 if ( (type & Gesture::Tap) && mImpl->mTapGestureDetector )
632 mImpl->mTapGestureDetector.Detach(Self());
633 mImpl->mTapGestureDetector.Reset();
636 if ( (type & Gesture::LongPress) && mImpl->mLongPressGestureDetector)
638 mImpl->mLongPressGestureDetector.Detach(Self());
639 mImpl->mLongPressGestureDetector.Reset();
643 PinchGestureDetector Control::GetPinchGestureDetector() const
645 return mImpl->mPinchGestureDetector;
648 PanGestureDetector Control::GetPanGestureDetector() const
650 return mImpl->mPanGestureDetector;
653 TapGestureDetector Control::GetTapGestureDetector() const
655 return mImpl->mTapGestureDetector;
658 LongPressGestureDetector Control::GetLongPressGestureDetector() const
660 return mImpl->mLongPressGestureDetector;
663 void Control::SetBackgroundColor( const Vector4& color )
665 Background& background( mImpl->GetBackground() );
667 if ( background.actor )
669 // Just set the actor color
670 background.actor.SetColor( color );
675 MeshActor meshActor = MeshActor::New( CreateMesh() );
677 meshActor.SetAffectedByLighting( false );
678 SetupBackgroundActor( meshActor, Actor::SCALE, color );
680 // Set the background actor before adding so that we do not inform deriving classes
681 background.actor = meshActor;
682 Self().Add( meshActor );
685 background.color = color;
688 Vector4 Control::GetBackgroundColor() const
690 if ( mImpl->mBackground )
692 return mImpl->mBackground->color;
694 return Color::TRANSPARENT;
697 void Control::SetBackground( Image image )
699 Background& background( mImpl->GetBackground() );
701 if ( background.actor )
703 // Remove Current actor, unset AFTER removal so that we do not inform deriving classes
704 Self().Remove( background.actor );
705 background.actor = NULL;
708 ImageActor imageActor = ImageActor::New( image );
709 SetupBackgroundActor( imageActor, Actor::SIZE, background.color );
711 // Set the background actor before adding so that we do not inform derived classes
712 background.actor = imageActor;
713 Self().Add( imageActor );
716 void Control::ClearBackground()
718 if ( mImpl->mBackground )
720 Background& background( mImpl->GetBackground() );
721 Self().Remove( background.actor );
723 delete mImpl->mBackground;
724 mImpl->mBackground = NULL;
728 Actor Control::GetBackgroundActor() const
730 if ( mImpl->mBackground )
732 return mImpl->mBackground->actor;
738 void Control::OnPinch(PinchGesture pinch)
740 if (pinch.state == Gesture::Started)
742 mImpl->mStartingPinchScale = Self().GetCurrentScale();
745 Self().SetScale(mImpl->mStartingPinchScale * pinch.scale);
748 void Control::OnStageConnection()
752 // Notify derived classes.
753 OnControlStageConnection();
756 void Control::OnStageDisconnection()
758 // Notify derived classes
759 OnControlStageDisconnection();
762 void Control::OnChildAdd(Actor& child)
764 // If this is the background actor, then we do not want to relayout or inform deriving classes
765 if ( mImpl->mBackground && ( child == mImpl->mBackground->actor ) )
770 // Request for relayout.
773 // Notify derived classes.
774 OnControlChildAdd( child );
777 void Control::OnChildRemove(Actor& child)
779 // If this is the background actor, then we do not want to relayout or inform deriving classes
780 if ( mImpl->mBackground && ( child == mImpl->mBackground->actor ) )
785 // Request for relayout.
788 // Notify derived classes.
789 OnControlChildRemove( child );
792 void Control::OnSizeSet(const Vector3& targetSize)
794 if( ( !mImpl->mLockSetSize ) && ( targetSize != mImpl->mSetSize ) )
796 // Only updates size if set through Actor's API
797 mImpl->mSetSize = targetSize;
800 if( targetSize != mImpl->mSize )
802 // Update control size.
803 mImpl->mSize = targetSize;
805 // Notify derived classes.
806 OnControlSizeSet( targetSize );
810 void Control::OnSizeAnimation(Animation& animation, const Vector3& targetSize)
815 bool Control::OnTouchEvent(const TouchEvent& event)
817 return false; // Do not consume
820 bool Control::OnKeyEvent(const KeyEvent& event)
822 return false; // Do not consume
825 bool Control::OnMouseWheelEvent(const MouseWheelEvent& event)
827 return false; // Do not consume
830 void Control::OnKeyInputFocusGained()
835 void Control::OnKeyInputFocusLost()
840 Actor Control::GetChildByAlias(const std::string& actorAlias)
845 bool Control::OnAccessibilityPan(PanGesture gesture)
847 return false; // Accessibility pan gesture is not handled by default
850 bool Control::OnAccessibilityValueChange(bool isIncrease)
852 return false; // Accessibility value change action is not handled by default
856 void Control::SetKeyboardNavigationSupport(bool isSupported)
858 mImpl->mIsKeyboardNavigationSupported = isSupported;
861 bool Control::IsKeyboardNavigationSupported()
863 return mImpl->mIsKeyboardNavigationSupported;
866 void Control::SetAsKeyboardFocusGroup(bool isFocusGroup)
868 mImpl->mIsKeyboardFocusGroup = isFocusGroup;
870 // The following line will be removed when the deprecated API in KeyboardFocusManager is deleted
871 Toolkit::KeyboardFocusManager::Get().SetAsFocusGroup(Self(), isFocusGroup);
874 bool Control::IsKeyboardFocusGroup()
876 return Toolkit::KeyboardFocusManager::Get().IsFocusGroup(Self());
879 Actor Control::GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocusNavigationDirection direction, bool loopEnabled)
884 bool Control::DoAction(BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes)
891 void Control::DoActivatedAction(const PropertyValueContainer& attributes)
896 Toolkit::Control::KeyEventSignalV2& Control::KeyEventSignal()
898 return mImpl->mKeyEventSignalV2;
901 void Control::SetSizePolicy( Toolkit::Control::SizePolicy widthPolicy, Toolkit::Control::SizePolicy heightPolicy )
903 bool relayoutRequest( false );
905 if ( ( mImpl->mWidthPolicy != widthPolicy ) || ( mImpl->mHeightPolicy != heightPolicy ) )
907 relayoutRequest = true;
910 mImpl->mWidthPolicy = widthPolicy;
911 mImpl->mHeightPolicy = heightPolicy;
913 // Ensure RelayoutRequest is called AFTER new policies have been set.
914 if ( relayoutRequest )
920 void Control::GetSizePolicy( Toolkit::Control::SizePolicy& widthPolicy, Toolkit::Control::SizePolicy& heightPolicy ) const
922 widthPolicy = mImpl->mWidthPolicy;
923 heightPolicy = mImpl->mHeightPolicy;
926 void Control::SetMinimumSize( const Vector3& size )
928 if ( mImpl->mMinimumSize != size )
930 mImpl->mMinimumSize = size;
932 // Only relayout if our control is using the minimum or range policy.
933 if ( ( mImpl->mHeightPolicy == Toolkit::Control::Minimum ) || ( mImpl->mWidthPolicy == Toolkit::Control::Minimum ) ||
934 ( mImpl->mHeightPolicy == Toolkit::Control::Range ) || ( mImpl->mWidthPolicy == Toolkit::Control::Range ) )
941 const Vector3& Control::GetMinimumSize() const
943 return mImpl->mMinimumSize;
946 void Control::SetMaximumSize( const Vector3& size )
948 if ( mImpl->mMaximumSize != size )
950 mImpl->mMaximumSize = size;
952 // Only relayout if our control is using the maximum or range policy.
953 if ( ( mImpl->mHeightPolicy == Toolkit::Control::Maximum ) || ( mImpl->mWidthPolicy == Toolkit::Control::Maximum ) ||
954 ( mImpl->mHeightPolicy == Toolkit::Control::Range ) || ( mImpl->mWidthPolicy == Toolkit::Control::Range ) )
961 const Vector3& Control::GetMaximumSize() const
963 return mImpl->mMaximumSize;
966 Vector3 Control::GetNaturalSize()
968 // could be overridden in derived classes.
969 return mImpl->mSetSize;
972 float Control::GetHeightForWidth( float width )
974 // could be overridden in derived classes.
975 float height( 0.0f );
976 if ( mImpl->mSetSize.width > 0.0f )
978 height = mImpl->mSetSize.height * width / mImpl->mSetSize.width;
983 float Control::GetWidthForHeight( float height )
985 // could be overridden in derived classes.
987 if ( mImpl->mSetSize.height > 0.0f )
989 width = mImpl->mSetSize.width * height / mImpl->mSetSize.height;
994 const Vector3& Control::GetControlSize() const
999 const Vector3& Control::GetSizeSet() const
1001 return mImpl->mSetSize;
1004 void Control::SetKeyInputFocus()
1006 if( Self().OnStage() )
1008 Toolkit::KeyInputFocusManager::Get().SetFocus(Toolkit::Control::DownCast(Self()));
1012 bool Control::HasKeyInputFocus()
1014 bool result = false;
1015 if( Self().OnStage() )
1017 result = Toolkit::KeyInputFocusManager::Get().IsKeyboardListener(Toolkit::Control::DownCast(Self()));
1022 void Control::ClearKeyInputFocus()
1024 if( Self().OnStage() )
1026 Toolkit::KeyInputFocusManager::Get().RemoveFocus(Toolkit::Control::DownCast(Self()));
1030 void Control::RelayoutRequest()
1032 Internal::RelayoutController::Get().Request();
1035 void Control::Relayout( Vector2 size, ActorSizeContainer& container )
1037 // Avoids relayout again when OnSizeSet callback arrives.
1039 SetSizeLock lock( mImpl->mLockSetSize );
1040 Self().SetSize( size );
1043 // Only relayout controls which requested to be relaid out.
1044 OnRelaidOut( size, container );
1047 void Control::Relayout( Actor actor, Vector2 size, ActorSizeContainer& container )
1051 Toolkit::Control control( Toolkit::Control::DownCast( actor ) );
1054 control.GetImplementation().NegotiateSize( size, container );
1058 container.push_back( ActorSizePair( actor, size ) );
1063 void Control::OnRelaidOut( Vector2 size, ActorSizeContainer& container )
1065 unsigned int numChildren = Self().GetChildCount();
1067 for( unsigned int i=0; i<numChildren; ++i )
1069 container.push_back( ActorSizePair( Self().GetChildAt(i), size ) );
1073 void Control::NegotiateSize( Vector2 allocatedSize, ActorSizeContainer& container )
1077 if ( mImpl->mWidthPolicy == Toolkit::Control::Fixed )
1079 if ( mImpl->mHeightPolicy == Toolkit::Control::Fixed )
1081 // If a control says it has a fixed size, then use the size set by the application / control.
1082 Vector2 setSize( mImpl->mSetSize );
1083 if ( setSize != Vector2::ZERO )
1087 // Policy is set to Fixed, so if the application / control has not set one of the dimensions,
1088 // then we should use the natural size of the control rather than the full allocation.
1089 if ( EqualsZero( size.width ) )
1091 size.width = GetWidthForHeight( size.height );
1093 else if ( EqualsZero( size.height ) )
1095 size.height = GetHeightForWidth( size.width );
1100 // If that is not set then set the size to the control's natural size
1101 size = Vector2( GetNaturalSize() );
1106 // Width is fixed so if the application / control has set it, then use that.
1107 if ( !EqualsZero( mImpl->mSetSize.width ) )
1109 size.width = mImpl->mSetSize.width;
1113 // Otherwise, set the width to what has been allocated.
1114 size.width = allocatedSize.width;
1117 // Height is flexible so ask control what the height should be for our width.
1118 size.height = GetHeightForWidth( size.width );
1120 // Ensure height is within our policy rules
1121 size.height = Calculate( mImpl->mHeightPolicy, mImpl->mMinimumSize.height, mImpl->mMaximumSize.height, size.height );
1126 if ( mImpl->mHeightPolicy == Toolkit::Control::Fixed )
1128 // Height is fixed so if the application / control has set it, then use that.
1129 if ( !EqualsZero( mImpl->mSetSize.height ) )
1131 size.height = mImpl->mSetSize.height;
1135 // Otherwise, set the height to what has been allocated.
1136 size.height = allocatedSize.height;
1139 // Width is flexible so ask control what the width should be for our height.
1140 size.width = GetWidthForHeight( size.height );
1142 // Ensure width is within our policy rules
1143 size.width = Calculate( mImpl->mWidthPolicy, mImpl->mMinimumSize.width, mImpl->mMaximumSize.width, size.width );
1147 // Width and height are BOTH flexible.
1148 // Calculate the width and height using the policy rules.
1149 size.width = Calculate( mImpl->mWidthPolicy, mImpl->mMinimumSize.width, mImpl->mMaximumSize.width, allocatedSize.width );
1150 size.height = Calculate( mImpl->mHeightPolicy, mImpl->mMinimumSize.height, mImpl->mMaximumSize.height, allocatedSize.height );
1154 // If the width has not been set, then set to the allocated width.
1155 // Also if the width set is greater than the allocated, then set to allocated (no exceed support).
1156 if ( EqualsZero( size.width ) || ( size.width > allocatedSize.width ) )
1158 size.width = allocatedSize.width;
1161 // If the height has not been set, then set to the allocated height.
1162 // Also if the height set is greater than the allocated, then set to allocated (no exceed support).
1163 if ( EqualsZero( size.height ) || ( size.height > allocatedSize.height ) )
1165 size.height = allocatedSize.height;
1168 DALI_LOG_INFO( gLogFilter, Debug::Verbose,
1169 "%p: Natural: [%.2f, %.2f] Allocated: [%.2f, %.2f] Set: [%.2f, %.2f]\n",
1170 Self().GetObjectPtr(),
1171 GetNaturalSize().x, GetNaturalSize().y,
1172 allocatedSize.x, allocatedSize.y,
1175 Relayout( size, container );
1178 bool Control::EmitKeyEventSignal( const KeyEvent& event )
1180 // Guard against destruction during signal emission
1181 Dali::Toolkit::Control handle( GetOwner() );
1183 bool consumed = false;
1185 // signals are allocated dynamically when someone connects
1186 if ( !mImpl->mKeyEventSignalV2.Empty() )
1188 consumed = mImpl->mKeyEventSignalV2.Emit( handle, event );
1193 // Notification for derived classes
1194 consumed = OnKeyEvent(event);
1200 void Control::SignalConnected( SlotObserver* slotObserver, CallbackBase* callback )
1202 mImpl->SignalConnected( slotObserver, callback );
1205 void Control::SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback )
1207 mImpl->SignalDisconnected( slotObserver, callback );
1210 std::size_t Control::GetConnectionCount() const
1212 return mImpl->GetConnectionCount();
1215 Control::Control( bool requiresTouchEvents )
1216 : CustomActorImpl( requiresTouchEvents ),
1217 mImpl(new Impl(*this))
1221 } // namespace Internal
1223 } // namespace Toolkit