2 * Copyright (c) 2016 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/animation/constraint.h>
26 #include <dali/public-api/animation/constraints.h>
27 #include <dali/public-api/object/type-registry.h>
28 #include <dali/public-api/object/type-registry-helper.h>
29 #include <dali/public-api/rendering/renderer.h>
30 #include <dali/public-api/size-negotiation/relayout-container.h>
31 #include <dali/devel-api/common/owner-container.h>
32 #include <dali/devel-api/scripting/scripting.h>
33 #include <dali/integration-api/debug.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/public-api/styling/style-manager.h>
39 #include <dali-toolkit/public-api/visuals/color-visual-properties.h>
40 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
41 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
42 #include <dali-toolkit/devel-api/focus-manager/keyinput-focus-manager.h>
43 #include <dali-toolkit/internal/styling/style-manager-impl.h>
44 #include <dali-toolkit/internal/visuals/color/color-visual.h>
56 * Struct used to store Visual within the control, index is a unique key for each visual.
58 struct RegisteredVisual
60 Property::Index index;
61 Toolkit::Visual::Base visual;
64 RegisteredVisual( Property::Index aIndex, Toolkit::Visual::Base &aVisual, Actor &aPlacementActor) : index(aIndex), visual(aVisual), placementActor(aPlacementActor) {}
67 typedef Dali::OwnerContainer< RegisteredVisual* > RegisteredVisuals;
70 * Finds visual in given array, returning true if found along with the iterator for that visual as a out parameter
72 bool FindVisual( Property::Index targetIndex, RegisteredVisuals& visuals, RegisteredVisuals::Iterator& iter )
74 for ( iter = visuals.Begin(); iter != visuals.End(); iter++ )
76 if ( (*iter)->index == targetIndex )
85 * Creates control through type registry
89 return Internal::Control::New();
93 * Performs actions as requested using the action name.
94 * @param[in] object The object on which to perform the action.
95 * @param[in] actionName The action to perform.
96 * @param[in] attributes The attributes with which to perfrom this action.
97 * @return true if action has been accepted by this control
99 const char* ACTION_ACCESSIBILITY_ACTIVATED = "accessibilityActivated";
100 static bool DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes )
104 if( object && ( 0 == strcmp( actionName.c_str(), ACTION_ACCESSIBILITY_ACTIVATED ) ) )
106 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
109 // if cast succeeds there is an implementation so no need to check
110 ret = Internal::GetImplementation( control ).OnAccessibilityActivated();
118 * Connects a callback function with the object's signals.
119 * @param[in] object The object providing the signal.
120 * @param[in] tracker Used to disconnect the signal.
121 * @param[in] signalName The signal to connect to.
122 * @param[in] functor A newly allocated FunctorDelegate.
123 * @return True if the signal was connected.
124 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
126 const char* SIGNAL_KEY_EVENT = "keyEvent";
127 const char* SIGNAL_KEY_INPUT_FOCUS_GAINED = "keyInputFocusGained";
128 const char* SIGNAL_KEY_INPUT_FOCUS_LOST = "keyInputFocusLost";
129 const char* SIGNAL_TAPPED = "tapped";
130 const char* SIGNAL_PANNED = "panned";
131 const char* SIGNAL_PINCHED = "pinched";
132 const char* SIGNAL_LONG_PRESSED = "longPressed";
133 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
135 Dali::BaseHandle handle( object );
137 bool connected( false );
138 Toolkit::Control control = Toolkit::Control::DownCast( handle );
141 Internal::Control& controlImpl( Internal::GetImplementation( control ) );
144 if ( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_EVENT ) )
146 controlImpl.KeyEventSignal().Connect( tracker, functor );
148 else if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_INPUT_FOCUS_GAINED ) )
150 controlImpl.KeyInputFocusGainedSignal().Connect( tracker, functor );
152 else if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_INPUT_FOCUS_LOST ) )
154 controlImpl.KeyInputFocusLostSignal().Connect( tracker, functor );
156 else if( 0 == strcmp( signalName.c_str(), SIGNAL_TAPPED ) )
158 controlImpl.EnableGestureDetection( Gesture::Tap );
159 controlImpl.GetTapGestureDetector().DetectedSignal().Connect( tracker, functor );
161 else if( 0 == strcmp( signalName.c_str(), SIGNAL_PANNED ) )
163 controlImpl.EnableGestureDetection( Gesture::Pan );
164 controlImpl.GetPanGestureDetector().DetectedSignal().Connect( tracker, functor );
166 else if( 0 == strcmp( signalName.c_str(), SIGNAL_PINCHED ) )
168 controlImpl.EnableGestureDetection( Gesture::Pinch );
169 controlImpl.GetPinchGestureDetector().DetectedSignal().Connect( tracker, functor );
171 else if( 0 == strcmp( signalName.c_str(), SIGNAL_LONG_PRESSED ) )
173 controlImpl.EnableGestureDetection( Gesture::LongPress );
174 controlImpl.GetLongPressGestureDetector().DetectedSignal().Connect( tracker, functor );
180 // Setup signals and actions using the type-registry.
181 DALI_TYPE_REGISTRATION_BEGIN( Control, CustomActor, Create );
183 // Note: Properties are registered separately below.
185 SignalConnectorType registerSignal1( typeRegistration, SIGNAL_KEY_EVENT, &DoConnectSignal );
186 SignalConnectorType registerSignal2( typeRegistration, SIGNAL_KEY_INPUT_FOCUS_GAINED, &DoConnectSignal );
187 SignalConnectorType registerSignal3( typeRegistration, SIGNAL_KEY_INPUT_FOCUS_LOST, &DoConnectSignal );
188 SignalConnectorType registerSignal4( typeRegistration, SIGNAL_TAPPED, &DoConnectSignal );
189 SignalConnectorType registerSignal5( typeRegistration, SIGNAL_PANNED, &DoConnectSignal );
190 SignalConnectorType registerSignal6( typeRegistration, SIGNAL_PINCHED, &DoConnectSignal );
191 SignalConnectorType registerSignal7( typeRegistration, SIGNAL_LONG_PRESSED, &DoConnectSignal );
193 TypeAction registerAction( typeRegistration, ACTION_ACCESSIBILITY_ACTIVATED, &DoAction );
195 DALI_TYPE_REGISTRATION_END()
197 } // unnamed namespace
202 class Control::Impl : public ConnectionTracker
206 // Construction & Destruction
207 Impl(Control& controlImpl)
208 : mControlImpl( controlImpl ),
211 mBackgroundColor(Color::TRANSPARENT),
212 mStartingPinchScale( NULL ),
214 mPinchGestureDetector(),
215 mPanGestureDetector(),
216 mTapGestureDetector(),
217 mLongPressGestureDetector(),
218 mFlags( Control::ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
219 mIsKeyboardNavigationSupported( false ),
220 mIsKeyboardFocusGroup( false )
226 // All gesture detectors will be destroyed so no need to disconnect.
227 delete mStartingPinchScale;
230 // Gesture Detection Methods
232 void PinchDetected(Actor actor, const PinchGesture& pinch)
234 mControlImpl.OnPinch(pinch);
237 void PanDetected(Actor actor, const PanGesture& pan)
239 mControlImpl.OnPan(pan);
242 void TapDetected(Actor actor, const TapGesture& tap)
244 mControlImpl.OnTap(tap);
247 void LongPressDetected(Actor actor, const LongPressGesture& longPress)
249 mControlImpl.OnLongPress(longPress);
255 * Called when a property of an object of this type is set.
256 * @param[in] object The object whose property is set.
257 * @param[in] index The property index.
258 * @param[in] value The new property value.
260 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
262 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
266 Control& controlImpl( GetImplementation( control ) );
270 case Toolkit::Control::Property::STYLE_NAME:
272 controlImpl.SetStyleName( value.Get< std::string >() );
276 case Toolkit::Control::Property::BACKGROUND_COLOR:
278 DALI_LOG_WARNING( "BACKGROUND_COLOR property is deprecated. Use BACKGROUND property instead\n" );
279 controlImpl.SetBackgroundColor( value.Get< Vector4 >() );
283 case Toolkit::Control::Property::BACKGROUND_IMAGE:
285 DALI_LOG_WARNING( "BACKGROUND_IMAGE property is deprecated. Use BACKGROUND property instead\n" );
286 Image image = Scripting::NewImage( value );
289 controlImpl.SetBackgroundImage( image );
293 // An empty map means the background is no longer required
294 controlImpl.ClearBackground();
299 case Toolkit::Control::Property::KEY_INPUT_FOCUS:
301 if ( value.Get< bool >() )
303 controlImpl.SetKeyInputFocus();
307 controlImpl.ClearKeyInputFocus();
312 case Toolkit::Control::Property::BACKGROUND:
314 const Property::Map* map = value.GetMap();
317 controlImpl.SetBackground( *map );
321 // The background is not a property map, so we should clear the background
322 controlImpl.ClearBackground();
331 * Called to retrieve a property of an object of this type.
332 * @param[in] object The object whose property is to be retrieved.
333 * @param[in] index The property index.
334 * @return The current value of the property.
336 static Property::Value GetProperty( BaseObject* object, Property::Index index )
338 Property::Value value;
340 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
344 Control& controlImpl( GetImplementation( control ) );
348 case Toolkit::Control::Property::STYLE_NAME:
350 value = controlImpl.GetStyleName();
354 case Toolkit::Control::Property::BACKGROUND_COLOR:
356 DALI_LOG_WARNING( "BACKGROUND_COLOR property is deprecated. Use BACKGROUND property instead\n" );
357 value = controlImpl.GetBackgroundColor();
361 case Toolkit::Control::Property::BACKGROUND_IMAGE:
363 DALI_LOG_WARNING( "BACKGROUND_IMAGE property is deprecated. Use BACKGROUND property instead\n" );
365 if( controlImpl.mImpl->mBackgroundVisual )
367 controlImpl.mImpl->mBackgroundVisual.CreatePropertyMap( map );
373 case Toolkit::Control::Property::KEY_INPUT_FOCUS:
375 value = controlImpl.HasKeyInputFocus();
379 case Toolkit::Control::Property::BACKGROUND:
382 if( controlImpl.mImpl->mBackgroundVisual )
384 (controlImpl.mImpl->mBackgroundVisual).CreatePropertyMap( map );
399 Control& mControlImpl;
400 RegisteredVisuals mVisuals; // Stores visuals needed by the control, non trivial type so std::vector used.
401 std::string mStyleName;
402 Toolkit::Visual::Base mBackgroundVisual; ///< The visual to render the background
403 Vector4 mBackgroundColor; ///< The color of the background visual
404 Vector3* mStartingPinchScale; ///< The scale when a pinch gesture starts, TODO: consider removing this
405 Toolkit::Control::KeyEventSignalType mKeyEventSignal;
406 Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusGainedSignal;
407 Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusLostSignal;
410 PinchGestureDetector mPinchGestureDetector;
411 PanGestureDetector mPanGestureDetector;
412 TapGestureDetector mTapGestureDetector;
413 LongPressGestureDetector mLongPressGestureDetector;
415 ControlBehaviour mFlags : CONTROL_BEHAVIOUR_FLAG_COUNT; ///< Flags passed in from constructor.
416 bool mIsKeyboardNavigationSupported :1; ///< Stores whether keyboard navigation is supported by the control.
417 bool mIsKeyboardFocusGroup :1; ///< Stores whether the control is a focus group.
419 // Properties - these need to be members of Internal::Control::Impl as they need to function within this class.
420 static const PropertyRegistration PROPERTY_1;
421 static const PropertyRegistration PROPERTY_2;
422 static const PropertyRegistration PROPERTY_3;
423 static const PropertyRegistration PROPERTY_4;
424 static const PropertyRegistration PROPERTY_5;
427 // Properties registered without macro to use specific member variables.
428 const PropertyRegistration Control::Impl::PROPERTY_1( typeRegistration, "styleName", Toolkit::Control::Property::STYLE_NAME, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
429 const PropertyRegistration Control::Impl::PROPERTY_2( typeRegistration, "backgroundColor", Toolkit::Control::Property::BACKGROUND_COLOR, Property::VECTOR4, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
430 const PropertyRegistration Control::Impl::PROPERTY_3( typeRegistration, "backgroundImage", Toolkit::Control::Property::BACKGROUND_IMAGE, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
431 const PropertyRegistration Control::Impl::PROPERTY_4( typeRegistration, "keyInputFocus", Toolkit::Control::Property::KEY_INPUT_FOCUS, Property::BOOLEAN, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
432 const PropertyRegistration Control::Impl::PROPERTY_5( typeRegistration, "background", Toolkit::Control::Property::BACKGROUND, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
434 Toolkit::Control Control::New()
436 // Create the implementation, temporarily owned on stack
437 IntrusivePtr<Control> controlImpl = new Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) );
439 // Pass ownership to handle
440 Toolkit::Control handle( *controlImpl );
442 // Second-phase init of the implementation
443 // This can only be done after the CustomActor connection has been made...
444 controlImpl->Initialize();
454 void Control::SetStyleName( const std::string& styleName )
456 if( styleName != mImpl->mStyleName )
458 mImpl->mStyleName = styleName;
460 // Apply new style, if stylemanager is available
461 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
464 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
469 const std::string& Control::GetStyleName() const
471 return mImpl->mStyleName;
474 void Control::SetBackgroundColor( const Vector4& color )
476 Actor self( Self() );
477 mImpl->mBackgroundColor = color;
479 map[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::COLOR;
480 map[ Toolkit::ColorVisual::Property::MIX_COLOR ] = color;
481 mImpl->mBackgroundVisual = Toolkit::VisualFactory::Get().CreateVisual( map );
482 RegisterVisual( Toolkit::Control::Property::BACKGROUND, self, mImpl->mBackgroundVisual );
483 if( mImpl->mBackgroundVisual )
485 mImpl->mBackgroundVisual.SetDepthIndex( DepthIndex::BACKGROUND );
489 Vector4 Control::GetBackgroundColor() const
491 return mImpl->mBackgroundColor;
494 void Control::SetBackground( const Property::Map& map )
496 Actor self( Self() );
497 mImpl->mBackgroundVisual = Toolkit::VisualFactory::Get().CreateVisual( map );
498 RegisterVisual( Toolkit::Control::Property::BACKGROUND, self, mImpl->mBackgroundVisual );
499 if( mImpl->mBackgroundVisual )
501 mImpl->mBackgroundVisual.SetDepthIndex( DepthIndex::BACKGROUND );
505 void Control::SetBackgroundImage( Image image )
507 Actor self( Self() );
508 mImpl->mBackgroundVisual = Toolkit::VisualFactory::Get().CreateVisual( image );
509 RegisterVisual( Toolkit::Control::Property::BACKGROUND, self, mImpl->mBackgroundVisual );
510 if( mImpl->mBackgroundVisual )
512 mImpl->mBackgroundVisual.SetDepthIndex( DepthIndex::BACKGROUND );
516 void Control::ClearBackground()
518 Actor self( Self() );
519 mImpl->mBackgroundVisual.RemoveAndReset( self );
520 mImpl->mBackgroundColor = Color::TRANSPARENT;
523 void Control::EnableGestureDetection(Gesture::Type type)
525 if ( (type & Gesture::Pinch) && !mImpl->mPinchGestureDetector )
527 mImpl->mPinchGestureDetector = PinchGestureDetector::New();
528 mImpl->mPinchGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PinchDetected);
529 mImpl->mPinchGestureDetector.Attach(Self());
532 if ( (type & Gesture::Pan) && !mImpl->mPanGestureDetector )
534 mImpl->mPanGestureDetector = PanGestureDetector::New();
535 mImpl->mPanGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PanDetected);
536 mImpl->mPanGestureDetector.Attach(Self());
539 if ( (type & Gesture::Tap) && !mImpl->mTapGestureDetector )
541 mImpl->mTapGestureDetector = TapGestureDetector::New();
542 mImpl->mTapGestureDetector.DetectedSignal().Connect(mImpl, &Impl::TapDetected);
543 mImpl->mTapGestureDetector.Attach(Self());
546 if ( (type & Gesture::LongPress) && !mImpl->mLongPressGestureDetector )
548 mImpl->mLongPressGestureDetector = LongPressGestureDetector::New();
549 mImpl->mLongPressGestureDetector.DetectedSignal().Connect(mImpl, &Impl::LongPressDetected);
550 mImpl->mLongPressGestureDetector.Attach(Self());
554 void Control::DisableGestureDetection(Gesture::Type type)
556 if ( (type & Gesture::Pinch) && mImpl->mPinchGestureDetector )
558 mImpl->mPinchGestureDetector.Detach(Self());
559 mImpl->mPinchGestureDetector.Reset();
562 if ( (type & Gesture::Pan) && mImpl->mPanGestureDetector )
564 mImpl->mPanGestureDetector.Detach(Self());
565 mImpl->mPanGestureDetector.Reset();
568 if ( (type & Gesture::Tap) && mImpl->mTapGestureDetector )
570 mImpl->mTapGestureDetector.Detach(Self());
571 mImpl->mTapGestureDetector.Reset();
574 if ( (type & Gesture::LongPress) && mImpl->mLongPressGestureDetector)
576 mImpl->mLongPressGestureDetector.Detach(Self());
577 mImpl->mLongPressGestureDetector.Reset();
581 PinchGestureDetector Control::GetPinchGestureDetector() const
583 return mImpl->mPinchGestureDetector;
586 PanGestureDetector Control::GetPanGestureDetector() const
588 return mImpl->mPanGestureDetector;
591 TapGestureDetector Control::GetTapGestureDetector() const
593 return mImpl->mTapGestureDetector;
596 LongPressGestureDetector Control::GetLongPressGestureDetector() const
598 return mImpl->mLongPressGestureDetector;
601 void Control::SetKeyboardNavigationSupport(bool isSupported)
603 mImpl->mIsKeyboardNavigationSupported = isSupported;
606 bool Control::IsKeyboardNavigationSupported()
608 return mImpl->mIsKeyboardNavigationSupported;
611 void Control::SetKeyInputFocus()
613 if( Self().OnStage() )
615 Toolkit::KeyInputFocusManager::Get().SetFocus(Toolkit::Control::DownCast(Self()));
619 bool Control::HasKeyInputFocus()
622 if( Self().OnStage() )
624 result = Toolkit::KeyInputFocusManager::Get().IsKeyboardListener(Toolkit::Control::DownCast(Self()));
629 void Control::ClearKeyInputFocus()
631 if( Self().OnStage() )
633 Toolkit::KeyInputFocusManager::Get().RemoveFocus(Toolkit::Control::DownCast(Self()));
637 void Control::SetAsKeyboardFocusGroup(bool isFocusGroup)
639 mImpl->mIsKeyboardFocusGroup = isFocusGroup;
641 // The following line will be removed when the deprecated API in KeyboardFocusManager is deleted
642 Toolkit::KeyboardFocusManager::Get().SetAsFocusGroup(Self(), isFocusGroup);
645 bool Control::IsKeyboardFocusGroup()
647 return Toolkit::KeyboardFocusManager::Get().IsFocusGroup(Self());
650 void Control::AccessibilityActivate()
652 // Inform deriving classes
653 OnAccessibilityActivated();
656 void Control::KeyboardEnter()
658 // Inform deriving classes
662 void Control::RegisterVisual( Property::Index index, Actor& placementActor, Toolkit::Visual::Base& visual )
664 bool visualReplaced ( false );
665 Actor actorToRegister; // Null actor, replaced if placement actor not Self
668 if ( placementActor != self ) // Prevent increasing ref count if actor self
670 actorToRegister = placementActor;
673 if ( !mImpl->mVisuals.Empty() )
675 RegisteredVisuals::Iterator iter;
676 // Check if visual (index) is already registered. Replace if so.
677 if ( FindVisual( index, mImpl->mVisuals, iter ) )
679 if( (*iter)->visual && self.OnStage() )
681 if( (*iter)->placementActor )
683 (*iter)->visual.SetOffStage( (*iter)->placementActor );
687 (*iter)->visual.SetOffStage( self );
690 (*iter)->visual = visual;
691 (*iter)->placementActor = actorToRegister;
692 visualReplaced = true;
696 if ( !visualReplaced ) // New registration entry
698 mImpl->mVisuals.PushBack( new RegisteredVisual( index, visual, actorToRegister ) );
701 if( visual && self.OnStage() )
703 visual.SetOnStage( placementActor );
707 void Control::UnregisterVisual( Property::Index index )
709 RegisteredVisuals::Iterator iter;
710 if ( FindVisual( index, mImpl->mVisuals, iter ) )
712 mImpl->mVisuals.Erase( iter );
716 Toolkit::Visual::Base Control::GetVisual( Property::Index index ) const
718 RegisteredVisuals::Iterator iter;
719 if ( FindVisual( index, mImpl->mVisuals, iter ) )
721 return (*iter)->visual;
724 return Toolkit::Visual::Base();
727 Actor Control::GetPlacementActor( Property::Index index ) const
729 RegisteredVisuals::Iterator iter;
730 if ( FindVisual( index, mImpl->mVisuals, iter ) )
732 if( (*iter)->placementActor )
734 return (*iter)->placementActor;
745 bool Control::OnAccessibilityActivated()
747 return false; // Accessibility activation is not handled by default
750 bool Control::OnKeyboardEnter()
752 return false; // Keyboard enter is not handled by default
755 bool Control::OnAccessibilityPan(PanGesture gesture)
757 return false; // Accessibility pan gesture is not handled by default
760 bool Control::OnAccessibilityTouch(const TouchEvent& touchEvent)
762 return false; // Accessibility touch event is not handled by default
765 bool Control::OnAccessibilityValueChange(bool isIncrease)
767 return false; // Accessibility value change action is not handled by default
770 bool Control::OnAccessibilityZoom()
772 return false; // Accessibility zoom action is not handled by default
775 Actor Control::GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocus::Direction direction, bool loopEnabled)
780 void Control::OnKeyboardFocusChangeCommitted(Actor commitedFocusableActor)
784 Toolkit::Control::KeyEventSignalType& Control::KeyEventSignal()
786 return mImpl->mKeyEventSignal;
789 Toolkit::Control::KeyInputFocusSignalType& Control::KeyInputFocusGainedSignal()
791 return mImpl->mKeyInputFocusGainedSignal;
794 Toolkit::Control::KeyInputFocusSignalType& Control::KeyInputFocusLostSignal()
796 return mImpl->mKeyInputFocusLostSignal;
799 bool Control::EmitKeyEventSignal( const KeyEvent& event )
801 // Guard against destruction during signal emission
802 Dali::Toolkit::Control handle( GetOwner() );
804 bool consumed = false;
806 // signals are allocated dynamically when someone connects
807 if ( !mImpl->mKeyEventSignal.Empty() )
809 consumed = mImpl->mKeyEventSignal.Emit( handle, event );
814 // Notification for derived classes
815 consumed = OnKeyEvent(event);
821 Control::Control( ControlBehaviour behaviourFlags )
822 : CustomActorImpl( static_cast< ActorFlags >( behaviourFlags ) ),
823 mImpl(new Impl(*this))
825 mImpl->mFlags = behaviourFlags;
828 void Control::Initialize()
830 // Call deriving classes so initialised before styling is applied to them.
833 if( (mImpl->mFlags & REQUIRES_STYLE_CHANGE_SIGNALS) ||
834 !(mImpl->mFlags & DISABLE_STYLE_CHANGE_SIGNALS) )
836 Toolkit::StyleManager styleManager = StyleManager::Get();
838 // if stylemanager is available
841 StyleManager& styleManagerImpl = GetImpl( styleManager );
843 // Register for style changes
844 styleManagerImpl.ControlStyleChangeSignal().Connect( this, &Control::OnStyleChange );
846 // Apply the current style
847 styleManagerImpl.ApplyThemeStyleAtInit( Toolkit::Control( GetOwner() ) );
851 if( mImpl->mFlags & REQUIRES_KEYBOARD_NAVIGATION_SUPPORT )
853 SetKeyboardNavigationSupport( true );
857 void Control::OnInitialize()
861 void Control::OnControlChildAdd( Actor& child )
865 void Control::OnControlChildRemove( Actor& child )
869 void Control::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
871 // By default the control is only interested in theme (not font) changes
872 if( styleManager && change == StyleChange::THEME_CHANGE )
874 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
879 void Control::OnPinch(const PinchGesture& pinch)
881 if( !( mImpl->mStartingPinchScale ) )
884 mImpl->mStartingPinchScale = new Vector3;
887 if( pinch.state == Gesture::Started )
889 *( mImpl->mStartingPinchScale ) = Self().GetCurrentScale();
892 Self().SetScale( *( mImpl->mStartingPinchScale ) * pinch.scale );
895 void Control::OnPan( const PanGesture& pan )
899 void Control::OnTap(const TapGesture& tap)
903 void Control::OnLongPress( const LongPressGesture& longPress )
907 void Control::EmitKeyInputFocusSignal( bool focusGained )
909 Dali::Toolkit::Control handle( GetOwner() );
913 // signals are allocated dynamically when someone connects
914 if ( !mImpl->mKeyInputFocusGainedSignal.Empty() )
916 mImpl->mKeyInputFocusGainedSignal.Emit( handle );
921 // signals are allocated dynamically when someone connects
922 if ( !mImpl->mKeyInputFocusLostSignal.Empty() )
924 mImpl->mKeyInputFocusLostSignal.Emit( handle );
929 void Control::OnStageConnection( int depth )
931 for(RegisteredVisuals::Iterator iter = mImpl->mVisuals.Begin(); iter!= mImpl->mVisuals.End(); iter++)
933 // Check whether the visual is empty, as it is allowed to register a placement actor without visual.
934 if( (*iter)->visual )
936 if( (*iter)->placementActor )
938 (*iter)->visual.SetOnStage( (*iter)->placementActor );
942 Actor self( Self() );
943 (*iter)->visual.SetOnStage( self );
949 void Control::OnStageDisconnection()
951 for(RegisteredVisuals::Iterator iter = mImpl->mVisuals.Begin(); iter!= mImpl->mVisuals.End(); iter++)
953 // Check whether the visual is empty, as it is allowed to register a placement actor without visual.
954 if( (*iter)->visual )
956 if( (*iter)->placementActor )
958 (*iter)->visual.SetOffStage( (*iter)->placementActor );
962 Actor self( Self() );
963 (*iter)->visual.SetOffStage( self );
969 void Control::OnKeyInputFocusGained()
971 EmitKeyInputFocusSignal( true );
974 void Control::OnKeyInputFocusLost()
976 EmitKeyInputFocusSignal( false );
979 void Control::OnChildAdd(Actor& child)
981 // Notify derived classes.
982 OnControlChildAdd( child );
985 void Control::OnChildRemove(Actor& child)
987 // Notify derived classes.
988 OnControlChildRemove( child );
991 void Control::OnSizeSet(const Vector3& targetSize)
993 if( mImpl->mBackgroundVisual )
995 Vector2 size( targetSize );
996 mImpl->mBackgroundVisual.SetSize( size );
1000 void Control::OnSizeAnimation(Animation& animation, const Vector3& targetSize)
1002 // @todo size negotiate background to new size, animate as well?
1005 bool Control::OnTouchEvent(const TouchEvent& event)
1007 return false; // Do not consume
1010 bool Control::OnHoverEvent(const HoverEvent& event)
1012 return false; // Do not consume
1015 bool Control::OnKeyEvent(const KeyEvent& event)
1017 return false; // Do not consume
1020 bool Control::OnWheelEvent(const WheelEvent& event)
1022 return false; // Do not consume
1025 void Control::OnRelayout( const Vector2& size, RelayoutContainer& container )
1027 for( unsigned int i = 0, numChildren = Self().GetChildCount(); i < numChildren; ++i )
1029 container.Add( Self().GetChildAt( i ), size );
1033 void Control::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
1037 Vector3 Control::GetNaturalSize()
1039 if( mImpl->mBackgroundVisual )
1041 Vector2 naturalSize;
1042 mImpl->mBackgroundVisual.GetNaturalSize(naturalSize);
1043 return Vector3(naturalSize);
1045 return Vector3::ZERO;
1048 float Control::CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension )
1050 return CalculateChildSizeBase( child, dimension );
1053 float Control::GetHeightForWidth( float width )
1055 return GetHeightForWidthBase( width );
1058 float Control::GetWidthForHeight( float height )
1060 return GetWidthForHeightBase( height );
1063 bool Control::RelayoutDependentOnChildren( Dimension::Type dimension )
1065 return RelayoutDependentOnChildrenBase( dimension );
1068 void Control::OnCalculateRelayoutSize( Dimension::Type dimension )
1072 void Control::OnLayoutNegotiated( float size, Dimension::Type dimension )
1076 void Control::SignalConnected( SlotObserver* slotObserver, CallbackBase* callback )
1078 mImpl->SignalConnected( slotObserver, callback );
1081 void Control::SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback )
1083 mImpl->SignalDisconnected( slotObserver, callback );
1086 Control& GetImplementation( Dali::Toolkit::Control& handle )
1088 CustomActorImpl& customInterface = handle.GetImplementation();
1089 // downcast to control
1090 Control& impl = dynamic_cast< Internal::Control& >( customInterface );
1094 const Control& GetImplementation( const Dali::Toolkit::Control& handle )
1096 const CustomActorImpl& customInterface = handle.GetImplementation();
1097 // downcast to control
1098 const Control& impl = dynamic_cast< const Internal::Control& >( customInterface );
1102 } // namespace Internal
1104 } // namespace Toolkit