Multiline - Create a text-editor control.
[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) 2015 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()                            |
46  * | maxLengthReached     | @ref MaxLengthReachedSignal()                       |
47  *
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    */
56   enum PropertyRange
57   {
58     PROPERTY_START_INDEX = Control::CONTROL_PROPERTY_END_INDEX + 1,
59     PROPERTY_END_INDEX =   PROPERTY_START_INDEX + 1000              ///< Reserve property indices
60   };
61
62   /**
63    * @brief An enumeration of properties belonging to the TextField class.
64    */
65   struct Property
66   {
67     enum
68     {
69       RENDERING_BACKEND = PROPERTY_START_INDEX, ///< name "renderingBackend",                    The type or rendering e.g. bitmap-based,                                           type INT
70       TEXT,                                     ///< name "text",                                The text to display in UTF-8 format,                                               type STRING
71       PLACEHOLDER_TEXT,                         ///< name "placeholderText",                     The text to display when the TextField is empty and inactive,                      type STRING
72       PLACEHOLDER_TEXT_FOCUSED,                 ///< name "placeholderTextFocused",              The text to display when the TextField is empty with key-input focus,              type STRING
73       FONT_FAMILY,                              ///< name "fontFamily",                          The requested font family,                                                         type STRING
74       FONT_STYLE,                               ///< name "fontStyle",                           The requested font style,                                                          type STRING
75       POINT_SIZE,                               ///< name "pointSize",                           The size of font in points,                                                        type FLOAT
76       MAX_LENGTH,                               ///< name "maxLength"                            The maximum number of characters that can be inserted,                             type INTEGER
77       EXCEED_POLICY,                            ///< name "exceedPolicy"                         Specifies how the text is truncated when it does not fit,                          type INTEGER
78       HORIZONTAL_ALIGNMENT,                     ///< name "horizontalAlignment",                 The line horizontal alignment,                                                     type STRING,  values "BEGIN", "CENTER", "END"
79       VERTICAL_ALIGNMENT,                       ///< name "verticalAlignment",                   The line vertical alignment,                                                       type STRING,  values "TOP",   "CENTER", "BOTTOM"
80       TEXT_COLOR,                               ///< name "textColor",                           The text color,                                                                    type VECTOR4
81       PLACEHOLDER_TEXT_COLOR,                   ///< name "placeholderTextColor",                The placeholder-text color,                                                        type VECTOR4
82       SHADOW_OFFSET,                            ///< name "shadowOffset",                        The drop shadow offset 0 indicates no shadow,                                      type VECTOR2
83       SHADOW_COLOR,                             ///< name "shadowColor",                         The color of a drop shadow,                                                        type VECTOR4
84       PRIMARY_CURSOR_COLOR,                     ///< name "primaryCursorColor",                  The color to apply to the primary cursor,                                          type VECTOR4
85       SECONDARY_CURSOR_COLOR,                   ///< name "secondaryCursorColor",                The color to apply to the secondary cursor,                                        type VECTOR4
86       ENABLE_CURSOR_BLINK,                      ///< name "enableCursorBlink",                   Whether the cursor should blink or not,                                            type BOOLEAN
87       CURSOR_BLINK_INTERVAL,                    ///< name "cursorBlinkInterval",                 The time interval in seconds between cursor on/off states,                         type FLOAT
88       CURSOR_BLINK_DURATION,                    ///< name "cursorBlinkDuration",                 The cursor will stop blinking after this number of seconds (if non-zero),          type FLOAT
89       CURSOR_WIDTH,                             ///< name "cursorWidth",                         The cursor width,                                                                  type INTEGER
90       GRAB_HANDLE_IMAGE,                        ///< name "grabHandleImage",                     The image to display for the grab handle,                                          type STRING
91       GRAB_HANDLE_PRESSED_IMAGE,                ///< name "grabHandlePressedImage",              The image to display when the grab handle is pressed,                              type STRING
92       SCROLL_THRESHOLD,                         ///< name "scrollThreshold"                      Horizontal scrolling will occur if the cursor is this close to the control border, type FLOAT
93       SCROLL_SPEED,                             ///< name "scrollSpeed"                          The scroll speed in pixels per second,                                             type FLOAT
94       SELECTION_HANDLE_IMAGE_LEFT,              ///< name "selectionHandleImageLeft",            The image to display for the left selection handle,                                type MAP
95       SELECTION_HANDLE_IMAGE_RIGHT,             ///< name "selectionHandleImageRight",           The image to display for the right selection handle,                               type MAP
96       SELECTION_HANDLE_PRESSED_IMAGE_LEFT,      ///< name "selectionHandlePressedImageLeft",     The image to display when the left selection handle is pressed,                    type MAP
97       SELECTION_HANDLE_PRESSED_IMAGE_RIGHT,     ///< name "selectionHandlePressedImageRight",    The image to display when the right selection handle is pressed,                   type MAP
98       SELECTION_HANDLE_MARKER_IMAGE_LEFT,       ///< name "selectionHandleMarkerImageLeft",      The image to display for the left selection handle marker,                         type MAP
99       SELECTION_HANDLE_MARKER_IMAGE_RIGHT,      ///< name "selectionHandleMarkerImageRight",     The image to display for the right selection handle marker,                        type MAP
100       SELECTION_HIGHLIGHT_COLOR,                ///< name "selectionHighlightColor",             The color of the selection highlight,                                              type VECTOR4
101       DECORATION_BOUNDING_BOX,                  ///< name "decorationBoundingBox",               The decorations (handles etc) will positioned within this area on-screen,          type RECTANGLE
102       INPUT_METHOD_SETTINGS,                    ///< name "inputMethodSettings",                 The settings to relating to the System's Input Method, Key and Value               type MAP
103       INPUT_COLOR,                              ///< name "inputColor",                          The color of the new input text,                                                   type VECTOR4
104       ENABLE_MARKUP,                            ///< name "enableMarkup",                        Whether the mark-up processing is enabled.                                         type BOOLEAN
105       INPUT_FONT_FAMILY,                        ///< name "inputFontFamily",                     The font's family of the new input text,                                           type STRING
106       INPUT_FONT_STYLE,                         ///< name "inputFontStyle",                      The font's style of the new input text,                                            type STRING
107       INPUT_POINT_SIZE                          ///< name "inputPointSize",                      The font's size of the new input text in points,                                   type FLOAT
108     };
109   };
110
111   /**
112    * @brief Specifies how the text is truncated when it does not fit
113    *
114    * The default value is \e EXCEED_POLICY_CLIP.
115    */
116   enum ExceedPolicy
117   {
118     EXCEED_POLICY_ORIGINAL,        ///< The text will be display at original size, and may exceed the TextField boundary.
119     EXCEED_POLICY_CLIP             ///< The end of text will be clipped to fit within the TextField.
120   };
121
122   // Type Defs
123
124   /// @brief Text changed signal type.
125   typedef Signal<void ( TextField ) > TextChangedSignalType;
126   /// @brief Max Characters Exceed signal type.
127   typedef Signal<void ( TextField ) > MaxLengthReachedSignalType;
128
129   /**
130    * @brief Create the TextField control.
131    * @return A handle to the TextField control.
132    */
133   static TextField New();
134
135   /**
136    * @brief Creates an empty handle.
137    */
138   TextField();
139
140   /**
141    * @brief Copy constructor.
142    *
143    * @param[in] handle The handle to copy from.
144    */
145   TextField( const TextField& handle );
146
147   /**
148    * @brief Assignment operator.
149    *
150    * @param[in] handle The handle to copy from.
151    * @return A reference to this.
152    */
153   TextField& operator=( const TextField& handle );
154
155   /**
156    * @brief Destructor.
157    *
158    * This is non-virtual since derived Handle types must not contain data or virtual methods.
159    */
160   ~TextField();
161
162   /**
163    * @brief Downcast a handle to TextField.
164    *
165    * If the BaseHandle points is a TextField the downcast returns a valid handle.
166    * If not the returned handle is left empty.
167    *
168    * @param[in] handle Handle to an object.
169    * @return handle to a TextField or an empty handle.
170    */
171   static TextField DownCast( BaseHandle handle );
172
173   // Signals
174
175   /**
176    * @brief This signal is emitted when the text changes.
177    *
178    * A callback of the following type may be connected:
179    * @code
180    *   void YourCallbackName( TextField textField );
181    * @endcode
182    * @return The signal to connect to.
183    */
184   TextChangedSignalType& TextChangedSignal();
185
186   /**
187    * @brief This signal is emitted when inserted text exceeds the maximum character limit.
188    *
189    * A callback of the following type may be connected:
190    * @code
191    *   void YourCallbackName( TextField textField );
192    * @endcode
193    * @return The signal to connect to.
194    */
195   MaxLengthReachedSignalType& MaxLengthReachedSignal();
196
197 public: // Not intended for application developers
198
199   /**
200    * @brief Creates a handle using the Toolkit::Internal implementation.
201    *
202    * @param[in] implementation The Control implementation.
203    */
204   DALI_INTERNAL TextField( Internal::TextField& implementation );
205
206   /**
207    * @brief Allows the creation of this Control from an Internal::CustomActor pointer.
208    *
209    * @param[in]  internal  A pointer to the internal CustomActor.
210    */
211   explicit DALI_INTERNAL TextField( Dali::Internal::CustomActor* internal );
212 };
213
214 /**
215  * @}
216  */
217 } // namespace Toolkit
218
219 } // namespace Dali
220
221 #endif // __DALI_TOOLKIT_TEXT_FIELD_H__