Add a TextEditor property to limit input to maximum characters
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / public-api / controls / text-controls / text-editor.h
1 #ifndef DALI_TOOLKIT_TEXT_EDITOR_H
2 #define DALI_TOOLKIT_TEXT_EDITOR_H
3
4 /*
5  * Copyright (c) 2020 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
21 // INTERNAL INCLUDES
22 #include <dali-toolkit/public-api/controls/control.h>
23
24 namespace Dali
25 {
26
27 namespace Toolkit
28 {
29
30 namespace Internal DALI_INTERNAL
31 {
32   class TextEditor;
33 }
34 /**
35  * @addtogroup dali_toolkit_controls_text_controls
36  * @{
37  */
38
39 /**
40  * @brief A control which provides a multi-line editable text editor.
41  *
42  * Signals
43  * | %Signal Name         | Method                         |                    |
44  * |----------------------|--------------------------------|--------------------|
45  * | textChanged          | @ref TextChangedSignal()       | @SINCE_1_1.37      |
46  * | inputStyleChanged    | @ref InputStyleChangedSignal() | @SINCE_1_2_2       |
47  *
48  */
49 class DALI_TOOLKIT_API TextEditor : public Control
50 {
51 public:
52
53   /**
54    * @brief Enumeration for the start and end property ranges for this control.
55    * @SINCE_1_1.37
56    */
57   enum PropertyRange
58   {
59     PROPERTY_START_INDEX = Control::CONTROL_PROPERTY_END_INDEX + 1,
60     PROPERTY_END_INDEX = PROPERTY_START_INDEX + 1000              ///< Reserve property indices
61   };
62
63   /**
64    * @brief Enumeration for the instance of properties belonging to the TextEditor class.
65    * @SINCE_1_1.37
66    */
67   struct Property
68   {
69     /**
70      * @brief Enumeration for the instance of properties belonging to the TextEditor class.
71      * @SINCE_1_1.37
72      */
73     enum
74     {
75       /**
76        * @brief The text to display in UTF-8 format.
77        * @details Name "text", type Property::STRING.
78        * @SINCE_1_1.37
79        */
80       TEXT = PROPERTY_START_INDEX,
81
82       /**
83        * @brief The text color.
84        * @details Name "textColor", type Property::VECTOR4.
85        * @SINCE_1_1.37
86        */
87       TEXT_COLOR,
88
89       /**
90        * @brief The requested font family.
91        * @details Name "fontFamily", type Property::STRING.
92        * @SINCE_1_1.37
93        */
94       FONT_FAMILY,
95
96       /**
97        * @brief The requested font style.
98        * @details Name "fontStyle", type Property::STRING or Property::MAP.
99        * @SINCE_1_2.13
100        */
101       FONT_STYLE,
102
103       /**
104        * @brief The size of font in points.
105        * @details Name "pointSize", type Property::FLOAT.
106        *          Conversion from Pixel size to Point size : Point size = Pixel size * 72 / DPI.
107        * @SINCE_1_1.37
108        */
109       POINT_SIZE,
110
111       /**
112        * @brief The text horizontal alignment.
113        * @details Name "horizontalAlignment", type Property::STRING or type HorizontalAlignment::Type (Property::INTEGER)
114        *          Values "BEGIN" "CENTER" "END".
115        * @note Return type is Property::STRING
116        * @SINCE_1_1.37
117        */
118       HORIZONTAL_ALIGNMENT,
119
120       /**
121        * @brief Vertical scrolling will occur if the cursor is this close to the control border.
122        * @details Name "scrollThreshold", type Property::FLOAT.
123        * @SINCE_1_1.37
124        */
125       SCROLL_THRESHOLD,
126
127       /**
128        * @brief The scroll speed in pixels per second.
129        * @details Name "scrollSpeed", type Property::FLOAT.
130        * @SINCE_1_1.37
131        */
132       SCROLL_SPEED,
133
134       /**
135        * @brief The color to apply to the primary cursor.
136        * @details Name "primaryCursorColor", type Property::VECTOR4.
137        * @SINCE_1_1.37
138        */
139       PRIMARY_CURSOR_COLOR,
140
141       /**
142        * @brief The color to apply to the secondary cursor.
143        * @details Name "secondaryCursorColor", type Property::VECTOR4.
144        * @SINCE_1_1.37
145        */
146       SECONDARY_CURSOR_COLOR,
147
148       /**
149        * @brief Whether the cursor should blink or not.
150        * @details Name "enableCursorBlink", type Property::BOOLEAN.
151        * @SINCE_1_1.37
152        */
153       ENABLE_CURSOR_BLINK,
154
155       /**
156        * @brief The time interval in seconds between cursor on/off states.
157        * @details Name "cursorBlinkInterval", type Property::FLOAT.
158        * @SINCE_1_1.37
159        */
160       CURSOR_BLINK_INTERVAL,
161
162       /**
163        * @brief The cursor will stop blinking after this number of seconds (if non-zero).
164        * @details Name "cursorBlinkDuration", type Property::FLOAT.
165        * @SINCE_1_1.37
166        */
167       CURSOR_BLINK_DURATION,
168
169       /**
170        * @brief The cursor width.
171        * @details Name "cursorWidth", type Property::INTEGER.
172        * @SINCE_1_1.37
173        */
174       CURSOR_WIDTH,
175
176       /**
177        * @brief The image to display for the grab handle.
178        * @details Name "grabHandleImage", type Property::STRING.
179        * @SINCE_1_1.37
180        */
181       GRAB_HANDLE_IMAGE,
182
183       /**
184        * @brief The image to display when the grab handle is pressed.
185        * @details Name "grabHandlePressedImage", type Property::STRING.
186        * @SINCE_1_1.37
187        */
188       GRAB_HANDLE_PRESSED_IMAGE,
189
190       /**
191        * @brief The image to display for the left selection handle.
192        * @details Name "selectionHandleImageLeft", type Property::MAP.
193        * @SINCE_1_1.37
194        */
195       SELECTION_HANDLE_IMAGE_LEFT,
196
197       /**
198        * @brief The image to display for the right selection handle.
199        * @details Name "selectionHandleImageRight", type Property::MAP.
200        * @SINCE_1_1.37
201        */
202       SELECTION_HANDLE_IMAGE_RIGHT,
203
204       /**
205        * @brief The image to display when the left selection handle is pressed.
206        * @details Name "selectionHandlePressedImageLeft", type Property::MAP.
207        * @SINCE_1_1.37
208        */
209       SELECTION_HANDLE_PRESSED_IMAGE_LEFT,
210
211       /**
212        * @brief The image to display when the right selection handle is pressed.
213        * @details Name "selectionHandlePressedImageRight", type Property::MAP.
214        * @SINCE_1_1.37
215        */
216       SELECTION_HANDLE_PRESSED_IMAGE_RIGHT,
217
218       /**
219        * @brief The image to display for the left selection handle marker.
220        * @details Name "selectionHandleMarkerImageLeft", type Property::MAP.
221        * @SINCE_1_1.37
222        */
223       SELECTION_HANDLE_MARKER_IMAGE_LEFT,
224
225       /**
226        * @brief The image to display for the right selection handle marker.
227        * @details Name "selectionHandleMarkerImageRight", type Property::MAP.
228        * @SINCE_1_1.37
229        */
230       SELECTION_HANDLE_MARKER_IMAGE_RIGHT,
231
232       /**
233        * @brief The color of the selection highlight.
234        * @details Name "selectionHighlightColor", type Property::VECTOR4.
235        * @SINCE_1_1.37
236        */
237       SELECTION_HIGHLIGHT_COLOR,
238
239       /**
240        * @brief The decorations (handles etc) will positioned within this area on-screen.
241        * @details Name "decorationBoundingBox", type Property::RECTANGLE.
242        * @SINCE_1_1.37
243        */
244       DECORATION_BOUNDING_BOX,
245
246       /**
247        * @brief Whether the mark-up processing is enabled.
248        * @details Name "enableMarkup", type Property::BOOLEAN.
249        * @SINCE_1_1.37
250        */
251       ENABLE_MARKUP,
252
253       /**
254        * @brief The color of the new input text.
255        * @details Name "inputColor", type Property::VECTOR4.
256        * @SINCE_1_1.37
257        */
258       INPUT_COLOR,
259
260       /**
261        * @brief The font's family of the new input text.
262        * @details Name "inputFontFamily", type Property::STRING.
263        * @SINCE_1_1.37
264        */
265       INPUT_FONT_FAMILY,
266
267       /**
268        * @brief The font's style of the new input text.
269        * @details Name "inputFontStyle", type Property::MAP.
270        * @SINCE_1_2.13
271        */
272       INPUT_FONT_STYLE,
273
274       /**
275        * @brief The font's size of the new input text in points.
276        * @details Name "inputPointSize", type Property::FLOAT.
277        * @SINCE_1_1.37
278        */
279       INPUT_POINT_SIZE,
280
281       /**
282        * @brief The default extra space between lines in points.
283        * @details Name "lineSpacing", type Property::FLOAT.
284        * @SINCE_1_1.37
285        */
286       LINE_SPACING,
287
288       /**
289        * @brief The extra space between lines in points.
290        * @details Name "inputLineSpacing",  type Property::FLOAT.
291        * @SINCE_1_1.37
292        * @note This affects the whole paragraph where the new input text is inserted.
293        */
294       INPUT_LINE_SPACING,
295
296       /**
297        * @copydoc Dali::Toolkit::TextLabel::Property::UNDERLINE
298        */
299       UNDERLINE,
300
301       /**
302        * @brief The underline parameters of the new input text.
303        * @details Name "inputUnderline", type Property::MAP.
304        * @SINCE_1_2.13
305        */
306       INPUT_UNDERLINE,
307
308       /**
309        * @copydoc Dali::Toolkit::TextLabel::Property::SHADOW
310        */
311       SHADOW,
312
313       /**
314        * @brief The shadow parameters of the new input text.
315        * @details Name "inputShadow", type Property::MAP.
316        * @SINCE_1_2.13
317        */
318       INPUT_SHADOW,
319
320       /**
321        * @brief The default emboss parameters.
322        * @details Name "emboss", type Property::MAP.
323        * @SINCE_1_2.13
324        */
325       EMBOSS,
326
327       /**
328        * @brief The emboss parameters of the new input text.
329        * @details Name "inputEmboss", type Property::MAP.
330        * @SINCE_1_2.13
331        */
332       INPUT_EMBOSS,
333
334       /**
335        * @copydoc Dali::Toolkit::TextLabel::Property::OUTLINE
336        */
337       OUTLINE,
338
339       /**
340        * @brief The outline parameters of the new input text.
341        * @details Name "inputOutline", type Property::MAP.
342        * @SINCE_1_2.13
343        */
344       INPUT_OUTLINE,
345
346       /**
347        * @brief Enable or disable the smooth scroll animation.
348        * @details Name "smoothScroll", type Property::BOOLEAN.
349        * @SINCE_1_2.60
350        */
351       SMOOTH_SCROLL,
352
353       /**
354        * @brief Sets the duration of smooth scroll animation.
355        * @details Name "smoothScrollDuration", type Property::FLOAT.
356        * @SINCE_1_2.60
357        */
358       SMOOTH_SCROLL_DURATION,
359
360       /**
361        * @brief Enable or disable the scroll bar.
362        * @details Name "enableScrollBar", type Property::BOOLEAN.
363        * @SINCE_1_2.60
364        */
365       ENABLE_SCROLL_BAR,
366
367       /**
368        * @brief Sets the duration of scroll bar to show.
369        * @details Name "scrollBarShowDuration", type Property::FLOAT.
370        * @SINCE_1_2.60
371        */
372       SCROLL_BAR_SHOW_DURATION,
373
374       /**
375        * @brief Sets the duration of scroll bar to fade out.
376        * @details Name "scrollBarFadeDuration", type Property::FLOAT.
377        * @SINCE_1_2.60
378        */
379       SCROLL_BAR_FADE_DURATION,
380
381       /**
382        * @brief The size of font in pixels.
383        * @details Name "pixelSize", type Property::FLOAT.
384        *          Conversion from Point size to Pixel size:
385        *           Pixel size = Point size * DPI / 72
386        * @SINCE_1_2.60
387        */
388       PIXEL_SIZE,
389
390       /**
391        * @brief The line count of text.
392        * @details Name "lineCount", type Property::INTEGER.
393        * @SINCE_1_2.60
394        * @note This property is read-only.
395        */
396       LINE_COUNT,
397
398       /**
399        * @brief Enables Text selection, such as the cursor, handle, clipboard, and highlight color.
400        * @details Name "enableSelection", type Property::BOOLEAN.
401        * @SINCE_1_2.60
402        */
403       ENABLE_SELECTION,
404
405       /**
406        * @brief Sets the placeholder : text, color, font family, font style, point size, and pixel size.
407        * @details Name "placeholder", type Property::MAP.
408        * Example:
409        * @code
410        *   Property::Map propertyMap;
411        *   propertyMap["placeholderText"] = "Setting Placeholder Text";
412        *   propertyMap["placeholderTextFocused"] = "Setting Placeholder Text Focused";
413        *   propertyMap["placeholderColor"] = Color::RED;
414        *   propertyMap["placeholderFontFamily"] = "Arial";
415        *   propertyMap["placeholderPointSize"] = 12.0f;
416        *
417        *   Property::Map fontStyleMap;
418        *   fontStyleMap.Insert( "weight", "bold" );
419        *   fontStyleMap.Insert( "width", "condensed" );
420        *   fontStyleMap.Insert( "slant", "italic" );
421        *   propertyMap["placeholderFontStyle"] = fontStyleMap;
422        *
423        *   editor.SetProperty( TextEditor::Property::PLACEHOLDER, propertyMap );
424        * @endcode
425        *
426        * @SINCE_1_2.60
427        */
428       PLACEHOLDER,
429
430       /**
431        * @brief Line wrap mode when text lines are greater than the layout width.
432        * @details Name "lineWrapMode", type Text::LineWrap::Mode (Text::Property::INTEGER) or Property::STRING.
433        * @SINCE_1_2.60
434        * @note Default is Text::LineWrap::WORD.
435        * @note Return type is Text::LineWrap::Mode (Text::Property::INTEGER).
436        * @see Text::LineWrap
437        */
438       LINE_WRAP_MODE,
439     };
440   };
441
442   /**
443    * @brief Mask used by the signal InputStyleChangedSignal(). Notifies which parameters of the input style have changed.
444    *
445    * @SINCE_1_2_2
446    */
447   struct InputStyle
448   {
449     /**
450      * @brief Enumeration for mask used by the signal InputStyleChangedSignal().
451      * @SINCE_1_2_2
452      */
453     enum Mask
454     {
455       NONE = 0x0000, ///< @SINCE_1_2_2
456       COLOR = 0x0001, ///< @SINCE_1_2_2
457       FONT_FAMILY = 0x0002, ///< @SINCE_1_2_2
458       POINT_SIZE = 0x0004, ///< @SINCE_1_2_2
459       FONT_STYLE = 0x0008, ///< @SINCE_1_2_2
460       LINE_SPACING = 0x0010, ///< @SINCE_1_2_2
461       UNDERLINE = 0x0020, ///< @SINCE_1_2_2
462       SHADOW = 0x0040, ///< @SINCE_1_2_2
463       EMBOSS = 0x0080, ///< @SINCE_1_2_2
464       OUTLINE = 0x0100  ///< @SINCE_1_2_2
465     };
466   };
467
468   /**
469    * @brief Enumerations for the type of scrolling.
470    * @SINCE_1_2.60
471    * @see ScrollStateChangedSignal()
472    */
473   struct Scroll
474   {
475     /**
476      * @brief Enumerations for the type of scrolling.
477      * @SINCE_1_2.60
478      * @see ScrollStateChangedSignal()
479      */
480     enum Type
481     {
482       STARTED,   ///< Scrolling has started. @SINCE_1_2.60
483       FINISHED   ///< Scrolling has finished. @SINCE_1_2.60
484     };
485   };
486
487   // Type Defs
488
489   /**
490    * @brief Text changed signal type.
491    * @SINCE_1_1.37
492    */
493   typedef Signal< void
494   ( TextEditor ) > TextChangedSignalType;
495
496   /**
497    * @brief Input Style changed signal type.
498    * @SINCE_1_2_2
499    */
500   typedef Signal< void
501   ( TextEditor, InputStyle::Mask ) > InputStyleChangedSignalType;
502
503   /**
504    * @brief Scroll state changed signal type.
505    * @SINCE_1_2.60
506    */
507   typedef Signal< void
508   ( TextEditor, Scroll::Type ) > ScrollStateChangedSignalType;
509
510   /**
511    * @brief Creates the TextEditor control.
512    *
513    * @SINCE_1_1.37
514    * @return A handle to the TextEditor control
515    */
516   static TextEditor
517   New();
518
519   /**
520    * @brief Creates an empty handle.
521    *
522    * @SINCE_1_1.37
523    */
524   TextEditor();
525
526   /**
527    * @brief Copy constructor.
528    *
529    * @SINCE_1_1.37
530    * @param[in] handle The handle to copy from
531    */
532   TextEditor( const TextEditor &handle );
533
534   /**
535    * @brief Assignment operator.
536    *
537    * @SINCE_1_1.37
538    * @param[in] handle The handle to copy from
539    * @return A reference to this
540    */
541   TextEditor&
542   operator=( const TextEditor &handle );
543
544   /**
545    * @brief Destructor.
546    *
547    * This is non-virtual since derived Handle types must not contain data or virtual methods.
548    * @SINCE_1_1.37
549    */
550   ~TextEditor();
551
552   /**
553    * @brief Downcasts a handle to TextEditor.
554    *
555    * If the BaseHandle points is a TextEditor, the downcast returns a valid handle.
556    * If not, the returned handle is left empty.
557    *
558    * @SINCE_1_1.37
559    * @param[in] handle Handle to an object
560    * @return Handle to a TextEditor or an empty handle
561    */
562   static TextEditor
563   DownCast( BaseHandle handle );
564
565   // Signals
566
567   /**
568    * @brief This signal is emitted when the text changes.
569    *
570    * A callback of the following type may be connected:
571    * @code
572    *   void YourCallbackName( TextEditor textEditor );
573    * @endcode
574    *
575    * @SINCE_1_1.37
576    * @return The signal to connect to
577    */
578   TextChangedSignalType&
579   TextChangedSignal();
580
581   /**
582    * @brief This signal is emitted when the input style is updated as a consequence of a change in the cursor position.
583    * i.e. The signal is not emitted when the input style is updated through the property system.
584    *
585    * A callback of the following type may be connected. The @p mask parameter notifies which parts of the style have changed.
586    * @code
587    *   void YourCallbackName( TextEditor textEditor, TextEditor::InputStyle::Mask mask );
588    * @endcode
589    *
590    * @SINCE_1_2_2
591    * @return The signal to connect to
592    */
593   InputStyleChangedSignalType&
594   InputStyleChangedSignal();
595
596   /**
597    * @brief This signal is emitted when TextEditor scrolling is started or finished.
598    *
599    * A callback of the following type may be connected:
600    * @code
601    *   void YourCallbackName( Scroll::Type type );
602    * @endcode
603    * type: Whether the scrolling is started or finished.
604    *
605    * @SINCE_1_2.60
606    * @return The signal to connect to
607    */
608   ScrollStateChangedSignalType&
609   ScrollStateChangedSignal();
610
611 public: // Not intended for application developers
612
613   /// @cond internal
614   /**
615    * @brief Creates a handle using the Toolkit::Internal implementation.
616    *
617    * @SINCE_1_1.37
618    * @param[in] implementation The Control implementation
619    */
620   DALI_INTERNAL
621   TextEditor( Internal::TextEditor &implementation );
622
623   /**
624    * @brief Allows the creation of this Control from an Internal::CustomActor pointer.
625    *
626    * @SINCE_1_1.37
627    * @param[in] internal A pointer to the internal CustomActor
628    */
629   explicit DALI_INTERNAL
630   TextEditor( Dali::Internal::CustomActor *internal );
631   /// @endcond
632 };
633
634 /**
635  * @}
636  */
637 } // namespace Toolkit
638
639 } // namespace Dali
640
641 #endif // DALI_TOOLKIT_TEXT_EDITOR_H