The Gtk.Editable.Gtk_Editable interface is an interface which should be implemented by text editing widgets, such as Gtk.GEntry.Gtk_Entry and Gtk.Spin_Button.Gtk_Spin_Button. 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 Gtk.Editable.Gtk_Editable::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)
{
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);
}
function "+" (W : Gtk_Editable) return Gtk_Editable
type Cb_GObject_Gint_Gint_Void is not null access procedure
(Self : access Glib.Object.GObject_Record'Class;
Start_Pos : Glib.Gint;
End_Pos : Glib.Gint);
type Cb_GObject_UTF8_String_Gint_Gint_Void is not null access procedure
(Self : access Glib.Object.GObject_Record'Class;
New_Text : UTF8_String;
New_Text_Length : Glib.Gint;
Position : access Glib.Gint);
type Cb_GObject_Void is not null access procedure
(Self : access Glib.Object.GObject_Record'Class);
type Cb_Gtk_Editable_Gint_Gint_Void is not null access procedure
(Self : Gtk_Editable;
Start_Pos : Glib.Gint;
End_Pos : Glib.Gint);
type Cb_Gtk_Editable_UTF8_String_Gint_Gint_Void is not null access procedure
(Self : Gtk_Editable;
New_Text : UTF8_String;
New_Text_Length : Glib.Gint;
Position : access Glib.Gint);
type Cb_Gtk_Editable_Void is not null access procedure (Self : Gtk_Editable);
procedure Copy_Clipboard (Editable : Gtk_Editable)
Copies the contents of the currently selected content in the editable and puts it on the clipboard.
procedure Cut_Clipboard (Editable : Gtk_Editable)
Removes the contents of the currently selected content in the editable and puts it on the clipboard.
procedure Delete_Selection (Editable : Gtk_Editable)
Deletes the currently selected text of the editable. This call doesn't do anything if there is no selected text.
procedure Delete_Text
(Editable : Gtk_Editable;
Start_Pos : Glib.Gint;
End_Pos : Glib.Gint := -1)
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 characters deleted are those from Start_Pos to the end of the text. Note that the positions are specified in characters, not bytes.
start position
end position
subtype Editable_Interface_Descr is Glib.Object.Interface_Description;
function Get_Chars
(Editable : Gtk_Editable;
Start_Pos : Glib.Gint;
End_Pos : Glib.Gint := -1) return UTF8_String
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 characters retrieved are those characters from Start_Pos to the end of the text. Note that positions are specified in characters, not bytes.
start of text
end of text
a pointer to the contents of the widget as a string. This string is allocated by the Gtk.Editable.Gtk_Editable implementation and should be freed by the caller.
function Get_Editable (Editable : Gtk_Editable) return Boolean
Retrieves whether Editable is editable. See Gtk.Editable.Set_Editable.
True if Editable is editable.
function Get_Position (Editable : Gtk_Editable) return Glib.Gint
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.
the cursor position
procedure Get_Selection_Bounds
(Editable : Gtk_Editable;
Start_Pos : out Glib.Gint;
End_Pos : out Glib.Gint;
Has_Selection : out Boolean)
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.
location to store the starting position, or null
location to store the end position, or null @return True if an area is selected, False otherwise
function Get_Type return Glib.GType
type Gtk_Editable is new Glib.Types.GType_Interface;
procedure Insert_Text
(Editable : Gtk_Editable;
New_Text : UTF8_String;
Position : in out Gint)
Convenience subprogram, identical to Insert_Text above without the requirement to supply the New_Text_Length argument.
procedure Insert_Text
(Editable : Gtk_Editable;
New_Text : UTF8_String;
New_Text_Length : Glib.Gint;
Position : in out Glib.Gint)
Inserts New_Text_Length bytes of New_Text into the contents of the widget, at position Position. Note that the position is in characters, not in bytes. The function updates Position to point after the newly inserted text.
the text to append
the length of the text in bytes, or -1
location of the position text will be inserted at
Null_Gtk_Editable : constant Gtk_Editable;
procedure On_Changed
(Self : Gtk_Editable;
Call : Cb_GObject_Void;
Slot : not null access Glib.Object.GObject_Record'Class;
After : Boolean := False)
The ::changed signal is emitted at the end of a single user-visible operation on the contents of the Gtk.Editable.Gtk_Editable.
E.g., a paste operation that replaces the contents of the selection will cause only one signal emission (even though it is implemented by first deleting the selection, then inserting the new content, and may cause multiple ::notify::text signals to be emitted).
procedure On_Changed
(Self : Gtk_Editable;
Call : Cb_Gtk_Editable_Void;
After : Boolean := False)
The ::changed signal is emitted at the end of a single user-visible operation on the contents of the Gtk.Editable.Gtk_Editable.
E.g., a paste operation that replaces the contents of the selection will cause only one signal emission (even though it is implemented by first deleting the selection, then inserting the new content, and may cause multiple ::notify::text signals to be emitted).
procedure On_Delete_Text
(Self : Gtk_Editable;
Call : Cb_GObject_Gint_Gint_Void;
Slot : not null access Glib.Object.GObject_Record'Class;
After : Boolean := False)
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 g_signal_stop_emission, 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.
Callback parameters: -- @param Start_Pos the starting position -- @param End_Pos the end position
procedure On_Delete_Text
(Self : Gtk_Editable;
Call : Cb_Gtk_Editable_Gint_Gint_Void;
After : Boolean := False)
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 g_signal_stop_emission, 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.
Callback parameters: -- @param Start_Pos the starting position -- @param End_Pos the end position
procedure On_Insert_Text
(Self : Gtk_Editable;
Call : Cb_GObject_UTF8_String_Gint_Gint_Void;
Slot : not null access Glib.Object.GObject_Record'Class;
After : Boolean := False)
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 g_signal_stop_emission, it is possible to modify the inserted text, or prevent it from being inserted entirely.
Callback parameters: -- @param New_Text the new text to insert -- @param New_Text_Length the length of the new text, in bytes, or -1 if -- new_text is nul-terminated -- @param 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.
procedure On_Insert_Text
(Self : Gtk_Editable;
Call : Cb_Gtk_Editable_UTF8_String_Gint_Gint_Void;
After : Boolean := False)
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 g_signal_stop_emission, it is possible to modify the inserted text, or prevent it from being inserted entirely.
Callback parameters: -- @param New_Text the new text to insert -- @param New_Text_Length the length of the new text, in bytes, or -1 if -- new_text is nul-terminated -- @param 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.
procedure Paste_Clipboard (Editable : Gtk_Editable)
Pastes the content of the clipboard to the current position of the cursor in the editable.
procedure Select_Region
(Editable : Gtk_Editable;
Start_Pos : Glib.Gint;
End_Pos : Glib.Gint := -1)
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 characters selected are those characters from Start_Pos to the end of the text. Note that positions are specified in characters, not bytes.
start of region
end of region
procedure Set_Changed
(Self : Editable_Interface_Descr;
Handler : Virtual_Changed)
procedure Set_Delete_Text
(Self : Editable_Interface_Descr;
Handler : Virtual_Delete_Text)
procedure Set_Do_Delete_Text
(Self : Editable_Interface_Descr;
Handler : Virtual_Do_Delete_Text)
procedure Set_Do_Insert_Text
(Self : Editable_Interface_Descr;
Handler : Virtual_Do_Insert_Text)
procedure Set_Editable (Editable : Gtk_Editable; Is_Editable : Boolean)
Determines if the user can edit the text in the editable widget or not.
True if the user is allowed to edit the text in the widget
procedure Set_Get_Chars
(Self : Editable_Interface_Descr;
Handler : Virtual_Get_Chars)
procedure Set_Get_Position
(Self : Editable_Interface_Descr;
Handler : Virtual_Get_Position)
procedure Set_Get_Selection_Bounds
(Self : Editable_Interface_Descr;
Handler : Virtual_Get_Selection_Bounds)
procedure Set_Insert_Text
(Self : Editable_Interface_Descr;
Handler : Virtual_Insert_Text)
procedure Set_Position (Editable : Gtk_Editable; Position : Glib.Gint)
Sets the cursor position in the editable to the given value. The cursor is displayed before the character with the given (base 0) index in the contents of 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 Position is in characters, not in bytes.
the position of the cursor
procedure Set_Set_Position
(Self : Editable_Interface_Descr;
Handler : Virtual_Set_Position)
procedure Set_Set_Selection_Bounds
(Self : Editable_Interface_Descr;
Handler : Virtual_Set_Selection_Bounds)
See Glib.Object.Add_Interface
Signal_Changed : constant Glib.Signal_Name := "changed";
The ::changed signal is emitted at the end of a single user-visible operation on the contents of the Gtk.Editable.Gtk_Editable.
E.g., a paste operation that replaces the contents of the selection will cause only one signal emission (even though it is implemented by first deleting the selection, then inserting the new content, and may cause multiple ::notify::text signals to be emitted).
Signal_Delete_Text : constant Glib.Signal_Name := "delete-text";
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 g_signal_stop_emission, 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.
Callback parameters: -- @param Start_Pos the starting position -- @param End_Pos the end position
Signal_Insert_Text : constant Glib.Signal_Name := "insert-text";
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 g_signal_stop_emission, it is possible to modify the inserted text, or prevent it from being inserted entirely.
Callback parameters: -- @param New_Text the new text to insert -- @param New_Text_Length the length of the new text, in bytes, or -1 if -- new_text is nul-terminated -- @param 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.
type Virtual_Changed is access procedure (Editable : Gtk_Editable);
type Virtual_Delete_Text is access procedure
(Editable : Gtk_Editable;
Start_Pos : Glib.Gint;
End_Pos : Glib.Gint);
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 characters deleted are those from Start_Pos to the end of the text. Note that the positions are specified in characters, not bytes.
start position
end position
type Virtual_Do_Delete_Text is access procedure
(Editable : Gtk_Editable;
Start_Pos : Glib.Gint;
End_Pos : Glib.Gint);
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 characters deleted are those from Start_Pos to the end of the text. Note that the positions are specified in characters, not bytes.
start position
end position
type Virtual_Do_Insert_Text is access procedure
(Editable : Gtk_Editable;
New_Text : Gtkada.Types.Chars_Ptr;
New_Text_Length : Glib.Gint;
Position : in out Glib.Gint);
Inserts New_Text_Length bytes of New_Text into the contents of the widget, at position Position. Note that the position is in characters, not in bytes. The function updates Position to point after the newly inserted text.
the text to append
the length of the text in bytes, or -1
location of the position text will be inserted at
type Virtual_Get_Chars is access function
(Editable : Gtk_Editable;
Start_Pos : Glib.Gint;
End_Pos : Glib.Gint) return Gtkada.Types.Chars_Ptr;
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 characters retrieved are those characters from Start_Pos to the end of the text. Note that positions are specified in characters, not bytes.
start of text
end of text
a pointer to the contents of the widget as a string. This string is allocated by the Gtk.Editable.Gtk_Editable implementation and should be freed by the caller.
type Virtual_Get_Position is access function (Editable : Gtk_Editable) return Glib.Gint;
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.
the cursor position
type Virtual_Get_Selection_Bounds is access function
(Editable : Gtk_Editable;
Start_Pos : access Glib.Gint;
End_Pos : access Glib.Gint) return Glib.Gboolean;
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.
location to store the starting position, or null
location to store the end position, or null
True if an area is selected, False otherwise
type Virtual_Insert_Text is access procedure
(Editable : Gtk_Editable;
New_Text : Gtkada.Types.Chars_Ptr;
New_Text_Length : Glib.Gint;
Position : in out Glib.Gint);
Inserts New_Text_Length bytes of New_Text into the contents of the widget, at position Position. Note that the position is in characters, not in bytes. The function updates Position to point after the newly inserted text.
the text to append
the length of the text in bytes, or -1
location of the position text will be inserted at
type Virtual_Set_Position is access procedure (Editable : Gtk_Editable; Position : Glib.Gint);
Sets the cursor position in the editable to the given value. The cursor is displayed before the character with the given (base 0) index in the contents of 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 Position is in characters, not in bytes.
the position of the cursor
type Virtual_Set_Selection_Bounds is access procedure
(Editable : Gtk_Editable;
Start_Pos : Glib.Gint;
End_Pos : Glib.Gint);
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 characters selected are those characters from Start_Pos to the end of the text. Note that positions are specified in characters, not bytes.
start of region
end of region