Merge "Fix the text artifact (i.e. vertical lines below the text) while scrolling...
[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) 2017 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_IMPORT_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        * @DEPRECATED_1_1.37 Use SHADOW instead.
173        * @brief The drop shadow offset 0 indicates no shadow.
174        * @details Name "shadowOffset", type Property::VECTOR2.
175        * @SINCE_1_0.0
176        */
177       SHADOW_OFFSET,
178
179       /**
180        * @DEPRECATED_1_1.37 Use SHADOW instead.
181        * @brief The color of a drop shadow.
182        * @details Name "shadowColor", type Property::VECTOR4.
183        * @SINCE_1_0.0
184        */
185       SHADOW_COLOR,
186
187       /**
188        * @brief The color to apply to the primary cursor.
189        * @details Name "primaryCursorColor", type Property::VECTOR4.
190        * @SINCE_1_0.0
191        */
192       PRIMARY_CURSOR_COLOR,
193
194       /**
195        * @brief The color to apply to the secondary cursor.
196        * @details Name "secondaryCursorColor", type Property::VECTOR4.
197        * @SINCE_1_0.0
198        */
199       SECONDARY_CURSOR_COLOR,
200
201       /**
202        * @brief Whether the cursor should blink or not.
203        * @details Name "enableCursorBlink", type Property::BOOLEAN.
204        * @SINCE_1_0.0
205        */
206       ENABLE_CURSOR_BLINK,
207
208       /**
209        * @brief The time interval in seconds between cursor on/off states.
210        * @details Name "cursorBlinkInterval", type Property::FLOAT.
211        * @SINCE_1_0.0
212        */
213       CURSOR_BLINK_INTERVAL,
214
215       /**
216        * @brief The cursor will stop blinking after this number of seconds (if non-zero)
217        * @details Name "cursorBlinkDuration", type Property::FLOAT.
218        * @SINCE_1_0.0
219        */
220       CURSOR_BLINK_DURATION,
221
222       /**
223        * @brief The cursor width.
224        * @details Name "cursorWidth", type Property::INTEGER.
225        * @SINCE_1_0.0
226        */
227       CURSOR_WIDTH,
228
229       /**
230        * @brief The image to display for the grab handle.
231        * @details Name "grabHandleImage", type Property::STRING.
232        * @SINCE_1_0.0
233        */
234       GRAB_HANDLE_IMAGE,
235
236       /**
237        * @brief The image to display when the grab handle is pressed
238        * @details Name "grabHandlePressedImage", type Property::STRING.
239        * @SINCE_1_0.0
240        */
241       GRAB_HANDLE_PRESSED_IMAGE,
242
243       /**
244        * @brief Horizontal scrolling will occur if the cursor is this close to the control border.
245        * @details Name "scrollThreshold", type Property::FLOAT.
246        * @SINCE_1_0.0
247        */
248       SCROLL_THRESHOLD,
249
250       /**
251        * @brief The scroll speed in pixels per second.
252        * @details Name "scrollSpeed", type Property::FLOAT.
253        * @SINCE_1_0.0
254        */
255       SCROLL_SPEED,
256
257       /**
258        * @brief The image to display for the left selection handle.
259        * @details Name "selectionHandleImageLeft", type Property::MAP.
260        * @SINCE_1_0.0
261        */
262       SELECTION_HANDLE_IMAGE_LEFT,
263
264       /**
265        * @brief The image to display for the right selection handle.
266        * @details Name "selectionHandleImageRight", type Property::MAP.
267        * @SINCE_1_0.0
268        */
269       SELECTION_HANDLE_IMAGE_RIGHT,
270
271       /**
272        * @brief The image to display when the left selection handle is pressed.
273        * @details Name "selectionHandlePressedImageLeft", type Property::MAP.
274        * @SINCE_1_0.0
275        */
276       SELECTION_HANDLE_PRESSED_IMAGE_LEFT,
277
278       /**
279        * @brief The image to display when the right selection handle is pressed.
280        * @details Name "selectionHandlePressedImageRight", type Property::MAP.
281        * @SINCE_1_0.0
282        */
283       SELECTION_HANDLE_PRESSED_IMAGE_RIGHT,
284
285       /**
286        * @brief The image to display for the left selection handle marker.
287        * @details Name "selectionHandleMarkerImageLeft", type Property::MAP.
288        * @SINCE_1_0.0
289        */
290       SELECTION_HANDLE_MARKER_IMAGE_LEFT,
291
292       /**
293        * @brief The image to display for the right selection handle marker.
294        * @details Name "selectionHandleMarkerImageRight", type Property::MAP.
295        * @SINCE_1_0.0
296        */
297       SELECTION_HANDLE_MARKER_IMAGE_RIGHT,
298
299       /**
300        * @brief The color of the selection highlight.
301        * @details Name "selectionHighlightColor", type Property::VECTOR4.
302        * @SINCE_1_0.0
303        */
304       SELECTION_HIGHLIGHT_COLOR,
305
306       /**
307        * @brief The decorations (handles etc) will positioned within this area on-screen.
308        * @details Name "decorationBoundingBox", type Property::RECTANGLE.
309        * @SINCE_1_0.0
310        */
311       DECORATION_BOUNDING_BOX,
312
313       /**
314        * @brief The settings to relating to the System's Input Method, Key and Value.
315        * @details Name "inputMethodSettings", type Property::MAP.
316        * @SINCE_1_0.0
317        */
318       INPUT_METHOD_SETTINGS,
319
320       /**
321        * @brief The color of the new input text.
322        * @details Name "inputColor", type Property::VECTOR4.
323        * @SINCE_1_0.0
324        */
325       INPUT_COLOR,
326
327       /**
328        * @brief Whether the mark-up processing is enabled.
329        * @details Name "enableMarkup", type Property::BOOLEAN.
330        * @SINCE_1_0.0
331        */
332       ENABLE_MARKUP,
333
334       /**
335        * @brief The font's family of the new input text.
336        * @details Name "inputFontFamily", type Property::STRING.
337        * @SINCE_1_0.0
338        */
339       INPUT_FONT_FAMILY,
340
341       /**
342        * @brief The font's style of the new input text.
343        * @details Name "inputFontStyle", type Property::MAP.
344        * @SINCE_1_2.13
345        */
346       INPUT_FONT_STYLE,
347
348       /**
349        * @brief The font's size of the new input text in points.
350        * @details Name "inputPointSize", type Property::FLOAT.
351        * @SINCE_1_0.0
352        */
353       INPUT_POINT_SIZE,
354
355       /**
356        * @brief The default underline parameters.
357        * @details Name "underline", type Property::MAP.
358        * @SINCE_1_2.13
359        */
360       UNDERLINE,
361
362       /**
363        * @brief The underline parameters of the new input text.
364        * @details Name "inputUnderline", type Property::MAP.
365        * @SINCE_1_2.13
366        */
367       INPUT_UNDERLINE,
368
369       /**
370        * @brief The default shadow parameters.
371        * @details Name "shadow", type Property::MAP.
372        * @SINCE_1_2.13
373        */
374       SHADOW,
375
376       /**
377        * @brief The shadow parameters of the new input text.
378        * @details Name "inputShadow", type Property::MAP.
379        * @SINCE_1_2.13
380        */
381       INPUT_SHADOW,
382
383       /**
384        * @brief The default emboss parameters.
385        * @details Name "emboss", type Property::MAP.
386        * @SINCE_1_2.13
387        */
388       EMBOSS,
389
390       /**
391        * @brief The emboss parameters of the new input text.
392        * @details Name "inputEmboss", type Property::MAP.
393        * @SINCE_1_2.13
394        */
395       INPUT_EMBOSS,
396
397       /**
398        * @brief The default outline parameters.
399        * @details Name "outline", type Property::MAP.
400        * @SINCE_1_2.13
401        */
402       OUTLINE,
403
404       /**
405        * @brief The outline parameters of the new input text.
406        * @details Name "inputOutline", type Property::MAP.
407        * @SINCE_1_2.13
408        */
409       INPUT_OUTLINE,
410
411       /**
412        * @brief Hides the input characters and instead shows a default character for password or pin entry.
413        * @details Name "hiddenInputSettings", type Property::MAP.
414        * @SINCE_1_2.60
415        * @note Optional.
416        * @see HiddenInput::Property
417        */
418       HIDDEN_INPUT_SETTINGS,
419
420       /**
421        * @brief The size of font in pixels.
422        * @details Name "pixelSize", type Property::FLOAT.
423        *          Conversion from Point size to Pixel size:
424        *           Pixel size = Point size * DPI / 72
425        * @SINCE_1_2.60
426        */
427       PIXEL_SIZE,
428
429       /**
430        * @brief Enables Text selection, such as the cursor, handle, clipboard, and highlight color.
431        * @details Name "enableSelection", type Property::BOOLEAN.
432        * @SINCE_1_2.60
433        */
434       ENABLE_SELECTION,
435
436       /**
437        * @brief Sets the placeholder : text, color, font family, font style, point size, and pixel size.
438        * @details Name "placeholder", type Property::MAP.
439        * Example Usage:
440        * @code
441        *   Property::Map propertyMap;
442        *   propertyMap[ Text::PlaceHolder::Property::TEXT ] = "Setting Placeholder Text";
443        *   propertyMap[ Text::PlaceHolder::Property::TEXT_FOCUSED] = "Setting Placeholder Text Focused";
444        *   propertyMap[ Text::PlaceHolder::Property::COLOR] = Color::RED;
445        *   propertyMap[ Text::PlaceHolder::Property::FONT_FAMILY ] = "Arial";
446        *   propertyMap[ Text::PlaceHolder::Property::POINT_SIZE ] = 12.0f;
447        *   propertyMap[ Text::PlaceHolder::Property::ELLIPSIS ] = true;
448        *
449        *   Property::Map fontStyleMap;
450        *   fontStyleMap.Insert( "weight", "bold" );
451        *   fontStyleMap.Insert( "width", "condensed" );
452        *   fontStyleMap.Insert( "slant", "italic" );
453        *   propertyMap[ Text::PlaceHolder::Property::FONT_STYLE] = fontStyleMap;
454        *
455        *   field.SetProperty( TextField::Property::PLACEHOLDER, propertyMap );
456        * @endcode
457        * @SINCE_1_2.60
458        */
459       PLACEHOLDER,
460
461       /**
462        * @brief Whether we should show the ellipsis if it is required.
463        * @details Name "ellipsis", type Property::BOOLEAN.
464        * @SINCE_1_2.60
465        * @note PLACEHOLDER map is used to add ellipsis to placeholder text.
466        */
467       ELLIPSIS,
468     };
469   };
470
471   /**
472    * @brief Enumeration for specifying how the text is truncated when it does not fit.
473    *
474    * The default value is \e EXCEED_POLICY_CLIP.
475    * @SINCE_1_0.0
476    */
477   enum ExceedPolicy
478   {
479     EXCEED_POLICY_ORIGINAL,        ///< The text will be display at original size, and may exceed the TextField boundary. @SINCE_1_0.0
480     EXCEED_POLICY_CLIP             ///< The end of text will be clipped to fit within the TextField. @SINCE_1_0.0
481   };
482
483   /**
484    * @brief Mask used by the signal InputStyleChangedSignal(). Notifies which parameters of the input style have changed.
485    *
486    * @SINCE_1_2_2
487    */
488   struct InputStyle
489   {
490   /**
491    * @brief Mask used by the signal InputStyleChangedSignal().
492    *
493    * @SINCE_1_2_2
494    */
495     enum Mask
496     {
497       NONE         = 0x0000, ///< @SINCE_1_2_2
498       COLOR        = 0x0001, ///< @SINCE_1_2_2
499       FONT_FAMILY  = 0x0002, ///< @SINCE_1_2_2
500       POINT_SIZE   = 0x0004, ///< @SINCE_1_2_2
501       FONT_STYLE   = 0x0008, ///< @SINCE_1_2_2
502       UNDERLINE    = 0x0010, ///< @SINCE_1_2_2
503       SHADOW       = 0x0020, ///< @SINCE_1_2_2
504       EMBOSS       = 0x0040, ///< @SINCE_1_2_2
505       OUTLINE      = 0x0080  ///< @SINCE_1_2_2
506     };
507   };
508
509   // Type Defs
510
511   /**
512    * @brief Text changed signal type.
513    * @SINCE_1_0.0
514    */
515   typedef Signal<void ( TextField ) > TextChangedSignalType;
516
517   /**
518    * @brief Max Characters Exceed signal type.
519    * @SINCE_1_0.0
520    */
521   typedef Signal<void ( TextField ) > MaxLengthReachedSignalType;
522
523   /**
524    * @brief Input Style changed signal type.
525    * @SINCE_1_2_2
526    */
527   typedef Signal<void ( TextField, InputStyle::Mask ) > InputStyleChangedSignalType;
528
529   /**
530    * @brief Creates the TextField control.
531    * @SINCE_1_0.0
532    * @return A handle to the TextField control
533    */
534   static TextField New();
535
536   /**
537    * @brief Creates an empty handle.
538    * @SINCE_1_0.0
539    */
540   TextField();
541
542   /**
543    * @brief Copy constructor.
544    *
545    * @SINCE_1_0.0
546    * @param[in] handle The handle to copy from
547    */
548   TextField( const TextField& handle );
549
550   /**
551    * @brief Assignment operator.
552    *
553    * @SINCE_1_0.0
554    * @param[in] handle The handle to copy from
555    * @return A reference to this
556    */
557   TextField& operator=( const TextField& handle );
558
559   /**
560    * @brief Destructor.
561    *
562    * This is non-virtual since derived Handle types must not contain data or virtual methods.
563    * @SINCE_1_0.0
564    */
565   ~TextField();
566
567   /**
568    * @brief Downcasts a handle to TextField.
569    *
570    * If the BaseHandle points is a TextField, the downcast returns a valid handle.
571    * If not, the returned handle is left empty.
572    *
573    * @SINCE_1_0.0
574    * @param[in] handle Handle to an object
575    * @return Handle to a TextField or an empty handle
576    */
577   static TextField DownCast( BaseHandle handle );
578
579   // Signals
580
581   /**
582    * @brief This signal is emitted when the text changes.
583    *
584    * A callback of the following type may be connected:
585    * @code
586    *   void YourCallbackName( TextField textField );
587    * @endcode
588    * @SINCE_1_0.0
589    * @return The signal to connect to.
590    */
591   TextChangedSignalType& TextChangedSignal();
592
593   /**
594    * @brief This signal is emitted when inserted text exceeds the maximum character limit.
595    *
596    * A callback of the following type may be connected:
597    * @code
598    *   void YourCallbackName( TextField textField );
599    * @endcode
600    * @SINCE_1_0.0
601    * @return The signal to connect to
602    */
603   MaxLengthReachedSignalType& MaxLengthReachedSignal();
604
605   /**
606    * @brief This signal is emitted when the input style is updated as a consequence of a change in the cursor position.
607    * i.e. The signal is not emitted when the input style is updated through the property system.
608    *
609    * A callback of the following type may be connected. The @p mask parameter notifies which parts of the style have changed.
610    * @code
611    *   void YourCallbackName( TextField textField, TextField::InputStyle::Mask mask );
612    * @endcode
613    *
614    * @SINCE_1_2_2
615    * @return The signal to connect to
616    */
617   InputStyleChangedSignalType& InputStyleChangedSignal();
618
619 public: // Not intended for application developers
620
621   /**
622    * @brief Creates a handle using the Toolkit::Internal implementation.
623    *
624    * @SINCE_1_0.0
625    * @param[in] implementation The Control implementation
626    */
627   DALI_INTERNAL TextField( Internal::TextField& implementation );
628
629   /**
630    * @brief Allows the creation of this Control from an Internal::CustomActor pointer.
631    *
632    * @SINCE_1_0.0
633    * @param[in] internal A pointer to the internal CustomActor
634    */
635   explicit DALI_INTERNAL TextField( Dali::Internal::CustomActor* internal );
636 };
637
638 /**
639  * @}
640  */
641 } // namespace Toolkit
642
643 } // namespace Dali
644
645 #endif // __DALI_TOOLKIT_TEXT_FIELD_H__