Package ch.bailu.gtk.gtk
Class IMContext
java.lang.Object
ch.bailu.gtk.type.Type
ch.bailu.gtk.type.Pointer
ch.bailu.gtk.gobject.Object
ch.bailu.gtk.gtk.IMContext
- All Implemented Interfaces:
PointerInterface
- Direct Known Subclasses:
IMContextSimple
,IMMulticontext
`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
[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 [class@Gtk.IMContextSimple]
implements the input of arbitrary Unicode code points by holding down the
<kbd>Control</kbd> and <kbd>Shift</kbd> keys and then typing <kbd>u</kbd>
followed by the hexadecimal digits of the code point. When releasing the
<kbd>Control</kbd> and <kbd>Shift</kbd> 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
[class@Gtk.IMMulticontext].
`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
[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 [class@Gtk.IMContextSimple]
implements the input of arbitrary Unicode code points by holding down the
<kbd>Control</kbd> and <kbd>Shift</kbd> keys and then typing <kbd>u</kbd>
followed by the hexadecimal digits of the code point. When releasing the
<kbd>Control</kbd> and <kbd>Shift</kbd> 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
[class@Gtk.IMMulticontext].
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
static interface
static interface
static interface
static interface
static interface
Nested classes/interfaces inherited from class ch.bailu.gtk.gobject.Object
Object.OnBindingTransformFunc, Object.OnDestroyNotify, Object.OnDuplicateFunc, Object.OnNotify, Object.OnToggleNotify, Object.OnWeakNotify
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
static final String
static final String
static final String
static final String
static final String
Fields inherited from class ch.bailu.gtk.gobject.Object
SIGNAL_ON_NOTIFY
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
deleteSurrounding
(int offset, int n_chars) Asks the widget that the input context is attached to delete
characters around the cursor position by emitting the
`::delete_surrounding` signal.boolean
filterKey
(boolean press, Surface surface, Device device, int time, int keycode, int state, int group) Allow an input method to forward key press and release events
to another input method without necessarily having a `GdkEvent`
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 ClassHandler
static int
static long
static TypeSystem.TypeSize
boolean
getSurroundingWithSelection
(Strs text, Int cursor_index, Int anchor_index) Retrieves context around the insertion point.static long
static TypeSystem.TypeSize
onCommit
(IMContext.OnCommit signal) Connect to signal "commit".Connect to signal "delete-surrounding".Connect to signal "preedit-changed".onPreeditEnd
(IMContext.OnPreeditEnd signal) Connect to signal "preedit-end".Connect to signal "preedit-start".Connect to signal "retrieve-surrounding".void
reset()
Notify the input method that a change such as a change in cursor
position has been made.void
setClientWidget
(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
setSurroundingWithSelection
(Str text, int len, int cursor_index, int anchor_index) Sets surrounding context around the insertion point and preedit
string.void
setSurroundingWithSelection
(String text, int len, int cursor_index, int anchor_index) Sets surrounding context around the insertion point and preedit
string.void
setUsePreedit
(boolean use_preedit) Sets whether the IM context should use the preedit string
to display feedback.Methods inherited from class ch.bailu.gtk.gobject.Object
addToggleRef, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, disconnect, disconnect, dupData, dupData, dupQdata, forceFloating, freezeNotify, get, get, getData, getData, getProperty, getProperty, getQdata, interfaceFindProperty, interfaceInstallProperty, isFloating, notify, notify, notifyByPspec, onNotify, ref, refSink, removeToggleRef, replaceData, replaceData, replaceQdata, runDispose, set, set, setData, setData, setDataFull, setDataFull, setProperty, setProperty, setQdata, setQdataFull, stealData, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref
Methods inherited from class ch.bailu.gtk.type.Pointer
asCPointer, cast, connectSignal, disconnectSignals, disconnectSignals, equals, hashCode, throwIfNull, throwNullPointerException, toString, unregisterCallbacks, unregisterCallbacks
Methods inherited from class ch.bailu.gtk.type.Type
asCPointer, asCPointer, asCPointerNotNull, asJnaPointer, asJnaPointer, asPointer, asPointer, cast, cast, throwIfNull
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface ch.bailu.gtk.type.PointerInterface
asCPointerNotNull, asJnaPointer, asPointer, isNotNull, isNull
-
Field Details
-
SIGNAL_ON_COMMIT
- See Also:
-
SIGNAL_ON_DELETE_SURROUNDING
- See Also:
-
SIGNAL_ON_PREEDIT_CHANGED
- See Also:
-
SIGNAL_ON_PREEDIT_END
- See Also:
-
SIGNAL_ON_PREEDIT_START
- See Also:
-
SIGNAL_ON_RETRIEVE_SURROUNDING
- See Also:
-
-
Constructor Details
-
IMContext
-
-
Method Details
-
getClassHandler
-
deleteSurrounding
public boolean deleteSurrounding(int offset, int n_chars) 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 `GtkIMContext`.
In order to use this function, you should first call
[method@Gtk.IMContext.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.- Parameters:
offset
- offset from cursor position in chars; a negative value means start before the cursor.n_chars
- number of characters to delete.- Returns:
- %TRUE if the signal was handled.
-
filterKey
public boolean filterKey(boolean press, @Nonnull Surface surface, @Nonnull Device device, int time, int keycode, int state, int group) Allow an input method to forward key press and release events
to another input method without necessarily having a `GdkEvent`
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. -
getSurroundingWithSelection
public boolean getSurroundingWithSelection(@Nonnull Strs text, @Nonnull Int cursor_index, @Nonnull Int anchor_index) 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
[method@Gtk.IMContext.set_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.- Parameters:
text
- location to store a UTF-8 encoded string of text holding context around the insertion point. If the function returns %TRUE, then you must free the result stored in this location with g_free().cursor_index
- location to store byte index of the insertion cursor within @text.anchor_index
- location to store byte index of the selection bound within @text- Returns:
- `TRUE` if surrounding text was provided; in this case you must free the result stored in `text`.
-
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 be %NULL 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
-
setSurroundingWithSelection
public void setSurroundingWithSelection(@Nonnull Str text, int len, int cursor_index, int anchor_index) 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.- Parameters:
text
- text surrounding the insertion point, as UTF-8. the preedit string should not be included within @textlen
- the length of @text, or -1 if @text is nul-terminatedcursor_index
- the byte index of the insertion cursor within @textanchor_index
- the byte index of the selection bound within @text
-
setSurroundingWithSelection
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.- Parameters:
text
- text surrounding the insertion point, as UTF-8. the preedit string should not be included within @textlen
- the length of @text, or -1 if @text is nul-terminatedcursor_index
- the byte index of the insertion cursor within @textanchor_index
- the byte index of the selection bound within @text
-
setUsePreedit
public void setUsePreedit(boolean use_preedit) 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.- Parameters:
use_preedit
- whether the IM context should use the preedit string.
-
onCommit
Connect to signal "commit".
SeeIMContext.OnCommit.onCommit(ch.bailu.gtk.type.Str)
for signal description.
FieldSIGNAL_ON_COMMIT
contains original signal name and can be used as resource reference.- Parameters:
signal
- callback function (lambda).- Returns:
SignalHandler
. Can be used to disconnect signal and to release callback function.
-
onDeleteSurrounding
Connect to signal "delete-surrounding".
SeeIMContext.OnDeleteSurrounding.onDeleteSurrounding(int, int)
for signal description.
FieldSIGNAL_ON_DELETE_SURROUNDING
contains original signal name and can be used as resource reference.- Parameters:
signal
- callback function (lambda).- Returns:
SignalHandler
. Can be used to disconnect signal and to release callback function.
-
onPreeditChanged
Connect to signal "preedit-changed".
SeeIMContext.OnPreeditChanged.onPreeditChanged()
for signal description.
FieldSIGNAL_ON_PREEDIT_CHANGED
contains original signal name and can be used as resource reference.- Parameters:
signal
- callback function (lambda).- Returns:
SignalHandler
. Can be used to disconnect signal and to release callback function.
-
onPreeditEnd
Connect to signal "preedit-end".
SeeIMContext.OnPreeditEnd.onPreeditEnd()
for signal description.
FieldSIGNAL_ON_PREEDIT_END
contains original signal name and can be used as resource reference.- Parameters:
signal
- callback function (lambda).- Returns:
SignalHandler
. Can be used to disconnect signal and to release callback function.
-
onPreeditStart
Connect to signal "preedit-start".
SeeIMContext.OnPreeditStart.onPreeditStart()
for signal description.
FieldSIGNAL_ON_PREEDIT_START
contains original signal name and can be used as resource reference.- Parameters:
signal
- callback function (lambda).- Returns:
SignalHandler
. Can be used to disconnect signal and to release callback function.
-
onRetrieveSurrounding
Connect to signal "retrieve-surrounding".
SeeIMContext.OnRetrieveSurrounding.onRetrieveSurrounding()
for signal description.
FieldSIGNAL_ON_RETRIEVE_SURROUNDING
contains original signal name and can be used as resource reference.- Parameters:
signal
- callback function (lambda).- Returns:
SignalHandler
. Can be used to disconnect signal and to release callback function.
-
getTypeID
public static long getTypeID() -
getParentTypeID
public static long getParentTypeID() -
getTypeSize
-
getParentTypeSize
-
getInstanceSize
public static int getInstanceSize()
-