Next: , Previous: GtkSpinButton, Up: Top


25 GtkEditable

Interface for text-editing widgets

25.1 Overview

The <gtk-editable> interface is an interface which should be implemented by text editing widgets, such as <gtk-entry> and <gtk-text>. 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.

     
     #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);
     }

25.2 Usage

— Class: <gtk-editable>

Derives from <ginterface>.

This class defines no direct slots.

— Signal on <gtk-editable>: changed

Indicates that the user has changed the contents of the widget.

— Signal on <gtk-editable>: insert-text (arg0 <gchararray>) (arg1 <gint>) (arg2 <gpointer>)

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.

— Signal on <gtk-editable>: delete-text (arg0 <gint>) (arg1 <gint>)

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 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. The start-pos and end-pos parameters are interpreted as for gtk-editable-delete-text

— Function: gtk-editable-select-region (self <gtk-editable>) (start int) (end int)
— Method: select-region

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 <gtk-editable> widget.
start
the starting position.
end
the end position.
— Function: gtk-editable-get-selection-bounds (self <gtk-editable>) ⇒  (ret bool) (start int) (end int)
— Method: get-selection-bounds

Gets the current selection bounds, if there is a selection.

editable
a <gtk-editable> widget.
start
location to store the starting position, or ‘#f’.
end
location to store the end position, or ‘#f’.
ret
#t’ if there is a selection.
— Function: gtk-editable-insert-text (self <gtk-editable>) (new_text mchars) (position int) ⇒  (ret int)
— Method: insert-text

Inserts text at a given position.

editable
a <gtk-editable> 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.
— Function: gtk-editable-delete-text (self <gtk-editable>) (start_pos int) (end_pos int)
— Method: delete-text

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 <gtk-editable> widget.
start-pos
the starting position.
end-pos
the end position.
— Function: gtk-editable-get-chars (self <gtk-editable>) (start_pos int) (end_pos int) ⇒  (ret mchars)
— Method: get-chars

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 <gtk-editable> widget.
start-pos
the starting position.
end-pos
the end position.
ret
the characters in the indicated region. The result must be freed with g-free when the application is finished with it.
— Function: gtk-editable-cut-clipboard (self <gtk-editable>)
— Method: cut-clipboard

Causes the characters in the current selection to be copied to the clipboard and then deleted from the widget.

editable
a <gtk-editable> widget.
— Function: gtk-editable-copy-clipboard (self <gtk-editable>)
— Method: copy-clipboard

Causes the characters in the current selection to be copied to the clipboard.

editable
a <gtk-editable> widget.
— Function: gtk-editable-paste-clipboard (self <gtk-editable>)
— Method: paste-clipboard

Causes the contents of the clipboard to be pasted into the given widget at the current cursor position.

editable
a <gtk-editable> widget.
— Function: gtk-editable-delete-selection (self <gtk-editable>)
— Method: delete-selection

Deletes the current contents of the widgets selection and disclaims the selection.

editable
a <gtk-editable> widget.
— Function: gtk-editable-set-position (self <gtk-editable>) (position int)
— Method: set-position

Sets the cursor position.

editable
a <gtk-editable> 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.
— Function: gtk-editable-get-position (self <gtk-editable>) ⇒  (ret int)
— Method: get-position

Retrieves the current cursor position.

editable
a <gtk-editable> widget.
ret
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.
— Function: gtk-editable-set-editable (self <gtk-editable>) (is_editable bool)
— Method: set-editable

Determines if the user can edit the text in the editable widget or not.

editable
a <gtk-editable> widget.
is-editable
#t’ if the user is allowed to edit the text in the widget.
— Function: gtk-editable-get-editable (self <gtk-editable>) ⇒  (ret bool)
— Method: get-editable

Retrieves whether editable is editable. See gtk-editable-set-editable.

editable
a <gtk-editable>
ret
#t’ if editable is editable.