class Gtk::IMContext
- Gtk::IMContext
- GObject::Object
- Reference
- Object
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.crConstructors
-
.new
Initialize a new
IMContext
. - .new(*, input_hints : Gtk::InputHints? = nil, input_purpose : Gtk::InputPurpose? = nil)
Class Method Summary
-
.g_type : UInt64
Returns the type id (GType) registered in GLib type system.
Instance Method Summary
-
#client_widget=(widget : Gtk::Widget?) : Nil
Set the client widget for the input context.
- #commit_signal
-
#cursor_location=(area : Gdk::Rectangle) : Nil
Notify the input method that a change in cursor position has been made.
-
#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. - #delete_surrounding_signal
-
#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. -
#filter_keypress(event : Gdk::Event) : Bool
Allow an input method to internally handle key press and release events.
-
#focus_in : Nil
Notify the input method that the widget to which this input context corresponds has gained focus.
-
#focus_out : Nil
Notify the input method that the widget to which this input context corresponds has lost focus.
- #input_hints : Gtk::InputHints
- #input_hints=(value : Gtk::InputHints) : Gtk::InputHints
- #input_purpose : Gtk::InputPurpose
- #input_purpose=(value : Gtk::InputPurpose) : Gtk::InputPurpose
- #preedit_changed_signal
- #preedit_end_signal
- #preedit_start_signal
-
#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.
-
#reset : Nil
Notify the input method that a change such as a change in cursor position has been made.
- #retrieve_surrounding_signal
-
#set_surrounding(text : String, len : Int32, cursor_index : Int32) : Nil
Sets surrounding context around the insertion point and preedit string.
-
#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.
-
#surrounding(text : String, cursor_index : Int32) : Bool
Retrieves context around the insertion point.
-
#surrounding_with_selection(text : String, cursor_index : Int32, anchor_index : Int32) : Bool
Retrieves context around the insertion point.
-
#use_preedit=(use_preedit : Bool) : Nil
Sets whether the IM context should use the preedit string to display feedback.
Instance methods inherited from class GObject::Object
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)?
data,
finalize
finalize,
freeze_notify : Nil
freeze_notify,
getv(names : Enumerable(String), values : Enumerable(_)) : Nil
getv,
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)?
qdata,
ref_count : UInt32
ref_count,
run_dispose : Nil
run_dispose,
set_data(key : String, data : Pointer(Void)?) : Nil
set_data,
set_property(property_name : String, value : _) : Nil
set_property,
steal_data(key : String) : Pointer(Void)?
steal_data,
steal_qdata(quark : UInt32) : Pointer(Void)?
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,
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
compat_control(what : UInt64, data : Pointer(Void)?) : 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
Class Method Detail
Instance Method Detail
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.
Notify the input method that a change in cursor position has been made.
The location is relative to the client widget.
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.
Allow an input method to forward key press and release events
to another input method without necessarily having a Gdk::Event
available.
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.
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.
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.
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.
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.
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.
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.
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.
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.