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/relayout-controller.h"
24 #include "dali-toolkit/internal/controls/relayout-helper.h"
25 #include "dali-toolkit/public-api/focus-manager/keyinput-focus-manager.h"
26 #include "dali-toolkit/public-api/focus-manager/keyboard-focus-manager.h"
27 #include <dali-toolkit/public-api/controls/control.h>
29 #include <dali-toolkit/public-api/styling/style-manager.h>
30 #include <dali-toolkit/internal/styling/style-manager-impl.h>
38 const Property::Index Control::PROPERTY_BACKGROUND_COLOR = Internal::Control::CONTROL_PROPERTY_START_INDEX;
39 const Property::Index Control::PROPERTY_BACKGROUND = Internal::Control::CONTROL_PROPERTY_START_INDEX + 1;
40 const Property::Index Control::PROPERTY_WIDTH_POLICY = Internal::Control::CONTROL_PROPERTY_START_INDEX + 2;
41 const Property::Index Control::PROPERTY_HEIGHT_POLICY = Internal::Control::CONTROL_PROPERTY_START_INDEX + 3;
42 const Property::Index Control::PROPERTY_MINIMUM_SIZE = Internal::Control::CONTROL_PROPERTY_START_INDEX + 4;
43 const Property::Index Control::PROPERTY_MAXIMUM_SIZE = Internal::Control::CONTROL_PROPERTY_START_INDEX + 5;
44 const Property::Index Control::PROPERTY_KEY_INPUT_FOCUS = Internal::Control::CONTROL_PROPERTY_START_INDEX + 6;
49 const Scripting::StringEnum< Control::SizePolicy > SIZE_POLICY_STRING_TABLE[] =
51 { "FIXED", Control::Fixed },
52 { "MINIMUM", Control::Minimum },
53 { "MAXIMUM", Control::Maximum },
54 { "RANGE", Control::Range },
55 { "FLEXIBLE", Control::Flexible },
57 const unsigned int SIZE_POLICY_STRING_TABLE_COUNT = sizeof( SIZE_POLICY_STRING_TABLE ) / sizeof( SIZE_POLICY_STRING_TABLE[0] );
59 #if defined(DEBUG_ENABLED)
60 Integration::Log::Filter* gLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_CONTROL");
63 const float MAX_FLOAT_VALUE( std::numeric_limits<float>::max() );
64 const float BACKGROUND_ACTOR_Z_POSITION( -0.1f );
68 return Internal::Control::New();
71 TypeRegistration CONTROL_TYPE( typeid(Control), typeid(CustomActor), Create );
73 // Property Registration after Internal::Control::Impl definition below
75 TypeAction ACTION_TYPE_1(CONTROL_TYPE, Toolkit::Control::ACTION_CONTROL_ACTIVATED, &Internal::Control::DoAction);
78 * Helper class used to set the Control's size through the Actor's API or through children added.
83 SetSizeLock( bool& lock )
99 * Structure which holds information about the background of a control
103 Actor actor; ///< Either a MeshActor or an ImageActor
104 Vector4 color; ///< The color of the actor.
111 color( Color::WHITE )
117 * Helper function to calculate a dimension given the policy of that dimension; the minimum &
118 * maximum values that dimension can be; and the allocated value for that dimension.
120 * @param[in] policy The size policy for that dimension.
121 * @param[in] minimum The minimum value that dimension can be.
122 * @param[in] maximum The maximum value that dimension can be.
123 * @param[in] allocated The value allocated for that dimension.
125 * @return The value that the dimension should be.
127 * @note This does not handle Control::Fixed policy.
129 float Calculate( Control::SizePolicy policy, float minimum, float maximum, float allocated )
131 float size( allocated );
137 // Use allocated value
141 case Control::Minimum:
143 // Size is always at least the minimum.
144 size = std::max( allocated, minimum );
148 case Control::Maximum:
150 // Size can grow but up to a maximum value.
151 size = std::min( allocated, maximum );
157 // Size is at least the minimum and can grow up to the maximum
158 size = std::max( size, minimum );
159 size = std::min( size, maximum );
163 case Control::Flexible:
165 // Size grows or shrinks with no limits.
172 DALI_ASSERT_DEBUG( false && "This function was not intended to be used by any other policy." );
181 * Creates a white coloured Mesh.
185 Vector3 white( Color::WHITE );
189 // Create vertices with a white color (actual color is set by actor color)
190 MeshData::VertexContainer vertices(4);
191 vertices[ 0 ] = MeshData::Vertex( Vector3( -0.5f, -0.5f, 0.0f ), Vector2::ZERO, white );
192 vertices[ 1 ] = MeshData::Vertex( Vector3( 0.5f, -0.5f, 0.0f ), Vector2::ZERO, white );
193 vertices[ 2 ] = MeshData::Vertex( Vector3( -0.5f, 0.5f, 0.0f ), Vector2::ZERO, white );
194 vertices[ 3 ] = MeshData::Vertex( Vector3( 0.5f, 0.5f, 0.0f ), Vector2::ZERO, white );
196 // Specify all the faces
197 MeshData::FaceIndices faces;
198 faces.reserve( 6 ); // 2 triangles in Quad
199 faces.push_back( 0 ); faces.push_back( 3 ); faces.push_back( 1 );
200 faces.push_back( 0 ); faces.push_back( 2 ); faces.push_back( 3 );
202 // Create the mesh data from the vertices and faces
203 meshData.SetMaterial( Material::New( "ControlMaterial" ) );
204 meshData.SetVertices( vertices );
205 meshData.SetFaceIndices( faces );
206 meshData.SetHasColor( true );
208 return Mesh::New( meshData );
212 * Sets all the required properties for the background actor.
214 * @param[in] actor The actor to set the properties on.
215 * @param[in] constrainingIndex The property index to constrain the parent's size on.
216 * @param[in] color The required color of the actor.
218 void SetupBackgroundActor( Actor actor, Property::Index constrainingIndex, const Vector4& color )
220 actor.SetColor( color );
221 actor.SetPositionInheritanceMode( USE_PARENT_POSITION_PLUS_LOCAL_POSITION );
222 actor.SetZ( BACKGROUND_ACTOR_Z_POSITION );
224 Constraint constraint = Constraint::New<Vector3>( constrainingIndex,
225 ParentSource( Actor::SIZE ),
226 EqualToConstraint() );
227 actor.ApplyConstraint( constraint );
230 } // unnamed namespace
235 class Control::Impl : public ConnectionTrackerInterface
238 // Construction & Destruction
239 Impl(Control& controlImpl)
240 : mControlImpl(controlImpl),
241 mInitialized( false ),
242 mPinchGestureDetector(),
243 mPanGestureDetector(),
244 mTapGestureDetector(),
245 mLongPressGestureDetector(),
246 mStartingPinchScale(),
247 mLockSetSize( false ),
248 mWidthPolicy( Toolkit::Control::Fixed ),
249 mHeightPolicy( Toolkit::Control::Fixed ),
253 mMaximumSize( MAX_FLOAT_VALUE, MAX_FLOAT_VALUE, MAX_FLOAT_VALUE ),
254 mIsKeyboardNavigationSupported(false),
255 mIsKeyboardFocusGroup(false),
258 mFlags( Control::CONTROL_BEHAVIOUR_NONE )
264 // All gesture detectors will be destroyed so no need to disconnect.
271 // Gesture Detection Methods
273 void PinchDetected(Actor actor, PinchGesture pinch)
275 mControlImpl.OnPinch(pinch);
278 void PanDetected(Actor actor, PanGesture pan)
280 mControlImpl.OnPan(pan);
283 void TapDetected(Actor actor, TapGesture tap)
285 mControlImpl.OnTap(tap);
288 void LongPressDetected(Actor actor, LongPressGesture longPress)
290 mControlImpl.OnLongPress(longPress);
294 * @copydoc ConnectionTrackerInterface::SignalConnected
296 virtual void SignalConnected( SlotObserver* slotObserver, CallbackBase* callback )
298 mConnectionTracker.SignalConnected( slotObserver, callback );
302 * @copydoc ConnectionTrackerInterface::SignalDisconnected
304 virtual void SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback )
306 mConnectionTracker.SignalDisconnected( slotObserver, callback );
310 * @copydoc ConnectionTrackerInterface::GetConnectionCount
312 virtual std::size_t GetConnectionCount() const
314 return mConnectionTracker.GetConnectionCount();
317 // Background Methods
320 * Only creates an instance of the background if we actually use it.
321 * @return A reference to the Background structure.
323 Background& GetBackground()
327 mBackground = new Background;
335 * Called when a property of an object of this type is set.
336 * @param[in] object The object whose property is set.
337 * @param[in] index The property index.
338 * @param[in] value The new property value.
340 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
342 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
346 Control& controlImpl( control.GetImplementation() );
350 case Toolkit::Control::PROPERTY_BACKGROUND_COLOR:
352 controlImpl.SetBackgroundColor( value.Get< Vector4 >() );
356 case Toolkit::Control::PROPERTY_BACKGROUND:
358 if ( value.HasKey( "image" ) )
360 Property::Map imageMap = value.GetValue( "image" ).Get< Property::Map >();
361 Image image = Scripting::NewImage( imageMap );
365 controlImpl.SetBackground( image );
368 else if ( value.Get< Property::Map >().empty() )
370 // An empty map means the background is no longer required
371 controlImpl.ClearBackground();
376 case Toolkit::Control::PROPERTY_WIDTH_POLICY:
378 controlImpl.mImpl->mWidthPolicy = Scripting::GetEnumeration< Toolkit::Control::SizePolicy >( value.Get< std::string >(), SIZE_POLICY_STRING_TABLE, SIZE_POLICY_STRING_TABLE_COUNT );
382 case Toolkit::Control::PROPERTY_HEIGHT_POLICY:
384 controlImpl.mImpl->mHeightPolicy = Scripting::GetEnumeration< Toolkit::Control::SizePolicy >( value.Get< std::string >(), SIZE_POLICY_STRING_TABLE, SIZE_POLICY_STRING_TABLE_COUNT );
388 case Toolkit::Control::PROPERTY_MINIMUM_SIZE:
390 controlImpl.SetMinimumSize( value.Get< Vector3 >() );
394 case Toolkit::Control::PROPERTY_MAXIMUM_SIZE:
396 controlImpl.SetMaximumSize( value.Get< Vector3 >() );
400 case Toolkit::Control::PROPERTY_KEY_INPUT_FOCUS:
402 if ( value.Get< bool >() )
404 controlImpl.SetKeyInputFocus();
408 controlImpl.ClearKeyInputFocus();
417 * Called to retrieve a property of an object of this type.
418 * @param[in] object The object whose property is to be retrieved.
419 * @param[in] index The property index.
420 * @return The current value of the property.
422 static Property::Value GetProperty( BaseObject* object, Property::Index index )
424 Property::Value value;
426 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
430 Control& controlImpl( control.GetImplementation() );
434 case Toolkit::Control::PROPERTY_BACKGROUND_COLOR:
436 value = controlImpl.GetBackgroundColor();
440 case Toolkit::Control::PROPERTY_BACKGROUND:
444 Actor actor = controlImpl.GetBackgroundActor();
447 ImageActor imageActor = ImageActor::DownCast( actor );
450 Image image = imageActor.GetImage();
451 Property::Map imageMap;
452 Scripting::CreatePropertyMap( image, imageMap );
453 map.push_back( Property::StringValuePair( "image", imageMap ) );
461 case Toolkit::Control::PROPERTY_WIDTH_POLICY:
463 value = std::string( Scripting::GetEnumerationName< Toolkit::Control::SizePolicy >( controlImpl.mImpl->mWidthPolicy, SIZE_POLICY_STRING_TABLE, SIZE_POLICY_STRING_TABLE_COUNT ) );
467 case Toolkit::Control::PROPERTY_HEIGHT_POLICY:
469 value = std::string( Scripting::GetEnumerationName< Toolkit::Control::SizePolicy >( controlImpl.mImpl->mHeightPolicy, SIZE_POLICY_STRING_TABLE, SIZE_POLICY_STRING_TABLE_COUNT ) );
473 case Toolkit::Control::PROPERTY_MINIMUM_SIZE:
475 value = controlImpl.mImpl->mMinimumSize;
479 case Toolkit::Control::PROPERTY_MAXIMUM_SIZE:
481 value = controlImpl.mImpl->mMaximumSize;
485 case Toolkit::Control::PROPERTY_KEY_INPUT_FOCUS:
487 value = controlImpl.HasKeyInputFocus();
498 Control& mControlImpl;
502 ConnectionTracker mConnectionTracker; // signal connection tracker
506 PinchGestureDetector mPinchGestureDetector;
507 PanGestureDetector mPanGestureDetector;
508 TapGestureDetector mTapGestureDetector;
509 LongPressGestureDetector mLongPressGestureDetector;
511 Vector3 mStartingPinchScale; ///< The scale when a pinch gesture starts
513 // Relayout and size negotiation
515 bool mLockSetSize; ///< Used to avoid. Can't be a bitfield as a reference to this member is used in SetSizeLock helper class.
517 Toolkit::Control::SizePolicy mWidthPolicy; ///< Stores the width policy.
518 Toolkit::Control::SizePolicy mHeightPolicy; ///< Stores the height policy.
520 Vector3 mSize; ///< Stores the current control's size.
521 Vector3 mSetSize; ///< Always stores the size set through the Actor's API. Useful when reset to the initial size is needed.
522 Vector3 mMinimumSize; ///< Stores the control's minimum size.
523 Vector3 mMaximumSize; ///< Stores the control's maximum size.
525 bool mIsKeyboardNavigationSupported; ///< Stores whether keyboard navigation is supported by the control.
526 bool mIsKeyboardFocusGroup; ///< Stores whether the control is a focus group.
528 Toolkit::Control::KeyEventSignalV2 mKeyEventSignalV2;
531 Background* mBackground; ///< Only create the background if we use it
533 ControlBehaviour mFlags; ///< Flags passed in from constructor
535 // Properties - these need to be members of Internal::Control::Impl as they need to functions within this class.
536 static PropertyRegistration PROPERTY_1;
537 static PropertyRegistration PROPERTY_2;
538 static PropertyRegistration PROPERTY_3;
539 static PropertyRegistration PROPERTY_4;
540 static PropertyRegistration PROPERTY_5;
541 static PropertyRegistration PROPERTY_6;
542 static PropertyRegistration PROPERTY_7;
545 PropertyRegistration Control::Impl::PROPERTY_1( CONTROL_TYPE, "background-color", Toolkit::Control::PROPERTY_BACKGROUND_COLOR, Property::VECTOR4, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
546 PropertyRegistration Control::Impl::PROPERTY_2( CONTROL_TYPE, "background", Toolkit::Control::PROPERTY_BACKGROUND, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
547 PropertyRegistration Control::Impl::PROPERTY_3( CONTROL_TYPE, "width-policy", Toolkit::Control::PROPERTY_WIDTH_POLICY, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
548 PropertyRegistration Control::Impl::PROPERTY_4( CONTROL_TYPE, "height-policy", Toolkit::Control::PROPERTY_HEIGHT_POLICY, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
549 PropertyRegistration Control::Impl::PROPERTY_5( CONTROL_TYPE, "minimum-size", Toolkit::Control::PROPERTY_MINIMUM_SIZE, Property::VECTOR3, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
550 PropertyRegistration Control::Impl::PROPERTY_6( CONTROL_TYPE, "maximum-size", Toolkit::Control::PROPERTY_MAXIMUM_SIZE, Property::VECTOR3, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
551 PropertyRegistration Control::Impl::PROPERTY_7( CONTROL_TYPE, "key-input-focus", Toolkit::Control::PROPERTY_KEY_INPUT_FOCUS, Property::BOOLEAN, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
553 Toolkit::Control Control::New()
555 // Create the implementation, temporarily owned on stack
556 IntrusivePtr<Control> controlImpl = new Control( CONTROL_BEHAVIOUR_NONE );
558 // Pass ownership to handle
559 Toolkit::Control handle( *controlImpl );
561 // Second-phase init of the implementation
562 // This can only be done after the CustomActor connection has been made...
563 controlImpl->Initialize();
573 void Control::Initialize()
576 // Calling deriving classes
579 if( mImpl->mFlags & REQUIRES_THEME_CHANGE_SIGNALS )
581 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
583 // Register for font/theme changes
584 styleManager.ThemeChangeSignal().Connect( this, &ControlImpl::OnThemeChange );
587 GetImpl( styleManager ).ApplyThemeStyle( GetOwner() );
590 mImpl->mInitialized = true;
593 void Control::EnableGestureDetection(Gesture::Type type)
595 if ( (type & Gesture::Pinch) && !mImpl->mPinchGestureDetector )
597 mImpl->mPinchGestureDetector = PinchGestureDetector::New();
598 mImpl->mPinchGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PinchDetected);
599 mImpl->mPinchGestureDetector.Attach(Self());
602 if ( (type & Gesture::Pan) && !mImpl->mPanGestureDetector )
604 mImpl->mPanGestureDetector = PanGestureDetector::New();
605 mImpl->mPanGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PanDetected);
606 mImpl->mPanGestureDetector.Attach(Self());
609 if ( (type & Gesture::Tap) && !mImpl->mTapGestureDetector )
611 mImpl->mTapGestureDetector = TapGestureDetector::New();
612 mImpl->mTapGestureDetector.DetectedSignal().Connect(mImpl, &Impl::TapDetected);
613 mImpl->mTapGestureDetector.Attach(Self());
616 if ( (type & Gesture::LongPress) && !mImpl->mLongPressGestureDetector )
618 mImpl->mLongPressGestureDetector = LongPressGestureDetector::New();
619 mImpl->mLongPressGestureDetector.DetectedSignal().Connect(mImpl, &Impl::LongPressDetected);
620 mImpl->mLongPressGestureDetector.Attach(Self());
624 void Control::DisableGestureDetection(Gesture::Type type)
626 if ( (type & Gesture::Pinch) && mImpl->mPinchGestureDetector )
628 mImpl->mPinchGestureDetector.Detach(Self());
629 mImpl->mPinchGestureDetector.Reset();
632 if ( (type & Gesture::Pan) && mImpl->mPanGestureDetector )
634 mImpl->mPanGestureDetector.Detach(Self());
635 mImpl->mPanGestureDetector.Reset();
638 if ( (type & Gesture::Tap) && mImpl->mTapGestureDetector )
640 mImpl->mTapGestureDetector.Detach(Self());
641 mImpl->mTapGestureDetector.Reset();
644 if ( (type & Gesture::LongPress) && mImpl->mLongPressGestureDetector)
646 mImpl->mLongPressGestureDetector.Detach(Self());
647 mImpl->mLongPressGestureDetector.Reset();
651 PinchGestureDetector Control::GetPinchGestureDetector() const
653 return mImpl->mPinchGestureDetector;
656 PanGestureDetector Control::GetPanGestureDetector() const
658 return mImpl->mPanGestureDetector;
661 TapGestureDetector Control::GetTapGestureDetector() const
663 return mImpl->mTapGestureDetector;
666 LongPressGestureDetector Control::GetLongPressGestureDetector() const
668 return mImpl->mLongPressGestureDetector;
671 void Control::SetBackgroundColor( const Vector4& color )
673 Background& background( mImpl->GetBackground() );
675 if ( background.actor )
677 // Just set the actor color
678 background.actor.SetColor( color );
683 MeshActor meshActor = MeshActor::New( CreateMesh() );
685 meshActor.SetAffectedByLighting( false );
686 SetupBackgroundActor( meshActor, Actor::SCALE, color );
688 // Set the background actor before adding so that we do not inform deriving classes
689 background.actor = meshActor;
690 Self().Add( meshActor );
693 background.color = color;
696 Vector4 Control::GetBackgroundColor() const
698 if ( mImpl->mBackground )
700 return mImpl->mBackground->color;
702 return Color::TRANSPARENT;
705 void Control::SetBackground( Image image )
707 Background& background( mImpl->GetBackground() );
709 if ( background.actor )
711 // Remove Current actor, unset AFTER removal so that we do not inform deriving classes
712 Self().Remove( background.actor );
713 background.actor = NULL;
716 ImageActor imageActor = ImageActor::New( image );
717 SetupBackgroundActor( imageActor, Actor::SIZE, background.color );
719 // Set the background actor before adding so that we do not inform derived classes
720 background.actor = imageActor;
721 Self().Add( imageActor );
724 void Control::ClearBackground()
726 if ( mImpl->mBackground )
728 Background& background( mImpl->GetBackground() );
729 Self().Remove( background.actor );
731 delete mImpl->mBackground;
732 mImpl->mBackground = NULL;
736 Actor Control::GetBackgroundActor() const
738 if ( mImpl->mBackground )
740 return mImpl->mBackground->actor;
746 void Control::OnPinch(PinchGesture pinch)
748 if (pinch.state == Gesture::Started)
750 mImpl->mStartingPinchScale = Self().GetCurrentScale();
753 Self().SetScale(mImpl->mStartingPinchScale * pinch.scale);
756 void Control::OnStageConnection()
760 // Notify derived classes.
761 OnControlStageConnection();
764 void Control::OnStageDisconnection()
766 // Notify derived classes
767 OnControlStageDisconnection();
770 void Control::OnChildAdd(Actor& child)
772 // If this is the background actor, then we do not want to relayout or inform deriving classes
773 if ( mImpl->mBackground && ( child == mImpl->mBackground->actor ) )
778 // Request for relayout.
781 // Notify derived classes.
782 OnControlChildAdd( child );
785 void Control::OnChildRemove(Actor& child)
787 // If this is the background actor, then we do not want to relayout or inform deriving classes
788 if ( mImpl->mBackground && ( child == mImpl->mBackground->actor ) )
793 // Request for relayout.
796 // Notify derived classes.
797 OnControlChildRemove( child );
800 void Control::OnSizeSet(const Vector3& targetSize)
802 if( ( !mImpl->mLockSetSize ) && ( targetSize != mImpl->mSetSize ) )
804 // Only updates size if set through Actor's API
805 mImpl->mSetSize = targetSize;
808 if( targetSize != mImpl->mSize )
810 // Update control size.
811 mImpl->mSize = targetSize;
813 // Notify derived classes.
814 OnControlSizeSet( targetSize );
818 void Control::OnSizeAnimation(Animation& animation, const Vector3& targetSize)
823 bool Control::OnTouchEvent(const TouchEvent& event)
825 return false; // Do not consume
828 bool Control::OnKeyEvent(const KeyEvent& event)
830 return false; // Do not consume
833 bool Control::OnMouseWheelEvent(const MouseWheelEvent& event)
835 return false; // Do not consume
838 void Control::OnKeyInputFocusGained()
843 void Control::OnKeyInputFocusLost()
848 Actor Control::GetChildByAlias(const std::string& actorAlias)
853 bool Control::OnAccessibilityPan(PanGesture gesture)
855 return false; // Accessibility pan gesture is not handled by default
858 bool Control::OnAccessibilityTouch(const TouchEvent& touchEvent)
860 return false; // Accessibility touch event is not handled by default
863 bool Control::OnAccessibilityValueChange(bool isIncrease)
865 return false; // Accessibility value change action is not handled by default
869 void Control::SetKeyboardNavigationSupport(bool isSupported)
871 mImpl->mIsKeyboardNavigationSupported = isSupported;
874 bool Control::IsKeyboardNavigationSupported()
876 return mImpl->mIsKeyboardNavigationSupported;
879 void Control::SetAsKeyboardFocusGroup(bool isFocusGroup)
881 mImpl->mIsKeyboardFocusGroup = isFocusGroup;
883 // The following line will be removed when the deprecated API in KeyboardFocusManager is deleted
884 Toolkit::KeyboardFocusManager::Get().SetAsFocusGroup(Self(), isFocusGroup);
887 bool Control::IsKeyboardFocusGroup()
889 return Toolkit::KeyboardFocusManager::Get().IsFocusGroup(Self());
892 Actor Control::GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocusNavigationDirection direction, bool loopEnabled)
897 bool Control::DoAction(BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes)
904 void Control::DoActivatedAction(const PropertyValueContainer& attributes)
909 Toolkit::Control::KeyEventSignalV2& Control::KeyEventSignal()
911 return mImpl->mKeyEventSignalV2;
914 void Control::SetSizePolicy( Toolkit::Control::SizePolicy widthPolicy, Toolkit::Control::SizePolicy heightPolicy )
916 bool relayoutRequest( false );
918 if ( ( mImpl->mWidthPolicy != widthPolicy ) || ( mImpl->mHeightPolicy != heightPolicy ) )
920 relayoutRequest = true;
923 mImpl->mWidthPolicy = widthPolicy;
924 mImpl->mHeightPolicy = heightPolicy;
926 // Ensure RelayoutRequest is called AFTER new policies have been set.
927 if ( relayoutRequest )
933 void Control::GetSizePolicy( Toolkit::Control::SizePolicy& widthPolicy, Toolkit::Control::SizePolicy& heightPolicy ) const
935 widthPolicy = mImpl->mWidthPolicy;
936 heightPolicy = mImpl->mHeightPolicy;
939 void Control::SetMinimumSize( const Vector3& size )
941 if ( mImpl->mMinimumSize != size )
943 mImpl->mMinimumSize = size;
945 // Only relayout if our control is using the minimum or range policy.
946 if ( ( mImpl->mHeightPolicy == Toolkit::Control::Minimum ) || ( mImpl->mWidthPolicy == Toolkit::Control::Minimum ) ||
947 ( mImpl->mHeightPolicy == Toolkit::Control::Range ) || ( mImpl->mWidthPolicy == Toolkit::Control::Range ) )
954 const Vector3& Control::GetMinimumSize() const
956 return mImpl->mMinimumSize;
959 void Control::SetMaximumSize( const Vector3& size )
961 if ( mImpl->mMaximumSize != size )
963 mImpl->mMaximumSize = size;
965 // Only relayout if our control is using the maximum or range policy.
966 if ( ( mImpl->mHeightPolicy == Toolkit::Control::Maximum ) || ( mImpl->mWidthPolicy == Toolkit::Control::Maximum ) ||
967 ( mImpl->mHeightPolicy == Toolkit::Control::Range ) || ( mImpl->mWidthPolicy == Toolkit::Control::Range ) )
974 const Vector3& Control::GetMaximumSize() const
976 return mImpl->mMaximumSize;
979 Vector3 Control::GetNaturalSize()
981 // could be overridden in derived classes.
982 return mImpl->mSetSize;
985 float Control::GetHeightForWidth( float width )
987 // could be overridden in derived classes.
988 float height( 0.0f );
989 if ( mImpl->mSetSize.width > 0.0f )
991 height = mImpl->mSetSize.height * width / mImpl->mSetSize.width;
996 float Control::GetWidthForHeight( float height )
998 // could be overridden in derived classes.
1000 if ( mImpl->mSetSize.height > 0.0f )
1002 width = mImpl->mSetSize.width * height / mImpl->mSetSize.height;
1007 const Vector3& Control::GetControlSize() const
1009 return mImpl->mSize;
1012 const Vector3& Control::GetSizeSet() const
1014 return mImpl->mSetSize;
1017 void Control::SetKeyInputFocus()
1019 if( Self().OnStage() )
1021 Toolkit::KeyInputFocusManager::Get().SetFocus(Toolkit::Control::DownCast(Self()));
1025 bool Control::HasKeyInputFocus()
1027 bool result = false;
1028 if( Self().OnStage() )
1030 result = Toolkit::KeyInputFocusManager::Get().IsKeyboardListener(Toolkit::Control::DownCast(Self()));
1035 void Control::ClearKeyInputFocus()
1037 if( Self().OnStage() )
1039 Toolkit::KeyInputFocusManager::Get().RemoveFocus(Toolkit::Control::DownCast(Self()));
1043 void Control::RelayoutRequest()
1045 Internal::RelayoutController::Get().Request();
1048 void Control::Relayout( Vector2 size, ActorSizeContainer& container )
1050 // Avoids relayout again when OnSizeSet callback arrives.
1052 SetSizeLock lock( mImpl->mLockSetSize );
1053 Self().SetSize( size );
1056 // Only relayout controls which requested to be relaid out.
1057 OnRelaidOut( size, container );
1060 void Control::Relayout( Actor actor, Vector2 size, ActorSizeContainer& container )
1064 Toolkit::Control control( Toolkit::Control::DownCast( actor ) );
1067 control.GetImplementation().NegotiateSize( size, container );
1071 container.push_back( ActorSizePair( actor, size ) );
1076 void Control::OnRelaidOut( Vector2 size, ActorSizeContainer& container )
1078 unsigned int numChildren = Self().GetChildCount();
1080 for( unsigned int i=0; i<numChildren; ++i )
1082 container.push_back( ActorSizePair( Self().GetChildAt(i), size ) );
1086 void Control::NegotiateSize( Vector2 allocatedSize, ActorSizeContainer& container )
1090 if ( mImpl->mWidthPolicy == Toolkit::Control::Fixed )
1092 if ( mImpl->mHeightPolicy == Toolkit::Control::Fixed )
1094 // If a control says it has a fixed size, then use the size set by the application / control.
1095 Vector2 setSize( mImpl->mSetSize );
1096 if ( setSize != Vector2::ZERO )
1100 // Policy is set to Fixed, so if the application / control has not set one of the dimensions,
1101 // then we should use the natural size of the control rather than the full allocation.
1102 if ( EqualsZero( size.width ) )
1104 size.width = GetWidthForHeight( size.height );
1106 else if ( EqualsZero( size.height ) )
1108 size.height = GetHeightForWidth( size.width );
1113 // If that is not set then set the size to the control's natural size
1114 size = Vector2( GetNaturalSize() );
1119 // Width is fixed so if the application / control has set it, then use that.
1120 if ( !EqualsZero( mImpl->mSetSize.width ) )
1122 size.width = mImpl->mSetSize.width;
1126 // Otherwise, set the width to what has been allocated.
1127 size.width = allocatedSize.width;
1130 // Height is flexible so ask control what the height should be for our width.
1131 size.height = GetHeightForWidth( size.width );
1133 // Ensure height is within our policy rules
1134 size.height = Calculate( mImpl->mHeightPolicy, mImpl->mMinimumSize.height, mImpl->mMaximumSize.height, size.height );
1139 if ( mImpl->mHeightPolicy == Toolkit::Control::Fixed )
1141 // Height is fixed so if the application / control has set it, then use that.
1142 if ( !EqualsZero( mImpl->mSetSize.height ) )
1144 size.height = mImpl->mSetSize.height;
1148 // Otherwise, set the height to what has been allocated.
1149 size.height = allocatedSize.height;
1152 // Width is flexible so ask control what the width should be for our height.
1153 size.width = GetWidthForHeight( size.height );
1155 // Ensure width is within our policy rules
1156 size.width = Calculate( mImpl->mWidthPolicy, mImpl->mMinimumSize.width, mImpl->mMaximumSize.width, size.width );
1160 // Width and height are BOTH flexible.
1161 // Calculate the width and height using the policy rules.
1162 size.width = Calculate( mImpl->mWidthPolicy, mImpl->mMinimumSize.width, mImpl->mMaximumSize.width, allocatedSize.width );
1163 size.height = Calculate( mImpl->mHeightPolicy, mImpl->mMinimumSize.height, mImpl->mMaximumSize.height, allocatedSize.height );
1167 // If the width has not been set, then set to the allocated width.
1168 // Also if the width set is greater than the allocated, then set to allocated (no exceed support).
1169 if ( EqualsZero( size.width ) || ( size.width > allocatedSize.width ) )
1171 size.width = allocatedSize.width;
1174 // If the height has not been set, then set to the allocated height.
1175 // Also if the height set is greater than the allocated, then set to allocated (no exceed support).
1176 if ( EqualsZero( size.height ) || ( size.height > allocatedSize.height ) )
1178 size.height = allocatedSize.height;
1181 DALI_LOG_INFO( gLogFilter, Debug::Verbose,
1182 "%p: Natural: [%.2f, %.2f] Allocated: [%.2f, %.2f] Set: [%.2f, %.2f]\n",
1183 Self().GetObjectPtr(),
1184 GetNaturalSize().x, GetNaturalSize().y,
1185 allocatedSize.x, allocatedSize.y,
1188 Relayout( size, container );
1191 void Control::OnThemeChange( Toolkit::StyleManager styleManager )
1193 GetImpl( styleManager ).ApplyThemeStyle( GetOwner() );
1196 bool Control::EmitKeyEventSignal( const KeyEvent& event )
1198 // Guard against destruction during signal emission
1199 Dali::Toolkit::Control handle( GetOwner() );
1201 bool consumed = false;
1203 // signals are allocated dynamically when someone connects
1204 if ( !mImpl->mKeyEventSignalV2.Empty() )
1206 consumed = mImpl->mKeyEventSignalV2.Emit( handle, event );
1211 // Notification for derived classes
1212 consumed = OnKeyEvent(event);
1218 void Control::SignalConnected( SlotObserver* slotObserver, CallbackBase* callback )
1220 mImpl->SignalConnected( slotObserver, callback );
1223 void Control::SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback )
1225 mImpl->SignalDisconnected( slotObserver, callback );
1228 std::size_t Control::GetConnectionCount() const
1230 return mImpl->GetConnectionCount();
1233 Control::Control( bool requiresTouchEvents )
1234 : CustomActorImpl( requiresTouchEvents ),
1235 mImpl(new Impl(*this))
1239 Control::Control( ControlBehaviour behaviourFlags )
1240 : CustomActorImpl( behaviourFlags & REQUIRES_TOUCH_EVENTS ),
1241 mImpl(new Impl(*this))
1243 mImpl->mFlags = behaviourFlags;
1246 } // namespace Internal
1248 } // namespace Toolkit