1 #ifndef DALI_TOOLKIT_TEXT_CONTROLLER_H
2 #define DALI_TOOLKIT_TEXT_CONTROLLER_H
5 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include <dali/devel-api/adaptor-framework/input-method-context.h>
23 #include <dali/public-api/events/gesture.h>
26 #include <dali-toolkit/devel-api/controls/text-controls/text-label-devel.h>
27 #include <dali-toolkit/devel-api/controls/text-controls/text-selection-popup-callback-interface.h>
28 #include <dali-toolkit/devel-api/controls/text-controls/text-anchor-devel.h>
29 #include <dali-toolkit/devel-api/text/text-enumerations-devel.h>
30 #include <dali-toolkit/internal/text/decorator/text-decorator.h>
31 #include <dali-toolkit/internal/text/hidden-text.h>
32 #include <dali-toolkit/internal/text/input-filter.h>
33 #include <dali-toolkit/internal/text/layouts/layout-engine.h>
34 #include <dali-toolkit/internal/text/text-anchor-control-interface.h>
35 #include <dali-toolkit/internal/text/text-model-interface.h>
36 #include <dali-toolkit/internal/text/text-selectable-control-interface.h>
37 #include <dali-toolkit/public-api/text/text-enumerations.h>
39 namespace Dali::Toolkit::Text
42 class ControlInterface;
43 class EditableControlInterface;
45 class RenderingController;
48 * @brief Text selection operations .
52 INTERACTIVE = 0x0000, ///< Select the word where the cursor is located.
53 ALL = 0x0001, ///< Select the whole text.
54 NONE = 0x0002, ///< Unselect the whole text.
55 RANGE = 0x0003 ///< Select the range text.
58 typedef IntrusivePtr<Controller> ControllerPtr;
61 * @brief A Text Controller is used by UI Controls which display text.
63 * It manipulates the Logical & Visual text models on behalf of the UI Controls.
64 * It provides a view of the text that can be used by rendering back-ends.
66 * For selectable/editable UI controls, the controller handles input events from the UI control
67 * and decorations (grab handles etc) via the Decorator::ControllerInterface interface.
69 * The text selection popup button callbacks are as well handled via the TextSelectionPopupCallbackInterface interface.
71 class Controller : public RefObject, public Decorator::ControllerInterface, public TextSelectionPopupCallbackInterface, public HiddenText::Observer
73 public: // Enumerated types.
75 * @brief Text related operations to be done in the relayout process.
79 NO_OPERATION = 0x0000,
80 CONVERT_TO_UTF32 = 0x0001,
82 VALIDATE_FONTS = 0x0004,
83 GET_LINE_BREAKS = 0x0008,
86 GET_GLYPH_METRICS = 0x0040,
88 UPDATE_LAYOUT_SIZE = 0x0100,
92 UPDATE_DIRECTION = 0x1000,
93 ALL_OPERATIONS = 0xFFFF
97 * @brief Used to distinguish between regular key events and InputMethodContext events
106 * @brief Used to specify whether to update the input style.
108 enum UpdateInputStyleType
111 DONT_UPDATE_INPUT_STYLE
115 * @brief Used to specify what has been updated after the Relayout() method has been called.
119 NONE_UPDATED = 0x0, ///< Nothing has been updated.
120 MODEL_UPDATED = 0x1, ///< The text's model has been updated.
121 DECORATOR_UPDATED = 0x2 ///< The decoration has been updated.
125 * @brief Different placeholder-text can be shown when the control is active/inactive.
129 PLACEHOLDER_TYPE_ACTIVE,
130 PLACEHOLDER_TYPE_INACTIVE,
134 * @brief Enumeration for Font Size Type.
138 POINT_SIZE, // The size of font in points.
139 PIXEL_SIZE // The size of font in pixels.
146 NO_ACTION, ///< Does no action if there is a tap on top of an area with no text.
147 HIGHLIGHT, ///< Highlights the nearest text (at the beginning or end of the text) and shows the text's selection popup.
148 SHOW_SELECTION_POPUP ///< Shows the text's selection popup.
160 TEXT_FIT_FONT_SIZE_TYPE
164 public: // Constructor.
166 * @brief Create a new instance of a Controller.
168 * @return A pointer to a new Controller.
170 static ControllerPtr New()
172 return ControllerPtr(new Controller());
176 * @brief Create a new instance of a Controller.
178 * @param[in] controlInterface The control's interface.
180 * @return A pointer to a new Controller.
182 static ControllerPtr New(ControlInterface* controlInterface)
184 return ControllerPtr(new Controller(controlInterface));
188 * @brief Create a new instance of a Controller.
190 * @param[in] controlInterface The control's interface.
191 * @param[in] editableControlInterface The editable control's interface.
192 * @param[in] selectableControlInterface The selectable control's interface.
193 * @param[in] anchorControlInterface The anchor control's interface.
195 * @return A pointer to a new Controller.
197 static ControllerPtr New(ControlInterface* controlInterface,
198 EditableControlInterface* editableControlInterface,
199 SelectableControlInterface* selectableControlInterface,
200 AnchorControlInterface* anchorControlInterface)
202 return ControllerPtr(new Controller(controlInterface,
203 editableControlInterface,
204 selectableControlInterface,
205 anchorControlInterface));
208 public: // Configure the text controller.
210 * @brief Called to enable text input.
212 * @note Selectable or editable controls should call this once after Controller::New().
213 * @param[in] decorator Used to create cursor, selection handle decorations etc.
214 * @param[in] inputMethodContext Used to manager ime.
216 void EnableTextInput(DecoratorPtr decorator, InputMethodContext& inputMethodContext);
219 * @brief Used to switch between bitmap & vector based glyphs
221 * @param[in] glyphType The type of glyph; note that metrics for bitmap & vector based glyphs are different.
223 void SetGlyphType(TextAbstraction::GlyphType glyphType);
226 * @brief Enables/disables the mark-up processor.
228 * By default is disabled.
230 * @param[in] enable Whether to enable the mark-up processor.
232 void SetMarkupProcessorEnabled(bool enable);
235 * @brief Retrieves whether the mark-up processor is enabled.
237 * By default is disabled.
239 * @return @e true if the mark-up processor is enabled, otherwise returns @e false.
241 bool IsMarkupProcessorEnabled() const;
244 * @brief Retrieves whether the current text contains anchors.
246 * @return @e true if the current text contains anchors. @e false.
248 bool HasAnchors() const;
251 * @brief Enables/disables the auto text scrolling
253 * By default is disabled.
255 * @param[in] enable Whether to enable the auto scrolling
257 void SetAutoScrollEnabled(bool enable);
260 * @brief Retrieves whether auto text scrolling is enabled.
262 * By default is disabled.
264 * @return @e true if auto scrolling is enabled, otherwise returns @e false.
266 bool IsAutoScrollEnabled() const;
269 * @brief Get direction of the text from the first line of text,
270 * @return bool rtl (right to left) is true
272 CharacterDirection GetAutoScrollDirection() const;
275 * @brief Get the alignment offset of the first line of text.
277 * @return The alignment offset.
279 float GetAutoScrollLineAlignment() const;
282 * @brief Enables the horizontal scrolling.
284 * @param[in] enable Whether to enable the horizontal scrolling.
286 void SetHorizontalScrollEnabled(bool enable);
289 * @brief Retrieves whether the horizontal scrolling is enabled.
291 * @return @e true if the horizontal scrolling is enabled, otherwise it returns @e false.
293 bool IsHorizontalScrollEnabled() const;
296 * @brief Enables the vertical scrolling.
298 * @param[in] enable Whether to enable the vertical scrolling.
300 void SetVerticalScrollEnabled(bool enable);
303 * @brief Retrieves whether the verticall scrolling is enabled.
305 * @return @e true if the vertical scrolling is enabled, otherwise it returns @e false.
307 bool IsVerticalScrollEnabled() const;
310 * @brief Enables the smooth handle panning.
312 * @param[in] enable Whether to enable the smooth handle panning.
314 void SetSmoothHandlePanEnabled(bool enable);
317 * @brief Retrieves whether the smooth handle panning is enabled.
319 * @return @e true if the smooth handle panning is enabled.
321 bool IsSmoothHandlePanEnabled() const;
324 * @brief Sets the maximum number of characters that can be inserted into the TextModel
326 * @param[in] maxCharacters maximum number of characters to be accepted
328 void SetMaximumNumberOfCharacters(Length maxCharacters);
331 * @brief Sets the maximum number of characters that can be inserted into the TextModel
333 * @param[in] maxCharacters maximum number of characters to be accepted
335 int GetMaximumNumberOfCharacters();
338 * @brief Called to enable/disable cursor blink.
340 * @note Only editable controls should calls this.
341 * @param[in] enabled Whether the cursor should blink or not.
343 void SetEnableCursorBlink(bool enable);
346 * @brief Query whether cursor blink is enabled.
348 * @return Whether the cursor should blink or not.
350 bool GetEnableCursorBlink() const;
353 * @brief Whether to enable the multi-line layout.
355 * @param[in] enable \e true enables the multi-line (by default)
357 void SetMultiLineEnabled(bool enable);
360 * @return Whether the multi-line layout is enabled.
362 bool IsMultiLineEnabled() const;
365 * @brief Sets the text's horizontal alignment.
367 * @param[in] alignment The horizontal alignment.
369 void SetHorizontalAlignment(HorizontalAlignment::Type alignment);
372 * @copydoc ModelInterface::GetHorizontalAlignment()
374 HorizontalAlignment::Type GetHorizontalAlignment() const;
377 * @brief Sets the text's vertical alignment.
379 * @param[in] alignment The vertical alignment.
381 void SetVerticalAlignment(VerticalAlignment::Type alignment);
384 * @copydoc ModelInterface::GetVerticalAlignment()
386 VerticalAlignment::Type GetVerticalAlignment() const;
389 * @brief Sets the text's wrap mode
390 * @param[in] text wrap mode The unit of wrapping
392 void SetLineWrapMode(Text::LineWrap::Mode textWarpMode);
395 * @brief Retrieve text wrap mode previously set.
396 * @return text wrap mode
398 Text::LineWrap::Mode GetLineWrapMode() const;
401 * @brief Enable or disable the text elide.
403 * @param[in] enabled Whether to enable the text elide.
405 void SetTextElideEnabled(bool enabled);
408 * @copydoc ModelInterface::IsTextElideEnabled()
410 bool IsTextElideEnabled() const;
413 * @brief Enable or disable the text fit.
415 * @param[in] enabled Whether to enable the text fit.
417 void SetTextFitEnabled(bool enabled);
420 * @brief Whether the text fit is enabled or not.
422 * @return True if the text fit is enabled
424 bool IsTextFitEnabled() const;
427 * @brief Sets minimum size valid for text fit.
429 * @param[in] minimum size value.
430 * @param[in] type The font size type is point size or pixel size
432 void SetTextFitMinSize(float pointSize, FontSizeType type);
435 * @brief Retrieves the minimum point size valid for text fit.
437 * @return The minimum point size valid for text fit
439 float GetTextFitMinSize() const;
442 * @brief Sets maximum size valid for text fit.
444 * @param[in] maximum size value.
445 * @param[in] type The font size type is point size or pixel size
447 void SetTextFitMaxSize(float pointSize, FontSizeType type);
450 * @brief Retrieves the maximum point size valid for text fit.
452 * @return The maximum point size valid for text fit
454 float GetTextFitMaxSize() const;
457 * @brief Sets step size for font increase valid for text fit.
459 * @param[in] step size value.
460 * @param[in] type The font size type is point size or pixel size
462 void SetTextFitStepSize(float step, FontSizeType type);
465 * @brief Retrieves the step point size valid for text fit.
467 * @return The step point size valid for text fit
469 float GetTextFitStepSize() const;
472 * @brief Sets content size valid for text fit.
474 * @param[in] Content size value.
476 void SetTextFitContentSize(Vector2 size);
479 * @brief Retrieves the content size valid for text fit.
481 * @return The content size valid for text fit
483 Vector2 GetTextFitContentSize() const;
486 * @brief Retrieve the fited point size.
488 * @return The fited point size.
490 float GetTextFitPointSize() const;
493 * @brief Sets whether the text fit properties have changed.
495 * @param[in] changed Whether to changed the text fit.
497 void SetTextFitChanged(bool changed);
500 * @brief Whether the text fit properties are changed or not.
502 * @return True if the text fit properties are changed
504 bool IsTextFitChanged() const;
507 * @brief Enable or disable the placeholder text elide.
508 * @param enabled Whether to enable the placeholder text elide.
510 void SetPlaceholderTextElideEnabled(bool enabled);
513 * @brief Whether the placeholder text elide property is enabled.
514 * @return True if the placeholder text elide property is enabled, false otherwise.
516 bool IsPlaceholderTextElideEnabled() const;
519 * @brief Enable or disable the text selection.
520 * @param[in] enabled Whether to enable the text selection.
522 void SetSelectionEnabled(bool enabled);
525 * @brief Whether the text selection is enabled or not.
526 * @return True if the text selection is enabled
528 bool IsSelectionEnabled() const;
531 * @brief Enable or disable the text selection using Shift key.
532 * @param enabled Whether to enable the text selection using Shift key
534 void SetShiftSelectionEnabled(bool enabled);
537 * @brief Whether the text selection using Shift key is enabled or not.
538 * @return True if the text selection using Shift key is enabled
540 bool IsShiftSelectionEnabled() const;
543 * @brief Enable or disable the grab handles for text selection.
545 * @param[in] enabled Whether to enable the grab handles
547 void SetGrabHandleEnabled(bool enabled);
550 * @brief Returns whether the grab handles are enabled.
552 * @return True if the grab handles are enabled
554 bool IsGrabHandleEnabled() const;
557 * @brief Enable or disable the grab handles for text selection.
559 * @param[in] enabled Whether to enable the grab handles
561 void SetGrabHandlePopupEnabled(bool enabled);
564 * @brief Returns whether the grab handles are enabled.
566 * @return True if the grab handles are enabled
568 bool IsGrabHandlePopupEnabled() const;
571 * @brief Sets input type to password
573 * @note The string is displayed hidden character
575 * @param[in] passwordInput True if password input is enabled.
577 void SetInputModePassword(bool passwordInput);
580 * @brief Returns whether the input mode type is set as password.
582 * @return True if input mode type is password
584 bool IsInputModePassword();
587 * @brief Sets the action when there is a double tap event on top of a text area with no text.
589 * @param[in] action The action to do.
591 void SetNoTextDoubleTapAction(NoTextTap::Action action);
594 * @brief Retrieves the action when there is a double tap event on top of a text area with no text.
596 * @return The action to do.
598 NoTextTap::Action GetNoTextDoubleTapAction() const;
601 * @briefSets the action when there is a long press event on top of a text area with no text.
603 * @param[in] action The action to do.
605 void SetNoTextLongPressAction(NoTextTap::Action action);
608 * @brief Retrieves the action when there is a long press event on top of a text area with no text.
610 * @return The action to do.
612 NoTextTap::Action GetNoTextLongPressAction() const;
615 * @brief Query if Underline settings were provided by string or map
616 * @return bool true if set by string
618 bool IsUnderlineSetByString();
621 * Set method underline setting were set by
622 * @param[in] bool, true if set by string
624 void UnderlineSetByString(bool setByString);
627 * @brief Query if shadow settings were provided by string or map
628 * @return bool true if set by string
630 bool IsShadowSetByString();
633 * Set method shadow setting were set by
634 * @param[in] bool, true if set by string
636 void ShadowSetByString(bool setByString);
639 * @brief Query if outline settings were provided by string or map
640 * @return bool true if set by string
642 bool IsOutlineSetByString();
645 * Set method outline setting were set by
646 * @param[in] bool, true if set by string
648 void OutlineSetByString(bool setByString);
651 * @brief Query if font style settings were provided by string or map
652 * @return bool true if set by string
654 bool IsFontStyleSetByString();
657 * Set method font style setting were set by
658 * @param[in] bool, true if set by string
660 void FontStyleSetByString(bool setByString);
664 * @brief Replaces any text previously set.
666 * @note This will be converted into UTF-32 when stored in the text model.
667 * @param[in] text A string of UTF-8 characters.
669 void SetText(const std::string& text);
672 * @brief Retrieve any text previously set.
674 * @param[out] text A string of UTF-8 characters.
676 void GetText(std::string& text) const;
679 * @brief Replaces any placeholder text previously set.
681 * @param[in] type Different placeholder-text can be shown when the control is active/inactive.
682 * @param[in] text A string of UTF-8 characters.
684 void SetPlaceholderText(PlaceholderType type, const std::string& text);
687 * @brief Retrieve any placeholder text previously set.
689 * @param[in] type Different placeholder-text can be shown when the control is active/inactive.
690 * @param[out] A string of UTF-8 characters.
692 void GetPlaceholderText(PlaceholderType type, std::string& text) const;
695 * @ brief Update the text after a font change
696 * @param[in] newDefaultFont The new font to change to
698 void UpdateAfterFontChange(const std::string& newDefaultFont);
701 * @brief The method acquires currently selected text
702 * @param selectedText variable to place selected text in
704 void RetrieveSelection(std::string& selectedText) const;
707 * @brief The method sets selection in given range
708 * @param start index of first character
709 * @param end index of first character after selection
711 void SetSelection(int start, int end);
714 * @brief This method retrieve indexes of current selection
716 * @return a pair, where first element is left index of selection and second is the right one
718 std::pair<int, int> GetSelectionIndexes() const;
721 * Place string in system clipboard
722 * @param source std::string
724 void CopyStringToClipboard(const std::string& source);
727 * Place currently selected text in system clipboard
728 * @param deleteAfterSending flag pointing if text should be deleted after sending to clipboard
730 void SendSelectionToClipboard(bool deleteAfterSending);
732 public: // Default style & Input style
734 * @brief Set the default font family.
736 * @param[in] defaultFontFamily The default font family.
738 void SetDefaultFontFamily(const std::string& defaultFontFamily);
741 * @brief Retrieve the default font family.
743 * @return The default font family.
745 const std::string& GetDefaultFontFamily() const;
748 * @brief Sets the placeholder text font family.
749 * @param[in] placeholderTextFontFamily The placeholder text font family.
751 void SetPlaceholderFontFamily(const std::string& placeholderTextFontFamily);
754 * @brief Retrieves the placeholder text font family.
756 * @return The placeholder text font family
758 const std::string& GetPlaceholderFontFamily() const;
761 * @brief Sets the default font weight.
763 * @param[in] weight The font weight.
765 void SetDefaultFontWeight(FontWeight weight);
768 * @brief Whether the font's weight has been defined.
770 bool IsDefaultFontWeightDefined() const;
773 * @brief Retrieves the default font weight.
775 * @return The default font weight.
777 FontWeight GetDefaultFontWeight() const;
780 * @brief Sets the placeholder text font weight.
782 * @param[in] weight The font weight
784 void SetPlaceholderTextFontWeight(FontWeight weight);
787 * @brief Whether the font's weight has been defined.
789 * @return True if the placeholder text font weight is defined
791 bool IsPlaceholderTextFontWeightDefined() const;
794 * @brief Retrieves the placeholder text font weight.
796 * @return The placeholder text font weight
798 FontWeight GetPlaceholderTextFontWeight() const;
801 * @brief Sets the default font width.
803 * @param[in] width The font width.
805 void SetDefaultFontWidth(FontWidth width);
808 * @brief Whether the font's width has been defined.
810 bool IsDefaultFontWidthDefined() const;
813 * @brief Retrieves the default font width.
815 * @return The default font width.
817 FontWidth GetDefaultFontWidth() const;
820 * @brief Sets the placeholder text font width.
822 * @param[in] width The font width
824 void SetPlaceholderTextFontWidth(FontWidth width);
827 * @brief Whether the font's width has been defined.
829 * @return True if the placeholder text font width is defined
831 bool IsPlaceholderTextFontWidthDefined() const;
834 * @brief Retrieves the placeholder text font width.
836 * @return The placeholder text font width
838 FontWidth GetPlaceholderTextFontWidth() const;
841 * @brief Sets the default font slant.
843 * @param[in] slant The font slant.
845 void SetDefaultFontSlant(FontSlant slant);
848 * @brief Whether the font's slant has been defined.
850 bool IsDefaultFontSlantDefined() const;
853 * @brief Retrieves the default font slant.
855 * @return The default font slant.
857 FontSlant GetDefaultFontSlant() const;
860 * @brief Sets the placeholder text font slant.
862 * @param[in] slant The font slant
864 void SetPlaceholderTextFontSlant(FontSlant slant);
867 * @brief Whether the font's slant has been defined.
869 * @return True if the placeholder text font slant is defined
871 bool IsPlaceholderTextFontSlantDefined() const;
874 * @brief Retrieves the placeholder text font slant.
876 * @return The placeholder text font slant
878 FontSlant GetPlaceholderTextFontSlant() const;
881 * @brief Set the default font size.
883 * @param[in] fontSize The default font size
884 * @param[in] type The font size type is point size or pixel size
886 void SetDefaultFontSize(float fontSize, FontSizeType type);
889 * @brief Retrieve the default point size.
891 * @param[in] type The font size type
892 * @return The default point size.
894 float GetDefaultFontSize(FontSizeType type) const;
897 * @brief Set the font size scale.
899 * @param[in] scale The font size scale
901 void SetFontSizeScale(float scale);
904 * @brief Get the font size scale.
906 * @return The font size scale.
908 float GetFontSizeScale() const;
911 * @brief Sets the Placeholder text font size.
912 * @param[in] fontSize The placeholder text font size
913 * @param[in] type The font size type is point size or pixel size
915 void SetPlaceholderTextFontSize(float fontSize, FontSizeType type);
918 * @brief Retrieves the Placeholder text font size.
919 * @param[in] type The font size type
920 * @return The placeholder font size
922 float GetPlaceholderTextFontSize(FontSizeType type) const;
925 * @brief Sets the text's default color.
927 * @param color The default color.
929 void SetDefaultColor(const Vector4& color);
932 * @brief Retrieves the text's default color.
934 * @return The default color.
936 const Vector4& GetDefaultColor() const;
939 * @brief Set the text color
941 * @param textColor The text color
943 void SetPlaceholderTextColor(const Vector4& textColor);
946 * @brief Retrieve the text color
948 * @return The text color
950 const Vector4& GetPlaceholderTextColor() const;
953 * @brief Set the shadow offset.
955 * @param[in] shadowOffset The shadow offset, 0,0 indicates no shadow.
957 void SetShadowOffset(const Vector2& shadowOffset);
960 * @brief Retrieve the shadow offset.
962 * @return The shadow offset.
964 const Vector2& GetShadowOffset() const;
967 * @brief Set the shadow color.
969 * @param[in] shadowColor The shadow color.
971 void SetShadowColor(const Vector4& shadowColor);
974 * @brief Retrieve the shadow color.
976 * @return The shadow color.
978 const Vector4& GetShadowColor() const;
981 * @brief Set the shadow blur radius.
983 * @param[in] shadowBlurRadius The shadow blur radius, 0,0 indicates no blur.
985 void SetShadowBlurRadius(const float& shadowBlurRadius);
988 * @brief Retrieve the shadow blur radius.
990 * @return The shadow blur radius.
992 const float& GetShadowBlurRadius() const;
995 * @brief Set the underline color.
997 * @param[in] color color of underline.
999 void SetUnderlineColor(const Vector4& color);
1002 * @brief Retrieve the underline color.
1004 * @return The underline color.
1006 const Vector4& GetUnderlineColor() const;
1009 * @brief Set the underline enabled flag.
1011 * @param[in] enabled The underline enabled flag.
1013 void SetUnderlineEnabled(bool enabled);
1016 * @brief Returns whether the text is underlined or not.
1018 * @return The underline state.
1020 bool IsUnderlineEnabled() const;
1023 * @brief Set the override used for underline height, 0 indicates height will be supplied by font metrics
1025 * @param[in] height The height in pixels of the underline
1027 void SetUnderlineHeight(float height);
1030 * @brief Retrieves the override height of an underline, 0 indicates height is supplied by font metrics
1032 * @return The height of the underline, or 0 if height is not overrided.
1034 float GetUnderlineHeight() const;
1037 * @brief Set the outline color.
1039 * @param[in] color color of outline.
1041 void SetOutlineColor(const Vector4& color);
1044 * @brief Retrieve the outline color.
1046 * @return The outline color.
1048 const Vector4& GetOutlineColor() const;
1051 * @brief Set the outline width
1053 * @param[in] width The width in pixels of the outline, 0 indicates no outline
1055 void SetOutlineWidth(uint16_t width);
1058 * @brief Retrieves the width of an outline
1060 * @return The width of the outline.
1062 uint16_t GetOutlineWidth() const;
1065 * @brief Set the background color.
1067 * @param[in] color color of background.
1069 void SetBackgroundColor(const Vector4& color);
1072 * @brief Retrieve the background color.
1074 * @return The background color.
1076 const Vector4& GetBackgroundColor() const;
1079 * @brief Set the background enabled flag.
1081 * @param[in] enabled The background enabled flag.
1083 void SetBackgroundEnabled(bool enabled);
1086 * @brief Returns whether to enable text background or not.
1088 * @return Whether text background is enabled.
1090 bool IsBackgroundEnabled() const;
1093 * @brief Sets the emboss's properties string.
1095 * @note The string is stored to be recovered.
1097 * @param[in] embossProperties The emboss's properties string.
1099 void SetDefaultEmbossProperties(const std::string& embossProperties);
1102 * @brief Retrieves the emboss's properties string.
1104 * @return The emboss's properties string.
1106 const std::string& GetDefaultEmbossProperties() const;
1109 * @brief Sets the outline's properties string.
1111 * @note The string is stored to be recovered.
1113 * @param[in] outlineProperties The outline's properties string.
1115 void SetDefaultOutlineProperties(const std::string& outlineProperties);
1118 * @brief Retrieves the outline's properties string.
1120 * @return The outline's properties string.
1122 const std::string& GetDefaultOutlineProperties() const;
1125 * @brief Sets the default line spacing.
1127 * @param[in] lineSpacing The line spacing.
1129 * @return True if lineSpacing has been updated, false otherwise
1131 bool SetDefaultLineSpacing(float lineSpacing);
1134 * @brief Retrieves the default line spacing.
1136 * @return The line spacing.
1138 float GetDefaultLineSpacing() const;
1141 * @brief Sets the default line size.
1143 * @param[in] lineSize The line size.
1145 * @return True if lineSize has been updated, false otherwise
1147 bool SetDefaultLineSize(float lineSize);
1150 * @brief Retrieves the default line size.
1152 * @return The line size.
1154 float GetDefaultLineSize() const;
1157 * @brief Sets the input text's color.
1159 * @param[in] color The input text's color.
1161 void SetInputColor(const Vector4& color);
1164 * @brief Retrieves the input text's color.
1166 * @return The input text's color.
1168 const Vector4& GetInputColor() const;
1171 * @brief Sets the input text's font family name.
1173 * @param[in] fontFamily The text's font family name.
1175 void SetInputFontFamily(const std::string& fontFamily);
1178 * @brief Retrieves the input text's font family name.
1180 * @return The input text's font family name.
1182 const std::string& GetInputFontFamily() const;
1185 * @brief Sets the input font's weight.
1187 * @param[in] weight The input font's weight.
1189 void SetInputFontWeight(FontWeight weight);
1192 * @return Whether the font's weight has been defined.
1194 bool IsInputFontWeightDefined() const;
1197 * @brief Retrieves the input font's weight.
1199 * @return The input font's weight.
1201 FontWeight GetInputFontWeight() const;
1204 * @brief Sets the input font's width.
1206 * @param[in] width The input font's width.
1208 void SetInputFontWidth(FontWidth width);
1211 * @return Whether the font's width has been defined.
1213 bool IsInputFontWidthDefined() const;
1216 * @brief Retrieves the input font's width.
1218 * @return The input font's width.
1220 FontWidth GetInputFontWidth() const;
1223 * @brief Sets the input font's slant.
1225 * @param[in] slant The input font's slant.
1227 void SetInputFontSlant(FontSlant slant);
1230 * @return Whether the font's slant has been defined.
1232 bool IsInputFontSlantDefined() const;
1235 * @brief Retrieves the input font's slant.
1237 * @return The input font's slant.
1239 FontSlant GetInputFontSlant() const;
1242 * @brief Sets the input font's point size.
1244 * @param[in] size The input font's point size.
1246 void SetInputFontPointSize(float size);
1249 * @brief Retrieves the input font's point size.
1251 * @return The input font's point size.
1253 float GetInputFontPointSize() const;
1256 * @brief Sets the input line spacing.
1258 * @param[in] lineSpacing The line spacing.
1260 void SetInputLineSpacing(float lineSpacing);
1263 * @brief Retrieves the input line spacing.
1265 * @return The line spacing.
1267 float GetInputLineSpacing() const;
1270 * @brief Sets the input shadow's properties string.
1272 * @note The string is stored to be recovered.
1274 * @param[in] shadowProperties The shadow's properties string.
1276 void SetInputShadowProperties(const std::string& shadowProperties);
1279 * @brief Retrieves the input shadow's properties string.
1281 * @return The shadow's properties string.
1283 const std::string& GetInputShadowProperties() const;
1286 * @brief Sets the input underline's properties string.
1288 * @note The string is stored to be recovered.
1290 * @param[in] underlineProperties The underline's properties string.
1292 void SetInputUnderlineProperties(const std::string& underlineProperties);
1295 * @brief Retrieves the input underline's properties string.
1297 * @return The underline's properties string.
1299 const std::string& GetInputUnderlineProperties() const;
1302 * @brief Sets the input emboss's properties string.
1304 * @note The string is stored to be recovered.
1306 * @param[in] embossProperties The emboss's properties string.
1308 void SetInputEmbossProperties(const std::string& embossProperties);
1311 * @brief Retrieves the input emboss's properties string.
1313 * @return The emboss's properties string.
1315 const std::string& GetInputEmbossProperties() const;
1318 * @brief Sets input the outline's properties string.
1320 * @note The string is stored to be recovered.
1322 * @param[in] outlineProperties The outline's properties string.
1324 void SetInputOutlineProperties(const std::string& outlineProperties);
1327 * @brief Retrieves the input outline's properties string.
1329 * @return The outline's properties string.
1331 const std::string& GetInputOutlineProperties() const;
1334 * @brief Set the control's interface.
1336 * @param[in] controlInterface The control's interface.
1338 void SetControlInterface(ControlInterface* controlInterface);
1341 * @brief Set the anchor control's interface.
1343 * @param[in] anchorControlInterface The control's interface.
1345 void SetAnchorControlInterface(AnchorControlInterface* anchorControlInterface);
1347 public: // Queries & retrieves.
1349 * @brief Return the layout engine.
1351 * @return A reference to the layout engine.
1353 Layout::Engine& GetLayoutEngine();
1356 * @brief Return a view of the text.
1358 * @return A reference to the view.
1363 * @copydoc Control::GetNaturalSize()
1365 Vector3 GetNaturalSize();
1368 * @copydoc Control::GetHeightForWidth()
1370 float GetHeightForWidth(float width);
1373 * @brief Calculates the point size for text for given layout()
1375 void FitPointSizeforLayout(Size layoutSize);
1378 * @brief Checks if the point size fits within the layout size.
1380 * @return Whether the point size fits within the layout size.
1382 bool CheckForTextFit(float pointSize, Size& layoutSize);
1385 * @brief Retrieves the text's number of lines for a given width.
1386 * @param[in] width The width of the text's area.
1387 * @ return The number of lines.
1389 int GetLineCount(float width);
1392 * @brief Retrieves the text's model.
1394 * @return A pointer to the text's model.
1396 const ModelInterface* const GetTextModel() const;
1399 * @brief Used to get scrolled distance by user input
1401 * @return Distance from last scroll offset to new scroll offset
1403 float GetScrollAmountByUserInput();
1406 * @brief Get latest scroll amount, control size and layout size
1408 * This method is used to get information of control's scroll
1409 * @param[out] scrollPosition The current scrolled position
1410 * @param[out] controlHeight The size of a UI control
1411 * @param[out] layoutHeight The size of a bounding box to layout text within.
1413 * @return Whether the text scroll position is changed or not after last update.
1415 bool GetTextScrollInfo(float& scrollPosition, float& controlHeight, float& layoutHeight);
1418 * @brief Used to set the hidden input option
1420 void SetHiddenInputOption(const Property::Map& options);
1423 * @brief Used to get the hidden input option
1425 void GetHiddenInputOption(Property::Map& options);
1428 * @brief Used to set the input filter option
1430 void SetInputFilterOption(const Property::Map& options);
1433 * @brief Used to get the input filter option
1435 void GetInputFilterOption(Property::Map& options);
1438 * @brief Sets the Placeholder Properties.
1440 * @param[in] map The placeholder property map
1442 void SetPlaceholderProperty(const Property::Map& map);
1445 * @brief Retrieves the Placeholder Property map.
1447 * @param[out] map The property map
1449 void GetPlaceholderProperty(Property::Map& map);
1452 * @brief Checks text direction.
1453 * @return The text direction.
1455 Toolkit::DevelText::TextDirection::Type GetTextDirection();
1458 * @brief Retrieves vertical line alignment
1459 * @return The vertical line alignment
1461 Toolkit::DevelText::VerticalLineAlignment::Type GetVerticalLineAlignment() const;
1464 * @brief Sets vertical line alignment
1465 * @param[in] alignment The vertical line alignment for the text
1467 void SetVerticalLineAlignment(Toolkit::DevelText::VerticalLineAlignment::Type alignment);
1470 * @brief Retrieves ellipsis position
1471 * @return The ellipsis position
1473 Toolkit::DevelText::EllipsisPosition::Type GetEllipsisPosition() const;
1476 * @brief Sets ellipsis position
1477 * @param[in] ellipsisPosition The ellipsis position for the text
1479 void SetEllipsisPosition(Toolkit::DevelText::EllipsisPosition::Type ellipsisPosition);
1482 * @brief Retrieves ignoreSpaceAfterText value from model
1483 * @return The value of ignoreSpaceAfterText
1485 bool IsIgnoreSpacesAfterText() const;
1488 * @brief Sets ignoreSpaceAfterText value to model
1489 * @param[in] ignore The value of ignoreSpacesAfterText for the text
1491 void SetIgnoreSpacesAfterText(bool ignore);
1494 * @brief Sets SetMatchLayoutDirection value to model
1495 * @param[in] match The value of matchLayoutDirection for the text
1497 void SetMatchLayoutDirection(DevelText::MatchLayoutDirection type);
1500 * @brief Retrieves matchLayoutDirection value from model
1501 * @return The value of matchLayoutDirection
1503 DevelText::MatchLayoutDirection GetMatchLayoutDirection() const;
1506 * @brief Sets layoutDirection type value.
1507 * @param[in] layoutDirection The value of the layout direction type.
1509 void SetLayoutDirection(Dali::LayoutDirection::Type layoutDirection);
1512 * @brief Gets layoutDirection type value.
1513 * @param[in] actor The actor which will get the layout direction type.
1514 * @return The value of the layout direction type.
1516 Dali::LayoutDirection::Type GetLayoutDirection(Dali::Actor& actor) const;
1519 * @brief Sets the layout direction changed.
1521 void ChangedLayoutDirection();
1524 * @brief Retrieves if showing real text or not.
1525 * @return The value of showing real text.
1527 bool IsShowingRealText() const;
1529 public: // Relayout.
1531 * @brief Triggers a relayout which updates View (if necessary).
1533 * @note UI Controls are expected to minimize calls to this method e.g. call once after size negotiation.
1534 * @param[in] size A the size of a bounding box to layout text within.
1535 * @param[in] layoutDirection The direction of the system language.
1537 * @return Whether the text model or decorations were updated.
1539 UpdateTextType Relayout(const Size& size, Dali::LayoutDirection::Type layoutDirection = Dali::LayoutDirection::LEFT_TO_RIGHT);
1542 * @brief Request a relayout using the ControlInterface.
1544 void RequestRelayout();
1546 public: // Input style change signals.
1548 * @return Whether the queue of input style changed signals is empty.
1550 bool IsInputStyleChangedSignalsQueueEmpty();
1553 * @brief Process all pending input style changed signals.
1555 * Calls the Text::ControlInterface::InputStyleChanged() method which is overriden by the
1556 * text controls. Text controls may send signals to state the input style has changed.
1558 void ProcessInputStyleChangedSignals();
1560 public: // Text-input Event Queuing.
1562 * @brief Called by editable UI controls when keyboard focus is gained.
1564 void KeyboardFocusGainEvent();
1567 * @brief Called by editable UI controls when focus is lost.
1569 void KeyboardFocusLostEvent();
1572 * @brief Called by editable UI controls when key events are received.
1574 * @param[in] event The key event.
1575 * @param[in] type Used to distinguish between regular key events and InputMethodContext events.
1577 bool KeyEvent(const Dali::KeyEvent& event);
1580 * @brief Called by anchor when a tap gesture occurs.
1581 * @param[in] x The x position relative to the top-left of the parent control.
1582 * @param[in] y The y position relative to the top-left of the parent control.
1584 void AnchorEvent(float x, float y);
1587 * @brief Called by editable UI controls when a tap gesture occurs.
1588 * @param[in] tapCount The number of taps.
1589 * @param[in] x The x position relative to the top-left of the parent control.
1590 * @param[in] y The y position relative to the top-left of the parent control.
1592 void TapEvent(unsigned int tapCount, float x, float y);
1595 * @brief Called by editable UI controls when a pan gesture occurs.
1597 * @param[in] state The state of the gesture.
1598 * @param[in] displacement This distance panned since the last pan gesture.
1600 void PanEvent(GestureState state, const Vector2& displacement);
1603 * @brief Called by editable UI controls when a long press gesture occurs.
1605 * @param[in] state The state of the gesture.
1606 * @param[in] x The x position relative to the top-left of the parent control.
1607 * @param[in] y The y position relative to the top-left of the parent control.
1609 void LongPressEvent(GestureState state, float x, float y);
1612 * @brief Used to get the Primary cursor position.
1614 * @return Primary cursor position.
1616 CharacterIndex GetPrimaryCursorPosition() const;
1619 * @brief Used to set the Primary cursor position.
1621 * @param[in] index for the Primary cursor position.
1622 * @param[in] focused true if UI control has gained focus to receive key event, false otherwise.
1623 * @return[in] true if cursor position changed, false otherwise.
1625 bool SetPrimaryCursorPosition(CharacterIndex index, bool focused);
1628 * @brief Creates a selection event.
1630 * It could be called from the TapEvent (double tap) or when the text selection popup's sellect all button is pressed.
1632 * @param[in] x The x position relative to the top-left of the parent control.
1633 * @param[in] y The y position relative to the top-left of the parent control.
1634 * @param[in] selection type like the whole text is selected or unselected.
1636 void SelectEvent(float x, float y, SelectionType selection);
1639 * @brief Creates a selection event with a selection index.
1641 * It could be called from the SelectText().
1642 * The start and end parameters are passed through the event.
1644 * @param[in] start The start selection position.
1645 * @param[in] end The end selection position.
1646 * @param[in] selection type like the range.
1648 void SelectEvent(const uint32_t start, const uint32_t end, SelectionType selection);
1651 * @copydoc Text::SelectableControlInterface::SetTextSelectionRange()
1653 void SetTextSelectionRange(const uint32_t* start, const uint32_t* end);
1656 * @copydoc Text::SelectableControlInterface::GetTextSelectionRange()
1658 Uint32Pair GetTextSelectionRange() const;
1661 * @copydoc Text::SelectableControlInterface::SelectWholeText()
1663 void SelectWholeText();
1666 * @copydoc Text::EditableControlInterface::CopyText()
1671 * @copydoc Text::EditableControlInterface::CutText()
1676 * @copydoc Text::EditableControlInterface::PasteText()
1681 * @copydoc Text::SelectableControlInterface::SelectNone()
1686 * @copydoc Text::SelectableControlInterface::SelectText()
1688 void SelectText(const uint32_t start, const uint32_t end);
1691 * @copydoc Text::SelectableControlInterface::GetSelectedText()
1693 string GetSelectedText() const;
1696 * @copydoc Text::EditableControlInterface::IsEditable()
1698 virtual bool IsEditable() const;
1701 * @copydoc Text::EditableControlInterface::SetEditable()
1703 virtual void SetEditable(bool editable);
1706 * @copydoc Dali::Toolkit::Internal::TextEditor::ScrollBy()
1708 virtual void ScrollBy(Vector2 scroll);
1711 * @copydoc Dali::Toolkit::Internal::TextEditor::GetHorizontalScrollPosition()
1713 float GetHorizontalScrollPosition();
1716 * @copydoc Dali::Toolkit::Internal::TextEditor::GetVerticalScrollPosition()
1718 float GetVerticalScrollPosition();
1721 * @brief Event received from input method context
1723 * @param[in] inputMethodContext The input method context.
1724 * @param[in] inputMethodContextEvent The event received.
1725 * @return A data struture indicating if update is needed, cursor position and current text.
1727 InputMethodContext::CallbackData OnInputMethodContextEvent(InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent);
1730 * @brief Event from Clipboard notifying an Item has been selected for pasting
1732 void PasteClipboardItemEvent();
1735 * @brief Return true when text control should clear key input focus when escape key is pressed.
1737 * @return Whether text control should clear key input focus or not when escape key is pressed.
1739 bool ShouldClearFocusOnEscape() const;
1742 * @brief Create an actor that renders the text background color
1744 * @return the created actor or an empty handle if no background color needs to be rendered.
1746 Actor CreateBackgroundActor();
1749 * @brief Used to reset the cursor position after setting a new text.
1751 * @param[in] cursorIndex Where to place the cursor.
1753 void ResetCursorPosition(CharacterIndex cursorIndex);
1756 * @brief The method acquires current position of cursor
1757 * @return unsigned value with cursor position
1759 CharacterIndex GetCursorPosition();
1762 * @brief Resets a provided vector with actors that marks the position of anchors in markup enabled text
1764 * @param[out] anchorActors the vector of actor (empty collection if no anchors available).
1766 void GetAnchorActors(std::vector<Toolkit::TextAnchor>& anchorActors);
1769 * @brief Return an index of first anchor in the anchor vector whose boundaries includes given character offset
1771 * @param[in] characterOffset A position in text coords.
1773 * @return the index in anchor vector (-1 if an anchor not found)
1775 int GetAnchorIndex(size_t characterOffset);
1777 protected: // Inherit from Text::Decorator::ControllerInterface.
1779 * @copydoc Dali::Toolkit::Text::Decorator::ControllerInterface::GetTargetSize()
1781 void GetTargetSize(Vector2& targetSize) override;
1784 * @copydoc Dali::Toolkit::Text::Decorator::ControllerInterface::AddDecoration()
1786 void AddDecoration(Actor& actor, bool needsClipping) override;
1789 * @copydoc Dali::Toolkit::Text::Decorator::ControllerInterface::DecorationEvent()
1791 void DecorationEvent(HandleType handle, HandleState state, float x, float y) override;
1793 protected: // Inherit from TextSelectionPopup::TextPopupButtonCallbackInterface.
1795 * @copydoc Dali::Toolkit::TextSelectionPopup::TextPopupButtonCallbackInterface::TextPopupButtonTouched()
1797 void TextPopupButtonTouched(Dali::Toolkit::TextSelectionPopup::Buttons button) override;
1799 protected: // Inherit from HiddenText.
1801 * @brief Invoked from HiddenText when showing time of the last character was expired
1803 void DisplayTimeExpired() override;
1807 * @brief Called by editable UI controls when key events are received.
1809 * @param[in] text The text to insert.
1810 * @param[in] type Used to distinguish between regular key events and InputMethodContext events.
1812 void InsertText(const std::string& text, InsertType type);
1815 * @copydoc Text::EditableControlInterface::PasteText()
1817 void PasteText(const std::string& stringToPaste);
1820 * @brief Remove a given number of characters
1822 * When predictve text is used the pre-edit text is removed and inserted again with the new characters.
1823 * The UpdateInputStyleType @type parameter if set to DONT_UPDATE_INPUT_STYLE avoids to update the input
1824 * style when pre-edit text is removed.
1826 * @param[in] cursorOffset Start position from the current cursor position to start deleting characters.
1827 * @param[in] numberOfCharacters The number of characters to delete from the cursorOffset.
1828 * @param[in] type Whether to update the input style.
1829 * @return True if the remove was successful.
1831 bool RemoveText(int cursorOffset,
1832 int numberOfCharacters,
1833 UpdateInputStyleType type);
1836 * @brief Checks if text is selected and if so removes it.
1837 * @return true if text was removed
1839 bool RemoveSelectedText();
1842 * @brief Update anchor position from given number of inserted characters.
1844 * @param[in] numberOfCharacters The number of inserted characters.
1845 * @param[in] previousCursorIndex A cursor position before event occurs.
1847 void InsertTextAnchor(int numberOfCharacters,
1848 CharacterIndex previousCursorIndex);
1851 * @brief Update anchor position from given number of removed characters.
1853 * @param[in] cursorOffset Start position from the current cursor position to start deleting characters.
1854 * @param[in] numberOfCharacters The number of removed characters.
1855 * @param[in] previousCursorIndex A cursor position before event occurs.
1857 void RemoveTextAnchor(int cursorOffset,
1858 int numberOfCharacters,
1859 CharacterIndex previousCursorIndex);
1861 private: // Relayout.
1863 * @brief Lays-out the text.
1865 * GetNaturalSize(), GetHeightForWidth() and Relayout() calls this method.
1867 * @param[in] size A the size of a bounding box to layout text within.
1868 * @param[in] operations The layout operations which need to be done.
1869 * @param[out] layoutSize The size of the laid-out text.
1871 bool DoRelayout(const Size& size,
1872 OperationsMask operations,
1876 * @brief Calulates the vertical offset to align the text inside the bounding box.
1878 * @param[in] size The size of the bounding box.
1880 void CalculateVerticalOffset(const Size& size);
1884 * @brief Process queued events which modify the model.
1886 void ProcessModifyEvents();
1889 * @brief Used to process an event queued from SetText()
1891 void TextReplacedEvent();
1894 * @brief Used to process an event queued from key events etc.
1896 void TextInsertedEvent();
1899 * @brief Used to process an event queued from backspace key etc.
1901 void TextDeletedEvent();
1904 * @brief Helper to KeyEvent() to handle the backspace or delete key case.
1906 * @param[in] keyCode The keycode for the key pressed
1907 * @return True if a character was deleted.
1909 bool DeleteEvent(int keyCode);
1911 private: // Helpers.
1913 * @brief Used to remove the text included the placeholder text.
1918 * @brief Helper to show the place holder text..
1920 void ShowPlaceholderText();
1922 private: // Private contructors & copy operator.
1924 * @brief Private constructor.
1927 : Controller(nullptr, nullptr, nullptr, nullptr)
1932 * @brief Private constructor.
1934 Controller(ControlInterface* controlInterface)
1935 : Controller(controlInterface, nullptr, nullptr, nullptr)
1940 * @brief Private constructor.
1942 Controller(ControlInterface* controlInterface,
1943 EditableControlInterface* editableControlInterface,
1944 SelectableControlInterface* selectableControlInterface,
1945 AnchorControlInterface* anchorControlInterface);
1947 Controller(const Controller& handle) = delete;
1948 Controller& operator=(const Controller& handle) = delete;
1950 protected: // Destructor.
1952 * @brief A reference counted object may only be deleted by calling Unreference().
1954 virtual ~Controller();
1957 struct Impl; ///< Made public for testing purposes
1960 struct EventHandler;
1961 struct InputFontHandler;
1962 struct InputProperties;
1963 struct PlaceholderHandler;
1970 } // namespace Dali::Toolkit::Text
1972 #endif // DALI_TOOLKIT_TEXT_CONTROLLER_H