2 * Copyright (c) 2017 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
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/public-api/object/type-registry-helper.h>
30 #include <dali/public-api/rendering/renderer.h>
31 #include <dali/public-api/size-negotiation/relayout-container.h>
32 #include <dali/devel-api/common/owner-container.h>
33 #include <dali/devel-api/object/handle-devel.h>
34 #include <dali/devel-api/scripting/enum-helper.h>
35 #include <dali/devel-api/scripting/scripting.h>
36 #include <dali/integration-api/debug.h>
39 #include <dali-toolkit/public-api/focus-manager/keyboard-focus-manager.h>
40 #include <dali-toolkit/public-api/controls/control.h>
41 #include <dali-toolkit/public-api/styling/style-manager.h>
42 #include <dali-toolkit/public-api/visuals/color-visual-properties.h>
43 #include <dali-toolkit/public-api/visuals/image-visual-properties.h>
44 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
45 #include <dali-toolkit/devel-api/controls/control-devel.h>
46 #include <dali-toolkit/devel-api/visuals/text-visual-properties.h>
47 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
48 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
49 #include <dali-toolkit/devel-api/focus-manager/keyinput-focus-manager.h>
50 #include <dali-toolkit/internal/styling/style-manager-impl.h>
51 #include <dali-toolkit/internal/visuals/color/color-visual.h>
52 #include <dali-toolkit/internal/visuals/transition-data-impl.h>
53 #include <dali-toolkit/internal/visuals/visual-string-constants.h>
54 #include <dali-toolkit/devel-api/align-enums.h>
55 #include <dali-toolkit/internal/controls/tooltip/tooltip.h>
66 extern const Dali::Scripting::StringEnum ControlStateTable[];
67 extern const unsigned int ControlStateTableCount;
70 // Not static or anonymous - shared with other translation units
71 const Scripting::StringEnum ControlStateTable[] = {
72 { "NORMAL", Toolkit::DevelControl::NORMAL },
73 { "FOCUSED", Toolkit::DevelControl::FOCUSED },
74 { "DISABLED", Toolkit::DevelControl::DISABLED },
75 }; const unsigned int ControlStateTableCount = sizeof( ControlStateTable ) / sizeof( ControlStateTable[0] );
77 } // Internal namespace
82 #if defined(DEBUG_ENABLED)
83 Debug::Filter* gLogFilter = Debug::Filter::New( Debug::NoLogging, false, "LOG_CONTROL_VISUALS");
86 DALI_ENUM_TO_STRING_TABLE_BEGIN( CLIPPING_MODE )
87 DALI_ENUM_TO_STRING_WITH_SCOPE( ClippingMode, DISABLED )
88 DALI_ENUM_TO_STRING_WITH_SCOPE( ClippingMode, CLIP_CHILDREN )
89 DALI_ENUM_TO_STRING_TABLE_END( CLIPPING_MODE )
92 * Struct used to store Visual within the control, index is a unique key for each visual.
94 struct RegisteredVisual
96 Property::Index index;
97 Toolkit::Visual::Base visual;
100 RegisteredVisual( Property::Index aIndex, Toolkit::Visual::Base &aVisual, bool aEnabled)
101 : index(aIndex), visual(aVisual), enabled(aEnabled)
106 typedef Dali::OwnerContainer< RegisteredVisual* > RegisteredVisualContainer;
109 * Finds visual in given array, returning true if found along with the iterator for that visual as a out parameter
111 bool FindVisual( Property::Index targetIndex, RegisteredVisualContainer& visuals, RegisteredVisualContainer::Iterator& iter )
113 for ( iter = visuals.Begin(); iter != visuals.End(); iter++ )
115 if ( (*iter)->index == targetIndex )
123 Toolkit::Visual::Base GetVisualByName(
124 RegisteredVisualContainer& visuals,
125 const std::string& visualName )
127 Toolkit::Visual::Base visualHandle;
129 RegisteredVisualContainer::Iterator iter;
130 for ( iter = visuals.Begin(); iter != visuals.End(); iter++ )
132 Toolkit::Visual::Base visual = (*iter)->visual;
133 if( visual && visual.GetName() == visualName )
135 visualHandle = visual;
143 * Creates control through type registry
147 return Internal::Control::New();
151 * Performs actions as requested using the action name.
152 * @param[in] object The object on which to perform the action.
153 * @param[in] actionName The action to perform.
154 * @param[in] attributes The attributes with which to perfrom this action.
155 * @return true if action has been accepted by this control
157 const char* ACTION_ACCESSIBILITY_ACTIVATED = "accessibilityActivated";
158 static bool DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes )
162 if( object && ( 0 == strcmp( actionName.c_str(), ACTION_ACCESSIBILITY_ACTIVATED ) ) )
164 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
167 // if cast succeeds there is an implementation so no need to check
168 ret = Internal::GetImplementation( control ).OnAccessibilityActivated();
176 * Connects a callback function with the object's signals.
177 * @param[in] object The object providing the signal.
178 * @param[in] tracker Used to disconnect the signal.
179 * @param[in] signalName The signal to connect to.
180 * @param[in] functor A newly allocated FunctorDelegate.
181 * @return True if the signal was connected.
182 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
184 const char* SIGNAL_KEY_EVENT = "keyEvent";
185 const char* SIGNAL_KEY_INPUT_FOCUS_GAINED = "keyInputFocusGained";
186 const char* SIGNAL_KEY_INPUT_FOCUS_LOST = "keyInputFocusLost";
187 const char* SIGNAL_TAPPED = "tapped";
188 const char* SIGNAL_PANNED = "panned";
189 const char* SIGNAL_PINCHED = "pinched";
190 const char* SIGNAL_LONG_PRESSED = "longPressed";
191 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
193 Dali::BaseHandle handle( object );
195 bool connected( false );
196 Toolkit::Control control = Toolkit::Control::DownCast( handle );
199 Internal::Control& controlImpl( Internal::GetImplementation( control ) );
202 if ( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_EVENT ) )
204 controlImpl.KeyEventSignal().Connect( tracker, functor );
206 else if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_INPUT_FOCUS_GAINED ) )
208 controlImpl.KeyInputFocusGainedSignal().Connect( tracker, functor );
210 else if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_INPUT_FOCUS_LOST ) )
212 controlImpl.KeyInputFocusLostSignal().Connect( tracker, functor );
214 else if( 0 == strcmp( signalName.c_str(), SIGNAL_TAPPED ) )
216 controlImpl.EnableGestureDetection( Gesture::Tap );
217 controlImpl.GetTapGestureDetector().DetectedSignal().Connect( tracker, functor );
219 else if( 0 == strcmp( signalName.c_str(), SIGNAL_PANNED ) )
221 controlImpl.EnableGestureDetection( Gesture::Pan );
222 controlImpl.GetPanGestureDetector().DetectedSignal().Connect( tracker, functor );
224 else if( 0 == strcmp( signalName.c_str(), SIGNAL_PINCHED ) )
226 controlImpl.EnableGestureDetection( Gesture::Pinch );
227 controlImpl.GetPinchGestureDetector().DetectedSignal().Connect( tracker, functor );
229 else if( 0 == strcmp( signalName.c_str(), SIGNAL_LONG_PRESSED ) )
231 controlImpl.EnableGestureDetection( Gesture::LongPress );
232 controlImpl.GetLongPressGestureDetector().DetectedSignal().Connect( tracker, functor );
238 // Setup signals and actions using the type-registry.
239 DALI_TYPE_REGISTRATION_BEGIN( Control, CustomActor, Create );
241 // Note: Properties are registered separately below.
243 SignalConnectorType registerSignal1( typeRegistration, SIGNAL_KEY_EVENT, &DoConnectSignal );
244 SignalConnectorType registerSignal2( typeRegistration, SIGNAL_KEY_INPUT_FOCUS_GAINED, &DoConnectSignal );
245 SignalConnectorType registerSignal3( typeRegistration, SIGNAL_KEY_INPUT_FOCUS_LOST, &DoConnectSignal );
246 SignalConnectorType registerSignal4( typeRegistration, SIGNAL_TAPPED, &DoConnectSignal );
247 SignalConnectorType registerSignal5( typeRegistration, SIGNAL_PANNED, &DoConnectSignal );
248 SignalConnectorType registerSignal6( typeRegistration, SIGNAL_PINCHED, &DoConnectSignal );
249 SignalConnectorType registerSignal7( typeRegistration, SIGNAL_LONG_PRESSED, &DoConnectSignal );
251 TypeAction registerAction( typeRegistration, ACTION_ACCESSIBILITY_ACTIVATED, &DoAction );
253 DALI_TYPE_REGISTRATION_END()
255 } // unnamed namespace
260 class Control::Impl : public ConnectionTracker
264 // Construction & Destruction
265 Impl(Control& controlImpl)
266 : mControlImpl( controlImpl ),
267 mState( Toolkit::DevelControl::NORMAL ),
269 mLeftFocusableActorId( -1 ),
270 mRightFocusableActorId( -1 ),
271 mUpFocusableActorId( -1 ),
272 mDownFocusableActorId( -1 ),
274 mBackgroundColor(Color::TRANSPARENT),
275 mStartingPinchScale( NULL ),
277 mPinchGestureDetector(),
278 mPanGestureDetector(),
279 mTapGestureDetector(),
280 mLongPressGestureDetector(),
281 mFlags( Control::ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
282 mIsKeyboardNavigationSupported( false ),
283 mIsKeyboardFocusGroup( false )
289 // 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);
318 * Called when a property of an object of this type is set.
319 * @param[in] object The object whose property is set.
320 * @param[in] index The property index.
321 * @param[in] value The new property value.
323 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
325 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
329 Control& controlImpl( GetImplementation( control ) );
333 case Toolkit::Control::Property::STYLE_NAME:
335 controlImpl.SetStyleName( value.Get< std::string >() );
339 case Toolkit::DevelControl::Property::STATE:
341 bool withTransitions=true;
342 const Property::Value* valuePtr=&value;
343 Property::Map* map = value.GetMap();
346 Property::Value* value2 = map->Find("withTransitions");
349 withTransitions = value2->Get<bool>();
352 valuePtr = map->Find("state");
357 Toolkit::DevelControl::State state( controlImpl.mImpl->mState );
358 if( Scripting::GetEnumerationProperty< Toolkit::DevelControl::State >( *valuePtr, ControlStateTable, ControlStateTableCount, state ) )
360 controlImpl.mImpl->SetState( state, withTransitions );
366 case Toolkit::DevelControl::Property::SUB_STATE:
368 std::string subState;
369 if( value.Get( subState ) )
371 controlImpl.mImpl->SetSubState( subState );
376 case Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID:
379 if( value.Get( focusId ) )
381 controlImpl.mImpl->mLeftFocusableActorId = focusId;
386 case Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID:
389 if( value.Get( focusId ) )
391 controlImpl.mImpl->mRightFocusableActorId = focusId;
396 case Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID:
399 if( value.Get( focusId ) )
401 controlImpl.mImpl->mUpFocusableActorId = focusId;
406 case Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID:
409 if( value.Get( focusId ) )
411 controlImpl.mImpl->mDownFocusableActorId = focusId;
416 case Toolkit::Control::Property::BACKGROUND_COLOR:
418 DALI_LOG_WARNING( "BACKGROUND_COLOR property is deprecated. Use BACKGROUND property instead\n" );
419 controlImpl.SetBackgroundColor( value.Get< Vector4 >() );
423 case Toolkit::Control::Property::BACKGROUND_IMAGE:
425 DALI_LOG_WARNING( "BACKGROUND_IMAGE property is deprecated. Use BACKGROUND property instead\n" );
426 Image image = Scripting::NewImage( value );
429 controlImpl.SetBackgroundImage( image );
433 // An empty image means the background is no longer required
434 controlImpl.ClearBackground();
439 case Toolkit::Control::Property::KEY_INPUT_FOCUS:
441 if ( value.Get< bool >() )
443 controlImpl.SetKeyInputFocus();
447 controlImpl.ClearKeyInputFocus();
452 case Toolkit::Control::Property::BACKGROUND:
456 const Property::Map* map = value.GetMap();
457 if( map && !map->Empty() )
459 controlImpl.SetBackground( *map );
461 else if( value.Get( url ) )
463 // don't know the size to load
464 Toolkit::Visual::Base visual = Toolkit::VisualFactory::Get().CreateVisual( url, ImageDimensions() );
467 controlImpl.RegisterVisual( Toolkit::Control::Property::BACKGROUND, visual );
468 visual.SetDepthIndex( DepthIndex::BACKGROUND );
471 else if( value.Get( color ) )
473 controlImpl.SetBackgroundColor(color);
477 // The background is an empty property map, so we should clear the background
478 controlImpl.ClearBackground();
483 case Toolkit::DevelControl::Property::TOOLTIP:
485 TooltipPtr& tooltipPtr = controlImpl.mImpl->mTooltip;
488 tooltipPtr = Tooltip::New( control );
490 tooltipPtr->SetProperties( value );
497 * Called to retrieve a property of an object of this type.
498 * @param[in] object The object whose property is to be retrieved.
499 * @param[in] index The property index.
500 * @return The current value of the property.
502 static Property::Value GetProperty( BaseObject* object, Property::Index index )
504 Property::Value value;
506 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
510 Control& controlImpl( GetImplementation( control ) );
514 case Toolkit::Control::Property::STYLE_NAME:
516 value = controlImpl.GetStyleName();
520 case Toolkit::DevelControl::Property::STATE:
522 value = controlImpl.mImpl->mState;
526 case Toolkit::DevelControl::Property::SUB_STATE:
528 value = controlImpl.mImpl->mSubStateName;
532 case Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID:
534 value = controlImpl.mImpl->mLeftFocusableActorId;
538 case Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID:
540 value = controlImpl.mImpl->mRightFocusableActorId;
544 case Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID:
546 value = controlImpl.mImpl->mUpFocusableActorId;
550 case Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID:
552 value = controlImpl.mImpl->mDownFocusableActorId;
556 case Toolkit::Control::Property::BACKGROUND_COLOR:
558 DALI_LOG_WARNING( "BACKGROUND_COLOR property is deprecated. Use BACKGROUND property instead\n" );
559 value = controlImpl.GetBackgroundColor();
563 case Toolkit::Control::Property::BACKGROUND_IMAGE:
565 DALI_LOG_WARNING( "BACKGROUND_IMAGE property is deprecated. Use BACKGROUND property instead\n" );
567 Toolkit::Visual::Base visual = controlImpl.GetVisual( Toolkit::Control::Property::BACKGROUND );
570 visual.CreatePropertyMap( map );
576 case Toolkit::Control::Property::KEY_INPUT_FOCUS:
578 value = controlImpl.HasKeyInputFocus();
582 case Toolkit::Control::Property::BACKGROUND:
585 Toolkit::Visual::Base visual = controlImpl.GetVisual( Toolkit::Control::Property::BACKGROUND );
588 visual.CreatePropertyMap( map );
595 case Toolkit::DevelControl::Property::TOOLTIP:
598 if( controlImpl.mImpl->mTooltip )
600 controlImpl.mImpl->mTooltip->CreatePropertyMap( map );
613 void CopyInstancedProperties( RegisteredVisualContainer& visuals, Dictionary<Property::Map>& instancedProperties )
615 for(RegisteredVisualContainer::Iterator iter = visuals.Begin(); iter!= visuals.End(); iter++)
617 if( (*iter)->visual )
619 Property::Map instanceMap;
620 Toolkit::GetImplementation((*iter)->visual).CreateInstancePropertyMap(instanceMap);
621 instancedProperties.Add( (*iter)->visual.GetName(), instanceMap );
627 void Remove( Dictionary<T>& keyValues, const std::string& name )
629 keyValues.Remove(name);
632 void Remove( DictionaryKeys& keys, const std::string& name )
634 DictionaryKeys::iterator iter = std::find( keys.begin(), keys.end(), name );
635 if( iter != keys.end())
641 void FindChangableVisuals( Dictionary<Property::Map>& stateVisualsToAdd,
642 Dictionary<Property::Map>& stateVisualsToChange,
643 DictionaryKeys& stateVisualsToRemove)
645 DictionaryKeys copyOfStateVisualsToRemove = stateVisualsToRemove;
647 for( DictionaryKeys::iterator iter = copyOfStateVisualsToRemove.begin();
648 iter != copyOfStateVisualsToRemove.end(); ++iter )
650 const std::string& visualName = (*iter);
651 Property::Map* toMap = stateVisualsToAdd.Find( visualName );
654 stateVisualsToChange.Add( visualName, *toMap );
655 stateVisualsToAdd.Remove( visualName );
656 Remove( stateVisualsToRemove, visualName );
661 void RemoveVisual( RegisteredVisualContainer& visuals, const std::string& visualName )
663 Actor self( mControlImpl.Self() );
665 for ( RegisteredVisualContainer::Iterator visualIter = visuals.Begin();
666 visualIter != visuals.End(); ++visualIter )
668 Toolkit::Visual::Base visual = (*visualIter)->visual;
669 if( visual && visual.GetName() == visualName )
671 Toolkit::GetImplementation(visual).SetOffStage( self );
672 (*visualIter)->visual.Reset();
673 visuals.Erase( visualIter );
679 void RemoveVisuals( RegisteredVisualContainer& visuals, DictionaryKeys& removeVisuals )
681 Actor self( mControlImpl.Self() );
682 for( DictionaryKeys::iterator iter = removeVisuals.begin(); iter != removeVisuals.end(); ++iter )
684 const std::string visualName = *iter;
685 RemoveVisual( visuals, visualName );
689 Toolkit::Visual::Type GetVisualTypeFromMap( const Property::Map& map )
691 Property::Value* typeValue = map.Find( Toolkit::Visual::Property::TYPE, VISUAL_TYPE );
692 Toolkit::Visual::Type type = Toolkit::Visual::IMAGE;
695 Scripting::GetEnumerationProperty( *typeValue, VISUAL_TYPE_TABLE, VISUAL_TYPE_TABLE_COUNT, type );
701 * Go through the list of visuals that are common to both states.
702 * If they are different types, or are both image types with different
703 * URLs, then the existing visual needs moving and the new visual creating
705 void RecreateChangedVisuals( Dictionary<Property::Map>& stateVisualsToChange,
706 Dictionary<Property::Map>& instancedProperties )
708 Dali::CustomActor handle( mControlImpl.GetOwner() );
709 for( Dictionary<Property::Map>::iterator iter = stateVisualsToChange.Begin();
710 iter != stateVisualsToChange.End(); ++iter )
712 const std::string& visualName = (*iter).key;
713 const Property::Map& toMap = (*iter).entry;
715 // is it a candidate for re-creation?
716 bool recreate = false;
718 Toolkit::Visual::Base visual = GetVisualByName( mVisuals, visualName );
721 Property::Map fromMap;
722 visual.CreatePropertyMap( fromMap );
724 Toolkit::Visual::Type fromType = GetVisualTypeFromMap( fromMap );
725 Toolkit::Visual::Type toType = GetVisualTypeFromMap( toMap );
727 if( fromType != toType )
733 if( fromType == Toolkit::Visual::IMAGE )
735 Property::Value* fromUrl = fromMap.Find( Toolkit::ImageVisual::Property::URL, IMAGE_URL_NAME );
736 Property::Value* toUrl = toMap.Find( Toolkit::ImageVisual::Property::URL, IMAGE_URL_NAME );
738 if( fromUrl && toUrl )
740 std::string fromUrlString;
741 std::string toUrlString;
742 fromUrl->Get(fromUrlString);
743 toUrl->Get(toUrlString);
745 if( fromUrlString != toUrlString )
753 const Property::Map* instancedMap = instancedProperties.FindConst( visualName );
754 if( recreate || instancedMap )
756 RemoveVisual( mVisuals, visualName );
757 Style::ApplyVisual( handle, visualName, toMap, instancedMap );
761 // @todo check to see if we can apply toMap without recreating the visual
762 // e.g. by setting only animatable properties
763 // For now, recreate all visuals, but merge in instance data.
764 RemoveVisual( mVisuals, visualName );
765 Style::ApplyVisual( handle, visualName, toMap, instancedMap );
771 void ReplaceStateVisualsAndProperties( const StylePtr oldState, const StylePtr newState, const std::string& subState )
773 // Collect all old visual names
774 DictionaryKeys stateVisualsToRemove;
777 oldState->visuals.GetKeys( stateVisualsToRemove );
778 if( ! subState.empty() )
780 const StylePtr* oldSubState = oldState->subStates.FindConst(subState);
783 DictionaryKeys subStateVisualsToRemove;
784 (*oldSubState)->visuals.GetKeys( subStateVisualsToRemove );
785 Merge( stateVisualsToRemove, subStateVisualsToRemove );
790 // Collect all new visual properties
791 Dictionary<Property::Map> stateVisualsToAdd;
794 stateVisualsToAdd = newState->visuals;
795 if( ! subState.empty() )
797 const StylePtr* newSubState = newState->subStates.FindConst(subState);
800 stateVisualsToAdd.Merge( (*newSubState)->visuals );
805 // If a name is in both add/remove, move it to change list.
806 Dictionary<Property::Map> stateVisualsToChange;
807 FindChangableVisuals( stateVisualsToAdd, stateVisualsToChange, stateVisualsToRemove);
809 // Copy instanced properties (e.g. text label) of current visuals
810 Dictionary<Property::Map> instancedProperties;
811 CopyInstancedProperties( mVisuals, instancedProperties );
813 // For each visual in remove list, remove from mVisuals
814 RemoveVisuals( mVisuals, stateVisualsToRemove );
816 // For each visual in add list, create and add to mVisuals
817 Dali::CustomActor handle( mControlImpl.GetOwner() );
818 Style::ApplyVisuals( handle, stateVisualsToAdd, instancedProperties );
820 // For each visual in change list, if it requires a new visual,
821 // remove old visual, create and add to mVisuals
822 RecreateChangedVisuals( stateVisualsToChange, instancedProperties );
825 void SetState( DevelControl::State newState, bool withTransitions=true )
827 DevelControl::State oldState = mState;
828 Dali::CustomActor handle( mControlImpl.GetOwner() );
829 DALI_LOG_INFO(gLogFilter, Debug::Concise, "Control::Impl::SetState: %s\n",
830 (mState == DevelControl::NORMAL ? "NORMAL" :(
831 mState == DevelControl::FOCUSED ?"FOCUSED" : (
832 mState == DevelControl::DISABLED?"DISABLED":"NONE" ))));
834 if( mState != newState )
836 // If mState was Disabled, and new state is Focused, should probably
837 // store that fact, e.g. in another property that FocusManager can access.
840 // Trigger state change and transitions
841 // Apply new style, if stylemanager is available
842 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
845 const StylePtr stylePtr = GetImpl( styleManager ).GetRecordedStyle( Toolkit::Control( mControlImpl.GetOwner() ) );
849 std::string oldStateName = Scripting::GetEnumerationName< Toolkit::DevelControl::State >( oldState, ControlStateTable, ControlStateTableCount );
850 std::string newStateName = Scripting::GetEnumerationName< Toolkit::DevelControl::State >( newState, ControlStateTable, ControlStateTableCount );
852 const StylePtr* newStateStyle = stylePtr->subStates.Find( newStateName );
853 const StylePtr* oldStateStyle = stylePtr->subStates.Find( oldStateName );
854 if( oldStateStyle && newStateStyle )
856 // Only change if both state styles exist
857 ReplaceStateVisualsAndProperties( *oldStateStyle, *newStateStyle, mSubStateName );
864 void SetSubState( const std::string& subStateName, bool withTransitions=true )
866 if( mSubStateName != subStateName )
868 // Get existing sub-state visuals, and unregister them
869 Dali::CustomActor handle( mControlImpl.GetOwner() );
871 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
874 const StylePtr stylePtr = GetImpl( styleManager ).GetRecordedStyle( Toolkit::Control( mControlImpl.GetOwner() ) );
878 std::string stateName = Scripting::GetEnumerationName< Toolkit::DevelControl::State >( mState, ControlStateTable, ControlStateTableCount );
880 const StylePtr* state = stylePtr->subStates.Find( stateName );
883 StylePtr stateStyle(*state);
885 const StylePtr* newStateStyle = stateStyle->subStates.Find( subStateName );
886 const StylePtr* oldStateStyle = stateStyle->subStates.Find( mSubStateName );
887 if( oldStateStyle && newStateStyle )
890 ReplaceStateVisualsAndProperties( *oldStateStyle, *newStateStyle, empty );
896 mSubStateName = subStateName;
902 Control& mControlImpl;
903 DevelControl::State mState;
904 std::string mSubStateName;
906 int mLeftFocusableActorId; ///< Actor ID of Left focusable control.
907 int mRightFocusableActorId; ///< Actor ID of Right focusable control.
908 int mUpFocusableActorId; ///< Actor ID of Up focusable control.
909 int mDownFocusableActorId; ///< Actor ID of Down focusable control.
911 RegisteredVisualContainer mVisuals; // Stores visuals needed by the control, non trivial type so std::vector used.
912 std::string mStyleName;
913 Vector4 mBackgroundColor; ///< The color of the background visual
914 Vector3* mStartingPinchScale; ///< The scale when a pinch gesture starts, TODO: consider removing this
915 Toolkit::Control::KeyEventSignalType mKeyEventSignal;
916 Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusGainedSignal;
917 Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusLostSignal;
920 PinchGestureDetector mPinchGestureDetector;
921 PanGestureDetector mPanGestureDetector;
922 TapGestureDetector mTapGestureDetector;
923 LongPressGestureDetector mLongPressGestureDetector;
928 ControlBehaviour mFlags : CONTROL_BEHAVIOUR_FLAG_COUNT; ///< Flags passed in from constructor.
929 bool mIsKeyboardNavigationSupported :1; ///< Stores whether keyboard navigation is supported by the control.
930 bool mIsKeyboardFocusGroup :1; ///< Stores whether the control is a focus group.
932 // Properties - these need to be members of Internal::Control::Impl as they access private methods/data of Internal::Control and Internal::Control::Impl.
933 static const PropertyRegistration PROPERTY_1;
934 static const PropertyRegistration PROPERTY_2;
935 static const PropertyRegistration PROPERTY_3;
936 static const PropertyRegistration PROPERTY_4;
937 static const PropertyRegistration PROPERTY_5;
938 static const PropertyRegistration PROPERTY_6;
939 static const PropertyRegistration PROPERTY_7;
940 static const PropertyRegistration PROPERTY_8;
941 static const PropertyRegistration PROPERTY_9;
942 static const PropertyRegistration PROPERTY_10;
943 static const PropertyRegistration PROPERTY_11;
944 static const PropertyRegistration PROPERTY_12;
947 // Properties registered without macro to use specific member variables.
948 const PropertyRegistration Control::Impl::PROPERTY_1( typeRegistration, "styleName", Toolkit::Control::Property::STYLE_NAME, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
949 const PropertyRegistration Control::Impl::PROPERTY_2( typeRegistration, "backgroundColor", Toolkit::Control::Property::BACKGROUND_COLOR, Property::VECTOR4, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
950 const PropertyRegistration Control::Impl::PROPERTY_3( typeRegistration, "backgroundImage", Toolkit::Control::Property::BACKGROUND_IMAGE, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
951 const PropertyRegistration Control::Impl::PROPERTY_4( typeRegistration, "keyInputFocus", Toolkit::Control::Property::KEY_INPUT_FOCUS, Property::BOOLEAN, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
952 const PropertyRegistration Control::Impl::PROPERTY_5( typeRegistration, "background", Toolkit::Control::Property::BACKGROUND, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
953 const PropertyRegistration Control::Impl::PROPERTY_6( typeRegistration, "tooltip", Toolkit::DevelControl::Property::TOOLTIP, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
954 const PropertyRegistration Control::Impl::PROPERTY_7( typeRegistration, "state", Toolkit::DevelControl::Property::STATE, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
955 const PropertyRegistration Control::Impl::PROPERTY_8( typeRegistration, "subState", Toolkit::DevelControl::Property::SUB_STATE, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
956 const PropertyRegistration Control::Impl::PROPERTY_9( typeRegistration, "leftFocusableActorId", Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID, Property::INTEGER, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
957 const PropertyRegistration Control::Impl::PROPERTY_10( typeRegistration, "rightFocusableActorId", Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID,Property::INTEGER, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
958 const PropertyRegistration Control::Impl::PROPERTY_11( typeRegistration, "upFocusableActorId", Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID, Property::INTEGER, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
959 const PropertyRegistration Control::Impl::PROPERTY_12( typeRegistration, "downFocusableActorId", Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID, Property::INTEGER, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
961 Toolkit::Control Control::New()
963 // Create the implementation, temporarily owned on stack
964 IntrusivePtr<Control> controlImpl = new Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) );
966 // Pass ownership to handle
967 Toolkit::Control handle( *controlImpl );
969 // Second-phase init of the implementation
970 // This can only be done after the CustomActor connection has been made...
971 controlImpl->Initialize();
976 void Control::SetStyleName( const std::string& styleName )
978 if( styleName != mImpl->mStyleName )
980 mImpl->mStyleName = styleName;
982 // Apply new style, if stylemanager is available
983 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
986 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
991 const std::string& Control::GetStyleName() const
993 return mImpl->mStyleName;
996 void Control::SetBackgroundColor( const Vector4& color )
998 mImpl->mBackgroundColor = color;
1000 map[ Toolkit::DevelVisual::Property::TYPE ] = Toolkit::Visual::COLOR;
1001 map[ Toolkit::ColorVisual::Property::MIX_COLOR ] = color;
1003 SetBackground( map );
1006 Vector4 Control::GetBackgroundColor() const
1008 return mImpl->mBackgroundColor;
1011 void Control::SetBackground( const Property::Map& map )
1013 Toolkit::Visual::Base visual = Toolkit::VisualFactory::Get().CreateVisual( map );
1016 RegisterVisual( Toolkit::Control::Property::BACKGROUND, visual );
1017 visual.SetDepthIndex( DepthIndex::BACKGROUND );
1019 // Trigger a size negotiation request that may be needed by the new visual to relayout its contents.
1024 void Control::SetBackgroundImage( Image image )
1026 Toolkit::Visual::Base visual = Toolkit::VisualFactory::Get().CreateVisual( image );
1029 RegisterVisual( Toolkit::Control::Property::BACKGROUND, visual );
1030 visual.SetDepthIndex( DepthIndex::BACKGROUND );
1034 void Control::ClearBackground()
1036 UnregisterVisual( Toolkit::Control::Property::BACKGROUND );
1037 mImpl->mBackgroundColor = Color::TRANSPARENT;
1039 // Trigger a size negotiation request that may be needed when unregistering a visual.
1043 void Control::EnableGestureDetection(Gesture::Type type)
1045 if ( (type & Gesture::Pinch) && !mImpl->mPinchGestureDetector )
1047 mImpl->mPinchGestureDetector = PinchGestureDetector::New();
1048 mImpl->mPinchGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PinchDetected);
1049 mImpl->mPinchGestureDetector.Attach(Self());
1052 if ( (type & Gesture::Pan) && !mImpl->mPanGestureDetector )
1054 mImpl->mPanGestureDetector = PanGestureDetector::New();
1055 mImpl->mPanGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PanDetected);
1056 mImpl->mPanGestureDetector.Attach(Self());
1059 if ( (type & Gesture::Tap) && !mImpl->mTapGestureDetector )
1061 mImpl->mTapGestureDetector = TapGestureDetector::New();
1062 mImpl->mTapGestureDetector.DetectedSignal().Connect(mImpl, &Impl::TapDetected);
1063 mImpl->mTapGestureDetector.Attach(Self());
1066 if ( (type & Gesture::LongPress) && !mImpl->mLongPressGestureDetector )
1068 mImpl->mLongPressGestureDetector = LongPressGestureDetector::New();
1069 mImpl->mLongPressGestureDetector.DetectedSignal().Connect(mImpl, &Impl::LongPressDetected);
1070 mImpl->mLongPressGestureDetector.Attach(Self());
1074 void Control::DisableGestureDetection(Gesture::Type type)
1076 if ( (type & Gesture::Pinch) && mImpl->mPinchGestureDetector )
1078 mImpl->mPinchGestureDetector.Detach(Self());
1079 mImpl->mPinchGestureDetector.Reset();
1082 if ( (type & Gesture::Pan) && mImpl->mPanGestureDetector )
1084 mImpl->mPanGestureDetector.Detach(Self());
1085 mImpl->mPanGestureDetector.Reset();
1088 if ( (type & Gesture::Tap) && mImpl->mTapGestureDetector )
1090 mImpl->mTapGestureDetector.Detach(Self());
1091 mImpl->mTapGestureDetector.Reset();
1094 if ( (type & Gesture::LongPress) && mImpl->mLongPressGestureDetector)
1096 mImpl->mLongPressGestureDetector.Detach(Self());
1097 mImpl->mLongPressGestureDetector.Reset();
1101 PinchGestureDetector Control::GetPinchGestureDetector() const
1103 return mImpl->mPinchGestureDetector;
1106 PanGestureDetector Control::GetPanGestureDetector() const
1108 return mImpl->mPanGestureDetector;
1111 TapGestureDetector Control::GetTapGestureDetector() const
1113 return mImpl->mTapGestureDetector;
1116 LongPressGestureDetector Control::GetLongPressGestureDetector() const
1118 return mImpl->mLongPressGestureDetector;
1121 void Control::SetKeyboardNavigationSupport(bool isSupported)
1123 mImpl->mIsKeyboardNavigationSupported = isSupported;
1126 bool Control::IsKeyboardNavigationSupported()
1128 return mImpl->mIsKeyboardNavigationSupported;
1131 void Control::SetKeyInputFocus()
1133 if( Self().OnStage() )
1135 Toolkit::KeyInputFocusManager::Get().SetFocus(Toolkit::Control::DownCast(Self()));
1139 bool Control::HasKeyInputFocus()
1141 bool result = false;
1142 if( Self().OnStage() )
1144 result = Toolkit::KeyInputFocusManager::Get().IsKeyboardListener(Toolkit::Control::DownCast(Self()));
1149 void Control::ClearKeyInputFocus()
1151 if( Self().OnStage() )
1153 Toolkit::KeyInputFocusManager::Get().RemoveFocus(Toolkit::Control::DownCast(Self()));
1157 void Control::SetAsKeyboardFocusGroup(bool isFocusGroup)
1159 mImpl->mIsKeyboardFocusGroup = isFocusGroup;
1161 // The following line will be removed when the deprecated API in KeyboardFocusManager is deleted
1162 Toolkit::KeyboardFocusManager::Get().SetAsFocusGroup(Self(), isFocusGroup);
1165 bool Control::IsKeyboardFocusGroup()
1167 return Toolkit::KeyboardFocusManager::Get().IsFocusGroup(Self());
1170 void Control::AccessibilityActivate()
1172 // Inform deriving classes
1173 OnAccessibilityActivated();
1176 void Control::KeyboardEnter()
1178 // Inform deriving classes
1182 void Control::RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual )
1184 RegisterVisual( index, visual, true );
1187 void Control::RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, bool enabled )
1189 bool visualReplaced ( false );
1190 Actor self = Self();
1192 if( !mImpl->mVisuals.Empty() )
1194 RegisteredVisualContainer::Iterator iter;
1195 // Check if visual (index) is already registered. Replace if so.
1196 if ( FindVisual( index, mImpl->mVisuals, iter ) )
1198 if( (*iter)->visual && self.OnStage() )
1200 Toolkit::GetImplementation((*iter)->visual).SetOffStage( self );
1202 (*iter)->visual = visual;
1203 visualReplaced = true;
1207 // If not set, set the name of the visual to the same name as the control's property.
1208 // ( If the control has been type registered )
1209 if( visual.GetName().empty() )
1211 // Check if the control has been type registered:
1212 TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(*this) );
1215 // Check if the property index has been registered:
1216 Property::IndexContainer indices;
1217 typeInfo.GetPropertyIndices( indices );
1218 Property::IndexContainer::Iterator iter = std::find( indices.Begin(), indices.End(), index );
1219 if( iter != indices.End() )
1221 // If it has, then get it's name and use that for the visual
1222 std::string visualName = typeInfo.GetPropertyName( index );
1223 visual.SetName( visualName );
1228 if( !visualReplaced ) // New registration entry
1230 mImpl->mVisuals.PushBack( new RegisteredVisual( index, visual, enabled ) );
1233 if( visual && self.OnStage() && enabled )
1235 Toolkit::GetImplementation(visual).SetOnStage( self );
1238 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::RegisterVisual() Registered %s(%d), enabled:%s\n", visual.GetName().c_str(), index, enabled?"T":"F" );
1241 void Control::UnregisterVisual( Property::Index index )
1243 RegisteredVisualContainer::Iterator iter;
1244 if ( FindVisual( index, mImpl->mVisuals, iter ) )
1246 Actor self( Self() );
1247 Toolkit::GetImplementation((*iter)->visual).SetOffStage( self );
1248 (*iter)->visual.Reset();
1249 mImpl->mVisuals.Erase( iter );
1253 Toolkit::Visual::Base Control::GetVisual( Property::Index index ) const
1255 RegisteredVisualContainer::Iterator iter;
1256 if ( FindVisual( index, mImpl->mVisuals, iter ) )
1258 return (*iter)->visual;
1261 return Toolkit::Visual::Base();
1264 void Control::EnableVisual( Property::Index index, bool enable )
1266 RegisteredVisualContainer::Iterator iter;
1267 if ( FindVisual( index, mImpl->mVisuals, iter ) )
1269 if ( (*iter)->enabled == enable )
1271 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::EnableVisual Visual %s(%d) already %s\n", (*iter)->visual.GetName().c_str(), index, enable?"enabled":"disabled");
1275 (*iter)->enabled = enable;
1276 Actor parentActor = Self();
1277 if ( Self().OnStage() ) // If control not on Stage then Visual will be added when StageConnection is called.
1281 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::EnableVisual Setting %s(%d) on stage \n", (*iter)->visual.GetName().c_str(), index );
1282 Toolkit::GetImplementation((*iter)->visual).SetOnStage( parentActor );
1286 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::EnableVisual Setting %s(%d) off stage \n", (*iter)->visual.GetName().c_str(), index );
1287 Toolkit::GetImplementation((*iter)->visual).SetOffStage( parentActor ); // No need to call if control not staged.
1293 bool Control::IsVisualEnabled( Property::Index index ) const
1295 RegisteredVisualContainer::Iterator iter;
1296 if ( FindVisual( index, mImpl->mVisuals, iter ) )
1298 return (*iter)->enabled;
1303 Dali::Animation Control::CreateTransition( const Toolkit::TransitionData& handle )
1305 Dali::Animation transition;
1306 const Internal::TransitionData& transitionData = Toolkit::GetImplementation( handle );
1308 if( transitionData.Count() > 0 )
1310 // Setup a Transition from TransitionData.
1311 TransitionData::Iterator end = transitionData.End();
1312 for( TransitionData::Iterator iter = transitionData.Begin() ;
1313 iter != end; ++iter )
1315 TransitionData::Animator* animator = (*iter);
1317 Toolkit::Visual::Base visual = GetVisualByName( mImpl->mVisuals, animator->objectName );
1321 Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
1322 visualImpl.AnimateProperty( transition, *animator );
1326 // Otherwise, try any actor children of control (Including the control)
1327 Actor child = Self().FindChildByName( animator->objectName );
1330 Property::Index propertyIndex = DevelHandle::GetPropertyIndex( child, animator->propertyKey );
1331 if( propertyIndex != Property::INVALID_INDEX )
1333 if( animator->animate == false )
1335 if( animator->targetValue.GetType() != Property::NONE )
1337 child.SetProperty( propertyIndex, animator->targetValue );
1340 else // animate the property
1342 if( animator->initialValue.GetType() != Property::NONE )
1344 child.SetProperty( propertyIndex, animator->initialValue );
1349 transition = Dali::Animation::New( 0.1f );
1352 transition.AnimateTo( Property( child, propertyIndex ),
1353 animator->targetValue,
1354 animator->alphaFunction,
1355 TimePeriod( animator->timePeriodDelay,
1356 animator->timePeriodDuration ) );
1367 bool Control::OnAccessibilityActivated()
1369 return false; // Accessibility activation is not handled by default
1372 bool Control::OnKeyboardEnter()
1374 return false; // Keyboard enter is not handled by default
1377 bool Control::OnAccessibilityPan(PanGesture gesture)
1379 return false; // Accessibility pan gesture is not handled by default
1382 bool Control::OnAccessibilityTouch(const TouchEvent& touchEvent)
1384 return false; // Accessibility touch event is not handled by default
1387 bool Control::OnAccessibilityValueChange(bool isIncrease)
1389 return false; // Accessibility value change action is not handled by default
1392 bool Control::OnAccessibilityZoom()
1394 return false; // Accessibility zoom action is not handled by default
1397 Actor Control::GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocus::Direction direction, bool loopEnabled)
1402 void Control::OnKeyboardFocusChangeCommitted(Actor commitedFocusableActor)
1406 Toolkit::Control::KeyEventSignalType& Control::KeyEventSignal()
1408 return mImpl->mKeyEventSignal;
1411 Toolkit::Control::KeyInputFocusSignalType& Control::KeyInputFocusGainedSignal()
1413 return mImpl->mKeyInputFocusGainedSignal;
1416 Toolkit::Control::KeyInputFocusSignalType& Control::KeyInputFocusLostSignal()
1418 return mImpl->mKeyInputFocusLostSignal;
1421 bool Control::EmitKeyEventSignal( const KeyEvent& event )
1423 // Guard against destruction during signal emission
1424 Dali::Toolkit::Control handle( GetOwner() );
1426 bool consumed = false;
1428 // signals are allocated dynamically when someone connects
1429 if ( !mImpl->mKeyEventSignal.Empty() )
1431 consumed = mImpl->mKeyEventSignal.Emit( handle, event );
1436 // Notification for derived classes
1437 consumed = OnKeyEvent(event);
1443 Control::Control( ControlBehaviour behaviourFlags )
1444 : CustomActorImpl( static_cast< ActorFlags >( behaviourFlags ) ),
1445 mImpl(new Impl(*this))
1447 mImpl->mFlags = behaviourFlags;
1455 void Control::Initialize()
1457 // Call deriving classes so initialised before styling is applied to them.
1460 if( (mImpl->mFlags & REQUIRES_STYLE_CHANGE_SIGNALS) ||
1461 !(mImpl->mFlags & DISABLE_STYLE_CHANGE_SIGNALS) )
1463 Toolkit::StyleManager styleManager = StyleManager::Get();
1465 // if stylemanager is available
1468 StyleManager& styleManagerImpl = GetImpl( styleManager );
1470 // Register for style changes
1471 styleManagerImpl.ControlStyleChangeSignal().Connect( this, &Control::OnStyleChange );
1473 // Apply the current style
1474 styleManagerImpl.ApplyThemeStyleAtInit( Toolkit::Control( GetOwner() ) );
1478 if( mImpl->mFlags & REQUIRES_KEYBOARD_NAVIGATION_SUPPORT )
1480 SetKeyboardNavigationSupport( true );
1484 void Control::OnInitialize()
1488 void Control::OnControlChildAdd( Actor& child )
1492 void Control::OnControlChildRemove( Actor& child )
1496 void Control::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
1498 // By default the control is only interested in theme (not font) changes
1499 if( styleManager && change == StyleChange::THEME_CHANGE )
1501 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
1506 void Control::OnPinch(const PinchGesture& pinch)
1508 if( !( mImpl->mStartingPinchScale ) )
1511 mImpl->mStartingPinchScale = new Vector3;
1514 if( pinch.state == Gesture::Started )
1516 *( mImpl->mStartingPinchScale ) = Self().GetCurrentScale();
1519 Self().SetScale( *( mImpl->mStartingPinchScale ) * pinch.scale );
1522 void Control::OnPan( const PanGesture& pan )
1526 void Control::OnTap(const TapGesture& tap)
1530 void Control::OnLongPress( const LongPressGesture& longPress )
1534 void Control::EmitKeyInputFocusSignal( bool focusGained )
1536 Dali::Toolkit::Control handle( GetOwner() );
1540 // signals are allocated dynamically when someone connects
1541 if ( !mImpl->mKeyInputFocusGainedSignal.Empty() )
1543 mImpl->mKeyInputFocusGainedSignal.Emit( handle );
1548 // signals are allocated dynamically when someone connects
1549 if ( !mImpl->mKeyInputFocusLostSignal.Empty() )
1551 mImpl->mKeyInputFocusLostSignal.Emit( handle );
1556 void Control::OnStageConnection( int depth )
1558 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::OnStageConnection number of registered visuals(%d)\n", mImpl->mVisuals.Size() );
1560 Actor self( Self() );
1562 for(RegisteredVisualContainer::Iterator iter = mImpl->mVisuals.Begin(); iter!= mImpl->mVisuals.End(); iter++)
1564 // Check whether the visual is empty and enabled
1565 if( (*iter)->visual && (*iter)->enabled )
1567 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::OnStageConnection Setting visual(%d) on stage\n", (*iter)->index );
1568 Toolkit::GetImplementation((*iter)->visual).SetOnStage( self );
1572 if( mImpl->mVisuals.Empty() && ! self.GetRendererCount() )
1574 Property::Value clippingValue = self.GetProperty( Actor::Property::CLIPPING_MODE );
1575 int clippingMode = ClippingMode::DISABLED;
1576 if( clippingValue.Get( clippingMode ) )
1578 // Add a transparent background if we do not have any renderers or visuals so we clip our children
1580 if( clippingMode == ClippingMode::CLIP_CHILDREN )
1582 // Create a transparent background visual which will also get staged.
1583 SetBackgroundColor( Color::TRANSPARENT );
1589 void Control::OnStageDisconnection()
1591 for(RegisteredVisualContainer::Iterator iter = mImpl->mVisuals.Begin(); iter!= mImpl->mVisuals.End(); iter++)
1593 // Check whether the visual is empty
1594 if( (*iter)->visual )
1596 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::OnStageDisconnection Setting visual(%d) off stage\n", (*iter)->index );
1597 Actor self( Self() );
1598 Toolkit::GetImplementation((*iter)->visual).SetOffStage( self );
1603 void Control::OnKeyInputFocusGained()
1605 EmitKeyInputFocusSignal( true );
1608 void Control::OnKeyInputFocusLost()
1610 EmitKeyInputFocusSignal( false );
1613 void Control::OnChildAdd(Actor& child)
1615 // Notify derived classes.
1616 OnControlChildAdd( child );
1619 void Control::OnChildRemove(Actor& child)
1621 // Notify derived classes.
1622 OnControlChildRemove( child );
1625 void Control::OnPropertySet( Property::Index index, Property::Value propertyValue )
1627 Actor self( Self() );
1628 if( index == Actor::Property::CLIPPING_MODE )
1630 // Only set the background if we're already on the stage and have no renderers or visuals
1632 if( mImpl->mVisuals.Empty() && ! self.GetRendererCount() && self.OnStage() )
1634 ClippingMode::Type clippingMode = ClippingMode::DISABLED;
1635 if( Scripting::GetEnumerationProperty< ClippingMode::Type >( propertyValue, CLIPPING_MODE_TABLE, CLIPPING_MODE_TABLE_COUNT, clippingMode ) )
1637 // Add a transparent background if we do not have one so we clip children
1639 if( clippingMode == ClippingMode::CLIP_CHILDREN )
1641 SetBackgroundColor( Color::TRANSPARENT );
1648 void Control::OnSizeSet(const Vector3& targetSize)
1650 Toolkit::Visual::Base visual = GetVisual( Toolkit::Control::Property::BACKGROUND );
1653 Vector2 size( targetSize );
1654 visual.SetTransformAndSize( Property::Map(), size ); // Send an empty map as we do not want to modify the visual's set transform
1658 void Control::OnSizeAnimation(Animation& animation, const Vector3& targetSize)
1660 // @todo size negotiate background to new size, animate as well?
1663 bool Control::OnTouchEvent(const TouchEvent& event)
1665 return false; // Do not consume
1668 bool Control::OnHoverEvent(const HoverEvent& event)
1670 return false; // Do not consume
1673 bool Control::OnKeyEvent(const KeyEvent& event)
1675 return false; // Do not consume
1678 bool Control::OnWheelEvent(const WheelEvent& event)
1680 return false; // Do not consume
1683 void Control::OnRelayout( const Vector2& size, RelayoutContainer& container )
1685 for( unsigned int i = 0, numChildren = Self().GetChildCount(); i < numChildren; ++i )
1687 container.Add( Self().GetChildAt( i ), size );
1690 Toolkit::Visual::Base visual = GetVisual( Toolkit::Control::Property::BACKGROUND );
1693 visual.SetTransformAndSize( Property::Map(), size ); // Send an empty map as we do not want to modify the visual's set transform
1697 void Control::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
1701 Vector3 Control::GetNaturalSize()
1703 Toolkit::Visual::Base visual = GetVisual( Toolkit::Control::Property::BACKGROUND );
1706 Vector2 naturalSize;
1707 visual.GetNaturalSize( naturalSize );
1708 return Vector3( naturalSize );
1710 return Vector3::ZERO;
1713 float Control::CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension )
1715 return CalculateChildSizeBase( child, dimension );
1718 float Control::GetHeightForWidth( float width )
1720 return GetHeightForWidthBase( width );
1723 float Control::GetWidthForHeight( float height )
1725 return GetWidthForHeightBase( height );
1728 bool Control::RelayoutDependentOnChildren( Dimension::Type dimension )
1730 return RelayoutDependentOnChildrenBase( dimension );
1733 void Control::OnCalculateRelayoutSize( Dimension::Type dimension )
1737 void Control::OnLayoutNegotiated( float size, Dimension::Type dimension )
1741 void Control::SignalConnected( SlotObserver* slotObserver, CallbackBase* callback )
1743 mImpl->SignalConnected( slotObserver, callback );
1746 void Control::SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback )
1748 mImpl->SignalDisconnected( slotObserver, callback );
1751 Control& GetImplementation( Dali::Toolkit::Control& handle )
1753 CustomActorImpl& customInterface = handle.GetImplementation();
1754 // downcast to control
1755 Control& impl = dynamic_cast< Internal::Control& >( customInterface );
1759 const Control& GetImplementation( const Dali::Toolkit::Control& handle )
1761 const CustomActorImpl& customInterface = handle.GetImplementation();
1762 // downcast to control
1763 const Control& impl = dynamic_cast< const Internal::Control& >( customInterface );
1767 } // namespace Internal
1769 } // namespace Toolkit