IMContextProtocol
public protocol IMContextProtocol : ObjectProtocol
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
[signalGtk.IMContext::preedit-start], [signalGtk.IMContext::preedit-changed]
and [signalGtk.IMContext::preedit-end] signals.
For instance, the built-in GTK input method [classGtk.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
[classGtk.IMMulticontext].
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.If the commit comes after a preediting sequence, the
commitsignal is emitted afterpreedit-end.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 case [method
Gtk.IMContext.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 the [method
Gtk.IMContext.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 delete characters around the cursor position by emitting the
delete_surroundingsignal.Note that
offsetandn_charsare in characters not in bytes which differs from the usage other places inGtkIMContext.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.
Declaration
Swift
@inlinable func deleteSurrounding(offset: Int, nChars: Int) -> Bool -
filterKey(press:Extension methodsurface: device: time: keycode: state: group: ) Allow an input method to forward key press and release events to another input method without necessarily having a
GdkEventavailable.Declaration
Swift
@inlinable func filterKey<DeviceT, SurfaceT>(press: Bool, surface: SurfaceT, device: DeviceT, time: guint32, keycode: Int, state: Gdk.ModifierType, group: Int) -> Bool where DeviceT : DeviceProtocol, SurfaceT : SurfaceProtocol -
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<EventT>(event: EventT) -> Bool where EventT : EventProtocol -
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() -
getPreeditString(str: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 getPreeditString(str: UnsafeMutablePointer<UnsafeMutablePointer<CChar>?>!, 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 [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 [methodGtk.IMContext.set_surrounding].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.get_surrounding is deprecated: Use [method@Gtk.IMContext.get_surrounding_with_selection] instead.
Declaration
Swift
@available(*, deprecated) @inlinable func getSurrounding(text: UnsafeMutablePointer<UnsafeMutablePointer<CChar>?>!, cursorIndex: UnsafeMutablePointer<gint>!) -> Bool -
getSurroundingWithSelection(text:Extension methodcursorIndex: 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 [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 [methodGtk.IMContext.set_surrounding_with_selection].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.Declaration
Swift
@inlinable func getSurroundingWithSelection(text: UnsafeMutablePointer<UnsafeMutablePointer<CChar>?>!, cursorIndex: UnsafeMutablePointer<gint>!, anchorIndex: 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(widget:Extension method) 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.Declaration
Swift
@inlinable func setClient(widget: WidgetRef? = nil) -
setClient(widget:Extension method) 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.Declaration
Swift
@inlinable func setClient<WidgetT>(widget: WidgetT?) where WidgetT : WidgetProtocol -
setCursorLocation(area:Extension method) Notify the input method that a change in cursor position has been made.
The location is relative to the client widget.
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 [signal
Gtk.IMContext::retrieve-surrounding] signal, and will likely have no effect if called at other times.set_surrounding is deprecated: Use [method@Gtk.IMContext.set_surrounding_with_selection] instead
Declaration
Swift
@available(*, deprecated) @inlinable func setSurrounding(text: UnsafePointer<CChar>!, len: Int, cursorIndex: Int) -
setSurroundingWithSelection(text:Extension methodlen: cursorIndex: anchorIndex: ) 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.Declaration
Swift
@inlinable func setSurroundingWithSelection(text: UnsafePointer<CChar>!, len: Int, cursorIndex: Int, anchorIndex: Int) -
set(usePreedit:Extension method) Sets whether the IM context should use the preedit string to display feedback.
If
use_preeditisfalse(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.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