2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <dali-toolkit/public-api/controls/control-impl.h>
22 #include <dali/integration-api/debug.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>
30 #include <dali-toolkit/public-api/styling/style-manager.h>
31 #include <dali-toolkit/internal/styling/style-manager-impl.h>
39 const Property::Index Control::PROPERTY_BACKGROUND_COLOR = Internal::Control::CONTROL_PROPERTY_START_INDEX;
40 const Property::Index Control::PROPERTY_BACKGROUND = Internal::Control::CONTROL_PROPERTY_START_INDEX + 1;
41 const Property::Index Control::PROPERTY_WIDTH_POLICY = Internal::Control::CONTROL_PROPERTY_START_INDEX + 2;
42 const Property::Index Control::PROPERTY_HEIGHT_POLICY = Internal::Control::CONTROL_PROPERTY_START_INDEX + 3;
43 const Property::Index Control::PROPERTY_MINIMUM_SIZE = Internal::Control::CONTROL_PROPERTY_START_INDEX + 4;
44 const Property::Index Control::PROPERTY_MAXIMUM_SIZE = Internal::Control::CONTROL_PROPERTY_START_INDEX + 5;
45 const Property::Index Control::PROPERTY_KEY_INPUT_FOCUS = Internal::Control::CONTROL_PROPERTY_START_INDEX + 6;
50 const Scripting::StringEnum< Control::SizePolicy > SIZE_POLICY_STRING_TABLE[] =
52 { "FIXED", Control::Fixed },
53 { "MINIMUM", Control::Minimum },
54 { "MAXIMUM", Control::Maximum },
55 { "RANGE", Control::Range },
56 { "FLEXIBLE", Control::Flexible },
58 const unsigned int SIZE_POLICY_STRING_TABLE_COUNT = sizeof( SIZE_POLICY_STRING_TABLE ) / sizeof( SIZE_POLICY_STRING_TABLE[0] );
60 #if defined(DEBUG_ENABLED)
61 Integration::Log::Filter* gLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_CONTROL");
64 const float MAX_FLOAT_VALUE( std::numeric_limits<float>::max() );
65 const float BACKGROUND_ACTOR_Z_POSITION( -0.1f );
69 return Internal::Control::New();
72 TypeRegistration CONTROL_TYPE( typeid(Control), typeid(CustomActor), Create );
74 // Property Registration after Internal::Control::Impl definition below
76 TypeAction ACTION_TYPE_1(CONTROL_TYPE, Toolkit::Control::ACTION_CONTROL_ACTIVATED, &Internal::Control::DoAction);
79 * Helper class used to set the Control's size through the Actor's API or through children added.
84 SetSizeLock( bool& lock )
100 * Structure which holds information about the background of a control
104 Actor actor; ///< Either a MeshActor or an ImageActor
105 Vector4 color; ///< The color of the actor.
112 color( Color::WHITE )
118 * Helper function to calculate a dimension given the policy of that dimension; the minimum &
119 * maximum values that dimension can be; and the allocated value for that dimension.
121 * @param[in] policy The size policy for that dimension.
122 * @param[in] minimum The minimum value that dimension can be.
123 * @param[in] maximum The maximum value that dimension can be.
124 * @param[in] allocated The value allocated for that dimension.
126 * @return The value that the dimension should be.
128 * @note This does not handle Control::Fixed policy.
130 float Calculate( Control::SizePolicy policy, float minimum, float maximum, float allocated )
132 float size( allocated );
138 // Use allocated value
142 case Control::Minimum:
144 // Size is always at least the minimum.
145 size = std::max( allocated, minimum );
149 case Control::Maximum:
151 // Size can grow but up to a maximum value.
152 size = std::min( allocated, maximum );
158 // Size is at least the minimum and can grow up to the maximum
159 size = std::max( size, minimum );
160 size = std::min( size, maximum );
164 case Control::Flexible:
166 // Size grows or shrinks with no limits.
173 DALI_ASSERT_DEBUG( false && "This function was not intended to be used by any other policy." );
182 * Creates a white coloured Mesh.
186 Vector3 white( Color::WHITE );
190 // Create vertices with a white color (actual color is set by actor color)
191 MeshData::VertexContainer vertices(4);
192 vertices[ 0 ] = MeshData::Vertex( Vector3( -0.5f, -0.5f, 0.0f ), Vector2::ZERO, white );
193 vertices[ 1 ] = MeshData::Vertex( Vector3( 0.5f, -0.5f, 0.0f ), Vector2::ZERO, white );
194 vertices[ 2 ] = MeshData::Vertex( Vector3( -0.5f, 0.5f, 0.0f ), Vector2::ZERO, white );
195 vertices[ 3 ] = MeshData::Vertex( Vector3( 0.5f, 0.5f, 0.0f ), Vector2::ZERO, white );
197 // Specify all the faces
198 MeshData::FaceIndices faces;
199 faces.reserve( 6 ); // 2 triangles in Quad
200 faces.push_back( 0 ); faces.push_back( 3 ); faces.push_back( 1 );
201 faces.push_back( 0 ); faces.push_back( 2 ); faces.push_back( 3 );
203 // Create the mesh data from the vertices and faces
204 meshData.SetMaterial( Material::New( "ControlMaterial" ) );
205 meshData.SetVertices( vertices );
206 meshData.SetFaceIndices( faces );
207 meshData.SetHasColor( true );
209 return Mesh::New( meshData );
213 * Sets all the required properties for the background actor.
215 * @param[in] actor The actor to set the properties on.
216 * @param[in] constrainingIndex The property index to constrain the parent's size on.
217 * @param[in] color The required color of the actor.
219 void SetupBackgroundActor( Actor actor, Property::Index constrainingIndex, const Vector4& color )
221 actor.SetColor( color );
222 actor.SetPositionInheritanceMode( USE_PARENT_POSITION_PLUS_LOCAL_POSITION );
223 actor.SetZ( BACKGROUND_ACTOR_Z_POSITION );
225 Constraint constraint = Constraint::New<Vector3>( constrainingIndex,
226 ParentSource( Actor::SIZE ),
227 EqualToConstraint() );
228 actor.ApplyConstraint( constraint );
231 } // unnamed namespace
236 class Control::Impl : public ConnectionTrackerInterface
239 // Construction & Destruction
240 Impl(Control& controlImpl)
241 : mControlImpl(controlImpl),
244 mPinchGestureDetector(),
245 mPanGestureDetector(),
246 mTapGestureDetector(),
247 mLongPressGestureDetector(),
248 mStartingPinchScale(),
252 mMaximumSize( MAX_FLOAT_VALUE, MAX_FLOAT_VALUE, MAX_FLOAT_VALUE ),
253 mLockSetSize( false ),
254 mWidthPolicy( Toolkit::Control::Fixed ),
255 mHeightPolicy( Toolkit::Control::Fixed ),
256 mFlags( Control::CONTROL_BEHAVIOUR_NONE ),
257 mIsKeyboardNavigationSupported(false),
258 mIsKeyboardFocusGroup(false),
259 mInitialized( false )
265 // All gesture detectors will be destroyed so no need to disconnect.
272 // Gesture Detection Methods
274 void PinchDetected(Actor actor, PinchGesture pinch)
276 mControlImpl.OnPinch(pinch);
279 void PanDetected(Actor actor, PanGesture pan)
281 mControlImpl.OnPan(pan);
284 void TapDetected(Actor actor, TapGesture tap)
286 mControlImpl.OnTap(tap);
289 void LongPressDetected(Actor actor, LongPressGesture longPress)
291 mControlImpl.OnLongPress(longPress);
295 * @copydoc ConnectionTrackerInterface::SignalConnected
297 virtual void SignalConnected( SlotObserver* slotObserver, CallbackBase* callback )
299 mConnectionTracker.SignalConnected( slotObserver, callback );
303 * @copydoc ConnectionTrackerInterface::SignalDisconnected
305 virtual void SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback )
307 mConnectionTracker.SignalDisconnected( slotObserver, callback );
311 * @copydoc ConnectionTrackerInterface::GetConnectionCount
313 virtual std::size_t GetConnectionCount() const
315 return mConnectionTracker.GetConnectionCount();
318 // Background Methods
321 * Only creates an instance of the background if we actually use it.
322 * @return A reference to the Background structure.
324 Background& GetBackground()
328 mBackground = new Background;
336 * Called when a property of an object of this type is set.
337 * @param[in] object The object whose property is set.
338 * @param[in] index The property index.
339 * @param[in] value The new property value.
341 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
343 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
347 Control& controlImpl( control.GetImplementation() );
351 case Toolkit::Control::PROPERTY_BACKGROUND_COLOR:
353 controlImpl.SetBackgroundColor( value.Get< Vector4 >() );
357 case Toolkit::Control::PROPERTY_BACKGROUND:
359 if ( value.HasKey( "image" ) )
361 Property::Map imageMap = value.GetValue( "image" ).Get< Property::Map >();
362 Image image = Scripting::NewImage( imageMap );
366 controlImpl.SetBackground( image );
369 else if ( value.Get< Property::Map >().empty() )
371 // An empty map means the background is no longer required
372 controlImpl.ClearBackground();
377 case Toolkit::Control::PROPERTY_WIDTH_POLICY:
379 controlImpl.mImpl->mWidthPolicy = Scripting::GetEnumeration< Toolkit::Control::SizePolicy >( value.Get< std::string >(), SIZE_POLICY_STRING_TABLE, SIZE_POLICY_STRING_TABLE_COUNT );
383 case Toolkit::Control::PROPERTY_HEIGHT_POLICY:
385 controlImpl.mImpl->mHeightPolicy = Scripting::GetEnumeration< Toolkit::Control::SizePolicy >( value.Get< std::string >(), SIZE_POLICY_STRING_TABLE, SIZE_POLICY_STRING_TABLE_COUNT );
389 case Toolkit::Control::PROPERTY_MINIMUM_SIZE:
391 controlImpl.SetMinimumSize( value.Get< Vector3 >() );
395 case Toolkit::Control::PROPERTY_MAXIMUM_SIZE:
397 controlImpl.SetMaximumSize( value.Get< Vector3 >() );
401 case Toolkit::Control::PROPERTY_KEY_INPUT_FOCUS:
403 if ( value.Get< bool >() )
405 controlImpl.SetKeyInputFocus();
409 controlImpl.ClearKeyInputFocus();
418 * Called to retrieve a property of an object of this type.
419 * @param[in] object The object whose property is to be retrieved.
420 * @param[in] index The property index.
421 * @return The current value of the property.
423 static Property::Value GetProperty( BaseObject* object, Property::Index index )
425 Property::Value value;
427 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
431 Control& controlImpl( control.GetImplementation() );
435 case Toolkit::Control::PROPERTY_BACKGROUND_COLOR:
437 value = controlImpl.GetBackgroundColor();
441 case Toolkit::Control::PROPERTY_BACKGROUND:
445 Actor actor = controlImpl.GetBackgroundActor();
448 ImageActor imageActor = ImageActor::DownCast( actor );
451 Image image = imageActor.GetImage();
452 Property::Map imageMap;
453 Scripting::CreatePropertyMap( image, imageMap );
454 map.push_back( Property::StringValuePair( "image", imageMap ) );
462 case Toolkit::Control::PROPERTY_WIDTH_POLICY:
464 value = std::string( Scripting::GetEnumerationName< Toolkit::Control::SizePolicy >( controlImpl.mImpl->mWidthPolicy, SIZE_POLICY_STRING_TABLE, SIZE_POLICY_STRING_TABLE_COUNT ) );
468 case Toolkit::Control::PROPERTY_HEIGHT_POLICY:
470 value = std::string( Scripting::GetEnumerationName< Toolkit::Control::SizePolicy >( controlImpl.mImpl->mHeightPolicy, SIZE_POLICY_STRING_TABLE, SIZE_POLICY_STRING_TABLE_COUNT ) );
474 case Toolkit::Control::PROPERTY_MINIMUM_SIZE:
476 value = controlImpl.mImpl->mMinimumSize;
480 case Toolkit::Control::PROPERTY_MAXIMUM_SIZE:
482 value = controlImpl.mImpl->mMaximumSize;
486 case Toolkit::Control::PROPERTY_KEY_INPUT_FOCUS:
488 value = controlImpl.HasKeyInputFocus();
499 Control& mControlImpl;
500 Background* mBackground; ///< Only create the background if we use it
501 ConnectionTracker mConnectionTracker; // signal connection tracker
502 Toolkit::Control::KeyEventSignalV2 mKeyEventSignalV2;
505 PinchGestureDetector mPinchGestureDetector;
506 PanGestureDetector mPanGestureDetector;
507 TapGestureDetector mTapGestureDetector;
508 LongPressGestureDetector mLongPressGestureDetector;
509 Vector3 mStartingPinchScale; ///< The scale when a pinch gesture starts
511 Vector3 mSize; ///< Stores the current control's size.
512 Vector3 mSetSize; ///< Always stores the size set through the Actor's API. Useful when reset to the initial size is needed.
513 Vector3 mMinimumSize; ///< Stores the control's minimum size.
514 Vector3 mMaximumSize; ///< Stores the control's maximum size.
516 bool mLockSetSize; ///< Used to avoid. Can't be a bitfield as a reference to this member is used in SetSizeLock helper class.
518 Toolkit::Control::SizePolicy mWidthPolicy:3; ///< Stores the width policy. 3 bits covers 8 values
519 Toolkit::Control::SizePolicy mHeightPolicy:3; ///< Stores the height policy. 3 bits covers 8 values
520 ControlBehaviour mFlags:4; ///< Flags passed in from constructor. Need to increase this size when new enums are added
521 bool mIsKeyboardNavigationSupported:1; ///< Stores whether keyboard navigation is supported by the control.
522 bool mIsKeyboardFocusGroup:1; ///< Stores whether the control is a focus group.
525 // Properties - these need to be members of Internal::Control::Impl as they need to functions within this class.
526 static PropertyRegistration PROPERTY_1;
527 static PropertyRegistration PROPERTY_2;
528 static PropertyRegistration PROPERTY_3;
529 static PropertyRegistration PROPERTY_4;
530 static PropertyRegistration PROPERTY_5;
531 static PropertyRegistration PROPERTY_6;
532 static PropertyRegistration PROPERTY_7;
535 PropertyRegistration Control::Impl::PROPERTY_1( CONTROL_TYPE, "background-color", Toolkit::Control::PROPERTY_BACKGROUND_COLOR, Property::VECTOR4, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
536 PropertyRegistration Control::Impl::PROPERTY_2( CONTROL_TYPE, "background", Toolkit::Control::PROPERTY_BACKGROUND, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
537 PropertyRegistration Control::Impl::PROPERTY_3( CONTROL_TYPE, "width-policy", Toolkit::Control::PROPERTY_WIDTH_POLICY, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
538 PropertyRegistration Control::Impl::PROPERTY_4( CONTROL_TYPE, "height-policy", Toolkit::Control::PROPERTY_HEIGHT_POLICY, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
539 PropertyRegistration Control::Impl::PROPERTY_5( CONTROL_TYPE, "minimum-size", Toolkit::Control::PROPERTY_MINIMUM_SIZE, Property::VECTOR3, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
540 PropertyRegistration Control::Impl::PROPERTY_6( CONTROL_TYPE, "maximum-size", Toolkit::Control::PROPERTY_MAXIMUM_SIZE, Property::VECTOR3, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
541 PropertyRegistration Control::Impl::PROPERTY_7( CONTROL_TYPE, "key-input-focus", Toolkit::Control::PROPERTY_KEY_INPUT_FOCUS, Property::BOOLEAN, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
543 Toolkit::Control Control::New()
545 // Create the implementation, temporarily owned on stack
546 IntrusivePtr<Control> controlImpl = new Control( CONTROL_BEHAVIOUR_NONE );
548 // Pass ownership to handle
549 Toolkit::Control handle( *controlImpl );
551 // Second-phase init of the implementation
552 // This can only be done after the CustomActor connection has been made...
553 controlImpl->Initialize();
563 void Control::Initialize()
566 // Calling deriving classes
569 if( mImpl->mFlags & REQUIRES_STYLE_CHANGE_SIGNALS )
571 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
573 // Register for style changes
574 styleManager.StyleChangeSignal().Connect( this, &ControlImpl::DoStyleChange );
577 GetImpl( styleManager ).ApplyThemeStyle( GetOwner() );
580 mImpl->mInitialized = true;
583 void Control::EnableGestureDetection(Gesture::Type type)
585 if ( (type & Gesture::Pinch) && !mImpl->mPinchGestureDetector )
587 mImpl->mPinchGestureDetector = PinchGestureDetector::New();
588 mImpl->mPinchGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PinchDetected);
589 mImpl->mPinchGestureDetector.Attach(Self());
592 if ( (type & Gesture::Pan) && !mImpl->mPanGestureDetector )
594 mImpl->mPanGestureDetector = PanGestureDetector::New();
595 mImpl->mPanGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PanDetected);
596 mImpl->mPanGestureDetector.Attach(Self());
599 if ( (type & Gesture::Tap) && !mImpl->mTapGestureDetector )
601 mImpl->mTapGestureDetector = TapGestureDetector::New();
602 mImpl->mTapGestureDetector.DetectedSignal().Connect(mImpl, &Impl::TapDetected);
603 mImpl->mTapGestureDetector.Attach(Self());
606 if ( (type & Gesture::LongPress) && !mImpl->mLongPressGestureDetector )
608 mImpl->mLongPressGestureDetector = LongPressGestureDetector::New();
609 mImpl->mLongPressGestureDetector.DetectedSignal().Connect(mImpl, &Impl::LongPressDetected);
610 mImpl->mLongPressGestureDetector.Attach(Self());
614 void Control::DisableGestureDetection(Gesture::Type type)
616 if ( (type & Gesture::Pinch) && mImpl->mPinchGestureDetector )
618 mImpl->mPinchGestureDetector.Detach(Self());
619 mImpl->mPinchGestureDetector.Reset();
622 if ( (type & Gesture::Pan) && mImpl->mPanGestureDetector )
624 mImpl->mPanGestureDetector.Detach(Self());
625 mImpl->mPanGestureDetector.Reset();
628 if ( (type & Gesture::Tap) && mImpl->mTapGestureDetector )
630 mImpl->mTapGestureDetector.Detach(Self());
631 mImpl->mTapGestureDetector.Reset();
634 if ( (type & Gesture::LongPress) && mImpl->mLongPressGestureDetector)
636 mImpl->mLongPressGestureDetector.Detach(Self());
637 mImpl->mLongPressGestureDetector.Reset();
641 PinchGestureDetector Control::GetPinchGestureDetector() const
643 return mImpl->mPinchGestureDetector;
646 PanGestureDetector Control::GetPanGestureDetector() const
648 return mImpl->mPanGestureDetector;
651 TapGestureDetector Control::GetTapGestureDetector() const
653 return mImpl->mTapGestureDetector;
656 LongPressGestureDetector Control::GetLongPressGestureDetector() const
658 return mImpl->mLongPressGestureDetector;
661 void Control::SetBackgroundColor( const Vector4& color )
663 Background& background( mImpl->GetBackground() );
665 if ( background.actor )
667 // Just set the actor color
668 background.actor.SetColor( color );
673 MeshActor meshActor = MeshActor::New( CreateMesh() );
675 meshActor.SetAffectedByLighting( false );
676 SetupBackgroundActor( meshActor, Actor::SCALE, color );
678 // Set the background actor before adding so that we do not inform deriving classes
679 background.actor = meshActor;
680 Self().Add( meshActor );
683 background.color = color;
686 Vector4 Control::GetBackgroundColor() const
688 if ( mImpl->mBackground )
690 return mImpl->mBackground->color;
692 return Color::TRANSPARENT;
695 void Control::SetBackground( Image image )
697 Background& background( mImpl->GetBackground() );
699 if ( background.actor )
701 // Remove Current actor, unset AFTER removal so that we do not inform deriving classes
702 Self().Remove( background.actor );
703 background.actor = NULL;
706 ImageActor imageActor = ImageActor::New( image );
707 SetupBackgroundActor( imageActor, Actor::SIZE, background.color );
709 // Set the background actor before adding so that we do not inform derived classes
710 background.actor = imageActor;
711 Self().Add( imageActor );
714 void Control::ClearBackground()
716 if ( mImpl->mBackground )
718 Background& background( mImpl->GetBackground() );
719 Self().Remove( background.actor );
721 delete mImpl->mBackground;
722 mImpl->mBackground = NULL;
726 Actor Control::GetBackgroundActor() const
728 if ( mImpl->mBackground )
730 return mImpl->mBackground->actor;
736 void Control::OnThemeChange( Toolkit::StyleManager styleManager )
738 GetImpl( styleManager ).ApplyThemeStyle( GetOwner() );
741 void Control::OnPinch(PinchGesture pinch)
743 if (pinch.state == Gesture::Started)
745 mImpl->mStartingPinchScale = Self().GetCurrentScale();
748 Self().SetScale(mImpl->mStartingPinchScale * pinch.scale);
751 void Control::OnStageConnection()
755 // Notify derived classes.
756 OnControlStageConnection();
759 void Control::OnStageDisconnection()
761 // Notify derived classes
762 OnControlStageDisconnection();
765 void Control::OnChildAdd(Actor& child)
767 // If this is the background actor, then we do not want to relayout or inform deriving classes
768 if ( mImpl->mBackground && ( child == mImpl->mBackground->actor ) )
773 // Request for relayout as we may need to position the new child and old ones
776 // Notify derived classes.
777 OnControlChildAdd( child );
780 void Control::OnChildRemove(Actor& child)
782 // If this is the background actor, then we do not want to relayout or inform deriving classes
783 if ( mImpl->mBackground && ( child == mImpl->mBackground->actor ) )
788 // Request for relayout as we may need to re-position the old child
791 // Notify derived classes.
792 OnControlChildRemove( child );
795 void Control::OnSizeSet(const Vector3& targetSize)
797 if( ( !mImpl->mLockSetSize ) && ( targetSize != mImpl->mSetSize ) )
799 // Only updates size if set through Actor's API
800 mImpl->mSetSize = targetSize;
803 if( targetSize != mImpl->mSize )
805 // Update control size.
806 mImpl->mSize = targetSize;
808 // Notify derived classes.
809 OnControlSizeSet( targetSize );
813 void Control::OnSizeAnimation(Animation& animation, const Vector3& targetSize)
818 bool Control::OnTouchEvent(const TouchEvent& event)
820 return false; // Do not consume
823 bool Control::OnKeyEvent(const KeyEvent& event)
825 return false; // Do not consume
828 bool Control::OnMouseWheelEvent(const MouseWheelEvent& event)
830 return false; // Do not consume
833 void Control::OnKeyInputFocusGained()
838 void Control::OnKeyInputFocusLost()
843 Actor Control::GetChildByAlias(const std::string& actorAlias)
848 bool Control::OnAccessibilityPan(PanGesture gesture)
850 return false; // Accessibility pan gesture is not handled by default
853 bool Control::OnAccessibilityTouch(const TouchEvent& touchEvent)
855 return false; // Accessibility touch event is not handled by default
858 bool Control::OnAccessibilityValueChange(bool isIncrease)
860 return false; // Accessibility value change action is not handled by default
864 void Control::SetKeyboardNavigationSupport(bool isSupported)
866 mImpl->mIsKeyboardNavigationSupported = isSupported;
869 bool Control::IsKeyboardNavigationSupported()
871 return mImpl->mIsKeyboardNavigationSupported;
874 void Control::SetAsKeyboardFocusGroup(bool isFocusGroup)
876 mImpl->mIsKeyboardFocusGroup = isFocusGroup;
878 // The following line will be removed when the deprecated API in KeyboardFocusManager is deleted
879 Toolkit::KeyboardFocusManager::Get().SetAsFocusGroup(Self(), isFocusGroup);
882 bool Control::IsKeyboardFocusGroup()
884 return Toolkit::KeyboardFocusManager::Get().IsFocusGroup(Self());
887 Actor Control::GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocusNavigationDirection direction, bool loopEnabled)
892 bool Control::DoAction(BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes)
896 if( object && (actionName == Toolkit::Control::ACTION_CONTROL_ACTIVATED) )
898 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
901 // if cast succeeds there is an implementation so no need to check
902 control.GetImplementation().OnActivated();
909 void Control::DoStyleChange( Toolkit::StyleManager styleManager, StyleChange change )
911 if( change.themeChange )
913 OnThemeChange( styleManager );
915 else if( change.defaultFontChange || change.defaultFontSizeChange )
917 // This OnStyleChange(StyleChange change ) is deprecated, use OnFontChange instead
918 OnStyleChange( change );
920 OnFontChange( change.defaultFontChange, change.defaultFontSizeChange );
924 Toolkit::Control::KeyEventSignalV2& Control::KeyEventSignal()
926 return mImpl->mKeyEventSignalV2;
929 void Control::SetSizePolicy( Toolkit::Control::SizePolicy widthPolicy, Toolkit::Control::SizePolicy heightPolicy )
931 bool relayoutRequest( false );
933 if ( ( mImpl->mWidthPolicy != widthPolicy ) || ( mImpl->mHeightPolicy != heightPolicy ) )
935 relayoutRequest = true;
938 mImpl->mWidthPolicy = widthPolicy;
939 mImpl->mHeightPolicy = heightPolicy;
941 // Ensure RelayoutRequest is called AFTER new policies have been set.
942 if ( relayoutRequest )
948 void Control::GetSizePolicy( Toolkit::Control::SizePolicy& widthPolicy, Toolkit::Control::SizePolicy& heightPolicy ) const
950 widthPolicy = mImpl->mWidthPolicy;
951 heightPolicy = mImpl->mHeightPolicy;
954 void Control::SetMinimumSize( const Vector3& size )
956 if ( mImpl->mMinimumSize != size )
958 mImpl->mMinimumSize = size;
960 // Only relayout if our control is using the minimum or range policy.
961 if ( ( mImpl->mHeightPolicy == Toolkit::Control::Minimum ) || ( mImpl->mWidthPolicy == Toolkit::Control::Minimum ) ||
962 ( mImpl->mHeightPolicy == Toolkit::Control::Range ) || ( mImpl->mWidthPolicy == Toolkit::Control::Range ) )
969 const Vector3& Control::GetMinimumSize() const
971 return mImpl->mMinimumSize;
974 void Control::SetMaximumSize( const Vector3& size )
976 if ( mImpl->mMaximumSize != size )
978 mImpl->mMaximumSize = size;
980 // Only relayout if our control is using the maximum or range policy.
981 if ( ( mImpl->mHeightPolicy == Toolkit::Control::Maximum ) || ( mImpl->mWidthPolicy == Toolkit::Control::Maximum ) ||
982 ( mImpl->mHeightPolicy == Toolkit::Control::Range ) || ( mImpl->mWidthPolicy == Toolkit::Control::Range ) )
989 const Vector3& Control::GetMaximumSize() const
991 return mImpl->mMaximumSize;
994 Vector3 Control::GetNaturalSize()
996 // could be overridden in derived classes.
997 return mImpl->mSetSize;
1000 float Control::GetHeightForWidth( float width )
1002 // could be overridden in derived classes.
1003 float height( 0.0f );
1004 if ( mImpl->mSetSize.width > 0.0f )
1006 height = mImpl->mSetSize.height * width / mImpl->mSetSize.width;
1011 float Control::GetWidthForHeight( float height )
1013 // could be overridden in derived classes.
1014 float width( 0.0f );
1015 if ( mImpl->mSetSize.height > 0.0f )
1017 width = mImpl->mSetSize.width * height / mImpl->mSetSize.height;
1022 const Vector3& Control::GetControlSize() const
1024 return mImpl->mSize;
1027 const Vector3& Control::GetSizeSet() const
1029 return mImpl->mSetSize;
1032 void Control::SetKeyInputFocus()
1034 if( Self().OnStage() )
1036 Toolkit::KeyInputFocusManager::Get().SetFocus(Toolkit::Control::DownCast(Self()));
1040 bool Control::HasKeyInputFocus()
1042 bool result = false;
1043 if( Self().OnStage() )
1045 result = Toolkit::KeyInputFocusManager::Get().IsKeyboardListener(Toolkit::Control::DownCast(Self()));
1050 void Control::ClearKeyInputFocus()
1052 if( Self().OnStage() )
1054 Toolkit::KeyInputFocusManager::Get().RemoveFocus(Toolkit::Control::DownCast(Self()));
1058 void Control::RelayoutRequest()
1060 // unfortunate double negative but thats to guarantee new controls get size negotiation
1061 // by default and have to "opt-out" if they dont want it
1062 if( !(mImpl->mFlags & NO_SIZE_NEGOTIATION) )
1064 Internal::RelayoutController::Request();
1068 void Control::Relayout( Vector2 size, ActorSizeContainer& container )
1070 // Avoids relayout again when OnSizeSet callback arrives.
1072 SetSizeLock lock( mImpl->mLockSetSize );
1073 Self().SetSize( size );
1076 // Only relayout controls which requested to be relaid out.
1077 OnRelaidOut( size, container );
1080 void Control::Relayout( Actor actor, Vector2 size, ActorSizeContainer& container )
1084 Toolkit::Control control( Toolkit::Control::DownCast( actor ) );
1087 control.GetImplementation().NegotiateSize( size, container );
1091 container.push_back( ActorSizePair( actor, size ) );
1096 void Control::OnRelaidOut( Vector2 size, ActorSizeContainer& container )
1098 unsigned int numChildren = Self().GetChildCount();
1100 for( unsigned int i=0; i<numChildren; ++i )
1102 container.push_back( ActorSizePair( Self().GetChildAt(i), size ) );
1106 void Control::NegotiateSize( Vector2 allocatedSize, ActorSizeContainer& container )
1110 if ( mImpl->mWidthPolicy == Toolkit::Control::Fixed )
1112 if ( mImpl->mHeightPolicy == Toolkit::Control::Fixed )
1114 // If a control says it has a fixed size, then use the size set by the application / control.
1115 Vector2 setSize( mImpl->mSetSize );
1116 if ( setSize != Vector2::ZERO )
1120 // Policy is set to Fixed, so if the application / control has not set one of the dimensions,
1121 // then we should use the natural size of the control rather than the full allocation.
1122 if ( EqualsZero( size.width ) )
1124 size.width = GetWidthForHeight( size.height );
1126 else if ( EqualsZero( size.height ) )
1128 size.height = GetHeightForWidth( size.width );
1133 // If that is not set then set the size to the control's natural size
1134 size = Vector2( GetNaturalSize() );
1139 // Width is fixed so if the application / control has set it, then use that.
1140 if ( !EqualsZero( mImpl->mSetSize.width ) )
1142 size.width = mImpl->mSetSize.width;
1146 // Otherwise, set the width to what has been allocated.
1147 size.width = allocatedSize.width;
1150 // Height is flexible so ask control what the height should be for our width.
1151 size.height = GetHeightForWidth( size.width );
1153 // Ensure height is within our policy rules
1154 size.height = Calculate( mImpl->mHeightPolicy, mImpl->mMinimumSize.height, mImpl->mMaximumSize.height, size.height );
1159 if ( mImpl->mHeightPolicy == Toolkit::Control::Fixed )
1161 // Height is fixed so if the application / control has set it, then use that.
1162 if ( !EqualsZero( mImpl->mSetSize.height ) )
1164 size.height = mImpl->mSetSize.height;
1168 // Otherwise, set the height to what has been allocated.
1169 size.height = allocatedSize.height;
1172 // Width is flexible so ask control what the width should be for our height.
1173 size.width = GetWidthForHeight( size.height );
1175 // Ensure width is within our policy rules
1176 size.width = Calculate( mImpl->mWidthPolicy, mImpl->mMinimumSize.width, mImpl->mMaximumSize.width, size.width );
1180 // Width and height are BOTH flexible.
1181 // Calculate the width and height using the policy rules.
1182 size.width = Calculate( mImpl->mWidthPolicy, mImpl->mMinimumSize.width, mImpl->mMaximumSize.width, allocatedSize.width );
1183 size.height = Calculate( mImpl->mHeightPolicy, mImpl->mMinimumSize.height, mImpl->mMaximumSize.height, allocatedSize.height );
1187 // If the width has not been set, then set to the allocated width.
1188 // Also if the width set is greater than the allocated, then set to allocated (no exceed support).
1189 if ( EqualsZero( size.width ) || ( size.width > allocatedSize.width ) )
1191 size.width = allocatedSize.width;
1194 // If the height has not been set, then set to the allocated height.
1195 // Also if the height set is greater than the allocated, then set to allocated (no exceed support).
1196 if ( EqualsZero( size.height ) || ( size.height > allocatedSize.height ) )
1198 size.height = allocatedSize.height;
1201 DALI_LOG_INFO( gLogFilter, Debug::Verbose,
1202 "%p: Natural: [%.2f, %.2f] Allocated: [%.2f, %.2f] Set: [%.2f, %.2f]\n",
1203 Self().GetObjectPtr(),
1204 GetNaturalSize().x, GetNaturalSize().y,
1205 allocatedSize.x, allocatedSize.y,
1208 Relayout( size, container );
1211 bool Control::EmitKeyEventSignal( const KeyEvent& event )
1213 // Guard against destruction during signal emission
1214 Dali::Toolkit::Control handle( GetOwner() );
1216 bool consumed = false;
1218 // signals are allocated dynamically when someone connects
1219 if ( !mImpl->mKeyEventSignalV2.Empty() )
1221 consumed = mImpl->mKeyEventSignalV2.Emit( handle, event );
1226 // Notification for derived classes
1227 consumed = OnKeyEvent(event);
1233 void Control::SignalConnected( SlotObserver* slotObserver, CallbackBase* callback )
1235 mImpl->SignalConnected( slotObserver, callback );
1238 void Control::SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback )
1240 mImpl->SignalDisconnected( slotObserver, callback );
1243 std::size_t Control::GetConnectionCount() const
1245 return mImpl->GetConnectionCount();
1248 Control::Control( bool requiresTouchEvents )
1249 : CustomActorImpl( requiresTouchEvents ),
1250 mImpl(new Impl(*this))
1254 Control::Control( ControlBehaviour behaviourFlags )
1255 : CustomActorImpl( behaviourFlags & REQUIRES_TOUCH_EVENTS ),
1256 mImpl(new Impl(*this))
1258 mImpl->mFlags = behaviourFlags;
1261 } // namespace Internal
1263 } // namespace Toolkit