gtkmm: Gtk::Editable Class Reference

gtkmm 4.16.0

Public Member Functions | Static Public Member Functions | Protected Member Functions | Related Symbols | List of all members
Gtk::Editable Class Reference

Base class for text-editing widgets. More...

`#include <gtkmm/editable.h>`

Inheritance diagram for Gtk::Editable:
[legend]

## Public Member Functions
| Editable (Editable && src) noexcept
Editable & | operator= (Editable && src) noexcept
| ~Editable () noexcept override
GtkEditable * | gobj ()
| Provides access to the underlying C GObject.
const GtkEditable * | gobj () const
| Provides access to the underlying C GObject.
Glib::ustring | get_text () const
| Retrieves the contents of editable.
void | set_text (const Glib::ustring & text)
| Sets the text in the editable to the given value.
void | delete_selection ()
| Deletes the currently selected text of the editable.
void | set_editable (bool is_editable=true)
| Determines if the user can edit the text in the editable widget.
bool | get_editable () const
| Retrieves whether editable is editable.
void | insert_text (const Glib::ustring & new_text, int new_text_length, int & position)
| Inserts new_text_length bytes of new_text into the contents of the widget, at position position.
void | delete_text (int start_pos, int end_pos)
| Deletes a sequence of characters.
Glib::ustring | get_chars (int start_pos, int end_pos) const
| Retrieves a sequence of characters.
void | select_region (int start_pos, int end_pos)
| Selects a region of text.
bool | get_selection_bounds (int & start_pos, int & end_pos) const
| Retrieves the selection bound of the editable.
void | set_position (int position)
| Sets the cursor position in the editable to the given value.
int | get_position () const
| Retrieves the current position of the cursor relative to the start of the content of the editable.
float | get_alignment () const
| Gets the alignment of the editable.
void | set_alignment (float xalign)
| Sets the alignment for the contents of the editable.
int | get_width_chars () const
| Gets the number of characters of space reserved for the contents of the editable.
void | set_width_chars (int n_chars)
| Changes the size request of the editable to be about the right size for n_chars characters.
int | get_max_width_chars () const
| Retrieves the desired maximum width of editable, in characters.
void | set_max_width_chars (int n_chars)
| Sets the desired maximum width in characters of editable.
bool | get_enable_undo () const
| Gets if undo/redo actions are enabled for editable.
void | set_enable_undo (bool enable_undo=true)
| If enabled, changes to editable will be saved for undo/redo actions.
Glib::SignalProxy< void(const Glib::ustring &, int *)> | signal_insert_text ()
Glib::SignalProxy< void(int, int)> | signal_delete_text ()
Glib::SignalProxy< void()> | signal_changed ()
Glib::PropertyProxy< Glib::ustring > | property_text ()
| The contents of the entry.
Glib::PropertyProxy_ReadOnly< Glib::ustring > | property_text () const
| The contents of the entry.
Glib::PropertyProxy_ReadOnly< int > | property_cursor_position () const
| The current position of the insertion cursor in chars.
Glib::PropertyProxy< bool > | property_enable_undo ()
| If undo/redo should be enabled for the editable.
Glib::PropertyProxy_ReadOnly< bool > | property_enable_undo () const
| If undo/redo should be enabled for the editable.
Glib::PropertyProxy_ReadOnly< int > | property_selection_bound () const
| The position of the opposite end of the selection from the cursor in chars.
Glib::PropertyProxy< bool > | property_editable ()
| Whether the entry contents can be edited.
Glib::PropertyProxy_ReadOnly< bool > | property_editable () const
| Whether the entry contents can be edited.
Glib::PropertyProxy< int > | property_width_chars ()
| Number of characters to leave space for in the entry.
Glib::PropertyProxy_ReadOnly< int > | property_width_chars () const
| Number of characters to leave space for in the entry.
Glib::PropertyProxy< int > | property_max_width_chars ()
| The desired maximum width of the entry, in characters.
Glib::PropertyProxy_ReadOnly< int > | property_max_width_chars () const
| The desired maximum width of the entry, in characters.
Glib::PropertyProxy< float > | property_xalign ()
| The horizontal alignment, from 0 (left) to 1 (right).
Glib::PropertyProxy_ReadOnly< float > | property_xalign () const
| The horizontal alignment, from 0 (left) to 1 (right).
Public Member Functions inherited from Glib::Interface
| Interface ()
| Interface (Interface &&src) noexcept
Interface & | operator= (Interface &&src) noexcept
| Interface (const Glib::Interface_Class &interface_class)
| Interface (GObject *castitem)
| ~Interface () noexcept override
| Interface (const Interface &)=delete
Interface & | operator= (const Interface &)=delete
GObject * | gobj ()
const GObject * | gobj () const
Public Member Functions inherited from Glib::ObjectBase
| ObjectBase (const ObjectBase &)=delete
ObjectBase & | operator= (const ObjectBase &)=delete
void | set_property_value (const Glib::ustring &property_name, const Glib::ValueBase &value)
void | get_property_value (const Glib::ustring &property_name, Glib::ValueBase &value) const
void | set_property (const Glib::ustring &property_name, const PropertyType &value)
void | get_property (const Glib::ustring &property_name, PropertyType &value) const
PropertyType | get_property (const Glib::ustring &property_name) const
sigc::connection | connect_property_changed (const Glib::ustring &property_name, const sigc::slot< void()> &slot)
sigc::connection | connect_property_changed (const Glib::ustring &property_name, sigc::slot< void()> &&slot)
void | freeze_notify ()
void | thaw_notify ()
virtual void | reference () const
virtual void | unreference () const
GObject * | gobj ()
const GObject * | gobj () const
GObject * | gobj_copy () const

## Static Public Member Functions
static void | add_interface (GType gtype_implementer)
static GType | get_type ()
| Get the GType for this class, for use with the underlying GObject type system.

## Protected Member Functions
| Editable ()
| You should derive from this class to use it.
virtual void | delete_text_vfunc (int start_pos, int end_pos)
virtual Glib::ustring | get_text_vfunc () const
virtual void | select_region_vfunc (int start_pos, int end_pos)
virtual bool | get_selection_bounds_vfunc (int & start_pos, int & end_pos) const
virtual void | insert_text_vfunc (const Glib::ustring & text, int & position)
virtual void | on_insert_text (const Glib::ustring & text, int * position)
| This is a default handler for the signal signal_insert_text().
virtual void | on_delete_text (int start_pos, int end_pos)
| This is a default handler for the signal signal_delete_text().
virtual void | on_changed ()
| This is a default handler for the signal signal_changed().
Protected Member Functions inherited from Glib::ObjectBase
| ObjectBase ()
| ObjectBase (const char *custom_type_name)
| ObjectBase (const std::type_info &custom_type_info)
| ObjectBase (ObjectBase &&src) noexcept
ObjectBase & | operator= (ObjectBase &&src) noexcept
virtual | ~ObjectBase () noexcept=0
void | initialize (GObject *castitem)
void | initialize_move (GObject *castitem, Glib::ObjectBase *previous_wrapper)

## Related Symbols
(Note that these are not member symbols.)
Glib::RefPtr< Gtk::Editable > | wrap (GtkEditable * object, bool take_copy=false)
| A Glib::wrap() method for this object.

## Detailed Description

Base class for text-editing widgets.

The Gtk::Editable class is a base class for widgets for editing text, such as Gtk::Entry. 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.

## Constructor & Destructor Documentation

## ◆ Editable() [1/2]

Gtk::Editable::Editable | ( |  | ) |
| protected

You should derive from this class to use it.

## ◆ Editable() [2/2]

Gtk::Editable::Editable | ( | Editable && | src | ) |
| noexcept

## ◆ ~Editable()

Gtk::Editable::~Editable | ( |  | ) |
| overridenoexcept

## Member Function Documentation

## ◆ add_interface()

static void Gtk::Editable::add_interface | ( | GType | gtype_implementer | ) |
| static

## ◆ delete_selection()

void Gtk::Editable::delete_selection | ( |  | ) |

Deletes the currently selected text of the editable.

This call doesn’t do anything if there is no selected text.

## ◆ delete_text()

void Gtk::Editable::delete_text | ( | int | start_pos,
|  | int | end_pos )

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.

Parameters

  start_pos | Start position.
  end_pos | End position.

## ◆ delete_text_vfunc()

virtual void Gtk::Editable::delete_text_vfunc | ( | int | start_pos,
|  | int | end_pos )
| protectedvirtual

## ◆ get_alignment()

float Gtk::Editable::get_alignment | ( |  | ) | const

Gets the alignment of the editable.

Returns
  The alignment.

## ◆ get_chars()

Glib::ustring Gtk::Editable::get_chars | ( | int | start_pos,
|  | int | end_pos ) const

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.

Parameters

  start_pos | Start of text.
  end_pos | End of text.

Returns
  A pointer to the contents of the widget as a string. This string is allocated by the `Gtk::Editable` implementation and should be freed by the caller.

## ◆ get_editable()

bool Gtk::Editable::get_editable | ( |  | ) | const

Retrieves whether editable is editable.

Returns
  `true` if editable is editable.

## ◆ get_enable_undo()

bool Gtk::Editable::get_enable_undo | ( |  | ) | const

Gets if undo/redo actions are enabled for editable.

Returns
  `true` if undo is enabled.

## ◆ get_max_width_chars()

int Gtk::Editable::get_max_width_chars | ( |  | ) | const

Retrieves the desired maximum width of editable, in characters.

Returns
  The maximum width of the entry, in characters.

## ◆ get_position()

int Gtk::Editable::get_position | ( |  | ) | const

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.

Returns
  The cursor position.

## ◆ get_selection_bounds()

bool Gtk::Editable::get_selection_bounds | ( | int & | start_pos,
|  | int & | end_pos ) const

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.

Parameters

  start_pos | Location to store the starting position.
  end_pos | Location to store the end position.

Returns
  `true` if there is a non-empty selection, `false` otherwise.

## ◆ get_selection_bounds_vfunc()

virtual bool Gtk::Editable::get_selection_bounds_vfunc | ( | int & | start_pos,
|  | int & | end_pos ) const
| protectedvirtual

## ◆ get_text()

Glib::ustring Gtk::Editable::get_text | ( |  | ) | const

Retrieves the contents of editable.

The returned string is owned by GTK and must not be modified or freed.

Returns
  A pointer to the contents of the editable.

## ◆ get_text_vfunc()

virtual Glib::ustring Gtk::Editable::get_text_vfunc | ( |  | ) | const
| protectedvirtual

## ◆ get_type()

static GType Gtk::Editable::get_type | ( |  | ) |
| static

Get the GType for this class, for use with the underlying GObject type system.

## ◆ get_width_chars()

int Gtk::Editable::get_width_chars | ( |  | ) | const

Gets the number of characters of space reserved for the contents of the editable.

Returns
  Number of chars to request space for, or negative if unset.

## ◆ gobj() [1/2]

GtkEditable * Gtk::Editable::gobj | ( |  | ) |
| inline

Provides access to the underlying C GObject.

## ◆ gobj() [2/2]

const GtkEditable * Gtk::Editable::gobj | ( |  | ) | const
| inline

Provides access to the underlying C GObject.

## ◆ insert_text()

void Gtk::Editable::insert_text | ( | const Glib::ustring & | new_text,
|  | int | new_text_length,
|  | int & | position )

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.

Parameters

  new_text | The text to insert.
  new_text_length | The length of the text in bytes, or -1.
  position | Location of the position text will be inserted at.

## ◆ insert_text_vfunc()

virtual void Gtk::Editable::insert_text_vfunc | ( | const Glib::ustring & | text,
|  | int & | position )
| protectedvirtual

## ◆ on_changed()

virtual void Gtk::Editable::on_changed | ( |  | ) |
| protectedvirtual

This is a default handler for the signal signal_changed().

## ◆ on_delete_text()

virtual void Gtk::Editable::on_delete_text | ( | int | start_pos,
|  | int | end_pos )
| protectedvirtual

This is a default handler for the signal signal_delete_text().

## ◆ on_insert_text()

virtual void Gtk::Editable::on_insert_text | ( | const Glib::ustring & | text,
|  | int * | position )
| protectedvirtual

This is a default handler for the signal signal_insert_text().

## ◆ operator=()

Editable & Gtk::Editable::operator= | ( | Editable && | src | ) |
| noexcept

## ◆ property_cursor_position()

Glib::PropertyProxy_ReadOnly< int > Gtk::Editable::property_cursor_position | ( |  | ) | const

The current position of the insertion cursor in chars.

Default value: 0

Returns
  A PropertyProxy_ReadOnly that allows you to get the value of the property, or receive notification when the value of the property changes.

## ◆ property_editable() [1/2]

Glib::PropertyProxy< bool > Gtk::Editable::property_editable | ( |  | ) |

Whether the entry contents can be edited.

Default value: `true`

Returns
  A PropertyProxy that allows you to get or set the value of the property, or receive notification when the value of the property changes.

## ◆ property_editable() [2/2]

Glib::PropertyProxy_ReadOnly< bool > Gtk::Editable::property_editable | ( |  | ) | const

Whether the entry contents can be edited.

Default value: `true`

Returns
  A PropertyProxy_ReadOnly that allows you to get the value of the property, or receive notification when the value of the property changes.

## ◆ property_enable_undo() [1/2]

Glib::PropertyProxy< bool > Gtk::Editable::property_enable_undo | ( |  | ) |

If undo/redo should be enabled for the editable.

Default value: `true`

Returns
  A PropertyProxy that allows you to get or set the value of the property, or receive notification when the value of the property changes.

## ◆ property_enable_undo() [2/2]

Glib::PropertyProxy_ReadOnly< bool > Gtk::Editable::property_enable_undo | ( |  | ) | const

If undo/redo should be enabled for the editable.

Default value: `true`

Returns
  A PropertyProxy_ReadOnly that allows you to get the value of the property, or receive notification when the value of the property changes.

## ◆ property_max_width_chars() [1/2]

Glib::PropertyProxy< int > Gtk::Editable::property_max_width_chars | ( |  | ) |

The desired maximum width of the entry, in characters.

Default value: -1

Returns
  A PropertyProxy that allows you to get or set the value of the property, or receive notification when the value of the property changes.

## ◆ property_max_width_chars() [2/2]

Glib::PropertyProxy_ReadOnly< int > Gtk::Editable::property_max_width_chars | ( |  | ) | const

The desired maximum width of the entry, in characters.

Default value: -1

Returns
  A PropertyProxy_ReadOnly that allows you to get the value of the property, or receive notification when the value of the property changes.

## ◆ property_selection_bound()

Glib::PropertyProxy_ReadOnly< int > Gtk::Editable::property_selection_bound | ( |  | ) | const

The position of the opposite end of the selection from the cursor in chars.

Default value: 0

Returns
  A PropertyProxy_ReadOnly that allows you to get the value of the property, or receive notification when the value of the property changes.

## ◆ property_text() [1/2]

Glib::PropertyProxy< Glib::ustring > Gtk::Editable::property_text | ( |  | ) |

The contents of the entry.

Default value: ""

Returns
  A PropertyProxy that allows you to get or set the value of the property, or receive notification when the value of the property changes.

## ◆ property_text() [2/2]

Glib::PropertyProxy_ReadOnly< Glib::ustring > Gtk::Editable::property_text | ( |  | ) | const

The contents of the entry.

Default value: ""

Returns
  A PropertyProxy_ReadOnly that allows you to get the value of the property, or receive notification when the value of the property changes.

## ◆ property_width_chars() [1/2]

Glib::PropertyProxy< int > Gtk::Editable::property_width_chars | ( |  | ) |

Number of characters to leave space for in the entry.

Default value: -1

Returns
  A PropertyProxy that allows you to get or set the value of the property, or receive notification when the value of the property changes.

## ◆ property_width_chars() [2/2]

Glib::PropertyProxy_ReadOnly< int > Gtk::Editable::property_width_chars | ( |  | ) | const

Number of characters to leave space for in the entry.

Default value: -1

Returns
  A PropertyProxy_ReadOnly that allows you to get the value of the property, or receive notification when the value of the property changes.

## ◆ property_xalign() [1/2]

Glib::PropertyProxy< float > Gtk::Editable::property_xalign | ( |  | ) |

The horizontal alignment, from 0 (left) to 1 (right).

Reversed for RTL layouts.

Default value: 0

Returns
  A PropertyProxy that allows you to get or set the value of the property, or receive notification when the value of the property changes.

## ◆ property_xalign() [2/2]

Glib::PropertyProxy_ReadOnly< float > Gtk::Editable::property_xalign | ( |  | ) | const

The horizontal alignment, from 0 (left) to 1 (right).

Reversed for RTL layouts.

Default value: 0

Returns
  A PropertyProxy_ReadOnly that allows you to get the value of the property, or receive notification when the value of the property changes.

## ◆ select_region()

void Gtk::Editable::select_region | ( | int | start_pos,
|  | int | end_pos )

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.

Parameters

  start_pos | Start of region.
  end_pos | End of region.

## ◆ select_region_vfunc()

virtual void Gtk::Editable::select_region_vfunc | ( | int | start_pos,
|  | int | end_pos )
| protectedvirtual

## ◆ set_alignment()

void Gtk::Editable::set_alignment | ( | float | xalign | ) |

Sets the alignment for the contents of the editable.

This controls the horizontal positioning of the contents when the displayed text is shorter than the width of the editable.

Parameters

  xalign | The horizontal alignment, from 0 (left) to 1 (right). Reversed for RTL layouts.

## ◆ set_editable()

void Gtk::Editable::set_editable | ( | bool | is_editable = true | ) |

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

Parameters

  is_editable | `true` if the user is allowed to edit the text in the widget.

## ◆ set_enable_undo()

void Gtk::Editable::set_enable_undo | ( | bool | enable_undo = true | ) |

If enabled, changes to editable will be saved for undo/redo actions.

This results in an additional copy of text changes and are not stored in secure memory. As such, undo is forcefully disabled when Gtk::Text::property_visibility() is set to `false`.

Parameters

  enable_undo | If undo/redo should be enabled.

## ◆ set_max_width_chars()

void Gtk::Editable::set_max_width_chars | ( | int | n_chars | ) |

Sets the desired maximum width in characters of editable.

Parameters

  n_chars | The new desired maximum width, in characters.

## ◆ set_position()

void Gtk::Editable::set_position | ( | int | position | ) |

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.

Parameters

  position | The position of the cursor.

## ◆ set_text()

void Gtk::Editable::set_text | ( | const Glib::ustring & | text | ) |

Sets the text in the editable to the given value.

This is replacing the current contents.

Parameters

  text | The text to set.

## ◆ set_width_chars()

void Gtk::Editable::set_width_chars | ( | int | n_chars | ) |

Changes the size request of the editable to be about the right size for n_chars characters.

Note that it changes the size request, the size can still be affected by how you pack the widget into containers. If n_chars is -1, the size reverts to the default size.

Parameters

  n_chars | Width in chars.

## ◆ signal_changed()

Glib::SignalProxy< void()> Gtk::Editable::signal_changed | ( |  | ) |

Slot Prototype:
  `void on_my_changed()`

Flags: Run Last

Emitted at the end of a single user-visible operation on the contents.

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()

Glib::SignalProxy< void(int, int)> Gtk::Editable::signal_delete_text | ( |  | ) |

Slot Prototype:
  `void on_my_delete_text(int start_pos, int end_pos)`

Flags: Run Last

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 Glib::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().

Parameters

  start_pos | The starting position.
  end_pos | The end position.

## ◆ signal_insert_text()

Glib::SignalProxy< void(const Glib::ustring &, int *)> Gtk::Editable::signal_insert_text | ( |  | ) |

## Friends And Related Symbol Documentation

## ◆ wrap()

Glib::RefPtr< Gtk::Editable > wrap | ( | GtkEditable * | object,
|  | bool | take_copy = false )
| related

A Glib::wrap() method for this object.

Parameters

  object | The C instance.
  take_copy | False if the result should take ownership of the C instance. True if it should take a new copy or ref.

Returns
  A C++ instance that wraps this C instance.