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