class Gtk::IMContext

Overview

Gtk::IMContext defines the interface for GTK input methods.

Gtk::IMContext is used by GTK text input widgets like Gtk::Text to map from key events to Unicode character strings.

An input method may consume multiple key events in sequence before finally outputting 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. To do so, the Gtk::IMContext will emit [signal@Gtk.IMContext::preedit-start], [signal@Gtk.IMContext::preedit-changed] and [signal@Gtk.IMContext::preedit-end] signals.

For instance, the built-in GTK input method Gtk::IMContextSimple 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. For example,

Ctrl+Shift+u 2 0 A C

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 provides a GIOExtension for the extension point named "gtk-im-module".

To connect a widget to the users preferred input method, you should use Gtk::IMMulticontext.

Direct Known Subclasses

Defined in:

lib/gi-crystal/src/auto/gtk-4.0/im_context.cr

Constructors

Class Method Summary

Instance Method Summary

Instance methods inherited from class GObject::Object

==(other : self) ==, bind_property(source_property : String, target : GObject::Object, target_property : String, flags : GObject::BindingFlags) : GObject::Binding bind_property, bind_property_full(source_property : String, target : GObject::Object, target_property : String, flags : GObject::BindingFlags, transform_to : GObject::Closure, transform_from : GObject::Closure) : GObject::Binding bind_property_full, data(key : String) : Pointer(Void) | Nil data, finalize finalize, freeze_notify : Nil freeze_notify, getv(names : Enumerable(String), values : Enumerable(_)) : Nil getv, hash(hasher) hash, notify(property_name : String) : Nil notify, notify_by_pspec(pspec : GObject::ParamSpec) : Nil notify_by_pspec, notify_signal notify_signal, property(property_name : String, value : _) : Nil property, qdata(quark : UInt32) : Pointer(Void) | Nil qdata, ref_count : UInt32 ref_count, run_dispose : Nil run_dispose, set_data(key : String, data : Pointer(Void) | Nil) : Nil set_data, set_property(property_name : String, value : _) : Nil set_property, steal_data(key : String) : Pointer(Void) | Nil steal_data, steal_qdata(quark : UInt32) : Pointer(Void) | Nil steal_qdata, thaw_notify : Nil thaw_notify, to_unsafe : Pointer(Void) to_unsafe, watch_closure(closure : GObject::Closure) : Nil watch_closure

Constructor methods inherited from class GObject::Object

cast(obj : GObject::Object) : self cast, new(pointer : Pointer(Void), transfer : GICrystal::Transfer)
new
new
, newv(object_type : UInt64, parameters : Enumerable(GObject::Parameter)) : self newv

Class methods inherited from class GObject::Object

cast?(obj : GObject::Object) : self | Nil cast?, compat_control(what : UInt64, data : Pointer(Void) | Nil) : UInt64 compat_control, g_type : UInt64 g_type, interface_find_property(g_iface : GObject::TypeInterface, property_name : String) : GObject::ParamSpec interface_find_property, interface_list_properties(g_iface : GObject::TypeInterface) : Enumerable(GObject::ParamSpec) interface_list_properties

Constructor Detail

def self.new #

Initialize a new IMContext.


[View source]
def self.new(*, input_hints : Gtk::InputHints | Nil = nil, input_purpose : Gtk::InputPurpose | Nil = nil) #

[View source]

Class Method Detail

def self.g_type : UInt64 #

Returns the type id (GType) registered in GLib type system.


[View source]

Instance Method Detail

def ==(other : self) #
Description copied from class Reference

Returns true if this reference is the same as other. Invokes same?.


def client_widget=(widget : Gtk::Widget | Nil) : Nil #

Set the client widget for the input context.

This is the Gtk::Widget holding the input focus. This widget is used in order to correctly position status windows, and may also be used for purposes internal to the input method.


[View source]
def commit_signal #

[View source]
def cursor_location=(area : Gdk::Rectangle) : Nil #

Notify the input method that a change in cursor position has been made.

The location is relative to the client widget.


[View source]
def delete_surrounding(offset : Int32, n_chars : Int32) : Bool #

Asks the widget that the input context is attached to delete characters around the cursor position by emitting the ::delete_surrounding signal.

Note that offset and n_chars are in characters not in bytes which differs from the usage other places in Gtk::IMContext.

In order to use this function, you should first call Gtk::IMContext#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.


[View source]
def delete_surrounding_signal #

[View source]
def filter_key(press : Bool, surface : Gdk::Surface, device : Gdk::Device, time : UInt32, keycode : UInt32, state : Gdk::ModifierType, group : Int32) : Bool #

Allow an input method to forward key press and release events to another input method without necessarily having a Gdk::Event available.


[View source]
def filter_keypress(event : Gdk::Event) : Bool #

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.


[View source]
def focus_in : Nil #

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.


[View source]
def focus_out : Nil #

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.


[View source]
def hash(hasher) #
Description copied from class Reference

See Object#hash(hasher)


def input_hints : Gtk::InputHints #

[View source]
def input_hints=(value : Gtk::InputHints) : Gtk::InputHints #

[View source]
def input_purpose : Gtk::InputPurpose #

[View source]
def input_purpose=(value : Gtk::InputPurpose) : Gtk::InputPurpose #

[View source]
def preedit_changed_signal #

[View source]
def preedit_end_signal #

[View source]
def preedit_start_signal #

[View source]
def preedit_string(str : String, attrs : Pango::AttrList, cursor_pos : Int32) : Nil #

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.


[View source]
def reset : Nil #

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.


[View source]
def retrieve_surrounding_signal #

[View source]
def set_surrounding(text : String, len : Int32, cursor_index : Int32) : Nil #

Sets surrounding context around the insertion point and preedit string.

This function is expected to be called in response to the [signal@Gtk.IMContext::retrieve-surrounding] signal, and will likely have no effect if called at other times.

DEPRECATED


[View source]
def set_surrounding_with_selection(text : String, len : Int32, cursor_index : Int32, anchor_index : Int32) : Nil #

Sets surrounding context around the insertion point and preedit string. This function is expected to be called in response to the Gtk::IMContext::#retrieve_surrounding signal, and will likely have no effect if called at other times.


[View source]
def surrounding(text : String, cursor_index : Int32) : Bool #

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 [signal@Gtk.IMContext::retrieve-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::IMContext#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.

DEPRECATED


[View source]
def surrounding_with_selection(text : String, cursor_index : Int32, anchor_index : Int32) : Bool #

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 [signal@Gtk.IMContext::retrieve-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::IMContext#surrounding_with_selection=.

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.


[View source]
def use_preedit=(use_preedit : Bool) : Nil #

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.


[View source]