Text - FONT_STYLE and INPUT_FONT_STYLE properties refactor.
[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) 2016 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 An enumeration of properties belonging to the TextField class.
65    * @SINCE_1_0.0
66    */
67   struct Property
68   {
69     enum
70     {
71       RENDERING_BACKEND = PROPERTY_START_INDEX, ///< name "renderingBackend",                    The type or rendering e.g. bitmap-based,                                           type INT @SINCE_1_0.0
72       TEXT,                                     ///< name "text",                                The text to display in UTF-8 format,                                               type STRING @SINCE_1_0.0
73       PLACEHOLDER_TEXT,                         ///< name "placeholderText",                     The text to display when the TextField is empty and inactive,                      type STRING @SINCE_1_0.0
74       PLACEHOLDER_TEXT_FOCUSED,                 ///< name "placeholderTextFocused",              The text to display when the TextField is empty with key-input focus,              type STRING @SINCE_1_0.0
75       FONT_FAMILY,                              ///< name "fontFamily",                          The requested font family,                                                         type STRING @SINCE_1_0.0
76       FONT_STYLE,                               ///< name "fontStyle",                           The requested font style,                                                          type STRING or MAP @SINCE_1_2.13
77       POINT_SIZE,                               ///< name "pointSize",                           The size of font in points,                                                        type FLOAT @SINCE_1_0.0
78       MAX_LENGTH,                               ///< name "maxLength"                            The maximum number of characters that can be inserted,                             type INTEGER @SINCE_1_0.0
79       EXCEED_POLICY,                            ///< name "exceedPolicy"                         Specifies how the text is truncated when it does not fit,                          type INTEGER @SINCE_1_0.0
80       HORIZONTAL_ALIGNMENT,                     ///< name "horizontalAlignment",                 The line horizontal alignment,                                                     type STRING,  values "BEGIN", "CENTER", "END" @SINCE_1_0.0
81       VERTICAL_ALIGNMENT,                       ///< name "verticalAlignment",                   The line vertical alignment,                                                       type STRING,  values "TOP",   "CENTER", "BOTTOM" @SINCE_1_0.0
82       TEXT_COLOR,                               ///< name "textColor",                           The text color,                                                                    type VECTOR4 @SINCE_1_0.0
83       PLACEHOLDER_TEXT_COLOR,                   ///< name "placeholderTextColor",                The placeholder-text color,                                                        type VECTOR4 @SINCE_1_0.0
84       SHADOW_OFFSET,                            ///< name "shadowOffset",                        The drop shadow offset 0 indicates no shadow,                                      type VECTOR2 @DEPRECATED_1_1.37 Use SHADOW instead.
85       SHADOW_COLOR,                             ///< name "shadowColor",                         The color of a drop shadow,                                                        type VECTOR4 @DEPRECATED_1_1.37 Use SHADOW instead.
86       PRIMARY_CURSOR_COLOR,                     ///< name "primaryCursorColor",                  The color to apply to the primary cursor,                                          type VECTOR4 @SINCE_1_0.0
87       SECONDARY_CURSOR_COLOR,                   ///< name "secondaryCursorColor",                The color to apply to the secondary cursor,                                        type VECTOR4 @SINCE_1_0.0
88       ENABLE_CURSOR_BLINK,                      ///< name "enableCursorBlink",                   Whether the cursor should blink or not,                                            type BOOLEAN @SINCE_1_0.0
89       CURSOR_BLINK_INTERVAL,                    ///< name "cursorBlinkInterval",                 The time interval in seconds between cursor on/off states,                         type FLOAT @SINCE_1_0.0
90       CURSOR_BLINK_DURATION,                    ///< name "cursorBlinkDuration",                 The cursor will stop blinking after this number of seconds (if non-zero),          type FLOAT @SINCE_1_0.0
91       CURSOR_WIDTH,                             ///< name "cursorWidth",                         The cursor width,                                                                  type INTEGER @SINCE_1_0.0
92       GRAB_HANDLE_IMAGE,                        ///< name "grabHandleImage",                     The image to display for the grab handle,                                          type STRING @SINCE_1_0.0
93       GRAB_HANDLE_PRESSED_IMAGE,                ///< name "grabHandlePressedImage",              The image to display when the grab handle is pressed,                              type STRING @SINCE_1_0.0
94       SCROLL_THRESHOLD,                         ///< name "scrollThreshold"                      Horizontal scrolling will occur if the cursor is this close to the control border, type FLOAT @SINCE_1_0.0
95       SCROLL_SPEED,                             ///< name "scrollSpeed"                          The scroll speed in pixels per second,                                             type FLOAT @SINCE_1_0.0
96       SELECTION_HANDLE_IMAGE_LEFT,              ///< name "selectionHandleImageLeft",            The image to display for the left selection handle,                                type MAP @SINCE_1_0.0
97       SELECTION_HANDLE_IMAGE_RIGHT,             ///< name "selectionHandleImageRight",           The image to display for the right selection handle,                               type MAP @SINCE_1_0.0
98       SELECTION_HANDLE_PRESSED_IMAGE_LEFT,      ///< name "selectionHandlePressedImageLeft",     The image to display when the left selection handle is pressed,                    type MAP @SINCE_1_0.0
99       SELECTION_HANDLE_PRESSED_IMAGE_RIGHT,     ///< name "selectionHandlePressedImageRight",    The image to display when the right selection handle is pressed,                   type MAP @SINCE_1_0.0
100       SELECTION_HANDLE_MARKER_IMAGE_LEFT,       ///< name "selectionHandleMarkerImageLeft",      The image to display for the left selection handle marker,                         type MAP @SINCE_1_0.0
101       SELECTION_HANDLE_MARKER_IMAGE_RIGHT,      ///< name "selectionHandleMarkerImageRight",     The image to display for the right selection handle marker,                        type MAP @SINCE_1_0.0
102       SELECTION_HIGHLIGHT_COLOR,                ///< name "selectionHighlightColor",             The color of the selection highlight,                                              type VECTOR4 @SINCE_1_0.0
103       DECORATION_BOUNDING_BOX,                  ///< name "decorationBoundingBox",               The decorations (handles etc) will positioned within this area on-screen,          type RECTANGLE @SINCE_1_0.0
104       INPUT_METHOD_SETTINGS,                    ///< name "inputMethodSettings",                 The settings to relating to the System's Input Method, Key and Value               type MAP @SINCE_1_0.0
105       INPUT_COLOR,                              ///< name "inputColor",                          The color of the new input text,                                                   type VECTOR4 @SINCE_1_0.0
106       ENABLE_MARKUP,                            ///< name "enableMarkup",                        Whether the mark-up processing is enabled.                                         type BOOLEAN @SINCE_1_0.0
107       INPUT_FONT_FAMILY,                        ///< name "inputFontFamily",                     The font's family of the new input text,                                           type STRING @SINCE_1_0.0
108       INPUT_FONT_STYLE,                         ///< name "inputFontStyle",                      The font's style of the new input text,                                            type STRING or MAP @SINCE_1_2.13
109       INPUT_POINT_SIZE,                         ///< name "inputPointSize",                      The font's size of the new input text in points,                                   type FLOAT @SINCE_1_0.0
110       UNDERLINE,                                ///< name "underline"                            The default underline parameters,                                                  type STRING or MAP @SINCE_1_2.13
111       INPUT_UNDERLINE,                          ///< name "inputUnderline"                       The underline parameters of the new input text,                                    type STRING or MAP @SINCE_1_2.13
112       SHADOW,                                   ///< name "shadow"                               The default shadow parameters,                                                     type STRING or MAP @SINCE_1_2.13
113       INPUT_SHADOW,                             ///< name "inputShadow"                          The shadow parameters of the new input text,                                       type STRING or MAP @SINCE_1_2.13
114       EMBOSS,                                   ///< name "emboss"                               The default emboss parameters,                                                     type STRING or MAP @SINCE_1_2.13
115       INPUT_EMBOSS,                             ///< name "inputEmboss"                          The emboss parameters of the new input text,                                       type STRING or MAP @SINCE_1_2.13
116       OUTLINE,                                  ///< name "outline"                              The default outline parameters,                                                    type STRING or MAP @SINCE_1_2.13
117       INPUT_OUTLINE,                            ///< name "inputOutline"                         The outline parameters of the new input text,                                      type STRING or MAP @SINCE_1_2.13
118     };
119   };
120
121   /**
122    * @brief Specifies how the text is truncated when it does not fit
123    *
124    * The default value is \e EXCEED_POLICY_CLIP.
125    * @SINCE_1_0.0
126    */
127   enum ExceedPolicy
128   {
129     EXCEED_POLICY_ORIGINAL,        ///< The text will be display at original size, and may exceed the TextField boundary. @SINCE_1_0.0
130     EXCEED_POLICY_CLIP             ///< The end of text will be clipped to fit within the TextField. @SINCE_1_0.0
131   };
132
133   /**
134    * @brief Mask used by the signal InputStyleChangedSignal(). Notifies which parameters of the input style have changed.
135    *
136    * @SINCE_1_2_2
137    */
138   struct InputStyle
139   {
140     enum Mask
141     {
142       NONE         = 0x0000, ///< @SINCE_1_2_2
143       COLOR        = 0x0001, ///< @SINCE_1_2_2
144       FONT_FAMILY  = 0x0002, ///< @SINCE_1_2_2
145       POINT_SIZE   = 0x0004, ///< @SINCE_1_2_2
146       FONT_STYLE   = 0x0008, ///< @SINCE_1_2_2
147       UNDERLINE    = 0x0010, ///< @SINCE_1_2_2
148       SHADOW       = 0x0020, ///< @SINCE_1_2_2
149       EMBOSS       = 0x0040, ///< @SINCE_1_2_2
150       OUTLINE      = 0x0080  ///< @SINCE_1_2_2
151     };
152   };
153
154   // Type Defs
155
156   /**
157    * @brief Text changed signal type.
158    * @SINCE_1_0.0
159    */
160   typedef Signal<void ( TextField ) > TextChangedSignalType;
161
162   /**
163    * @brief Max Characters Exceed signal type.
164    * @SINCE_1_0.0
165    */
166   typedef Signal<void ( TextField ) > MaxLengthReachedSignalType;
167
168   /**
169    * @brief Input Style changed signal type.
170    * @SINCE_1_2_2
171    */
172   typedef Signal<void ( TextField, InputStyle::Mask ) > InputStyleChangedSignalType;
173
174   /**
175    * @brief Create the TextField control.
176    * @SINCE_1_0.0
177    * @return A handle to the TextField control.
178    */
179   static TextField New();
180
181   /**
182    * @brief Creates an empty handle.
183    * @SINCE_1_0.0
184    */
185   TextField();
186
187   /**
188    * @brief Copy constructor.
189    *
190    * @SINCE_1_0.0
191    * @param[in] handle The handle to copy from.
192    */
193   TextField( const TextField& handle );
194
195   /**
196    * @brief Assignment operator.
197    *
198    * @SINCE_1_0.0
199    * @param[in] handle The handle to copy from.
200    * @return A reference to this.
201    */
202   TextField& operator=( const TextField& handle );
203
204   /**
205    * @brief Destructor.
206    *
207    * This is non-virtual since derived Handle types must not contain data or virtual methods.
208    * @SINCE_1_0.0
209    */
210   ~TextField();
211
212   /**
213    * @brief Downcast a handle to TextField.
214    *
215    * If the BaseHandle points is a TextField the downcast returns a valid handle.
216    * If not the returned handle is left empty.
217    *
218    * @SINCE_1_0.0
219    * @param[in] handle Handle to an object.
220    * @return handle to a TextField or an empty handle.
221    */
222   static TextField DownCast( BaseHandle handle );
223
224   // Signals
225
226   /**
227    * @brief This signal is emitted when the text changes.
228    *
229    * A callback of the following type may be connected:
230    * @code
231    *   void YourCallbackName( TextField textField );
232    * @endcode
233    * @SINCE_1_0.0
234    * @return The signal to connect to.
235    */
236   TextChangedSignalType& TextChangedSignal();
237
238   /**
239    * @brief This signal is emitted when inserted text exceeds the maximum character limit.
240    *
241    * A callback of the following type may be connected:
242    * @code
243    *   void YourCallbackName( TextField textField );
244    * @endcode
245    * @SINCE_1_0.0
246    * @return The signal to connect to.
247    */
248   MaxLengthReachedSignalType& MaxLengthReachedSignal();
249
250   /**
251    * @brief This signal is emitted when the input style is updated as a consequence of a change in the cursor position.
252    * i.e. The signal is not emitted when the input style is updated through the property system.
253    *
254    * A callback of the following type may be connected. The @p mask parameter notifies which parts of the style have changed.
255    * @code
256    *   void YourCallbackName( TextField textField, TextField::InputStyle::Mask mask );
257    * @endcode
258    *
259    * @SINCE_1_2_2
260    * @return The signal to connect to.
261    */
262   InputStyleChangedSignalType& InputStyleChangedSignal();
263
264 public: // Not intended for application developers
265
266   /**
267    * @brief Creates a handle using the Toolkit::Internal implementation.
268    *
269    * @SINCE_1_0.0
270    * @param[in] implementation The Control implementation.
271    */
272   DALI_INTERNAL TextField( Internal::TextField& implementation );
273
274   /**
275    * @brief Allows the creation of this Control from an Internal::CustomActor pointer.
276    *
277    * @SINCE_1_0.0
278    * @param[in]  internal  A pointer to the internal CustomActor.
279    */
280   explicit DALI_INTERNAL TextField( Dali::Internal::CustomActor* internal );
281 };
282
283 /**
284  * @}
285  */
286 } // namespace Toolkit
287
288 } // namespace Dali
289
290 #endif // __DALI_TOOLKIT_TEXT_FIELD_H__