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::DevelVisual::Type GetVisualTypeFromMap( const Property::Map& map )
691 Property::Value* typeValue = map.Find( Toolkit::DevelVisual::Property::TYPE, VISUAL_TYPE );
692 Toolkit::DevelVisual::Type type = Toolkit::DevelVisual::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::DevelVisual::Type fromType = GetVisualTypeFromMap( fromMap );
725 Toolkit::DevelVisual::Type toType = GetVisualTypeFromMap( toMap );
727 if( fromType != toType )
733 if( fromType == Toolkit::DevelVisual::IMAGE || fromType == Toolkit::DevelVisual::N_PATCH
734 || fromType == Toolkit::DevelVisual::SVG || fromType == Toolkit::DevelVisual::ANIMATED_IMAGE )
736 Property::Value* fromUrl = fromMap.Find( Toolkit::ImageVisual::Property::URL, IMAGE_URL_NAME );
737 Property::Value* toUrl = toMap.Find( Toolkit::ImageVisual::Property::URL, IMAGE_URL_NAME );
739 if( fromUrl && toUrl )
741 std::string fromUrlString;
742 std::string toUrlString;
743 fromUrl->Get(fromUrlString);
744 toUrl->Get(toUrlString);
746 if( fromUrlString != toUrlString )
754 const Property::Map* instancedMap = instancedProperties.FindConst( visualName );
755 if( recreate || instancedMap )
757 RemoveVisual( mVisuals, visualName );
758 Style::ApplyVisual( handle, visualName, toMap, instancedMap );
762 // @todo check to see if we can apply toMap without recreating the visual
763 // e.g. by setting only animatable properties
764 // For now, recreate all visuals, but merge in instance data.
765 RemoveVisual( mVisuals, visualName );
766 Style::ApplyVisual( handle, visualName, toMap, instancedMap );
772 void ReplaceStateVisualsAndProperties( const StylePtr oldState, const StylePtr newState, const std::string& subState )
774 // Collect all old visual names
775 DictionaryKeys stateVisualsToRemove;
778 oldState->visuals.GetKeys( stateVisualsToRemove );
779 if( ! subState.empty() )
781 const StylePtr* oldSubState = oldState->subStates.FindConst(subState);
784 DictionaryKeys subStateVisualsToRemove;
785 (*oldSubState)->visuals.GetKeys( subStateVisualsToRemove );
786 Merge( stateVisualsToRemove, subStateVisualsToRemove );
791 // Collect all new visual properties
792 Dictionary<Property::Map> stateVisualsToAdd;
795 stateVisualsToAdd = newState->visuals;
796 if( ! subState.empty() )
798 const StylePtr* newSubState = newState->subStates.FindConst(subState);
801 stateVisualsToAdd.Merge( (*newSubState)->visuals );
806 // If a name is in both add/remove, move it to change list.
807 Dictionary<Property::Map> stateVisualsToChange;
808 FindChangableVisuals( stateVisualsToAdd, stateVisualsToChange, stateVisualsToRemove);
810 // Copy instanced properties (e.g. text label) of current visuals
811 Dictionary<Property::Map> instancedProperties;
812 CopyInstancedProperties( mVisuals, instancedProperties );
814 // For each visual in remove list, remove from mVisuals
815 RemoveVisuals( mVisuals, stateVisualsToRemove );
817 // For each visual in add list, create and add to mVisuals
818 Dali::CustomActor handle( mControlImpl.GetOwner() );
819 Style::ApplyVisuals( handle, stateVisualsToAdd, instancedProperties );
821 // For each visual in change list, if it requires a new visual,
822 // remove old visual, create and add to mVisuals
823 RecreateChangedVisuals( stateVisualsToChange, instancedProperties );
826 void SetState( DevelControl::State newState, bool withTransitions=true )
828 DevelControl::State oldState = mState;
829 Dali::CustomActor handle( mControlImpl.GetOwner() );
830 DALI_LOG_INFO(gLogFilter, Debug::Concise, "Control::Impl::SetState: %s\n",
831 (mState == DevelControl::NORMAL ? "NORMAL" :(
832 mState == DevelControl::FOCUSED ?"FOCUSED" : (
833 mState == DevelControl::DISABLED?"DISABLED":"NONE" ))));
835 if( mState != newState )
837 // If mState was Disabled, and new state is Focused, should probably
838 // store that fact, e.g. in another property that FocusManager can access.
841 // Trigger state change and transitions
842 // Apply new style, if stylemanager is available
843 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
846 const StylePtr stylePtr = GetImpl( styleManager ).GetRecordedStyle( Toolkit::Control( mControlImpl.GetOwner() ) );
850 std::string oldStateName = Scripting::GetEnumerationName< Toolkit::DevelControl::State >( oldState, ControlStateTable, ControlStateTableCount );
851 std::string newStateName = Scripting::GetEnumerationName< Toolkit::DevelControl::State >( newState, ControlStateTable, ControlStateTableCount );
853 const StylePtr* newStateStyle = stylePtr->subStates.Find( newStateName );
854 const StylePtr* oldStateStyle = stylePtr->subStates.Find( oldStateName );
855 if( oldStateStyle && newStateStyle )
857 // Only change if both state styles exist
858 ReplaceStateVisualsAndProperties( *oldStateStyle, *newStateStyle, mSubStateName );
865 void SetSubState( const std::string& subStateName, bool withTransitions=true )
867 if( mSubStateName != subStateName )
869 // Get existing sub-state visuals, and unregister them
870 Dali::CustomActor handle( mControlImpl.GetOwner() );
872 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
875 const StylePtr stylePtr = GetImpl( styleManager ).GetRecordedStyle( Toolkit::Control( mControlImpl.GetOwner() ) );
879 std::string stateName = Scripting::GetEnumerationName< Toolkit::DevelControl::State >( mState, ControlStateTable, ControlStateTableCount );
881 const StylePtr* state = stylePtr->subStates.Find( stateName );
884 StylePtr stateStyle(*state);
886 const StylePtr* newStateStyle = stateStyle->subStates.Find( subStateName );
887 const StylePtr* oldStateStyle = stateStyle->subStates.Find( mSubStateName );
888 if( oldStateStyle && newStateStyle )
891 ReplaceStateVisualsAndProperties( *oldStateStyle, *newStateStyle, empty );
897 mSubStateName = subStateName;
903 Control& mControlImpl;
904 DevelControl::State mState;
905 std::string mSubStateName;
907 int mLeftFocusableActorId; ///< Actor ID of Left focusable control.
908 int mRightFocusableActorId; ///< Actor ID of Right focusable control.
909 int mUpFocusableActorId; ///< Actor ID of Up focusable control.
910 int mDownFocusableActorId; ///< Actor ID of Down focusable control.
912 RegisteredVisualContainer mVisuals; // Stores visuals needed by the control, non trivial type so std::vector used.
913 std::string mStyleName;
914 Vector4 mBackgroundColor; ///< The color of the background visual
915 Vector3* mStartingPinchScale; ///< The scale when a pinch gesture starts, TODO: consider removing this
916 Toolkit::Control::KeyEventSignalType mKeyEventSignal;
917 Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusGainedSignal;
918 Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusLostSignal;
921 PinchGestureDetector mPinchGestureDetector;
922 PanGestureDetector mPanGestureDetector;
923 TapGestureDetector mTapGestureDetector;
924 LongPressGestureDetector mLongPressGestureDetector;
929 ControlBehaviour mFlags : CONTROL_BEHAVIOUR_FLAG_COUNT; ///< Flags passed in from constructor.
930 bool mIsKeyboardNavigationSupported :1; ///< Stores whether keyboard navigation is supported by the control.
931 bool mIsKeyboardFocusGroup :1; ///< Stores whether the control is a focus group.
933 // Properties - these need to be members of Internal::Control::Impl as they access private methods/data of Internal::Control and Internal::Control::Impl.
934 static const PropertyRegistration PROPERTY_1;
935 static const PropertyRegistration PROPERTY_2;
936 static const PropertyRegistration PROPERTY_3;
937 static const PropertyRegistration PROPERTY_4;
938 static const PropertyRegistration PROPERTY_5;
939 static const PropertyRegistration PROPERTY_6;
940 static const PropertyRegistration PROPERTY_7;
941 static const PropertyRegistration PROPERTY_8;
942 static const PropertyRegistration PROPERTY_9;
943 static const PropertyRegistration PROPERTY_10;
944 static const PropertyRegistration PROPERTY_11;
945 static const PropertyRegistration PROPERTY_12;
948 // Properties registered without macro to use specific member variables.
949 const PropertyRegistration Control::Impl::PROPERTY_1( typeRegistration, "styleName", Toolkit::Control::Property::STYLE_NAME, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
950 const PropertyRegistration Control::Impl::PROPERTY_2( typeRegistration, "backgroundColor", Toolkit::Control::Property::BACKGROUND_COLOR, Property::VECTOR4, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
951 const PropertyRegistration Control::Impl::PROPERTY_3( typeRegistration, "backgroundImage", Toolkit::Control::Property::BACKGROUND_IMAGE, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
952 const PropertyRegistration Control::Impl::PROPERTY_4( typeRegistration, "keyInputFocus", Toolkit::Control::Property::KEY_INPUT_FOCUS, Property::BOOLEAN, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
953 const PropertyRegistration Control::Impl::PROPERTY_5( typeRegistration, "background", Toolkit::Control::Property::BACKGROUND, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
954 const PropertyRegistration Control::Impl::PROPERTY_6( typeRegistration, "tooltip", Toolkit::DevelControl::Property::TOOLTIP, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
955 const PropertyRegistration Control::Impl::PROPERTY_7( typeRegistration, "state", Toolkit::DevelControl::Property::STATE, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
956 const PropertyRegistration Control::Impl::PROPERTY_8( typeRegistration, "subState", Toolkit::DevelControl::Property::SUB_STATE, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
957 const PropertyRegistration Control::Impl::PROPERTY_9( typeRegistration, "leftFocusableActorId", Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID, Property::INTEGER, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
958 const PropertyRegistration Control::Impl::PROPERTY_10( typeRegistration, "rightFocusableActorId", Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID,Property::INTEGER, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
959 const PropertyRegistration Control::Impl::PROPERTY_11( typeRegistration, "upFocusableActorId", Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID, Property::INTEGER, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
960 const PropertyRegistration Control::Impl::PROPERTY_12( typeRegistration, "downFocusableActorId", Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID, Property::INTEGER, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
962 Toolkit::Control Control::New()
964 // Create the implementation, temporarily owned on stack
965 IntrusivePtr<Control> controlImpl = new Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) );
967 // Pass ownership to handle
968 Toolkit::Control handle( *controlImpl );
970 // Second-phase init of the implementation
971 // This can only be done after the CustomActor connection has been made...
972 controlImpl->Initialize();
977 void Control::SetStyleName( const std::string& styleName )
979 if( styleName != mImpl->mStyleName )
981 mImpl->mStyleName = styleName;
983 // Apply new style, if stylemanager is available
984 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
987 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
992 const std::string& Control::GetStyleName() const
994 return mImpl->mStyleName;
997 void Control::SetBackgroundColor( const Vector4& color )
999 mImpl->mBackgroundColor = color;
1001 map[ Toolkit::DevelVisual::Property::TYPE ] = Toolkit::Visual::COLOR;
1002 map[ Toolkit::ColorVisual::Property::MIX_COLOR ] = color;
1004 SetBackground( map );
1007 Vector4 Control::GetBackgroundColor() const
1009 return mImpl->mBackgroundColor;
1012 void Control::SetBackground( const Property::Map& map )
1014 Toolkit::Visual::Base visual = Toolkit::VisualFactory::Get().CreateVisual( map );
1017 RegisterVisual( Toolkit::Control::Property::BACKGROUND, visual );
1018 visual.SetDepthIndex( DepthIndex::BACKGROUND );
1020 // Trigger a size negotiation request that may be needed by the new visual to relayout its contents.
1025 void Control::SetBackgroundImage( Image image )
1027 Toolkit::Visual::Base visual = Toolkit::VisualFactory::Get().CreateVisual( image );
1030 RegisterVisual( Toolkit::Control::Property::BACKGROUND, visual );
1031 visual.SetDepthIndex( DepthIndex::BACKGROUND );
1035 void Control::ClearBackground()
1037 UnregisterVisual( Toolkit::Control::Property::BACKGROUND );
1038 mImpl->mBackgroundColor = Color::TRANSPARENT;
1040 // Trigger a size negotiation request that may be needed when unregistering a visual.
1044 void Control::EnableGestureDetection(Gesture::Type type)
1046 if ( (type & Gesture::Pinch) && !mImpl->mPinchGestureDetector )
1048 mImpl->mPinchGestureDetector = PinchGestureDetector::New();
1049 mImpl->mPinchGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PinchDetected);
1050 mImpl->mPinchGestureDetector.Attach(Self());
1053 if ( (type & Gesture::Pan) && !mImpl->mPanGestureDetector )
1055 mImpl->mPanGestureDetector = PanGestureDetector::New();
1056 mImpl->mPanGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PanDetected);
1057 mImpl->mPanGestureDetector.Attach(Self());
1060 if ( (type & Gesture::Tap) && !mImpl->mTapGestureDetector )
1062 mImpl->mTapGestureDetector = TapGestureDetector::New();
1063 mImpl->mTapGestureDetector.DetectedSignal().Connect(mImpl, &Impl::TapDetected);
1064 mImpl->mTapGestureDetector.Attach(Self());
1067 if ( (type & Gesture::LongPress) && !mImpl->mLongPressGestureDetector )
1069 mImpl->mLongPressGestureDetector = LongPressGestureDetector::New();
1070 mImpl->mLongPressGestureDetector.DetectedSignal().Connect(mImpl, &Impl::LongPressDetected);
1071 mImpl->mLongPressGestureDetector.Attach(Self());
1075 void Control::DisableGestureDetection(Gesture::Type type)
1077 if ( (type & Gesture::Pinch) && mImpl->mPinchGestureDetector )
1079 mImpl->mPinchGestureDetector.Detach(Self());
1080 mImpl->mPinchGestureDetector.Reset();
1083 if ( (type & Gesture::Pan) && mImpl->mPanGestureDetector )
1085 mImpl->mPanGestureDetector.Detach(Self());
1086 mImpl->mPanGestureDetector.Reset();
1089 if ( (type & Gesture::Tap) && mImpl->mTapGestureDetector )
1091 mImpl->mTapGestureDetector.Detach(Self());
1092 mImpl->mTapGestureDetector.Reset();
1095 if ( (type & Gesture::LongPress) && mImpl->mLongPressGestureDetector)
1097 mImpl->mLongPressGestureDetector.Detach(Self());
1098 mImpl->mLongPressGestureDetector.Reset();
1102 PinchGestureDetector Control::GetPinchGestureDetector() const
1104 return mImpl->mPinchGestureDetector;
1107 PanGestureDetector Control::GetPanGestureDetector() const
1109 return mImpl->mPanGestureDetector;
1112 TapGestureDetector Control::GetTapGestureDetector() const
1114 return mImpl->mTapGestureDetector;
1117 LongPressGestureDetector Control::GetLongPressGestureDetector() const
1119 return mImpl->mLongPressGestureDetector;
1122 void Control::SetKeyboardNavigationSupport(bool isSupported)
1124 mImpl->mIsKeyboardNavigationSupported = isSupported;
1127 bool Control::IsKeyboardNavigationSupported()
1129 return mImpl->mIsKeyboardNavigationSupported;
1132 void Control::SetKeyInputFocus()
1134 if( Self().OnStage() )
1136 Toolkit::KeyInputFocusManager::Get().SetFocus(Toolkit::Control::DownCast(Self()));
1140 bool Control::HasKeyInputFocus()
1142 bool result = false;
1143 if( Self().OnStage() )
1145 Toolkit::Control control = Toolkit::KeyInputFocusManager::Get().GetCurrentFocusControl();
1146 if( Self() == control )
1154 void Control::ClearKeyInputFocus()
1156 if( Self().OnStage() )
1158 Toolkit::KeyInputFocusManager::Get().RemoveFocus(Toolkit::Control::DownCast(Self()));
1162 void Control::SetAsKeyboardFocusGroup(bool isFocusGroup)
1164 mImpl->mIsKeyboardFocusGroup = isFocusGroup;
1166 // The following line will be removed when the deprecated API in KeyboardFocusManager is deleted
1167 Toolkit::KeyboardFocusManager::Get().SetAsFocusGroup(Self(), isFocusGroup);
1170 bool Control::IsKeyboardFocusGroup()
1172 return Toolkit::KeyboardFocusManager::Get().IsFocusGroup(Self());
1175 void Control::AccessibilityActivate()
1177 // Inform deriving classes
1178 OnAccessibilityActivated();
1181 void Control::KeyboardEnter()
1183 // Inform deriving classes
1187 void Control::RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual )
1189 RegisterVisual( index, visual, true );
1192 void Control::RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, bool enabled )
1194 bool visualReplaced ( false );
1195 Actor self = Self();
1197 if( !mImpl->mVisuals.Empty() )
1199 RegisteredVisualContainer::Iterator iter;
1200 // Check if visual (index) is already registered. Replace if so.
1201 if ( FindVisual( index, mImpl->mVisuals, iter ) )
1203 if( (*iter)->visual && self.OnStage() )
1205 Toolkit::GetImplementation((*iter)->visual).SetOffStage( self );
1207 (*iter)->visual = visual;
1208 visualReplaced = true;
1212 // If not set, set the name of the visual to the same name as the control's property.
1213 // ( If the control has been type registered )
1214 if( visual.GetName().empty() )
1216 // Check if the control has been type registered:
1217 TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(*this) );
1220 // Check if the property index has been registered:
1221 Property::IndexContainer indices;
1222 typeInfo.GetPropertyIndices( indices );
1223 Property::IndexContainer::Iterator iter = std::find( indices.Begin(), indices.End(), index );
1224 if( iter != indices.End() )
1226 // If it has, then get it's name and use that for the visual
1227 std::string visualName = typeInfo.GetPropertyName( index );
1228 visual.SetName( visualName );
1233 if( !visualReplaced ) // New registration entry
1235 mImpl->mVisuals.PushBack( new RegisteredVisual( index, visual, enabled ) );
1238 if( visual && self.OnStage() && enabled )
1240 Toolkit::GetImplementation(visual).SetOnStage( self );
1243 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::RegisterVisual() Registered %s(%d), enabled:%s\n", visual.GetName().c_str(), index, enabled?"T":"F" );
1246 void Control::UnregisterVisual( Property::Index index )
1248 RegisteredVisualContainer::Iterator iter;
1249 if ( FindVisual( index, mImpl->mVisuals, iter ) )
1251 Actor self( Self() );
1252 Toolkit::GetImplementation((*iter)->visual).SetOffStage( self );
1253 (*iter)->visual.Reset();
1254 mImpl->mVisuals.Erase( iter );
1258 Toolkit::Visual::Base Control::GetVisual( Property::Index index ) const
1260 RegisteredVisualContainer::Iterator iter;
1261 if ( FindVisual( index, mImpl->mVisuals, iter ) )
1263 return (*iter)->visual;
1266 return Toolkit::Visual::Base();
1269 void Control::EnableVisual( Property::Index index, bool enable )
1271 RegisteredVisualContainer::Iterator iter;
1272 if ( FindVisual( index, mImpl->mVisuals, iter ) )
1274 if ( (*iter)->enabled == enable )
1276 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::EnableVisual Visual %s(%d) already %s\n", (*iter)->visual.GetName().c_str(), index, enable?"enabled":"disabled");
1280 (*iter)->enabled = enable;
1281 Actor parentActor = Self();
1282 if ( Self().OnStage() ) // If control not on Stage then Visual will be added when StageConnection is called.
1286 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::EnableVisual Setting %s(%d) on stage \n", (*iter)->visual.GetName().c_str(), index );
1287 Toolkit::GetImplementation((*iter)->visual).SetOnStage( parentActor );
1291 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::EnableVisual Setting %s(%d) off stage \n", (*iter)->visual.GetName().c_str(), index );
1292 Toolkit::GetImplementation((*iter)->visual).SetOffStage( parentActor ); // No need to call if control not staged.
1298 bool Control::IsVisualEnabled( Property::Index index ) const
1300 RegisteredVisualContainer::Iterator iter;
1301 if ( FindVisual( index, mImpl->mVisuals, iter ) )
1303 return (*iter)->enabled;
1308 Dali::Animation Control::CreateTransition( const Toolkit::TransitionData& handle )
1310 Dali::Animation transition;
1311 const Internal::TransitionData& transitionData = Toolkit::GetImplementation( handle );
1313 if( transitionData.Count() > 0 )
1315 // Setup a Transition from TransitionData.
1316 TransitionData::Iterator end = transitionData.End();
1317 for( TransitionData::Iterator iter = transitionData.Begin() ;
1318 iter != end; ++iter )
1320 TransitionData::Animator* animator = (*iter);
1322 Toolkit::Visual::Base visual = GetVisualByName( mImpl->mVisuals, animator->objectName );
1326 Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
1327 visualImpl.AnimateProperty( transition, *animator );
1331 // Otherwise, try any actor children of control (Including the control)
1332 Actor child = Self().FindChildByName( animator->objectName );
1335 Property::Index propertyIndex = DevelHandle::GetPropertyIndex( child, animator->propertyKey );
1336 if( propertyIndex != Property::INVALID_INDEX )
1338 if( animator->animate == false )
1340 if( animator->targetValue.GetType() != Property::NONE )
1342 child.SetProperty( propertyIndex, animator->targetValue );
1345 else // animate the property
1347 if( animator->initialValue.GetType() != Property::NONE )
1349 child.SetProperty( propertyIndex, animator->initialValue );
1354 transition = Dali::Animation::New( 0.1f );
1357 transition.AnimateTo( Property( child, propertyIndex ),
1358 animator->targetValue,
1359 animator->alphaFunction,
1360 TimePeriod( animator->timePeriodDelay,
1361 animator->timePeriodDuration ) );
1372 bool Control::OnAccessibilityActivated()
1374 return false; // Accessibility activation is not handled by default
1377 bool Control::OnKeyboardEnter()
1379 return false; // Keyboard enter is not handled by default
1382 bool Control::OnAccessibilityPan(PanGesture gesture)
1384 return false; // Accessibility pan gesture is not handled by default
1387 bool Control::OnAccessibilityTouch(const TouchEvent& touchEvent)
1389 return false; // Accessibility touch event is not handled by default
1392 bool Control::OnAccessibilityValueChange(bool isIncrease)
1394 return false; // Accessibility value change action is not handled by default
1397 bool Control::OnAccessibilityZoom()
1399 return false; // Accessibility zoom action is not handled by default
1402 Actor Control::GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocus::Direction direction, bool loopEnabled)
1407 void Control::OnKeyboardFocusChangeCommitted(Actor commitedFocusableActor)
1411 Toolkit::Control::KeyEventSignalType& Control::KeyEventSignal()
1413 return mImpl->mKeyEventSignal;
1416 Toolkit::Control::KeyInputFocusSignalType& Control::KeyInputFocusGainedSignal()
1418 return mImpl->mKeyInputFocusGainedSignal;
1421 Toolkit::Control::KeyInputFocusSignalType& Control::KeyInputFocusLostSignal()
1423 return mImpl->mKeyInputFocusLostSignal;
1426 bool Control::EmitKeyEventSignal( const KeyEvent& event )
1428 // Guard against destruction during signal emission
1429 Dali::Toolkit::Control handle( GetOwner() );
1431 bool consumed = false;
1433 // signals are allocated dynamically when someone connects
1434 if ( !mImpl->mKeyEventSignal.Empty() )
1436 consumed = mImpl->mKeyEventSignal.Emit( handle, event );
1441 // Notification for derived classes
1442 consumed = OnKeyEvent(event);
1448 Control::Control( ControlBehaviour behaviourFlags )
1449 : CustomActorImpl( static_cast< ActorFlags >( behaviourFlags ) ),
1450 mImpl(new Impl(*this))
1452 mImpl->mFlags = behaviourFlags;
1460 void Control::Initialize()
1462 // Call deriving classes so initialised before styling is applied to them.
1465 if( (mImpl->mFlags & REQUIRES_STYLE_CHANGE_SIGNALS) ||
1466 !(mImpl->mFlags & DISABLE_STYLE_CHANGE_SIGNALS) )
1468 Toolkit::StyleManager styleManager = StyleManager::Get();
1470 // if stylemanager is available
1473 StyleManager& styleManagerImpl = GetImpl( styleManager );
1475 // Register for style changes
1476 styleManagerImpl.ControlStyleChangeSignal().Connect( this, &Control::OnStyleChange );
1478 // Apply the current style
1479 styleManagerImpl.ApplyThemeStyleAtInit( Toolkit::Control( GetOwner() ) );
1483 if( mImpl->mFlags & REQUIRES_KEYBOARD_NAVIGATION_SUPPORT )
1485 SetKeyboardNavigationSupport( true );
1489 void Control::OnInitialize()
1493 void Control::OnControlChildAdd( Actor& child )
1497 void Control::OnControlChildRemove( Actor& child )
1501 void Control::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
1503 // By default the control is only interested in theme (not font) changes
1504 if( styleManager && change == StyleChange::THEME_CHANGE )
1506 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
1511 void Control::OnPinch(const PinchGesture& pinch)
1513 if( !( mImpl->mStartingPinchScale ) )
1516 mImpl->mStartingPinchScale = new Vector3;
1519 if( pinch.state == Gesture::Started )
1521 *( mImpl->mStartingPinchScale ) = Self().GetCurrentScale();
1524 Self().SetScale( *( mImpl->mStartingPinchScale ) * pinch.scale );
1527 void Control::OnPan( const PanGesture& pan )
1531 void Control::OnTap(const TapGesture& tap)
1535 void Control::OnLongPress( const LongPressGesture& longPress )
1539 void Control::EmitKeyInputFocusSignal( bool focusGained )
1541 Dali::Toolkit::Control handle( GetOwner() );
1545 // signals are allocated dynamically when someone connects
1546 if ( !mImpl->mKeyInputFocusGainedSignal.Empty() )
1548 mImpl->mKeyInputFocusGainedSignal.Emit( handle );
1553 // signals are allocated dynamically when someone connects
1554 if ( !mImpl->mKeyInputFocusLostSignal.Empty() )
1556 mImpl->mKeyInputFocusLostSignal.Emit( handle );
1561 void Control::OnStageConnection( int depth )
1563 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::OnStageConnection number of registered visuals(%d)\n", mImpl->mVisuals.Size() );
1565 Actor self( Self() );
1567 for(RegisteredVisualContainer::Iterator iter = mImpl->mVisuals.Begin(); iter!= mImpl->mVisuals.End(); iter++)
1569 // Check whether the visual is empty and enabled
1570 if( (*iter)->visual && (*iter)->enabled )
1572 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::OnStageConnection Setting visual(%d) on stage\n", (*iter)->index );
1573 Toolkit::GetImplementation((*iter)->visual).SetOnStage( self );
1577 if( mImpl->mVisuals.Empty() && ! self.GetRendererCount() )
1579 Property::Value clippingValue = self.GetProperty( Actor::Property::CLIPPING_MODE );
1580 int clippingMode = ClippingMode::DISABLED;
1581 if( clippingValue.Get( clippingMode ) )
1583 // Add a transparent background if we do not have any renderers or visuals so we clip our children
1585 if( clippingMode == ClippingMode::CLIP_CHILDREN )
1587 // Create a transparent background visual which will also get staged.
1588 SetBackgroundColor( Color::TRANSPARENT );
1594 void Control::OnStageDisconnection()
1596 for(RegisteredVisualContainer::Iterator iter = mImpl->mVisuals.Begin(); iter!= mImpl->mVisuals.End(); iter++)
1598 // Check whether the visual is empty
1599 if( (*iter)->visual )
1601 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::OnStageDisconnection Setting visual(%d) off stage\n", (*iter)->index );
1602 Actor self( Self() );
1603 Toolkit::GetImplementation((*iter)->visual).SetOffStage( self );
1608 void Control::OnKeyInputFocusGained()
1610 EmitKeyInputFocusSignal( true );
1613 void Control::OnKeyInputFocusLost()
1615 EmitKeyInputFocusSignal( false );
1618 void Control::OnChildAdd(Actor& child)
1620 // Notify derived classes.
1621 OnControlChildAdd( child );
1624 void Control::OnChildRemove(Actor& child)
1626 // Notify derived classes.
1627 OnControlChildRemove( child );
1630 void Control::OnPropertySet( Property::Index index, Property::Value propertyValue )
1632 Actor self( Self() );
1633 if( index == Actor::Property::CLIPPING_MODE )
1635 // Only set the background if we're already on the stage and have no renderers or visuals
1637 if( mImpl->mVisuals.Empty() && ! self.GetRendererCount() && self.OnStage() )
1639 ClippingMode::Type clippingMode = ClippingMode::DISABLED;
1640 if( Scripting::GetEnumerationProperty< ClippingMode::Type >( propertyValue, CLIPPING_MODE_TABLE, CLIPPING_MODE_TABLE_COUNT, clippingMode ) )
1642 // Add a transparent background if we do not have one so we clip children
1644 if( clippingMode == ClippingMode::CLIP_CHILDREN )
1646 SetBackgroundColor( Color::TRANSPARENT );
1653 void Control::OnSizeSet(const Vector3& targetSize)
1655 Toolkit::Visual::Base visual = GetVisual( Toolkit::Control::Property::BACKGROUND );
1658 Vector2 size( targetSize );
1659 visual.SetTransformAndSize( Property::Map(), size ); // Send an empty map as we do not want to modify the visual's set transform
1663 void Control::OnSizeAnimation(Animation& animation, const Vector3& targetSize)
1665 // @todo size negotiate background to new size, animate as well?
1668 bool Control::OnTouchEvent(const TouchEvent& event)
1670 return false; // Do not consume
1673 bool Control::OnHoverEvent(const HoverEvent& event)
1675 return false; // Do not consume
1678 bool Control::OnKeyEvent(const KeyEvent& event)
1680 return false; // Do not consume
1683 bool Control::OnWheelEvent(const WheelEvent& event)
1685 return false; // Do not consume
1688 void Control::OnRelayout( const Vector2& size, RelayoutContainer& container )
1690 for( unsigned int i = 0, numChildren = Self().GetChildCount(); i < numChildren; ++i )
1692 container.Add( Self().GetChildAt( i ), size );
1695 Toolkit::Visual::Base visual = GetVisual( Toolkit::Control::Property::BACKGROUND );
1698 visual.SetTransformAndSize( Property::Map(), size ); // Send an empty map as we do not want to modify the visual's set transform
1702 void Control::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
1706 Vector3 Control::GetNaturalSize()
1708 Toolkit::Visual::Base visual = GetVisual( Toolkit::Control::Property::BACKGROUND );
1711 Vector2 naturalSize;
1712 visual.GetNaturalSize( naturalSize );
1713 return Vector3( naturalSize );
1715 return Vector3::ZERO;
1718 float Control::CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension )
1720 return CalculateChildSizeBase( child, dimension );
1723 float Control::GetHeightForWidth( float width )
1725 return GetHeightForWidthBase( width );
1728 float Control::GetWidthForHeight( float height )
1730 return GetWidthForHeightBase( height );
1733 bool Control::RelayoutDependentOnChildren( Dimension::Type dimension )
1735 return RelayoutDependentOnChildrenBase( dimension );
1738 void Control::OnCalculateRelayoutSize( Dimension::Type dimension )
1742 void Control::OnLayoutNegotiated( float size, Dimension::Type dimension )
1746 void Control::SignalConnected( SlotObserver* slotObserver, CallbackBase* callback )
1748 mImpl->SignalConnected( slotObserver, callback );
1751 void Control::SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback )
1753 mImpl->SignalDisconnected( slotObserver, callback );
1756 Control& GetImplementation( Dali::Toolkit::Control& handle )
1758 CustomActorImpl& customInterface = handle.GetImplementation();
1759 // downcast to control
1760 Control& impl = dynamic_cast< Internal::Control& >( customInterface );
1764 const Control& GetImplementation( const Dali::Toolkit::Control& handle )
1766 const CustomActorImpl& customInterface = handle.GetImplementation();
1767 // downcast to control
1768 const Control& impl = dynamic_cast< const Internal::Control& >( customInterface );
1772 } // namespace Internal
1774 } // namespace Toolkit