1 <!-- ##### SECTION Title ##### -->
4 <!-- ##### SECTION Short_Description ##### -->
5 Interface for text-editing widgets.
7 <!-- ##### SECTION Long_Description ##### -->
9 The #GtkEditable class is a base class for widgets
10 for editing text, such as #GtkEntry and #GtkText. It
11 cannot be instantiated by itself. The editable
12 class contains functions for generically manipulating
13 an editable widget, a large number of action signals
14 used for key bindings, and several signals that
15 an application can connect to to modify the behavior
20 As an example of the latter usage, by connecting
21 the following handler to "insert_text", an application
22 can convert all entry into a widget into uppercase.
25 <title>Forcing entry to uppercase.</title>
27 #include <ctype.h>
30 insert_text_handler (GtkEditable *editable,
37 gchar *result = g_new (gchar, length);
39 for (i = 0; i < length; i++)
40 result[i] = islower (text[i]) ? toupper (text[i]) : text[i];
42 g_signal_handlers_block_by_func (GTK_OBJECT (editable),
43 insert_text_handler, data);
44 gtk_editable_insert_text (editable, result, length, position);
45 g_signal_handlers_unblock_by_func (GTK_OBJECT (editable),
46 insert_text_handler, data);
48 g_signal_stop_emission_by_name (GTK_OBJECT (editable), "insert_text");
56 <!-- ##### SECTION See_Also ##### -->
61 <!-- ##### STRUCT GtkEditable ##### -->
63 The #GtkEditable structure contains the following fields.
64 (These fields should be considered read-only. They should
65 never be set by an application.)
67 <informaltable pgwide="1" frame="none" role="struct">
68 <tgroup cols="2"><colspec colwidth="2*"/><colspec colwidth="8*"/>
72 <entry>#guint selection_start;</entry>
73 <entry>the starting position of the selected characters
74 in the widget.</entry>
78 <entry>#guint selection_end;</entry>
79 <entry>the end position of the selected characters
80 in the widget.</entry>
84 <entry>#guint editable;</entry>
85 <entry>a flag indicating whether or not the widget is
86 editable by the user.</entry>
89 </tbody></tgroup></informaltable>
93 <!-- ##### FUNCTION gtk_editable_select_region ##### -->
95 Selects a region of text. The characters that
96 are selected are those characters at positions from
97 @start_pos up to, but not including @end_pos. If
98 @end_pos is negative, then the the characters selected
99 will be those characters from @start_pos to the end
103 @editable: a #GtkEditable widget.
104 @start: the starting position.
105 @end: the end position.
108 <!-- ##### FUNCTION gtk_editable_get_selection_bounds ##### -->
110 Gets the current selection bounds, if there is a selection.
113 @editable: a #GtkEditable widget.
114 @start: location to store the starting position, or %NULL.
115 @end: location to store the end position, or %NULL.
116 @Returns: %TRUE if there is a selection.
119 <!-- ##### FUNCTION gtk_editable_insert_text ##### -->
121 Inserts text at a given position.
124 @editable: a #GtkEditable widget.
125 @new_text: the text to insert.
126 @new_text_length: the length of the text to insert, in bytes
127 @position: an inout parameter. The caller initializes it to
128 the position at which to insert the text. After the
129 call it points at the position after the newly
133 <!-- ##### FUNCTION gtk_editable_delete_text ##### -->
135 Deletes a sequence of characters. The characters that
136 are deleted are those characters at positions from
137 @start_pos up to, but not including @end_pos. If
138 @end_pos is negative, then the the characters deleted
139 will be those characters from @start_pos to the end
143 @editable: a #GtkEditable widget.
144 @start_pos: the starting position.
145 @end_pos: the end position.
148 <!-- ##### FUNCTION gtk_editable_get_chars ##### -->
150 Retrieves a sequence of characters. The characters that
151 are retrieved are those characters at positions from
152 @start_pos up to, but not including @end_pos. If
153 @end_pos is negative, then the the characters retrieved
154 will be those characters from @start_pos to the end
158 @editable: a #GtkEditable widget.
159 @start_pos: the starting position.
160 @end_pos: the end position.
161 @Returns: the characters in the indicated region.
162 The result must be freed with g_free() when
163 the application is finished with it.
166 <!-- ##### FUNCTION gtk_editable_cut_clipboard ##### -->
168 Causes the characters in the current selection to
169 be copied to the clipboard and then deleted from
173 @editable: a #GtkEditable widget.
176 <!-- ##### FUNCTION gtk_editable_copy_clipboard ##### -->
178 Causes the characters in the current selection to
179 be copied to the clipboard.
182 @editable: a #GtkEditable widget.
185 <!-- ##### FUNCTION gtk_editable_paste_clipboard ##### -->
187 Causes the contents of the clipboard to be pasted into
188 the given widget at the current cursor position.
191 @editable: a #GtkEditable widget.
194 <!-- ##### FUNCTION gtk_editable_delete_selection ##### -->
196 Deletes the current contents of the widgets selection and
197 disclaims the selection.
200 @editable: a #GtkEditable widget.
203 <!-- ##### FUNCTION gtk_editable_set_position ##### -->
205 Sets the cursor position.
208 @editable: a #GtkEditable widget.
209 @position: the position of the cursor. The cursor is displayed
210 before the character with the given (base 0) index
211 in the widget. The value must be less than or
212 equal to the number of characters in the widget.
213 A value of -1 indicates that the position should
214 be set after the last character in the entry.
215 Note that this position is in characters, not in
219 <!-- ##### FUNCTION gtk_editable_get_position ##### -->
221 Retrieves the current cursor position.
224 @editable: a #GtkEditable widget.
225 @Returns: the position of the cursor. The cursor is displayed
226 before the character with the given (base 0) index
227 in the widget. The value will be less than or
228 equal to the number of characters in the widget.
229 Note that this position is in characters, not in
233 <!-- ##### FUNCTION gtk_editable_set_editable ##### -->
235 Determines if the user can edit the text in the editable
239 @editable: a #GtkEditable widget.
240 @is_editable: %TRUE if the user is allowed to edit the text
244 <!-- ##### FUNCTION gtk_editable_get_editable ##### -->
253 <!-- ##### SIGNAL GtkEditable::changed ##### -->
255 Indicates that the user has changed the contents
259 @editable: the object which received the signal.
261 <!-- ##### SIGNAL GtkEditable::delete-text ##### -->
263 This signal is emitted when text is deleted from
264 the widget by the user. The default handler for
265 this signal will normally be responsible for inserting
266 the text, so by connecting to this signal and then
267 stopping the signal with gtk_signal_emit_stop(), it
268 is possible to modify the inserted text, or prevent
269 it from being inserted entirely. The @start_pos
270 and @end_pos parameters are interpreted as for
271 gtk_editable_delete_text()
274 @editable: the object which received the signal.
275 @start_pos: the starting position.
276 @end_pos: the end position.
278 <!-- ##### SIGNAL GtkEditable::insert-text ##### -->
280 This signal is emitted when text is inserted into
281 the widget by the user. The default handler for
282 this signal will normally be responsible for inserting
283 the text, so by connecting to this signal and then
284 stopping the signal with gtk_signal_emit_stop(), it
285 is possible to modify the inserted text, or prevent
286 it from being inserted entirely.
289 @editable: the object which received the signal.
290 @new_text: the new text to insert.
291 @new_text_length: the length of the new text.
292 @position: the position at which to insert the new text.
293 this is an in-out paramter. After the signal
294 emission is finished, it should point after
295 the newly inserted text.