IMContextProtocol

public protocol IMContextProtocol : ObjectProtocol

GtkIMContext defines the interface for GTK+ input methods. An input method is used by GTK+ text input widgets like GtkEntry to map from key events to Unicode character strings.

The default input method can be set programmatically via the GtkSettings:gtk-im-module GtkSettings property. Alternatively, you may set the GTK_IM_MODULE environment variable as documented in Running GTK+ Applications.

The GtkEntry GtkEntry:im-module and GtkTextView GtkTextView:im-module properties may also be used to set input methods for specific widget instances. For instance, a certain entry widget might be expected to contain certain characters which would be easier to input with a certain input method.

An input method may consume multiple key events in sequence and finally output the composed result. This is called preediting, and an input method may provide feedback about this process by displaying the intermediate composition states as preedit text. For instance, the default GTK+ input method implements the input of arbitrary Unicode code points by holding down the Control and Shift keys and then typing “U” followed by the hexadecimal digits of the code point. When releasing the Control and Shift keys, preediting ends and the character is inserted as text. Ctrl+Shift+u20AC for example results in the € sign.

Additional input methods can be made available for use by GTK+ widgets as loadable modules. An input method module is a small shared library which implements a subclass of GtkIMContext or GtkIMContextSimple and exports these four functions:

(C Language Example):

void im_module_init(GTypeModule *module);

This function should register the GType of the GtkIMContext subclass which implements the input method by means of g_type_module_register_type(). Note that g_type_register_static() cannot be used as the type needs to be registered dynamically.

(C Language Example):

void im_module_exit(void);

Here goes any cleanup code your input method might require on module unload.

(C Language Example):

void im_module_list(const GtkIMContextInfo ***contexts, int *n_contexts)
{
  *contexts = info_list;
  *n_contexts = G_N_ELEMENTS (info_list);
}

This function returns the list of input methods provided by the module. The example implementation above shows a common solution and simply returns a pointer to statically defined array of GtkIMContextInfo items for each provided input method.

(C Language Example):

GtkIMContext * im_module_create(const gchar *context_id);

This function should return a pointer to a newly created instance of the GtkIMContext subclass identified by context_id. The context ID is the same as specified in the GtkIMContextInfo array returned by im_module_list().

After a new loadable input method module has been installed on the system, the configuration file gtk.immodules needs to be regenerated by gtk-query-immodules-3.0, in order for the new input method to become available to GTK+ applications.

The IMContextProtocol protocol exposes the methods and properties of an underlying GtkIMContext instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, see IMContext. Alternatively, use IMContextRef as a lighweight, unowned reference if you already have an instance you just want to use.

  • ptr

    Untyped pointer to the underlying GtkIMContext instance.

    Declaration

    Swift

    var ptr: UnsafeMutableRawPointer! { get }
  • im_context_ptr Default implementation

    Typed pointer to the underlying GtkIMContext instance.

    Default Implementation

    Return the stored, untyped pointer as a typed pointer to the GtkIMContext instance.

    Declaration

    Swift

    var im_context_ptr: UnsafeMutablePointer<GtkIMContext>! { get }
  • Required Initialiser for types conforming to IMContextProtocol

    Declaration

    Swift

    init(raw: UnsafeMutableRawPointer)

IMContext Class

  • Bind a IMContextPropertyName source property to a given target object.

    Declaration

    Swift

    @discardableResult
    @inlinable
    func bind<Q, T>(property source_property: IMContextPropertyName, to target: T, _ target_property: Q, flags f: BindingFlags = .default, transformFrom transform_from: @escaping GLibObject.ValueTransformer = { $0.transform(destValue: $1) }, transformTo transform_to: @escaping GLibObject.ValueTransformer = { $0.transform(destValue: $1) }) -> BindingRef! where Q : PropertyNameProtocol, T : ObjectProtocol

    Parameters

    source_property

    the source property to bind

    target

    the target object to bind to

    target_property

    the target property to bind to

    flags

    the flags to pass to the Binding

    transform_from

    ValueTransformer to use for forward transformation

    transform_to

    ValueTransformer to use for backwards transformation

    Return Value

    binding reference or nil in case of an error

  • get(property:) Extension method

    Get the value of a IMContext property

    Declaration

    Swift

    @inlinable
    func get(property: IMContextPropertyName) -> GLibObject.Value

    Parameters

    property

    the property to get the value for

    Return Value

    the value of the named property

  • set(property:value:) Extension method

    Set the value of a IMContext property. Note that this will only have an effect on properties that are writable and not construct-only!

    Declaration

    Swift

    @inlinable
    func set(property: IMContextPropertyName, value v: GLibObject.Value)

    Parameters

    property

    the property to get the value for

    Return Value

    the value of the named property

IMContext signals

  • Connect a Swift signal handler to the given, typed IMContextSignalName signal

    Declaration

    Swift

    @discardableResult
    @inlinable
    func connect(signal s: IMContextSignalName, flags f: ConnectFlags = ConnectFlags(0), handler h: @escaping SignalHandler) -> Int

    Parameters

    signal

    The signal to connect

    flags

    The connection flags to use

    data

    A pointer to user data to provide to the callback

    destroyData

    A GClosureNotify C function to destroy the data pointed to by userData

    handler

    The Swift signal handler (function or callback) to invoke on the given signal

    Return Value

    The signal handler ID (always greater than 0 for successful connections)

  • Connect a C signal handler to the given, typed IMContextSignalName signal

    Declaration

    Swift

    @discardableResult
    @inlinable
    func connect(signal s: IMContextSignalName, flags f: ConnectFlags = ConnectFlags(0), data userData: gpointer!, destroyData destructor: GClosureNotify? = nil, signalHandler h: @escaping GCallback) -> Int

    Parameters

    signal

    The signal to connect

    flags

    The connection flags to use

    data

    A pointer to user data to provide to the callback

    destroyData

    A GClosureNotify C function to destroy the data pointed to by userData

    signalHandler

    The C function to be called on the given signal

    Return Value

    The signal handler ID (always greater than 0 for successful connections)

  • onCommit(flags:handler:) Extension method

    The commit signal is emitted when a complete input sequence has been entered by the user. This can be a single character immediately after a key press or the final result of preediting.

    Note

    This represents the underlying commit signal

    Declaration

    Swift

    @discardableResult
    @inlinable
    func onCommit(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: IMContextRef, _ str: String) -> Void) -> Int

    Parameters

    flags

    Flags

    unownedSelf

    Reference to instance of self

    str

    the completed character(s) entered by the user

    handler

    The signal handler to call Run the given callback whenever the commit signal is emitted

  • commitSignal Extension method

    Typed commit signal for using the connect(signal:) methods

    Declaration

    Swift

    static var commitSignal: IMContextSignalName { get }
  • The delete-surrounding signal is emitted when the input method needs to delete all or part of the context surrounding the cursor.

    Note

    This represents the underlying delete-surrounding signal

    Declaration

    Swift

    @discardableResult
    @inlinable
    func onDeleteSurrounding(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: IMContextRef, _ offset: Int, _ nChars: Int) -> Bool) -> Int

    Parameters

    flags

    Flags

    unownedSelf

    Reference to instance of self

    offset

    the character offset from the cursor position of the text to be deleted. A negative value indicates a position before the cursor.

    nChars

    the number of characters to be deleted

    handler

    true if the signal was handled. Run the given callback whenever the deleteSurrounding signal is emitted

  • deleteSurroundingSignal Extension method

    Typed delete-surrounding signal for using the connect(signal:) methods

    Declaration

    Swift

    static var deleteSurroundingSignal: IMContextSignalName { get }
  • The preedit-changed signal is emitted whenever the preedit sequence currently being entered has changed. It is also emitted at the end of a preedit sequence, in which case gtk_im_context_get_preedit_string() returns the empty string.

    Note

    This represents the underlying preedit-changed signal

    Declaration

    Swift

    @discardableResult
    @inlinable
    func onPreeditChanged(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: IMContextRef) -> Void) -> Int

    Parameters

    flags

    Flags

    unownedSelf

    Reference to instance of self

    handler

    The signal handler to call Run the given callback whenever the preeditChanged signal is emitted

  • preeditChangedSignal Extension method

    Typed preedit-changed signal for using the connect(signal:) methods

    Declaration

    Swift

    static var preeditChangedSignal: IMContextSignalName { get }
  • onPreeditEnd(flags:handler:) Extension method

    The preedit-end signal is emitted when a preediting sequence has been completed or canceled.

    Note

    This represents the underlying preedit-end signal

    Declaration

    Swift

    @discardableResult
    @inlinable
    func onPreeditEnd(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: IMContextRef) -> Void) -> Int

    Parameters

    flags

    Flags

    unownedSelf

    Reference to instance of self

    handler

    The signal handler to call Run the given callback whenever the preeditEnd signal is emitted

  • preeditEndSignal Extension method

    Typed preedit-end signal for using the connect(signal:) methods

    Declaration

    Swift

    static var preeditEndSignal: IMContextSignalName { get }
  • The preedit-start signal is emitted when a new preediting sequence starts.

    Note

    This represents the underlying preedit-start signal

    Declaration

    Swift

    @discardableResult
    @inlinable
    func onPreeditStart(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: IMContextRef) -> Void) -> Int

    Parameters

    flags

    Flags

    unownedSelf

    Reference to instance of self

    handler

    The signal handler to call Run the given callback whenever the preeditStart signal is emitted

  • preeditStartSignal Extension method

    Typed preedit-start signal for using the connect(signal:) methods

    Declaration

    Swift

    static var preeditStartSignal: IMContextSignalName { get }
  • The retrieve-surrounding signal is emitted when the input method requires the context surrounding the cursor. The callback should set the input method surrounding context by calling the gtk_im_context_set_surrounding() method.

    Note

    This represents the underlying retrieve-surrounding signal

    Declaration

    Swift

    @discardableResult
    @inlinable
    func onRetrieveSurrounding(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: IMContextRef) -> Bool) -> Int

    Parameters

    flags

    Flags

    unownedSelf

    Reference to instance of self

    handler

    true if the signal was handled. Run the given callback whenever the retrieveSurrounding signal is emitted

  • retrieveSurroundingSignal Extension method

    Typed retrieve-surrounding signal for using the connect(signal:) methods

    Declaration

    Swift

    static var retrieveSurroundingSignal: IMContextSignalName { get }
  • The notify signal is emitted on an object when one of its properties has its value set through g_object_set_property(), g_object_set(), et al.

    Note that getting this signal doesn’t itself guarantee that the value of the property has actually changed. When it is emitted is determined by the derived GObject class. If the implementor did not create the property with G_PARAM_EXPLICIT_NOTIFY, then any call to g_object_set_property() results in notify being emitted, even if the new value is the same as the old. If they did pass G_PARAM_EXPLICIT_NOTIFY, then this signal is emitted only when they explicitly call g_object_notify() or g_object_notify_by_pspec(), and common practice is to do that only when the value has actually changed.

    This signal is typically used to obtain change notification for a single property, by specifying the property name as a detail in the g_signal_connect() call, like this:

    (C Language Example):

    g_signal_connect (text_view->buffer, "notify::paste-target-list",
                      G_CALLBACK (gtk_text_view_target_list_notify),
                      text_view)
    

    It is important to note that you must use canonical parameter names as detail strings for the notify signal.

    Note

    This represents the underlying notify::input-hints signal

    Declaration

    Swift

    @discardableResult
    @inlinable
    func onNotifyInputHints(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: IMContextRef, _ pspec: ParamSpecRef) -> Void) -> Int

    Parameters

    flags

    Flags

    unownedSelf

    Reference to instance of self

    pspec

    the GParamSpec of the property which changed.

    handler

    The signal handler to call Run the given callback whenever the notifyInputHints signal is emitted

  • notifyInputHintsSignal Extension method

    Typed notify::input-hints signal for using the connect(signal:) methods

    Declaration

    Swift

    static var notifyInputHintsSignal: IMContextSignalName { get }
  • The notify signal is emitted on an object when one of its properties has its value set through g_object_set_property(), g_object_set(), et al.

    Note that getting this signal doesn’t itself guarantee that the value of the property has actually changed. When it is emitted is determined by the derived GObject class. If the implementor did not create the property with G_PARAM_EXPLICIT_NOTIFY, then any call to g_object_set_property() results in notify being emitted, even if the new value is the same as the old. If they did pass G_PARAM_EXPLICIT_NOTIFY, then this signal is emitted only when they explicitly call g_object_notify() or g_object_notify_by_pspec(), and common practice is to do that only when the value has actually changed.

    This signal is typically used to obtain change notification for a single property, by specifying the property name as a detail in the g_signal_connect() call, like this:

    (C Language Example):

    g_signal_connect (text_view->buffer, "notify::paste-target-list",
                      G_CALLBACK (gtk_text_view_target_list_notify),
                      text_view)
    

    It is important to note that you must use canonical parameter names as detail strings for the notify signal.

    Note

    This represents the underlying notify::input-purpose signal

    Declaration

    Swift

    @discardableResult
    @inlinable
    func onNotifyInputPurpose(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: IMContextRef, _ pspec: ParamSpecRef) -> Void) -> Int

    Parameters

    flags

    Flags

    unownedSelf

    Reference to instance of self

    pspec

    the GParamSpec of the property which changed.

    handler

    The signal handler to call Run the given callback whenever the notifyInputPurpose signal is emitted

  • notifyInputPurposeSignal Extension method

    Typed notify::input-purpose signal for using the connect(signal:) methods

    Declaration

    Swift

    static var notifyInputPurposeSignal: IMContextSignalName { get }

IMContext Class: IMContextProtocol extension (methods and fields)

  • Asks the widget that the input context is attached to to delete characters around the cursor position by emitting the GtkIMContextdelete_surrounding signal. Note that offset and n_chars are in characters not in bytes which differs from the usage other places in GtkIMContext.

    In order to use this function, you should first call gtk_im_context_get_surrounding() to get the current context, and call this function immediately afterwards to make sure that you know what you are deleting. You should also account for the fact that even if the signal was handled, the input context might not have deleted all the characters that were requested to be deleted.

    This function is used by an input method that wants to make subsitutions in the existing text in response to new input. It is not useful for applications.

    Declaration

    Swift

    @inlinable
    func deleteSurrounding(offset: Int, nChars: Int) -> Bool
  • filterKeypress(event:) Extension method

    Allow an input method to internally handle key press and release events. If this function returns true, then no further processing should be done for this key event.

    Declaration

    Swift

    @inlinable
    func filterKeypress<EventKeyT>(event: EventKeyT) -> Bool where EventKeyT : EventKeyProtocol
  • focusIn() Extension method

    Notify the input method that the widget to which this input context corresponds has gained focus. The input method may, for example, change the displayed feedback to reflect this change.

    Declaration

    Swift

    @inlinable
    func focusIn()
  • focusOut() Extension method

    Notify the input method that the widget to which this input context corresponds has lost focus. The input method may, for example, change the displayed feedback or reset the contexts state to reflect this change.

    Declaration

    Swift

    @inlinable
    func focusOut()
  • Retrieve the current preedit string for the input context, and a list of attributes to apply to the string. This string should be displayed inserted at the insertion point.

    Declaration

    Swift

    @inlinable
    func getPreedit(string str: UnsafeMutablePointer<UnsafeMutablePointer<gchar>?>!, attrs: UnsafeMutablePointer<UnsafeMutablePointer<PangoAttrList>?>!, cursorPos: UnsafeMutablePointer<gint>!)
  • Retrieves context around the insertion point. Input methods typically want context in order to constrain input text based on existing text; this is important for languages such as Thai where only some sequences of characters are allowed.

    This function is implemented by emitting the GtkIMContextretrieve_surrounding signal on the input method; in response to this signal, a widget should provide as much context as is available, up to an entire paragraph, by calling gtk_im_context_set_surrounding(). Note that there is no obligation for a widget to respond to the retrieve_surrounding signal, so input methods must be prepared to function without context.

    Declaration

    Swift

    @inlinable
    func getSurrounding(text: UnsafeMutablePointer<UnsafeMutablePointer<gchar>?>!, cursorIndex: UnsafeMutablePointer<gint>!) -> Bool
  • reset() Extension method

    Notify the input method that a change such as a change in cursor position has been made. This will typically cause the input method to clear the preedit state.

    Declaration

    Swift

    @inlinable
    func reset()
  • setClient(window:) Extension method

    Set the client window for the input context; this is the GdkWindow in which the input appears. This window is used in order to correctly position status windows, and may also be used for purposes internal to the input method.

    Declaration

    Swift

    @inlinable
    func setClient(window: Gdk.WindowRef? = nil)
  • setClient(window:) Extension method

    Set the client window for the input context; this is the GdkWindow in which the input appears. This window is used in order to correctly position status windows, and may also be used for purposes internal to the input method.

    Declaration

    Swift

    @inlinable
    func setClient<WindowT>(window: WindowT?) where WindowT : WindowProtocol
  • setCursorLocation(area:) Extension method

    Notify the input method that a change in cursor position has been made. The location is relative to the client window.

    Declaration

    Swift

    @inlinable
    func setCursorLocation<RectangleT>(area: RectangleT) where RectangleT : RectangleProtocol
  • Sets surrounding context around the insertion point and preedit string. This function is expected to be called in response to the GtkIMContextretrieve_surrounding signal, and will likely have no effect if called at other times.

    Declaration

    Swift

    @inlinable
    func setSurrounding(text: UnsafePointer<gchar>!, len: Int, cursorIndex: Int)
  • set(usePreedit:) Extension method

    Sets whether the IM context should use the preedit string to display feedback. If use_preedit is FALSE (default is TRUE), then the IM context may use some other method to display feedback, such as displaying it in a child of the root window.

    Declaration

    Swift

    @inlinable
    func set(usePreedit: Bool)
  • parentInstance Extension method

    Undocumented

    Declaration

    Swift

    @inlinable
    var parentInstance: GObject { get }