Class IMContext
- All Implemented Interfaces:
Proxy
- Direct Known Subclasses:
IMContext.IMContext$Impl,IMContextSimple,IMMulticontext,VimIMContext
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
Nested ClassesModifier and TypeClassDescriptionstatic classIMContext.Builder<B extends IMContext.Builder<B>>Inner class implementing a builder pattern to construct a GObject with properties.static interfaceFunctional interface declaration of theCommitCallbackcallback.static interfaceFunctional interface declaration of theDeleteSurroundingCallbackcallback.static classThe IMContext$Impl type represents a native instance of the abstract IMContext class.static classstatic interfaceFunctional interface declaration of thePreeditChangedCallbackcallback.static interfaceFunctional interface declaration of thePreeditEndCallbackcallback.static interfaceFunctional interface declaration of thePreeditStartCallbackcallback.static interfaceFunctional interface declaration of theRetrieveSurroundingCallbackcallback.Nested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new IMContext.IMContext(MemorySegment address) Create a IMContext proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidbooleanactivateOsk(@Nullable Event event) Requests the platform to show an on-screen keyboard for user input.protected booleanactivateOskWithEvent(Event event) protected IMContextasParent()Returns this instance as if it were its parent type.protected voidDefault handler of theGtk.IMContext::commitsignal.booleandeleteSurrounding(int offset, int nChars) Asks the widget that the input context is attached to delete characters around the cursor position by emitting the::delete_surroundingsignal.voidemitCommit(String str) Emits the "commit" signal.booleanemitDeleteSurrounding(int offset, int nChars) Emits the "delete-surrounding" signal.voidEmits the "preedit-changed" signal.voidEmits the "preedit-end" signal.voidEmits the "preedit-start" signal.booleanEmits the "retrieve-surrounding" signal.booleanfilterKey(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 aGdkEventavailable.booleanfilterKey(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 aGdkEventavailable.booleanfilterKeypress(Event event) Allow an input method to internally handle key press and release events.voidfocusIn()Notify the input method that the widget to which this input context corresponds has gained focus.voidfocusOut()Notify the input method that the widget to which this input context corresponds has lost focus.static MemoryLayoutThe memory layout of the native struct.voidRetrieve the current preedit string for the input context, and a list of attributes to apply to the string.booleangetSurrounding(Out<String> text, Out<Integer> cursorIndex) Deprecated.booleanRetrieves context around the insertion point.static @Nullable TypegetType()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 voidDefault handler of theGtk.IMContext::preedit-changedsignal.protected voidDefault handler of theGtk.IMContext::preedit-endsignal.protected voidDefault handler of theGtk.IMContext::preedit-startsignal.voidreset()Notify the input method that a change such as a change in cursor position has been made.protected booleanDefault handler of theGtk.IMContext::retrieve-surroundingsignal.voidsetClientWidget(@Nullable Widget widget) Set the client widget for the input context.voidsetCursorLocation(Rectangle area) Notify the input method that a change in cursor position has been made.voidsetSurrounding(String text, int len, int cursorIndex) Deprecated.voidsetSurroundingWithSelection(String text, int len, int cursorIndex, int anchorIndex) Sets surrounding context around the insertion point and preedit string.voidsetUsePreedit(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, builder, 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, 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, withPropertiesMethods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, cast, getPrivate, readGClass, writeGClassMethods inherited from class org.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
-
IMContext
public IMContext()Creates a new IMContext.
-
-
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 Javasuperkeyword, 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
trueif 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:
trueif an on-screen keyboard could be requested to the platform.- Since:
- 4.14
-
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_surroundingsignal.Note that
offsetandnCharsare in characters not in bytes which differs from the usage other places inGtkIMContext.In order to use this function, you should first call
getSurrounding(org.javagi.base.Out<java.lang.String>, org.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:
trueif 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 aGdkEventavailable.- 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:
trueif 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 aGdkEventavailable.- 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:
trueif 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:
trueif 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-surroundingsignal 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-surroundingsignal, 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:
TRUEif 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-surroundingsignal 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-surroundingsignal, 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:
TRUEif surrounding text was provided; in this case you must free the result stored intext.- Since:
- 4.2
-
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
GtkWidgetholding 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 benullto 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-surroundingsignal, 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 withintextlen- the length oftext,or -1 iftextis 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_surroundingsignal, 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 withintextlen- the length oftext,or -1 iftextis nul-terminatedcursorIndex- the byte index of the insertion cursor withintextanchorIndex- the byte index of the selection bound withintext- Since:
- 4.2
-
setUsePreedit
public void setUsePreedit(boolean usePreedit) Sets whether the IM context should use the preedit string to display feedback.If
usePreeditisfalse(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::commitsignal. -
preeditChanged
protected void preeditChanged()Default handler of theGtk.IMContext::preedit-changedsignal. -
preeditEnd
protected void preeditEnd()Default handler of theGtk.IMContext::preedit-endsignal. -
preeditStart
protected void preeditStart()Default handler of theGtk.IMContext::preedit-startsignal. -
retrieveSurrounding
protected boolean retrieveSurrounding()Default handler of theGtk.IMContext::retrieve-surroundingsignal. -
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(org.javagi.base.Out<java.lang.String>, org.javagi.base.Out<org.gnome.pango.AttrList>, org.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).
-
getSurroundingWithSelection(org.javagi.base.Out<java.lang.String>, org.javagi.base.Out<java.lang.Integer>, org.javagi.base.Out<java.lang.Integer>)instead.