Add outline property to text visual
[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        * @copydoc Dali::Toolkit::TextLabel::Property::UNDERLINE
357        */
358       UNDERLINE,
359
360       /**
361        * @brief The underline parameters of the new input text.
362        * @details Name "inputUnderline", type Property::MAP.
363        * @SINCE_1_2.13
364        */
365       INPUT_UNDERLINE,
366
367       /**
368        * @copydoc Dali::Toolkit::TextLabel::Property::SHADOW
369        */
370       SHADOW,
371
372       /**
373        * @brief The shadow parameters of the new input text.
374        * @details Name "inputShadow", type Property::MAP.
375        * @SINCE_1_2.13
376        */
377       INPUT_SHADOW,
378
379       /**
380        * @brief The default emboss parameters.
381        * @details Name "emboss", type Property::MAP.
382        * @SINCE_1_2.13
383        */
384       EMBOSS,
385
386       /**
387        * @brief The emboss parameters of the new input text.
388        * @details Name "inputEmboss", type Property::MAP.
389        * @SINCE_1_2.13
390        */
391       INPUT_EMBOSS,
392
393       /**
394        * @copydoc Dali::Toolkit::TextLabel::Property::OUTLINE
395        */
396       OUTLINE,
397
398       /**
399        * @brief The outline parameters of the new input text.
400        * @details Name "inputOutline", type Property::MAP.
401        * @SINCE_1_2.13
402        */
403       INPUT_OUTLINE,
404
405       /**
406        * @brief Hides the input characters and instead shows a default character for password or pin entry.
407        * @details Name "hiddenInputSettings", type Property::MAP.
408        * @SINCE_1_2.60
409        * @note Optional.
410        * @see HiddenInput::Property
411        */
412       HIDDEN_INPUT_SETTINGS,
413
414       /**
415        * @brief The size of font in pixels.
416        * @details Name "pixelSize", type Property::FLOAT.
417        *          Conversion from Point size to Pixel size:
418        *           Pixel size = Point size * DPI / 72
419        * @SINCE_1_2.60
420        */
421       PIXEL_SIZE,
422
423       /**
424        * @brief Enables Text selection, such as the cursor, handle, clipboard, and highlight color.
425        * @details Name "enableSelection", type Property::BOOLEAN.
426        * @SINCE_1_2.60
427        */
428       ENABLE_SELECTION,
429
430       /**
431        * @brief Sets the placeholder : text, color, font family, font style, point size, and pixel size.
432        * @details Name "placeholder", type Property::MAP.
433        * Example Usage:
434        * @code
435        *   Property::Map propertyMap;
436        *   propertyMap[ Text::PlaceHolder::Property::TEXT ] = "Setting Placeholder Text";
437        *   propertyMap[ Text::PlaceHolder::Property::TEXT_FOCUSED] = "Setting Placeholder Text Focused";
438        *   propertyMap[ Text::PlaceHolder::Property::COLOR] = Color::RED;
439        *   propertyMap[ Text::PlaceHolder::Property::FONT_FAMILY ] = "Arial";
440        *   propertyMap[ Text::PlaceHolder::Property::POINT_SIZE ] = 12.0f;
441        *   propertyMap[ Text::PlaceHolder::Property::ELLIPSIS ] = true;
442        *
443        *   Property::Map fontStyleMap;
444        *   fontStyleMap.Insert( "weight", "bold" );
445        *   fontStyleMap.Insert( "width", "condensed" );
446        *   fontStyleMap.Insert( "slant", "italic" );
447        *   propertyMap[ Text::PlaceHolder::Property::FONT_STYLE] = fontStyleMap;
448        *
449        *   field.SetProperty( TextField::Property::PLACEHOLDER, propertyMap );
450        * @endcode
451        * @SINCE_1_2.60
452        */
453       PLACEHOLDER,
454
455       /**
456        * @brief Whether we should show the ellipsis if it is required.
457        * @details Name "ellipsis", type Property::BOOLEAN.
458        * @SINCE_1_2.60
459        * @note PLACEHOLDER map is used to add ellipsis to placeholder text.
460        */
461       ELLIPSIS,
462     };
463   };
464
465   /**
466    * @brief Enumeration for specifying how the text is truncated when it does not fit.
467    *
468    * The default value is \e EXCEED_POLICY_CLIP.
469    * @SINCE_1_0.0
470    */
471   enum ExceedPolicy
472   {
473     EXCEED_POLICY_ORIGINAL,        ///< The text will be display at original size, and may exceed the TextField boundary. @SINCE_1_0.0
474     EXCEED_POLICY_CLIP             ///< The end of text will be clipped to fit within the TextField. @SINCE_1_0.0
475   };
476
477   /**
478    * @brief Mask used by the signal InputStyleChangedSignal(). Notifies which parameters of the input style have changed.
479    *
480    * @SINCE_1_2_2
481    */
482   struct InputStyle
483   {
484   /**
485    * @brief Mask used by the signal InputStyleChangedSignal().
486    *
487    * @SINCE_1_2_2
488    */
489     enum Mask
490     {
491       NONE         = 0x0000, ///< @SINCE_1_2_2
492       COLOR        = 0x0001, ///< @SINCE_1_2_2
493       FONT_FAMILY  = 0x0002, ///< @SINCE_1_2_2
494       POINT_SIZE   = 0x0004, ///< @SINCE_1_2_2
495       FONT_STYLE   = 0x0008, ///< @SINCE_1_2_2
496       UNDERLINE    = 0x0010, ///< @SINCE_1_2_2
497       SHADOW       = 0x0020, ///< @SINCE_1_2_2
498       EMBOSS       = 0x0040, ///< @SINCE_1_2_2
499       OUTLINE      = 0x0080  ///< @SINCE_1_2_2
500     };
501   };
502
503   // Type Defs
504
505   /**
506    * @brief Text changed signal type.
507    * @SINCE_1_0.0
508    */
509   typedef Signal<void ( TextField ) > TextChangedSignalType;
510
511   /**
512    * @brief Max Characters Exceed signal type.
513    * @SINCE_1_0.0
514    */
515   typedef Signal<void ( TextField ) > MaxLengthReachedSignalType;
516
517   /**
518    * @brief Input Style changed signal type.
519    * @SINCE_1_2_2
520    */
521   typedef Signal<void ( TextField, InputStyle::Mask ) > InputStyleChangedSignalType;
522
523   /**
524    * @brief Creates the TextField control.
525    * @SINCE_1_0.0
526    * @return A handle to the TextField control
527    */
528   static TextField New();
529
530   /**
531    * @brief Creates an empty handle.
532    * @SINCE_1_0.0
533    */
534   TextField();
535
536   /**
537    * @brief Copy constructor.
538    *
539    * @SINCE_1_0.0
540    * @param[in] handle The handle to copy from
541    */
542   TextField( const TextField& handle );
543
544   /**
545    * @brief Assignment operator.
546    *
547    * @SINCE_1_0.0
548    * @param[in] handle The handle to copy from
549    * @return A reference to this
550    */
551   TextField& operator=( const TextField& handle );
552
553   /**
554    * @brief Destructor.
555    *
556    * This is non-virtual since derived Handle types must not contain data or virtual methods.
557    * @SINCE_1_0.0
558    */
559   ~TextField();
560
561   /**
562    * @brief Downcasts a handle to TextField.
563    *
564    * If the BaseHandle points is a TextField, the downcast returns a valid handle.
565    * If not, the returned handle is left empty.
566    *
567    * @SINCE_1_0.0
568    * @param[in] handle Handle to an object
569    * @return Handle to a TextField or an empty handle
570    */
571   static TextField DownCast( BaseHandle handle );
572
573   // Signals
574
575   /**
576    * @brief This signal is emitted when the text changes.
577    *
578    * A callback of the following type may be connected:
579    * @code
580    *   void YourCallbackName( TextField textField );
581    * @endcode
582    * @SINCE_1_0.0
583    * @return The signal to connect to.
584    */
585   TextChangedSignalType& TextChangedSignal();
586
587   /**
588    * @brief This signal is emitted when inserted text exceeds the maximum character limit.
589    *
590    * A callback of the following type may be connected:
591    * @code
592    *   void YourCallbackName( TextField textField );
593    * @endcode
594    * @SINCE_1_0.0
595    * @return The signal to connect to
596    */
597   MaxLengthReachedSignalType& MaxLengthReachedSignal();
598
599   /**
600    * @brief This signal is emitted when the input style is updated as a consequence of a change in the cursor position.
601    * i.e. The signal is not emitted when the input style is updated through the property system.
602    *
603    * A callback of the following type may be connected. The @p mask parameter notifies which parts of the style have changed.
604    * @code
605    *   void YourCallbackName( TextField textField, TextField::InputStyle::Mask mask );
606    * @endcode
607    *
608    * @SINCE_1_2_2
609    * @return The signal to connect to
610    */
611   InputStyleChangedSignalType& InputStyleChangedSignal();
612
613 public: // Not intended for application developers
614
615   /**
616    * @brief Creates a handle using the Toolkit::Internal implementation.
617    *
618    * @SINCE_1_0.0
619    * @param[in] implementation The Control implementation
620    */
621   DALI_INTERNAL TextField( Internal::TextField& implementation );
622
623   /**
624    * @brief Allows the creation of this Control from an Internal::CustomActor pointer.
625    *
626    * @SINCE_1_0.0
627    * @param[in] internal A pointer to the internal CustomActor
628    */
629   explicit DALI_INTERNAL TextField( Dali::Internal::CustomActor* internal );
630 };
631
632 /**
633  * @}
634  */
635 } // namespace Toolkit
636
637 } // namespace Dali
638
639 #endif // __DALI_TOOLKIT_TEXT_FIELD_H__