2 * Copyright (c) 2019 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 "control-data-impl.h"
22 #include <dali-toolkit/public-api/dali-toolkit-common.h>
23 #include <dali/integration-api/debug.h>
24 #include <dali/devel-api/object/handle-devel.h>
25 #include <dali/devel-api/scripting/enum-helper.h>
26 #include <dali/devel-api/scripting/scripting.h>
27 #include <dali/integration-api/debug.h>
28 #include <dali/public-api/object/type-registry-helper.h>
29 #include <dali/integration-api/adaptor-framework/adaptor.h>
34 #include <dali-toolkit/internal/visuals/visual-base-impl.h>
35 #include <dali-toolkit/public-api/visuals/image-visual-properties.h>
36 #include <dali-toolkit/public-api/visuals/visual-properties.h>
37 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
38 #include <dali-toolkit/devel-api/controls/control-devel.h>
39 #include <dali-toolkit/devel-api/controls/control-wrapper-impl.h>
40 #include <dali-toolkit/internal/styling/style-manager-impl.h>
41 #include <dali-toolkit/internal/visuals/visual-string-constants.h>
52 extern const Dali::Scripting::StringEnum ControlStateTable[];
53 extern const unsigned int ControlStateTableCount;
56 // Not static or anonymous - shared with other translation units
57 const Scripting::StringEnum ControlStateTable[] = {
58 { "NORMAL", Toolkit::DevelControl::NORMAL },
59 { "FOCUSED", Toolkit::DevelControl::FOCUSED },
60 { "DISABLED", Toolkit::DevelControl::DISABLED },
62 const unsigned int ControlStateTableCount = sizeof( ControlStateTable ) / sizeof( ControlStateTable[0] );
69 #if defined(DEBUG_ENABLED)
70 Debug::Filter* gLogFilter = Debug::Filter::New( Debug::NoLogging, false, "LOG_CONTROL_VISUALS");
75 void Remove( Dictionary<T>& keyValues, const std::string& name )
77 keyValues.Remove(name);
80 void Remove( DictionaryKeys& keys, const std::string& name )
82 DictionaryKeys::iterator iter = std::find( keys.begin(), keys.end(), name );
83 if( iter != keys.end())
89 Toolkit::Visual::Type GetVisualTypeFromMap( const Property::Map& map )
91 Property::Value* typeValue = map.Find( Toolkit::Visual::Property::TYPE, VISUAL_TYPE );
92 Toolkit::Visual::Type type = Toolkit::Visual::IMAGE;
95 Scripting::GetEnumerationProperty( *typeValue, VISUAL_TYPE_TABLE, VISUAL_TYPE_TABLE_COUNT, type );
101 * Finds visual in given array, returning true if found along with the iterator for that visual as a out parameter
103 bool FindVisual( Property::Index targetIndex, const RegisteredVisualContainer& visuals, RegisteredVisualContainer::Iterator& iter )
105 for ( iter = visuals.Begin(); iter != visuals.End(); iter++ )
107 if ( (*iter)->index == targetIndex )
115 void FindChangableVisuals( Dictionary<Property::Map>& stateVisualsToAdd,
116 Dictionary<Property::Map>& stateVisualsToChange,
117 DictionaryKeys& stateVisualsToRemove)
119 DictionaryKeys copyOfStateVisualsToRemove = stateVisualsToRemove;
121 for( DictionaryKeys::iterator iter = copyOfStateVisualsToRemove.begin();
122 iter != copyOfStateVisualsToRemove.end(); ++iter )
124 const std::string& visualName = (*iter);
125 Property::Map* toMap = stateVisualsToAdd.Find( visualName );
128 stateVisualsToChange.Add( visualName, *toMap );
129 stateVisualsToAdd.Remove( visualName );
130 Remove( stateVisualsToRemove, visualName );
135 Toolkit::Visual::Base GetVisualByName(
136 const RegisteredVisualContainer& visuals,
137 const std::string& visualName )
139 Toolkit::Visual::Base visualHandle;
141 RegisteredVisualContainer::Iterator iter;
142 for ( iter = visuals.Begin(); iter != visuals.End(); iter++ )
144 Toolkit::Visual::Base visual = (*iter)->visual;
145 if( visual && visual.GetName() == visualName )
147 visualHandle = visual;
155 * Move visual from source to destination container
157 void MoveVisual( RegisteredVisualContainer::Iterator sourceIter, RegisteredVisualContainer& source, RegisteredVisualContainer& destination )
159 Toolkit::Visual::Base visual = (*sourceIter)->visual;
162 RegisteredVisual* rv = source.Release( sourceIter );
163 destination.PushBack( rv );
168 * Performs actions as requested using the action name.
169 * @param[in] object The object on which to perform the action.
170 * @param[in] actionName The action to perform.
171 * @param[in] attributes The attributes with which to perfrom this action.
172 * @return true if action has been accepted by this control
174 const char* ACTION_ACCESSIBILITY_ACTIVATED = "accessibilityActivated";
175 static bool DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes )
179 if( object && ( 0 == strcmp( actionName.c_str(), ACTION_ACCESSIBILITY_ACTIVATED ) ) )
181 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
184 // if cast succeeds there is an implementation so no need to check
185 ret = Internal::GetImplementation( control ).OnAccessibilityActivated();
193 * Connects a callback function with the object's signals.
194 * @param[in] object The object providing the signal.
195 * @param[in] tracker Used to disconnect the signal.
196 * @param[in] signalName The signal to connect to.
197 * @param[in] functor A newly allocated FunctorDelegate.
198 * @return True if the signal was connected.
199 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
201 const char* SIGNAL_KEY_EVENT = "keyEvent";
202 const char* SIGNAL_KEY_INPUT_FOCUS_GAINED = "keyInputFocusGained";
203 const char* SIGNAL_KEY_INPUT_FOCUS_LOST = "keyInputFocusLost";
204 const char* SIGNAL_TAPPED = "tapped";
205 const char* SIGNAL_PANNED = "panned";
206 const char* SIGNAL_PINCHED = "pinched";
207 const char* SIGNAL_LONG_PRESSED = "longPressed";
208 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
210 Dali::BaseHandle handle( object );
212 bool connected( false );
213 Toolkit::Control control = Toolkit::Control::DownCast( handle );
216 Internal::Control& controlImpl( Internal::GetImplementation( control ) );
219 if ( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_EVENT ) )
221 controlImpl.KeyEventSignal().Connect( tracker, functor );
223 else if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_INPUT_FOCUS_GAINED ) )
225 controlImpl.KeyInputFocusGainedSignal().Connect( tracker, functor );
227 else if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_INPUT_FOCUS_LOST ) )
229 controlImpl.KeyInputFocusLostSignal().Connect( tracker, functor );
231 else if( 0 == strcmp( signalName.c_str(), SIGNAL_TAPPED ) )
233 controlImpl.EnableGestureDetection( GestureType::TAP );
234 controlImpl.GetTapGestureDetector().DetectedSignal().Connect( tracker, functor );
236 else if( 0 == strcmp( signalName.c_str(), SIGNAL_PANNED ) )
238 controlImpl.EnableGestureDetection( GestureType::PAN );
239 controlImpl.GetPanGestureDetector().DetectedSignal().Connect( tracker, functor );
241 else if( 0 == strcmp( signalName.c_str(), SIGNAL_PINCHED ) )
243 controlImpl.EnableGestureDetection( GestureType::PINCH );
244 controlImpl.GetPinchGestureDetector().DetectedSignal().Connect( tracker, functor );
246 else if( 0 == strcmp( signalName.c_str(), SIGNAL_LONG_PRESSED ) )
248 controlImpl.EnableGestureDetection( GestureType::LONG_PRESS );
249 controlImpl.GetLongPressGestureDetector().DetectedSignal().Connect( tracker, functor );
256 * Creates control through type registry
260 return Internal::Control::New();
262 // Setup signals and actions using the type-registry.
263 DALI_TYPE_REGISTRATION_BEGIN( Control, CustomActor, Create );
265 // Note: Properties are registered separately below.
267 SignalConnectorType registerSignal1( typeRegistration, SIGNAL_KEY_EVENT, &DoConnectSignal );
268 SignalConnectorType registerSignal2( typeRegistration, SIGNAL_KEY_INPUT_FOCUS_GAINED, &DoConnectSignal );
269 SignalConnectorType registerSignal3( typeRegistration, SIGNAL_KEY_INPUT_FOCUS_LOST, &DoConnectSignal );
270 SignalConnectorType registerSignal4( typeRegistration, SIGNAL_TAPPED, &DoConnectSignal );
271 SignalConnectorType registerSignal5( typeRegistration, SIGNAL_PANNED, &DoConnectSignal );
272 SignalConnectorType registerSignal6( typeRegistration, SIGNAL_PINCHED, &DoConnectSignal );
273 SignalConnectorType registerSignal7( typeRegistration, SIGNAL_LONG_PRESSED, &DoConnectSignal );
275 TypeAction registerAction( typeRegistration, ACTION_ACCESSIBILITY_ACTIVATED, &DoAction );
277 DALI_TYPE_REGISTRATION_END()
280 * @brief Iterate through given container and setOffScene any visual found
282 * @param[in] container Container of visuals
283 * @param[in] parent Parent actor to remove visuals from
285 void SetVisualsOffScene( const RegisteredVisualContainer& container, Actor parent )
287 for( auto iter = container.Begin(), end = container.End() ; iter!= end; iter++)
289 if( (*iter)->visual )
291 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::SetOffScene Setting visual(%d) off stage\n", (*iter)->index );
292 Toolkit::GetImplementation((*iter)->visual).SetOffScene( parent );
297 } // unnamed namespace
300 // Properties registered without macro to use specific member variables.
301 const PropertyRegistration Control::Impl::PROPERTY_1( typeRegistration, "styleName", Toolkit::Control::Property::STYLE_NAME, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
302 const PropertyRegistration Control::Impl::PROPERTY_4( typeRegistration, "keyInputFocus", Toolkit::Control::Property::KEY_INPUT_FOCUS, Property::BOOLEAN, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
303 const PropertyRegistration Control::Impl::PROPERTY_5( typeRegistration, "background", Toolkit::Control::Property::BACKGROUND, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
304 const PropertyRegistration Control::Impl::PROPERTY_6( typeRegistration, "margin", Toolkit::Control::Property::MARGIN, Property::EXTENTS, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
305 const PropertyRegistration Control::Impl::PROPERTY_7( typeRegistration, "padding", Toolkit::Control::Property::PADDING, Property::EXTENTS, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
306 const PropertyRegistration Control::Impl::PROPERTY_8( typeRegistration, "tooltip", Toolkit::DevelControl::Property::TOOLTIP, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
307 const PropertyRegistration Control::Impl::PROPERTY_9( typeRegistration, "state", Toolkit::DevelControl::Property::STATE, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
308 const PropertyRegistration Control::Impl::PROPERTY_10( typeRegistration, "subState", Toolkit::DevelControl::Property::SUB_STATE, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
309 const PropertyRegistration Control::Impl::PROPERTY_11( typeRegistration, "leftFocusableActorId", Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID, Property::INTEGER, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
310 const PropertyRegistration Control::Impl::PROPERTY_12( typeRegistration, "rightFocusableActorId", Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID,Property::INTEGER, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
311 const PropertyRegistration Control::Impl::PROPERTY_13( typeRegistration, "upFocusableActorId", Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID, Property::INTEGER, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
312 const PropertyRegistration Control::Impl::PROPERTY_14( typeRegistration, "downFocusableActorId", Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID, Property::INTEGER, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
313 const PropertyRegistration Control::Impl::PROPERTY_15( typeRegistration, "shadow", Toolkit::DevelControl::Property::SHADOW, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
315 Control::Impl::Impl( Control& controlImpl )
316 : mControlImpl( controlImpl ),
317 mState( Toolkit::DevelControl::NORMAL ),
319 mLeftFocusableActorId( -1 ),
320 mRightFocusableActorId( -1 ),
321 mUpFocusableActorId( -1 ),
322 mDownFocusableActorId( -1 ),
324 mBackgroundColor(Color::TRANSPARENT),
325 mStartingPinchScale(nullptr),
326 mMargin( 0, 0, 0, 0 ),
327 mPadding( 0, 0, 0, 0 ),
329 mKeyInputFocusGainedSignal(),
330 mKeyInputFocusLostSignal(),
331 mResourceReadySignal(),
332 mVisualEventSignal(),
333 mPinchGestureDetector(),
334 mPanGestureDetector(),
335 mTapGestureDetector(),
336 mLongPressGestureDetector(),
338 mInputMethodContext(),
339 mIdleCallback(nullptr),
341 mAutofillContainer(),
342 mFlags( Control::ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
343 mIsKeyboardNavigationSupported( false ),
344 mIsKeyboardFocusGroup( false ),
345 mIsEmittingResourceReadySignal(false),
346 mNeedToEmitResourceReady(false),
347 mIsAutofillEnabled( false )
351 Control::Impl::~Impl()
353 for( auto&& iter : mVisuals )
355 StopObservingVisual( iter->visual );
358 for( auto&& iter : mRemoveVisuals )
360 StopObservingVisual( iter->visual );
363 // All gesture detectors will be destroyed so no need to disconnect.
364 delete mStartingPinchScale;
366 if(mIdleCallback && Adaptor::IsAvailable())
368 // Removes the callback from the callback manager in case the control is destroyed before the callback is executed.
369 Adaptor::Get().RemoveIdle(mIdleCallback);
373 Control::Impl& Control::Impl::Get( Internal::Control& internalControl )
375 return *internalControl.mImpl;
378 const Control::Impl& Control::Impl::Get( const Internal::Control& internalControl )
380 return *internalControl.mImpl;
383 // Gesture Detection Methods
384 void Control::Impl::PinchDetected(Actor actor, const PinchGesture& pinch)
386 mControlImpl.OnPinch(pinch);
389 void Control::Impl::PanDetected(Actor actor, const PanGesture& pan)
391 mControlImpl.OnPan(pan);
394 void Control::Impl::TapDetected(Actor actor, const TapGesture& tap)
396 mControlImpl.OnTap(tap);
399 void Control::Impl::LongPressDetected(Actor actor, const LongPressGesture& longPress)
401 mControlImpl.OnLongPress(longPress);
404 void Control::Impl::RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual )
406 RegisterVisual( index, visual, VisualState::ENABLED, DepthIndexValue::NOT_SET );
409 void Control::Impl::RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, int depthIndex )
411 RegisterVisual( index, visual, VisualState::ENABLED, DepthIndexValue::SET, depthIndex );
414 void Control::Impl::RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, bool enabled )
416 RegisterVisual( index, visual, ( enabled ? VisualState::ENABLED : VisualState::DISABLED ), DepthIndexValue::NOT_SET );
419 void Control::Impl::RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, bool enabled, int depthIndex )
421 RegisterVisual( index, visual, ( enabled ? VisualState::ENABLED : VisualState::DISABLED ), DepthIndexValue::SET, depthIndex );
424 void Control::Impl::RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, VisualState::Type enabled, DepthIndexValue::Type depthIndexValueSet, int depthIndex )
426 DALI_LOG_INFO( gLogFilter, Debug::Concise, "RegisterVisual:%d \n", index );
428 bool visualReplaced ( false );
429 Actor self = mControlImpl.Self();
431 // Set the depth index, if not set by caller this will be either the current visual depth, max depth of all visuals
433 int requiredDepthIndex = visual.GetDepthIndex();
435 if( depthIndexValueSet == DepthIndexValue::SET )
437 requiredDepthIndex = depthIndex;
440 // Visual replacement, existing visual should only be removed from stage when replacement ready.
441 if( !mVisuals.Empty() )
443 RegisteredVisualContainer::Iterator registeredVisualsiter;
444 // Check if visual (index) is already registered, this is the current visual.
445 if( FindVisual( index, mVisuals, registeredVisualsiter ) )
447 Toolkit::Visual::Base& currentRegisteredVisual = (*registeredVisualsiter)->visual;
448 if( currentRegisteredVisual )
450 // Store current visual depth index as may need to set the replacement visual to same depth
451 const int currentDepthIndex = (*registeredVisualsiter)->visual.GetDepthIndex();
453 // No longer required to know if the replaced visual's resources are ready
454 StopObservingVisual( currentRegisteredVisual );
456 // If control staged and visual enabled then visuals will be swapped once ready
457 if( self.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) && enabled )
459 // Check if visual is currently in the process of being replaced ( is in removal container )
460 RegisteredVisualContainer::Iterator visualQueuedForRemoval;
461 if ( FindVisual( index, mRemoveVisuals, visualQueuedForRemoval ) )
463 // Visual with same index is already in removal container so current visual pending
464 // Only the the last requested visual will be displayed so remove current visual which is staged but not ready.
465 Toolkit::GetImplementation( currentRegisteredVisual ).SetOffScene( self );
466 mVisuals.Erase( registeredVisualsiter );
470 // current visual not already in removal container so add now.
471 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "RegisterVisual Move current registered visual to removal Queue: %d \n", index );
472 MoveVisual( registeredVisualsiter, mVisuals, mRemoveVisuals );
477 // Control not staged or visual disabled so can just erase from registered visuals and new visual will be added later.
478 mVisuals.Erase( registeredVisualsiter );
481 // If we've not set the depth-index value and the new visual does not have a depth index applied to it, then use the previously set depth-index for this index
482 if( ( depthIndexValueSet == DepthIndexValue::NOT_SET ) &&
483 ( visual.GetDepthIndex() == 0 ) )
485 requiredDepthIndex = currentDepthIndex;
489 visualReplaced = true;
493 // If not set, set the name of the visual to the same name as the control's property.
494 // ( If the control has been type registered )
495 if( visual.GetName().empty() )
497 // returns empty string if index is not found as long as index is not -1
498 std::string visualName = self.GetPropertyName( index );
499 if( !visualName.empty() )
501 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Setting visual name for property %d to %s\n",
502 index, visualName.c_str() );
503 visual.SetName( visualName );
507 if( !visualReplaced ) // New registration entry
509 // If we've not set the depth-index value, we have more than one visual and the visual does not have a depth index, then set it to be the highest
510 if( ( depthIndexValueSet == DepthIndexValue::NOT_SET ) &&
511 ( mVisuals.Size() > 0 ) &&
512 ( visual.GetDepthIndex() == 0 ) )
514 int maxDepthIndex = std::numeric_limits< int >::min();
516 RegisteredVisualContainer::ConstIterator iter;
517 const RegisteredVisualContainer::ConstIterator endIter = mVisuals.End();
518 for ( iter = mVisuals.Begin(); iter != endIter; iter++ )
520 const int visualDepthIndex = (*iter)->visual.GetDepthIndex();
521 if ( visualDepthIndex > maxDepthIndex )
523 maxDepthIndex = visualDepthIndex;
526 ++maxDepthIndex; // Add one to the current maximum depth index so that our added visual appears on top
527 requiredDepthIndex = std::max( 0, maxDepthIndex ); // Start at zero if maxDepth index belongs to a background
533 // Set determined depth index
534 visual.SetDepthIndex( requiredDepthIndex );
536 // Monitor when the visual resources are ready
537 StartObservingVisual( visual );
539 DALI_LOG_INFO( gLogFilter, Debug::Concise, "New Visual registration index[%d] depth[%d]\n", index, requiredDepthIndex );
540 RegisteredVisual* newRegisteredVisual = new RegisteredVisual( index, visual,
541 ( enabled == VisualState::ENABLED ? true : false ),
542 ( visualReplaced && enabled ) ) ;
543 mVisuals.PushBack( newRegisteredVisual );
545 Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
546 // Put on stage if enabled and the control is already on the stage
547 if( ( enabled == VisualState::ENABLED ) && self.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) )
549 visualImpl.SetOnScene( self );
551 else if( visualImpl.IsResourceReady() ) // When not being staged, check if visual already 'ResourceReady' before it was Registered. ( Resource may have been loaded already )
553 ResourceReady( visualImpl );
558 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::RegisterVisual() Registered %s(%d), enabled:%s\n", visual.GetName().c_str(), index, enabled?"true":"false" );
561 void Control::Impl::UnregisterVisual( Property::Index index )
563 RegisteredVisualContainer::Iterator iter;
564 if ( FindVisual( index, mVisuals, iter ) )
566 // stop observing visual
567 StopObservingVisual( (*iter)->visual );
569 Actor self( mControlImpl.Self() );
570 Toolkit::GetImplementation((*iter)->visual).SetOffScene( self );
571 (*iter)->visual.Reset();
572 mVisuals.Erase( iter );
575 if( FindVisual( index, mRemoveVisuals, iter ) )
577 Actor self( mControlImpl.Self() );
578 Toolkit::GetImplementation( (*iter)->visual ).SetOffScene( self );
579 (*iter)->pending = false;
580 (*iter)->visual.Reset();
581 mRemoveVisuals.Erase( iter );
585 Toolkit::Visual::Base Control::Impl::GetVisual( Property::Index index ) const
587 RegisteredVisualContainer::Iterator iter;
588 if ( FindVisual( index, mVisuals, iter ) )
590 return (*iter)->visual;
593 return Toolkit::Visual::Base();
596 void Control::Impl::EnableVisual( Property::Index index, bool enable )
598 DALI_LOG_INFO( gLogFilter, Debug::General, "Control::EnableVisual(%d, %s)\n", index, enable?"T":"F");
600 RegisteredVisualContainer::Iterator iter;
601 if ( FindVisual( index, mVisuals, iter ) )
603 if ( (*iter)->enabled == enable )
605 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::EnableVisual Visual %s(%d) already %s\n", (*iter)->visual.GetName().c_str(), index, enable?"enabled":"disabled");
609 (*iter)->enabled = enable;
610 Actor parentActor = mControlImpl.Self();
611 if ( mControlImpl.Self().GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) ) // If control not on Scene then Visual will be added when SceneConnection is called.
615 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::EnableVisual Setting %s(%d) on stage \n", (*iter)->visual.GetName().c_str(), index );
616 Toolkit::GetImplementation((*iter)->visual).SetOnScene( parentActor );
620 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::EnableVisual Setting %s(%d) off stage \n", (*iter)->visual.GetName().c_str(), index );
621 Toolkit::GetImplementation((*iter)->visual).SetOffScene( parentActor ); // No need to call if control not staged.
627 DALI_LOG_WARNING( "Control::EnableVisual(%d, %s) FAILED - NO SUCH VISUAL\n", index, enable?"T":"F" );
631 bool Control::Impl::IsVisualEnabled( Property::Index index ) const
633 RegisteredVisualContainer::Iterator iter;
634 if ( FindVisual( index, mVisuals, iter ) )
636 return (*iter)->enabled;
641 void Control::Impl::StopObservingVisual( Toolkit::Visual::Base& visual )
643 Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
645 // Stop observing the visual
646 visualImpl.RemoveEventObserver( *this );
649 void Control::Impl::StartObservingVisual( Toolkit::Visual::Base& visual)
651 Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
653 // start observing the visual for events
654 visualImpl.AddEventObserver( *this );
657 // Called by a Visual when it's resource is ready
658 void Control::Impl::ResourceReady( Visual::Base& object)
660 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::Impl::ResourceReady() replacements pending[%d]\n", mRemoveVisuals.Count() );
662 Actor self = mControlImpl.Self();
664 // A resource is ready, find resource in the registered visuals container and get its index
665 for( auto registeredIter = mVisuals.Begin(), end = mVisuals.End(); registeredIter != end; ++registeredIter )
667 Internal::Visual::Base& registeredVisualImpl = Toolkit::GetImplementation( (*registeredIter)->visual );
669 if( &object == ®isteredVisualImpl )
671 RegisteredVisualContainer::Iterator visualToRemoveIter;
672 // Find visual with the same index in the removal container
673 // Set if off stage as it's replacement is now ready.
674 // Remove if from removal list as now removed from stage.
675 // Set Pending flag on the ready visual to false as now ready.
676 if( FindVisual( (*registeredIter)->index, mRemoveVisuals, visualToRemoveIter ) )
678 (*registeredIter)->pending = false;
679 Toolkit::GetImplementation( (*visualToRemoveIter)->visual ).SetOffScene( self );
680 mRemoveVisuals.Erase( visualToRemoveIter );
686 // A visual is ready so control may need relayouting if staged
687 if ( self.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) )
689 mControlImpl.RelayoutRequest();
692 // Emit signal if all enabled visuals registered by the control are ready.
693 if( IsResourceReady() )
696 mNeedToEmitResourceReady = false;
698 EmitResourceReadySignal();
702 void Control::Impl::NotifyVisualEvent( Visual::Base& object, Property::Index signalId )
704 for( auto registeredIter = mVisuals.Begin(), end = mVisuals.End(); registeredIter != end; ++registeredIter )
706 Internal::Visual::Base& registeredVisualImpl = Toolkit::GetImplementation( (*registeredIter)->visual );
707 if( &object == ®isteredVisualImpl )
709 Dali::Toolkit::Control handle( mControlImpl.GetOwner() );
710 mVisualEventSignal.Emit( handle, (*registeredIter)->index, signalId );
716 bool Control::Impl::IsResourceReady() const
718 // Iterate through and check all the enabled visuals are ready
719 for( auto visualIter = mVisuals.Begin();
720 visualIter != mVisuals.End(); ++visualIter )
722 const Toolkit::Visual::Base visual = (*visualIter)->visual;
723 const Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
725 // one of the enabled visuals is not ready
726 if( !visualImpl.IsResourceReady() && (*visualIter)->enabled )
734 Toolkit::Visual::ResourceStatus Control::Impl::GetVisualResourceStatus( Property::Index index ) const
736 RegisteredVisualContainer::Iterator iter;
737 if ( FindVisual( index, mVisuals, iter ) )
739 const Toolkit::Visual::Base visual = (*iter)->visual;
740 const Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
741 return visualImpl.GetResourceStatus( );
744 return Toolkit::Visual::ResourceStatus::PREPARING;
749 void Control::Impl::AddTransitions( Dali::Animation& animation,
750 const Toolkit::TransitionData& handle,
751 bool createAnimation )
753 // Setup a Transition from TransitionData.
754 const Internal::TransitionData& transitionData = Toolkit::GetImplementation( handle );
755 TransitionData::Iterator end = transitionData.End();
756 for( TransitionData::Iterator iter = transitionData.Begin() ;
757 iter != end; ++iter )
759 TransitionData::Animator* animator = (*iter);
761 Toolkit::Visual::Base visual = GetVisualByName( mVisuals, animator->objectName );
765 #if defined(DEBUG_ENABLED)
766 Dali::TypeInfo typeInfo;
767 ControlWrapper* controlWrapperImpl = dynamic_cast<ControlWrapper*>(&mControlImpl);
768 if( controlWrapperImpl )
770 typeInfo = controlWrapperImpl->GetTypeInfo();
773 DALI_LOG_INFO( gLogFilter, Debug::Concise, "CreateTransition: Found %s visual for %s\n",
774 visual.GetName().c_str(), typeInfo?typeInfo.GetName().c_str():"Unknown" );
776 Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
777 visualImpl.AnimateProperty( animation, *animator );
781 DALI_LOG_INFO( gLogFilter, Debug::Concise, "CreateTransition: Could not find visual. Trying actors");
782 // Otherwise, try any actor children of control (Including the control)
783 Actor child = mControlImpl.Self().FindChildByName( animator->objectName );
786 Property::Index propertyIndex = child.GetPropertyIndex( animator->propertyKey );
787 if( propertyIndex != Property::INVALID_INDEX )
789 if( animator->animate == false )
791 if( animator->targetValue.GetType() != Property::NONE )
793 child.SetProperty( propertyIndex, animator->targetValue );
796 else // animate the property
798 if( animator->initialValue.GetType() != Property::NONE )
800 child.SetProperty( propertyIndex, animator->initialValue );
803 if( createAnimation && !animation )
805 animation = Dali::Animation::New( 0.1f );
808 animation.AnimateTo( Property( child, propertyIndex ),
809 animator->targetValue,
810 animator->alphaFunction,
811 TimePeriod( animator->timePeriodDelay,
812 animator->timePeriodDuration ) );
820 Dali::Animation Control::Impl::CreateTransition( const Toolkit::TransitionData& transitionData )
822 Dali::Animation transition;
824 if( transitionData.Count() > 0 )
826 AddTransitions( transition, transitionData, true );
833 void Control::Impl::DoAction( Dali::Property::Index visualIndex, Dali::Property::Index actionId, const Dali::Property::Value attributes )
835 RegisteredVisualContainer::Iterator iter;
836 if ( FindVisual( visualIndex, mVisuals, iter ) )
838 Toolkit::GetImplementation((*iter)->visual).DoAction( actionId, attributes );
842 void Control::Impl::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
844 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
848 Control& controlImpl( GetImplementation( control ) );
852 case Toolkit::Control::Property::STYLE_NAME:
854 controlImpl.SetStyleName( value.Get< std::string >() );
858 case Toolkit::DevelControl::Property::STATE:
860 bool withTransitions=true;
861 const Property::Value* valuePtr=&value;
862 const Property::Map* map = value.GetMap();
865 Property::Value* value2 = map->Find("withTransitions");
868 withTransitions = value2->Get<bool>();
871 valuePtr = map->Find("state");
876 Toolkit::DevelControl::State state( controlImpl.mImpl->mState );
877 if( Scripting::GetEnumerationProperty< Toolkit::DevelControl::State >( *valuePtr, ControlStateTable, ControlStateTableCount, state ) )
879 controlImpl.mImpl->SetState( state, withTransitions );
885 case Toolkit::DevelControl::Property::SUB_STATE:
887 std::string subState;
888 if( value.Get( subState ) )
890 controlImpl.mImpl->SetSubState( subState );
895 case Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID:
898 if( value.Get( focusId ) )
900 controlImpl.mImpl->mLeftFocusableActorId = focusId;
905 case Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID:
908 if( value.Get( focusId ) )
910 controlImpl.mImpl->mRightFocusableActorId = focusId;
915 case Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID:
918 if( value.Get( focusId ) )
920 controlImpl.mImpl->mUpFocusableActorId = focusId;
925 case Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID:
928 if( value.Get( focusId ) )
930 controlImpl.mImpl->mDownFocusableActorId = focusId;
935 case Toolkit::Control::Property::KEY_INPUT_FOCUS:
937 if ( value.Get< bool >() )
939 controlImpl.SetKeyInputFocus();
943 controlImpl.ClearKeyInputFocus();
948 case Toolkit::Control::Property::BACKGROUND:
952 const Property::Map* map = value.GetMap();
953 if( map && !map->Empty() )
955 controlImpl.SetBackground( *map );
957 else if( value.Get( url ) )
959 // don't know the size to load
960 Toolkit::Visual::Base visual = Toolkit::VisualFactory::Get().CreateVisual( url, ImageDimensions() );
963 controlImpl.mImpl->RegisterVisual( Toolkit::Control::Property::BACKGROUND, visual, DepthIndex::BACKGROUND );
966 else if( value.Get( color ) )
968 controlImpl.SetBackgroundColor(color);
972 // The background is an empty property map, so we should clear the background
973 controlImpl.ClearBackground();
978 case Toolkit::Control::Property::MARGIN:
981 if( value.Get( margin ) )
983 controlImpl.mImpl->SetMargin( margin );
988 case Toolkit::Control::Property::PADDING:
991 if( value.Get( padding ) )
993 controlImpl.mImpl->SetPadding( padding );
998 case Toolkit::DevelControl::Property::TOOLTIP:
1000 TooltipPtr& tooltipPtr = controlImpl.mImpl->mTooltip;
1003 tooltipPtr = Tooltip::New( control );
1005 tooltipPtr->SetProperties( value );
1009 case Toolkit::DevelControl::Property::SHADOW:
1011 const Property::Map* map = value.GetMap();
1012 if( map && !map->Empty() )
1014 controlImpl.mImpl->SetShadow( *map );
1018 // The shadow is an empty property map, so we should clear the shadow
1019 controlImpl.mImpl->ClearShadow();
1028 Property::Value Control::Impl::GetProperty( BaseObject* object, Property::Index index )
1030 Property::Value value;
1032 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
1036 Control& controlImpl( GetImplementation( control ) );
1040 case Toolkit::Control::Property::STYLE_NAME:
1042 value = controlImpl.GetStyleName();
1046 case Toolkit::DevelControl::Property::STATE:
1048 value = controlImpl.mImpl->mState;
1052 case Toolkit::DevelControl::Property::SUB_STATE:
1054 value = controlImpl.mImpl->mSubStateName;
1058 case Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID:
1060 value = controlImpl.mImpl->mLeftFocusableActorId;
1064 case Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID:
1066 value = controlImpl.mImpl->mRightFocusableActorId;
1070 case Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID:
1072 value = controlImpl.mImpl->mUpFocusableActorId;
1076 case Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID:
1078 value = controlImpl.mImpl->mDownFocusableActorId;
1082 case Toolkit::Control::Property::KEY_INPUT_FOCUS:
1084 value = controlImpl.HasKeyInputFocus();
1088 case Toolkit::Control::Property::BACKGROUND:
1091 Toolkit::Visual::Base visual = controlImpl.mImpl->GetVisual( Toolkit::Control::Property::BACKGROUND );
1094 visual.CreatePropertyMap( map );
1101 case Toolkit::Control::Property::MARGIN:
1103 value = controlImpl.mImpl->GetMargin();
1107 case Toolkit::Control::Property::PADDING:
1109 value = controlImpl.mImpl->GetPadding();
1113 case Toolkit::DevelControl::Property::TOOLTIP:
1116 if( controlImpl.mImpl->mTooltip )
1118 controlImpl.mImpl->mTooltip->CreatePropertyMap( map );
1124 case Toolkit::DevelControl::Property::SHADOW:
1127 Toolkit::Visual::Base visual = controlImpl.mImpl->GetVisual( Toolkit::DevelControl::Property::SHADOW );
1130 visual.CreatePropertyMap( map );
1143 void Control::Impl::CopyInstancedProperties( RegisteredVisualContainer& visuals, Dictionary<Property::Map>& instancedProperties )
1145 for(RegisteredVisualContainer::Iterator iter = visuals.Begin(); iter!= visuals.End(); iter++)
1147 if( (*iter)->visual )
1149 Property::Map instanceMap;
1150 Toolkit::GetImplementation((*iter)->visual).CreateInstancePropertyMap(instanceMap);
1151 instancedProperties.Add( (*iter)->visual.GetName(), instanceMap );
1157 void Control::Impl::RemoveVisual( RegisteredVisualContainer& visuals, const std::string& visualName )
1159 Actor self( mControlImpl.Self() );
1161 for ( RegisteredVisualContainer::Iterator visualIter = visuals.Begin();
1162 visualIter != visuals.End(); ++visualIter )
1164 Toolkit::Visual::Base visual = (*visualIter)->visual;
1165 if( visual && visual.GetName() == visualName )
1167 Toolkit::GetImplementation(visual).SetOffScene( self );
1168 (*visualIter)->visual.Reset();
1169 visuals.Erase( visualIter );
1175 void Control::Impl::RemoveVisuals( RegisteredVisualContainer& visuals, DictionaryKeys& removeVisuals )
1177 Actor self( mControlImpl.Self() );
1178 for( DictionaryKeys::iterator iter = removeVisuals.begin(); iter != removeVisuals.end(); ++iter )
1180 const std::string visualName = *iter;
1181 RemoveVisual( visuals, visualName );
1185 void Control::Impl::RecreateChangedVisuals( Dictionary<Property::Map>& stateVisualsToChange,
1186 Dictionary<Property::Map>& instancedProperties )
1188 Dali::CustomActor handle( mControlImpl.GetOwner() );
1189 for( Dictionary<Property::Map>::iterator iter = stateVisualsToChange.Begin();
1190 iter != stateVisualsToChange.End(); ++iter )
1192 const std::string& visualName = (*iter).key;
1193 const Property::Map& toMap = (*iter).entry;
1195 // is it a candidate for re-creation?
1196 bool recreate = false;
1198 Toolkit::Visual::Base visual = GetVisualByName( mVisuals, visualName );
1201 Property::Map fromMap;
1202 visual.CreatePropertyMap( fromMap );
1204 Toolkit::Visual::Type fromType = GetVisualTypeFromMap( fromMap );
1205 Toolkit::Visual::Type toType = GetVisualTypeFromMap( toMap );
1207 if( fromType != toType )
1213 if( fromType == Toolkit::Visual::IMAGE || fromType == Toolkit::Visual::N_PATCH
1214 || fromType == Toolkit::Visual::SVG || fromType == Toolkit::Visual::ANIMATED_IMAGE )
1216 Property::Value* fromUrl = fromMap.Find( Toolkit::ImageVisual::Property::URL, IMAGE_URL_NAME );
1217 Property::Value* toUrl = toMap.Find( Toolkit::ImageVisual::Property::URL, IMAGE_URL_NAME );
1219 if( fromUrl && toUrl )
1221 std::string fromUrlString;
1222 std::string toUrlString;
1223 fromUrl->Get(fromUrlString);
1224 toUrl->Get(toUrlString);
1226 if( fromUrlString != toUrlString )
1234 const Property::Map* instancedMap = instancedProperties.FindConst( visualName );
1235 if( recreate || instancedMap )
1237 RemoveVisual( mVisuals, visualName );
1238 Style::ApplyVisual( handle, visualName, toMap, instancedMap );
1242 // @todo check to see if we can apply toMap without recreating the visual
1243 // e.g. by setting only animatable properties
1244 // For now, recreate all visuals, but merge in instance data.
1245 RemoveVisual( mVisuals, visualName );
1246 Style::ApplyVisual( handle, visualName, toMap, instancedMap );
1252 void Control::Impl::ReplaceStateVisualsAndProperties( const StylePtr oldState, const StylePtr newState, const std::string& subState )
1254 // Collect all old visual names
1255 DictionaryKeys stateVisualsToRemove;
1258 oldState->visuals.GetKeys( stateVisualsToRemove );
1259 if( ! subState.empty() )
1261 const StylePtr* oldSubState = oldState->subStates.FindConst(subState);
1264 DictionaryKeys subStateVisualsToRemove;
1265 (*oldSubState)->visuals.GetKeys( subStateVisualsToRemove );
1266 Merge( stateVisualsToRemove, subStateVisualsToRemove );
1271 // Collect all new visual properties
1272 Dictionary<Property::Map> stateVisualsToAdd;
1275 stateVisualsToAdd = newState->visuals;
1276 if( ! subState.empty() )
1278 const StylePtr* newSubState = newState->subStates.FindConst(subState);
1281 stateVisualsToAdd.Merge( (*newSubState)->visuals );
1286 // If a name is in both add/remove, move it to change list.
1287 Dictionary<Property::Map> stateVisualsToChange;
1288 FindChangableVisuals( stateVisualsToAdd, stateVisualsToChange, stateVisualsToRemove);
1290 // Copy instanced properties (e.g. text label) of current visuals
1291 Dictionary<Property::Map> instancedProperties;
1292 CopyInstancedProperties( mVisuals, instancedProperties );
1294 // For each visual in remove list, remove from mVisuals
1295 RemoveVisuals( mVisuals, stateVisualsToRemove );
1297 // For each visual in add list, create and add to mVisuals
1298 Dali::CustomActor handle( mControlImpl.GetOwner() );
1299 Style::ApplyVisuals( handle, stateVisualsToAdd, instancedProperties );
1301 // For each visual in change list, if it requires a new visual,
1302 // remove old visual, create and add to mVisuals
1303 RecreateChangedVisuals( stateVisualsToChange, instancedProperties );
1306 void Control::Impl::SetState( DevelControl::State newState, bool withTransitions )
1308 DevelControl::State oldState = mState;
1309 Dali::CustomActor handle( mControlImpl.GetOwner() );
1310 DALI_LOG_INFO(gLogFilter, Debug::Concise, "Control::Impl::SetState: %s\n",
1311 (mState == DevelControl::NORMAL ? "NORMAL" :(
1312 mState == DevelControl::FOCUSED ?"FOCUSED" : (
1313 mState == DevelControl::DISABLED?"DISABLED":"NONE" ))));
1315 if( mState != newState )
1317 // If mState was Disabled, and new state is Focused, should probably
1318 // store that fact, e.g. in another property that FocusManager can access.
1321 // Trigger state change and transitions
1322 // Apply new style, if stylemanager is available
1323 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
1326 const StylePtr stylePtr = GetImpl( styleManager ).GetRecordedStyle( Toolkit::Control( mControlImpl.GetOwner() ) );
1330 std::string oldStateName = Scripting::GetEnumerationName< Toolkit::DevelControl::State >( oldState, ControlStateTable, ControlStateTableCount );
1331 std::string newStateName = Scripting::GetEnumerationName< Toolkit::DevelControl::State >( newState, ControlStateTable, ControlStateTableCount );
1333 const StylePtr* newStateStyle = stylePtr->subStates.Find( newStateName );
1334 const StylePtr* oldStateStyle = stylePtr->subStates.Find( oldStateName );
1335 if( oldStateStyle && newStateStyle )
1337 // Only change if both state styles exist
1338 ReplaceStateVisualsAndProperties( *oldStateStyle, *newStateStyle, mSubStateName );
1345 void Control::Impl::SetSubState( const std::string& subStateName, bool withTransitions )
1347 if( mSubStateName != subStateName )
1349 // Get existing sub-state visuals, and unregister them
1350 Dali::CustomActor handle( mControlImpl.GetOwner() );
1352 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
1355 const StylePtr stylePtr = GetImpl( styleManager ).GetRecordedStyle( Toolkit::Control( mControlImpl.GetOwner() ) );
1359 std::string stateName = Scripting::GetEnumerationName< Toolkit::DevelControl::State >( mState, ControlStateTable, ControlStateTableCount );
1361 const StylePtr* state = stylePtr->subStates.Find( stateName );
1364 StylePtr stateStyle(*state);
1366 const StylePtr* newStateStyle = stateStyle->subStates.Find( subStateName );
1367 const StylePtr* oldStateStyle = stateStyle->subStates.Find( mSubStateName );
1368 if( oldStateStyle && newStateStyle )
1371 ReplaceStateVisualsAndProperties( *oldStateStyle, *newStateStyle, empty );
1377 mSubStateName = subStateName;
1381 void Control::Impl::OnSceneDisconnection()
1383 Actor self = mControlImpl.Self();
1385 // Any visuals set for replacement but not yet ready should still be registered.
1386 // Reason: If a request was made to register a new visual but the control removed from scene before visual was ready
1387 // then when this control appears back on stage it should use that new visual.
1389 // Iterate through all registered visuals and set off scene
1390 SetVisualsOffScene( mVisuals, self );
1392 // Visuals pending replacement can now be taken out of the removal list and set off scene
1393 // Iterate through all replacement visuals and add to a move queue then set off scene
1394 for( auto removalIter = mRemoveVisuals.Begin(), end = mRemoveVisuals.End(); removalIter != end; removalIter++ )
1396 Toolkit::GetImplementation((*removalIter)->visual).SetOffScene( self );
1399 for( auto replacedIter = mVisuals.Begin(), end = mVisuals.End(); replacedIter != end; replacedIter++ )
1401 (*replacedIter)->pending = false;
1404 mRemoveVisuals.Clear();
1407 void Control::Impl::SetMargin( Extents margin )
1409 mControlImpl.mImpl->mMargin = margin;
1411 // Trigger a size negotiation request that may be needed when setting a margin.
1412 mControlImpl.RelayoutRequest();
1415 Extents Control::Impl::GetMargin() const
1417 return mControlImpl.mImpl->mMargin;
1420 void Control::Impl::SetPadding( Extents padding )
1422 mControlImpl.mImpl->mPadding = padding;
1424 // Trigger a size negotiation request that may be needed when setting a padding.
1425 mControlImpl.RelayoutRequest();
1428 Extents Control::Impl::GetPadding() const
1430 return mControlImpl.mImpl->mPadding;
1433 void Control::Impl::SetInputMethodContext( InputMethodContext& inputMethodContext )
1435 mInputMethodContext = inputMethodContext;
1438 bool Control::Impl::FilterKeyEvent( const KeyEvent& event )
1440 bool consumed ( false );
1442 if ( mInputMethodContext )
1444 consumed = mInputMethodContext.FilterEventKey( event );
1449 DevelControl::VisualEventSignalType& Control::Impl::VisualEventSignal()
1451 return mVisualEventSignal;
1454 void Control::Impl::SetShadow( const Property::Map& map )
1456 Toolkit::Visual::Base visual = Toolkit::VisualFactory::Get().CreateVisual( map );
1457 visual.SetName("shadow");
1461 mControlImpl.mImpl->RegisterVisual( Toolkit::DevelControl::Property::SHADOW, visual, DepthIndex::BACKGROUND_EFFECT );
1463 mControlImpl.RelayoutRequest();
1467 void Control::Impl::ClearShadow()
1469 mControlImpl.mImpl->UnregisterVisual( Toolkit::DevelControl::Property::SHADOW );
1471 // Trigger a size negotiation request that may be needed when unregistering a visual.
1472 mControlImpl.RelayoutRequest();
1475 void Control::Impl::EmitResourceReadySignal()
1477 if(!mIsEmittingResourceReadySignal)
1479 // Guard against calls to emit the signal during the callback
1480 mIsEmittingResourceReadySignal = true;
1482 // If the signal handler changes visual, it may become ready during this call & therefore this method will
1483 // get called again recursively. If so, mNeedToEmitResourceReady is set below, and we act on it after that secondary
1484 // invocation has completed by notifying in an Idle callback to prevent further recursion.
1485 Dali::Toolkit::Control handle(mControlImpl.GetOwner());
1486 mResourceReadySignal.Emit(handle);
1488 if(mNeedToEmitResourceReady)
1490 // Add idler to emit the signal again
1493 // The callback manager takes the ownership of the callback object.
1494 mIdleCallback = MakeCallback( this, &Control::Impl::OnIdleCallback);
1495 Adaptor::Get().AddIdle(mIdleCallback, false);
1499 mIsEmittingResourceReadySignal = false;
1503 mNeedToEmitResourceReady = true;
1507 void Control::Impl::OnIdleCallback()
1509 if(mNeedToEmitResourceReady)
1512 mNeedToEmitResourceReady = false;
1514 // A visual is ready so control may need relayouting if staged
1515 if(mControlImpl.Self().GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE))
1517 mControlImpl.RelayoutRequest();
1520 EmitResourceReadySignal();
1523 // Set the pointer to null as the callback manager deletes the callback after execute it.
1524 mIdleCallback = nullptr;
1527 void Control::Impl::SetAutofillEnabled( bool autofillEnabled )
1529 mIsAutofillEnabled = autofillEnabled;
1532 bool Control::Impl::IsAutofillEnabled()
1534 return mIsAutofillEnabled;
1537 void Control::Impl::SetAutofillItemHandle( Dali::AutofillItem item )
1539 mAutofillItem = item;
1542 Dali::AutofillItem Control::Impl::GetAutofillItemHandle()
1544 return mAutofillItem;
1547 void Control::Impl::SetAutofillContainer( Toolkit::AutofillContainer container )
1549 mAutofillContainer = container;
1552 Toolkit::AutofillContainer Control::Impl::GetAutofillContainer()
1554 return mAutofillContainer;
1557 } // namespace Internal
1559 } // namespace Toolkit