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/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>
33 #include <dali-toolkit/internal/visuals/visual-base-impl.h>
34 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
35 #include <dali-toolkit/internal/styling/style-manager-impl.h>
36 #include <dali-toolkit/public-api/visuals/image-visual-properties.h>
37 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
38 #include <dali-toolkit/internal/visuals/visual-string-constants.h>
39 #include <dali-toolkit/devel-api/controls/control-devel.h>
50 extern const Dali::Scripting::StringEnum ControlStateTable[];
51 extern const unsigned int ControlStateTableCount;
54 // Not static or anonymous - shared with other translation units
55 const Scripting::StringEnum ControlStateTable[] = {
56 { "NORMAL", Toolkit::DevelControl::NORMAL },
57 { "FOCUSED", Toolkit::DevelControl::FOCUSED },
58 { "DISABLED", Toolkit::DevelControl::DISABLED },
60 const unsigned int ControlStateTableCount = sizeof( ControlStateTable ) / sizeof( ControlStateTable[0] );
67 #if defined(DEBUG_ENABLED)
68 Debug::Filter* gLogFilter = Debug::Filter::New( Debug::NoLogging, false, "LOG_CONTROL_VISUALS");
73 void Remove( Dictionary<T>& keyValues, const std::string& name )
75 keyValues.Remove(name);
78 void Remove( DictionaryKeys& keys, const std::string& name )
80 DictionaryKeys::iterator iter = std::find( keys.begin(), keys.end(), name );
81 if( iter != keys.end())
87 Toolkit::DevelVisual::Type GetVisualTypeFromMap( const Property::Map& map )
89 Property::Value* typeValue = map.Find( Toolkit::DevelVisual::Property::TYPE, VISUAL_TYPE );
90 Toolkit::DevelVisual::Type type = Toolkit::DevelVisual::IMAGE;
93 Scripting::GetEnumerationProperty( *typeValue, VISUAL_TYPE_TABLE, VISUAL_TYPE_TABLE_COUNT, type );
99 * Finds visual in given array, returning true if found along with the iterator for that visual as a out parameter
101 bool FindVisual( Property::Index targetIndex, const RegisteredVisualContainer& visuals, RegisteredVisualContainer::Iterator& iter )
103 for ( iter = visuals.Begin(); iter != visuals.End(); iter++ )
105 if ( (*iter)->index == targetIndex )
113 void FindChangableVisuals( Dictionary<Property::Map>& stateVisualsToAdd,
114 Dictionary<Property::Map>& stateVisualsToChange,
115 DictionaryKeys& stateVisualsToRemove)
117 DictionaryKeys copyOfStateVisualsToRemove = stateVisualsToRemove;
119 for( DictionaryKeys::iterator iter = copyOfStateVisualsToRemove.begin();
120 iter != copyOfStateVisualsToRemove.end(); ++iter )
122 const std::string& visualName = (*iter);
123 Property::Map* toMap = stateVisualsToAdd.Find( visualName );
126 stateVisualsToChange.Add( visualName, *toMap );
127 stateVisualsToAdd.Remove( visualName );
128 Remove( stateVisualsToRemove, visualName );
133 Toolkit::Visual::Base GetVisualByName(
134 const RegisteredVisualContainer& visuals,
135 const std::string& visualName )
137 Toolkit::Visual::Base visualHandle;
139 RegisteredVisualContainer::Iterator iter;
140 for ( iter = visuals.Begin(); iter != visuals.End(); iter++ )
142 Toolkit::Visual::Base visual = (*iter)->visual;
143 if( visual && visual.GetName() == visualName )
145 visualHandle = visual;
153 * Performs actions as requested using the action name.
154 * @param[in] object The object on which to perform the action.
155 * @param[in] actionName The action to perform.
156 * @param[in] attributes The attributes with which to perfrom this action.
157 * @return true if action has been accepted by this control
159 const char* ACTION_ACCESSIBILITY_ACTIVATED = "accessibilityActivated";
160 static bool DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes )
164 if( object && ( 0 == strcmp( actionName.c_str(), ACTION_ACCESSIBILITY_ACTIVATED ) ) )
166 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
169 // if cast succeeds there is an implementation so no need to check
170 ret = Internal::GetImplementation( control ).OnAccessibilityActivated();
178 * Connects a callback function with the object's signals.
179 * @param[in] object The object providing the signal.
180 * @param[in] tracker Used to disconnect the signal.
181 * @param[in] signalName The signal to connect to.
182 * @param[in] functor A newly allocated FunctorDelegate.
183 * @return True if the signal was connected.
184 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
186 const char* SIGNAL_KEY_EVENT = "keyEvent";
187 const char* SIGNAL_KEY_INPUT_FOCUS_GAINED = "keyInputFocusGained";
188 const char* SIGNAL_KEY_INPUT_FOCUS_LOST = "keyInputFocusLost";
189 const char* SIGNAL_TAPPED = "tapped";
190 const char* SIGNAL_PANNED = "panned";
191 const char* SIGNAL_PINCHED = "pinched";
192 const char* SIGNAL_LONG_PRESSED = "longPressed";
193 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
195 Dali::BaseHandle handle( object );
197 bool connected( false );
198 Toolkit::Control control = Toolkit::Control::DownCast( handle );
201 Internal::Control& controlImpl( Internal::GetImplementation( control ) );
204 if ( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_EVENT ) )
206 controlImpl.KeyEventSignal().Connect( tracker, functor );
208 else if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_INPUT_FOCUS_GAINED ) )
210 controlImpl.KeyInputFocusGainedSignal().Connect( tracker, functor );
212 else if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_INPUT_FOCUS_LOST ) )
214 controlImpl.KeyInputFocusLostSignal().Connect( tracker, functor );
216 else if( 0 == strcmp( signalName.c_str(), SIGNAL_TAPPED ) )
218 controlImpl.EnableGestureDetection( Gesture::Tap );
219 controlImpl.GetTapGestureDetector().DetectedSignal().Connect( tracker, functor );
221 else if( 0 == strcmp( signalName.c_str(), SIGNAL_PANNED ) )
223 controlImpl.EnableGestureDetection( Gesture::Pan );
224 controlImpl.GetPanGestureDetector().DetectedSignal().Connect( tracker, functor );
226 else if( 0 == strcmp( signalName.c_str(), SIGNAL_PINCHED ) )
228 controlImpl.EnableGestureDetection( Gesture::Pinch );
229 controlImpl.GetPinchGestureDetector().DetectedSignal().Connect( tracker, functor );
231 else if( 0 == strcmp( signalName.c_str(), SIGNAL_LONG_PRESSED ) )
233 controlImpl.EnableGestureDetection( Gesture::LongPress );
234 controlImpl.GetLongPressGestureDetector().DetectedSignal().Connect( tracker, functor );
241 * Creates control through type registry
245 return Internal::Control::New();
247 // Setup signals and actions using the type-registry.
248 DALI_TYPE_REGISTRATION_BEGIN( Control, CustomActor, Create );
250 // Note: Properties are registered separately below.
252 SignalConnectorType registerSignal1( typeRegistration, SIGNAL_KEY_EVENT, &DoConnectSignal );
253 SignalConnectorType registerSignal2( typeRegistration, SIGNAL_KEY_INPUT_FOCUS_GAINED, &DoConnectSignal );
254 SignalConnectorType registerSignal3( typeRegistration, SIGNAL_KEY_INPUT_FOCUS_LOST, &DoConnectSignal );
255 SignalConnectorType registerSignal4( typeRegistration, SIGNAL_TAPPED, &DoConnectSignal );
256 SignalConnectorType registerSignal5( typeRegistration, SIGNAL_PANNED, &DoConnectSignal );
257 SignalConnectorType registerSignal6( typeRegistration, SIGNAL_PINCHED, &DoConnectSignal );
258 SignalConnectorType registerSignal7( typeRegistration, SIGNAL_LONG_PRESSED, &DoConnectSignal );
260 TypeAction registerAction( typeRegistration, ACTION_ACCESSIBILITY_ACTIVATED, &DoAction );
262 DALI_TYPE_REGISTRATION_END()
264 } // unnamed namespace
267 // Properties registered without macro to use specific member variables.
268 const PropertyRegistration Control::Impl::PROPERTY_1( typeRegistration, "styleName", Toolkit::Control::Property::STYLE_NAME, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
269 const PropertyRegistration Control::Impl::PROPERTY_2( typeRegistration, "backgroundColor", Toolkit::Control::Property::BACKGROUND_COLOR, Property::VECTOR4, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
270 const PropertyRegistration Control::Impl::PROPERTY_3( typeRegistration, "backgroundImage", Toolkit::Control::Property::BACKGROUND_IMAGE, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
271 const PropertyRegistration Control::Impl::PROPERTY_4( typeRegistration, "keyInputFocus", Toolkit::Control::Property::KEY_INPUT_FOCUS, Property::BOOLEAN, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
272 const PropertyRegistration Control::Impl::PROPERTY_5( typeRegistration, "background", Toolkit::Control::Property::BACKGROUND, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
273 const PropertyRegistration Control::Impl::PROPERTY_6( typeRegistration, "tooltip", Toolkit::DevelControl::Property::TOOLTIP, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
274 const PropertyRegistration Control::Impl::PROPERTY_7( typeRegistration, "state", Toolkit::DevelControl::Property::STATE, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
275 const PropertyRegistration Control::Impl::PROPERTY_8( typeRegistration, "subState", Toolkit::DevelControl::Property::SUB_STATE, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
276 const PropertyRegistration Control::Impl::PROPERTY_9( typeRegistration, "leftFocusableActorId", Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID, Property::INTEGER, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
277 const PropertyRegistration Control::Impl::PROPERTY_10( typeRegistration, "rightFocusableActorId", Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID,Property::INTEGER, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
278 const PropertyRegistration Control::Impl::PROPERTY_11( typeRegistration, "upFocusableActorId", Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID, Property::INTEGER, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
279 const PropertyRegistration Control::Impl::PROPERTY_12( typeRegistration, "downFocusableActorId", Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID, Property::INTEGER, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
283 Control::Impl::Impl( Control& controlImpl )
284 : mControlImpl( controlImpl ),
285 mState( Toolkit::DevelControl::NORMAL ),
287 mLeftFocusableActorId( -1 ),
288 mRightFocusableActorId( -1 ),
289 mUpFocusableActorId( -1 ),
290 mDownFocusableActorId( -1 ),
292 mBackgroundColor(Color::TRANSPARENT),
293 mStartingPinchScale( NULL ),
295 mPinchGestureDetector(),
296 mPanGestureDetector(),
297 mTapGestureDetector(),
298 mLongPressGestureDetector(),
299 mFlags( Control::ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
300 mIsKeyboardNavigationSupported( false ),
301 mIsKeyboardFocusGroup( false )
306 Control::Impl::~Impl()
308 // All gesture detectors will be destroyed so no need to disconnect.
309 delete mStartingPinchScale;
312 Control::Impl& Control::Impl::Get( Internal::Control& internalControl )
314 return *internalControl.mImpl;
317 const Control::Impl& Control::Impl::Get( const Internal::Control& internalControl )
319 return *internalControl.mImpl;
322 // Gesture Detection Methods
323 void Control::Impl::PinchDetected(Actor actor, const PinchGesture& pinch)
325 mControlImpl.OnPinch(pinch);
328 void Control::Impl::PanDetected(Actor actor, const PanGesture& pan)
330 mControlImpl.OnPan(pan);
333 void Control::Impl::TapDetected(Actor actor, const TapGesture& tap)
335 mControlImpl.OnTap(tap);
338 void Control::Impl::LongPressDetected(Actor actor, const LongPressGesture& longPress)
340 mControlImpl.OnLongPress(longPress);
343 // Called by a Visual when it's resource is ready
344 void Control::Impl::ResourceReady( Visual::Base& object)
347 // go through and check if all the visuals are ready, if they are emit a signal
348 for ( RegisteredVisualContainer::ConstIterator visualIter = mVisuals.Begin();
349 visualIter != mVisuals.End(); ++visualIter )
351 const Toolkit::Visual::Base visual = (*visualIter)->visual;
352 const Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
354 // one of the visuals is not ready
355 if( !visualImpl.IsResourceReady() )
361 // all the visuals are ready
362 Dali::Toolkit::Control handle( mControlImpl.GetOwner() );
363 mResourceReadySignal.Emit( handle );
367 bool Control::Impl::IsResourceReady() const
369 // go through and check all the visuals are ready
370 for ( RegisteredVisualContainer::ConstIterator visualIter = mVisuals.Begin();
371 visualIter != mVisuals.End(); ++visualIter )
373 const Toolkit::Visual::Base visual = (*visualIter)->visual;
374 const Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
376 // one of the visuals is not ready
377 if( !visualImpl.IsResourceReady() )
385 void Control::Impl::RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual )
387 RegisterVisual( index, visual, VisualState::ENABLED, DepthIndexValue::NOT_SET );
390 void Control::Impl::RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, float depthIndex )
392 RegisterVisual( index, visual, VisualState::ENABLED, DepthIndexValue::SET, depthIndex );
395 void Control::Impl::RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, bool enabled )
397 RegisterVisual( index, visual, ( enabled ? VisualState::ENABLED : VisualState::DISABLED ), DepthIndexValue::NOT_SET );
400 void Control::Impl::RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, bool enabled, float depthIndex )
402 RegisterVisual( index, visual, ( enabled ? VisualState::ENABLED : VisualState::DISABLED ), DepthIndexValue::SET, depthIndex );
405 void Control::Impl::RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, VisualState::Type enabled, DepthIndexValue::Type depthIndexValueSet, float depthIndex )
407 bool visualReplaced ( false );
408 Actor self = mControlImpl.Self();
410 if( !mVisuals.Empty() )
412 RegisteredVisualContainer::Iterator iter;
413 // Check if visual (index) is already registered. Replace if so.
414 if ( FindVisual( index, mVisuals, iter ) )
416 if( (*iter)->visual && self.OnStage() )
418 Toolkit::GetImplementation((*iter)->visual).SetOffStage( self );
421 // 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
422 if( ( depthIndexValueSet == DepthIndexValue::NOT_SET ) &&
423 EqualsZero( visual.GetDepthIndex() ) )
425 const float currentDepthIndex = (*iter)->visual.GetDepthIndex();
426 visual.SetDepthIndex( currentDepthIndex );
429 StopObservingVisual( (*iter)->visual );
430 StartObservingVisual( visual );
432 (*iter)->visual = visual;
433 (*iter)->enabled = ( enabled == VisualState::ENABLED ) ? true : false;
434 visualReplaced = true;
438 // If not set, set the name of the visual to the same name as the control's property.
439 // ( If the control has been type registered )
440 if( visual.GetName().empty() )
442 // Check if the control has been type registered:
443 TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid( mControlImpl ) );
446 // Check if the property index has been registered:
447 Property::IndexContainer indices;
448 typeInfo.GetPropertyIndices( indices );
449 Property::IndexContainer::Iterator iter = std::find( indices.Begin(), indices.End(), index );
450 if( iter != indices.End() )
452 // If it has, then get it's name and use that for the visual
453 std::string visualName = typeInfo.GetPropertyName( index );
454 visual.SetName( visualName );
459 if( !visualReplaced ) // New registration entry
461 mVisuals.PushBack( new RegisteredVisual( index, visual, ( enabled == VisualState::ENABLED ? true : false ) ) );
463 // monitor when the visuals resources are ready
464 StartObservingVisual( visual );
466 // 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
467 if( ( depthIndexValueSet == DepthIndexValue::NOT_SET ) &&
468 ( mVisuals.Size() > 1 ) &&
469 EqualsZero( visual.GetDepthIndex() ) )
471 float maxDepthIndex = std::numeric_limits< float >::min();
473 RegisteredVisualContainer::ConstIterator iter;
474 const RegisteredVisualContainer::ConstIterator endIter = mVisuals.End();
475 for ( iter = mVisuals.Begin(); iter != endIter; iter++ )
477 const float visualDepthIndex = (*iter)->visual.GetDepthIndex();
478 if ( visualDepthIndex > maxDepthIndex )
480 maxDepthIndex = visualDepthIndex;
484 ++maxDepthIndex; // Add one to the current maximum depth index so that our added visual appears on top
485 visual.SetDepthIndex( maxDepthIndex );
491 // If the caller has set the depth-index, then set it here
492 if( depthIndexValueSet == DepthIndexValue::SET )
494 visual.SetDepthIndex( depthIndex );
497 // Put on stage if enabled and the control is already on the stage
498 if( ( enabled == VisualState::ENABLED ) && self.OnStage() )
500 Toolkit::GetImplementation(visual).SetOnStage( self );
504 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::RegisterVisual() Registered %s(%d), enabled:%s\n", visual.GetName().c_str(), index, enabled?"T":"F" );
507 void Control::Impl::UnregisterVisual( Property::Index index )
509 RegisteredVisualContainer::Iterator iter;
510 if ( FindVisual( index, mVisuals, iter ) )
512 // stop observing visual
513 StopObservingVisual( (*iter)->visual );
515 Actor self( mControlImpl.Self() );
516 Toolkit::GetImplementation((*iter)->visual).SetOffStage( self );
517 (*iter)->visual.Reset();
518 mVisuals.Erase( iter );
522 Toolkit::Visual::Base Control::Impl::GetVisual( Property::Index index ) const
524 RegisteredVisualContainer::Iterator iter;
525 if ( FindVisual( index, mVisuals, iter ) )
527 return (*iter)->visual;
530 return Toolkit::Visual::Base();
533 void Control::Impl::EnableVisual( Property::Index index, bool enable )
535 RegisteredVisualContainer::Iterator iter;
536 if ( FindVisual( index, mVisuals, iter ) )
538 if ( (*iter)->enabled == enable )
540 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::EnableVisual Visual %s(%d) already %s\n", (*iter)->visual.GetName().c_str(), index, enable?"enabled":"disabled");
544 (*iter)->enabled = enable;
545 Actor parentActor = mControlImpl.Self();
546 if ( mControlImpl.Self().OnStage() ) // If control not on Stage then Visual will be added when StageConnection is called.
550 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::EnableVisual Setting %s(%d) on stage \n", (*iter)->visual.GetName().c_str(), index );
551 Toolkit::GetImplementation((*iter)->visual).SetOnStage( parentActor );
555 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::EnableVisual Setting %s(%d) off stage \n", (*iter)->visual.GetName().c_str(), index );
556 Toolkit::GetImplementation((*iter)->visual).SetOffStage( parentActor ); // No need to call if control not staged.
562 bool Control::Impl::IsVisualEnabled( Property::Index index ) const
564 RegisteredVisualContainer::Iterator iter;
565 if ( FindVisual( index, mVisuals, iter ) )
567 return (*iter)->enabled;
572 void Control::Impl::StopObservingVisual( Toolkit::Visual::Base& visual )
574 Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
576 // Stop observing the visual
577 visualImpl.RemoveResourceObserver( *this );
580 void Control::Impl::StartObservingVisual( Toolkit::Visual::Base& visual)
582 Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
584 // start observing the visual for resource ready
585 visualImpl.AddResourceObserver( *this );
588 Dali::Animation Control::Impl::CreateTransition( const Toolkit::TransitionData& handle )
590 Dali::Animation transition;
591 const Internal::TransitionData& transitionData = Toolkit::GetImplementation( handle );
593 if( transitionData.Count() > 0 )
595 // Setup a Transition from TransitionData.
596 TransitionData::Iterator end = transitionData.End();
597 for( TransitionData::Iterator iter = transitionData.Begin() ;
598 iter != end; ++iter )
600 TransitionData::Animator* animator = (*iter);
602 Toolkit::Visual::Base visual = GetVisualByName( mVisuals, animator->objectName );
606 Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
607 visualImpl.AnimateProperty( transition, *animator );
611 // Otherwise, try any actor children of control (Including the control)
612 Actor child = mControlImpl.Self().FindChildByName( animator->objectName );
615 Property::Index propertyIndex = DevelHandle::GetPropertyIndex( child, animator->propertyKey );
616 if( propertyIndex != Property::INVALID_INDEX )
618 if( animator->animate == false )
620 if( animator->targetValue.GetType() != Property::NONE )
622 child.SetProperty( propertyIndex, animator->targetValue );
625 else // animate the property
627 if( animator->initialValue.GetType() != Property::NONE )
629 child.SetProperty( propertyIndex, animator->initialValue );
634 transition = Dali::Animation::New( 0.1f );
637 transition.AnimateTo( Property( child, propertyIndex ),
638 animator->targetValue,
639 animator->alphaFunction,
640 TimePeriod( animator->timePeriodDelay,
641 animator->timePeriodDuration ) );
652 void Control::Impl::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
654 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
658 Control& controlImpl( GetImplementation( control ) );
662 case Toolkit::Control::Property::STYLE_NAME:
664 controlImpl.SetStyleName( value.Get< std::string >() );
668 case Toolkit::DevelControl::Property::STATE:
670 bool withTransitions=true;
671 const Property::Value* valuePtr=&value;
672 Property::Map* map = value.GetMap();
675 Property::Value* value2 = map->Find("withTransitions");
678 withTransitions = value2->Get<bool>();
681 valuePtr = map->Find("state");
686 Toolkit::DevelControl::State state( controlImpl.mImpl->mState );
687 if( Scripting::GetEnumerationProperty< Toolkit::DevelControl::State >( *valuePtr, ControlStateTable, ControlStateTableCount, state ) )
689 controlImpl.mImpl->SetState( state, withTransitions );
695 case Toolkit::DevelControl::Property::SUB_STATE:
697 std::string subState;
698 if( value.Get( subState ) )
700 controlImpl.mImpl->SetSubState( subState );
705 case Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID:
708 if( value.Get( focusId ) )
710 controlImpl.mImpl->mLeftFocusableActorId = focusId;
715 case Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID:
718 if( value.Get( focusId ) )
720 controlImpl.mImpl->mRightFocusableActorId = focusId;
725 case Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID:
728 if( value.Get( focusId ) )
730 controlImpl.mImpl->mUpFocusableActorId = focusId;
735 case Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID:
738 if( value.Get( focusId ) )
740 controlImpl.mImpl->mDownFocusableActorId = focusId;
745 case Toolkit::Control::Property::BACKGROUND_COLOR:
747 DALI_LOG_WARNING( "BACKGROUND_COLOR property is deprecated. Use BACKGROUND property instead\n" );
748 controlImpl.SetBackgroundColor( value.Get< Vector4 >() );
752 case Toolkit::Control::Property::BACKGROUND_IMAGE:
754 DALI_LOG_WARNING( "BACKGROUND_IMAGE property is deprecated. Use BACKGROUND property instead\n" );
755 Image image = Scripting::NewImage( value );
758 controlImpl.SetBackgroundImage( image );
762 // An empty image means the background is no longer required
763 controlImpl.ClearBackground();
768 case Toolkit::Control::Property::KEY_INPUT_FOCUS:
770 if ( value.Get< bool >() )
772 controlImpl.SetKeyInputFocus();
776 controlImpl.ClearKeyInputFocus();
781 case Toolkit::Control::Property::BACKGROUND:
785 const Property::Map* map = value.GetMap();
786 if( map && !map->Empty() )
788 controlImpl.SetBackground( *map );
790 else if( value.Get( url ) )
792 // don't know the size to load
793 Toolkit::Visual::Base visual = Toolkit::VisualFactory::Get().CreateVisual( url, ImageDimensions() );
796 controlImpl.mImpl->RegisterVisual( Toolkit::Control::Property::BACKGROUND, visual, float( DepthIndex::BACKGROUND ) );
799 else if( value.Get( color ) )
801 controlImpl.SetBackgroundColor(color);
805 // The background is an empty property map, so we should clear the background
806 controlImpl.ClearBackground();
811 case Toolkit::DevelControl::Property::TOOLTIP:
813 TooltipPtr& tooltipPtr = controlImpl.mImpl->mTooltip;
816 tooltipPtr = Tooltip::New( control );
818 tooltipPtr->SetProperties( value );
824 Property::Value Control::Impl::GetProperty( BaseObject* object, Property::Index index )
826 Property::Value value;
828 Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
832 Control& controlImpl( GetImplementation( control ) );
836 case Toolkit::Control::Property::STYLE_NAME:
838 value = controlImpl.GetStyleName();
842 case Toolkit::DevelControl::Property::STATE:
844 value = controlImpl.mImpl->mState;
848 case Toolkit::DevelControl::Property::SUB_STATE:
850 value = controlImpl.mImpl->mSubStateName;
854 case Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID:
856 value = controlImpl.mImpl->mLeftFocusableActorId;
860 case Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID:
862 value = controlImpl.mImpl->mRightFocusableActorId;
866 case Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID:
868 value = controlImpl.mImpl->mUpFocusableActorId;
872 case Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID:
874 value = controlImpl.mImpl->mDownFocusableActorId;
878 case Toolkit::Control::Property::BACKGROUND_COLOR:
880 DALI_LOG_WARNING( "BACKGROUND_COLOR property is deprecated. Use BACKGROUND property instead\n" );
881 value = controlImpl.GetBackgroundColor();
885 case Toolkit::Control::Property::BACKGROUND_IMAGE:
887 DALI_LOG_WARNING( "BACKGROUND_IMAGE property is deprecated. Use BACKGROUND property instead\n" );
889 Toolkit::Visual::Base visual = controlImpl.mImpl->GetVisual( Toolkit::Control::Property::BACKGROUND );
892 visual.CreatePropertyMap( map );
898 case Toolkit::Control::Property::KEY_INPUT_FOCUS:
900 value = controlImpl.HasKeyInputFocus();
904 case Toolkit::Control::Property::BACKGROUND:
907 Toolkit::Visual::Base visual = controlImpl.mImpl->GetVisual( Toolkit::Control::Property::BACKGROUND );
910 visual.CreatePropertyMap( map );
917 case Toolkit::DevelControl::Property::TOOLTIP:
920 if( controlImpl.mImpl->mTooltip )
922 controlImpl.mImpl->mTooltip->CreatePropertyMap( map );
935 void Control::Impl::CopyInstancedProperties( RegisteredVisualContainer& visuals, Dictionary<Property::Map>& instancedProperties )
937 for(RegisteredVisualContainer::Iterator iter = visuals.Begin(); iter!= visuals.End(); iter++)
939 if( (*iter)->visual )
941 Property::Map instanceMap;
942 Toolkit::GetImplementation((*iter)->visual).CreateInstancePropertyMap(instanceMap);
943 instancedProperties.Add( (*iter)->visual.GetName(), instanceMap );
949 void Control::Impl::RemoveVisual( RegisteredVisualContainer& visuals, const std::string& visualName )
951 Actor self( mControlImpl.Self() );
953 for ( RegisteredVisualContainer::Iterator visualIter = visuals.Begin();
954 visualIter != visuals.End(); ++visualIter )
956 Toolkit::Visual::Base visual = (*visualIter)->visual;
957 if( visual && visual.GetName() == visualName )
959 Toolkit::GetImplementation(visual).SetOffStage( self );
960 (*visualIter)->visual.Reset();
961 visuals.Erase( visualIter );
967 void Control::Impl::RemoveVisuals( RegisteredVisualContainer& visuals, DictionaryKeys& removeVisuals )
969 Actor self( mControlImpl.Self() );
970 for( DictionaryKeys::iterator iter = removeVisuals.begin(); iter != removeVisuals.end(); ++iter )
972 const std::string visualName = *iter;
973 RemoveVisual( visuals, visualName );
977 void Control::Impl::RecreateChangedVisuals( Dictionary<Property::Map>& stateVisualsToChange,
978 Dictionary<Property::Map>& instancedProperties )
980 Dali::CustomActor handle( mControlImpl.GetOwner() );
981 for( Dictionary<Property::Map>::iterator iter = stateVisualsToChange.Begin();
982 iter != stateVisualsToChange.End(); ++iter )
984 const std::string& visualName = (*iter).key;
985 const Property::Map& toMap = (*iter).entry;
987 // is it a candidate for re-creation?
988 bool recreate = false;
990 Toolkit::Visual::Base visual = GetVisualByName( mVisuals, visualName );
993 Property::Map fromMap;
994 visual.CreatePropertyMap( fromMap );
996 Toolkit::DevelVisual::Type fromType = GetVisualTypeFromMap( fromMap );
997 Toolkit::DevelVisual::Type toType = GetVisualTypeFromMap( toMap );
999 if( fromType != toType )
1005 if( fromType == Toolkit::DevelVisual::IMAGE || fromType == Toolkit::DevelVisual::N_PATCH
1006 || fromType == Toolkit::DevelVisual::SVG || fromType == Toolkit::DevelVisual::ANIMATED_IMAGE )
1008 Property::Value* fromUrl = fromMap.Find( Toolkit::ImageVisual::Property::URL, IMAGE_URL_NAME );
1009 Property::Value* toUrl = toMap.Find( Toolkit::ImageVisual::Property::URL, IMAGE_URL_NAME );
1011 if( fromUrl && toUrl )
1013 std::string fromUrlString;
1014 std::string toUrlString;
1015 fromUrl->Get(fromUrlString);
1016 toUrl->Get(toUrlString);
1018 if( fromUrlString != toUrlString )
1026 const Property::Map* instancedMap = instancedProperties.FindConst( visualName );
1027 if( recreate || instancedMap )
1029 RemoveVisual( mVisuals, visualName );
1030 Style::ApplyVisual( handle, visualName, toMap, instancedMap );
1034 // @todo check to see if we can apply toMap without recreating the visual
1035 // e.g. by setting only animatable properties
1036 // For now, recreate all visuals, but merge in instance data.
1037 RemoveVisual( mVisuals, visualName );
1038 Style::ApplyVisual( handle, visualName, toMap, instancedMap );
1044 void Control::Impl::ReplaceStateVisualsAndProperties( const StylePtr oldState, const StylePtr newState, const std::string& subState )
1046 // Collect all old visual names
1047 DictionaryKeys stateVisualsToRemove;
1050 oldState->visuals.GetKeys( stateVisualsToRemove );
1051 if( ! subState.empty() )
1053 const StylePtr* oldSubState = oldState->subStates.FindConst(subState);
1056 DictionaryKeys subStateVisualsToRemove;
1057 (*oldSubState)->visuals.GetKeys( subStateVisualsToRemove );
1058 Merge( stateVisualsToRemove, subStateVisualsToRemove );
1063 // Collect all new visual properties
1064 Dictionary<Property::Map> stateVisualsToAdd;
1067 stateVisualsToAdd = newState->visuals;
1068 if( ! subState.empty() )
1070 const StylePtr* newSubState = newState->subStates.FindConst(subState);
1073 stateVisualsToAdd.Merge( (*newSubState)->visuals );
1078 // If a name is in both add/remove, move it to change list.
1079 Dictionary<Property::Map> stateVisualsToChange;
1080 FindChangableVisuals( stateVisualsToAdd, stateVisualsToChange, stateVisualsToRemove);
1082 // Copy instanced properties (e.g. text label) of current visuals
1083 Dictionary<Property::Map> instancedProperties;
1084 CopyInstancedProperties( mVisuals, instancedProperties );
1086 // For each visual in remove list, remove from mVisuals
1087 RemoveVisuals( mVisuals, stateVisualsToRemove );
1089 // For each visual in add list, create and add to mVisuals
1090 Dali::CustomActor handle( mControlImpl.GetOwner() );
1091 Style::ApplyVisuals( handle, stateVisualsToAdd, instancedProperties );
1093 // For each visual in change list, if it requires a new visual,
1094 // remove old visual, create and add to mVisuals
1095 RecreateChangedVisuals( stateVisualsToChange, instancedProperties );
1098 void Control::Impl::SetState( DevelControl::State newState, bool withTransitions )
1100 DevelControl::State oldState = mState;
1101 Dali::CustomActor handle( mControlImpl.GetOwner() );
1102 DALI_LOG_INFO(gLogFilter, Debug::Concise, "Control::Impl::SetState: %s\n",
1103 (mState == DevelControl::NORMAL ? "NORMAL" :(
1104 mState == DevelControl::FOCUSED ?"FOCUSED" : (
1105 mState == DevelControl::DISABLED?"DISABLED":"NONE" ))));
1107 if( mState != newState )
1109 // If mState was Disabled, and new state is Focused, should probably
1110 // store that fact, e.g. in another property that FocusManager can access.
1113 // Trigger state change and transitions
1114 // Apply new style, if stylemanager is available
1115 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
1118 const StylePtr stylePtr = GetImpl( styleManager ).GetRecordedStyle( Toolkit::Control( mControlImpl.GetOwner() ) );
1122 std::string oldStateName = Scripting::GetEnumerationName< Toolkit::DevelControl::State >( oldState, ControlStateTable, ControlStateTableCount );
1123 std::string newStateName = Scripting::GetEnumerationName< Toolkit::DevelControl::State >( newState, ControlStateTable, ControlStateTableCount );
1125 const StylePtr* newStateStyle = stylePtr->subStates.Find( newStateName );
1126 const StylePtr* oldStateStyle = stylePtr->subStates.Find( oldStateName );
1127 if( oldStateStyle && newStateStyle )
1129 // Only change if both state styles exist
1130 ReplaceStateVisualsAndProperties( *oldStateStyle, *newStateStyle, mSubStateName );
1137 void Control::Impl::SetSubState( const std::string& subStateName, bool withTransitions )
1139 if( mSubStateName != subStateName )
1141 // Get existing sub-state visuals, and unregister them
1142 Dali::CustomActor handle( mControlImpl.GetOwner() );
1144 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
1147 const StylePtr stylePtr = GetImpl( styleManager ).GetRecordedStyle( Toolkit::Control( mControlImpl.GetOwner() ) );
1151 std::string stateName = Scripting::GetEnumerationName< Toolkit::DevelControl::State >( mState, ControlStateTable, ControlStateTableCount );
1153 const StylePtr* state = stylePtr->subStates.Find( stateName );
1156 StylePtr stateStyle(*state);
1158 const StylePtr* newStateStyle = stateStyle->subStates.Find( subStateName );
1159 const StylePtr* oldStateStyle = stateStyle->subStates.Find( mSubStateName );
1160 if( oldStateStyle && newStateStyle )
1163 ReplaceStateVisualsAndProperties( *oldStateStyle, *newStateStyle, empty );
1169 mSubStateName = subStateName;
1173 } // namespace Internal
1175 } // namespace Toolkit