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 "control-data-impl.h"
22 #include <dali/public-api/common/dali-common.h>
23 #include <dali/integration-api/debug.h>
24 #include <dali/devel-api/scripting/enum-helper.h>
25 #include <dali/devel-api/scripting/scripting.h>
26 #include <dali/integration-api/debug.h>
27 #include <dali/public-api/object/type-registry-helper.h>
31 #include <dali-toolkit/internal/visuals/visual-base-impl.h>
32 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
33 #include <dali-toolkit/internal/styling/style-manager-impl.h>
34 #include <dali-toolkit/public-api/visuals/image-visual-properties.h>
35 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
36 #include <dali-toolkit/internal/visuals/visual-string-constants.h>
37 #include <dali-toolkit/devel-api/controls/control-devel.h>
48 extern const Dali::Scripting::StringEnum ControlStateTable[];
49 extern const unsigned int ControlStateTableCount;
52 // Not static or anonymous - shared with other translation units
53 const Scripting::StringEnum ControlStateTable[] = {
54 { "NORMAL", Toolkit::DevelControl::NORMAL },
55 { "FOCUSED", Toolkit::DevelControl::FOCUSED },
56 { "DISABLED", Toolkit::DevelControl::DISABLED },
58 const unsigned int ControlStateTableCount = sizeof( ControlStateTable ) / sizeof( ControlStateTable[0] );
65 #if defined(DEBUG_ENABLED)
66 Debug::Filter* gLogFilter = Debug::Filter::New( Debug::NoLogging, false, "LOG_CONTROL_VISUALS");
71 void Remove( Dictionary<T>& keyValues, const std::string& name )
73 keyValues.Remove(name);
76 void Remove( DictionaryKeys& keys, const std::string& name )
78 DictionaryKeys::iterator iter = std::find( keys.begin(), keys.end(), name );
79 if( iter != keys.end())
85 Toolkit::DevelVisual::Type GetVisualTypeFromMap( const Property::Map& map )
87 Property::Value* typeValue = map.Find( Toolkit::DevelVisual::Property::TYPE, VISUAL_TYPE );
88 Toolkit::DevelVisual::Type type = Toolkit::DevelVisual::IMAGE;
91 Scripting::GetEnumerationProperty( *typeValue, VISUAL_TYPE_TABLE, VISUAL_TYPE_TABLE_COUNT, type );
96 void FindChangableVisuals( Dictionary<Property::Map>& stateVisualsToAdd,
97 Dictionary<Property::Map>& stateVisualsToChange,
98 DictionaryKeys& stateVisualsToRemove)
100 DictionaryKeys copyOfStateVisualsToRemove = stateVisualsToRemove;
102 for( DictionaryKeys::iterator iter = copyOfStateVisualsToRemove.begin();
103 iter != copyOfStateVisualsToRemove.end(); ++iter )
105 const std::string& visualName = (*iter);
106 Property::Map* toMap = stateVisualsToAdd.Find( visualName );
109 stateVisualsToChange.Add( visualName, *toMap );
110 stateVisualsToAdd.Remove( visualName );
111 Remove( stateVisualsToRemove, visualName );
117 * Performs actions as requested using the action name.
118 * @param[in] object The object on which to perform the action.
119 * @param[in] actionName The action to perform.
120 * @param[in] attributes The attributes with which to perfrom this action.
121 * @return true if action has been accepted by this control
123 const char* ACTION_ACCESSIBILITY_ACTIVATED = "accessibilityActivated";
124 static bool DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes )
128 if( object && ( 0 == strcmp( actionName.c_str(), ACTION_ACCESSIBILITY_ACTIVATED ) ) )
130 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
133 // if cast succeeds there is an implementation so no need to check
134 ret = Internal::GetImplementation( control ).OnAccessibilityActivated();
142 * Connects a callback function with the object's signals.
143 * @param[in] object The object providing the signal.
144 * @param[in] tracker Used to disconnect the signal.
145 * @param[in] signalName The signal to connect to.
146 * @param[in] functor A newly allocated FunctorDelegate.
147 * @return True if the signal was connected.
148 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
150 const char* SIGNAL_KEY_EVENT = "keyEvent";
151 const char* SIGNAL_KEY_INPUT_FOCUS_GAINED = "keyInputFocusGained";
152 const char* SIGNAL_KEY_INPUT_FOCUS_LOST = "keyInputFocusLost";
153 const char* SIGNAL_TAPPED = "tapped";
154 const char* SIGNAL_PANNED = "panned";
155 const char* SIGNAL_PINCHED = "pinched";
156 const char* SIGNAL_LONG_PRESSED = "longPressed";
157 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
159 Dali::BaseHandle handle( object );
161 bool connected( false );
162 Toolkit::Control control = Toolkit::Control::DownCast( handle );
165 Internal::Control& controlImpl( Internal::GetImplementation( control ) );
168 if ( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_EVENT ) )
170 controlImpl.KeyEventSignal().Connect( tracker, functor );
172 else if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_INPUT_FOCUS_GAINED ) )
174 controlImpl.KeyInputFocusGainedSignal().Connect( tracker, functor );
176 else if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_INPUT_FOCUS_LOST ) )
178 controlImpl.KeyInputFocusLostSignal().Connect( tracker, functor );
180 else if( 0 == strcmp( signalName.c_str(), SIGNAL_TAPPED ) )
182 controlImpl.EnableGestureDetection( Gesture::Tap );
183 controlImpl.GetTapGestureDetector().DetectedSignal().Connect( tracker, functor );
185 else if( 0 == strcmp( signalName.c_str(), SIGNAL_PANNED ) )
187 controlImpl.EnableGestureDetection( Gesture::Pan );
188 controlImpl.GetPanGestureDetector().DetectedSignal().Connect( tracker, functor );
190 else if( 0 == strcmp( signalName.c_str(), SIGNAL_PINCHED ) )
192 controlImpl.EnableGestureDetection( Gesture::Pinch );
193 controlImpl.GetPinchGestureDetector().DetectedSignal().Connect( tracker, functor );
195 else if( 0 == strcmp( signalName.c_str(), SIGNAL_LONG_PRESSED ) )
197 controlImpl.EnableGestureDetection( Gesture::LongPress );
198 controlImpl.GetLongPressGestureDetector().DetectedSignal().Connect( tracker, functor );
205 * Creates control through type registry
209 return Internal::Control::New();
211 // Setup signals and actions using the type-registry.
212 DALI_TYPE_REGISTRATION_BEGIN( Control, CustomActor, Create );
214 // Note: Properties are registered separately below.
216 SignalConnectorType registerSignal1( typeRegistration, SIGNAL_KEY_EVENT, &DoConnectSignal );
217 SignalConnectorType registerSignal2( typeRegistration, SIGNAL_KEY_INPUT_FOCUS_GAINED, &DoConnectSignal );
218 SignalConnectorType registerSignal3( typeRegistration, SIGNAL_KEY_INPUT_FOCUS_LOST, &DoConnectSignal );
219 SignalConnectorType registerSignal4( typeRegistration, SIGNAL_TAPPED, &DoConnectSignal );
220 SignalConnectorType registerSignal5( typeRegistration, SIGNAL_PANNED, &DoConnectSignal );
221 SignalConnectorType registerSignal6( typeRegistration, SIGNAL_PINCHED, &DoConnectSignal );
222 SignalConnectorType registerSignal7( typeRegistration, SIGNAL_LONG_PRESSED, &DoConnectSignal );
224 TypeAction registerAction( typeRegistration, ACTION_ACCESSIBILITY_ACTIVATED, &DoAction );
226 DALI_TYPE_REGISTRATION_END()
230 } // unnamed namespace
233 // Properties registered without macro to use specific member variables.
234 const PropertyRegistration Control::Impl::PROPERTY_1( typeRegistration, "styleName", Toolkit::Control::Property::STYLE_NAME, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
235 const PropertyRegistration Control::Impl::PROPERTY_2( typeRegistration, "backgroundColor", Toolkit::Control::Property::BACKGROUND_COLOR, Property::VECTOR4, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
236 const PropertyRegistration Control::Impl::PROPERTY_3( typeRegistration, "backgroundImage", Toolkit::Control::Property::BACKGROUND_IMAGE, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
237 const PropertyRegistration Control::Impl::PROPERTY_4( typeRegistration, "keyInputFocus", Toolkit::Control::Property::KEY_INPUT_FOCUS, Property::BOOLEAN, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
238 const PropertyRegistration Control::Impl::PROPERTY_5( typeRegistration, "background", Toolkit::Control::Property::BACKGROUND, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
239 const PropertyRegistration Control::Impl::PROPERTY_6( typeRegistration, "tooltip", Toolkit::DevelControl::Property::TOOLTIP, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
240 const PropertyRegistration Control::Impl::PROPERTY_7( typeRegistration, "state", Toolkit::DevelControl::Property::STATE, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
241 const PropertyRegistration Control::Impl::PROPERTY_8( typeRegistration, "subState", Toolkit::DevelControl::Property::SUB_STATE, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
242 const PropertyRegistration Control::Impl::PROPERTY_9( typeRegistration, "leftFocusableActorId", Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID, Property::INTEGER, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
243 const PropertyRegistration Control::Impl::PROPERTY_10( typeRegistration, "rightFocusableActorId", Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID,Property::INTEGER, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
244 const PropertyRegistration Control::Impl::PROPERTY_11( typeRegistration, "upFocusableActorId", Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID, Property::INTEGER, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
245 const PropertyRegistration Control::Impl::PROPERTY_12( typeRegistration, "downFocusableActorId", Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID, Property::INTEGER, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
249 Control::Impl::Impl( Control& controlImpl )
250 : mControlImpl( controlImpl ),
251 mState( Toolkit::DevelControl::NORMAL ),
253 mLeftFocusableActorId( -1 ),
254 mRightFocusableActorId( -1 ),
255 mUpFocusableActorId( -1 ),
256 mDownFocusableActorId( -1 ),
258 mBackgroundColor(Color::TRANSPARENT),
259 mStartingPinchScale( NULL ),
261 mPinchGestureDetector(),
262 mPanGestureDetector(),
263 mTapGestureDetector(),
264 mLongPressGestureDetector(),
265 mFlags( Control::ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
266 mIsKeyboardNavigationSupported( false ),
267 mIsKeyboardFocusGroup( false )
272 Control::Impl::~Impl()
274 // All gesture detectors will be destroyed so no need to disconnect.
275 delete mStartingPinchScale;
278 Control::Impl& Control::Impl::Get( Internal::Control& internalControl )
280 return *internalControl.mImpl;
283 const Control::Impl& Control::Impl::Get( const Internal::Control& internalControl )
285 return *internalControl.mImpl;
291 Toolkit::Visual::Base Control::Impl::GetVisualByName(
292 RegisteredVisualContainer& visuals,
293 const std::string& visualName )
295 Toolkit::Visual::Base visualHandle;
297 RegisteredVisualContainer::Iterator iter;
298 for ( iter = visuals.Begin(); iter != visuals.End(); iter++ )
300 Toolkit::Visual::Base visual = (*iter)->visual;
301 if( visual && visual.GetName() == visualName )
303 visualHandle = visual;
310 // Gesture Detection Methods
311 void Control::Impl::PinchDetected(Actor actor, const PinchGesture& pinch)
313 mControlImpl.OnPinch(pinch);
316 void Control::Impl::PanDetected(Actor actor, const PanGesture& pan)
318 mControlImpl.OnPan(pan);
321 void Control::Impl::TapDetected(Actor actor, const TapGesture& tap)
323 mControlImpl.OnTap(tap);
326 void Control::Impl::LongPressDetected(Actor actor, const LongPressGesture& longPress)
328 mControlImpl.OnLongPress(longPress);
331 // Called by a Visual when it's resource is ready
332 void Control::Impl::ResourceReady( Visual::Base& object)
335 // go through and check if all the visuals are ready, if they are emit a signal
336 for ( RegisteredVisualContainer::ConstIterator visualIter = mVisuals.Begin();
337 visualIter != mVisuals.End(); ++visualIter )
339 const Toolkit::Visual::Base visual = (*visualIter)->visual;
340 const Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
342 // one of the visuals is not ready
343 if( !visualImpl.IsResourceReady() )
349 // all the visuals are ready
350 Dali::Toolkit::Control handle( mControlImpl.GetOwner() );
351 mResourceReadySignal.Emit( handle );
355 bool Control::Impl::IsResourceReady() const
357 // go through and check all the visuals are ready
358 for ( RegisteredVisualContainer::ConstIterator visualIter = mVisuals.Begin();
359 visualIter != mVisuals.End(); ++visualIter )
361 const Toolkit::Visual::Base visual = (*visualIter)->visual;
362 const Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
364 // one of the visuals is not ready
365 if( !visualImpl.IsResourceReady() )
372 void Control::Impl::StopObservingVisual( Toolkit::Visual::Base& visual )
374 Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
376 // Stop observing the visual
377 visualImpl.RemoveResourceObserver( *this );
380 void Control::Impl::StartObservingVisual( Toolkit::Visual::Base& visual)
382 Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
384 // start observing the visual for resource ready
385 visualImpl.AddResourceObserver( *this );
391 * Called when a property of an object of this type is set.
392 * @param[in] object The object whose property is set.
393 * @param[in] index The property index.
394 * @param[in] value The new property value.
396 void Control::Impl::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
398 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
402 Control& controlImpl( GetImplementation( control ) );
406 case Toolkit::Control::Property::STYLE_NAME:
408 controlImpl.SetStyleName( value.Get< std::string >() );
412 case Toolkit::DevelControl::Property::STATE:
414 bool withTransitions=true;
415 const Property::Value* valuePtr=&value;
416 Property::Map* map = value.GetMap();
419 Property::Value* value2 = map->Find("withTransitions");
422 withTransitions = value2->Get<bool>();
425 valuePtr = map->Find("state");
430 Toolkit::DevelControl::State state( controlImpl.mImpl->mState );
431 if( Scripting::GetEnumerationProperty< Toolkit::DevelControl::State >( *valuePtr, ControlStateTable, ControlStateTableCount, state ) )
433 controlImpl.mImpl->SetState( state, withTransitions );
439 case Toolkit::DevelControl::Property::SUB_STATE:
441 std::string subState;
442 if( value.Get( subState ) )
444 controlImpl.mImpl->SetSubState( subState );
449 case Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID:
452 if( value.Get( focusId ) )
454 controlImpl.mImpl->mLeftFocusableActorId = focusId;
459 case Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID:
462 if( value.Get( focusId ) )
464 controlImpl.mImpl->mRightFocusableActorId = focusId;
469 case Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID:
472 if( value.Get( focusId ) )
474 controlImpl.mImpl->mUpFocusableActorId = focusId;
479 case Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID:
482 if( value.Get( focusId ) )
484 controlImpl.mImpl->mDownFocusableActorId = focusId;
489 case Toolkit::Control::Property::BACKGROUND_COLOR:
491 DALI_LOG_WARNING( "BACKGROUND_COLOR property is deprecated. Use BACKGROUND property instead\n" );
492 controlImpl.SetBackgroundColor( value.Get< Vector4 >() );
496 case Toolkit::Control::Property::BACKGROUND_IMAGE:
498 DALI_LOG_WARNING( "BACKGROUND_IMAGE property is deprecated. Use BACKGROUND property instead\n" );
499 Image image = Scripting::NewImage( value );
502 controlImpl.SetBackgroundImage( image );
506 // An empty image means the background is no longer required
507 controlImpl.ClearBackground();
512 case Toolkit::Control::Property::KEY_INPUT_FOCUS:
514 if ( value.Get< bool >() )
516 controlImpl.SetKeyInputFocus();
520 controlImpl.ClearKeyInputFocus();
525 case Toolkit::Control::Property::BACKGROUND:
529 const Property::Map* map = value.GetMap();
530 if( map && !map->Empty() )
532 controlImpl.SetBackground( *map );
534 else if( value.Get( url ) )
536 // don't know the size to load
537 Toolkit::Visual::Base visual = Toolkit::VisualFactory::Get().CreateVisual( url, ImageDimensions() );
540 controlImpl.RegisterVisual( Toolkit::Control::Property::BACKGROUND, visual );
541 visual.SetDepthIndex( DepthIndex::BACKGROUND );
544 else if( value.Get( color ) )
546 controlImpl.SetBackgroundColor(color);
550 // The background is an empty property map, so we should clear the background
551 controlImpl.ClearBackground();
556 case Toolkit::DevelControl::Property::TOOLTIP:
558 TooltipPtr& tooltipPtr = controlImpl.mImpl->mTooltip;
561 tooltipPtr = Tooltip::New( control );
563 tooltipPtr->SetProperties( value );
570 * Called to retrieve a property of an object of this type.
571 * @param[in] object The object whose property is to be retrieved.
572 * @param[in] index The property index.
573 * @return The current value of the property.
575 Property::Value Control::Impl::GetProperty( BaseObject* object, Property::Index index )
577 Property::Value value;
579 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
583 Control& controlImpl( GetImplementation( control ) );
587 case Toolkit::Control::Property::STYLE_NAME:
589 value = controlImpl.GetStyleName();
593 case Toolkit::DevelControl::Property::STATE:
595 value = controlImpl.mImpl->mState;
599 case Toolkit::DevelControl::Property::SUB_STATE:
601 value = controlImpl.mImpl->mSubStateName;
605 case Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID:
607 value = controlImpl.mImpl->mLeftFocusableActorId;
611 case Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID:
613 value = controlImpl.mImpl->mRightFocusableActorId;
617 case Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID:
619 value = controlImpl.mImpl->mUpFocusableActorId;
623 case Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID:
625 value = controlImpl.mImpl->mDownFocusableActorId;
629 case Toolkit::Control::Property::BACKGROUND_COLOR:
631 DALI_LOG_WARNING( "BACKGROUND_COLOR property is deprecated. Use BACKGROUND property instead\n" );
632 value = controlImpl.GetBackgroundColor();
636 case Toolkit::Control::Property::BACKGROUND_IMAGE:
638 DALI_LOG_WARNING( "BACKGROUND_IMAGE property is deprecated. Use BACKGROUND property instead\n" );
640 Toolkit::Visual::Base visual = controlImpl.GetVisual( Toolkit::Control::Property::BACKGROUND );
643 visual.CreatePropertyMap( map );
649 case Toolkit::Control::Property::KEY_INPUT_FOCUS:
651 value = controlImpl.HasKeyInputFocus();
655 case Toolkit::Control::Property::BACKGROUND:
658 Toolkit::Visual::Base visual = controlImpl.GetVisual( Toolkit::Control::Property::BACKGROUND );
661 visual.CreatePropertyMap( map );
668 case Toolkit::DevelControl::Property::TOOLTIP:
671 if( controlImpl.mImpl->mTooltip )
673 controlImpl.mImpl->mTooltip->CreatePropertyMap( map );
686 void Control::Impl::CopyInstancedProperties( RegisteredVisualContainer& visuals, Dictionary<Property::Map>& instancedProperties )
688 for(RegisteredVisualContainer::Iterator iter = visuals.Begin(); iter!= visuals.End(); iter++)
690 if( (*iter)->visual )
692 Property::Map instanceMap;
693 Toolkit::GetImplementation((*iter)->visual).CreateInstancePropertyMap(instanceMap);
694 instancedProperties.Add( (*iter)->visual.GetName(), instanceMap );
700 void Control::Impl::RemoveVisual( RegisteredVisualContainer& visuals, const std::string& visualName )
702 Actor self( mControlImpl.Self() );
704 for ( RegisteredVisualContainer::Iterator visualIter = visuals.Begin();
705 visualIter != visuals.End(); ++visualIter )
707 Toolkit::Visual::Base visual = (*visualIter)->visual;
708 if( visual && visual.GetName() == visualName )
710 Toolkit::GetImplementation(visual).SetOffStage( self );
711 (*visualIter)->visual.Reset();
712 visuals.Erase( visualIter );
718 void Control::Impl::RemoveVisuals( RegisteredVisualContainer& visuals, DictionaryKeys& removeVisuals )
720 Actor self( mControlImpl.Self() );
721 for( DictionaryKeys::iterator iter = removeVisuals.begin(); iter != removeVisuals.end(); ++iter )
723 const std::string visualName = *iter;
724 RemoveVisual( visuals, visualName );
730 * Go through the list of visuals that are common to both states.
731 * If they are different types, or are both image types with different
732 * URLs, then the existing visual needs moving and the new visual creating
734 void Control::Impl::RecreateChangedVisuals( Dictionary<Property::Map>& stateVisualsToChange,
735 Dictionary<Property::Map>& instancedProperties )
737 Dali::CustomActor handle( mControlImpl.GetOwner() );
738 for( Dictionary<Property::Map>::iterator iter = stateVisualsToChange.Begin();
739 iter != stateVisualsToChange.End(); ++iter )
741 const std::string& visualName = (*iter).key;
742 const Property::Map& toMap = (*iter).entry;
744 // is it a candidate for re-creation?
745 bool recreate = false;
747 Toolkit::Visual::Base visual = GetVisualByName( mVisuals, visualName );
750 Property::Map fromMap;
751 visual.CreatePropertyMap( fromMap );
753 Toolkit::DevelVisual::Type fromType = GetVisualTypeFromMap( fromMap );
754 Toolkit::DevelVisual::Type toType = GetVisualTypeFromMap( toMap );
756 if( fromType != toType )
762 if( fromType == Toolkit::DevelVisual::IMAGE || fromType == Toolkit::DevelVisual::N_PATCH
763 || fromType == Toolkit::DevelVisual::SVG || fromType == Toolkit::DevelVisual::ANIMATED_IMAGE )
765 Property::Value* fromUrl = fromMap.Find( Toolkit::ImageVisual::Property::URL, IMAGE_URL_NAME );
766 Property::Value* toUrl = toMap.Find( Toolkit::ImageVisual::Property::URL, IMAGE_URL_NAME );
768 if( fromUrl && toUrl )
770 std::string fromUrlString;
771 std::string toUrlString;
772 fromUrl->Get(fromUrlString);
773 toUrl->Get(toUrlString);
775 if( fromUrlString != toUrlString )
783 const Property::Map* instancedMap = instancedProperties.FindConst( visualName );
784 if( recreate || instancedMap )
786 RemoveVisual( mVisuals, visualName );
787 Style::ApplyVisual( handle, visualName, toMap, instancedMap );
791 // @todo check to see if we can apply toMap without recreating the visual
792 // e.g. by setting only animatable properties
793 // For now, recreate all visuals, but merge in instance data.
794 RemoveVisual( mVisuals, visualName );
795 Style::ApplyVisual( handle, visualName, toMap, instancedMap );
801 void Control::Impl::ReplaceStateVisualsAndProperties( const StylePtr oldState, const StylePtr newState, const std::string& subState )
803 // Collect all old visual names
804 DictionaryKeys stateVisualsToRemove;
807 oldState->visuals.GetKeys( stateVisualsToRemove );
808 if( ! subState.empty() )
810 const StylePtr* oldSubState = oldState->subStates.FindConst(subState);
813 DictionaryKeys subStateVisualsToRemove;
814 (*oldSubState)->visuals.GetKeys( subStateVisualsToRemove );
815 Merge( stateVisualsToRemove, subStateVisualsToRemove );
820 // Collect all new visual properties
821 Dictionary<Property::Map> stateVisualsToAdd;
824 stateVisualsToAdd = newState->visuals;
825 if( ! subState.empty() )
827 const StylePtr* newSubState = newState->subStates.FindConst(subState);
830 stateVisualsToAdd.Merge( (*newSubState)->visuals );
835 // If a name is in both add/remove, move it to change list.
836 Dictionary<Property::Map> stateVisualsToChange;
837 FindChangableVisuals( stateVisualsToAdd, stateVisualsToChange, stateVisualsToRemove);
839 // Copy instanced properties (e.g. text label) of current visuals
840 Dictionary<Property::Map> instancedProperties;
841 CopyInstancedProperties( mVisuals, instancedProperties );
843 // For each visual in remove list, remove from mVisuals
844 RemoveVisuals( mVisuals, stateVisualsToRemove );
846 // For each visual in add list, create and add to mVisuals
847 Dali::CustomActor handle( mControlImpl.GetOwner() );
848 Style::ApplyVisuals( handle, stateVisualsToAdd, instancedProperties );
850 // For each visual in change list, if it requires a new visual,
851 // remove old visual, create and add to mVisuals
852 RecreateChangedVisuals( stateVisualsToChange, instancedProperties );
855 void Control::Impl::SetState( DevelControl::State newState, bool withTransitions )
857 DevelControl::State oldState = mState;
858 Dali::CustomActor handle( mControlImpl.GetOwner() );
859 DALI_LOG_INFO(gLogFilter, Debug::Concise, "Control::Impl::SetState: %s\n",
860 (mState == DevelControl::NORMAL ? "NORMAL" :(
861 mState == DevelControl::FOCUSED ?"FOCUSED" : (
862 mState == DevelControl::DISABLED?"DISABLED":"NONE" ))));
864 if( mState != newState )
866 // If mState was Disabled, and new state is Focused, should probably
867 // store that fact, e.g. in another property that FocusManager can access.
870 // Trigger state change and transitions
871 // Apply new style, if stylemanager is available
872 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
875 const StylePtr stylePtr = GetImpl( styleManager ).GetRecordedStyle( Toolkit::Control( mControlImpl.GetOwner() ) );
879 std::string oldStateName = Scripting::GetEnumerationName< Toolkit::DevelControl::State >( oldState, ControlStateTable, ControlStateTableCount );
880 std::string newStateName = Scripting::GetEnumerationName< Toolkit::DevelControl::State >( newState, ControlStateTable, ControlStateTableCount );
882 const StylePtr* newStateStyle = stylePtr->subStates.Find( newStateName );
883 const StylePtr* oldStateStyle = stylePtr->subStates.Find( oldStateName );
884 if( oldStateStyle && newStateStyle )
886 // Only change if both state styles exist
887 ReplaceStateVisualsAndProperties( *oldStateStyle, *newStateStyle, mSubStateName );
894 void Control::Impl::SetSubState( const std::string& subStateName, bool withTransitions )
896 if( mSubStateName != subStateName )
898 // Get existing sub-state visuals, and unregister them
899 Dali::CustomActor handle( mControlImpl.GetOwner() );
901 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
904 const StylePtr stylePtr = GetImpl( styleManager ).GetRecordedStyle( Toolkit::Control( mControlImpl.GetOwner() ) );
908 std::string stateName = Scripting::GetEnumerationName< Toolkit::DevelControl::State >( mState, ControlStateTable, ControlStateTableCount );
910 const StylePtr* state = stylePtr->subStates.Find( stateName );
913 StylePtr stateStyle(*state);
915 const StylePtr* newStateStyle = stateStyle->subStates.Find( subStateName );
916 const StylePtr* oldStateStyle = stateStyle->subStates.Find( mSubStateName );
917 if( oldStateStyle && newStateStyle )
920 ReplaceStateVisualsAndProperties( *oldStateStyle, *newStateStyle, empty );
926 mSubStateName = subStateName;
930 } // namespace Internal
932 } // namespace Toolkit