1 <!-- ##### SECTION Title ##### -->
4 <!-- ##### SECTION Short_Description ##### -->
5 Interface for text-editing widgets.
7 <!-- ##### SECTION Long_Description ##### -->
9 The #GtkEditable interface is an interface which should be implemented by
10 text editing widgets, such as #GtkEntry and #GtkText. It contains functions
11 for generically manipulating an editable widget, a large number of action
12 signals used for key bindings, and several signals that an application can
13 connect to to modify the behavior of a widget.
17 As an example of the latter usage, by connecting
18 the following handler to "insert_text", an application
19 can convert all entry into a widget into uppercase.
22 <title>Forcing entry to uppercase.</title>
24 #include <ctype.h>
27 insert_text_handler (GtkEditable *editable,
34 gchar *result = g_new (gchar, length);
36 for (i = 0; i < length; i++)
37 result[i] = islower (text[i]) ? toupper (text[i]) : text[i];
39 g_signal_handlers_block_by_func (GTK_OBJECT (editable),
40 insert_text_handler, data);
41 gtk_editable_insert_text (editable, result, length, position);
42 g_signal_handlers_unblock_by_func (GTK_OBJECT (editable),
43 insert_text_handler, data);
45 g_signal_stop_emission_by_name (GTK_OBJECT (editable), "insert_text");
53 <!-- ##### SECTION See_Also ##### -->
58 <!-- ##### STRUCT GtkEditable ##### -->
60 The #GtkEditable structure contains the following fields.
61 (These fields should be considered read-only. They should
62 never be set by an application.)
64 <informaltable pgwide="1" frame="none" role="struct">
65 <tgroup cols="2"><colspec colwidth="2*"/><colspec colwidth="8*"/>
69 <entry>#guint selection_start;</entry>
70 <entry>the starting position of the selected characters
71 in the widget.</entry>
75 <entry>#guint selection_end;</entry>
76 <entry>the end position of the selected characters
77 in the widget.</entry>
81 <entry>#guint editable;</entry>
82 <entry>a flag indicating whether or not the widget is
83 editable by the user.</entry>
86 </tbody></tgroup></informaltable>
90 <!-- ##### FUNCTION gtk_editable_select_region ##### -->
92 Selects a region of text. The characters that
93 are selected are those characters at positions from
94 @start_pos up to, but not including @end_pos. If
95 @end_pos is negative, then the the characters selected
96 will be those characters from @start_pos to the end
100 @editable: a #GtkEditable widget.
101 @start: the starting position.
102 @end: the end position.
105 <!-- ##### FUNCTION gtk_editable_get_selection_bounds ##### -->
107 Gets the current selection bounds, if there is a selection.
110 @editable: a #GtkEditable widget.
111 @start: location to store the starting position, or %NULL.
112 @end: location to store the end position, or %NULL.
113 @Returns: %TRUE if there is a selection.
116 <!-- ##### FUNCTION gtk_editable_insert_text ##### -->
118 Inserts text at a given position.
121 @editable: a #GtkEditable widget.
122 @new_text: the text to insert.
123 @new_text_length: the length of the text to insert, in bytes
124 @position: an inout parameter. The caller initializes it to
125 the position at which to insert the text. After the
126 call it points at the position after the newly
130 <!-- ##### FUNCTION gtk_editable_delete_text ##### -->
132 Deletes a sequence of characters. The characters that
133 are deleted are those characters at positions from
134 @start_pos up to, but not including @end_pos. If
135 @end_pos is negative, then the the characters deleted
136 will be those characters from @start_pos to the end
140 @editable: a #GtkEditable widget.
141 @start_pos: the starting position.
142 @end_pos: the end position.
145 <!-- ##### FUNCTION gtk_editable_get_chars ##### -->
147 Retrieves a sequence of characters. The characters that
148 are retrieved are those characters at positions from
149 @start_pos up to, but not including @end_pos. If
150 @end_pos is negative, then the the characters retrieved
151 will be those characters from @start_pos to the end
155 @editable: a #GtkEditable widget.
156 @start_pos: the starting position.
157 @end_pos: the end position.
158 @Returns: the characters in the indicated region.
159 The result must be freed with g_free() when
160 the application is finished with it.
163 <!-- ##### FUNCTION gtk_editable_cut_clipboard ##### -->
165 Causes the characters in the current selection to
166 be copied to the clipboard and then deleted from
170 @editable: a #GtkEditable widget.
173 <!-- ##### FUNCTION gtk_editable_copy_clipboard ##### -->
175 Causes the characters in the current selection to
176 be copied to the clipboard.
179 @editable: a #GtkEditable widget.
182 <!-- ##### FUNCTION gtk_editable_paste_clipboard ##### -->
184 Causes the contents of the clipboard to be pasted into
185 the given widget at the current cursor position.
188 @editable: a #GtkEditable widget.
191 <!-- ##### FUNCTION gtk_editable_delete_selection ##### -->
193 Deletes the current contents of the widgets selection and
194 disclaims the selection.
197 @editable: a #GtkEditable widget.
200 <!-- ##### FUNCTION gtk_editable_set_position ##### -->
202 Sets the cursor position.
205 @editable: a #GtkEditable widget.
206 @position: the position of the cursor. The cursor is displayed
207 before the character with the given (base 0) index
208 in the widget. The value must be less than or
209 equal to the number of characters in the widget.
210 A value of -1 indicates that the position should
211 be set after the last character in the entry.
212 Note that this position is in characters, not in
216 <!-- ##### FUNCTION gtk_editable_get_position ##### -->
218 Retrieves the current cursor position.
221 @editable: a #GtkEditable widget.
222 @Returns: the position of the cursor. The cursor is displayed
223 before the character with the given (base 0) index
224 in the widget. The value will be less than or
225 equal to the number of characters in the widget.
226 Note that this position is in characters, not in
230 <!-- ##### FUNCTION gtk_editable_set_editable ##### -->
232 Determines if the user can edit the text in the editable
236 @editable: a #GtkEditable widget.
237 @is_editable: %TRUE if the user is allowed to edit the text
241 <!-- ##### FUNCTION gtk_editable_get_editable ##### -->
250 <!-- ##### SIGNAL GtkEditable::changed ##### -->
252 Indicates that the user has changed the contents
256 @editable: the object which received the signal.
258 <!-- ##### SIGNAL GtkEditable::delete-text ##### -->
260 This signal is emitted when text is deleted from
261 the widget by the user. The default handler for
262 this signal will normally be responsible for inserting
263 the text, so by connecting to this signal and then
264 stopping the signal with gtk_signal_emit_stop(), it
265 is possible to modify the inserted text, or prevent
266 it from being inserted entirely. The @start_pos
267 and @end_pos parameters are interpreted as for
268 gtk_editable_delete_text()
271 @editable: the object which received the signal.
272 @start_pos: the starting position.
273 @end_pos: the end position.
275 <!-- ##### SIGNAL GtkEditable::insert-text ##### -->
277 This signal is emitted when text is inserted into
278 the widget by the user. The default handler for
279 this signal will normally be responsible for inserting
280 the text, so by connecting to this signal and then
281 stopping the signal with gtk_signal_emit_stop(), it
282 is possible to modify the inserted text, or prevent
283 it from being inserted entirely.
286 @editable: the object which received the signal.
287 @new_text: the new text to insert.
288 @new_text_length: the length of the new text.
289 @position: the position at which to insert the new text.
290 this is an in-out paramter. After the signal
291 emission is finished, it should point after
292 the newly inserted text.