1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 2000 Red Hat, Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
24 #include <gdk/gdkkeysyms.h>
25 #include "gtkprivate.h"
26 #include "gtkaccelgroup.h"
27 #include "gtkimcontextsimple.h"
28 #include "gtksettings.h"
29 #include "gtkwidget.h"
33 typedef struct _GtkComposeTable GtkComposeTable;
34 typedef struct _GtkComposeTableCompact GtkComposeTableCompact;
36 struct _GtkComposeTable
43 struct _GtkComposeTableCompact
51 /* This file contains the table of the compose sequences,
52 * static const guint16 gtk_compose_seqs_compact[] = {}
53 * IT is generated from the compose-parse.py script.
55 #include "gtkimcontextsimpleseqs.h"
57 /* From the values below, the value 23 means the number of different first keysyms
58 * that exist in the Compose file (from Xorg). When running compose-parse.py without
59 * parameters, you get the count that you can put here. Needed when updating the
60 * gtkimcontextsimpleseqs.h header file (contains the compose sequences).
62 static const GtkComposeTableCompact gtk_compose_table_compact = {
63 gtk_compose_seqs_compact,
69 static const guint16 gtk_compose_ignore[] = {
88 static void gtk_im_context_simple_finalize (GObject *obj);
89 static gboolean gtk_im_context_simple_filter_keypress (GtkIMContext *context,
91 static void gtk_im_context_simple_reset (GtkIMContext *context);
92 static void gtk_im_context_simple_get_preedit_string (GtkIMContext *context,
94 PangoAttrList **attrs,
97 G_DEFINE_TYPE (GtkIMContextSimple, gtk_im_context_simple, GTK_TYPE_IM_CONTEXT)
100 gtk_im_context_simple_class_init (GtkIMContextSimpleClass *class)
102 GtkIMContextClass *im_context_class = GTK_IM_CONTEXT_CLASS (class);
103 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
105 im_context_class->filter_keypress = gtk_im_context_simple_filter_keypress;
106 im_context_class->reset = gtk_im_context_simple_reset;
107 im_context_class->get_preedit_string = gtk_im_context_simple_get_preedit_string;
108 gobject_class->finalize = gtk_im_context_simple_finalize;
112 gtk_im_context_simple_init (GtkIMContextSimple *im_context_simple)
117 gtk_im_context_simple_finalize (GObject *obj)
119 GtkIMContextSimple *context_simple = GTK_IM_CONTEXT_SIMPLE (obj);
121 if (context_simple->tables)
123 g_slist_foreach (context_simple->tables, (GFunc)g_free, NULL);
124 g_slist_free (context_simple->tables);
126 context_simple->tables = NULL;
129 G_OBJECT_CLASS (gtk_im_context_simple_parent_class)->finalize (obj);
133 * gtk_im_context_simple_new:
135 * Creates a new #GtkIMContextSimple.
137 * Returns: a new #GtkIMContextSimple.
140 gtk_im_context_simple_new (void)
142 return g_object_new (GTK_TYPE_IM_CONTEXT_SIMPLE, NULL);
146 gtk_im_context_simple_commit_char (GtkIMContext *context,
152 GtkIMContextSimple *context_simple = GTK_IM_CONTEXT_SIMPLE (context);
154 g_return_if_fail (g_unichar_validate (ch));
156 len = g_unichar_to_utf8 (ch, buf);
159 if (context_simple->tentative_match || context_simple->in_hex_sequence)
161 context_simple->in_hex_sequence = FALSE;
162 context_simple->tentative_match = 0;
163 context_simple->tentative_match_len = 0;
164 g_signal_emit_by_name (context_simple, "preedit-changed");
165 g_signal_emit_by_name (context_simple, "preedit-end");
168 g_signal_emit_by_name (context, "commit", &buf);
172 compare_seq_index (const void *key, const void *value)
174 const guint *keysyms = key;
175 const guint16 *seq = value;
177 if (keysyms[0] < seq[0])
179 else if (keysyms[0] > seq[0])
186 compare_seq (const void *key, const void *value)
189 const guint *keysyms = key;
190 const guint16 *seq = value;
194 if (keysyms[i] < seq[i])
196 else if (keysyms[i] > seq[i])
206 check_table (GtkIMContextSimple *context_simple,
207 const GtkComposeTable *table,
210 gint row_stride = table->max_seq_len + 2;
213 /* Will never match, if the sequence in the compose buffer is longer
214 * than the sequences in the table. Further, compare_seq (key, val)
215 * will overrun val if key is longer than val. */
216 if (n_compose > table->max_seq_len)
219 seq = bsearch (context_simple->compose_buffer,
220 table->data, table->n_seqs,
221 sizeof (guint16) * row_stride,
228 /* Back up to the first sequence that matches to make sure
229 * we find the exact match if their is one.
231 while (seq > table->data)
233 prev_seq = seq - row_stride;
234 if (compare_seq (context_simple->compose_buffer, prev_seq) != 0)
239 if (n_compose == table->max_seq_len ||
240 seq[n_compose] == 0) /* complete sequence */
244 0x10000 * seq[table->max_seq_len] + seq[table->max_seq_len + 1];
247 /* We found a tentative match. See if there are any longer
248 * sequences containing this subsequence
250 next_seq = seq + row_stride;
251 if (next_seq < table->data + row_stride * table->n_seqs)
253 if (compare_seq (context_simple->compose_buffer, next_seq) == 0)
255 context_simple->tentative_match = value;
256 context_simple->tentative_match_len = n_compose;
258 g_signal_emit_by_name (context_simple, "preedit-changed");
264 gtk_im_context_simple_commit_char (GTK_IM_CONTEXT (context_simple), value);
265 context_simple->compose_buffer[0] = 0;
274 /* Checks if a keysym is a dead key. Dead key keysym values are defined in
275 * ../gdk/gdkkeysyms.h and the first is GDK_dead_grave. As X.Org is updated,
276 * more dead keys are added and we need to update the upper limit.
277 * Currently, the upper limit is GDK_dead_dasia+1. The +1 has to do with
278 * a temporary issue in the X.Org header files.
279 * In future versions it will be just the keysym (no +1).
281 #define IS_DEAD_KEY(k) \
282 ((k) >= GDK_dead_grave && (k) <= (GDK_dead_dasia+1))
284 #ifdef GDK_WINDOWING_WIN32
286 /* On Windows, user expectation is that typing a dead accent followed
287 * by space will input the corresponding spacing character. The X
288 * compose tables are different for dead acute and diaeresis, which
289 * when followed by space produce a plain ASCII apostrophe and double
290 * quote respectively. So special-case those.
294 check_win32_special_cases (GtkIMContextSimple *context_simple,
297 if (n_compose == 2 &&
298 context_simple->compose_buffer[1] == GDK_space)
302 switch (context_simple->compose_buffer[0])
305 value = 0x00B4; break;
306 case GDK_dead_diaeresis:
307 value = 0x00A8; break;
311 gtk_im_context_simple_commit_char (GTK_IM_CONTEXT (context_simple), value);
312 context_simple->compose_buffer[0] = 0;
314 GTK_NOTE (MISC, g_print ("win32: U+%04X\n", value));
322 check_win32_special_case_after_compact_match (GtkIMContextSimple *context_simple,
326 /* On Windows user expectation is that typing two dead accents will input
327 * two corresponding spacing accents.
329 if (n_compose == 2 &&
330 context_simple->compose_buffer[0] == context_simple->compose_buffer[1] &&
331 IS_DEAD_KEY (context_simple->compose_buffer[0]))
333 gtk_im_context_simple_commit_char (GTK_IM_CONTEXT (context_simple), value);
334 GTK_NOTE (MISC, g_print ("win32: U+%04X ", value));
341 check_compact_table (GtkIMContextSimple *context_simple,
342 const GtkComposeTableCompact *table,
350 /* Will never match, if the sequence in the compose buffer is longer
351 * than the sequences in the table. Further, compare_seq (key, val)
352 * will overrun val if key is longer than val. */
353 if (n_compose > table->max_seq_len)
356 seq_index = bsearch (context_simple->compose_buffer,
357 table->data, table->n_index_size,
358 sizeof (guint16) * table->n_index_stride,
363 GTK_NOTE (MISC, g_print ("compact: no\n"));
367 if (seq_index && n_compose == 1)
369 GTK_NOTE (MISC, g_print ("compact: yes\n"));
373 GTK_NOTE (MISC, g_print ("compact: %d ", *seq_index));
376 for (i = n_compose-1; i < table->max_seq_len; i++)
380 if (seq_index[i+1] - seq_index[i] > 0)
382 seq = bsearch (context_simple->compose_buffer + 1,
383 table->data + seq_index[i], (seq_index[i+1] - seq_index[i]) / row_stride,
384 sizeof (guint16) * row_stride,
389 if (i == n_compose - 1)
393 g_signal_emit_by_name (context_simple, "preedit-changed");
395 GTK_NOTE (MISC, g_print ("yes\n"));
404 GTK_NOTE (MISC, g_print ("no\n"));
411 value = seq[row_stride - 1];
413 gtk_im_context_simple_commit_char (GTK_IM_CONTEXT (context_simple), value);
415 check_win32_special_case_after_compact_match (context_simple, n_compose, value);
417 context_simple->compose_buffer[0] = 0;
419 GTK_NOTE (MISC, g_print ("U+%04X\n", value));
423 GTK_NOTE (MISC, g_print ("no\n"));
427 /* This function receives a sequence of Unicode characters and tries to
428 * normalize it (NFC). We check for the case the the resulting string
429 * has length 1 (single character).
430 * NFC normalisation normally rearranges diacritic marks, unless these
431 * belong to the same Canonical Combining Class.
432 * If they belong to the same canonical combining class, we produce all
433 * permutations of the diacritic marks, then attempt to normalize.
436 check_normalize_nfc (gunichar* combination_buffer, gint n_compose)
438 gunichar combination_buffer_temp[GTK_MAX_COMPOSE_LEN];
439 gchar *combination_utf8_temp = NULL;
440 gchar *nfc_temp = NULL;
447 for (i = 1; i < n_compose; i++ )
450 /* Xorg reuses dead_tilde for the perispomeni diacritic mark.
451 * We check if base character belongs to Greek Unicode block,
452 * and if so, we replace tilde with perispomeni. */
453 if (combination_buffer[0] >= 0x390 && combination_buffer[0] <= 0x3FF)
455 for (i = 1; i < n_compose; i++ )
456 if (combination_buffer[i] == 0x303)
457 combination_buffer[i] = 0x342;
460 memcpy (combination_buffer_temp, combination_buffer, GTK_MAX_COMPOSE_LEN * sizeof (gunichar) );
462 for (i = 0; i < n_combinations; i++ )
464 g_unicode_canonical_ordering (combination_buffer_temp, n_compose);
465 combination_utf8_temp = g_ucs4_to_utf8 (combination_buffer_temp, -1, NULL, NULL, NULL);
466 nfc_temp = g_utf8_normalize (combination_utf8_temp, -1, G_NORMALIZE_NFC);
468 if (g_utf8_strlen (nfc_temp, -1) == 1)
470 memcpy (combination_buffer, combination_buffer_temp, GTK_MAX_COMPOSE_LEN * sizeof (gunichar) );
472 g_free (combination_utf8_temp);
478 g_free (combination_utf8_temp);
483 temp_swap = combination_buffer_temp[i % (n_compose - 1) + 1];
484 combination_buffer_temp[i % (n_compose - 1) + 1] = combination_buffer_temp[(i+1) % (n_compose - 1) + 1];
485 combination_buffer_temp[(i+1) % (n_compose - 1) + 1] = temp_swap;
495 check_algorithmically (GtkIMContextSimple *context_simple,
500 gunichar combination_buffer[GTK_MAX_COMPOSE_LEN];
501 gchar *combination_utf8, *nfc;
503 if (n_compose >= GTK_MAX_COMPOSE_LEN)
506 for (i = 0; i < n_compose && IS_DEAD_KEY (context_simple->compose_buffer[i]); i++)
511 if (i > 0 && i == n_compose - 1)
513 combination_buffer[0] = gdk_keyval_to_unicode (context_simple->compose_buffer[i]);
514 combination_buffer[n_compose] = 0;
518 switch (context_simple->compose_buffer[i])
520 #define CASE(keysym, unicode) \
521 case GDK_dead_##keysym: combination_buffer[i+1] = unicode; break
523 CASE (grave, 0x0300);
524 CASE (acute, 0x0301);
525 CASE (circumflex, 0x0302);
526 CASE (tilde, 0x0303); /* Also used with perispomeni, 0x342. */
527 CASE (macron, 0x0304);
528 CASE (breve, 0x0306);
529 CASE (abovedot, 0x0307);
530 CASE (diaeresis, 0x0308);
532 CASE (abovering, 0x030A);
533 CASE (doubleacute, 0x030B);
534 CASE (caron, 0x030C);
535 CASE (abovecomma, 0x0313); /* Equivalent to psili */
536 CASE (abovereversedcomma, 0x0314); /* Equivalent to dasia */
537 CASE (horn, 0x031B); /* Legacy use for psili, 0x313 (or 0x343). */
538 CASE (belowdot, 0x0323);
539 CASE (cedilla, 0x0327);
540 CASE (ogonek, 0x0328); /* Legacy use for dasia, 0x314.*/
542 CASE (voiced_sound, 0x3099); /* Per Markus Kuhn keysyms.txt file. */
543 CASE (semivoiced_sound, 0x309A); /* Per Markus Kuhn keysyms.txt file. */
545 /* The following cases are to be removed once xkeyboard-config,
546 * xorg are fully updated.
548 /* Workaround for typo in 1.4.x xserver-xorg */
549 case 0xfe66: combination_buffer[i+1] = 0x314; break;
550 /* CASE (dasia, 0x314); */
551 /* CASE (perispomeni, 0x342); */
552 /* CASE (psili, 0x343); */
555 combination_buffer[i+1] = gdk_keyval_to_unicode (context_simple->compose_buffer[i]);
560 /* If the buffer normalizes to a single character,
561 * then modify the order of combination_buffer accordingly, if necessary,
564 if (check_normalize_nfc (combination_buffer, n_compose))
567 combination_utf8 = g_ucs4_to_utf8 (combination_buffer, -1, NULL, NULL, NULL);
568 nfc = g_utf8_normalize (combination_utf8, -1, G_NORMALIZE_NFC);
570 value = g_utf8_get_char (nfc);
571 gtk_im_context_simple_commit_char (GTK_IM_CONTEXT (context_simple), value);
572 context_simple->compose_buffer[0] = 0;
574 g_free (combination_utf8);
584 /* In addition to the table-driven sequences, we allow Unicode hex
585 * codes to be entered. The method chosen here is similar to the
586 * one recommended in ISO 14755, but not exactly the same, since we
587 * don't want to steal 16 valuable key combinations.
589 * A hex Unicode sequence must be started with Ctrl-Shift-U, followed
590 * by a sequence of hex digits entered with Ctrl-Shift still held.
591 * Releasing one of the modifiers or pressing space while the modifiers
592 * are still held commits the character. It is possible to erase
593 * digits using backspace.
595 * As an extension to the above, we also allow to start the sequence
596 * with Ctrl-Shift-U, then release the modifiers before typing any
597 * digits, and enter the digits without modifiers.
599 #define HEX_MOD_MASK (GTK_DEFAULT_ACCEL_MOD_MASK | GDK_SHIFT_MASK)
602 check_hex (GtkIMContextSimple *context_simple,
605 /* See if this is a hex sequence, return TRUE if so */
612 context_simple->tentative_match = 0;
613 context_simple->tentative_match_len = 0;
615 str = g_string_new (NULL);
618 while (i < n_compose)
622 ch = gdk_keyval_to_unicode (context_simple->compose_buffer[i]);
627 if (!g_unichar_isxdigit (ch))
630 buf[g_unichar_to_utf8 (ch, buf)] = '\0';
632 g_string_append (str, buf);
637 n = strtoul (str->str, &nptr, 16);
639 /* if strtoul fails it probably means non-latin digits were used;
640 * we should in principle handle that, but we probably don't.
642 if (nptr - str->str < str->len)
644 g_string_free (str, TRUE);
648 g_string_free (str, TRUE);
650 if (g_unichar_validate (n))
652 context_simple->tentative_match = n;
653 context_simple->tentative_match_len = n_compose;
660 beep_window (GdkWindow *window)
664 gdk_window_get_user_data (window, (gpointer) &widget);
666 if (GTK_IS_WIDGET (widget))
668 gtk_widget_error_bell (widget);
672 GdkScreen *screen = gdk_drawable_get_screen (GDK_DRAWABLE (window));
675 g_object_get (gtk_settings_get_for_screen (screen),
676 "gtk-error-bell", &beep,
680 gdk_window_beep (window);
685 no_sequence_matches (GtkIMContextSimple *context_simple,
689 GtkIMContext *context;
692 context = GTK_IM_CONTEXT (context_simple);
694 /* No compose sequences found, check first if we have a partial
697 if (context_simple->tentative_match)
699 gint len = context_simple->tentative_match_len;
702 gtk_im_context_simple_commit_char (context, context_simple->tentative_match);
703 context_simple->compose_buffer[0] = 0;
705 for (i=0; i < n_compose - len - 1; i++)
707 GdkEvent *tmp_event = gdk_event_copy ((GdkEvent *)event);
708 tmp_event->key.keyval = context_simple->compose_buffer[len + i];
710 gtk_im_context_filter_keypress (context, (GdkEventKey *)tmp_event);
711 gdk_event_free (tmp_event);
714 return gtk_im_context_filter_keypress (context, event);
718 context_simple->compose_buffer[0] = 0;
719 if (n_compose > 1) /* Invalid sequence */
721 beep_window (event->window);
725 ch = gdk_keyval_to_unicode (event->keyval);
728 gtk_im_context_simple_commit_char (context, ch);
737 is_hex_keyval (guint keyval)
739 gunichar ch = gdk_keyval_to_unicode (keyval);
741 return g_unichar_isxdigit (ch);
745 canonical_hex_keyval (GdkEventKey *event)
747 GdkKeymap *keymap = gdk_keymap_get_for_display (gdk_drawable_get_display (event->window));
749 guint *keyvals = NULL;
753 /* See if the keyval is already a hex digit */
754 if (is_hex_keyval (event->keyval))
755 return event->keyval;
757 /* See if this key would have generated a hex keyval in
758 * any other state, and return that hex keyval if so
760 gdk_keymap_get_entries_for_keycode (keymap,
761 event->hardware_keycode,
769 if (is_hex_keyval (keyvals[i]))
783 /* No way to make it a hex digit
789 gtk_im_context_simple_filter_keypress (GtkIMContext *context,
792 GtkIMContextSimple *context_simple = GTK_IM_CONTEXT_SIMPLE (context);
795 gboolean have_hex_mods;
796 gboolean is_hex_start;
798 gboolean is_backspace;
803 while (context_simple->compose_buffer[n_compose] != 0)
806 if (event->type == GDK_KEY_RELEASE)
808 if (context_simple->in_hex_sequence &&
809 (event->keyval == GDK_Control_L || event->keyval == GDK_Control_R ||
810 event->keyval == GDK_Shift_L || event->keyval == GDK_Shift_R))
812 if (context_simple->tentative_match &&
813 g_unichar_validate (context_simple->tentative_match))
815 gtk_im_context_simple_commit_char (context, context_simple->tentative_match);
816 context_simple->compose_buffer[0] = 0;
819 else if (n_compose == 0)
821 context_simple->modifiers_dropped = TRUE;
825 /* invalid hex sequence */
826 beep_window (event->window);
828 context_simple->tentative_match = 0;
829 context_simple->in_hex_sequence = FALSE;
830 context_simple->compose_buffer[0] = 0;
832 g_signal_emit_by_name (context_simple, "preedit-changed");
833 g_signal_emit_by_name (context_simple, "preedit-end");
842 /* Ignore modifier key presses */
843 for (i = 0; i < G_N_ELEMENTS (gtk_compose_ignore); i++)
844 if (event->keyval == gtk_compose_ignore[i])
847 if (context_simple->in_hex_sequence && context_simple->modifiers_dropped)
848 have_hex_mods = TRUE;
850 have_hex_mods = (event->state & (HEX_MOD_MASK)) == HEX_MOD_MASK;
851 is_hex_start = event->keyval == GDK_U;
852 is_hex_end = (event->keyval == GDK_space ||
853 event->keyval == GDK_KP_Space ||
854 event->keyval == GDK_Return ||
855 event->keyval == GDK_ISO_Enter ||
856 event->keyval == GDK_KP_Enter);
857 is_backspace = event->keyval == GDK_BackSpace;
858 is_escape = event->keyval == GDK_Escape;
859 hex_keyval = canonical_hex_keyval (event);
861 /* If we are already in a non-hex sequence, or
862 * this keystroke is not hex modifiers + hex digit, don't filter
863 * key events with accelerator modifiers held down. We only treat
864 * Control and Alt as accel modifiers here, since Super, Hyper and
865 * Meta are often co-located with Mode_Switch, Multi_Key or
868 if (!have_hex_mods ||
869 (n_compose > 0 && !context_simple->in_hex_sequence) ||
870 (n_compose == 0 && !context_simple->in_hex_sequence && !is_hex_start) ||
871 (context_simple->in_hex_sequence && !hex_keyval &&
872 !is_hex_start && !is_hex_end && !is_escape && !is_backspace))
874 if (event->state & (GDK_MOD1_MASK | GDK_CONTROL_MASK) ||
875 (context_simple->in_hex_sequence && context_simple->modifiers_dropped &&
876 (event->keyval == GDK_Return ||
877 event->keyval == GDK_ISO_Enter ||
878 event->keyval == GDK_KP_Enter)))
884 /* Handle backspace */
885 if (context_simple->in_hex_sequence && have_hex_mods && is_backspace)
890 context_simple->compose_buffer[n_compose] = 0;
891 check_hex (context_simple, n_compose);
895 context_simple->in_hex_sequence = FALSE;
898 g_signal_emit_by_name (context_simple, "preedit-changed");
900 if (!context_simple->in_hex_sequence)
901 g_signal_emit_by_name (context_simple, "preedit-end");
906 /* Check for hex sequence restart */
907 if (context_simple->in_hex_sequence && have_hex_mods && is_hex_start)
909 if (context_simple->tentative_match &&
910 g_unichar_validate (context_simple->tentative_match))
912 gtk_im_context_simple_commit_char (context, context_simple->tentative_match);
913 context_simple->compose_buffer[0] = 0;
917 /* invalid hex sequence */
919 beep_window (event->window);
921 context_simple->tentative_match = 0;
922 context_simple->in_hex_sequence = FALSE;
923 context_simple->compose_buffer[0] = 0;
927 /* Check for hex sequence start */
928 if (!context_simple->in_hex_sequence && have_hex_mods && is_hex_start)
930 context_simple->compose_buffer[0] = 0;
931 context_simple->in_hex_sequence = TRUE;
932 context_simple->modifiers_dropped = FALSE;
933 context_simple->tentative_match = 0;
935 g_signal_emit_by_name (context_simple, "preedit-start");
936 g_signal_emit_by_name (context_simple, "preedit-changed");
941 /* Then, check for compose sequences */
942 if (context_simple->in_hex_sequence)
945 context_simple->compose_buffer[n_compose++] = hex_keyval;
948 gtk_im_context_simple_reset (context);
952 else if (!is_hex_end)
954 /* non-hex character in hex sequence */
955 beep_window (event->window);
961 context_simple->compose_buffer[n_compose++] = event->keyval;
963 context_simple->compose_buffer[n_compose] = 0;
965 if (context_simple->in_hex_sequence)
967 /* If the modifiers are still held down, consider the sequence again */
970 /* space or return ends the sequence, and we eat the key */
971 if (n_compose > 0 && is_hex_end)
973 if (context_simple->tentative_match &&
974 g_unichar_validate (context_simple->tentative_match))
976 gtk_im_context_simple_commit_char (context, context_simple->tentative_match);
977 context_simple->compose_buffer[0] = 0;
981 /* invalid hex sequence */
982 beep_window (event->window);
984 context_simple->tentative_match = 0;
985 context_simple->in_hex_sequence = FALSE;
986 context_simple->compose_buffer[0] = 0;
989 else if (!check_hex (context_simple, n_compose))
990 beep_window (event->window);
992 g_signal_emit_by_name (context_simple, "preedit-changed");
994 if (!context_simple->in_hex_sequence)
995 g_signal_emit_by_name (context_simple, "preedit-end");
1002 tmp_list = context_simple->tables;
1005 if (check_table (context_simple, tmp_list->data, n_compose))
1007 tmp_list = tmp_list->next;
1012 for (i = 0; i < n_compose; i++)
1014 const gchar *keyval_name = gdk_keyval_name (context_simple->compose_buffer[i]);
1016 if (keyval_name != NULL)
1017 g_print ("%s ", keyval_name);
1019 g_print ("%04x ", context_simple->compose_buffer[i]);
1024 #ifdef GDK_WINDOWING_WIN32
1025 if (check_win32_special_cases (context_simple, n_compose))
1029 if (check_compact_table (context_simple, >k_compose_table_compact, n_compose))
1032 if (check_algorithmically (context_simple, n_compose))
1036 /* The current compose_buffer doesn't match anything */
1037 return no_sequence_matches (context_simple, n_compose, event);
1041 gtk_im_context_simple_reset (GtkIMContext *context)
1043 GtkIMContextSimple *context_simple = GTK_IM_CONTEXT_SIMPLE (context);
1045 context_simple->compose_buffer[0] = 0;
1047 if (context_simple->tentative_match || context_simple->in_hex_sequence)
1049 context_simple->in_hex_sequence = FALSE;
1050 context_simple->tentative_match = 0;
1051 context_simple->tentative_match_len = 0;
1052 g_signal_emit_by_name (context_simple, "preedit-changed");
1053 g_signal_emit_by_name (context_simple, "preedit-end");
1058 gtk_im_context_simple_get_preedit_string (GtkIMContext *context,
1060 PangoAttrList **attrs,
1063 char outbuf[37]; /* up to 6 hex digits */
1066 GtkIMContextSimple *context_simple = GTK_IM_CONTEXT_SIMPLE (context);
1068 if (context_simple->in_hex_sequence)
1075 while (context_simple->compose_buffer[hexchars] != 0)
1077 len += g_unichar_to_utf8 (gdk_keyval_to_unicode (context_simple->compose_buffer[hexchars]),
1082 g_assert (len < 25);
1084 else if (context_simple->tentative_match)
1085 len = g_unichar_to_utf8 (context_simple->tentative_match, outbuf);
1090 *str = g_strdup (outbuf);
1094 *attrs = pango_attr_list_new ();
1098 PangoAttribute *attr = pango_attr_underline_new (PANGO_UNDERLINE_SINGLE);
1099 attr->start_index = 0;
1100 attr->end_index = len;
1101 pango_attr_list_insert (*attrs, attr);
1110 * gtk_im_context_simple_add_table:
1111 * @context_simple: A #GtkIMContextSimple
1113 * @max_seq_len: Maximum length of a sequence in the table
1114 * (cannot be greater than #GTK_MAX_COMPOSE_LEN)
1115 * @n_seqs: number of sequences in the table
1117 * Adds an additional table to search to the input context.
1118 * Each row of the table consists of @max_seq_len key symbols
1119 * followed by two #guint16 interpreted as the high and low
1120 * words of a #gunicode value. Tables are searched starting
1121 * from the last added.
1123 * The table must be sorted in dictionary order on the
1124 * numeric value of the key symbol fields. (Values beyond
1125 * the length of the sequence should be zero.)
1128 gtk_im_context_simple_add_table (GtkIMContextSimple *context_simple,
1133 GtkComposeTable *table;
1135 g_return_if_fail (GTK_IS_IM_CONTEXT_SIMPLE (context_simple));
1136 g_return_if_fail (data != NULL);
1137 g_return_if_fail (max_seq_len <= GTK_MAX_COMPOSE_LEN);
1139 table = g_new (GtkComposeTable, 1);
1141 table->max_seq_len = max_seq_len;
1142 table->n_seqs = n_seqs;
1144 context_simple->tables = g_slist_prepend (context_simple->tables, table);