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