Extending Style - Adding Strikethrough
[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) 2021 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       STRIKETHROUGH = 0x0200,
463     };
464   };
465
466   /**
467    * @brief Enumerations for the type of scrolling.
468    * @SINCE_1_2.60
469    * @see ScrollStateChangedSignal()
470    */
471   struct Scroll
472   {
473     /**
474      * @brief Enumerations for the type of scrolling.
475      * @SINCE_1_2.60
476      * @see ScrollStateChangedSignal()
477      */
478     enum Type
479     {
480       STARTED, ///< Scrolling has started. @SINCE_1_2.60
481       FINISHED ///< Scrolling has finished. @SINCE_1_2.60
482     };
483   };
484
485   // Type Defs
486
487   /**
488    * @brief Text changed signal type.
489    * @SINCE_1_1.37
490    */
491   typedef Signal<void(TextEditor)> TextChangedSignalType;
492
493   /**
494    * @brief Input Style changed signal type.
495    * @SINCE_1_2_2
496    */
497   typedef Signal<void(TextEditor, InputStyle::Mask)> InputStyleChangedSignalType;
498
499   /**
500    * @brief Scroll state changed signal type.
501    * @SINCE_1_2.60
502    */
503   typedef Signal<void(TextEditor, Scroll::Type)> ScrollStateChangedSignalType;
504
505   /**
506    * @brief Creates the TextEditor control.
507    *
508    * @SINCE_1_1.37
509    * @return A handle to the TextEditor control
510    */
511   static TextEditor
512   New();
513
514   /**
515    * @brief Creates an empty handle.
516    *
517    * @SINCE_1_1.37
518    */
519   TextEditor();
520
521   /**
522    * @brief Copy constructor.
523    *
524    * @SINCE_1_1.37
525    * @param[in] handle The handle to copy from
526    */
527   TextEditor(const TextEditor& handle);
528
529   /**
530    * @brief Move constructor
531    * @SINCE_1_9.23
532    *
533    * @param[in] rhs A reference to the moved handle
534    */
535   TextEditor(TextEditor&& rhs);
536
537   /**
538    * @brief Assignment operator.
539    *
540    * @SINCE_1_1.37
541    * @param[in] handle The handle to copy from
542    * @return A reference to this
543    */
544   TextEditor& operator=(const TextEditor& handle);
545
546   /**
547    * @brief Move assignment
548    * @SINCE_1_9.23
549    *
550    * @param[in] rhs A reference to the moved handle
551    * @return A reference to this
552    */
553   TextEditor& operator=(TextEditor&& rhs);
554
555   /**
556    * @brief Destructor.
557    *
558    * This is non-virtual since derived Handle types must not contain data or virtual methods.
559    * @SINCE_1_1.37
560    */
561   ~TextEditor();
562
563   /**
564    * @brief Downcasts a handle to TextEditor.
565    *
566    * If the BaseHandle points is a TextEditor, the downcast returns a valid handle.
567    * If not, the returned handle is left empty.
568    *
569    * @SINCE_1_1.37
570    * @param[in] handle Handle to an object
571    * @return Handle to a TextEditor or an empty handle
572    */
573   static TextEditor
574   DownCast(BaseHandle handle);
575
576   // Signals
577
578   /**
579    * @brief This signal is emitted when the text changes.
580    *
581    * A callback of the following type may be connected:
582    * @code
583    *   void YourCallbackName( TextEditor textEditor );
584    * @endcode
585    *
586    * @SINCE_1_1.37
587    * @return The signal to connect to
588    */
589   TextChangedSignalType&
590   TextChangedSignal();
591
592   /**
593    * @brief This signal is emitted when the input style is updated as a consequence of a change in the cursor position.
594    * i.e. The signal is not emitted when the input style is updated through the property system.
595    *
596    * A callback of the following type may be connected. The @p mask parameter notifies which parts of the style have changed.
597    * @code
598    *   void YourCallbackName( TextEditor textEditor, TextEditor::InputStyle::Mask mask );
599    * @endcode
600    *
601    * @SINCE_1_2_2
602    * @return The signal to connect to
603    */
604   InputStyleChangedSignalType&
605   InputStyleChangedSignal();
606
607   /**
608    * @brief This signal is emitted when TextEditor scrolling is started or finished.
609    *
610    * A callback of the following type may be connected:
611    * @code
612    *   void YourCallbackName( Scroll::Type type );
613    * @endcode
614    * type: Whether the scrolling is started or finished.
615    *
616    * @SINCE_1_2.60
617    * @return The signal to connect to
618    */
619   ScrollStateChangedSignalType&
620   ScrollStateChangedSignal();
621
622 public: // Not intended for application developers
623   /// @cond internal
624   /**
625    * @brief Creates a handle using the Toolkit::Internal implementation.
626    *
627    * @SINCE_1_1.37
628    * @param[in] implementation The Control implementation
629    */
630   DALI_INTERNAL
631   TextEditor(Internal::TextEditor& implementation);
632
633   /**
634    * @brief Allows the creation of this Control from an Internal::CustomActor pointer.
635    *
636    * @SINCE_1_1.37
637    * @param[in] internal A pointer to the internal CustomActor
638    */
639   explicit DALI_INTERNAL
640   TextEditor(Dali::Internal::CustomActor* internal);
641   /// @endcond
642 };
643
644 /**
645  * @}
646  */
647 } // namespace Toolkit
648
649 } // namespace Dali
650
651 #endif // DALI_TOOLKIT_TEXT_EDITOR_H