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
GtkIMContext
instance.Declaration
Swift
var ptr: UnsafeMutableRawPointer! { get }
-
im_context_ptr
Default implementationTyped pointer to the underlying
GtkIMContext
instance.Default Implementation
Return the stored, untyped pointer as a typed pointer to the
GtkIMContext
instance.Declaration
Swift
var im_context_ptr: UnsafeMutablePointer<GtkIMContext>! { get }
-
Required Initialiser for types conforming to
IMContextProtocol
Declaration
Swift
init(raw: UnsafeMutableRawPointer)
-
bind(property:
Extension methodto: _: flags: transformFrom: transformTo: ) Bind a
IMContextPropertyName
source 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 : ObjectProtocol
Parameters
source_property
the source property to bind
target
the target object to bind to
target_property
the target property to bind to
flags
the flags to pass to the
Binding
transform_from
ValueTransformer
to use for forward transformationtransform_to
ValueTransformer
to use for backwards transformationReturn Value
binding reference or
nil
in case of an error -
get(property:
Extension method) Get the value of a IMContext property
Declaration
Swift
@inlinable func get(property: IMContextPropertyName) -> GLibObject.Value
Parameters
property
the 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
property
the 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
IMContextSignalName
signalDeclaration
Swift
@discardableResult @inlinable func connect(signal s: IMContextSignalName, flags f: ConnectFlags = ConnectFlags(0), handler h: @escaping SignalHandler) -> Int
Parameters
signal
The signal to connect
flags
The connection flags to use
data
A pointer to user data to provide to the callback
destroyData
A
GClosureNotify
C function to destroy the data pointed to byuserData
handler
The 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
IMContextSignalName
signalDeclaration
Swift
@discardableResult @inlinable func connect(signal s: IMContextSignalName, flags f: ConnectFlags = ConnectFlags(0), data userData: gpointer!, destroyData destructor: GClosureNotify? = nil, signalHandler h: @escaping GCallback) -> Int
Parameters
signal
The signal to connect
flags
The connection flags to use
data
A pointer to user data to provide to the callback
destroyData
A
GClosureNotify
C function to destroy the data pointed to byuserData
signalHandler
The 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
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 afterpreedit-end
.This can be a single character immediately after a key press or the final result of preediting.
Note
This represents the underlyingcommit
signalDeclaration
Swift
@discardableResult @inlinable func onCommit(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: IMContextRef, _ str: String) -> Void) -> Int
Parameters
flags
Flags
unownedSelf
Reference to instance of self
str
the completed
character(s)
entered by the userhandler
The signal handler to call Run the given callback whenever the
commit
signal is emitted -
commitSignal
Extension methodTyped
commit
signal for using theconnect(signal:)
methodsDeclaration
Swift
static var commitSignal: IMContextSignalName { get }
-
onDeleteSurrounding(flags:
Extension methodhandler: ) The
delete-surrounding
signal is emitted when the input method needs to delete all or part of the context surrounding the cursor.Note
This represents the underlyingdelete-surrounding
signalDeclaration
Swift
@discardableResult @inlinable func onDeleteSurrounding(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: IMContextRef, _ offset: Int, _ nChars: Int) -> Bool) -> Int
Parameters
flags
Flags
unownedSelf
Reference to instance of self
offset
the character offset from the cursor position of the text to be deleted. A negative value indicates a position before the cursor.
nChars
the number of characters to be deleted
handler
true
if the signal was handled. Run the given callback whenever thedeleteSurrounding
signal is emitted -
deleteSurroundingSignal
Extension methodTyped
delete-surrounding
signal for using theconnect(signal:)
methodsDeclaration
Swift
static var deleteSurroundingSignal: IMContextSignalName { get }
-
onPreeditChanged(flags:
Extension methodhandler: ) 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 [method
Gtk.IMContext.get_preedit_string
] returns the empty string.Note
This represents the underlyingpreedit-changed
signalDeclaration
Swift
@discardableResult @inlinable func onPreeditChanged(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: IMContextRef) -> Void) -> Int
Parameters
flags
Flags
unownedSelf
Reference to instance of self
handler
The signal handler to call Run the given callback whenever the
preeditChanged
signal is emitted -
preeditChangedSignal
Extension methodTyped
preedit-changed
signal for using theconnect(signal:)
methodsDeclaration
Swift
static var preeditChangedSignal: IMContextSignalName { get }
-
onPreeditEnd(flags:
Extension methodhandler: ) The
preedit-end
signal is emitted when a preediting sequence has been completed or canceled.Note
This represents the underlyingpreedit-end
signalDeclaration
Swift
@discardableResult @inlinable func onPreeditEnd(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: IMContextRef) -> Void) -> Int
Parameters
flags
Flags
unownedSelf
Reference to instance of self
handler
The signal handler to call Run the given callback whenever the
preeditEnd
signal is emitted -
preeditEndSignal
Extension methodTyped
preedit-end
signal for using theconnect(signal:)
methodsDeclaration
Swift
static var preeditEndSignal: IMContextSignalName { get }
-
onPreeditStart(flags:
Extension methodhandler: ) The
preedit-start
signal is emitted when a new preediting sequence starts.Note
This represents the underlyingpreedit-start
signalDeclaration
Swift
@discardableResult @inlinable func onPreeditStart(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: IMContextRef) -> Void) -> Int
Parameters
flags
Flags
unownedSelf
Reference to instance of self
handler
The signal handler to call Run the given callback whenever the
preeditStart
signal is emitted -
preeditStartSignal
Extension methodTyped
preedit-start
signal for using theconnect(signal:)
methodsDeclaration
Swift
static var preeditStartSignal: IMContextSignalName { get }
-
onRetrieveSurrounding(flags:
Extension methodhandler: ) 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 [method
Gtk.IMContext.set_surrounding
] method.Note
This represents the underlyingretrieve-surrounding
signalDeclaration
Swift
@discardableResult @inlinable func onRetrieveSurrounding(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: IMContextRef) -> Bool) -> Int
Parameters
flags
Flags
unownedSelf
Reference to instance of self
handler
true
if the signal was handled. Run the given callback whenever theretrieveSurrounding
signal is emitted -
retrieveSurroundingSignal
Extension methodTyped
retrieve-surrounding
signal 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 innotify
being 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-hints
signalDeclaration
Swift
@discardableResult @inlinable func onNotifyInputHints(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: IMContextRef, _ pspec: ParamSpecRef) -> Void) -> Int
Parameters
flags
Flags
unownedSelf
Reference to instance of self
pspec
the
GParamSpec
of the property which changed.handler
The signal handler to call Run the given callback whenever the
notifyInputHints
signal is emitted -
notifyInputHintsSignal
Extension methodTyped
notify::input-hints
signal 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 innotify
being 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-purpose
signalDeclaration
Swift
@discardableResult @inlinable func onNotifyInputPurpose(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: IMContextRef, _ pspec: ParamSpecRef) -> Void) -> Int
Parameters
flags
Flags
unownedSelf
Reference to instance of self
pspec
the
GParamSpec
of the property which changed.handler
The signal handler to call Run the given callback whenever the
notifyInputPurpose
signal is emitted -
notifyInputPurposeSignal
Extension methodTyped
notify::input-purpose
signal 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_surrounding
signal.Note that
offset
andn_chars
are 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
GdkEvent
available.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-surrounding
signal, 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-surrounding
signal, 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
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.Declaration
Swift
@inlinable func setClient(widget: WidgetRef? = nil)
-
setClient(widget:
Extension method) 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.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_preedit
isfalse
(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)
-
parentInstance
Extension methodUndocumented
Declaration
Swift
@inlinable var parentInstance: GObject { get }