Next: , Previous: GtkWidget, Up: Top


139 GtkIMContext

Base class for input method contexts

139.1 Overview

139.2 Usage

— Class: <gtk-im-context>

Derives from <gobject>.

This class defines no direct slots.

— Signal on <gtk-im-context>: preedit-start
— Signal on <gtk-im-context>: preedit-end
— Signal on <gtk-im-context>: preedit-changed
— Signal on <gtk-im-context>: commit (arg0 <gchararray>)
— Signal on <gtk-im-context>: retrieve-surrounding ⇒ <gboolean>
— Signal on <gtk-im-context>: delete-surrounding (arg0 <gint>) (arg1 <gint>) ⇒ <gboolean>
— Function: gtk-im-context-set-client-window (self <gtk-im-context>) (window <gdk-window>)
— Method: set-client-window

Set the client window for the input context; this is the <gdk-window> in which the input appears. This window is used in order to correctly position status windows, and may also be used for purposes internal to the input method.

context
a <gtk-im-context>
window
the client window. This may be ‘#f’ to indicate that the previous client window no longer exists.
— Function: gtk-im-context-filter-keypress (self <gtk-im-context>) (event <gdk-event-key>) ⇒  (ret bool)
— Method: filter-keypress

Allow an input method to internally handle key press and release events. If this function returns ‘#t’, then no further processing should be done for this key event.

context
a <gtk-im-context>
event
the key event
ret
#t’ if the input method handled the key event.
— Function: gtk-im-context-focus-in (self <gtk-im-context>)
— Method: focus-in

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.

context
a <gtk-im-context>
— Function: gtk-im-context-focus-out (self <gtk-im-context>)
— Method: focus-out

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.

context
a <gtk-im-context>
— Function: gtk-im-context-reset (self <gtk-im-context>)
— Method: 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.

context
a <gtk-im-context>
— Function: gtk-im-context-set-cursor-location (self <gtk-im-context>) (area <gdk-rectangle>)
— Method: set-cursor-location

Notify the input method that a change in cursor position has been made. The location is relative to the client window.

context
a <gtk-im-context>
area
new location
— Function: gtk-im-context-set-use-preedit (self <gtk-im-context>) (use_preedit bool)
— Method: set-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.

context
a <gtk-im-context>
use-preedit
whether the IM context should use the preedit string.
— Function: gtk-im-context-set-surrounding (self <gtk-im-context>) (text mchars) (len int) (cursor_index int)
— Method: set-surrounding

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

context
a <gtk-im-context>
text
text surrounding the insertion point, as UTF-8. the preedit string should not be included within text.
len
the length of text, or -1 if text is nul-terminated
cursor-index
the byte index of the insertion cursor within text.
— Function: gtk-im-context-get-surrounding (self <gtk-im-context>) ⇒  (ret bool) (text mchars) (cursor_index int)
— Method: get-surrounding

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 GtkIMContext::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-im-context-set-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.

context
a <gtk-im-context>
text
location to store a UTF-8 encoded string of text holding context around the insertion point. If the function returns ‘#t’, 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.
ret
#t’ if surrounding text was provided; in this case you must free the result stored in *text.
— Function: gtk-im-context-delete-surrounding (self <gtk-im-context>) (offset int) (n_chars int) ⇒  (ret bool)
— Method: delete-surrounding

Asks the widget that the input context is attached to to delete characters around the cursor position by emitting the GtkIMContext::delete_surrounding signal. Note that offset and n-chars are in characters not in bytes which differs from the usage other places in <gtk-im-context>.

In order to use this function, you should first call gtk-im-context-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.

context
a <gtk-im-context>
offset
offset from cursor position in chars; a negative value means start before the cursor.
n-chars
number of characters to delete.
ret
#t’ if the signal was handled.