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/layouts/layout-engine.h>
32 #include <dali-toolkit/internal/text/text-anchor-control-interface.h>
33 #include <dali-toolkit/internal/text/text-model-interface.h>
34 #include <dali-toolkit/internal/text/text-selectable-control-interface.h>
35 #include <dali-toolkit/public-api/text/text-enumerations.h>
44 class ControlInterface;
45 class EditableControlInterface;
47 class RenderingController;
50 * @brief Text selection operations .
59 typedef IntrusivePtr<Controller> ControllerPtr;
62 * @brief A Text Controller is used by UI Controls which display text.
64 * It manipulates the Logical & Visual text models on behalf of the UI Controls.
65 * It provides a view of the text that can be used by rendering back-ends.
67 * For selectable/editable UI controls, the controller handles input events from the UI control
68 * and decorations (grab handles etc) via the Decorator::ControllerInterface interface.
70 * The text selection popup button callbacks are as well handled via the TextSelectionPopupCallbackInterface interface.
72 class Controller : public RefObject, public Decorator::ControllerInterface, public TextSelectionPopupCallbackInterface, public HiddenText::Observer
74 public: // Enumerated types.
76 * @brief Text related operations to be done in the relayout process.
80 NO_OPERATION = 0x0000,
81 CONVERT_TO_UTF32 = 0x0001,
83 VALIDATE_FONTS = 0x0004,
84 GET_LINE_BREAKS = 0x0008,
87 GET_GLYPH_METRICS = 0x0040,
89 UPDATE_LAYOUT_SIZE = 0x0100,
93 UPDATE_DIRECTION = 0x1000,
94 ALL_OPERATIONS = 0xFFFF
98 * @brief Used to distinguish between regular key events and InputMethodContext events
107 * @brief Used to specify whether to update the input style.
109 enum UpdateInputStyleType
112 DONT_UPDATE_INPUT_STYLE
116 * @brief Used to specify what has been updated after the Relayout() method has been called.
120 NONE_UPDATED = 0x0, ///< Nothing has been updated.
121 MODEL_UPDATED = 0x1, ///< The text's model has been updated.
122 DECORATOR_UPDATED = 0x2 ///< The decoration has been updated.
126 * @brief Different placeholder-text can be shown when the control is active/inactive.
130 PLACEHOLDER_TYPE_ACTIVE,
131 PLACEHOLDER_TYPE_INACTIVE,
135 * @brief Enumeration for Font Size Type.
139 POINT_SIZE, // The size of font in points.
140 PIXEL_SIZE // The size of font in pixels.
147 NO_ACTION, ///< Does no action if there is a tap on top of an area with no text.
148 HIGHLIGHT, ///< Highlights the nearest text (at the beginning or end of the text) and shows the text's selection popup.
149 SHOW_SELECTION_POPUP ///< Shows the text's selection popup.
161 TEXT_FIT_FONT_SIZE_TYPE
165 public: // Constructor.
167 * @brief Create a new instance of a Controller.
169 * @return A pointer to a new Controller.
171 static ControllerPtr New();
174 * @brief Create a new instance of a Controller.
176 * @param[in] controlInterface The control's interface.
178 * @return A pointer to a new Controller.
180 static ControllerPtr New(ControlInterface* controlInterface);
183 * @brief Create a new instance of a Controller.
185 * @param[in] controlInterface The control's interface.
186 * @param[in] editableControlInterface The editable control's interface.
187 * @param[in] selectableControlInterface The selectable control's interface.
188 * @param[in] anchorControlInterface The anchor control's interface.
190 * @return A pointer to a new Controller.
192 static ControllerPtr New(ControlInterface* controlInterface,
193 EditableControlInterface* editableControlInterface,
194 SelectableControlInterface* selectableControlInterface,
195 AnchorControlInterface* anchorControlInterface);
197 public: // Configure the text controller.
199 * @brief Called to enable text input.
201 * @note Selectable or editable controls should call this once after Controller::New().
202 * @param[in] decorator Used to create cursor, selection handle decorations etc.
203 * @param[in] inputMethodContext Used to manager ime.
205 void EnableTextInput(DecoratorPtr decorator, InputMethodContext& inputMethodContext);
208 * @brief Used to switch between bitmap & vector based glyphs
210 * @param[in] glyphType The type of glyph; note that metrics for bitmap & vector based glyphs are different.
212 void SetGlyphType(TextAbstraction::GlyphType glyphType);
215 * @brief Enables/disables the mark-up processor.
217 * By default is disabled.
219 * @param[in] enable Whether to enable the mark-up processor.
221 void SetMarkupProcessorEnabled(bool enable);
224 * @brief Retrieves whether the mark-up processor is enabled.
226 * By default is disabled.
228 * @return @e true if the mark-up processor is enabled, otherwise returns @e false.
230 bool IsMarkupProcessorEnabled() const;
233 * @brief Enables/disables the auto text scrolling
235 * By default is disabled.
237 * @param[in] enable Whether to enable the auto scrolling
239 void SetAutoScrollEnabled(bool enable);
242 * @brief Retrieves whether auto text scrolling is enabled.
244 * By default is disabled.
246 * @return @e true if auto scrolling is enabled, otherwise returns @e false.
248 bool IsAutoScrollEnabled() const;
251 * @brief Get direction of the text from the first line of text,
252 * @return bool rtl (right to left) is true
254 CharacterDirection GetAutoScrollDirection() const;
257 * @brief Get the alignment offset of the first line of text.
259 * @return The alignment offset.
261 float GetAutoScrollLineAlignment() const;
264 * @brief Enables the horizontal scrolling.
266 * @param[in] enable Whether to enable the horizontal scrolling.
268 void SetHorizontalScrollEnabled(bool enable);
271 * @brief Retrieves whether the horizontal scrolling is enabled.
273 * @return @e true if the horizontal scrolling is enabled, otherwise it returns @e false.
275 bool IsHorizontalScrollEnabled() const;
278 * @brief Enables the vertical scrolling.
280 * @param[in] enable Whether to enable the vertical scrolling.
282 void SetVerticalScrollEnabled(bool enable);
285 * @brief Retrieves whether the verticall scrolling is enabled.
287 * @return @e true if the vertical scrolling is enabled, otherwise it returns @e false.
289 bool IsVerticalScrollEnabled() const;
292 * @brief Enables the smooth handle panning.
294 * @param[in] enable Whether to enable the smooth handle panning.
296 void SetSmoothHandlePanEnabled(bool enable);
299 * @brief Retrieves whether the smooth handle panning is enabled.
301 * @return @e true if the smooth handle panning is enabled.
303 bool IsSmoothHandlePanEnabled() const;
306 * @brief Sets the maximum number of characters that can be inserted into the TextModel
308 * @param[in] maxCharacters maximum number of characters to be accepted
310 void SetMaximumNumberOfCharacters(Length maxCharacters);
313 * @brief Sets the maximum number of characters that can be inserted into the TextModel
315 * @param[in] maxCharacters maximum number of characters to be accepted
317 int GetMaximumNumberOfCharacters();
320 * @brief Called to enable/disable cursor blink.
322 * @note Only editable controls should calls this.
323 * @param[in] enabled Whether the cursor should blink or not.
325 void SetEnableCursorBlink(bool enable);
328 * @brief Query whether cursor blink is enabled.
330 * @return Whether the cursor should blink or not.
332 bool GetEnableCursorBlink() const;
335 * @brief Whether to enable the multi-line layout.
337 * @param[in] enable \e true enables the multi-line (by default)
339 void SetMultiLineEnabled(bool enable);
342 * @return Whether the multi-line layout is enabled.
344 bool IsMultiLineEnabled() const;
347 * @brief Sets the text's horizontal alignment.
349 * @param[in] alignment The horizontal alignment.
351 void SetHorizontalAlignment(HorizontalAlignment::Type alignment);
354 * @copydoc ModelInterface::GetHorizontalAlignment()
356 HorizontalAlignment::Type GetHorizontalAlignment() const;
359 * @brief Sets the text's vertical alignment.
361 * @param[in] alignment The vertical alignment.
363 void SetVerticalAlignment(VerticalAlignment::Type alignment);
366 * @copydoc ModelInterface::GetVerticalAlignment()
368 VerticalAlignment::Type GetVerticalAlignment() const;
371 * @brief Sets the text's wrap mode
372 * @param[in] text wrap mode The unit of wrapping
374 void SetLineWrapMode(Text::LineWrap::Mode textWarpMode);
377 * @brief Retrieve text wrap mode previously set.
378 * @return text wrap mode
380 Text::LineWrap::Mode GetLineWrapMode() const;
383 * @brief Enable or disable the text elide.
385 * @param[in] enabled Whether to enable the text elide.
387 void SetTextElideEnabled(bool enabled);
390 * @copydoc ModelInterface::IsTextElideEnabled()
392 bool IsTextElideEnabled() const;
395 * @brief Enable or disable the text fit.
397 * @param[in] enabled Whether to enable the text fit.
399 void SetTextFitEnabled(bool enabled);
402 * @brief Whether the text fit is enabled or not.
404 * @return True if the text fit is enabled
406 bool IsTextFitEnabled() const;
409 * @brief Sets minimum size valid for text fit.
411 * @param[in] minimum size value.
412 * @param[in] type The font size type is point size or pixel size
414 void SetTextFitMinSize(float pointSize, FontSizeType type);
417 * @brief Retrieves the minimum point size valid for text fit.
419 * @return The minimum point size valid for text fit
421 float GetTextFitMinSize() const;
424 * @brief Sets maximum size valid for text fit.
426 * @param[in] maximum size value.
427 * @param[in] type The font size type is point size or pixel size
429 void SetTextFitMaxSize(float pointSize, FontSizeType type);
432 * @brief Retrieves the maximum point size valid for text fit.
434 * @return The maximum point size valid for text fit
436 float GetTextFitMaxSize() const;
439 * @brief Sets step size for font increase valid for text fit.
441 * @param[in] step size value.
442 * @param[in] type The font size type is point size or pixel size
444 void SetTextFitStepSize(float step, FontSizeType type);
447 * @brief Retrieves the step point size valid for text fit.
449 * @return The step point size valid for text fit
451 float GetTextFitStepSize() const;
454 * @brief Sets content size valid for text fit.
456 * @param[in] Content size value.
458 void SetTextFitContentSize(Vector2 size);
461 * @brief Retrieves the content size valid for text fit.
463 * @return The content size valid for text fit
465 Vector2 GetTextFitContentSize() const;
468 * @brief Enable or disable the placeholder text elide.
469 * @param enabled Whether to enable the placeholder text elide.
471 void SetPlaceholderTextElideEnabled(bool enabled);
474 * @brief Whether the placeholder text elide property is enabled.
475 * @return True if the placeholder text elide property is enabled, false otherwise.
477 bool IsPlaceholderTextElideEnabled() const;
480 * @brief Enable or disable the text selection.
481 * @param[in] enabled Whether to enable the text selection.
483 void SetSelectionEnabled(bool enabled);
486 * @brief Whether the text selection is enabled or not.
487 * @return True if the text selection is enabled
489 bool IsSelectionEnabled() const;
492 * @brief Enable or disable the text selection using Shift key.
493 * @param enabled Whether to enable the text selection using Shift key
495 void SetShiftSelectionEnabled(bool enabled);
498 * @brief Whether the text selection using Shift key is enabled or not.
499 * @return True if the text selection using Shift key is enabled
501 bool IsShiftSelectionEnabled() const;
504 * @brief Enable or disable the grab handles for text selection.
506 * @param[in] enabled Whether to enable the grab handles
508 void SetGrabHandleEnabled(bool enabled);
511 * @brief Returns whether the grab handles are enabled.
513 * @return True if the grab handles are enabled
515 bool IsGrabHandleEnabled() const;
518 * @brief Enable or disable the grab handles for text selection.
520 * @param[in] enabled Whether to enable the grab handles
522 void SetGrabHandlePopupEnabled(bool enabled);
525 * @brief Returns whether the grab handles are enabled.
527 * @return True if the grab handles are enabled
529 bool IsGrabHandlePopupEnabled() const;
532 * @brief Sets input type to password
534 * @note The string is displayed hidden character
536 * @param[in] passwordInput True if password input is enabled.
538 void SetInputModePassword(bool passwordInput);
541 * @brief Returns whether the input mode type is set as password.
543 * @return True if input mode type is password
545 bool IsInputModePassword();
548 * @brief Sets the action when there is a double tap event on top of a text area with no text.
550 * @param[in] action The action to do.
552 void SetNoTextDoubleTapAction(NoTextTap::Action action);
555 * @brief Retrieves the action when there is a double tap event on top of a text area with no text.
557 * @return The action to do.
559 NoTextTap::Action GetNoTextDoubleTapAction() const;
562 * @briefSets the action when there is a long press event on top of a text area with no text.
564 * @param[in] action The action to do.
566 void SetNoTextLongPressAction(NoTextTap::Action action);
569 * @brief Retrieves the action when there is a long press event on top of a text area with no text.
571 * @return The action to do.
573 NoTextTap::Action GetNoTextLongPressAction() const;
576 * @brief Query if Underline settings were provided by string or map
577 * @return bool true if set by string
579 bool IsUnderlineSetByString();
582 * Set method underline setting were set by
583 * @param[in] bool, true if set by string
585 void UnderlineSetByString(bool setByString);
588 * @brief Query if shadow settings were provided by string or map
589 * @return bool true if set by string
591 bool IsShadowSetByString();
594 * Set method shadow setting were set by
595 * @param[in] bool, true if set by string
597 void ShadowSetByString(bool setByString);
600 * @brief Query if outline settings were provided by string or map
601 * @return bool true if set by string
603 bool IsOutlineSetByString();
606 * Set method outline setting were set by
607 * @param[in] bool, true if set by string
609 void OutlineSetByString(bool setByString);
612 * @brief Query if font style settings were provided by string or map
613 * @return bool true if set by string
615 bool IsFontStyleSetByString();
618 * Set method font style setting were set by
619 * @param[in] bool, true if set by string
621 void FontStyleSetByString(bool setByString);
625 * @brief Replaces any text previously set.
627 * @note This will be converted into UTF-32 when stored in the text model.
628 * @param[in] text A string of UTF-8 characters.
630 void SetText(const std::string& text);
633 * @brief Retrieve any text previously set.
635 * @param[out] text A string of UTF-8 characters.
637 void GetText(std::string& text) const;
640 * @brief Replaces any placeholder text previously set.
642 * @param[in] type Different placeholder-text can be shown when the control is active/inactive.
643 * @param[in] text A string of UTF-8 characters.
645 void SetPlaceholderText(PlaceholderType type, const std::string& text);
648 * @brief Retrieve any placeholder text previously set.
650 * @param[in] type Different placeholder-text can be shown when the control is active/inactive.
651 * @param[out] A string of UTF-8 characters.
653 void GetPlaceholderText(PlaceholderType type, std::string& text) const;
656 * @ brief Update the text after a font change
657 * @param[in] newDefaultFont The new font to change to
659 void UpdateAfterFontChange(const std::string& newDefaultFont);
662 * @brief The method acquires currently selected text
663 * @param selectedText variable to place selected text in
665 void RetrieveSelection(std::string& selectedText) const;
668 * @brief The method sets selection in given range
669 * @param start index of first character
670 * @param end index of first character after selection
672 void SetSelection(int start, int end);
675 * @brief This method retrieve indexes of current selection
677 * @return a pair, where first element is left index of selection and second is the right one
679 std::pair<int, int> GetSelectionIndexes() const;
682 * Place string in system clipboard
683 * @param source std::string
685 void CopyStringToClipboard(const std::string& source);
688 * Place currently selected text in system clipboard
689 * @param deleteAfterSending flag pointing if text should be deleted after sending to clipboard
691 void SendSelectionToClipboard(bool deleteAfterSending);
693 public: // Default style & Input style
695 * @brief Set the default font family.
697 * @param[in] defaultFontFamily The default font family.
699 void SetDefaultFontFamily(const std::string& defaultFontFamily);
702 * @brief Retrieve the default font family.
704 * @return The default font family.
706 const std::string& GetDefaultFontFamily() const;
709 * @brief Sets the placeholder text font family.
710 * @param[in] placeholderTextFontFamily The placeholder text font family.
712 void SetPlaceholderFontFamily(const std::string& placeholderTextFontFamily);
715 * @brief Retrieves the placeholder text font family.
717 * @return The placeholder text font family
719 const std::string& GetPlaceholderFontFamily() const;
722 * @brief Sets the default font weight.
724 * @param[in] weight The font weight.
726 void SetDefaultFontWeight(FontWeight weight);
729 * @brief Whether the font's weight has been defined.
731 bool IsDefaultFontWeightDefined() const;
734 * @brief Retrieves the default font weight.
736 * @return The default font weight.
738 FontWeight GetDefaultFontWeight() const;
741 * @brief Sets the placeholder text font weight.
743 * @param[in] weight The font weight
745 void SetPlaceholderTextFontWeight(FontWeight weight);
748 * @brief Whether the font's weight has been defined.
750 * @return True if the placeholder text font weight is defined
752 bool IsPlaceholderTextFontWeightDefined() const;
755 * @brief Retrieves the placeholder text font weight.
757 * @return The placeholder text font weight
759 FontWeight GetPlaceholderTextFontWeight() const;
762 * @brief Sets the default font width.
764 * @param[in] width The font width.
766 void SetDefaultFontWidth(FontWidth width);
769 * @brief Whether the font's width has been defined.
771 bool IsDefaultFontWidthDefined() const;
774 * @brief Retrieves the default font width.
776 * @return The default font width.
778 FontWidth GetDefaultFontWidth() const;
781 * @brief Sets the placeholder text font width.
783 * @param[in] width The font width
785 void SetPlaceholderTextFontWidth(FontWidth width);
788 * @brief Whether the font's width has been defined.
790 * @return True if the placeholder text font width is defined
792 bool IsPlaceholderTextFontWidthDefined() const;
795 * @brief Retrieves the placeholder text font width.
797 * @return The placeholder text font width
799 FontWidth GetPlaceholderTextFontWidth() const;
802 * @brief Sets the default font slant.
804 * @param[in] slant The font slant.
806 void SetDefaultFontSlant(FontSlant slant);
809 * @brief Whether the font's slant has been defined.
811 bool IsDefaultFontSlantDefined() const;
814 * @brief Retrieves the default font slant.
816 * @return The default font slant.
818 FontSlant GetDefaultFontSlant() const;
821 * @brief Sets the placeholder text font slant.
823 * @param[in] slant The font slant
825 void SetPlaceholderTextFontSlant(FontSlant slant);
828 * @brief Whether the font's slant has been defined.
830 * @return True if the placeholder text font slant is defined
832 bool IsPlaceholderTextFontSlantDefined() const;
835 * @brief Retrieves the placeholder text font slant.
837 * @return The placeholder text font slant
839 FontSlant GetPlaceholderTextFontSlant() const;
842 * @brief Set the default font size.
844 * @param[in] fontSize The default font size
845 * @param[in] type The font size type is point size or pixel size
847 void SetDefaultFontSize(float fontSize, FontSizeType type);
850 * @brief Retrieve the default point size.
852 * @param[in] type The font size type
853 * @return The default point size.
855 float GetDefaultFontSize(FontSizeType type) const;
858 * @brief Set the font size scale.
860 * @param[in] scale The font size scale
862 void SetFontSizeScale(float scale);
865 * @brief Get the font size scale.
867 * @return The font size scale.
869 float GetFontSizeScale() const;
872 * @brief Sets the Placeholder text font size.
873 * @param[in] fontSize The placeholder text font size
874 * @param[in] type The font size type is point size or pixel size
876 void SetPlaceholderTextFontSize(float fontSize, FontSizeType type);
879 * @brief Retrieves the Placeholder text font size.
880 * @param[in] type The font size type
881 * @return The placeholder font size
883 float GetPlaceholderTextFontSize(FontSizeType type) const;
886 * @brief Sets the text's default color.
888 * @param color The default color.
890 void SetDefaultColor(const Vector4& color);
893 * @brief Retrieves the text's default color.
895 * @return The default color.
897 const Vector4& GetDefaultColor() const;
900 * @brief Set the text color
902 * @param textColor The text color
904 void SetPlaceholderTextColor(const Vector4& textColor);
907 * @brief Retrieve the text color
909 * @return The text color
911 const Vector4& GetPlaceholderTextColor() const;
914 * @brief Set the shadow offset.
916 * @param[in] shadowOffset The shadow offset, 0,0 indicates no shadow.
918 void SetShadowOffset(const Vector2& shadowOffset);
921 * @brief Retrieve the shadow offset.
923 * @return The shadow offset.
925 const Vector2& GetShadowOffset() const;
928 * @brief Set the shadow color.
930 * @param[in] shadowColor The shadow color.
932 void SetShadowColor(const Vector4& shadowColor);
935 * @brief Retrieve the shadow color.
937 * @return The shadow color.
939 const Vector4& GetShadowColor() const;
942 * @brief Set the shadow blur radius.
944 * @param[in] shadowBlurRadius The shadow blur radius, 0,0 indicates no blur.
946 void SetShadowBlurRadius(const float& shadowBlurRadius);
949 * @brief Retrieve the shadow blur radius.
951 * @return The shadow blur radius.
953 const float& GetShadowBlurRadius() const;
956 * @brief Set the underline color.
958 * @param[in] color color of underline.
960 void SetUnderlineColor(const Vector4& color);
963 * @brief Retrieve the underline color.
965 * @return The underline color.
967 const Vector4& GetUnderlineColor() const;
970 * @brief Set the underline enabled flag.
972 * @param[in] enabled The underline enabled flag.
974 void SetUnderlineEnabled(bool enabled);
977 * @brief Returns whether the text is underlined or not.
979 * @return The underline state.
981 bool IsUnderlineEnabled() const;
984 * @brief Set the override used for underline height, 0 indicates height will be supplied by font metrics
986 * @param[in] height The height in pixels of the underline
988 void SetUnderlineHeight(float height);
991 * @brief Retrieves the override height of an underline, 0 indicates height is supplied by font metrics
993 * @return The height of the underline, or 0 if height is not overrided.
995 float GetUnderlineHeight() const;
998 * @brief Set the outline color.
1000 * @param[in] color color of outline.
1002 void SetOutlineColor(const Vector4& color);
1005 * @brief Retrieve the outline color.
1007 * @return The outline color.
1009 const Vector4& GetOutlineColor() const;
1012 * @brief Set the outline width
1014 * @param[in] width The width in pixels of the outline, 0 indicates no outline
1016 void SetOutlineWidth(uint16_t width);
1019 * @brief Retrieves the width of an outline
1021 * @return The width of the outline.
1023 uint16_t GetOutlineWidth() const;
1026 * @brief Set the background color.
1028 * @param[in] color color of background.
1030 void SetBackgroundColor(const Vector4& color);
1033 * @brief Retrieve the background color.
1035 * @return The background color.
1037 const Vector4& GetBackgroundColor() const;
1040 * @brief Set the background enabled flag.
1042 * @param[in] enabled The background enabled flag.
1044 void SetBackgroundEnabled(bool enabled);
1047 * @brief Returns whether to enable text background or not.
1049 * @return Whether text background is enabled.
1051 bool IsBackgroundEnabled() const;
1054 * @brief Sets the emboss's properties string.
1056 * @note The string is stored to be recovered.
1058 * @param[in] embossProperties The emboss's properties string.
1060 void SetDefaultEmbossProperties(const std::string& embossProperties);
1063 * @brief Retrieves the emboss's properties string.
1065 * @return The emboss's properties string.
1067 const std::string& GetDefaultEmbossProperties() const;
1070 * @brief Sets the outline's properties string.
1072 * @note The string is stored to be recovered.
1074 * @param[in] outlineProperties The outline's properties string.
1076 void SetDefaultOutlineProperties(const std::string& outlineProperties);
1079 * @brief Retrieves the outline's properties string.
1081 * @return The outline's properties string.
1083 const std::string& GetDefaultOutlineProperties() const;
1086 * @brief Sets the default line spacing.
1088 * @param[in] lineSpacing The line spacing.
1090 * @return True if lineSpacing has been updated, false otherwise
1092 bool SetDefaultLineSpacing(float lineSpacing);
1095 * @brief Retrieves the default line spacing.
1097 * @return The line spacing.
1099 float GetDefaultLineSpacing() const;
1102 * @brief Sets the default line size.
1104 * @param[in] lineSize The line size.
1106 * @return True if lineSize has been updated, false otherwise
1108 bool SetDefaultLineSize(float lineSize);
1111 * @brief Retrieves the default line size.
1113 * @return The line size.
1115 float GetDefaultLineSize() const;
1118 * @brief Sets the input text's color.
1120 * @param[in] color The input text's color.
1122 void SetInputColor(const Vector4& color);
1125 * @brief Retrieves the input text's color.
1127 * @return The input text's color.
1129 const Vector4& GetInputColor() const;
1132 * @brief Sets the input text's font family name.
1134 * @param[in] fontFamily The text's font family name.
1136 void SetInputFontFamily(const std::string& fontFamily);
1139 * @brief Retrieves the input text's font family name.
1141 * @return The input text's font family name.
1143 const std::string& GetInputFontFamily() const;
1146 * @brief Sets the input font's weight.
1148 * @param[in] weight The input font's weight.
1150 void SetInputFontWeight(FontWeight weight);
1153 * @return Whether the font's weight has been defined.
1155 bool IsInputFontWeightDefined() const;
1158 * @brief Retrieves the input font's weight.
1160 * @return The input font's weight.
1162 FontWeight GetInputFontWeight() const;
1165 * @brief Sets the input font's width.
1167 * @param[in] width The input font's width.
1169 void SetInputFontWidth(FontWidth width);
1172 * @return Whether the font's width has been defined.
1174 bool IsInputFontWidthDefined() const;
1177 * @brief Retrieves the input font's width.
1179 * @return The input font's width.
1181 FontWidth GetInputFontWidth() const;
1184 * @brief Sets the input font's slant.
1186 * @param[in] slant The input font's slant.
1188 void SetInputFontSlant(FontSlant slant);
1191 * @return Whether the font's slant has been defined.
1193 bool IsInputFontSlantDefined() const;
1196 * @brief Retrieves the input font's slant.
1198 * @return The input font's slant.
1200 FontSlant GetInputFontSlant() const;
1203 * @brief Sets the input font's point size.
1205 * @param[in] size The input font's point size.
1207 void SetInputFontPointSize(float size);
1210 * @brief Retrieves the input font's point size.
1212 * @return The input font's point size.
1214 float GetInputFontPointSize() const;
1217 * @brief Sets the input line spacing.
1219 * @param[in] lineSpacing The line spacing.
1221 void SetInputLineSpacing(float lineSpacing);
1224 * @brief Retrieves the input line spacing.
1226 * @return The line spacing.
1228 float GetInputLineSpacing() const;
1231 * @brief Sets the input shadow's properties string.
1233 * @note The string is stored to be recovered.
1235 * @param[in] shadowProperties The shadow's properties string.
1237 void SetInputShadowProperties(const std::string& shadowProperties);
1240 * @brief Retrieves the input shadow's properties string.
1242 * @return The shadow's properties string.
1244 const std::string& GetInputShadowProperties() const;
1247 * @brief Sets the input underline's properties string.
1249 * @note The string is stored to be recovered.
1251 * @param[in] underlineProperties The underline's properties string.
1253 void SetInputUnderlineProperties(const std::string& underlineProperties);
1256 * @brief Retrieves the input underline's properties string.
1258 * @return The underline's properties string.
1260 const std::string& GetInputUnderlineProperties() const;
1263 * @brief Sets the input emboss's properties string.
1265 * @note The string is stored to be recovered.
1267 * @param[in] embossProperties The emboss's properties string.
1269 void SetInputEmbossProperties(const std::string& embossProperties);
1272 * @brief Retrieves the input emboss's properties string.
1274 * @return The emboss's properties string.
1276 const std::string& GetInputEmbossProperties() const;
1279 * @brief Sets input the outline's properties string.
1281 * @note The string is stored to be recovered.
1283 * @param[in] outlineProperties The outline's properties string.
1285 void SetInputOutlineProperties(const std::string& outlineProperties);
1288 * @brief Retrieves the input outline's properties string.
1290 * @return The outline's properties string.
1292 const std::string& GetInputOutlineProperties() const;
1295 * @brief Set the control's interface.
1297 * @param[in] controlInterface The control's interface.
1299 void SetControlInterface(ControlInterface* controlInterface);
1302 * @brief Set the anchor control's interface.
1304 * @param[in] anchorControlInterface The control's interface.
1306 void SetAnchorControlInterface(AnchorControlInterface* anchorControlInterface);
1308 public: // Queries & retrieves.
1310 * @brief Return the layout engine.
1312 * @return A reference to the layout engine.
1314 Layout::Engine& GetLayoutEngine();
1317 * @brief Return a view of the text.
1319 * @return A reference to the view.
1324 * @copydoc Control::GetNaturalSize()
1326 Vector3 GetNaturalSize();
1329 * @copydoc Control::GetHeightForWidth()
1331 float GetHeightForWidth(float width);
1334 * @brief Calculates the point size for text for given layout()
1336 void FitPointSizeforLayout(Size layoutSize);
1339 * @brief Checks if the point size fits within the layout size.
1341 * @return Whether the point size fits within the layout size.
1343 bool CheckForTextFit(float pointSize, Size& layoutSize);
1346 * @brief Retrieves the text's number of lines for a given width.
1347 * @param[in] width The width of the text's area.
1348 * @ return The number of lines.
1350 int GetLineCount(float width);
1353 * @brief Retrieves the text's model.
1355 * @return A pointer to the text's model.
1357 const ModelInterface* const GetTextModel() const;
1360 * @brief Used to get scrolled distance by user input
1362 * @return Distance from last scroll offset to new scroll offset
1364 float GetScrollAmountByUserInput();
1367 * @brief Get latest scroll amount, control size and layout size
1369 * This method is used to get information of control's scroll
1370 * @param[out] scrollPosition The current scrolled position
1371 * @param[out] controlHeight The size of a UI control
1372 * @param[out] layoutHeight The size of a bounding box to layout text within.
1374 * @return Whether the text scroll position is changed or not after last update.
1376 bool GetTextScrollInfo(float& scrollPosition, float& controlHeight, float& layoutHeight);
1379 * @brief Used to set the hidden input option
1381 void SetHiddenInputOption(const Property::Map& options);
1384 * @brief Used to get the hidden input option
1386 void GetHiddenInputOption(Property::Map& options);
1389 * @brief Sets the Placeholder Properties.
1391 * @param[in] map The placeholder property map
1393 void SetPlaceholderProperty(const Property::Map& map);
1396 * @brief Retrieves the Placeholder Property map.
1398 * @param[out] map The property map
1400 void GetPlaceholderProperty(Property::Map& map);
1403 * @brief Checks text direction.
1404 * @return The text direction.
1406 Toolkit::DevelText::TextDirection::Type GetTextDirection();
1409 * @brief Retrieves vertical line alignment
1410 * @return The vertical line alignment
1412 Toolkit::DevelText::VerticalLineAlignment::Type GetVerticalLineAlignment() const;
1415 * @brief Sets vertical line alignment
1416 * @param[in] alignment The vertical line alignment for the text
1418 void SetVerticalLineAlignment(Toolkit::DevelText::VerticalLineAlignment::Type alignment);
1421 * @brief Retrieves ignoreSpaceAfterText value from model
1422 * @return The value of ignoreSpaceAfterText
1424 bool IsIgnoreSpacesAfterText() const;
1427 * @brief Sets ignoreSpaceAfterText value to model
1428 * @param[in] ignore The value of ignoreSpacesAfterText for the text
1430 void SetIgnoreSpacesAfterText(bool ignore);
1433 * @brief Retrieves matchSystemLanguageDirection value from model
1434 * @return The value of matchSystemLanguageDirection
1436 bool IsMatchSystemLanguageDirection() const;
1439 * @brief Sets matchSystemLanguageDirection value to model
1440 * @param[in] match The value of matchSystemLanguageDirection for the text
1442 void SetMatchSystemLanguageDirection(bool match);
1445 * @brief Sets layoutDirection value
1446 * @param[in] layoutDirection The value of system language direction
1448 void SetLayoutDirection(Dali::LayoutDirection::Type layoutDirection);
1451 * @brief Retrieves if showing real text or not.
1452 * @return The value of showing real text.
1454 bool IsShowingRealText() const;
1456 public: // Relayout.
1458 * @brief Triggers a relayout which updates View (if necessary).
1460 * @note UI Controls are expected to minimize calls to this method e.g. call once after size negotiation.
1461 * @param[in] size A the size of a bounding box to layout text within.
1462 * @param[in] layoutDirection The direction of the system language.
1464 * @return Whether the text model or decorations were updated.
1466 UpdateTextType Relayout(const Size& size, Dali::LayoutDirection::Type layoutDirection = Dali::LayoutDirection::LEFT_TO_RIGHT);
1469 * @brief Request a relayout using the ControlInterface.
1471 void RequestRelayout();
1473 public: // Input style change signals.
1475 * @return Whether the queue of input style changed signals is empty.
1477 bool IsInputStyleChangedSignalsQueueEmpty();
1480 * @brief Process all pending input style changed signals.
1482 * Calls the Text::ControlInterface::InputStyleChanged() method which is overriden by the
1483 * text controls. Text controls may send signals to state the input style has changed.
1485 void ProcessInputStyleChangedSignals();
1487 public: // Text-input Event Queuing.
1489 * @brief Called by editable UI controls when keyboard focus is gained.
1491 void KeyboardFocusGainEvent();
1494 * @brief Called by editable UI controls when focus is lost.
1496 void KeyboardFocusLostEvent();
1499 * @brief Called by editable UI controls when key events are received.
1501 * @param[in] event The key event.
1502 * @param[in] type Used to distinguish between regular key events and InputMethodContext events.
1504 bool KeyEvent(const Dali::KeyEvent& event);
1507 * @brief Called by anchor when a tap gesture occurs.
1508 * @param[in] x The x position relative to the top-left of the parent control.
1509 * @param[in] y The y position relative to the top-left of the parent control.
1511 void AnchorEvent(float x, float y);
1514 * @brief Called by editable UI controls when a tap gesture occurs.
1515 * @param[in] tapCount The number of taps.
1516 * @param[in] x The x position relative to the top-left of the parent control.
1517 * @param[in] y The y position relative to the top-left of the parent control.
1519 void TapEvent(unsigned int tapCount, float x, float y);
1522 * @brief Called by editable UI controls when a pan gesture occurs.
1524 * @param[in] state The state of the gesture.
1525 * @param[in] displacement This distance panned since the last pan gesture.
1527 void PanEvent(GestureState state, const Vector2& displacement);
1530 * @brief Called by editable UI controls when a long press gesture occurs.
1532 * @param[in] state The state of the gesture.
1533 * @param[in] x The x position relative to the top-left of the parent control.
1534 * @param[in] y The y position relative to the top-left of the parent control.
1536 void LongPressEvent(GestureState state, float x, float y);
1539 * @brief Used to get the Primary cursor position.
1541 * @return Primary cursor position.
1543 CharacterIndex GetPrimaryCursorPosition() const;
1546 * @brief Used to set the Primary cursor position.
1548 * @param[in] index for the Primary cursor position.
1549 * @return[in] true if cursor position changed, false otherwise.
1551 bool SetPrimaryCursorPosition(CharacterIndex index);
1554 * @brief Creates a selection event.
1556 * It could be called from the TapEvent (double tap) or when the text selection popup's sellect all button is pressed.
1558 * @param[in] x The x position relative to the top-left of the parent control.
1559 * @param[in] y The y position relative to the top-left of the parent control.
1560 * @param[in] selection type like the whole text is selected or unselected.
1562 void SelectEvent(float x, float y, SelectionType selection);
1565 * @copydoc Text::SelectableControlInterface::SetTextSelectionRange()
1567 void SetTextSelectionRange(const uint32_t* start, const uint32_t* end);
1570 * @copydoc Text::SelectableControlInterface::GetTextSelectionRange()
1572 Uint32Pair GetTextSelectionRange() const;
1575 * @copydoc Text::SelectableControlInterface::SelectWholeText()
1577 void SelectWholeText();
1580 * @copydoc Text::SelectableControlInterface::SelectNone()
1585 * @copydoc Text::SelectableControlInterface::GetSelectedText()
1587 string GetSelectedText() const;
1590 * @copydoc Text::EditableControlInterface::IsEditable()
1592 virtual bool IsEditable() const;
1595 * @copydoc Text::EditableControlInterface::SetEditable()
1597 virtual void SetEditable(bool editable);
1600 * @copydoc Dali::Toolkit::Internal::TextEditor::ScrollBy()
1602 virtual void ScrollBy(Vector2 scroll);
1605 * @copydoc Dali::Toolkit::Internal::TextEditor::GetHorizontalScrollPosition()
1607 float GetHorizontalScrollPosition();
1610 * @copydoc Dali::Toolkit::Internal::TextEditor::GetVerticalScrollPosition()
1612 float GetVerticalScrollPosition();
1615 * @brief Event received from input method context
1617 * @param[in] inputMethodContext The input method context.
1618 * @param[in] inputMethodContextEvent The event received.
1619 * @return A data struture indicating if update is needed, cursor position and current text.
1621 InputMethodContext::CallbackData OnInputMethodContextEvent(InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent);
1624 * @brief Event from Clipboard notifying an Item has been selected for pasting
1626 void PasteClipboardItemEvent();
1629 * @brief Return true when text control should clear key input focus when escape key is pressed.
1631 * @return Whether text control should clear key input focus or not when escape key is pressed.
1633 bool ShouldClearFocusOnEscape() const;
1636 * @brief Create an actor that renders the text background color
1638 * @return the created actor or an empty handle if no background color needs to be rendered.
1640 Actor CreateBackgroundActor();
1643 * @brief Used to reset the cursor position after setting a new text.
1645 * @param[in] cursorIndex Where to place the cursor.
1647 void ResetCursorPosition(CharacterIndex cursorIndex);
1650 * @brief The method acquires current position of cursor
1651 * @return unsigned value with cursor position
1653 CharacterIndex GetCursorPosition();
1655 protected: // Inherit from Text::Decorator::ControllerInterface.
1657 * @copydoc Dali::Toolkit::Text::Decorator::ControllerInterface::GetTargetSize()
1659 void GetTargetSize(Vector2& targetSize) override;
1662 * @copydoc Dali::Toolkit::Text::Decorator::ControllerInterface::AddDecoration()
1664 void AddDecoration(Actor& actor, bool needsClipping) override;
1667 * @copydoc Dali::Toolkit::Text::Decorator::ControllerInterface::DecorationEvent()
1669 void DecorationEvent(HandleType handle, HandleState state, float x, float y) override;
1671 protected: // Inherit from TextSelectionPopup::TextPopupButtonCallbackInterface.
1673 * @copydoc Dali::Toolkit::TextSelectionPopup::TextPopupButtonCallbackInterface::TextPopupButtonTouched()
1675 void TextPopupButtonTouched(Dali::Toolkit::TextSelectionPopup::Buttons button) override;
1677 protected: // Inherit from HiddenText.
1679 * @brief Invoked from HiddenText when showing time of the last character was expired
1681 void DisplayTimeExpired() override;
1685 * @brief Called by editable UI controls when key events are received.
1687 * @param[in] text The text to insert.
1688 * @param[in] type Used to distinguish between regular key events and InputMethodContext events.
1690 void InsertText(const std::string& text, InsertType type);
1693 * @brief Paste given string into Text model
1694 * @param[in] stringToPaste this string will be inserted into the text model
1696 void PasteText(const std::string& stringToPaste);
1699 * @brief Remove a given number of characters
1701 * When predictve text is used the pre-edit text is removed and inserted again with the new characters.
1702 * The UpdateInputStyleType @type parameter if set to DONT_UPDATE_INPUT_STYLE avoids to update the input
1703 * style when pre-edit text is removed.
1705 * @param[in] cursorOffset Start position from the current cursor position to start deleting characters.
1706 * @param[in] numberOfCharacters The number of characters to delete from the cursorOffset.
1707 * @param[in] type Whether to update the input style.
1708 * @return True if the remove was successful.
1710 bool RemoveText(int cursorOffset,
1711 int numberOfCharacters,
1712 UpdateInputStyleType type);
1715 * @brief Checks if text is selected and if so removes it.
1716 * @return true if text was removed
1718 bool RemoveSelectedText();
1721 * @brief Update anchor position from given number of inserted characters.
1723 * @param[in] numberOfCharacters The number of inserted characters.
1724 * @param[in] previousCursorIndex A cursor position before event occurs.
1726 void InsertTextAnchor(int numberOfCharacters,
1727 CharacterIndex previousCursorIndex);
1730 * @brief Update anchor position from given number of removed characters.
1732 * @param[in] cursorOffset Start position from the current cursor position to start deleting characters.
1733 * @param[in] numberOfCharacters The number of removed characters.
1734 * @param[in] previousCursorIndex A cursor position before event occurs.
1736 void RemoveTextAnchor(int cursorOffset,
1737 int numberOfCharacters,
1738 CharacterIndex previousCursorIndex);
1740 private: // Relayout.
1742 * @brief Lays-out the text.
1744 * GetNaturalSize(), GetHeightForWidth() and Relayout() calls this method.
1746 * @param[in] size A the size of a bounding box to layout text within.
1747 * @param[in] operations The layout operations which need to be done.
1748 * @param[out] layoutSize The size of the laid-out text.
1750 bool DoRelayout(const Size& size,
1751 OperationsMask operations,
1755 * @brief Calulates the vertical offset to align the text inside the bounding box.
1757 * @param[in] size The size of the bounding box.
1759 void CalculateVerticalOffset(const Size& size);
1763 * @brief Process queued events which modify the model.
1765 void ProcessModifyEvents();
1768 * @brief Used to process an event queued from SetText()
1770 void TextReplacedEvent();
1773 * @brief Used to process an event queued from key events etc.
1775 void TextInsertedEvent();
1778 * @brief Used to process an event queued from backspace key etc.
1780 void TextDeletedEvent();
1783 * @brief Helper to KeyEvent() to handle the backspace or delete key case.
1785 * @param[in] keyCode The keycode for the key pressed
1786 * @return True if a character was deleted.
1788 bool DeleteEvent(int keyCode);
1790 private: // Helpers.
1792 * @brief Used to remove the text included the placeholder text.
1797 * @brief Helper to show the place holder text..
1799 void ShowPlaceholderText();
1802 * @brief Helper to clear font-specific data (only).
1804 void ClearFontData();
1807 * @brief Helper to clear text's style data.
1809 void ClearStyleData();
1812 * @brief Used to reset the scroll position after setting a new text.
1814 void ResetScrollPosition();
1816 private: // Private contructors & copy operator.
1818 * @brief Private constructor.
1823 * @brief Private constructor.
1825 Controller(ControlInterface* controlInterface);
1828 * @brief Private constructor.
1830 Controller(ControlInterface* controlInterface,
1831 EditableControlInterface* editableControlInterface,
1832 SelectableControlInterface* selectableControlInterface,
1833 AnchorControlInterface* anchorControlInterface);
1836 Controller(const Controller& handle);
1839 Controller& operator=(const Controller& handle);
1841 protected: // Destructor.
1843 * @brief A reference counted object may only be deleted by calling Unreference().
1845 virtual ~Controller();
1848 struct Impl; ///< Made public for testing purposes
1851 struct EventHandler;
1852 struct InputFontHandler;
1853 struct PlaceholderHandler;
1862 } // namespace Toolkit
1866 #endif // DALI_TOOLKIT_TEXT_CONTROLLER_H