Add TextSelect()
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / devel-api / controls / text-controls / text-editor-devel.h
1 #ifndef DALI_TOOLKIT_TEXT_EDITOR_DEVEL_H
2 #define DALI_TOOLKIT_TEXT_EDITOR_DEVEL_H
3
4 /*
5  * Copyright (c) 2021 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-editor.h>
26
27 namespace Dali
28 {
29 namespace Toolkit
30 {
31 namespace DevelTextEditor
32 {
33 namespace Property
34 {
35 enum Type
36 {
37   TEXT                                 = Dali::Toolkit::TextEditor::Property::TEXT,
38   TEXT_COLOR                           = Dali::Toolkit::TextEditor::Property::TEXT_COLOR,
39   FONT_FAMILY                          = Dali::Toolkit::TextEditor::Property::FONT_FAMILY,
40   FONT_STYLE                           = Dali::Toolkit::TextEditor::Property::FONT_STYLE,
41   POINT_SIZE                           = Dali::Toolkit::TextEditor::Property::POINT_SIZE,
42   HORIZONTAL_ALIGNMENT                 = Dali::Toolkit::TextEditor::Property::HORIZONTAL_ALIGNMENT,
43   SCROLL_THRESHOLD                     = Dali::Toolkit::TextEditor::Property::SCROLL_THRESHOLD,
44   SCROLL_SPEED                         = Dali::Toolkit::TextEditor::Property::SCROLL_SPEED,
45   PRIMARY_CURSOR_COLOR                 = Dali::Toolkit::TextEditor::Property::PRIMARY_CURSOR_COLOR,
46   SECONDARY_CURSOR_COLOR               = Dali::Toolkit::TextEditor::Property::SECONDARY_CURSOR_COLOR,
47   ENABLE_CURSOR_BLINK                  = Dali::Toolkit::TextEditor::Property::ENABLE_CURSOR_BLINK,
48   CURSOR_BLINK_INTERVAL                = Dali::Toolkit::TextEditor::Property::CURSOR_BLINK_INTERVAL,
49   CURSOR_BLINK_DURATION                = Dali::Toolkit::TextEditor::Property::CURSOR_BLINK_DURATION,
50   CURSOR_WIDTH                         = Dali::Toolkit::TextEditor::Property::CURSOR_WIDTH,
51   GRAB_HANDLE_IMAGE                    = Dali::Toolkit::TextEditor::Property::GRAB_HANDLE_IMAGE,
52   GRAB_HANDLE_PRESSED_IMAGE            = Dali::Toolkit::TextEditor::Property::GRAB_HANDLE_PRESSED_IMAGE,
53   SELECTION_HANDLE_IMAGE_LEFT          = Dali::Toolkit::TextEditor::Property::SELECTION_HANDLE_IMAGE_LEFT,
54   SELECTION_HANDLE_IMAGE_RIGHT         = Dali::Toolkit::TextEditor::Property::SELECTION_HANDLE_IMAGE_RIGHT,
55   SELECTION_HANDLE_PRESSED_IMAGE_LEFT  = Dali::Toolkit::TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT,
56   SELECTION_HANDLE_PRESSED_IMAGE_RIGHT = Dali::Toolkit::TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT,
57   SELECTION_HANDLE_MARKER_IMAGE_LEFT   = Dali::Toolkit::TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT,
58   SELECTION_HANDLE_MARKER_IMAGE_RIGHT  = Dali::Toolkit::TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT,
59   SELECTION_HIGHLIGHT_COLOR            = Dali::Toolkit::TextEditor::Property::SELECTION_HIGHLIGHT_COLOR,
60   DECORATION_BOUNDING_BOX              = Dali::Toolkit::TextEditor::Property::DECORATION_BOUNDING_BOX,
61   ENABLE_MARKUP                        = Dali::Toolkit::TextEditor::Property::ENABLE_MARKUP,
62   INPUT_COLOR                          = Dali::Toolkit::TextEditor::Property::INPUT_COLOR,
63   INPUT_FONT_FAMILY                    = Dali::Toolkit::TextEditor::Property::INPUT_FONT_FAMILY,
64   INPUT_FONT_STYLE                     = Dali::Toolkit::TextEditor::Property::INPUT_FONT_STYLE,
65   INPUT_POINT_SIZE                     = Dali::Toolkit::TextEditor::Property::INPUT_POINT_SIZE,
66   LINE_SPACING                         = Dali::Toolkit::TextEditor::Property::LINE_SPACING,
67   INPUT_LINE_SPACING                   = Dali::Toolkit::TextEditor::Property::INPUT_LINE_SPACING,
68   UNDERLINE                            = Dali::Toolkit::TextEditor::Property::UNDERLINE,
69   INPUT_UNDERLINE                      = Dali::Toolkit::TextEditor::Property::INPUT_UNDERLINE,
70   SHADOW                               = Dali::Toolkit::TextEditor::Property::SHADOW,
71   INPUT_SHADOW                         = Dali::Toolkit::TextEditor::Property::INPUT_SHADOW,
72   EMBOSS                               = Dali::Toolkit::TextEditor::Property::EMBOSS,
73   INPUT_EMBOSS                         = Dali::Toolkit::TextEditor::Property::INPUT_EMBOSS,
74   OUTLINE                              = Dali::Toolkit::TextEditor::Property::OUTLINE,
75   INPUT_OUTLINE                        = Dali::Toolkit::TextEditor::Property::INPUT_OUTLINE,
76   SMOOTH_SCROLL                        = Dali::Toolkit::TextEditor::Property::SMOOTH_SCROLL,
77   SMOOTH_SCROLL_DURATION               = Dali::Toolkit::TextEditor::Property::SMOOTH_SCROLL_DURATION,
78   ENABLE_SCROLL_BAR                    = Dali::Toolkit::TextEditor::Property::ENABLE_SCROLL_BAR,
79   SCROLL_BAR_SHOW_DURATION             = Dali::Toolkit::TextEditor::Property::SCROLL_BAR_SHOW_DURATION,
80   SCROLL_BAR_FADE_DURATION             = Dali::Toolkit::TextEditor::Property::SCROLL_BAR_FADE_DURATION,
81   PIXEL_SIZE                           = Dali::Toolkit::TextEditor::Property::PIXEL_SIZE,
82   LINE_COUNT                           = Dali::Toolkit::TextEditor::Property::LINE_COUNT,
83   ENABLE_SELECTION                     = Dali::Toolkit::TextEditor::Property::ENABLE_SELECTION,
84   PLACEHOLDER                          = Dali::Toolkit::TextEditor::Property::PLACEHOLDER,
85   LINE_WRAP_MODE                       = Dali::Toolkit::TextEditor::Property::LINE_WRAP_MODE,
86
87   /**
88    * @brief The text to display when the TextEditor is empty and inactive.
89    * @details Name "placeholderText", type Property::STRING.
90    */
91   PLACEHOLDER_TEXT,
92
93   /**
94    * @brief The placeholder-text color.
95    * @details Name "placeholderTextColor", type Property::VECTOR4.
96    */
97   PLACEHOLDER_TEXT_COLOR,
98
99   /**
100    * @brief Enables Text selection using Shift key.
101    * @details Name "enableShiftSelection", type Property::BOOLEAN.
102    */
103   ENABLE_SHIFT_SELECTION,
104
105   /**
106    * @brief Enables the grab handles for text selection.
107    * @details Name "enableGrabHandle", type Property::BOOLEAN.
108    * @note The default value is true, which means the grab handles are enabled by default.
109    */
110   ENABLE_GRAB_HANDLE,
111
112   /**
113    * @brief Modifies the default text alignment to match the direction of the system language.
114    * @details Name "matchSystemLanguageDirection", type (Property::BOOLEAN), Read/Write
115    * @note The default value is true
116    */
117   MATCH_SYSTEM_LANGUAGE_DIRECTION,
118
119   /**
120    * @brief The type or rendering e.g. bitmap-based.
121    * @details Name "renderingBackend", type Property::INTEGER.
122    */
123   RENDERING_BACKEND,
124
125   /**
126    * @brief The maximum number of characters that can be inserted.
127    * @details Name "maxLength", type Property::INTEGER.
128    */
129   MAX_LENGTH,
130
131   /**
132    * @brief The selected text start position.
133    * @details Name "selectedTextStart", type Property::INTEGER.
134    */
135   SELECTED_TEXT_START,
136
137   /**
138    * @brief The selected text range end position.
139    * @details Name "selectedTextEnd", type Property::INTEGER.
140    */
141   SELECTED_TEXT_END,
142
143   /**
144    * @brief The horizontal scroll position in pixels.
145    * @details Name "horizontalScrollPosition", type Property::FLOAT.
146    */
147   HORIZONTAL_SCROLL_POSITION,
148
149   /**
150    * @brief The vertical scroll position in pixels.
151    * @details Name "verticalScrollPosition", type Property::FLOAT.
152    */
153   VERTICAL_SCROLL_POSITION,
154
155   /**
156    * @brief The Editable state of control.
157    * @details Name "enableEditing", type Property::BOOLEAN.
158    */
159   ENABLE_EDITING,
160
161   /**
162    * @brief The selected text in UTF-8 format.
163    * @details Name "selectedText", type Property::STRING.
164    * @note This property is read-only.
165    */
166   SELECTED_TEXT,
167
168   /**
169    * @brief The font size scale.
170    * @details name "fontSizeScale", type Property::FLOAT.
171    * @note The default value is 1.0 which does nothing.
172    * The given font size scale value is used for multiplying the specified font size before querying fonts.
173    *
174    * e.g. The rendering results of both cases are same.
175    *  - fontSize: 15pt, fontSizeScale: 1.0
176    *  - fontSize: 10pt, fontSizeScale: 1.5
177    */
178   FONT_SIZE_SCALE,
179
180   /**
181    * @brief The position for primary cursor.
182    * @details Name "primaryCursorPosition", type Property::INTEGER.
183    */
184   PRIMARY_CURSOR_POSITION,
185
186   /**
187    * @brief The color of the grab color.
188    * @details Name "grabHandleColor", type Property::VECTOR4.
189    */
190   GRAB_HANDLE_COLOR,
191
192   /**
193    * @brief Enables the grab handle popup for text selection.
194    * @details Name "enableGrabHandlePopup", type Property::BOOLEAN.
195    * @note The default value is true, which means the grab handle popup is enabled by default.
196    */
197   ENABLE_GRAB_HANDLE_POPUP,
198
199   /**
200    * @brief The settings to relating to the System's Input Method, Key and Value.
201    * @details Name "inputMethodSettings", type Property::MAP.
202    *
203    * @note VARIATION key can be changed depending on PANEL_LAYOUT.
204    * For example, when PANEL_LAYOUT key is InputMethod::PanelLayout::NORMAL,
205    * then VARIATION would be among NORMAL, WITH_FILENAME, and WITH_PERSON_NAME in Dali::InputMethod::NormalLayout.
206    * For more information, see Dali::InputMethod::Category.
207    *
208    * Example Usage:
209    * @code
210    *   Property::Map propertyMap;
211    *   InputMethod::PanelLayout::Type panelLayout = InputMethod::PanelLayout::NUMBER;
212    *   InputMethod::AutoCapital::Type autoCapital = InputMethod::AutoCapital::WORD;
213    *   InputMethod::ButtonAction::Type buttonAction = InputMethod::ButtonAction::GO;
214    *   int inputVariation = 1;
215    *   propertyMap["PANEL_LAYOUT"] = panelLayout;
216    *   propertyMap["AUTO_CAPITALIZE"] = autoCapital;
217    *   propertyMap["BUTTON_ACTION"] = buttonAction;
218    *   propertyMap["VARIATION"] = inputVariation;
219    *
220    *   editor.SetProperty(DevelTextEditor::Property::INPUT_METHOD_SETTINGS, propertyMap);
221    * @endcode
222    */
223   INPUT_METHOD_SETTINGS,
224
225   /**
226    * @brief The input filter
227    * @details Name "inputFilter", type Property::MAP.
228    *
229    * The inputFilter map contains the following keys:
230    *
231    * | %Property Name       | Type     | Required | Description                                                                                                         |
232    * |----------------------|----------|----------|---------------------------------------------------------------------------------------------------------------------|
233    * | accepted             | STRING   | No       | A regular expression in the set of characters to be accepted by the inputFilter (the default value is empty string) |
234    * | rejected             | STRING   | No       | A regular expression in the set of characters to be rejected by the inputFilter (the default value is empty string) |
235    *
236    * @note Optional.
237    * The character set must follow the regular expression rules.
238    * Behaviour can not be guaranteed for incorrect grammars.
239    * Refer the link below for detailed rules.
240    * The functions in std::regex library use the ECMAScript grammar:
241    * http://cplusplus.com/reference/regex/ECMAScript/
242    *
243    * You can use enums instead of "accepted" and "rejected" strings.
244    * @see Dali::Toolkit::InputFilter::Property::Type
245    *
246    * Example Usage:
247    * @code
248    *   Property::Map filter;
249    *   filter[InputFilter::Property::ACCEPTED] = "[\\d]"; // accept whole digits
250    *   filter[InputFilter::Property::REJECTED] = "[0-5]"; // reject 0, 1, 2, 3, 4, 5
251    *
252    *   editor.SetProperty(DevelTextEditor::Property::INPUT_FILTER, filter); // acceptable inputs are 6, 7, 8, 9
253    * @endcode
254    */
255   INPUT_FILTER,
256
257   /**
258   * @brief Whether we should show the ellipsis if required.
259   * @details Name "ellipsis", type Property::BOOLEAN.
260   */
261   ELLIPSIS,
262
263   /**
264   * @brief The enumerations used to specify whether to position the ellipsis at the END, START or MIDDLE of the text.
265   * @details Name "EllipsisPosition", type [Type](@ref Dali::Toolkit::DevelText::EllipsisPosition::Type) (Property::INTEGER), or Property::STRING. Read/Write
266   * @note Default is EllipsisPosition::END.
267   * @see DevelText::EllipsisPosition
268   */
269   ELLIPSIS_POSITION,
270 };
271
272 } // namespace Property
273
274 /**
275  * @brief Return the input method context of TextEditor.
276  *
277  * @param[in] textEditor The instance of TextEditor.
278  * @return InputMethodContext instance.
279  */
280 DALI_TOOLKIT_API InputMethodContext GetInputMethodContext(TextEditor textEditor);
281
282 /**
283  * @brief Max Characters Exceed signal type.
284   */
285 using MaxLengthReachedSignalType = Signal<void(TextEditor)>;
286
287 /**
288  * @brief This signal is emitted when inserted text exceeds the maximum character limit.
289  *
290  * A callback of the following type may be connected:
291  * @code
292  *   void YourCallbackName( TextEditor textEditor );
293  * @endcode
294  * @param[in] textEditor The instance of TextEditor.
295  * @return The signal to connect to
296  */
297 DALI_TOOLKIT_API MaxLengthReachedSignalType& MaxLengthReachedSignal(TextEditor textEditor);
298
299 /**
300  * @brief Anchor clicked signal type.
301  *
302  * @note Signal
303  *  - const char* : href of clicked anchor.
304  *  - uint32_t    : length of href.
305  */
306 using AnchorClickedSignalType = Signal<void(TextEditor, const char*, uint32_t)>;
307
308 /**
309  * @brief This signal is emitted when the anchor is clicked.
310  *
311  * A callback of the following type may be connected:
312  * @code
313  *   void YourCallbackName(TextEditor textEditor, const char* href, uint32_t hrefLength);
314  * @endcode
315  * @param[in] textEditor The instance of TextEditor.
316  * @return The signal to connect to.
317  */
318 DALI_TOOLKIT_API AnchorClickedSignalType& AnchorClickedSignal(TextEditor textEditor);
319
320 /**
321  * @brief Input filtered signal type.
322  */
323 using InputFilteredSignalType = Signal<void(TextEditor, Toolkit::InputFilter::Property::Type)>;
324
325 /**
326  * @brief This signal is emitted when the character to be inserted is filtered by the input filter.
327  *
328  * A callback of the following type may be connected:
329  * @code
330  *   void YourCallbackName(TextEditor textEditor, Toolkit::InputFilter::Property::Type type);
331  *
332  *   DevelTextEditor::InputFilteredSignal(textEditor).Connect(this, &OnInputFiltered);
333  *
334  *   void OnInputFiltered(TextEditor textEditor, InputFilter::Property::Type type)
335  *   {
336  *     if (type == InputFilter::Property::ACCEPTED)
337  *     {
338  *       // If the input has been filtered with an accepted filter, the type is ACCEPTED.
339  *     }
340  *     else if (type == InputFilter::Property::REJECTED)
341  *     {
342  *       // If the input has been filtered with an rejected filter, the type is REJECTED.
343  *     }
344  *   }
345  * @endcode
346  * @param[in] textEditor The instance of TextEditor.
347  * @return The signal to connect to.
348  */
349 DALI_TOOLKIT_API InputFilteredSignalType& InputFilteredSignal(TextEditor textEditor);
350
351 /**
352  * @brief Select the whole text of TextEditor.
353  *
354  * @param[in] textEditor The instance of TextEditor.
355  */
356 DALI_TOOLKIT_API void SelectWholeText(TextEditor textEditor);
357
358 /**
359  * @brief Unselect the whole text of TextEditor.
360  *
361  * @param[in] textEditor The instance of TextEditor.
362  */
363 DALI_TOOLKIT_API void SelectNone(TextEditor textEditor);
364
365 /**
366  * @brief Select the text from start index to end index of TextEditor.
367  * @note
368  * The selection index is based on the cursor index.
369  *
370  * text   H e l l o
371  * index 0 1 2 3 4 5
372  * if textEditor.SelectText(1, 4); is executed, "ell" is selected.
373  *
374  * @param[in] textEditor The instance of TextEditor.
375  * @param[in] start The start index of the text to select. (The starting point of start index is 0.)
376  * @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.)
377  */
378 DALI_TOOLKIT_API void SelectText(TextEditor textEditor, const uint32_t start, const uint32_t end);
379
380 /**
381  * @brief Scroll the TextEditor by specific amount.
382  *
383  * @param[in] textEditor The instance of TextEditor.
384  * @param[in] scroll amount (in pixels) of scrolling in horizontal & vectical directions.
385  */
386 DALI_TOOLKIT_API void ScrollBy(TextEditor textEditor, Vector2 scroll);
387
388 } // namespace DevelTextEditor
389
390 } // namespace Toolkit
391
392 } // namespace Dali
393
394 #endif // DALI_TOOLKIT_TEXT_EDITOR_DEVEL_H