[dali_2.3.20] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / devel-api / controls / text-controls / text-field-devel.h
1 #ifndef DALI_TOOLKIT_TEXT_FIELD_DEVEL_H
2 #define DALI_TOOLKIT_TEXT_FIELD_DEVEL_H
3
4 /*
5  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20 // EXTERNAL INCLUDES
21 #include <dali/devel-api/adaptor-framework/input-method-context.h>
22
23 // INTERNAL INCLUDES
24 #include <dali-toolkit/public-api/controls/text-controls/input-filter-properties.h>
25 #include <dali-toolkit/public-api/controls/text-controls/text-field.h>
26
27 namespace Dali
28 {
29 namespace Toolkit
30 {
31 namespace DevelTextField
32 {
33 namespace Property
34 {
35 enum
36 {
37   TEXT                                 = Dali::Toolkit::TextField::Property::TEXT,
38   PLACEHOLDER_TEXT                     = Dali::Toolkit::TextField::Property::PLACEHOLDER_TEXT,
39   PLACEHOLDER_TEXT_FOCUSED             = Dali::Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED,
40   FONT_FAMILY                          = Dali::Toolkit::TextField::Property::FONT_FAMILY,
41   FONT_STYLE                           = Dali::Toolkit::TextField::Property::FONT_STYLE,
42   POINT_SIZE                           = Dali::Toolkit::TextField::Property::POINT_SIZE,
43   MAX_LENGTH                           = Dali::Toolkit::TextField::Property::MAX_LENGTH,
44   EXCEED_POLICY                        = Dali::Toolkit::TextField::Property::EXCEED_POLICY,
45   HORIZONTAL_ALIGNMENT                 = Dali::Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT,
46   VERTICAL_ALIGNMENT                   = Dali::Toolkit::TextField::Property::VERTICAL_ALIGNMENT,
47   TEXT_COLOR                           = Dali::Toolkit::TextField::Property::TEXT_COLOR,
48   PLACEHOLDER_TEXT_COLOR               = Dali::Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR,
49   PRIMARY_CURSOR_COLOR                 = Dali::Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR,
50   SECONDARY_CURSOR_COLOR               = Dali::Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR,
51   ENABLE_CURSOR_BLINK                  = Dali::Toolkit::TextField::Property::ENABLE_CURSOR_BLINK,
52   CURSOR_BLINK_INTERVAL                = Dali::Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL,
53   CURSOR_BLINK_DURATION                = Dali::Toolkit::TextField::Property::CURSOR_BLINK_DURATION,
54   CURSOR_WIDTH                         = Dali::Toolkit::TextField::Property::CURSOR_WIDTH,
55   GRAB_HANDLE_IMAGE                    = Dali::Toolkit::TextField::Property::GRAB_HANDLE_IMAGE,
56   GRAB_HANDLE_PRESSED_IMAGE            = Dali::Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE,
57   SCROLL_THRESHOLD                     = Dali::Toolkit::TextField::Property::SCROLL_THRESHOLD,
58   SCROLL_SPEED                         = Dali::Toolkit::TextField::Property::SCROLL_SPEED,
59   SELECTION_HANDLE_IMAGE_LEFT          = Dali::Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT,
60   SELECTION_HANDLE_IMAGE_RIGHT         = Dali::Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT,
61   SELECTION_HANDLE_PRESSED_IMAGE_LEFT  = Dali::Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT,
62   SELECTION_HANDLE_PRESSED_IMAGE_RIGHT = Dali::Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT,
63   SELECTION_HANDLE_MARKER_IMAGE_LEFT   = Dali::Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT,
64   SELECTION_HANDLE_MARKER_IMAGE_RIGHT  = Dali::Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT,
65   SELECTION_HIGHLIGHT_COLOR            = Dali::Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR,
66   DECORATION_BOUNDING_BOX              = Dali::Toolkit::TextField::Property::DECORATION_BOUNDING_BOX,
67   INPUT_METHOD_SETTINGS                = Dali::Toolkit::TextField::Property::INPUT_METHOD_SETTINGS,
68   INPUT_COLOR                          = Dali::Toolkit::TextField::Property::INPUT_COLOR,
69   ENABLE_MARKUP                        = Dali::Toolkit::TextField::Property::ENABLE_MARKUP,
70   INPUT_FONT_FAMILY                    = Dali::Toolkit::TextField::Property::INPUT_FONT_FAMILY,
71   INPUT_FONT_STYLE                     = Dali::Toolkit::TextField::Property::INPUT_FONT_STYLE,
72   INPUT_POINT_SIZE                     = Dali::Toolkit::TextField::Property::INPUT_POINT_SIZE,
73   UNDERLINE                            = Dali::Toolkit::TextField::Property::UNDERLINE,
74   INPUT_UNDERLINE                      = Dali::Toolkit::TextField::Property::INPUT_UNDERLINE,
75   SHADOW                               = Dali::Toolkit::TextField::Property::SHADOW,
76   INPUT_SHADOW                         = Dali::Toolkit::TextField::Property::INPUT_SHADOW,
77   EMBOSS                               = Dali::Toolkit::TextField::Property::EMBOSS,
78   INPUT_EMBOSS                         = Dali::Toolkit::TextField::Property::INPUT_EMBOSS,
79   OUTLINE                              = Dali::Toolkit::TextField::Property::OUTLINE,
80   INPUT_OUTLINE                        = Dali::Toolkit::TextField::Property::INPUT_OUTLINE,
81   HIDDEN_INPUT_SETTINGS                = Dali::Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS,
82   PIXEL_SIZE                           = Dali::Toolkit::TextField::Property::PIXEL_SIZE,
83   ENABLE_SELECTION                     = Dali::Toolkit::TextField::Property::ENABLE_SELECTION,
84   PLACEHOLDER                          = Dali::Toolkit::TextField::Property::PLACEHOLDER,
85   ELLIPSIS                             = Dali::Toolkit::TextField::Property::ELLIPSIS,
86
87   /**
88    * @brief Enables Text selection using Shift key.
89    * @details Name "enableShiftSelection", type Property::BOOLEAN.
90    */
91   ENABLE_SHIFT_SELECTION = ELLIPSIS + 1,
92
93   /**
94    * @brief Enables the grab handles for text selection.
95    * @details Name "enableGrabHandle", type Property::BOOLEAN.
96    * @note The default value is true, which means the grab handles are enabled by default.
97    */
98   ENABLE_GRAB_HANDLE = ELLIPSIS + 2,
99
100   /**
101    * @brief Modifies the default text alignment to match the direction of the system language.
102    * @details Name "matchSystemLanguageDirection", type (Property::BOOLEAN), Read/Write
103    * @note The default value is true
104    */
105   MATCH_SYSTEM_LANGUAGE_DIRECTION = ELLIPSIS + 3,
106
107   /**
108    * @brief Enables the grab handle popup for text selection.
109    * @details Name "enableGrabHandlePopup", type Property::BOOLEAN.
110    * @note The default value is true, which means the grab handle popup is enabled by default.
111    */
112   ENABLE_GRAB_HANDLE_POPUP = ELLIPSIS + 4,
113
114   /**
115    * @brief The default text background parameters.
116    * @details Name "textBackground", type Property::VECTOR4.
117    * @note Use "textBackground" as property name to avoid conflict with Control's "background" property.
118    * @note The default value is Color::TRANSPARENT.
119    */
120   BACKGROUND = ELLIPSIS + 5,
121
122   /**
123    * @brief The selected text in UTF-8 format.
124    * @details Name "selectedText", type Property::STRING.
125    * @note This property is read-only.
126    */
127   SELECTED_TEXT = ELLIPSIS + 6,
128
129   /**
130    * @brief The type or rendering e.g. bitmap-based.
131    * @details Name "renderingBackend", type Property::INTEGER.
132    */
133   RENDERING_BACKEND = ELLIPSIS + 7,
134
135   /**
136    * @brief The selected text start position.
137    * @details Name "selectedTextStart", type Property::INTEGER.
138    */
139   SELECTED_TEXT_START,
140
141   /**
142    * @brief The selected text range end position.
143    * @details Name "selectedTextEnd", type Property::INTEGER.
144    */
145   SELECTED_TEXT_END,
146
147   /**
148    * @brief The Editable state of control.
149    * @details Name "enableEditing", type Property::BOOLEAN.
150    */
151   ENABLE_EDITING,
152
153   /**
154    * @brief The font size scale.
155    * @details name "fontSizeScale", type Property::FLOAT.
156    * @note The default value is 1.0 which does nothing.
157    * The given font size scale value is used for multiplying the specified font size before querying fonts.
158    *
159    * e.g. The rendering results of both cases are same.
160    *  - fontSize: 15pt, fontSizeScale: 1.0
161    *  - fontSize: 10pt, fontSizeScale: 1.5
162    */
163   FONT_SIZE_SCALE,
164
165   /**
166    * @brief True to enable the font size scale or false to disable.
167    * @details Name "enableFontSizeScale", type Property::BOOLEAN.
168    * @note The default value is true.
169    * If false, font size scale is not apppied.
170    */
171   ENABLE_FONT_SIZE_SCALE,
172
173   /**
174    * @brief The position for primary cursor.
175    * @details Name "primaryCursorPosition", type Property::INTEGER.
176    */
177   PRIMARY_CURSOR_POSITION,
178
179   /**
180    * @brief The color of the grab color.
181    * @details Name "grabHandleColor", type Property::VECTOR4.
182    */
183   GRAB_HANDLE_COLOR,
184
185   /**
186    * @brief The input filter
187    * @details Name "inputFilter", type Property::MAP.
188    *
189    * The inputFilter map contains the following keys:
190    *
191    * | %Property Name       | Type     | Required | Description                                                                                                         |
192    * |----------------------|----------|----------|---------------------------------------------------------------------------------------------------------------------|
193    * | accepted             | STRING   | No       | A regular expression in the set of characters to be accepted by the inputFilter (the default value is empty string) |
194    * | rejected             | STRING   | No       | A regular expression in the set of characters to be rejected by the inputFilter (the default value is empty string) |
195    *
196    * @note Optional.
197    * The character set must follow the regular expression rules.
198    * Behaviour can not be guaranteed for incorrect grammars.
199    * Refer the link below for detailed rules.
200    * The functions in std::regex library use the ECMAScript grammar:
201    * http://cplusplus.com/reference/regex/ECMAScript/
202    *
203    * You can use enums instead of "accepted" and "rejected" strings.
204    * @see Dali::Toolkit::InputFilter::Property::Type
205    *
206    * Example Usage:
207    * @code
208    *   Property::Map filter;
209    *   filter[InputFilter::Property::ACCEPTED] = "[\\d]"; // accept whole digits
210    *   filter[InputFilter::Property::REJECTED] = "[0-5]"; // reject 0, 1, 2, 3, 4, 5
211    *
212    *   field.SetProperty(DevelTextField::Property::INPUT_FILTER, filter); // acceptable inputs are 6, 7, 8, 9
213    * @endcode
214    */
215   INPUT_FILTER,
216
217   /**
218   * @brief The enumerations used to specify whether to position the ellipsis at the END, START or MIDDLE of the text.
219   * @details Name "EllipsisPosition", type [Type](@ref Dali::Toolkit::DevelText::EllipsisPosition::Type) (Property::INTEGER), or Property::STRING. Read/Write
220   * @note Default is EllipsisPosition::END.
221   * @see DevelText::EllipsisPosition
222   */
223   ELLIPSIS_POSITION,
224
225   /**
226    * @brief A horizontal line through the text center.
227    * @details Name "strikethrough", type Property::MAP.
228    */
229   STRIKETHROUGH,
230
231   /**
232    * @brief The strikethrough parameters of the new input text.
233    * @details Name "inputStrikethrough", type Property::MAP.
234    */
235   INPUT_STRIKETHROUGH,
236
237   /**
238   * @brief The spaces between characters in Pixels.
239   * @details Name "characterSpacing", type Property::FLOAT.
240   * @note
241   *   A positive value will make the characters far apart (expanded) and a negative value will bring them closer (condensed).
242   *   The default value is 0.f which does nothing.
243   */
244   CHARACTER_SPACING,
245
246   /**
247    * @brief Sets the selection popup style
248    * @details Name "selectionPopupStyle", type Property::MAP.
249    * @see Dali::Toolkit::TextSelectionPopup::Property
250    */
251   SELECTION_POPUP_STYLE,
252 };
253
254 } // namespace Property
255
256 /**
257  * @brief Return the input method context of TextField.
258  *
259  * @param[in] textField The instance of TextField.
260  * @return InputMethodContext instance.
261  */
262 DALI_TOOLKIT_API InputMethodContext GetInputMethodContext(TextField textField);
263
264 /**
265  * @brief Anchor clicked signal type.
266  *
267  * @note Signal
268  *  - const char* : href of clicked anchor.
269  *  - uint32_t    : length of href.
270  */
271 using AnchorClickedSignalType = Signal<void(TextField, const char*, uint32_t)>;
272
273 /**
274  * @brief This signal is emitted when the anchor is clicked.
275  *
276  * A callback of the following type may be connected:
277  * @code
278  *   void YourCallbackName(TextField textField, const char* href, uint32_t hrefLength);
279  * @endcode
280  * @param[in] textField The instance of TextField.
281  * @return The signal to connect to.
282  */
283 DALI_TOOLKIT_API AnchorClickedSignalType& AnchorClickedSignal(TextField textField);
284
285 /**
286  * @brief cursor position changed signal type.
287  *
288  * @note Signal
289  *  - uint32_t    : old position.
290  */
291 using CursorPositionChangedSignalType = Signal<void(TextField, uint32_t)>;
292
293 /**
294  * @brief This signal is emitted when the cursor position has been changed.
295  *
296  * A callback of the following type may be connected:
297  * @code
298  *   void YourCallbackName(TextField textField, uint32_t oldPosition);
299  * @endcode
300  * @param[in] textField The instance of TextField.
301  * @return The signal to connect to.
302  */
303 DALI_TOOLKIT_API CursorPositionChangedSignalType& CursorPositionChangedSignal(TextField textField);
304
305 /**
306  * @brief Input filtered signal type.
307  */
308 using InputFilteredSignalType = Signal<void(TextField, Toolkit::InputFilter::Property::Type)>;
309
310 /**
311  * @brief This signal is emitted when the character to be inserted is filtered by the input filter.
312  *
313  * A callback of the following type may be connected:
314  * @code
315  *   void YourCallbackName(TextField textField, Toolkit::InputFilter::Property::Type type);
316  *
317  *   DevelTextField::InputFilteredSignal(textField).Connect(this, &OnInputFiltered);
318  *
319  *   void OnInputFiltered(TextField textField, InputFilter::Property::Type type)
320  *   {
321  *     if (type == InputFilter::Property::ACCEPTED)
322  *     {
323  *       // If the input has been filtered with an accepted filter, the type is ACCEPTED.
324  *     }
325  *     else if (type == InputFilter::Property::REJECTED)
326  *     {
327  *       // If the input has been filtered with an rejected filter, the type is REJECTED.
328  *     }
329  *   }
330  * @endcode
331  * @param[in] textField The instance of TextField.
332  * @return The signal to connect to.
333  */
334 DALI_TOOLKIT_API InputFilteredSignalType& InputFilteredSignal(TextField textField);
335
336 /**
337  * @brief selection changed signal type.
338  *
339  * @note Signal
340  *  - uint32_t  : selection start before the change.
341  *  - uint32_t  : selection end before the change.
342  */
343 using SelectionChangedSignalType = Signal<void(TextField, uint32_t, uint32_t)>;
344
345 /**
346  * @brief This signal is emitted when the selection has been changed.
347  *
348  * A callback of the following type may be connected:
349  * @code
350  *   void YourCallbackName( TextField textField, uint32_t oldStart, uint32_t oldEnd);
351  * @endcode
352  * @param[in] textField The instance of TextField.
353  * @return The signal to connect to
354  */
355 DALI_TOOLKIT_API SelectionChangedSignalType& SelectionChangedSignal(TextField textField);
356
357 /**
358  * @brief selection cleared signal type.
359  */
360 using SelectionClearedSignalType = Signal<void(TextField)>;
361
362 /**
363  * @brief This signal is emitted when the selection has been cleared.
364  *
365  * A callback of the following type may be connected:
366  * @code
367  *   void YourCallbackName( TextField textField);
368  * @endcode
369  * @param[in] textField The instance of TextField.
370  * @return The signal to connect to
371  */
372 DALI_TOOLKIT_API SelectionClearedSignalType& SelectionClearedSignal(TextField textField);
373
374 /**
375  * @brief selection start signal type.
376  */
377 using SelectionStartedSignalType = Signal<void(TextField)>;
378
379 /**
380  * @brief This signal is emitted when the selection start.
381  *
382  * A callback of the following type may be connected:
383  * @code
384  *   void YourCallbackName( TextField textField);
385  * @endcode
386  * @param[in] textField The instance of TextField.
387  * @return The signal to connect to
388  */
389 DALI_TOOLKIT_API SelectionStartedSignalType& SelectionStartedSignal(TextField textField);
390
391 /**
392  * @brief Get the rendered size of a specific text range.
393  * if the requested text is at multilines, multiple sizes will be returned for each text located in a separate line.
394  * if a line contains characters with different directions, multiple sizes will be returned for each block of contiguous characters with the same direction.
395  *
396  * @param[in] textField The instance of TextField.
397  * @param[in] startIndex start index of the text requested to calculate size for.
398  * @param[in] endIndex end index(included) of the text requested to calculate size for.
399  * @return list of sizes of the reuested text.
400  */
401 DALI_TOOLKIT_API Vector<Vector2> GetTextSize(TextField textField, const uint32_t startIndex, const uint32_t endIndex);
402
403 /**
404  * @brief Get the top/left rendered position of a specific text range.
405  * if the requested text is at multilines, multiple positions will be returned for each text located in a separate line.
406  * if a line contains characters with different directions, multiple positions will be returned for each block of contiguous characters with the same direction.
407  *
408  * @param[in] textField The instance of TextField.
409  * @param[in] startIndex start index of the text requested to get position to.
410  * @param[in] endIndex end index(included) of the text requested to get position to.
411  * @return list of positions of the requested text.
412  */
413 DALI_TOOLKIT_API Vector<Vector2> GetTextPosition(TextField textField, const uint32_t startIndex, const uint32_t endIndex);
414
415 /**
416  * @brief Gets the bounding box of a specific text range.
417  *
418  * @param[in] textField The instance of textField.
419  * @param[in] startIndex start index of the text requested to get bounding box to.
420  * @param[in] endIndex end index(included) of the text requested to get bounding box to.
421  * @return bounding box of the requested text.
422  */
423 DALI_TOOLKIT_API Rect<> GetTextBoundingRectangle(TextField textField, uint32_t startIndex, uint32_t endIndex);
424
425 /**
426  * @brief Select the whole text of TextField.
427  *
428  * @param[in] textField The instance of TextField.
429  */
430 DALI_TOOLKIT_API void SelectWholeText(TextField textField);
431
432 /**
433  * @brief Unselect the whole text of TextField.
434  *
435  * @param[in] textField The instance of TextField.
436  */
437 DALI_TOOLKIT_API void SelectNone(TextField textField);
438
439 /**
440  * @brief Select the text from start index to end index of TextField.
441  * @note
442  * The selection index is based on the cursor index.
443  *
444  * text   H e l l o
445  * index 0 1 2 3 4 5
446  * if textField.SelectText(1, 4); is executed, "ell" is selected.
447  *
448  * @param[in] textField The instance of TextField.
449  * @param[in] start The start index of the text to select. (The starting point of start index is 0.)
450  * @param[in] end The end index of the text to select. (If end index > text's length, the end index is set to the length of the text.)
451  */
452 DALI_TOOLKIT_API void SelectText(TextField textField, const uint32_t start, const uint32_t end);
453
454 /**
455  * @brief Copy and return the selected text of TextField.
456  *
457  * @param[in] textField The instance of TextField.
458  * @return The copied text.
459  */
460 DALI_TOOLKIT_API std::string CopyText(TextField textField);
461
462 /**
463  * @brief Cut and return the selected text of TextField.
464  *
465  * @param[in] textField The instance of TextField.
466  * @return The cut text.
467  */
468 DALI_TOOLKIT_API std::string CutText(TextField textField);
469
470 /**
471  * @brief Paste the most recent clipboard text item into the TextField.
472  *
473  * @param[in] textField The instance of TextField.
474  */
475 DALI_TOOLKIT_API void PasteText(TextField textField);
476
477 } // namespace DevelTextField
478
479 } // namespace Toolkit
480
481 } // namespace Dali
482
483 #endif // DALI_TOOLKIT_TEXT_FIELD_DEVEL_H