GtkEditable
Base class for text-editing widgets.
The #GtkEditable class is a base class for widgets
for editing text, such as #GtkEntry and #GtkText. It
cannot be instantiated by itself. The editable
class contains functions for generically manipulating
an editable widget, a large number of action signals
used for key bindings, and several signals that
an application can connect to to modify the behavior
of a widget.
As an example of the latter usage, by connecting
the following handler to "insert_text", an application
can convert all entry into a widget into uppercase.
Forcing entry to uppercase
#include <ctype.h>
void
insert_text_handler (GtkEditable *editable,
const gchar *text,
gint length,
gint *position,
gpointer data)
{
int i;
gchar *result = g_new (gchar, length);
for (i=0; i<length; i++)
result[i] = islower(text[i]) ? toupper(text[i]) : text[i];
gtk_signal_handler_block_by_func (GTK_OBJECT (editable),
GTK_SIGNAL_FUNC (insert_text_handler),
data);
gtk_editable_insert_text (editable, result, length, position);
gtk_signal_handler_unblock_by_func (GTK_OBJECT (editable),
GTK_SIGNAL_FUNC (insert_text_handler),
data);
gtk_signal_emit_stop_by_name (GTK_OBJECT (editable), "insert_text");
g_free (result);
}
The #GtkEditable structure contains the following fields.
(These fields should be considered read-only. They should
never be set by an application.)
#guint selection_start;
the starting position of the selected characters
in the widget.
#guint selection_end;
the end position of the selected characters
in the widget.
#guint editable;
a flag indicating whether or not the widget is
editable by the user.
Selects a region of text. The characters that
are selected are those characters at positions from
@start_pos up to, but not including @end_pos. If
@end_pos is negative, then the the characters selected
will be those characters from @start_pos to the end
of the text.
@editable: a #GtkEditable widget.
@start: the starting position.
@end: the end position.
@editable:
@start:
@end:
@Returns:
Insert text at a given position.
@editable: a #GtkEditable widget.
@new_text: the text to insert.
@new_text_length: the length of the text to insert, in bytes
@position: an inout parameter. The caller initializes it to
the position at which to insert the text. After the
call it points at the position after the newly
inserted text.
Delete a sequence of characters. The characters that
are deleted are those characters at positions from
@start_pos up to, but not including @end_pos. If
@end_pos is negative, then the the characters deleted
will be those characters from @start_pos to the end
of the text.
@editable: a #GtkEditable widget.
@start_pos: the starting position.
@end_pos: the end position.
Retrieves a sequence of characters. The characters that
are retrieved are those characters at positions from
@start_pos up to, but not including @end_pos. If
@end_pos is negative, then the the characters retrieved
will be those characters from @start_pos to the end
of the text.
@editable: a #GtkEditable widget.
@start_pos: the starting position.
@end_pos: the end position.
@Returns: the characters in the indicated region.
The result must be freed with g_free() when
the application is finished with it.
Causes the characters in the current selection to
be copied to the clipboard and then deleted from
the widget.
@editable: a #GtkEditable widget.
Causes the characters in the current selection to
be copied to the clipboard.
@editable: a #GtkEditable widget.
Causes the contents of the clipboard to be pasted into
the given widget at the current cursor position.
@editable: a #GtkEditable widget.
Deletes the current contents of the widgets selection and
disclaims the selection.
@editable: a #GtkEditable widget.
Sets the cursor position.
@editable: a #GtkEditable widget.
@position: the position of the cursor. The cursor is displayed
before the character with the given (base 0) index
in the widget. The value must be less than or
equal to the number of characters in the widget.
A value of -1 indicates that the position should
be set after the last character in the entry.
Note that this position is in characters, not in
bytes.
Retrieves the current cursor position.
@editable: a #GtkEditable widget.
@Returns: the position of the cursor. The cursor is displayed
before the character with the given (base 0) index
in the widget. The value will be less than or
equal to the number of characters in the widget.
Note that this position is in characters, not in
bytes.
Determines if the user can edit the text in the editable
widget or not.
@editable: a #GtkEditable widget.
@is_editable: %TRUE if the user is allowed to edit the text
in the widget.