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 = ControlImpl::CONTROL_PROPERTY_START_INDEX;
38 const Property::Index Control::PROPERTY_BACKGROUND = ControlImpl::CONTROL_PROPERTY_START_INDEX + 1;
39 const Property::Index Control::PROPERTY_WIDTH_POLICY = ControlImpl::CONTROL_PROPERTY_START_INDEX + 2;
40 const Property::Index Control::PROPERTY_HEIGHT_POLICY = ControlImpl::CONTROL_PROPERTY_START_INDEX + 3;
41 const Property::Index Control::PROPERTY_MINIMUM_SIZE = ControlImpl::CONTROL_PROPERTY_START_INDEX + 4;
42 const Property::Index Control::PROPERTY_MAXIMUM_SIZE = ControlImpl::CONTROL_PROPERTY_START_INDEX + 5;
43 const Property::Index Control::PROPERTY_KEY_INPUT_FOCUS = ControlImpl::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 ControlImpl::New();
70 TypeRegistration CONTROL_TYPE( typeid(Control), typeid(CustomActor), Create );
72 // Property Registration after ControlImpl::Impl definition below
74 TypeAction ACTION_TYPE_1(CONTROL_TYPE, Toolkit::Control::ACTION_CONTROL_ACTIVATED, &ControlImpl::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
231 class ControlImpl::Impl : public ConnectionTrackerInterface
234 // Construction & Destruction
235 Impl(ControlImpl& controlImpl)
236 : mControlImpl(controlImpl),
237 mInitialized( false ),
238 mPinchGestureDetector(),
239 mPanGestureDetector(),
240 mTapGestureDetector(),
241 mLongPressGestureDetector(),
242 mStartingPinchScale(),
243 mLockSetSize( false ),
244 mWidthPolicy( Control::Fixed ),
245 mHeightPolicy( Control::Fixed ),
249 mMaximumSize( MAX_FLOAT_VALUE, MAX_FLOAT_VALUE, MAX_FLOAT_VALUE ),
250 mIsKeyboardNavigationSupported(false),
251 mIsKeyboardFocusGroup(false),
259 // All gesture detectors will be destroyed so no need to disconnect.
266 // Gesture Detection Methods
268 void PinchDetected(Actor actor, PinchGesture pinch)
270 mControlImpl.OnPinch(pinch);
273 void PanDetected(Actor actor, PanGesture pan)
275 mControlImpl.OnPan(pan);
278 void TapDetected(Actor actor, TapGesture tap)
280 mControlImpl.OnTap(tap);
283 void LongPressDetected(Actor actor, LongPressGesture longPress)
285 mControlImpl.OnLongPress(longPress);
289 * @copydoc ConnectionTrackerInterface::SignalConnected
291 virtual void SignalConnected( SlotObserver* slotObserver, CallbackBase* callback )
293 mConnectionTracker.SignalConnected( slotObserver, callback );
297 * @copydoc ConnectionTrackerInterface::SignalDisconnected
299 virtual void SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback )
301 mConnectionTracker.SignalDisconnected( slotObserver, callback );
305 * @copydoc ConnectionTrackerInterface::GetConnectionCount
307 virtual std::size_t GetConnectionCount() const
309 return mConnectionTracker.GetConnectionCount();
312 // Background Methods
315 * Only creates an instance of the background if we actually use it.
316 * @return A reference to the Background structure.
318 Background& GetBackground()
322 mBackground = new Background;
330 * Called when a property of an object of this type is set.
331 * @param[in] object The object whose property is set.
332 * @param[in] index The property index.
333 * @param[in] value The new property value.
335 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
337 Control control = Control::DownCast( BaseHandle( object ) );
341 ControlImpl& controlImpl( control.GetImplementation() );
345 case Control::PROPERTY_BACKGROUND_COLOR:
347 controlImpl.SetBackgroundColor( value.Get< Vector4 >() );
351 case Control::PROPERTY_BACKGROUND:
353 if ( value.HasKey( "image" ) )
355 Property::Map imageMap = value.GetValue( "image" ).Get< Property::Map >();
356 Image image = Scripting::NewImage( imageMap );
360 controlImpl.SetBackground( image );
363 else if ( value.Get< Property::Map >().empty() )
365 // An empty map means the background is no longer required
366 controlImpl.ClearBackground();
371 case Control::PROPERTY_WIDTH_POLICY:
373 controlImpl.mImpl->mWidthPolicy = Scripting::GetEnumeration< Control::SizePolicy >( value.Get< std::string >(), SIZE_POLICY_STRING_TABLE, SIZE_POLICY_STRING_TABLE_COUNT );
377 case Control::PROPERTY_HEIGHT_POLICY:
379 controlImpl.mImpl->mHeightPolicy = Scripting::GetEnumeration< Control::SizePolicy >( value.Get< std::string >(), SIZE_POLICY_STRING_TABLE, SIZE_POLICY_STRING_TABLE_COUNT );
383 case Control::PROPERTY_MINIMUM_SIZE:
385 controlImpl.SetMinimumSize( value.Get< Vector3 >() );
389 case Control::PROPERTY_MAXIMUM_SIZE:
391 controlImpl.SetMaximumSize( value.Get< Vector3 >() );
395 case Control::PROPERTY_KEY_INPUT_FOCUS:
397 if ( value.Get< bool >() )
399 controlImpl.SetKeyInputFocus();
403 controlImpl.ClearKeyInputFocus();
412 * Called to retrieve a property of an object of this type.
413 * @param[in] object The object whose property is to be retrieved.
414 * @param[in] index The property index.
415 * @return The current value of the property.
417 static Property::Value GetProperty( BaseObject* object, Property::Index index )
419 Property::Value value;
421 Control control = Control::DownCast( BaseHandle( object ) );
425 ControlImpl& controlImpl( control.GetImplementation() );
429 case Control::PROPERTY_BACKGROUND_COLOR:
431 value = controlImpl.GetBackgroundColor();
435 case Control::PROPERTY_BACKGROUND:
439 Actor actor = controlImpl.GetBackgroundActor();
442 ImageActor imageActor = ImageActor::DownCast( actor );
445 Image image = imageActor.GetImage();
446 Property::Map imageMap;
447 Scripting::CreatePropertyMap( image, imageMap );
448 map.push_back( Property::StringValuePair( "image", imageMap ) );
456 case Control::PROPERTY_WIDTH_POLICY:
458 value = std::string( Scripting::GetEnumerationName< Control::SizePolicy >( controlImpl.mImpl->mWidthPolicy, SIZE_POLICY_STRING_TABLE, SIZE_POLICY_STRING_TABLE_COUNT ) );
462 case Control::PROPERTY_HEIGHT_POLICY:
464 value = std::string( Scripting::GetEnumerationName< Control::SizePolicy >( controlImpl.mImpl->mHeightPolicy, SIZE_POLICY_STRING_TABLE, SIZE_POLICY_STRING_TABLE_COUNT ) );
468 case Control::PROPERTY_MINIMUM_SIZE:
470 value = controlImpl.mImpl->mMinimumSize;
474 case Control::PROPERTY_MAXIMUM_SIZE:
476 value = controlImpl.mImpl->mMaximumSize;
480 case Control::PROPERTY_KEY_INPUT_FOCUS:
482 value = controlImpl.HasKeyInputFocus();
493 ControlImpl& mControlImpl;
497 ConnectionTracker mConnectionTracker; // signal connection tracker
501 PinchGestureDetector mPinchGestureDetector;
502 PanGestureDetector mPanGestureDetector;
503 TapGestureDetector mTapGestureDetector;
504 LongPressGestureDetector mLongPressGestureDetector;
506 Vector3 mStartingPinchScale; ///< The scale when a pinch gesture starts
508 // Relayout and size negotiation
510 bool mLockSetSize; ///< Used to avoid. Can't be a bitfield as a reference to this member is used in SetSizeLock helper class.
512 Control::SizePolicy mWidthPolicy; ///< Stores the width policy.
513 Control::SizePolicy mHeightPolicy; ///< Stores the height policy.
515 Vector3 mSize; ///< Stores the current control's size.
516 Vector3 mSetSize; ///< Always stores the size set through the Actor's API. Useful when reset to the initial size is needed.
517 Vector3 mMinimumSize; ///< Stores the control's minimum size.
518 Vector3 mMaximumSize; ///< Stores the control's maximum size.
520 bool mIsKeyboardNavigationSupported; ///< Stores whether keyboard navigation is supported by the control.
521 bool mIsKeyboardFocusGroup; ///< Stores whether the control is a focus group.
523 Toolkit::Control::KeyEventSignalV2 mKeyEventSignalV2;
526 Background* mBackground; ///< Only create the background if we use it
528 // Properties - these need to be members of ControlImpl::Impl as they need to functions within this class.
529 static PropertyRegistration PROPERTY_1;
530 static PropertyRegistration PROPERTY_2;
531 static PropertyRegistration PROPERTY_3;
532 static PropertyRegistration PROPERTY_4;
533 static PropertyRegistration PROPERTY_5;
534 static PropertyRegistration PROPERTY_6;
535 static PropertyRegistration PROPERTY_7;
538 PropertyRegistration ControlImpl::Impl::PROPERTY_1( CONTROL_TYPE, "background-color", Control::PROPERTY_BACKGROUND_COLOR, Property::VECTOR4, &ControlImpl::Impl::SetProperty, &ControlImpl::Impl::GetProperty );
539 PropertyRegistration ControlImpl::Impl::PROPERTY_2( CONTROL_TYPE, "background", Control::PROPERTY_BACKGROUND, Property::MAP, &ControlImpl::Impl::SetProperty, &ControlImpl::Impl::GetProperty );
540 PropertyRegistration ControlImpl::Impl::PROPERTY_3( CONTROL_TYPE, "width-policy", Control::PROPERTY_WIDTH_POLICY, Property::STRING, &ControlImpl::Impl::SetProperty, &ControlImpl::Impl::GetProperty );
541 PropertyRegistration ControlImpl::Impl::PROPERTY_4( CONTROL_TYPE, "height-policy", Control::PROPERTY_HEIGHT_POLICY, Property::STRING, &ControlImpl::Impl::SetProperty, &ControlImpl::Impl::GetProperty );
542 PropertyRegistration ControlImpl::Impl::PROPERTY_5( CONTROL_TYPE, "minimum-size", Control::PROPERTY_MINIMUM_SIZE, Property::VECTOR3, &ControlImpl::Impl::SetProperty, &ControlImpl::Impl::GetProperty );
543 PropertyRegistration ControlImpl::Impl::PROPERTY_6( CONTROL_TYPE, "maximum-size", Control::PROPERTY_MAXIMUM_SIZE, Property::VECTOR3, &ControlImpl::Impl::SetProperty, &ControlImpl::Impl::GetProperty );
544 PropertyRegistration ControlImpl::Impl::PROPERTY_7( CONTROL_TYPE, "key-input-focus", Control::PROPERTY_KEY_INPUT_FOCUS, Property::BOOLEAN, &ControlImpl::Impl::SetProperty, &ControlImpl::Impl::GetProperty );
546 Control ControlImpl::New()
548 // Create the implementation, temporarily owned on stack
549 IntrusivePtr<ControlImpl> controlImpl = new ControlImpl( false );
551 // Pass ownership to handle
552 Control handle( *controlImpl );
554 // Second-phase init of the implementation
555 // This can only be done after the CustomActor connection has been made...
556 controlImpl->Initialize();
561 ControlImpl::~ControlImpl()
563 if( mImpl->mInitialized )
565 // Unregister only if control has been initialized.
566 Internal::StyleChangeProcessor::Unregister( this );
571 void ControlImpl::Initialize()
573 // Register with the style change processor so we are informed when the default style changes
574 Internal::StyleChangeProcessor::Register( this );
576 // Calling deriving classes
579 mImpl->mInitialized = true;
582 void ControlImpl::EnableGestureDetection(Gesture::Type type)
584 if ( (type & Gesture::Pinch) && !mImpl->mPinchGestureDetector )
586 mImpl->mPinchGestureDetector = PinchGestureDetector::New();
587 mImpl->mPinchGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PinchDetected);
588 mImpl->mPinchGestureDetector.Attach(Self());
591 if ( (type & Gesture::Pan) && !mImpl->mPanGestureDetector )
593 mImpl->mPanGestureDetector = PanGestureDetector::New();
594 mImpl->mPanGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PanDetected);
595 mImpl->mPanGestureDetector.Attach(Self());
598 if ( (type & Gesture::Tap) && !mImpl->mTapGestureDetector )
600 mImpl->mTapGestureDetector = TapGestureDetector::New();
601 mImpl->mTapGestureDetector.DetectedSignal().Connect(mImpl, &Impl::TapDetected);
602 mImpl->mTapGestureDetector.Attach(Self());
605 if ( (type & Gesture::LongPress) && !mImpl->mLongPressGestureDetector )
607 mImpl->mLongPressGestureDetector = LongPressGestureDetector::New();
608 mImpl->mLongPressGestureDetector.DetectedSignal().Connect(mImpl, &Impl::LongPressDetected);
609 mImpl->mLongPressGestureDetector.Attach(Self());
613 void ControlImpl::DisableGestureDetection(Gesture::Type type)
615 if ( (type & Gesture::Pinch) && mImpl->mPinchGestureDetector )
617 mImpl->mPinchGestureDetector.Detach(Self());
618 mImpl->mPinchGestureDetector.Reset();
621 if ( (type & Gesture::Pan) && mImpl->mPanGestureDetector )
623 mImpl->mPanGestureDetector.Detach(Self());
624 mImpl->mPanGestureDetector.Reset();
627 if ( (type & Gesture::Tap) && mImpl->mTapGestureDetector )
629 mImpl->mTapGestureDetector.Detach(Self());
630 mImpl->mTapGestureDetector.Reset();
633 if ( (type & Gesture::LongPress) && mImpl->mLongPressGestureDetector)
635 mImpl->mLongPressGestureDetector.Detach(Self());
636 mImpl->mLongPressGestureDetector.Reset();
640 PinchGestureDetector ControlImpl::GetPinchGestureDetector() const
642 return mImpl->mPinchGestureDetector;
645 PanGestureDetector ControlImpl::GetPanGestureDetector() const
647 return mImpl->mPanGestureDetector;
650 TapGestureDetector ControlImpl::GetTapGestureDetector() const
652 return mImpl->mTapGestureDetector;
655 LongPressGestureDetector ControlImpl::GetLongPressGestureDetector() const
657 return mImpl->mLongPressGestureDetector;
660 void ControlImpl::SetBackgroundColor( const Vector4& color )
662 Background& background( mImpl->GetBackground() );
664 if ( background.actor )
666 // Just set the actor color
667 background.actor.SetColor( color );
672 MeshActor meshActor = MeshActor::New( CreateMesh() );
674 meshActor.SetAffectedByLighting( false );
675 SetupBackgroundActor( meshActor, Actor::SCALE, color );
677 // Set the background actor before adding so that we do not inform deriving classes
678 background.actor = meshActor;
679 Self().Add( meshActor );
682 background.color = color;
685 Vector4 ControlImpl::GetBackgroundColor() const
687 if ( mImpl->mBackground )
689 return mImpl->mBackground->color;
691 return Color::TRANSPARENT;
694 void ControlImpl::SetBackground( Image image )
696 Background& background( mImpl->GetBackground() );
698 if ( background.actor )
700 // Remove Current actor, unset AFTER removal so that we do not inform deriving classes
701 Self().Remove( background.actor );
702 background.actor = NULL;
705 ImageActor imageActor = ImageActor::New( image );
706 SetupBackgroundActor( imageActor, Actor::SIZE, background.color );
708 // Set the background actor before adding so that we do not inform derived classes
709 background.actor = imageActor;
710 Self().Add( imageActor );
713 void ControlImpl::ClearBackground()
715 if ( mImpl->mBackground )
717 Background& background( mImpl->GetBackground() );
718 Self().Remove( background.actor );
720 delete mImpl->mBackground;
721 mImpl->mBackground = NULL;
725 Actor ControlImpl::GetBackgroundActor() const
727 if ( mImpl->mBackground )
729 return mImpl->mBackground->actor;
735 void ControlImpl::OnPinch(PinchGesture pinch)
737 if (pinch.state == Gesture::Started)
739 mImpl->mStartingPinchScale = Self().GetCurrentScale();
742 Self().SetScale(mImpl->mStartingPinchScale * pinch.scale);
745 void ControlImpl::OnStageConnection()
749 // Notify derived classes.
750 OnControlStageConnection();
753 void ControlImpl::OnStageDisconnection()
755 // Notify derived classes
756 OnControlStageDisconnection();
759 void ControlImpl::OnChildAdd(Actor& child)
761 // If this is the background actor, then we do not want to relayout or inform deriving classes
762 if ( mImpl->mBackground && ( child == mImpl->mBackground->actor ) )
767 // Request for relayout.
770 // Notify derived classes.
771 OnControlChildAdd( child );
774 void ControlImpl::OnChildRemove(Actor& child)
776 // If this is the background actor, then we do not want to relayout or inform deriving classes
777 if ( mImpl->mBackground && ( child == mImpl->mBackground->actor ) )
782 // Request for relayout.
785 // Notify derived classes.
786 OnControlChildRemove( child );
789 void ControlImpl::OnSizeSet(const Vector3& targetSize)
791 if( ( !mImpl->mLockSetSize ) && ( targetSize != mImpl->mSetSize ) )
793 // Only updates size if set through Actor's API
794 mImpl->mSetSize = targetSize;
797 if( targetSize != mImpl->mSize )
799 // Update control size.
800 mImpl->mSize = targetSize;
802 // Notify derived classes.
803 OnControlSizeSet( targetSize );
807 void ControlImpl::OnSizeAnimation(Animation& animation, const Vector3& targetSize)
812 bool ControlImpl::OnTouchEvent(const TouchEvent& event)
814 return false; // Do not consume
817 bool ControlImpl::OnKeyEvent(const KeyEvent& event)
819 return false; // Do not consume
822 bool ControlImpl::OnMouseWheelEvent(const MouseWheelEvent& event)
824 return false; // Do not consume
827 void ControlImpl::OnKeyInputFocusGained()
832 void ControlImpl::OnKeyInputFocusLost()
837 Actor ControlImpl::GetChildByAlias(const std::string& actorAlias)
842 bool ControlImpl::OnAccessibilityPan(PanGesture gesture)
844 return false; // Accessibility pan gesture is not handled by default
847 bool ControlImpl::OnAccessibilityValueChange(bool isIncrease)
849 return false; // Accessibility value change action is not handled by default
853 void ControlImpl::SetKeyboardNavigationSupport(bool isSupported)
855 mImpl->mIsKeyboardNavigationSupported = isSupported;
858 bool ControlImpl::IsKeyboardNavigationSupported()
860 return mImpl->mIsKeyboardNavigationSupported;
863 void ControlImpl::SetAsKeyboardFocusGroup(bool isFocusGroup)
865 mImpl->mIsKeyboardFocusGroup = isFocusGroup;
867 // The following line will be removed when the deprecated API in KeyboardFocusManager is deleted
868 KeyboardFocusManager::Get().SetAsFocusGroup(Self(), isFocusGroup);
871 bool ControlImpl::IsKeyboardFocusGroup()
873 return KeyboardFocusManager::Get().IsFocusGroup(Self());
876 Actor ControlImpl::GetNextKeyboardFocusableActor(Actor currentFocusedActor, Control::KeyboardFocusNavigationDirection direction, bool loopEnabled)
881 bool ControlImpl::DoAction(BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes)
888 void ControlImpl::DoActivatedAction(const PropertyValueContainer& attributes)
893 Toolkit::Control::KeyEventSignalV2& ControlImpl::KeyEventSignal()
895 return mImpl->mKeyEventSignalV2;
898 void ControlImpl::SetSizePolicy( Control::SizePolicy widthPolicy, Control::SizePolicy heightPolicy )
900 bool relayoutRequest( false );
902 if ( ( mImpl->mWidthPolicy != widthPolicy ) || ( mImpl->mHeightPolicy != heightPolicy ) )
904 relayoutRequest = true;
907 mImpl->mWidthPolicy = widthPolicy;
908 mImpl->mHeightPolicy = heightPolicy;
910 // Ensure RelayoutRequest is called AFTER new policies have been set.
911 if ( relayoutRequest )
917 void ControlImpl::GetSizePolicy( Control::SizePolicy& widthPolicy, Control::SizePolicy& heightPolicy ) const
919 widthPolicy = mImpl->mWidthPolicy;
920 heightPolicy = mImpl->mHeightPolicy;
923 void ControlImpl::SetMinimumSize( const Vector3& size )
925 if ( mImpl->mMinimumSize != size )
927 mImpl->mMinimumSize = size;
929 // Only relayout if our control is using the minimum or range policy.
930 if ( ( mImpl->mHeightPolicy == Control::Minimum ) || ( mImpl->mWidthPolicy == Control::Minimum ) ||
931 ( mImpl->mHeightPolicy == Control::Range ) || ( mImpl->mWidthPolicy == Control::Range ) )
938 const Vector3& ControlImpl::GetMinimumSize() const
940 return mImpl->mMinimumSize;
943 void ControlImpl::SetMaximumSize( const Vector3& size )
945 if ( mImpl->mMaximumSize != size )
947 mImpl->mMaximumSize = size;
949 // Only relayout if our control is using the maximum or range policy.
950 if ( ( mImpl->mHeightPolicy == Control::Maximum ) || ( mImpl->mWidthPolicy == Control::Maximum ) ||
951 ( mImpl->mHeightPolicy == Control::Range ) || ( mImpl->mWidthPolicy == Control::Range ) )
958 const Vector3& ControlImpl::GetMaximumSize() const
960 return mImpl->mMaximumSize;
963 Vector3 ControlImpl::GetNaturalSize()
965 // could be overridden in derived classes.
966 return mImpl->mSetSize;
969 float ControlImpl::GetHeightForWidth( float width )
971 // could be overridden in derived classes.
972 float height( 0.0f );
973 if ( mImpl->mSetSize.width > 0.0f )
975 height = mImpl->mSetSize.height * width / mImpl->mSetSize.width;
980 float ControlImpl::GetWidthForHeight( float height )
982 // could be overridden in derived classes.
984 if ( mImpl->mSetSize.height > 0.0f )
986 width = mImpl->mSetSize.width * height / mImpl->mSetSize.height;
991 const Vector3& ControlImpl::GetControlSize() const
996 const Vector3& ControlImpl::GetSizeSet() const
998 return mImpl->mSetSize;
1001 void ControlImpl::SetKeyInputFocus()
1003 if( Self().OnStage() )
1005 KeyInputFocusManager::Get().SetFocus(Control::DownCast(Self()));
1009 bool ControlImpl::HasKeyInputFocus()
1011 bool result = false;
1012 if( Self().OnStage() )
1014 result = KeyInputFocusManager::Get().IsKeyboardListener(Control::DownCast(Self()));
1019 void ControlImpl::ClearKeyInputFocus()
1021 if( Self().OnStage() )
1023 KeyInputFocusManager::Get().RemoveFocus(Control::DownCast(Self()));
1027 void ControlImpl::RelayoutRequest()
1029 Internal::RelayoutController::Get().Request();
1032 void ControlImpl::Relayout( Vector2 size, ActorSizeContainer& container )
1034 // Avoids relayout again when OnSizeSet callback arrives.
1036 SetSizeLock lock( mImpl->mLockSetSize );
1037 Self().SetSize( size );
1040 // Only relayout controls which requested to be relaid out.
1041 OnRelaidOut( size, container );
1044 void ControlImpl::Relayout( Actor actor, Vector2 size, ActorSizeContainer& container )
1048 Control control( Control::DownCast( actor ) );
1051 control.GetImplementation().NegotiateSize( size, container );
1055 container.push_back( ActorSizePair( actor, size ) );
1060 void ControlImpl::OnRelaidOut( Vector2 size, ActorSizeContainer& container )
1062 unsigned int numChildren = Self().GetChildCount();
1064 for( unsigned int i=0; i<numChildren; ++i )
1066 container.push_back( ActorSizePair( Self().GetChildAt(i), size ) );
1070 void ControlImpl::NegotiateSize( Vector2 allocatedSize, ActorSizeContainer& container )
1074 if ( mImpl->mWidthPolicy == Control::Fixed )
1076 if ( mImpl->mHeightPolicy == Control::Fixed )
1078 // If a control says it has a fixed size, then use the size set by the application / control.
1079 Vector2 setSize( mImpl->mSetSize );
1080 if ( setSize != Vector2::ZERO )
1084 // Policy is set to Fixed, so if the application / control has not set one of the dimensions,
1085 // then we should use the natural size of the control rather than the full allocation.
1086 if ( EqualsZero( size.width ) )
1088 size.width = GetWidthForHeight( size.height );
1090 else if ( EqualsZero( size.height ) )
1092 size.height = GetHeightForWidth( size.width );
1097 // If that is not set then set the size to the control's natural size
1098 size = Vector2( GetNaturalSize() );
1103 // Width is fixed so if the application / control has set it, then use that.
1104 if ( !EqualsZero( mImpl->mSetSize.width ) )
1106 size.width = mImpl->mSetSize.width;
1110 // Otherwise, set the width to what has been allocated.
1111 size.width = allocatedSize.width;
1114 // Height is flexible so ask control what the height should be for our width.
1115 size.height = GetHeightForWidth( size.width );
1117 // Ensure height is within our policy rules
1118 size.height = Calculate( mImpl->mHeightPolicy, mImpl->mMinimumSize.height, mImpl->mMaximumSize.height, size.height );
1123 if ( mImpl->mHeightPolicy == Control::Fixed )
1125 // Height is fixed so if the application / control has set it, then use that.
1126 if ( !EqualsZero( mImpl->mSetSize.height ) )
1128 size.height = mImpl->mSetSize.height;
1132 // Otherwise, set the height to what has been allocated.
1133 size.height = allocatedSize.height;
1136 // Width is flexible so ask control what the width should be for our height.
1137 size.width = GetWidthForHeight( size.height );
1139 // Ensure width is within our policy rules
1140 size.width = Calculate( mImpl->mWidthPolicy, mImpl->mMinimumSize.width, mImpl->mMaximumSize.width, size.width );
1144 // Width and height are BOTH flexible.
1145 // Calculate the width and height using the policy rules.
1146 size.width = Calculate( mImpl->mWidthPolicy, mImpl->mMinimumSize.width, mImpl->mMaximumSize.width, allocatedSize.width );
1147 size.height = Calculate( mImpl->mHeightPolicy, mImpl->mMinimumSize.height, mImpl->mMaximumSize.height, allocatedSize.height );
1151 // If the width has not been set, then set to the allocated width.
1152 // Also if the width set is greater than the allocated, then set to allocated (no exceed support).
1153 if ( EqualsZero( size.width ) || ( size.width > allocatedSize.width ) )
1155 size.width = allocatedSize.width;
1158 // If the height has not been set, then set to the allocated height.
1159 // Also if the height set is greater than the allocated, then set to allocated (no exceed support).
1160 if ( EqualsZero( size.height ) || ( size.height > allocatedSize.height ) )
1162 size.height = allocatedSize.height;
1165 DALI_LOG_INFO( gLogFilter, Debug::Verbose,
1166 "%p: Natural: [%.2f, %.2f] Allocated: [%.2f, %.2f] Set: [%.2f, %.2f]\n",
1167 Self().GetObjectPtr(),
1168 GetNaturalSize().x, GetNaturalSize().y,
1169 allocatedSize.x, allocatedSize.y,
1172 Relayout( size, container );
1175 bool ControlImpl::EmitKeyEventSignal( const KeyEvent& event )
1177 // Guard against destruction during signal emission
1178 Dali::Toolkit::Control handle( GetOwner() );
1180 bool consumed = false;
1182 // signals are allocated dynamically when someone connects
1183 if ( !mImpl->mKeyEventSignalV2.Empty() )
1185 consumed = mImpl->mKeyEventSignalV2.Emit( handle, event );
1190 // Notification for derived classes
1191 consumed = OnKeyEvent(event);
1197 void ControlImpl::SignalConnected( SlotObserver* slotObserver, CallbackBase* callback )
1199 mImpl->SignalConnected( slotObserver, callback );
1202 void ControlImpl::SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback )
1204 mImpl->SignalDisconnected( slotObserver, callback );
1207 std::size_t ControlImpl::GetConnectionCount() const
1209 return mImpl->GetConnectionCount();
1212 ControlImpl::ControlImpl( bool requiresTouchEvents )
1213 : CustomActorImpl( requiresTouchEvents ),
1214 mImpl(new Impl(*this))
1218 } // namespace Toolkit