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 result = Toolkit::KeyInputFocusManager::Get().IsKeyboardListener(Toolkit::Control::DownCast(Self()));
1150 void Control::ClearKeyInputFocus()
1152 if( Self().OnStage() )
1154 Toolkit::KeyInputFocusManager::Get().RemoveFocus(Toolkit::Control::DownCast(Self()));
1158 void Control::SetAsKeyboardFocusGroup(bool isFocusGroup)
1160 mImpl->mIsKeyboardFocusGroup = isFocusGroup;
1162 // The following line will be removed when the deprecated API in KeyboardFocusManager is deleted
1163 Toolkit::KeyboardFocusManager::Get().SetAsFocusGroup(Self(), isFocusGroup);
1166 bool Control::IsKeyboardFocusGroup()
1168 return Toolkit::KeyboardFocusManager::Get().IsFocusGroup(Self());
1171 void Control::AccessibilityActivate()
1173 // Inform deriving classes
1174 OnAccessibilityActivated();
1177 void Control::KeyboardEnter()
1179 // Inform deriving classes
1183 void Control::RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual )
1185 RegisterVisual( index, visual, true );
1188 void Control::RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, bool enabled )
1190 bool visualReplaced ( false );
1191 Actor self = Self();
1193 if( !mImpl->mVisuals.Empty() )
1195 RegisteredVisualContainer::Iterator iter;
1196 // Check if visual (index) is already registered. Replace if so.
1197 if ( FindVisual( index, mImpl->mVisuals, iter ) )
1199 if( (*iter)->visual && self.OnStage() )
1201 Toolkit::GetImplementation((*iter)->visual).SetOffStage( self );
1203 (*iter)->visual = visual;
1204 visualReplaced = true;
1208 // If not set, set the name of the visual to the same name as the control's property.
1209 // ( If the control has been type registered )
1210 if( visual.GetName().empty() )
1212 // Check if the control has been type registered:
1213 TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(*this) );
1216 // Check if the property index has been registered:
1217 Property::IndexContainer indices;
1218 typeInfo.GetPropertyIndices( indices );
1219 Property::IndexContainer::Iterator iter = std::find( indices.Begin(), indices.End(), index );
1220 if( iter != indices.End() )
1222 // If it has, then get it's name and use that for the visual
1223 std::string visualName = typeInfo.GetPropertyName( index );
1224 visual.SetName( visualName );
1229 if( !visualReplaced ) // New registration entry
1231 mImpl->mVisuals.PushBack( new RegisteredVisual( index, visual, enabled ) );
1234 if( visual && self.OnStage() && enabled )
1236 Toolkit::GetImplementation(visual).SetOnStage( self );
1239 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::RegisterVisual() Registered %s(%d), enabled:%s\n", visual.GetName().c_str(), index, enabled?"T":"F" );
1242 void Control::UnregisterVisual( Property::Index index )
1244 RegisteredVisualContainer::Iterator iter;
1245 if ( FindVisual( index, mImpl->mVisuals, iter ) )
1247 Actor self( Self() );
1248 Toolkit::GetImplementation((*iter)->visual).SetOffStage( self );
1249 (*iter)->visual.Reset();
1250 mImpl->mVisuals.Erase( iter );
1254 Toolkit::Visual::Base Control::GetVisual( Property::Index index ) const
1256 RegisteredVisualContainer::Iterator iter;
1257 if ( FindVisual( index, mImpl->mVisuals, iter ) )
1259 return (*iter)->visual;
1262 return Toolkit::Visual::Base();
1265 void Control::EnableVisual( Property::Index index, bool enable )
1267 RegisteredVisualContainer::Iterator iter;
1268 if ( FindVisual( index, mImpl->mVisuals, iter ) )
1270 if ( (*iter)->enabled == enable )
1272 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::EnableVisual Visual %s(%d) already %s\n", (*iter)->visual.GetName().c_str(), index, enable?"enabled":"disabled");
1276 (*iter)->enabled = enable;
1277 Actor parentActor = Self();
1278 if ( Self().OnStage() ) // If control not on Stage then Visual will be added when StageConnection is called.
1282 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::EnableVisual Setting %s(%d) on stage \n", (*iter)->visual.GetName().c_str(), index );
1283 Toolkit::GetImplementation((*iter)->visual).SetOnStage( parentActor );
1287 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::EnableVisual Setting %s(%d) off stage \n", (*iter)->visual.GetName().c_str(), index );
1288 Toolkit::GetImplementation((*iter)->visual).SetOffStage( parentActor ); // No need to call if control not staged.
1294 bool Control::IsVisualEnabled( Property::Index index ) const
1296 RegisteredVisualContainer::Iterator iter;
1297 if ( FindVisual( index, mImpl->mVisuals, iter ) )
1299 return (*iter)->enabled;
1304 Dali::Animation Control::CreateTransition( const Toolkit::TransitionData& handle )
1306 Dali::Animation transition;
1307 const Internal::TransitionData& transitionData = Toolkit::GetImplementation( handle );
1309 if( transitionData.Count() > 0 )
1311 // Setup a Transition from TransitionData.
1312 TransitionData::Iterator end = transitionData.End();
1313 for( TransitionData::Iterator iter = transitionData.Begin() ;
1314 iter != end; ++iter )
1316 TransitionData::Animator* animator = (*iter);
1318 Toolkit::Visual::Base visual = GetVisualByName( mImpl->mVisuals, animator->objectName );
1322 Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
1323 visualImpl.AnimateProperty( transition, *animator );
1327 // Otherwise, try any actor children of control (Including the control)
1328 Actor child = Self().FindChildByName( animator->objectName );
1331 Property::Index propertyIndex = DevelHandle::GetPropertyIndex( child, animator->propertyKey );
1332 if( propertyIndex != Property::INVALID_INDEX )
1334 if( animator->animate == false )
1336 if( animator->targetValue.GetType() != Property::NONE )
1338 child.SetProperty( propertyIndex, animator->targetValue );
1341 else // animate the property
1343 if( animator->initialValue.GetType() != Property::NONE )
1345 child.SetProperty( propertyIndex, animator->initialValue );
1350 transition = Dali::Animation::New( 0.1f );
1353 transition.AnimateTo( Property( child, propertyIndex ),
1354 animator->targetValue,
1355 animator->alphaFunction,
1356 TimePeriod( animator->timePeriodDelay,
1357 animator->timePeriodDuration ) );
1368 bool Control::OnAccessibilityActivated()
1370 return false; // Accessibility activation is not handled by default
1373 bool Control::OnKeyboardEnter()
1375 return false; // Keyboard enter is not handled by default
1378 bool Control::OnAccessibilityPan(PanGesture gesture)
1380 return false; // Accessibility pan gesture is not handled by default
1383 bool Control::OnAccessibilityTouch(const TouchEvent& touchEvent)
1385 return false; // Accessibility touch event is not handled by default
1388 bool Control::OnAccessibilityValueChange(bool isIncrease)
1390 return false; // Accessibility value change action is not handled by default
1393 bool Control::OnAccessibilityZoom()
1395 return false; // Accessibility zoom action is not handled by default
1398 Actor Control::GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocus::Direction direction, bool loopEnabled)
1403 void Control::OnKeyboardFocusChangeCommitted(Actor commitedFocusableActor)
1407 Toolkit::Control::KeyEventSignalType& Control::KeyEventSignal()
1409 return mImpl->mKeyEventSignal;
1412 Toolkit::Control::KeyInputFocusSignalType& Control::KeyInputFocusGainedSignal()
1414 return mImpl->mKeyInputFocusGainedSignal;
1417 Toolkit::Control::KeyInputFocusSignalType& Control::KeyInputFocusLostSignal()
1419 return mImpl->mKeyInputFocusLostSignal;
1422 bool Control::EmitKeyEventSignal( const KeyEvent& event )
1424 // Guard against destruction during signal emission
1425 Dali::Toolkit::Control handle( GetOwner() );
1427 bool consumed = false;
1429 // signals are allocated dynamically when someone connects
1430 if ( !mImpl->mKeyEventSignal.Empty() )
1432 consumed = mImpl->mKeyEventSignal.Emit( handle, event );
1437 // Notification for derived classes
1438 consumed = OnKeyEvent(event);
1444 Control::Control( ControlBehaviour behaviourFlags )
1445 : CustomActorImpl( static_cast< ActorFlags >( behaviourFlags ) ),
1446 mImpl(new Impl(*this))
1448 mImpl->mFlags = behaviourFlags;
1456 void Control::Initialize()
1458 // Call deriving classes so initialised before styling is applied to them.
1461 if( (mImpl->mFlags & REQUIRES_STYLE_CHANGE_SIGNALS) ||
1462 !(mImpl->mFlags & DISABLE_STYLE_CHANGE_SIGNALS) )
1464 Toolkit::StyleManager styleManager = StyleManager::Get();
1466 // if stylemanager is available
1469 StyleManager& styleManagerImpl = GetImpl( styleManager );
1471 // Register for style changes
1472 styleManagerImpl.ControlStyleChangeSignal().Connect( this, &Control::OnStyleChange );
1474 // Apply the current style
1475 styleManagerImpl.ApplyThemeStyleAtInit( Toolkit::Control( GetOwner() ) );
1479 if( mImpl->mFlags & REQUIRES_KEYBOARD_NAVIGATION_SUPPORT )
1481 SetKeyboardNavigationSupport( true );
1485 void Control::OnInitialize()
1489 void Control::OnControlChildAdd( Actor& child )
1493 void Control::OnControlChildRemove( Actor& child )
1497 void Control::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
1499 // By default the control is only interested in theme (not font) changes
1500 if( styleManager && change == StyleChange::THEME_CHANGE )
1502 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
1507 void Control::OnPinch(const PinchGesture& pinch)
1509 if( !( mImpl->mStartingPinchScale ) )
1512 mImpl->mStartingPinchScale = new Vector3;
1515 if( pinch.state == Gesture::Started )
1517 *( mImpl->mStartingPinchScale ) = Self().GetCurrentScale();
1520 Self().SetScale( *( mImpl->mStartingPinchScale ) * pinch.scale );
1523 void Control::OnPan( const PanGesture& pan )
1527 void Control::OnTap(const TapGesture& tap)
1531 void Control::OnLongPress( const LongPressGesture& longPress )
1535 void Control::EmitKeyInputFocusSignal( bool focusGained )
1537 Dali::Toolkit::Control handle( GetOwner() );
1541 // signals are allocated dynamically when someone connects
1542 if ( !mImpl->mKeyInputFocusGainedSignal.Empty() )
1544 mImpl->mKeyInputFocusGainedSignal.Emit( handle );
1549 // signals are allocated dynamically when someone connects
1550 if ( !mImpl->mKeyInputFocusLostSignal.Empty() )
1552 mImpl->mKeyInputFocusLostSignal.Emit( handle );
1557 void Control::OnStageConnection( int depth )
1559 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::OnStageConnection number of registered visuals(%d)\n", mImpl->mVisuals.Size() );
1561 Actor self( Self() );
1563 for(RegisteredVisualContainer::Iterator iter = mImpl->mVisuals.Begin(); iter!= mImpl->mVisuals.End(); iter++)
1565 // Check whether the visual is empty and enabled
1566 if( (*iter)->visual && (*iter)->enabled )
1568 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::OnStageConnection Setting visual(%d) on stage\n", (*iter)->index );
1569 Toolkit::GetImplementation((*iter)->visual).SetOnStage( self );
1573 if( mImpl->mVisuals.Empty() && ! self.GetRendererCount() )
1575 Property::Value clippingValue = self.GetProperty( Actor::Property::CLIPPING_MODE );
1576 int clippingMode = ClippingMode::DISABLED;
1577 if( clippingValue.Get( clippingMode ) )
1579 // Add a transparent background if we do not have any renderers or visuals so we clip our children
1581 if( clippingMode == ClippingMode::CLIP_CHILDREN )
1583 // Create a transparent background visual which will also get staged.
1584 SetBackgroundColor( Color::TRANSPARENT );
1590 void Control::OnStageDisconnection()
1592 for(RegisteredVisualContainer::Iterator iter = mImpl->mVisuals.Begin(); iter!= mImpl->mVisuals.End(); iter++)
1594 // Check whether the visual is empty
1595 if( (*iter)->visual )
1597 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::OnStageDisconnection Setting visual(%d) off stage\n", (*iter)->index );
1598 Actor self( Self() );
1599 Toolkit::GetImplementation((*iter)->visual).SetOffStage( self );
1604 void Control::OnKeyInputFocusGained()
1606 EmitKeyInputFocusSignal( true );
1609 void Control::OnKeyInputFocusLost()
1611 EmitKeyInputFocusSignal( false );
1614 void Control::OnChildAdd(Actor& child)
1616 // Notify derived classes.
1617 OnControlChildAdd( child );
1620 void Control::OnChildRemove(Actor& child)
1622 // Notify derived classes.
1623 OnControlChildRemove( child );
1626 void Control::OnPropertySet( Property::Index index, Property::Value propertyValue )
1628 Actor self( Self() );
1629 if( index == Actor::Property::CLIPPING_MODE )
1631 // Only set the background if we're already on the stage and have no renderers or visuals
1633 if( mImpl->mVisuals.Empty() && ! self.GetRendererCount() && self.OnStage() )
1635 ClippingMode::Type clippingMode = ClippingMode::DISABLED;
1636 if( Scripting::GetEnumerationProperty< ClippingMode::Type >( propertyValue, CLIPPING_MODE_TABLE, CLIPPING_MODE_TABLE_COUNT, clippingMode ) )
1638 // Add a transparent background if we do not have one so we clip children
1640 if( clippingMode == ClippingMode::CLIP_CHILDREN )
1642 SetBackgroundColor( Color::TRANSPARENT );
1649 void Control::OnSizeSet(const Vector3& targetSize)
1651 Toolkit::Visual::Base visual = GetVisual( Toolkit::Control::Property::BACKGROUND );
1654 Vector2 size( targetSize );
1655 visual.SetTransformAndSize( Property::Map(), size ); // Send an empty map as we do not want to modify the visual's set transform
1659 void Control::OnSizeAnimation(Animation& animation, const Vector3& targetSize)
1661 // @todo size negotiate background to new size, animate as well?
1664 bool Control::OnTouchEvent(const TouchEvent& event)
1666 return false; // Do not consume
1669 bool Control::OnHoverEvent(const HoverEvent& event)
1671 return false; // Do not consume
1674 bool Control::OnKeyEvent(const KeyEvent& event)
1676 return false; // Do not consume
1679 bool Control::OnWheelEvent(const WheelEvent& event)
1681 return false; // Do not consume
1684 void Control::OnRelayout( const Vector2& size, RelayoutContainer& container )
1686 for( unsigned int i = 0, numChildren = Self().GetChildCount(); i < numChildren; ++i )
1688 container.Add( Self().GetChildAt( i ), size );
1691 Toolkit::Visual::Base visual = GetVisual( Toolkit::Control::Property::BACKGROUND );
1694 visual.SetTransformAndSize( Property::Map(), size ); // Send an empty map as we do not want to modify the visual's set transform
1698 void Control::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
1702 Vector3 Control::GetNaturalSize()
1704 Toolkit::Visual::Base visual = GetVisual( Toolkit::Control::Property::BACKGROUND );
1707 Vector2 naturalSize;
1708 visual.GetNaturalSize( naturalSize );
1709 return Vector3( naturalSize );
1711 return Vector3::ZERO;
1714 float Control::CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension )
1716 return CalculateChildSizeBase( child, dimension );
1719 float Control::GetHeightForWidth( float width )
1721 return GetHeightForWidthBase( width );
1724 float Control::GetWidthForHeight( float height )
1726 return GetWidthForHeightBase( height );
1729 bool Control::RelayoutDependentOnChildren( Dimension::Type dimension )
1731 return RelayoutDependentOnChildrenBase( dimension );
1734 void Control::OnCalculateRelayoutSize( Dimension::Type dimension )
1738 void Control::OnLayoutNegotiated( float size, Dimension::Type dimension )
1742 void Control::SignalConnected( SlotObserver* slotObserver, CallbackBase* callback )
1744 mImpl->SignalConnected( slotObserver, callback );
1747 void Control::SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback )
1749 mImpl->SignalDisconnected( slotObserver, callback );
1752 Control& GetImplementation( Dali::Toolkit::Control& handle )
1754 CustomActorImpl& customInterface = handle.GetImplementation();
1755 // downcast to control
1756 Control& impl = dynamic_cast< Internal::Control& >( customInterface );
1760 const Control& GetImplementation( const Dali::Toolkit::Control& handle )
1762 const CustomActorImpl& customInterface = handle.GetImplementation();
1763 // downcast to control
1764 const Control& impl = dynamic_cast< const Internal::Control& >( customInterface );
1768 } // namespace Internal
1770 } // namespace Toolkit