GDK Reference Manual | |||
---|---|---|---|
<<< Previous Page | Home | Up | Next Page >>> |
#include <gdk/gdk.h> enum GdkIMStyle; gint gdk_im_ready (void); GdkIMStyle gdk_im_decide_style (GdkIMStyle supported_style); GdkIMStyle gdk_im_set_best_style (GdkIMStyle best_allowed_style); void gdk_im_begin (GdkIC *ic, GdkWindow *window); void gdk_im_end (void); |
Input Methods provide a way for complex character sets to be used in GTK+. Languages such as Chinese, Japanese, and Korean (often abbreviated to CJK) use a large number of ideographs, making it impossible to support all characters with a simple keyboard. Instead, text is usually pre-edited using a phonetic alphabet and then composed to form the ideographs.
GTK+ makes use of the input method mechanism provided by the X Windows platform. When a GTK+ application is started, it opens a connection to the input method appropriate for the current locale (if any).
Widgets which handle textual input, such as GtkEntry, need to do a number of things to support internationalized text input:
Check if an input method is being used with gdk_im_ready(). If it is, create a new Input Context using gdk_ic_new(). Find out which events the Input Context needs to receive with gdk_ic_get_events(), and make sure that the widget's window receives these events using gdk_window_set_events().
Update the appropriate Input Context attributes using gdk_ic_set_attr().
Call gdk_im_begin() or gdk_im_end() to start or finish editing the text.
The string and length fields of the GdkEventKey struct should be used to insert the composed text into the widget.
Destroy the Input Context.
See the XLib reference manual for more detailed information on input methods, and the GtkEntry and GtkText widgets for some example code.
typedef enum /*< flags >*/ { GDK_IM_PREEDIT_AREA = 0x0001, GDK_IM_PREEDIT_CALLBACKS = 0x0002, GDK_IM_PREEDIT_POSITION = 0x0004, GDK_IM_PREEDIT_NOTHING = 0x0008, GDK_IM_PREEDIT_NONE = 0x0010, GDK_IM_PREEDIT_MASK = 0x001f, GDK_IM_STATUS_AREA = 0x0100, GDK_IM_STATUS_CALLBACKS = 0x0200, GDK_IM_STATUS_NOTHING = 0x0400, GDK_IM_STATUS_NONE = 0x0800, GDK_IM_STATUS_MASK = 0x0f00 } GdkIMStyle; |
A set of bit-flags used to specify the input method styles which are supported or which are currently in use. The flags can be divided into 2 groups, the pre-edit flags and the status flags.
The pre-edit flags specify how pre-editing data is displayed. For example, this could display the text being typed in the phonetic alphabet before it is composed and inserted as an ideograph.
The status flags specify how status information is displayed. The status information can be thought of as an extension of the standard keyboard mode indicators, such as the Caps Lock indicator.
Note: The GDK_IM_PREEDIT_CALLBACKS and GDK_IM_STATUS_CALLBACKS styles are not currently supported in GTK+.
GDK_IM_PREEDIT_AREA | The application provides the input method with an area in which to perform off-the-spot pre-editing. |
GDK_IM_PREEDIT_CALLBACKS | The application registers a number of callback functions which are used to display pre-editing data. |
GDK_IM_PREEDIT_POSITION | The application provides the input method with the position of the insertion cursor, for over-the-spot pre-editing. The input method creates its own window over the widget to display the pre-editing data. |
GDK_IM_PREEDIT_NOTHING | The input method uses the root X window to perform pre-editing, so the application does not need to do anything. |
GDK_IM_PREEDIT_NONE | No pre-editing is done by the input method, or no pre-editing data needs to be displayed. |
GDK_IM_PREEDIT_MASK | A bit-mask containing all the pre-edit flags. |
GDK_IM_STATUS_AREA | The application provides the input method with an area in which to display status information. |
GDK_IM_STATUS_CALLBACKS | The applications registers a number of callback functions which are used to display status information. |
GDK_IM_STATUS_NOTHING | The input method uses the root X window to display status information, so the application does not need to do anything. |
GDK_IM_STATUS_NONE | The input method does not display status information. |
GDK_IM_STATUS_MASK | A bit-mask containing all the status flags. |
gint gdk_im_ready (void); |
Checks if an input method is to be used for the current locale. If GTK+ has been compiled without support for input methods, or the current locale doesn't need an input method, then this will return FALSE.
GdkIMStyle gdk_im_decide_style (GdkIMStyle supported_style); |
Decides which input method style should be used, by comparing the styles given in supported_style with those of the available input method.
GdkIMStyle gdk_im_set_best_style (GdkIMStyle best_allowed_style); |
Sets the best pre-edit and/or status style which should be used. This will affect the style chosen in gdk_im_decide_style().
The order of the pre-edit styles is (from worst to best): GDK_IM_PREEDIT_NONE, GDK_IM_PREEDIT_NOTHING, GDK_IM_PREEDIT_AREA, GDK_IM_PREEDIT_POSITION, GDK_IM_PREEDIT_CALLBACKS. The order of the status styles is: GDK_IM_STATUS_NONE, GDK_IM_STATUS_NOTHING, GDK_IM_STATUS_AREA, GDK_IM_STATUS_CALLBACKS.
So, for example, to set the best allowed pre-edit style to GDK_IM_PREEDIT_AREA you would do this:
Or to set the best allowed pre-edit style to GDK_IM_PREEDIT_POSITION and the best allowed status style to GDK_IM_STATUS_NOTHING you can do this:void gdk_im_begin (GdkIC *ic, GdkWindow *window); |
Starts editing, using the given input context and GdkWindow. This should be called when the widget receives the input focus, typically in the widget's focus_in_event method.
Used for each widget that handles internationalized text input using the global input method.