Adding Decorator BoundingBox
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / public-api / text / decorator / text-decorator.h
index b9adf17..4038d3f 100644 (file)
@@ -21,6 +21,7 @@
 // EXTERNAL INCLUDES
 #include <dali/public-api/common/intrusive-ptr.h>
 #include <dali/public-api/object/ref-object.h>
+#include <dali/public-api/math/rect.h>
 
 namespace Dali
 {
@@ -32,7 +33,10 @@ class Vector4;
 namespace Toolkit
 {
 
-class ControlImpl;
+namespace Internal
+{
+class Control;
+}
 
 namespace Text
 {
@@ -56,23 +60,103 @@ enum ActiveCursor
   ACTIVE_CURSOR_BOTH     ///< Both primary and secondary cursor are active
 };
 
+// The state information for grab handle events
+enum GrabHandleState
+{
+  GRAB_HANDLE_TAPPED,
+  GRAB_HANDLE_PRESSED,
+  GRAB_HANDLE_RELEASED
+};
+
+// The set the selection-handle positions etc.
+enum SelectionHandle
+{
+  PRIMARY_SELECTION_HANDLE,
+  SECONDARY_SELECTION_HANDLE,
+  SELECTION_HANDLE_COUNT
+};
+
+enum SelectionHandleState
+{
+  SELECTION_HANDLE_PRESSED,
+  SELECTION_HANDLE_RELEASED
+};
+
 /**
  * @brief A Text Decorator is used to display cursors, handles, selection highlights and pop-ups.
  *
  * The decorator is responsible for clipping decorations which are positioned outside of the parent area.
  * In some cases the decorations will be moved or flipped around, to maintain visibility on-screen.
+ *
+ * Decorator components forward input events to a controller class through an observer interface.
+ * The controller is responsible for selecting which components are active.
  */
 class Decorator : public RefObject
 {
 public:
 
+  class Observer
+  {
+  public:
+
+    /**
+     * @brief Constructor.
+     */
+    Observer() {};
+
+    /**
+     * @brief Virtual destructor.
+     */
+    virtual ~Observer() {};
+
+    /**
+     * @brief An input event from the grab handle.
+     *
+     * @param[in] state The grab handle state.
+     * @param[in] x The x position relative to the top-left of the parent control.
+     * @param[in] y The y position relative to the top-left of the parent control.
+     */
+    virtual void GrabHandleEvent( GrabHandleState state, float x, float y ) = 0;
+  };
+
   /**
    * @brief Create a new instance of a Decorator.
    *
    * @param[in] parent Decorations will be added to this parent control.
+   * @param[in] observer A class which receives input events from Decorator components.
    * @return A pointer to a new Decorator.
    */
-  static DecoratorPtr New( ControlImpl& parent );
+  static DecoratorPtr New( Dali::Toolkit::Internal::Control& parent, Observer& observer );
+
+  /**
+   * @brief Set the bounding box which handles, popup and similar decorations will not exceed.
+   *
+   * The default value is the width and height of the stage from the top left origin.
+   * If a title bar for example is on the top of the screen then the y should be the title's height and
+   * the boundary height the stage height minus the title's height.
+   * Restrictions - The boundary box should be set up with a fixed z position for the text-input and the default camera.
+   *
+   * ------------------------------------------
+   * |(x,y)                                   |
+   * |o---------------------------------------|
+   * ||                                      ||
+   * ||            Bounding Box              || boundary height
+   * ||                                      ||
+   * |----------------------------------------|
+   * ------------------------------------------
+   *               boundary width
+   *
+   * @param[in] boundingBox Vector( x coordinate, y coordinate, width, height )
+   */
+  void SetBoundingBox( const Rect<int>& boundingBox );
+
+  /**
+   * @brief Retrieve the bounding box origin and dimensions.
+   *
+   * default is set once control is added to stage, before this the return vector will be Vector4:ZERO
+   * @return Rect<int> the bounding box origin, width and height
+   */
+  const Rect<int>& GetBoundingBox() const;
 
   /**
    * @brief The decorator waits until a relayout before creating actors etc.
@@ -90,7 +174,7 @@ public:
   void SetActiveCursor( ActiveCursor activeCursor );
 
   /**
-   * @brief Sets whether a cursor should be visible.
+   * @brief Query which of the cursors are active.
    *
    * @return  Which of the cursors are active (if any).
    */
@@ -119,22 +203,21 @@ public:
   /**
    * @brief Sets the image for a cursor.
    *
-   * @param[in] cursor The cursor to set.
    * @param[in] image The image to use.
    */
-  void SetImage( Cursor cursor, Dali::Image image );
+  void SetCursorImage( Dali::Image image );
 
   /**
    * @brief Retrieves the image for a cursor.
    *
    * @return The cursor image.
    */
-  Dali::Image GetImage( Cursor cursor ) const;
+  Dali::Image GetCursorImage() const;
 
   /**
    * @brief Sets the color for a cursor.
    *
-   * @param[in] cursor The cursor to set.
+   * @param[in] cursor Whether this color is for the primary or secondary cursor.
    * @param[in] color The color to use.
    */
   void SetColor( Cursor cursor, const Dali::Vector4& color );
@@ -142,6 +225,7 @@ public:
   /**
    * @brief Retrieves the color for a cursor.
    *
+   * @param[in] cursor Whether this color is for the primary or secondary cursor.
    * @return The cursor color.
    */
   const Dali::Vector4& GetColor( Cursor cursor ) const;
@@ -184,6 +268,87 @@ public:
    */
   float GetCursorBlinkDuration() const;
 
+  /**
+   * @brief Sets whether the grab handle is active.
+   *
+   * @note The grab handle follows the cursor position set with SetPosition(Cursor, ...)
+   * @param[in] active True if the grab handle should be active.
+   */
+  void SetGrabHandleActive( bool active );
+
+  /**
+   * @brief Query whether the grab handle is active.
+   *
+   * @return True if the grab handle should be active.
+   */
+  bool IsGrabHandleActive() const;
+
+  /**
+   * @brief Sets the image for the grab handle.
+   *
+   * @param[in] image The image to use.
+   */
+  void SetGrabHandleImage( Dali::Image image );
+
+  /**
+   * @brief Retrieves the image for the grab handle.
+   *
+   * @return The grab handle image.
+   */
+  Dali::Image GetGrabHandleImage() const;
+
+  /**
+   * @brief Sets whether the selection handles and highlight are active.
+   *
+   * @param[in] active True if the selection handles and highlight are active.
+   */
+  void SetSelectionActive( bool active );
+
+  /**
+   * @brief Query whether the selection handles and highlight are active.
+   *
+   * @return True if the selection handles and highlight are active.
+   */
+  bool IsSelectionActive() const;
+
+  /**
+   * @brief Sets the position of a selection handle.
+   *
+   * @param[in] handle The handle to set.
+   * @param[in] x The x position relative to the top-left of the parent control.
+   * @param[in] y The y position relative to the top-left of the parent control.
+   * @param[in] cursorHeight The logical cursor height at this position.
+   */
+  void SetPosition( SelectionHandle handle, float x, float y, float cursorHeight );
+
+  /**
+   * @brief Retrieves the position of a selection handle.
+   *
+   * @param[in] handle The handle to get.
+   * @param[out] x The x position relative to the top-left of the parent control.
+   * @param[out] y The y position relative to the top-left of the parent control.
+   * @param[out] cursorHeight The logical cursor height at this position.
+   */
+  void GetPosition( SelectionHandle handle, float& x, float& y, float& cursorHeight ) const;
+
+  /**
+   * @brief Sets the image for one of the selection handles.
+   *
+   * @param[in] handle The selection handle.
+   * @param[in] state A different image can be set for the pressed/released states.
+   * @param[in] image The image to use.
+   */
+  void SetImage( SelectionHandle handle, SelectionHandleState state, Dali::Image image );
+
+  /**
+   * @brief Retrieves the image for a selection handle.
+   *
+   * @param[in] handle The selection handle.
+   * @param[in] state A different image can be set for the pressed/released states.
+   * @return The image.
+   */
+  Dali::Image GetImage( SelectionHandle handle, SelectionHandleState state ) const;
+
 protected:
 
   /**
@@ -196,8 +361,9 @@ private:
   /**
    * @brief Private constructor.
    * @param[in] parent Decorations will be added to this parent control.
+   * @param[in] observer A class which receives input events from Decorator components.
    */
-  Decorator(ControlImpl& parent);
+  Decorator(Dali::Toolkit::Internal::Control& parent, Observer& observer );
 
   // Undefined
   Decorator( const Decorator& handle );