Cleaning up the property framework; removal of duplicate methods and incorrect assers
[platform/core/uifw/dali-core.git] / dali / internal / event / actors / actor-impl.h
index d694054..74ad86e 100644 (file)
@@ -1,31 +1,32 @@
 #ifndef __DALI_INTERNAL_ACTOR_H__
 #define __DALI_INTERNAL_ACTOR_H__
 
-//
-// Copyright (c) 2014 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Flora License, Version 1.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//     http://floralicense.org/license/
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an AS IS BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
 
 // EXTERNAL INCLUDES
 #include <string>
 
 // INTERNAL INCLUDES
-#include <dali/public-api/common/map-wrapper.h>
 #include <dali/public-api/common/vector-wrapper.h>
 #include <dali/public-api/object/ref-object.h>
 #include <dali/public-api/actors/actor.h>
 #include <dali/public-api/common/dali-common.h>
+#include <dali/public-api/events/gesture.h>
 #include <dali/public-api/math/viewport.h>
 #include <dali/internal/event/common/proxy-object.h>
 #include <dali/internal/event/common/stage-def.h>
@@ -42,18 +43,19 @@ namespace Dali
 
 struct KeyEvent;
 struct TouchEvent;
+struct HoverEvent;
 struct MouseWheelEvent;
 
 namespace Internal
 {
 
 class Actor;
+class ActorGestureData;
+class Animation;
 class RenderTask;
-class ShaderEffect;
 struct DynamicsData;
 
 typedef IntrusivePtr<Actor>                   ActorPtr;
-typedef IntrusivePtr<ShaderEffect>            ShaderEffectPtr;
 typedef Dali::ActorContainer                  ActorContainer; // Store handles to return via public-api
 typedef ActorContainer::iterator              ActorIter;
 typedef ActorContainer::const_iterator        ActorConstIter;
@@ -162,6 +164,16 @@ public:
   void Add(Actor& child);
 
   /**
+   * Inserts a child Actor to this Actor's child list
+   * @pre The child actor is not the same as the parent actor.
+   * @pre The child actor does not already have a parent.
+   * @param [in] index in childlist to insert child at
+   * @param [in] child The child.
+   * @post The child will be referenced by its parent.
+   */
+  void Insert(unsigned int index, Actor& child);
+
+  /**
    * Removes a child Actor from this Actor.
    * @param [in] child The child.
    * @post The child will be unreferenced.
@@ -284,12 +296,27 @@ public:
   void SetDepth( float depth );
 
   /**
-   * Retrieve the Actor's size.
+   * Retrieve the Actor's size from event side.
+   * This size will be the size set or if animating then the target size.
+   * @return The Actor's size.
+   */
+  const Vector3& GetSize() const;
+
+  /**
+   * Retrieve the Actor's size from update side.
+   * This size will be the size set or animating but will be a frame behind.
    * @return The Actor's size.
    */
   const Vector3& GetCurrentSize() const;
 
   /**
+   * Return the natural size of the actor
+   *
+   * @return The actor's natural size
+   */
+  virtual Vector3 GetNaturalSize() const;
+
+  /**
    * Set the origin of an actor, within its parent's area.
    * This is expressed in 2D unit coordinates, such that (0.0, 0.0, 0.5) is the top-left corner of the parent,
    * and (1.0, 1.0, 0.5) is the bottom-right corner.
@@ -581,23 +608,24 @@ public:
   float GetCurrentOpacity() const;
 
   /**
-   * Sets whether an actor should emit touch signals; see SignalTouch().
+   * Sets whether an actor should emit touch or hover signals; see SignalTouch() and SignalHover().
    * An actor is sensitive by default, which means that as soon as an application connects to the SignalTouch(),
-   * the touch event signal will be emitted.
+   * the touch event signal will be emitted, and as soon as an application connects to the SignalHover(), the
+   * hover event signal will be emitted.
    *
-   * If the application wishes to temporarily disable the touch event signal emission, then they can do so by calling:
+   * If the application wishes to temporarily disable the touch or hover event signal emission, then they can do so by calling:
    * @code
    * actor.SetSensitive(false);
    * @endcode
    *
-   * Then, to re-enable the touch event signal emission, the application should call:
+   * Then, to re-enable the touch or hover event signal emission, the application should call:
    * @code
    * actor.SetSensitive(true);
    * @endcode
    *
-   * @see SignalTouch().
-   * @note If an actor's sensitivity is set to false, then it's children will not emit a touch event signal either.
-   * @param[in]  sensitive  true to enable emission of the touch event signals, false otherwise.
+   * @see SignalTouch() and SignalHover().
+   * @note If an actor's sensitivity is set to false, then it's children will not emit a touch or hover event signal either.
+   * @param[in]  sensitive  true to enable emission of the touch or hover event signals, false otherwise.
    */
   void SetSensitive(bool sensitive)
   {
@@ -605,9 +633,9 @@ public:
   }
 
   /**
-   * Query whether an actor emits touch event signals.
+   * Query whether an actor emits touch or hover event signals.
    * @see SetSensitive(bool)
-   * @return true, if emission of touch event signals is enabled, false otherwise.
+   * @return true, if emission of touch or hover event signals is enabled, false otherwise.
    */
   bool IsSensitive() const
   {
@@ -615,38 +643,6 @@ public:
   }
 
   /**
-   * Set whether the actor inherits a shader effect from its parent.
-   * The inherited effect can be overridden using SetShaderEffect()
-   * @param [in] inherit True if the parent effect is inherited.
-   */
-  void SetInheritShaderEffect(bool inherit);
-
-  /**
-   * Query whether the actor inherits a shader effect from its parent.
-   * @return True if the parent effect is inherited.
-   */
-  bool GetInheritShaderEffect() const;
-
-  /**
-   * Sets the shader effect for the Actor.
-   * Shader effects provide special effects like rippling and bending.
-   * Setting a shader effect removes any shader effect previously set by SetShaderEffect.
-   * @param [in] effect The shader effect.
-   */
-  void SetShaderEffect(ShaderEffect& effect);
-
-  /**
-   * Retrieve the shader effect for the Actor.
-   * @return The shader effect
-   */
-  ShaderEffectPtr GetShaderEffect() const;
-
-  /**
-   * Removes the current shader effect.
-   */
-  void RemoveShaderEffect();
-
-  /**
    * @copydoc Dali::Actor::SetDrawMode
    */
   void SetDrawMode( DrawMode::Type drawMode );
@@ -894,18 +890,18 @@ public:
   bool RayActorTest( const Vector4& rayOrigin, const Vector4& rayDir, Vector4& hitPointLocal, float& distance ) const;
 
   /**
-   * Sets whether the actor should receive a notification when touch motion events leave
+   * Sets whether the actor should receive a notification when touch or hover motion events leave
    * the boundary of the actor.
    *
    * @note By default, this is set to false as most actors do not require this.
-   * @note Need to connect to the SignalTouch to actually receive this event.
+   * @note Need to connect to the SignalTouch or SignalHover to actually receive this event.
    *
    * @param[in]  required  Should be set to true if a Leave event is required
    */
   void SetLeaveRequired(bool required);
 
   /**
-   * This returns whether the actor requires touch events whenever touch motion events leave
+   * This returns whether the actor requires touch or hover events whenever touch or hover motion events leave
    * the boundary of the actor.
    * @return true if a Leave event is required, false otherwise.
    */
@@ -928,6 +924,12 @@ public:
   bool GetTouchRequired() const;
 
   /**
+   * Query whether the application or derived actor type requires hover events.
+   * @return True if hover events are required.
+   */
+  bool GetHoverRequired() const;
+
+  /**
    * Query whether the application or derived actor type requires mouse wheel events.
    * @return True if mouse wheel events are required.
    */
@@ -940,6 +942,23 @@ public:
    */
   bool IsHittable() const;
 
+  // Gestures
+
+  /**
+   * Retrieve the gesture data associated with this actor. The first call to this method will
+   * allocate space for the ActorGestureData so this should only be called if an actor really does
+   * require gestures.
+   * @return Reference to the ActorGestureData for this actor.
+   * @note Once the gesture-data is created for an actor it is likely that gestures are required
+   * throughout the actor's lifetime so it will only be deleted when the actor is destroyed.
+   */
+  ActorGestureData& GetGestureData();
+
+  /**
+   * Queries whether the actor requires the gesture type.
+   * @param[in] type The gesture type.
+   */
+  bool IsGestureRequred( Gesture::Type type ) const;
 
   // Signals
 
@@ -951,6 +970,13 @@ public:
   bool EmitTouchEventSignal(const TouchEvent& event);
 
   /**
+   * Used by the EventProcessor to emit hover event signals.
+   * @param[in] event The hover event.
+   * @return True if the event was consumed.
+   */
+  bool EmitHoverEventSignal(const HoverEvent& event);
+
+  /**
    * Used by the EventProcessor to emit mouse wheel event signals.
    * @param[in] event The mouse wheel event.
    * @return True if the event was consumed.
@@ -963,6 +989,11 @@ public:
   Dali::Actor::TouchSignalV2& TouchedSignal();
 
   /**
+   * @copydoc Dali::Actor::HoveredSignal()
+   */
+  Dali::Actor::HoverSignalV2& HoveredSignal();
+
+  /**
    * @copydoc Dali::Actor::MouseWheelEventSignal()
    */
   Dali::Actor::MouseWheelEventSignalV2& MouseWheelEventSignal();
@@ -1005,10 +1036,18 @@ public:
 public:  // For Animation
 
   /**
+   * This should only be called by Animation, when the actor is resized using Animation::Resize().
+   *
+   * @param[in] animation The animation that resized the actor
+   * @param[in] targetSize The new target size of the actor
+   */
+  void NotifySizeAnimation( Animation& animation, const Vector3& targetSize);
+
+  /**
    * For use in derived classes.
    * This should only be called by Animation, when the actor is resized using Animation::Resize().
    */
-  virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize) {}
+  virtual void OnSizeAnimation( Animation& animation, const Vector3& targetSize) {}
 
 protected:
 
@@ -1040,21 +1079,24 @@ protected:
   /**
    * Called on a child during Add() when the parent actor is connected to the Stage.
    * @param[in] stage The stage.
+   * @param[in] index If set, it is only used for positioning the actor within the parent's child list.
    */
-  void ConnectToStage(Stage& stage);
+  void ConnectToStage(Stage& stage, int index = -1);
 
   /**
    * Helper for ConnectToStage, to recursively connect a tree of actors.
    * This is atomic i.e. not interrupted by user callbacks.
    * @param[in] stage The stage.
+   * @param[in] index If set, it is only used for positioning the actor within the parent's child list.
    * @param[out] connectionList On return, the list of connected actors which require notification.
    */
-  void RecursiveConnectToStage( Stage& stage, ActorContainer& connectionList );
+  void RecursiveConnectToStage( Stage& stage, ActorContainer& connectionList, int index = -1 );
 
   /**
    * Connect the Node associated with this Actor to the scene-graph.
+   * @param[in] index If set, it is only used for positioning the actor within the parent's child list.
    */
-  void ConnectToSceneGraph();
+  void ConnectToSceneGraph(int index = -1);
 
   /**
    * Helper for ConnectToStage, to notify a connected actor through the public API.
@@ -1089,12 +1131,16 @@ protected:
    */
   bool IsNodeConnected() const;
 
-public: // Default property extensions from ProxyObject
-
   /**
-   * @copydoc Dali::Internal::ProxyObject::IsSceneObjectRemovable()
+   * Calculate the size of the z dimension for a 2D size
+   *
+   * @param[in] size The 2D size (X, Y) to calculate Z from
+   *
+   * @return Return the Z dimension for this size
    */
-  virtual bool IsSceneObjectRemovable() const;
+  float CalculateSizeZ( const Vector2& size ) const;
+
+public: // Default property extensions from ProxyObject
 
   /**
    * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyCount()
@@ -1109,7 +1155,7 @@ public: // Default property extensions from ProxyObject
   /**
    * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyName()
    */
-  virtual const std::string& GetDefaultPropertyName(Property::Index index) const;
+  virtual const char* GetDefaultPropertyName(Property::Index index) const;
 
   /**
    * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyIndex()
@@ -1142,9 +1188,9 @@ public: // Default property extensions from ProxyObject
   virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
 
   /**
-   * @copydoc Dali::Internal::ProxyObject::SetCustomProperty()
+   * @copydoc Dali::Internal::ProxyObject::SetSceneGraphProperty()
    */
-  virtual void SetCustomProperty( Property::Index index, const CustomProperty& entry, const Property::Value& value );
+  virtual void SetSceneGraphProperty( Property::Index index, const CustomProperty& entry, const Property::Value& value );
 
   /**
    * @copydoc Dali::Internal::ProxyObject::GetDefaultProperty()
@@ -1152,9 +1198,9 @@ public: // Default property extensions from ProxyObject
   virtual Property::Value GetDefaultProperty( Property::Index index ) const;
 
   /**
-   * @copydoc Dali::Internal::ProxyObject::InstallSceneObjectProperty()
+   * @copydoc Dali::Internal::ProxyObject::GetPropertyOwner()
    */
-  virtual void InstallSceneObjectProperty( SceneGraph::PropertyBase& newProperty, const std::string& name, unsigned int index );
+  virtual const SceneGraph::PropertyOwner* GetPropertyOwner() const;
 
   /**
    * @copydoc Dali::Internal::ProxyObject::GetSceneObject()
@@ -1190,8 +1236,9 @@ private:
   /**
    * Set the actors parent.
    * @param[in] parent The new parent.
+   * @param[in] index If set, it is only used for positioning the actor within the parent's child list.
    */
-  void SetParent(Actor* parent);
+  void SetParent(Actor* parent, int index = -1);
 
   /**
    * Helper to create a Node for this Actor.
@@ -1251,19 +1298,19 @@ private:
 
   /**
    * For use in derived classes.
-   * This is called after a non animatable custom property is set.
-   * @param [in] index The index of the property.
-   * @param [in] propertyValue The value of the property.
+   * This is only called if mDerivedRequiresTouch is true, and the touch-signal was not consumed.
+   * @param[in] event The touch event.
+   * @return True if the event should be consumed.
    */
-  virtual void OnPropertySet( Property::Index index, Property::Value propertyValue ) {}
+  virtual bool OnTouchEvent(const TouchEvent& event) { return false; }
 
   /**
    * For use in derived classes.
-   * This is only called if mTouchRequired is true, and the touch-signal was not consumed.
-   * @param[in] event The touch event.
+   * This is only called if mDerivedRequiresHover is true, and the hover-signal was not consumed.
+   * @param[in] event The hover event.
    * @return True if the event should be consumed.
    */
-  virtual bool OnTouchEvent(const TouchEvent& event) { return false; }
+  virtual bool OnHoverEvent(const HoverEvent& event) { return false; }
 
   /**
    * For use in derived classes.
@@ -1304,16 +1351,20 @@ protected:
   DynamicsData*           mDynamicsData; ///< optional physics data
 #endif
 
+  ActorGestureData*       mGestureData; /// Optional Gesture data. Only created when actor requires gestures
+
   ActorAttachmentPtr      mAttachment;   ///< Optional referenced attachment
-  ShaderEffectPtr         mShaderEffect; ///< Optional referenced shader effect
 
   // Signals
   Dali::Actor::TouchSignalV2             mTouchedSignalV2;
+  Dali::Actor::HoverSignalV2             mHoveredSignalV2;
   Dali::Actor::MouseWheelEventSignalV2   mMouseWheelEventSignalV2;
   Dali::Actor::SetSizeSignalV2           mSetSizeSignalV2;
   Dali::Actor::OnStageSignalV2           mOnStageSignalV2;
   Dali::Actor::OffStageSignalV2          mOffStageSignalV2;
 
+  Vector3         mSize;      ///< Event-side storage for size (not a pointer as most actors will have a size)
+
   std::string     mName;      ///< Name of the actor
   unsigned int    mId;        ///< A unique ID to identify the actor starting from 1, and 0 is reserved
 
@@ -1326,6 +1377,7 @@ protected:
   bool mLeaveRequired                              : 1; ///< Whether a touch event signal is emitted when the a touch leaves the actor's bounds
   bool mKeyboardFocusable                          : 1; ///< Whether the actor should be focusable by keyboard navigation
   bool mDerivedRequiresTouch                       : 1; ///< Whether the derived actor type requires touch event signals
+  bool mDerivedRequiresHover                       : 1; ///< Whether the derived actor type requires hover event signals
   bool mDerivedRequiresMouseWheelEvent             : 1; ///< Whether the derived actor type requires mouse wheel event signals
   bool mOnStageSignalled                           : 1; ///< Set to true before OnStageConnection signal is emitted, and false before OnStageDisconnection
   bool mInheritRotation                            : 1; ///< Cached: Whether the parent's rotation should be inherited.
@@ -1334,29 +1386,11 @@ protected:
   PositionInheritanceMode mPositionInheritanceMode : 2; ///< Cached: Determines how position is inherited
   ColorMode mColorMode                             : 2; ///< Cached: Determines whether mWorldColor is inherited
 
-  // Default properties
-  typedef std::map<std::string, Property::Index> DefaultPropertyLookup;
-
 private:
 
   static ActorContainer mNullChildren; ///< Empty container (shared by all actors, returned by GetChildren() const)
   static unsigned int   mActorCounter; ///< A counter to track the actor instance creation
 
-  // Default properties
-  static DefaultPropertyLookup* mDefaultPropertyLookup;
-
-};
-
-/**
- * @brief Structure for setting up default properties and their details.
- */
-struct PropertyDetails
-{
-  std::string name;         ///< The name of the property.
-  Property::Type type;      ///< The property type.
-  bool writable:1;          ///< Whether the property is writable
-  bool animatable:1;        ///< Whether the property is animatable.
-  bool constraintInput:1;   ///< Whether the property can be used as an input to a constraint.
 };
 
 } // namespace Internal