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 "gtkaccelgroup.h"
26 #include "gtkimcontextsimple.h"
27 #include "gtksettings.h"
28 #include "gtkwidget.h"
32 typedef struct _GtkComposeTable GtkComposeTable;
33 typedef struct _GtkComposeTableCompact GtkComposeTableCompact;
35 struct _GtkComposeTable
42 struct _GtkComposeTableCompact
50 /* This file contains the table of the compose sequences,
51 * static const guint16 gtk_compose_seqs_compact[] = {}
52 * IT is generated from the compose-parse.py script.
54 #include "gtkimcontextsimpleseqs.h"
56 /* From the values below, the value 23 means the number of different first keysyms
57 * that exist in the Compose file (from Xorg). When running compose-parse.py without
58 * parameters, you get the count that you can put here. Needed when updating the
59 * gtkimcontextsimpleseqs.h header file (contains the compose sequences).
61 static const GtkComposeTableCompact gtk_compose_table_compact = {
62 gtk_compose_seqs_compact,
68 static const guint16 gtk_compose_ignore[] = {
87 static void gtk_im_context_simple_finalize (GObject *obj);
88 static gboolean gtk_im_context_simple_filter_keypress (GtkIMContext *context,
90 static void gtk_im_context_simple_reset (GtkIMContext *context);
91 static void gtk_im_context_simple_get_preedit_string (GtkIMContext *context,
93 PangoAttrList **attrs,
96 G_DEFINE_TYPE (GtkIMContextSimple, gtk_im_context_simple, GTK_TYPE_IM_CONTEXT)
99 gtk_im_context_simple_class_init (GtkIMContextSimpleClass *class)
101 GtkIMContextClass *im_context_class = GTK_IM_CONTEXT_CLASS (class);
102 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
104 im_context_class->filter_keypress = gtk_im_context_simple_filter_keypress;
105 im_context_class->reset = gtk_im_context_simple_reset;
106 im_context_class->get_preedit_string = gtk_im_context_simple_get_preedit_string;
107 gobject_class->finalize = gtk_im_context_simple_finalize;
111 gtk_im_context_simple_init (GtkIMContextSimple *im_context_simple)
116 gtk_im_context_simple_finalize (GObject *obj)
118 GtkIMContextSimple *context_simple = GTK_IM_CONTEXT_SIMPLE (obj);
120 if (context_simple->tables)
122 g_slist_foreach (context_simple->tables, (GFunc)g_free, NULL);
123 g_slist_free (context_simple->tables);
125 context_simple->tables = NULL;
128 G_OBJECT_CLASS (gtk_im_context_simple_parent_class)->finalize (obj);
132 * gtk_im_context_simple_new:
134 * Creates a new #GtkIMContextSimple.
136 * Returns: a new #GtkIMContextSimple.
139 gtk_im_context_simple_new (void)
141 return g_object_new (GTK_TYPE_IM_CONTEXT_SIMPLE, NULL);
145 gtk_im_context_simple_commit_char (GtkIMContext *context,
151 GtkIMContextSimple *context_simple = GTK_IM_CONTEXT_SIMPLE (context);
153 g_return_if_fail (g_unichar_validate (ch));
155 len = g_unichar_to_utf8 (ch, buf);
158 if (context_simple->tentative_match || context_simple->in_hex_sequence)
160 context_simple->in_hex_sequence = FALSE;
161 context_simple->tentative_match = 0;
162 context_simple->tentative_match_len = 0;
163 g_signal_emit_by_name (context_simple, "preedit-changed");
164 g_signal_emit_by_name (context_simple, "preedit-end");
167 g_signal_emit_by_name (context, "commit", &buf);
171 compare_seq_index (const void *key, const void *value)
173 const guint *keysyms = key;
174 const guint16 *seq = value;
176 if (keysyms[0] < seq[0])
178 else if (keysyms[0] > seq[0])
185 compare_seq (const void *key, const void *value)
188 const guint *keysyms = key;
189 const guint16 *seq = value;
193 if (keysyms[i] < seq[i])
195 else if (keysyms[i] > seq[i])
205 check_table (GtkIMContextSimple *context_simple,
206 const GtkComposeTable *table,
209 gint row_stride = table->max_seq_len + 2;
212 /* Will never match, if the sequence in the compose buffer is longer
213 * than the sequences in the table. Further, compare_seq (key, val)
214 * will overrun val if key is longer than val. */
215 if (n_compose > table->max_seq_len)
218 seq = bsearch (context_simple->compose_buffer,
219 table->data, table->n_seqs,
220 sizeof (guint16) * row_stride,
227 /* Back up to the first sequence that matches to make sure
228 * we find the exact match if their is one.
230 while (seq > table->data)
232 prev_seq = seq - row_stride;
233 if (compare_seq (context_simple->compose_buffer, prev_seq) != 0)
238 if (n_compose == table->max_seq_len ||
239 seq[n_compose] == 0) /* complete sequence */
243 0x10000 * seq[table->max_seq_len] + seq[table->max_seq_len + 1];
246 /* We found a tentative match. See if there are any longer
247 * sequences containing this subsequence
249 next_seq = seq + row_stride;
250 if (next_seq < table->data + row_stride * table->n_seqs)
252 if (compare_seq (context_simple->compose_buffer, next_seq) == 0)
254 context_simple->tentative_match = value;
255 context_simple->tentative_match_len = n_compose;
257 g_signal_emit_by_name (context_simple, "preedit-changed");
263 gtk_im_context_simple_commit_char (GTK_IM_CONTEXT (context_simple), value);
264 context_simple->compose_buffer[0] = 0;
273 /* Checks if a keysym is a dead key. Dead key keysym values are defined in
274 * ../gdk/gdkkeysyms.h and the first is GDK_dead_grave. As X.Org is updated,
275 * more dead keys are added and we need to update the upper limit.
276 * Currently, the upper limit is GDK_dead_dasia+1. The +1 has to do with
277 * a temporary issue in the X.Org header files.
278 * In future versions it will be just the keysym (no +1).
280 #define IS_DEAD_KEY(k) \
281 ((k) >= GDK_dead_grave && (k) <= (GDK_dead_dasia+1))
283 #ifdef GDK_WINDOWING_WIN32
285 /* On Windows, user expectation is that typing a dead accent followed
286 * by space will input the corresponding spacing character. The X
287 * compose tables are different for dead acute and diaeresis, which
288 * when followed by space produce a plain ASCII apostrophe and double
289 * quote respectively. So special-case those.
293 check_win32_special_cases (GtkIMContextSimple *context_simple,
296 if (n_compose == 2 &&
297 context_simple->compose_buffer[1] == GDK_space)
301 switch (context_simple->compose_buffer[0])
304 value = 0x00B4; break;
305 case GDK_dead_diaeresis:
306 value = 0x00A8; break;
310 gtk_im_context_simple_commit_char (GTK_IM_CONTEXT (context_simple), value);
311 context_simple->compose_buffer[0] = 0;
313 GTK_NOTE (MISC, g_print ("win32: U+%04X\n", value));
321 check_win32_special_case_after_compact_match (GtkIMContextSimple *context_simple,
325 /* On Windows user expectation is that typing two dead accents will input
326 * two corresponding spacing accents.
328 if (n_compose == 2 &&
329 context_simple->compose_buffer[0] == context_simple->compose_buffer[1] &&
330 IS_DEAD_KEY (context_simple->compose_buffer[0]))
332 gtk_im_context_simple_commit_char (GTK_IM_CONTEXT (context_simple), value);
333 GTK_NOTE (MISC, g_print ("win32: U+%04X ", value));
340 check_compact_table (GtkIMContextSimple *context_simple,
341 const GtkComposeTableCompact *table,
349 /* Will never match, if the sequence in the compose buffer is longer
350 * than the sequences in the table. Further, compare_seq (key, val)
351 * will overrun val if key is longer than val. */
352 if (n_compose > table->max_seq_len)
355 seq_index = bsearch (context_simple->compose_buffer,
356 table->data, table->n_index_size,
357 sizeof (guint16) * table->n_index_stride,
362 GTK_NOTE (MISC, g_print ("compact: no\n"));
366 if (seq_index && n_compose == 1)
368 GTK_NOTE (MISC, g_print ("compact: yes\n"));
372 GTK_NOTE (MISC, g_print ("compact: %d ", *seq_index));
375 for (i = n_compose-1; i < table->max_seq_len; i++)
379 if (seq_index[i+1] - seq_index[i] > 0)
381 seq = bsearch (context_simple->compose_buffer + 1,
382 table->data + seq_index[i], (seq_index[i+1] - seq_index[i]) / row_stride,
383 sizeof (guint16) * row_stride,
388 if (i == n_compose - 1)
392 g_signal_emit_by_name (context_simple, "preedit-changed");
394 GTK_NOTE (MISC, g_print ("yes\n"));
403 GTK_NOTE (MISC, g_print ("no\n"));
410 value = seq[row_stride - 1];
412 gtk_im_context_simple_commit_char (GTK_IM_CONTEXT (context_simple), value);
414 check_win32_special_case_after_compact_match (context_simple, n_compose, value);
416 context_simple->compose_buffer[0] = 0;
418 GTK_NOTE (MISC, g_print ("U+%04X\n", value));
422 GTK_NOTE (MISC, g_print ("no\n"));
426 /* This function receives a sequence of Unicode characters and tries to
427 * normalize it (NFC). We check for the case the the resulting string
428 * has length 1 (single character).
429 * NFC normalisation normally rearranges diacritic marks, unless these
430 * belong to the same Canonical Combining Class.
431 * If they belong to the same canonical combining class, we produce all
432 * permutations of the diacritic marks, then attempt to normalize.
435 check_normalize_nfc (gunichar* combination_buffer, gint n_compose)
437 gunichar combination_buffer_temp[GTK_MAX_COMPOSE_LEN];
438 gchar *combination_utf8_temp = NULL;
439 gchar *nfc_temp = NULL;
446 for (i = 1; i < n_compose; i++ )
449 /* Xorg reuses dead_tilde for the perispomeni diacritic mark.
450 * We check if base character belongs to Greek Unicode block,
451 * and if so, we replace tilde with perispomeni. */
452 if (combination_buffer[0] >= 0x390 && combination_buffer[0] <= 0x3FF)
454 for (i = 1; i < n_compose; i++ )
455 if (combination_buffer[i] == 0x303)
456 combination_buffer[i] = 0x342;
459 memcpy (combination_buffer_temp, combination_buffer, GTK_MAX_COMPOSE_LEN * sizeof (gunichar) );
461 for (i = 0; i < n_combinations; i++ )
463 g_unicode_canonical_ordering (combination_buffer_temp, n_compose);
464 combination_utf8_temp = g_ucs4_to_utf8 (combination_buffer_temp, -1, NULL, NULL, NULL);
465 nfc_temp = g_utf8_normalize (combination_utf8_temp, -1, G_NORMALIZE_NFC);
467 if (g_utf8_strlen (nfc_temp, -1) == 1)
469 memcpy (combination_buffer, combination_buffer_temp, GTK_MAX_COMPOSE_LEN * sizeof (gunichar) );
471 g_free (combination_utf8_temp);
477 g_free (combination_utf8_temp);
482 temp_swap = combination_buffer_temp[i % (n_compose - 1) + 1];
483 combination_buffer_temp[i % (n_compose - 1) + 1] = combination_buffer_temp[(i+1) % (n_compose - 1) + 1];
484 combination_buffer_temp[(i+1) % (n_compose - 1) + 1] = temp_swap;
494 check_algorithmically (GtkIMContextSimple *context_simple,
499 gunichar combination_buffer[GTK_MAX_COMPOSE_LEN];
500 gchar *combination_utf8, *nfc;
502 if (n_compose >= GTK_MAX_COMPOSE_LEN)
505 for (i = 0; i < n_compose && IS_DEAD_KEY (context_simple->compose_buffer[i]); i++)
510 if (i > 0 && i == n_compose - 1)
512 combination_buffer[0] = gdk_keyval_to_unicode (context_simple->compose_buffer[i]);
513 combination_buffer[n_compose] = 0;
517 switch (context_simple->compose_buffer[i])
519 #define CASE(keysym, unicode) \
520 case GDK_dead_##keysym: combination_buffer[i+1] = unicode; break
522 CASE (grave, 0x0300);
523 CASE (acute, 0x0301);
524 CASE (circumflex, 0x0302);
525 CASE (tilde, 0x0303); /* Also used with perispomeni, 0x342. */
526 CASE (macron, 0x0304);
527 CASE (breve, 0x0306);
528 CASE (abovedot, 0x0307);
529 CASE (diaeresis, 0x0308);
531 CASE (abovering, 0x030A);
532 CASE (doubleacute, 0x030B);
533 CASE (caron, 0x030C);
534 CASE (abovecomma, 0x0313); /* Equivalent to psili */
535 CASE (abovereversedcomma, 0x0314); /* Equivalent to dasia */
536 CASE (horn, 0x031B); /* Legacy use for psili, 0x313 (or 0x343). */
537 CASE (belowdot, 0x0323);
538 CASE (cedilla, 0x0327);
539 CASE (ogonek, 0x0328); /* Legacy use for dasia, 0x314.*/
541 CASE (voiced_sound, 0x3099); /* Per Markus Kuhn keysyms.txt file. */
542 CASE (semivoiced_sound, 0x309A); /* Per Markus Kuhn keysyms.txt file. */
544 /* The following cases are to be removed once xkeyboard-config,
545 * xorg are fully updated.
547 /* Workaround for typo in 1.4.x xserver-xorg */
548 case 0xfe66: combination_buffer[i+1] = 0x314; break;
549 /* CASE (dasia, 0x314); */
550 /* CASE (perispomeni, 0x342); */
551 /* CASE (psili, 0x343); */
554 combination_buffer[i+1] = gdk_keyval_to_unicode (context_simple->compose_buffer[i]);
559 /* If the buffer normalizes to a single character,
560 * then modify the order of combination_buffer accordingly, if necessary,
563 if (check_normalize_nfc (combination_buffer, n_compose))
566 combination_utf8 = g_ucs4_to_utf8 (combination_buffer, -1, NULL, NULL, NULL);
567 nfc = g_utf8_normalize (combination_utf8, -1, G_NORMALIZE_NFC);
569 value = g_utf8_get_char (nfc);
570 gtk_im_context_simple_commit_char (GTK_IM_CONTEXT (context_simple), value);
571 context_simple->compose_buffer[0] = 0;
573 g_free (combination_utf8);
583 /* In addition to the table-driven sequences, we allow Unicode hex
584 * codes to be entered. The method chosen here is similar to the
585 * one recommended in ISO 14755, but not exactly the same, since we
586 * don't want to steal 16 valuable key combinations.
588 * A hex Unicode sequence must be started with Ctrl-Shift-U, followed
589 * by a sequence of hex digits entered with Ctrl-Shift still held.
590 * Releasing one of the modifiers or pressing space while the modifiers
591 * are still held commits the character. It is possible to erase
592 * digits using backspace.
594 * As an extension to the above, we also allow to start the sequence
595 * with Ctrl-Shift-U, then release the modifiers before typing any
596 * digits, and enter the digits without modifiers.
598 #define HEX_MOD_MASK (GDK_CONTROL_MASK | GDK_SHIFT_MASK)
601 check_hex (GtkIMContextSimple *context_simple,
604 /* See if this is a hex sequence, return TRUE if so */
611 context_simple->tentative_match = 0;
612 context_simple->tentative_match_len = 0;
614 str = g_string_new (NULL);
617 while (i < n_compose)
621 ch = gdk_keyval_to_unicode (context_simple->compose_buffer[i]);
626 if (!g_unichar_isxdigit (ch))
629 buf[g_unichar_to_utf8 (ch, buf)] = '\0';
631 g_string_append (str, buf);
636 n = strtoul (str->str, &nptr, 16);
638 /* if strtoul fails it probably means non-latin digits were used;
639 * we should in principle handle that, but we probably don't.
641 if (nptr - str->str < str->len)
643 g_string_free (str, TRUE);
647 g_string_free (str, TRUE);
649 if (g_unichar_validate (n))
651 context_simple->tentative_match = n;
652 context_simple->tentative_match_len = n_compose;
659 beep_window (GdkWindow *window)
663 gdk_window_get_user_data (window, (gpointer) &widget);
665 if (GTK_IS_WIDGET (widget))
667 gtk_widget_error_bell (widget);
671 GdkScreen *screen = gdk_drawable_get_screen (GDK_DRAWABLE (window));
674 g_object_get (gtk_settings_get_for_screen (screen),
675 "gtk-error-bell", &beep,
679 gdk_window_beep (window);
684 no_sequence_matches (GtkIMContextSimple *context_simple,
688 GtkIMContext *context;
691 context = GTK_IM_CONTEXT (context_simple);
693 /* No compose sequences found, check first if we have a partial
696 if (context_simple->tentative_match)
698 gint len = context_simple->tentative_match_len;
701 gtk_im_context_simple_commit_char (context, context_simple->tentative_match);
702 context_simple->compose_buffer[0] = 0;
704 for (i=0; i < n_compose - len - 1; i++)
706 GdkEvent *tmp_event = gdk_event_copy ((GdkEvent *)event);
707 tmp_event->key.keyval = context_simple->compose_buffer[len + i];
709 gtk_im_context_filter_keypress (context, (GdkEventKey *)tmp_event);
710 gdk_event_free (tmp_event);
713 return gtk_im_context_filter_keypress (context, event);
717 context_simple->compose_buffer[0] = 0;
718 if (n_compose > 1) /* Invalid sequence */
720 beep_window (event->window);
724 ch = gdk_keyval_to_unicode (event->keyval);
727 gtk_im_context_simple_commit_char (context, ch);
736 is_hex_keyval (guint keyval)
738 gunichar ch = gdk_keyval_to_unicode (keyval);
740 return g_unichar_isxdigit (ch);
744 canonical_hex_keyval (GdkEventKey *event)
746 GdkKeymap *keymap = gdk_keymap_get_for_display (gdk_drawable_get_display (event->window));
748 guint *keyvals = NULL;
752 /* See if the keyval is already a hex digit */
753 if (is_hex_keyval (event->keyval))
754 return event->keyval;
756 /* See if this key would have generated a hex keyval in
757 * any other state, and return that hex keyval if so
759 gdk_keymap_get_entries_for_keycode (keymap,
760 event->hardware_keycode,
768 if (is_hex_keyval (keyvals[i]))
782 /* No way to make it a hex digit
788 gtk_im_context_simple_filter_keypress (GtkIMContext *context,
791 GtkIMContextSimple *context_simple = GTK_IM_CONTEXT_SIMPLE (context);
794 gboolean have_hex_mods;
795 gboolean is_hex_start;
797 gboolean is_backspace;
802 while (context_simple->compose_buffer[n_compose] != 0)
805 if (event->type == GDK_KEY_RELEASE)
807 if (context_simple->in_hex_sequence &&
808 (event->keyval == GDK_Control_L || event->keyval == GDK_Control_R ||
809 event->keyval == GDK_Shift_L || event->keyval == GDK_Shift_R))
811 if (context_simple->tentative_match &&
812 g_unichar_validate (context_simple->tentative_match))
814 gtk_im_context_simple_commit_char (context, context_simple->tentative_match);
815 context_simple->compose_buffer[0] = 0;
818 else if (n_compose == 0)
820 context_simple->modifiers_dropped = TRUE;
824 /* invalid hex sequence */
825 beep_window (event->window);
827 context_simple->tentative_match = 0;
828 context_simple->in_hex_sequence = FALSE;
829 context_simple->compose_buffer[0] = 0;
831 g_signal_emit_by_name (context_simple, "preedit-changed");
832 g_signal_emit_by_name (context_simple, "preedit-end");
841 /* Ignore modifier key presses */
842 for (i = 0; i < G_N_ELEMENTS (gtk_compose_ignore); i++)
843 if (event->keyval == gtk_compose_ignore[i])
846 if (context_simple->in_hex_sequence && context_simple->modifiers_dropped)
847 have_hex_mods = TRUE;
849 have_hex_mods = (event->state & (HEX_MOD_MASK)) == HEX_MOD_MASK;
850 is_hex_start = event->keyval == GDK_U;
851 is_hex_end = (event->keyval == GDK_space ||
852 event->keyval == GDK_KP_Space ||
853 event->keyval == GDK_Return ||
854 event->keyval == GDK_ISO_Enter ||
855 event->keyval == GDK_KP_Enter);
856 is_backspace = event->keyval == GDK_BackSpace;
857 is_escape = event->keyval == GDK_Escape;
858 hex_keyval = canonical_hex_keyval (event);
860 /* If we are already in a non-hex sequence, or
861 * this keystroke is not hex modifiers + hex digit, don't filter
862 * key events with accelerator modifiers held down.
864 if (!have_hex_mods ||
865 (n_compose > 0 && !context_simple->in_hex_sequence) ||
866 (n_compose == 0 && !context_simple->in_hex_sequence && !is_hex_start) ||
867 (context_simple->in_hex_sequence && !hex_keyval &&
868 !is_hex_start && !is_hex_end && !is_escape && !is_backspace))
870 if (event->state & (gtk_accelerator_get_default_mod_mask () & ~GDK_SHIFT_MASK) ||
871 (context_simple->in_hex_sequence && context_simple->modifiers_dropped &&
872 (event->keyval == GDK_Return ||
873 event->keyval == GDK_ISO_Enter ||
874 event->keyval == GDK_KP_Enter)))
880 /* Handle backspace */
881 if (context_simple->in_hex_sequence && have_hex_mods && is_backspace)
886 context_simple->compose_buffer[n_compose] = 0;
887 check_hex (context_simple, n_compose);
891 context_simple->in_hex_sequence = FALSE;
894 g_signal_emit_by_name (context_simple, "preedit-changed");
896 if (!context_simple->in_hex_sequence)
897 g_signal_emit_by_name (context_simple, "preedit-end");
902 /* Check for hex sequence restart */
903 if (context_simple->in_hex_sequence && have_hex_mods && is_hex_start)
905 if (context_simple->tentative_match &&
906 g_unichar_validate (context_simple->tentative_match))
908 gtk_im_context_simple_commit_char (context, context_simple->tentative_match);
909 context_simple->compose_buffer[0] = 0;
913 /* invalid hex sequence */
915 beep_window (event->window);
917 context_simple->tentative_match = 0;
918 context_simple->in_hex_sequence = FALSE;
919 context_simple->compose_buffer[0] = 0;
923 /* Check for hex sequence start */
924 if (!context_simple->in_hex_sequence && have_hex_mods && is_hex_start)
926 context_simple->compose_buffer[0] = 0;
927 context_simple->in_hex_sequence = TRUE;
928 context_simple->modifiers_dropped = FALSE;
929 context_simple->tentative_match = 0;
931 g_signal_emit_by_name (context_simple, "preedit-start");
932 g_signal_emit_by_name (context_simple, "preedit-changed");
937 /* Then, check for compose sequences */
938 if (context_simple->in_hex_sequence)
941 context_simple->compose_buffer[n_compose++] = hex_keyval;
944 gtk_im_context_simple_reset (context);
948 else if (!is_hex_end)
950 /* non-hex character in hex sequence */
951 beep_window (event->window);
957 context_simple->compose_buffer[n_compose++] = event->keyval;
959 context_simple->compose_buffer[n_compose] = 0;
961 if (context_simple->in_hex_sequence)
963 /* If the modifiers are still held down, consider the sequence again */
966 /* space or return ends the sequence, and we eat the key */
967 if (n_compose > 0 && is_hex_end)
969 if (context_simple->tentative_match &&
970 g_unichar_validate (context_simple->tentative_match))
972 gtk_im_context_simple_commit_char (context, context_simple->tentative_match);
973 context_simple->compose_buffer[0] = 0;
977 /* invalid hex sequence */
978 beep_window (event->window);
980 context_simple->tentative_match = 0;
981 context_simple->in_hex_sequence = FALSE;
982 context_simple->compose_buffer[0] = 0;
985 else if (!check_hex (context_simple, n_compose))
986 beep_window (event->window);
988 g_signal_emit_by_name (context_simple, "preedit-changed");
990 if (!context_simple->in_hex_sequence)
991 g_signal_emit_by_name (context_simple, "preedit-end");
998 tmp_list = context_simple->tables;
1001 if (check_table (context_simple, tmp_list->data, n_compose))
1003 tmp_list = tmp_list->next;
1008 for (i = 0; i < n_compose; i++)
1010 const gchar *keyval_name = gdk_keyval_name (context_simple->compose_buffer[i]);
1012 if (keyval_name != NULL)
1013 g_print ("%s ", keyval_name);
1015 g_print ("%04x ", context_simple->compose_buffer[i]);
1020 #ifdef GDK_WINDOWING_WIN32
1021 if (check_win32_special_cases (context_simple, n_compose))
1025 if (check_compact_table (context_simple, >k_compose_table_compact, n_compose))
1028 if (check_algorithmically (context_simple, n_compose))
1032 /* The current compose_buffer doesn't match anything */
1033 return no_sequence_matches (context_simple, n_compose, event);
1037 gtk_im_context_simple_reset (GtkIMContext *context)
1039 GtkIMContextSimple *context_simple = GTK_IM_CONTEXT_SIMPLE (context);
1041 context_simple->compose_buffer[0] = 0;
1043 if (context_simple->tentative_match || context_simple->in_hex_sequence)
1045 context_simple->in_hex_sequence = FALSE;
1046 context_simple->tentative_match = 0;
1047 context_simple->tentative_match_len = 0;
1048 g_signal_emit_by_name (context_simple, "preedit-changed");
1049 g_signal_emit_by_name (context_simple, "preedit-end");
1054 gtk_im_context_simple_get_preedit_string (GtkIMContext *context,
1056 PangoAttrList **attrs,
1059 char outbuf[37]; /* up to 6 hex digits */
1062 GtkIMContextSimple *context_simple = GTK_IM_CONTEXT_SIMPLE (context);
1064 if (context_simple->in_hex_sequence)
1071 while (context_simple->compose_buffer[hexchars] != 0)
1073 len += g_unichar_to_utf8 (gdk_keyval_to_unicode (context_simple->compose_buffer[hexchars]),
1078 g_assert (len < 25);
1080 else if (context_simple->tentative_match)
1081 len = g_unichar_to_utf8 (context_simple->tentative_match, outbuf);
1086 *str = g_strdup (outbuf);
1090 *attrs = pango_attr_list_new ();
1094 PangoAttribute *attr = pango_attr_underline_new (PANGO_UNDERLINE_SINGLE);
1095 attr->start_index = 0;
1096 attr->end_index = len;
1097 pango_attr_list_insert (*attrs, attr);
1106 * gtk_im_context_simple_add_table:
1107 * @context_simple: A #GtkIMContextSimple
1109 * @max_seq_len: Maximum length of a sequence in the table
1110 * (cannot be greater than #GTK_MAX_COMPOSE_LEN)
1111 * @n_seqs: number of sequences in the table
1113 * Adds an additional table to search to the input context.
1114 * Each row of the table consists of @max_seq_len key symbols
1115 * followed by two #guint16 interpreted as the high and low
1116 * words of a #gunicode value. Tables are searched starting
1117 * from the last added.
1119 * The table must be sorted in dictionary order on the
1120 * numeric value of the key symbol fields. (Values beyond
1121 * the length of the sequence should be zero.)
1124 gtk_im_context_simple_add_table (GtkIMContextSimple *context_simple,
1129 GtkComposeTable *table;
1131 g_return_if_fail (GTK_IS_IM_CONTEXT_SIMPLE (context_simple));
1132 g_return_if_fail (data != NULL);
1133 g_return_if_fail (max_seq_len <= GTK_MAX_COMPOSE_LEN);
1135 table = g_new (GtkComposeTable, 1);
1137 table->max_seq_len = max_seq_len;
1138 table->n_seqs = n_seqs;
1140 context_simple->tables = g_slist_prepend (context_simple->tables, table);
1143 #define __GTK_IM_CONTEXT_SIMPLE_C__
1144 #include "gtkaliasdef.c"