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 Enable or disable the placeholder text elide.
486 * @param enabled Whether to enable the placeholder text elide.
488 void SetPlaceholderTextElideEnabled(bool enabled);
491 * @brief Whether the placeholder text elide property is enabled.
492 * @return True if the placeholder text elide property is enabled, false otherwise.
494 bool IsPlaceholderTextElideEnabled() const;
497 * @brief Enable or disable the text selection.
498 * @param[in] enabled Whether to enable the text selection.
500 void SetSelectionEnabled(bool enabled);
503 * @brief Whether the text selection is enabled or not.
504 * @return True if the text selection is enabled
506 bool IsSelectionEnabled() const;
509 * @brief Enable or disable the text selection using Shift key.
510 * @param enabled Whether to enable the text selection using Shift key
512 void SetShiftSelectionEnabled(bool enabled);
515 * @brief Whether the text selection using Shift key is enabled or not.
516 * @return True if the text selection using Shift key is enabled
518 bool IsShiftSelectionEnabled() const;
521 * @brief Enable or disable the grab handles for text selection.
523 * @param[in] enabled Whether to enable the grab handles
525 void SetGrabHandleEnabled(bool enabled);
528 * @brief Returns whether the grab handles are enabled.
530 * @return True if the grab handles are enabled
532 bool IsGrabHandleEnabled() const;
535 * @brief Enable or disable the grab handles for text selection.
537 * @param[in] enabled Whether to enable the grab handles
539 void SetGrabHandlePopupEnabled(bool enabled);
542 * @brief Returns whether the grab handles are enabled.
544 * @return True if the grab handles are enabled
546 bool IsGrabHandlePopupEnabled() const;
549 * @brief Sets input type to password
551 * @note The string is displayed hidden character
553 * @param[in] passwordInput True if password input is enabled.
555 void SetInputModePassword(bool passwordInput);
558 * @brief Returns whether the input mode type is set as password.
560 * @return True if input mode type is password
562 bool IsInputModePassword();
565 * @brief Sets the action when there is a double tap event on top of a text area with no text.
567 * @param[in] action The action to do.
569 void SetNoTextDoubleTapAction(NoTextTap::Action action);
572 * @brief Retrieves the action when there is a double tap event on top of a text area with no text.
574 * @return The action to do.
576 NoTextTap::Action GetNoTextDoubleTapAction() const;
579 * @briefSets the action when there is a long press event on top of a text area with no text.
581 * @param[in] action The action to do.
583 void SetNoTextLongPressAction(NoTextTap::Action action);
586 * @brief Retrieves the action when there is a long press event on top of a text area with no text.
588 * @return The action to do.
590 NoTextTap::Action GetNoTextLongPressAction() const;
593 * @brief Query if Underline settings were provided by string or map
594 * @return bool true if set by string
596 bool IsUnderlineSetByString();
599 * Set method underline setting were set by
600 * @param[in] bool, true if set by string
602 void UnderlineSetByString(bool setByString);
605 * @brief Query if shadow settings were provided by string or map
606 * @return bool true if set by string
608 bool IsShadowSetByString();
611 * Set method shadow setting were set by
612 * @param[in] bool, true if set by string
614 void ShadowSetByString(bool setByString);
617 * @brief Query if outline settings were provided by string or map
618 * @return bool true if set by string
620 bool IsOutlineSetByString();
623 * Set method outline setting were set by
624 * @param[in] bool, true if set by string
626 void OutlineSetByString(bool setByString);
629 * @brief Query if font style settings were provided by string or map
630 * @return bool true if set by string
632 bool IsFontStyleSetByString();
635 * Set method font style setting were set by
636 * @param[in] bool, true if set by string
638 void FontStyleSetByString(bool setByString);
642 * @brief Replaces any text previously set.
644 * @note This will be converted into UTF-32 when stored in the text model.
645 * @param[in] text A string of UTF-8 characters.
647 void SetText(const std::string& text);
650 * @brief Retrieve any text previously set.
652 * @param[out] text A string of UTF-8 characters.
654 void GetText(std::string& text) const;
657 * @brief Replaces any placeholder text previously set.
659 * @param[in] type Different placeholder-text can be shown when the control is active/inactive.
660 * @param[in] text A string of UTF-8 characters.
662 void SetPlaceholderText(PlaceholderType type, const std::string& text);
665 * @brief Retrieve any placeholder text previously set.
667 * @param[in] type Different placeholder-text can be shown when the control is active/inactive.
668 * @param[out] A string of UTF-8 characters.
670 void GetPlaceholderText(PlaceholderType type, std::string& text) const;
673 * @ brief Update the text after a font change
674 * @param[in] newDefaultFont The new font to change to
676 void UpdateAfterFontChange(const std::string& newDefaultFont);
679 * @brief The method acquires currently selected text
680 * @param selectedText variable to place selected text in
682 void RetrieveSelection(std::string& selectedText) const;
685 * @brief The method sets selection in given range
686 * @param start index of first character
687 * @param end index of first character after selection
689 void SetSelection(int start, int end);
692 * @brief This method retrieve indexes of current selection
694 * @return a pair, where first element is left index of selection and second is the right one
696 std::pair<int, int> GetSelectionIndexes() const;
699 * Place string in system clipboard
700 * @param source std::string
702 void CopyStringToClipboard(const std::string& source);
705 * Place currently selected text in system clipboard
706 * @param deleteAfterSending flag pointing if text should be deleted after sending to clipboard
708 void SendSelectionToClipboard(bool deleteAfterSending);
710 public: // Default style & Input style
712 * @brief Set the default font family.
714 * @param[in] defaultFontFamily The default font family.
716 void SetDefaultFontFamily(const std::string& defaultFontFamily);
719 * @brief Retrieve the default font family.
721 * @return The default font family.
723 const std::string& GetDefaultFontFamily() const;
726 * @brief Sets the placeholder text font family.
727 * @param[in] placeholderTextFontFamily The placeholder text font family.
729 void SetPlaceholderFontFamily(const std::string& placeholderTextFontFamily);
732 * @brief Retrieves the placeholder text font family.
734 * @return The placeholder text font family
736 const std::string& GetPlaceholderFontFamily() const;
739 * @brief Sets the default font weight.
741 * @param[in] weight The font weight.
743 void SetDefaultFontWeight(FontWeight weight);
746 * @brief Whether the font's weight has been defined.
748 bool IsDefaultFontWeightDefined() const;
751 * @brief Retrieves the default font weight.
753 * @return The default font weight.
755 FontWeight GetDefaultFontWeight() const;
758 * @brief Sets the placeholder text font weight.
760 * @param[in] weight The font weight
762 void SetPlaceholderTextFontWeight(FontWeight weight);
765 * @brief Whether the font's weight has been defined.
767 * @return True if the placeholder text font weight is defined
769 bool IsPlaceholderTextFontWeightDefined() const;
772 * @brief Retrieves the placeholder text font weight.
774 * @return The placeholder text font weight
776 FontWeight GetPlaceholderTextFontWeight() const;
779 * @brief Sets the default font width.
781 * @param[in] width The font width.
783 void SetDefaultFontWidth(FontWidth width);
786 * @brief Whether the font's width has been defined.
788 bool IsDefaultFontWidthDefined() const;
791 * @brief Retrieves the default font width.
793 * @return The default font width.
795 FontWidth GetDefaultFontWidth() const;
798 * @brief Sets the placeholder text font width.
800 * @param[in] width The font width
802 void SetPlaceholderTextFontWidth(FontWidth width);
805 * @brief Whether the font's width has been defined.
807 * @return True if the placeholder text font width is defined
809 bool IsPlaceholderTextFontWidthDefined() const;
812 * @brief Retrieves the placeholder text font width.
814 * @return The placeholder text font width
816 FontWidth GetPlaceholderTextFontWidth() const;
819 * @brief Sets the default font slant.
821 * @param[in] slant The font slant.
823 void SetDefaultFontSlant(FontSlant slant);
826 * @brief Whether the font's slant has been defined.
828 bool IsDefaultFontSlantDefined() const;
831 * @brief Retrieves the default font slant.
833 * @return The default font slant.
835 FontSlant GetDefaultFontSlant() const;
838 * @brief Sets the placeholder text font slant.
840 * @param[in] slant The font slant
842 void SetPlaceholderTextFontSlant(FontSlant slant);
845 * @brief Whether the font's slant has been defined.
847 * @return True if the placeholder text font slant is defined
849 bool IsPlaceholderTextFontSlantDefined() const;
852 * @brief Retrieves the placeholder text font slant.
854 * @return The placeholder text font slant
856 FontSlant GetPlaceholderTextFontSlant() const;
859 * @brief Set the default font size.
861 * @param[in] fontSize The default font size
862 * @param[in] type The font size type is point size or pixel size
864 void SetDefaultFontSize(float fontSize, FontSizeType type);
867 * @brief Retrieve the default point size.
869 * @param[in] type The font size type
870 * @return The default point size.
872 float GetDefaultFontSize(FontSizeType type) const;
875 * @brief Set the font size scale.
877 * @param[in] scale The font size scale
879 void SetFontSizeScale(float scale);
882 * @brief Get the font size scale.
884 * @return The font size scale.
886 float GetFontSizeScale() const;
889 * @brief Sets the Placeholder text font size.
890 * @param[in] fontSize The placeholder text font size
891 * @param[in] type The font size type is point size or pixel size
893 void SetPlaceholderTextFontSize(float fontSize, FontSizeType type);
896 * @brief Retrieves the Placeholder text font size.
897 * @param[in] type The font size type
898 * @return The placeholder font size
900 float GetPlaceholderTextFontSize(FontSizeType type) const;
903 * @brief Sets the text's default color.
905 * @param color The default color.
907 void SetDefaultColor(const Vector4& color);
910 * @brief Retrieves the text's default color.
912 * @return The default color.
914 const Vector4& GetDefaultColor() const;
917 * @brief Set the text color
919 * @param textColor The text color
921 void SetPlaceholderTextColor(const Vector4& textColor);
924 * @brief Retrieve the text color
926 * @return The text color
928 const Vector4& GetPlaceholderTextColor() const;
931 * @brief Set the shadow offset.
933 * @param[in] shadowOffset The shadow offset, 0,0 indicates no shadow.
935 void SetShadowOffset(const Vector2& shadowOffset);
938 * @brief Retrieve the shadow offset.
940 * @return The shadow offset.
942 const Vector2& GetShadowOffset() const;
945 * @brief Set the shadow color.
947 * @param[in] shadowColor The shadow color.
949 void SetShadowColor(const Vector4& shadowColor);
952 * @brief Retrieve the shadow color.
954 * @return The shadow color.
956 const Vector4& GetShadowColor() const;
959 * @brief Set the shadow blur radius.
961 * @param[in] shadowBlurRadius The shadow blur radius, 0,0 indicates no blur.
963 void SetShadowBlurRadius(const float& shadowBlurRadius);
966 * @brief Retrieve the shadow blur radius.
968 * @return The shadow blur radius.
970 const float& GetShadowBlurRadius() const;
973 * @brief Set the underline color.
975 * @param[in] color color of underline.
977 void SetUnderlineColor(const Vector4& color);
980 * @brief Retrieve the underline color.
982 * @return The underline color.
984 const Vector4& GetUnderlineColor() const;
987 * @brief Set the underline enabled flag.
989 * @param[in] enabled The underline enabled flag.
991 void SetUnderlineEnabled(bool enabled);
994 * @brief Returns whether the text is underlined or not.
996 * @return The underline state.
998 bool IsUnderlineEnabled() const;
1001 * @brief Set the override used for underline height, 0 indicates height will be supplied by font metrics
1003 * @param[in] height The height in pixels of the underline
1005 void SetUnderlineHeight(float height);
1008 * @brief Retrieves the override height of an underline, 0 indicates height is supplied by font metrics
1010 * @return The height of the underline, or 0 if height is not overrided.
1012 float GetUnderlineHeight() const;
1015 * @brief Set the outline color.
1017 * @param[in] color color of outline.
1019 void SetOutlineColor(const Vector4& color);
1022 * @brief Retrieve the outline color.
1024 * @return The outline color.
1026 const Vector4& GetOutlineColor() const;
1029 * @brief Set the outline width
1031 * @param[in] width The width in pixels of the outline, 0 indicates no outline
1033 void SetOutlineWidth(uint16_t width);
1036 * @brief Retrieves the width of an outline
1038 * @return The width of the outline.
1040 uint16_t GetOutlineWidth() const;
1043 * @brief Set the background color.
1045 * @param[in] color color of background.
1047 void SetBackgroundColor(const Vector4& color);
1050 * @brief Retrieve the background color.
1052 * @return The background color.
1054 const Vector4& GetBackgroundColor() const;
1057 * @brief Set the background enabled flag.
1059 * @param[in] enabled The background enabled flag.
1061 void SetBackgroundEnabled(bool enabled);
1064 * @brief Returns whether to enable text background or not.
1066 * @return Whether text background is enabled.
1068 bool IsBackgroundEnabled() const;
1071 * @brief Sets the emboss's properties string.
1073 * @note The string is stored to be recovered.
1075 * @param[in] embossProperties The emboss's properties string.
1077 void SetDefaultEmbossProperties(const std::string& embossProperties);
1080 * @brief Retrieves the emboss's properties string.
1082 * @return The emboss's properties string.
1084 const std::string& GetDefaultEmbossProperties() const;
1087 * @brief Sets the outline's properties string.
1089 * @note The string is stored to be recovered.
1091 * @param[in] outlineProperties The outline's properties string.
1093 void SetDefaultOutlineProperties(const std::string& outlineProperties);
1096 * @brief Retrieves the outline's properties string.
1098 * @return The outline's properties string.
1100 const std::string& GetDefaultOutlineProperties() const;
1103 * @brief Sets the default line spacing.
1105 * @param[in] lineSpacing The line spacing.
1107 * @return True if lineSpacing has been updated, false otherwise
1109 bool SetDefaultLineSpacing(float lineSpacing);
1112 * @brief Retrieves the default line spacing.
1114 * @return The line spacing.
1116 float GetDefaultLineSpacing() const;
1119 * @brief Sets the default line size.
1121 * @param[in] lineSize The line size.
1123 * @return True if lineSize has been updated, false otherwise
1125 bool SetDefaultLineSize(float lineSize);
1128 * @brief Retrieves the default line size.
1130 * @return The line size.
1132 float GetDefaultLineSize() const;
1135 * @brief Sets the input text's color.
1137 * @param[in] color The input text's color.
1139 void SetInputColor(const Vector4& color);
1142 * @brief Retrieves the input text's color.
1144 * @return The input text's color.
1146 const Vector4& GetInputColor() const;
1149 * @brief Sets the input text's font family name.
1151 * @param[in] fontFamily The text's font family name.
1153 void SetInputFontFamily(const std::string& fontFamily);
1156 * @brief Retrieves the input text's font family name.
1158 * @return The input text's font family name.
1160 const std::string& GetInputFontFamily() const;
1163 * @brief Sets the input font's weight.
1165 * @param[in] weight The input font's weight.
1167 void SetInputFontWeight(FontWeight weight);
1170 * @return Whether the font's weight has been defined.
1172 bool IsInputFontWeightDefined() const;
1175 * @brief Retrieves the input font's weight.
1177 * @return The input font's weight.
1179 FontWeight GetInputFontWeight() const;
1182 * @brief Sets the input font's width.
1184 * @param[in] width The input font's width.
1186 void SetInputFontWidth(FontWidth width);
1189 * @return Whether the font's width has been defined.
1191 bool IsInputFontWidthDefined() const;
1194 * @brief Retrieves the input font's width.
1196 * @return The input font's width.
1198 FontWidth GetInputFontWidth() const;
1201 * @brief Sets the input font's slant.
1203 * @param[in] slant The input font's slant.
1205 void SetInputFontSlant(FontSlant slant);
1208 * @return Whether the font's slant has been defined.
1210 bool IsInputFontSlantDefined() const;
1213 * @brief Retrieves the input font's slant.
1215 * @return The input font's slant.
1217 FontSlant GetInputFontSlant() const;
1220 * @brief Sets the input font's point size.
1222 * @param[in] size The input font's point size.
1224 void SetInputFontPointSize(float size);
1227 * @brief Retrieves the input font's point size.
1229 * @return The input font's point size.
1231 float GetInputFontPointSize() const;
1234 * @brief Sets the input line spacing.
1236 * @param[in] lineSpacing The line spacing.
1238 void SetInputLineSpacing(float lineSpacing);
1241 * @brief Retrieves the input line spacing.
1243 * @return The line spacing.
1245 float GetInputLineSpacing() const;
1248 * @brief Sets the input shadow's properties string.
1250 * @note The string is stored to be recovered.
1252 * @param[in] shadowProperties The shadow's properties string.
1254 void SetInputShadowProperties(const std::string& shadowProperties);
1257 * @brief Retrieves the input shadow's properties string.
1259 * @return The shadow's properties string.
1261 const std::string& GetInputShadowProperties() const;
1264 * @brief Sets the input underline's properties string.
1266 * @note The string is stored to be recovered.
1268 * @param[in] underlineProperties The underline's properties string.
1270 void SetInputUnderlineProperties(const std::string& underlineProperties);
1273 * @brief Retrieves the input underline's properties string.
1275 * @return The underline's properties string.
1277 const std::string& GetInputUnderlineProperties() const;
1280 * @brief Sets the input emboss's properties string.
1282 * @note The string is stored to be recovered.
1284 * @param[in] embossProperties The emboss's properties string.
1286 void SetInputEmbossProperties(const std::string& embossProperties);
1289 * @brief Retrieves the input emboss's properties string.
1291 * @return The emboss's properties string.
1293 const std::string& GetInputEmbossProperties() const;
1296 * @brief Sets input the outline's properties string.
1298 * @note The string is stored to be recovered.
1300 * @param[in] outlineProperties The outline's properties string.
1302 void SetInputOutlineProperties(const std::string& outlineProperties);
1305 * @brief Retrieves the input outline's properties string.
1307 * @return The outline's properties string.
1309 const std::string& GetInputOutlineProperties() const;
1312 * @brief Set the control's interface.
1314 * @param[in] controlInterface The control's interface.
1316 void SetControlInterface(ControlInterface* controlInterface);
1319 * @brief Set the anchor control's interface.
1321 * @param[in] anchorControlInterface The control's interface.
1323 void SetAnchorControlInterface(AnchorControlInterface* anchorControlInterface);
1325 public: // Queries & retrieves.
1327 * @brief Return the layout engine.
1329 * @return A reference to the layout engine.
1331 Layout::Engine& GetLayoutEngine();
1334 * @brief Return a view of the text.
1336 * @return A reference to the view.
1341 * @copydoc Control::GetNaturalSize()
1343 Vector3 GetNaturalSize();
1346 * @copydoc Control::GetHeightForWidth()
1348 float GetHeightForWidth(float width);
1351 * @brief Calculates the point size for text for given layout()
1353 void FitPointSizeforLayout(Size layoutSize);
1356 * @brief Checks if the point size fits within the layout size.
1358 * @return Whether the point size fits within the layout size.
1360 bool CheckForTextFit(float pointSize, Size& layoutSize);
1363 * @brief Retrieves the text's number of lines for a given width.
1364 * @param[in] width The width of the text's area.
1365 * @ return The number of lines.
1367 int GetLineCount(float width);
1370 * @brief Retrieves the text's model.
1372 * @return A pointer to the text's model.
1374 const ModelInterface* const GetTextModel() const;
1377 * @brief Used to get scrolled distance by user input
1379 * @return Distance from last scroll offset to new scroll offset
1381 float GetScrollAmountByUserInput();
1384 * @brief Get latest scroll amount, control size and layout size
1386 * This method is used to get information of control's scroll
1387 * @param[out] scrollPosition The current scrolled position
1388 * @param[out] controlHeight The size of a UI control
1389 * @param[out] layoutHeight The size of a bounding box to layout text within.
1391 * @return Whether the text scroll position is changed or not after last update.
1393 bool GetTextScrollInfo(float& scrollPosition, float& controlHeight, float& layoutHeight);
1396 * @brief Used to set the hidden input option
1398 void SetHiddenInputOption(const Property::Map& options);
1401 * @brief Used to get the hidden input option
1403 void GetHiddenInputOption(Property::Map& options);
1406 * @brief Used to set the input filter option
1408 void SetInputFilterOption(const Property::Map& options);
1411 * @brief Used to get the input filter option
1413 void GetInputFilterOption(Property::Map& options);
1416 * @brief Sets the Placeholder Properties.
1418 * @param[in] map The placeholder property map
1420 void SetPlaceholderProperty(const Property::Map& map);
1423 * @brief Retrieves the Placeholder Property map.
1425 * @param[out] map The property map
1427 void GetPlaceholderProperty(Property::Map& map);
1430 * @brief Checks text direction.
1431 * @return The text direction.
1433 Toolkit::DevelText::TextDirection::Type GetTextDirection();
1436 * @brief Retrieves vertical line alignment
1437 * @return The vertical line alignment
1439 Toolkit::DevelText::VerticalLineAlignment::Type GetVerticalLineAlignment() const;
1442 * @brief Sets vertical line alignment
1443 * @param[in] alignment The vertical line alignment for the text
1445 void SetVerticalLineAlignment(Toolkit::DevelText::VerticalLineAlignment::Type alignment);
1448 * @brief Retrieves ellipsis position
1449 * @return The ellipsis position
1451 Toolkit::DevelText::EllipsisPosition::Type GetEllipsisPosition() const;
1454 * @brief Sets ellipsis position
1455 * @param[in] ellipsisPosition The ellipsis position for the text
1457 void SetEllipsisPosition(Toolkit::DevelText::EllipsisPosition::Type ellipsisPosition);
1460 * @brief Retrieves ignoreSpaceAfterText value from model
1461 * @return The value of ignoreSpaceAfterText
1463 bool IsIgnoreSpacesAfterText() const;
1466 * @brief Sets ignoreSpaceAfterText value to model
1467 * @param[in] ignore The value of ignoreSpacesAfterText for the text
1469 void SetIgnoreSpacesAfterText(bool ignore);
1472 * @brief Sets SetMatchLayoutDirection value to model
1473 * @param[in] match The value of matchLayoutDirection for the text
1475 void SetMatchLayoutDirection(DevelText::MatchLayoutDirection type);
1478 * @brief Retrieves matchLayoutDirection value from model
1479 * @return The value of matchLayoutDirection
1481 DevelText::MatchLayoutDirection GetMatchLayoutDirection() const;
1484 * @brief Sets layoutDirection type value.
1485 * @param[in] layoutDirection The value of the layout direction type.
1487 void SetLayoutDirection(Dali::LayoutDirection::Type layoutDirection);
1490 * @brief Gets layoutDirection type value.
1491 * @param[in] actor The actor which will get the layout direction type.
1492 * @return The value of the layout direction type.
1494 Dali::LayoutDirection::Type GetLayoutDirection(Dali::Actor& actor) const;
1497 * @brief Sets the layout direction changed.
1499 void ChangedLayoutDirection();
1502 * @brief Retrieves if showing real text or not.
1503 * @return The value of showing real text.
1505 bool IsShowingRealText() const;
1507 public: // Relayout.
1509 * @brief Triggers a relayout which updates View (if necessary).
1511 * @note UI Controls are expected to minimize calls to this method e.g. call once after size negotiation.
1512 * @param[in] size A the size of a bounding box to layout text within.
1513 * @param[in] layoutDirection The direction of the system language.
1515 * @return Whether the text model or decorations were updated.
1517 UpdateTextType Relayout(const Size& size, Dali::LayoutDirection::Type layoutDirection = Dali::LayoutDirection::LEFT_TO_RIGHT);
1520 * @brief Request a relayout using the ControlInterface.
1522 void RequestRelayout();
1524 public: // Input style change signals.
1526 * @return Whether the queue of input style changed signals is empty.
1528 bool IsInputStyleChangedSignalsQueueEmpty();
1531 * @brief Process all pending input style changed signals.
1533 * Calls the Text::ControlInterface::InputStyleChanged() method which is overriden by the
1534 * text controls. Text controls may send signals to state the input style has changed.
1536 void ProcessInputStyleChangedSignals();
1538 public: // Text-input Event Queuing.
1540 * @brief Called by editable UI controls when keyboard focus is gained.
1542 void KeyboardFocusGainEvent();
1545 * @brief Called by editable UI controls when focus is lost.
1547 void KeyboardFocusLostEvent();
1550 * @brief Called by editable UI controls when key events are received.
1552 * @param[in] event The key event.
1553 * @param[in] type Used to distinguish between regular key events and InputMethodContext events.
1555 bool KeyEvent(const Dali::KeyEvent& event);
1558 * @brief Called by anchor when a tap gesture occurs.
1559 * @param[in] x The x position relative to the top-left of the parent control.
1560 * @param[in] y The y position relative to the top-left of the parent control.
1562 void AnchorEvent(float x, float y);
1565 * @brief Called by editable UI controls when a tap gesture occurs.
1566 * @param[in] tapCount The number of taps.
1567 * @param[in] x The x position relative to the top-left of the parent control.
1568 * @param[in] y The y position relative to the top-left of the parent control.
1570 void TapEvent(unsigned int tapCount, float x, float y);
1573 * @brief Called by editable UI controls when a pan gesture occurs.
1575 * @param[in] state The state of the gesture.
1576 * @param[in] displacement This distance panned since the last pan gesture.
1578 void PanEvent(GestureState state, const Vector2& displacement);
1581 * @brief Called by editable UI controls when a long press gesture occurs.
1583 * @param[in] state The state of the gesture.
1584 * @param[in] x The x position relative to the top-left of the parent control.
1585 * @param[in] y The y position relative to the top-left of the parent control.
1587 void LongPressEvent(GestureState state, float x, float y);
1590 * @brief Used to get the Primary cursor position.
1592 * @return Primary cursor position.
1594 CharacterIndex GetPrimaryCursorPosition() const;
1597 * @brief Used to set the Primary cursor position.
1599 * @param[in] index for the Primary cursor position.
1600 * @param[in] focused true if UI control has gained focus to receive key event, false otherwise.
1601 * @return[in] true if cursor position changed, false otherwise.
1603 bool SetPrimaryCursorPosition(CharacterIndex index, bool focused);
1606 * @brief Creates a selection event.
1608 * It could be called from the TapEvent (double tap) or when the text selection popup's sellect all button is pressed.
1610 * @param[in] x The x position relative to the top-left of the parent control.
1611 * @param[in] y The y position relative to the top-left of the parent control.
1612 * @param[in] selection type like the whole text is selected or unselected.
1614 void SelectEvent(float x, float y, SelectionType selection);
1617 * @brief Creates a selection event with a selection index.
1619 * It could be called from the SelectText().
1620 * The start and end parameters are passed through the event.
1622 * @param[in] start The start selection position.
1623 * @param[in] end The end selection position.
1624 * @param[in] selection type like the range.
1626 void SelectEvent(const uint32_t start, const uint32_t end, SelectionType selection);
1629 * @copydoc Text::SelectableControlInterface::SetTextSelectionRange()
1631 void SetTextSelectionRange(const uint32_t* start, const uint32_t* end);
1634 * @copydoc Text::SelectableControlInterface::GetTextSelectionRange()
1636 Uint32Pair GetTextSelectionRange() const;
1639 * @copydoc Text::SelectableControlInterface::SelectWholeText()
1641 void SelectWholeText();
1644 * @copydoc Text::EditableControlInterface::CopyText()
1649 * @copydoc Text::EditableControlInterface::CutText()
1654 * @copydoc Text::EditableControlInterface::PasteText()
1659 * @copydoc Text::SelectableControlInterface::SelectNone()
1664 * @copydoc Text::SelectableControlInterface::SelectText()
1666 void SelectText(const uint32_t start, const uint32_t end);
1669 * @copydoc Text::SelectableControlInterface::GetSelectedText()
1671 string GetSelectedText() const;
1674 * @copydoc Text::EditableControlInterface::IsEditable()
1676 virtual bool IsEditable() const;
1679 * @copydoc Text::EditableControlInterface::SetEditable()
1681 virtual void SetEditable(bool editable);
1684 * @copydoc Dali::Toolkit::Internal::TextEditor::ScrollBy()
1686 virtual void ScrollBy(Vector2 scroll);
1689 * @copydoc Dali::Toolkit::Internal::TextEditor::GetHorizontalScrollPosition()
1691 float GetHorizontalScrollPosition();
1694 * @copydoc Dali::Toolkit::Internal::TextEditor::GetVerticalScrollPosition()
1696 float GetVerticalScrollPosition();
1699 * @brief Event received from input method context
1701 * @param[in] inputMethodContext The input method context.
1702 * @param[in] inputMethodContextEvent The event received.
1703 * @return A data struture indicating if update is needed, cursor position and current text.
1705 InputMethodContext::CallbackData OnInputMethodContextEvent(InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent);
1708 * @brief Event from Clipboard notifying an Item has been selected for pasting
1710 void PasteClipboardItemEvent();
1713 * @brief Return true when text control should clear key input focus when escape key is pressed.
1715 * @return Whether text control should clear key input focus or not when escape key is pressed.
1717 bool ShouldClearFocusOnEscape() const;
1720 * @brief Create an actor that renders the text background color
1722 * @return the created actor or an empty handle if no background color needs to be rendered.
1724 Actor CreateBackgroundActor();
1727 * @brief Used to reset the cursor position after setting a new text.
1729 * @param[in] cursorIndex Where to place the cursor.
1731 void ResetCursorPosition(CharacterIndex cursorIndex);
1734 * @brief The method acquires current position of cursor
1735 * @return unsigned value with cursor position
1737 CharacterIndex GetCursorPosition();
1739 protected: // Inherit from Text::Decorator::ControllerInterface.
1741 * @copydoc Dali::Toolkit::Text::Decorator::ControllerInterface::GetTargetSize()
1743 void GetTargetSize(Vector2& targetSize) override;
1746 * @copydoc Dali::Toolkit::Text::Decorator::ControllerInterface::AddDecoration()
1748 void AddDecoration(Actor& actor, bool needsClipping) override;
1751 * @copydoc Dali::Toolkit::Text::Decorator::ControllerInterface::DecorationEvent()
1753 void DecorationEvent(HandleType handle, HandleState state, float x, float y) override;
1755 protected: // Inherit from TextSelectionPopup::TextPopupButtonCallbackInterface.
1757 * @copydoc Dali::Toolkit::TextSelectionPopup::TextPopupButtonCallbackInterface::TextPopupButtonTouched()
1759 void TextPopupButtonTouched(Dali::Toolkit::TextSelectionPopup::Buttons button) override;
1761 protected: // Inherit from HiddenText.
1763 * @brief Invoked from HiddenText when showing time of the last character was expired
1765 void DisplayTimeExpired() override;
1769 * @brief Called by editable UI controls when key events are received.
1771 * @param[in] text The text to insert.
1772 * @param[in] type Used to distinguish between regular key events and InputMethodContext events.
1774 void InsertText(const std::string& text, InsertType type);
1777 * @copydoc Text::EditableControlInterface::PasteText()
1779 void PasteText(const std::string& stringToPaste);
1782 * @brief Remove a given number of characters
1784 * When predictve text is used the pre-edit text is removed and inserted again with the new characters.
1785 * The UpdateInputStyleType @type parameter if set to DONT_UPDATE_INPUT_STYLE avoids to update the input
1786 * style when pre-edit text is removed.
1788 * @param[in] cursorOffset Start position from the current cursor position to start deleting characters.
1789 * @param[in] numberOfCharacters The number of characters to delete from the cursorOffset.
1790 * @param[in] type Whether to update the input style.
1791 * @return True if the remove was successful.
1793 bool RemoveText(int cursorOffset,
1794 int numberOfCharacters,
1795 UpdateInputStyleType type);
1798 * @brief Checks if text is selected and if so removes it.
1799 * @return true if text was removed
1801 bool RemoveSelectedText();
1804 * @brief Update anchor position from given number of inserted characters.
1806 * @param[in] numberOfCharacters The number of inserted characters.
1807 * @param[in] previousCursorIndex A cursor position before event occurs.
1809 void InsertTextAnchor(int numberOfCharacters,
1810 CharacterIndex previousCursorIndex);
1813 * @brief Update anchor position from given number of removed characters.
1815 * @param[in] cursorOffset Start position from the current cursor position to start deleting characters.
1816 * @param[in] numberOfCharacters The number of removed characters.
1817 * @param[in] previousCursorIndex A cursor position before event occurs.
1819 void RemoveTextAnchor(int cursorOffset,
1820 int numberOfCharacters,
1821 CharacterIndex previousCursorIndex);
1823 private: // Relayout.
1825 * @brief Lays-out the text.
1827 * GetNaturalSize(), GetHeightForWidth() and Relayout() calls this method.
1829 * @param[in] size A the size of a bounding box to layout text within.
1830 * @param[in] operations The layout operations which need to be done.
1831 * @param[out] layoutSize The size of the laid-out text.
1833 bool DoRelayout(const Size& size,
1834 OperationsMask operations,
1838 * @brief Calulates the vertical offset to align the text inside the bounding box.
1840 * @param[in] size The size of the bounding box.
1842 void CalculateVerticalOffset(const Size& size);
1846 * @brief Process queued events which modify the model.
1848 void ProcessModifyEvents();
1851 * @brief Used to process an event queued from SetText()
1853 void TextReplacedEvent();
1856 * @brief Used to process an event queued from key events etc.
1858 void TextInsertedEvent();
1861 * @brief Used to process an event queued from backspace key etc.
1863 void TextDeletedEvent();
1866 * @brief Helper to KeyEvent() to handle the backspace or delete key case.
1868 * @param[in] keyCode The keycode for the key pressed
1869 * @return True if a character was deleted.
1871 bool DeleteEvent(int keyCode);
1873 private: // Helpers.
1875 * @brief Used to remove the text included the placeholder text.
1880 * @brief Helper to show the place holder text..
1882 void ShowPlaceholderText();
1885 * @brief Helper to clear font-specific data (only).
1887 void ClearFontData();
1890 * @brief Helper to clear text's style data.
1892 void ClearStyleData();
1895 * @brief Used to reset the scroll position after setting a new text.
1897 void ResetScrollPosition();
1899 private: // Private contructors & copy operator.
1901 * @brief Private constructor.
1904 : Controller(nullptr, nullptr, nullptr, nullptr)
1909 * @brief Private constructor.
1911 Controller(ControlInterface* controlInterface)
1912 : Controller(controlInterface, nullptr, nullptr, nullptr)
1917 * @brief Private constructor.
1919 Controller(ControlInterface* controlInterface,
1920 EditableControlInterface* editableControlInterface,
1921 SelectableControlInterface* selectableControlInterface,
1922 AnchorControlInterface* anchorControlInterface);
1924 Controller(const Controller& handle) = delete;
1925 Controller& operator=(const Controller& handle) = delete;
1927 protected: // Destructor.
1929 * @brief A reference counted object may only be deleted by calling Unreference().
1931 virtual ~Controller();
1934 struct Impl; ///< Made public for testing purposes
1937 struct EventHandler;
1938 struct InputFontHandler;
1939 struct InputProperties;
1940 struct PlaceholderHandler;
1947 } // namespace Dali::Toolkit::Text
1949 #endif // DALI_TOOLKIT_TEXT_CONTROLLER_H