Editable

open class Editable : Widget, EditableProtocol

GtkEditable is an interface for text editing widgets.

Typical examples of editable widgets are [classGtk.Entry] and [classGtk.SpinButton]. 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 modify the behavior of a widget.

As an example of the latter usage, by connecting the following handler to [signalGtk.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 char  *text,
                     int          length,
                     int         *position,
                     gpointer     data)
{
  char *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);
}

Implementing GtkEditable

The most likely scenario for implementing GtkEditable on your own widget is that you will embed a GtkText inside a complex widget, and want to delegate the editable functionality to that text widget. GtkEditable provides some utility functions to make this easy.

In your class_init function, call [funcGtk.Editable.install_properties], passing the first available property ID:

static void
my_class_init (MyClass *class)
{
  ...
  g_object_class_install_properties (object_class, NUM_PROPERTIES, props);
  gtk_editable_install_properties (object_clas, NUM_PROPERTIES);
  ...
}

In your interface_init function for the GtkEditable interface, provide an implementation for the get_delegate vfunc that returns your text widget:

GtkEditable *
get_editable_delegate (GtkEditable *editable)
{
  return GTK_EDITABLE (MY_WIDGET (editable)->text_widget);
}

static void
my_editable_init (GtkEditableInterface *iface)
{
  iface->get_delegate = get_editable_delegate;
}

You don’t need to provide any other vfuncs. The default implementations work by forwarding to the delegate that the GtkEditableInterface.get_delegate() vfunc returns.

In your instance_init function, create your text widget, and then call [methodGtk.Editable.init_delegate]:

static void
my_widget_init (MyWidget *self)
{
  ...
  self->text_widget = gtk_text_new ();
  gtk_editable_init_delegate (GTK_EDITABLE (self));
  ...
}

In your dispose function, call [methodGtk.Editable.finish_delegate] before destroying your text widget:

static void
my_widget_dispose (GObject *object)
{
  ...
  gtk_editable_finish_delegate (GTK_EDITABLE (self));
  g_clear_pointer (&self->text_widget, gtk_widget_unparent);
  ...
}

Finally, use [funcGtk.Editable.delegate_set_property] in your set_property function (and similar for get_property), to set the editable properties:

  ...
  if (gtk_editable_delegate_set_property (object, prop_id, value, pspec))
    return;

  switch (prop_id)
  ...

It is important to note that if you create a GtkEditable that uses a delegate, the low level [signalGtk.Editable::insert-text] and [signalGtk.Editable::delete-text] signals will be propagated from the “wrapper” editable to the delegate, but they will not be propagated from the delegate to the “wrapper” editable, as they would cause an infinite recursion. If you wish to connect to the [signalGtk.Editable::insert-text] and [signalGtk.Editable::delete-text] signals, you will need to connect to them on the delegate obtained via [methodGtk.Editable.get_delegate].

The Editable type acts as a reference-counted owner of an underlying GtkEditable instance. It provides the methods that can operate on this data type through EditableProtocol conformance. Use Editable as a strong reference or owner of a GtkEditable instance.

  • Designated initialiser from the underlying `C` data type.
    

    This creates an instance without performing an unbalanced retain i.e., ownership is transferred to the Editable instance.

    Declaration

    Swift

    @inlinable
    public init(_ op: UnsafeMutablePointer<GtkEditable>)

    Parameters

    op

    pointer to the underlying object

  • Designated initialiser from a constant pointer to the underlying C data type. This creates an instance without performing an unbalanced retain i.e., ownership is transferred to the Editable instance.

    Declaration

    Swift

    @inlinable
    public init(_ op: UnsafePointer<GtkEditable>)

    Parameters

    op

    pointer to the underlying object

  • Optional initialiser from a non-mutating gpointer to the underlying C data type. This creates an instance without performing an unbalanced retain i.e., ownership is transferred to the Editable instance.

    Declaration

    Swift

    @inlinable
    override public init!(gpointer op: gpointer?)

    Parameters

    op

    gpointer to the underlying object

  • Optional initialiser from a non-mutating gconstpointer to the underlying C data type. This creates an instance without performing an unbalanced retain i.e., ownership is transferred to the Editable instance.

    Declaration

    Swift

    @inlinable
    override public init!(gconstpointer op: gconstpointer?)

    Parameters

    op

    pointer to the underlying object

  • Optional initialiser from a constant pointer to the underlying C data type. This creates an instance without performing an unbalanced retain i.e., ownership is transferred to the Editable instance.

    Declaration

    Swift

    @inlinable
    public init!(_ op: UnsafePointer<GtkEditable>?)

    Parameters

    op

    pointer to the underlying object

  • Optional initialiser from the underlying C data type. This creates an instance without performing an unbalanced retain i.e., ownership is transferred to the Editable instance.

    Declaration

    Swift

    @inlinable
    public init!(_ op: UnsafeMutablePointer<GtkEditable>?)

    Parameters

    op

    pointer to the underlying object

  • Designated initialiser from the underlying C data type. Will retain GtkEditable. i.e., ownership is transferred to the Editable instance.

    Declaration

    Swift

    @inlinable
    public init(retaining op: UnsafeMutablePointer<GtkEditable>)

    Parameters

    op

    pointer to the underlying object

  • Reference intialiser for a related type that implements EditableProtocol Will retain GtkEditable.

    Declaration

    Swift

    @inlinable
    public init<T>(editable other: T) where T : EditableProtocol

    Parameters

    other

    an instance of a related type that implements EditableProtocol

  • Unsafe typed initialiser. Do not use unless you know the underlying data type the pointer points to conforms to EditableProtocol.

    Declaration

    Swift

    @inlinable
    override public init<T>(cPointer p: UnsafeMutablePointer<T>)

    Parameters

    cPointer

    pointer to the underlying object

  • Unsafe typed, retaining initialiser. Do not use unless you know the underlying data type the pointer points to conforms to EditableProtocol.

    Declaration

    Swift

    @inlinable
    override public init<T>(retainingCPointer cPointer: UnsafeMutablePointer<T>)

    Parameters

    cPointer

    pointer to the underlying object

  • Unsafe untyped initialiser. Do not use unless you know the underlying data type the pointer points to conforms to EditableProtocol.

    Declaration

    Swift

    @inlinable
    override public init(raw p: UnsafeRawPointer)

    Parameters

    p

    raw pointer to the underlying object

  • Unsafe untyped, retaining initialiser. Do not use unless you know the underlying data type the pointer points to conforms to EditableProtocol.

    Declaration

    Swift

    @inlinable
    override public init(retainingRaw raw: UnsafeRawPointer)
  • Unsafe untyped initialiser. Do not use unless you know the underlying data type the pointer points to conforms to EditableProtocol.

    Declaration

    Swift

    @inlinable
    public required init(raw p: UnsafeMutableRawPointer)

    Parameters

    p

    mutable raw pointer to the underlying object

  • Unsafe untyped, retaining initialiser. Do not use unless you know the underlying data type the pointer points to conforms to EditableProtocol.

    Declaration

    Swift

    @inlinable
    required public init(retainingRaw raw: UnsafeMutableRawPointer)

    Parameters

    raw

    mutable raw pointer to the underlying object

  • Unsafe untyped initialiser. Do not use unless you know the underlying data type the pointer points to conforms to EditableProtocol.

    Declaration

    Swift

    @inlinable
    override public init(opaquePointer p: OpaquePointer)

    Parameters

    p

    opaque pointer to the underlying object

  • Unsafe untyped, retaining initialiser. Do not use unless you know the underlying data type the pointer points to conforms to EditableProtocol.

    Declaration

    Swift

    @inlinable
    override public init(retainingOpaquePointer p: OpaquePointer)

    Parameters

    p

    opaque pointer to the underlying object