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/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/size-negotiation/relayout-container.h>
29 #include <dali/devel-api/object/type-registry-helper.h>
30 #include <dali/devel-api/rendering/renderer.h>
31 #include <dali/devel-api/scripting/scripting.h>
32 #include <dali/integration-api/debug.h>
35 #include <dali-toolkit/public-api/controls/control-depth-index-ranges.h>
36 #include <dali-toolkit/devel-api/controls/renderer-factory/renderer-factory.h>
37 #include <dali-toolkit/devel-api/focus-manager/keyinput-focus-manager.h>
38 #include <dali-toolkit/public-api/focus-manager/keyboard-focus-manager.h>
39 #include <dali-toolkit/public-api/controls/control.h>
40 #include <dali-toolkit/devel-api/styling/style-manager.h>
41 #include <dali-toolkit/internal/styling/style-manager-impl.h>
42 #include <dali-toolkit/internal/controls/renderers/color/color-renderer.h>
43 #include <dali-toolkit/internal/controls/renderers/image/image-renderer.h>
55 * Creates control through type registry
59 return Internal::Control::New();
63 * Performs actions as requested using the action name.
64 * @param[in] object The object on which to perform the action.
65 * @param[in] actionName The action to perform.
66 * @param[in] attributes The attributes with which to perfrom this action.
67 * @return true if action has been accepted by this control
69 const char* ACTION_ACCESSIBILITY_ACTIVATED = "accessibility-activated";
70 static bool DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes )
74 if( object && ( 0 == strcmp( actionName.c_str(), ACTION_ACCESSIBILITY_ACTIVATED ) ) )
76 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
79 // if cast succeeds there is an implementation so no need to check
80 ret = Internal::GetImplementation( control ).OnAccessibilityActivated();
88 * Connects a callback function with the object's signals.
89 * @param[in] object The object providing the signal.
90 * @param[in] tracker Used to disconnect the signal.
91 * @param[in] signalName The signal to connect to.
92 * @param[in] functor A newly allocated FunctorDelegate.
93 * @return True if the signal was connected.
94 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
96 const char* SIGNAL_KEY_EVENT = "key-event";
97 const char* SIGNAL_KEY_INPUT_FOCUS_GAINED = "key-input-focus-gained";
98 const char* SIGNAL_KEY_INPUT_FOCUS_LOST = "key-input-focus-lost";
99 const char* SIGNAL_TAPPED = "tapped";
100 const char* SIGNAL_PANNED = "panned";
101 const char* SIGNAL_PINCHED = "pinched";
102 const char* SIGNAL_LONG_PRESSED = "long-pressed";
103 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
105 Dali::BaseHandle handle( object );
107 bool connected( false );
108 Toolkit::Control control = Toolkit::Control::DownCast( handle );
111 Internal::Control& controlImpl( Internal::GetImplementation( control ) );
114 if ( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_EVENT ) )
116 controlImpl.KeyEventSignal().Connect( tracker, functor );
118 else if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_INPUT_FOCUS_GAINED ) )
120 controlImpl.KeyInputFocusGainedSignal().Connect( tracker, functor );
122 else if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_INPUT_FOCUS_LOST ) )
124 controlImpl.KeyInputFocusLostSignal().Connect( tracker, functor );
126 else if( 0 == strcmp( signalName.c_str(), SIGNAL_TAPPED ) )
128 controlImpl.EnableGestureDetection( Gesture::Tap );
129 controlImpl.GetTapGestureDetector().DetectedSignal().Connect( tracker, functor );
131 else if( 0 == strcmp( signalName.c_str(), SIGNAL_PANNED ) )
133 controlImpl.EnableGestureDetection( Gesture::Pan );
134 controlImpl.GetPanGestureDetector().DetectedSignal().Connect( tracker, functor );
136 else if( 0 == strcmp( signalName.c_str(), SIGNAL_PINCHED ) )
138 controlImpl.EnableGestureDetection( Gesture::Pinch );
139 controlImpl.GetPinchGestureDetector().DetectedSignal().Connect( tracker, functor );
141 else if( 0 == strcmp( signalName.c_str(), SIGNAL_LONG_PRESSED ) )
143 controlImpl.EnableGestureDetection( Gesture::LongPress );
144 controlImpl.GetLongPressGestureDetector().DetectedSignal().Connect( tracker, functor );
150 // Setup signals and actions using the type-registry.
151 DALI_TYPE_REGISTRATION_BEGIN( Control, CustomActor, Create );
153 // Note: Properties are registered separately below.
155 SignalConnectorType registerSignal1( typeRegistration, SIGNAL_KEY_EVENT, &DoConnectSignal );
156 SignalConnectorType registerSignal2( typeRegistration, SIGNAL_KEY_INPUT_FOCUS_GAINED, &DoConnectSignal );
157 SignalConnectorType registerSignal3( typeRegistration, SIGNAL_KEY_INPUT_FOCUS_LOST, &DoConnectSignal );
158 SignalConnectorType registerSignal4( typeRegistration, SIGNAL_TAPPED, &DoConnectSignal );
159 SignalConnectorType registerSignal5( typeRegistration, SIGNAL_PANNED, &DoConnectSignal );
160 SignalConnectorType registerSignal6( typeRegistration, SIGNAL_PINCHED, &DoConnectSignal );
161 SignalConnectorType registerSignal7( typeRegistration, SIGNAL_LONG_PRESSED, &DoConnectSignal );
163 TypeAction registerAction( typeRegistration, ACTION_ACCESSIBILITY_ACTIVATED, &DoAction );
165 DALI_TYPE_REGISTRATION_END()
168 const char * const BACKGROUND_COLOR_NAME("color");
171 * Structure which holds information about the background of a control
175 //ToDo: remove this actor and apply the Renderer on the Control
176 // when the implementation of Actor::RemoveRenderer(Renderer&) is in place.
177 Actor actor; ///< Background actor
178 ControlRenderer controlRenderer; ///< The control renderer to render the background
179 // The background can either be an image or a solid color.
180 Image image; ///< The background image
181 Vector4 color; ///< The background color
190 color( Color::TRANSPARENT )
195 //ToDo: skip this actor creation and apply the Renderer on the Control
196 // when the implementation of Actor::RemoveRenderer(Renderer&) is in place.
197 Actor CreateBackgroundActor()
200 Actor actor = Actor::New();
201 actor.SetSize( Vector3::ONE );
202 actor.SetPositionInheritanceMode( USE_PARENT_POSITION_PLUS_LOCAL_POSITION );
203 actor.SetColorMode( USE_PARENT_COLOR );
205 //Constraint scale of the background actor to the size of the control
206 Constraint constraint = Constraint::New<Vector3>( actor,
207 Actor::Property::SCALE,
208 EqualToConstraint() );
209 constraint.AddSource( ParentSource( Actor::Property::SIZE ) );
216 * @brief Create the background actor for the control.
218 * @param[in] actor The parent actor of the background
219 * @param[in] color The background color
221 void CreateBackground( Background& background, const Vector4& color )
223 background.actor = CreateBackgroundActor();
225 background.image.Reset();
226 background.color = color;
228 // Create the control renderer
229 RendererFactory rendererFactory = Toolkit::RendererFactory::Get();
230 background.controlRenderer = rendererFactory.GetControlRenderer(color);
232 // ToDo: Call SetOnStage at Control::OnStageConnection and call SetOffStage at Control::OnStageDisconnection;
233 // Currently Actor::RemoveRenderer doesnot work yet.
234 background.controlRenderer.SetOnStage( background.actor );
238 * @brief Create the background actor for the control.
240 * @param[in] actor The parent actor of the background
241 * @param[in] image The background image
243 void CreateBackground( Background& background, const Image& image )
245 background.actor = CreateBackgroundActor();
247 background.color = Color::TRANSPARENT;
248 background.image = image;
250 // Create the control renderer
251 RendererFactory rendererFactory = Toolkit::RendererFactory::Get();
252 background.controlRenderer = rendererFactory.GetControlRenderer(image);
254 // ToDo: Call SetOnStage at Control::OnStageConnection and call SetOffStage at Control::OnStageDisconnection;
255 // Currently Actor::RemoveRenderer doesnot work yet.
256 background.controlRenderer.SetOnStage( background.actor );
259 } // unnamed namespace
264 class Control::Impl : public ConnectionTracker
268 // Construction & Destruction
269 Impl(Control& controlImpl)
270 : mControlImpl( controlImpl ),
273 mStartingPinchScale( NULL ),
275 mPinchGestureDetector(),
276 mPanGestureDetector(),
277 mTapGestureDetector(),
278 mLongPressGestureDetector(),
279 mFlags( Control::ControlBehaviour( ACTOR_BEHAVIOUR_NONE ) ),
280 mIsKeyboardNavigationSupported( false ),
281 mIsKeyboardFocusGroup( false ),
282 mAddRemoveBackgroundChild( false )
288 // All gesture detectors will be destroyed so no need to disconnect.
290 delete mStartingPinchScale;
293 // Gesture Detection Methods
295 void PinchDetected(Actor actor, const PinchGesture& pinch)
297 mControlImpl.OnPinch(pinch);
300 void PanDetected(Actor actor, const PanGesture& pan)
302 mControlImpl.OnPan(pan);
305 void TapDetected(Actor actor, const TapGesture& tap)
307 mControlImpl.OnTap(tap);
310 void LongPressDetected(Actor actor, const LongPressGesture& longPress)
312 mControlImpl.OnLongPress(longPress);
315 // Background Methods
318 * Only creates an instance of the background if we actually use it.
319 * @return A reference to the Background structure.
321 Background& GetBackground()
325 mBackground = new Background;
333 * Called when a property of an object of this type is set.
334 * @param[in] object The object whose property is set.
335 * @param[in] index The property index.
336 * @param[in] value The new property value.
338 static void SetProperty( BaseObject* object, Property::Index index, const 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 controlImpl.SetStyleName( value.Get< std::string >() );
353 case Toolkit::Control::Property::BACKGROUND:
355 Image image = Scripting::NewImage( value );
358 controlImpl.SetBackgroundImage( image );
361 const Property::Map* map = value.GetMap();
364 const Property::Value* colorValue = map->Find( BACKGROUND_COLOR_NAME );
366 if( colorValue && colorValue->Get(color))
368 controlImpl.SetBackgroundColor( color );
373 // The background is neither an valid image nor a valid color, so it is no longer required
374 controlImpl.ClearBackground();
378 case Toolkit::Control::Property::KEY_INPUT_FOCUS:
380 if ( value.Get< bool >() )
382 controlImpl.SetKeyInputFocus();
386 controlImpl.ClearKeyInputFocus();
395 * Called to retrieve a property of an object of this type.
396 * @param[in] object The object whose property is to be retrieved.
397 * @param[in] index The property index.
398 * @return The current value of the property.
400 static Property::Value GetProperty( BaseObject* object, Property::Index index )
402 Property::Value value;
404 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
408 Control& controlImpl( GetImplementation( control ) );
412 case Toolkit::Control::Property::STYLE_NAME:
414 value = controlImpl.GetStyleName();
418 case Toolkit::Control::Property::BACKGROUND:
422 Background* back = controlImpl.mImpl->mBackground;
423 if ( back && back->actor)
427 Scripting::CreatePropertyMap( back->image, map );
431 map[BACKGROUND_COLOR_NAME] = back->color;
439 case Toolkit::Control::Property::KEY_INPUT_FOCUS:
441 value = controlImpl.HasKeyInputFocus();
452 Control& mControlImpl;
453 std::string mStyleName;
454 Background* mBackground; ///< Only create the background if we use it
455 Vector3* mStartingPinchScale; ///< The scale when a pinch gesture starts, TODO: consider removing this
456 Toolkit::Control::KeyEventSignalType mKeyEventSignal;
457 Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusGainedSignal;
458 Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusLostSignal;
461 PinchGestureDetector mPinchGestureDetector;
462 PanGestureDetector mPanGestureDetector;
463 TapGestureDetector mTapGestureDetector;
464 LongPressGestureDetector mLongPressGestureDetector;
466 ControlBehaviour mFlags :CONTROL_BEHAVIOUR_FLAG_COUNT; ///< Flags passed in from constructor.
467 bool mIsKeyboardNavigationSupported :1; ///< Stores whether keyboard navigation is supported by the control.
468 bool mIsKeyboardFocusGroup :1; ///< Stores whether the control is a focus group.
469 bool mAddRemoveBackgroundChild:1; ///< Flag to know when we are adding or removing our own actor to avoid call to OnControlChildAdd
471 // Properties - these need to be members of Internal::Control::Impl as they need to function within this class.
472 static PropertyRegistration PROPERTY_1;
473 static PropertyRegistration PROPERTY_2;
474 static PropertyRegistration PROPERTY_3;
477 // Properties registered without macro to use specific member variables.
478 PropertyRegistration Control::Impl::PROPERTY_1( typeRegistration, "style-name", Toolkit::Control::Property::STYLE_NAME, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
479 PropertyRegistration Control::Impl::PROPERTY_2( typeRegistration, "background", Toolkit::Control::Property::BACKGROUND, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
480 PropertyRegistration Control::Impl::PROPERTY_3( typeRegistration, "key-input-focus", Toolkit::Control::Property::KEY_INPUT_FOCUS, Property::BOOLEAN, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
482 Toolkit::Control Control::New()
484 // Create the implementation, temporarily owned on stack
485 IntrusivePtr<Control> controlImpl = new Control( ControlBehaviour( ACTOR_BEHAVIOUR_NONE ) );
487 // Pass ownership to handle
488 Toolkit::Control handle( *controlImpl );
490 // Second-phase init of the implementation
491 // This can only be done after the CustomActor connection has been made...
492 controlImpl->Initialize();
502 void Control::SetStyleName( const std::string& styleName )
504 if( styleName != mImpl->mStyleName )
506 mImpl->mStyleName = styleName;
508 // Apply new style, if stylemanager is available
509 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
512 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
517 const std::string& Control::GetStyleName() const
519 return mImpl->mStyleName;
522 void Control::SetBackgroundColor( const Vector4& color )
524 Background& background( mImpl->GetBackground() );
526 // The background renderer exits and it is a color renderer, we continue to use the current renderer
527 if ( background.actor && (!background.image)
528 && (!Toolkit::RendererFactory::Get().ResetRenderer( background.controlRenderer, color ) ))
530 background.color = color;
534 // TODO: Apply the new renderer directly, as Actor::RemoveRenderer is not working yet, we create a new actor
535 if( background.actor )
537 mImpl->mAddRemoveBackgroundChild = true;
538 Self().Remove( background.actor );
539 mImpl->mAddRemoveBackgroundChild = false;
541 // Create background actor
542 CreateBackground(background, color );
543 mImpl->mAddRemoveBackgroundChild = true;
544 // The actor does not need to be inserted to guarantee order.
545 Self().Add( background.actor );
546 mImpl->mAddRemoveBackgroundChild = false;
550 Vector4 Control::GetBackgroundColor() const
552 if ( mImpl->mBackground )
554 return mImpl->mBackground->color;
556 return Color::TRANSPARENT;
559 void Control::SetBackgroundImage( Image image )
561 Background& background( mImpl->GetBackground() );
563 // The background renderer exits and it is an image renderer, we continue to use the current renderer
564 if( background.actor && background.image
565 && (! Toolkit::RendererFactory::Get().ResetRenderer( background.controlRenderer, image ) ) )
567 background.image = image;
571 // TODO: Apply the new renderer directly, as Actor::RemoveRenderer is not working yet, we create a new actor
572 if( background.actor )
574 mImpl->mAddRemoveBackgroundChild = true;
575 Self().Remove( background.actor );
576 mImpl->mAddRemoveBackgroundChild = false;
578 // Create background actor
579 CreateBackground(background, image);
580 mImpl->mAddRemoveBackgroundChild = true;
581 // The actor does not need to be inserted to guarantee order.
582 Self().Add( background.actor );
583 mImpl->mAddRemoveBackgroundChild = false;
587 void Control::ClearBackground()
589 if ( mImpl->mBackground )
591 Background& background( mImpl->GetBackground() );
592 mImpl->mAddRemoveBackgroundChild = true;
593 Self().Remove( background.actor );
594 mImpl->mAddRemoveBackgroundChild = false;
596 delete mImpl->mBackground;
597 mImpl->mBackground = NULL;
601 void Control::EnableGestureDetection(Gesture::Type type)
603 if ( (type & Gesture::Pinch) && !mImpl->mPinchGestureDetector )
605 mImpl->mPinchGestureDetector = PinchGestureDetector::New();
606 mImpl->mPinchGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PinchDetected);
607 mImpl->mPinchGestureDetector.Attach(Self());
610 if ( (type & Gesture::Pan) && !mImpl->mPanGestureDetector )
612 mImpl->mPanGestureDetector = PanGestureDetector::New();
613 mImpl->mPanGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PanDetected);
614 mImpl->mPanGestureDetector.Attach(Self());
617 if ( (type & Gesture::Tap) && !mImpl->mTapGestureDetector )
619 mImpl->mTapGestureDetector = TapGestureDetector::New();
620 mImpl->mTapGestureDetector.DetectedSignal().Connect(mImpl, &Impl::TapDetected);
621 mImpl->mTapGestureDetector.Attach(Self());
624 if ( (type & Gesture::LongPress) && !mImpl->mLongPressGestureDetector )
626 mImpl->mLongPressGestureDetector = LongPressGestureDetector::New();
627 mImpl->mLongPressGestureDetector.DetectedSignal().Connect(mImpl, &Impl::LongPressDetected);
628 mImpl->mLongPressGestureDetector.Attach(Self());
632 void Control::DisableGestureDetection(Gesture::Type type)
634 if ( (type & Gesture::Pinch) && mImpl->mPinchGestureDetector )
636 mImpl->mPinchGestureDetector.Detach(Self());
637 mImpl->mPinchGestureDetector.Reset();
640 if ( (type & Gesture::Pan) && mImpl->mPanGestureDetector )
642 mImpl->mPanGestureDetector.Detach(Self());
643 mImpl->mPanGestureDetector.Reset();
646 if ( (type & Gesture::Tap) && mImpl->mTapGestureDetector )
648 mImpl->mTapGestureDetector.Detach(Self());
649 mImpl->mTapGestureDetector.Reset();
652 if ( (type & Gesture::LongPress) && mImpl->mLongPressGestureDetector)
654 mImpl->mLongPressGestureDetector.Detach(Self());
655 mImpl->mLongPressGestureDetector.Reset();
659 PinchGestureDetector Control::GetPinchGestureDetector() const
661 return mImpl->mPinchGestureDetector;
664 PanGestureDetector Control::GetPanGestureDetector() const
666 return mImpl->mPanGestureDetector;
669 TapGestureDetector Control::GetTapGestureDetector() const
671 return mImpl->mTapGestureDetector;
674 LongPressGestureDetector Control::GetLongPressGestureDetector() const
676 return mImpl->mLongPressGestureDetector;
679 void Control::SetKeyboardNavigationSupport(bool isSupported)
681 mImpl->mIsKeyboardNavigationSupported = isSupported;
684 bool Control::IsKeyboardNavigationSupported()
686 return mImpl->mIsKeyboardNavigationSupported;
689 void Control::SetKeyInputFocus()
691 if( Self().OnStage() )
693 Toolkit::KeyInputFocusManager::Get().SetFocus(Toolkit::Control::DownCast(Self()));
697 bool Control::HasKeyInputFocus()
700 if( Self().OnStage() )
702 result = Toolkit::KeyInputFocusManager::Get().IsKeyboardListener(Toolkit::Control::DownCast(Self()));
707 void Control::ClearKeyInputFocus()
709 if( Self().OnStage() )
711 Toolkit::KeyInputFocusManager::Get().RemoveFocus(Toolkit::Control::DownCast(Self()));
715 void Control::SetAsKeyboardFocusGroup(bool isFocusGroup)
717 mImpl->mIsKeyboardFocusGroup = isFocusGroup;
719 // The following line will be removed when the deprecated API in KeyboardFocusManager is deleted
720 Toolkit::KeyboardFocusManager::Get().SetAsFocusGroup(Self(), isFocusGroup);
723 bool Control::IsKeyboardFocusGroup()
725 return Toolkit::KeyboardFocusManager::Get().IsFocusGroup(Self());
728 void Control::AccessibilityActivate()
730 // Inform deriving classes
731 OnAccessibilityActivated();
734 void Control::KeyboardEnter()
736 // Inform deriving classes
740 bool Control::OnAccessibilityActivated()
742 return false; // Accessibility activation is not handled by default
745 bool Control::OnKeyboardEnter()
747 return false; // Keyboard enter is not handled by default
750 bool Control::OnAccessibilityPan(PanGesture gesture)
752 return false; // Accessibility pan gesture is not handled by default
755 bool Control::OnAccessibilityTouch(const TouchEvent& touchEvent)
757 return false; // Accessibility touch event is not handled by default
760 bool Control::OnAccessibilityValueChange(bool isIncrease)
762 return false; // Accessibility value change action is not handled by default
765 bool Control::OnAccessibilityZoom()
767 return false; // Accessibility zoom action is not handled by default
770 Actor Control::GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocus::Direction direction, bool loopEnabled)
775 void Control::OnKeyboardFocusChangeCommitted(Actor commitedFocusableActor)
779 Toolkit::Control::KeyEventSignalType& Control::KeyEventSignal()
781 return mImpl->mKeyEventSignal;
784 Toolkit::Control::KeyInputFocusSignalType& Control:: KeyInputFocusGainedSignal()
786 return mImpl->mKeyInputFocusGainedSignal;
789 Toolkit::Control::KeyInputFocusSignalType& Control:: KeyInputFocusLostSignal()
791 return mImpl->mKeyInputFocusLostSignal;
794 bool Control::EmitKeyEventSignal( const KeyEvent& event )
796 // Guard against destruction during signal emission
797 Dali::Toolkit::Control handle( GetOwner() );
799 bool consumed = false;
801 // signals are allocated dynamically when someone connects
802 if ( !mImpl->mKeyEventSignal.Empty() )
804 consumed = mImpl->mKeyEventSignal.Emit( handle, event );
809 // Notification for derived classes
810 consumed = OnKeyEvent(event);
816 Control::Control( ControlBehaviour behaviourFlags )
817 : CustomActorImpl( static_cast< ActorFlags >( behaviourFlags ) ),
818 mImpl(new Impl(*this))
820 mImpl->mFlags = behaviourFlags;
823 void Control::Initialize()
825 // Call deriving classes so initialised before styling is applied to them.
828 if( mImpl->mFlags & REQUIRES_STYLE_CHANGE_SIGNALS )
830 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
831 // if stylemanager is available
834 // Register for style changes
835 styleManager.StyleChangeSignal().Connect( this, &Control::OnStyleChange );
837 // Apply the current style
838 GetImpl( styleManager ).ApplyThemeStyleAtInit( Toolkit::Control( GetOwner() ) );
842 if( mImpl->mFlags & REQUIRES_KEYBOARD_NAVIGATION_SUPPORT )
844 SetKeyboardNavigationSupport( true );
848 void Control::OnInitialize()
852 void Control::OnControlChildAdd( Actor& child )
856 void Control::OnControlChildRemove( Actor& child )
860 void Control::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
862 // By default the control is only interested in theme (not font) changes
863 if( styleManager && change == StyleChange::THEME_CHANGE )
865 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
869 void Control::OnPinch(const PinchGesture& pinch)
871 if( !( mImpl->mStartingPinchScale ) )
874 mImpl->mStartingPinchScale = new Vector3;
877 if( pinch.state == Gesture::Started )
879 *( mImpl->mStartingPinchScale ) = Self().GetCurrentScale();
882 Self().SetScale( *( mImpl->mStartingPinchScale ) * pinch.scale );
885 void Control::OnPan( const PanGesture& pan )
889 void Control::OnTap(const TapGesture& tap)
893 void Control::OnLongPress( const LongPressGesture& longPress )
897 void Control::EmitKeyInputFocusSignal( bool focusGained )
899 Dali::Toolkit::Control handle( GetOwner() );
903 // signals are allocated dynamically when someone connects
904 if ( !mImpl->mKeyInputFocusGainedSignal.Empty() )
906 mImpl->mKeyInputFocusGainedSignal.Emit( handle );
911 // signals are allocated dynamically when someone connects
912 if ( !mImpl->mKeyInputFocusLostSignal.Empty() )
914 mImpl->mKeyInputFocusLostSignal.Emit( handle );
919 void Control::OnStageConnection( int depth )
921 unsigned int controlRendererCount = Self().GetRendererCount();
922 for( unsigned int i(0); i<controlRendererCount; ++i )
924 Renderer controlRenderer = Self().GetRendererAt(i);
925 if( controlRenderer )
927 controlRenderer.SetDepthIndex( CONTENT_DEPTH_INDEX+depth );
931 if( mImpl->mBackground && mImpl->mBackground->controlRenderer)
933 mImpl->mBackground->controlRenderer.SetDepthIndex( BACKGROUND_DEPTH_INDEX+depth );
937 void Control::OnStageDisconnection()
941 void Control::OnKeyInputFocusGained()
943 EmitKeyInputFocusSignal( true );
946 void Control::OnKeyInputFocusLost()
948 EmitKeyInputFocusSignal( false );
951 void Control::OnChildAdd(Actor& child)
953 // If this is the background actor, then we do not want to inform deriving classes
954 if ( mImpl->mAddRemoveBackgroundChild )
959 // Notify derived classes.
960 OnControlChildAdd( child );
963 void Control::OnChildRemove(Actor& child)
965 // If this is the background actor, then we do not want to inform deriving classes
966 if ( mImpl->mAddRemoveBackgroundChild )
971 // Notify derived classes.
972 OnControlChildRemove( child );
975 void Control::OnSizeSet(const Vector3& targetSize)
977 // Background is resized through size negotiation
980 void Control::OnSizeAnimation(Animation& animation, const Vector3& targetSize)
982 // @todo size negotiate background to new size, animate as well?
985 bool Control::OnTouchEvent(const TouchEvent& event)
987 return false; // Do not consume
990 bool Control::OnHoverEvent(const HoverEvent& event)
992 return false; // Do not consume
995 bool Control::OnKeyEvent(const KeyEvent& event)
997 return false; // Do not consume
1000 bool Control::OnWheelEvent(const WheelEvent& event)
1002 return false; // Do not consume
1005 void Control::OnRelayout( const Vector2& size, RelayoutContainer& container )
1007 for( unsigned int i = 0, numChildren = Self().GetChildCount(); i < numChildren; ++i )
1009 container.Add( Self().GetChildAt( i ), size );
1013 void Control::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
1017 Vector3 Control::GetNaturalSize()
1019 //Control's natural size is the size of its background image if it has been set, or ZERO otherwise
1020 Vector3 naturalSize = Vector3::ZERO;
1021 if( mImpl->mBackground )
1023 if( mImpl->mBackground->actor.GetRendererCount() > 0 )
1025 Material backgroundMaterial = mImpl->mBackground->actor.GetRendererAt(0).GetMaterial();
1026 if( backgroundMaterial.GetNumberOfSamplers() > 0 )
1028 Image backgroundImage = backgroundMaterial.GetSamplerAt(0).GetImage();
1029 if( backgroundImage )
1031 naturalSize.x = backgroundImage.GetWidth();
1032 naturalSize.y = backgroundImage.GetHeight();
1038 return mImpl->mBackground->actor.GetNaturalSize();
1045 float Control::CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension )
1047 return CalculateChildSizeBase( child, dimension );
1050 float Control::GetHeightForWidth( float width )
1052 if( mImpl->mBackground )
1054 Actor actor = mImpl->mBackground->actor;
1057 return actor.GetHeightForWidth( width );
1060 return GetHeightForWidthBase( width );
1063 float Control::GetWidthForHeight( float height )
1065 if( mImpl->mBackground )
1067 Actor actor = mImpl->mBackground->actor;
1070 return actor.GetWidthForHeight( height );
1073 return GetWidthForHeightBase( height );
1076 bool Control::RelayoutDependentOnChildren( Dimension::Type dimension )
1078 return RelayoutDependentOnChildrenBase( dimension );
1081 void Control::OnCalculateRelayoutSize( Dimension::Type dimension )
1085 void Control::OnLayoutNegotiated( float size, Dimension::Type dimension )
1089 void Control::SignalConnected( SlotObserver* slotObserver, CallbackBase* callback )
1091 mImpl->SignalConnected( slotObserver, callback );
1094 void Control::SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback )
1096 mImpl->SignalDisconnected( slotObserver, callback );
1099 Control& GetImplementation( Dali::Toolkit::Control& handle )
1101 CustomActorImpl& customInterface = handle.GetImplementation();
1102 // downcast to control
1103 Control& impl = dynamic_cast< Internal::Control& >( customInterface );
1107 const Control& GetImplementation( const Dali::Toolkit::Control& handle )
1109 const CustomActorImpl& customInterface = handle.GetImplementation();
1110 // downcast to control
1111 const Control& impl = dynamic_cast< const Internal::Control& >( customInterface );
1115 } // namespace Internal
1117 } // namespace Toolkit