Removed some redundant methods from TextController & Moved some code to other files
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / text-controller.h
index 109be1a..a582110 100644 (file)
@@ -25,6 +25,7 @@
 // INTERNAL INCLUDES
 #include <dali-toolkit/devel-api/controls/text-controls/text-label-devel.h>
 #include <dali-toolkit/devel-api/controls/text-controls/text-selection-popup-callback-interface.h>
+#include <dali-toolkit/devel-api/controls/text-controls/text-anchor-devel.h>
 #include <dali-toolkit/devel-api/text/text-enumerations-devel.h>
 #include <dali-toolkit/internal/text/decorator/text-decorator.h>
 #include <dali-toolkit/internal/text/hidden-text.h>
 #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;
@@ -170,7 +167,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.
@@ -179,7 +179,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.
@@ -194,7 +197,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.
   /**
@@ -474,6 +483,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.
    */
@@ -1606,18 +1636,6 @@ 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);
@@ -1633,6 +1651,21 @@ 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();
@@ -1713,6 +1746,22 @@ public: // Text-input Event Queuing.
    */
   CharacterIndex GetCursorPosition();
 
+  /**
+   * @brief Resets a provided vector with actors that marks the position of anchors in markup enabled text
+   *
+   * @param[out] anchorActors the vector of actor (empty collection if no anchors available).
+   */
+  void GetAnchorActors(std::vector<Toolkit::TextAnchor>& anchorActors);
+
+  /**
+   * @brief Return an index of first anchor in the anchor vector whose boundaries includes given character offset
+   *
+   * @param[in] characterOffset A position in text coords.
+   *
+   * @return the index in anchor vector (-1 if an anchor not found)
+   */
+  int GetAnchorIndex(size_t characterOffset);
+
 protected: // Inherit from Text::Decorator::ControllerInterface.
   /**
    * @copydoc Dali::Toolkit::Text::Decorator::ControllerInterface::GetTargetSize()
@@ -1741,154 +1790,22 @@ protected: // Inherit from HiddenText.
    */
   void DisplayTimeExpired() override;
 
-private: // Update.
-  /**
-   * @brief Called by editable UI controls when key events are received.
-   *
-   * @param[in] text The text to insert.
-   * @param[in] type Used to distinguish between regular key events and InputMethodContext events.
-   */
-  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
-   */
-  void PasteText(const std::string& stringToPaste);
-
-  /**
-   * @brief Remove a given number of characters
-   *
-   * When predictve text is used the pre-edit text is removed and inserted again with the new characters.
-   * The UpdateInputStyleType @type parameter if set to DONT_UPDATE_INPUT_STYLE avoids to update the input
-   * style when pre-edit text is removed.
-   *
-   * @param[in] cursorOffset Start position from the current cursor position to start deleting characters.
-   * @param[in] numberOfCharacters The number of characters to delete from the cursorOffset.
-   * @param[in] type Whether to update the input style.
-   * @return True if the remove was successful.
-   */
-  bool RemoveText(int                  cursorOffset,
-                  int                  numberOfCharacters,
-                  UpdateInputStyleType type);
-
-  /**
-   * @brief Checks if text is selected and if so removes it.
-   * @return true if text was removed
-   */
-  bool RemoveSelectedText();
-
-  /**
-   * @brief Update anchor position from given number of inserted characters.
-   *
-   * @param[in] numberOfCharacters The number of inserted characters.
-   * @param[in] previousCursorIndex A cursor position before event occurs.
-   */
-  void InsertTextAnchor(int            numberOfCharacters,
-                        CharacterIndex previousCursorIndex);
-
-  /**
-   * @brief Update anchor position from given number of removed characters.
-   *
-   * @param[in] cursorOffset Start position from the current cursor position to start deleting characters.
-   * @param[in] numberOfCharacters The number of removed characters.
-   * @param[in] previousCursorIndex A cursor position before event occurs.
-   */
-  void RemoveTextAnchor(int            cursorOffset,
-                        int            numberOfCharacters,
-                        CharacterIndex previousCursorIndex);
-
-private: // Relayout.
-  /**
-   * @brief Lays-out the text.
-   *
-   * GetNaturalSize(), GetHeightForWidth() and Relayout() calls this method.
-   *
-   * @param[in] size A the size of a bounding box to layout text within.
-   * @param[in] operations The layout operations which need to be done.
-   * @param[out] layoutSize The size of the laid-out text.
-   */
-  bool DoRelayout(const Size&    size,
-                  OperationsMask operations,
-                  Size&          layoutSize);
-
-  /**
-   * @brief Calulates the vertical offset to align the text inside the bounding box.
-   *
-   * @param[in] size The size of the bounding box.
-   */
-  void CalculateVerticalOffset(const Size& size);
-
-private: // Events.
-  /**
-   * @brief Process queued events which modify the model.
-   */
-  void ProcessModifyEvents();
-
-  /**
-   * @brief Used to process an event queued from SetText()
-   */
-  void TextReplacedEvent();
-
-  /**
-   * @brief Used to process an event queued from key events etc.
-   */
-  void TextInsertedEvent();
-
-  /**
-   * @brief Used to process an event queued from backspace key etc.
-   */
-  void TextDeletedEvent();
-
-  /**
-   * @brief Helper to KeyEvent() to handle the backspace or delete key case.
-   *
-   * @param[in] keyCode The keycode for the key pressed
-   * @return True if a character was deleted.
-   */
-  bool DeleteEvent(int keyCode);
-
-private: // Helpers.
-  /**
-   * @brief Used to remove the text included the placeholder text.
-   */
-  void ResetText();
-
-  /**
-   * @brief Helper to show the place holder text..
-   */
-  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();
-
-  /**
-   * @brief fill needed relayout parameters when line size is changed & request relayout.
-   */
-  void RelayoutForNewLineSize();
-
 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.
@@ -1898,11 +1815,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.
   /**
@@ -1916,6 +1830,7 @@ public:
 private:
   struct EventHandler;
   struct InputFontHandler;
+  struct InputProperties;
   struct PlaceholderHandler;
   struct Relayouter;
   struct TextUpdater;
@@ -1923,10 +1838,6 @@ private:
   Impl* mImpl;
 };
 
-} // namespace Text
-
-} // namespace Toolkit
-
-} // namespace Dali
+} // namespace Dali::Toolkit::Text
 
 #endif // DALI_TOOLKIT_TEXT_CONTROLLER_H