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