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
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. 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 casegtk_im_context_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 thegtk_im_context_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 to delete characters around the cursor position by emitting the GtkIMContext
delete_surrounding
signal. Note thatoffset
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
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_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 callinggtk_im_context_set_surrounding()
. Note that there is no obligation for a widget to respond to theretrieve_surrounding
signal, 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
GdkWindow
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.Declaration
Swift
@inlinable func setClient(window: Gdk.WindowRef? = nil)
-
setClient(window:
Extension method) Set the client window for the input context; this is the
GdkWindow
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.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_surrounding
signal, 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_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.Declaration
Swift
@inlinable func set(usePreedit: Bool)
-
parentInstance
Extension methodUndocumented
Declaration
Swift
@inlinable var parentInstance: GObject { get }