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/text/text-enumerations-devel.h>
29 #include <dali-toolkit/internal/text/decorator/text-decorator.h>
30 #include <dali-toolkit/internal/text/hidden-text.h>
31 #include <dali-toolkit/internal/text/input-filter.h>
32 #include <dali-toolkit/internal/text/layouts/layout-engine.h>
33 #include <dali-toolkit/internal/text/text-anchor-control-interface.h>
34 #include <dali-toolkit/internal/text/text-model-interface.h>
35 #include <dali-toolkit/internal/text/text-selectable-control-interface.h>
36 #include <dali-toolkit/public-api/text/text-enumerations.h>
38 namespace Dali::Toolkit::Text
41 class ControlInterface;
42 class EditableControlInterface;
44 class RenderingController;
47 * @brief Text selection operations .
51 INTERACTIVE = 0x0000, ///< Select the word where the cursor is located.
52 ALL = 0x0001, ///< Select the whole text.
53 NONE = 0x0002, ///< Unselect the whole text.
54 RANGE = 0x0003 ///< Select the range text.
57 typedef IntrusivePtr<Controller> ControllerPtr;
60 * @brief A Text Controller is used by UI Controls which display text.
62 * It manipulates the Logical & Visual text models on behalf of the UI Controls.
63 * It provides a view of the text that can be used by rendering back-ends.
65 * For selectable/editable UI controls, the controller handles input events from the UI control
66 * and decorations (grab handles etc) via the Decorator::ControllerInterface interface.
68 * The text selection popup button callbacks are as well handled via the TextSelectionPopupCallbackInterface interface.
70 class Controller : public RefObject, public Decorator::ControllerInterface, public TextSelectionPopupCallbackInterface, public HiddenText::Observer
72 public: // Enumerated types.
74 * @brief Text related operations to be done in the relayout process.
78 NO_OPERATION = 0x0000,
79 CONVERT_TO_UTF32 = 0x0001,
81 VALIDATE_FONTS = 0x0004,
82 GET_LINE_BREAKS = 0x0008,
85 GET_GLYPH_METRICS = 0x0040,
87 UPDATE_LAYOUT_SIZE = 0x0100,
91 UPDATE_DIRECTION = 0x1000,
92 ALL_OPERATIONS = 0xFFFF
96 * @brief Used to distinguish between regular key events and InputMethodContext events
105 * @brief Used to specify whether to update the input style.
107 enum UpdateInputStyleType
110 DONT_UPDATE_INPUT_STYLE
114 * @brief Used to specify what has been updated after the Relayout() method has been called.
118 NONE_UPDATED = 0x0, ///< Nothing has been updated.
119 MODEL_UPDATED = 0x1, ///< The text's model has been updated.
120 DECORATOR_UPDATED = 0x2 ///< The decoration has been updated.
124 * @brief Different placeholder-text can be shown when the control is active/inactive.
128 PLACEHOLDER_TYPE_ACTIVE,
129 PLACEHOLDER_TYPE_INACTIVE,
133 * @brief Enumeration for Font Size Type.
137 POINT_SIZE, // The size of font in points.
138 PIXEL_SIZE // The size of font in pixels.
145 NO_ACTION, ///< Does no action if there is a tap on top of an area with no text.
146 HIGHLIGHT, ///< Highlights the nearest text (at the beginning or end of the text) and shows the text's selection popup.
147 SHOW_SELECTION_POPUP ///< Shows the text's selection popup.
159 TEXT_FIT_FONT_SIZE_TYPE
163 public: // Constructor.
165 * @brief Create a new instance of a Controller.
167 * @return A pointer to a new Controller.
169 static ControllerPtr New()
171 return ControllerPtr(new Controller());
175 * @brief Create a new instance of a Controller.
177 * @param[in] controlInterface The control's interface.
179 * @return A pointer to a new Controller.
181 static ControllerPtr New(ControlInterface* controlInterface)
183 return ControllerPtr(new Controller(controlInterface));
187 * @brief Create a new instance of a Controller.
189 * @param[in] controlInterface The control's interface.
190 * @param[in] editableControlInterface The editable control's interface.
191 * @param[in] selectableControlInterface The selectable control's interface.
192 * @param[in] anchorControlInterface The anchor control's interface.
194 * @return A pointer to a new Controller.
196 static ControllerPtr New(ControlInterface* controlInterface,
197 EditableControlInterface* editableControlInterface,
198 SelectableControlInterface* selectableControlInterface,
199 AnchorControlInterface* anchorControlInterface)
201 return ControllerPtr(new Controller(controlInterface,
202 editableControlInterface,
203 selectableControlInterface,
204 anchorControlInterface));
207 public: // Configure the text controller.
209 * @brief Called to enable text input.
211 * @note Selectable or editable controls should call this once after Controller::New().
212 * @param[in] decorator Used to create cursor, selection handle decorations etc.
213 * @param[in] inputMethodContext Used to manager ime.
215 void EnableTextInput(DecoratorPtr decorator, InputMethodContext& inputMethodContext);
218 * @brief Used to switch between bitmap & vector based glyphs
220 * @param[in] glyphType The type of glyph; note that metrics for bitmap & vector based glyphs are different.
222 void SetGlyphType(TextAbstraction::GlyphType glyphType);
225 * @brief Enables/disables the mark-up processor.
227 * By default is disabled.
229 * @param[in] enable Whether to enable the mark-up processor.
231 void SetMarkupProcessorEnabled(bool enable);
234 * @brief Retrieves whether the mark-up processor is enabled.
236 * By default is disabled.
238 * @return @e true if the mark-up processor is enabled, otherwise returns @e false.
240 bool IsMarkupProcessorEnabled() const;
243 * @brief Retrieves whether the current text contains anchors.
245 * @return @e true if the current text contains anchors. @e false.
247 bool HasAnchors() const;
250 * @brief Enables/disables the auto text scrolling
252 * By default is disabled.
254 * @param[in] enable Whether to enable the auto scrolling
256 void SetAutoScrollEnabled(bool enable);
259 * @brief Retrieves whether auto text scrolling is enabled.
261 * By default is disabled.
263 * @return @e true if auto scrolling is enabled, otherwise returns @e false.
265 bool IsAutoScrollEnabled() const;
268 * @brief Get direction of the text from the first line of text,
269 * @return bool rtl (right to left) is true
271 CharacterDirection GetAutoScrollDirection() const;
274 * @brief Get the alignment offset of the first line of text.
276 * @return The alignment offset.
278 float GetAutoScrollLineAlignment() const;
281 * @brief Enables the horizontal scrolling.
283 * @param[in] enable Whether to enable the horizontal scrolling.
285 void SetHorizontalScrollEnabled(bool enable);
288 * @brief Retrieves whether the horizontal scrolling is enabled.
290 * @return @e true if the horizontal scrolling is enabled, otherwise it returns @e false.
292 bool IsHorizontalScrollEnabled() const;
295 * @brief Enables the vertical scrolling.
297 * @param[in] enable Whether to enable the vertical scrolling.
299 void SetVerticalScrollEnabled(bool enable);
302 * @brief Retrieves whether the verticall scrolling is enabled.
304 * @return @e true if the vertical scrolling is enabled, otherwise it returns @e false.
306 bool IsVerticalScrollEnabled() const;
309 * @brief Enables the smooth handle panning.
311 * @param[in] enable Whether to enable the smooth handle panning.
313 void SetSmoothHandlePanEnabled(bool enable);
316 * @brief Retrieves whether the smooth handle panning is enabled.
318 * @return @e true if the smooth handle panning is enabled.
320 bool IsSmoothHandlePanEnabled() const;
323 * @brief Sets the maximum number of characters that can be inserted into the TextModel
325 * @param[in] maxCharacters maximum number of characters to be accepted
327 void SetMaximumNumberOfCharacters(Length maxCharacters);
330 * @brief Sets the maximum number of characters that can be inserted into the TextModel
332 * @param[in] maxCharacters maximum number of characters to be accepted
334 int GetMaximumNumberOfCharacters();
337 * @brief Called to enable/disable cursor blink.
339 * @note Only editable controls should calls this.
340 * @param[in] enabled Whether the cursor should blink or not.
342 void SetEnableCursorBlink(bool enable);
345 * @brief Query whether cursor blink is enabled.
347 * @return Whether the cursor should blink or not.
349 bool GetEnableCursorBlink() const;
352 * @brief Whether to enable the multi-line layout.
354 * @param[in] enable \e true enables the multi-line (by default)
356 void SetMultiLineEnabled(bool enable);
359 * @return Whether the multi-line layout is enabled.
361 bool IsMultiLineEnabled() const;
364 * @brief Sets the text's horizontal alignment.
366 * @param[in] alignment The horizontal alignment.
368 void SetHorizontalAlignment(HorizontalAlignment::Type alignment);
371 * @copydoc ModelInterface::GetHorizontalAlignment()
373 HorizontalAlignment::Type GetHorizontalAlignment() const;
376 * @brief Sets the text's vertical alignment.
378 * @param[in] alignment The vertical alignment.
380 void SetVerticalAlignment(VerticalAlignment::Type alignment);
383 * @copydoc ModelInterface::GetVerticalAlignment()
385 VerticalAlignment::Type GetVerticalAlignment() const;
388 * @brief Sets the text's wrap mode
389 * @param[in] text wrap mode The unit of wrapping
391 void SetLineWrapMode(Text::LineWrap::Mode textWarpMode);
394 * @brief Retrieve text wrap mode previously set.
395 * @return text wrap mode
397 Text::LineWrap::Mode GetLineWrapMode() const;
400 * @brief Enable or disable the text elide.
402 * @param[in] enabled Whether to enable the text elide.
404 void SetTextElideEnabled(bool enabled);
407 * @copydoc ModelInterface::IsTextElideEnabled()
409 bool IsTextElideEnabled() const;
412 * @brief Enable or disable the text fit.
414 * @param[in] enabled Whether to enable the text fit.
416 void SetTextFitEnabled(bool enabled);
419 * @brief Whether the text fit is enabled or not.
421 * @return True if the text fit is enabled
423 bool IsTextFitEnabled() const;
426 * @brief Sets minimum size valid for text fit.
428 * @param[in] minimum size value.
429 * @param[in] type The font size type is point size or pixel size
431 void SetTextFitMinSize(float pointSize, FontSizeType type);
434 * @brief Retrieves the minimum point size valid for text fit.
436 * @return The minimum point size valid for text fit
438 float GetTextFitMinSize() const;
441 * @brief Sets maximum size valid for text fit.
443 * @param[in] maximum size value.
444 * @param[in] type The font size type is point size or pixel size
446 void SetTextFitMaxSize(float pointSize, FontSizeType type);
449 * @brief Retrieves the maximum point size valid for text fit.
451 * @return The maximum point size valid for text fit
453 float GetTextFitMaxSize() const;
456 * @brief Sets step size for font increase valid for text fit.
458 * @param[in] step size value.
459 * @param[in] type The font size type is point size or pixel size
461 void SetTextFitStepSize(float step, FontSizeType type);
464 * @brief Retrieves the step point size valid for text fit.
466 * @return The step point size valid for text fit
468 float GetTextFitStepSize() const;
471 * @brief Sets content size valid for text fit.
473 * @param[in] Content size value.
475 void SetTextFitContentSize(Vector2 size);
478 * @brief Retrieves the content size valid for text fit.
480 * @return The content size valid for text fit
482 Vector2 GetTextFitContentSize() const;
485 * @brief Retrieve the fited point size.
487 * @return The fited point size.
489 float GetTextFitPointSize() const;
492 * @brief Sets whether the text fit properties have changed.
494 * @param[in] changed Whether to changed the text fit.
496 void SetTextFitChanged(bool changed);
499 * @brief Whether the text fit properties are changed or not.
501 * @return True if the text fit properties are changed
503 bool IsTextFitChanged() const;
506 * @brief Enable or disable the placeholder text elide.
507 * @param enabled Whether to enable the placeholder text elide.
509 void SetPlaceholderTextElideEnabled(bool enabled);
512 * @brief Whether the placeholder text elide property is enabled.
513 * @return True if the placeholder text elide property is enabled, false otherwise.
515 bool IsPlaceholderTextElideEnabled() const;
518 * @brief Enable or disable the text selection.
519 * @param[in] enabled Whether to enable the text selection.
521 void SetSelectionEnabled(bool enabled);
524 * @brief Whether the text selection is enabled or not.
525 * @return True if the text selection is enabled
527 bool IsSelectionEnabled() const;
530 * @brief Enable or disable the text selection using Shift key.
531 * @param enabled Whether to enable the text selection using Shift key
533 void SetShiftSelectionEnabled(bool enabled);
536 * @brief Whether the text selection using Shift key is enabled or not.
537 * @return True if the text selection using Shift key is enabled
539 bool IsShiftSelectionEnabled() const;
542 * @brief Enable or disable the grab handles for text selection.
544 * @param[in] enabled Whether to enable the grab handles
546 void SetGrabHandleEnabled(bool enabled);
549 * @brief Returns whether the grab handles are enabled.
551 * @return True if the grab handles are enabled
553 bool IsGrabHandleEnabled() const;
556 * @brief Enable or disable the grab handles for text selection.
558 * @param[in] enabled Whether to enable the grab handles
560 void SetGrabHandlePopupEnabled(bool enabled);
563 * @brief Returns whether the grab handles are enabled.
565 * @return True if the grab handles are enabled
567 bool IsGrabHandlePopupEnabled() const;
570 * @brief Sets input type to password
572 * @note The string is displayed hidden character
574 * @param[in] passwordInput True if password input is enabled.
576 void SetInputModePassword(bool passwordInput);
579 * @brief Returns whether the input mode type is set as password.
581 * @return True if input mode type is password
583 bool IsInputModePassword();
586 * @brief Sets the action when there is a double tap event on top of a text area with no text.
588 * @param[in] action The action to do.
590 void SetNoTextDoubleTapAction(NoTextTap::Action action);
593 * @brief Retrieves the action when there is a double tap event on top of a text area with no text.
595 * @return The action to do.
597 NoTextTap::Action GetNoTextDoubleTapAction() const;
600 * @briefSets the action when there is a long press event on top of a text area with no text.
602 * @param[in] action The action to do.
604 void SetNoTextLongPressAction(NoTextTap::Action action);
607 * @brief Retrieves the action when there is a long press event on top of a text area with no text.
609 * @return The action to do.
611 NoTextTap::Action GetNoTextLongPressAction() const;
614 * @brief Query if Underline settings were provided by string or map
615 * @return bool true if set by string
617 bool IsUnderlineSetByString();
620 * Set method underline setting were set by
621 * @param[in] bool, true if set by string
623 void UnderlineSetByString(bool setByString);
626 * @brief Query if shadow settings were provided by string or map
627 * @return bool true if set by string
629 bool IsShadowSetByString();
632 * Set method shadow setting were set by
633 * @param[in] bool, true if set by string
635 void ShadowSetByString(bool setByString);
638 * @brief Query if outline settings were provided by string or map
639 * @return bool true if set by string
641 bool IsOutlineSetByString();
644 * Set method outline setting were set by
645 * @param[in] bool, true if set by string
647 void OutlineSetByString(bool setByString);
650 * @brief Query if font style settings were provided by string or map
651 * @return bool true if set by string
653 bool IsFontStyleSetByString();
656 * Set method font style setting were set by
657 * @param[in] bool, true if set by string
659 void FontStyleSetByString(bool setByString);
663 * @brief Replaces any text previously set.
665 * @note This will be converted into UTF-32 when stored in the text model.
666 * @param[in] text A string of UTF-8 characters.
668 void SetText(const std::string& text);
671 * @brief Retrieve any text previously set.
673 * @param[out] text A string of UTF-8 characters.
675 void GetText(std::string& text) const;
678 * @brief Replaces any placeholder text previously set.
680 * @param[in] type Different placeholder-text can be shown when the control is active/inactive.
681 * @param[in] text A string of UTF-8 characters.
683 void SetPlaceholderText(PlaceholderType type, const std::string& text);
686 * @brief Retrieve any placeholder text previously set.
688 * @param[in] type Different placeholder-text can be shown when the control is active/inactive.
689 * @param[out] A string of UTF-8 characters.
691 void GetPlaceholderText(PlaceholderType type, std::string& text) const;
694 * @ brief Update the text after a font change
695 * @param[in] newDefaultFont The new font to change to
697 void UpdateAfterFontChange(const std::string& newDefaultFont);
700 * @brief The method acquires currently selected text
701 * @param selectedText variable to place selected text in
703 void RetrieveSelection(std::string& selectedText) const;
706 * @brief The method sets selection in given range
707 * @param start index of first character
708 * @param end index of first character after selection
710 void SetSelection(int start, int end);
713 * @brief This method retrieve indexes of current selection
715 * @return a pair, where first element is left index of selection and second is the right one
717 std::pair<int, int> GetSelectionIndexes() const;
720 * Place string in system clipboard
721 * @param source std::string
723 void CopyStringToClipboard(const std::string& source);
726 * Place currently selected text in system clipboard
727 * @param deleteAfterSending flag pointing if text should be deleted after sending to clipboard
729 void SendSelectionToClipboard(bool deleteAfterSending);
731 public: // Default style & Input style
733 * @brief Set the default font family.
735 * @param[in] defaultFontFamily The default font family.
737 void SetDefaultFontFamily(const std::string& defaultFontFamily);
740 * @brief Retrieve the default font family.
742 * @return The default font family.
744 const std::string& GetDefaultFontFamily() const;
747 * @brief Sets the placeholder text font family.
748 * @param[in] placeholderTextFontFamily The placeholder text font family.
750 void SetPlaceholderFontFamily(const std::string& placeholderTextFontFamily);
753 * @brief Retrieves the placeholder text font family.
755 * @return The placeholder text font family
757 const std::string& GetPlaceholderFontFamily() const;
760 * @brief Sets the default font weight.
762 * @param[in] weight The font weight.
764 void SetDefaultFontWeight(FontWeight weight);
767 * @brief Whether the font's weight has been defined.
769 bool IsDefaultFontWeightDefined() const;
772 * @brief Retrieves the default font weight.
774 * @return The default font weight.
776 FontWeight GetDefaultFontWeight() const;
779 * @brief Sets the placeholder text font weight.
781 * @param[in] weight The font weight
783 void SetPlaceholderTextFontWeight(FontWeight weight);
786 * @brief Whether the font's weight has been defined.
788 * @return True if the placeholder text font weight is defined
790 bool IsPlaceholderTextFontWeightDefined() const;
793 * @brief Retrieves the placeholder text font weight.
795 * @return The placeholder text font weight
797 FontWeight GetPlaceholderTextFontWeight() const;
800 * @brief Sets the default font width.
802 * @param[in] width The font width.
804 void SetDefaultFontWidth(FontWidth width);
807 * @brief Whether the font's width has been defined.
809 bool IsDefaultFontWidthDefined() const;
812 * @brief Retrieves the default font width.
814 * @return The default font width.
816 FontWidth GetDefaultFontWidth() const;
819 * @brief Sets the placeholder text font width.
821 * @param[in] width The font width
823 void SetPlaceholderTextFontWidth(FontWidth width);
826 * @brief Whether the font's width has been defined.
828 * @return True if the placeholder text font width is defined
830 bool IsPlaceholderTextFontWidthDefined() const;
833 * @brief Retrieves the placeholder text font width.
835 * @return The placeholder text font width
837 FontWidth GetPlaceholderTextFontWidth() const;
840 * @brief Sets the default font slant.
842 * @param[in] slant The font slant.
844 void SetDefaultFontSlant(FontSlant slant);
847 * @brief Whether the font's slant has been defined.
849 bool IsDefaultFontSlantDefined() const;
852 * @brief Retrieves the default font slant.
854 * @return The default font slant.
856 FontSlant GetDefaultFontSlant() const;
859 * @brief Sets the placeholder text font slant.
861 * @param[in] slant The font slant
863 void SetPlaceholderTextFontSlant(FontSlant slant);
866 * @brief Whether the font's slant has been defined.
868 * @return True if the placeholder text font slant is defined
870 bool IsPlaceholderTextFontSlantDefined() const;
873 * @brief Retrieves the placeholder text font slant.
875 * @return The placeholder text font slant
877 FontSlant GetPlaceholderTextFontSlant() const;
880 * @brief Set the default font size.
882 * @param[in] fontSize The default font size
883 * @param[in] type The font size type is point size or pixel size
885 void SetDefaultFontSize(float fontSize, FontSizeType type);
888 * @brief Retrieve the default point size.
890 * @param[in] type The font size type
891 * @return The default point size.
893 float GetDefaultFontSize(FontSizeType type) const;
896 * @brief Set the font size scale.
898 * @param[in] scale The font size scale
900 void SetFontSizeScale(float scale);
903 * @brief Get the font size scale.
905 * @return The font size scale.
907 float GetFontSizeScale() const;
910 * @brief Sets the Placeholder text font size.
911 * @param[in] fontSize The placeholder text font size
912 * @param[in] type The font size type is point size or pixel size
914 void SetPlaceholderTextFontSize(float fontSize, FontSizeType type);
917 * @brief Retrieves the Placeholder text font size.
918 * @param[in] type The font size type
919 * @return The placeholder font size
921 float GetPlaceholderTextFontSize(FontSizeType type) const;
924 * @brief Sets the text's default color.
926 * @param color The default color.
928 void SetDefaultColor(const Vector4& color);
931 * @brief Retrieves the text's default color.
933 * @return The default color.
935 const Vector4& GetDefaultColor() const;
938 * @brief Set the text color
940 * @param textColor The text color
942 void SetPlaceholderTextColor(const Vector4& textColor);
945 * @brief Retrieve the text color
947 * @return The text color
949 const Vector4& GetPlaceholderTextColor() const;
952 * @brief Set the shadow offset.
954 * @param[in] shadowOffset The shadow offset, 0,0 indicates no shadow.
956 void SetShadowOffset(const Vector2& shadowOffset);
959 * @brief Retrieve the shadow offset.
961 * @return The shadow offset.
963 const Vector2& GetShadowOffset() const;
966 * @brief Set the shadow color.
968 * @param[in] shadowColor The shadow color.
970 void SetShadowColor(const Vector4& shadowColor);
973 * @brief Retrieve the shadow color.
975 * @return The shadow color.
977 const Vector4& GetShadowColor() const;
980 * @brief Set the shadow blur radius.
982 * @param[in] shadowBlurRadius The shadow blur radius, 0,0 indicates no blur.
984 void SetShadowBlurRadius(const float& shadowBlurRadius);
987 * @brief Retrieve the shadow blur radius.
989 * @return The shadow blur radius.
991 const float& GetShadowBlurRadius() const;
994 * @brief Set the underline color.
996 * @param[in] color color of underline.
998 void SetUnderlineColor(const Vector4& color);
1001 * @brief Retrieve the underline color.
1003 * @return The underline color.
1005 const Vector4& GetUnderlineColor() const;
1008 * @brief Set the underline enabled flag.
1010 * @param[in] enabled The underline enabled flag.
1012 void SetUnderlineEnabled(bool enabled);
1015 * @brief Returns whether the text is underlined or not.
1017 * @return The underline state.
1019 bool IsUnderlineEnabled() const;
1022 * @brief Set the override used for underline height, 0 indicates height will be supplied by font metrics
1024 * @param[in] height The height in pixels of the underline
1026 void SetUnderlineHeight(float height);
1029 * @brief Retrieves the override height of an underline, 0 indicates height is supplied by font metrics
1031 * @return The height of the underline, or 0 if height is not overrided.
1033 float GetUnderlineHeight() const;
1036 * @brief Set the outline color.
1038 * @param[in] color color of outline.
1040 void SetOutlineColor(const Vector4& color);
1043 * @brief Retrieve the outline color.
1045 * @return The outline color.
1047 const Vector4& GetOutlineColor() const;
1050 * @brief Set the outline width
1052 * @param[in] width The width in pixels of the outline, 0 indicates no outline
1054 void SetOutlineWidth(uint16_t width);
1057 * @brief Retrieves the width of an outline
1059 * @return The width of the outline.
1061 uint16_t GetOutlineWidth() const;
1064 * @brief Set the background color.
1066 * @param[in] color color of background.
1068 void SetBackgroundColor(const Vector4& color);
1071 * @brief Retrieve the background color.
1073 * @return The background color.
1075 const Vector4& GetBackgroundColor() const;
1078 * @brief Set the background enabled flag.
1080 * @param[in] enabled The background enabled flag.
1082 void SetBackgroundEnabled(bool enabled);
1085 * @brief Returns whether to enable text background or not.
1087 * @return Whether text background is enabled.
1089 bool IsBackgroundEnabled() const;
1092 * @brief Sets the emboss's properties string.
1094 * @note The string is stored to be recovered.
1096 * @param[in] embossProperties The emboss's properties string.
1098 void SetDefaultEmbossProperties(const std::string& embossProperties);
1101 * @brief Retrieves the emboss's properties string.
1103 * @return The emboss's properties string.
1105 const std::string& GetDefaultEmbossProperties() const;
1108 * @brief Sets the outline's properties string.
1110 * @note The string is stored to be recovered.
1112 * @param[in] outlineProperties The outline's properties string.
1114 void SetDefaultOutlineProperties(const std::string& outlineProperties);
1117 * @brief Retrieves the outline's properties string.
1119 * @return The outline's properties string.
1121 const std::string& GetDefaultOutlineProperties() const;
1124 * @brief Sets the default line spacing.
1126 * @param[in] lineSpacing The line spacing.
1128 * @return True if lineSpacing has been updated, false otherwise
1130 bool SetDefaultLineSpacing(float lineSpacing);
1133 * @brief Retrieves the default line spacing.
1135 * @return The line spacing.
1137 float GetDefaultLineSpacing() const;
1140 * @brief Sets the default line size.
1142 * @param[in] lineSize The line size.
1144 * @return True if lineSize has been updated, false otherwise
1146 bool SetDefaultLineSize(float lineSize);
1149 * @brief Retrieves the default line size.
1151 * @return The line size.
1153 float GetDefaultLineSize() const;
1156 * @brief Sets the input text's color.
1158 * @param[in] color The input text's color.
1160 void SetInputColor(const Vector4& color);
1163 * @brief Retrieves the input text's color.
1165 * @return The input text's color.
1167 const Vector4& GetInputColor() const;
1170 * @brief Sets the input text's font family name.
1172 * @param[in] fontFamily The text's font family name.
1174 void SetInputFontFamily(const std::string& fontFamily);
1177 * @brief Retrieves the input text's font family name.
1179 * @return The input text's font family name.
1181 const std::string& GetInputFontFamily() const;
1184 * @brief Sets the input font's weight.
1186 * @param[in] weight The input font's weight.
1188 void SetInputFontWeight(FontWeight weight);
1191 * @return Whether the font's weight has been defined.
1193 bool IsInputFontWeightDefined() const;
1196 * @brief Retrieves the input font's weight.
1198 * @return The input font's weight.
1200 FontWeight GetInputFontWeight() const;
1203 * @brief Sets the input font's width.
1205 * @param[in] width The input font's width.
1207 void SetInputFontWidth(FontWidth width);
1210 * @return Whether the font's width has been defined.
1212 bool IsInputFontWidthDefined() const;
1215 * @brief Retrieves the input font's width.
1217 * @return The input font's width.
1219 FontWidth GetInputFontWidth() const;
1222 * @brief Sets the input font's slant.
1224 * @param[in] slant The input font's slant.
1226 void SetInputFontSlant(FontSlant slant);
1229 * @return Whether the font's slant has been defined.
1231 bool IsInputFontSlantDefined() const;
1234 * @brief Retrieves the input font's slant.
1236 * @return The input font's slant.
1238 FontSlant GetInputFontSlant() const;
1241 * @brief Sets the input font's point size.
1243 * @param[in] size The input font's point size.
1245 void SetInputFontPointSize(float size);
1248 * @brief Retrieves the input font's point size.
1250 * @return The input font's point size.
1252 float GetInputFontPointSize() const;
1255 * @brief Sets the input line spacing.
1257 * @param[in] lineSpacing The line spacing.
1259 void SetInputLineSpacing(float lineSpacing);
1262 * @brief Retrieves the input line spacing.
1264 * @return The line spacing.
1266 float GetInputLineSpacing() const;
1269 * @brief Sets the input shadow's properties string.
1271 * @note The string is stored to be recovered.
1273 * @param[in] shadowProperties The shadow's properties string.
1275 void SetInputShadowProperties(const std::string& shadowProperties);
1278 * @brief Retrieves the input shadow's properties string.
1280 * @return The shadow's properties string.
1282 const std::string& GetInputShadowProperties() const;
1285 * @brief Sets the input underline's properties string.
1287 * @note The string is stored to be recovered.
1289 * @param[in] underlineProperties The underline's properties string.
1291 void SetInputUnderlineProperties(const std::string& underlineProperties);
1294 * @brief Retrieves the input underline's properties string.
1296 * @return The underline's properties string.
1298 const std::string& GetInputUnderlineProperties() const;
1301 * @brief Sets the input emboss's properties string.
1303 * @note The string is stored to be recovered.
1305 * @param[in] embossProperties The emboss's properties string.
1307 void SetInputEmbossProperties(const std::string& embossProperties);
1310 * @brief Retrieves the input emboss's properties string.
1312 * @return The emboss's properties string.
1314 const std::string& GetInputEmbossProperties() const;
1317 * @brief Sets input the outline's properties string.
1319 * @note The string is stored to be recovered.
1321 * @param[in] outlineProperties The outline's properties string.
1323 void SetInputOutlineProperties(const std::string& outlineProperties);
1326 * @brief Retrieves the input outline's properties string.
1328 * @return The outline's properties string.
1330 const std::string& GetInputOutlineProperties() const;
1333 * @brief Set the control's interface.
1335 * @param[in] controlInterface The control's interface.
1337 void SetControlInterface(ControlInterface* controlInterface);
1340 * @brief Set the anchor control's interface.
1342 * @param[in] anchorControlInterface The control's interface.
1344 void SetAnchorControlInterface(AnchorControlInterface* anchorControlInterface);
1346 public: // Queries & retrieves.
1348 * @brief Return the layout engine.
1350 * @return A reference to the layout engine.
1352 Layout::Engine& GetLayoutEngine();
1355 * @brief Return a view of the text.
1357 * @return A reference to the view.
1362 * @copydoc Control::GetNaturalSize()
1364 Vector3 GetNaturalSize();
1367 * @copydoc Control::GetHeightForWidth()
1369 float GetHeightForWidth(float width);
1372 * @brief Calculates the point size for text for given layout()
1374 void FitPointSizeforLayout(Size layoutSize);
1377 * @brief Checks if the point size fits within the layout size.
1379 * @return Whether the point size fits within the layout size.
1381 bool CheckForTextFit(float pointSize, Size& layoutSize);
1384 * @brief Retrieves the text's number of lines for a given width.
1385 * @param[in] width The width of the text's area.
1386 * @ return The number of lines.
1388 int GetLineCount(float width);
1391 * @brief Retrieves the text's model.
1393 * @return A pointer to the text's model.
1395 const ModelInterface* const GetTextModel() const;
1398 * @brief Used to get scrolled distance by user input
1400 * @return Distance from last scroll offset to new scroll offset
1402 float GetScrollAmountByUserInput();
1405 * @brief Get latest scroll amount, control size and layout size
1407 * This method is used to get information of control's scroll
1408 * @param[out] scrollPosition The current scrolled position
1409 * @param[out] controlHeight The size of a UI control
1410 * @param[out] layoutHeight The size of a bounding box to layout text within.
1412 * @return Whether the text scroll position is changed or not after last update.
1414 bool GetTextScrollInfo(float& scrollPosition, float& controlHeight, float& layoutHeight);
1417 * @brief Used to set the hidden input option
1419 void SetHiddenInputOption(const Property::Map& options);
1422 * @brief Used to get the hidden input option
1424 void GetHiddenInputOption(Property::Map& options);
1427 * @brief Used to set the input filter option
1429 void SetInputFilterOption(const Property::Map& options);
1432 * @brief Used to get the input filter option
1434 void GetInputFilterOption(Property::Map& options);
1437 * @brief Sets the Placeholder Properties.
1439 * @param[in] map The placeholder property map
1441 void SetPlaceholderProperty(const Property::Map& map);
1444 * @brief Retrieves the Placeholder Property map.
1446 * @param[out] map The property map
1448 void GetPlaceholderProperty(Property::Map& map);
1451 * @brief Checks text direction.
1452 * @return The text direction.
1454 Toolkit::DevelText::TextDirection::Type GetTextDirection();
1457 * @brief Retrieves vertical line alignment
1458 * @return The vertical line alignment
1460 Toolkit::DevelText::VerticalLineAlignment::Type GetVerticalLineAlignment() const;
1463 * @brief Sets vertical line alignment
1464 * @param[in] alignment The vertical line alignment for the text
1466 void SetVerticalLineAlignment(Toolkit::DevelText::VerticalLineAlignment::Type alignment);
1469 * @brief Retrieves ellipsis position
1470 * @return The ellipsis position
1472 Toolkit::DevelText::EllipsisPosition::Type GetEllipsisPosition() const;
1475 * @brief Sets ellipsis position
1476 * @param[in] ellipsisPosition The ellipsis position for the text
1478 void SetEllipsisPosition(Toolkit::DevelText::EllipsisPosition::Type ellipsisPosition);
1481 * @brief Retrieves ignoreSpaceAfterText value from model
1482 * @return The value of ignoreSpaceAfterText
1484 bool IsIgnoreSpacesAfterText() const;
1487 * @brief Sets ignoreSpaceAfterText value to model
1488 * @param[in] ignore The value of ignoreSpacesAfterText for the text
1490 void SetIgnoreSpacesAfterText(bool ignore);
1493 * @brief Sets SetMatchLayoutDirection value to model
1494 * @param[in] match The value of matchLayoutDirection for the text
1496 void SetMatchLayoutDirection(DevelText::MatchLayoutDirection type);
1499 * @brief Retrieves matchLayoutDirection value from model
1500 * @return The value of matchLayoutDirection
1502 DevelText::MatchLayoutDirection GetMatchLayoutDirection() const;
1505 * @brief Sets layoutDirection type value.
1506 * @param[in] layoutDirection The value of the layout direction type.
1508 void SetLayoutDirection(Dali::LayoutDirection::Type layoutDirection);
1511 * @brief Gets layoutDirection type value.
1512 * @param[in] actor The actor which will get the layout direction type.
1513 * @return The value of the layout direction type.
1515 Dali::LayoutDirection::Type GetLayoutDirection(Dali::Actor& actor) const;
1518 * @brief Sets the layout direction changed.
1520 void ChangedLayoutDirection();
1523 * @brief Retrieves if showing real text or not.
1524 * @return The value of showing real text.
1526 bool IsShowingRealText() const;
1528 public: // Relayout.
1530 * @brief Triggers a relayout which updates View (if necessary).
1532 * @note UI Controls are expected to minimize calls to this method e.g. call once after size negotiation.
1533 * @param[in] size A the size of a bounding box to layout text within.
1534 * @param[in] layoutDirection The direction of the system language.
1536 * @return Whether the text model or decorations were updated.
1538 UpdateTextType Relayout(const Size& size, Dali::LayoutDirection::Type layoutDirection = Dali::LayoutDirection::LEFT_TO_RIGHT);
1541 * @brief Request a relayout using the ControlInterface.
1543 void RequestRelayout();
1545 public: // Input style change signals.
1547 * @return Whether the queue of input style changed signals is empty.
1549 bool IsInputStyleChangedSignalsQueueEmpty();
1552 * @brief Process all pending input style changed signals.
1554 * Calls the Text::ControlInterface::InputStyleChanged() method which is overriden by the
1555 * text controls. Text controls may send signals to state the input style has changed.
1557 void ProcessInputStyleChangedSignals();
1559 public: // Text-input Event Queuing.
1561 * @brief Called by editable UI controls when keyboard focus is gained.
1563 void KeyboardFocusGainEvent();
1566 * @brief Called by editable UI controls when focus is lost.
1568 void KeyboardFocusLostEvent();
1571 * @brief Called by editable UI controls when key events are received.
1573 * @param[in] event The key event.
1574 * @param[in] type Used to distinguish between regular key events and InputMethodContext events.
1576 bool KeyEvent(const Dali::KeyEvent& event);
1579 * @brief Called by anchor when a tap gesture occurs.
1580 * @param[in] x The x position relative to the top-left of the parent control.
1581 * @param[in] y The y position relative to the top-left of the parent control.
1583 void AnchorEvent(float x, float y);
1586 * @brief Called by editable UI controls when a tap gesture occurs.
1587 * @param[in] tapCount The number of taps.
1588 * @param[in] x The x position relative to the top-left of the parent control.
1589 * @param[in] y The y position relative to the top-left of the parent control.
1591 void TapEvent(unsigned int tapCount, float x, float y);
1594 * @brief Called by editable UI controls when a pan gesture occurs.
1596 * @param[in] state The state of the gesture.
1597 * @param[in] displacement This distance panned since the last pan gesture.
1599 void PanEvent(GestureState state, const Vector2& displacement);
1602 * @brief Called by editable UI controls when a long press gesture occurs.
1604 * @param[in] state The state of the gesture.
1605 * @param[in] x The x position relative to the top-left of the parent control.
1606 * @param[in] y The y position relative to the top-left of the parent control.
1608 void LongPressEvent(GestureState state, float x, float y);
1611 * @brief Used to get the Primary cursor position.
1613 * @return Primary cursor position.
1615 CharacterIndex GetPrimaryCursorPosition() const;
1618 * @brief Used to set the Primary cursor position.
1620 * @param[in] index for the Primary cursor position.
1621 * @param[in] focused true if UI control has gained focus to receive key event, false otherwise.
1622 * @return[in] true if cursor position changed, false otherwise.
1624 bool SetPrimaryCursorPosition(CharacterIndex index, bool focused);
1627 * @brief Creates a selection event.
1629 * It could be called from the TapEvent (double tap) or when the text selection popup's sellect all button is pressed.
1631 * @param[in] x The x position relative to the top-left of the parent control.
1632 * @param[in] y The y position relative to the top-left of the parent control.
1633 * @param[in] selection type like the whole text is selected or unselected.
1635 void SelectEvent(float x, float y, SelectionType selection);
1638 * @brief Creates a selection event with a selection index.
1640 * It could be called from the SelectText().
1641 * The start and end parameters are passed through the event.
1643 * @param[in] start The start selection position.
1644 * @param[in] end The end selection position.
1645 * @param[in] selection type like the range.
1647 void SelectEvent(const uint32_t start, const uint32_t end, SelectionType selection);
1650 * @copydoc Text::SelectableControlInterface::SetTextSelectionRange()
1652 void SetTextSelectionRange(const uint32_t* start, const uint32_t* end);
1655 * @copydoc Text::SelectableControlInterface::GetTextSelectionRange()
1657 Uint32Pair GetTextSelectionRange() const;
1660 * @copydoc Text::SelectableControlInterface::SelectWholeText()
1662 void SelectWholeText();
1665 * @copydoc Text::EditableControlInterface::CopyText()
1670 * @copydoc Text::EditableControlInterface::CutText()
1675 * @copydoc Text::EditableControlInterface::PasteText()
1680 * @copydoc Text::SelectableControlInterface::SelectNone()
1685 * @copydoc Text::SelectableControlInterface::SelectText()
1687 void SelectText(const uint32_t start, const uint32_t end);
1690 * @copydoc Text::SelectableControlInterface::GetSelectedText()
1692 string GetSelectedText() const;
1695 * @copydoc Text::EditableControlInterface::IsEditable()
1697 virtual bool IsEditable() const;
1700 * @copydoc Text::EditableControlInterface::SetEditable()
1702 virtual void SetEditable(bool editable);
1705 * @copydoc Dali::Toolkit::Internal::TextEditor::ScrollBy()
1707 virtual void ScrollBy(Vector2 scroll);
1710 * @copydoc Dali::Toolkit::Internal::TextEditor::GetHorizontalScrollPosition()
1712 float GetHorizontalScrollPosition();
1715 * @copydoc Dali::Toolkit::Internal::TextEditor::GetVerticalScrollPosition()
1717 float GetVerticalScrollPosition();
1720 * @brief Event received from input method context
1722 * @param[in] inputMethodContext The input method context.
1723 * @param[in] inputMethodContextEvent The event received.
1724 * @return A data struture indicating if update is needed, cursor position and current text.
1726 InputMethodContext::CallbackData OnInputMethodContextEvent(InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent);
1729 * @brief Event from Clipboard notifying an Item has been selected for pasting
1731 void PasteClipboardItemEvent();
1734 * @brief Return true when text control should clear key input focus when escape key is pressed.
1736 * @return Whether text control should clear key input focus or not when escape key is pressed.
1738 bool ShouldClearFocusOnEscape() const;
1741 * @brief Create an actor that renders the text background color
1743 * @return the created actor or an empty handle if no background color needs to be rendered.
1745 Actor CreateBackgroundActor();
1748 * @brief Used to reset the cursor position after setting a new text.
1750 * @param[in] cursorIndex Where to place the cursor.
1752 void ResetCursorPosition(CharacterIndex cursorIndex);
1755 * @brief The method acquires current position of cursor
1756 * @return unsigned value with cursor position
1758 CharacterIndex GetCursorPosition();
1760 protected: // Inherit from Text::Decorator::ControllerInterface.
1762 * @copydoc Dali::Toolkit::Text::Decorator::ControllerInterface::GetTargetSize()
1764 void GetTargetSize(Vector2& targetSize) override;
1767 * @copydoc Dali::Toolkit::Text::Decorator::ControllerInterface::AddDecoration()
1769 void AddDecoration(Actor& actor, bool needsClipping) override;
1772 * @copydoc Dali::Toolkit::Text::Decorator::ControllerInterface::DecorationEvent()
1774 void DecorationEvent(HandleType handle, HandleState state, float x, float y) override;
1776 protected: // Inherit from TextSelectionPopup::TextPopupButtonCallbackInterface.
1778 * @copydoc Dali::Toolkit::TextSelectionPopup::TextPopupButtonCallbackInterface::TextPopupButtonTouched()
1780 void TextPopupButtonTouched(Dali::Toolkit::TextSelectionPopup::Buttons button) override;
1782 protected: // Inherit from HiddenText.
1784 * @brief Invoked from HiddenText when showing time of the last character was expired
1786 void DisplayTimeExpired() override;
1790 * @brief Called by editable UI controls when key events are received.
1792 * @param[in] text The text to insert.
1793 * @param[in] type Used to distinguish between regular key events and InputMethodContext events.
1795 void InsertText(const std::string& text, InsertType type);
1798 * @copydoc Text::EditableControlInterface::PasteText()
1800 void PasteText(const std::string& stringToPaste);
1803 * @brief Remove a given number of characters
1805 * When predictve text is used the pre-edit text is removed and inserted again with the new characters.
1806 * The UpdateInputStyleType @type parameter if set to DONT_UPDATE_INPUT_STYLE avoids to update the input
1807 * style when pre-edit text is removed.
1809 * @param[in] cursorOffset Start position from the current cursor position to start deleting characters.
1810 * @param[in] numberOfCharacters The number of characters to delete from the cursorOffset.
1811 * @param[in] type Whether to update the input style.
1812 * @return True if the remove was successful.
1814 bool RemoveText(int cursorOffset,
1815 int numberOfCharacters,
1816 UpdateInputStyleType type);
1819 * @brief Checks if text is selected and if so removes it.
1820 * @return true if text was removed
1822 bool RemoveSelectedText();
1825 * @brief Update anchor position from given number of inserted characters.
1827 * @param[in] numberOfCharacters The number of inserted characters.
1828 * @param[in] previousCursorIndex A cursor position before event occurs.
1830 void InsertTextAnchor(int numberOfCharacters,
1831 CharacterIndex previousCursorIndex);
1834 * @brief Update anchor position from given number of removed characters.
1836 * @param[in] cursorOffset Start position from the current cursor position to start deleting characters.
1837 * @param[in] numberOfCharacters The number of removed characters.
1838 * @param[in] previousCursorIndex A cursor position before event occurs.
1840 void RemoveTextAnchor(int cursorOffset,
1841 int numberOfCharacters,
1842 CharacterIndex previousCursorIndex);
1844 private: // Relayout.
1846 * @brief Lays-out the text.
1848 * GetNaturalSize(), GetHeightForWidth() and Relayout() calls this method.
1850 * @param[in] size A the size of a bounding box to layout text within.
1851 * @param[in] operations The layout operations which need to be done.
1852 * @param[out] layoutSize The size of the laid-out text.
1854 bool DoRelayout(const Size& size,
1855 OperationsMask operations,
1859 * @brief Calulates the vertical offset to align the text inside the bounding box.
1861 * @param[in] size The size of the bounding box.
1863 void CalculateVerticalOffset(const Size& size);
1867 * @brief Process queued events which modify the model.
1869 void ProcessModifyEvents();
1872 * @brief Used to process an event queued from SetText()
1874 void TextReplacedEvent();
1877 * @brief Used to process an event queued from key events etc.
1879 void TextInsertedEvent();
1882 * @brief Used to process an event queued from backspace key etc.
1884 void TextDeletedEvent();
1887 * @brief Helper to KeyEvent() to handle the backspace or delete key case.
1889 * @param[in] keyCode The keycode for the key pressed
1890 * @return True if a character was deleted.
1892 bool DeleteEvent(int keyCode);
1894 private: // Helpers.
1896 * @brief Used to remove the text included the placeholder text.
1901 * @brief Helper to show the place holder text..
1903 void ShowPlaceholderText();
1906 * @brief Helper to clear font-specific data (only).
1908 void ClearFontData();
1911 * @brief Helper to clear text's style data.
1913 void ClearStyleData();
1916 * @brief Used to reset the scroll position after setting a new text.
1918 void ResetScrollPosition();
1921 * @brief fill needed relayout parameters when line size is changed & request relayout.
1923 void RelayoutForNewLineSize();
1925 private: // Private contructors & copy operator.
1927 * @brief Private constructor.
1930 : Controller(nullptr, nullptr, nullptr, nullptr)
1935 * @brief Private constructor.
1937 Controller(ControlInterface* controlInterface)
1938 : Controller(controlInterface, nullptr, nullptr, nullptr)
1943 * @brief Private constructor.
1945 Controller(ControlInterface* controlInterface,
1946 EditableControlInterface* editableControlInterface,
1947 SelectableControlInterface* selectableControlInterface,
1948 AnchorControlInterface* anchorControlInterface);
1950 Controller(const Controller& handle) = delete;
1951 Controller& operator=(const Controller& handle) = delete;
1953 protected: // Destructor.
1955 * @brief A reference counted object may only be deleted by calling Unreference().
1957 virtual ~Controller();
1960 struct Impl; ///< Made public for testing purposes
1963 struct EventHandler;
1964 struct InputFontHandler;
1965 struct PlaceholderHandler;
1972 } // namespace Dali::Toolkit::Text
1974 #endif // DALI_TOOLKIT_TEXT_CONTROLLER_H