diff options
author | Takao Fujiwara <tfujiwar@redhat.com> | 2015-09-03 17:43:49 +0900 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2015-10-08 22:35:52 -0400 |
commit | 48a2477f2ddefb793e6845b14a84e715405f0c6e (patch) | |
tree | 99f67532176a6313d06baae77284e4680eac7f50 | |
parent | 22b0ed68078e022683bc81dbc33985837f4855d1 (diff) | |
download | gtk+-48a2477f2ddefb793e6845b14a84e715405f0c6e.tar.gz |
GtkIMContextSimple: export _gtk_check_compact_table() and GtkComposeTable
Some functions need to be exported if X11 compose files are loaded.
https://bugzilla.gnome.org/show_bug.cgi?id=721120
-rw-r--r-- | gtk/Makefile.am | 2 | ||||
-rw-r--r-- | gtk/gtkcomposetable.h | 46 | ||||
-rw-r--r-- | gtk/gtkimcontextsimple.c | 144 | ||||
-rw-r--r-- | gtk/gtkimcontextsimpleprivate.h | 49 |
4 files changed, 184 insertions, 57 deletions
diff --git a/gtk/Makefile.am b/gtk/Makefile.am index 801c3a5b87..919fd541a1 100644 --- a/gtk/Makefile.am +++ b/gtk/Makefile.am @@ -368,6 +368,7 @@ gtk_private_h_sources = \ gtkcolorscaleprivate.h \ gtkcolorchooserprivate.h \ gtkcomboboxprivate.h \ + gtkcomposetable.h \ gtkcontainerprivate.h \ gtkcssanimationprivate.h \ gtkcssanimatedstyleprivate.h \ @@ -452,6 +453,7 @@ gtk_private_h_sources = \ gtkiconhelperprivate.h \ gtkiconviewprivate.h \ gtkimageprivate.h \ + gtkimcontextsimpleprivate.h \ gtkimmoduleprivate.h \ gtkimcontextsimpleseqs.h \ gtkintl.h \ diff --git a/gtk/gtkcomposetable.h b/gtk/gtkcomposetable.h new file mode 100644 index 0000000000..fb3e8b2244 --- /dev/null +++ b/gtk/gtkcomposetable.h @@ -0,0 +1,46 @@ +/* GTK - The GIMP Toolkit + * Copyright (C) 2015 Takao Fujiwara <takao.fujiwara1@gmail.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef __GTK_COMPOSETABLE_H__ +#define __GTK_COMPOSETABLE_H__ + +#include <glib.h> + + +G_BEGIN_DECLS + +typedef struct _GtkComposeTable GtkComposeTable; +typedef struct _GtkComposeTableCompact GtkComposeTableCompact; + +struct _GtkComposeTable +{ + const guint16 *data; + gint max_seq_len; + gint n_seqs; +}; + +struct _GtkComposeTableCompact +{ + const guint16 *data; + gint max_seq_len; + gint n_index_size; + gint n_index_stride; +}; + +G_END_DECLS + +#endif /* __GTK_COMPOSETABLE_H__ */ diff --git a/gtk/gtkimcontextsimple.c b/gtk/gtkimcontextsimple.c index 6afc5d2342..d5d394b744 100644 --- a/gtk/gtkimcontextsimple.c +++ b/gtk/gtkimcontextsimple.c @@ -27,7 +27,9 @@ #include "gtkwidget.h" #include "gtkdebug.h" #include "gtkintl.h" +#include "gtkcomposetable.h" +#include "gtkimcontextsimpleprivate.h" /** * SECTION:gtkimcontextsimple @@ -36,9 +38,6 @@ */ -typedef struct _GtkComposeTable GtkComposeTable; -typedef struct _GtkComposeTableCompact GtkComposeTableCompact; - struct _GtkIMContextSimplePrivate { GSList *tables; @@ -51,33 +50,12 @@ struct _GtkIMContextSimplePrivate guint modifiers_dropped : 1; }; -struct _GtkComposeTable -{ - const guint16 *data; - gint max_seq_len; - gint n_seqs; -}; - -struct _GtkComposeTableCompact -{ - const guint16 *data; - gint max_seq_len; - gint n_index_size; - gint n_index_stride; -}; - -/* This file contains the table of the compose sequences, - * static const guint16 gtk_compose_seqs_compact[] = {} - * It is generated from the compose-parse.py script. - */ -#include "gtkimcontextsimpleseqs.h" - /* From the values below, the value 30 means the number of different first keysyms * that exist in the Compose file (from Xorg). When running compose-parse.py without * parameters, you get the count that you can put here. Needed when updating the * gtkimcontextsimpleseqs.h header file (contains the compose sequences). */ -static const GtkComposeTableCompact gtk_compose_table_compact = { +const GtkComposeTableCompact gtk_compose_table_compact = { gtk_compose_seqs_compact, 5, 30, @@ -414,12 +392,14 @@ check_quartz_special_cases (GtkIMContextSimple *context_simple, #endif -static gboolean -check_compact_table (GtkIMContextSimple *context_simple, - const GtkComposeTableCompact *table, - gint n_compose) +gboolean +gtk_check_compact_table (const GtkComposeTableCompact *table, + guint *compose_buffer, + gint n_compose, + gboolean *compose_finish, + gboolean *compose_match, + gunichar *output_char) { - GtkIMContextSimplePrivate *priv = context_simple->priv; gint row_stride; guint16 *seq_index; guint16 *seq; @@ -427,6 +407,13 @@ check_compact_table (GtkIMContextSimple *context_simple, gboolean match; gunichar value; + if (compose_finish) + *compose_finish = FALSE; + if (compose_match) + *compose_match = FALSE; + if (output_char) + *output_char = 0; + /* Will never match, if the sequence in the compose buffer is longer * than the sequences in the table. Further, compare_seq (key, val) * will overrun val if key is longer than val. @@ -434,7 +421,7 @@ check_compact_table (GtkIMContextSimple *context_simple, if (n_compose > table->max_seq_len) return FALSE; - seq_index = bsearch (priv->compose_buffer, + seq_index = bsearch (compose_buffer, table->data, table->n_index_size, sizeof (guint16) * table->n_index_stride, @@ -463,7 +450,7 @@ check_compact_table (GtkIMContextSimple *context_simple, if (seq_index[i + 1] - seq_index[i] > 0) { - seq = bsearch (priv->compose_buffer + 1, + seq = bsearch (compose_buffer + 1, table->data + seq_index[i], (seq_index[i + 1] - seq_index[i]) / row_stride, sizeof (guint16) * row_stride, @@ -478,15 +465,15 @@ check_compact_table (GtkIMContextSimple *context_simple, } else { + if (output_char) + *output_char = value; if (match) { + if (compose_match) + *compose_match = TRUE; GTK_NOTE (MISC, g_print ("tentative match U+%04X ", value)); - priv->tentative_match = value; - priv->tentative_match_len = n_compose; } - g_signal_emit_by_name (context_simple, "preedit-changed"); - GTK_NOTE (MISC, g_print ("yes\n")); return TRUE; } @@ -496,11 +483,12 @@ check_compact_table (GtkIMContextSimple *context_simple, if (match) { - gtk_im_context_simple_commit_char (GTK_IM_CONTEXT (context_simple), value); -#ifdef G_OS_WIN32 - check_win32_special_case_after_compact_match (context_simple, n_compose, value); -#endif - priv->compose_buffer[0] = 0; + if (compose_match) + *compose_match = TRUE; + if (compose_finish) + *compose_finish = TRUE; + if (output_char) + *output_char = value; GTK_NOTE (MISC, g_print ("U+%04X\n", value)); return TRUE; @@ -578,32 +566,35 @@ check_normalize_nfc (gunichar* combination_buffer, gint n_compose) return FALSE; } -static gboolean -check_algorithmically (GtkIMContextSimple *context_simple, - gint n_compose) +gboolean +gtk_check_algorithmically (const guint *compose_buffer, + gint n_compose, + gunichar *output_char) { - GtkIMContextSimplePrivate *priv = context_simple->priv; gint i; gunichar combination_buffer[GTK_MAX_COMPOSE_LEN]; gchar *combination_utf8, *nfc; + if (output_char) + *output_char = 0; + if (n_compose >= GTK_MAX_COMPOSE_LEN) return FALSE; - for (i = 0; i < n_compose && IS_DEAD_KEY (priv->compose_buffer[i]); i++) + for (i = 0; i < n_compose && IS_DEAD_KEY (compose_buffer[i]); i++) ; if (i == n_compose) return TRUE; if (i > 0 && i == n_compose - 1) { - combination_buffer[0] = gdk_keyval_to_unicode (priv->compose_buffer[i]); + combination_buffer[0] = gdk_keyval_to_unicode (compose_buffer[i]); combination_buffer[n_compose] = 0; i--; while (i >= 0) { - switch (priv->compose_buffer[i]) + switch (compose_buffer[i]) { #define CASE(keysym, unicode) \ case GDK_KEY_dead_##keysym: combination_buffer[i+1] = unicode; break @@ -640,7 +631,7 @@ check_algorithmically (GtkIMContextSimple *context_simple, /* CASE (psili, 0x343); */ #undef CASE default: - combination_buffer[i+1] = gdk_keyval_to_unicode (priv->compose_buffer[i]); + combination_buffer[i+1] = gdk_keyval_to_unicode (compose_buffer[i]); } i--; } @@ -650,13 +641,11 @@ check_algorithmically (GtkIMContextSimple *context_simple, */ if (check_normalize_nfc (combination_buffer, n_compose)) { - gunichar value; combination_utf8 = g_ucs4_to_utf8 (combination_buffer, -1, NULL, NULL, NULL); nfc = g_utf8_normalize (combination_utf8, -1, G_NORMALIZE_NFC); - value = g_utf8_get_char (nfc); - gtk_im_context_simple_commit_char (GTK_IM_CONTEXT (context_simple), value); - priv->compose_buffer[0] = 0; + if (output_char) + *output_char = g_utf8_get_char (nfc); g_free (combination_utf8); g_free (nfc); @@ -879,6 +868,9 @@ gtk_im_context_simple_filter_keypress (GtkIMContext *context, gboolean is_escape; guint hex_keyval; int i; + gboolean compose_finish; + gboolean compose_match; + gunichar output_char; while (priv->compose_buffer[n_compose] != 0) n_compose++; @@ -1121,11 +1113,49 @@ gtk_im_context_simple_filter_keypress (GtkIMContext *context, return TRUE; #endif - if (check_compact_table (context_simple, >k_compose_table_compact, n_compose)) - return TRUE; + if (gtk_check_compact_table (>k_compose_table_compact, + priv->compose_buffer, + n_compose, &compose_finish, + &compose_match, &output_char)) + { + if (compose_finish) + { + if (compose_match) + { + gtk_im_context_simple_commit_char (GTK_IM_CONTEXT (context_simple), + output_char); +#ifdef G_OS_WIN32 + check_win32_special_case_after_compact_match (context_simple, + n_compose, + output_char); +#endif + priv->compose_buffer[0] = 0; + } + } + else + { + if (compose_match) + { + priv->tentative_match = output_char; + priv->tentative_match_len = n_compose; + } + if (output_char) + g_signal_emit_by_name (context_simple, "preedit-changed"); + } + + return TRUE; + } - if (check_algorithmically (context_simple, n_compose)) - return TRUE; + if (gtk_check_algorithmically (priv->compose_buffer, n_compose, &output_char)) + { + if (output_char) + { + gtk_im_context_simple_commit_char (GTK_IM_CONTEXT (context_simple), + output_char); + priv->compose_buffer[0] = 0; + } + return TRUE; + } } /* The current compose_buffer doesn't match anything */ diff --git a/gtk/gtkimcontextsimpleprivate.h b/gtk/gtkimcontextsimpleprivate.h new file mode 100644 index 0000000000..7e59368f50 --- /dev/null +++ b/gtk/gtkimcontextsimpleprivate.h @@ -0,0 +1,49 @@ +/* GTK - The GIMP Toolkit + * Copyright (C) 2000 Red Hat Software + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef __GTK_IM_CONTEXT_SIMPLE_PRIVATE_H__ +#define __GTK_IM_CONTEXT_SIMPLE_PRIVATE_H__ + +#include <glib.h> + +#include "gdk/gdkkeysyms.h" + +/* This file contains the table of the compose sequences, + * static const guint16 gtk_compose_seqs_compact[] = {} + * IT is generated from the compose-parse.py script. + */ +#include "gtkimcontextsimpleseqs.h" + + +G_BEGIN_DECLS + +extern const GtkComposeTableCompact gtk_compose_table_compact; + +gboolean gtk_check_algorithmically (const guint *compose_buffer, + gint n_compose, + gunichar *output); +gboolean gtk_check_compact_table (const GtkComposeTableCompact *table, + guint *compose_buffer, + gint n_compose, + gboolean *compose_finish, + gboolean *compose_match, + gunichar *output_char); + +G_END_DECLS + + +#endif /* __GTK_IM_CONTEXT_SIMPLE_PRIVATE_H__ */ |