GTK+ Reference Manual | ||||
---|---|---|---|---|
#include <gtk/gtk.h> GtkEditable; void gtk_editable_select_region (GtkEditable *editable, gint start, gint end); gboolean gtk_editable_get_selection_bounds (GtkEditable *editable, gint *start, gint *end); void gtk_editable_insert_text (GtkEditable *editable, const gchar *new_text, gint new_text_length, gint *position); void gtk_editable_delete_text (GtkEditable *editable, gint start_pos, gint end_pos); gchar* gtk_editable_get_chars (GtkEditable *editable, gint start_pos, gint end_pos); void gtk_editable_cut_clipboard (GtkEditable *editable); void gtk_editable_copy_clipboard (GtkEditable *editable); void gtk_editable_paste_clipboard (GtkEditable *editable); void gtk_editable_delete_selection (GtkEditable *editable); void gtk_editable_set_position (GtkEditable *editable, gint position); gint gtk_editable_get_position (GtkEditable *editable); void gtk_editable_set_editable (GtkEditable *editable, gboolean is_editable); gboolean gtk_editable_get_editable (GtkEditable *editable);
GtkEditable is implemented by GtkEntry, GtkText, GtkOldEditable and GtkSpinButton.
The GtkEditable interface is an interface which should be implemented by text editing widgets, such as GtkEntry and GtkText. It 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.
Example 16. 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_utf8_strup (text, length); g_signal_handlers_block_by_func (editable, (gpointer) insert_text_handler, data); gtk_editable_insert_text (editable, result, length, position); g_signal_handlers_unblock_by_func (editable, (gpointer) insert_text_handler, data); g_signal_stop_emission_by_name (editable, "insert_text"); g_free (result); }
typedef struct _GtkEditable GtkEditable;
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. |
void gtk_editable_select_region (GtkEditable *editable, gint start, gint end);
Selects the text between start
and end
. Both start
and end
are
relative to the start of the content. Note that positions are specified
in characters, not bytes.
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 |
start : |
start of region |
end : |
end of region |
gboolean gtk_editable_get_selection_bounds (GtkEditable *editable, gint *start, gint *end);
Retrieves the selection bound of the editable. start_pos
will be filled
with the start of the selection and end_pos
with end. If no text was selected
both will be identical and FALSE
will be returned. Note that positions are
specified in characters, not bytes.
Gets the current selection bounds, if there is a selection.
editable : |
a GtkEditable |
start : |
location to store the starting position, or NULL .
|
end : |
location to store the end position, or NULL .
|
Returns : | TRUE if an area is selected, FALSE otherwise
|
void gtk_editable_insert_text (GtkEditable *editable, const gchar *new_text, gint new_text_length, gint *position);
Appends new_text_length
characters of new_text
to the contents of the widget,
at position position
. Note that this position is in characters, not in bytes.
Inserts text at a given position.
editable : |
a GtkEditable |
new_text : |
the text to append |
new_text_length : |
the text to append |
position : |
position text will be inserted at |
void gtk_editable_delete_text (GtkEditable *editable, gint start_pos, gint end_pos);
Deletes the content of the editable between start_pos
and end_pos
.
Note that positions are specified in characters, not bytes.
Deletes 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 |
start_pos : |
start position |
end_pos : |
end position |
gchar* gtk_editable_get_chars (GtkEditable *editable, gint start_pos, gint end_pos);
Retreives the content of the editable between start
and end
.
Note that positions are specified in characters, not bytes.
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 |
start_pos : |
the starting position. |
end_pos : |
the end position. |
Returns : | a pointer to the contents of the widget as a string. This string is allocated by the GtkEditable implementation and should be freed by the caller. |
void gtk_editable_cut_clipboard (GtkEditable *editable);
Removes the contents of the currently selected content in the editable and puts it on the clipboard.
Causes the characters in the current selection to be copied to the clipboard and then deleted from the widget.
editable : |
a GtkEditable |
void gtk_editable_copy_clipboard (GtkEditable *editable);
Copies the contents of the currently selected content in the editable and puts it on the clipboard.
Causes the characters in the current selection to be copied to the clipboard.
editable : |
a GtkEditable |
void gtk_editable_paste_clipboard (GtkEditable *editable);
Pastes the content of the clipboard to the current position of the cursor in the editable.
Causes the contents of the clipboard to be pasted into the given widget at the current cursor position.
editable : |
a GtkEditable |
void gtk_editable_delete_selection (GtkEditable *editable);
Deletes the currently selected text of the editable. This call will not do anything if there is no selected text.
Deletes the current contents of the widgets selection and disclaims the selection.
editable : |
a GtkEditable |
void gtk_editable_set_position (GtkEditable *editable, gint position);
Sets the cursor position in the editable to the given value.
Sets the cursor position.
editable : |
a GtkEditable |
position : |
the position of the cursor. The cursor is displayed before the character with the given (base 0) index in the editable. The value must be less than or equal to the number of characters in the editable. A value of -1 indicates that the position should be set after the last character of the editable. Note that this position is in characters, not in bytes. |
gint gtk_editable_get_position (GtkEditable *editable);
Retrieves the current position of the cursor relative to the start of the content of the editable. Note that this position is in characters, not in bytes.
Retrieves the current cursor position.
editable : |
a GtkEditable |
Returns : | the cursor position |
void gtk_editable_set_editable (GtkEditable *editable, gboolean is_editable);
Determines if the user can edit the text in the editable widget or not.
Determines if the user can edit the text in the editable widget or not.
editable : |
a GtkEditable |
is_editable : |
TRUE if the user is allowed to edit the text
in the widget
|
gboolean gtk_editable_get_editable (GtkEditable *editable);
Retrieves whether editable
is editable. See
gtk_editable_set_editable()
.
editable : |
a GtkEditable |
Returns : | TRUE if editable is editable.
|
"changed"
signalvoid user_function (GtkEditable *editable, gpointer user_data) : Run Last
Indicates that the user has changed the contents of the widget.
editable : |
the object which received the signal. |
user_data : |
user data set when the signal handler was connected. |
"delete-text"
signalvoid user_function (GtkEditable *editable, gint start_pos, gint end_pos, gpointer user_data) : Run Last
This signal is emitted when text is deleted from
the widget by the user. The default handler for
this signal will normally be responsible for deleting
the text, so by connecting to this signal and then
stopping the signal with gtk_signal_emit_stop()
, it
is possible to modify the range of deleted text, or
prevent it from being deleted entirely. The start_pos
and end_pos
parameters are interpreted as for
gtk_editable_delete_text()
editable : |
the object which received the signal. |
start_pos : |
the starting position. |
end_pos : |
the end position. |
user_data : |
user data set when the signal handler was connected. |
"insert-text"
signalvoid user_function (GtkEditable *editable, gchar *new_text, gint new_text_length, gint *position, gpointer user_data) : Run Last
This signal is emitted when text is inserted into
the widget by the user. The default handler for
this signal will normally be responsible for inserting
the text, so by connecting to this signal and then
stopping the signal with gtk_signal_emit_stop()
, it
is possible to modify the inserted text, or prevent
it from being inserted entirely.
editable : |
the object which received the signal. |
new_text : |
the new text to insert. |
new_text_length : |
the length of the new text, in bytes, or -1 if new_text is nul-terminated |
position : |
the position, in characters, at which to insert the new text. this is an in-out parameter. After the signal emission is finished, it should point after the newly inserted text. |
user_data : |
user data set when the signal handler was connected. |