01b1569cc809555e73e8db533535de58e38092be
[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) 2018 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 type or rendering e.g. bitmap-based.
77        * @details Name "renderingBackend", type Property::INTEGER.
78        * @SINCE_1_0.0
79        */
80       RENDERING_BACKEND = PROPERTY_START_INDEX,
81
82       /**
83        * @brief The text to display in UTF-8 format.
84        * @details Name "text", type Property::STRING.
85        * @SINCE_1_0.0
86        */
87       TEXT,
88
89       /**
90        * @brief The text to display when the TextField is empty and inactive.
91        * @details Name "placeholderText", type Property::STRING.
92        * @SINCE_1_0.0
93        */
94       PLACEHOLDER_TEXT,
95
96       /**
97        * @brief The text to display when the TextField is empty with key-input focus.
98        * @details Name "placeholderTextFocused", type Property::STRING.
99        * @SINCE_1_0.0
100        */
101       PLACEHOLDER_TEXT_FOCUSED,
102
103       /**
104        * @brief The requested font family.
105        * @details Name "fontFamily", type Property::STRING.
106        * @SINCE_1_0.0
107        */
108       FONT_FAMILY,
109
110       /**
111        * @brief The requested font style
112        * @details Name "fontStyle", type Property::STRING or Property::MAP.
113        * @SINCE_1_2.13
114        */
115       FONT_STYLE,
116
117       /**
118        * @brief The size of font in points.
119        * @details Name "pointSize", type Property::FLOAT.
120        *          (Conversion from Pixel size to Point size : Point size = Pixel size * 72 / DPI).
121        * @SINCE_1_0.0
122        */
123       POINT_SIZE,
124
125       /**
126        * @brief The maximum number of characters that can be inserted.
127        * @details Name "maxLength", type Property::INTEGER.
128        * @SINCE_1_0.0
129        */
130       MAX_LENGTH,
131
132       /**
133        * @brief Specifies how the text is truncated when it does not fit.
134        * @details Name "exceedPolicy", type Property::INTEGER.
135        * @SINCE_1_0.0
136        */
137       EXCEED_POLICY,
138
139       /**
140        * @brief The line horizontal alignment.
141        * @details Name "horizontalAlignment", type Property::STRING or type HorizontalAlignment::Type (Property::INTEGER)
142        *          Values "BEGIN", "CENTER", "END".
143        * @note Return type is Property::STRING
144        * @SINCE_1_0.0
145        */
146       HORIZONTAL_ALIGNMENT,
147
148       /**
149        * @brief The line vertical alignment.
150        * @details Name "verticalAlignment", type Property::STRING type VerticalAlignment::Type (Property::INTEGER)
151        *          Values "TOP",   "CENTER", "BOTTOM".
152        * @note Return type is Property::STRING
153        * @SINCE_1_0.0
154        */
155       VERTICAL_ALIGNMENT,
156
157       /**
158        * @brief The text color.
159        * @details Name "textColor", type Property::VECTOR4.
160        * @SINCE_1_0.0
161        */
162       TEXT_COLOR,
163
164       /**
165        * @brief The placeholder-text color.
166        * @details Name "placeholderTextColor", type Property::VECTOR4.
167        * @SINCE_1_0.0
168        */
169       PLACEHOLDER_TEXT_COLOR,
170
171       /**
172        * @brief This property is removed because it's deprecated.
173        */
174       RESERVED_PROPERTY_01,
175
176       /**
177        * @brief This property is removed because it's deprecated.
178        */
179       RESERVED_PROPERTY_02,
180
181       /**
182        * @brief The color to apply to the primary cursor.
183        * @details Name "primaryCursorColor", type Property::VECTOR4.
184        * @SINCE_1_0.0
185        */
186       PRIMARY_CURSOR_COLOR,
187
188       /**
189        * @brief The color to apply to the secondary cursor.
190        * @details Name "secondaryCursorColor", type Property::VECTOR4.
191        * @SINCE_1_0.0
192        */
193       SECONDARY_CURSOR_COLOR,
194
195       /**
196        * @brief Whether the cursor should blink or not.
197        * @details Name "enableCursorBlink", type Property::BOOLEAN.
198        * @SINCE_1_0.0
199        */
200       ENABLE_CURSOR_BLINK,
201
202       /**
203        * @brief The time interval in seconds between cursor on/off states.
204        * @details Name "cursorBlinkInterval", type Property::FLOAT.
205        * @SINCE_1_0.0
206        */
207       CURSOR_BLINK_INTERVAL,
208
209       /**
210        * @brief The cursor will stop blinking after this number of seconds (if non-zero)
211        * @details Name "cursorBlinkDuration", type Property::FLOAT.
212        * @SINCE_1_0.0
213        */
214       CURSOR_BLINK_DURATION,
215
216       /**
217        * @brief The cursor width.
218        * @details Name "cursorWidth", type Property::INTEGER.
219        * @SINCE_1_0.0
220        */
221       CURSOR_WIDTH,
222
223       /**
224        * @brief The image to display for the grab handle.
225        * @details Name "grabHandleImage", type Property::STRING.
226        * @SINCE_1_0.0
227        */
228       GRAB_HANDLE_IMAGE,
229
230       /**
231        * @brief The image to display when the grab handle is pressed
232        * @details Name "grabHandlePressedImage", type Property::STRING.
233        * @SINCE_1_0.0
234        */
235       GRAB_HANDLE_PRESSED_IMAGE,
236
237       /**
238        * @brief Horizontal scrolling will occur if the cursor is this close to the control border.
239        * @details Name "scrollThreshold", type Property::FLOAT.
240        * @SINCE_1_0.0
241        */
242       SCROLL_THRESHOLD,
243
244       /**
245        * @brief The scroll speed in pixels per second.
246        * @details Name "scrollSpeed", type Property::FLOAT.
247        * @SINCE_1_0.0
248        */
249       SCROLL_SPEED,
250
251       /**
252        * @brief The image to display for the left selection handle.
253        * @details Name "selectionHandleImageLeft", type Property::MAP.
254        * @SINCE_1_0.0
255        */
256       SELECTION_HANDLE_IMAGE_LEFT,
257
258       /**
259        * @brief The image to display for the right selection handle.
260        * @details Name "selectionHandleImageRight", type Property::MAP.
261        * @SINCE_1_0.0
262        */
263       SELECTION_HANDLE_IMAGE_RIGHT,
264
265       /**
266        * @brief The image to display when the left selection handle is pressed.
267        * @details Name "selectionHandlePressedImageLeft", type Property::MAP.
268        * @SINCE_1_0.0
269        */
270       SELECTION_HANDLE_PRESSED_IMAGE_LEFT,
271
272       /**
273        * @brief The image to display when the right selection handle is pressed.
274        * @details Name "selectionHandlePressedImageRight", type Property::MAP.
275        * @SINCE_1_0.0
276        */
277       SELECTION_HANDLE_PRESSED_IMAGE_RIGHT,
278
279       /**
280        * @brief The image to display for the left selection handle marker.
281        * @details Name "selectionHandleMarkerImageLeft", type Property::MAP.
282        * @SINCE_1_0.0
283        */
284       SELECTION_HANDLE_MARKER_IMAGE_LEFT,
285
286       /**
287        * @brief The image to display for the right selection handle marker.
288        * @details Name "selectionHandleMarkerImageRight", type Property::MAP.
289        * @SINCE_1_0.0
290        */
291       SELECTION_HANDLE_MARKER_IMAGE_RIGHT,
292
293       /**
294        * @brief The color of the selection highlight.
295        * @details Name "selectionHighlightColor", type Property::VECTOR4.
296        * @SINCE_1_0.0
297        */
298       SELECTION_HIGHLIGHT_COLOR,
299
300       /**
301        * @brief The decorations (handles etc) will positioned within this area on-screen.
302        * @details Name "decorationBoundingBox", type Property::RECTANGLE.
303        * @SINCE_1_0.0
304        */
305       DECORATION_BOUNDING_BOX,
306
307       /**
308        * @brief The settings to relating to the System's Input Method, Key and Value.
309        * @details Name "inputMethodSettings", type Property::MAP.
310        *
311        * @note VARIATION key can be changed depending on PANEL_LAYOUT.
312        * For example, when PANEL_LAYOUT key is InputMethod::PanelLayout::NORMAL,
313        * then VARIATION would be among NORMAL, WITH_FILENAME, and WITH_PERSON_NAME in Dali::InputMethod::NormalLayout.
314        * For more information, see Dali::InputMethod::Category.
315        *
316        * Example Usage:
317        * @code
318        *   Property::Map propertyMap;
319        *   InputMethod::PanelLayout::Type panelLayout = InputMethod::PanelLayout::NUMBER;
320        *   InputMethod::AutoCapital::Type autoCapital = InputMethod::AutoCapital::WORD;
321        *   InputMethod::ButtonAction::Type buttonAction = InputMethod::ButtonAction::GO;
322        *   int inputVariation = 1;
323        *   propertyMap["PANEL_LAYOUT"] = panelLayout;
324        *   propertyMap["AUTO_CAPITALIZE"] = autoCapital;
325        *   propertyMap["BUTTON_ACTION"] = buttonAction;
326        *   propertyMap["VARIATION"] = inputVariation;
327        *
328        *   field.SetProperty( TextField::Property::INPUT_METHOD_SETTINGS, propertyMap );
329        * @endcode
330        * @SINCE_1_0.0
331        */
332       INPUT_METHOD_SETTINGS,
333
334       /**
335        * @brief The color of the new input text.
336        * @details Name "inputColor", type Property::VECTOR4.
337        * @SINCE_1_0.0
338        */
339       INPUT_COLOR,
340
341       /**
342        * @brief Whether the mark-up processing is enabled.
343        * @details Name "enableMarkup", type Property::BOOLEAN.
344        * @SINCE_1_0.0
345        */
346       ENABLE_MARKUP,
347
348       /**
349        * @brief The font's family of the new input text.
350        * @details Name "inputFontFamily", type Property::STRING.
351        * @SINCE_1_0.0
352        */
353       INPUT_FONT_FAMILY,
354
355       /**
356        * @brief The font's style of the new input text.
357        * @details Name "inputFontStyle", type Property::MAP.
358        * @SINCE_1_2.13
359        */
360       INPUT_FONT_STYLE,
361
362       /**
363        * @brief The font's size of the new input text in points.
364        * @details Name "inputPointSize", type Property::FLOAT.
365        * @SINCE_1_0.0
366        */
367       INPUT_POINT_SIZE,
368
369       /**
370        * @copydoc Dali::Toolkit::TextLabel::Property::UNDERLINE
371        */
372       UNDERLINE,
373
374       /**
375        * @brief The underline parameters of the new input text.
376        * @details Name "inputUnderline", type Property::MAP.
377        * @SINCE_1_2.13
378        */
379       INPUT_UNDERLINE,
380
381       /**
382        * @copydoc Dali::Toolkit::TextLabel::Property::SHADOW
383        */
384       SHADOW,
385
386       /**
387        * @brief The shadow parameters of the new input text.
388        * @details Name "inputShadow", type Property::MAP.
389        * @SINCE_1_2.13
390        */
391       INPUT_SHADOW,
392
393       /**
394        * @brief The default emboss parameters.
395        * @details Name "emboss", type Property::MAP.
396        * @SINCE_1_2.13
397        */
398       EMBOSS,
399
400       /**
401        * @brief The emboss parameters of the new input text.
402        * @details Name "inputEmboss", type Property::MAP.
403        * @SINCE_1_2.13
404        */
405       INPUT_EMBOSS,
406
407       /**
408        * @copydoc Dali::Toolkit::TextLabel::Property::OUTLINE
409        */
410       OUTLINE,
411
412       /**
413        * @brief The outline parameters of the new input text.
414        * @details Name "inputOutline", type Property::MAP.
415        * @SINCE_1_2.13
416        */
417       INPUT_OUTLINE,
418
419       /**
420        * @brief Hides the input characters and instead shows a default character for password or pin entry.
421        * @details Name "hiddenInputSettings", type Property::MAP.
422        * @SINCE_1_2.60
423        * @note Optional.
424        * @see HiddenInput::Property
425        */
426       HIDDEN_INPUT_SETTINGS,
427
428       /**
429        * @brief The size of font in pixels.
430        * @details Name "pixelSize", type Property::FLOAT.
431        *          Conversion from Point size to Pixel size:
432        *           Pixel size = Point size * DPI / 72
433        * @SINCE_1_2.60
434        */
435       PIXEL_SIZE,
436
437       /**
438        * @brief Enables Text selection, such as the cursor, handle, clipboard, and highlight color.
439        * @details Name "enableSelection", type Property::BOOLEAN.
440        * @SINCE_1_2.60
441        */
442       ENABLE_SELECTION,
443
444       /**
445        * @brief Sets the placeholder : text, color, font family, font style, point size, and pixel size.
446        * @details Name "placeholder", type Property::MAP.
447        * Example Usage:
448        * @code
449        *   Property::Map propertyMap;
450        *   propertyMap[ Text::PlaceHolder::Property::TEXT ] = "Setting Placeholder Text";
451        *   propertyMap[ Text::PlaceHolder::Property::TEXT_FOCUSED] = "Setting Placeholder Text Focused";
452        *   propertyMap[ Text::PlaceHolder::Property::COLOR] = Color::RED;
453        *   propertyMap[ Text::PlaceHolder::Property::FONT_FAMILY ] = "Arial";
454        *   propertyMap[ Text::PlaceHolder::Property::POINT_SIZE ] = 12.0f;
455        *   propertyMap[ Text::PlaceHolder::Property::ELLIPSIS ] = true;
456        *
457        *   Property::Map fontStyleMap;
458        *   fontStyleMap.Insert( "weight", "bold" );
459        *   fontStyleMap.Insert( "width", "condensed" );
460        *   fontStyleMap.Insert( "slant", "italic" );
461        *   propertyMap[ Text::PlaceHolder::Property::FONT_STYLE] = fontStyleMap;
462        *
463        *   field.SetProperty( TextField::Property::PLACEHOLDER, propertyMap );
464        * @endcode
465        * @SINCE_1_2.60
466        */
467       PLACEHOLDER,
468
469       /**
470        * @brief Whether we should show the ellipsis if it is required.
471        * @details Name "ellipsis", type Property::BOOLEAN.
472        * @SINCE_1_2.60
473        * @note PLACEHOLDER map is used to add ellipsis to placeholder text.
474        */
475       ELLIPSIS,
476     };
477   };
478
479   /**
480    * @brief Enumeration for specifying how the text is truncated when it does not fit.
481    *
482    * The default value is \e EXCEED_POLICY_CLIP.
483    * @SINCE_1_0.0
484    */
485   enum ExceedPolicy
486   {
487     EXCEED_POLICY_ORIGINAL,        ///< The text will be display at original size, and may exceed the TextField boundary. @SINCE_1_0.0
488     EXCEED_POLICY_CLIP             ///< The end of text will be clipped to fit within the TextField. @SINCE_1_0.0
489   };
490
491   /**
492    * @brief Mask used by the signal InputStyleChangedSignal(). Notifies which parameters of the input style have changed.
493    *
494    * @SINCE_1_2_2
495    */
496   struct InputStyle
497   {
498   /**
499    * @brief Mask used by the signal InputStyleChangedSignal().
500    *
501    * @SINCE_1_2_2
502    */
503     enum Mask
504     {
505       NONE         = 0x0000, ///< @SINCE_1_2_2
506       COLOR        = 0x0001, ///< @SINCE_1_2_2
507       FONT_FAMILY  = 0x0002, ///< @SINCE_1_2_2
508       POINT_SIZE   = 0x0004, ///< @SINCE_1_2_2
509       FONT_STYLE   = 0x0008, ///< @SINCE_1_2_2
510       UNDERLINE    = 0x0010, ///< @SINCE_1_2_2
511       SHADOW       = 0x0020, ///< @SINCE_1_2_2
512       EMBOSS       = 0x0040, ///< @SINCE_1_2_2
513       OUTLINE      = 0x0080  ///< @SINCE_1_2_2
514     };
515   };
516
517   // Type Defs
518
519   /**
520    * @brief Text changed signal type.
521    * @SINCE_1_0.0
522    */
523   typedef Signal<void ( TextField ) > TextChangedSignalType;
524
525   /**
526    * @brief Max Characters Exceed signal type.
527    * @SINCE_1_0.0
528    */
529   typedef Signal<void ( TextField ) > MaxLengthReachedSignalType;
530
531   /**
532    * @brief Input Style changed signal type.
533    * @SINCE_1_2_2
534    */
535   typedef Signal<void ( TextField, InputStyle::Mask ) > InputStyleChangedSignalType;
536
537   /**
538    * @brief Creates the TextField control.
539    * @SINCE_1_0.0
540    * @return A handle to the TextField control
541    */
542   static TextField New();
543
544   /**
545    * @brief Creates an empty handle.
546    * @SINCE_1_0.0
547    */
548   TextField();
549
550   /**
551    * @brief Copy constructor.
552    *
553    * @SINCE_1_0.0
554    * @param[in] handle The handle to copy from
555    */
556   TextField( const TextField& handle );
557
558   /**
559    * @brief Assignment operator.
560    *
561    * @SINCE_1_0.0
562    * @param[in] handle The handle to copy from
563    * @return A reference to this
564    */
565   TextField& operator=( const TextField& handle );
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__