Merge "Add a callback to get textfitted font size." into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / text-controller.h
index 63a77a4..a5bc8b4 100644 (file)
 #include <dali-toolkit/internal/text/text-selectable-control-interface.h>
 #include <dali-toolkit/public-api/text/text-enumerations.h>
 
-namespace Dali
-{
-namespace Toolkit
-{
-namespace Text
+namespace Dali::Toolkit::Text
 {
 class Controller;
 class ControlInterface;
@@ -52,9 +48,10 @@ class RenderingController;
    */
 enum SelectionType
 {
-  INTERACTIVE = 0x0000,
-  ALL         = 0x0001,
-  NONE        = 0x0002
+  INTERACTIVE = 0x0000, ///< Select the word where the cursor is located.
+  ALL         = 0x0001, ///< Select the whole text.
+  NONE        = 0x0002, ///< Unselect the whole text.
+  RANGE       = 0x0003  ///< Select the range text.
 };
 
 typedef IntrusivePtr<Controller> ControllerPtr;
@@ -169,7 +166,10 @@ public: // Constructor.
    *
    * @return A pointer to a new Controller.
    */
-  static ControllerPtr New();
+  static ControllerPtr New()
+  {
+    return ControllerPtr(new Controller());
+  }
 
   /**
    * @brief Create a new instance of a Controller.
@@ -178,7 +178,10 @@ public: // Constructor.
    *
    * @return A pointer to a new Controller.
    */
-  static ControllerPtr New(ControlInterface* controlInterface);
+  static ControllerPtr New(ControlInterface* controlInterface)
+  {
+    return ControllerPtr(new Controller(controlInterface));
+  }
 
   /**
    * @brief Create a new instance of a Controller.
@@ -193,7 +196,13 @@ public: // Constructor.
   static ControllerPtr New(ControlInterface*           controlInterface,
                            EditableControlInterface*   editableControlInterface,
                            SelectableControlInterface* selectableControlInterface,
-                           AnchorControlInterface*     anchorControlInterface);
+                           AnchorControlInterface*     anchorControlInterface)
+  {
+    return ControllerPtr(new Controller(controlInterface,
+                                        editableControlInterface,
+                                        selectableControlInterface,
+                                        anchorControlInterface));
+  }
 
 public: // Configure the text controller.
   /**
@@ -473,6 +482,27 @@ public: // Configure the text controller.
   Vector2 GetTextFitContentSize() const;
 
   /**
+   * @brief Retrieve the fited point size.
+   *
+   * @return The fited point size.
+   */
+  float GetTextFitPointSize() const;
+
+  /**
+   * @brief Sets whether the text fit properties have changed.
+   *
+   * @param[in] changed Whether to changed the text fit.
+   */
+  void SetTextFitChanged(bool changed);
+
+  /**
+   * @brief Whether the text fit properties are changed or not.
+   *
+   * @return True if the text fit properties are changed
+   */
+  bool IsTextFitChanged() const;
+
+  /**
    * @brief Enable or disable the placeholder text elide.
    * @param enabled Whether to enable the placeholder text elide.
    */
@@ -1588,9 +1618,10 @@ public: // Text-input Event Queuing.
    * @brief Used to set the Primary cursor position.
    *
    * @param[in] index for the Primary cursor position.
+   * @param[in] focused true if UI control has gained focus to receive key event, false otherwise.
    * @return[in] true if cursor position changed, false otherwise.
    */
-  bool SetPrimaryCursorPosition(CharacterIndex index);
+  bool SetPrimaryCursorPosition(CharacterIndex index, bool focused);
 
   /**
    * @brief Creates a selection event.
@@ -1604,6 +1635,18 @@ public: // Text-input Event Queuing.
   void SelectEvent(float x, float y, SelectionType selection);
 
   /**
+   * @brief Creates a selection event with a selection index.
+   *
+   * It could be called from the SelectText().
+   * The start and end parameters are passed through the event.
+   *
+   * @param[in] start The start selection position.
+   * @param[in] end The end selection position.
+   * @param[in] selection type like the range.
+   */
+  void SelectEvent(const uint32_t start, const uint32_t end, SelectionType selection);
+
+  /**
    * @copydoc Text::SelectableControlInterface::SetTextSelectionRange()
    */
   void SetTextSelectionRange(const uint32_t* start, const uint32_t* end);
@@ -1619,11 +1662,31 @@ public: // Text-input Event Queuing.
   void SelectWholeText();
 
   /**
+   * @copydoc Text::EditableControlInterface::CopyText()
+   */
+  string CopyText();
+
+  /**
+   * @copydoc Text::EditableControlInterface::CutText()
+   */
+  string CutText();
+
+  /**
+   * @copydoc Text::EditableControlInterface::PasteText()
+   */
+  void PasteText();
+
+  /**
    * @copydoc Text::SelectableControlInterface::SelectNone()
    */
   void SelectNone();
 
   /**
+   * @copydoc Text::SelectableControlInterface::SelectText()
+   */
+  void SelectText(const uint32_t start, const uint32_t end);
+
+  /**
    * @copydoc Text::SelectableControlInterface::GetSelectedText()
    */
   string GetSelectedText() const;
@@ -1732,8 +1795,7 @@ private: // Update.
   void InsertText(const std::string& text, InsertType type);
 
   /**
-   * @brief Paste given string into Text model
-   * @param[in] stringToPaste this string will be inserted into the text model
+   * @copydoc Text::EditableControlInterface::PasteText()
    */
   void PasteText(const std::string& stringToPaste);
 
@@ -1840,31 +1902,22 @@ private: // Helpers.
    */
   void ShowPlaceholderText();
 
-  /**
-   * @brief Helper to clear font-specific data (only).
-   */
-  void ClearFontData();
-
-  /**
-   * @brief Helper to clear text's style data.
-   */
-  void ClearStyleData();
-
-  /**
-   * @brief Used to reset the scroll position after setting a new text.
-   */
-  void ResetScrollPosition();
-
 private: // Private contructors & copy operator.
   /**
    * @brief Private constructor.
    */
-  Controller();
+  Controller()
+  : Controller(nullptr, nullptr, nullptr, nullptr)
+  {
+  }
 
   /**
    * @brief Private constructor.
    */
-  Controller(ControlInterface* controlInterface);
+  Controller(ControlInterface* controlInterface)
+  : Controller(controlInterface, nullptr, nullptr, nullptr)
+  {
+  }
 
   /**
    * @brief Private constructor.
@@ -1874,11 +1927,8 @@ private: // Private contructors & copy operator.
              SelectableControlInterface* selectableControlInterface,
              AnchorControlInterface*     anchorControlInterface);
 
-  // Undefined
-  Controller(const Controller& handle);
-
-  // Undefined
-  Controller& operator=(const Controller& handle);
+  Controller(const Controller& handle) = delete;
+  Controller& operator=(const Controller& handle) = delete;
 
 protected: // Destructor.
   /**
@@ -1892,6 +1942,7 @@ public:
 private:
   struct EventHandler;
   struct InputFontHandler;
+  struct InputProperties;
   struct PlaceholderHandler;
   struct Relayouter;
   struct TextUpdater;
@@ -1899,10 +1950,6 @@ private:
   Impl* mImpl;
 };
 
-} // namespace Text
-
-} // namespace Toolkit
-
-} // namespace Dali
+} // namespace Dali::Toolkit::Text
 
 #endif // DALI_TOOLKIT_TEXT_CONTROLLER_H