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