2 * Copyright (c) 2015 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.
19 #include <dali-toolkit/public-api/controls/control-impl.h>
22 #include <cstring> // for strcmp
25 #include <dali/public-api/actors/image-actor.h>
26 #include <dali/public-api/animation/constraint.h>
27 #include <dali/public-api/animation/constraints.h>
28 #include <dali/public-api/object/type-registry.h>
29 #include <dali/devel-api/object/type-registry-helper.h>
30 #include <dali/devel-api/scripting/scripting.h>
31 #include <dali/public-api/size-negotiation/relayout-container.h>
32 #include <dali/integration-api/debug.h>
35 #include <dali-toolkit/devel-api/focus-manager/keyinput-focus-manager.h>
36 #include <dali-toolkit/public-api/focus-manager/keyboard-focus-manager.h>
37 #include <dali-toolkit/public-api/controls/control.h>
38 #include <dali-toolkit/devel-api/styling/style-manager.h>
39 #include <dali-toolkit/internal/styling/style-manager-impl.h>
51 * Creates control through type registry
55 return Internal::Control::New();
59 * Performs actions as requested using the action name.
60 * @param[in] object The object on which to perform the action.
61 * @param[in] actionName The action to perform.
62 * @param[in] attributes The attributes with which to perfrom this action.
63 * @return true if action has been accepted by this control
65 const char* ACTION_CONTROL_ACTIVATED = "control-activated";
66 static bool DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes )
70 if( object && ( 0 == strcmp( actionName.c_str(), ACTION_CONTROL_ACTIVATED ) ) )
72 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
75 // if cast succeeds there is an implementation so no need to check
76 ret = Internal::GetImplementation( control ).OnAccessibilityActivated();
84 * Connects a callback function with the object's signals.
85 * @param[in] object The object providing the signal.
86 * @param[in] tracker Used to disconnect the signal.
87 * @param[in] signalName The signal to connect to.
88 * @param[in] functor A newly allocated FunctorDelegate.
89 * @return True if the signal was connected.
90 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
92 const char* SIGNAL_KEY_EVENT = "key-event";
93 const char* SIGNAL_KEY_INPUT_FOCUS_GAINED = "key-input-focus-gained";
94 const char* SIGNAL_KEY_INPUT_FOCUS_LOST = "key-input-focus-lost";
95 const char* SIGNAL_TAPPED = "tapped";
96 const char* SIGNAL_PANNED = "panned";
97 const char* SIGNAL_PINCHED = "pinched";
98 const char* SIGNAL_LONG_PRESSED = "long-pressed";
99 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
101 Dali::BaseHandle handle( object );
103 bool connected( false );
104 Toolkit::Control control = Toolkit::Control::DownCast( handle );
107 Internal::Control& controlImpl( Internal::GetImplementation( control ) );
110 if ( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_EVENT ) )
112 controlImpl.KeyEventSignal().Connect( tracker, functor );
114 else if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_INPUT_FOCUS_GAINED ) )
116 controlImpl.KeyInputFocusGainedSignal().Connect( tracker, functor );
118 else if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_INPUT_FOCUS_LOST ) )
120 controlImpl.KeyInputFocusLostSignal().Connect( tracker, functor );
122 else if( 0 == strcmp( signalName.c_str(), SIGNAL_TAPPED ) )
124 controlImpl.EnableGestureDetection( Gesture::Tap );
125 controlImpl.GetTapGestureDetector().DetectedSignal().Connect( tracker, functor );
127 else if( 0 == strcmp( signalName.c_str(), SIGNAL_PANNED ) )
129 controlImpl.EnableGestureDetection( Gesture::Pan );
130 controlImpl.GetPanGestureDetector().DetectedSignal().Connect( tracker, functor );
132 else if( 0 == strcmp( signalName.c_str(), SIGNAL_PINCHED ) )
134 controlImpl.EnableGestureDetection( Gesture::Pinch );
135 controlImpl.GetPinchGestureDetector().DetectedSignal().Connect( tracker, functor );
137 else if( 0 == strcmp( signalName.c_str(), SIGNAL_LONG_PRESSED ) )
139 controlImpl.EnableGestureDetection( Gesture::LongPress );
140 controlImpl.GetLongPressGestureDetector().DetectedSignal().Connect( tracker, functor );
146 // Setup signals and actions using the type-registry.
147 DALI_TYPE_REGISTRATION_BEGIN( Control, CustomActor, Create );
149 // Note: Properties are registered separately below.
151 SignalConnectorType registerSignal1( typeRegistration, SIGNAL_KEY_EVENT, &DoConnectSignal );
152 SignalConnectorType registerSignal2( typeRegistration, SIGNAL_KEY_INPUT_FOCUS_GAINED, &DoConnectSignal );
153 SignalConnectorType registerSignal3( typeRegistration, SIGNAL_KEY_INPUT_FOCUS_LOST, &DoConnectSignal );
154 SignalConnectorType registerSignal4( typeRegistration, SIGNAL_TAPPED, &DoConnectSignal );
155 SignalConnectorType registerSignal5( typeRegistration, SIGNAL_PANNED, &DoConnectSignal );
156 SignalConnectorType registerSignal6( typeRegistration, SIGNAL_PINCHED, &DoConnectSignal );
157 SignalConnectorType registerSignal7( typeRegistration, SIGNAL_LONG_PRESSED, &DoConnectSignal );
159 TypeAction registerAction( typeRegistration, ACTION_CONTROL_ACTIVATED, &DoAction );
161 DALI_TYPE_REGISTRATION_END()
164 * Structure which holds information about the background of a control
168 Actor actor; ///< Either a MeshActor or an ImageActor
169 Vector4 color; ///< The color of the actor.
176 color( Color::WHITE )
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 );
210 //return Mesh::New( meshData );
214 * Sets all the required properties for the background actor.
216 * @param[in] actor The actor to set the properties on.
217 * @param[in] color The required color of the actor.
219 void SetupBackgroundActor( Actor actor, const Vector4& color )
221 actor.SetColor( color );
222 actor.SetPositionInheritanceMode( USE_PARENT_POSITION_PLUS_LOCAL_POSITION );
223 actor.SetColorMode( USE_OWN_MULTIPLY_PARENT_COLOR );
224 actor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
228 * Sets all the required properties for the background actor.
230 * @param[in] actor The actor to set the properties on.
231 * @param[in] constrainingIndex The property index to constrain the parent's size on.
232 * @param[in] color The required color of the actor.
234 void SetupBackgroundActorConstrained( Actor actor, Property::Index constrainingIndex, const Vector4& color )
236 actor.SetColor( color );
237 actor.SetPositionInheritanceMode( USE_PARENT_POSITION_PLUS_LOCAL_POSITION );
238 actor.SetColorMode( USE_OWN_MULTIPLY_PARENT_COLOR );
240 Constraint constraint = Constraint::New<Vector3>( actor,
242 EqualToConstraint() );
243 constraint.AddSource( ParentSource( Actor::Property::SIZE ) );
247 } // unnamed namespace
252 class Control::Impl : public ConnectionTracker
256 // Construction & Destruction
257 Impl(Control& controlImpl)
258 : mControlImpl( controlImpl ),
261 mStartingPinchScale( NULL ),
263 mPinchGestureDetector(),
264 mPanGestureDetector(),
265 mTapGestureDetector(),
266 mLongPressGestureDetector(),
267 mFlags( Control::ControlBehaviour( ACTOR_BEHAVIOUR_NONE ) ),
268 mIsKeyboardNavigationSupported( false ),
269 mIsKeyboardFocusGroup( false ),
270 mAddRemoveBackgroundChild( false )
276 // All gesture detectors will be destroyed so no need to disconnect.
278 delete mStartingPinchScale;
281 // Gesture Detection Methods
283 void PinchDetected(Actor actor, const PinchGesture& pinch)
285 mControlImpl.OnPinch(pinch);
288 void PanDetected(Actor actor, const PanGesture& pan)
290 mControlImpl.OnPan(pan);
293 void TapDetected(Actor actor, const TapGesture& tap)
295 mControlImpl.OnTap(tap);
298 void LongPressDetected(Actor actor, const LongPressGesture& longPress)
300 mControlImpl.OnLongPress(longPress);
303 // Background Methods
306 * Only creates an instance of the background if we actually use it.
307 * @return A reference to the Background structure.
309 Background& GetBackground()
313 mBackground = new Background;
321 * Called when a property of an object of this type is set.
322 * @param[in] object The object whose property is set.
323 * @param[in] index The property index.
324 * @param[in] value The new property value.
326 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
328 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
332 Control& controlImpl( GetImplementation( control ) );
336 case Toolkit::Control::Property::STYLE_NAME:
338 controlImpl.SetStyleName( value.Get< std::string >() );
342 case Toolkit::Control::Property::BACKGROUND_COLOR:
344 controlImpl.SetBackgroundColor( value.Get< Vector4 >() );
348 case Toolkit::Control::Property::BACKGROUND_IMAGE:
350 if ( value.HasKey( "image" ) )
352 Property::Map imageMap = value.GetValue( "image" ).Get< Property::Map >();
353 Image image = Scripting::NewImage( imageMap );
357 controlImpl.SetBackgroundImage( image );
360 else if ( value.Get< Property::Map >().Empty() )
362 // An empty map means the background is no longer required
363 controlImpl.ClearBackground();
368 case Toolkit::Control::Property::KEY_INPUT_FOCUS:
370 if ( value.Get< bool >() )
372 controlImpl.SetKeyInputFocus();
376 controlImpl.ClearKeyInputFocus();
385 * Called to retrieve a property of an object of this type.
386 * @param[in] object The object whose property is to be retrieved.
387 * @param[in] index The property index.
388 * @return The current value of the property.
390 static Property::Value GetProperty( BaseObject* object, Property::Index index )
392 Property::Value value;
394 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
398 Control& controlImpl( GetImplementation( control ) );
402 case Toolkit::Control::Property::STYLE_NAME:
404 value = controlImpl.GetStyleName();
408 case Toolkit::Control::Property::BACKGROUND_COLOR:
410 value = controlImpl.GetBackgroundColor();
414 case Toolkit::Control::Property::BACKGROUND_IMAGE:
418 Background* back = controlImpl.mImpl->mBackground;
421 ImageActor imageActor = ImageActor::DownCast( back->actor );
424 Image image = imageActor.GetImage();
425 Property::Map imageMap;
426 Scripting::CreatePropertyMap( image, imageMap );
427 map[ "image" ] = imageMap;
435 case Toolkit::Control::Property::KEY_INPUT_FOCUS:
437 value = controlImpl.HasKeyInputFocus();
448 Control& mControlImpl;
449 std::string mStyleName;
450 Background* mBackground; ///< Only create the background if we use it
451 Vector3* mStartingPinchScale; ///< The scale when a pinch gesture starts, TODO: consider removing this
452 Toolkit::Control::KeyEventSignalType mKeyEventSignal;
453 Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusGainedSignal;
454 Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusLostSignal;
457 PinchGestureDetector mPinchGestureDetector;
458 PanGestureDetector mPanGestureDetector;
459 TapGestureDetector mTapGestureDetector;
460 LongPressGestureDetector mLongPressGestureDetector;
462 ControlBehaviour mFlags :CONTROL_BEHAVIOUR_FLAG_COUNT; ///< Flags passed in from constructor.
463 bool mIsKeyboardNavigationSupported :1; ///< Stores whether keyboard navigation is supported by the control.
464 bool mIsKeyboardFocusGroup :1; ///< Stores whether the control is a focus group.
465 bool mAddRemoveBackgroundChild:1; ///< Flag to know when we are adding or removing our own actor to avoid call to OnControlChildAdd
467 // Properties - these need to be members of Internal::Control::Impl as they need to function within this class.
468 static PropertyRegistration PROPERTY_1;
469 static PropertyRegistration PROPERTY_2;
470 static PropertyRegistration PROPERTY_3;
471 static PropertyRegistration PROPERTY_4;
474 // Properties registered without macro to use specific member variables.
475 PropertyRegistration Control::Impl::PROPERTY_1( typeRegistration, "style-name", Toolkit::Control::Property::STYLE_NAME, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
476 PropertyRegistration Control::Impl::PROPERTY_2( typeRegistration, "background-color", Toolkit::Control::Property::BACKGROUND_COLOR, Property::VECTOR4, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
477 PropertyRegistration Control::Impl::PROPERTY_3( typeRegistration, "background-image", Toolkit::Control::Property::BACKGROUND_IMAGE, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
478 PropertyRegistration Control::Impl::PROPERTY_4( typeRegistration, "key-input-focus", Toolkit::Control::Property::KEY_INPUT_FOCUS, Property::BOOLEAN, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
480 Toolkit::Control Control::New()
482 // Create the implementation, temporarily owned on stack
483 IntrusivePtr<Control> controlImpl = new Control( ControlBehaviour( ACTOR_BEHAVIOUR_NONE ) );
485 // Pass ownership to handle
486 Toolkit::Control handle( *controlImpl );
488 // Second-phase init of the implementation
489 // This can only be done after the CustomActor connection has been made...
490 controlImpl->Initialize();
500 void Control::SetStyleName( const std::string& styleName )
502 if( styleName != mImpl->mStyleName )
504 mImpl->mStyleName = styleName;
507 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
508 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
512 const std::string& Control::GetStyleName() const
514 return mImpl->mStyleName;
517 void Control::SetBackgroundColor( const Vector4& color )
519 Background& background( mImpl->GetBackground() );
521 if ( background.actor )
523 // Just set the actor color
524 background.actor.SetColor( color );
530 MeshActor meshActor = MeshActor::New( CreateMesh() );
532 SetupBackgroundActorConstrained( meshActor, Actor::Property::SCALE, color );
534 background.actor = meshActor;
535 // Set the flag to avoid notifying children
536 mImpl->mAddRemoveBackgroundChild = true;
537 // use insert to guarantee its the first child (so that OVERLAY mode works)
538 Self().Insert( 0, meshActor );
539 mImpl->mAddRemoveBackgroundChild = false;
543 background.color = color;
546 Vector4 Control::GetBackgroundColor() const
548 if ( mImpl->mBackground )
550 return mImpl->mBackground->color;
552 return Color::TRANSPARENT;
555 void Control::SetBackgroundImage( Image image )
557 Background& background( mImpl->GetBackground() );
559 if ( background.actor )
561 // Remove Current actor, unset AFTER removal
562 mImpl->mAddRemoveBackgroundChild = true;
563 Self().Remove( background.actor );
564 mImpl->mAddRemoveBackgroundChild = false;
565 background.actor.Reset();
569 ImageActor imageActor = ImageActor::New( image );
570 SetupBackgroundActor( imageActor, background.color );
572 // Set the background actor before adding so that we do not inform derived classes
573 background.actor = imageActor;
574 mImpl->mAddRemoveBackgroundChild = true;
575 // use insert to guarantee its the first child (so that OVERLAY mode works)
576 Self().Insert( 0, imageActor );
577 mImpl->mAddRemoveBackgroundChild = false;
581 void Control::ClearBackground()
583 if ( mImpl->mBackground )
585 Background& background( mImpl->GetBackground() );
586 mImpl->mAddRemoveBackgroundChild = true;
587 Self().Remove( background.actor );
588 mImpl->mAddRemoveBackgroundChild = false;
590 delete mImpl->mBackground;
591 mImpl->mBackground = NULL;
595 void Control::EnableGestureDetection(Gesture::Type type)
597 if ( (type & Gesture::Pinch) && !mImpl->mPinchGestureDetector )
599 mImpl->mPinchGestureDetector = PinchGestureDetector::New();
600 mImpl->mPinchGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PinchDetected);
601 mImpl->mPinchGestureDetector.Attach(Self());
604 if ( (type & Gesture::Pan) && !mImpl->mPanGestureDetector )
606 mImpl->mPanGestureDetector = PanGestureDetector::New();
607 mImpl->mPanGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PanDetected);
608 mImpl->mPanGestureDetector.Attach(Self());
611 if ( (type & Gesture::Tap) && !mImpl->mTapGestureDetector )
613 mImpl->mTapGestureDetector = TapGestureDetector::New();
614 mImpl->mTapGestureDetector.DetectedSignal().Connect(mImpl, &Impl::TapDetected);
615 mImpl->mTapGestureDetector.Attach(Self());
618 if ( (type & Gesture::LongPress) && !mImpl->mLongPressGestureDetector )
620 mImpl->mLongPressGestureDetector = LongPressGestureDetector::New();
621 mImpl->mLongPressGestureDetector.DetectedSignal().Connect(mImpl, &Impl::LongPressDetected);
622 mImpl->mLongPressGestureDetector.Attach(Self());
626 void Control::DisableGestureDetection(Gesture::Type type)
628 if ( (type & Gesture::Pinch) && mImpl->mPinchGestureDetector )
630 mImpl->mPinchGestureDetector.Detach(Self());
631 mImpl->mPinchGestureDetector.Reset();
634 if ( (type & Gesture::Pan) && mImpl->mPanGestureDetector )
636 mImpl->mPanGestureDetector.Detach(Self());
637 mImpl->mPanGestureDetector.Reset();
640 if ( (type & Gesture::Tap) && mImpl->mTapGestureDetector )
642 mImpl->mTapGestureDetector.Detach(Self());
643 mImpl->mTapGestureDetector.Reset();
646 if ( (type & Gesture::LongPress) && mImpl->mLongPressGestureDetector)
648 mImpl->mLongPressGestureDetector.Detach(Self());
649 mImpl->mLongPressGestureDetector.Reset();
653 PinchGestureDetector Control::GetPinchGestureDetector() const
655 return mImpl->mPinchGestureDetector;
658 PanGestureDetector Control::GetPanGestureDetector() const
660 return mImpl->mPanGestureDetector;
663 TapGestureDetector Control::GetTapGestureDetector() const
665 return mImpl->mTapGestureDetector;
668 LongPressGestureDetector Control::GetLongPressGestureDetector() const
670 return mImpl->mLongPressGestureDetector;
673 void Control::SetKeyboardNavigationSupport(bool isSupported)
675 mImpl->mIsKeyboardNavigationSupported = isSupported;
678 bool Control::IsKeyboardNavigationSupported()
680 return mImpl->mIsKeyboardNavigationSupported;
683 void Control::SetKeyInputFocus()
685 if( Self().OnStage() )
687 Toolkit::KeyInputFocusManager::Get().SetFocus(Toolkit::Control::DownCast(Self()));
691 bool Control::HasKeyInputFocus()
694 if( Self().OnStage() )
696 result = Toolkit::KeyInputFocusManager::Get().IsKeyboardListener(Toolkit::Control::DownCast(Self()));
701 void Control::ClearKeyInputFocus()
703 if( Self().OnStage() )
705 Toolkit::KeyInputFocusManager::Get().RemoveFocus(Toolkit::Control::DownCast(Self()));
709 void Control::SetAsKeyboardFocusGroup(bool isFocusGroup)
711 mImpl->mIsKeyboardFocusGroup = isFocusGroup;
713 // The following line will be removed when the deprecated API in KeyboardFocusManager is deleted
714 Toolkit::KeyboardFocusManager::Get().SetAsFocusGroup(Self(), isFocusGroup);
717 bool Control::IsKeyboardFocusGroup()
719 return Toolkit::KeyboardFocusManager::Get().IsFocusGroup(Self());
722 void Control::AccessibilityActivate()
724 // Inform deriving classes
725 OnAccessibilityActivated();
728 bool Control::OnAccessibilityActivated()
730 return false; // Accessibility activation is not handled by default
733 bool Control::OnAccessibilityPan(PanGesture gesture)
735 return false; // Accessibility pan gesture is not handled by default
738 bool Control::OnAccessibilityTouch(const TouchEvent& touchEvent)
740 return false; // Accessibility touch event is not handled by default
743 bool Control::OnAccessibilityValueChange(bool isIncrease)
745 return false; // Accessibility value change action is not handled by default
748 Actor Control::GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocus::Direction direction, bool loopEnabled)
753 void Control::OnKeyboardFocusChangeCommitted(Actor commitedFocusableActor)
757 Toolkit::Control::KeyEventSignalType& Control::KeyEventSignal()
759 return mImpl->mKeyEventSignal;
762 Toolkit::Control::KeyInputFocusSignalType& Control:: KeyInputFocusGainedSignal()
764 return mImpl->mKeyInputFocusGainedSignal;
767 Toolkit::Control::KeyInputFocusSignalType& Control:: KeyInputFocusLostSignal()
769 return mImpl->mKeyInputFocusLostSignal;
772 bool Control::EmitKeyEventSignal( const KeyEvent& event )
774 // Guard against destruction during signal emission
775 Dali::Toolkit::Control handle( GetOwner() );
777 bool consumed = false;
779 // signals are allocated dynamically when someone connects
780 if ( !mImpl->mKeyEventSignal.Empty() )
782 consumed = mImpl->mKeyEventSignal.Emit( handle, event );
787 // Notification for derived classes
788 consumed = OnKeyEvent(event);
794 Control::Control( ControlBehaviour behaviourFlags )
795 : CustomActorImpl( static_cast< ActorFlags >( behaviourFlags ) ),
796 mImpl(new Impl(*this))
798 mImpl->mFlags = behaviourFlags;
801 void Control::Initialize()
803 if( mImpl->mFlags & REQUIRES_STYLE_CHANGE_SIGNALS )
805 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
807 // Register for style changes
808 styleManager.StyleChangeSignal().Connect( this, &Control::OnStyleChange );
811 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
814 if( mImpl->mFlags & REQUIRES_KEYBOARD_NAVIGATION_SUPPORT )
816 SetKeyboardNavigationSupport( true );
819 // Calling deriving classes
823 void Control::OnInitialize()
827 void Control::OnControlChildAdd( Actor& child )
831 void Control::OnControlChildRemove( Actor& child )
835 void Control::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
837 // By default the control is only interested in theme (not font) changes
838 if( change == StyleChange::THEME_CHANGE )
840 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
844 void Control::OnPinch(const PinchGesture& pinch)
846 if( !( mImpl->mStartingPinchScale ) )
849 mImpl->mStartingPinchScale = new Vector3;
852 if( pinch.state == Gesture::Started )
854 *( mImpl->mStartingPinchScale ) = Self().GetCurrentScale();
857 Self().SetScale( *( mImpl->mStartingPinchScale ) * pinch.scale );
860 void Control::OnPan( const PanGesture& pan )
864 void Control::OnTap(const TapGesture& tap)
868 void Control::OnLongPress( const LongPressGesture& longPress )
872 void Control::EmitKeyInputFocusSignal( bool focusGained )
874 Dali::Toolkit::Control handle( GetOwner() );
878 // signals are allocated dynamically when someone connects
879 if ( !mImpl->mKeyInputFocusGainedSignal.Empty() )
881 mImpl->mKeyInputFocusGainedSignal.Emit( handle );
886 // signals are allocated dynamically when someone connects
887 if ( !mImpl->mKeyInputFocusLostSignal.Empty() )
889 mImpl->mKeyInputFocusLostSignal.Emit( handle );
894 void Control::OnStageConnection()
898 void Control::OnStageDisconnection()
902 void Control::OnKeyInputFocusGained()
904 EmitKeyInputFocusSignal( true );
907 void Control::OnKeyInputFocusLost()
909 EmitKeyInputFocusSignal( false );
912 void Control::OnChildAdd(Actor& child)
914 // If this is the background actor, then we do not want to inform deriving classes
915 if ( mImpl->mAddRemoveBackgroundChild )
920 // Notify derived classes.
921 OnControlChildAdd( child );
924 void Control::OnChildRemove(Actor& child)
926 // If this is the background actor, then we do not want to inform deriving classes
927 if ( mImpl->mAddRemoveBackgroundChild )
932 // Notify derived classes.
933 OnControlChildRemove( child );
936 void Control::OnSizeSet(const Vector3& targetSize)
938 // Background is resized through size negotiation
941 void Control::OnSizeAnimation(Animation& animation, const Vector3& targetSize)
943 // @todo size negotiate background to new size, animate as well?
946 bool Control::OnTouchEvent(const TouchEvent& event)
948 return false; // Do not consume
951 bool Control::OnHoverEvent(const HoverEvent& event)
953 return false; // Do not consume
956 bool Control::OnKeyEvent(const KeyEvent& event)
958 return false; // Do not consume
961 bool Control::OnWheelEvent(const WheelEvent& event)
963 return false; // Do not consume
966 void Control::OnRelayout( const Vector2& size, RelayoutContainer& container )
968 for( unsigned int i = 0, numChildren = Self().GetChildCount(); i < numChildren; ++i )
970 container.Add( Self().GetChildAt( i ), size );
974 void Control::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
978 Vector3 Control::GetNaturalSize()
980 if( mImpl->mBackground )
982 Actor actor = mImpl->mBackground->actor;
985 return actor.GetNaturalSize();
991 float Control::CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension )
993 return CalculateChildSizeBase( child, dimension );
996 float Control::GetHeightForWidth( float width )
998 if( mImpl->mBackground )
1000 Actor actor = mImpl->mBackground->actor;
1003 return actor.GetHeightForWidth( width );
1006 return GetHeightForWidthBase( width );
1009 float Control::GetWidthForHeight( float height )
1011 if( mImpl->mBackground )
1013 Actor actor = mImpl->mBackground->actor;
1016 return actor.GetWidthForHeight( height );
1019 return GetWidthForHeightBase( height );
1022 bool Control::RelayoutDependentOnChildren( Dimension::Type dimension )
1024 return RelayoutDependentOnChildrenBase( dimension );
1027 void Control::OnCalculateRelayoutSize( Dimension::Type dimension )
1031 void Control::OnLayoutNegotiated( float size, Dimension::Type dimension )
1035 void Control::SignalConnected( SlotObserver* slotObserver, CallbackBase* callback )
1037 mImpl->SignalConnected( slotObserver, callback );
1040 void Control::SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback )
1042 mImpl->SignalDisconnected( slotObserver, callback );
1045 Control& GetImplementation( Dali::Toolkit::Control& handle )
1047 CustomActorImpl& customInterface = handle.GetImplementation();
1048 // downcast to control
1049 Control& impl = dynamic_cast< Internal::Control& >( customInterface );
1053 const Control& GetImplementation( const Dali::Toolkit::Control& handle )
1055 const CustomActorImpl& customInterface = handle.GetImplementation();
1056 // downcast to control
1057 const Control& impl = dynamic_cast< const Internal::Control& >( customInterface );
1061 } // namespace Internal
1063 } // namespace Toolkit