Added TextChanged signal to TextField
[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 /**
36  * @brief A control which provides a single-line editable text field.
37  *
38  *  * Signals
39  * | %Signal Name           | Method                                              |
40  * |------------------------|-----------------------------------------------------|
41  * | text-changed           | @ref TextChangedSignal()                            |
42  * | max-length-reached     | @ref MaxLengthReachedSignal()                       |
43  *
44  */
45 class DALI_IMPORT_API TextField : public Control
46 {
47 public:
48
49   /**
50    * @brief The start and end property ranges for this control.
51    */
52   enum PropertyRange
53   {
54     PROPERTY_START_INDEX = Control::CONTROL_PROPERTY_END_INDEX + 1,
55     PROPERTY_END_INDEX =   PROPERTY_START_INDEX + 1000              ///< Reserve property indices
56   };
57
58   /**
59    * @brief An enumeration of properties belonging to the TextLabel class.
60    */
61   struct Property
62   {
63     enum
64     {
65       RENDERING_BACKEND = PROPERTY_START_INDEX, ///< name "rendering-backend",                   The type or rendering e.g. bitmap-based,                                  type INT
66       TEXT,                                     ///< name "text",                                The text to display in UTF-8 format,                                      type STRING
67       PLACEHOLDER_TEXT,                         ///< name "placeholder-text",                    The text to display when the TextField is empty and inactive,             type STRING
68       PLACEHOLDER_TEXT_FOCUSED,                 ///< name "placeholder-text-focused",            The text to display when the TextField is empty with key-input focus,     type STRING
69       FONT_FAMILY,                              ///< name "font-family",                         The requested font family,                                                type STRING
70       FONT_STYLE,                               ///< name "font-style",                          The requested font style e.g. Regular/Italic,                             type STRING
71       POINT_SIZE,                               ///< name "point-size",                          The size of font in points,                                               type FLOAT
72       MAX_LENGTH,                               ///< name "max-length"                           The maximum number of characters that can be inserted,                    type INTEGER
73       EXCEED_POLICY,                            ///< name "exceed-policy"                        Specifies how the text is truncated when it does not fit,                 type INTEGER
74       HORIZONTAL_ALIGNMENT,                     ///< name "horizontal-alignment",                The line horizontal alignment,                                            type STRING,  values "BEGIN", "CENTER", "END"
75       VERTICAL_ALIGNMENT,                       ///< name "vertical-alignment",                  The line vertical alignment,                                              type STRING,  values   "TOP",   "CENTER",   "BOTTOM"
76       TEXT_COLOR,                               ///< name "text-color",                          The text color,                                                           type VECTOR4
77       PLACEHOLDER_TEXT_COLOR,                   ///< name "placeholder-text-color",              The placeholder-text color,                                               type VECTOR4
78       SHADOW_OFFSET,                            ///< name "shadow-offset",                       The drop shadow offset 0 indicates no shadow,                             type VECTOR2
79       SHADOW_COLOR,                             ///< name "shadow-color",                        The color of a drop shadow,                                               type VECTOR4
80       PRIMARY_CURSOR_COLOR,                     ///< name "primary-cursor-color",                The color to apply to the primary cursor,                                 type VECTOR4
81       SECONDARY_CURSOR_COLOR,                   ///< name "secondary-cursor-color",              The color to apply to the secondary cursor,                               type VECTOR4
82       ENABLE_CURSOR_BLINK,                      ///< name "enable-cursor-blink",                 Whether the cursor should blink or not,                                   type BOOLEAN
83       CURSOR_BLINK_INTERVAL,                    ///< name "cursor-blink-interval",               The time interval in seconds between cursor on/off states,                type FLOAT
84       CURSOR_BLINK_DURATION,                    ///< name "cursor-blink-duration",               The cursor will stop blinking after this number of seconds (if non-zero), type FLOAT
85       GRAB_HANDLE_IMAGE,                        ///< name "grab-handle-image",                   The image to display for the grab handle,                                 type STRING
86       GRAB_HANDLE_PRESSED_IMAGE,                ///< name "grab-handle-pressed-image",           The image to display when the grab handle is pressed,                     type STRING
87       SCROLL_THRESHOLD,                         ///< name "scroll-threshold"                     Scrolling will occur if the cursor is this close to the control border,   type FLOAT
88       SCROLL_SPEED,                             ///< name "scroll-speed"                         The scroll speed in pixels per second,                                    type FLOAT
89       SELECTION_HANDLE_IMAGE_LEFT,              ///< name "selection-handle-image-left",         The image to display for the left selection handle,                       type STRING
90       SELECTION_HANDLE_IMAGE_RIGHT,             ///< name "selection-handle-image-right",        The image to display for the right selection handle,                      type STRING
91       SELECTION_HANDLE_PRESSED_IMAGE_LEFT,      ///< name "selection-handle-pressed-image-left"  The image to display when the left selection handle is pressed,           type STRING
92       SELECTION_HANDLE_PRESSED_IMAGE_RIGHT,     ///< name "selection-handle-pressed-image-right" The image to display when the right selection handle is pressed,          type STRING
93       SELECTION_HIGHLIGHT_COLOR,                ///< name "selection-highlight-color"            The color of the selection highlight,                                     type VECTOR4
94       DECORATION_BOUNDING_BOX,                  ///< name "decoration-bounding-box"              The decorations (handles etc) will positioned within this area on-screen, type RECTANGLE
95       INPUT_METHOD_SETTINGS                     ///< name "input-method-settings"                The settings to relating to the System's Input Method, Key and Value      type MAP
96     };
97   };
98
99   /**
100    * @brief Specifies how the text is truncated when it does not fit
101    *
102    * The default value is \e EXCEED_POLICY_CLIP.
103    */
104   enum ExceedPolicy
105   {
106     EXCEED_POLICY_ORIGINAL,        ///< The text will be display at original size, and may exceed the TextField boundary.
107     EXCEED_POLICY_CLIP             ///< The end of text will be clipped to fit within the TextField.
108   };
109
110   // Type Defs
111
112   /// @brief Max Characters Exceed signal type;
113   typedef Signal<void ( TextField ) > TextChangedSignalType;
114   typedef Signal<void ( TextField ) > MaxLengthReachedSignalType;
115
116   /**
117    * Create the TextField control.
118    * @return A handle to the TextField control.
119    */
120   static TextField New();
121
122   /**
123    * @brief Creates an empty handle.
124    */
125   TextField();
126
127   /**
128    * @brief Copy constructor.
129    *
130    * @param[in] handle The handle to copy from.
131    */
132   TextField( const TextField& handle );
133
134   /**
135    * @brief Assignment operator.
136    *
137    * @param[in] handle The handle to copy from.
138    * @return A reference to this.
139    */
140   TextField& operator=( const TextField& handle );
141
142   /**
143    * @brief Destructor
144    *
145    * This is non-virtual since derived Handle types must not contain data or virtual methods.
146    */
147   ~TextField();
148
149   /**
150    * @brief Downcast a handle to TextField.
151    *
152    * If the BaseHandle points is a TextField the downcast returns a valid handle.
153    * If not the returned handle is left empty.
154    *
155    * @param[in] handle Handle to an object
156    * @return handle to a TextField or an empty handle
157    */
158   static TextField DownCast( BaseHandle handle );
159
160   // Signals
161
162   /**
163    * @brief This signal is emitted when the text changes.
164    *
165    * A callback of the following type may be connected:
166    * @code
167    *   void YourCallbackName( TextField textField );
168    * @endcode
169    * @return The signal to connect to.
170    */
171   TextChangedSignalType& TextChangedSignal();
172
173   /**
174    * @brief This signal is emitted when inserted text exceeds the maximum character limit.
175    *
176    * A callback of the following type may be connected:
177    * @code
178    *   void YourCallbackName( TextField textField );
179    * @endcode
180    * @return The signal to connect to.
181    */
182   MaxLengthReachedSignalType& MaxLengthReachedSignal();
183
184 public: // Not intended for application developers
185
186   /**
187    * @brief Creates a handle using the Toolkit::Internal implementation.
188    *
189    * @param[in] implementation The Control implementation.
190    */
191   DALI_INTERNAL TextField( Internal::TextField& implementation );
192
193   /**
194    * @brief Allows the creation of this Control from an Internal::CustomActor pointer.
195    *
196    * @param[in]  internal  A pointer to the internal CustomActor.
197    */
198   explicit DALI_INTERNAL TextField( Dali::Internal::CustomActor* internal );
199 };
200
201 } // namespace Toolkit
202
203 } // namespace Dali
204
205 #endif // __DALI_TOOLKIT_TEXT_FIELD_H__