Class IMContext
- All Implemented Interfaces:
Proxy
- Direct Known Subclasses:
IMContext.IMContextImpl
,IMContextSimple
,IMMulticontext
,VimIMContext
GtkIMContext
defines the interface for GTK input methods.
GtkIMContext
is used by GTK text input widgets like GtkText
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 GtkIMContext
will emit
Gtk.IMContext::preedit-start
, Gtk.IMContext::preedit-changed
and Gtk.IMContext::preedit-end
signals.
For instance, the built-in GTK input method 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
IMMulticontext
.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
IMContext.Builder<B extends IMContext.Builder<B>>
Inner class implementing a builder pattern to construct a GObject with properties.static interface
Functional interface declaration of theCommitCallback
callback.static interface
Functional interface declaration of theDeleteSurroundingCallback
callback.static class
static class
The IMContextImpl type represents a native instance of the abstract IMContext class.static interface
Functional interface declaration of thePreeditChangedCallback
callback.static interface
Functional interface declaration of thePreeditEndCallback
callback.static interface
Functional interface declaration of thePreeditStartCallback
callback.static interface
Functional interface declaration of theRetrieveSurroundingCallback
callback.Nested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass
-
Constructor Summary
ConstructorDescriptionIMContext
(MemorySegment address) Create a IMContext proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
boolean
activateOsk
(@Nullable Event event) Requests the platform to show an on-screen keyboard for user input.protected boolean
activateOskWithEvent
(Event event) protected IMContext
asParent()
Returns this instance as if it were its parent type.static IMContext.Builder
<? extends IMContext.Builder> builder()
AIMContext.Builder
object constructs aIMContext
with the specified properties.protected void
Default handler of theGtk.IMContext::commit
signal.boolean
deleteSurrounding
(int offset, int nChars) Asks the widget that the input context is attached to delete characters around the cursor position by emitting the::delete_surrounding
signal.void
emitCommit
(String str) Emits the "commit" signal.boolean
emitDeleteSurrounding
(int offset, int nChars) Emits the "delete-surrounding" signal.void
Emits the "preedit-changed" signal.void
Emits the "preedit-end" signal.void
Emits the "preedit-start" signal.boolean
Emits the "retrieve-surrounding" signal.boolean
filterKey
(boolean press, Surface surface, Device device, int time, int keycode, Set<ModifierType> state, int group) Allow an input method to forward key press and release events to another input method without necessarily having aGdkEvent
available.boolean
filterKey
(boolean press, Surface surface, Device device, int time, int keycode, ModifierType state, int group) Allow an input method to forward key press and release events to another input method without necessarily having aGdkEvent
available.boolean
filterKeypress
(Event event) Allow an input method to internally handle key press and release events.void
focusIn()
Notify the input method that the widget to which this input context corresponds has gained focus.void
focusOut()
Notify the input method that the widget to which this input context corresponds has lost focus.static MemoryLayout
The memory layout of the native struct.void
Retrieve the current preedit string for the input context, and a list of attributes to apply to the string.boolean
getSurrounding
(Out<String> text, Out<Integer> cursorIndex) Deprecated.boolean
Retrieves context around the insertion point.static Type
getType()
Get the GType of the IMContext classonCommit
(IMContext.CommitCallback handler) The ::commit signal is emitted when a complete input sequence has been entered by the user.The ::delete-surrounding signal is emitted when the input method needs to delete all or part of the context surrounding the cursor.The ::preedit-changed signal is emitted whenever the preedit sequence currently being entered has changed.onPreeditEnd
(IMContext.PreeditEndCallback handler) The ::preedit-end signal is emitted when a preediting sequence has been completed or canceled.The ::preedit-start signal is emitted when a new preediting sequence starts.The ::retrieve-surrounding signal is emitted when the input method requires the context surrounding the cursor.protected void
Default handler of theGtk.IMContext::preedit-changed
signal.protected void
Default handler of theGtk.IMContext::preedit-end
signal.protected void
Default handler of theGtk.IMContext::preedit-start
signal.void
reset()
Notify the input method that a change such as a change in cursor position has been made.protected boolean
Default handler of theGtk.IMContext::retrieve-surrounding
signal.void
setClientWidget
(@Nullable Widget widget) Set the client widget for the input context.void
setCursorLocation
(Rectangle area) Notify the input method that a change in cursor position has been made.void
setSurrounding
(String text, int len, int cursorIndex) Deprecated.void
setSurroundingWithSelection
(String text, int len, int cursorIndex, int anchorIndex) Sets surrounding context around the insertion point and preedit string.void
setUsePreedit
(boolean usePreedit) Sets whether the IM context should use the preedit string to display feedback.Methods inherited from class org.gnome.gobject.GObject
addToggleRef, addWeakPointer, bindProperty, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, connect, constructed, disconnect, dispatchPropertiesChanged, dispose, dupData, dupQdata, emit, emitNotify, finalize_, forceFloating, freezeNotify, get, getData, getProperty, getProperty, getProperty, getQdata, getv, interfaceFindProperty, interfaceInstallProperty, interfaceListProperties, isFloating, newInstance, newInstance, newInstance, newInstance, newv, notify_, notify_, notifyByPspec, onNotify, ref, refSink, removeToggleRef, removeWeakPointer, replaceData, replaceQdata, runDispose, set, setData, setDataFull, setProperty, setProperty, setProperty, setQdata, setQdataFull, setv, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref, withProperties
Methods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, getPrivate, readGClass, writeGClass
Methods inherited from class io.github.jwharm.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
IMContext
Create a IMContext proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
-
Method Details
-
getType
-
getMemoryLayout
The memory layout of the native struct.- Returns:
- the memory layout
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuper
keyword, but will set the native typeclass function pointers to the parent type. When overriding a native virtual method in Java, "chaining up" withsuper.methodName()
doesn't work, because it invokes the overridden function pointer again. To chain up, callasParent().methodName()
. This will call the native function pointer of this virtual method in the typeclass of the parent type. -
activateOsk
Requests the platform to show an on-screen keyboard for user input.This method will return
true
if this request was actually performed to the platform, other environmental factors may result in an on-screen keyboard effectively not showing up.- Parameters:
event
- aEvent
- Returns:
true
if an on-screen keyboard could be requested to the platform.
-
deleteSurrounding
public boolean deleteSurrounding(int offset, int nChars) 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
andnChars
are in characters not in bytes which differs from the usage other places inGtkIMContext
.In order to use this function, you should first call
getSurrounding(io.github.jwharm.javagi.base.Out<java.lang.String>, io.github.jwharm.javagi.base.Out<java.lang.Integer>)
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 substitutions in the existing text in response to new input. It is not useful for applications.
- Parameters:
offset
- offset from cursor position in chars; a negative value means start before the cursor.nChars
- number of characters to delete.- Returns:
true
if the signal was handled.
-
filterKey
public boolean filterKey(boolean press, Surface surface, Device device, int time, int keycode, Set<ModifierType> state, int group) Allow an input method to forward key press and release events to another input method without necessarily having aGdkEvent
available.- Parameters:
press
- whether to forward a key press or release eventsurface
- the surface the event is fordevice
- the device that the event is fortime
- the timestamp for the eventkeycode
- the keycode for the eventstate
- modifier state for the eventgroup
- the active keyboard group for the event- Returns:
true
if the input method handled the key event.
-
filterKey
public boolean filterKey(boolean press, Surface surface, Device device, int time, int keycode, ModifierType state, int group) Allow an input method to forward key press and release events to another input method without necessarily having aGdkEvent
available.- Parameters:
press
- whether to forward a key press or release eventsurface
- the surface the event is fordevice
- the device that the event is fortime
- the timestamp for the eventkeycode
- the keycode for the eventstate
- modifier state for the eventgroup
- the active keyboard group for the event- Returns:
true
if the input method handled the key event.
-
filterKeypress
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.- Parameters:
event
- the key event- Returns:
true
if the input method handled the key event.
-
focusIn
public void focusIn()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.
-
focusOut
public void focusOut()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.
-
getPreeditString
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.
- Parameters:
str
- location to store the retrieved string. The string retrieved must be freed with g_free().attrs
- location to store the retrieved attribute list. When you are done with this list, you must unreference it withAttrList.unref()
.cursorPos
- location to store position of cursor (in characters) within the preedit string.
-
getSurrounding
Deprecated.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
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 callingsetSurrounding(java.lang.String, int, int)
.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.- Parameters:
text
- location to store a UTF-8 encoded string of text holding context around the insertion point. If the function returnstrue
, then you must free the result stored in this location with g_free().cursorIndex
- location to store byte index of the insertion cursor withintext
.- Returns:
TRUE
if surrounding text was provided; in this case you must free the result stored intext
.
-
getSurroundingWithSelection
public boolean getSurroundingWithSelection(Out<String> text, Out<Integer> cursorIndex, Out<Integer> anchorIndex) 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
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 callingsetSurroundingWithSelection(java.lang.String, int, int, int)
.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.- Parameters:
text
- location to store a UTF-8 encoded string of text holding context around the insertion point. If the function returnstrue
, then you must free the result stored in this location with g_free().cursorIndex
- location to store byte index of the insertion cursor withintext
.anchorIndex
- location to store byte index of the selection bound withintext
- Returns:
TRUE
if surrounding text was provided; in this case you must free the result stored intext
.
-
reset
public void reset()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.
-
setClientWidget
Set the client widget for the input context.This is the
GtkWidget
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.- Parameters:
widget
- the client widget. This may benull
to indicate that the previous client widget no longer exists.
-
setCursorLocation
Notify the input method that a change in cursor position has been made.The location is relative to the client widget.
- Parameters:
area
- new location
-
setSurrounding
Deprecated.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.- Parameters:
text
- text surrounding the insertion point, as UTF-8. the preedit string should not be included withintext
len
- the length oftext
, or -1 iftext
is nul-terminatedcursorIndex
- the byte index of the insertion cursor withintext
.
-
setSurroundingWithSelection
Sets surrounding context around the insertion point and preedit string. This function is expected to be called in response to theGtk.IMContext::retrieve_surrounding
signal, and will likely have no effect if called at other times.- Parameters:
text
- text surrounding the insertion point, as UTF-8. the preedit string should not be included withintext
len
- the length oftext
, or -1 iftext
is nul-terminatedcursorIndex
- the byte index of the insertion cursor withintext
anchorIndex
- the byte index of the selection bound withintext
-
setUsePreedit
public void setUsePreedit(boolean usePreedit) Sets whether the IM context should use the preedit string to display feedback.If
usePreedit
isfalse
(default istrue
), then the IM context may use some other method to display feedback, such as displaying it in a child of the root window.- Parameters:
usePreedit
- whether the IM context should use the preedit string.
-
activateOsk
protected void activateOsk() -
activateOskWithEvent
-
commit
Default handler of theGtk.IMContext::commit
signal. -
preeditChanged
protected void preeditChanged()Default handler of theGtk.IMContext::preedit-changed
signal. -
preeditEnd
protected void preeditEnd()Default handler of theGtk.IMContext::preedit-end
signal. -
preeditStart
protected void preeditStart()Default handler of theGtk.IMContext::preedit-start
signal. -
retrieveSurrounding
protected boolean retrieveSurrounding()Default handler of theGtk.IMContext::retrieve-surrounding
signal. -
onCommit
The ::commit signal is emitted when a complete input sequence has been entered by the user.If the commit comes after a preediting sequence, the ::commit signal is emitted after ::preedit-end.
This can be a single character immediately after a key press or the final result of preediting.
- Parameters:
handler
- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitCommit
Emits the "commit" signal. SeeonCommit(org.gnome.gtk.IMContext.CommitCallback)
. -
onDeleteSurrounding
public SignalConnection<IMContext.DeleteSurroundingCallback> onDeleteSurrounding(IMContext.DeleteSurroundingCallback handler) The ::delete-surrounding signal is emitted when the input method needs to delete all or part of the context surrounding the cursor.- Parameters:
handler
- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitDeleteSurrounding
public boolean emitDeleteSurrounding(int offset, int nChars) Emits the "delete-surrounding" signal. SeeonDeleteSurrounding(org.gnome.gtk.IMContext.DeleteSurroundingCallback)
. -
onPreeditChanged
public SignalConnection<IMContext.PreeditChangedCallback> onPreeditChanged(IMContext.PreeditChangedCallback handler) 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
getPreeditString(io.github.jwharm.javagi.base.Out<java.lang.String>, io.github.jwharm.javagi.base.Out<org.gnome.pango.AttrList>, io.github.jwharm.javagi.base.Out<java.lang.Integer>)
returns the empty string.- Parameters:
handler
- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitPreeditChanged
public void emitPreeditChanged()Emits the "preedit-changed" signal. SeeonPreeditChanged(org.gnome.gtk.IMContext.PreeditChangedCallback)
. -
onPreeditEnd
public SignalConnection<IMContext.PreeditEndCallback> onPreeditEnd(IMContext.PreeditEndCallback handler) The ::preedit-end signal is emitted when a preediting sequence has been completed or canceled.- Parameters:
handler
- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitPreeditEnd
public void emitPreeditEnd()Emits the "preedit-end" signal. SeeonPreeditEnd(org.gnome.gtk.IMContext.PreeditEndCallback)
. -
onPreeditStart
public SignalConnection<IMContext.PreeditStartCallback> onPreeditStart(IMContext.PreeditStartCallback handler) The ::preedit-start signal is emitted when a new preediting sequence starts.- Parameters:
handler
- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitPreeditStart
public void emitPreeditStart()Emits the "preedit-start" signal. SeeonPreeditStart(org.gnome.gtk.IMContext.PreeditStartCallback)
. -
onRetrieveSurrounding
public SignalConnection<IMContext.RetrieveSurroundingCallback> onRetrieveSurrounding(IMContext.RetrieveSurroundingCallback handler) 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
setSurrounding(java.lang.String, int, int)
method.- Parameters:
handler
- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitRetrieveSurrounding
public boolean emitRetrieveSurrounding()Emits the "retrieve-surrounding" signal. SeeonRetrieveSurrounding(org.gnome.gtk.IMContext.RetrieveSurroundingCallback)
. -
builder
AIMContext.Builder
object constructs aIMContext
with the specified properties. Use the variousset...()
methods to set properties, and finish construction withIMContext.Builder.build()
.
-
getSurroundingWithSelection(io.github.jwharm.javagi.base.Out<java.lang.String>, io.github.jwharm.javagi.base.Out<java.lang.Integer>, io.github.jwharm.javagi.base.Out<java.lang.Integer>)
instead.