Cleaning up the property framework; removal of duplicate methods and incorrect assers
[platform/core/uifw/dali-core.git] / dali / internal / event / actors / actor-impl.cpp
index fcb0680..d9a67fe 100644 (file)
@@ -42,7 +42,6 @@
 #include <dali/internal/event/animation/constraint-impl.h>
 #include <dali/internal/event/common/projection.h>
 #include <dali/internal/update/common/animatable-property.h>
-#include <dali/internal/update/common/property-owner-messages.h>
 #include <dali/internal/update/nodes/node-messages.h>
 #include <dali/internal/update/nodes/node-declarations.h>
 #include <dali/internal/update/animation/scene-graph-constraint.h>
@@ -61,8 +60,6 @@ using Dali::Internal::SceneGraph::Node;
 using Dali::Internal::SceneGraph::AnimatableProperty;
 using Dali::Internal::SceneGraph::PropertyBase;
 
-using namespace std;
-
 namespace Dali
 {
 
@@ -209,17 +206,16 @@ BaseHandle CreateActor()
 TypeRegistration mType( typeid(Dali::Actor), typeid(Dali::Handle), CreateActor );
 
 SignalConnectorType signalConnector1(mType, Dali::Actor::SIGNAL_TOUCHED,    &Actor::DoConnectSignal);
-SignalConnectorType signalConnector2(mType, Dali::Actor::SIGNAL_SET_SIZE,   &Actor::DoConnectSignal);
-SignalConnectorType signalConnector3(mType, Dali::Actor::SIGNAL_ON_STAGE,   &Actor::DoConnectSignal);
-SignalConnectorType signalConnector4(mType, Dali::Actor::SIGNAL_OFF_STAGE,  &Actor::DoConnectSignal);
+SignalConnectorType signalConnector2(mType, Dali::Actor::SIGNAL_HOVERED,    &Actor::DoConnectSignal);
+SignalConnectorType signalConnector3(mType, Dali::Actor::SIGNAL_SET_SIZE,   &Actor::DoConnectSignal);
+SignalConnectorType signalConnector4(mType, Dali::Actor::SIGNAL_ON_STAGE,   &Actor::DoConnectSignal);
+SignalConnectorType signalConnector5(mType, Dali::Actor::SIGNAL_OFF_STAGE,  &Actor::DoConnectSignal);
 
 TypeAction a1(mType, Dali::Actor::ACTION_SHOW, &Actor::DoAction);
 TypeAction a2(mType, Dali::Actor::ACTION_HIDE, &Actor::DoAction);
 
 }
 
-Actor::DefaultPropertyLookup* Actor::mDefaultPropertyLookup = NULL;
-
 ActorPtr Actor::New()
 {
   ActorPtr actor( new Actor( BASIC ) );
@@ -353,7 +349,7 @@ void Actor::Insert(unsigned int index, Actor& child)
   if ( !child.mParent )
   {
     // Do this first, since user callbacks from within SetParent() may need to remove child
-    if (index < child.GetChildCount())
+    if (index < GetChildCount())
     {
       ActorIter it = mChildren->begin();
       std::advance(it, index);
@@ -1863,6 +1859,11 @@ bool Actor::GetTouchRequired() const
   return !mTouchedSignalV2.Empty() || mDerivedRequiresTouch;
 }
 
+bool Actor::GetHoverRequired() const
+{
+  return !mHoveredSignalV2.Empty() || mDerivedRequiresHover;
+}
+
 bool Actor::GetMouseWheelEventRequired() const
 {
   return !mMouseWheelEventSignalV2.Empty() || mDerivedRequiresMouseWheelEvent;
@@ -1911,6 +1912,25 @@ bool Actor::EmitTouchEventSignal(const TouchEvent& event)
   return consumed;
 }
 
+bool Actor::EmitHoverEventSignal(const HoverEvent& event)
+{
+  bool consumed = false;
+
+  if ( !mHoveredSignalV2.Empty() )
+  {
+    Dali::Actor handle( this );
+    consumed = mHoveredSignalV2.Emit( handle, event );
+  }
+
+  if (!consumed)
+  {
+    // Notification for derived classes
+    consumed = OnHoverEvent( event );
+  }
+
+  return consumed;
+}
+
 bool Actor::EmitMouseWheelEventSignal(const MouseWheelEvent& event)
 {
   bool consumed = false;
@@ -1935,6 +1955,11 @@ Dali::Actor::TouchSignalV2& Actor::TouchedSignal()
   return mTouchedSignalV2;
 }
 
+Dali::Actor::HoverSignalV2& Actor::HoveredSignal()
+{
+  return mHoveredSignalV2;
+}
+
 Dali::Actor::MouseWheelEventSignalV2& Actor::MouseWheelEventSignal()
 {
   return mMouseWheelEventSignalV2;
@@ -1964,6 +1989,10 @@ bool Actor::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tra
   {
     actor->TouchedSignal().Connect( tracker, functor );
   }
+  else if(Dali::Actor::SIGNAL_HOVERED == signalName)
+  {
+    actor->HoveredSignal().Connect( tracker, functor );
+  }
   else if(Dali::Actor::SIGNAL_MOUSE_WHEEL_EVENT == signalName)
   {
     actor->MouseWheelEventSignal().Connect( tracker, functor );
@@ -2013,6 +2042,7 @@ Actor::Actor( DerivedType derivedType )
   mLeaveRequired( false ),
   mKeyboardFocusable( false ),
   mDerivedRequiresTouch( false ),
+  mDerivedRequiresHover( false ),
   mDerivedRequiresMouseWheelEvent( false ),
   mOnStageSignalled( false ),
   mInheritRotation( true ),
@@ -2033,16 +2063,6 @@ void Actor::Initialize()
   AddNodeMessage( mStage->GetUpdateManager(), *node ); // Pass ownership to scene-graph
   mNode = node; // Keep raw-pointer to Node
 
-  if(!mDefaultPropertyLookup)
-  {
-    mDefaultPropertyLookup = new DefaultPropertyLookup();
-
-    for (int i=0; i<DEFAULT_PROPERTY_COUNT; ++i)
-    {
-      (*mDefaultPropertyLookup)[DEFAULT_PROPERTY_DETAILS[i].name] = i;
-    }
-  }
-
   OnInitialize();
 
   RegisterObject();
@@ -2299,11 +2319,6 @@ bool Actor::IsNodeConnected() const
   return connected;
 }
 
-bool Actor::IsSceneObjectRemovable() const
-{
-  return false;
-}
-
 unsigned int Actor::GetDefaultPropertyCount() const
 {
   return DEFAULT_PROPERTY_COUNT;
@@ -2319,7 +2334,7 @@ void Actor::GetDefaultPropertyIndices( Property::IndexContainer& indices ) const
   }
 }
 
-const std::string& Actor::GetDefaultPropertyName( Property::Index index ) const
+const char* Actor::GetDefaultPropertyName( Property::Index index ) const
 {
   if( index < DEFAULT_PROPERTY_COUNT )
   {
@@ -2327,8 +2342,7 @@ const std::string& Actor::GetDefaultPropertyName( Property::Index index ) const
   }
   else
   {
-    // index out of range..return empty string
-    return String::EMPTY;
+    return NULL;
   }
 }
 
@@ -2336,13 +2350,15 @@ Property::Index Actor::GetDefaultPropertyIndex(const std::string& name) const
 {
   Property::Index index = Property::INVALID_INDEX;
 
-  DALI_ASSERT_DEBUG( NULL != mDefaultPropertyLookup );
-
   // Look for name in default properties
-  DefaultPropertyLookup::const_iterator result = mDefaultPropertyLookup->find( name );
-  if ( mDefaultPropertyLookup->end() != result )
+  for( int i = 0; i < DEFAULT_PROPERTY_COUNT; ++i )
   {
-    index = result->second;
+    const Internal::PropertyDetails* property = &DEFAULT_PROPERTY_DETAILS[ i ];
+    if( 0 == strcmp( name.c_str(), property->name ) ) // dont want to convert rhs to string
+    {
+      index = i;
+      break;
+    }
   }
 
   return index;
@@ -2613,105 +2629,122 @@ void Actor::SetDefaultProperty( Property::Index index, const Property::Value& pr
 
     default:
     {
-      DALI_ASSERT_ALWAYS(false && "Actor::Property is out of bounds"); // should not come here
+      // this can happen in the case of a non-animatable default property so just do nothing
       break;
     }
   }
 }
 
-void Actor::SetCustomProperty( Property::Index index, const CustomProperty& entry, const Property::Value& value )
+// TODO: This method needs to be removed
+void Actor::SetSceneGraphProperty( Property::Index index, const CustomProperty& entry, const Property::Value& value )
 {
-  // TODO: This should be deprecated
   OnPropertySet(index, value);
 
-  if(entry.IsAnimatable())
+  switch ( entry.type )
   {
-    // TODO: ADD MATRIX & MATRIX3 types
+    case Property::BOOLEAN:
+    {
+      const AnimatableProperty<bool>* property = dynamic_cast< const AnimatableProperty<bool>* >( entry.GetSceneGraphProperty() );
+      DALI_ASSERT_DEBUG( NULL != property );
+
+      // property is being used in a separate thread; queue a message to set the property
+      SceneGraph::NodePropertyMessage<bool>::Send( mStage->GetUpdateManager(), mNode, property, &AnimatableProperty<bool>::Bake, value.Get<bool>() );
 
-    switch ( entry.type )
+      break;
+    }
+
+    case Property::FLOAT:
     {
-      case Property::BOOLEAN:
-      {
-        AnimatableProperty<bool>* property = dynamic_cast< AnimatableProperty<bool>* >( entry.GetSceneGraphProperty() );
-        DALI_ASSERT_DEBUG( NULL != property );
+      const AnimatableProperty<float>* property = dynamic_cast< const AnimatableProperty<float>* >( entry.GetSceneGraphProperty() );
+      DALI_ASSERT_DEBUG( NULL != property );
 
-        // property is being used in a separate thread; queue a message to set the property
-        SceneGraph::NodePropertyMessage<bool>::Send( mStage->GetUpdateManager(), mNode, property, &AnimatableProperty<bool>::Bake, value.Get<bool>() );
+      // property is being used in a separate thread; queue a message to set the property
+      SceneGraph::NodePropertyMessage<float>::Send( mStage->GetUpdateManager(), mNode, property, &AnimatableProperty<float>::Bake, value.Get<float>() );
 
-        break;
-      }
+      break;
+    }
 
-      case Property::FLOAT:
-      {
-        AnimatableProperty<float>* property = dynamic_cast< AnimatableProperty<float>* >( entry.GetSceneGraphProperty() );
-        DALI_ASSERT_DEBUG( NULL != property );
+    case Property::INTEGER:
+    {
+      const AnimatableProperty<int>* property = dynamic_cast< const AnimatableProperty<int>* >( entry.GetSceneGraphProperty() );
+      DALI_ASSERT_DEBUG( NULL != property );
 
-        // property is being used in a separate thread; queue a message to set the property
-        SceneGraph::NodePropertyMessage<float>::Send( mStage->GetUpdateManager(), mNode, property, &AnimatableProperty<float>::Bake, value.Get<float>() );
+      // property is being used in a separate thread; queue a message to set the property
+      SceneGraph::NodePropertyMessage<int>::Send( mStage->GetUpdateManager(), mNode, property, &AnimatableProperty<int>::Bake, value.Get<int>() );
 
-        break;
-      }
+      break;
+    }
 
-      case Property::INTEGER:
-      {
-        AnimatableProperty<int>* property = dynamic_cast< AnimatableProperty<int>* >( entry.GetSceneGraphProperty() );
-        DALI_ASSERT_DEBUG( NULL != property );
+    case Property::VECTOR2:
+    {
+      const AnimatableProperty<Vector2>* property = dynamic_cast< const AnimatableProperty<Vector2>* >( entry.GetSceneGraphProperty() );
+      DALI_ASSERT_DEBUG( NULL != property );
 
-        // property is being used in a separate thread; queue a message to set the property
-        SceneGraph::NodePropertyMessage<int>::Send( mStage->GetUpdateManager(), mNode, property, &AnimatableProperty<int>::Bake, value.Get<int>() );
+      // property is being used in a separate thread; queue a message to set the property
+      SceneGraph::NodePropertyMessage<Vector2>::Send( mStage->GetUpdateManager(), mNode, property, &AnimatableProperty<Vector2>::Bake, value.Get<Vector2>() );
 
-        break;
-      }
+      break;
+    }
 
-      case Property::VECTOR2:
-      {
-        AnimatableProperty<Vector2>* property = dynamic_cast< AnimatableProperty<Vector2>* >( entry.GetSceneGraphProperty() );
-        DALI_ASSERT_DEBUG( NULL != property );
+    case Property::VECTOR3:
+    {
+      const AnimatableProperty<Vector3>* property = dynamic_cast< const AnimatableProperty<Vector3>* >( entry.GetSceneGraphProperty() );
+      DALI_ASSERT_DEBUG( NULL != property );
 
-        // property is being used in a separate thread; queue a message to set the property
-        SceneGraph::NodePropertyMessage<Vector2>::Send( mStage->GetUpdateManager(), mNode, property, &AnimatableProperty<Vector2>::Bake, value.Get<Vector2>() );
+      // property is being used in a separate thread; queue a message to set the property
+      SceneGraph::NodePropertyMessage<Vector3>::Send( mStage->GetUpdateManager(), mNode, property, &AnimatableProperty<Vector3>::Bake, value.Get<Vector3>() );
 
-        break;
-      }
+      break;
+    }
 
-      case Property::VECTOR3:
-      {
-        AnimatableProperty<Vector3>* property = dynamic_cast< AnimatableProperty<Vector3>* >( entry.GetSceneGraphProperty() );
-        DALI_ASSERT_DEBUG( NULL != property );
+    case Property::VECTOR4:
+    {
+      const AnimatableProperty<Vector4>* property = dynamic_cast< const AnimatableProperty<Vector4>* >( entry.GetSceneGraphProperty() );
+      DALI_ASSERT_DEBUG( NULL != property );
 
-        // property is being used in a separate thread; queue a message to set the property
-        SceneGraph::NodePropertyMessage<Vector3>::Send( mStage->GetUpdateManager(), mNode, property, &AnimatableProperty<Vector3>::Bake, value.Get<Vector3>() );
+      // property is being used in a separate thread; queue a message to set the property
+      SceneGraph::NodePropertyMessage<Vector4>::Send( mStage->GetUpdateManager(), mNode, property, &AnimatableProperty<Vector4>::Bake, value.Get<Vector4>() );
 
-        break;
-      }
+      break;
+    }
 
-      case Property::VECTOR4:
-      {
-        AnimatableProperty<Vector4>* property = dynamic_cast< AnimatableProperty<Vector4>* >( entry.GetSceneGraphProperty() );
-        DALI_ASSERT_DEBUG( NULL != property );
+    case Property::ROTATION:
+    {
+      const AnimatableProperty<Quaternion>* property = dynamic_cast< const AnimatableProperty<Quaternion>* >( entry.GetSceneGraphProperty() );
+      DALI_ASSERT_DEBUG( NULL != property );
 
-        // property is being used in a separate thread; queue a message to set the property
-        SceneGraph::NodePropertyMessage<Vector4>::Send( mStage->GetUpdateManager(), mNode, property, &AnimatableProperty<Vector4>::Bake, value.Get<Vector4>() );
+      // property is being used in a separate thread; queue a message to set the property
+      SceneGraph::NodePropertyMessage<Quaternion>::Send( mStage->GetUpdateManager(), mNode, property,&AnimatableProperty<Quaternion>::Bake,  value.Get<Quaternion>() );
 
-        break;
-      }
+      break;
+    }
 
-      case Property::ROTATION:
-      {
-        AnimatableProperty<Quaternion>* property = dynamic_cast< AnimatableProperty<Quaternion>* >( entry.GetSceneGraphProperty() );
-        DALI_ASSERT_DEBUG( NULL != property );
+    case Property::MATRIX:
+    {
+      const AnimatableProperty<Matrix>* property = dynamic_cast< const AnimatableProperty<Matrix>* >( entry.GetSceneGraphProperty() );
+      DALI_ASSERT_DEBUG( NULL != property );
 
-        // property is being used in a separate thread; queue a message to set the property
-        SceneGraph::NodePropertyMessage<Quaternion>::Send( mStage->GetUpdateManager(), mNode, property,&AnimatableProperty<Quaternion>::Bake,  value.Get<Quaternion>() );
+      // property is being used in a separate thread; queue a message to set the property
+      SceneGraph::NodePropertyMessage<Matrix>::Send( mStage->GetUpdateManager(), mNode, property,&AnimatableProperty<Matrix>::Bake,  value.Get<Matrix>() );
 
-        break;
-      }
+      break;
+    }
 
-      default:
-      {
-        DALI_ASSERT_ALWAYS( false && "Property type enumeration out of bounds" ); // should not come here
-        break;
-      }
+    case Property::MATRIX3:
+    {
+      const AnimatableProperty<Matrix3>* property = dynamic_cast< const AnimatableProperty<Matrix3>* >( entry.GetSceneGraphProperty() );
+      DALI_ASSERT_DEBUG( NULL != property );
+
+      // property is being used in a separate thread; queue a message to set the property
+      SceneGraph::NodePropertyMessage<Matrix3>::Send( mStage->GetUpdateManager(), mNode, property,&AnimatableProperty<Matrix3>::Bake,  value.Get<Matrix3>() );
+
+      break;
+    }
+
+    default:
+    {
+      DALI_ASSERT_ALWAYS( false && "Property type enumeration out of bounds" ); // should not come here
+      break;
     }
   }
 }
@@ -2990,13 +3023,9 @@ Property::Value Actor::GetDefaultProperty(Property::Index index) const
   return value;
 }
 
-void Actor::InstallSceneObjectProperty( PropertyBase& newProperty, const std::string& name, unsigned int index )
+const SceneGraph::PropertyOwner* Actor::GetPropertyOwner() const
 {
-  if( NULL != mNode )
-  {
-    // mNode is being used in a separate thread; queue a message to add the property
-    InstallCustomPropertyMessage( mStage->GetUpdateInterface(), *mNode, newProperty ); // Message takes ownership
-  }
+  return mNode;
 }
 
 const SceneGraph::PropertyOwner* Actor::GetSceneObject() const
@@ -3019,11 +3048,10 @@ const PropertyBase* Actor::GetSceneObjectAnimatableProperty( Property::Index ind
 
   if ( static_cast<unsigned int>(index) >= DEFAULT_PROPERTY_MAX_COUNT )
   {
-    CustomPropertyLookup::const_iterator entry = GetCustomPropertyLookup().find( index );
+    CustomProperty* custom = FindCustomProperty( index );
+    DALI_ASSERT_ALWAYS( custom && "Property index is invalid" );
 
-    DALI_ASSERT_ALWAYS( GetCustomPropertyLookup().end() != entry && "index is invalid" );
-
-    property = dynamic_cast<const PropertyBase*>( entry->second.GetSceneGraphProperty() );
+    property = custom->GetSceneGraphProperty();
   }
   else if( NULL != mNode )
   {
@@ -3125,11 +3153,9 @@ const PropertyInputImpl* Actor::GetSceneObjectInputProperty( Property::Index ind
 
   if ( index >= DEFAULT_PROPERTY_MAX_COUNT )
   {
-    CustomPropertyLookup::const_iterator entry = GetCustomPropertyLookup().find( index );
-
-    DALI_ASSERT_ALWAYS( GetCustomPropertyLookup().end() != entry && "property index is invalid" );
-
-    property = entry->second.GetSceneGraphProperty();
+    CustomProperty* custom = FindCustomProperty( index );
+    DALI_ASSERT_ALWAYS( custom && "Property index is invalid" );
+    property = custom->GetSceneGraphProperty();
   }
   else if( NULL != mNode )
   {