-namespace Internal
-{
-
-class Control::Impl : public ConnectionTracker
-{
-public:
-
- // Construction & Destruction
- Impl(Control& controlImpl)
- : mControlImpl( controlImpl ),
- mState( Toolkit::DevelControl::NORMAL ),
- mSubStateName(""),
- mStyleName(""),
- mBackgroundColor(Color::TRANSPARENT),
- mStartingPinchScale( NULL ),
- mKeyEventSignal(),
- mPinchGestureDetector(),
- mPanGestureDetector(),
- mTapGestureDetector(),
- mLongPressGestureDetector(),
- mFlags( Control::ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
- mIsKeyboardNavigationSupported( false ),
- mIsKeyboardFocusGroup( false )
- {
- }
-
- ~Impl()
- {
- // All gesture detectors will be destroyed so no need to disconnect.
- delete mStartingPinchScale;
- }
-
- // Gesture Detection Methods
-
- void PinchDetected(Actor actor, const PinchGesture& pinch)
- {
- mControlImpl.OnPinch(pinch);
- }
-
- void PanDetected(Actor actor, const PanGesture& pan)
- {
- mControlImpl.OnPan(pan);
- }
-
- void TapDetected(Actor actor, const TapGesture& tap)
- {
- mControlImpl.OnTap(tap);
- }
-
- void LongPressDetected(Actor actor, const LongPressGesture& longPress)
- {
- mControlImpl.OnLongPress(longPress);
- }
-
- // Properties
-
- /**
- * Called when a property of an object of this type is set.
- * @param[in] object The object whose property is set.
- * @param[in] index The property index.
- * @param[in] value The new property value.
- */
- static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
- {
- Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
-
- if ( control )
- {
- Control& controlImpl( GetImplementation( control ) );
-
- switch ( index )
- {
- case Toolkit::Control::Property::STYLE_NAME:
- {
- controlImpl.SetStyleName( value.Get< std::string >() );
- break;
- }
-
- case Toolkit::DevelControl::Property::STATE:
- {
- bool withTransitions=true;
- const Property::Value* valuePtr=&value;
- Property::Map* map = value.GetMap();
- if(map)
- {
- Property::Value* value2 = map->Find("withTransitions");
- if( value2 )
- {
- withTransitions = value2->Get<bool>();
- }
-
- valuePtr = map->Find("state");
- }
-
- if( valuePtr )
- {
- Toolkit::DevelControl::State state( controlImpl.mImpl->mState );
- if( Scripting::GetEnumerationProperty< Toolkit::DevelControl::State >( *valuePtr, ControlStateTable, ControlStateTableCount, state ) )
- {
- controlImpl.mImpl->SetState( state, withTransitions );
- }
- }
- }
- break;
-
- case Toolkit::DevelControl::Property::SUB_STATE:
- {
- std::string subState;
- if( value.Get( subState ) )
- {
- controlImpl.mImpl->SetSubState( subState );
- }
- }
- break;
-
- case Toolkit::Control::Property::BACKGROUND_COLOR:
- {
- DALI_LOG_WARNING( "BACKGROUND_COLOR property is deprecated. Use BACKGROUND property instead\n" );
- controlImpl.SetBackgroundColor( value.Get< Vector4 >() );
- break;
- }
-
- case Toolkit::Control::Property::BACKGROUND_IMAGE:
- {
- DALI_LOG_WARNING( "BACKGROUND_IMAGE property is deprecated. Use BACKGROUND property instead\n" );
- Image image = Scripting::NewImage( value );
- if ( image )
- {
- controlImpl.SetBackgroundImage( image );
- }
- else
- {
- // An empty image means the background is no longer required
- controlImpl.ClearBackground();
- }
- break;
- }
-
- case Toolkit::Control::Property::KEY_INPUT_FOCUS:
- {
- if ( value.Get< bool >() )
- {
- controlImpl.SetKeyInputFocus();
- }
- else
- {
- controlImpl.ClearKeyInputFocus();
- }
- break;
- }
-
- case Toolkit::Control::Property::BACKGROUND:
- {
- std::string url;
- const Property::Map* map = value.GetMap();
- if( map && !map->Empty() )
- {
- controlImpl.SetBackground( *map );
- }
- else if( value.Get( url ) )
- {
- // don't know the size to load
- Toolkit::Visual::Base visual = Toolkit::VisualFactory::Get().CreateVisual( url, ImageDimensions() );
- if( visual )
- {
- controlImpl.RegisterVisual( Toolkit::Control::Property::BACKGROUND, visual );
- visual.SetDepthIndex( DepthIndex::BACKGROUND );
- }
- }
- else
- {
- // The background is an empty property map, so we should clear the background
- controlImpl.ClearBackground();
- }
- break;
- }
-
- case Toolkit::DevelControl::Property::TOOLTIP:
- {
- TooltipPtr& tooltipPtr = controlImpl.mImpl->mTooltip;
- if( ! tooltipPtr )
- {
- tooltipPtr = Tooltip::New( control );
- }
- tooltipPtr->SetProperties( value );
- }
- }
- }
- }
-
- /**
- * Called to retrieve a property of an object of this type.
- * @param[in] object The object whose property is to be retrieved.
- * @param[in] index The property index.
- * @return The current value of the property.
- */
- static Property::Value GetProperty( BaseObject* object, Property::Index index )
- {
- Property::Value value;
-
- Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
-
- if ( control )
- {
- Control& controlImpl( GetImplementation( control ) );
-
- switch ( index )
- {
- case Toolkit::Control::Property::STYLE_NAME:
- {
- value = controlImpl.GetStyleName();
- break;
- }
-
- case Toolkit::DevelControl::Property::STATE:
- {
- value = controlImpl.mImpl->mState;
- break;
- }
-
- case Toolkit::DevelControl::Property::SUB_STATE:
- {
- value = controlImpl.mImpl->mSubStateName;
- break;
- }
-
- case Toolkit::Control::Property::BACKGROUND_COLOR:
- {
- DALI_LOG_WARNING( "BACKGROUND_COLOR property is deprecated. Use BACKGROUND property instead\n" );
- value = controlImpl.GetBackgroundColor();
- break;
- }
-
- case Toolkit::Control::Property::BACKGROUND_IMAGE:
- {
- DALI_LOG_WARNING( "BACKGROUND_IMAGE property is deprecated. Use BACKGROUND property instead\n" );
- Property::Map map;
- Toolkit::Visual::Base visual = controlImpl.GetVisual( Toolkit::Control::Property::BACKGROUND );
- if( visual )
- {
- visual.CreatePropertyMap( map );
- }
- value = map;
- break;
- }
-
- case Toolkit::Control::Property::KEY_INPUT_FOCUS:
- {
- value = controlImpl.HasKeyInputFocus();
- break;
- }
-
- case Toolkit::Control::Property::BACKGROUND:
- {
- Property::Map map;
- Toolkit::Visual::Base visual = controlImpl.GetVisual( Toolkit::Control::Property::BACKGROUND );
- if( visual )
- {
- visual.CreatePropertyMap( map );
- }
-
- value = map;
- break;
- }
-
- case Toolkit::DevelControl::Property::TOOLTIP:
- {
- Property::Map map;
- if( controlImpl.mImpl->mTooltip )
- {
- controlImpl.mImpl->mTooltip->CreatePropertyMap( map );
- }
- value = map;
- break;
- }
-
- }
- }
-
- return value;
- }
-
-
- void CopyInstancedProperties( RegisteredVisualContainer& visuals, Dictionary<Property::Map>& instancedProperties )
- {
- for(RegisteredVisualContainer::Iterator iter = visuals.Begin(); iter!= visuals.End(); iter++)
- {
- if( (*iter)->visual )
- {
- Property::Map instanceMap;
- Toolkit::GetImplementation((*iter)->visual).CreateInstancePropertyMap(instanceMap);
- instancedProperties.Add( (*iter)->visual.GetName(), instanceMap );
- }
- }
- }
-
- template<typename T>
- void Remove( Dictionary<T>& keyValues, const std::string& name )
- {
- keyValues.Remove(name);
- }
-
- void Remove( DictionaryKeys& keys, const std::string& name )
- {
- DictionaryKeys::iterator iter = std::find( keys.begin(), keys.end(), name );
- if( iter != keys.end())
- {
- keys.erase(iter);
- }
- }
-
- void FindChangableVisuals( Dictionary<Property::Map>& stateVisualsToAdd,
- Dictionary<Property::Map>& stateVisualsToChange,
- DictionaryKeys& stateVisualsToRemove)
- {
- DictionaryKeys copyOfStateVisualsToRemove = stateVisualsToRemove;
-
- for( DictionaryKeys::iterator iter = copyOfStateVisualsToRemove.begin();
- iter != copyOfStateVisualsToRemove.end(); ++iter )
- {
- const std::string& visualName = (*iter);
- Property::Map* toMap = stateVisualsToAdd.Find( visualName );
- if( toMap )
- {
- stateVisualsToChange.Add( visualName, *toMap );
- stateVisualsToAdd.Remove( visualName );
- Remove( stateVisualsToRemove, visualName );
- }
- }
- }
-
- void RemoveVisual( RegisteredVisualContainer& visuals, const std::string& visualName )
- {
- Actor self( mControlImpl.Self() );
-
- for ( RegisteredVisualContainer::Iterator visualIter = visuals.Begin();
- visualIter != visuals.End(); ++visualIter )
- {
- Toolkit::Visual::Base visual = (*visualIter)->visual;
- if( visual && visual.GetName() == visualName )
- {
- Toolkit::GetImplementation(visual).SetOffStage( self );
- (*visualIter)->visual.Reset();
- visuals.Erase( visualIter );
- break;
- }
- }
- }
-
- void RemoveVisuals( RegisteredVisualContainer& visuals, DictionaryKeys& removeVisuals )
- {
- Actor self( mControlImpl.Self() );
- for( DictionaryKeys::iterator iter = removeVisuals.begin(); iter != removeVisuals.end(); ++iter )
- {
- const std::string visualName = *iter;
- RemoveVisual( visuals, visualName );
- }
- }
-
- Toolkit::Visual::Type GetVisualTypeFromMap( const Property::Map& map )
- {
- Property::Value* typeValue = map.Find( Toolkit::Visual::Property::TYPE, VISUAL_TYPE );
- Toolkit::Visual::Type type = Toolkit::Visual::IMAGE;
- if( typeValue )
- {
- Scripting::GetEnumerationProperty( *typeValue, VISUAL_TYPE_TABLE, VISUAL_TYPE_TABLE_COUNT, type );
- }
- return type;
- }
-
- /**
- * Go through the list of visuals that are common to both states.
- * If they are different types, or are both image types with different
- * URLs, then the existing visual needs moving and the new visual creating
- */
- void RecreateChangedVisuals( Dictionary<Property::Map>& stateVisualsToChange,
- Dictionary<Property::Map>& instancedProperties )
- {
- Dali::CustomActor handle( mControlImpl.GetOwner() );
- for( Dictionary<Property::Map>::iterator iter = stateVisualsToChange.Begin();
- iter != stateVisualsToChange.End(); ++iter )
- {
- const std::string& visualName = (*iter).key;
- const Property::Map& toMap = (*iter).entry;
-
- // is it a candidate for re-creation?
- bool recreate = false;
-
- Toolkit::Visual::Base visual = GetVisualByName( mVisuals, visualName );
- if( visual )
- {
- Property::Map fromMap;
- visual.CreatePropertyMap( fromMap );
-
- Toolkit::Visual::Type fromType = GetVisualTypeFromMap( fromMap );
- Toolkit::Visual::Type toType = GetVisualTypeFromMap( toMap );
-
- if( fromType != toType )
- {
- recreate = true;
- }
- else
- {
- if( fromType == Toolkit::Visual::IMAGE )
- {
- Property::Value* fromUrl = fromMap.Find( Toolkit::ImageVisual::Property::URL, IMAGE_URL_NAME );
- Property::Value* toUrl = toMap.Find( Toolkit::ImageVisual::Property::URL, IMAGE_URL_NAME );
-
- if( fromUrl && toUrl )
- {
- std::string fromUrlString;
- std::string toUrlString;
- fromUrl->Get(fromUrlString);
- toUrl->Get(toUrlString);
-
- if( fromUrlString != toUrlString )
- {
- recreate = true;
- }
- }
- }
- }