IMContextProtocol
public protocol IMContextProtocol : ObjectProtocol
GtkIMContext defines the interface for GTK+ input methods. An input method
is used by GTK+ text input widgets like GtkEntry to map from key events to
Unicode character strings.
The default input method can be set programmatically via the
GtkSettings:gtk-im-module GtkSettings property. Alternatively, you may set
the GTK_IM_MODULE environment variable as documented in
Running GTK+ Applications.
The GtkEntry GtkEntry:im-module and GtkTextView GtkTextView:im-module
properties may also be used to set input methods for specific widget
instances. For instance, a certain entry widget might be expected to contain
certain characters which would be easier to input with a certain input
method.
An input method may consume multiple key events in sequence and finally output 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. For instance, the default GTK+ input method 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. Ctrl+Shift+u20AC for example 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
implements a subclass of GtkIMContext or GtkIMContextSimple and exports
these four functions:
(C Language Example):
void im_module_init(GTypeModule *module);
This function should register the GType of the GtkIMContext subclass which
implements the input method by means of g_type_module_register_type(). Note
that g_type_register_static() cannot be used as the type needs to be
registered dynamically.
(C Language Example):
void im_module_exit(void);
Here goes any cleanup code your input method might require on module unload.
(C Language Example):
void im_module_list(const GtkIMContextInfo ***contexts, int *n_contexts)
{
*contexts = info_list;
*n_contexts = G_N_ELEMENTS (info_list);
}
This function returns the list of input methods provided by the module. The
example implementation above shows a common solution and simply returns a
pointer to statically defined array of GtkIMContextInfo items for each
provided input method.
(C Language Example):
GtkIMContext * im_module_create(const gchar *context_id);
This function should return a pointer to a newly created instance of the
GtkIMContext subclass identified by context_id. The context ID is the same
as specified in the GtkIMContextInfo array returned by im_module_list().
After a new loadable input method module has been installed on the system,
the configuration file gtk.immodules needs to be
regenerated by gtk-query-immodules-3.0,
in order for the new input method to become available to GTK+ applications.
The IMContextProtocol protocol exposes the methods and properties of an underlying GtkIMContext instance.
The default implementation of these can be found in the protocol extension below.
For a concrete class that implements these methods and properties, see IMContext.
Alternatively, use IMContextRef as a lighweight, unowned reference if you already have an instance you just want to use.
-
Untyped pointer to the underlying
GtkIMContextinstance.Declaration
Swift
var ptr: UnsafeMutableRawPointer! { get } -
im_context_ptrDefault implementationTyped pointer to the underlying
GtkIMContextinstance.Default Implementation
Return the stored, untyped pointer as a typed pointer to the
GtkIMContextinstance.Declaration
Swift
var im_context_ptr: UnsafeMutablePointer<GtkIMContext>! { get } -
Required Initialiser for types conforming to
IMContextProtocolDeclaration
Swift
init(raw: UnsafeMutableRawPointer)
-
bind(property:Extension methodto: _: flags: transformFrom: transformTo: ) Bind a
IMContextPropertyNamesource property to a given target object.Declaration
Swift
@discardableResult @inlinable func bind<Q, T>(property source_property: IMContextPropertyName, to target: T, _ target_property: Q, flags f: BindingFlags = .default, transformFrom transform_from: @escaping GLibObject.ValueTransformer = { $0.transform(destValue: $1) }, transformTo transform_to: @escaping GLibObject.ValueTransformer = { $0.transform(destValue: $1) }) -> BindingRef! where Q : PropertyNameProtocol, T : ObjectProtocolParameters
source_propertythe source property to bind
targetthe target object to bind to
target_propertythe target property to bind to
flagsthe flags to pass to the
Bindingtransform_fromValueTransformerto use for forward transformationtransform_toValueTransformerto use for backwards transformationReturn Value
binding reference or
nilin case of an error -
get(property:Extension method) Get the value of a IMContext property
Declaration
Swift
@inlinable func get(property: IMContextPropertyName) -> GLibObject.ValueParameters
propertythe property to get the value for
Return Value
the value of the named property
-
set(property:Extension methodvalue: ) Set the value of a IMContext property. Note that this will only have an effect on properties that are writable and not construct-only!
Declaration
Swift
@inlinable func set(property: IMContextPropertyName, value v: GLibObject.Value)Parameters
propertythe property to get the value for
Return Value
the value of the named property
-
connect(signal:Extension methodflags: handler: ) Connect a Swift signal handler to the given, typed
IMContextSignalNamesignalDeclaration
Swift
@discardableResult @inlinable func connect(signal s: IMContextSignalName, flags f: ConnectFlags = ConnectFlags(0), handler h: @escaping SignalHandler) -> IntParameters
signalThe signal to connect
flagsThe connection flags to use
dataA pointer to user data to provide to the callback
destroyDataA
GClosureNotifyC function to destroy the data pointed to byuserDatahandlerThe Swift signal handler (function or callback) to invoke on the given signal
Return Value
The signal handler ID (always greater than 0 for successful connections)
-
connect(signal:Extension methodflags: data: destroyData: signalHandler: ) Connect a C signal handler to the given, typed
IMContextSignalNamesignalDeclaration
Swift
@discardableResult @inlinable func connect(signal s: IMContextSignalName, flags f: ConnectFlags = ConnectFlags(0), data userData: gpointer!, destroyData destructor: GClosureNotify? = nil, signalHandler h: @escaping GCallback) -> IntParameters
signalThe signal to connect
flagsThe connection flags to use
dataA pointer to user data to provide to the callback
destroyDataA
GClosureNotifyC function to destroy the data pointed to byuserDatasignalHandlerThe C function to be called on the given signal
Return Value
The signal handler ID (always greater than 0 for successful connections)
-
onCommit(flags:Extension methodhandler: ) The
commitsignal is emitted when a complete input sequence has been entered by the user. This can be a single character immediately after a key press or the final result of preediting.Note
This represents the underlyingcommitsignalDeclaration
Swift
@discardableResult @inlinable func onCommit(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: IMContextRef, _ str: String) -> Void) -> IntParameters
flagsFlags
unownedSelfReference to instance of self
strthe completed
character(s)entered by the userhandlerThe signal handler to call Run the given callback whenever the
commitsignal is emitted -
commitSignalExtension methodTyped
commitsignal for using theconnect(signal:)methodsDeclaration
Swift
static var commitSignal: IMContextSignalName { get } -
onDeleteSurrounding(flags:Extension methodhandler: ) The
delete-surroundingsignal is emitted when the input method needs to delete all or part of the context surrounding the cursor.Note
This represents the underlyingdelete-surroundingsignalDeclaration
Swift
@discardableResult @inlinable func onDeleteSurrounding(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: IMContextRef, _ offset: Int, _ nChars: Int) -> Bool) -> IntParameters
flagsFlags
unownedSelfReference to instance of self
offsetthe character offset from the cursor position of the text to be deleted. A negative value indicates a position before the cursor.
nCharsthe number of characters to be deleted
handlertrueif the signal was handled. Run the given callback whenever thedeleteSurroundingsignal is emitted -
deleteSurroundingSignalExtension methodTyped
delete-surroundingsignal for using theconnect(signal:)methodsDeclaration
Swift
static var deleteSurroundingSignal: IMContextSignalName { get } -
onPreeditChanged(flags:Extension methodhandler: ) The
preedit-changedsignal is emitted whenever the preedit sequence currently being entered has changed. It is also emitted at the end of a preedit sequence, in which casegtk_im_context_get_preedit_string()returns the empty string.Note
This represents the underlyingpreedit-changedsignalDeclaration
Swift
@discardableResult @inlinable func onPreeditChanged(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: IMContextRef) -> Void) -> IntParameters
flagsFlags
unownedSelfReference to instance of self
handlerThe signal handler to call Run the given callback whenever the
preeditChangedsignal is emitted -
preeditChangedSignalExtension methodTyped
preedit-changedsignal for using theconnect(signal:)methodsDeclaration
Swift
static var preeditChangedSignal: IMContextSignalName { get } -
onPreeditEnd(flags:Extension methodhandler: ) The
preedit-endsignal is emitted when a preediting sequence has been completed or canceled.Note
This represents the underlyingpreedit-endsignalDeclaration
Swift
@discardableResult @inlinable func onPreeditEnd(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: IMContextRef) -> Void) -> IntParameters
flagsFlags
unownedSelfReference to instance of self
handlerThe signal handler to call Run the given callback whenever the
preeditEndsignal is emitted -
preeditEndSignalExtension methodTyped
preedit-endsignal for using theconnect(signal:)methodsDeclaration
Swift
static var preeditEndSignal: IMContextSignalName { get } -
onPreeditStart(flags:Extension methodhandler: ) The
preedit-startsignal is emitted when a new preediting sequence starts.Note
This represents the underlyingpreedit-startsignalDeclaration
Swift
@discardableResult @inlinable func onPreeditStart(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: IMContextRef) -> Void) -> IntParameters
flagsFlags
unownedSelfReference to instance of self
handlerThe signal handler to call Run the given callback whenever the
preeditStartsignal is emitted -
preeditStartSignalExtension methodTyped
preedit-startsignal for using theconnect(signal:)methodsDeclaration
Swift
static var preeditStartSignal: IMContextSignalName { get } -
onRetrieveSurrounding(flags:Extension methodhandler: ) The
retrieve-surroundingsignal is emitted when the input method requires the context surrounding the cursor. The callback should set the input method surrounding context by calling thegtk_im_context_set_surrounding()method.Note
This represents the underlyingretrieve-surroundingsignalDeclaration
Swift
@discardableResult @inlinable func onRetrieveSurrounding(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: IMContextRef) -> Bool) -> IntParameters
flagsFlags
unownedSelfReference to instance of self
handlertrueif the signal was handled. Run the given callback whenever theretrieveSurroundingsignal is emitted -
retrieveSurroundingSignalExtension methodTyped
retrieve-surroundingsignal for using theconnect(signal:)methodsDeclaration
Swift
static var retrieveSurroundingSignal: IMContextSignalName { get } -
onNotifyInputHints(flags:Extension methodhandler: ) The notify signal is emitted on an object when one of its properties has its value set through
g_object_set_property(),g_object_set(), et al.Note that getting this signal doesn’t itself guarantee that the value of the property has actually changed. When it is emitted is determined by the derived GObject class. If the implementor did not create the property with
G_PARAM_EXPLICIT_NOTIFY, then any call tog_object_set_property()results innotifybeing emitted, even if the new value is the same as the old. If they did passG_PARAM_EXPLICIT_NOTIFY, then this signal is emitted only when they explicitly callg_object_notify()org_object_notify_by_pspec(), and common practice is to do that only when the value has actually changed.This signal is typically used to obtain change notification for a single property, by specifying the property name as a detail in the
g_signal_connect()call, like this:(C Language Example):
g_signal_connect (text_view->buffer, "notify::paste-target-list", G_CALLBACK (gtk_text_view_target_list_notify), text_view)It is important to note that you must use canonical parameter names as detail strings for the notify signal.
Note
This represents the underlyingnotify::input-hintssignalDeclaration
Swift
@discardableResult @inlinable func onNotifyInputHints(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: IMContextRef, _ pspec: ParamSpecRef) -> Void) -> IntParameters
flagsFlags
unownedSelfReference to instance of self
pspecthe
GParamSpecof the property which changed.handlerThe signal handler to call Run the given callback whenever the
notifyInputHintssignal is emitted -
notifyInputHintsSignalExtension methodTyped
notify::input-hintssignal for using theconnect(signal:)methodsDeclaration
Swift
static var notifyInputHintsSignal: IMContextSignalName { get } -
onNotifyInputPurpose(flags:Extension methodhandler: ) The notify signal is emitted on an object when one of its properties has its value set through
g_object_set_property(),g_object_set(), et al.Note that getting this signal doesn’t itself guarantee that the value of the property has actually changed. When it is emitted is determined by the derived GObject class. If the implementor did not create the property with
G_PARAM_EXPLICIT_NOTIFY, then any call tog_object_set_property()results innotifybeing emitted, even if the new value is the same as the old. If they did passG_PARAM_EXPLICIT_NOTIFY, then this signal is emitted only when they explicitly callg_object_notify()org_object_notify_by_pspec(), and common practice is to do that only when the value has actually changed.This signal is typically used to obtain change notification for a single property, by specifying the property name as a detail in the
g_signal_connect()call, like this:(C Language Example):
g_signal_connect (text_view->buffer, "notify::paste-target-list", G_CALLBACK (gtk_text_view_target_list_notify), text_view)It is important to note that you must use canonical parameter names as detail strings for the notify signal.
Note
This represents the underlyingnotify::input-purposesignalDeclaration
Swift
@discardableResult @inlinable func onNotifyInputPurpose(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: IMContextRef, _ pspec: ParamSpecRef) -> Void) -> IntParameters
flagsFlags
unownedSelfReference to instance of self
pspecthe
GParamSpecof the property which changed.handlerThe signal handler to call Run the given callback whenever the
notifyInputPurposesignal is emitted -
notifyInputPurposeSignalExtension methodTyped
notify::input-purposesignal for using theconnect(signal:)methodsDeclaration
Swift
static var notifyInputPurposeSignal: IMContextSignalName { get }
-
deleteSurrounding(offset:Extension methodnChars: ) Asks the widget that the input context is attached to to delete characters around the cursor position by emitting the GtkIMContext
delete_surroundingsignal. Note thatoffsetandn_charsare in characters not in bytes which differs from the usage other places inGtkIMContext.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.
Declaration
Swift
@inlinable func deleteSurrounding(offset: Int, nChars: Int) -> Bool -
filterKeypress(event:Extension method) 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.Declaration
Swift
@inlinable func filterKeypress<EventKeyT>(event: EventKeyT) -> Bool where EventKeyT : EventKeyProtocol -
focusIn()Extension methodNotify 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.
Declaration
Swift
@inlinable func focusIn() -
focusOut()Extension methodNotify 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.
Declaration
Swift
@inlinable func focusOut() -
getPreedit(string:Extension methodattrs: cursorPos: ) 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.
Declaration
Swift
@inlinable func getPreedit(string str: UnsafeMutablePointer<UnsafeMutablePointer<gchar>?>!, attrs: UnsafeMutablePointer<UnsafeMutablePointer<PangoAttrList>?>!, cursorPos: UnsafeMutablePointer<gint>!) -
getSurrounding(text:Extension methodcursorIndex: ) 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_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 callinggtk_im_context_set_surrounding(). Note that there is no obligation for a widget to respond to theretrieve_surroundingsignal, so input methods must be prepared to function without context.Declaration
Swift
@inlinable func getSurrounding(text: UnsafeMutablePointer<UnsafeMutablePointer<gchar>?>!, cursorIndex: UnsafeMutablePointer<gint>!) -> Bool -
reset()Extension methodNotify 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.
Declaration
Swift
@inlinable func reset() -
setClient(window:Extension method) Set the client window for the input context; this is the
GdkWindowin 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.Declaration
Swift
@inlinable func setClient(window: Gdk.WindowRef? = nil) -
setClient(window:Extension method) Set the client window for the input context; this is the
GdkWindowin 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.Declaration
Swift
@inlinable func setClient<WindowT>(window: WindowT?) where WindowT : WindowProtocol -
setCursorLocation(area:Extension method) Notify the input method that a change in cursor position has been made. The location is relative to the client window.
Declaration
Swift
@inlinable func setCursorLocation<RectangleT>(area: RectangleT) where RectangleT : RectangleProtocol -
setSurrounding(text:Extension methodlen: cursorIndex: ) Sets surrounding context around the insertion point and preedit string. This function is expected to be called in response to the GtkIMContext
retrieve_surroundingsignal, and will likely have no effect if called at other times.Declaration
Swift
@inlinable func setSurrounding(text: UnsafePointer<gchar>!, len: Int, cursorIndex: Int) -
set(usePreedit:Extension method) Sets whether the IM context should use the preedit string to display feedback. If
use_preeditis 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.Declaration
Swift
@inlinable func set(usePreedit: Bool) -
parentInstanceExtension methodUndocumented
Declaration
Swift
@inlinable var parentInstance: GObject { get }
View on GitHub
Install in Dash
IMContextProtocol Protocol Reference